Hi all!
I am new to Blender and after taking a look at modeling, physics, and particles, I experienced quickly with geometry nodes and quickly decided to go for python scripting.
My initial goal was to generate buildings to make a small city skyline.
I understand that there are probably a lot of existing plugins for that, but thought that it was one simple way to learn.
I built such a script and this kind of work, however, I have a few (probably stupid) questions.
If this helps, my current script is available at https://gist.github.com/tiry/dc76dd16f2549d92ad20030e70df0ac0
Speed:
The execution of the script is painfully slow.
Basically, running my script to generate a few city blocks would take hours whereas the code is fairly simple.
My current guess is that my code is not optimized and especially, I am using operators that probably include a lot of overhead (like Undo, Refresh, Messaging …).
Is there something I can do to speed up the process?
Creating primitives:
I am currently using operators to create cubes and cylinders.
bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, align='WORLD', location=(x, y, h/2+dh), scale=(w, l, h))
My understanding is that I could use the “data” API and directly create mesh objects without using the operators.
However, from what I was able to see, this implies that I need to pre-initialize a data structure with the vertex, edges, and faces.
Am I missing something?
If my python script must generate all the low-level vertex/edge/faces: should I just work on having an external python script generate the mesh in Collada format?
Operators:
My current understanding is that I should avoid using operators for generating mesh because it introduces some overhead and a dependency on the UI (like what collection is selected when running the script).
Is this correct? Should I avoid using operators?
I will appreciate any advice pointing me in the right direction.
Thanks in advance.
Tiry