@gridspace/raster-path 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@gridspace/raster-path",
3
+ "version": "1.0.2",
4
+ "private": false,
5
+ "description": "Terrain and Tool Raster Path Finder using WebGPU",
6
+ "type": "module",
7
+ "main": "build/raster-path.js",
8
+ "exports": {
9
+ ".": "./build/raster-path.js",
10
+ "./worker": "./build/webgpu-worker.js"
11
+ },
12
+ "files": [
13
+ "build/**/*",
14
+ "src/**/*.js",
15
+ "src/**/*.wgsl",
16
+ "scripts/**/*",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "sideEffects": false,
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/gridspace/raster-path.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/gridspace/raster-path/issues"
27
+ },
28
+ "scripts": {
29
+ "prepare": "npm run build",
30
+ "postinstall": "npm run build",
31
+ "build": "npm run clean && npm run build:web && npm run build:shaders",
32
+ "build:shaders": "node scripts/build-shaders.js",
33
+ "build:web": "mkdir -p build && cp src/web/*.html src/web/*.css src/web/*.js build/ && cp src/index.js build/raster-path.js && cp src/etc/serve.json build/",
34
+ "clean": "rm -rf build/",
35
+ "dev": "npm run build && npm run serve",
36
+ "serve": "npx serve build --config serve.json --listen 9090",
37
+ "test": "npm run test:planar && npm run test:radial",
38
+ "test:planar": "npm run build && npx electron src/test/planar-test.cjs",
39
+ "test:planar-tiling": "npm run build && npx electron src/test/planar-tiling-test.cjs",
40
+ "test:radial": "npm run build && npx electron src/test/radial-test.cjs"
41
+ },
42
+ "keywords": [
43
+ "cnc",
44
+ "toolpath",
45
+ "rasterization",
46
+ "terrain",
47
+ "webgpu",
48
+ "stl",
49
+ "3d",
50
+ "gpu-accelerated"
51
+ ],
52
+ "author": "",
53
+ "license": "MIT",
54
+ "devDependencies": {
55
+ "electron": "^28.0.0",
56
+ "serve": "^14.2.1"
57
+ }
58
+ }
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Build script: Injects shader code into webgpu-worker.js
4
+ *
5
+ * Replaces placeholders like SHADER-radial-cull with shader file contents
6
+ */
7
+
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import { fileURLToPath } from 'url';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+
15
+ const SHADER_DIR = path.join(__dirname, '../src/shaders');
16
+ const WORKER_SRC = path.join(__dirname, '../src/web/webgpu-worker.js');
17
+ const BUILD_DIR = path.join(__dirname, '../build');
18
+ const WORKER_DEST = path.join(BUILD_DIR, 'webgpu-worker.js');
19
+
20
+ // Read worker source
21
+ let workerCode = fs.readFileSync(WORKER_SRC, 'utf8');
22
+
23
+ // Find all shader placeholders
24
+ const shaderRegex = /\/\*SHADER:([a-z0-9-]+)\*\//g;
25
+ let match;
26
+ const replacements = [];
27
+
28
+ while ((match = shaderRegex.exec(workerCode)) !== null) {
29
+ const shaderName = match[1];
30
+ const placeholder = match[0];
31
+ replacements.push({ shaderName, placeholder });
32
+ }
33
+
34
+ // Replace each placeholder with shader code
35
+ for (const { shaderName, placeholder } of replacements) {
36
+ const shaderPath = path.join(SHADER_DIR, `${shaderName}.wgsl`);
37
+
38
+ if (!fs.existsSync(shaderPath)) {
39
+ console.error(`❌ Shader file not found: ${shaderPath}`);
40
+ process.exit(1);
41
+ }
42
+
43
+ const shaderCode = fs.readFileSync(shaderPath, 'utf8');
44
+
45
+ // Wrap in template literal and escape backticks
46
+ const escapedShader = shaderCode.replace(/`/g, '\\`').replace(/\$/g, '\\$');
47
+ const wrapped = '`' + escapedShader + '`';
48
+
49
+ workerCode = workerCode.replace(placeholder, wrapped);
50
+ console.log(`✅ Injected shader: ${shaderName}.wgsl`);
51
+ }
52
+
53
+ // Ensure build directory exists
54
+ if (!fs.existsSync(BUILD_DIR)) {
55
+ fs.mkdirSync(BUILD_DIR, { recursive: true });
56
+ }
57
+
58
+ // Inject unique build ID
59
+ const buildId = Math.random().toString(36).substring(2, 10).toUpperCase();
60
+ workerCode = workerCode.replace(/BUILD_ID_PLACEHOLDER/g, buildId);
61
+ console.log(`🔨 Build ID: ${buildId}`);
62
+
63
+ // Write output
64
+ fs.writeFileSync(WORKER_DEST, workerCode, 'utf8');
65
+ console.log(`✅ Built: ${WORKER_DEST}`);