Finding RGBA values for a particular vertex in a mesh's color bufer

Let’s say we have a fairly simple mesh with 100 vertices in it. That means that its color buffer will have 100 entries in it, where each entry is a collection of 4 floats representing a particular vertex’s RGBA values. Hence, this mesh’s color buffer will contain 100 vertices * 4 floats/vertex = 400 floats in it.

Let’s say I have a Vector3f representing a particular vertex in this mesh. Is there any way to to look up index/position of this vertex’s entry (that is, the index/position of the 4 RGBA floats) in the color buffer?

So for example:

Vector3f vertex = getSomehow(); // doesn't matter for this example
FloatBuffer colorBuffer = (FloatBuffer)(mesh.getBuffer(VertexBuffer.Type.Color).getData());

// Perhaps the 4 floats representing this vertex's RGBA values are the 62nd set of floats,
// located at positions 247 - 250 in the color buffer. So I am looking for something that would
// be able to give me a value of 247 for indexOfVertexRGBAFloats below:
int indexOfVertexRGBAFloats = someMagic.getIndexOfRGBAFloats(vertex, colorBuffer);

I’ve looked in BufferUtils but all I see are add* and set* methods…nothing resembling a getter that fetches buffer data based on a Vector3f vertex.

How can I lookup the location of the Vector3f vertex’s RGBA floats in the color buffer? Thanks in advance!


posBufferIndex = vertIndex * 3
colorBufferIndex = vertIndex * 4

Or if you don’t like math:

Right, thanks @pspeed but I think you’re misunderstanding my disconnect.

How do you get vertIndex in the first place?

That is, I have a Vector3f instance (that I’m actually populating from mesh.getTriangle(...). So how do I obtain vertIndex from the Vector3f instance?

Vector3f v1, v2, v3;
v1 = new Vector3f();
v2 = new Vector3f();
v3 = new Vector3f();

// Obtain vertex data for the 400th triangle.
mesh.getTriangle(400, v1, v2, v3);

// Now find the location of v1's 4 RGBA floats in the color buffer
int vertIndex = getSomehow(v1); // <--- this is what I need help with

400 * 3 = vert index.

The 400th triangle in the mesh. No?

Any anyway, in the end it’s even more complicated than that.

Really, just look at the getTriangle() code.

I feel like you could save a lot of typing just by opening the Java files in this case.