ok so the first of new object commands...
i've set this up to mimic vertex data commands from darkbasic pro and also ian's matrix utils
(yes you can now make a new object from scratch using this in agk!)
new commands for agk:
-initialize_objectsinclude()..preps the array data for first usage
-makenewobject(vertexcount,indexcount)
-setvertexdataposition(vertex,x#,y#,z#)
-setvertexdatauv(vertex,u#,v#,w#)
-setvertexdatanormals(vertex,x#,y#,z#)
-setindexdata(index,vertex)
-savenewobject(object_number,filename$,flag1,flag2)
(the last command has the option of loading the new object in at the object_number specified)
include_file...
function initialize_objectsinclude()
dim edit_object1#[2,8]
dim edit_object2[2]
global max_vertexcount=0
global max_indexcount=0
endfunction
function makenewobject(vertex_cnt,index_cnt)
if vertex_cnt-1<2 then exitfunction -1
if index_cnt-1<2 then exitfunction -1
dim edit_object1#[vertex_cnt-1,8]
dim edit_object2[index_cnt-1]
max_vertexcount=vertex_cnt-1
max_indexcount=index_cnt-1
endfunction 1
function setvertexdataposition(vertex,x#,y#,z#)
if vertex>max_vertexcount then exitfunction -1
if vertex<0 then exitfunction -1
edit_object1#[vertex,0]=x#
edit_object1#[vertex,1]=y#
edit_object1#[vertex,2]=z#
endfunction 1
function setvertexdatanormals(vertex,x#,y#,z#)
if vertex>max_vertexcount then exitfunction -1
if vertex<0 then exitfunction -1
edit_object1#[vertex,3]=x#
edit_object1#[vertex,4]=y#
edit_object1#[vertex,5]=z#
endfunction 1
function setvertexdatauv(vertex,u#,v#,w#)
if vertex>max_vertexcount then exitfunction -1
if vertex<0 then exitfunction -1
edit_object1#[vertex,6]=u#
edit_object1#[vertex,7]=v#
edit_object1#[vertex,8]=w#
endfunction 1
function setindexdata(index,v1)
if index<0 then exitfunction -1
if index>max_indexcount then exitfunction -1
if v1<0 then exitfunction -1
if v1>max_vertexcount then exitfunction -1
edit_object2[index]=v1
endfunction 1
function savenewobject(object_number,filename$,flag1,flag2)
//flag1 1 = overwrite existing file
//flag1 <>0 = fail if file exists
//flag2 load it in after saving it =1
if getfileexists(filename$)=1 and flag1<>1 then exitfunction -1
if max_vertexcount<2 then exitfunction -1
if max_indexcount<2 then exitfunction -1
//ok lets write the file
if getfileexists(filename$)=1 then deletefile(filename$)
opentowrite(1,filename$)
writeline(1,"# obj file format")
writeline(1,"# "+str(max_vertexcount+1)+" vertex positions" )
for v=0 to max_vertexcount step 1
writeline(1,"v "+str(edit_object1#[v,0])+" "+str(edit_object1#[v,1])+" "+str(edit_object1#[v,2]))
next v
writeline(1,"# "+str(max_vertexcount+1)+" uv coordinates" )
for v=0 to max_vertexcount step 1
writeline(1,"vt "+str(edit_object1#[v,6])+" "+str(edit_object1#[v,7])+" "+str(edit_object1#[v,8]))
next v
writeline(1,"# "+str(max_vertexcount+1)+" vertex normals" )
for v=0 to max_vertexcount step 1
writeline(1,"vn "+str(edit_object1#[v,3])+" "+str(edit_object1#[v,4])+" "+str(edit_object1#[v,5]))
next v
ind_count=(max_indexcount+1)/3
writeline(1,"# Mesh 'object_name' with "+str(ind_count)+" faces" )
writeline(1,"# " ) // normally would specify material name but agk ignores this
writeline(1,"g object_name")
for i=0 to max_indexcount step 3
index1=edit_object2[i]+1
index2=edit_object2[i+1]+1
index3=edit_object2[i+2]+1
writeline(1,"f "+str(index1)+"/"+str(index1)+"/"+str(index1)+" "+str(index2)+"/"+str(index2)+"/"+str(index2)+" "+str(index3)+"/"+str(index3)+"/"+str(index3))
next i
writeline(1,"# thats it ")
//message("saved something?")
closefile(1)
if flag2=1
if getobjectexists(object_number)=1 then deleteobject(object_number)
loadobject(object_number,filename$)
endif
endfunction 1
here is an example of its usage
#include "objects_include.agc"
//this sets up the arrays
initialize_objectsinclude()
//test new functions
ok=makenewobject(4,6) //this reports 1 if successful (vertex count,index count)
//setting data
//vertex data positions
ok=setvertexdataposition(0,-50,50,0)
ok=setvertexdataposition(1,50,50,0)
ok=setvertexdataposition(2,50,-50,0)
ok=setvertexdataposition(3,-50,-50,0)
//vertex data normals
ok=setvertexdatanormals(0,0,0,0)
ok=setvertexdatanormals(1,0,0,0)
ok=setvertexdatanormals(2,0,0,0)
ok=setvertexdatanormals(3,0,0,0)
//vertex data uv
ok=setvertexdatauv(0,0,1,0)
ok=setvertexdatauv(1,1,1,0)
ok=setvertexdatauv(2,1,0,0)
ok=setvertexdatauv(3,0,0,0)
//vertex indexes (faces)
ok=setindexdata(0,0)
ok=setindexdata(1,1)
ok=setindexdata(2,2)
ok=setindexdata(3,0)
ok=setindexdata(4,2)
ok=setindexdata(5,3)
//now to save and load the object
ok=savenewobject(1,"test_square.obj",1,1) //(obj_number, filename$, overwritefile if exists?,load it in after?)
//setobjectimage(1,1,0) //if you load an image it is uvwrapped
setcamerarange(1,1,5000)
do
setobjectrotation(1,0,getobjectangley(1)+2,0)
setcameraposition(1,0,0,400)
setcameralookat(1,0,0,0,0)
Sync()
loop
questions... requests... let me know as im trying to add as much new 3d stuff as I can using code.
any raw shapes you would like to see as single commands...eg make triangle... ill add it in if ya wish
requests now open