Cannot set or add color to object dynamic mesh


Recommended Posts

According to the documentation we can set or add color to the objectdynanmicmesh class.
But when I try to set or add color to them I get an error.


Here is my code for setting:


mesh.setColor (i,vec4(1.0f,1.0f,1.0f,0.0f));
and adding:


For both of them error says: "unknown objectmeshdynamic class member".



Link to post

Hi Yiğit,


setColor() method for MeshDynamic objects is available only since Unigine 2.0. This method designed to set the vertex color of the mesh which can be seen only in ResourceEditor application. There is currently no mecanism to display vertex color in runtime, sorry.



How to submit a good bug report
FTP server for test scenes and user uploads:

Link to post

So, How I will set color for a mesh?


This is how I create a mesh:


mesh2 = (new ObjectMeshDynamic(2));
Link to post

Hi Yiğit,


The main idea here is to assign material, that already have desired color. 


You can prepare such material manually inside the Unigine Editor set of materials and save them into *.mat file or you can inherit material from mesh_base and modify it's diffuse color parameter via the setParameter() method.



How to submit a good bug report
FTP server for test scenes and user uploads:

Link to post
  • 3 years later...

Basically you can do this like below codes :


    ObjectMeshDynamicPtr m_mesh = Primitives::createBox(Math::vec3(1, 1, 5));
    m_mesh->setWorldPosition(Math::Vec3(0, 0, 2.5));
    m_mesh->setMaterial("mesh_base", "*");
    auto mat = m_mesh->getMaterial(0);
    mat->setState("vertex_color", 1);
    mat->setState("vertex_albedo", 1);
    for (int i = 0; i < m_mesh->getNumVertex(); ++i)
        auto v = m_mesh->getWorldTransform() * m_mesh->getVertex(i);
        m_mesh->setColor(i, Math::vec4(v.z/5.0, 1- v.z / 5.0, 0, 1));
Link to post