blender-to-gmstudio / blender-to-smf

Import-Export of Blender model from/to SMF model format
MIT License
11 stars 2 forks source link

Speed up image loading and saving using NumPy and bpy_prop_collection's foreach_get/foreach_set #41

Closed bartteunis closed 2 years ago

bartteunis commented 2 years ago

Getting and setting the data of Image.pixels is unacceptably slow. As an example, loading a normally sized texture image of 512x512 using the current importer code in dev takes minutes.

Blender's bpy_prop_collection has foreach_get/foreach_set methods that allow fast get/set on the pixel data. That way, the slow loop is moved entirely to optimized Python code. One additional difficulty is the conversion from np.ubyte values in [0, 255] range to np.float values in [0, 1] range. NumPy can be used to perform that conversion very quickly.

Fixed in 19dfb6c in dev.

To be changed in the exporter as well.

bartteunis commented 2 years ago

Changed in export_smf.py in 4f6b056