better system for texture terrain.

This commit is contained in:
Troispoils 2024-03-01 21:56:18 +01:00
parent 3aa6b5bc83
commit 443b3a319d
9 changed files with 120 additions and 69 deletions

View file

@ -1,22 +1,26 @@
using AC2RE.Definitions;
using ImageMagick;
using LandblockExtraction.DatEngine;
using LandblockExtraction.Tools;
using System.Numerics;
namespace LandblockExtraction.AtlasMaker;
public class TerrainAtlasManager {
private PortalEngine portalEngine;
private Dictionary<int, DataId> mapTerrain;
public Dictionary<int, Vector2> textureCoord;
public Dictionary<int, MagickImage> terrainTexture;
public Dictionary<int, Terrain> terrains;
public TerrainAtlasManager(PortalEngine portalEngine) {
this.portalEngine = portalEngine;
mapTerrain = new();
textureCoord = new Dictionary<int, Vector2>();
terrainTexture = new Dictionary<int, MagickImage>();
terrains = new Dictionary<int, Terrain>();
testGenerateList();
InitialiseTerrainDic();
GenerateTerrain();
}
public void ExtractTexture() {
using (var atlasBuilder = new AtlasBuilder(portalEngine)) {
@ -36,27 +40,56 @@ public class TerrainAtlasManager {
}
}
}
/*private Terrain GenerateSubTerrain(int index, List<CSurfaceDesc.MaterialGroup> materialGroups) {
Terrain tmpTerrain = new Terrain(index);
foreach(var material in materialGroups) {
int indexTer = GetIndexBySurface(material.s)
SubTerrain subTerrain = new(ma)
private void GenerateTerrain() {
foreach(var terrain in portalEngine.cTerrainDesc.terrains) {
Terrain tmpTer = new((int)terrain.terrainIndex);
foreach(var surface in portalEngine.cSurfaceDesc.surfaces) {
if(terrain.surfaceInfo == surface.surfIndex) {
foreach(var mat in surface.terrainMaterials) {
tmpTer.subTerrains.Add(new(GetIndex(mat.baseMaterials.First().materialDid),
mat.minPitch,
mat.maxPitch,
MathOperations.RGBAColorToVector4(mat.vertexColor.First().vertexColor),
MathOperations.RGBAColorToVector4(mat.vertexColor.First().farVertexColor)));
}
}
}
terrains.Add((int)terrain.terrainIndex, tmpTer);
Console.WriteLine("Init: " + terrain.terrainIndex);
}
}*/
private void testGenerateList() {
foreach(var surfaces in portalEngine.cSurfaceDesc.surfaces) {
Console.WriteLine($"{surfaces.surfIndex} :");
foreach( var surface in surfaces.terrainMaterials) {
Console.WriteLine($"\t[{surface.minPitch} < {surface.maxPitch}]({surface.baseMaterials.First().materialDid}) - Vec3: {surface.vertexColor.First().vertexColor}");
}
private void testGenerateList() {
foreach (var terrain in portalEngine.cTerrainDesc.terrains) {
foreach (var surfaces in portalEngine.cSurfaceDesc.surfaces) {
if (surfaces.surfIndex != terrain.surfaceInfo) continue;
foreach (var surface in surfaces.terrainMaterials) {
uint test = 0;
//foreach(var m in map) { if (m.Key == surface.baseMaterials.First().materialDid) test = m.Value; }
Console.Write($"({test})[{terrain.terrainName}]{surfaces.surfIndex} :");
Console.WriteLine($"\t[{surface.minPitch} < {surface.maxPitch}]({surface.baseMaterials.First().materialDid}) - Vec3: {surface.vertexColor.First().vertexColor}");
}
Console.WriteLine("--------");
}
}
}
private int? GetIndexBySurface(uint surfaceIndex) {
private void InitialiseTerrainDic() {
foreach(var terrain in portalEngine.cTerrainDesc.terrains) {
if (terrain.surfaceInfo == surfaceIndex)
return (int)terrain.terrainIndex;
foreach (var surface in portalEngine.cSurfaceDesc.surfaces) {
if (terrain.surfaceInfo == surface.surfIndex) {
var id = surface.terrainMaterials.First().baseMaterials.First().materialDid;
mapTerrain.Add((int)terrain.terrainIndex, id);
break;
}
}
}
return null;
}
private int GetIndex(DataId id) {
foreach(var mat in mapTerrain) {
if(mat.Value == id) return mat.Key;
}
return 0;
}
public void GenerateUV() {
int count = (int)Math.Ceiling(Math.Sqrt(textureCoord.Count));