This page has been translated automatically.
Programming
Fundamentals
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

ObjectDynamic Class

Inherits:Object

The following sample demonstrates the ObjectDynamic class usage:

Creating a Dynamic Object

An example of creating a dynamic object - square:

Notice
Do not forget to create .mat file with all the materials for the new dynamic object and add a reference to it in the .world file.

Source code (UnigineScript)
#include <core/unigine.h>

/*
 */
 
// create a new dynamic object 
ObjectDynamic dynamic;

/*
 */
int init() {
	
	// load a library to the world
	engine.materials.addWorldLibrary("dynamic.mat");
	
	// add a free-flying camera and set position to it
	Player player = new PlayerSpectator();
	player.setPosition(Vec3(4.0f,4.0f,4.0f));
	player.setDirection(vec3(-1.0f));
	engine.game.setPlayer(player);
	
	// add new dynamic object and set its coordinates
	dynamic = new ObjectDynamic(1);
	dynamic.setMaterial("dynamic_mesh_base","*");
	
	// set vertex format
	dynamic.setVertexFormat((
		ivec3( 0, OBJECT_DYNAMIC_TYPE_FLOAT, 2),
		ivec3( 8, OBJECT_DYNAMIC_TYPE_HALF, 4),
		ivec3( 16, OBJECT_DYNAMIC_TYPE_HALF, 4),
		ivec3( 24, OBJECT_DYNAMIC_TYPE_HALF, 4),
	));
	
	// set vertex adding parameters
	void add_vertex(vec3 vertex,vec4 texcoord,vec3 normal,vec4 tangent) {
		dynamic.addVertexFloat(0,vertex,2);
		dynamic.setVertexHalf(1,texcoord,4);
		dynamic.setVertexHalf(2,vec4(normal,vertex.z),4);
		dynamic.setVertexHalf(3,tangent,4);
	}
	
	// add four vertices of a square 
	add_vertex(vec3(-1.0f,-1.0f,0.0f),vec4(0.0f,0.0f,0.0f,0.0f),vec3(0.0f,0.0f,1.0f),vec4(1.0f,0.0f,0.0f,1.0f));
	add_vertex(vec3( 1.0f,-1.0f,0.0f),vec4(1.0f,0.0f,0.0f,0.0f),vec3(0.0f,0.0f,1.0f),vec4(1.0f,0.0f,0.0f,1.0f));
	add_vertex(vec3( 1.0f, 1.0f,0.0f),vec4(1.0f,1.0f,0.0f,0.0f),vec3(0.0f,0.0f,1.0f),vec4(1.0f,0.0f,0.0f,1.0f));
	add_vertex(vec3(-1.0f, 1.0f,0.0f),vec4(0.0f,1.0f,0.0f,0.0f),vec3(0.0f,0.0f,1.0f),vec4(1.0f,0.0f,0.0f,1.0f));
	
	// add the indices for the vertices
	dynamic.addIndex(0);
	dynamic.addIndex(1);
	dynamic.addIndex(2);
	
	dynamic.addIndex(2);
	dynamic.addIndex(3);
	dynamic.addIndex(0);
	
	// set a bounding box for the object
	BoundBox bb = new BoundBox(vec3(-1.0f),vec3(1.0f));
	dynamic.setBoundBox(bb);
	
	return 1;
}

/*
 */
int update() {
	
	// add a rotation to the object (if needed)
	dynamic.setWorldTransform(rotateZ(engine.game.getTime() * 32.0f));
	
	return 1;
}

The obtained result in the Editor:

ObjectDynamic Class

Members


static ObjectDynamic(int flags = 0)

Constructor. Creates a new dynamic object. By default, no flags are used.

Arguments

ObjectDynamic cast(Node node)

Casts an ObjectDynamic out of the Node instance.

Arguments

  • Node node - Node instance.

Return value

ObjectDynamic instance.

ObjectDynamic cast(Object base)

Casts an ObjectDynamic out of the Object instance.

