Test array texture

This commit is contained in:
Troispoils 2024-03-01 14:03:04 +01:00
parent 2b62d3b9e4
commit 51325d8650
4 changed files with 80 additions and 22 deletions

View file

@ -42,11 +42,12 @@ 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.verticesStruct.texturecoord[indice] = GenerateUVForSubTile(x, y);
blockStruct.indices = GenerateBasicIndices();
}
}
//blockStruct.verticesStruct.texturecoord = GenerateBasicUVTest(blockStruct);
blockStruct.verticesStruct.normal = GenerateBasicNormal(blockStruct);
//DoubleEdgeVertices(blockStruct);
@ -69,7 +70,37 @@ namespace LandblockExtraction.LandBlockExtractor {
return new Vector2(u, v);
}
private Vector2 GenerateUVForSubTile(int x, int y) {
// Taille d'une "mini-tuile" en termes de coordonnées UV
float miniTileSize = 1f / BlockSize - 1; // Comme la sous-grille est 5x5
// Calcul des coordonnées UV basées sur la position (x, y) dans la sous-grille
float u = x * miniTileSize;
float v = y * miniTileSize;
return new Vector2(u, v);
}
private Vector2[] GenerateBasicUVTest(BlockStruct blockStruct) {
Vector2[] uvs = new Vector2[blockStruct.verticesStruct.position.Length];
for (int i = 0; i < uvs.Length; i++) {
uvs[i] = new Vector2(0, 0);
}
for (int i = 0; i < blockStruct.indices.Length; i += 6) {
int index1 = blockStruct.indices[i];
int index2 = blockStruct.indices[i + 1];
int index3 = blockStruct.indices[i + 2];
int index4 = blockStruct.indices[i + 5];
uvs[index1] = new(0, 0);
uvs[index2] = new(0, 1);
uvs[index3] = new(1, 0);
uvs[index4] = new(1, 1);
}
return uvs;
}
private Vector3[] GenerateBasicNormal(BlockStruct blockStruct) {
Vector3[] normals = new Vector3[blockStruct.verticesStruct.position.Length];