@UberGoober Now I know why I never created a good explanation for the tables. There’s a lot going on but once you understand it, it’s not too bad. Here’s an example where I tried to comment things, but there’s still more to it. The points P1 thru P4 show the counterclockwise direction that I use. The triangles are also created counterclockwise. Near the bottom is the layout of how to overlay an image onto a rectangle created from triangles. An image value goes from 0 to 1 in both x,y directions. You can use fractional values to use part of an image if you want. So basically larger things are created by the buildup of triangles. The tables just get bigger based on how many triangles you use.
I know I’m not explaining this very well, so if you have other questions just ask.
viewer.mode=FULLSCREEN
function setup()
assert(OrbitViewer, "Please include Cameras as a dependency")
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(72, 195, 234)
skyMaterial.horizon=color(160, 226, 117)
scene.sun.rotation=quat.eulerAngles(40,60,30)
v=scene.camera:add(OrbitViewer,vec3(0,0,0), 100, 0, 1000)
v.ry=180
v.camera.farPlane=1000
fill(255)
-- coordinates of triangles for creating a rectangle
p1=vec3(-10,0,0)
p2=vec3(10,0,0)
p3=vec3(10,10,0)
p4=vec3(-10,10,0)
-- create normals table. used for reflections and brightness of image texture
nor1={}
norm1(p1,p2,p3)
norm1(p1,p3,p4)
pos={p1,p2,p3,p1,p3,p4} -- triangle coord in counter clockwise direction
-- double the size of pos table gives both sides
ind={1,2,3,4,5,6,6,5,4,3,2,1} -- both sides visible when rotated
--ind={1,2,3,4,5,6} -- one side visible when rotated
-- define image values, vec2 for each point in pos table
uvs={vec2(0,0),vec2(1,0),vec2(1,1),vec2(0,0),vec2(1,1),vec2(0,1)}
createTile1()
end
function draw()
update(DeltaTime)
scene:draw()
showText()
end
function showText()
sprite(asset.builtin.Blocks.Missing,WIDTH/2,200)
text("(P1= -10,0,0)",WIDTH/2-100,HEIGHT/2+200)
text("(P2= 10,0,0)",WIDTH/2+100,HEIGHT/2+200)
text("(P3= 10,10,0)",WIDTH/2+100,HEIGHT/2+300)
text("(P4= -10,10,0)",WIDTH/2-100,HEIGHT/2+300)
text("triangle 1= P1,P2,P3 triangle 2= P1,P3,P4",WIDTH/2,HEIGHT/2+160)
text("(0,0)",WIDTH/2-70,120)
text("(1,0)",WIDTH/2+70,120)
text("(1,1)",WIDTH/2+70,280)
text("(0,1)",WIDTH/2-70,280)
end
function update(dt)
scene:update(dt)
end
function createTile1()
r=scene:entity()
r.model = craft.model()
r.model.positions=pos
r.model.indices=ind
-- uvs table defines image area to use, values between 0 and 1
r.model.uvs=uvs
-- color table used with Materials Basic
c=color(255)
r.model.colors={c,c,c,c,c,c}
-- normals table used with Material Standard and Specular for reflection
r.model.normals=nor1
r.material = craft.material(asset.builtin.Materials.Specular)
r.material.map=readImage(asset.builtin.Blocks.Missing)
end
function norm1(a,b,c)
v1=b-a
v2=c-b
n1=v1:cross(v2)
table.insert(nor1,n1)
table.insert(nor1,n1)
table.insert(nor1,n1)
end