Arguments

  • Object base - Object instance.

Return value

ObjectDynamic instance.

Attribute * getAttributes()

Returns an array of vertex attributes.

Return value

Array of vertex attributes.

void setBoundBox(BoundBox bb)

Sets a bounding box of a specified size for a given dynamic object surface.

Arguments

  • BoundBox bb - Bounding box.

void setBoundBox(BoundBox bb, int surface)

Sets a bounding box of a specified size for a given dynamic object surface.

Arguments

  • BoundBox bb - Bounding box.
  • int surface - Surface number in range from 0 to the total number of dynamic mesh surfaces.

void setIndex(int num, int index)

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

Return value

Vertex index in the index buffer.

void setInstancing(int instancing)

Activates the hardware instancing technique.

Arguments

  • int instancing - Instancing flag. 1 to enable hardware instancing, 0 to disable it.

int getInstancing()

Returns a value indicating if the hardware instancing flag is enabled.

Return value

1 if the hardware instancing flag is enabled; otherwise, 0.

int getNumAttributes()

Returns the number of vertex attributes.

Return value

Number of vertex attributes.

void setNumIndices(int indices)

Sets the number of vertex indices.

Arguments

  • int indices - Number of indices.

int getNumIndices()

Returns the number of vertex indices used by the object.

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 composing the object.

Return value

Number of vertices.

void setParameterBool(string name, int value)

Sets boolean shader parameter of the specified value.

Arguments

  • string name - Name of the parameter.
  • int value - Parameter value.

void setParameterFloat(string name, float[] value)

Sets float shader parameter of the specified value.

Arguments

  • string name - Name of the parameter.
  • float[] value - Parameter value pointer.

void setParameterInt(string name, int[] value)

Sets integer shader parameter of the specified value.

Arguments

  • string name - Name of the parameter.
  • int[] value - Parameter value.

void setSurfaceBegin(int begin, int surface)

Sets the begin index for the specified object surface.

Arguments

  • int begin - The index to be set as the begin one for the surface.
  • int surface - Number of the target surface.

int getSurfaceBegin(int surface)

Returns the begin index of the specified object surface.

Arguments

  • int surface - The number of the target surface in range from 0 to the total number of surfaces.

Return value

The begin index.

void setSurfaceEnd(int end, int surface)

Sets the end index for the specified object surface.

Arguments

  • int end - The index to be set as the end one for the surface.
  • int surface - Number of the target surface.

int getSurfaceEnd(int surface)

Returns the end index of the specified object surface.

Arguments

  • int surface - TThe number of the target surface in range from 0 to the total number of surfaces.

Return value

The end index.

void setSurfaceMode(int mode, int surface)

Sets primitives to render an object surface with: triangles (by default), lines or points.

Arguments

int getSurfaceMode(int surface)

Returns primitives used to render the object surface with: triangles (by default), lines or points.

Arguments

  • int surface - Surface number.

Return value

Surface rendering mode:
  • OBJECT_DYNAMIC_MODE_POINTS = 0
  • OBJECT_DYNAMIC_MODE_LINES
  • OBJECT_DYNAMIC_MODE_TRIANGLES

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 setVertexDouble(int attribute, double[] value)

Updates the last added vertex to the vertex of the double type with the given parameters.

Arguments

  • int attribute - Attribute number.
  • double[] value - Value pointer.

void setVertexDouble(int vertex, int attribute, double[] value)

Updates the given vertex to the vertex of the double type with the given parameters.

Arguments

  • int vertex - Vertex index.
  • int attribute - Attribute number.
  • double[] value - Value pointer.

void setVertexFloat(int attribute, float[] value)

Updates the last added vertex to the vertex of the float type with the given parameters.

Arguments

  • int attribute - The number of the attribute, set in the setVertexFormat() method.
  • float[] value - Vertex coordinates.

void setVertexFloat(int vertex, int attribute, float[] value)

