Change color of selected vertices of a model

Hello,

Is there a way to only change the color of one or multiple selected vertex from a loaded model?
This requires two steps:
1. Get the position of vertices of a model in 3D space
2. If the position of certain vertices pass

The reason I need this is that I am trying to mark the nearest one or several vertices of a model to a given position by changing the color of those vertices.
The model I’m using is the “panda” one that comes with the engine.

My current progress is that I can access each vertex through the following procedure (From manual [link]):
geomNode → geom ->VertexData.
By calling getData3() I can get the position.

But what’s next? Or am I on a completely wrong path?

First of all, greetings, and welcome to the forum! I hope that you find your time here to be good! :slight_smile:

I would imagine that the thing to do might be to use a GeomVertexWriter to modify the colour associated with the vertex.

Given that you’re working with an extant model, you may have to modify the internal structure of it in order to include vertex colours, if they’re not already present.

I’d suggest that you start by looking at the page on “Reading existing geometry data” (as it gives an introduction to the process):
https://docs.panda3d.org/1.10/python/programming/internal-structures/other-manipulation/reading-existing-geometry

Then go on to looking at the page on “Modifying existing geometry data”:
https://docs.panda3d.org/1.10/python/programming/internal-structures/other-manipulation/modifying-existing-geometry

Do note that the latter page includes mention of modifying the internal structure of the model to add data (in this case vertex-colours), and links to the relevant pages, I believe.

1 Like