@displayxr/inline3d-tools 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -15,11 +15,11 @@ sandboxed agent, prefer the MCP server** (below): MCP servers run outside the sa
15
15
  sandbox. Otherwise run them as shell commands:
16
16
 
17
17
  ```sh
18
- npx -y @displayxr/inline3d-tools@0.1.3 check <url | dir | page.html> [--root <project>] [--max-texture 4096]
19
- npx -y @displayxr/inline3d-tools@0.1.3 assets <file.glb> [--target tablet|desktop]
20
- npx -y @displayxr/inline3d-tools@0.1.3 assets prep <in> <out.glb> [--metres 0.01] [--decimate 0.5]
21
- npx -y @displayxr/inline3d-tools@0.1.3 scaffold <esm|vite> <target-dir> --title "<page title>"
22
- npx -y @displayxr/inline3d-tools@0.1.3 gen providers | gen run <adapter> ... --confirm-paid | gen provenance --file ...
18
+ npx -y @displayxr/inline3d-tools@0.1.5 check <url | dir | page.html> [--root <project>] [--max-texture 4096]
19
+ npx -y @displayxr/inline3d-tools@0.1.5 assets <file.glb> [--target tablet|desktop]
20
+ npx -y @displayxr/inline3d-tools@0.1.5 assets prep <in> <out.glb> [--metres 0.01] [--decimate 0.5]
21
+ npx -y @displayxr/inline3d-tools@0.1.5 scaffold <esm|vite> <target-dir> --title "<page title>"
22
+ npx -y @displayxr/inline3d-tools@0.1.5 gen providers | gen run <adapter> ... --confirm-paid | gen provenance --file ...
23
23
  ```
24
24
 
25
25
  or, with the MCP server configured (`inline3d-tools mcp`; config snippets for Codex, Cursor and
@@ -88,13 +88,28 @@ three when the page already is a three.js app (`addScene` + `EyeCamera`, see
88
88
  - Budgets are reports, not limits to stay far inside: never lower depth as the user zooms.
89
89
  Details: `docs/authoring-inline-3d.md` § Aim for real depth.
90
90
 
91
- ### 3. Depth and comfort (`docs/making-3d-look-right.md`, nine rules)
91
+ ### 3. Depth and comfort (`docs/making-3d-look-right.md`, ten rules)
92
92
 
93
- Centre the subject on z = 0 (the glass), at real proportions; don't push it back or flatten it.
93
+ The subject straddles the glass (z = 0): about a quarter in front, the rest just behind, at real
94
+ proportions; don't push it back, shrink it or flatten it. `addModel` does this by default (SDK
95
+ 1.57.0+): screen plane at the surface's 75th-percentile depth toward the viewer, pivot at the surface's
96
+ median, fit from trimmed extents, so a thin tail or antenna moves neither size nor depth; keep that
97
+ placement (`framing: 'box'` restores the old bounding-box centring, only for a reason you can name).
98
+ `addSplat` and `SceneViewer.fitTo(center, extent)` centre the subject's robust centre on the glass; a
99
+ scene you build yourself follows the same rule.
94
100
  `+z` is OUT of the glass. Frame the whole subject in the first view. Tilt flat layouts 25–40° about an
95
101
  axis through the glass. Keep moving things' forward swing small. Worlds: fixed convergence, keep the
96
102
  camera clear of near geometry. Light/mid-tone low-contrast backgrounds (never pure black behind a
97
- bright subject). Text as HTML near the glass, not in the scene. No coplanar faces (z-fighting), no
103
+ bright subject). **A backdrop sits behind the subject, never on the glass** (rule 10): a CSS image
104
+ behind a transparent canvas is on the glass and conflicts with any part of the subject behind it.
105
+ Draw a photo backdrop in the scene as ONE unlit plane fixed to the display, NOT to the subject (it
106
+ does not turn with the orbit or grow with the zoom; never parent it to the model. PlayCanvas: a child of
107
+ `handle.viewer.rigNode`; +z toward the viewer, one tile height = `viewer.vH`), behind the subject's
108
+ farthest point at any turn and the largest zoom you allow (cap the zoom so this holds), at about 40% of the rear comfort budget:
109
+ `backdropPlacement({ backH, tileHeightM })` from `@displayxr/inline3d/depth` returns its depth
110
+ (`depthH`) and size (`widthH` × `heightH`), tile heights. Pre-blurred, mid-tone; no skybox or
111
+ environment map as a backdrop. A plain colour or soft gradient needs none of this.
112
+ Text as HTML near the glass, not in the scene. No coplanar faces (z-fighting), no
98
113
  sub-pixel detail. Scene units: metres for a `virtualDisplayHeight` (0.24 by default); never scale the
99
114
  world per frame. Shrinking depth: rotate or scale uniformly, never squash z.
100
115
 
@@ -122,8 +137,9 @@ world per frame. Shrinking depth: rotate or scale uniformly, never squash z.
122
137
  `woven-canvas-rules.md` §11).
123
138
  - [ ] **What is behind a transparent tile is part of the picture.** `addSplat` / `addModel` clear
124
139
  transparent by default, and the browser pre-blends the page under both eyes, flat, at half
125
- horizontal resolution. Make that page area a soft light or mid-tone colour or gradient (no
126
- text or photo behind a tile, never black behind a bright subject), or pass an opaque
140
+ horizontal resolution, on the glass. Make that page area a soft light or mid-tone colour or gradient (no
141
+ text or photo behind a tile, never black behind a bright subject; a photo backdrop goes IN the
142
+ scene, behind the subject: §3, rule 10), or pass an opaque
127
143
  `clearColor: [r, g, b, 1]` (0..1).
