Success to blend 4 texture
Need improuve for angle.
This commit is contained in:
parent
b9a2b87fe9
commit
664eb5872a
8 changed files with 186 additions and 105 deletions
|
|
@ -9,23 +9,27 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace LandblockExtraction.AtlasMaker;
|
||||
public class AtlasBuilder {
|
||||
public class AtlasBuilder : IDisposable {
|
||||
private readonly int TEXTURESIZE = 64;
|
||||
private TexturesImage texturesImage;
|
||||
private List<MagickImage> textures;
|
||||
public Dictionary<int, MagickImage> textures;
|
||||
|
||||
public AtlasBuilder(PortalEngine portalEngine) {
|
||||
textures = new();
|
||||
texturesImage = new TexturesImage(portalEngine);
|
||||
}
|
||||
|
||||
public bool AddTexture(DataId matId) {
|
||||
public bool AddTexture(int index, DataId matId) {
|
||||
var img = texturesImage.GetImage(matId);
|
||||
if(img == null) return false;
|
||||
textures.Add(img);
|
||||
textures.Add(index, img);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
textures.Clear();
|
||||
}
|
||||
|
||||
public void GenerateAtlas() {
|
||||
int count = (int)Math.Ceiling(Math.Sqrt(textures.Count));
|
||||
int atlasSize = (int)TEXTURESIZE * count;
|
||||
|
|
@ -36,7 +40,7 @@ public class AtlasBuilder {
|
|||
foreach (var kvp in textures) {
|
||||
int x = (index % count) * (int)TEXTURESIZE;
|
||||
int y = (index / count) * (int)TEXTURESIZE;
|
||||
atlas.Composite(kvp, x, y);
|
||||
atlas.Composite(kvp.Value, x, y);
|
||||
|
||||
index++;
|
||||
if (index >= count * count) break;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using AC2RE.Definitions;
|
||||
using ImageMagick;
|
||||
using LandblockExtraction.DatEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -11,28 +12,31 @@ using System.Threading.Tasks;
|
|||
namespace LandblockExtraction.AtlasMaker;
|
||||
public class TerrainAtlasManager {
|
||||
private PortalEngine portalEngine;
|
||||
private AtlasBuilder atlasBuilder;
|
||||
|
||||
public Dictionary<int, Vector2> textureCoord;
|
||||
|
||||
public Dictionary<int, MagickImage> terrainTexture;
|
||||
public TerrainAtlasManager(PortalEngine portalEngine) {
|
||||
this.portalEngine = portalEngine;
|
||||
textureCoord = new Dictionary<int, Vector2>();
|
||||
atlasBuilder = new AtlasBuilder(portalEngine);
|
||||
terrainTexture = new Dictionary<int, MagickImage>();
|
||||
}
|
||||
public void ExtractTexture() {
|
||||
foreach(var terrain in portalEngine.cTerrainDesc.terrains) {
|
||||
foreach(var surface in portalEngine.cSurfaceDesc.surfaces) {
|
||||
if(surface.surfIndex == terrain.surfaceInfo) {
|
||||
atlasBuilder.AddTexture(surface.terrainMaterials.First().baseMaterials.First().materialDid);
|
||||
using (var atlasBuilder = new AtlasBuilder(portalEngine)) {
|
||||
foreach (var terrain in portalEngine.cTerrainDesc.terrains) {
|
||||
foreach (var surface in portalEngine.cSurfaceDesc.surfaces) {
|
||||
if (surface.surfIndex == terrain.surfaceInfo) {
|
||||
atlasBuilder.AddTexture((int)terrain.terrainIndex, surface.terrainMaterials.First().baseMaterials.First().materialDid);
|
||||
}
|
||||
}
|
||||
textureCoord.Add((int)terrain.terrainIndex, Vector2.Zero);
|
||||
}
|
||||
|
||||
atlasBuilder.GenerateAtlas();
|
||||
foreach(var img in atlasBuilder.textures) {
|
||||
terrainTexture.Add(img.Key, img.Value);
|
||||
}
|
||||
textureCoord.Add((int)terrain.terrainIndex, Vector2.Zero);
|
||||
}
|
||||
}
|
||||
public void GenerateAtlas() {
|
||||
atlasBuilder.GenerateAtlas();
|
||||
}
|
||||
public void GenerateUV() {
|
||||
int count = (int)Math.Ceiling(Math.Sqrt(textureCoord.Count));
|
||||
int atlasSize = (int)64 * count;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue