#include "Objects_included.agc"
#include "keyboard_include.agc"
global release$


release$="R3"
completerawjoystickdetection()
//createlightdirectional(1,-1,-1.25,-2,255,255,255)
setsundirection(-1,-1.25,-2)

news$="AGKII3D Animator By: Sheldon MacDonald - SheldonsCreations (c)2015 "+release$
setwindowtitle(news$)

SetRawWritePath( GetDocumentsPath())
setfolder("")
makefolder("AGK Animations")
SetRawWritePath( GetDocumentsPath()+"/AGK Animations")
if getfileexists("place_here.txt")=0
	//copy startup files
	opentowrite(1,"place_here.txt")
	writeline(1,"place all obj files and png files for the editor in this folder")
	closefile(1)
	
	//lets copy example files over
	setfolder("media")
	if getmemblockexists(1)=1 then deletememblock(1)
	if getmemblockexists(2)=1 then deletememblock(2)
	if getmemblockexists(3)=1 then deletememblock(3)
	if getmemblockexists(4)=1 then deletememblock(4)
	if getmemblockexists(5)=1 then deletememblock(5)
	
	creatememblockfromfile(1,"swatguy.ob2")
	creatememblockfromfile(2,"swatguy.png")
	creatememblockfromfile(3,"jacob_knight.ob2")
	creatememblockfromfile(4,"swatguy copyright info.txt")
	creatememblockfromfile(5,"master.png")
	
	setfolder("")
	createfilefrommemblock("swatguy.ob2",1)
	createfilefrommemblock("swatguy.png",2)
	createfilefrommemblock("jacob_knight.ob2",3)
	createfilefrommemblock("swatguy copyright info.txt",4)
    createfilefrommemblock("master.png",5)

	if getmemblockexists(1)=1 then deletememblock(1)
	if getmemblockexists(2)=1 then deletememblock(2)
	if getmemblockexists(3)=1 then deletememblock(3)
	if getmemblockexists(4)=1 then deletememblock(4)
	if getmemblockexists(5)=1 then deletememblock(5)
	
endif

//perform this always
	setfolder("media")
	//copy blank pivot file
	loadobj(2,"pivotpoint.obj")
	setfolder("")
	savenewobject(2,"pivotpoint.obj",1,1)
	deleteobject(2)

	setfolder("media")


global lastwheel#
global myfile$
global currentfile$
currentfile$=""

global mylimb=1
global lastedit=0

global gstart
global gend
global speed#=0.05

global flash=0
global flashtime=0
global flashclr=0
global mouseset=0
global oldmousex#
global oldmousey#

setscreenresolution(1024,600)
SetVirtualResolution(1024,600)
initialize_objects(21)

//create in your face interface lol...
loadimage(101,"data/menubar.png",1)
createsprite(1,101)
setspritedepth(1,5)
setspritecolor(1,200,200,200,255)

//add some buttons
//open file
loadimage(102,"data/button_0.png",1)
createsprite(2,102)
setspritedepth(2,4)
setspritescale(2,2.2,0.5)
setspriteposition(2,10,10)
createtext(2,"Open Model")
settextsize(2,20)
settextdepth(2,3)
settextcolor(2,0,255,0,255)
settextposition(2,15,15)

//savefile
loadimage(103,"data/button_0.png",1)
createsprite(3,103)
setspritedepth(3,4)
setspritescale(3,2.2,0.5)
setspriteposition(3,10,45)
createtext(3,"Save Model")
settextsize(3,20)
settextdepth(3,3)
settextcolor(3,255,0,0,255)
settextposition(3,15,50)



//play button
loadimage(104,"data/button_0.png",1)
createsprite(4,104)
setspritedepth(4,4)
setspritescale(4,1.0,0.5)
setspriteposition(4,500,60)
createtext(4,"PLAY")
settextsize(4,20)
settextdepth(4,3)
settextcolor(4,255,0,0,255)
settextposition(4,505,65)


//load image button
loadimage(105,"data/button_0.png",1)
createsprite(5,105)
setspritedepth(5,4)
setspritescale(5,2.2,0.5)
setspriteposition(5,800,10)
createtext(5,"Set Image")
settextsize(5,20)
settextdepth(5,3)
settextcolor(5,255,255,255,255)
settextposition(5,810,15)

//load object
loadimage(106,"data/button_0.png",1)
createsprite(6,106)
setspritedepth(6,4)
setspritescale(6,2.2,0.5)
setspriteposition(6,800,45)
createtext(6,"Load Obj")
settextsize(6,20)
settextdepth(6,3)
settextcolor(6,255,255,255,255)
settextposition(6,818,50)

//merge animation
loadimage(107,"data/button_0.png",1)
createsprite(7,107)
setspritedepth(7,4)
setspritescale(7,2.2,0.5)
setspriteposition(7,800,80)
createtext(7,"Flush Objs")
settextsize(7,20)
settextdepth(7,3)
settextcolor(7,255,255,255,255)
settextposition(7,805,85)


//newfile
loadimage(108,"data/button_0.png",1)
createsprite(8,108)
setspritedepth(8,4)
setspritescale(8,2.2,0.5)
setspriteposition(8,10,80)
createtext(8,"New Model")
settextsize(8,20)
settextdepth(8,3)
settextcolor(8,255,255,255,255)
settextposition(8,20,85)




//copy button
loadimage(109,"data/button_0.png",1)
createsprite(9,109)
setspritedepth(9,4)
setspritescale(9,1.0,0.5)
setspriteposition(9,575,60)
createtext(9,"Copy")
settextsize(9,20)
settextdepth(9,3)
settextcolor(9,0,255,0,255)
settextposition(9,580,65)


//copy button
loadimage(110,"data/button_0.png",1)
createsprite(10,110)
setspritedepth(10,4)
setspritescale(10,1.0,0.5)
setspriteposition(10,650,60)
createtext(10,"Paste")
settextsize(10,20)
settextdepth(10,3)
settextcolor(10,0,0,255,255)
settextposition(10,650,65)


//erase button
loadimage(111,"data/button_0.png",1)
createsprite(11,111)
setspritedepth(11,4)
setspritescale(11,1.0,0.5)
setspriteposition(11,725,60)
createtext(11,"Erase")
settextsize(11,20)
settextdepth(11,3)
settextcolor(11,255,0,0,255)
settextposition(11,725,65)