128
144
  - [ ] **`onLayerLost` goes flat** (`addScene` pages): pass `onLayerLost` and, in it, render ONE mono
129
145
  camera across the whole canvas on your own rAF loop (the `!wall.supported` path) or show a 2D
@@ -131,8 +147,15 @@ world per frame. Shrinking depth: rotate or scale uniformly, never squash z.
131
147
  `onLayerLost: viewer.onLayerLost`; `addSplat` / `addModel` / `addPlayer` handle it themselves.
132
148
  - [ ] **Nothing opaque above the canvas**; backgrounds and black go *under* it. Never overlap two
133
149
  woven canvases (hide the lower one with `display: none`).
134
- - [ ] **Buffer = 2 × eye width**: `addScene` pages size it themselves (2× the box aspect, devicePixelRatio
135
- ≤ 2, every side ≤ 4096 for tablets) and draw into `gl.drawingBufferWidth/Height`. three.js:
150
+ - [ ] **Buffer = 2 × eye width, from `sceneBufferSize`** (core, 1.58.0+): an `addScene` page sizes its
151
+ canvas with `sceneBufferSize(canvas, { sbs, viewScale: sbs ? await handle.getDisplayInfo() : null })` (set
152
+ `canvas.width/height`, or `renderer.setSize(s.width, s.height, false)`, only when they change;
153
+ camera aspect from `s.eyeWidth / s.eyeHeight`), never `clientWidth × devicePixelRatio × 2`. Per eye
154
+ it is window device px × the runtime's view scale (dpr ≤ 2 without one), fitted to the GL limits
155
+ and the browser's drawing-buffer area cap. Hand-rolled on an 8K panel at 300% it asks for
156
+ 15360×4320; the browser silently shrinks the buffer, the eyes land off-centre and one eye shows
157
+ both images. The SDK's `the browser clamped this canvas's drawing buffer` warning is that bug.
158
+ Draw into `gl.drawingBufferWidth/Height`. three.js:
136
159
  `renderer.setPixelRatio(1)` when you use `getViewport()`.
137
160
  - [ ] **Validate before you clear**: skip the clear when `views.length < 2` or a viewport is `null`;
138
161
  repaint the last good frame. Copy `XRViewport` / `XRView` fields by name (their fields are
@@ -166,8 +189,8 @@ world per frame. Shrinking depth: rotate or scale uniformly, never squash z.
166
189
 
167
190
  ### 6. Pins (exact versions, no `^`)
168
191
 
169
- `@displayxr/inline3d` **1.56.1**, `playcanvas` **2.24.0** (exact; `>=2.22.3 <3` is the supported
170
- range), `three` **0.180.0**. CDN import maps pin the same: `https://cdn.jsdelivr.net/npm/@displayxr/inline3d@1.56.1/js/inline3d.js`,
192
+ `@displayxr/inline3d` **1.58.0**, `playcanvas` **2.24.0** (exact; `>=2.22.3 <3` is the supported
193
+ range), `three` **0.180.0**. CDN import maps pin the same: `https://cdn.jsdelivr.net/npm/@displayxr/inline3d@1.58.0/js/inline3d.js`,
171
194
  `https://cdn.jsdelivr.net/npm/playcanvas@2.24.0/build/playcanvas.mjs`,
172
195
  `https://cdn.jsdelivr.net/npm/three@0.180.0/build/three.module.js`. If a newer SDK is installed, its
173
196
  `CHANGELOG.md` says what changed; prefer the installed version's docs over this list.
@@ -175,7 +198,7 @@ range), `three` **0.180.0**. CDN import maps pin the same: `https://cdn.jsdelivr
175
198
  ### 7. Before you say done: run the checker
176
199
 
177
200
  ```sh
178
- npx -y @displayxr/inline3d-tools@0.1.3 check <url | dir | page.html> [--root <project>] [--max-texture 4096]
201
+ npx -y @displayxr/inline3d-tools@0.1.5 check <url | dir | page.html> [--root <project>] [--max-texture 4096]
179
202
  ```
180
203
 
181
204
  This runs the exact-pinned `@displayxr/inline3d-tools` package from npm (the first run downloads it;
@@ -203,8 +226,8 @@ The templates ship in the exact-pinned `@displayxr/inline3d-tools` npm package;
203
226
  command copies them (the first run downloads the package; the user may be asked to approve the command):
204
227
 
205
228
  ```sh
