@fleox/agent3d 0.3.0 → 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 +21 -0
- package/dist/agent/agent3d.mjs +36 -18
- package/dist/agent/chunks/{depth-Dih8jLqx.mjs → depth-BZT4gseQ.mjs} +1 -1
- package/dist/agent/chunks/{depth-0bZsQn6N.mjs → depth-CD_ql3QJ.mjs} +1 -1
- package/dist/agent/chunks/{export-Cdqt3mt_.mjs → export-CEX5DFLo.mjs} +83 -5
- package/dist/agent/chunks/{package-d5e08XSG.mjs → package-DjRnLzcU.mjs} +2 -2
- package/dist/agent/chunks/{tools-Cv6N_YBI.mjs → tools-CZyIc4zw.mjs} +16 -6
- package/dist/runtime/agent3d-photo.js +31 -0
- package/dist/runtime/agent3d-runtime.js +41 -41
- package/dist/runtime/agent3d-runtime.single.js +252 -247
- 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-BlDYgYFM.js → photo-w6dwHX7j.js} +27 -22
- 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-BjgHj9g8.js → editor-DzyukvQl.js} +1 -1
- package/dist/studio/assets/game-DNpTN_Ga.js +19 -0
- package/dist/studio/assets/{generators-DqkPMEzm.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-gVpEEiSK.js → params-D-Ul6GSt.js} +1 -1
- package/dist/studio/assets/{photo-DRoVO5iZ.js → photo-Dx2IBJ11.js} +27 -22
- package/dist/studio/assets/physicsHost-z9qn_mpg.js +1 -0
- package/dist/studio/assets/{postfx-JFUGdY0d.js → postfx-B3jDEaEK.js} +13 -13
- package/dist/studio/assets/runtime-rd9RW3WH.js +572 -0
- package/dist/studio/assets/{shaders-C7u6rN_6.js → shaders-bFhELLmD.js} +1 -1
- package/dist/studio/assets/svg-BkV9LeqP.js +2 -0
- package/dist/studio/assets/{text-LISSAism.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 +27 -27
- package/plugin/skills/agent3d-create/SKILL.md +28 -27
- 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/templates/hero-photo-3d/assets/depth/street-depth.png +0 -0
- package/templates/hero-photo-3d/assets/manifest.json +3 -3
- package/templates/hero-photo-3d/assets/textures/street.webp +0 -0
- package/templates/hero-photo-3d/scene.json +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-BFJsr9Oo.js +0 -1
- package/dist/studio/assets/camera-DT0xHipx.js +0 -2
- package/dist/studio/assets/game-BXZEc9HN.js +0 -19
- package/dist/studio/assets/index-DVTzVcBD.js +0 -479
- package/dist/studio/assets/model-BqQW4Dg-.js +0 -2
- package/dist/studio/assets/physicsHost-DNdZ7AsT.js +0 -1
- package/dist/studio/assets/runtime-CMAP4azF.js +0 -572
- package/dist/studio/assets/svg-DkIOJjzS.js +0 -2
- package/templates/hero-photo-3d/assets/textures/street.jpg +0 -0
|
@@ -4,7 +4,7 @@ description: Build a mini game or an interactive 3D experience for a web page wi
|
|
|
4
4
|
license: PolyForm-Noncommercial-1.0.0
|
|
5
5
|
compatibility: Requires Node.js 22+ and Google Chrome (or Chromium/Edge) for renders.
|
|
6
6
|
metadata:
|
|
7
|
-
version: "0.
|
|
7
|
+
version: "0.4.0"
|
|
8
8
|
repository: "https://github.com/fleox/agent3d"
|
|
9
9
|
allowed-tools: Bash Read Write
|
|
10
10
|
---
|
|
@@ -15,13 +15,13 @@ A game is an ordinary scene (`target.kind: "game"`) plus **scripts**: ES modules
|
|
|
15
15
|
|
|
16
16
|
**Language:** talk to the user in their language; keep commands, ids, code and files in English.
|
|
17
17
|
|
|
18
|
-
Every command is `npx -y @fleox/agent3d@0.
|
|
18
|
+
Every command is `npx -y @fleox/agent3d@0.4.0 <command> --json` with `--project <dir>`. Read `error.hint` when `ok` is false.
|
|
19
19
|
|
|
20
20
|
## Start
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
npx -y @fleox/agent3d@0.
|
|
24
|
-
npx -y @fleox/agent3d@0.
|
|
23
|
+
npx -y @fleox/agent3d@0.4.0 new dodge --target game --title "Dodge" --json
|
|
24
|
+
npx -y @fleox/agent3d@0.4.0 scene summary --project dodge --json
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
The game starter has a `kinematic` player moved by position, coins with a `coin` tag, a follow camera, a score HUD, a coin sound and `scripts/game.js` (move with arrows / WASD, collect coins). Game templates to start from (`templates list --json`): `game-coin-collector`, `game-runner`, `game-maze`, `game-tap-targets`, `game-physics-playground` (rigid bodies, impulses, impact sounds) — `new my-game --template game-physics-playground --json`. A complete validated example (lane runner: lanes, spawning by cloning, difficulty ramp, best score, attract mode) is in skill `agent3d-create` → `references/recipes.md` ("Lane runner game"; "Physics toss game" for rigid bodies); patterns in [references/game-patterns.md](references/game-patterns.md); the full API in [references/script-api.md](references/script-api.md).
|
|
@@ -55,15 +55,15 @@ Scripts only get `api`. `check` fails (`forbidden-script`) on `fetch`, `XMLHttpR
|
|
|
55
55
|
1. Design the loop with the user in one paragraph: goal, controls (keyboard + touch), how you lose, what the score counts, how long a round lasts (30–90 s for a web page).
|
|
56
56
|
2. Declare the scene: player and obstacle templates (hidden, with `tags` and a `body`), camera, HUD elements per phase, sounds (`catalog sounds`), `data` for tuning.
|
|
57
57
|
3. Write the script (patterns below). Keep it under ~200 lines; one file is fine.
|
|
58
|
-
4. Validate and lint: `npx -y @fleox/agent3d@0.
|
|
58
|
+
4. Validate and lint: `npx -y @fleox/agent3d@0.4.0 check --project dodge --json` (sandbox errors carry the line: `scripts/game.js:12`).
|
|
59
59
|
5. Render several moments and LOOK:
|
|
60
60
|
```bash
|
|
61
|
-
npx -y @fleox/agent3d@0.
|
|
61
|
+
npx -y @fleox/agent3d@0.4.0 render --project dodge --sheet --frames 0,2,4,6 --json
|
|
62
62
|
```
|
|
63
63
|
Plain renders have no player input, so the game must show something on its own: an **attract mode** (an autopilot plays during the `ready` phase, behind the title and Play button). The HUD is captured because the scene has a `ui` (`--capture page` forces it); posters (`export --format poster`, the embed's `poster.webp`) and videos show the canvas only, without the HUD. Check `data.issues` and `data.consoleErrors` for `script-error`. `data.state` is the script's `api.state` after the last frame (e.g. `{ "score": 0, "phase": "ready" }`); frame and sheet paths are relative to the project folder `data.dir`.
|
|
64
64
|
6. **Play it headlessly** with `--input`: a JSON script of simulated keys / clicks applied while seeking (frames are rendered in time order), then check `data.state` and the frames:
|
|
65
65
|
```bash
|
|
66
|
-
npx -y @fleox/agent3d@0.
|
|
66
|
+
npx -y @fleox/agent3d@0.4.0 render --project dodge --sheet --frames 0,1,2,3 --input '[{"t": 0.2, "click": [0, -0.3]}, {"t": 0.5, "key": "ArrowLeft", "hold": 0.6}, {"t": 1.5, "key": "Space", "down": true}, {"t": 1.6, "key": "Space", "down": false}]' --json
|
|
67
67
|
```
|
|
68
68
|
Events: `{ "t", "key", "down" }` (`key` is a `KeyboardEvent.code`: `ArrowLeft`, `KeyA`, `Space`…; `down: false` releases), `{ "t", "key", "hold": seconds }` (press and release), `{ "t", "click": [x, y] }`, `{ "t", "pointer": [x, y] }` (add `"down": true` / `false` to press / release there), `{ "t", "pointerDown": [x, y] }` and `{ "t", "pointerUp": [x, y] }` (hold the pointer: `api.input.pointer.down`), `{ "t", "drag": { "from": [x, y], "to": [x, y], "duration": 0.4 } }` (press, move, release), `{ "t", "swipe": "left" | "right" | "up" | "down" }` (what `api.input.swipe()` returns next step), `{ "t", "scroll": 0.5 }` (page scroll progress, scroll-driven scenes), `{ "t", "ui": "retryBtn" }` (click that HUD button by id — a warning in `inputWarnings` when it is hidden at that time), `{ "t", "emit": "retry" }` (emit the event / button action directly), `{ "t", "segment": "intro" }` (play a timeline segment) — canvas coordinates −1..1, y up (a canvas `click` never presses a HUD button: use `ui`). Unknown fields are rejected (exit 2, the hint lists the valid shapes). Test the touch controls too, e.g. `--input '[{"t": 0.5, "swipe": "left"}, {"t": 1.2, "drag": {"from": [0, -0.5], "to": [0, 0.3], "duration": 0.3}}]'`. Use `@inputs.json` for longer scripts. MCP: `render_preview` takes the same events as `input`.
|
|
69
69
|
7. To test a state that is hard to reach with input (game over screen, high score), temporarily set the starting phase in `api.data` (e.g. `"startPhase": "over"`), render, then restore it.
|
|
@@ -4,7 +4,7 @@ description: Export an Agent3D scene and put it on a website - embed folder (Web
|
|
|
4
4
|
license: PolyForm-Noncommercial-1.0.0
|
|
5
5
|
compatibility: Requires Node.js 22+ and Google Chrome (or Chromium/Edge) for renders.
|
|
6
6
|
metadata:
|
|
7
|
-
version: "0.
|
|
7
|
+
version: "0.4.0"
|
|
8
8
|
repository: "https://github.com/fleox/agent3d"
|
|
9
9
|
allowed-tools: Bash Read Write
|
|
10
10
|
---
|
|
@@ -13,12 +13,12 @@ allowed-tools: Bash Read Write
|
|
|
13
13
|
|
|
14
14
|
**Language:** talk to the user in their language; keep commands, code and files in English.
|
|
15
15
|
|
|
16
|
-
Every command is `npx -y @fleox/agent3d@0.
|
|
16
|
+
Every command is `npx -y @fleox/agent3d@0.4.0 <command> --json` with `--project <dir>`. Read `error.hint` when `ok` is false.
|
|
17
17
|
|
|
18
18
|
## Before exporting
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npx -y @fleox/agent3d@0.
|
|
21
|
+
npx -y @fleox/agent3d@0.4.0 check --project my-banner --render --json
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
No errors, no warnings (or warnings the user accepted). Keep the `licences` list: credits ship in the export.
|
|
@@ -39,15 +39,15 @@ Every asset the scene uses is copied into the export (never hotlinked): a 3D pho
|
|
|
39
39
|
Default outputs land in `<project>/dist/`. A relative `--out` is resolved from the **project folder** (like every output path of `render` and `export`): `--project my-banner --out dist/promo.mp4` writes `my-banner/dist/promo.mp4`; absolute paths are kept.
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
npx -y @fleox/agent3d@0.
|
|
43
|
-
npx -y @fleox/agent3d@0.
|
|
44
|
-
npx -y @fleox/agent3d@0.
|
|
45
|
-
npx -y @fleox/agent3d@0.
|
|
46
|
-
npx -y @fleox/agent3d@0.
|
|
47
|
-
npx -y @fleox/agent3d@0.
|
|
48
|
-
npx -y @fleox/agent3d@0.
|
|
49
|
-
npx -y @fleox/agent3d@0.
|
|
50
|
-
npx -y @fleox/agent3d@0.
|
|
42
|
+
npx -y @fleox/agent3d@0.4.0 export --project my-banner --json
|
|
43
|
+
npx -y @fleox/agent3d@0.4.0 export --project my-banner --name spring-banner --out ./site/agent3d --json
|
|
44
|
+
npx -y @fleox/agent3d@0.4.0 export --project my-banner --base-url /wp-content/uploads/agent3d/ --cache-bust --out ./wp --json
|
|
45
|
+
npx -y @fleox/agent3d@0.4.0 export --project my-banner --optimize --json
|
|
46
|
+
npx -y @fleox/agent3d@0.4.0 export --format zip --project my-banner --json
|
|
47
|
+
npx -y @fleox/agent3d@0.4.0 export --format single-html --project my-banner --json
|
|
48
|
+
npx -y @fleox/agent3d@0.4.0 export --format poster --time 2 --image png --quality high --transparent --project my-banner --json
|
|
49
|
+
npx -y @fleox/agent3d@0.4.0 export --format video --out dist/promo.mp4 --duration 8 --fps 30 --size 1920x1080 --project my-banner --json
|
|
50
|
+
npx -y @fleox/agent3d@0.4.0 export --format gif --duration 4 --project my-banner --json
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
Embed / zip options:
|
|
@@ -62,19 +62,21 @@ Embed / zip options:
|
|
|
62
62
|
| `--no-poster` | No poster nor og-image (no Chrome needed). The element then shows nothing until the first frame and has no fallback without WebGL: prefer keeping it |
|
|
63
63
|
| `--no-og` | No `<name>/og-image.png` (1200×630 social preview). To use it, add `<meta property="og:image" content="https://<site>/…/<name>/og-image.png">` and `<meta name="twitter:card" content="summary_large_image">` to the page head — crawlers need an absolute URL (the demo `index.html` uses a relative one) |
|
|
64
64
|
| `--no-extras` | No `EMBED.md` and no `frameworks/` |
|
|
65
|
+
| `--runtime auto\|full` | `auto` (default, also for `single-html`): a scene that is a single 3D photo (one `photo` object in parallax mode or without depth, fixed perspective camera, `#hex` or transparent background, no timeline / interactions / postfx / scripts / text) ships the photo-only lite runtime `agent3d-photo.js` (~14 KB gzipped, no three.js) instead of ~210 KB. `full` forces `agent3d-runtime.js` |
|
|
65
66
|
|
|
66
67
|
- **Page weight**: for a brief like "under 300 KB", quote `pageKb` / `pageKbGzip` from the export result (what a visitor downloads for this scene, runtime chunks included — `folderKb` counts every file written, unused chunks too). `--prune-runtime` copies only the chunks this scene loads (a smaller folder to upload) — only when this runtime folder serves this scene alone; other scenes sharing `agent3d-runtime/` may need the chunks it leaves out.
|
|
68
|
+
- **3D photo heroes**: check the result's `runtime`. `"photo-lite"` = the light runtime (the snippet loads `agent3d-runtime/agent3d-photo.js`); `"full"` comes with `runtimeReasons` (e.g. `"post effects (postfx)"`, `"2 objects (the lite runtime shows exactly one photo)"`). When the brief is about page weight and the reasons are cosmetic (a vignette, a 3D headline that could be HTML text over the element), tell the user what removing them would save. The lite and full runtimes render the same pixels.
|
|
67
69
|
- Exporting again into a non-empty folder prints a plan (`needsConfirmation`, with the existing entries): re-run with `--yes` after the user agreed.
|
|
68
|
-
- The result gives `snippet`, `head` (all modulepreload links), `integrity`, `runtimeDir`, `out`, `entry` (the demo page, or the zip / html file), `pageKb` / `pageKbGzip` (what a visitor downloads for this scene: the runtime entry + the lazy chunks it uses + scene, assets, scripts, poster — quote this one as the page weight), `folderKb` (= `totalKb`, every file written, all chunks and og-image included), `page` (runtime files loaded / chunks skipped), `sizes` (`runtimeKb`, `sceneKb`, `assetsKb`, `scriptsKb`, `posterKb`), `credits`, `issues` (+ `optimized` with `--optimize`). Media formats return `{ format, path, codec?, frames?, fps?, duration?, size, bytes }`.
|
|
70
|
+
- The result gives `snippet`, `head` (all modulepreload links), `integrity`, `runtimeDir`, `out`, `entry` (the demo page, or the zip / html file), `pageKb` / `pageKbGzip` (what a visitor downloads for this scene: the runtime entry + the lazy chunks it uses + scene, assets, scripts, poster — quote this one as the page weight), `folderKb` (= `totalKb`, every file written, all chunks and og-image included), `page` (runtime files loaded / chunks skipped), `runtime` (`photo-lite` or `full`, + `runtimeReasons`), `sizes` (`runtimeKb`, `sceneKb`, `assetsKb`, `scriptsKb`, `posterKb`), `credits`, `issues` (+ `optimized` with `--optimize`). Media formats return `{ format, path, codec?, frames?, fps?, duration?, size, bytes }`.
|
|
69
71
|
|
|
70
72
|
Media straight from `render` (frame-exact, any size / fps; LOOK at a few frames of the result):
|
|
71
73
|
|
|
72
74
|
```bash
|
|
73
|
-
npx -y @fleox/agent3d@0.
|
|
74
|
-
npx -y @fleox/agent3d@0.
|
|
75
|
-
npx -y @fleox/agent3d@0.
|
|
76
|
-
npx -y @fleox/agent3d@0.
|
|
77
|
-
npx -y @fleox/agent3d@0.
|
|
75
|
+
npx -y @fleox/agent3d@0.4.0 render --video renders/promo.mp4 --duration 6 --size 1920x1080 --quality high --project my-banner --json
|
|
76
|
+
npx -y @fleox/agent3d@0.4.0 render --gif renders/banner.gif --duration 4 --project my-banner --json
|
|
77
|
+
npx -y @fleox/agent3d@0.4.0 render --webp renders/banner.webp --duration 4 --project my-banner --json
|
|
78
|
+
npx -y @fleox/agent3d@0.4.0 render --frames 2 --size 2400x600 --quality ultra --transparent --project my-banner --json
|
|
79
|
+
npx -y @fleox/agent3d@0.4.0 render --scroll 0.5 --project my-scroll-story --json
|
|
78
80
|
```
|
|
79
81
|
|
|
80
82
|
`--quality high|ultra` supersamples 2× / 3× (smoother edges), `--transparent` gives alpha PNG / GIF / WebP, `--scroll 0.5` holds a scroll-driven scene at that scroll progress, `--fps` / `--start` / `--bitrate` tune videos, `--yes` overwrites an existing media file. `--video`, `--gif` and `--webp` paths (like `--out`) are relative to the project folder. MP4 needs Google Chrome or Edge (H.264 encoder); with Chromium, render `.webm`. Videos and posters capture the WebGL canvas only (no HUD).
|
|
@@ -82,8 +84,8 @@ npx -y @fleox/agent3d@0.3.0 render --scroll 0.5 --project my-scroll-story --json
|
|
|
82
84
|
Scenes whose timeline waits for the visitor (`autoplay: false`, `trigger: "manual"` / `"click"`, segments played by interactions) are still at t = 0 in a plain render: film the segment with `--segment`, or play the interaction with `--input` (frames, `--video`, `--gif` and `--webp` all apply it):
|
|
83
85
|
|
|
84
86
|
```bash
|
|
85
|
-
npx -y @fleox/agent3d@0.
|
|
86
|
-
npx -y @fleox/agent3d@0.
|
|
87
|
+
npx -y @fleox/agent3d@0.4.0 render --video renders/celebrate.webm --segment celebrate --duration 4 --project my-mascot --json
|
|
88
|
+
npx -y @fleox/agent3d@0.4.0 render --sheet --frames 0,1,2,3 --input '[{"t": 0, "segment": "celebrate"}]' --project my-mascot --json
|
|
87
89
|
```
|
|
88
90
|
|
|
89
91
|
`--reduced-motion` renders what visitors with prefers-reduced-motion see.
|
|
@@ -114,7 +116,7 @@ Always paste the snippet from the export result (hashes and file names change wi
|
|
|
114
116
|
Write `{data.key}` in a text object's `text` (or an `href`), give defaults in `scene.data`, and the page fills them per embed — no re-export:
|
|
115
117
|
|
|
116
118
|
```bash
|
|
117
|
-
npx -y @fleox/agent3d@0.
|
|
119
|
+
npx -y @fleox/agent3d@0.4.0 scene patch --project my-banner '[{"op":"set","path":"data","value":{"title":"Spring sale"}},{"op":"updateObject","id":"title","set":{"text":"{data.title}"}}]' --json
|
|
118
120
|
```
|
|
119
121
|
|
|
120
122
|
```html
|
|
@@ -127,7 +129,7 @@ Placeholders work in text objects' `text`, any object's `href` and HUD texts. `{
|
|
|
127
129
|
|
|
128
130
|
Step-by-step per platform (plain HTML, WordPress, AgentCMS, React / Next.js, Astro, Vue / Nuxt, Svelte, static hosts and CDNs): [references/integrations.md](references/integrations.md). In short:
|
|
129
131
|
|
|
130
|
-
- **Plain HTML / static hosts** (Netlify, GitHub Pages, Cloudflare Pages, S3): copy the export folder next to the page, paste the snippet. Open `index.html` of the export through a local server (`npx -y @fleox/agent3d@0.
|
|
132
|
+
- **Plain HTML / static hosts** (Netlify, GitHub Pages, Cloudflare Pages, S3): copy the export folder next to the page, paste the snippet. Open `index.html` of the export through a local server (`npx -y @fleox/agent3d@0.4.0 serve --project my-banner` previews the project; module scripts don't run from `file://`: opened that way, the demo page only shows the poster and a note asking for a web server).
|
|
131
133
|
- **WordPress**: export with `--base-url /wp-content/uploads/agent3d/`, upload the export folder there (SFTP / the host's file manager), then a **Custom HTML** block with the snippet. The media library refuses `.js` / `.json` files.
|
|
132
134
|
- **Webflow / Shopify**: host the folder on a static host or CDN, export with `--base-url https://…/`, paste the snippet in an Embed element / Custom Liquid section.
|
|
133
135
|
- **Squarespace / Wix / Framer**: `single-html` in an `<iframe>`.
|
|
@@ -7,7 +7,7 @@ All examples assume the embed export was uploaded to `/agent3d/` at the root of
|
|
|
7
7
|
/agent3d/spring-banner/scene.json (+ assets/, scripts/, poster.webp, og-image.png, CREDITS.txt)
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
Export straight into that layout with `npx -y @fleox/agent3d@0.
|
|
10
|
+
Export straight into that layout with `npx -y @fleox/agent3d@0.4.0 export --project spring-banner --out ./public/agent3d --base-url /agent3d/ --json` (the `<name>` folder defaults to the project name; `--name` changes it; `--base-url` writes root-absolute URLs in the snippet, the wrappers and EMBED.md). Paste the `snippet` of the result: the examples below shorten the integrity hashes and the poster markup.
|
|
11
11
|
|
|
12
12
|
## Plain HTML
|
|
13
13
|
|
|
Binary file
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
{
|
|
4
4
|
"path": "assets/depth/street-depth.png",
|
|
5
5
|
"kind": "texture",
|
|
6
|
-
"bytes":
|
|
6
|
+
"bytes": 80233,
|
|
7
7
|
"source": "depth-anything-v2-small",
|
|
8
8
|
"sourceUrl": "https://huggingface.co/onnx-community/depth-anything-v2-small",
|
|
9
9
|
"license": "CC0-1.0",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"addedAt": "2026-11-26T00:00:00.000Z"
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
"path": "assets/textures/street.
|
|
15
|
+
"path": "assets/textures/street.webp",
|
|
16
16
|
"kind": "texture",
|
|
17
|
-
"bytes":
|
|
17
|
+
"bytes": 329510,
|
|
18
18
|
"source": "local",
|
|
19
19
|
"sourceUrl": "https://commons.wikimedia.org/wiki/File:Herzog-Friedrich-Stra%C3%9Fe_in_Innsbruck%27s_Historic_Old_Town,_Austria.jpg",
|
|
20
20
|
"license": "CC0-1.0",
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e){return e.endsWith(`/`)?e:e+`/`}function t(t){let n=e(t.assetBase??`./`),r=e(t.libraryBase??n+`assets/library/`),i=t.assetUrls??{};return e=>{if(i[e])return i[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`),i[`library:`+t]?i[`library:`+t]:r+t}return n+e.replace(/^\.\//,``)}}var n=/* @__PURE__ */ new Map;function r(e){let t=n.get(e);return t||(t=fetch(e).then(t=>{if(!t.ok)throw Error(`HTTP ${t.status} for ${e}`);return t.text()}),t.catch(()=>n.delete(e)),n.set(e,t)),t}async function i(e){return JSON.parse(await r(e))}var a=/* @__PURE__ */ new Map;function o(e){let t=a.get(e);return t||(t=import(`./three.module-DnaBiDAJ.js`).then(e=>e.a).then(t=>new Promise((n,r)=>{new t.TextureLoader().load(e,n,void 0,()=>r(/* @__PURE__ */ Error(`Cannot load texture ${e}`)))})),t.catch(()=>a.delete(e)),a.set(e,t)),t.then(e=>{let t=e.clone();return t.needsUpdate=!0,t})}export{o as i,i as n,r,t};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import{Lt as e,Mn as t,Nn as n,Yt as r}from"./three.module-DnaBiDAJ.js";import{t as i}from"./random-eeej60NW.js";import{d as a,s as o,t as s}from"./util-CyaW1fcW.js";function c(e,t,n){let r=null,i=null,a=!!e?.muted,o=null,s=/* @__PURE__ */ new Map,c=null,l=!!e?.music,u=()=>import(`./audio-DbVNbf-r.js`).then(e=>o=e.SOUND_IMPLS).catch(()=>o={}),d=e=>{let i=s.get(e);if(!i&&r){let a=r;i=fetch(t(e)).then(e=>e.arrayBuffer()).then(e=>a.decodeAudioData(e)).catch(t=>(n(t.message,e),null)),s.set(e,i)}return i??Promise.resolve(null)},f=(e,t=!1)=>{if(!r||!i)return null;let n=e.volume??1;if(e.preset){let t=o?.[e.preset];return t?t.play(r,i,n):null}if(e.src){let a=r,o=i,s=null,c=!1;return d(e.src).then(e=>{if(!e||c)return;s=a.createBufferSource(),s.buffer=e,s.loop=t;let r=a.createGain();r.gain.value=n,s.connect(r).connect(o),s.start()}),{stop(){c=!0;try{s?.stop()}catch{}}}}return null},p=()=>{!c&&e?.music&&!a&&r&&(c=f(e.music,e.music.loop!==!1))};return u(),{play(t){if(a||!r)return;let n=e?.sounds?.[t];n?f(n):o?.[t]&&o[t].play(r,i,1)},music(e){l=e,e?p():(c?.stop(),c=null)},muted:()=>a,setMuted(t){a=t,i&&r&&i.gain.setTargetAtTime(+!t,r.currentTime,.02),t?(c?.stop(),c=null):(l||e?.music)&&(l=!0,p())},unlock(){if(r){r.state===`suspended`&&r.resume();return}let e=globalThis.AudioContext??globalThis.webkitAudioContext;if(e)try{r=new e,i=r.createGain(),i.gain.value=+!a,i.connect(r.destination),l&&p()}catch(e){n(e.message)}},dispose(){c?.stop(),r?.close().catch(()=>void 0),r=null}}}var l={aliceblue:`f0f8ff`,antiquewhite:`faebd7`,aqua:`00ffff`,aquamarine:`7fffd4`,azure:`f0ffff`,beige:`f5f5dc`,bisque:`ffe4c4`,black:`000000`,blanchedalmond:`ffebcd`,blue:`0000ff`,blueviolet:`8a2be2`,brown:`a52a2a`,burlywood:`deb887`,cadetblue:`5f9ea0`,chartreuse:`7fff00`,chocolate:`d2691e`,coral:`ff7f50`,cornflowerblue:`6495ed`,cornsilk:`fff8dc`,crimson:`dc143c`,cyan:`00ffff`,darkblue:`00008b`,darkcyan:`008b8b`,darkgoldenrod:`b8860b`,darkgray:`a9a9a9`,darkgreen:`006400`,darkgrey:`a9a9a9`,darkkhaki:`bdb76b`,darkmagenta:`8b008b`,darkolivegreen:`556b2f`,darkorange:`ff8c00`,darkorchid:`9932cc`,darkred:`8b0000`,darksalmon:`e9967a`,darkseagreen:`8fbc8f`,darkslateblue:`483d8b`,darkslategray:`2f4f4f`,darkslategrey:`2f4f4f`,darkturquoise:`00ced1`,darkviolet:`9400d3`,deeppink:`ff1493`,deepskyblue:`00bfff`,dimgray:`696969`,dimgrey:`696969`,dodgerblue:`1e90ff`,firebrick:`b22222`,floralwhite:`fffaf0`,forestgreen:`228b22`,fuchsia:`ff00ff`,gainsboro:`dcdcdc`,ghostwhite:`f8f8ff`,gold:`ffd700`,goldenrod:`daa520`,gray:`808080`,green:`008000`,greenyellow:`adff2f`,grey:`808080`,honeydew:`f0fff0`,hotpink:`ff69b4`,indianred:`cd5c5c`,indigo:`4b0082`,ivory:`fffff0`,khaki:`f0e68c`,lavender:`e6e6fa`,lavenderblush:`fff0f5`,lawngreen:`7cfc00`,lemonchiffon:`fffacd`,lightblue:`add8e6`,lightcoral:`f08080`,lightcyan:`e0ffff`,lightgoldenrodyellow:`fafad2`,lightgray:`d3d3d3`,lightgreen:`90ee90`,lightgrey:`d3d3d3`,lightpink:`ffb6c1`,lightsalmon:`ffa07a`,lightseagreen:`20b2aa`,lightskyblue:`87cefa`,lightslategray:`778899`,lightslategrey:`778899`,lightsteelblue:`b0c4de`,lightyellow:`ffffe0`,lime:`00ff00`,limegreen:`32cd32`,linen:`faf0e6`,magenta:`ff00ff`,maroon:`800000`,mediumaquamarine:`66cdaa`,mediumblue:`0000cd`,mediumorchid:`ba55d3`,mediumpurple:`9370db`,mediumseagreen:`3cb371`,mediumslateblue:`7b68ee`,mediumspringgreen:`00fa9a`,mediumturquoise:`48d1cc`,mediumvioletred:`c71585`,midnightblue:`191970`,mintcream:`f5fffa`,mistyrose:`ffe4e1`,moccasin:`ffe4b5`,navajowhite:`ffdead`,navy:`000080`,oldlace:`fdf5e6`,olive:`808000`,olivedrab:`6b8e23`,orange:`ffa500`,orangered:`ff4500`,orchid:`da70d6`,palegoldenrod:`eee8aa`,palegreen:`98fb98`,paleturquoise:`afeeee`,palevioletred:`db7093`,papayawhip:`ffefd5`,peachpuff:`ffdab9`,peru:`cd853f`,pink:`ffc0cb`,plum:`dda0dd`,powderblue:`b0e0e6`,purple:`800080`,rebeccapurple:`663399`,red:`ff0000`,rosybrown:`bc8f8f`,royalblue:`4169e1`,saddlebrown:`8b4513`,salmon:`fa8072`,sandybrown:`f4a460`,seagreen:`2e8b57`,seashell:`fff5ee`,sienna:`a0522d`,silver:`c0c0c0`,skyblue:`87ceeb`,slateblue:`6a5acd`,slategray:`708090`,slategrey:`708090`,snow:`fffafa`,springgreen:`00ff7f`,steelblue:`4682b4`,tan:`d2b48c`,teal:`008080`,thistle:`d8bfd8`,tomato:`ff6347`,turquoise:`40e0d0`,violet:`ee82ee`,wheat:`f5deb3`,white:`ffffff`,whitesmoke:`f5f5f5`,yellow:`ffff00`,yellowgreen:`9acd32`},u=(e,t,n)=>Math.min(n,Math.max(t,e));function d(e){if(!/^[0-9a-f]+$/i.test(e)||((e.length===3||e.length===4)&&(e=[...e].map(e=>e+e).join(``)),e.length!==6&&e.length!==8))return null;let t=t=>parseInt(e.slice(t,t+2),16);return{r:t(0),g:t(2),b:t(4),a:e.length===8?t(6)/255:1}}function f(e,t){let n=/^(-?\d*\.?\d+(?:e-?\d+)?)(%?)$/i.exec(e.trim());if(!n)return null;let r=Number(n[1]);return n[2]?r/100*t:r}function p(e){let t=/^(-?\d*\.?\d+)(deg|rad|turn|grad)?$/i.exec(e.trim());if(!t)return null;let n=Number(t[1]);switch((t[2]??`deg`).toLowerCase()){case`rad`:return n*180/Math.PI;case`turn`:return n*360;case`grad`:return n*.9;default:return n}}function m(e){let t=e.split(`/`);if(t.length>2)return null;let n=(t[0].includes(`,`)?t[0].split(`,`):t[0].trim().split(/\s+/)).map(e=>e.trim()).filter(e=>e!==``);return t.length===2&&n.push(t[1].trim()),n}function h(e,t,n){e=(e%360+360)%360;let r=(1-Math.abs(2*n-1))*t,i=r*(1-Math.abs(e/60%2-1)),a=n-r/2,[o,s,c]=e<60?[r,i,0]:e<120?[i,r,0]:e<180?[0,r,i]:e<240?[0,i,r]:e<300?[i,0,r]:[r,0,i];return[(o+a)*255,(s+a)*255,(c+a)*255]}function g(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();if(!t)return null;if(t.startsWith(`#`))return d(t.slice(1));if(t===`transparent`)return{r:0,g:0,b:0,a:0};let n=l[t];if(n)return d(n);let r=/^(rgba?|hsla?)\((.*)\)$/.exec(t);if(!r)return null;let i=m(r[2]);if(!i||i.length!==3&&i.length!==4)return null;let a=i.length===4?f(i[3],1):1;if(a===null)return null;if(r[1].startsWith(`rgb`)){let[e,t,n]=i.slice(0,3).map(e=>f(e,255));return e===null||t===null||n===null?null:{r:u(e,0,255),g:u(t,0,255),b:u(n,0,255),a:u(a,0,1)}}let o=p(i[0]),s=f(i[1],1),c=f(i[2],1);if(o===null||s===null||c===null||!i[1].trim().endsWith(`%`)||!i[2].trim().endsWith(`%`))return null;let[g,_,v]=h(o,u(s,0,1),u(c,0,1));return{r:g,g:_,b:v,a:u(a,0,1)}}function _(e){let t=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}function v(e,t){let n=_(e),r=_(t);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)}function y(e){let t=g(e);return t?v(t,{r:255,g:255,b:255,a:1})>=v(t,{r:17,g:19,b:24,a:1})?`#ffffff`:`#111318`:`#ffffff`}function b(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(/\s/.test(r)){n++;continue}if(/[0-9]/.test(r)||r===`-`&&/[0-9]/.test(e[n+1]??``)&&(t.length===0||t[t.length-1].t===`op`)){let r=n+1;for(;r<e.length&&/[0-9.]/.test(e[r]);)r++;t.push({t:`num`,v:Number(e.slice(n,r))}),n=r;continue}if(r===`'`||r===`"`){let i=n+1,a=``;for(;i<e.length&&e[i]!==r;)e[i]===`\\`&&i+1<e.length&&i++,a+=e[i++];if(i>=e.length)throw Error(`Unterminated string`);t.push({t:`str`,v:a}),n=i+1;continue}if(/[A-Za-z_$]/.test(r)){let r=n+1;for(;r<e.length&&/[A-Za-z0-9_$.]/.test(e[r]);)r++;t.push({t:`id`,v:e.slice(n,r)}),n=r;continue}let i=e.slice(n,n+3),a=e.slice(n,n+2);if(i===`===`||i===`!==`)t.push({t:`op`,v:i.slice(0,2)}),n+=3;else if([`==`,`!=`,`>=`,`<=`,`&&`,`||`].includes(a))t.push({t:`op`,v:a}),n+=2;else if(`!<>()`.includes(r))t.push({t:`op`,v:r}),n++;else throw Error(`Unexpected "${r}"`)}return t}var x=/* @__PURE__ */ new Set([`__proto__`,`prototype`,`constructor`]);function S(e,t){let n=t.split(`.`);n[0]===`state`&&n.shift();let r=e;for(let e of n){if(x.has(e)||typeof r!=`object`||!r||!Object.prototype.hasOwnProperty.call(r,e))return;r=r[e]}return r}function C(e,t){let n=b(e),r=0,i=()=>n[r],a=e=>i()?.t===`op`&&i().v===e;function o(){let e=n[r++];if(!e)throw Error(`Unexpected end`);if(e.t===`num`||e.t===`str`)return e.v;if(e.t===`id`)return e.v===`true`?!0:e.v===`false`?!1:e.v===`null`||e.v===`undefined`?null:S(t,e.v);if(e.v===`(`){let e=u();if(!a(`)`))throw Error(`Missing )`);return r++,e}throw Error(`Unexpected "${e.v}"`)}function s(){let e=o(),t=i();if(t?.t===`op`&&[`==`,`!=`,`>`,`<`,`>=`,`<=`].includes(t.v)){r++;let n=o(),i=e,a=n;switch(t.v){case`==`:return e==n||e==null&&n==null;case`!=`:return e!=n;case`>`:return i>a;case`<`:return i<a;case`>=`:return i>=a;default:return i<=a}}return e}function c(){return a(`!`)?(r++,!c()):s()}function l(){let e=c();for(;a(`&&`);){r++;let t=c();e&&=t}return e}function u(){let e=l();for(;a(`||`);){r++;let t=l();e||=t}return e}let d=u();if(r<n.length)throw Error(`Unexpected "${n[r].v}"`);return d}function w(e,t){if(e===void 0)return!0;if(typeof e==`boolean`)return e;try{return!!C(e,t)}catch{return!1}}function T(e,t){return e.replace(/\{([^{}]+)\}/g,(e,n)=>{let r=n.trim(),i;try{i=/^[A-Za-z_$][A-Za-z0-9_$.]*$/.test(r)?S(t,r):C(r,t)}catch{i=void 0}return i==null?``:String(typeof i==`number`?Number.isInteger(i)?i:Math.round(i*100)/100:i)})}var E={"top-left":`grid-row:1;grid-column:1;align-items:flex-start;align-self:start;`,top:`grid-row:1;grid-column:2;align-items:center;align-self:start;text-align:center;`,"top-right":`grid-row:1;grid-column:3;align-items:flex-end;align-self:start;text-align:right;`,left:`grid-row:2;grid-column:1;align-items:flex-start;align-self:center;`,center:`grid-row:2;grid-column:2;align-items:center;align-self:center;text-align:center;`,right:`grid-row:2;grid-column:3;align-items:flex-end;align-self:center;text-align:right;`,"bottom-left":`grid-row:3;grid-column:1;align-items:flex-start;align-self:end;`,bottom:`grid-row:3;grid-column:2;align-items:center;align-self:end;text-align:center;`,"bottom-right":`grid-row:3;grid-column:3;align-items:flex-end;align-self:end;text-align:right;`},D=(e,t,n)=>`font-size:${n}px;font-size:clamp(${e}px,min(${t}cqw,${(t*1.6).toFixed(1)}cqh),${n}px)`,O=(e,t,n,r)=>`
|
|
2
|
-
.a3d-hud{position:absolute;inset:0;pointer-events:none;font-family:${e};color:${t};z-index:2;overflow:hidden;user-select:none;-webkit-user-select:none;container-type:size;display:grid;grid-template-columns:minmax(min-content,1fr) fit-content(56%) minmax(min-content,1fr);grid-template-rows:auto minmax(0,1fr) auto}
|
|
3
|
-
.a3d-zone{display:flex;flex-direction:column;gap:8px;gap:clamp(4px,1.6cqw,8px);padding:14px;padding:clamp(8px,2.6cqw,14px);min-width:0;max-width:100%;box-sizing:border-box}
|
|
4
|
-
.a3d-el{line-height:1.2;text-shadow:0 1px 3px rgba(0,0,0,.45);white-space:pre-line;overflow-wrap:break-word}
|
|
5
|
-
.a3d-plain{${D(11,3.2,15)};font-weight:600}
|
|
6
|
-
.a3d-pill{${D(11,3,14)};font-weight:700;padding:.43em 1em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%;box-sizing:border-box;flex:none;border-radius:999px;background:rgba(0,0,0,.42);backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px);text-shadow:none}
|
|
7
|
-
.a3d-title{${D(20,7,44)};font-weight:800;letter-spacing:-.01em}
|
|
8
|
-
.a3d-subtitle{${D(12,3.6,18)};font-weight:500;opacity:.9}
|
|
9
|
-
.a3d-panel{${D(13,3.6,18)};font-weight:600;line-height:1.45;padding:1.1em 1.6em;border-radius:18px;background:rgba(10,12,20,.72);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);box-shadow:0 10px 34px rgba(0,0,0,.35);text-shadow:none;max-width:100%;box-sizing:border-box}
|
|
10
|
-
.a3d-panel::first-line{font-size:1.45em;font-weight:800}
|
|
11
|
-
.a3d-btn{pointer-events:auto;cursor:pointer;border:0;font:inherit;${D(12,3.4,15)};font-weight:700;color:${r};background:${n};padding:.67em 1.47em;border-radius:999px;box-shadow:0 4px 14px rgba(0,0,0,.25);transition:transform .12s ease,filter .12s ease;text-shadow:none;min-height:36px}
|
|
12
|
-
.a3d-btn:hover{transform:translateY(-1px);filter:brightness(1.08)}.a3d-btn:active{transform:translateY(1px)}
|
|
13
|
-
.a3d-bar{width:160px;width:clamp(80px,30cqw,160px);height:10px;height:clamp(7px,2cqw,10px);border-radius:999px;background:rgba(0,0,0,.35);overflow:hidden}
|
|
14
|
-
.a3d-bar>i{display:block;height:100%;width:0;background:${n};border-radius:inherit}
|
|
15
|
-
.a3d-toast{position:absolute;left:50%;bottom:18%;transform:translateX(-50%);max-width:86%;box-sizing:border-box;text-align:center;padding:.53em 1.2em;border-radius:999px;background:rgba(0,0,0,.6);color:#fff;font-weight:700;${D(12,3.4,15)};transition:opacity .25s ease;text-shadow:none}
|
|
16
|
-
.a3d-mute{pointer-events:auto;width:34px;height:34px;width:clamp(28px,8cqw,34px);height:clamp(28px,8cqw,34px);border-radius:50%;border:0;background:rgba(0,0,0,.4);color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0;flex:none}
|
|
17
|
-
.a3d-mute svg{width:55%;height:55%}
|
|
18
|
-
`,k=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5 6 9H2v6h4l5 4V5z"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/><path d="M19 5a10 10 0 0 1 0 14"/></svg>`,A=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5 6 9H2v6h4l5 4V5z"/><path d="m23 9-6 6"/><path d="m17 9 6 6"/></svg>`;function j(e,t,n){let r=e.ownerDocument,i=r.createElement(`div`);i.className=`a3d-hud`,i.setAttribute(`aria-live`,`polite`);let a=r.createElement(`style`),o=t?.accent??`#ff006e`;a.textContent=O(t?.font??`system-ui,-apple-system,'Segoe UI',Roboto,sans-serif`,t?.color??`#ffffff`,o,t?.buttonText??y(o)),i.appendChild(a);let s=/* @__PURE__ */ new Map,c=e=>{let t=s.get(e);return t||(t=r.createElement(`div`),t.className=`a3d-zone`,t.style.cssText=E[e]??E[`top-left`],t.dataset.anchor=e,i.appendChild(t),s.set(e,t)),t},l=[[`top-left`,`top`,`top-right`],[`left`,`center`,`right`],[`bottom-left`,`bottom`,`bottom-right`]],u=()=>{for(let[e,t,n]of l){let r=s.get(t);r&&(r.style.gridColumn=s.has(e)||s.has(n)?`2`:`1 / -1`)}},d=/* @__PURE__ */ new Map;for(let e of t?.elements??[]){let t,i;if(e.type===`button`){let i=r.createElement(`button`);i.type=`button`,i.className=`a3d-btn`,i.addEventListener(`click`,t=>{t.stopPropagation(),e.action&&n(e.action)}),i.addEventListener(`pointerdown`,e=>e.stopPropagation()),t=i}else e.type===`bar`?(t=r.createElement(`div`),t.className=`a3d-bar`,i=r.createElement(`i`),t.appendChild(i)):(t=r.createElement(`div`),t.className=`a3d-el a3d-${e.style??`plain`}`);e.color&&(t.style.color=e.color,e.type===`bar`&&i&&(i.style.background=e.color)),e.background&&(t.style.background=e.background),e.type===`button`&&e.background&&!e.color&&(t.style.color=y(e.background)),t.dataset.id=e.id,c(e.anchor??`top-left`).appendChild(t),d.set(e.id,{def:e,node:t,fill:i,override:{},last:``})}u(),e.appendChild(i);let f=null,p=0,m=null,h=null,g=null;return{root:i,setTimeline(e){g=e},set(e,t){let n=d.get(e);n&&Object.assign(n.override,t)},toast(e,t=2){m={text:e,seconds:t}},update(e,t){let n=g&&!Object.prototype.hasOwnProperty.call(e,`timeline`)?{...e,timeline:g}:e;for(let e of d.values()){let t=e.override.visible??w(e.def.visible,n);if(e.node.style.display=t?``:`none`,!t)continue;if(e.def.type===`bar`){let t=e.override.value??Number(e.def.value?S(n,e.def.value):0),r=Math.max(0,Math.min(1,Number.isFinite(t)?t:0));e.fill.style.width=`${(r*100).toFixed(1)}%`;continue}let r=e.override.text??T(e.def.text??``,n);r!==e.last&&(e.node.textContent=r,e.last=r)}m&&=(f||(f=r.createElement(`div`),f.className=`a3d-toast`,i.appendChild(f)),f.textContent=m.text,f.style.opacity=`1`,p=t+m.seconds,null),f&&t>p&&(f.style.opacity=`0`)},setMuteButton(e,t){e===null?(h?.remove(),h=null):(h||(h=r.createElement(`button`),h.type=`button`,h.className=`a3d-mute`,h.addEventListener(`pointerdown`,e=>e.stopPropagation()),h.addEventListener(`click`,e=>{e.stopPropagation(),t?.()}),c(`bottom-right`).appendChild(h),u()),h.innerHTML=e?A:k,h.setAttribute(`aria-label`,e?`Unmute sound`:`Mute sound`))},dispose(){i.remove()}}}var M=null,N=()=>M??=import(`./physicsHost-ChPgysMQ.js`);function P(e,t=1,n){return{get x(){return e().x/t},set x(r){e().x=r*t,n?.()},get y(){return e().y/t},set y(r){e().y=r*t,n?.()},get z(){return e().z/t},set z(r){e().z=r*t,n?.()},set(r,i,a){e().set(r*t,i*t,a*t),n?.()}}}var F=/* @__PURE__ */ new Map,I=class l{opts;world;physics=null;state={};hud=null;audio;instances=[];factories=[];objCache=/* @__PURE__ */ new Map;handlers=/* @__PURE__ */ new Map;collisionHandlers=[];collisionEndHandlers=[];triggerEnterHandlers=[];triggerExitHandlers=[];rng;simTime=0;acc=0;stepDt;pendingPressed=/* @__PURE__ */ new Set;pendingJust=!1;pendingSwipe=null;stepPressed=/* @__PURE__ */ new Set;stepJust=!1;stepSwipe=null;shake={intensity:0,duration:0,until:0};restartRequested=!1;cloneCounter=0;unlockListeners=null;api;constructor(e){this.opts=e,this.stepDt=Math.min(Math.max(e.scene.physics?.step??1/60,1/480),1/10),this.rng=i(e.scene.seed??1),this.audio=c(e.scene.audio,e.resolveAsset,(t,n)=>e.issue({code:`asset-load`,message:t,path:n})),this.api=this.createApi()}static async create(e,t){let n=new l(e);if(n.hud=e.scene.ui?.elements?.length||e.scene.audio?j(e.container,e.scene.ui,e=>n.emit(e)):null,e.scene.audio&&n.hud){let e=()=>n.hud.setMuteButton(n.audio.muted(),()=>{n.audio.unlock(),n.audio.setMuted(!n.audio.muted()),e()});e()}if(!e.deterministic){let t=()=>n.audio.unlock();e.container.addEventListener(`pointerdown`,t),e.container.addEventListener(`keydown`,t),n.unlockListeners=()=>{e.container.removeEventListener(`pointerdown`,t),e.container.removeEventListener(`keydown`,t)}}return await n.loadScripts(),await n.attach(t),n}async loadScripts(){let{scene:e,scriptSources:t,resolveAsset:n,issue:r}=this.opts;for(let i of e.scripts??[]){let e=t?.[i],a=e===void 0?n(i):`src:${i}:${e.length}:${e.slice(0,64)}`,o=F.get(a);o||(o=(async()=>{let t,r=null;e===void 0?t=n(i):(t=URL.createObjectURL(new Blob([e],{type:`text/javascript`})),r=t);try{let e=await import(
|
|
19
|
-
/* @vite-ignore */
|
|
20
|
-
t);if(typeof e.default!=`function`)throw Error(`the default export must be a function (api) => ({ start, update })`);return e.default}finally{r&&URL.revokeObjectURL(r)}})(),o.catch(()=>F.delete(a)),F.set(a,o));try{let e=await o;e&&this.factories.push({path:i,factory:e})}catch(e){r({code:`script-error`,message:`${i}: ${e.message}`,path:i})}}}async attach(e){this.world=e,this.objCache.clear(),this.physics?.dispose(),this.physics=null,e.scene.updateMatrixWorld(!0),this.needsPhysics(e)&&await this.ensurePhysics(),this.instances=[];for(let{path:e,factory:t}of this.factories)try{this.instances.push({path:e,inst:t(this.api)??{},failed:!1})}catch(t){this.opts.issue({code:`script-error`,message:`${e}: ${t.message}`,path:e})}for(let e of this.instances)try{await e.inst.start?.()}catch(t){e.failed=!0,this.opts.issue({code:`script-error`,message:`${e.path} start(): ${t.message}`,path:e.path})}this.hud?.update(this.state,0)}needsPhysics(e){if(this.opts.scene.physics?.joints?.length)return!0;for(let t of e.entries.values())if(t.kind!==`light`&&(t.def.body||Array.isArray(t.object.userData.bodies)))return!0;return!1}async ensurePhysics(){if(this.physics)return this.physics;let{PhysicsBridge:e}=await N(),t=new e(this.opts.scene.physics,this.world,e=>this.opts.issue(e));return t.engine.onCollision((e,t,n)=>this.dispatchContact(e.id,t.id,n)),t.engine.onCollisionEnd((e,t)=>this.dispatchContact(e.id,t.id,null)),this.physics=t,t.attachAll(),t}dispatchContact(e,t,n){let r=this.api.get(e),i=this.api.get(t);if(!r||!i||!this.physics)return;let a=this.physics.engine.get(e)?.type===`trigger`,o=this.physics.engine.get(t)?.type===`trigger`;if(n){for(let e of this.collisionHandlers)this.safe(()=>e(r,i,n),`onCollision`);for(let e of this.triggerEnterHandlers)a&&this.safe(()=>e(r,i),`onTriggerEnter`),o&&this.safe(()=>e(i,r),`onTriggerEnter`)}else{for(let e of this.collisionEndHandlers)this.safe(()=>e(r,i),`onCollisionEnd`);for(let e of this.triggerExitHandlers)a&&this.safe(()=>e(r,i),`onTriggerExit`),o&&this.safe(()=>e(i,r),`onTriggerExit`)}}async addBodies(e,t){let n=[];e.object.traverse(e=>{let t=e.userData.a3dId;t&&!n.includes(t)&&n.push(t)});let r=n.map(e=>this.world.entries.get(e)).filter(e=>!!e).filter(n=>n===e&&t||n.def.body);if(!r.length)return;let i=await this.ensurePhysics();for(let n of r)i.has(n.id)||i.addEntry(n,n===e?t:void 0)}requestRestart(){this.restartRequested=!0}get pendingRestart(){return this.restartRequested}async restart(){this.restartRequested=!1;for(let e of this.instances)this.safe(()=>e.inst.dispose?.(),`dispose`);for(let e of Object.keys(this.state))delete this.state[e];this.handlers.clear(),this.collisionHandlers=[],this.collisionEndHandlers=[],this.triggerEnterHandlers=[],this.triggerExitHandlers=[],this.rng=i(this.opts.scene.seed??1),this.simTime=0,this.acc=0,this.shake={intensity:0,duration:0,until:0};let e=await this.opts.rebuild();return await this.attach(e),e}time(){return this.simTime}advance(e){let t=this.opts.input;for(let e of t.pressed)this.pendingPressed.add(e);t.pointer.justPressed&&(this.pendingJust=!0),t.swipe&&(this.pendingSwipe=t.swipe),this.acc+=Math.min(e,.25);let n=0;for(;this.acc>=this.stepDt-1e-9&&n<30;)this.fixedStep(),this.acc-=this.stepDt,n++}advanceTo(e){let t=this.opts.input;for(let e of t.pressed)this.pendingPressed.add(e);for(t.pointer.justPressed&&(this.pendingJust=!0),t.swipe&&(this.pendingSwipe=t.swipe);this.simTime+this.stepDt<=e+1e-9;)this.fixedStep()}fixedStep(){this.stepPressed=this.pendingPressed,this.pendingPressed=/* @__PURE__ */ new Set,this.stepJust=this.pendingJust,this.pendingJust=!1,this.stepSwipe=this.pendingSwipe,this.pendingSwipe=null;let e=this.stepDt;this.simTime+=e;for(let t of this.instances)if(!t.failed&&t.inst.update)try{t.inst.update(e,this.simTime)}catch(e){t.failed=!0,this.opts.issue({code:`script-error`,message:`${t.path} update(): ${e.message}`,path:t.path})}this.physics?.step(e),this.stepPressed=/* @__PURE__ */ new Set,this.stepJust=!1,this.stepSwipe=null}afterFrame(){let e=this.world.rig,t=this.simTime;if(t<this.shake.until&&this.shake.duration>0){let n=(this.shake.until-t)/this.shake.duration*this.shake.intensity;e.shake.set((this.rng.next()-.5)*2*n,(this.rng.next()-.5)*2*n,(this.rng.next()-.5)*n)}else e.shake.set(0,0,0);this.hud?.update(this.state,t)}emit(e,t){for(let n of this.handlers.get(e)??[])this.safe(()=>n(t),`on(${e})`);for(let n of this.instances)!n.failed&&n.inst.onEvent&&this.safe(()=>n.inst.onEvent(e,t),`onEvent`)}safe(e,t){try{e()}catch(e){this.opts.issue({code:`script-error`,message:`${t}: ${e.message}`})}}dispose(){for(let e of this.instances)this.safe(()=>e.inst.dispose?.(),`dispose`);this.instances=[],this.physics?.dispose(),this.hud?.dispose(),this.audio.dispose(),this.unlockListeners?.()}wrap(e){let t=this.objCache.get(e.id);if(t)return t;let r=this,i=e.id,c=()=>r.world.entries.get(i)??e,l=()=>{let e=c();e.animated&&(e.rest.position.copy(e.object.position),e.rest.quaternion.copy(e.object.quaternion),e.rest.scale.copy(e.object.scale)),r.physics?.moved(i)},u=()=>r.physics?.engine.get(i)?.velocity??[0,0,0],d=(e,t)=>{let n=u();n[e]=t,r.physics?.engine.setVelocity(i,n)},f={id:i,position:P(()=>c().object.position,1,l),rotation:P(()=>c().object.rotation,s,l),scale:P(()=>c().object.scale,1,l),get visible(){return c().object.visible},set visible(e){let t=c();t.object.visible=e,t.rest.visible=e},velocity:{get x(){return u()[0]},set x(e){d(0,e)},get y(){return u()[1]},set y(e){d(1,e)},get z(){return u()[2]},set z(e){d(2,e)},set(e,t,n){r.physics?.engine.setVelocity(i,[e,t,n])}},get userData(){return c().object.userData},get tags(){return c().object.userData.tags??[]},setColor(e){let t=a(e);for(let e of o(c().object))e.color?.copy(t)},setOpacity(e){for(let t of o(c().object))t.opacity=e,e<1&&!t.transparent&&(t.transparent=!0,t.needsUpdate=!0)},playAnimation(e,t){c().animator?.play(e,t)},distanceTo(e){let t=c().object.getWorldPosition(new n),i=r.world.entries.get(e.id);return i?t.distanceTo(i.object.getWorldPosition(new n)):1/0},remove(){r.world.entries.get(i)?.object.traverse(e=>{let t=e.userData.a3dId;t&&r.physics?.remove(t)}),r.physics?.remove(i),r.world.removeEntry(i),r.objCache.delete(i)}};return this.objCache.set(i,f),f}idOf(e){return typeof e==`string`?e:e.id}createApi(){let i=this,a=()=>i.opts.input,o={id:`camera`,position:P(()=>i.world.rig.rest.position),rotation:P(()=>i.world.camera.rotation,s),scale:P(()=>i.world.camera.scale),visible:!0,velocity:P(()=>new n),userData:{},tags:[],setColor(){},setOpacity(){},playAnimation(){},distanceTo(e){let t=i.world.entries.get(e.id);return t?i.world.camera.position.distanceTo(t.object.getWorldPosition(new n)):1/0},remove(){},lookAt(e,t,n){i.world.rig.rest.target.set(e,t,n)},shake(e,t){i.shake={intensity:e,duration:t,until:i.simTime+t}}},c=new r,l={get:e=>{let t=i.world.entries.get(e);return t&&t.kind!==`light`?i.wrap(t):null},findByTag:e=>{let t=[];for(let n of i.world.entries.values())n.kind!==`light`&&(n.object.userData.tags??[]).includes(e)&&t.push(i.wrap(n));return t},spawn:async(e,t)=>{let n=t?i.world.entries.get(t):void 0,r=await i.world.addObject(e,n?.object??i.world.scene,n?.id,/* @__PURE__ */ new Map);if(!r)throw Error(`spawn(${e.id}) failed`);return i.world.scene.updateMatrixWorld(!0),await i.addBodies(r),i.wrap(r)},clone:(e,t)=>{let n=i.world.entries.get(e);if(!n||n.kind===`light`)throw Error(`clone: unknown object "${e}"`);let r=t?.id;for(;!r||i.world.entries.has(r);)r=`${e}_${++i.cloneCounter}`;let a=n.object.clone(!0);a.traverse(e=>{let t=e;t.isMesh&&t.material&&(t.material=Array.isArray(t.material)?t.material.map(e=>e.clone()):t.material.clone()),e.userData.a3dId&&(e.userData={...e.userData})}),a.userData.a3dId=r,t?.position&&a.position.set(...t.position),(n.object.parent??i.world.scene).add(a);let o={...n.def,id:r,children:void 0},s={...n,id:r,def:o,object:a,rest:{position:a.position.clone(),quaternion:a.quaternion.clone(),scale:a.scale.clone(),visible:a.visible},runners:[],animator:void 0};return i.world.entries.set(r,s),i.world.scene.updateMatrixWorld(!0),o.body&&i.physics&&i.physics.addEntry(s),i.wrap(s)},camera:o,time:()=>i.simTime,random:()=>i.rng.next(),randomRange:(e,t)=>i.rng.range(e,t),input:{isDown:e=>a().keys.has(e),pressed:e=>i.stepPressed.has(e),get pointer(){let e=a().pointer;return{x:e.x,y:e.y,down:e.down,justPressed:i.stepJust}},swipe:()=>i.stepSwipe,pointerWorld:()=>{let r=a().pointer;c.setFromCamera(new t(r.x,r.y),i.world.camera);let o=[];for(let e of i.physics?.engine.bodies??[]){let t=i.world.entries.get(e.id);t&&o.push(t.object)}let s=o.length?c.intersectObjects(o,!0)[0]:void 0;if(s){let e=i.world.idsFor(s.object);return{x:s.point.x,y:s.point.y,z:s.point.z,objectId:e[0]}}let l=new n;return c.ray.intersectPlane(new e(new n(0,1,0),0),l)?{x:l.x,y:l.y,z:l.z}:null}},physics:{overlaps:(e,t)=>i.physics?.engine.overlaps(i.idOf(e),i.idOf(t))??!1,contacts:e=>(i.physics?.engine.contactsOf(i.idOf(e))??[]).map(e=>l.get(e.id)).filter(e=>!!e),raycast:(e,t,n,r)=>{let a=i.physics?.engine;if(!a)return null;let o=new Set((r?.ignore??[]).map(e=>i.idOf(e))),s=a.raycast(e,t,n??1/0,{ignore:o.size?e=>o.has(e.id):void 0,mask:r?.layers?a.layerMask(r.layers):void 0,triggers:r?.triggers});return s?{objectId:s.body.id,distance:s.distance,point:s.point,normal:s.normal}:null},applyImpulse:(e,t,n)=>i.physics?.engine.applyImpulse(i.idOf(e),t,n),applyForce:(e,t,n)=>i.physics?.engine.applyForce(i.idOf(e),t,n),applyTorque:(e,t)=>i.physics?.engine.applyTorque(i.idOf(e),t),setVelocity:(e,t)=>i.physics?.engine.setVelocity(i.idOf(e),t),getVelocity:e=>i.physics?.engine.get(i.idOf(e))?.velocity??[0,0,0],setAngularVelocity:(e,t)=>i.physics?.engine.setAngularVelocity(i.idOf(e),[t[0]*s,t[1]*s,t[2]*s]),getAngularVelocity:e=>{let t=i.physics?.engine.get(i.idOf(e))?.angularVelocity??[0,0,0];return[t[0]/s,t[1]/s,t[2]/s]},grounded:e=>i.physics?.engine.grounded(i.idOf(e))??!1,moveCharacter:(e,t,n)=>{let r=Array.isArray(t)?[t[0],t[1]]:[t.x,t.z];i.physics?.engine.moveCharacter(i.idOf(e),r,n)},jump:(e,t)=>i.physics?.engine.jump(i.idOf(e),t)??!1,wake:e=>i.physics?.engine.wake(i.idOf(e)),setMotorSpeed:(e,t)=>i.physics?.engine.setMotorSpeed(e,t*s),onCollision:e=>void i.collisionHandlers.push(e),onCollisionEnd:e=>void i.collisionEndHandlers.push(e),onTriggerEnter:e=>void i.triggerEnterHandlers.push(e),onTriggerExit:e=>void i.triggerExitHandlers.push(e)},state:i.state,ui:{set:(e,t)=>i.hud?.set(e,t),toast:(e,t)=>i.hud?.toast(e,t)},audio:{play:e=>i.audio.play(e),music:e=>i.audio.music(e)},on:(e,t)=>{let n=i.handlers.get(e)??[];n.push(t),i.handlers.set(e,n)},emit:(e,t)=>i.emit(e,t),storage:{get(e){try{let t=globalThis.localStorage?.getItem(`agent3d:${i.opts.scene.id}:${e}`);return t==null?void 0:JSON.parse(t)}catch{return}},set(e,t){try{globalThis.localStorage?.setItem(`agent3d:${i.opts.scene.id}:${e}`,JSON.stringify(t))}catch{}}},data:i.opts.scene.data??{},restart:()=>i.requestRestart(),log:(...e)=>console.log(`[agent3d]`,...e)};return l}};export{I as GameHost};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import{Ct as e,Et as t,Gt as n,Mn as r,Qt as i,St as a,T as o,Tt as s,b as c,bt as l,en as u,h as d,ht as f,kn as p,n as m,ot as h,st as g,wt as _}from"./three.module-DnaBiDAJ.js";import{a as v,c as y}from"./catalog--OTp4gjy.js";import{i as b}from"./assets-qnxDnVkj.js";import{c as x,d as S,i as ee,t as C}from"./util-CyaW1fcW.js";import{n as w}from"./params-BCNrVCYZ.js";import{t as T}from"./random-eeej60NW.js";import{t as E}from"./toon-BsvVk_nK.js";var D={map:`color`,emissiveMap:`color`,normalMap:`normal`,roughnessMap:`data`,metalnessMap:`data`,aoMap:`data`,bumpMap:`data`,displacementMap:`data`,alphaMap:`data`},O=class{perm=/* @__PURE__ */ new Uint16Array(512);grads=/* @__PURE__ */ new Float32Array(512);constructor(e){let t=T(e),n=Array.from({length:256},(e,t)=>t);for(let e=255;e>0;e--){let r=Math.floor(t.next()*(e+1));[n[e],n[r]]=[n[r],n[e]]}for(let e=0;e<512;e++)this.perm[e]=n[e&255];for(let e=0;e<256;e++){let n=t.next()*Math.PI*2;this.grads[e*2]=Math.cos(n),this.grads[e*2+1]=Math.sin(n)}}g(e,t,n,r,i,a){let o=(e%n+n)%n,s=(t%r+r)%r,c=this.perm[this.perm[o&255]+s&511]&255;return this.grads[c*2]*i+this.grads[c*2+1]*a}noise(e,t,n,r){let i=Math.floor(e),a=Math.floor(t),o=e-i,s=t-a,c=o*o*o*(o*(o*6-15)+10),l=s*s*s*(s*(s*6-15)+10),u=this.g(i,a,n,r,o,s),d=this.g(i+1,a,n,r,o-1,s),f=this.g(i,a+1,n,r,o,s-1),p=this.g(i+1,a+1,n,r,o-1,s-1);return(u+(d-u)*c+(f-u)*l+(u-d-f+p)*c*l)*1.4}fbm(e,t,n,r,i=n){let a=0,o=.5,s=0,c=n,l=i;for(let n=0;n<r;n++)a+=o*this.noise(e*c,t*l,c,l),s+=o,o*=.5,c*=2,l*=2;return a/s}},k=(e,t,n)=>{let r=Math.imul(e|0,374761393)+Math.imul(t|0,668265263)+Math.imul(n|0,2246822519)|0;return r=Math.imul(r^r>>>13,1274126177),r^=r>>>16,(r>>>0)/4294967296},A=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e||1e-6)));return r*r*(3-2*r)},j=e=>e-Math.floor(e);function M(e,t,n,r,i){let a=e*n,o=t*n,s=Math.floor(a),c=Math.floor(o),l=9,u=9,d=0,f=0;for(let e=-1;e<=1;e++)for(let t=-1;t<=1;t++){let p=s+t,m=c+e,h=(p%n+n)%n,g=(m%n+n)%n,_=p+.5+(k(h,g,i)-.5)*r,v=m+.5+(k(h,g,i+17)-.5)*r,y=Math.hypot(_-a,v-o);y<l?(u=l,l=y,d=h,f=g):y<u&&(u=y)}return{f1:l,f2:u,cx:d,cy:f}}var N={marble(e,t){let n=e.num(`scale`),r=Math.max(1,Math.round(2*n)),i=2+e.num(`veins`)*22,a=e.num(`turbulence`);return{h(e,n){let o=t.fbm(e,n,r*2,5),s=t.fbm(e+.37,n+.71,r*2,5),c=t.fbm(e+o*.12*a,n+s*.12*a,r*3,6),l=(e*.6+n)*r+a*2.6*c,u=(1-Math.abs(Math.sin(Math.PI*l)))**i,d=t.fbm(e+.5,n,r*6,5),f=(1-Math.abs(Math.sin(Math.PI*(l*2.3+d*3))))**(i*2.5)*.45,p=(t.fbm(e,n+.3,r*2,4)*.5+.5)*.18;return Math.min(1,u*.9+f+p)}}},wood(e,t){let n=e.num(`scale`),r=e.num(`rings`),i=e.num(`grain`),a=Math.max(1,Math.round(n));return{h(e,o){let s=t.fbm(e,o,2*a,4,1*a),c=j(e*Math.round(r*n)+s*1.8),l=A(0,.7,c)*(1-A(.85,1,c)),u=t.noise(e*64*a,o*3*a,64*a,3*a)*.5+.5;return Math.min(1,Math.max(0,l*.75+u*i*.35+(s*.5+.5)*.15))}}},terrazzo(e,t,n){let r=Math.max(2,Math.round(10*e.num(`scale`)/e.num(`chipSize`))),i=e.num(`density`),a=Math.max(1,e.colors(`colors`).length-1),o=(e,o)=>{let s=M(e,o,r,1,n);if(k(s.cx,s.cy,n+5)>i)return{m:0,idx:-1};let c=.18+k(s.cx,s.cy,n+9)*.3,l=s.f1+t.noise(e*r*4,o*r*4,r*4,r*4)*.08;return{m:1-A(c-.03,c+.01,l),idx:1+Math.floor(k(s.cx,s.cy,n+3)*a)}};return{h(e,t){return o(e,t).m},pick(e,t){let n=o(e,t);return n.m>.5?n.idx:-1}}},carbon(e,t){let n=Math.max(2,Math.round(8*e.num(`scale`)));return{h(e,r){let i=e*n,a=r*n,o=Math.floor(i),s=Math.floor(a),c=i-o,l=a-s,u=((o+s)%4+4)%4<2,d=u?l:c,f=u?e:r,p=Math.sin(Math.PI*d),m=t.noise(f*n*2,d*40,n*2,40)*.5+.5;return Math.min(1,p*(u?.85:.45)*(.75+m*.25))}}},noise(e,t){let n=Math.max(1,Math.round(4*e.num(`scale`))),r=e.int(`octaves`),i=e.num(`contrast`);return{h:(e,a)=>Math.min(1,Math.max(0,.5+t.fbm(e,a,n,r)*.5*i*1.6))}},voronoi(e,t,n){let r=Math.max(1,Math.round(8*e.num(`scale`))),i=e.num(`jitter`);return{h(e,t){let a=M(e,t,r,i,n);return A(0,.25,a.f2-a.f1)}}},flakes(e,t,n){let r=Math.max(4,Math.round(64*e.num(`scale`))),i=e.num(`strength`);return{h(e,t){return k(Math.floor(e*r),Math.floor(t*r),n)},normal(e,t,a){let o=M(e,t,r,1,n),s=k(o.cx,o.cy,n+1)*Math.PI*2,c=Math.sqrt(k(o.cx,o.cy,n+2))*i,l=Math.cos(s)*c,u=Math.sin(s)*c;a[0]=l,a[1]=u,a[2]=Math.sqrt(Math.max(0,1-l*l-u*u))}}},brushed(e,t){let n=Math.max(1,Math.round(e.num(`scale`))),r=e.num(`streaks`),i=Math.max(8,Math.round(300*r*n));return{h(e,r){let a=t.noise(e*2*n,r*i,2*n,i)*.5+.5,o=t.noise(e*6*n,r*i*2.5,6*n,Math.round(i*2.5))*.5+.5,s=t.fbm(e,r,3*n,3)*.5+.5;return Math.min(1,Math.max(0,a*.5+o*.3+s*.2))}}},grid(e,t,n,r){let i=Math.max(1,Math.round(e.int(`cells`)*e.num(`scale`))),a=i/r,o=Math.max(e.num(`lineWidth`)*.5,a*.75);return{h(e,t){let n=j(e*i),r=j(t*i),s=Math.min(n,1-n,r,1-r);return 1-A(o-a*.5,o+a*.5,s)}}},checker(e){let t=Math.max(1,Math.round(e.int(`cells`)*e.num(`scale`)));return{h:(e,n)=>Math.floor(e*t)+Math.floor(n*t)&1?1:0}},stripes(e){let t=Math.max(1,Math.round(e.int(`count`)*e.num(`scale`))),n=e.num(`angle`)*Math.PI/180,r=Math.round(Math.cos(n)*t),i=Math.round(Math.sin(n)*t),a=Math.max(.002,e.num(`softness`));return{h(e,t){let n=Math.abs(j(e*r+t*i)-.5)*2;return A(.5-a*2,.5+a*2,n)}}},dots(e){let t=Math.max(1,Math.round(e.int(`cells`)*e.num(`scale`))),n=e.num(`radius`);return{h(e,r){let i=j(e*t)-.5,a=j(r*t)-.5;return 1-A(n-.02,n+.01,Math.hypot(i,a))}}}};Object.keys(N);var P=e=>{let t=e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;return Math.max(0,Math.min(255,Math.round(t*255)))},F=/* @__PURE__ */ new Map;function I(e){return 2**Math.round(Math.log2(Math.max(32,Math.min(2048,e))))}function L(e,t){let n=t+`:`+JSON.stringify(e),r=F.get(n);if(r)return r;let i=y.find(t=>t.id===e.procedural),a=N[e.procedural];if(!i||!a)throw Error(`Unknown procedural texture "${e.procedural}"`);let o=w(i,e),s=o.int(`seed`),c=I(o.int(`resolution`)),l=a(o,new O(s),s,c),u=new Uint8Array(c*c*4),d=new Float32Array(c*c);for(let e=0;e<c;e++){let t=(e+.5)/c;for(let n=0;n<c;n++)d[e*c+n]=l.h((n+.5)/c,t)}if(t===`color`){let e=o.colors(`colors`).map(e=>[e.r,e.g,e.b]),t=e.length;for(let n=0;n<c;n++)for(let r=0;r<c;r++){let i=n*c+r,a,o,s,f=l.pick?l.pick((r+.5)/c,(n+.5)/c):-1;if(f>=0)[a,o,s]=e[Math.min(f,t-1)];else if(l.pick)[a,o,s]=e[0];else{let n=Math.min(1,Math.max(0,d[i]))*(t-1),r=Math.min(t-2,Math.floor(n)),c=t>1?n-r:0,l=e[Math.max(0,r)],u=e[Math.min(t-1,r+1)];a=l[0]+(u[0]-l[0])*c,o=l[1]+(u[1]-l[1])*c,s=l[2]+(u[2]-l[2])*c}u[i*4]=P(a),u[i*4+1]=P(o),u[i*4+2]=P(s),u[i*4+3]=255}}else if(t===`normal`){let e=[0,0,1],t=c/256*2;for(let n=0;n<c;n++)for(let r=0;r<c;r++){let i=n*c+r,a,o,s;if(l.normal)l.normal((r+.5)/c,(n+.5)/c,e),[a,o,s]=e;else{let e=(e,t)=>d[(t+c)%c*c+(e+c)%c],i=(e(r+1,n-1)+2*e(r+1,n)+e(r+1,n+1)-e(r-1,n-1)-2*e(r-1,n)-e(r-1,n+1))/8,l=(e(r-1,n+1)+2*e(r,n+1)+e(r+1,n+1)-e(r-1,n-1)-2*e(r,n-1)-e(r+1,n-1))/8;a=-i*t,o=-l*t,s=1;let u=Math.hypot(a,o,s);a/=u,o/=u,s/=u}u[i*4]=Math.round((a*.5+.5)*255),u[i*4+1]=Math.round((o*.5+.5)*255),u[i*4+2]=Math.round((s*.5+.5)*255),u[i*4+3]=255}}else for(let e=0;e<c*c;e++){let t=Math.round(Math.min(1,Math.max(0,d[e]))*255);u[e*4]=u[e*4+1]=u[e*4+2]=t,u[e*4+3]=255}let f={data:u,size:c};return F.size>64&&F.clear(),F.set(n,f),f}function R(e,t){let r=L(e,t),a=new o(r.data,r.size,r.size,n,p);return a.colorSpace=t===`color`?u:``,a.wrapS=a.wrapT=i,a.magFilter=h,a.minFilter=g,a.generateMipmaps=!0,a.anisotropy=4,a.needsUpdate=!0,a.name=`procedural:${e.procedural}`,a}v.map(e=>e.id);function z(e){let t=e??{},n={...(t.preset?v.find(e=>e.id===t.preset):void 0)?.props??{}};for(let[e,r]of Object.entries(t))r!==void 0&&e!==`preset`&&(n[e]=r);return n.type||=n.shader?`shader`:n.gradient?`gradient`:`standard`,n}function B(e,t,n){let r=e.userData.a3dPatches;if(!r){r=e.userData.a3dPatches=[];let t=e.onBeforeCompile;if(t!==f.prototype.onBeforeCompile){let n=e.customProgramCacheKey.call(e);r.push({key:`own(${n})`,patch:(n,r)=>t.call(e,n,r)})}}if(r.some(e=>e.key===t))return;r.push({key:t,patch:n});let i=r;e.onBeforeCompile=(e,t)=>{for(let n of i)n.patch(e,t)},e.customProgramCacheKey=()=>`agent3d:`+i.map(e=>e.key).join(`+`),e.needsUpdate=!0}var V=null;function H(){if(V)return V;if(typeof document>`u`)return null;let e=document.createElement(`canvas`);e.width=e.height=256;let t=e.getContext(`2d`);if(!t)return null;let n=t.createRadialGradient(97.28,81.92,5.12,128,128,133.12);n.addColorStop(0,`#ffffff`),n.addColorStop(.25,`#e6e6ea`),n.addColorStop(.7,`#7d7f88`),n.addColorStop(1,`#2a2b30`),t.fillStyle=n,t.fillRect(0,0,256,256);let r=t.createRadialGradient(128,128,102.4,128,128,128);return r.addColorStop(0,`rgba(255,255,255,0)`),r.addColorStop(1,`rgba(200,210,255,0.35)`),t.fillStyle=r,t.fillRect(0,0,256,256),V=new d(e),V.colorSpace=u,V}var U={front:0,back:1,double:2},W=8;function G(e,t,n=!1){let r=t.slice(0,W).map(e=>S(e));for(;r.length<W;)r.push(r[r.length-1].clone());let i={uGradColors:{value:r},uGradCount:{value:Math.min(Math.max(t.length,1),W)},uGradMin:{value:-.5},uGradMax:{value:.5}};return B(e,n?`gradient-emissive`:`gradient`,e=>{Object.assign(e.uniforms,i),e.vertexShader=`varying float vGradY;
|
|
2
|
-
`+e.vertexShader.replace(`#include <begin_vertex>`,`#include <begin_vertex>
|
|
3
|
-
vGradY = position.y;`);let t=`varying float vGradY;\nuniform vec3 uGradColors[${W}];\nuniform int uGradCount;\nuniform float uGradMin;\nuniform float uGradMax;\n`+e.fragmentShader.replace(`vec4 diffuseColor = vec4( diffuse, opacity );`,`float gT = clamp((vGradY - uGradMin) / max(uGradMax - uGradMin, 1e-5), 0.0, 1.0);
|
|
4
|
-
vec3 gCol = uGradColors[0];
|
|
5
|
-
if (uGradCount > 1) {
|
|
6
|
-
float f = gT * float(uGradCount - 1);
|
|
7
|
-
for (int i = 0; i < 7; i++) {
|
|
8
|
-
if (i < uGradCount - 1) gCol = mix(gCol, uGradColors[i + 1], clamp(f - float(i), 0.0, 1.0));
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
vec4 diffuseColor = vec4( diffuse * gCol, opacity );`);n&&(t=t.replace(`#include <emissivemap_fragment>`,`#include <emissivemap_fragment>
|
|
12
|
-
totalEmissiveRadiance *= gCol;`)),e.fragmentShader=t}),e.userData.gradient=i,i}function K(e,t){for(let n of Array.isArray(e)?e:[e]){let e=n.userData.gradient;if(!e)continue;t.boundingBox||t.computeBoundingBox();let r=t.boundingBox;e.uGradMin.value=r.min.y,e.uGradMax.value=r.max.y}}var q=`
|
|
13
|
-
varying vec3 vTriPos;
|
|
14
|
-
varying vec3 vTriNormal;
|
|
15
|
-
uniform vec2 uTriScale;
|
|
16
|
-
vec3 triW() {
|
|
17
|
-
vec3 w = pow(abs(normalize(vTriNormal)), vec3(4.0));
|
|
18
|
-
return w / max(w.x + w.y + w.z, 1e-5);
|
|
19
|
-
}
|
|
20
|
-
vec4 triSample(sampler2D tex) {
|
|
21
|
-
vec3 w = triW();
|
|
22
|
-
vec3 p = vTriPos;
|
|
23
|
-
return texture2D(tex, p.zy * uTriScale) * w.x + texture2D(tex, p.xz * uTriScale) * w.y + texture2D(tex, p.xy * uTriScale) * w.z;
|
|
24
|
-
}
|
|
25
|
-
`;function te(e,t,n){let i={value:new r(t*(n?.[0]??1),t*(n?.[1]??n?.[0]??1))};B(e,`triplanar`,e=>{e.uniforms.uTriScale=i,e.vertexShader=`varying vec3 vTriPos;
|
|
26
|
-
varying vec3 vTriNormal;
|
|
27
|
-
`+e.vertexShader.replace(`#include <begin_vertex>`,`#include <begin_vertex>
|
|
28
|
-
vTriPos = position;
|
|
29
|
-
vTriNormal = normal;`);let t=e.fragmentShader;t=t.replace(`#include <common>`,`#include <common>
|
|
30
|
-
`+q+`
|
|
31
|
-
#if defined( USE_NORMALMAP_TANGENTSPACE ) && !defined( USE_NORMALMAP_OBJECTSPACE )
|
|
32
|
-
uniform mat3 normalMatrix;
|
|
33
|
-
#endif
|
|
34
|
-
`),t=t.replace(`#include <map_fragment>`,`#ifdef USE_MAP
|
|
35
|
-
diffuseColor *= triSample( map );
|
|
36
|
-
#endif`),t=t.replace(`#include <roughnessmap_fragment>`,`float roughnessFactor = roughness;
|
|
37
|
-
#ifdef USE_ROUGHNESSMAP
|
|
38
|
-
roughnessFactor *= triSample( roughnessMap ).g;
|
|
39
|
-
#endif`),t=t.replace(`#include <metalnessmap_fragment>`,`float metalnessFactor = metalness;
|
|
40
|
-
#ifdef USE_METALNESSMAP
|
|
41
|
-
metalnessFactor *= triSample( metalnessMap ).b;
|
|
42
|
-
#endif`),t=t.replace(`#include <emissivemap_fragment>`,`#ifdef USE_EMISSIVEMAP
|
|
43
|
-
totalEmissiveRadiance *= triSample( emissiveMap ).rgb;
|
|
44
|
-
#endif`),t=t.replace(`#include <normal_fragment_maps>`,`#if defined( USE_NORMALMAP_TANGENTSPACE )
|
|
45
|
-
{
|
|
46
|
-
vec3 tw = triW();
|
|
47
|
-
vec3 on = normalize( vTriNormal );
|
|
48
|
-
vec3 p = vTriPos;
|
|
49
|
-
vec3 tx = texture2D( normalMap, p.zy * uTriScale ).xyz * 2.0 - 1.0;
|
|
50
|
-
vec3 ty = texture2D( normalMap, p.xz * uTriScale ).xyz * 2.0 - 1.0;
|
|
51
|
-
vec3 tz = texture2D( normalMap, p.xy * uTriScale ).xyz * 2.0 - 1.0;
|
|
52
|
-
tx.xy *= normalScale; ty.xy *= normalScale; tz.xy *= normalScale;
|
|
53
|
-
tx = vec3( tx.xy + on.zy, abs( tx.z ) * on.x );
|
|
54
|
-
ty = vec3( ty.xy + on.xz, abs( ty.z ) * on.y );
|
|
55
|
-
tz = vec3( tz.xy + on.xy, abs( tz.z ) * on.z );
|
|
56
|
-
vec3 objN = normalize( tx.zyx * tw.x + ty.xzy * tw.y + tz.xyz * tw.z );
|
|
57
|
-
normal = normalize( normalMatrix * objN ) * faceDirection;
|
|
58
|
-
}
|
|
59
|
-
#else
|
|
60
|
-
#include <normal_fragment_maps>
|
|
61
|
-
#endif`),e.fragmentShader=t})}var ne=Object.keys(D);function J(e,t,n){e.colorSpace=n?u:``,(t.repeat||t.triplanar)&&(e.wrapS=e.wrapT=i,t.repeat&&!t.triplanar&&e.repeat.set(t.repeat[0],t.repeat[1])),e.anisotropy=Math.max(e.anisotropy,4)}function Y(e,t,n,r){let i=e;i[t]=n,t===`map`&&!r.color&&e.color?.set(16777215),t===`emissiveMap`&&!r.emissive&&e.emissive?.set(16777215),t===`alphaMap`&&(e.transparent=r.transparent??!0),e.needsUpdate=!0}function re(e,t,n){for(let r of ne){let a=t[r];if(!a||!(r in e))continue;let o=D[r];if(typeof a==`object`){try{let n=R(a,o);J(n,t,o===`color`),n.wrapS=n.wrapT=i,Y(e,r,n,t)}catch(e){n.issue(`unknown-catalog-id`,e.message,`material.${String(r)}`)}continue}let s=n.resolveAsset(a);n.track(b(s).then(n=>{J(n,t,o===`color`),Y(e,r,n,t)}).catch(e=>n.issue(`asset-load`,e.message,a)))}}function X(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}async function Z(n,i,o={}){let u=z(n),d=u.type??`standard`,f=u.color??(n?.preset?void 0:o.defaultColor);if(d===`shader`){let e=await i.shaders().catch(()=>({})),t=u.shader??`plasma`,n=e[t];if(n){let e={...u.uniforms??{}};u.color&&e.color===void 0&&(e.color=u.color),u.gradient&&e.colors===void 0&&(e.colors=u.gradient),u.opacity!==void 0&&e.opacity===void 0&&(e.opacity=u.opacity);let t=n.create(e,i);if(t.update){let e=t.update.bind(t);i.onUpdate(t=>e(t))}return u.side&&(t.material.side=U[u.side]),t.material}i.issue(`unknown-catalog-id`,`Unknown shader "${t}"`,`material.shader`)}let p={};f&&(p.color=S(f)),u.opacity!==void 0&&(p.opacity=u.opacity),(u.transparent!==void 0||u.opacity!==void 0&&u.opacity<1)&&(p.transparent=u.transparent??!0),u.wireframe&&(p.wireframe=!0),u.side&&(p.side=U[u.side]),o.vertexColors&&(p.vertexColors=!0);let m={...p};u.emissive&&(m.emissive=S(u.emissive)),u.emissiveIntensity!==void 0&&(m.emissiveIntensity=u.emissiveIntensity),u.flatShading&&(m.flatShading=!0),u.bumpScale!==void 0&&(m.bumpScale=u.bumpScale),u.normalScale!==void 0&&(m.normalScale=new r(u.normalScale,u.normalScale)),u.aoMapIntensity!==void 0&&(m.aoMapIntensity=u.aoMapIntensity),u.displacementScale!==void 0&&(m.displacementScale=u.displacementScale);let h={...m};u.metalness!==void 0&&(h.metalness=u.metalness),h.roughness=x(u.roughness,.5),u.envMapIntensity!==void 0&&(h.envMapIntensity=u.envMapIntensity);let g;switch(d){case`physical`:{let e={...h};if(u.transmission!==void 0&&(e.transmission=u.transmission),u.thickness!==void 0&&(e.thickness=u.thickness),u.ior!==void 0&&(e.ior=u.ior),u.clearcoat!==void 0&&(e.clearcoat=u.clearcoat,e.clearcoatRoughness=x(u.clearcoatRoughness,.1)),u.iridescence!==void 0){e.iridescence=u.iridescence,e.iridescenceIOR=x(u.iridescenceIOR,1.6);let[t,n]=u.iridescenceThicknessRange??[180,600];e.iridescenceThicknessMinimum=t,e.iridescenceThicknessMaximum=n}u.sheen!==void 0&&(e.sheen=u.sheen,e.sheenRoughness=x(u.sheenRoughness,.6),e.sheenColor=u.sheenColor?S(u.sheenColor):S(f??`#ffffff`).lerp(new c(1,1,1),.5)),u.anisotropy!==void 0&&(e.anisotropy=u.anisotropy,e.anisotropyRotation=x(u.anisotropyRotation,0)*C),u.attenuationColor!==void 0&&(e.attenuationColor=S(u.attenuationColor)),u.attenuationDistance!==void 0&&(e.attenuationDistance=u.attenuationDistance),u.specularIntensity!==void 0&&(e.specularIntensity=u.specularIntensity),u.specularColor!==void 0&&(e.specularColor=S(u.specularColor)),u.dispersion!==void 0&&(e.dispersion=u.dispersion),g=new s(e),u.transmission&&!$(u)&&oe(g);break}case`basic`:g=new l(p);break;case`lambert`:g=new a(m);break;case`toon`:g=E({...h,roughness:x(u.roughness,.75)});break;case`normal`:g=new _(X({flatShading:!!u.flatShading,wireframe:!!u.wireframe,side:p.side,transparent:p.transparent,opacity:u.opacity??1}));break;case`matcap`:g=new e(X({...p,flatShading:!!u.flatShading,matcap:H()??void 0}));break;case`gradient`:g=new t({...h,color:S(u.color??`#ffffff`)}),G(g,ee(u.gradient,[`#3a86ff`,`#ff006e`]),!!u.gradientEmissive);break;default:g=new t(h)}return u.envMapIntensity!==void 0&&g instanceof t&&u.envMapIntensity!==1&&(Q(g).value=u.envMapIntensity),g instanceof s&&$(u)&&se(g,u),u.triplanar&&g instanceof t&&te(g,typeof u.triplanar==`number`?u.triplanar:1,u.repeat),re(g,u,i),g}async function ie(e,t,n){let r=await Z(t,n);e.traverse(e=>{let t=e;t.isMesh&&(t.material=r,K(r,t.geometry))})}function Q(e){let t=e.userData.envScale;if(t)return t;let n={value:1};return e.userData.envScale=n,B(e,`env-scale`,e=>{e.uniforms.uA3dEnvScale=n,e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
|
|
62
|
-
uniform float uA3dEnvScale;`).replace(`#include <lights_fragment_maps>`,`#include <lights_fragment_maps>
|
|
63
|
-
#if defined( RE_IndirectSpecular ) && defined( RE_IndirectDiffuse )
|
|
64
|
-
radiance *= uA3dEnvScale;
|
|
65
|
-
clearcoatRadiance *= uA3dEnvScale;
|
|
66
|
-
iblIrradiance *= uA3dEnvScale;
|
|
67
|
-
#endif`)}),n}var ae=`vec3 a3dSoftClip(vec3 c) { vec3 e = max(c - 1.0, 0.0); return min(c, 1.0) + e / (1.0 + e); }`;function oe(e){B(e,`transmission-clamp`,e=>{e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>\n${ae}`).replace(`#include <transmission_fragment>`,m.transmission_fragment.replace(`material.transmissionAlpha = mix(`,`transmitted.rgb = a3dSoftClip( transmitted.rgb );
|
|
68
|
-
material.transmissionAlpha = mix(`))})}function $(e){return(e.transmission??0)>=.5&&(e.ior??1.5)>=1.7&&(e.roughness??.5)<=.15}function se(e,t){let n={uA3dGemIor:{value:t.ior??2},uA3dGemDisp:{value:Math.min(.12,(t.dispersion??0)*.012)},uA3dGemTint:{value:t.attenuationColor?S(t.attenuationColor):new c(1,1,1)},uA3dGemEnv:Q(e),uA3dGemAmount:{value:Math.min(.85,.45+Math.max(0,(t.ior??2)-1.5)*.45)}};e.userData.gemSparkle=n,B(e,`gem-sparkle`,e=>{Object.assign(e.uniforms,n),e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>
|
|
69
|
-
varying vec3 vA3dJ0; varying vec3 vA3dJ1; varying vec3 vA3dJ2;
|
|
70
|
-
vec3 a3dGemHash(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }`).replace(`#include <beginnormal_vertex>`,`#include <beginnormal_vertex>
|
|
71
|
-
vec3 a3dOn = floor(objectNormal * 64.0 + 0.5);
|
|
72
|
-
vA3dJ0 = normalMatrix * (a3dGemHash(a3dOn + 1.7) - 0.5);
|
|
73
|
-
vA3dJ1 = normalMatrix * (a3dGemHash(a3dOn + 9.3) - 0.5);
|
|
74
|
-
vA3dJ2 = normalMatrix * (a3dGemHash(a3dOn + 23.1) - 0.5);`),e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
|
|
75
|
-
varying vec3 vA3dJ0; varying vec3 vA3dJ1; varying vec3 vA3dJ2;
|
|
76
|
-
uniform float uA3dGemIor; uniform float uA3dGemDisp; uniform vec3 uA3dGemTint; uniform float uA3dGemEnv; uniform float uA3dGemAmount;`).replace(`#include <opaque_fragment>`,`#if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_PMREM )
|
|
77
|
-
{
|
|
78
|
-
vec3 gV = normalize(geometryViewDir);
|
|
79
|
-
vec3 gN = normalize(normal);
|
|
80
|
-
vec3 sp = vec3(0.0);
|
|
81
|
-
vec3 iors = vec3(uA3dGemIor - uA3dGemDisp, uA3dGemIor, uA3dGemIor + uA3dGemDisp);
|
|
82
|
-
for (int k = 0; k < 3; k++) {
|
|
83
|
-
vec3 J = k == 0 ? vA3dJ0 : (k == 1 ? vA3dJ1 : vA3dJ2);
|
|
84
|
-
vec3 fn = normalize(-gN + J * 1.6);
|
|
85
|
-
for (int c = 0; c < 3; c++) {
|
|
86
|
-
vec3 rd = refract(-gV, gN, 1.0 / iors[c]);
|
|
87
|
-
vec3 d = normalize(reflect(rd, fn));
|
|
88
|
-
// A second inner bounce off the next fake facet: the exit ray swings a
|
|
89
|
-
// lot with the view angle, so faces break into light / dark areas.
|
|
90
|
-
vec3 J2 = k == 0 ? vA3dJ1 : (k == 1 ? vA3dJ2 : vA3dJ0);
|
|
91
|
-
d = normalize(reflect(d, normalize(d * -0.5 + J2 * 2.0 + gN * 0.3)));
|
|
92
|
-
sp[c] += getIBLRadiance(d, d, 0.0)[c];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
sp *= uA3dGemEnv / 3.0;
|
|
96
|
-
// Contrast: facets catching bright light flash, the others go dark.
|
|
97
|
-
// Relative to the environment's average brightness (its irradiance), so it
|
|
98
|
-
// works on a uniformly light softbox as well as on a dark studio.
|
|
99
|
-
vec3 avgEnv = (getIBLIrradiance(gN) + getIBLIrradiance(-gN)) / (2.0 * PI) * uA3dGemEnv / max(envMapIntensity, 1e-3);
|
|
100
|
-
float la = max(dot(avgEnv, vec3(0.2126, 0.7152, 0.0722)), 1e-3);
|
|
101
|
-
float l = dot(sp, vec3(0.2126, 0.7152, 0.0722));
|
|
102
|
-
sp *= smoothstep(0.7 * la, 1.6 * la, l) * 1.6;
|
|
103
|
-
float F = pow(1.0 - saturate(dot(gN, gV)), 5.0);
|
|
104
|
-
outgoingLight = mix(outgoingLight, sp * uA3dGemTint + outgoingLight * 0.25, uA3dGemAmount * (1.0 - F));
|
|
105
|
-
}
|
|
106
|
-
#endif
|
|
107
|
-
#include <opaque_fragment>`)})}export{ie as a,K as i,Z as n,z as o,Q as r,B as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{H as e,Nn as t,c as n,d as r,ft as i,pt as a}from"./three.module-DnaBiDAJ.js";import{c as o}from"./util-CyaW1fcW.js";import{a as s}from"./materials-dC4vDNHh.js";var c=/* @__PURE__ */ new Map;function l(e){let t=new Uint8Array(e),n;if(t.byteLength>=20&&new DataView(e).getUint32(0,!0)===1179937895){let r=new DataView(e).getUint32(12,!0);n=new TextDecoder().decode(t.subarray(20,20+r))}else n=new TextDecoder().decode(t);try{let e=JSON.parse(n);return Array.isArray(e.extensionsUsed)?e.extensionsUsed.filter(e=>typeof e==`string`):[]}catch{return[]}}async function u(e){let t=c.get(e);return t||(t=(async()=>{let[{GLTFLoader:t},n]=await Promise.all([import(`./GLTFLoader-Z9Inv-Xm.js`),fetch(e)]);if(!n.ok)throw Error(`HTTP ${n.status} for ${e}`);let r=await n.arrayBuffer(),i=l(r);if(i.includes(`KHR_draco_mesh_compression`))throw Error(`${e} uses Draco compression (KHR_draco_mesh_compression), which the Agent3D runtime does not decode. Re-export it without Draco (Blender: uncheck "Compression"), or convert it to meshopt with gltfpack (\`gltfpack -i in.glb -o out.glb -cc\`), then run \`agent3d assets optimize\`.`);let a=new t;if(i.includes(`EXT_meshopt_compression`)){let{MeshoptDecoder:e}=await import(`./meshopt_decoder.module-DXTYc6wn.js`);await e.ready,a.setMeshoptDecoder(e)}let o=e.slice(0,e.lastIndexOf(`/`)+1);return a.parseAsync(r,/^data:/.test(e)?``:o)})(),t.catch(()=>c.delete(e)),c.set(e,t)),t}function d(e,t){e.traverse(e=>{let n=e;if(n.isMesh&&n.morphTargetDictionary&&n.morphTargetInfluences)for(let[e,r]of Object.entries(t)){let t=n.morphTargetDictionary[e];t!==void 0&&typeof r==`number`&&(n.morphTargetInfluences[t]=r)}})}async function f(c,l){let f=await u(l.resolveAsset(c.src)),{clone:p}=await import(`./SkeletonUtils-DHlReJx3.js`),m=p(f.scene),h=new e;h.add(m),m.updateMatrixWorld(!0);let g=new r().setFromObject(m);if(!g.isEmpty()){let e=g.getSize(new t),n=Math.max(e.x,e.y,e.z),r=c.fit&&n>0?c.fit/n:1;if(m.scale.multiplyScalar(r),c.center!==!1){let e=g.getCenter(new t);m.position.set(-e.x*r,-g.min.y*r,-e.z*r)}}m.traverse(e=>{let t=e;t.isMesh&&(t.castShadow=c.castShadow??!0,t.receiveShadow=c.receiveShadow??!1)}),c.material&&await s(m,c.material,l),c.morph&&d(m,c.morph);let _;if(f.animations.length){let e=new n(m),t=null,r=e=>typeof e==`number`||/^\d+$/.test(String(e))?f.animations[Number(e)]:f.animations.find(t=>t.name===e)??f.animations.find(t=>t.name.toLowerCase().includes(String(e).toLowerCase())),s=/* @__PURE__ */ new Set,u=e=>{let t=r(e);return!t&&!s.has(String(e))&&(s.add(String(e)),l.issue(`asset-load`,`Model ${c.id} has no animation clip "${e}" (clips: ${f.animations.map(e=>e.name).join(`, `)})`,`objects#${c.id}.animation.clip`)),t},d=(n,r={})=>{let s=u(n);if(!s)return;let c=e.clipAction(s);c.setLoop(r.loop===!1?i:a,1/0),c.clampWhenFinished=r.loop===!1,c.timeScale=o(r.speed,1),c.enabled=!0,t&&t!==c?(c.reset().setEffectiveWeight(1).play(),t.crossFadeTo(c,o(r.crossfade,.3),!1)):c.setEffectiveWeight(1).play(),t=c},p=t=>{let n=u(t);if(!n)return null;let r=e.clipAction(n);return r.isRunning()||(r.enabled=!0,r.setLoop(a,1/0),r.play()),r},h={weight(e,t){p(e)?.setEffectiveWeight(Math.max(0,t))},speed(e,t){let n=p(e);n&&(n.timeScale=t)},time(e,t){let n=p(e);n&&(n.paused=!0,n.time=Math.max(0,t))}},g=c.animation??{},v=()=>{e.stopAllAction(),t=null,d(g.clip??0,g),g.offset&&t&&(t.time=Math.max(0,g.offset));for(let[e,t]of Object.entries(g.blend??{}))h.weight(e,t);e.update(0)};_={mixer:e,clips:f.animations,play:d,control:h,reset:v},v()}return{object:h,animator:_}}export{f as buildModel};
|