map3drendering/LandblockExtraction/AtlasMaker/TerrainAtlasManager.cs
Troispoils 664eb5872a Success to blend 4 texture
Need improuve for angle.
2024-02-27 20:57:37 +01:00

51 lines
1.8 KiB
C#

using AC2RE.Definitions;
using ImageMagick;
using LandblockExtraction.DatEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace LandblockExtraction.AtlasMaker;
public class TerrainAtlasManager {
private PortalEngine portalEngine;
public Dictionary<int, Vector2> textureCoord;
public Dictionary<int, MagickImage> terrainTexture;
public TerrainAtlasManager(PortalEngine portalEngine) {
this.portalEngine = portalEngine;
textureCoord = new Dictionary<int, Vector2>();
terrainTexture = new Dictionary<int, MagickImage>();
}
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);
}
}
textureCoord.Add((int)terrain.terrainIndex, Vector2.Zero);
}
atlasBuilder.GenerateAtlas();
foreach(var img in atlasBuilder.textures) {
terrainTexture.Add(img.Key, img.Value);
}
}
}
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++;
}
}
}