206
- npx -y @displayxr/inline3d-tools@0.1.3 scaffold esm <target-dir> --title "<page title>"
207
- npx -y @displayxr/inline3d-tools@0.1.3 scaffold vite <target-dir> --title "<page title>" [--name <npm-name>]
229
+ npx -y @displayxr/inline3d-tools@0.1.5 scaffold esm <target-dir> --title "<page title>"
230
+ npx -y @displayxr/inline3d-tools@0.1.5 scaffold vite <target-dir> --title "<page title>" [--name <npm-name>]
208
231
  ```
209
232
 
210
233
  It never overwrites an existing file (`--force` replaces). What it writes:
@@ -214,7 +237,7 @@ It never overwrites an existing file (`--force` replaces). What it writes:
214
237
  | `app.js` | the page logic (shared by both flavours): a three.js scene on `addScene` with `EyeCamera`, display rig, validate-before-clear with last-good replay, buffer sized 2× the box (dpr ≤ 2, clamped to the GPU), cover removed on `handle.firstWoven` + a 4 s timeout + `catch`, a mono 2D fallback |
215
238
  | `style.css` | page styles; the canvas and its ancestors carry no CSS effects |
216
239
  | `index.html` (esm) | no build step: an import map with exact CDN pins |
217
- | `index.html` + `package.json` (vite) | Vite: exact npm pins (`@displayxr/inline3d` 1.56.1, `three` 0.180.0) |
240
+ | `index.html` + `package.json` (vite) | Vite: exact npm pins (`@displayxr/inline3d` 1.58.0, `three` 0.180.0) |
218
241
 
219
242
  ### Steps
220
243
 
@@ -245,7 +268,7 @@ It never overwrites an existing file (`--force` replaces). What it writes:
245
268
  without `player.firstWoven`, wait for the first frame and then ~1200 ms more.
246
269
 
247
270
  Add `"playcanvas": "https://cdn.jsdelivr.net/npm/playcanvas@2.24.0/build/playcanvas.mjs"` and
248
- `"@displayxr/inline3d/model": "https://cdn.jsdelivr.net/npm/@displayxr/inline3d@1.56.1/js/inline3d-model-entry.js"`
271
+ `"@displayxr/inline3d/model": "https://cdn.jsdelivr.net/npm/@displayxr/inline3d@1.58.0/js/inline3d-model-entry.js"`
249
272
  (or `.../js/inline3d-splat-pc-entry.js` for `/splat/playcanvas`) to the import map, or
250
273
  `"playcanvas": "2.24.0"` to `package.json`. Images and video use `wall.addImage(canvas, 'pic_2x1.jpg')`
251
274
  / `wall.addVideo(canvas, videoEl)` in the 3D branch and an `<img>` of the left half (or a mono
@@ -256,8 +279,8 @@ It never overwrites an existing file (`--force` replaces). What it writes:
256
279
  5. **Run the checker before saying done**, and fix every FAIL:
257
280
 
258
281
  ```sh
259
- npx -y @displayxr/inline3d-tools@0.1.3 check <target-dir> # esm
260
- npx -y @displayxr/inline3d-tools@0.1.3 check http://localhost:5173/ # vite dev server
282
+ npx -y @displayxr/inline3d-tools@0.1.5 check <target-dir> # esm
283
+ npx -y @displayxr/inline3d-tools@0.1.5 check http://localhost:5173/ # vite dev server
261
284
  ```
262
285
 
263
286
  The untouched template passes every check (verdict PASS). If your change makes a check fail, the
@@ -274,17 +297,17 @@ Tools, in the order to reach for them:
274
297
 
275
298
  | Tool | When | Install |
276
299
  |---|---|---|
277
- | `inline3d-tools assets` | always, last | `npx -y @displayxr/inline3d-tools@0.1.3 assets` (exact pin, from npm; Node only) |
300
+ | `inline3d-tools assets` | always, last | `npx -y @displayxr/inline3d-tools@0.1.5 assets` (exact pin, from npm; Node only) |
278
301
  | glTF-Transform CLI | glTF/GLB in, glTF/GLB out: inspect, resize, compress, simplify, centre | `npx -y @gltf-transform/cli@4.3.0` (pinned; nothing installed globally) |
279
302
  | Blender (headless) | any other format (FBX, OBJ, STL, PLY, DAE, .blend), units/axis fixes, heavy decimation | **only if already installed**; never install it |
280
- | `inline3d-tools gen` | no asset exists and the user wants one generated | `npx -y @displayxr/inline3d-tools@0.1.3 gen`; needs the user's own API key in the environment; every call is paid and needs the user's yes |
303
+ | `inline3d-tools gen` | no asset exists and the user wants one generated | `npx -y @displayxr/inline3d-tools@0.1.5 gen`; needs the user's own API key in the environment; every call is paid and needs the user's yes |
281
304
 
282
305
  ### 1. Get it
283
306
 
284
307
  In order of preference:
285
308
 
286
309
  1. **The user's own asset** (in the project, or a path they gave). Record it:
287
- `npx -y @displayxr/inline3d-tools@0.1.3 gen provenance --file assets/x.glb --source "supplied by the user" --license "user's"`.
310
+ `npx -y @displayxr/inline3d-tools@0.1.5 gen provenance --file assets/x.glb --source "supplied by the user" --license "user's"`.
288
311
  2. **A library asset with a clear licence** (CC0 / CC-BY, e.g. the Khronos glTF sample models,
289
312
  Poly Haven). Record the URL, author and licence; CC-BY needs visible credit on the page.
290
313
  3. **A placeholder you build** (primitives in three.js/PlayCanvas) when nothing fits and the user
@@ -314,7 +337,7 @@ fetches decoders from a CDN). Other fixes: `$GT simplify in.glb out.glb --ratio
314
337
  **Anything else (Blender, if present).** Detect it, don't install it:
315
338
 
316
339
  ```sh
317
- npx -y @displayxr/inline3d-tools@0.1.3 assets prep in.fbx out.glb [--metres 0.01] [--decimate 0.5] [--blender <path>]
340
+ npx -y @displayxr/inline3d-tools@0.1.5 assets prep in.fbx out.glb [--metres 0.01] [--decimate 0.5] [--blender <path>]
318
341
  ```
319
342
 
