Skip to content

Commit

Permalink
fix: anim rotation model translation calc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeronimo97 committed Sep 25, 2024
1 parent bb9b440 commit 19bd6eb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,26 @@

public class ModelTranslation {

private VectorWrapper firstTranslation;
private VectorWrapper pivotTranslation;
private Quaternion quaternion = new Quaternion(0, 0, 0, 0);
private VectorWrapper lastTranslation;
private SignalAnimation animation;
private VectorWrapper modelTranslation = VectorWrapper.ZERO;
private boolean renderModel = false;

public ModelTranslation(final VectorWrapper firstTranslation, final Quaternion quaternion,
final VectorWrapper lastTranslation) {
this.firstTranslation = firstTranslation;
public ModelTranslation(final VectorWrapper firstTranslation, final Quaternion quaternion) {
this.pivotTranslation = firstTranslation;
this.quaternion = quaternion;
this.lastTranslation = lastTranslation;
}

public void translate(final RenderAnimationInfo info) {
info.stack.translate(firstTranslation.getX(), firstTranslation.getY(),
firstTranslation.getZ());
info.stack.mulPose(quaternion);
info.stack.translate(lastTranslation.getX(), lastTranslation.getY(),
lastTranslation.getZ());

if (!modelTranslation.equals(VectorWrapper.ZERO)) {
info.stack.translate(modelTranslation.getX(), modelTranslation.getY(),
modelTranslation.getZ());
modelTranslation.getZ()); // Modell verschieben
}
info.stack.mulPose(quaternion);
info.stack.translate(pivotTranslation.getX(), pivotTranslation.getY(),
pivotTranslation.getZ()); // Pivot Punkt
}

public Quaternion getQuaternion() {
Expand All @@ -48,9 +44,8 @@ public ModelTranslation setRenderModel(final boolean renderModel) {
}

public void setUpNewTranslation(final ModelTranslation other) {
this.firstTranslation = other.firstTranslation;
this.pivotTranslation = other.pivotTranslation;
this.quaternion = other.quaternion;
this.lastTranslation = other.lastTranslation;
}

public void setModelTranslation(final VectorWrapper translation) {
Expand All @@ -75,7 +70,7 @@ public SignalAnimation getAssigendAnimation() {

@Override
public int hashCode() {
return Objects.hash(firstTranslation, lastTranslation, quaternion, renderModel);
return Objects.hash(pivotTranslation, quaternion, renderModel);
}

@Override
Expand All @@ -87,8 +82,7 @@ public boolean equals(final Object obj) {
if (getClass() != obj.getClass())
return false;
final ModelTranslation other = (ModelTranslation) obj;
return Objects.equals(firstTranslation, other.firstTranslation)
&& Objects.equals(lastTranslation, other.lastTranslation)
return Objects.equals(pivotTranslation, other.pivotTranslation)
&& Objects.equals(quaternion, other.quaternion) && renderModel == other.renderModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public void render(final RenderAnimationInfo info) {
final BlockState state = tile.getBlockState();
final SignalAngel angle = state.getValue(Signal.ANGEL);
final ModelBlockRenderer renderer = info.dispatcher.getModelRenderer();
final VertexConsumer vertex = info.source
.getBuffer(ItemBlockRenderTypes.getRenderType(state, false));
final VertexConsumer vertex =
info.source.getBuffer(ItemBlockRenderTypes.getRenderType(state, false));
final IModelData data = tile.getModelData();

animationPerModel.forEach((model, entry) -> {
Expand All @@ -57,8 +57,9 @@ public void render(final RenderAnimationInfo info) {
info.overlayTexture, data);
info.stack.popPose();

if (translation.isAnimationAssigned())
if (translation.isAnimationAssigned()) {
updateAnimation(translation);
}
});
}

Expand Down Expand Up @@ -125,8 +126,8 @@ public void updateAnimationListFromBlock() {
map.forEach((entry, animations) -> {
final BakedModel model = SignalCustomModel.getModelFromLocation(
new ResourceLocation(OpenSignalsMain.MODID, entry.getKey()));
final ModelTranslation translation = new ModelTranslation(VectorWrapper.ZERO,
new Quaternion(0, 0, 0, 0), VectorWrapper.ZERO);
final ModelTranslation translation =
new ModelTranslation(VectorWrapper.ZERO, new Quaternion(0, 0, 0, 0));
translation.setModelTranslation(entry.getValue());
animationPerModel.put(model, Maps.immutableEntry(translation, animations));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ public void setUpAnimationValues(final ModelTranslation currentTranslation) {

@Override
public ModelTranslation getFinalModelTranslation() {
return new ModelTranslation(pivot, axis.getForAxis(-rotation * 0.005f * animationSpeed),
pivot);
return new ModelTranslation(pivot, axis.getForAxis(-rotation * 0.005f * animationSpeed));
}

@Override
public ModelTranslation getModelTranslation() {
return new ModelTranslation(pivot, calc.getQuaternion(), pivot);
return new ModelTranslation(pivot, calc.getQuaternion());
}

@Override
public boolean isFinished() {
if (calc == null)
return true;
return calc.isAnimationFinished();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"animations": {
"semaphore_signals/sema_main_wing1": {
"translationX": 5,
"translationX": 0.15,
"translationY": 6.95,
"translationZ": -0.5,
"animationConfigs": [
{
"predicate": "config(WING1.FALSE)",
"mode": "ROTATION",
"rotationAxis": "Z",
"rotation": 0,
"pivotX": 0,
"pivotY": 0,
"pivotX": -0.65,
"pivotY": -4.45,
"pivotZ": 0
},
{
"predicate": "config(WING1.TRUE)",
"mode": "ROTATION",
"rotationAxis": "Z",
"rotation": 100,
"pivotX": 0,
"pivotY": 0,
"rotation": 155,
"pivotX": -0.65,
"pivotY": -4.45,
"pivotZ": 0
}
]
Expand Down

0 comments on commit 19bd6eb

Please sign in to comment.