ObjectMeshSkinned Class
Interface for object mesh skinned handling. See also the UnigineScript analog.
To use this class, include the UnigineObjectMeshSkinned.h file.
ObjectMeshSkinned Class
Members
ObjectMeshSkinned (const Ptr<Mesh> & mesh)
Arguments
- const Ptr<Mesh> & mesh
ObjectMeshSkinned (const char * name, int dynamic = 0)
Arguments
- const char * name
- int dynamic
int getTargetIndex (int target, int surface)
Returns the weight of the animation target.Arguments
- int target - Target number.
- int surface - Surface number.
Return value
Index of the animation target.void setLayerWeight (int layer, float weight)
Sets a weight for the animation layer.Arguments
- int layer - Layer number.
- float weight - Layer weight.
int getLoop ()
Returns a value indicating if the animation is looped. 1 if the animation is looped; otherwise - 0.Return value
The loop flag.void setWorldBoneChildrenTransform (int bone, const Math::Mat4 & transform)
Applies transformation to a given bone in the world space coordinates. All child bones will recalculate their matrices.Arguments
- int bone - Bone number.
- const Math::Mat4 & transform - Transformation matrix in the world space.
void setTIndex (int num, int index, int surface)
Updates a triangle index.Arguments
- int num - Index number in the index buffer.
- int index - Triangle index.
- int surface - Surface number.
void setTargetIndex (int target, int index, int surface)
Sets an index for the animation target.Arguments
- int target - Target number.
- int index - Target index.
- int surface - Surface number.
void copyLayer (int layer, int layer_0)
Copies transformations of bones from the source layer to the destination one.- If the destination layer has more bones than the source one, those bones will have old transformations.
- If the source layer has more bones than destination one, those bones will be added to the destination layer.
Arguments
- int layer - Number of the destination layer in range from 0 to the total number of animation layers.
- int layer_0 - Number of the source layer in range from 0 to the total number of animation layers.
Math::vec3 getVertex (int num, int surface, int target = 0)
Returns coordinate of a given vertex.Arguments
- int num - Vertex number.
- int surface - Surface number.
- int target - Target number.
Return value
Vertex coordinate.void setMeshName (const char * name)
Sets the mesh name.Arguments
- const char * name - The name of the mesh.
int setAnimation (int layer, int animation)
Sets the animation name on the given animation layer.Arguments
- int layer - Layer number.
- int animation - Animation name.
Return value
Math::mat4 getBoneBindTransform (int bone)
Returns bind pose bone transformation matrix.Arguments
- int bone - Bone number.
Return value
Bind pose transformation matrix.void play ()
Continues playback of the animation, if it was paused, or starts playback if it was stopped.int getMeshSurface (const Ptr<Mesh> & mesh, int surface, int target = -1)
Gets the mesh surface from the current meshArguments
- const Ptr<Mesh> & mesh - Mesh pointer to copy a surface into.
- int surface - Mesh surface number to copy.
- int target - Mesh target number to copy.
Return value
Number of the added mesh surface.void setTargetEnabled (int target, int enabled, int surface)
Enables or disables a given animation target.Arguments
- int target - Target number.
- int enabled - 1 to enable the animation target, 0 to disable it.
- int surface - Surface number.
Math::mat4 getIBoneTransform (int bone)
Returns an inverse transformation matrix for a given bone relatively to the parent object.Arguments
- int bone - Bone number.
Return value
Inverse transformation matrix.int isStopped ()
Returns stop status.Return value
1 if animation is stopped; otherwise, 0.void setNumTexCoords1 (int num, int surface)
Sets the number of second texture coordinates.Arguments
- int num - Number of second texture coordinates.
- int surface - Surface number.
void setTime (float time)
Sets the animation time, in animation frames. The time count starts from the zero frame. If the time is set to be between frames, animation is blended. If the time is set outside the animation frame range, the animation is looped.The setTime() function corresponds to the Play and Stop options in the editor. In all other cases use setFrame() to set the animation.
Arguments
- float time - Animation time.
Math::mat4 getLayerBoneTransform (int layer, int bone)
Returns a transformation matrix of a given bone relatively to the parent object. The difference fromgetBoneTransform() is that this method takes into account only the transformation in the animation layer (no blending is done).Arguments
- int layer - Layer number.
- int bone - Bone number.
Return value
Transformation matrix.void setControlled (int controlled)
Sets a value indicating if the animation should be controlled by a parent ObjectMeshSkinned (useful for attaching clothes to a character body).Arguments
- int controlled - Control flag
void setNumLayers (int layers)
Sets the number of animation layers for blending. For example, when two layers are blended, bone transformations in between the layers are interpolated, and vertex positions can be calculated using the interpolated results. For more details, see the article on Skinned Mesh.Arguments
- int layers - Number of animation layers (must be greater than 0).
int getNumCIndices (int surface)
Returns the number of coordinate indices.Arguments
- int surface - Surface number.
Return value
Number of coordinate indices.void clearLayer (int layer)
Clears a given animation layer.Arguments
- int layer - Layer number.
int addLayer ()
Adds an animation layer.Return value
Number of the added layer.Math::Mat4 getWorldBoneTransform (int bone)
Returns the current transformation matrix applied to the bone in the world space coordinate.Arguments
- int bone - Bone number.
Return value
World transformation matrix in the world space.int getFrameTo (int layer)
Returns the end frame passed to the last setFrame() call.Arguments
- int layer - Layer number.
Return value
End frame.Math::mat4 getBoneTransform (int bone)
Returns a transformation matrix for a given bone relatively to the parent object.Arguments
- int bone - Bone number.
Return value
Transformation matrix.int getNumSurfaceTargets (int surface)
Returns the number of surface targets.Arguments
- int surface - Surface number.
Return value
Number of surface targets.void setTexCoord0 (int num, const Math::vec2 & texcoord, int surface)
Updates first texture coordinate.Arguments
- int num - Vertex number.
- const Math::vec2 & texcoord - Second texture coordinate.
- int surface - Surface number.
int addMeshSurface (const char * name, const Ptr<ObjectMeshSkinned> & mesh, int surface, int target = -1)
Appends a new mesh surface to the current mesh.Arguments
- const char * name - Name of the new surface of the current mesh.
- const Ptr<ObjectMeshSkinned> & mesh - Mesh pointer to copy a surface from.
- int surface - Mesh surface number to copy.
- int target - Mesh target number to copy.
Return value
Number of the added mesh surface.int createMesh (const char * name, int dynamic = 0)
Creates a mesh.Arguments
- const char * name - Path to the mesh file.
- int dynamic - Create dynamic mesh.
Return value
Returns 1 if the mesh is loaded successfully; otherwise, 0.int getNumVertex (int surface)
Returns the number of vertices in a given mesh surface.Arguments
- int surface - Surface number.
Return value
Number of the surface vertices.int loadMesh (const char * name)
Loads a mesh file.Arguments
- const char * name - Mesh file name.
Return value
Returns 1 if the mesh is loaded successfully; otherwise, 0.int getTIndex (int num, int surface)
Returns a triangle index.Arguments
- int num - Index number in the index buffer.
- int surface - Surface number.
Return value
Triangle index.int addMeshSurface (int dest_surface, const Ptr<ObjectMeshSkinned> & mesh, int surface, int target = -1)
Appends a new mesh surface to the current mesh.Arguments
- int dest_surface - Name of the new surface of the current mesh.
- const Ptr<ObjectMeshSkinned> & mesh - Mesh pointer to copy a surface from.
- int surface - Mesh surface number to copy.
- int target - Mesh target number to copy.
Return value
Number of the added mesh surface.void setWorldBoneTransform (int bone, const Math::Mat4 & transform)
Applies transformation to a given bone in the world space coordinates.Arguments
- int bone - Bone number.
- const Math::Mat4 & transform - Transformation matrix in the world space.
int addEmptySurface (const char * name, int num_vertex, int num_indices)
Appends a new surface into the mesh.Arguments
- const char * name - New surface name.
- int num_vertex - Number of surface vertices.
- int num_indices - Number of surface indices.
Return value
Appended surface number.int getAnimationID (int num)
Returns the identifier of the animation at the specified position.Arguments
- int num - Animation number.
Return value
Animation identifier.int addSurfaceTarget (int surface, const char * name = 0)
Appends a surface target into the mesh.Arguments
- int surface - Surface number.
- const char * name - New target name.
Return value
Appended target number.float getSpeed ()
Returns a multiplier for animation playback time.Return value
A multiplier value.void setTarget (int target, int enabled, int index, float weight, int surface)
Sets all parameters to a given animation target.Arguments
- int target - Target number.
- int enabled - Target enabled.
- int index - Target index.
- float weight - Target weight.
- int surface - Surface number.
int addMeshSurface (const char * name, const Ptr<Mesh> & mesh, int surface, int target = -1)
Appends a new mesh surface to the current mesh.Arguments
- const char * name - Name of the new surface of the current mesh.
- const Ptr<Mesh> & mesh - Mesh pointer to copy a surface from.
- int surface - Mesh surface number to copy.
- int target - Mesh target number to copy.
Return value
Number of the added mesh surface.void setNumTargets (int num, int surface)
Sets the number of animation targets.Arguments
- int num - Number of animation targets.
- int surface - Surface number.
int getAnimation (int layer)
Returns the animation identifier from the given animation layer.Arguments
- int layer - Layer number.
Return value
Animation identifier.int addTarget (int surface)
Adds an animation target.Arguments
- int surface - Surface number.
Return value
Number of the added target.void inverseLayer (int layer, int layer_0)
Copies inverse transformations of bones from the source layer to the destination one. Note that the destination layer is not cleared before writing to it.Arguments
- int layer - Number of the destination layer in range from 0 to the total number of animation layers.
- int layer_0 - Number of the source layer in range from 0 to the total number of animation layers.
int getFrameFrom (int layer)
Returns the start frame passed to the last setFrame() call.Arguments
- int layer - Layer number.
Return value
Start frame.int getNumColors (int surface)
Returns the number of vertex colors.Arguments
- int surface - Surface number.
Return value
Number of vertex colors.int getNumAnimationFrames (int animation)
Returns the number of animation frames.Arguments
- int animation - Number of the animation.
Return value
Number of animation frames.int getNumFrames (int layer)
Returns the number of animation frames in the layer.Arguments
- int layer - The number of the layer.
Return value
Number of animation frames.int getNumBones ()
Returns the number of bones taking part in animation.Return value
Number of bones.int addAnimation (const Ptr<Mesh> & mesh, const char * animation = 0)
Loads the additional animation from an external file.Arguments
- const Ptr<Mesh> & mesh - Path to the animation file.
- const char * animation - Animation name.
Return value
Animation identifier.Math::vec4 getColor (int num, int surface)
Returns vertex color.Arguments
- int num - Vertex number.
- int surface - Surface number.
Return value
Vertex color.void setTargetWeight (int target, float weight, int surface)
Sets a weight for the animation target.Arguments
- int target - Target number.
- float weight - Target weight.
- int surface - Surface number.
int setAnimation (int layer, const char * name)
Sets the animation name on the given animation layer.Arguments
- int layer - Layer number.
- const char * name - Animation name.
Return value
void setSpeed (float speed)
Updates a multiplier value for the animation playback time.Arguments
- float speed - Multiplier value.
int getNumTargets (int surface)
Returns the number of animation targets.Arguments
- int surface - Surface number.
Return value
Number of animation targets.Math::quat getSkinnedTangent (int num, int index, int surface)
Returns skinned tangent of a given vertex.Arguments
- int num - Vertex number.
- int index - Coordinate index.
- int surface - Surface number.
Return value
Skinned tangent.void removeLayer (int layer)
Removes an animation layer.Arguments
- int layer - Layer number in range from 0 to the total number of animation layers.
int getBoneParent (int bone)
Returns the number of the parent bone.The function is deprecated. It is provided to keep your code working until the next release. Please, replace it with getNumBoneChildren().
Arguments
- int bone - Bone number.
Return value
Parent bone number.float getLayerWeight (int layer)
Returns the weight of the animation layer.Arguments
- int layer - Layer number.
Return value
Weight of the animation layer.void setBoneTransform (int bone, const Math::mat4 & transform)
Sets a transformation matrix for a given bone.Arguments
- int bone - Bone number.
- const Math::mat4 & transform - Transformation matrix.
const char * getMeshName ()
Returns the mesh name.Return value
Name of the mesh.void importLayer (int layer)
Imports a given animation layer.Arguments
- int layer - Layer number.
void setBoneTransforms (const int * bones, const Math::mat4 * transforms, int num_bones)
Sets a transformation matrix for a given bones.Arguments
- const int * bones - Bone numbers.
- const Math::mat4 * transforms - Transformation matrices.
- int num_bones - Number of bones.
int findBone (const char * name)
Searches for a bone with a given name.Arguments
- const char * name - Bone name.
Return value
Returns bone number if found; otherwise, -1.void setLayerBoneTransformEnabled (int layer, int bone, int enabled)
Sets a layer transformation enabled flag for a given bone.Arguments
- int layer - Layer number.
- int bone - Bone number.
- int enabled - Enabled flag.
void stop ()
Stops animation playback. This function saves the playback position so that playing of the animation can be resumed from the same point.int isLayerBoneTransform (int layer, int bone)
Returns a value indicating if the bone transformation is applied only to the animation layer (no blending is done).Arguments
- int layer - Layer number.
- int bone - Bone number.
Return value
Bone transformation flag: 1 if the bone transformation is applied only to the animation layer; otherwise, 0.void updateSurfaceBounds (int surface = -1)
Updates mesh bounds.Arguments
- int surface - Surface number (use -1 for all surfaces).
int isPlaying ()
Returns playback status.Return value
1 if animation is playing; otherwise, 0.Math::vec3 getSkinnedNormal (int num, int index, int surface)
Returns the skinned normal for the given vertex.Arguments
- int num - Vertex number.
- int index - Coordinate index.
- int surface - Surface number.
Return value
Skinned normal.int findSurfaceTarget (const char * name, int surface)
Searches for an surface target with a given name.Arguments
- const char * name - Target name.
- int surface - Surface number.
Return value
Target number if it is exists; otherwise, -1.float setFrame (int layer, float frame, int from = -1, int to = -1)
Sets a frame of the animation layer.Arguments
- int layer - Layer number.
- float frame - Frame number in the
- int from - Start frame. -1 means the first frame of animation.
- int to - End frame. -1 means the last frame of animation.
Return value
The number of the frame.void flushMesh ()
Flushes the mesh geometry into the video memory.float getTargetWeight (int target, int surface)
Returns the weight of the animation target.Arguments
- int target - Target number.
- int surface - Surface number.
Return value
Weight of the animation target.int setMesh (const Ptr<Mesh> & mesh)
Copies the source mesh into the current mesh.Arguments
- const Ptr<Mesh> & mesh - The source mesh to be copied.
Return value
1 if the mesh is copied successfully; otherwise, 0.void setTexCoord1 (int num, const Math::vec2 & texcoord, int surface)
Updates second texture coordinate.Arguments
- int num - Vertex number.
- const Math::vec2 & texcoord - Second texture coordinate.
- int surface - Surface number.
float getFrame (int layer)
Returns the frame number (time value passed to the last setFrame() call).Arguments
- int layer - Layer number.
Return value
Frame number.const char * getAnimationName (int animation)
Returns the animation name.Arguments
- int animation - Animation identifier.
Return value
Animation name.int isQuaternion ()
Returns the value indicating if the quaternion skinning mode is used.Return value
1 if the quaternion skinning mode is used; otherwise, 0.void setTangent (int num, const Math::quat & tangent, int surface, int target = 0)
Updates tangent of a given vertex.Arguments
- int num - Vertex number.
- const Math::quat & tangent - Vertex tangent.
- int surface - Surface number.
- int target - Target number.
void setBoneChildrenTransform (int bone, const Math::mat4 & transform)
Sets a transformation matrix for a given bone. All child bones will recalculate their matrices.Arguments
- int bone - Bone number.
- const Math::mat4 & transform - Transformation matrix.
void removeAnimation (int animation)
Removes animation.Arguments
- int animation - Animation identifier.
void setNumTexCoords0 (int num, int surface)
Sets the number of first texture coordinates.Arguments
- int num - Number of first texture coordinates.
- int surface - Surface number.
Math::vec2 getTexCoord1 (int num, int surface)
Returns second texture coordinate.Arguments
- int num - Vertex number.
- int surface - Surface number.
Return value
Vertex second texture coordinate.Math::vec2 getTexCoord0 (int num, int surface)
Returns first texture coordinate.Arguments
- int num - Vertex number.
- int surface - Surface number.
Return value
Vertex first texture coordinate.int getMesh (const Ptr<Mesh> & mesh)
Copies the current mesh into the source mesh.Arguments
- const Ptr<Mesh> & mesh - Source mesh.
Return value
1 if the mesh is copied successfully; otherwise, 0.Math::vec3 getSkinnedVertex (int num, int surface)
Returns skinned coordinate of a given vertex.Arguments
- int num - Vertex number.
- int surface - Surface number.
Return value
Vertex coordinate.float getTime ()
Returns the current animation time, in animation frames. The time count starts from the zero frame.Return value
Animation time.void setLayerBoneTransform (int layer, int bone, const Math::mat4 & transform)
Sets a transformation matrix for a given bone. The difference from the setBoneTransform() function is that this method takes into account only the transformation in the animation layer (no blending is done). Take notice that a bone can be scaled only uniformly.Arguments
- int layer - Layer number.
- int bone - Bone number.
- const Math::mat4 & transform - Transformation matrix.
void lerpLayer (int layer, int layer_0, int layer_1, float weight)
Copies interpolated bone transformations from two source layers to the destination layer. If there is no bone in a source layer, the bone transformation from another one will be copied to the destination layer without interpolation.Arguments
- int layer - Number of the destination layer in range from 0 to the total number of animation layers.
- int layer_0 - Number of the first source layer in range from 0 to the total number of animation layers.
- int layer_1 - Number of the second source layer in range from 0 to the total number of animation layers.
- float weight - Interpolation weight.
const char * getAnimName ()
Returns the name of the current animation.Return value
The name of the animation.int getNumAnimations ()
Returns the number of loaded animations.Return value
Number of loaded animations.int getNumBoneChildren (int bone)
Returns the number of child bones.Arguments
- int bone - Bone number.
Return value
Number of child bones.void setVertex (int num, const Math::vec3 & vertex, int surface, int target = 0)
Updates coordinate of a given vertex.Arguments
- int num - Vertex number.
- const Math::vec3 & vertex - Vertex position coordinate.
- int surface - Surface number.
- int target - Target number.
int getNumAnimationBones (int animation)
Returns the number of animation bones.Arguments
- int animation - Number of the animation.
Return value
Number of animation bones.const char * getSurfaceTargetName (int surface, int target)
Returns the name of a given surface target.Arguments
- int surface - Surface number.
- int target - Target number.
Return value
Target name.int isTargetEnabled (int target, int surface)
Returns a value indicating if a given animation target is enabled.Arguments
- int target - Target number.
- int surface - Surface number.
Return value
Returns 1 if the given surface is disabled; otherwise, 0.int getNumTexCoords1 (int surface)
Returns the number of second texture coordinates.Arguments
- int surface - Surface number.
Return value
Number of second texture coordinates.int addAnimation (const char * name, const char * animation = 0)
Loads the additional animation from an external file.Arguments
- const char * name - Path to the animation file.
- const char * animation - Animation name.
Return value
Animation identifier.void setAnimName (const char * name)
Sets the animation name.Arguments
- const char * name - The name of the animation.
int getBoneChild (int bone, int child)
Returns the number of a child of a given bone.Arguments
- int bone - Bone number.
- int child - Child number.
Return value
Number of the child in the collection of all bones.const char * getBoneName (int bone)
Returns name of a given bone.Arguments
- int bone - Bone number.
Return value
Bone name.int findAnimation (const char * name)
Searches for an animation with a given name.Arguments
- const char * name - Animation name.
Return value
Returns animation identifier if found; otherwise, -1.void setLayer (int layer, int enabled, float weight)
Sets all parameters to a given animation layer.Arguments
- int layer - Layer number.
- int enabled - Layer enabled.
- float weight - Layer weight.
void setLoop (int loop)
Sets a value indicating if the animation should be looped.Arguments
- int loop - 1 is to play the animation in a loop, 0 is to play it only once.
void setColor (int num, const Math::vec4 & color, int surface)
Updates vertex color.Arguments
- int num - Vertex number.
- const Math::vec4 & color - Vertex color.
- int surface - Surface number.
int isLayerEnabled (int layer)
Returns a value indicating if a given animation layer is enabled.Arguments
- int layer - Layer number.
Return value
Returns 1 if the given surface is disabled; otherwise, 0.int getNumTangents (int surface)
Returns the number of tangents in a given mesh surface.Arguments
- int surface - Surface number.
Return value
Number of the surface vertices.int getCIndex (int num, int surface)
Returns an coordinate index.Arguments
- int num - Index number in the index buffer.
- int surface - Surface number.
Return value
Coordinate index.int saveMesh (const char * name)
Saves the dynamic mesh into a file.Arguments
- const char * name - Mesh file name.
Return value
Returns 1 if the mesh is saved successfully; otherwise, 0.Math::mat4 getIBoneBindTransform (int bone)
Returns inverse bind pose bone transformation matrix.Arguments
- int bone - Bone number.
Return value
Inverse bind pose transformation matrix.void setQuaternion (int quaternion)
Sets the quaternion skinning mode.Arguments
- int quaternion - Quaternion flag.
void setCIndex (int num, int index, int surface)
Updates an coordinate index.Arguments
- int num - Index number in the index buffer.
- int index - Coordinate index.
- int surface - Surface number.
int getNumTexCoords0 (int surface)
Returns the number of first texture coordinates.Arguments
- int surface - Surface number.
Return value
Number of first texture coordinates.Math::vec3 getNormal (int num, int surface, int target = 0)
Returns normal of a given vertex.Arguments
- int num - Vertex number.
- int surface - Surface number.
- int target - Target number.
Return value
Normal vector.int isControlled ()
Returns a value indicating if the animation is controlled by a parent ObjectMeshSkinned.Return value
1 if the animation is controlled by a parent ObjectMeshSkinned; otherwise, 0.int getNumLayers ()
Returns the number of animation layers set for blending. For more details, see the article on Skinned Mesh.Return value
Number of animation layers.void setLayerEnabled (int layer, int enabled)
Enables or disables a given animation layer.Arguments
- int layer - Layer number.
- int enabled - 1 to enable the animation layer, 0 to disable it.
void removeTarget (int target, int surface)
Removes an animation target.Arguments
- int target - Target number in range from 0 to the total number of animation targets.
- int surface - Surface number.
void mulLayer (int layer, int layer_0, int layer_1, float weight = 1.0f)
Copies multiplied bone transformations from two source layers to the destination layer.Arguments
- int layer - Number of the destination layer in range from 0 to the total number of animation layers.
- int layer_0 - Number of the first source layer in range from 0 to the total number of animation layers.
- int layer_1 - Number of the second source layer in range from 0 to the total number of animation layers.
- float weight - Interpolation weight.
Math::quat getTangent (int num, int surface, int target = 0)
Returns tangent of a given vertex.Arguments
- int num - Vertex number.
- int surface - Surface number.
- int target - Target number.
Return value
Tangent vector.void setSurfaceTransform (const Math::mat4 & transform, int surface, int target = -1)
Transforms the mesh surface.Arguments
- const Math::mat4 & transform - Transformation matrix.
- int surface - Surface number.
- int target - Target number.
int getNumTIndices (int surface)
Returns the number of triangle indices.Arguments
- int surface - Surface number.
Return value
Number of triangle indices.Last update: 2017-07-03
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)