0
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Related Only need to create icosphere once (or never) with an operator. $\endgroup$
    – batFINGER
    Commented Nov 3, 2017 at 23:45
  • $\begingroup$ Interesting. So you're suggesting I create one icosphere of each type I need and just copy it? I'll look into it, thanks. $\endgroup$
    – Neywiny
    Commented Nov 4, 2017 at 0:20

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ That's what I was thinking it was. Do you have a solution around it to complement your very useful (not sarcastic) information. $\endgroup$
    – Neywiny
    Commented Nov 4, 2017 at 2:47
  • $\begingroup$ 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. $\endgroup$
    – user34831
    Commented Nov 4, 2017 at 3:11
  • $\begingroup$ As a side note, C code for it is allready in blender, but not used by default. Seek for IDNameLib_Map in sources. $\endgroup$
    – user34831
    Commented Nov 4, 2017 at 3:47
  • $\begingroup$ 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. $\endgroup$
    – Neywiny
    Commented Nov 4, 2017 at 4:04
  • $\begingroup$ 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. $\endgroup$ Commented Dec 14, 2017 at 5:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .