I need to create an object (width = w, length = l, height = h) using python and have created the following vertices with bmesh.
#bottom vertices
v0 = bm.verts.new((x-w/2, y-l, z)) #left, front, bottom
v1 = bm.verts.new((x+w/2, y-l, z)) #right, front, bottom
v2 = bm.verts.new((x-w/2, y, z)) #left, rear, bottom
v3 = bm.verts.new((x+w/2, y, z)) #right, rear, bottom
#top vertices
v4 = bm.verts.new((x-w/2, y, z+h)) #left, rear, top
v5 = bm.verts.new((x-w/2, y-l, z+h)) #left, front, top
v6 = bm.verts.new((x+w/2, y-l, z+h)) #right, front, top
v7 = bm.verts.new((x+w/2, y, z+h)) #right, rear, top
The corresponding faces are:
bm.faces.new((v0, v1, v3, v2)) #bottom plane
bm.faces.new((v5, v6, v7, v4)) #top plane
bm.faces.new((v0, v1, v6, v5)) #front plane
bm.faces.new((v2, v3, v7, v4)) #rear plane
bm.faces.new((v0, v2, v4, v5)) #left (lateral) plane
bm.faces.new((v1, v3, v7, v6)) #right (lateral) plane
But with these faces, even though the object appears to have been properly created, the normals are messed up. This is apparent when, for instance, a bevel modifier is applied to the object (the object gets completely distorted).
What is the right way (the right sequence of faces?) to construct an object with multiple polygons using bmesh (I have other objects with more than 6 faces, which are having a similar problem) ?