I’ve run into a serious performance issue when using Python that I wasn’t able to find an answer to using a search.
I’m trying to render a series of frames, where for each frame different stl files are read. After loading the stl files I would like to assign the resulting mesh objects a predefined material. Here’s the code segment that loops through all scene objects and assigns to those that start with Mesh the material water.
sce = Blender.Scene.GetCurrent() # assign water material to loaded stl meshes for obj in sce.objects: if obj.type == 'Mesh': objname = obj.getName() iid = objname.find("Mesh") if iid == 0: print objname print 'GetData' n = obj.getData() print 'Assign material' n.materials = [water] print 'update' n.update() print 'Done updating materials'
Here’s the problem:
The last command n.update that updates the materials object takes extremely long (as timed by the print commands). It takes at times several hours per object (granted, the binary stl files are about 25MB (2 total)). If I do the same action through the GUI (select the mesh, assign the material), this takes only a second.
Is there a other/faster way of assigning a material to a mesh object in Python than the one I used above?
Thanks in advance!