[Closed] create bone
Hi, I am simply trying to create a bone @ 0,0,0 . I recorded the macro and am trying to run it in the editor but it isnt working. Is this pretty simple to do?
to create a bone you have use BoneSys inteface:
<node>BoneSys.createBone <point3>startPos <point3>endPos <point3>zAxis
It returns the new bone node that was created.
<point3>startPos : The location of the new bone as point3
<point3>endPos : The direction (X axis) of the bone and the bone length as point3
<point3>zAxis: The direction of the Z axis for the new bone node as point3
see MAX Script Help BoneSys Interface for more info
When i create bones via maxscript, some of the bones has a different axis orientation, how can i control this?, the only axis that remains the same is the one i define along the bone.
i´m taking the information of a bone chain that already exist and recreate it via maxscript in order to solve fliped axis caused by the mirror tool. So my script goes like this. I need to orient the new bones, all the same way.
function reconstructBones =
(
n = selection.count
originalBones = for o in selection where (classof o == BoneGeometry) collect o
skinBones = #()
for i=1 to n-1 do (skinBones [i] = boneSys.createBone originalBones [i].pos originalBones [i+1].pos [1,0,0])
skinbones.wirecolor = yellow
)
reconstructBones()
fn reconstructBones root parent =
(
if (classof root) == BoneGeometry then
(
b = BoneSys.createBone root.transform.row4 (root.pos+root.transform.row1*root.length) [0,0,1]
b.parent = parent
)
else
(
b = point()
b.transform = root.transform
b.parent = parent
)
b.wirecolor = yellow
for c in root.children do (reconstructBones c b)
)
reconstructBones $ undefined
This takes the object at the top of the hierarchy, not the entire selection, and rebuilds that hierarchy so you only want to have the root bone selected. Here are a couple things to note:
[ul]
[li]the 3rd argument to bone creation is the z-axis so it should be [0,0,1]
[/li][li]you have to specify the parent when creating bone systems if you want to rebuild a hierarchy
[/li][li]this function creates a point helper in the hierarchy for all objects not of class boneGeometry
[/li][li]using the bones child as the 2nd point 3 parameter is not wise because the bone could have multiple children or may not be aligned to its child at all. A better approach is to use the bone’s position and add it to the bone’s x-axis* it’s length. This will give you the original bones correct alignment and length.
[/li][/ul]
Also, you should not use max’s regular mirror tool to mirror bones because it creates negative scale, as you have mentioned. You can avoid this by using the mirror tool in the Animation–>Bone Tools dialog. it lets you mirror bones without negative scale.
Hope this helps.
–Jon
Thank you very much Jon for you reply. It works great!. Well, i have a question about the ecuation for the second point 3 in the creation bone (root.pos+root.transform.row1*root.length) . You use root.pos as a starting point for the end position of the bone. Then you add to it, the result of the multiplication between root.transform.row1 (wich i think that contains the direction of the x axis of the bone, doesn´t it), and *root.length to get the value to sum to the first vector, that is the same of the starting point for the next bone.
I used zAxis alignment [1,0,0] because when i have to rig a character, i use to draw bones in Right view, so when i go the front view, all bones are straight aligned and then i reposition the bones, and when i do this, Max put the x axis along the bone and the z axis across the world x axis pointing right (x positive quadrant) so to copy this, y align my z axis this way [1,0,0] on boneSys.createBone parameters.
And i´m scripting some tools for automatize rigging procces, and i need to prevent if someone uses the regular mirror tool instead of Mirror from BoneTools by reconstructing the bone chain in order to get the correct axis alignment. Perhaps it´s a better solution than mirroring the matrix of the bones, because rebuilding it prevent also scale or stretch on bones.
Thank you again Jon!.
BoneSys.createBone
[0,0,0]
[0,1,0]
[0,0,1]
is this code accurate for creating a single bone @ 0,0,0? It doesn’t error, but it doesn’t work either. :banghead:
bah, a little searching and I got this frankensteined together
startPos=[0,0,0]
endPos=[0,1,0]
b = boneSys.createBone startPos endPos [0,0,1]
b.width = 5
b.height = 5
b.taper = 30
b.sideFins = off
b.frontFin = off
b.backFin = off