Update AtlasBuilder and TerrainAtlasManager
This commit is contained in:
parent
e7cf3bdf5a
commit
4777783ffb
4 changed files with 90 additions and 8 deletions
|
|
@ -11,7 +11,6 @@ using System.Threading.Tasks;
|
|||
namespace LandblockExtraction.AtlasMaker;
|
||||
public class AtlasBuilder {
|
||||
private readonly int TEXTURESIZE = 64;
|
||||
|
||||
private TexturesImage texturesImage;
|
||||
private List<MagickImage> textures;
|
||||
|
||||
|
|
@ -20,7 +19,30 @@ public class AtlasBuilder {
|
|||
texturesImage = new TexturesImage(portalEngine);
|
||||
}
|
||||
|
||||
public AddTexture(DataId vdesc) {
|
||||
public bool AddTexture(DataId matId) {
|
||||
var img = texturesImage.GetImage(matId);
|
||||
if(img == null) return false;
|
||||
textures.Add(img);
|
||||
return true;
|
||||
}
|
||||
|
||||
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.Draw(new Drawables().Composite(x, y, kvp));
|
||||
index++;
|
||||
if (index >= count * count) break;
|
||||
}
|
||||
|
||||
atlas.Write("atlas.jpg");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue