From 8efb1d4b187f35f92116c088bdc05b778a2e9fdf Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Tue, 11 May 2021 23:46:05 +0200 Subject: [PATCH] adjustments in paperfold --- .../import_3d_mesh/import_3d_mesh.py | 4 ++-- extensions/fablabchemnitz/paperfold.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/extensions/fablabchemnitz/import_3d_mesh/import_3d_mesh.py b/extensions/fablabchemnitz/import_3d_mesh/import_3d_mesh.py index 2fc91b75..948caccd 100644 --- a/extensions/fablabchemnitz/import_3d_mesh/import_3d_mesh.py +++ b/extensions/fablabchemnitz/import_3d_mesh/import_3d_mesh.py @@ -243,7 +243,7 @@ class WavefrontObj(object): edge_list = [] for face in self.fce: for j, edge in enumerate(face): - # Ascending order of certices (for duplicate detection) + # Ascending order of vertices (for duplicate detection) edge_list.append(sorted([edge, face[(j + 1) % len(face)]])) return [list(x) for x in sorted(set(tuple(x) for x in edge_list))] @@ -308,7 +308,7 @@ class Poly3D(inkex.GenerateExtension): # we will put all the rotations in the object name, so it can be repeated in poly = Group.new(obj.name + ':' + make_rotation_log(so)) (pos_x, pos_y) = self.svg.namedview.center - poly.transform.add_translate(pos_x, pos_y) + #poly.transform.add_translate(pos_x, pos_y) poly.transform.add_scale(scale) # TRANSFORMATION OF THE OBJECT (ROTATION, SCALE, ETC) diff --git a/extensions/fablabchemnitz/paperfold.py b/extensions/fablabchemnitz/paperfold.py index 8e530fb9..7b770d25 100644 --- a/extensions/fablabchemnitz/paperfold.py +++ b/extensions/fablabchemnitz/paperfold.py @@ -40,6 +40,7 @@ todo: - write tab and slot generator (like joinery/polyhedra extension) - fstl preview - fix line: dualGraph.add_edge(face1.idx(), face2.idx(), idx=edge.idx(), weight=edgeweight) # #might fail without throwing any error (silent aborts) ... +- option to set fill color per face """ class Unfold(inkex.EffectExtension): @@ -713,14 +714,14 @@ class Unfold(inkex.EffectExtension): #mesh = om.read_polymesh(self.options.inputfile) #we must work with triangles instead of polygons because the algorithm works with that fullUnfolded, unfoldedComponents = self.unfold(mesh) - + unfoldComponentCount = len(unfoldedComponents) #if len(unfoldedComponents) == 0: # inkex.utils.debug("Error: no components were unfolded.") # exit(1) if self.options.printStats is True: - inkex.utils.debug("Unfolding components: {:0.0f}".format(len(unfoldedComponents))) + inkex.utils.debug("Unfolding components: {:0.0f}".format(unfoldComponentCount)) # Compute maxSize of the components # All components must be scaled to the same size as the largest component @@ -729,6 +730,8 @@ class Unfold(inkex.EffectExtension): [xmin, ymin, boxSize] = self.findBoundingBox(unfolding[0]) if boxSize > maxSize: maxSize = boxSize + + xSpacing = maxSize / unfoldComponentCount * 0.1 # 10% spacing between each component; calculated by max box size ######################################################### # mode config for joinery: @@ -760,6 +763,10 @@ class Unfold(inkex.EffectExtension): self.options.joineryMode = True #we set to true even if false because we need the same flat structure for origami simulator self.options.separateGluePairsByColor = False #we need to have no weird random colors in this mode self.options.edgeStyle = "opacitiesForAngles" #highly important for simulation + self.options.dashes = False + self.options.printGluePairNumbers = False + self.options.printAngles = False + self.options.printLengths = False self.options.importCoplanarEdges = True self.options.colorCutEdges = "#000000" #black self.options.colorCoplanarEdges = "#ffff00" #yellow @@ -786,12 +793,12 @@ class Unfold(inkex.EffectExtension): if i != 0: previous_bbox = paperfoldMainGroup[i-1].bounding_box() this_bbox = paperfoldPageGroup.bounding_box() - paperfoldPageGroup.set("transform","translate({:0.6f}, 0.0)".format(previous_bbox.left + previous_bbox.width - this_bbox.left)) + paperfoldPageGroup.set("transform", "translate({:0.6f}, 0.0)".format(previous_bbox.left + previous_bbox.width - this_bbox.left + xSpacing)) paperfoldMainGroup.append(paperfoldPageGroup) #apply scale factor - translation_matrix = [[self.options.scalefactor, 0.0, 0.0], [0.0, self.options.scalefactor, 0.0]] + translation_matrix = [[self.options.scalefactor, 0.0, 0.0], [0.0, self.options.scalefactor, 0.0]] paperfoldMainGroup.transform = Transform(translation_matrix) * paperfoldMainGroup.transform #paperfoldMainGroup.set('transform', 'scale(%f,%f)' % (self.options.scalefactor, self.options.scalefactor))