47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using AC2RE.Definitions;
|
|
using ImageMagick;
|
|
using LandblockExtraction.DatEngine;
|
|
|
|
namespace LandblockExtraction.AtlasMaker;
|
|
public class AtlasBuilder : IDisposable {
|
|
private readonly int TEXTURESIZE = 64;
|
|
private TexturesImage texturesImage;
|
|
public Dictionary<int, MagickImage> textures;
|
|
|
|
public AtlasBuilder(PortalEngine portalEngine) {
|
|
textures = new();
|
|
texturesImage = new TexturesImage(portalEngine);
|
|
}
|
|
|
|
public bool AddTexture(int index, DataId matId) {
|
|
var img = texturesImage.GetImage(matId);
|
|
if (img == null) return false;
|
|
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;
|
|
|
|
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.Composite(kvp.Value, x, y);
|
|
|
|
index++;
|
|
if (index >= count * count) break;
|
|
}
|
|
|
|
atlas.Write("atlas.jpg");
|
|
}
|
|
|
|
}
|
|
}
|