using System; using System.Numerics; namespace LandblockExtraction.LandBlockExtractor { public class BlockStruct { public readonly static int BlockSize = 17; public VerticesStruct verticesStruct; public int[] indices; public BlockStruct() { verticesStruct = new VerticesStruct(BlockSize); indices = new int[(BlockSize - 1) * (BlockSize - 1) * 6]; } public void GenerateIndices() { int index = 0; for (int y = 0; y < BlockSize - 1; y++) { for (int x = 0; x < BlockSize - 1; x++) { // Indices des sommets du premier triangle indices[index++] = y * BlockSize + x; indices[index++] = (y + 1) * BlockSize + x; indices[index++] = y * BlockSize + x + 1; // Indices des sommets du deuxième triangle indices[index++] = y * BlockSize + x + 1; indices[index++] = (y + 1) * BlockSize + x; indices[index++] = (y + 1) * BlockSize + x + 1; } } } public void GenerateUVByIndices() { // Calculer les UV en fonction de la position de chaque sommet for (int y = 0; y < BlockSize; y++) { for (int x = 0; x < BlockSize; x++) { // Indices des sommets du premier triangle //float u = ((float)x / (BlockSize - 1)) * 16; //float v = ((float)y / (BlockSize - 1)) * 16; // Définir la position de la texture dans l'atlas int textureIndexX = 1; // Deuxième colonne int textureIndexY = 0; // Première ligne int atlasSize = 4; // L'atlas contient 4x4 textures // Calculer le décalage dans l'atlas pour la texture ciblée float offsetX = (float)textureIndexX / atlasSize; float offsetY = (float)textureIndexY / atlasSize; // Calculer la taille d'une texture dans l'atlas float textureSize = 1.0f / atlasSize; // Calculer les coordonnées UV pour la répétition float u = ((float)x / (BlockSize - 1)) * 16 * textureSize + offsetX; float v = ((float)y / (BlockSize - 1)) * 16 * textureSize + offsetY; verticesStruct.texturecoord[y * BlockSize + x] = new(u, v); } } } } }