| 2172 | } |
| 2173 | |
| 2174 | bool 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 | |
| 2210 | void TerrainPatch::UpdateCollisionScale() const |
| 2211 | { |
nothing calls this directly
no test coverage detected