🧵 Seams to Sewing Pattern (v 0.9, for 2.8 and 2.9)

New feature coming up:
Sewing pattern to SVG.

Here’s how it works:
Perform the Seams to Sewing Patterns operation.
Mark sewing edges that would help if they were highlighted as “Seam” (this can be done automatically, by finding corners)

Export the sewing pattern as .SVG

All those highlighted edges are now color-coded, and will help you when assembling the pieces in real life.

The resulting SVG is a bit of a mess, I’ll work on grouping each island so you can easily reassemble.

It’s still a proof-of-concept, but should make it into the plugin soon enough!

For the experimental people:
(The SVG is copied to clipboard, save manually)

Find corners and mark sewing lines as Seam.py
import bpy
import bmesh
import mathutils
import random

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_mode(type="EDGE")
bpy.ops.mesh.select_all(action='SELECT')

obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)

bpy.ops.mesh.region_to_loop()

bpy.ops.mesh.select_mode(type="VERT")

boundary_vertices = [v for v in bm.verts if v.select]

for v in boundary_vertices:
    intrest = 0
    for e in v.link_edges:
        if (len(e.link_faces) != 0):
            intrest += 1;
    if intrest == 2:
        for l in v.link_edges:
            if (len(l.link_faces) == 0):
                l.seam = True
Sewing pattern to SVG.py
import bpy
import bmesh
import mathutils
import random

svgstring = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">'
svgstring += '\n<defs><style>.seam{stroke: #000; stroke-width:0.1px;} .sewinguide{stroke-width:0.1px;}</style></defs>'
svgstring += '\n<g>'
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_mode(type="EDGE")
bpy.ops.mesh.select_all(action='SELECT')

obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)

bpy.ops.mesh.region_to_loop()

boundary_loop = [e for e in bm.edges if e.select]

uv_layer = bm.loops.layers.uv.active


for e in boundary_loop:

    svgstring += '<path class="seam" d="M '
    uv1 = e.link_loops[0][uv_layer].uv
    svgstring += str(uv1.x*100)
    svgstring += ','
    svgstring += str(uv1.y*100)
    svgstring += ' '
    
    uv2 = e.link_loops[0].link_loop_next[uv_layer].uv

    svgstring += str(uv2.x*100)
    svgstring += ','
    svgstring += str(uv2.y*100)
    svgstring += ' '
    svgstring += '"/>\n'

bpy.ops.mesh.select_mode(type="VERT")

boundary_vertices = [v for v in bm.verts if v.select]

for v in boundary_vertices:
    has_wire = False
    for w in v.link_edges:
        if w.is_wire and w.seam:
            has_wire = True
            wire = w
    if has_wire:
        #get desired direction
        wire_dir = mathutils.Vector((0,0));
        for l in v.link_edges:
            if (len(l.link_loops) > 0 and len(l.link_faces) == 1):
                this_dir = l.link_loops[0][uv_layer].uv - l.link_loops[0].link_loop_next[uv_layer].uv
                if (l.link_loops[0].vert == v):
                    wire_dir -= this_dir
                else:
                    wire_dir -= this_dir
                                
        wire_dir.normalize()
        wire_dir.y *= -1;
        wire_dir.xy = wire_dir.yx
        wire_dir *= 2;
        
        sew_color = mathutils.Color((1,0,0))
        color_hash = (hash(wire))
        color_hash /= 100000000.0
        color_hash *= 1345235.23523
        color_hash %= 1.0
        sew_color.hsv = color_hash, 1, 1
        sew_color_hex = "#%.2x%.2x%.2x" % (int(sew_color.r * 255), int(sew_color.g * 255), int(sew_color.b * 255))
        
        svgstring += '<path class="sewinguide" stroke="' + sew_color_hex + '" d="M '
        uv1 = v.link_loops[0][uv_layer].uv.copy();
        svgstring += str(uv1.x*100)
        svgstring += ','
        svgstring += str(uv1.y*100)
        svgstring += ' '
    
        svgstring += str(uv1.x*100 - wire_dir.x)
        svgstring += ','
        svgstring += str(uv1.y*100 - wire_dir.y)
        svgstring += ' '
        svgstring += '"/>\n'    
        
svgstring += '\n</g></svg>'
bpy.context.window_manager.clipboard = svgstring
7 Likes