clr.AddReference('mscorlib') from System import Array clr.AddReference('System.Windows.Forms') from System.Windows.Forms import * clr.AddReference('System.Drawing') from System.Drawing import Bitmap empty = Color( 255, 255, 255, 0 ) ofd = OpenFileDialog() ofd.CheckFileExists = True ofd.Multiselect = False ofd.Filter = "Image files (*.*)|*.*" if ofd.ShowDialog() == DialogResult.OK: heightmap = Bitmap( ofd.FileName ) newvox = Array.CreateInstance( Color, heightmap.Width, heightmap.Height, height ) for x in range(heightmap.Width): for y in range(heightmap.Height): for z in range(height): newvox[x,y,z] = empty for x in range(heightmap.Width): for y in range(heightmap.Height): dh = ( heightmap.GetPixel( x, y ).R / 255.0 ) maxz = int( dh * (height-3) ) if maxz >= 0 and maxz < (height - 3): for z in range(maxz+4): newvox[x,y,z] = frontColor voxels = newvox width, depth = heightmap.Width, heightmap.Height heightmap.Dispose()