Updates the given vertex to the vertex of the float type with the given parameters

Arguments

  • int vertex - Vertex index.
  • int attribute - The number of the attribute, set in the setVertexFormat() method.
  • float[] value - Vertex coordinates.

void setVertexFormat(Attribute[] attributes)

Sets the number of the vertex attributes.
Notice
This method does not create vertices, but their attributes. Vertices should be created with addVertexFloat(), addVertexHalf() or addVertexUChar() methods accordingly to the type specified in this method.

The example of setting 3 different vertices attributes:

Source code (UnigineScript)
// vertex format
dynamic.setVertexFormat((
	ivec3( 0, OBJECT_DYNAMIC_TYPE_FLOAT, 1),
	ivec3( 12, OBJECT_DYNAMIC_TYPE_HALF, 2),
	ivec3( 24, OBJECT_DYNAMIC_TYPE_UCHAR, 4),
));

Arguments

  • Attribute[] attributes - Number of the vertex attributes, can be up to 16 attributes for one vertex. The numeration starts from 0. Each attribute consists of:
    • An offset of the vertex in bytes, depends on the vertex type and size.
    • Type of the vertex: OBJECT_DYNAMIC_TYPE_FLOAT, OBJECT_DYNAMIC_TYPE_HALF, OBJECT_DYNAMIC_TYPE_UCHAR
    • Size of the vertex: can be 1,2,3,4 for float type; 2,4 for half type; 4 for UChar type
      Notice
      When it goes to shader, 0 -attribute always comes with the size of 4, no matter what size is specified in the method. All the other attributes comes with the specified sizes.

void setVertexHalf(int attribute, float[] value)

Updates the last added vertex to the vertex of the half-float type with the given parameters.

Arguments

  • int attribute - The number of the attribute, set in the setVertexFormat() method.
  • float[] value - Vertex coordinates.

void setVertexHalf(int vertex, int attribute, float[] value)

Updates the last added vertex to the vertex of the half-float type with the given parameters.

Arguments

  • int vertex - Vertex index.
  • int attribute - The number of the attribute, set in the setVertexFormat() method.
  • float[] value - Vertex coordinates.

int getVertexSize()

Returns the size of the current vertex, bytes.

Return value

Vertex size.

void setVertexUShort(int attribute, int value, int size)

Updates the last added vertex to the vertex of the unsigned short type with the given parameters.

Arguments

  • int attribute - Attribute number.
  • int value - Value pointer.
  • int size - Size of the vertex: can be 4 bytes for this type.

void setVertexUShort(int vertex, int attribute, ushort[] value)

Updates the given vertex to the vertex of the unsigned short type with the given parameters.

Arguments

  • int vertex - Vertex index.
  • int attribute - The number of the attribute, set in the setVertexFormat() method.
  • ushort[] value - Vertex coordinates.

void addIndex(int index)

Adds an index to the index buffer.

Arguments

  • int index - Index to add.

void addLineStrip(int num_vertex)

Adds a line strip to the object.
Notice
This method does not add the new vertices, but allocates their indices. Vertices should be created with addVertexFloat(), addVertexHalf() or addVertexUChar() methods accordingly to the required vertex type.

Arguments

  • int num_vertex - Number of vertices composing the strip.

void addPoints(int num_points)

Adds the points to the object.
Notice
This method does not add the new vertices, but allocates their indices. Vertices should be created with addVertexFloat(), addVertexHalf() or addVertexUChar() methods accordingly to the required vertex type.

Arguments

  • int num_points - Number of points.

void addSurface(string name)

Adds all the last listed and unsigned vertices and triangles to a new object surface with a specified name.

Arguments

  • string name - Name of the new surface.

void addTriangleFan(int num_vertex)

Adds a triangle fan to the object.
Notice
This method does not add the new vertices, but allocates their indices. Vertices should be created with addVertexFloat(), addVertexHalf() or addVertexUChar() methods accordingly to the required vertex type.

