09th / YABEE

Export models from the Blender to Panda3D game engine
MIT License
107 stars 39 forks source link

Address texture analysis performance issue #12

Closed eswartz closed 9 years ago

eswartz commented 9 years ago

Thanks for taking the earlier fix.

I was exporting this houseplant model that I found on the 'net and it took more than five minutes to export. After debugging, it seems the hotspot was in checking UV coords for the same material over and over on ~4000 polys. This simple fix speeds things up a lot. I tested with various textured models and it doesn't seem to break anything.

Again, this includes the model files for testing, but you may choose to leave them out, especially since they're kind of big.

09th commented 9 years ago

Thanks! I see you also use game settings for material.

eswartz commented 9 years ago

Hi, well, I don't always use the Blender Game mode or materials. I just changed that bit of the code to make sure the face (f) wasn't actually used anywhere else.

In that regard, I wonder, why doesn't this code just iterate all the materials on the object directly? To gather the materials, it doesn't need to iterate every poly, since the same ones are probably used on most faces. For example:

                handled = set()
                for f in obj.data.polygons:
                    if f.material_index < len(obj.data.materials):
                        mat = obj.data.materials[f.material_index]
                        if not mat or mat in handled:
                            continue
                        handled.add(mat)

changes to:

                for mat in obj.data.materials:
                        if not mat:
                            continue

Or is the goal to cull out texture materials that really aren't used (as "used_textures" implies), like if someone puts 10 "temporary" materials on an object but never assigns them to any faces?

09th commented 9 years ago

Yes, I did it to exclude materials that are not actually assigned to any face. However, if it's so affects performance, then I think that there is nothing wrong if that unused materials will be written to the resulting file.

eswartz commented 9 years ago

I agree. rdb mentioned on #panda3d that the egg loader will cull out unused materials.

On the other hand, in texture bake mode, if you can avoid baking unused materials, that may be good. shrug

I don't think the performance now will be so bad unless there are really millions of polys in an object.

09th commented 9 years ago

Ok. Anyway bake mode is still experimental, and I suspect that it almost never used.