[Bf-extensions-cvs] [6dcaf5f] master: paper model: switch to millimeters for all dimensions; fixed two errors

Adam Dominec noreply at git.blender.org
Wed May 13 14:07:44 CEST 2015


Commit: 6dcaf5f5b25bd16e45052abd2b90940f6c587b4f
Author: Adam Dominec
Date:   Wed May 13 14:04:21 2015 +0200
Branches: master
https://developer.blender.org/rBAC6dcaf5f5b25bd16e45052abd2b90940f6c587b4f

paper model: switch to millimeters for all dimensions; fixed two errors

Corresponding commits in my development repository (latest first):
 3e2a: compatibility fix for blender 2.70
 437b: line thickness as (common_base) * (coefficient)
 9ee4: fix: exporting without tabs
 8963: unit handling: convert everything in the SVG to millimeters

===================================================================

M	io_export_paper_model.py

===================================================================

diff --git a/io_export_paper_model.py b/io_export_paper_model.py
index 2917470..cf8caee 100644
--- a/io_export_paper_model.py
+++ b/io_export_paper_model.py
@@ -185,8 +185,8 @@ class Unfolder:
     def save(self, properties):
         """Export the document"""
         # Note about scale: input is direcly in blender length
-        # Island.apply_scale multiplies everything by a user-defined ratio
-        # SVG object multiplies everything by ppm (output in pixels)
+        # Mesh.scale_islands multiplies everything by a user-defined ratio
+        # SVG object multiplies everything by 1000 (output in millimeters)
         filepath = properties.filepath
         if filepath.lower().endswith((".svg", ".png")):
             filepath = filepath[0:-4]
@@ -237,7 +237,7 @@ class Unfolder:
                 tex.active = True
                 bpy.ops.mesh.uv_texture_remove()
 
-        svg = SVG(page_size, ppm, properties.style, (properties.output_type == 'NONE'))
+        svg = SVG(page_size, properties.style, (properties.output_type == 'NONE'))
         svg.do_create_stickers = properties.do_create_stickers
         svg.margin = properties.output_margin
         svg.text_size = properties.sticker_width
@@ -649,7 +649,7 @@ class Edge:
         self.is_main_cut = True
         self.priority = None
         self.angle = None
-        self.freestyle = edge.use_freestyle_mark # freestyle edges will be highlighted
+        self.freestyle = getattr(edge, "use_freestyle_mark", False) # freestyle edges will be highlighted
         self.va.edges.append(self)  #FIXME: editing foreign attribute
         self.vb.edges.append(self)  #FIXME: editing foreign attribute
 
@@ -1311,12 +1311,11 @@ class NumberAlone:
 class SVG:
     """Simple SVG exporter"""
 
-    def __init__(self, page_size: M.Vector, ppm, style, pure_net=True):
+    def __init__(self, page_size: M.Vector, style, pure_net=True):
         """Initialize document settings.
         page_size: document dimensions in meters
         pure_net: if True, do not use image"""
         self.page_size = page_size
-        self.ppm = ppm
         self.pure_net = pure_net
         self.style = style
         self.margin = 0
@@ -1325,14 +1324,16 @@ class SVG:
     def format_vertex(self, vector, pos=M.Vector((0, 0))):
         """Return a string with both coordinates of the given vertex."""
         x, y = vector + pos
-        return "{:.6f} {:.6f}".format((x + self.margin) * self.ppm, (self.page_size.y - y - self.margin) * self.ppm)
+        return "{:.6f} {:.6f}".format((x + self.margin) * 1000, (self.page_size.y - y - self.margin) * 1000)
 
     def write(self, mesh, filename):
         """Write data to a file given by its name."""
         line_through = " L ".join  # used for formatting of SVG path data
-        format_style = {'SOLID': "none", 'DOT': "0.2,4", 'DASH': "4,8", 'LONGDASH': "6,3", 'DASHDOT': "8,4,2,4"}
         rows = "\n".join
 
+        dl = ["{:.2f}".format(length * self.style.line_width * 1000) for length in (2, 5, 10)]
+        format_style = {'SOLID': "none", 'DOT': "{0},{1}".format(*dl), 'DASH': "{1},{2}".format(*dl), 'LONGDASH': "{2},{1}".format(*dl), 'DASHDOT': "{2},{1},{0},{1}".format(*dl)}
+
         def format_color(vec):
             return "#{:02x}{:02x}{:02x}".format(round(vec[0] * 255), round(vec[1] * 255), round(vec[2] * 255))
 
@@ -1357,22 +1358,17 @@ class SVG:
             ("freestyle_alpha", "freestyle_color"),
             ("inbg_alpha", "inbg_color"), ("sticker_alpha", "sticker_fill"),
             ("text_alpha", "text_color"))})
-        styleargs.update({name: getattr(self.style, name) for name in
-            ("outer_width", "convex_width", "concave_width", "freestyle_width")})
-        styleargs.update({"outbg_width": self.style.outer_width * self.style.outbg_width,
-            "convexbg_width": self.style.convex_width * self.style.inbg_width,
-            "concavebg_width": self.style.concave_width * self.style.inbg_width})
-        page_size_pixels = self.page_size * self.ppm
-        margin_pixels = self.margin * self.ppm
+        styleargs.update({name: getattr(self.style, name) * self.style.line_width * 1000 for name in
+            ("outer_width", "convex_width", "concave_width", "freestyle_width", "outbg_width", "inbg_width")})
         for num, page in enumerate(mesh.pages):
             with open("{}_{}.svg".format(filename, page.name), 'w') as f:
