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

fix: performance issue when dealing with models with a lot of objects rendering over and over again #40

Closed lucasew closed 2 years ago

lucasew commented 2 years ago

In our project, we have models with about 500 objects but much fewer segmentation instances, and when calculating segmentations repeatedly, we had a very annoying performance problem. Each render iteration gets a bit slower kinda linearly.

After some investigation, we discovered that when this library kicks in it creates one material for each object but every time a render is requested it creates another material instead of reusing the one already there.

This pull request changes this behavior by creating one material per _instid instead of per object and check if the material is already created so it will not be created again reusing that material and avoiding the slowdown.

DIYer22 commented 2 years ago

Thank you for the contribution!