macroScript BipMatcher category:"Tools"\

	tooltip:"Match biped horizontal keys to target oobject"\

	buttontext:"BipMatcher"\



(



fn bip_filt obj = classof obj == Biped_Object

fn sel_by_name name = 

	(

	for test in objects do

		if test.name == name then 

			(return test

			exit)

	return ""

	)

	

Rollout BM "Biped Position matcher"

(

	pickbutton PBip "Choose Biped       >" across:2 width:120 filter:bip_filt

	edittext BipName text:"Bip01"

	pickbutton PTar "Choose Target      >" across:2 width:120

	edittext Tarname

	label SPC1 ""

	spinner starttime "Match movement from " range:[animationrange.start ,\

		animationrange.end ,\

		animationrange.start ] type:#integer across:3 fieldwidth:30 offset:[64,0]

	spinner Endtime "to " range:[animationrange.start,\

		animationrange.end,\

		animationrange.end] type:#integer fieldwidth:30 offset:[34,0]

	Spinner Step "by " type:#integer fieldwidth:24 range:[1,10,1] offset:[6,0]

	button BMgo "MatchMove"

	label SPC2 ""

	progressbar Pbar width:260 offset:[10,0]

	

	on Pbip picked bip do 

		(

		btemp = bip.name as stringstream

		seek btemp 0

		Bipname.text = ReadDelimitedString Btemp " "

		)

	

	on Ptar picked obj do Tarname.text = obj.name

	

	on BMgo pressed do

		(



		Currtime = slidertime

		target = Sel_by_name Tarname.text

		Follower = Sel_by_name BipName.text

		if target != "" and follower != ""  then

			(

			animbuttonenabled = false

			animate on

			slidertime = starttime.value

			DisableSceneRedraw()

			while slidertime < ((endtime.value) + 1) do

				(

				Offset = target.pos - Follower[3][2].value.translationpart

			   select follower

				move follower [offset.x, offset.y, 0]

				Pbar.value = 100 * ((slidertime.frame - starttime.value) / (endtime.value - starttime.value)) 

				if slidertime == animationrange.end then exit

				slidertime += Step.value

				)

		

			animate off

			animbuttonenabled = true

			Pbar.value = 0

			EnableSceneRedraw()

			slidertime = Currtime

			)

		else

			Messagebox "Target or Biped not found"

		)

	



)

BMwindow = NewRolloutFloater "BipMatcher" 320 240

Addrollout    BM BMwindow

)
