Webpack setup, mesh and math classes

This commit is contained in:
Alan O'Cull 2023-12-02 19:42:46 -05:00
parent dbf095b2ca
commit 53381f0496
16 changed files with 30015 additions and 9 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
node_modules/
build/
dist/

24
assets/css/puzzle.css Normal file
View File

@ -0,0 +1,24 @@
body {
overflow: hidden;
}
h1 {
text-align: center;
width: 80%;
margin-left: 10%;
margin-right: 10%;
}
.canvas_container {
width: 100%;
align-content: center;
justify-content: center;
}
canvas {
width: 80vmin;
height: 80vmin;
display: block;
margin-left: auto;
margin-right: auto;
}

28761
assets/objects/hard/clover.obj Normal file

File diff suppressed because it is too large Load Diff

17
assets/puzzle.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Pattern Packer</title>
<link rel="stylesheet" href="../css/puzzle.css">
<script src="client.js"></script>
</head>
<body>
<h1>01</h1>
<div class="canvas_container">
<canvas id="draw" width="1024" height="1024">
</canvas>
</div>
</body>
</html>

688
package-lock.json generated
View File

@ -11,11 +11,24 @@
"dependencies": {
"dotenv": "^16.3.1",
"express": "^4.18.2",
"webpack": "^5.89.0"
"lodash": "^4.17.21",
"webpack": "^5.89.0",
"webpack-node-externals": "^3.0.0"
},
"devDependencies": {
"@types/express": "^4.17.21",
"typescript": "^5.3.2"
"ts-loader": "^9.5.1",
"typescript": "^5.3.2",
"webpack-cli": "^5.1.4"
}
},
"node_modules/@discoveryjs/json-ext": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz",
"integrity": "sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==",
"dev": true,
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/@jridgewell/gen-mapping": {
@ -325,6 +338,50 @@
"@xtuc/long": "4.2.2"
}
},
"node_modules/@webpack-cli/configtest": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@webpack-cli/configtest/-/configtest-2.1.1.tgz",
"integrity": "sha512-wy0mglZpDSiSS0XHrVR+BAdId2+yxPSoJW8fsna3ZpYSlufjvxnP4YbKTCBZnNIcGN4r6ZPXV55X4mYExOfLmw==",
"dev": true,
"engines": {
"node": ">=14.15.0"
},
"peerDependencies": {
"webpack": "5.x.x",
"webpack-cli": "5.x.x"
}
},
"node_modules/@webpack-cli/info": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@webpack-cli/info/-/info-2.0.2.tgz",
"integrity": "sha512-zLHQdI/Qs1UyT5UBdWNqsARasIA+AaF8t+4u2aS2nEpBQh2mWIVb8qAklq0eUENnC5mOItrIB4LiS9xMtph18A==",
"dev": true,
"engines": {
"node": ">=14.15.0"
},
"peerDependencies": {
"webpack": "5.x.x",
"webpack-cli": "5.x.x"
}
},
"node_modules/@webpack-cli/serve": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/@webpack-cli/serve/-/serve-2.0.5.tgz",
"integrity": "sha512-lqaoKnRYBdo1UgDX8uF24AfGMifWK19TxPmM5FHc2vAGxrJ/qtyUyFBWoY1tISZdelsQ5fBcOusifo5o5wSJxQ==",
"dev": true,
"engines": {
"node": ">=14.15.0"
},
"peerDependencies": {
"webpack": "5.x.x",
"webpack-cli": "5.x.x"
},
"peerDependenciesMeta": {
"webpack-dev-server": {
"optional": true
}
}
},
"node_modules/@xtuc/ieee754": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz",
@ -389,6 +446,21 @@
"ajv": "^6.9.1"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
@ -417,6 +489,18 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"dev": true,
"dependencies": {
"fill-range": "^7.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/browserslist": {
"version": "4.22.1",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.22.1.tgz",
@ -493,6 +577,34 @@
}
]
},
"node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/chalk/node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/chrome-trace-event": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz",
@ -501,6 +613,44 @@
"node": ">=6.0"
}
},
"node_modules/clone-deep": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz",
"integrity": "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==",
"dev": true,
"dependencies": {
"is-plain-object": "^2.0.4",
"kind-of": "^6.0.2",
"shallow-clone": "^3.0.0"
},
"engines": {
"node": ">=6"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"node_modules/colorette": {
"version": "2.0.20",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz",
"integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==",
"dev": true
},
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
@ -538,6 +688,20 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
},
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
"dev": true,
"dependencies": {
"path-key": "^3.1.0",
"shebang-command": "^2.0.0",
"which": "^2.0.1"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@ -617,6 +781,18 @@
"node": ">=10.13.0"
}
},
"node_modules/envinfo": {
"version": "7.11.0",
"resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.11.0.tgz",
"integrity": "sha512-G9/6xF1FPbIw0TtalAMaVPpiq2aDEuKLXM314jPVAO9r2fo2a4BLqMNkmRS7O/xPPZ+COAhGIz3ETvHEV3eUcg==",
"dev": true,
"bin": {
"envinfo": "dist/cli.js"
},
"engines": {
"node": ">=4"
}
},
"node_modules/es-module-lexer": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.4.1.tgz",
@ -741,6 +917,27 @@
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
},
"node_modules/fastest-levenshtein": {
"version": "1.0.16",
"resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz",
"integrity": "sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg==",
"dev": true,
"engines": {
"node": ">= 4.9.1"
}
},
"node_modules/fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"dev": true,
"dependencies": {
"to-regex-range": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/finalhandler": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
@ -758,6 +955,28 @@
"node": ">= 0.8"
}
},
"node_modules/find-up": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
"integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
"dev": true,
"dependencies": {
"locate-path": "^5.0.0",
"path-exists": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/flat": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz",
"integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==",
"dev": true,
"bin": {
"flat": "cli.js"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -895,11 +1114,39 @@
"node": ">=0.10.0"
}
},
"node_modules/import-local": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/import-local/-/import-local-3.1.0.tgz",
"integrity": "sha512-ASB07uLtnDs1o6EHjKpX34BKYDSqnFerfTOJL2HvMqF70LnxpjkzDB8J44oT9pu4AMPkQwf8jl6szgvNd2tRIg==",
"dev": true,
"dependencies": {
"pkg-dir": "^4.2.0",
"resolve-cwd": "^3.0.0"
},
"bin": {
"import-local-fixture": "fixtures/cli.js"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"node_modules/interpret": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/interpret/-/interpret-3.1.1.tgz",
"integrity": "sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ==",
"dev": true,
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
@ -908,6 +1155,54 @@
"node": ">= 0.10"
}
},
"node_modules/is-core-module": {
"version": "2.13.1",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz",
"integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==",
"dev": true,
"dependencies": {
"hasown": "^2.0.0"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/is-number": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
"dev": true,
"engines": {
"node": ">=0.12.0"
}
},
"node_modules/is-plain-object": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
"integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
"dev": true,
"dependencies": {
"isobject": "^3.0.1"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
"dev": true
},
"node_modules/isobject": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
"integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/jest-worker": {
"version": "27.5.1",
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz",
@ -931,6 +1226,15 @@
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
},
"node_modules/kind-of": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
"integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/loader-runner": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.3.0.tgz",
@ -939,6 +1243,35 @@
"node": ">=6.11.5"
}
},
"node_modules/locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
"integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==",
"dev": true,
"dependencies": {
"p-locate": "^4.1.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@ -965,6 +1298,19 @@
"node": ">= 0.6"
}
},
"node_modules/micromatch": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz",
"integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==",
"dev": true,
"dependencies": {
"braces": "^3.0.2",
"picomatch": "^2.3.1"
},
"engines": {
"node": ">=8.6"
}
},
"node_modules/mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
@ -1037,6 +1383,42 @@
"node": ">= 0.8"
}
},
"node_modules/p-limit": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
"integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
"dev": true,
"dependencies": {
"p-try": "^2.0.0"
},
"engines": {
"node": ">=6"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/p-locate": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz",
"integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==",
"dev": true,
"dependencies": {
"p-limit": "^2.2.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/p-try": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
@ -1045,6 +1427,30 @@
"node": ">= 0.8"
}
},
"node_modules/path-exists": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/path-key": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/path-parse": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
"dev": true
},
"node_modules/path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
@ -1055,6 +1461,30 @@
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
},
"node_modules/picomatch": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true,
"engines": {
"node": ">=8.6"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/pkg-dir": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz",
"integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==",
"dev": true,
"dependencies": {
"find-up": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
@ -1119,6 +1549,56 @@
"node": ">= 0.8"
}
},
"node_modules/rechoir": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.8.0.tgz",
"integrity": "sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==",
"dev": true,
"dependencies": {
"resolve": "^1.20.0"
},
"engines": {
"node": ">= 10.13.0"
}
},
"node_modules/resolve": {
"version": "1.22.8",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz",
"integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==",
"dev": true,
"dependencies": {
"is-core-module": "^2.13.0",
"path-parse": "^1.0.7",
"supports-preserve-symlinks-flag": "^1.0.0"
},
"bin": {
"resolve": "bin/resolve"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/resolve-cwd": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz",
"integrity": "sha512-OrZaX2Mb+rJCpH/6CpSqt9xFVpN++x01XnN2ie9g6P5/3xelLAkXWVADpdz1IHD/KFfEXyE6V0U01OQ3UO2rEg==",
"dev": true,
"dependencies": {
"resolve-from": "^5.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/resolve-from": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
@ -1160,6 +1640,21 @@
"url": "https://opencollective.com/webpack"
}
},
"node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/send": {
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz",
@ -1229,6 +1724,39 @@
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
},
"node_modules/shallow-clone": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz",
"integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==",
"dev": true,
"dependencies": {
"kind-of": "^6.0.2"
},
"engines": {
"node": ">=8"
}
},
"node_modules/shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
"dev": true,
"dependencies": {
"shebang-regex": "^3.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/shebang-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/side-channel": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
@ -1281,6 +1809,18 @@
"url": "https://github.com/chalk/supports-color?sponsor=1"
}
},
"node_modules/supports-preserve-symlinks-flag": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
"dev": true,
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/tapable": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz",
@ -1339,6 +1879,18 @@
}
}
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
"dev": true,
"dependencies": {
"is-number": "^7.0.0"
},
"engines": {
"node": ">=8.0"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
@ -1347,6 +1899,35 @@
"node": ">=0.6"
}
},
"node_modules/ts-loader": {
"version": "9.5.1",
"resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-9.5.1.tgz",
"integrity": "sha512-rNH3sK9kGZcH9dYzC7CewQm4NtxJTjSEVRJ2DyBZR7f8/wcta+iV44UPCXc5+nzDzivKtlzV6c9P4e+oFhDLYg==",
"dev": true,
"dependencies": {
"chalk": "^4.1.0",
"enhanced-resolve": "^5.0.0",
"micromatch": "^4.0.0",
"semver": "^7.3.4",
"source-map": "^0.7.4"
},
"engines": {
"node": ">=12.0.0"
},
"peerDependencies": {
"typescript": "*",
"webpack": "^5.0.0"
}
},
"node_modules/ts-loader/node_modules/source-map": {
"version": "0.7.4",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz",
"integrity": "sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==",
"dev": true,
"engines": {
"node": ">= 8"
}
},
"node_modules/type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
@ -1496,6 +2077,82 @@
}
}
},
"node_modules/webpack-cli": {
"version": "5.1.4",
"resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-5.1.4.tgz",
"integrity": "sha512-pIDJHIEI9LR0yxHXQ+Qh95k2EvXpWzZ5l+d+jIo+RdSm9MiHfzazIxwwni/p7+x4eJZuvG1AJwgC4TNQ7NRgsg==",
"dev": true,
"dependencies": {
"@discoveryjs/json-ext": "^0.5.0",
"@webpack-cli/configtest": "^2.1.1",
"@webpack-cli/info": "^2.0.2",
"@webpack-cli/serve": "^2.0.5",
"colorette": "^2.0.14",
"commander": "^10.0.1",
"cross-spawn": "^7.0.3",
"envinfo": "^7.7.3",
"fastest-levenshtein": "^1.0.12",
"import-local": "^3.0.2",
"interpret": "^3.1.1",
"rechoir": "^0.8.0",
"webpack-merge": "^5.7.3"
},
"bin": {
"webpack-cli": "bin/cli.js"
},
"engines": {
"node": ">=14.15.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/webpack"
},
"peerDependencies": {
"webpack": "5.x.x"
},
"peerDependenciesMeta": {
"@webpack-cli/generators": {
"optional": true
},
"webpack-bundle-analyzer": {
"optional": true
},
"webpack-dev-server": {
"optional": true
}
}
},
"node_modules/webpack-cli/node_modules/commander": {
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz",
"integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==",
"dev": true,
"engines": {
"node": ">=14"
}
},
"node_modules/webpack-merge": {
"version": "5.10.0",
"resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.10.0.tgz",
"integrity": "sha512-+4zXKdx7UnO+1jaN4l2lHVD+mFvnlZQP/6ljaJVb4SZiwIKeUnrT5l0gkT8z+n4hKpC+jpOv6O9R+gLtag7pSA==",
"dev": true,
"dependencies": {
"clone-deep": "^4.0.1",
"flat": "^5.0.2",
"wildcard": "^2.0.0"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/webpack-node-externals": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz",
"integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==",
"engines": {
"node": ">=6"
}
},
"node_modules/webpack-sources": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz",
@ -1503,6 +2160,33 @@
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"dev": true,
"dependencies": {
"isexe": "^2.0.0"
},
"bin": {
"node-which": "bin/node-which"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/wildcard": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/wildcard/-/wildcard-2.0.1.tgz",
"integrity": "sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ==",
"dev": true
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}
}
}

