mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-28 07:35:51 +00:00
Add generic model data interface
This commit is contained in:
1 parent
7e0251a98d
commit
9595859b22
2 files changed
+33
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user