1
0
mirror of https://github.com/GeyserMC/Rainbow.git synced 2025-12-19 14:59:16 +00:00

"Proper" 1st-person animation mapping

This commit is contained in:
Eclipse
2025-07-06 10:55:12 +00:00
parent 3cb91d3d64
commit d72dbda83b
2 changed files with 18 additions and 5 deletions

View File

@@ -7,17 +7,29 @@ import org.joml.Vector3f;
import org.joml.Vector3fc;
public class AnimationMapper {
private static final Vector3fc POSITION_OFFSET = new Vector3f(0.0F, 13.0F, -3.0F);
private static final Vector3fc ROTATION_OFFSET = new Vector3f(90.0F, -90.0F, 0.0F);
// These aren't perfect... but I spent over 1.5 hours trying to get these. It's good enough for me.
private static final Vector3fc FIRST_PERSON_POSITION_OFFSET = new Vector3f(-7.0F, 22.5F, -7.0F);
private static final Vector3fc FIRST_PERSON_ROTATION_OFFSET = new Vector3f(-22.5F, 50.0F, -32.5F);
private static final Vector3fc THIRD_PERSON_POSITION_OFFSET = new Vector3f(0.0F, 13.0F, -3.0F);
private static final Vector3fc THIRD_PERSON_ROTATION_OFFSET = new Vector3f(90.0F, -90.0F, 0.0F);
public static BedrockAnimationContext mapAnimation(String identifier, String bone, ItemTransforms transforms) {
// I don't think it's possible to display separate animations for left- and right hands
ItemTransform firstPerson = transforms.firstPersonRightHand();
Vector3f firstPersonPosition = FIRST_PERSON_POSITION_OFFSET.add(firstPerson.translation(), new Vector3f());
Vector3f firstPersonRotation = FIRST_PERSON_ROTATION_OFFSET.add(firstPerson.rotation(), new Vector3f());
Vector3f firstPersonScale = new Vector3f(firstPerson.scale());
ItemTransform thirdPerson = transforms.thirdPersonLeftHand();
Vector3f thirdPersonPosition = POSITION_OFFSET.add(thirdPerson.translation(), new Vector3f());
Vector3f thirdPersonRotation = ROTATION_OFFSET.add(-thirdPerson.rotation().x(), thirdPerson.rotation().y(), thirdPerson.rotation().z(), new Vector3f());
Vector3f thirdPersonPosition = THIRD_PERSON_POSITION_OFFSET.add(thirdPerson.translation(), new Vector3f());
Vector3f thirdPersonRotation = THIRD_PERSON_ROTATION_OFFSET.add(-thirdPerson.rotation().x(), thirdPerson.rotation().y(), thirdPerson.rotation().z(), new Vector3f());
Vector3f thirdPersonScale = new Vector3f(thirdPerson.scale());
return new BedrockAnimationContext(BedrockAnimation.builder()
.withAnimation(identifier + ".hold_first_person", BedrockAnimation.animation())
.withAnimation(identifier + ".hold_first_person", BedrockAnimation.animation()
.withLoopMode(BedrockAnimation.LoopMode.LOOP)
.withBone(bone, firstPersonPosition, firstPersonRotation, firstPersonScale))
.withAnimation(identifier + ".hold_third_person", BedrockAnimation.animation()
.withLoopMode(BedrockAnimation.LoopMode.LOOP)
.withBone(bone, thirdPersonPosition, thirdPersonRotation, thirdPersonScale))

View File

@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
// TODO make vectors immutable
public record BedrockGeometry(BedrockVersion formatVersion, List<GeometryDefinition> definitions) {
public static final BedrockVersion FORMAT_VERSION = BedrockVersion.of(1, 21, 0);
public static final Vector3f VECTOR3F_ZERO = new Vector3f();