Mise à jour du dépôt en fonction du .gitignore

This commit is contained in:
Troispoils 2024-02-25 22:03:08 +01:00
parent 1f0f033fad
commit 4a59748e67
224 changed files with 6785 additions and 0 deletions

View file

@ -0,0 +1,83 @@
using AC2RE.Definitions;
using LandblockExtraction.DatEngine;
using LandblockExtraction.Tools;
using System.Numerics;
namespace LandblockExtraction.LandBlockExtractor {
public class LandBlockExtrator {
private PortalEngine portalEngine;
private CellEngine cellEngine;
private readonly int NumberLandBlocks = 255;
private readonly int BlockSize = 17;
private readonly int cellSize = 8;
public LandBlockExtrator(PortalEngine portalEngine, CellEngine cellEngine) {
this.portalEngine = portalEngine;
this.cellEngine = cellEngine;
}
public BlockStruct? GetBlock(int landX, int landY) {
CellId landBlockId = new CellId((byte)landX, (byte)landY, 0xFF, 0xFF);
var landBlock = cellEngine.GetLandBlockData(landBlockId.id);
if (landBlock == null) return null;
return GenerateBlockStructByData(landBlock, landX, landY);
}
public BlockStruct GenerateBlockStructByData(CLandBlockData blockData, int landX, int landY) {
BlockStruct blockStruct = new BlockStruct();
for (int y = 0; y < BlockStruct.BlockSize; y++) {
for (int x = 0; x < BlockStruct.BlockSize; x++) {
var indice = y * BlockStruct.BlockSize + x;
blockStruct.verticesStruct.position[indice] = GenerateVertexPosition(landX, landY, x, y, blockData.heights[indice]);
blockStruct.verticesStruct.color[indice] = GenerateVertexColor(blockData.cellInfos[indice]);
blockStruct.verticesStruct.farcolor[indice] = GenerateVertexFarColor(blockData.cellInfos[indice]);
blockStruct.GenerateIndices();
}
}
return blockStruct;
}
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;
var newX = (tmpx - (NumberLandBlocks * BlockSize * cellSize / 2));
var newY = (tmpy - ((NumberLandBlocks * BlockSize * cellSize) - (NumberLandBlocks * BlockSize * cellSize / 2) - 1));
return new Vector3(newX, portalEngine.landScapeDefs.landHeightTable[height], newY);
}
private Vector4 GenerateVertexColor(uint cellInfo) {
var terrain = MathOperations.GetTerrainInCellInfo(cellInfo);
foreach (var terrainType in portalEngine.cTerrainDesc.terrains) {
if (terrainType.terrainIndex == terrain) {
foreach (var surfaceIndex in portalEngine.cSurfaceDesc.surfaces) {
if (surfaceIndex.surfIndex == terrainType.surfaceInfo) {
var color = surfaceIndex.terrainMaterials.First().vertexColor.First().vertexColor;
return MathOperations.RGBAColorToVector4(color);
}
}
}
}
return Vector4.One;
}
private Vector4 GenerateVertexFarColor(uint cellInfo) {
var terrain = MathOperations.GetTerrainInCellInfo(cellInfo);
foreach (var terrainType in portalEngine.cTerrainDesc.terrains) {
if (terrainType.terrainIndex == terrain) {
foreach (var surfaceIndex in portalEngine.cSurfaceDesc.surfaces) {
if (surfaceIndex.surfIndex == terrainType.surfaceInfo) {
var color = surfaceIndex.terrainMaterials.First().vertexColor.First().farVertexColor;
return MathOperations.RGBAColorToVector4(color);
}
}
}
}
return Vector4.One;
}
}
}

View file

@ -0,0 +1,30 @@
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;
}
}
}
}
}

View file

@ -0,0 +1,34 @@
using System.Numerics;
namespace LandblockExtraction.LandBlockExtractor {
public class VerticesStruct {
public Vector3[] position { get; set; }
public Vector4[] color { get; set; }
public Vector4[] farcolor { get; set; }
public VerticesStruct(int blockSize) {
position = new Vector3[blockSize * blockSize];
color = new Vector4[blockSize * blockSize];
farcolor = new Vector4[blockSize * blockSize];
}
public float[] Vertices() {
int length = position.Length;
float[] vertices = new float[length * 11]; // 3 pour position, 4 pour color, et 4 pour farcolor
for (int i = 0, vi = 0; i < length; i++, vi += 11) {
vertices[vi] = position[i].X;
vertices[vi + 1] = position[i].Y;
vertices[vi + 2] = position[i].Z;
vertices[vi + 3] = color[i].X;
vertices[vi + 4] = color[i].Y;
vertices[vi + 5] = color[i].Z;
vertices[vi + 6] = color[i].W;
vertices[vi + 7] = farcolor[i].X;
vertices[vi + 8] = farcolor[i].Y;
vertices[vi + 9] = farcolor[i].Z;
vertices[vi + 10] = farcolor[i].W;
}
return vertices;
}
}
}