Thanks, here's a demo that uses the convex hull to make boxes, spheres, cylinders, pyramids, tetrahedrons, octahedrons, capsules, cones, and chamfer boxes.
I also worked on the convex hull algorithm. While it still wants the first 4 points to be non coplanar, it can add points that are coplanar to the existing points in the convex hull. If the first 4 points are coplanar, for the time being it wiggles them slightly until they're not, though the proper way to do it would be to search the array of points for 4 non-coplanar points and start with those.
sync on
sync rate 0
cls
set display mode 1024,768,32
hide mouse
autocam off
set camera range 0.01,100
type tri_type
v1
v2
v3
endtype
dim object_data(0) as tri_type
empty array object_data(0)
type v12
v1
v2
endtype
dim horizon(0) as v12
empty array horizon(0)
autocam off
type xyz
x as float
y as float
z as float
endtype
global point_amount=0
dim points(800) as xyz
make matrix 1,100,100,40,40
position camera 50,2,50
color backdrop 0
timer0=timer()
global time#=0
ink rgb(0,255,0),0
dim oldkeystate(200)
dim keypress(200)
global dist#=5.0
do
set cursor 0,0
print "[1] Box"
print "[2] Sphere"
print "[3] Cylinder"
print "[4] Pyramid"
print "[5] Tetrahedron"
print "[6] Octahedron"
print "[7] Capsule"
print "[8] Cone"
print "[9] Chamfer Box"
print "Shift+[num] for regular version of shapes"
time#=(timer()-timer0)/1000.0
timer0=timer()
rotate camera camera angle x()+mousemovey(),camera angle y()+mousemovex(),0
move camera (keystate(17)-keystate(31))*5*time#
xr#=camera angle x()
xrotate camera 0
yrotate camera camera angle y()+90
move camera (keystate(32)-keystate(30))*5*time#
yrotate camera camera angle y()-90
xrotate camera xr#
if shiftkey()=0
if keypress(2)=1
o=freeobject()
x#=1.0+rnd(100)/100.0
y#=1.0+rnd(100)/100.0
z#=1.0+rnd(100)/100.0
make_object_box(o,x#,y#,z#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(3)=1
o=freeobject()
x#=1.0+rnd(100)/100.0
y#=1.0+rnd(100)/100.0
z#=1.0+rnd(100)/100.0
make_object_spheroid(o,x#,y#,z#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(4)=1
o=freeobject()
x#=1.0+rnd(100)/100.0
y#=1.0+rnd(100)/100.0
z#=1.0+rnd(100)/100.0
make_object_elliptic_cylinder(o,x#,y#,z#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(5)=1
o=freeobject()
x#=1.0+rnd(100)/100.0
y#=1.0+rnd(100)/100.0
z#=1.0+rnd(100)/100.0
make_object_pyramid(o,x#,y#,z#,3+rnd(3))
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(6)=1
o=freeobject()
r#=0.5+rnd(150)/100.0
a#=acos(-1.0/3)-90
x1#=0
y1#=r#
z1#=0
r#=0.5+rnd(150)/100.0
x2#=0
y2#=-r#*sin(a#)
z2#=r#*cos(a#)
r#=0.5+rnd(150)/100.0
x3#=r#*cos(a#)*sin(120)
y3#=-r#*sin(a#)
z3#=r#*cos(a#)*cos(120)
r#=0.5+rnd(150)/100.0
x4#=r#*cos(a#)*sin(240)
y4#=-r#*sin(a#)
z4#=r#*cos(a#)*cos(240)
make_object_tetrahedron(o,x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#,x4#,y4#,z4#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(7)=1
o=freeobject()
x#=1.0+rnd(100)/100.0
y#=1.0+rnd(100)/100.0
z#=1.0+rnd(100)/100.0
make_object_octahedron(o,x#,y#,z#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(8)=1
o=freeobject()
x#=1.0+rnd(100)/100.0
y#=1.0+rnd(100)/100.0
z#=1.0+rnd(100)/100.0
make_object_elliptic_capsule(o,x#,y#,z#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(9)=1
o=freeobject()
x#=1.0+rnd(100)/100.0
y#=1.0+rnd(100)/100.0
z#=1.0+rnd(100)/100.0
make_object_elliptic_cone(o,x#,y#,z#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(10)=1
o=freeobject()
x#=1.0+rnd(100)/100.0
y#=1.0+rnd(100)/100.0
z#=1.0+rnd(100)/100.0
c#=0.1+rnd(20)/100.0
make_object_chamfer_box(o,x#,y#,z#,c#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
else
if keypress(2)=1
o=freeobject()
s#=1.0+rnd(100)/100.0
make_object_cube(o,s#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(3)=1
o=freeobject()
d#=1.0+rnd(100)/100.0
make_object_sphere(o,d#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(4)=1
o=freeobject()
d#=1.0+rnd(100)/100.0
h#=1.0+rnd(100)/100.0
make_object_cylinder(o,d#,h#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(5)=1
o=freeobject()
s#=1.0+rnd(100)/100.0
make_object_square_pyramid(o,s#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(6)=1
o=freeobject()
r#=1.0+rnd(100)/100.0
make_object_regular_tetrahedron(o,r#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(7)=1
o=freeobject()
s#=1.0+rnd(100)/100.0
make_object_regular_octahedron(o,s#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(8)=1
o=freeobject()
d#=1.0+rnd(100)/100.0
h#=1.0+rnd(100)/100.0
make_object_capsule(o,d#,h#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(9)=1
o=freeobject()
d#=1.0+rnd(100)/100.0
h#=1.0+rnd(100)/100.0
make_object_cone(o,d#,h#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
if keypress(10)=1
o=freeobject()
s#=1.0+rnd(100)/100.0
c#=0.1+rnd(20)/100.0
make_object_chamfer_cube(o,s#,c#)
rotate object o,rnd(20)-10,rnd(360),rnd(20)-10
move camera dist#:position object o,camera position x(),camera position y(),camera position z():move camera -dist#
endif
endif
for n=1 to 200
keypress(n)=keystate(n)-oldkeystate(n)
oldkeystate(n)=keystate(n)
next n
sync
loop
function freeobject()
o=1
while object exist(o)
inc o
endwhile
endfunction o
function add_point(x#,y#,z#)
inc point_amount
points(point_amount).x=x#
points(point_amount).y=y#
points(point_amount).z=z#
endfunction
function position_point(n,x#,y#,z#)
points(n).x=x#
points(n).y=y#
points(n).z=z#
endfunction
function create_convex_hull(obj_num)
rem This function creates an object that is a convex hull, containing all points in the array points().
if point_amount=1
make object triangle obj_num,points(1).x,points(1).y,points(1).z,points(1).x,points(1).y,points(1).z,points(1).x,points(1).y,points(1).z
endif
if point_amount=2
make object triangle obj_num,points(1).x,points(1).y,points(1).z,points(1).x,points(1).y,points(1).z,points(2).x,points(2).y,points(2).z
endif
if point_amount=3
make object triangle obj_num,points(1).x,points(1).y,points(1).z,points(2).x,points(2).y,points(2).z,points(3).x,points(3).y,points(3).z
set object normals obj_num
endif
if point_amount>3
fvf_format=274
fvf_size=32
dim edge(point_amount,point_amount) as v12
empty array object_data(0)
empty array horizon(0)
k=make vector3(1)
k=make vector3(2)
k=make vector3(3)
k=make vector3(4)
for t=1 to 4
v1=t
v2=v1+1
if v2>4 then v2=v2-4
v3=v2+1
if v3>4 then v3=v3-4
v4=v3+1
if v4>4 then v4=v4-4
rem cross product is used to check the direction the triangle ia facing
do
set vector3 1,points(v3).x-points(v1).x,points(v3).y-points(v1).y,points(v3).z-points(v1).z
set vector3 2,points(v2).x-points(v1).x,points(v2).y-points(v1).y,points(v2).z-points(v1).z
cross product vector3 1,1,2
c#=(points(v4).x-points(v1).x)*x vector3(1)+(points(v4).y-points(v1).y)*y vector3(1)+(points(v4).z-points(v1).z)*z vector3(1)
if c#<0
rem swap 2 points if it is facing the wrong way
temp=v3
v3=v2
v2=temp
endif
if c#=0
points(v1).x=points(v1).x+(rnd(2)-1)*0.00001
points(v1).y=points(v1).y+(rnd(2)-1)*0.00001
points(v1).z=points(v1).z+(rnd(2)-1)*0.00001
points(v2).x=points(v2).x+(rnd(2)-1)*0.00001
points(v2).y=points(v2).y+(rnd(2)-1)*0.00001
points(v2).z=points(v2).z+(rnd(2)-1)*0.00001
points(v3).x=points(v3).x+(rnd(2)-1)*0.00001
points(v3).y=points(v3).y+(rnd(2)-1)*0.00001
points(v3).z=points(v3).z+(rnd(2)-1)*0.00001
points(v4).x=points(v4).x+(rnd(2)-1)*0.00001
points(v4).y=points(v4).y+(rnd(2)-1)*0.00001
points(v4).z=points(v4).z+(rnd(2)-1)*0.00001
else
exit
endif
loop
array insert at bottom object_data(0)
object_data(array count(object_data(0))).v1=v1
object_data(array count(object_data(0))).v2=v2
object_data(array count(object_data(0))).v3=v3
next t
for v=5 to point_amount
empty array horizon(0)
outside=0
for p1=1 to point_amount
for p2=1 to point_amount
edge(p1,p2).v1=0
edge(p1,p2).v2=0
next p2
next p1
for t=0 to array count(object_data(0))
v1=object_data(t).v1
v2=object_data(t).v2
v3=object_data(t).v3
v4=v
set vector3 1,points(v3).x-points(v1).x,points(v3).y-points(v1).y,points(v3).z-points(v1).z
set vector3 2,points(v2).x-points(v1).x,points(v2).y-points(v1).y,points(v2).z-points(v1).z
cross product vector3 1,1,2
c#=(points(v4).x-points(v1).x)*x vector3(1)+(points(v4).y-points(v1).y)*y vector3(1)+(points(v4).z-points(v1).z)*z vector3(1)
if c#<0
outside=1
array delete element object_data(0),t
dec t
if v2<v1
a1=v2
a2=v1
else
a1=v1
a2=v2
endif
edge(a1,a2).v1=1
if edge(a1,a2).v2=1
array insert at bottom horizon(0)
horizon(array count(horizon(0))).v1=a1
horizon(array count(horizon(0))).v2=a2
endif
if v3<v2
a1=v3
a2=v2
else
a1=v2
a2=v3
endif
edge(a1,a2).v1=1
if edge(a1,a2).v2=1
array insert at bottom horizon(0)
horizon(array count(horizon(0))).v1=a1
horizon(array count(horizon(0))).v2=a2
endif
if v3<v1
a1=v3
a2=v1
else
a1=v1
a2=v3
endif
edge(a1,a2).v1=1
if edge(a1,a2).v2=1
array insert at bottom horizon(0)
horizon(array count(horizon(0))).v1=a1
horizon(array count(horizon(0))).v2=a2
endif
endif
if c#>=0
if v2<v1
a1=v2
a2=v1
else
a1=v1
a2=v2
endif
edge(a1,a2).v2=1
if edge(a1,a2).v1=1
array insert at bottom horizon(0)
horizon(array count(horizon(0))).v1=a1
horizon(array count(horizon(0))).v2=a2
endif
if v3<v2
a1=v3
a2=v2
else
a1=v2
a2=v3
endif
edge(a1,a2).v2=1
if edge(a1,a2).v1=1
array insert at bottom horizon(0)
horizon(array count(horizon(0))).v1=a1
horizon(array count(horizon(0))).v2=a2
endif
if v3<v1
a1=v3
a2=v1
else
a1=v1
a2=v3
endif
edge(a1,a2).v2=1
if edge(a1,a2).v1=1
array insert at bottom horizon(0)
horizon(array count(horizon(0))).v1=a1
horizon(array count(horizon(0))).v2=a2
endif
endif
next t
if outside=1
rem the point is outside the convex hull. Expand the hull.
for h=0 to array count(horizon(0))
for h2=0 to h-1
if (horizon(h).v1=horizon(h2).v1 and horizon(h).v2=horizon(h2).v2) or (horizon(h).v1=horizon(h2).v2 and horizon(h).v2=horizon(h2).v1)
array delete element horizon(0),h2
dec h2
dec h
endif
next h2
next h
for h=0 to array count(horizon(0))
v1=v
v2=horizon(h).v1
v3=horizon(h).v2
v4=0
c#=0
while c#=0
inc v4
while v4=v1 or v4=v2 or v4=v3
inc v4
endwhile
set vector3 1,points(v3).x-points(v1).x,points(v3).y-points(v1).y,points(v3).z-points(v1).z
set vector3 2,points(v2).x-points(v1).x,points(v2).y-points(v1).y,points(v2).z-points(v1).z
cross product vector3 1,1,2
c#=(points(v4).x-points(v1).x)*x vector3(1)+(points(v4).y-points(v1).y)*y vector3(1)+(points(v4).z-points(v1).z)*z vector3(1)
if c#<0
rem swap 2 points if it is facing the wrong way
temp=v3
v3=v2
v2=temp
endif
endwhile
array insert at bottom object_data(0)
object_data(array count(object_data(0))).v1=v1
object_data(array count(object_data(0))).v2=v2
object_data(array count(object_data(0))).v3=v3
next h
endif
next v
rem create the memblock
vertex_amount=(array count(object_data(0)) +1)* 3
make memblock 1,12+(vertex_amount)*fvf_size
write memblock dword 1,0,fvf_format
write memblock dword 1,4,fvf_size
write memblock dword 1,8,vertex_amount
for t=0 to array count(object_data(0))
write memblock float 1,12+fvf_size*(t*3),points(object_data(t).v1).x
write memblock float 1,12+fvf_size*(t*3)+4,points(object_data(t).v1).y
write memblock float 1,12+fvf_size*(t*3)+8,points(object_data(t).v1).z
write memblock float 1,12+fvf_size*(t*3+1),points(object_data(t).v2).x
write memblock float 1,12+fvf_size*(t*3+1)+4,points(object_data(t).v2).y
write memblock float 1,12+fvf_size*(t*3+1)+8,points(object_data(t).v2).z
write memblock float 1,12+fvf_size*(t*3+2),points(object_data(t).v3).x
write memblock float 1,12+fvf_size*(t*3+2)+4,points(object_data(t).v3).y
write memblock float 1,12+fvf_size*(t*3+2)+8,points(object_data(t).v3).z
next t
rem create the mesh
make mesh from memblock 1,1
rem create the object
make object obj_num,1,0
set object normals obj_num
delete mesh 1
delete memblock 1
endif
endfunction
rem new primitives:
function make_object_cube(obj_num,s#)
point_amount=8
position_point(1,-s#/2.0,-s#/2.0,-s#/2.0)
position_point(5,s#/2.0,-s#/2.0,-s#/2.0)
position_point(2,-s#/2.0,-s#/2.0,s#/2.0)
position_point(6,s#/2.0,-s#/2.0,s#/2.0)
position_point(7,-s#/2.0,s#/2.0,-s#/2.0)
position_point(3,s#/2.0,s#/2.0,-s#/2.0)
position_point(4,-s#/2.0,s#/2.0,s#/2.0)
position_point(8,s#/2.0,s#/2.0,s#/2.0)
create_convex_hull(obj_num)
endfunction
function make_object_box(obj_num,x#,y#,z#)
point_amount=8
position_point(1,-x#/2.0,-y#/2.0,-z#/2.0)
position_point(5,x#/2.0,-y#/2.0,-z#/2.0)
position_point(2,-x#/2.0,-y#/2.0,z#/2.0)
position_point(6,x#/2.0,-y#/2.0,z#/2.0)
position_point(7,-x#/2.0,y#/2.0,-z#/2.0)
position_point(3,x#/2.0,y#/2.0,-z#/2.0)
position_point(4,-x#/2.0,y#/2.0,z#/2.0)
position_point(8,x#/2.0,y#/2.0,z#/2.0)
create_convex_hull(obj_num)
endfunction
function make_object_pyramid(obj_num,x#,y#,z#,s)
point_amount=s+1
position_point(1,0,y#/2.0,0)
for i=1 to s
a#=(i-0.5)*360.0/s
position_point(i+1,sin(a#)*x#/2.0,-y#/2.0,cos(a#)*z#/2.0)
next i
create_convex_hull(obj_num)
endfunction
function make_object_square_pyramid(obj_num,s#)
point_amount=5
d#=s#*sqrt(2.0)
h#=sqrt(s#^2-0.25*d#^2)
position_point(1,0,h#/2.0,0)
position_point(2,-s#/2.0,-h#/2.0,-s#/2.0)
position_point(3,s#/2.0,-h#/2.0,-s#/2.0)
position_point(4,-s#/2.0,-h#/2.0,s#/2.0)
position_point(5,s#/2.0,-h#/2.0,s#/2.0)
create_convex_hull(obj_num)
endfunction
function make_object_cylinder(obj_num,d#,h#)
point_amount=40
for n=1 to 20
position_point(n*2-1,d#*sin((n-1)*360.0/20.0)*0.5,-h#/2.0,d#*cos((n-1)*360.0/20.0)*0.5)
position_point(n*2,d#*sin(n*360.0/20.0)*0.5,h#/2.0,d#*cos(n*360.0/20.0)*0.5)
next n
create_convex_hull(obj_num)
set object smoothing obj_num,40
endfunction
function make_object_elliptic_cylinder(obj_num,x#,y#,z#)
point_amount=40
for n=1 to 20
position_point(n*2-1,x#*sin((n-1)*360.0/20.0)*0.5,-y#/2.0,z#*cos((n-1)*360.0/20.0)*0.5)
position_point(n*2,x#*sin(n*360.0/20.0)*0.5,y#/2.0,z#*cos(n*360.0/20.0)*0.5)
next n
create_convex_hull(obj_num)
set object smoothing obj_num,40
endfunction
function make_object_sphere(obj_num,d#)
point_amount=20*9+2
p=0
inc p
position_point(p,0,-0.5*d#,0)
inc p
position_point(p,0,0.5*d#,0)
for y=1 to 9
for x=1 to 20
inc p
yang#=(x-1)*360.0/20.0
xang#=y*180.0/10.0-90.0
position_point(p,0.5*d#*sin(yang#)*cos(xang#),0.5*d#*sin(xang#),0.5*d#*cos(yang#)*cos(xang#))
next x
next y
create_convex_hull(obj_num)
set object smoothing obj_num,40
endfunction
function make_object_spheroid(obj_num,x#,y#,z#)
point_amount=20*9+2
p=0
inc p
position_point(p,0,-0.5*y#,0)
inc p
position_point(p,0,0.5*y#,0)
for y=1 to 9
for x=1 to 20
inc p
yang#=(x-1)*360.0/20.0
xang#=y*180.0/10.0-90.0
position_point(p,0.5*x#*sin(yang#)*cos(xang#),0.5*y#*sin(xang#),0.5*z#*cos(yang#)*cos(xang#))
next x
next y
create_convex_hull(obj_num)
set object smoothing obj_num,40
endfunction
function make_object_regular_tetrahedron(obj_num,r#)
point_amount=4
position_point(1,0,r#,0)
a#=acos(-1.0/3)-90
position_point(2,0,-r#*sin(a#),r#*cos(a#))
position_point(3,r#*cos(a#)*sin(120),-r#*sin(a#),r#*cos(a#)*cos(120))
position_point(4,r#*cos(a#)*sin(240),-r#*sin(a#),r#*cos(a#)*cos(240))
create_convex_hull(obj_num)
endfunction
function make_object_tetrahedron(obj_num,x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#,x4#,y4#,z4#)
point_amount=4
position_point(1,x1#,y1#,z1#)
position_point(2,x2#,y2#,z2#)
position_point(3,x3#,y3#,z3#)
position_point(4,x4#,y4#,z4#)
create_convex_hull(obj_num)
endfunction
function make_object_octahedron(obj_num,x#,y#,z#)
point_amount=6
position_point(1,0,y#/2.0,0)
position_point(2,0,-y#/2.0,0)
position_point(3,-x#/2.0,0,-z#/2.0)
position_point(4,x#/2.0,0,-z#/2.0)
position_point(5,-x#/2.0,0,z#/2.0)
position_point(6,x#/2.0,0,z#/2.0)
create_convex_hull(obj_num)
endfunction
function make_object_regular_octahedron(obj_num,s#)
point_amount=6
d#=s#*sqrt(2.0)
h#=sqrt(s#^2-0.25*d#^2)
position_point(1,0,h#,0)
position_point(2,0,-h#,0)
position_point(3,-s#/2.0,0,-s#/2.0)
position_point(4,s#/2.0,0,-s#/2.0)
position_point(5,-s#/2.0,0,s#/2.0)
position_point(6,s#/2.0,0,s#/2.0)
create_convex_hull(obj_num)
endfunction
function make_object_elliptic_capsule(obj_num,x#,y#,z#)
point_amount=20*10+2
p=0
inc p
d#=(x#+z#)/2.0
position_point(p,0,-0.5*y#-d#*0.5,0)
inc p
position_point(p,0,0.5*y#+d#*0.5,0)
for y=1 to 5
for x=1 to 20
inc p
yang#=(x-1)*360.0/20.0
xang#=y*180.0/10.0-90.0
h#=0.5*d#*sin(xang#)-y#/2.0
position_point(p,0.5*x#*sin(yang#)*cos(xang#),h#,0.5*z#*cos(yang#)*cos(xang#))
next x
next y
for y=1 to 5
for x=1 to 20
inc p
yang#=(x-1)*360.0/20.0
xang#=y*180.0/10.0
h#=0.5*d#*sin(xang#)+y#/2.0
position_point(p,0.5*x#*sin(yang#)*cos(xang#),h#,0.5*z#*cos(yang#)*cos(xang#))
next x
next y
create_convex_hull(obj_num)
set object smoothing obj_num,40
endfunction
function make_object_capsule(obj_num,d#,h#)
point_amount=20*10+2
p=0
inc p
position_point(p,0,-0.5*h#-d#*0.5,0)
inc p
position_point(p,0,0.5*h#+d#*0.5,0)
for y=1 to 5
for x=1 to 20
inc p
yang#=(x-1)*360.0/20.0
xang#=y*180.0/10.0-90.0
y#=0.5*d#*sin(xang#)-h#/2.0
position_point(p,0.5*d#*sin(yang#)*cos(xang#),y#,0.5*d#*cos(yang#)*cos(xang#))
next x
next y
for y=1 to 5
for x=1 to 20
inc p
yang#=(x-1)*360.0/20.0
xang#=y*180.0/10.0
y#=0.5*d#*sin(xang#)+h#/2.0
position_point(p,0.5*d#*sin(yang#)*cos(xang#),y#,0.5*d#*cos(yang#)*cos(xang#))
next x
next y
create_convex_hull(obj_num)
set object smoothing obj_num,40
endfunction
function make_object_elliptic_cone(obj_num,x#,y#,z#)
point_amount=21
position_point(1,0,y#/2.0,0)
for n=2 to 21
position_point(n,x#*sin(n*360.0/20.0)*0.5,-y#/2.0,z#*cos(n*360.0/20.0)*0.5)
next n
create_convex_hull(obj_num)
set object smoothing obj_num,40
endfunction
function make_object_cone(obj_num,d#,h#)
point_amount=21
position_point(1,0,h#/2.0,0)
for n=2 to 21
position_point(n,d#*sin(n*360.0/20.0)*0.5,-h#/2.0,d#*cos(n*360.0/20.0)*0.5)
next n
create_convex_hull(obj_num)
set object smoothing obj_num,40
endfunction
function make_object_chamfer_box(obj_num,x#,y#,z#,c#)
point_amount=24
position_point(1,-x#/2.0+c#,-y#/2.0+c#,-z#/2.0)
position_point(5,x#/2.0-c#,-y#/2.0+c#,-z#/2.0)
position_point(2,-x#/2.0+c#,-y#/2.0+c#,z#/2.0)
position_point(6,x#/2.0-c#,-y#/2.0+c#,z#/2.0)
position_point(7,-x#/2.0+c#,y#/2.0-c#,-z#/2.0)
position_point(3,x#/2.0-c#,y#/2.0-c#,-z#/2.0)
position_point(4,-x#/2.0+c#,y#/2.0-c#,z#/2.0)
position_point(8,x#/2.0-c#,y#/2.0-c#,z#/2.0)
position_point(9,-x#/2.0,-y#/2.0+c#,-z#/2.0+c#)
position_point(10,x#/2.0,-y#/2.0+c#,-z#/2.0+c#)
position_point(11,-x#/2.0,-y#/2.0+c#,z#/2.0-c#)
position_point(12,x#/2.0,-y#/2.0+c#,z#/2.0-c#)
position_point(13,-x#/2.0,y#/2.0-c#,-z#/2.0+c#)
position_point(14,x#/2.0,y#/2.0-c#,-z#/2.0+c#)
position_point(15,-x#/2.0,y#/2.0-c#,z#/2.0-c#)
position_point(16,x#/2.0,y#/2.0-c#,z#/2.0-c#)
position_point(17,-x#/2.0+c#,-y#/2.0,-z#/2.0+c#)
position_point(18,x#/2.0-c#,-y#/2.0,-z#/2.0+c#)
position_point(19,-x#/2.0+c#,-y#/2.0,z#/2.0-c#)
position_point(20,x#/2.0-c#,-y#/2.0,z#/2.0-c#)
position_point(21,-x#/2.0+c#,y#/2.0,-z#/2.0+c#)
position_point(22,x#/2.0-c#,y#/2.0,-z#/2.0+c#)
position_point(23,-x#/2.0+c#,y#/2.0,z#/2.0-c#)
position_point(24,x#/2.0-c#,y#/2.0,z#/2.0-c#)
create_convex_hull(obj_num)
endfunction
function make_object_chamfer_cube(obj_num,s#,c#)
point_amount=24
position_point(1,-s#/2.0+c#,-s#/2.0+c#,-s#/2.0)
position_point(5,s#/2.0-c#,-s#/2.0+c#,-s#/2.0)
position_point(2,-s#/2.0+c#,-s#/2.0+c#,s#/2.0)
position_point(6,s#/2.0-c#,-s#/2.0+c#,s#/2.0)
position_point(7,-s#/2.0+c#,s#/2.0-c#,-s#/2.0)
position_point(3,s#/2.0-c#,s#/2.0-c#,-s#/2.0)
position_point(4,-s#/2.0+c#,s#/2.0-c#,s#/2.0)
position_point(8,s#/2.0-c#,s#/2.0-c#,s#/2.0)
position_point(9,-s#/2.0,-s#/2.0+c#,-s#/2.0+c#)
position_point(10,s#/2.0,-s#/2.0+c#,-s#/2.0+c#)
position_point(11,-s#/2.0,-s#/2.0+c#,s#/2.0-c#)
position_point(12,s#/2.0,-s#/2.0+c#,s#/2.0-c#)
position_point(13,-s#/2.0,s#/2.0-c#,-s#/2.0+c#)
position_point(14,s#/2.0,s#/2.0-c#,-s#/2.0+c#)
position_point(15,-s#/2.0,s#/2.0-c#,s#/2.0-c#)
position_point(16,s#/2.0,s#/2.0-c#,s#/2.0-c#)
position_point(17,-s#/2.0+c#,-s#/2.0,-s#/2.0+c#)
position_point(18,s#/2.0-c#,-s#/2.0,-s#/2.0+c#)
position_point(19,-s#/2.0+c#,-s#/2.0,s#/2.0-c#)
position_point(20,s#/2.0-c#,-s#/2.0,s#/2.0-c#)
position_point(21,-s#/2.0+c#,s#/2.0,-s#/2.0+c#)
position_point(22,s#/2.0-c#,s#/2.0,-s#/2.0+c#)
position_point(23,-s#/2.0+c#,s#/2.0,s#/2.0-c#)
position_point(24,s#/2.0-c#,s#/2.0,s#/2.0-c#)
create_convex_hull(obj_num)
endfunction