I have written some new function comands that will help people create 3d animations and limbed characters.
These comands will work with agk v1 and v2.
comand list: so far... not in any order
Index List:
-initialize_objects() This is used to initialize the arrays needed.
In this function you can adjust how many objects you would like to use
for animation and its default is set to 100.
-setobjectspeed(object,value#) This command can be called to modify playback speed. The range of
playback speed is between 0.00 to 1.0 being 100%. If the object was
not playing to start with then it will be un effected by this command.
-moveobjectx(object,value#) This command replaces the command to moveobjectlocalx. This new command
will move local x and effect the limbs connected to it. This command does
not refresh the drawing of the model and only adjusts the array data.
...see updateobject(object,limb count) to refresh the drawing.
-moveobjecty(object,value#) This command replaces the command to moveobjectlocaly. This new command
will move local y and effect the limbs connected to it. This command does
not refresh the drawing of the model and only adjusts the array data.
...see updateobject(object,limb count) to refresh the drawing.
-moveobjectz(object,value#) This command replaces the command to moveobjectlocalz. This new command
will move local z and effect the limbs connected to it. This command does
not refresh the drawing of the model and only adjusts the array data.
...see updateobject(object,limb count) to refresh the drawing.
-loadobject2(object,filename$,texture$) This command loads a raw .obj file into the array system to be used to create
a limbed object. Once the object is linked together and animation frames set, it
can be saved as a new model file that will load in with a single command.
Use an object number within the array size or this command will fail. The array
size is set within the function initialize_objects() under max_objects=100 etc...
Once an object has been linked and created you may delete the original solid shape.
-setobjecttexturefilename(object,limb,file$) If you didnt use loadobject2 to load your solid shapes in you can
use this command to set the texture filename for a specific limb.
-setobjectmeshfilename(object,limb,file$) If you didnt use loadobject2 to load your solid shapes in you can
use this command to set the solid shape filename for a specific limb.
-positionobject(object,limb,x#,y#,z#) This command replaces setobjectposition. limb 0-20 max if applicable and this
command only updates the arrays.
...see updateobject(object,limb count) to refresh the drawing.
-linklimb(object1,child,parent) After adding limbs to an object you can link them together. Limbs are numbered 0-20
zero is the base of the object. By default all limbs added are linked to limb 0.
I recomend adding limb linkage in order so the computer does not need to run several
cycles just to draw the object correctly. An example of this would be:
-limb 0 = waist
-limb 1 = body
-limb 2 = neck
-limb 3 = head
-limb 4 = upper left arm
-limb 5 = lower left arm
-limb 6 = left hand
-etc
if linkage is in order like this the computer will only need to cycle through the code
once per object. If you switched the order of your arm linkage even once will cause the computer
to cycle through all the limbs again to make sure it draws it correctly. Failing to do this
will cause un nessesary frame drops in your game / application and is easy to prevent.
-getlimbcount(object) This command counts the total limbs currently added to an object.
-wrapvalue(angle#) This was a nice 360 deg wrap code standard with darkbasic. It works well with agk but do not use
for angle X as it only can handle -89 to 89 deg i think?? Correct me in the forums if im wrong.
-getlimbanglex(object,limb) This command will return the base pose angle of the specified object limb.
limb 0 is for the base object.
-getlimbangley(object,limb) This command will return the base pose angle of the specified object limb.
limb 0 is for the base object.
-getlimbanglez(object,limb) This command will return the base pose angle of the specified object limb.
limb 0 is for the base object.
-getlimbrotationx(object,limb) This command will return the exact angle of a current object limb even if its playing an animation.
Limb 0 is for the base of the object which is not modified with animation frames.
-getlimbrotationy(object,limb) This command will return the exact angle of a current object limb even if its playing an animation.
Limb 0 is for the base of the object which is not modified with animation frames.
-getlimbrotationz(object,limb) This command will return the exact angle of a current object limb even if its playing an animation.
Limb 0 is for the base of the object which is not modified with animation frames.
-getlimbpositionx(object,limb) This command will return the exact position of a current object limb even if its playing an animation.
Again Limb 0 is the base of the object.
-getlimbpositiony(object,limb) This command will return the exact position of a current object limb even if its playing an animation.
Again Limb 0 is the base of the object.
-getlimbpositionz(object,limb) This command will return the exact position of a current object limb even if its playing an animation.
Again Limb 0 is the base of the object.
-updateobject(object,limb count) You will need to use this command to refresh the object before you sync the screen. If you have multiple
objects that should be drawn to screen then they should all be updated at least once before syncing.
if you do not specify limb count you will cause the computer to cycle through all 20 possible limbs even
if your object does not have them. Make sure this command is called at least once before you start to
run animations so that the limb count is set correctly. This command should only be called once per sync.
-addlimb(object to add,object) Use this command to add a limb to an object. The limbs link in order so if this was the first call, all
modifications for that limb would be to limb # 1. As you add limbs together the limb count goes in order.
-setlimbkeyposition(object,limb,x#,y#,z#,key_frame) This command sets a keyframe position for animations. If you modify keyframe 0 then you
are modifying the base pose for all the animation sequences to follow. Key frames can
be set from 0 to 30 and do not use 31,32 or 33 as those are used to perform transitions.
-setlimbkeyrotation(object,limb,x#,y#,z#,key_frame) Use this command to set rotation animations. Key frame ranges from 0-30. zero is for the
base pose of an object. keyframed rotations from 1-30 do not use 360deg. Instead they use
integers that range as far as you like. If I was to rotate around the y axis -640.0 then the
object would rotate left twice in between the transition frame set. The base of this rotation
would be found on the base pose.
-example:
-keyframe 0 = 45 deg (base pose)
-keyframe 1 = -45 (this would rotate the limb to 0 deg)
-keyframe 2 = -90 (this would rotate the limb to -315 deg)
-keyframe 3 = 0 (this would rotate the limb back to 45 deg)
-playobject(object,startkey,endkey,continous,speed#,limbcount) This command plays back an animation sequence. Make sure you have the correct
limb count so it draws all the limbs correctly when it does the update.
speed# is in the range of 0.000 to 1.000
startkey of your animation to the endkey of your animation. Both start and end
keys should have the same keyframe data for smooth animation looping if desired.
...see updateobject(object,limb count) to refresh the drawing as this command only
updates the arrays.
-setobjectframe(object,frame#) This command will alter an objects current animation frame to show what you wanted. If you had an animation
running this may not be the command your looking for. I would call this command only if you have stopped the
object from playing.
-runanimationtransition(object,startframe,endframe,continous,speed#,limbcount) Use this command to change the animation sequence smoothly. If you do
not want it to start looping the new animation set the continous flag to 0
-getobjectplaying(object1) This command will return 1 if the object is playing animation.
-getobjectframe#(object1) Will return the current frame its displaying.
-getobjectspeed#(object1) This will return the current set animation playback speed.
-stopobject(object1) What it says it does. Any animation will stop playing with that object.
-cloneanimatedobject(source,destination) If you have a object with limbs animated....you can clone it as long as the new object is in the array
bounds.
-deleteanimatedobject(object) Use to delete the array data and any limbs associated with the object to remove it from memory. Do not use deleteobject
as it will not delete the array data nor will it delete the limbs.
-instanceanimatedobject(source,destination) This is like clone except it shares the same memory. If you delete the original animated object without
deleting an instanced animated object, your app/ game will crash. So be carefull!
-hideobject(object) This hides the object and its limbs.
-hidelimb(object,limb) This command will just hide a limb object.
-showobject(object) This command will show the object and its limbs.
-showlimb(object,limb) This command will show the limb object.
-makenewobject(vertex_cnt,index_cnt) Use this command to make a new object from scratch. Indexes must be divisible by 3.
-setvertexdataposition(vertex,x#,y#,z#) Used to set vertex data for the creation of new 3d models.
-setvertexdatanormals(vertex,x#,y#,z#) Used to set vertex normals.
-setvertexdatauv(vertex,u#,v#,w#) Used to set vertex texture alignment. U# is the horizontal plane from 0.0 to 1.0.
V# is the vertical plane from 0.0 to 1.0. I have no clew what the w# is used for...
-setindexdata(index,v1) Used to set index data for the creation of 3d faces.
-savenewobject(object_number,filename$,flag1,flag2) Saves a new model from the vertex array data you have entered in. object number is used if
you would like to load the file in after saving it. Flag1 is to overwrite existing filename if
it exists. Flag 2 is if you would like to load it in after saving it.
-loadobj(object1,filename$) This command loads the object in and also loads it into the vertex array for editting.
-adjustobjectpivotpoint(object1,filename$,x#,y#,z#) This command loads the object in and adjusts pivot point. Then it saves over original file and
loads it back in.
-saveanimatedmodel(object1,filenameb$,flag) This is one of the best commands here. Once you have loaded and linked your object with limbs, animated it,
then you can save the whole dang thing as 1 file excluding the textures. The textures will need to be found
in a simular directory for them to load again. eg if i had them in media folder.... this is where the plugin will
look for them.
-loadanimatedmodel(object1,filename$,flag) This loads a saved animated model with one command. You could go into this command and edit it if you would
like to be able to edit the file and save it again. For now its just ment to load in a finished model.
request this from me if thats something you want.
-getdistance#(x1#,y1#,z1#,x2#,y2#,z2#) This great command reports the distance between 2 3d points in space.
i will post more examples soon...
here is the source example using animation
http://www.smotion3d.com/downloads/objexample1.zip
source code file objects_include.agc
//this is the latest include file available for download
//save it as objects_include.agc or whatever you want
//
//Version 1.0 July 28,2014
//
//modify this code freely
//
function initialize_objects()
dim edit_object1#[2,8]
dim edit_object2[2]
global max_vertexcount=0
global max_indexcount=0
//animation stuff
//change this value if you need more
global max_objects=100
//dont change limb amnt at this time!!
global max_limbs=20
global max_keyframes=33
global limb_start_obj=10000
dim object_buffer#[max_objects,max_limbs,6,max_keyframes]
dim transition#[max_objects,5]
dim object_filenames$[max_objects,max_limbs,1]
//0=filename for obj, 1 is texturename
dim refresh_object[20]
dim objects_playing#[max_objects,6]
dim count_data[20,4]
endfunction
function setobjectspeed(object1,value#)
objects_playing#[object1,4]=value#
endfunction
function moveobjectz(object1,value#)
moveobjectlocalz(object1,value#)
x#=getobjectx(object1)
y#=getobjecty(object1)
z#=getobjectz(object1)
positionobject(object1,0,x#,y#,z#)
endfunction
function moveobjectx(object1,value#)
moveobjectlocalx(object1,value#)
x#=getobjectx(object1)
y#=getobjecty(object1)
z#=getobjectz(object1)
positionobject(object1,0,x#,y#,z#)
endfunction
function moveobjecty(object1,value#)
moveobjectlocaly(object1,value#)
x#=getobjectx(object1)
y#=getobjecty(object1)
z#=getobjectz(object1)
positionobject(object1,0,x#,y#,z#)
endfunction
function setobjectmeshfilename(object1,limb1,file$)
if object1<1 then exitfunction
if object1>max_objects then exitfunction
if limb1<0 then exitfunction
if limb1>max_limbs then exitfunction
object_filenames$[object1,limb1,0]=file$
endfunction
function loadobject2(object1,filename$,texture$)
//load it and store source filename
if object1<1 then exitfunction
if object1>max_objects then exitfunction
if getfileexists(filename$)=0 then exitfunction
loadobject(object1,filename$)
if texture$="" then texture$="NULL"
if getfileexists(texture$)=0 then texture$="NULL"
object_filenames$[object1,0,0]=filename$
object_filenames$[object1,0,1]=texture$
if getfileexists(texture$)=1
//load it and apply it
//limb_start_obj+(object1*20)
limb=0
if getimageexists(limb_start_obj+(object1*20)+limb)=1 then deleteimage(limb_start_obj+(object1*20)+limb)
loadimage(limb_start_obj+(object1*20)+limb,texture$,1)
setobjectimage(object1,limb_start_obj+(object1*20)+limb,0)
endif
endfunction
function setobjecttexturefilename(object1,limb1,file$)
if object1<1 then exitfunction
if object1>max_objects then exitfunction
if limb1<0 then exitfunction
if limb1>max_limbs then exitfunction
object_filenames$[object1,limb1,1]=file$
endfunction
function positionobject(object1,lmb,x#,y#,z#)
if object1<0 or object1>max_objects then exitfunction
if getobjectexists(object1)=0 then exitfunction
object_buffer#[object1,lmb,1,0]=x#
object_buffer#[object1,lmb,2,0]=y#
object_buffer#[object1,lmb,3,0]=z#
//update_limbs(object1,20)
endfunction
function linklimb(object1,child,parent)
if getobjectexists(object1)=0 then exitfunction
if getobjectexists(limb_start_obj+(object1*20)+parent)=0 then exitfunction
if getobjectexists(limb_start_obj+(object1*20)+child)=0 then exitfunction
object_buffer#[object1,child,0,0]=parent
endfunction
function getlimbcount(object1)
cnt=0
for limb=1 to 20 step 1
if getobjectexists(limb_start_obj+(object1*20)+limb)=1 then cnt=cnt+1
next limb
endfunction cnt
function wrapvalue(a#)
while a#<0 or a#>360
if a#<0 then a#=a#+360
if a#>360 then a#=a#-360
endwhile
endfunction a#
function wrapvaluex(a#)
//while a#<-90 or a#>90
if a#<-88 then a#=-88
if a#>88 then a#=88
//endwhile
//no actual wrap just limits
endfunction a#
function rotateobject(object1,lmb,x#,y#,z#)
if object1<0 or object1>max_objects then exitfunction
if getobjectexists(object1)=0 then exitfunction
if x#>88 then x#=88
if x#<-88 then x#=-88
y#=wrapvalue(y#)
z#=wrapvalue(z#)
object_buffer#[object1,lmb,4,0]=x#
object_buffer#[object1,lmb,5,0]=y#
object_buffer#[object1,lmb,6,0]=z#
//update_limbs(object1,20)
endfunction
function getlimbangley(object1,limb)
if object1<1 then exitfunction 0.0
if object1>max_objects then exitfunction 0.0
if limb<0 then exitfunction 0.0
if limb>20 then exitfunction 0.0
ret#=object_buffer#[object1,limb,5,0]
endfunction ret#
function getlimbanglex(object1,limb)
if object1<1 then exitfunction 0.0
if object1>max_objects then exitfunction 0.0
if limb<0 then exitfunction 0.0
if limb>20 then exitfunction 0.0
ret#=object_buffer#[object1,limb,4,0]
endfunction ret#
function getlimbanglez(object1,limb)
if object1<1 then exitfunction 0.0
if object1>max_objects then exitfunction 0.0
if limb<0 then exitfunction 0.0
if limb>20 then exitfunction 0.0
ret#=object_buffer#[object1,limb,6,0]
endfunction ret#
function getlimbrotationy(object1,limb)
if object1<1 then exitfunction 0.0
if object1>max_objects then exitfunction 0.0
if limb<0 then exitfunction 0.0
if limb>20 then exitfunction 0.0
obj=limb_start_obj+(object1*20)+limb
ret#=getobjectangley(obj)
endfunction ret#
function getlimbrotationx(object1,limb)
if object1<1 then exitfunction 0.0
if object1>max_objects then exitfunction 0.0
if limb<0 then exitfunction 0.0
if limb>20 then exitfunction 0.0
obj=limb_start_obj+(object1*20)+limb
ret#=getobjectanglex(obj)
endfunction ret#
function getlimbrotationz(object1,limb)
if object1<1 then exitfunction 0.0
if object1>max_objects then exitfunction 0.0
if limb<0 then exitfunction 0.0
if limb>20 then exitfunction 0.0
obj=limb_start_obj+(object1*20)+limb
ret#=getobjectanglez(obj)
endfunction ret#
function getlimbpositionx(object1,limb)
obj=limb_start_obj+(object1*20)+limb
ret#=getobjectx(obj)
endfunction ret#
function getlimbpositiony(object1,limb)
obj=limb_start_obj+(object1*20)+limb
ret#=getobjecty(obj)
endfunction ret#
function getlimbpositionz(object1,limb)
obj=limb_start_obj+(object1*20)+limb
ret#=getobjectz(obj)
endfunction ret#
function updateobject(object1,limbcount)
if object1<1 or object1>max_objects then exitfunction
if getobjectexists(object1)=0 then exitfunction
key_frame#=transition#[object1,5]
setobjectposition(object1,object_buffer#[object1,0,1,0],object_buffer#[object1,0,2,0],object_buffer#[object1,0,3,0])
setobjectrotation(object1,object_buffer#[object1,0,4,0],object_buffer#[object1,0,5,0],object_buffer#[object1,0,6,0])
//limb 0 should have no anim data!!
refresh_object[0]=1
rfobject=0
runthrough=0
while rfobject<limbcount
for limb=1 to limbcount step 1
if runthrough=0
refresh_object[limb]=0
if getobjectexists(limb_start_obj+(object1*20)+limb)=0
refresh_object[limb]=1
rfobject=rfobject+1
endif
endif
if refresh_object[limb]=0
parent=object_buffer#[object1,limb,0,0]
p_updated=refresh_object[parent]
if p_updated=1 or parent=0
c_obj=limb_start_obj+(object1*20)+limb
refresh_object[limb]=1
p_obj=limb_start_obj+(object1*20)+parent
if parent=0 then p_obj=object1
setobjectposition(c_obj,getobjectx(p_obj),getobjecty(p_obj),getobjectz(p_obj))
setobjectrotation(c_obj,getobjectanglex(p_obj),getobjectangley(p_obj),getobjectanglez(p_obj))
//transition code here
baseframe#=object_buffer#[object1,limb,1,0]
frame1=trunc(key_frame#)
frame2=trunc(key_frame#)+1
transition#=key_frame#-trunc(key_frame#)
if frame1=0 then x1#=object_buffer#[object1,limb,1,0]
if frame1>0 then x1#=object_buffer#[object1,limb,1,0]+object_buffer#[object1,limb,1,frame1]
x2#=object_buffer#[object1,limb,1,0]+object_buffer#[object1,limb,1,frame2]
lengthx#=x2#-x1#
xdraw#=x1#+(lengthx#*transition#)
if frame1=0 then y1#=object_buffer#[object1,limb,2,0]
if frame1>0 then y1#=object_buffer#[object1,limb,2,0]+object_buffer#[object1,limb,2,frame1]
y2#=object_buffer#[object1,limb,2,0]+object_buffer#[object1,limb,2,frame2]
lengthy#=y2#-y1#
ydraw#=y1#+(lengthy#*transition#)
if frame1=0 then z1#=object_buffer#[object1,limb,3,0]
if frame1>0 then z1#=object_buffer#[object1,limb,3,0]+object_buffer#[object1,limb,3,frame1]
z2#=object_buffer#[object1,limb,3,0]+object_buffer#[object1,limb,3,frame2]
lengthz#=z2#-z1#
zdraw#=z1#+(lengthz#*transition#)
moveobjectlocalx(c_obj,xdraw#)
moveobjectlocaly(c_obj,ydraw#)
moveobjectlocalz(c_obj,zdraw#)
if frame1=0 then ax1#=object_buffer#[object1,limb,4,0]
if frame1>0 then ax1#=wrapvaluex(object_buffer#[object1,limb,4,0]+object_buffer#[object1,limb,4,frame1])
ax2#=wrapvaluex(object_buffer#[object1,limb,4,0]+object_buffer#[object1,limb,4,frame2])
lengthax#=ax2#-ax1#
axdraw#=wrapvaluex(ax1#+(lengthax#*transition#))
if frame1=0 then ay1#=object_buffer#[object1,limb,5,0]
if frame1>0 then ay1#=object_buffer#[object1,limb,5,0]+object_buffer#[object1,limb,5,frame1]
ay2#=object_buffer#[object1,limb,5,0]+object_buffer#[object1,limb,5,frame2]
lengthay#=ay2#-ay1#
aydraw#=wrapvalue(ay1#+(lengthay#*transition#))
if frame1=0 then az1#=object_buffer#[object1,limb,6,0]
if frame1>0 then az1#=object_buffer#[object1,limb,6,0]+object_buffer#[object1,limb,6,frame1]
az2#=object_buffer#[object1,limb,6,0]+object_buffer#[object1,limb,6,frame2]
lengthaz#=az2#-az1#
azdraw#=wrapvalue(az1#+(lengthaz#*transition#))
rotateobjectlocalx(c_obj,axdraw#)
rotateobjectlocaly(c_obj,aydraw#)
rotateobjectlocalz(c_obj,azdraw#)
rfobject=rfobject+1
endif
endif
next limb
runthrough=1
endwhile
endfunction
function addlimb(objtoadd,object1)
if getobjectexists(objtoadd)=0 then exitfunction
if getobjectexists(object1)=0 then exitfunction
if object1<1 then exitfunction
if objtoadd<1 then exitfunction
if object1>max_objects then exitfunction
//do a limb count and see if it can be added
for limb=1 to 20 step 1
cp=limb_start_obj+(object1*20)+limb
if getobjectexists(cp)=0
if getlimbcount(object1)=0
//mt out array completely for clean start
for lmb=1 to 20 step 1
for dat=0 to 6 step 1
for f=1 to 33 step 1
object_buffer#[object1,lmb,dat,f]=0.0
next f
next dat
next lmb
endif
cloneobject(cp,objtoadd)
//copy filename sources
object_filenames$[object1,limb,0]=object_filenames$[objtoadd,0,0]
object_filenames$[object1,limb,1]=object_filenames$[objtoadd,0,1]
for d=0 to 20 step 1
object_buffer#[object1,limb,d,0]=0
next d
exitfunction
endif
next limb
endfunction
function setlimbkeyposition(object1,limb,x#,y#,z#,key_frame)
if key_frame<1 or key_frame>max_keyframes then exitfunction
if object1<1 or object1>max_objects then exitfunction
if limb<1 or limb>max_limbs then exitfunction
object_buffer#[object1,limb,1,key_frame]=x#
object_buffer#[object1,limb,2,key_frame]=y#
object_buffer#[object1,limb,3,key_frame]=z#
endfunction
function setlimbkeyrotation(object1,limb,x#,y#,z#,key_frame)
if key_frame<1 or key_frame>max_keyframes then exitfunction
if object1<1 or object1>max_objects then exitfunction
if limb<1 or limb>max_limbs then exitfunction
object_buffer#[object1,limb,4,key_frame]=x#
object_buffer#[object1,limb,5,key_frame]=y#
object_buffer#[object1,limb,6,key_frame]=z#
endfunction
function playobject(object1,startkey,endkey,continous,speed#,limbcount)
//objects_playing[max_objects,6]
objects_playing#[object1,0]=1 //is playing
objects_playing#[object1,1]=startkey
objects_playing#[object1,2]=endkey
objects_playing#[object1,3]=continous
objects_playing#[object1,4]=speed#
objects_playing#[object1,5]=limbcount
transition#[object1,5]=startkey
endfunction
function setobjectframe(object1,frame#)
transition#[object1,5]=frame#
endfunction
function runanimationtransition(object1,startframe,endframe,continous,speed#,limbcount)
//lets writeout to frame 21
//get values to make starting point
key_frame#=transition#[object1,5]
//if key_frame#<0 then key_frame#=0
//if key_frame#>22.0 then key_frame#=22.0
for limb=1 to 20 step 1
//baseframe#=object_buffer#[object1,limb,1,0]
frame1=trunc(key_frame#)
frame2=trunc(key_frame#)+1
transition#=key_frame#-trunc(key_frame#)
if frame1=0 then x1#=object_buffer#[object1,limb,1,0]
if frame1>0 then x1#=object_buffer#[object1,limb,1,0]+object_buffer#[object1,limb,1,frame1]
x2#=object_buffer#[object1,limb,1,0]+object_buffer#[object1,limb,1,frame2]
lengthx#=x2#-x1#
xdraw#=x1#+(lengthx#*transition#)
if frame1=0 then y1#=object_buffer#[object1,limb,2,0]
if frame1>0 then y1#=object_buffer#[object1,limb,2,0]+object_buffer#[object1,limb,2,frame1]
y2#=object_buffer#[object1,limb,2,0]+object_buffer#[object1,limb,2,frame2]
lengthy#=y2#-y1#
ydraw#=y1#+(lengthy#*transition#)
if frame1=0 then z1#=object_buffer#[object1,limb,3,0]
if frame1>0 then z1#=object_buffer#[object1,limb,3,0]+object_buffer#[object1,limb,3,frame1]
z2#=object_buffer#[object1,limb,3,0]+object_buffer#[object1,limb,3,frame2]
lengthz#=z2#-z1#
zdraw#=z1#+(lengthz#*transition#)
//moveobjectlocalx(c_obj,xdraw#)
//moveobjectlocaly(c_obj,ydraw#)
//moveobjectlocalz(c_obj,zdraw#)
if frame1=0 then ax1#=object_buffer#[object1,limb,4,0]
if frame1>0 then ax1#=object_buffer#[object1,limb,4,0]+object_buffer#[object1,limb,4,frame1]
ax2#=object_buffer#[object1,limb,4,0]+object_buffer#[object1,limb,4,frame2]
lengthax#=ax2#-ax1#
axdraw#=ax1#+(lengthax#*transition#)
if frame1=0 then ay1#=object_buffer#[object1,limb,5,0]
if frame1>0 then ay1#=object_buffer#[object1,limb,5,0]+object_buffer#[object1,limb,5,frame1]
ay2#=object_buffer#[object1,limb,5,0]+object_buffer#[object1,limb,5,frame2]
lengthay#=ay2#-ay1#
aydraw#=ay1#+(lengthay#*transition#)
if frame1=0 then az1#=object_buffer#[object1,limb,6,0]
if frame1>0 then az1#=object_buffer#[object1,limb,6,0]+object_buffer#[object1,limb,6,frame1]
az2#=object_buffer#[object1,limb,6,0]+object_buffer#[object1,limb,6,frame2]
lengthaz#=az2#-az1#
azdraw#=az1#+(lengthaz#*transition#)
//rotateobjectlocalx(c_obj,axdraw#)
//rotateobjectlocaly(c_obj,aydraw#)
//rotateobjectlocalz(c_obj,azdraw#)
//if startframe>0.00
object_buffer#[object1,limb,1,31]=xdraw#-object_buffer#[object1,limb,1,0]
object_buffer#[object1,limb,2,31]=ydraw#-object_buffer#[object1,limb,2,0]
object_buffer#[object1,limb,3,31]=zdraw#-object_buffer#[object1,limb,3,0]
object_buffer#[object1,limb,4,31]=axdraw#-object_buffer#[object1,limb,4,0]
object_buffer#[object1,limb,5,31]=aydraw#-object_buffer#[object1,limb,5,0]
object_buffer#[object1,limb,6,31]=azdraw#-object_buffer#[object1,limb,6,0]
//endif
//if startframe=0.0
// object_buffer#[object1,limb,1,31]=0
// object_buffer#[object1,limb,2,31]=0
// object_buffer#[object1,limb,3,31]=0
// object_buffer#[object1,limb,4,31]=0
// object_buffer#[object1,limb,5,31]=0
// object_buffer#[object1,limb,6,31]=0
//endif
//copy frame in
//if startframe>0
object_buffer#[object1,limb,1,32]=object_buffer#[object1,limb,1,startframe+1]
object_buffer#[object1,limb,2,32]=object_buffer#[object1,limb,2,startframe+1]
object_buffer#[object1,limb,3,32]=object_buffer#[object1,limb,3,startframe+1]
object_buffer#[object1,limb,4,32]=object_buffer#[object1,limb,4,startframe+1]
object_buffer#[object1,limb,5,32]=object_buffer#[object1,limb,5,startframe+1]
object_buffer#[object1,limb,6,32]=object_buffer#[object1,limb,6,startframe+1]
//endif
//if startframe=0
//object_buffer#[object1,limb,1,32]=0
//object_buffer#[object1,limb,2,32]=0
//object_buffer#[object1,limb,3,32]=0
//object_buffer#[object1,limb,4,32]=0
//object_buffer#[object1,limb,5,32]=0
//object_buffer#[object1,limb,6,32]=0
//endif
next limb
//then swap animation loop
//transition[max_objects,4]
//0 data
//1 keyframe
//2 transition?
//3 start frame
//4 end frame
transition#[object1,0]=1 //activated
transition#[object1,1]=continous
transition#[object1,3]=startframe
transition#[object1,4]=endframe
transition#[object1,5]=31.0
playobject(object1,31,32,0,speed#,limbcount)
endfunction
function getobjectplaying(object1)
if objects_playing#[object1,0]=1 then exitfunction 1
endfunction 0
function getobjectframe#(object1)
v#=transition#[object1,5]
endfunction v#
function getobjectspeed#(object1)
v#=objects_playing#[object1,4]
endfunction v#
function stopobject(object1)
objects_playing#[object1,0]=0
transition#[object1,0]=0
endfunction
function cloneanimatedobject(source,destination)
if source<1 then exitfunction
if source>max_objects then exitfunction
if getobjectexists(source)=0 then exitfunction
if destination<1 then exitfunction
if destination>max_objects then exitfunction
if getobjectexists(destination)=1 then deleteobject(destination)
//ok lets clone away
cloneobject(destination,source)
for limb=1 to 20 step 1
sobj=limb_start_obj+(source*20)+limb
dobj=limb_start_obj+(destination*20)+limb
if getobjectexists(dobj)=1 then deleteobject(dobj)
if getobjectexists(sobj)=1 then cloneobject(dobj,sobj)
next limb
//now copy animation data
for limb=0 to 20 step 1
//copy file names
object_filenames$[destination,limb,0]=object_filenames$[source,limb,0]
object_filenames$[destination,limb,1]=object_filenames$[source,limb,1]
for dat=0 to 6 step 1
for key=0 to 30 step 1
object_buffer#[destination,limb,dat,key]=object_buffer#[source,limb,dat,key]
next key
next dat
next limb
//frame 0 start
transition#[object1,5]=0.0
updateobject(destination,20)
endfunction
function deleteanimatedobject(object1)
if getobjectexists(object1)=1 then deleteobject(object1)
for limb=1 to 20 step 1
sobj=limb_start_obj+(object1*20)+limb
if getobjectexists(sobj)=1 then deleteobject(sobj)
next limb
//clear array
for limb=0 to 20 step 1
object_filenames$[object1,limb,0]=""
object_filenames$[object1,limb,1]=""
for dat=0 to 6 step 1
for key=0 to 30 step 1
object_buffer#[object1,limb,dat,key]=0
next key
next dat
next limb
endfunction
function instanceanimatedobject(source,destination)
if source<1 then exitfunction
if source>max_objects then exitfunction
if getobjectexists(source)=0 then exitfunction
if destination<1 then exitfunction
if destination>max_objects then exitfunction
if getobjectexists(destination)=1 then deleteobject(destination)
//ok lets clone away
instanceobject(destination,source)
for limb=1 to 20 step 1
sobj=limb_start_obj+(source*20)+limb
dobj=limb_start_obj+(destination*20)+limb
if getobjectexists(dobj)=1 then deleteobject(dobj)
if getobjectexists(sobj)=1 then instanceobject(dobj,sobj)
next limb
//now copy animation data
for limb=0 to 20 step 1
object_filenames$[destination,limb,0]=object_filenames$[source,limb,0]
object_filenames$[destination,limb,1]=object_filenames$[source,limb,1]
for dat=0 to 6 step 1
for key=0 to 30 step 1
object_buffer#[destination,limb,dat,key]=object_buffer#[source,limb,dat,key]
next key
next dat
next limb
//
transition#[object1,5]=0
updateobject(destination,20)
endfunction
function hideobject(object1)
setobjectvisible(object1,0)
for limb=1 to 20 step 1
sobj=limb_start_obj+(object1*20)+limb
if getobjectexists(sobj)=1 then setobjectvisible(sobj,0)
next limb
endfunction
function hidelimb(object1,limb)
if limb=0 then setobjectvisible(object1,0)
if limb>0
sobj=limb_start_obj+(object1*20)+limb
if getobjectexists(sobj)=1 then setobjectvisible(sobj,0)
endif
endfunction
function showlimb(object1,limb)
if limb=0 then setobjectvisible(object1,1)
if limb>0
sobj=limb_start_obj+(object1*20)+limb
if getobjectexists(sobj)=1 then setobjectvisible(sobj,1)
endif
endfunction
function showobject(object1)
setobjectvisible(object1,1)
for limb=1 to 20 step 1
sobj=limb_start_obj+(object1*20)+limb
if getobjectexists(sobj)=1 then setobjectvisible(sobj,1)
next limb
endfunction
function updateobjectanimation(object1)
//not based on timer yet!
atkey#=transition#[object1,5]
//skip=0
//test if its running transition
//print(str(transition#[object1,0]))
//check if playing
if objects_playing#[object1,0]=1
if transition#[object1,0]=1 and atkey#=32.0 //activated
objects_playing#[object1,3]=transition#[object1,1] //countinous
atkey#=transition#[object1,3]+1
objects_playing#[object1,1]=transition#[object1,3]
objects_playing#[object1,2]=transition#[object1,4]
transition#[object1,0]=0
//skip=1
endif
//test forward
if objects_playing#[object1,2]>objects_playing#[object1,1] //and skip=0
atkey#=atkey#+objects_playing#[object1,4]
if atkey#=>objects_playing#[object1,2] and objects_playing#[object1,3]=1 then atkey#=objects_playing#[object1,1]
if atkey#=>objects_playing#[object1,2] and objects_playing#[object1,3]=0
atkey#=objects_playing#[object1,2]
if transition#[object1,0]=0 then objects_playing#[object1,0]=0
endif
endif
//test backward
if objects_playing#[object1,1]>objects_playing#[object1,2] //and skip=0
atkey#=atkey#-objects_playing#[object1,4]
if atkey#=<objects_playing#[object1,2] and objects_playing#[object1,3]=1 then atkey#=objects_playing#[object1,2]
if atkey#=<objects_playing#[object1,2] and objects_playing#[object1,3]=0
atkey#=objects_playing#[object1,2]
if transition#[object1,0]=0 then objects_playing#[object1,0]=0
endif
endif
endif
transition#[object1,5]=atkey#
if objects_playing#[object1,5]=0 then objects_playing#[object1,5]=getlimbcount(object1)
updateobject(object1,objects_playing#[object1,5])
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,"# agk easy editable object format")
writeline(1,"# "+str(max_vertexcount+1)+" vertex positions" )
stp=-1
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
function loadobj(object1,filename$)
//lets load the file 2 times to count data
opentoread(1,filename$)
vertex_counter=0
uv_counter=0
nm_counter=0
index_counter=0
while fileeof(1)=0
cmd$=readline(1)
if left(cmd$,2)="v "
vertex_counter=vertex_counter+1
endif
if left(cmd$,2)="vn"
nm_counter=nm_counter+1
endif
if left(cmd$,2)="vt"
uv_counter=uv_counter+1
endif
if left(cmd$,2)="f "
index_counter=index_counter+1
endif
endwhile
closefile(1)
//ok so we have some general data to actualy load the file in
if vertex_counter<3 then exitfunction
if index_counter<3 then exitfunction
ic=(index_counter*3)
makenewobject(vertex_counter,ic)
//load it in and fill in the data
opentoread(1,filename$)
vertex_counter=0
uv_counter=0
nm_counter=0
index_counter=0
while fileeof(1)=0
cmd$=readline(1)
if left(cmd$,2)="v "
vertex_counter=vertex_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdataposition(vertex_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="vn"
nm_counter=nm_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdatanormals(nm_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="vt"
uv_counter=uv_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdatauv(uv_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="f "
index_counter=index_counter+1
//split into several strings
num=countstringtokens(cmd$," ")
st1$=getstringtoken(cmd$," ",2)
st2$=getstringtoken(cmd$," ",3)
st3$=getstringtoken(cmd$," ",4)
ind1=val(getstringtoken(st1$,"/",1))
ind2=val(getstringtoken(st2$,"/",1))
ind3=val(getstringtoken(st3$,"/",1))
ic=(index_counter*3.0)-3
setindexdata(ic,ind1-1)
setindexdata(ic+1,ind2-1)
setindexdata(ic+2,ind3-1)
endif
endwhile
closefile(1)
//ok lets save temp obj and loadit in.
savenewobject(object1,"temporary_smd.obj",1,1)
//benefits you ask? you can edit it and save it again!
//automatically fills vertex and index data into memory
endfunction
function adjustobjectpivotpoint(object1,filename$,x#,y#,z#)
//first load it in
loadobj(object1,filename$)
//adjust all vertex data offsets
for v=0 to max_vertexcount step 1
edit_object1#[v,0]=edit_object1#[v,0]+x#
edit_object1#[v,1]=edit_object1#[v,1]+y#
edit_object1#[v,2]=edit_object1#[v,2]+z#
next v
//save temporary object and reload it.
savenewobject(object1,"temporary_smd.obj",1,1)
endfunction
function saveanimatedmodel(object1,filenameb$,flag)
if object1<1 then exitfunction
if object1>max_objects then exitfunction
//flag 1 = overwrite if exists
if getfileexists(filenameb$)=1 and flag=0 then exitfunction
if getfileexists(filenameb$)=1 then deletefile(filenameb$)
//count for each object and store them
//count_data[20,3]
//can we have 2 files open at once?
opentowrite(2,filenameb$)
writeline(2,"[ANIMATED OBJ FORMAT FOR AGK r0.1]")
writeline(2,"[ANIMDATA]")
//store anim data first
for limb=0 to 20 step 1
for dat=0 to 6 step 1
for key=0 to 30 step 1
writefloat(2,object_buffer#[object1,limb,dat,key])
next key
next dat
next limb
writeline(2,"[ENDANIMDATA]")
for limb=0 to 20 step 1
count_objectdata(object1,limb)
//get it into memory
if count_data[limb,0]=1
//load that data in
loadobjectarray(object1,limb)
writeline(2,"[NEW OBJECT]")
writeline(2,"[TEXTURE "+object_filenames$[object1,limb,1]+" ]")
writeline(2,"[VTOTAL "+str(max_vertexcount+1)+" ]")
writeline(2,"[UVTOTAL "+str(max_vertexcount+1)+" ]" )
writeline(2,"[NMTOTAL "+str(max_vertexcount+1)+" ]" )
ind_count=(max_indexcount+1)/3
writeline(2,"[IFACES "+str(ind_count)+" ]" )
for v=0 to max_vertexcount step 1
writeline(2,"v "+str(edit_object1#[v,0])+" "+str(edit_object1#[v,1])+" "+str(edit_object1#[v,2]))
next v
for v=0 to max_vertexcount step 1
writeline(2,"vt "+str(edit_object1#[v,6])+" "+str(edit_object1#[v,7])+" "+str(edit_object1#[v,8]))
next v
for v=0 to max_vertexcount step 1
writeline(2,"vn "+str(edit_object1#[v,3])+" "+str(edit_object1#[v,4])+" "+str(edit_object1#[v,5]))
next v
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(2,"f "+str(index1)+"/"+str(index1)+"/"+str(index1)+" "+str(index2)+"/"+str(index2)+"/"+str(index2)+" "+str(index3)+"/"+str(index3)+"/"+str(index3))
next i
writeline(2,"[ENDOBJ]")
endif
if count_data[limb,0]=0
writeline(2,"[MT OBJECT]")
endif
next limb
//ok setup info complete
closefile(2)
endfunction
function loadobjectarray(object1,limb)
filename3$=object_filenames$[object1,limb,0]
//ok so we have some general data to actualy load the file in
vertex_counter=count_data[limb,1]
index_counter=count_data[limb,4]
ic=(index_counter*3)
makenewobject(vertex_counter,ic)
//load it in and fill in the data
opentoread(1,filename3$)
vertex_counter=0
uv_counter=0
nm_counter=0
index_counter=0
while fileeof(1)=0
cmd$=readline(1)
if left(cmd$,2)="v "
vertex_counter=vertex_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdataposition(vertex_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="vn"
nm_counter=nm_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdatanormals(nm_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="vt"
uv_counter=uv_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdatauv(uv_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="f "
index_counter=index_counter+1
//split into several strings
num=countstringtokens(cmd$," ")
st1$=getstringtoken(cmd$," ",2)
st2$=getstringtoken(cmd$," ",3)
st3$=getstringtoken(cmd$," ",4)
ind1=val(getstringtoken(st1$,"/",1))
ind2=val(getstringtoken(st2$,"/",1))
ind3=val(getstringtoken(st3$,"/",1))
ic=(index_counter*3.0)-3
setindexdata(ic,ind1-1)
setindexdata(ic+1,ind2-1)
setindexdata(ic+2,ind3-1)
endif
endwhile
closefile(1)
//datas in
endfunction
function count_objectdata(objecta,limb)
//lets look for data
if objecta<1 then exitfunction
if objecta>max_objects then exitfunction
filename2$=object_filenames$[objecta,limb,0]
if getfileexists(filename2$)=0 then exitfunction
opentoread(1,filename2$)
vertex_counter=0
uv_counter=0
nm_counter=0
index_counter=0
while fileeof(1)=0
cmd$=readline(1)
if left(cmd$,2)="v "
vertex_counter=vertex_counter+1
endif
if left(cmd$,2)="vn"
nm_counter=nm_counter+1
endif
if left(cmd$,2)="vt"
uv_counter=uv_counter+1
endif
if left(cmd$,2)="f "
index_counter=index_counter+1
endif
endwhile
closefile(1)
count_data[limb,0]=1 //exists
count_data[limb,1]=vertex_counter //v
count_data[limb,2]=nm_counter //n
count_data[limb,3]=uv_counter //t
count_data[limb,4]=index_counter //f
endfunction
function loadanimatedmodel(object1,filename$,flag)
//flag =0 no texturing
//flag =1 if attemp to load and apply textures
//flag =2 if load only first texture and apply to all limbs
if getfileexists(filename$)=0 then exitfunction
if object1<1 then exitfunction
if object1>max_objects then exitfunction
//ok load it here
if getobjectexists(object1)=1 then deleteobject(object1)
opentoread(1,filename$)
a$=readline(1)
a$=readline(1)
//now animation data
//store anim data first
for limb=0 to 20 step 1
for dat=0 to 6 step 1
for key=0 to 30 step 1
object_buffer#[object1,limb,dat,key]=readfloat(1)
next key
next dat
next limb
a$=readline(1)
//process objects / make them / save data / load in obj/ apply texture
limb=-1
tex$="NULL"
while fileeof(1)=0
cmd$=readline(1)
//process comands
if cmd$="[NEW OBJECT]" then limb=limb+1
if left(cmd$,8)="[TEXTURE" then tex$=getstringtoken(cmd$," ",2)
if left(cmd$,7)="[VTOTAL" then vertex_counter=val(getstringtoken(cmd$," ",2))
if left(cmd$,8)="[UVTOTAL" then uv_counter=val(getstringtoken(cmd$," ",2))
if left(cmd$,8)="[NMTOTAL" then nm_counter=val(getstringtoken(cmd$," ",2))
if left(cmd$,7)="[IFACES"
index_counter=val(getstringtoken(cmd$," ",2))
//start object
ic=(index_counter*3.0)
makenewobject(vertex_counter,ic)
//0 the data
vertex_counter=0
uv_counter=0
nm_counter=0
index_counter=0
endif
if left(cmd$,2)="v "
vertex_counter=vertex_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdataposition(vertex_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="vn"
nm_counter=nm_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdatanormals(nm_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="vt"
uv_counter=uv_counter+1
num=countstringtokens(cmd$," ")
v1#=0.0
v2#=0.0
v3#=0.0
v1#=valfloat(getstringtoken(cmd$," ",2))
v2#=valfloat(getstringtoken(cmd$," ",3))
v3#=valfloat(getstringtoken(cmd$," ",4))
setvertexdatauv(uv_counter-1,v1#,v2#,v3#)
endif
if left(cmd$,2)="f "
index_counter=index_counter+1
//split into several strings
num=countstringtokens(cmd$," ")
st1$=getstringtoken(cmd$," ",2)
st2$=getstringtoken(cmd$," ",3)
st3$=getstringtoken(cmd$," ",4)
ind1=val(getstringtoken(st1$,"/",1))
ind2=val(getstringtoken(st2$,"/",1))
ind3=val(getstringtoken(st3$,"/",1))
ic=((index_counter)*3.0)-3
setindexdata(ic,ind1-1)
setindexdata(ic+1,ind2-1)
setindexdata(ic+2,ind3-1)
endif
if cmd$="[ENDOBJ]"
//ok lets save it and load it in place
if limb=0 then savenewobjectlimb(object1)
if limb>0 then savenewobjectlimb(limb_start_obj+(object1*20)+limb)
//apply texture if any
if flag=1 or flag=2 and limb=0
if getimageexists(limb_start_obj+(object1*20)+limb)=1 then deleteimage(limb_start_obj+(object1*20)+limb)
if tex$<>"NULL" and getfileexists(tex$)=1
loadimage(limb_start_obj+(object1*20)+limb,tex$)
if limb>0 then setobjectimage(limb_start_obj+(object1*20)+limb,limb_start_obj+(object1*20)+limb,0)
if limb=0 then setobjectimage(object1,limb_start_obj+(object1*20)+limb,0)
endif
endif
if flag=2
if getimageexists(limb_start_obj+(object1*20))=1 then setobjectimage(limb_start_obj+(object1*20)+limb,limb_start_obj+(object1*20),0)
endif
//vertex_counter=0
//uv_counter=0
//nm_counter=0
//index_counter=0
endif
if cmd$="[MT OBJECT]"
limb=limb+1
if getobjectexists(limb_start_obj+(object1*20)+limb)=1 then deleteobject(limb_start_obj+(object1*20)+limb)
endif
endwhile
closefile(1)
endfunction
function savenewobjectlimb(object)
//flag1 1 = overwrite existing file
//flag1 <>0 = fail if file exists
//flag2 load it in after saving it =1
filename4$="temporary_smd_"+str(object)+".obj"
if max_vertexcount<2 then exitfunction
if max_indexcount<2 then exitfunction
//ok lets write the file
if getfileexists(filename4$)=1 then deletefile(filename4$)
opentowrite(3,filename4$)
writeline(3,"# agk easy editable object format")
writeline(3,"# "+str(max_vertexcount+1)+" vertex positions" )
stp=-1
for v=0 to max_vertexcount step 1
writeline(3,"v "+str(edit_object1#[v,0])+" "+str(edit_object1#[v,1])+" "+str(edit_object1#[v,2]))
next v
writeline(3,"# "+str(max_vertexcount+1)+" uv coordinates" )
for v=0 to max_vertexcount step 1
writeline(3,"vt "+str(edit_object1#[v,6])+" "+str(edit_object1#[v,7])+" "+str(edit_object1#[v,8]))
next v
writeline(3,"# "+str(max_vertexcount+1)+" vertex normals" )
for v=0 to max_vertexcount step 1
writeline(3,"vn "+str(edit_object1#[v,3])+" "+str(edit_object1#[v,4])+" "+str(edit_object1#[v,5]))
next v
ic=(max_indexcount)
writeline(3,"# Mesh 'object_name' with "+str(max_indexcount)+" faces" )
writeline(3,"# " ) // normally would specify material name but agk ignores this
writeline(3,"g object_name")
for i=0 to ic step 3
index1=edit_object2[i]+1
index2=edit_object2[i+1]+1
index3=edit_object2[i+2]+1
writeline(3,"f "+str(index1)+"/"+str(index1)+"/"+str(index1)+" "+str(index2)+"/"+str(index2)+"/"+str(index2)+" "+str(index3)+"/"+str(index3)+"/"+str(index3))
next i
writeline(3,"# thats it ")
//message("saved something?")
closefile(3)
if getobjectexists(object)=1 then deleteobject(object)
loadobject(object,filename4$)
deletefile(filename4$)
endfunction 1
function getdistance#(x1#,y1#,z1#,x2#,y2#,z2#)
dx# = x2#-x1#
dy# = y2#-y1#
dz# = z2#-z1#
d#=sqrt(dx#*dx# + dy#*dy# + dz#*dz#)
endfunction d#