Class SkinnedMesh
java.lang.Object
com.ardor3d.scenegraph.Spatial
com.ardor3d.scenegraph.Mesh
com.ardor3d.extension.animation.skeletal.SkinnedMesh
- All Implemented Interfaces:
PoseListener
,Pickable
,Hintable
,Renderable
,Savable
Mesh supporting deformation via skeletal animation.
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Flag for enabling automatically updating the skin's model bound when the pose changes.protected MeshData
The original bind pose form of this SkinnedMesh.protected SkeletonPose
The current skeleton pose we are targeting.protected SkinPoseApplyLogic
Custom update apply logic.protected int
Size to pad our attributes to.protected GLSLShaderObjectsState
The shader state to update with GLSL attributes/uniforms related to GPU skinning.protected boolean
If true and we are using gpu skinning, we'll reorder our weights for matrix attribute use.protected short[]
Storage for per vertex joint indices.protected FloatBufferData
protected boolean
Flag for switching between GPU and CPU skinning.protected float[]
Storage for per vertex joint indices.protected FloatBufferData
protected int
Number of weights per vertex.Fields inherited from class com.ardor3d.scenegraph.Mesh
_defaultColor, _isVisible, _lightState, _meshData, _modelBound, _states, RENDER_VERTEX_ONLY
Fields inherited from class com.ardor3d.scenegraph.Spatial
_controllers, _delegateMap, _dirtyMark, _frustumIntersects, _listener, _localTransform, _name, _parent, _queueDistance, _renderStateList, _sceneHints, _userData, _worldBound, _worldTransform, ON_DIRTY_ATTACHED, ON_DIRTY_BOUNDING, ON_DIRTY_RENDERSTATE, ON_DIRTY_TRANSFORM, ON_DIRTY_TRANSFORM_ONLY
-
Constructor Summary
ConstructorDescriptionConstructs a new SkinnedMesh.SkinnedMesh
(String name) Constructs a new SkinnedMesh with a given name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Apply skinning values for CPU skinning.void
constrainWeightCount
(int maxCount) Rewrites the weights on this SkinnedMesh, if necessary, to reduce the number of weights per vert to the given max.Class
<? extends SkinnedMesh> int
short[]
float[]
int
boolean
boolean
boolean
isUseGPU()
makeCopy
(boolean shareGeometricData) Create a copy of this spatial.void
poseUpdated
(SkeletonPose pose) Calls to apply our pose on pose update.void
read
(InputCapsule capsule) void
void
void
Override render to allow for GPU/CPU switchvoid
reorderIndices
(IndexBufferData<?> newIndices, IndexMode[] modes, int[] lengths) Let this mesh know we want to change its indices to the provided new order.void
reorderVertexData
(int[] newVertexOrder) Swap around the order of the vertex data in this Mesh.void
setAutoUpdateSkinBounds
(boolean autoUpdateSkinBound) void
setBindPoseData
(MeshData poseData) Sets the bind pose mesh data object used by this skinned mesh.void
setCurrentPose
(SkeletonPose currentPose) void
setCustomApplier
(SkinPoseApplyLogic customApplier) Set custom logic for how this skin should react when it is told its pose has updated.void
setGpuAttributeSize
(int size) void
setGPUShader
(GLSLShaderObjectsState shaderState) void
setGpuUseMatrixAttribute
(boolean useMatrix) void
setJointIndices
(short[] jointIndices) Sets the joint indices used by this skinned mesh to compute mesh deformation.void
setUseGPU
(boolean useGPU) This should be set after setting up gpu attribute params.void
setWeights
(float[] weights) Sets the joint weights used by this skinned mesh.void
setWeightsPerVert
(int weightsPerVert) protected void
void
Recalculate the local bounding volume of this Mesh to fit its vertices.protected void
void
write
(OutputCapsule capsule) Methods inherited from class com.ardor3d.scenegraph.Mesh
applyWorldRenderStates, draw, getDefaultColor, getLightState, getMeshData, getModelBound, getModelBound, getWorldNormals, getWorldRenderState, getWorldVectors, intersectsPrimitivesWhere, intersectsWorldBound, intersectsWorldBoundsWhere, isVisible, makeInstanced, render, renderArrays, renderVBO, reorderVertexData, setDefaultColor, setDefaultColor, setLightState, setMeshData, setModelBound, setModelBound, setRandomColors, setSolidColor, setVisible, sortLights, supportsBoundsIntersectionRecord, supportsPrimitivesIntersectionRecord, updateWorldBound
Methods inherited from class com.ardor3d.scenegraph.Spatial
acceptVisitor, addController, addTranslation, addTranslation, clearControllers, clearDirty, clearDirty, clearRenderState, getController, getControllerCount, getControllers, getCurrentRenderDelegate, getLastFrustumIntersection, getListener, getLocalLastFrustumIntersection, getLocalRenderState, getLocalRenderStates, getName, getParent, getParentHintable, getRenderDelegate, getRotation, getScale, getSceneHints, getTransform, getTranslation, getUserData, getWorldBound, getWorldRotation, getWorldScale, getWorldTransform, getWorldTranslation, hasAncestor, isDirty, localToWorld, markDirty, markDirty, onDraw, propagateBoundToRoot, propagateDirtyDown, propagateDirtyUp, propagateStatesFromRoot, propageEventUp, removeController, removeController, removeFromParent, setLastFrustumIntersection, setListener, setName, setParent, setRenderDelegate, setRenderState, setRotation, setRotation, setScale, setScale, setScale, setTransform, setTranslation, setTranslation, setUserData, setWorldRotation, setWorldRotation, setWorldScale, setWorldScale, setWorldScale, setWorldTransform, setWorldTranslation, setWorldTranslation, toString, updateChildren, updateControllers, updateGeometricState, updateGeometricState, updateWorldRenderStates, updateWorldRenderStates, updateWorldTransform, worldToLocal
-
Field Details
-
_weightsPerVert
protected int _weightsPerVertNumber of weights per vertex. -
_gpuUseMatrixAttribute
protected boolean _gpuUseMatrixAttributeIf true and we are using gpu skinning, we'll reorder our weights for matrix attribute use. -
_gpuAttributeSize
protected int _gpuAttributeSizeSize to pad our attributes to. If we are using matrices (seesetGpuUseMatrixAttribute(boolean)
) then this is the size of an edge of the matrix. eg. 4 would mean either a vec4 or a mat4 object is expected in the shader. -
_jointIndices
protected short[] _jointIndicesStorage for per vertex joint indices. There should be "weightsPerVert" entries per vertex. -
_jointIndicesBuf
-
_weights
protected float[] _weightsStorage for per vertex joint indices. These should already be normalized (all joints affecting the vertex add to 1.) There should be "weightsPerVert" entries per vertex. -
_weightsBuf
-
_bindPoseData
The original bind pose form of this SkinnedMesh. When doing CPU skinning, this will be used as a source and the destination will go into the normal _meshData field for rendering. For GPU skinning, _meshData will be ignored and only _bindPose will be sent to the card. -
_currentPose
The current skeleton pose we are targeting. -
_useGPU
protected boolean _useGPUFlag for switching between GPU and CPU skinning. -
_gpuShader
The shader state to update with GLSL attributes/uniforms related to GPU skinning. See class doc for more. -
_autoUpdateSkinBound
protected boolean _autoUpdateSkinBoundFlag for enabling automatically updating the skin's model bound when the pose changes. Only effective in CPU skinning mode. Default is false as this is currently expensive.
XXX: If we can find a better way to update the bounds, maybe we should make this default to true or remove this altogether. -
_customApplier
Custom update apply logic.
-
-
Constructor Details
-
SkinnedMesh
public SkinnedMesh()Constructs a new SkinnedMesh. -
SkinnedMesh
Constructs a new SkinnedMesh with a given name.- Parameters:
name
- the name of the skinned mesh.
-
-
Method Details
-
getBindPoseData
- Returns:
- the bind pose MeshData object used by this skinned mesh.
-
setBindPoseData
Sets the bind pose mesh data object used by this skinned mesh.- Parameters:
poseData
- the new bind pose
-
getWeightsPerVert
public int getWeightsPerVert()- Returns:
- the number of weights and jointIndices this skin uses per vertex.
-
setWeightsPerVert
public void setWeightsPerVert(int weightsPerVert) - Parameters:
weightsPerVert
- the number of weights and jointIndices this skin should use per vertex. Make sure this value matches up with the contents of jointIndices and weights.
-
isGpuUseMatrixAttribute
public boolean isGpuUseMatrixAttribute()- Returns:
- true if we should use a matrix to send joints and weights to a gpu shader.
-
setGpuUseMatrixAttribute
public void setGpuUseMatrixAttribute(boolean useMatrix) - Parameters:
useMatrix
- true if we should use a matrix to send joints and weights to a gpu shader.
-
getGpuAttributeSize
public int getGpuAttributeSize()- Returns:
- size to pad our attributes to. If we are using matrices (see
setGpuUseMatrixAttribute(boolean)
) then this is the size of an edge of the matrix. eg. 4 would mean either a vec4 or a mat4 object is expected in the shader.
-
setGpuAttributeSize
public void setGpuAttributeSize(int size) - Parameters:
size
- Size to pad our attributes to. If we are using matrices (seesetGpuUseMatrixAttribute(boolean)
) then this is the size of an edge of the matrix. eg. 4 would mean either a vec4 or a mat4 object is expected in the shader.
-
getJointIndices
public short[] getJointIndices()- Returns:
- this skinned mesh's joint influences as indices into a Skeleton's Joint array.
- See Also:
-
setJointIndices
public void setJointIndices(short[] jointIndices) Sets the joint indices used by this skinned mesh to compute mesh deformation. Each entry is interpreted as an 16bit signed integer index into a Skeleton's Joint.- Parameters:
jointIndices
- the joint indices
-
getWeights
public float[] getWeights()- Returns:
- this skinned mesh's joint weights.
- See Also:
-
setWeights
public void setWeights(float[] weights) Sets the joint weights used by this skinned mesh.- Parameters:
weights
- the new weights.
-
getCurrentPose
- Returns:
- a representation of the pose and skeleton to use for morphing this mesh.
-
setCurrentPose
- Parameters:
currentPose
- the representation responsible for the pose and skeleton to use for morphing this mesh.
-
isAutoUpdateSkinBounds
public boolean isAutoUpdateSkinBounds()- Returns:
- true if we should automatically update our model bounds when our pose updates. If useGPU is true, bounds are ignored.
-
setAutoUpdateSkinBounds
public void setAutoUpdateSkinBounds(boolean autoUpdateSkinBound) - Parameters:
autoUpdateSkinBound
- true if we should automatically update our model bounds when our pose updates. If useGPU is true, bounds are ignored.
-
isUseGPU
public boolean isUseGPU()- Returns:
- true if we are doing skinning on the card (GPU) or false if on the CPU.
-
setUseGPU
public void setUseGPU(boolean useGPU) This should be set after setting up gpu attribute params.- Parameters:
useGPU
- true if we should do skinning on the card (GPU) or false if on the CPU.
-
updateWeightsAndJointsOnGPUShader
protected void updateWeightsAndJointsOnGPUShader() -
updateJointPaletteOnGPUShader
protected void updateJointPaletteOnGPUShader() -
getGPUShader
- Returns:
- the shader being used for GPU skinning. Must first have been set via
setGPUShader(GLSLShaderObjectsState)
-
setGPUShader
- Parameters:
shaderState
- the shader to use for GPU skinning. Should be set up to accept vec4 attributes "Weights" and "JointIDs" and a mat4[] uniform called "JointPalette". Applies the renderstate to this mesh as well.
-
getCustomApplier
- Returns:
- any custom apply logic set on this skin or null if default logic is used.
- See Also:
-
setCustomApplier
Set custom logic for how this skin should react when it is told its pose has updated. This might include throttling skin application, ignoring skin application when the skin is outside of the camera view, etc. If null, (the default) the skin will always apply the new pose and optionally update the model bound.- Parameters:
customApplier
- the new custom logic, or null to use the default behavior.
-
applyPose
public void applyPose()Apply skinning values for CPU skinning. -
render
Override render to allow for GPU/CPU switch- Specified by:
render
in interfaceRenderable
- Overrides:
render
in classMesh
- Parameters:
renderer
- the renderer
-
poseUpdated
Calls to apply our pose on pose update.- Specified by:
poseUpdated
in interfacePoseListener
- Parameters:
pose
- the pose that was updated.
-
updateModelBound
public void updateModelBound()Description copied from class:Mesh
Recalculate the local bounding volume of this Mesh to fit its vertices.- Overrides:
updateModelBound
in classMesh
-
recreateJointAttributeBuffer
public void recreateJointAttributeBuffer() -
recreateWeightAttributeBuffer
public void recreateWeightAttributeBuffer() -
makeCopy
Description copied from class:Spatial
Create a copy of this spatial. -
reorderIndices
Description copied from class:Mesh
Let this mesh know we want to change its indices to the provided new order. Override this to provide extra functionality for sub types as needed.- Overrides:
reorderIndices
in classMesh
- Parameters:
newIndices
- the IntBufferData to switch to.modes
- the new segment modes to use.lengths
- the new lengths to use.
-
reorderVertexData
public void reorderVertexData(int[] newVertexOrder) Description copied from class:Mesh
Swap around the order of the vertex data in this Mesh. This is usually called by a tool that has attempted to determine a more optimal order for vertex data.- Overrides:
reorderVertexData
in classMesh
- Parameters:
newVertexOrder
- a mapping to the desired new order, where the current location of a vertex is the index into this array and the value at that location in the array is the new location to store the vertex data.
-
constrainWeightCount
public void constrainWeightCount(int maxCount) Rewrites the weights on this SkinnedMesh, if necessary, to reduce the number of weights per vert to the given max. This is done by dropping the least significant weight and balancing the remainder to total 1.0 again.- Parameters:
maxCount
- the desired maximum weightsPerVert. If this is greater than or equal to the current weightsPerVert, this method is a NOOP.
-
getClassTag
- Specified by:
getClassTag
in interfaceSavable
- Overrides:
getClassTag
in classMesh
- See Also:
-
write
- Specified by:
write
in interfaceSavable
- Overrides:
write
in classMesh
- Parameters:
capsule
- the capsule- Throws:
IOException
- Signals that an I/O exception has occurred.- See Also:
-
read
- Specified by:
read
in interfaceSavable
- Overrides:
read
in classMesh
- Parameters:
capsule
- the input capsule- Throws:
IOException
- Signals that an I/O exception has occurred.- See Also:
-