Merge meshes in animated models by finding ones that maintain the same
relative position throughout all animations. Also, don't include transforms in the animations for nodes that never move. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@218 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -41,6 +41,7 @@ import com.jme.util.export.InputCapsule;
|
||||
import com.jme.util.export.OutputCapsule;
|
||||
|
||||
import com.threerings.jme.Log;
|
||||
import com.threerings.jme.util.JmeUtil;
|
||||
|
||||
/**
|
||||
* A {@link Node} with a serialization mechanism tailored to stored models.
|
||||
@@ -55,7 +56,7 @@ public class ModelNode extends Node
|
||||
{
|
||||
super("node");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Standard constructor.
|
||||
*/
|
||||
@@ -63,14 +64,14 @@ public class ModelNode extends Node
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
@Override // documentation inherited
|
||||
public int hashCode ()
|
||||
{
|
||||
// hash on the name rather than the identity for consistent ordering
|
||||
return getName().hashCode();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursively searches the scene graph rooted at this node for a
|
||||
* node with the provided name.
|
||||
@@ -90,7 +91,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a reference to the model space transform of the node.
|
||||
*/
|
||||
@@ -98,7 +99,7 @@ public class ModelNode extends Node
|
||||
{
|
||||
return _modelTransform;
|
||||
}
|
||||
|
||||
|
||||
@Override // documentation inherited
|
||||
public void updateWorldData (float time)
|
||||
{
|
||||
@@ -108,7 +109,7 @@ public class ModelNode extends Node
|
||||
super.updateWorldData(time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override // documentation inherited
|
||||
public void updateWorldBound ()
|
||||
{
|
||||
@@ -117,22 +118,22 @@ public class ModelNode extends Node
|
||||
super.updateWorldBound();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override // documentation inherited
|
||||
public void updateWorldVectors ()
|
||||
{
|
||||
super.updateWorldVectors();
|
||||
if (parent instanceof ModelNode) {
|
||||
setTransform(getLocalTranslation(), getLocalRotation(),
|
||||
JmeUtil.setTransform(getLocalTranslation(), getLocalRotation(),
|
||||
getLocalScale(), _localTransform);
|
||||
((ModelNode)parent).getModelTransform().mult(_localTransform,
|
||||
_modelTransform);
|
||||
|
||||
|
||||
} else {
|
||||
_modelTransform.loadIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface ModelSpatial
|
||||
public Spatial putClone (Spatial store, Model.CloneCreator properties)
|
||||
{
|
||||
@@ -178,7 +179,7 @@ public class ModelNode extends Node
|
||||
mstore._hasVisibleDescendants = _hasVisibleDescendants;
|
||||
return mstore;
|
||||
}
|
||||
|
||||
|
||||
@Override // documentation inherited
|
||||
public void read (JMEImporter im)
|
||||
throws IOException
|
||||
@@ -198,7 +199,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override // documentation inherited
|
||||
public void write (JMEExporter ex)
|
||||
throws IOException
|
||||
@@ -210,7 +211,7 @@ public class ModelNode extends Node
|
||||
capsule.write(getLocalScale(), "localScale", null);
|
||||
capsule.writeSavableArrayList(getChildren(), "children", null);
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface ModelSpatial
|
||||
public void expandModelBounds ()
|
||||
{
|
||||
@@ -221,7 +222,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface ModelSpatial
|
||||
public void setReferenceTransforms ()
|
||||
{
|
||||
@@ -233,7 +234,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface ModelSpatial
|
||||
public void lockStaticMeshes (
|
||||
Renderer renderer, boolean useVBOs, boolean useDisplayLists)
|
||||
@@ -246,7 +247,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface ModelSpatial
|
||||
public void resolveTextures (TextureProvider tprov)
|
||||
{
|
||||
@@ -257,7 +258,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface ModelSpatial
|
||||
public void storeMeshFrame (int frameId, boolean blend)
|
||||
{
|
||||
@@ -268,7 +269,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface ModelSpatial
|
||||
public void setMeshFrame (int frameId)
|
||||
{
|
||||
@@ -279,7 +280,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// documentation inherited from interface ModelSpatial
|
||||
public void blendMeshFrames (int frameId1, int frameId2, float alpha)
|
||||
{
|
||||
@@ -291,7 +292,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether this node should be culled even if it has mesh
|
||||
* descendants.
|
||||
@@ -300,7 +301,7 @@ public class ModelNode extends Node
|
||||
{
|
||||
_forceCull = force;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether this node should be culled even if it has mesh
|
||||
* descendants.
|
||||
@@ -309,7 +310,7 @@ public class ModelNode extends Node
|
||||
{
|
||||
return _forceCull;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the cull state of any nodes that do not contain geometric
|
||||
* descendants to {@link CULL_ALWAYS} so that they don't waste
|
||||
@@ -330,7 +331,7 @@ public class ModelNode extends Node
|
||||
updateCullMode();
|
||||
return _hasVisibleDescendants;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Locks the transforms and bounds of this instance with the assumption
|
||||
* that the position will never change.
|
||||
@@ -344,14 +345,14 @@ public class ModelNode extends Node
|
||||
{
|
||||
updateWorldVectors();
|
||||
lockedMode |= LOCKED_TRANSFORMS;
|
||||
|
||||
|
||||
boolean containsTargets = false;
|
||||
for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
|
||||
Spatial child = getChild(ii);
|
||||
if (targets.contains(child) || (child instanceof ModelNode &&
|
||||
((ModelNode)child).lockInstance(targets))) {
|
||||
containsTargets = true;
|
||||
|
||||
|
||||
} else if (child instanceof ModelMesh) {
|
||||
((ModelMesh)child).lockInstance();
|
||||
}
|
||||
@@ -364,7 +365,7 @@ public class ModelNode extends Node
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursively culls all model nodes under this one in preparation for
|
||||
* activating the ones listed in an animation.
|
||||
@@ -379,7 +380,7 @@ public class ModelNode extends Node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Makes this node visible if and only if it has visible descendants and
|
||||
* has not been specifically culled.
|
||||
@@ -389,42 +390,16 @@ public class ModelNode extends Node
|
||||
setCullMode((_hasVisibleDescendants && !_forceCull) ?
|
||||
CULL_INHERIT : CULL_ALWAYS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a matrix to the transform defined by the given translation,
|
||||
* rotation, and scale values.
|
||||
*/
|
||||
protected static Matrix4f setTransform (
|
||||
Vector3f translation, Quaternion rotation, Vector3f scale,
|
||||
Matrix4f result)
|
||||
{
|
||||
result.setRotationQuaternion(rotation);
|
||||
result.setTranslation(translation);
|
||||
|
||||
result.m00 *= scale.x;
|
||||
result.m01 *= scale.y;
|
||||
result.m02 *= scale.z;
|
||||
|
||||
result.m10 *= scale.x;
|
||||
result.m11 *= scale.y;
|
||||
result.m12 *= scale.z;
|
||||
|
||||
result.m20 *= scale.x;
|
||||
result.m21 *= scale.y;
|
||||
result.m22 *= scale.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/** The node's transform in local and model space. */
|
||||
protected Matrix4f _localTransform = new Matrix4f(),
|
||||
_modelTransform = new Matrix4f();
|
||||
|
||||
/** Whether or not this node has mesh descendants. */
|
||||
protected boolean _hasVisibleDescendants;
|
||||
|
||||
|
||||
/** If true, cull the node even if it has mesh descendants. */
|
||||
protected boolean _forceCull;
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user