Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Setting vertex colours

Setting vertex colours

duncan_rowland
Explorer Explorer
318 Views
2 Replies
Message 1 of 3

Setting vertex colours

duncan_rowland
Explorer
Explorer

Hello,
   just trying to understand how to set vertex colours. When I run the code below (Box001 is an editable mesh), I still need to add and then remove a vertex paint modifier to get the colours copied to the base object. Is there a better way to directly access the base object's vertices?

   Many thanks in advance, -Duncan.

INode* node = GetCOREInterface()->GetINodeByName(_T("Box001"));
const ObjectState* os = &node->EvalWorldState(MAXScript_time());
Object* obj = os->obj;
TriObject* as_tri = dynamic_cast<TriObject*>(obj);
Mesh* mesh = &as_tri->GetMesh();


for (int i = 0; i < mesh->getNumVertCol(); i++) {
   mesh->vertCol[i].x = 1.f;
   mesh->vertCol[i].y = 0.f;
   mesh->vertCol[i].z = 0.f;
}

 

0 Likes
319 Views
2 Replies
Replies (2)
Message 2 of 3

2829024262
Contributor
Contributor

Can you check the C++ SDK to see if the "bool SetVertColor (UVVert clr, int mapChannel, DWORD flag=MN_SEL)" function is the one you need? It is under the MNMesh class.

0 Likes
Message 3 of 3

denisT.MaxDoctor
Advisor
Advisor

You are correctly assigning vertex colors. However, if the Vertex Paint modifier is present in the stack, it will overwrite your mesh colors. Make sure to update the mesh to invalidate the mesh data.

0 Likes