@Gai_Gai What do you mean?
@Kolosso How can the mesh know where to draw?
@Kolosso Because there is a lot of block at there and each block have a different location, how mesh know where to draw ?
@Gai_Gai Meshes can be translated with the translate(x,y,z)
command. Is that what you were asking about?
@dave1707 I delete the print, the fps is still low, I donāt think this is the problem.
@Kolosso Yea! Thank you! I try this at begin of the draw blocks and all of the blocks all moved! That is work! Thank you very much to help me.
@Gai_Gai Iām happy to help!
@Kolosso By the way, do I need 12 mesh for one type of block? Because if I donāt use it, the mesh need to change the vertices again.
@Gai_Gai Deleting the print statement wonāt solve the whole problem, but it will help some. If you leave the print statement in there, it will eventually cause the program to slow down to a crawl and then crash.
@dave1707 What if I change the print to text? I what to see the fps.
@Kolosso By the way, do I need 12 mesh for one type of block? Because if I donāt use it, the mesh need to change the vertices again.
You can do a parameter.watch(āFPSā) and put FPS=1/DeltaTime//1 in the draw() function.
@dave1707 That is a great idea, thanks for the help.
By the way, do I need 12 mesh for one type of block? Because if I donāt use it, the mesh need to change the vertices again.
@Gai_Gai What do you mean?
@Kolosso I think I need 12 mesh for a type of block, because one mesh need to draw one triangle and the triangle has the same location and one block have 12 triangle so I think I need 12 mesh for a type of block.
@Gai_Gai meshes can hold unlimited amount of triangles.
@Gai_Gai If I look at your running code, thereās a cube made up of 16x16x2 rectangles with the crate texture. On my iPad Air it runs at approx 7 FPS. Hereās an example I put together with a cube made up of 17x17x2 rectangles with the crate texture. I changed the size of the texture to make it look solid. This runs at approx 50 FPS on my iPad. Iām not sure about everything youāre doing in your code, but I just wanted to show you that the FPS can be increased. To see a 360 degree view of the inside of the cube, push cenX all the way to the right, then cenZ. Then push cenX all the way to the left, then cenZ. Repeat. Change eyeX,Y,Z for other views.
function setup()
parameter.watch("fps")
parameter.integer("eyeX",-4000,4000,0)
parameter.integer("eyeY",-200,200,40)
parameter.integer("eyeZ",-4000,4000,140)
parameter.integer("cenX",-1000,1000,-1000)
parameter.integer("cenZ",-1000,1000,-1000)
sides={}
for x=-8,8 do
for z=-8,8 do
table.insert(sides,side(x*20,40,z*20,"top"))
table.insert(sides,side(x*20,20,z*20,"bottom"))
end
end
for x=-8,8 do
for y=1,2 do
table.insert(sides,side(x*20,y*20,160,"front"))
table.insert(sides,side(x*20,y*20,-160,"back"))
table.insert(sides,side(180,y*20,x*20,"left"))
table.insert(sides,side(-180,y*20,x*20,"right"))
end
end
end
function draw()
background(40, 40, 50)
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(-10+x, -10+y, 10+z), -- Left bottom front
vec3( 10+x, -10+y, 10+z), -- Right bottom front
vec3( 10+x, 10+y, 10+z), -- Right top front
vec3(-10+x, 10+y, 10+z), -- Left top front
vec3(-10+x, -10+y, -10+z), -- Left bottom back
vec3( 10+x, -10+y, -10+z), -- Right bottom back
vec3( 10+x, 10+y, -10+z), -- Right top back
vec3(-10+x, 10+y, -10+z) } -- Left top back
self.ms=mesh()
self.ms.texture="Cargo Bot:Crate Green 1"
tex={ vec2(.1,.1),vec2(.9,.1),vec2(.1,.9),vec2(.9,.9) }
self.ms.texCoords={ tex[1],tex[2],tex[4],tex[1],tex[4],tex[3] }
if pos=="back" then
self.ms.vertices={ v[6],v[5],v[8],v[6],v[8],v[7] }
elseif pos=="front" then
self.ms.vertices={ v[1],v[2],v[3],v[1],v[3],v[4] }
elseif pos=="top" then
self.ms.vertices={ v[4],v[3],v[7],v[4],v[7],v[8] }
elseif pos=="bottom" then
self.ms.vertices={ v[5],v[6],v[2],v[5],v[2],v[1] }
elseif pos=="right" then
self.ms.vertices={ v[2],v[6],v[7],v[2],v[7],v[3] }
elseif pos=="left" then
self.ms.vertices={ v[5],v[1],v[4],v[5],v[4],v[8] }
end
self.ms:setColors(0,255,0,255)
end
function side:draw()
self.ms:draw()
end
@dave1707 thank you very much for the code , I will study on it, thank you very much.
@dave1707 can you teach me how does the code work? Iām not understand how the code work. How can the location of the mesh change without change the vertices?
@Gai_Gai The vertices values are different for each mesh. In the setup() function, I create an entry in the table sides for each mesh by calling side with different x,y,z values table insert(sides,side(x*20,40,z*20,"top"))
. The first for loop creates all the meshes for the top and bottom of the cube. The second for loop creates the sides. If you look at those, youāll see that there will be different values. Iām not sure if this is usable for what you might want to do, but then I donāt know what you want to do. This was written just to show that the FPS can be increased. There are 714 meshes, each with different vertices. I believe that the number of meshes can be reduced to 6 by creating a mesh for each side with all the vertices for those sides.