adjustments in paperfold

This commit is contained in:
Mario Voigt 2021-05-11 23:46:05 +02:00
parent 5f9d872b47
commit 8efb1d4b18
2 changed files with 13 additions and 6 deletions

View File

@ -243,7 +243,7 @@ class WavefrontObj(object):
edge_list = [] edge_list = []
for face in self.fce: for face in self.fce:
for j, edge in enumerate(face): 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)]])) 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))] 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 # 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)) poly = Group.new(obj.name + ':' + make_rotation_log(so))
(pos_x, pos_y) = self.svg.namedview.center (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) poly.transform.add_scale(scale)
# TRANSFORMATION OF THE OBJECT (ROTATION, SCALE, ETC) # TRANSFORMATION OF THE OBJECT (ROTATION, SCALE, ETC)

View File

@ -40,6 +40,7 @@ todo:
- write tab and slot generator (like joinery/polyhedra extension) - write tab and slot generator (like joinery/polyhedra extension)
- fstl preview - fstl preview
- fix line: dualGraph.add_edge(face1.idx(), face2.idx(), idx=edge.idx(), weight=edgeweight) # #might fail without throwing any error (silent aborts) ... - 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): 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 #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) fullUnfolded, unfoldedComponents = self.unfold(mesh)
unfoldComponentCount = len(unfoldedComponents)
#if len(unfoldedComponents) == 0: #if len(unfoldedComponents) == 0:
# inkex.utils.debug("Error: no components were unfolded.") # inkex.utils.debug("Error: no components were unfolded.")
# exit(1) # exit(1)
if self.options.printStats is True: 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 # Compute maxSize of the components
# All components must be scaled to the same size as the largest component # All components must be scaled to the same size as the largest component
@ -730,6 +731,8 @@ class Unfold(inkex.EffectExtension):
if boxSize > maxSize: if boxSize > maxSize:
maxSize = boxSize maxSize = boxSize
xSpacing = maxSize / unfoldComponentCount * 0.1 # 10% spacing between each component; calculated by max box size
######################################################### #########################################################
# mode config for joinery: # 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.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.separateGluePairsByColor = False #we need to have no weird random colors in this mode
self.options.edgeStyle = "opacitiesForAngles" #highly important for simulation 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.importCoplanarEdges = True
self.options.colorCutEdges = "#000000" #black self.options.colorCutEdges = "#000000" #black
self.options.colorCoplanarEdges = "#ffff00" #yellow self.options.colorCoplanarEdges = "#ffff00" #yellow
@ -786,7 +793,7 @@ class Unfold(inkex.EffectExtension):
if i != 0: if i != 0:
previous_bbox = paperfoldMainGroup[i-1].bounding_box() previous_bbox = paperfoldMainGroup[i-1].bounding_box()
this_bbox = paperfoldPageGroup.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) paperfoldMainGroup.append(paperfoldPageGroup)