'******************************************************************************
'//
'// HandyMansScript Ver 1.0 by Graham D Clark
'// g@grahamdclark.com
'// Date : Wednesday, January 23rd, 2002
'// (c) Copyright 2001  Lawson&Clark
'//
'The HandyMansScripts purpose is to automate the task of attaching 'the ends of
'each finger and thumb to a shape to be shape animated 'for different hand 
'gestures. 
'It was inspired by sign language. "NTID at Rochester Institute of Technology is
'the worlds first and largest technological college for students who are deaf 
'and hard of hearing."
'The HandyMansScript works with most skeleton setups, including normal hands 
'with four fingers and one thumb or alien hands with three or whatever. 
'The HandyMansScript is also available in Mel, but some !~@#$% will copy this one
'and put it on highend anyway.
'******************************************************************************
'Usage:
'Perhaps test with the default XSI comples skeletons first.
'1.Select wrist part that you will be animating the orientaion of for entire 
' hand. On the XSI primitive skeleton that is RHand or RHandRoot.
'2.Select in order the fingers and thumb or either way, doesn't matter as long 
'as in order.
'3.'When script is complete shape animate the new object into hand gestures. The
'skeleton in this may need to be in its default position, when shape animating.
'Script can also be used for entire body, but it produces kind of a floaty 
'effect that would only be useful for swimming.
'4.Drag the new shapes onto the mixer and make custom sliders for them.
'Much easier than making and moving sliders for each finger.
'******************************************************************************
'Limitations:
'The disadvantage of this way of animating hands is that an inbetween position
'is often needed for example between the pose of the hand outstretched and in a 
'fist, the reason being as you'll see that the knuckles moveup over the plane of
'the back of the hand before the fingers are outstretched which is unnatural for 
'most :)
'Shape key at default position may be required or use constraints in script and
'orient the wrists
'******************************************************************************
'Modification: Shape animation with custom sliders could be added. This would 
'require auto-scaling the target shapes to work on each character. Not
'enough time, may come back to do this.
'******************************************************************************
Handi

Function Handi

'create an object containing a collection of all my effectors
set effectors = GetValue("SelectionList")
newname = GetValue(effectors.Items(0)&".Name")&"Handi"

'start curve to be called return of name
SICreateCurve newname, 1, 1

'finish curve adding points at each effectors position
num=0
if TypeName(effectors) = "Nothing" then
		LogMessage "No effectors selected" 	
	else
		for each thing in effectors
			set vector = CreateObject("Sumatra\Scripting\Math\SIVector3")	
			vector.x = GetValue(thing & ".kine.global.pos.posx")
			vector.y = GetValue(thing & ".kine.global.pos.posy")
			vector.z = GetValue(thing & ".kine.global.pos.posz")
			SIAddPointOnCurveAtEnd newname, vector.x, vector.y, vector.z, False
			SelectGeometryComponents newname&".pnt["&num&"]"
			CreateCluster
			if num > 0 then
					ApplyCns "ObjectToCluster", thing, newname&".crvlist.cls.Point"&num
				else
					set wrist = CreateObject("Sumatra\Scripting\Math\SIVector3")	
					wrist.x = vector.x 
					wrist.y = vector.y 
					wrist.z = vector.z 
			end if
			num = num + 1
		next
End if 
Translate newname, wrist.x, wrist.y, wrist.z, siAbsolute, siGlobal, siCtr, siXYZ
ParentObj effectors.Items(0), newname
'ApplyCns "Position", newname, effectors.Items(0), TRUE
'ApplyCns "Orientation", newname, effectors.Items(0), TRUE  
End Function