If you are creating a set of blocks in a kind of wall that won’t move, ie the wall won’t break up into pieces, it’s way more efficient to create the wall as a single 3D block, and tile the texture image on it to create the illusion of separate blocks.
As I said in my post above, the 714 meshes could be reduced to 6. Here’s similar code to what I have above and it uses 6 meshes, one for each side, and runs at approx 60 FPS.
EDIT: Changed code.
function setup()
m=mesh()
for x=0,15 do
for y=0,15 do
m:addRect(x*42+21,y*42+21,42,42)
end
end
m.texture="Cargo Bot:Crate Blue 1"
img=image(42*16,42*16)
setContext(img)
m:draw()
setContext()
m=mesh()
for x=0,15 do
for y=0,1 do
m:addRect(x*42+21,y*42+21,42,42)
end
end
m.texture="Cargo Bot:Crate Green 2"
img1=image(42*16,42*2)
setContext(img1)
m:draw()
setContext()
parameter.watch("fps")
parameter.integer("eyeX",-4000,4000,0)
parameter.integer("eyeY",-200,200,0)
parameter.integer("eyeZ",-4000,4000,0)
parameter.integer("cenX",-1000,1000,-1000)
parameter.integer("cenZ",-1000,1000,-1000)
sides={}
table.insert(sides,side(100,21,100,"top"))
table.insert(sides,side(100,21,100,"bottom"))
table.insert(sides,side(100,21,100,"front"))
table.insert(sides,side(100,21,100,"back"))
table.insert(sides,side(100,21,100,"left"))
table.insert(sides,side(100,21,100,"right"))
end
function draw()
background(0)
perspective(100)
camera(eyeX,eyeY,eyeZ, cenX,0,cenZ, 0,1,0)
for a,b in pairs(sides) do
b:draw()
end
fps=1/DeltaTime//1
end
side=class()
function side:init(x,y,z,pos)
v={ vec3(-x, -y, z), -- Left bottom front
vec3( x, -y, z), -- Right bottom front
vec3( x, y, z), -- Right top front
vec3(-x, y, z), -- Left top front
vec3(-x, -y, -z), -- Left bottom back
vec3( x, -y, -z), -- Right bottom back
vec3( x, y, -z), -- Right top back
vec3(-x, y, -z) } -- Left top back
self.ms=mesh()
tex={ vec2(0,0),vec2(1,0),vec2(0,1),vec2(1,1) }
self.ms.texCoords={ tex[1],tex[2],tex[4],tex[1],tex[4],tex[3] }
if pos=="back" then
self.ms.texture=img1
self.ms.vertices={ v[6],v[5],v[8],v[6],v[8],v[7] }
elseif pos=="front" then
self.ms.texture=img1
self.ms.vertices={ v[1],v[2],v[3],v[1],v[3],v[4] }
elseif pos=="top" then
self.ms.texture=img
self.ms.vertices={ v[4],v[3],v[7],v[4],v[7],v[8] }
elseif pos=="bottom" then
self.ms.texture=img
self.ms.vertices={ v[5],v[6],v[2],v[5],v[2],v[1] }
elseif pos=="right" then
self.ms.texture=img1
self.ms.vertices={ v[2],v[6],v[7],v[2],v[7],v[3] }
elseif pos=="left" then
self.ms.texture=img1
self.ms.vertices={ v[5],v[1],v[4],v[5],v[4],v[8] }
end
self.ms:setColors(255,255,255,255)
end
function side:draw()
self.ms:draw()
end
You could make an if statement when the FPS is less than 40 then smooth graphics is disabled else smooth graphics is enabled.
if FPS <= 40 then
noSmooth()
else
smooth()
end