I do not want to use BMesh this time.
I want to create a mesh programmatically, for this purpose I created this short script to see what I do wrong in my importer script. In this script I try to create a tetraeder. First I create the mesh, then define the vertices. Then I go for the polygons, but here I do something bad, because at the end I got no polygons defined.
The code:
mesh = bpy.data.meshes.new("Teszt")
mesh.vertices.add(4)
mesh.vertices[0].co = (0,0,0)
mesh.vertices[1].co = (2,0,0)
mesh.vertices[2].co = (1,2,0)
mesh.vertices[3].co = (1,1,3)
mesh.polygons.add(4)
mesh.polygons[0].vertices = (0,1,2)
mesh.polygons[1].vertices = (0,1,3)
mesh.polygons[2].vertices = (1,2,3)
mesh.polygons[3].vertices = (0,2,3)
print(len(mesh.polygons[3].vertices))
mesh.polygons[3].vertices = [0,2,3]
print(len(mesh.polygons[3].vertices))
#mesh.update()
#from bpy_extras import object_utils
#object_utils.object_data_add(bpy.context, mesh)
I am pretty new to Python, so it may be totally my fault, but when I check the len of (0,2,3), that is 3, when I execute mesh.polygons[3].vertices = (0,2,3)
it says 0. No exception or error message, just shallows it.
When I try to update()
or ...data_add(
at the end, Blender simply exits.
So my question is: how to define the polygons properly (and without using bmesh)?