better system for texture terrain.
This commit is contained in:
parent
3aa6b5bc83
commit
443b3a319d
9 changed files with 120 additions and 69 deletions
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
namespace LandblockExtraction.AtlasMaker;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LandblockExtraction.AtlasMaker;
|
||||
|
||||
public class SubTerrain {
|
||||
public int terrainIndex { get; set; }
|
||||
public float minPitch { get; set; }
|
||||
public float maxPitch { get; set; }
|
||||
public SubTerrain(int terrainIndex, float minPitch, float maxPitch) {
|
||||
public Vector4 Color { get; set; }
|
||||
public Vector4 farColor { get; set; }
|
||||
public SubTerrain(int terrainIndex, float minPitch, float maxPitch, Vector4 color, Vector4 farcolor) {
|
||||
this.terrainIndex = terrainIndex;
|
||||
this.minPitch = minPitch;
|
||||
this.maxPitch = maxPitch;
|
||||
this.Color = color;
|
||||
this.farColor = farcolor;
|
||||
}
|
||||
public bool MatchesPitch(float pitch) {
|
||||
return pitch >= minPitch && pitch <= maxPitch;
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ public class Terrain {
|
|||
subTerrains.Add(sousTerrain);
|
||||
}
|
||||
|
||||
public int DetermineSubTerrain(float pitch) {
|
||||
public SubTerrain DetermineSubTerrain(float pitch) {
|
||||
foreach (var terrain in subTerrains) {
|
||||
if (terrain.MatchesPitch(pitch)) {
|
||||
return terrain.terrainIndex;
|
||||
return terrain;
|
||||
}
|
||||
}
|
||||
return terrainIndex;
|
||||
return subTerrains.First();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue