diff --git a/examples/public/index.html b/examples/index.html similarity index 96% rename from examples/public/index.html rename to examples/index.html index 71d8f934..7869cd53 100644 --- a/examples/public/index.html +++ b/examples/index.html @@ -35,7 +35,7 @@ let scriptUrl = urlParams.get('scriptUrl'); const name = urlParams.get('name') || 'nodes/glTFIBL'; if (name !== null) { - scriptUrl = `./js/${name}/index.js`; + scriptUrl = `./src/${name}/index.ts`; } var script = document.createElement('script'); script.setAttribute('type', 'module'); diff --git a/examples/package.json b/examples/package.json index 7d53c8da..ed3b1118 100644 --- a/examples/package.json +++ b/examples/package.json @@ -8,15 +8,12 @@ "dist" ], "scripts": { - "build": "glsl-transpiler -r src -o src && tsc --noEmit && threeify-build src/**/index.ts --bundle --optimize", - "dev": "glsl-transpiler -r src -o src --watch & tsc --noEmit --watch & threeify-build src/**/index.ts --bundle --serve" + "build": "glsl-transpiler -r src -o src && vite build", + "dev": "glsl-transpiler -r src -o src --watch & vite" }, "dependencies": { "@threeify/core": "*", "@threeify/math": "*", "@threeify/scene": "*" - }, - "devDependencies": { - "@threeify/build": "*" } } diff --git a/examples/vite.config.js b/examples/vite.config.js new file mode 100644 index 00000000..2de94bd0 --- /dev/null +++ b/examples/vite.config.js @@ -0,0 +1,12 @@ +import { defineConfig } from 'vite'; + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + port: 3000, + proxy: { + '/api': 'http://localhost:3001' + }, + host: '0.0.0.0' // allow for local external connections + } +}); diff --git a/package-lock.json b/package-lock.json index 96d84145..fc819ead 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,6 @@ "@types/node": "^20.3.1", "@types/offscreencanvas": "^2019.7.0", "@typescript-eslint/eslint-plugin": "^5.59.11", - "esbuild": "0.18.3", "eslint": "^8.42.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.27.5", @@ -41,7 +40,8 @@ "ts-jest-resolver": "^2.0.1", "ts-node": "^10.9.1", "typescript": "5.1.3", - "vite": "^4.1.4" + "vite": "^4.4.3", + "vite-tsconfig-paths": "^4.2.0" } }, "examples": { @@ -51,9 +51,6 @@ "@threeify/core": "*", "@threeify/math": "*", "@threeify/scene": "*" - }, - "devDependencies": { - "@threeify/build": "*" } }, "node_modules/@ampproject/remapping": { @@ -655,12 +652,59 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@esbuild/android-arm": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.16.tgz", + "integrity": "sha512-gCHjjQmA8L0soklKbLKA6pgsLk1byULuHe94lkZDzcO3/Ta+bbeewJioEn1Fr7kgy9NWNFy/C+MrBwC6I/WCug==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.16.tgz", + "integrity": "sha512-wsCqSPqLz+6Ov+OM4EthU43DyYVVyfn15S4j1bJzylDpc1r1jZFFfJQNfDuT8SlgwuqpmpJXK4uPlHGw6ve7eA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.16.tgz", + "integrity": "sha512-ldsTXolyA3eTQ1//4DS+E15xl0H/3DTRJaRL0/0PgkqDsI0fV/FlOtD+h0u/AUJr+eOTlZv4aC9gvfppo3C4sw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/@esbuild/darwin-arm64": { "version": "0.18.3", "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -670,6 +714,294 @@ "node": ">=12" } }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.16.tgz", + "integrity": "sha512-6w4Dbue280+rp3LnkgmriS1icOUZDyPuZo/9VsuMUTns7SYEiOaJ7Ca1cbhu9KVObAWfmdjUl4gwy9TIgiO5eA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.16.tgz", + "integrity": "sha512-x35fCebhe9s979DGKbVAwXUOcTmCIE32AIqB9CB1GralMIvxdnMLAw5CnID17ipEw9/3MvDsusj/cspYt2ZLNQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.16.tgz", + "integrity": "sha512-YM98f+PeNXF3GbxIJlUsj+McUWG1irguBHkszCIwfr3BXtXZsXo0vqybjUDFfu9a8Wr7uUD/YSmHib+EeGAFlg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.16.tgz", + "integrity": "sha512-b5ABb+5Ha2C9JkeZXV+b+OruR1tJ33ePmv9ZwMeETSEKlmu/WJ45XTTG+l6a2KDsQtJJ66qo/hbSGBtk0XVLHw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.16.tgz", + "integrity": "sha512-XIqhNUxJiuy+zsR77+H5Z2f7s4YRlriSJKtvx99nJuG5ATuJPjmZ9n0ANgnGlPCpXGSReFpgcJ7O3SMtzIFeiQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.16.tgz", + "integrity": "sha512-no+pfEpwnRvIyH+txbBAWtjxPU9grslmTBfsmDndj7bnBmr55rOo/PfQmRfz7Qg9isswt1FP5hBbWb23fRWnow==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.16.tgz", + "integrity": "sha512-Zbnczs9ZXjmo0oZSS0zbNlJbcwKXa/fcNhYQjahDs4Xg18UumpXG/lwM2lcSvHS3mTrRyCYZvJbmzYc4laRI1g==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.16.tgz", + "integrity": "sha512-YMF7hih1HVR/hQVa/ot4UVffc5ZlrzEb3k2ip0nZr1w6fnYypll9td2qcoMLvd3o8j3y6EbJM3MyIcXIVzXvQQ==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.16.tgz", + "integrity": "sha512-Wkz++LZ29lDwUyTSEnzDaaP5OveOgTU69q9IyIw9WqLRxM4BjTBjz9un4G6TOvehWpf/J3gYVFN96TjGHrbcNQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.16.tgz", + "integrity": "sha512-LFMKZ30tk78/mUv1ygvIP+568bwf4oN6reG/uczXnz6SvFn4e2QUFpUpZY9iSJT6Qpgstrhef/nMykIXZtZWGQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.16.tgz", + "integrity": "sha512-3ZC0BgyYHYKfZo3AV2/66TD/I9tlSBaW7eWTEIkrQQKfJIifKMMttXl9FrAg+UT0SGYsCRLI35Gwdmm96vlOjg==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.16.tgz", + "integrity": "sha512-xu86B3647DihHJHv/wx3NCz2Dg1gjQ8bbf9cVYZzWKY+gsvxYmn/lnVlqDRazObc3UMwoHpUhNYaZset4X8IPA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.16.tgz", + "integrity": "sha512-uVAgpimx9Ffw3xowtg/7qQPwHFx94yCje+DoBx+LNm2ePDpQXHrzE+Sb0Si2VBObYz+LcRps15cq+95YM7gkUw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.16.tgz", + "integrity": "sha512-6OjCQM9wf7z8/MBi6BOWaTL2AS/SZudsZtBziXMtNI8r/U41AxS9x7jn0ATOwVy08OotwkPqGRMkpPR2wcTJXA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.16.tgz", + "integrity": "sha512-ZoNkruFYJp9d1LbUYCh8awgQDvB9uOMZqlQ+gGEZR7v6C+N6u7vPr86c+Chih8niBR81Q/bHOSKGBK3brJyvkQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.16.tgz", + "integrity": "sha512-+j4anzQ9hrs+iqO+/wa8UE6TVkKua1pXUb0XWFOx0FiAj6R9INJ+WE//1/Xo6FG1vB5EpH3ko+XcgwiDXTxcdw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.16.tgz", + "integrity": "sha512-5PFPmq3sSKTp9cT9dzvI67WNfRZGvEVctcZa1KGjDDu4n3H8k59Inbk0du1fz0KrAbKKNpJbdFXQMDUz7BG4rQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.16.tgz", + "integrity": "sha512-sCIVrrtcWN5Ua7jYXNG1xD199IalrbfV2+0k/2Zf2OyV2FtnQnMgdzgpRAbi4AWlKJj1jkX+M+fEGPQj6BQB4w==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "dev": true, @@ -2607,6 +2939,10 @@ "resolved": "packages/math", "link": true }, + "node_modules/@threeify/rollup-plugin-glsl-transpiler": { + "resolved": "tools/rollup-plugin-glsl-transpiler", + "link": true + }, "node_modules/@threeify/scene": { "resolved": "packages/scene", "link": true @@ -5223,7 +5559,6 @@ }, "node_modules/esbuild": { "version": "0.18.3", - "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { @@ -5257,6 +5592,321 @@ "@esbuild/win32-x64": "0.18.3" } }, + "node_modules/esbuild/node_modules/@esbuild/android-arm": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.3.tgz", + "integrity": "sha512-QOn3VIlL6Qv1eHBpQB/s7simaZgGss2ASyxDOwYSLmc6vD0uuizZkuYawHmuLjWEm5wPwp0JQWhbpaYwwGevYw==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/android-arm64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.3.tgz", + "integrity": "sha512-PgabCsoaEEnnOiF6rUhOBXgYoLFIrHWP6mfLOzuQ1oZ1lwBdTL0hp5ivC4K3Kvz3BD8EipjeQo6l0aty3nr4qQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/android-x64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.3.tgz", + "integrity": "sha512-1OkJf8wNX1W5ucbp5HrK+z42b9DINb4ix59oJH/PIsh9cyFMqjgRKtCBXg0zEWhkmP1k3egdfrnS7cDTpLH43g==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/darwin-x64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.3.tgz", + "integrity": "sha512-NVBqMnxT9qvgu7Z322LUDlwjh4GDk6wEePyAQnHF9noxik/WvLFmr5v3Vgz5LSvqFducLCxsdmLztKhdpFW0Gg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/freebsd-arm64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.3.tgz", + "integrity": "sha512-XiLK1AsCk2wKxN7j8h9GXXCs8FPZhp07U0rnpwRkAVSVGgLaIWYSqpTRzKjAfqJiZlp+XKo1HwsmDdICEKB3Dg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/freebsd-x64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.3.tgz", + "integrity": "sha512-xyITfrF0G3l1gwR79hvNCCWKQ/16uK14xNNPFgzjbIqF4EpBvhO6l3jrWxXFUW51z6dVIl2Szh3x3uIbBWzH1Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-arm": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.3.tgz", + "integrity": "sha512-fc/T0QHMzvmnlF+kfD6bHLB8u+17gg13260p/E86yYjVoKNFjonL/+Y0GGQjMbFUas9QijqOa7pcR00a9RNkwg==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-arm64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.3.tgz", + "integrity": "sha512-lsKUYVd8L/j2uNs8dhMjMsKC5MHYh77gR9EThu7YCeeFz1XpIkx1I4a7mhoVfPS2VPVD1pMCh+PgxuAHUcEmXw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-ia32": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.3.tgz", + "integrity": "sha512-EyfGWeOwRqK5Xj18vok0qv8IFBZ1/+hKV+cqD44oVhGsxHo9TmPtoSiDrWn8Sa2swq/VuO5Aiog6YPDj81oIkA==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-loong64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.3.tgz", + "integrity": "sha512-PwXkcl3t0kSeYH5RuJIeh/fHOzKZd+ZdifAWzpVO+9TLWArutTFBJvOSkTZ3CcqQqNrTj1Qyo6nqE8MQj/a7cQ==", + "cpu": [ + "loong64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-mips64el": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.3.tgz", + "integrity": "sha512-CRVkkSXf5GQcq7Am2a2tdIn85oqi/bkjuPvhNqcdeTgI0xgNbqLnEPRy2AEGkRuaJWB5uCX1IC4sqnY8ET14Yg==", + "cpu": [ + "mips64el" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-ppc64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.3.tgz", + "integrity": "sha512-t7zK1Cheh0xvzfZbimztiE0wGnpV+YRsBg3tefcEBN3O4GzgLu6fFpA5HxEyVm3hHZW1jAC4OhoGEp7C5Ii6Eg==", + "cpu": [ + "ppc64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-riscv64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.3.tgz", + "integrity": "sha512-fUZPtyCYih6y4lDYdSM4Yoax4nS7aH0/XixJStys+9tfp5cAlIAZhEVKOOdeGXmQn0IEyiUtlIsPnfObbeDQfQ==", + "cpu": [ + "riscv64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-s390x": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.3.tgz", + "integrity": "sha512-oIcK2LqHWqfMERqjvaKJ3QJmycHn723HsXIv5gH4iGfmePfSj+gi0ZQv2h4bHUg2bs2gJtV0DlIjGhEuvdgxLw==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/linux-x64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.3.tgz", + "integrity": "sha512-RW9lpfZ6XZ6f5to2DJPvt0f/4RXEW229Xf++quVoW+YbnPrcapIJChtD/AmZ8cK3hglO/hXxJjs21pV0/l7L5w==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/netbsd-x64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.3.tgz", + "integrity": "sha512-piZ2oBoaq58pKZvhgdV6PemlL30Uhd9GmmOkIGZYgChwNcyVSSl6iMEJxMzU7x44Lk9q+hJ6a343M/iVEMEvxA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/openbsd-x64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.3.tgz", + "integrity": "sha512-vaMfouYTz/4tKdQsXDccqhV6wgPEr+hfuxdNU5Pl/vQxYTsqcXv5DYEa5Z1RAxCoua5aEB+Uj5V7VT/bM92wxw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/sunos-x64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.3.tgz", + "integrity": "sha512-Fa3rNQQ9q1qwy9u2cdDvuGKy3jmPnPPMDdyy/qbn5d395Pb9hjLYiPzX9BozXMPJDlCNofSY7jN3miM9gyAdHA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/win32-arm64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.3.tgz", + "integrity": "sha512-LPJC8ub+9uzyC6ygVmp00dAqet1q1DsZ/OldGIIBt+y+Ctd1OfnKNlzQgXK8nxwY1G8fAhklFSeSRRgAUJnR0w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/win32-ia32": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.3.tgz", + "integrity": "sha512-WtUyRspyxZR6NTc2HG4xd9Wvz8lP4C6OUY1gAqisrf151HvXIxsK0mfAacFJNS7EN2wvPTgjP+SM8vgBOx5+zA==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild/node_modules/@esbuild/win32-x64": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.3.tgz", + "integrity": "sha512-Z8qCK4BkBm40j5KUM4NrkxYQS0R12cBO1NBVtI4vws6uwh1n/VaNu31Hm+n2cJUWdFbfH57PBghkhm9yLgmPfw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/escalade": { "version": "3.1.1", "dev": true, @@ -6099,7 +6749,6 @@ }, "node_modules/fsevents": { "version": "2.3.2", - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -10107,6 +10756,8 @@ }, "node_modules/nanoid": { "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", "dev": true, "funding": [ { @@ -10114,7 +10765,6 @@ "url": "https://github.com/sponsors/ai" } ], - "license": "MIT", "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -11606,7 +12256,9 @@ } }, "node_modules/postcss": { - "version": "8.4.24", + "version": "8.4.27", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.27.tgz", + "integrity": "sha512-gY/ACJtJPSmUFPDCHtX78+01fHa64FaU4zaaWfuh1MhGJISufJAH4cun6k/8fwsHYeK4UQmENQK+tRLCFJE8JQ==", "dev": true, "funding": [ { @@ -11622,7 +12274,6 @@ "url": "https://github.com/sponsors/ai" } ], - "license": "MIT", "dependencies": { "nanoid": "^3.3.6", "picocolors": "^1.0.0", @@ -12422,9 +13073,9 @@ } }, "node_modules/rollup": { - "version": "3.25.1", - "dev": true, - "license": "MIT", + "version": "3.26.3", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.26.3.tgz", + "integrity": "sha512-7Tin0C8l86TkpcMtXvQu6saWH93nhG3dGQ1/+l5V2TDMceTxO7kDiK6GzbfLWNNxqJXm591PcEZUozZm51ogwQ==", "bin": { "rollup": "dist/bin/rollup" }, @@ -12711,8 +13362,9 @@ }, "node_modules/source-map-js": { "version": "1.0.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", + "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", "dev": true, - "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" } @@ -13457,6 +14109,26 @@ } } }, + "node_modules/tsconfck": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/tsconfck/-/tsconfck-2.1.2.tgz", + "integrity": "sha512-ghqN1b0puy3MhhviwO2kGF8SeMDNhEbnKxjK7h6+fvY9JAxqvXi8y5NAHSQv687OVboS2uZIByzGd45/YxrRHg==", + "dev": true, + "bin": { + "tsconfck": "bin/tsconfck.js" + }, + "engines": { + "node": "^14.13.1 || ^16 || >=18" + }, + "peerDependencies": { + "typescript": "^4.3.5 || ^5.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/tsconfig-paths": { "version": "3.14.2", "dev": true, @@ -13797,13 +14469,14 @@ } }, "node_modules/vite": { - "version": "4.3.9", + "version": "4.4.6", + "resolved": "https://registry.npmjs.org/vite/-/vite-4.4.6.tgz", + "integrity": "sha512-EY6Mm8vJ++S3D4tNAckaZfw3JwG3wa794Vt70M6cNJ6NxT87yhq7EC8Rcap3ahyHdo8AhCmV9PTk+vG1HiYn1A==", "dev": true, - "license": "MIT", "dependencies": { - "esbuild": "^0.17.5", - "postcss": "^8.4.23", - "rollup": "^3.21.0" + "esbuild": "^0.18.10", + "postcss": "^8.4.26", + "rollup": "^3.25.2" }, "bin": { "vite": "bin/vite.js" @@ -13811,12 +14484,16 @@ "engines": { "node": "^14.18.0 || >=16.0.0" }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, "optionalDependencies": { "fsevents": "~2.3.2" }, "peerDependencies": { "@types/node": ">= 14", "less": "*", + "lightningcss": "^1.21.0", "sass": "*", "stylus": "*", "sugarss": "*", @@ -13829,6 +14506,9 @@ "less": { "optional": true }, + "lightningcss": { + "optional": true + }, "sass": { "optional": true }, @@ -13843,13 +14523,33 @@ } } }, + "node_modules/vite-tsconfig-paths": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/vite-tsconfig-paths/-/vite-tsconfig-paths-4.2.0.tgz", + "integrity": "sha512-jGpus0eUy5qbbMVGiTxCL1iB9ZGN6Bd37VGLJU39kTDD6ZfULTTb1bcc5IeTWqWJKiWV5YihCaibeASPiGi8kw==", + "dev": true, + "dependencies": { + "debug": "^4.1.1", + "globrex": "^0.1.2", + "tsconfck": "^2.1.0" + }, + "peerDependencies": { + "vite": "*" + }, + "peerDependenciesMeta": { + "vite": { + "optional": true + } + } + }, "node_modules/vite/node_modules/@esbuild/darwin-arm64": { - "version": "0.17.19", + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.16.tgz", + "integrity": "sha512-aBxruWCII+OtluORR/KvisEw0ALuw/qDQWvkoosA+c/ngC/Kwk0lLaZ+B++LLS481/VdydB2u6tYpWxUfnLAIw==", "cpu": [ "arm64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "darwin" @@ -13859,10 +14559,11 @@ } }, "node_modules/vite/node_modules/esbuild": { - "version": "0.17.19", + "version": "0.18.16", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.16.tgz", + "integrity": "sha512-1xLsOXrDqwdHxyXb/x/SOyg59jpf/SH7YMvU5RNSU7z3TInaASNJWNFJ6iRvLvLETZMasF3d1DdZLg7sgRimRQ==", "dev": true, "hasInstallScript": true, - "license": "MIT", "bin": { "esbuild": "bin/esbuild" }, @@ -13870,28 +14571,28 @@ "node": ">=12" }, "optionalDependencies": { - "@esbuild/android-arm": "0.17.19", - "@esbuild/android-arm64": "0.17.19", - "@esbuild/android-x64": "0.17.19", - "@esbuild/darwin-arm64": "0.17.19", - "@esbuild/darwin-x64": "0.17.19", - "@esbuild/freebsd-arm64": "0.17.19", - "@esbuild/freebsd-x64": "0.17.19", - "@esbuild/linux-arm": "0.17.19", - "@esbuild/linux-arm64": "0.17.19", - "@esbuild/linux-ia32": "0.17.19", - "@esbuild/linux-loong64": "0.17.19", - "@esbuild/linux-mips64el": "0.17.19", - "@esbuild/linux-ppc64": "0.17.19", - "@esbuild/linux-riscv64": "0.17.19", - "@esbuild/linux-s390x": "0.17.19", - "@esbuild/linux-x64": "0.17.19", - "@esbuild/netbsd-x64": "0.17.19", - "@esbuild/openbsd-x64": "0.17.19", - "@esbuild/sunos-x64": "0.17.19", - "@esbuild/win32-arm64": "0.17.19", - "@esbuild/win32-ia32": "0.17.19", - "@esbuild/win32-x64": "0.17.19" + "@esbuild/android-arm": "0.18.16", + "@esbuild/android-arm64": "0.18.16", + "@esbuild/android-x64": "0.18.16", + "@esbuild/darwin-arm64": "0.18.16", + "@esbuild/darwin-x64": "0.18.16", + "@esbuild/freebsd-arm64": "0.18.16", + "@esbuild/freebsd-x64": "0.18.16", + "@esbuild/linux-arm": "0.18.16", + "@esbuild/linux-arm64": "0.18.16", + "@esbuild/linux-ia32": "0.18.16", + "@esbuild/linux-loong64": "0.18.16", + "@esbuild/linux-mips64el": "0.18.16", + "@esbuild/linux-ppc64": "0.18.16", + "@esbuild/linux-riscv64": "0.18.16", + "@esbuild/linux-s390x": "0.18.16", + "@esbuild/linux-x64": "0.18.16", + "@esbuild/netbsd-x64": "0.18.16", + "@esbuild/openbsd-x64": "0.18.16", + "@esbuild/sunos-x64": "0.18.16", + "@esbuild/win32-arm64": "0.18.16", + "@esbuild/win32-ia32": "0.18.16", + "@esbuild/win32-x64": "0.18.16" } }, "node_modules/walk-up-path": { @@ -14361,7 +15062,6 @@ "@threeify/math": "*" }, "devDependencies": { - "@threeify/build": "*", "@threeify/glsl-transpiler": "*" } }, @@ -14373,7 +15073,6 @@ "@threeify/math": "*" }, "devDependencies": { - "@threeify/build": "*", "@threeify/glsl-transpiler": "*" } }, @@ -14381,7 +15080,6 @@ "name": "@threeify/math", "version": "4.0.3", "devDependencies": { - "@threeify/build": "*", "@threeify/glsl-transpiler": "*" } }, @@ -14395,7 +15093,6 @@ "meshoptimizer": "^0.18.1" }, "devDependencies": { - "@threeify/build": "*", "@threeify/glsl-transpiler": "*", "@types/draco3dgltf": "^1.4.0" } @@ -14413,7 +15110,10 @@ }, "tools/esbuild-plugin-glsl-transpiler": { "name": "@threeify/esbuild-plugin-glsl-transpiler", - "version": "4.0.2" + "version": "4.0.2", + "dependencies": { + "esbuild": "0.18.3" + } }, "tools/examples-server": { "version": "1.0.0", @@ -14509,6 +15209,13 @@ "engines": { "node": ">=10" } + }, + "tools/rollup-plugin-glsl-transpiler": { + "name": "@threeify/rollup-plugin-glsl-transpiler", + "version": "4.0.2", + "dependencies": { + "rollup": "^3.26.3" + } } } } diff --git a/package.json b/package.json index c9f19778..05c31bc8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "@types/node": "^20.3.1", "@types/offscreencanvas": "^2019.7.0", "@typescript-eslint/eslint-plugin": "^5.59.11", - "esbuild": "0.18.3", "eslint": "^8.42.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.27.5", @@ -61,6 +60,7 @@ "ts-jest-resolver": "^2.0.1", "ts-node": "^10.9.1", "typescript": "5.1.3", - "vite": "^4.1.4" + "vite": "^4.4.3", + "vite-tsconfig-paths": "^4.2.0" } } diff --git a/packages/core/package.json b/packages/core/package.json index 8824853e..f205d6c2 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -25,7 +25,6 @@ "@threeify/math": "*" }, "devDependencies": { - "@threeify/build": "*", "@threeify/glsl-transpiler": "*" } } diff --git a/packages/core/src/renderers/effects/gaussianblur/GaussianBlur.ts b/packages/core/src/renderers/effects/gaussianblur/GaussianBlur.ts index 5d262b64..7f63b5ad 100644 --- a/packages/core/src/renderers/effects/gaussianblur/GaussianBlur.ts +++ b/packages/core/src/renderers/effects/gaussianblur/GaussianBlur.ts @@ -2,8 +2,9 @@ import { Color3, Vec2, vec2Equals, vec2ToString } from '@threeify/math'; import { assert } from '../../../core/assert.js'; import { using } from '../../../core/using.js'; +import { Blending } from '../../../index.js'; import { ShaderMaterial } from '../../../materials/ShaderMaterial.js'; -import { BlendState } from '../../webgl/BlendState.js'; +import { blendModeToBlendState, BlendState } from '../../webgl/BlendState.js'; import { ClearState } from '../../webgl/ClearState.js'; import { BufferBit } from '../../webgl/framebuffers/BufferBit.js'; import { @@ -101,7 +102,9 @@ export async function createGaussianBlur( program, uniforms, blendState: - targetAlpha < 1 ? BlendState.PremultipliedOver : BlendState.None + targetAlpha < 1 + ? blendModeToBlendState(Blending.Over, true) + : BlendState.None }); }, diff --git a/packages/core/src/renderers/webgl/BlendState.ts b/packages/core/src/renderers/webgl/BlendState.ts index 8760589e..f17d9b80 100644 --- a/packages/core/src/renderers/webgl/BlendState.ts +++ b/packages/core/src/renderers/webgl/BlendState.ts @@ -57,10 +57,6 @@ export class BlendState implements ICloneable, IEquatable { static readonly None = new BlendState(); - static readonly PremultipliedOver = blendModeToBlendState( - Blending.Over, - true - ); // TODO: Should be initialized to default WebGL states constructor( diff --git a/packages/layer-compositor/package.json b/packages/layer-compositor/package.json index edef37c0..ef2defe2 100644 --- a/packages/layer-compositor/package.json +++ b/packages/layer-compositor/package.json @@ -15,7 +15,6 @@ "@threeify/math": "*" }, "devDependencies": { - "@threeify/build": "*", "@threeify/glsl-transpiler": "*" } } diff --git a/packages/math/package.json b/packages/math/package.json index 35dd62cb..f50e765f 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -11,7 +11,6 @@ "dev": "glsl-transpiler -r src -o dist --watch & tsc --watch" }, "devDependencies": { - "@threeify/build": "*", "@threeify/glsl-transpiler": "*" } } diff --git a/packages/scene/package.json b/packages/scene/package.json index ecb427e0..d729d721 100644 --- a/packages/scene/package.json +++ b/packages/scene/package.json @@ -16,7 +16,6 @@ "meshoptimizer": "^0.18.1" }, "devDependencies": { - "@threeify/build": "*", "@threeify/glsl-transpiler": "*", "@types/draco3dgltf": "^1.4.0" } diff --git a/packages/scene/src/renderer/rendering.ts b/packages/scene/src/renderer/rendering.ts index 8be6b7b4..5babb5b8 100644 --- a/packages/scene/src/renderer/rendering.ts +++ b/packages/scene/src/renderer/rendering.ts @@ -1,6 +1,8 @@ import { Attachment, biltFramebuffers, + Blending, + blendModeToBlendState, BlendState, BufferBit, CanvasFramebuffer, @@ -140,7 +142,7 @@ export function renderScene( outputTransformFlags: 0x4 }, DepthTestState.LessOrEqual, - BlendState.PremultipliedOver, + blendModeToBlendState(Blending.Over, true), CullingState.Back ); @@ -166,7 +168,7 @@ export function renderScene( blendMeshBatches, blendUniforms, DepthTestState.Less, - BlendState.PremultipliedOver, + blendModeToBlendState(Blending.Over, true), CullingState.Front ); @@ -176,7 +178,7 @@ export function renderScene( blendMeshBatches, blendUniforms, DepthTestState.Less, - BlendState.PremultipliedOver, + blendModeToBlendState(Blending.Over, true), CullingState.Back ); } diff --git a/tools/esbuild-plugin-glsl-transpiler/package.json b/tools/esbuild-plugin-glsl-transpiler/package.json index be079ae7..49cbef2f 100644 --- a/tools/esbuild-plugin-glsl-transpiler/package.json +++ b/tools/esbuild-plugin-glsl-transpiler/package.json @@ -8,5 +8,8 @@ "build": "tsc", "dev": "tsc --watch", "types": "tsc --emitDeclarationOnly --outDir dist --watch" + }, + "dependencies": { + "esbuild": "0.18.3" } } diff --git a/tools/examples-server/package.json b/tools/examples-server/package.json index 660c7008..e6dd4dcf 100644 --- a/tools/examples-server/package.json +++ b/tools/examples-server/package.json @@ -1,11 +1,9 @@ { "name": "examples-server", "version": "1.0.0", - "main": "src/server.js", "scripts": { - "build": "tsc --noEmit && esbuild src/server.ts --format=cjs --platform=node --bundle --outfile=dist/server.js", - "dev": "tsc --noEmit --watch & esbuild src/server.ts --format=cjs --platform=node --bundle --sourcemap --outfile=dist/server.js --watch", - "start": "nodemon dist/server.js" + "build": "tsc", + "dev": "tsc --watch & nodemon dist/server.js" }, "devDependencies": { "@types/hapi__joi": "^17.1.9", diff --git a/tools/examples-server/src/config.ts b/tools/examples-server/src/config.ts index 834ba3a8..4ffe0c70 100644 --- a/tools/examples-server/src/config.ts +++ b/tools/examples-server/src/config.ts @@ -4,7 +4,7 @@ import dotenv from 'dotenv'; dotenv.config(); export const HOST = process.env.HOST ?? 'http://127.0.0.1'; -export const PORT = Number.parseInt(process.env.PORT ?? '8000'); +export const PORT = Number.parseInt(process.env.PORT ?? '3001'); export const NODE_ENV = process.env.NODE_ENV ?? 'production'; export const EXAMPLES_ROOT = process.env.EXAMPLES_ROOT ?? '../../examples'; export const ASSETS_ROOT = process.env.ASSETS_ROOT ?? '../../assets'; diff --git a/tools/rollup-plugin-glsl-transpiler/package.json b/tools/rollup-plugin-glsl-transpiler/package.json new file mode 100644 index 00000000..3dd33089 --- /dev/null +++ b/tools/rollup-plugin-glsl-transpiler/package.json @@ -0,0 +1,15 @@ +{ + "name": "@threeify/rollup-plugin-glsl-transpiler", + "version": "4.0.2", + "type": "module", + "main": "./dist/index.js", + "source": "./src/index.ts", + "scripts": { + "build": "tsc", + "dev": "tsc --watch", + "types": "tsc --emitDeclarationOnly --outDir dist --watch" + }, + "dependencies": { + "rollup": "^3.26.3" + } +} diff --git a/tools/rollup-plugin-glsl-transpiler/src/index.ts b/tools/rollup-plugin-glsl-transpiler/src/index.ts new file mode 100644 index 00000000..e131c763 --- /dev/null +++ b/tools/rollup-plugin-glsl-transpiler/src/index.ts @@ -0,0 +1,35 @@ +import fs from 'fs/promises'; +import path from 'path'; +import { Plugin } from 'rollup'; + +import { transpileSource } from './transpileSource.js'; + +export default function glslTranspiler(): Plugin { + return { + name: 'glsl-transpiler', + + async load(id: string) { + if (!id.match(/\.glsl$/)) return null; + + const parsedPath = path.parse(id); + + const glslSource = await fs.readFile(id, 'utf-8'); + const jsSource = transpileSource( + parsedPath.dir, + parsedPath.base, + glslSource + ); + + return jsSource; + }, + + transform(code: string, id: string) { + if (!id.match(/\.glsl$/)) return null; + + return { + code, + map: { mappings: '' } + }; + } + }; +} diff --git a/tools/rollup-plugin-glsl-transpiler/src/transpileSource.ts b/tools/rollup-plugin-glsl-transpiler/src/transpileSource.ts new file mode 100644 index 00000000..ec99200f --- /dev/null +++ b/tools/rollup-plugin-glsl-transpiler/src/transpileSource.ts @@ -0,0 +1,83 @@ +// matches with // #pragma import +const importRegex = /^#pragma import "(?[^\n"]+)"$/gm; + +function pathToVariableName(path: string): string { + const variableName = path + .replace(/@/g, '_') + .replace(/\//g, '_') + .replace(/\./g, '_') + .replace(/.glsl/g, '') + .replace(/_+/g, '_'); + // console.log('pathToVariableName', path, variableName); + return variableName; +} + +export function transpileSource( + rootDir: string, + glslSourceFileName: string, + glslSource: string +): string { + // create a list of imports + const importNamesToPaths: Map = new Map(); + + // for each match of the import regex, add the import to the list of imports, and remove the import from the glsl source + // and insert the expected variable into the javascript literal. + // the expected variable is the name of the file without the extension + // for example, if the import is #pragma import './my-shader.glsl' + + glslSource = glslSource.replace( + importRegex, + (match: string, importPath: string, other: string) => { + // console.log( + // `replacement match:${match} importPath:${importPath} other:${other}` + // ); + + // convert the import path to a variable name + const importName = pathToVariableName(importPath); + + // add the import to the list of imports + importNamesToPaths.set(importName, importPath); + + // replace the import from the glsl source with the expected import name + return '${' + importName + '}'; + } + ); + + if (glslSource.includes('#pragma once')) { + // convert the import path to a variable name + const includeGuardName = pathToVariableName( + glslSourceFileName.replace(rootDir, '') + ); + + const includeGuardPrefix = `#ifndef ${includeGuardName}\n#define ${includeGuardName}\n`; + const includeGuardPostfix = `\n\n#endif // end of include guard`; + + glslSource = + includeGuardPrefix + + glslSource.replace(/#pragma once/gm, '') + + '\n' + + includeGuardPostfix; + } + + // create the javascript literal + const jsLiteral = '`' + glslSource + '`'; + + // create the typescript source + let tsSource = ''; + + // add the imports + importNamesToPaths.forEach((importPath, importName) => { + if (importPath.includes('/dist/') || importPath.includes('@')) { + importPath += ''; + } + tsSource += `import ${importName} from '${importPath}';\n`; + }); + + tsSource += '\n'; + + // add the export + tsSource += 'export default ' + jsLiteral + ';'; + + // get path from filename + return tsSource; +} diff --git a/tools/rollup-plugin-glsl-transpiler/tsconfig.json b/tools/rollup-plugin-glsl-transpiler/tsconfig.json new file mode 100644 index 00000000..e675c412 --- /dev/null +++ b/tools/rollup-plugin-glsl-transpiler/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src"], + "compilerOptions": { + "outDir": "dist" + } +}