Hello, I previously asked about how to draw tens of thousands of cylinders in my scene. I now have found a way to draw lots of objects, using the following code.
circleobj = bpy.data.objects["BezierCircle"] # done only once
circleobj.name = "Segment base circle"
for armname in data['Arms']:
burgers = int(arm['burgers']) if burgers not in materials:
materials[burgers] = CreateBurgersMaterial(burgers)
# note: only a total of maybe 5 materials are created here for this scene
material = materials[burgers]
objects.append(ExtrudePolyLine("%s curve %d"%(armname, curvenum), locations, circleobj, material))
for obj in objects:
bpy.context.scene.objects.link(obj)
def ExtrudePolyLine(name, locations, bevelobj, material):
curvedata = bpy.data.curves.new(name="%s line curve"%name, type='CURVE')
curvedata.dimensions = '3D'
#
obj = bpy.data.objects.new("%s line obj"%name, curvedata)
obj.location = (0,0,0) #object origin
#
polyline = curvedata.splines.new('NURBS')
polyline.points.add(len(locations)-1)
for num in range(len(locations)):
toadd = (locations[num])
print ("Adding point %s"%toadd)
polyline.points[num].co = toadd
#
polyline.order_u = len(polyline.points)-1
polyline.use_endpoint_u = True
obj.data.bevel_object = bevelobj
return obj
Now I want to optimize performance. However, some piece is eluding my timings. For a data set with n elements, here is my performance measurements:
numarms: 16161 in 60.003793 seconds, numarms/sec = 269.332974
numcurves: 17139 in 60.003793 seconds, numcurves/sec = 285.631943
numnodes: 108154 in 60.003793 seconds, numnodes/sec = 1802.452722
numsegs: 91015 in 60.003793 seconds, numsegs/sec = 1516.820778
Performance data every 5 seconds:
n elapsed curves curves/sec
0.000000 0.00 0.00 0.00
1.000000 1.00 2345.00 2341.92
2.000000 6.00 6028.00 1004.17
3.000000 11.00 8273.00 751.79
4.000000 16.00 9869.00 616.63
5.000000 21.01 11085.00 527.67
6.000000 26.01 12220.00 469.78
7.000000 31.01 13214.00 426.08
8.000000 36.02 14096.00 391.38
9.000000 41.02 14824.00 361.39
10.000000 46.03 15464.00 335.98
11.000000 51.03 16074.00 315.01
12.000000 56.03 16641.00 297.01
13.000000 60.00 17139.00 285.63
You can see that performance declines over time, which I think tells me that my code is somehow updating the scene per object. But in addition to the 60 seconds captured above, there is an extra lag of 32 seconds after the python code’s execution that I cannot account for. What I mean is that after I hit the enter key, it takes 92 seconds for the scene to appear by my stopwatch (note that no objects are linked yet, so this is not a matter of rendering). Thus python is missing a large piece of the timing.
So my question is two fold:
A) how can I avoid the performance decrease I’m seeing in my timings as the number of objects builds up? Is there a trick to creating curves or objects that avoids this?
B) what is the GUI doing for the extra 32 seconds after the python code thinks it’s complete?
Thanks!