Heute beendeten wir die Arbeit an dem stl-Format-Projekt; der Code funktioniert nun. Der aktuelle Code lautet so:
# -*- coding: utf-8 -*- from __future__ import division from __future__ import print_function #from visual import * import numpy as np import stl from stl import mesh from matplotlib import pyplot # def erstelle_vertices(x): # for n in x: # while l < 8: # vertices[n] = np.array([x[n][l]]) # l += 1 # return vertices[2] # Listen von je drei Punkten, aus denen ein Dreieck gemacht werden soll faces = np.array([[4,6,7], [5,4,6], [5,6,2], [5,2,6], [3,0,7], [0,7,4], [0,1,2], [0,2,3], [2,3,6], [3,6,7], [0,1,4], [1,4,5]]) def eckpunkte_to_cube(liste, faces): for n, vertices in enumerate(liste): cube = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype)) for i, f in enumerate(faces): for j in range(3): print (i,j,f[j], type(f[j]), cube.vectors) cube.vectors[i][j] = vertices[int(f[j])] cube.save('cube'+str(n)+'.stl') raum = [ [(5.0, -1.5, -2.35), (5.0, -1.5, -2.65), (-5.0, -1.5, -2.65), (-5.0, -1.5, -2.35), (5.0, 1.5, -2.35), (5.0, 1.5, -2.65), (-5.0, 1.5, -2.65),(-5.0, 1.5, -2.35)], [(5.0, -1.5, 2.65), (5.0, -1.5, 2.35), (-5.0, -1.5, 2.35), (-5.0, -1.5, 2.65), (5.0, 1.5, 2.65), (5.0, 1.5, 2.35), (-5.0, 1.5, 2.35), (-5.0, 1.5, 2.65)], [(-4.561538461538461, -1.5, -1.9115384615384619), (-4.561538461538461, -1.5, -2.2115384615384617), (-5.438461538461539, -1.5, -2.2115384615384617), (-5.438461538461539, -1.5, -1.9115384615384619), (-4.561538461538461, 1.5, -1.9115384615384619),(-4.561538461538461, 1.5, -2.2115384615384617), (-5.438461538461539, 1.5, -2.2115384615384617), (-5.438461538461539, 1.5, -1.9115384615384619)], [(-4.4, -0.5, -0.8730769230769234), (-4.4, -0.5, -1.1730769230769234), (-5.6, -0.5, -1.1730769230769234), (-5.6, -0.5, -0.8730769230769234), (-4.4, 2.5, -0.8730769230769234), (-4.4, 2.5, -1.1730769230769234), (-5.6, 2.5, -1.1730769230769234), (-5.6, 2.5, -0.8730769230769234)], [(-3.5384615384615383, -1.5, 1.1884615384615378), (-3.5384615384615383, -1.5, 0.8884615384615379), (-6.461538461538462, -1.5, 0.8884615384615379), (-6.461538461538462, -1.5, 1.1884615384615378), (-3.5384615384615383, 1.5, 1.1884615384615378), (-3.5384615384615383, 1.5, 0.8884615384615379), (-6.461538461538462, 1.5, 0.8884615384615379), (-6.461538461538462, 1.5, 1.1884615384615378)], [(6.0, -1.5, -1.35), (6.0, -1.5, -1.65), (4.0, -1.5, -1.65), (4.0, -1.5, -1.35), (6.0, 1.5, -1.35), (6.0, 1.5, -1.65), (4.0, 1.5, -1.65), (4.0,1.5, -1.35)], [(5.5, -2.5, 0.15), (5.5, -2.5, -0.15), (4.5, -2.5, -0.15), (4.5, -2.5, 0.15), (5.5, 0.5, 0.15), (5.5, 0.5, -0.15), (4.5, 0.5, -0.15), (4.5, 0.5, 0.15)], [(6.0, -1.5, 1.65), (6.0, -1.5, 1.35), (4.0, -1.5, 1.35), (4.0, -1.5, 1.65), (6.0, 1.5, 1.65), (6.0, 1.5, 1.35), (4.0, 1.5, 1.35), (4.0, 1.5, 1.65)], [(5.5, -0.5, 0.15), (5.5, -0.5, -0.15), (4.5, -0.5, -0.15), (4.5, -0.5, 0.15), (5.5, 2.5, 0.15), (5.5, 2.5, -0.15), (4.5, 2.5, -0.15), (4.5, 2.5, 0.15)] ] if __name__ == "__main__": eckpunkte_to_cube(raum,faces)