Notifications
Clear all

[Closed] Querying bone orientation problem

Hi,

I am scripting the alignment of an object to a bone. I need to copy the world z rotation of a bone to the world z rotation of a mesh object. If I open the Rotate Transform Type-In window (ref coord sys set to world), I see that the bone has a zero value in Z. However, when I query the bone using “in coordsys world radToDeg bone.rotation.z” i get a value of 28 something degrees. So as I align, the aligned object ends up with a wonky orientation.

Is there any particular reason for this difference in bone rotation between the type-in tool and what the script sees?

Thanks,
Rune

5 Replies

I solved the problem using vector math instead, creating a vector from the start to the end of the bone, and calculating the angle from that.

 JHN

Hi Rune, could you tell me how you retreive the end of the bone pos?

Thanks,
-Johan

Hi there Johan,

In this case it was easy, I could just pick the position of the next bone in the chain

But here’s a piece of code that might do the trick:

fn boneEnd obj =
(	
	-- Bone vector at origo
	local boneVec = [obj.length, 0 ,0]
	
	-- Align the vector to the bone
	boneVec = boneVec * inverse (obj.rotation as matrix3)
	
	-- Offset the vector to the bone
	boneVec = boneVec + obj.pos
	
	return boneVec
)

point pos:(boneEnd $)

This works with the default bones I have in my 3ds max, but there are most likely cases where it won’t work. So no responsibilities for loss of scenefiles or computers while using this function

Rune

 JHN

Hi Rune,

Thanks for the code, I did some work on it to account for scaling and stretching


 	fn boneEnd obj =
 	(	
 		-- Bone vector at origo
 		local boneStretch = obj.transform.scale.x * obj.inode.stretchTM.scale.x * obj.length
 		local boneVec = [boneStretch, 0 ,0]
 		
 		-- Align the vector to the bone
 		boneVec = boneVec * inverse (obj.rotation as matrix3)
 		
 		-- Offset the vector to the bone
 		boneVec = boneVec + obj.pos
 		
 		return boneVec
 	)
 

This is the code that I came up with myself, it’s somewhat similar with different code… my vector math is quit weak i hate to say…


    (preTranslate o.transform [(o.inode.stretchTM.scale.x * o.length),0,0]).pos
 

Is freelancing working out for you, hope so…

Cheers,
-Johan

I’m (sometimes) good with vectors, and now that I bought the Matrix Explained DVD that Bobo did, I hope I can finally get to understand matrices as well. Impressive you managed to condense it to one line. I tend to come up with solutions, but they’re always kind of verbose. Glad it worked out for you

Freelancing has been fantastic so far! Struggled abit with RSI at the start, but that seems to wear off now. Things are looking really bright