parent
ce170b8b53
commit
e5057ad7fa
@ -0,0 +1,78 @@ |
||||
package com.jme3.anim; |
||||
|
||||
import com.jme3.anim.util.JointModelTransform; |
||||
import com.jme3.export.*; |
||||
import com.jme3.math.Matrix4f; |
||||
import com.jme3.math.Transform; |
||||
import com.jme3.util.clone.Cloner; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* This JointModelTransform implementation accumulate joints transforms in a Matrix4f to properly |
||||
* support non uniform scaling in an armature hierarchy |
||||
*/ |
||||
public class MatrixJointModelTransform implements JointModelTransform { |
||||
|
||||
private Matrix4f modelTransformMatrix = new Matrix4f(); |
||||
private Transform modelTransform = new Transform(); |
||||
|
||||
@Override |
||||
public void updateModelTransform(Transform localTransform, Joint parent) { |
||||
localTransform.toTransformMatrix(modelTransformMatrix); |
||||
if (parent != null) { |
||||
((MatrixJointModelTransform) parent.getJointModelTransform()).getModelTransformMatrix().mult(modelTransformMatrix, modelTransformMatrix); |
||||
} |
||||
modelTransform.fromTransformMatrix(modelTransformMatrix); |
||||
} |
||||
|
||||
public void getOffsetTransform(Matrix4f outTransform, Matrix4f inverseModelBindMatrix) { |
||||
outTransform.set(modelTransformMatrix).mult(inverseModelBindMatrix, outTransform); |
||||
} |
||||
|
||||
@Override |
||||
public void applyBindPose(Transform localTransform, Matrix4f inverseModelBindMatrix, Joint parent) { |
||||
modelTransformMatrix.set(inverseModelBindMatrix).invertLocal(); // model transform = model bind
|
||||
if (parent != null) { |
||||
((MatrixJointModelTransform) parent.getJointModelTransform()).getModelTransformMatrix().invert().mult(modelTransformMatrix, modelTransformMatrix); |
||||
} |
||||
localTransform.fromTransformMatrix(modelTransformMatrix); |
||||
} |
||||
|
||||
public Matrix4f getModelTransformMatrix() { |
||||
return modelTransformMatrix; |
||||
} |
||||
|
||||
@Override |
||||
public Transform getModelTransform() { |
||||
return modelTransform; |
||||
} |
||||
|
||||
@Override |
||||
public void write(JmeExporter ex) throws IOException { |
||||
OutputCapsule oc = ex.getCapsule(this); |
||||
oc.write(modelTransformMatrix, "modelTransformMatrix", new Matrix4f()); |
||||
} |
||||
|
||||
@Override |
||||
public void read(JmeImporter im) throws IOException { |
||||
InputCapsule ic = im.getCapsule(this); |
||||
modelTransformMatrix = (Matrix4f) ic.readSavable("modelTransformMatrix", new Matrix4f()); |
||||
modelTransform.fromTransformMatrix(modelTransformMatrix); |
||||
} |
||||
|
||||
@Override |
||||
public Object jmeClone() { |
||||
try { |
||||
MatrixJointModelTransform clone = (MatrixJointModelTransform) super.clone(); |
||||
return clone; |
||||
} catch (CloneNotSupportedException ex) { |
||||
throw new AssertionError(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void cloneFields(Cloner cloner, Object original) { |
||||
modelTransformMatrix = modelTransformMatrix.clone(); |
||||
} |
||||
} |
@ -0,0 +1,74 @@ |
||||
package com.jme3.anim; |
||||
|
||||
import com.jme3.anim.util.JointModelTransform; |
||||
import com.jme3.export.*; |
||||
import com.jme3.math.Matrix4f; |
||||
import com.jme3.math.Transform; |
||||
import com.jme3.util.clone.Cloner; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* This JointModelTransform implementation accumulates model transform in a Transform class
|
||||
* This does NOT support proper non uniform scale in the armature hierarchy. |
||||
* But the effect might be useful in some circumstances. |
||||
* Note that this is how the old animation system was working, so you might want to use this |
||||
* if your model has non uniform scale and was migrated from old j3o model. |
||||
*/ |
||||
public class SeparateJointModelTransform implements JointModelTransform { |
||||
|
||||
private Transform modelTransform = new Transform(); |
||||
|
||||
@Override |
||||
public void updateModelTransform(Transform localTransform, Joint parent) { |
||||
modelTransform.set(localTransform); |
||||
if (parent != null) { |
||||
modelTransform.combineWithParent(parent.getModelTransform()); |
||||
} |
||||
} |
||||
|
||||
public void getOffsetTransform(Matrix4f outTransform, Matrix4f inverseModelBindMatrix) { |
||||
modelTransform.toTransformMatrix(outTransform).mult(inverseModelBindMatrix, outTransform); |
||||
} |
||||
|
||||
@Override |
||||
public void applyBindPose(Transform localTransform, Matrix4f inverseModelBindMatrix, Joint parent) { |
||||
localTransform.fromTransformMatrix(inverseModelBindMatrix); |
||||
localTransform.invert(); //model transform
|
||||
if (parent != null) { |
||||
localTransform.combineWithParent(parent.getModelTransform().invert()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Transform getModelTransform() { |
||||
return modelTransform; |
||||
} |
||||
|
||||
@Override |
||||
public void write(JmeExporter ex) throws IOException { |
||||
OutputCapsule oc = ex.getCapsule(this); |
||||
oc.write(modelTransform, "modelTransform", new Transform()); |
||||
} |
||||
|
||||
@Override |
||||
public void read(JmeImporter im) throws IOException { |
||||
InputCapsule ic = im.getCapsule(this); |
||||
modelTransform = (Transform) ic.readSavable("modelTransform", new Transform()); |
||||
} |
||||
|
||||
@Override |
||||
public Object jmeClone() { |
||||
try { |
||||
SeparateJointModelTransform clone = (SeparateJointModelTransform) super.clone(); |
||||
return clone; |
||||
} catch (CloneNotSupportedException ex) { |
||||
throw new AssertionError(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void cloneFields(Cloner cloner, Object original) { |
||||
modelTransform = modelTransform.clone(); |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package com.jme3.anim.util; |
||||
|
||||
import com.jme3.anim.Joint; |
||||
import com.jme3.export.Savable; |
||||
import com.jme3.math.Matrix4f; |
||||
import com.jme3.math.Transform; |
||||
import com.jme3.util.clone.JmeCloneable; |
||||
|
||||
/** |
||||
* Implementations of this interface holds accumulated model transform of a Joint. |
||||
* Implementation might choose different accumulation strategy. |
||||
*/ |
||||
public interface JointModelTransform extends JmeCloneable, Savable { |
||||
|
||||
void updateModelTransform(Transform localTransform, Joint parent); |
||||
|
||||
void getOffsetTransform(Matrix4f outTransform, Matrix4f inverseModelBindMatrix); |
||||
|
||||
void applyBindPose(Transform localTransform, Matrix4f inverseModelBindMatrix, Joint parent); |
||||
|
||||
Transform getModelTransform(); |
||||
} |
Loading…
Reference in new issue