In face, it could be useable to build anything, not just spaceships. It was my first idea, so I added symmetry to make it easier to produce spaceships - that normally have symmetrical geometry - but yes, I know it has potential to do anything.
Sad CSG doesn't work with spheres, cylinders or cones, because with them I could produce better results.
I am thinking about using it to produce a set of "pieces" - like LEGO blocks - and add them to be useable by the program itself to further objects, since boxes are not very versatile for making complex structures.
The part of removing identical faces is beyond my actual skills. I am still scratching the surface of vertexdata stuff...
This is something that someone with a deeper knowledge could put into a plugin to make it easy - a snippet would be good, but a dll would be far better.
It would be great to just call a REMOVE REDUNDANT FACES(object number) and see it done without being bothered by the technical stuff.
Another dodgy part of it is that the UV data is impossible (for me, at least) to manipulate properly. The idea was that the final object could behave as a sphere (with the texture being seamlessly wrapped around it), but all I've got are boxes and pieces of boxes. And, since it is just a helping app to make objects for my simple games, I will probably never try to learn UV data manipulation to fix it in the way I want to.
Ah, you'll probably laugh on that: I found why did my vertex count was so high! Well, always when I performed a CSG union or difference, I didn't delete the objects and, since the keypresses were longer than the time required to perform the operation, it was performed various times in the same object, producing really high vertex counts and - due a bug in rotation - some bizarre results sometimes. I solved it just deleting the objects after the union and resetting the brush data to zero, telling the software that there was nothing to be merged with the object and this reduced vertex count dramatically.
This is the current version, a bit better than the previous one.
SET DISPLAY MODE DESKTOP WIDTH(),DESKTOP HEIGHT(),32
MAXIMIZE WINDOW
SET WINDOW LAYOUT 0,0,0
color backdrop 0
global parts as integer // for me to know how many pieces there are indexed
GLOBAL VCOUNT AS INTEGER
parts = 20
type curs
x as integer
y as integer
z as integer
brush as integer
roll as integer
turn as integer
pitch as integer
zoom as integer
cam as integer
endtype
global precision as float
cursor as curs //makes the cursor that will be used to position stuff
sync on : sync rate 15
//MODEL BUILDER
//no media required
//Creates and saves 3D models
//
//using CSG construction
//builds the grid texture for the background
cls
for x = 0 to 100 step 10
line 0,x,100,x,rgb(0,0,155)
line x,0,x,100,rgb(0,0,155)
Next
get image 1,0,0,100,100,1
cls rgb(255,255,255)
box 1,1,19,19,rgb(0,0,0)
get image 2,0,0,20,20,1
make_parts()
make object cube 1,-250
texture object 1,1
set object transparency 1,1
set object light 1,0
set object fog 1,0
color backdrop 0
autocam off
set text size 50
SET AMBIENT LIGHT 255
make object cube 2,5
texture object 2,2
do
move_cursor()
create_part(cursor.brush)
apply_parts()
cam_control()
symmetry()
save_object()
sync
Loop
function move_cursor()
if inkey$() = "1" then precision = 0.2
if inkey$() = "2" then precision = 0.5
if inkey$() = "3" then precision = 1
if inkey$() = "4" then precision = 1.5
if inkey$() = "5" then precision = 2
if controlkey() = 0 and shiftkey() = 0
if upkey() = 1 then inc cursor.y,5*precision
if downkey() = 1 then dec cursor.y,5*precision
if leftkey() = 1 then dec cursor.x,5*precision
if rightkey()= 1 then inc cursor.x,5*precision
endif
if controlkey() = 0 and shiftkey() = 1
if upkey() = 1 then inc cursor.z,5*precision
if downkey() = 1 then dec cursor.z,5*precision
if leftkey() = 1 then dec cursor.roll,15
if rightkey()= 1 then inc cursor.roll,15
endif
if controlkey() = 1 and shiftkey() = 0
if upkey() = 1 then inc cursor.pitch,15
if downkey() = 1 then dec cursor.pitch,15
if leftkey() = 1 then dec cursor.turn,15
if rightkey()= 1 then inc cursor.turn,15
endif
if controlkey() = 1 and shiftkey() = 1
if upkey() = 1 then inc cursor.zoom,5
if downkey() = 1 then dec cursor.zoom,5
if leftkey() = 1 then dec cursor.cam,5
if rightkey()= 1 then inc cursor.cam,5
endif
if spacekey() = 1
cursor.x = 0
cursor.y = 0
cursor.z = 0
cursor.turn = 0
cursor.pitch = 0
cursor.roll = 0
Endif
cursor.x = crop(cursor.x,-100,100)
cursor.y = crop(cursor.y,-100,100)
cursor.z = crop(cursor.z,-100,100)
cursor.turn = crop(cursor.turn,-90,90)
cursor.roll = crop(cursor.roll,-90,90)
cursor.pitch = crop(cursor.pitch,-90,90)
cursor.brush = cycle(cursor.brush,1,parts)
cursor.zoom = crop(cursor.zoom,20,100)
cursor.cam = crop(cursor.cam,-180,180)
Endfunction
function crop(v,f,t)
if v < f then v = f
if v > t then v = t
Endfunction v
function cam_control()
x = sin(cursor.cam)*cursor.zoom + cursor.x
z = cos(cursor.cam) * cursor.zoom + cursor.z
position camera 0,x,cursor.y+cursor.zoom,z
point camera 0,cursor.x,cursor.y,cursor.z
show_text()
Endfunction
function show_text()
text 0,0,"X:"+str$(cursor.x)
text 0,50,"Y:"+str$(cursor.y)
text 0,100,"Z:"+str$(cursor.z)
IF VCOUNT > 30000 THEN INK RGB(255,0,0) ELSE INK RGB(0,255,0)
TEXT 0,150,"Vertex:"+STR$(VCOUNT)
INK RGB(255,255,255)
text 0,200,"Prec:"+str$(precision)
Endfunction
function make_parts()
dim part(parts) as integer
for p = 1 to parts
part(p) = p + 10
Next
make object box part(1),10,5,10
make object box part(2),10,10,10
make object box part(3),15,5,10
make object box part(4),10,10,20
make object box part(5),20,10,20
make object box part(6),5,10,20
make object box part(7),10,1,10
make object box part(8),20,1,5
make object box part(9),5,5,5
make object box part(10),1,10,1
make object box part(11),20,1,15
make object box part(12),10,10,20
make object box part(13),20,10,20
make object box part(14),3,3,15
make object box part(15),8,8,8
make object box part(16),12,5,12
make object box part(17),20,2,2
make object box part(18),1,25,15
make object box part(19),4,4,10
make object box part(20),15,10,7
for p = 1 to parts
set object light part(p),0
set object filter part(p),0
set object cull part(p),1
hide object part(p)
Next
Endfunction
function create_part(b)
if returnkey() = 1 and controlkey() = 0 and b > 0
if object exist(3) = 1 and object exist(4) = 1
delete objects 3,4
inc cursor.brush,1
endif
clone object 3,part(b) : texture object 3,2
clone object 4,part(b) : texture object 4,2
Endif
endfunction
function symmetry()
if object exist(3) = 1 and object exist(4) = 1
position object 3,-cursor.x,cursor.y,cursor.z
position object 4,cursor.x,cursor.y,cursor.z
rotate object 3,cursor.pitch,cursor.turn,cursor.roll
rotate object 4,cursor.pitch,-cursor.turn,-cursor.roll
Endif
Endfunction
function apply_parts()
if controlkey() = 1 and returnkey() = 1 and object exist(3) = 1 and object exist(4) = 1
if shiftkey() = 0
e = equal()
perform csg union 2,3
if e = 0 then perform csg union 2,4
flush video memory
endif
if shiftkey() = 1
perform csg difference 2,3
if e = 0 then perform csg difference 2,4
flush video memory
endif
delete object 3
delete object 4
cursor.brush = 0
GET_VERTEX()
Endif
Endfunction
function cycle(v,f,t)
//works like WRAP of matrix1utils, but since not everyone has it, i made my own
if v > t then v = f
if v < f then v = t
Endfunction v
function save_object()
if shiftkey() = 1 and spacekey() = 1
if object exist(3) = 1 and object exist(4) = 1 then delete objects 3,4
lock object on 2
position object 2,0,0,50
repeat
turn object left 2,1
sync
Until returnkey() = 1
repeat
cls 0
input "Nome do arquivo:",file$
until file exist(file$+".dbo") = 0
save object file$+".dbo",2
delete object 2
make object cube 2,5
texture object 2,2
Endif
Endfunction
FUNCTION GET_vertex()
MAKE MESH FROM OBJECT 2,2
DELETE OBJECT 2
LOCK VERTEXDATA FOR MESH 2
VCOUNT = GET VERTEXDATA VERTEX COUNT()
UNLOCK VERTEXDATA
MAKE OBJECT 2,2
DELETE MESH 2
TEXTURE OBJECT 2,2
Endfunction
function equal()
ax1 = object angle x(3) : ax2 = object angle x(4)
ay1 = object angle y(3) : ay2 = object angle y(4)
az1 = object angle z(3) : az2 = object angle z(4)
x1=object position x(3)
y1=object position y(3)
z1=object position z(3)
x2=object position x(4)
y2=object position y(4)
z2=object position z(4)
if x1 = x2 and y1 = y2 and z1 = z2 and ax1 = ax2 and ay1 = ay2 and az1 = az2 then e = 1 else e = 0
Endfunction e
By the way, can anyone tell me why it is not compiling properly (no EXE created) but works fine in debug mode?
[size=+2]Forever and one[/size]