Mesh Class
Mesh class provides an interface for mesh loading, manipulating and saving.
By using this class, you can create a mesh, add geometry to it (e.g. box, plane, capsule or cylinder surface), add animations and bones (if you want to create a skinned mesh) and then use it to create the following objects:
Features of the mesh are listed below:
- Each surface of the mesh supports several morph targets.
- Each surface has a quaternion-based tangent basis for the better loading speed.
- 8-bit vertex colors are supported.
- Each vertex of a surface has 2 sets of indices: coordinate and triangle indices. It improves the loading speed and reduces data duplicating.
- Each vertex of a surface has 2 UV sets.
- A bind pose transformation is stored for each mesh (even if there are no animations and animation frames). See also the getBoneTransfroms() function.
The 1st animation frame should not contain the bind pose.
Vertex Indices
Each vertex stores information about its position, normal, binormal, tangent and texture coordinates in 2 separate buffers: coordinate and triangle buffers.
On the picture below, arrows are used to show triangle vertices:
The coordinate buffer is an array of coordinate vertices. For example, the coordinate buffer for the surface presented on the picture above is the following:
CB = [C0,C1,C2,C3]
The triangle buffer is an array of triangle vertices. For example, the triangle buffer for the surface presented on the picture above is the following:
TB = [T0,T1,T2,T3,T4,T5]
- Normal
- Binormal
- Tangent
- 1st UV map texture coordinates
- 2nd UV map texture coordinates
- Color
Both the coordinate and triangle vertices have indices.
Coordinate Indices
Each coordinate vertex has a coordinate index. The number of coordinate indices is equal to 3*number of triangles. For the given surface the array of the coordinate indices is the following:
CIndices = [Ci0,Ci1,Ci3,Ci1,Ci2,Ci3]
- The first 3 elements are the coordinate indices of the first (bottom) triangle.
- The second 3 elements are the coordinate indices of the second (top) triangle.
Triangle Indices
Each triangle vertex has a triangle index. The number of triangle indices is equal to 3*number of triangles. For the given surface the array of the triangle indices is the following:
TIndices = [Ti0,Ti1,Ti5,Ti2,Ti3,Ti4]
- The first 3 elements are the triangle indices of the first (bottom) triangle.
- The second 3 elements are the triangle indices of the second (top) triangle.
See Also
- Article on Mesh File Formats
Mesh Class
Members
Mesh ()
Constructor. Creates an empty mesh.Mesh (variable v)
Constructor. Creates a mesh by using the given mesh name or the other mesh.By using this constructor you can copy one mesh instance to another.
Usage Example
The following example shows how to copy the ObjectMeshDynamic to the Mesh class instance and create the new Mesh class instance by using the first mesh.
/* ... */
// create ObjectMeshDynamic and Mesh instances
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic();
Mesh firstMesh = new Mesh();
// get the ObjectMeshDynamic and copy it to the Mesh class instance
dynamicMesh.getMesh(firstMesh);
// create a new Mesh which is the copy of the firstMesh
Mesh secondMesh = new Mesh(firstMesh);
/* ... */
Arguments
- variable v -
Argument of one of the following types:
- string name - Mesh name.
- Mesh mesh - Mesh: instance of the Mesh class.
int addAnimation (string name = 0)
Appends an animation with a given name to the current mesh.Arguments
- string name - Name of the animation. This argument is empty by default.
Return value
Number of mesh animations.int addBone (string name = 0, int parent = -1)
Appends a new mesh bone.Arguments
- string name - Bone name. This argument is empty by default.
- int parent - The parent bone number. -1 means no parent bone.
Return value
Number of mesh bones.int addBoxSurface (string name, vec3 size)
Appends a box surface to the current mesh.Usage Example
// create a mesh instance
Mesh mesh = new Mesh();
// add box surface with the name "box_surface" and the size of the surface is Vec3(1.0, 1.0, 1.0)
mesh.addBoxSurface("box_surface", Vec3(1.0f));
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear.
Arguments
- string name - Surface name.
- vec3 size - Box size along the X, Y and Z axes.
Return value
The added surface number.void addCIndex (int index, int surface)
Appends a coordinate index to the array of the surface coordinate indices.Arguments
- int index - The index number in the index buffer.
- int surface - The surface number.
int addCapsuleSurface (string name, float radius, float height, int stacks, int slices)
Appends a capsule surface to the current mesh. The stacks and slices specify the surface's subdivision.Usage Example
// create a mesh instance
Mesh mesh = new Mesh();
// add capsule surface with the name "capsule_surface".
// the radius of the capsule is 1.0, the height is 2.0,
// stacks and slices are equals to 200 and 100, respectively
mesh.addCapsuleSurface("box_surface", 1.0f, 2.0f, 200, 100);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear.
Arguments
- string name - Surface name.
- float radius - Radius of the capsule.
- float height - Height of the capsule.
- int stacks - Number of stacks that divide the capsule radially.
- int slices - Number of slices that divide the capsule horizontally.
Return value
The added surface number.void addColor (vec4 color, int surface)
Appends the given color to the vertex color array of the given surface.Arguments
- vec4 color - Color to be added.
- int surface - The surface number.
int addCylinderSurface (string name, float radius, float height, int stacks, int slices)
Appends a cylinder surface to the current mesh. The stacks and slices specify the surface's subdivision.Usage Example
// create a mesh instance
Mesh mesh = new Mesh();
// add cylinder surface with the name "cylinder_surface".
// the radius of the cylinder is 1.0, the height is 2.0,
// stacks and slices are equals to 200 and 100, respectively
mesh.addCylinderSurface("cylinder_surface", 1.0f, 2.0f, 200, 100);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear.
Arguments
- string name - Surface name.
- float radius - Radius of the cylinder.
- float height - Height of the cylinder.
- int stacks - Number of stacks that divide the cylinder radially.
- int slices - Number of slices that divide the cylinder horizontally.
Return value
The added surface number.int addDodecahedronSurface (string name, float radius)
Appends a dodecahedron surface to the current mesh.Usage Example
// create a mesh instance
Mesh mesh = new Mesh();
// add dodecahedron surface with the name "dodecahedron_surface".
// the radius of the dodecahedron is 1.0
mesh.addDodecahedronSurface("dodecahedron_surface", 1.0f);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear.
Arguments
- string name - Surface name.
- float radius - Radius of the dodecahedron.
Return value
The added surface number.int addEmptySurface (string name, int num_vertex, int num_indices)
Appends a new empty surface to the current mesh.Arguments
- string name - The surface name.
- int num_vertex - Number of surface vertices.
- int num_indices - Number of surface indices.
Return value
Number of the mesh surfaces.int addIcosahedronSurface (string name, float radius)
Appends a icosahedron surface to the current mesh.Usage Example
// create a mesh instance
Mesh mesh = new Mesh();
// add icosahedron surface with the name "icosahedron_surface".
// the radius of the icosahedron is 1.0
mesh.addIcosahedronSurface("icosahedron_surface", 1.0f);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear.
Arguments
- string name - Surface name.
- float radius - Radius of the icosahedron.
Return value
The added surface number.void addIndex (int index, int surface)
Appends a given index to the arrays of coordinate and triangle indices for the given surface.Arguments
- int index - The index number in the index buffer.
- int surface - The surface number.
int addMeshSurface (variable v, Mesh mesh, int surface, int target = -1)
Depending on the first variable passed as an argument, the function appends the source mesh surface to the existing or the new surface of the current mesh, namely, the specified morph targets, all surface weights, bones, texture coordinates and colors.Usage Example
The following example show how to add a surface from the one mesh object to another.
// create mesh instances
Mesh mesh_1 = new Mesh();
Mesh mesh_2 = new Mesh();
// add Surfaces for the added meshes
mesh_1.addCapsuleSurface("capsule_surface", 1.0f, 2.0f, 200, 100);
mesh_2.addBoxSurface("box_surface", vec3(2.2));
// add the surface from the mesh_2 to the mesh_1 as a new surface
// with the name "new_box_surface"
mesh_1.addMeshSurface("new_box_surface", mesh_2, 0);
// create the ObjectMeshDynamic from the mesh_1 object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh_1);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear.
Arguments
- variable v - Variable used to control to which surface of the current mesh geometry is added:
- int dest_surface - The number of the existing surface of the current mesh, to which the geometry is added.
- string name - The name of the new surface added to the current mesh.
- Mesh mesh - Source mesh to copy geometry (or a surface) from.
- int surface - The number of the source mesh surface to copy geometry from.
- int target - The number of the morph target of the source mesh surface. -1 means all of the morph targets.
Return value
Depending on the first variable passed as an argument, the function returns the following:- int - Returns the number of the surface to which the geometry has been added.
- string - Returns the number of the mesh surfaces.
If the geometry (or the surface) is not added, the function will return -1.
void addNormal (vec3 normal, int surface, int target = 0)
Appends a normal to the array of normals of the given morph target.Arguments
- vec3 normal - Normal to be added.
- int surface - The surface number.
- int target - The morph target number.
int addPlaneSurface (string name, float width, float height, float step)
Appends a plane surface to the current mesh. The plane is divided into equal squares whose size is defined by the given step.Usage Example
// create a mesh instance
Mesh mesh = new Mesh();
// add the plane surface with the name "plane_surface".
// the width is 2 and the height is 3
mesh.addPlaneSurface("plane_surface", 2.0f, 3.0f, 1.0f);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear. You could see that the plane divided each 1 unit to equal squares.
Arguments
- string name - Surface name.
- float width - Width of the plane.
- float height - Height of the plane.
- float step - Step of surface subdivision (vertical and horizontal).
Return value
The added surface number.int addPrismSurface (string name, float size_0, float size_1, float height, int sides)
Appends a prism surface to the current mesh.Usage Example
// create a mesh instance
Mesh mesh = new Mesh();
// add the prism surface with the name "prism_surface".
// the radius of the top is 1.0f, of the bottom is 2.0f
// the height of the prism is 3.0f, and it has 4 sides
mesh.addPrismSurface("prism_surface", 1.0f, 2.0f, 3.0f, 4);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear.
Arguments
- string name - Surface name.
- float size_0 - Radius of the circle circumscribed about the top prism base.
- float size_1 - Radius of the circle circumscribed about the bottom prism base.
- float height - Height of the prism.
- int sides - Number of the prism faces.
Return value
The added surface number.int addSphereSurface (string name, float radius, int stacks, int slices)
Appends a sphere surface to the current mesh. The stacks and slices specify the surface's subdivision.Usage Example
// create a mesh instance
Mesh mesh = new Mesh();
// add the sphere surface with the name "sphere_surface".
// the radius of the sphere is 1.0f
// and it has 200 stacks and 100 slices
mesh.addSphereSurface("sphere_surface", 1.0f, 200, 100);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("Dynamic Mesh");
After adding to the editor, the mesh will appear.
Arguments
- string name - Surface name.
- float radius - Radius of the sphere.
- int stacks - Number of stacks that divide the sphere radially.
- int slices - Number of slices that divide the sphere horizontally.
Return value
The added surface number.int addSurfaceTarget (int surface, string name = 0)
Appends a morph target with the given name to the given surface.Arguments
- int surface - The surface number.
- string name - Name of the morph target. This argument is empty by default.
Return value
Number of morph targets.int addSurface (string name = 0)
Appends a new surface with the given name to the current mesh.Usage Example
In the following example, we create a new surface and add vertices and indices to create a plane.
// create a mesh instance
Mesh mesh = new Mesh();
// add a new surface
mesh.addSurface("surface_0");
// add vertices of the plane
mesh.addVertex(vec3(0.0f,0.0f,0.0f),0);
mesh.addVertex(vec3(0.0f,0.0f,1.0f),0);
mesh.addVertex(vec3(0.0f,1.0f,0.0f),0);
mesh.addVertex(vec3(0.0f,1.0f,1.0f),0);
// add indices
mesh.addIndex(0,0);
mesh.addIndex(1,0);
mesh.addIndex(2,0);
mesh.addIndex(3,0);
mesh.addIndex(2,0);
mesh.addIndex(1,0);
// create tangents
mesh.createTangents();
// create mesh bounds
mesh.createBounds(0);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("new_mesh");
Arguments
- string name - Surface name. This argument is empty by default.
Return value
Number of mesh surfaces.void addTIndex (int index, int surface)
Appends a triangle index to the given mesh surface.Arguments
- int index - The index number in the index buffer.
- int surface - The number of the surface to which the triangle index is added.
void addTangent (quat tangent, int surface, int target = 0)
Appends the given tangent to the specified surface.Arguments
- quat tangent - Tangent to add.
- int surface - Number of the mesh surface.
- int target - Number of the surface's morph target.
void addTexCoord0 (vec2 texcoord, int surface)
Appends texture coordinates to the array of the first UV map coordinates of the given mesh surface.Arguments
- vec2 texcoord - Coordinates of the first UV map to be added.
- int surface - The surface number.
void addTexCoord1 (vec2 texcoord, int surface)
Appends texture coordinates to the array of the second UV map coordinates of the given mesh surface.Arguments
- vec2 texcoord - Coordinates of the second UV map to be added.
- int surface - The surface number.
void addVertex (vec3 vertex, int surface, int target = 0)
Appends a new vertex with the given coordinates to the morph target of the mesh surface.Usage Example
In the following example, we create a new surface and add 4 vertices to it. We use local coordinates to define a vertex and specify the surface. After that we specify 6 indices to create a plane by using defined vertices.
// create a mesh instance
Mesh mesh = new Mesh();
// add a new surface
mesh.addSurface("surface_0");
// add vertices of the plane
mesh.addVertex(vec3(0.0f,0.0f,0.0f),0);
mesh.addVertex(vec3(0.0f,0.0f,1.0f),0);
mesh.addVertex(vec3(0.0f,1.0f,0.0f),0);
mesh.addVertex(vec3(0.0f,1.0f,1.0f),0);
// add indices
mesh.addIndex(0,0);
mesh.addIndex(1,0);
mesh.addIndex(2,0);
mesh.addIndex(3,0);
mesh.addIndex(2,0);
mesh.addIndex(1,0);
// create tangents
mesh.createTangents();
// create mesh bounds
mesh.createBounds(0);
// create the ObjectMeshDynamic from the Mesh object
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh);
// add dynamicMesh to the editor as a Node object
engine.editor.addNode(node_remove(dynamicMesh));
// set the position of the mesh
dynamicMesh.setWorldTransform(translate(Vec3(10.0f,10.0f,10.0f)));
// set the material to the mesh
dynamicMesh.setMaterial("mesh_base","*");
// set the property to the mesh
dynamicMesh.setProperty("surface_base","*");
// set the name of the mesh
dynamicMesh.setName("new_mesh");
Arguments
- vec3 vertex - Coordinates of the vertex to be added.
- int surface - The mesh surface number.
- int target - The morph target number.
void clear ()
Clears the mesh including bones, animation, surfaces, bounding boxes and spheres.int createBounds (int surface = -1)
Creates bounds (a bounding box and a bounding sphere) for the given surface. If the default value is used as an argument, the bounds will be created for all of the mesh surfaces.Arguments
- int surface - The mesh surface number. -1 means all of the mesh surfaces.
Return value
1 if bounds are created successfully; otherwise, 0.int createIndices (int surface = -1)
Creates indices for the given surface. If the default value is used as an argument, the indices will be created for all of the mesh surfaces.Arguments
- int surface - Number of the mesh surface. -1 means all of the mesh surfaces.
Return value
1 if indices are created successfully; otherwise, 0.int createNormals (float angle, int surface, int target)
Creates normals for the morph target. If there are several normals at one vertex, a mean normal for this vertex will be calculated by using the given angle.Arguments
- float angle - Angle between normals used to calculate the mean vertex normal.
- int surface - The mesh surface number. -1 means all of the mesh surfaces.
- int target - The morph target number. -1 means all of the morph targets.
Return value
1 if the normals are created successfully; otherwise, 0.int createNormals ()
Creates normals for all of the mesh surfaces.Return value
1 if the normals are created successfully; otherwise, 0.int createNormals (variable v0)
Creates normals, namely:- If the passed argument is the mesh surface number, the normals will be created for all of the morph targets of the given mesh surface.
- If the passed argument is the angle between normals, the normals will be created for all of the mesh surfaces and their morph targets.
If there are several normals at one vertex, a mean normal for this vertex will be calculated by using the given angle.
Arguments
- variable v0 - Argument of one of the following types:
- int surface - The mesh surface number.
- float angle - Angle between normals used to calculate the mean vertex normal.
Return value
1 if the normals are created successfully; otherwise, 0.int createNormals (variable v0, int v1)
Creates normals, namely:- If the first passed argument is the mesh surface number, the normals will be created for the given morph target.
- If the first passed argument is the angle between normals, the normals will be created for all of the morph targets.
If there are several normals at one vertex of the surface, a mean normal for this vertex will be calculated by using the given angle.
Arguments
- variable v0 - Argument of one of the following types:
- int surface - The mesh surface number.
- float angle - Angle between normals used to calculate the mean vertex normal.
- int v1 - Argument of one of the following types:
The type of this argument depends on the first argument type.
- int target - The morph target number (if the first argument type is int).
- int surface - The mesh surface number (if the first argument type is float).
Return value
1 if the normals are created successfully; otherwise, 0.int createTangents (int surface = -1, int target = -1)
Creates tangents for the given morph target.Arguments
- int surface - The mesh surface number. -1 means all of the mesh surfaces.
- int target - The morph target number. -1 means all of the morph targets.
Return value
1 if the tangents are created successfully; otherwise, 0.int findAnimation (string name)
Searches for the animation by the name and returns its number.Arguments
- string name - Name of the animation.
Return value
The animation number, if found; otherwise, -1.int findBone (string name)
Searches for a bone with a given name and returns its number.Arguments
- string name - Name of the bone.
Return value
The bone number.int findSurfaceTarget (int surface, string name)
Searches for the morph target number by the target name.Arguments
- int surface - The mesh surface number.
- string name - The morph target name.
Return value
The morph target number, if exists; otherwise, -1.int findSurface (string name)
Searches for the surface number by its name.Arguments
- string name - The mesh surface name.
Return value
The mesh surface number, if found; otherwise, -1.int flipTangent (int surface = -1)
Flips the sign of the binormal component of the surface tangent space.Arguments
- int surface - The mesh surface number. -1 means all of the mesh surfaces.
Return value
1 if the sign of the binormal component is flipped successfully; otherwise, 0.int flipYZ (int surface = -1)
Flips the Y and Z axes for the given surface:- Y axis becomes equal to -Z
- Z axis becomes equal to Y
Arguments
- int surface - The mesh surface number. -1 means all of the mesh surfaces.
Return value
1 if the axes are flipped successfully; otherwise, 0.void getAnimationBones (int animation, int id = [])
Adds all bones of the given animation to the given array.Arguments
- int animation - The animation number.
- int id - Array with indices of bones taking part in the animation.
void getAnimationFrame (int animation, int num, int xyz_id = [], int rot_id = [], int scale_id = [])
Adds the animation frame coordinates, rotation quaternions and scaling vectors to the corresponding arrays passed to the function as arguments.Arguments
- int animation - The animation number.
- int num - The frame number in the array of the animation frames.
- int xyz_id - Array with coordinates of the animation frame.
- int rot_id - Array with rotation quaternions of the animation frame.
- int scale_id - Array with scaling vectors of the animation frame.
void getAnimationFrame (int animation, int num, int id = [])
Adds the animation frame coordinates, rotation quaternions and scaling vectors to the given matrix passed to the function as the third argument.Arguments
- int animation - The animation number.
- int num - Number of the frame in the array of the animation frames.
- int id - Matrix that includes coordinates, rotation quaternions and scaling vectors of the animation frame.
string getAnimationName (int animation)
Returns the name of the given animation.Arguments
- int animation - The animation number.
Return value
The animation name.string getBoneName (int bone)
Returns the name of the given bone.Arguments
- int bone - The bone number.
Return value
The bone name.int getBoneParent (int bone)
Returns the number of the parent bone of the given one.Arguments
- int bone - The bone number, for which the parent bone will be returned.
Return value
The parent bone number.mat4 getBoneTransform (int bone)
Returns the transformation matrix for the given bone.Arguments
- int bone - The bone number.
Return value
Transformation matrix.int getBoneTransforms (int id = [], int animation = -1, int frame = 0)
Appends the world-space transformation matrices for bones of the given animation frame to the given array.Arguments
- int id - Array of transformation matrices. It is empty by default.
- int animation - The animation number.
- int frame - The animation frame number.
Return value
1 if the array of bones' transformations is filled successfully; otherwise, 0.BoundBox getBoundBox ()
Returns the bounding box of the current mesh.Return value
Bounding box.BoundBox getBoundBox (int surface)
Returns the bounding box of a given surface.Arguments
- int surface - The surface number.
Return value
Bounding box.BoundSphere getBoundSphere ()
Returns the bounding sphere of the current mesh.Return value
Bounding sphere.BoundSphere getBoundSphere (int surface)
Returns the bounding sphere of a given surface.Arguments
- int surface - The surface number.
Return value
Bounding sphere.int getCIndex (int num, int surface)
Returns the coordinate index by its number.Arguments
- int num - The index number in range from 0 to the total number of coordinate indices of the given surface.
- int surface - The mesh surface number.
Return value
The coordinate index.vec4 getColor (int num, int surface)
Returns the vertex color.Arguments
- int num - The vertex color number in the vertex color array.
- int surface - The mesh surface number.
Return value
Vertex color.int getIndex (int num, int surface)
Returns the coordinate index by using the given number if the coordinate index is equal to the triangle index.Arguments
- int num - The index number in the array of coordinate indices.
- int surface - The mesh surface number.
Return value
The coordinate index.vec3 getNormal (int num, int surface, int target = 0)
Returns the vertex normal of the given morph target by using the vertex normal number.Arguments
- int num - The vertex normal number in the array of normals.
- int surface - The mesh surface number.
- int target - The morph target number.
Return value
Vertex normal.int getNumAnimationFrames (int animation)
Returns the number of animation frames for the given animation.Arguments
- int animation - The animation number.
Return value
Number of the animation frames.int getNumAnimations ()
Returns the total number of mesh animations.Return value
Number of the mesh animations.int getNumBones ()
Returns the total number of mesh bones.Return value
Number of the mesh bones.int getNumCIndices (int surface)
Returns the number of coordinate indices for the given surface.Arguments
- int surface - The mesh surface number.
Return value
Number of the coordinate indices.int getNumCVertex (int surface)
Returns the number of coordinate vertices of the given surface.Arguments
- int surface - The mesh surface number.
Return value
Number of the coordinate vertices.int getNumColors (int surface)
Returns the number of colors set for vertices of the given surface.Arguments
- int surface - The mesh surface number.
Return value
Number of colors.int getNumIndices (int surface)
Returns the number of coordinate indices of the given surface if the number of the coordinate indices is equal to the number of triangle indices.Arguments
- int surface - The mesh surface number.
Return value
Number of the coordinate indices.int getNumNormals (int surface, int target = 0)
Returns the number of normals for the given morph target.Arguments
- int surface - The mesh surface number.
- int target - The morph target number.
Return value
Number of normals.int getNumSurfaceTargets (int surface)
Returns the number of morph targets for the given surface.Arguments
- int surface - The mesh surface number.
Return value
Number of morph targets.int getNumSurfaces ()
Returns the total number of mesh surfaces.Return value
Number of the mesh surfaces.int getNumTIndices (int surface)
Returns the number of triangle indices for the given surface.Arguments
- int surface - The mesh surface number.
Return value
Number of the triangle indices.int getNumTVertex (int surface)
Returns the number of triangle vertices for the given mesh surface.Arguments
- int surface - The mesh surface number.
Return value
Number of the triangle vertices.int getNumTangents (int surface, int tangent = 0)
Returns the number of tangents for the given morph target.Arguments
- int surface - The mesh surface number.
- int tangent - The morph target number.
Return value
Number of tangents.int getNumTexCoords0 (int surface)
Returns the number of the first UV map texture coordinates for the given mesh surface.Arguments
- int surface - The mesh surface number.
Return value
Number of the first UV map texture coordinates.int getNumTexCoords1 (int surface)
Returns the number of the second UV map texture coordinates for the given mesh surface.Arguments
- int surface - The mesh surface number.
Return value
Number of the second UV map texture coordinates.int getNumVertex (int surface, int target = 0)
Returns the number of vertices for the given morph target.Arguments
- int surface - The mesh surface number.
- int target - The morph target number.
Return value
Number of the vertices.int getNumWeights (int surface)
Returns the number of weights set for vertices of the given surface.Arguments
- int surface - The mesh surface number.
Return value
Number of the weights.string getSurfaceName (int surface)
Returns the name of the given surface.Arguments
- int surface - The mesh surface number.
Return value
The surface name.string getSurfaceTargetName (int surface, int target)
Returns the name of the given morph target.Arguments
- int surface - The mesh surface number.
- int target - The morph target number.
Return value
The morph target name.int getTIndex (int num, int surface)
Returns the triangle index for the given surface by using the index number.Arguments
- int num - The index number in the array of triangle indices.
- int surface - The mesh surface number.
Return value
The triangle index.quat getTangent (int num, int surface, int target = 0)
Returns the tangent for the given vertex of the mesh surface.Arguments
- int num - Number of the vertex in the vertex buffer.
- int surface - Number of the mesh surface.
- int target - Number of the surface's morph target.
Return value
Vertex tangent.vec2 getTexCoord0 (int num, int surface)
Returns the first UV map texture coordinates for the given surface.Arguments
- int num - The number of the texture coordinates in the array of the first UV map texture coordinates.
- int surface - The mesh surface number.
Return value
The first UV map texture coordinates.vec2 getTexCoord1 (int num, int surface)
Returns the second UV map texture coordinates for the given surface.Arguments
- int num - The number of the texture coordinates in the array of the second UV map texture coordinates.
- int surface - The mesh surface number.
Return value
The second UV map texture coordinates.vec3 getVertex (int num, int surface, int target = 0)
Returns coordinates of the given vertex.Arguments
- int num - The vertex number in the vertex buffer.
- int surface - The mesh surface number.
- int target - The morph target number.
Return value
Vertex coordinates.ivec4 getWeightBones (int num, int surface)
Returns a vector of bone indices that affect the vertex with the given weight.- The 4 bone indices;
- The 4 bone weights;
- Number of the weights.
Arguments
- int num - The weight number in the array of vertex weights.
- int surface - The mesh surface number.
Return value
Vector of the bone indices associated with the given weight.int getWeightCount (int num, int surface)
Returns the number of weights that affect the vertex with the given weight.- The 4 bone indices;
- The 4 bone weights;
- Number of the weights.
Arguments
- int num - The weight number in the array of vertex weights.
- int surface - The mesh surface number.
Return value
Number of weights.vec4 getWeightWeights (int num, int surface)
Returns a vector of bone weights that affect the vertex with the given weight.- The 4 bone indices;
- The 4 bone weights;
- Number of the weights.
Arguments
- int num - The weight number in the array of vertex weights.
- int surface - The mesh surface number.
Return value
Bone weights associated with the given weight.int info (string name)
Returns an information about the given mesh or animation.Arguments
- string name - The mesh or animation name.
Return value
1 if the information returned successfully; otherwise, 0.int load (string name)
Loads the given mesh.Arguments
- string name - The mesh name.
Return value
1 if the mesh is loaded successfully; otherwise, 0.int optimizeIndices (int flags, int surface = -1)
Optimizes indices of the given mesh surface.As polygons are added to a surface, vertices of the adjacent polygons are duplicated (you can get the number of such vertices by using the getNumTVertex()), because normals, texture coordinates and tangents of such vertices differ depending on the polygons, to which this vertices belongs. The optimizeIndices() function serves to decrease the number of such vertices and create indices for them that will be store the corresponding normals, tangents and texture coordinates.
Arguments
- int flags - One of the flags used for indices' optimization: MESH_BACK_TO_FRONT or MESH_VERTEX_CACHE.
- int surface - The mesh surface number.
Return value
1 if the indices are optimized successfully; otherwise, 0.int remapCVertex (int surface)
Sets the size of the array of coordinate indices to be equal to the size of the array of triangle indices and increases the size of the vertex buffer to the size of the array of triangle vertices by using the coordinate vertex duplicating.Arguments
- int surface - The mesh surface number.
Return value
1 if indices are copied successfully; otherwise, 0.int removeIndices (int surface = -1)
Clears the coordinate and triangle indices of the given surface.Arguments
- int surface - The mesh surface number. -1 means all of the mesh surfaces.
Return value
1 if the indices are cleared successfully; otherwise, 0.int save (string name)
Saves the given mesh.Arguments
- string name - Mesh name.
Return value
1 if the mesh is saved successfully; otherwise, 0.void setAnimationBones (int animation, int id = [])
Copies bones from the given array to the current array of animation bones.Arguments
- int animation - The animation number.
- int id - Array of bones taking part in the animation to be set.
void setAnimationFrame (int animation, int num, int xyz_id = [], int rot_id = [], int scale_id = [])
Updates the animation frame coordinates, rotation quaternions and scaling vectors.Arguments
- int animation - The animation number.
- int num - The frame number in the array of the animation frames.
- int xyz_id - Array with coordinates of the animation frame.
- int rot_id - Array with rotation quaternions of the animation frame.
- int scale_id - Array with scaling vectors of the animation frame.
Examples
Arrays passed to the function can be declared as follows:
Mesh animated_mesh; // we assume that the mesh is loaded here
vec3 translations[0];
quat rotations[0];
vec3 scales[0];
forloop(int i = 0; animated_mesh.getNumBones()) {
translations.append(vec3(1.0f,0.0f,0.0f));
rotations.append(quat(1.0f,0.0f,0.0f,45));
scales.append(vec3(1.5f,1.0f,1.0f));
}
animated_mesh.setAnimationFrame(0,0,translations,rotations,scales);
void setAnimationFrame (int animation, int num, int id = [])
Updates the animation frame coordinates, rotation quaternions and scaling vectors.Arguments
- int animation - The animation number.
- int num - The frame number in the array of the animation frames.
- int id - Matrix that includes coordinates, rotation quaternions and scaling vectors of the animation frame.
Examples
The matrix passed to the function can be declared as follows:
Mesh animated_mesh; // we assume that the mesh is loaded here
mat4 transforms[0];
forloop(int i = 0; animated_mesh.getNumBones()) {
transforms.append(translate(1.0f,0.0f,0.0f) * rotateX(45.0f) * scale(1.5f,1.0f,1.0f));
}
animated_mesh.setAnimationFrame(0,0,transforms);
void setAnimationName (int animation, string name)
Sets a name for the given animation.Arguments
- int animation - The animation number.
- string name - The animation name to be set.
void setBoneName (int bone, string name)
Sets a name for the given bone.Arguments
- int bone - The bone number.
- string name - The bone name to be set.
void setBoneParent (int bone, int parent)
Sets the parent bone for the given one.Arguments
- int bone - The bone number, for which the parent bone should be set.
- int parent - The bone to be set as a parent.
void setBoneTransform (int bone, mat4 transform)
Sets the transformation matrix for the given bone.Arguments
- int bone - The bone number.
- mat4 transform - Transformation matrix to be set.
int setBoneTransforms (int id = [], int animation = -1, int frame = 0)
Updates the array of the world-space transformation matrices for bones of the given animation frame.Arguments
- int id - Array of transformation matrices to be set. Its size must be equal to the number of animation bones.
- int animation - The animation number.
- int frame - The animation frame number.
Return value
1 if the array of bones' transformations is updated successfully; otherwise, 0.void setBoundBox (BoundBox bb, int surface)
Sets the bounding box for the given mesh surface.Arguments
- BoundBox bb - Bounding box to be set.
- int surface - The mesh surface number.
void setBoundBox (BoundBox bb)
Sets the bounding box for the current mesh.Arguments
- BoundBox bb - Bounding box to be set.
void setBoundSphere (BoundSphere bs, int surface)
Sets the bounding sphere for the given mesh surface.Arguments
- BoundSphere bs - Bounding sphere to be set.
- int surface - The mesh surface number.
void setBoundSphere (BoundSphere bs)
Sets the bounding sphere for the current mesh.Arguments
- BoundSphere bs - Bounding sphere to be set.
void setCIndex (int num, int index, int surface)
Sets the coordinate index.Arguments
- int num - The index number in range from 0 to the total number of coordinate indices of the given surface.
- int index - The coordinate index to be set.
- int surface - The mesh surface number.
void setColor (int num, vec4 color, int surface)
Sets the vertex color.Arguments
- int num - The vertex color number in the array of vertex colors.
- vec4 color - Vertex color to be set.
- int surface - The mesh surface number.
void setIndex (int num, int index, int surface)
Updates the index with the specified number.Arguments
- int num - The index number in the array of coordinate indices.
- int index - The index to be set.
- int surface - The mesh surface number.
void setNormal (int num, vec3 normal, int surface, int target = 0)
Updates the vertex normal of the given morph target by using the vertex normal number.Arguments
- int num - The vertex normal number in the array of normals.
- vec3 normal - Normal to be set.
- int surface - The mesh surface number.
- int target - The morph target number.
void setNumAnimationFrames (int animation, int num)
Sets the number of animation frames for the given animation.Arguments
- int animation - The animation number.
- int num - Number of the animation frames to be set.
void setNumCIndices (int size, int surface)
Sets the number of coordinate indices for the given surface.Arguments
- int size - Number of the coordinate indices to be set.
- int surface - The mesh surface number.
void setNumColors (int size, int surface)
Sets the number of colors set for vertices of the given surface.Arguments
- int size - Number of colors to be set.
- int surface - The mesh surface number.
void setNumIndices (int size, int surface)
Sets the number of indices for the given surface: updates the number of coordinate and triangle indices. For example, if you pass 5 as the first argument, the number of the coordinate indices and the number of triangle indices will be set to 5.Arguments
- int size - Number of indices to be set.
- int surface - The mesh surface number.
void setNumNormals (int size, int surface, int target = 0)
Sets the number of normals for the given morph target.Arguments
- int size - Number of normals to be set.
- int surface - The mesh surface number.
- int target - The morph target number.
void setNumSurfaceTargets (int surface, int num)
Sets the number of targets for the given mesh surface.Arguments
- int surface - The mesh surface number.
- int num - Number of the morph targets to be set.
void setNumTIndices (int size, int surface)
Sets the number of triangle indices for the given surface.Arguments
- int size - Number of triangle indices to be set.
- int surface - Number of the mesh surface.
void setNumTangents (int size, int surface, int target = 0)
Sets the number of tangents for the given morph target.Arguments
- int size - Number of tangents to be set.
- int surface - The mesh surface number.
- int target - The morph target number.
void setNumTexCoords0 (int size, int surface)
Sets the number of the first UV map texture coordinates for the given mesh surface.Arguments
- int size - Number of the first UV map texture coordinates to be set.
- int surface - The mesh surface number.
void setNumTexCoords1 (int size, int surface)
Sets the number of the second UV map texture coordinates for the given mesh surface.Arguments
- int size - Number of the second UV map texture coordinates to be set.
- int surface - The mesh surface number.
void setNumVertex (int size, int surface, int target = 0)
Updates the number of vertices for the given morph target.Arguments
- int size - Number of the vertices to be set.
- int surface - The mesh surface number.
- int target - The morph target number.
void setNumWeights (int size, int surface)
Sets the number of weights set for vertices of the given surface.Arguments
- int size - Number of weights to be set.
- int surface - The mesh surface number.
void setSurfaceName (int surface, string name)
Sets the name for the given mesh surface.Arguments
- int surface - The mesh surface number.
- string name - The surface name to be set.
void setSurfaceTargetName (int surface, int target, string name)
Sets the name for the given morph target.Arguments
- int surface - The mesh surface number.
- int target - The morph target number.
- string name - The morph target name to be set.
int setSurfaceTransform (mat4 transform, int surface = -1, int target = -1)
Sets the transformation matrix for the given morph target.Arguments
- mat4 transform - Transformation matrix to be set.
- int surface - The mesh surface number. -1 - apply to all of the mesh surfaces.
If all surfaces are chosen, bones and animations transformations will also be recalculated.
- int target - The morph target number. -1 - apply to all of the morph targets.
Return value
1 if the transformation matrix is set successfully; otherwise, 0.void setTIndex (int num, int index, int surface)
Updates the given triangle index of the given surface.Arguments
- int num - The index number in the array of triangle indices.
- int index - Index value to be set.
- int surface - The mesh surface number.
void setTangent (int num, quat tangent, int surface, int target = 0)
Sets the new tangent for the given vertex of the mesh surface.Arguments
- int num - Number of the vertex in the vertex buffer.
- quat tangent - Tangent to be set.
- int surface - Number of the mesh surface.
- int target - Number of the surface's morph target.
void setTexCoord0 (int num, vec2 texcoord, int surface)
Updates the first UV map texture coordinates of the given surface.Arguments
- int num - The number of the texture coordinates in the array of the first UV map texture coordinates.
- vec2 texcoord - The first UV map texture coordinates to be set.
- int surface - The mesh surface number.
void setTexCoord1 (int num, vec2 texcoord, int surface)
Updates the second UV map texture coordinates of the given surface.Arguments
- int num - The number of the texture coordinates in the array of the second UV map texture coordinates.
- vec2 texcoord - The second UV map texture coordinates to be set.
- int surface - The mesh surface number.
void setVertex (int num, vec3 vertex, int surface, int target = 0)
Sets the coordinates of the vertex of the given morph target.Arguments
- int num - The vertex number in the vertex buffer.
- vec3 vertex - Vertex coordinates to be set.
- int surface - The mesh surface number.
- int target - The morph target number.
void setWeightBones (int num, ivec4 bones, int surface)
Sets the vector of bone indices that affect the vertex with the given weight.Arguments
- int num - The weight number in the array of vertex weights.
- ivec4 bones - Vector of the bone indices to be set.
- int surface - The mesh surface number.
void setWeightCount (int num, int count, int surface)
Sets the number of weights that affect the vertex with the given weight.Arguments
- int num - The weight number in the array of vertex weights.
- int count - Number of weights to be set.
- int surface - The mesh surface number.
void setWeightWeights (int num, vec4 weights, int surface)
Sets the vector of bone weights that affect the vertex with the given weight.Arguments
- int num - The weight number in the array of vertex weights.
- vec4 weights - Vector of bone weights to be set.
- int surface - The mesh surface number.