//exit button
loadimage(112,"data/button_0.png",1)
createsprite(12,112)
setspritedepth(12,4)
setspritescale(12,1.0,0.5)
setspriteposition(12,945,10)
createtext(12,"QUIT")
settextsize(12,20)
settextdepth(12,3)
settextcolor(12,255,0,0,255)
settextposition(12,950,15)

//wifi button
loadimage(113,"data/button_0.png",1)
createsprite(13,113)
setspritedepth(13,4)
setspritescale(13,1.0,0.5)
setspriteposition(13,945,45)
createtext(13,"FixP")
settextsize(13,20)
settextdepth(13,3)
settextcolor(13,0,0,255,255)
settextposition(13,950,50)


//about button
loadimage(114,"data/button_0.png",1)
createsprite(14,114)
setspritedepth(14,4)
setspritescale(14,1.0,0.5)
setspriteposition(14,945,80)
createtext(14,"INFO")
settextsize(14,20)
settextdepth(14,3)
settextcolor(14,0,255,0,255)
settextposition(14,950,85)






setclearcolor(0,0,100)
global camx#
global camy#
global camz#
global camangx#
global camangy#
global camangz#
camx#=0
camy#=30
camz#=0
camangx#=0
camangy#=180
camangz#=0
global mousemode=0
global editmode=0
global zoom#=-400.0

setcamerarange(1,1,10000)


//create a dummy ground object
createobjectplane(22,100,100)
setobjectposition(22,0,-50,0)
setobjectrotation(22,90,0,0)
loadimage(22,"data/ground.png",1)
setobjectimage(22,22,0)


//SETUP TEXT
//row 1
createtext(100,"GH")
settextposition(100,292,35)
settextalignment(100,1)
settextdepth(100,3)
settextsize(100,12)
settextcolor(100,0,0,0,255)

createtext(101,"POS X")
settextposition(101,292,58)
settextalignment(101,1)
settextdepth(101,3)
settextsize(101,12)
settextcolor(101,0,0,0,255)

createtext(102,"ROT X")
settextposition(102,292,81)
settextalignment(102,1)
settextdepth(102,3)
settextsize(102,12)
settextcolor(102,0,0,0,255)

createtext(113,"SC  X")
settextposition(113,292,104)
settextalignment(113,1)
settextdepth(113,3)
settextsize(113,12)
settextcolor(113,0,0,0,255)

//row 2
createtext(103,"LIMB #")
settextposition(103,366,35)
settextalignment(103,1)
settextdepth(103,3)
settextsize(103,12)
settextcolor(103,0,0,0,255)

createtext(104,"POS Y")
settextposition(104,366,58)
settextalignment(104,1)
settextdepth(104,3)
settextsize(104,12)
settextcolor(104,0,0,0,255)

createtext(105,"ROT Y")
settextposition(105,366,81)
settextalignment(105,1)
settextdepth(105,3)
settextsize(105,12)
settextcolor(105,0,0,0,255)

createtext(114,"SC  Y")
settextposition(114,366,104)
settextalignment(114,1)
settextdepth(114,3)
settextsize(114,12)
settextcolor(114,0,0,0,255)

//row 3
createtext(106,"PARENT #")
settextposition(106,440,35)
settextalignment(106,1)
settextdepth(106,3)
settextsize(106,12)
settextcolor(106,0,0,0,255)

createtext(107,"POS Z")
settextposition(107,440,58)
settextalignment(107,1)
settextdepth(107,3)
settextsize(107,12)
settextcolor(107,0,0,0,255)

createtext(108,"ROT Z")
settextposition(108,440,81)
settextalignment(108,1)
settextdepth(108,3)
settextsize(108,12)
settextcolor(108,0,0,0,255)

createtext(115,"SC  Z")
settextposition(115,440,104)
settextalignment(115,1)
settextdepth(115,3)
settextsize(115,12)
settextcolor(115,0,0,0,255)

//last 4
createtext(109,"frame")
settextposition(109,534,35)
settextalignment(109,1)
settextdepth(109,3)
settextsize(109,12)
settextcolor(109,0,0,0,255)

createtext(110,"0")
settextposition(110,608,35)
settextalignment(110,1)
settextdepth(110,3)
settextsize(110,12)
settextcolor(110,0,0,0,255)

createtext(111,"80")
settextposition(111,682,35)
settextalignment(111,1)
settextdepth(111,3)
settextsize(111,12)
settextcolor(111,0,0,0,255)


createtext(112,"0.05")
settextposition(112,756,35)
settextalignment(112,1)
settextdepth(112,3)
settextsize(112,12)
settextcolor(112,0,0,0,255)



//new text gadgets
createtext(116,"256")
settextposition(116,522,105)
settextalignment(116,1)
settextdepth(116,3)
settextsize(116,12)
settextcolor(116,0,0,0,255)

createtext(117,"256")
settextposition(117,595,105)
settextalignment(117,1)
settextdepth(117,3)
settextsize(117,12)
settextcolor(117,0,0,0,255)

createtext(118,"256")
settextposition(118,670,105)
settextalignment(118,1)
settextdepth(118,3)
settextsize(118,12)
settextcolor(118,0,0,0,255)

createtext(119,"256")
settextposition(119,744,105)
settextalignment(119,1)
settextdepth(119,3)
settextsize(119,12)
settextcolor(119,0,0,0,255)

createtext(120,"X")
settextposition(120,785,105)
settextalignment(120,1)
settextdepth(120,3)
settextsize(120,12)
settextcolor(120,0,0,0,255)

//lets load pivot point
loadobject2(1,"pivotpoint.obj","")
global playing=0
hidelimb(1,0)



