When transforming bones into mesh space to deform the skin, use the
mesh's transform in the reference position rather than its current transform. Otherwise, when we try to scale the mesh up, the bones get scaled down, and the scale goes away. Also fixed a couple minor bugs in the viewer. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4182 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -536,6 +536,15 @@ public class Model extends ModelNode
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the currently running animation, or
|
||||
* <code>null</code> if no animation is running.
|
||||
*/
|
||||
public Animation getAnimation ()
|
||||
{
|
||||
return _anim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the currently running animation.
|
||||
*/
|
||||
|
||||
@@ -209,6 +209,7 @@ public class SkinMesh extends ModelMesh
|
||||
properties.addProperty("displaylistid");
|
||||
mstore._frames = _frames;
|
||||
mstore._useDisplayLists = _useDisplayLists;
|
||||
mstore._invRefTransform = _invRefTransform;
|
||||
mstore._bones = new Bone[_bones.length];
|
||||
HashMap<Bone, Bone> bmap = new HashMap<Bone, Bone>();
|
||||
for (int ii = 0; ii < _bones.length; ii++) {
|
||||
@@ -254,11 +255,18 @@ public class SkinMesh extends ModelMesh
|
||||
@Override // documentation inherited
|
||||
public void setReferenceTransforms ()
|
||||
{
|
||||
updateWorldVectors();
|
||||
_modelTransform.invert(_transform);
|
||||
_invRefTransform = new Matrix4f();
|
||||
if (parent instanceof ModelNode) {
|
||||
Matrix4f transform = new Matrix4f();
|
||||
ModelNode.setTransform(getLocalTranslation(), getLocalRotation(),
|
||||
getLocalScale(), transform);
|
||||
((ModelNode)parent).getModelTransform().mult(transform,
|
||||
_invRefTransform);
|
||||
_invRefTransform.invertLocal();
|
||||
}
|
||||
for (Bone bone : _bones) {
|
||||
bone.invRefTransform =
|
||||
_transform.mult(bone.node.getModelTransform()).invert();
|
||||
_invRefTransform.mult(bone.node.getModelTransform()).invert();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,21 +319,6 @@ public class SkinMesh extends ModelMesh
|
||||
nbuf.put(_nbuf);
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
public void updateWorldVectors ()
|
||||
{
|
||||
super.updateWorldVectors();
|
||||
if (parent instanceof ModelNode) {
|
||||
ModelNode.setTransform(getLocalTranslation(), getLocalRotation(),
|
||||
getLocalScale(), _transform);
|
||||
((ModelNode)parent).getModelTransform().mult(_transform,
|
||||
_modelTransform);
|
||||
|
||||
} else {
|
||||
_modelTransform.loadIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
public void updateWorldData (float time)
|
||||
{
|
||||
@@ -334,9 +327,9 @@ public class SkinMesh extends ModelMesh
|
||||
return;
|
||||
}
|
||||
// update the bone transforms
|
||||
_modelTransform.invert(_transform);
|
||||
for (Bone bone : _bones) {
|
||||
_transform.mult(bone.node.getModelTransform(), bone.transform);
|
||||
_invRefTransform.mult(bone.node.getModelTransform(),
|
||||
bone.transform);
|
||||
bone.transform.multLocal(bone.invRefTransform);
|
||||
}
|
||||
|
||||
@@ -474,6 +467,9 @@ public class SkinMesh extends ModelMesh
|
||||
* meshes. */
|
||||
protected boolean _useDisplayLists;
|
||||
|
||||
/** The inverse of the model space reference transform. */
|
||||
protected Matrix4f _invRefTransform;
|
||||
|
||||
/** The groups of vertices influenced by different sets of bones. */
|
||||
protected WeightGroup[] _weightGroups;
|
||||
|
||||
@@ -492,12 +488,6 @@ public class SkinMesh extends ModelMesh
|
||||
/** Whether or not the stored frame id will be used for blending. */
|
||||
protected boolean _storeBlend;
|
||||
|
||||
/** The node's transform in model space. */
|
||||
protected Matrix4f _modelTransform = new Matrix4f();
|
||||
|
||||
/** Working transform. */
|
||||
protected Matrix4f _transform = new Matrix4f();
|
||||
|
||||
/** A dummy mesh that simply hold transformation values. */
|
||||
protected static final TriMesh DUMMY_MESH = new TriMesh();
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ public class ModelViewer extends JmeCanvasApp
|
||||
if (_model.hasAnimation(anim)) {
|
||||
_model.startAnimation(anim);
|
||||
} else { // it's a sequence
|
||||
if (_sequence != null) {
|
||||
if (_model.getAnimation() != null) {
|
||||
_sequence = null;
|
||||
_model.stopAnimation();
|
||||
}
|
||||
@@ -385,6 +385,7 @@ public class ModelViewer extends JmeCanvasApp
|
||||
_ctx.getGeometry().setRenderState(mstate);
|
||||
_ctx.getGeometry().setRenderState(
|
||||
_wfstate = _ctx.getRenderer().createWireframeState());
|
||||
_ctx.getGeometry().setNormalsMode(Spatial.NM_GL_NORMALIZE_PROVIDED);
|
||||
_wfstate.setEnabled(false);
|
||||
|
||||
// create a grid on the XY plane to provide some reference
|
||||
|
||||
Reference in New Issue
Block a user