Class FpArmRenderUtil

java.lang.Object
com.github.razorplay01.fp_pal.firstperson.FpArmRenderUtil

public final class FpArmRenderUtil extends Object
Utility class for rendering player arms in first person with custom transforms.

1:1 port of AzureLib's AzItemArmRenderUtil (MIT License, Copyright (c) 2024 AzureDoom), adapted only for PAL's types (PlayerAnimBone instead of AzBone, FpRenderBuffer instead of AzModelRenderer).

AzureLib does not animate a separate first-person arm model: the leftArm / rightArm bones are part of the animated model, and this class draws the vanilla arm mesh at that bone (the bone itself stays hidden). The pose must already be in the model frame, created by applyCameraAnchor(PoseStack) or applyHandTransform(PoseStack, boolean) plus applyArmDisplayTransform(PoseStack, float[], float).

PAL's loader keeps the raw Blockbench values, so the X/Y negation AzureLib applies when baking is done here in translateMatrixToBone(PoseStack, PlayerAnimBone) and rotateMatrixAroundBone(PoseStack, PlayerAnimBone) (rotation order Z, Y, X).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Bone name used by AzureLib and by player_arms_import.bbmodel.
    static final float[]
    Rotation centre of the left arm as authored in player_arms_import.bbmodel.
    static final float[]
    Pivot of the fp_l_item bone, mirror of RIGHT_ITEM_PIVOT.
    static final float[]
    The rig root needs no pivot translation: its pivot is the model origin.
    static final String
    Bone name used by AzureLib and by player_arms_import.bbmodel.
    static final float[]
    Rotation centre of the right arm in model units, as stored after AzureLib's X mirroring.
    static final float[]
    Pivot of the fp_r_item bone, which sits on the hand like rightArm.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    applyArmDisplayTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, float[] translation, float scale)
    Applies the display transform of the item model that owns the arm bones: the translation (in 1/16 block) and uniform scale of a firstperson_* entry.
    static void
    applyArmTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone arm, float[] pivot)
    Applies an arm bone's full transform in the model frame.
    static void
    applyBoneTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
    Applies the offset, rotation and scale of a bone around the pose origin.
    static void
    applyBoneTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone, float[] pivot)
    Applies the offset, pivot, rotation and scale of a bone in one go (same order as RenderUtils.prepMatrixForBone).
    static void
    applyCameraAnchor(com.mojang.blaze3d.vertex.PoseStack poseStack)
    Applies the camera anchor: same distance and height as the vanilla hand anchor, but on the view axis, so a rig authored around the model origin renders centred like in Blockbench.
    static void
    applyCameraTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone camera)
    Applies the fp_camera transform, which moves, rotates and scales the first-person pass around the view origin.
    static void
    applyHandTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, boolean isLeftHand)
    Applies the vanilla first-person hand anchor (without equip progress), the frame AzureLib gun rigs are authored against.
    static void
    applyItemTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone item)
    Applies the item bone offset in the model frame, keeping the item on the model origin (the fpDisplayAnchor: "hand" convention).
    static void
    applyItemTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone item, float[] pivot)
    Applies the item bone transform so the item model ends up on the bone itself.
    static void
    applyRootTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone wholeRig)
    Applies the fp_player_arms root transform, which moves, rotates and scales the whole rig (both arms and both held items) around the model origin.
    static void
    applyRootTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone wholeRig, float[] pivot)
    Applies the animated model root around its own pivot, like AzureLib's prepMatrixForBone.
    static boolean
    isArmBone(com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
     
    static void
    renderArmForBone(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone, float[] pivot, net.minecraft.client.model.player.PlayerModel playerModel, net.minecraft.resources.Identifier playerSkin, int packedLight, FpRenderBuffer render)
    Renders the vanilla player arm for the given arm bone, hiding the bone itself but keeping children visible.
    static void
    Restores the vanilla arm and sleeve parts of the local player's shared model, so the third-person renderer never inherits the first-person rig pose.
    static void
    rotateMatrixAroundBone(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
     
    static void
    scaleMatrixForBone(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
     
    static void
    translateAwayFromPivotPoint(com.mojang.blaze3d.vertex.PoseStack poseStack, float[] pivot)
     
    static void
    translateMatrixToBone(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
    Same convention as AzureLib's translateMatrixToBone: X is negated and Y is not, because PAL's loader keeps the raw Blockbench value.
    static void
    translateToPivotPoint(com.mojang.blaze3d.vertex.PoseStack poseStack, float[] pivot)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LEFT_ARM_BONE

      public static final String LEFT_ARM_BONE
      Bone name used by AzureLib and by player_arms_import.bbmodel.
      See Also:
    • RIGHT_ARM_BONE

      public static final String RIGHT_ARM_BONE
      Bone name used by AzureLib and by player_arms_import.bbmodel.
      See Also:
    • RIGHT_ARM_PIVOT

      public static final float[] RIGHT_ARM_PIVOT
      Rotation centre of the right arm in model units, as stored after AzureLib's X mirroring.
    • LEFT_ARM_PIVOT

      public static final float[] LEFT_ARM_PIVOT
      Rotation centre of the left arm as authored in player_arms_import.bbmodel.
    • RIGHT_ITEM_PIVOT

      public static final float[] RIGHT_ITEM_PIVOT
      Pivot of the fp_r_item bone, which sits on the hand like rightArm.
    • LEFT_ITEM_PIVOT

      public static final float[] LEFT_ITEM_PIVOT
      Pivot of the fp_l_item bone, mirror of RIGHT_ITEM_PIVOT.
    • NO_PIVOT

      public static final float[] NO_PIVOT
      The rig root needs no pivot translation: its pivot is the model origin.
  • Method Details

    • isArmBone

      public static boolean isArmBone(com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
      Returns:
      true if this is a left or right arm bone
    • renderArmForBone

      public static void renderArmForBone(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone, float[] pivot, net.minecraft.client.model.player.PlayerModel playerModel, net.minecraft.resources.Identifier playerSkin, int packedLight, FpRenderBuffer render)
      Renders the vanilla player arm for the given arm bone, hiding the bone itself but keeping children visible. The pose stack must already be in the model frame and contain the parent chain of the arm (for PAL's first-person rig, fp_player_arms).
    • resetPlayerModelArms

      public static void resetPlayerModelArms()
      Restores the vanilla arm and sleeve parts of the local player's shared model, so the third-person renderer never inherits the first-person rig pose.
    • applyHandTransform

      public static void applyHandTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, boolean isLeftHand)
      Applies the vanilla first-person hand anchor (without equip progress), the frame AzureLib gun rigs are authored against.
    • applyCameraAnchor

      public static void applyCameraAnchor(com.mojang.blaze3d.vertex.PoseStack poseStack)
      Applies the camera anchor: same distance and height as the vanilla hand anchor, but on the view axis, so a rig authored around the model origin renders centred like in Blockbench.
    • applyArmDisplayTransform

      public static void applyArmDisplayTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, float[] translation, float scale)
      Applies the display transform of the item model that owns the arm bones: the translation (in 1/16 block) and uniform scale of a firstperson_* entry.
    • applyRootTransform

      public static void applyRootTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone wholeRig)
      Applies the fp_player_arms root transform, which moves, rotates and scales the whole rig (both arms and both held items) around the model origin.
    • applyRootTransform

      public static void applyRootTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone wholeRig, float[] pivot)
      Applies the animated model root around its own pivot, like AzureLib's prepMatrixForBone.
      Parameters:
      pivot - root pivot in model units (FpRenderState.fpRootPivot)
    • applyCameraTransform

      public static void applyCameraTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone camera)
      Applies the fp_camera transform, which moves, rotates and scales the first-person pass around the view origin. The camera keeps PAL's (+X, -Y, +Z) convention.
    • applyArmTransform

      public static void applyArmTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone arm, float[] pivot)
      Applies an arm bone's full transform in the model frame. This is the same transform used by renderArmForBone(PoseStack, PlayerAnimBone, float[], PlayerModel, Identifier, int, FpRenderBuffer), exposed so a held item can be rendered in exactly the same arm frame.
    • applyItemTransform

      public static void applyItemTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone item)
      Applies the item bone offset in the model frame, keeping the item on the model origin (the fpDisplayAnchor: "hand" convention). A rig authored around the model origin uses applyItemTransform(PoseStack, PlayerAnimBone, float[]) instead.
    • applyItemTransform

      public static void applyItemTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone item, float[] pivot)
      Applies the item bone transform so the item model ends up on the bone itself. Vanilla draws the item's 1x1x1 box around the origin of the frame it is handed, so the box has to be moved to the bone origin before the bone rotation is applied; rotating it about the pivot without that translation would offset it by -R * pivot.
      Parameters:
      pivot - the bone origin in model units, or NO_PIVOT for a rig whose item sits on the model origin
    • applyBoneTransform

      public static void applyBoneTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
      Applies the offset, rotation and scale of a bone around the pose origin.
    • applyBoneTransform

      public static void applyBoneTransform(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone, float[] pivot)
      Applies the offset, pivot, rotation and scale of a bone in one go (same order as RenderUtils.prepMatrixForBone).
      Parameters:
      pivot - rotation centre in model units (raw model space, Y keeps its sign here)
    • translateMatrixToBone

      public static void translateMatrixToBone(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
      Same convention as AzureLib's translateMatrixToBone: X is negated and Y is not, because PAL's loader keeps the raw Blockbench value.
    • translateToPivotPoint

      public static void translateToPivotPoint(com.mojang.blaze3d.vertex.PoseStack poseStack, float[] pivot)
    • rotateMatrixAroundBone

      public static void rotateMatrixAroundBone(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
    • scaleMatrixForBone

      public static void scaleMatrixForBone(com.mojang.blaze3d.vertex.PoseStack poseStack, com.zigythebird.playeranimcore.bones.PlayerAnimBone bone)
    • translateAwayFromPivotPoint

      public static void translateAwayFromPivotPoint(com.mojang.blaze3d.vertex.PoseStack poseStack, float[] pivot)