Пример #1
0
    def execute(self, context):

        selected = bpyutil.selected_objects()
        materials = []
        for obj in selected:
            if obj.type == "MESH":
                materials.clean_materials(obj.material_slots)

        return {'FINISHED'}
Пример #2
0
def convert_makehuman_avatar_hifi():
    # Should Probably have a confirmation dialog when using this.
    original_type = bpy.context.area.type
    bpy.context.area.type = 'VIEW_3D'

    # Change mode to object mode

    marked_for_purge = []
    marked_for_deletion = []

    bpy.ops.object.mode_set(mode='OBJECT')
    for scene in bpy.data.scenes:
        for obj in scene.objects:
            bpy.ops.object.select_all(action='DESELECT')
            if obj is not None:
                obj.select = True
                bpy.context.scene.objects.active = obj

                # Delete joints and rigid bodies items. Perhaps later convert this to flow.
                print("Reading", obj.name)
                if obj.name == "joints" or obj.name == "rigidbodies":
                    marked_for_purge.append(obj)

                elif obj.type == "EMPTY" and obj.parent is None:
                    marked_for_deletion.append(obj)

                elif obj.type == 'ARMATURE':
                    convert_bones(obj)

                elif obj.type == 'MESH' and obj.parent is not None and obj.parent.type == 'ARMATURE':
                    bpy.ops.object.mode_set(mode='OBJECT')
                    print(" Cleaning up Materials now. May take a while ")
                    materials.clean_materials(obj.material_slots)
                    set_material_properties(obj)
                    remove_modifier_by_type(obj, "SUBSURF")

    create_blink_shapes("EyeBlink_L", "orbicularis03.L", "orbicularis04.L")
    create_blink_shapes("EyeBlink_R", "orbicularis03.R", "orbicularis04.R")

    for deletion in marked_for_deletion:
        deletion.select = True
        bpy.context.scene.objects.active = deletion
        bpy.ops.object.delete()

    bpy.context.area.type = original_type
Пример #3
0
def rename_bones_and_fix_most_things(self, context):
    print("Rename bones fix most things", self.armature)
    if len(self.armature) < 1:
        print("Armature Update cancelled")
        return {"CANCELLED"}

    bpy.ops.wm.console_toggle()
    mode = bpy.context.area.type

    # Naming Converted
    bpy.ops.object.mode_set(mode="EDIT")
    armature = bpy.data.armatures[self.armature]
    ebones = armature.edit_bones
    
    print("--------")
    print("Updating Bone Names")
    update_bone_name(ebones, self.hips, "Hips")
    update_bone_name(ebones, self.spine, "Spine")
    update_bone_name(ebones, self.spine2, "Spine2")

    spine_was_split = False
    if len(self.spine1) < 1:
        spine1 = ebones.get("Spine2") # Get what is supposed to be the last spine.
        spine1.select = True
        bpy.ops.armature.subdivide()

        # Spine2.001 = new spine 2
        # Spine2 = spine1
        spine2 = ebones.get("Spine2.001")
        spine1.name = "Spine1"
        spine2.name = "Spine2"
        spine_was_split = True

    else:
        update_bone_name(ebones, self.spine1, "Spine1")
    
    update_bone_name(ebones, self.neck, "Neck")
    update_bone_name(ebones, self.head, "Head")

    print("--------")
    print("Updating Bone Names Mirrored")
    update_bone_name_mirrored(ebones, self.eye, "Eye")
    update_bone_name_mirrored(ebones, self.shoulder, "Shoulder")
    update_bone_name_mirrored(ebones, self.arm, "Arm")
    update_bone_name_mirrored(ebones, self.fore_arm, "ForeArm")
    update_bone_name_mirrored(ebones, self.hand, "Hand")

    update_bone_name_mirrored(ebones, self.up_leg, "UpLeg")
    update_bone_name_mirrored(ebones, self.leg, "Leg")
    update_bone_name_mirrored(ebones, self.foot, "Foot")
    update_bone_name_mirrored(ebones, self.toe, "Toe")

    print("--------")
    print("Updating Bone Names Chained Mirrored")
    update_bone_name_chained_mirrored(ebones, self.hand_thumb, "HandThumb")
    update_bone_name_chained_mirrored(ebones, self.hand_index, "HandIndex")
    update_bone_name_chained_mirrored(ebones, self.hand_middle, "HandMiddle")
    update_bone_name_chained_mirrored(ebones, self.hand_ring, "HandRing")
    update_bone_name_chained_mirrored(ebones, self.hand_pinky, "HandPinky")
    
    bpy.ops.object.mode_set(mode="OBJECT")
    armature = bpy.data.armatures[self.armature]

    object_armature = None
    for obj in bpy.data.objects:
        if obj.type == "ARMATURE" and obj.data == armature:
            object_armature = obj
            break

    bones.reset_scale_rotation(object_armature)

    # Fixing Rotations and Scales
    # Now Refresh datablocks

    print("Reset Scale to unit scale")
    print("--------")
    print("Fix Rotations")


    bpy.ops.object.mode_set(mode="EDIT")
    
    ebones = armature.edit_bones

    for bone in ebones:
        bone.hide = False
        bone.name = bones.clean_up_bone_name(bone.name)
        bones.correct_bone_rotations(bone)
        bones.correct_bone(bone, ebones)
        

    bones.correct_bone_parents(armature.edit_bones)
    bpy.ops.object.mode_set(mode="OBJECT")
    bpy.ops.object.select_all(action="DESELECT")
    # TODO: This should be more selective and only affect the armature object's children.

    children = bpy.data.objects 
    for child in children:
        if child.type == "ARMATURE":
            child.select = True
            bones.correct_scale_rotation(child, True)
            bpy.ops.object.mode_set(mode="POSE")
            bpy.ops.pose.select_all(action="SELECT")
            bpy.ops.pose.transforms_clear()
            bpy.ops.pose.select_all(action="DESELECT")
            bpy.ops.object.mode_set(mode="OBJECT")
                
            if self.pin_problems:
                print("PIN PROBLEM")
                bpy.ops.object.mode_set(mode="EDIT")
                bones.pin_common_bones(child, self.fix_rolls)
            
        if child.type == "MESH":
            #        mesh.clean_unused_vertex_groups(child)
            bones.reset_scale_rotation(child)
            if spine_was_split:
                print("Dealing with the Spine split for" + child.name)
                spine1_weights = child.vertex_groups["Spine1"]
                if spine1_weights is not None:
                    spine1_weights.name = "Spine2"
                 
            if self.common_shapekey_correct:
                # common_cats_blend_mapping
                # Reset all shapekeys.
                ## TODO: Perhaps dettach this into a function.
                print("Going Through blendshapes and creating new ones")
                bpy.ops.object.mode_set(mode="OBJECT")
                bpy.ops.object.select_all(action="DESELECT")
                bpy.context.scene.objects.active = child
                child.select = True
                blocks = child.data.shape_keys.key_blocks

                for shape_key in blocks:
                    shape_key.value = 0

               
                for blend_map in common_cats_blend_mapping:
                    blocks.update()
                    block = blocks.get(blend_map.frm)
                    if block is not None:
                        target_block = blocks.get(blend_map.to)
                        if target_block is None:
                            block.value = blend_map.value
                            child.shape_key_add(name=blend_map.to, from_mix=True)
                            block.value = 0
            
            if self.compress_materials:
                materials.clean_materials(child.material_slots)
    
    if self.remove_ends:
        bpy.context.area.type = mode
        bpy.ops.object.mode_set(mode="OBJECT")
        bpy.ops.object.mode_set(mode="EDIT")
        bones.clean_ends(child)


    for material in bpy.data.materials:
        materials.flip_material_specular(material)

    if self.remove_metallic:
        materials.remove_materials_metallic(bpy.data.materials)
    
    if self.mask_textures:
        materials.convert_images_to_mask(bpy.data.images)

    bpy.ops.object.mode_set(mode="OBJECT")

    bpy.context.area.type = mode
    bpy.ops.object.mode_set(mode="OBJECT")

    bpy.ops.wm.console_toggle()
    return {"FINISHED"}
