Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.18/animation test #249

Merged
merged 27 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a5edd40
feat: add simple block animator
Jeronimo97 Apr 25, 2024
1b5e22c
feat: add animationsystem per signal tile
Jeronimo97 Aug 2, 2024
cb571e4
ref: first thing for animatino
Uhutown Sep 22, 2024
9d986d0
ref: applied to signal angel
Uhutown Sep 22, 2024
ee0be63
ref: update test animation
Jeronimo97 Sep 22, 2024
779947b
feat: added basic animation system
Uhutown Sep 23, 2024
945c6b4
feat: added new calc logic for rotating animations
Uhutown Sep 24, 2024
543c13f
feat: added system for Rotation on all axis
Uhutown Sep 24, 2024
bb9b440
feat: added model translation
Uhutown Sep 24, 2024
19bd6eb
fix: anim rotation model translation calc
Jeronimo97 Sep 25, 2024
1f199af
feat: added AnimationTranslation
Uhutown Sep 30, 2024
dc53a45
ref: better code performance
Uhutown Oct 7, 2024
3ba6bb1
fix: anim default model offset
Jeronimo97 Oct 7, 2024
7ecec38
fix: animation rotation angle and speed
Jeronimo97 Oct 7, 2024
282800b
ref: better code performance
Uhutown Oct 7, 2024
028b652
ref: added gate and semaphore animations
Jeronimo97 Oct 8, 2024
134625e
ref: changed to ModelInfoWrapper & fixed problem with 2 animations at…
Uhutown Oct 8, 2024
272b28b
feat: added global pivot
Uhutown Oct 8, 2024
acf07b3
fix: loading of animation models
Uhutown Oct 8, 2024
faab190
ref: update animation models
Jeronimo97 Oct 8, 2024
d71d29b
fix: problems with models in animation
Uhutown Oct 8, 2024
a7f647f
ref: add semaphore distant animation
Jeronimo97 Oct 8, 2024
107f42f
fix: issue with wrong things showed in SignalController
Uhutown Oct 9, 2024
df9a787
fix: issue in guilib
Uhutown Oct 9, 2024
7acda94
Merge branch '1.18-master' into 1.18/animationTest
Uhutown Oct 23, 2024
04828d7
ref: rework semaphore dist lamps
Jeronimo97 Nov 4, 2024
2ec6bec
ref: rework semaphore lamps
Jeronimo97 Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.troblecodings.signals.animation;

import java.util.Arrays;

