From 1d6d43a7e254c4e4c70a375fcabf30cb4e0ce62b Mon Sep 17 00:00:00 2001 From: woutervdub Date: Wed, 8 Jun 2022 07:50:05 -0700 Subject: [PATCH] Now with Teeth! --- packages/hi/config/index.js | 3 +- packages/hi/src/belly.js | 23 ++++++----- packages/hi/src/body.js | 7 +++- packages/hi/src/index.js | 4 ++ packages/hi/src/lowerTeeth.js | 62 ++++++++++++++++++++++++++++ packages/hi/src/mouth.js | 25 ++++++++++-- packages/hi/src/tail.js | 5 +++ packages/hi/src/teeth.js | 37 +++++++++++++++++ packages/hi/src/upperTeeth.js | 77 +++++++++++++++++++++++++++++++++++ 9 files changed, 227 insertions(+), 16 deletions(-) create mode 100644 packages/hi/src/lowerTeeth.js create mode 100644 packages/hi/src/teeth.js create mode 100644 packages/hi/src/upperTeeth.js diff --git a/packages/hi/config/index.js b/packages/hi/config/index.js index 0a4d8ac4e3b..54805c9a07a 100644 --- a/packages/hi/config/index.js +++ b/packages/hi/config/index.js @@ -12,13 +12,14 @@ export default { style: ['size','nosePointiness','aggressive'], }, measurements: ['neck'], - parts: ['body','tail','aboveMouth','belly','topFin','bottomFin','mouth'], + parts: ['body','tail','aboveMouth','belly','topFin','bottomFin','mouth','lowerTeeth','upperTeeth'], dependencies: { tail: 'body', aboveMouth: ['body','mouth'], topFin: 'body', belly: ['body','aboveMouth'], bottomFin: ['body','belly','aboveMouth'], + mouth: ['lowerTeeth', 'upperTeeth'], }, inject: {}, hide: [], diff --git a/packages/hi/src/belly.js b/packages/hi/src/belly.js index 5c0f23f65cb..bd06f5ca257 100644 --- a/packages/hi/src/belly.js +++ b/packages/hi/src/belly.js @@ -120,11 +120,11 @@ export default function (part) { diff = 0 iteration = 0 do { - points.belly04.x -= diff - points.belly04cp1.x -= diff - points.belly04cp2.x -= diff - points.belly05.x -= diff - points.belly05cp2.x -= diff + points.belly04.x += diff + points.belly04cp1.x += diff + points.belly04cp2.x += diff + points.belly05.x += diff + points.belly05cp2.x += diff iteration++ diff = @@ -133,14 +133,15 @@ export default function (part) { .move(points.belly03) .curve(points.belly03cp1, points.belly04cp2, points.belly04) .length() + + console.log({ + actual: new Path() + .move(points.belly03) + .curve(points.belly03cp1, points.belly04cp2, points.belly04) + .length(), + }) } while ((diff < -1 || diff > 1) && iteration < 100) - console.log({ - actual: new Path() - .move(points.belly03) - .curve(points.belly03cp1, points.belly04cp2, points.belly04) - .length(), - }) points.belly05cp1 = points.belly05cp2.flipY() points.belly06 = points.belly04.flipY() diff --git a/packages/hi/src/body.js b/packages/hi/src/body.js index 32f01e8d83a..113a5dd9e04 100644 --- a/packages/hi/src/body.js +++ b/packages/hi/src/body.js @@ -171,7 +171,7 @@ let body19_01a = 59.63482522 let body01cp1a = 161.5263465 let body01cp2a = 255.6503959 let body02cp1a = 31.95354992 -//let body02cp2a = 359.48842 +// let body02cp2a = 359.48842 // let body02cp2a = 2.48842 let body02cp2a = 10 @@ -444,6 +444,11 @@ let gillAngle = 103.9416747 // Complete? if (complete) { + points.bodyTailSnippet = new Path() + .move(points.body13) + .curve(points.body13cp1, points.body14cp2, points.body14) + .shiftFractionAlong(0.25) + snippets.bodyTail = new Snippet('bnotch', points.bodyTailSnippet) if( sa ) { paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') } diff --git a/packages/hi/src/index.js b/packages/hi/src/index.js index e52e69247f1..176322d9374 100644 --- a/packages/hi/src/index.js +++ b/packages/hi/src/index.js @@ -8,6 +8,8 @@ import draftAboveMouth from './aboveMouth' import draftBelly from './belly' import draftTopFin from './topFin' import draftBottomFin from './bottomFin' +import draftLowerTeeth from './lowerTeeth' +import draftUpperTeeth from './upperTeeth' // Create design const Pattern = new freesewing.Design(config, plugins) @@ -19,5 +21,7 @@ Pattern.prototype.draftAboveMouth = draftAboveMouth Pattern.prototype.draftBelly = draftBelly Pattern.prototype.draftTopFin = draftTopFin Pattern.prototype.draftBottomFin = draftBottomFin +Pattern.prototype.draftLowerTeeth = draftLowerTeeth +Pattern.prototype.draftUpperTeeth = draftUpperTeeth export default Pattern diff --git a/packages/hi/src/lowerTeeth.js b/packages/hi/src/lowerTeeth.js new file mode 100644 index 00000000000..620e8f7f532 --- /dev/null +++ b/packages/hi/src/lowerTeeth.js @@ -0,0 +1,62 @@ +import { createTeeth } from './teeth.js' + +export default function (part) { + let { + store, + sa, + Point, + points, + Path, + paths, + Snippet, + snippets, + options, + measurements, + complete, + paperless, + macro, + } = part.shorthand() + + let lowerTeeth01_02d = 75.74338717643937 * options.size + let lowerTeeth01_02a = 25.414236606099728 + 180 + let lowerTeeth02cp1d = 47.74891452755759 * options.size + let lowerTeeth02cp1a = 42.59332849750379 + let lowerTeeth01cp2d = 17.774046078481962 * options.size + let lowerTeeth01cp2a = 180 + + points.lowerTeeth01 = new Point(0, 0) + points.lowerTeeth02 = points.lowerTeeth01.shift(lowerTeeth01_02a, lowerTeeth01_02d) + points.lowerTeeth01cp2 = points.lowerTeeth01.shift(lowerTeeth01cp2a, lowerTeeth01cp2d) + points.lowerTeeth02cp1 = points.lowerTeeth02.shift(lowerTeeth02cp1a, lowerTeeth02cp1d) + points.lowerTeeth03 = points.lowerTeeth02.flipX() + points.lowerTeeth01cp1 = points.lowerTeeth01cp2.flipX() + points.lowerTeeth03cp2 = points.lowerTeeth02cp1.flipX() + + paths.seam = new Path() + .move(points.lowerTeeth02) + .curve(points.lowerTeeth02cp1, points.lowerTeeth01cp2, points.lowerTeeth01) + .curve(points.lowerTeeth01cp1, points.lowerTeeth03cp2, points.lowerTeeth03) + + store.set('lowerTeethLength', paths.seam.length()) + + paths.teeth = new Path().move(paths.seam.start()) + + createTeeth(paths.seam, 16 * options.size, 8 * options.size, 10, options.aggressive, paths.teeth) + + // Complete? + if (complete) { + snippets.lowerTeeth = new Snippet('bnotch', points.lowerTeeth01) + + if (sa) { + let pSA = paths.seam.offset(sa) + paths.sa = new Path() + .move(paths.seam.start()) + .line(pSA.start()) + .join(pSA) + .line(paths.seam.end()) + .attr('class', 'fabric sa') + } + } + + return part +} diff --git a/packages/hi/src/mouth.js b/packages/hi/src/mouth.js index 6699a243e1b..66e4388bc71 100644 --- a/packages/hi/src/mouth.js +++ b/packages/hi/src/mouth.js @@ -80,11 +80,30 @@ export default function (part) { .length() ) - snippets.mouthMidTop = new Snippet('bnotch', points.mouth01) - snippets.mouthMidBottom = new Snippet('bnotch', points.mouth03) - // Complete? if (complete) { + points.mouthUpperTeeth1 = new Path() + .move(points.mouth01) + .curve(points.mouth01cp1, points.mouth02cp2, points.mouth02) + .shiftAlong(store.get('upperTeethLength') / 2) + points.mouthUpperTeeth2 = new Path() + .move(points.mouth01) + .curve(points.mouth01cp2, points.mouth04cp1, points.mouth04) + .shiftAlong(store.get('upperTeethLength') / 2) + snippets.mouthUpperTeeth1 = new Snippet('bnotch', points.mouthUpperTeeth1) + snippets.mouthUpperTeeth2 = new Snippet('bnotch', points.mouthUpperTeeth2) + points.mouthlowerTeeth1 = new Path() + .move(points.mouth03) + .curve(points.mouth03cp1, points.mouth04cp2, points.mouth04) + .shiftAlong(store.get('lowerTeethLength') / 2) + points.mouthlowerTeeth2 = new Path() + .move(points.mouth03) + .curve(points.mouth03cp2, points.mouth02cp1, points.mouth02) + .shiftAlong(store.get('lowerTeethLength') / 2) + snippets.mouthlowerTeeth1 = new Snippet('bnotch', points.mouthlowerTeeth1) + snippets.mouthlowerTeeth2 = new Snippet('bnotch', points.mouthlowerTeeth2) + snippets.mouthMidTop = new Snippet('bnotch', points.mouth01) + snippets.mouthMidBottom = new Snippet('bnotch', points.mouth03) if (sa) { paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') } diff --git a/packages/hi/src/tail.js b/packages/hi/src/tail.js index 37af71f3e15..daefabd1ec4 100644 --- a/packages/hi/src/tail.js +++ b/packages/hi/src/tail.js @@ -84,6 +84,11 @@ export default function (part) { // Complete? if (complete) { + points.tailSnippet = new Path() + .move(points.tail01) + .curve(points.tail01cp2, points.tail05cp1, points.tail05) + .shiftFractionAlong(0.25) + snippets.tail = new Snippet('bnotch', points.tailSnippet) if (sa) { paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') } diff --git a/packages/hi/src/teeth.js b/packages/hi/src/teeth.js new file mode 100644 index 00000000000..af50f6553f8 --- /dev/null +++ b/packages/hi/src/teeth.js @@ -0,0 +1,37 @@ +export function createTeeth(path, largeTeeth, smallTeeth, numberOfTeeth, aggressive, newPath) { + let c = 0.55191502449351 + + let pLength = path.length() + let stepLength = pLength / numberOfTeeth + + let teethStep = (largeTeeth - smallTeeth) / (numberOfTeeth / 2 - 1) + let teethDirection = 1 + + let teethSize = smallTeeth + for (var i = 0; i < numberOfTeeth; i++) { + if (i == numberOfTeeth / 2) teethDirection = 0 + if (i > numberOfTeeth / 2) teethDirection = -1 + + teethSize += teethStep * teethDirection + let startP = path.shiftAlong(stepLength * i) + let midP = path.shiftAlong(stepLength * (i + 0.5)) + let endP = path.shiftAlong(stepLength * (i + 1)) + let midPangle = midP.angle(path.shiftAlong(stepLength * (i + 0.5) + 0.1)) + 90 + midP = midP.shift(midPangle, teethSize) + let startPcp = startP.shift( + startP.angle(path.shiftAlong(stepLength * i + 0.1)) + 90, + teethSize * c + ) + let endPcp = endP.shift( + endP.angle(path.shiftAlong(stepLength * (i + 1) - 0.1)) - 90, + teethSize * c + ) + let midPcp1 = midP.shift(midPangle - 90, stepLength * c * (aggressive ? 0.05 : 0.7)) + let midPcp2 = midP.shift(midPangle + 90, stepLength * c * (aggressive ? 0.05 : 0.7)) + + newPath.curve(startPcp, midPcp2, midP) + newPath.curve(midPcp1, endPcp, endP) + } + + return +} diff --git a/packages/hi/src/upperTeeth.js b/packages/hi/src/upperTeeth.js new file mode 100644 index 00000000000..6042cfd3573 --- /dev/null +++ b/packages/hi/src/upperTeeth.js @@ -0,0 +1,77 @@ +import { createTeeth } from './teeth.js' + +export default function (part) { + let { + store, + sa, + Point, + points, + Path, + paths, + Snippet, + snippets, + options, + measurements, + complete, + paperless, + macro, + } = part.shorthand() + + points.upperTeeth01 = new Point(149.3, 278.667) + points.upperTeeth01cp1 = new Point(197.492, 209.499) + points.upperTeeth02cp2 = new Point(239.637, 204.963) + points.upperTeeth02 = new Point(257.968, 204.963) + points.upperTeeth02cp1 = new Point(275.166, 204.773) + points.upperTeeth03cp2 = new Point(323.357, 210.254) + points.upperTeeth03 = new Point(366.26, 279.236) + + console.log({ upperTeeth01_02d: points.upperTeeth01.dist(points.upperTeeth02) }) + console.log({ upperTeeth01_02a: points.upperTeeth01.angle(points.upperTeeth02) }) + + console.log({ upperTeeth01cp1d: points.upperTeeth01.dist(points.upperTeeth01cp1) }) + console.log({ upperTeeth01cp1a: points.upperTeeth01.angle(points.upperTeeth01cp1) }) + console.log({ upperTeeth02cp2d: points.upperTeeth02.dist(points.upperTeeth02cp2) }) + console.log({ upperTeeth02cp2a: points.upperTeeth02.angle(points.upperTeeth02cp2) }) + + let upperTeeth01_02d = 131.305041182736 * options.size + let upperTeeth01_02a = 34.147056946748805 + 180 + let upperTeeth02cp1d = 84.30113337316406 * options.size + let upperTeeth02cp1a = 55.1335930733262 + let upperTeeth01cp2d = 18.331000000000017 * options.size + let upperTeeth01cp2a = 180 + + points.upperTeeth01 = new Point(0, 0) + points.upperTeeth02 = points.upperTeeth01.shift(upperTeeth01_02a, upperTeeth01_02d) + points.upperTeeth01cp2 = points.upperTeeth01.shift(upperTeeth01cp2a, upperTeeth01cp2d) + points.upperTeeth02cp1 = points.upperTeeth02.shift(upperTeeth02cp1a, upperTeeth02cp1d) + points.upperTeeth03 = points.upperTeeth02.flipX() + points.upperTeeth01cp1 = points.upperTeeth01cp2.flipX() + points.upperTeeth03cp2 = points.upperTeeth02cp1.flipX() + + paths.seam = new Path() + .move(points.upperTeeth02) + .curve(points.upperTeeth02cp1, points.upperTeeth01cp2, points.upperTeeth01) + .curve(points.upperTeeth01cp1, points.upperTeeth03cp2, points.upperTeeth03) + + store.set('upperTeethLength', paths.seam.length()) + + paths.teeth = new Path().move(paths.seam.start()) + + createTeeth(paths.seam, 18 * options.size, 9 * options.size, 15, options.aggressive, paths.teeth) + + // Complete? + if (complete) { + snippets.upperTeeth = new Snippet('bnotch', points.upperTeeth01) + if (sa) { + let pSA = paths.seam.offset(sa) + paths.sa = new Path() + .move(paths.seam.start()) + .line(pSA.start()) + .join(pSA) + .line(paths.seam.end()) + .attr('class', 'fabric sa') + } + } + + return part +}