0
$\begingroup$

I'm working on an import script and I am getting stuck on doing armatures properly.

So far I have been creating edit bones and I have it mostly looking correct, but while the directions that the bones are pointing in are correct, their roll rotations are wrong. And that is quite important.

Is there any examples of how to do this properly? Should I use pose mode instead? Would using pose mode screw up vertex weights when I get to that part?

Could someone show me a code snippet of how to properly set positions and rotations for bones for an import script?

$\endgroup$
1
$\begingroup$

So, in the end I ended up creating the bones using new() then I converted by absolute rotation to matrix and transformed the bone by that. Then after that I added the absolute position to both the head and the tail of each bone and that got me the correct result.

    for i, node in enumerate(jms.nodes):
        scene_node = edit_bones.new(name=NODE_NAME_PREFIX+node.name)

        # Assign parent if index is valid.
        scene_node.parent = scene_nodes.get(node.parent_index, None)

        # If a node has multiple children we cannot connect its tail end
        # to the children.

        pos = absolute_transforms[i]['translation']
        rot = absolute_transforms[i]['rotation']

        # Bones when created start at 0 0 0 for their tail and head.
        # We extend the tail so it sticks out a bit and signifies the direction.

        scene_node.tail = (scene_node.bbone_x, 0.0, 0.0)

        # We then rotate the bone by the absolute rotation that it should have.

        scene_node.transform(rot.to_matrix(), scale=False)

        # Then we add the absolute location to both the head and the tail.

        scene_node.head += Vector(
            (pos[0] * scale, pos[1] * scale, pos[2] * scale))
        scene_node.tail += Vector(
            (pos[0] * scale, pos[1] * scale, pos[2] * scale))
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.