320
343
  It looks for Blender (`--blender`, `$BLENDER`, `PATH`, the default install location), never installs
@@ -323,15 +346,16 @@ metres (`--metres` = metres per source unit: 0.01 for centimetres), decimates, r
323
346
  the glTF-Transform `optimize` line on its output (Blender writes PNG textures; WebP is far smaller).
324
347
  No Blender: say the format cannot be converted here, and ask for a GLB.
325
348
 
326
- Units: `addModel` frames the model on the glass from its bounds, so units and offset do not break
349
+ Units: `addModel` frames the model on the glass from its surface (screen plane at the 75th-percentile
350
+ depth, pivot at the median, fit from trimmed extents), so units, offset and a thin tail do not break
327
351
  it; a model you place in your own `addScene` must be in **metres, centred** (its real size: a
328
352
  helmet is ~0.3 m, not 2 m).
329
353
 
330
354
  ### 3. Check it (before the page uses it)
331
355
 
332
356
  ```sh
333
- npx -y @displayxr/inline3d-tools@0.1.3 assets out.glb # tablet budget (default)
334
- npx -y @displayxr/inline3d-tools@0.1.3 assets out.glb --target desktop
357
+ npx -y @displayxr/inline3d-tools@0.1.5 assets out.glb # tablet budget (default)
358
+ npx -y @displayxr/inline3d-tools@0.1.5 assets out.glb --target desktop
335
359
  ```
336
360
 
337
361
  It reports: missing external files, decoders the page must provide, triangles (both eyes draw
@@ -345,7 +369,7 @@ animations. Fix every FAIL; act on WARNs or say why not. Then run the page check
345
369
  ### 4. Generate it (optional, paid, the user's keys)
346
370
 
347
371
  ```sh
348
- npx -y @displayxr/inline3d-tools@0.1.3 gen providers # which adapters have a key (names only)
372
+ npx -y @displayxr/inline3d-tools@0.1.5 gen providers # which adapters have a key (names only)
349
373
  ```
350
374
 
351
375
  Adapters: `meshy` and `tripo` (text-to-3d, image-to-3d → GLB), `openai` (image → PNG, for
@@ -366,7 +390,7 @@ textures, posters and backdrops). Each reads its key from the environment (`MESH
366
390
  shippable.
367
391
 
368
392
  ```sh
369
- npx -y @displayxr/inline3d-tools@0.1.3 gen run meshy --kind text-to-3d --prompt "a brass desk lamp, PBR" --out assets/lamp-raw.glb --confirm-paid
393
+ npx -y @displayxr/inline3d-tools@0.1.5 gen run meshy --kind text-to-3d --prompt "a brass desk lamp, PBR" --out assets/lamp-raw.glb --confirm-paid
370
394
  ```
371
395
 
372
396
  ### 5. ASSETS.md
package/README.md CHANGED
@@ -9,7 +9,7 @@ same operations. [`AGENTS.md`](AGENTS.md) is the matching authoring checklist fo
9
9
  Needs Node ≥ 18. `check` also needs a local Chrome or Chromium. Always run an **exact version**:
10
10
 
11
11
  ```sh
12
- npx -y @displayxr/inline3d-tools@0.1.3 <command> ...
12
+ npx -y @displayxr/inline3d-tools@0.1.5 <command> ...
13
13
  ```
14
14
 
15
15
  ## CLI
@@ -47,7 +47,7 @@ environment only and are redacted from every tool result.
47
47
  ### Claude Code
48
48
 
49
49
  ```sh
50
- claude mcp add inline3d-tools -- npx -y @displayxr/inline3d-tools@0.1.3 mcp
50
+ claude mcp add inline3d-tools -- npx -y @displayxr/inline3d-tools@0.1.5 mcp
51
51
  ```
52
52
 
53
53
  or in a project's `.mcp.json`:
@@ -57,7 +57,7 @@ or in a project's `.mcp.json`:
57
57
  "mcpServers": {
58
58
  "inline3d-tools": {
59
59
  "command": "npx",
60
- "args": ["-y", "@displayxr/inline3d-tools@0.1.3", "mcp"]
60
+ "args": ["-y", "@displayxr/inline3d-tools@0.1.5", "mcp"]
61
61
  }
62
62
  }
63
63
  }
@@ -77,7 +77,7 @@ needs you to approve running it outside the sandbox. In `~/.codex/config.toml` (
77
77
  ```toml
78
78
  [mcp_servers.inline3d-tools]
79
79
  command = "npx"
80
- args = ["-y", "@displayxr/inline3d-tools@0.1.3", "mcp"]
80
+ args = ["-y", "@displayxr/inline3d-tools@0.1.5", "mcp"]
81
81
  # cwd = "/path/to/your/project" # relative paths in tool calls resolve here
82
82
  startup_timeout_sec = 30 # first run downloads the package (default 10)
83
83
  tool_timeout_sec = 180 # a page check takes 10-60 s; generation can take minutes (default 60)
@@ -85,11 +85,11 @@ tool_timeout_sec = 180 # a page check takes 10-60 s; generation can t
85
85
  # env_vars = ["MESHY_API_KEY", "TRIPO_API_KEY", "OPENAI_API_KEY"]
86
86
  ```
87
87
 
88
- or `codex mcp add inline3d-tools -- npx -y @displayxr/inline3d-tools@0.1.3 mcp`. The
88
+ or `codex mcp add inline3d-tools -- npx -y @displayxr/inline3d-tools@0.1.5 mcp`. The
89
89
  [`displayxr-inline3d-codex` plugin](https://github.com/DisplayXR/displayxr-web/tree/main/plugins/displayxr-inline3d-codex)
90
90
  sets the server up for you in Codex.
91
91
 
92
- **Fetch the package once before the first Codex session:** `npx -y @displayxr/inline3d-tools@0.1.3 --version`.
92
+ **Fetch the package once before the first Codex session:** `npx -y @displayxr/inline3d-tools@0.1.5 --version`.
93
93
  Codex starts MCP servers when a session starts and can stop one before a cold `npx` download
94
94
  finishes. The interrupted download leaves a broken entry in npm's `_npx` cache (`node_modules`
95
95
  without a `package.json`), and from then on the server fails at every start with
@@ -109,7 +109,7 @@ In `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project):
109
109
  "mcpServers": {
110
110
  "inline3d-tools": {
111
111
  "command": "npx",
112
- "args": ["-y", "@displayxr/inline3d-tools@0.1.3", "mcp"]
112
+ "args": ["-y", "@displayxr/inline3d-tools@0.1.5", "mcp"]
113
113
  }
114
114
  }
115
115
  }
