Is there anyway that I can make 2D text follow the X and Y coordinates of a craft model??
Thanks in advance
Is there anyway that I can make 2D text follow the X and Y coordinates of a craft model??
Thanks in advance
@Creator27 - If you check out the Ignatz website he developed a routine for transposing 3D positions to 2D. You can use that and offset for your text as needed.
P.s. I you don’t already know - the wiki site has links to most other sites, including that of Ignatz.
@Creator27 Here’s something I have.
viewer.mode=STANDARD
function setup()
parameter.integer("tx",0,360,270)
parameter.integer("ty",0,360)
parameter.integer("tz",0,360)
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(0, 62, 255, 255)
skyMaterial.horizon=color(0, 255, 201)
scene.sun.rotation=quat.eulerAngles(20,45,-30)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 60, 0, 200)
fill(255)
font("Baskerville-BoldItalic")
img=image(320,160)
setContext(img)
background(0,0,0,0)
fontSize(20)
fill(255, 0, 196)
text("red rubber ball",160,80)
setContext()
createObjects()
createCube()
end
function createObjects()
radius1=1
sphere1=scene:entity()
s1=sphere1:add(craft.rigidbody,DYNAMIC)
s1.restitution=1
sphere1.position=vec3(0,5,0)
sphere1:add(craft.shape.sphere,radius1)
sphere1.model = craft.model.icosphere(radius1,2)
sphere1.material = craft.material(asset.builtin.Materials.Specular)
sphere1.material.diffuse=color(255,0,0)
cube1=scene:entity()
c1=cube1:add(craft.rigidbody,STATIC)
c1.restitution=1
cube1.position=vec3(0,-20,0)
cube1:add(craft.shape.box,vec3(3,.1,3))
cube1.model = craft.model.cube(vec3(3,.1,3))
cube1.material = craft.material(asset.builtin.Materials.Specular)
cube1.material.diffuse=color(123, 255, 0)
end
function draw()
update(DeltaTime)
scene:draw()
t.rotation=quat.eulerAngles(tx,ty,tz)
t.position=vec3(sphere1.position.x,sphere1.position.y+2,sphere1.position.z)
end
function update(dt)
scene:update(dt)
end
function createCube()
t=scene:entity()
t.position=vec3(0,0,0)
t.model = craft.model.plane(vec2(20,10))
t.material = craft.material(asset.builtin.Materials.Standard)
t.material.map = img
t.material.blendMode = NORMAL
end
@dave1707 - oooooh that is neat !!!
@dave1707, thanks for your code, it worked very efficiently. Just one problem. I want the text to show a live display of a number that changes from 0 to 3. How am I supposed to do this??
Thanks in advance
Here’s a hacked up version.
viewer.mode=STANDARD
function setup()
parameter.integer("tx",0,360,270)
parameter.integer("ty",0,360)
parameter.integer("tz",0,360)
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(0, 62, 255, 255)
skyMaterial.horizon=color(0, 255, 201)
scene.sun.rotation=quat.eulerAngles(20,45,-30)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 60, 0, 200)
nbr=1
fill(255)
font("Baskerville-BoldItalic")
img1=image(400,200)
setContext(img1)
background(0,0,0,0)
fontSize(40)
fill(255, 0, 196)
text("1",200,100)
setContext()
img2=image(400,200)
setContext(img2)
background(0,0,0,0)
fontSize(40)
fill(255, 0, 196)
text("2",200,100)
setContext()
img3=image(400,200)
setContext(img3)
background(0,0,0,0)
fontSize(40)
fill(255, 0, 196)
text("3",200,100)
setContext()
createObjects()
createCube()
end
function createObjects()
radius1=1
sphere1=scene:entity()
s1=sphere1:add(craft.rigidbody,DYNAMIC)
s1.restitution=1
sphere1.position=vec3(0,5,0)
sphere1:add(craft.shape.sphere,radius1)
sphere1.model = craft.model.icosphere(radius1,2)
sphere1.material = craft.material(asset.builtin.Materials.Specular)
sphere1.material.diffuse=color(255,0,0)
cube1=scene:entity()
c1=cube1:add(craft.rigidbody,STATIC)
c1.restitution=1
cube1.position=vec3(0,-20,0)
cube1:add(craft.shape.box,vec3(3,.1,3))
cube1.model = craft.model.cube(vec3(3,.1,3))
cube1.material = craft.material(asset.builtin.Materials.Specular)
cube1.material.diffuse=color(123, 255, 0)
end
function draw()
update(DeltaTime)
scene:draw()
t.rotation=quat.eulerAngles(tx,ty,tz)
t.position=vec3(sphere1.position.x,sphere1.position.y+2,sphere1.position.z)
text("tap screen to change number",WIDTH/2,HEIGHT-100)
end
function update(dt)
scene:update(dt)
end
function touched(tch)
if tch.state==BEGAN then
nbr=nbr+1
if nbr>3 then
nbr=1
end
if nbr==1 then
t.material.map = img1
elseif nbr==2 then
t.material.map = img2
elseif nbr==3 then
t.material.map = img3
end
end
end
function createCube()
t=scene:entity()
t.position=vec3(0,0,0)
t.model = craft.model.plane(vec2(20,10))
t.material = craft.material(asset.builtin.Materials.Standard)
t.material.map = img1
t.material.blendMode = NORMAL
end
@dave1707, thank you SO MUCH for your help! It’s working completely flawlessly and I LOVE IT!! Once again, thank you
Here’s a cleaned up version that uses the slider so you can rotate the objects.
viewer.mode=STANDARD
function setup()
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
parameter.integer("nbr",1,3)
parameter.integer("tx",0,360,270)
parameter.integer("ty",0,360)
parameter.integer("tz",0,360)
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(0, 62, 255, 255)
skyMaterial.horizon=color(0, 255, 201)
scene.sun.rotation=quat.eulerAngles(20,45,-30)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 60, 0, 200)
font("Baskerville-BoldItalic")
img1=image(400,200)
img2=image(400,200)
img3=image(400,200)
fontSize(40)
fill(255, 0, 196)
setContext(img1)
background(0,0,0,0)
text("1",200,100)
setContext(img2)
text("2",200,100)
setContext(img3)
text("3",200,100)
setContext()
tab={img1,img2,img3}
createObjects()
createCube()
end
function createObjects()
radius1=1
sphere1=scene:entity()
s1=sphere1:add(craft.rigidbody,DYNAMIC)
s1.restitution=1
sphere1.position=vec3(0,5,0)
sphere1:add(craft.shape.sphere,radius1)
sphere1.model = craft.model.icosphere(radius1,2)
sphere1.material = craft.material(asset.builtin.Materials.Specular)
sphere1.material.diffuse=color(255,0,0)
cube1=scene:entity()
c1=cube1:add(craft.rigidbody,STATIC)
c1.restitution=1
cube1.position=vec3(0,-20,0)
cube1:add(craft.shape.box,vec3(3,.1,3))
cube1.model = craft.model.cube(vec3(3,.1,3))
cube1.material = craft.material(asset.builtin.Materials.Specular)
cube1.material.diffuse=color(123, 255, 0)
end
function draw()
update(DeltaTime)
scene:draw()
t.rotation=quat.eulerAngles(tx,ty,tz)
t.position=vec3(sphere1.position.x,sphere1.position.y+2,sphere1.position.z)
t.material.map = tab[nbr]
end
function update(dt)
scene:update(dt)
end
function createCube()
t=scene:entity()
t.position=vec3(0,0,0)
t.model = craft.model.plane(vec2(20,10))
t.material = craft.material(asset.builtin.Materials.Standard)
t.material.blendMode = NORMAL
end
Here’s another example.
viewer.mode=STANDARD
function setup()
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
parameter.integer("tx",0,360,270)
parameter.integer("ty",0,360)
parameter.integer("tz",0,360)
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(0, 62, 255, 255)
skyMaterial.horizon=color(0, 255, 201)
scene.sun.rotation=quat.eulerAngles(20,45,-30)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 60, 0, 200)
font("Baskerville-BoldItalic")
img=image(200,100)
createObjects()
end
function createObjects()
radius1=1
sphere1=scene:entity()
s1=sphere1:add(craft.rigidbody,DYNAMIC)
s1.restitution=1
sphere1.position=vec3(0,15,0)
sphere1:add(craft.shape.sphere,radius1)
sphere1.model = craft.model.icosphere(radius1,2)
sphere1.material = craft.material(asset.builtin.Materials.Specular)
sphere1.material.diffuse=color(255,0,0)
cube1=scene:entity()
c1=cube1:add(craft.rigidbody,STATIC)
c1.restitution=1
cube1.position=vec3(0,-20,0)
cube1:add(craft.shape.box,vec3(3,.1,.3))
cube1.model = craft.model.cube(vec3(3,.1,3))
cube1.material = craft.material(asset.builtin.Materials.Specular)
cube1.material.diffuse=color(123, 255, 0)
end
function draw()
update(DeltaTime)
scene:draw()
createCube()
end
function update(dt)
scene:update(dt)
end
function createCube()
fontSize(80)
fill(255, 0, 196)
setContext(img)
background(0,0,0,0)
text(sphere1.position.y//1,100,50)
setContext()
if t then t:destroy() end
t=scene:entity()
t.position=vec3(sphere1.position.x,sphere1.position.y+2,sphere1.position.z)
t.model = craft.model.plane(vec2(4,2))
t.material = craft.material(asset.builtin.Materials.Standard)
t.material.blendMode = NORMAL
t.material.map=img
t.rotation=quat.eulerAngles(tx,ty,tz)
end