MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / CreateHeightField

Method CreateHeightField

Source/Engine/Terrain/TerrainPatch.cpp:2174–2208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2172}
2173
2174bool TerrainPatch::CreateHeightField()
2175{
2176 PROFILE_CPU();
2177 ASSERT(_physicsHeightField == nullptr);
2178
2179 // Skip if height field data is missing but warn on loading failed
2180 if (_heightfield == nullptr)
2181 return true;
2182 if (_heightfield->WaitForLoaded() || _heightfield->Data.IsEmpty())
2183 {
2184 LOG(Warning, "Cannot create terrain collision. Failed to load heightfield data for terrain {0} patch {1}x{2}.", _terrain->ToString(), _x, _z);
2185 return true;
2186 }
2187
2188 // Check if the cooked collision matches the engine version
2189 auto collisionHeader = (TerrainCollisionDataHeader*)_heightfield->Data.Get();
2190 if (collisionHeader->CheckOldMagicNumber != MAX_int32 || collisionHeader->Version != TerrainCollisionDataHeader::CurrentVersion)
2191 {
2192 // Reset height map
2193 PROFILE_CPU_NAMED("ResetHeightMap");
2194 const float* data = GetHeightmapData();
2195 return SetupHeightMap(_cachedHeightMap.Count(), data);
2196 }
2197
2198 // Create heightfield object from the data
2199 _collisionScaleXZ = collisionHeader->ScaleXZ * TERRAIN_UNITS_PER_VERTEX;
2200 _physicsHeightField = PhysicsBackend::CreateHeightField(_heightfield->Data.Get() + sizeof(TerrainCollisionDataHeader), _heightfield->Data.Count() - sizeof(TerrainCollisionDataHeader));
2201 if (_physicsHeightField == nullptr)
2202 {
2203 LOG(Error, "Failed to create terrain collision height field.");
2204 return true;
2205 }
2206
2207 return false;
2208}
2209
2210void TerrainPatch::UpdateCollisionScale() const
2211{

Callers

nothing calls this directly

Calls 5

WaitForLoadedMethod · 0.80
IsEmptyMethod · 0.45
ToStringMethod · 0.45
GetMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected