ObjectMeshDynamic Class
Inherits: | Object |
This class is used to procedurally create dynamic meshes (i.e. triangles), lines or points and modify them in run-time. You can also load an existing mesh as a dynamic one in order to modify it.
The following samples demonstrate the ObjectMeshDynamic class usage:
See Also
- Article on ObjectMeshDynamic class usage examples
ObjectMeshDynamic Class
Members
static ObjectMeshDynamic(Mesh mesh, int flags = 0)
ObjectMeshDynamic constructor.Arguments
- Mesh mesh - Mesh instance.
- int flags - Dynamic flag: one of the OBJECT_MESH_DYNAMIC_DYNAMIC_* or OBJECT_MESH_DYNAMIC_IMMUTABLE_*.
ObjectMeshDynamic cast(Object base)
Casts an ObjectMeshDynamic out of the Object instance.Arguments
- Object base - Object instance.
Return value
ObjectMeshDynamic instance.ObjectMeshDynamic cast(Node node)
Casts an ObjectMeshDynamic out of the Node instance.Arguments
- Node node - Node instance.
Return value
ObjectMeshDynamic instance.void setBoundBox(BoundBox bb)
Sets a bounding box of a specified size for a given dynamic mesh surface.Arguments
- BoundBox bb - Bounding box.
void setBoundBox(BoundBox bb, int surface)
Sets a bounding box of a specified size for a given dynamic mesh surface.Arguments
- BoundBox bb - Bounding box.
- int surface - Surface number in range from 0 to the total number of dynamic mesh surfaces.
void setColor(int num, vec4 color)
Updates the color of a given vertex.Arguments
- int num - Vertex number in range from 0 to the total number of mesh vertices.
- vec4 color - Color.
vec4 getColor(int num)
Returns the color of a given vertex.Arguments
- int num - Vertex number in range from 0 to the total number of mesh vertices.
Return value
Vertex color.void setIndex(int num, int index)
Updates a given index in the index buffer (replaces the index with the given number with the specified index of the vertex).Arguments
- int num - Index number in the index buffer.
- int index - Vertex index in the index buffer to set.
int getIndex(int num)
Returns the index of the vertex by the index number.Arguments
- int num - Index number in the index buffer.
Return value
Vertex index in the index buffer.int setMesh(Mesh mesh)
Allows for reinitialization of the ObjectMeshDynamic: it copies a given mesh into the current dynamic mesh. For example, you can copy a mesh into another one as follows:// create ObjectMeshDynamic instances
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic();
ObjectMeshDynamic dynamicMesh_2 = new ObjectMeshDynamic();
// create a Mesh instance
Mesh firstMesh = new Mesh();
// get the mesh of the ObjectMeshDynamic and copy it to the Mesh class instance
dynamicMesh.getMesh(firstMesh);
// put the firstMesh mesh to the dynamicMesh_2 instance
dynamicMesh_2.setMesh(firstMesh);
Arguments
- Mesh mesh - Mesh.
Return value
1 if the mesh is copied successfully; otherwise, 0.int getMesh(Mesh mesh)
Copies the current dynamic mesh into the received mesh. For example, you can obtain geometry of the dynamic mesh and then change it:// a dynamic mesh from which geometry will be obtained
Mesh mesh_0 = new Mesh("box.mesh");
ObjectMeshDynamic dynamicMesh = new ObjectMeshDynamic(mesh_0);
// create a new mesh
Mesh mesh_1 = new Mesh();
// copy geometry to the Mesh instance
if(dynamicMesh.getMesh(mesh_1)) {
// do something with the obtained mesh
} else {
log.error("Failed to copy a mesh\n");
}
Arguments
- Mesh mesh - Mesh.
Return value
1 if the mesh is copied successfully; otherwise, 0.void setMeshName(string name)
Sets a name for a mesh.Arguments
- string name - Mesh name.
string getMeshName()
Returns a name of the mesh.Return value
Mesh name.vec3 getNormal(int num)
Returns a normal vector of a given vertex.Arguments
- int num - Number of the vertex in the vertex buffer.
Return value
The vertex normal vector.void setNumIndices(int num)
Sets the number of vertex indices.Arguments
- int num - Number of indices.
int getNumIndices()
Returns the number of vertex indices used by the mesh.Return value
Number of indices.void setNumVertex(int num)
Sets the number of mesh vertices.Arguments
- int num - Number of mesh vertices.
int getNumVertex()
Returns the number of vertices comprising the mesh.Return value
Number of vertices.void setSurfaceBegin(int begin, int surface)
Sets the begin index to the specified surface of the dynamic object mesh. It means that the surface will be rendered the first.Arguments
- int begin - Begin index.
- int surface - Number of the target surface.
int getSurfaceBegin(int surface)
Returns the begin index of the specified mesh surface.Arguments
- int surface - Surface number.
Return value
Begin index of the surface.void setSurfaceEnd(int end, int surface)
Sets the end index to the specified surface of the dynamic object mesh. It means that the surface will be rendered the last.Arguments
- int end - End index.
- int surface - Number of the target surface.
int getSurfaceEnd(int surface)
Returns the end index of the specified mesh surface.Arguments
- int surface - Surface number.
Return value
Returns the end index of the surface.void setSurfaceName(string name, int surface)
Sets the name for the specified surface.The name will be set only if the specified surface was added via the addSurface() method.
Arguments
- string name - New name of the surface.
- int surface - Number of a target surface in range from 0 to the total number of surfaces.
void setTangent(int num, quat tangent)
Sets the new tangent vector for the given vertex.Arguments
- int num - Number of the vertex in the vertex buffer.
- quat tangent - Tangent vector to be set.
quat getTangent(int num)
Returns the tangent vector of the given vertex.Arguments
- int num - Number of the vertex in the vertex buffer.
Return value
Tangent vector.void setTexCoord(int num, vec4 texcoord)
Updates texture coordinates of a given vertex.Arguments
- int num - Number of the vertex in the vertex buffer.
- vec4 texcoord - New coordinate pairs for both texture channels.
vec4 getTexCoord(int num)
Returns texture coordinates of a given vertex.Arguments
- int num - Number of the vertex in the vertex buffer.
Return value
Coordinate pairs for both texture channels.void setVertex(int num, vec3 xyz)
Updates coordinates of a given vertex.Arguments
- int num - Number of the vertex in the vertex buffer.
- vec3 xyz - New coordinates in the mesh system of coordinates.
vec3 getVertex(int num)
Returns coordinates of a given vertex.Arguments
- int num - Number of the vertex in the vertex buffer.
Return value
Coordinates in the mesh system of coordinates.void setVertexArray(Vertex[] vertex)
Updates the vertex array of the dynamic mesh.Arguments
- Vertex[] vertex
Vertex * getVertexArray()
Returns an array of vertices of the dynamic mesh.Return value
Pointer to the array of vertices.void addColor(vec4 color)
Adds a color to the last added vertex.Arguments
- vec4 color - Color.
void addIndex(int index)
Adds an index to the index buffer.Arguments
- int index - Index to add.
void addSurface(string name)
Adds all of the last listed and unsigned vertices and triangles to a new mesh surface with a specified name.Arguments
- string name - Name of the new surface.
void addTangent(quat tangent)
Appends the given tangent to the last added vertex.Arguments
- quat tangent - Tangent to add.
void addTexCoord(vec4 texcoord)
Adds texture coordinates to the last added vertex.Arguments
- vec4 texcoord - Coordinate pairs for both texture channels.
void addTriangleFan(int num_vertex)
Adds a triangle fan to the mesh. This method does not add vertices, rather it allocates indices, for which vertices should be then created with addVertex(). Indices will point to vertices starting from the current last vertex in the vertex buffer.Arguments
- int num_vertex - Number of vertices comprising the fan.
void addTriangleQuads(int num_quads)
Adds a given number of quadrilaterals to the mesh. This method does not add vertices, rather it allocates indices, for which vertices should be then created with the addVertex() function. Indices will point to vertices starting from the current last vertex in the vertex buffer.Arguments
- int num_quads - Number of quadrilaterals to add.
void addTriangles(int num_triangles)
Adds a given number of triangles to the mesh. This method does not add vertices, rather it allocates indices, for which vertices should be then created with addVertex().Indices will point to vertices starting from the current last vertex in the vertex buffer.Arguments
- int num_triangles - Number of triangles.
void addTriangleStrip(int num_vertex)
Adds a triangle strip to the mesh. This method does not add vertices, rather it allocates indices, for which vertices should be then created with addVertex(). Indices will point to vertices starting from the current last vertex in the vertex buffer.Arguments
- int num_vertex - Number of vertices comprising the strip.
void addVertex(vec3 xyz)
Adds a vertex with given coordinates to the mesh.Arguments
- vec3 xyz - Vertex coordinates in the mesh system of coordinates.
void addVertexArray(Vertex[] vertex)
Adds an array of vertices to the dynamic mesh.Arguments
- Vertex[] vertex
void allocateIndices(int num)
Allocate an index buffer for a given number of indices that will be used for a mesh. With this function, memory can be allocated once rather than in chunks, making the creation faster.Arguments
- int num - The number of indices that will be stored in a buffer.
void allocateVertex(int num)
Allocate a vertex buffer for a given number of vertices that will be used for a mesh. With this function, memory can be allocated once rather than in chunks, making the creation faster.Arguments
- int num - The number of vertices that will be stored in a buffer.
void clearIndices()
Clears all vertex indices used by the mesh.void clearSurfaces()
Clears all the surface settings.void clearVertex()
Clears all vertices comprising the mesh.void flushIndices()
Flushes the index buffer and sends data to the GPU. This function is called automatically, if the length of the index buffer changes. If you change the content of the index buffer, you should call this method.void flushVertex()
Flushes the vertex buffer and sends data to the GPU. This function is called automatically, if the length of the vertex buffer changes. If you change the content of the vertex buffer, you should call this method.int loadMesh(string name)
Loads a mesh for the current mesh from the file. This function doesn't change the mesh name.Arguments
- string name - Mesh file name.
Return value
1 if the mesh is loaded successfully; otherwise, 0.void removeIndices(int num, int size)
Removes the specified number of indices starting from the given index.Arguments
- int num - Number of the index in the index buffer.
- int size - Number of indices to remove.
void removeSurface(int surface)
Removes the surface with the given index.Arguments
- int surface - Surface index.
void removeSurfaces(string name)
Removes surfaces with the given name.Arguments
- string name - Surface name.
void removeVertex(int num, int size, int indices)
Removes the specified number of vertices starting from the given vertex. To fix the index buffer after removal of vertices, pass 1 as the 3rd argument.Arguments
- int num - Number of the vertex in the vertex buffer.
- int size - Number of vertices to remove.
- int indices - 1 to fix the index buffer after removal of vertices; otherwise, 0.
int saveMesh(string name)
Saves the dynamic mesh into .mesh or .anim format.Arguments
- string name - Mesh file name.
Return value
1 if the mesh is saved successfully; otherwise, 0.int type()
Returns the type of the node.Return value
Object type identifier.int updateBounds()
Calculates a bounding box and a bounding sphere for the current mesh.Return value
1 if the bounds are calculated successfully; otherwise, 0.int updateIndices()
Optimizes vertex indices by removing duplicated vertices.Return value
1 if the indices are updated successfully; otherwise, 0.void updateSurfaceBegin(int surface)
Synchronizes surface begin index.Arguments
- int surface - ID of a target surface.
void updateSurfaceEnd(int surface)
Synchronizes surface end index.Arguments
- int surface - ID of a target surface.
int updateTangents()
Updates tangent vectors of the mesh vertices.Return value
1 if the tangents are updated successfully; otherwise, 0.int OBJECT_MESH_DYNAMIC_DYNAMIC_ALL
int OBJECT_MESH_DYNAMIC_DYNAMIC_INDICES
int OBJECT_MESH_DYNAMIC_DYNAMIC_VERTEX
int OBJECT_MESH_DYNAMIC_IMMUTABLE_ALL
int OBJECT_MESH_DYNAMIC_IMMUTABLE_INDICES
int OBJECT_MESH_DYNAMIC_IMMUTABLE_VERTEX
int OBJECT_MESH_DYNAMIC_MODE_LINES
Description
Mode to render lines.int OBJECT_MESH_DYNAMIC_MODE_POINTS
Description
Mode to render points.int OBJECT_MESH_DYNAMIC_MODE_QUAD_PATCHES
int OBJECT_MESH_DYNAMIC_MODE_TRIANGLES
Description
Mode to render triangles (to create meshes).int OBJECT_MESH_DYNAMIC_MODE_TRIANGLE_PATCHES
int OBJECT_MESH_DYNAMIC_TYPE_DOUBLE
int OBJECT_MESH_DYNAMIC_TYPE_FLOAT
int OBJECT_MESH_DYNAMIC_TYPE_HALF
int OBJECT_MESH_DYNAMIC_TYPE_UCHAR
int OBJECT_MESH_DYNAMIC_TYPE_USHORT
Last update: 2018-08-10
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)