Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Render workspace: first basic delivery to main (#6050)

seluneb7b25f9e2be4
diff --git a/.config/nextest.toml b/.config/nextest.toml
index 619a0b6be2..7bb332efde 100644
--- a/.config/nextest.toml
+++ b/.config/nextest.toml
@@ -70,6 +70,16 @@ filter = """
"""
priority = 100
+# Each nextest test has its own process/device. Concurrent cold lavapipe path
+# compiles contend for CPU and can exhaust the 600 s pipeline setup budget.
+# Serialize this module per CI shard; other tests retain their normal parallelism.
+[test-groups.gpu-path]
+max-threads = 1
+
+[[profile.ci.overrides]]
+filter = "package(=solidcraft-gpu) & test(/^path::/)"
+test-group = "gpu-path"
+
# Full local validation opts into its own scheduling policy. Keep GitHub CI's
# worker reservation and slow-test priorities above independent of this runner.
[profile.local-ci]
diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md
index a9f62fd8cc..e1a43341bf 100644
--- a/ATTRIBUTION.md
+++ b/ATTRIBUTION.md
@@ -15,8 +15,20 @@ Editable drawing code, native projects and shipped exports are collected under `
| File | Author | Source | Licence |
|---|---|---|---|
| examples/chebyshev-motion-trace.json | SolidCraft contributors | Original parametric Chebyshev lambda mechanism and associative-trace demo, constructed from analytic circle intersections; classical link proportions documented at https://doi.org/10.1002/rcs.70095; no external CAD geometry or artwork | MIT OR Apache-2.0 |
+| examples/material-card.json | SolidCraft contributors | original analytic box and explicitly synthetic engineering card; invented illustrative constants, no external material dataset | MIT OR Apache-2.0 |
+| examples/studio/author_sweep.py | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/author_scene.py | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/materials.json | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-exploded-sweep.json | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-exploded-render.json | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-exploded.json | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/stage1-sweep.json | SolidCraft contributors | original tangent circular-arc CAD cyclorama; no external assets | MIT OR Apache-2.0 |
+| examples/studio/stage1.json | SolidCraft contributors | original editable CAD studio scene; no imported geometry or external image assets | MIT OR Apache-2.0 |
+| examples/studio/stage1-render.json | SolidCraft contributors | original studio camera and lighting parameters | MIT OR Apache-2.0 |
| examples/render-studio.json | SolidCraft contributors | original procedural box/cylinder enclosure script for the integrated Render workspace | MIT OR Apache-2.0 |
| examples/render-opaque-studio.json | SolidCraft contributors | original procedural sphere study varying opaque metal fraction and roughness independently; no external assets or engineering data | MIT OR Apache-2.0 |
+| examples/render-path-studio.json | SolidCraft contributors | original procedural opaque enclosure, teal insert and metal fasteners for progressive rendering; no imported models | MIT OR Apache-2.0 |
+| crates/gpu/src/path/path.wgsl | SolidCraft contributors | original software BVH traversal and path integration using the existing SolidCraft surface/studio equations; no external shader source | MIT OR Apache-2.0 |
| crates/gpu/src/pbr.rs | SolidCraft contributors | original WGSL translation of SolidCraft's opaque surface and fixed studio reference, embedded as Rust source; no external shader code | MIT OR Apache-2.0 |
| assets/icons/app/macos/source/SolidCraft.icon/icon.json | SolidCraft contributors | approved Icon Composer composition and appearance settings for the original SolidCraft artwork | MIT OR Apache-2.0 |
| assets/icons/app/macos/source/SolidCraft.icon/Assets/02-grid.svg | SolidCraft contributors | original perspective grid with elliptical radial alpha, exported from VectorCraft | MIT OR Apache-2.0 |
@@ -98,6 +110,7 @@ Editable drawing code, native projects and shipped exports are collected under `
| tests/oracle/63-hinge-knuckle/reference.stl | SolidCraft contributors | triangulation of our own recipe (tests/oracle/63-hinge-knuckle/recipe.json) built with FreeCAD as an external tool by tools/freecad-oracle | MIT OR Apache-2.0 |
| tests/oracle/65-sketch-gear-tooth/reference.stl | SolidCraft contributors | triangulation of our own recipe (tests/oracle/65-sketch-gear-tooth/recipe.json) built with FreeCAD as an external tool by tools/freecad-oracle | MIT OR Apache-2.0 |
| assets/appearances/library.rs | SolidCraft contributors | Original SolidCraft resource data or drawing code, collected without redesign | MIT OR Apache-2.0 |
+| assets/appearances/starter_pack.rs | SolidCraft contributors | original illustrative optical recipes, authored scalar values and future procedural resource descriptors; no measured or external material dataset | MIT OR Apache-2.0 |
| assets/fonts/biz-udp-gothic/OFL.txt | The BIZ UDGothic Project Authors | Unmodified accompanying font licence | SIL OFL 1.1 |
| assets/fonts/ibm-plex-mono/OFL.txt | IBM Corp. | Unmodified accompanying font licence | SIL OFL 1.1 |
| assets/fonts/ibm-plex-sans/OFL.txt | IBM Corp. | Unmodified accompanying font licence | SIL OFL 1.1 |
@@ -546,6 +559,12 @@ copied into SolidCraft.
| Directory | Source | Licence | Changes |
|---|---|---|---|
+| examples/studio/author_sweep.py | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/author_scene.py | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/materials.json | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-exploded-sweep.json | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-exploded-render.json | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-exploded.json | SolidCraft contributors | original editable CAD scene and authoring metadata; no external assets | MIT OR Apache-2.0 |
| vendor/truck-meshalgo | truck-meshalgo 0.4.0, https://github.com/ricosjp/truck (RICOS Co. Ltd.) | Apache-2.0 | meshing: bounded parameter searches, collapsed-boundary projection, subdivision and provisional fixed-grid previews (vendor/README.md) |
| vendor/truck-stepio | truck-stepio 0.3.0, https://github.com/ricosjp/truck (RICOS Co. Ltd.) | Apache-2.0 | STEP writer: intersection-curve surfaces written at unique ids (vendor/README.md) |
| vendor/truck-shapeops | truck-shapeops 0.4.0, https://github.com/ricosjp/truck (RICOS Co. Ltd.) | Apache-2.0 | robust meshing and nearest-parameter fallback in booleans; degenerate intersection-curve rejection; face and edge history of booleans; trace macro; corner choice at vertices several intersection curves end on; reuse of an operand's meshes (vendor/README.md) |
@@ -564,3 +583,75 @@ A frame whose meshes the GPU refuses to stage (device lost or out of memory) is
skipped with a warning instead of panicking (#1469).
Paint callbacks are prepared only after a drawable is acquired, so a skipped
surface frame cannot strand cached meshes without their GPU initialization.
+
+## Runtime studio lighting mathematics
+
+`crates/gpu/src/path/path.wgsl` implements the power-heuristic estimator from the
+mathematical description in [PBRT fourth edition, section 13.4](https://pbr-book.org/4ed/Light_Transport_I_Surface_Reflection/A_Better_Path_Tracer).
+No PBRT code or assets were copied. `crates/render/src/job/lighting.rs` evaluates
+[Krzysztof Narkowicz's published 2016 ACES rational fit](https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/)
+using its published coefficients (author licenses the fit under CC0/MIT).
+These original implementations are under SolidCraft's MIT OR Apache-2.0 licence.
+
+## Original coffee framing variant
+
+| File | Author | Provenance | Licence |
+|---|---|---|---|
+| examples/studio/author_coffee_framing.py | SolidCraft contributors | original editable composition, camera and documentation; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-framing.json | SolidCraft contributors | original editable composition, camera and documentation; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-framing-sweep.json | SolidCraft contributors | original editable composition, camera and documentation; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-framing-render.json | SolidCraft contributors | original editable composition, camera and documentation; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-framing.md | SolidCraft contributors | original editable composition, camera and documentation; no external assets | MIT OR Apache-2.0 |
+
+## Original cylindrical coffee housing variant
+
+| File | Author | Provenance | Licence |
+|---|---|---|---|
+| examples/studio/author_coffee_cylinder.py | SolidCraft contributors | original parametric cylindrical CAD construction and editable command recipes; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-cylinder.json | SolidCraft contributors | original cylindrical housing on the original exploded coffee composition; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-cylinder-sweep.json | SolidCraft contributors | original cylindrical housing and continuous CAD cyclorama; no external assets | MIT OR Apache-2.0 |
+| examples/studio/coffee-cylinder-render.json | SolidCraft contributors | original camera, studio lighting and optical settings retained from the framing variant | MIT OR Apache-2.0 |
+| examples/studio/coffee-cylinder.md | SolidCraft contributors | original dimensional recipe, provenance and validation limitations | MIT OR Apache-2.0 |
+
+## Runtime environment sampling
+
+`crates/render/src/lighting/environment.rs` and the environment/sun portions of
+`crates/gpu/src/path/path.wgsl` are original SolidCraft implementations of
+solid-angle importance sampling and MIS, informed by the mathematical description
+in [PBRT fourth edition, sections 12.5](https://pbr-book.org/4ed/Light_Sources/Infinite_Area_Lights)
+and [13.4](https://pbr-book.org/4ed/Light_Transport_I_Surface_Reflection/A_Better_Path_Tracer).
+The procedural gradient and inline RGBE test fixtures are original mathematical
+colours, not downloaded imagery. No third-party environment images or shader code
+are included. Licence: MIT OR Apache-2.0.
+
+## Original tumbler showcase assets
+
+The CAD room, tumblers, window opening, wood/weave patterns and RGBE sky below
+are original SolidCraft contributor work. No third-party scene, photograph, HDRI,
+texture, or AI-generated artwork was used. Python authoring sources are included.
+All listed files use the repository MIT OR Apache-2.0 licence.
+
+| File | Source / author | Use | License |
+| --- | --- | --- | --- |
+| examples/studio/author_showcase.py | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/author_tumblers.py | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/textures/ATTRIBUTION.md | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/textures/author_textures.py | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/textures/environment-manifest.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/textures/manifest.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-hdr-textures-blocked-render.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-hdr-textures-render.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-materials.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-render.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-sun-render.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-sun-textures-blocked-render.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-sun-textures-render.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-sun.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-textures-blocked-render.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers-textures-render.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+| examples/studio/tumblers.json | Original SolidCraft contributors | Editable scene / runtime resource / reproducible authoring metadata | MIT OR Apache-2.0 |
+
+The original studio generators produce local ignored PNG maps and an RGBE gradient.
+Generated image bytes are not source assets; their authorship, licences and expected
+hashes are documented under `examples/studio/textures`. Rendered evidence belongs
+on the results branch. No photographs, scans or external image assets are included.
diff --git a/Cargo.lock b/Cargo.lock
index c95c2c52ef..1a0e19b408 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4312,9 +4312,11 @@ dependencies = [
name = "solidcraft-gpu"
version = "0.21.0"
dependencies = [
+ "image",
"log",
"naga",
"pollster 0.4.0",
+ "robust",
"serde",
"serde_json",
"solidcraft-engine",
diff --git a/ROADMAP.md b/ROADMAP.md
index 01168c25b2..33869bdc91 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -143,6 +143,12 @@ completed drawings publish atomically. The browser still exports synchronously.
## Render foundation
+- Original starter appearances (#1722): 34 opaque recipes through existing commands, with six explicitly unavailable glass recipes and preserved legacy looks; see [the contract](docs/render-starter-appearances.md).
+
+- Bounded linear film accumulation (#1696) supplies caller-admitted mean/variance storage and complete-pass views; actual progressive consumers remain separate. See [the film contract](docs/render-film.md).
+
+- Definition-local visual mapping (#1214) supplies a bounded numerical frame, physical repeat coordinates and a deterministic one-time grain-axis suggestion. It adds no saved record or texture consumer; see [the mapping contract](docs/render-visual-mapping.md).
+
- Explicit texture normalization (#1218) produces completed float RGBA with
role-aware linear color/data semantics, bounded matrix/TRC ICC conversion and
opt-in EXIF orientation. It retains high-precision raw samples and records lossy
diff --git a/apps/solidcraft-cli/examples/studio_evidence.rs b/apps/solidcraft-cli/examples/studio_evidence.rs
new file mode 100644
index 0000000000..ef01e79aec
--- /dev/null
+++ b/apps/solidcraft-cli/examples/studio_evidence.rs
@@ -0,0 +1,102 @@
+//! Reproducible evidence through the production command/job interfaces.
+//! Usage: studio_evidence RECIPE.json RENDER-PARAMS.json OUTPUT.png
+//! Writes the editable design, command timings and actual adapter/job metadata beside PNG.
+use serde_json::{Value, json};
+use solidcraft_engine::{
+ Session,
+ render::job::{CpuHost, ErrorCode, JobId, Phase},
+};
+use std::{
+ io::Read,
+ path::Path,
+ time::{Duration, Instant},
+};
+
+fn read_json(path: &str) -> Result<Value, String> {
+ let mut bytes = Vec::new();
+ std::fs::File::open(path).map_err(|e| format!("{path}: {e}"))?.take(16_777_217).read_to_end(&mut bytes).map_err(|e| e.to_string())?;
+ if bytes.len() > 16_777_216 {
+ return Err("evidence input exceeds 16 MiB".into());
+ }
+ serde_json::from_slice(&bytes).map_err(|e| format!("{path}: {e}"))
+}
+
+fn run() -> Result<(), String> {
+ let args: Vec<String> = std::env::args().skip(1).collect();
+ let [recipe_path, params_path, output_path] = args.as_slice() else {
+ return Err("usage: studio_evidence RECIPE.json RENDER-PARAMS.json OUTPUT.png".into());
+ };
+ let output = Path::new(output_path);
+ if !output.extension().is_some_and(|e| e.eq_ignore_ascii_case("png")) {
+ return Err("output must have a .png extension".into());
+ }
+ let recipe = read_json(recipe_path)?;
+ let params = read_json(params_path)?;
+ let mut session = Session::default();
+ eprintln!("Generating original CAD scene from {recipe_path}");
+ let generation_start = Instant::now();
+ let (commands, command_timings) = session.run_script_timed(&recipe, false).map_err(|e| e.to_string())?;
+ let generation_seconds = generation_start.elapsed().as_secs_f64();
+ let design_path = output.with_extension("solidcraft");
+ session.execute("file.save_as", &json!({"path":design_path})).map_err(|e| e.to_string())?;
+ let scene = solidcraft_engine::product_scene::extract(&session).map_err(|e| e.to_string())?;
+ let bodies: Vec<Value> = scene
+ .meshes
+ .iter()
+ .map(|mesh| json!({"name":mesh.name,"vertices":mesh.mesh.positions.len(),"triangles":mesh.mesh.triangles.len()}))
+ .collect();
+ drop(scene);
+
+ let policy = solidcraft_gpu::select::Policy::from_env().map_err(|e| e.to_string())?;
+ let (adapter, adapter_report) = solidcraft_gpu::select::pick(policy).ok_or("no adapter satisfies the requested GPU policy")?;
+ let host_start = Instant::now();
+ session.set_render_job_host(Some(CpuHost::for_platform().map_err(|e| e.to_string())?)).map_err(|e| e.to_string())?;
+ session.register_render_job_host(solidcraft_gpu::path::host_on_adapter(&adapter).map_err(|e| e.to_string())?).map_err(|e| e.to_string())?;
+ let host_seconds = host_start.elapsed().as_secs_f64();
+ let preflight = session.execute("render.preflight", &params).map_err(|e| e.to_string())?;
+ let start = Instant::now();
+ let started = session.execute("render.start", &params).map_err(|e| e.to_string())?;
+ let id: JobId = serde_json::from_value(started.get("job").cloned().ok_or("missing job id")?).map_err(|e| e.to_string())?;
+ let handle = session.render_job_handle(id).map_err(|e| e.to_string())?;
+ eprintln!("Rendering through production gpu-path host: {adapter_report:?}");
+ let status = loop {
+ match handle.wait_timeout(Duration::from_secs(10)) {
+ Ok(status) => break status,
+ Err(error) if error.code == ErrorCode::TimedOut && start.elapsed() < Duration::from_secs(3600) => {
+ let status = handle.status().map_err(|e| e.to_string())?;
+ eprintln!(
+ "Render progress: {:?} {}/{} after {:.1}s",
+ status.progress.phase,
+ status.progress.done,
+ status.progress.total,
+ start.elapsed().as_secs_f64()
+ );
+ }
+ Err(error) => {
+ let _ = handle.cancel();
+ return Err(error.to_string());
+ }
+ }
+ };
+ let render_and_encode_seconds = start.elapsed().as_secs_f64();
+ if status.progress.phase != Phase::Completed {
+ return Err(status.error.map_or_else(|| "render did not complete".into(), |e| e.to_string()));
+ }
+ let exported = session.execute("render.export", &json!({"job":id,"path":output_path,"overwrite":true})).map_err(|e| e.to_string())?;
+ let report = json!({
+ "recipe":recipe_path,"render_params":params,"adapter":adapter_report,
+ "environment":{"SOLIDCRAFT_GPU":std::env::var("SOLIDCRAFT_GPU").ok(),"WGPU_BACKEND":std::env::var("WGPU_BACKEND").ok()},
+ "cad_generation_seconds":generation_seconds,"gpu_host_setup_seconds":host_seconds,
+ "render_and_encode_seconds":render_and_encode_seconds,
+ "timing_scope":"wall time from render.start through completed PNG encoding; includes job preparation and readback, excludes CAD generation and initial GPU pipeline setup",
+ "bodies":bodies,"commands":commands,"command_timings":command_timings,
+ "preflight":preflight,"export":exported,"editable_design":design_path
+ });
+ std::fs::write(output.with_extension("json"), serde_json::to_vec_pretty(&report).map_err(|e| e.to_string())?).map_err(|e| e.to_string())?;
+ println!("{}", serde_json::to_string_pretty(&report).map_err(|e| e.to_string())?);
+ Ok(())
+}
+
+fn main() -> Result<(), String> {
+ run()
+}
diff --git a/apps/solidcraft-cli/src/main.rs b/apps/solidcraft-cli/src/main.rs
index f342fefc3b..0d46ee1071 100644
--- a/apps/solidcraft-cli/src/main.rs
+++ b/apps/solidcraft-cli/src/main.rs
@@ -69,7 +69,7 @@ const USAGE_BENCH_ASSISTANT: &str = " solidcraft-cli bench-assistant --connect
/// `snapshot`'s lines in the usage.
const USAGE_SNAPSHOT: &str = " solidcraft-cli snapshot <script|design> [--in design.solidcraft|part.step] --out shot.png [--width W] [--height H] [--view NAME | --camera JSON] [--no-grid] [--no-axes]\n [--body NAME:opacity=0.3,color=#rrggbb]... [--tool NAME]... [--section z=27]\n solidcraft-cli snapshot --in <design.solidcraft|part.step> --out shot.png ...\n (as with run, --in starts from a design and the script runs on top of it; an option snapshot doesn't take is an error;\n --view: iso, front, back, top, bottom, left, right, or the name of a view saved in the design with view.save;\n --camera: {target: [x,y,z], yaw, pitch, distance, fov?} in mm and radians, as the MCP screenshot takes it (docs/mcp.md);\n --no-grid and --no-axes leave the ground grid (on Z 0) and the origin's axes out of the picture;\n --body: how one body is drawn, as appearance.assign takes it: opacity 0-1 (below 1 is see-through, so what is inside\n it shows) and color #rrggbb, either or both, once per body;\n --tool: draw this body solid in the tool colour and every other body see-through, so a cut's or a join's tool body\n is visible inside the material it meets; a later --body overrides it;\n --section: cut the model as inspect.section does, so the inside shows: z=27 (the plane through that world\n coordinate, keeping the smaller side), add ,flip to keep the other side, or XY, XZ, YZ, or its own JSON)\n";
/// `render`'s lines in the usage.
-const USAGE_RENDER: &str = " solidcraft-cli render <script|design> --out image.png [--setup NAME] [--width W] [--height H] [--transparent] [--overwrite] [--timeout SECONDS]\n";
+const USAGE_RENDER: &str = " solidcraft-cli render <script|design> --out image.png [--setup NAME] [--width W] [--height H] [--transparent] [--overwrite] [--timeout SECONDS]\n [--progressive] [--samples N] [--max-depth N] [--seed N] [--exposure EV] [--lighting FILE.json] [--environment FILE.json] [--tone-map reinhard|aces_fitted]\n";
/// `exec`'s lines in the usage.
const USAGE_EXEC: &str = " solidcraft-cli exec <command> [json-params]\n";
/// `commands`'s lines in the usage.
diff --git a/apps/solidcraft-cli/src/render.rs b/apps/solidcraft-cli/src/render.rs
index 0d32ad9156..ed13e1e12e 100644
--- a/apps/solidcraft-cli/src/render.rs
+++ b/apps/solidcraft-cli/src/render.rs
@@ -11,15 +11,25 @@ pub fn run(args: &[String]) -> Result<(), String> {
let mut setup = None;
let mut width = None;
let mut height = None;
+ let mut progressive = false;
+ let mut samples = None;
+ let mut max_depth = None;
+ let mut seed = None;
+ let mut exposure = None;
+ let mut lighting = None;
+ let mut tone_map = None;
+ let mut environment = None;
let mut transparent = false;
let mut overwrite = false;
let mut timeout = 120u64;
let mut i = 1;
while let Some(arg) = args.get(i) {
match arg.as_str() {
+ "--progressive" => progressive = true,
"--transparent" => transparent = true,
"--overwrite" => overwrite = true,
- "--out" | "--setup" | "--width" | "--height" | "--timeout" => {
+ "--out" | "--setup" | "--width" | "--height" | "--timeout" | "--samples" | "--max-depth" | "--seed" | "--exposure" | "--lighting"
+ | "--tone-map" | "--environment" => {
i += 1;
let value = args.get(i).ok_or_else(|| format!("missing value for {arg}"))?;
match arg.as_str() {
@@ -27,6 +37,26 @@ pub fn run(args: &[String]) -> Result<(), String> {
"--setup" => setup = Some(value.clone()),
"--width" => width = Some(value.parse::<u32>().map_err(|_| "invalid width")?),
"--height" => height = Some(value.parse::<u32>().map_err(|_| "invalid height")?),
+ "--samples" => samples = Some(value.parse::<u32>().map_err(|_| "invalid samples")?),
+ "--max-depth" => max_depth = Some(value.parse::<u32>().map_err(|_| "invalid depth")?),
+ "--seed" => seed = Some(value.parse::<u32>().map_err(|_| "invalid seed")?),
+ "--exposure" => exposure = Some(value.parse::<f64>().map_err(|_| "invalid exposure")?),
+ "--environment" => {
+ let text =
+ solidcraft_engine::io::vfs::read_to_string(value, 65536).map_err(|e| format!("could not read environment: {e}"))?;
+ environment = Some(serde_json::from_str::<serde_json::Value>(&text).map_err(|e| e.to_string())?);
+ }
+ "--lighting" => {
+ let text = solidcraft_engine::io::vfs::read_to_string(value, 65536).map_err(|e| format!("could not read lighting: {e}"))?;
+ lighting = Some(serde_json::from_str::<solidcraft_engine::render::job::StudioLighting>(&text).map_err(|e| e.to_string())?);
+ }
+ "--tone-map" => {
+ tone_map = Some(match value.as_str() {
+ "reinhard" => solidcraft_engine::render::job::ToneMap::Reinhard,
+ "aces_fitted" => solidcraft_engine::render::job::ToneMap::AcesFitted,
+ _ => return Err("tone-map must be reinhard or aces_fitted".into()),
+ })
+ }
_ => timeout = value.parse::<u64>().map_err(|_| "invalid timeout")?,
}
}
@@ -40,6 +70,9 @@ pub fn run(args: &[String]) -> Result<(), String> {
let out = out.ok_or("render requires --out FILE.png")?;
let mut session = crate::load(input)?;
session.set_render_job_host(Some(CpuHost::for_platform().map_err(|e| e.to_string())?)).map_err(|e| e.to_string())?;
+ if progressive {
+ session.register_render_job_host(solidcraft_gpu::path::host().map_err(|e| e.to_string())?).map_err(|e| e.to_string())?;
+ }
session.execute("render.scene", &json!({})).map_err(|e| e.to_string())?;
let mut settings = if let Some(name) = setup {
session.doc.render.setups.get(&name).cloned().ok_or("no saved render setup with that name")?
@@ -58,7 +91,10 @@ pub fn run(args: &[String]) -> Result<(), String> {
if let Some(height) = height {
settings.height = height;
}
- let params = json!({"settings":settings,"transparent_background":transparent});
+ if let Some(exposure) = exposure {
+ settings.exposure_ev = exposure;
+ }
+ let params = json!({"settings":settings,"transparent_background":transparent,"progressive":progressive,"samples":samples,"max_depth":max_depth,"seed":seed,"lighting":lighting,"tone_map":tone_map,"environment":environment});
let preflight = session.execute("render.preflight", &params).map_err(|e| e.to_string())?;
let started = session.execute("render.start", &params).map_err(|e| e.to_string())?;
let id: JobId = serde_json::from_value(started["job"].clone()).map_err(|e| e.to_string())?;
diff --git a/apps/solidcraft-cli/tests/help_output.rs b/apps/solidcraft-cli/tests/help_output.rs
index 1762f363bc..4b86bdd5c9 100644
--- a/apps/solidcraft-cli/tests/help_output.rs
+++ b/apps/solidcraft-cli/tests/help_output.rs
@@ -144,3 +144,16 @@ fn fuzz_refuses_an_argument_it_does_not_take() {
assert!(stderr.contains(arg), "`fuzz {arg}`: {stderr}");
}
}
+
+#[test]
+fn render_help_keeps_the_registered_gpu_request_controls() {
+ for args in [vec!["--help"], vec!["render", "--help"]] {
+ let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).args(&args).output().unwrap();
+ assert!(output.status.success(), "{args:?}: {}", String::from_utf8_lossy(&output.stderr));
+ assert!(output.stderr.is_empty());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ for flag in ["--progressive", "--samples", "--max-depth", "--seed", "--exposure", "--lighting", "--environment", "--tone-map"] {
+ assert!(stdout.contains(flag), "{args:?} lost {flag}: {stdout}");
+ }
+ }
+}
diff --git a/assets/appearances/starter_pack.rs b/assets/appearances/starter_pack.rs
new file mode 100644
index 0000000000..29ee53fc45
--- /dev/null
+++ b/assets/appearances/starter_pack.rs
@@ -0,0 +1,292 @@
+//! Original starter visual data, MIT OR Apache-2.0. No external material library.
+use crate::appearance_pack::{Category, GlassBoundary, GlassRecipe, OpaqueRecipe, TextureAxis, TextureRecipe, VisualPreset};
+
+const WOOD: &str = "Uniform opaque preview only; grain resources/mapping are not applied";
+const SOLAR: &str = "Uniform opaque preview only; no cell grid, busbars, electricity or efficiency claim";
+const REGOLITH: &str = "Uniform opaque preview only; no granular displacement or measured lunar optical data";
+const OPAQUE: &str = "Illustrative opaque isotropic PBR; no measured alloy, polymer or engineering properties";
+
+const fn look(color: [u8; 3], metallic: f64, roughness: f64, dielectric_ior: f64) -> OpaqueRecipe {
+ OpaqueRecipe { color, metallic, roughness, dielectric_ior }
+}
+const fn maps(id: &'static str, repeat_mm: [f64; 2], grain: bool) -> Option<TextureRecipe> {
+ Some(TextureRecipe { id, repeat_mm, grain_axis: if grain { Some(TextureAxis::V) } else { None } })
+}
+const fn glass(transmission_linear_rgb: [f64; 3], ior: f64, reference_path_mm: f64, boundary: GlassBoundary) -> GlassRecipe {
+ GlassRecipe { transmission_linear_rgb, dielectric_ior: ior, reference_path_mm, boundary }
+}
+
+pub const STARTER_PACK: [VisualPreset; 40] = [
+ VisualPreset::opaque(
+ "starter.wood.oak-honey",
+ "Wood - Honey Oak Uniform Preview",
+ Category::Wood,
+ look([190, 145, 88], 0.0, 0.64, 1.5),
+ WOOD,
+ maps("starter.wood.oak-honey.maps-v1", [120.0, 240.0], true),
+ ),
+ VisualPreset::opaque(
+ "starter.wood.oak-smoked",
+ "Wood - Smoked Oak Uniform Preview",
+ Category::Wood,
+ look([91, 72, 55], 0.0, 0.68, 1.5),
+ WOOD,
+ maps("starter.wood.oak-smoked.maps-v1", [120.0, 240.0], true),
+ ),
+ VisualPreset::opaque(
+ "starter.wood.walnut-dark",
+ "Wood - Dark Walnut Uniform Preview",
+ Category::Wood,
+ look([99, 66, 43], 0.0, 0.60, 1.5),
+ WOOD,
+ maps("starter.wood.walnut-dark.maps-v1", [100.0, 220.0], true),
+ ),
+ VisualPreset::opaque(
+ "starter.wood.maple-light",
+ "Wood - Light Maple Uniform Preview",
+ Category::Wood,
+ look([221, 192, 141], 0.0, 0.57, 1.5),
+ WOOD,
+ maps("starter.wood.maple-light.maps-v1", [100.0, 200.0], true),
+ ),
+ VisualPreset::opaque(
+ "starter.wood.cherry-warm",
+ "Wood - Warm Cherry Uniform Preview",
+ Category::Wood,
+ look([164, 99, 65], 0.0, 0.58, 1.5),
+ WOOD,
+ maps("starter.wood.cherry-warm.maps-v1", [110.0, 220.0], true),
+ ),
+ VisualPreset::opaque(
+ "starter.wood.ash-pale",
+ "Wood - Pale Ash Uniform Preview",
+ Category::Wood,
+ look([209, 186, 146], 0.0, 0.70, 1.5),
+ WOOD,
+ maps("starter.wood.ash-pale.maps-v1", [120.0, 260.0], true),
+ ),
+ VisualPreset::opaque(
+ "starter.wood.birch-cream",
+ "Wood - Cream Birch Uniform Preview",
+ Category::Wood,
+ look([228, 206, 163], 0.0, 0.63, 1.5),
+ WOOD,
+ maps("starter.wood.birch-cream.maps-v1", [100.0, 200.0], true),
+ ),
+ VisualPreset::opaque(
+ "starter.wood.teak-golden",
+ "Wood - Golden Teak Uniform Preview",
+ Category::Wood,
+ look([167, 122, 66], 0.0, 0.61, 1.5),
+ WOOD,
+ maps("starter.wood.teak-golden.maps-v1", [110.0, 250.0], true),
+ ),
+ VisualPreset::opaque(
+ "starter.metal.carbon-steel-polished",
+ "Metal - Polished Carbon Steel",
+ Category::Metal,
+ look([161, 166, 173], 1.0, 0.16, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.stainless-soft-satin",
+ "Metal - Soft Satin Stainless",
+ Category::Metal,
+ look([187, 193, 201], 1.0, 0.36, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.aluminum-bead-blast",
+ "Metal - Bead Blast Aluminum",
+ Category::Metal,
+ look([195, 201, 210], 1.0, 0.58, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.aluminum-silver-polish",
+ "Metal - Silver Polish Aluminum",
+ Category::Metal,
+ look([218, 224, 232], 1.0, 0.13, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.copper-aged-warm",
+ "Metal - Warm Aged Copper",
+ Category::Metal,
+ look([171, 95, 57], 1.0, 0.48, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.brass-champagne",
+ "Metal - Champagne Satin Brass",
+ Category::Metal,
+ look([205, 173, 102], 1.0, 0.32, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.bronze-dark-cast",
+ "Metal - Dark Cast Bronze",
+ Category::Metal,
+ look([133, 95, 58], 1.0, 0.66, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.titanium-matte",
+ "Metal - Matte Gray Titanium",
+ Category::Metal,
+ look([147, 149, 157], 1.0, 0.53, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.gold-warm",
+ "Metal - Warm Reflective Gold",
+ Category::Metal,
+ look([235, 190, 82], 1.0, 0.18, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.metal.silver-cool",
+ "Metal - Cool Reflective Silver",
+ Category::Metal,
+ look([225, 230, 237], 1.0, 0.12, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.plastic.abs-charcoal",
+ "Plastic - Charcoal ABS",
+ Category::Plastic,
+ look([43, 45, 48], 0.0, 0.44, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.plastic.abs-warm-white",
+ "Plastic - Warm White ABS",
+ Category::Plastic,
+ look([232, 229, 220], 0.0, 0.40, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque("starter.plastic.pla-coral", "Plastic - Coral PLA", Category::Plastic, look([218, 99, 83], 0.0, 0.43, 1.5), OPAQUE, None),
+ VisualPreset::opaque(
+ "starter.plastic.petg-cyan-opaque",
+ "Plastic - Opaque Cyan PETG",
+ Category::Plastic,
+ look([36, 148, 167], 0.0, 0.29, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.plastic.nylon-ivory",
+ "Plastic - Ivory Nylon",
+ Category::Plastic,
+ look([220, 213, 190], 0.0, 0.62, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.plastic.pc-graphite-opaque",
+ "Plastic - Opaque Graphite PC",
+ Category::Plastic,
+ look([70, 76, 84], 0.0, 0.27, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.plastic.hdpe-natural-opaque",
+ "Plastic - Opaque Natural HDPE",
+ Category::Plastic,
+ look([221, 222, 207], 0.0, 0.48, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque("starter.plastic.pom-black", "Plastic - Black POM", Category::Plastic, look([29, 31, 35], 0.0, 0.32, 1.5), OPAQUE, None),
+ VisualPreset::opaque(
+ "starter.plastic.tpu-matte-black",
+ "Plastic - Matte Black TPU",
+ Category::Plastic,
+ look([31, 30, 32], 0.0, 0.83, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::opaque(
+ "starter.plastic.peek-amber-opaque",
+ "Plastic - Opaque Amber PEEK",
+ Category::Plastic,
+ look([157, 119, 62], 0.0, 0.51, 1.5),
+ OPAQUE,
+ None,
+ ),
+ VisualPreset::glass(
+ "starter.glass.clear-soda-lime",
+ "Glass Recipe - Clear Soda Lime",
+ glass([0.92, 0.98, 0.96], 1.52, 3.0, GlassBoundary::Closed),
+ ),
+ VisualPreset::glass("starter.glass.low-iron-clear", "Glass Recipe - Low Iron Clear", glass([0.98, 0.99, 1.0], 1.50, 4.0, GlassBoundary::Closed)),
+ VisualPreset::glass("starter.glass.smoky-neutral", "Glass Recipe - Smoky Neutral", glass([0.35, 0.38, 0.42], 1.52, 3.0, GlassBoundary::Closed)),
+ VisualPreset::glass("starter.glass.amber-tint", "Glass Recipe - Amber Tint", glass([0.84, 0.38, 0.08], 1.51, 3.0, GlassBoundary::Closed)),
+ VisualPreset::glass("starter.glass.cobalt-blue", "Glass Recipe - Cobalt Blue", glass([0.06, 0.14, 0.76], 1.53, 3.0, GlassBoundary::Closed)),
+ VisualPreset::glass(
+ "starter.glass.thin-clear",
+ "Glass Recipe - Thin Clear Sheet",
+ glass([0.95, 0.98, 0.99], 1.50, 2.0, GlassBoundary::Thin { thickness_mm: 2.0 }),
+ ),
+ VisualPreset::opaque(
+ "starter.solar.mono-blue",
+ "Solar Panel - Mono Blue Uniform Preview",
+ Category::Solar,
+ look([20, 41, 85], 0.0, 0.20, 1.5),
+ SOLAR,
+ maps("starter.solar.mono-blue.maps-v1", [160.0, 160.0], false),
+ ),
+ VisualPreset::opaque(
+ "starter.solar.thin-film-dark",
+ "Solar Panel - Dark Thin Film Uniform Preview",
+ Category::Solar,
+ look([28, 33, 42], 0.0, 0.28, 1.5),
+ SOLAR,
+ maps("starter.solar.thin-film-dark.maps-v1", [100.0, 200.0], false),
+ ),
+ VisualPreset::opaque(
+ "starter.regolith.mare-charcoal",
+ "Regolith - Mare Charcoal Uniform Preview",
+ Category::Regolith,
+ look([56, 56, 55], 0.0, 0.97, 1.5),
+ REGOLITH,
+ maps("starter.regolith.mare-charcoal.maps-v1", [200.0, 200.0], false),
+ ),
+ VisualPreset::opaque(
+ "starter.regolith.highland-pale",
+ "Regolith - Highland Pale Uniform Preview",
+ Category::Regolith,
+ look([116, 113, 106], 0.0, 0.93, 1.5),
+ REGOLITH,
+ maps("starter.regolith.highland-pale.maps-v1", [200.0, 200.0], false),
+ ),
+ VisualPreset::opaque(
+ "starter.regolith.dust-neutral",
+ "Regolith - Neutral Dust Uniform Preview",
+ Category::Regolith,
+ look([86, 85, 81], 0.0, 1.0, 1.5),
+ REGOLITH,
+ maps("starter.regolith.dust-neutral.maps-v1", [150.0, 150.0], false),
+ ),
+ VisualPreset::opaque(
+ "starter.regolith.agglutinate-dark",
+ "Regolith - Dark Agglutinate Uniform Preview",
+ Category::Regolith,
+ look([66, 63, 60], 0.0, 0.89, 1.5),
+ REGOLITH,
+ maps("starter.regolith.agglutinate-dark.maps-v1", [200.0, 200.0], false),
+ ),
+];
diff --git a/assets/locales/cs.json b/assets/locales/cs.json
index d321a8aaba..0c281b5d85 100644
--- a/assets/locales/cs.json
+++ b/assets/locales/cs.json
@@ -1012,9 +1012,11 @@
"render.image_help": "Náhledový obrázek z CPU · PNG · přibližná průhlednost",
"render.image_overwrite": "Nahradit existující soubor",
"render.image_preparing": "Příprava obrázku",
+ "render.image_progressive": "Progresivní render",
"render.image_queued": "Čeká na render",
"render.image_reduce": "Zkuste menší obrázek nebo jednodušší scénu.",
"render.image_running": "Renderování obrázku",
+ "render.image_samples": "Vzorků na pixel",
"render.image_stale": "Tento obrázek používá scénu zachycenou před pozdějšími změnami.",
"render.image_start": "Spustit render",
"render.image_supported": "Požadavek na render je podporován; fronta a paměť se znovu ověří při spuštění.",
@@ -1030,6 +1032,7 @@
"render.perspective": "Perspektivní kamera",
"render.preview": "Integrovaný náhled",
"render.preview_help": "Rastrové stínování a smíšená průhlednost. Lom světla, HDRI a finální render zatím nejsou k dispozici.",
+ "render.progressive_image_summary": "Náhledové PNG · neprůhledné PBR · postupné vzorkování",
"render.reload_settings": "Znovu načíst uložené nastavení",
"render.restore_camera": "Obnovit uloženou kameru",
"render.return_design": "Zpět k návrhu",
diff --git a/assets/locales/en.json b/assets/locales/en.json
index 7f8a1e04eb..68e9bb49ac 100644
--- a/assets/locales/en.json
+++ b/assets/locales/en.json
@@ -1341,6 +1341,9 @@
"recovery.never_saved": "never saved",
"render.background": "Scene background",
"render.fit": "Fit Product",
+ "render.gpu_path_failed": "GPU path tracer unavailable",
+ "render.gpu_path_first_setup": "The first setup on this GPU can take several minutes; SolidCraft stays usable meanwhile. Later starts reuse the compiled shaders where the driver keeps them.",
+ "render.gpu_path_preparing": "GPU path tracer: compiling shaders…",
"render.image_cancelled": "Render cancelled",
"render.image_cancelling": "Cancelling",
"render.image_completed": "Image ready to export",
@@ -1351,9 +1354,11 @@
"render.image_help": "CPU preview image · PNG · approximate transparency",
"render.image_overwrite": "Replace existing file",
"render.image_preparing": "Preparing image",
+ "render.image_progressive": "Progressive rendering",
"render.image_queued": "Waiting to render",
"render.image_reduce": "Try a smaller image or simpler scene.",
"render.image_running": "Rendering image",
+ "render.image_samples": "Samples per pixel",
"render.image_stale": "This image uses the scene captured before subsequent changes.",
"render.image_start": "Start Render",
"render.image_supported": "Render request is supported; the queue and memory pool are checked again at start.",
@@ -1369,6 +1374,7 @@
"render.perspective": "Perspective camera",
"render.preview": "Integrated preview",
"render.preview_help": "Raster shading and blended transparency. Refraction, HDRI and final rendering are not available yet.",
+ "render.progressive_image_summary": "Preview PNG · PBR and glass · progressive samples",
"render.reload_settings": "Reload Saved Settings",
"render.restore_camera": "Restore Saved Camera",
"render.return_design": "Return to Design",
diff --git a/assets/locales/ja.json b/assets/locales/ja.json
index 8143f215fc..7f85b6d838 100644
--- a/assets/locales/ja.json
+++ b/assets/locales/ja.json
@@ -1341,6 +1341,9 @@
"recovery.never_saved": "未保存",
"render.background": "シーンの背景",
"render.fit": "製品を画面に合わせる",
+ "render.gpu_path_failed": "GPUパストレーサーを利用できません",
+ "render.gpu_path_first_setup": "このGPUでの初回セットアップには数分かかることがあります。その間もSolidCraftは使用できます。以降の起動では、ドライバーが保持していればコンパイル済みのシェーダーを再利用します。",
+ "render.gpu_path_preparing": "GPUパストレーサー:シェーダーをコンパイル中…",
"render.image_cancelled": "レンダリングをキャンセルしました",
"render.image_cancelling": "キャンセル中",
"render.image_completed": "画像をエクスポートできます",
@@ -1351,9 +1354,11 @@
"render.image_help": "CPUプレビュー画像 · PNG · 近似透過",
"render.image_overwrite": "既存のファイルを置換",
"render.image_preparing": "画像を準備中",
+ "render.image_progressive": "プログレッシブレンダリング",
"render.image_queued": "レンダリング待機中",
"render.image_reduce": "画像を小さくするかシーンを簡略化してください。",
"render.image_running": "画像をレンダリング中",
+ "render.image_samples": "ピクセルあたりのサンプル数",
"render.image_stale": "この画像は後続の変更前に取得したシーンを使用しています。",
"render.image_start": "レンダリングを開始",
"render.image_supported": "レンダリング要求に対応しています。開始時にキューとメモリを再確認します。",
@@ -1369,6 +1374,7 @@
"render.perspective": "透視投影カメラ",
"render.preview": "統合プレビュー",
"render.preview_help": "ラスタシェーディングとブレンド透明度を使用します。屈折、HDRI、最終レンダリングはまだ利用できません。",
+ "render.progressive_image_summary": "プレビューPNG · 不透明PBR · プログレッシブサンプリング",
"render.reload_settings": "保存した設定を再読み込み",
"render.restore_camera": "保存したカメラを復元",
"render.return_design": "設計に戻る",
diff --git a/assets/locales/zh.json b/assets/locales/zh.json
index a331329562..8c55420dc9 100644
--- a/assets/locales/zh.json
+++ b/assets/locales/zh.json
@@ -1341,6 +1341,9 @@
"recovery.never_saved": "从未保存",
"render.background": "场景背景",
"render.fit": "适配产品视图",
+ "render.gpu_path_failed": "GPU 路径追踪器不可用",
+ "render.gpu_path_first_setup": "首次在此 GPU 上设置可能需要几分钟,期间 SolidCraft 仍可正常使用。之后启动时,如果驱动程序保留了已编译的着色器,将直接复用。",
+ "render.gpu_path_preparing": "GPU 路径追踪器:正在编译着色器…",
"render.image_cancelled": "渲染已取消",
"render.image_cancelling": "正在取消",
"render.image_completed": "图像可导出",
@@ -1351,9 +1354,11 @@
"render.image_help": "CPU 预览图像 · PNG · 近似透明度",
"render.image_overwrite": "替换现有文件",
"render.image_preparing": "正在准备图像",
+ "render.image_progressive": "渐进式渲染",
"render.image_queued": "等待渲染",
"render.image_reduce": "请尝试更小的图像或更简单的场景。",
"render.image_running": "正在渲染图像",
+ "render.image_samples": "每像素采样数",
"render.image_stale": "此图像使用后续更改之前捕获的场景。",
"render.image_start": "开始渲染",
"render.image_supported": "支持此渲染请求;开始时将再次检查队列和内存池。",
@@ -1369,6 +1374,7 @@
"render.perspective": "透视相机",
"render.preview": "集成预览",
"render.preview_help": "光栅着色和混合透明度。暂不支持折射、HDRI 和最终渲染。",
+ "render.progressive_image_summary": "预览 PNG · 不透明 PBR · 渐进采样",
"render.reload_settings": "重新加载已保存设置",
"render.restore_camera": "恢复已保存相机",
"render.return_design": "返回设计",
diff --git a/crates/doc/src/appearance.rs b/crates/doc/src/appearance.rs
index 13024d3a10..96893d2483 100644
--- a/crates/doc/src/appearance.rs
+++ b/crates/doc/src/appearance.rs
@@ -138,12 +138,11 @@ pub use defaults::LIBRARY;
/// A library appearance by name (case-insensitive).
pub fn library(name: &str) -> Option<Look> {
- LIBRARY.iter().find(|(n, _, _)| n.eq_ignore_ascii_case(name.trim())).map(|(n, c, o)| Look {
- name: n.to_string(),
- color: *c,
- opacity: *o,
- pbr: None,
- })
+ LIBRARY
+ .iter()
+ .find(|(n, _, _)| n.eq_ignore_ascii_case(name.trim()))
+ .map(|(n, c, o)| Look { name: n.to_string(), color: *c, opacity: *o, pbr: None })
+ .or_else(|| crate::appearance_pack::find(name)?.opaque_look().ok())
}
/// The look a physical material gives a body that has no appearance of its own.
@@ -327,4 +326,122 @@ mod tests {
assert_eq!(Look::custom([1, 2, 3], 7.0).opacity, 1.0);
assert_eq!(Look::custom([255, 0, 16], 1.0).hex(), "#ff0010");
}
+ mod starter_pack {
+ use crate::appearance::Look;
+ use crate::appearance_pack::*;
+ use std::collections::BTreeSet;
+
+ #[test]
+ fn stable_ids_categories_and_original_licences_cover_the_requested_pack() {
+ let mut ids = BTreeSet::new();
+ let mut names = BTreeSet::new();
+ for preset in &STARTER_PACK {
+ assert!(preset.id.starts_with("starter.") && preset.id.len() <= 128);
+ assert!(preset.id.bytes().all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'.' || b == b'-'));
+ assert!(ids.insert(preset.id));
+ assert!(names.insert(preset.name.to_ascii_lowercase()));
+ assert_eq!(preset.revision, 1);
+ assert_eq!(preset.provenance.license, "MIT OR Apache-2.0");
+ assert!(!preset.provenance.author.is_empty());
+ assert_eq!(preset.provenance.source, "assets/appearances/starter_pack.rs");
+ assert_eq!(find(preset.id), Some(preset));
+ assert_eq!(find(preset.name), Some(preset));
+ }
+ for (category, count) in [
+ (Category::Wood, 8),
+ (Category::Metal, 10),
+ (Category::Plastic, 10),
+ (Category::Glass, 6),
+ (Category::Solar, 2),
+ (Category::Regolith, 4),
+ ] {
+ assert_eq!(STARTER_PACK.iter().filter(|p| p.category == category).count(), count);
+ }
+ }
+
+ #[test]
+ fn opaque_construction_and_owned_look_roundtrip_preserve_current_response() {
+ let mut admitted = 0;
+ for preset in &STARTER_PACK {
+ if let Recipe::Opaque(recipe) = preset.recipe {
+ let look = preset.opaque_look().unwrap();
+ assert_eq!(look.opacity, 1.0);
+ assert_eq!(look.color, recipe.color);
+ let surface = look.opaque_surface().unwrap().unwrap();
+ assert_eq!(surface.metallic(), recipe.metallic);
+ assert_eq!(surface.roughness(), recipe.roughness);
+ let json = serde_json::to_value(&look).unwrap();
+ assert_eq!(serde_json::from_value::<Look>(json.clone()).unwrap(), look);
+ assert!(json.get("provenance").is_none() && json.get("requirements").is_none() && json.get("id").is_none());
+ assert_eq!(preset.requirements, &[Requirement::OpaquePbr]);
+ admitted += 1;
+ }
+ }
+ assert_eq!(admitted, 34);
+ }
+
+ #[test]
+ fn glass_transmission_recipes_are_valid_but_never_scalar_or_alpha_looks() {
+ for preset in STARTER_PACK.iter().filter(|p| p.category == Category::Glass) {
+ let Recipe::Glass(recipe) = preset.recipe else { panic!("glass category must carry a glass recipe") };
+ recipe.validate().unwrap();
+ assert!(!preset.is_opaque());
+ assert!(preset.opaque_look().is_err());
+ assert_eq!(preset.requirements, &[Requirement::Refraction, Requirement::CertifiedThinOrClosed]);
+ // Compatibility of illustrative values only: the real optics adapter must
+ // derive and admit these absorption values after geometry certification.
+ assert!(recipe.transmission_linear_rgb.iter().all(|t| (-t.ln() / recipe.reference_path_mm) <= 100.0));
+ for channel in [0.0, -1.0, 1.01, f64::NAN, f64::INFINITY] {
+ let mut bad = recipe;
+ bad.transmission_linear_rgb[0] = channel;
+ assert!(bad.validate().is_err());
+ }
+ let mut bad = recipe;
+ bad.reference_path_mm = 0.0;
+ assert!(bad.validate().is_err());
+ bad = recipe;
+ bad.boundary = GlassBoundary::Thin { thickness_mm: 10001.0 };
+ assert!(bad.validate().is_err());
+ }
+ }
+
+ #[test]
+ fn legacy_library_and_six_existing_finish_names_are_not_overridden_or_duplicated() {
+ assert_eq!(crate::appearance::LIBRARY.len(), 20);
+ for (name, color, opacity) in crate::appearance::LIBRARY {
+ let look = crate::appearance::library(name).unwrap();
+ assert_eq!(look.color, color);
+ assert_eq!(look.opacity, opacity);
+ assert!(look.pbr.is_none());
+ assert!(find(name).is_none());
+ }
+ for name in [
+ "Steel - Satin PBR",
+ "Aluminum - Satin PBR",
+ "Copper - Clean PBR",
+ "ABS - Molded PBR",
+ "PLA - Smooth PBR",
+ "Wood - Oak Uniform PBR Preview",
+ ] {
+ assert!(STARTER_PACK.iter().all(|p| !p.name.eq_ignore_ascii_case(name)), "existing #1366 finish must remain independent");
+ }
+ }
+
+ #[test]
+ fn uniform_previews_and_planned_resource_scale_are_explicit_and_not_bindings() {
+ let mut recipes = 0;
+ for preset in &STARTER_PACK {
+ if let Some(recipe) = preset.future_texture_recipe {
+ assert!(preset.name.contains("Uniform Preview"));
+ assert!(preset.preview_note.contains("Uniform opaque preview only"));
+ assert_eq!(recipe.id, format!("{}.maps-v1", preset.id));
+ assert!(recipe.repeat_mm.iter().all(|v| v.is_finite() && *v > 0.0 && *v <= 10000.0));
+ assert_eq!(recipe.grain_axis, if preset.category == Category::Wood { Some(TextureAxis::V) } else { None });
+ assert_eq!(preset.requirements, &[Requirement::OpaquePbr]);
+ recipes += 1;
+ }
+ }
+ assert_eq!(recipes, 14);
+ }
+ }
}
diff --git a/crates/doc/src/appearance_pack.rs b/crates/doc/src/appearance_pack.rs
new file mode 100644
index 0000000000..29c8d4f392
--- /dev/null
+++ b/crates/doc/src/appearance_pack.rs
@@ -0,0 +1,186 @@
+//! Original visual authoring choices; never engineering material grades or a catalog codec.
+use serde::Serialize;
+
+use crate::{DocError, Result, appearance::Look, pbr_appearance::PbrParameters};
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum Category {
+ Wood,
+ Metal,
+ Plastic,
+ Glass,
+ Solar,
+ Regolith,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum Requirement {
+ OpaquePbr,
+ Refraction,
+ CertifiedThinOrClosed,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum TextureAxis {
+ V,
+}
+
+/// Planned original procedural resources, not a loaded texture or a saved binding.
+/// Albedo is sRGB; roughness and positive-Y tangent normals are linear data.
+#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
+pub struct TextureRecipe {
+ pub id: &'static str,
+ pub repeat_mm: [f64; 2],
+ pub grain_axis: Option<TextureAxis>,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
+pub struct Provenance {
+ pub author: &'static str,
+ pub license: &'static str,
+ pub source: &'static str,
+ pub kind: &'static str,
+}
+pub const ORIGINAL: Provenance = Provenance {
+ author: "SolidCraft contributors",
+ license: "MIT OR Apache-2.0",
+ source: "assets/appearances/starter_pack.rs",
+ kind: "original illustrative optical authoring; not measured material data",
+};
+
+#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
+pub struct OpaqueRecipe {
+ pub color: [u8; 3],
+ pub metallic: f64,
+ pub roughness: f64,
+ pub dielectric_ior: f64,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
+#[serde(tag = "mode", rename_all = "snake_case")]
+pub enum GlassBoundary {
+ Thin { thickness_mm: f64 },
+ Closed,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
+pub struct GlassRecipe {
+ pub dielectric_ior: f64,
+ /// Linear transmittance over reference_path_mm, not sRGB tint or alpha.
+ pub transmission_linear_rgb: [f64; 3],
+ pub reference_path_mm: f64,
+ pub boundary: GlassBoundary,
+}
+impl GlassRecipe {
+ pub fn validate(&self) -> Result<()> {
+ if !self.dielectric_ior.is_finite()
+ || !(1.0..=3.0).contains(&self.dielectric_ior)
+ || self.transmission_linear_rgb.iter().any(|v| !v.is_finite() || *v <= 0.0 || *v > 1.0)
+ || !self.reference_path_mm.is_finite()
+ || self.reference_path_mm <= 0.0
+ || self.reference_path_mm > 1e6
+ || matches!(self.boundary,GlassBoundary::Thin {thickness_mm} if !thickness_mm.is_finite() || thickness_mm<=0.0 || thickness_mm>10000.0)
+ {
+ return Err(DocError::Invalid(
+ "invalid illustrative glass recipe: finite IOR1..3, linear transmission0<T<=1, bounded positive reference path/thickness required"
+ .into(),
+ ));
+ }
+ Ok(())
+ }
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
+#[serde(tag = "kind", rename_all = "snake_case")]
+pub enum Recipe {
+ Opaque(OpaqueRecipe),
+ Glass(GlassRecipe),
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
+pub struct VisualPreset {
+ pub id: &'static str,
+ pub name: &'static str,
+ pub category: Category,
+ pub revision: u32,
+ pub provenance: Provenance,
+ pub requirements: &'static [Requirement],
+ pub recipe: Recipe,
+ pub preview_note: &'static str,
+ pub future_texture_recipe: Option<TextureRecipe>,
+}
+
+impl VisualPreset {
+ pub const fn opaque(
+ id: &'static str,
+ name: &'static str,
+ category: Category,
+ recipe: OpaqueRecipe,
+ preview_note: &'static str,
+ future_texture_recipe: Option<TextureRecipe>,
+ ) -> Self {
+ Self {
+ id,
+ name,
+ category,
+ revision: 1,
+ provenance: ORIGINAL,
+ requirements: &[Requirement::OpaquePbr],
+ recipe: Recipe::Opaque(recipe),
+ preview_note,
+ future_texture_recipe,
+ }
+ }
+ pub const fn glass(id: &'static str, name: &'static str, recipe: GlassRecipe) -> Self {
+ Self {
+ id,
+ name,
+ category: Category::Glass,
+ revision: 1,
+ provenance: ORIGINAL,
+ requirements: &[Requirement::Refraction, Requirement::CertifiedThinOrClosed],
+ recipe: Recipe::Glass(recipe),
+ preview_note: "Recipe only: requires actual refraction and a certified thin/closed geometry path; no alpha substitute",
+ future_texture_recipe: None,
+ }
+ }
+ pub fn is_opaque(&self) -> bool {
+ matches!(self.recipe, Recipe::Opaque(_))
+ }
+ pub fn preview_color(&self) -> [u8; 3] {
+ match self.recipe {
+ Recipe::Opaque(r) => r.color,
+ // A UI swatch of the transmission values, not rendered glass or absorption.
+ Recipe::Glass(r) => r.transmission_linear_rgb.map(|v| {
+ let encoded = if v <= 0.0031308 { 12.92 * v } else { 1.055 * v.powf(1.0 / 2.4) - 0.055 };
+ (encoded.clamp(0.0, 1.0) * 255.0).round() as u8
+ }),
+ }
+ }
+
+ /// All opaque presets share the existing finite PBR constructor and owned Look.
+ /// Refraction recipes cannot be smuggled into a scalar/alpha appearance.
+ pub fn opaque_look(&self) -> Result<Look> {
+ let Recipe::Opaque(recipe) = self.recipe else {
+ return Err(DocError::Invalid(
+ "glass recipe unavailable: actual refraction and certified thin/closed geometry are required; alpha transparency is not a substitute"
+ .into(),
+ ));
+ };
+ let pbr = PbrParameters::new(recipe.metallic, recipe.roughness, recipe.dielectric_ior).map_err(|e| DocError::Invalid(e.to_string()))?;
+ Ok(Look { name: self.name.into(), color: recipe.color, opacity: 1.0, pbr: Some(pbr) })
+ }
+}
+
+#[path = "../../../assets/appearances/starter_pack.rs"]
+mod data;
+pub use data::STARTER_PACK;
+
+/// Stable IDs are preferred for commands; display-name lookup is unambiguous.
+pub fn find(id_or_name: &str) -> Option<&'static VisualPreset> {
+ let key = id_or_name.trim();
+ STARTER_PACK.iter().find(|p| p.id.eq_ignore_ascii_case(key) || p.name.eq_ignore_ascii_case(key))
+}
diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rs
index cd2ec9198e..76e88afd63 100644
--- a/crates/doc/src/document.rs
+++ b/crates/doc/src/document.rs
@@ -3709,8 +3709,14 @@ pub struct UserMaterial {
pub density: f64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub appearance: Option<crate::appearance::Look>,
+ /// Candidate engineering data; independent of assigned mass density and optics.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub physical_card: Option<crate::physical_material::ValidatedCard>,
}
+/// Bound design-owned definitions consistently in commands and normal file loading.
+pub const MAX_USER_MATERIALS: usize = 1000;
+
/// Largest density a material may have (g/cm³); the densest elements are about 22.6.
pub const MAX_DENSITY: f64 = 1000.0;
diff --git a/crates/doc/src/format.rs b/crates/doc/src/format.rs
index 27afafc78b..5d718dc1f9 100644
--- a/crates/doc/src/format.rs
+++ b/crates/doc/src/format.rs
@@ -1041,10 +1041,36 @@ const MAX_REAL: f64 = 1e9;
/// alone: it is other tools' data, kept as it is and never read as a number (#1015); parsing
/// already bounds its nesting.
fn check_design_numbers(v: &Value) -> Result<()> {
- match v {
- Value::Object(m) => m.iter().filter(|(k, _)| k.as_str() != "metadata").try_for_each(|(_, x)| check_numbers(x, 1)),
- v => check_numbers(v, 0),
+ let Some(root) = v.as_object() else { return check_numbers(v, 0) };
+ for (key, value) in root {
+ if key == "metadata" {
+ continue;
+ }
+ if key != "user_materials" {
+ check_numbers(value, 1)?;
+ continue;
+ }
+ let Some(materials) = value.as_array() else { return check_numbers(value, 1) };
+ if materials.len() > crate::MAX_USER_MATERIALS {
+ return Err(DocError::Invalid("document exceeds 1000 user materials".into()));
+ }
+ for material in materials {
+ let Some(fields) = material.as_object() else {
+ check_numbers(material, 2)?;
+ continue;
+ };
+ for (field, data) in fields {
+ // SI engineering constants have separate typed bounds. No other field,
+ // including nested fields with this name, bypasses coordinate limits.
+ if field == "physical_card" && !data.is_null() {
+ crate::physical_material::validate_card(data)?;
+ } else {
+ check_numbers(data, 3)?;
+ }
+ }
+ }
}
+ Ok(())
}
/// The range check again, on the typed design: an integer such as `9223372036854775808` passes
diff --git a/crates/doc/src/format/pending/material-engineering-cards.rs b/crates/doc/src/format/pending/material-engineering-cards.rs
new file mode 100644
index 0000000000..c2002ce602
--- /dev/null
+++ b/crates/doc/src/format/pending/material-engineering-cards.rs
@@ -0,0 +1,5 @@
+//! User materials can save a validated SI engineering card (`physical_card`) with property
+//! conditions and source claims, independently of assigned mass density and visual appearance.
+//! Older designs need no transformation: an absent card means unspecified engineering data.
+//! The last release refuses this newer format; pending builds without this change refuse its
+//! `material-engineering-cards` descriptor instead of silently dropping the saved card.
diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs
index 003c56a214..f2a39be7c7 100644
--- a/crates/doc/src/lib.rs
+++ b/crates/doc/src/lib.rs
@@ -6,6 +6,7 @@
#![forbid(unsafe_code)]
pub mod appearance;
+pub mod appearance_pack;
mod assembly;
mod body_transfer;
mod body_transfer_sheet;
diff --git a/crates/doc/src/physical_material.rs b/crates/doc/src/physical_material.rs
index ad3b16444a..2516095244 100644
--- a/crates/doc/src/physical_material.rs
+++ b/crates/doc/src/physical_material.rs
@@ -17,6 +17,31 @@ pub struct MaterialCard {
pub properties: Vec<Property>,
}
+/// Design-owned candidate data. Private storage prevents bypassing admission;
+/// validation does not certify sources, applicability or analysis capability.
+#[derive(Clone, Debug, PartialEq, Serialize)]
+#[serde(transparent)]
+pub struct ValidatedCard(MaterialCard);
+
+impl ValidatedCard {
+ pub fn from_value(value: &Value) -> Result<Self> {
+ let card = admit_card(value)?;
+ card.validate()?;
+ Ok(Self(card))
+ }
+
+ pub fn card(&self) -> &MaterialCard {
+ &self.0
+ }
+}
+
+impl<'de> Deserialize<'de> for ValidatedCard {
+ fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> std::result::Result<Self, D::Error> {
+ let value = Value::deserialize(deserializer)?;
+ Self::from_value(&value).map_err(serde::de::Error::custom)
+ }
+}
+
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Family {
diff --git a/crates/doc/src/tests.rs b/crates/doc/src/tests.rs
index 87f0199a94..7c18478781 100644
--- a/crates/doc/src/tests.rs
+++ b/crates/doc/src/tests.rs
@@ -261,7 +261,7 @@ fn a_body_reads_the_material_its_mass_is_computed_with() {
let usable = [("Walnut", 0.65), ("Mote", f64::MIN_POSITIVE), ("Limit", MAX_DENSITY)];
let unusable = [("Broken", -3.0), ("Weightless", 0.0), ("Beyond", MAX_DENSITY.next_up())];
for (name, density) in usable.into_iter().chain(unusable) {
- doc.user_materials.push(UserMaterial { name: name.into(), density, appearance: None });
+ doc.user_materials.push(UserMaterial { name: name.into(), density, appearance: None, physical_card: None });
}
// (body, its assignment as stored, the material it reads and weighs, that material's density)
let cases = [
diff --git a/crates/engine/src/cmd/inspect.rs b/crates/engine/src/cmd/inspect.rs
index 5e271a87b1..7e006e571b 100644
--- a/crates/engine/src/cmd/inspect.rs
+++ b/crates/engine/src/cmd/inspect.rs
@@ -30,19 +30,19 @@ pub static COMMANDS: &[CommandSpec] = &[
.params("bodies: [names]; material: name (Steel, Aluminum, ABS Plastic, …, or one made with material.create; `material.list`)"),
CommandSpec::new("appearance.assign", "Appearance", appearance).at("SOLID", "MODIFY").icon("appearance").key("A").params(
"bodies?: [names]; faces?: [[x,y,z] on faces] (body?: which body, default the nearest); components?: [names or ids, or occurrence names]; \
- appearance?: library name (appearance.library) | color: \"#rrggbb\" or [r, g, b] (0–255), opacity? (0–1, default 1); \
- pbr?: {metallic:0..1, roughness:0.045..1, dielectric_ior:1..3} (requires color/appearance and opacity 1); omitted/null uses legacy scalar shading. Neither appearance nor color (or color: null): clear, so the face follows its body, the body its component, the component its material",
+ appearance?: library name or stable starter.* ID (appearance.library) | color: \"#rrggbb\" or [r, g, b] (0–255), opacity? (0–1, default 1); \
+ name?: inert copied look label (requires color, mutually exclusive with appearance); pbr?: {metallic:0..1, roughness:0.045..1, dielectric_ior:1..3} (requires color/appearance and opacity 1); a starter ID or registered starter name resolves its recipe before color overrides; omitted pbr retains that response and pbr: null explicitly clears it. Unavailable glass recipes refuse through either selector. Other custom labels with an explicit color retain legacy scalar behavior. Neither appearance nor color (or color: null): clear, so the face follows its body, the body its component, the component its material",
),
CommandSpec::new("appearance.library", "Appearance Library", appearance_library).icon("library")
.noundo()
- .params("→ the built-in appearances (name, colour, opacity)"),
+ .params("→ 20 legacy scalar appearances and 40 starter recipes with IDs, categories, provenance, requirements and availability; six starter glass recipes are unavailable"),
CommandSpec::new("appearance.list", "List Appearances", appearance_list).icon("list")
.noundo()
.params("body?: name → assigned appearances; with body, its resolved look and its faces' (face index, look)"),
CommandSpec::new("material.list", "List Materials", material_list).icon("list")
.noundo()
.doc_only()
- .params("→ the built-in materials, then the design's own (user: true, with their look)"),
+ .params("→ built-in and design-owned materials (user: true, look, optional physical_card/physical_validation/density_comparison). Read-only; candidate engineering records do not certify sources or supply a solver"),
CommandSpec::new("engine.commands", "List Commands", commands).icon("list").noundo(),
CommandSpec::new("engine.describe", "Describe Command", crate::checked!("engine.describe", DESCRIBE_CONTRACT, describe))
.icon("list")
@@ -387,36 +387,68 @@ pub(super) fn color_param(v: &Value) -> Option<[u8; 3]> {
Some([c(0)?, c(1)?, c(2)?])
}
-fn appearance(s: &mut Session, p: &Value) -> Result<Value> {
+pub(super) fn appearance(s: &mut Session, p: &Value) -> Result<Value> {
use solidcraft_doc::appearance::{FaceLook, Look, library};
let cmd = "appearance.assign";
- let mut look: Option<Look> = match (str_(p, "appearance"), p.get("color")) {
- // A colour with a name: that colour, called that (a name not in the library is fine).
- (Some(n), Some(v)) if !v.is_null() => {
- let c = color_param(v).ok_or_else(|| bad(cmd, "`color` must be \"#rrggbb\" or [r, g, b] with values 0–255"))?;
- let o = p.get("opacity").and_then(Value::as_f64).filter(|x| x.is_finite()).unwrap_or(1.0);
- let mut l = Look::custom(c, o);
- l.name = n.chars().take(128).collect();
- Some(l)
+ // A saved label is data, not a request to resolve a recipe. Keep the explicit
+ // appearance selector separate so an owned look may have any recipe's ID as its name.
+ let copied_name = match p.get("name") {
+ None | Some(Value::Null) => None,
+ Some(Value::String(name)) if !name.is_empty() && name.chars().count() <= 128 && !name.chars().any(char::is_control) => Some(name),
+ _ => return Err(bad(cmd, "`name` must be a nonempty label of at most 128 characters without controls")),
+ };
+ if copied_name.is_some() && (p.get("color").is_none_or(Value::is_null) || p.get("appearance").is_some_and(|value| !value.is_null())) {
+ return Err(bad(cmd, "`name` requires an explicit color and cannot be combined with `appearance`"));
+ }
+ // Both the stable ID and a registered display name explicitly select a recipe.
+ // Copied labels use `name`, so color overrides cannot bypass unsupported optics.
+ let preset = str_(p, "appearance").and_then(solidcraft_doc::appearance_pack::find);
+ let mut look: Option<Look> = if let Some(preset) = preset {
+ // Refuse unsupported optics before any color/PBR/opacity override.
+ let mut look = preset.opaque_look().map_err(|e| bad(cmd, e.to_string()))?;
+ if let Some(color) = p.get("color").filter(|v| !v.is_null()) {
+ look.color = color_param(color).ok_or_else(|| bad(cmd, "invalid preset color override"))?;
}
- (Some(n), _) => {
- let mut l = library(n).ok_or_else(|| bad(cmd, format!("no appearance `{n}` in the library (appearance.library)")))?;
- if let Some(o) = p.get("opacity").and_then(Value::as_f64).filter(|x| x.is_finite()) {
- l.opacity = o.clamp(0.0, 1.0);
- }
- Some(l)
+ if let Some(opacity) = p.get("opacity").and_then(Value::as_f64).filter(|x| x.is_finite()) {
+ look.opacity = opacity.clamp(0.0, 1.0);
}
- (None, None | Some(Value::Null)) => None,
- (None, Some(v)) => {
- let c = color_param(v).ok_or_else(|| bad(cmd, "`color` must be \"#rrggbb\" or [r, g, b] with values 0–255"))?;
- let o = match p.get("opacity") {
- Some(o) => o.as_f64().filter(|x| x.is_finite() && (0.0..=1.0).contains(x)).ok_or_else(|| bad(cmd, "`opacity` must be 0…1"))?,
- None => 1.0,
- };
- Some(Look::custom(c, o))
+ Some(look)
+ } else {
+ match (str_(p, "appearance"), p.get("color")) {
+ // A colour with a name: that colour, called that (a name not in the library is fine).
+ (Some(n), Some(v)) if !v.is_null() => {
+ let c = color_param(v).ok_or_else(|| bad(cmd, "`color` must be \"#rrggbb\" or [r, g, b] with values 0–255"))?;
+ let o = p.get("opacity").and_then(Value::as_f64).filter(|x| x.is_finite()).unwrap_or(1.0);
+ let mut l = Look::custom(c, o);
+ l.name = n.chars().take(128).collect();
+ Some(l)
+ }
+ (Some(n), _) => {
+ let mut l = if let Some(preset) = solidcraft_doc::appearance_pack::find(n) {
+ preset.opaque_look().map_err(|e| bad(cmd, e.to_string()))?
+ } else {
+ library(n).ok_or_else(|| bad(cmd, format!("no appearance `{n}` in the library (appearance.library)")))?
+ };
+ if let Some(o) = p.get("opacity").and_then(Value::as_f64).filter(|x| x.is_finite()) {
+ l.opacity = o.clamp(0.0, 1.0);
+ }
+ Some(l)
+ }
+ (None, None | Some(Value::Null)) => None,
+ (None, Some(v)) => {
+ let c = color_param(v).ok_or_else(|| bad(cmd, "`color` must be \"#rrggbb\" or [r, g, b] with values 0–255"))?;
+ let o = match p.get("opacity") {
+ Some(o) => o.as_f64().filter(|x| x.is_finite() && (0.0..=1.0).contains(x)).ok_or_else(|| bad(cmd, "`opacity` must be 0…1"))?,
+ None => 1.0,
+ };
+ Some(Look::custom(c, o))
+ }
}
};
if let Some(l) = &mut look {
+ if let Some(name) = copied_name {
+ l.name = name.clone();
+ }
attach_pbr(cmd, p, l)?;
} else if p.get("pbr").is_some_and(|v| !v.is_null()) {
return Err(bad(cmd, "`pbr` requires a color or appearance"));
@@ -543,38 +575,52 @@ pub(super) fn look_json(l: &solidcraft_doc::appearance::Look) -> Value {
mod pbr_tests;
pub(super) fn attach_pbr(cmd: &str, params: &Value, look: &mut solidcraft_doc::appearance::Look) -> Result<()> {
- let Some(value) = params.get("pbr") else { return Ok(()) };
- if value.is_null() {
- look.pbr = None;
- return Ok(());
- }
- if let Some(opacity) = params.get("opacity")
- && opacity.as_f64().filter(|v| v.is_finite() && *v == 1.0).is_none()
- {
- return Err(bad(cmd, "opaque PBR requires numeric opacity 1"));
+ if let Some(value) = params.get("pbr") {
+ look.pbr = if value.is_null() {
+ None
+ } else {
+ let object = value
+ .as_object()
+ .filter(|o| o.len() == 3 && o.keys().all(|k| matches!(k.as_str(), "metallic" | "roughness" | "dielectric_ior")))
+ .ok_or_else(|| bad(cmd, "`pbr` requires exactly metallic, roughness and dielectric_ior"))?;
+ let number = |key: &str| object.get(key).and_then(Value::as_f64).ok_or_else(|| bad(cmd, format!("`pbr.{key}` must be a finite number")));
+ Some(
+ solidcraft_doc::pbr_appearance::PbrParameters::new(number("metallic")?, number("roughness")?, number("dielectric_ior")?)
+ .map_err(|e| bad(cmd, e.to_string()))?,
+ )
+ };
}
- let object = value
- .as_object()
- .filter(|o| o.len() == 3 && o.keys().all(|k| matches!(k.as_str(), "metallic" | "roughness" | "dielectric_ior")))
- .ok_or_else(|| bad(cmd, "`pbr` requires exactly metallic, roughness and dielectric_ior"))?;
- let number = |key: &str| object.get(key).and_then(Value::as_f64).ok_or_else(|| bad(cmd, format!("`pbr.{key}` must be a finite number")));
- let response = solidcraft_doc::pbr_appearance::PbrParameters::new(number("metallic")?, number("roughness")?, number("dielectric_ior")?)
- .map_err(|e| bad(cmd, e.to_string()))?;
- if look.opacity != 1.0 {
- return Err(bad(cmd, "opaque PBR requires opacity 1; refraction/transmission is not supported"));
+ // Validate the final look, including a named preset's inherited response.
+ // Both appearance assignments and physical-material defaults use this path.
+ if look.pbr.is_some() {
+ if let Some(opacity) = params.get("opacity")
+ && opacity.as_f64().filter(|v| v.is_finite() && *v == 1.0).is_none()
+ {
+ return Err(bad(cmd, "opaque PBR requires numeric opacity 1"));
+ }
+ if look.opacity != 1.0 {
+ return Err(bad(cmd, "opaque PBR requires opacity 1; refraction/transmission is not supported"));
+ }
}
- look.pbr = Some(response);
Ok(())
}
fn appearance_library(_s: &mut Session, _p: &Value) -> Result<Value> {
- let list: Vec<Value> = solidcraft_doc::appearance::LIBRARY
+ let mut list: Vec<Value> = solidcraft_doc::appearance::LIBRARY
.iter()
.map(|(n, c, o)| {
let category = n.split(" - ").next().unwrap_or(n);
json!({"name": n, "category": category, "color": format!("#{:02x}{:02x}{:02x}", c[0], c[1], c[2]), "opacity": o})
})
.collect();
+ for preset in &solidcraft_doc::appearance_pack::STARTER_PACK {
+ let c = preset.preview_color();
+ let pbr = preset.opaque_look().ok().and_then(|look| look.pbr);
+ list.push(json!({"id":preset.id,"name":preset.name,"category":preset.category,"revision":preset.revision,
+ "color":format!("#{:02x}{:02x}{:02x}",c[0],c[1],c[2]),"opacity":1.0,"pbr":pbr,
+ "available":preset.is_opaque(),"requirements":preset.requirements,"provenance":preset.provenance,
+ "recipe":preset.recipe,"preview_note":preset.preview_note,"future_texture_recipe":preset.future_texture_recipe}));
+ }
Ok(json!({"appearances": list}))
}
@@ -640,8 +686,15 @@ fn appearance_list(s: &mut Session, p: &Value) -> Result<Value> {
fn material_list(s: &mut Session, _p: &Value) -> Result<Value> {
let built_in = solidcraft_doc::MATERIALS.iter().map(|(n, d)| json!({"name": n, "density_g_cm3": d}));
- let user = s.doc.user_materials.iter().map(
- |m| json!({"name": m.name, "density_g_cm3": m.density, "appearance": s.doc.material_look(&m.name).as_ref().map(look_json), "user": true}),
- );
+ let user = s
+ .doc
+ .user_materials
+ .iter()
+ .map(|m| {
+ let mut out = super::materials::material_json(m)?;
+ out["appearance"] = json!(s.doc.material_look(&m.name).as_ref().map(look_json));
+ Ok(out)
+ })
+ .collect::<Result<Vec<_>>>()?;
Ok(json!({"materials": built_in.chain(user).collect::<Vec<_>>()}))
}
diff --git a/crates/engine/src/cmd/libraries.rs b/crates/engine/src/cmd/libraries.rs
index ad64fef61d..433ad7755c 100644
--- a/crates/engine/src/cmd/libraries.rs
+++ b/crates/engine/src/cmd/libraries.rs
@@ -1,4 +1,4 @@
-//! Scalar local libraries: inspect/export files and copy exact revisions into a design.
+//! Local material libraries: inspect/export files and copy exact revisions into a design.
use super::CommandSpec;
use crate::{Result, Session, params::bad};
use serde::Deserialize;
@@ -7,9 +7,9 @@ use solidcraft_io::catalog::{Catalog, Definition, Provenance};
pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("library.inspect", "Inspect Local Library", inspect).icon("inspect").noundo().doc_only()
- .params("path: scalar library JSON; returns validated catalog and exact entry revisions, without changing the design"),
+ .params("path: v1/v2 library JSON; returns validated catalog and exact entry revisions, without changing the design"),
CommandSpec::new("library.export", "Export Design Library", export).icon("export").noundo().doc_only()
- .params("path: .json; id? (default user.local), name?, provenance?, overwrite? false. Copies assigned looks and design-local physical definitions; never changes the design"),
+ .params("path: .json; id? (default user.local), name?, provenance?, overwrite? false, format? solidcraft-library/2 (default) | solidcraft-library/1 (refuses PBR/cards). Copies assigned looks and design-local physical definitions; never changes the design"),
CommandSpec::new("library.apply", "Apply Local Library Entry", apply).icon("import").enabled(super::not_in_sketch)
.params("path, entry: qualified ID, revision: exact content SHA-256; targets?: {bodies?, faces?: [{body,point}], components?}; name?: physical material name on import. Copies values in one undo step; material conflicts are explicit"),
];
@@ -31,6 +31,11 @@ struct Export {
provenance: Provenance,
#[serde(default)]
overwrite: bool,
+ #[serde(default = "default_format")]
+ format: String,
+}
+fn default_format() -> String {
+ solidcraft_io::catalog::FORMAT.into()
}
fn default_id() -> String {
"user.local".into()
@@ -107,7 +112,9 @@ fn export(s: &mut Session, p: &Value) -> Result<Value> {
if !request.path.to_ascii_lowercase().ends_with(".json") {
return Err(bad(cmd, "library export path must end in .json"));
}
- let catalog = Catalog::from_document(&s.doc, &request.id, &request.name, request.provenance).map_err(|e| bad(cmd, e.to_string()))?;
+ let catalog = Catalog::from_document(&s.doc, &request.id, &request.name, request.provenance)
+ .and_then(|catalog| catalog.in_format(&request.format))
+ .map_err(|e| bad(cmd, e.to_string()))?;
let bytes = catalog.encode().map_err(|e| bad(cmd, e.to_string()))?;
#[cfg(not(target_arch = "wasm32"))]
let result = if request.overwrite {
@@ -143,9 +150,11 @@ fn apply(s: &mut Session, p: &Value) -> Result<Value> {
return Err(bad(cmd, "appearance entries need targets and do not take a material name"));
}
let mut target = serde_json::to_value(&request.targets).map_err(|e| bad(cmd, e.to_string()))?;
- target["appearance"] = json!(look.name);
+ target["name"] = json!(look.name);
target["color"] = json!(look.color);
target["opacity"] = json!(look.opacity);
+ // Catalog labels are inert; a full replacement explicitly clears absent PBR.
+ target["pbr"] = json!(look.pbr);
nested(s, "appearance.assign", &target)?
}
Definition::Material(material) => {
@@ -172,6 +181,12 @@ fn apply(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(look) = &material.appearance {
params["color"] = json!(look.color);
params["opacity"] = json!(look.opacity);
+ if let Some(pbr) = look.pbr {
+ params["pbr"] = json!(pbr);
+ }
+ }
+ if let Some(card) = &material.physical_card {
+ params["physical_card"] = json!(card);
}
nested(s, "material.create", &params)?;
// The existing colour API labels a custom look after its material.
diff --git a/crates/engine/src/cmd/libraries_tests.rs b/crates/engine/src/cmd/libraries_tests.rs
index 0cb53ce9bb..ddb4f9b57a 100644
--- a/crates/engine/src/cmd/libraries_tests.rs
+++ b/crates/engine/src/cmd/libraries_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use solidcraft_io::catalog::{Definition, Entry, FORMAT, ScalarLook, ScalarMaterial};
+use solidcraft_io::catalog::{Definition, Entry, FORMAT, LibraryLook, LibraryMaterial};
use std::sync::{
Arc,
atomic::{AtomicU64, Ordering},
@@ -33,16 +33,17 @@ fn catalog() -> Catalog {
entries: vec![
Entry::new(
"user.test",
- Definition::Appearance(ScalarLook { name: "Warm oak colour".into(), color: [180, 120, 70], opacity: 0.8 }),
+ Definition::Appearance(LibraryLook { name: "Warm oak colour".into(), color: [180, 120, 70], opacity: 0.8, pbr: None }),
Provenance::default(),
)
.unwrap(),
Entry::new(
"user.test",
- Definition::Material(ScalarMaterial {
+ Definition::Material(LibraryMaterial {
name: "Timber density".into(),
density_g_cm3: 0.7,
- appearance: Some(ScalarLook { name: "Timber tint".into(), color: [180, 120, 70], opacity: 1.0 }),
+ physical_card: None,
+ appearance: Some(LibraryLook { name: "Timber tint".into(), color: [180, 120, 70], opacity: 1.0, pbr: None }),
}),
Provenance::default(),
)
@@ -60,6 +61,113 @@ fn apply_entry(s: &mut Session, file: &File, entry: &Entry, targets: Value) -> R
s.execute("library.apply", &json!({"path":file.0,"entry":entry.id,"revision":entry.revision,"targets":targets}))
}
+fn rich_catalog() -> Catalog {
+ use solidcraft_doc::{pbr_appearance::PbrParameters, physical_material::ValidatedCard};
+ let mut c = catalog();
+ if let Definition::Appearance(l) = &mut c.entries[0].definition {
+ l.opacity = 1.0;
+ l.pbr = Some(PbrParameters::new(1., 0.25, 1.5).unwrap());
+ }
+ if let Definition::Material(m) = &mut c.entries[1].definition {
+ m.density_g_cm3 = 0.8;
+ m.appearance.as_mut().unwrap().pbr = Some(PbrParameters::new(0., 0.65, 1.4).unwrap());
+ m.physical_card = Some(
+ ValidatedCard::from_value(&json!({"schema_version":1,"designation":"Original synthetic candidate","family":"other",
+ "sources":[{"id":"fixture","title":"Original invented density","kind":"illustrative"}],
+ "properties":[{"source_id":"fixture","data":{"kind":"density","kg_m3":700.0}}]}))
+ .unwrap(),
+ );
+ }
+ for e in &mut c.entries {
+ *e = Entry::new("user.test", e.definition.clone(), e.provenance.clone()).unwrap();
+ }
+ c
+}
+
+#[test]
+fn rich_appearance_copy_preserves_product_response_and_mass_without_source_file() {
+ let file = File::new();
+ let c = rich_catalog();
+ file.write(&c);
+ let mut s = session();
+ let mass = s.execute("component.properties", &json!({})).unwrap();
+ let scene = crate::product_scene::extract(&s).unwrap();
+ let undo = s.undo.len();
+ apply_entry(&mut s, &file, &c.entries[0], json!({"bodies":["Body1"]})).unwrap();
+ assert_eq!(s.undo.len(), undo + 1);
+ let after = crate::product_scene::extract(&s).unwrap();
+ assert!(Arc::ptr_eq(&scene.meshes[0].mesh, &after.meshes[0].mesh));
+ assert_eq!(after.meshes[0].surface.unwrap().metallic(), 1.0);
+ assert_eq!(s.execute("component.properties", &json!({})).unwrap(), mass);
+ let saved = solidcraft_io::write_design(&s.doc);
+ std::fs::remove_file(&file.0).unwrap();
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert!(s.doc.appearances.bodies.is_empty());
+ s.execute("edit.redo", &json!({})).unwrap();
+ let mut reopened = Session::new(solidcraft_io::read_design(&saved).unwrap());
+ assert_eq!(reopened.doc.appearances, s.doc.appearances);
+ assert_eq!(reopened.execute("component.properties", &json!({})).unwrap(), mass);
+}
+
+#[test]
+fn rich_material_copy_retains_engineering_card_label_optics_and_explicit_mass_density() {
+ let file = File::new();
+ let c = rich_catalog();
+ file.write(&c);
+ let mut s = session();
+ let undo = s.undo.len();
+ apply_entry(&mut s, &file, &c.entries[1], json!({"bodies":["Body1"]})).unwrap();
+ assert_eq!(s.undo.len(), undo + 1);
+ let material = &s.doc.user_materials[0];
+ assert_eq!(material.appearance.as_ref().unwrap().name, "Timber tint");
+ assert_eq!(material.appearance.as_ref().unwrap().pbr.unwrap().roughness(), 0.65);
+ assert!(material.physical_card.is_some());
+ assert_eq!(material.density, 0.8);
+ let mass = s.execute("component.properties", &json!({})).unwrap()["total"]["mass_g"].as_f64().unwrap();
+ assert!((mass - 0.8).abs() < 1e-8);
+ let saved = solidcraft_io::write_design(&s.doc);
+ std::fs::remove_file(&file.0).unwrap();
+ let reopened = Session::new(solidcraft_io::read_design(&saved).unwrap());
+ assert_eq!(reopened.doc.user_materials, s.doc.user_materials);
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert!(s.doc.user_materials.is_empty());
+ s.execute("edit.redo", &json!({})).unwrap();
+ assert_eq!(s.doc.user_materials, reopened.doc.user_materials);
+}
+
+#[test]
+fn explicit_v1_export_refuses_richer_data_before_overwriting_and_scalar_v1_still_works() {
+ let file = File::new();
+ let sentinel = b"Existing catalog must survive";
+ std::fs::write(&file.0, sentinel).unwrap();
+ let mut s = session();
+ s.execute(
+ "appearance.assign",
+ &json!({"bodies":["Body1"],"color":"#b47846",
+ "pbr":{"metallic":1,"roughness":0.3,"dielectric_ior":1.5}}),
+ )
+ .unwrap();
+ let before = s.doc.clone();
+ let history = (s.undo.len(), s.redo.len(), s.revision);
+ assert!(s.execute("library.export", &json!({"path":file.0,"format":solidcraft_io::catalog::V1_FORMAT,"overwrite":true})).is_err());
+ assert_eq!(std::fs::read(&file.0).unwrap(), sentinel);
+ assert!(Arc::ptr_eq(&before, &s.doc));
+ assert_eq!(history, (s.undo.len(), s.redo.len(), s.revision));
+ s.execute("library.export", &json!({"path":file.0,"overwrite":true})).unwrap();
+ assert_eq!(Catalog::read(&file.0).unwrap().format, FORMAT);
+ s.execute("appearance.assign", &json!({"bodies":["Body1"],"color":"#b47846"})).unwrap();
+ s.execute("library.export", &json!({"path":file.0,"format":solidcraft_io::catalog::V1_FORMAT,"overwrite":true})).unwrap();
+ assert_eq!(Catalog::read(&file.0).unwrap().format, solidcraft_io::catalog::V1_FORMAT);
+ let rich = rich_catalog();
+ file.write(&rich);
+ s.execute("material.create", &json!({"name":"Timber density","density_g_cm3":0.8,"color":"#b47846"})).unwrap();
+ let before = s.doc.clone();
+ let history = (s.undo.len(), s.redo.len(), s.revision);
+ assert!(apply_entry(&mut s, &file, &rich.entries[1], json!({"bodies":["Body1"]})).is_err());
+ assert!(Arc::ptr_eq(&before, &s.doc));
+ assert_eq!(history, (s.undo.len(), s.redo.len(), s.revision));
+}
+
#[test]
fn catalog_export_obeys_file_scope_in_new_file_and_overwrite_modes() {
let file = File::new();
@@ -237,7 +345,8 @@ fn lossy_scalar_export_never_creates_or_replaces_a_file_or_changes_history() {
std::fs::write(&file.0, b"preserve existing library").unwrap();
}
for overwrite in [false, true] {
- let error = s.execute("library.export", &json!({"path":file.0,"overwrite":overwrite})).unwrap_err();
+ let error =
+ s.execute("library.export", &json!({"path":file.0,"overwrite":overwrite,"format":solidcraft_io::catalog::V1_FORMAT})).unwrap_err();
assert!(error.to_string().contains("cannot preserve PBR"));
if existing {
assert_eq!(std::fs::read(&file.0).unwrap(), b"preserve existing library");
diff --git a/crates/engine/src/cmd/material_card_persistence_tests.rs b/crates/engine/src/cmd/material_card_persistence_tests.rs
new file mode 100644
index 0000000000..6afe0d20fa
--- /dev/null
+++ b/crates/engine/src/cmd/material_card_persistence_tests.rs
@@ -0,0 +1,243 @@
+use crate::{Session, doc::Document, product_scene};
+use serde_json::{Value, json};
+use std::sync::Arc;
+
+fn card() -> Value {
+ json!({"schema_version":1,"designation":"Original synthetic card, not design data","family":"other",
+ "sources":[{"id":"fixture","title":"Original analytic constants","kind":"illustrative","license":"MIT OR Apache-2.0"}],
+ "properties":[{"source_id":"fixture","conditions":{"temperature_k":293.15,"state":"synthetic"},
+ "data":{"kind":"density","kg_m3":700.0}},
+ {"source_id":"fixture","data":{"kind":"elasticity","model":{
+ "symmetry":"isotropic","young_modulus_pa":12.25e9,"poisson_ratio":0.25}}}]})
+}
+
+fn fixture() -> Session {
+ let mut s = Session::default();
+ s.execute("solid.box", &json!({"body_name":"Specimen","length":10,"width":20,"height":5})).unwrap();
+ s.execute(
+ "material.create",
+ &json!({"name":"Synthetic","density_g_cm3":0.8,"color":"#b47846",
+ "pbr":{"metallic":0,"roughness":0.4,"dielectric_ior":1.5}}),
+ )
+ .unwrap();
+ s.execute("material.assign", &json!({"bodies":["Specimen"],"material":"Synthetic"})).unwrap();
+ s
+}
+
+#[test]
+fn card_edits_preserve_mass_optics_and_geometry_and_survive_undo_reopen() {
+ let mut s = fixture();
+ let scene = product_scene::extract(&s).unwrap();
+ let mass = s.execute("component.properties", &json!({})).unwrap();
+ let before_undo = s.undo.len();
+ let out = s.execute("material.edit", &json!({"material":"Synthetic","physical_card":card()})).unwrap();
+ assert_eq!(out["physical_validation"]["isotropic_moduli"]["shear_pa"], 4.9e9);
+ assert_eq!(out["density_comparison"]["assigned_density_kg_m3"], 800.0);
+ assert_eq!(out["density_comparison"]["matches_within_relative_tolerance"], false);
+ assert_eq!(out["physical_validation"]["source_review_required"], json!(["fixture"]));
+ assert_eq!(out["physical_validation"]["analysis_solver_available"], false);
+ assert_eq!(s.undo.len(), before_undo + 1);
+ assert_eq!(s.execute("component.properties", &json!({})).unwrap(), mass);
+ let after = product_scene::extract(&s).unwrap();
+ assert!(Arc::ptr_eq(&scene.meshes[0].mesh, &after.meshes[0].mesh));
+ assert_eq!(scene.meshes[0].surface, after.meshes[0].surface);
+ let saved = s.doc.to_json();
+ assert_eq!(serde_json::from_str::<Value>(&saved).unwrap()["format"], solidcraft_doc::format::format_string(solidcraft_doc::format::FORMAT));
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert!(s.doc.user_materials[0].physical_card.is_none());
+ s.execute("edit.redo", &json!({})).unwrap();
+ let mut reopened = Session::new(Document::from_json(&saved).unwrap());
+ assert_eq!(reopened.execute("component.properties", &json!({})).unwrap(), mass);
+ assert_eq!(reopened.doc.user_materials, s.doc.user_materials);
+ let modulus = reopened.doc.user_materials[0].physical_card.as_ref().unwrap().card().directional_modulus([1., 2., 3.]).unwrap();
+ assert_eq!(modulus.young_modulus_pa, 12.25e9);
+ let doc = reopened.doc.clone();
+ let before = (reopened.revision, reopened.undo.len(), reopened.camera, reopened.selection.clone());
+ let list = reopened.execute("material.list", &json!({})).unwrap();
+ let material = list["materials"].as_array().unwrap().iter().find(|m| m["name"] == "Synthetic").unwrap();
+ assert_eq!(material["physical_card"], out["physical_card"]);
+ assert!(Arc::ptr_eq(&doc, &reopened.doc));
+ assert_eq!(before, (reopened.revision, reopened.undo.len(), reopened.camera, reopened.selection.clone()));
+}
+
+#[test]
+fn omission_retains_null_clears_and_unrelated_material_edits_retain_cards() {
+ let mut s = fixture();
+ s.execute("material.create", &json!({"name":"With card","density_g_cm3":0.7,"physical_card":card()})).unwrap();
+ let original = s.doc.user_materials[1].physical_card.clone();
+ for p in [json!({"density_g_cm3":0.9}), json!({"color":"#112233"}), json!({"name":"Renamed"})] {
+ let mut p = p;
+ p["material"] = json!(s.doc.user_materials[1].name);
+ s.execute("material.edit", &p).unwrap();
+ assert_eq!(s.doc.user_materials[1].physical_card, original);
+ }
+ let mut only_card = Document::default();
+ only_card.user_materials.push(s.doc.user_materials[1].clone());
+ let error = solidcraft_io::catalog::Catalog::from_document(&only_card, "user.fixture", "Original", Default::default())
+ .and_then(|c| c.in_format(solidcraft_io::catalog::V1_FORMAT))
+ .unwrap_err();
+ assert!(error.to_string().contains("engineering cards"));
+ s.execute("material.edit", &json!({"material":"Renamed","physical_card":null})).unwrap();
+ assert!(s.doc.user_materials[1].physical_card.is_none());
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(s.doc.user_materials[1].physical_card, original);
+}
+
+#[test]
+fn hostile_cards_refuse_atomically_and_saved_card_admission_is_not_bypassed() {
+ let mut s = fixture();
+ let mut bad = card();
+ bad["properties"][1]["data"]["model"]["poisson_ratio"] = json!(0.6);
+ let mut oversized = card();
+ oversized["sources"] = json!(vec![json!({}); 33]);
+ let mut unknown = card();
+ unknown["unrecognized"] = json!(true);
+ let mut missing = card();
+ missing["properties"][0]["source_id"] = json!("missing");
+ let doc = s.doc.clone();
+ let before = (s.undo.len(), s.redo.len(), s.revision, s.camera, s.selection.clone());
+ for candidate in [bad, oversized, unknown, missing, json!(true)] {
+ assert!(s.execute("material.edit", &json!({"material":"Synthetic","physical_card":candidate})).is_err());
+ assert!(s.execute("material.create", &json!({"name":"Refused","density_g_cm3":1,"physical_card":candidate})).is_err());
+ assert!(Arc::ptr_eq(&doc, &s.doc));
+ assert_eq!(before, (s.undo.len(), s.redo.len(), s.revision, s.camera, s.selection.clone()));
+ let mut saved = serde_json::to_value(&*s.doc).unwrap();
+ saved["user_materials"][0]["physical_card"] = candidate;
+ assert!(Document::from_json(&saved.to_string()).is_err());
+ assert!(serde_json::from_value::<Document>(saved).is_err());
+ }
+ // Large finite SI constants are accepted only in this typed card, not geometry.
+ let mut saved = serde_json::to_value(&*s.doc).unwrap();
+ saved["user_materials"][0]["physical_card"] = card();
+ assert!(Document::from_json(&saved.to_string()).is_ok());
+ saved["hostile_numeric_probe"] = json!(12.25e9);
+ assert!(Document::from_json(&saved.to_string()).unwrap_err().to_string().contains("number"));
+}
+
+#[test]
+fn configurations_rename_and_paste_new_keep_design_owned_material_semantics() {
+ let mut s = Session::default();
+ let part = s.execute("component.create", &json!({"name":"Part"})).unwrap()["component"].as_u64().unwrap();
+ s.execute("solid.box", &json!({"body_name":"Specimen","length":10,"width":10,"height":10})).unwrap();
+ s.execute("material.create", &json!({"name":"Synthetic","density_g_cm3":0.8,"physical_card":card()})).unwrap();
+ s.execute("config.configure", &json!({"materials":["Specimen"]})).unwrap();
+ s.execute("config.row", &json!({"name":"Candidate","values":{"material:Specimen":"Synthetic"}})).unwrap();
+ s.execute("config.activate", &json!({"row":"Candidate"})).unwrap();
+ s.execute("component.activate", &json!({"component":0})).unwrap();
+ s.execute("component.paste_new", &json!({"component":part,"translate":[30,0,0]})).unwrap();
+ assert_eq!(s.doc.user_materials.len(), 1);
+ assert_eq!(s.doc.materials.values().filter(|m| *m == "Synthetic").count(), 2);
+ let original = s.doc.user_materials[0].physical_card.clone();
+ s.execute("material.edit", &json!({"material":"Synthetic","name":"Renamed candidate"})).unwrap();
+ s.execute("config.activate", &json!({"row":"Default"})).unwrap();
+ s.execute("config.activate", &json!({"row":"Candidate"})).unwrap();
+ let loaded = Document::from_json(&s.doc.to_json()).unwrap();
+ assert_eq!(loaded.user_materials[0].physical_card, original);
+ assert_eq!(loaded.materials.values().filter(|m| *m == "Renamed candidate").count(), 2);
+ assert!(loaded.configs.rows.iter().any(|r| r.cells.iter().any(|c| c == "Renamed candidate")));
+}
+
+#[test]
+fn format21_materials_without_cards_keep_their_optical_look() {
+ let s = fixture();
+ let mut saved = serde_json::to_value(&*s.doc).unwrap();
+ saved["format"] = json!("solidcraft/21");
+ let loaded = Document::from_json(&saved.to_string()).unwrap();
+ assert_eq!(loaded.user_materials, s.doc.user_materials);
+ assert!(loaded.user_materials[0].physical_card.is_none());
+ assert_eq!(loaded.format, solidcraft_doc::format::format_string(solidcraft_doc::format::FORMAT));
+}
+
+#[test]
+fn scalar_catalog_refuses_card_export_without_creating_or_replacing_files_or_history() {
+ struct ProbeFile(std::path::PathBuf);
+ impl Drop for ProbeFile {
+ fn drop(&mut self) {
+ let _ = std::fs::remove_file(&self.0);
+ }
+ }
+ let unique = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();
+ let file = ProbeFile(std::env::temp_dir().join(format!("solidcraft-card-refusal-{}-{unique}.json", std::process::id())));
+ let mut s = Session::default();
+ s.execute("material.create", &json!({"name":"Card only","density_g_cm3":0.8,"physical_card":card()})).unwrap();
+ s.mark_saved();
+ let doc = s.doc.clone();
+ let history = (s.undo.len(), s.redo.len(), s.revision);
+ for existing in [false, true] {
+ if existing {
+ std::fs::write(&file.0, b"keep existing catalog").unwrap();
+ }
+ for overwrite in [false, true] {
+ // The default writer is rich v2. Request scalar v1 explicitly so this
+ // regression still exercises refusal rather than a valid lossless copy.
+ let error =
+ s.execute("library.export", &json!({"path":file.0,"overwrite":overwrite,"format":solidcraft_io::catalog::V1_FORMAT})).unwrap_err();
+ let message = error.to_string();
+ assert!(message.contains("catalog v1") && message.contains("engineering cards"), "{message}");
+ if existing {
+ assert_eq!(std::fs::read(&file.0).unwrap(), b"keep existing catalog");
+ } else {
+ assert!(!file.0.exists());
+ }
+ assert!(Arc::ptr_eq(&doc, &s.doc));
+ assert_eq!((s.undo.len(), s.redo.len(), s.revision), history);
+ assert!(!s.is_dirty());
+ }
+ }
+}
+
+#[test]
+fn native_container_keeps_large_si_card_values_sources_conditions_and_density_separate() {
+ let mut s = fixture();
+ s.execute("material.edit", &json!({"material":"Synthetic","physical_card":card()})).unwrap();
+ let before = s.execute("component.properties", &json!({})).unwrap();
+ let scene = product_scene::extract(&s).unwrap();
+ let native = solidcraft_io::write_design_container(&s.doc).unwrap();
+ assert!(solidcraft_io::is_design_container(&native));
+ let loaded = solidcraft_io::read_design(&native).unwrap();
+ assert_eq!(loaded.format, solidcraft_doc::format::format_string(solidcraft_doc::format::FORMAT));
+ assert_eq!(loaded.user_materials, s.doc.user_materials);
+ let mut reopened = Session::new(loaded);
+ assert_eq!(reopened.execute("component.properties", &json!({})).unwrap(), before);
+ assert_eq!(product_scene::extract(&reopened).unwrap().meshes[0].surface, scene.meshes[0].surface);
+ let list = reopened.execute("material.list", &json!({})).unwrap();
+ let material = list["materials"].as_array().unwrap().iter().find(|m| m["name"] == "Synthetic").unwrap();
+ assert_eq!(material["physical_card"], serde_json::to_value(s.doc.user_materials[0].physical_card.as_ref().unwrap()).unwrap());
+ assert_eq!(material["density_comparison"]["assigned_density_kg_m3"], 800.0);
+ assert_eq!(material["density_comparison"]["card_density_kg_m3"], 700.0);
+ assert_eq!(material["physical_validation"]["source_review_required"], json!(["fixture"]));
+}
+
+#[test]
+fn format20_materials_without_cards_upgrade_to21_without_changing_their_optical_look() {
+ let s = fixture();
+ let mut saved = serde_json::to_value(&*s.doc).unwrap();
+ saved["format"] = json!("solidcraft/20");
+ let loaded = Document::from_json(&saved.to_string()).unwrap();
+ assert_eq!(loaded.user_materials, s.doc.user_materials);
+ assert!(loaded.user_materials[0].physical_card.is_none());
+ assert_eq!(loaded.format, solidcraft_doc::format::format_string(solidcraft_doc::format::FORMAT));
+}
+
+#[test]
+fn card_number_admission_preserves_metadata_without_exempting_other_material_fields() {
+ let s = fixture();
+ let mut saved = serde_json::to_value(&*s.doc).unwrap();
+ saved["user_materials"][0]["physical_card"] = card();
+ let metadata = json!({"org.example.measurement":{"value":12.25e9,"physical_card":{"untyped":12.25e9}}});
+ saved["metadata"] = metadata.clone();
+ let loaded = Document::from_json(&saved.to_string()).unwrap();
+ let reopened = solidcraft_io::read_design(&solidcraft_io::write_design_container(&loaded).unwrap()).unwrap();
+ assert_eq!(serde_json::to_value(&reopened.metadata).unwrap(), metadata);
+ assert_eq!(reopened.user_materials, loaded.user_materials);
+
+ // Only the exact root user-material card receives SI admission. The same key
+ // nested elsewhere must not exempt a hostile number from geometry limits.
+ for field in ["appearance", "unrecognized"] {
+ let mut hostile = saved.clone();
+ hostile["user_materials"][0][field] = json!({"physical_card":{"untyped":12.25e9}});
+ assert!(Document::from_json(&hostile.to_string()).unwrap_err().to_string().contains("number"));
+ }
+ saved["user_materials"][0]["density"] = json!(12.25e9);
+ assert!(Document::from_json(&saved.to_string()).unwrap_err().to_string().contains("number"));
+}
diff --git a/crates/engine/src/cmd/materials.rs b/crates/engine/src/cmd/materials.rs
index 233748a237..ced81e4df8 100644
--- a/crates/engine/src/cmd/materials.rs
+++ b/crates/engine/src/cmd/materials.rs
@@ -7,7 +7,7 @@
use serde_json::{Value, json};
use solidcraft_doc::appearance::{Look, library};
use solidcraft_doc::config::Column;
-use solidcraft_doc::{DEFAULT_MATERIAL, MATERIALS, UserMaterial, valid_density};
+use solidcraft_doc::{DEFAULT_MATERIAL, MATERIALS, MAX_USER_MATERIALS, UserMaterial, valid_density};
use super::CommandSpec;
use super::inspect::{color_param, look_json};
@@ -16,18 +16,19 @@ use crate::{Result, Session};
pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("material.create", "New Physical Material", create).icon("material").params(
- "name (not a built-in material's); density_g_cm3: (0, 1000]; appearance?: library name (appearance.library) | color?: \"#rrggbb\" or [r, g, b] (0–255), opacity? (0–1), pbr?: {metallic:0..1, roughness:0.045..1, dielectric_ior:1..3} (opaque only, needs color/appearance): the default look. Optical edits do not change density. Assign it with material.assign",
+ "name (not a built-in material's); density_g_cm3: (0, 1000]; appearance?: library name (appearance.library) | color?: \"#rrggbb\" or [r, g, b] (0–255), opacity? (0–1), pbr?: {metallic:0..1, roughness:0.045..1, dielectric_ior:1..3} (opaque only, needs color/appearance): the default look. Optical edits do not change density. physical_card?: validated SI candidate record (null/omitted means unknown); card density never changes assigned density. Assign it with material.assign",
),
CommandSpec::new("material.edit", "Edit Physical Material", edit).icon("material").enabled(has_user_materials).params(
- "material: a material defined in this design; name? (bodies and configuration cells follow); density_g_cm3?; appearance? | color?, opacity?, pbr? (as material.create; color: null clears the look). Omitted appearance/color retains the entire current look",
+ "material: a material defined in this design; name? (bodies and configuration cells follow); density_g_cm3?; appearance? | color?, opacity?, pbr? (as material.create; color: null clears the look). physical_card?: validated SI candidate record (omitted retains, null clears). Omitted appearance/color retains the entire current look",
),
CommandSpec::new("material.delete", "Delete Physical Material", delete).icon("delete").enabled(has_user_materials).params(
"material: a material defined in this design; replace?: material for the bodies and configuration cells that use it (without it, a material in use is refused)",
),
];
-/// Most materials a design defines.
-const MAX_USER_MATERIALS: usize = 1000;
+#[cfg(test)]
+#[path = "material_card_persistence_tests.rs"]
+mod persistence_tests;
fn has_user_materials(s: &Session) -> std::result::Result<(), String> {
if s.doc.user_materials.is_empty() { Err("the design defines no physical materials (material.create)".into()) } else { Ok(()) }
@@ -86,8 +87,35 @@ fn look(cmd: &str, p: &Value, material: &str) -> Result<Option<Option<Look>>> {
Ok(Some(Some(l)))
}
-fn material_json(m: &UserMaterial) -> Value {
- json!({"name": m.name, "density_g_cm3": m.density, "appearance": m.appearance.as_ref().map(look_json), "user": true})
+pub(super) fn material_json(m: &UserMaterial) -> Result<Value> {
+ let mut out = json!({"name": m.name, "density_g_cm3": m.density, "appearance": m.appearance.as_ref().map(look_json), "user": true});
+ if let Some(record) = &m.physical_card {
+ let card = record.card();
+ out["physical_card"] = json!(record);
+ out["physical_validation"] = json!(card.validate()?);
+ let measured = card.properties.iter().find_map(|p| match p.data {
+ solidcraft_doc::physical_material::PropertyData::Density { kg_m3 } => Some(kg_m3),
+ _ => None,
+ });
+ if let Some(measured) = measured {
+ let assigned = m.density * 1000.0;
+ let relative_difference = (assigned - measured).abs() / assigned.max(measured);
+ out["density_comparison"] = json!({"assigned_density_kg_m3":assigned,"card_density_kg_m3":measured,
+ "relative_difference":relative_difference,"matches_within_relative_tolerance":relative_difference <= 1e-9,
+ "relative_tolerance":1e-9});
+ }
+ }
+ Ok(out)
+}
+
+fn physical_card(cmd: &str, p: &Value) -> Result<Option<Option<solidcraft_doc::physical_material::ValidatedCard>>> {
+ match p.get("physical_card") {
+ None => Ok(None),
+ Some(Value::Null) => Ok(Some(None)),
+ Some(value) => {
+ solidcraft_doc::physical_material::ValidatedCard::from_value(value).map(|card| Some(Some(card))).map_err(|e| bad(cmd, e.to_string()))
+ }
+ }
}
/// The index of the design material `material` names.
@@ -106,8 +134,9 @@ fn create(s: &mut Session, p: &Value) -> Result<Value> {
if s.doc.user_materials.len() >= MAX_USER_MATERIALS {
return Err(bad(cmd, format!("a design defines at most {MAX_USER_MATERIALS} materials")));
}
- let material = UserMaterial { density: density(cmd, p)?, appearance: look(cmd, p, &name)?.flatten(), name };
- let out = material_json(&material);
+ let material =
+ UserMaterial { density: density(cmd, p)?, appearance: look(cmd, p, &name)?.flatten(), name, physical_card: physical_card(cmd, p)?.flatten() };
+ let out = material_json(&material)?;
s.doc_mut().user_materials.push(material);
Ok(out)
}
@@ -173,8 +202,9 @@ fn edit(s: &mut Session, p: &Value) -> Result<Value> {
l
}),
};
- let material = UserMaterial { name: name.clone(), density, appearance };
- let mut out = material_json(&material);
+ let physical_card = physical_card(cmd, p)?.unwrap_or(old.physical_card);
+ let material = UserMaterial { name: name.clone(), density, appearance, physical_card };
+ let mut out = material_json(&material)?;
if let Some(m) = s.doc_mut().user_materials.get_mut(i) {
*m = material;
}
diff --git a/crates/engine/src/cmd/pbr_appearance_tests.rs b/crates/engine/src/cmd/pbr_appearance_tests.rs
index 00cd3e0684..5933d2b7a5 100644
--- a/crates/engine/src/cmd/pbr_appearance_tests.rs
+++ b/crates/engine/src/cmd/pbr_appearance_tests.rs
@@ -89,7 +89,11 @@ fn invalid_optical_requests_refuse_atomically_and_scalar_export_cannot_lose_them
"pbr":{"metallic":0,"roughness":0.5,"dielectric_ior":1.5}}),
)
.unwrap();
- assert!(solidcraft_io::catalog::Catalog::from_document(&s.doc, "user.fixture", "Original", Default::default()).is_err());
+ assert!(
+ solidcraft_io::catalog::Catalog::from_document(&s.doc, "user.fixture", "Original", Default::default())
+ .and_then(|c| c.in_format(solidcraft_io::catalog::V1_FORMAT))
+ .is_err()
+ );
let mut invalid: serde_json::Value = serde_json::from_str(&s.doc.to_json()).unwrap();
invalid["appearances"]["bodies"]["Specimen"]["opacity"] = json!(0.5);
assert!(crate::doc::Document::from_json(&invalid.to_string()).is_err());
@@ -115,7 +119,11 @@ fn physical_default_look_and_face_override_keep_independent_optical_meaning() {
assert!(scene.meshes[0].surface.is_some());
assert!(scene.meshes[0].faces.iter().any(|f| f.color == [0, 128, 160] && f.surface.is_none()));
assert_eq!(s.doc.user_materials[0].density, 0.7);
- assert!(solidcraft_io::catalog::Catalog::from_document(&s.doc, "user.fixture", "Original", Default::default()).is_err());
+ assert!(
+ solidcraft_io::catalog::Catalog::from_document(&s.doc, "user.fixture", "Original", Default::default())
+ .and_then(|c| c.in_format(solidcraft_io::catalog::V1_FORMAT))
+ .is_err()
+ );
}
#[test]
@@ -144,3 +152,213 @@ fn independent_component_copy_keeps_its_opaque_response_after_source_edits_and_r
let reopened = crate::doc::Document::from_json(&s.doc.to_json()).unwrap();
assert_eq!(reopened.appearances.components[&copied], original);
}
+
+fn pack_session() -> Session {
+ let mut s = Session::default();
+ s.execute("solid.box", &json!({"length":10,"width":20,"height":30,"body_name":"Swatch"})).unwrap();
+ s.execute("material.assign", &json!({"bodies":["Swatch"],"material":"Aluminum"})).unwrap();
+ s
+}
+
+#[test]
+fn copied_recipe_id_labels_are_inert_and_explicit_recipe_requests_stay_strict() {
+ let mut s = fixture();
+ for name in ["starter.metal.gold-warm", "starter.glass.clear-soda-lime"] {
+ for pbr in [serde_json::Value::Null, json!({"metallic":0.0,"roughness":0.73,"dielectric_ior":1.37})] {
+ s.execute("appearance.assign", &json!({"bodies":["Specimen"],"name":name,"color":[31,61,91],"opacity":1.0,"pbr":pbr})).unwrap();
+ let look = &s.doc.appearances.bodies["Specimen"];
+ assert_eq!(look.name, name);
+ assert_eq!(look.color, [31, 61, 91]);
+ assert_eq!(serde_json::to_value(look.pbr).unwrap(), pbr);
+ assert_eq!(product_scene::extract(&s).unwrap().meshes[0].surface.is_some(), !pbr.is_null());
+ }
+ }
+ let before = s.doc.clone();
+ let history = (s.undo.len(), s.redo.len(), s.revision);
+ for params in [
+ json!({"bodies":["Specimen"],"name":"Owned label"}),
+ json!({"bodies":["Specimen"],"name":"Owned label","appearance":"starter.metal.gold-warm","color":[31,61,91]}),
+ json!({"bodies":["Specimen"],"appearance":"starter.glass.clear-soda-lime","color":[31,61,91],"pbr":null}),
+ json!({"bodies":["Specimen"],"name":"x".repeat(129),"color":[31,61,91]}),
+ ] {
+ assert!(s.execute("appearance.assign", &params).is_err());
+ assert!(Arc::ptr_eq(&before, &s.doc));
+ assert_eq!((s.undo.len(), s.redo.len(), s.revision), history);
+ }
+ s.execute("appearance.assign", &json!({"bodies":["Specimen"],"appearance":"starter.metal.gold-warm"})).unwrap();
+ assert_eq!(s.doc.appearances.bodies["Specimen"].name, "Metal - Warm Reflective Gold");
+ assert_eq!(s.doc.appearances.bodies["Specimen"].pbr.unwrap().metallic(), 1.0);
+}
+
+#[test]
+fn pack_listing_keeps_legacy_rows_and_labels_unavailable_recipes_without_mutation() {
+ let mut s = pack_session();
+ let doc = s.doc.clone();
+ let undo = s.undo.len();
+ let reply = s.execute("appearance.library", &json!({})).unwrap();
+ let rows = reply["appearances"].as_array().unwrap();
+ // Compatibility fixture: exact pre-pack scalar library, independent of the
+ // separate six PBR finishes (#1366), which may also have no catalog IDs.
+ let legacy: [(&str, [u8; 3], f64); 20] = [
+ ("Aluminum - Satin", [204, 208, 214], 1.0),
+ ("Aluminum - Anodized Black", [44, 46, 50], 1.0),
+ ("Aluminum - Anodized Blue", [52, 92, 160], 1.0),
+ ("Steel - Satin", [158, 164, 172], 1.0),
+ ("Stainless Steel - Brushed", [186, 191, 198], 1.0),
+ ("Cast Iron", [104, 104, 110], 1.0),
+ ("Brass - Polished", [208, 172, 88], 1.0),
+ ("Copper", [204, 122, 80], 1.0),
+ ("Titanium", [150, 148, 158], 1.0),
+ ("ABS - White", [236, 236, 230], 1.0),
+ ("ABS - Black", [36, 36, 38], 1.0),
+ ("ABS - Red", [196, 40, 40], 1.0),
+ ("ABS - Blue", [40, 90, 186], 1.0),
+ ("ABS - Yellow", [236, 196, 40], 1.0),
+ ("ABS - Green", [52, 150, 80], 1.0),
+ ("Rubber - Black", [28, 28, 28], 1.0),
+ ("Glass - Clear", [190, 220, 228], 0.25),
+ ("Glass - Smoked", [90, 96, 104], 0.45),
+ ("Wood - Oak", [190, 146, 92], 1.0),
+ ("Paint - Gloss White", [246, 246, 244], 1.0),
+ ];
+ assert_eq!(solidcraft_doc::appearance::LIBRARY, legacy);
+ for (name, color, opacity) in legacy {
+ let matching: Vec<_> = rows.iter().filter(|row| row["name"] == name).collect();
+ assert_eq!(matching.len(), 1, "legacy appearance must occur exactly once: {name}");
+ let row = matching[0];
+ assert_eq!(row["color"], format!("#{:02x}{:02x}{:02x}", color[0], color[1], color[2]));
+ assert_eq!(row["opacity"], opacity);
+ assert!(row.get("id").is_none() && row.get("pbr").is_none(), "legacy scalar meaning changed: {name}");
+ }
+ assert_eq!(rows.len(), 60);
+ assert_eq!(rows.iter().filter(|row| row["available"] != false).count(), 54);
+ assert_eq!(rows.iter().filter(|row| row["available"] != false && row["opacity"] == 1.0).count(), 52);
+ assert_eq!(rows.iter().filter(|row| row["opacity"] != 1.0).count(), 2);
+ assert_eq!(rows.iter().filter(|v| v.get("id").is_some()).count(), 40);
+ assert_eq!(rows.iter().filter(|v| v["available"] == false).count(), 6);
+ for row in rows.iter().filter(|v| v["category"] == "glass") {
+ assert_eq!(row["available"], false);
+ assert_eq!(row["opacity"], 1.0);
+ assert!(row["pbr"].is_null());
+ assert_eq!(row["requirements"], json!(["refraction", "certified_thin_or_closed"]));
+ }
+ assert!(Arc::ptr_eq(&doc, &s.doc));
+ assert_eq!(s.undo.len(), undo);
+}
+
+#[test]
+fn opaque_pack_uses_normal_assignment_undo_and_preserves_engineering_properties() {
+ let mut s = pack_session();
+ let before = s.doc.clone();
+ let undo = s.undo.len();
+ let density = s.doc.density("Swatch");
+ let physical = s.execute("component.properties", &json!({"component":"root"})).unwrap()["total"].clone();
+ s.execute("appearance.assign", &json!({"bodies":["Swatch"],"appearance":"starter.metal.gold-warm"})).unwrap();
+ let look = s.doc.appearances.bodies.get("Swatch").unwrap();
+ assert_eq!(look.pbr.unwrap().metallic(), 1.0);
+ assert_eq!(look.opacity, 1.0);
+ assert_eq!(s.undo.len(), undo + 1);
+ assert_eq!(s.doc.density("Swatch"), density);
+ assert_eq!(s.execute("component.properties", &json!({"component":"root"})).unwrap()["total"], physical);
+ let assigned = s.doc.clone();
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(*s.doc, *before);
+ s.execute("edit.redo", &json!({})).unwrap();
+ assert_eq!(*s.doc, *assigned);
+}
+
+#[test]
+fn unavailable_glass_and_invalid_opaque_override_refuse_atomically() {
+ let mut s = pack_session();
+ let doc = s.doc.clone();
+ let before = (s.revision, s.undo.len(), s.redo.len(), s.is_dirty());
+ for extra in [json!({}), json!({"color":"#ffffff"}), json!({"opacity":0.25,"pbr":null})] {
+ let mut params = json!({"bodies":["Swatch"],"appearance":"starter.glass.clear-soda-lime"});
+ params.as_object_mut().unwrap().extend(extra.as_object().unwrap().clone());
+ assert!(s.execute("appearance.assign", &params).unwrap_err().to_string().contains("refraction"));
+ assert!(Arc::ptr_eq(&doc, &s.doc));
+ assert_eq!(before, (s.revision, s.undo.len(), s.redo.len(), s.is_dirty()));
+ }
+ assert!(s.execute("appearance.assign", &json!({"bodies":["Swatch"],"appearance":"starter.wood.oak-honey","opacity":0.4})).is_err());
+ assert!(Arc::ptr_eq(&doc, &s.doc));
+ assert_eq!(before, (s.revision, s.undo.len(), s.redo.len(), s.is_dirty()));
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+#[test]
+fn cold_native_reopen_keeps_owned_opaque_values_without_pack_metadata_or_assets() {
+ let mut s = pack_session();
+ s.execute("appearance.assign", &json!({"bodies":["Swatch"],"appearance":"starter.wood.walnut-dark"})).unwrap();
+ let look = s.doc.appearances.bodies.get("Swatch").unwrap().clone();
+ let density = s.doc.density("Swatch");
+ let nonce = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();
+ let dir = std::env::temp_dir().join(format!("solidcraft-pack-{}-{nonce}", std::process::id()));
+ std::fs::create_dir(&dir).unwrap();
+ let path = dir.join("opaque.solidcraft");
+ s.execute("file.save", &json!({"path":path.to_str().unwrap()})).unwrap();
+ let mut reopened = Session::default();
+ reopened.execute("doc.open", &json!({"path":path.to_str().unwrap()})).unwrap();
+ assert_eq!(reopened.doc.appearances.bodies.get("Swatch"), Some(&look));
+ assert_eq!(reopened.doc.density("Swatch"), density);
+ let json = reopened.doc.to_json();
+ assert!(!json.contains("starter.wood.walnut-dark") && !json.contains("starter_pack.rs"));
+ std::fs::remove_dir_all(dir).unwrap();
+}
+
+#[test]
+fn starter_selectors_keep_final_validation_and_custom_names_stay_inert() {
+ let mut s = pack_session();
+ let preset = solidcraft_doc::appearance_pack::find("starter.wood.oak-honey").unwrap();
+ let doc = s.doc.clone();
+ let history = (s.undo.len(), s.redo.len(), s.revision);
+ for selector in [preset.id, preset.name] {
+ for opacity in [json!(0.5), json!(2.0), json!("1"), json!(null)] {
+ assert!(s.execute("appearance.assign", &json!({"bodies":["Swatch"],"appearance":selector,"opacity":opacity})).is_err());
+ assert!(Arc::ptr_eq(&doc, &s.doc));
+ assert_eq!((s.undo.len(), s.redo.len(), s.revision), history);
+ }
+ }
+ s.execute("appearance.assign", &json!({"bodies":["Swatch"],"appearance":preset.id,"pbr":null,"opacity":0.4})).unwrap();
+ assert!(s.doc.appearances.bodies["Swatch"].pbr.is_none());
+ assert_eq!(s.doc.appearances.bodies["Swatch"].opacity, 0.4);
+ // A copied name is inert; it is not a request to select the registered recipe.
+ s.execute("appearance.assign", &json!({"bodies":["Swatch"],"name":preset.name,"color":"#123456","opacity":0.6})).unwrap();
+ let look = &s.doc.appearances.bodies["Swatch"];
+ assert_eq!((look.name.as_str(), look.color, look.opacity, look.pbr), (preset.name, [18, 52, 86], 0.6, None));
+ s.execute("appearance.assign", &json!({"bodies":["Swatch"],"appearance":preset.name})).unwrap();
+ assert_eq!(s.doc.appearances.bodies["Swatch"], preset.opaque_look().unwrap());
+}
+
+#[test]
+fn starter_names_and_ids_share_admission_before_all_overrides() {
+ use crate::doc::appearance_pack::{Recipe, STARTER_PACK};
+ let mut s = pack_session();
+ for preset in &STARTER_PACK {
+ for selector in [preset.id, preset.name] {
+ if matches!(preset.recipe, Recipe::Glass(_)) {
+ for overrides in [
+ json!({}),
+ json!({"color":"#aabbcc"}),
+ json!({"color":"#aabbcc","opacity":0.5,"pbr":null}),
+ json!({"color":"#aabbcc","pbr":{"metallic":0.0,"roughness":0.5,"dielectric_ior":1.5}}),
+ ] {
+ let before = s.doc.clone();
+ let history = (s.undo.len(), s.redo.len(), s.revision);
+ let mut params = overrides;
+ params["bodies"] = json!(["Swatch"]);
+ params["appearance"] = json!(selector);
+ let error = s.execute("appearance.assign", &params).unwrap_err().to_string();
+ assert!(error.contains("refraction"), "{selector}: {error}");
+ assert!(Arc::ptr_eq(&before, &s.doc));
+ assert_eq!((s.undo.len(), s.redo.len(), s.revision), history);
+ }
+ } else {
+ s.execute("appearance.assign", &json!({"bodies":["Swatch"],"appearance":selector,"color":[31,61,91]})).unwrap();
+ let look = &s.doc.appearances.bodies["Swatch"];
+ assert_eq!(look.name, preset.name);
+ assert_eq!(look.color, [31, 61, 91]);
+ assert_eq!(look.pbr, preset.opaque_look().unwrap().pbr);
+ }
+ }
+ }
+}
diff --git a/crates/engine/src/cmd/render.rs b/crates/engine/src/cmd/render.rs
index e516b985f3..90d8b8e554 100644
--- a/crates/engine/src/cmd/render.rs
+++ b/crates/engine/src/cmd/render.rs
@@ -10,11 +10,15 @@ use super::CommandSpec;
use crate::params::bad;
use crate::{Result, Session};
+mod clear_coat;
+mod environment;
mod jobs;
+mod textures;
+mod transmission;
pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("render.preflight", "Check Render Request", jobs::preflight).icon("inspect").noundo().doc_only()
- .params("setup?: saved name OR settings?: full RenderSetup; transparent_background?: false; replace?: false. Validates the installed image host and bounded captured product scene without starting work. Stale geometry is rejected. See docs/render-jobs.md"),
+ .params("setup?: saved name OR settings?: full RenderSetup; transparent_background?: false; replace?: false; progressive?: false; samples?: 1..4096 (64); max_depth?: 1..16 (8); seed?: u32 (0). raytrace?: {dielectrics: up to eight runtime body overrides, clear_coats: up to 64 runtime opaque coat overrides, textures: bounded body mappings (docs/render-runtime-textures.md)} (see docs/render-transmission.md); lens?: {aperture_radius_mm, focus_distance_mm} (see docs/render-thin-lens.md). environment?: {kind: hdr, path, assume_linear_srgb?} OR {kind: sky, gradient?}, with rotation_rad/intensity (docs/render-environment.md); lighting?: {sun?: {direction,angular_radius_rad,radiance}, environment: [r,g,b], area_lights: [{center,u,v,radiance}]} and tone_map?: reinhard|aces_fitted (docs/render-studio-lighting.md); denoise?: bool (false), native GPU final edge-aware filter (docs/render-denoise.md). Sampling, exposure, transmission, clear-coat, texture, lens, lighting, tone-map and denoise controls require progressive rendering. Validates the installed image host and bounded captured product scene without starting work. Stale geometry is rejected. See docs/render-jobs.md"),
CommandSpec::new("render.start", "Render Image", jobs::start).noundo().doc_only().at("RENDER", "IMAGE").icon("render_image")
.params("Same request as render.preflight. Captures an immutable product scene and queues a bounded image job. Returns its session-scoped job identity, captured scene_generation and progress. Does not change the design. See docs/render-jobs.md"),
CommandSpec::new("render.status", "Render Progress", jobs::status).icon("list").noundo().doc_only()
@@ -45,7 +49,8 @@ fn scene(s: &mut Session, params: &Value) -> Result<Value> {
let bodies: Vec<_> = scene
.meshes
.iter()
- .map(|m| json!({"name":m.name,"triangles":m.mesh.triangles.len(),"color":m.color,"opacity":m.opacity,"face_appearances":m.faces.len()}))
+ .enumerate()
+ .map(|(ordinal,m)| json!({"ordinal":ordinal,"name":m.name,"triangles":m.mesh.triangles.len(),"color":m.color,"opacity":m.opacity,"face_appearances":m.faces.len()}))
.collect();
Ok(
json!({"bodies":bodies,"bounds":if scene.bounds.is_empty() { Value::Null } else { json!({"min":scene.bounds.min,"max":scene.bounds.max}) },"overlays":false}),
diff --git a/crates/engine/src/cmd/render/clear_coat.rs b/crates/engine/src/cmd/render/clear_coat.rs
new file mode 100644
index 0000000000..f8a47a35c7
--- /dev/null
+++ b/crates/engine/src/cmd/render/clear_coat.rs
@@ -0,0 +1,87 @@
+//! Request-only coat overrides on immutable captured geometry; no saved appearance changes.
+use crate::{Result, params::bad};
+use serde::Deserialize;
+use solidcraft_geom::Vec3;
+use solidcraft_render::{
+ ProductScene,
+ clear_coat::ClearCoat,
+ surface::{OpaqueSurface, srgb8_to_linear},
+};
+
+#[derive(Deserialize)]
+#[serde(deny_unknown_fields)]
+pub(super) struct Override {
+ body_index: usize,
+ body_name: String,
+ weight: f64,
+ roughness: f64,
+ ior: f64,
+}
+pub(super) fn apply(scene: &mut ProductScene, overrides: &[Override], command: &str) -> Result<()> {
+ if overrides.len() > 64 {
+ return Err(bad(command, "at most 64 runtime clear-coat overrides are supported"));
+ }
+ let mut ordinals = std::collections::BTreeSet::new();
+ for input in overrides {
+ if input.body_name.is_empty()
+ || input.body_name.len() > 1024
+ || input.body_name.chars().any(char::is_control)
+ || !ordinals.insert(input.body_index)
+ {
+ return Err(bad(command, "clear coats require bounded names and distinct captured body ordinals"));
+ }
+ let coat = ClearCoat::new(input.weight, input.roughness, input.ior).map_err(|e| bad(command, e.to_string()))?;
+ let body = scene
+ .meshes
+ .get_mut(input.body_index)
+ .filter(|m| m.name == input.body_name)
+ .ok_or_else(|| bad(command, "clear-coat body ordinal and exact name must both match render.scene"))?;
+ // A zero-weight override is a true no-op, including legacy appearances.
+ if coat.weight() == 0.0 {
+ continue;
+ }
+ if body.transmission.is_some() || body.faces.iter().any(|f| f.transmission.is_some()) {
+ return Err(bad(command, "clear coat and transmission cannot share a body"));
+ }
+ let surface = |color: [u8; 3], existing: Option<OpaqueSurface>| -> Result<OpaqueSurface> {
+ let [r, g, b] = color.map(srgb8_to_linear);
+ let base =
+ existing.map(Ok).unwrap_or_else(|| OpaqueSurface::new(Vec3::new(r, g, b), 0.0, 0.5, 1.5)).map_err(|e| bad(command, e.to_string()))?;
+ Ok(base.with_clear_coat(coat))
+ };
+ body.surface = Some(surface(body.color, body.surface)?);
+ for face in &mut body.faces {
+ face.surface = Some(surface(face.color, face.surface)?);
+ }
+ }
+ Ok(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+ #[test]
+ fn coat_is_runtime_only_and_validates_exact_body_and_values() {
+ let mut s = crate::Session::default();
+ s.execute("solid.box", &json!({"length":10,"width":10,"height":2,"body_name":"Housing"})).unwrap();
+ let saved = s.doc.to_json();
+ let original = crate::product_scene::extract(&s).unwrap();
+ let input = json!({"body_index":0,"body_name":"Housing","weight":1,"roughness":0.12,"ior":1.5});
+ let mut scene = original.clone();
+ apply(&mut scene, &[serde_json::from_value(input.clone()).unwrap()], "render.start").unwrap();
+ assert!(scene.meshes[0].surface.unwrap().clear_coat().is_some());
+ assert!(std::sync::Arc::ptr_eq(&scene.meshes[0].mesh, &original.meshes[0].mesh));
+ assert_eq!(s.doc.to_json(), saved);
+ assert!(crate::product_scene::extract(&s).unwrap().meshes[0].surface.is_none_or(|s| s.clear_coat().is_none()));
+ for (key, value) in
+ [("weight", json!(-0.1)), ("roughness", json!(0)), ("ior", json!(4)), ("body_index", json!(1)), ("body_name", json!("Wrong"))]
+ {
+ let mut bad_input = input.clone();
+ bad_input[key] = value;
+ assert!(apply(&mut original.clone(), &[serde_json::from_value(bad_input).unwrap()], "render.start").is_err());
+ }
+ let duplicate = serde_json::from_value::<Vec<Override>>(json!([input, input])).unwrap();
+ assert!(apply(&mut original.clone(), &duplicate, "render.start").is_err());
+ }
+}
diff --git a/crates/engine/src/cmd/render/environment.rs b/crates/engine/src/cmd/render/environment.rs
new file mode 100644
index 0000000000..ed3dadb225
--- /dev/null
+++ b/crates/engine/src/cmd/render/environment.rs
@@ -0,0 +1,48 @@
+//! Runtime environment inputs. Captures bytes through the caller's scoped VFS.
+use crate::{Result, params::bad};
+use serde::Deserialize;
+use solidcraft_render::lighting::{
+ MAX_HDR_BYTES,
+ environment::{EnvironmentResource, EnvironmentSource, SkyGradient},
+};
+use std::sync::Arc;
+fn unit() -> f64 {
+ 1.0
+}
+#[derive(Deserialize)]
+#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
+pub(super) enum Input {
+ Hdr {
+ path: String,
+ #[serde(default)]
+ rotation_rad: f64,
+ #[serde(default = "unit")]
+ intensity: f64,
+ #[serde(default)]
+ assume_linear_srgb: bool,
+ },
+ Sky {
+ #[serde(default)]
+ gradient: SkyGradient,
+ #[serde(default)]
+ rotation_rad: f64,
+ #[serde(default = "unit")]
+ intensity: f64,
+ },
+}
+impl Input {
+ pub(super) fn capture(&self, command: &str) -> Result<EnvironmentResource> {
+ let source = match self {
+ Self::Hdr { path, rotation_rad, intensity, assume_linear_srgb } => {
+ if path.is_empty() || path.len() > 4096 || path.chars().any(char::is_control) {
+ return Err(bad(command, "bounded HDR path required"));
+ }
+ let bytes = solidcraft_io::vfs::read(path, MAX_HDR_BYTES).map_err(|e| bad(command, format!("could not capture HDR: {e}")))?;
+ EnvironmentSource::hdr(bytes, *rotation_rad, *intensity, *assume_linear_srgb)
+ }
+ Self::Sky { gradient, rotation_rad, intensity } => EnvironmentSource::sky(*gradient, *rotation_rad, *intensity),
+ }
+ .map_err(|e| bad(command, e.to_string()))?;
+ Ok(Arc::new(source))
+ }
+}
diff --git a/crates/engine/src/cmd/render/job_tests.rs b/crates/engine/src/cmd/render/job_tests.rs
index 3caec0b444..d48265a651 100644
--- a/crates/engine/src/cmd/render/job_tests.rs
+++ b/crates/engine/src/cmd/render/job_tests.rs
@@ -23,6 +23,94 @@ fn finish(host: &CpuHost) {
panic!("cooperative job did not finish");
}
+#[cfg(not(target_arch = "wasm32"))]
+#[test]
+fn additional_executor_routes_by_capability_and_survives_document_adoption() {
+ use solidcraft_render::job::{Admission, CancelToken, ImageExecutor, ImageHost, ImageRequest, ImageTask, ImageWork, JobOptions};
+ struct Progressive;
+ impl ImageExecutor for Progressive {
+ fn descriptor(&self) -> solidcraft_render::job::Result<solidcraft_render::ExecutorDescriptor> {
+ let mut descriptor = CpuHost::cooperative().descriptor()?;
+ descriptor.id = solidcraft_render::ExecutorId::new("test-progressive").unwrap();
+ descriptor.profiles[0].features.push(solidcraft_render::RenderFeature::Progressive);
+ descriptor.profiles[0].features.push(solidcraft_render::RenderFeature::Hdri);
+ Ok(descriptor)
+ }
+ fn admit(
+ &self,
+ scene: &solidcraft_render::ProductScene,
+ request: &ImageRequest,
+ options: JobOptions,
+ ) -> solidcraft_render::job::Result<Admission> {
+ options.validate()?;
+ // admit_geometry counts source geometry only; this executor renders through the
+ // CPU task, which ignores the environment and textures, so budget its pixels and
+ // PNG with the CPU estimate for the same frame.
+ solidcraft_render::job::admit(scene, &ImageRequest { environment: None, textures: None, ..request.clone() })
+ }
+ fn begin(
+ &self,
+ scene: solidcraft_render::ProductScene,
+ request: ImageRequest,
+ _: JobOptions,
+ cancel: CancelToken,
+ ) -> solidcraft_render::job::Result<Box<dyn ImageWork>> {
+ Ok(Box::new(ImageTask::new(scene, request, cancel)?))
+ }
+ }
+ let (mut session, cpu) = session();
+ let additional = ImageHost::with_executor(Arc::new(Progressive)).unwrap();
+ session.register_render_job_host(additional.clone()).unwrap();
+ assert!(
+ session.register_render_job_host(ImageHost::with_executor(Arc::new(Progressive)).unwrap()).is_err(),
+ "duplicate executor IDs must be rejected"
+ );
+ let cpu_id = start(&mut session);
+ let request = json!({"settings":{"width":16,"height":16},"progressive":true,"samples":3});
+ let preflight = session.execute("render.preflight", &request).unwrap();
+ assert_eq!(preflight["resolved"]["executor"], "test-progressive");
+ assert_eq!(additional.admitted_bytes(), 0);
+ let mut studio = request.clone();
+ studio["lighting"] = json!({"environment":[1,1,1],"area_lights":[{"center":[0,0,10],"u":[2,0,0],"v":[0,-2,0],"radiance":[4,4,4]}]});
+ studio["tone_map"] = json!("aces_fitted");
+ let document = session.doc.clone();
+ let studio_reply = session.execute("render.preflight", &studio).unwrap();
+ assert_eq!(studio_reply["options"]["lighting"]["environment"], json!([1.0, 1.0, 1.0]));
+ assert_eq!(studio_reply["options"]["tone_map"], "aces_fitted");
+ assert!(Arc::ptr_eq(&document, &session.doc));
+ studio["environment"] = json!({"kind":"sky","intensity":0.5,"rotation_rad":0.3});
+ let env_reply = session.execute("render.preflight", &studio).unwrap();
+ assert_eq!(env_reply["environment"]["kind"], "original_gradient_sky");
+ assert_eq!(env_reply["environment"]["width"], 512);
+ assert_eq!(env_reply["environment"]["source_sha256"].as_str().unwrap().len(), 64);
+ assert!(env_reply["request"].get("environment").is_none());
+ assert!(Arc::ptr_eq(&document, &session.doc));
+ studio["progressive"] = json!(false);
+ assert!(session.execute("render.preflight", &studio).unwrap_err().to_string().contains("require progressive"));
+ studio["progressive"] = json!(true);
+ studio["lighting"]["area_lights"][0]["u"] = json!([0, 0, 0]);
+ assert!(session.execute("render.preflight", &studio).is_err());
+ let started = session.execute("render.start", &request).unwrap();
+ let id: JobId = serde_json::from_value(started["job"].clone()).unwrap();
+ let status = session.render_job_handle(id).unwrap().wait_timeout(std::time::Duration::from_secs(10)).unwrap();
+ assert_eq!(status.resolved.executor.as_str(), "test-progressive");
+ assert_eq!(status.options.samples, 3);
+ assert_eq!(status.progress.phase, solidcraft_render::job::Phase::Completed);
+ finish(&cpu);
+ assert_eq!(session.execute("render.status", &json!({"job":cpu_id})).unwrap()["frame"]["executor"], "cpu-product");
+ assert!(session.scratch().execute("render.status", &json!({"job":id})).is_err());
+ session.execute("file.new", &json!({})).unwrap();
+ assert_eq!(session.execute("render.preflight", &request).unwrap()["resolved"]["executor"], "test-progressive");
+ assert!(session.execute("render.status", &json!({"job":id})).is_err());
+ for bad in [json!({"samples":0}), json!({"max_depth":17}), json!({"seed":-1}), json!({"samples":4097})] {
+ let mut params = request.clone();
+ for (key, value) in bad.as_object().unwrap() {
+ params[key] = value.clone();
+ }
+ assert!(session.execute("render.start", &params).is_err());
+ }
+}
+
#[test]
fn runtime_commands_preserve_document_history_and_evaluation() {
let (mut s, host) = session();
@@ -217,3 +305,13 @@ fn native_start_and_cancel_measure_cached_capture_without_timing_assertions() {
);
assert!(status.progress.phase.terminal());
}
+
+#[test]
+fn runtime_texture_controls_require_progressive_and_leave_document_unchanged() {
+ let (mut s, _) = session();
+ let doc = s.doc.clone();
+ let input = json!({"raytrace":{"textures":[{"body_index":0,"body_name":"No body","frame":{"origin":[0,0,0],"u":[1,0,0],"v":[0,1,0]},"normal_opengl":"not-opened.png"}]}});
+ let error = s.execute("render.preflight", &input).unwrap_err().to_string();
+ assert!(error.contains("require progressive"), "{error}");
+ assert!(Arc::ptr_eq(&doc, &s.doc));
+}
diff --git a/crates/engine/src/cmd/render/jobs.rs b/crates/engine/src/cmd/render/jobs.rs
index 8056c62727..3b630f57e8 100644
--- a/crates/engine/src/cmd/render/jobs.rs
+++ b/crates/engine/src/cmd/render/jobs.rs
@@ -14,14 +14,50 @@ struct Start {
settings: Option<RenderSetup>,
transparent_background: bool,
replace: bool,
+ progressive: bool,
+ samples: Option<u32>,
+ max_depth: Option<u32>,
+ seed: Option<u32>,
+ raytrace: super::transmission::Raytrace,
+ lens: Option<solidcraft_render::job::ThinLens>,
+ lighting: Option<solidcraft_render::job::StudioLighting>,
+ tone_map: Option<solidcraft_render::job::ToneMap>,
+ environment: Option<super::environment::Input>,
+ denoise: bool,
}
-fn prepare(s: &Session, params: &Value, command: &str) -> Result<(Start, solidcraft_render::ProductScene, ImageRequest, Value)> {
+struct Prepared {
+ input: Start,
+ scene: solidcraft_render::ProductScene,
+ request: ImageRequest,
+ reply: Value,
+ executor: solidcraft_render::ExecutorId,
+ options: solidcraft_render::job::JobOptions,
+}
+
+fn prepare(s: &Session, params: &Value, command: &str) -> Result<Prepared> {
let input: Start = serde_json::from_value(params.clone()).map_err(|e| bad(command, e.to_string()))?;
if input.setup.is_some() && input.settings.is_some() {
return Err(bad(command, "choose either setup or settings"));
}
- let scene = crate::product_scene::extract(s)?;
+ let mut scene = crate::product_scene::extract(s)?;
+ if !input.progressive
+ && (!input.raytrace.dielectrics.is_empty()
+ || !input.raytrace.clear_coats.is_empty()
+ || !input.raytrace.textures.is_empty()
+ || input.lens.is_some()
+ || input.lighting.is_some()
+ || input.tone_map.is_some()
+ || input.environment.is_some()
+ || input.denoise)
+ {
+ return Err(bad(
+ command,
+ "runtime transmission, clear-coat, texture, lens, environment, lighting, tone-map and denoise controls require progressive rendering",
+ ));
+ }
+ super::transmission::apply(&mut scene, &input.raytrace.dielectrics, command)?;
+ super::clear_coat::apply(&mut scene, &input.raytrace.clear_coats, command)?;
let settings = if let Some(name) = &input.setup {
s.doc.render.setups.get(name).cloned().ok_or_else(|| bad(command, "no saved render setup with that name"))?
} else if let Some(settings) = &input.settings {
@@ -36,12 +72,38 @@ fn prepare(s: &Session, params: &Value, command: &str) -> Result<(Start, solidcr
settings
};
settings.validate().map_err(|e| bad(command, e.to_string()))?;
- if settings.exposure_ev != 0.0 || settings.environment_rotation != 0.0 || settings.environment_intensity != 1.0 {
- return Err(bad(command, "exposure and environment controls are not supported by the R4a CPU image executor"));
+ if settings.environment_rotation != 0.0 || settings.environment_intensity != 1.0 {
+ return Err(bad(command, "environment controls are not supported by the installed image executors"));
}
- let host = s.render_job_host().ok_or_else(|| bad(command, "no image host is installed"))?;
- if !host.is_available() {
- return Err(bad(command, "image host is unavailable"));
+ if !input.progressive && (input.samples.is_some() || input.max_depth.is_some() || input.seed.is_some() || settings.exposure_ev != 0.0) {
+ return Err(bad(command, "sampling and exposure controls require progressive rendering"));
+ }
+ let mut options = solidcraft_render::job::JobOptions::default();
+ if let Some(samples) = input.samples {
+ options.samples = samples;
+ }
+ if let Some(depth) = input.max_depth {
+ options.max_depth = depth;
+ }
+ if let Some(seed) = input.seed {
+ options.seed = seed;
+ }
+ options.exposure_ev = settings.exposure_ev;
+ options.lens = input.lens;
+ options.lighting = input.lighting;
+ options.tone_map = input.tone_map.unwrap_or_default();
+ options.denoise = input.denoise;
+ options.validate().map_err(job_error)?;
+ let environment = input.environment.as_ref().map(|source| source.capture(command)).transpose()?;
+ let mut features = scene.required_features();
+ if environment.is_some() {
+ features.push(solidcraft_render::RenderFeature::Hdri);
+ }
+ if input.progressive {
+ features.push(solidcraft_render::RenderFeature::Progressive);
+ if scene.has_transmission() {
+ features.push(solidcraft_render::RenderFeature::Refraction);
+ }
}
let resolved = solidcraft_render::resolve_request(
&[s.render_backend()],
@@ -52,33 +114,50 @@ fn prepare(s: &Session, params: &Value, command: &str) -> Result<(Start, solidcr
width: u64::from(settings.width),
height: u64::from(settings.height),
format: Some(settings.format),
- features: scene.required_features(),
+ features,
policy: Default::default(),
},
)
.map_err(|e| bad(command, e.to_string()))?;
- if resolved.executor.as_str() != "cpu-product" {
- return Err(bad(command, "resolved executor is not installed as an image job host"));
+ if options.denoise && resolved.executor.as_str() != "gpu-path" {
+ return Err(bad(command, "denoise requires the native gpu-path executor"));
+ }
+ let host = s.render_jobs.host_for(&resolved.executor).ok_or_else(|| bad(command, "resolved executor is not installed as an image job host"))?;
+ if !host.is_available() {
+ return Err(bad(command, "image host is unavailable"));
}
let request = ImageRequest {
+ environment,
camera: settings.camera,
width: settings.width,
height: settings.height,
background: settings.background,
transparent_background: input.transparent_background,
+ textures: super::textures::capture(&scene, &input.raytrace.textures, command)?,
};
- let admission = solidcraft_render::job::admit(&scene, &request).map_err(job_error)?;
- let reply = json!({"resolved":resolved,"admission":admission,"request":request,"scene_generation":s.revision,"host":host.kind(),"transparency":"sorted_alpha_approximation","refraction":false});
- Ok((input, scene, request, reply))
+ let admission = host.admit(&scene, &request, options).map_err(job_error)?;
+ let refraction = input.progressive && scene.has_transmission();
+ let reply = json!({"resolved":resolved,"admission":admission,"request":request,"textures":request.textures.as_ref().map(|resources|resources.summary()),"scene_generation":s.revision,"host":host.kind(),"transparency":if refraction {"physical_transmission"} else if input.progressive {"opaque_only"} else {"sorted_alpha_approximation"},"options":options,"environment":request.environment.as_ref().map(|source|source.info()),"refraction":refraction,"dielectric_boundaries": if resolved.executor.as_str() == "gpu-path" {vec!["thin_sheet","closed_box","closed_mesh"]} else {Vec::<&str>::new()}});
+ let mut reply = reply;
+ if options.denoise {
+ reply["denoising"] = json!({
+ "method":"edge_aware_atrous", "passes":3, "steps":[1,2,4],
+ "guides":"deterministic_center_ray_albedo_normal_position_depth",
+ "bypass":"glass, smooth metal/coat, emitter, background and partial coverage first hits",
+ "limitation":"first-hit guides do not reconstruct reflection/refraction or depth-of-field correspondences",
+ "raw_linear_accumulator_preserved":true, "output_stage":"linear_before_tone_map"
+ });
+ }
+ Ok(Prepared { input, scene, request, reply, executor: resolved.executor, options })
}
pub(super) fn preflight(s: &mut Session, params: &Value) -> Result<Value> {
- prepare(s, params, "render.preflight").map(|(_, _, _, reply)| reply)
+ prepare(s, params, "render.preflight").map(|prepared| prepared.reply)
}
pub(super) fn start(s: &mut Session, params: &Value) -> Result<Value> {
- let (input, scene, request, _) = prepare(s, params, "render.start")?;
- let status = s.render_jobs.start(s.revision, scene, request, input.replace).map_err(job_error)?;
+ let p = prepare(s, params, "render.start")?;
+ let status = s.render_jobs.start(s.revision, p.scene, p.request, p.input.replace, &p.executor, p.options).map_err(job_error)?;
Ok(json!(status))
}
diff --git a/crates/engine/src/cmd/render/textures.rs b/crates/engine/src/cmd/render/textures.rs
new file mode 100644
index 0000000000..d2779ff3cc
--- /dev/null
+++ b/crates/engine/src/cmd/render/textures.rs
@@ -0,0 +1,106 @@
+//! Bounded immutable file capture; decoding is deferred to the admitted worker.
+use crate::{Result, params::bad};
+use serde::Deserialize;
+use solidcraft_render::{
+ ProductScene,
+ job::textures::{MAX_TEXTURE_BINDINGS, MAX_TEXTURE_SOURCE_BYTES, PlanarFrame, RuntimeTextures, TextureBinding, TextureMap},
+ texture_input::MapRole,
+};
+use std::sync::Arc;
+
+#[derive(Deserialize)]
+#[serde(deny_unknown_fields)]
+pub(super) struct Override {
+ body_index: usize,
+ body_name: String,
+ frame: PlanarFrame,
+ #[serde(default)]
+ base_color_srgb: Option<String>,
+ #[serde(default)]
+ normal_opengl: Option<String>,
+ #[serde(default = "normal_strength")]
+ normal_strength: f64,
+}
+fn normal_strength() -> f64 {
+ 1.0
+}
+fn load(path: &str, role: MapRole, remaining: &mut u64, command: &str) -> Result<TextureMap> {
+ if path.is_empty() || path.len() > 4096 || path.chars().any(char::is_control) {
+ return Err(bad(command, "texture path must be a bounded local path"));
+ }
+ let bytes = solidcraft_io::vfs::read(path, *remaining as usize).map_err(|e| bad(command, format!("could not capture texture: {e}")))?;
+ if bytes.is_empty() {
+ return Err(bad(command, "texture file must not be empty"));
+ }
+ let map = TextureMap::new(bytes, role).map_err(|e| bad(command, e.to_string()))?;
+ *remaining = remaining.checked_sub(map.retained_bytes() as u64).ok_or_else(|| bad(command, "encoded texture capacity exceeds budget"))?;
+ Ok(map)
+}
+pub(super) fn capture(scene: &ProductScene, overrides: &[Override], command: &str) -> Result<Option<Arc<RuntimeTextures>>> {
+ if overrides.is_empty() {
+ return Ok(None);
+ }
+ if overrides.len() > MAX_TEXTURE_BINDINGS {
+ return Err(bad(command, "at most 16 runtime texture bodies are supported"));
+ }
+ let mut remaining = MAX_TEXTURE_SOURCE_BYTES;
+ let mut bindings = Vec::new();
+ for input in overrides {
+ input.frame.validate().map_err(|e| bad(command, e.to_string()))?;
+ // Refuse stale identity or unsupported optics before touching any file.
+ let body = scene
+ .meshes
+ .get(input.body_index)
+ .filter(|b| b.name == input.body_name)
+ .ok_or_else(|| bad(command, "texture ordinal and name must both match render.scene"))?;
+ if body.transmission.is_some() || body.opacity != 1.0 || body.faces.iter().any(|f| f.transmission.is_some() || f.opacity != 1.0) {
+ return Err(bad(command, "runtime maps support opaque bodies only"));
+ }
+ let base_color = input.base_color_srgb.as_ref().map(|p| load(p, MapRole::BaseColor, &mut remaining, command)).transpose()?;
+ let normal = input.normal_opengl.as_ref().map(|p| load(p, MapRole::NormalOpenGl, &mut remaining, command)).transpose()?;
+ bindings.push(TextureBinding {
+ body_index: input.body_index,
+ body_name: input.body_name.clone(),
+ frame: input.frame,
+ normal_strength: input.normal_strength,
+ base_color,
+ normal,
+ });
+ }
+ let resources = RuntimeTextures::new(bindings).map_err(|e| bad(command, e.to_string()))?;
+ resources.validate_scene(scene).map_err(|e| bad(command, e.to_string()))?;
+ Ok(Some(Arc::new(resources)))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+ use solidcraft_geom::{Aabb3, Mesh};
+ #[test]
+ fn unsupported_or_stale_map_targets_fail_before_file_io() {
+ let scene = ProductScene {
+ bounds: Aabb3::EMPTY,
+ meshes: vec![solidcraft_render::ProductMesh {
+ name: "Glass".into(),
+ mesh: Arc::new(Mesh::default()),
+ color: [255; 3],
+ opacity: 1.,
+ surface: None,
+ transmission: Some(solidcraft_render::transmission::Transmission::new(solidcraft_geom::Vec3::ZERO, Some(1.)).unwrap()),
+ faces: vec![],
+ }],
+ };
+ let value =
+ json!({"body_index":0,"body_name":"Glass","frame":{"origin":[0,0,0],"u":[1,0,0],"v":[0,1,0]},"base_color_srgb":"nonexistent-image.png"});
+ let input: Override = serde_json::from_value(value.clone()).unwrap();
+ assert!(capture(&scene, &[input], "render.start").unwrap_err().to_string().contains("opaque bodies"));
+ let mut stale = value.clone();
+ stale["body_name"] = json!("Stale");
+ let input: Override = serde_json::from_value(stale).unwrap();
+ assert!(capture(&scene, &[input], "render.start").unwrap_err().to_string().contains("ordinal and name"));
+ let mut unknown = value;
+ unknown["metallic_map"] = json!("foo");
+ assert!(serde_json::from_value::<Override>(unknown).is_err());
+ }
+}
diff --git a/crates/engine/src/cmd/render/transmission.rs b/crates/engine/src/cmd/render/transmission.rs
new file mode 100644
index 0000000000..dd83c58362
--- /dev/null
+++ b/crates/engine/src/cmd/render/transmission.rs
@@ -0,0 +1,223 @@
+//! Agreed #1659 runtime wire adapter, coordinated in Mailbox 9075.
+//! Keep wire details here until the CPU contract is published. Never save them.
+use crate::{Result, params::bad};
+use serde::Deserialize;
+use solidcraft_geom::Vec3;
+use solidcraft_render::{
+ ProductScene,
+ surface::{OpaqueSurface, srgb8_to_linear},
+ transmission::Transmission,
+};
+#[derive(Default, Deserialize)]
+#[serde(default, deny_unknown_fields)]
+pub(super) struct Raytrace {
+ pub dielectrics: Vec<Override>,
+ pub clear_coats: Vec<super::clear_coat::Override>,
+ pub textures: Vec<super::textures::Override>,
+}
+#[derive(Deserialize)]
+#[serde(deny_unknown_fields)]
+pub(super) struct Override {
+ body_index: usize,
+ body_name: String,
+ ior: f64,
+ absorption_per_mm: [f64; 3],
+ boundary: Boundary,
+ thickness_mm: f64,
+ #[serde(default)]
+ shadow_transmission: Option<bool>,
+}
+#[derive(Deserialize)]
+#[serde(try_from = "String")]
+enum Boundary {
+ ThinSheet,
+ ClosedBox,
+ ClosedMesh,
+}
+impl TryFrom<String> for Boundary {
+ type Error = &'static str;
+ fn try_from(value: String) -> std::result::Result<Self, Self::Error> {
+ match value.as_str() {
+ "thin_sheet" => Ok(Self::ThinSheet),
+ "closed_box" => Ok(Self::ClosedBox),
+ "closed_mesh" => Ok(Self::ClosedMesh),
+ _ => Err("boundary must be thin_sheet, closed_box or closed_mesh"),
+ }
+ }
+}
+pub(super) fn apply(scene: &mut ProductScene, overrides: &[Override], command: &str) -> Result<()> {
+ if overrides.len() > 8 {
+ return Err(bad(command, "at most eight runtime dielectric overrides are supported"));
+ }
+ let mut ordinals = std::collections::BTreeSet::new();
+ for input in overrides {
+ if input.body_name.is_empty()
+ || input.body_name.len() > 1024
+ || input.body_name.chars().any(char::is_control)
+ || !ordinals.insert(input.body_index)
+ {
+ return Err(bad(command, "dielectrics require bounded names and distinct captured body ordinals"));
+ }
+ let thickness = match input.boundary {
+ Boundary::ThinSheet => Some(input.thickness_mm),
+ _ => None,
+ };
+ if !matches!(input.boundary, Boundary::ThinSheet) && input.thickness_mm != 0.0 {
+ return Err(bad(command, "closed dielectric thickness_mm must be zero; distance comes from geometry"));
+ }
+ let [r, g, b] = input.absorption_per_mm;
+ let mut transmission = Transmission::new(Vec3::new(r, g, b), thickness).map_err(|e| bad(command, e.to_string()))?;
+ if let Some(enabled) = input.shadow_transmission {
+ transmission = transmission.with_shadow_transmission(enabled);
+ }
+ OpaqueSurface::new(Vec3::ZERO, 0.0, 0.5, input.ior).map_err(|e| bad(command, e.to_string()))?;
+ let body = scene
+ .meshes
+ .get_mut(input.body_index)
+ .filter(|m| m.name == input.body_name)
+ .ok_or_else(|| bad(command, "dielectric body ordinal and exact name must both match render.scene"))?;
+ if matches!(input.boundary, Boundary::ClosedBox) {
+ certify_box(&body.mesh, command)?;
+ }
+ // Full dielectric override replaces optical metalness in the job snapshot only.
+ let surface = |color: [u8; 3], existing: Option<OpaqueSurface>| {
+ let [r, g, b] = color.map(srgb8_to_linear);
+ OpaqueSurface::new(Vec3::new(r, g, b), 0.0, existing.map_or(0.5, |s| s.roughness()), input.ior).map_err(|e| bad(command, e.to_string()))
+ };
+ body.surface = Some(surface(body.color, body.surface)?);
+ body.transmission = Some(transmission);
+ for face in &mut body.faces {
+ face.surface = Some(surface(face.color, face.surface)?);
+ face.transmission = Some(transmission);
+ }
+ }
+ Ok(())
+}
+fn certify_box(mesh: &solidcraft_geom::Mesh, command: &str) -> Result<()> {
+ let bounds = mesh.bounds();
+ if mesh.triangles.is_empty()
+ || !bounds.min.is_finite()
+ || !bounds.max.is_finite()
+ || bounds.min.x >= bounds.max.x
+ || bounds.min.y >= bounds.max.y
+ || bounds.min.z >= bounds.max.z
+ {
+ return Err(bad(command, "closed_box requires a nonempty axis-aligned box"));
+ }
+ for triangle in &mesh.triangles {
+ let points = triangle.map(|i| mesh.positions.get(i as usize).copied());
+ let [Some(a), Some(b), Some(c)] = points else {
+ return Err(bad(command, "invalid closed_box triangle"));
+ };
+ let on_plane = |x: f64, y: f64, z: f64, lo: f64, hi: f64| {
+ [lo, hi].into_iter().any(|plane| [x, y, z].into_iter().all(|v| v.is_finite() && (v - plane).abs() <= 1e-6))
+ };
+ if !(on_plane(a.x, b.x, c.x, bounds.min.x, bounds.max.x)
+ || on_plane(a.y, b.y, c.y, bounds.min.y, bounds.max.y)
+ || on_plane(a.z, b.z, c.z, bounds.min.z, bounds.max.z))
+ {
+ return Err(bad(command, "closed_box requires axis-aligned bounding planes; use GPU-only closed_mesh for other closed geometry"));
+ }
+ }
+ // GPU preparation additionally certifies closed, outward two-manifold topology.
+ Ok(())
+}
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+ use std::sync::Arc;
+ fn fixture() -> crate::Session {
+ let mut s = crate::Session::default();
+ s.execute("solid.box", &json!({"length":10,"width":10,"height":2,"body_name":"Glass"})).unwrap();
+ s
+ }
+ fn input() -> serde_json::Value {
+ json!({"body_index":0,"body_name":"Glass","ior":1.5,"absorption_per_mm":[0.1,0.02,0],"boundary":"closed_box","thickness_mm":0})
+ }
+ #[test]
+ fn request_glass_leaves_document_geometry_and_preview_unchanged() {
+ let mut s = fixture();
+ s.execute("appearance.assign", &json!({"bodies":["Glass"],"color":"#c0e0ff","opacity":0.2})).unwrap();
+ let saved = s.doc.to_json();
+ let mut scene = crate::product_scene::extract(&s).unwrap();
+ let mesh = scene.meshes[0].mesh.clone();
+ apply(&mut scene, &[serde_json::from_value(input()).unwrap()], "render.start").unwrap();
+ assert!(scene.has_transmission());
+ assert_eq!(scene.meshes[0].opacity, 0.2);
+ assert!(Arc::ptr_eq(&mesh, &scene.meshes[0].mesh));
+ assert_eq!(scene.meshes[0].surface.unwrap().dielectric_ior(), 1.5);
+ assert_eq!(saved, s.doc.to_json());
+ let reopened = crate::Session::new(solidcraft_doc::Document::from_json(&saved).unwrap());
+ assert!(!crate::product_scene::extract(&reopened).unwrap().has_transmission());
+ assert!(
+ s.execute(
+ "appearance.assign",
+ &json!({"bodies":["Glass"],"color":"#ffffff",
+ "pbr":{"metallic":0,"roughness":0.1,"dielectric_ior":1.5,"transmission":{}}})
+ )
+ .is_err()
+ );
+ }
+ #[test]
+ fn request_glass_rejects_unknown_fractional_duplicate_and_mismatched_inputs() {
+ let s = fixture();
+ for (key, value) in [
+ ("weight", json!(0.5)),
+ ("ior", json!(0.9)),
+ ("absorption_per_mm", json!([100.01, 0, 0])),
+ ("body_index", json!(1)),
+ ("body_name", json!("missing")),
+ ("thickness_mm", json!(-1)),
+ ("boundary", json!({"thin_sheet":null})),
+ ("extra", json!(true)),
+ ] {
+ let mut value_input = input();
+ value_input[key] = value;
+ let rejected = match serde_json::from_value::<Override>(value_input) {
+ Ok(value) => apply(&mut crate::product_scene::extract(&s).unwrap(), &[value], "render.start").is_err(),
+ Err(_) => true,
+ };
+ assert!(rejected, "{key}");
+ }
+ for count in [2, 9] {
+ let overrides = serde_json::from_value::<Vec<Override>>(json!(vec![input(); count])).unwrap();
+ assert!(apply(&mut crate::product_scene::extract(&s).unwrap(), &overrides, "render.start").is_err());
+ }
+ let mut thin = input();
+ thin["boundary"] = json!("thin_sheet");
+ assert!(apply(&mut crate::product_scene::extract(&s).unwrap(), &[serde_json::from_value(thin).unwrap()], "render.start").is_ok());
+ }
+ #[test]
+ fn closed_box_certificate_rejects_deformed_mesh_but_closed_mesh_is_explicit() {
+ let mut scene = crate::product_scene::extract(&fixture()).unwrap();
+ Arc::make_mut(&mut scene.meshes[0].mesh).positions[0] += Vec3::new(0.2, 0.3, 0.4);
+ assert!(apply(&mut scene.clone(), &[serde_json::from_value(input()).unwrap()], "render.start").is_err());
+ let mut value = input();
+ value["boundary"] = json!("closed_mesh");
+ assert!(apply(&mut scene, &[serde_json::from_value(value).unwrap()], "render.start").is_ok());
+ }
+ #[test]
+ fn shadow_flags_follow_boundary_defaults_and_explicit_runtime_overrides() {
+ let s = fixture();
+ let saved = s.doc.to_json();
+ for thin in [false, true] {
+ for flag in [None, Some(false), Some(true)] {
+ let mut value = input();
+ if thin {
+ value["boundary"] = json!("thin_sheet");
+ }
+ if let Some(flag) = flag {
+ value["shadow_transmission"] = json!(flag);
+ }
+ let mut scene = crate::product_scene::extract(&s).unwrap();
+ apply(&mut scene, &[serde_json::from_value(value).unwrap()], "render.start").unwrap();
+ assert_eq!(scene.meshes[0].transmission.unwrap().shadow_transmission(), flag.unwrap_or(thin));
+ assert_eq!(s.doc.to_json(), saved);
+ }
+ }
+ let mut malformed = input();
+ malformed["shadow_transmission"] = json!(0.5);
+ assert!(serde_json::from_value::<Override>(malformed).is_err());
+ }
+}
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 7084bc65a7..bd8c97d4a8 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -507,11 +507,14 @@ impl Session {
}
if let Some(executor) = &self.render_jobs.descriptor {
let mut executor = executor.clone();
- if self.render_jobs.host.as_ref().is_none_or(|host| !host.is_available()) {
- executor.availability = render::Availability::Unavailable { reason: "CPU image host is unavailable".into() };
- }
+ executor.availability = image_host_availability(self.render_jobs.host.as_ref(), &executor.id);
backend.executors.push(executor);
}
+ for (host, descriptor) in &self.render_jobs.additional {
+ let mut descriptor = descriptor.clone();
+ descriptor.availability = image_host_availability(Some(host), &descriptor.id);
+ backend.executors.push(descriptor);
+ }
backend
}
@@ -532,6 +535,7 @@ impl Session {
if let Some(executor) = &self.render_jobs.descriptor {
backend.executors.push(executor.clone());
}
+ backend.executors.extend(self.render_jobs.additional.iter().map(|(_, d)| d.clone()));
backend.executors.push(executor.clone());
// Resolution validates the whole registry, including duplicate executor IDs.
let request = render::RenderRequest {
@@ -851,6 +855,7 @@ impl Session {
let spec = find_command(id).ok_or_else(|| EngineError::UnknownCommand(id.to_string()))?;
let host_viewport = self.render_viewport.clone();
let host_jobs = self.render_jobs.host.clone();
+ let additional_jobs = self.render_jobs.additional.clone();
let live = spec.live.filter(|_| params.get("live").and_then(Value::as_bool) == Some(true));
if live.is_none() && spec.reads_model && self.model.is_stale() {
self.refresh();
@@ -894,6 +899,9 @@ impl Session {
if self.render_jobs.host.is_none() && host_jobs.is_some() {
self.set_render_job_host(host_jobs)?;
}
+ for (host, _) in additional_jobs {
+ self.register_render_job_host(host)?;
+ }
if outermost && crash::enabled() {
// A failed command leaves the design as it was (restored below).
let failed = r.as_ref().err().map(ToString::to_string);
@@ -1295,3 +1303,13 @@ fn own_values(sk: &solidcraft_sketch::Sketch) -> std::collections::BTreeMap<Stri
}
values
}
+
+/// Capabilities are fixed at registration; availability is live device/host state.
+fn image_host_availability(host: Option<&render::job::ImageHost>, expected: &render::ExecutorId) -> render::Availability {
+ match host.map(render::job::ImageHost::descriptor) {
+ Some(Ok(current)) if current.id == *expected => current.availability,
+ Some(Ok(_)) => render::Availability::Unavailable { reason: "image executor identity changed after registration".into() },
+ Some(Err(error)) => render::Availability::Unavailable { reason: format!("image executor status unavailable: {error}") },
+ None => render::Availability::Unavailable { reason: "image host is unavailable".into() },
+ }
+}
diff --git a/crates/engine/src/product_scene.rs b/crates/engine/src/product_scene.rs
index 9721d2d901..43fa52f644 100644
--- a/crates/engine/src/product_scene.rs
+++ b/crates/engine/src/product_scene.rs
@@ -32,6 +32,7 @@ pub fn extract(s: &Session) -> Result<ProductScene> {
color: look.color,
opacity: look.opacity.clamp(0.0, 1.0),
surface: look.opaque_surface().map_err(|e| EngineError::Other(e.to_string()))?,
+ transmission: None,
})
})
.collect::<Result<Vec<_>>>()?;
@@ -42,6 +43,7 @@ pub fn extract(s: &Session) -> Result<ProductScene> {
color,
opacity: s.doc.model_body_opacity(body).clamp(0.0, 1.0),
surface,
+ transmission: None,
faces,
});
}
diff --git a/crates/engine/src/render_jobs.rs b/crates/engine/src/render_jobs.rs
index 267e171d4f..7ea24a4a6a 100644
--- a/crates/engine/src/render_jobs.rs
+++ b/crates/engine/src/render_jobs.rs
@@ -30,6 +30,7 @@ pub(crate) struct Jobs {
generation: u64,
pub(crate) host: Option<CpuHost>,
pub(crate) descriptor: Option<ExecutorDescriptor>,
+ pub(crate) additional: Vec<(CpuHost, ExecutorDescriptor)>,
live: Vec<JobHandle>,
history: VecDeque<JobStatus>,
last_good: Option<JobHandle>,
@@ -37,7 +38,17 @@ pub(crate) struct Jobs {
impl Default for Jobs {
fn default() -> Self {
- Self { owner: owner(), serial: 0, generation: 0, host: None, descriptor: None, live: Vec::new(), history: VecDeque::new(), last_good: None }
+ Self {
+ owner: owner(),
+ serial: 0,
+ generation: 0,
+ host: None,
+ descriptor: None,
+ additional: Vec::new(),
+ live: Vec::new(),
+ history: VecDeque::new(),
+ last_good: None,
+ }
}
}
@@ -50,10 +61,18 @@ impl Drop for Jobs {
}
impl Jobs {
+ pub(crate) fn host_for(&self, executor: &solidcraft_render::ExecutorId) -> Option<&CpuHost> {
+ if self.descriptor.as_ref().is_some_and(|d| &d.id == executor) {
+ return self.host.as_ref();
+ }
+ self.additional.iter().find(|(_, d)| &d.id == executor).map(|(host, _)| host)
+ }
+
pub(crate) fn scratch(&self) -> Self {
let mut jobs = Self::default();
jobs.host = self.host.clone();
jobs.descriptor = self.descriptor.clone();
+ jobs.additional = self.additional.clone();
jobs
}
@@ -83,9 +102,11 @@ impl Jobs {
scene: solidcraft_render::ProductScene,
request: solidcraft_render::job::ImageRequest,
replace: bool,
+ executor: &solidcraft_render::ExecutorId,
+ options: solidcraft_render::job::JobOptions,
) -> Result<JobStatus, JobError> {
self.collect()?;
- let host = self.host.as_ref().ok_or_else(|| JobError::new(ErrorCode::HostUnavailable, "no image host is installed"))?.clone();
+ let host = self.host_for(executor).ok_or_else(|| JobError::new(ErrorCode::HostUnavailable, "resolved image host is not installed"))?.clone();
if replace {
for job in self.live.drain(..) {
let mut status = job.cancel()?;
@@ -109,7 +130,7 @@ impl Jobs {
}
let serial = self.serial.checked_add(1).ok_or_else(|| JobError::new(ErrorCode::LimitExceeded, "render job identity exhausted"))?;
let generation = self.generation.checked_add(1).ok_or_else(|| JobError::new(ErrorCode::LimitExceeded, "render generation exhausted"))?;
- let handle = host.submit(JobId { session: self.owner, serial, generation }, revision, scene, request)?;
+ let handle = host.submit_with_options(JobId { session: self.owner, serial, generation }, revision, scene, request, options)?;
let status = handle.status()?;
self.serial = serial;
self.generation = generation;
@@ -176,12 +197,43 @@ impl crate::Session {
)
.map_err(|e| crate::EngineError::Other(e.to_string()))?;
let mut jobs = Jobs::default();
+ jobs.additional = self.render_jobs.additional.clone();
jobs.host = host;
jobs.descriptor = descriptor;
self.render_jobs = jobs;
Ok(())
}
+ /// Add an executor without replacing CPU jobs or their ownership. Applications share
+ /// this host across document sessions; descriptor IDs must be unique in the registry.
+ pub fn register_render_job_host(&mut self, host: solidcraft_render::job::ImageHost) -> crate::Result<()> {
+ let descriptor = host.descriptor().map_err(job_error)?;
+ if self.render_jobs.additional.iter().any(|(old, _)| old.same_host(&host)) {
+ return Ok(());
+ }
+ if descriptor.profiles.iter().any(|p| p.operation != solidcraft_render::RenderOperation::Image) {
+ return Err(crate::EngineError::Other("image host must only register image profiles".into()));
+ }
+ let mut registry = self.render_backend();
+ registry.executors.push(descriptor.clone());
+ solidcraft_render::resolve_request(
+ &[registry],
+ &solidcraft_render::RenderRequest {
+ backend: None,
+ mode: solidcraft_render::RenderMode::Preview,
+ operation: solidcraft_render::RenderOperation::Image,
+ width: 1,
+ height: 1,
+ format: Some(solidcraft_render::RenderFormat::Png),
+ features: Vec::new(),
+ policy: Default::default(),
+ },
+ )
+ .map_err(|e| crate::EngineError::Other(e.to_string()))?;
+ self.render_jobs.additional.push((host, descriptor));
+ Ok(())
+ }
+
pub fn render_job_host(&self) -> Option<&CpuHost> {
self.render_jobs.host.as_ref()
}
diff --git a/crates/gpu/Cargo.toml b/crates/gpu/Cargo.toml
index b8bc671f41..d609bf863b 100644
--- a/crates/gpu/Cargo.toml
+++ b/crates/gpu/Cargo.toml
@@ -9,6 +9,7 @@ license.workspace = true
workspace = true
[dependencies]
+robust = "1.2"
solidcraft-geom = { workspace = true }
solidcraft-render = { workspace = true }
wgpu = { workspace = true }
@@ -22,6 +23,7 @@ pollster = { workspace = true }
wgpu = { workspace = true, features = ["metal", "vulkan", "dx12", "gles"] }
[dev-dependencies]
+image = { workspace = true }
solidcraft-kernel = { workspace = true }
# Headless pictures of real designs (capture tests).
solidcraft-engine = { workspace = true }
diff --git a/crates/gpu/src/lib.rs b/crates/gpu/src/lib.rs
index a99f630158..25f0fc06a5 100644
--- a/crates/gpu/src/lib.rs
+++ b/crates/gpu/src/lib.rs
@@ -20,6 +20,8 @@ use solidcraft_geom::tess::{EvalCurve, EvalSurface, TessPlan};
use wgpu::util::DeviceExt;
pub mod capture;
+#[cfg(not(target_arch = "wasm32"))]
+pub mod path;
mod pbr;
#[cfg(not(target_arch = "wasm32"))]
pub mod select;
@@ -65,14 +67,19 @@ fn popped(f: impl std::future::Future<Output = Option<wgpu::Error>>) -> Option<w
fn open_headless() -> Result<(wgpu::Adapter, wgpu::Device, wgpu::Queue)> {
let policy = select::Policy::from_env().map_err(GpuError::Policy)?;
let (adapter, _) = select::pick(policy).ok_or(GpuError::NoAdapter(policy.name()))?;
- let (device, queue) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
+ let (device, queue) = open_device(&adapter)?;
+ Ok((adapter, device, queue))
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+fn open_device(adapter: &wgpu::Adapter) -> Result<(wgpu::Device, wgpu::Queue)> {
+ pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
label: Some("solidcraft headless"),
- required_features: depth_features(&adapter),
+ required_features: depth_features(adapter),
required_limits: wgpu::Limits::downlevel_defaults().using_resolution(adapter.limits()),
..Default::default()
}))
- .map_err(|e| GpuError::Device(e.to_string()))?;
- Ok((adapter, device, queue))
+ .map_err(|e| GpuError::Device(e.to_string()))
}
/// Most vertices evaluated in one dispatch (bounds the buffers; larger plans go in batches).
diff --git a/crates/gpu/src/path/denoise.rs b/crates/gpu/src/path/denoise.rs
new file mode 100644
index 0000000000..4da1e5ac44
--- /dev/null
+++ b/crates/gpu/src/path/denoise.rs
@@ -0,0 +1,218 @@
+//! Optional output filtering; never writes the Monte Carlo accumulation buffer.
+use super::{Context, Result, SHADER, TIMEOUT, Task, checked, placeholder_bind, scopes, warm_up};
+use wgpu::util::DeviceExt;
+
+pub(super) const BYTES_PER_PIXEL: u64 = 80; // three guide vec4s and two colour vec4s
+const FILTER: &str = include_str!("denoise.wgsl");
+const GUIDES: &str = include_str!("denoise_guides.wgsl");
+#[cfg(test)]
+#[path = "denoise_tests.rs"]
+mod tests;
+
+// Shared by every denoised job on a device: the guide pipeline compiles the whole
+// path shader, so it is built and warmed once rather than per job.
+pub(super) struct Pipelines {
+ guide: wgpu::ComputePipeline,
+ filter: wgpu::ComputePipeline,
+ filter_layout: wgpu::BindGroupLayout,
+}
+
+impl Pipelines {
+ fn new(context: &Context) -> Result<Self> {
+ let device = &context.device;
+ let error_scopes = scopes(device);
+ let guide_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("denoise guides"),
+ source: wgpu::ShaderSource::Wgsl(format!("{SHADER}\n{GUIDES}").into()),
+ });
+ let guide_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: Some("denoise guides"),
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let guide = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: Some("denoise guides"),
+ layout: Some(&guide_layout),
+ module: &guide_shader,
+ entry_point: Some("denoise_guides"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let entries: Vec<_> = (0..4)
+ .map(|binding| wgpu::BindGroupLayoutEntry {
+ binding,
+ visibility: wgpu::ShaderStages::COMPUTE,
+ ty: wgpu::BindingType::Buffer {
+ ty: if binding == 0 { wgpu::BufferBindingType::Uniform } else { wgpu::BufferBindingType::Storage { read_only: binding != 3 } },
+ has_dynamic_offset: false,
+ min_binding_size: None,
+ },
+ count: None,
+ })
+ .collect();
+ let filter_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { label: Some("denoise filter"), entries: &entries });
+ let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: Some("denoise filter"),
+ bind_group_layouts: &[Some(&filter_layout)],
+ immediate_size: 0,
+ });
+ let shader = device
+ .create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("denoise filter"), source: wgpu::ShaderSource::Wgsl(FILTER.into()) });
+ let filter = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: Some("denoise filter"),
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("atrous"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ checked(error_scopes)?;
+ warm_up(device, &context.queue, &guide, &placeholder_bind(device, &context.layout, 7)?, &context.healthy)?;
+ warm_up(device, &context.queue, &filter, &placeholder_bind(device, &filter_layout, 4)?, &context.healthy)?;
+ Ok(Self { guide, filter, filter_layout })
+ }
+
+ fn shared(context: &Context) -> Result<&Self> {
+ if let Some(pipelines) = context.denoise.get() {
+ return Ok(pipelines);
+ }
+ let built = Self::new(context)?;
+ Ok(context.denoise.get_or_init(|| built))
+ }
+}
+
+pub(super) struct Resources {
+ guide_pipeline: wgpu::ComputePipeline,
+ guide_bind: wgpu::BindGroup,
+ filter_pipeline: wgpu::ComputePipeline,
+ filter_uniform: wgpu::Buffer,
+ filter_binds: Vec<wgpu::BindGroup>,
+ output: wgpu::Buffer,
+ // Retained for diagnostic tests; bind groups also retain the guide allocation.
+ _guides: wgpu::Buffer,
+}
+
+impl Resources {
+ pub(super) fn new(
+ context: &Context,
+ path_uniform: &wgpu::Buffer,
+ scene: [&wgpu::Buffer; 5],
+ accumulation: &wgpu::Buffer,
+ size: u64,
+ ) -> Result<Self> {
+ let pipelines = Pipelines::shared(context)?;
+ let device = &context.device;
+ let error_scopes = scopes(device);
+ let buffer = |label, bytes| {
+ device.create_buffer(&wgpu::BufferDescriptor {
+ label: Some(label),
+ size: bytes,
+ usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC | wgpu::BufferUsages::COPY_DST,
+ mapped_at_creation: false,
+ })
+ };
+ let guides = buffer("denoise first-hit guides", size * 3);
+ let output = buffer("denoise filtered colour", size);
+ let temporary = buffer("denoise intermediate colour", size);
+ let [triangles, nodes, environment, textures, failures] = scene;
+ let entries: Vec<_> = [path_uniform, triangles, nodes, &guides, environment, textures, failures]
+ .into_iter()
+ .enumerate()
+ .map(|(binding, value)| wgpu::BindGroupEntry { binding: binding as u32, resource: value.as_entire_binding() })
+ .collect();
+ let guide_bind =
+ device.create_bind_group(&wgpu::BindGroupDescriptor { label: Some("denoise guides"), layout: &context.layout, entries: &entries });
+ let filter_uniform = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
+ label: Some("denoise parameters"),
+ contents: &[0; 32],
+ usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
+ });
+ let filter_binds = [(accumulation, &output), (&output, &temporary), (&temporary, &output)]
+ .into_iter()
+ .map(|(source, destination)| {
+ let entries: Vec<_> = [&filter_uniform, &guides, source, destination]
+ .into_iter()
+ .enumerate()
+ .map(|(binding, value)| wgpu::BindGroupEntry { binding: binding as u32, resource: value.as_entire_binding() })
+ .collect();
+ device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: Some("denoise filter"),
+ layout: &pipelines.filter_layout,
+ entries: &entries,
+ })
+ })
+ .collect();
+ checked(error_scopes)?;
+ Ok(Self {
+ guide_pipeline: pipelines.guide.clone(),
+ guide_bind,
+ filter_pipeline: pipelines.filter.clone(),
+ filter_uniform,
+ filter_binds,
+ output,
+ _guides: guides,
+ })
+ }
+
+ pub(super) fn output(&self) -> &wgpu::Buffer {
+ &self.output
+ }
+
+ pub(super) fn run(&self, task: &Task) -> Result<()> {
+ let pixels = task.request.width * task.request.height;
+ let mut budget = super::dispatch::Budget::default();
+ let mut offset = 0;
+ while offset < pixels {
+ task.cancel.check()?;
+ let count = budget.count(pixels - offset);
+ let mut parameters = task.parameters(count);
+ if let Some(bytes) = parameters.get_mut(12..16) {
+ bytes.copy_from_slice(&offset.to_le_bytes());
+ }
+ task.context.queue.write_buffer(&task.uniform, 0, &parameters);
+ let started = std::time::Instant::now();
+ dispatch(&task.context, &self.guide_pipeline, &self.guide_bind, count)?;
+ budget.observe(count, started.elapsed());
+ offset += count;
+ }
+ self.run_filter(task)
+ }
+
+ fn run_filter(&self, task: &Task) -> Result<()> {
+ let pixels = task.request.width * task.request.height;
+ for (pass, bind) in self.filter_binds.iter().enumerate() {
+ let mut budget = super::dispatch::Budget::default();
+ let mut offset = 0;
+ while offset < pixels {
+ task.cancel.check()?;
+ let count = budget.count(pixels - offset);
+ let mut bytes = Vec::with_capacity(32);
+ for word in [task.request.width, task.request.height, 1 << pass, offset, count, task.sample, 0, 0] {
+ bytes.extend_from_slice(&word.to_le_bytes());
+ }
+ task.context.queue.write_buffer(&self.filter_uniform, 0, &bytes);
+ let started = std::time::Instant::now();
+ dispatch(&task.context, &self.filter_pipeline, bind, count)?;
+ budget.observe(count, started.elapsed());
+ offset += count;
+ }
+ }
+ task.cancel.check()
+ }
+}
+
+fn dispatch(context: &Context, pipeline: &wgpu::ComputePipeline, bind: &wgpu::BindGroup, count: u32) -> Result<()> {
+ context.ensure_available()?;
+ let error_scopes = scopes(&context.device);
+ let mut encoder = context.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("denoise tile") });
+ {
+ let mut pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: Some("denoise tile"), timestamp_writes: None });
+ pass.set_pipeline(pipeline);
+ pass.set_bind_group(0, bind, &[]);
+ pass.dispatch_workgroups(count.div_ceil(64), 1, 1);
+ }
+ let submission = context.queue.submit([encoder.finish()]);
+ checked(error_scopes)?;
+ context.wait(submission, TIMEOUT)?;
+ Ok(())
+}
diff --git a/crates/gpu/src/path/denoise.wgsl b/crates/gpu/src/path/denoise.wgsl
new file mode 100644
index 0000000000..9502b35dd3
--- /dev/null
+++ b/crates/gpu/src/path/denoise.wgsl
@@ -0,0 +1,48 @@
+// Original three-pass edge-avoiding a-trous filter inspired by Dammertz et al.
+// Inputs/outputs keep accumulated linear premultiplied radiance and raw alpha.
+struct FilterParams { image: vec4<u32>, work: vec4<u32> };
+@group(0) @binding(0) var<uniform> f: FilterParams;
+@group(0) @binding(1) var<storage,read> guides: array<vec4<f32>>;
+@group(0) @binding(2) var<storage,read> source: array<vec4<f32>>;
+@group(0) @binding(3) var<storage,read_write> filtered: array<vec4<f32>>;
+fn kernel(x:i32)->f32 {
+ if x==0 { return 6.0; }
+ if abs(x)==1 { return 4.0; }
+ return 1.0;
+}
+fn max_component(v:vec3<f32>)->f32 { return max(max(v.x,v.y),v.z); }
+@compute @workgroup_size(64)
+fn atrous(@builtin(global_invocation_id) gid:vec3<u32>) {
+ let pixel=f.image.w+gid.x;
+ if gid.x>=f.work.x || pixel>=f.image.x*f.image.y { return; }
+ let c=source[pixel];
+ let a=guides[pixel*3u]; let n=guides[pixel*3u+1u]; let p=guides[pixel*3u+2u];
+ if a.w==0.0 || c.w<f32(f.work.y)*0.999 { filtered[pixel]=c; return; }
+ let xy=vec2<i32>(i32(pixel%f.image.x),i32(pixel/f.image.x));
+ var mean=vec3<f32>(0.0); var total=0.0;
+ let samples=f32(f.work.y);
+ let color=c.xyz/samples;
+ for(var y=-2;y<=2;y+=1) { for(var x=-2;x<=2;x+=1) {
+ let q=xy+vec2<i32>(x,y)*i32(f.image.z);
+ if any(q<vec2<i32>(0)) || q.x>=i32(f.image.x) || q.y>=i32(f.image.y) { continue; }
+ let j=u32(q.y)*f.image.x+u32(q.x);
+ let b=guides[j*3u]; let m=guides[j*3u+1u]; let r=guides[j*3u+2u];
+ let v=source[j];
+ if b.w!=a.w || abs(v.w-c.w)>samples*0.01 { continue; }
+ let da=a.xyz-b.xyz; let dp=r.xyz-p.xyz;
+ let plane=abs(dot(dp,n.xyz))+abs(dot(dp,m.xyz));
+ let scale=max(0.05*max(p.w,r.w)*f32(f.image.z),0.000001);
+ let depth=abs(n.w-m.w)/max(8.0*max(p.w,r.w)*f32(f.image.z),0.000001);
+ let dc=max_component(abs(color-v.xyz/samples));
+ let color_scale=0.25+0.5*max(max_component(color),max_component(v.xyz/samples));
+ let weight=kernel(x)*kernel(y)*exp(-dot(da,da)/0.04-plane/scale-depth-dc/color_scale)
+ *pow(max(dot(n.xyz,m.xyz),0.0),32.0);
+ if weight>0.0 {
+ total+=weight;
+ // Online convex averaging avoids overflow of radiance times kernel.
+ mean+=(v.xyz-mean)*(weight/total);
+ }
+ }}
+ // The centre always contributes; retain original coverage without filtering.
+ filtered[pixel]=vec4<f32>(mean,c.w);
+}
diff --git a/crates/gpu/src/path/denoise_guides.wgsl b/crates/gpu/src/path/denoise_guides.wgsl
new file mode 100644
index 0000000000..67d464d53d
--- /dev/null
+++ b/crates/gpu/src/path/denoise_guides.wgsl
@@ -0,0 +1,35 @@
+// Original deterministic first-hit guides. Uses the production intersection and
+// material/normal texture evaluation, without advancing the path random stream.
+@compute @workgroup_size(64)
+fn denoise_guides(@builtin(global_invocation_id) gid: vec3<u32>) {
+ let pixel=u.image.w+gid.x;
+ if gid.x>=u.sampling.z || pixel>=u.image.x*u.image.y { return; }
+ let base=pixel*3u;
+ accumulation[base]=vec4<f32>(0.0);
+ accumulation[base+1u]=vec4<f32>(0.0);
+ accumulation[base+2u]=vec4<f32>(0.0);
+ let xy=vec2<f32>(f32(pixel%u.image.x)+0.5,f32(pixel/u.image.x)+0.5);
+ let uv=vec2<f32>(xy.x/f32(u.image.x)*2.0-1.0,1.0-xy.y/f32(u.image.y)*2.0);
+ let ray=primary_ray(uv,vec2<f32>(0.0));
+ let hit=trace(ray.origin,ray.direction,false);
+ if hit.triangle==0xffffffffu { return; }
+ if u.environment.w>0.0 && emitter_hit_bounded(ray.origin,ray.direction,u.lighting.x).distance<hit.distance { return; }
+ var t=triangle(hit.triangle);
+ let position=surface_point(t,hit.bary);
+ t=texture_surface(t,position);
+ // Single first-hit guides cannot describe refracted or sharp reflected images.
+ if t.base.w>0.0 || (t.parameters.x>0.5 && t.parameters.y<0.25) || (t.coat.x>0.0 && t.coat.y<0.05) { return; }
+ var geometric=unit(cross(t.p1.xyz-t.p0.xyz,t.p2.xyz-t.p0.xyz));
+ if dot(geometric,-ray.direction)<0.0 { geometric=-geometric; }
+ var n=unit(t.n0.xyz*hit.bary.x+t.n1.xyz*hit.bary.y+t.n2.xyz*hit.bary.z);
+ if dot(n,geometric)<0.0 { n=-n; }
+ if dot(n,-ray.direction)<=0.0 { n=geometric; }
+ let mapped=texture_normal(t,position,n,geometric);
+ if dot(mapped,-ray.direction)>0.0 { n=mapped; }
+ let depth=dot(position-u.eye.xyz,-u.back.xyz);
+ var footprint=2.0*length(u.up.xyz)/f32(u.image.y);
+ if u.eye.w>0.5 { footprint*=max(depth,0.0)/u.back.w; }
+ accumulation[base]=vec4<f32>(t.base.xyz,t.optics.w);
+ accumulation[base+1u]=vec4<f32>(n,depth);
+ accumulation[base+2u]=vec4<f32>(position,max(footprint,0.000001));
+}
diff --git a/crates/gpu/src/path/denoise_tests.rs b/crates/gpu/src/path/denoise_tests.rs
new file mode 100644
index 0000000000..b48af2e01b
--- /dev/null
+++ b/crates/gpu/src/path/denoise_tests.rs
@@ -0,0 +1,331 @@
+use super::super::{Executor, JobOptions, Task, open_headless};
+use super::*;
+use solidcraft_geom::{Mesh, Vec3};
+use solidcraft_render::{
+ Camera, ProductMesh, ProductScene, StandardView,
+ job::{CancelToken, ImageRequest, ImageWork, TaskPoll},
+ surface::OpaqueSurface,
+};
+use std::sync::Arc;
+
+type Guide = [[f64; 4]; 3];
+fn dot(a: [f64; 3], b: [f64; 3]) -> f64 {
+ a.into_iter().zip(b).map(|(x, y)| x * y).sum()
+}
+fn diff(a: [f64; 4], b: [f64; 4]) -> [f64; 3] {
+ [a[0] - b[0], a[1] - b[1], a[2] - b[2]]
+}
+fn xyz(a: [f64; 4]) -> [f64; 3] {
+ [a[0], a[1], a[2]]
+}
+
+// Independent f64 gather oracle: all inputs are averaged linear values, so the
+// GPU's accumulated-sample scaling is absent from this numerical implementation.
+fn reference(width: usize, input: &[[f64; 4]], guides: &[Guide], step: usize) -> Vec<[f64; 4]> {
+ let height = input.len() / width;
+ let kernel = [1.0, 4.0, 6.0, 4.0, 1.0];
+ input
+ .iter()
+ .enumerate()
+ .map(|(i, &center)| {
+ let [a, n, p] = guides[i];
+ if a[3] == 0.0 || center[3] < 0.999 {
+ return center;
+ }
+ let mut result = [0.0; 4];
+ let mut total = 0.0;
+ for (ky, &wy) in kernel.iter().enumerate() {
+ for (kx, &wx) in kernel.iter().enumerate() {
+ let x = (i % width) as isize + (kx as isize - 2) * step as isize;
+ let y = (i / width) as isize + (ky as isize - 2) * step as isize;
+ if x < 0 || y < 0 || x >= width as isize || y >= height as isize {
+ continue;
+ }
+ let j = y as usize * width + x as usize;
+ let [b, m, q] = guides[j];
+ let value = input[j];
+ if a[3] != b[3] || (value[3] - center[3]).abs() > 0.01 {
+ continue;
+ }
+ let albedo = diff(a, b);
+ let position = diff(q, p);
+ let plane = dot(position, xyz(n)).abs() + dot(position, xyz(m)).abs();
+ let scale = (0.05 * p[3].max(q[3]) * step as f64).max(1e-6);
+ let depth = (n[3] - m[3]).abs() / (8.0 * p[3].max(q[3]) * step as f64).max(1e-6);
+ let color = diff(center, value);
+ let maximum = |v: [f64; 3]| v.into_iter().fold(0.0, f64::max);
+ let color_scale = 0.25 + 0.5 * maximum(xyz(center)).max(maximum(xyz(value)));
+ let weight = wx
+ * wy
+ * (-dot(albedo, albedo) / 0.04 - plane / scale - depth - maximum(color.map(f64::abs)) / color_scale).exp()
+ * dot(xyz(n), xyz(m)).max(0.0).powi(32);
+ for k in 0..3 {
+ result[k] += value[k] * weight;
+ }
+ total += weight;
+ }
+ }
+ for v in result.iter_mut().take(3) {
+ *v /= total;
+ }
+ result[3] = center[3];
+ result
+ })
+ .collect()
+}
+fn guide(x: usize, y: usize) -> Guide {
+ [[0.5, 0.5, 0.5, 1.0], [0.0, 0.0, 1.0, 4.0], [x as f64, y as f64, 0.0, 1.0]]
+}
+fn fixture(size: usize) -> (Vec<[f64; 4]>, Vec<Guide>) {
+ let mut pixels = Vec::new();
+ let mut guides = Vec::new();
+ for y in 0..size {
+ for x in 0..size {
+ // Deterministic white noise in [0.4, 0.6]. A pixel-frequency checker would
+ // be invisible to the step-2 and step-4 passes, which only reach same-parity pixels.
+ let hash = ((x * 7919 + y * 104_729) as u64).wrapping_mul(0x9e37_79b9_7f4a_7c15) >> 40;
+ let level = 0.4 + 0.2 * hash as f64 / f64::from(1u32 << 24);
+ pixels.push([level, level, level, 1.0]);
+ guides.push(guide(x, y));
+ }
+ }
+ (pixels, guides)
+}
+#[test]
+fn f64_atrous_reduces_flat_noise_preserves_constant_and_coverage() {
+ let (input, guides) = fixture(17);
+ let mut result = input.clone();
+ for step in [1, 2, 4] {
+ result = reference(17, &result, &guides, step);
+ }
+ let variance = |image: &[[f64; 4]]| {
+ let mean = image.iter().map(|p| p[0]).sum::<f64>() / image.len() as f64;
+ image.iter().map(|p| (p[0] - mean).powi(2)).sum::<f64>() / image.len() as f64
+ };
+ println!("noise variance {} -> {}", variance(&input), variance(&result));
+ assert!(variance(&result) < variance(&input) / 4.0, "noise variance {} -> {}", variance(&input), variance(&result));
+ assert_eq!(reference(17, &vec![[0.7, 0.3, 0.1, 0.5]; 289], &guides, 1), vec![[0.7, 0.3, 0.1, 0.5]; 289]);
+ let constant = reference(17, &vec![[0.75, 0.75, 0.75, 1.0]; 289], &guides, 4);
+ assert!(constant.iter().all(|p| p[..3].iter().all(|x| (*x - 0.75).abs() < 1e-14)));
+}
+#[test]
+fn f64_atrous_preserves_body_normal_depth_and_albedo_edges() {
+ for edge in 0..5 {
+ let mut pixels = Vec::new();
+ let mut guides = Vec::new();
+ for y in 0..17 {
+ for x in 0..17 {
+ let mut g = guide(x, y);
+ let c = if x < 8 { 0.0 } else { 1.0 };
+ if x >= 8 {
+ match edge {
+ 0 => g[0][3] = 2.0,
+ 1 => g[1] = [1.0, 0.0, 0.0, 4.0],
+ 2 => g[2][2] = 10.0,
+ 4 => g[1][3] = 1004.0,
+ _ => g[0] = [1.0, 1.0, 1.0, 1.0],
+ }
+ }
+ if edge == 3 && x < 8 {
+ g[0] = [0.0, 0.0, 0.0, 1.0];
+ }
+ pixels.push([c, c, c, 1.0]);
+ guides.push(g);
+ }
+ }
+ let mut filtered = pixels.clone();
+ for step in [1, 2, 4] {
+ filtered = reference(17, &filtered, &guides, step);
+ }
+ assert!(filtered.iter().zip(&pixels).all(|(a, b)| (a[0] - b[0]).abs() < 1e-12), "edge {edge}");
+ }
+}
+fn context() -> Option<Arc<Context>> {
+ let (_, device, queue) = match open_headless() {
+ Ok(v) => v,
+ Err(e) => {
+ // The path tracer runs on Vulkan only: where the backends in use leave Vulkan out
+ // (macOS, or `WGPU_BACKEND=dx12`), it is unavailable by design, not missing.
+ let vulkan = crate::select::native_backends().contains(wgpu::Backends::VULKAN);
+ assert!(!vulkan || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required GPU unavailable: {e}");
+ return None;
+ }
+ };
+ Some(Executor::new(device, queue).unwrap().context)
+}
+fn request(size: u32) -> ImageRequest {
+ let mut camera = Camera { distance: 4.0, ..Default::default() };
+ camera.set_view(StandardView::Top);
+ ImageRequest { camera, width: size, height: size, background: [0; 3], transparent_background: false, environment: None, textures: None }
+}
+fn plane() -> ProductScene {
+ let mesh = Mesh {
+ positions: vec![Vec3::new(-1.0, -1.0, 0.0), Vec3::new(1.0, -1.0, 0.0), Vec3::new(1.0, 1.0, 0.0), Vec3::new(-1.0, 1.0, 0.0)],
+ normals: vec![Vec3::Z; 4],
+ triangles: vec![[0, 1, 2], [0, 2, 3]],
+ tri_face: vec![0, 0],
+ ..Default::default()
+ };
+ ProductScene {
+ bounds: mesh.bounds(),
+ meshes: vec![ProductMesh {
+ name: "original denoise plane".into(),
+ mesh: Arc::new(mesh),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(OpaqueSurface::new(Vec3::new(0.5, 0.5, 0.5), 0.0, 1.0, 1.5).unwrap()),
+ transmission: None,
+ faces: Vec::new(),
+ }],
+ }
+}
+fn read_guides(context: &Context, buffer: &wgpu::Buffer) -> Vec<[f32; 4]> {
+ let staging = context.device.create_buffer(&wgpu::BufferDescriptor {
+ label: None,
+ size: buffer.size(),
+ usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
+ mapped_at_creation: false,
+ });
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ encoder.copy_buffer_to_buffer(buffer, 0, &staging, 0, buffer.size());
+ let submission = context.queue.submit([encoder.finish()]);
+ let (tx, rx) = std::sync::mpsc::channel();
+ staging.slice(..).map_async(wgpu::MapMode::Read, move |v| {
+ tx.send(v).unwrap();
+ });
+ context.device.poll(wgpu::PollType::Wait { submission_index: Some(submission), timeout: Some(TIMEOUT) }).unwrap();
+ rx.recv().unwrap().unwrap();
+ let mapped = staging.slice(..).get_mapped_range().unwrap();
+ let values = mapped.as_chunks::<16>().0.iter().map(|v| [0, 4, 8, 12].map(|i| f32::from_le_bytes(v[i..i + 4].try_into().unwrap()))).collect();
+ drop(mapped);
+ staging.unmap();
+ values
+}
+#[test]
+fn denoise_admission_counts_guides_and_ping_pong_only_when_enabled() {
+ let scene = plane();
+ let request = request(32);
+ let plain = super::super::admission(&scene, &request, JobOptions::default()).unwrap();
+ let filtered = super::super::admission(&scene, &request, JobOptions { denoise: true, ..Default::default() }).unwrap();
+ assert_eq!(filtered.pixel_scratch_bytes - plain.pixel_scratch_bytes, 32 * 32 * 80);
+ assert_eq!(filtered.estimated_total_bytes - plain.estimated_total_bytes, 32 * 32 * 80);
+ let large = ImageRequest { width: 2000, height: 2000, ..request.clone() };
+ assert!(super::super::admission(&scene, &large, JobOptions::default()).is_ok());
+ assert_eq!(
+ super::super::admission(&scene, &large, JobOptions { denoise: true, ..Default::default() }).unwrap_err().code,
+ solidcraft_render::job::ErrorCode::LimitExceeded
+ );
+ assert!(!serde_json::from_str::<JobOptions>("{}").unwrap().denoise);
+ assert!(serde_json::from_str::<JobOptions>(r#"{"denoise":"true"}"#).is_err());
+}
+#[test]
+fn gpu_atrous_matches_f64_guides_and_leaves_input_unchanged() {
+ let Some(context) = context() else {
+ return;
+ };
+ let (mut input, mut guides) = fixture(13);
+ for y in 0..13 {
+ for x in 7..13 {
+ guides[y * 13 + x][0][3] = 2.0;
+ input[y * 13 + x][0] += 0.8;
+ }
+ }
+ guides[0][0][3] = 0.0;
+ input[1][3] = 0.5;
+ let bytes: Vec<u8> = input.iter().flatten().flat_map(|x| (*x as f32).to_le_bytes()).collect();
+ let device = &context.device;
+ let make = |label, bytes: &[u8]| {
+ device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
+ label: Some(label),
+ contents: bytes,
+ usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC,
+ })
+ };
+ let raw = make("denoise fixture raw", &bytes);
+ let dummy = make("denoise unused geometry", &[0; 64]);
+ let mut task = Task::new(context.clone(), plane(), request(13), JobOptions::default(), CancelToken::default()).unwrap();
+ task.sample = 1;
+ let filter = Resources::new(&context, &task.uniform, [&dummy, &dummy, &dummy, &dummy, &dummy], &raw, bytes.len() as u64).unwrap();
+ let guide_bytes: Vec<u8> = guides.iter().flatten().flatten().flat_map(|x| (*x as f32).to_le_bytes()).collect();
+ context.queue.write_buffer(&filter._guides, 0, &guide_bytes);
+ let before = task.read_linear_buffer(&raw).unwrap();
+ filter.run_filter(&task).unwrap();
+ assert_eq!(before, task.read_linear_buffer(&raw).unwrap());
+ let actual = task.read_linear_buffer(filter.output()).unwrap();
+ let mut expected = input;
+ for step in [1, 2, 4] {
+ expected = reference(13, &expected, &guides, step);
+ }
+ for (a, b) in actual.iter().zip(&expected) {
+ for (x, y) in a.iter().zip(b) {
+ assert!((f64::from(*x) - *y).abs() < 2e-5, "{a:?} vs {b:?}");
+ }
+ }
+}
+#[test]
+fn gpu_denoise_default_false_is_identical_and_true_preserves_raw() {
+ let Some(context) = context() else {
+ return;
+ };
+ let mut outputs = Vec::new();
+ let mut pngs = Vec::new();
+ for options in [
+ JobOptions { samples: 4, ..Default::default() },
+ JobOptions { samples: 4, denoise: false, ..Default::default() },
+ JobOptions { samples: 4, denoise: true, ..Default::default() },
+ ] {
+ let mut task = Task::new(context.clone(), plane(), request(8), options, CancelToken::default()).unwrap();
+ assert_eq!(task.denoiser.is_some(), options.denoise);
+ while task.sample < 4 {
+ task.complete_sample().unwrap();
+ }
+ let raw = task.read_linear().unwrap();
+ if let Some(filter) = &task.denoiser {
+ filter.run(&task).unwrap();
+ assert_eq!(raw, task.read_linear().unwrap());
+ let filtered = task.read_linear_buffer(filter.output()).unwrap();
+ assert!(filtered.iter().all(|p| p.iter().all(|v| v.is_finite())));
+ let guides = read_guides(&context, &filter._guides);
+ assert_eq!(guides[0], [0.0; 4]);
+ let center = (4 * 8 + 4) * 3;
+ assert_eq!(guides[center], [0.5, 0.5, 0.5, 1.0]);
+ assert_eq!(guides[center + 1], [0.0, 0.0, 1.0, 16.0]);
+ assert!((guides[center + 2][0] - 0.2).abs() < 1e-6);
+ assert!((guides[center + 2][1] + 0.2).abs() < 1e-6);
+ assert!((guides[center + 2][3] - 0.4).abs() < 1e-6);
+ }
+ outputs.push(raw);
+ for _ in 0..100 {
+ if let TaskPoll::Complete(png) = task.step(4096).unwrap() {
+ pngs.push(png);
+ break;
+ }
+ }
+ }
+ assert_eq!(outputs[0], outputs[1]);
+ assert_eq!(outputs[0], outputs[2]);
+ assert_eq!(pngs.len(), 3);
+ assert_eq!(pngs[0], pngs[1]);
+}
+#[test]
+fn gpu_denoise_preflight_reports_limits_without_changing_document() {
+ let Some(context) = context() else {
+ return;
+ };
+ let mut session = solidcraft_engine::Session::default();
+ session.set_render_job_host(Some(solidcraft_render::job::CpuHost::cooperative())).unwrap();
+ session.register_render_job_host(solidcraft_render::job::ImageHost::with_executor(Arc::new(Executor { context })).unwrap()).unwrap();
+ session.execute("solid.box", &serde_json::json!({"length":2,"width":2,"height":1})).unwrap();
+ let before = session.doc.to_json();
+ let mut params = serde_json::json!({"progressive":true,"denoise":true,"settings":{"width":8,"height":8}});
+ let reply = session.execute("render.preflight", &params).unwrap();
+ assert_eq!(reply["options"]["denoise"], true);
+ assert_eq!(reply["denoising"]["passes"], 3);
+ assert_eq!(reply["denoising"]["raw_linear_accumulator_preserved"], true);
+ assert_eq!(before, session.doc.to_json());
+ params["progressive"] = serde_json::json!(false);
+ assert!(session.execute("render.preflight", &params).is_err());
+ params["denoise"] = serde_json::json!(false);
+ let reply = session.execute("render.preflight", &params).unwrap();
+ assert!(reply.get("denoising").is_none());
+}
diff --git a/crates/gpu/src/path/dispatch.rs b/crates/gpu/src/path/dispatch.rs
new file mode 100644
index 0000000000..556e5ca180
--- /dev/null
+++ b/crates/gpu/src/path/dispatch.rs
@@ -0,0 +1,70 @@
+//! Conservative work quanta selected from actual submission completion latency.
+//! This is a bounded controller, not a guarantee about a driver's scheduling deadline.
+use std::time::Duration;
+
+pub(super) const MIN_PATHS: u32 = 64;
+pub(super) const MAX_PATHS: u32 = 16_384;
+const TARGET: Duration = Duration::from_millis(20);
+
+#[derive(Clone, Copy, Debug)]
+pub(super) struct Budget {
+ paths: u32,
+}
+impl Default for Budget {
+ fn default() -> Self {
+ Self { paths: MIN_PATHS }
+ }
+}
+impl Budget {
+ pub(super) fn count(&self, remaining: u32) -> u32 {
+ remaining.min(self.paths)
+ }
+ pub(super) fn observe(&mut self, completed: u32, elapsed: Duration) {
+ if completed == 0 {
+ return;
+ }
+ let ideal = u128::from(completed).saturating_mul(TARGET.as_nanos()) / elapsed.as_nanos().max(1);
+ let bounded = ideal.clamp(u128::from(MIN_PATHS), u128::from(MAX_PATHS));
+ let requested = u32::try_from(bounded).unwrap_or(MIN_PATHS);
+ // Never jump from the first tiny/fast dispatch to a large unmeasured one.
+ self.paths = requested.min(self.paths.saturating_mul(2)).clamp(MIN_PATHS, MAX_PATHS);
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ #[test]
+ fn cold_dispatch_starts_small_and_growth_is_bounded() {
+ let mut budget = Budget::default();
+ assert_eq!(budget.count(u32::MAX), 64);
+ for _ in 0..100 {
+ let before = budget.count(u32::MAX);
+ budget.observe(before, Duration::from_nanos(1));
+ let after = budget.count(u32::MAX);
+ assert!(after <= before * 2 && after <= MAX_PATHS);
+ }
+ assert_eq!(budget.count(u32::MAX), MAX_PATHS);
+ budget.observe(MAX_PATHS, Duration::from_secs(10));
+ assert_eq!(budget.count(u32::MAX), MIN_PATHS);
+ assert_eq!(budget.count(17), 17);
+ assert_eq!(budget.count(0), 0);
+ }
+ #[test]
+ fn observed_cost_controls_the_quantum_without_overflow_or_zero_work() {
+ let mut budget = Budget::default();
+ for _ in 0..10 {
+ budget.observe(budget.paths, Duration::from_millis(1));
+ }
+ let before = budget.paths;
+ budget.observe(before, Duration::from_millis(80));
+ assert_eq!(budget.paths, before / 4);
+ let unchanged = budget.paths;
+ budget.observe(0, Duration::ZERO);
+ assert_eq!(budget.paths, unchanged);
+ budget.observe(u32::MAX, Duration::MAX);
+ assert_eq!(budget.paths, MIN_PATHS);
+ budget.observe(u32::MAX, Duration::ZERO);
+ assert_eq!(budget.paths, MIN_PATHS * 2);
+ }
+}
diff --git a/crates/gpu/src/path/mod.rs b/crates/gpu/src/path/mod.rs
new file mode 100644
index 0000000000..1b52e20f9d
--- /dev/null
+++ b/crates/gpu/src/path/mod.rs
@@ -0,0 +1,743 @@
+//! Native progressive product rendering. Software BVH traversal needs no ray-query
+//! features. Small measured quanta adapt to the device, then check cancellation.
+use solidcraft_geom::Vec3;
+use solidcraft_render::{
+ Availability, ExecutorDescriptor, ExecutorId, ProductScene, RenderFeature, RenderFormat, RenderLimits, RenderMode, RenderOperation,
+ RenderProfile, ScratchLayout,
+ job::{
+ Admission, CancelToken, ErrorCode, ImageExecutor, ImageHost, ImageRequest, ImageWork, JobError, JobOptions, Phase, PngTask, Progress, Result,
+ TaskPoll, ToneMap, admit_geometry,
+ },
+};
+use std::{
+ sync::{
+ Arc,
+ atomic::{AtomicBool, Ordering},
+ },
+ time::{Duration, Instant},
+};
+use wgpu::util::DeviceExt;
+
+mod denoise;
+mod dispatch;
+mod scene;
+#[cfg(test)]
+mod tests;
+mod textures;
+const SHADER: &str = concat!(include_str!("path.wgsl"), "\n", include_str!("shadows.wgsl"), "\n", include_str!("textures.wgsl"));
+const MAX_TRIANGLES: u64 = 1_048_576;
+const PARAMETER_BYTES: usize = 448;
+// Eight u32 words: count low, pixel, bounce, sample, code, count high, first-writer flag, spare.
+const FAILURE_BYTES: u64 = 32;
+// A path that cannot classify its glass medium ends there. Isolated paths at the
+// limits of f32 geometry are tolerated and logged; more than this fraction of all
+// paths (any systematic error such as a camera inside glass) fails the job.
+const FAILURE_FRACTION: f64 = 1e-6;
+const TIMEOUT: Duration = Duration::from_secs(30);
+// Software Vulkan drivers can compile a pipeline at its first dispatch, which on a cold
+// shader cache exceeds the per-dispatch hang timeout. Setup dispatches once with no work
+// and allows this longer wait, so jobs keep the short one.
+const SETUP_TIMEOUT: Duration = Duration::from_secs(600);
+
+fn gpu(e: impl std::fmt::Display) -> JobError {
+ JobError::new(ErrorCode::HostUnavailable, e.to_string())
+}
+
+fn scopes(device: &wgpu::Device) -> [wgpu::ErrorScopeGuard; 3] {
+ [wgpu::ErrorFilter::Validation, wgpu::ErrorFilter::OutOfMemory, wgpu::ErrorFilter::Internal].map(|f| device.push_error_scope(f))
+}
+fn checked(scopes: [wgpu::ErrorScopeGuard; 3]) -> Result<()> {
+ let mut error = None;
+ for scope in scopes.into_iter().rev() {
+ if let Some(e) = pollster::block_on(scope.pop()) {
+ error = Some(e);
+ }
+ }
+ error.map_or(Ok(()), |e| Err(gpu(e)))
+}
+
+/// Drain every scope, in reverse order, even when resource creation returns an error.
+/// The ordinary cancellation/error path must not drop an array of guards forwards.
+fn checked_creation<T>(device: &wgpu::Device, create: impl FnOnce() -> Result<T>) -> Result<T> {
+ let error_scopes = scopes(device);
+ let result = create();
+ checked(error_scopes)?;
+ result
+}
+
+/// Open and validate a native device before advertising the executor. Failure leaves the
+/// caller's CPU host usable. Respects SOLIDCRAFT_GPU, including the software adapter policy.
+pub fn host() -> Result<ImageHost> {
+ let (adapter, device, queue) = open_headless()?;
+ log::info!("gpu-path adapter: {} ({:?})", adapter.get_info().name, adapter.get_info().device_type);
+ ImageHost::with_executor(Arc::new(Executor::new(device, queue)?))
+}
+
+/// Open an independent job device on the viewport's selected adapter. In particular,
+/// software fallback and safe mode must not rediscover a failing hardware driver.
+/// An explicit incompatible SOLIDCRAFT_GPU policy leaves this executor unavailable.
+/// The path tracer runs on Vulkan only: a viewport on another backend is reopened on the same
+/// GPU through Vulkan, and without one the executor is unavailable and images render on the CPU.
+pub fn host_on_adapter(adapter: &wgpu::Adapter) -> Result<ImageHost> {
+ let policy = crate::select::Policy::from_env().map_err(gpu)?;
+ let info = adapter.get_info();
+ if !policy.admits(crate::select::tier_of(info.device_type)) {
+ return Err(gpu(format!("viewport adapter does not satisfy SOLIDCRAFT_GPU={}", policy.name())));
+ }
+ if info.backend != wgpu::Backend::Vulkan {
+ let (vulkan, _) = crate::select::pick_vulkan(policy, |i| i.vendor == info.vendor && i.device == info.device)
+ .ok_or_else(|| gpu(format!("{VULKAN_ONLY}; the viewport uses {:?}", info.backend)))?;
+ let (device, queue) = open_device(&vulkan)?;
+ log::info!("gpu-path viewport GPU: {} through Vulkan", info.name);
+ return ImageHost::with_executor(Arc::new(Executor::new(device, queue)?));
+ }
+ let (device, queue) = open_device(adapter)?;
+ log::info!("gpu-path viewport adapter: {} ({:?})", info.name, info.device_type);
+ ImageHost::with_executor(Arc::new(Executor::new(device, queue)?))
+}
+
+/// Why the executor is unavailable without Vulkan (#3217).
+const VULKAN_ONLY: &str = "the GPU path tracer needs a Vulkan driver (images render on the CPU without one)";
+
+// Path resources need six storage buffers (geometry, BVH, accumulation, HDRI,
+// textures, medium-failure counts). Request that limit only on this independent path device: raster and
+// tessellation keep their existing four-buffer downlevel requirement.
+const PATH_STORAGE_BUFFERS: u32 = 6;
+fn device_limits(supported: wgpu::Limits) -> Result<wgpu::Limits> {
+ if supported.max_storage_buffers_per_shader_stage < PATH_STORAGE_BUFFERS {
+ return Err(gpu("gpu-path requires six storage buffers per shader stage"));
+ }
+ let mut limits = wgpu::Limits::downlevel_defaults().using_resolution(supported);
+ limits.max_storage_buffers_per_shader_stage = PATH_STORAGE_BUFFERS;
+ Ok(limits)
+}
+fn open_device(adapter: &wgpu::Adapter) -> Result<(wgpu::Device, wgpu::Queue)> {
+ let required_limits = device_limits(adapter.limits())?;
+ pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
+ label: Some("solidcraft progressive path"),
+ required_features: crate::depth_features(adapter),
+ required_limits,
+ ..Default::default()
+ }))
+ .map_err(gpu)
+}
+fn open_headless() -> Result<(wgpu::Adapter, wgpu::Device, wgpu::Queue)> {
+ let policy = crate::select::Policy::from_env().map_err(gpu)?;
+ let (adapter, _) = crate::select::pick_vulkan(policy, |_| true)
+ .ok_or_else(|| gpu(format!("{VULKAN_ONLY}; no Vulkan adapter satisfies SOLIDCRAFT_GPU={}", policy.name())))?;
+ let (device, queue) = open_device(&adapter)?;
+ Ok((adapter, device, queue))
+}
+
+struct Context {
+ healthy: Arc<AtomicBool>,
+ device: wgpu::Device,
+ queue: wgpu::Queue,
+ pipeline: wgpu::ComputePipeline,
+ // Built and warmed by the first denoised job, then shared by later ones.
+ denoise: std::sync::OnceLock<denoise::Pipelines>,
+ layout: wgpu::BindGroupLayout,
+}
+impl Context {
+ fn ensure_available(&self) -> Result<()> {
+ if self.healthy.load(Ordering::Acquire) {
+ Ok(())
+ } else {
+ Err(JobError::new(
+ ErrorCode::HostUnavailable,
+ "GPU path device was lost or failed to complete work; restart the renderer before retrying",
+ ))
+ }
+ }
+ fn wait(&self, submission: wgpu::SubmissionIndex, timeout: Duration) -> Result<()> {
+ wait_device(&self.device, &self.healthy, submission, timeout)
+ }
+}
+
+fn wait_device(device: &wgpu::Device, healthy: &AtomicBool, submission: wgpu::SubmissionIndex, timeout: Duration) -> Result<()> {
+ if !healthy.load(Ordering::Acquire) {
+ return Err(JobError::new(ErrorCode::HostUnavailable, "GPU path device is unavailable"));
+ }
+ if let Err(error) = device.poll(wgpu::PollType::Wait { submission_index: Some(submission), timeout: Some(timeout) }) {
+ healthy.store(false, Ordering::Release);
+ return Err(JobError::new(ErrorCode::HostUnavailable, format!("GPU path completion failed; executor retired: {error}")));
+ }
+ if !healthy.load(Ordering::Acquire) {
+ return Err(JobError::new(ErrorCode::HostUnavailable, "GPU path device was lost while completing work"));
+ }
+ Ok(())
+}
+
+struct Executor {
+ context: Arc<Context>,
+}
+impl Executor {
+ fn new(device: wgpu::Device, queue: wgpu::Queue) -> Result<Self> {
+ device_limits(device.limits())?;
+ let healthy = Arc::new(AtomicBool::new(true));
+ let uncaptured = healthy.clone();
+ device.on_uncaptured_error(Arc::new(move |e: wgpu::Error| {
+ uncaptured.store(false, Ordering::Release);
+ log::error!("gpu-path executor retired after uncaptured error: {e}");
+ }));
+ let lost = healthy.clone();
+ device.set_device_lost_callback(move |reason, message| {
+ lost.store(false, Ordering::Release);
+ log::warn!("gpu-path device lost ({reason:?}); executor unavailable: {message}");
+ });
+ let scopes = scopes(&device);
+ let shader =
+ device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("gpu-path"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let entries: Vec<_> = (0..7)
+ .map(|binding| wgpu::BindGroupLayoutEntry {
+ binding,
+ visibility: wgpu::ShaderStages::COMPUTE,
+ ty: wgpu::BindingType::Buffer {
+ ty: if binding == 0 {
+ wgpu::BufferBindingType::Uniform
+ } else {
+ wgpu::BufferBindingType::Storage { read_only: binding != 3 && binding != 6 }
+ },
+ has_dynamic_offset: false,
+ min_binding_size: None,
+ },
+ count: None,
+ })
+ .collect();
+ let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { label: Some("gpu-path"), entries: &entries });
+ let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: Some("gpu-path"),
+ bind_group_layouts: &[Some(&layout)],
+ immediate_size: 0,
+ });
+ let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: Some("gpu-path"),
+ layout: Some(&pipeline_layout),
+ module: &shader,
+ entry_point: Some("main"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ checked(scopes)?;
+ warm_up(&device, &queue, &pipeline, &placeholder_bind(&device, &layout, 7)?, &healthy)?;
+ Ok(Self { context: Arc::new(Context { healthy, device, queue, pipeline, layout, denoise: std::sync::OnceLock::new() }) })
+ }
+}
+
+// Small zeroed bindings: binding 0 is a uniform whose zero work count makes every
+// invocation return at once; the others are storage buffers.
+fn placeholder_bind(device: &wgpu::Device, layout: &wgpu::BindGroupLayout, count: u32) -> Result<wgpu::BindGroup> {
+ let scopes = scopes(device);
+ let buffers: Vec<_> = (0..count)
+ .map(|binding| {
+ device.create_buffer(&wgpu::BufferDescriptor {
+ label: Some("gpu-path warm-up"),
+ size: if binding == 0 { PARAMETER_BYTES as u64 } else { 256 },
+ usage: if binding == 0 { wgpu::BufferUsages::UNIFORM } else { wgpu::BufferUsages::STORAGE },
+ mapped_at_creation: false,
+ })
+ })
+ .collect();
+ let entries: Vec<_> = buffers
+ .iter()
+ .enumerate()
+ .map(|(binding, buffer)| wgpu::BindGroupEntry { binding: binding as u32, resource: buffer.as_entire_binding() })
+ .collect();
+ let bind = device.create_bind_group(&wgpu::BindGroupDescriptor { label: Some("gpu-path warm-up"), layout, entries: &entries });
+ checked(scopes)?;
+ Ok(bind)
+}
+
+fn warm_up(device: &wgpu::Device, queue: &wgpu::Queue, pipeline: &wgpu::ComputePipeline, bind: &wgpu::BindGroup, healthy: &AtomicBool) -> Result<()> {
+ let scopes = scopes(device);
+ let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("gpu-path warm-up") });
+ {
+ let mut pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: Some("gpu-path warm-up"), timestamp_writes: None });
+ pass.set_pipeline(pipeline);
+ pass.set_bind_group(0, bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ let submission = queue.submit([encoder.finish()]);
+ checked(scopes)?;
+ wait_device(device, healthy, submission, SETUP_TIMEOUT)?;
+ Ok(())
+}
+
+fn medium_failures_tolerated(failed: u64, paths: u64) -> bool {
+ failed as f64 <= paths as f64 * FAILURE_FRACTION
+}
+
+fn descriptor() -> Result<ExecutorDescriptor> {
+ Ok(ExecutorDescriptor {
+ id: ExecutorId::new("gpu-path").map_err(gpu)?,
+ availability: Availability::Available,
+ profiles: vec![RenderProfile {
+ mode: RenderMode::Preview,
+ operation: RenderOperation::Image,
+ formats: vec![RenderFormat::Png],
+ features: vec![RenderFeature::Pbr, RenderFeature::Progressive, RenderFeature::Refraction, RenderFeature::Hdri],
+ }],
+ limits: RenderLimits::default(),
+ scratch: ScratchLayout { sample_scale: 1, sample_bytes_per_pixel: 16, output_bytes_per_pixel: 16, encoding_bytes_per_pixel: 16 },
+ })
+}
+
+fn admission(scene: &ProductScene, request: &ImageRequest, options: JobOptions) -> Result<Admission> {
+ options.validate()?;
+ if let Some(environment) = &request.environment {
+ environment.validate()?;
+ }
+ let camera = request.camera;
+ if options.lens.is_some_and(|lens| lens.aperture_radius_mm > 0.0)
+ && (camera.distance < 1e-6 || !(1e-6..=1e6).contains(&(camera.half_height() / camera.distance)) || camera.fov == 0.0)
+ {
+ return Err(JobError::new(
+ ErrorCode::InvalidRequest,
+ "thin-lens depth of field requires a bounded perspective camera (distance >= 0.000001 mm and tan(fov/2) in 0.000001..1000000)",
+ ));
+ }
+ if !camera.fov.is_finite()
+ || !(0.0..std::f64::consts::PI).contains(&camera.fov)
+ || !camera.half_height().is_finite()
+ || camera.half_height() > 1e12
+ || camera.distance > 1e9
+ {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "gpu-path requires a bounded finite camera"));
+ }
+ let mut admission = admit_geometry(scene, request, MAX_TRIANGLES)?;
+ if scene
+ .meshes
+ .iter()
+ .any(|m| (m.opacity != 1.0 && m.transmission.is_none()) || m.faces.iter().any(|f| f.opacity != 1.0 && f.transmission.is_none()))
+ {
+ return Err(JobError::new(ErrorCode::InvalidScene, "gpu-path requires explicit transmission for nonopaque preview appearances"));
+ }
+ // Peak preparation: f64 triangles + nodes + serialized upload. After preparation:
+ // serialized + device geometry + accumulation/readback/RGBA/PNG. These phases don't overlap.
+ let pixels = u64::from(request.width) * u64::from(request.height);
+ let denoise_bytes = pixels * if options.denoise { denoise::BYTES_PER_PIXEL } else { 0 };
+ admission.pixel_scratch_bytes = pixels * 64 + denoise_bytes;
+ let vertex_bytes = scene.meshes.iter().map(|m| m.mesh.positions.len() as u64 * 32).sum::<u64>();
+ let triangle_preparation =
+ (admission.triangles * 400_u64.max(scene::planar_preparation_bytes_per_triangle() as u64)).max(scene::medium_preparation_bytes(scene));
+ admission.preparation_bytes = (triangle_preparation + vertex_bytes * 2 + admission.face_appearances * 8)
+ .max(admission.triangles * 232 + vertex_bytes * 2 + pixels * 32 + denoise_bytes)
+ .max(admission.triangles * 116 + vertex_bytes + admission.pixel_scratch_bytes)
+ + 1_048_576;
+ admission.preparation_bytes += request.environment.as_ref().map_or(0, |source| source.admitted_bytes());
+ if let Some(textures) = &request.textures {
+ textures.validate_scene(scene)?;
+ admission.preparation_bytes += textures.working_bytes();
+ }
+ admission.estimated_total_bytes = admission.geometry_bytes + admission.preparation_bytes;
+ if admission.estimated_total_bytes > 512 * 1024 * 1024 {
+ return Err(JobError::new(ErrorCode::LimitExceeded, "gpu-path job exceeds its 512 MiB admission estimate"));
+ }
+ Ok(admission)
+}
+
+impl ImageExecutor for Executor {
+ fn descriptor(&self) -> Result<ExecutorDescriptor> {
+ let mut value = descriptor()?;
+ if !self.context.healthy.load(Ordering::Acquire) {
+ value.availability = Availability::Unavailable { reason: "GPU path device was lost or failed to complete work; restart renderer".into() };
+ }
+ Ok(value)
+ }
+ fn admit(&self, scene: &ProductScene, request: &ImageRequest, options: JobOptions) -> Result<Admission> {
+ self.context.ensure_available()?;
+ let a = admission(scene, request, options)?;
+ let limit = self.context.device.limits().max_storage_buffer_binding_size;
+ let geometry_bytes = 16 + a.triangles.max(1) * 84 + scene.meshes.iter().map(|m| m.mesh.positions.len() as u64 * 32).sum::<u64>();
+ let texture_bytes = request
+ .textures
+ .as_ref()
+ .map_or(16, |t| t.summary().linear_pixel_bytes + 4 * (5 + scene.meshes.len() as u64 + t.bindings().len() as u64 * 16));
+ let environment_bytes =
+ request.environment.as_ref().map_or(48, |source| 16 + u64::from(source.info().width) * u64::from(source.info().height) * 32);
+ if texture_bytes > limit
+ || environment_bytes > limit
+ || geometry_bytes > limit
+ || u64::from(request.width) * u64::from(request.height) * 16 > limit
+ || (options.denoise && u64::from(request.width) * u64::from(request.height) * 48 > limit)
+ {
+ return Err(JobError::new(ErrorCode::LimitExceeded, "gpu-path storage buffer exceeds this device's limit"));
+ }
+ Ok(a)
+ }
+ fn begin(&self, scene: ProductScene, request: ImageRequest, options: JobOptions, cancel: CancelToken) -> Result<Box<dyn ImageWork>> {
+ self.admit(&scene, &request, options)?;
+ Ok(Box::new(Task::new(self.context.clone(), scene, request, options, cancel)?))
+ }
+}
+
+/// Build all fallible CPU environment data before opening GPU error scopes.
+fn prepare_environment(request: &ImageRequest, cancel: &CancelToken) -> Result<Vec<u8>> {
+ cancel.check()?;
+ let mut environment_bytes = Vec::new();
+ if let Some(source) = &request.environment {
+ let prepared = source.prepare(cancel)?;
+ environment_bytes = scene::reserved(16 + prepared.texels().len() * 32)?;
+ let [width, height] = prepared.dimensions();
+ for x in [width, height, width * height, 0] {
+ environment_bytes.extend_from_slice(&x.to_le_bytes());
+ }
+ for (index, texel) in prepared.texels().iter().enumerate() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ for x in texel.rgb.into_iter().chain([texel.pdf, texel.threshold]) {
+ environment_bytes.extend_from_slice(&x.to_le_bytes());
+ }
+ environment_bytes.extend_from_slice(&texel.alias.to_le_bytes());
+ environment_bytes.extend_from_slice(&[0; 8]);
+ }
+ } else {
+ environment_bytes.resize(48, 0);
+ }
+ Ok(environment_bytes)
+}
+
+struct Task {
+ dispatch_budget: dispatch::Budget,
+ context: Arc<Context>,
+ request: ImageRequest,
+ options: JobOptions,
+ cancel: CancelToken,
+ uniform: wgpu::Buffer,
+ accumulation: wgpu::Buffer,
+ failures: wgpu::Buffer,
+ readback: wgpu::Buffer,
+ bind: wgpu::BindGroup,
+ denoiser: Option<denoise::Resources>,
+ sample: u32,
+ offset: u32,
+ epsilon: f32,
+ png: Option<PngTask>,
+ started: Instant,
+ // Uniform environment is used only by the numerical furnace test, never advertised as HDRI.
+ environment: f32,
+ environment_bottom_only: bool,
+ studio: f32,
+ #[cfg(test)]
+ metrics: (f64, u64, f64),
+}
+impl Task {
+ fn new(context: Arc<Context>, scene: ProductScene, mut request: ImageRequest, options: JobOptions, cancel: CancelToken) -> Result<Self> {
+ cancel.check()?;
+ let start = Instant::now();
+ if let Some(resources) = &request.textures {
+ resources.validate_scene(&scene)?;
+ }
+ let texture_upload = textures::flatten(request.textures.as_deref(), scene.meshes.len(), request.camera.target, &cancel)?;
+ request.textures = None; // GPU upload owns decoded pixels; release captured source bytes.
+ let upload = scene::flatten(&scene, request.camera.target, &cancel)?;
+ let bvh_ms = start.elapsed().as_secs_f64() * 1000.0;
+ let mut upload_bytes = (upload.geometry.len() + upload.nodes.len() + texture_upload.len()) as u64;
+ let environment_bytes = prepare_environment(&request, &cancel)?;
+ cancel.check()?;
+ let uploading = Instant::now();
+ drop(scene);
+ let device = &context.device;
+ let (uniform, accumulation, failures, readback, bind, denoiser) = checked_creation(device, || {
+ let make = |label, bytes: &[u8], usage| {
+ device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(label), contents: bytes, usage })
+ };
+ upload_bytes += environment_bytes.len() as u64;
+ let environment = make("path environment", &environment_bytes, wgpu::BufferUsages::STORAGE);
+ drop(environment_bytes);
+ let triangles = make("path triangles", &upload.geometry, wgpu::BufferUsages::STORAGE);
+ let nodes = make("path BVH", &upload.nodes, wgpu::BufferUsages::STORAGE);
+ let texture_buffer = make("path opaque textures", &texture_upload, wgpu::BufferUsages::STORAGE);
+ let uniform = make("path parameters", &[0; PARAMETER_BYTES], wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST);
+ let size = u64::from(request.width) * u64::from(request.height) * 16;
+ let accumulation = device.create_buffer(&wgpu::BufferDescriptor {
+ label: Some("path accumulation"),
+ size,
+ usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC,
+ mapped_at_creation: false,
+ });
+ // Inconsistent-medium path count and the first such path's location (see read_linear).
+ let failures = make(
+ "path medium failures",
+ &[0; FAILURE_BYTES as usize],
+ wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC | wgpu::BufferUsages::COPY_DST,
+ );
+ let readback = device.create_buffer(&wgpu::BufferDescriptor {
+ label: Some("path readback"),
+ size: size + FAILURE_BYTES,
+ usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
+ mapped_at_creation: false,
+ });
+ let mut entries: Vec<_> = [&uniform, &triangles, &nodes, &accumulation, &environment]
+ .iter()
+ .enumerate()
+ .map(|(binding, buffer)| wgpu::BindGroupEntry { binding: binding as u32, resource: buffer.as_entire_binding() })
+ .collect();
+ entries.push(wgpu::BindGroupEntry { binding: 5, resource: texture_buffer.as_entire_binding() });
+ entries.push(wgpu::BindGroupEntry { binding: 6, resource: failures.as_entire_binding() });
+ let bind = device.create_bind_group(&wgpu::BindGroupDescriptor { label: Some("gpu-path"), layout: &context.layout, entries: &entries });
+ let denoiser = if options.denoise {
+ Some(denoise::Resources::new(
+ &context,
+ &uniform,
+ [&triangles, &nodes, &environment, &texture_buffer, &failures],
+ &accumulation,
+ size,
+ )?)
+ } else {
+ None
+ };
+ Ok((uniform, accumulation, failures, readback, bind, denoiser))
+ })?;
+ let submission = context.queue.submit([]);
+ context.wait(submission, TIMEOUT)?;
+ let upload_ms = uploading.elapsed().as_secs_f64() * 1000.0;
+ log::info!("gpu-path BVH {bvh_ms:.3} ms, upload {upload_bytes} bytes in {upload_ms:.3} ms");
+ cancel.check()?;
+ Ok(Self {
+ dispatch_budget: Default::default(),
+ context,
+ request,
+ options,
+ cancel,
+ uniform,
+ accumulation,
+ failures,
+ readback,
+ bind,
+ denoiser,
+ sample: 0,
+ offset: 0,
+ epsilon: upload.epsilon,
+ png: None,
+ started: Instant::now(),
+ environment: 0.0,
+ environment_bottom_only: false,
+ studio: 1.0,
+ #[cfg(test)]
+ metrics: (bvh_ms, upload_bytes, upload_ms),
+ })
+ }
+ fn parameters(&self, count: u32) -> Vec<u8> {
+ let mut bytes = Vec::with_capacity(PARAMETER_BYTES);
+ for x in [
+ self.request.width,
+ self.request.height,
+ self.sample,
+ self.offset,
+ self.options.seed,
+ self.options.max_depth,
+ count,
+ u32::from(self.environment_bottom_only),
+ ] {
+ bytes.extend_from_slice(&x.to_le_bytes());
+ }
+ let camera = self.request.camera;
+ let (right, up, back) = camera.basis();
+ let perspective = camera.fov > 0.0;
+ let eye = back * (camera.distance * if perspective { 1.0 } else { 4.0 });
+ scene::vector(&mut bytes, eye, if perspective { 1.0 } else { 0.0 });
+ scene::vector(
+ &mut bytes,
+ right * camera.half_height() * (f64::from(self.request.width) / f64::from(self.request.height)),
+ self.options.lens.map_or(0.0, |l| l.aperture_radius_mm as f32),
+ );
+ scene::vector(&mut bytes, up * camera.half_height(), self.options.lens.map_or(0.0, |l| l.focus_distance_mm as f32));
+ scene::vector(&mut bytes, back, camera.distance as f32);
+ scene::vector(&mut bytes, Vec3::new(f64::from(self.epsilon), f64::from(self.environment), f64::from(self.studio)), 0.0);
+ let lighting = self.options.lighting.unwrap_or_default();
+ scene::vector(
+ &mut bytes,
+ Vec3::new(lighting.environment[0], lighting.environment[1], lighting.environment[2]),
+ if self.options.lighting.is_some() || self.request.environment.is_some() { 1.0 } else { 0.0 },
+ );
+ scene::vector(&mut bytes, Vec3::ZERO, lighting.area_lights.iter().count() as f32);
+ for light in lighting.area_lights.iter() {
+ let vector = |[x, y, z]: [f64; 3]| Vec3::new(x, y, z);
+ scene::vector(&mut bytes, vector(light.center) - camera.target, light.area() as f32);
+ scene::vector(&mut bytes, vector(light.u), 0.0);
+ scene::vector(&mut bytes, vector(light.v), 0.0);
+ scene::vector(&mut bytes, vector(light.radiance), 0.0);
+ }
+ bytes.resize(400, 0);
+ if let Some(source) = &self.request.environment {
+ let info = source.info();
+ scene::vector(&mut bytes, Vec3::new(info.rotation_rad.cos(), info.rotation_rad.sin(), info.intensity), 1.0);
+ } else {
+ scene::vector(&mut bytes, Vec3::ZERO, 0.0);
+ }
+ if let Some(sun) = lighting.sun {
+ scene::vector(&mut bytes, sun.direction(), sun.angular_radius_rad.cos() as f32);
+ let [r, g, b] = sun.radiance;
+ scene::vector(&mut bytes, Vec3::new(r, g, b), (1.0 / sun.solid_angle()) as f32);
+ } else {
+ bytes.resize(PARAMETER_BYTES, 0);
+ }
+
+ bytes
+ }
+ fn dispatch(&mut self) -> Result<()> {
+ self.cancel.check()?;
+ self.context.ensure_available()?;
+ let dispatch_started = Instant::now();
+ let pixels = self.request.width * self.request.height;
+ let count = self.dispatch_budget.count(pixels - self.offset);
+ let context = &self.context;
+ let scopes = scopes(&context.device);
+ context.queue.write_buffer(&self.uniform, 0, &self.parameters(count));
+ let mut encoder = context.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("path tile") });
+ {
+ let mut pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: Some("path tile"), timestamp_writes: None });
+ pass.set_pipeline(&context.pipeline);
+ pass.set_bind_group(0, &self.bind, &[]);
+ pass.dispatch_workgroups(count.div_ceil(64), 1, 1);
+ }
+ let submission = context.queue.submit([encoder.finish()]);
+ checked(scopes)?;
+ context.wait(submission, TIMEOUT)?;
+ self.dispatch_budget.observe(count, dispatch_started.elapsed());
+ self.cancel.check()?;
+ self.offset += count;
+ if self.offset == pixels {
+ self.sample += 1;
+ self.offset = 0;
+ }
+ Ok(())
+ }
+ #[cfg(test)]
+ fn complete_sample(&mut self) -> Result<()> {
+ let wanted = self.sample.checked_add(1).ok_or_else(|| gpu("sample counter overflow"))?;
+ let maximum = (self.request.width * self.request.height).div_ceil(dispatch::MIN_PATHS);
+ for _ in 0..maximum {
+ self.dispatch()?;
+ if self.sample == wanted {
+ return Ok(());
+ }
+ }
+ Err(gpu("bounded full-sample test helper did not advance"))
+ }
+ fn read_linear(&self) -> Result<Vec<[f32; 4]>> {
+ self.read_linear_buffer(&self.accumulation)
+ }
+ fn read_linear_buffer(&self, source: &wgpu::Buffer) -> Result<Vec<[f32; 4]>> {
+ self.cancel.check()?;
+ let context = &self.context;
+ let scopes = scopes(&context.device);
+ let mut encoder = context.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("path readback") });
+ encoder.copy_buffer_to_buffer(source, 0, &self.readback, 0, self.accumulation.size());
+ encoder.copy_buffer_to_buffer(&self.failures, 0, &self.readback, self.accumulation.size(), FAILURE_BYTES);
+ let submission = context.queue.submit([encoder.finish()]);
+ checked(scopes)?;
+ let slice = self.readback.slice(..);
+ let (tx, rx) = std::sync::mpsc::channel();
+ slice.map_async(wgpu::MapMode::Read, move |result| {
+ let _ = tx.send(result);
+ });
+ context.wait(submission, TIMEOUT)?;
+ rx.try_recv().map_err(gpu)?.map_err(gpu)?;
+ let data = slice.get_mapped_range().map_err(gpu)?;
+ let (pixels, failures) = data.split_at(data.len().saturating_sub(FAILURE_BYTES as usize));
+ let word = |i: usize| failures.as_chunks::<4>().0.get(i).map_or(0, |w| u32::from_le_bytes(*w));
+ let failed = u64::from(word(0)) | (u64::from(word(5)) << 32);
+ if failed > 0 {
+ let paths = u64::from(self.request.width) * u64::from(self.request.height) * u64::from(self.sample.max(1));
+ let detail = format!("{failed} of {paths} paths, first at pixel {}, bounce {}, sample {}, code {}", word(1), word(2), word(3), word(4));
+ if !medium_failures_tolerated(failed, paths) {
+ return Err(JobError::new(
+ ErrorCode::InvalidScene,
+ format!(
+ "inconsistent glass medium paths ({detail}): camera must start outside volumes; overlapping solids or more than 16 nested media are unsupported"
+ ),
+ ));
+ }
+ log::warn!("gpu-path ended {detail} at an unclassifiable glass medium");
+ }
+ let mut values = scene::reserved((self.request.width * self.request.height) as usize)?;
+ for pixel in pixels.as_chunks::<16>().0 {
+ let mut value = [0.0; 4];
+ for (v, bytes) in value.iter_mut().zip(pixel.as_chunks::<4>().0) {
+ *v = f32::from_le_bytes(*bytes) / self.sample as f32;
+ if !v.is_finite() || *v < 0.0 {
+ return Err(JobError::new(ErrorCode::Internal, "nonfinite or negative path radiance"));
+ }
+ }
+ values.push(value);
+ }
+ drop(data);
+ self.readback.unmap();
+ self.cancel.check()?;
+ Ok(values)
+ }
+}
+#[derive(Clone, Copy)]
+struct Display {
+ exposure: f64,
+ tone_map: ToneMap,
+ background: [f64; 3],
+ transparent: bool,
+}
+impl Display {
+ fn encode(self, input: &[[f32; 4]], output: &mut [u8], cancel: &CancelToken) -> Result<()> {
+ for (index, (pixel, rgba)) in input.iter().zip(output.as_chunks_mut::<4>().0).enumerate() {
+ if index % 4096 == 0 {
+ cancel.check()?;
+ }
+ let alpha = f64::from(pixel[3]).clamp(0.0, 1.0);
+ for ((radiance, background), out) in pixel.iter().take(3).zip(self.background).zip(rgba.iter_mut()) {
+ let c = if alpha > 0.0 { f64::from(*radiance) * self.exposure / alpha } else { 0.0 };
+ let mapped = self.tone_map.map(c);
+ let value = if self.transparent { mapped } else { mapped * alpha + background * (1.0 - alpha) };
+ let encoded = if value <= 0.0031308 { value * 12.92 } else { 1.055 * value.powf(1.0 / 2.4) - 0.055 };
+ *out = (encoded.clamp(0.0, 1.0) * 255.0).round() as u8;
+ }
+ rgba[3] = if self.transparent { (alpha * 255.0).round() as u8 } else { 255 };
+ }
+ Ok(())
+ }
+}
+impl ImageWork for Task {
+ fn step(&mut self, units: usize) -> Result<TaskPoll> {
+ self.cancel.check()?;
+ self.context.ensure_available()?;
+ if let Some(png) = &mut self.png {
+ return png.step(units);
+ }
+ if self.sample < self.options.samples {
+ self.dispatch()?;
+ return Ok(TaskPoll::Pending(Progress { phase: Phase::Running, done: u64::from(self.sample), total: u64::from(self.options.samples) }));
+ }
+ log::info!("gpu-path {} spp, {:.3} ms/spp", self.sample, self.started.elapsed().as_secs_f64() * 1000.0 / f64::from(self.sample));
+ let mut linear = self.read_linear()?;
+ if let Some(denoiser) = &self.denoiser {
+ // Diagnose the raw path buffer before filtering: never hide invalid media
+ // or nonfinite radiance by replacing a pixel with neighbouring values.
+ drop(linear);
+ denoiser.run(self)?;
+ linear = self.read_linear_buffer(denoiser.output())?;
+ }
+ let mut rgba = scene::reserved(linear.len() * 4)?;
+ rgba.resize(linear.len() * 4, 0);
+ let display = Display {
+ exposure: 2.0f64.powf(self.options.exposure_ev),
+ tone_map: self.options.tone_map,
+ background: self.request.background.map(solidcraft_render::surface::srgb8_to_linear),
+ transparent: self.request.transparent_background,
+ };
+ // Pixels are independent: encode contiguous chunks on every core.
+ let workers = std::thread::available_parallelism().map_or(1, |n| n.get()).clamp(1, 16);
+ let chunk = linear.len().div_ceil(workers).max(1);
+ let cancel = &self.cancel;
+ std::thread::scope(|scope| {
+ let jobs: Vec<_> = linear
+ .chunks(chunk)
+ .zip(rgba.chunks_mut(chunk * 4))
+ .map(|(input, output)| scope.spawn(move || display.encode(input, output, cancel)))
+ .collect();
+ jobs.into_iter()
+ .try_for_each(|job| job.join().unwrap_or_else(|_| Err(JobError::new(ErrorCode::Internal, "display encoding worker failed"))))
+ })?;
+ self.png = Some(PngTask::new(&self.request, rgba, self.cancel.clone())?);
+ Ok(TaskPoll::Pending(Progress { phase: Phase::Encoding, done: 0, total: u64::from(self.request.height) }))
+ }
+}
diff --git a/crates/gpu/src/path/path.wgsl b/crates/gpu/src/path/path.wgsl
new file mode 100644
index 0000000000..a027415a54
--- /dev/null
+++ b/crates/gpu/src/path/path.wgsl
@@ -0,0 +1,1197 @@
+// Original software BVH and unidirectional Monte Carlo integrator. All directions
+// at a surface point away from it, matching render::surface's GGX/Smith oracle.
+struct Triangle {
+ p0: vec4<f32>, p1: vec4<f32>, p2: vec4<f32>,
+ n0: vec4<f32>, n1: vec4<f32>, n2: vec4<f32>,
+ // base.w: dielectric flag, parameters.w: thin-sheet thickness (-1 = solid).
+ // optics.xyz: extinction per mm, optics.w: body/medium identity (1..16384).
+ base: vec4<f32>, parameters: vec4<f32>, optics: vec4<f32>,
+ coat: vec4<f32>, // weight, perceptual roughness, IOR, shadow transmission flag
+};
+struct Node { lo: vec3<f32>, first: u32, hi: vec3<f32>, count: u32 };
+struct AreaLight { center: vec4<f32>, u: vec4<f32>, v: vec4<f32>, radiance: vec4<f32> };
+struct Params {
+ // width, height, sample index, pixel offset
+ image: vec4<u32>,
+ // seed, maximum depth, tile length, reserved
+ sampling: vec4<u32>,
+ eye: vec4<f32>, right: vec4<f32>, up: vec4<f32>, back: vec4<f32>,
+ // ray epsilon, test environment radiance, studio scale, reserved
+ lighting: vec4<f32>,
+ environment: vec4<f32>, // RGB radiance, enabled flag
+ light_count: vec4<f32>, // w: rectangle count
+ area_lights: array<AreaLight,4>,
+ environment_map: vec4<f32>, // cosine rotation, sine rotation, intensity, enabled
+ sun_direction: vec4<f32>, // normalized toward sun, cosine angular radius
+ sun_radiance: vec4<f32>, // linear RGB, cone density (zero when disabled)
+
+};
+@group(0) @binding(0) var<uniform> u: Params;
+@group(0) @binding(1) var<storage, read> geometry: array<u32>;
+@group(0) @binding(2) var<storage, read> nodes: array<Node>;
+@group(0) @binding(3) var<storage, read_write> accumulation: array<vec4<f32>>;
+struct EnvironmentTexel { rgb: vec3<f32>, pdf: f32, threshold: f32, alternate: u32, padding: vec2<f32> };
+struct EnvironmentData { header: vec4<u32>, texels: array<EnvironmentTexel> };
+@group(0) @binding(4) var<storage, read> environment_data: EnvironmentData;
+// Count low, first pixel/bounce/sample/code, count high, first-writer flag, spare.
+// Two atomic words count jobs with more than 2^32 paths without wrapping to zero.
+@group(0) @binding(6) var<storage, read_write> failures: array<atomic<u32>>;
+// Codes: 1 escaped inside a medium, 2 exit with no medium, 3 exit from another
+// medium, 4 entry while inside a medium or beyond 16 nested media.
+fn medium_failure(radiance: vec3<f32>, coverage: f32, pixel: u32, bounce: u32, code: u32) -> vec4<f32> {
+ if atomicAdd(&failures[0],1u)==0xffffffffu { atomicAdd(&failures[5],1u); }
+ if atomicExchange(&failures[6],1u)==0u {
+ atomicStore(&failures[1],pixel); atomicStore(&failures[2],bounce);
+ atomicStore(&failures[3],u.image.z); atomicStore(&failures[4],code);
+ }
+ // End the path with the light it has already gathered.
+ return vec4<f32>(radiance,coverage);
+}
+const PI: f32 = 3.141592653589793;
+const FAR: f32 = 1e30;
+
+// Header: triangle count, vertex offset, material offset, planar-patch offset (all words).
+// Indexed triangles contain three vertex indices and one resolved material ID.
+fn vector_at(word: u32) -> vec4<f32> {
+ return bitcast<vec4<f32>>(vec4<u32>(geometry[word],geometry[word+1u],geometry[word+2u],geometry[word+3u]));
+}
+fn triangle(index: u32) -> Triangle {
+ let word = 4u+index*4u;
+ let a = geometry[1]+geometry[word]*8u;
+ let b = geometry[1]+geometry[word+1u]*8u;
+ let c = geometry[1]+geometry[word+2u]*8u;
+ let material = geometry[2]+geometry[word+3u]*16u;
+ return Triangle(vector_at(a),vector_at(b),vector_at(c),vector_at(a+4u),vector_at(b+4u),vector_at(c+4u),vector_at(material),vector_at(material+4u),vector_at(material+8u),vector_at(material+12u));
+}
+
+// Exact s/p power reflectance and transmitted cosine; -1 denotes TIR.
+fn dielectric(c: f32, ni: f32, nt: f32) -> vec3<f32> {
+ if ni == nt { return vec3<f32>(0.0,0.0,c); }
+ let eta = ni/nt;
+ let s2 = eta*eta*max(0.0,1.0-c*c);
+ if s2 >= 1.0 { return vec3<f32>(1.0,1.0,-1.0); }
+ let ct = sqrt(1.0-s2);
+ let rs = (ni*c-nt*ct)/(ni*c+nt*ct);
+ let rp = (nt*c-ni*ct)/(nt*c+ni*ct);
+ return vec3<f32>(rs*rs,rp*rp,ct);
+}
+struct Sheet { reflection: vec3<f32>, transmission: vec3<f32> };
+fn sheet_polarization(r: f32, a: vec3<f32>) -> Sheet {
+ let denominator = vec3<f32>(1.0)-r*r*a*a;
+ // The grazing lossless limit is perfectly reflecting.
+ if r >= 1.0 { return Sheet(vec3<f32>(1.0),vec3<f32>(0.0)); }
+ return Sheet(vec3<f32>(r)+(1.0-r)*(1.0-r)*r*a*a/denominator,(1.0-r)*(1.0-r)*a/denominator);
+}
+fn sheet(t: Triangle, f: vec3<f32>) -> Sheet {
+ if f.z <= 0.0 { return Sheet(vec3<f32>(1.0),vec3<f32>(0.0)); }
+ let attenuation = exp(-t.optics.xyz*(t.parameters.w/f.z));
+ let s = sheet_polarization(f.x,attenuation);
+ let p = sheet_polarization(f.y,attenuation);
+ return Sheet((s.reflection+p.reflection)*0.5,(s.transmission+p.transmission)*0.5);
+}
+struct Medium { id: f32, ior: f32, sigma: vec3<f32> };
+
+fn random(state: ptr<function, u32>) -> f32 {
+ *state = *state * 747796405u + 2891336453u;
+ let word = ((*state >> ((*state >> 28u) + 4u)) ^ *state) * 277803737u;
+ return f32(((word >> 22u) ^ word) >> 8u) * (1.0 / 16777216.0);
+}
+
+fn unit(v: vec3<f32>) -> vec3<f32> {
+ let scale = max(max(abs(v.x), abs(v.y)), abs(v.z));
+ if scale == 0.0 { return vec3<f32>(0.0, 0.0, 1.0); }
+ return normalize(v / scale);
+}
+fn fresnel(f0: vec3<f32>, c: f32) -> vec3<f32> {
+ let t = 1.0 - clamp(c, 0.0, 1.0);
+ return f0 + (vec3<f32>(1.0) - f0) * (t*t*t*t*t);
+}
+// An index-matched dielectric has no interface reflection at any angle.
+// Metal fractions still contribute their independently weighted grazing limit.
+fn base_fresnel(f0:vec3<f32>,cosine:f32,metallic:f32,ior:f32)->vec3<f32> {
+ let x=1.0-clamp(cosine,0.0,1.0);
+ let grazing=select(1.0,metallic,ior==1.0);
+ return f0+(vec3<f32>(grazing)-f0)*(x*x*x*x*x);
+}
+fn distribution(nh: f32, a2: f32) -> f32 {
+ let d = (1.0 - nh*nh) + nh*nh*a2;
+ return a2 / (PI*d*d);
+}
+fn brdf(t: Triangle, n: vec3<f32>, v: vec3<f32>, l: vec3<f32>) -> vec3<f32> {
+ let nv = clamp(dot(n,v), -1.0, 1.0);
+ let nl = clamp(dot(n,l), -1.0, 1.0);
+ if nv <= 0.0 || nl <= 0.0 { return vec3<f32>(0.0); }
+ let h = unit(v+l);
+ let a = t.parameters.y*t.parameters.y;
+ let a2 = a*a;
+ let d = distribution(clamp(dot(n,h), 0.0, 1.0), a2);
+ let gv = 2.0 / (nv + sqrt(a2 + (1.0-a2)*nv*nv));
+ let gl = 2.0 / (nl + sqrt(a2 + (1.0-a2)*nl*nl));
+ let ratio = (t.parameters.z - 1.0) / (t.parameters.z + 1.0);
+ let f0 = mix(vec3<f32>(ratio*ratio), t.base.xyz, t.parameters.x);
+ let diffuse = t.base.xyz * ((1.0-t.parameters.x)/PI);
+ let base = base_fresnel(f0, dot(v,h), t.parameters.x, t.parameters.z) * (d*0.25*gv*gl)
+ + (vec3<f32>(1.0)-base_fresnel(f0,nv,t.parameters.x,t.parameters.z)) * (vec3<f32>(1.0)-base_fresnel(f0,nl,t.parameters.x,t.parameters.z)) * diffuse;
+ if t.coat.x <= 0.0 { return base; }
+ let coat_a = t.coat.y*t.coat.y;
+ let coat_a2 = coat_a*coat_a;
+ let coat_d = distribution(clamp(dot(n,h),0.0,1.0),coat_a2);
+ let coat_gv = 2.0/(nv+sqrt(coat_a2+(1.0-coat_a2)*nv*nv));
+ let coat_gl = 2.0/(nl+sqrt(coat_a2+(1.0-coat_a2)*nl*nl));
+ let coat_ratio = (t.coat.z-1.0)/(t.coat.z+1.0);
+ let coat_f0 = vec3<f32>(coat_ratio*coat_ratio);
+ let attenuation = (vec3<f32>(1.0)-t.coat.x*coat_energy_bound(coat_f0,nv))*(vec3<f32>(1.0)-t.coat.x*coat_energy_bound(coat_f0,nl));
+ return base*attenuation+t.coat.x*fresnel(coat_f0,dot(v,h))*(coat_d*0.25*coat_gv*coat_gl);
+}
+
+// Explicit stored vertex anchor plus unadded local offset. Neither field is
+// an error-free floating residual; do not combine them before relative tests.
+// Shader backends may reassociate floating expressions, so the captured corner
+// regressions remain required on each supported backend.
+// Integer-defined IEEE-754 binary32 addition, round-to-nearest/ties-to-even.
+// All alignment and rounding happen in u32, so shader floating reassociation
+// cannot combine anchor subtraction with the subsequent local displacement.
+// The bit interface also preserves subnormals for the arithmetic oracle; normal
+// shader float consumers may still flush subnormal values under WGSL's rules.
+fn fp_shift_jam(value: u32, amount: u32) -> u32 {
+ if amount == 0u { return value; }
+ if amount >= 32u { return select(0u,1u,value != 0u); }
+ let lost = value << (32u-amount);
+ return (value >> amount) | select(0u,1u,lost != 0u);
+}
+fn fp_add_bits(left: u32, right: u32) -> u32 {
+ var a=left;
+ var b=right;
+ if (a&0x7fffffffu) < (b&0x7fffffffu) { a=right; b=left; }
+ let sign=a&0x80000000u;
+ let ea=(a>>23u)&255u;
+ let eb=(b>>23u)&255u;
+ let fa=a&0x7fffffu;
+ let fb=b&0x7fffffu;
+ if ea == 255u {
+ if fa != 0u || (eb == 255u && fb != 0u) { return 0x7fc00000u; }
+ if eb == 255u && ((a^b)&0x80000000u) != 0u { return 0x7fc00000u; }
+ return a;
+ }
+ if (b&0x7fffffffu) == 0u {
+ if (a&0x7fffffffu) == 0u { return (a&b)&0x80000000u; }
+ return a;
+ }
+ var exponent=max(ea,1u);
+ let other_exponent=max(eb,1u);
+ let sa=(fa | select(0u,0x800000u,ea != 0u))<<3u;
+ let sb=fp_shift_jam((fb | select(0u,0x800000u,eb != 0u))<<3u,exponent-other_exponent);
+ var significand=0u;
+ if ((a^b)&0x80000000u) == 0u {
+ significand=sa+sb;
+ if significand >= 0x8000000u {
+ significand=fp_shift_jam(significand,1u);
+ exponent+=1u;
+ }
+ } else {
+ significand=sa-sb;
+ if significand == 0u { return 0u; }
+ // Nonzero significand is below bit 27. Shift to bit 26, or stop at
+ // the subnormal exponent, exactly as the bounded normalization loop.
+ let shift=min(countLeadingZeros(significand)-5u,exponent-1u);
+ significand<<=shift;
+ exponent-=shift;
+ }
+ let remainder=significand&7u;
+ var rounded=significand>>3u;
+ if remainder>4u || (remainder == 4u && (rounded&1u) != 0u) { rounded+=1u; }
+ if rounded >= 0x1000000u { rounded>>=1u; exponent+=1u; }
+ if exponent >= 255u { return sign|0x7f800000u; }
+ if rounded < 0x800000u { exponent=0u; }
+ return sign|(exponent<<23u)|(rounded&0x7fffffu);
+}
+fn fp_sub_bits(left: u32, right: u32) -> u32 {
+ return fp_add_bits(left,right^0x80000000u);
+}
+// Exact identities, then a guarded Sterbenz subtraction. WGSL does not specify
+// RTE for a general floating subtraction, so approximate differences must retain
+// the integer implementation. The fast case has an exactly representable normal
+// result, independent of rounding direction and permitted subnormal flushing.
+fn fp_sub_barrier_bits(left: u32, right: u32) -> u32 {
+ let a=left&0x7fffffffu;
+ let b=right&0x7fffffffu;
+ if a>=0x7f800000u || b>=0x7f800000u { return fp_sub_bits(left,right); }
+ if a==0u {
+ if b==0u { return left&(right^0x80000000u)&0x80000000u; }
+ return right^0x80000000u;
+ }
+ if b==0u { return left; }
+ if left==right { return 0u; }
+ let small=min(a,b);
+ let large=max(a,b);
+ let small_exponent=small>>23u;
+ let large_exponent=large>>23u;
+ let same_sign=((left^right)&0x80000000u)==0u;
+ let within_two=large_exponent==small_exponent ||
+ (large_exponent==small_exponent+1u && (large&0x7fffffu)<=(small&0x7fffffu));
+ // Encoded exponent 24 has spacing 2^-126. Any distinct pair admitted here
+ // therefore has a normal difference, including the closest adjacent pair.
+ if same_sign && small_exponent>=24u && within_two {
+ return bitcast<u32>(bitcast<f32>(left)-bitcast<f32>(right));
+ }
+ return fp_sub_bits(left,right);
+}
+fn anchored_delta_bits(a: u32, a_low: u32, b: u32, b_low: u32) -> u32 {
+ let offset=fp_sub_barrier_bits(a_low,b_low);
+ // Identical finite anchors have +0 difference. Adding it preserves a
+ // nonzero offset; either sign of a zero offset becomes +0.
+ if a==b && (a&0x7fffffffu)<0x7f800000u {
+ return select(offset,0u,(offset&0x7fffffffu)==0u);
+ }
+ let anchor=fp_sub_barrier_bits(a,b);
+ if (offset&0x7fffffffu)==0u {
+ // IEEE RTE addition of two zeros retains -0 only if both are -0.
+ return select(anchor,anchor&offset,(anchor&0x7fffffffu)==0u);
+ }
+ // This nonlinear integer operation is the reassociation barrier. Keep it
+ // even when both component differences used exact hardware subtraction.
+ return fp_add_bits(anchor,offset);
+}
+fn anchored_delta_component(a: f32, a_low: f32, b: f32, b_low: f32) -> f32 {
+ return bitcast<f32>(anchored_delta_bits(bitcast<u32>(a),bitcast<u32>(a_low),bitcast<u32>(b),bitcast<u32>(b_low)));
+}
+
+struct PrecisePoint { hi: vec3<f32>, lo: vec3<f32> };
+fn precise_point_delta(a: vec3<f32>, a_low: vec3<f32>, b: vec3<f32>, b_low: vec3<f32>) -> vec3<f32> {
+ if all(a_low==vec3<f32>(0.0)) && all(b_low==vec3<f32>(0.0)) { return a-b; }
+ return vec3<f32>(anchored_delta_component(a.x,a_low.x,b.x,b_low.x),anchored_delta_component(a.y,a_low.y,b.y,b_low.y),anchored_delta_component(a.z,a_low.z,b.z,b_low.z));
+}
+fn ray_segment_precise(o: vec3<f32>, o_low: vec3<f32>, previous: vec3<f32>, previous_low: vec3<f32>, d: vec3<f32>, distance: f32) -> vec3<f32> {
+ // Subtract the physical origins before adding a possibly tiny ray segment.
+ return precise_point_delta(o,o_low,previous,previous_low)+d*distance;
+}
+
+// Explicit parallel slab handling avoids 0*infinity/NaN at box boundaries.
+// Returns the entry distance into the padded box within [0, limit], or -1.
+fn box_entry_padded(node: Node, o: vec3<f32>, d: vec3<f32>, limit: f32, pad: f32) -> f32 {
+ var near = 0.0;
+ var far = limit;
+ for (var k = 0u; k < 3u; k += 1u) {
+ if abs(d[k]) < 1e-20 {
+ if o[k] < node.lo[k]-pad || o[k] > node.hi[k]+pad { return -1.0; }
+ } else {
+ let a = (node.lo[k]-pad-o[k])/d[k];
+ let b = (node.hi[k]+pad-o[k])/d[k];
+ near = max(near, min(a,b)); far = min(far, max(a,b));
+ }
+ }
+ return select(-1.0,near,far >= near);
+}
+// A strictly positive ray cannot reach a triangle when any coordinate starts
+// on/outside its exact stored bound and moves away. These comparisons introduce
+// no epsilon or rounded division; padded BVH bounds remain only broad phase.
+fn triangle_ahead(t: Triangle, o: vec3<f32>, d: vec3<f32>) -> bool {
+ let lo=min(t.p0.xyz,min(t.p1.xyz,t.p2.xyz));
+ let hi=max(t.p0.xyz,max(t.p1.xyz,t.p2.xyz));
+ if any((o<=lo)&(d<vec3<f32>(0.0))) || any((o>=hi)&(d>vec3<f32>(0.0))) { return false; }
+ if any((d==vec3<f32>(0.0))&((o<lo)|(o>hi))) { return false; }
+ return true;
+}
+fn triangle_ahead_precise(t: Triangle, o: vec3<f32>, o_low: vec3<f32>, d: vec3<f32>) -> bool {
+ if all(o_low==vec3<f32>(0.0)) { return triangle_ahead(t,o,d); }
+ let lo=precise_point_delta(min(t.p0.xyz,min(t.p1.xyz,t.p2.xyz)),vec3<f32>(0.0),o,o_low);
+ let hi=precise_point_delta(max(t.p0.xyz,max(t.p1.xyz,t.p2.xyz)),vec3<f32>(0.0),o,o_low);
+ if any((lo>=vec3<f32>(0.0))&(d<vec3<f32>(0.0))) || any((hi<=vec3<f32>(0.0))&(d>vec3<f32>(0.0))) { return false; }
+ if any((d==vec3<f32>(0.0))&((lo>vec3<f32>(0.0))|(hi<vec3<f32>(0.0)))) { return false; }
+ return true;
+}
+fn difference_products(a: f32, b: f32, c: f32, d: f32) -> f32 {
+ let cd = c*d;
+ let error = fma(-c,d,cd);
+ return fma(a,b,-cd)+error;
+}
+struct Hit { distance: f32, triangle: u32, bary: vec3<f32> };
+// A closed continuation that leaves its producing triangle at a shared edge or
+// vertex can meet an adjacent face of the same body within the origin's rounding
+// error, crossing in the direction it just crossed (an entry while inside, an
+// exit while outside). That is the same interface crossing seen again, not a
+// medium change. Consistent crossings, however short, are always kept.
+fn repeated_crossing(t: Triangle, source: Triangle, d: vec3<f32>, inside: bool, distance: f32, tolerance: f32) -> bool {
+ if distance>tolerance || t.base.w<=0.0 || t.parameters.w>=0.0 || t.optics.w!=source.optics.w { return false; }
+ let a=array<vec3<f32>,3>(t.p0.xyz,t.p1.xyz,t.p2.xyz);
+ let b=array<vec3<f32>,3>(source.p0.xyz,source.p1.xyz,source.p2.xyz);
+ var adjacent=false;
+ for (var i=0u; i<3u; i+=1u) { for (var j=0u; j<3u; j+=1u) { adjacent = adjacent || all(a[i]==b[j]); } }
+ let front=dot(cross(t.p1.xyz-t.p0.xyz,t.p2.xyz-t.p0.xyz),d)<0.0;
+ return adjacent && front==inside;
+}
+// Hits are ordered by the unscaled dominant-axis depth: scaling by 1/d[kz]
+// can round a sharp-rim entry and exit to one distance. On an exact depth tie
+// prefer the face that changes the current medium state: the entry from
+// outside, the exit from inside. Traversal order must not choose it.
+fn tie_preferred(t: Triangle, d: vec3<f32>, inside: bool) -> bool {
+ let front=dot(cross(t.p1.xyz-t.p0.xyz,t.p2.xyz-t.p0.xyz),d)<0.0;
+ return front!=inside;
+}
+fn trace_precise(o: vec3<f32>, o_low: vec3<f32>, d: vec3<f32>, any_hit: bool, excluded: u32, minimum: f32, inside: bool) -> Hit {
+ return trace_precise_within(o,o_low,d,any_hit,excluded,minimum,inside,FAR,-1.0);
+}
+// Only hits closer than `limit` are reported, and nodes beyond it are culled.
+// An opaque or shadow-blocking hit closer than `blocker` ends traversal at once:
+// a shadow connection is blocked whichever such hit is closest.
+fn trace_precise_within(o: vec3<f32>, o_low: vec3<f32>, d: vec3<f32>, any_hit: bool, excluded: u32, minimum: f32, inside: bool, limit: f32, blocker: f32) -> Hit {
+ // Dispatch once before traversal. Ordinary rays keep the original lean BVH
+ // loop, without precision-helper branches inside every candidate/node test.
+ if all(o_low==vec3<f32>(0.0)) { return trace_ordered_within(o,d,any_hit,excluded,minimum,inside,limit,blocker); }
+ var hit = Hit(limit, 0xffffffffu, vec3<f32>(0.0));
+ // Project every candidate into the same ray-aligned 2D coordinate system.
+ // Shared edges then use identical products with opposite signs, avoiding the
+ // independently rounded barycentric comparisons of Moller-Trumbore.
+ var kz = 0u;
+ if abs(d.y)>abs(d.x) { kz=1u; }
+ if abs(d.z)>abs(d[kz]) { kz=2u; }
+ let kx=(kz+1u)%3u; let ky=(kx+1u)%3u;
+ let shear=vec3<f32>(d[kx]/d[kz],d[ky]/d[kz],1.0/d[kz]);
+ let order=select(-1.0,1.0,d[kz]>0.0);
+ var best=FAR;
+ // Only candidates near the origin need the integer-defined deltas. The
+ // rounded origin is within a few ULPs of the true anchor plus offset, so
+ // boxes grown by that bound reject conservatively: every point the true
+ // ray reaches at depth t lies in the grown box along the rounded ray at
+ // the same t. A triangle whose bounds are farther from the rounded origin
+ // than the near radius uses ordinary arithmetic from it: that error cannot
+ // reorder such a hit, but it can move the ray across an edge, so decisions
+ // within the error bound of an edge or bound fall back to the exact path.
+ let rounded=o+o_low;
+ let scale=max(max(abs(rounded.x),max(abs(rounded.y),abs(rounded.z))),1.0);
+ let origin_error=scale*(1.0/1048576.0);
+ let pad=u.lighting.x+origin_error;
+ var source: Triangle;
+ if excluded!=0xffffffffu { source=triangle(excluded); }
+ let near_radius=scale*(1.0/256.0);
+ // Children are tested at their parent and visited near-first. The build
+ // bounds tree depth to 30, so at most 31 nodes are pending.
+ var stack: array<u32, 32>;
+ var entry: array<f32, 32>;
+ if nodes[0].first == 0xffffffffu { return hit; }
+ entry[0] = box_entry_padded(nodes[0], rounded, d, hit.distance, pad);
+ if entry[0] < 0.0 { return hit; }
+ stack[0] = 0u;
+ var size = 1u;
+ loop {
+ if size == 0u { break; }
+ size -= 1u;
+ if entry[size] > hit.distance { continue; }
+ let node = nodes[stack[size]];
+ if node.count == 0u {
+ if size + 2u > 32u { break; }
+ let left = box_entry_padded(nodes[node.first], rounded, d, hit.distance, pad);
+ let right = box_entry_padded(nodes[node.first+1u], rounded, d, hit.distance, pad);
+ var near_child = node.first; var near_entry = left;
+ var far_child = node.first+1u; var far_entry = right;
+ if right >= 0.0 && (left < 0.0 || right < left) {
+ near_child = node.first+1u; near_entry = right;
+ far_child = node.first; far_entry = left;
+ }
+ if far_entry >= 0.0 { stack[size] = far_child; entry[size] = far_entry; size += 1u; }
+ if near_entry >= 0.0 { stack[size] = near_child; entry[size] = near_entry; size += 1u; }
+ continue;
+ }
+ for (var i = node.first; i < node.first + node.count; i += 1u) {
+ if i == excluded { continue; }
+ // A straight continuation cannot revisit its producing exact plane.
+ // IDs join only connected, exactly coplanar uploaded f32 triangles
+ // of one body; curved facets and other bodies remain candidates.
+ if excluded!=0xffffffffu && geometry[geometry[3]+i]==geometry[geometry[3]+excluded] { continue; }
+ let t = triangle(i);
+ let lo=min(t.p0.xyz,min(t.p1.xyz,t.p2.xyz));
+ let hi=max(t.p0.xyz,max(t.p1.xyz,t.p2.xyz));
+ let gap=max(lo-rounded,rounded-hi);
+ if any(gap>vec3<f32>(near_radius)) {
+ // The rounded origin is within origin_error of the true one on each
+ // axis. Bound and edge decisions that close to their threshold could
+ // flip, while a nearby neighbour across the edge is tested exactly:
+ // a crossing would fall between them. Such candidates take the exact
+ // path below.
+ if any((rounded<=lo-vec3<f32>(origin_error))&(d<vec3<f32>(0.0))) || any((rounded>=hi+vec3<f32>(origin_error))&(d>vec3<f32>(0.0))) { continue; }
+ if any((d==vec3<f32>(0.0))&((rounded<lo-vec3<f32>(origin_error))|(rounded>hi+vec3<f32>(origin_error)))) { continue; }
+ let qa=t.p0.xyz-rounded; let qb=t.p1.xyz-rounded; let qc=t.p2.xyz-rounded;
+ let fa=vec2<f32>(qa[kx]-shear.x*qa[kz],qa[ky]-shear.y*qa[kz]);
+ let fb=vec2<f32>(qb[kx]-shear.x*qb[kz],qb[ky]-shear.y*qb[kz]);
+ let fc=vec2<f32>(qc[kx]-shear.x*qc[kz],qc[ky]-shear.y*qc[kz]);
+ let far_weights=vec3<f32>(difference_products(fb.x,fc.y,fb.y,fc.x),difference_products(fc.x,fa.y,fc.y,fa.x),difference_products(fa.x,fb.y,fa.y,fb.x));
+ let edge_error=origin_error*vec3<f32>(length(fb-fc),length(fc-fa),length(fa-fb));
+ if all(abs(far_weights)>edge_error) {
+ if any(far_weights<vec3<f32>(0.0)) && any(far_weights>vec3<f32>(0.0)) { continue; }
+ let far_det=far_weights.x+far_weights.y+far_weights.z;
+ let far_bary=far_weights/far_det;
+ let far_depth=surface_ray_depth(t,far_bary,rounded,kz);
+ let far_distance=far_depth*shear.z;
+ let far_key=far_depth*order;
+ if far_distance > minimum && far_distance < limit && (far_key < best || (far_key == best && tie_preferred(t,d,inside))) {
+ hit = Hit(far_distance,i,far_bary); best=far_key;
+ if any_hit || (far_distance < blocker && (t.base.w<=0.0 || t.coat.w<=0.0)) { return hit; }
+ }
+ continue;
+ }
+ }
+ if !triangle_ahead_precise(t,o,o_low,d) { continue; }
+ let pa=precise_point_delta(t.p0.xyz,vec3<f32>(0.0),o,o_low);
+ let pb=precise_point_delta(t.p1.xyz,vec3<f32>(0.0),o,o_low);
+ let pc=precise_point_delta(t.p2.xyz,vec3<f32>(0.0),o,o_low);
+ let a=vec2<f32>(pa[kx]-shear.x*pa[kz],pa[ky]-shear.y*pa[kz]);
+ let b=vec2<f32>(pb[kx]-shear.x*pb[kz],pb[ky]-shear.y*pb[kz]);
+ let c=vec2<f32>(pc[kx]-shear.x*pc[kz],pc[ky]-shear.y*pc[kz]);
+ let weights=vec3<f32>(difference_products(b.x,c.y,b.y,c.x),difference_products(c.x,a.y,c.y,a.x),difference_products(a.x,b.y,a.y,b.x));
+ if any(weights<vec3<f32>(0.0)) && any(weights>vec3<f32>(0.0)) { continue; }
+ let det=weights.x+weights.y+weights.z;
+ if det==0.0 { continue; }
+ // Retain all three directly evaluated weights: 1-u-v can erase a
+ // small corner clearance when the other two weights sum to one.
+ let bary=weights/det;
+ let depth=surface_ray_depth_precise(t,bary,o,o_low,kz);
+ let distance=depth*shear.z;
+ let key=depth*order;
+ if excluded!=0xffffffffu && repeated_crossing(t,source,d,inside,distance,origin_error) { continue; }
+ if distance > minimum && distance < limit && (key < best || (key == best && tie_preferred(t,d,inside))) {
+ hit = Hit(distance,i,bary); best=key;
+ if any_hit || (distance < blocker && (t.base.w<=0.0 || t.coat.w<=0.0)) { return hit; }
+ }
+ }
+ }
+ return hit;
+}
+
+fn trace_bounded(o: vec3<f32>, d: vec3<f32>, any_hit: bool, excluded: u32, minimum: f32) -> Hit {
+ return trace_ordered_within(o,d,any_hit,excluded,minimum,false,FAR,-1.0);
+}
+fn trace_ordered_within(o: vec3<f32>, d: vec3<f32>, any_hit: bool, excluded: u32, minimum: f32, inside: bool, limit: f32, blocker: f32) -> Hit {
+ var hit = Hit(limit, 0xffffffffu, vec3<f32>(0.0));
+ let origin_error=max(max(abs(o.x),max(abs(o.y),abs(o.z))),1.0)*(1.0/1048576.0);
+ var source: Triangle;
+ if excluded!=0xffffffffu { source=triangle(excluded); }
+ // Project every candidate into the same ray-aligned 2D coordinate system.
+ // Shared edges then use identical products with opposite signs, avoiding the
+ // independently rounded barycentric comparisons of Moller-Trumbore.
+ var kz = 0u;
+ if abs(d.y)>abs(d.x) { kz=1u; }
+ if abs(d.z)>abs(d[kz]) { kz=2u; }
+ let kx=(kz+1u)%3u; let ky=(kx+1u)%3u;
+ let shear=vec3<f32>(d[kx]/d[kz],d[ky]/d[kz],1.0/d[kz]);
+ let order=select(-1.0,1.0,d[kz]>0.0);
+ var best=FAR;
+ // Children are tested at their parent and visited near-first. The build
+ // bounds tree depth to 30, so at most 31 nodes are pending.
+ var stack: array<u32, 32>;
+ var entry: array<f32, 32>;
+ if nodes[0].first == 0xffffffffu { return hit; }
+ entry[0] = box_entry_padded(nodes[0], o, d, hit.distance, u.lighting.x);
+ if entry[0] < 0.0 { return hit; }
+ stack[0] = 0u;
+ var size = 1u;
+ loop {
+ if size == 0u { break; }
+ size -= 1u;
+ if entry[size] > hit.distance { continue; }
+ let node = nodes[stack[size]];
+ if node.count == 0u {
+ if size + 2u > 32u { break; }
+ let left = box_entry_padded(nodes[node.first], o, d, hit.distance, u.lighting.x);
+ let right = box_entry_padded(nodes[node.first+1u], o, d, hit.distance, u.lighting.x);
+ var near_child = node.first; var near_entry = left;
+ var far_child = node.first+1u; var far_entry = right;
+ if right >= 0.0 && (left < 0.0 || right < left) {
+ near_child = node.first+1u; near_entry = right;
+ far_child = node.first; far_entry = left;
+ }
+ if far_entry >= 0.0 { stack[size] = far_child; entry[size] = far_entry; size += 1u; }
+ if near_entry >= 0.0 { stack[size] = near_child; entry[size] = near_entry; size += 1u; }
+ continue;
+ }
+ for (var i = node.first; i < node.first + node.count; i += 1u) {
+ if i == excluded { continue; }
+ // A straight continuation cannot revisit its producing exact plane.
+ // IDs join only connected, exactly coplanar uploaded f32 triangles
+ // of one body; curved facets and other bodies remain candidates.
+ if excluded!=0xffffffffu && geometry[geometry[3]+i]==geometry[geometry[3]+excluded] { continue; }
+ let t = triangle(i);
+ if !triangle_ahead(t,o,d) { continue; }
+ let pa=t.p0.xyz-o; let pb=t.p1.xyz-o; let pc=t.p2.xyz-o;
+ let a=vec2<f32>(pa[kx]-shear.x*pa[kz],pa[ky]-shear.y*pa[kz]);
+ let b=vec2<f32>(pb[kx]-shear.x*pb[kz],pb[ky]-shear.y*pb[kz]);
+ let c=vec2<f32>(pc[kx]-shear.x*pc[kz],pc[ky]-shear.y*pc[kz]);
+ let weights=vec3<f32>(difference_products(b.x,c.y,b.y,c.x),difference_products(c.x,a.y,c.y,a.x),difference_products(a.x,b.y,a.y,b.x));
+ if any(weights<vec3<f32>(0.0)) && any(weights>vec3<f32>(0.0)) { continue; }
+ let det=weights.x+weights.y+weights.z;
+ if det==0.0 { continue; }
+ // Retain all three directly evaluated weights: 1-u-v can erase a
+ // small corner clearance when the other two weights sum to one.
+ let bary=weights/det;
+ let depth=surface_ray_depth(t,bary,o,kz);
+ let distance=depth*shear.z;
+ let key=depth*order;
+ if excluded!=0xffffffffu && repeated_crossing(t,source,d,inside,distance,origin_error) { continue; }
+ if distance > minimum && distance < limit && (key < best || (key == best && tie_preferred(t,d,inside))) {
+ hit = Hit(distance,i,bary); best=key;
+ if any_hit || (distance < blocker && (t.base.w<=0.0 || t.coat.w<=0.0)) { return hit; }
+ }
+ }
+ }
+ return hit;
+}
+fn trace(o: vec3<f32>, d: vec3<f32>, any_hit: bool) -> Hit {
+ return trace_bounded(o,d,any_hit,0xffffffffu,u.lighting.x);
+}
+fn dominant_vertex(bary: vec3<f32>) -> u32 {
+ var anchor=0u;
+ if bary.y>bary.x { anchor=1u; }
+ if bary.z>bary[anchor] { anchor=2u; }
+ return anchor;
+}
+fn surface_point(t: Triangle, bary: vec3<f32>) -> vec3<f32> {
+ // Anchor near the hit, retaining the two other directly computed weights.
+ // A tiny weight on a distant vertex can encode an entire corner clearance.
+ // Do not recover that weight by subtracting the other two from one.
+ let p=array<vec3<f32>,3>(t.p0.xyz,t.p1.xyz,t.p2.xyz);
+ let a=dominant_vertex(bary); let b=(a+1u)%3u; let c=(a+2u)%3u;
+ return p[a]+((p[b]-p[a])*bary[b]+(p[c]-p[a])*bary[c]);
+}
+fn surface_point_precise(t: Triangle, bary: vec3<f32>) -> PrecisePoint {
+ let p=array<vec3<f32>,3>(t.p0.xyz,t.p1.xyz,t.p2.xyz);
+ let a=dominant_vertex(bary); let b=(a+1u)%3u; let c=(a+2u)%3u;
+ // Keep the world anchor separate from its local displacement.
+ return PrecisePoint(p[a],(p[b]-p[a])*bary[b]+(p[c]-p[a])*bary[c]);
+}
+fn surface_ray_depth_precise(t: Triangle, bary: vec3<f32>, origin: vec3<f32>, origin_low: vec3<f32>, axis: u32) -> f32 {
+ if all(origin_low==vec3<f32>(0.0)) { return surface_ray_depth(t,bary,origin,axis); }
+ let point=surface_point_precise(t,bary);
+ return anchored_delta_component(point.hi[axis],point.lo[axis],origin[axis],origin_low[axis]);
+}
+fn surface_ray_depth(t: Triangle, bary: vec3<f32>, origin: vec3<f32>, axis: u32) -> f32 {
+ let p=array<vec3<f32>,3>(t.p0.xyz,t.p1.xyz,t.p2.xyz);
+ let a=dominant_vertex(bary); let b=(a+1u)%3u; let c=(a+2u)%3u;
+ // Original vertex differences avoid subtracting two rounded ray-relative
+ // coordinates; adding the anchor last preserves distant thin-hit ordering.
+ return (p[a][axis]-origin[axis])+((p[b][axis]-p[a][axis])*bary[b]+(p[c][axis]-p[a][axis])*bary[c]);
+}
+
+fn from_local(p: vec3<f32>, n: vec3<f32>) -> vec3<f32> {
+ let axis = select(vec3<f32>(0.0,0.0,1.0),vec3<f32>(0.0,1.0,0.0),abs(n.z)>0.9);
+ let x = unit(cross(axis,n));
+ return unit(x*p.x + cross(n,x)*p.y + n*p.z);
+}
+fn sample_surface(t: Triangle, n: vec3<f32>, v: vec3<f32>, rng: ptr<function,u32>) -> vec3<f32> {
+ let component = random(rng); let x = random(rng); let y = random(rng);
+ return sample_surface_values(t,n,v,vec3<f32>(component,x,y));
+}
+// Conditional opaque mixture density; branch selection is accounted for by callers.
+fn surface_pdf(t: Triangle, n: vec3<f32>, v: vec3<f32>, l: vec3<f32>) -> f32 {
+ let nl = dot(n,l);
+ if nl<=0.0 || dot(n,v)<=0.0 { return 0.0; }
+ let h = unit(v+l); let vh = max(dot(v,h),1e-20);
+ let nh = max(dot(n,h),0.0);
+ let alpha = t.parameters.y*t.parameters.y;
+ let base = 0.5*nl/PI+0.5*distribution(nh,alpha*alpha)*nh/(4.0*vh);
+ if t.coat.x<=0.0 { return base; }
+ let coat_alpha = t.coat.y*t.coat.y;
+ let coat_pdf = distribution(nh,coat_alpha*coat_alpha)*nh/(4.0*vh);
+ return (1.0-t.coat.x*0.5)*base+t.coat.x*0.5*coat_pdf;
+}
+fn power_weight(a: f32, b: f32) -> f32 {
+ // Ratio form avoids overflow for grazing/very distant rectangular samples.
+ if a <= 0.0 { return 0.0; }
+ let ratio = b/a;
+ return 1.0/(1.0+ratio*ratio);
+}
+struct EmitterHit { distance: f32, index: u32 };
+fn emitter_hit_precise(o: vec3<f32>, o_low: vec3<f32>, d: vec3<f32>, minimum: f32) -> EmitterHit {
+ var hit = EmitterHit(FAR,0xffffffffu);
+ for (var i=0u; i<u32(u.light_count.w); i+=1u) {
+ let light = u.area_lights[i];
+ let normal = unit(cross(light.u.xyz,light.v.xyz));
+ let cosine = dot(normal,d);
+ if abs(cosine)<1e-8 { continue; }
+ let to_light=precise_point_delta(light.center.xyz,vec3<f32>(0.0),o,o_low);
+ let distance = dot(to_light,normal)/cosine;
+ if distance <= minimum || distance >= hit.distance { continue; }
+ var q = o+d*distance-light.center.xyz;
+ if any(o_low!=vec3<f32>(0.0)) { q=fma(d,vec3<f32>(distance),-to_light); }
+ if abs(dot(q,light.u.xyz))<=dot(light.u.xyz,light.u.xyz) && abs(dot(q,light.v.xyz))<=dot(light.v.xyz,light.v.xyz) {
+ hit = EmitterHit(distance,i);
+ }
+ }
+ return hit;
+}
+fn emitter_hit_bounded(o: vec3<f32>, d: vec3<f32>, minimum: f32) -> EmitterHit {
+ return emitter_hit_precise(o,vec3<f32>(0.0),d,minimum);
+}
+fn emitter_hit(o: vec3<f32>, d: vec3<f32>) -> EmitterHit {
+ return emitter_hit_bounded(o,d,u.lighting.x);
+}
+
+fn area_pdf(light: AreaLight, delta: vec3<f32>) -> f32 {
+ let cosine = dot(unit(cross(light.u.xyz,light.v.xyz)),-unit(delta));
+ if cosine<=0.0 { return 0.0; }
+ return dot(delta,delta)/(light.center.w*cosine);
+}
+fn visible(o: vec3<f32>, d: vec3<f32>, distance: f32) -> ShadowResult {
+ if emitter_hit(o,d).distance<distance-u.lighting.x*2.0 { return blocked_shadow(); }
+ return shadow_transmittance(o,d,distance);
+}
+struct EnvironmentSample { direction: vec3<f32>, radiance: vec3<f32>, pdf: f32 };
+fn environment_to_world(d: vec3<f32>) -> vec3<f32> {
+ return vec3<f32>(u.environment_map.x*d.x-u.environment_map.y*d.y,u.environment_map.y*d.x+u.environment_map.x*d.y,d.z);
+}
+fn environment_index(d: vec3<f32>) -> u32 {
+ let local=vec3<f32>(u.environment_map.x*d.x+u.environment_map.y*d.y,-u.environment_map.y*d.x+u.environment_map.x*d.y,d.z);
+ var phi=atan2(local.y,local.x); if phi<0.0 {phi+=2.0*PI;}
+ let dims=environment_data.header.xy;
+ let x=min(u32(phi/(2.0*PI)*f32(dims.x)),dims.x-1u);
+ let y=min(u32(acos(clamp(local.z,-1.0,1.0))/PI*f32(dims.y)),dims.y-1u);
+ return y*dims.x+x;
+}
+fn env_eval(d: vec3<f32>) -> vec3<f32> {
+ if u.environment_map.w>0.0 {return environment_data.texels[environment_index(d)].rgb*u.environment_map.z;}
+ return u.environment.xyz;
+}
+fn env_pdf(d: vec3<f32>) -> f32 {
+ if u.environment_map.w>0.0 {return environment_data.texels[environment_index(d)].pdf;}
+ return 1.0/(4.0*PI);
+}
+fn env_sample(rng: ptr<function,u32>) -> EnvironmentSample {
+ if u.environment_map.w>0.0 {
+ let dims=environment_data.header.xy;
+ let choice=random(rng)*f32(environment_data.header.z);
+ let initial=min(u32(choice),environment_data.header.z-1u);
+ let entry=environment_data.texels[initial];
+ let index=select(entry.alternate,initial,random(rng)<entry.threshold);
+ let texel=environment_data.texels[index];
+ let row=index/dims.x; let column=index%dims.x;
+ let top=cos(PI*f32(row)/f32(dims.y)); let bottom=cos(PI*f32(row+1u)/f32(dims.y));
+ let z=mix(top,bottom,random(rng));
+ let phi=2.0*PI*(f32(column)+random(rng))/f32(dims.x);
+ let radius=sqrt(max(0.0,1.0-z*z));
+ let direction=environment_to_world(vec3<f32>(radius*cos(phi),radius*sin(phi),z));
+ return EnvironmentSample(direction,texel.rgb*u.environment_map.z,texel.pdf);
+ }
+ let z=1.0-2.0*random(rng);let phi=2.0*PI*random(rng);
+ let radius=sqrt(max(0.0,1.0-z*z));
+ return EnvironmentSample(vec3<f32>(radius*cos(phi),radius*sin(phi),z),u.environment.xyz,1.0/(4.0*PI));
+}
+fn sun_pdf(d:vec3<f32>)->f32 {
+ return select(0.0,u.sun_radiance.w,dot(d,u.sun_direction.xyz)>=u.sun_direction.w);
+}
+fn sun_eval(d:vec3<f32>)->vec3<f32> {
+ return select(vec3<f32>(0.0),u.sun_radiance.xyz,sun_pdf(d)>0.0);
+}
+fn sun_sample(rng:ptr<function,u32>)->EnvironmentSample {
+ // Derive 1-cos(radius) from the CPU's stable solid angle, not f32 subtraction.
+ let z=1.0-random(rng)/(2.0*PI*u.sun_radiance.w);
+ let phi=2.0*PI*random(rng);let radius=sqrt(max(0.0,1.0-z*z));
+ let direction=from_local(vec3<f32>(radius*cos(phi),radius*sin(phi),z),u.sun_direction.xyz);
+ return EnvironmentSample(direction,u.sun_radiance.xyz,u.sun_radiance.w);
+}
+fn direct_studio(t: Triangle, position: vec3<f32>, o: vec3<f32>, n: vec3<f32>, geometric: vec3<f32>, v: vec3<f32>, remaining: u32, rng: ptr<function,u32>) -> vec3<f32> {
+ var result = vec3<f32>(0.0);
+ let opaque = 1.0-t.base.w;
+ if opaque<=0.0 { return result; }
+ for (var i=0u; i<u32(u.light_count.w); i+=1u) {
+ let light = u.area_lights[i];
+ let point = light.center.xyz + light.u.xyz*(2.0*random(rng)-1.0) + light.v.xyz*(2.0*random(rng)-1.0);
+ let delta = point-position;
+ let direction = unit(delta);
+ let pdf = area_pdf(light,delta);
+ let nl = dot(n,direction);
+ if pdf<=0.0 || nl<=0.0 || dot(geometric,direction)<=0.0 { continue; }
+ let shadow = point-o;
+ let visibility=visible(o,unit(shadow),length(shadow));
+ let competing=opaque*surface_pdf(t,n,v,direction)*visibility.branch_pdf;
+ let weight=select(power_weight(pdf,competing),1.0,visibility.solid || visibility.crossings>=remaining);
+ result += visibility.transmittance*brdf(t,n,v,direction)*light.radiance.xyz*(opaque*nl*weight/pdf);
+ }
+ if u.environment_map.w>0.0 || any(u.environment.xyz>vec3<f32>(0.0)) {
+ let sample=env_sample(rng);
+ let nl=dot(n,sample.direction);
+ if sample.pdf>0.0 && nl>0.0 && dot(geometric,sample.direction)>0.0 {
+ let visibility=visible(o,sample.direction,FAR);
+ let competing=opaque*surface_pdf(t,n,v,sample.direction)*visibility.branch_pdf;
+ let weight=select(power_weight(sample.pdf,competing),1.0,visibility.solid || visibility.crossings>=remaining);
+ result+=visibility.transmittance*brdf(t,n,v,sample.direction)*sample.radiance*(opaque*nl*weight/sample.pdf);
+ }
+ }
+ if u.sun_radiance.w>0.0 {
+ let sample=sun_sample(rng);
+ let nl=dot(n,sample.direction);
+ if nl>0.0 && dot(geometric,sample.direction)>0.0 {
+ let visibility=visible(o,sample.direction,FAR);
+ let competing=opaque*surface_pdf(t,n,v,sample.direction)*visibility.branch_pdf;
+ let weight=select(power_weight(sample.pdf,competing),1.0,visibility.solid || visibility.crossings>=remaining);
+ result+=visibility.transmittance*brdf(t,n,v,sample.direction)*sample.radiance*(opaque*nl*weight/sample.pdf);
+ }
+ }
+ return result;
+}
+struct CameraRay { origin: vec3<f32>, direction: vec3<f32> };
+// The lens lies in the eye plane. A uniform-area disk (r=sqrt(u), phi=2pi*v)
+// aims at the pinhole ray's intersection with the axial focus plane.
+fn primary_ray(uv: vec2<f32>, lens_sample: vec2<f32>) -> CameraRay {
+ let offset = u.right.xyz*uv.x + u.up.xyz*uv.y;
+ var o = u.eye.xyz + offset;
+ var d = -u.back.xyz;
+ if u.eye.w > 0.5 { o = u.eye.xyz; d = unit(offset-u.back.xyz*u.back.w); }
+ if u.eye.w > 0.5 && u.right.w > 0.0 {
+ let radius = sqrt(lens_sample.x)*u.right.w;
+ let phi = 2.0*PI*lens_sample.y;
+ let displacement = radius*(cos(phi)*unit(u.right.xyz)+sin(phi)*unit(u.up.xyz));
+ // Construct the focal point directly, avoiding division by a tiny ray cosine.
+ let focal = offset*(u.up.w/u.back.w)-u.back.xyz*u.up.w;
+ o += displacement;
+ d = unit(focal-displacement);
+ }
+ return CameraRay(o,d);
+}
+fn sample_path(pixel: u32) -> vec4<f32> {
+ var rng = pixel ^ (u.image.z * 0x9e3779b9u) ^ u.sampling.x;
+ let xy = vec2<f32>(f32(pixel % u.image.x)+random(&rng), f32(pixel / u.image.x)+random(&rng));
+ let uv = vec2<f32>(xy.x/f32(u.image.x)*2.0-1.0, 1.0-xy.y/f32(u.image.y)*2.0);
+ var lens_sample = vec2<f32>(0.0);
+ // Zero aperture consumes no variates: preserve the pinhole sample stream exactly.
+ if u.eye.w > 0.5 && u.right.w > 0.0 { lens_sample = vec2<f32>(random(&rng),random(&rng)); }
+ let primary = primary_ray(uv,lens_sample);
+ var o = primary.origin;
+ var o_low = vec3<f32>(0.0);
+ var d = primary.direction;
+ var previous_position = o;
+ var previous_position_low = vec3<f32>(0.0);
+ var ray_excluded = 0xffffffffu;
+ var ray_minimum = u.lighting.x;
+ var previous_scatter_position = o;
+ var previous_scatter_position_low = vec3<f32>(0.0);
+ // NEE-only opt-in solid approximation replaces direct transmitted emitter
+ // paths from an opaque bounce. Camera and reflected paths stay physical.
+ var suppress_direct = false;
+ var throughput = vec3<f32>(1.0);
+ var radiance = vec3<f32>(0.0);
+ var coverage = 0.0;
+ var previous_pdf = 0.0;
+ var previous_delta = true;
+ var media: array<Medium,16>;
+ var medium_count = 0u;
+ let lights = array<vec4<f32>,3>(vec4<f32>(0.6,0.0,0.8,3.0),vec4<f32>(-0.8,0.0,0.6,1.0),vec4<f32>(0.0,-0.6,0.8,1.5));
+ for (var bounce = 0u; bounce < u.sampling.y; bounce += 1u) {
+ // Closed-glass continuations set an excluded producing triangle; every
+ // other launch (camera, opaque or thin-sheet surface) does not.
+ let continued = ray_excluded != 0xffffffffu;
+ let hit = trace_precise(o,o_low,d,false,ray_excluded,ray_minimum,medium_count>0u);
+ if u.environment.w > 0.0 {
+ let emitter = emitter_hit_precise(o,o_low,d,ray_minimum);
+ if emitter.distance < hit.distance {
+ let light = u.area_lights[emitter.index];
+ let segment = ray_segment_precise(o,o_low,previous_position,previous_position_low,d,emitter.distance);
+ if medium_count>0u {
+ throughput *= exp(-media[medium_count-1u].sigma*length(segment));
+ }
+ let scatter_segment = ray_segment_precise(o,o_low,previous_scatter_position,previous_scatter_position_low,d,emitter.distance);
+ let pdf = area_pdf(light,scatter_segment);
+ if pdf>0.0 && !suppress_direct {
+ let weight = select(power_weight(previous_pdf,pdf),1.0,previous_delta);
+ radiance += throughput*light.radiance.xyz*weight;
+ }
+ coverage = 1.0;
+ break;
+ }
+ }
+ if hit.triangle == 0xffffffffu {
+ // Camera-inside and intersecting/open volumes are deliberately unsupported.
+ if medium_count > 0u { return medium_failure(radiance,coverage,pixel,bounce,1u); }
+ if u.environment.w > 0.0 {
+ // The backplate remains request.background; environment lights covered paths.
+ if bounce>0u && !suppress_direct {
+ let weight = select(power_weight(previous_pdf,env_pdf(d)),1.0,previous_delta);
+ radiance += throughput*env_eval(d)*weight;
+ let sun_weight=select(power_weight(previous_pdf,sun_pdf(d)),1.0,previous_delta);
+ radiance += throughput*sun_eval(d)*sun_weight;
+ }
+ } else if u.sampling.w == 0u || d.z < 0.0 { radiance += throughput * u.lighting.y; }
+ break;
+ }
+ coverage = 1.0;
+ ray_excluded = 0xffffffffu; ray_minimum = u.lighting.x;
+ var t = triangle(hit.triangle); let v = -d;
+ var geometric = unit(cross(t.p1.xyz-t.p0.xyz,t.p2.xyz-t.p0.xyz));
+ let entering = dot(geometric,v)>=0.0;
+ if !entering { geometric = -geometric; }
+ var ni = 1.0;
+ if medium_count > 0u {
+ let current = media[medium_count-1u];
+ ni = current.ior;
+ }
+ var n = unit(t.n0.xyz*hit.bary.x+t.n1.xyz*hit.bary.y+t.n2.xyz*hit.bary.z);
+ if dot(n,geometric)<0.0 { n = -n; }
+ if dot(n,v)<=0.0 { n = geometric; }
+ // Recover the surface point from barycentrics. A distant ray's f32 distance
+ // loses precision on skinny triangles; o+d*t can land behind the surface
+ // and make the next shadow ray intersect the same face.
+ var position = surface_point(t,hit.bary);
+ var position_low = vec3<f32>(0.0);
+ if t.base.w>0.0 && t.parameters.w<0.0 {
+ let point=surface_point_precise(t,hit.bary);
+ position=point.hi; position_low=point.lo;
+ }
+ let shading_position = position+position_low;
+ t = texture_surface(t,shading_position);
+ let original_normal = n;
+ n = texture_normal(t,shading_position,n,geometric);
+ if dot(n,v)<=0.0 { n=original_normal; }
+ if medium_count > 0u {
+ let segment=precise_point_delta(position,position_low,previous_position,previous_position_low);
+ throughput *= exp(-media[medium_count-1u].sigma*length(segment));
+ }
+ previous_position = position; previous_position_low=position_low;
+ o = position + geometric*(u.lighting.x*2.0); o_low=vec3<f32>(0.0);
+ if u.environment.w > 0.0 {
+ radiance += throughput*direct_studio(t,position,o,n,geometric,v,u.sampling.y-bounce-1u,&rng);
+ }
+ for (var i=0u; i<3u && u.environment.w==0.0; i+=1u) {
+ let light = lights[i];
+ if u.lighting.z > 0.0 && dot(geometric,light.xyz)>0.0 && dot(n,light.xyz)>0.0 {
+ let visibility=shadow_transmittance(o,light.xyz,FAR);
+ radiance += visibility.transmittance * throughput * brdf(t,n,v,light.xyz) * ((1.0-t.base.w)*light.w*dot(n,light.xyz)*u.lighting.z);
+ }
+ }
+ if t.base.w > 0.0 && random(&rng) < t.base.w {
+ var nt = t.parameters.z;
+ if t.parameters.w < 0.0 && entering && medium_count > 0u {
+ return medium_failure(radiance,coverage,pixel,bounce,4u);
+ }
+ if t.parameters.w < 0.0 && !entering {
+ if medium_count == 0u {
+ // A ray launched from a surface (not the camera, not a glass
+ // continuation) whose first crossing exits closed glass started
+ // inside that body: the surface touches or lies within the glass,
+ // like a tumbler resting on a table. Start the path in its medium.
+ if continued || bounce == 0u { return medium_failure(radiance,coverage,pixel,bounce,2u); }
+ media[0] = Medium(t.optics.w,t.parameters.z,t.optics.xyz);
+ medium_count = 1u;
+ ni = t.parameters.z;
+ throughput *= exp(-t.optics.xyz*hit.distance);
+ }
+ if media[medium_count-1u].id != t.optics.w { return medium_failure(radiance,coverage,pixel,bounce,3u); }
+ nt = 1.0;
+ if medium_count > 1u { nt = media[medium_count-2u].ior; }
+ }
+ var f = dielectric(clamp(dot(n,v),0.0,1.0),ni,nt);
+ var transmitted = refract(d,n,ni/nt);
+ // A bent shading normal must not send a transmitted ray into the wrong
+ // geometric hemisphere. Fall back to the geometric interface there.
+ if (f.z >= 0.0 && dot(transmitted,geometric) >= 0.0) || dot(reflect(d,n),geometric) <= 0.0 {
+ n = geometric;
+ f = dielectric(clamp(dot(n,v),0.0,1.0),ni,nt);
+ transmitted = refract(d,n,ni/nt);
+ }
+ if t.parameters.w >= 0.0 {
+ let weights = sheet(t,f);
+ let mean_r = dot(weights.reflection,vec3<f32>(1.0/3.0));
+ let mean_t = dot(weights.transmission,vec3<f32>(1.0/3.0));
+ if mean_r+mean_t <= 0.0 { break; }
+ let probability = mean_r/(mean_r+mean_t);
+ if random(&rng) < probability {
+ previous_delta=true; previous_scatter_position=position; previous_scatter_position_low=position_low; suppress_direct=false;
+ throughput *= weights.reflection/probability;
+ d = reflect(d,n);
+ } else {
+ throughput *= weights.transmission/(1.0-probability);
+ if t.coat.w>0.0 { previous_pdf*=1.0-probability; }
+ else { previous_delta=true; previous_scatter_position=position; previous_scatter_position_low=position_low; suppress_direct=false; }
+ // Keep a straight connection through sheets: geometric-normal
+ // offsets would change emitter solid-angle PDFs along this chain.
+ o = position+d*(u.lighting.x*2.0);
+ // Parallel thin sheet: unchanged direction, no optical displacement.
+ }
+ } else if random(&rng) < (f.x+f.y)*0.5 {
+ previous_delta=true; previous_scatter_position=position; previous_scatter_position_low=position_low; suppress_direct=false;
+ d = reflect(d,n);
+ } else {
+ if t.coat.w>0.0 { suppress_direct=suppress_direct || !previous_delta; }
+ else { suppress_direct=false; }
+ previous_delta=true; previous_scatter_position=position; previous_scatter_position_low=position_low;
+ if entering {
+ if medium_count >= 16u { return medium_failure(radiance,coverage,pixel,bounce,4u); }
+ media[medium_count] = Medium(t.optics.w,nt,t.optics.xyz);
+ medium_count += 1u;
+ } else { medium_count -= 1u; }
+ throughput *= (ni/nt)*(ni/nt);
+ d = unit(transmitted);
+ o = position-geometric*(u.lighting.x*2.0);
+ }
+ if dot(d,geometric) > 0.0 { o = position+geometric*(u.lighting.x*2.0); }
+ if t.parameters.w<0.0 {
+ // A finite normal offset can cross the next face near a closed
+ // corner. Launch on the reconstructed boundary, suppress only
+ // the producing triangle, and retain every strictly positive exit.
+ // Consistent medium crossings retain even arbitrarily short
+ // exits; repeated adjacent crossings are handled by traversal.
+ // A continuation within 1e-6 of tangent skims its producing face:
+ // the reconstructed point's rounding then decides which side of
+ // the neighbouring faces it is on, so its medium cannot be
+ // classified. Such directions carry negligible energy; end the path.
+ if abs(dot(d,geometric))<1e-6 { break; }
+ o=position; o_low=position_low; ray_excluded=hit.triangle; ray_minimum=0.0;
+ }
+ continue;
+ }
+ d = sample_surface(t,n,v,&rng);
+ let nl = dot(n,d);
+ if nl<=0.0 || dot(geometric,d)<=0.0 { break; }
+ let pdf = surface_pdf(t,n,v,d);
+ previous_pdf = (1.0-t.base.w)*pdf;
+ previous_scatter_position=position; previous_scatter_position_low=position_low;
+ previous_delta = false;
+ suppress_direct=false;
+ throughput *= brdf(t,n,v,d) * (nl/pdf);
+ if bounce>=3u {
+ let survive = clamp(max(max(throughput.x,throughput.y),throughput.z),0.05,0.95);
+ if random(&rng)>survive { break; }
+ throughput /= survive;
+ }
+ }
+ return vec4<f32>(radiance,coverage);
+}
+
+@compute @workgroup_size(64)
+fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
+ let pixel = u.image.w + gid.x;
+ if gid.x >= u.sampling.z || pixel >= u.image.x*u.image.y { return; }
+ let sample = sample_path(pixel);
+ if u.image.z == 0u { accumulation[pixel] = sample; }
+ else { accumulation[pixel] += sample; }
+}
+
+// Validation entry point: exact same BRDF used by production paths, read back in tests.
+@compute @workgroup_size(1)
+fn reference() {
+ accumulation[0] = vec4<f32>(brdf(triangle(0u),u.up.xyz,u.back.xyz,u.right.xyz),1.0);
+}
+
+@compute @workgroup_size(1)
+fn dielectric_reference() {
+ let f = dielectric(u.up.x,u.up.y,u.up.z);
+ accumulation[0] = vec4<f32>(f.xy,max(f.z,0.0),1.0);
+}
+
+@compute @workgroup_size(1)
+fn camera_reference() {
+ let ray = primary_ray(u.lighting.xy,u.lighting.zw);
+ // Bias signed test coordinates for the radiance readback's nonnegative contract.
+ accumulation[0] = vec4<f32>(ray.origin+vec3<f32>(16.0),1.0);
+ accumulation[1] = vec4<f32>(ray.direction+vec3<f32>(2.0),1.0);
+}
+
+// Deterministic image-space ball-lens check. Uses the production BVH/intersection
+// and interpolated normal data, with Snell transport through both interfaces.
+@compute @workgroup_size(1)
+fn lens_reference() {
+ let direction = u.back.xyz;
+ let entry = trace(u.eye.xyz,direction,false);
+ if entry.triangle == 0xffffffffu { accumulation[0] = vec4<f32>(0.0); return; }
+ let a = triangle(entry.triangle);
+ let pa = surface_point(a,entry.bary);
+ let na = unit(a.n0.xyz*entry.bary.x+a.n1.xyz*entry.bary.y+a.n2.xyz*entry.bary.z);
+ let inside = refract(direction,na,1.0/a.parameters.z);
+ let exit = trace(pa-na*u.lighting.x*2.0,inside,false);
+ if exit.triangle == 0xffffffffu { accumulation[0] = vec4<f32>(0.0); return; }
+ let b = triangle(exit.triangle);
+ let pb = surface_point(b,exit.bary);
+ let nb = unit(b.n0.xyz*exit.bary.x+b.n1.xyz*exit.bary.y+b.n2.xyz*exit.bary.z);
+ let outgoing = refract(inside,-nb,b.parameters.z);
+ let spot = pb+outgoing*((-u.back.w-pb.z)/outgoing.z);
+ accumulation[0] = vec4<f32>(spot+vec3<f32>(1.0,1.0,3.0),1.0);
+}
+
+// GPU/CPU orientation and matched-density check uses the production lookup helpers.
+@compute @workgroup_size(1)
+fn environment_reference() {
+ accumulation[0]=vec4<f32>(env_eval(u.right.xyz),env_pdf(u.right.xyz));
+}
+
+fn coat_energy_bound(f0: vec3<f32>, cosine: f32) -> vec3<f32> {
+ let minimum_vh = cosine/sqrt(2.0*(1.0+sqrt(max(0.0,1.0-cosine*cosine))));
+ return fresnel(f0,minimum_vh);
+}
+
+fn sample_surface_values(t: Triangle, n: vec3<f32>, v: vec3<f32>, variates: vec3<f32>) -> vec3<f32> {
+ let component = variates.x;
+ let x = variates.y; let phi = 2.0*PI*variates.z;
+ let coat_probability = t.coat.x*0.5;
+ if component < (1.0-coat_probability)*0.5 {
+ let radius = sqrt(x);
+ return from_local(vec3<f32>(radius*cos(phi),radius*sin(phi),sqrt(1.0-x)),n);
+ }
+ let roughness = select(t.parameters.y,t.coat.y,component >= 1.0-coat_probability);
+ let alpha = roughness*roughness;
+ let cosine = sqrt((1.0-x)/(1.0+(alpha*alpha-1.0)*x));
+ let sine = sqrt(max(0.0,1.0-cosine*cosine));
+ let h = from_local(vec3<f32>(sine*cos(phi),sine*sin(phi),cosine),n);
+ return reflect(-v,h);
+}
+
+@compute @workgroup_size(1)
+fn surface_sample_reference() {
+ let d = sample_surface_values(triangle(0u),u.up.xyz,u.back.xyz,u.lighting.xyz);
+ accumulation[0] = vec4<f32>(d+vec3<f32>(2.0),1.0);
+}
+
+@compute @workgroup_size(1)
+fn pdf_reference() {
+ accumulation[0] = vec4<f32>(surface_pdf(triangle(0u),u.up.xyz,u.back.xyz,u.right.xyz),0.0,0.0,1.0);
+}
+
+// Diagnostic entry point for independently specified closed-corner fixtures.
+@compute @workgroup_size(1)
+fn boundary_reference() {
+ let entry=trace(u.eye.xyz,u.back.xyz,false);
+ if entry.triangle==0xffffffffu {accumulation[0]=vec4<f32>(9.0,9.0,9.0,1.0);return;}
+ let t=triangle(entry.triangle);
+ let position=surface_point(t,entry.bary);
+ let outward=unit(cross(t.p1.xyz-t.p0.xyz,t.p2.xyz-t.p0.xyz));
+ let shifted=position-outward*(2.0*u.lighting.x);
+ let legacy=trace(shifted,u.right.xyz,false);
+ let low_min=trace_bounded(shifted,u.right.xyz,false,entry.triangle,0.0);
+ let exact=trace_bounded(position,u.right.xyz,false,entry.triangle,0.0);
+ accumulation[0]=vec4<f32>(select(0.0,1.0,legacy.triangle!=0xffffffffu),select(0.0,1.0,low_min.triangle!=0xffffffffu),select(0.0,1.0,exact.triangle!=0xffffffffu),1.0);
+ accumulation[1]=vec4<f32>(exact.distance,0.0,0.0,1.0);
+ accumulation[2]=vec4<f32>(abs(position),1.0);
+ accumulation[3]=vec4<f32>(f32(entry.triangle),entry.bary.yz,1.0);
+}
+
+@compute @workgroup_size(1)
+fn positive_triangle_reference() {
+ let hit=trace_bounded(u.eye.xyz,u.right.xyz,false,0xffffffffu,0.0);
+ accumulation[0]=vec4<f32>(select(0.0,1.0,hit.triangle!=0xffffffffu),0.0,0.0,1.0);
+}
+
+// Producing hit barycentrics are prescribed independently to exercise f32 point
+// reconstruction on a translated oblique split plane, then a grazing reflection.
+@compute @workgroup_size(1)
+fn coplanar_boundary_reference() {
+ let position=surface_point(triangle(0u),vec3<f32>(1.0-u.eye.x-u.eye.y,u.eye.xy));
+ let hit=trace_bounded(position,u.right.xyz,false,0u,0.0);
+ accumulation[0]=vec4<f32>(select(0.0,1.0,hit.triangle!=0xffffffffu),hit.distance,0.0,1.0);
+ accumulation[1]=vec4<f32>(position,1.0);
+}
+
+fn ordering_candidate(t: Triangle, o: vec3<f32>, d: vec3<f32>) -> vec2<f32> {
+ var kz=0u;
+ if abs(d.y)>abs(d.x) {kz=1u;}
+ if abs(d.z)>abs(d[kz]) {kz=2u;}
+ let kx=(kz+1u)%3u; let ky=(kx+1u)%3u;
+ let shear=vec3<f32>(d[kx]/d[kz],d[ky]/d[kz],1.0/d[kz]);
+ let pa=t.p0.xyz-o; let pb=t.p1.xyz-o; let pc=t.p2.xyz-o;
+ let a=vec2<f32>(pa[kx]-shear.x*pa[kz],pa[ky]-shear.y*pa[kz]);
+ let b=vec2<f32>(pb[kx]-shear.x*pb[kz],pb[ky]-shear.y*pb[kz]);
+ let c=vec2<f32>(pc[kx]-shear.x*pc[kz],pc[ky]-shear.y*pc[kz]);
+ let weights=vec3<f32>(difference_products(b.x,c.y,b.y,c.x),difference_products(c.x,a.y,c.y,a.x),difference_products(a.x,b.y,a.y,b.x));
+ let det=weights.x+weights.y+weights.z;
+ let bary=weights/det;
+ let distance=surface_ray_depth(t,bary,o,kz)*shear.z;
+ let valid=!(any(weights<vec3<f32>(0.0))&&any(weights>vec3<f32>(0.0))) && det!=0.0;
+ return vec2<f32>(distance,select(0.0,1.0,valid));
+}
+// Closed continuation from an anchor (eye) plus local offset (right) along up,
+// excluding triangle 0's producing patch; eye.w > 0.5 starts inside a medium.
+@compute @workgroup_size(1)
+fn continuation_reference() {
+ let hit=trace_precise(u.eye.xyz,u.right.xyz,u.up.xyz,false,0u,0.0,u.eye.w>0.5);
+ accumulation[0]=vec4<f32>(f32(hit.triangle),hit.distance,0.0,1.0);
+}
+@compute @workgroup_size(1)
+fn ordering_reference() {
+ let hit=trace(u.eye.xyz,u.right.xyz,false);
+ let a=ordering_candidate(triangle(0u),u.eye.xyz,u.right.xyz);
+ let b=ordering_candidate(triangle(1u),u.eye.xyz,u.right.xyz);
+ accumulation[0]=vec4<f32>(f32(hit.triangle),hit.distance,0.0,1.0);
+ accumulation[1]=vec4<f32>(a,0.0,1.0);
+ accumulation[2]=vec4<f32>(b,0.0,1.0);
+}
+
+@compute @workgroup_size(1)
+fn refracted_corner_reference() {
+ let entry=trace(u.eye.xyz,u.right.xyz,false);
+ if entry.triangle==0xffffffffu {accumulation[0]=vec4<f32>(0.0,0.0,0.0,1.0);return;}
+ let t=triangle(entry.triangle);
+ let position=surface_point(t,entry.bary);
+ let outward=unit(cross(t.p1.xyz-t.p0.xyz,t.p2.xyz-t.p0.xyz));
+ let inside=refract(u.right.xyz,outward,1.0/t.parameters.z);
+ let exit=trace_ordered_within(position,inside,false,entry.triangle,0.0,true,FAR,-1.0);
+ var valid_exit=false;
+ if exit.triangle!=0xffffffffu {
+ let other=triangle(exit.triangle);
+ let normal=unit(cross(other.p1.xyz-other.p0.xyz,other.p2.xyz-other.p0.xyz));
+ valid_exit=other.optics.w==t.optics.w && dot(normal,inside)>0.0;
+ }
+ accumulation[0]=vec4<f32>(select(0.0,1.0,dot(outward,u.right.xyz)<0.0),select(0.0,1.0,exit.triangle!=0xffffffffu),select(0.0,1.0,valid_exit),1.0);
+ accumulation[1]=vec4<f32>(exit.distance,0.0,0.0,1.0);
+ accumulation[2]=vec4<f32>(abs(position),1.0);
+ accumulation[3]=vec4<f32>(inside+vec3<f32>(2.0),1.0);
+}
+
+@compute @workgroup_size(1)
+fn rib_residual_reference() {
+ var source=0xffffffffu;
+ for(var i=0u;i<geometry[0];i+=1u) {
+ let t=triangle(i);
+ if all(t.p0.xyz==u.eye.xyz)&&all(t.p1.xyz==u.right.xyz)&&all(t.p2.xyz==u.up.xyz) {source=i;break;}
+ }
+ if source==0xffffffffu {accumulation[0]=vec4<f32>(9.0,9.0,9.0,1.0);return;}
+ let t=triangle(source);
+ let point=surface_point_precise(t,u.environment.xyz);
+ let outward=unit(cross(t.p1.xyz-t.p0.xyz,t.p2.xyz-t.p0.xyz));
+ let direction=reflect(u.back.xyz,outward);
+ let f=dielectric(abs(dot(outward,u.back.xyz)),t.parameters.z,1.0);
+ let dropped=trace_bounded(point.hi+point.lo,direction,false,source,0.0);
+ let retained=trace_precise(point.hi,point.lo,direction,false,source,0.0,true);
+ var valid_exit=false;
+ if retained.triangle!=0xffffffffu {
+ let other=triangle(retained.triangle);
+ let n=unit(cross(other.p1.xyz-other.p0.xyz,other.p2.xyz-other.p0.xyz));
+ valid_exit=other.optics.w==t.optics.w&&dot(n,direction)>0.0;
+ }
+ accumulation[0]=vec4<f32>(select(0.0,1.0,dropped.triangle!=0xffffffffu),select(0.0,1.0,retained.triangle!=0xffffffffu),select(0.0,1.0,valid_exit),1.0);
+ accumulation[1]=vec4<f32>(retained.distance,select(0.0,1.0,f.z<0.0),0.0,1.0);
+ accumulation[2]=vec4<f32>(abs(point.hi),1.0);
+ accumulation[3]=vec4<f32>(abs(point.lo),1.0);
+}
+
+// Results are encoded as exact positive 16-bit integers in floats so the normal
+// radiance readback can transport every binary32 bit pattern, including NaNs.
+@compute @workgroup_size(64)
+fn integer_float_reference(@builtin(global_invocation_id) invocation: vec3<u32>) {
+ let i=invocation.x;
+ if i>=geometry[0] { return; }
+ let a=geometry[1u+i*2u];
+ let b=geometry[2u+i*2u];
+ let sum=fp_add_bits(a,b);
+ let difference=fp_sub_barrier_bits(a,b);
+ accumulation[i]=vec4<f32>(f32(sum&65535u),f32(sum>>16u),f32(difference&65535u),f32(difference>>16u));
+}
+
+@compute @workgroup_size(1)
+fn emitter_segment_reference() {
+ // A local offset large compared with this real ray segment. Accumulating
+ // the endpoint into the offset first needlessly rounds away part of d*t.
+ let anchor=vec3<f32>(-163.7,-55.0,-55.0);
+ let offset=vec3<f32>(0.000007887696,0.000009279658,-10.753371);
+ let direction=vec3<f32>(0.6,0.0,0.8);
+ let distance=0.00001;
+ let segment=ray_segment_precise(anchor,offset,anchor,offset,direction,distance);
+ let light=AreaLight(vec4<f32>(0.0,0.0,0.0,16.0),vec4<f32>(0.0,2.0,0.0,0.0),vec4<f32>(2.0,0.0,0.0,0.0),vec4<f32>(1.0));
+ accumulation[0]=vec4<f32>(length(segment),exp(-5000.0*length(segment)),area_pdf(light,segment),1.0);
+}
+
+@compute @workgroup_size(64)
+fn integer_relative_reference(@builtin(global_invocation_id) invocation: vec3<u32>) {
+ let i=invocation.x;
+ if i>=geometry[0] { return; }
+ let a=geometry[1u+i*4u];
+ let al=geometry[2u+i*4u];
+ let b=geometry[3u+i*4u];
+ let bl=geometry[4u+i*4u];
+ let reference=fp_add_bits(fp_sub_bits(a,b),fp_sub_bits(al,bl));
+ let candidate=anchored_delta_bits(a,al,b,bl);
+ accumulation[i]=vec4<f32>(f32(reference&65535u),f32(reference>>16u),f32(candidate&65535u),f32(candidate>>16u));
+}
diff --git a/crates/gpu/src/path/planar_patches.rs b/crates/gpu/src/path/planar_patches.rs
new file mode 100644
index 0000000000..2bfc4c7122
--- /dev/null
+++ b/crates/gpu/src/path/planar_patches.rs
@@ -0,0 +1,239 @@
+//! Exact connected planar patches of the positions actually uploaded to the GPU.
+//! This is a source-plane identity, not an angular or distance tolerance. A ray
+//! leaving a plane cannot meet that same plane again at a positive distance.
+use super::{Triangle, invalid, medium_root, reserved};
+use robust::{Coord, Coord3D, orient2d, orient3d};
+use solidcraft_render::job::{CancelToken, Result};
+
+#[derive(Eq, PartialEq, Ord, PartialOrd)]
+struct Edge {
+ body: u32,
+ a: [u32; 3],
+ b: [u32; 3],
+ triangle: usize,
+}
+
+pub(super) fn temporary_bytes_per_triangle() -> usize {
+ 3 * std::mem::size_of::<Edge>() + std::mem::size_of::<usize>() + std::mem::size_of::<u32>()
+}
+
+fn uploaded(t: &Triangle) -> [Coord3D<f64>; 3] {
+ t.p.map(|p| Coord3D { x: f64::from(p.x as f32), y: f64::from(p.y as f32), z: f64::from(p.z as f32) })
+}
+
+fn key(p: Coord3D<f64>) -> [u32; 3] {
+ [p.x, p.y, p.z].map(|x| if x == 0.0 { 0 } else { (x as f32).to_bits() })
+}
+
+fn nondegenerate(p: [Coord3D<f64>; 3]) -> bool {
+ for axes in [(0, 1), (0, 2), (1, 2)] {
+ let q = p.map(|v| {
+ let values = [v.x, v.y, v.z];
+ Coord { x: values[axes.0], y: values[axes.1] }
+ });
+ if orient2d(q[0], q[1], q[2]) != 0.0 {
+ return true;
+ }
+ }
+ false
+}
+
+pub(super) fn ids(triangles: &[Triangle], cancel: &CancelToken) -> Result<Vec<u32>> {
+ cancel.check()?;
+ if triangles.len() >= u32::MAX as usize {
+ return Err(invalid("too many triangles for planar patch identities"));
+ }
+ let edge_count = triangles.len().checked_mul(3).ok_or_else(|| invalid("planar edge count overflow"))?;
+ let mut edges = reserved::<Edge>(edge_count)?;
+ let mut parents = reserved::<usize>(triangles.len())?;
+ parents.extend(0..triangles.len());
+ for (index, triangle) in triangles.iter().enumerate() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ let p = uploaded(triangle);
+ // An f64 triangle can collapse at upload precision. It has no valid plane
+ // and must never connect otherwise unrelated planes into one patch.
+ if !nondegenerate(p) {
+ continue;
+ }
+ let keys = p.map(key);
+ for (a, b) in [(0, 1), (1, 2), (2, 0)] {
+ let (a, b) = if keys[a] <= keys[b] { (keys[a], keys[b]) } else { (keys[b], keys[a]) };
+ edges.push(Edge { body: triangle.medium, a, b, triangle: index });
+ }
+ }
+ cancel.check()?;
+ edges.sort_unstable();
+ cancel.check()?;
+ let mut begin = 0;
+ while begin < edges.len() {
+ if begin % 1024 < 3 {
+ cancel.check()?;
+ }
+ let first = edges.get(begin).ok_or_else(|| invalid("missing planar edge"))?;
+ let mut end = begin + 1;
+ while let Some(edge) = edges.get(end) {
+ if (edge.body, edge.a, edge.b) != (first.body, first.a, first.b) {
+ break;
+ }
+ if end % 1024 == 0 {
+ cancel.check()?;
+ }
+ end += 1;
+ }
+ // Only unambiguous two-face adjacency is joined. At nonmanifold edges
+ // leave identities separate rather than inferring a connected surface.
+ if end - begin == 2 {
+ let second = edges.get(begin + 1).ok_or_else(|| invalid("missing planar neighbor"))?;
+ let a = uploaded(triangles.get(first.triangle).ok_or_else(|| invalid("missing planar triangle"))?);
+ let b = uploaded(triangles.get(second.triangle).ok_or_else(|| invalid("missing planar triangle"))?);
+ // Adaptive exact predicates on f32-as-f64 coordinates. Mirrored
+ // winding does not change plane identity; curved facets do.
+ if b.iter().all(|&p| orient3d(a[0], a[1], a[2], p) == 0.0) {
+ let root_a = medium_root(&mut parents, first.triangle)?;
+ let root_b = medium_root(&mut parents, second.triangle)?;
+ let (keep, merge) = (root_a.min(root_b), root_a.max(root_b));
+ *parents.get_mut(merge).ok_or_else(|| invalid("missing planar component"))? = keep;
+ }
+ }
+ begin = end;
+ }
+ let mut result = reserved(triangles.len())?;
+ for index in 0..triangles.len() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ result.push(medium_root(&mut parents, index)? as u32 + 1);
+ }
+ cancel.check()?;
+ Ok(result)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use solidcraft_geom::Vec3;
+ use solidcraft_render::surface::OpaqueSurface;
+
+ fn triangle(p: [[f64; 3]; 3], body: u32) -> Triangle {
+ Triangle {
+ p: p.map(|v| Vec3::new(v[0], v[1], v[2])),
+ indices: [0, 1, 2],
+ surface: OpaqueSurface::new(Vec3::ZERO, 0.0, 0.5, 1.5).unwrap(),
+ transmission: None,
+ medium: body,
+ }
+ }
+
+ #[test]
+ fn exact_connected_planes_join_with_either_winding() {
+ let a = [191.3_f32 as f64, 79.2_f32 as f64, 84.7_f32 as f64];
+ let b = [a[0] + 8.0, a[1], a[2] + 2.0];
+ let c = [a[0] + 8.0, a[1] + 8.0, a[2] + 6.0];
+ let d = [a[0], a[1] + 8.0, a[2] + 4.0];
+ for neighbor in [[a, c, d], [d, c, a]] {
+ let values = ids(&[triangle([a, b, c], 1), triangle(neighbor, 1)], &CancelToken::default()).unwrap();
+ assert_eq!(values[0], values[1]);
+ }
+ }
+
+ #[test]
+ fn disconnected_parallel_bent_and_different_bodies_stay_separate() {
+ let a = [0.0, 0.0, 0.0];
+ let b = [1.0, 0.0, 0.0];
+ let c = [1.0, 1.0, 0.0];
+ let d = [0.0, 1.0, 0.0];
+ let cases = [
+ (triangle([a, c, d], 2), "different bodies"),
+ (triangle([[2.0, 0.0, 0.0], [3.0, 0.0, 0.0], [2.0, 1.0, 0.0]], 1), "disconnected"),
+ (triangle([a, c, [0.0, 1.0, 1e-20]], 1), "arbitrarily shallow bend"),
+ (triangle([[0.0, 0.0, 1e-20], [1.0, 1.0, 1e-20], [0.0, 1.0, 1e-20]], 1), "near parallel"),
+ ];
+ for (neighbor, name) in cases {
+ let values = ids(&[triangle([a, b, c], 1), neighbor], &CancelToken::default()).unwrap();
+ assert_ne!(values[0], values[1], "{name}");
+ }
+ }
+
+ #[test]
+ fn grouping_uses_upload_precision_and_normalizes_signed_zero() {
+ let values = ids(
+ &[
+ triangle([[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0]], 1),
+ triangle([[-0.0, -0.0, 1.0 + 1e-10], [1.0, 1.0, 1.0 + 1e-10], [0.0, 1.0, 1.0]], 1),
+ ],
+ &CancelToken::default(),
+ )
+ .unwrap();
+ assert_eq!(values[0], values[1]);
+ }
+
+ #[test]
+ fn cancelled_and_empty_preparation_are_bounded() {
+ let cancel = CancelToken::default();
+ assert!(ids(&[], &cancel).unwrap().is_empty());
+ cancel.cancel();
+ assert!(ids(&[], &cancel).is_err());
+ assert!(temporary_bytes_per_triangle() >= 3 * std::mem::size_of::<Edge>() + 12);
+ }
+
+ #[test]
+ fn upload_collapse_never_bridges_planes() {
+ let a = [1.0, 0.0, 0.0];
+ let b = [1.0 + 1e-10, 0.0, 0.0];
+ let c = [1.0, 1.0, 0.0];
+ let values =
+ ids(&[triangle([a, c, [2.0, 0.0, 0.0]], 1), triangle([a, b, c], 1), triangle([a, c, [1.0, 0.0, 1.0]], 1)], &CancelToken::default())
+ .unwrap();
+ assert_ne!(values[0], values[1]);
+ assert_ne!(values[1], values[2]);
+ assert_ne!(values[0], values[2]);
+ }
+
+ #[test]
+ fn packing_offset_and_ids_follow_bvh_reordering() {
+ use solidcraft_geom::Mesh;
+ use solidcraft_render::{ProductMesh, ProductScene};
+ use std::sync::Arc;
+ let mut mesh = Mesh::default();
+ for z in [5.0, 0.0, 10.0] {
+ let first = mesh.positions.len() as u32;
+ mesh.positions.extend([Vec3::new(0.0, 0.0, z), Vec3::new(1.0, 0.0, z), Vec3::new(1.0, 1.0, z), Vec3::new(0.0, 1.0, z)]);
+ mesh.normals.extend([Vec3::Z; 4]);
+ mesh.triangles.extend([[first, first + 1, first + 2], [first, first + 2, first + 3]]);
+ mesh.tri_face.extend([0, 0]);
+ }
+ let bounds = mesh.bounds();
+ let scene = ProductScene {
+ bounds,
+ meshes: vec![ProductMesh {
+ name: "three separate planes".into(),
+ mesh: Arc::new(mesh),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: None,
+ transmission: None,
+ faces: vec![],
+ }],
+ };
+ let upload = super::super::flatten(&scene, Vec3::ZERO, &CancelToken::default()).unwrap();
+ let word = |index: usize| u32::from_le_bytes(upload.geometry[index * 4..index * 4 + 4].try_into().unwrap()) as usize;
+ assert_eq!(word(0), 6);
+ assert_eq!(word(3), word(2) + 6 * 16);
+ assert_eq!(upload.geometry.len(), 16 + 6 * 84 + 12 * 32);
+ let mut pairs = Vec::new();
+ for index in 0..6 {
+ let vertex = word(4 + index * 4);
+ let z = f32::from_bits(word(word(1) + vertex * 8 + 2) as u32);
+ pairs.push((z, word(word(3) + index)));
+ }
+ for (a, pa) in &pairs {
+ for (b, pb) in &pairs {
+ assert_eq!(a == b, pa == pb);
+ }
+ }
+ assert!(!upload.nodes.is_empty());
+ assert!(upload.epsilon > 0.0);
+ }
+}
diff --git a/crates/gpu/src/path/scene.rs b/crates/gpu/src/path/scene.rs
new file mode 100644
index 0000000000..c975fa8a83
--- /dev/null
+++ b/crates/gpu/src/path/scene.rs
@@ -0,0 +1,526 @@
+//! Original median-split BVH. World geometry is rebased around the camera target for f32.
+#[path = "planar_patches.rs"]
+mod planar_patches;
+use std::collections::HashMap;
+
+use solidcraft_geom::Vec3;
+use solidcraft_render::{
+ ProductScene,
+ job::{CancelToken, ErrorCode, JobError, Result},
+ surface::{OpaqueSurface, srgb8_to_linear},
+ transmission::Transmission,
+};
+
+pub(super) struct Triangle {
+ pub p: [Vec3; 3],
+ pub indices: [u32; 3],
+ pub surface: OpaqueSurface,
+ pub transmission: Option<Transmission>,
+ pub medium: u32,
+}
+type MediumEdge = (usize, usize, i32);
+pub(super) fn medium_preparation_bytes(scene: &ProductScene) -> u64 {
+ // Validation consumes one body's scratch at a time. Opaque/thin-sheet bodies
+ // allocate none of the weld table: do not charge their triangles for it.
+ let closed = |t: Option<Transmission>| t.is_some_and(|v| v.thin_wall_thickness_mm().is_none());
+ let mut total = 0u64;
+ let mut largest_medium = 0u64;
+ for body in &scene.meshes {
+ let triangles = body.mesh.triangles.len() as u64;
+ total = total.saturating_add(triangles);
+ if closed(body.transmission) || body.faces.iter().any(|face| closed(face.transmission)) {
+ largest_medium = largest_medium.max(triangles);
+ }
+ }
+ // Three representatives per triangle at most. The 320 includes positions,
+ // full eight-slot hash entries, control bytes and worst-case table rounding.
+ let scratch = 3 * (std::mem::size_of::<MediumEdge>() + 320) + std::mem::size_of::<usize>();
+ total.saturating_mul(std::mem::size_of::<Triangle>() as u64).saturating_add(largest_medium.saturating_mul(scratch as u64))
+}
+
+pub(super) fn planar_preparation_bytes_per_triangle() -> usize {
+ let common = std::mem::size_of::<Triangle>() + 2 * std::mem::size_of::<Node>();
+ (common + planar_patches::temporary_bytes_per_triangle()).max(common + 84 + 64 + 4)
+}
+
+impl Triangle {
+ fn centre(&self, axis: usize) -> f64 {
+ self.p.iter().map(|p| [p.x, p.y, p.z].get(axis).copied().unwrap_or(0.0)).sum::<f64>() / 3.0
+ }
+}
+
+#[derive(Default)]
+struct Node {
+ lo: [f32; 3],
+ hi: [f32; 3],
+ first: u32,
+ count: u32,
+}
+
+pub(super) struct Upload {
+ pub geometry: Vec<u8>,
+ pub nodes: Vec<u8>,
+ pub epsilon: f32,
+}
+
+fn invalid(message: &str) -> JobError {
+ JobError::new(ErrorCode::InvalidScene, message)
+}
+pub(super) fn reserved<T>(count: usize) -> Result<Vec<T>> {
+ let mut v = Vec::new();
+ v.try_reserve_exact(count).map_err(|_| JobError::new(ErrorCode::AllocationFailed, "path tracer allocation failed"))?;
+ Ok(v)
+}
+
+pub(super) fn flatten(scene: &ProductScene, origin: Vec3, cancel: &CancelToken) -> Result<Upload> {
+ let count = scene.meshes.iter().map(|m| m.mesh.triangles.len()).sum::<usize>();
+ let mut triangles = reserved(count)?;
+ let vertex_count = scene.meshes.iter().map(|m| m.mesh.positions.len()).sum::<usize>();
+ let mut vertices = reserved(vertex_count * 32)?;
+ let mut vertex_offset = 0u32;
+ let mut media_bounds = reserved::<(Vec3, Vec3, bool)>(8)?;
+ for (body_index, body) in scene.meshes.iter().enumerate() {
+ cancel.check()?;
+ let body_start = triangles.len();
+ let mut faces = reserved(body.faces.len())?;
+ faces.extend(body.faces.iter());
+ faces.sort_unstable_by_key(|f| f.face);
+ if faces.windows(2).any(|f| f[0].face == f[1].face) {
+ return Err(invalid("duplicate face appearance"));
+ }
+ let mesh = &body.mesh;
+ if mesh.normals.len() != mesh.positions.len() || mesh.tri_face.len() != mesh.triangles.len() {
+ return Err(invalid("path tracer requires normals and a face ID for every triangle"));
+ }
+ for (index, (position, normal)) in mesh.positions.iter().zip(&mesh.normals).enumerate() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ let position = *position - origin;
+ if !position.is_finite() || [position.x, position.y, position.z].iter().any(|x| x.abs() > 1e7) {
+ return Err(invalid("path geometry must be finite and within 1e7 mm of the camera target"));
+ }
+ let normal = solidcraft_render::surface::unit_direction(*normal).map_err(|_| invalid("invalid mesh normal"))?;
+ vector(&mut vertices, position, 0.0);
+ vector(&mut vertices, normal, 0.0);
+ }
+ for (index, indices) in mesh.triangles.iter().enumerate() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ let face = mesh.tri_face.get(index).copied().ok_or_else(|| invalid("missing triangle face"))?;
+ let look = faces.binary_search_by_key(&face, |f| f.face).ok().and_then(|i| faces.get(i));
+ let opacity = look.map_or(body.opacity, |f| f.opacity);
+ let transmission = look.map_or(body.transmission, |f| f.transmission);
+ if opacity != 1.0 && transmission.is_none() {
+ return Err(invalid("gpu-path requires explicit transmission for nonopaque preview appearances"));
+ }
+ let color = look.map_or(body.color, |f| f.color);
+ let surface = look
+ .map_or(body.surface, |f| f.surface)
+ .map(Ok)
+ .unwrap_or_else(|| {
+ OpaqueSurface::new(Vec3::new(srgb8_to_linear(color[0]), srgb8_to_linear(color[1]), srgb8_to_linear(color[2])), 0.0, 0.5, 1.5)
+ })
+ .map_err(|e| invalid(&e.to_string()))?;
+ let mut p = [Vec3::ZERO; 3];
+ let mut global_indices = [0u32; 3];
+ for (corner, &vertex) in indices.iter().enumerate() {
+ let position = *mesh.positions.get(vertex as usize).ok_or_else(|| invalid("triangle index out of bounds"))? - origin;
+ if !position.is_finite() || [position.x, position.y, position.z].iter().any(|x| x.abs() > 1e7) {
+ return Err(invalid("path geometry must be finite and within 1e7 mm of the camera target"));
+ }
+ if let Some(v) = p.get_mut(corner) {
+ *v = position;
+ }
+ if let Some(v) = global_indices.get_mut(corner) {
+ *v = vertex.checked_add(vertex_offset).ok_or_else(|| invalid("vertex offset overflow"))?;
+ }
+ }
+ if (p[1] - p[0]).cross(p[2] - p[0]).len() <= 1e-12 {
+ continue;
+ }
+ if transmission.is_some() && surface.clear_coat().is_some() {
+ return Err(invalid("clear coat and transmission cannot share a surface"));
+ }
+ if transmission.is_some() && surface.metallic() != 0.0 {
+ return Err(invalid("transmission requires a nonmetallic surface"));
+ }
+ triangles.push(Triangle { p, indices: global_indices, surface, transmission, medium: body_index as u32 + 1 });
+ }
+ validate_medium(&triangles[body_start..], cancel)?;
+ let body_triangles = &triangles[body_start..];
+ if body_triangles.iter().any(|t| t.transmission.is_some()) {
+ if media_bounds.len() >= 8 {
+ return Err(invalid("at most eight dielectric bodies are supported"));
+ }
+ let closed = body_triangles.iter().any(|t| t.transmission.is_some_and(|v| v.thin_wall_thickness_mm().is_none()));
+ let mut lo = Vec3::new(f64::INFINITY, f64::INFINITY, f64::INFINITY);
+ let mut hi = -lo;
+ for t in body_triangles {
+ for p in t.p {
+ lo = lo.min(p);
+ hi = hi.max(p);
+ }
+ }
+ for (other_lo, other_hi, other_closed) in &media_bounds {
+ if (closed || *other_closed)
+ && !(hi.x < other_lo.x || lo.x > other_hi.x || hi.y < other_lo.y || lo.y > other_hi.y || hi.z < other_lo.z || lo.z > other_hi.z)
+ {
+ return Err(invalid("nested or overlapping dielectric bounds are unsupported; separate the bodies' bounds"));
+ }
+ }
+ media_bounds.push((lo, hi, closed));
+ }
+ vertex_offset = vertex_offset.checked_add(mesh.positions.len() as u32).ok_or_else(|| invalid("vertex offset overflow"))?;
+ }
+ let mut nodes = reserved(triangles.len().saturating_mul(2).max(1))?;
+ nodes.push(Node::default());
+ build(&mut triangles, 0, &mut nodes, 0, 0, cancel)?;
+ let patches = planar_patches::ids(&triangles, cancel)?;
+ let extent = nodes.first().map_or(1.0, |n| n.lo.iter().zip(n.hi).map(|(a, b)| b - a).fold(0.0f32, f32::max));
+ let mut geometry = reserved(16 + triangles.len().max(1) * 84 + vertices.len())?;
+ let mut materials = reserved(triangles.len().max(1) * 64)?;
+ let vertex_word = 4 + triangles.len().max(1) * 4;
+ let material_word = vertex_word + vertices.len() / 4;
+ let patch_word = material_word + triangles.len().max(1) * 16;
+ for word in [triangles.len() as u32, vertex_word as u32, material_word as u32, patch_word as u32] {
+ geometry.extend_from_slice(&word.to_le_bytes());
+ }
+ for (material, t) in triangles.into_iter().enumerate() {
+ if material % 1024 == 0 {
+ cancel.check()?;
+ }
+ for index in t.indices {
+ geometry.extend_from_slice(&index.to_le_bytes());
+ }
+ geometry.extend_from_slice(&(material as u32).to_le_bytes());
+ vector(&mut materials, t.surface.base_color(), if t.transmission.is_some() { 1.0 } else { 0.0 });
+ vector(
+ &mut materials,
+ Vec3::new(t.surface.metallic(), t.surface.roughness(), t.surface.dielectric_ior()),
+ t.transmission.and_then(|t| t.thin_wall_thickness_mm()).unwrap_or(-1.0) as f32,
+ );
+ vector(&mut materials, t.transmission.map_or(Vec3::ZERO, |t| t.extinction()), t.medium as f32);
+ let coat = t.surface.clear_coat().map_or(Vec3::new(0.0, 0.5, 1.5), |c| Vec3::new(c.weight(), c.roughness(), c.ior()));
+ vector(&mut materials, coat, if t.transmission.is_some_and(|t| t.shadow_transmission()) { 1.0 } else { 0.0 });
+ }
+ if geometry.len() == 16 {
+ geometry.resize(32, 0);
+ materials.resize(64, 0);
+ }
+ geometry.extend_from_slice(&vertices);
+ drop(vertices);
+ geometry.extend_from_slice(&materials);
+ drop(materials);
+ if patches.is_empty() {
+ geometry.extend_from_slice(&0u32.to_le_bytes());
+ } else {
+ for (index, patch) in patches.into_iter().enumerate() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ geometry.extend_from_slice(&patch.to_le_bytes());
+ }
+ }
+ let mut node_bytes = reserved(nodes.len() * 32)?;
+ for node in nodes {
+ for x in node.lo {
+ node_bytes.extend_from_slice(&x.to_le_bytes());
+ }
+ node_bytes.extend_from_slice(&node.first.to_le_bytes());
+ for x in node.hi {
+ node_bytes.extend_from_slice(&x.to_le_bytes());
+ }
+ node_bytes.extend_from_slice(&node.count.to_le_bytes());
+ }
+ Ok(Upload { geometry, nodes: node_bytes, epsilon: (extent * 1e-7).max(1e-5) })
+}
+
+const MEDIUM_WELD_MM: f64 = 1e-6;
+
+#[derive(Default)]
+struct MediumBucket {
+ representatives: [usize; 8],
+ len: usize,
+}
+
+/// Only topology uses these representatives; every uploaded vertex stays unchanged.
+/// Checking neighboring cells avoids rounding-boundary cracks in curved CAD seams.
+struct MediumWeld {
+ cells: HashMap<[i64; 3], MediumBucket>,
+ positions: Vec<Vec3>,
+ limit: usize,
+}
+
+impl MediumWeld {
+ fn new(limit: usize) -> Result<Self> {
+ let mut cells = HashMap::new();
+ cells.try_reserve(limit).map_err(|_| JobError::new(ErrorCode::AllocationFailed, "glass topology allocation failed"))?;
+ Ok(Self { cells, positions: reserved(limit)?, limit })
+ }
+
+ fn key(&mut self, point: Vec3) -> Result<usize> {
+ let xyz = [point.x, point.y, point.z];
+ // Leave room for neighboring cells and refuse saturated integer casts.
+ if !xyz.into_iter().all(|v| v.is_finite() && v.abs() <= 1e9) {
+ return Err(invalid("glass topology position exceeds finite coordinate bounds"));
+ }
+ let cell = xyz.map(|v| (v / MEDIUM_WELD_MM).floor() as i64);
+ let mut found: Option<usize> = None;
+ for dx in -1..=1 {
+ for dy in -1..=1 {
+ for dz in -1..=1 {
+ let neighbor = [cell[0] + dx, cell[1] + dy, cell[2] + dz];
+ let Some(bucket) = self.cells.get(&neighbor) else { continue };
+ for &index in bucket.representatives.iter().take(bucket.len) {
+ let other = self.positions.get(index).ok_or_else(|| invalid("missing glass topology representative"))?;
+ let delta = point - *other;
+ if delta.dot(delta) <= MEDIUM_WELD_MM * MEDIUM_WELD_MM && found.is_none_or(|old| index < old) {
+ found = Some(index);
+ }
+ }
+ }
+ }
+ }
+ if let Some(index) = found {
+ return Ok(index);
+ }
+ if self.positions.len() >= self.limit {
+ return Err(invalid("glass topology representative budget exceeded"));
+ }
+ let index = self.positions.len();
+ let bucket = self.cells.entry(cell).or_default();
+ // Split a unit cell into eight half-size cubes: points sharing one are
+ // at most sqrt(3)/2 tolerances apart, so a cell has at most eight reps.
+ let slot = bucket.representatives.get_mut(bucket.len).ok_or_else(|| invalid("glass topology cell budget exceeded"))?;
+ *slot = index;
+ bucket.len += 1;
+ self.positions.push(point);
+ Ok(index)
+ }
+}
+
+// Volume transmission needs a consistently oriented closed two-manifold. CAD
+// tessellation duplicates face-seam vertices; compare their actual Euclidean
+// separation at the existing one-nanometre-in-mm tolerance, without modifying
+// uploaded geometry or merging chains beyond a representative's tolerance.
+fn validate_medium(triangles: &[Triangle], cancel: &CancelToken) -> Result<()> {
+ let Some(first) = triangles.iter().find(|t| t.transmission.is_some_and(|v| v.thin_wall_thickness_mm().is_none())) else {
+ return Ok(());
+ };
+ if triangles.iter().any(|t| t.transmission != first.transmission || t.surface.dielectric_ior() != first.surface.dielectric_ior()) {
+ return Err(invalid("a closed glass body must use one homogeneous transmission medium; use separate bodies or thin walls"));
+ }
+ let vertex_count = triangles.len().checked_mul(3).ok_or_else(|| invalid("glass topology vertex count overflow"))?;
+ let mut edges = reserved::<MediumEdge>(vertex_count)?;
+ let mut weld = MediumWeld::new(vertex_count)?;
+ let mut parents = reserved::<usize>(triangles.len())?;
+ parents.extend(0..triangles.len());
+ let origin = first.p[0];
+ let mut six_volume = 0.0;
+ for (index, triangle) in triangles.iter().enumerate() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ let keys = [weld.key(triangle.p[0])?, weld.key(triangle.p[1])?, weld.key(triangle.p[2])?];
+ for (a, b) in [(0, 1), (1, 2), (2, 0)] {
+ if keys[a] == keys[b] {
+ return Err(invalid("glass triangle collapses at the 1e-6 mm topology tolerance"));
+ }
+ let ordinal = i32::try_from(index + 1).map_err(|_| invalid("too many glass triangles"))?;
+ edges.push(if keys[a] < keys[b] { (keys[a], keys[b], ordinal) } else { (keys[b], keys[a], -ordinal) });
+ }
+ six_volume += (triangle.p[0] - origin).dot((triangle.p[1] - origin).cross(triangle.p[2] - origin));
+ }
+ edges.sort_unstable();
+ for edge in edges.chunks(2) {
+ let [a, b] = edge else {
+ return Err(invalid("volume glass requires a closed mesh; use thin_wall_thickness_mm for sheets"));
+ };
+ if a.0 != b.0 || a.1 != b.1 || a.2.signum() + b.2.signum() != 0 {
+ return Err(invalid("volume glass requires a closed, consistently outward-oriented mesh"));
+ }
+ let first = medium_root(&mut parents, a.2.unsigned_abs() as usize - 1)?;
+ let second = medium_root(&mut parents, b.2.unsigned_abs() as usize - 1)?;
+ *parents.get_mut(first).ok_or_else(|| invalid("invalid glass component"))? = second;
+ }
+ // Groups with four or more coincident directed edges cannot be a two-manifold.
+ if edges.windows(3).any(|e| e[0].0 == e[2].0 && e[0].1 == e[2].1) {
+ return Err(invalid("nonmanifold glass edge"));
+ }
+ let component = medium_root(&mut parents, 0)?;
+ for index in 0..parents.len() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ if medium_root(&mut parents, index)? != component {
+ return Err(invalid("closed dielectric body must contain exactly one connected shell"));
+ }
+ }
+ if six_volume <= 0.0 || !six_volume.is_finite() {
+ return Err(invalid("glass mesh must enclose positive outward-oriented volume"));
+ }
+ cancel.check()
+}
+
+fn medium_root(parents: &mut [usize], mut index: usize) -> Result<usize> {
+ loop {
+ let parent = *parents.get(index).ok_or_else(|| invalid("invalid glass component index"))?;
+ if parent == index {
+ return Ok(index);
+ }
+ let grandparent = *parents.get(parent).ok_or_else(|| invalid("invalid glass component parent"))?;
+ *parents.get_mut(index).ok_or_else(|| invalid("invalid glass component index"))? = grandparent;
+ index = grandparent;
+ }
+}
+
+// The shader's traversal stack holds 32 nodes and needs at most depth + 1.
+const MAX_BVH_DEPTH: usize = 30;
+const SAH_BINS: usize = 16;
+type Bounds = ([f32; 3], [f32; 3]);
+const EMPTY_BOUNDS: Bounds = ([f32::INFINITY; 3], [f32::NEG_INFINITY; 3]);
+
+fn grow(bounds: &mut Bounds, t: &Triangle) {
+ for p in t.p {
+ for (axis, value) in [p.x as f32, p.y as f32, p.z as f32].into_iter().enumerate() {
+ bounds.0[axis] = bounds.0[axis].min(value);
+ bounds.1[axis] = bounds.1[axis].max(value);
+ }
+ }
+}
+
+fn merge(bounds: &mut Bounds, other: &Bounds) {
+ for axis in 0..3 {
+ bounds.0[axis] = bounds.0[axis].min(other.0[axis]);
+ bounds.1[axis] = bounds.1[axis].max(other.1[axis]);
+ }
+}
+
+fn half_area(bounds: &Bounds) -> f64 {
+ let [x, y, z] = [0, 1, 2].map(|axis| f64::from((bounds.1[axis] - bounds.0[axis]).max(0.0)));
+ x * y + y * z + z * x
+}
+
+// Depth a median split adds below a node of `count` triangles.
+fn median_levels(mut count: usize) -> usize {
+ let mut levels = 0;
+ while count > 4 {
+ count = count.div_ceil(2);
+ levels += 1;
+ }
+ levels
+}
+
+// Binned surface-area heuristic over triangle centres. A split is accepted only
+// if a median split of its larger side still fits MAX_BVH_DEPTH, so the median
+// fallback always remains available. Returns the left count after partitioning.
+fn sah_split(triangles: &mut [Triangle], depth: usize) -> Option<usize> {
+ let mut centre_lo = [f64::INFINITY; 3];
+ let mut centre_hi = [f64::NEG_INFINITY; 3];
+ for t in triangles.iter() {
+ for axis in 0..3 {
+ centre_lo[axis] = centre_lo[axis].min(t.centre(axis));
+ centre_hi[axis] = centre_hi[axis].max(t.centre(axis));
+ }
+ }
+ let bin = |t: &Triangle, axis: usize| {
+ let scaled = (t.centre(axis) - centre_lo[axis]) / (centre_hi[axis] - centre_lo[axis]) * SAH_BINS as f64;
+ (scaled as usize).min(SAH_BINS - 1)
+ };
+ let mut best: Option<(f64, usize, usize)> = None;
+ for axis in 0..3 {
+ if centre_hi[axis] - centre_lo[axis] <= 0.0 {
+ continue;
+ }
+ let mut counts = [0usize; SAH_BINS];
+ let mut boxes = [EMPTY_BOUNDS; SAH_BINS];
+ for t in triangles.iter() {
+ let b = bin(t, axis);
+ counts[b] += 1;
+ grow(&mut boxes[b], t);
+ }
+ let mut right_area = [0.0; SAH_BINS];
+ let mut right_count = [0usize; SAH_BINS];
+ let mut accumulated = EMPTY_BOUNDS;
+ let mut count = 0;
+ for b in (1..SAH_BINS).rev() {
+ merge(&mut accumulated, &boxes[b]);
+ count += counts[b];
+ right_area[b] = half_area(&accumulated);
+ right_count[b] = count;
+ }
+ accumulated = EMPTY_BOUNDS;
+ count = 0;
+ for b in 1..SAH_BINS {
+ merge(&mut accumulated, &boxes[b - 1]);
+ count += counts[b - 1];
+ let right = right_count[b];
+ if count == 0 || right == 0 || depth + 1 + median_levels(count.max(right)) > MAX_BVH_DEPTH {
+ continue;
+ }
+ let cost = half_area(&accumulated) * count as f64 + right_area[b] * right as f64;
+ if best.is_none_or(|(lowest, _, _)| cost < lowest) {
+ best = Some((cost, axis, b));
+ }
+ }
+ }
+ let (_, axis, split) = best?;
+ let mut middle = 0;
+ for i in 0..triangles.len() {
+ if bin(&triangles[i], axis) < split {
+ triangles.swap(i, middle);
+ middle += 1;
+ }
+ }
+ Some(middle)
+}
+
+fn build(triangles: &mut [Triangle], offset: usize, nodes: &mut Vec<Node>, index: usize, depth: usize, cancel: &CancelToken) -> Result<()> {
+ cancel.check()?;
+ let mut bounds = EMPTY_BOUNDS;
+ for t in triangles.iter() {
+ grow(&mut bounds, t);
+ }
+ let (lo, hi) = bounds;
+ let mut node = Node { lo, hi, first: offset as u32, count: triangles.len() as u32 };
+ if triangles.is_empty() {
+ node = Node { first: u32::MAX, ..Default::default() };
+ }
+ if triangles.len() > 4 {
+ let middle = match sah_split(triangles, depth) {
+ Some(middle) => middle,
+ None => {
+ let axis = (0..3).max_by(|&a, &b| (hi[a] - lo[a]).total_cmp(&(hi[b] - lo[b]))).unwrap_or(0);
+ let middle = triangles.len() / 2;
+ triangles.select_nth_unstable_by(middle, |a, b| a.centre(axis).total_cmp(&b.centre(axis)));
+ middle
+ }
+ };
+ let first = nodes.len();
+ nodes.push(Node::default());
+ nodes.push(Node::default());
+ node.first = first as u32;
+ node.count = 0;
+ let (left, right) = triangles.split_at_mut(middle);
+ build(left, offset, nodes, first, depth + 1, cancel)?;
+ build(right, offset + middle, nodes, first + 1, depth + 1, cancel)?;
+ }
+ *nodes.get_mut(index).ok_or_else(|| invalid("missing BVH node"))? = node;
+ Ok(())
+}
+
+pub(super) fn vector(bytes: &mut Vec<u8>, v: Vec3, w: f32) {
+ for value in [v.x as f32, v.y as f32, v.z as f32, w] {
+ bytes.extend_from_slice(&value.to_le_bytes());
+ }
+}
+
+#[cfg(test)]
+#[path = "scene_weld_tests.rs"]
+mod weld_tests;
+
+#[cfg(test)]
+#[path = "scene_bvh_tests.rs"]
+mod bvh_tests;
diff --git a/crates/gpu/src/path/scene_bvh_tests.rs b/crates/gpu/src/path/scene_bvh_tests.rs
new file mode 100644
index 0000000000..50151a72ac
--- /dev/null
+++ b/crates/gpu/src/path/scene_bvh_tests.rs
@@ -0,0 +1,62 @@
+use super::{MAX_BVH_DEPTH, Node, Triangle, build};
+use solidcraft_geom::Vec3;
+use solidcraft_render::{job::CancelToken, surface::OpaqueSurface};
+
+// Triangle centres spread over 60 decades: a sixteen-bin SAH split on the
+// centre range peels only the few largest triangles off at each level, so an
+// unbounded build is far deeper than the shader's traversal stack allows.
+fn decades(count: usize) -> Vec<Triangle> {
+ let surface = OpaqueSurface::new(Vec3::new(0.5, 0.5, 0.5), 0.0, 0.5, 1.5).unwrap();
+ (0..count)
+ .map(|i| {
+ let x = 10f64.powf(-30.0 + 60.0 * i as f64 / count as f64);
+ Triangle {
+ p: [Vec3::new(x, 0., 0.), Vec3::new(x * 1.5, 0., 0.), Vec3::new(x, x, x)],
+ indices: [0, 1, 2].map(|c| (3 * i + c) as u32),
+ surface,
+ transmission: None,
+ medium: 0,
+ }
+ })
+ .collect()
+}
+
+#[test]
+fn sah_tree_respects_the_shader_stack_depth_and_covers_every_triangle_once() {
+ let count = 2048;
+ let mut triangles = decades(count);
+ let mut nodes = vec![Node::default()];
+ build(&mut triangles, 0, &mut nodes, 0, 0, &CancelToken::default()).unwrap();
+ assert!(nodes.len() < 2 * count, "{} nodes", nodes.len());
+ let mut covered = vec![0; count];
+ let mut deepest = 0;
+ let mut pending = vec![(0usize, 0usize)];
+ while let Some((index, depth)) = pending.pop() {
+ let node = &nodes[index];
+ let (first, size) = (node.first as usize, node.count as usize);
+ deepest = deepest.max(depth);
+ if size == 0 {
+ for child in [first, first + 1] {
+ let inner = &nodes[child];
+ for axis in 0..3 {
+ assert!(node.lo[axis] <= inner.lo[axis] && inner.hi[axis] <= node.hi[axis], "child box escapes its parent");
+ }
+ pending.push((child, depth + 1));
+ }
+ continue;
+ }
+ assert!(size <= 4);
+ for (slot, triangle) in covered[first..first + size].iter_mut().zip(&triangles[first..first + size]) {
+ *slot += 1;
+ for p in triangle.p {
+ for (axis, value) in [p.x as f32, p.y as f32, p.z as f32].into_iter().enumerate() {
+ assert!(node.lo[axis] <= value && value <= node.hi[axis], "triangle escapes its leaf");
+ }
+ }
+ }
+ }
+ assert!(covered.iter().all(|&c| c == 1), "{covered:?}");
+ assert!(deepest <= MAX_BVH_DEPTH, "depth {deepest}");
+ // Covering 2048 triangles in leaves of four needs at least nine levels.
+ assert!(deepest >= 9, "depth {deepest}");
+}
diff --git a/crates/gpu/src/path/scene_weld_tests.rs b/crates/gpu/src/path/scene_weld_tests.rs
new file mode 100644
index 0000000000..0b9b2bbaa9
--- /dev/null
+++ b/crates/gpu/src/path/scene_weld_tests.rs
@@ -0,0 +1,87 @@
+use std::sync::Arc;
+
+use super::{MediumWeld, Triangle, flatten, medium_preparation_bytes};
+use solidcraft_geom::{Mesh, Vec3};
+use solidcraft_render::{ProductMesh, ProductScene, job::CancelToken, surface::OpaqueSurface, transmission::Transmission};
+
+fn seam_tetra(offset: Vec3) -> ProductScene {
+ // Original outward tetrahedron. Only one face has a duplicated CAD seam
+ // endpoint; its measured displacement comes from our revolved tumbler.
+ let origin = Vec3::new(-81.00000000023796, -51.6269330409162, 592.0);
+ let mesh = Mesh {
+ positions: vec![origin, origin + Vec3::X, origin + Vec3::Y, origin + Vec3::Z, origin + offset],
+ normals: vec![Vec3::Z; 5],
+ triangles: vec![[4, 2, 1], [0, 1, 3], [0, 3, 2], [1, 2, 3]],
+ tri_face: vec![0; 4],
+ ..Default::default()
+ };
+ let bounds = mesh.bounds();
+ ProductScene {
+ meshes: vec![ProductMesh {
+ name: "original seam tetrahedron".into(),
+ mesh: Arc::new(mesh),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap()),
+ transmission: Some(Transmission::new(Vec3::ZERO, None).unwrap()),
+ faces: Vec::new(),
+ }],
+ bounds,
+ }
+}
+
+#[test]
+fn closed_cad_seam_across_rounding_cells_keeps_one_nanometre_tolerance() {
+ let delta = Vec3::new(-0.00000054155099, 0.00000031266462, 0.0);
+ assert!(delta.len() < 1e-6);
+ let scene = seam_tetra(delta);
+ assert!(flatten(&scene, Vec3::ZERO, &CancelToken::default()).is_ok());
+ let open = seam_tetra(Vec3::new(1.01e-6, 0.0, 0.0));
+ assert!(flatten(&open, Vec3::ZERO, &CancelToken::default()).is_err());
+}
+
+#[test]
+fn spatial_weld_is_deterministic_without_transitive_or_diagonal_expansion() {
+ for _ in 0..8 {
+ let mut weld = MediumWeld::new(8).unwrap();
+ let a = weld.key(Vec3::ZERO).unwrap();
+ assert_eq!(a, weld.key(Vec3::new(0.75e-6, 0.0, 0.0)).unwrap());
+ assert_ne!(a, weld.key(Vec3::new(1.5e-6, 0.0, 0.0)).unwrap());
+ assert_ne!(a, weld.key(Vec3::new(0.9e-6, 0.9e-6, 0.9e-6)).unwrap());
+ assert!(weld.key(Vec3::new(f64::NAN, 0.0, 0.0)).is_err());
+ }
+}
+
+#[test]
+fn spatial_weld_preserves_winding_and_connected_component_checks() {
+ let mut inward = seam_tetra(Vec3::ZERO);
+ for tri in &mut Arc::make_mut(&mut inward.meshes[0].mesh).triangles {
+ tri.swap(1, 2);
+ }
+ assert!(flatten(&inward, Vec3::ZERO, &CancelToken::default()).is_err());
+
+ let mut disconnected = seam_tetra(Vec3::ZERO);
+ let mesh = Arc::make_mut(&mut disconnected.meshes[0].mesh);
+ let second = mesh.clone();
+ mesh.positions.extend(second.positions.iter().map(|p| *p + Vec3::new(4.0, 0.0, 0.0)));
+ mesh.normals.extend(&second.normals);
+ mesh.triangles.extend(second.triangles.iter().map(|t| t.map(|i| i + 5)));
+ mesh.tri_face.extend(&second.tri_face);
+ let error = flatten(&disconnected, Vec3::ZERO, &CancelToken::default()).err().unwrap();
+ assert!(error.to_string().contains("one connected shell"), "{error}");
+}
+
+#[test]
+fn weld_scratch_only_counts_the_largest_closed_medium() {
+ let glass = seam_tetra(Vec3::ZERO);
+ let triangle_bytes = 4 * std::mem::size_of::<Triangle>() as u64;
+ let mut opaque = glass.clone();
+ opaque.meshes[0].transmission = None;
+ assert_eq!(medium_preparation_bytes(&opaque), triangle_bytes);
+ assert!(medium_preparation_bytes(&opaque) <= 4 * 400);
+ opaque.meshes[0].transmission = Some(Transmission::new(Vec3::ZERO, Some(1.0)).unwrap());
+ assert_eq!(medium_preparation_bytes(&opaque), triangle_bytes);
+ let mut two = glass.clone();
+ two.meshes.push(glass.meshes[0].clone());
+ assert_eq!(medium_preparation_bytes(&two), medium_preparation_bytes(&glass) + triangle_bytes);
+}
diff --git a/crates/gpu/src/path/shadows.wgsl b/crates/gpu/src/path/shadows.wgsl
new file mode 100644
index 0000000000..2d09ced362
--- /dev/null
+++ b/crates/gpu/src/path/shadows.wgsl
@@ -0,0 +1,105 @@
+// Bounded straight connection, not refracted caustic transport. Host preparation
+// certifies disjoint closed media; malformed crossing order is still blocked.
+struct ShadowResult { transmittance: vec3<f32>, branch_pdf: f32, crossings: u32, solid: bool };
+fn blocked_shadow() -> ShadowResult {
+ return ShadowResult(vec3<f32>(0.0),0.0,0u,false);
+}
+fn shadow_transmittance(origin: vec3<f32>, direction: vec3<f32>, limit: f32) -> ShadowResult {
+ var result = ShadowResult(vec3<f32>(1.0),1.0,0u,false);
+ var o = origin;
+ var o_low = vec3<f32>(0.0);
+ var ray_excluded = 0xffffffffu;
+ var ray_minimum = u.lighting.x;
+ var medium_id = 0.0;
+ var medium_ior = 1.0;
+ var sigma = vec3<f32>(0.0);
+ var entry = origin;
+ var entry_low = vec3<f32>(0.0);
+ // Up to 64 interfaces. If traversal cannot establish visibility, block it.
+ for (var step=0u; step<=64u; step+=1u) {
+ let traversed = dot(precise_point_delta(o,o_low,origin,vec3<f32>(0.0)),direction);
+ let remaining = limit-traversed;
+ // Outside media nothing beyond the endpoint matters. Inside, the
+ // endpoint branch below must still see the farther boundary.
+ let hit = trace_precise_within(o,o_low,direction,false,ray_excluded,ray_minimum,medium_id!=0.0,select(FAR,remaining,medium_id==0.0),remaining);
+ if hit.triangle == 0xffffffffu {
+ if medium_id!=0.0 { return blocked_shadow(); }
+ return result;
+ }
+ if hit.distance>=remaining {
+ // A finite emitter may be inside a certified medium. Attenuate only
+ // to that emitter, never to the body's farther exit surface.
+ if medium_id!=0.0 { result.transmittance*=exp(-sigma*length(ray_segment_precise(o,o_low,entry,entry_low,direction,remaining)))/(medium_ior*medium_ior); }
+ return result;
+ }
+ if step==64u { return blocked_shadow(); }
+ let t = triangle(hit.triangle);
+ if t.base.w<=0.0 || t.coat.w<=0.0 { return blocked_shadow(); }
+ var position=surface_point(t,hit.bary);
+ var position_low=vec3<f32>(0.0);
+ if t.parameters.w<0.0 {
+ let point=surface_point_precise(t,hit.bary);
+ position=point.hi; position_low=point.lo;
+ }
+ let outward=unit(cross(t.p1.xyz-t.p0.xyz,t.p2.xyz-t.p0.xyz));
+ let entering=dot(outward,direction)<0.0;
+ let geometric=select(-outward,outward,entering);
+ var n=unit(t.n0.xyz*hit.bary.x+t.n1.xyz*hit.bary.y+t.n2.xyz*hit.bary.z);
+ if dot(n,geometric)<0.0 { n=-n; }
+ if dot(n,-direction)<=0.0 { n=geometric; }
+ if t.parameters.w>=0.0 {
+ if medium_id!=0.0 { return blocked_shadow(); }
+ // Match the primary path's shading-normal fallback before the sheet sum.
+ var f=dielectric(clamp(dot(n,-direction),0.0,1.0),1.0,t.parameters.z);
+ let refracted=refract(direction,n,1.0/t.parameters.z);
+ if (f.z>=0.0 && dot(refracted,geometric)>=0.0) || dot(reflect(direction,n),geometric)<=0.0 {
+ n=geometric;
+ f=dielectric(clamp(dot(n,-direction),0.0,1.0),1.0,t.parameters.z);
+ }
+ let weights=sheet(t,f);
+ let r=dot(weights.reflection,vec3<f32>(1.0/3.0));
+ let tr=dot(weights.transmission,vec3<f32>(1.0/3.0));
+ if r+tr<=0.0 || tr<=0.0 { return blocked_shadow(); }
+ result.transmittance*=weights.transmission;
+ result.branch_pdf*=tr/(r+tr);
+ } else {
+ result.solid=true;
+ // Reciprocal external-angle Fresnel at each surface. Applying an
+ // inside critical angle to this unrefracted connection would invent TIR.
+ let f=dielectric(clamp(abs(dot(outward,direction)),0.0,1.0),1.0,t.parameters.z);
+ result.transmittance*=1.0-(f.x+f.y)*0.5;
+ if entering {
+ if medium_id!=0.0 { return blocked_shadow(); }
+ medium_id=t.optics.w; medium_ior=t.parameters.z; entry=position; entry_low=position_low; sigma=t.optics.xyz;
+ } else {
+ // The first crossing from the shading point exits a closed body:
+ // the point touches or lies within it (see the path loop).
+ if medium_id==0.0 && step==0u {
+ medium_id=t.optics.w; medium_ior=t.parameters.z; sigma=t.optics.xyz; entry=origin; entry_low=vec3<f32>(0.0);
+ }
+ if medium_id==0.0 || medium_id!=t.optics.w { return blocked_shadow(); }
+ result.transmittance*=exp(-sigma*length(precise_point_delta(position,position_low,entry,entry_low)));
+ medium_id=0.0;
+ }
+ }
+ result.crossings+=1u;
+ if max(max(result.transmittance.x,result.transmittance.y),result.transmittance.z)<=0.0 { return blocked_shadow(); }
+ // Stay on the same line so the finite emitter endpoint remains meaningful.
+ // Absorption uses unshifted entry/exit endpoints, not this numerical offset.
+ o=position+direction*(u.lighting.x*2.0); o_low=vec3<f32>(0.0);
+ ray_excluded=0xffffffffu; ray_minimum=u.lighting.x;
+ if t.parameters.w<0.0 {
+ // Preserve arbitrarily short real corner segments, using the same
+ // producing-plane exclusion as closed primary-path continuation.
+ o=position; o_low=position_low; ray_excluded=hit.triangle; ray_minimum=0.0;
+ }
+ }
+ return blocked_shadow();
+}
+
+@compute @workgroup_size(1)
+fn shadow_reference() {
+ let shadow=shadow_transmittance(u.eye.xyz,u.back.xyz,u.back.w);
+ accumulation[0]=vec4<f32>(shadow.transmittance,1.0);
+ accumulation[1]=vec4<f32>(shadow.branch_pdf,f32(shadow.crossings),select(0.0,1.0,shadow.solid),1.0);
+}
diff --git a/crates/gpu/src/path/tests.rs b/crates/gpu/src/path/tests.rs
new file mode 100644
index 0000000000..27e9b6d5d2
--- /dev/null
+++ b/crates/gpu/src/path/tests.rs
@@ -0,0 +1,2832 @@
+use super::*;
+use solidcraft_geom::{Aabb3, Mesh};
+use solidcraft_render::{Camera, ProductMesh, StandardView, surface::OpaqueSurface};
+
+fn executor() -> Option<Executor> {
+ let (adapter, device, queue) = match open_headless() {
+ Ok(device) => device,
+ Err(e) => {
+ // The path tracer runs on Vulkan only: where the backends in use leave Vulkan out
+ // (macOS, or `WGPU_BACKEND=dx12`), it is unavailable by design, not missing.
+ let vulkan = crate::select::native_backends().contains(wgpu::Backends::VULKAN);
+ assert!(!vulkan || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required GPU unavailable: {e}");
+ eprintln!("gpu-path device test skipped: {e}");
+ return None;
+ }
+ };
+ eprintln!("gpu-path tests on {} ({:?}, {:?})", adapter.get_info().name, adapter.get_info().device_type, adapter.get_info().backend);
+ Some(Executor::new(device, queue).unwrap())
+}
+fn request(size: u32) -> ImageRequest {
+ let mut camera = Camera { distance: 4.0, ..Default::default() };
+ camera.set_view(StandardView::Top);
+ ImageRequest { textures: None, environment: None, camera, width: size, height: size, background: [10, 20, 30], transparent_background: false }
+}
+fn sphere(surface: OpaqueSurface) -> ProductScene {
+ sphere_grid(surface, 48, 96)
+}
+fn sphere_grid(surface: OpaqueSurface, rows: u32, columns: u32) -> ProductScene {
+ sphere_section(surface, rows, columns, rows)
+}
+fn sphere_section(surface: OpaqueSurface, rows: u32, columns: u32, rings: u32) -> ProductScene {
+ // Original unit sphere, deliberately triangulated here rather than imported test data.
+ let mut mesh = Mesh::default();
+ for i in 0..=rings {
+ let theta = f64::from(i) * std::f64::consts::PI / f64::from(rows);
+ for j in 0..=columns {
+ let phi = f64::from(j) * std::f64::consts::TAU / f64::from(columns);
+ let n = Vec3::new(theta.sin() * phi.cos(), theta.sin() * phi.sin(), theta.cos());
+ mesh.positions.push(n);
+ mesh.normals.push(n);
+ }
+ }
+ for i in 0..rings {
+ for j in 0..columns {
+ let a = i * (columns + 1) + j;
+ let b = a + columns + 1;
+ mesh.triangles.extend([[a, b, a + 1], [a + 1, b, b + 1]]);
+ mesh.tri_face.extend([0, 0]);
+ }
+ }
+ let bounds = mesh.bounds();
+ ProductScene {
+ meshes: vec![ProductMesh {
+ name: "original sphere".into(),
+ mesh: Arc::new(mesh),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(surface),
+ transmission: None,
+ faces: Vec::new(),
+ }],
+ bounds,
+ }
+}
+fn white() -> OpaqueSurface {
+ OpaqueSurface::new(Vec3::new(1.0, 1.0, 1.0), 0.0, 1.0, 1.0).unwrap()
+}
+
+fn clear_glass() -> solidcraft_render::transmission::Transmission {
+ solidcraft_render::transmission::Transmission::new(Vec3::ZERO, None).unwrap()
+}
+
+#[test]
+fn volume_glass_requires_closed_outward_homogeneous_geometry() {
+ let mut glass = sphere(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap());
+ glass.meshes[0].transmission = Some(clear_glass());
+ assert!(scene::flatten(&glass, Vec3::ZERO, &CancelToken::default()).is_ok());
+ let mut open = glass.clone();
+ let mesh = Arc::make_mut(&mut open.meshes[0].mesh);
+ mesh.triangles.remove(300);
+ mesh.tri_face.remove(300);
+ assert!(scene::flatten(&open, Vec3::ZERO, &CancelToken::default()).is_err());
+ let mut inward = glass;
+ for t in &mut Arc::make_mut(&mut inward.meshes[0].mesh).triangles {
+ t.swap(1, 2);
+ }
+ assert!(scene::flatten(&inward, Vec3::ZERO, &CancelToken::default()).is_err());
+ open.meshes[0].transmission = Some(solidcraft_render::transmission::Transmission::new(Vec3::ZERO, Some(0.1)).unwrap());
+ assert!(scene::flatten(&open, Vec3::ZERO, &CancelToken::default()).is_ok());
+}
+
+#[test]
+fn nested_and_overlapping_dielectric_bounds_are_rejected_before_upload() {
+ let mut outer = sphere(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap());
+ outer.meshes[0].transmission = Some(clear_glass());
+ for shift in [0.0, 0.5] {
+ let mut inner = outer.meshes[0].clone();
+ for p in &mut Arc::make_mut(&mut inner.mesh).positions {
+ *p = *p * 0.5 + Vec3::new(shift, 0.0, 0.0);
+ }
+ let mut scene = outer.clone();
+ scene.meshes.push(inner);
+ assert!(scene::flatten(&scene, Vec3::ZERO, &CancelToken::default()).is_err());
+ }
+}
+
+#[test]
+fn multiple_closed_shells_in_one_dielectric_body_are_rejected() {
+ let mut scene = sphere(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap());
+ scene.meshes[0].transmission = Some(clear_glass());
+ let second = scene.meshes[0].mesh.clone();
+ let mesh = Arc::make_mut(&mut scene.meshes[0].mesh);
+ let offset = mesh.positions.len() as u32;
+ mesh.positions.extend(second.positions.iter().map(|p| *p + Vec3::new(4.0, 0.0, 0.0)));
+ mesh.normals.extend(&second.normals);
+ mesh.triangles.extend(second.triangles.iter().map(|t| t.map(|i| i + offset)));
+ mesh.tri_face.extend(&second.tri_face);
+ let error = scene::flatten(&scene, Vec3::ZERO, &CancelToken::default()).err().unwrap();
+ assert!(error.to_string().contains("one connected shell"), "{error}");
+}
+
+#[test]
+fn gpu_exact_dielectric_matches_f64_fresnel() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("dielectric_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let mut task = Task::new(context.clone(), sphere(white()), request(1), JobOptions::default(), CancelToken::default()).unwrap();
+ for (ni, nt) in [(1.0_f64, 1.0_f64), (1.0, 1.5), (1.5, 1.0), (1.0, 3.0)] {
+ for cosine in [0.0, 0.01, 0.5, (nt / ni).atan().cos(), 1.0] {
+ let mut params = vec![0; 64];
+ scene::vector(&mut params, Vec3::new(cosine, ni, nt), 0.0);
+ params.resize(PARAMETER_BYTES, 0);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let actual = task.read_linear().unwrap()[0];
+ let expected = solidcraft_render::transmission::fresnel(cosine, ni, nt).unwrap();
+ for (a, b) in actual.iter().zip([expected.s, expected.p, expected.transmitted_cosine.unwrap_or(0.0)]) {
+ assert!((f64::from(*a) - b).abs() < 2e-5, "Fresnel {ni}->{nt} cos={cosine}: {a} != {b}");
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_nonabsorbing_glass_sphere_white_furnace_conserves_radiance() {
+ let Some(executor) = executor() else { return };
+ let mut scene = sphere(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap());
+ scene.meshes[0].transmission = Some(clear_glass());
+ scene.meshes[0].opacity = 0.2;
+ let options = JobOptions { samples: 512, max_depth: 16, seed: 1948, ..Default::default() };
+ let mut task = Task::new(executor.context.clone(), scene, request(16), options, CancelToken::default()).unwrap();
+ task.environment = 1.0;
+ task.studio = 0.0;
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ for (index, pixel) in task.read_linear().unwrap().iter().enumerate() {
+ assert!((pixel[0] - 1.0).abs() < 0.025, "glass furnace pixel {index}: {pixel:?}");
+ }
+}
+
+#[test]
+fn gpu_ball_lens_focus_uses_actual_mesh_intersections() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("lens_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let mut scene = sphere_grid(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap(), 128, 256);
+ scene.meshes[0].transmission = Some(clear_glass());
+ let mut task = Task::new(context.clone(), scene, request(1), JobOptions::default(), CancelToken::default()).unwrap();
+ for height in [0.01, 0.02, 0.03] {
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, Vec3::new(height, 0.0, 3.0), 0.0);
+ scene::vector(&mut params, Vec3::ZERO, 0.0);
+ scene::vector(&mut params, Vec3::ZERO, 0.0);
+ scene::vector(&mut params, -Vec3::Z, 1.5); // nR/(2(n-1)), measured from centre.
+ scene::vector(&mut params, Vec3::new(f64::from(task.epsilon), 0.0, 0.0), 0.0);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let actual = task.read_linear().unwrap()[0];
+ assert_eq!(actual[3], 1.0);
+ assert!((actual[0] - 1.0).abs() < 5e-5 && (actual[1] - 1.0).abs() < 5e-5, "image-space focal spot at h={height}: {actual:?}");
+ }
+}
+
+#[test]
+fn gpu_camera_inside_volume_fails_without_publishing_fake_radiance() {
+ let Some(executor) = executor() else { return };
+ let mut scene = sphere(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap());
+ scene.meshes[0].transmission = Some(clear_glass());
+ let mut request = request(1);
+ request.camera.distance = 0.1;
+ let mut task = Task::new(executor.context.clone(), scene.clone(), request.clone(), JobOptions::default(), CancelToken::default()).unwrap();
+ task.complete_sample().unwrap();
+ assert_eq!(task.read_linear().unwrap_err().code, ErrorCode::InvalidScene);
+ drop(task);
+ // Seed just below the 32-bit wrap: the next real failed path must carry
+ // into the high word, rather than clearing diagnostics and publishing black.
+ let mut task = Task::new(executor.context.clone(), scene, request, JobOptions::default(), CancelToken::default()).unwrap();
+ let mut failures = [0; FAILURE_BYTES as usize];
+ failures[..4].copy_from_slice(&u32::MAX.to_le_bytes());
+ task.context.queue.write_buffer(&task.failures, 0, &failures);
+ task.complete_sample().unwrap();
+ let error = task.read_linear().unwrap_err();
+ assert_eq!(error.code, ErrorCode::InvalidScene);
+ assert!(error.message.contains("4294967296 of 1 paths"), "{error}");
+}
+
+#[test]
+fn engine_preflight_keeps_cpu_alpha_and_routes_physical_glass_to_the_native_host() {
+ use serde_json::json;
+ let Some(executor) = executor() else { return };
+ let mut s = solidcraft_engine::Session::default();
+ s.set_render_job_host(Some(solidcraft_render::job::CpuHost::cooperative())).unwrap();
+ s.execute("solid.box", &json!({"length":10,"width":10,"height":2,"body_name":"Glass"})).unwrap();
+ s.execute("appearance.assign", &json!({"bodies":["Glass"],"color":"#c0e0ff","opacity":0.2})).unwrap();
+ let cpu = s.execute("render.preflight", &json!({"settings":{"width":16,"height":16}})).unwrap();
+ assert_eq!(cpu["refraction"], false);
+ assert_eq!(cpu["transparency"], "sorted_alpha_approximation");
+ assert!(s.execute("render.preflight", &json!({"progressive":true,"settings":{"width":16,"height":16}})).is_err());
+ s.register_render_job_host(ImageHost::with_executor(Arc::new(executor)).unwrap()).unwrap();
+ let snapshot = s.doc.to_json();
+ let mut params = json!({"progressive":true,"settings":{"width":16,"height":16},
+ "raytrace":{"dielectrics":[{"body_index":0,"body_name":"Glass","ior":1.5,"absorption_per_mm":[0.1,0.02,0],"boundary":"closed_box","thickness_mm":0}]}});
+ let gpu = s.execute("render.preflight", &params).unwrap();
+ assert_eq!(gpu["refraction"], true);
+ assert_eq!(gpu["dielectric_boundaries"], json!(["thin_sheet", "closed_box", "closed_mesh"]));
+ assert_eq!(gpu["transparency"], "physical_transmission");
+ assert_eq!(gpu["resolved"]["executor"], "gpu-path");
+ params["settings"]["camera"] = json!(Camera { distance: 40.0, fov: 0.7, ..Default::default() });
+ params["lens"] = json!({"aperture_radius_mm":0.5,"focus_distance_mm":40});
+ let lens = s.execute("render.preflight", &params).unwrap();
+ assert_eq!(lens["options"]["lens"]["aperture_radius_mm"], 0.5);
+ assert_eq!(snapshot, s.doc.to_json());
+ params["progressive"] = json!(false);
+ assert!(s.execute("render.preflight", &params).is_err());
+ assert!(!solidcraft_engine::product_scene::extract(&s).unwrap().has_transmission());
+}
+
+#[test]
+fn gpu_thin_lens_focus_and_defocus_match_geometric_oracle() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("camera_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for (yaw, pitch, roll) in [(0.0, 0.0, 0.0), (-0.45, 0.5, 0.7)] {
+ let mut request = request(2);
+ request.camera = Camera { distance: 12.0, fov: 0.7, yaw, pitch, roll, ..Default::default() };
+ let camera = request.camera;
+ let lens = solidcraft_render::job::ThinLens { aperture_radius_mm: 0.4, focus_distance_mm: 9.0 };
+ let options = JobOptions { lens: Some(lens), ..Default::default() };
+ let mut task = Task::new(context.clone(), sphere(white()), request, options, CancelToken::default()).unwrap();
+ let (right, up, back) = camera.basis();
+ let eye = back * camera.distance;
+ for (ux, uy) in [(0.0_f64, 0.0_f64), (0.7, -0.6)] {
+ let focal =
+ eye + (right * ux + up * uy) * (camera.half_height() * lens.focus_distance_mm / camera.distance) - back * lens.focus_distance_mm;
+ for (radial, azimuth) in [(0.0_f64, 0.0_f64), (0.25, 0.125), (0.75, 0.625), (0.999, 0.999)] {
+ let mut params = task.parameters(1);
+ params.truncate(96);
+ scene::vector(&mut params, Vec3::new(ux, uy, radial), azimuth as f32);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let rays = task.read_linear().unwrap();
+ let vec = |p: [f32; 4]| Vec3::new(f64::from(p[0]), f64::from(p[1]), f64::from(p[2]));
+ let origin = vec(rays[0]) - Vec3::new(16.0, 16.0, 16.0);
+ let direction = vec(rays[1]) - Vec3::new(2.0, 2.0, 2.0);
+ let disk = (right * (azimuth * std::f64::consts::TAU).cos() + up * (azimuth * std::f64::consts::TAU).sin())
+ * (radial.sqrt() * lens.aperture_radius_mm);
+ assert!((origin - eye - disk).len() < 3e-6);
+ let focus_hit = origin + direction * ((focal - origin).dot(back) / direction.dot(back));
+ assert!((focus_hit - focal).len() < 5e-6, "focus {focus_hit:?} != {focal:?}");
+ // At axial depth z, signed displacement from the pinhole hit is
+ // disk*(1-z/focus). Check both sides, including the flip beyond focus.
+ for depth in [4.5, 18.0] {
+ let centre = eye - back * depth;
+ let hit = origin + direction * ((centre - origin).dot(back) / direction.dot(back));
+ let pinhole = eye + (focal - eye) * (depth / lens.focus_distance_mm);
+ assert!((hit - pinhole - disk * (1.0 - depth / lens.focus_distance_mm)).len() < 1e-5);
+ }
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_zero_aperture_is_bit_identical_and_lens_admission_is_explicit() {
+ let Some(executor) = executor() else { return };
+ let mut request = request(16);
+ request.camera.fov = 0.7;
+ let render = |lens, fov| {
+ let options = JobOptions { samples: 8, lens, seed: 1948, ..Default::default() };
+ let mut image = request.clone();
+ image.camera.fov = fov;
+ let mut task = Task::new(executor.context.clone(), sphere(white()), image, options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ task.read_linear().unwrap()
+ };
+ for fov in [0.0, 0.7] {
+ assert_eq!(render(None, fov), render(Some(solidcraft_render::job::ThinLens { aperture_radius_mm: 0.0, focus_distance_mm: 8.0 }), fov));
+ }
+ let lens = Some(solidcraft_render::job::ThinLens { aperture_radius_mm: 0.3, focus_distance_mm: 4.0 });
+ assert_eq!(render(lens, 0.7), render(lens, 0.7));
+ request.camera.fov = 0.0;
+ assert!(admission(&sphere(white()), &request, JobOptions { lens, ..Default::default() }).is_err());
+ request.camera.fov = 1e-100;
+ assert!(admission(&sphere(white()), &request, JobOptions { lens, ..Default::default() }).is_err());
+}
+
+#[test]
+#[ignore = "manual glass transport evidence; set SOLIDCRAFT_GLASS_EVIDENCE to a PNG path"]
+fn glass_transport_evidence() {
+ let Some(executor) = executor() else { return };
+ let output = std::env::var("SOLIDCRAFT_GLASS_EVIDENCE").unwrap();
+ let mut meshes = Vec::new();
+ for (centre, radius, color) in
+ [(Vec3::new(-1.3, 0.0, 1.5), 1.5, Vec3::new(0.75, 0.94, 1.0)), (Vec3::new(2.0, 1.0, 1.0), 1.0, Vec3::new(1.0, 0.7, 0.35))]
+ {
+ let mut scene = sphere_grid(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap(), 96, 192);
+ let mut body = scene.meshes.remove(0);
+ for p in &mut Arc::make_mut(&mut body.mesh).positions {
+ *p = *p * radius + centre;
+ }
+ body.transmission =
+ Some(solidcraft_render::transmission::Transmission::new(Vec3::new(-color.x.ln(), -color.y.ln(), -color.z.ln()) / 5.0, None).unwrap());
+ meshes.push(body);
+ }
+ for y in -16..16 {
+ for x in -16..16 {
+ let color = if (x + y) % 2 == 0 { Vec3::new(0.65, 0.7, 0.75) } else { Vec3::new(0.035, 0.055, 0.08) };
+ let x = f64::from(x) * 2.0;
+ let y = f64::from(y) * 2.0;
+ let mesh = Mesh {
+ positions: vec![
+ Vec3::new(x, y, -0.01),
+ Vec3::new(x + 2.0, y, -0.01),
+ Vec3::new(x + 2.0, y + 2.0, -0.01),
+ Vec3::new(x, y + 2.0, -0.01),
+ ],
+ normals: vec![Vec3::Z; 4],
+ triangles: vec![[0, 1, 2], [0, 2, 3]],
+ tri_face: vec![0, 0],
+ ..Default::default()
+ };
+ meshes.push(ProductMesh {
+ name: "original checker tile".into(),
+ mesh: Arc::new(mesh),
+ color: [200; 3],
+ opacity: 1.0,
+ surface: Some(OpaqueSurface::new(color, 0.0, 0.65, 1.5).unwrap()),
+ transmission: None,
+ faces: vec![],
+ });
+ }
+ }
+ let bounds = meshes.iter().fold(Aabb3::EMPTY, |a, m| a.union(&m.mesh.bounds()));
+ let camera = Camera { target: Vec3::new(0.0, 0.0, 1.0), yaw: -0.45, pitch: 0.5, distance: 13.0, fov: 0.65, ..Default::default() };
+ let request = ImageRequest {
+ textures: None,
+ environment: None,
+ camera,
+ width: 960,
+ height: 720,
+ background: [236, 240, 245],
+ transparent_background: false,
+ };
+ let lens =
+ std::env::var_os("SOLIDCRAFT_GLASS_DOF").map(|_| solidcraft_render::job::ThinLens { aperture_radius_mm: 0.5, focus_distance_mm: 12.0 });
+ let options = JobOptions { samples: 256, max_depth: 16, seed: 1948, lens, ..Default::default() };
+ let mut task = Task::new(executor.context.clone(), ProductScene { meshes, bounds }, request, options, CancelToken::default()).unwrap();
+ task.environment = 1.0;
+ loop {
+ if let TaskPoll::Complete(png) = task.step(4096).unwrap() {
+ std::fs::write(&output, png).unwrap();
+ break;
+ }
+ }
+}
+
+fn glass_slab(thin: bool) -> ProductScene {
+ let mut mesh = Mesh::default();
+ let faces = [
+ ([[-10., -10., 0.5], [10., -10., 0.5], [10., 10., 0.5], [-10., 10., 0.5]], Vec3::Z),
+ ([[-10., 10., -0.5], [10., 10., -0.5], [10., -10., -0.5], [-10., -10., -0.5]], -Vec3::Z),
+ ([[10., -10., -0.5], [10., 10., -0.5], [10., 10., 0.5], [10., -10., 0.5]], Vec3::X),
+ ([[-10., 10., -0.5], [-10., -10., -0.5], [-10., -10., 0.5], [-10., 10., 0.5]], -Vec3::X),
+ ([[10., 10., -0.5], [-10., 10., -0.5], [-10., 10., 0.5], [10., 10., 0.5]], Vec3::Y),
+ ([[-10., -10., -0.5], [10., -10., -0.5], [10., -10., 0.5], [-10., -10., 0.5]], -Vec3::Y),
+ ];
+ for (index, (positions, normal)) in faces.into_iter().enumerate() {
+ if thin && index > 0 {
+ break;
+ }
+ let offset = mesh.positions.len() as u32;
+ for p in positions {
+ mesh.positions.push(Vec3::new(p[0], p[1], p[2]));
+ mesh.normals.push(normal);
+ }
+ mesh.triangles.extend([[offset, offset + 1, offset + 2], [offset, offset + 2, offset + 3]]);
+ mesh.tri_face.extend([0, 0]);
+ }
+ let bounds = mesh.bounds();
+ ProductScene {
+ bounds,
+ meshes: vec![ProductMesh {
+ name: "original slab".into(),
+ mesh: Arc::new(mesh),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap()),
+ transmission: Some(
+ solidcraft_render::transmission::Transmission::new(Vec3::new(-0.5_f64.ln(), -0.8_f64.ln(), 0.0), thin.then_some(1.0)).unwrap(),
+ ),
+ faces: vec![],
+ }],
+ }
+}
+
+#[test]
+fn gpu_solid_and_thin_slabs_match_absorbing_interreflection_oracle() {
+ let Some(executor) = executor() else { return };
+ for (thin, thickness) in [(false, 1.0), (true, 1.0), (true, 0.0)] {
+ let mut scene = glass_slab(thin);
+ if thin {
+ let sigma = scene.meshes[0].transmission.unwrap().extinction();
+ scene.meshes[0].transmission = Some(solidcraft_render::transmission::Transmission::new(sigma, Some(thickness)).unwrap());
+ }
+ let (_, expected) = solidcraft_render::transmission::slab(scene.meshes[0].transmission.unwrap(), thickness, 1.0, 1.0, 1.5).unwrap();
+ let mut request = request(1);
+ request.camera.fov = 0.0001;
+ let options = JobOptions { samples: 4096, max_depth: 16, seed: 1948, ..Default::default() };
+ let mut task = Task::new(executor.context.clone(), scene, request, options, CancelToken::default()).unwrap();
+ task.environment = 1.0;
+ task.environment_bottom_only = true;
+ // Deliberately large offset: Beer uses unshifted geometric endpoints.
+ task.epsilon = 0.05;
+ task.studio = 0.0;
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let actual = task.read_linear().unwrap()[0];
+ for (a, b) in actual.iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 0.015, "slab thin={thin} thickness={thickness}: {actual:?} vs {expected:?}");
+ }
+ }
+}
+
+#[test]
+fn shader_validates_without_a_device() {
+ let module = naga::front::wgsl::parse_str(SHADER).unwrap();
+ let parameters = module.types.iter().find(|(_, ty)| ty.name.as_deref() == Some("Params")).unwrap().1;
+ let naga::TypeInner::Struct { span, .. } = &parameters.inner else { panic!("Params must be a struct") };
+ assert_eq!(*span as usize, PARAMETER_BYTES);
+ naga::valid::Validator::new(naga::valid::ValidationFlags::all(), naga::valid::Capabilities::empty()).validate(&module).unwrap();
+}
+
+/// #3217: the path tracer opens Vulkan adapters only, and none where the platform has no
+/// Vulkan backend (macOS).
+#[test]
+fn path_devices_are_vulkan_only() {
+ let picked = crate::select::pick_vulkan(crate::select::Policy::Auto, |_| true);
+ if let Some((adapter, report)) = &picked {
+ assert_eq!(adapter.get_info().backend, wgpu::Backend::Vulkan);
+ assert_eq!(report.backend, "Vulkan");
+ }
+ if cfg!(target_os = "macos") {
+ assert!(picked.is_none());
+ }
+}
+
+#[test]
+fn admission_rejects_hostile_parameters_and_transparency() {
+ let mut scene = sphere(white());
+ let mut r = request(16);
+ for size in [0, 4097, u32::MAX] {
+ r.width = size;
+ assert!(admission(&scene, &r, JobOptions::default()).is_err());
+ }
+ r.width = 16;
+ for samples in [0, 4097, u32::MAX] {
+ assert!(admission(&scene, &r, JobOptions { samples, ..Default::default() }).is_err());
+ }
+ for depth in [0, 17, u32::MAX] {
+ assert!(admission(&scene, &r, JobOptions { max_depth: depth, ..Default::default() }).is_err());
+ }
+ for ev in [f64::NAN, f64::INFINITY, 33.0] {
+ assert!(admission(&scene, &r, JobOptions { exposure_ev: ev, ..Default::default() }).is_err());
+ }
+ scene.meshes[0].opacity = 0.5;
+ assert!(admission(&scene, &r, JobOptions::default()).is_err());
+ scene.meshes[0].opacity = 1.0;
+ Arc::make_mut(&mut scene.meshes[0].mesh).triangles[0][0] = u32::MAX;
+ assert!(scene::flatten(&scene, Vec3::ZERO, &CancelToken::default()).is_err());
+}
+
+#[test]
+fn admission_applies_the_gpu_estimate_instead_of_the_cpu_raster_budget() {
+ // A library-bounded source (not an ordinary UI scene): about 100 MiB of face appearances
+ // on a small mesh at the largest image. Its CPU raster estimate is above 384 MiB (covered
+ // in the render crate); the GPU's own estimate stays within its 512 MiB job cap.
+ let count = (100 * 1024 * 1024 / std::mem::size_of::<solidcraft_render::FaceAppearance>()).min(1_000_000);
+ let mut scene = sphere(white());
+ let appearance = solidcraft_render::FaceAppearance { face: 0, color: [255; 3], opacity: 1.0, surface: None, transmission: None };
+ scene.meshes[0].faces = vec![appearance; count];
+ let r = request(2048);
+ let a = admission(&scene, &r, JobOptions::default()).unwrap();
+ assert!(a.estimated_total_bytes <= 512 * 1024 * 1024, "{a:?}");
+ assert_eq!(a.face_appearances, count as u64);
+ // The CPU host still rejects the same source.
+ assert_eq!(solidcraft_render::job::admit(&scene, &r).unwrap_err().code, ErrorCode::LimitExceeded);
+}
+
+#[test]
+fn bvh_handles_empty_and_cancelled_scenes() {
+ let empty = ProductScene { meshes: Vec::new(), bounds: Aabb3::EMPTY };
+ let upload = scene::flatten(&empty, Vec3::ZERO, &CancelToken::default()).unwrap();
+ assert_eq!(upload.nodes.len(), 32);
+ assert_eq!(&upload.nodes[12..16], &u32::MAX.to_le_bytes());
+ let cancel = CancelToken::default();
+ cancel.cancel();
+ assert_eq!(scene::flatten(&sphere(white()), Vec3::ZERO, &cancel).err().unwrap().code, ErrorCode::Cancelled);
+}
+
+#[test]
+fn gpu_brdf_matches_f64_surface_oracle() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context
+ .device
+ .create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("path BRDF reference"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for metallic in [0.0, 0.5, 1.0] {
+ for roughness in [0.045, 0.25, 1.0] {
+ for ior in [1.0, 1.5, 3.0] {
+ let surface = OpaqueSurface::new(Vec3::new(0.8, 0.5, 0.2), metallic, roughness, ior).unwrap();
+ let mut task = Task::new(context.clone(), sphere(surface), request(1), JobOptions::default(), CancelToken::default()).unwrap();
+ for (view, light) in [
+ (Vec3::Z, Vec3::Z),
+ (Vec3::new(0.5, 0.2, 1.0), Vec3::new(-0.4, 0.3, 0.8)),
+ (Vec3::new(1.0, 0.0, 0.02), Vec3::new(-1.0, 0.1, 0.02)),
+ ] {
+ let view = view.normalized().unwrap();
+ let light = light.normalized().unwrap();
+ let mut params = vec![0; 48];
+ scene::vector(&mut params, light, 0.0);
+ scene::vector(&mut params, Vec3::Z, 0.0);
+ scene::vector(&mut params, view, 0.0);
+ scene::vector(&mut params, Vec3::ZERO, 0.0);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let actual = task.read_linear().unwrap()[0];
+ let expected = surface.brdf(Vec3::Z, view, light).unwrap();
+ if metallic == 0.0 && ior == 1.0 {
+ let diffuse = Vec3::new(0.8, 0.5, 0.2) / std::f64::consts::PI;
+ assert!((expected - diffuse).len() < 1e-12, "index-matched diffuse has no interface reflection");
+ }
+ for (a, b) in actual.iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() <= 3e-3 * b.abs() + 2e-5, "m={metallic}, r={roughness}, ior={ior}: {a} vs {b}");
+ }
+ }
+ }
+ }
+ }
+}
+
+/// The viewport embeds a separate WGSL translation. Exercise its actual function
+/// on the same native device as the path-tracer oracle, not a copied Rust formula.
+#[test]
+fn viewport_brdf_matches_f64_surface_oracle_at_index_match() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let source = format!(
+ "{}\n{}\n{}",
+ r#"
+struct ViewUniform { vp: mat4x4<f32>, back: vec4<f32>, eye: vec4<f32>, };
+@group(1) @binding(0) var<uniform> u: ViewUniform;
+struct Probe { base: vec4<f32>, parameters: vec4<f32>, view: vec4<f32>, light: vec4<f32>, };
+@group(0) @binding(0) var<uniform> probe: Probe;
+@group(0) @binding(1) var<storage, read_write> result: array<vec4<f32>>;
+"#,
+ crate::pbr::SOURCE,
+ r#"
+@compute @workgroup_size(1)
+fn probe_pbr() {
+ result[0] = vec4<f32>(pbr_brdf(probe.base.xyz, probe.parameters.xyz,
+ vec3<f32>(0.0,0.0,1.0),probe.view.xyz,probe.light.xyz),1.0);
+}
+"#
+ );
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("actual viewport PBR oracle"),
+ source: wgpu::ShaderSource::Wgsl(source.into()),
+ });
+ let layout = context.device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
+ label: None,
+ entries: &[
+ wgpu::BindGroupLayoutEntry {
+ binding: 0,
+ visibility: wgpu::ShaderStages::COMPUTE,
+ ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, min_binding_size: None },
+ count: None,
+ },
+ wgpu::BindGroupLayoutEntry {
+ binding: 1,
+ visibility: wgpu::ShaderStages::COMPUTE,
+ ty: wgpu::BindingType::Buffer {
+ ty: wgpu::BufferBindingType::Storage { read_only: false },
+ has_dynamic_offset: false,
+ min_binding_size: None,
+ },
+ count: None,
+ },
+ ],
+ });
+ let pipeline_layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&pipeline_layout),
+ module: &shader,
+ entry_point: Some("probe_pbr"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let uniform = context.device.create_buffer(&wgpu::BufferDescriptor {
+ label: None,
+ size: 64,
+ usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
+ mapped_at_creation: false,
+ });
+ let values = context.device.create_buffer(&wgpu::BufferDescriptor {
+ label: None,
+ size: 16,
+ usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC,
+ mapped_at_creation: false,
+ });
+ let readback = context.device.create_buffer(&wgpu::BufferDescriptor {
+ label: None,
+ size: 16,
+ usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
+ mapped_at_creation: false,
+ });
+ let bind = context.device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: None,
+ layout: &layout,
+ entries: &[
+ wgpu::BindGroupEntry { binding: 0, resource: uniform.as_entire_binding() },
+ wgpu::BindGroupEntry { binding: 1, resource: values.as_entire_binding() },
+ ],
+ });
+ for metallic in [0.0, 0.5, 1.0] {
+ for roughness in [0.045, 0.5, 1.0] {
+ for ior in [1.0, 1.5, 3.0] {
+ let base = Vec3::new(0.8, 0.5, 0.2);
+ let surface = OpaqueSurface::new(base, metallic, roughness, ior).unwrap();
+ for (view, light) in [
+ (Vec3::Z, Vec3::Z),
+ (Vec3::new(0.5, 0.0, 1.0).normalized().unwrap(), Vec3::new(-0.4, 0.3, 0.8).normalized().unwrap()),
+ (Vec3::new(1.0, 0.0, 0.02).normalized().unwrap(), Vec3::new(-1.0, 0.1, 0.02).normalized().unwrap()),
+ ] {
+ let input = [
+ 0.8_f32,
+ 0.5,
+ 0.2,
+ 0.0,
+ metallic as f32,
+ roughness as f32,
+ ior as f32,
+ 0.0,
+ view.x as f32,
+ view.y as f32,
+ view.z as f32,
+ 0.0,
+ light.x as f32,
+ light.y as f32,
+ light.z as f32,
+ 0.0,
+ ];
+ let bytes: Vec<u8> = input.iter().flat_map(|value| value.to_le_bytes()).collect();
+ context.queue.write_buffer(&uniform, 0, &bytes);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ encoder.copy_buffer_to_buffer(&values, 0, &readback, 0, 16);
+ let submission = context.queue.submit([encoder.finish()]);
+ let slice = readback.slice(..);
+ let (tx, rx) = std::sync::mpsc::channel();
+ slice.map_async(wgpu::MapMode::Read, move |result| {
+ let _ = tx.send(result);
+ });
+ context.wait(submission, TIMEOUT).unwrap();
+ rx.try_recv().unwrap().unwrap();
+ let data = slice.get_mapped_range().unwrap();
+ let actual: Vec<f32> = data.as_chunks::<4>().0.iter().map(|bytes| f32::from_le_bytes(*bytes)).collect();
+ drop(data);
+ readback.unmap();
+ let expected = surface.brdf(Vec3::Z, view, light).unwrap();
+ if metallic == 0.0 && ior == 1.0 {
+ assert!((expected - base / std::f64::consts::PI).len() < 1e-12);
+ }
+ for (a, b) in actual.iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 2e-5 + 3e-3 * b.abs(), "viewport m={metallic}, r={roughness}, ior={ior}: {a} vs {b}");
+ }
+ }
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_tiny_scene_matches_cpu_studio_with_face_appearance() {
+ let Some(executor) = executor() else { return };
+ let surface = OpaqueSurface::new(Vec3::new(0.7, 0.2, 0.1), 0.5, 0.3, 1.5).unwrap();
+ let mesh = Mesh {
+ positions: vec![Vec3::new(-3.0, -3.0, 0.0), Vec3::new(3.0, -3.0, 0.0), Vec3::new(3.0, 3.0, 0.0), Vec3::new(-3.0, 3.0, 0.0)],
+ normals: vec![Vec3::Z; 4],
+ triangles: vec![[0, 1, 2], [0, 2, 3]],
+ tri_face: vec![7, 9],
+ ..Default::default()
+ };
+ let bounds = mesh.bounds();
+ let scene = ProductScene {
+ meshes: vec![ProductMesh {
+ name: "reference plane".into(),
+ mesh: Arc::new(mesh),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(white()),
+ transmission: None,
+ faces: [7, 9]
+ .map(|face| solidcraft_render::FaceAppearance { face, color: [0; 3], opacity: 1.0, surface: Some(surface), transmission: None })
+ .to_vec(),
+ }],
+ bounds,
+ };
+ let mut task =
+ Task::new(executor.context.clone(), scene, request(4), JobOptions { samples: 4, max_depth: 1, ..Default::default() }, CancelToken::default())
+ .unwrap();
+ for _ in 0..4 {
+ task.complete_sample().unwrap();
+ }
+ let actual = task.read_linear().unwrap();
+ let expected = solidcraft_render::studio::shade(surface, Vec3::Z, Vec3::Z).unwrap();
+ for pixel in actual {
+ assert_eq!(pixel[3], 1.0);
+ for (a, b) in pixel.iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 3e-3 * b.abs() + 2e-5, "{a} vs {b}");
+ }
+ }
+}
+
+#[test]
+fn gpu_furnace_fixed_seed_and_cancellation() {
+ let Some(executor) = executor() else { return };
+ let options = JobOptions { samples: 4096, max_depth: 8, seed: 37, ..Default::default() };
+ let mut task = Task::new(executor.context.clone(), sphere(white()), request(8), options, CancelToken::default()).unwrap();
+ task.environment = 1.0;
+ task.studio = 0.0;
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let result = task.read_linear().unwrap();
+ eprintln!("furnace centre {:?}; BVH {:.3} ms; upload {} bytes / {:.3} ms", result[27], task.metrics.0, task.metrics.1, task.metrics.2);
+ // The oracle includes Schlick entry/exit attenuation even at IOR=1, plus single-
+ // scattering GGX. It is near-white, not an exactly energy-preserving Lambert model.
+ for index in [27, 28, 35, 36] {
+ assert!((result[index][0] - 1.0).abs() < 0.07, "furnace radiance: {:?}", result[index]);
+ }
+ let mut repeat = Task::new(executor.context.clone(), sphere(white()), request(8), options, CancelToken::default()).unwrap();
+ repeat.environment = 1.0;
+ repeat.studio = 0.0;
+ for _ in 0..options.samples {
+ repeat.complete_sample().unwrap();
+ }
+ assert_eq!(result, repeat.read_linear().unwrap(), "fixed sample indices and seed must repeat on the same adapter");
+ let token = CancelToken::default();
+ let mut cancelled = Task::new(executor.context.clone(), sphere(white()), request(16), options, token.clone()).unwrap();
+ cancelled.dispatch().unwrap();
+ token.cancel();
+ assert_eq!(cancelled.step(4096).err().unwrap().code, ErrorCode::Cancelled);
+}
+
+#[test]
+fn skinny_polar_triangles_do_not_shadow_themselves() {
+ let Some(executor) = executor() else { return };
+ let mut image = request(32);
+ image.camera.distance = 16.0;
+ image.camera.fov = 0.0005;
+ let mut task = Task::new(
+ executor.context.clone(),
+ sphere_section(white(), 512, 1024, 1),
+ image,
+ JobOptions { samples: 1, max_depth: 1, ..Default::default() },
+ CancelToken::default(),
+ )
+ .unwrap();
+ task.complete_sample().unwrap();
+ let pixels = task.read_linear().unwrap();
+ for (index, pixel) in pixels.iter().enumerate() {
+ assert_eq!(pixel[3], 1.0, "polar cap covers the image: {index} {pixel:?}");
+ assert!(pixel[0] > 0.1, "outward-facing cap must receive unobstructed studio light: {index} {pixel:?}");
+ }
+}
+
+#[test]
+fn native_host_cancel_never_publishes_a_frame() {
+ let Some(executor) = executor() else { return };
+ let host = ImageHost::with_executor(Arc::new(executor)).unwrap();
+ let job = host
+ .submit_with_options(
+ solidcraft_render::job::JobId { session: 1, serial: 1, generation: 1 },
+ 1,
+ sphere(white()),
+ request(64),
+ JobOptions { samples: 4096, ..Default::default() },
+ )
+ .unwrap();
+ let deadline = Instant::now() + Duration::from_secs(30);
+ loop {
+ let status = job.status().unwrap();
+ if status.progress.phase == Phase::Running {
+ break;
+ }
+ assert!(!status.progress.phase.terminal(), "{status:?}");
+ assert!(Instant::now() < deadline);
+ std::thread::sleep(Duration::from_millis(5));
+ }
+ job.cancel().unwrap();
+ assert_eq!(job.wait_timeout(Duration::from_secs(30)).unwrap().progress.phase, Phase::Cancelled);
+ assert!(job.frame().unwrap().is_none());
+}
+
+/// Explicit benchmark: large allocation and sustained GPU load must not run in ordinary CI.
+#[test]
+#[ignore = "manual 1M-triangle 1920x1080 GPU performance measurement"]
+fn path_performance() {
+ let executor = executor().expect("benchmark requires an adapter");
+ let samples = std::env::var("SOLIDCRAFT_PATH_BENCH_SAMPLES").ok().map(|s| s.parse::<u32>().unwrap()).unwrap_or(1);
+ let options = JobOptions { samples, ..Default::default() };
+ options.validate().unwrap();
+ let surface = OpaqueSurface::new(Vec3::new(0.8, 0.4, 0.2), 0.25, 0.4, 1.5).unwrap();
+ let scene = sphere_grid(surface, 512, 1024);
+ let mut request = request(1920);
+ request.height = 1080;
+ let admitted = executor.admit(&scene, &request, options).unwrap();
+ let mut task = Task::new(executor.context.clone(), scene, request, options, CancelToken::default()).unwrap();
+ let started = Instant::now();
+ while task.sample < samples {
+ task.complete_sample().unwrap();
+ }
+ let seconds = started.elapsed().as_secs_f64();
+ let linear = task.read_linear().unwrap();
+ assert!(linear.iter().all(|p| p.iter().all(|v| v.is_finite())));
+ let coverage = linear.iter().map(|p| f64::from(p[3])).sum::<f64>() / linear.len() as f64;
+ assert!((0.16..0.19).contains(&coverage), "sphere must occupy the expected projected area: {coverage}");
+ let centre = linear[540 * 1920 + 960];
+ let lit = linear.iter().filter(|p| p[0] > 0.01).count();
+ eprintln!(
+ "PATH_BENCH_DIAGNOSTIC coverage={coverage:.6} centre={centre:?} lit_pixels={lit} nearby={:?}",
+ [linear[500 * 1920 + 960], linear[540 * 1920 + 1000], linear[580 * 1920 + 960]]
+ );
+ assert_eq!(centre[3], 1.0);
+ assert!(centre[0] > 0.01, "benchmark must actually shade the sphere: {centre:?}");
+ eprintln!("PATH_BENCH_IMAGE coverage={coverage:.6} centre={centre:?}");
+ eprintln!(
+ "PATH_BENCH input_triangles={} resolution=1920x1080 spp={} bvh_ms={:.3} upload_bytes={} upload_ms={:.3} admitted_bytes={} render_seconds={:.6} ms_per_spp={:.3}",
+ admitted.triangles,
+ samples,
+ task.metrics.0,
+ task.metrics.1,
+ task.metrics.2,
+ admitted.estimated_total_bytes,
+ seconds,
+ seconds * 1000.0 / f64::from(samples)
+ );
+}
+
+#[test]
+fn gpu_clear_coat_brdf_matches_f64_surface_oracle() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context
+ .device
+ .create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("path BRDF reference"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for metallic in [0.0, 1.0] {
+ for roughness in [0.045, 0.12, 0.5] {
+ for ior in [1.5, 3.0] {
+ let surface = OpaqueSurface::new(Vec3::new(0.8, 0.5, 0.2), metallic, 0.3, 1.5)
+ .unwrap()
+ .with_clear_coat(solidcraft_render::clear_coat::ClearCoat::new(1.0, roughness, ior).unwrap());
+ let mut task = Task::new(context.clone(), sphere(surface), request(1), JobOptions::default(), CancelToken::default()).unwrap();
+ for (view, light) in [
+ (Vec3::Z, Vec3::Z),
+ (Vec3::new(0.5, 0.2, 1.0), Vec3::new(-0.4, 0.3, 0.8)),
+ (Vec3::new(1.0, 0.0, 0.02), Vec3::new(-1.0, 0.1, 0.02)),
+ ] {
+ let view = view.normalized().unwrap();
+ let light = light.normalized().unwrap();
+ let mut params = vec![0; 48];
+ scene::vector(&mut params, light, 0.0);
+ scene::vector(&mut params, Vec3::Z, 0.0);
+ scene::vector(&mut params, view, 0.0);
+ scene::vector(&mut params, Vec3::ZERO, 0.0);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let actual = task.read_linear().unwrap()[0];
+ let expected = surface.brdf(Vec3::Z, view, light).unwrap();
+ for (a, b) in actual.iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() <= 3e-3 * b.abs() + 2e-5, "m={metallic}, r={roughness}, ior={ior}: {a} vs {b}");
+ }
+ }
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_clear_coat_pdf_matches_f64_surface_oracle() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context
+ .device
+ .create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("path BRDF reference"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("pdf_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for metallic in [0.0, 1.0] {
+ for roughness in [0.045, 0.12, 0.5] {
+ for ior in [1.5, 3.0] {
+ let surface = OpaqueSurface::new(Vec3::new(0.8, 0.5, 0.2), metallic, 0.3, 1.5)
+ .unwrap()
+ .with_clear_coat(solidcraft_render::clear_coat::ClearCoat::new(1.0, roughness, ior).unwrap());
+ let mut task = Task::new(context.clone(), sphere(surface), request(1), JobOptions::default(), CancelToken::default()).unwrap();
+ for (view, light) in [
+ (Vec3::Z, Vec3::Z),
+ (Vec3::new(0.5, 0.2, 1.0), Vec3::new(-0.4, 0.3, 0.8)),
+ (Vec3::new(1.0, 0.0, 0.02), Vec3::new(-1.0, 0.1, 0.02)),
+ ] {
+ let view = view.normalized().unwrap();
+ let light = light.normalized().unwrap();
+ let mut params = vec![0; 48];
+ scene::vector(&mut params, light, 0.0);
+ scene::vector(&mut params, Vec3::Z, 0.0);
+ scene::vector(&mut params, view, 0.0);
+ scene::vector(&mut params, Vec3::ZERO, 0.0);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let actual = task.read_linear().unwrap()[0];
+ let expected = solidcraft_render::clear_coat::surface_pdf(surface, Vec3::Z, view, light).unwrap();
+ for (a, b) in actual.iter().zip([expected, 0.0, 0.0]) {
+ assert!((f64::from(*a) - b).abs() <= 3e-3 * b.abs() + 2e-5, "m={metallic}, r={roughness}, ior={ior}: {a} vs {b}");
+ }
+ }
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_clear_coat_samples_the_pdf_mixture_components() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context
+ .device
+ .create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("coat sampling oracle"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("surface_sample_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for weight in [0.0, 0.4, 1.0] {
+ let surface = OpaqueSurface::new(Vec3::new(0.02, 0.02, 0.02), 0.0, 0.45, 1.5)
+ .unwrap()
+ .with_clear_coat(solidcraft_render::clear_coat::ClearCoat::new(weight, 0.12, 1.5).unwrap());
+ let mut task = Task::new(context.clone(), sphere(surface), request(1), JobOptions::default(), CancelToken::default()).unwrap();
+ let p = weight * 0.5;
+ // One variate strictly inside each nonempty mixture interval.
+ for component in [(1.0 - p) * 0.25, (1.0 - p) * 0.75, 1.0 - p * 0.5] {
+ if component >= 1.0 {
+ continue;
+ }
+ for x in [0.125_f64, 0.75] {
+ let mut params = vec![0; 48];
+ scene::vector(&mut params, Vec3::ZERO, 0.0);
+ scene::vector(&mut params, Vec3::Z, 0.0);
+ scene::vector(&mut params, Vec3::Z, 0.0);
+ scene::vector(&mut params, Vec3::new(component, x, 0.25), 0.0);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let actual = task.read_linear().unwrap()[0];
+ let expected = if component < (1.0 - p) * 0.5 {
+ Vec3::new(0.0, x.sqrt(), (1.0 - x).sqrt())
+ } else {
+ let r = if component >= 1.0 - p { 0.12_f64 } else { 0.45_f64 };
+ let c = ((1.0 - x) / (1.0 + (r.powi(4) - 1.0) * x)).sqrt();
+ Vec3::new(0.0, 2.0 * c * (1.0 - c * c).sqrt(), 2.0 * c * c - 1.0)
+ } + Vec3::new(2.0, 2.0, 2.0);
+ for (a, b) in actual.iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 2e-5, "weight={weight}, component={component}, x={x}: {actual:?}, {expected:?}");
+ }
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_studio_area_mis_matches_independent_quadrature_and_distance_visibility() {
+ use solidcraft_render::job::{AreaLight, AreaLights, StudioLighting};
+ let Some(executor) = executor() else { return };
+ let surface = white();
+ let plane = |z: f64| {
+ let mesh = Mesh {
+ positions: vec![Vec3::new(-10.0, -10.0, z), Vec3::new(10.0, -10.0, z), Vec3::new(10.0, 10.0, z), Vec3::new(-10.0, 10.0, z)],
+ normals: vec![Vec3::Z; 4],
+ triangles: vec![[0, 1, 2], [0, 2, 3]],
+ tri_face: vec![0, 0],
+ ..Default::default()
+ };
+ ProductMesh {
+ name: "original quadrature plane".into(),
+ mesh: Arc::new(mesh),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(surface),
+ transmission: None,
+ faces: Vec::new(),
+ }
+ };
+ let light = AreaLight { center: [2.0, 0.0, 2.0], u: [1.0, 0.0, 0.0], v: [0.0, -1.0, 0.0], radiance: [3.0; 3] };
+ let mut expected = 0.0;
+ for y in 0..256 {
+ for x in 0..256 {
+ let delta = Vec3::new(1.0 + (f64::from(x) + 0.5) / 128.0, -1.0 + (f64::from(y) + 0.5) / 128.0, 2.0);
+ let l = delta.normalized().unwrap();
+ expected += surface.brdf(Vec3::Z, Vec3::Z, l).unwrap().x * 3.0 * l.z * l.z / delta.len2() * 4.0 / (256.0 * 256.0);
+ }
+ }
+ for depth in [1, 2] {
+ for blocker in [None, Some(4.0), Some(1.0)] {
+ let mut scene = ProductScene { meshes: vec![plane(0.0)], bounds: Aabb3::EMPTY };
+ if let Some(z) = blocker {
+ scene.meshes.push(plane(z));
+ }
+ // Camera sits below any blocker and sees the receiver. Geometry behind
+ // the emitter must not shadow it; the nearer blocker must.
+ let mut image = request(1);
+ image.camera.distance = 0.1;
+ image.camera.fov = 0.001;
+ let options = JobOptions {
+ samples: 4096,
+ max_depth: depth,
+ seed: 37,
+ lighting: Some(StudioLighting { sun: None, environment: [0.0; 3], area_lights: AreaLights::new(&[light]).unwrap() }),
+ ..Default::default()
+ };
+ let mut task = Task::new(executor.context.clone(), scene, image, options, CancelToken::default()).unwrap();
+ assert_eq!(task.parameters(1).len(), PARAMETER_BYTES);
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let value = f64::from(task.read_linear().unwrap()[0][0]);
+ if blocker == Some(1.0) {
+ assert!(value < 1e-6, "blocked depth{depth}: {value}");
+ } else {
+ assert!((value - expected).abs() < 0.04 * expected, "depth{depth}, blocker{blocker:?}: {value} vs {expected}");
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_studio_environment_mis_matches_furnace_at_last_and_continuing_bounces() {
+ use solidcraft_render::job::StudioLighting;
+ let Some(executor) = executor() else { return };
+ for depth in [1, 2] {
+ let options = JobOptions {
+ samples: 4096,
+ max_depth: depth,
+ seed: 37,
+ lighting: Some(StudioLighting { sun: None, environment: [1.0; 3], ..Default::default() }),
+ ..Default::default()
+ };
+ let mut task = Task::new(executor.context.clone(), sphere(white()), request(8), options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let pixels = task.read_linear().unwrap();
+ for index in [27, 28, 35, 36] {
+ assert!((pixels[index][0] - 1.0).abs() < 0.07, "depth{depth}: {:?}", pixels[index]);
+ }
+ }
+}
+
+#[test]
+fn gpu_emitter_inside_glass_applies_final_segment_absorption() {
+ use solidcraft_render::job::{AreaLight, AreaLights, StudioLighting};
+ let Some(executor) = executor() else { return };
+ let mut glass = sphere(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.0).unwrap());
+ glass.meshes[0].transmission = Some(solidcraft_render::transmission::Transmission::new(Vec3::new(0.7, 0.3, 0.0), None).unwrap());
+ let light = AreaLight { center: [0.0; 3], u: [0.4, 0.0, 0.0], v: [0.0, 0.4, 0.0], radiance: [3.0; 3] };
+ let options = JobOptions {
+ samples: 16,
+ max_depth: 2,
+ lighting: Some(StudioLighting { sun: None, environment: [0.0; 3], area_lights: AreaLights::new(&[light]).unwrap() }),
+ ..Default::default()
+ };
+ let mut image = request(2);
+ image.camera.fov = 0.0001;
+ let mut task = Task::new(executor.context.clone(), glass, image, options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ for pixel in task.read_linear().unwrap() {
+ for (value, sigma) in pixel.iter().zip([0.7_f64, 0.3, 0.0]) {
+ assert!((f64::from(*value) - 3.0 * (-sigma).exp()).abs() < 0.002, "{pixel:?}");
+ }
+ }
+}
+
+fn environment_plane() -> ProductScene {
+ let mesh = Mesh {
+ positions: vec![Vec3::new(-3.0, -3.0, 0.0), Vec3::new(3.0, -3.0, 0.0), Vec3::new(3.0, 3.0, 0.0), Vec3::new(-3.0, 3.0, 0.0)],
+ normals: vec![Vec3::Z; 4],
+ triangles: vec![[0, 1, 2], [0, 2, 3]],
+ tri_face: vec![0, 0],
+ ..Default::default()
+ };
+ let bounds = mesh.bounds();
+ ProductScene {
+ meshes: vec![ProductMesh {
+ name: "original environment test plane".into(),
+ mesh: Arc::new(mesh),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(white()),
+ transmission: None,
+ faces: Vec::new(),
+ }],
+ bounds,
+ }
+}
+fn original_hdr() -> Vec<u8> {
+ let mut bytes = b"#?RADIANCE\nFORMAT=32-bit_rle_rgbe\nPRIMARIES=0.64 0.33 0.30 0.60 0.15 0.06 0.3127 0.3290\n\n-Y 2 +X 4\n".to_vec();
+ for _ in 0..8 {
+ bytes.extend_from_slice(&[128, 128, 128, 129]);
+ }
+ bytes
+}
+#[test]
+fn gpu_hdr_environment_matches_constant_furnace_and_resource_admission() {
+ use solidcraft_render::lighting::environment::EnvironmentSource;
+ let Some(executor) = executor() else { return };
+ let source = Arc::new(EnvironmentSource::hdr(original_hdr(), 0.3, 1.0, false).unwrap());
+ let mut image = request(8);
+ image.environment = Some(source.clone());
+ let options = JobOptions { samples: 2048, max_depth: 2, seed: 37, ..Default::default() };
+ let plain = admission(&sphere(white()), &request(8), options).unwrap();
+ let with_map = admission(&sphere(white()), &image, options).unwrap();
+ assert_eq!(with_map.estimated_total_bytes - plain.estimated_total_bytes, source.admitted_bytes());
+ let mut task = Task::new(executor.context.clone(), sphere(white()), image, options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let pixels = task.read_linear().unwrap();
+ for index in [27, 28, 35, 36] {
+ assert!((pixels[index][0] - 1.0).abs() < 0.07, "{:?}", pixels[index]);
+ }
+}
+#[test]
+fn gpu_finite_sun_matches_cone_quadrature_at_final_and_continuing_bounces() {
+ use solidcraft_render::job::{StudioLighting, Sun};
+ let Some(executor) = executor() else { return };
+ let sun = Sun { direction: [0.0, 0.0, 1.0], angular_radius_rad: 0.4, radiance: [3.0; 3] };
+ let mut expected = 0.0;
+ for i in 0..4096 {
+ let z = 1.0 - (f64::from(i) + 0.5) / 4096.0 * (1.0 - sun.angular_radius_rad.cos());
+ let l = Vec3::new((1.0 - z * z).sqrt(), 0.0, z);
+ expected += white().brdf(Vec3::Z, Vec3::Z, l).unwrap().x * z * 3.0 * sun.solid_angle() / 4096.0;
+ }
+ for max_depth in [1, 2] {
+ let mut image = request(2);
+ image.camera.distance = 0.1;
+ image.camera.fov = 0.001;
+ let options = JobOptions {
+ samples: 2048,
+ max_depth,
+ seed: 123,
+ lighting: Some(StudioLighting { sun: Some(sun), ..Default::default() }),
+ ..Default::default()
+ };
+ let mut task = Task::new(executor.context.clone(), environment_plane(), image, options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ for pixel in task.read_linear().unwrap() {
+ assert!((f64::from(pixel[0]) - expected).abs() < 0.03 * expected, "depth{max_depth}: {pixel:?}, {expected}");
+ }
+ }
+}
+
+#[test]
+fn gpu_environment_orientation_rotation_intensity_and_pdf_match_cpu() {
+ use solidcraft_render::lighting::environment::EnvironmentSource;
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let mut bytes = b"#?RADIANCE\nFORMAT=32-bit_rle_rgbe\n\n-Y 2 +X 4\n".to_vec();
+ for i in 0..8u8 {
+ bytes.extend_from_slice(&[16 * (i + 1), 32, 64, 129]);
+ }
+ let rotation = 0.7_f64;
+ let intensity = 2.5;
+ let source = Arc::new(EnvironmentSource::hdr(bytes, rotation, intensity, true).unwrap());
+ let cpu = source.prepare(&CancelToken::default()).unwrap();
+ let mut image = request(1);
+ image.environment = Some(source);
+ let mut task = Task::new(context.clone(), sphere(white()), image, JobOptions::default(), CancelToken::default()).unwrap();
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("environment_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for row in 0..2 {
+ for column in 0..4 {
+ let theta = std::f64::consts::PI * (f64::from(row) + 0.5) / 2.0;
+ let phi = std::f64::consts::TAU * (f64::from(column) + 0.5) / 4.0;
+ let local = Vec3::new(theta.sin() * phi.cos(), theta.sin() * phi.sin(), theta.cos());
+ let direction =
+ Vec3::new(rotation.cos() * local.x - rotation.sin() * local.y, rotation.sin() * local.x + rotation.cos() * local.y, local.z);
+ let mut params = task.parameters(1);
+ for (out, value) in params[48..60].as_chunks_mut::<4>().0.iter_mut().zip([direction.x, direction.y, direction.z]) {
+ out.copy_from_slice(&(value as f32).to_le_bytes());
+ }
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let actual = task.read_linear().unwrap()[0];
+ let (rgb, pdf) = cpu.evaluate(local).unwrap();
+ for (a, b) in actual.iter().zip(rgb.into_iter().map(|v| v * intensity as f32).chain([pdf])) {
+ assert!((a - b).abs() < 1e-5, "{actual:?} vs {rgb:?}/{pdf}");
+ }
+ }
+ }
+}
+
+fn shadow_probe(context: &Arc<Context>, scene: ProductScene, origin: Vec3, direction: Vec3, limit: f64) -> [[f32; 4]; 2] {
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("shadow connection oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("shadow_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let mut task = Task::new(context.clone(), scene, request(2), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, origin, 0.0);
+ scene::vector(&mut params, Vec3::ZERO, 0.0);
+ scene::vector(&mut params, Vec3::ZERO, 0.0);
+ scene::vector(&mut params, direction, limit as f32);
+ // Large offset catches Beer intervals incorrectly measured from shifted origins.
+ scene::vector(&mut params, Vec3::new(0.01, 0.0, 0.0), 0.0);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let pixels = task.read_linear().unwrap();
+ [pixels[0], pixels[1]]
+}
+
+#[test]
+fn gpu_shadow_sheets_solids_endpoints_and_invalid_crossings_match_oracles() {
+ use solidcraft_render::transmission::{slab, solid_shadow};
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ for thin in [true, false] {
+ let mut scene = glass_slab(thin);
+ let optics = scene.meshes[0].transmission.unwrap().with_shadow_transmission(true);
+ scene.meshes[0].transmission = Some(optics);
+ for cosine in [1.0_f64, 0.8] {
+ let d = Vec3::new((1.0 - cosine * cosine).sqrt(), 0.0, -cosine);
+ let actual = shadow_probe(context, scene.clone(), Vec3::new(0.0, 0.0, 2.0), d, 8.0);
+ let expected =
+ if thin { slab(optics, 1.0, cosine, 1.0, 1.5).unwrap().1 } else { solid_shadow(optics, 1.0 / cosine, cosine, cosine, 1.5).unwrap() };
+ for (a, b) in actual[0].iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 2e-5, "thin={thin}, cosine={cosine}: {actual:?} vs {expected:?}");
+ }
+ assert_eq!(actual[1][1], if thin { 1.0 } else { 2.0 });
+ }
+ let before = shadow_probe(context, scene.clone(), Vec3::new(0.0, 0.0, 2.0), -Vec3::Z, 1.0);
+ assert_eq!(before[0], [1.0; 4]);
+ if !thin {
+ let inside = shadow_probe(context, scene.clone(), Vec3::new(0.0, 0.0, 2.0), -Vec3::Z, 2.0);
+ let expected = optics.attenuation(0.5).unwrap() * (0.96 / 2.25);
+ for (a, b) in inside[0].iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 2e-5);
+ }
+ // Shadow rays start at shading points, which may touch or lie inside
+ // glass. A first exit infers that medium and absorbs from the origin.
+ let from_inside = shadow_probe(context, scene.clone(), Vec3::ZERO, Vec3::Z, 8.0);
+ let expected = optics.attenuation(0.5).unwrap() * 0.96;
+ for (a, b) in from_inside[0].iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 2e-5, "{from_inside:?} vs {expected:?}");
+ }
+ assert_eq!(from_inside[1][1], 1.0);
+ }
+ scene.meshes[0].transmission = Some(optics.with_shadow_transmission(false));
+ assert_eq!(shadow_probe(context, scene, Vec3::new(0.0, 0.0, 2.0), -Vec3::Z, 8.0)[0], [0.0, 0.0, 0.0, 1.0]);
+ }
+ let mut opaque = glass_slab(true);
+ opaque.meshes[0].transmission = None;
+ assert_eq!(shadow_probe(context, opaque, Vec3::new(0.0, 0.0, 2.0), -Vec3::Z, 8.0)[0], [0.0, 0.0, 0.0, 1.0]);
+}
+
+#[test]
+fn gpu_shadow_interface_walk_is_bounded_and_stacked_sheet_pdf_matches() {
+ let Some(executor) = executor() else { return };
+ for count in [2_u32, 64, 65] {
+ let mut scene = glass_slab(true);
+ let base = scene.meshes[0].mesh.clone();
+ let mut mesh = Mesh::default();
+ for layer in 0..count {
+ let offset = mesh.positions.len() as u32;
+ mesh.positions.extend(base.positions.iter().map(|p| *p - Vec3::Z * f64::from(layer)));
+ mesh.normals.extend_from_slice(&base.normals);
+ mesh.triangles.extend(base.triangles.iter().map(|t| t.map(|i| i + offset)));
+ mesh.tri_face.extend_from_slice(&base.tri_face);
+ }
+ scene.meshes[0].mesh = Arc::new(mesh);
+ scene.meshes[0].transmission = Some(solidcraft_render::transmission::Transmission::new(Vec3::ZERO, Some(0.0)).unwrap());
+ let actual = shadow_probe(&executor.context, scene, Vec3::new(0.0, 0.0, 2.0), -Vec3::Z, 100.0);
+ if count == 65 {
+ assert_eq!(actual[0], [0.0, 0.0, 0.0, 1.0]);
+ } else {
+ let expected = (0.96_f64 / 1.04).powi(count as i32);
+ assert!((f64::from(actual[0][0]) - expected).abs() < 2e-5);
+ assert!((f64::from(actual[1][0]) - expected).abs() < 2e-5);
+ assert_eq!(actual[1][1], count as f32);
+ }
+ }
+}
+
+#[test]
+fn gpu_shadow_mis_does_not_double_direct_energy_through_index_matched_glass() {
+ use solidcraft_render::job::{AreaLight, AreaLights, StudioLighting};
+ let Some(executor) = executor() else { return };
+ let surface = white();
+ let receiver = ProductMesh {
+ name: "shadow MIS receiver".into(),
+ mesh: Arc::new(Mesh {
+ positions: vec![Vec3::new(-20.0, -20.0, -2.0), Vec3::new(20.0, -20.0, -2.0), Vec3::new(20.0, 20.0, -2.0), Vec3::new(-20.0, 20.0, -2.0)],
+ normals: vec![Vec3::Z; 4],
+ triangles: vec![[0, 1, 2], [0, 2, 3]],
+ tri_face: vec![0, 0],
+ ..Default::default()
+ }),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(surface),
+ transmission: None,
+ faces: vec![],
+ };
+ let light = AreaLight { center: [0.0, 0.0, 2.0], u: [4.0, 0.0, 0.0], v: [0.0, -4.0, 0.0], radiance: [1.0; 3] };
+ let mut expected = 0.0;
+ for y in 0..128 {
+ for x in 0..128 {
+ let delta = Vec3::new(-4.0 + (f64::from(x) + 0.5) / 16.0, -4.0 + (f64::from(y) + 0.5) / 16.0, 4.0);
+ let l = delta.normalized().unwrap();
+ expected += surface.brdf(Vec3::Z, Vec3::Z, l).unwrap().x * l.z * l.z / delta.len2() * 64.0 / 16384.0;
+ }
+ }
+ for (thin, enabled, depth) in [(true, true, 2), (true, true, 4), (true, false, 4), (false, true, 1), (false, true, 4), (false, false, 4)] {
+ let mut scene = glass_slab(thin);
+ scene.meshes[0].surface = Some(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.0).unwrap());
+ scene.meshes[0].transmission =
+ Some(solidcraft_render::transmission::Transmission::new(Vec3::ZERO, thin.then_some(0.0)).unwrap().with_shadow_transmission(enabled));
+ scene.meshes.push(receiver.clone());
+ let options = JobOptions {
+ samples: 4096,
+ max_depth: depth,
+ seed: 37,
+ lighting: Some(StudioLighting { sun: None, environment: [0.0; 3], area_lights: AreaLights::new(&[light]).unwrap() }),
+ ..Default::default()
+ };
+ let mut image = request(1);
+ image.camera.target = Vec3::new(0.0, 0.0, -2.0);
+ image.camera.distance = 0.1;
+ image.camera.fov = 0.001;
+ let mut task = Task::new(executor.context.clone(), scene, image, options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let actual = f64::from(task.read_linear().unwrap()[0][0]);
+ assert!((actual - expected).abs() < 0.08 * expected, "thin={thin}, enabled={enabled}, depth={depth}: {actual} vs {expected}");
+ }
+}
+
+#[test]
+fn gpu_absorbing_two_sheet_mis_matches_f64_quadrature() {
+ use solidcraft_render::job::{AreaLight, AreaLights, StudioLighting};
+ let Some(executor) = executor() else { return };
+ let surface = white();
+ // A tiny receiver excludes sheet-reflection returns from this direct-only oracle.
+ // Its half-width still exceeds the primary ray footprint by two orders of magnitude.
+ let receiver = ProductMesh {
+ name: "shadow MIS receiver".into(),
+ mesh: Arc::new(Mesh {
+ positions: vec![Vec3::new(-0.01, -0.01, -2.0), Vec3::new(0.01, -0.01, -2.0), Vec3::new(0.01, 0.01, -2.0), Vec3::new(-0.01, 0.01, -2.0)],
+ normals: vec![Vec3::Z; 4],
+ triangles: vec![[0, 1, 2], [0, 2, 3]],
+ tri_face: vec![0, 0],
+ ..Default::default()
+ }),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(surface),
+ transmission: None,
+ faces: vec![],
+ };
+ let light = AreaLight { center: [0.0, 0.0, 2.0], u: [4.0, 0.0, 0.0], v: [0.0, -4.0, 0.0], radiance: [1.0; 3] };
+ let optics = solidcraft_render::transmission::Transmission::new(Vec3::new(0.2, 0.1, 0.05), Some(0.7)).unwrap();
+ let mut expected = 0.0;
+ for y in 0..128 {
+ for x in 0..128 {
+ let delta = Vec3::new(-4.0 + (f64::from(x) + 0.5) / 16.0, -4.0 + (f64::from(y) + 0.5) / 16.0, 4.0);
+ let l = delta.normalized().unwrap();
+ let transmission = solidcraft_render::transmission::slab(optics, 0.7, l.z, 1.0, 1.5).unwrap().1.x;
+ expected += transmission * transmission * surface.brdf(Vec3::Z, Vec3::Z, l).unwrap().x * l.z * l.z / delta.len2() * 64.0 / 16384.0;
+ }
+ }
+ for (thin, enabled, depth) in [(true, true, 1), (true, true, 4), (true, false, 4)] {
+ let mut scene = glass_slab(thin);
+ scene.meshes[0].transmission = Some(optics.with_shadow_transmission(enabled));
+ let mut second = scene.meshes[0].clone();
+ second.name = "second absorbing sheet".into();
+ for p in &mut Arc::make_mut(&mut second.mesh).positions {
+ p.z -= 1.0;
+ }
+ scene.meshes.push(second);
+ scene.meshes.push(receiver.clone());
+ let options = JobOptions {
+ samples: 4096,
+ max_depth: depth,
+ seed: 37,
+ lighting: Some(StudioLighting { sun: None, environment: [0.0; 3], area_lights: AreaLights::new(&[light]).unwrap() }),
+ ..Default::default()
+ };
+ let mut image = request(1);
+ image.camera.target = Vec3::new(0.0, 0.0, -2.0);
+ image.camera.distance = 0.1;
+ image.camera.fov = 0.001;
+ let mut task = Task::new(executor.context.clone(), scene, image, options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let actual = f64::from(task.read_linear().unwrap()[0][0]);
+ assert!((actual - expected).abs() < 0.08 * expected, "thin={thin}, enabled={enabled}, depth={depth}: {actual} vs {expected}");
+ }
+}
+
+#[test]
+fn gpu_hdr_and_sun_shadow_mis_preserve_index_matched_energy() {
+ use solidcraft_render::job::{StudioLighting, Sun};
+ use solidcraft_render::lighting::environment::EnvironmentSource;
+ let Some(executor) = executor() else { return };
+ let sun = Sun { direction: [0.0, 0.0, 1.0], angular_radius_rad: 0.4, radiance: [3.0; 3] };
+ let mut sun_expected = 0.0;
+ for i in 0..4096 {
+ let z = 1.0 - (f64::from(i) + 0.5) / 4096.0 * (1.0 - sun.angular_radius_rad.cos());
+ let l = Vec3::new((1.0 - z * z).sqrt(), 0.0, z);
+ sun_expected += white().brdf(Vec3::Z, Vec3::Z, l).unwrap().x * z * 3.0 * sun.solid_angle() / 4096.0;
+ }
+ // The original HDR has unit radiance everywhere. With IOR one the receiver
+ // is pure diffuse; retain the independent directional-albedo quadrature.
+ let mut hdr_expected = 0.0;
+ for i in 0..256 {
+ let z = (f64::from(i) + 0.5) / 256.0;
+ for j in 0..256 {
+ let phi = (f64::from(j) + 0.5) / 256.0 * std::f64::consts::TAU;
+ let l = Vec3::new((1.0 - z * z).sqrt() * phi.cos(), (1.0 - z * z).sqrt() * phi.sin(), z);
+ hdr_expected += white().brdf(Vec3::Z, Vec3::Z, l).unwrap().x * z * std::f64::consts::TAU / 65536.0;
+ }
+ }
+ for solar in [false, true] {
+ for (thin, depth) in [(true, 2), (true, 4), (false, 1), (false, 4)] {
+ let mut scene = glass_slab(thin);
+ scene.meshes[0].surface = Some(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.0).unwrap());
+ scene.meshes[0].transmission =
+ Some(solidcraft_render::transmission::Transmission::new(Vec3::ZERO, thin.then_some(0.0)).unwrap().with_shadow_transmission(true));
+ let mut receiver = environment_plane().meshes.remove(0);
+ for p in &mut Arc::make_mut(&mut receiver.mesh).positions {
+ p.z -= 2.0;
+ }
+ scene.meshes.push(receiver);
+ scene.bounds = scene.meshes.iter().fold(Aabb3::EMPTY, |a, m| a.union(&m.mesh.bounds()));
+ let mut image = request(1);
+ image.camera.target = Vec3::new(0.0, 0.0, -2.0);
+ image.camera.distance = 0.1;
+ image.camera.fov = 0.001;
+ if !solar {
+ image.environment = Some(Arc::new(EnvironmentSource::hdr(original_hdr(), 0.3, 1.0, false).unwrap()));
+ }
+ let options = JobOptions {
+ samples: 4096,
+ max_depth: depth,
+ seed: 37,
+ lighting: Some(StudioLighting { sun: solar.then_some(sun), ..Default::default() }),
+ ..Default::default()
+ };
+ let mut task = Task::new(executor.context.clone(), scene, image, options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let actual = f64::from(task.read_linear().unwrap()[0][0]);
+ let expected = if solar { sun_expected } else { hdr_expected };
+ assert!((actual - expected).abs() < 0.07 * expected, "sun={solar}, thin={thin}, depth={depth}: {actual} vs {expected}");
+ }
+ }
+}
+
+fn texture_fixture(frame: solidcraft_render::job::textures::PlanarFrame) -> Arc<solidcraft_render::job::textures::RuntimeTextures> {
+ use image::ImageEncoder;
+ use solidcraft_render::{
+ job::textures::{RuntimeTextures, TextureBinding, TextureMap},
+ texture_input::MapRole,
+ };
+ let map = |pixels: &[u8], role| {
+ let mut bytes = Vec::new();
+ image::codecs::png::PngEncoder::new(&mut bytes).write_image(pixels, 2, 2, image::ExtendedColorType::Rgba8).unwrap();
+ TextureMap::new(bytes, role).unwrap()
+ };
+ Arc::new(
+ RuntimeTextures::new(vec![TextureBinding {
+ body_index: 0,
+ body_name: "original sphere".into(),
+ frame,
+ normal_strength: 0.75,
+ base_color: Some(map(&[128, 64, 255, 0, 255, 0, 32, 255, 64, 128, 192, 0, 0, 255, 128, 255], MapRole::BaseColor)),
+ normal: Some(map(&[128, 128, 255, 0, 192, 128, 224, 255, 128, 192, 224, 0, 64, 96, 224, 255], MapRole::NormalOpenGl)),
+ }])
+ .unwrap(),
+ )
+}
+#[test]
+fn texture_admission_rejects_glass_and_stale_identity_and_honors_cancellation() {
+ use solidcraft_render::job::textures::PlanarFrame;
+ let source = texture_fixture(PlanarFrame { origin: [0.; 3], u: [1., 0., 0.], v: [0., 1., 0.] });
+ let mut input = request(2);
+ input.textures = Some(source.clone());
+ let mut scene = sphere(white());
+ let plain = admission(&scene, &request(2), JobOptions::default()).unwrap();
+ let textured = admission(&scene, &input, JobOptions::default()).unwrap();
+ assert_eq!(textured.preparation_bytes - plain.preparation_bytes, source.working_bytes());
+ assert!(solidcraft_render::job::admit(&scene, &input).is_err());
+ let cancel = CancelToken::default();
+ cancel.cancel();
+ assert_eq!(textures::flatten(Some(&source), 1, Vec3::ZERO, &cancel).unwrap_err().code, ErrorCode::Cancelled);
+ scene.meshes[0].name = "stale".into();
+ assert!(admission(&scene, &input, JobOptions::default()).is_err());
+ scene.meshes[0].name = "original sphere".into();
+ scene.meshes[0].transmission = Some(clear_glass());
+ assert!(admission(&scene, &input, JobOptions::default()).is_err());
+}
+#[test]
+fn gpu_planar_color_and_normal_maps_match_cpu_sampling_oracle() {
+ use solidcraft_render::job::textures::{PlanarFrame, sample_map};
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("texture_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for handed in [1., -1.] {
+ let frame = PlanarFrame { origin: [0.; 3], u: [2., 0., 0.], v: [0., 2. * handed, 0.] };
+ let source = texture_fixture(frame);
+ let binding = &source.bindings()[0];
+ let base = binding.base_color.as_ref().unwrap().decode(&CancelToken::default()).unwrap();
+ let normals = binding.normal.as_ref().unwrap().decode(&CancelToken::default()).unwrap();
+ for point in [Vec3::new(0.5, 0.5, 0.), Vec3::new(-0.25, 1.125, 0.), Vec3::new(0., 0., 0.)] {
+ let mut input = request(2);
+ input.textures = Some(source.clone());
+ let mut task = Task::new(context.clone(), sphere(white()), input, JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, point, 0.);
+ scene::vector(&mut params, Vec3::ZERO, 0.);
+ scene::vector(&mut params, Vec3::Z, 0.);
+ scene::vector(&mut params, Vec3::Z, 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let actual = task.read_linear().unwrap();
+ let uv = frame.uv(point).unwrap();
+ let expected = sample_map(&base, [2, 2], uv).unwrap();
+ let mapped = frame.mapped_normal(Vec3::Z, Vec3::Z, sample_map(&normals, [2, 2], uv).unwrap(), 0.75).unwrap();
+ for (a, b) in actual[0].iter().zip(expected) {
+ assert!((f64::from(*a) - b).abs() < 2e-6, "color {actual:?} vs {expected:?}");
+ }
+ for (a, b) in actual[1].iter().zip([mapped.x + 2., mapped.y + 2., mapped.z + 2.]) {
+ assert!((f64::from(*a) - b).abs() < 3e-6, "normal {actual:?} vs {mapped:?}");
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_finite_emitter_inside_solid_retains_entry_radiance_eta() {
+ use solidcraft_render::job::{AreaLight, AreaLights, StudioLighting};
+ let Some(executor) = executor() else { return };
+ let surface = white();
+ let receiver = ProductMesh {
+ name: "shadow MIS receiver".into(),
+ mesh: Arc::new(Mesh {
+ positions: vec![Vec3::new(-0.01, -0.01, -2.0), Vec3::new(0.01, -0.01, -2.0), Vec3::new(0.01, 0.01, -2.0), Vec3::new(-0.01, 0.01, -2.0)],
+ normals: vec![Vec3::Z; 4],
+ triangles: vec![[0, 1, 2], [0, 2, 3]],
+ tri_face: vec![0, 0],
+ ..Default::default()
+ }),
+ color: [255; 3],
+ opacity: 1.0,
+ surface: Some(surface),
+ transmission: None,
+ faces: vec![],
+ };
+ let light = AreaLight { center: [0.0, 0.0, 0.0], u: [9.0, 0.0, 0.0], v: [0.0, -9.0, 0.0], radiance: [1.0; 3] };
+ // Broad finite emitter makes edge/refraction disagreement small; the missing eta term is a 125% error.
+ let mut expected = 0.0;
+ for y in 0..128 {
+ for x in 0..128 {
+ let delta = Vec3::new(-9.0 + (f64::from(x) + 0.5) * 18.0 / 128.0, -9.0 + (f64::from(y) + 0.5) * 18.0 / 128.0, 2.0);
+ let l = delta.normalized().unwrap();
+ let r = solidcraft_render::transmission::fresnel(l.z, 1.0, 1.5).unwrap().reflectance();
+ expected += (1.0 - r) / 2.25 * surface.brdf(Vec3::Z, Vec3::Z, l).unwrap().x * l.z * l.z / delta.len2() * 324.0 / 16384.0;
+ }
+ }
+ for (thin, enabled, depth) in [(false, true, 1), (false, true, 4), (false, false, 4)] {
+ let mut scene = glass_slab(thin);
+ scene.meshes[0].surface = Some(OpaqueSurface::new(Vec3::ZERO, 0.0, 0.1, 1.5).unwrap());
+ scene.meshes[0].transmission =
+ Some(solidcraft_render::transmission::Transmission::new(Vec3::ZERO, thin.then_some(0.0)).unwrap().with_shadow_transmission(enabled));
+ scene.meshes.push(receiver.clone());
+ let options = JobOptions {
+ samples: 4096,
+ max_depth: depth,
+ seed: 37,
+ lighting: Some(StudioLighting { sun: None, environment: [0.0; 3], area_lights: AreaLights::new(&[light]).unwrap() }),
+ ..Default::default()
+ };
+ let mut image = request(1);
+ image.camera.target = Vec3::new(0.0, 0.0, -2.0);
+ image.camera.distance = 0.1;
+ image.camera.fov = 0.001;
+ let mut task = Task::new(executor.context.clone(), scene, image, options, CancelToken::default()).unwrap();
+ for _ in 0..options.samples {
+ task.complete_sample().unwrap();
+ }
+ let actual = f64::from(task.read_linear().unwrap()[0][0]);
+ assert!((actual - expected).abs() < 0.08 * expected, "thin={thin}, enabled={enabled}, depth={depth}: {actual} vs {expected}");
+ }
+}
+
+#[test]
+fn path_device_limits_require_six_storage_buffers_without_changing_raster_defaults() {
+ let mut supported = wgpu::Limits::downlevel_defaults();
+ assert_eq!(supported.max_storage_buffers_per_shader_stage, 4);
+ assert!(device_limits(supported.clone()).is_err());
+ supported.max_storage_buffers_per_shader_stage = 8;
+ let requested = device_limits(supported.clone()).unwrap();
+ let mut expected = wgpu::Limits::downlevel_defaults().using_resolution(supported);
+ expected.max_storage_buffers_per_shader_stage = 6;
+ assert_eq!(requested, expected);
+}
+
+#[test]
+fn gpu_secondary_closed_corner_exits_are_not_skipped() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("closed corner boundary oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("boundary_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for case in 0..3 {
+ let pyramid = case == 1;
+ let mut scene = glass_slab(false);
+ let (origin, direction) = if pyramid {
+ let mut mesh = Mesh::default();
+ let corners = [Vec3::new(-1., -1., 1.), Vec3::new(1., -1., 1.), Vec3::new(1., 1., 1.), Vec3::new(-1., 1., 1.)];
+ let tip = Vec3::new(0., 0., -1.);
+ let faces = [
+ [corners[0], corners[1], corners[2]],
+ [corners[0], corners[2], corners[3]],
+ [corners[1], corners[0], tip],
+ [corners[2], corners[1], tip],
+ [corners[3], corners[2], tip],
+ [corners[0], corners[3], tip],
+ ];
+ for face in faces {
+ let n = (face[1] - face[0]).cross(face[2] - face[0]).normalized().unwrap();
+ let first = mesh.positions.len() as u32;
+ mesh.positions.extend(face);
+ mesh.normals.extend([n; 3]);
+ mesh.triangles.push([first, first + 1, first + 2]);
+ mesh.tri_face.push(0);
+ }
+ scene.meshes[0].mesh = Arc::new(mesh);
+ scene.bounds = scene.meshes[0].mesh.bounds();
+ (Vec3::new(0.9999, 0., 2.), -Vec3::Z)
+ } else {
+ (Vec3::new(9.9999, if case == 2 { 9.9999 } else { 0. }, 2.), Vec3::new(1., 0., -1.).normalized().unwrap())
+ };
+ let mut task = Task::new(context.clone(), scene, request(2), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, origin, 0.);
+ scene::vector(&mut params, direction, 0.);
+ scene::vector(&mut params, Vec3::ZERO, 0.);
+ scene::vector(&mut params, -Vec3::Z, 0.);
+ scene::vector(&mut params, Vec3::new(0.001, 0., 0.), 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ let result = values[0];
+ let expected_distance = if pyramid { 0.0002 } else { 0.0001 * 2.0_f32.sqrt() };
+ assert!((values[1][0] - expected_distance).abs() < 3e-6, "case={case}: {:?}", values);
+ assert_eq!(result, if pyramid { [0., 0., 1., 1.] } else { [0., 1., 1., 1.] }, "pyramid={pyramid}");
+ }
+}
+
+#[test]
+fn gpu_triangle_bound_away_rejects_rounded_behind_origin_hit() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("positive triangle oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("positive_triangle_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ // Actual stored f32 tank-edge failure. Ray starts at the minimum x and moves
+ // away, yet the projected distance numerator previously rounded positive.
+ let vertices = [[218.38487_f32, -3.8715396, -86.], [220.27007, -2.9226143, 85.], [218.38487, -3.8715396, 85.]];
+ let origin = [218.38487_f32, -3.871542, -67.5458];
+ let direction = [-0.3121568_f32, -0.45083842, 0.8362433];
+ for axis in 0..3 {
+ for sign in [-1.0, 1.0] {
+ let transform =
+ |v: [f32; 3]| Vec3::new(f64::from(v[axis]) * sign, f64::from(v[(axis + 1) % 3]) * sign, f64::from(v[(axis + 2) % 3]) * sign);
+ let points = vertices.map(transform);
+ let d = transform(direction);
+ let n = (points[1] - points[0]).cross(points[2] - points[0]).normalized().unwrap();
+ let mesh = Mesh { positions: points.to_vec(), normals: vec![n; 3], triangles: vec![[0, 1, 2]], tri_face: vec![0], ..Default::default() };
+ let mut scene = sphere_grid(white(), 2, 3);
+ scene.bounds = mesh.bounds();
+ scene.meshes[0].mesh = Arc::new(mesh);
+ for positive in [false, true] {
+ // Close positive intersections remain admitted; no epsilon is used.
+ let o = if positive { (points[0] + points[1] + points[2]) / 3.0 - d * 0.001 } else { transform(origin) };
+ let mut task = Task::new(context.clone(), scene.clone(), request(1), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, o, 0.);
+ scene::vector(&mut params, d, 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ assert_eq!(values[0][0], if positive { 1.0 } else { 0.0 }, "axis={axis} sign={sign} positive={positive}");
+ }
+ }
+ }
+}
+
+#[test]
+fn gpu_oblique_coplanar_grazing_reflection_does_not_rehit() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("coplanar boundary oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("coplanar_boundary_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let a = Vec3::new(f64::from(191.3_f32), f64::from(79.2_f32), f64::from(84.7_f32));
+ let points = [a, a + Vec3::new(8., 0., 2.), a + Vec3::new(8., 8., 6.), a + Vec3::new(0., 8., 4.)];
+ let n = Vec3::new(-0.25, -0.5, 1.).normalized().unwrap();
+ let d = Vec3::new(f64::from(-0.69632584_f32), f64::from(0.69628024_f32), f64::from(0.17413844_f32));
+ assert!(n.dot(d) > 0.0, "outward reflection");
+ let mesh =
+ Mesh { positions: points.to_vec(), normals: vec![n; 4], triangles: vec![[0, 1, 2], [0, 2, 3]], tri_face: vec![0, 0], ..Default::default() };
+ let mut scene = sphere_grid(white(), 2, 3);
+ scene.bounds = mesh.bounds();
+ scene.meshes[0].mesh = Arc::new(mesh);
+ let mut task = Task::new(context.clone(), scene, request(2), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, Vec3::new(f64::from(1.734274e-6_f32), f64::from(0.23548841_f32), 0.), 0.);
+ scene::vector(&mut params, d, 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ // A source point on this exact stored plane and an outward ray cannot hit
+ // its adjacent coplanar triangle at any strictly positive distance.
+ assert_eq!(values[0][0], 0.0, "hit/distance={:?}, reconstructed={:?}", values[0], values[1]);
+}
+
+#[test]
+fn gpu_shadow_closed_corner_keeps_short_exit_segment() {
+ let Some(executor) = executor() else { return };
+ let mut scene = glass_slab(false);
+ let optics = scene.meshes[0].transmission.unwrap().with_shadow_transmission(true);
+ scene.meshes[0].transmission = Some(optics);
+ let cosine = std::f64::consts::FRAC_1_SQRT_2;
+ let actual = shadow_probe(&executor.context, scene, Vec3::new(8.4999, 0., 2.), Vec3::new(cosine, 0., -cosine), 4.);
+ let expected = solidcraft_render::transmission::solid_shadow(optics, 0.0001 * 2.0_f64.sqrt(), cosine, cosine, 1.5).unwrap();
+ assert_eq!(actual[1][1], 2.0, "{actual:?}");
+ for (a, b) in actual[0].iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 2e-5, "{actual:?} vs {expected:?}");
+ }
+}
+
+#[test]
+fn gpu_shadow_endpoint_near_interfaces_uses_true_distance() {
+ let Some(executor) = executor() else { return };
+ let mut scene = glass_slab(false);
+ let optics = scene.meshes[0].transmission.unwrap().with_shadow_transmission(true);
+ scene.meshes[0].transmission = Some(optics);
+ // shadow_probe deliberately uses epsilon .01. Both offsets are smaller
+ // than its old 2epsilon cutoff, and must still classify the actual endpoint.
+ for (limit, length, factor, crossings) in
+ [(1.495, 0.0, 1.0, 0.0), (1.505, 0.005, 0.96 / 2.25, 1.0), (2.495, 0.995, 0.96 / 2.25, 1.0), (2.505, 1.0, 0.96 * 0.96, 2.0)]
+ {
+ let actual = shadow_probe(&executor.context, scene.clone(), Vec3::new(0., 0., 2.), -Vec3::Z, limit);
+ let expected = optics.attenuation(length).unwrap() * factor;
+ assert_eq!(actual[1][1], crossings, "limit={limit}: {actual:?}");
+ for (a, b) in actual[0].iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - b).abs() < 2e-5, "limit={limit}: {actual:?} vs {expected:?}");
+ }
+ }
+}
+
+#[test]
+fn gpu_long_ray_thin_corner_orders_entry_before_exit() {
+ let Some(executor) = executor() else { return };
+ let origin = Vec3::new(f64::from(f32::from_bits(0x43ad5626)), f64::from(f32::from_bits(0x44737912)), f64::from(f32::from_bits(0xc2dd2710)));
+ let direction = Vec3::new(f64::from(f32::from_bits(0xbe341340)), f64::from(f32::from_bits(0xbf762fdb)), f64::from(f32::from_bits(0x3e577470)));
+ // Captured stored-f32 tank side entry and top exit. Independent f64 plane
+ // distances are 929.5224413721813 and 929.5225421330013 respectively.
+ let side = [Vec3::new(243., 80., -86.), Vec3::new(157., 80., 85.), Vec3::new(243., 80., 85.)];
+ let top = [Vec3::new(157., 80., 85.), Vec3::new(160., 77., 85.), Vec3::new(243., 80., 85.)];
+ assert_entry_before_exit(&executor.context, origin, direction, side, top);
+}
+
+#[test]
+fn gpu_camera_ray_sharp_rim_tie_orders_entry_before_exit() {
+ let Some(executor) = executor() else { return };
+ let origin = Vec3::new(f64::from(f32::from_bits(0xc409ad54)), f64::from(f32::from_bits(0xc45c5451)), f64::from(f32::from_bits(0x44160000)));
+ let direction = Vec3::new(f64::from(f32::from_bits(0x3eac85fe)), f64::from(f32::from_bits(0x3f3d52db)), f64::from(f32::from_bits(0xbf152b54)));
+ // Captured 64-spp coffee camera ray across the bin rim. Exact ray
+ // parameters are 1124.0922606444 (entry) and 1124.0923198562 (exit):
+ // closer than one f32 ULP, and both rounded to one scaled distance.
+ let bottom = [Vec3::new(-152., -50., -55.), Vec3::new(-212., -50., -55.), Vec3::new(-182., -53., -55.)];
+ let side = [Vec3::new(-152., -50., -55.), Vec3::new(-152., -50., -124.), Vec3::new(-212., -50., -55.)];
+ assert_entry_before_exit(&executor.context, origin, direction, bottom, side);
+}
+
+#[test]
+fn gpu_exact_rim_tie_prefers_entry_from_outside() {
+ let Some(executor) = executor() else { return };
+ // The ray crosses the shared rim edge itself: both faces report the same
+ // exact depth, so only the medium-state tie preference can order them.
+ let top = [Vec3::new(0., 0., 0.), Vec3::new(0.5, -1., 0.), Vec3::new(1., 0., 0.)];
+ let side = [Vec3::new(0., 0., 0.), Vec3::new(1., 0., 0.), Vec3::new(0.5, 0., -1.)];
+ assert_entry_before_exit(&executor.context, Vec3::new(0.25, -4., 4.), Vec3::new(0., 1., -1.), top, side);
+}
+
+fn assert_entry_before_exit(context: &Arc<Context>, origin: Vec3, direction: Vec3, entry: [Vec3; 3], exit: [Vec3; 3]) {
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("long-ray ordering oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("ordering_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ for permutation in [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]] {
+ let odd = (permutation[0] > permutation[1]) ^ (permutation[0] > permutation[2]) ^ (permutation[1] > permutation[2]);
+ for reflection in 0..8_u32 {
+ let sign = |axis: u32| if reflection & (1 << axis) == 0 { 1.0 } else { -1.0 };
+ let transform = |v: Vec3| {
+ let a = [v.x, v.y, v.z];
+ Vec3::new(a[permutation[0]] * sign(0), a[permutation[1]] * sign(1), a[permutation[2]] * sign(2))
+ };
+ let invert = odd ^ (reflection.count_ones() % 2 != 0);
+ for reverse in [false, true] {
+ let mut mesh = Mesh::default();
+ for face in if reverse { [exit, entry] } else { [entry, exit] } {
+ let mut face = face.map(transform);
+ if invert {
+ face.swap(1, 2);
+ }
+ let n = (face[1] - face[0]).cross(face[2] - face[0]).normalized().unwrap();
+ let i = mesh.positions.len() as u32;
+ mesh.positions.extend(face);
+ mesh.normals.extend([n; 3]);
+ mesh.triangles.push([i, i + 1, i + 2]);
+ mesh.tri_face.push(0);
+ }
+ let mut scene = sphere_grid(white(), 2, 3);
+ scene.bounds = mesh.bounds();
+ scene.meshes[0].mesh = Arc::new(mesh);
+ let mut task = Task::new(context.clone(), scene, request(2), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, transform(origin), 0.);
+ scene::vector(&mut params, transform(direction), 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ assert_eq!(
+ values[0][0],
+ if reverse { 1.0 } else { 0.0 },
+ "permutation={permutation:?}, reflection={reflection}, reverse={reverse}, best/candidates={values:?}"
+ );
+ assert_eq!(values[1][1], 1.0, "candidate0 rejected: {values:?}");
+ assert_eq!(values[2][1], 1.0, "candidate1 rejected: {values:?}");
+ }
+ }
+ }
+}
+#[test]
+fn gpu_far_rib_reentry_near_an_edge_is_not_lost_between_paths() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context
+ .device
+ .create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("rib re-entry oracle"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("continuation_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let bits = |x: u32, y: u32, z: u32| Vec3::new(f64::from(f32::from_bits(x)), f64::from(f32::from_bits(y)), f64::from(f32::from_bits(z)));
+ // Captured stored-f32 faces of the coffee bin's ribbed wall: the producing
+ // face, its nearby neighbour, the far re-entry face sharing the neighbour's
+ // edge, and the next exit. The ray leaves the producing face and truly
+ // re-enters 2.615 mm later, inside the re-entry face but very close to the
+ // shared edge; it then exits 17.529 mm along.
+ let faces = [
+ [bits(0x438a6e62, 0x4175ca91, 0xc2860000), bits(0x4389b018, 0x416145f8, 0x42c80000), bits(0x438a6e62, 0x4175ca91, 0x42c80000)],
+ [bits(0x438b2463, 0x4185b9d0, 0xc2860000), bits(0x438a6e62, 0x4175ca91, 0x42c80000), bits(0x438b2463, 0x4185b9d0, 0x42c80000)],
+ [bits(0x438b2463, 0x4185b9d0, 0xc2860000), bits(0x438b2463, 0x4185b9d0, 0x42c80000), bits(0x438bd1ab, 0x419119e4, 0xc2860000)],
+ [bits(0x43906f8f, 0x41d4ebca, 0xc28e0000), bits(0x43906f8f, 0x41d4ebca, 0x42c80000), bits(0x438ff618, 0x41c5d6eb, 0xc28e0000)],
+ ];
+ let mut mesh = Mesh::default();
+ for face in faces {
+ let n = (face[1] - face[0]).cross(face[2] - face[0]).normalized().unwrap();
+ let i = mesh.positions.len() as u32;
+ mesh.positions.extend(face);
+ mesh.normals.extend([n; 3]);
+ mesh.triangles.push([i, i + 1, i + 2]);
+ mesh.tri_face.push(0);
+ }
+ let mut scene = sphere_grid(white(), 2, 3);
+ scene.bounds = mesh.bounds();
+ scene.meshes[0].mesh = Arc::new(mesh);
+ let mut task = Task::new(context.clone(), scene, request(2), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, bits(0x438a6e62, 0x4175ca91, 0xc2860000), 0.);
+ scene::vector(&mut params, bits(0xbedb21b8, 0xbebd05fd, 0x4295df13), 0.);
+ scene::vector(&mut params, bits(0x3f3519ed, 0x3f28acac, 0xbe82f446), 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ assert_eq!(values[0][0], 2.0, "hit/distance={:?}", values[0]);
+ assert!((f64::from(values[0][1]) - 2.615).abs() < 0.01, "hit/distance={:?}", values[0]);
+}
+#[test]
+fn gpu_entry_at_a_shared_edge_does_not_reenter_the_adjacent_face() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context
+ .device
+ .create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("edge entry oracle"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("continuation_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let bits = |x: u32, y: u32, z: u32| Vec3::new(f64::from(f32::from_bits(x)), f64::from(f32::from_bits(y)), f64::from(f32::from_bits(z)));
+ // Captured tumbler faces: a refracted ray entered the glass through the first
+ // face 8e-9 (barycentric) from its edge with the second. Its reconstructed
+ // start is 6.5e-9 mm outside both planes, so it met the second face from
+ // outside 1.1e-8 mm later: an "entry" while already inside. A cone to an
+ // apex behind both faces closes the captured pair into valid closed glass.
+ let a = bits(0x43050000, 0x42095be6, 0x42140000);
+ let b = bits(0x4304aef7, 0x4218aea0, 0x41b80000);
+ let c = bits(0x4303bd40, 0x4205b1dd, 0x41b80000);
+ let e = bits(0x4305c374, 0x421b114d, 0x42140000);
+ let f = Vec3::new(140.75, 34.75, 29.5);
+ let faces = [[c, a, b], [e, b, a], [a, c, f], [e, a, f], [b, e, f], [c, b, f]];
+ let mut mesh = Mesh::default();
+ for face in faces {
+ let n = (face[1] - face[0]).cross(face[2] - face[0]).normalized().unwrap();
+ let i = mesh.positions.len() as u32;
+ mesh.positions.extend(face);
+ mesh.normals.extend([n; 3]);
+ mesh.triangles.push([i, i + 1, i + 2]);
+ mesh.tri_face.push(0);
+ }
+ let mut scene = glass_slab(false);
+ scene.bounds = mesh.bounds();
+ scene.meshes[0].mesh = Arc::new(mesh);
+ let mut task = Task::new(context.clone(), scene, request(2), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, bits(0x43050000, 0x42095be6, 0x42140000), 1.);
+ scene::vector(&mut params, bits(0xbda74978, 0x3f7d0fd4, 0xc06735c3), 0.);
+ scene::vector(&mut params, bits(0x3f4ff9cf, 0x3f0c3c0f, 0xbe4c997d), 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ // The ray must leave through one of the closing faces, at a real distance.
+ assert!(values[0][0] >= 2.0 && values[0][0] < 6.0, "hit/distance={:?}", values[0]);
+ assert!(values[0][1] > 1e-3, "hit/distance={:?}", values[0]);
+}
+#[test]
+fn gpu_long_ray_near_corner_refraction_keeps_real_exit() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("refracted corner oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("refracted_corner_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let origin = Vec3::new(f64::from(f32::from_bits(0x43ad5626)), f64::from(f32::from_bits(0x44737912)), f64::from(f32::from_bits(0xc2dd2710)));
+ let direction = Vec3::new(f64::from(f32::from_bits(0xbe341340)), f64::from(f32::from_bits(0xbf762fdb)), f64::from(f32::from_bits(0x3e577470)));
+ let ior = f64::from(1.586_f32);
+ let ni = direction.x / ior;
+ let nk = direction.z / ior;
+ let refracted = Vec3::new(ni, -(1.0 - ni * ni - nk * nk).sqrt(), nk);
+ let entry_distance = (80.0 - origin.y) / direction.y;
+ let entry_z = origin.z + direction.z * entry_distance;
+ let exit_distance = (85.0 - entry_z) / refracted.z;
+ // Independent f64 plane/refraction oracle: true entry clearance is ~21um.
+ assert!(85.0 - entry_z > 0.00002 && 85.0 - entry_z < 0.000022);
+ let faces = [
+ [[157., 0., 85.], [243., 0., 85.], [243., 80., 85.], [157., 80., 85.]],
+ [[157., 80., -86.], [243., 80., -86.], [243., 0., -86.], [157., 0., -86.]],
+ [[243., 80., -86.], [157., 80., -86.], [157., 80., 85.], [243., 80., 85.]],
+ [[157., 0., -86.], [243., 0., -86.], [243., 0., 85.], [157., 0., 85.]],
+ [[243., 0., -86.], [243., 80., -86.], [243., 80., 85.], [243., 0., 85.]],
+ [[157., 80., -86.], [157., 0., -86.], [157., 0., 85.], [157., 80., 85.]],
+ ];
+ for permutation in [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]] {
+ let odd = (permutation[0] > permutation[1]) ^ (permutation[0] > permutation[2]) ^ (permutation[1] > permutation[2]);
+ for reflection in 0..8_u32 {
+ let sign = |axis: u32| if reflection & (1 << axis) == 0 { 1.0 } else { -1.0 };
+ let transform = |v: Vec3| {
+ let a = [v.x, v.y, v.z];
+ Vec3::new(a[permutation[0]] * sign(0), a[permutation[1]] * sign(1), a[permutation[2]] * sign(2))
+ };
+ let invert = odd ^ (reflection.count_ones() % 2 != 0);
+ let mut mesh = Mesh::default();
+ for face in faces {
+ for indices in [[0, 1, 2], [0, 2, 3]] {
+ let mut p = indices.map(|i| {
+ let a = face[i];
+ transform(Vec3::new(a[0], a[1], a[2]))
+ });
+ if invert {
+ p.swap(1, 2);
+ }
+ let n = (p[1] - p[0]).cross(p[2] - p[0]).normalized().unwrap();
+ let i = mesh.positions.len() as u32;
+ mesh.positions.extend(p);
+ mesh.normals.extend([n; 3]);
+ mesh.triangles.push([i, i + 1, i + 2]);
+ mesh.tri_face.push(0);
+ }
+ }
+ let mut scene = glass_slab(false);
+ scene.bounds = mesh.bounds();
+ scene.meshes[0].mesh = Arc::new(mesh);
+ scene.meshes[0].surface = Some(OpaqueSurface::new(Vec3::ZERO, 0., 0.1, ior).unwrap());
+ scene.meshes[0].transmission = Some(solidcraft_render::transmission::Transmission::new(Vec3::ZERO, None).unwrap());
+ let mut task = Task::new(context.clone(), scene, request(2), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, transform(origin), 0.);
+ scene::vector(&mut params, transform(direction), 0.);
+ scene::vector(&mut params, Vec3::ZERO, 0.);
+ scene::vector(&mut params, Vec3::ZERO, 0.);
+ scene::vector(&mut params, Vec3::new(0.00084, 0., 0.), 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ assert_eq!(values[0], [1.; 4], "permutation={permutation:?} reflection={reflection}: {values:?}");
+ let z_axis = permutation.iter().position(|axis| *axis == 2).unwrap();
+ assert!(values[2][z_axis] < 85.0, "rounded entry onto top edge: {values:?}");
+ // Two position ULP at z85, propagated through the refracted angle.
+ let tolerance = 2.0 * f64::from(f32::from_bits(85.0_f32.to_bits() + 1) - 85.0) / refracted.z;
+ assert!(
+ (f64::from(values[1][0]) - exit_distance).abs() < tolerance,
+ "distance={:?} expected={exit_distance} tolerance={tolerance}",
+ values[1]
+ );
+ let expected = transform(refracted);
+ for (a, b) in values[3].iter().zip([expected.x, expected.y, expected.z]) {
+ assert!((f64::from(*a) - 2.0 - b).abs() < 2e-6);
+ }
+ }
+ }
+}
+#[test]
+fn gpu_rib_total_internal_reflection_retains_origin_residual() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context
+ .device
+ .create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("rib residual oracle"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("rib_residual_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let a = Vec3::new(-162., -53., -127.);
+ let b = Vec3::new(f64::from(-163.7_f32), -55., -55.);
+ let c = Vec3::new(f64::from(-163.7_f32), -55., -127.);
+ let other = Vec3::new(-165.5, -53., -55.);
+ let bary = Vec3::new(f64::from(f32::from_bits(0x369bafd4)), f64::from(f32::from_bits(0x3f59c40b)), f64::from(f32::from_bits(0x3e18ee9d)));
+ let incoming = Vec3::new(f64::from(f32::from_bits(0xbeba12cc)), f64::from(f32::from_bits(0xbf6e1a19)), f64::from(f32::from_bits(0xbd5b2b1e)));
+ // These are captured GPU barycentrics, not an idealized primary-ray hit.
+ let point = b + (a - b) * bary.x + (c - b) * bary.z;
+ let normal = (b - a).cross(c - a).normalized().unwrap();
+ let outgoing = incoming - normal * (2.0 * incoming.dot(normal));
+ let exit_normal = (other - b).cross(c - b).normalized().unwrap();
+ let expected = -(point - b).dot(exit_normal) / outgoing.dot(exit_normal);
+ assert!(expected > 1e-5 && expected < 1.5e-5);
+ let cross_section = [[-162., -53.], [f64::from(-163.7_f32), -55.], [-165.5, -53.]];
+ let mut faces = Vec::new();
+ let lower = cross_section.map(|p| Vec3::new(p[0], p[1], -127.));
+ let upper = cross_section.map(|p| Vec3::new(p[0], p[1], -55.));
+ faces.push(lower);
+ faces.push([upper[0], upper[2], upper[1]]);
+ for i in 0..3 {
+ let j = (i + 1) % 3;
+ faces.push([lower[i], upper[i], upper[j]]);
+ faces.push([lower[i], upper[j], lower[j]]);
+ }
+ for permutation in [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]] {
+ let odd = (permutation[0] > permutation[1]) ^ (permutation[0] > permutation[2]) ^ (permutation[1] > permutation[2]);
+ for reflection in 0..8_u32 {
+ let sign = |axis: u32| if reflection & (1 << axis) == 0 { 1.0 } else { -1.0 };
+ let transform = |v: Vec3| {
+ let a = [v.x, v.y, v.z];
+ Vec3::new(a[permutation[0]] * sign(0), a[permutation[1]] * sign(1), a[permutation[2]] * sign(2))
+ };
+ let invert = odd ^ (reflection.count_ones() % 2 != 0);
+ let mut mesh = Mesh::default();
+ for face in &faces {
+ let mut p = face.map(transform);
+ if invert {
+ p.swap(1, 2);
+ }
+ let n = (p[1] - p[0]).cross(p[2] - p[0]).normalized().unwrap();
+ let i = mesh.positions.len() as u32;
+ mesh.positions.extend(p);
+ mesh.normals.extend([n; 3]);
+ mesh.triangles.push([i, i + 1, i + 2]);
+ mesh.tri_face.push(0);
+ }
+ let mut scene = glass_slab(false);
+ scene.bounds = mesh.bounds();
+ scene.meshes[0].mesh = Arc::new(mesh);
+ scene.meshes[0].surface = Some(OpaqueSurface::new(Vec3::ZERO, 0., 0.1, f64::from(1.49_f32)).unwrap());
+ scene.meshes[0].transmission = Some(solidcraft_render::transmission::Transmission::new(Vec3::ZERO, None).unwrap());
+ let mut task = Task::new(context.clone(), scene, request(2), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut params = vec![0; 32];
+ scene::vector(&mut params, transform(a), 0.);
+ scene::vector(&mut params, transform(if invert { c } else { b }), 0.);
+ scene::vector(&mut params, transform(if invert { b } else { c }), 0.);
+ scene::vector(&mut params, transform(incoming), 0.);
+ scene::vector(&mut params, Vec3::new(0.00084, 0., 0.), 0.);
+ scene::vector(&mut params, if invert { Vec3::new(bary.x, bary.z, bary.y) } else { bary }, 0.);
+ context.queue.write_buffer(&task.uniform, 0, &params);
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ assert_eq!(values[0], [0., 1., 1., 1.], "permutation={permutation:?} reflection={reflection}: {values:?}");
+ assert_eq!(values[1][1], 1.0, "must be TIR: {values:?}");
+ assert!((f64::from(values[1][0]) - expected).abs() < 2e-7, "expected={expected}: {values:?}");
+ }
+ }
+}
+#[test]
+fn gpu_integer_binary32_add_sub_matches_hardware_bits() {
+ use wgpu::util::DeviceExt;
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let mut pairs = Vec::new();
+ let fractions = [0, 1, 0x3fffff, 0x400000, 0x400001, 0x7ffffe, 0x7fffff];
+ for exponent in [0u32, 1, 2, 23, 24, 25, 31, 32, 63, 126, 127, 128, 253, 254, 255] {
+ for gap in [0, 1, 23, 24, 25, 31, 32, 63, 254] {
+ for a_fraction in fractions {
+ for b_fraction in fractions {
+ let a = exponent << 23 | a_fraction;
+ let b = exponent.saturating_sub(gap) << 23 | b_fraction;
+ pairs.extend([[a, b], [a ^ 0x80000000, b], [b, a], [b, a ^ 0x80000000]]);
+ }
+ }
+ }
+ }
+ pairs.extend([[0x80000000, 0x80000000], [0, 0x80000000], [1, 0x80000001]]);
+ let mut state = 0x9e3779b9u32;
+ while pairs.len() < 65536 {
+ state = state.wrapping_mul(1664525).wrapping_add(1013904223);
+ let a = state;
+ state = state.wrapping_mul(1664525).wrapping_add(1013904223);
+ pairs.push([a, state]);
+ }
+ assert_eq!(pairs.len(), 65536);
+ let mut bytes = Vec::with_capacity(4 + pairs.len() * 8);
+ bytes.extend((pairs.len() as u32).to_le_bytes());
+ for pair in &pairs {
+ for word in pair {
+ bytes.extend(word.to_le_bytes());
+ }
+ }
+ let input = context.device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
+ label: Some("integer binary32 inputs"),
+ contents: &bytes,
+ usage: wgpu::BufferUsages::STORAGE,
+ });
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("integer binary32 oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: None,
+ module: &shader,
+ entry_point: Some("integer_float_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let mut task = Task::new(context.clone(), glass_slab(false), request(256), JobOptions::default(), CancelToken::default()).unwrap();
+ let bind = context.device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: Some("integer binary32 oracle"),
+ layout: &pipeline.get_bind_group_layout(0),
+ entries: &[
+ wgpu::BindGroupEntry { binding: 1, resource: input.as_entire_binding() },
+ wgpu::BindGroupEntry { binding: 3, resource: task.accumulation.as_entire_binding() },
+ ],
+ });
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &bind, &[]);
+ pass.dispatch_workgroups(1024, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ let bits = |value: f32| if value.is_nan() { 0x7fc00000 } else { value.to_bits() };
+ for (i, ([a, b], value)) in pairs.iter().zip(values).enumerate() {
+ let a_float = f32::from_bits(*a);
+ let b_float = f32::from_bits(*b);
+ let sum = value[0] as u32 | (value[1] as u32) << 16;
+ let difference = value[2] as u32 | (value[3] as u32) << 16;
+ assert_eq!(sum, bits(a_float + b_float), "sum index={i} a={a:08x} b={b:08x}");
+ assert_eq!(difference, bits(a_float - b_float), "difference index={i} a={a:08x} b={b:08x}");
+ }
+}
+#[test]
+fn gpu_emitter_short_segment_beer_and_area_pdf() {
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("short emitter segment oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let layout = context.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: None,
+ bind_group_layouts: &[Some(&context.layout)],
+ immediate_size: 0,
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: Some(&layout),
+ module: &shader,
+ entry_point: Some("emitter_segment_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let mut task = Task::new(context.clone(), glass_slab(false), request(1), JobOptions::default(), CancelToken::default()).unwrap();
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &task.bind, &[]);
+ pass.dispatch_workgroups(1, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let result = task.read_linear().unwrap()[0];
+ let ray = Vec3::new(f64::from(0.6f32), 0., f64::from(0.8f32));
+ let distance = f64::from(0.00001f32);
+ let length = ray.len() * distance;
+ let cosine = ray.z / ray.len();
+ let expected = [length, (-5000. * length).exp(), length * length / (16. * cosine)];
+ for i in 0..3 {
+ assert!((f64::from(result[i]) / expected[i] - 1.).abs() < 2e-6, "channel={i} expected={expected:?} result={result:?}");
+ }
+}
+#[test]
+fn gpu_integer_relative_fast_paths_match_ordered_rounding() {
+ use wgpu::util::DeviceExt;
+ let Some(executor) = executor() else { return };
+ let context = &executor.context;
+ let mut quads = Vec::new();
+ let fractions = [0, 1, 0x3fffff, 0x400000, 0x400001, 0x7ffffe, 0x7fffff];
+ for exponent in [0u32, 1, 2, 23, 24, 25, 126, 127, 128, 253, 254, 255] {
+ for fraction in fractions {
+ let a = exponent << 23 | fraction;
+ for b in [a, a ^ 1, a.wrapping_add(0x800000), a ^ 0x80000000, 0, 0x80000000] {
+ for offset in [0, 0x80000000, 1, 0x80000001, 0x3f800000, 0xbf800000, a, b] {
+ quads.extend([[a, 0, b, offset], [a, offset, b, 0], [a, offset, a, b], [a, b, b, a]]);
+ }
+ }
+ }
+ }
+ let mut state = 0x12345678u32;
+ while quads.len() < 65536 {
+ let mut next = || {
+ state = state.wrapping_mul(1664525).wrapping_add(1013904223);
+ state
+ };
+ let mut quad = [next(), next(), next(), next()];
+ match quads.len() % 5 {
+ 0 => quad[2] = quad[0],
+ 1 => {
+ quad[1] = 0;
+ quad[3] = 0;
+ }
+ 2 => quad[1] = 0,
+ 3 => {
+ quad[0] = 0x3f800000 | (quad[0] & 0x7fffff);
+ quad[2] = quad[0] ^ 1;
+ }
+ _ => {}
+ }
+ quads.push(quad);
+ }
+ assert_eq!(quads.len(), 65536);
+ let mut bytes = Vec::with_capacity(4 + quads.len() * 16);
+ bytes.extend((quads.len() as u32).to_le_bytes());
+ for quad in &quads {
+ for word in quad {
+ bytes.extend(word.to_le_bytes());
+ }
+ }
+ let input = context.device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
+ label: Some("relative coordinate inputs"),
+ contents: &bytes,
+ usage: wgpu::BufferUsages::STORAGE,
+ });
+ let shader = context.device.create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("relative coordinate oracle"),
+ source: wgpu::ShaderSource::Wgsl(SHADER.into()),
+ });
+ let pipeline = context.device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: None,
+ layout: None,
+ module: &shader,
+ entry_point: Some("integer_relative_reference"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let mut task = Task::new(context.clone(), glass_slab(false), request(256), JobOptions::default(), CancelToken::default()).unwrap();
+ let bind = context.device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: Some("relative coordinate oracle"),
+ layout: &pipeline.get_bind_group_layout(0),
+ entries: &[
+ wgpu::BindGroupEntry { binding: 1, resource: input.as_entire_binding() },
+ wgpu::BindGroupEntry { binding: 3, resource: task.accumulation.as_entire_binding() },
+ ],
+ });
+ let mut encoder = context.device.create_command_encoder(&Default::default());
+ {
+ let mut pass = encoder.begin_compute_pass(&Default::default());
+ pass.set_pipeline(&pipeline);
+ pass.set_bind_group(0, &bind, &[]);
+ pass.dispatch_workgroups(1024, 1, 1);
+ }
+ context.queue.submit([encoder.finish()]);
+ task.sample = 1;
+ let values = task.read_linear().unwrap();
+ for (i, (quad, value)) in quads.iter().zip(values).enumerate() {
+ let reference = value[0] as u32 | (value[1] as u32) << 16;
+ let candidate = value[2] as u32 | (value[3] as u32) << 16;
+ let [a, al, b, bl] = quad.map(f32::from_bits);
+ let anchor = a - b;
+ let offset = al - bl;
+ let result = anchor + offset;
+ let expected = if result.is_nan() { 0x7fc00000 } else { result.to_bits() };
+ assert_eq!(reference, expected, "reference index={i} input={quad:08x?}");
+ assert_eq!(candidate, expected, "candidate index={i} input={quad:08x?}");
+ }
+}
+
+#[test]
+fn medium_failures_are_tolerated_only_when_rare() {
+ // One failure in one path (a camera inside glass) is never tolerated.
+ assert!(!medium_failures_tolerated(1, 1));
+ assert!(medium_failures_tolerated(0, 1));
+ assert!(medium_failures_tolerated(1, 1_000_000));
+ assert!(!medium_failures_tolerated(2, 1_000_000));
+ // 1080p at 256 spp tolerates up to 530 isolated paths.
+ assert!(medium_failures_tolerated(530, 1920 * 1080 * 256));
+ assert!(!medium_failures_tolerated(531, 1920 * 1080 * 256));
+ assert!(!medium_failures_tolerated(1_u64 << 32, 1_u64 << 32));
+}
+
+/// Cancellation in fallible HDR preparation must not drop three wgpu scopes in
+/// forward order. Exercise the real preparation routine inside the guarded path,
+/// then prove that the same device still accepts a fresh nested scope stack.
+#[test]
+fn cancelled_environment_preparation_unwinds_gpu_error_scopes() {
+ use solidcraft_render::lighting::environment::EnvironmentSource;
+ let Ok((_, device, _queue)) = open_headless() else {
+ let vulkan = crate::select::native_backends().contains(wgpu::Backends::VULKAN);
+ assert!(!vulkan || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required Vulkan device unavailable");
+ return;
+ };
+ let mut image = request(1);
+ image.environment = Some(Arc::new(EnvironmentSource::hdr(original_hdr(), 0.0, 1.0, false).unwrap()));
+ let token = CancelToken::default();
+ let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
+ checked_creation(&device, || {
+ token.cancel();
+ prepare_environment(&image, &token)
+ })
+ }));
+ let error = outcome.expect("ordinary cancellation must not panic").unwrap_err();
+ assert_eq!(error.code, ErrorCode::Cancelled);
+ checked(scopes(&device)).unwrap();
+ let bytes = prepare_environment(&image, &CancelToken::default()).unwrap();
+ let info = image.environment.as_ref().unwrap().info();
+ assert_eq!(bytes.len(), 16 + info.width as usize * info.height as usize * 32);
+}
+
+/// A denoiser allocation can fail after the outer resource scopes were opened.
+/// Preserve its Result while draining every scope, not only the last one.
+#[test]
+fn failed_resource_creation_unwinds_gpu_error_scopes() {
+ let Ok((_, device, _queue)) = open_headless() else {
+ let vulkan = crate::select::native_backends().contains(wgpu::Backends::VULKAN);
+ assert!(!vulkan || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required Vulkan device unavailable");
+ return;
+ };
+ let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
+ checked_creation(&device, || -> Result<()> { Err(JobError::new(ErrorCode::LimitExceeded, "synthetic bounded allocation refusal")) })
+ }));
+ let error = outcome.expect("ordinary allocation refusal must not panic").unwrap_err();
+ assert_eq!(error.code, ErrorCode::LimitExceeded);
+ checked(scopes(&device)).unwrap();
+}
+
+#[test]
+fn actual_first_gpu_quantum_is_small_and_cancellation_retains_no_completed_image() {
+ let Some(executor) = executor() else { return };
+ let token = CancelToken::default();
+ let mut task = Task::new(executor.context.clone(), sphere(white()), request(64), JobOptions::default(), token.clone()).unwrap();
+ task.dispatch().unwrap();
+ assert_eq!(task.offset, dispatch::MIN_PATHS);
+ assert_eq!(task.sample, 0);
+ token.cancel();
+ assert_eq!(task.step(4096).err().unwrap().code, ErrorCode::Cancelled);
+ assert!(task.png.is_none());
+}
+
+#[test]
+fn real_device_loss_retires_the_executor_and_the_sessions_cached_availability() {
+ use solidcraft_engine::Session;
+ let Some(executor) = executor() else { return };
+ let context = executor.context.clone();
+ let host = ImageHost::with_executor(Arc::new(executor)).unwrap();
+ let mut session = Session::default();
+ session.register_render_job_host(host.clone()).unwrap();
+ assert!(matches!(host.descriptor().unwrap().availability, Availability::Available));
+ context.device.destroy();
+ let deadline = Instant::now() + Duration::from_secs(2);
+ while context.healthy.load(Ordering::Acquire) && Instant::now() < deadline {
+ let _ = context.device.poll(wgpu::PollType::Poll);
+ std::thread::yield_now();
+ }
+ assert!(!context.healthy.load(Ordering::Acquire), "actual device-loss callback must retire the host");
+ assert!(matches!(host.descriptor().unwrap().availability, Availability::Unavailable { .. }));
+ let scene = sphere(white());
+ assert_eq!(host.admit(&scene, &request(1), JobOptions::default()).unwrap_err().code, ErrorCode::HostUnavailable);
+ let backend = session.render_backend();
+ assert!(backend.executors.iter().any(|d| d.id.as_str() == "gpu-path" && matches!(d.availability, Availability::Unavailable { .. })));
+}
diff --git a/crates/gpu/src/path/textures.rs b/crates/gpu/src/path/textures.rs
new file mode 100644
index 0000000000..061b8adc3e
--- /dev/null
+++ b/crates/gpu/src/path/textures.rs
@@ -0,0 +1,73 @@
+//! One read-only storage buffer: body lookup, planar records and linear RGBA pixels.
+use solidcraft_geom::Vec3;
+use solidcraft_render::job::{
+ CancelToken, ErrorCode, JobError, Result,
+ textures::{RuntimeTextures, TextureMap},
+};
+
+fn vector(a: [f64; 3]) -> Vec3 {
+ Vec3::new(a[0], a[1], a[2])
+}
+fn write_word(bytes: &mut [u8], word: usize, value: u32) -> Result<()> {
+ bytes
+ .get_mut(word * 4..word * 4 + 4)
+ .ok_or_else(|| JobError::new(ErrorCode::Internal, "texture record outside allocation"))?
+ .copy_from_slice(&value.to_le_bytes());
+ Ok(())
+}
+fn pixels(bytes: &mut Vec<u8>, map: Option<&TextureMap>, cancel: &CancelToken) -> Result<(u32, [u32; 2])> {
+ let Some(map) = map else {
+ return Ok((0, [0; 2]));
+ };
+ cancel.check()?;
+ let rgba = map.decode(cancel)?;
+ let offset = bytes.len() / 4;
+ for (index, value) in rgba.into_iter().enumerate() {
+ if index % 4096 == 0 {
+ cancel.check()?;
+ }
+ bytes.extend_from_slice(&value.to_le_bytes());
+ }
+ Ok((offset as u32, map.dimensions()))
+}
+pub(super) fn flatten(resources: Option<&RuntimeTextures>, body_count: usize, origin: Vec3, cancel: &CancelToken) -> Result<Vec<u8>> {
+ let Some(resources) = resources else {
+ return Ok(vec![0; 16]);
+ };
+ let header = 4 + body_count + 1;
+ let record_words = resources.bindings().len() * 16;
+ let mut bytes = super::scene::reserved((header + record_words) * 4 + resources.summary().linear_pixel_bytes as usize)?;
+ bytes.resize((header + record_words) * 4, 0);
+ write_word(&mut bytes, 0, (body_count + 1) as u32)?;
+ for (index, binding) in resources.bindings().iter().enumerate() {
+ cancel.check()?;
+ let record = header + index * 16;
+ write_word(&mut bytes, 4 + binding.body_index + 1, record as u32)?;
+ let delta = vector(binding.frame.origin) - origin;
+ if [delta.x, delta.y, delta.z].iter().any(|v| v.abs() > 1e7) {
+ return Err(JobError::new(ErrorCode::InvalidScene, "texture frame must be within 1e7 mm of camera target"));
+ }
+ let u = vector(binding.frame.u);
+ let v = vector(binding.frame.v);
+ for (offset, p) in [(0, delta), (4, u / u.len2()), (8, v / v.len2())] {
+ for (k, c) in [p.x, p.y, p.z].into_iter().enumerate() {
+ write_word(&mut bytes, record + offset + k, (c as f32).to_bits())?;
+ }
+ }
+ let (base, base_size) = pixels(&mut bytes, binding.base_color.as_ref(), cancel)?;
+ let (normal, normal_size) = pixels(&mut bytes, binding.normal.as_ref(), cancel)?;
+ for (offset, value) in [
+ (3, base),
+ (7, base_size[0]),
+ (11, base_size[1]),
+ (12, normal),
+ (13, normal_size[0]),
+ (14, normal_size[1]),
+ (15, (binding.normal_strength as f32).to_bits()),
+ ] {
+ write_word(&mut bytes, record + offset, value)?;
+ }
+ }
+ cancel.check()?;
+ Ok(bytes)
+}
diff --git a/crates/gpu/src/path/textures.wgsl b/crates/gpu/src/path/textures.wgsl
new file mode 100644
index 0000000000..e6b9082500
--- /dev/null
+++ b/crates/gpu/src/path/textures.wgsl
@@ -0,0 +1,58 @@
+@group(0) @binding(5) var<storage, read> texture_words: array<u32>;
+fn texture_vector(word:u32)->vec3<f32> {
+ return bitcast<vec3<f32>>(vec3<u32>(texture_words[word],texture_words[word+1u],texture_words[word+2u]));
+}
+fn texture_record(t:Triangle)->u32 {
+ let body=u32(t.optics.w);
+ if body>=texture_words[0] {return 0u;}
+ return texture_words[4u+body];
+}
+fn texture_pixel(offset:u32,width:u32,x:u32,y:u32)->vec3<f32> {
+ return texture_vector(offset+4u*(y*width+x));
+}
+fn texture_sample(offset:u32,size:vec2<u32>,uv:vec2<f32>)->vec3<f32> {
+ let position=fract(uv)*vec2<f32>(size)-vec2<f32>(0.5);
+ let lower=vec2<i32>(floor(position));
+ let first=vec2<u32>((lower+vec2<i32>(size))%vec2<i32>(size));
+ let second=(first+vec2<u32>(1u))%size;
+ let fraction=fract(position);
+ let a=texture_pixel(offset,size.x,first.x,first.y);
+ let b=texture_pixel(offset,size.x,second.x,first.y);
+ let c=texture_pixel(offset,size.x,first.x,second.y);
+ let d=texture_pixel(offset,size.x,second.x,second.y);
+ return mix(mix(a,b,fraction.x),mix(c,d,fraction.x),fraction.y);
+}
+fn texture_uv(record:u32,position:vec3<f32>)->vec2<f32> {
+ let delta=position-texture_vector(record);
+ return vec2<f32>(dot(delta,texture_vector(record+4u)),dot(delta,texture_vector(record+8u)));
+}
+fn texture_surface(t:Triangle,position:vec3<f32>)->Triangle {
+ let record=texture_record(t);var result=t;
+ if record==0u || texture_words[record+3u]==0u {return result;}
+ let rgb=texture_sample(texture_words[record+3u],vec2<u32>(texture_words[record+7u],texture_words[record+11u]),texture_uv(record,position));
+ // Texture modulates linear reflectance, never emission or scalar alpha.
+ result.base=vec4<f32>(t.base.xyz*rgb,t.base.w);
+ return result;
+}
+fn texture_normal(t:Triangle,position:vec3<f32>,n:vec3<f32>,geometric:vec3<f32>)->vec3<f32> {
+ let record=texture_record(t);
+ if record==0u || texture_words[record+12u]==0u {return n;}
+ let rgb=texture_sample(texture_words[record+12u],vec2<u32>(texture_words[record+13u],texture_words[record+14u]),texture_uv(record,position));
+ let u=unit(texture_vector(record+4u));
+ let tangent=u-n*dot(n,u);
+ if dot(tangent,tangent)<1e-12 {return n;}
+ let tangent_unit=unit(tangent);
+ let handedness=select(1.0,-1.0,dot(n,cross(texture_vector(record+4u),texture_vector(record+8u)))<0.0);
+ let strength=bitcast<f32>(texture_words[record+15u]);
+ let local=vec3<f32>((2.0*rgb.xy-vec2<f32>(1.0))*strength,2.0*rgb.z-1.0);
+ if dot(local,local)<1e-12 || local.z<=0.0 {return n;}
+ let mapped=unit(tangent_unit*local.x+cross(n,tangent_unit)*(handedness*local.y)+n*local.z);
+ return select(mapped,n,dot(mapped,geometric)<=0.0);
+}
+@compute @workgroup_size(1)
+fn texture_reference() {
+ let t=triangle(0u);
+ let mapped=texture_surface(t,u.eye.xyz);
+ accumulation[0]=vec4<f32>(mapped.base.xyz,1.0);
+ accumulation[1]=vec4<f32>(texture_normal(t,u.eye.xyz,u.up.xyz,u.back.xyz)+vec3<f32>(2.0),1.0);
+}
diff --git a/crates/gpu/src/pbr.rs b/crates/gpu/src/pbr.rs
index bd3618d207..865ed4c841 100644
--- a/crates/gpu/src/pbr.rs
+++ b/crates/gpu/src/pbr.rs
@@ -34,9 +34,11 @@ fn vs_pbr(@location(0) p: vec3<f32>, @location(1) n: vec3<f32>, @location(2) bas
return o;
}
-fn pbr_fresnel(f0: vec3<f32>, cosine: f32) -> vec3<f32> {
+fn pbr_fresnel(f0: vec3<f32>, cosine: f32, metallic: f32, ior: f32) -> vec3<f32> {
let t = 1.0 - cosine;
- return f0 + (vec3<f32>(1.0) - f0) * (t * t * t * t * t);
+ // Match the shared surface: an index-matched dielectric has no interface.
+ let grazing = select(1.0, metallic, ior == 1.0);
+ return f0 + (vec3<f32>(grazing) - f0) * (t * t * t * t * t);
}
fn pbr_brdf(base: vec3<f32>, parameters: vec3<f32>, n: vec3<f32>, v: vec3<f32>, l: vec3<f32>) -> vec3<f32> {
@@ -54,9 +56,9 @@ fn pbr_brdf(base: vec3<f32>, parameters: vec3<f32>, n: vec3<f32>, v: vec3<f32>,
let gl = 2.0 / (nl + sqrt(a2 + (1.0 - a2) * nl * nl));
let ratio = (parameters.z - 1.0) / (parameters.z + 1.0);
let f0 = mix(vec3<f32>(ratio * ratio), base, parameters.x);
- let specular = pbr_fresnel(f0, vh) * (distribution * 0.25 * gv * gl);
+ let specular = pbr_fresnel(f0, vh, parameters.x, parameters.z) * (distribution * 0.25 * gv * gl);
let diffuse = base * ((1.0 - parameters.x) / 3.141592653589793);
- return specular + (vec3<f32>(1.0) - pbr_fresnel(f0, nv)) * (vec3<f32>(1.0) - pbr_fresnel(f0, nl)) * diffuse;
+ return specular + (vec3<f32>(1.0) - pbr_fresnel(f0, nv, parameters.x, parameters.z)) * (vec3<f32>(1.0) - pbr_fresnel(f0, nl, parameters.x, parameters.z)) * diffuse;
}
@fragment
diff --git a/crates/gpu/src/select.rs b/crates/gpu/src/select.rs
index c7a1559fc9..24c92cd4b2 100644
--- a/crates/gpu/src/select.rs
+++ b/crates/gpu/src/select.rs
@@ -91,7 +91,7 @@ impl Policy {
}
}
- fn admits(self, tier: Tier) -> bool {
+ pub(crate) fn admits(self, tier: Tier) -> bool {
match self {
Policy::Auto => true,
Policy::Hardware => tier == Tier::Hardware,
@@ -139,7 +139,7 @@ pub fn native_backends() -> wgpu::Backends {
}
}
-fn tier_of(t: wgpu::DeviceType) -> Tier {
+pub(crate) fn tier_of(t: wgpu::DeviceType) -> Tier {
match t {
wgpu::DeviceType::Cpu => Tier::Software,
wgpu::DeviceType::DiscreteGpu | wgpu::DeviceType::IntegratedGpu | wgpu::DeviceType::VirtualGpu | wgpu::DeviceType::Other => Tier::Hardware,
@@ -201,6 +201,28 @@ pub fn survey(policy: Policy) -> Survey {
Survey { backends: format!("{:?}", native_backends()), adapters: found, chosen, lands_on }
}
+/// The Vulkan adapter `policy` picks among those `keep` accepts, with its report; `None` where
+/// the native backends (or `WGPU_BACKEND`) leave out Vulkan, as on macOS. The GPU path tracer
+/// runs on Vulkan only (#3217): D3D12 was never faster in our measurements and needs minutes to
+/// compile its shader at every start, where Vulkan keeps compiled pipelines between runs.
+#[cfg(not(target_arch = "wasm32"))]
+pub fn pick_vulkan(policy: Policy, keep: impl Fn(&wgpu::AdapterInfo) -> bool) -> Option<(wgpu::Adapter, AdapterReport)> {
+ if !native_backends().contains(wgpu::Backends::VULKAN) {
+ return None;
+ }
+ let mut desc = wgpu::InstanceDescriptor::new_without_display_handle_from_env();
+ desc.backends = wgpu::Backends::VULKAN;
+ let mut all = pollster::block_on(wgpu::Instance::new(desc).enumerate_adapters(wgpu::Backends::VULKAN));
+ all.sort_by_key(|a| std::cmp::Reverse(rank(a.get_info().device_type)));
+ all.into_iter()
+ .filter(|a| keep(&a.get_info()))
+ .map(|a| {
+ let r = report(&a.get_info());
+ (a, r)
+ })
+ .find(|(_, r)| policy.admits(r.tier))
+}
+
/// The adapter `policy` picks, with its report; `None` when no adapter qualifies.
#[cfg(not(target_arch = "wasm32"))]
pub fn pick(policy: Policy) -> Option<(wgpu::Adapter, AdapterReport)> {
diff --git a/crates/io/src/catalog.rs b/crates/io/src/catalog.rs
index 2b764aef7b..ad24ec9bb9 100644
--- a/crates/io/src/catalog.rs
+++ b/crates/io/src/catalog.rs
@@ -1,11 +1,12 @@
-//! Portable scalar libraries; no renderer, network, external resources or design links.
+//! Portable material libraries; no network, external resources or design links.
use crate::{IoError, Result};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use solidcraft_doc::{Document, UserMaterial, appearance::Look, valid_density};
use std::collections::BTreeMap;
-pub const FORMAT: &str = "solidcraft-library/1";
+pub const FORMAT: &str = "solidcraft-library/2";
+pub const V1_FORMAT: &str = "solidcraft-library/1";
pub const MAX_BYTES: usize = 4 * 1024 * 1024;
pub const MAX_ENTRIES: usize = 1024;
/// Bound source inspection even when many assignments reuse the same definition.
@@ -51,47 +52,57 @@ impl Provenance {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
-pub struct ScalarLook {
+pub struct LibraryLook {
pub name: String,
pub color: [u8; 3],
pub opacity: f64,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub pbr: Option<solidcraft_doc::pbr_appearance::PbrParameters>,
}
-impl ScalarLook {
+impl LibraryLook {
pub fn from_look(look: &Look) -> Result<Self> {
- if look.pbr.is_some() {
- return Err(invalid("scalar catalog v1 cannot preserve PBR parameters; export refused"));
- }
- Ok(Self { name: look.name.clone(), color: look.color, opacity: look.opacity })
+ let out = Self { name: look.name.clone(), color: look.color, opacity: look.opacity, pbr: look.pbr };
+ out.validate()?;
+ Ok(out)
}
pub fn to_look(&self) -> Look {
- Look { name: self.name.clone(), color: self.color, opacity: self.opacity, pbr: None }
+ Look { name: self.name.clone(), color: self.color, opacity: self.opacity, pbr: self.pbr }
}
fn validate(&self) -> Result<()> {
if !text(&self.name, 128) || !self.opacity.is_finite() || !(0.0..=1.0).contains(&self.opacity) {
return Err(invalid("library appearance needs a 1–128 byte name and finite opacity 0–1"));
}
+ self.to_look().opaque_surface().map_err(|e| invalid(e.to_string()))?;
Ok(())
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
-pub struct ScalarMaterial {
+pub struct LibraryMaterial {
pub name: String,
pub density_g_cm3: f64,
#[serde(default, skip_serializing_if = "Option::is_none")]
- pub appearance: Option<ScalarLook>,
+ pub appearance: Option<LibraryLook>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub physical_card: Option<solidcraft_doc::physical_material::ValidatedCard>,
}
-impl ScalarMaterial {
+impl LibraryMaterial {
pub fn from_material(material: &UserMaterial) -> Result<Self> {
Ok(Self {
name: material.name.clone(),
density_g_cm3: material.density,
- appearance: material.appearance.as_ref().map(ScalarLook::from_look).transpose()?,
+ appearance: material.appearance.as_ref().map(LibraryLook::from_look).transpose()?,
+ physical_card: material.physical_card.clone(),
})
}
pub fn to_material(&self, name: String) -> UserMaterial {
- UserMaterial { name, density: self.density_g_cm3, appearance: self.appearance.as_ref().map(ScalarLook::to_look) }
+ UserMaterial {
+ name,
+ density: self.density_g_cm3,
+ appearance: self.appearance.as_ref().map(LibraryLook::to_look),
+ physical_card: self.physical_card.clone(),
+ }
}
fn validate(&self) -> Result<()> {
if !text(&self.name, 128) || !valid_density(self.density_g_cm3) {
@@ -107,10 +118,16 @@ impl ScalarMaterial {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind", content = "value", rename_all = "snake_case", deny_unknown_fields)]
pub enum Definition {
- Appearance(ScalarLook),
- Material(ScalarMaterial),
+ Appearance(LibraryLook),
+ Material(LibraryMaterial),
}
impl Definition {
+ fn requires_v2(&self) -> bool {
+ match self {
+ Self::Appearance(look) => look.pbr.is_some(),
+ Self::Material(material) => material.physical_card.is_some() || material.appearance.as_ref().is_some_and(|l| l.pbr.is_some()),
+ }
+ }
pub fn name(&self) -> &str {
match self {
Self::Appearance(l) => &l.name,
@@ -140,7 +157,8 @@ pub struct Entry {
pub definition: Definition,
}
impl Entry {
- /// Revision is SHA-256 of compact serde JSON `[provenance, definition]` in this v1 contract.
+ /// SHA-256 of compact serde JSON `[provenance, definition]`. Absent v2 fields
+ /// are omitted, preserving the exact v1 scalar writer contract.
pub fn content_revision(&self) -> Result<String> {
self.provenance.validate()?;
self.definition.validate()?;
@@ -207,11 +225,15 @@ fn bounded_entries<'de, D: serde::Deserializer<'de>>(deserializer: D) -> std::re
}
impl Catalog {
pub fn validate(&self) -> Result<()> {
- if self.format != FORMAT || !identifier(&self.id) || !text(&self.name, 128) || self.entries.len() > MAX_ENTRIES {
- return Err(invalid("unsupported or invalid scalar library (v1, 1024 entries, 128 byte name)"));
+ if !matches!(self.format.as_str(), FORMAT | V1_FORMAT) || !identifier(&self.id) || !text(&self.name, 128) || self.entries.len() > MAX_ENTRIES
+ {
+ return Err(invalid("unsupported or invalid library (v1/v2, 1024 entries, 128 byte name)"));
}
let mut ids = std::collections::BTreeSet::new();
for entry in &self.entries {
+ if self.format == V1_FORMAT && entry.definition.requires_v2() {
+ return Err(invalid("catalog v1 cannot preserve PBR or engineering cards; export refused"));
+ }
entry.validate(&self.id)?;
if !ids.insert(&entry.id) {
return Err(invalid("duplicate library entry identity"));
@@ -223,18 +245,53 @@ impl Catalog {
if bytes.len() > MAX_BYTES {
return Err(invalid("scalar library exceeds 4 MiB"));
}
+ // Keep the v1 wire schema strict, including newly recognized null fields.
+ // This bounded raw preflight is not arbitrary JSON canonicalization.
+ let raw: serde_json::Value = serde_json::from_slice(bytes).map_err(|e| invalid(format!("invalid library: {e}")))?;
+ if raw.get("format").and_then(serde_json::Value::as_str) == Some(V1_FORMAT)
+ && let Some(entries) = raw.get("entries").and_then(serde_json::Value::as_array)
+ {
+ if entries.len() > MAX_ENTRIES {
+ return Err(invalid("library exceeds 1024 entries"));
+ }
+ for entry in entries {
+ if let Some(value) = entry.get("definition").and_then(|d| d.get("value")) {
+ let has = |v: &serde_json::Value, key: &str| v.as_object().is_some_and(|o| o.contains_key(key));
+ if has(value, "pbr") || has(value, "physical_card") || value.get("appearance").is_some_and(|a| has(a, "pbr")) {
+ return Err(invalid("v1 definitions cannot contain v2 fields"));
+ }
+ }
+ }
+ }
+ drop(raw);
let catalog: Self = serde_json::from_slice(bytes).map_err(|e| invalid(format!("invalid scalar library: {e}")))?;
catalog.validate()?;
Ok(catalog)
}
pub fn encode(&self) -> Result<Vec<u8>> {
self.validate()?;
+ let mut budget = 4096usize;
+ for entry in &self.entries {
+ budget = budget.saturating_add(entry_encoded_bound(entry)?);
+ if budget > MAX_BYTES {
+ return Err(invalid("library exceeds 4 MiB encoded admission budget"));
+ }
+ }
let bytes = serde_json::to_vec_pretty(self).map_err(|e| invalid(e.to_string()))?;
if bytes.len() > MAX_BYTES {
return Err(invalid("scalar library exceeds 4 MiB"));
}
Ok(bytes)
}
+ /// Change only the envelope version; reject any lossy downgrade.
+ pub fn in_format(mut self, format: &str) -> Result<Self> {
+ if !matches!(format, FORMAT | V1_FORMAT) {
+ return Err(invalid("unsupported library format"));
+ }
+ self.format = format.into();
+ self.validate()?;
+ Ok(self)
+ }
pub fn read(path: &str) -> Result<Self> {
// Check the VFS size first as well: its browser read clones the stored bytes.
if crate::vfs::len(path).map_err(|e| invalid(e.to_string()))? > MAX_BYTES as u64 {
@@ -258,6 +315,7 @@ impl Catalog {
return Err(invalid("library export exceeds 100000 source references"));
}
let mut entries = BTreeMap::new();
+ let mut budget = 4096usize;
let mut insert = |definition| -> Result<()> {
let entry = Entry::new(id, definition, provenance.clone())?;
if let Some(previous) = entries.get(&entry.id) {
@@ -268,17 +326,21 @@ impl Catalog {
if entries.len() >= MAX_ENTRIES {
return Err(invalid("scalar library exceeds 1024 unique entries"));
}
+ budget = budget.saturating_add(entry_encoded_bound(&entry)?);
+ if budget > MAX_BYTES {
+ return Err(invalid("library exceeds 4 MiB encoded admission budget"));
+ }
entries.insert(entry.id.clone(), entry);
}
Ok(())
};
for look in doc.appearances.bodies.values().chain(doc.appearances.components.values()).chain(doc.appearances.faces.iter().map(|f| &f.look)) {
- insert(Definition::Appearance(ScalarLook::from_look(look)?))?;
+ insert(Definition::Appearance(LibraryLook::from_look(look)?))?;
}
for material in &doc.user_materials {
- insert(Definition::Material(ScalarMaterial::from_material(material)?))?;
+ insert(Definition::Material(LibraryMaterial::from_material(material)?))?;
if let Some(look) = &material.appearance {
- insert(Definition::Appearance(ScalarLook::from_look(look)?))?;
+ insert(Definition::Appearance(LibraryLook::from_look(look)?))?;
}
}
let out = Self { format: FORMAT.into(), id: id.into(), name: name.into(), entries: entries.into_values().collect() };
@@ -287,6 +349,18 @@ impl Catalog {
}
}
+/// Bound retained unique definitions and the final pretty writer before a full
+/// catalog allocation. Each admitted entry is bounded independently; reserve
+/// envelope text, four spaces per nested line, separators and a final newline.
+fn entry_encoded_bound(entry: &Entry) -> Result<usize> {
+ let bytes = serde_json::to_vec_pretty(entry).map_err(|e| invalid(e.to_string()))?;
+ let lines = bytes.iter().filter(|b| **b == b'\n').count().saturating_add(1);
+ Ok(bytes.len().saturating_add(lines.saturating_mul(4)).saturating_add(2))
+}
+
#[cfg(test)]
#[path = "catalog_tests.rs"]
mod tests;
+#[cfg(test)]
+#[path = "catalog_v2_tests.rs"]
+mod v2_tests;
diff --git a/crates/io/src/catalog_tests.rs b/crates/io/src/catalog_tests.rs
index 1b65e7954d..20d5b1c7ea 100644
--- a/crates/io/src/catalog_tests.rs
+++ b/crates/io/src/catalog_tests.rs
@@ -4,7 +4,7 @@ use serde_json::json;
fn catalog() -> Catalog {
let entry = Entry::new(
"user.test",
- Definition::Appearance(ScalarLook { name: "Warm oak colour".into(), color: [180, 120, 70], opacity: 0.8 }),
+ Definition::Appearance(LibraryLook { name: "Warm oak colour".into(), color: [180, 120, 70], opacity: 0.8, pbr: None }),
Provenance::default(),
)
.unwrap();
@@ -34,7 +34,7 @@ fn strict_schema_rejects_unknown_kinds_fields_versions_and_bad_identity() {
for changed in [
{
let mut v = value.clone();
- v["format"] = json!("solidcraft-library/2");
+ v["format"] = json!("solidcraft-library/99");
v
},
{
@@ -96,14 +96,17 @@ fn scalar_validation_refuses_nonfinite_density_opacity_counts_strings_and_oversi
assert!(
Entry::new(
"user.test",
- Definition::Material(ScalarMaterial { name: "Timber".into(), density_g_cm3: density, appearance: None }),
+ Definition::Material(LibraryMaterial { name: "Timber".into(), density_g_cm3: density, appearance: None, physical_card: None }),
Provenance::default()
)
.is_err()
);
}
for name in ["".into(), "x".repeat(129), "bad\nname".into(), " leading".into()] {
- assert!(Entry::new("user.test", Definition::Appearance(ScalarLook { name, color: [1, 2, 3], opacity: 1.0 }), Provenance::default()).is_err());
+ assert!(
+ Entry::new("user.test", Definition::Appearance(LibraryLook { name, color: [1, 2, 3], opacity: 1.0, pbr: None }), Provenance::default())
+ .is_err()
+ );
}
assert!(Catalog::decode(&vec![b' '; MAX_BYTES + 1]).is_err());
let source = Provenance { source_url: Some("x".repeat(2049)), ..Default::default() };
@@ -112,10 +115,10 @@ fn scalar_validation_refuses_nonfinite_density_opacity_counts_strings_and_oversi
#[test]
fn design_export_deduplicates_exact_looks_and_keeps_physical_properties_distinct() {
let mut doc = Document::default();
- let look = ScalarLook { name: "Warm oak colour".into(), color: [180, 120, 70], opacity: 0.8 }.to_look();
+ let look = LibraryLook { name: "Warm oak colour".into(), color: [180, 120, 70], opacity: 0.8, pbr: None }.to_look();
doc.appearances.bodies.insert("Body1".into(), look.clone());
doc.appearances.bodies.insert("Body2".into(), look.clone());
- doc.user_materials.push(UserMaterial { name: "Timber density".into(), density: 0.7, appearance: Some(look) });
+ doc.user_materials.push(UserMaterial { name: "Timber density".into(), density: 0.7, appearance: Some(look), physical_card: None });
let library = Catalog::from_document(&doc, "user.test", "Test", Provenance::default()).unwrap();
assert_eq!(library.entries.len(), 2);
assert!(library.entries.iter().any(|e| matches!(&e.definition,Definition::Material(m) if m.density_g_cm3==0.7)));
@@ -127,7 +130,7 @@ fn design_export_deduplicates_exact_looks_and_keeps_physical_properties_distinct
#[test]
fn scalar_export_refuses_pbr_in_every_design_owned_appearance_location() {
use solidcraft_doc::{appearance::FaceLook, pbr_appearance::PbrParameters};
- let mut look = ScalarLook { name: "Original PBR specimen".into(), color: [180, 120, 70], opacity: 1.0 }.to_look();
+ let mut look = LibraryLook { name: "Original PBR specimen".into(), color: [180, 120, 70], opacity: 1.0, pbr: None }.to_look();
look.pbr = Some(PbrParameters::new(1.0, 0.3, 1.5).unwrap());
for location in 0..4 {
let mut doc = Document::default();
@@ -146,10 +149,16 @@ fn scalar_export_refuses_pbr_in_every_design_owned_appearance_location() {
strict_name: false,
certificate: None,
}),
- _ => doc.user_materials.push(UserMaterial { name: "Original material".into(), density: 1.2, appearance: Some(look.clone()) }),
+ _ => doc.user_materials.push(UserMaterial {
+ name: "Original material".into(),
+ density: 1.2,
+ appearance: Some(look.clone()),
+ physical_card: None,
+ }),
}
let before = doc.clone();
- let error = Catalog::from_document(&doc, "user.test", "Test", Provenance::default()).unwrap_err();
+ let rich = Catalog::from_document(&doc, "user.test", "Test", Provenance::default()).unwrap();
+ let error = rich.in_format(V1_FORMAT).unwrap_err();
assert!(error.to_string().contains("cannot preserve PBR"));
assert_eq!(doc, before);
}
diff --git a/crates/io/src/catalog_v2_tests.rs b/crates/io/src/catalog_v2_tests.rs
new file mode 100644
index 0000000000..a2e7838cfc
--- /dev/null
+++ b/crates/io/src/catalog_v2_tests.rs
@@ -0,0 +1,135 @@
+use super::*;
+use serde_json::{Value, json};
+use solidcraft_doc::{pbr_appearance::PbrParameters, physical_material::ValidatedCard};
+
+// Exact bytes and revisions captured from the pre-v2 writer at 75e66eea.
+const V1: &str = r#"{
+ "format": "solidcraft-library/1",
+ "id": "user.test",
+ "name": "Original v1 fixture",
+ "entries": [
+ {
+ "id": "user.test/appearance-c17adc43c1eb8c7d",
+ "revision": "c17adc43c1eb8c7d6badd7e7821150509bf513eb29c75a90c4027f46d9b49437",
+ "provenance": {
+ "license": "LicenseRef-User-Provided"
+ },
+ "definition": {
+ "kind": "appearance",
+ "value": {
+ "name": "Original scalar study",
+ "color": [
+ 180,
+ 120,
+ 70
+ ],
+ "opacity": 0.8
+ }
+ }
+ }
+ ]
+}"#;
+
+fn card() -> ValidatedCard {
+ ValidatedCard::from_value(&json!({"schema_version":1,"designation":"Original synthetic card","family":"other",
+ "sources":[{"id":"fixture","title":"Original invented constants","kind":"illustrative"}],
+ "properties":[{"source_id":"fixture","data":{"kind":"elasticity","model":{
+ "symmetry":"isotropic","young_modulus_pa":12.25e9,"poisson_ratio":0.25}}}]}))
+ .unwrap()
+}
+
+fn rich() -> Catalog {
+ let mut doc = Document::default();
+ let mut look = Look::custom([180, 120, 70], 1.0);
+ look.name = "Original opaque study".into();
+ look.pbr = Some(PbrParameters::new(1.0, 0.3, 1.5).unwrap());
+ doc.appearances.bodies.insert("Body1".into(), look.clone());
+ doc.user_materials.push(UserMaterial { name: "Original candidate".into(), density: 0.8, appearance: Some(look), physical_card: Some(card()) });
+ Catalog::from_document(&doc, "user.test", "Original v2 fixture", Default::default()).unwrap()
+}
+
+#[test]
+fn pinned_v1_bytes_revisions_and_scalar_material_canonical_fields_are_preserved() {
+ let old = Catalog::decode(V1.as_bytes()).unwrap();
+ assert_eq!(old.encode().unwrap(), V1.as_bytes());
+ let upgraded = old.clone().in_format(FORMAT).unwrap();
+ assert_eq!(upgraded.entries, old.entries);
+ assert_eq!(upgraded.encode().unwrap(), V1.replacen(V1_FORMAT, FORMAT, 1).as_bytes());
+ let material = LibraryMaterial {
+ name: "Original scalar material".into(),
+ density_g_cm3: 0.7,
+ appearance: Some(LibraryLook { name: "Original scalar material".into(), color: [180, 120, 70], opacity: 1.0, pbr: None }),
+ physical_card: None,
+ };
+ let provenance = Provenance {
+ license: "MIT OR Apache-2.0".into(),
+ author: Some("SolidCraft contributors".into()),
+ source_url: Some("https://example.invalid/original".into()),
+ };
+ let entry = Entry::new("user.test", Definition::Material(material), provenance).unwrap();
+ assert_eq!(entry.revision, "3dc003a875463baef587b85b9883f227cb546178317271c60078989bdb86c245");
+ assert_eq!(entry.id, "user.test/material-3dc003a875463bae");
+}
+
+#[test]
+fn v2_roundtrip_keeps_optics_cards_and_revisions_cover_richer_data() {
+ let original = rich();
+ let copy = Catalog::decode(&original.encode().unwrap()).unwrap();
+ assert_eq!(copy, original);
+ assert!(copy.clone().in_format(V1_FORMAT).is_err());
+ let mut changed = copy.clone();
+ for entry in &mut changed.entries {
+ match &mut entry.definition {
+ Definition::Appearance(l) => l.pbr = Some(PbrParameters::new(0., 0.8, 1.4).unwrap()),
+ Definition::Material(m) => {
+ assert_eq!(m.to_material(m.name.clone()).physical_card, Some(card()));
+ let mut v = serde_json::to_value(card()).unwrap();
+ v["designation"] = json!("Changed synthetic designation");
+ m.physical_card = Some(ValidatedCard::from_value(&v).unwrap());
+ }
+ }
+ assert_ne!(entry.content_revision().unwrap(), entry.revision);
+ }
+ assert!(changed.validate().is_err());
+}
+
+#[test]
+fn wire_versions_unknown_fields_invalid_optics_and_hostile_cards_refuse() {
+ let legacy: Value = serde_json::from_str(V1).unwrap();
+ for value in [Value::Null, json!({"metallic":0,"roughness":0.3,"dielectric_ior":1.5})] {
+ let mut bad = legacy.clone();
+ bad["entries"][0]["definition"]["value"]["pbr"] = value;
+ assert!(Catalog::decode(&serde_json::to_vec(&bad).unwrap()).is_err());
+ }
+ let v = serde_json::to_value(rich()).unwrap();
+ let appearance = v["entries"].as_array().unwrap().iter().position(|e| e["definition"]["kind"] == "appearance").unwrap();
+ let material = v["entries"].as_array().unwrap().iter().position(|e| e["definition"]["kind"] == "material").unwrap();
+ for (path, value) in [("opacity", json!(0.5)), ("pbr", json!({"metallic":0,"roughness":0,"dielectric_ior":1.5})), ("unknown", json!(true))] {
+ let mut bad = v.clone();
+ bad["entries"][appearance]["definition"]["value"][path] = value;
+ assert!(Catalog::decode(&serde_json::to_vec(&bad).unwrap()).is_err());
+ }
+ let mut bad = v.clone();
+ bad["entries"][material]["definition"]["value"]["physical_card"]["sources"] = json!(vec![json!({}); 33]);
+ assert!(Catalog::decode(&serde_json::to_vec(&bad).unwrap()).is_err());
+ let mut downgraded = v.clone();
+ downgraded["format"] = json!(V1_FORMAT);
+ assert!(Catalog::decode(&serde_json::to_vec(&downgraded).unwrap()).is_err());
+}
+
+#[test]
+fn rich_export_bounds_retained_definitions_before_whole_catalog_encoding() {
+ let mut v = serde_json::to_value(card()).unwrap();
+ v["properties"] = json!([]);
+ v["sources"] = json!(
+ (0..32)
+ .map(|i| json!({"id":format!("s{i}"),"title":"Original synthetic metadata","kind":"illustrative","reference":"x".repeat(2048)}))
+ .collect::<Vec<_>>()
+ );
+ let record = ValidatedCard::from_value(&v).unwrap();
+ let mut doc = Document::default();
+ for i in 0..64 {
+ doc.user_materials.push(UserMaterial { name: format!("Candidate {i}"), density: 0.8, appearance: None, physical_card: Some(record.clone()) });
+ }
+ assert!(Catalog::from_document(&doc, "user.test", "Original large fixture", Default::default()).unwrap_err().to_string().contains("4 MiB"));
+}
diff --git a/crates/render/src/anisotropic_surface.rs b/crates/render/src/anisotropic_surface.rs
new file mode 100644
index 0000000000..1b8746e1fa
--- /dev/null
+++ b/crates/render/src/anisotropic_surface.rs
@@ -0,0 +1,370 @@
+//! Original anisotropic GGX reflection with separable Smith masking and Schlick Fresnel.
+//!
+//! Mathematics: Heitz, JCGT 7(4), 2018, equations 1 and 2,
+//! <https://jcgt.org/published/0007/04/01/>. No external implementation adapted.
+//! The explicit legacy numerical controls use the **NDF**:
+//! `p(h) = D(h) * n.h`, then `p(l) = p(h) / (4 * v.h)`.
+//! Rejected reflections are null events, never resampled or renormalized.
+//! The separate `sample_visible_reflection` API uses a matched GGX VNDF and PDF.
+//! Its original spherical-cap construction follows Dupuy and Benyoub (2023),
+//! <https://arxiv.org/abs/2306.05044>; see docs/render-vndf-prototype.md.
+//!
+//! This numerical module does not install a renderer, persist a material or alter
+//! engineering axes. The visual frame's normal may be a shading normal, but the
+//! original geometric normal is required separately to reject below-surface rays.
+//! Consumers retain geometric normals for ray spawning and optical boundaries.
+//! No shading-normal energy correction, multiple scattering or transmission is modeled.
+
+use std::f64::consts::{PI, TAU};
+
+use solidcraft_geom::Vec3;
+
+use crate::surface::{MIN_ROUGHNESS, OpaqueSurface, SurfaceError, unit_direction};
+
+/// Admission or finite-arithmetic failure in the anisotropic numerical contract.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum AnisotropicError {
+ /// An existing opaque-surface parameter or direction was invalid.
+ Surface(SurfaceError),
+ /// A visual frame was not orthogonal, or opposed its geometric normal.
+ Frame,
+ /// A variate was not finite in the half-open interval [0, 1).
+ Variates,
+ /// A computed density, response or sample weight was not finite/nonnegative.
+ Arithmetic,
+}
+
+impl From<SurfaceError> for AnisotropicError {
+ fn from(value: SurfaceError) -> Self {
+ Self::Surface(value)
+ }
+}
+
+impl std::fmt::Display for AnisotropicError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Self::Surface(e) => std::fmt::Display::fmt(e, f),
+ Self::Frame => f.write_str("visual frame must be orthogonal and face the geometric normal"),
+ Self::Variates => f.write_str("anisotropic variates must be finite in [0, 1)"),
+ Self::Arithmetic => f.write_str("anisotropic result must be finite and nonnegative"),
+ }
+ }
+}
+impl std::error::Error for AnisotropicError {}
+
+type Result<T> = std::result::Result<T, AnisotropicError>;
+
+/// Right-handed orthonormal visual axes; independent of engineering material axes.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct VisualFrame {
+ normal: Vec3,
+ tangent: Vec3,
+ bitangent: Vec3,
+}
+
+impl VisualFrame {
+ /// Normalize finite nonzero orthogonal inputs. An arbitrary oblique tangent is
+ /// refused rather than silently choosing a different brushed direction.
+ /// Roundoff within 1e-10 of perpendicular is removed by orthogonalization.
+ pub fn new(normal: Vec3, tangent: Vec3) -> Result<Self> {
+ let normal = unit_direction(normal)?;
+ let tangent = unit_direction(tangent)?;
+ let dot = normal.dot(tangent);
+ if dot.abs() > 1e-10 {
+ return Err(AnisotropicError::Frame);
+ }
+ let tangent = unit_direction(tangent - normal * dot)?;
+ let bitangent = unit_direction(normal.cross(tangent))?;
+ Ok(Self { normal, tangent, bitangent })
+ }
+
+ /// Shading normal, never a replacement for an original geometric normal.
+ pub fn normal(self) -> Vec3 {
+ self.normal
+ }
+
+ /// Visual X axis, associated with the first roughness.
+ pub fn tangent(self) -> Vec3 {
+ self.tangent
+ }
+
+ /// Visual Y axis, associated with the second roughness.
+ pub fn bitangent(self) -> Vec3 {
+ self.bitangent
+ }
+
+ fn local(self, direction: Vec3) -> Vec3 {
+ Vec3::new(self.tangent.dot(direction), self.bitangent.dot(direction), self.normal.dot(direction))
+ }
+
+ fn world(self, local: Vec3) -> Vec3 {
+ self.tangent * local.x + self.bitangent * local.y + self.normal * local.z
+ }
+
+ fn geometric(self, normal: Vec3) -> Result<Vec3> {
+ let normal = unit_direction(normal)?;
+ if normal.dot(self.normal) <= 0.0 {
+ return Err(AnisotropicError::Frame);
+ }
+ Ok(normal)
+ }
+}
+
+/// A bounded opaque response with two perceptual roughness axes in [0.045, 1].
+/// Alpha is roughness squared, matching [`OpaqueSurface`].
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct AnisotropicSurface {
+ base: OpaqueSurface,
+ roughness_y: f64,
+}
+
+/// One reflected **specular-only** sample. Fields are in world coordinates.
+/// Its producing method identifies the NDF or visible-normal proposal.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct ReflectionSample {
+ /// Outgoing direction, pointing away from the surface.
+ pub direction: Vec3,
+ /// Unconditional density per steradian, without renormalizing null events.
+ pub pdf: f64,
+ /// `specular_brdf * shading_cosine / pdf`, in linear RGB.
+ /// Diffuse response is excluded; its sampling strategy belongs to the consumer.
+ pub weight: Vec3,
+}
+
+impl AnisotropicSurface {
+ /// Linear-sRGB reflectance, metal fraction and IOR use the opaque contract.
+ /// Perfect delta mirrors and out-of-range roughness are refused, not clamped.
+ pub fn new(base_color: Vec3, metallic: f64, roughness_x: f64, roughness_y: f64, dielectric_ior: f64) -> Result<Self> {
+ let base = OpaqueSurface::new(base_color, metallic, roughness_x, dielectric_ior)?;
+ if !roughness_y.is_finite() || !(MIN_ROUGHNESS..=1.0).contains(&roughness_y) {
+ return Err(SurfaceError::Roughness.into());
+ }
+ Ok(Self { base, roughness_y })
+ }
+
+ /// Admitted perceptual roughness along visual X and Y.
+ pub fn roughness(self) -> [f64; 2] {
+ [self.base.roughness(), self.roughness_y]
+ }
+
+ fn alpha(self) -> [f64; 2] {
+ [self.base.roughness().powi(2), self.roughness_y.powi(2)]
+ }
+
+ fn fresnel(self, cosine: f64) -> Vec3 {
+ self.base.specular_fresnel(cosine)
+ }
+
+ fn distribution_local(self, h: Vec3) -> f64 {
+ if h.z <= 0.0 {
+ return 0.0;
+ }
+ let [ax, ay] = self.alpha();
+ let q = (h.x / ax).powi(2) + (h.y / ay).powi(2) + h.z * h.z;
+ 1.0 / (PI * ax * ay * q * q)
+ }
+
+ // Smith G1 / cosine, avoiding division by tiny cosines and tan(theta).
+ fn visibility(self, w: Vec3) -> f64 {
+ let [ax, ay] = self.alpha();
+ 2.0 / (w.z + (w.z * w.z + (ax * w.x).powi(2) + (ay * w.y).powi(2)).sqrt())
+ }
+
+ /// GGX normal distribution D, per steradian of microfacet normal.
+ /// This is not a normalized probability density: [`Self::normal_pdf`] is.
+ pub fn distribution(self, frame: VisualFrame, half: Vec3) -> Result<f64> {
+ finite_scalar(self.distribution_local(frame.local(unit_direction(half)?)))
+ }
+
+ /// Projected NDF density `D(h) * n.h` on the upper shading hemisphere.
+ /// Its integral over that hemisphere is one.
+ pub fn normal_pdf(self, frame: VisualFrame, half: Vec3) -> Result<f64> {
+ let h = frame.local(unit_direction(half)?);
+ finite_scalar(self.distribution_local(h) * h.z.max(0.0))
+ }
+
+ /// Sample the projected NDF by stretching a radial GGX slope distribution.
+ /// The inverse radial CDF is `r = sqrt(u/(1-u))`; homogeneous coordinates
+ /// `(alpha_x*sqrt(u)*cos(phi), alpha_y*sqrt(u)*sin(phi), sqrt(1-u))`
+ /// avoid a large intermediate radius. No heap, rejection loop or RNG is used.
+ pub fn sample_normal(self, frame: VisualFrame, variates: [f64; 2]) -> Result<Vec3> {
+ let [u, azimuth] = variates;
+ if !variates.into_iter().all(|v| v.is_finite() && (0.0..1.0).contains(&v)) {
+ return Err(AnisotropicError::Variates);
+ }
+ let [ax, ay] = self.alpha();
+ let phi = TAU * azimuth;
+ let radial = u.sqrt();
+ let h = unit_direction(Vec3::new(ax * radial * phi.cos(), ay * radial * phi.sin(), (1.0 - u).sqrt()))?;
+ Ok(unit_direction(frame.world(h))?)
+ }
+
+ /// One view-conditioned visible-normal attempt. The legacy `sample_normal`
+ /// remains an explicitly projected-NDF utility, not this production proposal.
+ /// An upper-hemisphere view is required; no retries or probability clamps.
+ pub fn sample_visible_normal(self, frame: VisualFrame, view: Vec3, variates: [f64; 2]) -> Result<Option<Vec3>> {
+ if !variates.into_iter().all(|u| u.is_finite() && (0.0..1.0).contains(&u)) {
+ return Err(AnisotropicError::Variates);
+ }
+ let v = frame.local(unit_direction(view)?);
+ if v.z <= 0.0 {
+ return Ok(None);
+ }
+ let [ax, ay] = self.alpha();
+ let stretched = unit_direction(Vec3::new(ax * v.x, ay * v.y, v.z))?;
+ // The reflected unit-roughness hemisphere is uniform on z in [-v.z,1].
+ // Factor the radial square, avoiding a negative 1-z*z from cancellation.
+ let z = 1.0 - variates[0] * (1.0 + stretched.z);
+ let radius = ((1.0 - z) * (1.0 + z)).sqrt();
+ let phi = TAU * variates[1];
+ // Directly retain (v+c).z; adding cap.z to v.z loses this positive
+ // component near the lower cap boundary. Normalization is homogeneous,
+ // so apply the covector stretch before the single local normalization.
+ let height = (1.0 - variates[0]) * (1.0 + stretched.z);
+ let h = unit_direction(Vec3::new(ax * (stretched.x + radius * phi.cos()), ay * (stretched.y + radius * phi.sin()), height))?;
+ Ok(Some(unit_direction(frame.world(h))?))
+ }
+
+ /// Visible-normal density D(h)*G1(v)*max(v.h,0)/(n.v), per steradian.
+ /// This is distinct from the projected-NDF `normal_pdf` utility.
+ pub fn visible_normal_pdf(self, frame: VisualFrame, view: Vec3, half: Vec3) -> Result<f64> {
+ let v = frame.local(unit_direction(view)?);
+ let h = frame.local(unit_direction(half)?);
+ let vh = v.dot(h);
+ if v.z <= 0.0 || h.z <= 0.0 || vh <= 0.0 {
+ return Ok(0.0);
+ }
+ finite_scalar(self.distribution_local(h) * self.visibility(v) * vh)
+ }
+
+ /// Matched unconditional VNDF reflected-direction density; null attempts are
+ /// not renormalized. Reflection's Jacobian cancels the positive v.h factor.
+ pub fn visible_reflection_pdf(self, frame: VisualFrame, geometric: Vec3, view: Vec3, light: Vec3) -> Result<f64> {
+ let Some((v, _, h)) = self.directions(frame, geometric, view, light)? else { return Ok(0.0) };
+ finite_scalar(self.distribution_local(h) * self.visibility(v) * 0.25)
+ }
+
+ /// One VNDF specular attempt using the unchanged separable-Smith BSDF.
+ /// Weight f*cos/pdf reduces to F(v.h)*G1(l), without dividing by tiny n.v
+ /// or v.h. Geometric/shading rejection remains a zero event counted in R.
+ pub fn sample_visible_reflection(self, frame: VisualFrame, geometric: Vec3, view: Vec3, variates: [f64; 2]) -> Result<Option<ReflectionSample>> {
+ let geometric_unit = frame.geometric(geometric)?;
+ let view_unit = unit_direction(view)?;
+ let Some(half) = self.sample_visible_normal(frame, view, variates)? else { return Ok(None) };
+ if geometric_unit.dot(view_unit) <= 0.0 {
+ return Ok(None);
+ }
+ let vh = view_unit.dot(half);
+ if vh <= 0.0 {
+ return Ok(None);
+ }
+ let light = unit_direction(half * (2.0 * vh) - view_unit)?;
+ let Some((v, l, h)) = self.directions(frame, geometric, view, light)? else { return Ok(None) };
+ let pdf = finite_scalar(self.distribution_local(h) * self.visibility(v) * 0.25)?;
+ if pdf <= 0.0 {
+ return Err(AnisotropicError::Arithmetic);
+ }
+ let weight = finite_rgb(self.fresnel(v.dot(h)) * (l.z * self.visibility(l)))?;
+ Ok(Some(ReflectionSample { direction: light, pdf, weight }))
+ }
+
+ fn directions(self, frame: VisualFrame, geometric: Vec3, view: Vec3, light: Vec3) -> Result<Option<(Vec3, Vec3, Vec3)>> {
+ let geometric = frame.geometric(geometric)?;
+ let view = unit_direction(view)?;
+ let light = unit_direction(light)?;
+ let (v, l) = (frame.local(view), frame.local(light));
+ if v.z <= 0.0 || l.z <= 0.0 || geometric.dot(view) <= 0.0 || geometric.dot(light) <= 0.0 {
+ return Ok(None);
+ }
+ let h = unit_direction(view + light)?;
+ Ok(Some((v, l, frame.local(h))))
+ }
+
+ fn specular_local(self, v: Vec3, l: Vec3, h: Vec3) -> Result<Vec3> {
+ finite_rgb(self.fresnel(v.dot(h)) * (self.distribution_local(h) * 0.25 * self.visibility(v) * self.visibility(l)))
+ }
+
+ /// Specular component only, with independent geometric hemisphere rejection.
+ /// All input directions point away from the surface.
+ pub fn specular_brdf(self, frame: VisualFrame, geometric: Vec3, view: Vec3, light: Vec3) -> Result<Vec3> {
+ let Some((v, l, h)) = self.directions(frame, geometric, view, light)? else { return Ok(Vec3::ZERO) };
+ self.specular_local(v, l, h)
+ }
+
+ /// Full opaque BRDF, including the same symmetric attenuated Lambert term as
+ /// [`OpaqueSurface`]. No radiance, cosine, exposure or display transform included.
+ /// Equal roughness axes delegate to the existing isotropic numerical contract.
+ pub fn brdf(self, frame: VisualFrame, geometric: Vec3, view: Vec3, light: Vec3) -> Result<Vec3> {
+ let Some((v, l, h)) = self.directions(frame, geometric, view, light)? else { return Ok(Vec3::ZERO) };
+ if self.base.roughness() == self.roughness_y {
+ return Ok(self.base.brdf(frame.normal, view, light)?);
+ }
+ let specular = self.specular_local(v, l, h)?;
+ let fv = self.fresnel(v.z);
+ let fl = self.fresnel(l.z);
+ let diffuse = self.base.base_color() * ((1.0 - self.base.metallic()) / PI);
+ finite_rgb(
+ specular
+ + Vec3::new(
+ (1.0 - fv.x) * (1.0 - fl.x) * diffuse.x,
+ (1.0 - fv.y) * (1.0 - fl.y) * diffuse.y,
+ (1.0 - fv.z) * (1.0 - fl.z) * diffuse.z,
+ ),
+ )
+ }
+
+ /// Unconditional reflected-direction density for the specular NDF sampler.
+ /// Integrates to the acceptance probability, not necessarily one: invalid
+ /// microfacets and below-geometric/shading-hemisphere reflections are null events.
+ /// A mixture with a diffuse or environment sampler must use its own mixture PDF.
+ pub fn reflection_pdf(self, frame: VisualFrame, geometric: Vec3, view: Vec3, light: Vec3) -> Result<f64> {
+ let Some((v, _, h)) = self.directions(frame, geometric, view, light)? else { return Ok(0.0) };
+ finite_scalar(self.distribution_local(h) * h.z.max(0.0) / (4.0 * v.dot(h).max(0.0)))
+ }
+
+ /// One specular NDF attempt. `None` is a zero-contribution event and must
+ /// still count towards the consumer's sample denominator. Never retry until
+ /// success. Ray origins/visibility use the consumer's original geometric data.
+ pub fn sample_reflection(self, frame: VisualFrame, geometric: Vec3, view: Vec3, variates: [f64; 2]) -> Result<Option<ReflectionSample>> {
+ let geometric = frame.geometric(geometric)?;
+ let view = unit_direction(view)?;
+ let half = self.sample_normal(frame, variates)?;
+ let v = frame.local(view);
+ if v.z <= 0.0 || geometric.dot(view) <= 0.0 {
+ return Ok(None);
+ }
+ let vh = view.dot(half);
+ if vh <= 0.0 {
+ return Ok(None);
+ }
+ let light = unit_direction(half * (2.0 * vh) - view)?;
+ let l = frame.local(light);
+ if l.z <= 0.0 || geometric.dot(light) <= 0.0 {
+ return Ok(None);
+ }
+ let h = frame.local(half);
+ let pdf = self.reflection_pdf(frame, geometric, view, light)?;
+ if pdf <= 0.0 {
+ return Err(AnisotropicError::Arithmetic);
+ }
+ // Cancel D algebraically in f_spec * cos / pdf. No tiny-cosine division.
+ let weight = finite_rgb(self.fresnel(vh) * (self.visibility(v) * (self.visibility(l) * l.z) * vh / h.z))?;
+ Ok(Some(ReflectionSample { direction: light, pdf, weight }))
+ }
+}
+
+fn finite_scalar(value: f64) -> Result<f64> {
+ if value.is_finite() && value >= 0.0 { Ok(value) } else { Err(AnisotropicError::Arithmetic) }
+}
+
+fn finite_rgb(value: Vec3) -> Result<Vec3> {
+ if value.is_finite() && [value.x, value.y, value.z].into_iter().all(|c| c >= 0.0) { Ok(value) } else { Err(AnisotropicError::Arithmetic) }
+}
+
+#[cfg(test)]
+#[path = "anisotropic_surface_tests.rs"]
+mod tests;
+
+#[cfg(test)]
+#[path = "anisotropic_vndf_tests.rs"]
+mod vndf_tests;
diff --git a/crates/render/src/anisotropic_surface_tests.rs b/crates/render/src/anisotropic_surface_tests.rs
new file mode 100644
index 0000000000..6e963aebb6
--- /dev/null
+++ b/crates/render/src/anisotropic_surface_tests.rs
@@ -0,0 +1,277 @@
+use super::*;
+
+fn frame() -> VisualFrame {
+ VisualFrame::new(Vec3::Z, Vec3::X).unwrap()
+}
+
+fn surface(rx: f64, ry: f64) -> AnisotropicSurface {
+ AnisotropicSurface::new(Vec3::new(0.8, 0.5, 0.2), 1.0, rx, ry, 1.5).unwrap()
+}
+
+fn close(a: f64, b: f64, tolerance: f64) {
+ assert!((a - b).abs() <= tolerance * (1.0 + a.abs().max(b.abs())), "{a} != {b}");
+}
+
+fn close_rgb(a: Vec3, b: Vec3, tolerance: f64) {
+ close(a.x, b.x, tolerance);
+ close(a.y, b.y, tolerance);
+ close(a.z, b.z, tolerance);
+}
+
+fn hemisphere(mu: f64, phi: f64) -> Vec3 {
+ let radius = (1.0 - mu * mu).sqrt();
+ Vec3::new(radius * phi.cos(), radius * phi.sin(), mu)
+}
+
+#[test]
+fn constructor_rejects_hostile_parameters_on_both_axes() {
+ for bad in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 0.0, MIN_ROUGHNESS.next_down(), 1.01] {
+ assert!(AnisotropicSurface::new(Vec3::X, 1.0, bad, 0.5, 1.5).is_err());
+ assert!(AnisotropicSurface::new(Vec3::X, 1.0, 0.5, bad, 1.5).is_err());
+ }
+ for bad in [f64::NAN, f64::INFINITY, -0.1, 1.1] {
+ assert!(AnisotropicSurface::new(Vec3::new(bad, 0.0, 0.0), 1.0, 0.5, 0.8, 1.5).is_err());
+ assert!(AnisotropicSurface::new(Vec3::X, bad, 0.5, 0.8, 1.5).is_err());
+ }
+ for bad in [f64::NAN, 0.99, 3.01] {
+ assert!(AnisotropicSurface::new(Vec3::X, 1.0, 0.5, 0.8, bad).is_err());
+ }
+ assert_eq!(surface(MIN_ROUGHNESS, 1.0).roughness(), [MIN_ROUGHNESS, 1.0]);
+}
+
+#[test]
+fn frame_is_right_handed_and_requires_an_explicit_orthogonal_axis() {
+ let f = VisualFrame::new(Vec3::new(0.0, 0.0, 1e308), Vec3::new(1e-300, 0.0, 0.0)).unwrap();
+ assert_eq!(f.normal(), Vec3::Z);
+ assert_eq!(f.tangent(), Vec3::X);
+ assert_eq!(f.bitangent(), Vec3::Y);
+ for (n, t) in [(Vec3::ZERO, Vec3::X), (Vec3::Z, Vec3::Z), (Vec3::Z, Vec3::X + Vec3::Z), (Vec3::Z, Vec3::new(f64::NAN, 0.0, 0.0))] {
+ assert!(VisualFrame::new(n, t).is_err());
+ }
+ let tilted = VisualFrame::new(Vec3::new(0.3, 0.4, 1.0), Vec3::new(0.8, -0.6, 0.0)).unwrap();
+ close(tilted.tangent().dot(tilted.normal()), 0.0, 1e-14);
+ close_rgb(tilted.tangent().cross(tilted.bitangent()), tilted.normal(), 1e-14);
+}
+
+#[test]
+fn normal_incidence_matches_independent_ggx_peak() {
+ let s = surface(0.3, 0.7);
+ let d = 1.0 / (PI * 0.3_f64.powi(2) * 0.7_f64.powi(2));
+ close(s.distribution(frame(), Vec3::Z).unwrap(), d, 1e-14);
+ close(s.normal_pdf(frame(), Vec3::Z).unwrap(), d, 1e-14);
+ close_rgb(s.brdf(frame(), Vec3::Z, Vec3::Z, Vec3::Z).unwrap(), Vec3::new(0.8, 0.5, 0.2) * (d / 4.0), 1e-14);
+}
+
+#[test]
+fn isotropic_limit_matches_existing_opaque_contract() {
+ for r in [MIN_ROUGHNESS, 0.3, 0.7, 1.0] {
+ for metallic in [0.0, 0.5, 1.0] {
+ let color = Vec3::new(0.8, 0.5, 0.2);
+ let a = AnisotropicSurface::new(color, metallic, r, r, 1.5).unwrap();
+ let opaque = OpaqueSurface::new(color, metallic, r, 1.5).unwrap();
+ for (v, l) in [(Vec3::Z, Vec3::Z), (Vec3::new(0.4, 0.2, 0.8), Vec3::new(-0.2, 0.7, 0.6))] {
+ assert_eq!(a.brdf(frame(), Vec3::Z, v, l).unwrap(), opaque.brdf(Vec3::Z, v, l).unwrap());
+ if metallic == 1.0 {
+ close_rgb(a.specular_brdf(frame(), Vec3::Z, v, l).unwrap(), opaque.brdf(Vec3::Z, v, l).unwrap(), 1e-10);
+ }
+ }
+ }
+ }
+}
+
+#[test]
+fn reciprocal_for_unequal_axes_and_mixed_metal_fraction() {
+ for metallic in [0.0, 0.4, 1.0] {
+ let s = AnisotropicSurface::new(Vec3::new(0.8, 0.5, 0.2), metallic, 0.2, 0.9, 2.0).unwrap();
+ for (v, l) in [(Vec3::new(0.4, 0.1, 1.0), Vec3::new(-0.3, 0.2, 0.8)), (Vec3::new(1.0, 0.0, 1e-300), Vec3::new(-1.0, 0.0, 1e-300))] {
+ close_rgb(s.brdf(frame(), Vec3::Z, v, l).unwrap(), s.brdf(frame(), Vec3::Z, l, v).unwrap(), 1e-12);
+ }
+ }
+}
+
+#[test]
+fn ninety_degree_visual_rotation_swaps_the_brushed_response() {
+ let s = surface(0.25, 0.8);
+ let swapped = surface(0.8, 0.25);
+ let rotated = VisualFrame::new(Vec3::Z, Vec3::Y).unwrap();
+ let light = Vec3::new(0.6, 0.0, 0.8);
+ let initial = s.brdf(frame(), Vec3::Z, Vec3::Z, light).unwrap();
+ let turned = s.brdf(rotated, Vec3::Z, Vec3::Z, light).unwrap();
+ assert!((initial - turned).len() > 0.01);
+ close_rgb(turned, swapped.brdf(frame(), Vec3::Z, Vec3::Z, light).unwrap(), 1e-13);
+ let h = s.sample_normal(frame(), [0.3, 0.2]).unwrap();
+ let rotated_h = s.sample_normal(rotated, [0.3, 0.2]).unwrap();
+ close_rgb(rotated_h, Vec3::new(-h.y, h.x, h.z), 1e-14);
+}
+
+#[test]
+fn geometric_and_shading_hemispheres_are_independent() {
+ let shading = VisualFrame::new(Vec3::new(0.8, 0.0, 0.6), Vec3::Y).unwrap();
+ let light = Vec3::new(0.99, 0.0, -0.1);
+ let s = surface(0.5, 0.8);
+ assert!(shading.normal().dot(light) > 0.0);
+ assert_eq!(s.brdf(shading, Vec3::Z, Vec3::Z, light).unwrap(), Vec3::ZERO);
+ assert_eq!(s.reflection_pdf(shading, Vec3::Z, Vec3::Z, light).unwrap(), 0.0);
+ assert!(s.brdf(frame(), -Vec3::Z, Vec3::Z, Vec3::Z).is_err());
+ assert_eq!(s.brdf(frame(), Vec3::Z, Vec3::Z, Vec3::X).unwrap(), Vec3::ZERO);
+ assert_eq!(s.brdf(frame(), Vec3::Z, -Vec3::Z, Vec3::Z).unwrap(), Vec3::ZERO);
+}
+
+#[test]
+fn grazing_and_extreme_finite_direction_magnitudes_remain_finite() {
+ for (rx, ry) in [(MIN_ROUGHNESS, 1.0), (1.0, MIN_ROUGHNESS), (MIN_ROUGHNESS, MIN_ROUGHNESS)] {
+ let s = surface(rx, ry);
+ for (v, l) in [(Vec3::new(1.0, 0.0, 1e-300), Vec3::new(-1.0, 0.0, 1e-300)), (Vec3::new(1e308, 1e308, 1e308), Vec3::new(-1e-300, 0.0, 1e-300))]
+ {
+ let b = s.brdf(frame(), Vec3::Z, v, l).unwrap();
+ assert!(b.is_finite() && b.x >= 0.0 && b.y >= 0.0 && b.z >= 0.0);
+ }
+ for u in [0.0, f64::from_bits(1), 0.5, 1.0_f64.next_down()] {
+ let h = s.sample_normal(frame(), [u, 0.5]).unwrap();
+ assert!(h.is_finite() && h.z > 0.0);
+ assert!(s.normal_pdf(frame(), h).unwrap().is_finite());
+ }
+ let view = Vec3::new(1.0, 0.0, 1e-300);
+ let sample = s.sample_reflection(frame(), Vec3::Z, view, [0.0, 0.0]).unwrap().unwrap();
+ assert!(sample.pdf.is_finite() && sample.pdf > 0.0 && sample.weight.is_finite());
+ // A mathematical density beyond f64 is a typed refusal, never clamped.
+ assert_eq!(s.sample_reflection(frame(), Vec3::Z, Vec3::new(1.0, 0.0, f64::from_bits(1)), [0.0, 0.0]), Err(AnisotropicError::Arithmetic));
+ }
+}
+
+#[test]
+fn malformed_directions_and_variates_fail_without_clamping() {
+ let s = surface(0.5, 0.8);
+ for bad in [Vec3::ZERO, Vec3::new(f64::NAN, 0.0, 1.0), Vec3::new(f64::INFINITY, 0.0, 1.0)] {
+ assert!(s.brdf(frame(), Vec3::Z, bad, Vec3::Z).is_err());
+ assert!(s.brdf(frame(), bad, Vec3::Z, Vec3::Z).is_err());
+ assert!(s.brdf(frame(), Vec3::Z, Vec3::Z, bad).is_err());
+ assert!(s.normal_pdf(frame(), bad).is_err());
+ }
+ for bad in [-0.1, 1.0, f64::NAN, f64::INFINITY] {
+ assert!(s.sample_reflection(frame(), Vec3::Z, Vec3::Z, [bad, 0.5]).is_err());
+ assert!(s.sample_reflection(frame(), Vec3::Z, Vec3::Z, [0.5, bad]).is_err());
+ }
+}
+
+#[test]
+fn sampled_slopes_follow_the_independent_inverse_radial_cdf() {
+ let s = surface(0.3, 0.7);
+ for u in [0.0, 0.01, 0.3, 0.8, 0.9999] {
+ for azimuth in [0.0, 0.2, 0.5, 0.8] {
+ let h = s.sample_normal(frame(), [u, azimuth]).unwrap();
+ let sx = h.x / (0.3_f64.powi(2) * h.z);
+ let sy = h.y / (0.7_f64.powi(2) * h.z);
+ let radius2 = sx * sx + sy * sy;
+ close(radius2 / (1.0 + radius2), u, 1e-13);
+ close_rgb(h, s.sample_normal(frame(), [u, azimuth]).unwrap(), 0.0);
+ }
+ }
+}
+
+#[test]
+fn reflection_samples_match_pdf_and_specular_throughput() {
+ let s = surface(0.4, 0.8);
+ let view = unit_direction(Vec3::new(0.2, 0.3, 1.0)).unwrap();
+ let mut accepted = 0;
+ let mut null = 0;
+ for i in 0..32 {
+ for j in 0..32 {
+ let uv = [(i as f64 + 0.5) / 32.0, (j as f64 + 0.5) / 32.0];
+ match s.sample_reflection(frame(), Vec3::Z, view, uv).unwrap() {
+ Some(sample) => {
+ accepted += 1;
+ close(sample.pdf, s.reflection_pdf(frame(), Vec3::Z, view, sample.direction).unwrap(), 1e-13);
+ let expected = s.specular_brdf(frame(), Vec3::Z, view, sample.direction).unwrap() * (sample.direction.z / sample.pdf);
+ close_rgb(sample.weight, expected, 1e-10);
+ }
+ None => null += 1,
+ }
+ }
+ }
+ assert!(accepted > 0 && null > 0);
+ assert_eq!(accepted + null, 1024);
+}
+
+#[test]
+fn unit_roughness_normal_view_has_half_null_mass_and_uniform_reflection_pdf() {
+ let s = surface(1.0, 1.0);
+ assert!(s.sample_reflection(frame(), Vec3::Z, Vec3::Z, [0.75, 0.3]).unwrap().is_none());
+ let sample = s.sample_reflection(frame(), Vec3::Z, Vec3::Z, [0.25, 0.3]).unwrap().unwrap();
+ close(sample.pdf, 1.0 / (4.0 * PI), 1e-14);
+ let mut accepted = 0;
+ for i in 0..1024 {
+ accepted += usize::from(s.sample_reflection(frame(), Vec3::Z, Vec3::Z, [(i as f64 + 0.5) / 1024.0, 0.3]).unwrap().is_some());
+ }
+ assert_eq!(accepted, 512);
+ // p(l)=1/(4*pi) over the upper hemisphere: valid mass exactly1/2.
+ close(s.reflection_pdf(frame(), Vec3::Z, Vec3::Z, Vec3::Z).unwrap() * (2.0 * PI), 0.5, 1e-14);
+ assert_eq!(s.reflection_pdf(frame(), Vec3::Z, Vec3::Z, -Vec3::Z).unwrap(), 0.0);
+}
+
+#[test]
+fn invisible_microfacets_are_null_and_weights_exclude_the_diffuse_substrate() {
+ let s = AnisotropicSurface::new(Vec3::new(0.8, 0.5, 0.2), 0.0, 1.0, 1.0, 1.5).unwrap();
+ let view = unit_direction(Vec3::new(0.99, 0.0, 0.1)).unwrap();
+ assert!(s.sample_reflection(frame(), Vec3::Z, view, [0.9, 0.5]).unwrap().is_none());
+ let sample = s.sample_reflection(frame(), Vec3::Z, Vec3::Z, [0.1, 0.2]).unwrap().unwrap();
+ let scale = sample.direction.z / sample.pdf;
+ let specular = s.specular_brdf(frame(), Vec3::Z, Vec3::Z, sample.direction).unwrap() * scale;
+ let total = s.brdf(frame(), Vec3::Z, Vec3::Z, sample.direction).unwrap() * scale;
+ close_rgb(sample.weight, specular, 1e-13);
+ assert!(total.x > sample.weight.x + 0.1);
+ assert_eq!(s.normal_pdf(frame(), -Vec3::Z).unwrap(), 0.0);
+ assert_eq!(s.normal_pdf(frame(), Vec3::X).unwrap(), 0.0);
+}
+
+#[test]
+fn quadrature_distinguishes_normal_pdf_mass_from_valid_reflection_mass() {
+ // Finite midpoint grids resolve these broad lobes only. Narrowest admitted
+ // roughness is tested analytically and with inverse-CDF samples elsewhere.
+ const N: usize = 256;
+ for (rx, ry) in [(1.0, 1.0), (0.6, 0.9)] {
+ let s = surface(rx, ry);
+ let mut normal_mass = 0.0;
+ let mut valid_mass = 0.0;
+ let mut accepted = 0;
+ for i in 0..N {
+ for j in 0..N {
+ let u = (i as f64 + 0.5) / N as f64;
+ let azimuth = (j as f64 + 0.5) / N as f64;
+ let l = hemisphere(u, TAU * azimuth);
+ normal_mass += s.normal_pdf(frame(), l).unwrap();
+ valid_mass += s.reflection_pdf(frame(), Vec3::Z, Vec3::Z, l).unwrap();
+ accepted += usize::from(s.sample_reflection(frame(), Vec3::Z, Vec3::Z, [u, azimuth]).unwrap().is_some());
+ }
+ }
+ let domega = TAU / (N * N) as f64;
+ close(normal_mass * domega, 1.0, 0.001);
+ close(valid_mass * domega, accepted as f64 / (N * N) as f64, 0.003);
+ assert!(valid_mass * domega < 1.0);
+ }
+}
+
+#[test]
+fn broad_lobe_importance_estimate_agrees_with_integrated_energy() {
+ // White metal, normal view, deterministic256² grids. A scoped consistency
+ // check, not universal energy certification or a variance/convergence claim.
+ const N: usize = 256;
+ let s = AnisotropicSurface::new(Vec3::new(1.0, 1.0, 1.0), 1.0, 0.6, 0.9, 1.5).unwrap();
+ let mut integrated = Vec3::ZERO;
+ let mut sampled = Vec3::ZERO;
+ for i in 0..N {
+ for j in 0..N {
+ let uv = [(i as f64 + 0.5) / N as f64, (j as f64 + 0.5) / N as f64];
+ let light = hemisphere(uv[0], TAU * uv[1]);
+ integrated += s.specular_brdf(frame(), Vec3::Z, Vec3::Z, light).unwrap() * light.z;
+ if let Some(sample) = s.sample_reflection(frame(), Vec3::Z, Vec3::Z, uv).unwrap() {
+ sampled += sample.weight;
+ }
+ }
+ }
+ integrated = integrated * (TAU / (N * N) as f64);
+ sampled = sampled / (N * N) as f64; // Includes ALL null attempts.
+ assert!(integrated.x > 0.0 && integrated.x <= 1.001);
+ assert!(sampled.x > 0.0 && sampled.x <= 1.001);
+ close_rgb(integrated, sampled, 0.003);
+}
diff --git a/crates/render/src/anisotropic_vndf_tests.rs b/crates/render/src/anisotropic_vndf_tests.rs
new file mode 100644
index 0000000000..223c38b52e
--- /dev/null
+++ b/crates/render/src/anisotropic_vndf_tests.rs
@@ -0,0 +1,326 @@
+//! VNDF proposal tests, written but not executed. Legacy NDF assertions stay intact.
+use super::*;
+
+fn frame() -> VisualFrame {
+ VisualFrame::new(Vec3::Z, Vec3::X).unwrap()
+}
+fn white(rx: f64, ry: f64) -> AnisotropicSurface {
+ AnisotropicSurface::new(Vec3::new(1.0, 1.0, 1.0), 1.0, rx, ry, 1.5).unwrap()
+}
+fn close(a: f64, b: f64, tolerance: f64) {
+ assert!((a - b).abs() <= tolerance * (1.0 + a.abs().max(b.abs())), "{a} != {b}");
+}
+fn rotate(v: Vec3) -> Vec3 {
+ Vec3::new(-v.y, v.x, v.z)
+}
+
+#[test]
+fn vndf_normal_incidence_has_analytic_mean_second_moment_and_half_null_mass() {
+ let surface = white(1.0, 1.0);
+ let (mut sum, mut second, mut nulls) = (0.0, 0.0, 0);
+ const N: usize = 4096;
+ for i in 0..N {
+ let u = (i as f64 + 0.5) / N as f64;
+ let value = match surface.sample_visible_reflection(frame(), Vec3::Z, Vec3::Z, [u, 0.3]).unwrap() {
+ Some(s) => {
+ close(s.direction.z, 1.0 - 2.0 * u, 1e-13);
+ close(s.pdf, 1.0 / (4.0 * PI), 1e-13);
+ close(s.weight.x, 2.0 * s.direction.z / (1.0 + s.direction.z), 1e-13);
+ s.weight.x
+ }
+ None => {
+ nulls += 1;
+ 0.0
+ }
+ };
+ sum += value;
+ second += value * value;
+ }
+ assert_eq!(nulls, N / 2);
+ // Independent integrals of (1-2u)/(1-u) and its square on [0,1/2].
+ close(sum / N as f64, 1.0 - 2.0_f64.ln(), 1e-6);
+ close(second / N as f64, 3.0 - 4.0 * 2.0_f64.ln(), 1e-6);
+}
+
+#[test]
+fn unit_roughness_visible_cap_has_analytic_grazing_pdf_and_acceptance_mass() {
+ const N: usize = 2048;
+ let s = white(1.0, 1.0);
+ for cosine in [1.0_f64, 0.2, 1e-12] {
+ let view = Vec3::new(((1.0 - cosine) * (1.0 + cosine)).sqrt(), 0.0, cosine);
+ let mut accepted = 0;
+ for i in 0..N {
+ let u = (i as f64 + 0.5) / N as f64;
+ if let Some(sample) = s.sample_visible_reflection(frame(), Vec3::Z, view, [u, 0.37]).unwrap() {
+ accepted += 1;
+ close(sample.pdf, 1.0 / (2.0 * PI * (1.0 + cosine)), 1e-10);
+ close(sample.weight.x, 2.0 * sample.direction.z / (1.0 + sample.direction.z), 1e-10);
+ }
+ }
+ close(accepted as f64 / N as f64, 1.0 / (1.0 + cosine), 1.0 / N as f64);
+ }
+}
+
+#[test]
+fn anisotropic_visible_samples_match_unchanged_specular_bsdf_and_pdf() {
+ let s = AnisotropicSurface::new(Vec3::new(0.8, 0.5, 0.2), 0.4, 0.4, 0.8, 1.5).unwrap();
+ let v = unit_direction(Vec3::new(0.2, 0.3, 1.0)).unwrap();
+ let (mut accepted, mut nulls) = (0, 0);
+ for i in 0..32 {
+ for j in 0..32 {
+ let uv = [(i as f64 + 0.5) / 32.0, (j as f64 + 0.5) / 32.0];
+ match s.sample_visible_reflection(frame(), Vec3::Z, v, uv).unwrap() {
+ Some(sample) => {
+ accepted += 1;
+ let pdf = s.visible_reflection_pdf(frame(), Vec3::Z, v, sample.direction).unwrap();
+ close(sample.pdf, pdf, 1e-13);
+ let expected = s.specular_brdf(frame(), Vec3::Z, v, sample.direction).unwrap() * (sample.direction.z / pdf);
+ assert!((sample.weight - expected).len() < 1e-10);
+ assert!([sample.weight.x, sample.weight.y, sample.weight.z].into_iter().all(|w| (0.0..=1.0 + 1e-12).contains(&w)));
+ }
+ None => nulls += 1,
+ }
+ }
+ }
+ assert!(accepted > 0 && nulls > 0);
+ assert_eq!(accepted + nulls, 1024);
+}
+
+#[test]
+fn anisotropic_visible_mapping_is_covariant_under_visual_frame_rotation() {
+ let s = white(0.2, 0.8);
+ let v = unit_direction(Vec3::new(0.4, 0.2, 1.0)).unwrap();
+ let turned = VisualFrame::new(Vec3::Z, Vec3::Y).unwrap();
+ for u in [[0.0, 0.0], [0.2, 0.3], [0.8, 0.7], [1.0_f64.next_down(), 0.5]] {
+ let a = s.sample_visible_normal(frame(), v, u).unwrap().unwrap();
+ let b = s.sample_visible_normal(turned, rotate(v), u).unwrap().unwrap();
+ assert!((rotate(a) - b).len() < 1e-12);
+ close(s.visible_normal_pdf(frame(), v, a).unwrap(), s.visible_normal_pdf(turned, rotate(v), b).unwrap(), 1e-11);
+ let a = s.sample_visible_reflection(frame(), Vec3::Z, v, u).unwrap();
+ let b = s.sample_visible_reflection(turned, Vec3::Z, rotate(v), u).unwrap();
+ match (a, b) {
+ (Some(a), Some(b)) => {
+ assert!((rotate(a.direction) - b.direction).len() < 1e-12);
+ assert!((a.weight - b.weight).len() < 1e-12);
+ close(a.pdf, b.pdf, 1e-11);
+ }
+ (None, None) => {}
+ _ => panic!("rotation changed null support"),
+ }
+ }
+}
+
+#[test]
+fn visible_mapping_retains_finite_open_endpoints_and_grazing_limits() {
+ for (rx, ry) in [(MIN_ROUGHNESS, 1.0), (1.0, MIN_ROUGHNESS), (MIN_ROUGHNESS, MIN_ROUGHNESS), (1.0, 1.0)] {
+ let s = white(rx, ry);
+ for view in [Vec3::Z, Vec3::new(1.0, 0.0, 1e-300), Vec3::new(1.0, 0.0, f64::from_bits(1))] {
+ for u in [0.0, f64::from_bits(1), 0.5, 1.0_f64.next_down()] {
+ for phi in [0.0, 0.5, 1.0_f64.next_down()] {
+ let h = s.sample_visible_normal(frame(), view, [u, phi]).unwrap().unwrap();
+ assert!(h.is_finite() && h.z > 0.0);
+ close(h.len(), 1.0, 1e-13);
+ assert!(s.visible_normal_pdf(frame(), view, h).unwrap().is_finite());
+ if let Some(sample) = s.sample_visible_reflection(frame(), Vec3::Z, view, [u, phi]).unwrap() {
+ assert!(sample.pdf.is_finite() && sample.pdf > 0.0 && sample.weight.is_finite());
+ }
+ }
+ }
+ }
+ // This endpoint was an overflowing NDF-density control; VNDF cancels
+ // the tiny view cosine analytically instead of clamping that old PDF.
+ let sample = s.sample_visible_reflection(frame(), Vec3::Z, Vec3::new(1.0, 0.0, f64::from_bits(1)), [0.0, 0.0]).unwrap().unwrap();
+ assert!(sample.pdf.is_finite() && sample.weight.is_finite());
+ }
+}
+
+#[test]
+fn visible_density_has_correct_support_and_rejects_hostile_variates() {
+ let s = white(0.4, 0.8);
+ for bad in [-0.1, 1.0, f64::NAN, f64::INFINITY] {
+ assert!(s.sample_visible_normal(frame(), Vec3::Z, [bad, 0.2]).is_err());
+ assert!(s.sample_visible_reflection(frame(), Vec3::Z, Vec3::Z, [0.2, bad]).is_err());
+ }
+ assert!(s.sample_visible_normal(frame(), Vec3::ZERO, [0.2, 0.2]).is_err());
+ assert_eq!(s.visible_normal_pdf(frame(), Vec3::Z, -Vec3::Z).unwrap(), 0.0);
+ assert_eq!(s.visible_normal_pdf(frame(), Vec3::Z, Vec3::X).unwrap(), 0.0);
+ assert_eq!(s.visible_normal_pdf(frame(), Vec3::new(1.0, 0.0, 0.01), Vec3::new(-1.0, 0.0, 0.1)).unwrap(), 0.0);
+ assert_eq!(s.visible_reflection_pdf(frame(), Vec3::Z, Vec3::Z, -Vec3::Z).unwrap(), 0.0);
+ assert!(s.sample_visible_reflection(frame(), Vec3::Z, -Vec3::Z, [0.2, 0.2]).unwrap().is_none());
+ let tilted = VisualFrame::new(Vec3::new(0.8, 0.0, 0.6), Vec3::Y).unwrap();
+ assert_eq!(s.visible_reflection_pdf(tilted, Vec3::Z, Vec3::Z, Vec3::new(0.99, 0.0, -0.1)).unwrap(), 0.0);
+}
+
+#[test]
+fn unit_roughness_visible_normal_density_integrates_to_one() {
+ const N: usize = 256;
+ let s = white(1.0, 1.0);
+ for view in [Vec3::Z, unit_direction(Vec3::new(1.0, 0.0, 0.2)).unwrap()] {
+ let mut mass = 0.0;
+ for i in 0..N {
+ let z = (i as f64 + 0.5) / N as f64;
+ let radius = ((1.0 - z) * (1.0 + z)).sqrt();
+ for j in 0..N {
+ let phi = TAU * (j as f64 + 0.5) / N as f64;
+ mass += s.visible_normal_pdf(frame(), view, Vec3::new(radius * phi.cos(), radius * phi.sin(), z)).unwrap();
+ }
+ }
+ close(mass * TAU / (N * N) as f64, 1.0, 0.002);
+ }
+}
+
+fn oblique_rotation(v: Vec3) -> Vec3 {
+ // Original Rodrigues construction about an axis with all three components.
+ let axis = unit_direction(Vec3::new(1.0, 2.0, 3.0)).unwrap();
+ let (sine, cosine) = 0.71_f64.sin_cos();
+ v * cosine + axis.cross(v) * sine + axis * (axis.dot(v) * (1.0 - cosine))
+}
+
+#[test]
+fn visible_samples_and_densities_follow_an_arbitrarily_tilted_visual_frame() {
+ let s = white(0.65, 0.9);
+ let tilted = VisualFrame::new(oblique_rotation(Vec3::Z), oblique_rotation(Vec3::X)).unwrap();
+ let v = unit_direction(Vec3::new(0.3, -0.2, 1.0)).unwrap();
+ let geometric = unit_direction(Vec3::new(0.1, 0.0, 1.0)).unwrap();
+ for uv in [[0.0, 0.0], [0.1, 0.3], [0.5, 0.7], [0.9, 0.2]] {
+ let h = s.sample_visible_normal(frame(), v, uv).unwrap().unwrap();
+ let rotated_h = s.sample_visible_normal(tilted, oblique_rotation(v), uv).unwrap().unwrap();
+ assert!((oblique_rotation(h) - rotated_h).len() < 1e-11);
+ close(s.visible_normal_pdf(frame(), v, h).unwrap(), s.visible_normal_pdf(tilted, oblique_rotation(v), rotated_h).unwrap(), 1e-10);
+ match (
+ s.sample_visible_reflection(frame(), geometric, v, uv).unwrap(),
+ s.sample_visible_reflection(tilted, oblique_rotation(geometric), oblique_rotation(v), uv).unwrap(),
+ ) {
+ (Some(a), Some(b)) => {
+ assert!((oblique_rotation(a.direction) - b.direction).len() < 1e-10);
+ assert!((a.weight - b.weight).len() < 1e-10);
+ close(a.pdf, b.pdf, 1e-10);
+ }
+ (None, None) => {}
+ _ => panic!("tilting changed support away from a hemisphere boundary"),
+ }
+ }
+}
+
+#[test]
+fn tilted_grazing_and_cap_opposition_are_finite_with_explicit_null_support() {
+ let tilted = VisualFrame::new(oblique_rotation(Vec3::Z), oblique_rotation(Vec3::X)).unwrap();
+ // A resolved 1e-6/1e-9 elevation, rather than an unrepresentable subnormal
+ // added to O(1) world components. The existing frame-Z subnormal test stays.
+ for elevation in [1e-6, 1e-9] {
+ let local_view = unit_direction(Vec3::new(1.0, 0.0, elevation)).unwrap();
+ let view = oblique_rotation(local_view);
+ for (rx, ry) in [(0.65, 0.9), (0.9, 0.65), (MIN_ROUGHNESS, 1.0)] {
+ let s = white(rx, ry);
+ for radial in [0.0, 0.5, 1.0_f64.next_down()] {
+ // Azimuth 1/2 opposes the stretched view's positive X component;
+ // radial→1 approaches the lower cap boundary (w+c cancellation).
+ for azimuth in [0.5_f64.next_down(), 0.5, 0.5_f64.next_up()] {
+ let uv = [radial, azimuth];
+ let h = s.sample_visible_normal(tilted, view, uv).unwrap().unwrap();
+ assert!(h.is_finite());
+ close(h.len(), 1.0, 1e-13);
+ let pdf_h = s.visible_normal_pdf(tilted, view, h).unwrap();
+ assert!(pdf_h.is_finite() && pdf_h >= 0.0);
+ if let Some(sample) = s.sample_visible_reflection(tilted, tilted.normal(), view, uv).unwrap() {
+ assert!(sample.direction.dot(tilted.normal()) > 0.0);
+ assert!(sample.pdf.is_finite() && sample.pdf > 0.0 && sample.weight.is_finite());
+ close(sample.pdf, s.visible_reflection_pdf(tilted, tilted.normal(), view, sample.direction).unwrap(), 1e-12);
+ }
+ }
+ }
+ // Both sides of the shading horizon have explicit support. This
+ // avoids inferring a sign from an exactly tangent, rounded dot.
+ assert!(s.sample_visible_normal(tilted, oblique_rotation(Vec3::new(1.0, 0.0, -elevation)), [0.2, 0.3]).unwrap().is_none());
+ assert_eq!(s.visible_normal_pdf(tilted, oblique_rotation(Vec3::new(1.0, 0.0, -elevation)), tilted.normal()).unwrap(), 0.0);
+ }
+ }
+}
+
+fn independent_visible_density(rx: f64, ry: f64, v: Vec3, h: Vec3) -> f64 {
+ if v.z <= 0.0 || h.z <= 0.0 || v.dot(h) <= 0.0 {
+ return 0.0;
+ }
+ let (ax, ay) = (rx * rx, ry * ry);
+ let q = (h.x / ax).powi(2) + (h.y / ay).powi(2) + h.z * h.z;
+ let distribution = 1.0 / (PI * ax * ay * q * q);
+ let masking_over_cosine = 2.0 / (v.z + (v.z * v.z + (ax * v.x).powi(2) + (ay * v.y).powi(2)).sqrt());
+ distribution * masking_over_cosine * v.dot(h)
+}
+
+#[test]
+fn unequal_axes_normal_view_has_analytic_acceptance_and_unconditional_pdf_mass() {
+ const N: usize = 256;
+ for (rx, ry) in [(0.65_f64, 0.9_f64), (0.9, 0.65)] {
+ let s = white(rx, ry);
+ let (ax, ay) = (rx * rx, ry * ry);
+ // At v=n, tan²(theta_h)=u/(1-u)*(ax² cos²(phi)+ay² sin²(phi)).
+ // l.z>0 iff u<1/(1+ax² cos²(phi)+ay² sin²(phi)); integrating phi
+ // gives 1/sqrt((1+ax²)*(1+ay²)), not a density normalized to success.
+ let acceptance = 1.0 / ((1.0 + ax * ax) * (1.0 + ay * ay)).sqrt();
+ let (mut accepted, mut nulls, mut pdf_mass, mut normal_mass) = (0, 0, 0.0, 0.0);
+ for i in 0..N {
+ let u = (i as f64 + 0.5) / N as f64;
+ let radius = ((1.0 - u) * (1.0 + u)).sqrt();
+ for j in 0..N {
+ let t = (j as f64 + 0.5) / N as f64;
+ let phi = TAU * t;
+ let direction = Vec3::new(radius * phi.cos(), radius * phi.sin(), u);
+ let half = unit_direction(Vec3::Z + direction).unwrap();
+ let expected_pdf = independent_visible_density(rx, ry, Vec3::Z, half) / (4.0 * half.z);
+ close(s.visible_reflection_pdf(frame(), Vec3::Z, Vec3::Z, direction).unwrap(), expected_pdf, 1e-12);
+ pdf_mass += expected_pdf;
+ normal_mass += independent_visible_density(rx, ry, Vec3::Z, direction);
+ if s.sample_visible_reflection(frame(), Vec3::Z, Vec3::Z, [u, t]).unwrap().is_some() {
+ accepted += 1;
+ } else {
+ nulls += 1;
+ }
+ }
+ }
+ assert_eq!(accepted + nulls, N * N);
+ assert!(nulls > 0);
+ // Midpoint radial acceptance has <=1/N counting error per azimuth;
+ // smooth-azimuth and solid-angle quadrature remain separate checks.
+ close(accepted as f64 / (N * N) as f64, acceptance, 1.0 / N as f64);
+ close(pdf_mass * TAU / (N * N) as f64, acceptance, 0.002);
+ close(normal_mass * TAU / (N * N) as f64, 1.0, 0.002);
+ assert!(pdf_mass * TAU / ((N * N) as f64) < 1.0);
+ }
+}
+
+#[test]
+fn unequal_axes_grazing_pdf_mass_matches_attempts_and_geometric_rejection() {
+ const N: usize = 256;
+ let s = white(0.65, 0.9);
+ let view = unit_direction(Vec3::new(1.0, 0.2, 0.1)).unwrap();
+ let geometric = unit_direction(Vec3::new(-0.05, 0.0, 1.0)).unwrap();
+ let (mut accepted, mut nulls, mut mass, mut normal_mass) = (0, 0, 0.0, 0.0);
+ for i in 0..N {
+ let u = (i as f64 + 0.5) / N as f64;
+ let radius = ((1.0 - u) * (1.0 + u)).sqrt();
+ for j in 0..N {
+ let t = (j as f64 + 0.5) / N as f64;
+ let phi = TAU * t;
+ let light = Vec3::new(radius * phi.cos(), radius * phi.sin(), u);
+ let half = unit_direction(view + light).unwrap();
+ let expected = if geometric.dot(light) > 0.0 { independent_visible_density(0.65, 0.9, view, half) / (4.0 * view.dot(half)) } else { 0.0 };
+ close(s.visible_reflection_pdf(frame(), geometric, view, light).unwrap(), expected, 1e-11);
+ mass += expected;
+ normal_mass += independent_visible_density(0.65, 0.9, view, light);
+ if s.sample_visible_reflection(frame(), geometric, view, [u, t]).unwrap().is_some() {
+ accepted += 1;
+ } else {
+ nulls += 1;
+ }
+ }
+ }
+ assert_eq!(accepted + nulls, N * N);
+ assert!(accepted > 0 && nulls > 0);
+ let integrated = mass * TAU / (N * N) as f64;
+ // A discontinuous geometric-hemisphere cut and two independently parameterized
+ // midpoint grids have a finite 0.01 agreement gate; no universal error bound.
+ close(integrated, accepted as f64 / (N * N) as f64, 0.01);
+ close(normal_mass * TAU / (N * N) as f64, 1.0, 0.002);
+ assert!(integrated > 0.0 && integrated < 1.0);
+}
diff --git a/crates/render/src/clear_coat.rs b/crates/render/src/clear_coat.rs
new file mode 100644
index 0000000000..688819e070
--- /dev/null
+++ b/crates/render/src/clear_coat.rs
@@ -0,0 +1,201 @@
+//! Original single-scattering GGX dielectric coat over the opaque surface oracle.
+//! The substrate is attenuated at entry and exit; internal inter-layer scattering
+//! and refraction of substrate directions are omitted. This is a bounded preview
+//! model, not a full layered random walk. See docs/render-clear-coat.md.
+use crate::surface::{MIN_ROUGHNESS, OpaqueSurface, SurfaceError, unit_direction};
+use solidcraft_geom::Vec3;
+use std::f64::consts::PI;
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct ClearCoat {
+ weight: f64,
+ roughness: f64,
+ ior: f64,
+}
+
+impl ClearCoat {
+ pub fn new(weight: f64, roughness: f64, ior: f64) -> Result<Self, SurfaceError> {
+ if !weight.is_finite() || !(0.0..=1.0).contains(&weight) {
+ return Err(SurfaceError::CoatWeight);
+ }
+ if !roughness.is_finite() || !(MIN_ROUGHNESS..=1.0).contains(&roughness) {
+ return Err(SurfaceError::Roughness);
+ }
+ if !ior.is_finite() || !(1.0..=3.0).contains(&ior) {
+ return Err(SurfaceError::DielectricIor);
+ }
+ Ok(Self { weight, roughness, ior })
+ }
+ pub fn weight(self) -> f64 {
+ self.weight
+ }
+ pub fn roughness(self) -> f64 {
+ self.roughness
+ }
+ pub fn ior(self) -> f64 {
+ self.ior
+ }
+ fn fresnel(self, c: f64) -> f64 {
+ let ratio = (self.ior - 1.0) / (self.ior + 1.0);
+ let f0 = ratio * ratio;
+ f0 + (1.0 - f0) * (1.0 - c).powi(5)
+ }
+ /// Upper bound on coat directional reflectance: over the upper hemisphere,
+ /// v.h >= nv/sqrt(2*(1+sqrt(1-nv^2))). Schlick decreases with v.h and
+ /// the unit-Fresnel single-scattering Smith GGX lobe reflects at most one.
+ fn energy_bound(self, cosine: f64) -> f64 {
+ self.fresnel(cosine / (2.0 * (1.0 + (1.0 - cosine * cosine).max(0.0).sqrt())).sqrt())
+ }
+ pub(crate) fn layer(self, base: Vec3, nv: f64, nl: f64, nh: f64, vh: f64) -> Vec3 {
+ let a2 = self.roughness.powi(4);
+ let denom = (1.0 - nh * nh) + nh * nh * a2;
+ let d = a2 / (PI * denom * denom);
+ let visibility = |c: f64| 2.0 / (c + (a2 + (1.0 - a2) * c * c).sqrt());
+ let coat = self.weight * self.fresnel(vh) * d * 0.25 * visibility(nv) * visibility(nl);
+ let attenuation = (1.0 - self.weight * self.energy_bound(nv)) * (1.0 - self.weight * self.energy_bound(nl));
+ base * attenuation + Vec3::new(coat, coat, coat)
+ }
+}
+
+/// Conditional opaque-lobe PDF, including the coat and base mixture. Rejected
+/// below-surface microfacet samples retain their mass; never renormalize them.
+pub fn surface_pdf(surface: OpaqueSurface, normal: Vec3, view: Vec3, light: Vec3) -> Result<f64, SurfaceError> {
+ let n = unit_direction(normal)?;
+ let v = unit_direction(view)?;
+ let l = unit_direction(light)?;
+ let nl = n.dot(l);
+ if nl <= 0.0 || n.dot(v) <= 0.0 {
+ return Ok(0.0);
+ }
+ let h = unit_direction(v + l)?;
+ let nh = n.dot(h).clamp(0.0, 1.0);
+ let vh = v.dot(h).max(1e-20);
+ let ggx = |roughness: f64| {
+ let a2 = roughness.powi(4);
+ let d = (1.0 - nh * nh) + nh * nh * a2;
+ a2 / (PI * d * d) * nh / (4.0 * vh)
+ };
+ let base = 0.5 * nl / PI + 0.5 * ggx(surface.roughness());
+ Ok(surface.clear_coat().map_or(base, |coat| {
+ let p = coat.weight() * 0.5;
+ (1.0 - p) * base + p * ggx(coat.roughness())
+ }))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ #[test]
+ fn admission_zero_coat_and_reciprocity() {
+ for bad in [f64::NAN, f64::INFINITY, -0.1, 1.1] {
+ assert!(ClearCoat::new(bad, 0.2, 1.5).is_err());
+ }
+ for bad in [0.0, 0.044, 1.1, f64::NAN] {
+ assert!(ClearCoat::new(1.0, bad, 1.5).is_err());
+ }
+ for bad in [0.99, 3.01, f64::NAN] {
+ assert!(ClearCoat::new(1.0, 0.2, bad).is_err());
+ }
+ let base = OpaqueSurface::new(Vec3::new(0.01, 0.02, 0.03), 0.0, 0.3, 1.5).unwrap();
+ assert_eq!(base, base.with_clear_coat(ClearCoat::new(0.0, 0.1, 1.5).unwrap()));
+ let coated = base.with_clear_coat(ClearCoat::new(1.0, 0.12, 1.5).unwrap());
+ let v = Vec3::new(0.5, 0.0, 0.8);
+ let l = Vec3::new(-0.3, 0.2, 0.6);
+ assert!((coated.brdf(Vec3::Z, v, l).unwrap() - coated.brdf(Vec3::Z, l, v).unwrap()).len() < 1e-12);
+ assert!(coated.brdf(Vec3::Z, Vec3::Z, Vec3::Z).unwrap().x > base.brdf(Vec3::Z, Vec3::Z, Vec3::Z).unwrap().x);
+ // Normal incidence: D=1/(pi*roughness^4), G=1, Fresnel=.04.
+ let expected = base.brdf(Vec3::Z, Vec3::Z, Vec3::Z).unwrap() * (1.0 - ClearCoat::new(1.0, 0.12, 1.5).unwrap().energy_bound(1.0)).powi(2)
+ + Vec3::new(1.0, 1.0, 1.0) * (0.04 / (4.0 * PI * 0.12_f64.powi(4)));
+ assert!((coated.brdf(Vec3::Z, Vec3::Z, Vec3::Z).unwrap() - expected).len() < 1e-10);
+ }
+ #[test]
+ fn layered_white_furnace_and_pdf_quadrature() {
+ // Deterministic quadrature resolves these lobes; it is not a proof for
+ // arbitrary roughness. Narrow coat lobes have separate GPU oracle checks.
+ for roughness in [0.25, 0.5, 1.0] {
+ for metallic in [0.0, 1.0] {
+ for cosine in [0.2_f64, 1.0] {
+ let s = OpaqueSurface::new(Vec3::new(1.0, 1.0, 1.0), metallic, 0.5, 1.5)
+ .unwrap()
+ .with_clear_coat(ClearCoat::new(1.0, roughness, 1.5).unwrap());
+ let v = Vec3::new((1.0 - cosine * cosine).sqrt(), 0.0, cosine);
+ let mut energy = 0.0;
+ let mut probability = 0.0;
+ for i in 0..256 {
+ let mu = (f64::from(i) + 0.5) / 256.0;
+ let r = (1.0 - mu * mu).sqrt();
+ for j in 0..256 {
+ let phi = 2.0 * PI * (f64::from(j) + 0.5) / 256.0;
+ let l = Vec3::new(r * phi.cos(), r * phi.sin(), mu);
+ energy += s.brdf(Vec3::Z, v, l).unwrap().x * mu;
+ probability += surface_pdf(s, Vec3::Z, v, l).unwrap();
+ }
+ }
+ energy *= 2.0 * PI / 65536.0;
+ probability *= 2.0 * PI / 65536.0;
+ assert!(energy <= 1.025, "roughness={roughness} metal={metallic} cosine={cosine} energy={energy}");
+ assert!((0.2..=1.005).contains(&probability), "{probability}");
+ }
+ }
+ }
+ }
+
+ #[test]
+ fn conservative_bound_and_layer_furnace_include_shiny_bases_and_grazing() {
+ const COUNT: u32 = 4096;
+ let mut maximum = 0.0_f64;
+ for base_roughness in [0.045, 0.12, 0.5, 1.0] {
+ for coat_roughness in [0.12, 0.5, 1.0] {
+ for weight in [0.25, 1.0] {
+ for ior in [1.0, 1.5, 3.0] {
+ for cosine in [0.02_f64, 0.2, 1.0] {
+ for metallic in [0.0, 1.0] {
+ let coat = ClearCoat::new(weight, coat_roughness, ior).unwrap();
+ let surface =
+ OpaqueSurface::new(Vec3::new(1.0, 1.0, 1.0), metallic, base_roughness, 1.5).unwrap().with_clear_coat(coat);
+ let v = Vec3::new((1.0 - cosine * cosine).sqrt(), 0.0, cosine);
+ let p = weight * 0.5;
+ let mut energy = 0.0;
+ // Integrate each proposal with its mixture probability.
+ // NDF importance quadrature resolves sharp lobes, unlike
+ // a uniform hemisphere grid at roughness 0.045.
+ for (component, probability) in [(0, (1.0 - p) * 0.5), (1, (1.0 - p) * 0.5), (2, p)] {
+ for i in 0..COUNT {
+ let x = (f64::from(i) + 0.5) / f64::from(COUNT);
+ let phi = 2.0 * PI * f64::from(i.reverse_bits()) / 4294967296.0;
+ let l = if component == 0 {
+ Vec3::new(x.sqrt() * phi.cos(), x.sqrt() * phi.sin(), (1.0 - x).sqrt())
+ } else {
+ let r = if component == 1 { base_roughness } else { coat_roughness };
+ let c = ((1.0 - x) / (1.0 + (r.powi(4) - 1.0) * x)).sqrt();
+ let radius = (1.0 - c * c).sqrt();
+ let h = Vec3::new(radius * phi.cos(), radius * phi.sin(), c);
+ h * (2.0 * v.dot(h)) - v
+ };
+ if l.z <= 0.0 {
+ continue;
+ }
+ let h = unit_direction(v + l).unwrap();
+ assert!(coat.fresnel(v.dot(h).clamp(0.0, 1.0)) <= coat.energy_bound(cosine) + 1e-12);
+ let pdf = surface_pdf(surface, Vec3::Z, v, l).unwrap();
+ energy += probability * surface.brdf(Vec3::Z, v, l).unwrap().x * l.z / pdf / f64::from(COUNT);
+ }
+ }
+ maximum = maximum.max(energy);
+ assert!(
+ energy.is_finite() && energy <= 1.003,
+ "base={base_roughness}, coat={coat_roughness}, w={weight}, ior={ior}, nv={cosine}, m={metallic}: {energy}"
+ );
+ }
+ }
+ }
+ }
+ }
+ }
+ eprintln!("maximum conservative layered furnace reflectance: {maximum}");
+ for cosine in [0.0, 1e-300, 1e-20, 0.02, 1.0] {
+ let bound = ClearCoat::new(1.0, 0.12, 1.5).unwrap().energy_bound(cosine);
+ assert!(bound.is_finite() && (0.0..=1.0).contains(&bound));
+ }
+ }
+}
diff --git a/crates/render/src/dielectric_oracle_tests.rs b/crates/render/src/dielectric_oracle_tests.rs
new file mode 100644
index 0000000000..51c7c3add9
--- /dev/null
+++ b/crates/render/src/dielectric_oracle_tests.rs
@@ -0,0 +1,78 @@
+//! Original MIT OR Apache-2.0 analytic fixtures for the shared CPU/GPU dielectric contract.
+//! Provenance: elementary Fresnel s/p equations, Snell law and Beer-Lambert attenuation.
+//! No external assets or renderer outputs. Tolerances are absolute f64 errors stated per assertion.
+//! Import this test module with the optical math module; only the API adapter needs changing.
+use super::*;
+
+#[test]
+fn oblique_polarizations_and_snell_match_independent_angle_equations() {
+ let brewster = 1.5_f64.atan();
+ for angle in [0.3, brewster - 1e-4, brewster, brewster + 1e-4, 1.2] {
+ let transmitted_angle = (angle.sin() / 1.5).asin();
+ let expected_s = ((angle - transmitted_angle).sin() / (angle + transmitted_angle).sin()).powi(2);
+ let expected_p = ((angle - transmitted_angle).tan() / (angle + transmitted_angle).tan()).powi(2);
+ let actual = fresnel(angle.cos(), 1.0, 1.5).unwrap();
+ assert!((actual.s - expected_s).abs() < 1e-14);
+ assert!((actual.p - expected_p).abs() < 1e-14);
+ let incident = Vec3::new(angle.sin(), 0.0, -angle.cos());
+ let outgoing = refract(incident, Vec3::Z, 1.0, 1.5).unwrap().unwrap();
+ assert!((outgoing.x - transmitted_angle.sin()).abs() < 1e-14);
+ assert!((outgoing.z + transmitted_angle.cos()).abs() < 1e-14);
+ let reversed = refract(-outgoing, -Vec3::Z, 1.5, 1.0).unwrap().unwrap();
+ assert!((reversed + incident).len() < 1e-13);
+ }
+ let critical = (1.0_f64 / 1.5).asin();
+ assert!(fresnel((critical - 1e-5).cos(), 1.5, 1.0).unwrap().transmitted_cosine.is_some());
+ assert!(fresnel((critical + 1e-5).cos(), 1.5, 1.0).unwrap().transmitted_cosine.is_none());
+ assert!(refract(Vec3::new(0.9, 0.0, -(1.0_f64 - 0.81).sqrt()), Vec3::Z, 1.5, 1.0).unwrap().is_none());
+ let zero_sheet = Transmission::new(Vec3::new(100.0, 100.0, 100.0), Some(0.0)).unwrap();
+ let (r, t) = slab(zero_sheet, 0.0, 1.0, 1.0, 1.5).unwrap();
+ assert!((r.x + t.x - 1.0).abs() < 1e-14);
+ assert!((t.x - 0.96_f64.powi(2) / (1.0 - 0.04_f64.powi(2))).abs() < 1e-14);
+}
+
+#[test]
+fn exact_fresnel_brewster_critical_and_index_matched_limits() {
+ for n in [1.0_f64, 1.33, 1.5, 3.0] {
+ assert!((fresnel(1.0, 1.0, n).unwrap().reflectance() - ((n - 1.0) / (n + 1.0)).powi(2)).abs() < 1e-15);
+ assert!(fresnel(n.atan().cos(), 1.0, n).unwrap().p < 1e-30);
+ }
+ assert_eq!(fresnel(0.5, 1.5, 1.0).unwrap().transmitted_cosine, None);
+ assert_eq!(fresnel(0.0, 1.0, 1.0).unwrap().reflectance(), 0.0);
+ assert_eq!(fresnel(0.0, 1.0, 1.5).unwrap().reflectance(), 1.0);
+ for cosine in [0.01, 0.3, 0.9, 1.0] {
+ let f = fresnel(cosine, 1.0, 1.5).unwrap();
+ let reverse = fresnel(f.transmitted_cosine.unwrap(), 1.5, 1.0).unwrap();
+ assert!((f.reflectance() - reverse.reflectance()).abs() < 1e-12);
+ }
+}
+
+#[test]
+fn beer_lambert_slab_and_lossless_energy() {
+ let t = Transmission::new(Vec3::new(-0.5_f64.ln(), -0.8_f64.ln(), 0.0) / 10.0, None).unwrap();
+ assert!((t.attenuation(20.0).unwrap() - Vec3::new(0.25, 0.64, 1.0)).len() < 1e-15);
+ let (r, through) = slab(t, 10.0, 1.0, 1.0, 1.5).unwrap();
+ assert!((through.x - 0.96_f64.powi(2) * 0.5 / (1.0 - 0.04_f64.powi(2) * 0.25)).abs() < 1e-15);
+ assert!((r.z + through.z - 1.0).abs() < 1e-15);
+ assert!(r.x + through.x < 1.0);
+ let clear = Transmission::new(Vec3::ZERO, None).unwrap();
+ for cosine in [0.001, 0.1, 0.5, 1.0] {
+ let (r, t) = slab(clear, 1.0, cosine, 1.0, 1.5).unwrap();
+ assert!((r.x + t.x - 1.0).abs() < 1e-13);
+ }
+}
+
+#[test]
+fn hostile_optics_are_rejected_without_clamping() {
+ for v in [f64::NAN, f64::INFINITY, -1.0, 100.01] {
+ assert!(Transmission::new(Vec3::new(v, 0.0, 0.0), None).is_err());
+ }
+ for v in [f64::NAN, f64::INFINITY, -1.0, 10000.01] {
+ assert!(Transmission::new(Vec3::ZERO, Some(v)).is_err());
+ }
+ assert!(Transmission::new(Vec3::ZERO, Some(0.0)).is_ok());
+ assert!(fresnel(f64::NAN, 1.0, 1.5).is_err());
+ assert!(fresnel(0.5, f64::INFINITY, 1.5).is_err());
+ assert!(refract(Vec3::ZERO, Vec3::Z, 1.0, 1.5).is_err());
+ assert!(refract(Vec3::Z, Vec3::Z, 1.0, 1.5).is_err());
+}
diff --git a/crates/render/src/film.rs b/crates/render/src/film.rs
new file mode 100644
index 0000000000..9e102c3501
--- /dev/null
+++ b/crates/render/src/film.rs
@@ -0,0 +1,226 @@
+//! Bounded linear RGB statistics, independent of rendering and display transforms.
+//! Samples use the renderer's linear-sRGB primaries; source HDR conversion is a
+//! caller prerequisite. Display-sRGB primary backgrounds need a separate coverage
+//! policy before camera samples can be mixed; this module does not invent one.
+//!
+//! The caller reserves `required_bytes` in its EXISTING job/host lease before
+//! construction, and supplies a charge callback debiting that job's cumulative
+//! work budget. This module creates no pool, thread, cache or cancellation token.
+//! Fallible allocation checks actual capacity against that same admission.
+//!
+//! Samples for each pixel must arrive in the same order for bitwise reproducible
+//! results. Splitting contiguous updates into smaller calls preserves that order;
+//! arbitrary floating-point reductions or reordered samples are not equivalent.
+//!
+//! `complete_pass` borrows the film immutably and refuses uneven/empty counts.
+//! Its iterator exposes linear means only; the consumer applies exposure, tone
+//! mapping and encoding ONCE, in bounded cancellable chunks. Publishing requires
+//! a fully resolved owned snapshot with its own host lease, generation check and
+//! cancellation/publication lock. Neither a partial update nor this borrowed view
+//! is a publishable frame. Progressive host/UI wiring is a separate integration.
+
+use crate::job::{CancelToken, ErrorCode, JobError, Result};
+
+pub const MAX_DIMENSION: u32 = 16_384;
+pub const MAX_PIXELS: usize = 16_777_216;
+pub const MAX_SAMPLES: u32 = 1_048_576;
+pub const MAX_UPDATE: usize = 256;
+pub const MAX_BYTES: u64 = 384 * 1024 * 1024;
+
+#[derive(Clone, Copy, Debug, Default, PartialEq)]
+struct Pixel {
+ mean: [f64; 3],
+ m2: [f64; 3],
+ count: u32,
+}
+
+/// Unbiased sample variance, zero by convention before two samples.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct PixelStatistics {
+ pub mean: [f64; 3],
+ pub variance: [f64; 3],
+ pub count: u32,
+}
+
+/// Storage stays private so callers cannot bypass finite/count invariants.
+pub struct FilmAccumulator {
+ width: u32,
+ height: u32,
+ sample_limit: u32,
+ pixels: Vec<Pixel>,
+}
+
+/// An immutable uniform pass; not an owned or publishable preview image.
+pub struct CompletePass<'a> {
+ film: &'a FilmAccumulator,
+ samples_per_pixel: u32,
+}
+
+fn invalid(message: &'static str) -> JobError {
+ JobError::new(ErrorCode::InvalidRequest, message)
+}
+fn limit(message: &'static str) -> JobError {
+ JobError::new(ErrorCode::LimitExceeded, message)
+}
+
+fn dimensions(width: u32, height: u32, sample_limit: u32) -> Result<usize> {
+ if width == 0 || height == 0 || width > MAX_DIMENSION || height > MAX_DIMENSION || sample_limit == 0 || sample_limit > MAX_SAMPLES {
+ return Err(invalid("invalid film dimensions or sample limit"));
+ }
+ let pixels = u64::from(width).checked_mul(u64::from(height)).ok_or_else(|| limit("film dimensions overflow"))?;
+ usize::try_from(pixels).ok().filter(|n| *n <= MAX_PIXELS).ok_or_else(|| limit("film pixel limit exceeded"))
+}
+
+fn bytes_for_capacity(capacity: usize) -> Result<u64> {
+ let bytes = u64::try_from(capacity)
+ .ok()
+ .and_then(|n| n.checked_mul(std::mem::size_of::<Pixel>() as u64))
+ .and_then(|n| n.checked_add(std::mem::size_of::<FilmAccumulator>() as u64))
+ .and_then(|n| n.checked_add(std::mem::size_of::<[Pixel; MAX_UPDATE]>() as u64))
+ .filter(|n| *n <= MAX_BYTES)
+ .ok_or_else(|| limit("film storage limit exceeded"))?;
+ Ok(bytes)
+}
+
+impl Pixel {
+ fn updated(self, rgb: [f64; 3], sample_limit: u32) -> Result<Self> {
+ if rgb.iter().any(|c| !c.is_finite() || *c < 0.0) {
+ return Err(invalid("film samples must be finite nonnegative linear RGB"));
+ }
+ let count = self.count.checked_add(1).filter(|n| *n <= sample_limit).ok_or_else(|| limit("film sample limit exceeded"))?;
+ let mut result = self;
+ for ((mean, m2), value) in result.mean.iter_mut().zip(result.m2.iter_mut()).zip(rgb) {
+ let delta = value - *mean;
+ *mean += delta / f64::from(count);
+ *m2 += delta * (value - *mean);
+ if !mean.is_finite() || !m2.is_finite() || *mean < 0.0 || *m2 < 0.0 {
+ return Err(invalid("film statistics exceed finite numeric range"));
+ }
+ }
+ result.count = count;
+ Ok(result)
+ }
+
+ fn statistics(self) -> PixelStatistics {
+ let denominator = f64::from(self.count.saturating_sub(1).max(1));
+ PixelStatistics { mean: self.mean, variance: self.m2.map(|m2| m2 / denominator), count: self.count }
+ }
+}
+
+impl FilmAccumulator {
+ /// Required host-admitted storage, including the film object and the bounded
+ /// atomic-update stack scratch used while this film is alive. Allocator
+ /// bookkeeping is outside this byte contract; actual Vec capacity is checked.
+ pub fn required_bytes(width: u32, height: u32, sample_limit: u32) -> Result<u64> {
+ bytes_for_capacity(dimensions(width, height, sample_limit)?)
+ }
+
+ /// `admitted_bytes` is an existing host lease amount, not a second pool.
+ /// The caller must preserve that lease for this object's entire lifetime.
+ pub fn new(
+ width: u32,
+ height: u32,
+ sample_limit: u32,
+ admitted_bytes: u64,
+ cancel: &CancelToken,
+ charge: &mut impl FnMut(u64) -> Result<()>,
+ ) -> Result<Self> {
+ cancel.check()?;
+ let count = dimensions(width, height, sample_limit)?;
+ let required = bytes_for_capacity(count)?;
+ if admitted_bytes < required || admitted_bytes > MAX_BYTES {
+ return Err(limit("film is not covered by caller admission"));
+ }
+ let mut pixels = Vec::new();
+ pixels.try_reserve_exact(count).map_err(|_| JobError::new(ErrorCode::AllocationFailed, "could not reserve film storage"))?;
+ if bytes_for_capacity(pixels.capacity())? > admitted_bytes {
+ return Err(limit("actual film capacity exceeds caller admission"));
+ }
+ for _ in 0..count {
+ cancel.check()?;
+ charge(1)?;
+ pixels.push(Pixel::default());
+ }
+ cancel.check()?;
+ Ok(Self { width, height, sample_limit, pixels })
+ }
+
+ pub fn dimensions(&self) -> (u32, u32) {
+ (self.width, self.height)
+ }
+
+ /// Actual retained capacity plus object and maximum update scratch allowance.
+ pub fn allocated_bytes(&self) -> Result<u64> {
+ bytes_for_capacity(self.pixels.capacity())
+ }
+
+ /// For diagnostics/variance decisions, not partially published image output.
+ pub fn pixel_statistics(&self, index: usize) -> Result<PixelStatistics> {
+ self.pixels.get(index).copied().map(Pixel::statistics).ok_or_else(|| invalid("film pixel index out of range"))
+ }
+
+ /// One sample per consecutive pixel, at most MAX_UPDATE. Validate the whole
+ /// update before mutation. Validation/commit work is charged up front; failed
+ /// work/cancel/input checks leave the film unchanged (budget stays consumed).
+ /// After the last cancellation check, bounded commit is the linearization
+ /// point: cancellation during commit is observed by the caller before publish.
+ pub fn add_range(&mut self, start: usize, samples: &[[f64; 3]], cancel: &CancelToken, charge: &mut impl FnMut(u64) -> Result<()>) -> Result<()> {
+ cancel.check()?;
+ if samples.is_empty() || samples.len() > MAX_UPDATE {
+ return Err(invalid("film update must contain 1..256 samples"));
+ }
+ let end = start.checked_add(samples.len()).ok_or_else(|| invalid("film update range overflow"))?;
+ let pixels = self.pixels.get(start..end).ok_or_else(|| invalid("film update range out of bounds"))?;
+ // Fixed bounded stack scratch gives atomic commit without a second heap
+ // buffer or recomputation that might fail after earlier pixels mutated.
+ let mut staged = [Pixel::default(); MAX_UPDATE];
+ for ((pixel, sample), target) in pixels.iter().zip(samples).zip(staged.iter_mut()) {
+ cancel.check()?;
+ charge(2)?;
+ *target = pixel.updated(*sample, self.sample_limit)?;
+ }
+ cancel.check()?;
+ let target = self.pixels.get_mut(start..end).ok_or_else(|| invalid("film update range changed"))?;
+ target.copy_from_slice(staged.get(..samples.len()).ok_or_else(|| invalid("film staging range invalid"))?);
+ Ok(())
+ }
+
+ /// No allocation and no display transform. Each checked pixel charges one
+ /// unit to the same job and checks its cancellation token.
+ pub fn complete_pass<'a>(&'a self, cancel: &CancelToken, charge: &mut impl FnMut(u64) -> Result<()>) -> Result<CompletePass<'a>> {
+ cancel.check()?;
+ let count = self.pixels.first().map(|p| p.count).ok_or_else(|| invalid("film has no pixels"))?;
+ if count == 0 {
+ return Err(invalid("film has no complete pass"));
+ }
+ for pixel in &self.pixels {
+ cancel.check()?;
+ charge(1)?;
+ if pixel.count != count {
+ return Err(invalid("film pass is incomplete"));
+ }
+ }
+ cancel.check()?;
+ Ok(CompletePass { film: self, samples_per_pixel: count })
+ }
+}
+
+impl CompletePass<'_> {
+ pub fn samples_per_pixel(&self) -> u32 {
+ self.samples_per_pixel
+ }
+
+ pub fn dimensions(&self) -> (u32, u32) {
+ self.film.dimensions()
+ }
+
+ /// Borrowed immutable linear means. Resolving/copying/encoding and its work
+ /// accounting/cancellation remain caller-owned; no output buffer is allocated.
+ pub fn pixels(&self) -> impl ExactSizeIterator<Item = [f64; 3]> + '_ {
+ self.film.pixels.iter().map(|p| p.mean)
+ }
+}
+
+#[cfg(test)]
+#[path = "film_tests.rs"]
+mod tests;
diff --git a/crates/render/src/film_tests.rs b/crates/render/src/film_tests.rs
new file mode 100644
index 0000000000..60e5e5b3ea
--- /dev/null
+++ b/crates/render/src/film_tests.rs
@@ -0,0 +1,191 @@
+use super::*;
+
+fn film(width: u32, height: u32, limit: u32) -> FilmAccumulator {
+ let bytes = FilmAccumulator::required_bytes(width, height, limit).unwrap();
+ FilmAccumulator::new(width, height, limit, bytes, &CancelToken::default(), &mut |_| Ok(())).unwrap()
+}
+
+fn add(film: &mut FilmAccumulator, start: usize, values: &[[f64; 3]]) {
+ film.add_range(start, values, &CancelToken::default(), &mut |_| Ok(())).unwrap();
+}
+
+#[test]
+fn constant_and_alternating_samples_have_analytic_statistics() {
+ let mut film = film(2, 1, 4);
+ for value in [0.0, 2.0, 0.0, 2.0] {
+ add(&mut film, 0, &[[7.0, 3.0, 1.0], [value; 3]]);
+ }
+ assert_eq!(film.pixel_statistics(0).unwrap(), PixelStatistics { mean: [7.0, 3.0, 1.0], variance: [0.0; 3], count: 4 });
+ let statistics = film.pixel_statistics(1).unwrap();
+ assert_eq!(statistics.mean, [1.0; 3]);
+ assert_eq!(statistics.variance, [4.0 / 3.0; 3]);
+}
+
+#[test]
+fn complete_pass_refuses_empty_or_uneven_counts_and_keeps_linear_values() {
+ let mut film = film(2, 1, 3);
+ assert!(film.complete_pass(&CancelToken::default(), &mut |_| Ok(())).is_err());
+ add(&mut film, 0, &[[20.0, 2.0, 0.0]]);
+ assert!(film.complete_pass(&CancelToken::default(), &mut |_| Ok(())).is_err());
+ add(&mut film, 1, &[[4.0, 8.0, 16.0]]);
+ let pass = film.complete_pass(&CancelToken::default(), &mut |_| Ok(())).unwrap();
+ assert_eq!(pass.samples_per_pixel(), 1);
+ assert_eq!(pass.dimensions(), (2, 1));
+ assert_eq!(pass.pixels().collect::<Vec<_>>(), vec![[20.0, 2.0, 0.0], [4.0, 8.0, 16.0]]);
+}
+
+#[test]
+fn invalid_sample_at_end_leaves_entire_update_unchanged() {
+ for bad in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, -1.0] {
+ let mut film = film(2, 1, 3);
+ add(&mut film, 0, &[[1.0; 3], [2.0; 3]]);
+ let before = film.pixels.clone();
+ assert_eq!(film.add_range(0, &[[3.0; 3], [bad; 3]], &CancelToken::default(), &mut |_| Ok(())).unwrap_err().code, ErrorCode::InvalidRequest);
+ assert_eq!(film.pixels, before);
+ }
+}
+
+#[test]
+fn sample_limit_and_numeric_overflow_refuse_atomically() {
+ let mut limited = film(2, 1, 1);
+ add(&mut limited, 1, &[[1.0; 3]]);
+ let before = limited.pixels.clone();
+ assert_eq!(limited.add_range(0, &[[1.0; 3]; 2], &CancelToken::default(), &mut |_| Ok(())).unwrap_err().code, ErrorCode::LimitExceeded);
+ assert_eq!(limited.pixels, before);
+ let mut extreme = film(2, 1, 3);
+ add(&mut extreme, 0, &[[1.0; 3], [f64::MAX; 3]]);
+ let before = extreme.pixels.clone();
+ assert!(extreme.add_range(0, &[[2.0; 3], [0.0; 3]], &CancelToken::default(), &mut |_| Ok(())).is_err());
+ assert_eq!(extreme.pixels, before);
+}
+
+#[test]
+fn dimensions_bytes_and_actual_capacity_are_checked() {
+ for (width, height, samples) in [(0, 1, 1), (1, 0, 1), (u32::MAX, u32::MAX, 1), (1, 1, 0), (1, 1, MAX_SAMPLES + 1)] {
+ assert!(FilmAccumulator::required_bytes(width, height, samples).is_err());
+ }
+ assert!(FilmAccumulator::required_bytes(MAX_DIMENSION, MAX_DIMENSION, 1).is_err());
+ assert!(bytes_for_capacity(usize::MAX).is_err());
+ let bytes = FilmAccumulator::required_bytes(2, 2, 1).unwrap();
+ assert!(FilmAccumulator::new(2, 2, 1, bytes - 1, &CancelToken::default(), &mut |_| Ok(())).is_err());
+ let film = film(2, 2, 1);
+ assert!(film.allocated_bytes().unwrap() <= bytes);
+ assert_eq!(film.allocated_bytes().unwrap(), bytes_for_capacity(film.pixels.capacity()).unwrap());
+ assert!(film.allocated_bytes().unwrap() >= (std::mem::size_of::<Pixel>() * (4 + MAX_UPDATE)) as u64);
+}
+
+#[test]
+fn invalid_ranges_and_oversized_updates_preserve_state() {
+ let mut film = film(2, 1, 1);
+ for (start, values) in [(0, Vec::new()), (usize::MAX, vec![[1.0; 3]]), (2, vec![[1.0; 3]]), (0, vec![[1.0; 3]; MAX_UPDATE + 1])] {
+ assert!(film.add_range(start, &values, &CancelToken::default(), &mut |_| Ok(())).is_err());
+ assert!(film.pixels.iter().all(|p| *p == Pixel::default()));
+ }
+ assert!(film.pixel_statistics(2).is_err());
+}
+
+#[test]
+fn incremental_partitions_preserve_bitwise_results_in_sample_order() {
+ let mut whole = film(4, 1, 3);
+ let mut partitioned = film(4, 1, 3);
+ for values in [
+ [[1.0; 3], [1e12; 3], [0.25; 3], [4.0; 3]],
+ [[2.0; 3], [1e12 + 1.0; 3], [0.5; 3], [2.0; 3]],
+ [[4.0; 3], [1e12 - 1.0; 3], [0.75; 3], [0.0; 3]],
+ ] {
+ add(&mut whole, 0, &values);
+ add(&mut partitioned, 0, &values[..1]);
+ add(&mut partitioned, 1, &values[1..3]);
+ add(&mut partitioned, 3, &values[3..]);
+ }
+ assert_eq!(whole.pixels, partitioned.pixels);
+ assert_eq!(whole.pixel_statistics(1).unwrap().variance, [1.0; 3]);
+}
+
+#[test]
+fn cancellation_and_work_failure_preserve_all_pixels() {
+ let mut film = film(2, 1, 3);
+ let cancel = CancelToken::default();
+ let observer = cancel.clone();
+ assert_eq!(
+ film.add_range(0, &[[1.0; 3]; 2], &cancel, &mut |_| {
+ observer.cancel();
+ Ok(())
+ })
+ .unwrap_err()
+ .code,
+ ErrorCode::Cancelled
+ );
+ assert!(film.pixels.iter().all(|p| *p == Pixel::default()));
+ let mut charged = 0;
+ assert_eq!(
+ film.add_range(0, &[[1.0; 3]; 2], &CancelToken::default(), &mut |units| {
+ charged += units;
+ if charged > 2 { Err(limit("job work exhausted")) } else { Ok(()) }
+ })
+ .unwrap_err()
+ .code,
+ ErrorCode::LimitExceeded
+ );
+ assert_eq!(charged, 4);
+ assert!(film.pixels.iter().all(|p| *p == Pixel::default()));
+}
+
+#[test]
+fn construction_and_complete_pass_share_caller_work_and_cancel() {
+ let bytes = FilmAccumulator::required_bytes(2, 1, 1).unwrap();
+ let cancel = CancelToken::default();
+ cancel.cancel();
+ assert!(FilmAccumulator::new(2, 1, 1, bytes, &cancel, &mut |_| panic!("cancelled construction charged work")).is_err());
+ let mut charged = 0;
+ let mut film = FilmAccumulator::new(2, 1, 1, bytes, &CancelToken::default(), &mut |n| {
+ charged += n;
+ Ok(())
+ })
+ .unwrap();
+ assert_eq!(charged, 2);
+ add(&mut film, 0, &[[1.0; 3]; 2]);
+ assert!(film.complete_pass(&CancelToken::default(), &mut |_| Err(limit("job exhausted"))).is_err());
+ let pass = film
+ .complete_pass(&CancelToken::default(), &mut |n| {
+ charged += n;
+ Ok(())
+ })
+ .unwrap();
+ assert_eq!(charged, 4);
+ assert_eq!(pass.samples_per_pixel(), 1);
+}
+
+#[test]
+fn sample_counts_reach_4096_and_the_declared_cap_without_truncation() {
+ for samples in [4096, MAX_SAMPLES] {
+ let mut film = film(1, 1, samples);
+ let cancel = CancelToken::default();
+ let mut charged = 0u64;
+ for _ in 0..samples {
+ film.add_range(0, &[[7.0, 3.0, 1.0]], &cancel, &mut |n| {
+ charged += n;
+ Ok(())
+ })
+ .unwrap();
+ }
+ assert_eq!(charged, u64::from(samples) * 2);
+ let expected = PixelStatistics { mean: [7.0, 3.0, 1.0], variance: [0.0; 3], count: samples };
+ assert_eq!(film.pixel_statistics(0).unwrap(), expected);
+ assert_eq!(film.complete_pass(&cancel, &mut |_| Ok(())).unwrap().samples_per_pixel(), samples);
+ assert_eq!(film.add_range(0, &[[1.0; 3]], &cancel, &mut |_| Ok(())).unwrap_err().code, ErrorCode::LimitExceeded);
+ assert_eq!(film.pixel_statistics(0).unwrap(), expected);
+ }
+}
+
+#[test]
+fn construction_stops_on_exhausted_caller_work() {
+ let bytes = FilmAccumulator::required_bytes(4, 1, 1).unwrap();
+ let mut charged = 0u64;
+ let result = FilmAccumulator::new(4, 1, 1, bytes, &CancelToken::default(), &mut |n| {
+ charged += n;
+ if charged > 2 { Err(limit("existing job budget exhausted")) } else { Ok(()) }
+ });
+ assert!(matches!(result, Err(JobError { code: ErrorCode::LimitExceeded, .. })));
+ assert_eq!(charged, 3);
+}
diff --git a/crates/render/src/job/host.rs b/crates/render/src/job/host.rs
index 12f09f6fdc..774041f710 100644
--- a/crates/render/src/job/host.rs
+++ b/crates/render/src/job/host.rs
@@ -1,4 +1,4 @@
-//! Caller-owned CPU execution host. One worker, two bounded queued inputs; browser pumping
+//! Caller-owned image execution host. One worker, two bounded queued inputs; browser pumping
//! uses the same incremental task without threads. Shared ownership never includes CAD state.
use std::collections::VecDeque;
@@ -12,8 +12,8 @@ use std::sync::{
use serde::Serialize;
use super::{
- Admission, AlphaConvention, CancelToken, ColourEncoding, ErrorCode, FrameInfo, ImageRequest, ImageTask, JobError, JobId, Phase, Progress, Result,
- TaskPoll, admit,
+ Admission, AlphaConvention, CancelToken, ColourEncoding, ErrorCode, FrameInfo, ImageExecutor, ImageRequest, ImageTask, ImageWork, JobError,
+ JobId, JobOptions, Phase, Progress, Result, TaskPoll, admit,
};
use crate::{
Availability, ExecutorDescriptor, ExecutorId, ProductScene, RenderFormat, RenderLimits, RenderMode, RenderOperation, RenderProfile, ScratchLayout,
@@ -48,7 +48,7 @@ impl Budget {
let next = used
.checked_add(bytes)
.filter(|n| *n <= MEMORY_LIMIT)
- .ok_or_else(|| JobError::new(ErrorCode::LimitExceeded, "CPU image host's 512 MiB admission pool is full"))?;
+ .ok_or_else(|| JobError::new(ErrorCode::LimitExceeded, "image host's 512 MiB admission pool is full"))?;
match self.used.compare_exchange_weak(used, next, Ordering::AcqRel, Ordering::Acquire) {
Ok(_) => break,
Err(current) => used = current,
@@ -90,7 +90,10 @@ pub struct JobStatus {
pub job: JobId,
pub scene_generation: u64,
pub request: ImageRequest,
+ pub environment: Option<crate::lighting::environment::EnvironmentInfo>,
pub resolved: crate::ResolvedRequest,
+ pub options: JobOptions,
+ pub textures: Option<super::textures::TextureSummary>,
pub progress: Progress,
pub error: Option<JobError>,
pub frame: Option<FrameInfo>,
@@ -102,11 +105,14 @@ struct Data {
frame: Option<Arc<RenderFrame>>,
}
struct Record {
+ textures: Option<super::textures::TextureSummary>,
id: JobId,
scene_generation: u64,
request: ImageRequest,
+ environment: Option<crate::lighting::environment::EnvironmentInfo>,
resolved: crate::ResolvedRequest,
cancel: CancelToken,
+ options: JobOptions,
data: Mutex<Data>,
#[cfg(not(target_arch = "wasm32"))]
done: Condvar,
@@ -132,7 +138,10 @@ impl JobHandle {
job: self.0.id,
scene_generation: self.0.scene_generation,
request: self.0.request.clone(),
+ environment: self.0.environment.clone(),
resolved: self.0.resolved.clone(),
+ options: self.0.options,
+ textures: self.0.textures.clone(),
progress: data.progress,
error: data.error.clone(),
frame: data.frame.as_ref().map(|f| f.info.clone()),
@@ -176,12 +185,16 @@ impl JobHandle {
}
struct Work {
+ request: ImageRequest,
+ executor: Arc<dyn ImageExecutor>,
scene: ProductScene,
handle: JobHandle,
reservation: Reservation,
}
struct Running {
- task: ImageTask,
+ /// Taken and dropped as the frame completes, before the reservation shrinks to the PNG: the
+ /// task owns its scratch (pixels, device buffers), which the full reservation pays for.
+ task: Option<Box<dyn ImageWork>>,
handle: JobHandle,
reservation: Option<Reservation>,
}
@@ -214,9 +227,12 @@ impl Running {
{
data.progress.phase = Phase::Preparing;
}
- let task = ImageTask::new(work.scene, work.handle.0.request.clone(), work.handle.0.cancel.clone());
+ let task = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
+ work.executor.begin(work.scene, work.request, work.handle.0.options, work.handle.0.cancel.clone())
+ }))
+ .unwrap_or_else(|_| Err(JobError::new(ErrorCode::Internal, "image executor failed while preparing the job")));
match task {
- Ok(task) => Some(Self { task, handle: work.handle, reservation: Some(work.reservation) }),
+ Ok(task) => Some(Self { task: Some(task), handle: work.handle, reservation: Some(work.reservation) }),
Err(e) => {
terminal(&work.handle, e);
None
@@ -225,7 +241,8 @@ impl Running {
}
fn advance(&mut self, units: usize) -> Result<bool> {
- let result = self.task.step(units)?;
+ let task = self.task.as_mut().ok_or_else(|| JobError::new(ErrorCode::Internal, "render task already finished"))?;
+ let result = task.step(units)?;
let mut data = self.handle.0.data.lock().map_err(|_| JobError::new(ErrorCode::Internal, "render status lock poisoned"))?;
// The final publication check is under the same lock as cancellation.
if self.handle.0.cancel.is_cancelled() {
@@ -240,6 +257,8 @@ impl Running {
Ok(true)
}
TaskPoll::Complete(png) => {
+ // The task's scratch goes before its charge does (still under the publication lock).
+ drop(self.task.take());
let mut reservation = self.reservation.take().ok_or_else(|| JobError::new(ErrorCode::Internal, "missing render reservation"))?;
reservation.shrink(png.capacity() as u64 + 1024)?;
let info = FrameInfo {
@@ -269,7 +288,7 @@ impl Running {
false
}
Err(_) => {
- terminal(&self.handle, JobError::new(ErrorCode::Internal, "CPU image host encountered an internal error"));
+ terminal(&self.handle, JobError::new(ErrorCode::Internal, "image host encountered an internal error"));
false
}
}
@@ -286,6 +305,7 @@ struct Shared {
}
struct Owner {
+ executor: Arc<dyn ImageExecutor>,
shared: Arc<Shared>,
kind: HostKind,
running: Mutex<Option<Running>>,
@@ -320,9 +340,12 @@ impl Drop for Owner {
}
#[derive(Clone)]
-pub struct CpuHost(Arc<Owner>);
+pub struct ImageHost(Arc<Owner>);
+
+/// Backwards-compatible CPU host constructors. Additional executors use `ImageHost::with_executor`.
+pub type CpuHost = ImageHost;
-impl CpuHost {
+impl ImageHost {
fn shared() -> Arc<Shared> {
Arc::new(Shared {
queue: Mutex::new(VecDeque::new()),
@@ -335,7 +358,13 @@ impl CpuHost {
}
pub fn cooperative() -> Self {
+ Self::cooperative_with(Arc::new(CpuExecutor))
+ }
+
+ /// A cooperative host over `executor` (pumped by its caller).
+ fn cooperative_with(executor: Arc<dyn ImageExecutor>) -> Self {
Self(Arc::new(Owner {
+ executor,
shared: Self::shared(),
kind: HostKind::Cooperative,
running: Mutex::new(None),
@@ -351,14 +380,29 @@ impl CpuHost {
}
#[cfg(not(target_arch = "wasm32"))]
{
- let shared = Self::shared();
- let worker_shared = shared.clone();
- let worker = std::thread::Builder::new()
- .name("solidcraft-render".into())
- .spawn(move || native_worker(worker_shared))
- .map_err(|e| JobError::new(ErrorCode::HostUnavailable, format!("could not start CPU image worker: {e}")))?;
- Ok(Self(Arc::new(Owner { shared, kind: HostKind::NativeWorker, running: Mutex::new(None), _worker: Some(worker) })))
+ Self::with_executor(Arc::new(CpuExecutor))
+ }
+ }
+
+ /// Start an isolated bounded native worker. GPU discovery occurs before registration.
+ #[cfg(not(target_arch = "wasm32"))]
+ pub fn with_executor(executor: Arc<dyn ImageExecutor>) -> Result<Self> {
+ let descriptor = executor.descriptor()?;
+ if descriptor.profiles.len() != 1
+ || descriptor
+ .profiles
+ .iter()
+ .any(|p| p.mode != RenderMode::Preview || p.operation != RenderOperation::Image || p.formats != [RenderFormat::Png])
+ {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "image worker currently accepts one Preview/Image/PNG profile"));
}
+ let shared = Self::shared();
+ let worker_shared = shared.clone();
+ let worker = std::thread::Builder::new()
+ .name("solidcraft-render".into())
+ .spawn(move || native_worker(worker_shared))
+ .map_err(|e| JobError::new(ErrorCode::HostUnavailable, format!("could not start image worker: {e}")))?;
+ Ok(Self(Arc::new(Owner { executor, shared, kind: HostKind::NativeWorker, running: Mutex::new(None), _worker: Some(worker) })))
}
pub fn kind(&self) -> HostKind {
@@ -376,31 +420,38 @@ impl CpuHost {
}
pub fn descriptor(&self) -> Result<ExecutorDescriptor> {
- Ok(ExecutorDescriptor {
- id: ExecutorId::new("cpu-product").map_err(|e| JobError::new(ErrorCode::Internal, e.to_string()))?,
- availability: if self.0.shared.stop.load(Ordering::Acquire) {
- Availability::Unavailable { reason: "CPU image host has stopped".into() }
- } else {
- Availability::Available
- },
- profiles: vec![RenderProfile {
- mode: RenderMode::Preview,
- operation: RenderOperation::Image,
- formats: vec![RenderFormat::Png],
- features: vec![crate::RenderFeature::Pbr],
- }],
- limits: RenderLimits::default(),
- scratch: ScratchLayout { sample_scale: 2, sample_bytes_per_pixel: 8, output_bytes_per_pixel: 8, encoding_bytes_per_pixel: 8 },
- })
+ let mut descriptor = self.0.executor.descriptor()?;
+ if !self.is_available() {
+ descriptor.availability = Availability::Unavailable { reason: "image host has stopped".into() };
+ }
+ Ok(descriptor)
+ }
+
+ pub fn admit(&self, scene: &ProductScene, request: &ImageRequest, options: JobOptions) -> Result<Admission> {
+ options.validate()?;
+ self.0.executor.admit(scene, request, options)
}
pub fn submit(&self, id: JobId, scene_generation: u64, scene: ProductScene, request: ImageRequest) -> Result<JobHandle> {
+ self.submit_with_options(id, scene_generation, scene, request, JobOptions::default())
+ }
+
+ pub fn submit_with_options(
+ &self,
+ id: JobId,
+ scene_generation: u64,
+ scene: ProductScene,
+ request: ImageRequest,
+ options: JobOptions,
+ ) -> Result<JobHandle> {
if id.session == 0 || id.serial == 0 || id.generation == 0 {
return Err(JobError::new(ErrorCode::InvalidRequest, "invalid render job identity"));
}
- let Admission { estimated_total_bytes, .. } = admit(&scene, &request)?;
+ let Admission { estimated_total_bytes, .. } = self.admit(&scene, &request, options)?;
let mut backend = crate::builtin_backend();
- backend.executors.push(self.descriptor()?);
+ let descriptor = self.descriptor()?;
+ let executor = descriptor.id.clone();
+ backend.executors = vec![descriptor];
let resolved = crate::resolve_request(
&[backend],
&crate::RenderRequest {
@@ -415,29 +466,37 @@ impl CpuHost {
},
)
.map_err(|e| JobError::new(ErrorCode::HostUnavailable, e.to_string()))?;
- if resolved.executor.as_str() != "cpu-product" {
- return Err(JobError::new(ErrorCode::HostUnavailable, "CPU product executor is unavailable"));
+ if resolved.executor != executor {
+ return Err(JobError::new(ErrorCode::HostUnavailable, "image executor is unavailable"));
}
let mut queue = self.0.shared.queue.lock().map_err(|_| JobError::new(ErrorCode::HostUnavailable, "render queue lock poisoned"))?;
if self.0.shared.stop.load(Ordering::Acquire) {
- return Err(JobError::new(ErrorCode::HostUnavailable, "CPU image host has stopped"));
+ return Err(JobError::new(ErrorCode::HostUnavailable, "image host has stopped"));
}
queue.retain(|work| !work.handle.0.cancel.is_cancelled());
if queue.len() >= QUEUE_LIMIT {
- return Err(JobError::new(ErrorCode::QueueFull, "CPU image queue is full"));
+ return Err(JobError::new(ErrorCode::QueueFull, "image queue is full"));
}
let reservation = self.0.shared.budget.reserve(estimated_total_bytes)?;
+ // Keep large captured sources in admitted work only. Status/retained frames
+ // must not keep resource bytes alive after the reservation is shrunk.
+ let environment = request.environment.as_ref().map(|source| source.info().clone());
+ let public_request = ImageRequest { textures: None, environment: None, ..request.clone() };
+ let textures = request.textures.as_ref().map(|t| t.summary());
let handle = JobHandle(Arc::new(Record {
+ textures,
id,
scene_generation,
- request,
+ request: public_request,
+ environment,
resolved,
cancel: CancelToken::default(),
+ options,
data: Mutex::new(Data { progress: Progress { phase: Phase::Queued, done: 0, total: 1 }, error: None, frame: None }),
#[cfg(not(target_arch = "wasm32"))]
done: Condvar::new(),
}));
- queue.push_back(Work { scene, handle: handle.clone(), reservation });
+ queue.push_back(Work { request, executor: self.0.executor.clone(), scene, handle: handle.clone(), reservation });
drop(queue);
#[cfg(not(target_arch = "wasm32"))]
self.0.shared.wake.notify_one();
@@ -514,3 +573,31 @@ fn native_worker(shared: Arc<Shared>) {
}
}
}
+
+struct CpuExecutor;
+impl ImageExecutor for CpuExecutor {
+ fn descriptor(&self) -> Result<ExecutorDescriptor> {
+ Ok(ExecutorDescriptor {
+ id: ExecutorId::new("cpu-product").map_err(|e| JobError::new(ErrorCode::Internal, e.to_string()))?,
+ availability: Availability::Available,
+ profiles: vec![RenderProfile {
+ mode: RenderMode::Preview,
+ operation: RenderOperation::Image,
+ formats: vec![RenderFormat::Png],
+ features: vec![crate::RenderFeature::Pbr],
+ }],
+ limits: RenderLimits::default(),
+ scratch: ScratchLayout { sample_scale: 2, sample_bytes_per_pixel: 8, output_bytes_per_pixel: 8, encoding_bytes_per_pixel: 8 },
+ })
+ }
+
+ fn admit(&self, scene: &ProductScene, request: &ImageRequest, options: JobOptions) -> Result<Admission> {
+ if options != JobOptions::default() {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "CPU product does not support sampling or exposure controls"));
+ }
+ admit(scene, request)
+ }
+ fn begin(&self, scene: ProductScene, request: ImageRequest, _options: JobOptions, cancel: CancelToken) -> Result<Box<dyn ImageWork>> {
+ Ok(Box::new(ImageTask::new(scene, request, cancel)?))
+ }
+}
diff --git a/crates/render/src/job/host_tests.rs b/crates/render/src/job/host_tests.rs
index cb5634f978..e06d79ab65 100644
--- a/crates/render/src/job/host_tests.rs
+++ b/crates/render/src/job/host_tests.rs
@@ -2,7 +2,15 @@ use super::*;
use solidcraft_geom::{Aabb3, Mesh};
fn request() -> ImageRequest {
- ImageRequest { camera: Default::default(), width: 16, height: 16, background: [40, 80, 120], transparent_background: false }
+ ImageRequest {
+ textures: None,
+ environment: None,
+ camera: Default::default(),
+ width: 16,
+ height: 16,
+ background: [40, 80, 120],
+ transparent_background: false,
+ }
}
fn empty() -> ProductScene {
ProductScene { meshes: Vec::new(), bounds: Aabb3::EMPTY }
@@ -77,6 +85,7 @@ fn malformed_preparation_fails_the_job_without_stopping_the_host() {
color: [0; 3],
opacity: 1.0,
surface: None,
+ transmission: None,
faces: Vec::new(),
}],
};
@@ -129,3 +138,192 @@ fn native_job_finishes_without_any_poll_or_ui_pump() {
assert_eq!(status.progress.phase, Phase::Completed);
assert_eq!(job.frame().unwrap().unwrap().info.scene_generation, 12);
}
+
+#[test]
+fn environment_payload_is_owned_by_admitted_work_not_retained_status() {
+ struct ResourceExecutor;
+ impl ImageExecutor for ResourceExecutor {
+ fn descriptor(&self) -> Result<ExecutorDescriptor> {
+ CpuExecutor.descriptor()
+ }
+ fn admit(&self, scene: &ProductScene, request: &ImageRequest, _: JobOptions) -> Result<Admission> {
+ let mut admission = super::super::admit_geometry(scene, request, 262_144)?;
+ admission.estimated_total_bytes += request.environment.as_ref().map_or(0, |source| source.admitted_bytes());
+ Ok(admission)
+ }
+ fn begin(&self, scene: ProductScene, mut request: ImageRequest, _: JobOptions, cancel: CancelToken) -> Result<Box<dyn ImageWork>> {
+ request.environment = None;
+ Ok(Box::new(ImageTask::new(scene, request, cancel)?))
+ }
+ }
+ for cancelled in [false, true] {
+ let host = ImageHost(Arc::new(Owner {
+ executor: Arc::new(ResourceExecutor),
+ shared: ImageHost::shared(),
+ kind: HostKind::Cooperative,
+ running: Mutex::new(None),
+ #[cfg(not(target_arch = "wasm32"))]
+ _worker: None,
+ }));
+ let source = Arc::new(crate::lighting::environment::EnvironmentSource::sky(Default::default(), 0.0, 1.0).unwrap());
+ let weak = Arc::downgrade(&source);
+ let mut input = request();
+ input.environment = Some(source);
+ let job = host.submit(id(1, 1), 1, empty(), input).unwrap();
+ let status = job.status().unwrap();
+ assert!(status.request.environment.is_none());
+ assert_eq!(status.environment.as_ref().unwrap().kind, "original_gradient_sky");
+ assert!(weak.upgrade().is_some(), "queuedwork owns source");
+ if cancelled {
+ job.cancel().unwrap();
+ }
+ drain(&host);
+ assert!(weak.upgrade().is_none(), "completed/cancelled work releases captured source despite retained status/job");
+ assert_eq!(job.status().unwrap().progress.phase, if cancelled { Phase::Cancelled } else { Phase::Completed });
+ }
+}
+
+#[test]
+fn texture_payload_is_owned_by_admitted_work_not_retained_status() {
+ struct ResourceExecutor;
+ impl ImageExecutor for ResourceExecutor {
+ fn descriptor(&self) -> Result<ExecutorDescriptor> {
+ CpuExecutor.descriptor()
+ }
+ fn admit(&self, scene: &ProductScene, request: &ImageRequest, _: JobOptions) -> Result<Admission> {
+ let mut admission = super::super::admit_geometry(scene, request, 262_144)?;
+ admission.estimated_total_bytes += request.textures.as_ref().map_or(0, |source| source.working_bytes());
+ Ok(admission)
+ }
+ fn begin(&self, scene: ProductScene, mut request: ImageRequest, _: JobOptions, cancel: CancelToken) -> Result<Box<dyn ImageWork>> {
+ request.textures = None;
+ Ok(Box::new(ImageTask::new(scene, request, cancel)?))
+ }
+ }
+ for cancelled in [false, true] {
+ let host = ImageHost(Arc::new(Owner {
+ executor: Arc::new(ResourceExecutor),
+ shared: ImageHost::shared(),
+ kind: HostKind::Cooperative,
+ running: Mutex::new(None),
+ #[cfg(not(target_arch = "wasm32"))]
+ _worker: None,
+ }));
+ use crate::job::textures::{PlanarFrame, RuntimeTextures, TextureBinding, TextureMap};
+ use image::ImageEncoder;
+ let mut bytes = Vec::new();
+ image::codecs::png::PngEncoder::new(&mut bytes).write_image(&[128, 128, 255, 255], 1, 1, image::ExtendedColorType::Rgba8).unwrap();
+ let source = Arc::new(
+ RuntimeTextures::new(vec![TextureBinding {
+ body_index: 0,
+ body_name: "unused test resource".into(),
+ frame: PlanarFrame { origin: [0.; 3], u: [1., 0., 0.], v: [0., 1., 0.] },
+ normal_strength: 1.,
+ base_color: Some(TextureMap::new(bytes, crate::texture_input::MapRole::BaseColor).unwrap()),
+ normal: None,
+ }])
+ .unwrap(),
+ );
+ let weak = Arc::downgrade(&source);
+ let mut input = request();
+ input.textures = Some(source);
+ let job = host.submit(id(1, 1), 1, empty(), input).unwrap();
+ let status = job.status().unwrap();
+ assert!(status.request.textures.is_none());
+ assert_eq!(status.textures.as_ref().unwrap().bodies, 1);
+ assert!(weak.upgrade().is_some(), "queuedwork owns source");
+ if cancelled {
+ job.cancel().unwrap();
+ }
+ drain(&host);
+ assert!(weak.upgrade().is_none(), "completed/cancelled work releases captured source despite retained status/job");
+ assert_eq!(job.status().unwrap().progress.phase, if cancelled { Phase::Cancelled } else { Phase::Completed });
+ }
+}
+/// An executor whose task reports, as it is dropped, how much of the pool is admitted, and
+/// completes after `steps` steps (or never, cancelled on its last one with `cancel_last`).
+struct DropProbe {
+ admitted_at_drop: Arc<AtomicU64>,
+ budget: Arc<std::sync::OnceLock<Arc<Budget>>>,
+ estimated: u64,
+}
+struct ProbeTask {
+ admitted_at_drop: Arc<AtomicU64>,
+ budget: Arc<std::sync::OnceLock<Arc<Budget>>>,
+ steps: u32,
+}
+impl Drop for ProbeTask {
+ fn drop(&mut self) {
+ let used = self.budget.get().map_or(u64::MAX, |b| b.used.load(Ordering::Acquire));
+ self.admitted_at_drop.store(used, Ordering::Release);
+ }
+}
+impl ImageWork for ProbeTask {
+ fn step(&mut self, _units: usize) -> Result<TaskPoll> {
+ self.steps += 1;
+ if self.steps < 3 {
+ return Ok(TaskPoll::Pending(Progress { phase: Phase::Running, done: u64::from(self.steps), total: 3 }));
+ }
+ Ok(TaskPoll::Complete(vec![0u8; 100]))
+ }
+}
+impl ImageExecutor for DropProbe {
+ fn descriptor(&self) -> Result<ExecutorDescriptor> {
+ CpuExecutor.descriptor()
+ }
+ fn admit(&self, _: &ProductScene, _: &ImageRequest, _: JobOptions) -> Result<Admission> {
+ Ok(Admission {
+ triangles: 0,
+ face_appearances: 0,
+ geometry_bytes: 0,
+ pixel_scratch_bytes: self.estimated,
+ preparation_bytes: 0,
+ estimated_total_bytes: self.estimated,
+ encoded_limit: 4096,
+ })
+ }
+ fn begin(&self, _: ProductScene, _: ImageRequest, _: JobOptions, _: CancelToken) -> Result<Box<dyn ImageWork>> {
+ Ok(Box::new(ProbeTask { admitted_at_drop: self.admitted_at_drop.clone(), budget: self.budget.clone(), steps: 0 }))
+ }
+}
+
+fn probe_host(estimated: u64) -> (CpuHost, Arc<AtomicU64>) {
+ let admitted_at_drop = Arc::new(AtomicU64::new(0));
+ let budget = Arc::new(std::sync::OnceLock::new());
+ let host = CpuHost::cooperative_with(Arc::new(DropProbe { admitted_at_drop: admitted_at_drop.clone(), budget: budget.clone(), estimated }));
+ let _ = budget.set(host.0.shared.budget.clone());
+ (host, admitted_at_drop)
+}
+
+#[test]
+fn a_completed_task_is_dropped_while_its_full_reservation_still_pays_for_it() {
+ let estimated = 1 << 20;
+ let (host, admitted_at_drop) = probe_host(estimated);
+ let job = host.submit(id(1, 1), 1, empty(), request()).unwrap();
+ drain(&host);
+ assert_eq!(job.status().unwrap().progress.phase, Phase::Completed);
+ // While the task (and its scratch) was being dropped, its whole charge was still held.
+ assert_eq!(admitted_at_drop.load(Ordering::Acquire), estimated);
+ // Afterwards only the PNG's lease remains, and the frame keeps it.
+ let frame = job.frame().unwrap().unwrap();
+ assert!(host.admitted_bytes() > 0 && host.admitted_bytes() < estimated, "{}", host.admitted_bytes());
+ drop(job);
+ drop(frame);
+ assert_eq!(host.admitted_bytes(), 0);
+}
+
+#[test]
+fn a_cancel_on_the_final_step_publishes_no_frame_and_drops_the_task() {
+ let estimated = 1 << 20;
+ let (host, admitted_at_drop) = probe_host(estimated);
+ let job = host.submit(id(1, 1), 1, empty(), request()).unwrap();
+ // Two pending steps, then cancel before the step that would complete.
+ host.pump(1).unwrap();
+ host.pump(1).unwrap();
+ job.cancel().unwrap();
+ drain(&host);
+ assert_eq!(job.status().unwrap().progress.phase, Phase::Cancelled);
+ assert!(job.frame().unwrap().is_none());
+ assert_eq!(admitted_at_drop.load(Ordering::Acquire), estimated, "the task went before its charge");
+ assert_eq!(host.admitted_bytes(), 0);
+}
diff --git a/crates/render/src/job/image.rs b/crates/render/src/job/image.rs
index 48b91379e1..ada8de811e 100644
--- a/crates/render/src/job/image.rs
+++ b/crates/render/src/job/image.rs
@@ -49,7 +49,35 @@ fn add_bytes(sum: &mut u64, count: usize, size: usize) -> Result<()> {
/// Conservative admission before allocating pixels or projected-work lists. Source Arcs are
/// counted even when another owner already holds them. Allocator and codec internals are estimates.
+/// Includes the CPU raster work estimate and its 384 MiB per-job check.
pub fn admit(scene: &ProductScene, request: &ImageRequest) -> Result<Admission> {
+ if request.environment.is_some() {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "CPU product does not support environment maps"));
+ }
+ if request.textures.is_some() {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "runtime textures require the progressive GPU executor"));
+ }
+ admit_raster(admit_source(scene, request, MAX_TRIANGLES)?)
+}
+
+/// Common camera, dimension and source admission for registered executors, without any CPU
+/// raster estimate: the returned admission counts retained source geometry only
+/// (`pixel_scratch_bytes` and `preparation_bytes` are zero). Executors budget their own
+/// preparation and pixel storage, apply their own job limit, and validate triangle contents
+/// before uploading anything to a device.
+pub fn admit_geometry(scene: &ProductScene, request: &ImageRequest, max_triangles: u64) -> Result<Admission> {
+ Ok(admit_source(scene, request, max_triangles)?.admission)
+}
+
+/// A validated source with its geometry accounting, and the builtin raster scratch estimate
+/// for the requested dimensions (used only by the CPU estimate).
+struct Source {
+ admission: Admission,
+ bodies: u64,
+ raster_scratch_bytes: u64,
+}
+
+fn admit_source(scene: &ProductScene, request: &ImageRequest, max_triangles: u64) -> Result<Source> {
if !request.camera.is_valid() {
return Err(JobError::new(ErrorCode::InvalidRequest, "invalid image camera"));
}
@@ -77,8 +105,8 @@ pub fn admit(scene: &ProductScene, request: &ImageRequest) -> Result<Admission>
triangles = triangles.checked_add(m.triangles.len() as u64).ok_or_else(|| limit("triangle count overflow"))?;
faces = faces.checked_add(body.faces.len() as u64).ok_or_else(|| limit("appearance count overflow"))?;
polylines = polylines.checked_add(m.edges.len() as u64 + m.edge_faces.len() as u64).ok_or_else(|| limit("edge count overflow"))?;
- if triangles > MAX_TRIANGLES || faces > MAX_TRIANGLES || polylines > MAX_TRIANGLES {
- return Err(limit("product image exceeds the 262144 triangle/appearance/polyline admission cap"));
+ if triangles > max_triangles || faces > max_triangles || polylines > max_triangles {
+ return Err(limit("product image exceeds its triangle/appearance/polyline admission cap"));
}
add_bytes(&mut geometry, m.positions.capacity(), std::mem::size_of::<Vec3>())?;
add_bytes(&mut geometry, m.normals.capacity(), std::mem::size_of::<Vec3>())?;
@@ -97,36 +125,51 @@ pub fn admit(scene: &ProductScene, request: &ImageRequest) -> Result<Admission>
for count in [m.seams.capacity(), m.smooth_edges.capacity(), m.sharp_edges.capacity()] {
add_bytes(&mut geometry, count, 1)?;
}
- if body.surface.is_some() && body.opacity != 1.0 {
+ if body.surface.is_some() && body.transmission.is_none() && body.opacity != 1.0 {
return Err(invalid("opaque PBR requires opacity 1"));
}
if !body.opacity.is_finite() || !(0.0..=1.0).contains(&body.opacity) {
return Err(invalid("invalid body opacity"));
}
}
+ let encoded_limit = u64::from(request.width) * u64::from(request.height) * 8 + 65_536;
+ Ok(Source {
+ admission: Admission {
+ triangles,
+ face_appearances: faces,
+ geometry_bytes: geometry,
+ pixel_scratch_bytes: 0,
+ preparation_bytes: 0,
+ estimated_total_bytes: geometry,
+ encoded_limit,
+ },
+ bodies: scene.meshes.len() as u64,
+ raster_scratch_bytes: resolved.estimated_scratch_bytes,
+ })
+}
+
+/// The CPU raster scratch/preparation estimate and its 384 MiB per-job check.
+fn admit_raster(source: Source) -> Result<Admission> {
+ let mut a = source.admission;
// Three bounded 16-byte lists, a conservative map-node allowance, and codec overhead.
- let preparation = triangles
+ let preparation = a
+ .triangles
.checked_mul(48)
- .and_then(|n| faces.checked_mul(160).and_then(|f| n.checked_add(f)))
- .and_then(|n| n.checked_add(scene.meshes.len() as u64 * 128 + 262_144))
+ .and_then(|n| a.face_appearances.checked_mul(160).and_then(|f| n.checked_add(f)))
+ .and_then(|n| n.checked_add(source.bodies * 128 + 262_144))
.ok_or_else(|| limit("work list size overflow"))?;
- let total = geometry
+ let total = a
+ .geometry_bytes
.checked_add(preparation)
- .and_then(|n| n.checked_add(resolved.estimated_scratch_bytes))
+ .and_then(|n| n.checked_add(source.raster_scratch_bytes))
.ok_or_else(|| limit("image memory overflow"))?;
if total > MAX_JOB_BYTES {
return Err(limit("product job exceeds its 384 MiB admission estimate"));
}
- let encoded_limit = u64::from(request.width) * u64::from(request.height) * 8 + 65_536;
- Ok(Admission {
- triangles,
- face_appearances: faces,
- geometry_bytes: geometry,
- pixel_scratch_bytes: resolved.estimated_scratch_bytes,
- preparation_bytes: preparation,
- estimated_total_bytes: total,
- encoded_limit,
- })
+ a.pixel_scratch_bytes = source.raster_scratch_bytes;
+ a.preparation_bytes = preparation;
+ a.estimated_total_bytes = total;
+ Ok(a)
}
fn reserve<T>(count: usize) -> Result<Vec<T>> {
@@ -380,7 +423,11 @@ impl ImageTask {
return Err(invalid("non-finite product triangle"));
}
let look = self.looks.get(draw.body as usize).and_then(|looks| mesh.tri_face.get(draw.triangle as usize).and_then(|face| looks.get(face)));
- let (colour, opacity, surface) = look.map_or((body.color, body.opacity, body.surface), |look| (look.color, look.opacity, look.surface));
+ // Transmission is physical optical data, never a request to change CPU preview.
+ // Keep the existing scalar sorted-alpha shading for glass previews.
+ let (colour, opacity, surface) = look.map_or((body.color, body.opacity, body.surface.filter(|_| body.transmission.is_none())), |look| {
+ (look.color, look.opacity, look.surface.filter(|_| look.transmission.is_none()))
+ });
if surface.is_some() && opacity != 1.0 {
return Err(invalid("opaque PBR requires opacity 1"));
}
diff --git a/crates/render/src/job/image_tests.rs b/crates/render/src/job/image_tests.rs
index 18406e1f47..b0d2211261 100644
--- a/crates/render/src/job/image_tests.rs
+++ b/crates/render/src/job/image_tests.rs
@@ -5,7 +5,7 @@ use solidcraft_geom::{Aabb3, Mesh};
fn request() -> ImageRequest {
let mut camera = Camera { distance: 50.0, ..Default::default() };
camera.set_view(StandardView::Front);
- ImageRequest { camera, width: 64, height: 64, background: [20, 40, 60], transparent_background: true }
+ ImageRequest { textures: None, environment: None, camera, width: 64, height: 64, background: [20, 40, 60], transparent_background: true }
}
fn square(name: &str, colour: [u8; 3], opacity: f64, offset: Vec3) -> ProductMesh {
@@ -21,7 +21,7 @@ fn square(name: &str, colour: [u8; 3], opacity: f64, offset: Vec3) -> ProductMes
tri_face: vec![0, 1],
..Default::default()
};
- ProductMesh { name: name.into(), mesh: Arc::new(mesh), color: colour, opacity, surface: None, faces: Vec::new() }
+ ProductMesh { name: name.into(), mesh: Arc::new(mesh), color: colour, opacity, surface: None, transmission: None, faces: Vec::new() }
}
fn scene(meshes: Vec<ProductMesh>) -> ProductScene {
@@ -68,6 +68,17 @@ fn glass_is_sorted_back_to_front_independently_of_body_order() {
assert!(p[2] > p[0] + 30, "the near blue layer contributes more: {p:?}");
}
+#[test]
+fn physical_transmission_keeps_the_exact_scalar_cpu_preview() {
+ let original = square("Glass", [80, 180, 140], 0.25, Vec3::ZERO);
+ let mut glass = original.clone();
+ glass.surface = Some(crate::surface::OpaqueSurface::new(Vec3::new(0.2, 0.4, 0.3), 0.0, 0.1, 1.5).unwrap());
+ glass.transmission = Some(crate::transmission::Transmission::new(Vec3::new(-0.7_f64.ln(), -0.9_f64.ln(), 0.0) / 10.0, None).unwrap());
+ let expected = finish(ImageTask::new(scene(vec![original]), request(), CancelToken::default()).unwrap());
+ let actual = finish(ImageTask::new(scene(vec![glass]), request(), CancelToken::default()).unwrap());
+ assert_eq!(actual, expected);
+}
+
#[test]
fn cancellation_is_observed_during_preparation_sort_pixels_and_encoding() {
for stage in [Stage::Looks, Stage::Prepare, Stage::Sort, Stage::Clear, Stage::Glass, Stage::Downsample, Stage::Encode] {
@@ -116,7 +127,7 @@ fn invalid_sizes_indices_opacity_and_large_work_lists_fail_without_a_frame() {
if bad == 0 {
Arc::make_mut(&mut body.mesh).triangles[0][0] = u32::MAX;
} else {
- body.faces.push(FaceAppearance { face: 0, color: [0; 3], opacity: f64::NAN, surface: None });
+ body.faces.push(FaceAppearance { face: 0, color: [0; 3], opacity: f64::NAN, surface: None, transmission: None });
}
let mut task = ImageTask::new(scene(vec![body]), request(), CancelToken::default()).unwrap();
let error = loop {
@@ -145,3 +156,25 @@ fn png_output_budget_and_cancellation_fail_without_partial_publication() {
assert!(writer.flush().is_err());
assert_eq!(*bytes.lock().unwrap(), b"PNG");
}
+
+#[test]
+fn registered_executor_geometry_admission_excludes_the_cpu_raster_estimate() {
+ // A library-bounded source: about 100 MiB of face appearances on a small mesh at the
+ // largest image. Its CPU raster estimate is above 384 MiB at a registered executor's cap.
+ let count = (100 * 1024 * 1024 / std::mem::size_of::<FaceAppearance>()).min(1_000_000);
+ let mut body = square("appearances", [200; 3], 1.0, Vec3::ZERO);
+ body.faces = vec![FaceAppearance { face: 0, color: [200; 3], opacity: 1.0, surface: None, transmission: None }; count];
+ let source = scene(vec![body]);
+ let mut r = request();
+ r.width = 2048;
+ r.height = 2048;
+ let cpu = admit_raster(admit_source(&source, &r, 1_048_576).unwrap()).unwrap_err();
+ assert_eq!(cpu.code, ErrorCode::LimitExceeded);
+ assert!(cpu.message.contains("384 MiB"), "{}", cpu.message);
+ let geometry = admit_geometry(&source, &r, 1_048_576).unwrap();
+ assert_eq!((geometry.pixel_scratch_bytes, geometry.preparation_bytes), (0, 0));
+ assert_eq!(geometry.estimated_total_bytes, geometry.geometry_bytes);
+ assert_eq!(geometry.face_appearances, count as u64);
+ // The CPU host itself keeps rejecting the source.
+ assert_eq!(admit(&source, &r).unwrap_err().code, ErrorCode::LimitExceeded);
+}
diff --git a/crates/render/src/job/lens.rs b/crates/render/src/job/lens.rs
new file mode 100644
index 0000000000..b76753c3b8
--- /dev/null
+++ b/crates/render/src/job/lens.rs
@@ -0,0 +1,43 @@
+//! Runtime thin-lens camera settings. Focus is an axial distance from the eye,
+//! not distance along an off-axis ray. No document or camera-navigation changes.
+use super::{ErrorCode, JobError, Result};
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct ThinLens {
+ pub aperture_radius_mm: f64,
+ pub focus_distance_mm: f64,
+}
+
+impl ThinLens {
+ pub fn validate(self) -> Result<()> {
+ if !self.aperture_radius_mm.is_finite()
+ || !(0.0..=1e7).contains(&self.aperture_radius_mm)
+ || !self.focus_distance_mm.is_finite()
+ || !(1e-6..=1e9).contains(&self.focus_distance_mm)
+ {
+ return Err(JobError::new(
+ ErrorCode::InvalidRequest,
+ "lens aperture radius must be 0..10000000 mm and axial focus distance 0.000001..1000000000 mm",
+ ));
+ }
+ Ok(())
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ #[test]
+ fn lens_admission_rejects_nonfinite_and_unbounded_values() {
+ for aperture in [f64::NAN, f64::INFINITY, -1.0, 1e7 + 1.0] {
+ assert!(ThinLens { aperture_radius_mm: aperture, focus_distance_mm: 10.0 }.validate().is_err());
+ }
+ for focus in [f64::NAN, f64::INFINITY, 0.0, -1.0, 1e9 + 1.0] {
+ assert!(ThinLens { aperture_radius_mm: 1.0, focus_distance_mm: focus }.validate().is_err());
+ }
+ assert!(ThinLens { aperture_radius_mm: 0.0, focus_distance_mm: 1.0 }.validate().is_ok());
+ assert!(serde_json::from_str::<ThinLens>(r#"{"aperture_radius_mm":1,"focus_distance_mm":10,"f_stop":2}"#).is_err());
+ }
+}
diff --git a/crates/render/src/job/lighting.rs b/crates/render/src/job/lighting.rs
new file mode 100644
index 0000000000..eb224248cf
--- /dev/null
+++ b/crates/render/src/job/lighting.rs
@@ -0,0 +1,234 @@
+//! Runtime rectangular emitters and constant environment radiance. Coordinates are
+//! world-space millimetres; radiance is linear RGB. No saved-document contract.
+use super::{ErrorCode, JobError, Result};
+use serde::{Deserialize, Serialize};
+use solidcraft_geom::Vec3;
+
+pub const MAX_AREA_LIGHTS: usize = 4;
+
+/// A one-sided rectangle: `center + u*s + v*t`, with s,t in [-1,1].
+/// Its emitting normal is `u cross v`; u and v are orthogonal half-edges.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct AreaLight {
+ pub center: [f64; 3],
+ pub u: [f64; 3],
+ pub v: [f64; 3],
+ pub radiance: [f64; 3],
+}
+
+fn vector(a: [f64; 3]) -> Vec3 {
+ let [x, y, z] = a;
+ Vec3::new(x, y, z)
+}
+
+impl AreaLight {
+ pub fn validate(self) -> Result<()> {
+ let u = vector(self.u);
+ let v = vector(self.v);
+ let ul = u.len();
+ let vl = v.len();
+ if self.center.into_iter().any(|x| !x.is_finite() || x.abs() > 1e12)
+ || self.u.into_iter().chain(self.v).any(|x| !x.is_finite())
+ || !(1e-4..=1e6).contains(&ul)
+ || !(1e-4..=1e6).contains(&vl)
+ || u.dot(v).abs() > 1e-6 * ul * vl
+ || self.radiance.into_iter().any(|x| !x.is_finite() || !(0.0..=1e6).contains(&x))
+ {
+ return Err(JobError::new(
+ ErrorCode::InvalidRequest,
+ "area light requires finite center, orthogonal half-edges of 0.0001..1000000 mm and radiance 0..1000000",
+ ));
+ }
+ Ok(())
+ }
+
+ pub fn area(self) -> f64 {
+ 4.0 * vector(self.u).cross(vector(self.v)).len()
+ }
+}
+
+/// Uniform-radiance finite angular disk at infinity. Direction points toward the sun.
+#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct Sun {
+ pub direction: [f64; 3],
+ pub angular_radius_rad: f64,
+ pub radiance: [f64; 3],
+}
+impl Sun {
+ pub fn validate(self) -> Result<()> {
+ if self.direction.iter().any(|x| !x.is_finite())
+ || !(1e-8..=1e8).contains(&vector(self.direction).len())
+ || !self.angular_radius_rad.is_finite()
+ || !(0.001..=std::f64::consts::FRAC_PI_2).contains(&self.angular_radius_rad)
+ || self.radiance.iter().any(|x| !x.is_finite() || !(0.0..=1e8).contains(x))
+ {
+ return Err(JobError::new(
+ ErrorCode::InvalidRequest,
+ "sun requires finite nonzero direction, radius 0.001..pi/2 radians and radiance 0..100000000",
+ ));
+ }
+ Ok(())
+ }
+ pub fn solid_angle(self) -> f64 {
+ 4.0 * std::f64::consts::PI * (0.5 * self.angular_radius_rad).sin().powi(2)
+ }
+ pub fn direction(self) -> Vec3 {
+ let d = vector(self.direction);
+ d / d.len()
+ }
+}
+
+/// A small copyable light list, serialized as an ordinary bounded JSON array.
+#[derive(Clone, Copy, Debug, PartialEq, Default)]
+pub struct AreaLights {
+ entries: [AreaLight; MAX_AREA_LIGHTS],
+ len: usize,
+}
+
+impl AreaLights {
+ pub fn new(lights: &[AreaLight]) -> Result<Self> {
+ if lights.len() > MAX_AREA_LIGHTS {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "at most four area lights are supported"));
+ }
+ let mut result = Self::default();
+ for (slot, light) in result.entries.iter_mut().zip(lights) {
+ light.validate()?;
+ *slot = *light;
+ }
+ result.len = lights.len();
+ Ok(result)
+ }
+
+ pub fn iter(&self) -> impl Iterator<Item = &AreaLight> {
+ self.entries.iter().take(self.len)
+ }
+}
+
+impl Serialize for AreaLights {
+ fn serialize<S: serde::Serializer>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> {
+ serializer.collect_seq(self.iter())
+ }
+}
+
+impl<'de> Deserialize<'de> for AreaLights {
+ fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> std::result::Result<Self, D::Error> {
+ struct Visitor;
+ impl<'de> serde::de::Visitor<'de> for Visitor {
+ type Value = AreaLights;
+ fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str("an array of at most four rectangular area lights")
+ }
+ fn visit_seq<A: serde::de::SeqAccess<'de>>(self, mut seq: A) -> std::result::Result<Self::Value, A::Error> {
+ let mut result = AreaLights::default();
+ while let Some(light) = seq.next_element::<AreaLight>()? {
+ let slot =
+ result.entries.get_mut(result.len).ok_or_else(|| serde::de::Error::custom("at most four area lights are supported"))?;
+ light.validate().map_err(serde::de::Error::custom)?;
+ *slot = light;
+ result.len += 1;
+ }
+ Ok(result)
+ }
+ }
+ deserializer.deserialize_seq(Visitor)
+ }
+}
+
+#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
+#[serde(default, deny_unknown_fields)]
+pub struct StudioLighting {
+ pub sun: Option<Sun>,
+ pub environment: [f64; 3],
+ pub area_lights: AreaLights,
+}
+
+impl StudioLighting {
+ pub fn validate(self) -> Result<()> {
+ if let Some(sun) = self.sun {
+ sun.validate()?;
+ }
+ if self.environment.into_iter().any(|x| !x.is_finite() || !(0.0..=1e6).contains(&x)) {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "environment radiance must be finite and 0..1000000"));
+ }
+ for light in self.area_lights.iter() {
+ light.validate()?;
+ }
+ Ok(())
+ }
+}
+
+/// Output-only transform, after linear accumulation and exposure, before sRGB.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum ToneMap {
+ #[default]
+ Reinhard,
+ AcesFitted,
+}
+
+impl ToneMap {
+ pub fn map(self, linear: f64) -> f64 {
+ let x = linear.max(0.0);
+ match self {
+ Self::Reinhard => x / (1.0 + x),
+ // Narkowicz (2016), published rational approximation to the ACES RRT/ODT.
+ // This is a per-channel fit, not the full ACES colour-management pipeline.
+ // https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
+ Self::AcesFitted => ((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14)).clamp(0.0, 1.0),
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn light() -> AreaLight {
+ AreaLight { center: [0.0, 0.0, 4.0], u: [2.0, 0.0, 0.0], v: [0.0, -3.0, 0.0], radiance: [5.0; 3] }
+ }
+
+ #[test]
+ fn bounded_lights_validate_geometry_and_round_trip() {
+ let lights = AreaLights::new(&[light(); 4]).unwrap();
+ assert_eq!(light().area(), 24.0);
+ assert_eq!(serde_json::from_str::<AreaLights>(&serde_json::to_string(&lights).unwrap()).unwrap(), lights);
+ assert!(AreaLights::new(&[light(); 5]).is_err());
+ assert!(serde_json::from_str::<AreaLights>(&serde_json::to_string(&vec![light(); 5]).unwrap()).is_err());
+ for bad in [
+ AreaLight { u: [0.0; 3], ..light() },
+ AreaLight { v: [1.0, 1.0, 0.0], ..light() },
+ AreaLight { radiance: [-1.0; 3], ..light() },
+ AreaLight { center: [f64::NAN; 3], ..light() },
+ ] {
+ assert!(bad.validate().is_err());
+ }
+ assert!(StudioLighting { environment: [f64::INFINITY; 3], ..Default::default() }.validate().is_err());
+ }
+
+ #[test]
+ fn finite_sun_validates_and_integrates_its_solid_angle() {
+ let sun = Sun { direction: [0.0, 0.0, 2.0], angular_radius_rad: 0.2, radiance: [3.0; 3] };
+ sun.validate().unwrap();
+ assert_eq!(sun.direction(), Vec3::Z);
+ assert!((sun.solid_angle() - 2.0 * std::f64::consts::PI * (1.0 - 0.2_f64.cos())).abs() < 1e-14);
+ for radius in [0.0, 0.00001, f64::NAN, 2.0] {
+ assert!(Sun { angular_radius_rad: radius, ..sun }.validate().is_err());
+ }
+ assert!(Sun { direction: [0.0; 3], ..sun }.validate().is_err());
+ }
+
+ #[test]
+ fn filmic_is_bounded_monotone_and_preserves_black() {
+ assert_eq!(ToneMap::default(), ToneMap::Reinhard);
+ assert_eq!(ToneMap::AcesFitted.map(0.0), 0.0);
+ assert!((ToneMap::AcesFitted.map(1.0) - 0.8037974683544302).abs() < 1e-14);
+ let mut previous = 0.0;
+ for i in 0..1000 {
+ let value = ToneMap::AcesFitted.map(f64::from(i) / 100.0);
+ assert!((previous..=1.0).contains(&value));
+ previous = value;
+ }
+ }
+}
diff --git a/crates/render/src/job/mod.rs b/crates/render/src/job/mod.rs
index e7f6c45e2d..7947d82459 100644
--- a/crates/render/src/job/mod.rs
+++ b/crates/render/src/job/mod.rs
@@ -1,4 +1,4 @@
-//! CPU product-image work and its device-independent, session-scoped protocol.
+//! Product-image work and its device-independent, session-scoped protocol.
//! Hosts own execution; documents and history never contain these values.
use std::fmt;
@@ -13,8 +13,73 @@ use crate::{BackendId, Camera, ExecutorId};
mod host;
mod image;
-pub use host::{CpuHost, HostKind, JobHandle, JobStatus, RenderFrame};
-pub use image::{Admission, ImageTask, TaskPoll, admit};
+mod lens;
+mod lighting;
+mod png;
+pub mod textures;
+pub use host::{CpuHost, HostKind, ImageHost, JobHandle, JobStatus, RenderFrame};
+pub use image::{Admission, ImageTask, TaskPoll, admit, admit_geometry};
+pub use lens::ThinLens;
+pub use lighting::{AreaLight, AreaLights, MAX_AREA_LIGHTS, StudioLighting, Sun, ToneMap};
+pub use png::PngTask;
+
+/// Runtime sampling intent, separate from saved documents and device resources.
+#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
+#[serde(default, deny_unknown_fields)]
+pub struct JobOptions {
+ pub samples: u32,
+ pub max_depth: u32,
+ pub seed: u32,
+ pub exposure_ev: f64,
+ pub lens: Option<ThinLens>,
+ pub lighting: Option<StudioLighting>,
+ pub tone_map: ToneMap,
+ /// Optional final spatial filter. Raw progressive accumulation remains unchanged.
+ pub denoise: bool,
+}
+
+impl Default for JobOptions {
+ fn default() -> Self {
+ Self { samples: 64, max_depth: 8, seed: 0, exposure_ev: 0.0, lens: None, lighting: None, tone_map: ToneMap::default(), denoise: false }
+ }
+}
+
+impl JobOptions {
+ pub fn validate(&self) -> Result<()> {
+ if let Some(lighting) = self.lighting {
+ lighting.validate()?;
+ }
+ if let Some(lens) = self.lens {
+ lens.validate()?;
+ }
+ if !(1..=4096).contains(&self.samples)
+ || !(1..=16).contains(&self.max_depth)
+ || !self.exposure_ev.is_finite()
+ || !(-32.0..=32.0).contains(&self.exposure_ev)
+ {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "samples must be 1..4096, depth 1..16 and exposure -32..32 EV"));
+ }
+ Ok(())
+ }
+}
+
+/// One bounded quantum of image work. Implementations check cancellation between quanta.
+pub trait ImageWork: Send {
+ fn step(&mut self, units: usize) -> Result<TaskPoll>;
+}
+impl ImageWork for ImageTask {
+ fn step(&mut self, units: usize) -> Result<TaskPoll> {
+ self.step(units)
+ }
+}
+
+/// Device-independent executor boundary. The host owns admission leases and publication;
+/// an executor owns computation only. GPU implementations live above the render crate.
+pub trait ImageExecutor: Send + Sync {
+ fn descriptor(&self) -> Result<crate::ExecutorDescriptor>;
+ fn admit(&self, scene: &crate::ProductScene, request: &ImageRequest, options: JobOptions) -> Result<Admission>;
+ fn begin(&self, scene: crate::ProductScene, request: ImageRequest, options: JobOptions, cancel: CancelToken) -> Result<Box<dyn ImageWork>>;
+}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
@@ -108,11 +173,16 @@ impl CancelToken {
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ImageRequest {
+ /// Captured runtime resources; never persisted or accepted as serialized pixel arrays.
+ #[serde(skip)]
+ pub environment: Option<Arc<crate::lighting::environment::EnvironmentSource>>,
pub camera: Camera,
pub width: u32,
pub height: u32,
pub background: [u8; 3],
pub transparent_background: bool,
+ #[serde(skip)]
+ pub textures: Option<Arc<textures::RuntimeTextures>>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
diff --git a/crates/render/src/job/png.rs b/crates/render/src/job/png.rs
new file mode 100644
index 0000000000..d60cb30aed
--- /dev/null
+++ b/crates/render/src/job/png.rs
@@ -0,0 +1,81 @@
+//! Bounded PNG encoding shared by native image executors.
+use super::{CancelToken, ErrorCode, ImageRequest, ImageWork, JobError, Phase, Progress, Result, TaskPoll};
+use std::{
+ io::Write,
+ sync::{Arc, Mutex},
+};
+
+struct Output {
+ bytes: Arc<Mutex<Vec<u8>>>,
+ limit: usize,
+ cancel: CancelToken,
+}
+impl Write for Output {
+ fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {
+ if self.cancel.is_cancelled() {
+ return Err(std::io::Error::other("render cancelled"));
+ }
+ let mut out = self.bytes.lock().map_err(|_| std::io::Error::other("PNG lock poisoned"))?;
+ if out.len().checked_add(bytes.len()).is_none_or(|n| n > self.limit) {
+ return Err(std::io::Error::other("PNG byte limit exceeded"));
+ }
+ out.try_reserve_exact(bytes.len()).map_err(|_| std::io::Error::other("PNG allocation failed"))?;
+ out.extend_from_slice(bytes);
+ Ok(bytes.len())
+ }
+ fn flush(&mut self) -> std::io::Result<()> {
+ Ok(())
+ }
+}
+
+/// Owns admitted RGBA bytes and yields after at most four scanlines.
+pub struct PngTask {
+ rgba: Vec<u8>,
+ row: usize,
+ width: usize,
+ height: usize,
+ bytes: Arc<Mutex<Vec<u8>>>,
+ writer: Option<png::StreamWriter<'static, Output>>,
+ cancel: CancelToken,
+}
+impl PngTask {
+ pub fn new(request: &ImageRequest, rgba: Vec<u8>, cancel: CancelToken) -> Result<Self> {
+ let pixels = u64::from(request.width) * u64::from(request.height);
+ if !(1..=4096).contains(&request.width) || !(1..=4096).contains(&request.height) || pixels > 4_194_304 || rgba.len() as u64 != pixels * 4 {
+ return Err(JobError::new(ErrorCode::InvalidRequest, "invalid PNG dimensions or RGBA length"));
+ }
+ cancel.check()?;
+ let bytes = Arc::new(Mutex::new(Vec::new()));
+ let output = Output { bytes: bytes.clone(), limit: (pixels * 8 + 65_536) as usize, cancel: cancel.clone() };
+ let mut encoder = png::Encoder::new(output, request.width, request.height);
+ encoder.set_color(png::ColorType::Rgba);
+ encoder.set_depth(png::BitDepth::Eight);
+ encoder.set_source_srgb(png::SrgbRenderingIntent::Perceptual);
+ let writer = encoder.write_header().and_then(|w| w.into_stream_writer()).map_err(encoding)?;
+ Ok(Self { rgba, row: 0, width: request.width as usize, height: request.height as usize, bytes, writer: Some(writer), cancel })
+ }
+}
+fn encoding(e: impl std::fmt::Display) -> JobError {
+ JobError::new(ErrorCode::EncodingFailed, e.to_string())
+}
+impl ImageWork for PngTask {
+ fn step(&mut self, _units: usize) -> Result<TaskPoll> {
+ self.cancel.check()?;
+ for _ in 0..4 {
+ if self.row == self.height {
+ break;
+ }
+ let start = self.row * self.width * 4;
+ let row = self.rgba.get(start..start + self.width * 4).ok_or_else(|| encoding("missing PNG row"))?;
+ self.writer.as_mut().ok_or_else(|| encoding("PNG already completed"))?.write_all(row).map_err(encoding)?;
+ self.row += 1;
+ }
+ if self.row != self.height {
+ return Ok(TaskPoll::Pending(Progress { phase: Phase::Encoding, done: self.row as u64, total: self.height as u64 }));
+ }
+ self.writer.take().ok_or_else(|| encoding("PNG already completed"))?.finish().map_err(encoding)?;
+ self.cancel.check()?;
+ let mut bytes = self.bytes.lock().map_err(|_| encoding("PNG lock poisoned"))?;
+ Ok(TaskPoll::Complete(std::mem::take(&mut *bytes)))
+ }
+}
diff --git a/crates/render/src/job/textures.rs b/crates/render/src/job/textures.rs
new file mode 100644
index 0000000000..c45395c616
--- /dev/null
+++ b/crates/render/src/job/textures.rs
@@ -0,0 +1,302 @@
+//! Immutable request-only planar opaque textures. Codecs run on the image worker.
+use super::{CancelToken, ErrorCode, JobError, Result};
+use crate::{
+ ProductScene,
+ surface::{srgb8_to_linear, unit_direction},
+ texture_input::{MapRole, TextureSource},
+ texture_sampling::TextureView,
+};
+use serde::{Deserialize, Serialize};
+use solidcraft_geom::Vec3;
+
+pub const MAX_TEXTURE_BINDINGS: usize = 16;
+pub const MAX_TEXTURE_PIXELS_BYTES: u64 = 32 * 1024 * 1024;
+pub const MAX_TEXTURE_SOURCE_BYTES: u64 = 16 * 1024 * 1024;
+pub const MAX_PLANAR_REPEAT: f64 = 128.0;
+
+fn invalid(message: impl Into<String>) -> JobError {
+ JobError::new(ErrorCode::InvalidRequest, message)
+}
+fn v(a: [f64; 3]) -> Vec3 {
+ Vec3::new(a[0], a[1], a[2])
+}
+
+/// `u` and `v` span one full repeat in world-space millimetres. Image v increases
+/// downward; normal-map green points along the caller's positive v direction.
+#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct PlanarFrame {
+ pub origin: [f64; 3],
+ pub u: [f64; 3],
+ pub v: [f64; 3],
+}
+impl PlanarFrame {
+ pub fn validate(self) -> Result<()> {
+ let u = v(self.u);
+ let vv = v(self.v);
+ let ul = u.len();
+ let vl = vv.len();
+ if self.origin.into_iter().any(|c| !c.is_finite() || c.abs() > 1e12)
+ || !u.is_finite()
+ || !vv.is_finite()
+ || !(0.001..=1e6).contains(&ul)
+ || !(0.001..=1e6).contains(&vl)
+ || u.dot(vv).abs() > 1e-6 * ul * vl
+ {
+ return Err(invalid("planar texture frame requires finite origin and orthogonal u/v repeat vectors of 0.001..1000000 mm"));
+ }
+ Ok(())
+ }
+ pub fn uv(self, point: Vec3) -> Result<[f64; 2]> {
+ self.validate()?;
+ let d = point - v(self.origin);
+ let u = v(self.u);
+ let vv = v(self.v);
+ let uv = [d.dot(u) / u.len2(), d.dot(vv) / vv.len2()];
+ if uv.iter().any(|c| !c.is_finite() || c.abs() > MAX_PLANAR_REPEAT) {
+ return Err(invalid("planar UV exceeds the GPU precision bound of 128 repeats"));
+ }
+ Ok(uv)
+ }
+ pub fn mapped_normal(self, normal: Vec3, geometric: Vec3, rgb: [f64; 3], strength: f64) -> Result<Vec3> {
+ self.validate()?;
+ if !strength.is_finite() || !(0.0..=1.0).contains(&strength) || rgb.iter().any(|c| !c.is_finite() || !(0.0..=1.0).contains(c)) {
+ return Err(invalid("invalid tangent normal input"));
+ }
+ let n = unit_direction(normal).map_err(|e| invalid(e.to_string()))?;
+ let g = unit_direction(geometric).map_err(|e| invalid(e.to_string()))?;
+ let u = unit_direction(v(self.u)).map_err(|e| invalid(e.to_string()))?;
+ let tangent = u - n * n.dot(u);
+ if tangent.len2() < 1e-12 {
+ return Ok(n);
+ }
+ let tangent = unit_direction(tangent).map_err(|e| invalid(e.to_string()))?;
+ let handedness = if n.dot(v(self.u).cross(v(self.v))) < 0.0 { -1.0 } else { 1.0 };
+ let local = Vec3::new((2.0 * rgb[0] - 1.0) * strength, (2.0 * rgb[1] - 1.0) * strength, 2.0 * rgb[2] - 1.0);
+ if local.len2() < 1e-12 || local.z <= 0.0 {
+ return Ok(n);
+ }
+ let mapped =
+ unit_direction(tangent * local.x + n.cross(tangent) * (handedness * local.y) + n * local.z).map_err(|e| invalid(e.to_string()))?;
+ Ok(if mapped.dot(g) <= 0.0 { n } else { mapped })
+ }
+}
+
+#[derive(Clone)]
+pub struct TextureMap {
+ source: TextureSource,
+ retained_bytes: usize,
+}
+impl std::fmt::Debug for TextureMap {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("TextureMap").field("info", self.source.info()).finish()
+ }
+}
+impl TextureMap {
+ pub fn new(bytes: Vec<u8>, role: MapRole) -> Result<Self> {
+ if !matches!(role, MapRole::BaseColor | MapRole::NormalOpenGl) {
+ return Err(invalid("only sRGB base color and OpenGL tangent normal maps are supported"));
+ }
+ let retained_bytes = bytes.capacity();
+ let source = TextureSource::new(bytes, role).map_err(|e| invalid(e.to_string()))?;
+ if source.info().width > 1024 || source.info().height > 1024 {
+ return Err(invalid("runtime texture maps are limited to 1024x1024"));
+ }
+ Ok(Self { source, retained_bytes })
+ }
+ pub fn retained_bytes(&self) -> usize {
+ self.retained_bytes
+ }
+ pub fn dimensions(&self) -> [u32; 2] {
+ [self.source.info().width, self.source.info().height]
+ }
+ pub fn role(&self) -> MapRole {
+ self.source.info().role
+ }
+ pub fn decode(&self, cancel: &CancelToken) -> Result<Vec<f32>> {
+ cancel.check()?;
+ let decoded = self.source.decode(|| cancel.is_cancelled()).map_err(|e| {
+ if cancel.is_cancelled() { JobError::new(ErrorCode::Cancelled, "texture decoding cancelled") } else { invalid(e.to_string()) }
+ })?;
+ let mut rgba = Vec::new();
+ rgba.try_reserve_exact(decoded.rgba().len()).map_err(|_| JobError::new(ErrorCode::AllocationFailed, "texture pixel allocation failed"))?;
+ for (index, pixel) in decoded.rgba().as_chunks::<4>().0.iter().enumerate() {
+ if index % 1024 == 0 {
+ cancel.check()?;
+ }
+ for (channel, value) in pixel.iter().enumerate() {
+ let linear = if self.role() == MapRole::BaseColor && channel < 3 { srgb8_to_linear(*value) } else { f64::from(*value) / 255.0 };
+ rgba.push(linear as f32);
+ }
+ }
+ Ok(rgba)
+ }
+}
+
+#[derive(Clone, Debug)]
+pub struct TextureBinding {
+ pub body_index: usize,
+ pub body_name: String,
+ pub frame: PlanarFrame,
+ pub normal_strength: f64,
+ pub base_color: Option<TextureMap>,
+ pub normal: Option<TextureMap>,
+}
+#[derive(Clone, Debug)]
+pub struct RuntimeTextures {
+ bindings: Vec<TextureBinding>,
+ source_bytes: u64,
+ pixel_bytes: u64,
+}
+#[derive(Clone, Debug, Serialize)]
+pub struct TextureSummary {
+ pub bodies: usize,
+ pub encoded_bytes: u64,
+ pub linear_pixel_bytes: u64,
+}
+impl RuntimeTextures {
+ pub fn new(bindings: Vec<TextureBinding>) -> Result<Self> {
+ if bindings.is_empty() || bindings.len() > MAX_TEXTURE_BINDINGS {
+ return Err(invalid("runtime textures require 1..16 distinct body bindings"));
+ }
+ let mut seen = std::collections::BTreeSet::new();
+ let mut source_bytes = 0;
+ let mut pixel_bytes = 0;
+ for binding in &bindings {
+ binding.frame.validate()?;
+ if binding.body_index >= 16384
+ || binding.body_name.is_empty()
+ || binding.body_name.len() > 1024
+ || binding.body_name.chars().any(char::is_control)
+ || !seen.insert(binding.body_index)
+ || !binding.normal_strength.is_finite()
+ || !(0.0..=1.0).contains(&binding.normal_strength)
+ || (binding.base_color.is_none() && binding.normal.is_none())
+ {
+ return Err(invalid("invalid or duplicate runtime texture body binding"));
+ }
+ if binding.base_color.as_ref().is_some_and(|m| m.role() != MapRole::BaseColor)
+ || binding.normal.as_ref().is_some_and(|m| m.role() != MapRole::NormalOpenGl)
+ {
+ return Err(invalid("texture role does not match its binding"));
+ }
+ for map in [&binding.base_color, &binding.normal].into_iter().flatten() {
+ source_bytes += map.retained_bytes as u64;
+ pixel_bytes += map.source.info().rgba_bytes * 4;
+ }
+ }
+ if source_bytes > MAX_TEXTURE_SOURCE_BYTES || pixel_bytes > MAX_TEXTURE_PIXELS_BYTES {
+ return Err(invalid("runtime textures exceed 16 MiB encoded or 32 MiB linear pixel budget"));
+ }
+ Ok(Self { bindings, source_bytes, pixel_bytes })
+ }
+ pub fn bindings(&self) -> &[TextureBinding] {
+ &self.bindings
+ }
+ pub fn summary(&self) -> TextureSummary {
+ TextureSummary { bodies: self.bindings.len(), encoded_bytes: self.source_bytes, linear_pixel_bytes: self.pixel_bytes }
+ }
+ /// Source snapshots, codec scratch, decoded bytes, staging and device buffer,
+ /// plus lookup records. Conservatively includes overlapping preparation.
+ pub fn working_bytes(&self) -> u64 {
+ self.source_bytes + self.pixel_bytes * 4 + 64 * 1024 * 1024 + 1024 * 1024
+ }
+ pub fn validate_scene(&self, scene: &ProductScene) -> Result<()> {
+ for binding in &self.bindings {
+ let body = scene
+ .meshes
+ .get(binding.body_index)
+ .filter(|body| body.name == binding.body_name)
+ .ok_or_else(|| invalid("texture ordinal and exact body name must match render.scene"))?;
+ if body.opacity != 1.0 || body.transmission.is_some() || body.faces.iter().any(|f| f.opacity != 1.0 || f.transmission.is_some()) {
+ return Err(invalid("texture maps currently support opaque bodies only; glass and alpha maps are unsupported"));
+ }
+ let bounds = body.mesh.bounds();
+ for x in [bounds.min.x, bounds.max.x] {
+ for y in [bounds.min.y, bounds.max.y] {
+ for z in [bounds.min.z, bounds.max.z] {
+ binding.frame.uv(Vec3::new(x, y, z))?;
+ }
+ }
+ }
+ }
+ Ok(())
+ }
+}
+
+/// Independent f64 bilinear reference over the worker's normalized pixels.
+pub fn sample_map(rgba: &[f32], dimensions: [u32; 2], uv: [f64; 2]) -> Result<[f64; 3]> {
+ TextureView::new(rgba, dimensions).and_then(|v| v.sample_repeat_opaque(uv)).map_err(|e| invalid(e.to_string()))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use image::ImageEncoder;
+ fn png(width: u32, height: u32, pixels: &[u8]) -> Vec<u8> {
+ let mut bytes = Vec::new();
+ image::codecs::png::PngEncoder::new(&mut bytes).write_image(pixels, width, height, image::ExtendedColorType::Rgba8).unwrap();
+ bytes
+ }
+ fn frame() -> PlanarFrame {
+ PlanarFrame { origin: [0.; 3], u: [2., 0., 0.], v: [0., 4., 0.] }
+ }
+ fn binding() -> TextureBinding {
+ TextureBinding {
+ body_index: 0,
+ body_name: "opaque".into(),
+ frame: frame(),
+ normal_strength: 1.,
+ base_color: Some(TextureMap::new(png(1, 1, &[128, 64, 255, 0]), MapRole::BaseColor).unwrap()),
+ normal: None,
+ }
+ }
+ #[test]
+ fn explicit_color_semantics_and_repeat_filter_ignore_alpha() {
+ let color = TextureMap::new(png(2, 1, &[128, 64, 255, 0, 255, 0, 128, 255]), MapRole::BaseColor).unwrap();
+ let data = TextureMap::new(png(1, 1, &[128, 64, 255, 0]), MapRole::NormalOpenGl).unwrap();
+ let c = color.decode(&CancelToken::default()).unwrap();
+ let n = data.decode(&CancelToken::default()).unwrap();
+ assert!((f64::from(c[0]) - srgb8_to_linear(128)).abs() < 1e-7);
+ assert!((n[0] - 128. / 255.).abs() < 1e-7);
+ let a = sample_map(&c, [2, 1], [0.25, 0.5]).unwrap();
+ let b = sample_map(&c, [2, 1], [-0.75, 100.5]).unwrap();
+ assert_eq!(a, b);
+ assert!((a[0] - srgb8_to_linear(128)).abs() < 1e-7);
+ let seam = sample_map(&c, [2, 1], [0., 0.]).unwrap();
+ assert!((seam[0] - (1. + a[0]) / 2.).abs() < 1e-7);
+ let cancel = CancelToken::default();
+ cancel.cancel();
+ assert_eq!(color.decode(&cancel).unwrap_err().code, ErrorCode::Cancelled);
+ }
+ #[test]
+ fn tangent_frame_preserves_handedness_and_falls_back_safely() {
+ let f = frame();
+ assert_eq!(f.uv(Vec3::new(-1., 2., 900.)).unwrap(), [-0.5, 0.5]);
+ let normal = f.mapped_normal(Vec3::Z, Vec3::Z, [0.5, 1., 1.], 1.).unwrap();
+ assert!((normal - Vec3::new(0., 1., 1.).normalized().unwrap()).len() < 1e-12);
+ let mirrored = PlanarFrame { v: [0., -4., 0.], ..f }.mapped_normal(Vec3::Z, Vec3::Z, [0.5, 1., 1.], 1.).unwrap();
+ assert!((mirrored - Vec3::new(0., -1., 1.).normalized().unwrap()).len() < 1e-12);
+ for rgb in [[0.5; 3], [0., 0., 0.], [1., 1., 0.5]] {
+ assert_eq!(f.mapped_normal(Vec3::Z, Vec3::Z, rgb, 1.).unwrap(), Vec3::Z);
+ }
+ assert_eq!(f.mapped_normal(Vec3::X, Vec3::X, [1.; 3], 1.).unwrap(), Vec3::X);
+ assert!(PlanarFrame { u: [0.; 3], ..f }.validate().is_err());
+ assert!(PlanarFrame { v: [1., 4., 0.], ..f }.validate().is_err());
+ assert!(f.uv(Vec3::new(258., 0., 0.)).is_err());
+ }
+ #[test]
+ fn bounded_resources_reject_duplicate_roles_and_encoded_capacity() {
+ let b = binding();
+ let t = RuntimeTextures::new(vec![b.clone()]).unwrap();
+ assert_eq!(t.summary().linear_pixel_bytes, 16);
+ assert!(RuntimeTextures::new(vec![b.clone(), b]).is_err());
+ let mut wrong = binding();
+ wrong.normal = wrong.base_color.take();
+ assert!(RuntimeTextures::new(vec![wrong]).is_err());
+ let mut bytes = png(1, 1, &[0; 4]);
+ bytes.reserve_exact(16 * 1024 * 1024);
+ assert!(TextureMap::new(bytes, MapRole::BaseColor).is_err());
+ assert!(TextureMap::new(png(1, 1, &[0; 4]), MapRole::Roughness).is_err());
+ }
+}
diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs
index 4f9e70be79..f5be5f0eb9 100644
--- a/crates/render/src/lib.rs
+++ b/crates/render/src/lib.rs
@@ -5,12 +5,16 @@
#![forbid(unsafe_code)]
mod analysis;
+pub mod anisotropic_surface;
mod backend;
mod camera;
+pub mod clear_coat;
mod curve_display;
+pub mod film;
mod gif;
pub mod job;
pub mod lighting;
+pub mod mapping;
mod product;
mod raster;
mod scene;
@@ -20,6 +24,7 @@ pub mod texture_input;
pub mod texture_interpolation;
pub mod texture_lod;
pub mod texture_sampling;
+pub mod transmission;
pub use analysis::{AnalysisColors, AnalysisMode, SceneAnalysis};
pub use backend::{
diff --git a/crates/render/src/lighting/environment.rs b/crates/render/src/lighting/environment.rs
new file mode 100644
index 0000000000..6a1500c8d4
--- /dev/null
+++ b/crates/render/src/lighting/environment.rs
@@ -0,0 +1,304 @@
+//! Captured runtime environment input and original exact-solid-angle importance tables.
+//! The HDR decoder retains source primaries: admission below makes interpretation explicit.
+use super::{HdrDecodeTask, HdrSource, HdrTaskPoll};
+use crate::job::{CancelToken, ErrorCode, JobError, Result};
+use serde::{Deserialize, Serialize};
+use sha2::{Digest, Sha256};
+use solidcraft_geom::Vec3;
+use std::{
+ f64::consts::{PI, TAU},
+ sync::Arc,
+};
+
+fn invalid(message: impl Into<String>) -> JobError {
+ JobError::new(ErrorCode::InvalidRequest, message)
+}
+fn reserve<T>(count: usize) -> Result<Vec<T>> {
+ let mut v = Vec::new();
+ v.try_reserve_exact(count).map_err(|_| JobError::new(ErrorCode::AllocationFailed, "environment allocation failed"))?;
+ Ok(v)
+}
+
+/// Original artistic gradient, not a calibrated atmosphere. No imported image assets.
+#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
+#[serde(default, deny_unknown_fields)]
+pub struct SkyGradient {
+ pub zenith: [f32; 3],
+ pub horizon: [f32; 3],
+ pub ground: [f32; 3],
+}
+impl Default for SkyGradient {
+ fn default() -> Self {
+ Self { zenith: [0.16, 0.32, 0.7], horizon: [0.8, 0.9, 1.0], ground: [0.12, 0.1, 0.08] }
+ }
+}
+impl SkyGradient {
+ pub fn validate(self) -> Result<()> {
+ if self.zenith.into_iter().chain(self.horizon).chain(self.ground).any(|v| !v.is_finite() || !(0.0..=1e6).contains(&v)) {
+ return Err(invalid("sky radiance must be finite and within 0..1000000"));
+ }
+ Ok(())
+ }
+ fn evaluate(self, z: f64) -> [f32; 3] {
+ let endpoint = if z >= 0.0 { self.zenith } else { self.ground };
+ let blend = z.abs().sqrt() as f32;
+ std::array::from_fn(|i| self.horizon[i] * (1.0 - blend) + endpoint[i] * blend)
+ }
+}
+
+#[derive(Clone, Debug, Serialize)]
+pub struct EnvironmentInfo {
+ pub kind: &'static str,
+ pub width: u32,
+ pub height: u32,
+ pub encoded_bytes: u64,
+ pub source_sha256: String,
+ pub color_policy: &'static str,
+ pub rotation_rad: f64,
+ pub intensity: f64,
+}
+#[derive(Clone)]
+enum Source {
+ Hdr(HdrSource),
+ Sky(SkyGradient),
+}
+/// Immutable captured input. Preparation happens in the image worker, with cancellation.
+#[derive(Clone)]
+pub struct EnvironmentSource {
+ source: Source,
+ info: EnvironmentInfo,
+ retained_bytes: u64,
+}
+impl std::fmt::Debug for EnvironmentSource {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("EnvironmentSource").field("info", &self.info).finish()
+ }
+}
+impl EnvironmentSource {
+ pub fn hdr(bytes: Vec<u8>, rotation_rad: f64, intensity: f64, assume_linear_srgb: bool) -> Result<Self> {
+ let retained_bytes = bytes.capacity() as u64;
+ let source = HdrSource::new(bytes).map_err(|e| invalid(e.to_string()))?;
+ let primaries = [0.64, 0.33, 0.30, 0.60, 0.15, 0.06, 0.3127, 0.3290];
+ let color_policy = match source.info().primaries {
+ Some(actual) if actual.iter().zip(primaries).all(|(a, b)| (a - b).abs() < 1e-5) => "declared_linear_srgb_d65",
+ Some(_) => return Err(invalid("HDR primaries must be sRGB/D65; convert the source before rendering")),
+ None if assume_linear_srgb => "explicit_assumed_linear_srgb_d65",
+ None => {
+ return Err(invalid("HDR primaries are unspecified: explicitly set assume_linear_srgb or supply a converted source with PRIMARIES"));
+ }
+ };
+ let info = EnvironmentInfo {
+ kind: "radiance_hdr",
+ width: source.info().width,
+ height: source.info().height,
+ encoded_bytes: source.info().encoded_bytes,
+ source_sha256: format!("{:x}", Sha256::digest(source.encoded_bytes())),
+ color_policy,
+ rotation_rad,
+ intensity,
+ };
+ let value = Self { source: Source::Hdr(source), info, retained_bytes };
+ value.validate()?;
+ Ok(value)
+ }
+ pub fn sky(sky: SkyGradient, rotation_rad: f64, intensity: f64) -> Result<Self> {
+ sky.validate()?;
+ let mut hash = Sha256::new();
+ hash.update(b"solidcraft.original-gradient-sky/1");
+ for v in sky.zenith.into_iter().chain(sky.horizon).chain(sky.ground) {
+ hash.update(v.to_le_bytes());
+ }
+ let value = Self {
+ source: Source::Sky(sky),
+ retained_bytes: 0,
+ info: EnvironmentInfo {
+ kind: "original_gradient_sky",
+ width: 512,
+ height: 256,
+ encoded_bytes: 0,
+ source_sha256: format!("{:x}", hash.finalize()),
+ color_policy: "authored_linear_srgb_d65",
+ rotation_rad,
+ intensity,
+ },
+ };
+ value.validate()?;
+ Ok(value)
+ }
+ pub fn info(&self) -> &EnvironmentInfo {
+ &self.info
+ }
+ pub fn validate(&self) -> Result<()> {
+ if !self.info.rotation_rad.is_finite()
+ || self.info.rotation_rad.abs() > 1e6
+ || !self.info.intensity.is_finite()
+ || !(0.0..=100.0).contains(&self.info.intensity)
+ {
+ return Err(invalid("environment rotation must be finite within +/-1000000 radians and intensity 0..100"));
+ }
+ Ok(())
+ }
+ /// Conservative additional peak: encoded bytes, decode/table/alias work, staging and GPU storage.
+ pub fn admitted_bytes(&self) -> u64 {
+ self.retained_bytes + u64::from(self.info.width) * u64::from(self.info.height) * 160 + 65536
+ }
+ pub fn prepare(&self, cancel: &CancelToken) -> Result<PreparedEnvironment> {
+ self.validate()?;
+ cancel.check()?;
+ let pixels = match &self.source {
+ Source::Hdr(source) => {
+ let mut task = HdrDecodeTask::new(source.clone()).map_err(|e| invalid(e.to_string()))?;
+ let decoded = loop {
+ cancel.check()?;
+ match task.step(16384, || cancel.is_cancelled()).map_err(|e| {
+ if cancel.is_cancelled() {
+ JobError::new(ErrorCode::Cancelled, "environment preparation cancelled")
+ } else {
+ invalid(e.to_string())
+ }
+ })? {
+ HdrTaskPoll::Pending(_) => {}
+ HdrTaskPoll::Complete(decoded) => break decoded,
+ }
+ };
+ let mut out = reserve(decoded.pixels().len())?;
+ out.extend_from_slice(decoded.pixels());
+ out
+ }
+ Source::Sky(sky) => {
+ let count = (self.info.width * self.info.height) as usize;
+ let mut out = reserve(count)?;
+ for y in 0..self.info.height {
+ cancel.check()?;
+ let z = (PI * (f64::from(y) + 0.5) / f64::from(self.info.height)).cos();
+ for _ in 0..self.info.width {
+ out.push(sky.evaluate(z));
+ }
+ }
+ out
+ }
+ };
+ PreparedEnvironment::new(self.info.width, self.info.height, pixels, cancel)
+ }
+}
+
+#[derive(Clone, Copy, Debug)]
+pub struct EnvironmentTexel {
+ pub rgb: [f32; 3],
+ /// Density per steradian, not probability per texel.
+ pub pdf: f32,
+ pub threshold: f32,
+ pub alias: u32,
+}
+pub struct PreparedEnvironment {
+ width: u32,
+ height: u32,
+ texels: Vec<EnvironmentTexel>,
+}
+impl PreparedEnvironment {
+ fn new(width: u32, height: u32, pixels: Vec<[f32; 3]>, cancel: &CancelToken) -> Result<Self> {
+ let count = (width * height) as usize;
+ if count != pixels.len() || count == 0 {
+ return Err(invalid("invalid environment storage"));
+ }
+ let mut masses = reserve(count)?;
+ let mut total = 0.0;
+ for (i, rgb) in pixels.iter().enumerate() {
+ if i % 1024 == 0 {
+ cancel.check()?;
+ }
+ let mass = (0.2126 * f64::from(rgb[0]) + 0.7152 * f64::from(rgb[1]) + 0.0722 * f64::from(rgb[2]))
+ * row_solid_angle(width, height, i / width as usize);
+ total += mass;
+ masses.push(mass);
+ }
+ if total == 0.0 {
+ for (i, mass) in masses.iter_mut().enumerate() {
+ *mass = row_solid_angle(width, height, i / width as usize);
+ }
+ total = 4.0 * PI;
+ }
+ let mut small = reserve(count)?;
+ let mut large = reserve(count)?;
+ let mut texels = reserve(count)?;
+ for (i, (rgb, mass)) in pixels.into_iter().zip(masses.iter_mut()).enumerate() {
+ if i % 1024 == 0 {
+ cancel.check()?;
+ }
+ let probability = *mass / total;
+ texels.push(EnvironmentTexel {
+ rgb,
+ pdf: (probability / row_solid_angle(width, height, i / width as usize)) as f32,
+ threshold: 1.0,
+ alias: i as u32,
+ });
+ *mass = probability * count as f64;
+ if *mass < 1.0 {
+ small.push(i);
+ } else {
+ large.push(i);
+ }
+ }
+ while !small.is_empty() && !large.is_empty() {
+ cancel.check()?;
+ let low = small.pop().ok_or_else(|| invalid("invalid alias table"))?;
+ let high = large.pop().ok_or_else(|| invalid("invalid alias table"))?;
+ let value = *masses.get(low).ok_or_else(|| invalid("invalid alias mass"))?;
+ let entry = texels.get_mut(low).ok_or_else(|| invalid("invalid alias index"))?;
+ entry.threshold = value as f32;
+ entry.alias = high as u32;
+ let remaining = masses.get_mut(high).ok_or_else(|| invalid("invalid alias mass"))?;
+ *remaining = (*remaining + value - 1.0).max(0.0);
+ if *remaining < 1.0 {
+ small.push(high);
+ } else {
+ large.push(high);
+ }
+ }
+ cancel.check()?;
+ Ok(Self { width, height, texels })
+ }
+ pub fn dimensions(&self) -> [u32; 2] {
+ [self.width, self.height]
+ }
+ pub fn texels(&self) -> &[EnvironmentTexel] {
+ &self.texels
+ }
+ /// CPU oracle of the same original piecewise-constant sphere mapping as WGSL.
+ pub fn sample(&self, choice: f64, coin: f64, azimuth: f64, vertical: f64) -> Result<(Vec3, [f32; 3], f32)> {
+ if [choice, coin, azimuth, vertical].into_iter().any(|v| !v.is_finite() || !(0.0..1.0).contains(&v)) {
+ return Err(invalid("environment samples must be in [0,1)"));
+ }
+ let scaled = choice * self.texels.len() as f64;
+ let index = scaled.floor() as usize;
+ let entry = self.texels.get(index).ok_or_else(|| invalid("environment sample index"))?;
+ let index = if coin < f64::from(entry.threshold) { index } else { entry.alias as usize };
+ let selected = self.texels.get(index).ok_or_else(|| invalid("environment alias index"))?;
+ let row = index / self.width as usize;
+ let column = index % self.width as usize;
+ let top = (PI * row as f64 / f64::from(self.height)).cos();
+ let bottom = (PI * (row + 1) as f64 / f64::from(self.height)).cos();
+ let z = top + (bottom - top) * vertical;
+ let phi = TAU * (column as f64 + azimuth) / f64::from(self.width);
+ let radius = (1.0 - z * z).max(0.0).sqrt();
+ Ok((Vec3::new(radius * phi.cos(), radius * phi.sin(), z), selected.rgb, selected.pdf))
+ }
+ pub fn evaluate(&self, direction: Vec3) -> Result<([f32; 3], f32)> {
+ let d = crate::surface::unit_direction(direction).map_err(|_| invalid("invalid environment direction"))?;
+ let column = ((d.y.atan2(d.x).rem_euclid(TAU) / TAU * f64::from(self.width)) as usize).min(self.width as usize - 1);
+ let row = ((d.z.clamp(-1.0, 1.0).acos() / PI * f64::from(self.height)) as usize).min(self.height as usize - 1);
+ let texel = self.texels.get(row * self.width as usize + column).ok_or_else(|| invalid("environment lookup index"))?;
+ Ok((texel.rgb, texel.pdf))
+ }
+}
+fn row_solid_angle(width: u32, height: u32, row: usize) -> f64 {
+ // Stable difference of cosines at polar rows.
+ let half = PI / (2.0 * f64::from(height));
+ (TAU / f64::from(width)) * 2.0 * (PI * (row as f64 + 0.5) / f64::from(height)).sin() * half.sin()
+}
+
+/// Shared captured source, cheap to clone into queued jobs.
+pub type EnvironmentResource = Arc<EnvironmentSource>;
+
+#[cfg(test)]
+mod tests;
diff --git a/crates/render/src/lighting/environment/tests.rs b/crates/render/src/lighting/environment/tests.rs
new file mode 100644
index 0000000000..e5b1fefbb1
--- /dev/null
+++ b/crates/render/src/lighting/environment/tests.rs
@@ -0,0 +1,104 @@
+use super::*;
+
+fn hdr(extra: &str, pixels: &[[u8; 4]]) -> Vec<u8> {
+ let mut bytes = format!("#?RADIANCE\nFORMAT=32-bit_rle_rgbe\n{extra}\n-Y 2 +X 4\n").into_bytes();
+ for pixel in pixels {
+ bytes.extend_from_slice(pixel);
+ }
+ bytes
+}
+#[test]
+fn captured_hdr_requires_explicit_color_policy_and_prepares_without_clipping() {
+ let bytes = hdr("", &[[128, 64, 32, 130]; 8]);
+ assert!(EnvironmentSource::hdr(bytes.clone(), 0.0, 1.0, false).is_err());
+ let source = EnvironmentSource::hdr(bytes, 0.3, 2.0, true).unwrap();
+ assert_eq!(source.info().source_sha256.len(), 64);
+ assert_eq!(source.info().color_policy, "explicit_assumed_linear_srgb_d65");
+ let prepared = source.prepare(&CancelToken::default()).unwrap();
+ assert_eq!(prepared.dimensions(), [4, 2]);
+ assert!(prepared.texels().iter().all(|t| t.rgb == [2.0, 1.0, 0.5]));
+ let wrong = hdr("PRIMARIES=0.67 0.33 0.21 0.71 0.14 0.08 0.31 0.33\n", &[[128, 128, 128, 129]; 8]);
+ assert!(EnvironmentSource::hdr(wrong, 0.0, 1.0, true).is_err());
+ let declared = hdr("PRIMARIES=0.64 0.33 0.30 0.60 0.15 0.06 0.3127 0.3290\n", &[[128, 128, 128, 129]; 8]);
+ assert!(EnvironmentSource::hdr(declared, 0.0, 1.0, false).is_ok());
+ assert!(EnvironmentSource::sky(SkyGradient::default(), f64::NAN, 1.0).is_err());
+ assert!(EnvironmentSource::sky(SkyGradient::default(), 0.0, 101.0).is_err());
+ let token = CancelToken::default();
+ token.cancel();
+ assert_eq!(source.prepare(&token).err().unwrap().code, ErrorCode::Cancelled);
+}
+#[test]
+fn exact_solid_angle_distribution_handles_poles_black_and_white_maps() {
+ for color in [[0.0; 3], [1.0; 3]] {
+ let map = PreparedEnvironment::new(64, 32, vec![color; 2048], &CancelToken::default()).unwrap();
+ let total: f64 = map.texels().iter().enumerate().map(|(i, t)| f64::from(t.pdf) * row_solid_angle(64, 32, i / 64)).sum();
+ assert!((total - 1.0).abs() < 1e-7);
+ for t in map.texels() {
+ assert!((f64::from(t.pdf) - 1.0 / (4.0 * PI)).abs() < 1e-8);
+ }
+ for d in [Vec3::Z, -Vec3::Z, Vec3::X, Vec3::new(1.0, -1e-12, 0.0)] {
+ let (value, pdf) = map.evaluate(d).unwrap();
+ assert_eq!(value, color);
+ assert!((f64::from(pdf) - 1.0 / (4.0 * PI)).abs() < 1e-8);
+ }
+ }
+}
+#[test]
+fn alias_samples_match_unequal_texel_probabilities_and_lookup_pdf() {
+ let mut pixels = vec![[0.0; 3]; 32];
+ pixels[2] = [1.0; 3];
+ pixels[11] = [4.0; 3];
+ pixels[29] = [2.0; 3];
+ let map = PreparedEnvironment::new(8, 4, pixels, &CancelToken::default()).unwrap();
+ let mut counts = [0usize; 32];
+ let mut rng = 17u64;
+ let mut random = || {
+ rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1);
+ (rng >> 11) as f64 / (1u64 << 53) as f64
+ };
+ let count = 200_000;
+ for _ in 0..count {
+ let (direction, rgb, pdf) = map.sample(random(), random(), random(), random()).unwrap();
+ let (actual, actual_pdf) = map.evaluate(direction).unwrap();
+ assert_eq!(rgb, actual);
+ assert_eq!(pdf, actual_pdf);
+ let index = if rgb == [1.0; 3] {
+ 2
+ } else if rgb == [4.0; 3] {
+ 11
+ } else {
+ assert_eq!(rgb, [2.0; 3]);
+ 29
+ };
+ counts[index] += 1;
+ }
+ for i in [2, 11, 29] {
+ let expected = f64::from(map.texels()[i].pdf) * row_solid_angle(8, 4, i / 8);
+ assert!((counts[i] as f64 / f64::from(count) - expected).abs() < 0.004);
+ }
+}
+#[test]
+fn original_sky_is_bounded_cancellable_and_reproducible() {
+ let source = EnvironmentSource::sky(SkyGradient::default(), 0.0, 1.0).unwrap();
+ let a = source.prepare(&CancelToken::default()).unwrap();
+ assert_eq!(a.dimensions(), [512, 256]);
+ let (zenith, _) = a.evaluate(Vec3::Z).unwrap();
+ let (horizon, _) = a.evaluate(Vec3::X).unwrap();
+ let (ground, _) = a.evaluate(-Vec3::Z).unwrap();
+ assert!(zenith[2] > zenith[0]);
+ assert!(horizon[0] > zenith[0]);
+ assert!(ground[0] > ground[2]);
+ assert!(source.admitted_bytes() > a.texels().len() as u64 * 64);
+ assert!(EnvironmentSource::sky(SkyGradient { zenith: [f32::INFINITY; 3], ..Default::default() }, 0.0, 1.0).is_err());
+}
+
+#[test]
+fn hdr_admission_counts_retained_capacity_not_just_file_length() {
+ let bytes = hdr("", &[[128, 128, 128, 129]; 8]);
+ let mut overallocated = Vec::with_capacity(super::super::MAX_HDR_BYTES);
+ overallocated.extend_from_slice(&bytes);
+ let retained = overallocated.capacity() as u64;
+ let source = EnvironmentSource::hdr(overallocated, 0.0, 1.0, true).unwrap();
+ assert_eq!(source.info().encoded_bytes, bytes.len() as u64);
+ assert_eq!(source.admitted_bytes(), retained + 8 * 160 + 65536);
+}
diff --git a/crates/render/src/lighting/mod.rs b/crates/render/src/lighting/mod.rs
index 8ff4403a29..6cc97027ca 100644
--- a/crates/render/src/lighting/mod.rs
+++ b/crates/render/src/lighting/mod.rs
@@ -1,5 +1,6 @@
//! Device-independent, bounded linear HDR input preparation.
+pub mod environment;
mod hdr;
mod task;
pub use hdr::{HdrInfo, HdrSource, MAX_HDR_BYTES, MAX_HDR_HEIGHT, MAX_HDR_PIXELS, MAX_HDR_WIDTH};
diff --git a/crates/render/src/mapping.rs b/crates/render/src/mapping.rs
new file mode 100644
index 0000000000..4e34f4aaed
--- /dev/null
+++ b/crates/render/src/mapping.rs
@@ -0,0 +1,141 @@
+//! Definition-local visual coordinates, independent of geometry and engineering axes.
+//! This numerical foundation installs no texture sampler, shader or persistent record.
+
+use solidcraft_geom::{Aabb3, Vec3};
+
+/// Admission bounds, not a GPU precision or engineering applicability guarantee.
+pub const MAX_LOCAL_MM: f64 = 1e9;
+pub const MIN_REPEAT_MM: f64 = 1e-3;
+pub const MAX_REPEAT_MM: f64 = 1e6;
+pub const MAX_REPEAT_COORDINATE: f64 = 1e6;
+/// Absolute tolerance for unit-length squared, orthogonality and handedness checks.
+pub const FRAME_TOLERANCE: f64 = 1e-10;
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum MappingError {
+ Position,
+ Frame,
+ RepeatSize,
+ Coordinates,
+ Bounds,
+}
+
+impl std::fmt::Display for MappingError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(match self {
+ Self::Position => "visual mapping positions must be finite and within +/-1e9 mm",
+ Self::Frame => "visual mapping axes must form a right-handed orthonormal frame",
+ Self::RepeatSize => "visual repeat sizes must be finite and within [0.001, 1e6] mm",
+ Self::Coordinates => "visual repeat coordinates exceed the +/-1e6 admission limit",
+ Self::Bounds => "grain suggestion needs finite ordered local bounds with a positive extent",
+ })
+ }
+}
+impl std::error::Error for MappingError {}
+
+/// A one-time visual suggestion; not a material-local mechanical L/R/T assignment.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum GrainAxis {
+ X,
+ Y,
+ Z,
+}
+
+impl GrainAxis {
+ /// First axis is the visual grain direction. The other two complete a right-handed frame.
+ pub fn axes(self) -> [Vec3; 3] {
+ match self {
+ Self::X => [Vec3::X, Vec3::Y, Vec3::Z],
+ Self::Y => [Vec3::Y, Vec3::Z, Vec3::X],
+ Self::Z => [Vec3::Z, Vec3::X, Vec3::Y],
+ }
+ }
+}
+
+/// Suggest from definition-local bounds only, with exact ties resolved X, then Y, then Z.
+/// The caller stores an accepted frame once; this function never observes a later rebuild.
+pub fn suggest_grain_axis(local_bounds: Aabb3) -> Result<GrainAxis, MappingError> {
+ if !bounded_position(local_bounds.min) || !bounded_position(local_bounds.max) || local_bounds.is_empty() {
+ return Err(MappingError::Bounds);
+ }
+ let extent = local_bounds.max - local_bounds.min;
+ if extent.x.max(extent.y).max(extent.z) <= 0.0 {
+ return Err(MappingError::Bounds);
+ }
+ if extent.x >= extent.y && extent.x >= extent.z {
+ Ok(GrainAxis::X)
+ } else if extent.y >= extent.z {
+ Ok(GrainAxis::Y)
+ } else {
+ Ok(GrainAxis::Z)
+ }
+}
+
+/// Immutable admitted visual frame. Fields cannot be changed without readmission.
+/// No serde implementation: eventual document/catalog readers must use `new`.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct VisualMapping {
+ origin_mm: Vec3,
+ axes: [Vec3; 3],
+ repeat_mm: Vec3,
+}
+
+impl VisualMapping {
+ /// Axes are unit directions in definition-local space, in grain/across/depth order.
+ /// Repeat sizes are distances along those directions, not body-bound fractions.
+ /// Small floating-point frame error is admitted within `FRAME_TOLERANCE`; no skew,
+ /// reflection, rescaling, orthogonalization or replacement frame is manufactured.
+ pub fn new(origin_mm: Vec3, axes: [Vec3; 3], repeat_mm: Vec3) -> Result<Self, MappingError> {
+ if !bounded_position(origin_mm) {
+ return Err(MappingError::Position);
+ }
+ let [x, y, z] = axes;
+ if !axes.into_iter().all(|v| v.is_finite() && (v.len2() - 1.0).abs() <= FRAME_TOLERANCE)
+ || x.dot(y).abs() > FRAME_TOLERANCE
+ || x.dot(z).abs() > FRAME_TOLERANCE
+ || y.dot(z).abs() > FRAME_TOLERANCE
+ || (x.cross(y).dot(z) - 1.0).abs() > FRAME_TOLERANCE
+ {
+ return Err(MappingError::Frame);
+ }
+ if ![repeat_mm.x, repeat_mm.y, repeat_mm.z].into_iter().all(|v| v.is_finite() && (MIN_REPEAT_MM..=MAX_REPEAT_MM).contains(&v)) {
+ return Err(MappingError::RepeatSize);
+ }
+ Ok(Self { origin_mm, axes, repeat_mm })
+ }
+
+ pub fn origin_mm(self) -> Vec3 {
+ self.origin_mm
+ }
+ pub fn axes(self) -> [Vec3; 3] {
+ self.axes
+ }
+ pub fn repeat_mm(self) -> Vec3 {
+ self.repeat_mm
+ }
+
+ /// Unwrapped signed repeat coordinates, calculated in f64. No clamping or UV seam.
+ /// The host must first invert the selected instance placement into definition-local
+ /// space. World-space bounding boxes and camera/mesh positions are not inputs here.
+ /// Samplers choose wrapping/filtering; GPU consumers need their own precision budget.
+ pub fn coordinates(self, local_point_mm: Vec3) -> Result<Vec3, MappingError> {
+ if !bounded_position(local_point_mm) {
+ return Err(MappingError::Position);
+ }
+ let delta = local_point_mm - self.origin_mm;
+ let [x, y, z] = self.axes;
+ let result = Vec3::new(delta.dot(x) / self.repeat_mm.x, delta.dot(y) / self.repeat_mm.y, delta.dot(z) / self.repeat_mm.z);
+ if !result.is_finite() || [result.x, result.y, result.z].into_iter().any(|v| v.abs() > MAX_REPEAT_COORDINATE) {
+ return Err(MappingError::Coordinates);
+ }
+ Ok(result)
+ }
+}
+
+fn bounded_position(value: Vec3) -> bool {
+ value.is_finite() && [value.x, value.y, value.z].into_iter().all(|v| v.abs() <= MAX_LOCAL_MM)
+}
+
+#[cfg(test)]
+#[path = "mapping_tests.rs"]
+mod tests;
diff --git a/crates/render/src/mapping_tests.rs b/crates/render/src/mapping_tests.rs
new file mode 100644
index 0000000000..5dcac3f662
--- /dev/null
+++ b/crates/render/src/mapping_tests.rs
@@ -0,0 +1,112 @@
+use super::*;
+
+fn close(actual: Vec3, expected: Vec3) {
+ assert!((actual - expected).len() < 1e-10, "{actual:?} != {expected:?}");
+}
+
+#[test]
+fn physical_repeats_translation_negative_coordinates_and_manual_rotation() {
+ // +90 degrees around local Z: grain +Y, across -X, depth +Z.
+ let origin = Vec3::new(10.0, -20.0, 30.0);
+ let mapping = VisualMapping::new(origin, [Vec3::Y, -Vec3::X, Vec3::Z], Vec3::new(100.0, 20.0, 5.0)).unwrap();
+ close(mapping.coordinates(origin).unwrap(), Vec3::ZERO);
+ close(mapping.coordinates(origin + Vec3::new(-10.0, 200.0, -15.0)).unwrap(), Vec3::new(2.0, 0.5, -3.0));
+ // One repeat is a physical distance, independent of a body's dimensions.
+ close(mapping.coordinates(origin + Vec3::Y * 100.0).unwrap(), Vec3::X);
+ assert_eq!(mapping.origin_mm(), origin);
+ assert_eq!(mapping.axes(), [Vec3::Y, -Vec3::X, Vec3::Z]);
+ assert_eq!(mapping.repeat_mm(), Vec3::new(100.0, 20.0, 5.0));
+}
+
+#[test]
+fn oblique_frame_has_analytic_coordinates_without_automatic_orthogonalization() {
+ let a = std::f64::consts::FRAC_1_SQRT_2;
+ let axes = [Vec3::new(a, a, 0.0), Vec3::new(-a, a, 0.0), Vec3::Z];
+ let mapping = VisualMapping::new(Vec3::ZERO, axes, Vec3::new(2.0, 3.0, 4.0)).unwrap();
+ close(mapping.coordinates(Vec3::new(2.0 * a, 2.0 * a, 0.0)).unwrap(), Vec3::X);
+ close(mapping.coordinates(Vec3::new(-3.0 * a, 3.0 * a, 4.0)).unwrap(), Vec3::new(0.0, 1.0, 1.0));
+ assert_eq!(mapping.axes(), axes);
+}
+
+#[test]
+fn longest_local_axis_uses_xyz_ties_and_accepts_planar_bounds() {
+ for (extent, expected) in [
+ (Vec3::new(3.0, 3.0, 3.0), GrainAxis::X),
+ (Vec3::new(2.0, 3.0, 3.0), GrainAxis::Y),
+ (Vec3::new(1.0, 2.0, 3.0), GrainAxis::Z),
+ (Vec3::new(0.0, 3.0, 0.0), GrainAxis::Y),
+ ] {
+ let min = Vec3::new(10.0, -4.0, 2.0);
+ let axis = suggest_grain_axis(Aabb3 { min, max: min + extent }).unwrap();
+ assert_eq!(axis, expected);
+ assert!(VisualMapping::new(Vec3::ZERO, axis.axes(), Vec3::new(1.0, 1.0, 1.0)).is_ok());
+ }
+}
+
+#[test]
+fn accepted_frame_does_not_flip_after_a_different_resize_suggestion() {
+ let first = suggest_grain_axis(Aabb3 { min: Vec3::ZERO, max: Vec3::new(100.0, 20.0, 10.0) }).unwrap();
+ let mapping = VisualMapping::new(Vec3::ZERO, first.axes(), Vec3::new(10.0, 10.0, 10.0)).unwrap();
+ let point = Vec3::new(25.0, 15.0, 5.0);
+ let before = mapping.coordinates(point).unwrap();
+ assert_eq!(suggest_grain_axis(Aabb3 { min: Vec3::ZERO, max: Vec3::new(100.0, 200.0, 10.0) }).unwrap(), GrainAxis::Y);
+ assert_eq!(mapping.coordinates(point).unwrap(), before);
+ close(before, Vec3::new(2.5, 1.5, 0.5));
+}
+
+#[test]
+fn rigid_instances_share_definition_coordinates_after_explicit_inverse_placement() {
+ let mapping = VisualMapping::new(Vec3::new(1.0, 2.0, 3.0), GrainAxis::Z.axes(), Vec3::new(5.0, 10.0, 20.0)).unwrap();
+ let definition_point = Vec3::new(21.0, -8.0, 13.0);
+ let expected = Vec3::new(2.0, 2.0, -0.5);
+ close(mapping.coordinates(definition_point).unwrap(), expected);
+ // Independent analytic instance transform: (x,y,z) -> (-y,x,z) + translation.
+ let translation = Vec3::new(-300.0, 70.0, 12.0);
+ let world = Vec3::new(-definition_point.y, definition_point.x, definition_point.z) + translation;
+ let shifted = world - translation;
+ let inverted = Vec3::new(shifted.y, -shifted.x, shifted.z);
+ close(mapping.coordinates(inverted).unwrap(), expected);
+ // Passing world points directly is deliberately not corrected by the utility.
+ assert_ne!(mapping.coordinates(world).unwrap(), expected);
+}
+
+#[test]
+fn malformed_frames_refuse_instead_of_repairing_or_reflecting() {
+ for axes in [
+ [Vec3::ZERO, Vec3::Y, Vec3::Z],
+ [Vec3::X * 2.0, Vec3::Y, Vec3::Z],
+ [Vec3::X, Vec3::X, Vec3::Z],
+ [Vec3::X, Vec3::Y, -Vec3::Z],
+ [Vec3::X, Vec3::new(0.01, 1.0, 0.0), Vec3::Z],
+ [Vec3::new(f64::NAN, 0.0, 0.0), Vec3::Y, Vec3::Z],
+ [Vec3::new(f64::MAX, 0.0, 0.0), Vec3::Y, Vec3::Z],
+ ] {
+ assert_eq!(VisualMapping::new(Vec3::ZERO, axes, Vec3::new(1.0, 1.0, 1.0)), Err(MappingError::Frame));
+ }
+}
+
+#[test]
+fn hostile_positions_sizes_bounds_and_excessive_coordinates_refuse() {
+ let mapping = VisualMapping::new(Vec3::ZERO, GrainAxis::X.axes(), Vec3::new(1.0, 1.0, 1.0)).unwrap();
+ for value in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, f64::MAX, MAX_LOCAL_MM * 2.0] {
+ let point = Vec3::new(value, 0.0, 0.0);
+ assert_eq!(VisualMapping::new(point, GrainAxis::X.axes(), Vec3::new(1.0, 1.0, 1.0)), Err(MappingError::Position));
+ assert_eq!(mapping.coordinates(point), Err(MappingError::Position));
+ assert_eq!(suggest_grain_axis(Aabb3 { min: Vec3::ZERO, max: point }), Err(MappingError::Bounds));
+ }
+ for value in [0.0, -1.0, f64::NAN, f64::INFINITY, f64::MIN_POSITIVE, MIN_REPEAT_MM * 0.5, MAX_REPEAT_MM * 2.0] {
+ assert_eq!(VisualMapping::new(Vec3::ZERO, GrainAxis::X.axes(), Vec3::new(1.0, value, 1.0)), Err(MappingError::RepeatSize));
+ }
+ for bounds in [Aabb3::EMPTY, Aabb3 { min: Vec3::X, max: Vec3::ZERO }, Aabb3 { min: Vec3::ZERO, max: Vec3::ZERO }] {
+ assert_eq!(suggest_grain_axis(bounds), Err(MappingError::Bounds));
+ }
+ assert_eq!(mapping.coordinates(Vec3::new(MAX_REPEAT_COORDINATE + 1.0, 0.0, 0.0)), Err(MappingError::Coordinates));
+}
+
+#[test]
+fn admitted_boundaries_remain_finite() {
+ let mapping = VisualMapping::new(Vec3::new(MAX_LOCAL_MM, 0.0, 0.0), GrainAxis::X.axes(), Vec3::new(MAX_REPEAT_MM, MIN_REPEAT_MM, 1.0)).unwrap();
+ close(mapping.coordinates(Vec3::new(-MAX_LOCAL_MM, 0.0, 0.0)).unwrap(), Vec3::new(-2000.0, 0.0, 0.0));
+ let tiny = VisualMapping::new(Vec3::ZERO, GrainAxis::X.axes(), Vec3::new(MIN_REPEAT_MM, 1.0, 1.0)).unwrap();
+ close(tiny.coordinates(Vec3::new(1000.0, 0.0, 0.0)).unwrap(), Vec3::new(MAX_REPEAT_COORDINATE, 0.0, 0.0));
+}
diff --git a/crates/render/src/product.rs b/crates/render/src/product.rs
index a72ca68e9b..1c1e353b4d 100644
--- a/crates/render/src/product.rs
+++ b/crates/render/src/product.rs
@@ -11,6 +11,7 @@ pub struct FaceAppearance {
pub color: [u8; 3],
pub opacity: f64,
pub surface: Option<crate::surface::OpaqueSurface>,
+ pub transmission: Option<crate::transmission::Transmission>,
}
#[derive(Clone, Debug)]
@@ -22,6 +23,7 @@ pub struct ProductMesh {
pub color: [u8; 3],
pub opacity: f64,
pub surface: Option<crate::surface::OpaqueSurface>,
+ pub transmission: Option<crate::transmission::Transmission>,
pub faces: Vec<FaceAppearance>,
}
@@ -32,6 +34,9 @@ pub struct ProductScene {
}
impl ProductScene {
+ pub fn has_transmission(&self) -> bool {
+ self.meshes.iter().any(|m| m.transmission.is_some() || m.faces.iter().any(|f| f.transmission.is_some()))
+ }
pub fn required_features(&self) -> Vec<crate::RenderFeature> {
if self.meshes.iter().any(|m| m.surface.is_some() || m.faces.iter().any(|f| f.surface.is_some())) {
vec![crate::RenderFeature::Pbr]
diff --git a/crates/render/src/surface.rs b/crates/render/src/surface.rs
index a6fba335f9..0e970dc3a8 100644
--- a/crates/render/src/surface.rs
+++ b/crates/render/src/surface.rs
@@ -16,12 +16,14 @@ pub struct OpaqueSurface {
metallic: f64,
roughness: f64,
dielectric_ior: f64,
+ clear_coat: Option<crate::clear_coat::ClearCoat>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SurfaceError {
BaseColor,
Metallic,
+ CoatWeight,
Roughness,
DielectricIor,
Direction,
@@ -32,6 +34,7 @@ impl std::fmt::Display for SurfaceError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::BaseColor => "linear base color channels must be finite and in [0, 1]",
+ Self::CoatWeight => "clear-coat weight must be finite and in [0, 1]",
Self::Metallic => "metallic fraction must be finite and in [0, 1]",
Self::Roughness => "perceptual roughness must be finite and in [0.045, 1]",
Self::DielectricIor => "dielectric IOR must be finite and in [1, 3]",
@@ -58,7 +61,16 @@ impl OpaqueSurface {
if !dielectric_ior.is_finite() || !(1.0..=3.0).contains(&dielectric_ior) {
return Err(SurfaceError::DielectricIor);
}
- Ok(Self { base_color, metallic, roughness, dielectric_ior })
+ Ok(Self { base_color, metallic, roughness, dielectric_ior, clear_coat: None })
+ }
+
+ /// Runtime optical layer; never serialized into a document appearance.
+ pub fn with_clear_coat(mut self, coat: crate::clear_coat::ClearCoat) -> Self {
+ self.clear_coat = if coat.weight() == 0.0 { None } else { Some(coat) };
+ self
+ }
+ pub fn clear_coat(self) -> Option<crate::clear_coat::ClearCoat> {
+ self.clear_coat
}
pub fn base_color(self) -> Vec3 {
@@ -79,6 +91,14 @@ impl OpaqueSurface {
Vec3::new(ratio * ratio, ratio * ratio, ratio * ratio).lerp(self.base_color, self.metallic)
}
+ /// Schlick approximation with the exact index-matched dielectric limit.
+ /// A conductor retains its own grazing response, including in a metal mix.
+ pub(crate) fn specular_fresnel(self, cosine: f64) -> Vec3 {
+ let f0 = self.normal_reflectance();
+ let grazing = if self.dielectric_ior == 1.0 { self.metallic } else { 1.0 };
+ f0 + (Vec3::new(grazing, grazing, grazing) - f0) * (1.0 - cosine.clamp(0.0, 1.0)).powi(5)
+ }
+
/// BRDF in inverse steradians. Directions point away from the surface.
/// No incident radiance, cosine weight, exposure or display transfer is included.
/// Back-facing/tangent directions return zero; malformed directions are errors.
@@ -102,19 +122,19 @@ impl OpaqueSurface {
// G1 / cos(theta) has a finite grazing limit: no epsilon cosine clamp.
let visibility = |cos: f64| 2.0 / (cos + (a2 + (1.0 - a2) * cos * cos).sqrt());
let specular = distribution * 0.25 * visibility(nv) * visibility(nl);
- let f0 = self.normal_reflectance();
- let fresnel = |cos: f64| f0 + (Vec3::new(1.0, 1.0, 1.0) - f0) * (1.0 - cos).powi(5);
+ let fresnel = |cos: f64| self.specular_fresnel(cos);
let f = fresnel(vh);
// Symmetric entry/exit attenuation avoids adding a full Lambert substrate
// to grazing reflection. Internal reflection / multi-scattering is omitted.
let fv = fresnel(nv);
let fl = fresnel(nl);
let diffuse = self.base_color * ((1.0 - self.metallic) / PI);
- Ok(Vec3::new(
+ let base = Vec3::new(
f.x * specular + (1.0 - fv.x) * (1.0 - fl.x) * diffuse.x,
f.y * specular + (1.0 - fv.y) * (1.0 - fl.y) * diffuse.y,
f.z * specular + (1.0 - fv.z) * (1.0 - fl.z) * diffuse.z,
- ))
+ );
+ Ok(self.clear_coat.map_or(base, |coat| coat.layer(base, nv, nl, nh, vh)))
}
}
@@ -228,6 +248,31 @@ mod tests {
}
}
+ #[test]
+ fn index_matched_dielectric_is_exact_lambert_at_oblique_and_grazing_angles() {
+ let color = Vec3::new(0.75, 0.35, 0.02);
+ for roughness in [MIN_ROUGHNESS, 0.25, 1.0] {
+ let s = OpaqueSurface::new(color, 0.0, roughness, 1.0).unwrap();
+ for cosine in [0.0, 1e-12, 0.02, 0.5, 1.0] {
+ assert_eq!(s.specular_fresnel(cosine), Vec3::ZERO);
+ }
+ for nv in [1e-8_f64, 0.02, 0.5, 1.0] {
+ for nl in [1e-8_f64, 0.2, 0.7, 1.0] {
+ let v = Vec3::new((1.0 - nv * nv).sqrt(), 0.0, nv);
+ let l = Vec3::new(0.0, (1.0 - nl * nl).sqrt(), nl);
+ assert!((s.brdf(Vec3::Z, v, l).unwrap() - color / PI).len() < 1e-14);
+ }
+ }
+ }
+ for metallic in [0.0, 0.25, 0.5, 1.0] {
+ let s = OpaqueSurface::new(color, metallic, 0.5, 1.0).unwrap();
+ for c in [0.0_f64, 0.2, 0.9, 1.0] {
+ let conductor = color + (Vec3::new(1., 1., 1.) - color) * (1.0 - c).powi(5);
+ assert!((s.specular_fresnel(c) - conductor * metallic).len() < 1e-14);
+ }
+ }
+ }
+
#[test]
fn srgb_conversion_includes_the_linear_toe() {
assert_eq!(srgb8_to_linear(0), 0.0);
diff --git a/crates/render/src/transmission.rs b/crates/render/src/transmission.rs
new file mode 100644
index 0000000000..f85cd7d939
--- /dev/null
+++ b/crates/render/src/transmission.rs
@@ -0,0 +1,194 @@
+//! Bounded optical data and original f64 dielectric transport oracles. Units are mm.
+use solidcraft_geom::Vec3;
+
+use crate::surface::{SurfaceError, unit_direction};
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Transmission {
+ absorption_per_mm: Vec3,
+ thin_wall_thickness_mm: Option<f64>,
+ shadow_transmission: bool,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum TransmissionError {
+ Absorption,
+ Distance,
+ Thickness,
+ Angle,
+ Ior,
+ Direction,
+}
+impl std::fmt::Display for TransmissionError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(match self {
+ Self::Absorption => "absorption_per_mm must be finite RGB coefficients in [0, 100] per mm",
+ Self::Distance => "geometric absorption distance must be finite and nonnegative",
+ Self::Thickness => "thin-sheet thickness must be finite and in [0, 10000] mm",
+ Self::Angle => "incident cosine must be finite and in [0, 1]",
+ Self::Ior => "medium IOR must be finite and in [1, 3]",
+ Self::Direction => "incident direction must face the finite nonzero interface normal",
+ })
+ }
+}
+impl std::error::Error for TransmissionError {}
+
+impl Transmission {
+ pub fn new(absorption_per_mm: Vec3, thin_wall_thickness_mm: Option<f64>) -> Result<Self, TransmissionError> {
+ if !absorption_per_mm.is_finite()
+ || ![absorption_per_mm.x, absorption_per_mm.y, absorption_per_mm.z].into_iter().all(|v| (0.0..=100.0).contains(&v))
+ {
+ return Err(TransmissionError::Absorption);
+ }
+ if thin_wall_thickness_mm.is_some_and(|v| !v.is_finite() || !(0.0..=10000.0).contains(&v)) {
+ return Err(TransmissionError::Thickness);
+ }
+ Ok(Self { absorption_per_mm, thin_wall_thickness_mm, shadow_transmission: thin_wall_thickness_mm.is_some() })
+ }
+ /// Thin sheets enable straight shadow transmission by default; solids opt in.
+ pub fn with_shadow_transmission(mut self, enabled: bool) -> Self {
+ self.shadow_transmission = enabled;
+ self
+ }
+ pub fn shadow_transmission(self) -> bool {
+ self.shadow_transmission
+ }
+ pub fn thin_wall_thickness_mm(self) -> Option<f64> {
+ self.thin_wall_thickness_mm
+ }
+ pub fn extinction(self) -> Vec3 {
+ self.absorption_per_mm
+ }
+ pub fn attenuation(self, distance_mm: f64) -> Result<Vec3, TransmissionError> {
+ if !distance_mm.is_finite() || distance_mm < 0.0 {
+ return Err(TransmissionError::Distance);
+ }
+ let s = self.extinction();
+ Ok(Vec3::new((-s.x * distance_mm).exp(), (-s.y * distance_mm).exp(), (-s.z * distance_mm).exp()))
+ }
+}
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Fresnel {
+ pub s: f64,
+ pub p: f64,
+ /// None at total internal reflection.
+ pub transmitted_cosine: Option<f64>,
+}
+impl Fresnel {
+ pub fn reflectance(self) -> f64 {
+ (self.s + self.p) * 0.5
+ }
+}
+
+/// Exact unpolarized power reflectance at a lossless dielectric interface.
+pub fn fresnel(cosine: f64, incident_ior: f64, transmitted_ior: f64) -> Result<Fresnel, TransmissionError> {
+ if !cosine.is_finite() || !(0.0..=1.0).contains(&cosine) {
+ return Err(TransmissionError::Angle);
+ }
+ if [incident_ior, transmitted_ior].into_iter().any(|v| !v.is_finite() || !(1.0..=3.0).contains(&v)) {
+ return Err(TransmissionError::Ior);
+ }
+ if incident_ior == transmitted_ior {
+ return Ok(Fresnel { s: 0.0, p: 0.0, transmitted_cosine: Some(cosine) });
+ }
+ let eta = incident_ior / transmitted_ior;
+ let sin2 = eta * eta * (1.0 - cosine * cosine).max(0.0);
+ if sin2 >= 1.0 {
+ return Ok(Fresnel { s: 1.0, p: 1.0, transmitted_cosine: None });
+ }
+ let ct = (1.0 - sin2).sqrt();
+ let rs = (incident_ior * cosine - transmitted_ior * ct) / (incident_ior * cosine + transmitted_ior * ct);
+ let rp = (transmitted_ior * cosine - incident_ior * ct) / (transmitted_ior * cosine + incident_ior * ct);
+ Ok(Fresnel { s: rs * rs, p: rp * rp, transmitted_cosine: Some(ct) })
+}
+
+/// Incident direction points toward the surface; normal points into the incident medium.
+pub fn refract(incident: Vec3, normal: Vec3, incident_ior: f64, transmitted_ior: f64) -> Result<Option<Vec3>, TransmissionError> {
+ let direction_error = |_: SurfaceError| TransmissionError::Direction;
+ let d = unit_direction(incident).map_err(direction_error)?;
+ let n = unit_direction(normal).map_err(direction_error)?;
+ let cosine = -d.dot(n);
+ if cosine < 0.0 {
+ return Err(TransmissionError::Direction);
+ }
+ let f = fresnel(cosine.min(1.0), incident_ior, transmitted_ior)?;
+ Ok(f.transmitted_cosine.map(|ct| {
+ let eta = incident_ior / transmitted_ior;
+ d * eta + n * (eta * cosine - ct)
+ }))
+}
+
+/// Incoherent parallel slab, including all repeated internal reflections. The two
+/// external media have the same IOR. Returns linear RGB (reflectance, transmittance).
+pub fn slab(
+ transmission: Transmission,
+ thickness_mm: f64,
+ cosine: f64,
+ outside_ior: f64,
+ inside_ior: f64,
+) -> Result<(Vec3, Vec3), TransmissionError> {
+ if !thickness_mm.is_finite() || !(0.0..=10000.0).contains(&thickness_mm) {
+ return Err(TransmissionError::Thickness);
+ }
+ let f = fresnel(cosine, outside_ior, inside_ior)?;
+ let Some(ct) = f.transmitted_cosine.filter(|v| *v > 0.0) else {
+ return Ok((Vec3::new(1.0, 1.0, 1.0), Vec3::ZERO));
+ };
+ let a = transmission.attenuation(thickness_mm / ct)?;
+ let channel = |r: f64, a: f64| {
+ let denominator = 1.0 - r * r * a * a;
+ if denominator <= 0.0 {
+ return (1.0, 0.0);
+ }
+ (r + (1.0 - r).powi(2) * r * a * a / denominator, (1.0 - r).powi(2) * a / denominator)
+ };
+ // A parallel slab preserves polarization. Sum each geometric series before
+ // averaging s/p, rather than repeatedly applying the unpolarized mean.
+ let average = |a: f64| {
+ let (rs, ts) = channel(f.s, a);
+ let (rp, tp) = channel(f.p, a);
+ ((rs + rp) * 0.5, (ts + tp) * 0.5)
+ };
+ let (rx, tx) = average(a.x);
+ let (ry, ty) = average(a.y);
+ let (rz, tz) = average(a.z);
+ Ok((Vec3::new(rx, ry, rz), Vec3::new(tx, ty, tz)))
+}
+
+/// Explicit straight-through solid shadow approximation. Both interface losses
+/// use reciprocal external-angle Fresnel; `distance_mm` is the actual geometric
+/// entry/exit interval. This omits refraction and repeated internal reflections.
+pub fn solid_shadow(transmission: Transmission, distance_mm: f64, entry_cosine: f64, exit_cosine: f64, ior: f64) -> Result<Vec3, TransmissionError> {
+ let entry = fresnel(entry_cosine, 1.0, ior)?.reflectance();
+ let exit = fresnel(exit_cosine, 1.0, ior)?.reflectance();
+ Ok(transmission.attenuation(distance_mm)? * ((1.0 - entry) * (1.0 - exit)))
+}
+
+#[cfg(test)]
+mod shadow_tests {
+ use super::*;
+ #[test]
+ fn defaults_and_reciprocal_solid_shadow_match_analytic_beer() {
+ let sigma = Vec3::new(-0.5_f64.ln(), -0.8_f64.ln(), 0.0);
+ let solid = Transmission::new(sigma, None).unwrap();
+ let sheet = Transmission::new(sigma, Some(1.0)).unwrap();
+ assert!(!solid.shadow_transmission());
+ assert!(sheet.shadow_transmission());
+ assert!(solid.with_shadow_transmission(true).shadow_transmission());
+ assert!(!sheet.with_shadow_transmission(false).shadow_transmission());
+ assert!((solid_shadow(solid, 1.0, 1.0, 1.0, 1.5).unwrap() - Vec3::new(0.5, 0.8, 1.0) * 0.96 * 0.96).len() < 1e-14);
+ assert_eq!(solid_shadow(solid, 1.0, 0.2, 0.8, 1.5).unwrap(), solid_shadow(solid, 1.0, 0.8, 0.2, 1.5).unwrap());
+ for ior in [1.0, 1.5, 3.0] {
+ for cosine in [0.0, 0.02, 0.5, 1.0] {
+ let shadow = solid_shadow(solid, 1.0, cosine, cosine, ior).unwrap();
+ assert!(shadow.is_finite() && shadow.x >= 0.0 && shadow.z <= 1.0);
+ }
+ }
+ assert!(solid_shadow(solid, f64::NAN, 1.0, 1.0, 1.5).is_err());
+ }
+}
+
+#[cfg(test)]
+#[path = "dielectric_oracle_tests.rs"]
+mod tests;
diff --git a/crates/ui-egui/src/dialogs_appearance.rs b/crates/ui-egui/src/dialogs_appearance.rs
index 5560a9d8d5..176fd49d18 100644
--- a/crates/ui-egui/src/dialogs_appearance.rs
+++ b/crates/ui-egui/src/dialogs_appearance.rs
@@ -60,6 +60,7 @@ pub fn library(app: &mut SolveApp) -> Vec<Look> {
let list = v.get("appearances").or(v.get("library")).unwrap_or(&v).as_array()?.clone();
let looks: Vec<Look> = list
.iter()
+ .filter(|entry| entry.get("available").and_then(Value::as_bool) != Some(false))
.filter_map(|x| {
Some(Look {
name: x.get("name")?.as_str()?.to_string(),
@@ -160,7 +161,7 @@ pub fn start(app: &SolveApp, id: &str) -> Option<(Kind, Vec<SelInput>)> {
}
/// The command giving `targets` (bodies or faces) a look.
-fn apply_params(targets: &[Sel], color: [u8; 3], opacity: f64, look: Option<&str>) -> Option<Value> {
+fn apply_params(targets: &[Sel], color: [u8; 3], opacity: f64, look: Option<&str>, pbr: Option<PbrParameters>) -> Option<Value> {
let bodies: Vec<String> = targets.iter().filter_map(|x| if let Sel::Body { name } = x { Some(name.clone()) } else { None }).collect();
let faces: Vec<Value> = targets
.iter()
@@ -184,8 +185,9 @@ fn apply_params(targets: &[Sel], color: [u8; 3], opacity: f64, look: Option<&str
}
}
p["opacity"] = json!(opacity);
+ p["pbr"] = json!(pbr);
if let Some(n) = look {
- p["appearance"] = json!(n);
+ p["name"] = json!(n);
}
Some(p)
}
@@ -205,15 +207,12 @@ pub fn commands(k: &Ap, inputs: &[SelInput]) -> Vec<(String, Value)> {
}
pub(super) fn selected_params(k: &Ap, items: &[Sel]) -> Option<Value> {
- let mut p = if let Some(component) = &k.component {
- Some(json!({"components": [component], "color": hex(k.color), "opacity": k.opacity, "appearance": k.look}))
+ // Every path applies its complete owned look, never re-resolves its label.
+ if let Some(component) = &k.component {
+ Some(json!({"components": [component], "color": hex(k.color), "opacity": k.opacity, "name": k.look, "pbr": k.pbr}))
} else {
- apply_params(items, k.color, k.opacity, k.look.as_deref())
- }?;
- if let Some(pbr) = k.pbr {
- p["pbr"] = json!(pbr);
+ apply_params(items, k.color, k.opacity, k.look.as_deref(), k.pbr)
}
- Some(p)
}
/// Removing an override restores the inherited component or material appearance.
@@ -221,6 +220,7 @@ fn clear_params(k: &Ap, items: &[Sel]) -> Option<Value> {
let mut p = selected_params(k, items)?;
if let Some(obj) = p.as_object_mut() {
obj.remove("appearance");
+ obj.remove("name");
obj.remove("color");
obj.remove("opacity");
obj.remove("pbr");
@@ -444,10 +444,7 @@ pub fn rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut Ap, inputs: &mut [Sel
k.pbr = look.pbr;
k.look = Some(look.name.clone());
k.remove_override = false;
- if let Some(mut p) = apply_params(&targets, look.color, look.opacity, k.look.as_deref()) {
- if let Some(pbr) = look.pbr {
- p["pbr"] = json!(pbr);
- }
+ if let Some(p) = apply_params(&targets, look.color, look.opacity, k.look.as_deref(), look.pbr) {
k.note = Some(match app.run("appearance.assign", p.clone()) {
Ok(_) => {
k.applied = Some(p);
@@ -564,7 +561,7 @@ mod tests {
a.viewport.hover = None;
a.viewport.hover_bodies = vec!["Body2".into()];
assert_eq!(drop_target(&a, false), vec![Sel::Body { name: "Body2".into() }]);
- let face = apply_params(&[Sel::Face { body: "Body1".into(), index: 0, point: p }], [1, 2, 3], 0.5, None).unwrap();
+ let face = apply_params(&[Sel::Face { body: "Body1".into(), index: 0, point: p }], [1, 2, 3], 0.5, None, None).unwrap();
assert_eq!(face["faces"][0]["body"], "Body1");
assert_eq!(face["opacity"], 0.5);
assert!(!library(&mut a).is_empty());
@@ -609,7 +606,7 @@ mod tests {
let Kind::Appearance(k) = &a.dialog.as_ref().unwrap().kind else { panic!("appearance dialog") };
assert_eq!(k.opacity, 0.25);
assert_eq!(k.look.as_deref(), Some("Tinted glass"));
- let p = apply_params(&[Sel::Body { name: "Body2".into() }], look.color, look.opacity, Some(&look.name)).unwrap();
+ let p = apply_params(&[Sel::Body { name: "Body2".into() }], look.color, look.opacity, Some(&look.name), look.pbr).unwrap();
a.run("appearance.assign", p).unwrap();
assert_eq!(a.session.doc.appearances.bodies.get("Body1"), a.session.doc.appearances.bodies.get("Body2"));
}
@@ -746,4 +743,67 @@ mod tests {
assert!(crate::scenario::handle_at(handle).is_some(), "missing {handle}");
}
}
+
+ #[test]
+ fn selectable_library_excludes_unavailable_starter_glass_recipes() {
+ let mut h = crate::scenario::Harness::new();
+ let listed = h.app.session.execute("appearance.library", &json!({})).unwrap();
+ let rows = listed["appearances"].as_array().unwrap();
+ let available = rows.iter().filter(|row| row.get("available").and_then(Value::as_bool) != Some(false)).count();
+ let selectable = library(&mut h.app);
+ assert_eq!(selectable.len(), available);
+ for preset in &solidcraft_engine::doc::appearance_pack::STARTER_PACK {
+ assert_eq!(selectable.iter().any(|look| look.name == preset.name), preset.is_opaque());
+ }
+ }
+
+ #[test]
+ fn applying_and_clearing_owned_recipe_labels_never_resolves_the_recipe() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.run("solid.box", json!({"body_name":"Owned","length":10,"width":10,"height":10})).unwrap();
+ for name in ["starter.glass.clear-soda-lime", "Glass Recipe - Low Iron Clear", "Metal - Warm Reflective Gold"] {
+ h.app.run("appearance.assign", json!({"bodies":["Owned"],"name":name,"color":[31,61,91],"pbr":null})).unwrap();
+ let original = h.app.session.doc.appearances.bodies["Owned"].clone();
+ h.app.session.selection = vec![Sel::Body { name: "Owned".into() }];
+ h.app.start("appearance.assign");
+ let dialog = h.app.dialog.as_ref().unwrap();
+ let Kind::Appearance(state) = &dialog.kind else { panic!("appearance editor expected") };
+ let params = selected_params(state, &dialog.inputs[0].items).unwrap();
+ let clear = clear_params(state, &dialog.inputs[0].items).unwrap();
+ assert_eq!(params["name"], name);
+ assert!(params.get("appearance").is_none());
+ assert_eq!(params["pbr"], Value::Null);
+ h.app.run("appearance.assign", params).unwrap();
+ assert_eq!(h.app.session.doc.appearances.bodies["Owned"], original);
+ assert!(clear.get("name").is_none() && clear.get("appearance").is_none());
+ h.app.run("appearance.assign", clear).unwrap();
+ assert!(!h.app.session.doc.appearances.bodies.contains_key("Owned"));
+ }
+ }
+
+ #[test]
+ fn dropped_scalar_and_pbr_requests_match_ok_without_an_extra_undo() {
+ for response in [None, Some(PbrParameters::new(0.7, 0.25, 1.5).unwrap())] {
+ let mut a = app();
+ a.session.selection = vec![Sel::Body { name: "Body1".into() }];
+ a.start("appearance.assign");
+ let mut dialog = a.dialog.clone().unwrap();
+ let Kind::Appearance(state) = &mut dialog.kind else { panic!("appearance editor") };
+ state.look = Some("Owned swatch".into());
+ state.color = [31, 61, 91];
+ state.opacity = 1.0;
+ state.pbr = response;
+ let params = apply_params(&dialog.inputs[0].items, state.color, state.opacity, state.look.as_deref(), state.pbr).unwrap();
+ assert!(params.get("pbr").is_some(), "the complete owned response is explicit");
+ assert_eq!(params["pbr"], json!(response));
+ let original = a.session.doc.clone();
+ let undo = a.session.undo.len();
+ a.run("appearance.assign", params.clone()).unwrap();
+ state.applied = Some(params);
+ assert_eq!(a.session.undo.len(), undo + 1);
+ assert!(commands(state, &dialog.inputs).is_empty(), "OK after a drop is not another edit");
+ a.run("edit.undo", json!({})).unwrap();
+ assert_eq!(a.session.doc, original);
+ }
+ }
}
diff --git a/crates/ui-egui/src/dialogs_library.rs b/crates/ui-egui/src/dialogs_library.rs
index 6633560ddb..83666407c4 100644
--- a/crates/ui-egui/src/dialogs_library.rs
+++ b/crates/ui-egui/src/dialogs_library.rs
@@ -235,8 +235,8 @@ fn import_rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut Ap, inputs: &[SelI
Ok(_) => {
if let Definition::Appearance(look) = entry.definition {
k.color = look.color;
- k.pbr = None;
k.opacity = look.opacity;
+ k.pbr = look.pbr;
k.look = Some(look.name.clone());
k.remove_override = false;
k.applied = selected_params(k, picked);
diff --git a/crates/ui-egui/src/dialogs_library_tests.rs b/crates/ui-egui/src/dialogs_library_tests.rs
index 9fb44dd263..4f53237c2d 100644
--- a/crates/ui-egui/src/dialogs_library_tests.rs
+++ b/crates/ui-egui/src/dialogs_library_tests.rs
@@ -4,21 +4,32 @@ use solidcraft_engine::{Sel, Session};
#[test]
fn catalog_clicked_load_apply_export_and_ok_keep_one_design_undo_step() {
+ clicked_catalog(None, "solidcraft-library/1").unwrap();
+}
+
+#[test]
+fn catalog_clicked_pbr_load_apply_export_and_ok_retains_the_optical_response() {
+ clicked_catalog(Some(solidcraft_engine::doc::pbr_appearance::PbrParameters::new(1., 0.3, 1.5).unwrap()), "solidcraft-library/2").unwrap();
+}
+
+#[test]
+fn catalog_clicked_rich_entry_without_pbr_clears_the_old_optical_response() {
+ clicked_catalog(None, "solidcraft-library/2").unwrap();
+}
+
+fn clicked_catalog(pbr: Option<solidcraft_engine::doc::pbr_appearance::PbrParameters>, format: &str) -> Result<(), Box<dyn std::error::Error>> {
let mut h = Harness::new();
h.call("ui.resize", json!({"width":1600,"height":1400}));
let path = h.dir.join("source-library.json").to_string_lossy().into_owned();
let mut source = Session::default();
- source.execute("solid.box", &json!({"length":10,"width":10,"height":10})).unwrap();
- source.execute("appearance.assign", &json!({"bodies":["Body1"],"appearance":"Warm oak colour","color":[180,120,70],"opacity":0.8})).unwrap();
- source.execute("library.export", &json!({"path":path})).unwrap();
- h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
- h.app
- .run(
- "appearance.assign",
- json!({"bodies":["Body1"],"color":[20,20,20],
- "pbr":{"metallic":1.0,"roughness":0.3,"dielectric_ior":1.5}}),
- )
- .unwrap();
+ source.execute("solid.box", &json!({"length":10,"width":10,"height":10}))?;
+ source.execute(
+ "appearance.assign",
+ &json!({"bodies":["Body1"],"appearance":"Warm oak colour","color":[180,120,70],"opacity":if pbr.is_some(){1.0}else{0.8},"pbr":pbr}),
+ )?;
+ source.execute("library.export", &json!({"path":path,"format":format}))?;
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10}))?;
+ h.app.run("appearance.assign", json!({"bodies":["Body1"],"color":[20,20,20],"pbr":{"metallic":1.0,"roughness":0.6,"dielectric_ior":1.7}}))?;
h.app.session.mark_saved();
h.app.session.selection = vec![Sel::Body { name: "Body1".into() }];
h.app.start("appearance.assign");
@@ -29,7 +40,7 @@ fn catalog_clicked_load_apply_export_and_ok_keep_one_design_undo_step() {
}
h.frames(3);
let undo = h.app.session.undo.len();
- h.step(&json!({"widget":"Load library"})).unwrap();
+ h.step(&json!({"widget":"Load library"}))?;
for handle in [
"library:path",
"library:load",
@@ -49,26 +60,36 @@ fn catalog_clicked_load_apply_export_and_ok_keep_one_design_undo_step() {
{
assert!(h.widget(message).is_some(), "missing {message}");
}
- h.step(&json!({"click":{"handle":"library:search"}})).unwrap();
- h.step(&json!({"text":"no such appearance"})).unwrap();
+ h.step(&json!({"click":{"handle":"library:search"}}))?;
+ h.step(&json!({"text":"no such appearance"}))?;
assert!(h.widget("No matching appearance presets.").is_some());
- h.step(&json!({"key":"A","cmd":true})).unwrap();
- h.step(&json!({"key":"Backspace"})).unwrap();
- h.step(&json!({"click":{"handle":"library:entry:0"}})).unwrap();
- h.step(&json!({"widget":"Apply library appearance"})).unwrap();
+ h.step(&json!({"key":"A","cmd":true}))?;
+ h.step(&json!({"key":"Backspace"}))?;
+ h.step(&json!({"click":{"handle":"library:entry:0"}}))?;
+ h.step(&json!({"widget":"Apply library appearance"}))?;
assert_eq!(h.app.session.doc.appearances.bodies["Body1"].name, "Warm oak colour");
- assert!(h.app.session.doc.appearances.bodies["Body1"].pbr.is_none());
+ assert_eq!(h.app.session.doc.appearances.bodies["Body1"].pbr, pbr);
+ if let Some(dialog) = &h.app.dialog
+ && let Kind::Appearance(state) = &dialog.kind
+ {
+ assert_eq!(state.pbr, pbr);
+ }
+
assert_eq!(h.app.session.undo.len(), undo + 1);
let revision = h.app.session.revision;
- h.step(&json!({"widget":"Export design library..."})).unwrap();
+ h.step(&json!({"widget":"Export design library..."}))?;
let exported = h.dir.join("my-library.solidcraft-library.json");
- let catalog = Catalog::read(&exported.to_string_lossy()).unwrap();
+ let catalog = Catalog::read(&exported.to_string_lossy())?;
assert_eq!(catalog.entries.len(), 1);
assert_eq!(catalog.entries[0].definition.name(), "Warm oak colour");
+ if let Definition::Appearance(look) = &catalog.entries[0].definition {
+ assert_eq!(look.pbr, pbr);
+ }
assert_eq!(h.app.session.revision, revision);
- h.step(&json!({"widget":"OK"})).unwrap();
+ h.step(&json!({"widget":"OK"}))?;
assert!(h.app.dialog.is_none());
assert_eq!(h.app.session.undo.len(), undo + 1);
+ Ok(())
}
fn appearance_fixture() -> Result<(Harness, Arc<()>), String> {
diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs
index cc10d39814..0ac099424b 100644
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@ -117,11 +117,30 @@ impl Locale {
/// Translate source labels from engine/UI tables, preserving unknown labels.
/// Also accepts stable IDs while table helpers migrate away from source text.
pub fn label(self, label: &str) -> &str {
- static LABEL_IDS: OnceLock<BTreeMap<&'static str, &'static str>> = OnceLock::new();
+ // Stable IDs are authoritative. An untranslated legacy ID identical to its
+ // English caption can still use another translated ID for that source label.
+ if ENGLISH.messages().get(label).is_some_and(|text| text != label || self.0.messages().contains_key(label)) {
+ return self.text(label);
+ }
+ static LABEL_IDS: OnceLock<BTreeMap<&'static str, Vec<&'static str>>> = OnceLock::new();
let ids = LABEL_IDS.get_or_init(|| {
- ENGLISH.messages().iter().filter(|(_, text)| !text.contains('{')).map(|(id, text)| (text.as_str(), id.as_str())).collect()
+ let mut ids: BTreeMap<_, Vec<_>> = BTreeMap::new();
+ for (id, text) in ENGLISH.messages().iter().filter(|(_, text)| !text.contains('{')) {
+ ids.entry(text.as_str()).or_default().push(id.as_str());
+ }
+ ids
});
- ids.get(label).map_or_else(|| self.text(label), |id| self.text(id))
+ if let Some(candidates) = ids.get(label) {
+ // Preserve the old last-ID preference among available translations. A new
+ // English-only alias must not hide a translation that already exists here.
+ if let Some(text) = candidates.iter().rev().find_map(|id| self.0.messages().get(*id)) {
+ return text;
+ }
+ if let Some(id) = candidates.last() {
+ return self.text(id);
+ }
+ }
+ self.text(label)
}
pub fn format(self, id: &str, args: &[(&str, &str)]) -> String {
@@ -248,6 +267,22 @@ pub fn tr_name(text: &str) -> String {
mod tests {
use super::*;
+ #[test]
+
+ fn alias_resolution_regression() {
+ static LEGACY: Catalog = Catalog::new("test-legacy", "Test", r#"{"Pitch":"legacy pitch"}"#);
+ static ALIAS: Catalog = Catalog::new("test-alias", "Test", r#"{"coupling.pitch":"mechanical pitch"}"#);
+ assert_eq!(ENGLISH.messages().get("Pitch").map(String::as_str), Some("Pitch"));
+ assert_eq!(ENGLISH.messages().get("coupling.pitch").map(String::as_str), Some("Pitch"));
+ let legacy = Locale(&LEGACY);
+ assert_eq!(legacy.label("Pitch"), "legacy pitch");
+ assert_eq!(legacy.label("coupling.pitch"), "Pitch");
+ let alias = Locale(&ALIAS);
+ assert_eq!(alias.label("Pitch"), "mechanical pitch");
+ assert_eq!(alias.label("coupling.pitch"), "mechanical pitch");
+ assert_eq!(alias.label("original unknown caption"), "original unknown caption");
+ }
+
/// English first, then by id, so adding a locale edits only its own line.
#[test]
fn locales_are_listed_english_first_then_by_id() {
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 6683cba137..a34499c2cd 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -696,6 +696,12 @@ impl SolveApp {
None
}
};
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ let adapter = rs.adapter.clone();
+ let key = render_workspace::adapter_key(&adapter.get_info());
+ self.render_workspace.defer_path_host(key, move || solidcraft_gpu::path::host_on_adapter(&adapter).map_err(|e| e.to_string()));
+ }
render_workspace::sync_backend(self);
self.msaa_supported = rs.msaa_supported.clone();
let info = rs.adapter.get_info();
@@ -722,6 +728,7 @@ impl SolveApp {
"ground_shadow": self.ui.ground_shadow,
"agent_cursor": self.ui.agent_cursor,
"preferences": self.preferences,
+ "gpu_path_setup_seconds": self.render_workspace.setup_seconds,
})
.to_string()
}
@@ -734,6 +741,9 @@ impl SolveApp {
if let Some(d) = flag("dark") {
self.ui.dark = d;
}
+ if let Some(t) = v.get("gpu_path_setup_seconds") {
+ self.render_workspace.setup_seconds = render_workspace::load_setup_seconds(t);
+ }
if let Some(g) = flag("grid") {
self.ui.show_grid = g;
}
diff --git a/crates/ui-egui/src/render_workspace.rs b/crates/ui-egui/src/render_workspace.rs
index e9490dbbe7..82b2343f97 100644
--- a/crates/ui-egui/src/render_workspace.rs
+++ b/crates/ui-egui/src/render_workspace.rs
@@ -7,6 +7,7 @@ use std::sync::{Arc, Mutex};
use egui::{Color32, Sense};
use serde_json::json;
use solidcraft_engine::doc::render_settings::RenderSetup;
+use solidcraft_engine::render::job::ImageHost;
use solidcraft_engine::render::{
Availability, Camera, ExecutorDescriptor, ExecutorId, ProductScene, RenderLimits, RenderMode, RenderOperation, RenderProfile, RenderRequest,
ScratchLayout,
@@ -21,8 +22,17 @@ const MAX_GEOMETRY_BYTES: usize = 128 * 1024 * 1024;
#[path = "render_workspace_tests.rs"]
mod tests;
+type PathFactory = Box<dyn FnOnce() -> Result<ImageHost, String> + Send>;
+
pub struct State {
+ pending_setup: Option<PathFactory>,
pub host: Option<ExecutorDescriptor>,
+ pub path_host: PathHost,
+ /// How long the last path tracer setup took, in seconds, per viewport adapter
+ /// ([`adapter_key`]); kept in the preferences to estimate the next one.
+ pub setup_seconds: std::collections::BTreeMap<String, f64>,
+ /// The viewport adapter the current setup runs on.
+ pub setup_key: Option<String>,
pub image_host: Option<solidcraft_engine::render::job::CpuHost>,
pub view: ViewState,
revision: u64,
@@ -31,6 +41,121 @@ pub struct State {
key: Option<u64>,
scene_signature: Option<(u64, usize, u64)>,
scene: Option<ProductScene>,
+ image: Option<(solidcraft_engine::render::job::JobId, Result<egui::TextureHandle, String>)>,
+}
+
+/// Application-wide setup, retained across document changes. The worker owns a
+/// cloned adapter and initializes the job device; the UI receives the finished host.
+#[derive(Default)]
+pub enum PathHost {
+ #[default]
+ NotStarted,
+ /// The worker's answer, and when it started: shader compilation can take minutes.
+ Preparing(std::sync::mpsc::Receiver<Result<ImageHost, String>>, std::time::Instant),
+ Ready(ImageHost),
+ Failed(String),
+}
+
+impl PathHost {
+ #[cfg(not(target_arch = "wasm32"))]
+ pub(crate) fn start(&mut self, create: impl FnOnce() -> Result<ImageHost, String> + Send + 'static) {
+ if !matches!(self, Self::NotStarted) {
+ return;
+ }
+ let (tx, rx) = std::sync::mpsc::channel();
+ // Dropping the handle detaches: neither startup nor shutdown joins a driver
+ // that may spend minutes compiling or warming up its pipelines.
+ *self = match std::thread::Builder::new().name("gpu-path-setup".into()).spawn(move || {
+ let result =
+ std::panic::catch_unwind(std::panic::AssertUnwindSafe(create)).unwrap_or_else(|_| Err("GPU path tracer setup panicked".into()));
+ let _ = tx.send(result);
+ }) {
+ Ok(_) => Self::Preparing(rx, std::time::Instant::now()),
+ Err(e) => Self::failed(format!("could not start setup worker: {e}")),
+ };
+ }
+
+ fn failed(message: String) -> Self {
+ log::warn!("progressive render unavailable: {message}");
+ Self::Failed(message)
+ }
+
+ /// Take the worker's answer if it has come; returns how long a successful setup took.
+ fn poll(&mut self) -> Option<std::time::Duration> {
+ let Self::Preparing(rx, started) = self else { return None };
+ let took = started.elapsed();
+ *self = match rx.try_recv() {
+ Ok(Ok(host)) => Self::Ready(host),
+ Ok(Err(error)) => Self::failed(error),
+ Err(std::sync::mpsc::TryRecvError::Empty) => return None,
+ Err(std::sync::mpsc::TryRecvError::Disconnected) => Self::failed("setup worker stopped without returning a host".into()),
+ };
+ matches!(self, Self::Ready(_)).then_some(took)
+ }
+}
+
+/// The samples slider's top end: 2^12 = 4096 samples per pixel.
+const MAX_SAMPLES_EXPONENT: u32 = 12;
+
+/// Setup times kept per adapter, at most.
+const MAX_SETUP_TIMES: usize = 16;
+
+/// The key [`State::setup_seconds`] files an adapter's setup time under: a driver update
+/// usually empties the driver's shader cache, so the driver is part of it.
+pub fn adapter_key(info: &egui_wgpu::wgpu::AdapterInfo) -> String {
+ format!("{} | {:?} | {} {}", info.name.trim(), info.backend, info.driver.trim(), info.driver_info.trim())
+}
+
+/// Remember how long the setup on `key` took, for the next start's estimate.
+fn record_setup(state: &mut State, took: std::time::Duration) {
+ let Some(key) = state.setup_key.clone() else { return };
+ if state.setup_seconds.len() >= MAX_SETUP_TIMES && !state.setup_seconds.contains_key(&key) {
+ return;
+ }
+ state.setup_seconds.insert(key, took.as_secs_f64());
+}
+
+/// Setup times from the preferences: finite, non-negative and at most a day each.
+pub fn load_setup_seconds(value: &serde_json::Value) -> std::collections::BTreeMap<String, f64> {
+ value
+ .as_object()
+ .into_iter()
+ .flatten()
+ .filter_map(|(k, v)| Some((k.clone(), v.as_f64().filter(|s| s.is_finite() && (0.0..=86_400.0).contains(s))?)))
+ .take(MAX_SETUP_TIMES)
+ .collect()
+}
+
+/// Minutes and seconds, as `1:05`.
+fn mmss(d: std::time::Duration) -> String {
+ let s = d.as_secs();
+ format!("{}:{:02}", s / 60, s % 60)
+}
+
+/// The path tracer's setup as it goes: a progress bar estimated from the last setup on this
+/// adapter, else a spinner with the time so far. Drivers report no progress of their own.
+fn setup_progress(ui: &mut egui::Ui, app: &SolveApp, started: std::time::Instant) {
+ let elapsed = started.elapsed();
+ let expected = app.render_workspace.setup_key.as_ref().and_then(|k| app.render_workspace.setup_seconds.get(k)).copied();
+ ui.label(app.tr("render.gpu_path_preparing"));
+ match expected.map(|s| std::time::Duration::from_secs_f64(s.max(1.0))) {
+ Some(expected) if elapsed < expected.mul_f64(1.5) => {
+ let fraction = (elapsed.as_secs_f32() / expected.as_secs_f32()).min(0.99);
+ crate::ui_kit::progress(ui, "gpu_path_setup", fraction);
+ ui.label(format!("{} / ~{}", mmss(elapsed), mmss(expected)));
+ // The bar moves with time, so keep drawing while it is shown.
+ ui.ctx().request_repaint_after(std::time::Duration::from_millis(250));
+ }
+ _ => {
+ ui.horizontal(|ui| {
+ ui.spinner();
+ ui.label(mmss(elapsed));
+ });
+ if expected.is_none() {
+ ui.small(app.tr("render.gpu_path_first_setup"));
+ }
+ }
+ }
}
/// Small per-document editor state; GPU uploads and host capabilities stay outside tabs.
@@ -42,12 +167,24 @@ pub struct ViewState {
job: Option<solidcraft_engine::render::job::JobId>,
completed: Option<solidcraft_engine::render::job::JobId>,
transparent: bool,
+ progressive: bool,
+ samples: u32,
overwrite: bool,
}
impl Default for ViewState {
fn default() -> Self {
- Self { name: "Studio".into(), draft: RenderSetup::default(), dirty: false, job: None, completed: None, transparent: false, overwrite: false }
+ Self {
+ name: "Studio".into(),
+ draft: RenderSetup::default(),
+ dirty: false,
+ job: None,
+ completed: None,
+ transparent: false,
+ progressive: false,
+ samples: 64,
+ overwrite: false,
+ }
}
}
@@ -55,6 +192,10 @@ impl Default for State {
fn default() -> Self {
Self {
host: None,
+ path_host: PathHost::default(),
+ pending_setup: None,
+ setup_seconds: Default::default(),
+ setup_key: None,
image_host: None,
view: Default::default(),
revision: u64::MAX,
@@ -63,6 +204,29 @@ impl Default for State {
key: None,
scene_signature: None,
scene: None,
+ image: None,
+ }
+ }
+}
+
+impl State {
+ /// Retain the selected viewport adapter, but do not open another device or
+ /// compile shaders until Render is used. A later viewport installation (for
+ /// example safe-mode fallback) replaces only a not-yet-started factory.
+ #[cfg(not(target_arch = "wasm32"))]
+ pub(crate) fn defer_path_host(&mut self, key: String, create: impl FnOnce() -> Result<ImageHost, String> + Send + 'static) {
+ if matches!(self.path_host, PathHost::NotStarted) {
+ self.setup_key = Some(key);
+ self.pending_setup = Some(Box::new(create));
+ }
+ }
+
+ #[cfg(not(target_arch = "wasm32"))]
+ fn start_deferred_path_host(&mut self) {
+ if matches!(self.path_host, PathHost::NotStarted)
+ && let Some(create) = self.pending_setup.take()
+ {
+ self.path_host.start(create);
}
}
}
@@ -99,6 +263,20 @@ pub fn host_executor(max_dimension: u32, depth: bool, samples: u32) -> Result<Ex
}
pub fn sync_backend(app: &mut SolveApp) {
+ #[cfg(not(target_arch = "wasm32"))]
+ if active(app) {
+ app.render_workspace.start_deferred_path_host();
+ }
+ if let Some(took) = app.render_workspace.path_host.poll() {
+ record_setup(&mut app.render_workspace, took);
+ }
+ if let PathHost::Ready(host) = &app.render_workspace.path_host
+ && let Err(e) = app.session.register_render_job_host(host.clone())
+ {
+ app.render_workspace.path_host = PathHost::failed(e.to_string());
+ app.set_status(e.to_string(), true);
+ }
+
if app.session.render_job_host().is_none()
&& let Some(host) = &app.render_workspace.image_host
&& let Err(e) = app.session.set_render_job_host(Some(host.clone()))
@@ -116,6 +294,10 @@ pub fn sync_backend(app: &mut SolveApp) {
/// Cooperative work belongs to the frame loop, never to a status/control request. Keep
/// scheduling frames even after leaving Render so a browser job can finish in Design.
pub fn tick(app: &mut SolveApp, ctx: &egui::Context) {
+ if matches!(app.render_workspace.path_host, PathHost::Preparing(..)) {
+ // Poll even in Design or an idle window, without continuously redrawing.
+ ctx.request_repaint_after(std::time::Duration::from_millis(100));
+ }
if let Some(host) = &app.render_workspace.image_host {
match host.pump(1024) {
Ok(true) => ctx.request_repaint(),
@@ -129,7 +311,11 @@ pub fn reset_document(app: &mut SolveApp) {
app.ui.ribbon_context = None;
let host = app.render_workspace.host.clone();
let image_host = app.render_workspace.image_host.clone();
- app.render_workspace = State { host, image_host, ..Default::default() };
+ let path_host = std::mem::take(&mut app.render_workspace.path_host);
+ let setup_seconds = std::mem::take(&mut app.render_workspace.setup_seconds);
+ let setup_key = app.render_workspace.setup_key.take();
+ let pending_setup = app.render_workspace.pending_setup.take();
+ app.render_workspace = State { host, image_host, path_host, setup_seconds, setup_key, pending_setup, ..Default::default() };
if active(app) {
app.ui.tab = "MODEL".into();
}
@@ -157,6 +343,8 @@ pub fn enter(app: &mut SolveApp, render: bool) -> Result<(), String> {
app.cam.fit(&scene.bounds);
}
}
+ #[cfg(not(target_arch = "wasm32"))]
+ app.render_workspace.start_deferred_path_host();
} else {
if let Some((camera, perspective)) = app.render_workspace.design_camera.take() {
app.cam = camera;
@@ -184,7 +372,7 @@ pub fn panel(app: &mut SolveApp, ui: &mut egui::Ui) {
egui::ScrollArea::vertical().show(ui, |ui| {
ui.heading(app.tr("cmd.render_settings_get"));
ui.label(app.tr("render.preview"));
- ui.small(app.tr("render.opaque_preview_help"));
+ ui.add(egui::Label::new(egui::RichText::new(app.tr("render.opaque_preview_help")).small()).wrap());
ui.separator();
let names: Vec<_> = app.session.doc.render.setups.keys().cloned().collect();
let old_name = app.render_workspace.view.name.clone();
@@ -266,7 +454,7 @@ pub fn panel(app: &mut SolveApp, ui: &mut egui::Ui) {
fn image_controls(app: &mut SolveApp, ui: &mut egui::Ui) {
ui.heading(app.tr("render.image_title"));
- ui.small(app.tr("render.opaque_image_summary"));
+ ui.small(app.tr(if app.render_workspace.view.progressive { "render.progressive_image_summary" } else { "render.opaque_image_summary" }));
ui.horizontal(|ui| {
ui.label(app.tr("render.image_width"));
if crate::ui_kit::number_field(ui, &mut app.render_workspace.view.draft.width, 1..=4096, 1.0, "").changed() {
@@ -289,11 +477,32 @@ fn image_controls(app: &mut SolveApp, ui: &mut egui::Ui) {
app.render_workspace.view.dirty = true;
}
}
+ match &app.render_workspace.path_host {
+ PathHost::Preparing(_, started) => setup_progress(ui, app, *started),
+ PathHost::Failed(error) => {
+ ui.add(egui::Label::new(format!("{}: {error}", app.tr("render.gpu_path_failed"))).wrap());
+ }
+ _ => {}
+ }
+ if matches!(app.render_workspace.path_host, PathHost::Ready(_)) {
+ let label = app.tr("render.image_progressive").to_string();
+ crate::ui_kit::checkbox(ui, &label, &mut app.render_workspace.view.progressive);
+ if app.render_workspace.view.progressive {
+ ui.label(app.tr("render.image_samples"));
+ // Powers of two from 1 to 4096 samples per pixel; requests from elsewhere keep any count.
+ let samples = &mut app.render_workspace.view.samples;
+ let mut exponent = (*samples).max(1).ilog2().min(MAX_SAMPLES_EXPONENT);
+ let slider = crate::ui_kit::Slider { integer: true, format: |e| format!("{}", 1u32 << (e as u32).min(31)), ..Default::default() };
+ if crate::ui_kit::slider(ui, &mut exponent, 0..=MAX_SAMPLES_EXPONENT, slider).changed() {
+ *samples = 1 << exponent.min(MAX_SAMPLES_EXPONENT);
+ }
+ }
+ }
let transparent_label = app.tr("render.image_transparent").to_string();
crate::ui_kit::checkbox(ui, &transparent_label, &mut app.render_workspace.view.transparent);
if crate::ui_kit::button(ui, app.tr("cmd.render_preflight"), crate::ui_kit::Button::Normal).clicked() {
let settings = RenderSetup { camera: app.cam, ..app.render_workspace.view.draft.clone() };
- if app.run("render.preflight", json!({"settings":settings,"transparent_background":app.render_workspace.view.transparent})).is_ok() {
+ if app.run("render.preflight", json!({"settings":settings,"transparent_background":app.render_workspace.view.transparent,"progressive":app.render_workspace.view.progressive,"samples":app.render_workspace.view.progressive.then_some(app.render_workspace.view.samples)})).is_ok() {
app.set_status(app.tr("render.image_supported").to_string(), false);
}
}
@@ -318,7 +527,7 @@ fn image_controls(app: &mut SolveApp, ui: &mut egui::Ui) {
app.render_workspace.view.completed = Some(job);
}
if let Some(message) = status["error"]["message"].as_str() {
- ui.label(message);
+ ui.add(egui::Label::new(message).wrap());
if status["error"]["code"] == "limit_exceeded" {
ui.small(app.tr("render.image_reduce"));
}
@@ -339,13 +548,13 @@ fn image_controls(app: &mut SolveApp, ui: &mut egui::Ui) {
}
}
Err(e) => {
- ui.label(e.to_string());
+ ui.add(egui::Label::new(e.to_string()).wrap());
}
}
}
if crate::ui_kit::button(ui, app.tr("render.image_start"), crate::ui_kit::Button::Enabled(!busy)).clicked() {
let settings = RenderSetup { camera: app.cam, ..app.render_workspace.view.draft.clone() };
- if let Ok(reply) = app.run("render.start", json!({"settings":settings,"transparent_background":app.render_workspace.view.transparent})) {
+ if let Ok(reply) = app.run("render.start", json!({"settings":settings,"transparent_background":app.render_workspace.view.transparent,"progressive":app.render_workspace.view.progressive,"samples":app.render_workspace.view.progressive.then_some(app.render_workspace.view.samples)})) {
app.render_workspace.view.job = serde_json::from_value(reply["job"].clone()).ok();
ui.ctx().request_repaint();
}
@@ -358,6 +567,56 @@ fn image_controls(app: &mut SolveApp, ui: &mut egui::Ui) {
{
export_image(app, job, app.render_workspace.view.overwrite);
}
+ completed_image(app, ui);
+}
+
+/// The job currently publishes a PNG only after encoding completes. Decode/upload once per
+/// completed job, not once per UI frame; keep the last exportable image during a new render.
+fn completed_image(app: &mut SolveApp, ui: &mut egui::Ui) {
+ let Some(job) = app.render_workspace.view.completed else {
+ app.render_workspace.image = None;
+ return;
+ };
+ if app.render_workspace.image.as_ref().is_none_or(|(old, _)| *old != job) {
+ let result = (|| -> Result<egui::TextureHandle, String> {
+ let handle = app.session.render_job_handle(job).map_err(|e| e.to_string())?;
+ let frame = handle.frame().map_err(|e| e.to_string())?.ok_or("render has no completed image")?;
+ let image = decode_image(frame.png(), frame.info.width, frame.info.height)?;
+ Ok(ui.ctx().load_texture("sc_render_image", image, egui::TextureOptions::LINEAR))
+ })();
+ // Cache errors too, so a bad frame cannot repeatedly allocate or decode on repaint.
+ app.render_workspace.image = Some((job, result));
+ }
+ if let Some((_, image)) = &app.render_workspace.image {
+ match image {
+ Ok(texture) => {
+ ui.add(egui::Image::new(texture).max_size(egui::vec2(ui.available_width(), 240.0)).shrink_to_fit())
+ .on_hover_text(app.tr("render.image_completed"));
+ }
+ Err(error) => {
+ ui.add(egui::Label::new(error).wrap());
+ }
+ }
+ }
+}
+
+fn decode_image(png: &[u8], width: u32, height: u32) -> Result<egui::ColorImage, String> {
+ let size = (u64::from(width), u64::from(height));
+ let budget = RenderLimits::default();
+ if budget.fit(size.0, size.1, None) != Some(size) {
+ return Err("render image exceeds preview limits".into());
+ }
+ let mut reader = image::ImageReader::with_format(std::io::Cursor::new(png), image::ImageFormat::Png);
+ let mut limits = image::Limits::default();
+ limits.max_image_width = Some(width);
+ limits.max_image_height = Some(height);
+ limits.max_alloc = Some(budget.max_pixels * 16);
+ reader.limits(limits);
+ let image = reader.decode().map_err(|e| e.to_string())?.to_rgba8();
+ if image.dimensions() != (width, height) {
+ return Err("render image dimensions do not match its job".into());
+ }
+ Ok(egui::ColorImage::from_rgba_unmultiplied([width as usize, height as usize], image.as_raw()))
}
/// Keep the selected image and overwrite consent fixed while the upstream picker holds model input.
@@ -399,17 +658,21 @@ pub fn gpu_scene(scene: &ProductScene) -> Result<(u64, GpuScene), String> {
body.name.hash(&mut hash);
body.color.hash(&mut hash);
body.opacity.to_bits().hash(&mut hash);
+ body.transmission.is_some().hash(&mut hash);
hash_surface(body.surface, &mut hash);
let looks: std::collections::BTreeMap<_, _> = body.faces.iter().map(|l| (l.face, l)).collect();
for face in &body.faces {
face.face.hash(&mut hash);
face.color.hash(&mut hash);
face.opacity.to_bits().hash(&mut hash);
+ face.transmission.is_some().hash(&mut hash);
hash_surface(face.surface, &mut hash);
}
for (index, triangle) in body.mesh.triangles.iter().enumerate() {
let face = body.mesh.tri_face.get(index).and_then(|f| looks.get(f));
- let (color, opacity, surface) = face.map_or((body.color, body.opacity, body.surface), |l| (l.color, l.opacity, l.surface));
+ let (color, opacity, surface) = face.map_or((body.color, body.opacity, body.surface.filter(|_| body.transmission.is_none())), |l| {
+ (l.color, l.opacity, l.surface.filter(|_| l.transmission.is_none()))
+ });
if surface.is_some() && opacity != 1.0 {
return Err("opaque PBR requires opacity 1".into());
}
diff --git a/crates/ui-egui/src/render_workspace_tests.rs b/crates/ui-egui/src/render_workspace_tests.rs
index 23408069ad..cec6de3228 100644
--- a/crates/ui-egui/src/render_workspace_tests.rs
+++ b/crates/ui-egui/src/render_workspace_tests.rs
@@ -2,6 +2,249 @@ use super::*;
use crate::scenario::Harness;
use solidcraft_engine::Session;
+#[cfg(not(target_arch = "wasm32"))]
+mod async_path_host {
+ use super::*;
+ use solidcraft_engine::render::job;
+ use std::sync::mpsc;
+ use std::time::{Duration, Instant};
+
+ /// Advertise the path capability without opening a device or rendering anything.
+ struct TestExecutor;
+ impl job::ImageExecutor for TestExecutor {
+ fn descriptor(&self) -> job::Result<ExecutorDescriptor> {
+ let mut descriptor = job::CpuHost::cooperative().descriptor()?;
+ descriptor.id = ExecutorId::new("test-path").unwrap();
+ descriptor.profiles[0].features.push(solidcraft_engine::render::RenderFeature::Progressive);
+ Ok(descriptor)
+ }
+ fn admit(&self, _: &ProductScene, _: &job::ImageRequest, _: job::JobOptions) -> job::Result<job::Admission> {
+ panic!("setup tests must not render")
+ }
+ fn begin(&self, _: ProductScene, _: job::ImageRequest, _: job::JobOptions, _: job::CancelToken) -> job::Result<Box<dyn job::ImageWork>> {
+ panic!("setup tests must not render")
+ }
+ }
+
+ fn panel_fixture() -> Harness {
+ let mut h = Harness::new();
+ h.call("ui.resize", json!({"width":1600,"height":1600}));
+ enter(&mut h.app, true).unwrap();
+ h.frames(3);
+ h
+ }
+
+ fn finish_setup(h: &mut Harness) {
+ let deadline = Instant::now() + Duration::from_secs(10);
+ while matches!(h.app.render_workspace.path_host, PathHost::Preparing(..)) {
+ assert!(Instant::now() < deadline, "test setup worker did not finish");
+ h.frames(1);
+ std::thread::sleep(Duration::from_millis(1));
+ }
+ h.frames(3);
+ }
+
+ #[test]
+ fn design_frames_and_document_reset_never_start_the_deferred_path_host() {
+ use std::sync::atomic::{AtomicUsize, Ordering};
+ let calls = Arc::new(AtomicUsize::new(0));
+ let observed = calls.clone();
+ let mut h = Harness::new();
+ h.app.render_workspace.defer_path_host("selected viewport".into(), move || {
+ observed.fetch_add(1, Ordering::SeqCst);
+ job::ImageHost::with_executor(Arc::new(TestExecutor)).map_err(|e| e.to_string())
+ });
+ h.frames(5);
+ crate::documents::adopt(&mut h.app, Session::default());
+ h.frames(5);
+ assert_eq!(calls.load(Ordering::SeqCst), 0);
+ assert!(matches!(h.app.render_workspace.path_host, PathHost::NotStarted));
+ assert!(h.app.render_workspace.pending_setup.is_some());
+ enter(&mut h.app, true).unwrap();
+ finish_setup(&mut h);
+ assert_eq!(calls.load(Ordering::SeqCst), 1);
+ assert!(matches!(h.app.render_workspace.path_host, PathHost::Ready(_)));
+ enter(&mut h.app, false).unwrap();
+ enter(&mut h.app, true).unwrap();
+ h.frames(5);
+ assert_eq!(calls.load(Ordering::SeqCst), 1);
+ }
+
+ #[test]
+ fn first_render_before_adapter_install_starts_once_when_the_adapter_arrives() {
+ use std::sync::atomic::{AtomicUsize, Ordering};
+ let calls = Arc::new(AtomicUsize::new(0));
+ let observed = calls.clone();
+ let mut h = panel_fixture();
+ assert!(matches!(h.app.render_workspace.path_host, PathHost::NotStarted));
+ h.app.render_workspace.defer_path_host("late selected viewport".into(), move || {
+ observed.fetch_add(1, Ordering::SeqCst);
+ Err("deliberate device refusal".into())
+ });
+ sync_backend(&mut h.app);
+ finish_setup(&mut h);
+ assert_eq!(calls.load(Ordering::SeqCst), 1);
+ assert!(matches!(h.app.render_workspace.path_host, PathHost::Failed(_)));
+ h.app.render_workspace.defer_path_host("must not retry".into(), || panic!("failed setup retried"));
+ enter(&mut h.app, false).unwrap();
+ enter(&mut h.app, true).unwrap();
+ h.frames(5);
+ assert_eq!(calls.load(Ordering::SeqCst), 1);
+ }
+
+ #[test]
+ fn a_fallback_viewport_replaces_an_unstarted_factory_without_opening_the_old_device() {
+ let mut h = Harness::new();
+ h.app.render_workspace.defer_path_host("old hardware adapter".into(), || panic!("superseded device opened"));
+ h.app.render_workspace.defer_path_host("selected safe-mode adapter".into(), || Err("selected adapter unavailable".into()));
+ h.frames(5);
+ assert_eq!(h.app.render_workspace.setup_key.as_deref(), Some("selected safe-mode adapter"));
+ enter(&mut h.app, true).unwrap();
+ finish_setup(&mut h);
+ let PathHost::Failed(message) = &h.app.render_workspace.path_host else { panic!("expected selected adapter result") };
+ assert_eq!(message, "selected adapter unavailable");
+ }
+
+ #[test]
+ fn preparing_keeps_frames_responsive_then_registers_ready_host() {
+ let mut h = panel_fixture();
+ let cpu_host = h.app.session.render_job_host().unwrap().clone();
+ let (release, wait) = mpsc::channel();
+ let (started, thread) = mpsc::channel();
+ h.app.render_workspace.path_host.start(move || {
+ started.send(std::thread::current().id()).unwrap();
+ wait.recv_timeout(Duration::from_secs(10)).unwrap();
+ job::ImageHost::with_executor(Arc::new(TestExecutor)).map_err(|e| e.to_string())
+ });
+ assert_ne!(thread.recv_timeout(Duration::from_secs(10)).unwrap(), std::thread::current().id());
+ // A second viewport installation cannot replace or duplicate setup.
+ h.app.render_workspace.path_host.start(|| panic!("setup started twice"));
+ h.frames(3);
+ assert!(h.widget("GPU path tracer: compiling shaders…").is_some());
+ assert!(h.widget("Progressive rendering").is_none());
+ assert!(!h.app.session.render_backend().executors.iter().any(|e| e.id.as_str() == "test-path"));
+ let transparent = h.app.tr("render.image_transparent").to_string();
+ h.step(&json!({"widget":transparent})).unwrap();
+ assert!(h.app.render_workspace.view.transparent);
+ // Replacing the current document must retain the receiver while setup waits.
+ crate::documents::adopt(&mut h.app, Session::default());
+ assert!(matches!(h.app.render_workspace.path_host, PathHost::Preparing(..)));
+ enter(&mut h.app, true).unwrap();
+ h.frames(3);
+ assert!(h.widget("GPU path tracer: compiling shaders…").is_some());
+ enter(&mut h.app, false).unwrap();
+ release.send(()).unwrap();
+ finish_setup(&mut h);
+ assert!(matches!(h.app.render_workspace.path_host, PathHost::Ready(_)));
+ enter(&mut h.app, true).unwrap();
+ h.frames(3);
+ assert!(h.widget("GPU path tracer: compiling shaders…").is_none());
+ assert!(h.widget("Progressive rendering").is_some());
+ assert_eq!(h.app.session.render_backend().executors.iter().filter(|e| e.id.as_str() == "test-path").count(), 1);
+ assert!(h.app.session.render_job_host().unwrap().same_host(&cpu_host));
+ h.step(&json!({"widget":"Progressive rendering"})).unwrap();
+ assert!(h.app.render_workspace.view.progressive);
+ crate::documents::adopt(&mut h.app, Session::default());
+ assert!(matches!(h.app.render_workspace.path_host, PathHost::Ready(_)));
+ assert_eq!(h.app.session.render_backend().executors.iter().filter(|e| e.id.as_str() == "test-path").count(), 1);
+ }
+
+ /// The first setup on an adapter shows a spinner, the time so far and a note; a later one
+ /// a bar estimated from the time the first took, which the preferences keep.
+ #[test]
+ fn setup_progress_is_estimated_from_the_last_setup_on_the_adapter() {
+ let mut h = panel_fixture();
+ h.app.render_workspace.setup_key = Some("Test GPU | Vulkan | 1.0".into());
+ let (release, wait) = mpsc::channel::<()>();
+ h.app.render_workspace.path_host.start(move || {
+ wait.recv_timeout(Duration::from_secs(10)).unwrap();
+ job::ImageHost::with_executor(Arc::new(TestExecutor)).map_err(|e| e.to_string())
+ });
+ h.frames(3);
+ let first = h.app.tr("render.gpu_path_first_setup").to_string();
+ assert!(h.widget("GPU path tracer: compiling shaders…").is_some());
+ assert!(h.widget(&first).is_some(), "the first setup explains the wait");
+ assert!(h.widget("0:00").is_some(), "and counts the time");
+ release.send(()).unwrap();
+ finish_setup(&mut h);
+ let took = h.app.render_workspace.setup_seconds.get("Test GPU | Vulkan | 1.0").copied();
+ assert!(took.is_some_and(|s| (0.0..10.0).contains(&s)), "{took:?}");
+
+ // The next start on the same adapter has an estimate, kept in the preferences.
+ let mut h = panel_fixture();
+ h.app.load_prefs(&json!({"gpu_path_setup_seconds": {"Test GPU | Vulkan | 1.0": 120.0}}).to_string());
+ h.app.render_workspace.setup_key = Some("Test GPU | Vulkan | 1.0".into());
+ let (release, wait) = mpsc::channel::<()>();
+ h.app.render_workspace.path_host.start(move || {
+ wait.recv_timeout(Duration::from_secs(10)).unwrap();
+ job::ImageHost::with_executor(Arc::new(TestExecutor)).map_err(|e| e.to_string())
+ });
+ h.frames(3);
+ assert!(h.widget(&first).is_none());
+ assert!(h.widget("0:00 / ~2:00").is_some(), "a bar with the estimate");
+ release.send(()).unwrap();
+ finish_setup(&mut h);
+ let prefs: serde_json::Value = serde_json::from_str(&h.app.prefs()).unwrap();
+ assert!(prefs["gpu_path_setup_seconds"]["Test GPU | Vulkan | 1.0"].as_f64().is_some_and(|s| s < 10.0));
+ }
+
+ #[test]
+ fn hostile_setup_times_are_ignored() {
+ let times = load_setup_seconds(&json!({"a": -1.0, "b": 1e300, "c": "slow", "d": 30.0}));
+ assert_eq!(times.into_iter().collect::<Vec<_>>(), [("d".to_string(), 30.0)]);
+ let many: serde_json::Map<String, serde_json::Value> = (0..100).map(|i| (format!("gpu {i}"), json!(1.0))).collect();
+ assert_eq!(load_setup_seconds(&serde_json::Value::Object(many)).len(), MAX_SETUP_TIMES);
+ }
+
+ #[test]
+ fn setup_error_is_visible_and_survives_document_reset() {
+ let mut h = panel_fixture();
+ h.app.render_workspace.path_host.start(|| Err("test driver refused the device".into()));
+ finish_setup(&mut h);
+ let message = "GPU path tracer unavailable: test driver refused the device";
+ assert!(h.widget(message).is_some());
+ assert!(h.widget("GPU path tracer: compiling shaders…").is_none());
+ assert!(h.widget("Progressive rendering").is_none());
+ assert!(h.app.session.render_job_host().is_some());
+ completed_preview(&mut h, [200, 210, 220]);
+ crate::documents::adopt(&mut h.app, Session::default());
+ enter(&mut h.app, true).unwrap();
+ h.frames(3);
+ assert!(h.widget(message).is_some());
+ h.app.render_workspace.path_host.start(|| panic!("failed setup retried on viewport install"));
+ assert!(matches!(h.app.render_workspace.path_host, PathHost::Failed(_)));
+ }
+
+ #[test]
+ fn disconnected_setup_is_reported_in_the_panel() {
+ let mut h = panel_fixture();
+ let (tx, rx) = mpsc::channel();
+ h.app.render_workspace.path_host = PathHost::Preparing(rx, Instant::now());
+ drop(tx);
+ h.frames(3);
+ assert!(h.widget("GPU path tracer unavailable: setup worker stopped without returning a host").is_some());
+ }
+
+ #[test]
+ fn panicking_setup_is_reported_in_the_panel() {
+ let mut h = panel_fixture();
+ h.app.render_workspace.path_host.start(|| panic!("simulated driver panic"));
+ finish_setup(&mut h);
+ assert!(h.widget("GPU path tracer unavailable: GPU path tracer setup panicked").is_some());
+ }
+
+ #[test]
+ fn registration_failure_is_reported_in_the_panel() {
+ let mut h = panel_fixture();
+ // A different host with the same CPU descriptor cannot be registered twice.
+ h.app.render_workspace.path_host.start(|| Ok(job::CpuHost::cooperative()));
+ finish_setup(&mut h);
+ let PathHost::Failed(message) = &h.app.render_workspace.path_host else { panic!("duplicate executor must fail") };
+ assert!(h.widget(&format!("GPU path tracer unavailable: {message}")).is_some());
+ assert!(h.widget("Progressive rendering").is_none());
+ }
+}
+
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn opaque_pbr_product_gpu_and_cpu_share_color_and_material_semantics() {
@@ -32,7 +275,15 @@ fn opaque_pbr_product_gpu_and_cpu_share_color_and_material_semantics() {
let eye = camera.eye().to_f32();
let mut task = ImageTask::new(
scene,
- ImageRequest { camera, width: SIZE, height: SIZE, background: [255; 3], transparent_background: false },
+ ImageRequest {
+ textures: None,
+ environment: None,
+ camera,
+ width: SIZE,
+ height: SIZE,
+ background: [255; 3],
+ transparent_background: false,
+ },
CancelToken::default(),
)
.unwrap();
@@ -211,6 +462,55 @@ fn saved_camera_survives_frames_and_product_fit_ignores_selection() {
assert_eq!(h.app.cam, design);
}
+#[cfg(not(target_arch = "wasm32"))]
+#[test]
+fn progressive_image_controls_route_to_the_registered_host() {
+ let host = solidcraft_gpu::select::Policy::from_env()
+ .and_then(|policy| solidcraft_gpu::select::pick(policy).ok_or_else(|| "no qualifying adapter".to_string()))
+ .and_then(|(adapter, _)| solidcraft_gpu::path::host_on_adapter(&adapter).map_err(|e| e.to_string()));
+ let host = match host {
+ Ok(host) => host,
+ Err(e) => {
+ assert!(std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required GPU unavailable: {e}");
+ eprintln!("skipping progressive UI device test: {e}");
+ return;
+ }
+ };
+ let mut h = Harness::new();
+ h.app.render_workspace.path_host = PathHost::Ready(host);
+ sync_backend(&mut h.app);
+ h.app.run("solid.box", json!({"length":10,"width":20,"height":5})).unwrap();
+ h.app.session.mark_saved();
+ h.call("ui.resize", json!({"width":1600,"height":1600}));
+ enter(&mut h.app, true).unwrap();
+ h.app.render_workspace.view.draft.width = 16;
+ h.app.render_workspace.view.draft.height = 16;
+ h.app.render_workspace.view.samples = 4;
+ h.frames(3);
+ let doc = h.app.session.doc.clone();
+ let undo = h.app.session.undo.len();
+ h.step(&json!({"widget":"Progressive rendering"})).unwrap();
+ assert!(h.app.render_workspace.view.progressive);
+ let start = h.app.tr("render.image_start").to_string();
+ h.step(&json!({"widget":start})).unwrap();
+ let job = h.app.render_workspace.view.job.unwrap();
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
+ while h.app.render_workspace.view.completed.is_none() {
+ assert!(std::time::Instant::now() < deadline, "progressive UI job did not complete");
+ std::thread::sleep(std::time::Duration::from_millis(5));
+ h.frames(1);
+ }
+ let status = h.app.session.execute("render.status", &json!({"job":job})).unwrap();
+ assert_eq!(status["frame"]["executor"], "gpu-path", "{status}");
+ assert_eq!(status["options"]["samples"], 4);
+ let export = h.app.tr("render.image_export").to_string();
+ h.step(&json!({"widget":export})).unwrap();
+ assert!(h.dir.join("render.png").is_file());
+ assert!(Arc::ptr_eq(&doc, &h.app.session.doc));
+ assert_eq!(h.app.session.undo.len(), undo);
+ assert!(!h.app.session.is_dirty());
+}
+
#[test]
fn clicked_render_workspace_saves_one_setup_and_restores_design_view() {
for language in ["en", "de", "ko", "ru"] {
@@ -291,6 +591,28 @@ fn product_gpu_buffers_preserve_opacity_and_never_contain_overlays() {
assert!(empty.tris.is_empty() && empty.glass.is_empty());
}
+#[test]
+fn transmission_uses_legacy_preview_buffers_and_invalidates_the_opaque_cache() {
+ let mut s = Session::default();
+ s.execute("solid.box", &json!({"length":10,"width":10,"height":10,"body_name":"Glass"})).unwrap();
+ let appearance = json!({"bodies":["Glass"],"color":"#336699",
+ "pbr":{"metallic":0,"roughness":0.1,"dielectric_ior":1.5}});
+ s.execute("appearance.assign", &appearance).unwrap();
+ let (opaque_key, opaque) = gpu_scene(&solidcraft_engine::product_scene::extract(&s).unwrap()).unwrap();
+ assert!(!opaque.pbr.is_empty());
+ let mut scene = solidcraft_engine::product_scene::extract(&s).unwrap();
+ scene.meshes[0].transmission =
+ Some(solidcraft_engine::render::transmission::Transmission::new(solidcraft_engine::geom::Vec3::ZERO, None).unwrap());
+ let (glass_key, glass) = gpu_scene(&scene).unwrap();
+ assert_ne!(opaque_key, glass_key);
+ assert!(glass.pbr.is_empty());
+ assert!(!glass.tris.is_empty());
+ scene.meshes[0].opacity = 0.4;
+ let (_, transparent) = gpu_scene(&scene).unwrap();
+ assert!(transparent.pbr.is_empty());
+ assert!(!transparent.glass.is_empty());
+}
+
#[test]
fn host_profiles_advertise_only_installed_opaque_pbr_not_hdri_refraction_or_final() {
use solidcraft_engine::render::*;
@@ -341,6 +663,100 @@ fn completed_preview(h: &mut Harness, background: [u8; 3]) -> solidcraft_engine:
panic!("small cooperative image did not complete within the work budget");
}
+fn image_panel_frame(app: &mut SolveApp, ctx: &egui::Context) -> egui::FullOutput {
+ ctx.run_ui(
+ egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(285.0, 1200.0))), ..Default::default() },
+ |ui| image_controls(app, ui),
+ )
+}
+
+#[test]
+fn completed_image_is_painted_once_available_and_upload_is_cached() {
+ let mut h = Harness::new();
+ let ctx = egui::Context::default();
+ image_panel_frame(&mut h.app, &ctx).textures_delta.clear();
+ assert!(h.app.render_workspace.image.is_none());
+ let doc = h.app.session.doc.clone();
+ let undo = h.app.session.undo.len();
+ let job = completed_preview(&mut h, [20, 40, 60]);
+ h.app.render_workspace.view.job = Some(job);
+ let mut output = image_panel_frame(&mut h.app, &ctx);
+ let (cached_job, texture) = h.app.render_workspace.image.as_ref().unwrap();
+ let texture = texture.as_ref().unwrap();
+ let id = texture.id();
+ assert_eq!(*cached_job, job);
+ assert_eq!(texture.size(), [16, 16]);
+ let uploaded = &output.textures_delta.set.get(&id).unwrap().first().unwrap().image;
+ let egui::ImageData::Color(pixels) = uploaded;
+ assert!(pixels.pixels.iter().all(|p| *p == Color32::from_rgb(20, 40, 60)));
+ // egui requires frame texture deltas to be applied or cleared.
+ output.textures_delta.clear();
+ assert!(
+ ctx.tessellate(output.shapes, output.pixels_per_point)
+ .iter()
+ .any(|shape| { matches!(&shape.primitive, egui::epaint::Primitive::Mesh(mesh) if mesh.texture_id == id && !mesh.indices.is_empty()) })
+ );
+ let mut output = image_panel_frame(&mut h.app, &ctx);
+ assert!(!output.textures_delta.set.contains_key(&id), "repaint must reuse the texture");
+ // egui requires frame texture deltas to be applied or cleared.
+ output.textures_delta.clear();
+ assert!(Arc::ptr_eq(&doc, &h.app.session.doc));
+ assert_eq!(h.app.session.undo.len(), undo);
+ let path = h.dir.join("displayed.png");
+ h.app.run("render.export", json!({"job":job,"path":path})).unwrap();
+ let frame = h.app.session.render_job_handle(job).unwrap().frame().unwrap().unwrap();
+ assert_eq!(std::fs::read(path).unwrap(), frame.png(), "displaying the image must not change export bytes");
+}
+
+#[test]
+fn completed_image_keeps_last_export_during_work_and_updates_for_the_next_job() {
+ let mut h = Harness::new();
+ let ctx = egui::Context::default();
+ let first = completed_preview(&mut h, [20, 40, 60]);
+ h.app.render_workspace.view.job = Some(first);
+ image_panel_frame(&mut h.app, &ctx).textures_delta.clear();
+ let old_texture = h.app.render_workspace.image.as_ref().unwrap().1.as_ref().unwrap().id();
+ let reply = h.app.run("render.start", json!({"settings":{"width":16,"height":16}})).unwrap();
+ let pending = serde_json::from_value(reply["job"].clone()).unwrap();
+ h.app.render_workspace.view.job = Some(pending);
+ image_panel_frame(&mut h.app, &ctx).textures_delta.clear();
+ assert_eq!(h.app.render_workspace.image.as_ref().unwrap().0, first);
+ h.app.run("render.cancel", json!({"job":pending})).unwrap();
+ image_panel_frame(&mut h.app, &ctx).textures_delta.clear();
+ assert_eq!(h.app.render_workspace.image.as_ref().unwrap().0, first);
+ let second = completed_preview(&mut h, [80, 100, 120]);
+ h.app.render_workspace.view.job = Some(second);
+ let mut output = image_panel_frame(&mut h.app, &ctx);
+ let (cached_job, texture) = h.app.render_workspace.image.as_ref().unwrap();
+ assert_eq!(*cached_job, second);
+ assert_ne!(texture.as_ref().unwrap().id(), old_texture);
+ assert!(output.textures_delta.free.contains(&old_texture));
+ // egui requires frame texture deltas to be applied or cleared.
+ output.textures_delta.clear();
+ crate::documents::open_tab(&mut h.app, Session::default()).unwrap();
+ image_panel_frame(&mut h.app, &ctx).textures_delta.clear();
+ assert!(h.app.render_workspace.image.is_none(), "another document must not show this image");
+ crate::documents::switch(&mut h.app, 0);
+ image_panel_frame(&mut h.app, &ctx).textures_delta.clear();
+ assert_eq!(h.app.render_workspace.image.as_ref().unwrap().0, second);
+ reset_document(&mut h.app);
+ assert!(h.app.render_workspace.image.is_none());
+}
+
+#[test]
+fn completed_image_decoder_preserves_alpha_and_rejects_invalid_sizes_and_pngs() {
+ let mut png = std::io::Cursor::new(Vec::new());
+ let pixels = image::RgbaImage::from_pixel(2, 1, image::Rgba([80, 120, 160, 128]));
+ pixels.write_to(&mut png, image::ImageFormat::Png).unwrap();
+ let decoded = decode_image(png.get_ref(), 2, 1).unwrap();
+ assert_eq!(decoded.size, [2, 1]);
+ assert_eq!(decoded.pixels, vec![Color32::from_rgba_unmultiplied(80, 120, 160, 128); 2]);
+ for (width, height) in [(0, 1), (u32::MAX, 1), (4096, 4096), (1, 1), (3, 1)] {
+ assert!(decode_image(png.get_ref(), width, height).is_err(), "{width}x{height}");
+ }
+ assert!(decode_image(b"invalid PNG", 2, 1).is_err());
+}
+
fn async_export_fixture() -> (Harness, solidcraft_engine::render::job::JobId) {
let mut h = Harness::new();
h.app.run("solid.box", json!({"length":10,"width":20,"height":5})).unwrap();
@@ -672,3 +1088,47 @@ fn four_and_five_k_viewports_preview_downscaled_within_the_limits() {
}
assert_eq!(preview_size(None, (5120, 2880)), (5120, 2880), "no executor: resolution reports it");
}
+
+/// Backend failures must remain readable in the fixed-width Render panel, not
+/// disappear into an ellipsis before the reason and recovery guidance are shown.
+#[test]
+fn backend_diagnostics_and_preview_help_wrap_without_elision() {
+ fn collect<'a>(shape: &'a egui::Shape, texts: &mut Vec<&'a egui::epaint::TextShape>) {
+ match shape {
+ egui::Shape::Text(text) => texts.push(text),
+ egui::Shape::Vec(shapes) => shapes.iter().for_each(|shape| collect(shape, texts)),
+ _ => {}
+ }
+ }
+ for mode in ["floating", "compact"] {
+ for dark in [false, true] {
+ let mut h = Harness::new();
+ h.app.home.open = false;
+ h.app.ui.dark = dark;
+ h.call("ui.resize", json!({"width":1400,"height":1800}));
+ h.app.run("view.layout", json!({"mode":mode})).unwrap();
+ enter(&mut h.app, true).unwrap();
+ let reason = "The selected viewport adapter has no compatible Vulkan path device. Images remain available on the CPU; keep the original design and review the driver before retrying.";
+ h.app.render_workspace.path_host = PathHost::Failed(reason.into());
+ h.frames(3);
+ let expected = format!("{}: {reason}", h.app.tr("render.gpu_path_failed"));
+ let help = h.app.tr("render.opaque_preview_help").to_owned();
+ let mut out = h.ctx.run_ui(
+ egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 1800.0))), ..Default::default() },
+ |ui| {
+ h.app.logic(ui.ctx());
+ h.app.ui(ui);
+ },
+ );
+ out.textures_delta.clear();
+ let mut texts = Vec::new();
+ out.shapes.iter().for_each(|shape| collect(&shape.shape, &mut texts));
+ for message in [&expected, &help] {
+ let text = texts.iter().find(|text| text.galley.job.text == *message).expect("the complete diagnostic is painted");
+ assert!(!text.galley.elided, "{mode}, dark={dark}: {message}");
+ assert!(text.galley.rows.len() > 1, "long messages must wrap in the narrow panel");
+ assert!(text.galley.rect.width() <= 285.0, "the message must not expand the panel");
+ }
+ }
+ }
+}
diff --git a/crates/ui-egui/tests/scenarios/s60_appearance_overrides.json b/crates/ui-egui/tests/scenarios/s60_appearance_overrides.json
index 6a40fdb08e..5f6aa57b99 100644
--- a/crates/ui-egui/tests/scenarios/s60_appearance_overrides.json
+++ b/crates/ui-egui/tests/scenarios/s60_appearance_overrides.json
@@ -7,6 +7,8 @@
{"expect": {"dialog": "Appearance", "shown": "Remove override"}},
{"note": "The shared 28 px controls make this card scroll; reveal Search inside its body."},
{"call": "ui.scroll", "params": {"x": 1345, "y": 650, "delta": -400}},
+ {"note": "Let the scroll animation settle before resolving the moving Search handle; the larger starter catalog otherwise puts a swatch under that click."},
+ {"frames": 20},
{"click": {"handle": "appearance:search"}},
{"text": "no-such-appearance"},
{"expect": {"shown": "No matching appearances"}},
diff --git a/docs/book/src/dev/local-libraries.md b/docs/book/src/dev/local-libraries.md
index fc7eda1626..763457c1bc 100644
--- a/docs/book/src/dev/local-libraries.md
+++ b/docs/book/src/dev/local-libraries.md
@@ -1,9 +1,10 @@
-# Local scalar libraries
+# Local material libraries
-The first local-library slice (#846) reuses the existing appearance and physical
-material commands. It is a small consumer of the broader [library proposal](libraries.md),
-not the complete resource-pack implementation. It adds no texture mapping, wood grain,
-PBR shader, HDRI lighting, online discovery or document-format version.
+The first scalar slice (#846) and portable v2 extension (#1062) reuse existing
+appearance/material commands. V2 transports existing opaque PBR looks and validated
+engineering cards; it does not add a shader, texture mapping, wood grain, HDRI,
+online discovery or document-format version. This remains a small consumer of
+the broader [library proposal](libraries.md).
## Desktop workflow
@@ -16,7 +17,7 @@ PBR shader, HDRI lighting, online discovery or document-format version.
3. Open that library in another design, search its appearance presets, select one and
choose **Apply library appearance**. The normal body/face/component targets are reused.
OK after this immediate application does not add a second undo step.
-4. Save the design. Its selected scalar definitions are ordinary copied design data;
+4. Save the design. Its selected definitions are ordinary copied design data;
the source library can be moved or removed without changing the saved result.
Export does not edit the design, its dirty state or history. An existing file is refused
@@ -72,11 +73,30 @@ outer undo transaction through the existing material commands. Mass remains the
volume × density calculation; a generic illustrative density is not an engineering grade.
`library.export` also accepts `id` (default `user.local`), `name` (default `My library`),
-`provenance` and `overwrite` (default false). Only explicit assignments/design-local
+`provenance`, `overwrite` (default false) and `format` (default `solidcraft-library/2`).
+Explicit `solidcraft-library/1` refuses PBR or engineering-card loss before publishing,
+including with overwrite enabled. Only explicit assignments/design-local
definitions are inspected, without evaluating geometry. Duplicate exact definitions are
deduplicated; different values with the same display name remain distinct entries.
-## Scalar catalog v1
+## Portable catalog v2 and scalar v1 compatibility
+
+`solidcraft-library/2` extends the same envelope and definition kinds with optional
+`pbr: {metallic, roughness, dielectric_ior}` on appearance values and optional
+`physical_card` on material values. PBR uses the existing bounded opaque contract
+and requires opacity exactly one. Cards use the existing bounded SI validator;
+source/condition records survive import, but validation does not authenticate or
+approve their sources. A card does not replace assigned mass density or supply a
+solver. Materials can carry both a card and an independent default PBR look.
+
+Absent richer fields are omitted from serialization. Existing v1 scalar bytes,
+content revisions and identities are preserved exactly; regression fixtures pin
+an appearance and a material revision from the pre-v2 writer. Changing only the
+envelope version does not change a revision. Nonempty PBR/card data participates
+in it. V1 wire input rejects even null v2-only fields; it cannot disguise richer
+data with an older format marker. Older readers refuse v2.
+
+The following v1 shape remains readable and writable explicitly:
The independent JSON format marker is `solidcraft-library/1`. It has `id`, `name` and an
`entries` array. Each entry has `id`, `revision`, `provenance` and a typed `definition`:
@@ -105,18 +125,24 @@ Provenance contains a required `license`, optional `author` and optional `source
It is supplied metadata, not verified permission or a publisher signature. URLs are never
fetched. The default `LicenseRef-User-Provided` does not claim that user data is openly
licensed. No external art/data is bundled in this slice. Catalog provenance/revisions stay
-in the catalog: the first consumer copies scalar values into existing `Look`/`UserMaterial`
-records, without a persistent catalog-origin/update receipt. Full resource embedding,
+in the catalog: values are copied into existing `Look`/`UserMaterial` records,
+without a persistent catalog-origin/update receipt. Engineering-card sources and
+conditions belong to the card and are copied with it. Full resource embedding,
design-owned provenance, scopes and explicit update links remain proposed follow-ups.
## Bounds and failure behavior
-The reader accepts at most 4 MiB encoded JSON and 1,024 entries. Entry decoding stops at
+The reader accepts at most 4 MiB encoded JSON and 1,024 entries. A bounded raw wire
+preflight preserves v1 field rules before typed decoding. Entry decoding stops at
the count cap with fallible vector growth. Names are trimmed, nonempty and at most 128
UTF-8 bytes; provenance license/author/source URL limits are 128/256/2,048 bytes. Control
characters, invalid identifiers, duplicate identities, bad revisions and nonfinite scalar
values fail. Export inspects at most 100,000 source references, deduplicating into at most
-1,024 entries. These are encoded/work limits, not a process-memory or latency guarantee.
+1,024 entries. Rich export bounds retained unique definitions before whole-catalog
+encoding, reserving 4 KiB for the envelope and counting each entry's pretty bytes plus
+nested-line indentation. This conservative writer admission can refuse a catalog
+close to 4 MiB even when a compact representation fits. These are encoded/work limits,
+not a process-memory or latency guarantee.
Native reads are bounded regular-file reads; browser reads check VFS size before cloning.
Native no-clobber writes reuse atomic new-file publication; explicit replacement is atomic
diff --git a/docs/physical-material-cards.md b/docs/physical-material-cards.md
index bb4818a22d..6357bdf2c8 100644
--- a/docs/physical-material-cards.md
+++ b/docs/physical-material-cards.md
@@ -3,8 +3,9 @@
`material.properties.validate {card}` checks a caller-supplied candidate record,
without assigning it, saving it in the design, reading files, fetching sources or
changing history, selection, camera or live geometry. This is phase 1 of #923/#922,
-building towards #785. Existing `material.create/edit` and their density/appearance
-behavior are unchanged. The design format is unchanged.
+building towards #785. The initial validator remains read-only. The design-owned persistence
+section below extends `material.create/edit` without changing assigned density or
+optical appearance.
Validation means numerical and structural consistency. It does not authenticate
sources, approve redistribution, certify design values, provide a solver or enable
@@ -189,3 +190,31 @@ The card's test conditions still apply; changing direction does not extrapolate
temperature, moisture, process, rate, damage or nonlinear behavior. Synthetic analytic
tests cover principal axes, the isotropic limit and off-axis shear/coupling terms.
No physical dataset or external implementation is included.
+
+## Design-owned persistence
+
+`material.create` accepts an optional `physical_card`; omission or null means
+unknown. `material.edit` retains an omitted card, validates and replaces a supplied
+card, and clears it only with explicit null. Density-only, appearance-only and
+rename edits retain the card. Assignment, configurations, undo/redo and Paste New
+keep using the same design-owned material definition.
+
+`material.list` reports the optional card, its validation report and a density
+comparison. Assigned density in g/cm3 and recorded density in kg/m3 stay separate:
+card data never silently changes the density used for mass. Source and condition
+claims are preserved, not certified, and this does not add an analysis solver.
+
+The single pending descriptor is `material-engineering-cards.rs`. The build
+assigns the pending format automatically; no released number, history or migration
+is edited. Older designs keep absent cards as unknown. Older readers refuse the
+newer saved format rather than silently losing engineering records.
+
+Only `user_materials[].physical_card` receives the typed SI admission needed for
+elastic moduli above coordinate limits. Other numeric/depth limits, including the
+second range check after integer-valued coordinates become typed floats, remain
+unchanged. Normal loading admits at most 1000 design-owned materials.
+
+Scalar catalog v1 refuses cards before creating or replacing an export file.
+Rich catalog transport is the separate #1086 contribution. The synthetic example
+`examples/material-card.json` uses an assigned density of 0.8 g/cm3, a recorded
+700 kg/m3 and invented isotropic constants; it is not a real material dataset.
diff --git a/docs/render-anisotropic-ggx.md b/docs/render-anisotropic-ggx.md
new file mode 100644
index 0000000000..f239c6b3f6
--- /dev/null
+++ b/docs/render-anisotropic-ggx.md
@@ -0,0 +1,46 @@
+# Anisotropic GGX numerical core
+
+`render::anisotropic_surface` supplies the independent optical core tracked in
+#1694/#1699. This constituent extracts the original source and analytic tests
+already published in #1698 at `463a3e0daaa6b84f169ba5f8f215fba4642c194a`.
+It adds no renderer registration, saved field, command, device dependency or
+engineering-material assignment. Runtime consumers remain separate work.
+
+## Contract
+
+`VisualFrame::new` admits finite, nonzero, perpendicular normal/tangent inputs,
+normalizes them, and constructs a right-handed visual frame. This is not a physical
+material-axis assignment. An original geometric normal is supplied separately;
+response and reflected samples reject either hemisphere when appropriate.
+
+Both perceptual roughness axes use the opaque surface range `[0.045, 1]`; alpha is
+roughness squared. Linear-sRGB reflectance, metal fraction and dielectric IOR use
+the existing `OpaqueSurface` admission. Invalid data is refused, not clamped.
+Equal roughness axes preserve the isotropic opaque BRDF contract exactly.
+
+Sampling uses the projected **normal distribution (NDF)**, not a visible-normal
+sampler. `normal_pdf` is `D(h) * n.h`; the unconditional reflected-direction PDF
+includes the `1 / (4 * v.h)` Jacobian. A rejected microfacet is a null event that
+must remain in the sample denominator. Never retry until a sample succeeds.
+Reflection weights contain the specular component only. Diffuse/environment
+mixtures, visibility, ray spawning, image budgets and multiple scattering belong
+to the consumer; this module does not claim to implement them.
+
+The implementation is original Rust using elementary GGX/Smith/Schlick equations.
+The public mathematical reference is Heitz, JCGT 7(4), 2018, equations 1 and 2:
+https://jcgt.org/published/0007/04/01/. No external implementation was adapted.
+
+## Reproduce the focused checks
+
+```sh
+cargo test --profile ci -p solidcraft-render --lib anisotropic_surface
+cargo clippy --profile ci -p solidcraft-render --all-targets -- -D warnings
+cargo check --target wasm32-unknown-unknown -p solidcraft-render
+```
+
+Analytic and deterministic quadrature tests cover hostile inputs, orthonormality,
+normal-incidence peaks, isotropic equivalence, reciprocity, 90-degree visual-axis
+rotation, geometric/shading hemisphere separation, grazing directions, inverse-CDF
+sampling, PDF/throughput agreement and retained null-event mass. Broad-lobe energy
+checks are scoped consistency tests, not universal energy certification, measured
+material data or evidence of an integrated rendered image.
diff --git a/docs/render-backends.md b/docs/render-backends.md
index e80878e5a4..a39faaf068 100644
--- a/docs/render-backends.md
+++ b/docs/render-backends.md
@@ -1,5 +1,7 @@
# Render backend capabilities (R1)
+Native progressive opaque PNG rendering is described in [Progressive product images](render-path.md). It registers alongside the CPU executor.
+
This page describes the R1 metadata contract. The installed GPU viewport and CPU
product-job hosts extend it through complete profiles; HDR input preparation adds
no lighting capability. See [the integrated phase boundaries](render-integration.md).
diff --git a/docs/render-clear-coat.md b/docs/render-clear-coat.md
new file mode 100644
index 0000000000..4d7c60fae1
--- /dev/null
+++ b/docs/render-clear-coat.md
@@ -0,0 +1,53 @@
+# Runtime clear coat
+
+Progressive image jobs accept an independent dielectric GGX coat over an opaque
+metallic/roughness substrate. A dark, moderately rough plastic base with a smooth
+coat can show narrow softbox reflections while retaining a dark body. Chrome uses
+the existing metallic surface; it does not need a coat.
+
+```json
+{"command":"render.start","params":{"progressive":true,"raytrace":{"clear_coats":[{"body_index":0,"body_name":"Housing","weight":1,"roughness":0.12,"ior":1.5}]}}}
+```
+
+`render.preflight` accepts the same override. Index and exact name must both match
+the captured `render.scene` body. At most 64 distinct bodies can be overridden.
+Weight is finite in [0,1], perceptual roughness in [0.045,1], and relative IOR in
+[1,3]. Unknown fields and repeated indices are errors. Weight zero is a no-op.
+Coats cannot be combined with runtime transmission on the same body. Overrides
+apply to the body and its faces in the job snapshot, never to the saved document,
+preview, undo history or appearance format. They require progressive rendering.
+
+The implementation adds single-scattering GGX/Smith coat reflection with its own
+Schlick Fresnel term. For cosine `c`, define the conservative directional bound
+`B(c) = Fcoat(c / sqrt(2 * (1 + sqrt(1 - c*c))))`. The base BRDF is multiplied by
+`(1-weight*B(N.V))*(1-weight*B(N.L))`. This is deliberately stronger attenuation
+than macro-normal Fresnel, which can leak energy with rough coats over shiny bases.
+
+For any reflected upper-hemisphere direction, the view/half-vector cosine is at
+least the argument used in B. Schlick decreases with cosine, and a unit-Fresnel
+single-scattering Smith GGX lobe reflects at most one. Thus the coat contributes
+at most `weight*B(N.V)`; the attenuated unit-energy base contributes at most
+`1-weight*B(N.V)`. The symmetric product retains reciprocity. This conservative
+allocation can darken grazing views and omits internal inter-layer scattering and
+refracted substrate directions; it is not a full layered transport solution.
+Importance-sampled f64 furnace quadrature covers shiny bases, rough coats, partial
+weights, IORs and grazing directions, alongside analytic and reciprocity checks.
+
+Continuation selects the coat GGX lobe with probability `weight/2`, otherwise the
+existing equal cosine/GGX base mixture. Evaluation uses the complete layered BRDF;
+the PDF is the same combined mixture for continuation and direct-light MIS. GGX
+samples below the surface are rejected without renormalizing the PDF. Zero weight
+preserves the old BRDF and random-number consumption exactly. GPU BRDF/PDF tests
+compare the production shader to the independent f64 numerical contract, including
+roughness 0.045 and grazing directions.
+
+The per-triangle resolved material occupies 64 bytes, including a 16-byte coat
+record. Storage-limit checks and peak-memory estimates include this additional
+record.
+
+The model was designed from the public descriptions of
+[layered materials in PBRT](https://pbr-book.org/4ed/Light_Transport_II_Volume_Rendering/Scattering_from_Layered_Materials)
+and [Filament's clear-coat model](https://google.github.io/filament/main/filament.html#materialsystem/clearcoatmodel).
+These motivate independent interfaces and substrate attenuation; this implementation
+is original and deliberately simpler than a multilayer random walk. No reference
+implementation source was copied.
diff --git a/docs/render-denoise.md b/docs/render-denoise.md
new file mode 100644
index 0000000000..d50a293fc0
--- /dev/null
+++ b/docs/render-denoise.md
@@ -0,0 +1,51 @@
+# Optional spatial denoising
+
+Native progressive GPU image requests accept `"denoise": true`. Omission and
+explicit `false` preserve the existing raw image path and allocate no denoising
+buffers or pipelines. This runtime flag is not stored in designs or appearances.
+The request is rejected on non-progressive or non-GPU executors.
+
+The optional final pass runs after all requested path samples, on linear
+premultiplied radiance, before the existing single exposure/tone-map/sRGB output
+step. It never changes the raw linear accumulator or the path random-number
+stream. Raw radiance and medium diagnostics are checked first, so denoising
+cannot conceal a failed glass path. To retain both raw and filtered PNGs, submit
+two otherwise identical jobs with the flag false and true respectively.
+
+The original implementation uses three edge-aware a-trous passes with pixel
+steps 1, 2 and 4 and the separable five-tap kernel [1,4,6,4,1]. It is inspired by
+the published method of [Dammertz, Sewtz, Hanika and Lensch, HPG 2010](https://holger.dammertz.org/publications/dammertz10hpg_bibtex.html).
+No third-party filtering source or weights are copied. A deterministic pixel-centre
+ray supplies textured albedo, shading normal, body identity, world position and
+depth. Bilateral weights use albedo difference, normal agreement, distance from
+the local tangent planes, axial depth difference, and radiance contrast. Spatial thresholds scale with
+the projected pixel footprint. Every pass retains the original alpha; the
+online convex average avoids overflowing radiance multiplied by kernel weights.
+
+First-hit guides cannot describe an image seen through refraction or a sharp
+reflection. Pixels first hitting glass, metals with roughness below 0.25,
+near-mirror coats with roughness below 0.05, light emitters, background or
+partial coverage bypass the filter. Glossier coats are filtered: on the studio
+coffee scenes their broad reflections of the cyclorama and area lights keep
+their shape, while the grain from choosing between coat and base layers is
+removed. A coat reflecting fine detail can lose some of it. First-hit guides also do not model depth-of-field correspondences:
+the centre lens ray is used, so out-of-focus boundaries may retain noise or
+acquire spatial bias. Rough glossy effects and soft shadows can lose detail.
+This is a biased, optional spatial filter, not a temporal or learned denoiser,
+and it cannot guarantee preservation of every lighting or texture feature.
+
+Preflight includes the enabled method, three passes, guide policy, bypass cases
+and these limitations. The job options retain the explicit flag. A job admits
+80 additional GPU bytes per pixel only when enabled: 48 for guides and 32 for
+two colour buffers. The 512 MiB job estimate and each device storage-binding
+limit apply. At 1920x1080 the guide buffer is 99,532,800 bytes; larger dimensions
+may be rejected before allocation rather than silently reducing resolution.
+The guide pass reuses the existing six-storage-buffer path layout; the filter
+needs three storage buffers. Cancellation is checked between bounded tiles.
+
+Regression coverage includes an independent f64 gather oracle, constant-image
+and coverage identity, checker noise reduction, albedo/normal/depth/body edge
+preservation, synthetic GPU/oracle agreement, production centre-ray guides,
+default/explicit-false image identity, raw-buffer preservation, admission and
+runtime preflight behaviour. GPU checks must be run on the target backends;
+source-level and shader validation alone do not establish rendered quality.
diff --git a/docs/render-environment.md b/docs/render-environment.md
new file mode 100644
index 0000000000..c508f6817e
--- /dev/null
+++ b/docs/render-environment.md
@@ -0,0 +1,102 @@
+# Runtime sun and environment lighting
+
+These controls extend progressive image jobs. They do not change the saved design,
+its render setups, the viewport lighting, or the legacy default render.
+
+An original artistic sky is available without downloading an image:
+
+```json
+{
+ "progressive": true,
+ "samples": 256,
+ "max_depth": 8,
+ "environment": {
+ "kind": "sky",
+ "gradient": {"zenith": [0.16, 0.32, 0.7], "horizon": [0.8, 0.9, 1.0], "ground": [0.12, 0.1, 0.08]},
+ "intensity": 1,
+ "rotation_rad": 0
+ },
+ "lighting": {
+ "sun": {"direction": [-0.4, -0.6, 0.7], "angular_radius_rad": 0.02, "radiance": [1000, 950, 850]}
+ },
+ "tone_map": "aces_fitted"
+}
+```
+
+The gradient is an original horizon-to-zenith/ground interpolation, sampled to
+512x256. It is an artistic environment, not a calibrated atmospheric model.
+Sun direction points toward the light. Its finite angular disk has uniform linear
+RGB radiance and supports radii 0.001..pi/2 radians. Increasing radius at fixed
+radiance increases total illumination; the cone's solid angle is
+`4*pi*sin(radius/2)^2`. The sun is a separate additive emitter, so a sun already
+present in an HDR image is not automatically removed.
+
+For a captured Radiance HDR file, replace the environment object with:
+
+```json
+{"kind": "hdr", "path": "original-studio.hdr", "assume_linear_srgb": true, "rotation_rad": 0.3, "intensity": 1}
+```
+
+Input is bounded to 16 MiB encoded, 2048x1024, 2:1 equirectangular and the standard
+`-Y +X` orientation. Header exposure and channel corrections are applied by the
+existing decoder. Declared primaries must be sRGB/D65. A source without primaries
+requires explicit `assume_linear_srgb: true`; this is an interpretation choice,
+not colour conversion. Other declared primaries are rejected even when that flag
+is set. No HDR values are tone mapped before lighting. Intensity is 0..100 and
+rotation is a finite bounded angle in radians about Z.
+
+Equirectangular +Z is the north pole, -Z the south pole. Column zero begins at +X;
+columns run toward +Y. Positive rotation turns the image about +Z. Horizontal
+coordinates wrap; polar rows do not repeat. Map radiance replaces the constant
+`lighting.environment` when a map is supplied. Rectangle and sun emitters remain
+additive. The camera backplate remains the request's background; environment
+radiance appears through surface lighting, reflections and refractions.
+
+The CLI accepts `--progressive --environment FILE.json`; that small JSON file
+contains the environment object above. `--lighting FILE.json` supplies the sun
+and/or rectangle lighting object. The engine captures bounded file bytes through
+its scoped VFS. Queued jobs own immutable shared bytes and never reopen paths.
+Preflight reports source SHA-256, dimensions and colour policy. A later start is a
+new capture; compare its descriptor if a source file may have changed.
+
+## Sampling and bounded preparation
+
+The worker uses the existing cooperative HDR decoder, then builds an alias table
+from luminance times exact texel solid angle. A row's solid angle per texel is
+`(2*pi/width)*(cos(theta_top)-cos(theta_bottom))`, evaluated with a stable sine
+identity near the poles. Within a selected texel, azimuth and cosine of polar
+angle are sampled uniformly. The directional density is texel probability divided
+by solid angle. Radiance uses the same piecewise-constant texel mapping. A black
+image uses a uniform distribution with zero emitted radiance. Independent random
+variates select the alias bucket and coin; sharing one 24-bit variate would bias
+large maps.
+
+The sun samples its cone uniformly. Environment and sun are sampled separately,
+and each escaped BSDF ray receives each emitter's radiance with its own matching
+power-heuristic weight. The existing opaque-branch, delta-event and final-bounce
+rules apply. Thin-sheet branch densities multiply the competing BSDF density;
+connections that exhaust the remaining depth use NEE only. Enabled straight
+solid-shadow connections also use NEE only, with their transmitted emitter hits
+suppressed to avoid double counting, as described in `render-glass-shadows.md`.
+This extends the original estimator from
+[PBRT fourth edition, sections 12.5](https://pbr-book.org/4ed/Light_Sources/Infinite_Area_Lights)
+and [13.4](https://pbr-book.org/4ed/Light_Transport_I_Surface_Reflection/A_Better_Path_Tracer);
+no PBRT source or images are copied.
+
+GPU storage uses one additional binding, 32 bytes per texel plus a 16-byte header.
+Admission conservatively adds retained encoded-buffer capacity, 160 bytes per texel and 64 KiB to the
+job's existing estimate for decoded/table/work/staging/device buffers. Device
+binding limits and the existing 512 MiB job limit also apply. Preparation checks
+cancellation while decoding, generating rows, building tables and staging uploads.
+CPU product rendering rejects environment resources explicitly.
+
+Tests use original in-memory RGBE fixtures and the generated gradient. They cover
+colour policy, malformed inputs, cancellation, polar/seam lookup, PDF normalization,
+unequal-mass sampling frequencies, resource admission, furnace consistency, sun
+cone quadrature and immutable engine preflight. No third-party HDRI or material
+assets are bundled. Original fixture generators live in `examples/studio/textures`;
+planar runtime colour/normal mapping is described in `render-runtime-textures.md`.
+
+The showcase PNG maps and RGBE gradient are generated locally before replay with
+`python examples/studio/author_showcase.py`. Image outputs are ignored and are not
+committed source assets; the recipes, generators and provenance remain editable.
diff --git a/docs/render-film.md b/docs/render-film.md
new file mode 100644
index 0000000000..32590e742f
--- /dev/null
+++ b/docs/render-film.md
@@ -0,0 +1,13 @@
+# Bounded linear film accumulation
+
+`solidcraft_render::film` is the independent accumulator for #1696. It is extracted from the original renderer donor at `3b892eab`; it does not install a CPU integrator, PNG resolver, camera coverage buffer or progressive UI.
+
+Samples are nonnegative finite linear RGB. Per-pixel running means and unbiased sample variance remain linear: no exposure, denoising, tone mapping or display conversion occurs here. A later consumer applies its output transform exactly once after resolving a complete pass. Sample order is significant; splitting the same ordered samples into bounded contiguous calls preserves identical results, while arbitrary floating-point reordering is not promised.
+
+The caller reserves `required_bytes` in the existing image-job lease and retains it throughout the film lifetime. Allocation is fallible and actual capacity is checked. Dimensions, pixel count, sample count, storage and update sizes are bounded. This module creates no second pool, thread, cache or cancellation token. Initialization and updates debit the same caller-provided cumulative work budget.
+
+`add_range` stages at most 256 pixel updates before committing. Invalid input, range/count overflow, exhausted work or cancellation before the bounded commit leaves prior pixels unchanged; consumed work is not refunded. Cancellation after commit must still be checked by the consumer before publication.
+
+`complete_pass` refuses empty or uneven sample counts and returns an immutable borrowed view, not an owned or publishable image. The caller must separately admit any output snapshot and enforce its existing generation/cancellation publication lock. Camera background coverage and actual progressive image delivery remain separate integration work.
+
+No design data is newly saved, so no format descriptor is introduced. No extra dependency, asset, geometry operation or renderer capability is advertised.
diff --git a/docs/render-glass-boundaries.md b/docs/render-glass-boundaries.md
new file mode 100644
index 0000000000..0ed663d97a
--- /dev/null
+++ b/docs/render-glass-boundaries.md
@@ -0,0 +1,149 @@
+# Closed-glass ray boundaries
+
+Closed dielectrics use the uploaded triangle boundary for medium transitions.
+A path that cannot classify its medium (an escape while inside glass, an exit
+with no matching entry, or an entry while already inside) ends there, keeping
+only the light it had already gathered; it is never converted into transparent
+background. Each job counts these paths. A handful at the limits of f32
+geometry (a few per billion on the captured 69-body tumbler scene) are logged
+and tolerated; more than one in a million paths fails the job with the first
+failure's pixel, bounce, sample and code. A camera inside glass, open meshes or
+overlapping solids fail every affected path and therefore the job.
+
+Surfaces may touch closed glass, as a tumbler resting on a table does. The
+offset launch from such a surface can start inside the glass, so its first
+crossing is an exit. A ray launched from an opaque or thin-sheet surface whose
+first crossing exits a closed body starts in that body's medium, with Beer
+absorption from the launch point; shadow connections do the same. Camera rays
+and closed-glass continuations that meet an unmatched exit are still errors.
+
+A scene-wide normal offset and positive minimum distance are unsuitable for a
+closed volume: near a sharp rim they can jump across the next face or discard a
+valid short exit. Closed-glass continuation instead starts at an affine
+barycentric surface point, excludes its producing boundary, and considers every
+strictly positive intersection. Primary rays and opaque/thin-sheet launch policy
+remain separate. Finite emitters use the same minimum distance as the continued
+ray. Beer attenuation measures between physical surface points.
+
+Triangle candidates first undergo an exact coordinate-bound test: when the ray
+is on or outside a stored coordinate bound and moves away, no positive hit is
+possible. This uses comparisons, without an epsilon or rounded division. It
+prevents cancellation in a projected intersection from turning a behind-origin
+intersection into a false forward hit. This check is narrower than the padded
+BVH broad phase.
+
+The producing boundary is an exactly coplanar, edge-connected patch within one
+body, computed from the positions actually uploaded as f32. Adaptive exact
+predicates distinguish a plane from even an arbitrarily shallow bend; nearby
+parallel faces and disconnected surfaces retain separate identities. Excluding
+only this patch avoids a rounded surface point re-hitting its own plane at a
+grazing angle. Patch identities add four bytes per triangle and their preparation
+storage is included in admission. Nonmanifold or collapsed adjacency is not used
+to infer a patch.
+
+Projected edge determinants use a compensated difference of products. This
+avoids losing exact shared-edge cancellation on tested GPU compilers. The
+algorithm follows the arithmetic described by
+[Matt Pharr's discussion of Kahan's difference of products](https://pharr.org/matt/blog/2019/11/03/difference-of-floats).
+WGSL [floating-point evaluation rules](https://www.w3.org/TR/WGSL/#floating-point-evaluation)
+permit implementation variation, including expansion of `fma`; backend tests
+are required, and this is not a proof of exact intersection for all WGSL devices.
+
+Hit depth also uses an affine base plus local vertex-edge increments. Summing
+three weighted distances can round a distant sharp-rim entry and exit to the
+same value and let traversal order choose the exit first. The captured coffee
+ray has real crossings separated by 0.00010076 mm at about 929.52 mm distance;
+its regression covers all axis permutations, coordinate reflections and both
+triangle orders. This improves distance ordering without treating an unmatched
+medium exit as transparent.
+
+Candidates are ordered by that dominant-axis depth before it is scaled into a
+ray distance. Scaling can round two different depths to one distance: a
+captured 64-sample coffee camera ray crosses a bin rim at ray parameters
+1124.0922606 and 1124.0923199, under one f32 ULP apart. The two depths still
+differed by one ULP, but both scaled distances were equal. Traversal order then
+picked the exit, and the path stopped at the medium gate. On an exact depth tie
+the hit that changes the current medium state wins: the entry face from
+outside, the exit face from inside. A ray through the shared rim edge itself
+exercises that rule. Traversal order never decides between them.
+
+The regression fixtures distinguish short real exits, a normal offset crossing a
+sloped adjacent face, exact diagonal hits, and a captured impossible hit at a
+polygon edge. Original editable CAD renders exercise hollow walls and repeated
+reflection/refraction through the production command and job interfaces.
+
+## Candidate anchor and local-offset continuation
+
+A rounded world-space hit point can lie outside a sharp rib even when all three
+barycentric weights are valid. The candidate continuation representation keeps
+the dominant stored vertex as an anchor and keeps the two weighted edge
+increments as a separate local offset. It is an anchor plus displacement, not an
+error-free two-float expansion. All three barycentric weights are retained
+directly; recovering a small weight as `1-u-v` can erase corner clearance.
+
+Ordinary floating expressions do not establish an evaluation barrier under
+WGSL. In the captured rib case, the compiler transformed a relative expression
+equivalent to `(vertex-anchor)-offset` into subtraction from a rounded world
+point. A float TwoSum/FMA residual formulation also lost its residual on that
+backend. The candidate therefore evaluates nonzero-offset point deltas using
+integer-defined binary32 addition and subtraction: align significands with a
+sticky bit, normalize, and round to nearest with ties to even. The sequence is
+`RTE(RTE(a-b)+RTE(a_offset-b_offset))`. No floating reassociation can change those
+integer rounding boundaries. Zero-offset rays retain the existing floating
+path. Integer bit results include subnormals; later floating consumers remain
+subject to WGSL's allowed subnormal handling.
+
+The candidate routes triangle coordinate bounds, relative vertices and hit depth
+of triangles near the origin, analytic emitter intersections, and physical-point
+Beer distances through this representation. Traversal itself does not: BVH boxes
+are tested in ordinary arithmetic from the rounded origin `anchor+offset`, grown
+by the scene broad-phase pad plus `2^-20` of the origin's largest coordinate
+magnitude (several ULPs, covering the rounding of that origin). Every point the
+true ray reaches at depth `t` lies in the grown box along the rounded ray at the
+same `t`, so box rejection stays conservative. A triangle whose stored bounds
+are separated from the rounded origin by more than `2^-8` of that magnitude on
+some axis (about 4 mm at 1 m) uses the ordinary intersection from the rounded
+origin: an origin error of a few ULPs cannot reorder a hit that far away.
+It can still move the ray across an edge. In a concave rib, a ray leaving
+through one face can re-enter the next face within micrometres of their shared
+edge. The far face, tested from the rounded origin, then reported a miss
+just outside that edge, while the nearby face across it, tested exactly from
+the true origin, correctly missed too, so the re-entry was lost (captured at
+256 spp: bounce 5, code 2). Far
+candidates whose bound or edge decision lies within `2^-20` of the origin
+magnitude, scaled by the projected edge length, therefore also take the exact
+path. Only those and the nearby triangles, which include every sharp-rib exit,
+use the integer-defined deltas. On the exploded coffee machine at 1080p
+and 8 samples per pixel this cuts closed-glass time on an NVIDIA GB10 from
+43.5 s to 5.7 s (opaque: 5.2 s); 3 of 2,073,600 pixels differ from the
+all-exact result, by at most 6/255. For a finite emitter, it first subtracts the
+previous physical point from the ray origin and then adds the ray segment `d*t`.
+It does not add a short segment into a large local offset and subtract that
+offset again. Area-light density uses the same resulting physical segment.
+
+This is a specified sequence of rounded operations, not an exact four-term sum
+or a universal watertightness proof. In particular, a large anchor difference
+followed by cancellation against the offset may still lose small information;
+edge projection, barycentric evaluation, and local-offset construction also
+retain ordinary floating arithmetic. Acceptance requires the integer bit oracle,
+captured rib/corner regressions, and production renders on each supported
+backend. These candidate notes do not claim those checks have passed.
+
+A closed-glass continuation within `1e-6` of tangent to its producing face
+ends the path. It skims that face, and the rounding of its reconstructed start
+point (a few `1e-8` mm on the captured 69-body tumbler scene) then decides
+which side of the neighbouring faces it is on. The captured ray left a face at
+a cosine of `4e-8` while inside a glass, and then entered the adjacent face of
+the same glass from outside at a shared edge. Those directions carry about a
+millionth of the hemisphere's projected solid angle; ending them removes
+negligible energy, not a classified medium error.
+
+The bounded opt-in glass shadow connection uses the same unshifted, zero-minimum continuation and exact producing-plane exclusion at closed interfaces. Thin-sheet shadow traversal retains its existing offset policy. A corner oracle checks a real exit shorter than the old global minimum while retaining both Fresnel interface factors and Beer attenuation.
+
+Closed shadow continuation also retains the stored anchor and local offset. It
+uses the same integer-defined point deltas for bounds, interfaces and Beer
+segments. For a finite endpoint inside a medium, attenuation uses the current
+ray-origin-to-entry difference plus the remaining ray segment; it does not form
+a rounded world endpoint. Geometry crossings are tested up to the true endpoint,
+without applying the separate analytic-emitter self-intersection allowance.
+The scatter history used by area-light MIS carries its associated local offset.
diff --git a/docs/render-glass-shadows.md b/docs/render-glass-shadows.md
new file mode 100644
index 0000000000..bdd00b86c3
--- /dev/null
+++ b/docs/render-glass-shadows.md
@@ -0,0 +1,65 @@
+# Glass shadow connections
+
+Runtime dielectric overrides accept optional `shadow_transmission: true|false`.
+Thin sheets default to true. Closed boxes and meshes default to false and opt in
+explicitly. This changes only a progressive job's captured optical data; document
+formats, saved appearances and scalar preview opacity are unchanged.
+
+```json
+{"progressive":true,"raytrace":{"dielectrics":[{"body_index":0,"body_name":"Glass","ior":1.5,"absorption_per_mm":[0.02,0.005,0],"boundary":"closed_mesh","thickness_mm":0,"shadow_transmission":true}]}}
+```
+
+Direct lighting traverses at most 64 dielectric interfaces before the emitter.
+It uses the closest hit, so geometry beyond a finite light does not shadow it.
+Opaque and disabled interfaces block. Unmatched exits, overlapping active media,
+an unclosed infinite connection, or an exhausted interface budget also block.
+A direct shadow connection starting at an opaque surface inside an active solid
+is currently unsupported and conservatively blocks at the unmatched exit. Such
+embedded opaque receivers should use disabled solid shadow transmission; they
+are outside the enabled solid approximation contract.
+The existing host topology/disjoint-volume admission remains in force. Coincident
+or sub-offset sheets are outside the existing ray-offset precision contract.
+
+For a thin sheet the connection multiplies the existing exact unpolarized slab
+transmittance, including Beer absorption along thickness/refracted cosine and
+repeated internal reflections summed separately for s/p polarization. The path
+direction stays straight. Light MIS and BSDF emitter hits use the same mixture
+PDF, including each sheet's transmission branch probability. The last opaque
+scattering point is kept separately from the Beer segment origin. Reflection
+starts a delta path; straight enabled sheet transmission preserves the MIS
+history. If the remaining path depth cannot traverse all sheets and reach the
+emitter, the light technique gets weight one. This avoids both double counting
+and losing energy at the depth limit.
+
+An opted-in solid uses an explicitly approximate straight connection. It applies
+reciprocal external-angle Fresnel at each interface and Beer absorption over the
+actual, unshifted geometric entry/exit distance. For a finite emitter inside a
+certified volume only the partial distance to that emitter is absorbed, and the
+uncancelled radiance factor `1 / ior^2` is retained. The physical endpoint is kept
+separate from the offset visibility cutoff. Applying
+inside critical angles to an unrefracted shadow ray would create artificial TIR,
+so the shadow approximation uses air-to-solid Fresnel at both boundaries.
+
+Solid direct transmission is **NEE only**: the direct connection gets weight one,
+and an opaque-bounce path transmitted through an enabled solid does not also add
+emitter/environment emission. Camera paths and paths after dielectric reflection
+retain the physical Snell/Fresnel transport. Another opaque hit starts a new direct
+lighting estimate. This approximation deliberately replaces transmitted direct
+caustic paths; it does not simulate focusing, caustics, refracted light silhouettes
+or internal multi-bounce transmission for direct lighting. Disable solid shadow
+transmission to retain the previous physical path estimator.
+
+Tests cover normal/oblique slab RGB against f64 Fresnel/Beer oracles, finite
+endpoints before/inside/beyond glass, disabled/opaque blockers, unmatched exits,
+stacked sheet PDFs, the 64/65 crossing boundary, and index-matched thin/solid
+fixtures at several path depths that reject doubled direct energy. The independent
+CPU oracle also checks reciprocity, defaults, hostile values and finite grazing
+behavior. GPU execution must be validated separately on available adapters;
+final combined backend and showcase acceptance remains incomplete.
+
+The estimator follows the public mathematical description of
+[multiple importance sampling in PBRT](https://pbr-book.org/4ed/Light_Transport_I_Surface_Reflection/A_Better_Path_Tracer).
+The straight solid policy is an explicit SolidCraft preview approximation, not a
+claim made by that reference. No reference source code was copied.
+
+Medium crossings are tested against the true finite endpoint distance. The analytic area-emitter self-hit tolerance is separate and does not shorten the geometric connection; exits or entries arbitrarily close before the endpoint still change its medium and radiance factor.
diff --git a/docs/render-integration.md b/docs/render-integration.md
index f964acf235..7a097cdb41 100644
--- a/docs/render-integration.md
+++ b/docs/render-integration.md
@@ -1,5 +1,7 @@
# Phased render and material integration
+Native progressive opaque PNG rendering is described in [Progressive product images](render-path.md). It registers alongside the CPU executor.
+
Tracked in #842, with parent render design #620 and physical/visual material roadmap
#922. The combined integration keeps contribution ancestry; it is an alternative
review path, not evidence that the individual PRs have merged. Each result in GitHub
diff --git a/docs/render-jobs.md b/docs/render-jobs.md
index 4bd8a69a73..423d405eb4 100644
--- a/docs/render-jobs.md
+++ b/docs/render-jobs.md
@@ -1,5 +1,7 @@
# Product-image jobs (R4a)
+Native progressive opaque PNG rendering is described in [Progressive product images](render-path.md). It registers alongside the CPU executor.
+
R4a adds bounded CPU preview images to the Render workspace. The installed `builtin` /
`cpu-product` executor supports Preview, Image and PNG. It does not promise refraction,
HDRI, exposure, final mode or EXR; those requests fail explicitly. The subsequent
diff --git a/docs/render-path.md b/docs/render-path.md
new file mode 100644
index 0000000000..bc4554caf1
--- /dev/null
+++ b/docs/render-path.md
@@ -0,0 +1,155 @@
+# Progressive product images
+
+This integration is a draft. Final combined CPU, wasm and GPU verification and
+full-resolution showcase acceptance remain incomplete. Test descriptions below
+state intended coverage, not a claim that every backend has passed.
+
+Native applications can register `solidcraft_gpu::path::host()` alongside the
+existing CPU image host. `render.backends` then exposes `builtin/gpu-path` with
+Preview, Image, PNG, Pbr, Progressive and Refraction. The browser keeps its CPU image host.
+Device discovery follows `SOLIDCRAFT_GPU` and `WGPU_BACKEND`; a device which cannot
+create the compute pipeline does not register an available path executor.
+The native UI retains a factory for the viewport's selected adapter at installation,
+without opening another device or compiling path shaders in Design (including safe-mode startup).
+The first entry into Render starts preparation once, asynchronously; if the viewport arrives
+later, that installation starts the already-requested preparation. Document changes retain
+the pending/ready/failed host, and failures are not retried on each viewport installation.
+It opens its independent job device on the viewport's selected adapter,
+so software fallback and safe mode do not rediscover a failing hardware driver.
+An incompatible explicit GPU policy leaves progressive rendering unavailable there.
+The path tracer runs on Vulkan only (#3217). A viewport on D3D12 is reopened on the
+same GPU through Vulkan. Where there is no Vulkan driver (macOS for now, Windows over
+Remote Desktop or on the WARP software adapter, older drivers), the path executor reports
+itself unavailable and images render on the CPU. On an RTX 4090, D3D12 was never faster:
+equal per sample with DXC and about 55% slower with FXC, and it compiles the path shader
+at every start (about 82 s with DXC, about 2 hours with FXC), where Vulkan's compiled
+pipelines persist between runs.
+
+In the Render workspace, enable **Progressive rendering** and select samples per
+pixel before checking or starting an image. These controls are transient image-job
+intent. Existing saved setup/camera/material formats are unchanged.
+The interactive canvas keeps its existing product preview; this first image-job
+integration reports sample progress and exports the completed PNG, without displaying
+partial accumulation buffers on the canvas.
+
+```json
+{"command":"render.start","params":{"settings":{"width":800,"height":600,"exposure_ev":0},"progressive":true,"samples":64,"max_depth":8,"seed":0}}
+```
+
+`render.preflight` accepts the same input. It resolves the Progressive capability
+to the installed GPU host and performs admission without reserving memory. Start
+checks again and returns the existing session/serial/generation identity. Progress
+reports complete samples per pixel; a partially computed sample is not counted.
+Cancel, status, retained-image ownership and atomic PNG export use the same host
+protocol as CPU jobs. Defaults are 64 samples, depth 8 and seed 0; the bounds are
+1–4096 samples and 1–16 bounces. Sampling controls require `progressive: true`.
+
+Runtime request-only [glass overrides](render-transmission.md) and an optional
+[thin-lens camera](render-thin-lens.md) and [clear coat](render-clear-coat.md) are available through those same commands.
+Neither adds saved document fields. Positive aperture requires perspective.
+
+```sh
+solidcraft-cli render examples/render-path-studio.json --out enclosure.png --progressive --samples 64 --max-depth 8 --seed 0 --width 800 --height 600
+```
+
+The CLI explicitly fails if a progressive request has no suitable device. Ordinary
+CPU requests retain their prior behavior. GPU PNG export averages linear radiance,
+applies saved exposure and the selected tone map (Reinhard by default), then
+encodes sRGB once. Runtime `aces_fitted` is described in
+[studio lighting](render-studio-lighting.md). A
+transparent background uses straight alpha; background color is independent of
+illumination.
+
+The original integrator uses software BVH traversal, opaque GGX/Smith/Schlick and
+the symmetric diffuse attenuation defined by `render::surface`. Each hit evaluates
+the three existing directional studio lights with shadow visibility. Continuation
+samples a mixture of cosine-weighted diffuse and GGX normals with the combined
+PDF; Russian roulette begins after four hits. There are indirect bounces, but no
+environment illumination in the default legacy lighting profile. All legacy opaque colors use
+linear-sRGB base color, metallic 0, roughness 0.5, IOR 1.5. Explicit face appearances
+take precedence over body appearances.
+
+Explicit optical appearances can now select smooth dielectric reflection,
+refraction, Beer–Lambert absorption and ideal thin sheets; see
+[the transmission contract](render-transmission.md). Preview opacity remains a
+separate scalar-alpha approximation. Opacity below one without an explicit
+transmission record is rejected by the path executor. Runtime
+[area lights](render-studio-lighting.md), [sun/HDR environment lighting](render-environment.md)
+and [opaque planar color/normal maps](render-runtime-textures.md) are available
+through explicit job inputs. They do not add saved document fields. Denoising,
+texture LOD/mipmap selection, EXR and Final mode remain unimplemented by this
+executor; a path-traced preview does not declare those capabilities.
+
+Each job builds a BVH over its immutable captured meshes with a sixteen-bin
+surface-area heuristic on triangle centres; there is no cross-document cache to
+confuse scene generations. A split is accepted only when a median split of its
+larger side would still keep the tree within 30 levels, the shader's 32-entry
+traversal stack; otherwise that node falls back to the median split. Traversal
+tests both child boxes at their parent and visits the nearer first. On the
+exploded coffee machine at 1080p and 8 samples per pixel, this halves render
+time on an NVIDIA GB10 (opaque 4.95 s to 2.49 s, closed glass 5.65 s to
+2.79 s) with bit-identical images. Positions are
+rebased around the camera target before f32 upload. The upload packs indexed 32-byte position/normal vertices, 16-byte triangle records
+(including material IDs), 64-byte resolved materials, four-byte planar patch IDs
+and 32-byte BVH nodes. Geometry arrays share one buffer. The progressive executor
+requires six storage buffers per stage for geometry, BVH, accumulation,
+environment, textures and medium-failure counts; raster device requirements remain unchanged.
+Geometry must be within 1e7 mm of the camera target. Opaque and thin-sheet ray
+offsets use max(1e-5 mm, extent × 1e-7); closed glass instead retains an anchor
+and local displacement with strictly positive intersections, as described in
+[closed-glass boundaries](render-glass-boundaries.md). These are bounded preview
+precision policies, not a robust CAD intersection oracle.
+
+Each GPU dispatch computes at most 262,144 pixel paths at one sample index. The
+worker waits for that dispatch before checking cancellation and issuing another.
+A driver wait has a 30-second timeout; cancellation cannot preempt a stalled GPU
+dispatch. Encoding yields every four rows. Invalid indices/normals, nonfinite
+geometry, excessive dimensions and sampling controls are errors.
+
+The GPU host admits at most 1,048,576 input triangles, 4096 pixels per side and
+4,194,304 pixels in all. The actual storage-buffer limit may lower these caps.
+The source geometry cap is 128 MiB and the per-host pool is 512 MiB, including
+retained PNG leases. Conservative estimates account for CPU BVH construction,
+serialized and device geometry, accumulation, readback, RGBA and PNG buffers.
+Allocator/driver bookkeeping is not an OS quota. CPU and GPU workers have separate
+pools and each retains the established two-entry queue bound; a document still
+has at most two live jobs across both executors.
+
+Validation lives in `gpu::path::tests` and engine render job tests. Set
+`SOLIDCRAFT_REQUIRE_GPU=1` to make absence of an adapter fail device tests rather
+than skip them. BRDF parity is checked against the f64 oracle with 0.3% relative
+plus 2e-5 absolute tolerance. The near-white furnace allows 0.07 absolute error:
+the existing single-scattering Schlick model is not a perfectly conserving pure
+Lambertian surface, even at IOR 1. Same-adapter determinism compares the actual
+linear buffers bit-for-bit; cross-adapter bitwise identity is not promised.
+
+The ignored `path_performance` test builds a 1,048,576-triangle procedural sphere
+and measures 1920×1080 dispatches, BVH construction and upload. Select sample count
+with `SOLIDCRAFT_PATH_BENCH_SAMPLES` (default 1). Run it explicitly with a clear GPU
+timing window; it is excluded from normal CI.
+
+## Dispatch and device-loss behavior
+
+Each new path job begins with 64 paths. Completed submissions target approximately
+20 ms and grow at most twofold, bounded to 64–16384 paths; a short image tail is
+smaller. Denoiser guide/filter passes use the same controller. Measured wall time
+includes scheduling contention, so this is a conservative responsiveness policy,
+not a promised GPU deadline or a substitute for the OS watchdog. Sample/seed and
+pixel identities are unchanged by tile boundaries.
+
+Actual device-loss callbacks, uncaptured device errors and failed completion waits
+retire that native executor. Existing and new jobs refuse further device work;
+preflight/session metadata reports it unavailable without inventing new capabilities.
+The application must deliberately recreate a host to recover. Merely registering the
+same cached host or opening another document does not advertise it as healthy again.
+
+
+### Shared index-matched base response
+
+The opaque base lobe uses the same Fresnel limit as `OpaqueSurface`: when the
+base IOR is exactly one, the dielectric fraction has no interface reflection at
+any angle. A metallic mixture retains its independently weighted conductor
+fraction. This applies to the specular term and both diffuse transmission factors.
+The existing actual-GPU BRDF oracle checks the limit at normal, oblique and grazing
+angles against the f64 surface, including mixed metallic values. Clear-coat and
+physical transmission contracts are unchanged by this base-lobe correction.
diff --git a/docs/render-runtime-textures.md b/docs/render-runtime-textures.md
new file mode 100644
index 0000000000..16aff9b6ad
--- /dev/null
+++ b/docs/render-runtime-textures.md
@@ -0,0 +1,54 @@
+# Runtime planar opaque maps
+
+Progressive GPU jobs accept immutable per-body base-color and OpenGL tangent-space
+normal maps. No document, appearance, recovery, or saved material format changes.
+Only explicit runtime commands capture file bytes; queued work does not reopen paths.
+
+```json
+{"progressive":true,"raytrace":{"textures":[{"body_index":3,"body_name":"Walnut tabletop","frame":{"origin":[0,0,480],"u":[900,0,0],"v":[0,90,0]},"base_color_srgb":"C:/art/wood.png","normal_opengl":"C:/art/wood-normal.png","normal_strength":0.35}]}}
+```
+
+Each `u` and `v` world-space vector spans one complete repeat, in millimetres. The
+vectors must be nonzero, orthogonal, and 0.001–1,000,000 mm long. The origin is UV
+zero. Image V increases downwards; normal red and green point along the positive
+projected U and V directions, with handedness preserved. Projection is planar,
+not triplanar: surfaces parallel to the projection axes may stretch. Each body's
+bounding-box corners must remain within ±128 repeats; the frame origin must be
+within 10 million mm of the camera target. These caps limit f32 coordinate loss.
+
+Base RGB is explicitly sRGB, converted to linear reflectance before bilinear
+filtering and multiplied by the body's linear base color. Use a white base to
+reproduce the map's color. Normal channels are untransformed linear data. Normal
+strength scales tangent XY in 0..1 before normalization; degenerate vectors, an
+invalid tangent projection, or a normal behind the geometric/view hemisphere
+fall back to the original shading normal. Alpha is ignored by this opaque-only
+consumer. Glass, scalar opacity, roughness, metalness, displacement, height and
+alpha maps are rejected or unsupported; they are not silently interpreted.
+
+Sampling uses bilinear level-zero periodic filtering at texel centers, including
+negative UV repeats. There is no mipmapping, anisotropic filter or UV mesh import
+in this increment, so fine distant patterns may alias. PNG/JPEG input is 8-bit,
+maximum 1024×1024 per map. Embedded ICC profiles and nonidentity orientation must
+be normalized beforehand; no implicit color-management guess is made. The sRGB
+base/data normal distinction follows the public
+[Khronos glTF material semantics](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#materials),
+without adopting its document format or copying implementation code.
+
+At most 16 exact name-and-index body bindings retain 16 MiB encoded capacity and
+32 MiB linear pixel data collectively. Admission counts captured bytes, codec
+scratch, normalized pixels, staging and device storage against the existing job
+budget. Codecs execute on the worker with cancellation checks before/after each
+bounded decode and during conversion/upload preparation. Public status contains
+metadata only; completion or cancellation releases captured source bytes even
+when callers retain job/status/frame handles. GPU preparation also releases
+source bytes after preparing the pixel buffer.
+
+The independent progressive device requests six storage buffers per shader
+stage. An adapter limited to fewer cannot install this executor; raster and
+tessellation device requirements remain unchanged.
+
+Independent f64 tests cover explicit sRGB decoding, linear normal channels,
+repeat filtering, handedness, degenerate fallback, admission and lifecycle.
+GPU reference tests compare the actual packed storage and WGSL sampler/normal
+frame against those CPU utilities. GPU execution and final visual evidence must
+be reported separately; source/shader validation alone is not rendering proof.
diff --git a/docs/render-starter-appearances.md b/docs/render-starter-appearances.md
new file mode 100644
index 0000000000..d44e18f662
--- /dev/null
+++ b/docs/render-starter-appearances.md
@@ -0,0 +1,30 @@
+# Original starter appearance recipes
+
+The existing `appearance.library` command lists 40 original illustrative recipes:
+34 opaque PBR appearances and six glass recipes that are explicitly unavailable
+through scalar appearance assignment. The 20 legacy scalar appearances are
+unchanged. The separate six-finish proposal is not included in this constituent.
+
+Use a stable `starter.*` ID with `appearance.assign` to request a recipe. Opaque
+presets become owned ordinary Look values; no external file, preset identifier or
+new document field is needed to reopen them. Color overrides retain an explicitly
+selected recipe response; `pbr: null` deliberately selects scalar shading.
+
+Glass recipes require a genuine certified refraction path. Color, PBR and opacity
+overrides do not bypass their refusal. They are not approximated by transparency.
+
+A copied look's `name` is inert data, distinct from the `appearance` selector.
+Catalog application uses that inert label and replaces the complete PBR value;
+a label matching an unavailable recipe cannot accidentally resolve that recipe.
+
+Recipes are MIT OR Apache-2.0 original optical authoring choices, not measured
+engineering grades. Visual edits do not change density, mass or geometry. Wood,
+solar and regolith entries are labelled uniform previews; their future texture
+metadata does not install textures, grain, displacement or electrical properties.
+
+This change uses existing appearance commands and persistence. It adds no image
+pack, runtime network access, new renderer, UI layout or manual format version.
+
+The Appearance dialog omits unavailable recipes from selectable swatches. Its
+Apply/OK/drop paths pass the complete owned look and an inert name, so editing a
+label that matches a recipe cannot silently re-resolve or change its response.
diff --git a/docs/render-studio-lighting.md b/docs/render-studio-lighting.md
new file mode 100644
index 0000000000..db1a252f84
--- /dev/null
+++ b/docs/render-studio-lighting.md
@@ -0,0 +1,69 @@
+# Runtime studio lighting
+
+`render.preflight` and `render.start` accept `lighting` and `tone_map` when
+`progressive: true`. They affect the captured job only: saving a design or render
+setup does not persist them. Omitting lighting retains the three legacy directional
+lights and their sample stream. Omitting tone_map retains Reinhard.
+
+```json
+{
+ "progressive": true,
+ "samples": 256,
+ "max_depth": 8,
+ "lighting": {
+ "environment": [0.5, 0.5, 0.5],
+ "area_lights": [
+ {"center": [-200, -150, 300], "u": [100, 0, 0], "v": [0, -80, 0], "radiance": [8, 8, 8]}
+ ]
+ },
+ "tone_map": "aces_fitted"
+}
+```
+
+All radiance is linear RGB, bounded to 0..1000000. Environment defaults to black;
+use equal RGB components for white illumination. The camera background remains
+the requested backplate. The environment illuminates surfaces and is visible in
+reflections/refractions. An empty lighting object makes an unlit studio.
+
+Each of at most four rectangles uses world-space millimetres. `u` and `v` are
+orthogonal half-edges, each 0.0001..1000000 mm long; the rectangle spans center
+plus/minus each half-edge. Its emitting side faces `u cross v`. Centers are finite
+and bounded to +/-1e12 mm. Rectangles are opaque, black on their back sides, visible
+to camera and reflected rays, and occlude other emitters. No lights are added to
+the model or product-scene body list.
+
+The CLI accepts `--progressive --lighting FILE.json --tone-map aces_fitted`.
+The file is the lighting object alone (at most 64 KiB); `reinhard` is the other
+accepted tone map. Exposure remains `--exposure EV`.
+
+## Estimator and output
+
+Every opaque hit samples each rectangle once in area and the constant environment
+once on the sphere. Rectangle density in solid angle is distance squared divided
+by area times the emitting cosine. The environment density is 1/(4*pi). These
+are combined with the BSDF continuation by the power heuristic on both direct
+samples and emitted radiance reached by continuation. Each light is sampled, so
+there is no light-selection probability. The actual opaque sampling density
+includes its (1 - transmission) branch probability. Delta events receive emission
+weight one. At the final allowed surface bounce, direct samples have weight one
+because there is no continuing BSDF sample. Shadow intersections stop at the
+sampled emitter; geometry beyond it cannot shadow it. See [glass shadow connections](render-glass-shadows.md) for thin-sheet MIS and
+the opt-in solid straight-through direct-light approximation.
+
+Accumulation stays linear. Only final output divides by coverage, applies exposure,
+then one selected tone map and sRGB encoding. `aces_fitted` uses Narkowicz's published
+rational fit; it is not the full ACES colour-management pipeline. The backplate
+compositing contract is unchanged.
+
+## References and validation
+
+The implementation is original from the estimator mathematics in
+[PBRT fourth edition, section 13.4](https://pbr-book.org/4ed/Light_Transport_I_Surface_Reflection/A_Better_Path_Tracer)
+and the published coefficients of
+[Narkowicz's 2016 curve](https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/).
+Tests compare rectangular illumination to independent f64 surface quadrature,
+exercise blockers before and beyond emitters, compare continuing and final-bounce
+MIS estimates with a white furnace, validate bounded requests, and check that
+preflight leaves the document unchanged. GPU tests require an actual supported
+adapter when SOLIDCRAFT_REQUIRE_GPU is set; no visual milestone is implied by these
+numerical tests.
diff --git a/docs/render-thin-lens.md b/docs/render-thin-lens.md
new file mode 100644
index 0000000000..378128b058
--- /dev/null
+++ b/docs/render-thin-lens.md
@@ -0,0 +1,69 @@
+# GPU depth of field
+
+`render.preflight` and `render.start` accept an optional runtime lens:
+
+```json
+{"progressive":true,"samples":256,
+ "lens":{"aperture_radius_mm":0.5,"focus_distance_mm":120}}
+```
+
+Use a perspective camera in `settings.camera` or the current view. Focus distance
+is measured from the eye along the forward axis, to a plane perpendicular to that
+axis. It is not distance along each ray. Aperture is the physical radius in mm,
+not an f-number. Units follow the scene; a radius of 0.5 mm is small for a room and
+large for a 3 mm object. No saved camera or render setup fields are added.
+
+A uniform-area circular aperture uses `r = radius * sqrt(u)` and `phi = 2*pi*v`.
+Each primary ray starts at that aperture point and aims at the pinhole ray's
+intersection with the focus plane. The image is the average of these radiance
+samples: changing aperture changes blur, not an aperture-area exposure factor.
+Exposure remains the existing explicit EV control. Circular bokeh has no blade
+shape, diffraction, lens distortion or chromatic aberration model.
+
+Omitting the lens or choosing radius zero preserves the existing pinhole or
+orthographic image bit-for-bit on the same adapter, including its random stream.
+Positive aperture requires perspective; orthographic requests fail admission.
+Radius is finite in [0, 1e7] mm and focus distance in [1e-6, 1e9] mm. Active lenses
+also require camera distance >= 1e-6 mm and tan(fov/2) in [1e-6, 1e6] to keep the
+f32 basis and focal point bounded. Existing image and scene caps still apply.
+The whole aperture must remain outside glass volumes, as must the pinhole camera.
+No UI lens editor or dedicated CLI flags are included; use the shared render
+commands through the control protocol, scripts or MCP.
+
+Tests read rays from the production WGSL camera function and compare against
+f64 geometric focus and defocus oracles, including an oblique rolled camera.
+At axial depth z, the displacement from a pinhole ray is
+`aperture_point * (1 - z/focus_distance)`: zero at focus, opposite-signed beyond it.
+Other tests cover strict admission, zero-aperture image identity and fixed-seed
+repeatability with an active lens. Glass evidence is an original procedural scene,
+with test-only uniform environment lighting, not a claim of HDRI implementation.
+
+## CPU draft coordination
+
+Read-only comparison: [CPU integration draft #1698](https://github.com/tangency-labs/solidcraft/pull/1698),
+head `463a3e0daaa6b84f169ba5f8f215fba4642c194a` (2026-10-17).
+No source from that draft is copied into this change.
+
+- `raytrace/reflection.rs` uses the existing opaque surface's Schlick Fresnel,
+ GGX NDF sampling and solid-angle PDF `D(h)*n.h/(4*v.h)`. Our opaque lobe already
+ shares that surface oracle; the GPU mixes GGX and cosine samples with equal
+ probability. CPU sample sequences differ, so comparisons are statistical.
+- The draft has no dielectric transport or thin-lens implementation to use as an
+ oracle. GPU glass retains the f64 Fresnel, Snell, slab and ball-lens checks.
+- Both intersections use dominant-axis projection, closed edges and two-sided
+ triangles. CPU uses f64 with outward representable bounds; GPU uses f32 after
+ target rebasing and conservative epsilon bounds. CPU secondary rays use a
+ component-wise barycentric error bound and outward representable steps; GPU
+ still uses max(1e-5 mm, scene extent * 1e-7). This precision difference is
+ explicit; no CPU/GPU intersection identity is claimed.
+- `lighting/environment_sampling.rs` defines +Z north, longitude atan2(y,x),
+ latitude acos(z), and inverse positive +Z rotation for lookup. The future GPU
+ environment adapter should use these conventions. CPU samples the sphere
+ uniformly with PDF 1/(4*pi); a GPU luminance CDF would use its own correctly
+ normalized solid-angle PDF and MIS. Neither is implemented by this lens change.
+- CPU accepts only explicitly declared sRGB/D65 HDR primaries. GPU HDR input
+ must honor that boundary or provide a separately validated gamut conversion.
+
+The agreed shared dielectric fields are IOR, linear RGB extinction per mm and
+thin-sheet thickness vs certified closed boundaries, identified by ordinal and name.
+Persistence belongs to the shared contract follow-up, not this GPU executor slice.
diff --git a/docs/render-transmission.md b/docs/render-transmission.md
new file mode 100644
index 0000000000..afc628461d
--- /dev/null
+++ b/docs/render-transmission.md
@@ -0,0 +1,93 @@
+# Runtime dielectric overrides
+
+The GPU executor uses the agreed shared CPU runtime contract from #1655 /
+#1659, coordinated in Mailbox 9063, 9068 and 9075. Its wire adapter is isolated in
+`crates/engine/src/cmd/render/transmission.rs` so the future shared type can replace it.
+No document format number, migration, appearance field or persistent material
+contract is added. The earlier experimental `pbr.transmission` proposal is removed.
+
+Pass this request to `render.preflight` or `render.start`:
+
+```json
+{"progressive":true,"raytrace":{"dielectrics":[{
+ "body_index":0,"body_name":"Glass","ior":1.5,
+ "absorption_per_mm":[0.022314355,0.005129329,0],
+ "boundary":"closed_mesh","thickness_mm":0}]}}
+```
+
+At most **eight** overrides are admitted. Both captured body ordinal and exact
+name from `render.scene` must match; duplicate ordinals are rejected. An override
+means a full dielectric interface, with no fractional transmission-weight field.
+It replaces optical metalness only in the captured job. Saved appearances,
+engineering properties, meshes, undo history and navigation do not change.
+
+IOR must be finite in [1,3]. `absorption_per_mm` contains finite linear RGB
+extinction coefficients in [0,100] per mm. Beer attenuation is
+`exp(-sigma * geometric_distance_mm)`, using unshifted geometric hit endpoints,
+not the distance after a numerical ray-origin offset. A colour authoring UI can
+convert transmittance T at a stated distance d with `sigma = -ln(T)/d`; no such UI
+or implicit sRGB conversion is added here. Zero sigma means no absorption.
+
+Boundary is one of:
+
+- `"thin_sheet"` with a sibling `"thickness_mm":3`: thickness in [0,10000] mm. An ideal
+ parallel sheet with no interior medium or lateral ray displacement. Absorption
+ uses thickness divided by the refracted cosine. Incoherent internal reflections
+ are summed separately for s/p polarization, then averaged. Zero thickness is
+ admitted and has no absorption, but retains the two-interface optical response.
+- `"closed_box"` with `"thickness_mm":0`: strict axis-aligned bounding-plane check (1e-6 mm tolerance),
+ followed by the GPU's closed, outward two-manifold topology validation.
+- `"closed_mesh"` with `"thickness_mm":0`: **GPU-only** extension for general closed sphere/lens meshes.
+ This is not a claim that the current CPU certificate admits those shapes.
+
+Preparation matches topology representatives within 1e-6 mm Euclidean distance,
+searching neighboring spatial cells so a rounding boundary cannot split a valid
+CAD seam. It does not alter uploaded geometry or join chains beyond a representative's
+tolerance. Weld scratch is bounded and budgeted for the largest closed dielectric
+body being validated; opaque and thin-sheet bodies allocate none of it.
+Preparation requires paired opposite edges, exactly one edge-connected shell, positive outward volume, and requires
+one homogeneous IOR/medium over a closed body's faces. Nested or overlapping
+closed media are refused conservatively: dielectric body AABBs must be disjoint
+when either body is closed. This can reject disjoint curved shapes whose boxes
+overlap. Thin sheets can overlap each other's bounds. Camera and the entire lens
+aperture must start outside volumes; unmatched exits fail without a published image.
+Multiple shells in one body are refused with a connected-component check and a
+negative two-shell fixture. Self-intersection of an otherwise oriented manifold
+is **not certified**; such geometry is outside the supported input contract and
+may not be detected. Edge counts and signed volume are not a proof of embedding.
+The hole, inward-winding, disconnected-shell, nested/overlapping bounds and
+camera-inside refusal paths have negative fixtures. GPU preflight reports
+`dielectric_boundaries: ["thin_sheet","closed_box","closed_mesh"]`; CPU preflight
+reports an empty list. The generic Refraction flag alone does not describe this policy.
+
+CPU and raster previews retain independently saved scalar opacity. CPU requests
+reject runtime dielectric/lens controls. Scalar alpha is never inferred to mean
+physical glass. Old opaque PBR appearances still require opacity one. Unknown keys,
+nonfinite inputs, invalid ordinals and out-of-range values are errors.
+
+## Transport and validation
+
+GPU transport uses geometric winding for entering/leaving media, exact s/p Fresnel
+including total internal reflection, Snell refraction and Beer attenuation. It
+includes the squared IOR ratio for radiance transport. Glass is smooth; rough
+transmission and fractional mixtures are absent. Runtime [glass shadow connections](render-glass-shadows.md)
+are enabled by default for thin sheets and opt-in for solids; the latter are explicitly
+straight-through NEE-only approximations, not caustics. The maximum path depth remains 16.
+The existing per-path stack storage is retained, but nested-entry events are errors.
+
+`crates/render/src/dielectric_oracle_tests.rs` is an original self-contained f64
+fixture module prepared for sharing with #1659: normal/oblique/Brewster s/p,
+Snell and critical-angle/TIR cases, Beer attenuation, lossless and absorbing slabs,
+and zero-thickness sheets. Its provenance and numerical tolerances are explicit.
+GPU tests additionally cover sphere furnace, actual-mesh ball-lens focus, and
+absorbing slab transport with deliberately large ray offsets to detect undercounted
+absorption distance. No test tolerance was relaxed for a backend.
+
+Secondary-ray epsilon remains max(1e-5 mm, scene extent * 1e-7). Intersections use
+original f32 dominant-axis projection and conservative bounds; they do not claim
+universal exact watertightness. The shared-edge regression at pixel171, sample357,
+seed1948 remains covered by the furnace. The general coordinate-transform idea is
+from [Woop, Benthin and Wald (2013)](https://jcgt.org/published/0002/01/05/paper.pdf);
+no external shader code was copied. See [thin-lens notes](render-thin-lens.md) for
+CPU draft convention differences. The production environment is still the studio;
+a uniform environment exists only in numerical/evidence tests, not as HDRI support.
diff --git a/docs/render-visual-mapping.md b/docs/render-visual-mapping.md
new file mode 100644
index 0000000000..4181c354de
--- /dev/null
+++ b/docs/render-visual-mapping.md
@@ -0,0 +1,55 @@
+# Definition-local visual mapping
+
+`solidcraft_render::mapping` provides numerical admission and coordinates for #1214,
+the first mapping foundation under #786. It is original Rust code with no new
+dependency or asset. It does not install a sampler, triplanar shader, texture pack,
+document record, command or UI. No renderer capability changes. Textured wood is
+not yet available through this utility.
+
+`VisualMapping::new(origin_mm, axes, repeat_mm)` admits an immutable frame. Origin
+and axes belong to the body's **definition-local** space. Axes are ordered visual
+grain/across/depth, not engineering L/R/T. They must be finite, unit length and
+mutually perpendicular, with positive handedness. Squared lengths, dot products
+and determinant use absolute tolerance `1e-10` for floating-point rotation error.
+Values within that tolerance are retained exactly; no normalization, skew repair
+or substitute frame is performed. Private fields and the absence of serde require
+future loaders to go through admission.
+
+Repeat sizes are positive physical distances along those axes, not fractions of a
+body's current bounds. Coordinates are the signed, unwrapped values
+`dot(local_point_mm - origin_mm, axis_i) / repeat_mm_i`. Negative coordinates are
+valid. Wrapping, filtering, map-role interpretation and normal-map tangent bases
+belong to the eventual consumer. These coordinates alone do not define seamless
+triplanar blending, end-grain appearance or an anisotropic optical model.
+
+Admission limits:
+
+- Each local origin/input coordinate: finite, absolute value at most `1e9` mm.
+- Each repeat size: finite, `[0.001, 1e6]` mm.
+- Each resulting repeat coordinate: finite, absolute value at most `1e6`.
+
+These are explicit numerical refusal bounds, not measured engineering ranges or
+GPU quality guarantees. Calculations use f64; a future f32 shader needs its own
+precision budget and supported scene limits. Values are never silently clamped.
+
+`suggest_grain_axis` considers only a finite, ordered definition-local AABB with
+at least one positive extent. It selects the largest extent; exact ties use X,
+then Y, then Z. Flat or line bounds are admissible, a point/empty box is not. Its
+`GrainAxis::axes()` supplies a deterministic right-handed initial frame. A caller
+must store an accepted frame once, and allow explicit edits; it must not rerun the
+suggestion automatically when parameters change. `VisualMapping` holds no bounds
+and therefore cannot independently flip on resize.
+
+For an instance, the host first inverts the actual rigid placement to recover
+definition-local coordinates. This utility neither guesses placement from world
+bounds nor implements another transform system. Mirroring, deformed/nonrigid
+instances and face-specific mapping need explicit consumer policies. Tests use an
+independent analytic quarter-turn/translation to check this coordinate convention;
+they do not certify a document/assembly adapter that has not been installed.
+
+The remaining phases are persistence/copy/undo/reopen through existing appearance
+commands, actual CPU/GPU texture consumption and honest unsupported-map behavior,
+then manual controls and native/browser visual evidence. No document version is
+reserved here. Source/license receipts and admitted resources must remain portable
+when that consumer is added. Visual grain never changes mass, CAD bounds, mechanical
+axes or manufacturing stock/nesting. #786/#813/#922 remain open.
diff --git a/docs/render-vndf-prototype.md b/docs/render-vndf-prototype.md
new file mode 100644
index 0000000000..c22ee46dae
--- /dev/null
+++ b/docs/render-vndf-prototype.md
@@ -0,0 +1,39 @@
+# Matched GGX visible-normal sampling foundation
+
+This constituent exposes an original safe-Rust numerical proposal through
+`AnisotropicSurface::sample_visible_normal`, `visible_normal_pdf`,
+`visible_reflection_pdf` and `sample_visible_reflection`. It does not yet install
+the CPU reflection consumer, alter GPU shaders, introduce a renderer capability,
+or persist new data. The consumer remains tracked by #1698 and #1654.
+
+The proposal conditions on the view direction using the spherical-cap
+construction. Its PDF and throughput use the same GGX distribution, separable
+Smith masking and Fresnel law as the existing surface. Geometric or shading
+hemisphere rejection is a null event, never retried or renormalized. Invalid
+variates and nonfinite arithmetic refuse explicitly. Existing projected-NDF
+methods remain available as independent numerical controls.
+
+At dielectric IOR exactly one, the specular contribution is zero at every angle;
+a metallic mixture retains only its conductor fraction. The shared Fresnel helper
+and both isotropic/anisotropic numerical paths use that same limit. No tolerance,
+energy clamp, sample budget or ignored test is changed.
+
+The original regressions exercise analytic moments, density mass and Jacobians,
+throughput/BSDF agreement, unequal roughness axes, rigid frame rotation,
+hemisphere rejection and resolved grazing/end-point cases. They do not establish
+a universal floating-point proof or measured image-quality/performance benefit.
+Actual source-pinned test results belong in the PR evidence, not this contract.
+
+## Primary references and provenance
+
+The original donor implementation was derived from the mathematical equations in
+Eric Heitz, *Sampling the GGX Distribution of Visible Normals* (JCGT 7(4), 2018),
+and Jonathan Dupuy / Anis Benyoub, *Sampling Visible GGX Normals with Spherical
+Caps* (2023). References:
+
+- https://jcgt.org/published/0007/04/01/
+- https://arxiv.org/abs/2306.05044
+
+The Rust implementation and tests are retained from the owned, reviewed donor;
+no external implementation or dependency is imported by this extraction. No paper
+text, figure or listing is included. Project code remains MIT OR Apache-2.0.
diff --git a/docs/render-workspace.md b/docs/render-workspace.md
index a1a0c2f5c1..6ac615ace9 100644
--- a/docs/render-workspace.md
+++ b/docs/render-workspace.md
@@ -1,5 +1,7 @@
# Integrated Render workspace (R3)
+The native image panel also offers [progressive opaque rendering](render-path.md) when its compute executor is available.
+
R4a builds on this viewport contract with a separately advertised CPU product-image
executor and Check/Start/Cancel/Export controls. See [render jobs](render-jobs.md) for
the asynchronous protocol, image limits, captured revisions and PNG export. The legacy
diff --git a/examples/material-card.json b/examples/material-card.json
new file mode 100644
index 0000000000..86466e2a02
--- /dev/null
+++ b/examples/material-card.json
@@ -0,0 +1,75 @@
+{
+ "commands": [
+ {
+ "params": {
+ "height": 5,
+ "width": 20,
+ "length": 10,
+ "body_name": "Specimen"
+ },
+ "command": "solid.box"
+ },
+ {
+ "params": {
+ "physical_card": {
+ "family": "other",
+ "sources": [
+ {
+ "kind": "illustrative",
+ "id": "fixture",
+ "license": "MIT OR Apache-2.0",
+ "title": "Original illustrative constants"
+ }
+ ],
+ "properties": [
+ {
+ "source_id": "fixture",
+ "data": {
+ "kind": "density",
+ "kg_m3": 700.0
+ },
+ "conditions": {
+ "state": "synthetic",
+ "temperature_k": 293.15
+ }
+ },
+ {
+ "source_id": "fixture",
+ "data": {
+ "kind": "elasticity",
+ "model": {
+ "poisson_ratio": 0.25,
+ "symmetry": "isotropic",
+ "young_modulus_pa": 12250000000.0
+ }
+ }
+ }
+ ],
+ "schema_version": 1,
+ "designation": "Original synthetic isotropic card - not design data"
+ },
+ "name": "Synthetic candidate",
+ "color": "#b47846",
+ "density_g_cm3": 0.8
+ },
+ "command": "material.create"
+ },
+ {
+ "params": {
+ "bodies": [
+ "Specimen"
+ ],
+ "material": "Synthetic candidate"
+ },
+ "command": "material.assign"
+ },
+ {
+ "params": {},
+ "command": "material.list"
+ },
+ {
+ "params": {},
+ "command": "component.properties"
+ }
+ ]
+}
diff --git a/examples/render-path-studio.json b/examples/render-path-studio.json
new file mode 100644
index 0000000000..47451b84fc
--- /dev/null
+++ b/examples/render-path-studio.json
@@ -0,0 +1,18 @@
+{
+ "commands": [
+ {"command":"file.new","params":{"name":"Original opaque enclosure"}},
+ {"command":"solid.box","params":{"body_name":"Base","corner":[-48,-32,0],"length":96,"width":64,"height":4}},
+ {"command":"solid.box","params":{"body_name":"Left wall","corner":[-48,-32,4],"length":4,"width":64,"height":14}},
+ {"command":"solid.box","params":{"body_name":"Right wall","corner":[44,-32,4],"length":4,"width":64,"height":14}},
+ {"command":"solid.box","params":{"body_name":"Back wall","corner":[-44,28,4],"length":88,"width":4,"height":14}},
+ {"command":"solid.box","params":{"body_name":"Front wall","corner":[-44,-32,4],"length":88,"width":4,"height":14}},
+ {"command":"solid.box","params":{"body_name":"Teal insert","corner":[-33,-19,4],"length":66,"width":38,"height":10}},
+ {"command":"solid.cylinder","params":{"body_name":"Fastener A","base":[-39,-23,4],"radius":3,"height":11}},
+ {"command":"solid.cylinder","params":{"body_name":"Fastener B","base":[39,-23,4],"radius":3,"height":11}},
+ {"command":"solid.cylinder","params":{"body_name":"Fastener C","base":[-39,23,4],"radius":3,"height":11}},
+ {"command":"solid.cylinder","params":{"body_name":"Fastener D","base":[39,23,4],"radius":3,"height":11}},
+ {"command":"appearance.assign","params":{"bodies":["Base","Left wall","Right wall","Back wall","Front wall"],"color":"#c5c9d2","pbr":{"metallic":0,"roughness":0.6,"dielectric_ior":1.5}}},
+ {"command":"appearance.assign","params":{"bodies":["Teal insert"],"color":"#218e9b","pbr":{"metallic":0,"roughness":0.35,"dielectric_ior":1.5}}},
+ {"command":"appearance.assign","params":{"bodies":["Fastener A","Fastener B","Fastener C","Fastener D"],"color":"#d2d4d8","pbr":{"metallic":1,"roughness":0.25,"dielectric_ior":1.5}}}
+ ]
+}
diff --git a/examples/studio/README.md b/examples/studio/README.md
new file mode 100644
index 0000000000..26c70afe2a
--- /dev/null
+++ b/examples/studio/README.md
@@ -0,0 +1,206 @@
+# Original SolidCraft studio scenes
+
+These are editable command recipes, not imported models or triangle meshes.
+Every part is authored here from sketches, extrusions, primitive solids, boolean
+cuts and swept pipes. There are no manufacturer logos, copied product assets or
+external textures. `author_scene.py` is the optional local authoring tool; the
+application reads the emitted JSON without Python.
+
+## Lighting study
+
+`stage1.json` is a five-body study of a hollow rounded black shell, an exploded
+lid, a chrome sphere and puck over a real floor. `stage1-render.json` supplies
+three rectangular softboxes and a neutral environment, with no clear-coat or
+transmission overrides. This separates lighting review from material review.
+
+## Exploded coffee machine
+
+`coffee-exploded.json` contains 32 named B-rep bodies. The cylindrical brewing
+head has an open horizontal bore, separate collar, recessed shower screen and
+capsule slot in its floating roof. A round swept chrome lever has ball ends.
+Other parts include a hollow D tank and detached matte lid, a hollow ribbed bin,
+D drip tray, a 42-hole stainless grate, rounded cap, nine-slot/four-hole service
+panel, eight slotted zinc screws and an S cable ending in a two-pin plug.
+
+The tank is cut from one extruded solid, leaving 3 mm walls and a 4 mm base.
+Its semicircle is a 64-chord editable sketch: maximum outer radial deviation
+from the ideal 43 mm circle is `43*(1-cos(pi/128)) = 0.01295 mm`. This is a
+deliberate geometry fixture approximation. The analytic-arc version produced
+unpaired tessellation edges at the current 1e-6 mm dielectric topology check;
+we did not relax that check or repair the renderer mesh silently. The emitted
+tank has 532 triangles with paired opposite directed edges; the bin has 178.
+Both pass an independent OBJ edge check at the same 1e-6 mm position precision.
+These counts describe the baseline CLI and are to be rechecked after integration.
+
+`coffee-exploded-render.json` adds seven coated-plastic bodies and two closed
+dielectric bodies. Body indices and names are both explicit and must match
+`render.scene`; editing the body list requires regenerating those indices.
+Smoky brown tank absorption is [0.045, 0.075, 0.12] per mm at IOR 1.586; the bin
+is nearly colourless at IOR 1.49. The black lid is opaque and matte. Metal is
+isotropic GGX; the grate is satin, not a claim of anisotropic brushed shading.
+
+Both render requests are 1920 by 1080, use an explicit front-left camera 30
+degrees above horizontal, and have no lens override or depth of field. Three
+large area lights and a neutral environment illuminate a real white-grey floor.
+The floor extends beyond the camera's horizon intersection and fills the image;
+it is a finite large studio floor, not an infinite-plane/shadow-catcher feature.
+
+For a true cyclorama, `stage1-sweep.json` and `coffee-exploded-sweep.json`
+replace only that floor with an extruded, closed YZ cross-section. Its exact
+circular inner curve is tangent to the horizontal floor and vertical wall;
+the concentric outer curve gives constant thickness. There is no geometric
+crease or separate floor/wall overlap at either join. `author_sweep.py`
+regenerates these variants from the baseline recipes. Use the corresponding
+baseline render request; all object, light and camera coordinates, appearances,
+body names and body ordinals are unchanged.
+
+The stage1 sweep is 3000 mm wide, with a 4 mm thickness, a floor starting at
+y=-1500, a 200 mm inner radius starting at y=250,z=0, and a rear wall at y=450
+rising to z=1500. The coffee sweep scales these dimensions by 2.8: 8400 mm
+width, 11.2 mm thickness, floor start y=-4200, a 560 mm curve starting at
+y=700,z=0, and wall y=1260 rising to z=4200. Both are real shadow-receiving
+opaque CAD solids, not image backplates. Integrated GPU comparison determines
+the final lighting presentation; existing flat-floor evidence remains separate.
+
+`materials.json` maps semantic names to intended material classes. Saved
+appearances remain the opaque PBR preview. Runtime optical controls belong to
+the render request, independently of engineering material properties.
+
+## Geometry review
+
+The recipes were initially replayed and saved with the compatible pre-existing
+CLI during authoring. The integrating worker rebuilds the exact source and
+repeats replay, geometry checks and GPU preflight before publishing render
+evidence. Reference volumes below are calculated from the authored dimensions;
+the measurement command integrates a tessellation, so a relative tolerance of
+0.0003 is appropriate for these isolated checks.
+
+| Body | Analytic volume, mm³ |
+|---|---:|
+| Coated curved shell | 65805.30723760049 |
+| Floating coated lid | 25908.18530717959 |
+| Chrome sphere | 102160.40430453529 |
+| Chrome floating puck | 12666.901579274047 |
+| Open brewing head | 265024.75625683495 |
+| Perforated stainless grate | 15815.487854690262 |
+
+For the tank use the polygon area, not the ideal circle: with
+`D(r,b)=2*r*b+32*r*r*sin(pi/64)`, its volume is
+`171*D(43,45)-167*D(40,42)`. Every body must have positive finite measured volume
+and one kernel shell; transparent boundaries additionally require paired
+opposite edges, one connected triangle shell and positive signed volume.
+
+Example replay (outputs belong outside the repository):
+
+```text
+solidcraft-cli run examples/studio/coffee-exploded.json --save coffee.solidcraft
+solidcraft-cli eval coffee.solidcraft --json-out coffee-measurements.json
+```
+
+Use the evidence runner with the paired render-request JSON to capture runtime
+lighting/material controls. The plain `render` CLI does not load that JSON as
+its request automatically.
+
+
+## Thick tumblers in an original room
+
+`tumblers.json` is a separate 69-body scene. Two thick, open, tapered glass
+tumblers rest on a dark walnut table, with a filleted upholstered sofa, soft
+rectangular cushions, a potted plant, and a real slatted window behind them.
+`author_tumblers.py` defines every dimension. The glass is made by revolving
+closed radial sections: tall outer radii 36/42 mm and height 112 mm, 4.5 mm
+walls and a 9 mm bottom; short radii 37/43 mm and height 94 mm, 5 mm walls and a
+10 mm bottom. These are analytic curved B-reps, not polygon replacements.
+
+`tumblers-render.json` supplies a warm small area light behind the blind slats,
+two broad fill panels, two closed dielectric overrides and a thin lens. It is
+1920 by 1080, with a 5.5 mm aperture radius and 670 mm axial focus distance.
+The blind shadows require real light transport; the recipe contains no painted
+shadow texture. `tumblers-materials.json` lists semantic material classes and
+suggested world-coordinate texture projections. The scene's saved walnut and
+linen appearances are plain colours: grain, woven texture and normal-map
+transport must be provided by the integrating renderer and are not implied by
+these material names.
+
+`tumblers-sun.json` and `tumblers-sun-render.json` are a separate daylight
+variation; the original studio-lit recipe and request are unchanged. The only
+geometry change is a real 1850 by 1080 mm opening through the rear wall at
+x = -1450..400, z = 760..1840. Without this opening, the intact rear wall would
+occlude the infinite sun even where rays passed between the modelled blinds.
+The sun points toward [-0.4, 1, 0.4], has a finite 0.00465 rad angular radius,
+and uses warm radiance [18000, 16500, 14000]. An original procedural sky
+gradient supplies cooler fill; it is an artistic gradient, not an atmospheric
+simulation or an imported environment photograph. No extra area lights are
+used in this variation. The camera, lens, glass and sample settings are retained.
+
+From the table point [0, 0, 480], the central sun ray reaches [-576, 1440, 1056]
+at the blind front and [-800, 2000, 1280] at the rear-wall opening. The ray is
+above the sofa; the blind slats, 12 mm thick and 45 mm apart, therefore produce
+real directional shadow stripes on the table. Their 52 mm depth also affects
+the occluded band width. Finite-disk softness and the final visible pattern must
+be checked in a GPU render; these analytic coordinates do not substitute for it.
+
+On the authoring baseline the two tumbler meshes have 4856 and 4160 triangles.
+Independent topology checks using Euclidean 1e-6 mm seam matching find zero
+unpaired directed edges. Rounded integer keys alone rejected a few points on
+opposite sides of a quantization boundary despite their sub-tolerance distance.
+The accompanying renderer fix searches adjacent cells at the same tolerance;
+it preserves original vertices, winding and connected-shell checks. Integration
+must rerun those tests and GPU admission before claiming this scene rendered.
+
+All three scenes have positive finite measured volume and one kernel shell per
+body on the authoring baseline. The evidence report must state the exact rebuilt
+source and backend; the initial CPU snapshots are composition checks only.
+
+## Runtime showcase requests (render validation pending)
+
+First generate the original local resource files from the repository root:
+
+```text
+python examples/studio/author_showcase.py
+```
+
+The source tree contains generators, editable scenes and runtime requests only.
+The four PNG maps and RGBE gradient are generated on demand into ignored paths in
+`examples/studio/textures`; they are not committed source assets. A fresh checkout
+must run this command before replaying a textured or HDR showcase request.
+The script uses only Python's standard library and downloads nothing.
+
+Run the production `studio_evidence` example from the repository root so its
+scoped VFS resolves these generated relative resource paths. Rendered outputs
+belong outside the source tree and may be published only as evidence on the
+results branch. Use these pairs:
+
+| Scene recipe | Runtime request | Lighting |
+| --- | --- | --- |
+| `tumblers.json` | `tumblers-textures-render.json` | Three finite studio panels and constant fill |
+| `tumblers-sun.json` | `tumblers-sun-textures-render.json` | Finite sun through actual window/blinds and original procedural sky |
+| `tumblers-sun.json` | `tumblers-hdr-textures-render.json` | Same finite sun and authored RGBE sky fixture |
+
+These requested settings are not a completed visual milestone. The requests use
+1920x1080, 2048 samples, depth16, seed1948, one final
+`aces_fitted` output transform, 5.5mm aperture radius and 670mm axial focus.
+The two closed glass tumblers explicitly enable `shadow_transmission`. Their
+matching `*-blocked-render.json` controls differ only by setting those two flags
+false. This isolates the optional straight shadow connection; it is not a
+refracted-caustic solver. Physical camera/reflection/refraction paths remain active.
+
+Thirteen opaque body bindings add the original walnut and woven-linen colour and
+OpenGL normal maps. Their 26MiB normalized pixels are below the32MiB texture cap.
+Mapping uses explicit planar world frames; the normal maps do not model yarn
+geometry and the side faces are not triplanar. Glass stays smooth and unmapped.
+See [texture provenance](textures/ATTRIBUTION.md) and `textures/manifest.json`.
+
+The locally generated HDR file contains only an original analytic gradient, sampled at512x256 and
+quantized to Radiance RGBE with declared linear-sRGB/D65 primaries. It contains no
+sun disk or downloaded imagery. The separate finite sun remains identical between
+the procedural-sky and HDR requests. RGBE quantization means these two inputs need
+not produce byte-identical renders. `textures/environment-manifest.json` records
+its hash, dimensions and authoring parameters.
+
+Regenerate the original room with `python examples/studio/author_tumblers.py` and
+the textures/HDR/portable requests with `python examples/studio/author_showcase.py`.
+These scripts use Python's standard library. They do not modify the coffee or
+stage1 recipes. Source validation and asset hashes do not constitute GPU evidence:
+the final report must include the actual backend, rebuilt source, full-resolution
+image, metadata and matched blocked-shadow control.
diff --git a/examples/studio/author_coffee_cylinder.py b/examples/studio/author_coffee_cylinder.py
new file mode 100644
index 0000000000..38a05244bb
--- /dev/null
+++ b/examples/studio/author_coffee_cylinder.py
@@ -0,0 +1,90 @@
+"""Original cylindrical coffee housing; editable CAD commands, no mesh assets.
+
+Derive separate variants from the reviewed coffee-framing recipes. Python is
+only an authoring tool. The emitted JSON is replayable without Python.
+"""
+import argparse
+import copy
+import json
+from pathlib import Path
+
+HERE = Path(__file__).parent
+
+
+def cylinder(name, base, radius, height):
+ return dict(command="solid.cylinder", params=dict(
+ body_name=name, base=base, radius=radius, height=height,
+ axis="Z", operation="new"))
+
+
+REPLACEMENTS = {
+ "Housing plinth": [cylinder("Housing plinth", [0, 8, 30], 76, 12)],
+ "Housing shell": [
+ cylinder("Housing shell", [0, 8, 55], 70, 210),
+ dict(command="solid.cylinder", params=dict(
+ base=[0, 8, 54], radius=65, height=212, axis="Z",
+ operation="cut", targets=["Housing shell"],
+ name="Through cylindrical housing cavity")),
+ ],
+ "Housing upper shoulder": [
+ cylinder("Housing upper shoulder", [0, 8, 265], 70, 8),
+ ],
+}
+
+
+def body_names(commands):
+ names = []
+ for item in commands:
+ params = item["params"]
+ if item["command"].startswith("solid.") and params.get("operation") == "new":
+ names.append(params["body_name"])
+ if item["command"] == "solid.combine":
+ for tool in params["tools"]:
+ names.remove(tool)
+ return names
+
+
+def variant(source, expected_names):
+ result = copy.deepcopy(source)
+ commands = result["commands"]
+ assert body_names(commands) == expected_names
+ for name, replacement in REPLACEMENTS.items():
+ starts = [i for i, c in enumerate(commands)
+ if c["command"] == "sketch.create"
+ and c["params"].get("name") == name + " profile"]
+ ends = [i for i, c in enumerate(commands)
+ if c["command"] == "solid.extrude"
+ and c["params"].get("body_name") == name]
+ assert len(starts) == len(ends) == 1 and starts[0] < ends[0]
+ commands[starts[0]:ends[0] + 1] = copy.deepcopy(replacement)
+ cuts = [c for c in commands if c["params"].get("name") == "Open brewing bay"]
+ assert len(cuts) == 1 and cuts[0]["params"]["targets"] == ["Housing shell"]
+ cuts[0]["params"].update(corner=[-47, -80, 88], length=94, width=80, height=149)
+ commands[0]["params"]["name"] = "Original exploded cylindrical coffee machine"
+ assert body_names(commands) == expected_names
+ return result
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--source", type=Path, default=HERE)
+ parser.add_argument("--output", type=Path, default=HERE)
+ args = parser.parse_args()
+ read = lambda name: json.loads((args.source / name).read_text(encoding="utf-8"))
+ names = list(read("materials.json")["coffee-exploded"])
+ assert len(names) == 32
+ for source, destination in [("coffee-framing.json", "coffee-cylinder.json"),
+ ("coffee-framing-sweep.json", "coffee-cylinder-sweep.json")]:
+ recipe = variant(read(source), names)
+ (args.output / destination).write_text(
+ json.dumps(recipe, indent=2) + "\n", encoding="utf-8", newline="\n")
+ render = read("coffee-framing-render.json")
+ for binding in render["raytrace"]["clear_coats"] + render["raytrace"]["dielectrics"]:
+ assert names[binding["body_index"]] == binding["body_name"]
+ # Copy bytes: camera, light orientation, coatings and closed glass stay exact.
+ (args.output / "coffee-cylinder-render.json").write_bytes(
+ (args.source / "coffee-framing-render.json").read_bytes())
+
+
+if __name__ == "__main__":
+ main()
diff --git a/examples/studio/author_coffee_framing.py b/examples/studio/author_coffee_framing.py
new file mode 100644
index 0000000000..1460b2b9c5
--- /dev/null
+++ b/examples/studio/author_coffee_framing.py
@@ -0,0 +1,71 @@
+"""Original framing variant; derives only new files from the reviewed baseline.
+
+Keep the baseline 32 bodies and names: append rigid translations, never copies.
+The camera is lower and closer; optical settings and corrected lights are copied.
+Run from any working directory with Python's standard library.
+"""
+import copy
+import json
+import math
+from pathlib import Path
+
+HERE = Path(__file__).parent
+SHIFTS = {'Open brewing head': [0, 0, 28],
+ 'Brewing collar': [0, 0, 28],
+ 'Shower screen': [0, 0, 28],
+ 'Brewing head roof': [0, 0, 40],
+ 'Bent chrome lever': [0, 0, 40],
+ 'Left lever ball': [0, 0, 40],
+ 'Right lever ball': [0, 0, 40],
+ 'Smoky D tank': [100, 8, 0],
+ 'Separate tank lid': [100, 8, 22],
+ 'Tank lid grip': [100, 8, 22],
+ 'Clear ribbed bin': [-70, -15, 0],
+ 'Louvred service panel': [-110, 15, 0],
+ 'Drip tray': [0, -34, 0],
+ 'Perforated stainless grate': [0, -34, 0],
+ 'Rounded tray cap': [38, -34, 0],
+ 'Black S power cable': [50, 8, 0],
+ 'Two pin plug': [50, 8, 0],
+ 'Plug pin 206': [50, 8, 0],
+ 'Plug pin 218': [50, 8, 0],
+ 'Zinc screw 1': [-28, 0, 0],
+ 'Zinc screw 2': [-28, 0, 0],
+ 'Zinc screw 3': [-28, 0, 0],
+ 'Zinc screw 4': [-28, 0, 0],
+ 'Zinc screw 5': [28, 0, 0],
+ 'Zinc screw 6': [28, 0, 0],
+ 'Zinc screw 7': [28, 0, 0],
+ 'Zinc screw 8': [28, 0, 0]}
+CAMERA = dict(target=[-25, -10, 170], yaw=math.radians(30), pitch=math.radians(18),
+ roll=0, distance=950, fov=math.radians(34))
+
+
+def read(name):
+ return json.loads((HERE / name).read_text(encoding="utf-8"))
+
+
+def write(name, value):
+ (HERE / name).write_text(json.dumps(value, indent=2) + "\n", encoding="utf-8", newline="\n")
+
+
+def main():
+ names = list(read("materials.json")["coffee-exploded"])
+ assert len(names) == 32 and set(SHIFTS).issubset(names)
+ for source, destination in [("coffee-exploded.json", "coffee-framing.json"),
+ ("coffee-exploded-sweep.json", "coffee-framing-sweep.json")]:
+ recipe = copy.deepcopy(read(source))
+ for name, translation in SHIFTS.items():
+ recipe["commands"].append(dict(command="solid.move", params=dict(
+ bodies=[name], translate=translation, copy=False,
+ name="Framing: " + name)))
+ write(destination, recipe)
+ render = copy.deepcopy(read("coffee-exploded-render.json"))
+ render["settings"]["camera"] = CAMERA
+ # Preserve the physical closed glass, all seven coats and the corrected fill.
+ # No smoothing or denoising is introduced by the framing variant.
+ write("coffee-framing-render.json", render)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/examples/studio/author_scene.py b/examples/studio/author_scene.py
new file mode 100644
index 0000000000..4dbb9b9cf5
--- /dev/null
+++ b/examples/studio/author_scene.py
@@ -0,0 +1,224 @@
+"""Original editable CAD recipe authoring; Python is not an application dependency.
+
+The emitted JSON is the editable authority consumed by SolidCraft commands.
+All dimensions are millimetres. No meshes or imported design assets are used.
+"""
+import json
+import math
+from pathlib import Path
+
+HERE = Path(__file__).parent
+MATERIALS = {
+ "coated_black": ("#101318", 0, .30),
+ "matte_black": ("#171a1f", 0, .55),
+ "chrome": ("#d5d9dd", 1, .12),
+ "stainless": ("#aeb4bb", 1, .25),
+ "zinc": ("#b0b5bc", 1, .32),
+ "rubber": ("#141414", 0, .8),
+ "floor": ("#e8e8e8", 0, .65),
+ "smoke": ("#c2c6ca", 0, .05),
+ "clear": ("#e4eff1", 0, .05),
+}
+
+
+class Scene:
+ def __init__(self, name):
+ self.commands = []
+ self.materials = {}
+ self.cmd("file.new", name=name)
+
+ def cmd(self, command, **params):
+ self.commands.append(dict(command=command, params=params))
+
+ def body(self, name, material):
+ self.materials[name] = material
+
+ def box(self, name, p, size, material, **extra):
+ self.cmd("solid.box", body_name=name, corner=p, length=size[0], width=size[1], height=size[2], operation="new", **extra)
+ self.body(name, material)
+
+ def cylinder(self, name, p, radius, height, material, axis="Z"):
+ self.cmd("solid.cylinder", body_name=name, base=p, radius=radius, height=height, axis=axis, operation="new")
+ self.body(name, material)
+
+ def sphere(self, name, p, radius, material):
+ self.cmd("solid.sphere", body_name=name, center=p, radius=radius, operation="new")
+ self.body(name, material)
+
+ def sketch(self, name, origin, x=(1, 0, 0), y=(0, 1, 0)):
+ self.cmd("sketch.create", name=name + " profile", plane=dict(origin=origin, x_dir=x, y_dir=y))
+
+ def extrude(self, name, height, material, point=None):
+ self.cmd("sketch.finish")
+ self.cmd("solid.extrude", distance=height, operation="new", body_name=name, **({"profiles":[{"point":point}]} if point else {}))
+ self.body(name, material)
+
+ def rounded(self, name, origin, width, depth, radius, height, material, wall=0, x=(1, 0, 0), y=(0, 1, 0)):
+ self.sketch(name, origin, x, y)
+ self.cmd("sketch.rectangle.rounded", p0=[-width/2, -depth/2], p1=[width/2, depth/2], radius=radius)
+ if wall:
+ self.cmd("sketch.rectangle.rounded", p0=[-width/2+wall, -depth/2+wall], p1=[width/2-wall, depth/2-wall], radius=max(.5, radius-wall))
+ self.extrude(name, height, material, [-width/2+wall/2,0] if wall else None)
+
+ def d_loop(self, radius, rear, prefix, segments=0):
+ # Straight back, parallel sides and one exact semicircular front.
+ if segments:
+ points=[[-radius,0],[-radius,rear],[radius,rear],[radius,0]]
+ points += [[radius*math.cos(math.pi*i/segments),-radius*math.sin(math.pi*i/segments)] for i in range(1,segments)]
+ self.cmd("sketch.line",points=points,closed=True,infer=False)
+ return
+ self.cmd("sketch.line", points=[[-radius, 0], [-radius, rear], [radius, rear], [radius, 0]], ids=[prefix+"left", prefix+"back", prefix+"right"], infer=False)
+ self.cmd("sketch.arc.three_point", start=[radius, 0], end=[-radius, 0], through=[0, -radius], id=prefix+"front")
+
+ def d_section(self, name, origin, radius, rear, height, material, wall=0, holes=(), segments=0):
+ self.sketch(name, origin)
+ self.d_loop(radius, rear, "outer",segments)
+ if wall:
+ # Back offset makes an actual uniform-thickness D shell.
+ self.d_loop(radius-wall, rear-wall, "inner",segments)
+ for cx, cy, r in holes:
+ self.cmd("sketch.circle.center", center=[cx, cy], radius=r)
+ self.extrude(name, height, material, [0,rear-(wall/2 if wall else 1)] if wall or holes else None)
+
+ def finish(self, stem, camera, scale=1):
+ for material, (color, metallic, roughness) in MATERIALS.items():
+ bodies = [name for name, mat in self.materials.items() if mat == material]
+ if bodies:
+ self.cmd("appearance.assign", bodies=bodies, color=color, pbr=dict(metallic=metallic, roughness=roughness, dielectric_ior=1.5))
+ write(stem + ".json", dict(commands=self.commands))
+ light = lambda center,u,v,power: dict(center=[q*scale for q in center], u=[q*scale for q in u], v=[q*scale for q in v], radiance=[power]*3)
+ render = dict(progressive=True, samples=256, max_depth=12, seed=1948, tone_map="aces_fitted",
+ settings=dict(width=1920, height=1080, camera=camera, background=[240,240,240]),
+ lighting=dict(environment=[.5,.5,.5], area_lights=[
+ light([-140,-130,280], [110,0,0], [0,-70,0], 8),
+ light([280,-160,180], [0,-60,0], [0,0,90], 6),
+ light([0,170,250], [70,0,0], [0,0,65], 10)]))
+ if stem == "coffee-exploded":
+ render["raytrace"] = {
+ "clear_coats":[dict(body_index=i,body_name=name,weight=1,roughness=.12,ior=1.5)
+ for i,(name,mat) in enumerate(self.materials.items()) if mat == "coated_black"],
+ "dielectrics":[dict(body_index=i,body_name=name,ior=1.586 if mat=="smoke" else 1.49,
+ absorption_per_mm=[.045,.075,.12] if mat=="smoke" else [.0004,.00015,.00005],
+ boundary="closed_mesh",thickness_mm=0)
+ for i,(name,mat) in enumerate(self.materials.items()) if mat in {"smoke","clear"}]
+ }
+ write(stem + "-render.json", render)
+ return self.materials
+
+
+def write(name, value):
+ (HERE/name).write_text(json.dumps(value, indent=2)+"\n", encoding="utf-8", newline="\n")
+
+
+def camera(target, distance):
+ # SolidCraft yaw zero is front (-Y); positive yaw moves left (-X).
+ return dict(target=target, yaw=math.radians(32), pitch=math.radians(30), roll=0, distance=distance, fov=math.radians(34))
+
+
+def stage1():
+ s = Scene("Original studio light and coating study")
+ s.box("Studio floor", [-1500,-1500,-4], [3000,3000,4], "floor")
+ s.rounded("Coated curved shell", [-42,8,35], 85,65,20,65,"coated_black",wall=4)
+ s.rounded("Floating coated lid", [-42,8,121], 85,65,20,5,"coated_black")
+ s.sphere("Chrome sphere", [60,-3,60], 29,"chrome")
+ s.cylinder("Chrome floating puck", [63,5,112], 24,7,"chrome")
+ return s.finish("stage1", camera([0,0,70],430))
+
+
+def coffee():
+ s = Scene("Original exploded bench coffee machine")
+ # Broad seamless studio floor. Its far edge is outside the explicit camera.
+ s.box("Studio floor", [-6000,-6000,-5], [12000,12000,5], "floor")
+ s.rounded("Housing plinth", [0,8,30], 140,130,24,12,"coated_black")
+ s.rounded("Housing shell", [0,8,55], 130,116,23,210,"coated_black",wall=5)
+ s.cmd("solid.box", corner=[-46,-60,88], length=92,width=35,height=149,operation="cut",targets=["Housing shell"],name="Open brewing bay")
+ s.rounded("Housing upper shoulder", [0,8,265],130,116,23,8,"coated_black")
+ s.box("Internal chassis", [-42,38,63], [84,5,189],"stainless")
+ # Open head floats above the shell: hollow collar and roof separated clearly.
+ s.cylinder("Open brewing head",[0,-76,307],43,95,"coated_black",axis="Y")
+ s.cmd("solid.cylinder",base=[0,-77,307],radius=31,height=97,axis="Y",operation="cut",targets=["Open brewing head"],name="Horizontal open brew bore")
+ s.rounded("Brewing head roof", [0,-6,352],115,103,25,7,"coated_black")
+ s.cmd("solid.box",corner=[-18,-9,351],length=36,width=7,height=9,operation="cut",targets=["Brewing head roof"],name="Capsule loading slot")
+ s.cylinder("Brewing collar", [0,-88,307], 35,9,"chrome",axis="Y")
+ s.cmd("solid.cylinder", base=[0,-89,307],radius=28,height=11,axis="Y",operation="cut",targets=["Brewing collar"],name="Open brew throat")
+ s.cylinder("Shower screen", [0,10,307], 27,2,"stainless",axis="Y")
+ for x,y in [(-10,-7),(0,-7),(10,-7),(-10,7),(0,7),(10,7)]:
+ s.cmd("solid.cylinder",base=[x,9,307+y],radius=1.6,height=4,axis="Y",operation="cut",targets=["Shower screen"],name="Shower aperture")
+ # Smooth bent U lever: exact line / circular arc pipe, not faceted cylinders.
+ s.sketch("Lever centerline", [0,-28,0], (1,0,0),(0,0,1))
+ s.cmd("sketch.line",points=[[-77,306],[-77,365]],ids=["lever_left"],infer=False)
+ s.cmd("sketch.arc.three_point",start=[-77,365],through=[-72.6066,375.6066],end=[-62,380],id="lever_bend_left")
+ s.cmd("sketch.line",points=[[-62,380],[62,380]],ids=["lever_top"],infer=False)
+ s.cmd("sketch.arc.three_point",start=[62,380],through=[72.6066,375.6066],end=[77,365],id="lever_bend_right")
+ s.cmd("sketch.line",points=[[77,365],[77,306]],ids=["lever_right"],infer=False)
+ s.cmd("sketch.finish")
+ s.cmd("solid.pipe",path_sketch="Lever centerline profile",path=["lever_left","lever_bend_left","lever_top","lever_bend_right","lever_right"],diameter=9,operation="new",body_name="Bent chrome lever")
+ s.body("Bent chrome lever","chrome")
+ for side,x in [("Left",-77),("Right",77)]:
+ s.sphere(side+" lever ball",[x,-28,306],8,"chrome")
+ # Open D tank: wall and base joined into one closed connected dielectric.
+ s.d_section("Smoky D tank", [225,35,99],43,45,171,"smoke",segments=64)
+ s.sketch("Tank cavity",[225,35,103])
+ s.d_loop(40,42,"cavity",segments=64)
+ s.cmd("sketch.finish")
+ s.cmd("solid.extrude",distance=169,operation="cut",targets=["Smoky D tank"],name="Open tank cavity with four millimetre base")
+ s.d_section("Separate tank lid", [225,35,304],45,47,5,"matte_black")
+ s.rounded("Tank lid grip", [225,41,309],38,12,5,5,"matte_black")
+ # A ribbed bin with a continuous connected wall and bottom. Fine triangular
+ # ribs are authored as an analytic line profile, then extruded as a B-rep.
+ s.sketch("Clear ribbed bin",[-157,-23,58])
+ front=[]
+ for i in range(12):
+ x=-33+i*5.5
+ front.extend([[x,-30],[x+1.8,-32],[x+3.5,-30]])
+ front.append([33,-30])
+ outline=front+[[33,30],[-33,30]]
+ s.cmd("sketch.line",points=outline,closed=True,infer=False)
+ s.cmd("sketch.rectangle.two_point",p0=[-30,-27],p1=[30,27])
+ s.extrude("Clear ribbed bin",72,"clear",[31,0])
+ s.box("Bin base tool",[-190,-53,57],[66,60,4],"clear")
+ s.cmd("solid.combine",target="Clear ribbed bin",tools=["Bin base tool"],operation="join")
+ del s.materials["Bin base tool"]
+ # D tray and floating perforated metal grate. Holes are profile islands,
+ # making true through apertures in a single editable extrude operation.
+ s.d_section("Drip tray",[0,-143,22],57,43,16,"coated_black",wall=4)
+ s.d_section("Tray base tool",[0,-143,21],57,43,4,"coated_black")
+ s.cmd("solid.combine",target="Drip tray",tools=["Tray base tool"],operation="join")
+ del s.materials["Tray base tool"]
+ holes=[(x,y,2.2) for y in [-30,-18,-6,6,18,30] for x in [-36,-24,-12,0,12,24,36] if y>=0 or x*x+y*y<47*47]
+ s.d_section("Perforated stainless grate",[0,-143,65],53,39,2,"stainless",holes=holes)
+ s.rounded("Rounded tray cap",[112,-143,40],38,54,15,16,"coated_black")
+ # Detached service panel faces front; slots and fixing holes are real voids.
+ s.sketch("Louvred service panel",[-122,143,173],(1,0,0),(0,0,1))
+ s.cmd("sketch.rectangle.rounded",p0=[-47,-91],p1=[47,91],radius=8)
+ for z in range(-60,61,15):
+ s.cmd("sketch.rectangle.rounded",p0=[-31,z-2],p1=[31,z+2],radius=1.5)
+ for x in [-38,38]:
+ for z in [-81,81]:
+ s.cmd("sketch.circle.center",center=[x,z],radius=2.4)
+ s.extrude("Louvred service panel",3,"matte_black",[43,0])
+ # Eight zinc screws in two separated assembly rails; the slotted heads are
+ # actual cuts, and threaded-shaft collars add readable mechanical detail.
+ for i in range(8):
+ x=(-99 if i<4 else 99)
+ z=87+(i%4)*55
+ name=f"Zinc screw {i+1}"
+ s.cylinder(name,[x,-68,z],2.1,14,"zinc",axis="Y")
+ s.cmd("solid.cylinder",base=[x,-71,z],radius=4.3,height=4,axis="Y",operation="join",targets=[name],name="Screw pan head")
+ s.cmd("solid.box",corner=[x-3.3,-72,z-.7],length=6.6,width=2.4,height=1.4,operation="cut",targets=[name],name="Driver slot")
+ # Black S cable follows two exact tangent circular arcs near the floor.
+ s.sketch("S cable centerline",[70,-75,9])
+ s.cmd("sketch.arc.three_point",start=[52,94],through=[92,54],end=[132,94],id="cable_a")
+ s.cmd("sketch.arc.three_point",start=[132,94],through=[172,134],end=[212,94],id="cable_b")
+ s.cmd("sketch.line",points=[[212,94],[212,66]],ids=["cable_end"],infer=False)
+ s.cmd("sketch.finish")
+ s.cmd("solid.pipe",path_sketch="S cable centerline profile",path=["cable_a","cable_b","cable_end"],diameter=5,operation="new",body_name="Black S power cable")
+ s.body("Black S power cable","rubber")
+ s.rounded("Two pin plug",[282,-30,3],24,35,7,16,"rubber")
+ for x in [206,218]:
+ s.cylinder(f"Plug pin {x}",[x+70,-64,11],2,18,"chrome",axis="Y")
+ return s.finish("coffee-exploded",camera([25,0,185],1200),scale=2.8)
+
+
+if __name__ == "__main__":
+ write("materials.json", {"stage1": stage1(), "coffee-exploded": coffee()})
diff --git a/examples/studio/author_showcase.py b/examples/studio/author_showcase.py
new file mode 100644
index 0000000000..328507ff7e
--- /dev/null
+++ b/examples/studio/author_showcase.py
@@ -0,0 +1,64 @@
+"""Original portable studio showcase resources. No downloaded imagery.
+Outputs are generated on demand into ignored paths; do not commit image bytes.
+Copyright 2026 SolidCraft contributors. SPDX-License-Identifier: MIT OR Apache-2.0
+"""
+from pathlib import Path
+import copy
+import hashlib
+import json
+import math
+import runpy
+
+HERE = Path(__file__).resolve().parent
+runpy.run_path(str(HERE / "textures" / "author_textures.py"))
+
+def write(name, data):
+ (HERE / name).write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8", newline="\n")
+
+# Same original artistic gradient as EnvironmentSource::sky, sampled at texel
+# centres and quantized to RGBE. No sun disk is baked into this environment.
+width, height = 512, 256
+zenith, horizon, ground = (.16,.32,.7), (.8,.9,1.), (.12,.1,.08)
+encoded = bytearray(b"#?RADIANCE\n# Original SolidCraft analytic gradient, no external imagery\nFORMAT=32-bit_rle_rgbe\nPRIMARIES=0.64 0.33 0.30 0.60 0.15 0.06 0.3127 0.3290\n\n-Y 256 +X 512\n")
+for row in range(height):
+ z = math.cos(math.pi * (row + .5) / height)
+ blend = math.sqrt(abs(z))
+ endpoint = zenith if z >= 0 else ground
+ rgb = [h * (1-blend) + e * blend for h,e in zip(horizon,endpoint)]
+ fraction, exponent = math.frexp(max(rgb))
+ scale = fraction * 256 / max(rgb)
+ rgbe = [min(255, int(c * scale)) for c in rgb] + [exponent + 128]
+ encoded.extend([2,2,width >> 8,width & 255])
+ for value in rgbe:
+ remaining = width
+ while remaining:
+ count = min(127, remaining)
+ encoded.extend([128+count,value])
+ remaining -= count
+hdr = HERE / "textures" / "original-gradient.hdr"
+hdr.write_bytes(encoded)
+write("textures/environment-manifest.json", {
+ "author":"SolidCraft contributors; original mathematical sky gradient",
+ "license":"MIT OR Apache-2.0", "no_external_images":True,
+ "width":width, "height":height, "color_space":"linear sRGB / D65",
+ "sun_baked_in":False, "bytes":len(encoded),
+ "sha256":hashlib.sha256(encoded).hexdigest(),
+ "gradient":{"zenith":zenith,"horizon":horizon,"ground":ground},
+ "encoding":"Radiance RGBE -Y +X; quantized texel-centre gradient"
+})
+sun = json.loads((HERE / "tumblers-sun-textures-render.json").read_text(encoding="utf-8"))
+hdr_params = copy.deepcopy(sun)
+hdr_params["environment"] = {
+ "kind":"hdr", "path":"examples/studio/textures/original-gradient.hdr",
+ "assume_linear_srgb":False, "rotation_rad":0, "intensity":1
+}
+write("tumblers-hdr-textures-render.json", hdr_params)
+for name in ["tumblers-textures-render.json", "tumblers-sun-textures-render.json", "tumblers-hdr-textures-render.json"]:
+ params = json.loads((HERE / name).read_text(encoding="utf-8"))
+ assert len(params["raytrace"]["textures"]) == 13
+ assert len(params["raytrace"]["dielectrics"]) == 2
+ assert all(v["shadow_transmission"] for v in params["raytrace"]["dielectrics"])
+ control = copy.deepcopy(params)
+ for glass in control["raytrace"]["dielectrics"]:
+ glass["shadow_transmission"] = False
+ write(name.replace("-render.json", "-blocked-render.json"), control)
diff --git a/examples/studio/author_sweep.py b/examples/studio/author_sweep.py
new file mode 100644
index 0000000000..5bbaa86c9b
--- /dev/null
+++ b/examples/studio/author_sweep.py
@@ -0,0 +1,44 @@
+"""Original CAD cyclorama variants; preserves all product bodies and render setup."""
+import copy
+import json
+import math
+from author_scene import HERE, Scene, write
+
+
+def sweep_commands(scale):
+ # A YZ cross-section extruded along +X. Inner and outer circular arcs share
+ # a centre, so the floor and wall are tangent to a constant-thickness sweep.
+ width=3000*scale
+ front=-1500*scale
+ start=250*scale
+ radius=200*scale
+ height=1500*scale
+ thickness=4*scale
+ q=math.sqrt(.5)
+ s=Scene("Sweep construction")
+ s.commands.clear()
+ s.sketch("Studio floor",[-width/2,0,0],(0,1,0),(0,0,1))
+ s.cmd("sketch.line",points=[[front,0],[start,0]],infer=False)
+ s.cmd("sketch.arc.three_point",start=[start,0],
+ through=[start+radius*q,radius-radius*q],end=[start+radius,radius],id="inner_sweep")
+ s.cmd("sketch.line",points=[[start+radius,radius],[start+radius,height],
+ [start+radius+thickness,height],[start+radius+thickness,radius]],infer=False)
+ outer=radius+thickness
+ s.cmd("sketch.arc.three_point",start=[start+outer,radius],
+ through=[start+outer*q,radius-outer*q],end=[start,-thickness],id="outer_sweep")
+ s.cmd("sketch.line",points=[[start,-thickness],[front,-thickness],[front,0]],infer=False)
+ s.extrude("Studio floor",width,"floor")
+ return s.commands
+
+
+def variant(stem,scale):
+ recipe=json.loads((HERE/(stem+".json")).read_text(encoding="utf-8"))
+ result=copy.deepcopy(recipe)
+ assert result["commands"][1]["params"]["body_name"]=="Studio floor"
+ result["commands"][1:2]=sweep_commands(scale)
+ write(stem+"-sweep.json",result)
+
+
+if __name__=="__main__":
+ variant("stage1",1)
+ variant("coffee-exploded",2.8)
diff --git a/examples/studio/author_tumblers.py b/examples/studio/author_tumblers.py
new file mode 100644
index 0000000000..72c37e70b8
--- /dev/null
+++ b/examples/studio/author_tumblers.py
@@ -0,0 +1,142 @@
+"""Original CAD room and thick tumbler authoring; no third-party scene assets."""
+import math
+import copy
+from author_scene import Scene, MATERIALS, write
+
+MATERIALS.update({
+ "walnut": ("#4c2818",0,.42),
+ "linen": ("#ada69b",0,.88),
+ "pillow_ochre": ("#a66c32",0,.9),
+ "pillow_taupe": ("#71685e",0,.9),
+ "leaf": ("#315a2b",0,.6),
+ "stem": ("#425c2b",0,.75),
+ "soil": ("#23190f",0,1),
+ "ceramic": ("#b4b3a5",0,.38),
+ "wall": ("#ded9d1",0,.85),
+ "blind": ("#bdac91",0,.7),
+ "glass": ("#ffffff",0,.045),
+})
+
+
+def ellipsoid(s, name, center, radii, material, yaw=0):
+ s.sphere(name,[0,0,0],1,material)
+ s.cmd("solid.scale",bodies=[name],factors=radii)
+ if yaw:
+ s.cmd("solid.move",bodies=[name],axis=[0,0,1],angle=f"{yaw} deg")
+ s.cmd("solid.move",bodies=[name],translate=center)
+
+
+def cushion(s,name,center,size,radius,material,yaw=0):
+ half=[v/2 for v in size]
+ s.box(name,[-v for v in half],size,material)
+ edges=[]
+ for axis in range(3):
+ others=[i for i in range(3) if i!=axis]
+ for a in [-1,1]:
+ for b in [-1,1]:
+ p=[0,0,0]
+ p[others[0]]=a*half[others[0]]
+ p[others[1]]=b*half[others[1]]
+ edges.append(p)
+ s.cmd("solid.fillet",body=name,edges=edges,radius=radius)
+ if yaw:
+ s.cmd("solid.move",bodies=[name],axis=[0,0,1],angle=f"{yaw} deg")
+ s.cmd("solid.move",bodies=[name],translate=center)
+
+
+def tumbler(s,name,position,r0,r1,height,wall,bottom):
+ s.sketch(name,[0,0,0],(1,0,0),(0,0,1))
+ s.cmd("sketch.line",points=[[0,0],[r0,0],[r1,height],[r1-wall,height],[r0-wall,bottom],[0,bottom]],closed=True,infer=False)
+ s.cmd("sketch.finish")
+ s.cmd("solid.revolve",axis="y",angle="360 deg",operation="new",body_name=name)
+ s.body(name,"glass")
+ s.cmd("solid.move",bodies=[name],translate=position)
+
+
+def room():
+ s=Scene("Original two tumblers in a warm sitting room")
+ s.box("Room floor",[-2400,-1800,-30],[4800,4300,30],"floor")
+ s.box("Rear plaster wall",[-2400,2000,0],[4800,30,2300],"wall")
+ s.box("Left plaster wall",[-2400,-1800,0],[30,3800,2300],"wall")
+ s.rounded("Walnut tabletop",[0,0,445],1200,700,55,35,"walnut")
+ for i,(x,y) in enumerate([(-470,-230),(470,-230),(-470,230),(470,230)]):
+ s.rounded(f"Table leg {i+1}",[x,y,0],55,55,12,445,"walnut")
+ # Cups sit on the table; disjoint bounds allow independent dielectric media.
+ tumbler(s,"Tall thick tumbler",[-102,-88,480],36,42,112,4.5,9)
+ tumbler(s,"Short thick tumbler",[88,35,480],37,43,94,5,10)
+ # Original tailored sofa with distinct soft seats, arms, back and cushions.
+ s.rounded("Sofa plinth",[0,1075,95],1680,670,65,140,"pillow_taupe")
+ s.rounded("Sofa back",[0,1350,235],1680,160,65,510,"linen")
+ for side,x in [("Left",-760),("Right",760)]:
+ s.rounded(side+" sofa arm",[x,1050,235],160,650,60,345,"linen")
+ for i,x in enumerate([-460,0,460]):
+ cushion(s,f"Seat cushion {i+1}",[x,1020,285],[455,540,150],55,"linen")
+ cushion(s,f"Back cushion {i+1}",[x,1230,545],[450,180,405],65,"linen")
+ cushion(s,"Ochre throw cushion",[-520,1090,560],[315,130,330],55,"pillow_ochre",yaw=-18)
+ cushion(s,"Taupe throw cushion",[530,1115,545],[290,130,310],55,"pillow_taupe",yaw=16)
+ # Plant on a separate side stand, with independently modelled stems/leaves.
+ s.rounded("Plant stand",[620,575,0],200,200,30,430,"walnut")
+ s.cylinder("Ceramic plant pot",[620,575,430],82,146,"ceramic")
+ s.cmd("solid.cylinder",base=[620,575,442],radius=73,height=136,operation="cut",targets=["Ceramic plant pot"],name="Open ceramic pot")
+ s.cylinder("Pot soil",[620,575,550],71,8,"soil")
+ for i in range(12):
+ phi=math.radians(i*137.5)
+ reach=100+(i%3)*24
+ end=[620+math.cos(phi)*reach,575+math.sin(phi)*reach,730+(i%4)*62]
+ base=[620,575,556]
+ vec=[b-a for a,b in zip(base,end)]
+ length=math.sqrt(sum(v*v for v in vec))
+ s.cylinder(f"Plant stem {i+1}",base,2.5,length,"stem",axis=vec)
+ ellipsoid(s,f"Plant leaf {i+1}",end,[62,23,4],"leaf",yaw=i*137.5)
+ # A detached slatted window screen within the room receives a small bright
+ # light behind it. The gaps are geometry, not a projected shadow texture.
+ for i in range(14):
+ s.box(f"Window blind slat {i+1}",[-1030,1440,660+i*45],[850,52,12],"blind")
+ for x in [-1048,-180]:
+ s.box(f"Window jamb {x}",[x,1434,620],[18,70,710],"wall")
+ for z in [620,1320]:
+ s.box(f"Window rail {z}",[-1030,1434,z],[850,70,18],"wall")
+ for x in [-860,-350]:
+ s.cylinder(f"Blind cord {x}",[x,1425,635],1.5,690,"linen")
+ cam=dict(target=[-8,-8,537],yaw=math.radians(-10),pitch=math.radians(15),roll=0,distance=670,fov=math.radians(40))
+ materials=s.finish("tumblers",cam)
+ # Render request is deliberately separate from scene geometry and textures.
+ render={
+ "progressive":True,"samples":512,"max_depth":16,"seed":1948,"tone_map":"aces_fitted",
+ "settings":{"width":1920,"height":1080,"camera":cam,"background":[218,222,226]},
+ "lens":{"aperture_radius_mm":5.5,"focus_distance_mm":670},
+ "lighting":{"environment":[.22,.25,.30],"area_lights":[
+ {"center":[-650,1750,1470],"u":[95,0,0],"v":[0,0,95],"radiance":[38,30,21]},
+ {"center":[-550,-300,1350],"u":[450,0,0],"v":[0,-300,0],"radiance":[3.5,3.5,3.5]},
+ {"center":[850,300,1100],"u":[0,-240,0],"v":[0,0,300],"radiance":[2.5,2.7,3.0]}
+ ]},
+ "raytrace":{"dielectrics":[dict(body_index=i,body_name=name,ior=1.52,absorption_per_mm=[.0008,.00025,.00012],boundary="closed_mesh",thickness_mm=0)
+ for i,(name,mat) in enumerate(materials.items()) if mat=="glass"]}
+ }
+ write("tumblers-render.json",render)
+ # Sun variation retains the original baseline. A real rear-wall opening is
+ # necessary: an infinite sun cannot illuminate through the intact wall.
+ sun_scene=copy.deepcopy(s.commands)
+ sun_scene.append({"command":"solid.box","params":{
+ "corner":[-1450,1990,760],"length":1850,"width":50,"height":1080,
+ "operation":"cut","targets":["Rear plaster wall"],"name":"Sunlight window opening"}})
+ write("tumblers-sun.json",{"commands":sun_scene})
+ sun_render=copy.deepcopy(render)
+ sun_render["environment"]={"kind":"sky","gradient":{
+ "zenith":[.16,.32,.7],"horizon":[.8,.9,1],"ground":[.12,.1,.08]},
+ "intensity":1,"rotation_rad":0}
+ sun_render["lighting"]={"environment":[0,0,0],"area_lights":[],
+ "sun":{"direction":[-.4,1,.4],"angular_radius_rad":.00465,
+ "radiance":[18000,16500,14000]}}
+ write("tumblers-sun-render.json",sun_render)
+ write("tumblers-materials.json",{
+ "bodies":materials,
+ "texture_coordinates":{
+ "Walnut tabletop":{"projection":"world_xy","grain_direction":[1,0,0],"period_mm":[900,90],"note":"Original procedural walnut grain; do not copy photographs. Coordinate is mm, rotate grain along table long X axis."},
+ "linen":{"projection":"triplanar_world","period_mm":[3,3,3],"note":"Fine low-contrast original woven noise, use broad albedo and subtle normal perturbation. No material runtime API assumed."},
+ "glass":{"projection":"none","note":"Smooth thick dielectric; geometry provides rims and bases. No normal-map waviness requested for these tumblers."}
+ }})
+
+
+if __name__=="__main__":
+ room()
diff --git a/examples/studio/coffee-cylinder-render.json b/examples/studio/coffee-cylinder-render.json
new file mode 100644
index 0000000000..f5bd0bf07c
--- /dev/null
+++ b/examples/studio/coffee-cylinder-render.json
@@ -0,0 +1,182 @@
+{
+ "progressive": true,
+ "samples": 256,
+ "max_depth": 12,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -25,
+ -10,
+ 170
+ ],
+ "yaw": 0.5235987755982988,
+ "pitch": 0.3141592653589793,
+ "roll": 0,
+ "distance": 950,
+ "fov": 0.5934119456780721
+ },
+ "background": [
+ 240,
+ 240,
+ 240
+ ]
+ },
+ "lighting": {
+ "environment": [
+ 0.5,
+ 0.5,
+ 0.5
+ ],
+ "area_lights": [
+ {
+ "center": [
+ -392.0,
+ -364.0,
+ 784.0
+ ],
+ "u": [
+ 308.0,
+ 0.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ -196.0,
+ 0.0
+ ],
+ "radiance": [
+ 8,
+ 8,
+ 8
+ ]
+ },
+ {
+ "center": [
+ 784,
+ -448,
+ 504
+ ],
+ "u": [
+ 0.0,
+ -168.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ 0.0,
+ 251.99999999999997
+ ],
+ "radiance": [
+ 6,
+ 6,
+ 6
+ ]
+ },
+ {
+ "center": [
+ 0.0,
+ 475.99999999999994,
+ 700.0
+ ],
+ "u": [
+ 196.0,
+ 0.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ 0.0,
+ 182.0
+ ],
+ "radiance": [
+ 10,
+ 10,
+ 10
+ ]
+ }
+ ]
+ },
+ "raytrace": {
+ "clear_coats": [
+ {
+ "body_index": 1,
+ "body_name": "Housing plinth",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 2,
+ "body_name": "Housing shell",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 3,
+ "body_name": "Housing upper shoulder",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 5,
+ "body_name": "Open brewing head",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 6,
+ "body_name": "Brewing head roof",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 16,
+ "body_name": "Drip tray",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 18,
+ "body_name": "Rounded tray cap",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ }
+ ],
+ "dielectrics": [
+ {
+ "body_index": 12,
+ "body_name": "Smoky D tank",
+ "ior": 1.586,
+ "absorption_per_mm": [
+ 0.045,
+ 0.075,
+ 0.12
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ },
+ {
+ "body_index": 15,
+ "body_name": "Clear ribbed bin",
+ "ior": 1.49,
+ "absorption_per_mm": [
+ 0.0004,
+ 0.00015,
+ 5e-05
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ }
+ ]
+ }
+}
diff --git a/examples/studio/coffee-cylinder-sweep.json b/examples/studio/coffee-cylinder-sweep.json
new file mode 100644
index 0000000000..0c31485775
--- /dev/null
+++ b/examples/studio/coffee-cylinder-sweep.json
@@ -0,0 +1,3807 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original exploded cylindrical coffee machine"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Studio floor profile",
+ "plane": {
+ "origin": [
+ -4200.0,
+ 0,
+ 0
+ ],
+ "x_dir": [
+ 0,
+ 1,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -4200.0,
+ 0
+ ],
+ [
+ 700.0,
+ 0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 700.0,
+ 0
+ ],
+ "through": [
+ 1095.9797974644666,
+ 164.02020253553337
+ ],
+ "end": [
+ 1260.0,
+ 560.0
+ ],
+ "id": "inner_sweep"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 1260.0,
+ 560.0
+ ],
+ [
+ 1260.0,
+ 4200.0
+ ],
+ [
+ 1271.2,
+ 4200.0
+ ],
+ [
+ 1271.2,
+ 560.0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 1271.2,
+ 560.0
+ ],
+ "through": [
+ 1103.8993934137561,
+ 156.100606586244
+ ],
+ "end": [
+ 700.0,
+ -11.2
+ ],
+ "id": "outer_sweep"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 700.0,
+ -11.2
+ ],
+ [
+ -4200.0,
+ -11.2
+ ],
+ [
+ -4200.0,
+ 0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 8400.0,
+ "operation": "new",
+ "body_name": "Studio floor"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Housing plinth",
+ "base": [
+ 0,
+ 8,
+ 30
+ ],
+ "radius": 76,
+ "height": 12,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Housing shell",
+ "base": [
+ 0,
+ 8,
+ 55
+ ],
+ "radius": 70,
+ "height": 210,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 8,
+ 54
+ ],
+ "radius": 65,
+ "height": 212,
+ "axis": "Z",
+ "operation": "cut",
+ "targets": [
+ "Housing shell"
+ ],
+ "name": "Through cylindrical housing cavity"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -47,
+ -80,
+ 88
+ ],
+ "length": 94,
+ "width": 80,
+ "height": 149,
+ "operation": "cut",
+ "targets": [
+ "Housing shell"
+ ],
+ "name": "Open brewing bay"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Housing upper shoulder",
+ "base": [
+ 0,
+ 8,
+ 265
+ ],
+ "radius": 70,
+ "height": 8,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Internal chassis",
+ "corner": [
+ -42,
+ 38,
+ 63
+ ],
+ "length": 84,
+ "width": 5,
+ "height": 189,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Open brewing head",
+ "base": [
+ 0,
+ -76,
+ 307
+ ],
+ "radius": 43,
+ "height": 95,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -77,
+ 307
+ ],
+ "radius": 31,
+ "height": 97,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Open brewing head"
+ ],
+ "name": "Horizontal open brew bore"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Brewing head roof profile",
+ "plane": {
+ "origin": [
+ 0,
+ -6,
+ 352
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -57.5,
+ -51.5
+ ],
+ "p1": [
+ 57.5,
+ 51.5
+ ],
+ "radius": 25
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 7,
+ "operation": "new",
+ "body_name": "Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -18,
+ -9,
+ 351
+ ],
+ "length": 36,
+ "width": 7,
+ "height": 9,
+ "operation": "cut",
+ "targets": [
+ "Brewing head roof"
+ ],
+ "name": "Capsule loading slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Brewing collar",
+ "base": [
+ 0,
+ -88,
+ 307
+ ],
+ "radius": 35,
+ "height": 9,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -89,
+ 307
+ ],
+ "radius": 28,
+ "height": 11,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Brewing collar"
+ ],
+ "name": "Open brew throat"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Shower screen",
+ "base": [
+ 0,
+ 10,
+ 307
+ ],
+ "radius": 27,
+ "height": 2,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Lever centerline profile",
+ "plane": {
+ "origin": [
+ 0,
+ -28,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -77,
+ 306
+ ],
+ [
+ -77,
+ 365
+ ]
+ ],
+ "ids": [
+ "lever_left"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ -77,
+ 365
+ ],
+ "through": [
+ -72.6066,
+ 375.6066
+ ],
+ "end": [
+ -62,
+ 380
+ ],
+ "id": "lever_bend_left"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -62,
+ 380
+ ],
+ [
+ 62,
+ 380
+ ]
+ ],
+ "ids": [
+ "lever_top"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 62,
+ 380
+ ],
+ "through": [
+ 72.6066,
+ 375.6066
+ ],
+ "end": [
+ 77,
+ 365
+ ],
+ "id": "lever_bend_right"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 77,
+ 365
+ ],
+ [
+ 77,
+ 306
+ ]
+ ],
+ "ids": [
+ "lever_right"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "Lever centerline profile",
+ "path": [
+ "lever_left",
+ "lever_bend_left",
+ "lever_top",
+ "lever_bend_right",
+ "lever_right"
+ ],
+ "diameter": 9,
+ "operation": "new",
+ "body_name": "Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Left lever ball",
+ "center": [
+ -77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Right lever ball",
+ "center": [
+ 77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Smoky D tank profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 99
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -43,
+ 0
+ ],
+ [
+ -43,
+ 45
+ ],
+ [
+ 43,
+ 45
+ ],
+ [
+ 43,
+ 0
+ ],
+ [
+ 42.948204616822416,
+ -2.1099099960789744
+ ],
+ [
+ 42.79294324690447,
+ -4.214737034171106
+ ],
+ [
+ 42.53458992848558,
+ -6.309410401580555
+ ],
+ [
+ 42.17376705733891,
+ -8.388883846693515
+ ],
+ [
+ 41.71134388736539,
+ -10.448147735840346
+ ],
+ [
+ 41.148434436484976,
+ -12.48224112194188
+ ],
+ [
+ 40.486394802869896,
+ -14.486263695865462
+ ],
+ [
+ 39.72681989798533,
+ -16.455387591698862
+ ],
+ [
+ 38.87153960430806,
+ -18.38486901750213
+ ],
+ [
+ 37.92261436697927,
+ -20.2700596835179
+ ],
+ [
+ 36.8823302300117,
+ -22.10641800030853
+ ],
+ [
+ 35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ 34.537923853667735,
+ -25.615070093174634
+ ],
+ [
+ 33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ 31.860898390263245,
+ -28.87703505842179
+ ],
+ [
+ 30.405591591021544,
+ -30.405591591021544
+ ],
+ [
+ 28.87703505842179,
+ -31.86089839026324
+ ],
+ [
+ 27.278911219036758,
+ -33.239449494597686
+ ],
+ [
+ 25.61507009317464,
+ -34.53792385366773
+ ],
+ [
+ 23.889520019842898,
+ -35.75319332900945
+ ],
+ [
+ 22.10641800030853,
+ -36.8823302300117
+ ],
+ [
+ 20.270059683517907,
+ -37.92261436697926
+ ],
+ [
+ 18.384869017502133,
+ -38.87153960430806
+ ],
+ [
+ 16.455387591698862,
+ -39.72681989798533
+ ],
+ [
+ 14.486263695865462,
+ -40.486394802869896
+ ],
+ [
+ 12.48224112194188,
+ -41.14843443648498
+ ],
+ [
+ 10.448147735840351,
+ -41.71134388736539
+ ],
+ [
+ 8.388883846693519,
+ -42.17376705733891
+ ],
+ [
+ 6.309410401580555,
+ -42.53458992848558
+ ],
+ [
+ 4.2147370341711135,
+ -42.792943246904464
+ ],
+ [
+ 2.1099099960789793,
+ -42.948204616822416
+ ],
+ [
+ 2.6329906181668092e-15,
+ -43.0
+ ],
+ [
+ -2.1099099960789744,
+ -42.948204616822416
+ ],
+ [
+ -4.214737034171108,
+ -42.79294324690447
+ ],
+ [
+ -6.309410401580551,
+ -42.53458992848558
+ ],
+ [
+ -8.388883846693512,
+ -42.17376705733891
+ ],
+ [
+ -10.448147735840346,
+ -41.71134388736539
+ ],
+ [
+ -12.482241121941874,
+ -41.14843443648498
+ ],
+ [
+ -14.486263695865457,
+ -40.486394802869896
+ ],
+ [
+ -16.45538759169886,
+ -39.72681989798533
+ ],
+ [
+ -18.38486901750212,
+ -38.87153960430807
+ ],
+ [
+ -20.2700596835179,
+ -37.92261436697927
+ ],
+ [
+ -22.106418000308526,
+ -36.8823302300117
+ ],
+ [
+ -23.889520019842884,
+ -35.75319332900945
+ ],
+ [
+ -25.615070093174634,
+ -34.537923853667735
+ ],
+ [
+ -27.27891121903675,
+ -33.23944949459769
+ ],
+ [
+ -28.877035058421793,
+ -31.860898390263237
+ ],
+ [
+ -30.40559159102154,
+ -30.405591591021544
+ ],
+ [
+ -31.86089839026323,
+ -28.877035058421797
+ ],
+ [
+ -33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ -34.53792385366773,
+ -25.61507009317464
+ ],
+ [
+ -35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ -36.882330230011696,
+ -22.106418000308537
+ ],
+ [
+ -37.92261436697926,
+ -20.270059683517907
+ ],
+ [
+ -38.87153960430806,
+ -18.384869017502126
+ ],
+ [
+ -39.72681989798533,
+ -16.455387591698866
+ ],
+ [
+ -40.48639480286989,
+ -14.486263695865475
+ ],
+ [
+ -41.148434436484976,
+ -12.482241121941883
+ ],
+ [
+ -41.71134388736539,
+ -10.448147735840354
+ ],
+ [
+ -42.17376705733891,
+ -8.38888384669353
+ ],
+ [
+ -42.53458992848558,
+ -6.309410401580558
+ ],
+ [
+ -42.792943246904464,
+ -4.214737034171115
+ ],
+ [
+ -42.948204616822416,
+ -2.1099099960789727
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 171,
+ "operation": "new",
+ "body_name": "Smoky D tank"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank cavity profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 103
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -40,
+ 0
+ ],
+ [
+ -40,
+ 42
+ ],
+ [
+ 40,
+ 42
+ ],
+ [
+ 40,
+ 0
+ ],
+ [
+ 39.9518182482069,
+ -1.9627069730967206
+ ],
+ [
+ 39.80738906688788,
+ -3.920685613182424
+ ],
+ [
+ 39.56706039859124,
+ -5.8692189782144695
+ ],
+ [
+ 39.23141121612922,
+ -7.8036128806451295
+ ],
+ [
+ 38.801250127781756,
+ -9.719207196130554
+ ],
+ [
+ 38.27761342928835,
+ -11.611387090178493
+ ],
+ [
+ 37.66176260732083,
+ -13.475594135688802
+ ],
+ [
+ 36.95518130045147,
+ -15.307337294603592
+ ],
+ [
+ 36.159571724937734,
+ -17.102203737211283
+ ],
+ [
+ 35.276850573934205,
+ -18.855869473039906
+ ],
+ [
+ 34.30914440001089,
+ -20.564109767728866
+ ],
+ [
+ 33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ 32.1283012592258,
+ -23.827972179697333
+ ],
+ [
+ 30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ 29.63804501419837,
+ -26.862358193880734
+ ],
+ [
+ 28.284271247461902,
+ -28.284271247461902
+ ],
+ [
+ 26.862358193880734,
+ -29.638045014198365
+ ],
+ [
+ 25.37573136654582,
+ -30.920418134509475
+ ],
+ [
+ 23.82797217969734,
+ -32.12830125922579
+ ],
+ [
+ 22.22280932078409,
+ -33.25878449210181
+ ],
+ [
+ 20.564109767728866,
+ -34.30914440001089
+ ],
+ [
+ 18.855869473039913,
+ -35.2768505739342
+ ],
+ [
+ 17.102203737211287,
+ -36.159571724937734
+ ],
+ [
+ 15.307337294603593,
+ -36.95518130045147
+ ],
+ [
+ 13.475594135688802,
+ -37.66176260732083
+ ],
+ [
+ 11.611387090178493,
+ -38.27761342928836
+ ],
+ [
+ 9.71920719613056,
+ -38.801250127781756
+ ],
+ [
+ 7.803612880645133,
+ -39.23141121612922
+ ],
+ [
+ 5.8692189782144695,
+ -39.56706039859124
+ ],
+ [
+ 3.920685613182431,
+ -39.80738906688787
+ ],
+ [
+ 1.962706973096725,
+ -39.9518182482069
+ ],
+ [
+ 2.4492935982947065e-15,
+ -40.0
+ ],
+ [
+ -1.9627069730967204,
+ -39.9518182482069
+ ],
+ [
+ -3.920685613182426,
+ -39.80738906688788
+ ],
+ [
+ -5.869218978214466,
+ -39.56706039859124
+ ],
+ [
+ -7.803612880645128,
+ -39.23141121612922
+ ],
+ [
+ -9.719207196130554,
+ -38.801250127781756
+ ],
+ [
+ -11.611387090178486,
+ -38.27761342928836
+ ],
+ [
+ -13.475594135688798,
+ -37.66176260732083
+ ],
+ [
+ -15.307337294603588,
+ -36.95518130045147
+ ],
+ [
+ -17.102203737211276,
+ -36.159571724937734
+ ],
+ [
+ -18.85586947303991,
+ -35.276850573934205
+ ],
+ [
+ -20.564109767728862,
+ -34.30914440001089
+ ],
+ [
+ -22.22280932078408,
+ -33.25878449210181
+ ],
+ [
+ -23.827972179697333,
+ -32.1283012592258
+ ],
+ [
+ -25.375731366545814,
+ -30.920418134509482
+ ],
+ [
+ -26.862358193880738,
+ -29.63804501419836
+ ],
+ [
+ -28.2842712474619,
+ -28.284271247461902
+ ],
+ [
+ -29.638045014198354,
+ -26.86235819388074
+ ],
+ [
+ -30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ -32.12830125922579,
+ -23.82797217969734
+ ],
+ [
+ -33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ -34.30914440001088,
+ -20.564109767728873
+ ],
+ [
+ -35.2768505739342,
+ -18.855869473039913
+ ],
+ [
+ -36.159571724937734,
+ -17.10220373721128
+ ],
+ [
+ -36.95518130045147,
+ -15.307337294603595
+ ],
+ [
+ -37.661762607320824,
+ -13.475594135688812
+ ],
+ [
+ -38.27761342928835,
+ -11.611387090178496
+ ],
+ [
+ -38.801250127781756,
+ -9.719207196130563
+ ],
+ [
+ -39.23141121612922,
+ -7.803612880645145
+ ],
+ [
+ -39.56706039859124,
+ -5.869218978214472
+ ],
+ [
+ -39.80738906688787,
+ -3.920685613182433
+ ],
+ [
+ -39.9518182482069,
+ -1.9627069730967186
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 169,
+ "operation": "cut",
+ "targets": [
+ "Smoky D tank"
+ ],
+ "name": "Open tank cavity with four millimetre base"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Separate tank lid profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 304
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -45,
+ 0
+ ],
+ [
+ -45,
+ 47
+ ],
+ [
+ 45,
+ 47
+ ],
+ [
+ 45,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 45,
+ 0
+ ],
+ "end": [
+ -45,
+ 0
+ ],
+ "through": [
+ 0,
+ -45
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Separate tank lid"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank lid grip profile",
+ "plane": {
+ "origin": [
+ 225,
+ 41,
+ 309
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -6.0
+ ],
+ "p1": [
+ 19.0,
+ 6.0
+ ],
+ "radius": 5
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Tank lid grip"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Clear ribbed bin profile",
+ "plane": {
+ "origin": [
+ -157,
+ -23,
+ 58
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -33.0,
+ -30
+ ],
+ [
+ -31.2,
+ -32
+ ],
+ [
+ -29.5,
+ -30
+ ],
+ [
+ -27.5,
+ -30
+ ],
+ [
+ -25.7,
+ -32
+ ],
+ [
+ -24.0,
+ -30
+ ],
+ [
+ -22.0,
+ -30
+ ],
+ [
+ -20.2,
+ -32
+ ],
+ [
+ -18.5,
+ -30
+ ],
+ [
+ -16.5,
+ -30
+ ],
+ [
+ -14.7,
+ -32
+ ],
+ [
+ -13.0,
+ -30
+ ],
+ [
+ -11.0,
+ -30
+ ],
+ [
+ -9.2,
+ -32
+ ],
+ [
+ -7.5,
+ -30
+ ],
+ [
+ -5.5,
+ -30
+ ],
+ [
+ -3.7,
+ -32
+ ],
+ [
+ -2.0,
+ -30
+ ],
+ [
+ 0.0,
+ -30
+ ],
+ [
+ 1.8,
+ -32
+ ],
+ [
+ 3.5,
+ -30
+ ],
+ [
+ 5.5,
+ -30
+ ],
+ [
+ 7.3,
+ -32
+ ],
+ [
+ 9.0,
+ -30
+ ],
+ [
+ 11.0,
+ -30
+ ],
+ [
+ 12.8,
+ -32
+ ],
+ [
+ 14.5,
+ -30
+ ],
+ [
+ 16.5,
+ -30
+ ],
+ [
+ 18.3,
+ -32
+ ],
+ [
+ 20.0,
+ -30
+ ],
+ [
+ 22.0,
+ -30
+ ],
+ [
+ 23.8,
+ -32
+ ],
+ [
+ 25.5,
+ -30
+ ],
+ [
+ 27.5,
+ -30
+ ],
+ [
+ 29.3,
+ -32
+ ],
+ [
+ 31.0,
+ -30
+ ],
+ [
+ 33,
+ -30
+ ],
+ [
+ 33,
+ 30
+ ],
+ [
+ -33,
+ 30
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.rectangle.two_point",
+ "params": {
+ "p0": [
+ -30,
+ -27
+ ],
+ "p1": [
+ 30,
+ 27
+ ]
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 72,
+ "operation": "new",
+ "body_name": "Clear ribbed bin",
+ "profiles": [
+ {
+ "point": [
+ 31,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Bin base tool",
+ "corner": [
+ -190,
+ -53,
+ 57
+ ],
+ "length": 66,
+ "width": 60,
+ "height": 4,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Clear ribbed bin",
+ "tools": [
+ "Bin base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Drip tray profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 22
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "innerleft",
+ "innerback",
+ "innerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "innerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Drip tray",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 41.0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tray base tool profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 21
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 4,
+ "operation": "new",
+ "body_name": "Tray base tool"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Drip tray",
+ "tools": [
+ "Tray base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Perforated stainless grate profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 65
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 2,
+ "operation": "new",
+ "body_name": "Perforated stainless grate",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 38
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Rounded tray cap profile",
+ "plane": {
+ "origin": [
+ 112,
+ -143,
+ 40
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -27.0
+ ],
+ "p1": [
+ 19.0,
+ 27.0
+ ],
+ "radius": 15
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Rounded tray cap"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Louvred service panel profile",
+ "plane": {
+ "origin": [
+ -122,
+ 143,
+ 173
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -47,
+ -91
+ ],
+ "p1": [
+ 47,
+ 91
+ ],
+ "radius": 8
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -62
+ ],
+ "p1": [
+ 31,
+ -58
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -47
+ ],
+ "p1": [
+ 31,
+ -43
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -32
+ ],
+ "p1": [
+ 31,
+ -28
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -17
+ ],
+ "p1": [
+ 31,
+ -13
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -2
+ ],
+ "p1": [
+ 31,
+ 2
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 13
+ ],
+ "p1": [
+ 31,
+ 17
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 28
+ ],
+ "p1": [
+ 31,
+ 32
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 43
+ ],
+ "p1": [
+ 31,
+ 47
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 58
+ ],
+ "p1": [
+ 31,
+ 62
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 3,
+ "operation": "new",
+ "body_name": "Louvred service panel",
+ "profiles": [
+ {
+ "point": [
+ 43,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 1",
+ "base": [
+ -99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 2",
+ "base": [
+ -99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 3",
+ "base": [
+ -99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 4",
+ "base": [
+ -99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 5",
+ "base": [
+ 99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 6",
+ "base": [
+ 99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 7",
+ "base": [
+ 99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 8",
+ "base": [
+ 99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "S cable centerline profile",
+ "plane": {
+ "origin": [
+ 70,
+ -75,
+ 9
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 52,
+ 94
+ ],
+ "through": [
+ 92,
+ 54
+ ],
+ "end": [
+ 132,
+ 94
+ ],
+ "id": "cable_a"
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 132,
+ 94
+ ],
+ "through": [
+ 172,
+ 134
+ ],
+ "end": [
+ 212,
+ 94
+ ],
+ "id": "cable_b"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 212,
+ 94
+ ],
+ [
+ 212,
+ 66
+ ]
+ ],
+ "ids": [
+ "cable_end"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "S cable centerline profile",
+ "path": [
+ "cable_a",
+ "cable_b",
+ "cable_end"
+ ],
+ "diameter": 5,
+ "operation": "new",
+ "body_name": "Black S power cable"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Two pin plug profile",
+ "plane": {
+ "origin": [
+ 282,
+ -30,
+ 3
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -12.0,
+ -17.5
+ ],
+ "p1": [
+ 12.0,
+ 17.5
+ ],
+ "radius": 7
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Two pin plug"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 206",
+ "base": [
+ 276,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 218",
+ "base": [
+ 288,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Housing plinth",
+ "Housing shell",
+ "Housing upper shoulder",
+ "Open brewing head",
+ "Brewing head roof",
+ "Drip tray",
+ "Rounded tray cap"
+ ],
+ "color": "#101318",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.3,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Separate tank lid",
+ "Tank lid grip",
+ "Louvred service panel"
+ ],
+ "color": "#171a1f",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.55,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Brewing collar",
+ "Bent chrome lever",
+ "Left lever ball",
+ "Right lever ball",
+ "Plug pin 206",
+ "Plug pin 218"
+ ],
+ "color": "#d5d9dd",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.12,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Internal chassis",
+ "Shower screen",
+ "Perforated stainless grate"
+ ],
+ "color": "#aeb4bb",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.25,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Zinc screw 1",
+ "Zinc screw 2",
+ "Zinc screw 3",
+ "Zinc screw 4",
+ "Zinc screw 5",
+ "Zinc screw 6",
+ "Zinc screw 7",
+ "Zinc screw 8"
+ ],
+ "color": "#b0b5bc",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.32,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Black S power cable",
+ "Two pin plug"
+ ],
+ "color": "#141414",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.8,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Studio floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "color": "#c2c6ca",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "color": "#e4eff1",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Open brewing head"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Open brewing head"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Brewing collar"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Brewing collar"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Shower screen"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Shower screen"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Brewing head roof"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Bent chrome lever"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Left lever ball"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Left lever ball"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Right lever ball"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Right lever ball"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Smoky D tank"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Separate tank lid"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 22
+ ],
+ "copy": false,
+ "name": "Framing: Separate tank lid"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Tank lid grip"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 22
+ ],
+ "copy": false,
+ "name": "Framing: Tank lid grip"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "translate": [
+ -70,
+ -15,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Clear ribbed bin"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Louvred service panel"
+ ],
+ "translate": [
+ -110,
+ 15,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Louvred service panel"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Drip tray"
+ ],
+ "translate": [
+ 0,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Drip tray"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Perforated stainless grate"
+ ],
+ "translate": [
+ 0,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Perforated stainless grate"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Rounded tray cap"
+ ],
+ "translate": [
+ 38,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Rounded tray cap"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Black S power cable"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Black S power cable"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Two pin plug"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Two pin plug"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plug pin 206"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Plug pin 206"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plug pin 218"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Plug pin 218"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 1"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 1"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 2"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 2"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 3"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 3"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 4"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 4"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 5"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 5"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 6"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 6"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 7"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 7"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 8"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 8"
+ }
+ }
+ ]
+}
diff --git a/examples/studio/coffee-cylinder.json b/examples/studio/coffee-cylinder.json
new file mode 100644
index 0000000000..49e9af4847
--- /dev/null
+++ b/examples/studio/coffee-cylinder.json
@@ -0,0 +1,3691 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original exploded cylindrical coffee machine"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Studio floor",
+ "corner": [
+ -6000,
+ -6000,
+ -5
+ ],
+ "length": 12000,
+ "width": 12000,
+ "height": 5,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Housing plinth",
+ "base": [
+ 0,
+ 8,
+ 30
+ ],
+ "radius": 76,
+ "height": 12,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Housing shell",
+ "base": [
+ 0,
+ 8,
+ 55
+ ],
+ "radius": 70,
+ "height": 210,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 8,
+ 54
+ ],
+ "radius": 65,
+ "height": 212,
+ "axis": "Z",
+ "operation": "cut",
+ "targets": [
+ "Housing shell"
+ ],
+ "name": "Through cylindrical housing cavity"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -47,
+ -80,
+ 88
+ ],
+ "length": 94,
+ "width": 80,
+ "height": 149,
+ "operation": "cut",
+ "targets": [
+ "Housing shell"
+ ],
+ "name": "Open brewing bay"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Housing upper shoulder",
+ "base": [
+ 0,
+ 8,
+ 265
+ ],
+ "radius": 70,
+ "height": 8,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Internal chassis",
+ "corner": [
+ -42,
+ 38,
+ 63
+ ],
+ "length": 84,
+ "width": 5,
+ "height": 189,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Open brewing head",
+ "base": [
+ 0,
+ -76,
+ 307
+ ],
+ "radius": 43,
+ "height": 95,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -77,
+ 307
+ ],
+ "radius": 31,
+ "height": 97,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Open brewing head"
+ ],
+ "name": "Horizontal open brew bore"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Brewing head roof profile",
+ "plane": {
+ "origin": [
+ 0,
+ -6,
+ 352
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -57.5,
+ -51.5
+ ],
+ "p1": [
+ 57.5,
+ 51.5
+ ],
+ "radius": 25
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 7,
+ "operation": "new",
+ "body_name": "Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -18,
+ -9,
+ 351
+ ],
+ "length": 36,
+ "width": 7,
+ "height": 9,
+ "operation": "cut",
+ "targets": [
+ "Brewing head roof"
+ ],
+ "name": "Capsule loading slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Brewing collar",
+ "base": [
+ 0,
+ -88,
+ 307
+ ],
+ "radius": 35,
+ "height": 9,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -89,
+ 307
+ ],
+ "radius": 28,
+ "height": 11,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Brewing collar"
+ ],
+ "name": "Open brew throat"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Shower screen",
+ "base": [
+ 0,
+ 10,
+ 307
+ ],
+ "radius": 27,
+ "height": 2,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Lever centerline profile",
+ "plane": {
+ "origin": [
+ 0,
+ -28,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -77,
+ 306
+ ],
+ [
+ -77,
+ 365
+ ]
+ ],
+ "ids": [
+ "lever_left"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ -77,
+ 365
+ ],
+ "through": [
+ -72.6066,
+ 375.6066
+ ],
+ "end": [
+ -62,
+ 380
+ ],
+ "id": "lever_bend_left"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -62,
+ 380
+ ],
+ [
+ 62,
+ 380
+ ]
+ ],
+ "ids": [
+ "lever_top"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 62,
+ 380
+ ],
+ "through": [
+ 72.6066,
+ 375.6066
+ ],
+ "end": [
+ 77,
+ 365
+ ],
+ "id": "lever_bend_right"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 77,
+ 365
+ ],
+ [
+ 77,
+ 306
+ ]
+ ],
+ "ids": [
+ "lever_right"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "Lever centerline profile",
+ "path": [
+ "lever_left",
+ "lever_bend_left",
+ "lever_top",
+ "lever_bend_right",
+ "lever_right"
+ ],
+ "diameter": 9,
+ "operation": "new",
+ "body_name": "Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Left lever ball",
+ "center": [
+ -77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Right lever ball",
+ "center": [
+ 77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Smoky D tank profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 99
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -43,
+ 0
+ ],
+ [
+ -43,
+ 45
+ ],
+ [
+ 43,
+ 45
+ ],
+ [
+ 43,
+ 0
+ ],
+ [
+ 42.948204616822416,
+ -2.1099099960789744
+ ],
+ [
+ 42.79294324690447,
+ -4.214737034171106
+ ],
+ [
+ 42.53458992848558,
+ -6.309410401580555
+ ],
+ [
+ 42.17376705733891,
+ -8.388883846693515
+ ],
+ [
+ 41.71134388736539,
+ -10.448147735840346
+ ],
+ [
+ 41.148434436484976,
+ -12.48224112194188
+ ],
+ [
+ 40.486394802869896,
+ -14.486263695865462
+ ],
+ [
+ 39.72681989798533,
+ -16.455387591698862
+ ],
+ [
+ 38.87153960430806,
+ -18.38486901750213
+ ],
+ [
+ 37.92261436697927,
+ -20.2700596835179
+ ],
+ [
+ 36.8823302300117,
+ -22.10641800030853
+ ],
+ [
+ 35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ 34.537923853667735,
+ -25.615070093174634
+ ],
+ [
+ 33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ 31.860898390263245,
+ -28.87703505842179
+ ],
+ [
+ 30.405591591021544,
+ -30.405591591021544
+ ],
+ [
+ 28.87703505842179,
+ -31.86089839026324
+ ],
+ [
+ 27.278911219036758,
+ -33.239449494597686
+ ],
+ [
+ 25.61507009317464,
+ -34.53792385366773
+ ],
+ [
+ 23.889520019842898,
+ -35.75319332900945
+ ],
+ [
+ 22.10641800030853,
+ -36.8823302300117
+ ],
+ [
+ 20.270059683517907,
+ -37.92261436697926
+ ],
+ [
+ 18.384869017502133,
+ -38.87153960430806
+ ],
+ [
+ 16.455387591698862,
+ -39.72681989798533
+ ],
+ [
+ 14.486263695865462,
+ -40.486394802869896
+ ],
+ [
+ 12.48224112194188,
+ -41.14843443648498
+ ],
+ [
+ 10.448147735840351,
+ -41.71134388736539
+ ],
+ [
+ 8.388883846693519,
+ -42.17376705733891
+ ],
+ [
+ 6.309410401580555,
+ -42.53458992848558
+ ],
+ [
+ 4.2147370341711135,
+ -42.792943246904464
+ ],
+ [
+ 2.1099099960789793,
+ -42.948204616822416
+ ],
+ [
+ 2.6329906181668092e-15,
+ -43.0
+ ],
+ [
+ -2.1099099960789744,
+ -42.948204616822416
+ ],
+ [
+ -4.214737034171108,
+ -42.79294324690447
+ ],
+ [
+ -6.309410401580551,
+ -42.53458992848558
+ ],
+ [
+ -8.388883846693512,
+ -42.17376705733891
+ ],
+ [
+ -10.448147735840346,
+ -41.71134388736539
+ ],
+ [
+ -12.482241121941874,
+ -41.14843443648498
+ ],
+ [
+ -14.486263695865457,
+ -40.486394802869896
+ ],
+ [
+ -16.45538759169886,
+ -39.72681989798533
+ ],
+ [
+ -18.38486901750212,
+ -38.87153960430807
+ ],
+ [
+ -20.2700596835179,
+ -37.92261436697927
+ ],
+ [
+ -22.106418000308526,
+ -36.8823302300117
+ ],
+ [
+ -23.889520019842884,
+ -35.75319332900945
+ ],
+ [
+ -25.615070093174634,
+ -34.537923853667735
+ ],
+ [
+ -27.27891121903675,
+ -33.23944949459769
+ ],
+ [
+ -28.877035058421793,
+ -31.860898390263237
+ ],
+ [
+ -30.40559159102154,
+ -30.405591591021544
+ ],
+ [
+ -31.86089839026323,
+ -28.877035058421797
+ ],
+ [
+ -33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ -34.53792385366773,
+ -25.61507009317464
+ ],
+ [
+ -35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ -36.882330230011696,
+ -22.106418000308537
+ ],
+ [
+ -37.92261436697926,
+ -20.270059683517907
+ ],
+ [
+ -38.87153960430806,
+ -18.384869017502126
+ ],
+ [
+ -39.72681989798533,
+ -16.455387591698866
+ ],
+ [
+ -40.48639480286989,
+ -14.486263695865475
+ ],
+ [
+ -41.148434436484976,
+ -12.482241121941883
+ ],
+ [
+ -41.71134388736539,
+ -10.448147735840354
+ ],
+ [
+ -42.17376705733891,
+ -8.38888384669353
+ ],
+ [
+ -42.53458992848558,
+ -6.309410401580558
+ ],
+ [
+ -42.792943246904464,
+ -4.214737034171115
+ ],
+ [
+ -42.948204616822416,
+ -2.1099099960789727
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 171,
+ "operation": "new",
+ "body_name": "Smoky D tank"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank cavity profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 103
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -40,
+ 0
+ ],
+ [
+ -40,
+ 42
+ ],
+ [
+ 40,
+ 42
+ ],
+ [
+ 40,
+ 0
+ ],
+ [
+ 39.9518182482069,
+ -1.9627069730967206
+ ],
+ [
+ 39.80738906688788,
+ -3.920685613182424
+ ],
+ [
+ 39.56706039859124,
+ -5.8692189782144695
+ ],
+ [
+ 39.23141121612922,
+ -7.8036128806451295
+ ],
+ [
+ 38.801250127781756,
+ -9.719207196130554
+ ],
+ [
+ 38.27761342928835,
+ -11.611387090178493
+ ],
+ [
+ 37.66176260732083,
+ -13.475594135688802
+ ],
+ [
+ 36.95518130045147,
+ -15.307337294603592
+ ],
+ [
+ 36.159571724937734,
+ -17.102203737211283
+ ],
+ [
+ 35.276850573934205,
+ -18.855869473039906
+ ],
+ [
+ 34.30914440001089,
+ -20.564109767728866
+ ],
+ [
+ 33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ 32.1283012592258,
+ -23.827972179697333
+ ],
+ [
+ 30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ 29.63804501419837,
+ -26.862358193880734
+ ],
+ [
+ 28.284271247461902,
+ -28.284271247461902
+ ],
+ [
+ 26.862358193880734,
+ -29.638045014198365
+ ],
+ [
+ 25.37573136654582,
+ -30.920418134509475
+ ],
+ [
+ 23.82797217969734,
+ -32.12830125922579
+ ],
+ [
+ 22.22280932078409,
+ -33.25878449210181
+ ],
+ [
+ 20.564109767728866,
+ -34.30914440001089
+ ],
+ [
+ 18.855869473039913,
+ -35.2768505739342
+ ],
+ [
+ 17.102203737211287,
+ -36.159571724937734
+ ],
+ [
+ 15.307337294603593,
+ -36.95518130045147
+ ],
+ [
+ 13.475594135688802,
+ -37.66176260732083
+ ],
+ [
+ 11.611387090178493,
+ -38.27761342928836
+ ],
+ [
+ 9.71920719613056,
+ -38.801250127781756
+ ],
+ [
+ 7.803612880645133,
+ -39.23141121612922
+ ],
+ [
+ 5.8692189782144695,
+ -39.56706039859124
+ ],
+ [
+ 3.920685613182431,
+ -39.80738906688787
+ ],
+ [
+ 1.962706973096725,
+ -39.9518182482069
+ ],
+ [
+ 2.4492935982947065e-15,
+ -40.0
+ ],
+ [
+ -1.9627069730967204,
+ -39.9518182482069
+ ],
+ [
+ -3.920685613182426,
+ -39.80738906688788
+ ],
+ [
+ -5.869218978214466,
+ -39.56706039859124
+ ],
+ [
+ -7.803612880645128,
+ -39.23141121612922
+ ],
+ [
+ -9.719207196130554,
+ -38.801250127781756
+ ],
+ [
+ -11.611387090178486,
+ -38.27761342928836
+ ],
+ [
+ -13.475594135688798,
+ -37.66176260732083
+ ],
+ [
+ -15.307337294603588,
+ -36.95518130045147
+ ],
+ [
+ -17.102203737211276,
+ -36.159571724937734
+ ],
+ [
+ -18.85586947303991,
+ -35.276850573934205
+ ],
+ [
+ -20.564109767728862,
+ -34.30914440001089
+ ],
+ [
+ -22.22280932078408,
+ -33.25878449210181
+ ],
+ [
+ -23.827972179697333,
+ -32.1283012592258
+ ],
+ [
+ -25.375731366545814,
+ -30.920418134509482
+ ],
+ [
+ -26.862358193880738,
+ -29.63804501419836
+ ],
+ [
+ -28.2842712474619,
+ -28.284271247461902
+ ],
+ [
+ -29.638045014198354,
+ -26.86235819388074
+ ],
+ [
+ -30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ -32.12830125922579,
+ -23.82797217969734
+ ],
+ [
+ -33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ -34.30914440001088,
+ -20.564109767728873
+ ],
+ [
+ -35.2768505739342,
+ -18.855869473039913
+ ],
+ [
+ -36.159571724937734,
+ -17.10220373721128
+ ],
+ [
+ -36.95518130045147,
+ -15.307337294603595
+ ],
+ [
+ -37.661762607320824,
+ -13.475594135688812
+ ],
+ [
+ -38.27761342928835,
+ -11.611387090178496
+ ],
+ [
+ -38.801250127781756,
+ -9.719207196130563
+ ],
+ [
+ -39.23141121612922,
+ -7.803612880645145
+ ],
+ [
+ -39.56706039859124,
+ -5.869218978214472
+ ],
+ [
+ -39.80738906688787,
+ -3.920685613182433
+ ],
+ [
+ -39.9518182482069,
+ -1.9627069730967186
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 169,
+ "operation": "cut",
+ "targets": [
+ "Smoky D tank"
+ ],
+ "name": "Open tank cavity with four millimetre base"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Separate tank lid profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 304
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -45,
+ 0
+ ],
+ [
+ -45,
+ 47
+ ],
+ [
+ 45,
+ 47
+ ],
+ [
+ 45,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 45,
+ 0
+ ],
+ "end": [
+ -45,
+ 0
+ ],
+ "through": [
+ 0,
+ -45
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Separate tank lid"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank lid grip profile",
+ "plane": {
+ "origin": [
+ 225,
+ 41,
+ 309
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -6.0
+ ],
+ "p1": [
+ 19.0,
+ 6.0
+ ],
+ "radius": 5
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Tank lid grip"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Clear ribbed bin profile",
+ "plane": {
+ "origin": [
+ -157,
+ -23,
+ 58
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -33.0,
+ -30
+ ],
+ [
+ -31.2,
+ -32
+ ],
+ [
+ -29.5,
+ -30
+ ],
+ [
+ -27.5,
+ -30
+ ],
+ [
+ -25.7,
+ -32
+ ],
+ [
+ -24.0,
+ -30
+ ],
+ [
+ -22.0,
+ -30
+ ],
+ [
+ -20.2,
+ -32
+ ],
+ [
+ -18.5,
+ -30
+ ],
+ [
+ -16.5,
+ -30
+ ],
+ [
+ -14.7,
+ -32
+ ],
+ [
+ -13.0,
+ -30
+ ],
+ [
+ -11.0,
+ -30
+ ],
+ [
+ -9.2,
+ -32
+ ],
+ [
+ -7.5,
+ -30
+ ],
+ [
+ -5.5,
+ -30
+ ],
+ [
+ -3.7,
+ -32
+ ],
+ [
+ -2.0,
+ -30
+ ],
+ [
+ 0.0,
+ -30
+ ],
+ [
+ 1.8,
+ -32
+ ],
+ [
+ 3.5,
+ -30
+ ],
+ [
+ 5.5,
+ -30
+ ],
+ [
+ 7.3,
+ -32
+ ],
+ [
+ 9.0,
+ -30
+ ],
+ [
+ 11.0,
+ -30
+ ],
+ [
+ 12.8,
+ -32
+ ],
+ [
+ 14.5,
+ -30
+ ],
+ [
+ 16.5,
+ -30
+ ],
+ [
+ 18.3,
+ -32
+ ],
+ [
+ 20.0,
+ -30
+ ],
+ [
+ 22.0,
+ -30
+ ],
+ [
+ 23.8,
+ -32
+ ],
+ [
+ 25.5,
+ -30
+ ],
+ [
+ 27.5,
+ -30
+ ],
+ [
+ 29.3,
+ -32
+ ],
+ [
+ 31.0,
+ -30
+ ],
+ [
+ 33,
+ -30
+ ],
+ [
+ 33,
+ 30
+ ],
+ [
+ -33,
+ 30
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.rectangle.two_point",
+ "params": {
+ "p0": [
+ -30,
+ -27
+ ],
+ "p1": [
+ 30,
+ 27
+ ]
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 72,
+ "operation": "new",
+ "body_name": "Clear ribbed bin",
+ "profiles": [
+ {
+ "point": [
+ 31,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Bin base tool",
+ "corner": [
+ -190,
+ -53,
+ 57
+ ],
+ "length": 66,
+ "width": 60,
+ "height": 4,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Clear ribbed bin",
+ "tools": [
+ "Bin base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Drip tray profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 22
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "innerleft",
+ "innerback",
+ "innerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "innerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Drip tray",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 41.0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tray base tool profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 21
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 4,
+ "operation": "new",
+ "body_name": "Tray base tool"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Drip tray",
+ "tools": [
+ "Tray base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Perforated stainless grate profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 65
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 2,
+ "operation": "new",
+ "body_name": "Perforated stainless grate",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 38
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Rounded tray cap profile",
+ "plane": {
+ "origin": [
+ 112,
+ -143,
+ 40
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -27.0
+ ],
+ "p1": [
+ 19.0,
+ 27.0
+ ],
+ "radius": 15
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Rounded tray cap"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Louvred service panel profile",
+ "plane": {
+ "origin": [
+ -122,
+ 143,
+ 173
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -47,
+ -91
+ ],
+ "p1": [
+ 47,
+ 91
+ ],
+ "radius": 8
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -62
+ ],
+ "p1": [
+ 31,
+ -58
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -47
+ ],
+ "p1": [
+ 31,
+ -43
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -32
+ ],
+ "p1": [
+ 31,
+ -28
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -17
+ ],
+ "p1": [
+ 31,
+ -13
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -2
+ ],
+ "p1": [
+ 31,
+ 2
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 13
+ ],
+ "p1": [
+ 31,
+ 17
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 28
+ ],
+ "p1": [
+ 31,
+ 32
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 43
+ ],
+ "p1": [
+ 31,
+ 47
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 58
+ ],
+ "p1": [
+ 31,
+ 62
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 3,
+ "operation": "new",
+ "body_name": "Louvred service panel",
+ "profiles": [
+ {
+ "point": [
+ 43,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 1",
+ "base": [
+ -99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 2",
+ "base": [
+ -99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 3",
+ "base": [
+ -99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 4",
+ "base": [
+ -99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 5",
+ "base": [
+ 99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 6",
+ "base": [
+ 99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 7",
+ "base": [
+ 99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 8",
+ "base": [
+ 99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "S cable centerline profile",
+ "plane": {
+ "origin": [
+ 70,
+ -75,
+ 9
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 52,
+ 94
+ ],
+ "through": [
+ 92,
+ 54
+ ],
+ "end": [
+ 132,
+ 94
+ ],
+ "id": "cable_a"
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 132,
+ 94
+ ],
+ "through": [
+ 172,
+ 134
+ ],
+ "end": [
+ 212,
+ 94
+ ],
+ "id": "cable_b"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 212,
+ 94
+ ],
+ [
+ 212,
+ 66
+ ]
+ ],
+ "ids": [
+ "cable_end"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "S cable centerline profile",
+ "path": [
+ "cable_a",
+ "cable_b",
+ "cable_end"
+ ],
+ "diameter": 5,
+ "operation": "new",
+ "body_name": "Black S power cable"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Two pin plug profile",
+ "plane": {
+ "origin": [
+ 282,
+ -30,
+ 3
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -12.0,
+ -17.5
+ ],
+ "p1": [
+ 12.0,
+ 17.5
+ ],
+ "radius": 7
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Two pin plug"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 206",
+ "base": [
+ 276,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 218",
+ "base": [
+ 288,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Housing plinth",
+ "Housing shell",
+ "Housing upper shoulder",
+ "Open brewing head",
+ "Brewing head roof",
+ "Drip tray",
+ "Rounded tray cap"
+ ],
+ "color": "#101318",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.3,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Separate tank lid",
+ "Tank lid grip",
+ "Louvred service panel"
+ ],
+ "color": "#171a1f",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.55,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Brewing collar",
+ "Bent chrome lever",
+ "Left lever ball",
+ "Right lever ball",
+ "Plug pin 206",
+ "Plug pin 218"
+ ],
+ "color": "#d5d9dd",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.12,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Internal chassis",
+ "Shower screen",
+ "Perforated stainless grate"
+ ],
+ "color": "#aeb4bb",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.25,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Zinc screw 1",
+ "Zinc screw 2",
+ "Zinc screw 3",
+ "Zinc screw 4",
+ "Zinc screw 5",
+ "Zinc screw 6",
+ "Zinc screw 7",
+ "Zinc screw 8"
+ ],
+ "color": "#b0b5bc",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.32,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Black S power cable",
+ "Two pin plug"
+ ],
+ "color": "#141414",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.8,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Studio floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "color": "#c2c6ca",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "color": "#e4eff1",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Open brewing head"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Open brewing head"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Brewing collar"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Brewing collar"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Shower screen"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Shower screen"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Brewing head roof"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Bent chrome lever"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Left lever ball"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Left lever ball"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Right lever ball"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Right lever ball"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Smoky D tank"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Separate tank lid"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 22
+ ],
+ "copy": false,
+ "name": "Framing: Separate tank lid"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Tank lid grip"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 22
+ ],
+ "copy": false,
+ "name": "Framing: Tank lid grip"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "translate": [
+ -70,
+ -15,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Clear ribbed bin"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Louvred service panel"
+ ],
+ "translate": [
+ -110,
+ 15,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Louvred service panel"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Drip tray"
+ ],
+ "translate": [
+ 0,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Drip tray"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Perforated stainless grate"
+ ],
+ "translate": [
+ 0,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Perforated stainless grate"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Rounded tray cap"
+ ],
+ "translate": [
+ 38,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Rounded tray cap"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Black S power cable"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Black S power cable"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Two pin plug"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Two pin plug"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plug pin 206"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Plug pin 206"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plug pin 218"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Plug pin 218"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 1"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 1"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 2"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 2"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 3"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 3"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 4"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 4"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 5"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 5"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 6"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 6"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 7"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 7"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 8"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 8"
+ }
+ }
+ ]
+}
diff --git a/examples/studio/coffee-cylinder.md b/examples/studio/coffee-cylinder.md
new file mode 100644
index 0000000000..a2d0c7ed30
--- /dev/null
+++ b/examples/studio/coffee-cylinder.md
@@ -0,0 +1,35 @@
+# Cylindrical coffee housing variant
+
+Use `coffee-cylinder-sweep.json` with `coffee-cylinder-render.json` for the
+continuous CAD cyclorama. `coffee-cylinder.json` is the flat-floor counterpart.
+These are separate original variants of the closer, lower coffee framing.
+Regenerate with `python examples/studio/author_coffee_cylinder.py` after placing
+the framing recipes beside the authoring tool.
+
+Three existing bodies receive cylindrical CAD construction. The plinth is an
+R76 mm cylinder at [0, 8, 30], 12 mm high. The tall housing has R70 mm outside
+and R65 mm inside, from Z55 to Z265. Its through-cavity cutter extends 1 mm past
+both ends to avoid coincident boolean caps. The round shoulder is R70 mm, from
+Z265 to Z273. All three share the same XY axis at [0, 8]. The visible outer skin
+is an analytic cylinder with a continuous broad curved silhouette.
+
+The open brewing bay removes X[-47,47], Y[-80,0], Z[88,237] mm from the annular
+shell. It opens the front wall while retaining side cheeks, a 33 mm lower band
+and a 28 mm upper band. There are no new decorative parts. The separate head,
+bent chrome lever and ball ends, tank, ribbed bin, perforated grate, service
+panel, screws, cable and plug retain the framing recipe's geometry and moves.
+
+The expected final body list remains the 32 names in the `coffee-exploded`
+entry of `materials.json`, in exactly that order. Replacing the three original
+sketch/extrude blocks creates no temporary additional bodies. The seven coating
+overrides and two closed-mesh dielectric overrides retain their named ordinals.
+The render request is copied byte-for-byte from `coffee-framing-render.json`,
+including the corrected fill, 1920x1080 camera, 256 samples and depth 12.
+
+This is independently authored SolidCraft geometry under MIT OR Apache-2.0.
+No reference models, image assets, logos, product-specific detailing or triangle
+soups are imported. Dimensions describe an original generic appliance study.
+
+CAD replay, actual `render.scene` body-order checks, material validation and
+rendered visual review are pending. Source command inspection alone does not
+establish successful booleans or the quality of the glossy cylindrical result.
diff --git a/examples/studio/coffee-exploded-render.json b/examples/studio/coffee-exploded-render.json
new file mode 100644
index 0000000000..507016ca95
--- /dev/null
+++ b/examples/studio/coffee-exploded-render.json
@@ -0,0 +1,182 @@
+{
+ "progressive": true,
+ "samples": 256,
+ "max_depth": 12,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ 25,
+ 0,
+ 185
+ ],
+ "yaw": 0.5585053606381855,
+ "pitch": 0.5235987755982988,
+ "roll": 0,
+ "distance": 1200,
+ "fov": 0.5934119456780721
+ },
+ "background": [
+ 240,
+ 240,
+ 240
+ ]
+ },
+ "lighting": {
+ "environment": [
+ 0.5,
+ 0.5,
+ 0.5
+ ],
+ "area_lights": [
+ {
+ "center": [
+ -392.0,
+ -364.0,
+ 784.0
+ ],
+ "u": [
+ 308.0,
+ 0.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ -196.0,
+ 0.0
+ ],
+ "radiance": [
+ 8,
+ 8,
+ 8
+ ]
+ },
+ {
+ "center": [
+ 784,
+ -448,
+ 504
+ ],
+ "u": [
+ 0.0,
+ -168.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ 0.0,
+ 251.99999999999997
+ ],
+ "radiance": [
+ 6,
+ 6,
+ 6
+ ]
+ },
+ {
+ "center": [
+ 0.0,
+ 475.99999999999994,
+ 700.0
+ ],
+ "u": [
+ 196.0,
+ 0.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ 0.0,
+ 182.0
+ ],
+ "radiance": [
+ 10,
+ 10,
+ 10
+ ]
+ }
+ ]
+ },
+ "raytrace": {
+ "clear_coats": [
+ {
+ "body_index": 1,
+ "body_name": "Housing plinth",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 2,
+ "body_name": "Housing shell",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 3,
+ "body_name": "Housing upper shoulder",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 5,
+ "body_name": "Open brewing head",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 6,
+ "body_name": "Brewing head roof",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 16,
+ "body_name": "Drip tray",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 18,
+ "body_name": "Rounded tray cap",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ }
+ ],
+ "dielectrics": [
+ {
+ "body_index": 12,
+ "body_name": "Smoky D tank",
+ "ior": 1.586,
+ "absorption_per_mm": [
+ 0.045,
+ 0.075,
+ 0.12
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ },
+ {
+ "body_index": 15,
+ "body_name": "Clear ribbed bin",
+ "ior": 1.49,
+ "absorption_per_mm": [
+ 0.0004,
+ 0.00015,
+ 5E-05
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ }
+ ]
+ }
+}
diff --git a/examples/studio/coffee-exploded-sweep.json b/examples/studio/coffee-exploded-sweep.json
new file mode 100644
index 0000000000..6bae94ca64
--- /dev/null
+++ b/examples/studio/coffee-exploded-sweep.json
@@ -0,0 +1,3508 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original exploded bench coffee machine"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Studio floor profile",
+ "plane": {
+ "origin": [
+ -4200.0,
+ 0,
+ 0
+ ],
+ "x_dir": [
+ 0,
+ 1,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -4200.0,
+ 0
+ ],
+ [
+ 700.0,
+ 0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 700.0,
+ 0
+ ],
+ "through": [
+ 1095.9797974644666,
+ 164.02020253553337
+ ],
+ "end": [
+ 1260.0,
+ 560.0
+ ],
+ "id": "inner_sweep"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 1260.0,
+ 560.0
+ ],
+ [
+ 1260.0,
+ 4200.0
+ ],
+ [
+ 1271.2,
+ 4200.0
+ ],
+ [
+ 1271.2,
+ 560.0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 1271.2,
+ 560.0
+ ],
+ "through": [
+ 1103.8993934137561,
+ 156.100606586244
+ ],
+ "end": [
+ 700.0,
+ -11.2
+ ],
+ "id": "outer_sweep"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 700.0,
+ -11.2
+ ],
+ [
+ -4200.0,
+ -11.2
+ ],
+ [
+ -4200.0,
+ 0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 8400.0,
+ "operation": "new",
+ "body_name": "Studio floor"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing plinth profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 30
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -70.0,
+ -65.0
+ ],
+ "p1": [
+ 70.0,
+ 65.0
+ ],
+ "radius": 24
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 12,
+ "operation": "new",
+ "body_name": "Housing plinth"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing shell profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 55
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -65.0,
+ -58.0
+ ],
+ "p1": [
+ 65.0,
+ 58.0
+ ],
+ "radius": 23
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -60.0,
+ -53.0
+ ],
+ "p1": [
+ 60.0,
+ 53.0
+ ],
+ "radius": 18
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 210,
+ "operation": "new",
+ "body_name": "Housing shell",
+ "profiles": [
+ {
+ "point": [
+ -62.5,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -46,
+ -60,
+ 88
+ ],
+ "length": 92,
+ "width": 35,
+ "height": 149,
+ "operation": "cut",
+ "targets": [
+ "Housing shell"
+ ],
+ "name": "Open brewing bay"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing upper shoulder profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 265
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -65.0,
+ -58.0
+ ],
+ "p1": [
+ 65.0,
+ 58.0
+ ],
+ "radius": 23
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 8,
+ "operation": "new",
+ "body_name": "Housing upper shoulder"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Internal chassis",
+ "corner": [
+ -42,
+ 38,
+ 63
+ ],
+ "length": 84,
+ "width": 5,
+ "height": 189,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Open brewing head",
+ "base": [
+ 0,
+ -76,
+ 307
+ ],
+ "radius": 43,
+ "height": 95,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -77,
+ 307
+ ],
+ "radius": 31,
+ "height": 97,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Open brewing head"
+ ],
+ "name": "Horizontal open brew bore"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Brewing head roof profile",
+ "plane": {
+ "origin": [
+ 0,
+ -6,
+ 352
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -57.5,
+ -51.5
+ ],
+ "p1": [
+ 57.5,
+ 51.5
+ ],
+ "radius": 25
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 7,
+ "operation": "new",
+ "body_name": "Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -18,
+ -9,
+ 351
+ ],
+ "length": 36,
+ "width": 7,
+ "height": 9,
+ "operation": "cut",
+ "targets": [
+ "Brewing head roof"
+ ],
+ "name": "Capsule loading slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Brewing collar",
+ "base": [
+ 0,
+ -88,
+ 307
+ ],
+ "radius": 35,
+ "height": 9,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -89,
+ 307
+ ],
+ "radius": 28,
+ "height": 11,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Brewing collar"
+ ],
+ "name": "Open brew throat"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Shower screen",
+ "base": [
+ 0,
+ 10,
+ 307
+ ],
+ "radius": 27,
+ "height": 2,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Lever centerline profile",
+ "plane": {
+ "origin": [
+ 0,
+ -28,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -77,
+ 306
+ ],
+ [
+ -77,
+ 365
+ ]
+ ],
+ "ids": [
+ "lever_left"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ -77,
+ 365
+ ],
+ "through": [
+ -72.6066,
+ 375.6066
+ ],
+ "end": [
+ -62,
+ 380
+ ],
+ "id": "lever_bend_left"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -62,
+ 380
+ ],
+ [
+ 62,
+ 380
+ ]
+ ],
+ "ids": [
+ "lever_top"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 62,
+ 380
+ ],
+ "through": [
+ 72.6066,
+ 375.6066
+ ],
+ "end": [
+ 77,
+ 365
+ ],
+ "id": "lever_bend_right"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 77,
+ 365
+ ],
+ [
+ 77,
+ 306
+ ]
+ ],
+ "ids": [
+ "lever_right"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "Lever centerline profile",
+ "path": [
+ "lever_left",
+ "lever_bend_left",
+ "lever_top",
+ "lever_bend_right",
+ "lever_right"
+ ],
+ "diameter": 9,
+ "operation": "new",
+ "body_name": "Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Left lever ball",
+ "center": [
+ -77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Right lever ball",
+ "center": [
+ 77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Smoky D tank profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 99
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -43,
+ 0
+ ],
+ [
+ -43,
+ 45
+ ],
+ [
+ 43,
+ 45
+ ],
+ [
+ 43,
+ 0
+ ],
+ [
+ 42.948204616822416,
+ -2.1099099960789744
+ ],
+ [
+ 42.79294324690447,
+ -4.214737034171106
+ ],
+ [
+ 42.53458992848558,
+ -6.309410401580555
+ ],
+ [
+ 42.17376705733891,
+ -8.388883846693515
+ ],
+ [
+ 41.71134388736539,
+ -10.448147735840346
+ ],
+ [
+ 41.148434436484976,
+ -12.48224112194188
+ ],
+ [
+ 40.486394802869896,
+ -14.486263695865462
+ ],
+ [
+ 39.72681989798533,
+ -16.455387591698862
+ ],
+ [
+ 38.87153960430806,
+ -18.38486901750213
+ ],
+ [
+ 37.92261436697927,
+ -20.2700596835179
+ ],
+ [
+ 36.8823302300117,
+ -22.10641800030853
+ ],
+ [
+ 35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ 34.537923853667735,
+ -25.615070093174634
+ ],
+ [
+ 33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ 31.860898390263245,
+ -28.87703505842179
+ ],
+ [
+ 30.405591591021544,
+ -30.405591591021544
+ ],
+ [
+ 28.87703505842179,
+ -31.86089839026324
+ ],
+ [
+ 27.278911219036758,
+ -33.239449494597686
+ ],
+ [
+ 25.61507009317464,
+ -34.53792385366773
+ ],
+ [
+ 23.889520019842898,
+ -35.75319332900945
+ ],
+ [
+ 22.10641800030853,
+ -36.8823302300117
+ ],
+ [
+ 20.270059683517907,
+ -37.92261436697926
+ ],
+ [
+ 18.384869017502133,
+ -38.87153960430806
+ ],
+ [
+ 16.455387591698862,
+ -39.72681989798533
+ ],
+ [
+ 14.486263695865462,
+ -40.486394802869896
+ ],
+ [
+ 12.48224112194188,
+ -41.14843443648498
+ ],
+ [
+ 10.448147735840351,
+ -41.71134388736539
+ ],
+ [
+ 8.388883846693519,
+ -42.17376705733891
+ ],
+ [
+ 6.309410401580555,
+ -42.53458992848558
+ ],
+ [
+ 4.2147370341711135,
+ -42.792943246904464
+ ],
+ [
+ 2.1099099960789793,
+ -42.948204616822416
+ ],
+ [
+ 2.6329906181668092e-15,
+ -43.0
+ ],
+ [
+ -2.1099099960789744,
+ -42.948204616822416
+ ],
+ [
+ -4.214737034171108,
+ -42.79294324690447
+ ],
+ [
+ -6.309410401580551,
+ -42.53458992848558
+ ],
+ [
+ -8.388883846693512,
+ -42.17376705733891
+ ],
+ [
+ -10.448147735840346,
+ -41.71134388736539
+ ],
+ [
+ -12.482241121941874,
+ -41.14843443648498
+ ],
+ [
+ -14.486263695865457,
+ -40.486394802869896
+ ],
+ [
+ -16.45538759169886,
+ -39.72681989798533
+ ],
+ [
+ -18.38486901750212,
+ -38.87153960430807
+ ],
+ [
+ -20.2700596835179,
+ -37.92261436697927
+ ],
+ [
+ -22.106418000308526,
+ -36.8823302300117
+ ],
+ [
+ -23.889520019842884,
+ -35.75319332900945
+ ],
+ [
+ -25.615070093174634,
+ -34.537923853667735
+ ],
+ [
+ -27.27891121903675,
+ -33.23944949459769
+ ],
+ [
+ -28.877035058421793,
+ -31.860898390263237
+ ],
+ [
+ -30.40559159102154,
+ -30.405591591021544
+ ],
+ [
+ -31.86089839026323,
+ -28.877035058421797
+ ],
+ [
+ -33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ -34.53792385366773,
+ -25.61507009317464
+ ],
+ [
+ -35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ -36.882330230011696,
+ -22.106418000308537
+ ],
+ [
+ -37.92261436697926,
+ -20.270059683517907
+ ],
+ [
+ -38.87153960430806,
+ -18.384869017502126
+ ],
+ [
+ -39.72681989798533,
+ -16.455387591698866
+ ],
+ [
+ -40.48639480286989,
+ -14.486263695865475
+ ],
+ [
+ -41.148434436484976,
+ -12.482241121941883
+ ],
+ [
+ -41.71134388736539,
+ -10.448147735840354
+ ],
+ [
+ -42.17376705733891,
+ -8.38888384669353
+ ],
+ [
+ -42.53458992848558,
+ -6.309410401580558
+ ],
+ [
+ -42.792943246904464,
+ -4.214737034171115
+ ],
+ [
+ -42.948204616822416,
+ -2.1099099960789727
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 171,
+ "operation": "new",
+ "body_name": "Smoky D tank"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank cavity profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 103
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -40,
+ 0
+ ],
+ [
+ -40,
+ 42
+ ],
+ [
+ 40,
+ 42
+ ],
+ [
+ 40,
+ 0
+ ],
+ [
+ 39.9518182482069,
+ -1.9627069730967206
+ ],
+ [
+ 39.80738906688788,
+ -3.920685613182424
+ ],
+ [
+ 39.56706039859124,
+ -5.8692189782144695
+ ],
+ [
+ 39.23141121612922,
+ -7.8036128806451295
+ ],
+ [
+ 38.801250127781756,
+ -9.719207196130554
+ ],
+ [
+ 38.27761342928835,
+ -11.611387090178493
+ ],
+ [
+ 37.66176260732083,
+ -13.475594135688802
+ ],
+ [
+ 36.95518130045147,
+ -15.307337294603592
+ ],
+ [
+ 36.159571724937734,
+ -17.102203737211283
+ ],
+ [
+ 35.276850573934205,
+ -18.855869473039906
+ ],
+ [
+ 34.30914440001089,
+ -20.564109767728866
+ ],
+ [
+ 33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ 32.1283012592258,
+ -23.827972179697333
+ ],
+ [
+ 30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ 29.63804501419837,
+ -26.862358193880734
+ ],
+ [
+ 28.284271247461902,
+ -28.284271247461902
+ ],
+ [
+ 26.862358193880734,
+ -29.638045014198365
+ ],
+ [
+ 25.37573136654582,
+ -30.920418134509475
+ ],
+ [
+ 23.82797217969734,
+ -32.12830125922579
+ ],
+ [
+ 22.22280932078409,
+ -33.25878449210181
+ ],
+ [
+ 20.564109767728866,
+ -34.30914440001089
+ ],
+ [
+ 18.855869473039913,
+ -35.2768505739342
+ ],
+ [
+ 17.102203737211287,
+ -36.159571724937734
+ ],
+ [
+ 15.307337294603593,
+ -36.95518130045147
+ ],
+ [
+ 13.475594135688802,
+ -37.66176260732083
+ ],
+ [
+ 11.611387090178493,
+ -38.27761342928836
+ ],
+ [
+ 9.71920719613056,
+ -38.801250127781756
+ ],
+ [
+ 7.803612880645133,
+ -39.23141121612922
+ ],
+ [
+ 5.8692189782144695,
+ -39.56706039859124
+ ],
+ [
+ 3.920685613182431,
+ -39.80738906688787
+ ],
+ [
+ 1.962706973096725,
+ -39.9518182482069
+ ],
+ [
+ 2.4492935982947065e-15,
+ -40.0
+ ],
+ [
+ -1.9627069730967204,
+ -39.9518182482069
+ ],
+ [
+ -3.920685613182426,
+ -39.80738906688788
+ ],
+ [
+ -5.869218978214466,
+ -39.56706039859124
+ ],
+ [
+ -7.803612880645128,
+ -39.23141121612922
+ ],
+ [
+ -9.719207196130554,
+ -38.801250127781756
+ ],
+ [
+ -11.611387090178486,
+ -38.27761342928836
+ ],
+ [
+ -13.475594135688798,
+ -37.66176260732083
+ ],
+ [
+ -15.307337294603588,
+ -36.95518130045147
+ ],
+ [
+ -17.102203737211276,
+ -36.159571724937734
+ ],
+ [
+ -18.85586947303991,
+ -35.276850573934205
+ ],
+ [
+ -20.564109767728862,
+ -34.30914440001089
+ ],
+ [
+ -22.22280932078408,
+ -33.25878449210181
+ ],
+ [
+ -23.827972179697333,
+ -32.1283012592258
+ ],
+ [
+ -25.375731366545814,
+ -30.920418134509482
+ ],
+ [
+ -26.862358193880738,
+ -29.63804501419836
+ ],
+ [
+ -28.2842712474619,
+ -28.284271247461902
+ ],
+ [
+ -29.638045014198354,
+ -26.86235819388074
+ ],
+ [
+ -30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ -32.12830125922579,
+ -23.82797217969734
+ ],
+ [
+ -33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ -34.30914440001088,
+ -20.564109767728873
+ ],
+ [
+ -35.2768505739342,
+ -18.855869473039913
+ ],
+ [
+ -36.159571724937734,
+ -17.10220373721128
+ ],
+ [
+ -36.95518130045147,
+ -15.307337294603595
+ ],
+ [
+ -37.661762607320824,
+ -13.475594135688812
+ ],
+ [
+ -38.27761342928835,
+ -11.611387090178496
+ ],
+ [
+ -38.801250127781756,
+ -9.719207196130563
+ ],
+ [
+ -39.23141121612922,
+ -7.803612880645145
+ ],
+ [
+ -39.56706039859124,
+ -5.869218978214472
+ ],
+ [
+ -39.80738906688787,
+ -3.920685613182433
+ ],
+ [
+ -39.9518182482069,
+ -1.9627069730967186
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 169,
+ "operation": "cut",
+ "targets": [
+ "Smoky D tank"
+ ],
+ "name": "Open tank cavity with four millimetre base"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Separate tank lid profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 304
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -45,
+ 0
+ ],
+ [
+ -45,
+ 47
+ ],
+ [
+ 45,
+ 47
+ ],
+ [
+ 45,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 45,
+ 0
+ ],
+ "end": [
+ -45,
+ 0
+ ],
+ "through": [
+ 0,
+ -45
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Separate tank lid"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank lid grip profile",
+ "plane": {
+ "origin": [
+ 225,
+ 41,
+ 309
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -6.0
+ ],
+ "p1": [
+ 19.0,
+ 6.0
+ ],
+ "radius": 5
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Tank lid grip"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Clear ribbed bin profile",
+ "plane": {
+ "origin": [
+ -157,
+ -23,
+ 58
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -33.0,
+ -30
+ ],
+ [
+ -31.2,
+ -32
+ ],
+ [
+ -29.5,
+ -30
+ ],
+ [
+ -27.5,
+ -30
+ ],
+ [
+ -25.7,
+ -32
+ ],
+ [
+ -24.0,
+ -30
+ ],
+ [
+ -22.0,
+ -30
+ ],
+ [
+ -20.2,
+ -32
+ ],
+ [
+ -18.5,
+ -30
+ ],
+ [
+ -16.5,
+ -30
+ ],
+ [
+ -14.7,
+ -32
+ ],
+ [
+ -13.0,
+ -30
+ ],
+ [
+ -11.0,
+ -30
+ ],
+ [
+ -9.2,
+ -32
+ ],
+ [
+ -7.5,
+ -30
+ ],
+ [
+ -5.5,
+ -30
+ ],
+ [
+ -3.7,
+ -32
+ ],
+ [
+ -2.0,
+ -30
+ ],
+ [
+ 0.0,
+ -30
+ ],
+ [
+ 1.8,
+ -32
+ ],
+ [
+ 3.5,
+ -30
+ ],
+ [
+ 5.5,
+ -30
+ ],
+ [
+ 7.3,
+ -32
+ ],
+ [
+ 9.0,
+ -30
+ ],
+ [
+ 11.0,
+ -30
+ ],
+ [
+ 12.8,
+ -32
+ ],
+ [
+ 14.5,
+ -30
+ ],
+ [
+ 16.5,
+ -30
+ ],
+ [
+ 18.3,
+ -32
+ ],
+ [
+ 20.0,
+ -30
+ ],
+ [
+ 22.0,
+ -30
+ ],
+ [
+ 23.8,
+ -32
+ ],
+ [
+ 25.5,
+ -30
+ ],
+ [
+ 27.5,
+ -30
+ ],
+ [
+ 29.3,
+ -32
+ ],
+ [
+ 31.0,
+ -30
+ ],
+ [
+ 33,
+ -30
+ ],
+ [
+ 33,
+ 30
+ ],
+ [
+ -33,
+ 30
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.rectangle.two_point",
+ "params": {
+ "p0": [
+ -30,
+ -27
+ ],
+ "p1": [
+ 30,
+ 27
+ ]
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 72,
+ "operation": "new",
+ "body_name": "Clear ribbed bin",
+ "profiles": [
+ {
+ "point": [
+ 31,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Bin base tool",
+ "corner": [
+ -190,
+ -53,
+ 57
+ ],
+ "length": 66,
+ "width": 60,
+ "height": 4,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Clear ribbed bin",
+ "tools": [
+ "Bin base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Drip tray profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 22
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "innerleft",
+ "innerback",
+ "innerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "innerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Drip tray",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 41.0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tray base tool profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 21
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 4,
+ "operation": "new",
+ "body_name": "Tray base tool"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Drip tray",
+ "tools": [
+ "Tray base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Perforated stainless grate profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 65
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 2,
+ "operation": "new",
+ "body_name": "Perforated stainless grate",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 38
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Rounded tray cap profile",
+ "plane": {
+ "origin": [
+ 112,
+ -143,
+ 40
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -27.0
+ ],
+ "p1": [
+ 19.0,
+ 27.0
+ ],
+ "radius": 15
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Rounded tray cap"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Louvred service panel profile",
+ "plane": {
+ "origin": [
+ -122,
+ 143,
+ 173
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -47,
+ -91
+ ],
+ "p1": [
+ 47,
+ 91
+ ],
+ "radius": 8
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -62
+ ],
+ "p1": [
+ 31,
+ -58
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -47
+ ],
+ "p1": [
+ 31,
+ -43
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -32
+ ],
+ "p1": [
+ 31,
+ -28
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -17
+ ],
+ "p1": [
+ 31,
+ -13
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -2
+ ],
+ "p1": [
+ 31,
+ 2
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 13
+ ],
+ "p1": [
+ 31,
+ 17
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 28
+ ],
+ "p1": [
+ 31,
+ 32
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 43
+ ],
+ "p1": [
+ 31,
+ 47
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 58
+ ],
+ "p1": [
+ 31,
+ 62
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 3,
+ "operation": "new",
+ "body_name": "Louvred service panel",
+ "profiles": [
+ {
+ "point": [
+ 43,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 1",
+ "base": [
+ -99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 2",
+ "base": [
+ -99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 3",
+ "base": [
+ -99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 4",
+ "base": [
+ -99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 5",
+ "base": [
+ 99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 6",
+ "base": [
+ 99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 7",
+ "base": [
+ 99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 8",
+ "base": [
+ 99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "S cable centerline profile",
+ "plane": {
+ "origin": [
+ 70,
+ -75,
+ 9
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 52,
+ 94
+ ],
+ "through": [
+ 92,
+ 54
+ ],
+ "end": [
+ 132,
+ 94
+ ],
+ "id": "cable_a"
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 132,
+ 94
+ ],
+ "through": [
+ 172,
+ 134
+ ],
+ "end": [
+ 212,
+ 94
+ ],
+ "id": "cable_b"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 212,
+ 94
+ ],
+ [
+ 212,
+ 66
+ ]
+ ],
+ "ids": [
+ "cable_end"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "S cable centerline profile",
+ "path": [
+ "cable_a",
+ "cable_b",
+ "cable_end"
+ ],
+ "diameter": 5,
+ "operation": "new",
+ "body_name": "Black S power cable"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Two pin plug profile",
+ "plane": {
+ "origin": [
+ 282,
+ -30,
+ 3
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -12.0,
+ -17.5
+ ],
+ "p1": [
+ 12.0,
+ 17.5
+ ],
+ "radius": 7
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Two pin plug"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 206",
+ "base": [
+ 276,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 218",
+ "base": [
+ 288,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Housing plinth",
+ "Housing shell",
+ "Housing upper shoulder",
+ "Open brewing head",
+ "Brewing head roof",
+ "Drip tray",
+ "Rounded tray cap"
+ ],
+ "color": "#101318",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.3,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Separate tank lid",
+ "Tank lid grip",
+ "Louvred service panel"
+ ],
+ "color": "#171a1f",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.55,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Brewing collar",
+ "Bent chrome lever",
+ "Left lever ball",
+ "Right lever ball",
+ "Plug pin 206",
+ "Plug pin 218"
+ ],
+ "color": "#d5d9dd",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.12,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Internal chassis",
+ "Shower screen",
+ "Perforated stainless grate"
+ ],
+ "color": "#aeb4bb",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.25,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Zinc screw 1",
+ "Zinc screw 2",
+ "Zinc screw 3",
+ "Zinc screw 4",
+ "Zinc screw 5",
+ "Zinc screw 6",
+ "Zinc screw 7",
+ "Zinc screw 8"
+ ],
+ "color": "#b0b5bc",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.32,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Black S power cable",
+ "Two pin plug"
+ ],
+ "color": "#141414",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.8,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Studio floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "color": "#c2c6ca",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "color": "#e4eff1",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ }
+ ]
+}
diff --git a/examples/studio/coffee-exploded.json b/examples/studio/coffee-exploded.json
new file mode 100644
index 0000000000..9b239c3395
--- /dev/null
+++ b/examples/studio/coffee-exploded.json
@@ -0,0 +1,3392 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original exploded bench coffee machine"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Studio floor",
+ "corner": [
+ -6000,
+ -6000,
+ -5
+ ],
+ "length": 12000,
+ "width": 12000,
+ "height": 5,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing plinth profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 30
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -70.0,
+ -65.0
+ ],
+ "p1": [
+ 70.0,
+ 65.0
+ ],
+ "radius": 24
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 12,
+ "operation": "new",
+ "body_name": "Housing plinth"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing shell profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 55
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -65.0,
+ -58.0
+ ],
+ "p1": [
+ 65.0,
+ 58.0
+ ],
+ "radius": 23
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -60.0,
+ -53.0
+ ],
+ "p1": [
+ 60.0,
+ 53.0
+ ],
+ "radius": 18
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 210,
+ "operation": "new",
+ "body_name": "Housing shell",
+ "profiles": [
+ {
+ "point": [
+ -62.5,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -46,
+ -60,
+ 88
+ ],
+ "length": 92,
+ "width": 35,
+ "height": 149,
+ "operation": "cut",
+ "targets": [
+ "Housing shell"
+ ],
+ "name": "Open brewing bay"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing upper shoulder profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 265
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -65.0,
+ -58.0
+ ],
+ "p1": [
+ 65.0,
+ 58.0
+ ],
+ "radius": 23
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 8,
+ "operation": "new",
+ "body_name": "Housing upper shoulder"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Internal chassis",
+ "corner": [
+ -42,
+ 38,
+ 63
+ ],
+ "length": 84,
+ "width": 5,
+ "height": 189,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Open brewing head",
+ "base": [
+ 0,
+ -76,
+ 307
+ ],
+ "radius": 43,
+ "height": 95,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -77,
+ 307
+ ],
+ "radius": 31,
+ "height": 97,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Open brewing head"
+ ],
+ "name": "Horizontal open brew bore"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Brewing head roof profile",
+ "plane": {
+ "origin": [
+ 0,
+ -6,
+ 352
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -57.5,
+ -51.5
+ ],
+ "p1": [
+ 57.5,
+ 51.5
+ ],
+ "radius": 25
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 7,
+ "operation": "new",
+ "body_name": "Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -18,
+ -9,
+ 351
+ ],
+ "length": 36,
+ "width": 7,
+ "height": 9,
+ "operation": "cut",
+ "targets": [
+ "Brewing head roof"
+ ],
+ "name": "Capsule loading slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Brewing collar",
+ "base": [
+ 0,
+ -88,
+ 307
+ ],
+ "radius": 35,
+ "height": 9,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -89,
+ 307
+ ],
+ "radius": 28,
+ "height": 11,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Brewing collar"
+ ],
+ "name": "Open brew throat"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Shower screen",
+ "base": [
+ 0,
+ 10,
+ 307
+ ],
+ "radius": 27,
+ "height": 2,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Lever centerline profile",
+ "plane": {
+ "origin": [
+ 0,
+ -28,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -77,
+ 306
+ ],
+ [
+ -77,
+ 365
+ ]
+ ],
+ "ids": [
+ "lever_left"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ -77,
+ 365
+ ],
+ "through": [
+ -72.6066,
+ 375.6066
+ ],
+ "end": [
+ -62,
+ 380
+ ],
+ "id": "lever_bend_left"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -62,
+ 380
+ ],
+ [
+ 62,
+ 380
+ ]
+ ],
+ "ids": [
+ "lever_top"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 62,
+ 380
+ ],
+ "through": [
+ 72.6066,
+ 375.6066
+ ],
+ "end": [
+ 77,
+ 365
+ ],
+ "id": "lever_bend_right"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 77,
+ 365
+ ],
+ [
+ 77,
+ 306
+ ]
+ ],
+ "ids": [
+ "lever_right"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "Lever centerline profile",
+ "path": [
+ "lever_left",
+ "lever_bend_left",
+ "lever_top",
+ "lever_bend_right",
+ "lever_right"
+ ],
+ "diameter": 9,
+ "operation": "new",
+ "body_name": "Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Left lever ball",
+ "center": [
+ -77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Right lever ball",
+ "center": [
+ 77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Smoky D tank profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 99
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -43,
+ 0
+ ],
+ [
+ -43,
+ 45
+ ],
+ [
+ 43,
+ 45
+ ],
+ [
+ 43,
+ 0
+ ],
+ [
+ 42.948204616822416,
+ -2.1099099960789744
+ ],
+ [
+ 42.79294324690447,
+ -4.214737034171106
+ ],
+ [
+ 42.53458992848558,
+ -6.309410401580555
+ ],
+ [
+ 42.17376705733891,
+ -8.388883846693515
+ ],
+ [
+ 41.71134388736539,
+ -10.448147735840346
+ ],
+ [
+ 41.148434436484976,
+ -12.48224112194188
+ ],
+ [
+ 40.486394802869896,
+ -14.486263695865462
+ ],
+ [
+ 39.72681989798533,
+ -16.455387591698862
+ ],
+ [
+ 38.87153960430806,
+ -18.38486901750213
+ ],
+ [
+ 37.92261436697927,
+ -20.2700596835179
+ ],
+ [
+ 36.8823302300117,
+ -22.10641800030853
+ ],
+ [
+ 35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ 34.537923853667735,
+ -25.615070093174634
+ ],
+ [
+ 33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ 31.860898390263245,
+ -28.87703505842179
+ ],
+ [
+ 30.405591591021544,
+ -30.405591591021544
+ ],
+ [
+ 28.87703505842179,
+ -31.86089839026324
+ ],
+ [
+ 27.278911219036758,
+ -33.239449494597686
+ ],
+ [
+ 25.61507009317464,
+ -34.53792385366773
+ ],
+ [
+ 23.889520019842898,
+ -35.75319332900945
+ ],
+ [
+ 22.10641800030853,
+ -36.8823302300117
+ ],
+ [
+ 20.270059683517907,
+ -37.92261436697926
+ ],
+ [
+ 18.384869017502133,
+ -38.87153960430806
+ ],
+ [
+ 16.455387591698862,
+ -39.72681989798533
+ ],
+ [
+ 14.486263695865462,
+ -40.486394802869896
+ ],
+ [
+ 12.48224112194188,
+ -41.14843443648498
+ ],
+ [
+ 10.448147735840351,
+ -41.71134388736539
+ ],
+ [
+ 8.388883846693519,
+ -42.17376705733891
+ ],
+ [
+ 6.309410401580555,
+ -42.53458992848558
+ ],
+ [
+ 4.2147370341711135,
+ -42.792943246904464
+ ],
+ [
+ 2.1099099960789793,
+ -42.948204616822416
+ ],
+ [
+ 2.6329906181668092e-15,
+ -43.0
+ ],
+ [
+ -2.1099099960789744,
+ -42.948204616822416
+ ],
+ [
+ -4.214737034171108,
+ -42.79294324690447
+ ],
+ [
+ -6.309410401580551,
+ -42.53458992848558
+ ],
+ [
+ -8.388883846693512,
+ -42.17376705733891
+ ],
+ [
+ -10.448147735840346,
+ -41.71134388736539
+ ],
+ [
+ -12.482241121941874,
+ -41.14843443648498
+ ],
+ [
+ -14.486263695865457,
+ -40.486394802869896
+ ],
+ [
+ -16.45538759169886,
+ -39.72681989798533
+ ],
+ [
+ -18.38486901750212,
+ -38.87153960430807
+ ],
+ [
+ -20.2700596835179,
+ -37.92261436697927
+ ],
+ [
+ -22.106418000308526,
+ -36.8823302300117
+ ],
+ [
+ -23.889520019842884,
+ -35.75319332900945
+ ],
+ [
+ -25.615070093174634,
+ -34.537923853667735
+ ],
+ [
+ -27.27891121903675,
+ -33.23944949459769
+ ],
+ [
+ -28.877035058421793,
+ -31.860898390263237
+ ],
+ [
+ -30.40559159102154,
+ -30.405591591021544
+ ],
+ [
+ -31.86089839026323,
+ -28.877035058421797
+ ],
+ [
+ -33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ -34.53792385366773,
+ -25.61507009317464
+ ],
+ [
+ -35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ -36.882330230011696,
+ -22.106418000308537
+ ],
+ [
+ -37.92261436697926,
+ -20.270059683517907
+ ],
+ [
+ -38.87153960430806,
+ -18.384869017502126
+ ],
+ [
+ -39.72681989798533,
+ -16.455387591698866
+ ],
+ [
+ -40.48639480286989,
+ -14.486263695865475
+ ],
+ [
+ -41.148434436484976,
+ -12.482241121941883
+ ],
+ [
+ -41.71134388736539,
+ -10.448147735840354
+ ],
+ [
+ -42.17376705733891,
+ -8.38888384669353
+ ],
+ [
+ -42.53458992848558,
+ -6.309410401580558
+ ],
+ [
+ -42.792943246904464,
+ -4.214737034171115
+ ],
+ [
+ -42.948204616822416,
+ -2.1099099960789727
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 171,
+ "operation": "new",
+ "body_name": "Smoky D tank"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank cavity profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 103
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -40,
+ 0
+ ],
+ [
+ -40,
+ 42
+ ],
+ [
+ 40,
+ 42
+ ],
+ [
+ 40,
+ 0
+ ],
+ [
+ 39.9518182482069,
+ -1.9627069730967206
+ ],
+ [
+ 39.80738906688788,
+ -3.920685613182424
+ ],
+ [
+ 39.56706039859124,
+ -5.8692189782144695
+ ],
+ [
+ 39.23141121612922,
+ -7.8036128806451295
+ ],
+ [
+ 38.801250127781756,
+ -9.719207196130554
+ ],
+ [
+ 38.27761342928835,
+ -11.611387090178493
+ ],
+ [
+ 37.66176260732083,
+ -13.475594135688802
+ ],
+ [
+ 36.95518130045147,
+ -15.307337294603592
+ ],
+ [
+ 36.159571724937734,
+ -17.102203737211283
+ ],
+ [
+ 35.276850573934205,
+ -18.855869473039906
+ ],
+ [
+ 34.30914440001089,
+ -20.564109767728866
+ ],
+ [
+ 33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ 32.1283012592258,
+ -23.827972179697333
+ ],
+ [
+ 30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ 29.63804501419837,
+ -26.862358193880734
+ ],
+ [
+ 28.284271247461902,
+ -28.284271247461902
+ ],
+ [
+ 26.862358193880734,
+ -29.638045014198365
+ ],
+ [
+ 25.37573136654582,
+ -30.920418134509475
+ ],
+ [
+ 23.82797217969734,
+ -32.12830125922579
+ ],
+ [
+ 22.22280932078409,
+ -33.25878449210181
+ ],
+ [
+ 20.564109767728866,
+ -34.30914440001089
+ ],
+ [
+ 18.855869473039913,
+ -35.2768505739342
+ ],
+ [
+ 17.102203737211287,
+ -36.159571724937734
+ ],
+ [
+ 15.307337294603593,
+ -36.95518130045147
+ ],
+ [
+ 13.475594135688802,
+ -37.66176260732083
+ ],
+ [
+ 11.611387090178493,
+ -38.27761342928836
+ ],
+ [
+ 9.71920719613056,
+ -38.801250127781756
+ ],
+ [
+ 7.803612880645133,
+ -39.23141121612922
+ ],
+ [
+ 5.8692189782144695,
+ -39.56706039859124
+ ],
+ [
+ 3.920685613182431,
+ -39.80738906688787
+ ],
+ [
+ 1.962706973096725,
+ -39.9518182482069
+ ],
+ [
+ 2.4492935982947065e-15,
+ -40.0
+ ],
+ [
+ -1.9627069730967204,
+ -39.9518182482069
+ ],
+ [
+ -3.920685613182426,
+ -39.80738906688788
+ ],
+ [
+ -5.869218978214466,
+ -39.56706039859124
+ ],
+ [
+ -7.803612880645128,
+ -39.23141121612922
+ ],
+ [
+ -9.719207196130554,
+ -38.801250127781756
+ ],
+ [
+ -11.611387090178486,
+ -38.27761342928836
+ ],
+ [
+ -13.475594135688798,
+ -37.66176260732083
+ ],
+ [
+ -15.307337294603588,
+ -36.95518130045147
+ ],
+ [
+ -17.102203737211276,
+ -36.159571724937734
+ ],
+ [
+ -18.85586947303991,
+ -35.276850573934205
+ ],
+ [
+ -20.564109767728862,
+ -34.30914440001089
+ ],
+ [
+ -22.22280932078408,
+ -33.25878449210181
+ ],
+ [
+ -23.827972179697333,
+ -32.1283012592258
+ ],
+ [
+ -25.375731366545814,
+ -30.920418134509482
+ ],
+ [
+ -26.862358193880738,
+ -29.63804501419836
+ ],
+ [
+ -28.2842712474619,
+ -28.284271247461902
+ ],
+ [
+ -29.638045014198354,
+ -26.86235819388074
+ ],
+ [
+ -30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ -32.12830125922579,
+ -23.82797217969734
+ ],
+ [
+ -33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ -34.30914440001088,
+ -20.564109767728873
+ ],
+ [
+ -35.2768505739342,
+ -18.855869473039913
+ ],
+ [
+ -36.159571724937734,
+ -17.10220373721128
+ ],
+ [
+ -36.95518130045147,
+ -15.307337294603595
+ ],
+ [
+ -37.661762607320824,
+ -13.475594135688812
+ ],
+ [
+ -38.27761342928835,
+ -11.611387090178496
+ ],
+ [
+ -38.801250127781756,
+ -9.719207196130563
+ ],
+ [
+ -39.23141121612922,
+ -7.803612880645145
+ ],
+ [
+ -39.56706039859124,
+ -5.869218978214472
+ ],
+ [
+ -39.80738906688787,
+ -3.920685613182433
+ ],
+ [
+ -39.9518182482069,
+ -1.9627069730967186
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 169,
+ "operation": "cut",
+ "targets": [
+ "Smoky D tank"
+ ],
+ "name": "Open tank cavity with four millimetre base"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Separate tank lid profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 304
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -45,
+ 0
+ ],
+ [
+ -45,
+ 47
+ ],
+ [
+ 45,
+ 47
+ ],
+ [
+ 45,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 45,
+ 0
+ ],
+ "end": [
+ -45,
+ 0
+ ],
+ "through": [
+ 0,
+ -45
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Separate tank lid"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank lid grip profile",
+ "plane": {
+ "origin": [
+ 225,
+ 41,
+ 309
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -6.0
+ ],
+ "p1": [
+ 19.0,
+ 6.0
+ ],
+ "radius": 5
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Tank lid grip"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Clear ribbed bin profile",
+ "plane": {
+ "origin": [
+ -157,
+ -23,
+ 58
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -33.0,
+ -30
+ ],
+ [
+ -31.2,
+ -32
+ ],
+ [
+ -29.5,
+ -30
+ ],
+ [
+ -27.5,
+ -30
+ ],
+ [
+ -25.7,
+ -32
+ ],
+ [
+ -24.0,
+ -30
+ ],
+ [
+ -22.0,
+ -30
+ ],
+ [
+ -20.2,
+ -32
+ ],
+ [
+ -18.5,
+ -30
+ ],
+ [
+ -16.5,
+ -30
+ ],
+ [
+ -14.7,
+ -32
+ ],
+ [
+ -13.0,
+ -30
+ ],
+ [
+ -11.0,
+ -30
+ ],
+ [
+ -9.2,
+ -32
+ ],
+ [
+ -7.5,
+ -30
+ ],
+ [
+ -5.5,
+ -30
+ ],
+ [
+ -3.7,
+ -32
+ ],
+ [
+ -2.0,
+ -30
+ ],
+ [
+ 0.0,
+ -30
+ ],
+ [
+ 1.8,
+ -32
+ ],
+ [
+ 3.5,
+ -30
+ ],
+ [
+ 5.5,
+ -30
+ ],
+ [
+ 7.3,
+ -32
+ ],
+ [
+ 9.0,
+ -30
+ ],
+ [
+ 11.0,
+ -30
+ ],
+ [
+ 12.8,
+ -32
+ ],
+ [
+ 14.5,
+ -30
+ ],
+ [
+ 16.5,
+ -30
+ ],
+ [
+ 18.3,
+ -32
+ ],
+ [
+ 20.0,
+ -30
+ ],
+ [
+ 22.0,
+ -30
+ ],
+ [
+ 23.8,
+ -32
+ ],
+ [
+ 25.5,
+ -30
+ ],
+ [
+ 27.5,
+ -30
+ ],
+ [
+ 29.3,
+ -32
+ ],
+ [
+ 31.0,
+ -30
+ ],
+ [
+ 33,
+ -30
+ ],
+ [
+ 33,
+ 30
+ ],
+ [
+ -33,
+ 30
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.rectangle.two_point",
+ "params": {
+ "p0": [
+ -30,
+ -27
+ ],
+ "p1": [
+ 30,
+ 27
+ ]
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 72,
+ "operation": "new",
+ "body_name": "Clear ribbed bin",
+ "profiles": [
+ {
+ "point": [
+ 31,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Bin base tool",
+ "corner": [
+ -190,
+ -53,
+ 57
+ ],
+ "length": 66,
+ "width": 60,
+ "height": 4,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Clear ribbed bin",
+ "tools": [
+ "Bin base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Drip tray profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 22
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "innerleft",
+ "innerback",
+ "innerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "innerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Drip tray",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 41.0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tray base tool profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 21
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 4,
+ "operation": "new",
+ "body_name": "Tray base tool"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Drip tray",
+ "tools": [
+ "Tray base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Perforated stainless grate profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 65
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 2,
+ "operation": "new",
+ "body_name": "Perforated stainless grate",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 38
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Rounded tray cap profile",
+ "plane": {
+ "origin": [
+ 112,
+ -143,
+ 40
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -27.0
+ ],
+ "p1": [
+ 19.0,
+ 27.0
+ ],
+ "radius": 15
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Rounded tray cap"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Louvred service panel profile",
+ "plane": {
+ "origin": [
+ -122,
+ 143,
+ 173
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -47,
+ -91
+ ],
+ "p1": [
+ 47,
+ 91
+ ],
+ "radius": 8
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -62
+ ],
+ "p1": [
+ 31,
+ -58
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -47
+ ],
+ "p1": [
+ 31,
+ -43
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -32
+ ],
+ "p1": [
+ 31,
+ -28
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -17
+ ],
+ "p1": [
+ 31,
+ -13
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -2
+ ],
+ "p1": [
+ 31,
+ 2
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 13
+ ],
+ "p1": [
+ 31,
+ 17
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 28
+ ],
+ "p1": [
+ 31,
+ 32
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 43
+ ],
+ "p1": [
+ 31,
+ 47
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 58
+ ],
+ "p1": [
+ 31,
+ 62
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 3,
+ "operation": "new",
+ "body_name": "Louvred service panel",
+ "profiles": [
+ {
+ "point": [
+ 43,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 1",
+ "base": [
+ -99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 2",
+ "base": [
+ -99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 3",
+ "base": [
+ -99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 4",
+ "base": [
+ -99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 5",
+ "base": [
+ 99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 6",
+ "base": [
+ 99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 7",
+ "base": [
+ 99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 8",
+ "base": [
+ 99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "S cable centerline profile",
+ "plane": {
+ "origin": [
+ 70,
+ -75,
+ 9
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 52,
+ 94
+ ],
+ "through": [
+ 92,
+ 54
+ ],
+ "end": [
+ 132,
+ 94
+ ],
+ "id": "cable_a"
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 132,
+ 94
+ ],
+ "through": [
+ 172,
+ 134
+ ],
+ "end": [
+ 212,
+ 94
+ ],
+ "id": "cable_b"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 212,
+ 94
+ ],
+ [
+ 212,
+ 66
+ ]
+ ],
+ "ids": [
+ "cable_end"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "S cable centerline profile",
+ "path": [
+ "cable_a",
+ "cable_b",
+ "cable_end"
+ ],
+ "diameter": 5,
+ "operation": "new",
+ "body_name": "Black S power cable"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Two pin plug profile",
+ "plane": {
+ "origin": [
+ 282,
+ -30,
+ 3
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -12.0,
+ -17.5
+ ],
+ "p1": [
+ 12.0,
+ 17.5
+ ],
+ "radius": 7
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Two pin plug"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 206",
+ "base": [
+ 276,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 218",
+ "base": [
+ 288,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Housing plinth",
+ "Housing shell",
+ "Housing upper shoulder",
+ "Open brewing head",
+ "Brewing head roof",
+ "Drip tray",
+ "Rounded tray cap"
+ ],
+ "color": "#101318",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.3,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Separate tank lid",
+ "Tank lid grip",
+ "Louvred service panel"
+ ],
+ "color": "#171a1f",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.55,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Brewing collar",
+ "Bent chrome lever",
+ "Left lever ball",
+ "Right lever ball",
+ "Plug pin 206",
+ "Plug pin 218"
+ ],
+ "color": "#d5d9dd",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.12,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Internal chassis",
+ "Shower screen",
+ "Perforated stainless grate"
+ ],
+ "color": "#aeb4bb",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.25,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Zinc screw 1",
+ "Zinc screw 2",
+ "Zinc screw 3",
+ "Zinc screw 4",
+ "Zinc screw 5",
+ "Zinc screw 6",
+ "Zinc screw 7",
+ "Zinc screw 8"
+ ],
+ "color": "#b0b5bc",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.32,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Black S power cable",
+ "Two pin plug"
+ ],
+ "color": "#141414",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.8,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Studio floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "color": "#c2c6ca",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "color": "#e4eff1",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ }
+ ]
+}
diff --git a/examples/studio/coffee-framing-render.json b/examples/studio/coffee-framing-render.json
new file mode 100644
index 0000000000..f5bd0bf07c
--- /dev/null
+++ b/examples/studio/coffee-framing-render.json
@@ -0,0 +1,182 @@
+{
+ "progressive": true,
+ "samples": 256,
+ "max_depth": 12,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -25,
+ -10,
+ 170
+ ],
+ "yaw": 0.5235987755982988,
+ "pitch": 0.3141592653589793,
+ "roll": 0,
+ "distance": 950,
+ "fov": 0.5934119456780721
+ },
+ "background": [
+ 240,
+ 240,
+ 240
+ ]
+ },
+ "lighting": {
+ "environment": [
+ 0.5,
+ 0.5,
+ 0.5
+ ],
+ "area_lights": [
+ {
+ "center": [
+ -392.0,
+ -364.0,
+ 784.0
+ ],
+ "u": [
+ 308.0,
+ 0.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ -196.0,
+ 0.0
+ ],
+ "radiance": [
+ 8,
+ 8,
+ 8
+ ]
+ },
+ {
+ "center": [
+ 784,
+ -448,
+ 504
+ ],
+ "u": [
+ 0.0,
+ -168.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ 0.0,
+ 251.99999999999997
+ ],
+ "radiance": [
+ 6,
+ 6,
+ 6
+ ]
+ },
+ {
+ "center": [
+ 0.0,
+ 475.99999999999994,
+ 700.0
+ ],
+ "u": [
+ 196.0,
+ 0.0,
+ 0.0
+ ],
+ "v": [
+ 0.0,
+ 0.0,
+ 182.0
+ ],
+ "radiance": [
+ 10,
+ 10,
+ 10
+ ]
+ }
+ ]
+ },
+ "raytrace": {
+ "clear_coats": [
+ {
+ "body_index": 1,
+ "body_name": "Housing plinth",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 2,
+ "body_name": "Housing shell",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 3,
+ "body_name": "Housing upper shoulder",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 5,
+ "body_name": "Open brewing head",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 6,
+ "body_name": "Brewing head roof",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 16,
+ "body_name": "Drip tray",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ },
+ {
+ "body_index": 18,
+ "body_name": "Rounded tray cap",
+ "weight": 1,
+ "roughness": 0.12,
+ "ior": 1.5
+ }
+ ],
+ "dielectrics": [
+ {
+ "body_index": 12,
+ "body_name": "Smoky D tank",
+ "ior": 1.586,
+ "absorption_per_mm": [
+ 0.045,
+ 0.075,
+ 0.12
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ },
+ {
+ "body_index": 15,
+ "body_name": "Clear ribbed bin",
+ "ior": 1.49,
+ "absorption_per_mm": [
+ 0.0004,
+ 0.00015,
+ 5e-05
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ }
+ ]
+ }
+}
diff --git a/examples/studio/coffee-framing-sweep.json b/examples/studio/coffee-framing-sweep.json
new file mode 100644
index 0000000000..b1c6403623
--- /dev/null
+++ b/examples/studio/coffee-framing-sweep.json
@@ -0,0 +1,3913 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original exploded bench coffee machine"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Studio floor profile",
+ "plane": {
+ "origin": [
+ -4200.0,
+ 0,
+ 0
+ ],
+ "x_dir": [
+ 0,
+ 1,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -4200.0,
+ 0
+ ],
+ [
+ 700.0,
+ 0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 700.0,
+ 0
+ ],
+ "through": [
+ 1095.9797974644666,
+ 164.02020253553337
+ ],
+ "end": [
+ 1260.0,
+ 560.0
+ ],
+ "id": "inner_sweep"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 1260.0,
+ 560.0
+ ],
+ [
+ 1260.0,
+ 4200.0
+ ],
+ [
+ 1271.2,
+ 4200.0
+ ],
+ [
+ 1271.2,
+ 560.0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 1271.2,
+ 560.0
+ ],
+ "through": [
+ 1103.8993934137561,
+ 156.100606586244
+ ],
+ "end": [
+ 700.0,
+ -11.2
+ ],
+ "id": "outer_sweep"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 700.0,
+ -11.2
+ ],
+ [
+ -4200.0,
+ -11.2
+ ],
+ [
+ -4200.0,
+ 0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 8400.0,
+ "operation": "new",
+ "body_name": "Studio floor"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing plinth profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 30
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -70.0,
+ -65.0
+ ],
+ "p1": [
+ 70.0,
+ 65.0
+ ],
+ "radius": 24
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 12,
+ "operation": "new",
+ "body_name": "Housing plinth"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing shell profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 55
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -65.0,
+ -58.0
+ ],
+ "p1": [
+ 65.0,
+ 58.0
+ ],
+ "radius": 23
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -60.0,
+ -53.0
+ ],
+ "p1": [
+ 60.0,
+ 53.0
+ ],
+ "radius": 18
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 210,
+ "operation": "new",
+ "body_name": "Housing shell",
+ "profiles": [
+ {
+ "point": [
+ -62.5,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -46,
+ -60,
+ 88
+ ],
+ "length": 92,
+ "width": 35,
+ "height": 149,
+ "operation": "cut",
+ "targets": [
+ "Housing shell"
+ ],
+ "name": "Open brewing bay"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing upper shoulder profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 265
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -65.0,
+ -58.0
+ ],
+ "p1": [
+ 65.0,
+ 58.0
+ ],
+ "radius": 23
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 8,
+ "operation": "new",
+ "body_name": "Housing upper shoulder"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Internal chassis",
+ "corner": [
+ -42,
+ 38,
+ 63
+ ],
+ "length": 84,
+ "width": 5,
+ "height": 189,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Open brewing head",
+ "base": [
+ 0,
+ -76,
+ 307
+ ],
+ "radius": 43,
+ "height": 95,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -77,
+ 307
+ ],
+ "radius": 31,
+ "height": 97,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Open brewing head"
+ ],
+ "name": "Horizontal open brew bore"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Brewing head roof profile",
+ "plane": {
+ "origin": [
+ 0,
+ -6,
+ 352
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -57.5,
+ -51.5
+ ],
+ "p1": [
+ 57.5,
+ 51.5
+ ],
+ "radius": 25
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 7,
+ "operation": "new",
+ "body_name": "Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -18,
+ -9,
+ 351
+ ],
+ "length": 36,
+ "width": 7,
+ "height": 9,
+ "operation": "cut",
+ "targets": [
+ "Brewing head roof"
+ ],
+ "name": "Capsule loading slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Brewing collar",
+ "base": [
+ 0,
+ -88,
+ 307
+ ],
+ "radius": 35,
+ "height": 9,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -89,
+ 307
+ ],
+ "radius": 28,
+ "height": 11,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Brewing collar"
+ ],
+ "name": "Open brew throat"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Shower screen",
+ "base": [
+ 0,
+ 10,
+ 307
+ ],
+ "radius": 27,
+ "height": 2,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Lever centerline profile",
+ "plane": {
+ "origin": [
+ 0,
+ -28,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -77,
+ 306
+ ],
+ [
+ -77,
+ 365
+ ]
+ ],
+ "ids": [
+ "lever_left"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ -77,
+ 365
+ ],
+ "through": [
+ -72.6066,
+ 375.6066
+ ],
+ "end": [
+ -62,
+ 380
+ ],
+ "id": "lever_bend_left"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -62,
+ 380
+ ],
+ [
+ 62,
+ 380
+ ]
+ ],
+ "ids": [
+ "lever_top"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 62,
+ 380
+ ],
+ "through": [
+ 72.6066,
+ 375.6066
+ ],
+ "end": [
+ 77,
+ 365
+ ],
+ "id": "lever_bend_right"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 77,
+ 365
+ ],
+ [
+ 77,
+ 306
+ ]
+ ],
+ "ids": [
+ "lever_right"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "Lever centerline profile",
+ "path": [
+ "lever_left",
+ "lever_bend_left",
+ "lever_top",
+ "lever_bend_right",
+ "lever_right"
+ ],
+ "diameter": 9,
+ "operation": "new",
+ "body_name": "Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Left lever ball",
+ "center": [
+ -77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Right lever ball",
+ "center": [
+ 77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Smoky D tank profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 99
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -43,
+ 0
+ ],
+ [
+ -43,
+ 45
+ ],
+ [
+ 43,
+ 45
+ ],
+ [
+ 43,
+ 0
+ ],
+ [
+ 42.948204616822416,
+ -2.1099099960789744
+ ],
+ [
+ 42.79294324690447,
+ -4.214737034171106
+ ],
+ [
+ 42.53458992848558,
+ -6.309410401580555
+ ],
+ [
+ 42.17376705733891,
+ -8.388883846693515
+ ],
+ [
+ 41.71134388736539,
+ -10.448147735840346
+ ],
+ [
+ 41.148434436484976,
+ -12.48224112194188
+ ],
+ [
+ 40.486394802869896,
+ -14.486263695865462
+ ],
+ [
+ 39.72681989798533,
+ -16.455387591698862
+ ],
+ [
+ 38.87153960430806,
+ -18.38486901750213
+ ],
+ [
+ 37.92261436697927,
+ -20.2700596835179
+ ],
+ [
+ 36.8823302300117,
+ -22.10641800030853
+ ],
+ [
+ 35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ 34.537923853667735,
+ -25.615070093174634
+ ],
+ [
+ 33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ 31.860898390263245,
+ -28.87703505842179
+ ],
+ [
+ 30.405591591021544,
+ -30.405591591021544
+ ],
+ [
+ 28.87703505842179,
+ -31.86089839026324
+ ],
+ [
+ 27.278911219036758,
+ -33.239449494597686
+ ],
+ [
+ 25.61507009317464,
+ -34.53792385366773
+ ],
+ [
+ 23.889520019842898,
+ -35.75319332900945
+ ],
+ [
+ 22.10641800030853,
+ -36.8823302300117
+ ],
+ [
+ 20.270059683517907,
+ -37.92261436697926
+ ],
+ [
+ 18.384869017502133,
+ -38.87153960430806
+ ],
+ [
+ 16.455387591698862,
+ -39.72681989798533
+ ],
+ [
+ 14.486263695865462,
+ -40.486394802869896
+ ],
+ [
+ 12.48224112194188,
+ -41.14843443648498
+ ],
+ [
+ 10.448147735840351,
+ -41.71134388736539
+ ],
+ [
+ 8.388883846693519,
+ -42.17376705733891
+ ],
+ [
+ 6.309410401580555,
+ -42.53458992848558
+ ],
+ [
+ 4.2147370341711135,
+ -42.792943246904464
+ ],
+ [
+ 2.1099099960789793,
+ -42.948204616822416
+ ],
+ [
+ 2.6329906181668092e-15,
+ -43.0
+ ],
+ [
+ -2.1099099960789744,
+ -42.948204616822416
+ ],
+ [
+ -4.214737034171108,
+ -42.79294324690447
+ ],
+ [
+ -6.309410401580551,
+ -42.53458992848558
+ ],
+ [
+ -8.388883846693512,
+ -42.17376705733891
+ ],
+ [
+ -10.448147735840346,
+ -41.71134388736539
+ ],
+ [
+ -12.482241121941874,
+ -41.14843443648498
+ ],
+ [
+ -14.486263695865457,
+ -40.486394802869896
+ ],
+ [
+ -16.45538759169886,
+ -39.72681989798533
+ ],
+ [
+ -18.38486901750212,
+ -38.87153960430807
+ ],
+ [
+ -20.2700596835179,
+ -37.92261436697927
+ ],
+ [
+ -22.106418000308526,
+ -36.8823302300117
+ ],
+ [
+ -23.889520019842884,
+ -35.75319332900945
+ ],
+ [
+ -25.615070093174634,
+ -34.537923853667735
+ ],
+ [
+ -27.27891121903675,
+ -33.23944949459769
+ ],
+ [
+ -28.877035058421793,
+ -31.860898390263237
+ ],
+ [
+ -30.40559159102154,
+ -30.405591591021544
+ ],
+ [
+ -31.86089839026323,
+ -28.877035058421797
+ ],
+ [
+ -33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ -34.53792385366773,
+ -25.61507009317464
+ ],
+ [
+ -35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ -36.882330230011696,
+ -22.106418000308537
+ ],
+ [
+ -37.92261436697926,
+ -20.270059683517907
+ ],
+ [
+ -38.87153960430806,
+ -18.384869017502126
+ ],
+ [
+ -39.72681989798533,
+ -16.455387591698866
+ ],
+ [
+ -40.48639480286989,
+ -14.486263695865475
+ ],
+ [
+ -41.148434436484976,
+ -12.482241121941883
+ ],
+ [
+ -41.71134388736539,
+ -10.448147735840354
+ ],
+ [
+ -42.17376705733891,
+ -8.38888384669353
+ ],
+ [
+ -42.53458992848558,
+ -6.309410401580558
+ ],
+ [
+ -42.792943246904464,
+ -4.214737034171115
+ ],
+ [
+ -42.948204616822416,
+ -2.1099099960789727
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 171,
+ "operation": "new",
+ "body_name": "Smoky D tank"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank cavity profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 103
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -40,
+ 0
+ ],
+ [
+ -40,
+ 42
+ ],
+ [
+ 40,
+ 42
+ ],
+ [
+ 40,
+ 0
+ ],
+ [
+ 39.9518182482069,
+ -1.9627069730967206
+ ],
+ [
+ 39.80738906688788,
+ -3.920685613182424
+ ],
+ [
+ 39.56706039859124,
+ -5.8692189782144695
+ ],
+ [
+ 39.23141121612922,
+ -7.8036128806451295
+ ],
+ [
+ 38.801250127781756,
+ -9.719207196130554
+ ],
+ [
+ 38.27761342928835,
+ -11.611387090178493
+ ],
+ [
+ 37.66176260732083,
+ -13.475594135688802
+ ],
+ [
+ 36.95518130045147,
+ -15.307337294603592
+ ],
+ [
+ 36.159571724937734,
+ -17.102203737211283
+ ],
+ [
+ 35.276850573934205,
+ -18.855869473039906
+ ],
+ [
+ 34.30914440001089,
+ -20.564109767728866
+ ],
+ [
+ 33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ 32.1283012592258,
+ -23.827972179697333
+ ],
+ [
+ 30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ 29.63804501419837,
+ -26.862358193880734
+ ],
+ [
+ 28.284271247461902,
+ -28.284271247461902
+ ],
+ [
+ 26.862358193880734,
+ -29.638045014198365
+ ],
+ [
+ 25.37573136654582,
+ -30.920418134509475
+ ],
+ [
+ 23.82797217969734,
+ -32.12830125922579
+ ],
+ [
+ 22.22280932078409,
+ -33.25878449210181
+ ],
+ [
+ 20.564109767728866,
+ -34.30914440001089
+ ],
+ [
+ 18.855869473039913,
+ -35.2768505739342
+ ],
+ [
+ 17.102203737211287,
+ -36.159571724937734
+ ],
+ [
+ 15.307337294603593,
+ -36.95518130045147
+ ],
+ [
+ 13.475594135688802,
+ -37.66176260732083
+ ],
+ [
+ 11.611387090178493,
+ -38.27761342928836
+ ],
+ [
+ 9.71920719613056,
+ -38.801250127781756
+ ],
+ [
+ 7.803612880645133,
+ -39.23141121612922
+ ],
+ [
+ 5.8692189782144695,
+ -39.56706039859124
+ ],
+ [
+ 3.920685613182431,
+ -39.80738906688787
+ ],
+ [
+ 1.962706973096725,
+ -39.9518182482069
+ ],
+ [
+ 2.4492935982947065e-15,
+ -40.0
+ ],
+ [
+ -1.9627069730967204,
+ -39.9518182482069
+ ],
+ [
+ -3.920685613182426,
+ -39.80738906688788
+ ],
+ [
+ -5.869218978214466,
+ -39.56706039859124
+ ],
+ [
+ -7.803612880645128,
+ -39.23141121612922
+ ],
+ [
+ -9.719207196130554,
+ -38.801250127781756
+ ],
+ [
+ -11.611387090178486,
+ -38.27761342928836
+ ],
+ [
+ -13.475594135688798,
+ -37.66176260732083
+ ],
+ [
+ -15.307337294603588,
+ -36.95518130045147
+ ],
+ [
+ -17.102203737211276,
+ -36.159571724937734
+ ],
+ [
+ -18.85586947303991,
+ -35.276850573934205
+ ],
+ [
+ -20.564109767728862,
+ -34.30914440001089
+ ],
+ [
+ -22.22280932078408,
+ -33.25878449210181
+ ],
+ [
+ -23.827972179697333,
+ -32.1283012592258
+ ],
+ [
+ -25.375731366545814,
+ -30.920418134509482
+ ],
+ [
+ -26.862358193880738,
+ -29.63804501419836
+ ],
+ [
+ -28.2842712474619,
+ -28.284271247461902
+ ],
+ [
+ -29.638045014198354,
+ -26.86235819388074
+ ],
+ [
+ -30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ -32.12830125922579,
+ -23.82797217969734
+ ],
+ [
+ -33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ -34.30914440001088,
+ -20.564109767728873
+ ],
+ [
+ -35.2768505739342,
+ -18.855869473039913
+ ],
+ [
+ -36.159571724937734,
+ -17.10220373721128
+ ],
+ [
+ -36.95518130045147,
+ -15.307337294603595
+ ],
+ [
+ -37.661762607320824,
+ -13.475594135688812
+ ],
+ [
+ -38.27761342928835,
+ -11.611387090178496
+ ],
+ [
+ -38.801250127781756,
+ -9.719207196130563
+ ],
+ [
+ -39.23141121612922,
+ -7.803612880645145
+ ],
+ [
+ -39.56706039859124,
+ -5.869218978214472
+ ],
+ [
+ -39.80738906688787,
+ -3.920685613182433
+ ],
+ [
+ -39.9518182482069,
+ -1.9627069730967186
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 169,
+ "operation": "cut",
+ "targets": [
+ "Smoky D tank"
+ ],
+ "name": "Open tank cavity with four millimetre base"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Separate tank lid profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 304
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -45,
+ 0
+ ],
+ [
+ -45,
+ 47
+ ],
+ [
+ 45,
+ 47
+ ],
+ [
+ 45,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 45,
+ 0
+ ],
+ "end": [
+ -45,
+ 0
+ ],
+ "through": [
+ 0,
+ -45
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Separate tank lid"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank lid grip profile",
+ "plane": {
+ "origin": [
+ 225,
+ 41,
+ 309
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -6.0
+ ],
+ "p1": [
+ 19.0,
+ 6.0
+ ],
+ "radius": 5
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Tank lid grip"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Clear ribbed bin profile",
+ "plane": {
+ "origin": [
+ -157,
+ -23,
+ 58
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -33.0,
+ -30
+ ],
+ [
+ -31.2,
+ -32
+ ],
+ [
+ -29.5,
+ -30
+ ],
+ [
+ -27.5,
+ -30
+ ],
+ [
+ -25.7,
+ -32
+ ],
+ [
+ -24.0,
+ -30
+ ],
+ [
+ -22.0,
+ -30
+ ],
+ [
+ -20.2,
+ -32
+ ],
+ [
+ -18.5,
+ -30
+ ],
+ [
+ -16.5,
+ -30
+ ],
+ [
+ -14.7,
+ -32
+ ],
+ [
+ -13.0,
+ -30
+ ],
+ [
+ -11.0,
+ -30
+ ],
+ [
+ -9.2,
+ -32
+ ],
+ [
+ -7.5,
+ -30
+ ],
+ [
+ -5.5,
+ -30
+ ],
+ [
+ -3.7,
+ -32
+ ],
+ [
+ -2.0,
+ -30
+ ],
+ [
+ 0.0,
+ -30
+ ],
+ [
+ 1.8,
+ -32
+ ],
+ [
+ 3.5,
+ -30
+ ],
+ [
+ 5.5,
+ -30
+ ],
+ [
+ 7.3,
+ -32
+ ],
+ [
+ 9.0,
+ -30
+ ],
+ [
+ 11.0,
+ -30
+ ],
+ [
+ 12.8,
+ -32
+ ],
+ [
+ 14.5,
+ -30
+ ],
+ [
+ 16.5,
+ -30
+ ],
+ [
+ 18.3,
+ -32
+ ],
+ [
+ 20.0,
+ -30
+ ],
+ [
+ 22.0,
+ -30
+ ],
+ [
+ 23.8,
+ -32
+ ],
+ [
+ 25.5,
+ -30
+ ],
+ [
+ 27.5,
+ -30
+ ],
+ [
+ 29.3,
+ -32
+ ],
+ [
+ 31.0,
+ -30
+ ],
+ [
+ 33,
+ -30
+ ],
+ [
+ 33,
+ 30
+ ],
+ [
+ -33,
+ 30
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.rectangle.two_point",
+ "params": {
+ "p0": [
+ -30,
+ -27
+ ],
+ "p1": [
+ 30,
+ 27
+ ]
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 72,
+ "operation": "new",
+ "body_name": "Clear ribbed bin",
+ "profiles": [
+ {
+ "point": [
+ 31,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Bin base tool",
+ "corner": [
+ -190,
+ -53,
+ 57
+ ],
+ "length": 66,
+ "width": 60,
+ "height": 4,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Clear ribbed bin",
+ "tools": [
+ "Bin base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Drip tray profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 22
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "innerleft",
+ "innerback",
+ "innerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "innerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Drip tray",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 41.0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tray base tool profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 21
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 4,
+ "operation": "new",
+ "body_name": "Tray base tool"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Drip tray",
+ "tools": [
+ "Tray base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Perforated stainless grate profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 65
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 2,
+ "operation": "new",
+ "body_name": "Perforated stainless grate",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 38
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Rounded tray cap profile",
+ "plane": {
+ "origin": [
+ 112,
+ -143,
+ 40
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -27.0
+ ],
+ "p1": [
+ 19.0,
+ 27.0
+ ],
+ "radius": 15
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Rounded tray cap"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Louvred service panel profile",
+ "plane": {
+ "origin": [
+ -122,
+ 143,
+ 173
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -47,
+ -91
+ ],
+ "p1": [
+ 47,
+ 91
+ ],
+ "radius": 8
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -62
+ ],
+ "p1": [
+ 31,
+ -58
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -47
+ ],
+ "p1": [
+ 31,
+ -43
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -32
+ ],
+ "p1": [
+ 31,
+ -28
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -17
+ ],
+ "p1": [
+ 31,
+ -13
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -2
+ ],
+ "p1": [
+ 31,
+ 2
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 13
+ ],
+ "p1": [
+ 31,
+ 17
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 28
+ ],
+ "p1": [
+ 31,
+ 32
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 43
+ ],
+ "p1": [
+ 31,
+ 47
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 58
+ ],
+ "p1": [
+ 31,
+ 62
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 3,
+ "operation": "new",
+ "body_name": "Louvred service panel",
+ "profiles": [
+ {
+ "point": [
+ 43,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 1",
+ "base": [
+ -99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 2",
+ "base": [
+ -99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 3",
+ "base": [
+ -99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 4",
+ "base": [
+ -99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 5",
+ "base": [
+ 99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 6",
+ "base": [
+ 99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 7",
+ "base": [
+ 99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 8",
+ "base": [
+ 99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "S cable centerline profile",
+ "plane": {
+ "origin": [
+ 70,
+ -75,
+ 9
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 52,
+ 94
+ ],
+ "through": [
+ 92,
+ 54
+ ],
+ "end": [
+ 132,
+ 94
+ ],
+ "id": "cable_a"
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 132,
+ 94
+ ],
+ "through": [
+ 172,
+ 134
+ ],
+ "end": [
+ 212,
+ 94
+ ],
+ "id": "cable_b"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 212,
+ 94
+ ],
+ [
+ 212,
+ 66
+ ]
+ ],
+ "ids": [
+ "cable_end"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "S cable centerline profile",
+ "path": [
+ "cable_a",
+ "cable_b",
+ "cable_end"
+ ],
+ "diameter": 5,
+ "operation": "new",
+ "body_name": "Black S power cable"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Two pin plug profile",
+ "plane": {
+ "origin": [
+ 282,
+ -30,
+ 3
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -12.0,
+ -17.5
+ ],
+ "p1": [
+ 12.0,
+ 17.5
+ ],
+ "radius": 7
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Two pin plug"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 206",
+ "base": [
+ 276,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 218",
+ "base": [
+ 288,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Housing plinth",
+ "Housing shell",
+ "Housing upper shoulder",
+ "Open brewing head",
+ "Brewing head roof",
+ "Drip tray",
+ "Rounded tray cap"
+ ],
+ "color": "#101318",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.3,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Separate tank lid",
+ "Tank lid grip",
+ "Louvred service panel"
+ ],
+ "color": "#171a1f",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.55,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Brewing collar",
+ "Bent chrome lever",
+ "Left lever ball",
+ "Right lever ball",
+ "Plug pin 206",
+ "Plug pin 218"
+ ],
+ "color": "#d5d9dd",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.12,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Internal chassis",
+ "Shower screen",
+ "Perforated stainless grate"
+ ],
+ "color": "#aeb4bb",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.25,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Zinc screw 1",
+ "Zinc screw 2",
+ "Zinc screw 3",
+ "Zinc screw 4",
+ "Zinc screw 5",
+ "Zinc screw 6",
+ "Zinc screw 7",
+ "Zinc screw 8"
+ ],
+ "color": "#b0b5bc",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.32,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Black S power cable",
+ "Two pin plug"
+ ],
+ "color": "#141414",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.8,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Studio floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "color": "#c2c6ca",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "color": "#e4eff1",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Open brewing head"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Open brewing head"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Brewing collar"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Brewing collar"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Shower screen"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Shower screen"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Brewing head roof"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Bent chrome lever"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Left lever ball"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Left lever ball"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Right lever ball"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Right lever ball"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Smoky D tank"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Separate tank lid"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 22
+ ],
+ "copy": false,
+ "name": "Framing: Separate tank lid"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Tank lid grip"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 22
+ ],
+ "copy": false,
+ "name": "Framing: Tank lid grip"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "translate": [
+ -70,
+ -15,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Clear ribbed bin"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Louvred service panel"
+ ],
+ "translate": [
+ -110,
+ 15,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Louvred service panel"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Drip tray"
+ ],
+ "translate": [
+ 0,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Drip tray"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Perforated stainless grate"
+ ],
+ "translate": [
+ 0,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Perforated stainless grate"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Rounded tray cap"
+ ],
+ "translate": [
+ 38,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Rounded tray cap"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Black S power cable"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Black S power cable"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Two pin plug"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Two pin plug"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plug pin 206"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Plug pin 206"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plug pin 218"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Plug pin 218"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 1"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 1"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 2"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 2"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 3"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 3"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 4"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 4"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 5"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 5"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 6"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 6"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 7"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 7"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 8"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 8"
+ }
+ }
+ ]
+}
diff --git a/examples/studio/coffee-framing.json b/examples/studio/coffee-framing.json
new file mode 100644
index 0000000000..90954e605d
--- /dev/null
+++ b/examples/studio/coffee-framing.json
@@ -0,0 +1,3797 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original exploded bench coffee machine"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Studio floor",
+ "corner": [
+ -6000,
+ -6000,
+ -5
+ ],
+ "length": 12000,
+ "width": 12000,
+ "height": 5,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing plinth profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 30
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -70.0,
+ -65.0
+ ],
+ "p1": [
+ 70.0,
+ 65.0
+ ],
+ "radius": 24
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 12,
+ "operation": "new",
+ "body_name": "Housing plinth"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing shell profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 55
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -65.0,
+ -58.0
+ ],
+ "p1": [
+ 65.0,
+ 58.0
+ ],
+ "radius": 23
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -60.0,
+ -53.0
+ ],
+ "p1": [
+ 60.0,
+ 53.0
+ ],
+ "radius": 18
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 210,
+ "operation": "new",
+ "body_name": "Housing shell",
+ "profiles": [
+ {
+ "point": [
+ -62.5,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -46,
+ -60,
+ 88
+ ],
+ "length": 92,
+ "width": 35,
+ "height": 149,
+ "operation": "cut",
+ "targets": [
+ "Housing shell"
+ ],
+ "name": "Open brewing bay"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Housing upper shoulder profile",
+ "plane": {
+ "origin": [
+ 0,
+ 8,
+ 265
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -65.0,
+ -58.0
+ ],
+ "p1": [
+ 65.0,
+ 58.0
+ ],
+ "radius": 23
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 8,
+ "operation": "new",
+ "body_name": "Housing upper shoulder"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Internal chassis",
+ "corner": [
+ -42,
+ 38,
+ 63
+ ],
+ "length": 84,
+ "width": 5,
+ "height": 189,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Open brewing head",
+ "base": [
+ 0,
+ -76,
+ 307
+ ],
+ "radius": 43,
+ "height": 95,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -77,
+ 307
+ ],
+ "radius": 31,
+ "height": 97,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Open brewing head"
+ ],
+ "name": "Horizontal open brew bore"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Brewing head roof profile",
+ "plane": {
+ "origin": [
+ 0,
+ -6,
+ 352
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -57.5,
+ -51.5
+ ],
+ "p1": [
+ 57.5,
+ 51.5
+ ],
+ "radius": 25
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 7,
+ "operation": "new",
+ "body_name": "Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -18,
+ -9,
+ 351
+ ],
+ "length": 36,
+ "width": 7,
+ "height": 9,
+ "operation": "cut",
+ "targets": [
+ "Brewing head roof"
+ ],
+ "name": "Capsule loading slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Brewing collar",
+ "base": [
+ 0,
+ -88,
+ 307
+ ],
+ "radius": 35,
+ "height": 9,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ -89,
+ 307
+ ],
+ "radius": 28,
+ "height": 11,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Brewing collar"
+ ],
+ "name": "Open brew throat"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Shower screen",
+ "base": [
+ 0,
+ 10,
+ 307
+ ],
+ "radius": 27,
+ "height": 2,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 300
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 0,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 10,
+ 9,
+ 314
+ ],
+ "radius": 1.6,
+ "height": 4,
+ "axis": "Y",
+ "operation": "cut",
+ "targets": [
+ "Shower screen"
+ ],
+ "name": "Shower aperture"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Lever centerline profile",
+ "plane": {
+ "origin": [
+ 0,
+ -28,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -77,
+ 306
+ ],
+ [
+ -77,
+ 365
+ ]
+ ],
+ "ids": [
+ "lever_left"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ -77,
+ 365
+ ],
+ "through": [
+ -72.6066,
+ 375.6066
+ ],
+ "end": [
+ -62,
+ 380
+ ],
+ "id": "lever_bend_left"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -62,
+ 380
+ ],
+ [
+ 62,
+ 380
+ ]
+ ],
+ "ids": [
+ "lever_top"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 62,
+ 380
+ ],
+ "through": [
+ 72.6066,
+ 375.6066
+ ],
+ "end": [
+ 77,
+ 365
+ ],
+ "id": "lever_bend_right"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 77,
+ 365
+ ],
+ [
+ 77,
+ 306
+ ]
+ ],
+ "ids": [
+ "lever_right"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "Lever centerline profile",
+ "path": [
+ "lever_left",
+ "lever_bend_left",
+ "lever_top",
+ "lever_bend_right",
+ "lever_right"
+ ],
+ "diameter": 9,
+ "operation": "new",
+ "body_name": "Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Left lever ball",
+ "center": [
+ -77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Right lever ball",
+ "center": [
+ 77,
+ -28,
+ 306
+ ],
+ "radius": 8,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Smoky D tank profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 99
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -43,
+ 0
+ ],
+ [
+ -43,
+ 45
+ ],
+ [
+ 43,
+ 45
+ ],
+ [
+ 43,
+ 0
+ ],
+ [
+ 42.948204616822416,
+ -2.1099099960789744
+ ],
+ [
+ 42.79294324690447,
+ -4.214737034171106
+ ],
+ [
+ 42.53458992848558,
+ -6.309410401580555
+ ],
+ [
+ 42.17376705733891,
+ -8.388883846693515
+ ],
+ [
+ 41.71134388736539,
+ -10.448147735840346
+ ],
+ [
+ 41.148434436484976,
+ -12.48224112194188
+ ],
+ [
+ 40.486394802869896,
+ -14.486263695865462
+ ],
+ [
+ 39.72681989798533,
+ -16.455387591698862
+ ],
+ [
+ 38.87153960430806,
+ -18.38486901750213
+ ],
+ [
+ 37.92261436697927,
+ -20.2700596835179
+ ],
+ [
+ 36.8823302300117,
+ -22.10641800030853
+ ],
+ [
+ 35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ 34.537923853667735,
+ -25.615070093174634
+ ],
+ [
+ 33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ 31.860898390263245,
+ -28.87703505842179
+ ],
+ [
+ 30.405591591021544,
+ -30.405591591021544
+ ],
+ [
+ 28.87703505842179,
+ -31.86089839026324
+ ],
+ [
+ 27.278911219036758,
+ -33.239449494597686
+ ],
+ [
+ 25.61507009317464,
+ -34.53792385366773
+ ],
+ [
+ 23.889520019842898,
+ -35.75319332900945
+ ],
+ [
+ 22.10641800030853,
+ -36.8823302300117
+ ],
+ [
+ 20.270059683517907,
+ -37.92261436697926
+ ],
+ [
+ 18.384869017502133,
+ -38.87153960430806
+ ],
+ [
+ 16.455387591698862,
+ -39.72681989798533
+ ],
+ [
+ 14.486263695865462,
+ -40.486394802869896
+ ],
+ [
+ 12.48224112194188,
+ -41.14843443648498
+ ],
+ [
+ 10.448147735840351,
+ -41.71134388736539
+ ],
+ [
+ 8.388883846693519,
+ -42.17376705733891
+ ],
+ [
+ 6.309410401580555,
+ -42.53458992848558
+ ],
+ [
+ 4.2147370341711135,
+ -42.792943246904464
+ ],
+ [
+ 2.1099099960789793,
+ -42.948204616822416
+ ],
+ [
+ 2.6329906181668092e-15,
+ -43.0
+ ],
+ [
+ -2.1099099960789744,
+ -42.948204616822416
+ ],
+ [
+ -4.214737034171108,
+ -42.79294324690447
+ ],
+ [
+ -6.309410401580551,
+ -42.53458992848558
+ ],
+ [
+ -8.388883846693512,
+ -42.17376705733891
+ ],
+ [
+ -10.448147735840346,
+ -41.71134388736539
+ ],
+ [
+ -12.482241121941874,
+ -41.14843443648498
+ ],
+ [
+ -14.486263695865457,
+ -40.486394802869896
+ ],
+ [
+ -16.45538759169886,
+ -39.72681989798533
+ ],
+ [
+ -18.38486901750212,
+ -38.87153960430807
+ ],
+ [
+ -20.2700596835179,
+ -37.92261436697927
+ ],
+ [
+ -22.106418000308526,
+ -36.8823302300117
+ ],
+ [
+ -23.889520019842884,
+ -35.75319332900945
+ ],
+ [
+ -25.615070093174634,
+ -34.537923853667735
+ ],
+ [
+ -27.27891121903675,
+ -33.23944949459769
+ ],
+ [
+ -28.877035058421793,
+ -31.860898390263237
+ ],
+ [
+ -30.40559159102154,
+ -30.405591591021544
+ ],
+ [
+ -31.86089839026323,
+ -28.877035058421797
+ ],
+ [
+ -33.23944949459769,
+ -27.278911219036758
+ ],
+ [
+ -34.53792385366773,
+ -25.61507009317464
+ ],
+ [
+ -35.75319332900945,
+ -23.889520019842895
+ ],
+ [
+ -36.882330230011696,
+ -22.106418000308537
+ ],
+ [
+ -37.92261436697926,
+ -20.270059683517907
+ ],
+ [
+ -38.87153960430806,
+ -18.384869017502126
+ ],
+ [
+ -39.72681989798533,
+ -16.455387591698866
+ ],
+ [
+ -40.48639480286989,
+ -14.486263695865475
+ ],
+ [
+ -41.148434436484976,
+ -12.482241121941883
+ ],
+ [
+ -41.71134388736539,
+ -10.448147735840354
+ ],
+ [
+ -42.17376705733891,
+ -8.38888384669353
+ ],
+ [
+ -42.53458992848558,
+ -6.309410401580558
+ ],
+ [
+ -42.792943246904464,
+ -4.214737034171115
+ ],
+ [
+ -42.948204616822416,
+ -2.1099099960789727
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 171,
+ "operation": "new",
+ "body_name": "Smoky D tank"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank cavity profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 103
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -40,
+ 0
+ ],
+ [
+ -40,
+ 42
+ ],
+ [
+ 40,
+ 42
+ ],
+ [
+ 40,
+ 0
+ ],
+ [
+ 39.9518182482069,
+ -1.9627069730967206
+ ],
+ [
+ 39.80738906688788,
+ -3.920685613182424
+ ],
+ [
+ 39.56706039859124,
+ -5.8692189782144695
+ ],
+ [
+ 39.23141121612922,
+ -7.8036128806451295
+ ],
+ [
+ 38.801250127781756,
+ -9.719207196130554
+ ],
+ [
+ 38.27761342928835,
+ -11.611387090178493
+ ],
+ [
+ 37.66176260732083,
+ -13.475594135688802
+ ],
+ [
+ 36.95518130045147,
+ -15.307337294603592
+ ],
+ [
+ 36.159571724937734,
+ -17.102203737211283
+ ],
+ [
+ 35.276850573934205,
+ -18.855869473039906
+ ],
+ [
+ 34.30914440001089,
+ -20.564109767728866
+ ],
+ [
+ 33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ 32.1283012592258,
+ -23.827972179697333
+ ],
+ [
+ 30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ 29.63804501419837,
+ -26.862358193880734
+ ],
+ [
+ 28.284271247461902,
+ -28.284271247461902
+ ],
+ [
+ 26.862358193880734,
+ -29.638045014198365
+ ],
+ [
+ 25.37573136654582,
+ -30.920418134509475
+ ],
+ [
+ 23.82797217969734,
+ -32.12830125922579
+ ],
+ [
+ 22.22280932078409,
+ -33.25878449210181
+ ],
+ [
+ 20.564109767728866,
+ -34.30914440001089
+ ],
+ [
+ 18.855869473039913,
+ -35.2768505739342
+ ],
+ [
+ 17.102203737211287,
+ -36.159571724937734
+ ],
+ [
+ 15.307337294603593,
+ -36.95518130045147
+ ],
+ [
+ 13.475594135688802,
+ -37.66176260732083
+ ],
+ [
+ 11.611387090178493,
+ -38.27761342928836
+ ],
+ [
+ 9.71920719613056,
+ -38.801250127781756
+ ],
+ [
+ 7.803612880645133,
+ -39.23141121612922
+ ],
+ [
+ 5.8692189782144695,
+ -39.56706039859124
+ ],
+ [
+ 3.920685613182431,
+ -39.80738906688787
+ ],
+ [
+ 1.962706973096725,
+ -39.9518182482069
+ ],
+ [
+ 2.4492935982947065e-15,
+ -40.0
+ ],
+ [
+ -1.9627069730967204,
+ -39.9518182482069
+ ],
+ [
+ -3.920685613182426,
+ -39.80738906688788
+ ],
+ [
+ -5.869218978214466,
+ -39.56706039859124
+ ],
+ [
+ -7.803612880645128,
+ -39.23141121612922
+ ],
+ [
+ -9.719207196130554,
+ -38.801250127781756
+ ],
+ [
+ -11.611387090178486,
+ -38.27761342928836
+ ],
+ [
+ -13.475594135688798,
+ -37.66176260732083
+ ],
+ [
+ -15.307337294603588,
+ -36.95518130045147
+ ],
+ [
+ -17.102203737211276,
+ -36.159571724937734
+ ],
+ [
+ -18.85586947303991,
+ -35.276850573934205
+ ],
+ [
+ -20.564109767728862,
+ -34.30914440001089
+ ],
+ [
+ -22.22280932078408,
+ -33.25878449210181
+ ],
+ [
+ -23.827972179697333,
+ -32.1283012592258
+ ],
+ [
+ -25.375731366545814,
+ -30.920418134509482
+ ],
+ [
+ -26.862358193880738,
+ -29.63804501419836
+ ],
+ [
+ -28.2842712474619,
+ -28.284271247461902
+ ],
+ [
+ -29.638045014198354,
+ -26.86235819388074
+ ],
+ [
+ -30.92041813450948,
+ -25.37573136654582
+ ],
+ [
+ -32.12830125922579,
+ -23.82797217969734
+ ],
+ [
+ -33.25878449210181,
+ -22.222809320784087
+ ],
+ [
+ -34.30914440001088,
+ -20.564109767728873
+ ],
+ [
+ -35.2768505739342,
+ -18.855869473039913
+ ],
+ [
+ -36.159571724937734,
+ -17.10220373721128
+ ],
+ [
+ -36.95518130045147,
+ -15.307337294603595
+ ],
+ [
+ -37.661762607320824,
+ -13.475594135688812
+ ],
+ [
+ -38.27761342928835,
+ -11.611387090178496
+ ],
+ [
+ -38.801250127781756,
+ -9.719207196130563
+ ],
+ [
+ -39.23141121612922,
+ -7.803612880645145
+ ],
+ [
+ -39.56706039859124,
+ -5.869218978214472
+ ],
+ [
+ -39.80738906688787,
+ -3.920685613182433
+ ],
+ [
+ -39.9518182482069,
+ -1.9627069730967186
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 169,
+ "operation": "cut",
+ "targets": [
+ "Smoky D tank"
+ ],
+ "name": "Open tank cavity with four millimetre base"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Separate tank lid profile",
+ "plane": {
+ "origin": [
+ 225,
+ 35,
+ 304
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -45,
+ 0
+ ],
+ [
+ -45,
+ 47
+ ],
+ [
+ 45,
+ 47
+ ],
+ [
+ 45,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 45,
+ 0
+ ],
+ "end": [
+ -45,
+ 0
+ ],
+ "through": [
+ 0,
+ -45
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Separate tank lid"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tank lid grip profile",
+ "plane": {
+ "origin": [
+ 225,
+ 41,
+ 309
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -6.0
+ ],
+ "p1": [
+ 19.0,
+ 6.0
+ ],
+ "radius": 5
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Tank lid grip"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Clear ribbed bin profile",
+ "plane": {
+ "origin": [
+ -157,
+ -23,
+ 58
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -33.0,
+ -30
+ ],
+ [
+ -31.2,
+ -32
+ ],
+ [
+ -29.5,
+ -30
+ ],
+ [
+ -27.5,
+ -30
+ ],
+ [
+ -25.7,
+ -32
+ ],
+ [
+ -24.0,
+ -30
+ ],
+ [
+ -22.0,
+ -30
+ ],
+ [
+ -20.2,
+ -32
+ ],
+ [
+ -18.5,
+ -30
+ ],
+ [
+ -16.5,
+ -30
+ ],
+ [
+ -14.7,
+ -32
+ ],
+ [
+ -13.0,
+ -30
+ ],
+ [
+ -11.0,
+ -30
+ ],
+ [
+ -9.2,
+ -32
+ ],
+ [
+ -7.5,
+ -30
+ ],
+ [
+ -5.5,
+ -30
+ ],
+ [
+ -3.7,
+ -32
+ ],
+ [
+ -2.0,
+ -30
+ ],
+ [
+ 0.0,
+ -30
+ ],
+ [
+ 1.8,
+ -32
+ ],
+ [
+ 3.5,
+ -30
+ ],
+ [
+ 5.5,
+ -30
+ ],
+ [
+ 7.3,
+ -32
+ ],
+ [
+ 9.0,
+ -30
+ ],
+ [
+ 11.0,
+ -30
+ ],
+ [
+ 12.8,
+ -32
+ ],
+ [
+ 14.5,
+ -30
+ ],
+ [
+ 16.5,
+ -30
+ ],
+ [
+ 18.3,
+ -32
+ ],
+ [
+ 20.0,
+ -30
+ ],
+ [
+ 22.0,
+ -30
+ ],
+ [
+ 23.8,
+ -32
+ ],
+ [
+ 25.5,
+ -30
+ ],
+ [
+ 27.5,
+ -30
+ ],
+ [
+ 29.3,
+ -32
+ ],
+ [
+ 31.0,
+ -30
+ ],
+ [
+ 33,
+ -30
+ ],
+ [
+ 33,
+ 30
+ ],
+ [
+ -33,
+ 30
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.rectangle.two_point",
+ "params": {
+ "p0": [
+ -30,
+ -27
+ ],
+ "p1": [
+ 30,
+ 27
+ ]
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 72,
+ "operation": "new",
+ "body_name": "Clear ribbed bin",
+ "profiles": [
+ {
+ "point": [
+ 31,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Bin base tool",
+ "corner": [
+ -190,
+ -53,
+ 57
+ ],
+ "length": 66,
+ "width": 60,
+ "height": 4,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Clear ribbed bin",
+ "tools": [
+ "Bin base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Drip tray profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 22
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "innerleft",
+ "innerback",
+ "innerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "innerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Drip tray",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 41.0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tray base tool profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 21
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -57,
+ 0
+ ],
+ [
+ -57,
+ 43
+ ],
+ [
+ 57,
+ 43
+ ],
+ [
+ 57,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 57,
+ 0
+ ],
+ "end": [
+ -57,
+ 0
+ ],
+ "through": [
+ 0,
+ -57
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 4,
+ "operation": "new",
+ "body_name": "Tray base tool"
+ }
+ },
+ {
+ "command": "solid.combine",
+ "params": {
+ "target": "Drip tray",
+ "tools": [
+ "Tray base tool"
+ ],
+ "operation": "join"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Perforated stainless grate profile",
+ "plane": {
+ "origin": [
+ 0,
+ -143,
+ 65
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -53,
+ 0
+ ],
+ [
+ -53,
+ 39
+ ],
+ [
+ 53,
+ 39
+ ],
+ [
+ 53,
+ 0
+ ]
+ ],
+ "ids": [
+ "outerleft",
+ "outerback",
+ "outerright"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 53,
+ 0
+ ],
+ "end": [
+ -53,
+ 0
+ ],
+ "through": [
+ 0,
+ -53
+ ],
+ "id": "outerfront"
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ -6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 6
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 18
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 0,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 12,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 24,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 36,
+ 30
+ ],
+ "radius": 2.2
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 2,
+ "operation": "new",
+ "body_name": "Perforated stainless grate",
+ "profiles": [
+ {
+ "point": [
+ 0,
+ 38
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Rounded tray cap profile",
+ "plane": {
+ "origin": [
+ 112,
+ -143,
+ 40
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -19.0,
+ -27.0
+ ],
+ "p1": [
+ 19.0,
+ 27.0
+ ],
+ "radius": 15
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Rounded tray cap"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Louvred service panel profile",
+ "plane": {
+ "origin": [
+ -122,
+ 143,
+ 173
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -47,
+ -91
+ ],
+ "p1": [
+ 47,
+ 91
+ ],
+ "radius": 8
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -62
+ ],
+ "p1": [
+ 31,
+ -58
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -47
+ ],
+ "p1": [
+ 31,
+ -43
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -32
+ ],
+ "p1": [
+ 31,
+ -28
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -17
+ ],
+ "p1": [
+ 31,
+ -13
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ -2
+ ],
+ "p1": [
+ 31,
+ 2
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 13
+ ],
+ "p1": [
+ 31,
+ 17
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 28
+ ],
+ "p1": [
+ 31,
+ 32
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 43
+ ],
+ "p1": [
+ 31,
+ 47
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -31,
+ 58
+ ],
+ "p1": [
+ 31,
+ 62
+ ],
+ "radius": 1.5
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ -38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ -81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 38,
+ 81
+ ],
+ "radius": 2.4
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 3,
+ "operation": "new",
+ "body_name": "Louvred service panel",
+ "profiles": [
+ {
+ "point": [
+ 43,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 1",
+ "base": [
+ -99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 1"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 2",
+ "base": [
+ -99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 2"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 3",
+ "base": [
+ -99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 3"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 4",
+ "base": [
+ -99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ -99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -102.3,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 4"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 5",
+ "base": [
+ 99,
+ -68,
+ 87
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 87
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 86.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 5"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 6",
+ "base": [
+ 99,
+ -68,
+ 142
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 142
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 141.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 6"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 7",
+ "base": [
+ 99,
+ -68,
+ 197
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 197
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 196.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 7"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Zinc screw 8",
+ "base": [
+ 99,
+ -68,
+ 252
+ ],
+ "radius": 2.1,
+ "height": 14,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 99,
+ -71,
+ 252
+ ],
+ "radius": 4.3,
+ "height": 4,
+ "axis": "Y",
+ "operation": "join",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Screw pan head"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ 95.7,
+ -72,
+ 251.3
+ ],
+ "length": 6.6,
+ "width": 2.4,
+ "height": 1.4,
+ "operation": "cut",
+ "targets": [
+ "Zinc screw 8"
+ ],
+ "name": "Driver slot"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "S cable centerline profile",
+ "plane": {
+ "origin": [
+ 70,
+ -75,
+ 9
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 52,
+ 94
+ ],
+ "through": [
+ 92,
+ 54
+ ],
+ "end": [
+ 132,
+ 94
+ ],
+ "id": "cable_a"
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 132,
+ 94
+ ],
+ "through": [
+ 172,
+ 134
+ ],
+ "end": [
+ 212,
+ 94
+ ],
+ "id": "cable_b"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 212,
+ 94
+ ],
+ [
+ 212,
+ 66
+ ]
+ ],
+ "ids": [
+ "cable_end"
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.pipe",
+ "params": {
+ "path_sketch": "S cable centerline profile",
+ "path": [
+ "cable_a",
+ "cable_b",
+ "cable_end"
+ ],
+ "diameter": 5,
+ "operation": "new",
+ "body_name": "Black S power cable"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Two pin plug profile",
+ "plane": {
+ "origin": [
+ 282,
+ -30,
+ 3
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -12.0,
+ -17.5
+ ],
+ "p1": [
+ 12.0,
+ 17.5
+ ],
+ "radius": 7
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 16,
+ "operation": "new",
+ "body_name": "Two pin plug"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 206",
+ "base": [
+ 276,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plug pin 218",
+ "base": [
+ 288,
+ -64,
+ 11
+ ],
+ "radius": 2,
+ "height": 18,
+ "axis": "Y",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Housing plinth",
+ "Housing shell",
+ "Housing upper shoulder",
+ "Open brewing head",
+ "Brewing head roof",
+ "Drip tray",
+ "Rounded tray cap"
+ ],
+ "color": "#101318",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.3,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Separate tank lid",
+ "Tank lid grip",
+ "Louvred service panel"
+ ],
+ "color": "#171a1f",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.55,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Brewing collar",
+ "Bent chrome lever",
+ "Left lever ball",
+ "Right lever ball",
+ "Plug pin 206",
+ "Plug pin 218"
+ ],
+ "color": "#d5d9dd",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.12,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Internal chassis",
+ "Shower screen",
+ "Perforated stainless grate"
+ ],
+ "color": "#aeb4bb",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.25,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Zinc screw 1",
+ "Zinc screw 2",
+ "Zinc screw 3",
+ "Zinc screw 4",
+ "Zinc screw 5",
+ "Zinc screw 6",
+ "Zinc screw 7",
+ "Zinc screw 8"
+ ],
+ "color": "#b0b5bc",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.32,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Black S power cable",
+ "Two pin plug"
+ ],
+ "color": "#141414",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.8,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Studio floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "color": "#c2c6ca",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "color": "#e4eff1",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.05,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Open brewing head"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Open brewing head"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Brewing collar"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Brewing collar"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Shower screen"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 28
+ ],
+ "copy": false,
+ "name": "Framing: Shower screen"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Brewing head roof"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Brewing head roof"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Bent chrome lever"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Bent chrome lever"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Left lever ball"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Left lever ball"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Right lever ball"
+ ],
+ "translate": [
+ 0,
+ 0,
+ 40
+ ],
+ "copy": false,
+ "name": "Framing: Right lever ball"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Smoky D tank"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Smoky D tank"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Separate tank lid"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 22
+ ],
+ "copy": false,
+ "name": "Framing: Separate tank lid"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Tank lid grip"
+ ],
+ "translate": [
+ 100,
+ 8,
+ 22
+ ],
+ "copy": false,
+ "name": "Framing: Tank lid grip"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Clear ribbed bin"
+ ],
+ "translate": [
+ -70,
+ -15,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Clear ribbed bin"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Louvred service panel"
+ ],
+ "translate": [
+ -110,
+ 15,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Louvred service panel"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Drip tray"
+ ],
+ "translate": [
+ 0,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Drip tray"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Perforated stainless grate"
+ ],
+ "translate": [
+ 0,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Perforated stainless grate"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Rounded tray cap"
+ ],
+ "translate": [
+ 38,
+ -34,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Rounded tray cap"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Black S power cable"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Black S power cable"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Two pin plug"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Two pin plug"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plug pin 206"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Plug pin 206"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plug pin 218"
+ ],
+ "translate": [
+ 50,
+ 8,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Plug pin 218"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 1"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 1"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 2"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 2"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 3"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 3"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 4"
+ ],
+ "translate": [
+ -28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 4"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 5"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 5"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 6"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 6"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 7"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 7"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Zinc screw 8"
+ ],
+ "translate": [
+ 28,
+ 0,
+ 0
+ ],
+ "copy": false,
+ "name": "Framing: Zinc screw 8"
+ }
+ }
+ ]
+}
diff --git a/examples/studio/coffee-framing.md b/examples/studio/coffee-framing.md
new file mode 100644
index 0000000000..b2bae59ee6
--- /dev/null
+++ b/examples/studio/coffee-framing.md
@@ -0,0 +1,29 @@
+# Closer, lower coffee framing variant
+
+This is a separate original composition for review. The baseline scene and render
+request remain unchanged. Use `coffee-framing-sweep.json` with
+`coffee-framing-render.json`; `coffee-framing.json` is the flat-floor counterpart.
+Run `python examples/studio/author_coffee_framing.py` to regenerate all three.
+
+The camera moves from 1200 mm / 30 degrees elevation to 950 mm / 18 degrees,
+with 30 degrees front-left yaw, a 34-degree vertical field of view and target
+[-25, -10, 170] mm. The recipe appends 27 named rigid translations with `copy:false`.
+It preserves the original 32 bodies, their names and their order: there are no new
+parts or replacement geometry. Replay and `render.scene` must verify this before
+using the existing named body-index overrides.
+
+The tank moves 100 mm farther right; its lid is also lifted 22 mm. The bin moves
+70 mm left and the service panel 110 mm left. The head/collar/screen rise 28 mm,
+while the roof and lever rise 40 mm. The tray moves 34 mm forward; the detached
+cap, screws, cable and plug spread modestly with it. Existing U lever and real
+perforated grate remain intact. All physical glass, coat, sample and corrected
+light settings are copied from the baseline request without adjustment.
+
+Projecting all corners of the original uploaded product-body bounds through the
+new camera gives conservative normalized bounds X [-0.596, 0.568], Y [-0.849,
+0.916], excluding the cyclorama. This occupies approximately 58% of frame width
+and 88% of height, versus 36% and 63% for the baseline. The nearest product margin
+is about 4% of image height. These are source-level framing checks, not a rendered
+quality claim: actual mesh replay, body-order verification, physical-glass render
+and visual review remain required. The deliberately broad cyclorama continues
+outside the frame.
diff --git a/examples/studio/materials.json b/examples/studio/materials.json
new file mode 100644
index 0000000000..4e2806831a
--- /dev/null
+++ b/examples/studio/materials.json
@@ -0,0 +1,43 @@
+{
+ "stage1": {
+ "Studio floor": "floor",
+ "Coated curved shell": "coated_black",
+ "Floating coated lid": "coated_black",
+ "Chrome sphere": "chrome",
+ "Chrome floating puck": "chrome"
+ },
+ "coffee-exploded": {
+ "Studio floor": "floor",
+ "Housing plinth": "coated_black",
+ "Housing shell": "coated_black",
+ "Housing upper shoulder": "coated_black",
+ "Internal chassis": "stainless",
+ "Open brewing head": "coated_black",
+ "Brewing head roof": "coated_black",
+ "Brewing collar": "chrome",
+ "Shower screen": "stainless",
+ "Bent chrome lever": "chrome",
+ "Left lever ball": "chrome",
+ "Right lever ball": "chrome",
+ "Smoky D tank": "smoke",
+ "Separate tank lid": "matte_black",
+ "Tank lid grip": "matte_black",
+ "Clear ribbed bin": "clear",
+ "Drip tray": "coated_black",
+ "Perforated stainless grate": "stainless",
+ "Rounded tray cap": "coated_black",
+ "Louvred service panel": "matte_black",
+ "Zinc screw 1": "zinc",
+ "Zinc screw 2": "zinc",
+ "Zinc screw 3": "zinc",
+ "Zinc screw 4": "zinc",
+ "Zinc screw 5": "zinc",
+ "Zinc screw 6": "zinc",
+ "Zinc screw 7": "zinc",
+ "Zinc screw 8": "zinc",
+ "Black S power cable": "rubber",
+ "Two pin plug": "rubber",
+ "Plug pin 206": "chrome",
+ "Plug pin 218": "chrome"
+ }
+}
diff --git a/examples/studio/stage1-render.json b/examples/studio/stage1-render.json
new file mode 100644
index 0000000000..ab94aae214
--- /dev/null
+++ b/examples/studio/stage1-render.json
@@ -0,0 +1,103 @@
+{
+ "progressive": true,
+ "samples": 256,
+ "max_depth": 12,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ 0,
+ 0,
+ 70
+ ],
+ "yaw": 0.5585053606381855,
+ "pitch": 0.5235987755982988,
+ "roll": 0,
+ "distance": 430,
+ "fov": 0.5934119456780721
+ },
+ "background": [
+ 240,
+ 240,
+ 240
+ ]
+ },
+ "lighting": {
+ "environment": [
+ 0.5,
+ 0.5,
+ 0.5
+ ],
+ "area_lights": [
+ {
+ "center": [
+ -140,
+ -130,
+ 280
+ ],
+ "u": [
+ 110,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ -70,
+ 0
+ ],
+ "radiance": [
+ 8,
+ 8,
+ 8
+ ]
+ },
+ {
+ "center": [
+ 280,
+ -160,
+ 180
+ ],
+ "u": [
+ 0,
+ -60,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ 90
+ ],
+ "radiance": [
+ 6,
+ 6,
+ 6
+ ]
+ },
+ {
+ "center": [
+ 0,
+ 170,
+ 250
+ ],
+ "u": [
+ 70,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ 65
+ ],
+ "radiance": [
+ 10,
+ 10,
+ 10
+ ]
+ }
+ ]
+ }
+}
diff --git a/examples/studio/stage1-sweep.json b/examples/studio/stage1-sweep.json
new file mode 100644
index 0000000000..278275a9f0
--- /dev/null
+++ b/examples/studio/stage1-sweep.json
@@ -0,0 +1,333 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original studio light and coating study"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Studio floor profile",
+ "plane": {
+ "origin": [
+ -1500.0,
+ 0,
+ 0
+ ],
+ "x_dir": [
+ 0,
+ 1,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ -1500,
+ 0
+ ],
+ [
+ 250,
+ 0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 250,
+ 0
+ ],
+ "through": [
+ 391.4213562373095,
+ 58.57864376269049
+ ],
+ "end": [
+ 450,
+ 200
+ ],
+ "id": "inner_sweep"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 450,
+ 200
+ ],
+ [
+ 450,
+ 1500
+ ],
+ [
+ 454,
+ 1500
+ ],
+ [
+ 454,
+ 200
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.arc.three_point",
+ "params": {
+ "start": [
+ 454,
+ 200
+ ],
+ "through": [
+ 394.2497833620557,
+ 55.750216637944305
+ ],
+ "end": [
+ 250,
+ -4
+ ],
+ "id": "outer_sweep"
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 250,
+ -4
+ ],
+ [
+ -1500,
+ -4
+ ],
+ [
+ -1500,
+ 0
+ ]
+ ],
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 3000,
+ "operation": "new",
+ "body_name": "Studio floor"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Coated curved shell profile",
+ "plane": {
+ "origin": [
+ -42,
+ 8,
+ 35
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -42.5,
+ -32.5
+ ],
+ "p1": [
+ 42.5,
+ 32.5
+ ],
+ "radius": 20
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -38.5,
+ -28.5
+ ],
+ "p1": [
+ 38.5,
+ 28.5
+ ],
+ "radius": 16
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 65,
+ "operation": "new",
+ "body_name": "Coated curved shell",
+ "profiles": [
+ {
+ "point": [
+ -40.5,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Floating coated lid profile",
+ "plane": {
+ "origin": [
+ -42,
+ 8,
+ 121
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -42.5,
+ -32.5
+ ],
+ "p1": [
+ 42.5,
+ 32.5
+ ],
+ "radius": 20
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Floating coated lid"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Chrome sphere",
+ "center": [
+ 60,
+ -3,
+ 60
+ ],
+ "radius": 29,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Chrome floating puck",
+ "base": [
+ 63,
+ 5,
+ 112
+ ],
+ "radius": 24,
+ "height": 7,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Coated curved shell",
+ "Floating coated lid"
+ ],
+ "color": "#101318",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.3,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Chrome sphere",
+ "Chrome floating puck"
+ ],
+ "color": "#d5d9dd",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.12,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Studio floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ }
+ ]
+}
diff --git a/examples/studio/stage1.json b/examples/studio/stage1.json
new file mode 100644
index 0000000000..fac96607c1
--- /dev/null
+++ b/examples/studio/stage1.json
@@ -0,0 +1,217 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original studio light and coating study"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Studio floor",
+ "corner": [
+ -1500,
+ -1500,
+ -4
+ ],
+ "length": 3000,
+ "width": 3000,
+ "height": 4,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Coated curved shell profile",
+ "plane": {
+ "origin": [
+ -42,
+ 8,
+ 35
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -42.5,
+ -32.5
+ ],
+ "p1": [
+ 42.5,
+ 32.5
+ ],
+ "radius": 20
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -38.5,
+ -28.5
+ ],
+ "p1": [
+ 38.5,
+ 28.5
+ ],
+ "radius": 16
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 65,
+ "operation": "new",
+ "body_name": "Coated curved shell",
+ "profiles": [
+ {
+ "point": [
+ -40.5,
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Floating coated lid profile",
+ "plane": {
+ "origin": [
+ -42,
+ 8,
+ 121
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -42.5,
+ -32.5
+ ],
+ "p1": [
+ 42.5,
+ 32.5
+ ],
+ "radius": 20
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 5,
+ "operation": "new",
+ "body_name": "Floating coated lid"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Chrome sphere",
+ "center": [
+ 60,
+ -3,
+ 60
+ ],
+ "radius": 29,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Chrome floating puck",
+ "base": [
+ 63,
+ 5,
+ 112
+ ],
+ "radius": 24,
+ "height": 7,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Coated curved shell",
+ "Floating coated lid"
+ ],
+ "color": "#101318",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.3,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Chrome sphere",
+ "Chrome floating puck"
+ ],
+ "color": "#d5d9dd",
+ "pbr": {
+ "metallic": 1,
+ "roughness": 0.12,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Studio floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ }
+ ]
+}
diff --git a/examples/studio/textures/.gitignore b/examples/studio/textures/.gitignore
new file mode 100644
index 0000000000..7d3b65d148
--- /dev/null
+++ b/examples/studio/textures/.gitignore
@@ -0,0 +1,6 @@
+# Procedural maps and HDR fixture are generated locally, never committed.
+linen-base-srgb.png
+linen-normal-opengl.png
+walnut-base-srgb.png
+walnut-normal-opengl.png
+original-gradient.hdr
diff --git a/examples/studio/textures/ATTRIBUTION.md b/examples/studio/textures/ATTRIBUTION.md
new file mode 100644
index 0000000000..1e4b236c04
--- /dev/null
+++ b/examples/studio/textures/ATTRIBUTION.md
@@ -0,0 +1,53 @@
+# Original procedural runtime texture generators
+
+All patterns are original analytic functions written for this task. No photographs,
+commercial assets, downloaded imagery or generated AI images were used. The editable
+authority is `author_textures.py`; it uses only Python standard-library math/zlib.
+Regenerate with `python author_textures.py`. The script locates its scene requests in the parent folder and writes portable
+repository-relative resource paths. Run rendering commands from the repository root.
+
+The PNG/RGBE output bytes are generated locally into ignored paths and are not
+committed to source. `../author_showcase.py` generates all five image files before
+rendering; it downloads nothing. The manifests retain reproducible output hashes,
+not image payloads. Rendered evidence may be kept on the results branch.
+
+All four generated PNGs are RGBA8 256x256 without ICC/orientation metadata. Base images are
+sRGB-encoded near-white modulation, preserving the scene's existing brown/linen/
+ochre/taupe hues; mean linear multipliers are walnut0.8376 and linen0.8600. They do
+not multiply a brown texture into an already brown body. Normal maps are linear
+OpenGL RGB from derivatives of the same original periodic height functions.
+Walnut U/V repeat is900/90mm, along the table's X grain. Linen repeats24mm with eight
+threads per tile, giving3mm thread spacing. Planar mapping stretches side/end faces;
+this is not triplanar upholstery and is not claimed as such.
+
+The two actual render requests retain the scene author's camera, lens, material and
+light values, adding thirteen opaque body maps. `tumblers-textures-render.json` pairs
+with examples/studio/tumblers.json; `tumblers-sun-textures-render.json` pairs with
+examples/studio/tumblers-sun.json. Both use the existing tumblers-materials.json base
+materials. They intentionally keep glass maps absent. Repository-relative resource paths point to this folder; source bytes are captured
+once at request admission. Final requests use 2048 samples and explicitly enable
+straight shadow transmission on both closed tumblers; separate blocked-shadow
+controls are generated by `../author_showcase.py`.
+
+Thirteen pairs occupy27262976 normalized bytes (26MiB), below32MiB aggregate; encoded
+files total less than140KiB counting each binding copy. Runtime body metadata and
+frame coordinates came from the scene author, not commercial reference geometry.
+No final render or GPU verification is claimed by these asset files alone.
+
+## Generator and generated-output provenance
+
+| File | Source / author | License | Use |
+| --- | --- | --- | --- |
+| `author_textures.py` | Original SolidCraft contributors, this task | MIT OR Apache-2.0 | Runtime texture authoring/evidence |
+| `linen-base-srgb.png` | Original SolidCraft contributors, this task | MIT OR Apache-2.0 | Runtime texture authoring/evidence |
+| `linen-normal-opengl.png` | Original SolidCraft contributors, this task | MIT OR Apache-2.0 | Runtime texture authoring/evidence |
+| `manifest.json` | Original SolidCraft contributors, this task | MIT OR Apache-2.0 | Runtime texture authoring/evidence |
+| `tumblers-sun-textures-render.json` | Original SolidCraft contributors, this task | MIT OR Apache-2.0 | Runtime texture authoring/evidence |
+| `tumblers-textures-render.json` | Original SolidCraft contributors, this task | MIT OR Apache-2.0 | Runtime texture authoring/evidence |
+| `walnut-base-srgb.png` | Original SolidCraft contributors, this task | MIT OR Apache-2.0 | Runtime texture authoring/evidence |
+| `walnut-normal-opengl.png` | Original SolidCraft contributors, this task | MIT OR Apache-2.0 | Runtime texture authoring/evidence |
+
+`original-gradient.hdr` is generated by `../author_showcase.py` from its original
+analytic sky-gradient formula, under MIT OR Apache-2.0. It contains no sampled
+photograph or scan. `environment-manifest.json` records the formula parameters
+and reproducible output hash; the HDR bytes themselves remain ignored.
diff --git a/examples/studio/textures/author_textures.py b/examples/studio/textures/author_textures.py
new file mode 100644
index 0000000000..b01fe5f600
--- /dev/null
+++ b/examples/studio/textures/author_textures.py
@@ -0,0 +1,63 @@
+"""Original deterministic studio map authoring; no imported imagery or dependencies.
+Outputs are generated on demand into ignored paths; do not commit image bytes.
+Copyright 2026 SolidCraft contributors. SPDX-License-Identifier: MIT OR Apache-2.0
+"""
+from pathlib import Path
+import hashlib,json,math,struct,zlib
+OUT=Path(__file__).resolve().parent
+SCENES=OUT.parent
+RESOURCE=Path("examples/studio/textures")
+N=256;TAU=math.tau
+
+def png(path,pixels):
+ def chunk(kind,data):return struct.pack(">I",len(data))+kind+data+struct.pack(">I",zlib.crc32(kind+data)&0xffffffff)
+ scan=b"".join(b"\0"+pixels[y*N*4:(y+1)*N*4] for y in range(N))
+ path.write_bytes(b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR",struct.pack(">IIBBBBB",N,N,8,6,0,0,0))+chunk(b"IDAT",zlib.compress(scan,9))+chunk(b"IEND",b""))
+def srgb(x):return round(255*(12.92*x if x<=.0031308 else 1.055*x**(1/2.4)-.055))
+def wood(u,v):
+ phase=TAU*(12*v+.34*math.sin(TAU*u)+.11*math.sin(TAU*(2*u+v)))
+ pore=.5+.5*math.cos(phase)
+ fine=.5+.5*math.sin(TAU*(37*v+2*u))
+ height=.12*math.cos(phase)+.025*math.sin(TAU*(37*v+2*u))
+ value=.72+.22*pore+.035*fine
+ return (value,min(1.,value*.99),value*.975),height
+
+def fabric(u,v):
+ warp=math.cos(TAU*8*u);weft=math.cos(TAU*8*v)
+ over=math.cos(TAU*4*u)*math.cos(TAU*4*v)
+ height=.065*(warp+weft)+.035*over
+ value=.86+.045*(warp+weft)+.025*over
+ return (value,value,value),height
+
+def author(name,fn,period):
+ color=bytearray();normal=bytearray();linear=[];step=1/N
+ for y in range(N):
+ for x in range(N):
+ u=(x+.5)/N;v=(y+.5)/N;rgb,_=fn(u,v);linear.extend(rgb)
+ color.extend([*(srgb(c) for c in rgb),255])
+ dx=(fn(u+step,v)[1]-fn(u-step,v)[1])/(2*step*period[0])
+ dy=(fn(u,v+step)[1]-fn(u,v-step)[1])/(2*step*period[1])
+ q=(-dx,-dy,1.);length=math.sqrt(sum(c*c for c in q))
+ normal.extend([*(round(255*(.5+.5*c/length)) for c in q),255])
+ png(OUT/(name+"-base-srgb.png"),bytes(color));png(OUT/(name+"-normal-opengl.png"),bytes(normal))
+ return {"mean_linear_multiplier":sum(linear)/len(linear),"min_linear_multiplier":min(linear),"max_linear_multiplier":max(linear),"period_mm":period}
+
+stats={"walnut":author("walnut",wood,(900,90)),"linen":author("linen",fabric,(24,24))}
+bindings=[]
+def bind(index,name,origin,u,v,material,strength):
+ bindings.append(dict(body_index=index,body_name=name,frame=dict(origin=origin,u=u,v=v),base_color_srgb=(RESOURCE/(material+"-base-srgb.png")).as_posix(),normal_opengl=(RESOURCE/(material+"-normal-opengl.png")).as_posix(),normal_strength=strength))
+bind(3,"Walnut tabletop",[0,0,480],[900,0,0],[0,90,0],"walnut",.65)
+front=[(10,"Sofa plinth",[0,740,165]),(11,"Sofa back",[0,1270,490]),(12,"Left sofa arm",[-760,725,407.5]),(13,"Right sofa arm",[760,725,407.5])]
+front += [(15+2*k,"Back cushion "+str(k+1),[-460+460*k,1140,545]) for k in range(3)]
+for index,name,origin in front:bind(index,name,origin,[24,0,0],[0,0,-24],"linen",.55)
+for k in range(3):bind(14+2*k,"Seat cushion "+str(k+1),[-460+460*k,1020,360],[24,0,0],[0,24,0],"linen",.55)
+bind(20,"Ochre throw cushion",[-540.0861,1028.1813,560],[22.82536,-7.41641,0],[0,0,-24],"linen",.55)
+bind(21,"Taupe throw cushion",[547.9164,1052.517,545],[23.07028,6.61530,0],[0,0,-24],"linen",.55)
+for source,target in [("tumblers-render.json","tumblers-textures-render.json"),("tumblers-sun-render.json","tumblers-sun-textures-render.json")]:
+ params=json.loads((SCENES/source).read_text(encoding="utf8",newline="\n"));params.setdefault("raytrace",{})["textures"]=bindings
+ params["samples"]=2048
+ for glass in params["raytrace"]["dielectrics"]: glass["shadow_transmission"]=True
+ (SCENES/target).write_text(json.dumps(params,indent=2)+"\n",encoding="utf8",newline="\n")
+manifest={"author":"SolidCraft contributors; original analytic patterns authored for this task", "license":"MIT OR Apache-2.0", "no_external_images":True,"dimensions":[N,N],"stats":stats,"bindings":len(bindings),"linear_pixel_bytes_across_bindings":len(bindings)*2*N*N*16,"files":{p.name:{"sha256":hashlib.sha256(p.read_bytes()).hexdigest(),"bytes":p.stat().st_size} for p in OUT.glob("*.png")}}
+(OUT/"manifest.json").write_text(json.dumps(manifest,indent=2)+"\n",encoding="utf8",newline="\n")
+print(json.dumps(manifest,indent=2))
diff --git a/examples/studio/textures/environment-manifest.json b/examples/studio/textures/environment-manifest.json
new file mode 100644
index 0000000000..e9f8c1ea3c
--- /dev/null
+++ b/examples/studio/textures/environment-manifest.json
@@ -0,0 +1,29 @@
+{
+ "author": "SolidCraft contributors; original mathematical sky gradient",
+ "license": "MIT OR Apache-2.0",
+ "no_external_images": true,
+ "width": 512,
+ "height": 256,
+ "color_space": "linear sRGB / D65",
+ "sun_baked_in": false,
+ "bytes": 11428,
+ "sha256": "a078163c28d0e56b0e91784e8193ac00a792cac15c382f5d676b4d82b27ed72e",
+ "gradient": {
+ "zenith": [
+ 0.16,
+ 0.32,
+ 0.7
+ ],
+ "horizon": [
+ 0.8,
+ 0.9,
+ 1.0
+ ],
+ "ground": [
+ 0.12,
+ 0.1,
+ 0.08
+ ]
+ },
+ "encoding": "Radiance RGBE -Y +X; quantized texel-centre gradient"
+}
diff --git a/examples/studio/textures/manifest.json b/examples/studio/textures/manifest.json
new file mode 100644
index 0000000000..9883b399cd
--- /dev/null
+++ b/examples/studio/textures/manifest.json
@@ -0,0 +1,49 @@
+{
+ "author": "SolidCraft contributors; original analytic patterns authored for this task",
+ "license": "MIT OR Apache-2.0",
+ "no_external_images": true,
+ "dimensions": [
+ 256,
+ 256
+ ],
+ "stats": {
+ "walnut": {
+ "mean_linear_multiplier": 0.8376124999999859,
+ "min_linear_multiplier": 0.7020116892647678,
+ "max_linear_multiplier": 0.9749948024038769,
+ "period_mm": [
+ 900,
+ 90
+ ]
+ },
+ "linen": {
+ "mean_linear_multiplier": 0.8600000000000197,
+ "min_linear_multiplier": 0.7703731836829046,
+ "max_linear_multiplier": 0.9745064344839002,
+ "period_mm": [
+ 24,
+ 24
+ ]
+ }
+ },
+ "bindings": 13,
+ "linear_pixel_bytes_across_bindings": 27262976,
+ "files": {
+ "linen-base-srgb.png": {
+ "sha256": "32674d3bbff1878f9c039b394a2dd99ed03feb176b4be9fabf851da2d67069ff",
+ "bytes": 2365
+ },
+ "linen-normal-opengl.png": {
+ "sha256": "4e23488f4972337583ccabdd82fc91ca012c368bccda3ba49681a295b73d8c43",
+ "bytes": 5229
+ },
+ "walnut-base-srgb.png": {
+ "sha256": "1abad123658349dc923a632b0df911c0d647c224af5bfa71082b9d7a25c474df",
+ "bytes": 24912
+ },
+ "walnut-normal-opengl.png": {
+ "sha256": "dc84a597b10296ce4bbd2c3ceace4eae8b47272550eca00ed886076bf2893884",
+ "bytes": 20904
+ }
+ }
+}
diff --git a/examples/studio/tumblers-hdr-textures-blocked-render.json b/examples/studio/tumblers-hdr-textures-blocked-render.json
new file mode 100644
index 0000000000..45597bf563
--- /dev/null
+++ b/examples/studio/tumblers-hdr-textures-blocked-render.json
@@ -0,0 +1,404 @@
+{
+ "progressive": true,
+ "samples": 2048,
+ "max_depth": 16,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -8,
+ -8,
+ 537
+ ],
+ "yaw": -0.17453292519943295,
+ "pitch": 0.2617993877991494,
+ "roll": 0,
+ "distance": 670,
+ "fov": 0.6981317007977318
+ },
+ "background": [
+ 218,
+ 222,
+ 226
+ ]
+ },
+ "lens": {
+ "aperture_radius_mm": 5.5,
+ "focus_distance_mm": 670
+ },
+ "lighting": {
+ "environment": [
+ 0,
+ 0,
+ 0
+ ],
+ "area_lights": [],
+ "sun": {
+ "direction": [
+ -0.4,
+ 1,
+ 0.4
+ ],
+ "angular_radius_rad": 0.00465,
+ "radiance": [
+ 18000,
+ 16500,
+ 14000
+ ]
+ }
+ },
+ "raytrace": {
+ "dielectrics": [
+ {
+ "body_index": 8,
+ "body_name": "Tall thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": false
+ },
+ {
+ "body_index": 9,
+ "body_name": "Short thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": false
+ }
+ ],
+ "textures": [
+ {
+ "body_index": 3,
+ "body_name": "Walnut tabletop",
+ "frame": {
+ "origin": [
+ 0,
+ 0,
+ 480
+ ],
+ "u": [
+ 900,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 90,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/walnut-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/walnut-normal-opengl.png",
+ "normal_strength": 0.65
+ },
+ {
+ "body_index": 10,
+ "body_name": "Sofa plinth",
+ "frame": {
+ "origin": [
+ 0,
+ 740,
+ 165
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 11,
+ "body_name": "Sofa back",
+ "frame": {
+ "origin": [
+ 0,
+ 1270,
+ 490
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 12,
+ "body_name": "Left sofa arm",
+ "frame": {
+ "origin": [
+ -760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 13,
+ "body_name": "Right sofa arm",
+ "frame": {
+ "origin": [
+ 760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 15,
+ "body_name": "Back cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 17,
+ "body_name": "Back cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 19,
+ "body_name": "Back cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 14,
+ "body_name": "Seat cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 16,
+ "body_name": "Seat cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 18,
+ "body_name": "Seat cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 20,
+ "body_name": "Ochre throw cushion",
+ "frame": {
+ "origin": [
+ -540.0861,
+ 1028.1813,
+ 560
+ ],
+ "u": [
+ 22.82536,
+ -7.41641,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 21,
+ "body_name": "Taupe throw cushion",
+ "frame": {
+ "origin": [
+ 547.9164,
+ 1052.517,
+ 545
+ ],
+ "u": [
+ 23.07028,
+ 6.6153,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ }
+ ]
+ },
+ "environment": {
+ "kind": "hdr",
+ "path": "examples/studio/textures/original-gradient.hdr",
+ "assume_linear_srgb": false,
+ "rotation_rad": 0,
+ "intensity": 1
+ }
+}
diff --git a/examples/studio/tumblers-hdr-textures-render.json b/examples/studio/tumblers-hdr-textures-render.json
new file mode 100644
index 0000000000..5585290719
--- /dev/null
+++ b/examples/studio/tumblers-hdr-textures-render.json
@@ -0,0 +1,404 @@
+{
+ "progressive": true,
+ "samples": 2048,
+ "max_depth": 16,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -8,
+ -8,
+ 537
+ ],
+ "yaw": -0.17453292519943295,
+ "pitch": 0.2617993877991494,
+ "roll": 0,
+ "distance": 670,
+ "fov": 0.6981317007977318
+ },
+ "background": [
+ 218,
+ 222,
+ 226
+ ]
+ },
+ "lens": {
+ "aperture_radius_mm": 5.5,
+ "focus_distance_mm": 670
+ },
+ "lighting": {
+ "environment": [
+ 0,
+ 0,
+ 0
+ ],
+ "area_lights": [],
+ "sun": {
+ "direction": [
+ -0.4,
+ 1,
+ 0.4
+ ],
+ "angular_radius_rad": 0.00465,
+ "radiance": [
+ 18000,
+ 16500,
+ 14000
+ ]
+ }
+ },
+ "raytrace": {
+ "dielectrics": [
+ {
+ "body_index": 8,
+ "body_name": "Tall thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": true
+ },
+ {
+ "body_index": 9,
+ "body_name": "Short thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": true
+ }
+ ],
+ "textures": [
+ {
+ "body_index": 3,
+ "body_name": "Walnut tabletop",
+ "frame": {
+ "origin": [
+ 0,
+ 0,
+ 480
+ ],
+ "u": [
+ 900,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 90,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/walnut-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/walnut-normal-opengl.png",
+ "normal_strength": 0.65
+ },
+ {
+ "body_index": 10,
+ "body_name": "Sofa plinth",
+ "frame": {
+ "origin": [
+ 0,
+ 740,
+ 165
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 11,
+ "body_name": "Sofa back",
+ "frame": {
+ "origin": [
+ 0,
+ 1270,
+ 490
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 12,
+ "body_name": "Left sofa arm",
+ "frame": {
+ "origin": [
+ -760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 13,
+ "body_name": "Right sofa arm",
+ "frame": {
+ "origin": [
+ 760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 15,
+ "body_name": "Back cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 17,
+ "body_name": "Back cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 19,
+ "body_name": "Back cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 14,
+ "body_name": "Seat cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 16,
+ "body_name": "Seat cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 18,
+ "body_name": "Seat cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 20,
+ "body_name": "Ochre throw cushion",
+ "frame": {
+ "origin": [
+ -540.0861,
+ 1028.1813,
+ 560
+ ],
+ "u": [
+ 22.82536,
+ -7.41641,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 21,
+ "body_name": "Taupe throw cushion",
+ "frame": {
+ "origin": [
+ 547.9164,
+ 1052.517,
+ 545
+ ],
+ "u": [
+ 23.07028,
+ 6.6153,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ }
+ ]
+ },
+ "environment": {
+ "kind": "hdr",
+ "path": "examples/studio/textures/original-gradient.hdr",
+ "assume_linear_srgb": false,
+ "rotation_rad": 0,
+ "intensity": 1
+ }
+}
diff --git a/examples/studio/tumblers-materials.json b/examples/studio/tumblers-materials.json
new file mode 100644
index 0000000000..0219f095d3
--- /dev/null
+++ b/examples/studio/tumblers-materials.json
@@ -0,0 +1,101 @@
+{
+ "bodies": {
+ "Room floor": "floor",
+ "Rear plaster wall": "wall",
+ "Left plaster wall": "wall",
+ "Walnut tabletop": "walnut",
+ "Table leg 1": "walnut",
+ "Table leg 2": "walnut",
+ "Table leg 3": "walnut",
+ "Table leg 4": "walnut",
+ "Tall thick tumbler": "glass",
+ "Short thick tumbler": "glass",
+ "Sofa plinth": "pillow_taupe",
+ "Sofa back": "linen",
+ "Left sofa arm": "linen",
+ "Right sofa arm": "linen",
+ "Seat cushion 1": "linen",
+ "Back cushion 1": "linen",
+ "Seat cushion 2": "linen",
+ "Back cushion 2": "linen",
+ "Seat cushion 3": "linen",
+ "Back cushion 3": "linen",
+ "Ochre throw cushion": "pillow_ochre",
+ "Taupe throw cushion": "pillow_taupe",
+ "Plant stand": "walnut",
+ "Ceramic plant pot": "ceramic",
+ "Pot soil": "soil",
+ "Plant stem 1": "stem",
+ "Plant leaf 1": "leaf",
+ "Plant stem 2": "stem",
+ "Plant leaf 2": "leaf",
+ "Plant stem 3": "stem",
+ "Plant leaf 3": "leaf",
+ "Plant stem 4": "stem",
+ "Plant leaf 4": "leaf",
+ "Plant stem 5": "stem",
+ "Plant leaf 5": "leaf",
+ "Plant stem 6": "stem",
+ "Plant leaf 6": "leaf",
+ "Plant stem 7": "stem",
+ "Plant leaf 7": "leaf",
+ "Plant stem 8": "stem",
+ "Plant leaf 8": "leaf",
+ "Plant stem 9": "stem",
+ "Plant leaf 9": "leaf",
+ "Plant stem 10": "stem",
+ "Plant leaf 10": "leaf",
+ "Plant stem 11": "stem",
+ "Plant leaf 11": "leaf",
+ "Plant stem 12": "stem",
+ "Plant leaf 12": "leaf",
+ "Window blind slat 1": "blind",
+ "Window blind slat 2": "blind",
+ "Window blind slat 3": "blind",
+ "Window blind slat 4": "blind",
+ "Window blind slat 5": "blind",
+ "Window blind slat 6": "blind",
+ "Window blind slat 7": "blind",
+ "Window blind slat 8": "blind",
+ "Window blind slat 9": "blind",
+ "Window blind slat 10": "blind",
+ "Window blind slat 11": "blind",
+ "Window blind slat 12": "blind",
+ "Window blind slat 13": "blind",
+ "Window blind slat 14": "blind",
+ "Window jamb -1048": "wall",
+ "Window jamb -180": "wall",
+ "Window rail 620": "wall",
+ "Window rail 1320": "wall",
+ "Blind cord -860": "linen",
+ "Blind cord -350": "linen"
+ },
+ "texture_coordinates": {
+ "Walnut tabletop": {
+ "projection": "world_xy",
+ "grain_direction": [
+ 1,
+ 0,
+ 0
+ ],
+ "period_mm": [
+ 900,
+ 90
+ ],
+ "note": "Original procedural walnut grain; do not copy photographs. Coordinate is mm, rotate grain along table long X axis."
+ },
+ "linen": {
+ "projection": "triplanar_world",
+ "period_mm": [
+ 3,
+ 3,
+ 3
+ ],
+ "note": "Fine low-contrast original woven noise, use broad albedo and subtle normal perturbation. No material runtime API assumed."
+ },
+ "glass": {
+ "projection": "none",
+ "note": "Smooth thick dielectric; geometry provides rims and bases. No normal-map waviness requested for these tumblers."
+ }
+ }
+}
diff --git a/examples/studio/tumblers-render.json b/examples/studio/tumblers-render.json
new file mode 100644
index 0000000000..3b6681a3fc
--- /dev/null
+++ b/examples/studio/tumblers-render.json
@@ -0,0 +1,135 @@
+{
+ "progressive": true,
+ "samples": 512,
+ "max_depth": 16,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -8,
+ -8,
+ 537
+ ],
+ "yaw": -0.17453292519943295,
+ "pitch": 0.2617993877991494,
+ "roll": 0,
+ "distance": 670,
+ "fov": 0.6981317007977318
+ },
+ "background": [
+ 218,
+ 222,
+ 226
+ ]
+ },
+ "lens": {
+ "aperture_radius_mm": 5.5,
+ "focus_distance_mm": 670
+ },
+ "lighting": {
+ "environment": [
+ 0.22,
+ 0.25,
+ 0.3
+ ],
+ "area_lights": [
+ {
+ "center": [
+ -650,
+ 1750,
+ 1470
+ ],
+ "u": [
+ 95,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ 95
+ ],
+ "radiance": [
+ 38,
+ 30,
+ 21
+ ]
+ },
+ {
+ "center": [
+ -550,
+ -300,
+ 1350
+ ],
+ "u": [
+ 450,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ -300,
+ 0
+ ],
+ "radiance": [
+ 3.5,
+ 3.5,
+ 3.5
+ ]
+ },
+ {
+ "center": [
+ 850,
+ 300,
+ 1100
+ ],
+ "u": [
+ 0,
+ -240,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ 300
+ ],
+ "radiance": [
+ 2.5,
+ 2.7,
+ 3.0
+ ]
+ }
+ ]
+ },
+ "raytrace": {
+ "dielectrics": [
+ {
+ "body_index": 8,
+ "body_name": "Tall thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ },
+ {
+ "body_index": 9,
+ "body_name": "Short thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ }
+ ]
+ }
+}
diff --git a/examples/studio/tumblers-sun-render.json b/examples/studio/tumblers-sun-render.json
new file mode 100644
index 0000000000..5319ee2b1c
--- /dev/null
+++ b/examples/studio/tumblers-sun-render.json
@@ -0,0 +1,103 @@
+{
+ "progressive": true,
+ "samples": 512,
+ "max_depth": 16,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -8,
+ -8,
+ 537
+ ],
+ "yaw": -0.17453292519943295,
+ "pitch": 0.2617993877991494,
+ "roll": 0,
+ "distance": 670,
+ "fov": 0.6981317007977318
+ },
+ "background": [
+ 218,
+ 222,
+ 226
+ ]
+ },
+ "lens": {
+ "aperture_radius_mm": 5.5,
+ "focus_distance_mm": 670
+ },
+ "lighting": {
+ "environment": [
+ 0,
+ 0,
+ 0
+ ],
+ "area_lights": [],
+ "sun": {
+ "direction": [
+ -0.4,
+ 1,
+ 0.4
+ ],
+ "angular_radius_rad": 0.00465,
+ "radiance": [
+ 18000,
+ 16500,
+ 14000
+ ]
+ }
+ },
+ "raytrace": {
+ "dielectrics": [
+ {
+ "body_index": 8,
+ "body_name": "Tall thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ },
+ {
+ "body_index": 9,
+ "body_name": "Short thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0
+ }
+ ]
+ },
+ "environment": {
+ "kind": "sky",
+ "gradient": {
+ "zenith": [
+ 0.16,
+ 0.32,
+ 0.7
+ ],
+ "horizon": [
+ 0.8,
+ 0.9,
+ 1
+ ],
+ "ground": [
+ 0.12,
+ 0.1,
+ 0.08
+ ]
+ },
+ "intensity": 1,
+ "rotation_rad": 0
+ }
+}
diff --git a/examples/studio/tumblers-sun-textures-blocked-render.json b/examples/studio/tumblers-sun-textures-blocked-render.json
new file mode 100644
index 0000000000..1cb1f66fde
--- /dev/null
+++ b/examples/studio/tumblers-sun-textures-blocked-render.json
@@ -0,0 +1,419 @@
+{
+ "progressive": true,
+ "samples": 2048,
+ "max_depth": 16,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -8,
+ -8,
+ 537
+ ],
+ "yaw": -0.17453292519943295,
+ "pitch": 0.2617993877991494,
+ "roll": 0,
+ "distance": 670,
+ "fov": 0.6981317007977318
+ },
+ "background": [
+ 218,
+ 222,
+ 226
+ ]
+ },
+ "lens": {
+ "aperture_radius_mm": 5.5,
+ "focus_distance_mm": 670
+ },
+ "lighting": {
+ "environment": [
+ 0,
+ 0,
+ 0
+ ],
+ "area_lights": [],
+ "sun": {
+ "direction": [
+ -0.4,
+ 1,
+ 0.4
+ ],
+ "angular_radius_rad": 0.00465,
+ "radiance": [
+ 18000,
+ 16500,
+ 14000
+ ]
+ }
+ },
+ "raytrace": {
+ "dielectrics": [
+ {
+ "body_index": 8,
+ "body_name": "Tall thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": false
+ },
+ {
+ "body_index": 9,
+ "body_name": "Short thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": false
+ }
+ ],
+ "textures": [
+ {
+ "body_index": 3,
+ "body_name": "Walnut tabletop",
+ "frame": {
+ "origin": [
+ 0,
+ 0,
+ 480
+ ],
+ "u": [
+ 900,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 90,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/walnut-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/walnut-normal-opengl.png",
+ "normal_strength": 0.65
+ },
+ {
+ "body_index": 10,
+ "body_name": "Sofa plinth",
+ "frame": {
+ "origin": [
+ 0,
+ 740,
+ 165
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 11,
+ "body_name": "Sofa back",
+ "frame": {
+ "origin": [
+ 0,
+ 1270,
+ 490
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 12,
+ "body_name": "Left sofa arm",
+ "frame": {
+ "origin": [
+ -760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 13,
+ "body_name": "Right sofa arm",
+ "frame": {
+ "origin": [
+ 760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 15,
+ "body_name": "Back cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 17,
+ "body_name": "Back cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 19,
+ "body_name": "Back cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 14,
+ "body_name": "Seat cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 16,
+ "body_name": "Seat cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 18,
+ "body_name": "Seat cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 20,
+ "body_name": "Ochre throw cushion",
+ "frame": {
+ "origin": [
+ -540.0861,
+ 1028.1813,
+ 560
+ ],
+ "u": [
+ 22.82536,
+ -7.41641,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 21,
+ "body_name": "Taupe throw cushion",
+ "frame": {
+ "origin": [
+ 547.9164,
+ 1052.517,
+ 545
+ ],
+ "u": [
+ 23.07028,
+ 6.6153,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ }
+ ]
+ },
+ "environment": {
+ "kind": "sky",
+ "gradient": {
+ "zenith": [
+ 0.16,
+ 0.32,
+ 0.7
+ ],
+ "horizon": [
+ 0.8,
+ 0.9,
+ 1
+ ],
+ "ground": [
+ 0.12,
+ 0.1,
+ 0.08
+ ]
+ },
+ "intensity": 1,
+ "rotation_rad": 0
+ }
+}
diff --git a/examples/studio/tumblers-sun-textures-render.json b/examples/studio/tumblers-sun-textures-render.json
new file mode 100644
index 0000000000..ba19f48b66
--- /dev/null
+++ b/examples/studio/tumblers-sun-textures-render.json
@@ -0,0 +1,419 @@
+{
+ "progressive": true,
+ "samples": 2048,
+ "max_depth": 16,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -8,
+ -8,
+ 537
+ ],
+ "yaw": -0.17453292519943295,
+ "pitch": 0.2617993877991494,
+ "roll": 0,
+ "distance": 670,
+ "fov": 0.6981317007977318
+ },
+ "background": [
+ 218,
+ 222,
+ 226
+ ]
+ },
+ "lens": {
+ "aperture_radius_mm": 5.5,
+ "focus_distance_mm": 670
+ },
+ "lighting": {
+ "environment": [
+ 0,
+ 0,
+ 0
+ ],
+ "area_lights": [],
+ "sun": {
+ "direction": [
+ -0.4,
+ 1,
+ 0.4
+ ],
+ "angular_radius_rad": 0.00465,
+ "radiance": [
+ 18000,
+ 16500,
+ 14000
+ ]
+ }
+ },
+ "raytrace": {
+ "dielectrics": [
+ {
+ "body_index": 8,
+ "body_name": "Tall thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": true
+ },
+ {
+ "body_index": 9,
+ "body_name": "Short thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": true
+ }
+ ],
+ "textures": [
+ {
+ "body_index": 3,
+ "body_name": "Walnut tabletop",
+ "frame": {
+ "origin": [
+ 0,
+ 0,
+ 480
+ ],
+ "u": [
+ 900,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 90,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/walnut-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/walnut-normal-opengl.png",
+ "normal_strength": 0.65
+ },
+ {
+ "body_index": 10,
+ "body_name": "Sofa plinth",
+ "frame": {
+ "origin": [
+ 0,
+ 740,
+ 165
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 11,
+ "body_name": "Sofa back",
+ "frame": {
+ "origin": [
+ 0,
+ 1270,
+ 490
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 12,
+ "body_name": "Left sofa arm",
+ "frame": {
+ "origin": [
+ -760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 13,
+ "body_name": "Right sofa arm",
+ "frame": {
+ "origin": [
+ 760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 15,
+ "body_name": "Back cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 17,
+ "body_name": "Back cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 19,
+ "body_name": "Back cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 14,
+ "body_name": "Seat cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 16,
+ "body_name": "Seat cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 18,
+ "body_name": "Seat cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 20,
+ "body_name": "Ochre throw cushion",
+ "frame": {
+ "origin": [
+ -540.0861,
+ 1028.1813,
+ 560
+ ],
+ "u": [
+ 22.82536,
+ -7.41641,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 21,
+ "body_name": "Taupe throw cushion",
+ "frame": {
+ "origin": [
+ 547.9164,
+ 1052.517,
+ 545
+ ],
+ "u": [
+ 23.07028,
+ 6.6153,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ }
+ ]
+ },
+ "environment": {
+ "kind": "sky",
+ "gradient": {
+ "zenith": [
+ 0.16,
+ 0.32,
+ 0.7
+ ],
+ "horizon": [
+ 0.8,
+ 0.9,
+ 1
+ ],
+ "ground": [
+ 0.12,
+ 0.1,
+ 0.08
+ ]
+ },
+ "intensity": 1,
+ "rotation_rad": 0
+ }
+}
diff --git a/examples/studio/tumblers-sun.json b/examples/studio/tumblers-sun.json
new file mode 100644
index 0000000000..88da77635d
--- /dev/null
+++ b/examples/studio/tumblers-sun.json
@@ -0,0 +1,2953 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original two tumblers in a warm sitting room"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Room floor",
+ "corner": [
+ -2400,
+ -1800,
+ -30
+ ],
+ "length": 4800,
+ "width": 4300,
+ "height": 30,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Rear plaster wall",
+ "corner": [
+ -2400,
+ 2000,
+ 0
+ ],
+ "length": 4800,
+ "width": 30,
+ "height": 2300,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Left plaster wall",
+ "corner": [
+ -2400,
+ -1800,
+ 0
+ ],
+ "length": 30,
+ "width": 3800,
+ "height": 2300,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Walnut tabletop profile",
+ "plane": {
+ "origin": [
+ 0,
+ 0,
+ 445
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -600.0,
+ -350.0
+ ],
+ "p1": [
+ 600.0,
+ 350.0
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 35,
+ "operation": "new",
+ "body_name": "Walnut tabletop"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Table leg 1 profile",
+ "plane": {
+ "origin": [
+ -470,
+ -230,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -27.5,
+ -27.5
+ ],
+ "p1": [
+ 27.5,
+ 27.5
+ ],
+ "radius": 12
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 445,
+ "operation": "new",
+ "body_name": "Table leg 1"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Table leg 2 profile",
+ "plane": {
+ "origin": [
+ 470,
+ -230,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -27.5,
+ -27.5
+ ],
+ "p1": [
+ 27.5,
+ 27.5
+ ],
+ "radius": 12
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 445,
+ "operation": "new",
+ "body_name": "Table leg 2"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Table leg 3 profile",
+ "plane": {
+ "origin": [
+ -470,
+ 230,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -27.5,
+ -27.5
+ ],
+ "p1": [
+ 27.5,
+ 27.5
+ ],
+ "radius": 12
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 445,
+ "operation": "new",
+ "body_name": "Table leg 3"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Table leg 4 profile",
+ "plane": {
+ "origin": [
+ 470,
+ 230,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -27.5,
+ -27.5
+ ],
+ "p1": [
+ 27.5,
+ 27.5
+ ],
+ "radius": 12
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 445,
+ "operation": "new",
+ "body_name": "Table leg 4"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tall thick tumbler profile",
+ "plane": {
+ "origin": [
+ 0,
+ 0,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 0,
+ 0
+ ],
+ [
+ 36,
+ 0
+ ],
+ [
+ 42,
+ 112
+ ],
+ [
+ 37.5,
+ 112
+ ],
+ [
+ 31.5,
+ 9
+ ],
+ [
+ 0,
+ 9
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.revolve",
+ "params": {
+ "axis": "y",
+ "angle": "360 deg",
+ "operation": "new",
+ "body_name": "Tall thick tumbler"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Tall thick tumbler"
+ ],
+ "translate": [
+ -102,
+ -88,
+ 480
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Short thick tumbler profile",
+ "plane": {
+ "origin": [
+ 0,
+ 0,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 0,
+ 0
+ ],
+ [
+ 37,
+ 0
+ ],
+ [
+ 43,
+ 94
+ ],
+ [
+ 38,
+ 94
+ ],
+ [
+ 32,
+ 10
+ ],
+ [
+ 0,
+ 10
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.revolve",
+ "params": {
+ "axis": "y",
+ "angle": "360 deg",
+ "operation": "new",
+ "body_name": "Short thick tumbler"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Short thick tumbler"
+ ],
+ "translate": [
+ 88,
+ 35,
+ 480
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Sofa plinth profile",
+ "plane": {
+ "origin": [
+ 0,
+ 1075,
+ 95
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -840.0,
+ -335.0
+ ],
+ "p1": [
+ 840.0,
+ 335.0
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 140,
+ "operation": "new",
+ "body_name": "Sofa plinth"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Sofa back profile",
+ "plane": {
+ "origin": [
+ 0,
+ 1350,
+ 235
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -840.0,
+ -80.0
+ ],
+ "p1": [
+ 840.0,
+ 80.0
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 510,
+ "operation": "new",
+ "body_name": "Sofa back"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Left sofa arm profile",
+ "plane": {
+ "origin": [
+ -760,
+ 1050,
+ 235
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -80.0,
+ -325.0
+ ],
+ "p1": [
+ 80.0,
+ 325.0
+ ],
+ "radius": 60
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 345,
+ "operation": "new",
+ "body_name": "Left sofa arm"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Right sofa arm profile",
+ "plane": {
+ "origin": [
+ 760,
+ 1050,
+ 235
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -80.0,
+ -325.0
+ ],
+ "p1": [
+ 80.0,
+ 325.0
+ ],
+ "radius": 60
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 345,
+ "operation": "new",
+ "body_name": "Right sofa arm"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Seat cushion 1",
+ "corner": [
+ -227.5,
+ -270.0,
+ -75.0
+ ],
+ "length": 455,
+ "width": 540,
+ "height": 150,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Seat cushion 1",
+ "edges": [
+ [
+ 0,
+ -270.0,
+ -75.0
+ ],
+ [
+ 0,
+ -270.0,
+ 75.0
+ ],
+ [
+ 0,
+ 270.0,
+ -75.0
+ ],
+ [
+ 0,
+ 270.0,
+ 75.0
+ ],
+ [
+ -227.5,
+ 0,
+ -75.0
+ ],
+ [
+ -227.5,
+ 0,
+ 75.0
+ ],
+ [
+ 227.5,
+ 0,
+ -75.0
+ ],
+ [
+ 227.5,
+ 0,
+ 75.0
+ ],
+ [
+ -227.5,
+ -270.0,
+ 0
+ ],
+ [
+ -227.5,
+ 270.0,
+ 0
+ ],
+ [
+ 227.5,
+ -270.0,
+ 0
+ ],
+ [
+ 227.5,
+ 270.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Seat cushion 1"
+ ],
+ "translate": [
+ -460,
+ 1020,
+ 285
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Back cushion 1",
+ "corner": [
+ -225.0,
+ -90.0,
+ -202.5
+ ],
+ "length": 450,
+ "width": 180,
+ "height": 405,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Back cushion 1",
+ "edges": [
+ [
+ 0,
+ -90.0,
+ -202.5
+ ],
+ [
+ 0,
+ -90.0,
+ 202.5
+ ],
+ [
+ 0,
+ 90.0,
+ -202.5
+ ],
+ [
+ 0,
+ 90.0,
+ 202.5
+ ],
+ [
+ -225.0,
+ 0,
+ -202.5
+ ],
+ [
+ -225.0,
+ 0,
+ 202.5
+ ],
+ [
+ 225.0,
+ 0,
+ -202.5
+ ],
+ [
+ 225.0,
+ 0,
+ 202.5
+ ],
+ [
+ -225.0,
+ -90.0,
+ 0
+ ],
+ [
+ -225.0,
+ 90.0,
+ 0
+ ],
+ [
+ 225.0,
+ -90.0,
+ 0
+ ],
+ [
+ 225.0,
+ 90.0,
+ 0
+ ]
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Back cushion 1"
+ ],
+ "translate": [
+ -460,
+ 1230,
+ 545
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Seat cushion 2",
+ "corner": [
+ -227.5,
+ -270.0,
+ -75.0
+ ],
+ "length": 455,
+ "width": 540,
+ "height": 150,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Seat cushion 2",
+ "edges": [
+ [
+ 0,
+ -270.0,
+ -75.0
+ ],
+ [
+ 0,
+ -270.0,
+ 75.0
+ ],
+ [
+ 0,
+ 270.0,
+ -75.0
+ ],
+ [
+ 0,
+ 270.0,
+ 75.0
+ ],
+ [
+ -227.5,
+ 0,
+ -75.0
+ ],
+ [
+ -227.5,
+ 0,
+ 75.0
+ ],
+ [
+ 227.5,
+ 0,
+ -75.0
+ ],
+ [
+ 227.5,
+ 0,
+ 75.0
+ ],
+ [
+ -227.5,
+ -270.0,
+ 0
+ ],
+ [
+ -227.5,
+ 270.0,
+ 0
+ ],
+ [
+ 227.5,
+ -270.0,
+ 0
+ ],
+ [
+ 227.5,
+ 270.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Seat cushion 2"
+ ],
+ "translate": [
+ 0,
+ 1020,
+ 285
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Back cushion 2",
+ "corner": [
+ -225.0,
+ -90.0,
+ -202.5
+ ],
+ "length": 450,
+ "width": 180,
+ "height": 405,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Back cushion 2",
+ "edges": [
+ [
+ 0,
+ -90.0,
+ -202.5
+ ],
+ [
+ 0,
+ -90.0,
+ 202.5
+ ],
+ [
+ 0,
+ 90.0,
+ -202.5
+ ],
+ [
+ 0,
+ 90.0,
+ 202.5
+ ],
+ [
+ -225.0,
+ 0,
+ -202.5
+ ],
+ [
+ -225.0,
+ 0,
+ 202.5
+ ],
+ [
+ 225.0,
+ 0,
+ -202.5
+ ],
+ [
+ 225.0,
+ 0,
+ 202.5
+ ],
+ [
+ -225.0,
+ -90.0,
+ 0
+ ],
+ [
+ -225.0,
+ 90.0,
+ 0
+ ],
+ [
+ 225.0,
+ -90.0,
+ 0
+ ],
+ [
+ 225.0,
+ 90.0,
+ 0
+ ]
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Back cushion 2"
+ ],
+ "translate": [
+ 0,
+ 1230,
+ 545
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Seat cushion 3",
+ "corner": [
+ -227.5,
+ -270.0,
+ -75.0
+ ],
+ "length": 455,
+ "width": 540,
+ "height": 150,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Seat cushion 3",
+ "edges": [
+ [
+ 0,
+ -270.0,
+ -75.0
+ ],
+ [
+ 0,
+ -270.0,
+ 75.0
+ ],
+ [
+ 0,
+ 270.0,
+ -75.0
+ ],
+ [
+ 0,
+ 270.0,
+ 75.0
+ ],
+ [
+ -227.5,
+ 0,
+ -75.0
+ ],
+ [
+ -227.5,
+ 0,
+ 75.0
+ ],
+ [
+ 227.5,
+ 0,
+ -75.0
+ ],
+ [
+ 227.5,
+ 0,
+ 75.0
+ ],
+ [
+ -227.5,
+ -270.0,
+ 0
+ ],
+ [
+ -227.5,
+ 270.0,
+ 0
+ ],
+ [
+ 227.5,
+ -270.0,
+ 0
+ ],
+ [
+ 227.5,
+ 270.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Seat cushion 3"
+ ],
+ "translate": [
+ 460,
+ 1020,
+ 285
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Back cushion 3",
+ "corner": [
+ -225.0,
+ -90.0,
+ -202.5
+ ],
+ "length": 450,
+ "width": 180,
+ "height": 405,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Back cushion 3",
+ "edges": [
+ [
+ 0,
+ -90.0,
+ -202.5
+ ],
+ [
+ 0,
+ -90.0,
+ 202.5
+ ],
+ [
+ 0,
+ 90.0,
+ -202.5
+ ],
+ [
+ 0,
+ 90.0,
+ 202.5
+ ],
+ [
+ -225.0,
+ 0,
+ -202.5
+ ],
+ [
+ -225.0,
+ 0,
+ 202.5
+ ],
+ [
+ 225.0,
+ 0,
+ -202.5
+ ],
+ [
+ 225.0,
+ 0,
+ 202.5
+ ],
+ [
+ -225.0,
+ -90.0,
+ 0
+ ],
+ [
+ -225.0,
+ 90.0,
+ 0
+ ],
+ [
+ 225.0,
+ -90.0,
+ 0
+ ],
+ [
+ 225.0,
+ 90.0,
+ 0
+ ]
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Back cushion 3"
+ ],
+ "translate": [
+ 460,
+ 1230,
+ 545
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Ochre throw cushion",
+ "corner": [
+ -157.5,
+ -65.0,
+ -165.0
+ ],
+ "length": 315,
+ "width": 130,
+ "height": 330,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Ochre throw cushion",
+ "edges": [
+ [
+ 0,
+ -65.0,
+ -165.0
+ ],
+ [
+ 0,
+ -65.0,
+ 165.0
+ ],
+ [
+ 0,
+ 65.0,
+ -165.0
+ ],
+ [
+ 0,
+ 65.0,
+ 165.0
+ ],
+ [
+ -157.5,
+ 0,
+ -165.0
+ ],
+ [
+ -157.5,
+ 0,
+ 165.0
+ ],
+ [
+ 157.5,
+ 0,
+ -165.0
+ ],
+ [
+ 157.5,
+ 0,
+ 165.0
+ ],
+ [
+ -157.5,
+ -65.0,
+ 0
+ ],
+ [
+ -157.5,
+ 65.0,
+ 0
+ ],
+ [
+ 157.5,
+ -65.0,
+ 0
+ ],
+ [
+ 157.5,
+ 65.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Ochre throw cushion"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "-18 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Ochre throw cushion"
+ ],
+ "translate": [
+ -520,
+ 1090,
+ 560
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Taupe throw cushion",
+ "corner": [
+ -145.0,
+ -65.0,
+ -155.0
+ ],
+ "length": 290,
+ "width": 130,
+ "height": 310,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Taupe throw cushion",
+ "edges": [
+ [
+ 0,
+ -65.0,
+ -155.0
+ ],
+ [
+ 0,
+ -65.0,
+ 155.0
+ ],
+ [
+ 0,
+ 65.0,
+ -155.0
+ ],
+ [
+ 0,
+ 65.0,
+ 155.0
+ ],
+ [
+ -145.0,
+ 0,
+ -155.0
+ ],
+ [
+ -145.0,
+ 0,
+ 155.0
+ ],
+ [
+ 145.0,
+ 0,
+ -155.0
+ ],
+ [
+ 145.0,
+ 0,
+ 155.0
+ ],
+ [
+ -145.0,
+ -65.0,
+ 0
+ ],
+ [
+ -145.0,
+ 65.0,
+ 0
+ ],
+ [
+ 145.0,
+ -65.0,
+ 0
+ ],
+ [
+ 145.0,
+ 65.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Taupe throw cushion"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "16 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Taupe throw cushion"
+ ],
+ "translate": [
+ 530,
+ 1115,
+ 545
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Plant stand profile",
+ "plane": {
+ "origin": [
+ 620,
+ 575,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -100.0,
+ -100.0
+ ],
+ "p1": [
+ 100.0,
+ 100.0
+ ],
+ "radius": 30
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 430,
+ "operation": "new",
+ "body_name": "Plant stand"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Ceramic plant pot",
+ "base": [
+ 620,
+ 575,
+ 430
+ ],
+ "radius": 82,
+ "height": 146,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 620,
+ 575,
+ 442
+ ],
+ "radius": 73,
+ "height": 136,
+ "operation": "cut",
+ "targets": [
+ "Ceramic plant pot"
+ ],
+ "name": "Open ceramic pot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Pot soil",
+ "base": [
+ 620,
+ 575,
+ 550
+ ],
+ "radius": 71,
+ "height": 8,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 1",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 200.6888138387389,
+ "axis": [
+ 100.0,
+ 0.0,
+ 174
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 1",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 1"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 1"
+ ],
+ "translate": [
+ 720.0,
+ 575.0,
+ 730
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 2",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 266.5933232472261,
+ "axis": [
+ -91.42238976445537,
+ 83.77318574434184,
+ 236
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 2",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 2"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 2"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "137.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 2"
+ ],
+ "translate": [
+ 528.5776102355446,
+ 658.7731857443418,
+ 792
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 3",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 332.7281172368816,
+ "axis": [
+ 12.899049926653333,
+ -147.43681531757835,
+ 298
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 3",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 3"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 3"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "275.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 3"
+ ],
+ "translate": [
+ 632.8990499266533,
+ 427.56318468242165,
+ 854
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 4",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 373.6308338453881,
+ "axis": [
+ 60.87614290087208,
+ 79.33533402912349,
+ 360
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 4",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 4"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 4"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "412.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 4"
+ ],
+ "translate": [
+ 680.8761429008721,
+ 654.3353340291235,
+ 916
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 5",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 213.66328650472454,
+ "axis": [
+ -122.11616137351382,
+ -21.532374030699316,
+ 174
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 5",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 5"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 5"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "550.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 5"
+ ],
+ "translate": [
+ 497.8838386264862,
+ 553.4676259693007,
+ 730
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 6",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 278.5677655436824,
+ "axis": [
+ 124.821933980307,
+ -79.52034203533003,
+ 236
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 6",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 6"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 6"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "687.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 6"
+ ],
+ "translate": [
+ 744.821933980307,
+ 495.47965796466997,
+ 792
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 7",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 314.33103569326397,
+ "axis": [
+ -25.881904510251957,
+ 96.59258262890683,
+ 298
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 7",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 7"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 7"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "825.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 7"
+ ],
+ "translate": [
+ 594.118095489748,
+ 671.5925826289068,
+ 854
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 8",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 380.7571404451924,
+ "axis": [
+ -57.256828041144104,
+ -109.98934331409953,
+ 360
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 8",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 8"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 8"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "962.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 8"
+ ],
+ "translate": [
+ 562.7431719588559,
+ 465.01065668590047,
+ 916
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 9",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 228.42942017174585,
+ "axis": [
+ 139.07450787631456,
+ 50.61898121219883,
+ 174
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 9",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 9"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 9"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "1100.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 9"
+ ],
+ "translate": [
+ 759.0745078763146,
+ 625.6189812121988,
+ 730
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 10",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 256.3123094976127,
+ "axis": [
+ -92.38795325112869,
+ 38.26834323650894,
+ 236
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 10",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 10"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 10"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "1237.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 10"
+ ],
+ "translate": [
+ 527.6120467488713,
+ 613.2683432365089,
+ 792
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 11",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 322.7692674341843,
+ "axis": [
+ 52.404664455846614,
+ -112.38216559254465,
+ 298
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 11",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 11"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 11"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "1375.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 11"
+ ],
+ "translate": [
+ 672.4046644558466,
+ 462.61783440745535,
+ 854
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 12",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 389.2351474366106,
+ "axis": [
+ 44.5044583266324,
+ 141.15010871073764,
+ 360
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 12",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 12"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 12"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "1512.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 12"
+ ],
+ "translate": [
+ 664.5044583266324,
+ 716.1501087107376,
+ 916
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 1",
+ "corner": [
+ -1030,
+ 1440,
+ 660
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 2",
+ "corner": [
+ -1030,
+ 1440,
+ 705
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 3",
+ "corner": [
+ -1030,
+ 1440,
+ 750
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 4",
+ "corner": [
+ -1030,
+ 1440,
+ 795
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 5",
+ "corner": [
+ -1030,
+ 1440,
+ 840
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 6",
+ "corner": [
+ -1030,
+ 1440,
+ 885
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 7",
+ "corner": [
+ -1030,
+ 1440,
+ 930
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 8",
+ "corner": [
+ -1030,
+ 1440,
+ 975
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 9",
+ "corner": [
+ -1030,
+ 1440,
+ 1020
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 10",
+ "corner": [
+ -1030,
+ 1440,
+ 1065
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 11",
+ "corner": [
+ -1030,
+ 1440,
+ 1110
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 12",
+ "corner": [
+ -1030,
+ 1440,
+ 1155
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 13",
+ "corner": [
+ -1030,
+ 1440,
+ 1200
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 14",
+ "corner": [
+ -1030,
+ 1440,
+ 1245
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window jamb -1048",
+ "corner": [
+ -1048,
+ 1434,
+ 620
+ ],
+ "length": 18,
+ "width": 70,
+ "height": 710,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window jamb -180",
+ "corner": [
+ -180,
+ 1434,
+ 620
+ ],
+ "length": 18,
+ "width": 70,
+ "height": 710,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window rail 620",
+ "corner": [
+ -1030,
+ 1434,
+ 620
+ ],
+ "length": 850,
+ "width": 70,
+ "height": 18,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window rail 1320",
+ "corner": [
+ -1030,
+ 1434,
+ 1320
+ ],
+ "length": 850,
+ "width": 70,
+ "height": 18,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Blind cord -860",
+ "base": [
+ -860,
+ 1425,
+ 635
+ ],
+ "radius": 1.5,
+ "height": 690,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Blind cord -350",
+ "base": [
+ -350,
+ 1425,
+ 635
+ ],
+ "radius": 1.5,
+ "height": 690,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Room floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Walnut tabletop",
+ "Table leg 1",
+ "Table leg 2",
+ "Table leg 3",
+ "Table leg 4",
+ "Plant stand"
+ ],
+ "color": "#4c2818",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.42,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Sofa back",
+ "Left sofa arm",
+ "Right sofa arm",
+ "Seat cushion 1",
+ "Back cushion 1",
+ "Seat cushion 2",
+ "Back cushion 2",
+ "Seat cushion 3",
+ "Back cushion 3",
+ "Blind cord -860",
+ "Blind cord -350"
+ ],
+ "color": "#ada69b",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.88,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Ochre throw cushion"
+ ],
+ "color": "#a66c32",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.9,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Sofa plinth",
+ "Taupe throw cushion"
+ ],
+ "color": "#71685e",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.9,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Plant leaf 1",
+ "Plant leaf 2",
+ "Plant leaf 3",
+ "Plant leaf 4",
+ "Plant leaf 5",
+ "Plant leaf 6",
+ "Plant leaf 7",
+ "Plant leaf 8",
+ "Plant leaf 9",
+ "Plant leaf 10",
+ "Plant leaf 11",
+ "Plant leaf 12"
+ ],
+ "color": "#315a2b",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.6,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Plant stem 1",
+ "Plant stem 2",
+ "Plant stem 3",
+ "Plant stem 4",
+ "Plant stem 5",
+ "Plant stem 6",
+ "Plant stem 7",
+ "Plant stem 8",
+ "Plant stem 9",
+ "Plant stem 10",
+ "Plant stem 11",
+ "Plant stem 12"
+ ],
+ "color": "#425c2b",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.75,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Pot soil"
+ ],
+ "color": "#23190f",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 1,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Ceramic plant pot"
+ ],
+ "color": "#b4b3a5",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.38,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Rear plaster wall",
+ "Left plaster wall",
+ "Window jamb -1048",
+ "Window jamb -180",
+ "Window rail 620",
+ "Window rail 1320"
+ ],
+ "color": "#ded9d1",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.85,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Window blind slat 1",
+ "Window blind slat 2",
+ "Window blind slat 3",
+ "Window blind slat 4",
+ "Window blind slat 5",
+ "Window blind slat 6",
+ "Window blind slat 7",
+ "Window blind slat 8",
+ "Window blind slat 9",
+ "Window blind slat 10",
+ "Window blind slat 11",
+ "Window blind slat 12",
+ "Window blind slat 13",
+ "Window blind slat 14"
+ ],
+ "color": "#bdac91",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.7,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Tall thick tumbler",
+ "Short thick tumbler"
+ ],
+ "color": "#ffffff",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.045,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "corner": [
+ -1450,
+ 1990,
+ 760
+ ],
+ "length": 1850,
+ "width": 50,
+ "height": 1080,
+ "operation": "cut",
+ "targets": [
+ "Rear plaster wall"
+ ],
+ "name": "Sunlight window opening"
+ }
+ }
+ ]
+}
diff --git a/examples/studio/tumblers-textures-blocked-render.json b/examples/studio/tumblers-textures-blocked-render.json
new file mode 100644
index 0000000000..5fe8f9b2c6
--- /dev/null
+++ b/examples/studio/tumblers-textures-blocked-render.json
@@ -0,0 +1,451 @@
+{
+ "progressive": true,
+ "samples": 2048,
+ "max_depth": 16,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -8,
+ -8,
+ 537
+ ],
+ "yaw": -0.17453292519943295,
+ "pitch": 0.2617993877991494,
+ "roll": 0,
+ "distance": 670,
+ "fov": 0.6981317007977318
+ },
+ "background": [
+ 218,
+ 222,
+ 226
+ ]
+ },
+ "lens": {
+ "aperture_radius_mm": 5.5,
+ "focus_distance_mm": 670
+ },
+ "lighting": {
+ "environment": [
+ 0.22,
+ 0.25,
+ 0.3
+ ],
+ "area_lights": [
+ {
+ "center": [
+ -650,
+ 1750,
+ 1470
+ ],
+ "u": [
+ 95,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ 95
+ ],
+ "radiance": [
+ 38,
+ 30,
+ 21
+ ]
+ },
+ {
+ "center": [
+ -550,
+ -300,
+ 1350
+ ],
+ "u": [
+ 450,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ -300,
+ 0
+ ],
+ "radiance": [
+ 3.5,
+ 3.5,
+ 3.5
+ ]
+ },
+ {
+ "center": [
+ 850,
+ 300,
+ 1100
+ ],
+ "u": [
+ 0,
+ -240,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ 300
+ ],
+ "radiance": [
+ 2.5,
+ 2.7,
+ 3.0
+ ]
+ }
+ ]
+ },
+ "raytrace": {
+ "dielectrics": [
+ {
+ "body_index": 8,
+ "body_name": "Tall thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": false
+ },
+ {
+ "body_index": 9,
+ "body_name": "Short thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": false
+ }
+ ],
+ "textures": [
+ {
+ "body_index": 3,
+ "body_name": "Walnut tabletop",
+ "frame": {
+ "origin": [
+ 0,
+ 0,
+ 480
+ ],
+ "u": [
+ 900,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 90,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/walnut-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/walnut-normal-opengl.png",
+ "normal_strength": 0.65
+ },
+ {
+ "body_index": 10,
+ "body_name": "Sofa plinth",
+ "frame": {
+ "origin": [
+ 0,
+ 740,
+ 165
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 11,
+ "body_name": "Sofa back",
+ "frame": {
+ "origin": [
+ 0,
+ 1270,
+ 490
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 12,
+ "body_name": "Left sofa arm",
+ "frame": {
+ "origin": [
+ -760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 13,
+ "body_name": "Right sofa arm",
+ "frame": {
+ "origin": [
+ 760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 15,
+ "body_name": "Back cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 17,
+ "body_name": "Back cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 19,
+ "body_name": "Back cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 14,
+ "body_name": "Seat cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 16,
+ "body_name": "Seat cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 18,
+ "body_name": "Seat cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 20,
+ "body_name": "Ochre throw cushion",
+ "frame": {
+ "origin": [
+ -540.0861,
+ 1028.1813,
+ 560
+ ],
+ "u": [
+ 22.82536,
+ -7.41641,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 21,
+ "body_name": "Taupe throw cushion",
+ "frame": {
+ "origin": [
+ 547.9164,
+ 1052.517,
+ 545
+ ],
+ "u": [
+ 23.07028,
+ 6.6153,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ }
+ ]
+ }
+}
diff --git a/examples/studio/tumblers-textures-render.json b/examples/studio/tumblers-textures-render.json
new file mode 100644
index 0000000000..b1a266f774
--- /dev/null
+++ b/examples/studio/tumblers-textures-render.json
@@ -0,0 +1,451 @@
+{
+ "progressive": true,
+ "samples": 2048,
+ "max_depth": 16,
+ "seed": 1948,
+ "tone_map": "aces_fitted",
+ "settings": {
+ "width": 1920,
+ "height": 1080,
+ "camera": {
+ "target": [
+ -8,
+ -8,
+ 537
+ ],
+ "yaw": -0.17453292519943295,
+ "pitch": 0.2617993877991494,
+ "roll": 0,
+ "distance": 670,
+ "fov": 0.6981317007977318
+ },
+ "background": [
+ 218,
+ 222,
+ 226
+ ]
+ },
+ "lens": {
+ "aperture_radius_mm": 5.5,
+ "focus_distance_mm": 670
+ },
+ "lighting": {
+ "environment": [
+ 0.22,
+ 0.25,
+ 0.3
+ ],
+ "area_lights": [
+ {
+ "center": [
+ -650,
+ 1750,
+ 1470
+ ],
+ "u": [
+ 95,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ 95
+ ],
+ "radiance": [
+ 38,
+ 30,
+ 21
+ ]
+ },
+ {
+ "center": [
+ -550,
+ -300,
+ 1350
+ ],
+ "u": [
+ 450,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ -300,
+ 0
+ ],
+ "radiance": [
+ 3.5,
+ 3.5,
+ 3.5
+ ]
+ },
+ {
+ "center": [
+ 850,
+ 300,
+ 1100
+ ],
+ "u": [
+ 0,
+ -240,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ 300
+ ],
+ "radiance": [
+ 2.5,
+ 2.7,
+ 3.0
+ ]
+ }
+ ]
+ },
+ "raytrace": {
+ "dielectrics": [
+ {
+ "body_index": 8,
+ "body_name": "Tall thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": true
+ },
+ {
+ "body_index": 9,
+ "body_name": "Short thick tumbler",
+ "ior": 1.52,
+ "absorption_per_mm": [
+ 0.0008,
+ 0.00025,
+ 0.00012
+ ],
+ "boundary": "closed_mesh",
+ "thickness_mm": 0,
+ "shadow_transmission": true
+ }
+ ],
+ "textures": [
+ {
+ "body_index": 3,
+ "body_name": "Walnut tabletop",
+ "frame": {
+ "origin": [
+ 0,
+ 0,
+ 480
+ ],
+ "u": [
+ 900,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 90,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/walnut-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/walnut-normal-opengl.png",
+ "normal_strength": 0.65
+ },
+ {
+ "body_index": 10,
+ "body_name": "Sofa plinth",
+ "frame": {
+ "origin": [
+ 0,
+ 740,
+ 165
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 11,
+ "body_name": "Sofa back",
+ "frame": {
+ "origin": [
+ 0,
+ 1270,
+ 490
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 12,
+ "body_name": "Left sofa arm",
+ "frame": {
+ "origin": [
+ -760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 13,
+ "body_name": "Right sofa arm",
+ "frame": {
+ "origin": [
+ 760,
+ 725,
+ 407.5
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 15,
+ "body_name": "Back cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 17,
+ "body_name": "Back cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 19,
+ "body_name": "Back cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1140,
+ 545
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 14,
+ "body_name": "Seat cushion 1",
+ "frame": {
+ "origin": [
+ -460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 16,
+ "body_name": "Seat cushion 2",
+ "frame": {
+ "origin": [
+ 0,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 18,
+ "body_name": "Seat cushion 3",
+ "frame": {
+ "origin": [
+ 460,
+ 1020,
+ 360
+ ],
+ "u": [
+ 24,
+ 0,
+ 0
+ ],
+ "v": [
+ 0,
+ 24,
+ 0
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 20,
+ "body_name": "Ochre throw cushion",
+ "frame": {
+ "origin": [
+ -540.0861,
+ 1028.1813,
+ 560
+ ],
+ "u": [
+ 22.82536,
+ -7.41641,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ },
+ {
+ "body_index": 21,
+ "body_name": "Taupe throw cushion",
+ "frame": {
+ "origin": [
+ 547.9164,
+ 1052.517,
+ 545
+ ],
+ "u": [
+ 23.07028,
+ 6.6153,
+ 0
+ ],
+ "v": [
+ 0,
+ 0,
+ -24
+ ]
+ },
+ "base_color_srgb": "examples/studio/textures/linen-base-srgb.png",
+ "normal_opengl": "examples/studio/textures/linen-normal-opengl.png",
+ "normal_strength": 0.55
+ }
+ ]
+ }
+}
diff --git a/examples/studio/tumblers.json b/examples/studio/tumblers.json
new file mode 100644
index 0000000000..b7e3ea2324
--- /dev/null
+++ b/examples/studio/tumblers.json
@@ -0,0 +1,2935 @@
+{
+ "commands": [
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Original two tumblers in a warm sitting room"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Room floor",
+ "corner": [
+ -2400,
+ -1800,
+ -30
+ ],
+ "length": 4800,
+ "width": 4300,
+ "height": 30,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Rear plaster wall",
+ "corner": [
+ -2400,
+ 2000,
+ 0
+ ],
+ "length": 4800,
+ "width": 30,
+ "height": 2300,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Left plaster wall",
+ "corner": [
+ -2400,
+ -1800,
+ 0
+ ],
+ "length": 30,
+ "width": 3800,
+ "height": 2300,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Walnut tabletop profile",
+ "plane": {
+ "origin": [
+ 0,
+ 0,
+ 445
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -600.0,
+ -350.0
+ ],
+ "p1": [
+ 600.0,
+ 350.0
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 35,
+ "operation": "new",
+ "body_name": "Walnut tabletop"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Table leg 1 profile",
+ "plane": {
+ "origin": [
+ -470,
+ -230,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -27.5,
+ -27.5
+ ],
+ "p1": [
+ 27.5,
+ 27.5
+ ],
+ "radius": 12
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 445,
+ "operation": "new",
+ "body_name": "Table leg 1"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Table leg 2 profile",
+ "plane": {
+ "origin": [
+ 470,
+ -230,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -27.5,
+ -27.5
+ ],
+ "p1": [
+ 27.5,
+ 27.5
+ ],
+ "radius": 12
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 445,
+ "operation": "new",
+ "body_name": "Table leg 2"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Table leg 3 profile",
+ "plane": {
+ "origin": [
+ -470,
+ 230,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -27.5,
+ -27.5
+ ],
+ "p1": [
+ 27.5,
+ 27.5
+ ],
+ "radius": 12
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 445,
+ "operation": "new",
+ "body_name": "Table leg 3"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Table leg 4 profile",
+ "plane": {
+ "origin": [
+ 470,
+ 230,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -27.5,
+ -27.5
+ ],
+ "p1": [
+ 27.5,
+ 27.5
+ ],
+ "radius": 12
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 445,
+ "operation": "new",
+ "body_name": "Table leg 4"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Tall thick tumbler profile",
+ "plane": {
+ "origin": [
+ 0,
+ 0,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 0,
+ 0
+ ],
+ [
+ 36,
+ 0
+ ],
+ [
+ 42,
+ 112
+ ],
+ [
+ 37.5,
+ 112
+ ],
+ [
+ 31.5,
+ 9
+ ],
+ [
+ 0,
+ 9
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.revolve",
+ "params": {
+ "axis": "y",
+ "angle": "360 deg",
+ "operation": "new",
+ "body_name": "Tall thick tumbler"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Tall thick tumbler"
+ ],
+ "translate": [
+ -102,
+ -88,
+ 480
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Short thick tumbler profile",
+ "plane": {
+ "origin": [
+ 0,
+ 0,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 0,
+ 1
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.line",
+ "params": {
+ "points": [
+ [
+ 0,
+ 0
+ ],
+ [
+ 37,
+ 0
+ ],
+ [
+ 43,
+ 94
+ ],
+ [
+ 38,
+ 94
+ ],
+ [
+ 32,
+ 10
+ ],
+ [
+ 0,
+ 10
+ ]
+ ],
+ "closed": true,
+ "infer": false
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.revolve",
+ "params": {
+ "axis": "y",
+ "angle": "360 deg",
+ "operation": "new",
+ "body_name": "Short thick tumbler"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Short thick tumbler"
+ ],
+ "translate": [
+ 88,
+ 35,
+ 480
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Sofa plinth profile",
+ "plane": {
+ "origin": [
+ 0,
+ 1075,
+ 95
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -840.0,
+ -335.0
+ ],
+ "p1": [
+ 840.0,
+ 335.0
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 140,
+ "operation": "new",
+ "body_name": "Sofa plinth"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Sofa back profile",
+ "plane": {
+ "origin": [
+ 0,
+ 1350,
+ 235
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -840.0,
+ -80.0
+ ],
+ "p1": [
+ 840.0,
+ 80.0
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 510,
+ "operation": "new",
+ "body_name": "Sofa back"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Left sofa arm profile",
+ "plane": {
+ "origin": [
+ -760,
+ 1050,
+ 235
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -80.0,
+ -325.0
+ ],
+ "p1": [
+ 80.0,
+ 325.0
+ ],
+ "radius": 60
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 345,
+ "operation": "new",
+ "body_name": "Left sofa arm"
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Right sofa arm profile",
+ "plane": {
+ "origin": [
+ 760,
+ 1050,
+ 235
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -80.0,
+ -325.0
+ ],
+ "p1": [
+ 80.0,
+ 325.0
+ ],
+ "radius": 60
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 345,
+ "operation": "new",
+ "body_name": "Right sofa arm"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Seat cushion 1",
+ "corner": [
+ -227.5,
+ -270.0,
+ -75.0
+ ],
+ "length": 455,
+ "width": 540,
+ "height": 150,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Seat cushion 1",
+ "edges": [
+ [
+ 0,
+ -270.0,
+ -75.0
+ ],
+ [
+ 0,
+ -270.0,
+ 75.0
+ ],
+ [
+ 0,
+ 270.0,
+ -75.0
+ ],
+ [
+ 0,
+ 270.0,
+ 75.0
+ ],
+ [
+ -227.5,
+ 0,
+ -75.0
+ ],
+ [
+ -227.5,
+ 0,
+ 75.0
+ ],
+ [
+ 227.5,
+ 0,
+ -75.0
+ ],
+ [
+ 227.5,
+ 0,
+ 75.0
+ ],
+ [
+ -227.5,
+ -270.0,
+ 0
+ ],
+ [
+ -227.5,
+ 270.0,
+ 0
+ ],
+ [
+ 227.5,
+ -270.0,
+ 0
+ ],
+ [
+ 227.5,
+ 270.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Seat cushion 1"
+ ],
+ "translate": [
+ -460,
+ 1020,
+ 285
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Back cushion 1",
+ "corner": [
+ -225.0,
+ -90.0,
+ -202.5
+ ],
+ "length": 450,
+ "width": 180,
+ "height": 405,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Back cushion 1",
+ "edges": [
+ [
+ 0,
+ -90.0,
+ -202.5
+ ],
+ [
+ 0,
+ -90.0,
+ 202.5
+ ],
+ [
+ 0,
+ 90.0,
+ -202.5
+ ],
+ [
+ 0,
+ 90.0,
+ 202.5
+ ],
+ [
+ -225.0,
+ 0,
+ -202.5
+ ],
+ [
+ -225.0,
+ 0,
+ 202.5
+ ],
+ [
+ 225.0,
+ 0,
+ -202.5
+ ],
+ [
+ 225.0,
+ 0,
+ 202.5
+ ],
+ [
+ -225.0,
+ -90.0,
+ 0
+ ],
+ [
+ -225.0,
+ 90.0,
+ 0
+ ],
+ [
+ 225.0,
+ -90.0,
+ 0
+ ],
+ [
+ 225.0,
+ 90.0,
+ 0
+ ]
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Back cushion 1"
+ ],
+ "translate": [
+ -460,
+ 1230,
+ 545
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Seat cushion 2",
+ "corner": [
+ -227.5,
+ -270.0,
+ -75.0
+ ],
+ "length": 455,
+ "width": 540,
+ "height": 150,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Seat cushion 2",
+ "edges": [
+ [
+ 0,
+ -270.0,
+ -75.0
+ ],
+ [
+ 0,
+ -270.0,
+ 75.0
+ ],
+ [
+ 0,
+ 270.0,
+ -75.0
+ ],
+ [
+ 0,
+ 270.0,
+ 75.0
+ ],
+ [
+ -227.5,
+ 0,
+ -75.0
+ ],
+ [
+ -227.5,
+ 0,
+ 75.0
+ ],
+ [
+ 227.5,
+ 0,
+ -75.0
+ ],
+ [
+ 227.5,
+ 0,
+ 75.0
+ ],
+ [
+ -227.5,
+ -270.0,
+ 0
+ ],
+ [
+ -227.5,
+ 270.0,
+ 0
+ ],
+ [
+ 227.5,
+ -270.0,
+ 0
+ ],
+ [
+ 227.5,
+ 270.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Seat cushion 2"
+ ],
+ "translate": [
+ 0,
+ 1020,
+ 285
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Back cushion 2",
+ "corner": [
+ -225.0,
+ -90.0,
+ -202.5
+ ],
+ "length": 450,
+ "width": 180,
+ "height": 405,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Back cushion 2",
+ "edges": [
+ [
+ 0,
+ -90.0,
+ -202.5
+ ],
+ [
+ 0,
+ -90.0,
+ 202.5
+ ],
+ [
+ 0,
+ 90.0,
+ -202.5
+ ],
+ [
+ 0,
+ 90.0,
+ 202.5
+ ],
+ [
+ -225.0,
+ 0,
+ -202.5
+ ],
+ [
+ -225.0,
+ 0,
+ 202.5
+ ],
+ [
+ 225.0,
+ 0,
+ -202.5
+ ],
+ [
+ 225.0,
+ 0,
+ 202.5
+ ],
+ [
+ -225.0,
+ -90.0,
+ 0
+ ],
+ [
+ -225.0,
+ 90.0,
+ 0
+ ],
+ [
+ 225.0,
+ -90.0,
+ 0
+ ],
+ [
+ 225.0,
+ 90.0,
+ 0
+ ]
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Back cushion 2"
+ ],
+ "translate": [
+ 0,
+ 1230,
+ 545
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Seat cushion 3",
+ "corner": [
+ -227.5,
+ -270.0,
+ -75.0
+ ],
+ "length": 455,
+ "width": 540,
+ "height": 150,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Seat cushion 3",
+ "edges": [
+ [
+ 0,
+ -270.0,
+ -75.0
+ ],
+ [
+ 0,
+ -270.0,
+ 75.0
+ ],
+ [
+ 0,
+ 270.0,
+ -75.0
+ ],
+ [
+ 0,
+ 270.0,
+ 75.0
+ ],
+ [
+ -227.5,
+ 0,
+ -75.0
+ ],
+ [
+ -227.5,
+ 0,
+ 75.0
+ ],
+ [
+ 227.5,
+ 0,
+ -75.0
+ ],
+ [
+ 227.5,
+ 0,
+ 75.0
+ ],
+ [
+ -227.5,
+ -270.0,
+ 0
+ ],
+ [
+ -227.5,
+ 270.0,
+ 0
+ ],
+ [
+ 227.5,
+ -270.0,
+ 0
+ ],
+ [
+ 227.5,
+ 270.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Seat cushion 3"
+ ],
+ "translate": [
+ 460,
+ 1020,
+ 285
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Back cushion 3",
+ "corner": [
+ -225.0,
+ -90.0,
+ -202.5
+ ],
+ "length": 450,
+ "width": 180,
+ "height": 405,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Back cushion 3",
+ "edges": [
+ [
+ 0,
+ -90.0,
+ -202.5
+ ],
+ [
+ 0,
+ -90.0,
+ 202.5
+ ],
+ [
+ 0,
+ 90.0,
+ -202.5
+ ],
+ [
+ 0,
+ 90.0,
+ 202.5
+ ],
+ [
+ -225.0,
+ 0,
+ -202.5
+ ],
+ [
+ -225.0,
+ 0,
+ 202.5
+ ],
+ [
+ 225.0,
+ 0,
+ -202.5
+ ],
+ [
+ 225.0,
+ 0,
+ 202.5
+ ],
+ [
+ -225.0,
+ -90.0,
+ 0
+ ],
+ [
+ -225.0,
+ 90.0,
+ 0
+ ],
+ [
+ 225.0,
+ -90.0,
+ 0
+ ],
+ [
+ 225.0,
+ 90.0,
+ 0
+ ]
+ ],
+ "radius": 65
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Back cushion 3"
+ ],
+ "translate": [
+ 460,
+ 1230,
+ 545
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Ochre throw cushion",
+ "corner": [
+ -157.5,
+ -65.0,
+ -165.0
+ ],
+ "length": 315,
+ "width": 130,
+ "height": 330,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Ochre throw cushion",
+ "edges": [
+ [
+ 0,
+ -65.0,
+ -165.0
+ ],
+ [
+ 0,
+ -65.0,
+ 165.0
+ ],
+ [
+ 0,
+ 65.0,
+ -165.0
+ ],
+ [
+ 0,
+ 65.0,
+ 165.0
+ ],
+ [
+ -157.5,
+ 0,
+ -165.0
+ ],
+ [
+ -157.5,
+ 0,
+ 165.0
+ ],
+ [
+ 157.5,
+ 0,
+ -165.0
+ ],
+ [
+ 157.5,
+ 0,
+ 165.0
+ ],
+ [
+ -157.5,
+ -65.0,
+ 0
+ ],
+ [
+ -157.5,
+ 65.0,
+ 0
+ ],
+ [
+ 157.5,
+ -65.0,
+ 0
+ ],
+ [
+ 157.5,
+ 65.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Ochre throw cushion"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "-18 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Ochre throw cushion"
+ ],
+ "translate": [
+ -520,
+ 1090,
+ 560
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Taupe throw cushion",
+ "corner": [
+ -145.0,
+ -65.0,
+ -155.0
+ ],
+ "length": 290,
+ "width": 130,
+ "height": 310,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.fillet",
+ "params": {
+ "body": "Taupe throw cushion",
+ "edges": [
+ [
+ 0,
+ -65.0,
+ -155.0
+ ],
+ [
+ 0,
+ -65.0,
+ 155.0
+ ],
+ [
+ 0,
+ 65.0,
+ -155.0
+ ],
+ [
+ 0,
+ 65.0,
+ 155.0
+ ],
+ [
+ -145.0,
+ 0,
+ -155.0
+ ],
+ [
+ -145.0,
+ 0,
+ 155.0
+ ],
+ [
+ 145.0,
+ 0,
+ -155.0
+ ],
+ [
+ 145.0,
+ 0,
+ 155.0
+ ],
+ [
+ -145.0,
+ -65.0,
+ 0
+ ],
+ [
+ -145.0,
+ 65.0,
+ 0
+ ],
+ [
+ 145.0,
+ -65.0,
+ 0
+ ],
+ [
+ 145.0,
+ 65.0,
+ 0
+ ]
+ ],
+ "radius": 55
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Taupe throw cushion"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "16 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Taupe throw cushion"
+ ],
+ "translate": [
+ 530,
+ 1115,
+ 545
+ ]
+ }
+ },
+ {
+ "command": "sketch.create",
+ "params": {
+ "name": "Plant stand profile",
+ "plane": {
+ "origin": [
+ 620,
+ 575,
+ 0
+ ],
+ "x_dir": [
+ 1,
+ 0,
+ 0
+ ],
+ "y_dir": [
+ 0,
+ 1,
+ 0
+ ]
+ }
+ }
+ },
+ {
+ "command": "sketch.rectangle.rounded",
+ "params": {
+ "p0": [
+ -100.0,
+ -100.0
+ ],
+ "p1": [
+ 100.0,
+ 100.0
+ ],
+ "radius": 30
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.extrude",
+ "params": {
+ "distance": 430,
+ "operation": "new",
+ "body_name": "Plant stand"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Ceramic plant pot",
+ "base": [
+ 620,
+ 575,
+ 430
+ ],
+ "radius": 82,
+ "height": 146,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "base": [
+ 620,
+ 575,
+ 442
+ ],
+ "radius": 73,
+ "height": 136,
+ "operation": "cut",
+ "targets": [
+ "Ceramic plant pot"
+ ],
+ "name": "Open ceramic pot"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Pot soil",
+ "base": [
+ 620,
+ 575,
+ 550
+ ],
+ "radius": 71,
+ "height": 8,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 1",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 200.6888138387389,
+ "axis": [
+ 100.0,
+ 0.0,
+ 174
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 1",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 1"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 1"
+ ],
+ "translate": [
+ 720.0,
+ 575.0,
+ 730
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 2",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 266.5933232472261,
+ "axis": [
+ -91.42238976445537,
+ 83.77318574434184,
+ 236
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 2",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 2"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 2"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "137.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 2"
+ ],
+ "translate": [
+ 528.5776102355446,
+ 658.7731857443418,
+ 792
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 3",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 332.7281172368816,
+ "axis": [
+ 12.899049926653333,
+ -147.43681531757835,
+ 298
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 3",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 3"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 3"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "275.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 3"
+ ],
+ "translate": [
+ 632.8990499266533,
+ 427.56318468242165,
+ 854
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 4",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 373.6308338453881,
+ "axis": [
+ 60.87614290087208,
+ 79.33533402912349,
+ 360
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 4",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 4"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 4"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "412.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 4"
+ ],
+ "translate": [
+ 680.8761429008721,
+ 654.3353340291235,
+ 916
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 5",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 213.66328650472454,
+ "axis": [
+ -122.11616137351382,
+ -21.532374030699316,
+ 174
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 5",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 5"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 5"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "550.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 5"
+ ],
+ "translate": [
+ 497.8838386264862,
+ 553.4676259693007,
+ 730
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 6",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 278.5677655436824,
+ "axis": [
+ 124.821933980307,
+ -79.52034203533003,
+ 236
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 6",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 6"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 6"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "687.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 6"
+ ],
+ "translate": [
+ 744.821933980307,
+ 495.47965796466997,
+ 792
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 7",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 314.33103569326397,
+ "axis": [
+ -25.881904510251957,
+ 96.59258262890683,
+ 298
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 7",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 7"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 7"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "825.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 7"
+ ],
+ "translate": [
+ 594.118095489748,
+ 671.5925826289068,
+ 854
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 8",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 380.7571404451924,
+ "axis": [
+ -57.256828041144104,
+ -109.98934331409953,
+ 360
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 8",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 8"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 8"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "962.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 8"
+ ],
+ "translate": [
+ 562.7431719588559,
+ 465.01065668590047,
+ 916
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 9",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 228.42942017174585,
+ "axis": [
+ 139.07450787631456,
+ 50.61898121219883,
+ 174
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 9",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 9"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 9"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "1100.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 9"
+ ],
+ "translate": [
+ 759.0745078763146,
+ 625.6189812121988,
+ 730
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 10",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 256.3123094976127,
+ "axis": [
+ -92.38795325112869,
+ 38.26834323650894,
+ 236
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 10",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 10"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 10"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "1237.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 10"
+ ],
+ "translate": [
+ 527.6120467488713,
+ 613.2683432365089,
+ 792
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 11",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 322.7692674341843,
+ "axis": [
+ 52.404664455846614,
+ -112.38216559254465,
+ 298
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 11",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 11"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 11"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "1375.0 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 11"
+ ],
+ "translate": [
+ 672.4046644558466,
+ 462.61783440745535,
+ 854
+ ]
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Plant stem 12",
+ "base": [
+ 620,
+ 575,
+ 556
+ ],
+ "radius": 2.5,
+ "height": 389.2351474366106,
+ "axis": [
+ 44.5044583266324,
+ 141.15010871073764,
+ 360
+ ],
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.sphere",
+ "params": {
+ "body_name": "Plant leaf 12",
+ "center": [
+ 0,
+ 0,
+ 0
+ ],
+ "radius": 1,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.scale",
+ "params": {
+ "bodies": [
+ "Plant leaf 12"
+ ],
+ "factors": [
+ 62,
+ 23,
+ 4
+ ]
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 12"
+ ],
+ "axis": [
+ 0,
+ 0,
+ 1
+ ],
+ "angle": "1512.5 deg"
+ }
+ },
+ {
+ "command": "solid.move",
+ "params": {
+ "bodies": [
+ "Plant leaf 12"
+ ],
+ "translate": [
+ 664.5044583266324,
+ 716.1501087107376,
+ 916
+ ]
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 1",
+ "corner": [
+ -1030,
+ 1440,
+ 660
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 2",
+ "corner": [
+ -1030,
+ 1440,
+ 705
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 3",
+ "corner": [
+ -1030,
+ 1440,
+ 750
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 4",
+ "corner": [
+ -1030,
+ 1440,
+ 795
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 5",
+ "corner": [
+ -1030,
+ 1440,
+ 840
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 6",
+ "corner": [
+ -1030,
+ 1440,
+ 885
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 7",
+ "corner": [
+ -1030,
+ 1440,
+ 930
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 8",
+ "corner": [
+ -1030,
+ 1440,
+ 975
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 9",
+ "corner": [
+ -1030,
+ 1440,
+ 1020
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 10",
+ "corner": [
+ -1030,
+ 1440,
+ 1065
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 11",
+ "corner": [
+ -1030,
+ 1440,
+ 1110
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 12",
+ "corner": [
+ -1030,
+ 1440,
+ 1155
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 13",
+ "corner": [
+ -1030,
+ 1440,
+ 1200
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window blind slat 14",
+ "corner": [
+ -1030,
+ 1440,
+ 1245
+ ],
+ "length": 850,
+ "width": 52,
+ "height": 12,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window jamb -1048",
+ "corner": [
+ -1048,
+ 1434,
+ 620
+ ],
+ "length": 18,
+ "width": 70,
+ "height": 710,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window jamb -180",
+ "corner": [
+ -180,
+ 1434,
+ 620
+ ],
+ "length": 18,
+ "width": 70,
+ "height": 710,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window rail 620",
+ "corner": [
+ -1030,
+ 1434,
+ 620
+ ],
+ "length": 850,
+ "width": 70,
+ "height": 18,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.box",
+ "params": {
+ "body_name": "Window rail 1320",
+ "corner": [
+ -1030,
+ 1434,
+ 1320
+ ],
+ "length": 850,
+ "width": 70,
+ "height": 18,
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Blind cord -860",
+ "base": [
+ -860,
+ 1425,
+ 635
+ ],
+ "radius": 1.5,
+ "height": 690,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "body_name": "Blind cord -350",
+ "base": [
+ -350,
+ 1425,
+ 635
+ ],
+ "radius": 1.5,
+ "height": 690,
+ "axis": "Z",
+ "operation": "new"
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Room floor"
+ ],
+ "color": "#e8e8e8",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.65,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Walnut tabletop",
+ "Table leg 1",
+ "Table leg 2",
+ "Table leg 3",
+ "Table leg 4",
+ "Plant stand"
+ ],
+ "color": "#4c2818",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.42,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Sofa back",
+ "Left sofa arm",
+ "Right sofa arm",
+ "Seat cushion 1",
+ "Back cushion 1",
+ "Seat cushion 2",
+ "Back cushion 2",
+ "Seat cushion 3",
+ "Back cushion 3",
+ "Blind cord -860",
+ "Blind cord -350"
+ ],
+ "color": "#ada69b",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.88,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Ochre throw cushion"
+ ],
+ "color": "#a66c32",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.9,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Sofa plinth",
+ "Taupe throw cushion"
+ ],
+ "color": "#71685e",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.9,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Plant leaf 1",
+ "Plant leaf 2",
+ "Plant leaf 3",
+ "Plant leaf 4",
+ "Plant leaf 5",
+ "Plant leaf 6",
+ "Plant leaf 7",
+ "Plant leaf 8",
+ "Plant leaf 9",
+ "Plant leaf 10",
+ "Plant leaf 11",
+ "Plant leaf 12"
+ ],
+ "color": "#315a2b",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.6,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Plant stem 1",
+ "Plant stem 2",
+ "Plant stem 3",
+ "Plant stem 4",
+ "Plant stem 5",
+ "Plant stem 6",
+ "Plant stem 7",
+ "Plant stem 8",
+ "Plant stem 9",
+ "Plant stem 10",
+ "Plant stem 11",
+ "Plant stem 12"
+ ],
+ "color": "#425c2b",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.75,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Pot soil"
+ ],
+ "color": "#23190f",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 1,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Ceramic plant pot"
+ ],
+ "color": "#b4b3a5",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.38,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Rear plaster wall",
+ "Left plaster wall",
+ "Window jamb -1048",
+ "Window jamb -180",
+ "Window rail 620",
+ "Window rail 1320"
+ ],
+ "color": "#ded9d1",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.85,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Window blind slat 1",
+ "Window blind slat 2",
+ "Window blind slat 3",
+ "Window blind slat 4",
+ "Window blind slat 5",
+ "Window blind slat 6",
+ "Window blind slat 7",
+ "Window blind slat 8",
+ "Window blind slat 9",
+ "Window blind slat 10",
+ "Window blind slat 11",
+ "Window blind slat 12",
+ "Window blind slat 13",
+ "Window blind slat 14"
+ ],
+ "color": "#bdac91",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.7,
+ "dielectric_ior": 1.5
+ }
+ }
+ },
+ {
+ "command": "appearance.assign",
+ "params": {
+ "bodies": [
+ "Tall thick tumbler",
+ "Short thick tumbler"
+ ],
+ "color": "#ffffff",
+ "pbr": {
+ "metallic": 0,
+ "roughness": 0.045,
+ "dielectric_ior": 1.5
+ }
+ }
+ }
+ ]
+}
diff --git a/xtask/src/ui_containers.rs b/xtask/src/ui_containers.rs
index 475f79851a..56735a2198 100644
--- a/xtask/src/ui_containers.rs
+++ b/xtask/src/ui_containers.rs
@@ -325,7 +325,8 @@ pub fn run(root: &Path) -> Result<(), String> {
let source = std::fs::read_to_string(&path).map_err(|e| format!("{}: {e}", path.display()))?;
let found = violations(&source).map_err(|e| format!("{}: {e}", path.display()))?;
if !found.is_empty() {
- failures.push(format!("{}: {}", path.strip_prefix(root).unwrap_or(&path).display(), found.join(", ")));
+ let relative = path.strip_prefix(root).unwrap_or(&path).to_string_lossy().replace('\\', "/");
+ failures.push(format!("{relative}: {}", found.join(", ")));
}
}
}