Closed UuuNyaa closed 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)
Thank you for your review! I adopted your code snippet.
I think it's fine. Maybe it can be merged.
64