Notifications
Clear all

[Closed] shifting rotation from parent to childbone

Hello!

We have a problem with our motioncapturedata – for example the x-rotation of the hand is divided up on the hand and the forearm bone. This is a problem because only the hand controls the skinmorph or rollbones. (this goes for all 2-d joints really)

What I want to do is subtract the xrotation from the forearm and add it to the hand, shift the rotation without altering the overall result. I wrote the following script:

fn slideRotation objs =
(
objs = makeObjArray objs

for obj in objs do (
	p = obj.parent 
	if p == undefined do (
		format "% doesnt have a parent. Quitting.." obj.name
		return false
	)

	--save transform
	t = copy obj.transform

	--reset the rotation on the axis on the parent to its default - or 0

	--get the local euler rotation
	local tra = (p.transform*inverse(p.parent.transform)) --local transform
	local e = tra as eulerangles --angles


	--create the transform with the reset rotations
	/*
	m = matrix3 1
	m*=rotateXMAtrix 0
	m*=rotateYMAtrix e.y	
	m*=rotateZMAtrix e.z 

	m.translation = tra.translation --keep the translation
	m *= p.parent.transform --get it back to worldposition
	
	m = orthogonalize m --not sure if i need that

	p.transform = m
	*/
	
	--this actually gives the same result DOH :/
	in coordsys local rotate p (angleaxis -e.x [1,0,0])

	--reset the transform of the child object (transforms are handled in worldspace)
	obj.transform = t
)

)

fn DoSlideStuff objs =
(
slidertime=animationRange.start

with redraw off 
	with animate on (
		for f = animationRange.start to animationRange.end do (
		slideRotation objs 
		slidertime+=1
	)
)

)

DoSlideStuff $handbone

the thing is, it all works! when i check with an exposetransform on the forearm bone, the local x rotation is for the whole animation 0 and the allover pose is perfectly unchanged.

BUT yet the bone rotates in cases – how is that possible? It doesnt flip but gradually rotates around especially if there is alot of rotation in the inital version (i copied the whole rig and checked).

I really dont understand why this is happening, maybe there are other ways of solving this?

Thanks for any hints!

Sebastian Schoellhammer :banghead:

1 Reply

Ok i fixed it Well. the problem was wrong in the first place… a 0 rotation wasnt actually required to make it work! So all i did was constructed a “natural rotation” as it should be for a 2d joint… heres the code if anybody is interested!

seb



fn slideRotation objs  =
(
	objs = makeObjArray objs

	for obj in objs do (
		p = obj.parent 
		pP = p.parent
		if p == undefined do (
			format "% doesnt have a parent. Quitting.." obj.name
			return false
		)
	
		--save transform
		t = copy obj.transform
			
		--to get the "right rotation" i need a lookat contraint
		--create a transform matrix that works like a lookat from the "elbow" to the hand 
		
		vX = normalize (obj.position-p.position)
		vPParent = normalize (pP.position-p.position )
		vY = normalize (cross vPParent vX)
		vZ = normalize (cross vX vY)
		
		newT = matrix3 vX vY vZ p.position
		--newT = orthogonalize newT
		
		p.transform = newT
						
		--reset the transform of the child object (transforms are handled in worldspace)
		obj.transform = t
		
	)
)

fn DoSlideStuff objs = 
(
	slidertime=animationRange.start

	with redraw off 
		with animate on (
			for f = animationRange.start to animationRange.end do (
			slideRotation objs 
			slidertime+=1
		)
	)
)