[Closed] 3DS maxscript autorig
Hi, i am new on this forum, but since it is where I find most of my ressources for maxscript, i figure i join in.
I recently decided to create an autorig system for my character to gain time when it come to pose them and to learn some coding. I know what kind of rig I wanted to do, but one week ago had no idea what coding was.
But I manage something.
As seen on the previous images, I have two button: one for creating the bones, and one to generate the control. And you can place your bone whereever you want between these two step.
My problem is : How could I mirror the right bone on the left bone (location and rotation)? My starting point is
(local sBones = (for obj in $* where (classof obj == bone) and (matchpattern obj.name pattern:'*.R' ignoreCase:false) collect obj)
--for each right bone
for sBone in sBones do
(
-- get the right bone position
bPos = sBone.pos
-- find name of the left bone
s1= ".R"
s2= ".L"
tBoneName = substituteString sBone.name s1 s2
--get left bone and move it
tBone = getnodebyname tBoneName
tBone.pos = [-bPos.pos.x , bPos.pos.y , bPos.pos.z ]
)
)
but the result is not enough:
and at this point I’m not sure how to proceed.
I’m glad to join in and thank you for your attention.
PS: all left bone name end up like *.L and right bone like *.R
tip:
the dot “.” seperator is best considered as a reserved key word/operator
so avoid “.” in any naming scheme
somethign.somethingelse
looks less like a name and more like an object.property or a class.method()
and is likely to get parsed that way
I generally use underscores
def_r_arm
def_r_leg
def_l_arm
def_l_leg
etc
To correctly flip bone you want to operate on the position values but on the transforms of the bones. Here is a function I use to match left to right bones in my rigs
fn mirrorBone ref obj=(
flipMatrix=scaleMatrix [1,-1,1] --Flip Y
mirrorMatrix=scaleMatrix [-1,1,1] --Mirror across X
obj.transform=flipMatrix*ref.transform*mirrorMatrix --multiply flip,mirror,and ref transforms and apply to obj
)
If matrix transforms are new to you, then welcome to the tip of the iceberg.
Bobo’s videos should get you started
hi Mambo4, Thanks frr the advice, it’s an old habit, but i’ll think about it. your piece of code work fine, i got this now
--fonction mirror
fn mirrorBone ref obj=
(
flipMatrix=scaleMatrix [1,-1,1] --Flip Y
mirrorMatrix=scaleMatrix [-1,1,1] --Mirror across X
obj.transform=flipMatrix*ref.transform*mirrorMatrix --multiply flip,mirror,and ref transforms and apply to obj
)
--get all Right Bones
sBones = for obj in $* where (classof obj == BoneGeometry) and (matchpattern obj.name pattern:"*_L" ignoreCase:false) collect obj
--for each right bone
for sBone in sBones do
(
-- get the right bone position
bPos = sBone.pos
-- find name of the left bone
s1= "_R"
s2= "_L"
tBoneName = substituteString sBone.name s1 s2
--get left bone and move it
tBone = getnodebyname tBoneName
mirrorBone sBone tBone
)
I didn’t get all the matrix stuff, but it’s now too late to understand it. i’ll look at it tomorrow.
Just one question, should i be worried about the orientation of the back fin?
So, I have been trying again to make this work… for a chain of 3 bone it worked, but in situation the whole thing explode…
It seems that having the bone moved via the bone tool keep me from using this method…
Should i rethink the whole thing?
You just have to think about your logic and order of operations it is totally doable.
You can’t just move child bones without their parents reacting(but you can break it) hence, when you move a child bone in bone edit mode the parent will auto adjust its rotation to properly point to the new position of the child node, but if you move the child bone with bone edit mode off notice that if you try to move it by hand you will be restrained by the parent bone and its length you will only be able to move the child bone around the parent’s radius and if you force a position value on the child bone through max script now you will have “broken the chain” they will still have the proper hierarchical relationship but the parent will be pointing to the child’s node last position and that is what you are getting(I think i have not ran your code, but from the screen Shot that is what looks like to be happening :)) it seems that you are lacking some of the basic understand of how bones work in max.
The simplest and hackiest way of doing this is to have bone edit mode turned on and then run your mirror process, it ain’t pretty but it works.
The next choice is to constraint your bones to points through position constraints and look -at constraints, perform your mirroring on the points and then blow away the points while maintaining the bones new transforms.
the last choice (there are more ways of doing this, but these are the 3 that come to mind at the time) is to recreate the bone chain with the mirrored values this is the cleaner way in my opinion and also the way I do my bone mirroring on my auto rigging system.
Cheers,
Hi, I dropped this a while, doing other stuff(and forgetting what i was trying to do) but i’m back. So i figured that it is complex to move all the stuf afterward, and it may be easier to think again the way of drawing the basic bone system (wich will allow me to clean up th code a bit). But i guess I lack logic at some point : I want to build a basic bone character (wich I did), be able to adapt it to any bipedal character, and keep it symmetrical. Could any of you explain how you would did something like that? or maybe have some link about this?
thanks