[Closed] Basic auto rig
Hi,
I started working on this script to learn a little about maxscript which is very new to me
and have a little problem in one of the steps.
it is a very basic start of a arm and leg ik setup based on a few points in space.
button 1 creates a few point which I place where ever the joints are.
button 2 creates 2 bone chains (based on a code I found in the threads by PEN)
button 3 align the bones to the points (this is were the I have a problem)
button 4 creates IK chains and controls.
on step 3, when I align the bones to the position of the the points they break up but still holding the hierarchy.
does anybody knows why that might happen?
Thanks
Asa
here the script
code:
–01 create points for leg and
–02 create bones
–03 align bones create ik
–04 create controls
rollout test_buttons “create rig”
(
button theButton “points” width:80 height:25
button createButton “Create Bone” width:80 height:25
button alignButton “align bone” width:80 height:25
button controlsButton “controls” width:80 height:25
———————————————————————-
–create points
on theButton pressed do
for i = 1 to 3 do
(
p = point pos:[i*25,0,0]
p2 = point pos:[0,0,i*-25]
)
–create bones
–for i = 1 to 3 do
on createButton pressed do
(
(
joints=#()
stPos=#([0,0,0],[0,-25,-100],[0,0,-200],[0,0,-205])
dir=[0,1,0]
)
(
jointsC=#()
stPosC=#([0,0,0],[100,50,0],[180,-40,0],[188.944,-45,0])
dirC=[0,0,1]
)
for i = 1 to 3 do
(
b=boneSys.createBone stPos[i] stPos[i+1] dir
if i>1 then b.parent=joints[i-1]
append joints b
)
for i = 1 to 3 do
(
c=boneSys.createBone stPosC[i] stPosC[i+1] dirC
if i>1 then c.parent=jointsC[i-1]
append jointsC c
)
)
on alignButton pressed do
(
$Bone01.pos = $point01.pos
$Bone02.pos = $point03.pos
$Bone03.pos = $point05.pos
$Bone04.pos = $point02.pos
$Bone05.pos = $point04.pos
$Bone06.pos = $point06.pos
iksys.ikchain $Bone01 $Bone03 “IKHISolver”
iksys.ikchain $Bone04 $Bone06 “IKHISolver”
)
on controlsButton pressed do
(
for i = 1 to 2 do
(
for i = 1 to 2 do
(
circle radius:10
)
$Circle01.pos=$Point05.pos
$Circle02.pos=$Point06.pos
select $‘IK Chain01’
$.parent = $Circle01
select $‘IK Chain02’
$.parent = $Circle02
)
)
)
createDialog test_buttons 150 150
I think the problem is in step 2 where you create the bones. When I press the “create bones” button, it creates the bones somewhere in 3d space. Why don’t you use the helpers coordinates to define the start and end positions for every bone instead of move/scaling them using the .pos = .pos?
If you would adjust your stPos values to the helpers positions, the bones would be already in position.
Furthermore I’d store the helpers position in a local variable so you can access that information from everywhere within your rollout.
I agree with the above, Also you want to make sure that you use the orientation of the helpers as well. The Z up value can be pulled from the helpers using the matrix of each helper with $.transform.row3. You then need to make sure that your point helpers all stay aligned as well. So what I do with this is link all the helpers in order and turn on the bone property for them and turn off freeze length. Also limit the point helper for the elbow to only rotate on Z. This way when the helpers are moved the parents look at them and when they are rotated the children follow. Before aligning anything to them make sure that you reset stretch on them. Of course you could just create the bones to start with and forgo the helpers.
Thanks zortech and Pen,
The idea with the helpers is that after they are created I place them according to my model.
I tried to simplify the script and took out the align button and tried to use the helpers coordinates to define the start and end positions for every bone.
But now i am getting this error
– Unable to convert: [25,0,0] to type: Float
how do i get a 3point and not a Float?
------------------------------------------------------------------------
rollout test_buttons "create rig"
(
button theButton "points" width:80 height:25
button createButton "Create Bone" width:80 height:25
button controlsButton "controls" width:80 height:25
----------------------------------------------------------------------
on theButton pressed do
for i = 1 to 3 do
(
p = point pos:[i*25,0,0]
p2 = point pos:[0,0,i*-25]
)
-----------------------------------------------------------------------------
on createButton pressed do
(
(
PP1 = $Point01.pos
PP2 = $Point02.pos
PP3 = $Point03.pos
PP4 = $Point04.pos
PP5 = $Point05.pos
PP6 = $Point06.pos
)
(
joints=#()
stPos=#([PP1,PP1,PP1],[PP3,PP3,PP3],[PP5,PP5,PP5],[0,0,PP5+5])
dir=[0,1,0]
)
(
jointsC=#()
stPosC=#([PP2,PP2,PP2],[PP4,PP4,PP4],[PP6,PP6,PP6],[PP6,PP6,PP6+5])
dirC=[0,0,1]
)
for i = 1 to 3 do
(
b=boneSys.createBone stPos[i] stPos[i+1] dir
if i>1 then b.parent=joints[i-1]
append joints b
)
for i = 1 to 3 do
(
c=boneSys.createBone stPosC[i] stPosC[i+1] dirC
if i>1 then c.parent=jointsC[i-1]
append jointsC c
)
)
-------------------------------------------------------------------------------
on controlsButton pressed do
(
for i = 1 to 2 do
(
for i = 1 to 2 do
(
circle radius:10
)
$Circle01.pos=$Point05.pos
$Circle02.pos=$Point06.pos
select $'IK Chain01'
$.parent = $Circle01
select $'IK Chain02'
$.parent = $Circle02
)
)
)
createDialog test_buttons 150 100
__________________
What you are getting is a point3 value so, point3.x or [25,0,0].x and .y,.z for the other two values.
Hi Asa, as mentioned above your variable PP1 etc … are already Point3 values. You cannot as far as I know nest a point3 inside a point3. I commented out 2 lines and replaced them with something that allows the script to execute.
The code below will show you what I did.
Cheers
Dan
rollout test_buttons "create rig"
(
button theButton "points" width:80 height:25
button createButton "Create Bone" width:80 height:25
button controlsButton "controls" width:80 height:25
----------------------------------------------------------------------
on theButton pressed do
for i = 1 to 3 do
(
p = point pos:[i*25,0,0]
p2 = point pos:[0,0,i*-25]
)
-----------------------------------------------------------------------------
on createButton pressed do
(
(
PP1 = $Point01.pos
PP2 = $Point02.pos
PP3 = $Point03.pos
PP4 = $Point04.pos
PP5 = $Point05.pos
PP6 = $Point06.pos
)
(
joints=#()
-- stPos=#([PP1,PP1,PP1],[PP3,PP3,PP3],[PP5,PP5,PP5],[0,0,PP5+5])
stPos=#(PP1,PP3,PP5,PP5 +[10,0,0])
dir=[0,1,0]
)
(
jointsC=#()
--stPosC=#([PP2,PP2,PP2],[PP4,PP4,PP4],[PP6,PP6,PP6],[PP6,PP6,PP6+5])
stPosC=#(PP2,PP4,PP6,PP6+[0,0,-10])
dirC=[0,0,1]
)
for i = 1 to 3 do
(
b=boneSys.createBone stPos[i] stPos[i+1] dir
if i>1 then b.parent=joints[i-1]
append joints b
)
for i = 1 to 3 do
(
c=boneSys.createBone stPosC[i] stPosC[i+1] dirC
if i>1 then c.parent=jointsC[i-1]
append jointsC c
)
)
-------------------------------------------------------------------------------
on controlsButton pressed do
(
for i = 1 to 2 do
(
for i = 1 to 2 do
(
circle radius:10
)
$Circle01.pos=$Point05.pos
$Circle02.pos=$Point06.pos
-- select IK Chain01'
$.parent = $Circle01
-- select IK Chain02'
$.parent = $Circle02
)
)
)
createDialog test_buttons 150 100
Thanks Dan, that is great.
And thank you PEN…you have my vote:)
Cheers,
Asa