@@ -151,7 +151,7 @@ forwarding). Never paste a key into an agent chat.
151
151
  ## check
152
152
 
153
153
  ```sh
154
- npx -y @displayxr/inline3d-tools@0.1.3 check <url | dir | page.html> [--root <dir>] [--max-texture 4096] [--json] [--out report.json]
154
+ npx -y @displayxr/inline3d-tools@0.1.5 check <url | dir | page.html> [--root <dir>] [--max-texture 4096] [--json] [--out report.json]
155
155
  ```
156
156
 
157
157
  Needs Node ≥ 18 and a local Chrome (`CHROME=/path/to/chrome` overrides the default location). It
@@ -184,6 +184,7 @@ disparity, so the checker can measure depth in millimetres of screen disparity.
184
184
  | `pins` | import-map CDN URLs and `package.json` versions for the SDK, playcanvas and three are exact | approximate |
185
185
  | `depth` | block-matched disparity of the primary canvas, in mm of screen disparity, against the Shibata comfort zone at 0.65 m; subject entirely off the glass | approximate |
186
186
  | `depth-underused` | too little depth is a failure too (a report, never a limit), 0.1.3. **Camera rig: measured** from the two eye images: the share of the Shibata comfort zone (0.65 m) the default view uses, on its binding side (`max(|p05| / front, p95 / behind)` of the block disparities, mm on the glass; `cameraRigComfortFactor` ≈ 1 / that share). Below 30 % is a WARN; a rig converged at infinity WARNs too. The hint gives the rule: convergence on the centre of interest, `metersToVirtual` = the true conversion or `convergence / 2` (no true scale), then `ipdFactor` ≈ 1 (open scene) or 0.8–1× `cameraRigComfortFactor` (bounded). **Display rig: from the rig** (its natural depth is the subject's real proportions, so the measured span is not judged): `ipdFactor` below 0.5 is a WARN (0 = 2D on purpose) | camera: approximate; display: real |
187
+ | `backdrop-on-glass` | rule 10, 0.1.4 (a report, never a limit). A picture the page draws under the woven canvas (a CSS `background-image` with a `url()`, an `<img>`, a `<video>`: found by walking the paint order below the canvas on a 9×6 grid) sits at the depth of the glass. WARN when at least 10% of the canvas has such a picture under it, at least 10% of the eye images is see-through, and the measured content reaches behind the glass (p95 of the block disparities past 10% of the rear comfort zone). The hint: draw the backdrop in the scene, behind the subject (`backdropPlacement()`), or bring the subject on or in front of the glass | approximate |
187
188
 
188
189
  Also reported: the rig (display/camera and its fields) and, for a camera rig, the comfort number
189
190
  `ipdFactor × metersToVirtual × convergenceDiopters × 0.65` (the divergence ceiling: keep ≤ 1).
@@ -317,3 +317,42 @@ export function rigDepthUse(rig, measured, zone) {
317
317
  }
318
318
  return { status: 'pass', summary: `the scene uses ${Math.round(use * 100)}% of the comfort zone at the default view (${front.toFixed(1)} mm in front, ${back.toFixed(1)} mm behind)`, details };
319
319
  }
