Test with new technique texturing
This commit is contained in:
parent
bb723036c0
commit
3a7d169b30
8 changed files with 125 additions and 61 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using LandblockExtraction.AtlasMaker;
|
||||
using LandblockExtraction.DatEngine;
|
||||
using LandblockExtraction.Tools;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LandblockExtraction.LandBlockExtractor {
|
||||
|
|
@ -21,6 +22,7 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
terrainAtlasManager = new TerrainAtlasManager(portalEngine);
|
||||
terrainAtlasManager.ExtractTexture();
|
||||
terrainAtlasManager.GenerateUV();
|
||||
terrainAtlasManager.SaveAllTerrain();
|
||||
}
|
||||
|
||||
public BlockStruct? GetBlock(int landX, int landY) {
|
||||
|
|
@ -40,15 +42,72 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
blockStruct.verticesStruct.color[indice] = GenerateVertexColor(blockData.cellInfos[indice]);
|
||||
blockStruct.verticesStruct.farcolor[indice] = GenerateVertexFarColor(blockData.cellInfos[indice]);
|
||||
blockStruct.verticesStruct.terraintype[indice] = GenerateVertexTerrainType(blockData.cellInfos[indice]);
|
||||
blockStruct.verticesStruct.texturecoord[indice] = GenerateBasicUV(x, y);
|
||||
blockStruct.indices = GenerateBasicIndices();
|
||||
|
||||
}
|
||||
}
|
||||
blockStruct.verticesStruct.normal = GenerateBasicNormal(blockStruct);
|
||||
//DoubleEdgeVertices(blockStruct);
|
||||
|
||||
Dictionary<int, int> testTerr = new Dictionary<int, int>();
|
||||
foreach (var test in blockStruct.verticesStruct.terraintype) {
|
||||
var type = (int)test.X;
|
||||
if (testTerr.ContainsKey(type)) {
|
||||
testTerr[type]++;
|
||||
} else {
|
||||
testTerr.Add(type, 1);
|
||||
}
|
||||
}
|
||||
|
||||
DoubleEdgeVertices(blockStruct);
|
||||
|
||||
return blockStruct;
|
||||
}
|
||||
|
||||
private Vector2 GenerateBasicUV(int x, int y) {
|
||||
float u = (float)x / (BlockSize - 1) * 16;
|
||||
float v = (float)y / (BlockSize - 1) * 16;
|
||||
|
||||
return new Vector2(u, v);
|
||||
}
|
||||
|
||||
private Vector3[] GenerateBasicNormal(BlockStruct blockStruct) {
|
||||
Vector3[] normals = new Vector3[blockStruct.verticesStruct.position.Length];
|
||||
|
||||
// Initialise tous les vecteurs normaux à zéro
|
||||
for (int i = 0; i < normals.Length; i++) {
|
||||
normals[i] = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
// Parcourt tous les indices et calcule les normales pour chaque triangle
|
||||
for (int i = 0; i < blockStruct.indices.Length; i += 3) {
|
||||
int index1 = blockStruct.indices[i];
|
||||
int index2 = blockStruct.indices[i + 1];
|
||||
int index3 = blockStruct.indices[i + 2];
|
||||
|
||||
Vector3 vertex1 = blockStruct.verticesStruct.position[index1];
|
||||
Vector3 vertex2 = blockStruct.verticesStruct.position[index2];
|
||||
Vector3 vertex3 = blockStruct.verticesStruct.position[index3];
|
||||
|
||||
// Calcule la normale du triangle
|
||||
/*Vector3 edge1 = vertex2 - vertex1;
|
||||
Vector3 edge2 = vertex3 - vertex1;
|
||||
Vector3 normal = Vector3.Cross(edge1, edge2);
|
||||
normal = Vector3.Normalize(normal);*/
|
||||
var normal = MathOperations.CalculateTriangleNormal(vertex1, vertex2, vertex3);
|
||||
// Ajoute la normale du triangle aux normales des sommets du triangle
|
||||
normals[index1] += normal;
|
||||
normals[index2] += normal;
|
||||
normals[index3] += normal;
|
||||
}
|
||||
|
||||
// Normalise toutes les normales de sommets pour qu'elles soient de longueur unitaire
|
||||
for (int i = 0; i < normals.Length; i++) {
|
||||
normals[i] = Vector3.Normalize(normals[i]);
|
||||
}
|
||||
|
||||
return normals;
|
||||
}
|
||||
|
||||
private int[] GenerateBasicIndices() {
|
||||
List<int> indices = new List<int>();
|
||||
|
||||
|
|
@ -147,7 +206,7 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
blockStruct.verticesStruct.terraintype[foor].X));
|
||||
newRealTerrainType.Add(blockStruct.verticesStruct.terraintype[one].X);
|
||||
|
||||
newPositions.Add(blockStruct.verticesStruct.position[two]);
|
||||
/*newPositions.Add(blockStruct.verticesStruct.position[two]);
|
||||
newColors.Add(blockStruct.verticesStruct.color[two]);
|
||||
newFarColors.Add(blockStruct.verticesStruct.farcolor[two]);
|
||||
newTerrainTypes.Add(new Vector4(blockStruct.verticesStruct.terraintype[one].X,
|
||||
|
|
@ -178,7 +237,7 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
newTexCoord.Add(new(0, 0));
|
||||
newTexCoord.Add(new(0, 1));
|
||||
newTexCoord.Add(new(1, 0));
|
||||
newTexCoord.Add(new(1, 1));
|
||||
newTexCoord.Add(new(1, 1));*/
|
||||
|
||||
var normal = MathOperations.CalculateQuadNormal(blockStruct.verticesStruct.position[one],
|
||||
blockStruct.verticesStruct.position[two],
|
||||
|
|
@ -186,9 +245,9 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
blockStruct.verticesStruct.position[foor]);
|
||||
|
||||
newNormals.Add(normal);
|
||||
newNormals.Add(normal);
|
||||
newNormals.Add(normal);
|
||||
newNormals.Add(normal);
|
||||
//newNormals.Add(normal);
|
||||
//newNormals.Add(normal);
|
||||
//newNormals.Add(normal);
|
||||
}
|
||||
|
||||
// Ajouter les nouveaux sommets à la structure BlockStruct (étape 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue