This code snippet "builds" objects from the ground up. It's not very fast on objects with lots of vertices.
Instead of scaling the objects, this will set the y position of each vertex above height# to height#. height# goes from the bottom vertex to the top vertex during construction.
sync on
sync rate 0
cls
hide mouse
`objects to build
make object sphere 1,1
make object cube 2,1
make object cone 3,1
make object cylinder 4,1
for n=1 to 4
hide object n
next n
autocam off
timer0=timer()
position camera 4,2,4
time_to_make#=3 `seconds
build_new=1
n=10
make matrix 1,100,100,10,10
do
time#=(timer()-timer0)/1000.0
timer0=timer()
set cursor 0,0
print screen fps()
if build_new=1
build_new=0
x#=rnd(object size x(1)*80)/10.0+6
z#=rnd(object size z(1)*80)/10.0+6
a#=0
inc n
s=rnd(3)+1
endif
if a#<=1
build(s,n,a#,x#,0.5,z#)
endif
a#=a#+time#/time_to_make#
if a#<=1
print "building..."
print a#
else
build_new=1
endif
rotate camera camera angle x()+mousemovey(),camera angle y()+mousemovex(),0
point camera x#,a#,z#
sync
loop
function build(obj1,obj2,amt#,x#,y#,z#)
if object exist(obj2) then delete object obj2
make mesh from object 1,obj1
make memblock from mesh 1,1
delete mesh 1
fvf_size=memblock dword(1,4)
vertex_amt=memblock dword(1,8)
for v=0 to vertex_amt-1
pos=12+v*fvf_size
vy#=memblock float(1,pos+4)
if v=0
min#=vy#
max#=vy#
else
if vy#<min# then min#=vy#
if vy#>max# then max#=vy#
endif
next v
height#=min#+amt#*(max#-min#)
for v=0 to vertex_amt-1
pos1=12+v*fvf_size
vy#=memblock float(1,pos1+4)
if vy#>height#
vy#=height#
write memblock float 1,pos1+4,vy#
endif
next v
make mesh from memblock 1,1
delete memblock 1
make object obj2,1,0
position object obj2,x#,y#,z#
endfunction
function build2(obj1,obj2,amt#,x#,y#,z#)
`this is a second way of doing it, but it crashes the program after a few buildings
if object exist(obj2) then delete object obj2
clone object obj2,obj1
lock vertexdata for limb obj2,0,2
vertex_amt=get vertexdata index count()
for v=0 to vertex_amt-1
vy#=get vertexdata position y(v)
if v=0
min#=vy#
max#=vy#
else
if vy#<min# then min#=vy#
if vy#>max# then max#=vy#
endif
next v
height#=min#+amt#*(max#-min#)
for v=0 to vertex_amt-1
vx#=get vertexdata position x(v)
vy#=get vertexdata position y(v)
vz#=get vertexdata position z(v)
if vy#>height#
set vertexdata position v,vx#,height#,vz#
endif
next v
unlock vertexdata
` delete mesh from vertexdata 0,vertex_amt,0,vertex_amt
position object obj2,x#,y#,z#
endfunction
I tried redoing the function using the vertexdata commands, and it is faster (vertexdata commands - 300 fps, memblock commands - 70 fps). The only problem is the program slows down really fast and then there's a unhandled win32 exception or something like that and the program crashes.