using AC2RE.Definitions; using ImageMagick; using LandblockExtraction.DatEngine; using System.Numerics; namespace LandblockExtraction.AtlasMaker; public class TerrainAtlasManager { private PortalEngine portalEngine; public Dictionary textureCoord; public Dictionary terrainTexture; public Dictionary terrains; public TerrainAtlasManager(PortalEngine portalEngine) { this.portalEngine = portalEngine; textureCoord = new Dictionary(); terrainTexture = new Dictionary(); terrains = new Dictionary(); testGenerateList(); } public void ExtractTexture() { using (var atlasBuilder = new AtlasBuilder(portalEngine)) { foreach (var terrain in portalEngine.cTerrainDesc.terrains) { foreach (var surface in portalEngine.cSurfaceDesc.surfaces) { if (surface.surfIndex == terrain.surfaceInfo) { atlasBuilder.AddTexture((int)terrain.terrainIndex, surface.terrainMaterials.First().baseMaterials.First().materialDid); //terrains.Add((int)terrain.terrainIndex, GenerateSubTerrain((int)terrain.terrainIndex, surface.terrainMaterials)); } } textureCoord.Add((int)terrain.terrainIndex, Vector2.Zero); } atlasBuilder.GenerateAtlas(); foreach (var img in atlasBuilder.textures) { terrainTexture.Add(img.Key, img.Value); } } } /*private Terrain GenerateSubTerrain(int index, List materialGroups) { Terrain tmpTerrain = new Terrain(index); foreach(var material in materialGroups) { int indexTer = GetIndexBySurface(material.s) SubTerrain subTerrain = new(ma) } }*/ private void testGenerateList() { foreach(var surface in portalEngine.cSurfaceDesc.surfaces) { foreach(var terrain in portalEngine.cTerrainDesc.terrains) { if(surface.surfIndex == terrain.surfaceInfo) { Console.WriteLine($"[{terrain.terrainIndex}:{terrain.terrainName}]\t- Surface: {surface.surfIndex:X8} | Base: {surface.terrainMaterials.First().baseMaterials.First().materialDid}"); } } } } private int? GetIndexBySurface(uint surfaceIndex) { foreach(var terrain in portalEngine.cTerrainDesc.terrains) { if (terrain.surfaceInfo == surfaceIndex) return (int)terrain.terrainIndex; } return null; } public void GenerateUV() { int count = (int)Math.Ceiling(Math.Sqrt(textureCoord.Count)); int atlasSize = (int)64 * count; int index = 0; foreach (var terrain in textureCoord) { int x = (index % count) * (int)64; int y = (index / count) * (int)64; textureCoord[index] = new Vector2(x, y); index++; } } }