Last active
December 16, 2023 11:52
-
-
Save fishfitz/b47edde12764dbad5ef29734675c3fce to your computer and use it in GitHub Desktop.
Dirty Womp Scripting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A sample data (write "Hello Womp!! :D") | |
const data = [[{"x":61.866678,"y":106.4429},{"x":61.866678,"y":122.47344}],[{"x":66.75519,"y":106.56164},{"x":66.75519,"y":122.47344}],[{"x":111.10732,"y":106.86959999999999},{"x":111.10732,"y":106.86959999999999},{"x":113.35692750000001,"y":107.30554624999999},{"x":115.22279,"y":108.97212999999999},{"x":115.22279,"y":108.97212999999999},{"x":115.812575,"y":110.12097499999999},{"x":116.21987,"y":111.43016999999999},{"x":116.21987,"y":111.43016999999999},{"x":116.56521874999999,"y":113.78767749999999},{"x":116.53946,"y":116.17996999999998},{"x":116.53946,"y":116.17996999999998},{"x":116.377915,"y":117.56488875},{"x":116.06574,"y":118.91109999999998},{"x":116.06574,"y":118.91109999999998},{"x":114.43705875,"y":121.74128124999997},{"x":111.90726000000001,"y":122.92314999999998},{"x":111.90726000000001,"y":122.92314999999998},{"x":109.73021875,"y":122.62010249999997},{"x":107.90090000000001,"y":121.12189999999998},{"x":107.90090000000001,"y":121.12189999999998},{"x":107.24220125,"y":119.98847124999999},{"x":106.77050000000001,"y":118.67360999999998},{"x":106.77050000000001,"y":118.67360999999998},{"x":106.41814125000002,"y":116.78550374999999},{"x":106.31194,"y":114.87377999999998},{"x":106.31194,"y":114.87377999999998},{"x":106.42418625000002,"y":112.90074124999998},{"x":106.81754000000001,"y":110.95518999999999},{"x":106.81754000000001,"y":110.95518999999999},{"x":108.49211625000001,"y":108.0507125},{"x":111.10732000000002,"y":106.86959999999999}],[{"x":102.48576000000001,"y":107.03661},{"x":102.48576000000001,"y":107.03661},{"x":102.14387375000001,"y":108.92739875},{"x":101.76352000000001,"y":110.95519},{"x":101.76352000000001,"y":110.95519},{"x":100.96410750000001,"y":115.22888875000001},{"x":100.16363000000001,"y":119.5048},{"x":100.16363000000001,"y":119.5048},{"x":99.97983275000001,"y":120.46801750000002},{"x":99.74755100000002,"y":121.23418000000001},{"x":99.74755100000002,"y":121.23418000000001},{"x":99.46790575000001,"y":121.64384625000001},{"x":98.96658300000001,"y":121.74431000000001},{"x":98.96658300000001,"y":121.74431000000001},{"x":98.52251937500003,"y":121.24161750000002},{"x":98.28099700000001,"y":120.33439000000001},{"x":98.28099700000001,"y":120.33439000000001},{"x":97.87998150000001,"y":118.2745575},{"x":97.49726300000002,"y":116.17997000000001},{"x":97.49726300000002,"y":116.17997000000001},{"x":97.05303262500001,"y":113.80600000000001},{"x":96.60844600000001,"y":111.43017000000002},{"x":96.60844600000001,"y":111.43017000000002},{"x":96.40468375,"y":110.32084500000002},{"x":96.18141100000001,"y":109.30047000000002},{"x":96.18141100000001,"y":109.30047000000002},{"x":95.80972325000002,"y":108.36094375000003},{"x":95.46408300000002,"y":107.86784000000002},{"x":95.46408300000002,"y":107.86784000000002},{"x":95.09547875000001,"y":108.38037500000002},{"x":94.69686700000001,"y":109.41665000000002},{"x":94.69686700000001,"y":109.41665000000002},{"x":94.43323050000002,"y":110.66894000000003},{"x":94.186985,"y":112.02389000000002},{"x":94.186985,"y":112.02389000000002},{"x":93.65490712500001,"y":114.93359125000002},{"x":93.11981800000001,"y":117.84240000000003},{"x":93.11981800000001,"y":117.84240000000003},{"x":92.88646175000001,"y":119.12081125000003},{"x":92.63700600000001,"y":120.33254000000002},{"x":92.63700600000001,"y":120.33254000000002},{"x":92.238134125,"y":121.45717750000001},{"x":91.81992200000002,"y":122.23596000000002}],[{"x":88.44240400000002,"y":107.15536000000002},{"x":88.44240400000002,"y":107.15536000000002},{"x":89.35532625000002,"y":111.71505750000001},{"x":90.20229500000002,"y":116.29871000000001},{"x":90.20229500000002,"y":116.29871000000001},{"x":90.59814287500001,"y":118.42099500000002},{"x":91.01694000000002,"y":120.45097000000001},{"x":91.01694000000002,"y":120.45097000000001},{"x":91.37413012500002,"y":121.43668375000001},{"x":91.73104200000002,"y":121.99846000000001}],[{"x":136.34982000000002,"y":116.06122},{"x":136.34982000000002,"y":116.06122},{"x":136.34980875000002,"y":113.14707625},{"x":136.34982000000002,"y":110.12398},{"x":136.34982000000002,"y":110.12398},{"x":136.33575625000003,"y":108.78513750000002},{"x":136.55444000000003,"y":107.56367},{"x":136.55444000000003,"y":107.56367},{"x":137.41379500000002,"y":107.09231875},{"x":138.48300000000003,"y":107.15808},{"x":138.48300000000003,"y":107.15808},{"x":139.56047375000003,"y":107.20875249999999},{"x":140.61616000000004,"y":107.39936},{"x":140.61616000000004,"y":107.39936},{"x":142.36560250000002,"y":108.74779},{"x":143.07724000000005,"y":111.31143},{"x":143.07724000000005,"y":111.31143},{"x":143.02295125000006,"y":112.27802125},{"x":142.82803000000004,"y":113.2112},{"x":142.82803000000004,"y":113.2112},{"x":141.74664875000005,"y":115.08370875},{"x":140.08287000000004,"y":115.98901000000001},{"x":140.08287000000004,"y":115.98901000000001},{"x":138.97142500000004,"y":116.14707250000002},{"x":137.86100000000005,"y":116.18041000000001},{"x":137.86100000000005,"y":116.18041000000001},{"x":137.18454125000005,"y":116.15022250000001},{"x":136.60193000000004,"y":116.45335000000001},{"x":136.60193000000004,"y":116.45335000000001},{"x":136.37801000000005,"y":117.21052750000001},{"x":136.35047000000003,"y":118.08037000000002},{"x":136.35047000000003,"y":118.08037000000002},{"x":136.347955,"y":120.27333875000001},{"x":136.34994000000003,"y":122.47344000000001}],[{"x":176.20808000000002,"y":107.42874},{"x":176.20808000000002,"y":107.42874},{"x":176.96170250000003,"y":107.11632375},{"x":177.85787000000002,"y":107.15607},{"x":177.85787000000002,"y":107.15607},{"x":180.34522500000003,"y":107.33638624999999},{"x":182.65732000000003,"y":108.3901},{"x":182.65732000000003,"y":108.3901},{"x":184.05834250000004,"y":110.04809125000001},{"x":184.90549000000001,"y":112.26139},{"x":184.90549000000001,"y":112.26139},{"x":185.10662000000002,"y":113.50294625000001},{"x":185.17308000000003,"y":114.75504000000001},{"x":185.17308000000003,"y":114.75504000000001},{"x":185.10426375000003,"y":116.1865525},{"x":184.86765000000003,"y":117.60491},{"x":184.86765000000003,"y":117.60491},{"x":184.15489500000004,"y":119.58095250000001},{"x":183.00573000000003,"y":121.15783},{"x":183.00573000000003,"y":121.15783},{"x":180.45085500000002,"y":122.44071375},{"x":177.68013000000002,"y":122.59205},{"x":177.68013000000002,"y":122.59205},{"x":176.73511625000003,"y":122.59105},{"x":176.03032000000002,"y":122.01837},{"x":176.03032000000002,"y":122.01837},{"x":175.88556375000002,"y":120.96554874999998},{"x":175.90247000000002,"y":119.86106000000001},{"x":175.90247000000002,"y":119.86106000000001},{"x":175.90238625,"y":117.01120374999999},{"x":175.90246000000002,"y":114.16131000000001},{"x":175.90246000000002,"y":114.16131000000001},{"x":175.90027625000002,"y":111.66617875000003},{"x":175.90299000000002,"y":109.17428000000001},{"x":175.90299000000002,"y":109.17428000000001},{"x":175.92734875000002,"y":108.23113750000002},{"x":176.20796,"y":107.42874}],[{"x":37.779661000000004,"y":107.39284},{"x":37.779738,"y":112.02389000000001},{"x":37.785738,"y":114.04255},{"x":37.779638,"y":116.17996000000001},{"x":37.779595,"y":122.35469}],[{"x":46.045624000000004,"y":107.39284},{"x":46.045581000000006,"y":111.90515},{"x":46.039481,"y":114.04255},{"x":46.045581000000006,"y":116.29870000000001},{"x":46.045604000000004,"y":122.35469}],[{"x":95.463992,"y":107.39284},{"x":95.463992,"y":107.86782000000001}],[{"x":121.15090000000001,"y":122.47343000000001},{"x":121.15090000000001,"y":122.47343000000001},{"x":121.15090000000001,"y":116.59553},{"x":121.15090000000001,"y":110.71769},{"x":121.15090000000001,"y":110.71769},{"x":121.14902500000001,"y":109.80110750000001},{"x":121.15390000000001,"y":108.9392},{"x":121.15390000000001,"y":108.9392},{"x":121.17107375,"y":108.26133750000001},{"x":121.40229000000001,"y":107.68906},{"x":121.40229000000001,"y":107.68906},{"x":122.04867375,"y":107.6910475},{"x":122.51223,"y":108.18718},{"x":122.51223,"y":108.18718},{"x":122.95447499999999,"y":109.14244124999999},{"x":123.33732,"y":110.24273},{"x":123.33732,"y":110.24273},{"x":124.169545,"y":112.62173999999999},{"x":125.00942,"y":114.99186999999999},{"x":125.00942,"y":114.99186999999999},{"x":125.43193375000001,"y":115.98685125},{"x":126.05073,"y":116.56952},{"x":126.05073,"y":116.56952},{"x":126.74884750000001,"y":116.1047375},{"x":127.19234,"y":114.99149},{"x":127.19234,"y":114.99149},{"x":128.2578125,"y":111.92518125000001},{"x":129.3452,"y":108.94714},{"x":129.3452,"y":108.94714},{"x":129.8209025,"y":108.02965375},{"x":130.46078,"y":107.67067},{"x":130.46078,"y":107.67067},{"x":130.888805,"y":107.87974},{"x":131.06606,"y":108.38041},{"x":131.06606,"y":108.38041},{"x":131.11705999999998,"y":109.37412},{"x":131.10536,"y":110.48021},{"x":131.10536,"y":110.48021},{"x":131.10537125,"y":116.41702500000001},{"x":131.10536,"y":122.35468}],[{"x":155.19239,"y":107.39284},{"x":155.27489,"y":110.71769},{"x":155.24039,"y":113.44883},{"x":155.19239,"y":117.72364}],[{"x":148.17065,"y":107.51159},{"x":148.17065,"y":110.00524},{"x":148.17065,"y":112.97384},{"x":148.17065,"y":114.87375999999999},{"x":148.17065,"y":117.72363999999999}],[{"x":50.489923,"y":116.4174},{"x":50.489923,"y":116.4174},{"x":50.78392899999999,"y":114.3397575},{"x":51.838356999999995,"y":112.26228},{"x":51.838356999999995,"y":112.26228},{"x":55.15597462499999,"y":111.23535625000001},{"x":57.48791299999999,"y":114.27995},{"x":57.48791299999999,"y":114.27995},{"x":57.573070249999994,"y":115.08907125},{"x":57.48860299999999,"y":115.86955},{"x":57.48860299999999,"y":115.86955},{"x":57.026824375,"y":116.42636375000002},{"x":56.355383999999994,"y":116.52903},{"x":56.355383999999994,"y":116.52903},{"x":55.74075512499999,"y":116.53875500000001},{"x":55.11178699999999,"y":116.53603000000001},{"x":55.11178699999999,"y":116.53603000000001},{"x":53.14135487499999,"y":116.51904625000002},{"x":51.38711699999999,"y":116.55313000000001},{"x":51.38711699999999,"y":116.55313000000001},{"x":50.99578362499998,"y":116.60964375},{"x":50.653671999999986,"y":116.94434000000001},{"x":50.653671999999986,"y":116.94434000000001},{"x":50.52128874999998,"y":117.71096250000001},{"x":50.560701999999985,"y":118.55494000000002},{"x":50.560701999999985,"y":118.55494000000002},{"x":51.141705749999986,"y":120.67542375000001},{"x":52.35818299999998,"y":122.21516000000001},{"x":52.35818299999998,"y":122.21516000000001},{"x":53.59777749999998,"y":122.8176325},{"x":54.93402299999998,"y":122.94435000000001},{"x":54.93402299999998,"y":122.94435000000001},{"x":56.39983449999998,"y":122.65880500000002},{"x":57.68936599999998,"y":122.11703000000001}],[{"x":73.95477599999998,"y":111.28444000000002},{"x":73.95477599999998,"y":111.28444000000002},{"x":75.04342874999998,"y":111.19168625000002},{"x":76.08759599999998,"y":111.48462000000002},{"x":76.08759599999998,"y":111.48462000000002},{"x":77.15949387499997,"y":112.39826500000001},{"x":77.89568799999998,"y":113.80517000000002},{"x":77.89568799999998,"y":113.80517000000002},{"x":78.14515412499998,"y":119.27002875000002},{"x":75.46576899999998,"y":122.90455000000001},{"x":75.46576899999998,"y":122.90455000000001},{"x":74.41983512499998,"y":123.00129000000001},{"x":73.42155099999998,"y":122.70665000000001},{"x":73.42155099999998,"y":122.70665000000001},{"x":72.36481424999998,"y":121.80433500000001},{"x":71.61187699999998,"y":120.45412000000002},{"x":71.61187699999998,"y":120.45412000000002},{"x":71.10049612499998,"y":116.32945750000002},{"x":72.22084599999998,"y":112.53517000000002},{"x":72.22084599999998,"y":112.53517000000002},{"x":73.01291749999999,"y":111.71810875000001},{"x":73.95477599999998,"y":111.28444000000002}],[{"x":169.23631999999998,"y":112.02373000000001},{"x":169.23631999999998,"y":112.37996000000001}],[{"x":37.86867399999997,"y":114.04239000000001},{"x":37.86867399999997,"y":114.04239000000001},{"x":38.405687124999965,"y":114.04239000000001},{"x":39.11378499999997,"y":114.04239000000001},{"x":39.11378499999997,"y":114.04239000000001},{"x":39.80797449999997,"y":114.04239000000001},{"x":40.53513399999997,"y":114.04239000000001},{"x":40.53513399999997,"y":114.04239000000001},{"x":42.56868874999997,"y":114.04239000000001},{"x":44.53457099999997,"y":114.04239000000001},{"x":44.53457099999997,"y":114.04239000000001},{"x":45.30355537499997,"y":114.04239000000001},{"x":45.95693699999997,"y":114.04239000000001}],[{"x":126.03965999999997,"y":117.01101000000001},{"x":126.03965999999997,"y":117.60474}],[{"x":169.23631999999998,"y":121.7608},{"x":169.23631999999998,"y":122.11703}],[{"x":148.08239999999998,"y":122.35453},{"x":148.17129999999997,"y":122.35453}],[{"x":155.19296999999997,"y":122.35453},{"x":155.28186999999997,"y":122.35453}]]; | |
// The dimension is a bit small for default curve (and it's upside down for some reason) so I call: | |
// createCurves(data.map(p => p.map(({x, y}) => ({ x: Math.round(x * 30) - 3000, y: 5000 - (Math.round(y * 30)) })))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run this in the console | |
// Then you should quickly refocus the active window for the fillCoord to work properly | |
// Womp sometime needs some air | |
const wait = (ms) => new Promise(r => setTimeout(r, 10)); | |
// Toggle the create shape pannel | |
const toggleCreate = async () => { | |
document.evaluate("//p[text()='OBJECTS']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null) | |
.singleNodeValue | |
.nextSibling | |
.children[0] | |
.click(); | |
await wait(); | |
} | |
// Scroll to bottom of element list | |
const scrollToBottom = async () => { | |
const container = document.querySelector('#scenelist_body [data-simplebar] .hide-scrollbar'); | |
container.scrollTop = container.scrollHeight; | |
await wait(); | |
} | |
// Filling coords (X, Y or Z) of selected element | |
const fillCoord = async (coord, value) => { | |
const element = document | |
.evaluate(`//p[text()='${coord}']`, document.getElementById('__scene_item_property_panel__'), null, XPathResult.FIRST_ORDERED_NODE_TYPE, null) | |
.singleNodeValue | |
.parentElement | |
.nextSibling; | |
element.focus(); | |
document.execCommand('selectAll', false); | |
document.execCommand('insertText', false, value); | |
await wait(); | |
} | |
// Create curves from array of parts | |
// A part is an array of { x, y } object | |
const createCurves = async (parts) => { | |
// Ignore empty parts | |
parts = parts.filter(points => points.length) | |
for (let points of parts) { | |
// I was too lazy to write a delete point function lol | |
if (points.length === 1) points = [points[0], points[0]] | |
// Open create panel, please | |
while (!document.getElementById('prim_panel_container')) await toggleCreate() | |
// Create a curve element | |
document | |
.evaluate("//p[text()='Curve']", document.getElementById('prim_panel_container'), null, XPathResult.FIRST_ORDERED_NODE_TYPE, null) | |
.singleNodeValue | |
.click(); | |
await wait(); | |
// That's the curve in the element list | |
const curve = document.querySelector('.bg-\\[\\#E0F2FE\\]'); | |
const parent = curve.parentElement.parentElement.parentElement; | |
await scrollToBottom(); // Elements are a virtual list so we need to keep elements visible | |
// Create all the points | |
let index = 0 | |
for (let point of points) { | |
// Reuse the 2 default curve points | |
if (index === 1) parent?.nextElementSibling?.querySelector('button')?.click() | |
else if (!index) parent?.nextElementSibling?.nextElementSibling?.querySelector('button')?.click() | |
// Create new curve point | |
else curve.querySelector('div.opacity-0 button').click(); | |
await wait(); | |
await fillCoord('X', point.x); | |
await fillCoord('Y', point.y); | |
await fillCoord('Z', 0); // Projection code goes there.... | |
index++; | |
} | |
await scrollToBottom(); | |
} | |
} | |
// So basically, calls createCurves(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert SVG path to array of points | |
// It may or may not handle correctly bezier curves, I'm not really sure | |
// Sorry I'm too lazy to comment it | |
// Run this in node | |
// YOUR PATH goes here | |
const path = 'M256.016,0C114.609,0,0,114.625,0,255.984C0,397.359,114.609,512,256.016,512 C397.391,512,512,397.359,512,255.984C512,114.625,397.391,0,256.016,0z M341.781,103.266l87.516,89.953l-127.766,33.109 L341.781,103.266z M256.016,245.781l25.859,37.016h-25.859h-25.891L256.016,245.781z M170.219,103.266l40.25,123.063 L82.703,193.219L170.219,103.266z M351.563,417.719l-3.5-26.719l-34.469,8.891v34.578c-18.188,5.688-37.5,8.828-57.625,8.828 c-14.156,0-27.953-1.563-41.219-4.5l-3.484-31.516l-40.078-4.344l1.391,21.234c-63.766-31-107.656-96.344-107.656-171.969 c0-10.922,0.922-21.609,2.672-32.016c9.484,40.938,43.531,75.844,90.813,96.344V357l43.844,3.438l1.25-29.766 c16.688,3.453,34.297,5.359,52.469,5.359c25,0,48.781-3.516,70.641-9.875l3.922,34.281l42.625-5.922l1.047-48.313 c36.422-20.922,62.141-51.297,70.203-86.016c1.75,10.406,2.703,21.094,2.703,32.016 C447.109,322.938,408.656,384.656,351.563,417.719z' | |
const Bezier = require("bezier-js").Bezier; | |
const svgPath = require('svg-path-parser'); | |
// Number of points to compute for beziers curves | |
const bezierLUT = 2 | |
const commands = svgPath(path); | |
const parts = []; | |
let position = { x: 0, y: 0 }; | |
let points = []; | |
commands.forEach((command, index) => { | |
const compute = (mod) => (command.relative | |
? ({ x: position.x + (mod.x || 0), y: position.y + (mod.y || 0) }) | |
: ({ x: mod.x || position.x, y: mod.y || position.y })) | |
if (command.command === 'moveto') { | |
if (points.length) parts.push(points); | |
position = compute({ x: command.x, y: command.y }); | |
points = [position]; | |
} | |
if (command.command === 'lineto') { | |
position = compute({ x: command.x, y: command.y }); | |
points.push(position); | |
} | |
if (command.command === 'vertical lineto') { | |
position = compute({ y: command.y }); | |
points.push(position); | |
} | |
if (command.command === 'horizontal lineto') { | |
position = compute({ x: command.x }); | |
points.push(position); | |
} | |
if (command.command === 'curveto') { | |
const bezierPoints = command.relative | |
? [ | |
{ x: position.x, y: position.y }, | |
{ x: position.x + command.x1, y: position.y + command.y1 }, | |
{ x: position.x + command.x2, y: position.y + command.y2 }, | |
{ x: position.x + command.x, y: position.y + command.y } | |
] | |
: [ | |
{ x: position.x, y: position.y }, | |
{ x: command.x1, y: command.y1 }, | |
{ x: command.x2, y: command.y2 }, | |
{ x: command.x, y: command.y } | |
] | |
points.push( | |
...(new Bezier(...bezierPoints)).getLUT(bezierLUT).map(({ x, y }) => ({ x, y })) | |
) | |
position = points[points.length - 1] | |
} | |
}); | |
if (points.length) parts.push(points); | |
console.log(JSON.stringify(parts)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment