Add Normal in vertex. And add light in shader.
This commit is contained in:
parent
8908ef1332
commit
0e96615b32
16 changed files with 221 additions and 85 deletions
|
|
@ -1,12 +1,6 @@
|
|||
using AC2RE.Definitions;
|
||||
using ImageMagick;
|
||||
using LandblockExtraction.DatEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LandblockExtraction.AtlasMaker;
|
||||
public class AtlasBuilder : IDisposable {
|
||||
|
|
@ -21,7 +15,7 @@ public class AtlasBuilder : IDisposable {
|
|||
|
||||
public bool AddTexture(int index, DataId matId) {
|
||||
var img = texturesImage.GetImage(matId);
|
||||
if(img == null) return false;
|
||||
if (img == null) return false;
|
||||
textures.Add(index, img);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -41,7 +35,7 @@ public class AtlasBuilder : IDisposable {
|
|||
int x = (index % count) * (int)TEXTURESIZE;
|
||||
int y = (index / count) * (int)TEXTURESIZE;
|
||||
atlas.Composite(kvp.Value, x, y);
|
||||
|
||||
|
||||
index++;
|
||||
if (index >= count * count) break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
15
LandblockExtraction/AtlasMaker/TerrainInfo/SubTerrain.cs
Normal file
15
LandblockExtraction/AtlasMaker/TerrainInfo/SubTerrain.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
namespace LandblockExtraction.AtlasMaker;
|
||||
|
||||
public class SubTerrain {
|
||||
public int terrainIndex { get; set; }
|
||||
public float minPitch { get; set; }
|
||||
public float maxPitch { get; set; }
|
||||
public SubTerrain(int terrainIndex, float minPitch, float maxPitch) {
|
||||
this.terrainIndex = terrainIndex;
|
||||
this.minPitch = minPitch;
|
||||
this.maxPitch = maxPitch;
|
||||
}
|
||||
public bool MatchesPitch(float pitch) {
|
||||
return pitch >= minPitch && pitch <= maxPitch;
|
||||
}
|
||||
}
|
||||
22
LandblockExtraction/AtlasMaker/TerrainInfo/Terrain.cs
Normal file
22
LandblockExtraction/AtlasMaker/TerrainInfo/Terrain.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
namespace LandblockExtraction.AtlasMaker;
|
||||
public class Terrain {
|
||||
public int terrainIndex { get; set; }
|
||||
public List<SubTerrain> subTerrains { get; set; }
|
||||
|
||||
public Terrain(int index) {
|
||||
terrainIndex = index;
|
||||
subTerrains = new List<SubTerrain>();
|
||||
}
|
||||
public void AddSubTerrain(SubTerrain sousTerrain) {
|
||||
subTerrains.Add(sousTerrain);
|
||||
}
|
||||
|
||||
public int DetermineSubTerrain(float pitch) {
|
||||
foreach (var terrain in subTerrains) {
|
||||
if (terrain.MatchesPitch(pitch)) {
|
||||
return terrain.terrainIndex;
|
||||
}
|
||||
}
|
||||
return terrainIndex;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,11 +2,6 @@
|
|||
using ImageMagick;
|
||||
using LandblockExtraction.DatEngine;
|
||||
using LandblockExtraction.Tools;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LandblockExtraction.AtlasMaker;
|
||||
public class TexturesImage {
|
||||
|
|
@ -19,10 +14,10 @@ public class TexturesImage {
|
|||
}
|
||||
|
||||
public MagickImage? GetImage(DataId matId) {
|
||||
if(!portalEngine.datReader.contains(matId)) return null;
|
||||
using(var data = portalEngine.datReader.getFileReader(matId)) {
|
||||
if (!portalEngine.datReader.contains(matId)) return null;
|
||||
using (var data = portalEngine.datReader.getFileReader(matId)) {
|
||||
var materialLayer = new RenderMaterial(data);
|
||||
if(materialLayer == null) return null;
|
||||
if (materialLayer == null) return null;
|
||||
|
||||
return ImageInMaterial(materialLayer);
|
||||
}
|
||||
|
|
@ -30,10 +25,10 @@ public class TexturesImage {
|
|||
|
||||
private MagickImage? ImageInMaterial(RenderMaterial materialLayer) {
|
||||
var vdescId = materialLayer.layers.First().stages.First().textureID;
|
||||
if(!portalEngine.datReader.contains(new(vdescId))) return null;
|
||||
using(var data = portalEngine.datReader.getFileReader(new(vdescId))) {
|
||||
if (!portalEngine.datReader.contains(new(vdescId))) return null;
|
||||
using (var data = portalEngine.datReader.getFileReader(new(vdescId))) {
|
||||
var texture = new RenderTexture(data);
|
||||
if(texture == null) return null;
|
||||
if (texture == null) return null;
|
||||
return TextureInRender(texture);
|
||||
}
|
||||
|
||||
|
|
@ -41,13 +36,13 @@ public class TexturesImage {
|
|||
|
||||
private MagickImage? TextureInRender(RenderTexture texture) {
|
||||
MagickImage magickImage;
|
||||
foreach(var img in texture.levelSurfaceDids) {
|
||||
if(!portalEngine.datReader.contains(img)) continue;
|
||||
using(var data = portalEngine.datReader.getFileReader(img)) {
|
||||
foreach (var img in texture.levelSurfaceDids) {
|
||||
if (!portalEngine.datReader.contains(img)) continue;
|
||||
using (var data = portalEngine.datReader.getFileReader(img)) {
|
||||
var image = new RenderSurface(data);
|
||||
if(image.width != 64) continue;
|
||||
if (image.width != 64) continue;
|
||||
var dataImg = DDSHeader.Generate(image);
|
||||
using(MagickImage realImg = new MagickImage(dataImg)) {
|
||||
using (MagickImage realImg = new MagickImage(dataImg)) {
|
||||
magickImage = new(realImg);
|
||||
}
|
||||
return magickImage;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue