Here’s an example of Craft spheres, one row without a texture and another row using a texture. Each face uses the texture. The columns show the spheres with higher and higher subdivisions. On the left is the image that’s being used. Try different images to see what you get. The sphere can be wrapped with a single texture, but it’s too involved to show here. I was able to wrap part of the sphere, but gave up trying to wrap the whole sphere because you can’t wrap an icosphere with a rectangular texture and have it work OK.
displayMode(FULLSCREEN)
function setup()
assert(craft, "Please include Craft as a dependency")
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(158, 202, 223, 255)
skyMaterial.horizon=color(98, 166, 114, 255)
scene.sun.rotation=quat.eulerAngles(-90,0,0)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 100, 0, 300)
texture=readImage("Small World:Heart Flat")
createSphere(vec3(12,30,0),0)
createSphere(vec3(12,15,0),1)
createSphere(vec3(12,0,0),2)
createSphere(vec3(12,-15,0),3)
createSphere(vec3(12,-30,0),4)
createSphere1(vec3(-12,30,0),0)
createSphere1(vec3(-12,15,0),1)
createSphere1(vec3(-12,0,0),2)
createSphere1(vec3(-12,-15,0),3)
createSphere1(vec3(-12,-30,0),4)
end
function draw()
update(DeltaTime)
scene:draw()
sprite(texture,100,HEIGHT/2,100)
fill(255)
text("No texture",WIDTH/2-120,HEIGHT-30)
text("Use texture",WIDTH/2+120,HEIGHT-30)
text("Texture used",100,HEIGHT/2+70)
end
function update(dt)
scene:update(dt)
end
function createSphere(p,s)
pt=scene:entity()
pt.position=vec3(p.x,p.y,p.z)
pt.model = craft.model.icosphere(5,s,1)
pt.material = craft.material("Materials:Standard")
end
function createSphere1(p,s)
pt=scene:entity()
pt.position=vec3(p.x,p.y,p.z)
pt.model = craft.model.icosphere(5,s,1)
uv={} -- need to change the uvs for texture
for z=1,#pt.model.uvs/3 do
table.insert(uv,vec2(0,0))
table.insert(uv,vec2(0,1))
table.insert(uv,vec2(1,1))
end
pt.model.uvs = uv
pt.material = craft.material("Materials:Standard")
pt.material.map=texture
end