320
+
321
+ /** backdrop-on-glass: the canvas counts as see-through when at least this share of an eye image is not opaque. */
322
+ export const BACKDROP_SEE_THROUGH = 0.1;
323
+ /** backdrop-on-glass: an image counts as "behind the canvas" when it shows under at least this share of it. */
324
+ export const BACKDROP_IMAGE_SHARE = 0.1;
325
+ /** backdrop-on-glass: content "extends behind the glass" past this share of the rear comfort zone (and 1 mm). */
326
+ export const BACKDROP_BEHIND_SHARE = 0.1;
327
+
328
+ /**
329
+ * Rule 10: a backdrop sits behind the subject, never on the glass. A picture the page draws under a
330
+ * see-through woven canvas (a CSS background-image, an <img> or a <video>) is at the depth of the
331
+ * glass, so any part of the subject that disparity puts behind the glass is drawn over a surface
332
+ * that is nearer than it. A report, never a limit.
333
+ * @param audit __dxrProbe.backdropAudit(): { total, imageFraction, sources: [{selector, kind, hits}] }
334
+ * @param seeThrough share of the eye images that is not opaque (0..1), or null when not captured
335
+ * @param measured on-glass disparities of the textured blocks, mm, signed (> 0 behind the glass)
336
+ * @param zone shibataZoneMm()
337
+ * @returns {{status: 'pass'|'warn'|'skip', summary: string, hint?: string, details: object|null}}
338
+ */
339
+ export function backdropOnGlass(audit, seeThrough, measured, zone) {
340
+ if (!audit || !audit.total) return { status: 'skip', summary: 'no woven canvas on screen to look behind', details: null };
341
+ const src = audit.sources && audit.sources[0];
342
+ const details = { imageBehind: +audit.imageFraction.toFixed(3), sources: audit.sources || [], seeThrough: seeThrough == null ? null : +seeThrough.toFixed(3) };
343
+ if (audit.imageFraction < BACKDROP_IMAGE_SHARE || !src) return { status: 'pass', summary: 'no page image behind the woven canvas', details };
344
+ if (seeThrough == null) return { status: 'skip', summary: 'no eye images to tell whether the canvas is see-through', details };
345
+ if (seeThrough < BACKDROP_SEE_THROUGH) return { status: 'pass', summary: `${src.selector} is behind the canvas, but the canvas is opaque, so it does not show through`, details };
346
+ if (!measured || measured.length < 3 || !zone) return { status: 'skip', summary: 'a page image shows through the canvas, but too few textured blocks to measure where the content sits', details };
347
+ const back = Math.max(0, quantile(measured, 0.95));
348
+ const limit = Math.max(1, BACKDROP_BEHIND_SHARE * (isFinite(zone.behindMm) ? zone.behindMm : 25));
349
+ Object.assign(details, { behindMm: +back.toFixed(2), behindLimitMm: +limit.toFixed(2) });
350
+ if (back <= limit) return { status: 'pass', summary: `${src.selector} shows through the canvas, and the content stays on or in front of the glass (${back.toFixed(1)} mm behind)`, details };
351
+ const what = src.kind === 'css' ? 'a CSS background-image' : `a <${src.kind}>`;
352
+ return {
353
+ status: 'warn',
354
+ summary: `${what} (${src.selector}) shows through the woven canvas, so it sits on the glass, while the content reaches ${back.toFixed(1)} mm behind the glass: the backdrop is in front of the part of the subject it should be behind`,
355
+ hint: 'Rule 10: a backdrop sits behind the subject, never on the glass. Draw the picture in the scene instead: one unlit plane fixed to the display (PlayCanvas: a child of viewer.rigNode), behind the subject, at about 40% of the rear comfort budget; backdropPlacement() from @displayxr/inline3d/depth gives its depth and size. Or keep the page image and bring the whole subject on or in front of the glass.',
356
+ details,
357
+ };
358
+ }
@@ -215,6 +215,64 @@
215
215
  };
216
216
  };
217
217
 
218
+ // Rule 10: what picture does the PAGE draw under the canvas? Hit-test a grid, start at the canvas
219
+ // and walk down the paint order to the first thing that fills the point: a CSS background-image
220
+ // (url), an <img>/<video>/<picture>, or an opaque colour (which ends the walk with no picture).
221
+ // A picture there is at the depth of the glass.
222
+ // Like occlusionAudit, it forces pointer-events on for the hit test, on purpose (a picture with
223
+ // pointer-events: none still paints); the rule is removed in `finally`, within the same task, so
224
+ // the page is never painted with it.
225
+ P.backdropAudit = function (canvas, cols = 9, rows = 6) {
226
+ const style = document.createElement('style');
227
+ style.textContent = '*{pointer-events:auto !important}';
228
+ document.documentElement.appendChild(style);
229
+ const r = canvas.getBoundingClientRect();
230
+ let total = 0, image = 0;
231
+ const sources = new Map();
232
+ const paints = (el) => {
233
+ const cs = getComputedStyle(el);
234
+ if (cs.visibility === 'hidden' || parseFloat(cs.opacity) < 0.05) return null;
235
+ const tag = el.tagName;
236
+ if (el !== canvas && (tag === 'IMG' || tag === 'VIDEO' || tag === 'PICTURE')) return tag.toLowerCase();
237
+ const bg = cs.backgroundImage || '';
238
+ if (/url\(/.test(bg)) return 'css';
239
+ if (el === canvas) return null; // its own background colour is under its pixels, not a picture
240
+ if (tag === 'CANVAS' || tag === 'IFRAME' || tag === 'svg' || bg !== 'none') return 'opaque';
241
+ const m = /rgba?\(([^)]+)\)/.exec(cs.backgroundColor || '');
242
+ if (!m) return null;
243
+ const parts = m[1].split(/[ ,/]+/).filter(Boolean).map(Number);
244
+ return (parts.length >= 4 ? parts[3] : 1) >= 0.9 ? 'opaque' : null;
245
+ };
246
+ try {
247
+ for (let j = 0; j < rows; j++) {
248
+ for (let i = 0; i < cols; i++) {
249
+ const x = r.left + ((i + 0.5) / cols) * r.width;
250
+ const y = r.top + ((j + 0.5) / rows) * r.height;
251
+ if (x < 0 || y < 0 || x >= innerWidth || y >= innerHeight) continue;
252
+ const list = document.elementsFromPoint(x, y);
253
+ const at = list.indexOf(canvas);
254
+ if (at < 0) continue;
255
+ total++;
256
+ for (let k = at; k < list.length; k++) {
257
+ const kind = paints(list[k]);
258
+ if (!kind) continue;
259
+ if (kind !== 'opaque') {
260
+ image++;
261
+ const s = selectorOf(list[k]) || list[k].tagName.toLowerCase();
262
+ const rec = sources.get(s) || { selector: s, kind, hits: 0 };
263
+ rec.hits++;
264
+ sources.set(s, rec);
265
+ }
266
+ break;
267
+ }
268
+ }
269
+ }
270
+ } finally {
271
+ style.remove();
272
+ }
273
+ return { total, imageFraction: total ? image / total : 0, sources: [...sources.values()].sort((a, b) => b.hits - a.hits) };
274
+ };
275
+
218
276
  // Media elements big enough to show a picture (for the "raw side-by-side shown flat" scan).
