Files
PixelPics/tools/ObjectTestRender.java
T

53 lines
2.9 KiB
Java

import eu.mhsl.minecraft.pixelpics.render.entity.*;
import org.bukkit.Material;
import org.bukkit.util.Vector;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.*;
import java.util.List;
/**
* Standalone (no server) render of {@link ObjectState}s (block/item/text displays, dropped items) in one scene,
* to check the ObjectBaker geometry, UV orientation and transforms. Output: {@code -Dout} (default
* ~/Dokumente/PixelPics-Entity-Renders/objects.png). Build: see {@link Harness}.
*/
public class ObjectTestRender {
static ObjectState item(Affine a, String id, Material block, String state) {
return ObjectState.item(a, new ItemSpec(id, block == null ? null : Harness.block(block, state), null, false), "none", false);
}
static ObjectState text(Affine a, int background, String... lines) {
return ObjectState.text(a, List.of(lines), 200, 0xFFFFFFFF, background, true);
}
public static void main(String[] args) throws Exception {
Harness h = new Harness("test");
List<ObjectState> objs = new ArrayList<>();
// Block displays: plain grass block (tinted), rotated + scaled stairs.
objs.add(ObjectState.block(Affine.translation(0, 0, 0), Harness.block(Material.GRASS_BLOCK, "snowy=false"), null));
objs.add(ObjectState.block(Affine.translation(2, 0, 0).mul(Affine.rotY(Math.toRadians(30))).mul(Affine.scale(0.75)),
Harness.block(Material.OAK_STAIRS, "facing=north,half=bottom,shape=straight,waterlogged=false"), null));
// Item displays: a flat item and a block item.
objs.add(item(Affine.translation(0.5, 2.0, 0.5), "diamond_sword", null, null));
objs.add(item(Affine.translation(2.5, 2.0, 0.5).mul(Affine.scale(0.6)), "oak_log", Material.OAK_LOG, "axis=y"));
// Text facing the camera on an opaque background, and seen from the BACK (front faces +Z, camera is on -Z)
// on the vanilla default 25% black background (blended); a shield item.
objs.add(text(Affine.translation(1.5, 3.0, 0).mul(Affine.rotY(Math.PI)).mul(Affine.scale(0.025)), 0xFF203040,
"Hallo PixelPics!", "Zeile zwei äöü"));
objs.add(text(Affine.translation(-0.5, 3.0, 0).mul(Affine.scale(0.025)), 0x40000000, "Rueckseite"));
objs.add(item(Affine.translation(4, 1.0, 0.5), "shield", null, null));
// Dropped item (flat) on the ground.
objs.add(item(Affine.translation(-1, 0.3, 0.5).mul(Affine.scale(0.5)), "apple", null, null));
int w = 480, ht = 360;
BufferedImage img = h.renderer.execute(Harness.job(Harness.emptyWorld(0, 1), new Vector(1.5, 3.2, -6.5),
new Vector(1.2, 1.3, 0.5), w, ht, List.of(), List.of(), List.of(), objs));
File out = new File(System.getProperty("out", "/home/elias/Dokumente/PixelPics-Entity-Renders/objects.png"));
ImageIO.write(img, "png", out);
System.out.println("WROTE " + out);
}
}