Unigine.ObjectMeshSkinned Class
Inherits from: | Object |
This class is used to create or modify skinned meshes.
Creating and Playing Animation#
To add the animation to the ObjectMeshSkinned and play it, do the following:
- Set the number of animation layers with the setNumLayers() method. There is only one layer by default.
- Enable the layer and set the animation weight for blending by calling the setLayer() function.
-
Add the animation .anim file by using addAnimation() or setAnimation() functions.
When you import your model with animations from an FBX container, the following path to your *.anim files should be used: <path_to_your_fbx_file>/<file.fbx>/<your_anim_file.anim>
For example: object->addAnimation("models/soldier/soldier.fbx/run.anim");
The recommended approach is to use the Component System and provide the guid of the .anim file.
UGUID guid = FileSystem::getGUID(anim_asset.getRaw()); int animation_1 = skinned_mesh->addAnimation(mesh,guid.getFileSystemString(), "run");
- Play the added animation by calling the setFrame() function for each animation layer.
Blending is performed between all layers. The contribution of each layer depends on its weight. Also, you can optionally define single bone transformations by hand, if needed, using either setBoneTransform() or setBoneTransformWithChildren().
Usage Example
The example here demonstrates blending animations using the gradient band interpolation. You can add all animations for ObjectMeshSkinned on separate layers and then update their weights.
This is a C# Component System component. Assign this component to your ObjectMeshSkinned and add the necessary animation files.
The complete source code:
using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;
[Component(PropertyGuid = "_______________(generated automatically)__________________")]
public class Blend2D : Component
{
private ObjectMeshSkinned meshSkinned = null;
public struct Animation
{
public string name;
[ParameterAsset(Filter = "anim")]
public AssetLink asset;
public vec2 point;
}
[ShowInEditor]
[ParameterSlider(Min = MathLib.EPSILON)]
private float targetDuration = 2.0f;
[ShowInEditor]
private List<Animation> animations = new List<Animation>()
{
new Animation() { name = "Idle", point = new vec2(0, 0) },
new Animation() { name = "Forward", point = new vec2(0, 1) },
new Animation() { name = "Backward", point = new vec2(0, -1) },
new Animation() { name = "Right", point = new vec2(1, 0) },
new Animation() { name = "Left", point = new vec2(-1, 0) },
};
// for playback
private float time = 0.0f;
private List<float> speeds = new List<float>();
// for blending
private List<vec2> points = new List<vec2>();
private List<float> weights = new List<float>();
private vec2 targetPoint = new vec2(0, 0);
private void Init()
{
meshSkinned = node as ObjectMeshSkinned;
if (!meshSkinned)
return;
// remove default layer
meshSkinned.RemoveLayer(0);
for (int i = 0; i < animations.Count; i++)
{
if (animations[i].asset.IsNull || !animations[i].asset.IsFileExist)
continue;
// create layer for each animation
int id = meshSkinned.AddAnimation(animations[i].asset.Path);
meshSkinned.AddLayer();
meshSkinned.SetAnimation(meshSkinned.NumLayers - 1, id);
// enable new layer and set default weight to 1.0
meshSkinned.SetLayer(meshSkinned.NumLayers - 1, true, 1.0f);
// calculate animation speed to play with fixed duration
int numFrames = meshSkinned.GetNumAnimationFrames(id);
float speed = numFrames / targetDuration;
speeds.Add(speed);
// add point and weight for blending
points.Add(animations[i].point);
weights.Add(1.0f);
}
}
private void Update()
{
if (!meshSkinned)
return;
// update weight for each layer
UpdateWeights();
// update layer frames and layer weights
for (int i = 0; i < meshSkinned.NumLayers; i++)
{
float frame = time * speeds[i];
meshSkinned.SetFrame(i, frame);
meshSkinned.SetLayerWeight(i, weights[i]);
}
time += Game.IFps;
if (time > targetDuration)
time -= targetDuration;
// update target point for blending
ivec2 movement = new ivec2();
if (Input.IsKeyPressed(Input.KEY.T))
movement += new ivec2(0, 1);
if (Input.IsKeyPressed(Input.KEY.G))
movement -= new ivec2(0, 1);
if (Input.IsKeyPressed(Input.KEY.H))
movement += new ivec2(1, 0);
if (Input.IsKeyPressed(Input.KEY.F))
movement -= new ivec2(1, 0);
if (movement.x != 0)
targetPoint.x += movement.x * Game.IFps * 2.0f;
else
targetPoint.x *= MathLib.Exp(-Game.IFps * 3.0f);
if (movement.y != 0)
targetPoint.y += movement.y * Game.IFps * 2.0f;
else
targetPoint.y *= MathLib.Exp(-Game.IFps * 3.0f);
targetPoint = MathLib.Clamp(targetPoint, new vec2(-1, -1), new vec2(1, 1));
}
private void UpdateWeights()
{
// gradient band interpolation
float totalWeight = 0.0f;
for (int i = 0; i < points.Count; i++)
{
vec2 pi = points[i];
vec2 targetVector = targetPoint - pi;
float weight = 1.0f;
for (int j = 0; j < points.Count; j++)
{
if (j == i)
continue;
vec2 jVector = points[j] - pi;
float newWeight = 1.0f - MathLib.Dot(targetVector, jVector) / jVector.Length2;
newWeight = MathLib.Clamp(newWeight, 0.0f, 1.0f);
weight = MathLib.Min(weight, newWeight);
}
weights[i] = weight;
totalWeight += weight;
}
for (int i = 0; i < weights.Count; i++)
weights[i] = weights[i] / totalWeight;
}
}
Updating Bone Transformations#
Some of the methods require to update the animation data before the renderer makes its update and actually draws the skinned mesh. Such update allows to get the correct result of blending between the frames and layers.
The execution sequence of updating bone transformations is the following:
- Call the method, which sets the update flag. This flag shows that the instance should be updated.
- Update the bone transformations by calling proper functions. These functions check the flag and if the flag is set, they calculate the transformations and set the flag to the default value.
- During the rendering, the engine performs animations and transformations which were calculated on the previous step or recalculates them, if the update flag has been set. If calculations have been performed, the flag is set to the default value.
If you try to update bone transformations before you set the flag to update, functions will not calculate new transformations and the engine doesn't perform them.
When you change the transformation of the bone, you should notify all skinned meshes which use these bone about these transformations to update the mesh. When you change transformations of a bone, skinned mesh instances get the flag to update. When you use the setFrame() function, you set necessary transformations for the specified skinned mesh.
Instancing#
Surfaces of identical skinned meshes which have the same materials assigned to them and the same number of bones attached to their vertices are automatically instanced and drawn in one draw call. The instancing flag is enabled by default (see corresponding console commands).
The data buffers for instanced objects that store bones transformations are limited in size; therefore, if skinned meshes have many bones, only a few meshes can populate the instance data buffer to be drawn in one draw call.
See Also#
- Mesh class
- Article on Mesh File Formats
- Samples located in the <UnigineSDK>/data/samples/animation folder
ObjectMeshSkinned Class
Enums
BONE_SPACE#
Defines which transformation of the bone is to be overridden by the bind node's transformation.Name | Description |
---|---|
WORLD = 0 | World coordinates. |
OBJECT = 1 | Coordinates relative to the skinned mesh object. |
LOCAL = 2 | Coordinates relative to the parent bone. |
NODE_SPACE#
Defines the type of transformation of the bind node to be used to override the transformation of the specified bone.Name | Description |
---|---|
WORLD = 0 | World transformation of the node. |
LOCAL = 1 | Local transformation of the node. |
BIND_MODE#
Type of blending of bind node's and bone's transformations.Name | Description |
---|---|
OVERRIDE = 0 | Replace bone's transformation with the transformation of the bind node. |
ADDITIVE = 1 | Bind node's transformation is added to the current transformation of the bone. |
Properties
int NumAnimations#
int NumBones#
int NumLayers#
bool IsStopped#
bool IsPlaying#
float Speed#
float Time#
int Loop#
bool Controlled#
bool Quaternion#
string AnimName#
string MeshName#
float UpdateDistanceLimit#
int FPSInvisible#
int FPSVisibleShadow#
int FPSVisibleCamera#
bool VisualizeAllBones#
Members
ObjectMeshSkinned ( Mesh mesh ) #
ObjectMeshSkinned constructor.Arguments
- Mesh mesh - Pointer to Mesh.
ObjectMeshSkinned ( string path, bool unique = false ) #
ObjectMeshSkinned constructor.Arguments
- string path - Path to the skinned mesh file.
- bool unique - When you create several objects out of a single .mesh file, the instance of the mesh geometry is created. If you then change the source geometry, its instances will be changed as well. To avoid this, set the unique flag to true (1), so a copy of the mesh geometry will be created and changes won't be applied.
int SetAnimation ( int layer, int animation ) #
Sets the animation identifier for the given animation layer.Arguments
- int layer - Layer number.
- int animation - Animation identifier.
int SetAnimation ( int layer, string path ) #
Sets the path to animation for the given animation layer.Arguments
- int layer - Layer number.
- string path - Path to animation file.
int GetAnimation ( int layer ) #
Returns the animation identifier from the given animation layer.Arguments
- int layer - Layer number.
Return value
Animation identifier.int GetAnimationID ( int num ) #
Returns the identifier of the animation at the specified position.Arguments
- int num - Animation number.
Return value
Animation identifier.string GetAnimationPath ( int animation ) #
Returns the path to a file containing the specified animation.Arguments
- int animation - Animation identifier.
Return value
Path to a file containing the specified animation.void SetAnimNameForce ( string name ) #
Sets the new path to the animation and forces setting this animation for the first animation layer.Arguments
- string name - Path to the animation file.
mat4 GetBoneBindTransform ( int bone ) #
Returns the bind pose bone transformation matrix. Bone transformations are relative.Arguments
- int bone - Bone number.
Return value
Bind pose bone transformation matrix.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.void SetBoneTransformWithChildren ( int bone, mat4 transform ) #
Sets transformation for the bone and all of its children (without considering node transformations).Arguments
- int bone - Bone number.
- mat4 transform - Transformation matrix.
string GetBoneName ( int bone ) #
Returns the name of the given bone.Arguments
- int bone - Bone number.
Return value
Bone name.int GetBoneParent ( int bone ) #
Returns the number of the parent bone for a given one.Arguments
- int bone - Number of the bone, for which the parent will be returned.
Return value
Parent bone number, if the parent exists; otherwise, -1.void SetBoneTransform ( int bone, mat4 transform ) #
Sets a transformation matrix for a given bone (without considering node transformations).Arguments
- int bone - Bone number.
- mat4 transform - Transformation matrix.
mat4 GetBoneTransform ( int bone ) #
Returns a transformation matrix of a given bone relatively to the parent object (not considering transformations of the node itself).Arguments
- int bone - Bone number.
Return value
Transformation matrix.void SetBoneTransforms ( int[] bones, mat4[] transforms, int num_bones ) #
Sets a transformation matrix for given bones.Arguments
- int[] bones - Bone numbers.
- mat4[] transforms - Transformation matrices.
- int num_bones - Number of bones.
void SetCIndex ( int num, int index, int surface ) #
Sets the new coordinate index for the given vertex of the given surface.Arguments
- int num - Vertex number in the range from 0 to the total number of coordinate indices for the given surface.
To get the total number of coordinate indices for the given surface, use the getNumCIndices() method.
- int index - Coordinate index to be set in the range from 0 to the total number of coordinate vertices for the given surface.
To get the total number of coordinate vertices for the given surface, use the getNumCVertex() method.
- int surface - Mesh surface number.
int GetCIndex ( int num, int surface ) #
Returns the coordinate index for the given vertex of the given surface.Arguments
- int num - Vertex number in the range from 0 to the total number of coordinate indices for the given surface.
To get the total number of coordinate indices for the given surface, use the getNumCIndices() method.
- int surface - Mesh surface number.
Return value
Coordinate index.void SetColor ( int num, vec4 color, int surface ) #
Sets the color for the given triangle vertex of the given surface.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of vertex color entries of the given surface.
To get the total number of vertex color entries for the surface, call the getNumColors() method.
- vec4 color - Vertex color to be set.
- int surface - Mesh surface number.
vec4 GetColor ( int num, int surface ) #
Returns the color of the given triangle vertex of the given surface.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of vertex color entries of the given surface.
To get the total number of vertex color entries for the surface, call the getNumColors() method.
- int surface - Mesh surface number.
Return value
Vertex color.float SetFrame ( int layer, float frame, int from = -1, int to = -1 ) #
Sets a frame for the given animation layer.Arguments
- int layer - Animation layer number.
- float frame - Frame number in the "from-to" interval. If the float argument is passed, animation is interpolated between nearby frames. 0 means the from frame. For larger values, a residue of a modulo (from-to) is calculated. If a negative value is provided, interpolation will be done from the current frame to the from frame.
- int from - Start frame. -1 means the first frame of the animation.
- int to - End frame. -1 means the last frame of the animation.
Return value
The number of the frame.float GetFrame ( int layer ) #
Returns the frame number passed as the time argument on the last setFrame() call.Arguments
- int layer - Animation layer number.
Return value
Frame number.int GetFrameFrom ( int layer ) #
Returns the start frame passed as the from argument on the last setFrame() call.Arguments
- int layer - Animation layer number.
Return value
Start frame.int GetFrameTo ( int layer ) #
Returns the end frame passed as the to argument on the last setFrame() call.Arguments
- int layer - Animation layer number.
Return value
End frame.mat4 GetBoneBindITransform ( int bone ) #
Returns the inverse bone transformation matrix of the bind pose in the world-space.Arguments
- int bone - Bone number.
Return value
Inverse bind pose transformation matrix.mat4 GetBoneITransform ( 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.void SetLayer ( int layer, bool enabled, float weight ) #
Enables or disables the given animation layer and sets the value of the weight parameter.Arguments
- int layer - Animation layer number.
- bool enabled - Enable flag. true to enable the layer, false to disable it.
- float weight - Animation layer weight.
void SetBoneLayerTransform ( int layer, int bone, 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 specified animation layer (no blending is performed).Arguments
- int layer - Animation layer number.
- int bone - Bone number.
- mat4 transform - Bone transformation matrix.
mat4 GetBoneLayerTransform ( int layer, int bone ) #
Returns a transformation matrix of a given bone relatively to the parent object.Arguments
- int layer - Animation layer number.
- int bone - Bone number.
Return value
Bone transformation matrix.bool IsBoneLayerTransform ( int layer, int bone ) #
Returns a value indicating if the bone transformation is applied only to the animation layer (no blending is performed).Arguments
- int layer - Animation layer number.
- int bone - Bone number.
Return value
true if the bone transformation is applied only to the animation layer; otherwise, false.void SetBoneLayerTransformEnabled ( int layer, int bone, bool enabled ) #
Enables or disables a layer transformation for a given bone.Arguments
- int layer - Animation layer number.
- int bone - Bone number.
- bool enabled - Enabled flag: true to enable layer transformation, false to disable it.
void SetLayerEnabled ( int layer, bool enabled ) #
Enables or disables a given animation layer.Arguments
- int layer - Animation layer number.
- bool enabled - true to enable the animation layer, false to disable it.
bool IsLayerEnabled ( int layer ) #
Returns a value indicating if a given animation layer is enabled.Arguments
- int layer - Animation layer number.
Return value
true if the layer is disabled; otherwise, false.void SetLayerWeight ( int layer, float weight ) #
Sets a weight for the animation layer.Arguments
- int layer - Animation layer number.
- float weight - Animation layer weight.
float GetLayerWeight ( int layer ) #
Returns the weight of the animation layer.Arguments
- int layer - Animation layer number.
Return value
Weight of the animation layer.int SetMesh ( Mesh mesh ) #
Copies the source mesh into the current mesh.// create ObjectMeshSkinned instances
ObjectMeshSkinned skinnedMesh = new ObjectMeshSkinned("soldier.mesh");
ObjectMeshSkinned skinnedMesh_2 = new ObjectMeshSkinned("doll.mesh");
// create a Mesh instance
Mesh firstMesh = new Mesh();
// get the mesh of the ObjectMeshSkinned and copy it to the Mesh class instance
skinnedMesh.getMesh(firstMesh);
// put the firstMesh mesh to the skinnedMesh_2 instance
skinnedMesh_2.setMesh(firstMesh);
Arguments
- Mesh mesh - The source mesh to be copied.
Return value
1 if the mesh is copied successfully; otherwise, 0.int GetMesh ( Mesh mesh ) #
Copies the current mesh into the source mesh.// a skinned mesh from which geometry will be obtained
ObjectMeshSkinned skinnedMesh = new ObjectMeshSkinned("skinned.mesh");
// create a new mesh
Mesh mesh = new Mesh();
// copy geometry to the created mesh
if (skinnedMesh.getMesh(mesh) == 1) {
// do something with the obtained mesh
}
else {
Log.Error("Failed to copy a mesh\n");
}
Arguments
- Mesh mesh - Source mesh.
Return value
1 if the mesh is copied successfully; otherwise, 0.void SetMeshNameForce ( string path ) #
Sets the new path to the mesh and forces mesh creation using the new path. The new mesh is created from the specified path immediately with the unique flag set to 0.Arguments
- string path - Path to the mesh file.
int GetMeshSurface ( Mesh mesh, int surface, int target = -1 ) #
Copies the specified mesh surface to the destination mesh.Arguments
- Mesh mesh - Destination Mesh to copy the surface to.
- int surface - Number of the mesh surface to be copied.
- int target - Number of the surface morph target to be copied. The default value is -1 (all morph targets).
Return value
Number of the new added mesh surface.vec3 GetNormal ( int num, int surface, int target = 0 ) #
Returns the normal for the given triangle vertex of the given surface target.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of vertex tangent entries of the given surface target.
Vertex normals are calculated using vertex tangents. To get the total number of vertex tangent entries for the surface target, call the getNumTangents() method.
- int surface - Mesh surface number.
- int target - Surface target number. The default value is 0.
Return value
Vertex normal.int GetNumAnimationBones ( int animation ) #
Returns the number of animation bones.Arguments
- int animation - Animation number.
Return value
Number of animation bones.int GetNumAnimationFrames ( int animation ) #
Returns the number of animation frames.Arguments
- int animation - Animation number.
Return value
Number of animation frames.int GetNumBoneChildren ( int bone ) #
Returns the number of children for the specified bone.Arguments
- int bone - Bone number.
Return value
Number of child bones.int GetNumCIndices ( int surface ) #
Returns the number of coordinate indices for the given mesh surface.Arguments
- int surface - Mesh surface number.
Return value
Number of coordinate indices.int GetNumColors ( int surface ) #
Returns the total number of vertex color entries for the given surface.Arguments
- int surface - Surface number.
Return value
Number of vertex color entries.int GetNumFrames ( int layer ) #
Returns the number of animation frames for a given layer.Arguments
- int layer - Animation layer number.
Return value
Number of animation frames.int GetNumSurfaceTargets ( int surface ) #
Returns the number of surface morph targets for the given mesh surface.Arguments
- int surface - Mesh surface number.
Return value
Number of surface morph targets.int GetNumTangents ( int surface ) #
Returns the number of vertex tangent entries of the given mesh surface.Arguments
- int surface - Mesh surface number.
Return value
Number of surface tangent vectors.void SetNumTargets ( int num, int surface ) #
Sets the number of animation morph targets for the given mesh surface.Arguments
- int num - Number of animation morph targets.
- int surface - Mesh surface number.
int GetNumTargets ( int surface ) #
Returns the total number of morph targets of the given mesh surface.Arguments
- int surface - Mesh surface number.
Return value
Number of animation morph targets.void SetNumTexCoords0 ( int num, int surface ) #
Sets the number of the first UV map texture coordinates for the given mesh surface.Arguments
- int num - Number of the first UV map texture coordinates to be set.
- int surface - Mesh surface number.
int GetNumTexCoords0 ( int surface ) #
Returns the number of the first UV map texture coordinates for the given mesh surface.Arguments
- int surface - Mesh surface number.
Return value
Number of the first UV map texture coordinates.void SetNumTexCoords1 ( int num, int surface ) #
Sets the number of the second UV map texture coordinates for the given mesh surface.Arguments
- int num - Number of the second UV map texture coordinates to be set.
- int surface - Mesh surface number.
int GetNumTexCoords1 ( int surface ) #
Returns the number of the second UV map texture coordinates for the given mesh surface.Arguments
- int surface - Mesh surface number.
Return value
Number of the second UV map texture coordinates.int GetNumTIndices ( int surface ) #
Returns the number of triangle indices for the given mesh surface.Arguments
- int surface - Mesh surface number.
Return value
Number of triangle indices.int GetNumVertex ( int surface ) #
Returns the number of coordinate vertices for the given mesh surface.Arguments
- int surface - Mesh surface number.
Return value
Number of the surface vertices.bool IsFlushed ( ) #
Returns a value indicating if vertex data of the mesh was flushed (create/upload operation) to video memory.Return value
true if vertex data of the mesh was flushed (create/upload operation) to video memory; otherwise, false.vec3 GetSkinnedNormal ( int num, int index, int surface ) #
Returns the skinned normal for the given triangle vertex.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of vertex tangent entries of the given surface target.
Vertex normals are calculated using vertex tangents. To get the total number of vertex tangent entries for the surface target, call the getNumTangents() method.
- int index - Coordinate index of the vertex.
if -1 is passed, the coordinate index will be obtained for the first vertex having its triangle index equal to the specified triangle vertex number.
- int surface - Mesh surface number.
Return value
Skinned normal.quat GetSkinnedTangent ( int num, int index, int surface ) #
Returns the skinned tangent vector for the given triangle vertex.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of vertex tangent entries of the given surface target.
To get the total number of vertex tangent entries for the surface target, call the getNumTangents() method.
- int index - Coordinate index of the vertex.
if -1 is passed, the coordinate index will be obtained for the first vertex having its triangle index equal to the specified triangle vertex number.
- int surface - Mesh surface number.
Return value
Skinned tangent.vec3 GetSkinnedVertex ( int num, int surface ) #
Returns skinned coordinates of the given coordinate vertex.Arguments
- int num - Coordinate vertex number in the range from 0 to the total number of coordinate vertices for the given surface.
To get the total number of coordinate vertices for the given surface, use the getNumVertex() method.
- int surface - Mesh surface number.
Return value
Vertex coordinates.string GetSurfaceTargetName ( int surface, int target ) #
Returns the name of the morph target for the given mesh surface.Arguments
- int surface - Mesh surface number.
- int target - Morph target number.
Return value
Morph target name.void SetSurfaceTransform ( mat4 transform, int surface, int target = -1 ) #
Transforms the given mesh surface target.Arguments
- mat4 transform - Transformation matrix.
- int surface - Mesh surface number.
- int target - Morph target number. The default value is -1 (the transformation will be applied to all morph targets).
void SetTangent ( int num, quat tangent, int surface, int target = 0 ) #
Sets the new tangent for the given triangle vertex of the given surface target.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of vertex tangent entries of the given surface.
To get the total number of vertex tangent entries for the surface, call the getNumTangents() method.
- quat tangent - Tangent to be set.
- int surface - Mesh surface number.
- int target - Surface target number. The default value is 0.
quat GetTangent ( int num, int surface, int target = 0 ) #
Returns the tangent for the given triangle vertex of the given surface target.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of vertex tangent entries of the given surface.
To get the total number of vertex tangent entries for the surface, call the getNumTangents() method.
- int surface - Mesh surface number.
- int target - Surface target number. The default value is 0.
Return value
Vertex tangent.void SetTarget ( int target, bool enabled, int index, float weight, int surface ) #
Enables or disables a given morph target and sets all its parameters.Arguments
- int target - Morph target number.
- bool enabled - Enable flag: true to enable the morph target; false to disable it.
- int index - Target index.
- float weight - Target weight.
- int surface - Surface number.
void SetTargetEnabled ( int target, bool enabled, int surface ) #
Enables or disables a given morph target.Arguments
- int target - Morph target number.
- bool enabled - true to enable the morph target, false to disable it.
- int surface
int IsTargetEnabled ( int target, int surface ) #
Returns a value indicating if the given morph target of the given surface is enabled.Arguments
- int target - Morph target number.
- int surface - Mesh surface number.
Return value
1 if the given morph target of the given surface is enabled; otherwise, 0.void SetTargetIndex ( int target, int index, int surface ) #
Sets an index for the given morph target.Arguments
- int target - Morph target number.
- int index - Morph target index.
- int surface - Mesh surface number.
int GetTargetIndex ( int target, int surface ) #
Returns the index of the morph target. Returns the index of the given morph target.Arguments
- int target - Morph target number.
- int surface - Mesh surface number.
Return value
Index of the given morph target.void SetTargetWeight ( int target, float weight, int surface ) #
Sets a weight for the given animation target.Arguments
- int target - Morph target number.
- float weight - Morph target weight.
- int surface - Mesh surface number.
float GetTargetWeight ( int target, int surface ) #
Returns the weight of the given morph target.Arguments
- int target - Morph target number.
- int surface - Mesh surface number.
Return value
Morph target weight.void SetTexCoord0 ( int num, vec2 texcoord, int surface ) #
Sets first UV map texture coordinates for the given triangle vertex of the given surface.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of first UV map texture coordinate entries of the given surface.
To get the total number of first UV map texture coordinate entries for the surface, call the getNumTexCoords0() method.
- vec2 texcoord - First UV map texture coordinates to be set.
- int surface - Mesh surface number.
vec2 GetTexCoord0 ( int num, int surface ) #
Returns first UV map texture coordinates for the given triangle vertex of the given surface.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of first UV map texture coordinate entries of the given surface.
To get the total number of first UV map texture coordinate entries for the surface, call the getNumTexCoords0() method.
- int surface - Mesh surface number.
Return value
First UV map texture coordinates.void SetTexCoord1 ( int num, vec2 texcoord, int surface ) #
Sets second UV map texture coordinates for the given triangle vertex of the given surface.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of second UV map texture coordinate entries of the given surface.
To get the total number of second UV map texture coordinate entries for the surface, call the getNumTexCoords1() method.
- vec2 texcoord - Second UV map texture coordinates to be set.
- int surface - Mesh surface number.
vec2 GetTexCoord1 ( int num, int surface ) #
Returns second UV map texture coordinates for the given triangle vertex of the given surface.Arguments
- int num - Triangle vertex number in the range from 0 to the total number of second UV map texture coordinate entries of the given surface.
To get the total number of second UV map texture coordinate entries for the surface, call the getNumTexCoords1() method.
- int surface - Mesh surface number.
Return value
Second UV map texture coordinates.void SetTIndex ( int num, int index, int surface ) #
Sets the new triangle index for the given vertex of the given surface.Arguments
- int num - Vertex number in the range from 0 to the total number of triangle indices for the given surface.
To get the total number of triangle indices, use the getNumTIndices() method.
- int index - Triangle index to be set in the range from 0 to the total number of triangle vertices for the given surface.
To get the total number of triangle vertices for the given surface, use the getNumTVertex() method.
- int surface - Mesh surface number.
int GetTIndex ( int num, int surface ) #
Returns the triangle index for the given surface by using the index number.Arguments
- int num - Vertex number in the range from 0 to the total number of triangle indices for the given surface.
To get the total number of triangle indices for the given surface, use the getNumTIndices() method.
- int surface - Mesh surface number.
Return value
Triangle index.void SetVertex ( int num, vec3 vertex, int surface, int target = 0 ) #
Sets the coordinates of the given coordinate vertex of the given surface target.Arguments
- int num - Coordinate vertex number in the range from 0 to the total number of coordinate vertices for the given surface.
To get the total number of coordinate vertices for the given surface, use the getNumCVertex() method.
- vec3 vertex - Vertex coordinates to be set.
- int surface - Mesh surface number.
- int target - Surface target number. The default value is 0.
vec3 GetVertex ( int num, int surface, int target = 0 ) #
Returns coordinates of the given coordinate vertex of the given surface target.Arguments
- int num - Coordinate vertex number in the range from 0 to the total number of coordinate vertices for the given surface.
To get the total number of coordinate vertices for the given surface, use the getNumCVertex() method.
- int surface - Mesh surface number.
- int target - Surface target number. The default value is 0.
Return value
Vertex coordinates.void SetBoneWorldTransformWithChildren ( int bone, mat4 transform ) #
Sets the transformation for the given bone and all of its children in the world coordinate space (considering node transformations).Arguments
- int bone - Bone number.
- mat4 transform - Transformation matrix in the world space.
void SetBoneWorldTransform ( int bone, mat4 transform ) #
Sets the transformation for the given bone in the world coordinate space.Arguments
- int bone - Bone number.
- mat4 transform - Transformation matrix in the world space.
mat4 GetBoneWorldTransform ( int bone ) #
Returns the current transformation matrix applied to the bone in the world coordinate space (considering node transformations).Arguments
- int bone - Bone number.
Return value
Transformation matrix in the world space.int AddAnimation ( Mesh mesh, string path = 0 ) #
Loads an additional animation from an external file.UGUID guid;
guid.generate();
int animation_1 = skinned_mesh->addAnimation(mesh,guid.getFileSystemString(), "run");
Arguments
- Mesh mesh - Mesh containing the animation to be added.
- string path - The parameter is a virtual unique path defining the animation. After loading the animation clip, its internal representation will be identified by the path when using findAnimation, setAnimation, etc. The default 0 value implies that the names of the animation clips will be used.
As the given mesh isn't associated with a file and, therefore, doesn't have path data, the path must be represented by an arbitrary unique string. You can generate a new string and use it as the virtual path for the animation.
Return value
Animation identifier.int AddAnimation ( string path ) #
Loads the additional animation from an external file.Arguments
- string path - Path to the animation file. The path can be represented by either a path to the file or its GUID, which is the recommended approach. After loading the animation, its internal representation is identified by the path when using findAnimation, setAnimation, etc. When you import your model with animations from an FBX container, the following path to your *.anim files should be used: <path_to_your_fbx_file>/<file.fbx>/<your_anim_file.anim>
For example: object->addAnimation("models/soldier/soldier.fbx/run.anim");
Return value
Animation identifier.int AddEmptySurface ( string name, int num_vertex, int num_indices ) #
Appends a new empty surface to the current mesh.Arguments
- string name - Name of the new surface.
- int num_vertex - Number of vertices of the new surface.
- int num_indices - Number of indices of the new surface.
Return value
Number of the new added surface.int AddLayer ( ) #
Appends a new animation layer to the current mesh.Return value
Number of the new added animation layer.int AddMeshSurface ( string name, ObjectMeshSkinned mesh, int surface, int target = -1 ) #
Appends a new mesh surface to the current mesh.Arguments
- string name - Name of the new surface of the current mesh.
- ObjectMeshSkinned mesh - Mesh pointer to copy a surface from.
- int surface - Number of mesh surface to copy.
- int target - Number of mesh target to copy. The default value is -1 (all morph targets will be copied).
Return value
Number of the added mesh surface.int AddMeshSurface ( int dest_surface, ObjectMeshSkinned mesh, int surface, int target = -1 ) #
Merges the specified surface from the source ObjectMeshSkinned with the specified destination surface of the mesh.Arguments
- int dest_surface - Number of the destination surface, with which a surface from the source ObjectMeshSkinned is to be merged.
- ObjectMeshSkinned mesh - Source ObjectMeshSkinned to copy a surface from.
- int surface - Number of the source mesh surface to copy.
- int target - Number of mesh target to merge. The default value is -1 (all morph targets will be merged).
Return value
Number of the destination mesh surface.int AddMeshSurface ( string name, Mesh mesh, int surface, int target = -1 ) #
Appends a new mesh surface to the current mesh by copying the specified surface from the source mesh.Arguments
- string name - Name of the new surface of the current mesh.
- Mesh mesh - Source mesh to copy a surface from.
- int surface - Number of the source mesh surface to copy.
- int target - Number of mesh target to copy. The default value is -1 (all morph targets will be copied).
Return value
Number of the added mesh surface.int AddSurfaceTarget ( int surface, string name = 0 ) #
Appends a new morph target to the given mesh surface.Arguments
- int surface - Number of the surface, to which the morph target will be appended.
- string name - Name of the new morph target.
Return value
Number of the new added morph target.int AddSurfaceTarget ( int dest_surface, ObjectMeshSkinned src_mesh, int src_surface, int src_target = -1 ) #
Appends a new morph target to the given mesh surface by copying it from the specified surface of the source ObjectMeshSkinned.Arguments
- int dest_surface - Number of the surface, to which the morph target will be appended.
- ObjectMeshSkinned src_mesh - Source ObjectMeshSkinned to copy the morph target from.
- int src_surface - Number of the surface of the source ObjectMeshSkinned to copy the morph target from.
- int src_target - Number of the morph target to copy. The default value is -1 (all morph targets will be copied).
Return value
Number of the new added morph target.int AddTarget ( int surface ) #
Appends a new empty morph target to the given mesh surface.Arguments
- int surface - Number of the surface, to which the morph target will be appended.
Return value
number of the new added morph target.void ClearLayer ( int layer ) #
Clears the given animation layer.Arguments
- int layer - Animation layer number.
void CopyLayer ( int dest, int src ) #
Copies source layer bones transformations to the destination layer. The copying conditions are the following:
- If the destination layer has more bones than the source one, it will keep its former transformations.
- If the source layer has more bones than destination one, those bones will be added to the destination layer.
Arguments
- int dest - Number of the destination layer in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
- int src - Number of the source layer in range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
int CreateMesh ( string path, bool unique = 0 ) #
Creates a skinned mesh.Arguments
- string path - Path to the mesh file.
- bool unique - Dynamic flag:
- false (0) - If the mesh vertices are changed in run-time, meshes loaded from the same file will be also changed.
- true (1) - If the mesh vertices are changed in run-time, meshes loaded from the same file won't be changed
Return value
1 if the mesh is created successfully; otherwise - 0.int FindAnimation ( string path ) #
Searches for an animation using the given path.Arguments
- string path - Path to animation file.
Use the path specified on animation loading.
Return value
Animation number, if found; otherwise, -1.int FindBone ( string name ) #
Searches for a bone with a given name.Arguments
- string name - Bone name.
Return value
Bone number if found; otherwise, -1.int FindSurfaceTarget ( string name, int surface ) #
Searches for a surface morph target with a given name.Arguments
- string name - Name of the morph target.
- int surface - Mesh surface number.
Return value
Number of the morph target, if exists; otherwise, -1.void FlushMesh ( ) #
Flushes mesh geometry to the video memory.void ImportLayer ( int layer ) #
Copies the current bone state to the given animation layer.Arguments
- int layer - Animation layer number.
void InverseLayer ( int dest, int src ) #
Copies inverse transformations of bones from the source layer to the destination layer.Arguments
- int dest - Number of the destination layer in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
- int src - Number of the source layer in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
void LerpLayer ( int dest, int layer0, int layer1, float weight ) #
Copies interpolated bone transformations from two source layers to a destination layer.Arguments
- int dest - Number of the destination layer in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
- int layer0 - Number of the first source layer in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
- int layer1 - Number of the second source layer in range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
- float weight - Interpolation weight.
int LoadMesh ( string path ) #
Loads a new mesh instead of the current mesh from the .mesh file. This function doesn't change the mesh name.Arguments
- string path - The path to the .mesh file.
Return value
1 if the mesh is loaded successfully; otherwise, 0.void MergeMeshSurface ( int dest_surface, ObjectMeshSkinned src_mesh, int src_surface ) #
Merges the specified surface from the source ObjectMeshSkinned with the specified destination surface of the mesh.Arguments
- int dest_surface - Number of the destination surface, with which a surface from the source ObjectMeshSkinned is to be merged.
- ObjectMeshSkinned src_mesh - Source ObjectMeshSkinned to copy a surface from.
- int src_surface - Number of source mesh surface to merge.
void MulLayer ( int dest, int layer0, int layer1, float weight = 1.0f ) #
Copies multiplied bone transformations from two source layers to the destination layer.Arguments
- int dest - Number of the destination layer in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
- int layer0 - Number of the first source layer in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
- int layer1 - Number of the second source layer in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
- float weight - Interpolation weight.
void Play ( ) #
Continues playback of the animation, if it was paused, or starts playback if it was stopped.void RemoveAnimation ( int animation ) #
Removes the given animation.Arguments
- int animation - Animation number.
void RemoveLayer ( int layer ) #
Removes an animation layer.Arguments
- int layer - Layer number in the range from 0 to the total number of animation layers.
To get the total number of animation layers, use the getNumLayers() method.
void RemoveTarget ( int target, int surface ) #
Removes the given morph target.Arguments
- int target - Target number in the range from 0 to the total number of morph targets.
To get the total number of morph targets for a given surface, use the getNumTargets() method.
- int surface - Mesh surface number.
int SaveMesh ( string path ) #
Saves the mesh to .mesh or .anim format.Arguments
- string path - Path to the file including the file name and extension — *.mesh or *.anim.
Return value
1 if the mesh is saved successfully; otherwise, 0.void Stop ( ) #
Stops animation playback. This function saves the playback position so that playing of the animation can be resumed from the same point.static int type ( ) #
Returns the type of the node.Return value
Node type identifier.void UpdateSurfaceBounds ( int surface = -1 ) #
Updates mesh surface bounds. This method is to be called to recalculate bounds after changing a mesh surface (e.g. modifying positions of coordinate vertices).Arguments
- int surface - Number of the surface to recalculate bound for. The default value is -1 (all surfaces).
void UpdateSkinned ( ) #
Forces update of all bone transformations.mat4 GetBoneNotAdditionalBindLocalTransform ( int bone ) #
Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
mat4 GetBoneNotAdditionalBindObjectTransform ( int bone ) #
Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
mat4 GetBoneNotAdditionalBindWorldTransform ( int bone ) #
Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
void SetBindNode ( int bone, Node node ) #
Sets a new node whose transformation is to be used to control the transformation of the bone with the specified number.Arguments
- int bone - Number of the bone to be controlled by the specified node, in the range from 0 to the total number of bones.
- Node node - Node whose transformation is used to control the transformation of the bone.
void RemoveBindNode ( int bone ) #
Removes the assigned bind node from the bone with the specified number.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
Node GetBindNode ( int bone ) #
Returns the bind node currently assigned to the bone with the specified number.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
Return value
Node whose transformation is used to control the transformation of the bone if it is assigned; otherwise - nullptr.void SetBindNodeSpace ( int bone, ObjectMeshSkinned.NODE_SPACE space ) #
Sets a new value indicating which transformation of the bind node (World or Local) is to be used to override the transformation of the specified bone.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
- ObjectMeshSkinned.NODE_SPACE space - Type of transformation of the bind node to be used to override the transformation of the specified bone, one of the NODE_SPACE* values.
ObjectMeshSkinned.NODE_SPACE GetBindNodeSpace ( int bone ) #
Returns the current value indicating which transformation of the bind node (World or Local) is to be used to override the transformation of the specified bone.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
Return value
Type of transformation of the bind node to be used to override the transformation of the specified bone, one of the NODE_SPACE* values.void SetBindBoneSpace ( int bone, ObjectMeshSkinned.BONE_SPACE space ) #
Sets a value indicating which transformation of the specified bone is to be overridden by the bind node's transformation.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
- ObjectMeshSkinned.BONE_SPACE space - Type of transformation of the specified bone to be overridden by the bind node's transformation, one of the BONE_SPACE* values.
ObjectMeshSkinned.BONE_SPACE GetBindBoneSpace ( int bone ) #
Returns the current value indicating which transformation of the specified bone is to be overridden by the bind node's transformation.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
Return value
Current type of transformation of the specified bone overridden by the bind node's transformation, one of the BONE_SPACE* values.void SetBindMode ( int bone, ObjectMeshSkinned.BIND_MODE mode ) #
Sets a new type of blending of bind node's and bone's transformations.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
- ObjectMeshSkinned.BIND_MODE mode - New type of blending of bind node's and bone's transformations:
- OVERRIDE - replace bone's transformation with the transformation of the node.
- ADDITIVE - node's transformation is added to the current transformation of the bone.
ObjectMeshSkinned.BIND_MODE GetBindMode ( int bone ) #
Returns the current type of blending of bind node's and bone's transformations.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
Return value
Current type of blending of bind node's and bone's transformations:- OVERRIDE - replace bone's transformation with the transformation of the node.
- ADDITIVE - node's transformation is added to the current transformation of the bone.
void SetBindNodeOffset ( int bone, mat4 offset ) #
Sets a new transformation matrix to be applied to the node's transformation before applying it to bone's transformation. This parameter serves for the purpose of additional correction of the node's transform for the bone's basis.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
- mat4 offset - Transformation matrix applied to the node's transformation before applying it to bone's transformation.
mat4 GetBindNodeOffset ( int bone ) #
Returns the current transformation matrix which is applied to the node's transformation before applying it to bone's transformation. This parameter serves for the purpose of additional correction of the node's transform for the bone's basis.Arguments
- int bone - Number of the bone, in the range from 0 to the total number of bones.
Return value
Transformation matrix currently applied to the node's transformation before applying it to bone's transformation.void AddVisualizeBone ( int bone ) #
Adds a bone with the specified number to the list of the bones for which the basis vectors are to be visualized.Arguments
- int bone - Number of the bone to be added to the visualizer, in the range from 0 to the total number of bones.
void RemoveVisualizeBone ( int bone ) #
Removes a bone with the specified number from the list of the bones for which the basis vectors are to be visualized.Arguments
- int bone - Number of the bone to be removed from the visualizer, in the range from 0 to the total number of bones.
void ClearVisualizeBones ( ) #
Clears the list of the bones for which the basis vectors are to be visualized.void SetVisualizeAllBones ( bool bones ) #
Sets a value indicating if visualization for bones and their basis vectors is enabled. The visualizer can be used for debugging purposes showing positions of bones and their basis vectors for multiple meshes simultaneously.Arguments
- bool bones - true to enable visualization of bones and their basis vectors; false — to disable it.