219
277
  P.mediaElements = function (exclude = []) {
220
278
  const out = [];
package/lib/check/run.mjs CHANGED
@@ -7,7 +7,7 @@ import { launchChrome, withTimeout } from './cdp.mjs';
7
7
  import { serveDir } from './server.mjs';
8
8
  import { decodePng } from './png.mjs';
9
9
  import {
10
- crop, halves, contentStats, regionDiff, compareEyes, blockDisparity, quantile, flatWideVerdict, sbsPairVerdict, shibataZoneMm, fromBase64Rgba, rigDepthUse,
10
+ crop, halves, contentStats, regionDiff, compareEyes, blockDisparity, quantile, flatWideVerdict, sbsPairVerdict, shibataZoneMm, fromBase64Rgba, rigDepthUse, backdropOnGlass,
11
11
  } from './analyze.mjs';
12
12
 
13
13
  const HERE = dirname(fileURLToPath(import.meta.url));
@@ -220,6 +220,7 @@ async function fakeRun(conn, url, opt, origin) {
220
220
  const buffer = await ev(page, `__dxrProbe.bufferInfo(__dxrCheck.layerCanvas(${l.index}))`).catch(() => null);
221
221
  const occlusion = await ev(page, `__dxrProbe.occlusionAudit(__dxrCheck.layerCanvas(${l.index}))`).catch(() => null);
222
222
  const css = await ev(page, `__dxrProbe.cssAudit(__dxrCheck.layerCanvas(${l.index}))`).catch(() => null);
223
+ const backdrop = await ev(page, `__dxrProbe.backdropAudit(__dxrCheck.layerCanvas(${l.index}))`).catch(() => null);
223
224
  const seen = cssSeen.get(l.index);
224
225
  if (css && seen) {
225
226
  for (const p of css.problems) seen.problems.set(`${p.element}|${p.prop}`, p);
@@ -229,7 +230,7 @@ async function fakeRun(conn, url, opt, origin) {
229
230
  const cssAll = seen
230
231
  ? { problems: [...seen.problems.values()], decorations: [...seen.decorations], animations: [...seen.animations.values()] }
231
232
  : css || { problems: [], decorations: [], animations: [] };
232
- layers.push({ ...l, snap, snapTries, buffer, occlusion, css: cssAll });
233
+ layers.push({ ...l, snap, snapTries, buffer, occlusion, backdrop, css: cssAll });
233
234
  }
234
235
  const shaderErrors = await ev(page, '__dxrProbe.shaderErrors').catch(() => []);
235
236
  const scrollY = await ev(page, 'window.scrollY').catch(() => 0);
@@ -757,7 +758,7 @@ function buildChecks(fake, plain, opt) {
757
758
  if (p05 < -zone.frontMm) warns.push(`pops out ${(-p05).toFixed(1)} mm (comfort zone ${zone.frontMm.toFixed(1)} mm in front)`);
758
759
  if (p95 > zone.behindMm) warns.push(`recedes ${p95.toFixed(1)} mm (comfort zone ${zone.behindMm.toFixed(1)} mm behind)`);
759
760
  const span = Math.max(1e-6, p95 - p05);
760
- if (Math.abs(p50) > Math.max(1.5, 0.6 * span) && (p05 > 0 || p95 < 0)) warns.push(`the subject sits entirely ${p50 > 0 ? 'behind' : 'in front of'} the glass (median ${p50.toFixed(1)} mm): centre it on z = 0`);
761
+ if (Math.abs(p50) > Math.max(1.5, 0.6 * span) && (p05 > 0 || p95 < 0)) warns.push(`the subject sits entirely ${p50 > 0 ? 'behind' : 'in front of'} the glass (median ${p50.toFixed(1)} mm): put the glass through it (about a quarter in front, the rest just behind)`);
761
762
  status = warns.length ? 'warn' : 'pass';
762
763
  summary = warns.length ? warns.join('; ') : `screen disparity ${p05.toFixed(1)} … ${p95.toFixed(1)} mm (median ${p50.toFixed(1)}), inside the comfort zone`;
763
764
  }
@@ -776,6 +777,20 @@ function buildChecks(fake, plain, opt) {
776
777
  doc: `${DOCS}/authoring-inline-3d.md#aim-for-real-depth`,
777
778
  }));
778
779
  }
780
+
781
+ // backdrop on the glass (rule 10): a page image showing through a see-through canvas, under
782
+ // content that reaches behind the glass. A report, never a limit.
783
+ {
784
+ const px = primary && primary.px;
785
+ const seeThrough = px ? 1 - (px.statsL.opaqueFraction + px.statsR.opaqueFraction) / 2 : null;
786
+ const r = backdropOnGlass(primary ? primary.backdrop : null, seeThrough, measuredMm, zone);
787
+ checks.push(check('backdrop-on-glass', '-', 'A backdrop sits behind the subject, never on the glass (a page image under a see-through canvas is on the glass)', r.status, r.summary, {
788
+ details: r.details,
789
+ hint: r.hint,
790
+ approximate: true,
791
+ doc: `${DOCS}/making-3d-look-right.md`,
792
+ }));
793
+ }
779
794
  return checks;
