# This file is part of the Printrun suite. # # Printrun is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Printrun is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Printrun. If not, see . import sys, struct, math def cross(v1, v2): return [v1[1]*v2[2]-v1[2]*v2[1], v1[2]*v2[0]-v1[0]*v2[2], v1[0]*v2[1]-v1[1]*v2[0]] def genfacet(v): veca = [v[1][0]-v[0][0], v[1][1]-v[0][1], v[1][2]-v[0][2]] vecb = [v[2][0]-v[1][0], v[2][1]-v[1][1], v[2][2]-v[1][2]] vecx = cross(veca, vecb) vlen = math.sqrt(sum(map(lambda x:x*x, vecx))) if vlen == 0: vlen = 1 normal = map(lambda x:x/vlen, vecx) return [normal, v] I = [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ] def transpose(matrix): return zip(*matrix) #return [[v[i] for v in matrix] for i in xrange(len(matrix[0]))] def multmatrix(vector, matrix): return map(sum, transpose(map(lambda x:[x[0]*p for p in x[1]], zip(vector, transpose(matrix))))) def applymatrix(facet, matrix = I): #return facet #return [map(lambda x:-1.0*x, multmatrix(facet[0]+[1], matrix)[:3]), map(lambda x:multmatrix(x+[1], matrix)[:3], facet[1])] return genfacet(map(lambda x:multmatrix(x+[1], matrix)[:3], facet[1])) f = [[0, 0, 0],[[-3.022642, 0.642482, -9.510565],[-3.022642, 0.642482, -9.510565],[-3.022642, 0.642482, -9.510565]]] m = [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 1], [0, 0, 0, 1] ] def emitstl(filename, facets = [], objname = "stltool_export", binary = 1): if filename is None: return if binary: f = open(filename, "wb") buf = "".join(["\0"]*80) buf+=struct.pack("i): working.remove(j[1]) else: break for j in (sorted(s.facetsmaxz)): if(j[0]