use of com.talosvfx.talos.editor.addons.scene.utils.metadata.SpriteMetadata in project talos by rockbite.
the class MainRenderer method renderSprite.
private void renderSprite(Batch batch, GameObject gameObject) {
SpriteRendererComponent spriteRenderer = gameObject.getComponent(SpriteRendererComponent.class);
SpriteMetadata metadata = SceneEditorAddon.get().workspace.getMetadata(spriteRenderer.path, SpriteMetadata.class);
vec.set(0, 0);
transformComponent.localToWorld(gameObject, vec);
Vector2 renderPosition = vec;
if (spriteRenderer.getTexture() != null) {
batch.setColor(spriteRenderer.color);
if (spriteRenderer.renderMode == SpriteRendererComponent.RenderMode.sliced) {
// todo: pelase fix me, i am such a shit
Texture texture = spriteRenderer.getTexture().getTexture();
// todo: this has to be done better
NinePatch patch = obtainNinePatch(texture, metadata);
// todo: and this renders wrong so this needs fixing too
float xSign = transformComponent.scale.x < 0 ? -1 : 1;
float ySign = transformComponent.scale.y < 0 ? -1 : 1;
patch.draw(batch, renderPosition.x - 0.5f * transformComponent.scale.x * xSign, renderPosition.y - 0.5f * transformComponent.scale.y * ySign, 0.5f * transformComponent.scale.x * xSign, 0.5f * transformComponent.scale.y * ySign, Math.abs(transformComponent.scale.x), Math.abs(transformComponent.scale.y), xSign, ySign, transformComponent.rotation);
} else if (spriteRenderer.renderMode == SpriteRendererComponent.RenderMode.tiled) {
spriteRenderer.getTexture().getTexture().setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
float repeatX = transformComponent.scale.x / (spriteRenderer.getTexture().getTexture().getWidth() / metadata.pixelsPerUnit);
float repeatY = transformComponent.scale.y / (spriteRenderer.getTexture().getTexture().getHeight() / metadata.pixelsPerUnit);
spriteRenderer.getTexture().setRegion(0, 0, repeatX, repeatY);
batch.draw(spriteRenderer.getTexture(), renderPosition.x - 0.5f, renderPosition.y - 0.5f, 0.5f, 0.5f, 1f, 1f, transformComponent.scale.x, transformComponent.scale.y, transformComponent.rotation);
} else if (spriteRenderer.renderMode == SpriteRendererComponent.RenderMode.simple) {
spriteRenderer.getTexture().getTexture().setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
spriteRenderer.getTexture().setRegion(0, 0, spriteRenderer.getTexture().getTexture().getWidth(), spriteRenderer.getTexture().getTexture().getHeight());
batch.draw(spriteRenderer.getTexture(), renderPosition.x - 0.5f, renderPosition.y - 0.5f, 0.5f, 0.5f, 1f, 1f, transformComponent.scale.x, transformComponent.scale.y, transformComponent.rotation);
}
batch.setColor(Color.WHITE);
}
}
use of com.talosvfx.talos.editor.addons.scene.utils.metadata.SpriteMetadata in project talos by rockbite.
the class SpriteImporter method importAsset.
@Override
public FileHandle importAsset(FileHandle fileHandle, FileHandle destinationDir) {
FileHandle importedAsset = importAssetFile(fileHandle, destinationDir);
if (fileHandle.nameWithoutExtension().endsWith(".9")) {
// it's a nine slice, and needs metadata created accordingly
FileHandle metadataHandle = AssetImporter.getMetadataHandleFor(importedAsset);
metadataHandle = renameAsset(metadataHandle, metadataHandle.nameWithoutExtension().replace(".9", "") + ".meta");
importedAsset = renameAsset(importedAsset, importedAsset.nameWithoutExtension().replace(".9", "") + ".png");
SpriteMetadata metadata = AssetImporter.readMetadata(metadataHandle, SpriteMetadata.class);
Pixmap pixmap = new Pixmap(importedAsset);
int[] splits = ImportUtils.getSplits(pixmap);
metadata.borderData = splits;
AssetImporter.saveMetadata(metadataHandle, metadata);
Pixmap newPixmap = ImportUtils.cropImage(pixmap, 1, 1, pixmap.getWidth() - 1, pixmap.getHeight() - 1);
PixmapIO.writePNG(importedAsset, newPixmap);
pixmap.dispose();
newPixmap.dispose();
}
return importedAsset;
}
use of com.talosvfx.talos.editor.addons.scene.utils.metadata.SpriteMetadata in project talos by rockbite.
the class SpriteImporter method createMetadataFor.
@Override
public FileHandle createMetadataFor(FileHandle handle) {
FileHandle metadataHandle = AssetImporter.getMetadataHandleFor(handle);
SpriteMetadata metadata = new SpriteMetadata();
AssetImporter.saveMetadata(metadataHandle, metadata);
return metadataHandle;
}
use of com.talosvfx.talos.editor.addons.scene.utils.metadata.SpriteMetadata in project talos by rockbite.
the class SpriteImporter method makeInstance.
@Override
public void makeInstance(FileHandle asset, GameObject parent) {
if (!AssetImporter.getMetadataHandleFor(asset).exists()) {
createMetadataFor(asset);
}
SpriteMetadata metadata = AssetImporter.readMetadataFor(asset, SpriteMetadata.class);
SceneEditorWorkspace workspace = SceneEditorAddon.get().workspace;
Vector2 sceneCords = workspace.getMouseCordsOnScene();
GameObject gameObject = workspace.createSpriteObject(asset, sceneCords, parent);
if (metadata.borderData != null) {
SpriteRendererComponent component = gameObject.getComponent(SpriteRendererComponent.class);
component.renderMode = SpriteRendererComponent.RenderMode.sliced;
} else {
if (gameObject.hasComponent(TransformComponent.class)) {
TransformComponent component = gameObject.getComponent(TransformComponent.class);
Texture texture = new Texture(asset);
component.scale.x = texture.getWidth() / metadata.pixelsPerUnit;
component.scale.y = texture.getHeight() / metadata.pixelsPerUnit;
}
}
}
Aggregations