This page has been translated automatically.
Getting Started
Migrating to UNIGINE 2.0
C++ API Migration
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

ObjectMeshDynamic Class

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

ObjectMeshDynamic Class

This class inherits from Object

Members


ObjectMeshDynamic (variable v = 0, int flags = 0)

Constructor. Creates a new dynamic mesh object.

Arguments

  • variable v - Argument of one of the following types:
    • Mesh mesh - Instance of the Mesh class. If this argument is passed to the constructor, a dynamic mesh will be created from a given mesh.
    • string name - Name of the mesh file. If this argument is passed to the constructor, a dynamic mesh will be created from a given mesh file.
    • int - Dynamic flag: one of the OBJECT_DYNAMIC_* or OBJECT_IMMUTABLE_* flags.
  • int flags - Dynamic flag: one of the OBJECT_DYNAMIC_* or OBJECT_IMMUTABLE_* flags.
    Notice
    If the dynamic flag is passed as the first argument, you shouldn't pass the second argument.

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 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 addTriangles (int 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 triangles - Number of triangles.

void addVertex (vec3 coordinates)

Adds a vertex with given coordinates to the mesh.

Arguments

  • vec3 coordinates - Vertex coordinates in the mesh system of coordinates.

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.

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.

int getIndex (int index)

Returns the index of the vertex by the index number.

Arguments

  • int index - Index number in the index buffer.

Return value

Vertex index in the index buffer.

string getMeshName ()

Returns a name of the mesh.

Return value

Mesh name.

int getMesh (Mesh mesh)

Copies the current dynamic mesh into the received mesh.

Arguments

  • Mesh mesh - Mesh.

Return value

1 if the mesh is copied successfully; otherwise, 0.

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.

int getNumIndices ()

Returns the number of vertex indices used by the mesh.

Return value

Number of indices.

int getNumVertex ()

Returns the number of vertices comprising the mesh.

Return value

Number of vertices.

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.

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.

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.

vec4 getTexCoord (int vertex)

Returns texture coordinates of a given vertex.

Arguments

  • int vertex - Number of the vertex in the vertex buffer.

Return value

Coordinate pairs for both texture channels.

vec3 getVertex (int vertex)

Returns coordinates of a given vertex.

Arguments

  • int vertex - Number of the vertex in the vertex buffer.

Return value

Coordinates in the mesh system of coordinates.

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 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.

Examples

To remove all vertices of the dynamic mesh except the last 4 vertices, use this function as follows::

Source code (UnigineScript)
while(dynamic_mesh.getNumVertex() >= 4) {
	dynamic_mesh.removeVertex(0, 1, 1);
}
						

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.

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 setBoundBox (BoundBox bb)

Sets a bounding box of the specified size for the dynamic object mesh.

Arguments

  • BoundBox bb - Bounding box.

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.

void setIndex (int index, int vertex)

Updates a given index in the index buffer (replaces the index with the given number with the specified index of the vertex).

Arguments

  • int index - Index number in the index buffer.
  • int vertex - Vertex index in the index buffer to set.

void setMeshName (string name)

Sets a name for a mesh.

Arguments

  • string name - Mesh name.

int setMesh (Mesh mesh)

Allows for reinitialization of the ObjectMeshDynamic: it copies a given mesh into the current dynamic mesh.

Arguments

  • Mesh mesh - Mesh.

Return value

1 if the mesh is copied successfully; otherwise, 0.

void setNumIndices (int num)

Sets the number of vertex indices.

Arguments

  • int num - Number of indices.

void setNumVertex (int num)

Sets the number of mesh vertices.

Arguments

  • int num - Number of mesh 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.

void setSurfaceEnd (int begin, 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 begin - End index.
  • int surface - Number of the target surface.

void setSurfaceName (string name, int surface)

Sets the name for the specified surface.
Notice
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.

void setTexCoord (int vertex, vec4 texcoord)

Updates texture coordinates of a given vertex.

Arguments

  • int vertex - Number of the vertex in the vertex buffer.
  • vec4 texcoord - New coordinate pairs for both texture channels.

void setVertex (int vertex, vec3 coordinates)

Updates coordinates of a given vertex.

Arguments

  • int vertex - Number of the vertex in the vertex buffer.
  • vec3 coordinates - New coordinates in the mesh system of coordinates.

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_MODE_LINES

Description

Mode to render lines.

int OBJECT_MESH_DYNAMIC_MODE_POINTS

Description

Mode to render points.

int OBJECT_MESH_DYNAMIC_MODE_TRIANGLES

Description

Mode to render triangles (to create meshes).
Last update: 03.07.2017
Build: ()