Arguments

  • int num_vertex - Number of vertices composing 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.

void addTriangles(int num_triangles)

Adds a given number of triangles to the object.
Notice
This method does not add the new vertices, but allocates their indices. Vertices should be created with addVertexFloat(), addVertexHalf() or addVertexUChar() methods accordingly to the required vertex type.

Arguments

  • int num_triangles - Number of triangles.

void addTriangleStrip(int num_vertex)

Adds a triangle strip to the object.
Notice
This method does not add the new vertices, but allocates their indices. Vertices should be created with addVertexFloat(), addVertexHalf() or addVertexUChar() methods accordingly to the required vertex type.

Arguments

  • int num_vertex - Number of vertices composing the strip.

void addVertexDouble(int attribute, double[] value)

Adds a vertex of a double type with the given attribute, coordinates and size to the object.

Arguments

  • int attribute - Attribute number.
  • double[] value - Value pointer.

void addVertexFloat(int attribute, float[] value)

Adds a vertex of a float type with the given attribute, coordinates and size to the object.
Notice
Before adding a vertex, make sure that you set all the attributes for it with the setVertexFormat() method.

Arguments

  • int attribute - The number of the attribute, set in the setVertexFormat() method.
  • float[] value - Vertex coordinates.

void addVertexHalf(int attribute, float[] value)

Adds a vertex of the half-float type with the given attribute, coordinates and size to the object.
Notice
Before adding a vertex, make sure that you set all the attributes for it with the setVertexFormat() method.

Arguments

  • int attribute - The number of the attribute, set in the setVertexFormat() method.
  • float[] value - Vertex coordinates.

void allocateIndices(int num)

Allocate an index buffer for a given number of indices that will be used for an object. 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 an object. 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 object.

void clearSurfaces()

Clears all the surface settings.

void clearVertex()

Clears all the current vertex settings.

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.

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.

int type()

Returns the type of the object.

Return value

Object Dynamic type identifier.

void updateSurfaceBegin(int surface)

Synchronizes surface begin index.

Arguments

  • int surface - The number of the target surface in range from 0 to the total number of surfaces.

void updateSurfaceEnd(int surface)

Synchronizes surface end index.

Arguments

  • int surface - The number of the target surface in range from 0 to the total number of surfaces.

int OBJECT_DYNAMIC_ALL

Description

A flag indicating both dynamic indices and vertices.

int OBJECT_DYNAMIC_INDICES

Description

A flag indicating dynamic indices.

int OBJECT_DYNAMIC_VERTEX

Description

A flag indicating dynamic vertices.

int OBJECT_IMMUTABLE_ALL

Description

A flag indicating both immutable indices and vertices.

int OBJECT_IMMUTABLE_INDICES

Description

A flag indicating immutable indices.

int OBJECT_IMMUTABLE_VERTEX

Description

A flag indicating immutable vertices.

int OBJECT_DYNAMIC_MODE_LINES

Description

Mode to render the lines.

int OBJECT_DYNAMIC_MODE_POINTS

Description

Mode to render the points.

int OBJECT_DYNAMIC_MODE_QUAD_PATCHES

Description

Mode to render the quad pathes.

int OBJECT_DYNAMIC_MODE_TRIANGLES

Description

Mode to render the triangles.

int OBJECT_DYNAMIC_MODE_TRIANGLE_PATCHES

Description

Mode to render the triangle pathes.

int OBJECT_DYNAMIC_TYPE_DOUBLE

Description

Double type to store vertices.

int OBJECT_DYNAMIC_TYPE_FLOAT

Description

Float type to store vertices.

int OBJECT_DYNAMIC_TYPE_HALF

Description

Half-float type to store vertices.

int OBJECT_DYNAMIC_TYPE_UCHAR

Description

Unsigned char type to store vertices.

int OBJECT_DYNAMIC_TYPE_USHORT

Description

Unsigned short type to store vertices.
Last update: 2017-07-03
Build: ()