-                print(self.svg_base.format(width=page_size_pixels.x, height=page_size_pixels.y), file=f)
+                print(self.svg_base.format(width=self.page_size.x*1000, height=self.page_size.y*1000), file=f)
                 print(self.css_base.format(**styleargs), file=f)
                 if page.image_path:
                     print(self.image_linked_tag.format(
-                        pos="{0} {0}".format(margin_pixels),
-                        width=page_size_pixels.x - 2 * margin_pixels,
-                        height=page_size_pixels.y - 2 * margin_pixels,
+                        pos="{0} {0}".format(self.page_size),
+                        width=self.page_size.x - 2 * self.page_size,
+                        height=self.page_size.y - 2 * self.page_size,
                         path=path_convert(page.image_path)),
                         file=f)
                 if len(page.islands) > 1:
@@ -1383,23 +1379,23 @@ class SVG:
                     if island.image_path:
                         print(self.image_linked_tag.format(
                             pos=self.format_vertex(island.pos + M.Vector((0, island.bounding_box.y))),
-                            width=island.bounding_box.x*self.ppm,
-                            height=island.bounding_box.y*self.ppm,
+                            width=island.bounding_box.x*1000,
+                            height=island.bounding_box.y*1000,
                             path=path_convert(island.image_path)),
                             file=f)
                     elif island.embedded_image:
                         print(self.image_embedded_tag.format(
                                 pos=self.format_vertex(island.pos + M.Vector((0, island.bounding_box.y))),
-                                width=island.bounding_box.x*self.ppm,
-                                height=island.bounding_box.y*self.ppm,
+                                width=island.bounding_box.x*1000,
+                                height=island.bounding_box.y*1000,
                                 path=island.image_path),
                             island.embedded_image, "'/>",
                             file=f, sep="")
                     if island.title:
                         print(self.text_tag.format(
-                            size=self.ppm * self.text_size,
-                            x=self.ppm * (island.bounding_box.x*0.5 + island.pos.x + self.margin),
-                            y=self.ppm * (self.page_size.y - island.pos.y - self.margin - 0.2 * self.text_size),
+                            size=1000 * self.text_size,
+                            x=1000 * (island.bounding_box.x*0.5 + island.pos.x + self.margin),
+                            y=1000 * (self.page_size.y - island.pos.y - self.margin - 0.2 * self.text_size),
                             label=island.title), file=f)
 
                     data_markers, data_stickerfill, data_outer, data_convex, data_concave, data_freestyle = (list() for i in range(6))
@@ -1412,9 +1408,9 @@ class SVG:
                                     label=marker.text,
                                     pos=self.format_vertex(marker.center, island.pos),
                                     mat=format_matrix(marker.rot),
-                                    size=marker.width * self.ppm))
+                                    size=marker.width * 1000))
                         elif isinstance(marker, Arrow):
-                            size = marker.size * self.ppm
+                            size = marker.size * 1000
                             position = marker.center + marker.rot*marker.size*M.Vector((0, -0.9))
                             data_markers.append(self.arrow_marker_tag.format(
                                 index=marker.text,
@@ -1426,8 +1422,8 @@ class SVG:
                             data_markers.append(self.text_transformed_tag.format(
                                 label=marker.text,
                                 pos=self.format_vertex(marker.center, island.pos),
-                                mat=format_matrix(marker.rot)),
-                                size=marker.size * self.ppm)
+                                mat=format_matrix(marker.rot),
+                                size=marker.size * 1000))
                     if data_stickerfill and self.style.sticker_fill[3] > 0:
                         print("<path class='sticker' d='", rows(data_stickerfill), "'/>", file=f)
 
@@ -1467,13 +1463,11 @@ class SVG:
 
                     if data_freestyle:
                         print("<path class='freestyle' d='", rows(data_freestyle), "'/>", file=f)
+                    if (data_convex or data_concave) and not self.pure_net and self.style.use_inbg:
+                        print("<path class='inner_background' d='", rows(data_convex + data_concave), "'/>", file=f)
                     if data_convex:
-                        if not self.pure_net and self.style.use_inbg:
-                            print("<path class='convex_background' d='", rows(data_convex), "'/>", file=f)
                         print("<path class='convex' d='", rows(data_convex), "'/>", file=f)
                     if data_concave:
-                        if not self.pure_net and self.style.use_inbg:
-                            print("<path class='concave_background' d='", rows(data_concave), "'/>", file=f)
                         print("<path class='concave' d='", rows(data_concave), "'/>", file=f)
                     if data_outer:
                         if not self.pure_net and self.style.use_outbg:
@@ -1489,20 +1483,19 @@ class SVG:
 
     image_linked_tag = "<image transform='translate({pos})' width='{width}' height='{height}' xlink:href='{path}'/>"
     image_embedded_tag = "<image transform='translate({pos})' widt

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list