Notifications
Clear all

[Closed] Dynamic Parenting and Animatable Pivot Scripts

Hello,

I’m not sure why, but I don’t tend to share a lot of what I do with the community, but I read the maxObjectTab tutorial on Paul Neale’s website and got some extra help with the same subject on here so I decided I’d share two scripts that I quickly created.

Dynamic Parenting:


(
	delete objects
	
	redBox = Box name:"Red Box" position:[-30,0,0] wireColor:red length:20 width:20 height:20
	greenBox = Box name:"Green Box" position:[0,0,0] wireColor:green length:20 width:20 height:20
	blueBox = Box name:"Blue Box" position:[30,0,0] wireColor:blue length:20 width:20 height:20
	parentPt = Point name:"Parent Point" position:[0,0,0] centerMarker:false axisTripod:false cross:false box:false size:0
	childBox = Box name:"Child Box" position:[0,30,0] wireColor:yellow length:10 width:10 height:10
	
	childBox.parent = parentPt
	
	posCon = Position_Constraint()
	posCon.appendTarget redBox 0
	posCon.appendTarget greenBox 0
	posCon.appendTarget blueBox 0
	parentPt.position.controller = posCon
	
	rotCon = Orientation_Constraint()
	rotCon.appendTarget redBox 0
	rotCon.appendTarget greenBox 0
	rotCon.appendTarget blueBox 0
	parentPt.rotation.controller = rotCon
	
	ca = attributes myParentTest 
	(
		parameters myParentP rollout:myParentR
		(
			listItem type:#integer ui:parentList default:1
			objectTab type:#maxObjectTab tabSizeVariable:on tabSize:0
		)
		
		rollout myParentR "Parent Switching"
		(
			dropDownList parentList "Parent List:" items:#("World", "Red", "Green", "Blue")
			
			on parentList selected item do
			(
				childRot = objectTab[2].node.rotation
				childPos = objectTab[2].node.position

				disableSceneRedraw()
				
				with animate on
				(
					sliderTime += -1
					case of
					(
						(objectTab[1].node.position.controller.getWeight 1 == 0 and objectTab[1].node.position.controller.getWeight 2 == 0 and objectTab[1].node.position.controller.getWeight 3 == 0):
						(
							objectTab[1].node.position.controller.setWeight 1 0
							objectTab[1].node.position.controller.setWeight 2 0
							objectTab[1].node.position.controller.setWeight 3 0
							objectTab[1].node.rotation.controller.setWeight 1 0
							objectTab[1].node.rotation.controller.setWeight 2 0
							objectTab[1].node.rotation.controller.setWeight 3 0
							objectTab[2].node.rotation = childRot
							objectTab[2].node.position = childPos
						)
						(objectTab[1].node.position.controller.getWeight 1 == 100):
						(
							objectTab[1].node.position.controller.setWeight 1 100
							objectTab[1].node.position.controller.setWeight 2 0
							objectTab[1].node.position.controller.setWeight 3 0
							objectTab[1].node.rotation.controller.setWeight 1 100
							objectTab[1].node.rotation.controller.setWeight 2 0
							objectTab[1].node.rotation.controller.setWeight 3 0
							objectTab[2].node.rotation = childRot
							objectTab[2].node.position = childPos
						)
						(objectTab[1].node.position.controller.getWeight 2 == 100):
						(
							objectTab[1].node.position.controller.setWeight 1 0
							objectTab[1].node.position.controller.setWeight 2 100
							objectTab[1].node.position.controller.setWeight 3 0
							objectTab[1].node.rotation.controller.setWeight 1 0
							objectTab[1].node.rotation.controller.setWeight 2 100
							objectTab[1].node.rotation.controller.setWeight 3 0
							objectTab[2].node.rotation = childRot
							objectTab[2].node.position = childPos
						)
						(objectTab[1].node.position.controller.getWeight 3 == 100):
						(
							objectTab[1].node.position.controller.setWeight 1 0
							objectTab[1].node.position.controller.setWeight 2 0
							objectTab[1].node.position.controller.setWeight 3 100
							objectTab[1].node.rotation.controller.setWeight 1 0
							objectTab[1].node.rotation.controller.setWeight 2 0
							objectTab[1].node.rotation.controller.setWeight 3 100
							objectTab[2].node.rotation = childRot
							objectTab[2].node.position = childPos
						)
					)
					
					sliderTime += 1
					
					case of
					(
						(item == 1):
						(
							objectTab[1].node.position.controller.setWeight 1 0
							objectTab[1].node.position.controller.setWeight 2 0
							objectTab[1].node.position.controller.setWeight 3 0
							objectTab[1].node.rotation.controller.setWeight 1 0
							objectTab[1].node.rotation.controller.setWeight 2 0
							objectTab[1].node.rotation.controller.setWeight 3 0
							objectTab[2].node.rotation = childRot
							objectTab[2].node.position = childPos
						)
						(item == 2):
						(
							objectTab[1].node.position.controller.setWeight 1 100
							objectTab[1].node.position.controller.setWeight 2 0
							objectTab[1].node.position.controller.setWeight 3 0
							objectTab[1].node.rotation.controller.setWeight 1 100
							objectTab[1].node.rotation.controller.setWeight 2 0
							objectTab[1].node.rotation.controller.setWeight 3 0
							objectTab[2].node.rotation = childRot
							objectTab[2].node.position = childPos
						)
						(item == 3):
						(
							objectTab[1].node.position.controller.setWeight 1 0
							objectTab[1].node.position.controller.setWeight 2 100
							objectTab[1].node.position.controller.setWeight 3 0
							objectTab[1].node.rotation.controller.setWeight 1 0
							objectTab[1].node.rotation.controller.setWeight 2 100
							objectTab[1].node.rotation.controller.setWeight 3 0
							objectTab[2].node.rotation = childRot
							objectTab[2].node.position = childPos
						)
						(item == 4):
						(
							objectTab[1].node.position.controller.setWeight 1 0
							objectTab[1].node.position.controller.setWeight 2 0
							objectTab[1].node.position.controller.setWeight 3 100
							objectTab[1].node.rotation.controller.setWeight 1 0
							objectTab[1].node.rotation.controller.setWeight 2 0
							objectTab[1].node.rotation.controller.setWeight 3 100
							objectTab[2].node.rotation = childRot
							objectTab[2].node.position = childPos
						)
					)
				)

				enableSceneRedraw()
			)
		)
	)
	
	addModifier childBox (EmptyModifier name:"Parent Switching")
	custAttributes.add childBox.modifiers[1] ca
	append childBox.modifiers[1].myParentTest.objectTab (nodeTransformMonitor node:parentPt forwardTransformChangeMsgs:false)
	append childBox.modifiers[1].myParentTest.objectTab (nodeTransformMonitor node:childBox forwardTransformChangeMsgs:false)
)

I uploaded a brief video to Vimeo showing how to work with it: https://vimeo.com/89361411

Animatable Pivot:


(
	delete objects
	
	myBox = Box name:"myBox"
	myAnimHelper = Point name:"animHelper" centerAxis:false axisTripod:false cross:false box:true
	myMoveHelper = Point name:"moveHelper" centerAxis:false axisTripod:false cross:true box:false
	myObjs = #(myBox, myAnimHelper, myMoveHelper)
	
	myAnimHelper.parent = myBox
	myMoveHelper.parent = myBox
	
	myBox.transform.controller = CATHDPivotTrans()
	myBox.transform.controller[#PRS].position.controller = Position_List()
	myAnimHelper.position.controller = Bezier_Position()
	myBox.transform.controller.pivot.controller = myAnimHelper.position.controller
	paramWire.connect myAnimHelper.transform.controller[#Position] myBox.transform.controller[#PRS][#Position][#Position_XYZ] "Position"
	myBox.transform.controller[#PRS][#Position][#Available].controller = Position_XYZ()
	myBox.transform.controller[#PRS][#Position].active = 2
	
	ca = attributes animPivotCA
	(
		parameters animPivotP rollout:animPivotR
		(
			nodeArray type:#maxObjectTab tabSize:0 tabSizeVariable:true
		)
		
		rollout animPivotR "Pivot Controls"
		(
			button hideMove "Show/Hide Mover" align:#center width:130
			button snapMove "Snap Pivot to Move" align:#center width:130
			
			on hideMove pressed do
				if nodeArray[2].node.isHidden == true then
				(
					nodeArray[2].node.isHidden = false
					nodeArray[3].node.isHidden = false
				)
				else
				(
					nodeArray[2].node.isHidden = true
					nodeArray[3].node.isHidden = true
				)
			on snapMove pressed do
			(
				myLocalPos = nodeArray[3].node.position.controller.value
				myPos = nodeArray[3].node.position
				myWorldPos = nodeArray[2].node.position
				
				nodeArray[2].node.position.controller.value = myLocalPos
				nodeArray[1].node.position= myPos
			)
		)
	)
	
	addModifier myBox (EmptyModifier())
	custAttributes.add myBox.modifiers[1] ca
	for a in myObjs do
		append myBox.modifiers[1].animPivotCA.nodeArray (nodeTransformMonitor node:a forwardTransformChangeMsgs:false)
)

The animatable pivot script is a strange one, it works perfectly well without Auto Key enabled but messes up with it on, but I thought it might be a good starting point for someone to do further development (I know Felix Joleanes has an animatable pivot plug-in but, hey, it’s fun trying to write your own stuff). It’s based on Jason Schleifer, use the cross helper to get the location of where you want the pivot to be and then “Snap Pivot to Move” button to actually reposition the pivot

Hopefully they’ll be of use to someone.
-Harry

1 Reply

Hey Harry,

Thanks for posting this stuff up. I learn a lot from this kind of thing.

On the animated pivot, there was a post in the rigging section a while back. A guy was trying to replicate this Maya tutorial in Max but couldn’t since Max’s animatable (CAT) pivot, in my experience anyway, doesn’t work very well.

http://forums.cgsociety.org/showthread.php?f=54&t=1142259

I see you’re using the CAT pivot and wonder if the Autokey on/off problems you’re having are just bugs with the CAT controller or something else?

Would the rolling pivot in these tutorials (below) even be possible using the CAT pivot? Would this be possible in Max at all? Or is this just another area exclusive to Maya?


Maya Cylindrical Foot Roll Demo
Sliding Pivot Foot Roll Tutorial