Пример #4
0
    def execute(self, context):
        for obj in bpy.data.object:
            if obj.type == "MESH":
                materials.clean_materials(obj.material_slots)

        return {'FINISHED'}
Пример #5
0
def convert_mmd_avatar_hifi():

    if not bpy.data.is_saved:
        print("Select a Directory")
        bpy.ops.hifi_error.save_file('INVOKE_DEFAULT')
        return

    bpy.ops.wm.console_toggle()

    print("Converting MMD Avatar to be Blender-High Fidelity compliant")
    # Should Probably have a confirmation dialog when using this.
    original_type = bpy.context.area.type
    bpy.context.area.type = 'VIEW_3D'

    Translator = MMDTranslator()
    # Change mode to object mode

    print("Translating Materials", len(bpy.data.materials))
    translate_list(Translator, list(bpy.data.materials))
    print("Translating Textures", len(bpy.data.textures))
    translate_list(Translator, list(bpy.data.textures))
    print("Translating Meshes", len(bpy.data.meshes))
    translate_list(Translator, list(bpy.data.meshes))
    print("Translating Meshes", len(bpy.data.meshes))
    translate_list(Translator, list(bpy.data.meshes))

    marked_for_purge = []
    marked_for_deletion = []

    bpy.ops.object.mode_set(mode='OBJECT')
    for scene in bpy.data.scenes:
        for obj in scene.objects:
            bpy.ops.object.select_all(action='DESELECT')
            if obj is not None:
                obj.select = True
                bpy.context.scene.objects.active = obj

                # Delete joints and rigid bodies items. Perhaps later convert this to flow.
                print("Reading", obj.name)
                if obj.name == "joints" or obj.name == "rigidbodies":
                    marked_for_purge.append(obj)

                elif obj.type == "EMPTY" and obj.parent is None:
                    marked_for_deletion.append(obj)

                elif obj.type == 'ARMATURE':
                    convert_bones(Translator, obj)
                    bones.scale_helper(obj)

                elif obj.type == 'MESH' and obj.parent is not None and obj.parent.type == 'ARMATURE':
                    clean_mesh(Translator, obj)
                    bpy.ops.object.mode_set(mode='OBJECT')
                    print(" Cleaning up Materials now. May take a while ")
                    materials.clean_materials(obj.material_slots)

            # translate armature names!

    bpy.ops.object.select_all(action='DESELECT')
    for deletion in marked_for_deletion:
        deletion.select = True
        bpy.context.scene.objects.active = deletion
        bpy.ops.object.delete()

    bpy.ops.object.select_all(action='DESELECT')
    for deletion in marked_for_purge:
        delete_self_and_children(deletion)

    materials.convert_to_png(bpy.data.images)
    materials.convert_images_to_mask(bpy.data.images)
    materials.cleanup_alpha(bpy.data.materials)

    bpy.context.area.type = original_type

    bpy.ops.file.make_paths_absolute()

    bpy.ops.wm.console_toggle()