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

public class SkinnedMesh extends Mesh implements PoseListener
Mesh supporting deformation via skeletal animation.
  • Field Details

    • _weightsPerVert

      protected int _weightsPerVert
      Number of weights per vertex.
    • _gpuUseMatrixAttribute

      protected boolean _gpuUseMatrixAttribute
      If true and we are using gpu skinning, we'll reorder our weights for matrix attribute use.
    • _gpuAttributeSize

      protected int _gpuAttributeSize
      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.
    • _jointIndices

      protected short[] _jointIndices
      Storage for per vertex joint indices. There should be "weightsPerVert" entries per vertex.
    • _jointIndicesBuf

      protected FloatBufferData _jointIndicesBuf
    • _weights

      protected float[] _weights
      Storage 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

      protected FloatBufferData _weightsBuf
    • _bindPoseData

      protected MeshData _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

      protected SkeletonPose _currentPose
      The current skeleton pose we are targeting.
    • _useGPU

      protected boolean _useGPU
      Flag for switching between GPU and CPU skinning.
    • _gpuShader

      protected GLSLShaderObjectsState _gpuShader
      The shader state to update with GLSL attributes/uniforms related to GPU skinning. See class doc for more.
    • _autoUpdateSkinBound

      protected boolean _autoUpdateSkinBound

      Flag 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

      protected SkinPoseApplyLogic _customApplier
      Custom update apply logic.
  • Constructor Details

    • SkinnedMesh

      public SkinnedMesh()
      Constructs a new SkinnedMesh.
    • SkinnedMesh

      public SkinnedMesh(String name)
      Constructs a new SkinnedMesh with a given name.
      Parameters:
      name - the name of the skinned mesh.
  • Method Details

    • getBindPoseData

      public MeshData getBindPoseData()
      Returns:
      the bind pose MeshData object used by this skinned mesh.
    • setBindPoseData

      public void setBindPoseData(MeshData poseData)
      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 (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.
    • 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

      public SkeletonPose getCurrentPose()
      Returns:
      a representation of the pose and skeleton to use for morphing this mesh.
    • setCurrentPose

      public void setCurrentPose(SkeletonPose currentPose)
      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

      public GLSLShaderObjectsState getGPUShader()
      Returns:
      the shader being used for GPU skinning. Must first have been set via setGPUShader(GLSLShaderObjectsState)
    • setGPUShader

      public void setGPUShader(GLSLShaderObjectsState shaderState)
      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

      public SkinPoseApplyLogic getCustomApplier()
      Returns:
      any custom apply logic set on this skin or null if default logic is used.
      See Also:
    • setCustomApplier

      public void setCustomApplier(SkinPoseApplyLogic customApplier)
      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

      public void render(Renderer renderer)
      Override render to allow for GPU/CPU switch
      Specified by:
      render in interface Renderable
      Overrides:
      render in class Mesh
      Parameters:
      renderer - the renderer
    • poseUpdated

      public void poseUpdated(SkeletonPose pose)
      Calls to apply our pose on pose update.
      Specified by:
      poseUpdated in interface PoseListener
      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 class Mesh
    • recreateJointAttributeBuffer

      public void recreateJointAttributeBuffer()
    • recreateWeightAttributeBuffer

      public void recreateWeightAttributeBuffer()
    • makeCopy

      public SkinnedMesh makeCopy(boolean shareGeometricData)
      Description copied from class: Spatial
      Create a copy of this spatial.
      Overrides:
      makeCopy in class Mesh
      Parameters:
      shareGeometricData - if true, reuse any data fields describing the geometric shape of the spatial, as applicable.
      Returns:
      the copy as described.
    • reorderIndices

      public void reorderIndices(IndexBufferData<?> newIndices, IndexMode[] modes, int[] lengths)
      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 class Mesh
      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 class Mesh
      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

      public Class<? extends SkinnedMesh> getClassTag()
      Specified by:
      getClassTag in interface Savable
      Overrides:
      getClassTag in class Mesh
      See Also:
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class Mesh
      Parameters:
      capsule - the capsule
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also:
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class Mesh
      Parameters:
      capsule - the input capsule
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also: