UuuNyaa / blender_mmd_tools

MMD Tools is a blender addon for importing/exporting Models and Motions of MikuMikuDance.
GNU General Public License v3.0
2.27k stars 109 forks source link

Add patching to all mmd_tools propeties #65

Closed UuuNyaa closed 2 years ago

UuuNyaa commented 2 years ago
One-sixth commented 2 years ago

I reviewed it and it looks no problem.

Then I found a new bug in the ensure_material_id_not_conflict function and that can be fixed by the way, it's a bug from the library override. The properties of the referenced library are not modifiable, but modifying it will not throw an error. Then it rolls back randomly, causing duplicate material IDs, breaking the imported material order.

This is the fixed ensure_material_id_not_conflict function.

    @staticmethod
    def ensure_material_id_not_conflict():
        mat_ids_set = set()

        # The reference library properties cannot be modified and bypassed in advance.
        need_update_mat = []
        for mat in bpy.data.materials:
            if mat.library is not None:
                if mat.mmd_material.material_id < 0:
                    continue
                mat_ids_set.add(mat.mmd_material.material_id)
            else:
                need_update_mat.append(mat)

        for mat in need_update_mat:
            if mat.mmd_material.material_id < 0:
                continue
            if mat.mmd_material.material_id in mat_ids_set:
                mat.mmd_material.material_id = max(mat_ids_set) + 1
            mat_ids_set.add(mat.mmd_material.material_id)
UuuNyaa commented 2 years ago

Thank you for your review! I adopted your code snippet.

One-sixth commented 2 years ago

I think it's fine. Maybe it can be merged.