Add Normal in vertex. And add light in shader.

This commit is contained in:
Troispoils 2024-02-28 17:07:45 +01:00
parent 8908ef1332
commit 0e96615b32
16 changed files with 221 additions and 85 deletions

View file

@ -1,13 +1,7 @@
using AC2RE.Definitions;
using ImageMagick;
using LandblockExtraction.DatEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace LandblockExtraction.AtlasMaker;
public class TerrainAtlasManager {
@ -15,10 +9,14 @@ public class TerrainAtlasManager {
public Dictionary<int, Vector2> textureCoord;
public Dictionary<int, MagickImage> terrainTexture;
public Dictionary<int, Terrain> terrains;
public TerrainAtlasManager(PortalEngine portalEngine) {
this.portalEngine = portalEngine;
textureCoord = new Dictionary<int, Vector2>();
terrainTexture = new Dictionary<int, MagickImage>();
terrains = new Dictionary<int, Terrain>();
testGenerateList();
}
public void ExtractTexture() {
using (var atlasBuilder = new AtlasBuilder(portalEngine)) {
@ -26,22 +24,46 @@ public class TerrainAtlasManager {
foreach (var surface in portalEngine.cSurfaceDesc.surfaces) {
if (surface.surfIndex == terrain.surfaceInfo) {
atlasBuilder.AddTexture((int)terrain.terrainIndex, surface.terrainMaterials.First().baseMaterials.First().materialDid);
//terrains.Add((int)terrain.terrainIndex, GenerateSubTerrain((int)terrain.terrainIndex, surface.terrainMaterials));
}
}
textureCoord.Add((int)terrain.terrainIndex, Vector2.Zero);
}
atlasBuilder.GenerateAtlas();
foreach(var img in atlasBuilder.textures) {
foreach (var img in atlasBuilder.textures) {
terrainTexture.Add(img.Key, img.Value);
}
}
}
/*private Terrain GenerateSubTerrain(int index, List<CSurfaceDesc.MaterialGroup> materialGroups) {
Terrain tmpTerrain = new Terrain(index);
foreach(var material in materialGroups) {
int indexTer = GetIndexBySurface(material.s)
SubTerrain subTerrain = new(ma)
}
}*/
private void testGenerateList() {
foreach(var surface in portalEngine.cSurfaceDesc.surfaces) {
foreach(var terrain in portalEngine.cTerrainDesc.terrains) {
if(surface.surfIndex == terrain.surfaceInfo) {
Console.WriteLine($"[{terrain.terrainIndex}:{terrain.terrainName}]\t- Surface: {surface.surfIndex:X8} | Base: {surface.terrainMaterials.First().baseMaterials.First().materialDid}");
}
}
}
}
private int? GetIndexBySurface(uint surfaceIndex) {
foreach(var terrain in portalEngine.cTerrainDesc.terrains) {
if (terrain.surfaceInfo == surfaceIndex)
return (int)terrain.terrainIndex;
}
return null;
}
public void GenerateUV() {
int count = (int)Math.Ceiling(Math.Sqrt(textureCoord.Count));
int atlasSize = (int)64 * count;
int index = 0;
foreach(var terrain in textureCoord) {
foreach (var terrain in textureCoord) {
int x = (index % count) * (int)64;
int y = (index / count) * (int)64;
textureCoord[index] = new Vector2(x, y);