In my application I have to create up to some 1000 tetraders (objects with 4 vertices, 4 faces, 6 edges). As input I get only the absolute vertex coordinates for each tetraeder. From the mathematical background I know that all tetraeders are identical but have a different location and rotation which I do not know.
The following code works (Tetra is some class providing the vertex coordinates of an tetraeder and some other informations which is not relevant here):
# object creation
def draw_Tetra(Tetra, Faces):
bm = bmesh.new()
V1 = bm.verts.new(Tetra.Vertices[0])
V2 = bm.verts.new(Tetra.Vertices[1])
V3 = bm.verts.new(Tetra.Vertices[2])
V4 = bm.verts.new(Tetra.Vertices[3])
if Faces == True:
bm.faces.new((V1, V2, V3))
bm.faces.new((V1, V2, V4))
bm.faces.new((V1, V3, V4))
bm.faces.new((V2, V3, V4))
else:
bm.edges.new((V1, V2))
bm.edges.new((V1, V3))
bm.edges.new((V2, V3))
bm.edges.new((V1, V4))
bm.edges.new((V2, V4))
bm.edges.new((V3, V4))
name = "T_" + Tetra.Type + "_" + Tetra.pedigree
me = bpy.data.meshes.new(name)
bm.to_mesh(me)
bm.free
obj = bpy.data.objects.new(name,me)
scene = bpy.context.scene
scene.objects.link(obj)
However the script is extremely slow, e.g. to create 5000 tetraeders takes many hours. I think that I have the same problem as discussed here:
Python performance with Blender operators
The problem is that I do not know how to use "low level code" in this special situation. Can someone give me a tip?