예제 #1
0
    def execute(self, context):
        import imp
        imp.reload(generate)

        try:
            generate.generate_rig(context, context.object)
        except rigify.utils.MetarigError as rig_exception:
            rigify_report_exception(self, rig_exception)

        return {'FINISHED'}
예제 #2
0
    def execute(self, context):
        import imp
        imp.reload(generate)

        try:
            generate.generate_rig(context, context.object)
        except rigify.utils.MetarigError as rig_exception:
            rigify_report_exception(self, rig_exception)

        return {'FINISHED'}
예제 #3
0
파일: ui.py 프로젝트: Badcreature/sagcg
    def execute(self, context):
        import imp
        imp.reload(generate)

        use_global_undo = context.user_preferences.edit.use_global_undo
        context.user_preferences.edit.use_global_undo = False
        try:
            generate.generate_rig(context, context.object)
        except rigify.utils.MetarigError as rig_exception:
            rigify_report_exception(self, rig_exception)
        finally:
            context.user_preferences.edit.use_global_undo = use_global_undo

        return {'FINISHED'}
예제 #4
0
    def execute(self, context):
        import imp
        imp.reload(generate)

        use_global_undo = context.user_preferences.edit.use_global_undo
        context.user_preferences.edit.use_global_undo = False
        try:
            generate.generate_rig(context, context.object)
        except rigify.utils.MetarigError as rig_exception:
            rigify_report_exception(self, rig_exception)
        finally:
            context.user_preferences.edit.use_global_undo = use_global_undo

        return {'FINISHED'}
    def execute(self, context):
        scn = context.scene

        rig = scn.objects['rig']
        metarig = scn.objects['metarig']

        if not metarig.is_visible(scn):
            self.report({'WARNING', 'INFO'}, "Metarig is not visible!")
            return {'FINISHED'}

        # Save rig_ui Text
        try:
            rig_ui_name = rig.users_group[0].name.rstrip('_GRP') + '_rig_ui.py'
        except:
            rig_ui_name = 'rig_ui.py'
        old_rig_id = bpy.data.armatures['rig']['rig_id']
        scn.NewRigID = old_rig_id
        scn.NewName = rig.users_group[0].name.rstrip('_GRP')

        # Duplicate metarig and rig
        bpy.ops.object.select_all(action='DESELECT')
        rig.select = True
        bpy.ops.object.duplicate()
        body_rig = scn.objects['rig.001']
        bpy.ops.object.select_all(action='DESELECT')
        metarig.select = True
        bpy.ops.object.duplicate()
        head_metarig = scn.objects['metarig.001']
        bpy.ops.object.select_all(action='DESELECT')

        # Eliminate unwanted head_metarig bones
        head_metarig.select = True
        scn.objects.active = head_metarig
        bpy.ops.object.mode_set(mode='EDIT')
        face_bones = find_face_bones(head_metarig)

        bpy.ops.armature.select_all(action='DESELECT')

        for bone in head_metarig.data.edit_bones:
            if bone.name not in face_bones:
                bone.select = True
        bpy.ops.armature.delete()

        # Generate head_metarig: the rig will be updated and contain only the head bones
        bpy.ops.object.mode_set(mode='OBJECT')
        generate_rig(context, head_metarig)
        bpy.ops.object.select_all(action='DESELECT')

        # Get head bone names from rig generated by head_metarig
        rig.select = True
        scn.objects.active = rig
        bpy.ops.object.mode_set(mode='EDIT')
        rig_face_bones = rig.data.edit_bones.keys()
        rig_face_bones.remove('root')
        rig.data.edit_bones.remove(rig.data.edit_bones['root'])
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.ops.object.select_all(action='DESELECT')

        # Eliminate head bones from body rig (rig.001) saving parents info first
        body_rig.select = True
        scn.objects.active = body_rig
        bpy.ops.object.mode_set(mode='EDIT')
        layers = []
        for i, lyr in enumerate(body_rig.data.layers):
            layers.append(body_rig.data.layers[i])
            body_rig.data.layers[i] = True
        bone_parents = get_bone_parents(body_rig, rig_face_bones)

        bpy.ops.armature.select_all(action='DESELECT')
        for bone in body_rig.data.edit_bones:
            if bone.name in rig_face_bones:
                bone.select = True

        bpy.ops.armature.delete()
        for i in range(0, 32):
            body_rig.data.layers[i] = layers[i]
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.ops.object.select_all(action='DESELECT')

        # Merge the head and body rigs
        rig.select = True
        body_rig.select = True
        scn.objects.active = rig
        bpy.ops.object.join()
        #body_rig.name = 'rig'
        #body_rig.data.name = 'rig'
        #rig = body_rig

        # Restore rig_ui
        duplicate_rig_ui(rig.users_group[0].name.rstrip('_GRP'), scn.NewName,
                         bpy.data.armatures[rig.name]['rig_id'], scn.NewRigID)
        bpy.data.armatures[rig.name]['rig_id'] = scn.NewRigID
        rig.users_group[0].name = scn.NewName + '_GRP'

        # Restore parenting and layers
        bpy.ops.object.select_all(action='DESELECT')
        rig.select = True
        scn.objects.active = rig
        bpy.ops.object.mode_set(mode='EDIT')

        for i in range(0, 32):
            rig.data.layers[i] = layers[i]

        for bone in rig.data.edit_bones:
            if bone.name in bone_parents.keys():
                bone.parent = rig.data.edit_bones[bone_parents[bone.name]]

        # Delete head_metarig
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.ops.object.select_all(action='DESELECT')
        head_metarig.select = True
        bpy.ops.object.delete()

        return {'FINISHED'}
    def execute(self, context):
        scn = context.scene

        rig = scn.objects['rig']
        metarig = scn.objects['metarig']

        if not metarig.is_visible(scn):
            self.report({'WARNING','INFO'}, "Metarig is not visible!")
            return {'FINISHED'}


        # Save rig_ui Text
        try:
            rig_ui_name = rig.users_group[0].name.rstrip('_GRP') + '_rig_ui.py'
        except:
            rig_ui_name = 'rig_ui.py'
        old_rig_id = bpy.data.armatures['rig']['rig_id']
        scn.NewRigID = old_rig_id
        scn.NewName = rig.users_group[0].name.rstrip('_GRP')

        # Duplicate metarig and rig
        bpy.ops.object.select_all(action='DESELECT')
        rig.select = True
        bpy.ops.object.duplicate()
        body_rig = scn.objects['rig.001']
        bpy.ops.object.select_all(action='DESELECT')
        metarig.select = True
        bpy.ops.object.duplicate()
        head_metarig = scn.objects['metarig.001']
        bpy.ops.object.select_all(action='DESELECT')

        # Eliminate unwanted head_metarig bones
        head_metarig.select = True
        scn.objects.active = head_metarig
        bpy.ops.object.mode_set(mode='EDIT')
        face_bones = find_face_bones(head_metarig)

        bpy.ops.armature.select_all(action='DESELECT')

        for bone in head_metarig.data.edit_bones:
            if bone.name not in face_bones:
                bone.select = True
        bpy.ops.armature.delete()

        # Generate head_metarig: the rig will be updated and contain only the head bones
        bpy.ops.object.mode_set(mode='OBJECT')
        generate_rig(context, head_metarig)
        bpy.ops.object.select_all(action='DESELECT')

        # Get head bone names from rig generated by head_metarig
        rig.select = True
        scn.objects.active = rig
        bpy.ops.object.mode_set(mode='EDIT')
        rig_face_bones = rig.data.edit_bones.keys()
        rig_face_bones.remove('root')
        rig.data.edit_bones.remove(rig.data.edit_bones['root'])
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.ops.object.select_all(action='DESELECT')

        # Eliminate head bones from body rig (rig.001) saving parents info first
        body_rig.select = True
        scn.objects.active = body_rig
        bpy.ops.object.mode_set(mode='EDIT')
        layers = []
        for i, lyr in enumerate(body_rig.data.layers):
            layers.append(body_rig.data.layers[i])
            body_rig.data.layers[i]=True
        bone_parents = get_bone_parents(body_rig, rig_face_bones)

        bpy.ops.armature.select_all(action='DESELECT')
        for bone in body_rig.data.edit_bones:
            if bone.name in rig_face_bones:
                bone.select = True

        bpy.ops.armature.delete()
        for i in range(0, 32):
            body_rig.data.layers[i] = layers[i]
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.ops.object.select_all(action='DESELECT')

        # Merge the head and body rigs
        rig.select = True
        body_rig.select = True
        scn.objects.active = rig
        bpy.ops.object.join()
        #body_rig.name = 'rig'
        #body_rig.data.name = 'rig'
        #rig = body_rig

        # Restore rig_ui
        duplicate_rig_ui(rig.users_group[0].name.rstrip('_GRP'), scn.NewName, bpy.data.armatures[rig.name]['rig_id'], scn.NewRigID)
        bpy.data.armatures[rig.name]['rig_id'] = scn.NewRigID
        rig.users_group[0].name = scn.NewName + '_GRP'

        # Restore parenting and layers
        bpy.ops.object.select_all(action='DESELECT')
        rig.select = True
        scn.objects.active = rig
        bpy.ops.object.mode_set(mode='EDIT')

        for i in range(0, 32):
            rig.data.layers[i] = layers[i]

        for bone in rig.data.edit_bones:
            if bone.name in bone_parents.keys():
                bone.parent = rig.data.edit_bones[bone_parents[bone.name]]

        # Delete head_metarig
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.ops.object.select_all(action='DESELECT')
        head_metarig.select = True
        bpy.ops.object.delete()


        return {'FINISHED'}