I have problems getting my head around it:
I have two arrays:
verts = np.array([1, 1, 0,
2, 1, 0,
3, 1, 0,
1, 2, 0,
2, 2, 0,
3, 2, 0,
1, 3, 0,
2, 3, 0,
3, 3, 0])
faces = np.array([0, 1, 4, 3,
1, 2, 5, 4,
3, 4, 7, 6,
4, 5, 8, 7])
The mesh (me) is prepared with the 9 verts from array "verts" in it already. Now i want to add the faces but the explanations i found were scarce at best.
So, how do i add faces using (an explanation would be great):
me.loops.add() #should be 4 loops per (4-sided) face, right?
me.loops.foreach_set("vertex_index",) #no idea...
me.polygons.add(faces.size / 4) #4 Faces in this case
me.polygons.foreach_set("loop_start",) #no idea...
me.polygons.foreach_set("loop_total",) #not sure... number of loops per face in a list: [4, 4, 4, 4] in this case?
#me.polygons.foreach_set("vertices", ) #needed at all? List of vert coordinates if they were no verts in mesh already?
I would be very happy if anybody could shed some light on it for me.
EDIT
After some investigation of "from_pydata" code in "bpy_types.py" as suggested by batFINGER i am a bit further but still not fully able to create the correct mesh.
I now have most of it right i think but because i have shared vertices for some of the loops and edges i am now pretty sure I need to use:
me.loops.foreach_set("vertex_index", vert_idx)
i thought i would need to add two verts per loop (start and end), so:
vert_idx = (0, 1,
1, 4,
4, 3,
3, 0,
1, 2,
2, 5,
5, 4,
4, 1,
3, 4,
4, 7,
7, 6,
6, 3,
4, 5,
5, 8,
8, 7,
7, 4)
or "faces" but both leads to a crash, like everything else i tried.
Mesh.from_pydata(...)
or a bmesh approach. Consider foreach get and set more a way to get or set property data to / from a flat list, rather than as a way to create meshes. $\endgroup$from_pydata
is inbpy_types.py
as mentioned here $\endgroup$