DIYer22 / bpycv

Computer vision utils for Blender (generate instance annoatation, depth and 6D pose by one line code)
MIT License
464 stars 58 forks source link

Objects that share the same mesh do not allow the emission material to be reversed #26

Closed jc211 closed 2 years ago

jc211 commented 2 years ago

If you have objects within your scene that share the same mesh, set_inst_material will not recover the original material after its done running. This causes the objects to permanently turn green. This is because of the replace_collection code. It doesn't recognize that its changed the same object twice so it ends up overwriting the original materials in the StatuRecover object with the emission material and therefore loses all reference to the original.

https://github.com/DIYer22/bpycv/blob/7a6c7a1b18e0e68505cb24339acbe0523fc9951d/bpycv/material_utils.py#L41 https://github.com/DIYer22/bpycv/blob/7a6c7a1b18e0e68505cb24339acbe0523fc9951d/bpycv/statu_recover.py#L56

jc211 commented 2 years ago

This can be fixed by changing the code found here to: https://github.com/DIYer22/bpycv/blob/7a6c7a1b18e0e68505cb24339acbe0523fc9951d/bpycv/material_utils.py#L26

to this

objs = {obj.data.id_data: obj for obj in bpy.data.objects if obj.type in ("MESH", "CURVE")}
for obj_idx, obj in enumerate(objs.values()):
    inst_id = obj.get("inst_id", 0)  # default inst_id is 0
DIYer22 commented 2 years ago

Thanks for Identify and fix the BUG. Could you please create a pull request?