do
    
	//print("mouse x="+str(getrawmousex()))
   //print("mouse y="+str(getrawmousey()))
    
    checkinterface()
    
    setcameraposition(1,camx#,camy#,camz#)
    
    //if getrawmouserightstate()=0 then mousemode=0
	if getrawmouseleftstate()=0 and getrawmouserightstate()=0 
		mousemode=0
		mouseset=0
	endif
	
	if getrawmousey()=>150 and getrawmouseleftstate()=1 or mouseset=1 and getrawmouseleftstate()=1
		if mousemode=0 
			setrawmouseposition(512,300)
			oldmousex#=512
			oldmousey#=300
		endif
		//if mousemode=2
		grabx#=getrawmousex()
		graby#=getrawmousey()
		adjusty#=0.0
		if graby#<oldmousey#
			adjusty#=oldmousey#-graby#
			oldmousey#=graby#
			zoom#=zoom#+adjusty#
			if zoom#=<-1000 then zoom#=-1000
			if zoom#=>-50 then zoom#=-50
		endif
		if graby#>oldmousey#
			adjusty#=graby#-oldmousey#
			oldmousey#=graby#
			zoom#=zoom#-adjusty#
			if zoom#=<-1000 then zoom#=-1000
			if zoom#=>-50 then zoom#=-50
		endif
		mouseset=1
		mousemode=2
		//setrawmouseposition(512,300)
	endif
    
    if getrawmouserightstate()=1 and getrawmousey()=>150 or mouseset=1 and getrawmouserightstate()=1
		if mousemode=0 
			setrawmouseposition(512,300)
			oldmousex#=512
			oldmousey#=300
		endif
		mouseset=1
		grabx#=getrawmousex()
		graby#=getrawmousey()
		adjustx#=0.0
		adjusty#=0.0
		
		if graby#<oldmousey#
			adjusty#=oldmousey#-graby#
			oldmousey#=graby#
			camangx#=wrapvalue(camangx#+adjusty#)
		endif
		if graby#>oldmousey#
			adjusty#=graby#-oldmousey#
			oldmousey#=graby#
			camangx#=wrapvalue(camangx#-adjusty#)
		endif
		if grabx#<oldmousex#
			adjustx#=oldmousex#-grabx#
			oldmousex#=grabx#
			camangy#=wrapvalue(camangy#+adjustx#)
		endif
		if grabx#>oldmousex#
			adjustx#=grabx#-oldmousex#
			oldmousex#=grabx#
			camangy#=wrapvalue(camangy#-adjustx#)
		endif

	
		
		mousemode=1
		//setrawmouseposition(512,300)
	endif
    
    setcamerarotation(1,camangx#,camangy#,camangz#)
    MoveCameraLocalZ(1,zoom#)
    //setcameralookat(1,camx#,camy#,camz#,0)
     
    for t=1 to 21 step 1
		updateobjectanimation(t)
		//if getobjectexists(t)=1
			//moveobjectz(t,1)
		//endif
	next t
    Sync()
loop


function checkinterface()
//update gui values
local y#
local x#
local z#
local value#
local value
local x
local y
local z
local newstring$
local didfunc=0


y#=getobjecty(22)
settextstring(100,left( str(y#) ,9))

if mylimb=0
	x#=getobjectx(1)
	y#=getobjecty(1)
	z#=getobjectz(1)
	settextstring(101,left( str(x#) ,9))
	settextstring(104,left( str(y#) ,9))
	settextstring(107,left( str(z#) ,9))
	//rotation
	x#=getlimbrotationx(1,0)
	y#=getlimbrotationy(1,0)
	z#=getlimbrotationz(1,0)
	settextstring(102,left( str(x#) ,9))
	settextstring(105,left( str(y#) ,9))
	settextstring(108,left( str(z#) ,9))
	//scale
	x#=getobjectscalex(1)
	y#=getobjectscaley(1)
	z#=getobjectscalez(1)
	settextstring(113,left( str(x#) ,9))
	settextstring(114,left( str(y#) ,9))
	settextstring(115,left( str(z#) ,9))
	
	//color and alpha
	r=0
	g=0
	b=0
	a=0
	if frame>0
		r=0
		g=0
		b=0
		a=0
	endif
	settextstring(116,left( str(r) ,4))
	settextstring(117,left( str(g) ,4))
	settextstring(118,left( str(b) ,4))
	settextstring(119,left( str(a) ,4))
	
	settextstring(120,"")
endif

if mylimb>0 and playing=1
	x#=getlimbpositionx(1,mylimb)
	y#=getlimbpositiony(1,mylimb)
	z#=getlimbpositionz(1,mylimb)
	settextstring(101,left( str(x#) ,9))
	settextstring(104,left( str(y#) ,9))
	settextstring(107,left( str(z#) ,9))
	//rotation
	x#=getlimbrotationx(1,mylimb)
	y#=getlimbrotationy(1,mylimb)
	z#=getlimbrotationz(1,mylimb)
	settextstring(102,left( str(x#) ,9))
	settextstring(105,left( str(y#) ,9))
	settextstring(108,left( str(z#) ,9))
	//scale
	x#=getobjectscalex(1)
	y#=getobjectscaley(1)
	z#=getobjectscalez(1)
	settextstring(113,left( str(x#) ,9))
	settextstring(114,left( str(y#) ,9))
	settextstring(115,left( str(z#) ,9))
	//color and alpha
	r=object_buffer#[1,mylimb,8,0]
	g=object_buffer#[1,mylimb,9,0]
	b=object_buffer#[1,mylimb,10,0]
	a=object_buffer#[1,mylimb,7,0]
	if frame>0
		r=object_buffer#[1,mylimb,8,0]+object_buffer#[1,mylimb,8,frame]
		g=object_buffer#[1,mylimb,9,0]+object_buffer#[1,mylimb,9,frame]
		b=object_buffer#[1,mylimb,10,0]+object_buffer#[1,mylimb,10,frame]
		a=object_buffer#[1,mylimb,7,0]+object_buffer#[1,mylimb,7,frame]
	endif
	settextstring(116,left( str(r) ,4))
	settextstring(117,left( str(g) ,4))
	settextstring(118,left( str(b) ,4))
	settextstring(119,left( str(a) ,4))
	
	tp=object_buffer#[1,mylimb,11,0]
	if tp=1 then settextstring(120,"X") else settextstring(120,"")
endif

if mylimb>0 and playing=0
	frame=val(left(gettextstring(109),2))
	x#=getlimbpositionxf(1,mylimb,frame)
	y#=getlimbpositionyf(1,mylimb,frame)
	z#=getlimbpositionzf(1,mylimb,frame)
	settextstring(101,left( str(x#) ,9))
	settextstring(104,left( str(y#) ,9))
	settextstring(107,left( str(z#) ,9))
	//rotation
	x#=getlimbrotationxf(1,mylimb,frame)
	y#=getlimbrotationyf(1,mylimb,frame)
	z#=getlimbrotationzf(1,mylimb,frame)
	settextstring(102,left( str(x#) ,9))
	settextstring(105,left( str(y#) ,9))
	settextstring(108,left( str(z#) ,9))
	//scale
	x#=getobjectscalex(1)
	y#=getobjectscaley(1)
	z#=getobjectscalez(1)
	settextstring(113,left( str(x#) ,9))
	settextstring(114,left( str(y#) ,9))
	settextstring(115,left( str(z#) ,9))
		//color and alpha
	r=object_buffer#[1,mylimb,8,0]
	g=object_buffer#[1,mylimb,9,0]
	b=object_buffer#[1,mylimb,10,0]
	a=object_buffer#[1,mylimb,7,0]
	if frame>0
		r=object_buffer#[1,mylimb,8,0]+object_buffer#[1,mylimb,8,frame]
		g=object_buffer#[1,mylimb,9,0]+object_buffer#[1,mylimb,9,frame]
		b=object_buffer#[1,mylimb,10,0]+object_buffer#[1,mylimb,10,frame]
		a=object_buffer#[1,mylimb,7,0]+object_buffer#[1,mylimb,7,frame]
	endif
	settextstring(116,left( str(r) ,4))
	settextstring(117,left( str(g) ,4))
	settextstring(118,left( str(b) ,4))
	settextstring(119,left( str(a) ,4))
	tp=object_buffer#[1,mylimb,11,0]
	if tp=1 then settextstring(120,"X") else settextstring(120,"")
endif

settextstring(103,left( str(mylimb) ,9))
value=object_buffer#[1,mylimb,0,0] //parrent
settextstring(106,left( str(value) ,9))

//what frame am i on
value#=getobjectframe#(1)
settextstring(109,left( str(value#) ,5))



//check for mouse select


//flash em
//global flash=0
//global flashtime=0
//global flashclr=0
flashtime=flashtime+1
if flashtime=>20 
	flashtime=0
	flash=flash+1
	if flash=>2 then flash=0
endif
if mylimb<>0
	if getobjectexists(limb_start_obj+(1*20)+mylimb)=1
		//if playing=1 then flash=1
		if flash=0 then setobjectcolor(limb_start_obj+(1*20)+mylimb,50,50,50,255)
		//if flash=1 then setobjectcolor(limb_start_obj+(1*20)+mylimb,255,255,255,255)
	endif
	
endif

if getrawmouseleftreleased()=1 and getrawmousey()<150 and mouseset=0
	
	
	//info button
	if getrawmousex()=>946 and getrawmousex()=<1005 and getrawmousey()=>80 and getrawmousey()=<110 and playing=0 and didfunc=0
		ok=messagebox(365,250,"AGKII 3D Animator "+release$,"Written By: Sheldon MacDonald","SheldonsCreations (c)2015","www.sheldonscreations.com",15,10000)
		didfunc=1
	endif
	
	//quit button
	if getrawmousex()=>946 and getrawmousex()=<1005 and getrawmousey()=>10 and getrawmousey()=<40 and playing=0 and didfunc=0
		ok=questionmessage(365,250,"End Session?",10000,10000,10000,0)
		didfunc=1
		if ok=1 then end
	endif
	
	//fixpivot button
	if getrawmousex()=>946 and getrawmousex()=<1005 and getrawmousey()=>45 and getrawmousey()=<75 and playing=0 and didfunc=0
		//check and see if limb exist first...
		didfunc=1
		if getlimbexists(1,mylimb)=1
			ok=questionmessage(365,250,"Overwrite Pivot?",10000,10000,10000,0)
			if ok=1 
				adjustpivotpoint(1,mylimb,object_buffer#[1,mylimb,1,0],object_buffer#[1,mylimb,2,0],object_buffer#[1,mylimb,3,0])
				object_buffer#[1,mylimb,1,0]=0
				object_buffer#[1,mylimb,2,0]=0
				object_buffer#[1,mylimb,3,0]=0
			endif
		endif
	endif

	//erase
	if getrawmousex()=>725 and getrawmousex()=<787 and getrawmousey()=>60 and getrawmousey()=<90 and playing=0 and didfunc=0
		frame=val(left(gettextstring(109),2))
		ok=questionmessage(365,250,"Erase Frame?",10000,10000,10000,0)
		if ok=1 and frame=<80 and frame>-1
			for lmb=0 to 20 step 1
				for dat=1 to 11 step 1
					object_buffer#[1,lmb,dat,frame]=0.0
					//if frame<>0 then object_buffer#[1,lmb,dat,frame]=0.0
				next dat
			next lmb		
		endif
		updateobject(1,20)
		didfunc=1
	endif

	//copy
	if getrawmousex()=>575 and getrawmousex()=<636 and getrawmousey()=>60 and getrawmousey()=<90 and playing=0 and didfunc=0
		frame=val(left(gettextstring(109),2))
		ok=questionmessage(365,250,"Frame Copied",10000,10000,10000,1)
		//if ok=1 and frame=<30 and frame>-1
			for lmb=0 to 20 step 1
				for dat=1 to 11 step 1
					if frame<>0 then object_buffer#[3,lmb,dat,0]=object_buffer#[1,lmb,dat,frame]
					if frame=0 then object_buffer#[3,lmb,dat,0]=0
				next dat
			next lmb		
		//endif
		didfunc=1
	endif

	//paste
	if getrawmousex()=>650 and getrawmousex()=<712 and getrawmousey()=>60 and getrawmousey()=<90 and playing=0 and didfunc=0
		frame=val(left(gettextstring(109),2))
		ok=questionmessage(365,250,"Paste Copied Frame?",10000,10000,10000,0)
		if ok=1 and frame=<80 and frame>-1
			for lmb=0 to 20 step 1
				for dat=1 to 11 step 1
					if frame<>0 then object_buffer#[1,lmb,dat,frame]=object_buffer#[3,lmb,dat,0]
					if frame=0 then object_buffer#[1,lmb,dat,frame]=object_buffer#[1,lmb,dat,0]+object_buffer#[3,lmb,dat,0]
				next dat
			next lmb		
			updateobject(1,20)
		endif
		didfunc=1
	endif


	//position edit
	if getrawmousex()=>260 and getrawmousex()=<325 and getrawmousey()=>55 and getrawmousey()=<73 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(101),9))
		value#=valfloat(newstring$)
		frame=val(left(gettextstring(109),2))
		object_buffer#[1,mylimb,1,frame]=value#
		updateobject(1,20)
		lastedit=0
		didfunc=1
	endif
	if getrawmousex()=>335 and getrawmousex()=<401 and getrawmousey()=>55 and getrawmousey()=<73 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(104),9))
		value#=valfloat(newstring$)
		frame=val(left(gettextstring(109),2))
		object_buffer#[1,mylimb,2,frame]=value#
		updateobject(1,20)
		lastedit=1
		didfunc=1
	endif
	if getrawmousex()=>406 and getrawmousex()=<475 and getrawmousey()=>55 and getrawmousey()=<73 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(107),9))
		value#=valfloat(newstring$)
		frame=val(left(gettextstring(109),2))
		object_buffer#[1,mylimb,3,frame]=value#
		updateobject(1,20)
		lastedit=2
		didfunc=1
	endif
	
	//rotation edit
	if getrawmousex()=>260 and getrawmousex()=<325 and getrawmousey()=>77 and getrawmousey()=<97 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(102),9))
		value#=valfloat(newstring$)
		frame=val(left(gettextstring(109),2))
		object_buffer#[1,mylimb,4,frame]=value#
		updateobject(1,20)
		lastedit=3
		didfunc=1
	endif
	if getrawmousex()=>335 and getrawmousex()=<401 and getrawmousey()=>77 and getrawmousey()=<97 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(105),9))
		value#=valfloat(newstring$)
		frame=val(left(gettextstring(109),2))
		object_buffer#[1,mylimb,5,frame]=value#
		updateobject(1,20)
		lastedit=4
		didfunc=1
	endif
	if getrawmousex()=>406 and getrawmousex()=<475 and getrawmousey()=>77 and getrawmousey()=<97 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(108),9))
		value#=valfloat(newstring$)
		frame=val(left(gettextstring(109),2))
		object_buffer#[1,mylimb,6,frame]=value#
		updateobject(1,20)
		lastedit=5
		didfunc=1
	endif	
	//scale info not saved fyi
	if getrawmousex()=>260 and getrawmousex()=<325 and getrawmousey()=>100 and getrawmousey()=<120 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(113),9))
		value#=valfloat(newstring$)
		if value#<0.01 then value#=0.01
		 
		//frame=val(left(gettextstring(113),2))
		object_scale#[1,0]=(value#-1.0)
		updateobject(1,20)
		lastedit=6
		didfunc=1
	endif
	if getrawmousex()=>333 and getrawmousex()=<401 and getrawmousey()=>100 and getrawmousey()=<120 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(114),9))
		value#=valfloat(newstring$)
		if value#<0.01 then value#=0.01
		 
		//frame=val(left(gettextstring(113),2))
		object_scale#[1,1]=(value#-1.0)
		updateobject(1,20)
		lastedit=7
		didfunc=1
	endif
	if getrawmousex()=>406 and getrawmousex()=<474 and getrawmousey()=>100 and getrawmousey()=<120 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,left(gettextstring(115),9))
		value#=valfloat(newstring$)
		if value#<0.01 then value#=0.01
		 
		//frame=val(left(gettextstring(113),2))
		object_scale#[1,2]=(value#-1.0)
		updateobject(1,20)
		lastedit=8
		didfunc=1
	endif
	
	
	//parent
	if getrawmousex()=>407 and getrawmousex()=<475 and getrawmousey()=>31 and getrawmousey()=<50 and mylimb>0 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,2,10000,10000,10000,left(gettextstring(106),2))
		value=val(newstring$)
		if value<0 then value=0
		if value=>20 then value=20
		if getlimbexists(1,value)=1 and getlimbexists(1,mylimb)=1 and value<>mylimb
			settextstring(106,str(value))
			//setobjectframe(1,value)
			setlimbparent(1,mylimb,value)
			updateobject(1,20)
		endif
		didfunc=1
	endif
	
	//frame
	if getrawmousex()=>500 and getrawmousex()=<568 and getrawmousey()=>31 and getrawmousey()=<50 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,2,10000,10000,10000,left(gettextstring(109),2))
		value=val(newstring$)
		if value<0 then value=0
		if value=>80 then value=80
		settextstring(109,str(value))
		setobjectframe(1,value)
		updateobject(1,20)
		didfunc=1
	endif
	//frame start
	if getrawmousex()=>575 and getrawmousex()=<643 and getrawmousey()=>31 and getrawmousey()=<50 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,2,10000,10000,10000,left(gettextstring(110),2))
		value=val(newstring$)
		if value<0 then value=0
		if value=>80 then value=80
		settextstring(110,str(value))
		//setobjectframe(1,value)
		gstart=val(gettextstring(110))
			gend=val(gettextstring(111))
			if gstart=>80 then gstart=80
			if gstart=<0 then gstart=0
			if gend=>80 then gend=80
			if gend=<0 then gend=0
			speed#=valfloat(gettextstring(112))
			if speed#=<0.01 then speed#=0.01
			if speed#=>1.0 then speed#=1.0
			if playing=1 then runanimationtransition(1,gstart,gend,1,speed#,20)
			didfunc=1
	endif	
	
	//frame end
	if getrawmousex()=>649 and getrawmousex()=<716 and getrawmousey()=>31 and getrawmousey()=<50 and playing=0 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,2,10000,10000,10000,left(gettextstring(111),2))
		value=val(newstring$)
		if value<0 then value=0
		if value=>80 then value=80
		settextstring(111,str(value))
		//setobjectframe(1,value)
		gstart=val(gettextstring(110))
			gend=val(gettextstring(111))
			if gstart=>80 then gstart=80
			if gstart=<0 then gstart=0
			if gend=>80 then gend=80
			if gend=<0 then gend=0
			speed#=valfloat(gettextstring(112))
			if speed#=<0.01 then speed#=0.01
			if speed#=>1.0 then speed#=1.0
			if playing=1 then runanimationtransition(1,gstart,gend,1,speed#,20)
			didfunc=1
	endif		
	
	//frame speed
	if getrawmousex()=>722 and getrawmousex()=<791 and getrawmousey()=>31 and getrawmousey()=<50 and didfunc=0
		newstring$=joystickkeyboard$(0,200,0,5,10000,10000,10000,left(gettextstring(112),5))
		value#=valfloat(left(newstring$,5))
		if value#<0.01 then value#=0.01
		if value#=>1.0 then value#=1.0
		settextstring(112,left(str(value#),5))
		setobjectspeed(1,value#)
		speed#=value#
		didfunc=1
	endif	



//colors r,g,b,a
	if getrawmousex()=>501 and getrawmousex()=<540 and getrawmousey()=>100 and getrawmousey()=<119 and playing=0 and didfunc=0
		value=object_buffer#[1,mylimb,8,frame]
		newstring$=joystickkeyboard$(0,200,0,4,10000,10000,10000,str(value))
		value=val(left(newstring$,4))
		if value<0 then value=0
		if value=>256 then value=256
		if frame>0 then object_buffer#[1,mylimb,8,frame]=val(left(str(value),4))-object_buffer#[1,mylimb,8,0]
		if frame=0 then object_buffer#[1,mylimb,8,frame]=val(left(str(value),4))
		didfunc=1
	endif
	
	if getrawmousex()=>575 and getrawmousex()=<614 and getrawmousey()=>100 and getrawmousey()=<119 and playing=0 and didfunc=0
		value=object_buffer#[1,mylimb,9,frame]
		newstring$=joystickkeyboard$(0,200,0,4,10000,10000,10000,str(value))
		value=val(left(newstring$,4))
		if value<0 then value=0
		if value=>256 then value=256
		if frame>0 then object_buffer#[1,mylimb,9,frame]=val(left(str(value),4))-object_buffer#[1,mylimb,9,0]
		if frame=0 then object_buffer#[1,mylimb,9,frame]=val(left(str(value),4))
		didfunc=1
	endif	
	if getrawmousex()=>649 and getrawmousex()=<689 and getrawmousey()=>100 and getrawmousey()=<119 and playing=0 and didfunc=0
		value=object_buffer#[1,mylimb,10,frame]
		newstring$=joystickkeyboard$(0,200,0,4,10000,10000,10000,str(value))
		value=val(left(newstring$,4))
		if value<0 then value=0
		if value=>256 then value=256
		if frame>0 then object_buffer#[1,mylimb,10,frame]=val(left(str(value),4))-object_buffer#[1,mylimb,10,0]
		if frame=0 then object_buffer#[1,mylimb,10,frame]=val(left(str(value),4))
		didfunc=1
	endif	
	if getrawmousex()=>722 and getrawmousex()=<762 and getrawmousey()=>100 and getrawmousey()=<119 and playing=0 and didfunc=0
		value=object_buffer#[1,mylimb,7,frame]
		newstring$=joystickkeyboard$(0,200,0,4,10000,10000,10000,str(value))
		value=val(left(newstring$,4))
		if value<0 then value=0
		if value=>256 then value=256
		if frame>0 then object_buffer#[1,mylimb,7,frame]=val(left(str(value),4))-object_buffer#[1,mylimb,7,0]
		if frame=0 then object_buffer#[1,mylimb,7,frame]=val(left(str(value),4))
		didfunc=1
	endif	
	//transparency
	if getrawmousex()=>779 and getrawmousex()=<792 and getrawmousey()=>100 and getrawmousey()=<119 and playing=0 and didfunc=0
		
		value=object_buffer#[1,mylimb,11,0]
		value=value+1
		if value=>2 then value=0
		object_buffer#[1,mylimb,11,0]=value
		didfunc=1
	endif	
	
	
	
	//play model
	if getrawmousex()=>500 and getrawmousex()=<560 and getrawmousey()=>60 and getrawmousey()=<90 and didfunc=0
		didfunc=1
		playing=playing+1
		if playing=>2 then playing=0
		if playing=1
			if getobjectexists(limb_start_obj+(1*20)+mylimb)=1 then setobjectcolor(limb_start_obj+(1*20)+mylimb,255,255,255,255)
			settextstring(4,"STOP")
			gstart=val(gettextstring(110))
			gend=val(gettextstring(111))
			if gstart=>80 then gstart=80
			if gstart=<0 then gstart=0
			if gend=>80 then gend=80
			if gend=<0 then gend=0
			speed#=valfloat(left(gettextstring(112),4))
			if speed#=<0.01 then speed#=0.01
			if speed#=>1.0 then speed#=1.0
			runanimationtransition(1,gstart,gend,1,speed#,20)
		endif
		
		if playing=0
			settextstring(4,"PLAY")
			stopobject(1)
			setobjectframe(1,gstart)
		endif
		
	endif
	
	
	
	//open model
	if getrawmousex()=>10 and getrawmousex()=<145
		
		//clear model
		if getrawmousey()=>80 and getrawmousey()=<112 and playing=0 and didfunc=0
			ok=questionmessage(365,250,"Clear The Scene?",10000,10000,10000,0)
			if ok=1 then clearscene()
			didfunc=1
		endif
		
		
		
		if getrawmousey()=>10 and getrawmousey()=<40 and playing=0 and didfunc=0
			//open model
			//end
			didfunc=1
			myfile$=functionfile$(212,150,2000,2000,2000,currentfile$,"ob2","Open Animated Model...",1)
			if myfile$<>"" and myfile$<>"NULL" 
				currentfile$=myfile$
				//load this puppy in
				//clearscene()
				loadanimatedmodel(1,"",currentfile$,1)
				//playobject(1,0,30,1,0.05,20)
				settextstring(110,"0")
				settextstring(111,"80")
				settextstring(112,"0.05")
				speed#=0.05
				setobjectlightmode(1,1)
				
				
				//lets load pivot point
				//loadobject2(1,"pivotpoint.obj","")
				object_filenames$[1,0,0]="pivotpoint.obj"
				object_filenames$[1,0,1]=""
				playing=0
				hidelimb(1,0)
				for t=0 to max_objects step 1
					object_scale#[t,0]=0
					object_scale#[t,1]=0
					object_scale#[t,2]=0
				next t
				
				updateobject(1,20)
				
				
			endif
			
		endif
	endif
	//save model
	if getrawmousex()=>10 and getrawmousex()=<145
		if getrawmousey()=>45 and getrawmousey()=<75 and playing=0 and didfunc=0
			didfunc=1
			myfile$=functionfile$(212,150,2000,2000,2000,currentfile$,"ob2","Save Animated Model...",0)
			if myfile$<>"" and myfile$<>"NULL" and myfile$<>"null" 
				currentfile$=myfile$
				//save this puppy
				if getfileexists(currentfile$)=1 
					if questionmessage(365,250,"Overwrite File?",10000,10000,10000,0)=1
						saveanimatedmodel(1,currentfile$,1)
						//playobject(1,0,30,1,0.05,20)
						settextstring(110,"0")
						settextstring(111,"80")
						settextstring(112,"0.05")
						speed#=0.05
						setobjectlightmode(1,1)
					endif
				endif

				if getfileexists(currentfile$)=0
					saveanimatedmodel(1,currentfile$,1)
					//playobject(1,0,30,1,0.05,20)
					settextstring(110,"0")
					settextstring(111,"80")
					settextstring(112,"0.05")
					speed#=0.05
					setobjectlightmode(1,1)
				endif
				
				
			endif
			
			//save model
			//end
		endif
	endif	
	
	
	//load image
	if getrawmousex()=>800 and getrawmousex()=<935
		if getrawmousey()=>10 and getrawmousey()=<40 and playing=0 and didfunc=0
			didfunc=1
			//load image
			if getlimbexists(1,mylimb)=1
				myfile$=functionfile$(212,150,2000,2000,2000,"","png","Open Texture File...",1)
				if getfileexists(myfile$)=1 
					//limb=mylimb
					//object1=1
					texture$=myfile$
					object_filenames$[1,mylimb,1]=texture$
					if getimageexists(limb_start_obj+(1*20)+mylimb)=1 then deleteimage(limb_start_obj+(1*20)+mylimb)
					loadimage(limb_start_obj+(1*20)+mylimb,texture$,1)
					if getobjectexists(limb_start_obj+(1*20)+mylimb)=1 then setobjectimage(limb_start_obj+(1*20)+mylimb,limb_start_obj+(1*20)+mylimb,0)
				endif
				
			endif
			
		endif
	endif
		
	//load object
	if getrawmousex()=>800 and getrawmousex()=<935
		if getrawmousey()=>45 and getrawmousey()=<75 and mylimb<>0 and playing=0 and didfunc=0
			didfunc=1
			//load object... this replaces whatever limb we have
			if getobjectexists(limb_start_obj+(1*20)+mylimb)=1
				ok=questionmessage(365,250,"Delete Current Object?",10000,10000,10000,0)
				if ok=1 
					deleteobject(limb_start_obj+(1*20)+mylimb)
					object_filenames$[1,mylimb,0]=""
					object_filenames$[1,mylimb,1]=""
				endif
			endif
			
			if getobjectexists(limb_start_obj+(1*20)+mylimb)=0
				//ok lets load it in
				//no linkage nessesary
				//use pre existing linkage
				myfile$=functionfile$(212,150,2000,2000,2000,"","obj","Open Object File...",1)
				if getfileexists(myfile$)=1
					loadobject(limb_start_obj+(1*20)+mylimb,myfile$)
					object_filenames$[1,mylimb,0]=myfile$
					object_filenames$[1,mylimb,1]=""
				endif
			endif
			
		endif
	endif	
	

	//clean obj folder
	if getrawmousex()=>800 and getrawmousex()=<935
		if getrawmousey()=>80 and getrawmousey()=<110 and playing=0 and didfunc=0
			didfunc=1
			ok=questionmessage(365,250,"Clean Mydocs Folder",10000,10000,10000,1)
			ok=questionmessage(365,250,"This Also Clears Scene",10000,10000,10000,1)
			ok=questionmessage(365,250,"Delete all obj files...",10000,10000,10000,0)
			if ok=1
				clearscene()
				//b=SetCurrentDir(".")
				setfolder("")
				a$=getfirstfile()
				if right(a$,3)="obj"
					deletefile(a$)
				endif
				filesmax99=1000
				for c=1 to filesmax99 step 1
					a$=getnextfile()
					if a$<>"" and right(a$,3)="obj"
						deletefile(a$)
					endif
				next c
				setfolder("media")
				//copy blank pivot file
				loadobj(2,"pivotpoint.obj")
				setfolder("")
				savenewobject(2,"pivotpoint.obj",1,1)
				deleteobject(2)
				
				setfolder("media")
			endif
			
		endif
	endif


	
	//edit ground height
	if getrawmousex()=>260 and getrawmousex()=<326 and getrawmousey()=>32 and getrawmousey()=<49 and didfunc=0
		didfunc=1
		newstring$=joystickkeyboard$(0,200,0,9,10000,10000,10000,gettextstring(100))
		value#=valfloat(newstring$)
		if value#>200.00 then value#=200.00
		if value#=<-200.00 then value#=-200.00
		setobjectposition(22,0,value#,0)
	endif
	//limb active
	if getrawmousex()=>333 and getrawmousex()=<400 and getrawmousey()=>32 and getrawmousey()=<49 and didfunc=0
		didfunc=1
		newstring$=joystickkeyboard$(0,200,0,2,10000,10000,10000,gettextstring(103))
		value=val(newstring$)
		if value>20 then value=20
		if value=<0 then value=0
		//setobjectposition(22,0,value#,0)
		if getobjectexists(limb_start_obj+(1*20)+mylimb)=1 then setobjectcolor(limb_start_obj+(1*20)+mylimb,255,255,255,255)
		mylimb=value
	endif
	


	
endif


	//keyboard shortcuts
	if getrawkeyreleased(38)=1
		//upkey
		if getobjectexists(limb_start_obj+(1*20)+mylimb)=1 then setobjectcolor(limb_start_obj+(1*20)+mylimb,255,255,255,255)
		mylimb=mylimb+1
		if mylimb=>19 then mylimb=19
		if mylimb=<0 then mylimb=0
	endif
	if getrawkeyreleased(40)=1
		//downkey
		if getobjectexists(limb_start_obj+(1*20)+mylimb)=1 then setobjectcolor(limb_start_obj+(1*20)+mylimb,255,255,255,255)
		mylimb=mylimb-1
		if mylimb=>19 then mylimb=19
		if mylimb=<0 then mylimb=0
	endif
	//move keyframes with left and right
	if getrawkeyreleased(37)=1 and playing=0
		//leftkey
		value=val(gettextstring(109))
		value=value-1
		if value=<0 then value=0
		if value=>80 then value=80
		settextstring(109,str(value))
		setobjectframe(1,value)
		updateobject(1,20)
	endif
	if getrawkeyreleased(39)=1 and playing=0
		//rightkey
		value=val(gettextstring(109))
		value=value+1
		if value=<0 then value=0
		if value=>80 then value=80
		settextstring(109,str(value))
		setobjectframe(1,value)
		updateobject(1,20)
	endif

	if getrawkeyreleased(81)=1 and playing=0
		//q
		//pos x
		if lastedit=<2
			newstring$=left(gettextstring(101),9)
			value#=valfloat(newstring$)
			value#=value#+1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,1,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>3 and lastedit=<5
			newstring$=left(gettextstring(102),9)
			value#=valfloat(newstring$)
			value#=value#+1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,4,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		
		if lastedit=>6
			newstring$=left(gettextstring(113),9)
			value#=valfloat(newstring$)
			value#=value#+0.05
			//frame=val(left(gettextstring(113),2))
			object_scale#[1,0]=(value#-1.0)
			updateobject(1,20)
			//lastedit=0
		endif
	endif
	
	if getrawkeyreleased(87)=1 and playing=0
		//w
		//pos y
		if lastedit=<2
			newstring$=left(gettextstring(104),9)
			value#=valfloat(newstring$)
			value#=value#+1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,2,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>3 and lastedit=<5
			newstring$=left(gettextstring(105),9)
			value#=valfloat(newstring$)
			value#=value#+1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,5,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>6
			newstring$=left(gettextstring(114),9)
			value#=valfloat(newstring$)
			value#=value#+0.05
			//frame=val(left(gettextstring(114),2))
			object_scale#[1,1]=(value#-1.0)
			updateobject(1,20)
			//lastedit=0
		endif
		
	endif

	if getrawkeyreleased(69)=1 and playing=0
		//e
		//pos z
		if lastedit=<2
			newstring$=left(gettextstring(107),9)
			value#=valfloat(newstring$)
			value#=value#+1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,3,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>3 and lastedit=<5
			newstring$=left(gettextstring(108),9)
			value#=valfloat(newstring$)
			value#=value#+1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,6,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>6
			newstring$=left(gettextstring(115),9)
			value#=valfloat(newstring$)
			value#=value#+0.05
			//frame=val(left(gettextstring(115),2))
			object_scale#[1,2]=(value#-1.0)
			updateobject(1,20)
			//lastedit=0
		endif
	endif	
	
	
	if getrawkeyreleased(65)=1 and playing=0
		//a
		//pos x
		if lastedit=<2
			newstring$=left(gettextstring(101),9)
			value#=valfloat(newstring$)
			value#=value#-1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,1,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>3 and lastedit=<5
			newstring$=left(gettextstring(102),9)
			value#=valfloat(newstring$)
			value#=value#-1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,4,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>6
			newstring$=left(gettextstring(113),9)
			value#=valfloat(newstring$)
			value#=value#-0.05
			if value#<0.05 then value#=0.05
			//frame=val(left(gettextstring(113),2))
			object_scale#[1,0]=(value#-1.0)
			updateobject(1,20)
			//lastedit=0
		endif
	endif	
	
	if getrawkeyreleased(83)=1 and playing=0
		//s
		//pos y
		if lastedit=<2
			newstring$=left(gettextstring(104),9)
			value#=valfloat(newstring$)
			value#=value#-1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,2,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>3 and lastedit=<5
			newstring$=left(gettextstring(105),9)
			value#=valfloat(newstring$)
			value#=value#-1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,5,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>6
			newstring$=left(gettextstring(114),9)
			value#=valfloat(newstring$)
			value#=value#-0.05
			if value#<0.05 then value#=0.05
			//frame=val(left(gettextstring(113),2))
			object_scale#[1,1]=(value#-1.0)
			updateobject(1,20)
			//lastedit=0
		endif
	endif	
	
	if getrawkeyreleased(68)=1 and playing=0
		//d
		//pos z
		if lastedit=<2
			newstring$=left(gettextstring(107),9)
			value#=valfloat(newstring$)
			value#=value#-1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,3,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>3 and lastedit=<5
			newstring$=left(gettextstring(108),9)
			value#=valfloat(newstring$)
			value#=value#-1.0
			frame=val(left(gettextstring(109),2))
			object_buffer#[1,mylimb,6,frame]=value#
			updateobject(1,20)
			//lastedit=0
		endif
		if lastedit=>6
			newstring$=left(gettextstring(115),9)
			value#=valfloat(newstring$)
			value#=value#-0.05
			if value#<0.05 then value#=0.05
			//frame=val(left(gettextstring(113),2))
			object_scale#[1,2]=(value#-1.0)
			updateobject(1,20)
			//lastedit=0
		endif
	endif
	
	
	
	
endfunction

function clearscene()
	//if ok=1
				//clear the scene
				deleteanimatedobject(1)
				//lets load pivot point
				setfolder("media")
				//copy blank pivot file
				loadobj(2,"pivotpoint.obj")
				setfolder("")
				savenewobject(2,"pivotpoint.obj",1,1)
				deleteobject(2)
				setfolder("media")
				
				for t=0 to max_objects step 1
					object_scale#[t,0]=0
					object_scale#[t,1]=0
					object_scale#[t,2]=0
				next t
				settextstring(113,"1.0" )
				settextstring(114,"1.0")
				settextstring(115,"1.0")
				
				loadobject2(1,"pivotpoint.obj","")
				playing=0
				hidelimb(1,0)
				mylimb=1
				settextstring(103,left( str(mylimb) ,9))
				value=object_buffer#[1,mylimb,0,0] //parrent
				settextstring(106,left( str(value) ,9))
				//what frame am i on
				value=0
				setobjectframe(1,0)
				settextstring(109,left( str(value) ,5))
			//endif
endfunction
