From ded085f16d9cc9ba99c0837d8d8efe01a5afc4af Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Sat, 8 Jun 2024 10:30:58 -0400 Subject: [PATCH] Make default demo a gyroid + sphere --- demos/web-editor/global.d.ts | 1 + demos/web-editor/index.html | 2 +- demos/web-editor/index.ts | 2 +- demos/web-editor/package-lock.json | 104 +++++++++++++++++++++++++++++ demos/web-editor/package.json | 1 + demos/web-editor/webpack.config.js | 4 ++ models/gyroid-sphere.rhai | 11 +++ 7 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 demos/web-editor/global.d.ts create mode 100644 models/gyroid-sphere.rhai diff --git a/demos/web-editor/global.d.ts b/demos/web-editor/global.d.ts new file mode 100644 index 00000000..d4ba1e74 --- /dev/null +++ b/demos/web-editor/global.d.ts @@ -0,0 +1 @@ +declare module "*.rhai"; diff --git a/demos/web-editor/index.html b/demos/web-editor/index.html index 353cfb27..0f2e3c11 100644 --- a/demos/web-editor/index.html +++ b/demos/web-editor/index.html @@ -51,7 +51,7 @@ Loading... diff --git a/demos/web-editor/index.ts b/demos/web-editor/index.ts index 9d3ac476..f144d284 100644 --- a/demos/web-editor/index.ts +++ b/demos/web-editor/index.ts @@ -17,7 +17,7 @@ import { import { RENDER_SIZE, WORKERS_PER_SIDE, WORKER_COUNT } from "./constants"; -const INITIAL_SCRIPT = "y + x*x"; +import INITIAL_SCRIPT from "../../models/gyroid-sphere.rhai"; var fidget: any = null; diff --git a/demos/web-editor/package-lock.json b/demos/web-editor/package-lock.json index 29f4b29c..80398d0a 100644 --- a/demos/web-editor/package-lock.json +++ b/demos/web-editor/package-lock.json @@ -11,6 +11,7 @@ "@wasm-tool/wasm-pack-plugin": "1.5.0", "html-webpack-plugin": "^5.3.2", "prettier": "3.2.5", + "raw-loader": "^4.0.2", "ts-loader": "^9.5.1", "typescript": "^5.4.5", "webpack": "^5.49.0", @@ -761,6 +762,15 @@ "integrity": "sha512-x+VAiMRL6UPkx+kudNvxTl6hB2XNNCG2r+7wixVfIYwu/2HKRXimwQyaumLjMveWvT2Hkd/cAJw+QBMfJ/EKVw==", "dev": true }, + "node_modules/big.js": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", + "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/binary-extensions": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", @@ -1373,6 +1383,15 @@ "integrity": "sha512-Rer6wc3ynLelKNM4lOCg7/zPQj8tPOCB2hzD32PX9wd3hgRRi9MxEbmkFCokzcEhRVMiOVLjnL9ig9cefJ+6+Q==", "dev": true }, + "node_modules/emojis-list": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", + "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, "node_modules/encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -2374,6 +2393,18 @@ "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -2402,6 +2433,20 @@ "node": ">=6.11.5" } }, + "node_modules/loader-utils": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz", + "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==", + "dev": true, + "dependencies": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + }, + "engines": { + "node": ">=8.9.0" + } + }, "node_modules/locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -2991,6 +3036,26 @@ "node": ">= 0.8" } }, + "node_modules/raw-loader": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-4.0.2.tgz", + "integrity": "sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA==", + "dev": true, + "dependencies": { + "loader-utils": "^2.0.0", + "schema-utils": "^3.0.0" + }, + "engines": { + "node": ">= 10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^4.0.0 || ^5.0.0" + } + }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -4994,6 +5059,12 @@ "integrity": "sha512-x+VAiMRL6UPkx+kudNvxTl6hB2XNNCG2r+7wixVfIYwu/2HKRXimwQyaumLjMveWvT2Hkd/cAJw+QBMfJ/EKVw==", "dev": true }, + "big.js": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", + "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==", + "dev": true + }, "binary-extensions": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", @@ -5458,6 +5529,12 @@ "integrity": "sha512-Rer6wc3ynLelKNM4lOCg7/zPQj8tPOCB2hzD32PX9wd3hgRRi9MxEbmkFCokzcEhRVMiOVLjnL9ig9cefJ+6+Q==", "dev": true }, + "emojis-list": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", + "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==", + "dev": true + }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -6178,6 +6255,12 @@ "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true }, + "json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true + }, "kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -6200,6 +6283,17 @@ "integrity": "sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==", "dev": true }, + "loader-utils": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz", + "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==", + "dev": true, + "requires": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + } + }, "locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -6649,6 +6743,16 @@ } } }, + "raw-loader": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-4.0.2.tgz", + "integrity": "sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA==", + "dev": true, + "requires": { + "loader-utils": "^2.0.0", + "schema-utils": "^3.0.0" + } + }, "readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", diff --git a/demos/web-editor/package.json b/demos/web-editor/package.json index 609f6259..7a2ae7c0 100644 --- a/demos/web-editor/package.json +++ b/demos/web-editor/package.json @@ -11,6 +11,7 @@ "@wasm-tool/wasm-pack-plugin": "1.5.0", "html-webpack-plugin": "^5.3.2", "prettier": "3.2.5", + "raw-loader": "^4.0.2", "ts-loader": "^9.5.1", "typescript": "^5.4.5", "webpack": "^5.49.0", diff --git a/demos/web-editor/webpack.config.js b/demos/web-editor/webpack.config.js index 09f1acc4..68ca74bd 100644 --- a/demos/web-editor/webpack.config.js +++ b/demos/web-editor/webpack.config.js @@ -11,6 +11,10 @@ module.exports = { use: "ts-loader", exclude: /node_modules/, }, + { + test: /\.rhai$/i, + use: "raw-loader", + }, ], }, resolve: { diff --git a/models/gyroid-sphere.rhai b/models/gyroid-sphere.rhai new file mode 100644 index 00000000..30802cd9 --- /dev/null +++ b/models/gyroid-sphere.rhai @@ -0,0 +1,11 @@ +let scale = 30; + +let x = x * scale; +let y = y * scale; +let z = z * scale; + +let gyroid = sin(x)*cos(y) + sin(y)*cos(z) + sin(z)*cos(x); +let fill = abs(gyroid) - 0.2; + +let sphere = sqrt(square(x) + square(y) + square(z)) - 25; +draw(max(sphere, fill));