Skip to content

Commit

Permalink
Made it so offsetPivot, offsetRot and offsetScale actually work, i think
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Dec 11, 2023
1 parent 5b8ec51 commit 718a4eb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
45 changes: 32 additions & 13 deletions common/src/main/java/org/figuramc/figura/model/FiguraModelPart.java
Expand Up @@ -45,6 +45,7 @@ public class FiguraModelPart implements Comparable<FiguraModelPart> {
public final PartCustomization customization;
public PartCustomization savedCustomization;
public ParentType parentType = ParentType.None;
public PartCustomization playerCustomization;

private final Map<String, FiguraModelPart> childCache = new HashMap<>();
public final List<FiguraModelPart> children;
Expand Down Expand Up @@ -104,13 +105,16 @@ private Map<Integer, List<Vertex>> copyVertices() {
}

public void applyVanillaTransforms(VanillaModelData vanillaModelData) {

if (vanillaModelData == null)
return;

// get part data
VanillaModelData.PartData partData = vanillaModelData.partMap.get(this.parentType);
if (partData == null)
return;
playerCustomization = new PartCustomization();
customization.copyTo(playerCustomization);

// apply vanilla transforms
customization.vanillaVisible = partData.visible;
Expand All @@ -120,31 +124,46 @@ public void applyVanillaTransforms(VanillaModelData vanillaModelData) {
defaultPivot.subtract(partData.pos);

if (!overrideVanillaScale()) {
defaultPivot.multiply(partData.scale);
defaultPivot.multiply(partData.scale.copy().add(customization.getOffsetScale()));
customization.offsetScale(partData.scale);
}

if (!overrideVanillaPos()) {
customization.offsetPivot(defaultPivot);
customization.offsetPos(defaultPivot);
customization.addOffsetPivot(defaultPivot);
customization.addOffsetPos(defaultPivot);
}

// customization.offsetPivot(pivot);
if (!overrideVanillaRot())
customization.offsetRot(partData.rot);
customization.addOffsetRot(partData.rot);
}

public void resetVanillaTransforms() {
if (parentType.provider != null) {
if (!overrideVanillaPos()) {
customization.offsetPivot(0, 0, 0);
customization.offsetPos(0, 0, 0);
if (playerCustomization != null) {
customization.offsetPivot(playerCustomization.getOffsetPivot());
customization.offsetPos(playerCustomization.getOffsetPos());
} else {
customization.offsetPivot(0, 0, 0);
customization.offsetPos(0, 0, 0);
}
}
if (!overrideVanillaRot())
customization.offsetRot(0, 0, 0);
if (!overrideVanillaScale())
customization.offsetScale(1, 1, 1);

if (!overrideVanillaRot()) {
if (playerCustomization != null) {
customization.offsetRot(playerCustomization.getOffsetRot());
} else {
customization.offsetRot(0, 0, 0);
}
}
if (!overrideVanillaScale()) {
if (playerCustomization != null) {
customization.offsetScale(playerCustomization.getOffsetScale());
} else {
customization.offsetScale(1, 1, 1);
}
}
playerCustomization = null;
customization.vanillaVisible = null;
}
}
Expand All @@ -170,7 +189,7 @@ public void applyExtraTransforms(PartCustomization currentTransforms) {
customization.setMatrix(prevPartToView);
}

// -- animations -- //
// -- animations -- //

public void animPosition(FiguraVec3 vec, boolean merge) {
if (merge) {
Expand Down Expand Up @@ -209,7 +228,7 @@ public void animScale(FiguraVec3 vec, boolean merge) {
}
}

// -- LUA BUSINESS --//
// -- LUA BUSINESS --//


@LuaWhitelist
Expand Down
Expand Up @@ -182,6 +182,13 @@ public void offsetPivot(double x, double y, double z) {
offsetPivot.set(x, y, z);
needsMatrixRecalculation = true;
}
public void addOffsetPivot(FiguraVec3 pivot) {
addOffsetPos(pivot.x, pivot.y, pivot.z);
}
public void addOffsetPivot(double x, double y, double z) {
offsetPivot.add(x, y, z);
needsMatrixRecalculation = true;
}
public FiguraVec3 getOffsetPivot() {
return offsetPivot.copy();
}
Expand All @@ -193,6 +200,13 @@ public void offsetPos(double x, double y, double z) {
offsetPos.set(x, y, z);
needsMatrixRecalculation = true;
}
public void addOffsetPos(FiguraVec3 pos) {
addOffsetPos(pos.x, pos.y, pos.z);
}
public void addOffsetPos(double x, double y, double z) {
offsetPos.add(x, y, z);
needsMatrixRecalculation = true;
}
public FiguraVec3 getOffsetPos() {
return offsetPos.copy();
}
Expand All @@ -204,6 +218,13 @@ public void offsetRot(double x, double y, double z) {
offsetRot.set(x, y, z);
needsMatrixRecalculation = true;
}
public void addOffsetRot(FiguraVec3 rot) {
addOffsetRot(rot.x, rot.y, rot.z);
}
public void addOffsetRot(double x, double y, double z) {
offsetRot.add(x, y, z);
needsMatrixRecalculation = true;
}
public FiguraVec3 getOffsetRot() {
return offsetRot.copy();
}
Expand All @@ -215,6 +236,13 @@ public void offsetScale(double x, double y, double z) {
offsetScale.set(x, y, z);
needsMatrixRecalculation = true;
}
public void addOffsetScale(FiguraVec3 scale) {
addOffsetScale(scale.x, scale.y, scale.z);
}
public void addOffsetScale(double x, double y, double z) {
offsetScale.add(x, y, z);
needsMatrixRecalculation = true;
}
public FiguraVec3 getOffsetScale() {
return offsetScale.copy();
}
Expand Down

0 comments on commit 718a4eb

Please sign in to comment.