Skip to content

Commit eed8d6b

Browse files
authored
Update MatrixJointModelTransform.java
1 parent 8751505 commit eed8d6b

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

jme3-core/src/main/java/com/jme3/anim/MatrixJointModelTransform.java

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,71 @@
1+
/*
2+
* Copyright (c) 2009-2025 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
132
package com.jme3.anim;
233

334
import com.jme3.anim.util.JointModelTransform;
435
import com.jme3.math.Matrix4f;
536
import com.jme3.math.Transform;
637

738
/**
8-
* This JointModelTransform implementation accumulate joints transforms in a Matrix4f to properly
9-
* support non uniform scaling in an armature hierarchy
39+
* An implementation of {@link JointModelTransform} that accumulates joint transformations
40+
* into a {@link Matrix4f}. This approach is particularly useful for correctly handling
41+
* non-uniform scaling within an armature hierarchy, as {@code Matrix4f} can represent
42+
* non-uniform scaling directly, unlike {@link Transform}, which typically handles
43+
* uniform scaling.
44+
* <p>
45+
* This class maintains a single {@link Matrix4f} to represent the accumulated
46+
* model-space transform of the joint it's associated with.
1047
*/
1148
public class MatrixJointModelTransform implements JointModelTransform {
1249

13-
final private Matrix4f modelTransformMatrix = new Matrix4f();
14-
final private Transform modelTransform = new Transform();
50+
/**
51+
* The model-space transform of the joint represented as a Matrix4f.
52+
* This matrix accumulates the local transform of the joint and the model transform
53+
* of its parent.
54+
*/
55+
private final Matrix4f modelTransformMatrix = new Matrix4f();
56+
/**
57+
* A temporary Transform instance used for converting the modelTransformMatrix
58+
* to a Transform object when {@link #getModelTransform()} is called.
59+
*/
60+
private final Transform modelTransform = new Transform();
1561

1662
@Override
1763
public void updateModelTransform(Transform localTransform, Joint parent) {
1864
localTransform.toTransformMatrix(modelTransformMatrix);
1965
if (parent != null) {
20-
((MatrixJointModelTransform) parent.getJointModelTransform()).getModelTransformMatrix().mult(modelTransformMatrix, modelTransformMatrix);
66+
MatrixJointModelTransform transform = (MatrixJointModelTransform) parent.getJointModelTransform();
67+
transform.getModelTransformMatrix().mult(modelTransformMatrix, modelTransformMatrix);
2168
}
22-
2369
}
2470

2571
@Override
@@ -31,7 +77,8 @@ public void getOffsetTransform(Matrix4f outTransform, Matrix4f inverseModelBindM
3177
public void applyBindPose(Transform localTransform, Matrix4f inverseModelBindMatrix, Joint parent) {
3278
modelTransformMatrix.set(inverseModelBindMatrix).invertLocal(); // model transform = model bind
3379
if (parent != null) {
34-
((MatrixJointModelTransform) parent.getJointModelTransform()).getModelTransformMatrix().invert().mult(modelTransformMatrix, modelTransformMatrix);
80+
MatrixJointModelTransform transform = (MatrixJointModelTransform) parent.getJointModelTransform();
81+
transform.getModelTransformMatrix().invert().mult(modelTransformMatrix, modelTransformMatrix);
3582
}
3683
localTransform.fromTransformMatrix(modelTransformMatrix);
3784
}

0 commit comments

Comments
 (0)