+ facelist.remove(Q)
+ facelist.insert(0, Q)
+ Q.smooth = 1
+ face_marked = 1
+
+ # Make merked faces BLUE. so to see them
+ #for c in Q.col:
+ # c.r = 0
+ # c.g = 0
+ # c.b = 255
+ # c.a = 255
+
+ debug("Q marked!\n")
+ print [f.smooth for f in facelist]
+ break
+
+ # Write P!
+ if split_done == 0 and face_marked == 0:
+ P = facelist[0]
+ facelist.remove(P)
+ maplist.append(P)
+
+ progress.update()
+ #if progress.progressModel.getProgress() == 100:
+ # break
+ if steps == 2:
+ """
+ for c in Q.col:
+ c.r = 0
+ c.g = 0
+ c.b = 255
+ c.a = 255
+ for c in P.col:
+ c.r = 0
+ c.g = 0
+ c.b = 255
+ c.a = 255
+ """
+ print steps
+ #maplist.append(P)
+ #maplist.append(Q)
+
+ # for f in facelist:
+ # if f not in old_facelist:
+ # print "splitted?"
+ # maplist.append(f)
+
+ break
+ """
+ """
+
+
+
+ nmesh.faces = maplist
+
+ for f in nmesh.faces:
+ f.sel = 1
+ nmesh.update()
+ print nmesh.faces
+
+ def _doHiddenSurfaceRemoval(self, mesh):
+ """Do HSR for the given mesh.
+ """
+ if len(mesh.faces) == 0:
+ return
+
+ if config.polygons['HSR'] == 'PAINTER':
+ print "\nUsing the Painter algorithm for HSR."
+ self.__simpleDepthSort(mesh)
+
+ elif config.polygons['HSR'] == 'NEWELL':
+ print "\nUsing the Newell's algorithm for HSR."
+ self.__newellDepthSort(mesh)
+
+
+ def _doEdgesStyle(self, mesh, edgestyleSelect):
+ """Process Mesh Edges accroding to a given selection style.
+
+ Examples of algorithms:
+
+ Contours:
+ given an edge if its adjacent faces have the same normal (that is
+ they are complanar), than deselect it.
+
+ Silhouettes:
+ given an edge if one its adjacent faces is frontfacing and the
+ other is backfacing, than select it, else deselect.
+ """
+
+ Mesh.Mode(Mesh.SelectModes['EDGE'])
+
+ edge_cache = MeshUtils.buildEdgeFaceUsersCache(mesh)
+
+ for i,edge_faces in enumerate(edge_cache):
+ mesh.edges[i].sel = 0
+ if edgestyleSelect(edge_faces):
+ mesh.edges[i].sel = 1
+
+ """
+ for e in mesh.edges:
+
+ e.sel = 0
+ if edgestyleSelect(e, mesh):
+ e.sel = 1
+ """
+
+
+
+# ---------------------------------------------------------------------
+#
+## GUI Class and Main Program
+#
+# ---------------------------------------------------------------------
+
+
+from Blender import BGL, Draw
+from Blender.BGL import *
+
+class GUI:
+
+ def _init():
+
+ # Output Format menu
+ output_format = config.output['FORMAT']
+ default_value = outputWriters.keys().index(output_format)+1
+ GUI.outFormatMenu = Draw.Create(default_value)
+ GUI.evtOutFormatMenu = 0
+
+ # Animation toggle button
+ GUI.animToggle = Draw.Create(config.output['ANIMATION'])
+ GUI.evtAnimToggle = 1
+
+ # Join Objects toggle button
+ GUI.joinObjsToggle = Draw.Create(config.output['JOIN_OBJECTS'])
+ GUI.evtJoinObjsToggle = 2
+
+ # Render filled polygons
+ GUI.polygonsToggle = Draw.Create(config.polygons['SHOW'])
+
+ # Shading Style menu
+ shading_style = config.polygons['SHADING']
+ default_value = shadingStyles.keys().index(shading_style)+1
+ GUI.shadingStyleMenu = Draw.Create(default_value)
+ GUI.evtShadingStyleMenu = 21
+
+ GUI.evtPolygonsToggle = 3
+ # We hide the config.polygons['EXPANSION_TRICK'], for now
+
+ # Render polygon edges
+ GUI.showEdgesToggle = Draw.Create(config.edges['SHOW'])
+ GUI.evtShowEdgesToggle = 4
+
+ # Render hidden edges
+ GUI.showHiddenEdgesToggle = Draw.Create(config.edges['SHOW_HIDDEN'])
+ GUI.evtShowHiddenEdgesToggle = 5
+
+ # Edge Style menu
+ edge_style = config.edges['STYLE']
+ default_value = edgeStyles.keys().index(edge_style)+1
+ GUI.edgeStyleMenu = Draw.Create(default_value)
+ GUI.evtEdgeStyleMenu = 6
+
+ # Edge Width slider
+ GUI.edgeWidthSlider = Draw.Create(config.edges['WIDTH'])
+ GUI.evtEdgeWidthSlider = 7
+
+ # Edge Color Picker
+ c = config.edges['COLOR']
+ GUI.edgeColorPicker = Draw.Create(c[0]/255.0, c[1]/255.0, c[2]/255.0)
+ GUI.evtEdgeColorPicker = 71
+
+ # Render Button
+ GUI.evtRenderButton = 8
+
+ # Exit Button
+ GUI.evtExitButton = 9
+
+ def draw():
+
+ # initialize static members
+ GUI._init()
+
+ glClear(GL_COLOR_BUFFER_BIT)
+ glColor3f(0.0, 0.0, 0.0)
+ glRasterPos2i(10, 350)
+ Draw.Text("VRM: Vector Rendering Method script. Version %s." %
+ __version__)
+ glRasterPos2i(10, 335)
+ Draw.Text("Press Q or ESC to quit.")
+
+ # Build the output format menu
+ glRasterPos2i(10, 310)
+ Draw.Text("Select the output Format:")
+ outMenuStruct = "Output Format %t"
+ for t in outputWriters.keys():
+ outMenuStruct = outMenuStruct + "|%s" % t
+ GUI.outFormatMenu = Draw.Menu(outMenuStruct, GUI.evtOutFormatMenu,
+ 10, 285, 160, 18, GUI.outFormatMenu.val, "Choose the Output Format")
+
+ # Animation toggle
+ GUI.animToggle = Draw.Toggle("Animation", GUI.evtAnimToggle,
+ 10, 260, 160, 18, GUI.animToggle.val,
+ "Toggle rendering of animations")
+
+ # Join Objects toggle
+ GUI.joinObjsToggle = Draw.Toggle("Join objects", GUI.evtJoinObjsToggle,
+ 10, 235, 160, 18, GUI.joinObjsToggle.val,
+ "Join objects in the rendered file")
+
+ # Render Button
+ Draw.Button("Render", GUI.evtRenderButton, 10, 210-25, 75, 25+18,
+ "Start Rendering")
+ Draw.Button("Exit", GUI.evtExitButton, 95, 210-25, 75, 25+18, "Exit!")
+
+ # Rendering Styles
+ glRasterPos2i(200, 310)
+ Draw.Text("Rendering Style:")
+
+ # Render Polygons
+ GUI.polygonsToggle = Draw.Toggle("Filled Polygons", GUI.evtPolygonsToggle,
+ 200, 285, 160, 18, GUI.polygonsToggle.val,
+ "Render filled polygons")
+
+ if GUI.polygonsToggle.val == 1:
+
+ # Polygon Shading Style
+ shadingStyleMenuStruct = "Shading Style %t"
+ for t in shadingStyles.keys():
+ shadingStyleMenuStruct = shadingStyleMenuStruct + "|%s" % t.lower()
+ GUI.shadingStyleMenu = Draw.Menu(shadingStyleMenuStruct, GUI.evtShadingStyleMenu,
+ 200, 260, 160, 18, GUI.shadingStyleMenu.val,
+ "Choose the shading style")
+
+
+ # Render Edges
+ GUI.showEdgesToggle = Draw.Toggle("Show Edges", GUI.evtShowEdgesToggle,
+ 200, 235, 160, 18, GUI.showEdgesToggle.val,
+ "Render polygon edges")
+
+ if GUI.showEdgesToggle.val == 1:
+
+ # Edge Style
+ edgeStyleMenuStruct = "Edge Style %t"
+ for t in edgeStyles.keys():
+ edgeStyleMenuStruct = edgeStyleMenuStruct + "|%s" % t.lower()
+ GUI.edgeStyleMenu = Draw.Menu(edgeStyleMenuStruct, GUI.evtEdgeStyleMenu,
+ 200, 210, 160, 18, GUI.edgeStyleMenu.val,
+ "Choose the edge style")
+
+ # Edge size
+ GUI.edgeWidthSlider = Draw.Slider("Width: ", GUI.evtEdgeWidthSlider,
+ 200, 185, 140, 18, GUI.edgeWidthSlider.val,
+ 0.0, 10.0, 0, "Change Edge Width")
+
+ # Edge Color
+ GUI.edgeColorPicker = Draw.ColorPicker(GUI.evtEdgeColorPicker,
+ 342, 185, 18, 18, GUI.edgeColorPicker.val, "Choose Edge Color")
+
+ # Show Hidden Edges
+ GUI.showHiddenEdgesToggle = Draw.Toggle("Show Hidden Edges",
+ GUI.evtShowHiddenEdgesToggle,
+ 200, 160, 160, 18, GUI.showHiddenEdgesToggle.val,
+ "Render hidden edges as dashed lines")
+
+ glRasterPos2i(10, 160)
+ Draw.Text("%s (c) 2006" % __author__)
+
+ def event(evt, val):
+
+ if evt == Draw.ESCKEY or evt == Draw.QKEY:
+ Draw.Exit()
+ else:
+ return
+
+ Draw.Redraw(1)
+
+ def button_event(evt):
+
+ if evt == GUI.evtExitButton:
+ Draw.Exit()
+
+ elif evt == GUI.evtOutFormatMenu:
+ i = GUI.outFormatMenu.val - 1
+ config.output['FORMAT']= outputWriters.keys()[i]
+
+ elif evt == GUI.evtAnimToggle:
+ config.output['ANIMATION'] = bool(GUI.animToggle.val)
+
+ elif evt == GUI.evtJoinObjsToggle:
+ config.output['JOIN_OBJECTS'] = bool(GUI.joinObjsToggle.val)
+
+ elif evt == GUI.evtPolygonsToggle:
+ config.polygons['SHOW'] = bool(GUI.polygonsToggle.val)
+
+ elif evt == GUI.evtShadingStyleMenu:
+ i = GUI.shadingStyleMenu.val - 1
+ config.polygons['SHADING'] = shadingStyles.keys()[i]
+
+ elif evt == GUI.evtShowEdgesToggle:
+ config.edges['SHOW'] = bool(GUI.showEdgesToggle.val)
+
+ elif evt == GUI.evtShowHiddenEdgesToggle:
+ config.edges['SHOW_HIDDEN'] = bool(GUI.showHiddenEdgesToggle.val)
+
+ elif evt == GUI.evtEdgeStyleMenu:
+ i = GUI.edgeStyleMenu.val - 1
+ config.edges['STYLE'] = edgeStyles.keys()[i]
+
+ elif evt == GUI.evtEdgeWidthSlider:
+ config.edges['WIDTH'] = float(GUI.edgeWidthSlider.val)
+
+ elif evt == GUI.evtEdgeColorPicker:
+ config.edges['COLOR'] = [int(c*255.0) for c in GUI.edgeColorPicker.val]
+
+ elif evt == GUI.evtRenderButton:
+ label = "Save %s" % config.output['FORMAT']
+ # Show the File Selector
+ global outputfile
+ Blender.Window.FileSelector(vectorize, label, outputfile)
+
+ else:
+ print "Event: %d not handled!" % evt
+
+ if evt:
+ Draw.Redraw(1)
+ #GUI.conf_debug()
+
+ def conf_debug():
+ from pprint import pprint
+ print "\nConfig"
+ pprint(config.output)
+ pprint(config.polygons)
+ pprint(config.edges)
+
+ _init = staticmethod(_init)
+ draw = staticmethod(draw)
+ event = staticmethod(event)
+ button_event = staticmethod(button_event)
+ conf_debug = staticmethod(conf_debug)
+
+# A wrapper function for the vectorizing process
+def vectorize(filename):
+ """The vectorizing process is as follows:
+
+ - Instanciate the writer and the renderer
+ - Render!
+ """
+
+ if filename == "":
+ print "\nERROR: invalid file name!"
+ return
+
+ from Blender import Window
+ editmode = Window.EditMode()
+ if editmode: Window.EditMode(0)
+
+ actualWriter = outputWriters[config.output['FORMAT']]
+ writer = actualWriter(filename)
+
+ renderer = Renderer()
+ renderer.doRendering(writer, config.output['ANIMATION'])
+
+ if editmode: Window.EditMode(1)
+
+# We use a global progress Indicator Object
+progress = None
+
+# Here the main
+if __name__ == "__main__":
+
+ global progress
+
+ outputfile = ""
+ basename = Blender.sys.basename(Blender.Get('filename'))
+ if basename != "":
+ outputfile = Blender.sys.splitext(basename)[0] + "." + str(config.output['FORMAT']).lower()
+
+ if Blender.mode == 'background':
+ progress = ConsoleProgressIndicator()
+ vectorize(outputfile)
+ else:
+ progress = GraphicalProgressIndicator()
+ Draw.Register(GUI.draw, GUI.event, GUI.button_event)