diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/client/model/BakeData.java b/src/main/java/com/gtnewhorizon/gtnhlib/client/model/BakeData.java new file mode 100644 index 00000000..ecc860c6 --- /dev/null +++ b/src/main/java/com/gtnewhorizon/gtnhlib/client/model/BakeData.java @@ -0,0 +1,26 @@ +package com.gtnewhorizon.gtnhlib.client.model; + +import org.joml.Matrix4f; + +public interface BakeData { + BakeData IDENTITY = new BakeData() { + private final Matrix4f I = new Matrix4f(); + + @Override + public Matrix4f getAffineMatrix() { + return I; + } + }; + + /** + * @return The affine matrix of the transformation. It may be reused - copy before mutating it! + */ + Matrix4f getAffineMatrix(); + + /** + * @return True if textures shouldn't be rotated with the rest of the model; false otherwise. + */ + default boolean lockUV() { + return false; + } +} diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/client/model/JSONVariant.java b/src/main/java/com/gtnewhorizon/gtnhlib/client/model/JSONVariant.java index e169ce44..828a3e23 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/client/model/JSONVariant.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/client/model/JSONVariant.java @@ -17,7 +17,7 @@ import org.joml.Matrix4f; * than zero. */ @Internal -public record JSONVariant(ResourceLocation model, float x, float y, float z, boolean uvLock, int weight) { +public record JSONVariant(ResourceLocation model, float x, float y, float z, boolean uvLock, int weight) implements BakeData { public JSONVariant(ResourceLocation model, int x, int y, boolean uvLock) { this(model, x, y, 0, uvLock, 1); @@ -31,12 +31,18 @@ public record JSONVariant(ResourceLocation model, float x, float y, float z, boo this(model, (float) toRadians(x), (float) toRadians(y), (float) toRadians(z), uvLock, weight); } + @Override public Matrix4f getAffineMatrix() { return new Matrix4f().translation(-.5f, -.5f, -.5f).rotateLocalX(x).rotateLocalY(y).rotateLocalZ(z) .translateLocal(.5f, .5f, .5f); } + @Override + public boolean lockUV() { + return uvLock; + } + /** * Convenience wrapper to combine a weight with a model. Does not uniquely identify a model, unlike JSONVariant * itself.