I am using PIL and trying to create heightfield mesh from a greyscale image. I have been able to read the image and its size to create the mesh points, but I am having difficulty in indexing the faces to create them. Here’s the code so far:
import Blender from Blender import * from math import * import Pil from Pil import Image #CNC variables CD = .25 #cutting depth CS = 125 #cutting speed ipm PS = 12 #plunge speed ipm pic = Image.open("c:/piltest.jpg") me = NMesh.GetRaw() for j in range (0,pic.size): for in range (0,pic.size): v = NMesh.Vert(j,i,0.0) me.verts.append(v) NMesh.PutRaw(me, "piltest", 1) Blender.Redraw()
My test image, piltest.jpg is simply a 10 x 12 greyscale image. The above code creates the points, but now I need to know forumulaically how to create or define the faces, since the greyscale images will vary in x and y. My z will be created later by get.pixel(x,y) which will return the value 0-255 for the pixels greyscale value. I will normalize it to the cutting depth variable above: get.pixel(x,y) * (CD/255) = Z
I guess I’m looking for a way to algorithmically roll through the matrix to create the faces without errors.