public enum AnimationMode {

ROTATION("ROTATION"), TRANSLATION("TRANSLATION");

private String mode;

private AnimationMode(final String mode) {
this.mode = mode;
}

public static AnimationMode of(final String mode) {
return Arrays.stream(values())
.filter(animationMode -> animationMode.mode.equalsIgnoreCase(mode)).findFirst()
.orElse(null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.troblecodings.signals.animation;

import java.util.Objects;

import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;

public class AnimationRotionCalc {

private float step;
private final RotationAxis axis;
private float progress;
private float max;

public AnimationRotionCalc(final Vector3f startPosition, final Vector3f finalPosition,
final float animationSpeed, final RotationAxis axis) {
this.step = 0.005f * animationSpeed;
this.axis = axis;
calculateWayAndValues(startPosition, finalPosition);
}

private void calculateWayAndValues(final Vector3f start, final Vector3f end) {
switch (axis) {
case X: {
progress = start.x();
max = end.x();
break;
}
case Y: {
progress = start.y();
max = end.y();
break;
}
case Z: {
progress = start.z();
max = end.z();
break;
}
}
if (max < progress) {
this.step = -step;
}
}

public void updateAnimation() {
progress += step;
}

public boolean isAnimationFinished() {
if (step > 0) {
if (progress < max)
return false;
} else {
if (max < progress)
return false;
}
return true;
}

public Quaternion getQuaternion() {
return axis.getForAxis(progress);
}

@Override
public int hashCode() {
return Objects.hash(axis, max, progress, step);
}

@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final AnimationRotionCalc other = (AnimationRotionCalc) obj;
return axis == other.axis && Float.floatToIntBits(max) == Float.floatToIntBits(other.max)
&& Float.floatToIntBits(progress) == Float.floatToIntBits(other.progress)
&& Float.floatToIntBits(step) == Float.floatToIntBits(other.step);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.troblecodings.signals.animation;

import java.util.Objects;

import com.troblecodings.core.VectorWrapper;

public class AnimationTranslationCalc {

private float stepX;
private float stepY;
private float stepZ;
private float progressX;
private float progressY;
private float progressZ;
private float maxX;
private float maxY;
private float maxZ;

private boolean finishedX = false;
private boolean finishedY = false;
private boolean finishedZ = false;

public AnimationTranslationCalc(final VectorWrapper startPosition,
final VectorWrapper finalPosition, final float animationSpeed) {
this.stepX = 0.005f * animationSpeed;
this.stepY = 0.005f * animationSpeed;
this.stepZ = 0.005f * animationSpeed;
calculateWayAndValues(startPosition, finalPosition);
}

private void calculateWayAndValues(final VectorWrapper start, final VectorWrapper end) {
this.progressX = start.getX();
this.progressY = start.getY();
this.progressZ = start.getZ();

this.maxX = end.getX();
this.maxY = end.getY();
this.maxZ = end.getZ();

if (maxX < progressX) {
this.stepX = -stepX;
}
if (maxY < progressY) {
this.stepY = -stepY;
}
if (maxZ < progressZ) {
this.stepZ = -stepZ;
}
}

public void updateAnimation() {
if (!finishedX) {
progressX += stepX;
this.finishedX = isAnimationOnAxisIsFinished(stepX, progressX, maxX);
}
if (!finishedY) {
progressY += stepY;
this.finishedY = isAnimationOnAxisIsFinished(stepY, progressY, maxY);
}
if (!finishedZ) {
progressZ += stepZ;
this.finishedZ = isAnimationOnAxisIsFinished(stepZ, progressZ, maxZ);
}
}

public boolean isAnimationFinished() {
return finishedX && finishedY && finishedZ;
}

private static boolean isAnimationOnAxisIsFinished(final float step, final float progress,
final float max) {
if (step > 0) {
if (progress < max) {
return false;
}
} else {
if (max < progress) {
return false;
}
}
return true;
}

public VectorWrapper getTranslation() {
return new VectorWrapper(progressX, progressY, progressZ);
}

@Override
public int hashCode() {
return Objects.hash(maxX, maxY, maxZ, progressX, progressY, progressZ);
}

@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final AnimationTranslationCalc other = (AnimationTranslationCalc) obj;
return Float.floatToIntBits(maxX) == Float.floatToIntBits(other.maxX)
&& Float.floatToIntBits(maxY) == Float.floatToIntBits(other.maxY)
&& Float.floatToIntBits(maxZ) == Float.floatToIntBits(other.maxZ)
&& Float.floatToIntBits(progressX) == Float.floatToIntBits(other.progressX)
&& Float.floatToIntBits(progressY) == Float.floatToIntBits(other.progressY)
&& Float.floatToIntBits(progressZ) == Float.floatToIntBits(other.progressZ);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.troblecodings.signals.animation;

import java.util.Objects;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Quaternion;
import com.troblecodings.core.VectorWrapper;

public class ModelTranslation {

private VectorWrapper pivotTranslation = VectorWrapper.ZERO;
private Quaternion quaternion = Quaternion.ONE;
private SignalAnimation animation;
private VectorWrapper modelTranslation = VectorWrapper.ZERO;
private VectorWrapper translation = VectorWrapper.ZERO;
private boolean renderModel = false;

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

public ModelTranslation(final VectorWrapper translation) {
this.translation = translation;
}

public void translate(final PoseStack stack) {
stack.translate(modelTranslation.getX() - 0.5f, modelTranslation.getY() - 0.5f,
modelTranslation.getZ() - 0.5f);

if (!quaternion.equals(Quaternion.ONE)) {
stack.mulPose(quaternion);
}
if (!translation.equals(VectorWrapper.ZERO)) {
stack.translate(translation.getX(), translation.getY(), translation.getZ());
}
stack.translate(pivotTranslation.getX(), pivotTranslation.getY(), pivotTranslation.getZ());
}

public Quaternion getQuaternion() {
return quaternion;
}

public VectorWrapper getTranslation() {
return translation;
}

public boolean shouldRenderModel() {
return renderModel;
}

public ModelTranslation setRenderModel(final boolean renderModel) {
this.renderModel = renderModel;
return this;
}

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

public void setModelTranslation(final VectorWrapper translation) {
this.modelTranslation = translation;
}

public void assignAnimation(final SignalAnimation animation) {
this.animation = animation;
}

public void removeAnimation() {
this.animation = null;
}

public boolean isAnimationAssigned() {
return animation != null;
}

public SignalAnimation getAssigendAnimation() {
return animation;
}

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

@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final ModelTranslation other = (ModelTranslation) obj;
return Objects.equals(pivotTranslation, other.pivotTranslation)
&& Objects.equals(quaternion, other.quaternion) && renderModel == other.renderModel;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.troblecodings.signals.animation;

import java.util.Arrays;

import com.mojang.math.Quaternion;
import com.troblecodings.signals.OpenSignalsMain;

public enum RotationAxis {

X("X"), Y("Y"), Z("Z");

private final String axis;

private RotationAxis(final String axis) {
this.axis = axis;
}

public static RotationAxis of(final String axis) {
return Arrays.stream(values())
.filter(rotationAxis -> rotationAxis.axis.equalsIgnoreCase(axis)).findFirst()
.orElseGet(() -> {
OpenSignalsMain.exitMinecraftWithMessage("[" + axis
+ "] is not a valid axis for a RotationAnimation! Valid are: "
+ values());
return null;
});
}

public Quaternion getForAxis(final float value) {
switch (this) {
case X:
return Quaternion.fromXYZ(value, 0, 0);
case Y:
return Quaternion.fromXYZ(0, value, 0);
case Z:
return Quaternion.fromXYZ(0, 0, value);
default:
return Quaternion.fromXYZ(0, 0, 0);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.troblecodings.signals.animation;

import java.util.function.Predicate;

import com.troblecodings.signals.models.ModelInfoWrapper;

public interface SignalAnimation extends Predicate<ModelInfoWrapper> {

public void updateAnimation();

public ModelTranslation getModelTranslation();

public ModelTranslation getFinalModelTranslation();

public boolean isFinished();

public void reset();

public void setUpAnimationValues(final ModelTranslation currentTranslation);

public SignalAnimation copy();

public Predicate<ModelInfoWrapper> getPredicate();

}
Loading
Loading