Remove the submesh class as that caused more problems than it solved

This commit is contained in:
Magnus Norddahl 2024-01-29 21:56:42 +01:00
commit 7bc2ed5436
20 changed files with 836 additions and 994 deletions

View file

@ -3017,8 +3017,8 @@ void MapLoader::InitLevelMesh(MapData* map)
{
if (Level->lightmaps)
{
Level->levelMesh->StaticMesh->SetupTileTransforms();
Level->levelMesh->StaticMesh->PackLightmapAtlas(0);
Level->levelMesh->SetupTileTransforms();
Level->levelMesh->PackLightmapAtlas(0);
}
}
}
@ -3100,12 +3100,11 @@ bool MapLoader::LoadLightmap(MapData* map)
uint8_t* data = (uint8_t*)&textureData[0];
fr.Read(data, numTexPixels * 3 * sizeof(uint16_t));
auto submesh = Level->levelMesh->StaticMesh.get();
const auto textureSize = submesh->LMTextureSize;
const auto textureSize = Level->levelMesh->LMTextureSize;
// Create lookup for finding tiles
std::map<LightmapTileBinding, LightmapTile*> levelTiles;
for (LightmapTile& tile : submesh->LightmapTiles)
for (LightmapTile& tile : Level->levelMesh->LightmapTiles)
{
levelTiles[tile.Binding] = &tile;
}
@ -3154,18 +3153,18 @@ bool MapLoader::LoadLightmap(MapData* map)
}
// Setup the tile transform for any tile missing in the lump (shouldn't be any, but if there are we let the lightmapper bake them)
for (auto& tile : submesh->LightmapTiles)
for (auto& tile : Level->levelMesh->LightmapTiles)
{
if (tile.NeedsUpdate)
tile.SetupTileTransform(submesh->LMTextureSize);
tile.SetupTileTransform(Level->levelMesh->LMTextureSize);
}
// Place all tiles in atlas textures
submesh->PackLightmapAtlas(0);
Level->levelMesh->PackLightmapAtlas(0);
// Start with empty lightmap textures
submesh->LMTextureData.Resize(submesh->LMTextureCount * textureSize * textureSize * 3);
memset(submesh->LMTextureData.Data(), 0, submesh->LMTextureData.Size() * sizeof(uint16_t));
Level->levelMesh->LMTextureData.Resize(Level->levelMesh->LMTextureCount * textureSize * textureSize * 3);
memset(Level->levelMesh->LMTextureData.Data(), 0, Level->levelMesh->LMTextureData.Size() * sizeof(uint16_t));
// Copy tile pixels to the texture
for (auto& binding : foundBindings)
@ -3174,7 +3173,7 @@ bool MapLoader::LoadLightmap(MapData* map)
LightmapTile* tile = binding.second;
const uint16_t* src = textureData.Data() + entry->pixelsOffset;
uint16_t* dst = &submesh->LMTextureData[tile->AtlasLocation.ArrayIndex * textureSize * textureSize * 3];
uint16_t* dst = &Level->levelMesh->LMTextureData[tile->AtlasLocation.ArrayIndex * textureSize * textureSize * 3];
int destx = tile->AtlasLocation.X;
int desty = tile->AtlasLocation.Y;
int width = tile->AtlasLocation.Width;