yigitakkok Posted August 18, 2015 Share Posted August 18, 2015 Hi. 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.setVertex(i++,vec3(x/5.0f,y/5.0f,z)); mesh.setColor (i,vec4(1.0f,1.0f,1.0f,0.0f)); and adding: mesh.addVertex(vec3(x/5.0f,y/5.0f,1)); mesh.addColor(vec4(1.0f,1.0f,1.0f,0.0f)); For both of them error says: "unknown objectmeshdynamic class member". Thanks. Link to comment
silent Posted August 19, 2015 Share Posted August 19, 2015 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: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
yigitakkok Posted August 26, 2015 Author Share Posted August 26, 2015 So, How I will set color for a mesh? This is how I create a mesh: mesh2 = (new ObjectMeshDynamic(2)); mesh2.setWorldTransform(translate(Vec3(-500.0f,-500.0f,0.0f))); mesh2.setMaterial("mesh_base","*"); Link to comment
silent Posted August 26, 2015 Share Posted August 26, 2015 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. Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
victor.dong Posted November 30, 2018 Share Posted November 30, 2018 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", "*"); m_mesh->getMaterialInherit(0); 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 comment
Recommended Posts