#
# Additional credits:
# Thanks to Emilio Aguirre for S2flender from which I took inspirations :)
-# Thanks to Anthony C. D'Agostino for the backface.py script
+# Thanks to Anthony C. D'Agostino for the original backface.py script
#
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
#
-## Mesh representation class
+## Object representation class
#
# ---------------------------------------------------------------------
for face in obj.getData().faces:
self._printPolygon(face)
+ self._printWireframe(obj.getData())
+
self.file.write("</g>\n")
self._printFooter()
"""Print SVG header."""
self.file.write("<?xml version=\"1.0\"?>\n")
- self.file.write("<svg version=\"1.2\"\n")
+ self.file.write("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n")
+ self.file.write("\t\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n")
+ self.file.write("<svg version=\"1.1\"\n")
self.file.write("\txmlns=\"http://www.w3.org/2000/svg\"\n")
self.file.write("\twidth=\"%d\" height=\"%d\" streamable=\"true\">\n\n" %
self.canvasSize)
self.file.write("\n</svg>\n")
self.file.close()
+ def _printWireframe(self, mesh):
+ """Print the wireframe using mesh edges... is this the correct way?
+ """
+
+ print mesh.edges
+ print
+ print mesh.verts
+
+ stroke_width=0.5
+ stroke_col = [0, 0, 0]
+
+ self.file.write("<g>\n")
+
+ for e in mesh.edges:
+ self.file.write("<line x1=\"%g\" y1=\"%g\" x2=\"%g\" y2=\"%g\"\n"
+ % ( e.v1[0], e.v1[1], e.v2[0], e.v2[1] ) )
+ self.file.write(" style=\"stroke:rgb("+str(stroke_col[0])+","+str(stroke_col[1])+","+str(stroke_col[2])+");")
+ self.file.write(" stroke-width:"+str(stroke_width)+";\n")
+ self.file.write(" stroke-linecap:round;stroke-linejoin:round")
+ self.file.write("\"/>\n")
+
+ self.file.write("</g>\n")
+
+
+
def _printPolygon(self, face):
"""Print our primitive, finally.
"""
transformed_mesh = NMesh.New("flat"+obj.name)
transformed_mesh.hasVertexColours(1)
+ # process Edges
+ for v in obj.getData().verts:
+ transformed_mesh.verts.append(v)
+ transformed_mesh.edges = self._processEdges(obj.getData().edges)
+ print transformed_mesh.edges
+
+
# Store the materials
materials = obj.getData().getMaterials()
return (d<0)
- def _doClipping(face):
+
+ def _doClipping():
+ return
+
+
+ # Per object methods
+
+ def _doVisibleSurfaceDetermination(object):
+ return
+
+ def _doColorizing(object):
return
+ def _doStylizingEdges(self, object, style):
+ """Process Mesh Edges. (For now copy the edge data, in next version it
+ can be a place where recognize silouhettes and/or contours).
+
+ input: an edge list
+ return: a processed edge list
+ """
+ return
+
+
# ---------------------------------------------------------------------
#
scene.link(o)
def vectorize(filename):
+ """The vectorizing process is as follows:
+
+ - Open the writer
+ - Render the scene
+ - Close the writer
+
+ If you want to render an animation the second pass should be
+ repeated for any frame, and the frame number should be passed to the
+ renderer.
+ """
print "Filename: %s" % filename
scene = Scene.GetCurrent()
renderer = Renderer()
-
+
flatScene = renderer.doRendering(scene)
canvasSize = renderer.getCanvasSize()
# Here the main
if __name__ == "__main__":
+ # with this trick we can run the script in batch mode
try:
Blender.Window.FileSelector (vectorize, 'Save SVG', "proba.svg")
except: