1
0
Fork 0
freesewing/designs/florent/src/top.mjs

238 lines
7.6 KiB
JavaScript
Raw Normal View History

2022-09-05 12:24:23 -07:00
import { pluginBundle } from '@freesewing/plugin-bundle'
2022-09-11 14:28:25 +02:00
function draftFlorentTop({
paperless,
sa,
points,
macro,
Point,
Path,
paths,
snippets,
Snippet,
complete,
store,
part,
}) {
2019-04-07 17:01:58 +02:00
const fitCap = (part, scale) => {
2019-08-03 15:03:33 +02:00
let { points, options, Point, Path, measurements } = part.shorthand()
2019-04-07 17:01:58 +02:00
let base = scale * measurements.head * (1 + options.headEase)
2019-04-07 17:01:58 +02:00
// Top
2019-08-03 15:03:33 +02:00
points.midFront = new Point(0, 0)
points.midFrontCp2 = points.midFront.shift(-90, base * 0.074)
points.midMid = points.midFront.shift(0, base * 0.34)
points.midBack = new Point(base * 0.654, base * 0.124)
points.midSide = new Point(base * 0.2525, base * 0.178)
points.midSideCp1 = points.midSide.shift(180, base * 0.185)
points.midSideCp2 = points.midSide.shift(0, base * 0.101)
points.backHollow = new Point(base * 0.488, base * 0.136)
points.backHollowCp1 = points.backHollow.shift(180, base * 0.033)
points.backHollowCp2 = points.backHollow.shift(0, base * 0.033)
points.backEdge = new Point(base * 0.576, base * 0.185)
let angle = points.backEdge.angle(points.midBack) + 90
points.backSide = points.backEdge.shift(angle, base * 0.025)
points.backSideCp1 = points.backSide.shift(angle, base * 0.02)
points.midMidCp1 = points.midMid.shift(0, base * 0.1)
points.midBackCp2 = points.midBack.shift(angle, base * 0.09)
2019-04-07 17:01:58 +02:00
// Side
2019-08-03 15:03:33 +02:00
points.foldTop = new Point(0, 0)
points.foldTopCp1 = points.foldTop.shift(-90, base * 0.0433)
points.foldBottom = points.foldTop.shift(0, base * 0.126)
points.foldBottomCp2 = points.foldBottom.shift(-90, base * 0.0866)
points.tip = new Point(base * 0.411, base * 0.207)
points.tipCp1 = points.tip.shift(-85, base * 0.1)
points.tipCp2 = points.tip.shift(177, base * 0.067)
points.outerTop = new Point(base * 0.328, base * 0.337)
points.outerTopCp1 = points.outerTop.shift(180, base * 0.05)
points.outerTopCp2 = points.outerTop.shift(0, base * 0.05)
points.outerGuide = new Point(base * 0.0867, base * 0.1913)
points.outerGuideCp1 = points.outerGuide.shift(135, base * 0.076)
points.outerGuideCp2 = points.outerGuide.shift(-45, base * 0.145)
points.innerGuide = new Point(base * 0.22, base * 0.172)
points.innerGuideCp1 = points.innerGuide.shift(-38, base * 0.052)
points.innerGuideCp2 = points.innerGuide.shift(142, base * 0.035)
let backLength = points.backEdge.dist(points.midBack) * 2
2019-04-07 17:01:58 +02:00
let sideLength =
new Path()
.move(points.tip)
.curve(points.tipCp2, points.innerGuideCp1, points.innerGuide)
.curve(points.innerGuideCp2, points.foldBottomCp2, points.foldBottom)
2019-08-03 15:03:33 +02:00
.length() * 2
2019-04-07 17:01:58 +02:00
// Return delta between target and actual seam length
return measurements.head * (1 + options.headEase) - (backLength + sideLength)
2019-08-03 15:03:33 +02:00
}
2019-04-07 17:01:58 +02:00
const sideSeamDelta = (part) => {
2019-08-03 15:03:33 +02:00
let { Path } = part.shorthand()
2019-04-07 17:01:58 +02:00
let top = new Path()
.move(points.midFront)
.curve(points.midFrontCp2, points.midSideCp1, points.midSide)
.curve(points.midSideCp2, points.backHollowCp1, points.backHollow)
.curve(points.backHollowCp2, points.backSideCp1, points.backSide)
.line(points.backEdge)
2019-08-03 15:03:33 +02:00
.length()
2019-04-07 17:01:58 +02:00
let side = new Path()
.move(points.foldTop)
.curve(points.foldTopCp1, points.outerGuideCp1, points.outerGuide)
.curve(points.outerGuideCp2, points.outerTopCp1, points.outerTop)
.curve(points.outerTopCp2, points.tipCp1, points.tip)
2019-08-03 15:03:33 +02:00
.length()
2019-04-07 17:01:58 +02:00
2019-08-03 15:03:33 +02:00
return top - side
}
2019-04-07 17:01:58 +02:00
// Fit head
2019-08-03 15:03:33 +02:00
let scale = 1
let count = 1
let delta = fitCap(part, scale)
2019-04-07 17:01:58 +02:00
while (Math.abs(delta) > 1 && count < 25) {
2019-08-03 15:03:33 +02:00
count++
if (delta > 0) scale = 1000 / (1000 - delta)
2019-04-07 17:01:58 +02:00
// Too small
2019-08-03 15:03:33 +02:00
else scale = 1000 / (1000 + delta) // Too large
delta = fitCap(part, scale)
2019-04-07 17:01:58 +02:00
}
// Match side seam
2019-08-03 15:03:33 +02:00
delta = sideSeamDelta(part)
count = 1
let top = ['outerTop', 'outerTopCp1', 'outerTopCp2']
let guide = ['outerGuide', 'outerGuideCp1', 'outerGuideCp2']
2019-04-07 17:01:58 +02:00
while (Math.abs(delta) > 1 && count < 25) {
2019-08-03 15:03:33 +02:00
for (let i of top) points[i] = points[i].shift(-90, delta / 3)
for (let i of guide) points[i] = points[i].shift(-135, delta / 3)
delta = sideSeamDelta(part)
count++
2019-04-07 17:01:58 +02:00
}
// Paths
paths.seam = new Path()
.move(points.midMid)
.line(points.midFront)
.curve(points.midFrontCp2, points.midSideCp1, points.midSide)
.curve(points.midSideCp2, points.backHollowCp1, points.backHollow)
.curve(points.backHollowCp2, points.backSideCp1, points.backSide)
.line(points.backEdge)
.line(points.midBack)
.curve(points.midBackCp2, points.midMidCp1, points.midMid)
.close()
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric')
2019-04-07 17:01:58 +02:00
paths.side = new Path()
.move(points.foldTop)
.curve(points.foldTopCp1, points.outerGuideCp1, points.outerGuide)
.curve(points.outerGuideCp2, points.outerTopCp1, points.outerTop)
.curve(points.outerTopCp2, points.tipCp1, points.tip)
.curve(points.tipCp2, points.innerGuideCp1, points.innerGuide)
.curve(points.innerGuideCp2, points.foldBottomCp2, points.foldBottom)
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric')
2019-04-07 17:01:58 +02:00
// Uncomment to see the side part here
2019-08-03 15:03:33 +02:00
paths.side.render = false
2019-04-07 17:01:58 +02:00
if (complete) {
2019-08-03 15:03:33 +02:00
points.title = new Point(points.midMid.x, points.midFrontCp2.y)
macro('title', {
2019-04-08 07:46:06 +02:00
at: points.title,
nr: 1,
2021-04-24 10:16:31 +02:00
title: 'top',
2019-08-03 15:03:33 +02:00
})
points.logo = new Point(points.title.x / 2, points.title.y)
snippets.logo = new Snippet('logo', points.logo).attr('data-scale', 0.75)
points.grainlineFrom = new Point(points.midSideCp1.x, points.midBack.y)
points.grainlineTo = points.midBack.clone()
macro('grainline', {
2019-04-08 07:46:06 +02:00
from: points.grainlineFrom,
2021-04-24 10:16:31 +02:00
to: points.grainlineTo,
2019-08-03 15:03:33 +02:00
})
macro('miniscale', { at: new Point(points.title.x * 0.75, points.title.y) })
macro('sprinkle', {
snippet: 'notch',
2021-08-30 11:40:16 +02:00
on: ['midMid', 'backHollow', 'midSide'],
})
2021-08-30 11:40:16 +02:00
store.set(
'topDistanceToFirstNotch',
new Path()
.move(points.backEdge)
.line(points.backSide)
.curve(points.backSideCp1, points.backHollowCp2, points.backHollow)
.length()
)
2021-08-30 11:40:16 +02:00
store.set(
'topDistanceToSecondNotch',
new Path()
.move(points.backHollow)
.curve(points.backHollowCp1, points.midSideCp2, points.midSide)
.length() + store.get('topDistanceToFirstNotch')
)
2019-08-03 15:03:33 +02:00
if (sa) paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa')
2019-04-07 17:01:58 +02:00
if (paperless) {
2019-08-03 15:03:33 +02:00
macro('vd', {
2019-04-08 07:46:06 +02:00
from: points.midSide,
to: points.foldTop,
2021-04-24 10:16:31 +02:00
x: points.foldTop.x - sa - 15,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-04-08 07:46:06 +02:00
from: points.backHollow,
to: points.midMid,
2021-04-24 10:16:31 +02:00
x: points.midMid.x - 15,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-04-08 07:46:06 +02:00
from: points.midBack,
to: points.midMid,
2021-04-24 10:16:31 +02:00
x: points.midBack.x + sa + 15,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-04-08 07:46:06 +02:00
from: points.backEdge,
to: points.midMid,
2021-04-24 10:16:31 +02:00
x: points.midBack.x + sa + 30,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2019-04-08 07:46:06 +02:00
from: points.foldTop,
to: points.midSide,
2021-04-24 10:16:31 +02:00
y: points.midSide.y + sa + 15,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2019-04-08 07:46:06 +02:00
from: points.foldTop,
to: points.backHollow,
2021-04-24 10:16:31 +02:00
y: points.midSide.y + sa + 30,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2019-04-08 07:46:06 +02:00
from: points.foldTop,
to: points.backEdge,
2021-04-24 10:16:31 +02:00
y: points.midSide.y + sa + 45,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2019-04-08 07:46:06 +02:00
from: points.foldTop,
to: points.midBack,
2021-04-24 10:16:31 +02:00
y: points.midSide.y + sa + 60,
2019-08-03 15:03:33 +02:00
})
2019-04-07 17:01:58 +02:00
}
}
2019-08-03 15:03:33 +02:00
return part
2019-04-07 17:01:58 +02:00
}
2022-09-05 12:24:23 -07:00
export const top = {
name: 'florent.top',
2022-09-11 14:28:25 +02:00
measurements: ['head'],
options: {
2022-09-05 12:24:23 -07:00
// Constants
topSide: 0.8,
brim: 0,
// Percentages
headEase: { pct: 2, min: 0, max: 5, menu: 'fit' },
},
2022-09-11 14:28:25 +02:00
plugins: [pluginBundle],
2022-09-05 12:24:23 -07:00
draft: draftFlorentTop,
}