Test not positif

This commit is contained in:
Troispoils 2024-03-03 19:07:02 +01:00
parent 443b3a319d
commit 7c7dddde5e
9 changed files with 286 additions and 32 deletions

View file

@ -46,11 +46,11 @@ public class TerrainAtlasManager {
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)));
tmpTer.AddSubTerrain(new(GetIndex(mat.baseMaterials.First().materialDid),
mat.minPitch,
mat.maxPitch,
MathOperations.RGBAColorToVector4(mat.vertexColor.First().vertexColor),
MathOperations.RGBAColorToVector4(mat.vertexColor.First().farVertexColor)));
}
}
}
@ -87,7 +87,7 @@ public class TerrainAtlasManager {
}
private int GetIndex(DataId id) {
foreach(var mat in mapTerrain) {
if(mat.Value == id) return mat.Key;
if(mat.Value.id == id.id) return mat.Key;
}
return 0;
}

View file

@ -65,23 +65,25 @@ namespace LandblockExtraction.LandBlockExtractor {
Vector3 vertex4 = blockStruct.verticesStruct.position[index4];
var normal = MathOperations.CalculateQuadNormal(vertex1, vertex2, vertex3, vertex4);
var test = MathOperations.CalculateInclination(normal);
var sub1 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index1].X].DetermineSubTerrain(1 - normal.Y);
var sub2 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index2].X].DetermineSubTerrain(1 - normal.Y);
var sub3 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index3].X].DetermineSubTerrain(1 - normal.Y);
var sub4 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index4].X].DetermineSubTerrain(1 - normal.Y);
var sub1 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index1].X].DetermineSubTerrain(test);
var sub2 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index2].X].DetermineSubTerrain(test);
var sub3 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index3].X].DetermineSubTerrain(test);
var sub4 = terrainAtlasManager.terrains[(int)blockStruct.verticesStruct.terraintype[index4].X].DetermineSubTerrain(test);
InitColorFarColorTerrain(index1, sub1, blockStruct);
InitColorFarColorTerrain(index2, sub2, blockStruct);
InitColorFarColorTerrain(index3, sub3, blockStruct);
InitColorFarColorTerrain(index4, sub4, blockStruct);
InitColorFarColorTerrain(index1, normal, sub1, blockStruct);
InitColorFarColorTerrain(index2, normal, sub2, blockStruct);
InitColorFarColorTerrain(index3, normal, sub3, blockStruct);
InitColorFarColorTerrain(index4, normal, sub4, blockStruct);
}
}
private void InitColorFarColorTerrain(int index, SubTerrain terrain, BlockStruct blockStruct) {
private void InitColorFarColorTerrain(int index, Vector3 normal, SubTerrain terrain, BlockStruct blockStruct) {
blockStruct.verticesStruct.terraintype[index].X = terrain.terrainIndex;
blockStruct.verticesStruct.color[index] = terrain.Color;
blockStruct.verticesStruct.farcolor[index] = terrain.farColor;
blockStruct.verticesStruct.normal[index] = normal;
}
@ -180,42 +182,34 @@ namespace LandblockExtraction.LandBlockExtractor {
newPositions.Add(blockStruct.verticesStruct.position[one]);
newColors.Add(blockStruct.verticesStruct.color[one]);
newFarColors.Add(blockStruct.verticesStruct.farcolor[one]);
newNormals.Add(blockStruct.verticesStruct.normal[one]);
newTerrainTypes.Add(terrainType);
newPositions.Add(blockStruct.verticesStruct.position[two]);
newColors.Add(blockStruct.verticesStruct.color[two]);
newFarColors.Add(blockStruct.verticesStruct.farcolor[two]);
newNormals.Add(blockStruct.verticesStruct.normal[two]);
newTerrainTypes.Add(terrainType);
newPositions.Add(blockStruct.verticesStruct.position[three]);
newColors.Add(blockStruct.verticesStruct.color[three]);
newFarColors.Add(blockStruct.verticesStruct.farcolor[three]);
newNormals.Add(blockStruct.verticesStruct.normal[three]);
newTerrainTypes.Add(terrainType);
newPositions.Add(blockStruct.verticesStruct.position[foor]);
newColors.Add(blockStruct.verticesStruct.color[foor]);
newFarColors.Add(blockStruct.verticesStruct.farcolor[foor]);
newNormals.Add(blockStruct.verticesStruct.normal[foor]);
newTerrainTypes.Add(terrainType);
newTexCoord.Add(new(0, 0));
newTexCoord.Add(new(0, 1));
newTexCoord.Add(new(1, 0));
newTexCoord.Add(new(1, 1));
var normal = MathOperations.CalculateQuadNormal(blockStruct.verticesStruct.position[one],
blockStruct.verticesStruct.position[two],
blockStruct.verticesStruct.position[three],
blockStruct.verticesStruct.position[foor]);
newNormals.Add(normal);
newNormals.Add(normal);
newNormals.Add(normal);
newNormals.Add(normal);
}
// Ajouter les nouveaux sommets à la structure BlockStruct (étape 2)
// Vous devez également mettre à jour les indices dans blockStruct.indices
blockStruct.verticesStruct.position = newPositions.ToArray();
blockStruct.verticesStruct.normal = newNormals.ToArray();
blockStruct.verticesStruct.color = newColors.ToArray();

View file

@ -41,5 +41,20 @@ namespace LandblockExtraction.Tools {
Vector3 averageNormal = (normal1 + normal2) / 2;
return Vector3.Normalize(averageNormal);
}
public static float CalculateInclination(Vector3 normal) {
Vector3 up = new Vector3(0, 0, 1); // Vecteur vertical de référence
normal = Vector3.Normalize(normal); // Normaliser la normale
float dotProduct = Vector3.Dot(normal, up); // Produit scalaire entre la normale et le vecteur vertical
// Calculer le cosinus de l'angle
float cosTheta = dotProduct;
// Calculer le sinus de l'angle à partir du cosinus
float sinTheta = (float)Math.Sqrt(1 - cosTheta * cosTheta);
return sinTheta; // Retourner l'angle d'inclinaison variant de 0 à 1
}
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace LandblockExtraction.WorldMap;
public struct VertexMap {
public Vector3 Position;
public Vector4 Color;
}

View file

@ -0,0 +1,165 @@
using AC2RE.Definitions;
using LandblockExtraction.AtlasMaker;
using LandblockExtraction.DatEngine;
using LandblockExtraction.Tools;
using System.Numerics;
namespace LandblockExtraction.WorldMap;
public class WorldMap {
private readonly int NumberLandBlocks = 254;
private readonly int BlockSize = 17;
private readonly int cellSize = 8;
private PortalEngine portalEngine;
private CellEngine cellEngine;
private TerrainAtlasManager terrainAtlasManager;
private VertexMap[,] vertexMaps;
public WorldMap(PortalEngine portalEngine, CellEngine cellEngine) {
this.portalEngine = portalEngine;
this.cellEngine = cellEngine;
terrainAtlasManager = new TerrainAtlasManager(portalEngine);
int globalSize = NumberLandBlocks * (BlockSize - 1);
vertexMaps = new VertexMap[globalSize, globalSize];
}
private void InitializeBaseMap() {
for (int landY = 0; landY <= NumberLandBlocks; landY++) {
for (int landX = 0; landX <= NumberLandBlocks; landX++) {
InitializeCellMap(landY, landX);
}
}
}
public void LoadRegion(int start, int end) {
for (int landY = start; landY <= end; landY++) {
for (int landX = start; landX <= end; landX++) {
InitializeCellMap(landY, landX);
}
}
}
private void InitializeCellMap(int landx, int landy) {
CellId landBlockId = new CellId((byte)landx, (byte)landy, 0xFF, 0xFF);
var landBlock = cellEngine.GetLandBlockData(landBlockId.id);
for (int y = 0; y < BlockSize; y++) {
for (int x = 0; x < BlockSize; x++) {
float height = 0;
Vector4 color = Vector4.Zero;
// Calculer les indices globaux en prenant en compte la position du land
int indiceX = landx * (BlockSize - 1) + y;
int indiceY = landy * (BlockSize - 1) + x;
if (landBlock != null) {
height = GetHeightInLandBlock(landBlock, x, y);
color = GetColorVertex(landBlock, x, y);
}
// Vérifier si les indices ne dépassent pas la taille globale de la grille
if (indiceX < NumberLandBlocks * (BlockSize - 1) && indiceY < NumberLandBlocks * (BlockSize - 1)) {
vertexMaps[indiceX, indiceY] = new VertexMap() {
Position = GenerateVertexPosition(landx, landy, x, y, height),
Color = color
};
}
}
}
}
private float GetHeightInLandBlock(CLandBlockData block, int x, int y) {
var indice = y * BlockSize + x;
return block.heights[indice];
}
private Vector4 GetColorVertex(CLandBlockData block, int x, int y) {
var indice = y * BlockSize + x;
var terrain = MathOperations.GetTerrainInCellInfo(block.cellInfos[indice]);
return terrainAtlasManager.terrains[(int)terrain].subTerrains.First().Color;
}
public float[] GetAllVertices() {
List<float> verticesList = new List<float>();
int rowLength = NumberLandBlocks * (BlockSize - 1);
for (int y = 0; y < rowLength; y++) {
for (int x = 0; x < rowLength; x++) {
// Ajouter la position du vertex à la liste
verticesList.Add(vertexMaps[x, y].Position.X);
verticesList.Add(vertexMaps[x, y].Position.Y);
verticesList.Add(vertexMaps[x, y].Position.Z);
// Ajouter la couleur si nécessaire
verticesList.Add(vertexMaps[x, y].Color.X);
verticesList.Add(vertexMaps[x, y].Color.Y);
verticesList.Add(vertexMaps[x, y].Color.Z);
verticesList.Add(vertexMaps[x, y].Color.W);
}
}
return verticesList.ToArray();
}
public int[] GenerateRegionIndices(int start, int end) {
List<int> indices = new List<int>();
// Calcul de la longueur de la ligne pour la région spécifiée
int rowLength = (end - start) * (BlockSize - 1);
// Parcours de chaque "cellule" de la grille pour la région spécifiée
for (int y = 0; y < rowLength; y++) {
for (int x = 0; x < rowLength; x++) {
int baseX = start * (BlockSize - 1);
int baseY = start * (BlockSize - 1);
int topLeft = (y + baseY) * (NumberLandBlocks * (BlockSize - 1)) + (x + baseX);
int topRight = topLeft + 1;
int bottomLeft = topLeft + (NumberLandBlocks * (BlockSize - 1));
int bottomRight = bottomLeft + 1;
indices.Add(topLeft);
indices.Add(bottomLeft);
indices.Add(bottomRight);
indices.Add(bottomLeft);
indices.Add(bottomRight);
indices.Add(topRight);
}
}
return indices.ToArray();
}
public int[] GenerateIndices() {
List<int> indices = new List<int>();
int rowLength = NumberLandBlocks * (BlockSize - 1);
// Parcourir chaque "cellule" de la grille, sauf la dernière colonne et la dernière ligne
for (int y = 0; y < rowLength - 1; y++) {
for (int x = 0; x < rowLength - 1; x++) {
// Calculer les indices des 4 sommets du carré courant
int topLeft = y * rowLength + x;
int topRight = topLeft + 1;
int bottomLeft = topLeft + rowLength;
int bottomRight = bottomLeft + 1;
// Ajouter les indices pour former les deux triangles
indices.Add(topLeft);
indices.Add(bottomLeft);
indices.Add(bottomRight);
indices.Add(bottomLeft);
indices.Add(bottomRight);
indices.Add(topRight);
}
}
return indices.ToArray();
}
private Vector3 GenerateVertexPosition(int landx, int landy, int x, int y, float height) {
int tmpx = (landx * BlockSize + y) * cellSize;
int tmpy = (BlockSize * NumberLandBlocks * cellSize) - ((landy * BlockSize + x) * cellSize) - 1;
var newX = (tmpx - (NumberLandBlocks * BlockSize * cellSize / 2)) - landx * cellSize;// (tmpx - (NumberLandBlocks * BlockSize * cellSize / 2));
var newY = (tmpy - ((NumberLandBlocks * BlockSize * cellSize) - (NumberLandBlocks * BlockSize * cellSize / 2) - 1)) + landy * cellSize; //(tmpy - ((NumberLandBlocks * BlockSize * cellSize) - (NumberLandBlocks * BlockSize * cellSize / 2) - 1));
return new Vector3(newX + 1020, height, newY - 1020);
}
}