# Copyright (C) 2006 - Giorgio Griffon # This program 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 2 of the License, or # (at your option) any later version. # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #esporta una mesh di blender in stl import Blender from Blender import NMesh,Object ######################################## # CAMBIARE QUESTO NOME IN BASE ALLA MESH DA ESPORTARE nome="Tube"#nome della mesh da esportare ######################################## f=open("blend.stl","w") f.write("solid "+nome+"\n") ############################# #questo servirebbe se l'oggetto ha i suoi assi propri #ruotati rispetto a quelli fissi #oggetto=Object.Get(nome) #print oggetto.rot ############################# mesh=NMesh.GetRaw(nome) print "##############" n_tr=0#numero triangoli dell'stl n_facce=len(mesh.faces) for i in range(0,n_facce): faccia=mesh.faces[i] print "faccia "+str(i) #print faccia.no nx=faccia.no[0] ny=faccia.no[1] nz=faccia.no[2] n_vertici=len(faccia.v) if n_vertici>2:#non dovrebbe succedere,ma se capita... f.write("facet normal "+str(nx)+" "+str(ny)+" "+str(nz)+"\n") f.write(" outer loop") for j in range(0,3): vertice=faccia.v[j] #print "vertice "+str(j) f.write("\n vertex") for k in range(0,3): #print vertice[k] f.write(" "+str(vertice[k])) f.write("\n endloop\n") f.write("endfacet\n") n_tr=n_tr+1 if n_vertici>3: f.write("facet normal "+str(nx)+" "+str(ny)+" "+str(nz)+"\n") f.write(" outer loop") for j in [0,2,3]: vertice=faccia.v[j] #print "vertice "+str(j) f.write("\n vertex") for k in range(0,3): #print vertice[k] f.write(" "+str(vertice[k])) f.write("\n endloop\n") f.write("endfacet\n") n_tr=n_tr+1 f.write("endsolid\n") f.close() print "salvato stl con "+str(n_tr)+" facce triangolari"