how do you color specific vertices in one mesh?

Lets say youve defined a mesh with 20 vertices how do you color just one of those triangles with one color but have the rest be another?

I’ve been trying to figure this out myself but keep getting index out of bound errors with the mesh.color

Here is a simple test case. Does this work for you?

It’s a bit confusing, but mesh doesn’t allocate memory for colours unless you assign a table of colours to its mesh.colors property. Then you can access the data using the mesh:color() method.

I think we should probably change this so internal buffers are always allocated.

function draw()
    background(0)

    local m = mesh()
    local verts = { vec3( 0,0,0 ), vec3(100,0,0), vec3(50,100,0) }'
    local colors = { color(0,0,0), color(0,0,0), color(0,0,0) }

    m.vertices = verts
    m.colors = colors

    -- Set the three vertex colours
    m:color(1, 255,0,0)
    m:color(2, 0,255,0)
    m:color(3, 0,0,255)

    m:draw()
end

Thanks Simeon, you’re fast.

Sorry but after extensive testing I still can’t get my vectors to render. But your’s rendered fine.

I’ve even tried limiting my vectors down to just the first three and eliminating all commentary and the spaces between them. I’ve tried restarting my Ipad even and closing the program nothing works. I should mention I initially tried to do it in a class but even as a standalone I get the same results.

Can you post your code? Or a stand-alone example that doesn’t work for you?

Got it working now thanks Simeon