Search in sources :

Example 1 with AtlasData

use of org.terasology.engine.rendering.assets.atlas.AtlasData in project Terasology by MovingBlocks.

the class WorldAtlasImpl method createTextureAtlas.

private void createTextureAtlas(final Texture texture) {
    final Map<Name, Map<Name, SubtextureData>> textureAtlases = Maps.newHashMap();
    final Vector2f texSize = new Vector2f(getRelativeTileSize(), getRelativeTileSize());
    tileIndexes.forEachEntry((tileUri, index) -> {
        Vector2f coords = getTexCoords(index);
        SubtextureData subtextureData = new SubtextureData(texture, new Rectanglef(coords, coords).setSize(texSize));
        Map<Name, SubtextureData> textureAtlas = textureAtlases.get(tileUri.getModuleName());
        if (textureAtlas == null) {
            textureAtlas = Maps.newHashMap();
            textureAtlases.put(tileUri.getModuleName(), textureAtlas);
        }
        textureAtlas.put(tileUri.getResourceName(), subtextureData);
        return true;
    });
    for (Map.Entry<Name, Map<Name, SubtextureData>> atlas : textureAtlases.entrySet()) {
        AtlasData data = new AtlasData(atlas.getValue());
        Assets.generateAsset(new ResourceUrn(atlas.getKey(), new Name("terrain")), data, Atlas.class);
    }
}
Also used : AtlasData(org.terasology.engine.rendering.assets.atlas.AtlasData) Vector2f(org.joml.Vector2f) SubtextureData(org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData) Rectanglef(org.terasology.joml.geom.Rectanglef) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) TObjectIntMap(gnu.trove.map.TObjectIntMap) Map(java.util.Map) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Name(org.terasology.gestalt.naming.Name)

Aggregations

TObjectIntMap (gnu.trove.map.TObjectIntMap)1 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 Map (java.util.Map)1 Vector2f (org.joml.Vector2f)1 AtlasData (org.terasology.engine.rendering.assets.atlas.AtlasData)1 SubtextureData (org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1 Name (org.terasology.gestalt.naming.Name)1 Rectanglef (org.terasology.joml.geom.Rectanglef)1