mesh vertices and colors

m = mesh()
m.vertices = {...}
m.colors = {...}

Why are the arguments of mesh vertices with their colors limited with 3? Currently I create two meshes (m and m1…), two triangles for one rectangle. But why can’t I make it all in one mesh?

@TokOut You can make as many triangles for vertices and colors as you want for one mesh, but it has to be in multiples of 3 for the 3 corners of a triangle. If you want to work with rectangles, then you can use addRect which combines 2 triangles to make a rectangle. Here’s an example of using addRect.

function setup()
    m=mesh()
    m:addRect(250,300,100,80)
    m:addRect(250,200,100,80)
    m:addRect(400,300,100,80)
    m:addRect(400,200,100,80)
    m.texture="Space Art:Red Ship"
end

function draw()
    background(236, 213, 65, 255)
    m:draw()
end

@TokOut Here’s an example showing things in one mesh. Use the slider to show a texture or colors. You can have a different color in each of the triangle corners or the same color in all three.

function setup()
    parameter.boolean("ShowImage",false)
    m=mesh()
    img = readImage("Planet Cute:Icon")
    m.vertices = { vec2(0,0),vec2(300,0),vec2(0,300),vec2(0,300),vec2(300,300),vec2(300,0) }    
    m.texCoords = { vec2(0,0),vec2(1,0),vec2(0,1),vec2(0,1),vec2(1,1),vec2(1,0) }
    m:setColors(255,255,255,255)
end

function draw()
    background(40, 40, 50)
    if ShowImage then
        m.texture = img
        for z=1,6 do
            m:color(z,255,255,255)
        end
    else
        m.texture=nil
        m:color(1,255,0,0)
        m:color(2,0,255,0)
        m:color(3,0,0,255)
        m:color(4,255,255,0)
        m:color(5,255,255,0)
        m:color(6,255,255,0)
    end
    m:draw()
end