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

Method CacheSplatData

Source/Engine/Terrain/TerrainPatch.cpp:1324–1391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1322}
1323
1324void TerrainPatch::CacheSplatData()
1325{
1326 PROFILE_CPU_NAMED("Terrain.CacheSplatData");
1327 PROFILE_MEM(LevelTerrain);
1328 const TerrainDataUpdateInfo info(this);
1329
1330 // Cache all the splatmaps
1331 for (int32 index = 0; index < TERRAIN_MAX_SPLATMAPS_COUNT; index++)
1332 {
1333 // Allocate data
1334 _cachedSplatMap[index].Resize(info.HeightmapLength);
1335 _wasSplatmapModified[index] = false;
1336
1337 // Skip if has missing splatmap asset
1338 if (Splatmap[index] == nullptr)
1339 {
1340 // Initialize splatmap (fill with the first layer if it's the first splatmap)
1341 const auto fillColor = index == 0 ? Color32(255, 0, 0, 0) : Color32::Transparent;
1342 _cachedSplatMap[index].SetAll(fillColor);
1343 continue;
1344 }
1345
1346 // Ensure that splatmap data is all loaded
1347 // TODO: disable streaming for heightmap texture if it's being modified by the editor
1348 if (Splatmap[index]->WaitForLoaded())
1349 {
1350 LOG(Error, "Failed to load patch splatmap data.");
1351 continue;
1352 }
1353
1354 // Get the LOD0 mip map data and extract the splatmap
1355 auto lock = Splatmap[index]->LockData();
1356 BytesContainer mipLOD0;
1357 Splatmap[index]->GetMipDataWithLoading(0, mipLOD0);
1358 if (mipLOD0.IsInvalid())
1359 {
1360 LOG(Error, "Failed to get patch splatmap data.");
1361 continue;
1362 }
1363
1364 // Extract splatmap data
1365 const auto splatMapPtr = static_cast<Color32*>(_cachedSplatMap[index].Get());
1366 for (int32 chunkIndex = 0; chunkIndex < Terrain::ChunksCount; chunkIndex++)
1367 {
1368 const int32 chunkTextureX = Chunks[chunkIndex]._x * info.VertexCountEdge;
1369 const int32 chunkTextureZ = Chunks[chunkIndex]._z * info.VertexCountEdge;
1370
1371 const int32 chunkHeightmapX = Chunks[chunkIndex]._x * info.ChunkSize;
1372 const int32 chunkHeightmapZ = Chunks[chunkIndex]._z * info.ChunkSize;
1373
1374 for (int32 z = 0; z < info.VertexCountEdge; z++)
1375 {
1376 const int32 tz = (chunkTextureZ + z) * info.TextureSize;
1377 const int32 sz = (chunkHeightmapZ + z) * info.HeightmapSize;
1378
1379 for (int32 x = 0; x < info.VertexCountEdge; x++)
1380 {
1381 const int32 tx = chunkTextureX + x;

Callers

nothing calls this directly

Calls 8

WaitForLoadedMethod · 0.80
GetMipDataWithLoadingMethod · 0.80
Color32Class · 0.50
ResizeMethod · 0.45
SetAllMethod · 0.45
LockDataMethod · 0.45
IsInvalidMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected