The following code is intended to create a mesh consisting of 20 randomly positioned plains by starting with a plain and adding 19 new plains to the mesh. Each component plain has zero size but that isn't the issue.
The
statistic(1) command reports 38 polys whereas there should be 40.
The program then outputs the new mesh. If you check the X file, you'll see that all 120 vertices are in fact listed (= 6 x 20), but data are only given for 38 polys (the first two are missing when you check the vertices used). It is easy enough to manually edit the X file to add these two missing polys.
However, there is one other issue. If you check the MeshNormals data in the X file you'll see that again all 120 are listed. However, all except for the first 6 vertices are (Nx, Ny, Nz) = (0, 0, 1). The program doesn't change the normals data - they should just be copied from the mesh used for the initial plain.
I don't think it's the
save mesh command causing these problems because the program reports only 38 polys when there should be 40 before the save mesh command is used.
Edit Forgot the code.
set display mode 1024, 768, 32
sync on: sync rate 0: sync
autocam off
position camera 0, 50, 350
point camera 0, 0, 0
numParticles = 20
objNum = 1
makeParticleObject(objNum, numParticles)
set object cull objNum, 0
global cx#
global cy#
cx# = camera angle x()
cy# = camera angle y()
repeat
text 20, 20, "cam X angle = "+str$(camera angle x(),2)
text 20, 40, "cam Y angle = "+str$(camera angle y(),2)
text 20, 60, "FS = "+str$(screen fps())
text 20, 80, "polys = "+str$(statistic(1))
positionCamera()
sync
until spacekey()
make mesh from object 2, 1
save mesh "test2.x", 2
end
function positionCamera()
control camera using arrowkeys 0, 1, 0
cx# = cx# + mousemovey(): cy# = cy# + mousemovex()
rotate camera cx#, cy#, 0
endfunction
function makeParticleObject(objNum, numParticles)
make object plain objNum, 0, 0
lock vertexdata for limb objNum, 0, 2
nv = get vertexdata vertex count() - 1
` set x, z data to random normalised direction
` set y coord to random speed factor in range 0 to 1
r1# = rnd(360)
r2# = rnd(100) * 0.01
for v = 0 to nv
set vertexdata position v, cos(r1#), r2#, sin(r1#)
next v
unlock vertexdata
make mesh from object 1, objNum
for i = 2 to numParticles
lock vertexdata for mesh 1
nv = get vertexdata vertex count() - 1
` set x, z data to random normalised direction
` set y coord to random speed factor in range 0 to 1
r1# = rnd(360)
r2# = rnd(100) * 0.01
for v = 0 to nv
set vertexdata position v, cos(r1#), r2#, sin(r1#)
next v
unlock vertexdata
lock vertexdata for limb objNum, 0, 2
add mesh to vertexdata 1
unlock vertexdata
next i
endfunction