import numpy as np from mayavi.scripts import mayavi2 from scipy.spatial import Delaunay from tvtk.api import tvtk class mayavidelaunay(object): def __init__(self, heightmap, length): self.points = [] self.polygons = [] self.length = length self.heightmap = heightmap self.mesh = None def createmesh(self): for n, i in enumerate(self.heightmap): for k, j in enumerate(i): self.points.append([(n*self.length), j, (k*self.length)]) points = np.asarray(self.points) polygons = [] for x in range(len(heightmap)): for y in range(len(heightmap)): polygons.append([x*self.length,y*self.length]) polygons = Delaunay(np.asarray(polygons)).simplices self.mesh = tvtk.PolyData(points=points, polys=polygons) @mayavi2.standalone def view(mesh): '''Stellt ein tvtk.Polydata mesh im mayavi2 Standalone dar.''' from mayavi.sources.vtk_data_source import VTKDataSource from mayavi.modules.surface import Surface mayavi.new_scene() src = VTKDataSource(data=mesh) mayavi.add_source(src) s = Surface() mayavi.add_module(s) import perlin2D if __name__ == '__main__': heightmap = [] for i in range(500): inmap = [] for j in range(500): inmap.append(perlin2D.Noise(i, j,0.03125, 0.5, 0.25)) heightmap.append(inmap) a = mayavidelaunay(heightmap, 0.05) a.createmesh() view(a.mesh)