How can I make per-bone non-uniform scaling code?

I want to make a character customizing system which is based on max bone scaling. For that, I searched non uniform scaling per bone and find this link.
http://www.gamedev.net/topic/484984-skeletal-animation---non-uniform-scale/

So, I made this code by maxscript.

fn ResetParentScale obj = 
(
	local oriTransform = obj.transform; --Get Original Transform of selected object
	local oriScaleMatrix = ScaleMatrix oriTransform.scale; --make scale space matrix
	local invParentScale = (inverse obj.parent.transform).scale; --make inverse of parentscale
	
	in coordsys oriScaleMatrix Rotate obj oriTransform.rotation; --rotate selected object to its rotation in scale space
		
	local modifiedTransform = obj.transform; --get rotated object transform
	
	PreScale modifiedTransform invParentScale; --applying scale
	Rotate modifiedTransform oriTransform.rotation; --rotate back again
	
	obj.transform = modifiedTransform; --set selected object transform
)

ResetParentScale $ --selected object is child of non uniform scaling bone. I want to reset scale of this bone to its original scale.

but as you can guess, it didn’t work. Could you help me to fix this problem?

I have no idea what you are trying to do.

If you want to do non-uniform scaling on bones, they MUST be leaf (child-most) bones. IE, make your entire character skeleton, then make a joint on top of the motion rig that is driven by the motion rig, everything is skinned to, and scales. If you try to scale nodes with children, you’re going to end up in a WORLD OF HURT.

If you adhere to those restrictions you will have a much easier/sane time and can avoid much or any code specifically for supporting it (as long as your animation system supports it).

Why I try to non-uniform scaling of bone that is for customizing body line of character. For example, I want to make two types of characters from one bone chain. First character has normal body line, but second character has thick upper arm, normal forearm and big hand. I want to do this kind of similar things by bone scaling.

As you know, I need to reset scale of child nodes to solve this problem. But 3ds max’s transform matrix is combined with scale and rotation, so when I multiply inverse scale of parent, child nodes’ scale is skewed. I want to fix it.

As your comment, uniform scaling or whole character non-uniform scaling is very easy and I want to go that way, but artists of my team want I go to “World of Hurt”. So, please, help me :slight_smile: