added some more features to paperfold
This commit is contained in:
parent
8cdbf8d9ef
commit
8616f0135f
@ -4,9 +4,11 @@
|
|||||||
<id>fablabchemnitz.de.paperfold</id>
|
<id>fablabchemnitz.de.paperfold</id>
|
||||||
<param name="tab" type="notebook">
|
<param name="tab" type="notebook">
|
||||||
<page name="tab_settings" gui-text="Paperfold for Inkscape">
|
<page name="tab_settings" gui-text="Paperfold for Inkscape">
|
||||||
<param name="inputfile" type="path" gui-text="Input File" filetypes="obj,off,ply,stl" gui-description="The model to unfold" mode="file">/your/beautiful/3dmodel/file</param>
|
<param name="inputfile" type="path" gui-text="Input File" filetypes="obj,off,ply,stl" mode="file" gui-description="The model to unfold. You can use obj files provided in extensions dir of Inkscape \Poly3DObjects\*.obj to play around">/your/beautiful/3dmodel/file</param>
|
||||||
<param name="maxNumFaces" type="int" min="1" max="99999" gui-text="Maximum allowed faces" gui-description="If the STL file has too much detail it contains a large number of faces. This will make unfolding extremely slow. So we can limit it.">200</param>
|
<param name="maxNumFaces" type="int" min="1" max="99999" gui-text="Maximum allowed faces" gui-description="If the STL file has too much detail it contains a large number of faces. This will make unfolding extremely slow. So we can limit it.">200</param>
|
||||||
<param name="printNumbers" type="bool" gui-text="Print numbers on the cut edges">true</param>
|
<param name="printNumbers" type="bool" gui-text="Print numbers on the cut edges">true</param>
|
||||||
|
<param name="printAngles" type="bool" gui-text="Print folding angles on the cut edges">true</param>
|
||||||
|
<param name="fontSize" type="int" min="1" max="100" gui-text="Label font size (%)">15</param>
|
||||||
<param name="scalefactor" type="float" precision="3" min="0.0001" max="10000.0" gui-text="Manual scale factor" gui-description="default is 1.0">1.0</param>
|
<param name="scalefactor" type="float" precision="3" min="0.0001" max="10000.0" gui-text="Manual scale factor" gui-description="default is 1.0">1.0</param>
|
||||||
<param name="resizetoimport" type="bool" gui-text="Resize the canvas to the imported drawing's bounding box">true</param>
|
<param name="resizetoimport" type="bool" gui-text="Resize the canvas to the imported drawing's bounding box">true</param>
|
||||||
<param name="extraborder" type="float" precision="3" gui-text="Add extra border around fitted canvas">0.0</param>
|
<param name="extraborder" type="float" precision="3" gui-text="Add extra border around fitted canvas">0.0</param>
|
||||||
@ -22,7 +24,10 @@
|
|||||||
<param name="color_coplanar_lines" type="color" appearance="colorbutton" gui-text="Color for coplanar lines">1943148287</param>
|
<param name="color_coplanar_lines" type="color" appearance="colorbutton" gui-text="Color for coplanar lines">1943148287</param>
|
||||||
<param name="color_valley_perforate" type="color" appearance="colorbutton" gui-text="Color for valley perforations">3422552319</param>
|
<param name="color_valley_perforate" type="color" appearance="colorbutton" gui-text="Color for valley perforations">3422552319</param>
|
||||||
<param name="color_mountain_perforate" type="color" appearance="colorbutton" gui-text="Color for mountain perforations">879076607</param>
|
<param name="color_mountain_perforate" type="color" appearance="colorbutton" gui-text="Color for mountain perforations">879076607</param>
|
||||||
|
<param name="dashes" type="bool" gui-text="Dashes for cut/coplanar lines">true</param>
|
||||||
<param name="printStats" type="bool" gui-text="Show some unfold statistics">true</param>
|
<param name="printStats" type="bool" gui-text="Show some unfold statistics">true</param>
|
||||||
|
<label appearance="header">Post Processing</label>
|
||||||
|
<label appearance="url">https://clementzheng.github.io/joinery</label>
|
||||||
</page>
|
</page>
|
||||||
<page name="tab_about" gui-text="About">
|
<page name="tab_about" gui-text="About">
|
||||||
<label appearance="header">Paperfold for Inkscape</label>
|
<label appearance="header">Paperfold for Inkscape</label>
|
||||||
|
@ -107,14 +107,7 @@ def triangleIntersection(t1, t2, epsilon):
|
|||||||
# Functions for visualisation and output
|
# Functions for visualisation and output
|
||||||
def addVisualisationData(mesh, unfoldedMesh, originalHalfedges, unfoldedHalfedges, glueNumber, foldingDirection):
|
def addVisualisationData(mesh, unfoldedMesh, originalHalfedges, unfoldedHalfedges, glueNumber, foldingDirection):
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
# Folding direction
|
foldingDirection[unfoldedMesh.edge_handle(unfoldedHalfedges[i]).idx()] = round(math.degrees(mesh.calc_dihedral_angle(originalHalfedges[i])), 3)
|
||||||
if round(math.degrees(mesh.calc_dihedral_angle(originalHalfedges[i])), 3) == 0.0:
|
|
||||||
foldingDirection[unfoldedMesh.edge_handle(unfoldedHalfedges[i]).idx()] = 0 # adjacent coplanar
|
|
||||||
elif mesh.calc_dihedral_angle(originalHalfedges[i]) < 0:
|
|
||||||
foldingDirection[unfoldedMesh.edge_handle(unfoldedHalfedges[i]).idx()] = -1
|
|
||||||
else:
|
|
||||||
foldingDirection[unfoldedMesh.edge_handle(unfoldedHalfedges[i]).idx()] = 1
|
|
||||||
|
|
||||||
# Information, which edges belong together
|
# Information, which edges belong together
|
||||||
glueNumber[unfoldedMesh.edge_handle(unfoldedHalfedges[i]).idx()] = mesh.edge_handle(originalHalfedges[i]).idx()
|
glueNumber[unfoldedMesh.edge_handle(unfoldedHalfedges[i]).idx()] = mesh.edge_handle(originalHalfedges[i]).idx()
|
||||||
|
|
||||||
@ -128,7 +121,7 @@ def unfoldSpanningTree(mesh, spanningTree):
|
|||||||
|
|
||||||
isFoldingEdge = np.zeros(numUnfoldedEdges, dtype=bool) # Indicates whether an edge is folded or cut
|
isFoldingEdge = np.zeros(numUnfoldedEdges, dtype=bool) # Indicates whether an edge is folded or cut
|
||||||
glueNumber = np.empty(numUnfoldedEdges, dtype=int) # Saves with which edge is glued together
|
glueNumber = np.empty(numUnfoldedEdges, dtype=int) # Saves with which edge is glued together
|
||||||
foldingDirection = np.empty(numUnfoldedEdges, dtype=int) # Valley folding or mountain folding
|
foldingDirection = np.empty(numUnfoldedEdges, dtype=float) # Valley folding or mountain folding
|
||||||
|
|
||||||
connections = np.empty(numFaces, dtype=int) # Saves which original triangle belongs to the unrolled one
|
connections = np.empty(numFaces, dtype=int) # Saves which original triangle belongs to the unrolled one
|
||||||
|
|
||||||
@ -447,10 +440,9 @@ def writeSVG(self, unfolding, size, printNumbers):
|
|||||||
strokewidth = 0.002 * boxSize
|
strokewidth = 0.002 * boxSize
|
||||||
dashLength = 0.008 * boxSize
|
dashLength = 0.008 * boxSize
|
||||||
spaceLength = 0.02 * boxSize
|
spaceLength = 0.02 * boxSize
|
||||||
textDistance = 0.02 * boxSize
|
textDistance = boxSize * self.options.fontSize / 800
|
||||||
textStrokewidth = 0.05 * strokewidth
|
textStrokewidth = 0.05 * strokewidth
|
||||||
textLength = 0.001 * boxSize
|
fontsize = boxSize * self.options.fontSize / 1000
|
||||||
fontsize = 0.015 * boxSize
|
|
||||||
|
|
||||||
# Generate a main group
|
# Generate a main group
|
||||||
paperfoldPageGroup = self.document.getroot().add(inkex.Group(id=self.svg.get_unique_id("paperfold-page-")))
|
paperfoldPageGroup = self.document.getroot().add(inkex.Group(id=self.svg.get_unique_id("paperfold-page-")))
|
||||||
@ -467,15 +459,18 @@ def writeSVG(self, unfolding, size, printNumbers):
|
|||||||
line.set('d', "M " + str(vertex0[0]) + "," + str(vertex0[1]) + " " + str(vertex1[0]) + "," + str(vertex1[1]))
|
line.set('d', "M " + str(vertex0[0]) + "," + str(vertex0[1]) + " " + str(vertex1[0]) + "," + str(vertex1[1]))
|
||||||
# Colour depending on folding direction
|
# Colour depending on folding direction
|
||||||
lineStyle = {"fill": "none"}
|
lineStyle = {"fill": "none"}
|
||||||
if foldingDirection[edge.idx()] > 0:
|
|
||||||
|
dihedralAngle = foldingDirection[edge.idx()]
|
||||||
|
|
||||||
|
if dihedralAngle > 0:
|
||||||
lineStyle.update({"stroke": self.options.color_mountain_cut})
|
lineStyle.update({"stroke": self.options.color_mountain_cut})
|
||||||
line.set("id", self.svg.get_unique_id("mountain-cut-"))
|
line.set("id", self.svg.get_unique_id("mountain-cut-"))
|
||||||
mountainCuts += 1
|
mountainCuts += 1
|
||||||
elif foldingDirection[edge.idx()] < 0:
|
elif dihedralAngle < 0:
|
||||||
lineStyle.update({"stroke": self.options.color_valley_cut})
|
lineStyle.update({"stroke": self.options.color_valley_cut})
|
||||||
line.set("id", self.svg.get_unique_id("valley-cut-"))
|
line.set("id", self.svg.get_unique_id("valley-cut-"))
|
||||||
valleyCuts += 1
|
valleyCuts += 1
|
||||||
elif foldingDirection[edge.idx()] == 0:
|
elif dihedralAngle == 0:
|
||||||
lineStyle.update({"stroke": self.options.color_coplanar_lines})
|
lineStyle.update({"stroke": self.options.color_coplanar_lines})
|
||||||
line.set("id", self.svg.get_unique_id("coplanar-line-"))
|
line.set("id", self.svg.get_unique_id("coplanar-line-"))
|
||||||
coplanarLines += 1
|
coplanarLines += 1
|
||||||
@ -487,12 +482,13 @@ def writeSVG(self, unfolding, size, printNumbers):
|
|||||||
|
|
||||||
# Dotted lines for folding edges
|
# Dotted lines for folding edges
|
||||||
if isFoldingEdge[edge.idx()]:
|
if isFoldingEdge[edge.idx()]:
|
||||||
|
if self.options.dashes is True:
|
||||||
lineStyle.update({"stroke-dasharray":(str(dashLength) + ", " + str(spaceLength))})
|
lineStyle.update({"stroke-dasharray":(str(dashLength) + ", " + str(spaceLength))})
|
||||||
if foldingDirection[edge.idx()] > 0:
|
if dihedralAngle > 0:
|
||||||
lineStyle.update({"stroke": self.options.color_mountain_perforate})
|
lineStyle.update({"stroke": self.options.color_mountain_perforate})
|
||||||
line.set("id", self.svg.get_unique_id("mountain-perforate-"))
|
line.set("id", self.svg.get_unique_id("mountain-perforate-"))
|
||||||
mountainPerforations += 1
|
mountainPerforations += 1
|
||||||
if foldingDirection[edge.idx()] < 0:
|
if dihedralAngle < 0:
|
||||||
lineStyle.update({"stroke": self.options.color_valley_perforate})
|
lineStyle.update({"stroke": self.options.color_valley_perforate})
|
||||||
line.set("id", self.svg.get_unique_id("valley-perforate-"))
|
line.set("id", self.svg.get_unique_id("valley-perforate-"))
|
||||||
valleyPerforations += 1
|
valleyPerforations += 1
|
||||||
@ -525,14 +521,17 @@ def writeSVG(self, unfolding, size, printNumbers):
|
|||||||
text.set("x", str(position[0]))
|
text.set("x", str(position[0]))
|
||||||
text.set("y", str(position[1]))
|
text.set("y", str(position[1]))
|
||||||
text.set("font-size", str(fontsize))
|
text.set("font-size", str(fontsize))
|
||||||
text.set("style", "stroke-width:" + str(textStrokewidth))
|
text.set("style", "stroke-width:" + str(textStrokewidth) + ";text-anchor:middle;text-align:center")
|
||||||
text.set("transform", "rotate(" + str(rotation) + "," + str(position[0]) + "," + str(position[1]) + ")")
|
text.set("transform", "rotate(" + str(rotation) + "," + str(position[0]) + "," + str(position[1]) + ")")
|
||||||
|
|
||||||
tspan = text.add(Tspan())
|
tspan = text.add(Tspan())
|
||||||
tspan.set("x", str(position[0]))
|
tspan.set("x", str(position[0]))
|
||||||
tspan.set("y", str(position[1]))
|
tspan.set("y", str(position[1]))
|
||||||
tspan.set("style", "stroke-width:" + str(textStrokewidth))
|
tspan.set("style", "stroke-width:" + str(textStrokewidth) + ";text-anchor:middle;text-align:center")
|
||||||
tspan.text = str(glueNumber[edge.idx()])
|
tspan.text = str(glueNumber[edge.idx()])
|
||||||
|
if self.options.printAngles is True:
|
||||||
|
tspan.text += " ({:0.2f}°)".format(dihedralAngle)
|
||||||
|
|
||||||
gluePairs += 1
|
gluePairs += 1
|
||||||
|
|
||||||
if self.options.printStats is True:
|
if self.options.printStats is True:
|
||||||
@ -554,6 +553,8 @@ class Unfold(inkex.EffectExtension):
|
|||||||
pars.add_argument("--inputfile")
|
pars.add_argument("--inputfile")
|
||||||
pars.add_argument("--maxNumFaces", type=int, default=200, help="If the STL file has too much detail it contains a large number of faces. This will make unfolding extremely slow. So we can limit it.")
|
pars.add_argument("--maxNumFaces", type=int, default=200, help="If the STL file has too much detail it contains a large number of faces. This will make unfolding extremely slow. So we can limit it.")
|
||||||
pars.add_argument("--printNumbers", type=inkex.Boolean, default=False, help="Print numbers on the cut edges")
|
pars.add_argument("--printNumbers", type=inkex.Boolean, default=False, help="Print numbers on the cut edges")
|
||||||
|
pars.add_argument("--printAngles", type=inkex.Boolean, default=False, help="Print folding angles on the cut edges")
|
||||||
|
pars.add_argument("--fontSize", type=int, default=15, help="Label font size (%)")
|
||||||
pars.add_argument("--scalefactor", type=float, default=1.0, help="Manual scale factor")
|
pars.add_argument("--scalefactor", type=float, default=1.0, help="Manual scale factor")
|
||||||
pars.add_argument("--resizetoimport", type=inkex.Boolean, default=True, help="Resize the canvas to the imported drawing's bounding box")
|
pars.add_argument("--resizetoimport", type=inkex.Boolean, default=True, help="Resize the canvas to the imported drawing's bounding box")
|
||||||
pars.add_argument("--extraborder", type=float, default=0.0)
|
pars.add_argument("--extraborder", type=float, default=0.0)
|
||||||
@ -563,6 +564,7 @@ class Unfold(inkex.EffectExtension):
|
|||||||
pars.add_argument("--color_coplanar_lines", type=Color, default='1943148287', help="Color for coplanar lines")
|
pars.add_argument("--color_coplanar_lines", type=Color, default='1943148287', help="Color for coplanar lines")
|
||||||
pars.add_argument("--color_valley_perforate", type=Color, default='3422552319', help="Color for valley perforations")
|
pars.add_argument("--color_valley_perforate", type=Color, default='3422552319', help="Color for valley perforations")
|
||||||
pars.add_argument("--color_mountain_perforate", type=Color, default='879076607', help="Color for mountain perforations")
|
pars.add_argument("--color_mountain_perforate", type=Color, default='879076607', help="Color for mountain perforations")
|
||||||
|
pars.add_argument("--dashes", type=inkex.Boolean, default=True, help="Dashes for cut/coplanar lines")
|
||||||
pars.add_argument("--printStats", type=inkex.Boolean, default=True, help="Show some unfold statistics")
|
pars.add_argument("--printStats", type=inkex.Boolean, default=True, help="Show some unfold statistics")
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
|
Reference in New Issue
Block a user