@Override protected Optional<? extends Asset<SubtextureData>> doCreateCopy(ResourceUrn instanceUrn, AssetType<?, SubtextureData> parentAssetType) { return Optional.of(new Subtexture(instanceUrn, parentAssetType, new SubtextureData(texture, subregion))); }
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, Rect2f.createFromMinAndSize(coords, 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); } }
private void process(FreeformDefinition freeform, Texture texture, Vector2i size, Map<Name, SubtextureData> out) { if (freeform.getName() == null || freeform.getName().isEmpty()) { logger.error("Bad subimage definition - missing mandatory property name"); return; } if (freeform.getMin() == null) { logger.error("Bad subimage definition '{}' - missing mandatory property min", freeform.getName()); return; } if (freeform.getSize() == null && freeform.getMax() == null) { logger.error("Bad subimage definition '{}' - requires one of max or size", freeform.getName()); return; } Vector2f min = new Vector2f((float) freeform.getMin().x / size.x, (float) freeform.getMin().y / size.y); if (freeform.getSize() != null) { Vector2f itemSize = new Vector2f((float) freeform.getSize().x / size.x, (float) freeform.getSize().y / size.y); out.put(new Name(freeform.getName()), new SubtextureData(texture, Rect2f.createFromMinAndSize(min, itemSize))); } else if (freeform.getMax() != null) { Vector2f max = new Vector2f((float) freeform.getMax().x / size.x, (float) freeform.getMax().y / size.y); out.put(new Name(freeform.getName()), new SubtextureData(texture, Rect2f.createFromMinAndMax(min, max))); } }
pos.y += tileY * tileSize.y; Rect2f tileLocation = Rect2f.createFromMinAndSize(offset.x + tileX * tileSize.x, offset.y + tileY * tileSize.y, tileSize.x, tileSize.y); out.put(new Name(name), new SubtextureData(texture, tileLocation));