From d8063a0d4fb1d4448857006369dd02c3d30c8df6 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Mon, 19 Jun 2006 00:19:34 +0200 Subject: [PATCH] Edge styles (silhouettes, contours) * Implement Edge styles (silhouettes, contours) * Handle face opacity (alpha component) in SVG output * Disable joining objects when in batch mode, it crashes blender * Prepare support for config settings Signed-off-by: Antonio Ospite --- vrm.py | 216 ++++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 161 insertions(+), 55 deletions(-) diff --git a/vrm.py b/vrm.py index 8914045..b3aac25 100755 --- a/vrm.py +++ b/vrm.py @@ -2,12 +2,12 @@ """ Name: 'VRM' Blender: 241 -Group: 'Export' -Tooltip: 'Vector Rendering Method Export Script' +Group: 'Render' +Tooltip: 'Vector Rendering Method script' """ __author__ = "Antonio Ospite" -__url__ = ["blender"] +__url__ = ["http://vrm.projects.blender.org"] __version__ = "0.3" __bpydoc__ = """\ @@ -43,19 +43,21 @@ __bpydoc__ = """\ # # Things TODO for a next release: # - Switch to the Mesh structure, should be considerably faster -# (partially done, but cannot sort faces, yet) +# (partially done, but with Mesh we cannot sort faces, yet) # - Use a better depth sorting algorithm # - Review how selections are made (this script uses selection states of # primitives to represent visibility infos) # - Implement clipping of primitives and do handle object intersections. # (for now only clipping for whole objects is supported). -# - Implement Edge Styles (silhouettes, contours, etc.) +# - Implement Edge Styles (silhouettes, contours, etc.) (partially done). # - Implement Edge coloring # - Use multiple lighting sources in color calculation -# - Implement Shading Styles? -# - Use another representation for the 2D projection? +# - Implement Shading Styles? (for now we use Flat Shading). +# - Use a data structure other than Mesh to represent the 2D image? # Think to a way to merge adjacent polygons that have the same color. -# - Add other Vector Writers. +# Or a way to use paths for silhouettes and contours. +# - Add Vector Writers other that SVG. +# - Consider SMIL for animation handling instead of ECMA Script? # # --------------------------------------------------------------------- # @@ -76,17 +78,81 @@ from math import * # Some global settings PRINT_POLYGONS = True -PRINT_EDGES = False -SHOW_HIDDEN_EDGES = False +POLYGON_EXPANSION_TRICK = True +PRINT_EDGES = True +SHOW_HIDDEN_EDGES = False +#EDGE_STYLE = 'normal' +EDGE_STYLE = 'silhouette' EDGES_WIDTH = 0.5 -POLYGON_EXPANSION_TRICK = True - RENDER_ANIMATION = False -# Does not work in batch mode!! -#OPTIMIZE_FOR_SPACE = True +OPTIMIZE_FOR_SPACE = True + +OUTPUT_FORMAT = 'SVG' + + +# --------------------------------------------------------------------- +# +## Utility Mesh class +# +# --------------------------------------------------------------------- +class MeshUtils: + def __init__(self): + return + + def getEdgeAdjacentFaces(self, edge, mesh): + """Get the faces adjacent to a given edge. + + There can be 0, 1 or more (usually 2) faces adjacent to an edge. + """ + adjface_list = [] + + for f in mesh.faces: + if (edge.v1 in f.v) and (edge.v2 in f.v): + adjface_list.append(f) + + return adjface_list + + def isVisibleEdge(self, e, mesh): + """Normal edge selection rule. + + An edge is visible if _any_ of its adjacent faces is selected. + Note: if the edge has no adjacent faces we want to show it as well, + useful for "edge only" portion of objects. + """ + + adjacent_faces = self.getEdgeAdjacentFaces(e, mesh) + + if len(adjacent_faces) == 0: + return True + + selected_faces = [f for f in adjacent_faces if f.sel] + + if len(selected_faces) != 0: + return True + else: + return False + + def isSilhouetteEdge(self, e, mesh): + """Silhuette selection rule. + + An edge is a silhuette edge if it is shared by two faces with + different selection status or if it is a boundary edge of a selected + face. + """ + + adjacent_faces = self.getEdgeAdjacentFaces(e, mesh) + + if ((len(adjacent_faces) == 1 and adjacent_faces[0].sel == 1) or + (len(adjacent_faces) == 2 and + adjacent_faces[0].sel != adjacent_faces[1].sel) + ): + return True + else: + return False + # --------------------------------------------------------------------- @@ -214,9 +280,10 @@ class Projector: return m + # --------------------------------------------------------------------- # -## 2DObject representation class +## 2D Object representation class # # --------------------------------------------------------------------- @@ -446,7 +513,7 @@ class SVGVectorWriter(VectorWriter): for face in mesh.faces: if not face.sel: - continue + continue self.file.write("