Color the mesh form mesh vectors in C++ commond


(Yyo942512) #1

Hi~
I am trying to color the mesh, and RGB represents the three vectors of the mesh.
I am trying to understand the sample program in github.
I think I need to use cmdSampleMeshFaceColor, SampleCustomMeshObjects and cmdSampleGetPointOnMesh.cpp.
But after I use cmdSampleMeshFaceColor, I find that the coloring can’t be saved,
cancel gs.GetString(); the color will disappear immediately.
Can I have a better solution to this problem or any example for it?
I will be grateful for any help you can provide !
Thanks!


(Dale Fugier) #2

Hi @yyo942512,

Meshes do not have face colors. However, you can draw meshes with face color using a conduit. This is what the example demonstrates.

That said meshes can have vertex colors. To create a mesh with vertex colors, just fill in the ON_Mesh::m_C array with RGB colors that correspond to vertices.

– Dale


(Yyo942512) #3

@dale Thanks for your reply.
When I use the example cmdSampleMeshFaceColor , the coloring can’t be saved.
And cancel gs.GetString(); the color will disappear immediately.
What can I do to always keep the color ?
Thanks!


(Dale Fugier) #4

Hi @yyo942512,

In the sample you reference, the conduit is created on the stack. Thus when the command end, the conduit is destroyed. If you want the conduit to persist, then add it as a member variable to the command, or allocate it on the heap.

– Dale


(Yyo942512) #5

Thank you very much @dale
It is help for me.:smile:
I will continue to try vertex colors .