def _create_armature(name, connected=False, rigid=False):
    arm = bpy.data.armatures.new(name)
    obj = bpy.data.objects.new(name, arm)
    bpy.context.scene.objects.link(obj)
    bpy.context.scene.objects.active = obj

    children = []
    with using_mode(mode='EDIT'):
        root = arm.edit_bones.new('root')
        root.tail = (0, 0, 1)

        child1 = arm.edit_bones.new('child1')
        child1.parent = root
        child1.head = root.tail if connected else (1, 0, 0)
        child1.tail = (0, 1, 1)
        children.append(child1.name)

        child2 = arm.edit_bones.new('child2')
        child2.parent = root
        child2.head = root.tail if connected else (1, 0, 0)
        child2.tail = (1, 0, 1)
        children.append(child2.name)

    with using_mode(mode='OBJECT'):
        ikjoint_type = '0' if rigid else '1'
        for child_name in children:
            arm.bones[child_name].xray.ikjoint.type = ikjoint_type

    return obj.data
Exemplo n.º 2
0
    def execute(self, context):
        armature_object = context.object
        armature = armature_object.data
        fake_names = []
        with utils.using_mode('EDIT'):
            for bone in armature.edit_bones:
                parent = bone.parent
                if parent is None:
                    continue
                if bone.head == parent.tail:
                    continue
                if armature.bones[bone.name].xray.ikjoint.is_rigid:
                    continue

                fake_bone = armature.edit_bones.new(
                    name=utils.build_fake_bone_name(bone.name))
                fake_bone.use_deform = False
                fake_bone.hide_viewport = True
                fake_bone.parent = parent
                fake_bone.use_connect = True
                fake_bone.tail = bone.head
                bone.parent = fake_bone
                bone.use_connect = True
                fake_names.append(fake_bone.name)

        with utils.using_mode('OBJECT'):
            for name in fake_names:
                pbone = armature_object.pose.bones[name]
                pbone.lock_ik_x = pbone.lock_ik_y = pbone.lock_ik_z = True

                bone = armature.bones[name]
                bone.hide_viewport = True

        self.report({'INFO'}, 'Created %d fake bones' % len(fake_names))
        return {'FINISHED'}
    def test_show_hide(self):
        operator = bpy.ops.io_scene_xray.toggle_fake_bones_visibility
        self.assertFalse(operator.poll(), msg='no armature')

        arm = _create_armature('test')
        self.assertFalse(operator.poll(), msg='not created yet')

        bpy.ops.io_scene_xray.create_fake_bones()
        self.assertTrue(operator.poll(), msg='created')

        self.assertEqual(_fake_hides(arm.bones), [True, True],
                         msg='hide by default')
        operator()
        self.assertEqual(_fake_hides(arm.bones), [False, False],
                         msg='shown now')
        with using_mode(mode='EDIT'):
            bones = arm.edit_bones
            self.assertEqual(_fake_hides(bones), [True, True],
                             msg='still hidden in edit-mode')
            operator()
            self.assertEqual(_fake_hides(bones), [False, False],
                             msg='shown in edit-mode')
            operator()
            self.assertEqual(_fake_hides(bones), [True, True],
                             msg='hidden in edit-mode')
        self.assertEqual(_fake_hides(arm.bones), [False, False],
                         msg='still shown in object-mode')
        operator()
        self.assertEqual(_fake_hides(arm.bones), [True, True],
                         msg='hide in object-mode')
Exemplo n.º 4
0
    def execute(self, context):
        armature = context.object.data
        original_count = len(armature.bones)
        with utils.using_mode('EDIT'):
            bones = armature.edit_bones
            for bone in tuple(bones):
                if not utils.is_fake_bone_name(bone.name):
                    continue
                bones.remove(bone)

        self.report(
            {'INFO'},
            'Removed %d fake bones' % (original_count - len(armature.bones)),
        )
        return {'FINISHED'}