I have topographical data which is height on a square lat/lon grid and I've generated a mesh with the script shown below. My polygons are all quadrangles (close to, but not quite squares in this case) and some are potato-chip bent pretty badly. I think this causes problems with vertex or face normals during rendering.
Is dividing each rectangle to two triangles likely to address this problem? Is there a magic way to convert to triangles with a simple python method?
I could probably modify the script loop to generate pairs of triangles as well if necessary, just need to make sure to go around each triangle in the same direction.
But a quad can be cut into triangles two different ways, and there is probably a good way and a bad way, depending on the particular shape of the potato-chipped quad. So if I did it manually in my loop, I'd have to test each one first...
verts = list(zip(scale_x*X.flatten(), scale_y*Y.flatten(), scale_z*Z.flatten()))
faces = []
for i in range(ny-1):
for j in range(nx-1):
v1 = i*(nx) + j
v2 = v1 + 1
v3 = v2 + nx
v4 = v3 - 1
faces.append((v1, v2, v3, v4))
name = 'topo'
me = bpy.data.meshes.new(name)
ob = bpy.data.objects.new(name, me)
bpy.context.scene.objects.link(ob)
me.from_pydata(verts, [], faces)
bpy.data.objects[name].select = False
bpy.data.objects[name].select = True
bpy.ops.object.shade_smooth()
Wireframe, Rendered, Texture