scad-gltf 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A powerful WebAssembly (WASM) build of a custom OpenSCAD fork that enables direct compilation of OpenSCAD (`.scad`) scripts to **glTF/GLB** formats natively in JavaScript (Node.js and Browser).
4
4
 
5
- Unlike standard OpenSCAD, this custom engine supports **Physically Based Rendering (PBR)** materials, **Hierarchical Skeletal Animations**, and **Texture Baking**, making it a perfect bridge between procedural CAD generation and modern 3D web rendering engines (like Three.js or Babylon.js).
5
+ Unlike standard OpenSCAD, this custom engine supports **Physically Based Rendering (PBR)** materials, **Hierarchical Node Animations**, and **Texture Baking**, making it a perfect bridge between procedural CAD generation and modern 3D web rendering engines (like Three.js or Babylon.js).
6
6
 
7
7
  The C++ source code for this custom OpenSCAD version is included directly in this repository within the `openscad/` subfolder.
8
8
 
@@ -14,8 +14,7 @@ The C++ source code for this custom OpenSCAD version is included directly in thi
14
14
 
15
15
  - **Direct SCAD to GLB conversion:** Compile geometry directly to web-ready binary glTF.
16
16
  - **Extended PBR Material Support:** Native extensions to the OpenSCAD `color()` module supporting `metalness`, `roughness`, `transmission` (glass), `thickness`, `ior`, `attenuationColor`, `attenuationDistance`, `clearcoat`, `sheen`, `emissive`, `specular`, and `iridescence`, plus a `$asa` special variable for auto smooth shading.
17
- - **Skeletal Animation:** Define animated armatures and bones directly within your `.scad` files.
18
- - **True Skeletal Skinning:** Exports absolute world transforms and properly bound animation tracks.
17
+ - **Hierarchical Node Animation:** Define articulated, rigid-body hierarchies and keyframe animations using `armature()` and `bone()` modules. Exports proper glTF node transform tracks (rigid parenting rather than vertex-weighted skinning—ideal for robots, mechanical parts, vehicles, and articulated components).
19
18
  - **Texture Baking:** Automatically generate UVs and bake high-poly details (colors, normals, ORM) onto low-poly meshes using the new `bake()` module.
20
19
  - **Web Editor & Real-time Viewer (Scadify):** In-browser IDE with live WebAssembly compilation, GPU path tracing, animation timeline scrubbing, video/image export, URL sharing, and `.scad` / `.hdr` drag-and-drop.
21
20
  - **LLM Friendly:** Includes a built-in modular prompt generator (`prompt.js` and Web UI) to help AI models (like Gemini, Claude, or ChatGPT) write compatible OpenSCAD scripts utilizing the new features.
@@ -23,6 +22,7 @@ The C++ source code for this custom OpenSCAD version is included directly in thi
23
22
  - **CLI Converter:** Bundled `scad-convert` CLI utility for single file and batch compiling `.scad` files with smart dependency hashing.
24
23
  - **MCP Server for AI Agents:** Bundled `scad-mcp` server enables MCP clients to iteratively design, compile, and **visually inspect** 3D models via multi-angle headless rendering and animation frame evaluation.
25
24
  - **AI Studio Extension:** Chrome extension to natively preview, prompt, take chat snapshots, open in Scadify, and locally save AI-generated 3D models directly inside Google AI Studio.
