Esempio n. 1
0
 def execute(self, context):
     materials.convert_to_png(bpy.data.images)
     return {'FINISHED'}
Esempio n. 2
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()