View File

@ -1,7 +1,9 @@
{
"devDependencies": {
"@types/express": "^4.17.21",
"typescript": "^5.3.2"
"ts-loader": "^9.5.1",
"typescript": "^5.3.2",
"webpack-cli": "^5.1.4"
},
"name": "pattern-packer",
"version": "1.0.0",
@ -9,10 +11,9 @@
"main": "index.js",
"scripts": {
"all": "npm run clean && npm run build && npm run start",
"allwin": "npm run build && npm run start",
"clean": "rm -rf build/",
"cleanwin": "rmdir -Recurse -Force /S /Q .\\build\\",
"build": "tsc",
"prebuild": "mkdir -p dist/public/ && cp -R assets/* dist/public/",
"build": "tsc && webpack --config ./webpack/development.js",
"rebuild": "npm run clean && npm run build",
"server": "node ./build/server/server.js",
"debug": "node ./build/server/server.js -debug"
@ -32,6 +33,8 @@
"dependencies": {
"dotenv": "^16.3.1",
"express": "^4.18.2",
"webpack": "^5.89.0"
"lodash": "^4.17.21",
"webpack": "^5.89.0",
"webpack-node-externals": "^3.0.0"
}
}

View File

@ -0,0 +1,13 @@
import { Mesh, MeshImport } from "./mesh";
const request_mesh = (filename: string) => {
let request = new XMLHttpRequest();
request.open('GET', `localhost:${3000}/mesh/${filename}`, false);
request.send(null);
return request.responseText;
}
const buff = request_mesh('clover.obj');
const mesh = MeshImport.parse(buff);
console.log(`Got mesh array at ${mesh.name}`);
console.log(mesh.shells);

5
src/client/math/index.ts Normal file
View File

@ -0,0 +1,5 @@
import Vector2 from './vector';
import Triangle from './triangle';
import Shell from './shell';
export { Vector2, Triangle, Shell };

65
src/client/math/shell.ts Normal file
View File

@ -0,0 +1,65 @@
import Vector2 from './vector';
import Triangle from './triangle';
class Shell {
public centerpoint: Vector2 = new Vector2();
public rotation: number = 0;
public scale: number = 1.0;
constructor(private triangles: Triangle[]) {
}
public get uvs(): Vector2[] {
let uvs: Vector2[] = [];
this.triangles.forEach((t: Triangle) => {
t.uvs.forEach((c: Vector2) => {
uvs.push(Vector2.Multiply(Vector2.Rotate(c, this.rotation), this.scale));
})
})
return uvs;
};
public connected(t: Triangle): boolean {
for (let i = 0; i < this.triangles.length; i++) {
if (this.triangles[i].connected_fast(t)) {
return true;
}
}
return false;
}
public connected_shell(s: Shell): boolean {
for (let i = 0; i < this.triangles.length; i++) {
for (let j = 0; j < s.triangles.length; j++) {
if (this.triangles[i].connected_fast(s.triangles[j])) {
return true;
}
}
}
return false;
}
public merge(other: Shell) {
this.triangles = this.triangles.concat(other.triangles);
}
public append(t: Triangle) {
this.triangles.push(t);
}
public calculate_centerpoint() {
let uvs = Triangle.find_unique_uvs(this.triangles);
this.centerpoint = new Vector2();
uvs.forEach((coord: Vector2) => {
this.centerpoint = Vector2.Add(this.centerpoint, coord);
});
this.centerpoint = Vector2.Divide(this.centerpoint, uvs.length);
this.triangles.forEach((t: Triangle) => {
t.set_centerpoint(this.centerpoint);
});
}
}
export { Shell as default };

View File

@ -0,0 +1,78 @@
import Vector2 from './vector';
const EPSILON = 0.0001;
class Triangle {
public uvs: Vector2[];
constructor (private coords: number[], private baseuvs: Vector2[], public uv_indices: number[]) {
this.uvs = [];
baseuvs.forEach((coord: Vector2) => {
this.uvs.push(Vector2.Clone(coord));
})
}
/**
* @summary Compares to see if the triangles share a UV coordinate
* @param t Triangle to see if this is connected to
* @returns If true, triangles are connected
*/
public connected(t: Triangle): boolean {
for (let i = 0; i < 3; i++) {
const c1 = this.baseuvs[i];
for (let j = 0; j < 3; j++) {
const c2 = t.baseuvs[j];
if (Vector2.Distance(c1, c2) < EPSILON) {
return true;
}
}
}
return false;
}
/**
* @summary Compares to see if the triangles share a UV coordinate (based on mesh indices)
* @param t Triangle to see if this is connected to
* @returns If true, triangles are connected
*/
public connected_fast(t: Triangle): boolean {
for (let i = 0; i < 3; i++) {
const idx1 = this.uv_indices[i];
for (let j = 0; j < 3; j++) {
const idx2 = t.uv_indices[j];
if (idx1 === idx2) {
return true;
}
}
}
return false;
}
public set_centerpoint(center: Vector2) {
for (let i = 0; i < this.uvs.length; i++) {
this.uvs[i] = Vector2.Subtract(this.baseuvs[i], center);
}
}
static find_unique_uvs(tris: Triangle[]): Vector2[] {
let uvs: Vector2[] = [];
tris.forEach((t: Triangle) => {
t.uvs.forEach((uv: Vector2) => {
let exists: boolean = false;
for (let i = 0; i < uvs.length; i++) {
if (Vector2.Distance(uv, uvs[i]) < EPSILON) {
exists = true;
break;
}
}
if (!exists) {
uvs.push(Vector2.Clone(uv));
}
});
});
return uvs;
}
}
export { Triangle as default };

117
src/client/math/vector.ts Normal file
View File

@ -0,0 +1,117 @@
const TwoPI = Math.PI * 2;
class Vector2 { // A structure that holds position data or direction and magnitude
public x: number;
public y: number;
constructor(X: number = 0, Y: number = 0) {
this.x = X;
this.y = Y;
}
// Returns length of this vector (or should this be static?)
public length():number {
return Math.sqrt((this.x ** 2) + (this.y ** 2));
}
// Limits length of this vector to a set field
public clamp(minLen: number, maxLen: number = minLen): Vector2 {
const len = this.length();
const lenF = Math.min(Math.max(len, minLen), maxLen);
if (lenF !== len) {
const unit = Vector2.UnitVector(this);
this.x = unit.x * lenF;
this.y = unit.y * lenF;
}
return this;
}
public equals(compareTo: Vector2): boolean {
return (this.x === compareTo.x && this.y === compareTo.y);
}
// Static methods--generates new vectors to avoid overriding old properties
static Add(a: Vector2, b: Vector2):Vector2 {
return new Vector2(a.x + b.x, a.y + b.y);
}
static Subtract(a: Vector2, b: Vector2):Vector2 {
return new Vector2(a.x - b.x, a.y - b.y);
}
static Multiply(a: Vector2, b: number):Vector2 { // A is a vector, b should be a scalar number
return new Vector2(a.x * b, a.y * b);
}
static Divide(a: Vector2, b: number):Vector2 {
return new Vector2(a.x / b, a.y / b);
}
static MultiplyVectors(a: Vector2, b: Vector2):Vector2 {
return new Vector2(a.x * b.x, a.y * b.y);
}
// Returns a copy of the given vector with the same direction but a length of one
static UnitVector(a: Vector2):Vector2 {
const len = a.length();
if (len <= 0) return new Vector2(0, 0);
return new Vector2(a.x / len, a.y / len);
}
static UnitVectorFromXY(x: number, y: number) {
const len = Math.sqrt((x ** 2) + (y ** 2));
if (len <= 0) return new Vector2(0, 0);
return new Vector2(x / len, y / len);
}
static UnitVectorFromAngle(angle: number): Vector2 {
return new Vector2(Math.cos(angle), Math.sin(angle));
}
// Gets the dot product between two vectors
// Use normalized vectors for scalar value between -1 and 1
static DotProduct(a: Vector2, b: Vector2): number {
return a.x * b.x + a.y * b.y;
}
static Distance(a: Vector2, b:Vector2):number {
return Math.sqrt(((a.x - b.x) ** 2) + ((a.y - b.y) ** 2));
}
static Average(a: Vector2, b: Vector2):Vector2 {
return new Vector2((a.x + b.x) / 2, (a.y + b.y) / 2);
}
static Lerp(a: Vector2, b: Vector2, alpha: number):Vector2 {
const alpha2 = 1 - alpha;
return new Vector2(a.x * alpha2 + b.x * alpha, a.y * alpha2 + b.y * alpha);
}
static Clone(a: Vector2):Vector2 {
return new Vector2(a.x, a.y);
}
static Angle(a: Vector2): number {
if (a.y < 0) {
return Math.atan2(a.y, a.x) + TwoPI;
}
return Math.atan2(a.y, a.x);
}
static Rotate(a: Vector2, angle: number) {
const delta = Vector2.Angle(a) + angle;
return Vector2.Multiply(Vector2.UnitVectorFromAngle(delta), a.length());
}
static ConstrainAngle(angle: number, min: number = 0, max: number = TwoPI): number {
let a = angle;
while (a < 0) {
a += TwoPI;
}
while (a >= TwoPI) {
a -= TwoPI;
}
return Math.max(min, Math.min(a, max));
}
static ToString(a: Vector2): string {
return `(${a.x}, ${a.y})`;
}
}
export { Vector2 as default };

112
src/client/mesh/import.ts Normal file
View File

@ -0,0 +1,112 @@
import { Vector2, Triangle, Shell } from "../math";
import Mesh from './mesh';
const parse_obj = (line: string) => {
return line.split(' ')[1];
}
const parse_vertex = (line: string) => {
let vals: string[] = line.split(' ');
let nums: number[] = [];
for (let i = 1; i < 4 && i < vals.length; i++) {
nums[i-1] = parseFloat(vals[i]);
}
return nums;
}
const parse_uv = (line: string) => {
let vals: string[] = line.split(' ');
return new Vector2(parseFloat(vals[1]), parseFloat(vals[2]));
}
const parse_tri = (line: string) => {
let vals: string[] = line.split(' ');
let nums: number[] = [];
for (let i = 1; i < 4 && i < vals.length; i++) {
nums[i-1] = parseFloat(vals[i]);
}
return nums;
}
class MeshImport {
public static parse(buffer: string) {
const buff = buffer.split('\n');
// Initialize buffers
let verts: number[] = [];
let uvs: Vector2[] = [];
let tris: number[] = [];
let name: string = 'obj';
// Parse data
buff.forEach((line: string) => {
if (line.startsWith('o')) {
name = parse_obj(line);
} else if (line.startsWith('vt')) {
uvs.push(parse_uv(line));
} else if (line.startsWith('v')) {
verts = verts.concat(parse_vertex(line));
} else if (line.startsWith('f')) {
tris = tris.concat(parse_tri(line));
}
});
// Construct triangles
let t: Triangle[] = [];
for (let i = 0; i < tris.length; i += 6) {
let indices: number[] = [tris[i], tris[i+2], tris[i+4]];
let v: number[] = [];
indices.forEach((x: number) => {
v.push(verts[x], verts[x+1], verts[x+2]);
});
let uvi: number[] = [tris[i+1] - 1, tris[i+3] - 1, tris[i+5] - 1];
let uv: Vector2[] = [uvs[uvi[0]], uvs[uvi[1]], uvs[uvi[2]]];
t.push(new Triangle(v, uv, uvi));
}
// Create an initial shell
let shells: Shell[] = [];
// Initialize shells by sorting triangles roughly int othem
for (let i = 0; i < t.length; i++) {
let tri: Triangle = t[i];
let utilized: boolean = false;
for (let j = 0; j < shells.length; j++) {
if (shells[j].connected(tri)) {
utilized = true;
shells[j].append(tri);
break;
}
}
// If we could not find a corresponding shell, generate one
if (!utilized) {
shells.push(new Shell([tri]));
}
}
// Now, combine shells
for (let i = 0; i < shells.length; i++) {
const a = shells[i];
for (let j = i+1; j < shells.length; j++) {
const b = shells[j];
if (a.connected_shell(b)) {
a.merge(b);
shells = shells.splice(j, 1);
j--;
}
}
}
// Finally, calculate shells
shells.forEach((s: Shell) => {
s.calculate_centerpoint();
});
// Generate corresponding mesh
return new Mesh(name, shells);
}
}
export { MeshImport as default };

4
src/client/mesh/index.ts Normal file
View File

@ -0,0 +1,4 @@
import Mesh from './mesh';
import MeshImport from './import';
export { Mesh, MeshImport };

10
src/client/mesh/mesh.ts Normal file
View File

@ -0,0 +1,10 @@
import { Shell } from "../math";
class Mesh {
constructor (public name: String, public shells: Shell[]) {
}
}
export { Mesh as default };

View File

@ -9,7 +9,15 @@ const app: Express = express();
const port = process.env.PORT;
app.get('/', (req: Request, res: Response) => {
res.send('hello world');
const last = req.url.lastIndexOf('/');
const mesh_name = req.url.substring(last + 1);
const filepath = `assets/pages/${mesh_name}`;
if (fs.existsSync(filepath)) {
fs.readFileSync(`assets/pages/${mesh_name}`).toString('utf8');
} else {
res.send('o hello world');
}
});
app.listen(port, () => {

105
webpack/development.js Normal file
View File

@ -0,0 +1,105 @@
/* eslint-disable no-console */
const _ = require('lodash');
// eslint-disable-next-line
const webpack = require('webpack');
const path = require('path');
// eslint-disable-next-line
const nodeExternals = require('webpack-node-externals');
const childProcess = require('child_process');
// https://webpack.js.org/concepts/targets/
// Also suggests splitting up the config into two pieces... Better for us anyway.
const commonConfig = {
mode: 'development',
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx'],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
};
const clientConfig = _.defaultsDeep(_.cloneDeep(commonConfig), {
target: 'web',
entry: {
client: './src/client/client.ts',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, '../dist/public'),
},
externals: ['perf_hooks'],
plugins: [
new webpack.DefinePlugin({
CANVAS_RENDERER: JSON.stringify(true),
WEBGL_RENDERER: JSON.stringify(true),
}),
],
devtool: 'eval-source-map', // inline-source-map
});
const serverConfig = _.defaultsDeep(_.cloneDeep(commonConfig), {
target: 'node',
entry: {
server: './src/server/server.ts',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, '../dist'),
},
externals: [nodeExternals()],
plugins: [
{
apply: (compiler) => {
let ps = null;
let watchEnabled = false;
async function startServer() {
const serverPath = path.join(__dirname, '../dist/server.js');
console.log(`Starting ${serverPath} ...`);
ps = childProcess.spawn('node', [serverPath]);
ps.stdout.on('data', (data) => {
process.stdout.write(data);
});
ps.stderr.on('data', (data) => {
process.stderr.write(data);
});
// Automatically restart the server if it crashes.
ps.once('close', () => {
console.log('Crash detected, restarting ...');
startServer();
});
}
// https://webpack.js.org/api/compiler-hooks/
compiler.hooks.afterEmit.tap('RunServer', () => {
if (watchEnabled) {
if (ps !== null) {
console.log('Killing old process ...');
ps.kill();
} else {
startServer();
}
}
});
compiler.hooks.watchRun.tap('RunServer', () => {
console.log('Watch enabled, will restart server process automatically');
watchEnabled = true;
});
},
},
],
});
module.exports = [clientConfig, serverConfig];