25
+ - **Godot 4 Integration & Web Demos:** Native Godot 4 importer addon for procedural `.scad` assets and prebuilt AI-generated [web game examples](https://iliagrigorevdev.github.io/scad-godot/).
26
26
 
27
27
  ---
28
28
 
@@ -32,7 +32,7 @@ The built-in web editor (**Scadify**) provides a full-featured development envir
32
32
 
33
33
  - **Real-Time 3D Viewport:** Instant WebAssembly compilation with auto-rendering, camera auto-framing, wireframe view, grid/axes toggles, ACES Filmic tone mapping, and full-screen mode.
34
34
  - **Photorealistic GPU Path Tracing:** Built-in hardware-accelerated path tracer with HDR environment lighting for realistic reflections, shadows, and glass refraction. Supports custom `.hdr` environment maps via drag-and-drop.
35
- - **Interactive Animation Controls:** Multi-animation selector, playback controls (play/pause), and smooth timeline scrubbing for skeletal rigs.
35
+ - **Interactive Animation Controls:** Multi-animation selector, playback controls (play/pause), and smooth timeline scrubbing for animated hierarchies.
36
36
  - **Modular AI Prompt Generator:** Built-in UI with fine-grained feature toggles (Basic PBR, Auto Smooth, Animations, Extended PBR, Texture Baking) and persistent local settings to generate optimized prompts for LLMs.
37
37
  - **Image & Video Capture:**
38
38
  - **📷 PNG Snapshots:** Export high-resolution renders with a single click.
@@ -219,6 +219,7 @@ When asking an LLM (like Gemini) to generate OpenSCAD code, the extension automa
219
219
  - **Instant 3D Preview:** Injects a **"Preview 3D"** button on any OpenSCAD code block to compile and render the model in an embedded 3D viewer with grid, wireframe, and full-screen support.
220
220
  - **Visual Chat Feedback (📷):** Click the snapshot button inside the 3D preview window to capture a PNG snapshot of the model and **automatically paste it into the AI Studio chat input**, allowing Gemini to visually evaluate and fix geometry.
221
221
  - **Smart Prompt Injection:** Click the floating **"✨ SCAD"** button to open the configuration modal. Select your desired engine feature set (PBR, auto-smooth, animations, baking) to automatically generate and inject the prompt rules into your chat input.
222
+ - **Local Model Refinement:** Connect to your local `scad-serve` workspace directly from the prompt modal. Select an existing `.scad` file to automatically append its source code to your prompt as a reference, enabling seamless AI iteration and refinement of your existing local designs.
222
223
  - **Open in Scadify:** Click **"Edit"** in the preview window to immediately transfer the current script into the full standalone Scadify editor via compressed URL hash.
223
224
  - **Local Workspace Saving:** Directly save and overwrite models to your local directory when running `scad-serve`.
224
225
 
@@ -284,7 +285,11 @@ This repository includes an official **Godot 4.x Importer Addon** located in the
284
285
 
285
286
  The addon allows you to drag-and-drop `.scad` files directly into your Godot project. It uses this WASM compiler under the hood to transform scripts into 3D scenes automatically.
286
287
 
287
- - **Features:** Supports PBR Materials and Skeletal Animations inside the Godot Editor.
288
+ **🕹️ Play Web Demos (No Installation Required):**
289
+ Try prebuilt AI-generated Godot games directly in your browser: [https://iliagrigorevdev.github.io/scad-godot/](https://iliagrigorevdev.github.io/scad-godot/)
290
+
291
+ - **Features:** Supports PBR Materials and Hierarchical Node Animations inside the Godot Editor.
292
+ - **Examples:** Check out AI-generated game templates in the [`godot/examples`](./godot/examples) directory.
288
293
  - **License:** The Godot Addon is licensed under **MIT**.
289
294
  - **Setup:** Simply copy the `addons/scad_importer` folder to your project and enable it in Project Settings.
290
295
 
@@ -329,9 +334,9 @@ color(
329
334
  }
330
335
  ```
331
336
 
332
- ### 2. Skeletal Animations
337
+ ### 2. Hierarchical Node Animations (Rigid Parenting)
333
338
 
334
- Define hierarchical armatures, resting positions, and keyframe animations:
339
+ Define hierarchical armatures, resting positions, and keyframe animations for rigid parts:
335
340
 
336
341
  ```openscad
337
342
  anim_data = [
@@ -422,7 +427,7 @@ console.log(promptContext);
422
427
 
423
428
  Once connected, an AI assistant can use the server to execute the following loop:
424
429
 
425
- 1. **Retrieve Syntax Rules:** The assistant calls the `get_scad_prompt` tool to get the extended syntax rules for PBR materials, skeletal animations, and texture baking.
430
+ 1. **Retrieve Syntax Rules:** The assistant calls the `get_scad_prompt` tool to get the extended syntax rules for PBR materials, hierarchical node animations, and texture baking.
426
431
  2. **Generate Code:** The assistant writes the `.scad` script based on your design request.
427
432
  3. **Compile & Visually Inspect:** The assistant calls the `render_scad_model` tool to inspect rendered multi-angle frames and keyframes, fixing any errors before final export.
428
433
 
package/bin/scad-godot.js CHANGED
@@ -90,7 +90,7 @@ async function main() {
90
90
  console.error("");
91
91
  console.error("Example with JSON options:");
92
92
  console.error(
93
- ' scad-godot "Game description" \'{"animation": false, "bakeColors": true}\'',
93
+ ' scad-godot "Game description" \'{"animation": false, "bakeColors": true, "scadFiles": ["player.scad"]}\'',
94
94
  );
95
95
  process.exit(1);
96
96
  }
@@ -102,6 +102,7 @@ async function main() {
102
102
  clearcoat: false,
103
103
  sheen: false,
104
104
  iridescence: false,
105
+ scadFiles: [],
105
106
  };
106
107
 
107
108
  if (optionsStr) {
@@ -138,6 +139,9 @@ async function main() {
138
139
  process.exit(1);
139
140
  }
140
141
 
142
+ const hasUserScadFiles =
143
+ Array.isArray(options.scadFiles) && options.scadFiles.length > 0;
144
+
141
145
  // 4. Construct the Main Godot Prompt System Text (System Instructions)
142
146
  const systemPrompt = `You are an expert Godot 4 game developer and procedural 3D technical artist.
143
147
 
@@ -158,7 +162,7 @@ What to generate:
158
162
  * OpenSCAD -Y (Back) -> Godot +Z (Back)
159
163
  * OpenSCAD +Z (Up) -> Godot +Y (Up)
160
164
  DO NOT manually apply root rotations (e.g., \`rotate([90, 0, 0])\`) to compensate for Godot.
161
- - CRITICAL: You must use the custom OpenSCAD glTF extensions for PBR materials (e.g., \`roughness\`, \`metalness\`, \`emissive\`) and Skeletal Animations (\`armature()\`, \`bone()\`). The rules and syntax for these features are provided below:
165
+ - CRITICAL: You must use the custom OpenSCAD glTF extensions for PBR materials (e.g., \`roughness\`, \`metalness\`, \`emissive\`) and Hierarchical Node Animations (\`armature()\`, \`bone()\`). The rules and syntax for these features are provided below:
162
166
 
163
167
  === OPENSCAD SYNTAX RULES ===
164
168
  ${promptRules}
@@ -185,7 +189,11 @@ ${promptRules}
185
189
  - The script must embed and write:
186
190
  - Your generated \`.scad\` game assets.
187
191
  - Your generated Godot project files.
188
- - The exact source code of the provided \`addons/scad_importer/*\` files, placed in their correct respective paths.
192
+ - The exact source code of the provided \`addons/scad_importer/*\` files, placed in their correct respective paths.${
193
+ hasUserScadFiles
194
+ ? "\n - The exact source code of the provided user `.scad` files, placed in the appropriate project folders."
195
+ : ""
196
+ }
189
197
  - Ensure all string file contents inside the Node.js script are properly escaped.`;
190
198
 
191
199
  // 5. Gather Addon Files content
@@ -229,6 +237,24 @@ ${promptRules}
229
237
  }
230
238
  }
231
239
 
240
+ if (hasUserScadFiles) {
241
+ systemClipboardOutput += `=== USER PROVIDED OPENSCAD FILES ===\n`;
242
+ systemClipboardOutput += `The following .scad files are provided as reference or base assets. You MUST embed and write them into the generated project, modifying them if necessary to fit the game logic.\n\n`;
243
+ for (const file of options.scadFiles) {
244
+ try {
245
+ const content = fs.readFileSync(file, "utf-8").replace(/\r\n/g, "\n");
246
+ const relativePath = path.isAbsolute(file)
247
+ ? path.relative(process.cwd(), file).replace(/\\/g, "/")
248
+ : file.replace(/\\/g, "/");
249
+ systemClipboardOutput += `### ${relativePath}\n---\n\`\`\`openscad\n${content}\n\`\`\`\n\n`;
250
+ } catch (e) {
251
+ console.error(
252
+ `Warning: Skipping user SCAD file '${file}'. It is not a readable file.`,
253
+ );
254
+ }
255
+ }
256
+ }
257
+
232
258
  systemClipboardOutput = systemClipboardOutput.trimEnd() + "\n";
233
259
 
234
260
  // 7. Format the input request output
package/bin/scad-web.js CHANGED
@@ -137,7 +137,7 @@ What to generate:
137
137
  1. 3D Web Assets (.scad):
138
138
  - Generate procedural 3D models for the web app using OpenSCAD.
139
139
  - CRITICAL: The SCAD to glTF converter automatically converts OpenSCAD's Z-up coordinate system to the standard glTF Y-up coordinate system. Design your models naturally in OpenSCAD.
140
- - CRITICAL: You must use the custom OpenSCAD glTF extensions for PBR materials (e.g., \`roughness\`, \`metalness\`, \`emissive\`) and Skeletal Animations (\`armature()\`, \`bone()\`). The rules and syntax for these features are provided below:
140
+ - CRITICAL: You must use the custom OpenSCAD glTF extensions for PBR materials (e.g., \`roughness\`, \`metalness\`, \`emissive\`) and Hierarchical Node Animations (\`armature()\`, \`bone()\`). The rules and syntax for these features are provided below:
141
141
 
142
142
  === OPENSCAD SYNTAX RULES ===
143
143
  ${promptRules}