Update for AtlasBuilder ok
Need to improuve duplicate vertex for mapping texture.
This commit is contained in:
parent
4777783ffb
commit
b9a2b87fe9
11 changed files with 160 additions and 33 deletions
|
|
@ -1,12 +1,15 @@
|
|||
using AC2RE.Definitions;
|
||||
using LandblockExtraction.AtlasMaker;
|
||||
using LandblockExtraction.DatEngine;
|
||||
using LandblockExtraction.Tools;
|
||||
using System.Dynamic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LandblockExtraction.LandBlockExtractor {
|
||||
public class LandBlockExtrator {
|
||||
private PortalEngine portalEngine;
|
||||
private CellEngine cellEngine;
|
||||
private TerrainAtlasManager terrainAtlasManager;
|
||||
|
||||
private readonly int NumberLandBlocks = 255;
|
||||
private readonly int BlockSize = 17;
|
||||
|
|
@ -15,6 +18,11 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
public LandBlockExtrator(PortalEngine portalEngine, CellEngine cellEngine) {
|
||||
this.portalEngine = portalEngine;
|
||||
this.cellEngine = cellEngine;
|
||||
|
||||
terrainAtlasManager = new TerrainAtlasManager(portalEngine);
|
||||
terrainAtlasManager.ExtractTexture();
|
||||
terrainAtlasManager.GenerateAtlas();
|
||||
terrainAtlasManager.GenerateUV();
|
||||
}
|
||||
|
||||
public BlockStruct? GetBlock(int landX, int landY) {
|
||||
|
|
@ -34,11 +42,65 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
blockStruct.verticesStruct.color[indice] = GenerateVertexColor(blockData.cellInfos[indice]);
|
||||
blockStruct.verticesStruct.farcolor[indice] = GenerateVertexFarColor(blockData.cellInfos[indice]);
|
||||
blockStruct.GenerateIndices();
|
||||
//blockStruct.GenerateUVByIndices();
|
||||
GenerateVertexTextureCoord(blockData, blockStruct);
|
||||
}
|
||||
}
|
||||
|
||||
return blockStruct;
|
||||
}
|
||||
|
||||
private void GenerateVertexTextureCoord(CLandBlockData blockData, BlockStruct blockStruct) {
|
||||
List<Vector3> vertices = new List<Vector3>(); // Liste pour stocker les positions des sommets dupliqués
|
||||
List<Vector4> colors = new List<Vector4>();
|
||||
List<Vector4> farcolors = new List<Vector4>();
|
||||
List<Vector2> uvs = new List<Vector2>(); // Liste pour stocker les coordonnées UV
|
||||
List<int> indices = new List<int>(); // Liste pour stocker les nouveaux indices
|
||||
|
||||
for (int y = 0; y < blockStruct.indices.Length; y = y + 6) {
|
||||
// Créez 4 sommets
|
||||
vertices.Add(blockStruct.verticesStruct.position[blockStruct.indices[y]]);
|
||||
vertices.Add(blockStruct.verticesStruct.position[blockStruct.indices[y + 1]]);
|
||||
vertices.Add(blockStruct.verticesStruct.position[blockStruct.indices[y + 2]]);
|
||||
vertices.Add(blockStruct.verticesStruct.position[blockStruct.indices[y + 5]]);
|
||||
|
||||
// Créez 4 color
|
||||
colors.Add(blockStruct.verticesStruct.color[blockStruct.indices[y]]);
|
||||
colors.Add(blockStruct.verticesStruct.color[blockStruct.indices[y + 1]]);
|
||||
colors.Add(blockStruct.verticesStruct.color[blockStruct.indices[y + 2]]);
|
||||
colors.Add(blockStruct.verticesStruct.color[blockStruct.indices[y + 5]]);
|
||||
|
||||
// Créez 4 farcolor
|
||||
farcolors.Add(blockStruct.verticesStruct.farcolor[blockStruct.indices[y]]);
|
||||
farcolors.Add(blockStruct.verticesStruct.farcolor[blockStruct.indices[y + 1]]);
|
||||
farcolors.Add(blockStruct.verticesStruct.farcolor[blockStruct.indices[y + 2]]);
|
||||
farcolors.Add(blockStruct.verticesStruct.farcolor[blockStruct.indices[y + 5]]);
|
||||
|
||||
// Assignez les coordonnées UV à chaque sommet
|
||||
uvs.Add(new Vector2(0, 0)); // Coin inférieur gauche
|
||||
uvs.Add(new Vector2(1, 0)); // Coin inférieur droit
|
||||
uvs.Add(new Vector2(0, 1)); // Coin supérieur gauche
|
||||
uvs.Add(new Vector2(1, 1)); // Coin supérieur droit
|
||||
|
||||
// Créez les indices pour les deux triangles du quad
|
||||
int baseIndex = (y / 6) * 4; // Calculez l'index de base pour ce quad
|
||||
indices.Add(baseIndex);
|
||||
indices.Add(baseIndex + 1);
|
||||
indices.Add(baseIndex + 2);
|
||||
|
||||
indices.Add(baseIndex + 2);
|
||||
indices.Add(baseIndex + 1);
|
||||
indices.Add(baseIndex + 3);
|
||||
}
|
||||
|
||||
// Mettez à jour le BlockStruct avec les nouvelles listes de sommets, UVs, et indices
|
||||
Console.WriteLine(indices.Count);
|
||||
blockStruct.verticesStruct.position = vertices.ToArray();
|
||||
blockStruct.verticesStruct.color = colors.ToArray();
|
||||
blockStruct.verticesStruct.farcolor = farcolors.ToArray();
|
||||
blockStruct.verticesStruct.texturecoord = uvs.ToArray();
|
||||
blockStruct.indices = indices.ToArray();
|
||||
}
|
||||
private Vector3 GenerateVertexPosition(int landx, int landy, int x, int y, byte height) {
|
||||
int tmpx = (landx * BlockSize + y) * cellSize;
|
||||
int tmpy = (BlockSize * NumberLandBlocks * cellSize) - ((landy * BlockSize + x) * cellSize) - 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue