Unigine::DecalMesh Class
Header: | #include <UnigineDecals.h> |
Inherits: | Decal |
This class describes how to create and modify mesh decals.
See Also#
A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/decals/ folder:
- mesh_00
- mesh_01
- mesh_02
Creating a Mesh Decal#
The following code illustrates how to create a mesh decal, set its parameters and add the node to UnigineEditor.
// AppWorldLogic.h
#include <UnigineLogic.h>
#include <UnigineObjects.h>
#include <UnigineEditor.h>
#include <UnigineDecals.h>
class AppWorldLogic : public Unigine::WorldLogic {
public:
AppWorldLogic();
virtual ~AppWorldLogic();
virtual int init();
virtual int update();
virtual int render();
virtual int flush();
virtual int shutdown();
virtual int destroy();
virtual int save(const Unigine::StreamPtr &stream);
virtual int restore(const Unigine::StreamPtr &stream);
private:
Unigine::DecalMeshPtr decal_mesh;
};
// AppWorldLogic.cpp
#include "AppWorldLogic.h";
using namespace Unigine;
int AppWorldLogic::init()
{
// create a mesh with a surface (e.g. a box primitive)
MeshPtr mesh = Mesh::create();
mesh->addBoxSurface("box_0", Math::vec3(1.0f));
// create a mesh decal using created mesh and setting its radius to 10, material to "decal_base"
decal_mesh = DecalMesh::create(mesh, 10.0f, "decal_base");
// set the name and position of the decal
decal_mesh->setName("Mesh Decal");
decal_mesh->setWorldPosition(Math::Vec3(0.0f, 0.0f, 5.0f));
// release ownership of its pointer and add the node to UnigineEditor
decal_mesh->release();
Editor::get()->addNode(decal_mesh->getNode());
return 1;
}
int AppWorldLogic::shutdown() {
// clear pointer
decal_mesh.clear();
return 1;
}
DecalMesh Class
Members
static DecalMeshPtr create ( const Ptr<Mesh> & mesh, float radius, const char * name )
Constructor. Creates a new mesh decal with the given properties.Arguments
- const Ptr<Mesh> & mesh - Pointer to Mesh.
- float radius - The height of the decal projection box along the Z axis, in units.
- const char * name - Material name.
static DecalMeshPtr create ( const char * mesh_name, float radius, const char * name )
Constructor. Creates a new mesh decal with the given properties.Arguments
- const char * mesh_name - Mesh name.The mesh should contain a single surface. In case if the mesh contains several surfaces, only the one with the 0 index will be used. Thus, the area of the decal will differ from the initial mesh.
- float radius - The height of the decal projection box along the Z axis, in units.
- const char * name - Material name
Ptr<DecalMesh> cast( const Ptr<Node> & node )
Casts a mesh decal out of the Node instance.Arguments
- const Ptr<Node> & node - Node smart pointer.
Return value
Pointer to the DecalMesh.Ptr<DecalMesh> cast( const Ptr<Decal> & base )
Casts a DecalMesh out of the Decal instance.Arguments
- const Ptr<Decal> & base - Decal smart pointer.
Return value
Pointer to the DecalMesh.int setMesh( const Ptr<Mesh> & mesh, int unique = 1 )
Copies a given source mesh into the current decal mesh.// create an empty decal mesh
DecalMeshPtr decalMesh = DecalMesh::create(NULL,8.0f,"decal_base_0");
// create a mesh
MeshPtr mesh = Mesh::create("decal.mesh");
// copy the mesh into the decal mesh
decalMesh->setMesh(mesh);
Arguments
- const Ptr<Mesh> & mesh - Mesh to be set.The mesh should contain a single surface. In case if the mesh contains several surfaces, only the one with the 0 index will be used. Thus, the area of the decal will differ from the initial mesh.
- int unique - Unique flag used when you create several objects out of a single Mesh instance:
- 0 - An instance of source mesh geometry is created. If the source geometry is changed at runtime, its instances will be changed as well.
- 1 - A copy of source mesh geometry is created and changes made to the source geometry do not affect the mesh.
Return value
1 if the mesh is copied successfully; otherwise, 0.int getMesh( const Ptr<Mesh> & mesh )
Copies the current decal mesh into the received mesh. For example, you can obtain geometry of the decal mesh and then change it:// a decal mesh from which geometry will be obtained
DecalMeshPtr decalMesh = DecalMesh::create("decal.mesh",8.0f,"decal_base_0");
// create a new mesh
MeshPtr mesh = Mesh::create();
// copy geometry to the created mesh
if (decalMesh->getMesh(mesh)) {
// do something with the obtained mesh
}
else {
Log::error("Failed to copy a mesh\n");
}
Arguments
- const Ptr<Mesh> & mesh - Current mesh.
Return value
1 if the mesh is copied successfully; otherwise, 0.void setMeshName( const char * name, int force_load = 0 )
Sets a new name for the mesh and forces loading of the mesh with the new name for the current decal mesh.The mesh should contain a single surface. In case if the mesh contains several surfaces, only the one with the 0 index will be used. Thus, the area of the decal will differ from the initial mesh.
Arguments
- const char * name - A new name to be set for the mesh.
- int force_load - Force flag.
- If 1 is specified, the mesh with the new name will be loaded immediately with the unique flag set to 0.
- If 0 is specified, only the mesh name will be updated.
const char * getMeshName( )
Returns the name of the mesh used as a base for the decal.Return value
The mesh name.void setRadius( float radius )
Sets the new height of the decal projection box along the Z axis.Arguments
- float radius - The height of the decal projection box along the Z axis, in units.
float getRadius( )
Returns the current height of the decal projection box along the Z axis.Return value
The height of the decal projection box along the Z axis, in units.void loadMesh( const char * name, int unique = 0 )
Loads a mesh for the current mesh from the file. This function doesn't change the mesh name.Arguments
- const char * name - The name of the mesh file.The mesh should contain a single surface. In case if the mesh contains several surfaces, only the one with the 0 index will be used. Thus, the area of the decal will differ from the initial mesh.
- int unique - Unique flag used when you create several objects out of a single .mesh file:
- 0 - An instance of source mesh geometry is created. If the source geometry is changed at runtime, its instances will be changed as well.
- 1 - A copy of source mesh geometry is created and changes made to the source geometry do not affect the mesh.
int saveMesh( const char * name )
Saves the decal mesh into a file.Arguments
- const char * name - A name of the mesh file.
Return value
1 if the mesh is saved successfully; otherwise, 0.int type( )
Returns a DecalMesh type identifier.Return value
Type identifier.Last update:
2020-01-14
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)