780
795
  }
781
796
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@displayxr/inline3d-tools",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Agent-agnostic tools for @displayxr/inline3d pages: a headless checker (fake DisplayXR Browser + plain 2D run), a glTF/GLB asset check, page scaffolds, optional asset generation with provenance, and a stdio MCP server exposing the same operations.",
5
5
  "type": "module",
6
6
  "bin": {
package/templates/app.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Display rig (the user turns a SUBJECT). Scene units are metres for a 0.24 m virtual display;
3
3
  // the subject straddles z = 0 (the glass). Replace buildScene() with your content.
4
4
  import * as THREE from 'three';
5
- import { createInline3D } from '@displayxr/inline3d';
5
+ import { createInline3D, sceneBufferSize } from '@displayxr/inline3d';
6
6
  import { EyeCamera } from '@displayxr/inline3d/three';
7
7
 
8
8
  const VIRTUAL_DISPLAY_HEIGHT = 0.24; // metres of virtual display the canvas shows
@@ -52,21 +52,19 @@ function animate(now) {
52
52
  subject.rotation.x = 0.35;
53
53
  }
54
54
 
55
- // ---- backing store: 2 x the box in 3D, 1 x in 2D; dpr <= 2; within the GPU's limits ---------
55
+ // ---- backing store: sceneBufferSize, never clientWidth x devicePixelRatio x 2 ----------------
56
+ // Per eye it gives window device px x the runtime's recommended view scale (once getDisplayInfo()
57
+ // has answered; devicePixelRatio <= 2 until then), fitted to the GL limits and the browser's
58
+ // drawing-buffer area cap. The view scale is the 3D mode's: never pass it for the flat 2D store.
59
+ // A hand-rolled store overflows that cap on a big panel: the browser
60
+ // shrinks the buffer silently, the eyes land off-centre and one eye shows both images.
61
+ let viewInfo = null;
56
62
  function sizeBuffer(stereo) {
57
- const r = canvas.getBoundingClientRect();
58
- const dpr = Math.min(window.devicePixelRatio || 1, 2);
59
- let w = Math.round(r.width * dpr * (stereo ? 2 : 1));
60
- let h = Math.round(r.height * dpr);
61
- const gl = renderer.getContext();
62
- const max = Math.min(gl.getParameter(gl.MAX_TEXTURE_SIZE), gl.getParameter(gl.MAX_RENDERBUFFER_SIZE), ...gl.getParameter(gl.MAX_VIEWPORT_DIMS));
63
- const k = Math.min(1, max / Math.max(w, h)); // one factor for both axes keeps the eyes' shape
64
- w = Math.max(2, Math.floor(w * k) & ~1);
65
- h = Math.max(1, Math.floor(h * k));
63
+ const s = sceneBufferSize(canvas, { sbs: stereo, viewScale: stereo ? viewInfo : null, gl: renderer.getContext() });
66
64
  // Writing width/height clears the buffer even when the value is the same: only on a change.
67
- if (canvas.width !== w || canvas.height !== h) {
68
- canvas.width = w;
69
- canvas.height = h;
65
+ if (canvas.width !== s.width || canvas.height !== s.height) {
66
+ canvas.width = s.width;
67
+ canvas.height = s.height;
70
68
  return true;
71
69
  }
72
70
  return false;
@@ -140,6 +138,10 @@ async function start() {
140
138
  onLayerLost: () => start2D('3D layer lost'),
141
139
  });
142
140
  statusEl.textContent = '3D on a Spatial Display';
141
+ handle.getDisplayInfo().then((info) => {
142
+ viewInfo = info;
143
+ if (sizeBuffer(true) && haveLast) drawEyes(lastGood);
144
+ }).catch(() => {});
143
145
  addEventListener('pagehide', () => wall.close());
144
146
  const result = await handle.firstWoven; // never rejects
145
147
  clearTimeout(coverTimer);
@@ -10,8 +10,8 @@
10
10
  { "imports": {
11
11
  "three": "https://cdn.jsdelivr.net/npm/three@0.180.0/build/three.module.js",
12
12
  "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.180.0/examples/jsm/",
13
- "@displayxr/inline3d": "https://cdn.jsdelivr.net/npm/@displayxr/inline3d@1.56.1/js/inline3d.js",
14
- "@displayxr/inline3d/three": "https://cdn.jsdelivr.net/npm/@displayxr/inline3d@1.56.1/js/inline3d-three.js"
13
+ "@displayxr/inline3d": "https://cdn.jsdelivr.net/npm/@displayxr/inline3d@1.58.0/js/inline3d.js",
14
+ "@displayxr/inline3d/three": "https://cdn.jsdelivr.net/npm/@displayxr/inline3d@1.58.0/js/inline3d-three.js"
15
15
  } }
16
16
  </script>
17
17
  </head>
@@ -9,7 +9,7 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
- "@displayxr/inline3d": "1.56.1",
12
+ "@displayxr/inline3d": "1.58.0",
13
13
  "three": "0.180.0"
14
14
  },
15
15
  "devDependencies": {