0

I have a script that parses a text file and creates the objects specified. The object creation should theoretically be O(1).

This method is the only thing other than an if quick unrelated if statement to set a Boolean and there's an increment of an int after that I included in my timing bounds.

def createAtom(aType,location):
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=4,size=atomProps[aType]['size']/100.0,location=location)
    ob = bpy.context.object
    for polygon in ob.data.polygons:
        polygon.use_smooth = True
    if len(aType): ob.active_material = atomProps[aType]['material']
    ob.parent = empty
    ob.name = str(currAtom)

as you can see, it doesn't iterate over anything except for setting smooth shading, and with that loop commented out it still increases pretty drastically over time.graph of increasing times The anomaly with the bond times is that sometimes there are double bonds, so it takes twice as long.

Neywiny
  • 11
  • 2

1 Answers1

1

This is a common issue related to unique name lookup.

When an object is added to scene, blender ensure the name is unique. So the more objects you add, the more time each one require for the name lookup.

user34831
  • 427
  • 3
  • 7
  • That's what I was thinking it was. Do you have a solution around it to complement your very useful (not sarcastic) information. – Neywiny Nov 04 '17 at 02:47
  • Given you need separate objects, i'm not aware of any simple solution for this, the hard way require modify the current name lookup implementation -probably a scan through a list -. On the other hand, if you dont need the separate objects, grouping data on a single mesh could be a workaround. – user34831 Nov 04 '17 at 03:11
  • As a side note, C code for it is allready in blender, but not used by default. Seek for IDNameLib_Map in sources. – user34831 Nov 04 '17 at 03:47
  • Yeah, the basic concept of the program is that you give it an input file and output specs (resolution and whatnot) and it generates atoms and their bonds. That means creating each bond and atom separately, and it should be deployable since I'm trying to get my code out there for future employers and stuff. – Neywiny Nov 04 '17 at 04:04
  • It can run faster if you generate your own vertex and color data outside of Blender, using a documented filetype, such as wavefront .obj - I figured that filetype out easily by looking at a few exported LeoCAD files, but Wiki has decent info on it as well. – Doyousketch2 Dec 14 '17 at 05:43