@fleox/agent3d 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/changelog.json +10 -0
- package/dist/agent/agent3d.mjs +30 -12
- package/dist/agent/chunks/{export-bJwh2SqG.mjs → export-CEX5DFLo.mjs} +79 -3
- package/dist/agent/chunks/{package-fMbw9UGh.mjs → package-DjRnLzcU.mjs} +2 -2
- package/dist/agent/chunks/{tools-Cm4BqDkO.mjs → tools-CZyIc4zw.mjs} +13 -3
- package/dist/runtime/agent3d-photo.js +31 -0
- package/dist/runtime/agent3d-runtime.js +41 -41
- package/dist/runtime/agent3d-runtime.single.js +251 -246
- package/dist/runtime/chunks/assets-kC2Z1Xy_.js +1 -0
- package/dist/runtime/chunks/game-CbQaEB4q.js +20 -0
- package/dist/runtime/chunks/materials-jwhXlLYl.js +107 -0
- package/dist/runtime/chunks/model-CG5T_jcB.js +1 -0
- package/dist/runtime/chunks/num-CQNAlL82.js +1 -0
- package/dist/runtime/chunks/{photo-DNf14X7B.js → photo-w6dwHX7j.js} +25 -20
- package/dist/runtime/chunks/physicsHost-BU-2V-CZ.js +1 -0
- package/dist/runtime/chunks/{postfx-Cbf_vvOr.js → postfx-DnIeKXAh.js} +1 -1
- package/dist/runtime/chunks/postfx-ylpcQcVK.js +1 -0
- package/dist/runtime/chunks/svg-fYjsY-rV.js +1 -0
- package/dist/runtime/chunks/{text-rSo_2Luk.js → text-CySfj5sH.js} +1 -1
- package/dist/runtime/chunks/util-BEflQURG.js +1 -0
- package/dist/studio/assets/assets--ehPZf8R.js +1 -0
- package/dist/studio/assets/camera-C0sxfRxy.js +2 -0
- package/dist/studio/assets/{editor-NkBUKsDB.js → editor-DzyukvQl.js} +1 -1
- package/dist/studio/assets/game-DNpTN_Ga.js +19 -0
- package/dist/studio/assets/{generators-BjIs-kHx.js → generators-BuVeRXnC.js} +5 -5
- package/dist/studio/assets/index-C2nMYSoW.js +479 -0
- package/dist/studio/assets/model-DQgOrTs4.js +2 -0
- package/dist/studio/assets/num-CQNAlL82.js +1 -0
- package/dist/studio/assets/{params-DhsDKSDs.js → params-D-Ul6GSt.js} +1 -1
- package/dist/studio/assets/{photo-DAHd1yNF.js → photo-Dx2IBJ11.js} +25 -20
- package/dist/studio/assets/physicsHost-z9qn_mpg.js +1 -0
- package/dist/studio/assets/{postfx-BGu30OJK.js → postfx-B3jDEaEK.js} +13 -13
- package/dist/studio/assets/runtime-rd9RW3WH.js +572 -0
- package/dist/studio/assets/{shaders-Dt6FGXH_.js → shaders-bFhELLmD.js} +1 -1
- package/dist/studio/assets/svg-BkV9LeqP.js +2 -0
- package/dist/studio/assets/{text-B-HM422i.js → text-Dp8gdjSA.js} +1 -1
- package/dist/studio/index.html +1 -1
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/skills/agent3d-assets/SKILL.md +26 -26
- package/plugin/skills/agent3d-create/SKILL.md +26 -26
- package/plugin/skills/agent3d-create/references/art-direction.md +3 -3
- package/plugin/skills/agent3d-create/references/recipes.md +6 -6
- package/plugin/skills/agent3d-edit/SKILL.md +22 -22
- package/plugin/skills/agent3d-edit/references/patch-ops.md +2 -2
- package/plugin/skills/agent3d-game/SKILL.md +7 -7
- package/plugin/skills/agent3d-publish/SKILL.md +24 -22
- package/plugin/skills/agent3d-publish/references/integrations.md +1 -1
- package/dist/runtime/chunks/assets-qnxDnVkj.js +0 -1
- package/dist/runtime/chunks/game-BoEiyZrL.js +0 -20
- package/dist/runtime/chunks/materials-dC4vDNHh.js +0 -107
- package/dist/runtime/chunks/model-BCAl_NRl.js +0 -1
- package/dist/runtime/chunks/physicsHost-ChPgysMQ.js +0 -1
- package/dist/runtime/chunks/postfx-CFucYRev.js +0 -1
- package/dist/runtime/chunks/svg-CLUxY6Zy.js +0 -1
- package/dist/runtime/chunks/util-CyaW1fcW.js +0 -1
- package/dist/studio/assets/assets-BW5lQkYR.js +0 -1
- package/dist/studio/assets/camera-BgzPVnn-.js +0 -2
- package/dist/studio/assets/game-DARpu0ah.js +0 -19
- package/dist/studio/assets/index-L-N-e2KM.js +0 -479
- package/dist/studio/assets/model-CqI8j03Z.js +0 -2
- package/dist/studio/assets/physicsHost-tEUto2-_.js +0 -1
- package/dist/studio/assets/runtime-C_qkIpAK.js +0 -572
- package/dist/studio/assets/svg-ZZt5MdNf.js +0 -2
package/README.md
CHANGED
|
@@ -109,19 +109,19 @@ Once the scene exists, changing it is a conversation:
|
|
|
109
109
|
### Without an agent
|
|
110
110
|
|
|
111
111
|
```bash
|
|
112
|
-
npx -y @fleox/agent3d@0.
|
|
113
|
-
npx -y @fleox/agent3d@0.
|
|
112
|
+
npx -y @fleox/agent3d@0.4.0 new bakery --target banner --title "Golden Crust"
|
|
113
|
+
npx -y @fleox/agent3d@0.4.0 studio --project bakery
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
The first command creates a project folder with an attractive starter scene for its target (banner, hero, card, square, fullscreen, inline or game); add `--template <id>` to start from one of the [templates](#templates). The second opens the [Studio](#the-studio) on it. You need **Node.js 22+** and **Google Chrome** (or Chromium / Edge / Brave) for renders; `npx -y @fleox/agent3d@0.
|
|
116
|
+
The first command creates a project folder with an attractive starter scene for its target (banner, hero, card, square, fullscreen, inline or game); add `--template <id>` to start from one of the [templates](#templates). The second opens the [Studio](#the-studio) on it. You need **Node.js 22+** and **Google Chrome** (or Chromium / Edge / Brave) for renders; `npx -y @fleox/agent3d@0.4.0 doctor` checks your setup with a test render.
|
|
117
117
|
|
|
118
118
|
The whole loop from a terminal:
|
|
119
119
|
|
|
120
120
|
```bash
|
|
121
|
-
npx -y @fleox/agent3d@0.
|
|
122
|
-
npx -y @fleox/agent3d@0.
|
|
123
|
-
npx -y @fleox/agent3d@0.
|
|
124
|
-
npx -y @fleox/agent3d@0.
|
|
121
|
+
npx -y @fleox/agent3d@0.4.0 scene patch --project bakery '[{"op":"set","path":"objects#title.material","value":{"preset":"gold"}}]'
|
|
122
|
+
npx -y @fleox/agent3d@0.4.0 render --project bakery --sheet # → renders/…-sheet.png
|
|
123
|
+
npx -y @fleox/agent3d@0.4.0 check --project bakery
|
|
124
|
+
npx -y @fleox/agent3d@0.4.0 export --project bakery # → dist/embed/ + the snippet
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
Step by step: [docs/getting-started.md](https://github.com/fleox/agent3d/blob/main/docs/getting-started.md).
|
|
@@ -171,7 +171,7 @@ Step by step: [docs/getting-started.md](https://github.com/fleox/agent3d/blob/ma
|
|
|
171
171
|
- 22 procedural **generators**: terrain (mountains, basins, valleys, islands), trees, rocks, grass, flowers, water with mirror reflections, clouds, birds, cities, roads, floating islands, globes, galaxies, crystals, 3D bar charts, mazes… deterministic from a seed
|
|
172
172
|
- A procedural **character** generator (humanoid, astronaut, robot, blob, cat, fox, bird, ghost) with animations such as wave, run, jump, dance and celebrate
|
|
173
173
|
- A built-in **library** of 179 assets usable offline (`library:<id>`): 128 models (rigged characters with clips, products, props), PBR textures and HDRIs; optional search and download from free CC0 sources (Poly Haven, ambientCG, Khronos samples) and Kenney / Quaternius pack import, with licences recorded
|
|
174
|
-
- **3D photos**: any photo plus a depth map estimated on your machine (`assets depth`: Depth Anything V2 Small, a 27 MB model downloaded once, then offline) moves in depth with the pointer, the phone's gyroscope, the scroll or a gentle automatic drift — shader parallax, a displaced mesh or pop-up layers
|
|
174
|
+
- **3D photos**: any photo plus a depth map estimated on your machine (`assets depth`: Depth Anything V2 Small, a 27 MB model downloaded once, then offline) moves in depth with the pointer, the phone's gyroscope, the scroll or a gentle automatic drift — shader parallax, a displaced mesh or pop-up layers; a photo-only hero exports with a 14 KB player instead of three.js
|
|
175
175
|
- 3D text in 13 kerned **fonts** with wrapping, outlines and letter-by-letter reveals; extruded **SVG logos** that keep their colours; 17 particle presets; 12 synth sounds
|
|
176
176
|
|
|
177
177
|
**Games**
|
|
@@ -194,7 +194,7 @@ Step by step: [docs/getting-started.md](https://github.com/fleox/agent3d/blob/ma
|
|
|
194
194
|
A visual editor for when you want to see and touch the scene yourself, on the same files and the same validated tools as the agent. Changes your agent makes in a terminal appear live in the open Studio.
|
|
195
195
|
|
|
196
196
|
```bash
|
|
197
|
-
npx -y @fleox/agent3d@0.
|
|
197
|
+
npx -y @fleox/agent3d@0.4.0 studio --project bakery
|
|
198
198
|
```
|
|
199
199
|
|
|
200
200
|
<p align="center">
|
|
@@ -323,7 +323,7 @@ Pick Spline when a designer wants a hosted visual tool, hand-written Three.js wh
|
|
|
323
323
|
|
|
324
324
|
## The `agent3d` CLI
|
|
325
325
|
|
|
326
|
-
The same engine the agents use, by hand: `npx -y @fleox/agent3d@0.
|
|
326
|
+
The same engine the agents use, by hand: `npx -y @fleox/agent3d@0.4.0 help`. Every command accepts `--json` and prints exactly one `{ ok, data }` or `{ ok: false, error }` object with an actionable hint, and commands that replace or overwrite something print a plan until you add `--yes`.
|
|
327
327
|
|
|
328
328
|
<p align="center">
|
|
329
329
|
<img src="https://raw.githubusercontent.com/fleox/agent3d/main/.github/assets/demo-cli.gif" width="820" alt="Terminal running the agent3d CLI: a project from the gradient-blob template, its scene summary, a gold torus added, a behaviour patch rejected with an actionable error then fixed, and the pre-export check">
|
|
@@ -361,7 +361,7 @@ Full reference: [docs/cli.md](https://github.com/fleox/agent3d/blob/main/docs/cl
|
|
|
361
361
|
## MCP server
|
|
362
362
|
|
|
363
363
|
```bash
|
|
364
|
-
claude mcp add agent3d -- npx -y @fleox/agent3d@0.
|
|
364
|
+
claude mcp add agent3d -- npx -y @fleox/agent3d@0.4.0 mcp --project ~/agent3d/my-banner
|
|
365
365
|
```
|
|
366
366
|
|
|
367
367
|
<p align="center">
|
package/changelog.json
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"versions": [
|
|
3
|
+
{
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"date": "2026-11-26",
|
|
6
|
+
"breaking": false,
|
|
7
|
+
"changes": [
|
|
8
|
+
"Photo-only exports load a 14 KB player instead of three.js: when the scene is a single 3D photo in parallax mode (no text, effects, timeline…), `export` ships `agent3d-photo.js` (raw WebGL2, the same `<agent3d-scene>` element, same pixels) — the landscape demo's runtime JavaScript went from ~242 KB to ~14 KB gzip. `export --runtime full` (and the `export` tool's `runtime`) keeps the full runtime; the result reports `runtime: \"photo-lite\" | \"full\"` and, when full, why.",
|
|
9
|
+
"A page that also shows a scene the photo player cannot render loads the full runtime for that element automatically."
|
|
10
|
+
],
|
|
11
|
+
"actions": []
|
|
12
|
+
},
|
|
3
13
|
{
|
|
4
14
|
"version": "0.3.1",
|
|
5
15
|
"date": "2026-11-26",
|
package/dist/agent/agent3d.mjs
CHANGED
|
@@ -6,7 +6,7 @@ __a3dRequire(import.meta.url);
|
|
|
6
6
|
const __filename = __a3dPath(import.meta.url);
|
|
7
7
|
__a3dDirname(__filename);
|
|
8
8
|
import { t as __exportAll } from "./chunks/rolldown-runtime-ebOQtxsr.mjs";
|
|
9
|
-
import { r as version, t as package_default } from "./chunks/package-
|
|
9
|
+
import { r as version, t as package_default } from "./chunks/package-DjRnLzcU.mjs";
|
|
10
10
|
import { n as didYouMean, r as listOptions, t as closest } from "./chunks/suggest-Cpcgv1RP.mjs";
|
|
11
11
|
import { format, parseArgs } from "node:util";
|
|
12
12
|
import { createReadStream, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
@@ -3623,6 +3623,14 @@ function libraryId(ref) {
|
|
|
3623
3623
|
function findLibraryAsset(index, id) {
|
|
3624
3624
|
return index?.assets.find((a) => a.id === id);
|
|
3625
3625
|
}
|
|
3626
|
+
// src/core/qualityTier.ts
|
|
3627
|
+
/** Upper bound of the device pixel ratio per tier (combined with target.maxDpr). */
|
|
3628
|
+
var TIER_DPR_CAP = {
|
|
3629
|
+
low: 1,
|
|
3630
|
+
medium: 1.5,
|
|
3631
|
+
high: 2,
|
|
3632
|
+
ultra: 3
|
|
3633
|
+
};
|
|
3626
3634
|
// src/core/postfx.ts
|
|
3627
3635
|
var SCALED = /* @__PURE__ */ new Set([
|
|
3628
3636
|
"strength",
|
|
@@ -3692,7 +3700,7 @@ function qualitySettings(tier) {
|
|
|
3692
3700
|
switch (tier) {
|
|
3693
3701
|
case "low": return {
|
|
3694
3702
|
tier,
|
|
3695
|
-
dprCap:
|
|
3703
|
+
dprCap: TIER_DPR_CAP.low,
|
|
3696
3704
|
msaa: 0,
|
|
3697
3705
|
effectScale: .5,
|
|
3698
3706
|
maxCost: "medium",
|
|
@@ -3703,7 +3711,7 @@ function qualitySettings(tier) {
|
|
|
3703
3711
|
};
|
|
3704
3712
|
case "medium": return {
|
|
3705
3713
|
tier,
|
|
3706
|
-
dprCap:
|
|
3714
|
+
dprCap: TIER_DPR_CAP.medium,
|
|
3707
3715
|
msaa: 4,
|
|
3708
3716
|
effectScale: .5,
|
|
3709
3717
|
maxCost: "high",
|
|
@@ -3714,7 +3722,7 @@ function qualitySettings(tier) {
|
|
|
3714
3722
|
};
|
|
3715
3723
|
case "ultra": return {
|
|
3716
3724
|
tier,
|
|
3717
|
-
dprCap:
|
|
3725
|
+
dprCap: TIER_DPR_CAP.ultra,
|
|
3718
3726
|
msaa: 8,
|
|
3719
3727
|
effectScale: 1,
|
|
3720
3728
|
maxCost: "high",
|
|
@@ -3725,7 +3733,7 @@ function qualitySettings(tier) {
|
|
|
3725
3733
|
};
|
|
3726
3734
|
default: return {
|
|
3727
3735
|
tier: "high",
|
|
3728
|
-
dprCap:
|
|
3736
|
+
dprCap: TIER_DPR_CAP.high,
|
|
3729
3737
|
msaa: 4,
|
|
3730
3738
|
effectScale: .5,
|
|
3731
3739
|
maxCost: "high",
|
|
@@ -7905,7 +7913,7 @@ function readRuntimeFiles(format = "embed") {
|
|
|
7905
7913
|
const files = {};
|
|
7906
7914
|
for (const f of walkFiles(root)) {
|
|
7907
7915
|
if (f.endsWith(".map")) continue;
|
|
7908
|
-
if (format === "single-html" ? f === "agent3d-runtime.single.js" : f !== "agent3d-runtime.single.js" && f !== "version.json") files[f] = new Uint8Array(readFileSync(join(root, f)));
|
|
7916
|
+
if (format === "single-html" ? f === "agent3d-runtime.single.js" || f === "agent3d-photo.js" : f !== "agent3d-runtime.single.js" && f !== "version.json") files[f] = new Uint8Array(readFileSync(join(root, f)));
|
|
7909
7917
|
}
|
|
7910
7918
|
if (format === "single-html" && !files["agent3d-runtime.single.js"]) throw new CliError("runtime-missing", `The single-file runtime is missing (${join(root, RUNTIME_SINGLE)}).`, "Run `npm run build:runtime` (it builds both runtimes), or export --format embed.");
|
|
7911
7919
|
return files;
|
|
@@ -9452,7 +9460,7 @@ function dirNonEmpty(dir) {
|
|
|
9452
9460
|
}
|
|
9453
9461
|
var exportCommand = {
|
|
9454
9462
|
name: "export",
|
|
9455
|
-
usage: "export [--format embed|zip|single-html|poster|video|gif] [--out <path>] [--name <slug>] [--base-url <url>] [--cache-bust] [--no-integrity] [--no-poster] [--no-og] [--prune-runtime] [--yes] [--project <dir>]",
|
|
9463
|
+
usage: "export [--format embed|zip|single-html|poster|video|gif] [--out <path>] [--name <slug>] [--base-url <url>] [--cache-bust] [--no-integrity] [--no-poster] [--no-og] [--prune-runtime] [--runtime auto|full] [--yes] [--project <dir>]",
|
|
9456
9464
|
summary: "Export for a website: embed (Web Component + static files + EMBED.md + React/Vue/Svelte wrappers, default), zip (the embed folder as one .zip), single-html (one file), poster (still image), video (MP4 H.264 / WebM VP9) or gif. Reports pageKb / pageKbGzip (what a visitor downloads for this scene: runtime entry + the chunks it loads + scene, assets, scripts, poster) and folderKb (every file written). Overwriting a non-empty --out needs --yes.",
|
|
9457
9465
|
writes: true,
|
|
9458
9466
|
options: [
|
|
@@ -9502,6 +9510,11 @@ var exportCommand = {
|
|
|
9502
9510
|
type: "boolean",
|
|
9503
9511
|
description: "embed / zip: copy only the runtime chunks this scene loads (smaller folder). Only for a runtime folder used by this scene alone — other scenes sharing it may need the left-out chunks; kept whole when a chunk's feature is unknown."
|
|
9504
9512
|
},
|
|
9513
|
+
{
|
|
9514
|
+
name: "runtime",
|
|
9515
|
+
type: "string",
|
|
9516
|
+
description: "embed / zip / single-html: auto (default) ships the photo-only lite runtime (agent3d-photo.js, ~14 KB gzipped, no three.js) when the scene is a single 3D photo with a fixed camera and a plain background; full always ships agent3d-runtime.js. The result's runtime / runtimeReasons say which and why."
|
|
9517
|
+
},
|
|
9505
9518
|
{
|
|
9506
9519
|
name: "no-og",
|
|
9507
9520
|
type: "boolean",
|
|
@@ -9649,9 +9662,11 @@ var exportCommand = {
|
|
|
9649
9662
|
const err = e;
|
|
9650
9663
|
warnings.push(`No poster: ${err.message}${err.hint ? ` (${err.hint})` : ""} — the export works without it (no image before load / without WebGL).`);
|
|
9651
9664
|
}
|
|
9665
|
+
const runtimeChoice = strOpt(options, "runtime") ?? "auto";
|
|
9666
|
+
if (runtimeChoice !== "auto" && runtimeChoice !== "full") usage(`Unknown --runtime "${runtimeChoice}".`, "Use auto (default: the photo-only lite runtime for single-3D-photo scenes) or full.");
|
|
9652
9667
|
const runtime = { files: readRuntimeFiles(format) };
|
|
9653
|
-
const { buildExport } = await import("./chunks/export-
|
|
9654
|
-
const { version } = (await import("./chunks/package-
|
|
9668
|
+
const { buildExport } = await import("./chunks/export-CEX5DFLo.mjs").then((n) => n.n);
|
|
9669
|
+
const { version } = (await import("./chunks/package-DjRnLzcU.mjs").then((n) => n.n)).default;
|
|
9655
9670
|
let exportFs = fs;
|
|
9656
9671
|
let exportLibrary = libraryProvider();
|
|
9657
9672
|
let optimizeReport;
|
|
@@ -9682,6 +9697,7 @@ var exportCommand = {
|
|
|
9682
9697
|
integrity: !boolOpt(options, "no-integrity"),
|
|
9683
9698
|
extras: !boolOpt(options, "no-extras"),
|
|
9684
9699
|
pruneRuntime: boolOpt(options, "prune-runtime"),
|
|
9700
|
+
runtimeChoice,
|
|
9685
9701
|
version
|
|
9686
9702
|
}).finally(() => closeCodec?.());
|
|
9687
9703
|
const optimized = optimizeReport?.();
|
|
@@ -9707,6 +9723,8 @@ var exportCommand = {
|
|
|
9707
9723
|
totalKb: r.totalKb,
|
|
9708
9724
|
sizes: r.sizes,
|
|
9709
9725
|
page: r.page,
|
|
9726
|
+
runtime: r.runtime,
|
|
9727
|
+
...r.runtimeReasons ? { runtimeReasons: r.runtimeReasons } : {},
|
|
9710
9728
|
...optimized ? { optimized } : {},
|
|
9711
9729
|
credits: r.credits,
|
|
9712
9730
|
issues: r.issues,
|
|
@@ -9714,7 +9732,7 @@ var exportCommand = {
|
|
|
9714
9732
|
...warnings.length ? { warnings } : {}
|
|
9715
9733
|
}, () => [
|
|
9716
9734
|
`Exported ${format} → ${out} (folder ${r.folderKb} KB, ${written.length} files)`,
|
|
9717
|
-
`Page weight: ${r.pageKb} KB${r.pageKbGzip !== void 0 ? ` (${r.pageKbGzip} KB gzipped)` : ""} — runtime ${r.page.runtimeKb} KB (${r.page.runtimeFiles.length} files; ${r.page.skippedChunks.length} lazy chunks this scene never loads${r.page.pruned ? ", left out" : ""}) + scene, assets, scripts, poster.`,
|
|
9735
|
+
r.runtime === "photo-lite" ? `Page weight: ${r.pageKb} KB${r.pageKbGzip !== void 0 ? ` (${r.pageKbGzip} KB gzipped)` : ""} — photo-only lite runtime ${r.page.runtimeKb} KB (agent3d-photo.js, no three.js) + scene, assets, poster.` : `Page weight: ${r.pageKb} KB${r.pageKbGzip !== void 0 ? ` (${r.pageKbGzip} KB gzipped)` : ""} — runtime ${r.page.runtimeKb} KB (${r.page.runtimeFiles.length} files; ${r.page.skippedChunks.length} lazy chunks this scene never loads${r.page.pruned ? ", left out" : ""}) + scene, assets, scripts, poster.`,
|
|
9718
9736
|
`Open: ${entry}`,
|
|
9719
9737
|
...optimized ? [`Optimised asset copies: ${optimized.beforeKb} → ${optimized.afterKb} KB (saved ${optimized.savedKb} KB; the project is unchanged).`] : [],
|
|
9720
9738
|
...format === "zip" ? [] : [
|
|
@@ -10432,7 +10450,7 @@ function toolContext(fs) {
|
|
|
10432
10450
|
};
|
|
10433
10451
|
}
|
|
10434
10452
|
async function listTools(opts = {}) {
|
|
10435
|
-
const { listAiTools } = await import("./chunks/tools-
|
|
10453
|
+
const { listAiTools } = await import("./chunks/tools-CZyIc4zw.mjs");
|
|
10436
10454
|
const host = nodeHost(null);
|
|
10437
10455
|
return listAiTools(opts.render === false ? host : {
|
|
10438
10456
|
...host,
|
|
@@ -10445,7 +10463,7 @@ async function listTools(opts = {}) {
|
|
|
10445
10463
|
}));
|
|
10446
10464
|
}
|
|
10447
10465
|
async function callTool(fs, name, input) {
|
|
10448
|
-
const { callAiTool } = await import("./chunks/tools-
|
|
10466
|
+
const { callAiTool } = await import("./chunks/tools-CZyIc4zw.mjs");
|
|
10449
10467
|
return callAiTool(toolContext(fs), name, input);
|
|
10450
10468
|
}
|
|
10451
10469
|
function previewImages(name, result, root = ".") {
|
|
@@ -47,6 +47,69 @@ function base64Encode(bytes) {
|
|
|
47
47
|
function dataUri(bytes, mime) {
|
|
48
48
|
return `data:${mime};base64,${base64Encode(bytes)}`;
|
|
49
49
|
}
|
|
50
|
+
// src/ops/liteRuntime.ts
|
|
51
|
+
var LITE_RUNTIME_FILE = "agent3d-photo.js";
|
|
52
|
+
var HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
53
|
+
var nonEmpty = (v) => Array.isArray(v) ? v.length > 0 : v !== void 0 && v !== null && v !== false;
|
|
54
|
+
function liteRuntimeEligibility(scene) {
|
|
55
|
+
const reasons = [];
|
|
56
|
+
const no = (cond, why) => {
|
|
57
|
+
if (cond) reasons.push(why);
|
|
58
|
+
};
|
|
59
|
+
const s = scene ?? {};
|
|
60
|
+
no((s.target ?? {}).kind === "game", "target.kind is game");
|
|
61
|
+
no(nonEmpty(s.timeline), "timeline");
|
|
62
|
+
no(nonEmpty(s.interactions), "interactions");
|
|
63
|
+
no(nonEmpty(s.postfx), "post effects (postfx)");
|
|
64
|
+
no(nonEmpty(s.physics), "physics");
|
|
65
|
+
no(nonEmpty(s.scripts), "scripts");
|
|
66
|
+
no(s.ui?.elements?.length, "ui (HUD)");
|
|
67
|
+
no(nonEmpty(s.audio), "audio");
|
|
68
|
+
no(/\{data\./.test(JSON.stringify(scene ?? {})), "data bindings ({data.*} placeholders)");
|
|
69
|
+
const cam = s.camera;
|
|
70
|
+
if (!cam || cam.type !== "perspective") reasons.push("camera is not perspective");
|
|
71
|
+
else {
|
|
72
|
+
no(cam.controls && cam.controls !== "none", `camera.controls "${cam.controls}"`);
|
|
73
|
+
no(cam.autoRotate, "camera.autoRotate");
|
|
74
|
+
no(nonEmpty(cam.shots), "camera.shots");
|
|
75
|
+
no(cam.shake, "camera.shake");
|
|
76
|
+
no(cam.lookAt, "camera.lookAt");
|
|
77
|
+
no(cam.follow, "camera.follow");
|
|
78
|
+
}
|
|
79
|
+
const env = s.environment;
|
|
80
|
+
const bg = env?.background;
|
|
81
|
+
no(bg !== void 0 && (typeof bg !== "string" || bg !== "transparent" && !HEX.test(bg)), "environment.background is not a #hex colour or transparent");
|
|
82
|
+
no(env?.ground, "environment.ground");
|
|
83
|
+
no(env?.contactShadows, "environment.contactShadows");
|
|
84
|
+
no(env?.rig, "environment.rig (light rig)");
|
|
85
|
+
for (const l of s.lights ?? []) {
|
|
86
|
+
no(l.type === "rect", "rect lights (visible panels)");
|
|
87
|
+
no(l.type === "spot" && l.volumetric, "volumetric spot lights");
|
|
88
|
+
}
|
|
89
|
+
const objects = s.objects ?? [];
|
|
90
|
+
if (objects.length !== 1) reasons.push(`${objects.length} objects (the lite runtime shows exactly one photo)`);
|
|
91
|
+
const o = objects[0];
|
|
92
|
+
if (o && o.kind !== "photo") reasons.push(`object "${o.id}" is a ${o.kind}, not a photo`);
|
|
93
|
+
else if (o) {
|
|
94
|
+
const p = o;
|
|
95
|
+
no(!!p.depth && p.mode && p.mode !== "parallax", `photo mode "${p.mode}" (lite: parallax or a flat photo)`);
|
|
96
|
+
no(nonEmpty(p.children), "photo has children");
|
|
97
|
+
no(p.visible === false, "photo is hidden");
|
|
98
|
+
no(nonEmpty(p.behaviours), "photo behaviours");
|
|
99
|
+
no(p.body, "photo physics body");
|
|
100
|
+
no(p.href, "photo link (href)");
|
|
101
|
+
no(p.attach, "photo attached to the camera");
|
|
102
|
+
no(Array.isArray(p.rotation) && p.rotation.some((r) => r !== 0), "photo is rotated");
|
|
103
|
+
const sc = p.scale;
|
|
104
|
+
no(sc !== void 0 && (typeof sc === "number" ? !(sc > 0) : !Array.isArray(sc) || !(sc[0] > 0 && sc[1] > 0)), "photo scale is not positive");
|
|
105
|
+
no(p.material?.color !== void 0 && !(typeof p.material.color === "string" && HEX.test(p.material.color)), "photo material.color is not a #hex colour");
|
|
106
|
+
no(typeof p.src !== "string" || !p.src, "photo has no src");
|
|
107
|
+
}
|
|
108
|
+
return reasons.length ? {
|
|
109
|
+
ok: false,
|
|
110
|
+
reasons
|
|
111
|
+
} : { ok: true };
|
|
112
|
+
}
|
|
50
113
|
// src/ops/runtimeChunks.ts
|
|
51
114
|
var hasKind = (scene, kinds) => {
|
|
52
115
|
const walk = (objs) => !!objs?.some((o) => kinds.includes(o.kind) || walk(o.children));
|
|
@@ -223,7 +286,7 @@ function pageRuntime(files, entry, scene) {
|
|
|
223
286
|
}
|
|
224
287
|
}
|
|
225
288
|
}
|
|
226
|
-
const js = Object.keys(files).filter((f) => f.endsWith(".js") && !f.endsWith(".single.js"));
|
|
289
|
+
const js = Object.keys(files).filter((f) => f.endsWith(".js") && !f.endsWith(".single.js") && f !== "agent3d-photo.js");
|
|
227
290
|
return {
|
|
228
291
|
loaded: [...loaded],
|
|
229
292
|
skipped: js.filter((f) => !loaded.has(f)),
|
|
@@ -756,7 +819,13 @@ async function buildExport(fs, opts) {
|
|
|
756
819
|
if (hasErrors(issues)) throw validationError("Cannot export an invalid scene:", issues, "Run check / scene_validate and fix the errors first.");
|
|
757
820
|
const projectManifest = await readJsonOr(fs, MANIFEST_FILE, null);
|
|
758
821
|
const name = slugify(opts.name ?? projectManifest?.name ?? source.id ?? "scene", "scene");
|
|
759
|
-
const
|
|
822
|
+
const choice = opts.runtimeChoice ?? "auto";
|
|
823
|
+
if (choice !== "auto" && choice !== "full") throw new OpsError("invalid", `Unknown runtime "${String(choice)}".`, "Use \"auto\" (the photo-only lite runtime when the scene is a single 3D photo) or \"full\".");
|
|
824
|
+
const eligibility = liteRuntimeEligibility(source);
|
|
825
|
+
const hasLite = !!opts.runtime?.files?.[LITE_RUNTIME_FILE];
|
|
826
|
+
const runtimeReasons = choice === "full" ? ["runtime: full was requested"] : !eligibility.ok ? eligibility.reasons : !hasLite ? [`the runtime files have no ${LITE_RUNTIME_FILE} (rebuild the runtime: npm run build:runtime)`] : void 0;
|
|
827
|
+
const lite = !runtimeReasons;
|
|
828
|
+
const runtimeEntry = lite ? LITE_RUNTIME_FILE : pickRuntime(opts.runtime, format === "single-html" ? "single-html" : "embed");
|
|
760
829
|
const manifest = await readAssetManifest(fs);
|
|
761
830
|
const entries = new Map(manifest.assets.map((a) => [a.path, a]));
|
|
762
831
|
const scene = clone(source);
|
|
@@ -849,7 +918,12 @@ async function buildExport(fs, opts) {
|
|
|
849
918
|
let head;
|
|
850
919
|
if (format === "embed" || format === "zip") {
|
|
851
920
|
const allRuntime = Object.entries(opts.runtime.files).filter(([k]) => !k.endsWith(".single.js"));
|
|
852
|
-
pageRt =
|
|
921
|
+
pageRt = lite ? {
|
|
922
|
+
loaded: [LITE_RUNTIME_FILE],
|
|
923
|
+
skipped: [],
|
|
924
|
+
unknown: [],
|
|
925
|
+
features: {}
|
|
926
|
+
} : pageRuntime(Object.fromEntries(allRuntime.filter(([k]) => k !== LITE_RUNTIME_FILE)), runtimeEntry, scene);
|
|
853
927
|
pruned = !!opts.pruneRuntime && !pageRt.unknown.length;
|
|
854
928
|
if (opts.pruneRuntime && pageRt.unknown.length) outIssues.push({
|
|
855
929
|
severity: "info",
|
|
@@ -1032,6 +1106,8 @@ async function buildExport(fs, opts) {
|
|
|
1032
1106
|
},
|
|
1033
1107
|
credits,
|
|
1034
1108
|
issues: outIssues,
|
|
1109
|
+
runtime: lite ? "photo-lite" : "full",
|
|
1110
|
+
...runtimeReasons ? { runtimeReasons } : {},
|
|
1035
1111
|
...runtimeDirName ? { runtimeDir: runtimeDirName } : {},
|
|
1036
1112
|
...integrity ? { integrity } : {},
|
|
1037
1113
|
...head ? { head } : {}
|
|
@@ -8,7 +8,7 @@ import { t as __exportAll } from "./rolldown-runtime-ebOQtxsr.mjs";
|
|
|
8
8
|
// package.json
|
|
9
9
|
var package_exports = /* @__PURE__ */ __exportAll({ default: () => package_default });
|
|
10
10
|
var name = "@fleox/agent3d";
|
|
11
|
-
var version = "0.
|
|
11
|
+
var version = "0.4.0";
|
|
12
12
|
var package_default = {
|
|
13
13
|
name,
|
|
14
14
|
version,
|
|
@@ -33,7 +33,7 @@ var package_default = {
|
|
|
33
33
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.agent.json",
|
|
34
34
|
"test": "vitest run",
|
|
35
35
|
"test:watch": "vitest",
|
|
36
|
-
"build:runtime": "vite build --config vite.runtime.config.ts && vite build --config vite.runtime.config.ts --mode single",
|
|
36
|
+
"build:runtime": "vite build --config vite.runtime.config.ts && vite build --config vite.runtime.config.ts --mode single && vite build --config vite.runtime.config.ts --mode photo",
|
|
37
37
|
"build:studio": "vite build",
|
|
38
38
|
"build:agent": "vite build --config vite.agent.config.ts",
|
|
39
39
|
"build": "npm run build:runtime && npm run build:studio && npm run build:agent && node scripts/write-version.mjs",
|
|
@@ -9,7 +9,7 @@ import { t as closest } from "./suggest-Cpcgv1RP.mjs";
|
|
|
9
9
|
import { a as listAssets, f as optimizedExportSources, i as importAssetZip, l as searchAssetsDetailed, o as listLibrary, p as SOURCE_IDS, r as downloadAsset, s as parseResolution, t as addAsset, u as optimizeAssets } from "./assets-YBkgdfgy.mjs";
|
|
10
10
|
import { r as modelFileBounds } from "./gltf-f_f0-OiV.mjs";
|
|
11
11
|
import { a as estimateDepth, n as checkDepthRequest } from "./depth-BZT4gseQ.mjs";
|
|
12
|
-
import { r as prefixFiles, t as buildExport } from "./export-
|
|
12
|
+
import { r as prefixFiles, t as buildExport } from "./export-CEX5DFLo.mjs";
|
|
13
13
|
import { i as getAt, t as PathError } from "./jsonPath-DUCe1JpS.mjs";
|
|
14
14
|
import { n as checkProject } from "./check-DP9fRYbK.mjs";
|
|
15
15
|
import { a as updateObject, i as removeObject, n as listObjects, t as addObject } from "./objects-DuytRxiC.mjs";
|
|
@@ -1073,7 +1073,7 @@ var ASSET_TOOLS = [
|
|
|
1073
1073
|
},
|
|
1074
1074
|
{
|
|
1075
1075
|
name: "export",
|
|
1076
|
-
description: "Build the self-contained embed and write it into the project (default dist/<format>/). \"embed\": a folder for any static site — agent3d-runtime/ (shared), <name>/scene.json + assets + scripts, index.html (demo page), snippet.html (paste into the page), EMBED.md and frameworks/ (React / Vue / Svelte wrappers). \"zip\": the same folder as one <name>-embed.zip. \"single-html\": one <name>.html with everything inline. Library assets are copied; nothing is hotlinked. Options: `baseUrl` (where the folder is served, so the snippet works from any page), `cacheBust` (versioned runtime folder + ?v= hash for long-term caching), `integrity` (SRI hash on the runtime script, default true), `optimize` (export lighter copies of the assets — the project is not modified), `og` (render a 1200×630 og-image.png social preview). Run check first; returns the snippet, sizes and budget warnings. When the host can render (CLI / MCP / Studio with Chrome): \"poster\" writes a still image (dist/poster.webp; `time`, `image`), \"video\" an MP4 / WebM (dist/video.webm; `codec`, `duration`, `fps`, `size`), \"gif\" / \"animated-webp\" an animated image (dist/animation.gif / .webp), returning { path } — `quality` supersamples, `transparent` keeps the alpha (poster, gif, animated-webp).",
|
|
1076
|
+
description: "Build the self-contained embed and write it into the project (default dist/<format>/). \"embed\": a folder for any static site — agent3d-runtime/ (shared), <name>/scene.json + assets + scripts, index.html (demo page), snippet.html (paste into the page), EMBED.md and frameworks/ (React / Vue / Svelte wrappers). \"zip\": the same folder as one <name>-embed.zip. \"single-html\": one <name>.html with everything inline. Library assets are copied; nothing is hotlinked. Options: `baseUrl` (where the folder is served, so the snippet works from any page), `cacheBust` (versioned runtime folder + ?v= hash for long-term caching), `integrity` (SRI hash on the runtime script, default true), `optimize` (export lighter copies of the assets — the project is not modified), `og` (render a 1200×630 og-image.png social preview), `runtime` (\"auto\" default: a scene that is a single 3D photo ships the photo-only lite runtime agent3d-photo.js, ~14 KB gzipped instead of ~210 KB; \"full\" forces agent3d-runtime.js — the result says which in `runtime`, with `runtimeReasons` when full). Run check first; returns the snippet, sizes and budget warnings. When the host can render (CLI / MCP / Studio with Chrome): \"poster\" writes a still image (dist/poster.webp; `time`, `image`), \"video\" an MP4 / WebM (dist/video.webm; `codec`, `duration`, `fps`, `size`), \"gif\" / \"animated-webp\" an animated image (dist/animation.gif / .webp), returning { path } — `quality` supersamples, `transparent` keeps the alpha (poster, gif, animated-webp).",
|
|
1077
1077
|
inputSchema: {
|
|
1078
1078
|
type: "object",
|
|
1079
1079
|
properties: {
|
|
@@ -1126,6 +1126,11 @@ var ASSET_TOOLS = [
|
|
|
1126
1126
|
type: "boolean",
|
|
1127
1127
|
description: "embed / zip: render a 1200×630 og-image.png social preview (needs a host that can render; default false)."
|
|
1128
1128
|
},
|
|
1129
|
+
runtime: {
|
|
1130
|
+
type: "string",
|
|
1131
|
+
enum: ["auto", "full"],
|
|
1132
|
+
description: "embed / zip / single-html: \"auto\" (default) ships the photo-only lite runtime (agent3d-photo.js, no three.js) when the scene is a single 3D photo, \"full\" always the full runtime."
|
|
1133
|
+
},
|
|
1129
1134
|
out: {
|
|
1130
1135
|
type: "string",
|
|
1131
1136
|
description: "poster / video / gif / animated-webp: project-relative output file under dist/ or renders/ (default \"dist/poster.webp\", \"dist/video.webm\" (.mp4 with codec mp4), \"dist/animation.gif\", \"dist/animation.webp\")."
|
|
@@ -1195,6 +1200,8 @@ var ASSET_TOOLS = [
|
|
|
1195
1200
|
if (!outDir.startsWith("dist/") && outDir !== "dist") throw new OpsError("invalid", `outDir must be under dist/ (got "${outDir}").`, "Use e.g. \"dist/embed\".");
|
|
1196
1201
|
const wantsOg = input.og === true && format !== "single-html";
|
|
1197
1202
|
if (wantsOg && !ctx.host.media) throw new OpsError("invalid", "This host cannot render the og image.", "Export without og, or with the CLI: agent3d export (renders the poster and og-image.png with Chrome).");
|
|
1203
|
+
const runtimeChoice = optStr(input, "runtime") ?? "auto";
|
|
1204
|
+
if (runtimeChoice !== "auto" && runtimeChoice !== "full") throw new OpsError("invalid", `Unknown runtime "${runtimeChoice}".`, "Use \"auto\" (default: the photo-only lite runtime for single-3D-photo scenes) or \"full\".");
|
|
1198
1205
|
const runtime = { files: await ctx.host.runtimeFiles(format) };
|
|
1199
1206
|
let library = ctx.host.library ?? {
|
|
1200
1207
|
index: { assets: [] },
|
|
@@ -1213,7 +1220,8 @@ var ASSET_TOOLS = [
|
|
|
1213
1220
|
baseUrl: optStr(input, "baseUrl"),
|
|
1214
1221
|
cacheBust: input.cacheBust === true,
|
|
1215
1222
|
integrity: input.integrity !== false,
|
|
1216
|
-
extras: input.extras !== false
|
|
1223
|
+
extras: input.extras !== false,
|
|
1224
|
+
runtimeChoice
|
|
1217
1225
|
});
|
|
1218
1226
|
let optimized;
|
|
1219
1227
|
let r;
|
|
@@ -1244,6 +1252,8 @@ var ASSET_TOOLS = [
|
|
|
1244
1252
|
skippedChunks: r.page.skippedChunks.length,
|
|
1245
1253
|
...r.page.pruned ? { pruned: true } : {}
|
|
1246
1254
|
},
|
|
1255
|
+
runtime: r.runtime,
|
|
1256
|
+
...r.runtimeReasons ? { runtimeReasons: r.runtimeReasons } : {},
|
|
1247
1257
|
snippet: format === "single-html" ? `(single file) ${outDir}/${r.entry}` : r.snippet,
|
|
1248
1258
|
...r.head ? { head: r.head } : {},
|
|
1249
1259
|
...r.runtimeDir ? { runtimeDir: r.runtimeDir } : {},
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var e=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,t=e=>Array.isArray(e)?e.length>0:e!=null&&e!==!1;function n(n){let r=[],i=(e,t)=>{e&&r.push(t)},a=n??{};i((a.target??{}).kind===`game`,`target.kind is game`),i(t(a.timeline),`timeline`),i(t(a.interactions),`interactions`),i(t(a.postfx),`post effects (postfx)`),i(t(a.physics),`physics`),i(t(a.scripts),`scripts`),i(a.ui?.elements?.length,`ui (HUD)`),i(t(a.audio),`audio`),i(/\{data\./.test(JSON.stringify(n??{})),`data bindings ({data.*} placeholders)`);let o=a.camera;!o||o.type!==`perspective`?r.push(`camera is not perspective`):(i(o.controls&&o.controls!==`none`,`camera.controls "${o.controls}"`),i(o.autoRotate,`camera.autoRotate`),i(t(o.shots),`camera.shots`),i(o.shake,`camera.shake`),i(o.lookAt,`camera.lookAt`),i(o.follow,`camera.follow`));let s=a.environment,c=s?.background;i(c!==void 0&&(typeof c!=`string`||c!==`transparent`&&!e.test(c)),`environment.background is not a #hex colour or transparent`),i(s?.ground,`environment.ground`),i(s?.contactShadows,`environment.contactShadows`),i(s?.rig,`environment.rig (light rig)`);for(let e of a.lights??[])i(e.type===`rect`,`rect lights (visible panels)`),i(e.type===`spot`&&e.volumetric,`volumetric spot lights`);let l=a.objects??[];l.length!==1&&r.push(`${l.length} objects (the lite runtime shows exactly one photo)`);let u=l[0];if(u&&u.kind!==`photo`)r.push(`object "${u.id}" is a ${u.kind}, not a photo`);else if(u){let n=u;i(!!n.depth&&n.mode&&n.mode!==`parallax`,`photo mode "${n.mode}" (lite: parallax or a flat photo)`),i(t(n.children),`photo has children`),i(n.visible===!1,`photo is hidden`),i(t(n.behaviours),`photo behaviours`),i(n.body,`photo physics body`),i(n.href,`photo link (href)`),i(n.attach,`photo attached to the camera`),i(Array.isArray(n.rotation)&&n.rotation.some(e=>e!==0),`photo is rotated`);let r=n.scale;i(r!==void 0&&(typeof r==`number`?!(r>0):!Array.isArray(r)||!(r[0]>0&&r[1]>0)),`photo scale is not positive`),i(n.material?.color!==void 0&&!(typeof n.material.color==`string`&&e.test(n.material.color)),`photo material.color is not a #hex colour`),i(typeof n.src!=`string`||!n.src,`photo has no src`)}return r.length?{ok:!1,reasons:r}:{ok:!0}}var r=/\{data\.([a-zA-Z_$][\w$-]*(?:\.[a-zA-Z_$][\w$-]*)*)(?:\|([^}]*))?\}/g;function i(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return n}function a(e){return typeof e!=`string`||!e.includes(`{data.`)?!1:(r.lastIndex=0,r.test(e))}function o(e,t){return e.includes(`{data.`)?e.replace(r,(e,n,r)=>{let a=i(t,n);return a==null||a===``?r??``:typeof a==`object`?JSON.stringify(a):String(a)}):e}var s=/^\{data\.([a-zA-Z_$][\w$-]*(?:\.[a-zA-Z_$][\w$-]*)*)(?:\|([^}]*))?\}$/;function c(e,t){if(typeof e!=`string`||!e.includes(`{data.`))return e;let n=s.exec(e.trim());if(!n)return o(e,t);let r=i(t,n[1]);if(r!=null&&r!==``)return r;if(n[2]!==void 0)try{return JSON.parse(n[2])}catch{return n[2]}}function l(e,t=e.data){let n=!1,r=e=>a(e)?(n=!0,o(e,t)):e,i=e=>{if(typeof e==`string`)return a(e)?(n=!0,c(e,t)):e;if(Array.isArray(e)){let t=e.map(i);return t.every((t,n)=>t===e[n])?e:t}if(e&&typeof e==`object`){let t=!1,n={};for(let[r,a]of Object.entries(e)){let e=i(a);e!==a&&(t=!0),e!==void 0&&(n[r]=e)}return t?n:e}return e},s=e=>{let t=e,n=t.kind===`text`?r(t.text):t.text,a=r(t.href),o=t.kind===`generator`&&t.params?i(t.params):t.params,c=e.children?.map(s);return n===t.text&&a===t.href&&o===t.params&&(!c||c.every((t,n)=>t===e.children[n]))?e:{...e,...t.kind===`text`?{text:n}:{},...t.href===void 0?{}:{href:a},...o===t.params?{}:{params:o},...c?{children:c}:{}}},l=e.interactions?.map(e=>{let t=e.do;if(!Array.isArray(t))return e;let n=t.map(e=>{let t=e;return!t||typeof t!=`object`||!a(t.openUrl)?e:{...t,openUrl:r(t.openUrl)}});return n.every((e,n)=>e===t[n])?e:{...e,do:n}}),u=(e.objects??[]).map(s),d=r(e.title),f=r(e.ariaLabel),p=e.ui?.elements?.map(e=>{let t=e,n=r(t.text);return n===t.text?e:{...e,text:n}});return n?{...e,title:d,...e.ariaLabel===void 0?{}:{ariaLabel:f},objects:u,...e.ui&&p?{ui:{...e.ui,elements:p}}:{},...l?{interactions:l}:{}}:e}function u(e){let t={};for(let[n,r]of Object.entries(e))if(r!==void 0){if(n===`json`)try{let e=JSON.parse(r);e&&typeof e==`object`&&!Array.isArray(e)&&Object.assign(t,e)}catch{}else t[n]=r}return t}var d=typeof HTMLElement<`u`?HTMLElement:class{},f=`
|
|
2
|
+
:host{display:block;position:relative;width:100%;overflow:hidden;background:var(--agent3d-background,transparent);contain:layout paint;-webkit-tap-highlight-color:transparent}
|
|
3
|
+
:host([hidden]){display:none}
|
|
4
|
+
:host([interactive="false"]) ::slotted(*){pointer-events:none}
|
|
5
|
+
::slotted(script){display:none}
|
|
6
|
+
.poster,.print{position:absolute;inset:0;width:100%;height:100%;z-index:1;pointer-events:none;transition:opacity var(--agent3d-fade,.4s) ease;border:0;overflow:hidden}
|
|
7
|
+
.poster img,::slotted([slot="poster"]),.print{object-fit:var(--agent3d-poster-fit,cover);display:block;width:100%;height:100%}
|
|
8
|
+
.poster[hidden],.print{display:none}
|
|
9
|
+
:host([status="ready"]) .poster{opacity:0}
|
|
10
|
+
.loading{position:absolute;left:0;right:0;bottom:0;height:3px;z-index:2;pointer-events:none;opacity:0;transition:opacity .3s ease .4s;overflow:hidden}
|
|
11
|
+
:host([status="loading"]) .loading{opacity:1}
|
|
12
|
+
.bar{height:100%;width:30%;background:var(--agent3d-loading-color,currentColor);opacity:.55;border-radius:0 2px 2px 0;transition:width .25s ease}
|
|
13
|
+
.loading.indeterminate .bar{animation:a3d-slide 1.2s ease-in-out infinite}
|
|
14
|
+
@keyframes a3d-slide{0%{transform:translateX(-100%)}100%{transform:translateX(340%)}}
|
|
15
|
+
.fallback{position:absolute;inset:0;z-index:1;display:none;align-items:center;justify-content:center;text-align:center;padding:12px;font:14px/1.4 system-ui,sans-serif;color:inherit;opacity:.75}
|
|
16
|
+
:host([status="unsupported"]) .fallback.show,:host([status="error"]) .fallback.show{display:flex}
|
|
17
|
+
:host([status="unsupported"]) .poster,:host([status="error"]) .poster{opacity:1}
|
|
18
|
+
@media (prefers-reduced-motion:reduce){.loading.indeterminate .bar{animation:none;width:100%;opacity:.3}.poster{transition:none}}
|
|
19
|
+
@media print{::slotted(canvas),::slotted(img){visibility:hidden}.print{display:block}.loading{display:none}.poster{opacity:1}}
|
|
20
|
+
`,p=null;function m(e){try{return`adoptedStyleSheets`in e&&typeof CSSStyleSheet<`u`&&typeof CSSStyleSheet.prototype.replaceSync==`function`}catch{return!1}}function h(e){let t=/^\s*([\d.]+)\s*[:/x]\s*([\d.]+)\s*$/.exec(e??``);return!t||!(Number(t[1])>0)||!(Number(t[2])>0)?null:`${t[1]} / ${t[2]}`}function g(){let e=typeof navigator<`u`?navigator:{};if(e.connection?.saveData)return`low`;let t=e.hardwareConcurrency??8,n=e.deviceMemory??8;return t<=2||n<=2?`low`:t<=4||n<=4?`medium`:`high`}function _(e,t){let n=e;if(t.data&&Object.keys(t.data).length&&(n={...n,data:{...n.data??{},...t.data}}),t.loop!=null&&n.timeline){let e=t.loop.trim().toLowerCase(),r=e===`pingpong`?`pingpong`:e!==`false`&&e!==`0`&&e!==`no`;n={...n,timeline:{...n.timeline,loop:r}}}let r=t.quality?t.quality===`auto`?g():t.quality:null;if((t.quality===`low`||t.quality===`medium`||t.quality===`high`||t.quality===`ultra`)&&(n={...n,target:{...n.target,quality:t.quality}}),r===`low`||r===`medium`||r===`high`){let e=r===`low`?1:r===`medium`?1.5:2,t={...n.target,maxDpr:Math.min(n.target?.maxDpr??2,e)};r===`low`&&Object.assign(t,{antialias:!1,shadows:!1}),n={...n,target:t,...r===`low`?{postfx:void 0}:{}}}return l(n)}var v=class extends d{static get observedAttributes(){return[`src`,`poster`,`aspect`,`alt`,`paused`,`loop`,`quality`,`library-base`]}player=null;ready;resolveReady;root=null;posterEl=null;posterBox=null;printEl=null;loadingEl=null;barEl=null;fallbackEl=null;sizeStyle=null;sizeSheet=null;sizeCssText=``;loadToken=0;connected=!1;source=null;dataOverrides={};dataObserver=null;interObs=null;inView=!0;lostTimer=null;wantPlay=null;autoAriaLabel=null;constructor(){super(),this.resetReady()}readySettled=!1;resetReady(){this.readySettled=!1,this.ready=new Promise(e=>this.resolveReady=e)}connectedCallback(){this.connected=!0,this.ensureShadow(),this.updatePoster(),this.applyAspect(null),this.ownerDocument.defaultView?.addEventListener(`beforeprint`,this.onBeforePrint),this.addEventListener(`webglcontextlost`,this.onContextLost,!0),this.addEventListener(`webglcontextrestored`,this.onContextRestored,!0),typeof MutationObserver<`u`&&(this.dataObserver=new MutationObserver(e=>{e.some(e=>e.attributeName?.startsWith(`data-`))&&this.refreshData()}),this.dataObserver.observe(this,{attributes:!0})),typeof IntersectionObserver<`u`&&(this.interObs=new IntersectionObserver(e=>this.inView=e.some(e=>e.isIntersecting)),this.interObs.observe(this)),this.load()}disconnectedCallback(){this.connected=!1,this.loadToken++,this.ownerDocument.defaultView?.removeEventListener(`beforeprint`,this.onBeforePrint),this.removeEventListener(`webglcontextlost`,this.onContextLost,!0),this.removeEventListener(`webglcontextrestored`,this.onContextRestored,!0),this.dataObserver?.disconnect(),this.dataObserver=null,this.interObs?.disconnect(),this.interObs=null,this.lostTimer&&clearTimeout(this.lostTimer),this.lostTimer=null,this.player?.dispose(),this.player=null,this.setStatus(`idle`)}attributeChangedCallback(e,t,n){this.connected&&t!==n&&(e===`poster`||e===`alt`?this.updatePoster():e===`aspect`?this.applyAspect(this.source):e===`paused`?n===null?this.getAttribute(`status`)===`ready`&&this.player?.play():this.player?.pause():e===`src`?(this.source=null,this.load()):this.rebuild())}play(){this.wantPlay=!0,this.hasAttribute(`paused`)&&this.removeAttribute(`paused`),this.player?.play()}pause(){this.wantPlay=!1,this.player?.pause()}async seek(e){await(this.player??await this.ready).seek(e)}get data(){return{...this.source?.data??{},...this.attrData(),...this.dataOverrides}}async setData(e,t={}){this.dataOverrides=t.replace?{...e}:{...this.dataOverrides,...e},await this.rebuild()}trigger(e,t){this.player?.emit?this.player.emit(e,t):this.ready.then(n=>n.emit?.(e,t))}reload(){return this.source=null,this.load()}ensureShadow(){if(this.root||typeof this.attachShadow!=`function`)return;let e=this.ownerDocument;this.root=this.shadowRoot??this.attachShadow({mode:`open`});let t=[];if(m(this.root))p||(p=new CSSStyleSheet,p.replaceSync(f)),this.sizeSheet=new CSSStyleSheet,this.root.adoptedStyleSheets=[p,this.sizeSheet];else{let n=e.createElement(`style`);n.textContent=f,this.sizeStyle=e.createElement(`style`),t=[n,this.sizeStyle]}let n=e.createElement(`slot`);this.posterBox=e.createElement(`div`),this.posterBox.className=`poster`,this.posterBox.setAttribute(`part`,`poster`);let r=e.createElement(`slot`);r.name=`poster`,this.posterEl=e.createElement(`img`),this.posterEl.setAttribute(`part`,`poster-image`),this.posterEl.decoding=`async`,r.appendChild(this.posterEl),this.posterBox.appendChild(r),this.printEl=e.createElement(`img`),this.printEl.className=`print`,this.printEl.alt=``,this.loadingEl=e.createElement(`div`),this.loadingEl.className=`loading indeterminate`,this.loadingEl.setAttribute(`part`,`loading`),this.loadingEl.setAttribute(`aria-hidden`,`true`),this.barEl=e.createElement(`div`),this.barEl.className=`bar`,this.barEl.setAttribute(`part`,`loading-bar`),this.loadingEl.appendChild(this.barEl),this.fallbackEl=e.createElement(`div`),this.fallbackEl.className=`fallback`,this.fallbackEl.setAttribute(`part`,`fallback`);let i=e.createElement(`slot`);i.name=`fallback`,this.fallbackEl.appendChild(i),this.root.append(...t,n,this.posterBox,this.printEl,this.loadingEl,this.fallbackEl)}updatePoster(){let e=this.posterEl;if(!e)return;let t=this.getAttribute(`poster`);e.alt=this.getAttribute(`alt`)??this.getAttribute(`aria-label`)??``,t?e.getAttribute(`src`)!==t&&(e.src=t):e.removeAttribute(`src`),this.posterBox&&(this.posterBox.hidden=!this.posterSrc()),this.updateFallbackText()}posterSrc(){let e=this.querySelector(`[slot="poster"]`),t=e?.tagName===`IMG`?e:e?.querySelector(`img`);return t?.currentSrc||t?.getAttribute(`src`)||this.getAttribute(`poster`)}updateFallbackText(){let e=this.fallbackEl;if(!e)return;let t=e.querySelector(`slot`),n=!!this.querySelector(`[slot="fallback"]`),r=!!this.posterSrc();e.classList.toggle(`show`,n||!r),t&&!n&&(t.textContent=this.getAttribute(`alt`)??this.getAttribute(`aria-label`)??``)}setStatus(e){e===`idle`?this.removeAttribute(`status`):this.setAttribute(`status`,e),(e===`unsupported`||e===`error`)&&this.updateFallbackText()}progress(e,t){this.loadingEl&&this.barEl&&t>0&&(this.loadingEl.classList.remove(`indeterminate`),this.barEl.style.width=`${Math.round(Math.min(e,t)/t*100)}%`),this.emit(`agent3d:progress`,{loaded:e,total:t})}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}fail(e){this.emit(`agent3d:error`,e),this.emit(`agent3d-error`,e)}onBeforePrint=()=>{let e=this.printEl;if(!e)return;let t=``;try{this.player&&this.getAttribute(`status`)===`ready`&&(t=this.player.snapshot(`image/png`))}catch{}(!t||t.length<32)&&(t=this.posterSrc()??``),t?e.src=t:e.removeAttribute(`src`)};onContextLost=e=>{this.player&&this.inView&&this.getAttribute(`status`)===`ready`&&(e.preventDefault(),this.fail({code:`context-lost`,message:`The WebGL context was lost; restoring.`}),this.setStatus(`loading`),this.lostTimer&&clearTimeout(this.lostTimer),this.lostTimer=setTimeout(()=>{this.lostTimer=null,this.rebuild(!0)},3e3))};onContextRestored=()=>{this.lostTimer&&clearTimeout(this.lostTimer),this.lostTimer=null;let e=this.player;e&&e.update(e.scene).then(()=>this.setStatus(`ready`),()=>void this.rebuild(!0))};childJson(e){let t=this.querySelector(e);if(t?.textContent)try{return JSON.parse(t.textContent)}catch(e){this.fail({code:`invalid-scene`,message:`Invalid inline JSON: ${e.message}`});return}}attrData(){return u(this.dataset??{})}refreshData(){this.source&&this.rebuild()}base(){let e=this.getAttribute(`src`);return e?new URL(`.`,new URL(e,this.ownerDocument.baseURI)).href:this.ownerDocument.baseURI}async fetchScene(){let e=this.childJson(`script[type="application/json"]:not([data-assets])`);if(e)return e;let t=this.getAttribute(`src`);if(!t)return;let n=new URL(t,this.ownerDocument.baseURI).href,r=await fetch(n);if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()}async load(){let e=++this.loadToken;if(!this.source){this.setStatus(`loading`);let t;try{if(t=await this.fetchScene(),!t&&this.ownerDocument.readyState===`loading`){if(await new Promise(e=>this.ownerDocument.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0})),e!==this.loadToken)return;t=await this.fetchScene()}}catch(t){if(e!==this.loadToken)return;this.setStatus(`error`),this.fail({code:`scene-load`,message:`Cannot load ${this.getAttribute(`src`)}: ${t.message}`,path:this.getAttribute(`src`)??void 0});return}if(e!==this.loadToken)return;if(!t){this.setStatus(`idle`);return}this.source=t}await this.mount(e)}async rebuild(e=!1){if(!this.connected||!this.source)return;let t=this.player;if(t&&!e&&this.getAttribute(`status`)===`ready`&&this.getAttribute(`library-base`)===this.mountedLibraryBase){let e=this.sceneForMount();this.applySizing(e),await t.update(e)}else await this.mount(++this.loadToken)}sceneForMount(){return _(this.source,{data:{...this.attrData(),...this.dataOverrides},loop:this.getAttribute(`loop`),quality:this.getAttribute(`quality`)})}mountedLibraryBase=null;async mount(e){this.player?.dispose(),this.player=null,this.readySettled&&this.resetReady(),this.setStatus(`loading`);let t=this.sceneForMount();this.applySizing(t);let n=this.childJson(`script[data-assets]`),r={};this.querySelectorAll(`script[type="text/agent3d-script"][data-path]`).forEach(e=>{r[e.getAttribute(`data-path`)]=e.textContent??``});let i=this.getAttribute(`library-base`);this.mountedLibraryBase=i;let a=this.mountPlayer(this,t,{assetBase:this.base(),libraryBase:i?new URL(i,this.ownerDocument.baseURI).href:void 0,assetUrls:n,scriptSources:Object.keys(r).length?r:void 0,onError:t=>{e===this.loadToken&&(t.code===`webgl-unavailable`&&this.setStatus(`unsupported`),this.fail(t))},onEvent:(t,n)=>e===this.loadToken&&this.emit(`agent3d:event`,{name:t,payload:n}),onClick:(t,n)=>e===this.loadToken&&this.emit(`agent3d:click`,{id:t,x:n.x,y:n.y}),onProgress:(t,n)=>e===this.loadToken&&this.progress(t,n)});this.player=a;try{await a.ready}catch{e===this.loadToken&&this.getAttribute(`status`)!==`unsupported`&&this.setStatus(`error`);return}if(e!==this.loadToken)return;let o=(this.getAttribute(`autoplay`)??``).toLowerCase();(this.hasAttribute(`paused`)||this.wantPlay===!1||this.wantPlay!==!0&&(o===`false`||o===`0`||o===`no`))&&a.pause(),this.setStatus(`ready`),this.readySettled=!0,this.resolveReady(a),this.emit(`agent3d:ready`,{player:a}),this.emit(`agent3d-ready`,{player:a})}applyAspect(e){if(!this.sizeStyle&&!this.sizeSheet)return;let t=e?.target,n;n=t?.height?`:host{height:${t.height}}`:t?.kind===`fullscreen`?`:host{height:100vh;height:100dvh}`:`:host{aspect-ratio:${h(e?t?.aspect??this.getAttribute(`aspect`):this.getAttribute(`aspect`)??`16:9`)??`16 / 9`}}`,this.sizeCssText!==n&&(this.sizeCssText=n,this.sizeSheet?this.sizeSheet.replaceSync(n):this.sizeStyle&&(this.sizeStyle.textContent=n))}applySizing(e){if(this.sizeStyle||this.sizeSheet)this.applyAspect(e);else{this.style.display||(this.style.display=`block`),this.style.width||(this.style.width=`100%`),this.style.position||(this.style.position=`relative`);let t=h(e.target?.aspect)??`16 / 9`;e.target?.height?this.style.height=e.target.height:this.style.aspectRatio=t}let t=e.target?.kind===`game`;this.setAttribute(`role`,t?`application`:`img`);let n=this.getAttribute(`aria-label`);(n===null||n===this.autoAriaLabel)&&(this.autoAriaLabel=e.ariaLabel||e.title||`3D scene`,this.setAttribute(`aria-label`,this.autoAriaLabel)),t&&!this.hasAttribute(`tabindex`)&&(this.tabIndex=0),this.updatePoster()}};function y(e,t=`agent3d-scene`){typeof customElements<`u`&&(customElements.get(t)||customElements.define(t,e))}var ee={low:1,medium:1.5,high:2,ultra:3};function b(e,t={}){return e&&e!==`auto`?e:t.deterministic?`high`:t.gpu&&/swiftshader|llvmpipe|softpipe|software|microsoft basic render/i.test(t.gpu)?`low`:t.mobile?(t.memoryGb??4)<=2||(t.cores??8)<=4?`low`:`medium`:t.cores!==void 0&&t.cores<=2||t.memoryGb!==void 0&&t.memoryGb<=2?`low`:t.cores!==void 0&&t.cores<=4||t.memoryGb!==void 0&&t.memoryGb<=4||t.gpu&&/intel|mali|adreno|powervr/i.test(t.gpu)?`medium`:`high`}function x(e){return e.endsWith(`/`)?e:e+`/`}function te(e){let t=x(e.assetBase??`./`),n=x(e.libraryBase??t+`assets/library/`),r=e.assetUrls??{};return e=>{if(r[e])return r[e];if(/^(https?:|data:|blob:|\/)/.test(e))return e;if(e.startsWith(`library:`)){let t=e.slice(8);return t.startsWith(`fonts/`)&&!/\.json$/.test(t)&&(t+=`.typeface.json`),r[`library:`+t]?r[`library:`+t]:n+t}return t+e.replace(/^\.\//,``)}}var S=Math.PI/180;function C(e,t,n){return e<t?t:e>n?n:e}function w(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function T(e,t){return!t||!(e>0)||e>=t?1:Math.min(t/e,3)}function E(e,t){return t<=1?e:Math.min(100,2*Math.atan(Math.tan(e*S/2)*t)/S)}function ne(e){let t=/^\s*([\d.]+)\s*[:/x]\s*([\d.]+)\s*$/.exec(e??``),n=t?Number(t[1])/Number(t[2]):void 0;return n&&Number.isFinite(n)&&n>0?n:void 0}function D(e,t){let n=t.x-e.x,r=t.y-e.y,i=t.z-e.z,a=Math.hypot(n,r,i);if(a<1e-9)return;let o=-1e-4/a;e.set(e.x+n*o,e.y+r*o,e.z+i*o)}var O={width:4,strength:.5,focus:.5,segments:256,layers:6,edgeCut:.08,speed:1,smoothing:.9};function re(e,t,n){let r=t>0&&n>0?t/n:1,i=typeof e.width==`number`&&e.width>0?e.width:void 0,a=typeof e.height==`number`&&e.height>0?e.height:void 0;if(i!==void 0&&a!==void 0)return{width:i,height:a};if(a!==void 0)return{width:a*r,height:a};let o=i??O.width;return{width:o,height:o/r}}function k(e,t,n){let r=2*Math.PI*Math.max(0,t)/10*n;switch(e??`sway`){case`sway`:return{x:.9*Math.sin(r),y:.35*Math.sin(2*r),zoom:0};case`orbit`:{let e=Math.min(1,r/Math.PI),t=.8*e*e*(3-2*e);return{x:t*Math.sin(r),y:t*Math.cos(r),zoom:0}}case`zoom`:return{x:0,y:0,zoom:.5-.5*Math.cos(r)};default:return{x:0,y:0,zoom:0}}}function ie(e){let t=C(w(e?.pointer,1),0,1);return{pointer:t,scroll:C(w(e?.scroll,0),0,1),gyro:typeof e?.gyro==`boolean`?e.gyro:t>0,auto:e?.auto??`sway`,speed:Math.max(0,w(e?.speed,O.speed)),smoothing:C(w(e?.smoothing,O.smoothing),0,.99)}}function A(e,t){let n=t.reduced?{x:0,y:0,zoom:0}:k(e.auto,e.speed,t.t),r=e.pointer*(t.reduced?.5:1),i=0,a=0,o=0;t.gyro&&e.gyro&&t.pointer.weight<.5?(i=t.gyro.x,a=t.gyro.y,o=+(r>0)):r>0&&(i=t.pointer.x,a=t.pointer.y,o=C(t.pointer.weight,0,1));let s=n.x*(1-o)+i*r*o,c=n.y*(1-o)+a*r*o;return e.scroll>0&&(c+=(C(t.scroll,0,1)*2-1)*e.scroll),{x:C(s,-1,1),y:C(c,-1,1),zoom:n.zoom*(1-o)}}function j(e,t,n,r){if(r<=0||n<=0)return n<=0&&r>0?e:t;let i=1-C(r,0,.99)**(n*60),a=e+(t-e)*i;return Math.abs(t-a)<1e-4?t:a}function ae(e,t,n){let r=C(e,0,1),i=Math.min(t,n),a=i/t,o=i/n;return{maxOffset:[r*.06*a,r*.06*o],inset:[1/(1+r*.1*a),1/(1+r*.1*o)]}}function M(e,t,n,r){let i=t-n.gamma,a=e-n.beta,o=(Math.round(r/90)%4+4)%4;return o===1?[i,a]=[a,-i]:o===2?[i,a]=[-i,-a]:o===3&&([i,a]=[-a,i]),{x:C(i/20,-1,1),y:C(-a/20,-1,1)}}function oe(e,t){return Math.max(8,Math.round((e===`low`?12:e===`medium`?20:e===`ultra`?48:32)*(.5+.5*Math.min(1,Math.max(0,t)/.6))))}function se(e,t){let{live:n}=t,r={x:0,y:0,weight:0,init:!1},i=null,a=null,o=null;if(n&&e.gyro&&e.pointer>0&&!t.flat&&typeof window<`u`&&typeof window.addEventListener==`function`){let e=e=>{if(e.beta===null||e.gamma===null)return;a??={beta:e.beta,gamma:e.gamma};let t=typeof screen<`u`&&screen.orientation?.angle||0;i=M(e.beta,e.gamma,a,t)};window.addEventListener(`deviceorientation`,e),o=()=>window.removeEventListener(`deviceorientation`,e)}return{offset(t,a,o){let s=o.pointer,c=s.inside?C(s.x,-1,1):0,l=s.inside?C(s.y,-1,1):0,u=+!!s.inside;return!n||!r.init?(r.x=c,r.y=l,r.weight=u,r.init=n):(r.x=j(r.x,c,a,e.smoothing),r.y=j(r.y,l,a,e.smoothing),r.weight=j(r.weight,u,a,e.smoothing)),A(e,{t,pointer:r,gyro:n?i:null,scroll:o.scroll,reduced:o.reduced})},dispose(){o?.(),o=null}}}var N=`uniform sampler2D uMap;uniform vec3 uTint;uniform float uOpacity;uniform float uIntensity;vec4 shade(vec4 c,float a){return vec4(c.rgb*uTint*uIntensity,c.a*a*uOpacity);}
|
|
21
|
+
`,P=`uniform sampler2D uDepth;uniform vec2 uView;uniform float uZoom;uniform vec2 uMaxOffset;uniform vec2 uInset;uniform float uFocus;uniform float uWallSlope;const int STEPS=__STEPS__;vec4 parallaxTexel(vec2 vUv){vec2 base=0.5+(vUv-0.5)*uInset*(1.0-0.06*uZoom);vec2 v=uView-(vUv-0.5)*2.0*uZoom;vec2 dir=v*uMaxOffset;vec2 uv=base;if(dot(dir,dir)>1e-10){float stepH=1.0/float(STEPS);float h=1.0;float prevH=1.0+stepH;bool hit=false;for(int i=0;i<=STEPS;i++){h=1.0-float(i)*stepH;float d=textureLod(uDepth,base+(h-uFocus)*dir,0.0).r;if(d>=h){hit=true;break;}prevH=h;}float lo=h,hi=min(prevH,1.0);if(hit){for(int j=0;j<6;j++){float mid=0.5*(lo+hi);float d=textureLod(uDepth,base+(mid-uFocus)*dir,0.0).r;if(d>=mid)lo=mid;else hi=mid;}}uv=base+(lo-uFocus)*dir;vec2 texel=1.0/vec2(textureSize(uDepth,0));vec4 dh=textureLod(uDepth,uv,0.0);vec2 grad=vec2(textureLod(uDepth,uv+vec2(texel.x*1.5,0.0),0.0).r-textureLod(uDepth,uv-vec2(texel.x*1.5,0.0),0.0).r,textureLod(uDepth,uv+vec2(0.0,texel.y*1.5),0.0).r-textureLod(uDepth,uv-vec2(0.0,texel.y*1.5),0.0).r)/3.0;float g=length(grad);vec2 toNear=grad/max(g,1e-6);float dNear=textureLod(uDepth,uv+toNear*texel*3.0,0.0).r;if(hit&&(g>uWallSlope||dh.a<0.5)&&dNear>lo+0.04){vec2 away=-toNear;vec2 probe=uv;for(int k=1;k<=6;k++){vec2 q=uv+away*texel*float(k*2);probe=q;if(textureLod(uDepth,q,0.0).r<lo-0.05)break;}uv=probe+away*texel*2.0;}}return textureGrad(uMap,uv,dFdx(base),dFdy(base));}
|
|
22
|
+
`,ce=.02,le=`#version 300 es
|
|
23
|
+
in vec2 aPos;out vec2 vNdc;void main(){vNdc=aPos;gl_Position=vec4(aPos,0.0,1.0);}
|
|
24
|
+
`,F=`#version 300 es
|
|
25
|
+
precision highp float;precision highp int;precision highp sampler2D;
|
|
26
|
+
`,I=`vec4 photoTexel(vec2 uv){return texture(uMap,uv);}
|
|
27
|
+
`,L=`vec4 photoTexel(vec2 uv){return parallaxTexel(uv);}
|
|
28
|
+
`,R=`uniform vec3 uO;uniform vec3 uF;uniform vec3 uR;uniform vec3 uU;uniform vec2 uClip;uniform vec4 uBg;uniform float uBlend;in vec2 vNdc;out vec4 fragColor;vec3 toSrgb(vec3 v){return mix(pow(v,vec3(0.41666))*1.055-vec3(0.055),v*12.92,vec3(lessThanEqual(v,vec3(0.0031308))));}void main(){vec3 d=uF+uR*vNdc.x+uU*vNdc.y;float t=d.z<0.0?-uO.z/d.z:-1.0;vec2 uv=uO.xy+t*d.xy+0.5;vec2 fw=max(fwidth(uv),vec2(1e-7));vec4 c=photoTexel(uv);vec2 e=min(uv,1.0-uv)/fw;float cover=uO.z>0.0&&t>=uClip.x&&t<=uClip.y?clamp(min(e.x,e.y)+0.5,0.0,1.0):0.0;vec4 s=shade(c,1.0);float a=c.a*uOpacity<0.004?0.0:uBlend>0.5?s.a:1.0;vec4 photo=vec4(toSrgb(s.rgb)*a,a)+uBg*(1.0-a);fragColor=mix(uBg,photo,cover);}
|
|
29
|
+
`,ue=(e,t)=>F+N+(e?I:P.replace(`__STEPS__`,String(t))+L)+R,de=[`uMap`,`uDepth`,`uTint`,`uOpacity`,`uIntensity`,`uView`,`uZoom`,`uMaxOffset`,`uInset`,`uFocus`,`uWallSlope`,`uO`,`uF`,`uR`,`uU`,`uClip`,`uBg`,`uBlend`],z=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],B=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],V=e=>{let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]};function fe(e,t){let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e??``);if(!n)return t;let r=n[1].length===3?n[1].replace(/./g,`$&$&`):n[1];return[0,2,4].map(e=>parseInt(r.slice(e,e+2),16)/255)}var pe=e=>e<.04045?e*.0773993808:(e*.9478672986+.0521327014)**2.4;function me(e,t){let n=e.camera,r=n.target??[0,0,0],i={x:n.position[0],y:n.position[1],z:n.position[2],set(e,t,n){this.x=e,this.y=t,this.z=n}};D(i,{x:r[0],y:r[1],z:r[2]});let a=[i.x,i.y,i.z],o=z(a,r);Math.hypot(...o)===0&&(o=[0,0,1]),o=V(o);let s=B([0,1,0],o);Math.hypot(...s)===0&&(o=V([o[0],o[1],o[2]+1e-4]),s=B([0,1,0],o)),s=V(s);let c=B(o,s),l=E(w(n.fov,45),T(t,ne(e.target?.aspect)));return{pos:a,right:s,up:c,fwd:[-o[0],-o[1],-o[2]],tanY:Math.tan(l*S/2),near:w(n.near,.1),far:w(n.far,1e3)}}function he(e){return new Promise((t,n)=>{let r=new Image;r.crossOrigin=`anonymous`,r.onload=()=>t(r),r.onerror=()=>n(/* @__PURE__ */ Error(`Cannot load texture ${e}`)),r.src=e})}function H(e,t,n={}){let r=t,i=!!n.deterministic,a=te(n),o,s,c=new Promise((e,t)=>(o=e,s=t));c.catch(()=>void 0);let l=e.ownerDocument,u=l.defaultView,d=l.createElement(`canvas`);d.style.cssText=`display:block;width:100%;height:100%;outline:none;touch-action:manipulation;`;let f=u.getComputedStyle(e).position;f&&f!==`static`||(e.style.position=`relative`),e.appendChild(d);let p=null,m=null,h={},g=[],_=null,v=null,y=[1,1],x=`high`,S=!1,T=1,E={x:0,y:0,inside:!1},D=null,k=0,A=0,j=0,M=0,N=0,P=0,F=!1,I=!0,L=!1,R=!1,z=!1,B=!1,V=1,H=1,U=1,W=null,G=[],K=/* @__PURE__ */ new Map,q=()=>r.target??{},ge=()=>r.objects[0],_e=e=>{try{n.onError?.(e)}catch{}n.onError||console.warn(`[agent3d] ${e.code}: ${e.message}`)},J=(e,t,n,r)=>{e.addEventListener(t,n,r),G.push(()=>e.removeEventListener(t,n,r))},ve=()=>{let t=Math.max(1,e.clientWidth||d.clientWidth||300);H=t,U=Math.max(1,e.clientHeight||Math.round(t/(ne(r.target?.aspect)??16/9))),d.width=Math.floor(H*T),d.height=Math.floor(U*T)},ye=()=>{if(D!==null)return D;if(i||B)return C(k/4,0,1);let t=e.getBoundingClientRect(),n=u.innerHeight||1;return C((n-t.top)/(n+t.height),0,1)},be=e=>{if(!p)return;let t=h,n=r.environment?.background,i=q().transparent?[0,0,0,0]:[...fe(typeof n==`string`?n:void 0,[0,0,0]),1];if(p.viewport(0,0,d.width,d.height),!m){p.clearColor(...i),p.clear(p.COLOR_BUFFER_BIT);return}p.useProgram(m),e&&(p.uniform2f(t.uView,e.x,e.y),p.uniform1f(t.uZoom,e.zoom));let a=ge(),o=H/Math.max(U,1),s=me(r,o),c=a.position??[0,0,0],l=a.scale??1,u=y[0]*(typeof l==`number`?l:l[0]),f=y[1]*(typeof l==`number`?l:l[1]),g=(e,t)=>[e[0]*t/u,e[1]*t/f,e[2]*t];p.uniform3f(t.uO,(s.pos[0]-c[0])/u,(s.pos[1]-c[1])/f,s.pos[2]-c[2]),p.uniform3f(t.uF,...g(s.fwd,1)),p.uniform3f(t.uR,...g(s.right,s.tanY*o)),p.uniform3f(t.uU,...g(s.up,s.tanY)),p.uniform2f(t.uClip,s.near,s.far),p.uniform4f(t.uBg,...i),p.drawArrays(p.TRIANGLES,0,3)},Y=e=>{p&&v&&be(v.offset(k,e,{pointer:E,scroll:ye(),reduced:B}))},X=()=>{p&&(ve(),(!A||i)&&be())},xe=e=>{N+=e,N<2||(M<40?P+=e:P=Math.max(0,P-e),P<3||(P=N=0,n.pixelRatio===void 0&&T>1.01?(T=Math.max(1,T*.75),X()):S=!1))},Z=()=>{let e=l.visibilityState===`hidden`,t=F&&!R&&!e&&(I||q().pauseOffscreen===!1)&&!!v;if(t&&!A){j=performance.now();let e=t=>{A=requestAnimationFrame(e);let n=Math.min(Math.max((t-j)/1e3,0),.1);j=t,n>.002&&(M=M?M*.9+1/n*.1:1/n),S&&xe(n),k=Math.max(k+n*V,0),Y(n*V)};A=requestAnimationFrame(e)}else!t&&A&&(cancelAnimationFrame(A),A=0)},Se=e=>{let t=q(),r=globalThis.navigator??{},a;try{let t=e.getExtension(`WEBGL_debug_renderer_info`);a=String(e.getParameter(t?t.UNMASKED_RENDERER_WEBGL:e.RENDERER)??``)}catch{}x=b(t.quality,{deterministic:i,mobile:r.userAgentData?.mobile??/Mobi|Android|iPhone|iPad|iPod/i.test(r.userAgent??``),cores:r.hardwareConcurrency,memoryGb:r.deviceMemory,gpu:a}),S=(t.quality??`auto`)===`auto`&&!i,N=P=0,T=n.pixelRatio??Math.min(globalThis.devicePixelRatio||1,t.maxDpr??2,ee[x]),ve()},Ce=async()=>{let e=ge(),t=0,r=0,i=(i,o,s)=>{let c=he(a(i));if(n.onProgress){t++;let e=()=>{try{n.onProgress?.(++r,t)}catch{}};c.then(e,e)}return c.catch(t=>(_e({code:`asset-load`,message:`${e.id}: ${o}${t.message}${s?` — showing the photo flat`:``}`,path:`objects#${e.id}${s}`}),null))},[o,s]=await Promise.all([i(e.src,``,``),e.depth?i(e.depth,`depth map: `,`.depth`):null]);return{map:o,depth:s}},we=()=>{if(p){for(let e of g)p.deleteTexture(e);g=[],m&&p.deleteProgram(m),m=null}},Te=async()=>{if(_??=await Ce(),R||!p)return;let e=p;Se(e),v?.dispose();let t=ge(),{map:n,depth:r}=_,a=!r;if(v=se(ie(t.motion),{live:!i,flat:a}),!n)return;let o=C(w(t.strength,O.strength),0,1),s=e.createProgram(),c=(t,n)=>{let r=e.createShader(t);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)&&!e.isContextLost())throw Error(`photo shader: ${e.getShaderInfoLog(r)}`);e.attachShader(s,r)};if(c(e.VERTEX_SHADER,le),c(e.FRAGMENT_SHADER,ue(a,oe(x,o))),e.bindAttribLocation(s,0,`aPos`),e.linkProgram(s),!e.getProgramParameter(s,e.LINK_STATUS)&&!e.isContextLost())throw Error(`photo shader: ${e.getProgramInfoLog(s)}`);m=s;for(let t of de)h[t]=e.getUniformLocation(s,t);e.bindBuffer(e.ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE);let l=(t,n,r)=>{let i=e.createTexture();if(g.push(i),e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,r?e.SRGB8_ALPHA8:e.RGBA8,e.RGBA,e.UNSIGNED_BYTE,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.MIRRORED_REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.MIRRORED_REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,r?e.LINEAR_MIPMAP_LINEAR:e.LINEAR),r){e.generateMipmap(e.TEXTURE_2D);let t=e.getExtension(`EXT_texture_filter_anisotropic`);t&&e.texParameterf(e.TEXTURE_2D,t.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(4,e.getParameter(t.MAX_TEXTURE_MAX_ANISOTROPY_EXT)))}};l(0,n,!0),r&&l(1,r,!1),e.useProgram(s);let u=h;e.uniform1i(u.uMap,0),e.uniform1i(u.uDepth,1);let d=t.material??{},f=fe(d.color,[1,1,1]).map(pe);e.uniform3f(u.uTint,f[0],f[1],f[2]);let ee=C(w(d.opacity,1),0,1);e.uniform1f(u.uOpacity,ee),e.uniform1f(u.uIntensity,Math.max(0,w(d.emissiveIntensity,1))),e.uniform1f(u.uBlend,ee<1||/\.(png|webp)$/i.test(t.src)?1:0);let b=re(t,n.naturalWidth||n.width||1,n.naturalHeight||n.height||1),te=ae(o,b.width,b.height);e.uniform2f(u.uMaxOffset,...te.maxOffset),e.uniform2f(u.uInset,...te.inset),e.uniform1f(u.uFocus,C(w(t.focus,O.focus),0,1)),e.uniform1f(u.uWallSlope,ce),y=[b.width,b.height]},Q=()=>{if(L||R)return;L=!0;let e=q();p=d.getContext(`webgl2`,{alpha:!!e.transparent,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!0,powerPreference:`high-performance`,preserveDrawingBuffer:i}),p?W=Te().then(()=>{R||(k=i?0:B?e.posterTime??0:k,Y(0),!i&&!B&&(F=!0,Z()),o(),z||n.onReady?.(Oe),z=!0)}).catch(e=>{_e({code:`build-error`,message:e.message}),s(e)}):(_e({code:`webgl-unavailable`,message:`WebGL is not available: no WebGL2 context`}),s(/* @__PURE__ */ Error(`webgl-unavailable`)))},Ee=e=>{D=e===null||!Number.isFinite(e)?null:C(e,0,1)},$=(e,t)=>{e!==void 0&&t!==void 0&&(E.x=e,E.y=t),E.inside=!0},De=()=>void 0,Oe={get scene(){return r},canvas:d,ready:c,input:{pointer:$,key:De,click:$,down:$,up:De,swipe:De,scroll:Ee},play(){F=!0,Q(),Z()},pause(){F=!1,Z()},async seek(e){if(L||Q(),await W,!p||!v)return;let t=Math.max(0,e);t<k-1e-9&&(k=0,v.offset(0,0,{pointer:E,scroll:0,reduced:B}));let n=t-k;k=t,Y(n)},time:()=>k,async update(e){await W,JSON.stringify(e.objects[0])!==JSON.stringify(r.objects[0])&&(_=null),r=e,p&&(we(),W=Te(),await W,Y(0))},resize:X,stats:()=>({triangles:+!!m,drawCalls:+!!m,geometries:+!!m,textures:g.length,fps:i?void 0:Math.round(M)||void 0}),inspect:()=>({objects:[],camera:{position:[...r.camera.position],target:[...r.camera.target??[0,0,0]]}}),snapshot(e=`image/png`,t){return be(),d.toDataURL(e,t)},state:()=>({}),pick:()=>null,emit(e,t){for(let n of[...K.get(e)??[]])try{n(t)}catch{}try{n.onEvent?.(e,t)}catch{}},on(e,t){let n=K.get(e);return n||K.set(e,n=/* @__PURE__ */ new Set),n.add(t),()=>n.delete(t)},setScrollProgress:Ee,dispose(){if(!R){R=!0,A&&cancelAnimationFrame(A),A=0;for(let e of G)e();G=[],v?.dispose(),we(),p?.getExtension(`WEBGL_lose_context`)?.loseContext(),p=null,d.remove()}}};if(J(e,`pointermove`,t=>{let n=e.getBoundingClientRect(),r=t;$((r.clientX-n.left)/Math.max(n.width,1)*2-1,-((r.clientY-n.top)/Math.max(n.height,1)*2-1))}),J(e,`pointerenter`,()=>E.inside=!0),J(e,`pointerleave`,()=>E.inside=!1),J(l,`visibilitychange`,Z),ve(),typeof ResizeObserver<`u`){let t=new ResizeObserver(X);t.observe(e),G.push(()=>t.disconnect())}let ke=q(),Ae=n.reducedMotion??(typeof matchMedia<`u`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches),je=ke.reducedMotion??`static`;if(Ae&&!i&&(je===`static`?B=!0:je===`slow`&&(V=.5)),i||ke.lazy===!1||typeof IntersectionObserver>`u`)Q();else{I=!1;let t=new IntersectionObserver(e=>{I=e.some(e=>e.isIntersecting),I&&Q(),Z()},{rootMargin:`200px 0px`});t.observe(e);let n=()=>{if(L||R||l.visibilityState===`hidden`||!e.isConnected)return;let t=e.getBoundingClientRect(),n=u.innerHeight||l.documentElement.clientHeight,r=u.innerWidth||l.documentElement.clientWidth;t.bottom>=-200&&t.top<=n+200&&t.right>=0&&t.left<=r&&(t.width>0||t.height>0)&&(I=!0,Q(),Z())},r=[setTimeout(n,500),setTimeout(n,2e3)],i=u.requestAnimationFrame(()=>i=u.requestAnimationFrame(n));J(u,`load`,n),J(u,`scroll`,n,{passive:!0}),J(l,`visibilitychange`,n),G.push(()=>{t.disconnect();for(let e of r)clearTimeout(e);u.cancelAnimationFrame(i)})}return d.isConnected&&X(),Oe}function U(e,t,n){let r=null,i=!1,a=!1,o=import.meta.url.replace(/[^/?#]*([?#].*)?$/,`agent3d-runtime.js`),s=import(
|
|
30
|
+
/* @vite-ignore */
|
|
31
|
+
o).then(o=>{if(a)throw Error(`disposed`);return r=o.mountScene(e,t,n),i&&r.pause(),r.ready},e=>{throw n.onError?.({code:`runtime-load`,message:`This scene needs the full runtime (${o}): ${e.message}`}),e});s.catch(()=>void 0);let c={ready:s,play:()=>(i=!1,r?.play()),pause:()=>(i=!0,r?.pause()),seek:async e=>(await s,r.seek(e)),dispose:()=>(a=!0,r?.dispose())};return new Proxy(c,{get(e,t){if(t in c)return c[t];let n=r?.[t];return typeof n==`function`?n.bind(r):n}})}var W=class extends v{mountPlayer(e,t,r){return n(t).ok?H(e,t,r):U(e,t,r)}};y(W);export{W as Agent3DPhotoElement,H as mountPhotoScene};
|