Hi there. I'm still around ... the covid19 has not been able to defeat me .
Lately I've been fiddling with the directx again . To export an object , if we are going to use only vertices color , we don't need the normals or texture coordinates but the position of each vertex x,y,z and its colors... this reduces the final file quite a bit. I have made a small example showing how we can export (write) .x files from AppGameKit . I have the same example exporting boxes that I use in my voxel creator and it works like a charm . I hope this example can be useful and inspiring for someone.
// Project: Export vertex color
// Created: 2021-04-19
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Export vertex color" )
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
n_cajas=110 `num of planes
n_verts=4 `vertex per object
type caja
x as float
y as float
z as float
t as float
r as float
g as float
b as float
endtype
dim ball[n_cajas] as caja
SetRandomSeed( 1 ) `crea siempre el mismo patron
for i=1 to n_cajas
ball[i].x=(Random(0,30)*10)
ball[i].y=(Random(0,30)*10)
ball[i].z=0
ball[i].t=10
ball[i].r=random(0,255.0)/255.0 ` DirectX color works from 0 to 1 , and AGK rgb works from 1 to 255
ball[i].g=random(0,255.0)/255.0 ` something like directX_col = AGK_col/255 Red = 120/255 = 0.470
ball[i].b=random(0,255.0)/255.0
next
`hold vertex vx,vy,vz
dim vx[4]
dim vy[4]
dim vz[4]
`Time so write to file
OpenToWrite (1,"raw:d:media\planes.x", 0 )
writeline(1,"xof 0303txt 0032")
writeline(1,"") `space
writeline(1,"# Saving planes from scratch to .x by Chafari ")
writeline(1,"# Made in AGK2 April 2021")
writeline(1,"") `space
for i= 1 to n_cajas
writeline(1,"") `space
writeline(1,"Mesh {")
writeline(1," "+ str(n_verts) + ";")
for a= 1 to n_verts
c=makecolor(255,0,0)
`holding vertex x,y,z of every plane ...this time we put them all in same Z position
vx[1]=ball[i].x-ball[i].t/2
vx[2]=ball[i].x+ball[i].t/2
vx[3]=ball[i].x+ball[i].t/2
vx[4]=ball[i].x-ball[i].t/2
vy[1]=ball[i].y-ball[i].t/2
vy[2]=ball[i].y-ball[i].t/2
vy[3]=ball[i].y+ball[i].t/2
vy[4]=ball[i].y+ball[i].t/2
vz[1]=ball[i].z
vz[2]=ball[i].z
vz[3]=ball[i].z
vz[4]=ball[i].z
if a < n_verts then app$ = ";," else app$ = ";;"
writeline(1," "+ str(vx[a], 6) + "; " + str(vy[a], 6) + "; " + str(vz[a], 6) + app$)
next
writeline(1,"") rem space
writeline(1," 2;")
writeline(1," 3;2,1,0;,")
writeline(1," 3;0,3,2;;")
writeline(1,"" ) rem space
writeline(1," MeshVertexColors {")
writeline(1," 4;")
writeline(1," 0;"+str(ball[i].r, 6)+";"+str(ball[i].g, 6)+";"+str(ball[i].b, 6)+";1.000000;;,")
writeline(1," 1;"+str(ball[i].r, 6)+";"+str(ball[i].g, 6)+";"+str(ball[i].b, 6)+";1.000000;;,")
writeline(1," 2;"+str(ball[i].r, 6)+";"+str(ball[i].g, 6)+";"+str(ball[i].b, 6)+";1.000000;;,")
writeline(1," 3;"+str(ball[i].r, 6)+";"+str(ball[i].g, 6)+";"+str(ball[i].b, 6)+";1.000000;;;")
writeline(1," }")
writeline(1,"}")
next
CloseFile ( 1 )
loadobject(1,"planes.x")
SetObjectCullMode(1,0)
SetObjectLightMode(1,0)
`sky
createobjectsphere(1200,3000,10,10)
SetObjectColorEmissive(1200,0,0,150)
SetObjectCullMode(1200,0)
setcameraposition(1,100,200,-600)
setcameralookat(1,100,200,0,0)
SetCameraRange(1,1,3000)
do
g=g+2
setobjectrotation(1,g,g,g)
Print( ScreenFPS() )
Sync()
loop
More to come if I feel myself motivated .
I'm not a grumpy grandpa