Hi there.
I put this thread separed of the one that puzzler2018 did as we both a working more o less in the same theme
What I did here, is convert any sphere to .Obj with texture. This is somehow a trick to achive that , as the programm doesn't know how many ring has the sphere and we have to adjust manually the Quantity of ring to make a nice sphere or one in low poly. From 5 up to 64 and more . At the moment it doesn't load automatically the texture and I have to add an Mtl file. Not media needed
Here is the code ...I hope someone can find it useful
// Project: Esfera
// Created: 2018-12-26
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Esfera" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
`number of ring that make the sphere
ring=64 ` Y O U C A N P L A Y W I T H T H I S V A L U E S
createobjectsphere(1,20,ring,ring)
setobjectvisible(1,0)
gosub save_obj
gosub texture
loadobject(1000,"sphere.obj")
setobjectimage(1000,10,0)
setcameraposition(1,0,50,-50)
setcameralookat(1,0,0,0,0)
do
g=g+1
setobjectrotation(1000,0,g,0)
Print( ScreenFPS() )
Sync()
loop
save_obj:
OpenToWrite ( 1, "raw:d:media\sphere.obj", 0 )
mesh = CreateMemblockFromObjectMesh(1,1)
`get object vertex quantity
verts= GetMemblockInt( mesh, 0 )
`VERTEX
for i= 1 to verts
x#=GetMeshMemblockVertexX(mesh,i-1)
y#=GetMeshMemblockVertexy(mesh,i-1)
z#=GetMeshMemblockVertexz(mesh,i-1)
Writeline ( 1, " v " + str(z#)+ " "+str(y#)+ " "+str(x#))
next i
`NORMALS
for i= 0 to verts
nx#=GetMeshMemblockVertexNormalX( mesh, i )
ny#=GetMeshMemblockVertexNormalY( mesh, i )
nz#=GetMeshMemblockVertexNormalz( mesh, i )
//writeline(1, " vn "+str(nx#)+" "+str(ny#)+" "+str(nz#))
next
`TEXTURE VERTICES
for i= 0 to verts
UU#=GetMeshMemblockVertexU( mesh, i )
VV#=GetMeshMemblockVertexV( mesh, i )
writeline(1, " vt "+str(UU#)+" "+str(VV#))
next
`FACES
for i= 1 to verts-(ring+2)
writeline (1, " f "+ str(i)+"/"+str(i)+" " +str(i+(ring+1))+"/"+str(i+(ring+1)) +" "+str(i+(ring+2))+"/"+str(i+(ring+2)))
writeline (1, " f "+ str(i)+"/"+str(i)+" " +str(i+(ring+2))+"/"+str(i+(ring+2)) +" "+str(i+1)+"/"+str(i+1))
next
DeleteMemblock(1)
CloseFile ( 1 )
return
Texture:
red=makecolor(155,155,0)
drawbox(0,0,640,480,red,red,red,red,1)
x=300
y=200
g=0
c=0
for i= 1 to 800
inc g,5
inc c,1
if c>255 then c=50
x=x+(cos(g)*i/50)
y=Y+(sin(g)*i/50)
col=makecolor(c*2,c,0)
drawbox(x,y,x+i/10,y+i/30,col,col,col,col,1)
next i
getimage(10,220,120,170,170)
return
I'm not a grumpy grandpa