Update for AtlasBuilder ok
Need to improuve duplicate vertex for mapping texture.
This commit is contained in:
parent
4777783ffb
commit
b9a2b87fe9
11 changed files with 160 additions and 33 deletions
|
|
@ -28,21 +28,22 @@ public class AtlasBuilder {
|
|||
|
||||
public void GenerateAtlas() {
|
||||
int count = (int)Math.Ceiling(Math.Sqrt(textures.Count));
|
||||
int atlasSize = (int)TEXTURESIZE * count;
|
||||
int atlasSize = (int)TEXTURESIZE * count;
|
||||
|
||||
using (MagickImage atlas = new MagickImage(new MagickColor("#FFFFFF"), atlasSize, atlasSize)) {
|
||||
int index = 0;
|
||||
using (MagickImage atlas = new MagickImage(new MagickColor("#FFFFFF"), atlasSize, atlasSize)) {
|
||||
int index = 0;
|
||||
|
||||
foreach (var kvp in textures) {
|
||||
int x = (index % count) * (int)TEXTURESIZE;
|
||||
int y = (index / count) * (int)TEXTURESIZE;
|
||||
atlas.Draw(new Drawables().Composite(x, y, kvp));
|
||||
index++;
|
||||
if (index >= count * count) break;
|
||||
}
|
||||
|
||||
atlas.Write("atlas.jpg");
|
||||
foreach (var kvp in textures) {
|
||||
int x = (index % count) * (int)TEXTURESIZE;
|
||||
int y = (index / count) * (int)TEXTURESIZE;
|
||||
atlas.Composite(kvp, x, y);
|
||||
|
||||
index++;
|
||||
if (index >= count * count) break;
|
||||
}
|
||||
|
||||
atlas.Write("atlas.jpg");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using LandblockExtraction.DatEngine;
|
||||
using AC2RE.Definitions;
|
||||
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;
|
||||
|
||||
|
|
@ -11,11 +13,11 @@ public class TerrainAtlasManager {
|
|||
private PortalEngine portalEngine;
|
||||
private AtlasBuilder atlasBuilder;
|
||||
|
||||
public Dictionary<uint, Vector2> textureCoord;
|
||||
public Dictionary<int, Vector2> textureCoord;
|
||||
|
||||
public TerrainAtlasManager(PortalEngine portalEngine) {
|
||||
this.portalEngine = portalEngine;
|
||||
textureCoord = new Dictionary<uint, Vector2>();
|
||||
textureCoord = new Dictionary<int, Vector2>();
|
||||
atlasBuilder = new AtlasBuilder(portalEngine);
|
||||
}
|
||||
public void ExtractTexture() {
|
||||
|
|
@ -25,9 +27,21 @@ public class TerrainAtlasManager {
|
|||
atlasBuilder.AddTexture(surface.terrainMaterials.First().baseMaterials.First().materialDid);
|
||||
}
|
||||
}
|
||||
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;
|
||||
int index = 0;
|
||||
foreach(var terrain in textureCoord) {
|
||||
int x = (index % count) * (int)64;
|
||||
int y = (index / count) * (int)64;
|
||||
textureCoord[index] = new Vector2(x, y);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ 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)) {
|
||||
|
|
@ -47,8 +48,9 @@ public class TexturesImage {
|
|||
if(image.width != 64) continue;
|
||||
var dataImg = DDSHeader.Generate(image);
|
||||
using(MagickImage realImg = new MagickImage(dataImg)) {
|
||||
return realImg;
|
||||
magickImage = new(realImg);
|
||||
}
|
||||
return magickImage;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue