spider-paint 0.0.0-stage → 26.11.24003

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.
Files changed (171) hide show
  1. package/Dockerfile +24 -0
  2. package/LICENSE +21 -0
  3. package/MCP.md +211 -0
  4. package/PLAYER.md +139 -0
  5. package/README.md +182 -2
  6. package/TRANSFER.md +63 -0
  7. package/api/mcp.mjs +60 -0
  8. package/api/store.mjs +158 -0
  9. package/bin/cloud-run.mjs +96 -0
  10. package/bin/spider-paint.mjs +27 -0
  11. package/bin/workshop-mcp.mjs +21 -0
  12. package/bin/workshop.mjs +137 -0
  13. package/emulator.html +17 -0
  14. package/engine/8fa668821759/bevel.js +265 -0
  15. package/engine/8fa668821759/camera.js +76 -0
  16. package/engine/8fa668821759/character.js +1019 -0
  17. package/engine/8fa668821759/check.js +83 -0
  18. package/engine/8fa668821759/csg.js +342 -0
  19. package/engine/8fa668821759/edit.js +48 -0
  20. package/engine/8fa668821759/galaxy.js +265 -0
  21. package/engine/8fa668821759/gl.js +798 -0
  22. package/engine/8fa668821759/gpu.js +1356 -0
  23. package/engine/8fa668821759/index.js +48 -0
  24. package/engine/8fa668821759/instances.js +41 -0
  25. package/engine/8fa668821759/joints.js +355 -0
  26. package/engine/8fa668821759/kernel-bytes.js +2 -0
  27. package/engine/8fa668821759/kernel.js +82 -0
  28. package/engine/8fa668821759/lathe.js +87 -0
  29. package/engine/8fa668821759/material.js +19 -0
  30. package/engine/8fa668821759/mesh.js +131 -0
  31. package/engine/8fa668821759/order.js +125 -0
  32. package/engine/8fa668821759/pick.js +85 -0
  33. package/engine/8fa668821759/place.js +17 -0
  34. package/engine/8fa668821759/planet.js +376 -0
  35. package/engine/8fa668821759/rig.js +417 -0
  36. package/engine/8fa668821759/saw.js +121 -0
  37. package/engine/8fa668821759/sky.js +428 -0
  38. package/engine/8fa668821759/svg.js +239 -0
  39. package/engine/8fa668821759/text.js +231 -0
  40. package/engine/8fa668821759/triangulate.js +72 -0
  41. package/engine/8fa668821759/types.js +2 -0
  42. package/engine/8fa668821759/vec.js +22 -0
  43. package/engine/8fa668821759/version.js +7 -0
  44. package/engine/8fa668821759/vrtsh.js +354 -0
  45. package/engine/8fa668821759/wire.js +346 -0
  46. package/favicon.svg +6 -0
  47. package/help.md +292 -0
  48. package/icons/apple-touch-icon.png +0 -0
  49. package/icons/favicon-32.png +0 -0
  50. package/icons/icon-192.png +0 -0
  51. package/icons/icon-512.png +0 -0
  52. package/icons/icon-maskable-512.png +0 -0
  53. package/icons/icon-maskable.svg +6 -0
  54. package/icons/icon.svg +6 -0
  55. package/index.html +13874 -0
  56. package/manifest.webmanifest +19 -0
  57. package/mcp/build-info.js +46 -0
  58. package/mcp/diagnostics.js +129 -0
  59. package/mcp/engine/bevel.js +265 -0
  60. package/mcp/engine/camera.js +76 -0
  61. package/mcp/engine/character.js +1019 -0
  62. package/mcp/engine/check.js +83 -0
  63. package/mcp/engine/csg.js +342 -0
  64. package/mcp/engine/edit.js +48 -0
  65. package/mcp/engine/galaxy.js +265 -0
  66. package/mcp/engine/gl.js +798 -0
  67. package/mcp/engine/gpu.js +1356 -0
  68. package/mcp/engine/index.js +48 -0
  69. package/mcp/engine/instances.js +41 -0
  70. package/mcp/engine/joints.js +355 -0
  71. package/mcp/engine/kernel-bytes.js +2 -0
  72. package/mcp/engine/kernel.js +82 -0
  73. package/mcp/engine/lathe.js +87 -0
  74. package/mcp/engine/material.js +19 -0
  75. package/mcp/engine/mesh.js +131 -0
  76. package/mcp/engine/order.js +125 -0
  77. package/mcp/engine/pick.js +85 -0
  78. package/mcp/engine/place.js +17 -0
  79. package/mcp/engine/planet.js +376 -0
  80. package/mcp/engine/rig.js +417 -0
  81. package/mcp/engine/saw.js +121 -0
  82. package/mcp/engine/sky.js +428 -0
  83. package/mcp/engine/svg.js +239 -0
  84. package/mcp/engine/text.js +231 -0
  85. package/mcp/engine/triangulate.js +72 -0
  86. package/mcp/engine/types.js +2 -0
  87. package/mcp/engine/vec.js +22 -0
  88. package/mcp/engine/version.js +7 -0
  89. package/mcp/engine/vrtsh.js +354 -0
  90. package/mcp/engine/wire.js +346 -0
  91. package/mcp/http.js +293 -0
  92. package/mcp/live.js +95 -0
  93. package/mcp/package.json +10 -0
  94. package/mcp/raster.js +275 -0
  95. package/mcp/scene.js +1163 -0
  96. package/mcp/serve.js +87 -0
  97. package/mcp/server.js +98 -0
  98. package/mcp/story.js +442 -0
  99. package/mcp/workshop-app.js +286 -0
  100. package/mcp/workshop-browser-model.js +81 -0
  101. package/mcp/workshop-client.js +46 -0
  102. package/mcp/workshop-native-inline.js +87 -0
  103. package/mcp/workshop-session.js +80 -0
  104. package/mcp/workshop-tools.js +7 -0
  105. package/mcp/workshop-widget.js +503 -0
  106. package/media/face-of-spider.png +0 -0
  107. package/media/spider-paint-2015.png +0 -0
  108. package/media/spider-paint-brand.svg +1 -0
  109. package/media/spider-paint-logo.svg +20 -0
  110. package/media/spider-web.png +0 -0
  111. package/models/UP-Explorer-cruise.scene.json +1 -0
  112. package/models/UP-Explorer-cutaway.scene.json +1 -0
  113. package/models/UP-Explorer-deployed.scene.json +1 -0
  114. package/models/WU-3463-Wyoming-UP-3463.json +1 -0
  115. package/models/betterman.scene.json +1 -0
  116. package/models/bridge.scene.json +1 -0
  117. package/models/command-bridge.scene.json +1 -0
  118. package/models/deepsky-lark.scene.json +1 -0
  119. package/models/deepsky.scene.json +1 -0
  120. package/models/ex27.scene.json +1 -0
  121. package/models/fifth-percent.game.json +14 -0
  122. package/models/globe.scene.json +1 -0
  123. package/models/human.scene.json +1 -0
  124. package/models/index.json +29 -0
  125. package/models/lark-4-cutaway.scene.json +1 -0
  126. package/models/lark-4-live-verification.json +1 -0
  127. package/models/lark-4-pending.json +1 -0
  128. package/models/lark-4-tutorial.html +23 -0
  129. package/models/lark-4-tutorial.json +1 -0
  130. package/models/lark-4-verification.json +45 -0
  131. package/models/lark-4-working.scene.json +1 -0
  132. package/models/lark-4.build.json +1 -0
  133. package/models/lark-4.scene.json +1 -0
  134. package/models/lark-4c-accident.build.json +1 -0
  135. package/models/lark-4c-accident.html +6 -0
  136. package/models/lark-4c-accident.md +86 -0
  137. package/models/lark-4c-accident.scene.json +1 -0
  138. package/models/lark.game.json +14 -0
  139. package/models/mechanics.scene.json +1 -0
  140. package/models/milkyway.scene.json +1 -0
  141. package/models/service-bay-scaled.scene.json +1 -0
  142. package/models/service-droid.scene.json +1 -0
  143. package/models/spider-build-example.build.json +398 -0
  144. package/models/spider-build-player.mjs +173 -0
  145. package/models/spider-build-v2.md +218 -0
  146. package/models/spider-build-v2.mjs +356 -0
  147. package/models/spider-build-v2.schema.json +1006 -0
  148. package/models/spider-sculpt.build.json +1 -0
  149. package/models/stars-plain.scene.json +1 -0
  150. package/models/stars.scene.json +1 -0
  151. package/models/station-screen.scene.json +1 -0
  152. package/models/station-technician.scene.json +1 -0
  153. package/models/tr74.scene.json +1 -0
  154. package/models/trappist-1.sky.json +17 -0
  155. package/models/workshop.scene.json +1 -0
  156. package/models/wyoming-massing.scene.json +1 -0
  157. package/nginx.conf +12 -0
  158. package/package.json +83 -4
  159. package/player.html +286 -0
  160. package/sky.html +133 -0
  161. package/sky.md +285 -0
  162. package/src/demo.js +92 -0
  163. package/src/emulator/devices.js +22 -0
  164. package/src/emulator/xr.js +362 -0
  165. package/src/math.js +77 -0
  166. package/src/tutorial-keycast.js +106 -0
  167. package/src/workshop-view.js +59 -0
  168. package/sw.js +39 -0
  169. package/workshop.html +46 -0
  170. package/xr-compare.html +332 -0
  171. package/xr-test.html +248 -0
package/Dockerfile ADDED
@@ -0,0 +1,24 @@
1
+ # spider-paint Cloud Run: embed the immutable source commit at image build time.
2
+ # Local Docker contexts include .git; CI may supply --build-arg SPIDER_PAINT_GIT_SHA.
3
+ FROM node:22-alpine AS source
4
+ RUN apk add --no-cache git
5
+ WORKDIR /app
6
+ COPY . .
7
+ ARG SPIDER_PAINT_GIT_SHA=""
8
+ ARG COMMIT_SHA=""
9
+ RUN set -eu; \
10
+ sha="$SPIDER_PAINT_GIT_SHA"; \
11
+ if [ -z "$sha" ]; then sha="$COMMIT_SHA"; fi; \
12
+ if [ -z "$sha" ] && [ -d .git ]; then sha="$(git rev-parse HEAD 2>/dev/null || true)"; fi; \
13
+ if [ -n "$sha" ]; then \
14
+ echo "$sha" | grep -Eiq '^[0-9a-f]{7,40}$' || (echo 'Invalid commit SHA' >&2; exit 1); \
15
+ printf '%s\n' "$sha" > mcp/build-sha.txt; \
16
+ fi; \
17
+ rm -rf .git
18
+ FROM node:22-alpine
19
+ WORKDIR /app
20
+ COPY --from=source /app/ ./
21
+ ENV NODE_ENV=production
22
+ ENV PORT=8080
23
+ EXPOSE 8080
24
+ CMD ["node", "bin/cloud-run.mjs"]
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vívó Péter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/MCP.md ADDED
@@ -0,0 +1,211 @@
1
+ # spider-paint MCP
2
+
3
+ This file is for the AI (and the person setting it up). spider-paint carries an MCP server: `mcp/server.js`, stdio, no dependencies, Node 18+. Through it an AI builds 3D models with tools, looks at them as SVG renders, and steers the live viewer in the browser: the spider-paint page and, when a 3Draft checkout sits beside this repo, the 3Draft viewer too. The server, its tools and the engine (`mcp/engine/`) are copied from 3Draft by `scripts/sync.mjs`, so it runs from this repo alone.
4
+
5
+ ## Public endpoint (Gemini, ChatGPT, any web MCP client)
6
+
7
+ **`https://spider-paint.vercel.app/api/mcp`** is a public Streamable HTTP MCP server: no install, no sign-in (choose "no authentication" where a client asks). It is `api/mcp.mjs`, a Vercel function around `mcp/http.js`, and it is stateless: it writes no files and cannot steer an open viewer, so every result carries an `open_url` link that opens the scene in spider-paint.
8
+
9
+ - **Gemini:** Customize → Connectors → **+ Custom** → MCP Server URL: `https://spider-paint.vercel.app/api/mcp` → Next.
10
+ - **ChatGPT:** Settings → Apps / Connectors → create a custom connector (developer mode) with the same URL, authentication: none.
11
+ - **Claude:** Settings → Connectors → Add custom connector, same URL.
12
+
13
+ Tools:
14
+
15
+ | tool | what it does |
16
+ | --- | --- |
17
+ | `build_model` | runs model steps (`add_box`, `add_extrusion`, `add_mesh`, `add_character`, `transform` (also rotate_x / rotate_z, pivot), `instance` (copies of one object or group: one tree, many placements; unedited copies are stored once as a scene v2 prototype, so the link stays small), `place_on` (like G G: puts an object onto a surface), `sense` / `sensing` (the cursor's feel from the camera, with distances; which objects it feels), `extrude_face`, `move_vertices`, `boolean`, `recolor`, `remove`, `list`, `inspect`, …) and returns the objects, an SVG render and an `open_url` (`/#scene=…`, the whole scene packed into the link); pass that link back as `from` to keep building |
18
+ | `build_story` | an **animated story** from a model: keyframed `motions` (move / rotate / scale per object or `match` group), a `camera` orbit or keyframes, `captions` → a Spider Build v2 recording (see [Stories](#stories-build_story)); returns `open_url` (`/#story=…`, the editor's Stories player), `player_url` (`/player.html#story=…`), `story_token` (for `open_workshop` `story`) and a PNG preview of three moments. spider-paint endpoint only |
19
+ | `sky_scene` | a 3draft-sky catalogue (stars, planets, orbits) → a `#sky=…` link, optionally `target` to lock onto one body |
20
+ | `find` | searches the Deep Sky catalogue (stars, galaxies, nebulae, planets) → name, kind, distance and a `?scene=deepsky&target=…` link |
21
+ | `examples` | the bundled scenes with their links |
22
+ | `sky_guide` | the sky catalogue guide (sky.md) |
23
+
24
+ Links hold the scene in the URL fragment (deflate-raw, base64url), so they never reach a server; very large scenes (over ~200 KB of link) are refused.
25
+
26
+ ## Set up
27
+
28
+ From the spider-paint folder:
29
+
30
+ ```
31
+ codex mcp add spider-paint -- node "$(pwd)/mcp/server.js"
32
+ claude mcp add spider-paint -- node "$(pwd)/mcp/server.js"
33
+ ```
34
+
35
+ Claude Desktop (`claude_desktop_config.json`):
36
+
37
+ ```json
38
+ { "mcpServers": { "spider-paint": { "command": "node", "args": ["/absolute/path/to/spider-paint/mcp/server.js"] } } }
39
+ ```
40
+
41
+ Then ask the AI for the `viewer` tool's URL and open it. Environment:
42
+
43
+ | variable | default | |
44
+ |---|---|---|
45
+ | `3DRAFT_PORT` | 5173 | the live viewer's port (the next free one up to +9 if taken) |
46
+ | `3DRAFT_LIVE` | on | `0`: no live viewer, tools only |
47
+ | `3DRAFT_DIR` | `../3Draft` or `../3draft` | a 3Draft checkout to serve at `/3draft/app/` |
48
+
49
+ `node mcp/serve.js` serves the same pages without the MCP scene (PORT, default 5173). Everything listens on 127.0.0.1 only.
50
+
51
+ ## The viewers
52
+
53
+ - `http://localhost:5173/?live`: spider-paint. `?live` turns on the link: it shows the MCP scene and follows the `view_*` commands.
54
+ - `http://localhost:5173/3draft/app/`: the 3Draft viewer (only when a 3Draft checkout was found). It listens to the same link.
55
+
56
+ Every open viewer gets every change and every command. The viewers do not write back into the MCP scene: what the person edits by hand in the page stays in the page. The `viewer` tool lists the URLs and how many tabs are open.
57
+
58
+ ## How to work (for the AI)
59
+
60
+ 1. **Model** with `add_box`, `add_extrusion`, `add_mesh`, then shape with `extrude_face`, `move_vertices`, `boolean`, `transform`, `recolor`. Feel the scene like the viewer's cursor with `sense` (through a pixel of a render: the first surface, everything behind it, the distances); leave objects out with `sensing` (or `exclude` for one call) to place behind or into them. Make mechanisms with `group` (objects that move as one) and `connect` (glue, pivot, hinge, rail, spring: the holder carries the held part, which moves only as the joint allows; `move_joint` turns or slides it inside its limits, `joints` reports their state). Put things on each other with `place_on` (the viewer's G G: the foot onto the surface straight down at [x, z], upright or turned to the surface) and figures in with `add_character`. Name objects after what they are (`seat`, `leg_fl`): every later tool finds them by name. Repeat things with `instance`: model one pine (or one needle ring, one rock), group it if it has parts, then place many copies in one step with `copies: [{ at, scale, rotate_y, color }]`; a uniform scale, no rotate_z and no `colors` keeps a copy compact (format v2 `prototypes`, as the viewer's stars).
61
+ 2. **Look** after every few changes: `render` (an SVG sheet of four views by default; read it), `inspect` (closed, planar, convex, faces counter-clockwise from outside), `pick` (a pixel of a render -> object, face, 3D point, normal).
62
+ 3. **Show** it: `viewer` gives the URL for the person. `view_target` aims the viewer at an object, `view_camera` places the eye, `view_state` tells you what the person sees.
63
+ 4. **Keep** it: `export` (JSON text, or a `.json` file inside the server's working directory), `import`.
64
+
65
+ The engine: flat-coloured convex faces, no textures (except screens, below). Y is up, the ground is y = 0. Faces are listed counter-clockwise seen from outside.
66
+
67
+ ### Stories: `build_story`
68
+
69
+ A story is a model on a timeline: assembly, disassembly, an explosion view, a mechanism moving, a camera flight. `build_story`
70
+ writes it in the **Spider Build v2** format ([models/spider-build-v2.md](models/spider-build-v2.md)), the same format as the
71
+ LARK–4 assembly and the LARK–4C black-hole scene, so the same players play it: the editor's **Stories** mode (play / pause,
72
+ time slider, steps, speed, recorded camera on / off, captions) and the bare `player.html` ([PLAYER.md](PLAYER.md)). It is
73
+ stateless like `build_model`: the whole story travels packed in the link's `#story=` fragment.
74
+
75
+ | argument | meaning |
76
+ |---|---|
77
+ | `from`, `steps` | the model: a `build_model` `open_url` and / or modelling steps (as `build_model`), run first |
78
+ | `motions` | `[{ object \| objects: [...] \| match: "pyr-*", pivot: "center" (default) \| "foot" \| [x, y, z], ease, keys: [{ t, move, rotate, scale, ease }] }]` |
79
+ | `camera` | `{ orbit: { turns (default 0.25), radius, height, center, start_yaw, fov } }` (default: a slow orbit round everything that moves) or `{ keys: [{ t, eye, look_at \| yaw + pitch, transition: smoothstep \| linear \| cut, fov, roll }] }` |
80
+ | `captions` | `[{ start, end, text, channel: voiceover \| operation \| chapter }]` (ms) |
81
+ | `duration_ms`, `hold_ms` | the length (default: the last key + `hold_ms`, 800) |
82
+ | `mode` | `auto` (default), `animation` or `frames` (below) |
83
+ | `sample_ms` | the sampling step (animation 50, frames 80) |
84
+ | `shapes`, `shape_ms` | continuous mesh changes: `[{ object, keys: [{ t, shape, ease }] }]`, the mesh stored every `shape_ms` (default 70) |
85
+ | `preview` | PNG frames of the start, middle and end (default true) |
86
+ | `include_doc` | also return the `.build.json` document itself, to save or edit |
87
+
88
+ - **Keys are poses relative to the model.** `move` is the offset from where the object stands in the model, `rotate`
89
+ degrees round X, Y, Z about the pivot (applied as `transform`: scale, X, Z, Y, then move), `scale` a number or
90
+ `[x, y, z]`. Before its first key an object holds that key's pose, after its last key the last one: a disassembly goes
91
+ from `move: [0, 0, 0]` to the far place, an assembly the other way round (its first key already far away).
92
+ - `ease` (per key, the approach to it; or per motion): `smooth` (default), `linear`, `in`, `out`, `cut`. An arc is a
93
+ middle key (up and out with `out`, down with `in`).
94
+ - One motion per object. One motion may name many objects (`objects`, `match` with `*`): they move alike, each about its
95
+ own pivot.
96
+ - **Two storages.** `animation`: one rigid affine channel per distinct motion on the shared animation clock
97
+ (`tracks.animation`), blended on the GPU: smooth and small, but at most **64** distinct motions (the engine's limit).
98
+ `frames`: stop-motion on the construction track: every `sample_ms` only the objects that moved are put again with their
99
+ moved mesh; no limit, the size grows with how much moves. `auto` takes `animation` when it fits, else `frames`.
100
+ - **Shapes are processes, not jumps.** A modelling operation (an extrusion growing, a face scaling) is shown as a
101
+ continuous morph: each key names another object of the model whose mesh is the shape at `t` (the object's own name is
102
+ its model mesh). Those template objects are left out of the story. Between two keys vertex *i* moves from vertex *i*
103
+ of the previous shape; a vertex the previous shape lacks grows out of its nearest vertex, so an `extrude_face` result
104
+ rises from the face it was pulled from. To hold a shape, repeat it in the next key. The frames go on the construction
105
+ track (a `put` of the object every `shape_ms`), so shapes work in both storages. A shaped object has no motion.
106
+ - Links over ~200 KB are refused (the result says so): use a larger `sample_ms`, fewer moving objects, or `include_doc`
107
+ and keep the `.build.json` as a file (`player.html?scene=<its address>`).
108
+ - **Inline:** `open_workshop` with `story: <story_token>` (or `story: "story:<name>"` for a story bundled as
109
+ `models/<name>.build.json`, such as `story:spider-sculpt`) plays it inside the chat, in the native editor's Stories player.
110
+ A story is a recording, not a shared workshop session: `workshop_state` / `workshop_edit` do not apply to it.
111
+
112
+ A 91-brick pyramid taken apart from the top (frames mode, ~116 000 characters of link):
113
+
114
+ ```json
115
+ { "tool": "build_story", "arguments": {
116
+ "title": "Brick pyramid, taken apart",
117
+ "from": "<build_model open_url of the pyramid>",
118
+ "motions": [
119
+ { "object": "pyr-90", "keys": [ { "t": 0 }, { "t": 450, "move": [1.5, 2.4, 2], "rotate": [30, 40, 15], "ease": "out" }, { "t": 900, "move": [3, -2.5, 4], "rotate": [0, 120, 0], "ease": "in" } ] },
120
+ { "object": "pyr-89", "keys": [ { "t": 55 }, { "t": 505, "move": [3, 2, 0], "ease": "out" }, { "t": 955, "move": [6, -2, 1], "ease": "in" } ] }
121
+ ],
122
+ "captions": [ { "start": 0, "end": 2500, "text": "The capstone goes first" } ],
123
+ "camera": { "orbit": { "turns": 0.3 } }
124
+ } }
125
+ ```
126
+
127
+ ### Screens: an image, a scene or a web page on a face
128
+
129
+ `set_screen` turns four-cornered faces of an object into a screen in the viewer. Give exactly one of:
130
+
131
+ | | What the face shows | Where it shows |
132
+ |---|---|---|
133
+ | `image` | a picture (`.png .jpg .jpeg .webp .gif .avif .svg`) laid on the face as a texture, cut to the face's shape (not stretched) | the WebGL2 / WebGPU view, **in VR too**; depth tested like the face |
134
+ | `scene` | a 3Draft scene file (`.json`) played on the face, turning round its middle | the same, in VR too |
135
+ | `url` | a web page in an iframe over the face | the desktop only (not in VR, no depth); sites that forbid framing stay blank |
136
+
137
+ - Only **four-cornered** faces show a screen, seen from the front (the side the face's counter-clockwise winding faces).
138
+ Without `face` every four-cornered face of the object becomes the screen (a box: all six sides); for one side give its
139
+ face index (`get_mesh`; an `add_box`'s faces are +z, −z, +x, −x, +y, −y: its front, facing +z, is face 0).
140
+ - An image is read with `fetch`, so its server must allow cross-origin reading (**CORS**): the Spider site's own files
141
+ (`media/…`, relative addresses) do, many image hosts do not. When it is refused the
142
+ desktop shows the picture as a page (an iframe) instead, and the viewer says so.
143
+ - The screen is a material (`material`, default `screen-<object>`; faces that share it share the screen) kept in the
144
+ scene's `palette`: `export` / `import` keep it, and the viewer adds it to its palette. Call `set_screen` without
145
+ image / scene / url to make the faces plain again.
146
+ - The person can do the same in the viewer: the palette (P), a material's **url** field takes a page, an image or a scene.
147
+
148
+ ```json
149
+ { "tool": "add_box", "arguments": { "name": "poster", "size": [1.6, 0.9, 0.04], "at": [0, 1.4, 0], "color": "#202020" } }
150
+ { "tool": "get_mesh", "arguments": { "name": "poster" } }
151
+ { "tool": "set_screen", "arguments": { "name": "poster", "face": 0, "image": "https://spider-paint.vercel.app/media/spider-web.png" } }
152
+ ```
153
+
154
+ ### Steering the viewer
155
+
156
+ - `view_example` loads one of the viewer's scenes into the browser (beside the MCP objects, or alone with `replace: true`): `deepsky` (1000 galaxies, 11 colliding systems, 400 black holes, 3000 stars), `stars` (500 nearest), `milkyway` (30 000 super-stars), `stars-plain`, `globe`, `bridge`, `ex27`, `betterman`, and in spider-paint `human`, `tr74`, `station-screen`. These live in the browser only: `render`, `inspect`, `list` do not see them.
157
+ - `view_target` finds by name like the viewer's Enter search: case and accents do not matter; the whole name ranks first, then the start, a word start, any part. It also takes a kind (`planet`, `black hole`, `spiral galaxy`, `white dwarf`, `hot gas giant`): the nearest one of that kind. It works on everything shown, also the example scenes (`andromeda`, `sirius`, `sgr a`).
158
+ - `view_camera`: `eye` [x, y, z], `yaw` (0 looks towards -z, positive turns towards +x), `pitch` (positive looks down, as in Spider Build), `roll` (starship bank), all in degrees. It lets the target go. In the star maps 1 unit = 1 light year and the Sun is at the origin.
159
+ - `view_vehicle`: `starship` (space flight; speeds in ly/s, braking program, orbit), `car` (drives on the ground), `none` (the model camera).
160
+ - `view_state` returns the viewer's last report (every 2 s): vehicle, eye, yaw / pitch / roll, target, speed, orbit, object count, scene, view mode, and the report's age. `null` when no viewer is open.
161
+
162
+ - `view_sky` makes a whole space scene from a **sky catalogue** (format `3draft-sky`): stars, planets, moons, exoplanets, black holes and galaxies in astronomers' units (RA / Dec, distance or parallax, spectral type, AU, Earth radii…). The server turns it into a scene and the viewer shows it; the result lists what was left out and why. The format, how every kind of object is drawn, example prompts and where to find the data are in the **sky guide**: `sky.md` (shown as a page at `/sky.html`, linked from the viewer's help and its sky group).
163
+
164
+ A command reaches only viewers that are open: the result's `sent_to` says how many.
165
+
166
+ ### What the person can do in the viewer
167
+
168
+ Enter: find a target by name. Tab: next target. W/S, A/D, R/F: speed forward, sideways, up. [ / ő and ] / ú: roll. 0 / ö: orbit. Space: stop. Esc: let go. `?` opens the full help (help.md).
169
+
170
+ ## Tools
171
+
172
+ <!-- tools:start -->
173
+ | tool | arguments (bold: required) | what it does |
174
+ |---|---|---|
175
+ | `add_box` | **name**, size, at, color, replace | Add an axis-aligned box. `at` is the CENTER, so its bottom is at at[1] - size[1] / 2. Y is up, the ground is y = 0. Units are arbitrary but keep them consistent. |
176
+ | `add_extrusion` | **name**, **polygon**, **height**, y, color, replace | Add a prism: a CONVEX footprint polygon on the ground plane, given as [[x, z], ...] in any winding, extruded up by `height` from `y`. Use it for triangles, hexagons, wedges, roofs, columns. Concave shapes must be split into several convex extrusions. |
177
+ | `add_mesh` | **name**, **positions**, **faces**, color, replace | Add a raw mesh: `positions` [[x,y,z],...] and `faces` [{ v: [indices], color }]. Each face must be planar, convex and listed COUNTER-CLOCKWISE seen from outside (right-hand rule: the normal points out). Run inspect afterwards. |
178
+ | `transform` | **name**, scale, rotate_x, rotate_z, rotate_y, pivot, move | Scale, then rotate round X, then round Z, then round Y, then move an object. Scale and rotations are about the center of its bounding box (or about `pivot`). Rotations are degrees, counter-clockwise looking from the + end of the axis towards the origin (right-hand rule): rotate_y 90 turns +x into -z, rotate_x 90 turns +y into +z, rotate_z 90 turns +x into +y. |
179
+ | `instance` | **name**, **source**, at, scale, rotate_x, rotate_y, rotate_z, color, colors, copies, replace | Copies of an object or group (`source`, the prototype as it is now), each placed by its foot at `at`, scaled and turned about the foot (as transform), with `color` (all faces) or `colors` ({ "#old": "#new" }). `copies` places many in one step; unnamed ones are <name>-1, <name>-2…; a group source makes <copy>.<member> objects grouped as <copy>. Copies with a uniform scale, no rotate_z and no `colors` are exported compactly (`export` with compact: true, and every `open_url`): scene format v2 `prototypes` + `{ name, proto, at, scale, rot, color }`, the same records the viewer uses for stars. Editing a copy later makes it a plain mesh again. |
180
+ | `place_on` | **name**, onto, at, point, normal, from, dir, x, y, view, yaw, pitch, size, exclude, include, align, turn, gap | Put an object down on the surface of others, like the viewer's G G: its foot (the middle of the bottom of its bounding box; for a character the middle of where it stands) goes onto the surface point, and with align "normal" its up turns to the surface normal (a thing on a slope, a ball, a wall). Say where with `at` [x, z] (dropped straight down there: the highest surface under that spot), or a pixel `x`, `y` of a render (the ray from the camera, like the viewer's cursor; view / yaw / pitch / size as render), or `point` (+ `normal`) from sense / pick, or a ray (`from` + `dir`). Default: straight down at the object's own x, z. It lands on the sensing set (see sensing) without itself, or on `onto`; exclude / include change the set for this call (exclude a wall to place behind it). Returns the new bounds and the surface it landed on with its distance along the ray. |
181
+ | `add_character` | **name**, preset, seed, spec, pose, at, yaw, onto, replace | Add a character from the viewer's character builder: a stylized figure (about 1.6-1.9 tall, the units are metres) in a few meshes merged into one object, its feet on y = 0 at `at`, facing `yaw`. Presets: scientist, mechanic, crew (Space 1999 style uniform), astronaut. `seed` makes a random variation of the preset, `spec` overrides any field of the builder's spec (base: "male" \| "female", body: { height, build, shoulders, head }, face: { shape, skin }, hair: { style, mat }, outfit: { kind, main, second, helmet }, prop). Pose: stand, sit (the seat under the hips at about 0.44) or walk (one stride). Give `onto` (and `at`) to stand it on a surface, as place_on. |
182
+ | `sense` | view, yaw, pitch, size, x, y, from, dir, exclude, include, limit | Feel the scene along a ray, as the viewer's cursor does from the camera: through pixel (x, y) of a render (same view and size as render), or from `from` along `dir`. Returns the first surface (object, face, point, normal, distance from the eye or `from`) and `hits`: everything along the ray, nearest first, with `outside` true where the ray enters an object and false where it leaves it, so you can see what is behind and how thick it is. Only the sensing set counts (see sensing); exclude / include change it for this call. Use the point and normal with place_on (point + normal), or give place_on the same pixel. |
183
+ | `sensing` | ignore, sense, only, reset | The sensing set: which objects sense, pick and place_on feel (the viewer's cursor feels everything; here you choose). New objects are sensed. ignore takes objects out (e.g. a wall to place things behind it, a box to place into it), sense puts them back, only senses just these, reset senses everything again. Returns the sensed and the ignored objects. |
184
+ | `group` | **name**, objects, rename | Make a group: the objects move as one (in the viewer a G on any of them takes the whole group; the user groups a B selection with Ctrl+G). `objects` join the group `name` (leaving any group they were in); `rename` gives the group a new name. Returns every group. |
185
+ | `ungroup` | **name** | Break a group up: its objects move on their own again (joints stay). |
186
+ | `connect` | **type**, **a**, **b**, name, at, at_b, contact, edge, axis, path, slider, limit, limits, rest_length, stiffness, damping, ends, spring_object, spring_line | Join two objects with a joint (the basic mechanics). `a` holds, `b` is held: moving a carries b along; b itself moves only as the joint allows (move_joint here, a drag in the viewer). Kinds: glue (a and b move together; `contact`: the touching point, line or face as points), pivot (b turns about the point `at`, a ball joint; `limits` { x: [min, max], y, z } degrees round the world axes from the pose now), hinge (b turns about a line: `edge` [i, j], two vertex indices of b, e.g. a door's vertical side, or `axis` [[x,y,z], [x,y,z]]; `limit` [min, max] degrees, positive counter-clockwise looking from the second point towards the first), rail (b slides along the polyline `path` of a, its point `slider` (default its vertex nearest the rail) on the rail; `limit` [min, max] distance along the rail from its start), spring (b hangs on a spring from `at` on a to `at_b` on b; `rest_length` (default the distance now), `stiffness` (default 40), `damping` (default 3), `ends` [glue \| pivot, glue \| pivot]; `spring_object`: an object to stretch between the ends, its line `spring_line` [i, j] (default its longest side); the viewer animates it). Every geometry is in world coordinates now and then sticks to the objects. Returns the joint and its state. |
187
+ | `disconnect` | **name** | Take a joint away (by its name; see joints). |
188
+ | `joints` | – | The joints and groups now: each joint's kind, holder (a), held part (b), its limits and its state (a hinge's angle, a pivot's angles, a rail's position, a spring's length) with its geometry in world coordinates. |
189
+ | `move_joint` | **name**, angle, angles, position | Move a held part as its joint allows, kept inside the limits: a hinge to `angle` (degrees from the pose it was connected in), a pivot to `angles` [x, y, z] (degrees round the world axes), a rail to `position` (distance along the rail). What b holds moves along. Returns the state reached (clamped). |
190
+ | `get_mesh` | **name** | Read an object's geometry so you can shape it: the vertices (index = position in the list) and the faces with their vertex indices, color, center and outward normal. Use it to find the face or vertex indices for extrude_face and move_vertices. |
191
+ | `extrude_face` | **name**, **face**, distance, scale, color | Shape an object by pushing one of its faces out, like a modeller. The face is replaced (same index) by a copy moved `distance` along its outward normal and scaled by `scale` about its center, joined to the old edges by new side faces. distance > 0 and scale 1: a prism grows out (a wing, a chimney, a step). distance > 0 and scale < 1: a taper (roof, tower top, frustum). distance 0 and scale < 1: an inset (a panel or window frame; extrude it again, negative, for a recess). distance < 0: a dent into the solid (a niche, a door recess). The result is a closed solid again; chain calls on the returned `cap` face. |
192
+ | `move_vertices` | **name**, **indices**, **by** | Move the vertices with the given indices by [dx, dy, dz] (see get_mesh for the indices): shear, lean, pinch a roof ridge, raise a corner. Faces keep their vertices, so moving only some corners of a face can make it non-planar; the result reports that. Move all the corners of a face together to keep it flat. |
193
+ | `boolean` | **a**, **b**, **op**, name, keep | Boolean of two closed solids: union, subtract (a minus b: a door, a window, a hole) or intersect. Both objects must be closed solids with outward faces (inspect says so). The result is a new closed solid; faces keep their colors and a face cut into a solid takes the color of the cutting face. By default a and b are replaced by the result; `keep: true` keeps them. |
194
+ | `recolor` | **name**, **color**, face | Change the color of a whole object, or of one face when `face` is given. |
195
+ | `set_screen` | **name**, face, image, scene, url, material, color | Make faces of an object a screen in the viewer: give exactly one of `image` (a picture, .png .jpg .jpeg .webp .gif .avif .svg: laid on the face as a texture, cut to the face's shape, depth tested and seen in VR too; its server must allow cross-origin reading (CORS), else the desktop shows it as a page), `scene` (a 3Draft scene file .3draft / .json, played on the face turning round its middle) or `url` (a web page, shown in an iframe over the face on the desktop; not in VR, sites that forbid framing stay blank). Only four-cornered faces show it; seen from the front (the side the face's CCW winding faces). Without `face` every four-cornered face of the object becomes the screen (a box: all six sides), so for one side give its face index (get_mesh). The screen is a material (`material`, default "screen-<object>") kept in the scene's palette (export / import keep it); give none of image / scene / url to make the faces plain again. |
196
+ | `remove` | **name** | Remove one object. |
197
+ | `clear` | – | Remove every object. |
198
+ | `list` | – | List the objects with their face counts and axis-aligned bounds (min / max corners). |
199
+ | `inspect` | name | Check an object (or all when name is omitted): closed shell, faces CCW from outside, planar, convex. Returns plain-text notes about what to fix. Run it after add_mesh. |
200
+ | `render` | view, yaw, pitch, size, points | Render the scene as a flat-colored SVG with edges and points (text, deterministic). Default is a 2x2 sheet of front, side, top and perspective. Each <polygon data-face=".."> is one face, <circle data-v=".."> a vertex. Look at it to judge the model, then fix and render again. |
201
+ | `pick` | view, yaw, pitch, size, **x**, **y**, exclude, include | What is at pixel (x, y) of a render? Uses the same camera and size as render. Returns the object, its face index, the 3D point, the surface normal and the distance. Use it to find coordinates to place or stack things. Only the sensing set counts (see sensing; exclude / include for this call); sense also lists what lies behind. |
202
+ | `export` | path | Return the scene as JSON, or write it to `path` (relative, inside the server working directory, ending in .3draft (the 3Draft scene file) or .json). |
203
+ | `import` | json, path | Replace the scene with a JSON scene, given as `json` text or read from `path` (same rules as export). |
204
+ | `view_target` | **name** | Make the open viewer target an object by name (as the viewer's Enter search: case and accents do not matter; the whole name, then the start, a word start, any part). In a star map the starship turns to it and the braking program stops it at the surface when you fly there. Works on everything the viewer shows, also the loaded example scenes (stars, galaxies), not only the MCP objects. |
205
+ | `view_camera` | **eye**, yaw, pitch, roll | Put the open viewer's eye at a point, looking along yaw / pitch (degrees; yaw 0 looks towards -z, positive yaw turns towards +x, positive pitch looks down, as in the Spider Build format). In a star map the units are light years (the Sun at the origin). `roll` (degrees) banks the starship. |
206
+ | `view_vehicle` | **vehicle** | Switch the open viewer's vehicle: "starship" (space flight, light years), "car" (drives on the ground), or "none" (the ordinary model camera). |
207
+ | `view_example` | **name**, replace | Load one of the viewer's bundled scenes into the open viewer (beside the MCP objects, or instead of everything with replace: true). The names are the viewer's scene list, e.g. deepsky (1000 galaxies, 400 black holes, 3000 stars), stars, milkyway, stars-plain, sky:trappist-1 (a sky catalogue), globe, bridge, ex27, betterman (spider-paint also: human, tr74, station-screen). It is shown in the browser only: render and inspect do not see it. |
208
+ | `view_sky` | sky, path, replace, save | Make a space scene from a sky catalogue and show it in the open viewer (the format is app/sky.md, "3draft-sky"): stars, planets, moons, dwarf planets, exoplanets, black holes and galaxies in astronomers' units. A place is ra / dec (degrees, or "hh mm ss" / "±dd mm ss" strings, or ra_h hours) with dist + unit (ly, pc, kpc, Mpc, AU, kly, Mly, Gly) or parallax (mas), or at [x, y, z] in scene light years (the Sun at the origin, y = equatorial north). A star: spect (e.g. "G2V", "M5.5Ve", "DA"), temp (K), lum (L☉) or absmag or vmag, radius (R☉). A planet / moon goes round another object with around (its name), a (AU) or a_km, optional incl / node / angle (degrees), radius_earth / radius_km / radius_jup, teq (K, else from the star), surface (a planet shader recipe), ring, orbit: true (draw the orbit). A black hole: mass (M☉), radius_ly (drawn size). A galaxy: kind (spiral, elliptical, irregular, dwarf, interacting, early), diameter_kly or radius_ly, incl / pa, arms, bar. Any object: name, info (shown under the name when targeted), category (the find box's kind), color. start: { near: name, distance: ly } or { eye, yaw, pitch }. Returns the counts and notes about anything left out; save writes the made scene as a .3draft file the viewer opens (f↑). |
209
+ | `view_state` | – | What the open viewer shows now (it reports every 2 seconds): vehicle, eye, yaw / pitch / roll (degrees), the target, the speed, the object count, the loaded scene. null when no viewer is open. |
210
+ | `viewer` | – | The URL of the live viewer: a browser page that shows this scene and updates after every change you make. Tell the user to open it. Returns null when the live viewer is off. |
211
+ <!-- tools:end -->
package/PLAYER.md ADDED
@@ -0,0 +1,139 @@
1
+ # Spider Player
2
+
3
+ A bare 3D player to embed in any web page. It shows one thing and has **no UI of its own**: no buttons, no panels, no
4
+ captions on screen, no keyboard or mouse handling. The page around it controls it with URL parameters and `postMessage`
5
+ commands, and it reports back with events.
6
+
7
+ - A **scene** (a 3Draft scene file, `.3draft`; older ones `.scene.json`) turns slowly on a turntable round its middle.
8
+ - A **story** (a Spider Build v2 file, `.build.json`) plays on its own timeline: the model is built step by step and the
9
+ recorded camera moves with it. It loops by default.
10
+ - The background is **transparent** (the page shows through) or a colour you give.
11
+
12
+ It loads only the renderer (WebGL2), the scene loading and the story format: about 180–200 kB, **50–60 kB gzipped**,
13
+ instead of the whole editor. The scene files themselves are usually the bigger download.
14
+
15
+ **Address:** `https://spider-paint.vercel.app/player.html` (in the 3Draft repository: `app/player.html`).
16
+
17
+ ## Embedding
18
+
19
+ ```html
20
+ <iframe
21
+ src="https://spider-paint.vercel.app/player.html?scene=models/lark-4.scene.json&bg=transparent&spin=20"
22
+ style="width: 640px; height: 400px; border: 0; background: transparent"
23
+ allowtransparency="true"
24
+ title="LARK-4"></iframe>
25
+ ```
26
+
27
+ The player fills the frame (any size or aspect ratio) and keeps the whole model in view across the shorter side.
28
+ A transparent background works when the iframe itself has no background (as above); the page's own colours show round the model.
29
+
30
+ ### Where scenes come from
31
+
32
+ - the Spider site's own models: `models/lark-4.scene.json`, `models/bridge.scene.json`, `models/lark-4.build.json`, …;
33
+ - the online store: `scene=/api/store?name=<name>` (a scene saved with ☁ in spider-paint);
34
+ - any other address that allows cross-origin reading (CORS), e.g. a raw GitHub file
35
+ (`https://raw.githubusercontent.com/<user>/<repo>/main/x.scene.json`).
36
+
37
+ A relative address is relative to the player page.
38
+
39
+ Without `scene`, the player reads a packed story or scene from its own fragment: `player.html#story=<…>` (MCP
40
+ `build_story`'s `player_url`) or `player.html#scene=<…>` (a `build_model` link's fragment), deflate-raw + base64url.
41
+
42
+ ## URL parameters
43
+
44
+ | Parameter | Default | Meaning |
45
+ |---|---|---|
46
+ | `scene` (or `src`) | — | the scene (`.3draft`, or an older `.scene.json`) or story (`.build.json`) to load |
47
+ | `bg` | `transparent` (or the story's own `presentation.background`) | `transparent`, or a colour: `1a1a2e`, `#1a1a2e`, `fff`; given, it wins over the story's |
48
+ | `spin` | `20` | the turntable's speed, degrees per second; `0` stands still, negative turns the other way |
49
+ | `yaw` | `30` | the turntable's starting angle round the vertical, degrees |
50
+ | `pitch` | `20` | how far the camera looks down on the model, degrees (−89 … 89) |
51
+ | `zoom` | `1` | `2` = twice as close, `0.5` = twice as far |
52
+ | `autoplay` | `1` | a story starts playing at once (`0`: it waits for `play`) |
53
+ | `loop` | `1` | a story starts again at its end (`0`: it stops on its last frame) |
54
+ | `speed` | `1` | a story's playback speed (0 … 16) |
55
+ | `camera` | `auto` | `auto`: a story uses its recorded camera, a scene the turntable; `orbit`: the turntable for a story too |
56
+ | `smooth` | `1` | smooth shading of curved surfaces (`0`: every face flat) |
57
+ | `studio` | `1` | three studio lights that follow the camera (`0`: one fixed sun) |
58
+ | `origin` | `*` | the embedding page's origin (e.g. `https://example.com`): events are posted only to that origin |
59
+
60
+ ## Commands (the page → the player)
61
+
62
+ Send a message to the iframe's window. Every command is an object with `target: 'spider-player'` and a `cmd`; an `id` of
63
+ your own comes back with the answer.
64
+
65
+ ```js
66
+ const player = document.querySelector('iframe').contentWindow;
67
+ const send = (cmd, extra = {}) => player.postMessage({ target: 'spider-player', cmd, ...extra }, '*');
68
+
69
+ send('load', { url: 'models/bridge.scene.json' });
70
+ send('spin', { value: 45 });
71
+ send('background', { value: '#101820' });
72
+ send('seek', { t: 12000, id: 'jump-1' });
73
+ ```
74
+
75
+ | `cmd` | Fields | Does |
76
+ |---|---|---|
77
+ | `load` | `url` (address) or `data` (the scene / story object itself) | loads another scene or story in place of the current one |
78
+ | `play` | — | plays the story (from the start if it is at its end) |
79
+ | `pause` | — | stops the story where it is |
80
+ | `toggle` | — | play ↔ pause |
81
+ | `seek` | `t` (ms) | jumps to that moment of the story |
82
+ | `speed` | `value` (0 … 16) | playback speed |
83
+ | `loop` | `value` (true / false) | start again at the end, or stop there |
84
+ | `camera` | `value`: `auto` / `orbit` | a story's recorded camera, or the turntable round the model |
85
+ | `spin` | `value` (°/s) | the turntable's speed (0: still) |
86
+ | `yaw` | `value` (°) | the turntable's angle now |
87
+ | `pitch` | `value` (°, −89 … 89) | how far the camera looks down |
88
+ | `zoom` | `value` (0.05 … 50) | closer / farther |
89
+ | `background` | `value`: `transparent` or a colour | the background |
90
+ | `smooth` | `value` (true / false) | smooth shading |
91
+ | `studio` | `value` (true / false) | studio lights |
92
+ | `state` | — | only answers with the state |
93
+
94
+ `play`, `pause`, `toggle` and `seek` work on a story only; on a scene they answer with an `error`.
95
+
96
+ ## Events (the player → the page)
97
+
98
+ Every event is a message with `source: 'spider-player'` and a `type`.
99
+
100
+ ```js
101
+ addEventListener('message', (e) => {
102
+ const m = e.data;
103
+ if (m?.source !== 'spider-player') return;
104
+ if (m.type === 'caption') subtitles.textContent = m.text;
105
+ if (m.type === 'time') progress.value = m.t / m.durationMs;
106
+ if (m.type === 'error') console.warn(m.message);
107
+ });
108
+ ```
109
+
110
+ | `type` | Fields | When |
111
+ |---|---|---|
112
+ | `ready` | the state | the player has started (and loaded the URL's `scene`, if there was one) |
113
+ | `loaded` | the state | a scene or story has been loaded |
114
+ | `state` | the state, `cmd`, `id` | the answer to every command that worked |
115
+ | `error` | `message`, `cmd`, `id` | a command failed, a file could not be loaded, or WebGL2 is missing |
116
+ | `time` | `t`, `durationMs` (ms) | while a story plays, four times a second |
117
+ | `caption` | `text`, `cues` ([{ `channel`, `text` }]) | a story's narration changed (`text` is empty when there is none); show it yourself if you want subtitles |
118
+ | `ended` | `loop` | a story reached its end (with `loop` it goes on from the start) |
119
+
120
+ **The state:** `{ url, kind: 'scene' | 'story', playing, t, durationMs, speed, loop, camera, spin, yaw, pitch, zoom,
121
+ background, objects, title }`.
122
+
123
+ ## On the same page (no iframe)
124
+
125
+ When the player page is opened directly (or from the same origin), the same commands are a function call and the same
126
+ events are a DOM event:
127
+
128
+ ```js
129
+ await spiderPlayer.send({ cmd: 'pause' }); // → the state, or throws the error
130
+ spiderPlayer.state();
131
+ addEventListener('spider-player', (e) => console.log(e.detail)); // { source, type, ... }
132
+ ```
133
+
134
+ ## What it does not do
135
+
136
+ - No sound: a story's audio cues are not played (their text comes as `caption` events).
137
+ - Star maps and sky backdrops (`deepsky`, a story's sky environment) are not drawn: it is a player for models.
138
+ - Image, page and scene screens on faces (material `image` / `url` / `scene`) are not shown; the faces keep their colour.
139
+ - No VR, no editing, no picking with the mouse.
package/README.md CHANGED
@@ -1,3 +1,183 @@
1
- # Temporary Holding Version
1
+ # spider-paint
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <img src="media/spider-paint-logo.svg" alt="spider-paint logo: an animated low-poly spider" width="256">
4
+
5
+ Interactive 3D creation and exploration, powered by **3Draft**. Based on the 2026 Fifth Percent competition sprint.
6
+
7
+ The editor opens with **no scene** and **does not request VR** until you choose Enter XR. WebXR/Meta Quest and ViRtuSH hand interactions remain available. The scene picker offers **Globe**, **Deep Sky** and **Fifth Percent VR (LARK + Deep Sky)**. Model-format tooling is retained.
8
+
9
+ ## OpenAI plugin package manifest
10
+
11
+ The portable [plugin.json](plugin.json) defines the **spider-paint** listing: display name, description, developer, existing PNG icons, and both `homepage` and `extensions.com.openai.interface.websiteURL` set to [Tüskék és Gyökerek](https://tuskek-es-gyokerek.vercel.app). The companion [mcp.json](mcp.json) declares the remote MCP endpoint used by the embedded workshop (`https://spider-paint.vercel.app/api/mcp`).
12
+
13
+ These are packaging files only. They do **not** change the existing custom MCP connection or automatically publish the plugin. For a public directory submission, use the plugin submission flow **With MCP** and complete domain verification, tool checks, and review materials. The currently absent `privacyPolicyURL` and `termsOfServiceURL` must be added only after genuine public pages exist; do not use placeholders. The manifest's semantic version (`1.0.0`) is the **plugin package version**, independent of spider-paint's date-based npm version.
14
+
15
+ ## Claude plugin
16
+
17
+ [plugins/spider-paint](plugins/spider-paint) is the Claude plugin: a manifest, the same remote MCP endpoint and a `spider-paint` skill that teaches the shared-workshop workflow. The repository root is also a Claude plugin marketplace ([.claude-plugin/marketplace.json](.claude-plugin/marketplace.json)), so in Claude Code: `/plugin marketplace add Pengeszikra/spider-paint` then `/plugin install spider-paint@spider-paint`. `node tests/claude-plugin.mjs` checks the package. Public Claude directory listing is a separate submission and is not done.
18
+
19
+ ## Native UI refinements (Nov 2026)
20
+
21
+ - The ChatGPT-embedded editor (`?workshop=1`) starts in spider-paint's **existing Zen mode** (model full-screen), with the native **Leave zen** control, **Z**, or **Esc** to restore the full UI. Normal standalone spider-paint starts with its full UI unchanged.
22
+ - The **SYS** panel now has an icon-only keyboard button for the **tutorial keycast**. When enabled, actual pressed keys and modifiers appear briefly at the top, without intercepting events or creating a second toolbar. Its enabled state is local to the browser (`spider-paint.tutorial`). To enable it in a Zen-started workshop, exit Zen, activate the keyboard icon in SYS, then return to Zen with Z.
23
+ - **Save** is a disk icon; **Character builder** is a person emoji. Both retain their original actions, titles, and accessible names.
24
+ - `node tests/tutorial-ui.mjs` tests the native controls, Zen activation, and passive keycast; the MCP App CI workflow runs the test.
25
+
26
+ ## ChatGPT-native collaborative MCP App Workshop
27
+
28
+ The primary workshop embeds the **real spider-paint editor** inside a ChatGPT MCP Apps widget (resource `ui://spider-paint/workshop-v7.html`). Its original controls, keys, selection, navigation, WebGL and XR remain authoritative: there is no second editor UI.
29
+
30
+ `open_workshop` creates a capability-scoped `session_id` and runs declarative modeling steps in the browser. The native editor publishes its scene after loading and after human geometry edits. The AI can then call `workshop_state({session_id})` to inspect the **actual** objects and revision, and `workshop_edit({session_id,revision,steps})` to enqueue further changes for **that same open workshop**. The widget polls for queued edits, models them in the browser through the 3Draft `WorkshopModel`, and imports the result into the native editor. The new scene is published back with a revision acknowledgement. A queued edit must not be mistaken for a completed edit; call `workshop_state` again to verify `last_edit.status === 'applied'`.
31
+
32
+ The older stateless `workshop_token` continuation and `#scene=` links still work. `workshop_edit` is the shared-workshop path and avoids generating a separate iframe for every agent change. A short integration guide, limits and detailed test procedure live in [WORKSHOP.md](WORKSHOP.md).
33
+
34
+ **MVP constraint:** session storage is **in memory** in the Cloud Run process (2-hour idle TTL, maximum 64 sessions). Keep Cloud Run at **one instance** for now; a cold restart, redeploy or different instance loses the session. This is not yet durable multi-user collaboration, and a server acknowledgement alone does not prove host-side rendering. Scenes are capped at 600 KB and edits use optimistic revisions to prevent stale writes. The `session_id` is a bearer capability: do not publish or log it.
35
+
36
+ Cloud Run serves the native browser app and the MCP bridge. WebGL and ordinary geometry execution remain browser-local. The earlier standalone `workshop.html` prototype is legacy diagnostics, not the product direction.
37
+
38
+ ## Animated stories over MCP
39
+
40
+ `build_story` turns a model plus keyframed motions, a camera path and captions into a Spider Build v2 story (the format of
41
+ the LARK assembly and the black-hole scene). Its `open_url` plays it in the editor's Stories player, `player_url` in the bare
42
+ `player.html`, and `open_workshop({ story })` plays it inline in the chat. See [MCP.md](MCP.md#stories-build_story).
43
+
44
+ ## Run locally
45
+
46
+ ```sh
47
+ npm install
48
+ npm start
49
+ # or, after publishing to npm:
50
+ npx spider-paint
51
+ ```
52
+
53
+ Open http://localhost:5173. No application build system is needed.
54
+
55
+ ## Project boundaries and deployments
56
+
57
+ - **spider-paint** (`Pengeszikra/spider-paint`) is deployed to Cloud Run only, at `spider-paint.run.app`, and has the `spider-paint` npm package. There is no spider-paint Vercel deployment.
58
+ - **3Draft** (`Pengeszikra/3Draft`) is the separate 3D engine repository and npm module.
59
+
60
+ The product name is always lowercase **spider-paint**. The app header can retain **3Draft** as a quiet engine attribution.
61
+
62
+ ## Cloud Run (browser app + MCP)
63
+
64
+ **Cloud Run deployment is automated in GitHub Actions** (once keyless Google Cloud IAM/WIF setup is completed). Push to `main` → `spider-paint MCP App` CI must succeed → `Deploy spider-paint to Cloud Run` builds and deploys that tested SHA. The deployment checks the service's `/api/version` response against the expected commit. See [the setup and verification guide](docs/cloud-run-ci.md), or run `bash scripts/setup-cloud-run-oidc.sh PROJECT_ID` once with authorized `gcloud` and `gh` credentials. **Without that setup, the workflow is present but cannot deploy.** Agents must follow the deployment rules in [AGENTS.md](AGENTS.md).
65
+
66
+
67
+ The Dockerfile now starts `bin/cloud-run.mjs` with Node.js on the Cloud Run `PORT`.
68
+ One origin serves the browser application, `POST /mcp` and the compatible `POST /api/mcp` endpoint.
69
+ It does **not** require a Vercel deployment. The legacy scene-store API is not hosted here.
70
+
71
+ ```sh
72
+ # Emergency manual fallback ONLY; normal deployments run from GitHub Actions:
73
+ gcloud run deploy spider-paint --source . --region europe-west1 --allow-unauthenticated \
74
+ --update-env-vars "SPIDER_PAINT_GIT_SHA=$(git rev-parse HEAD)"
75
+ # Check the actual Cloud Run service URL; do not guess the hostname:
76
+ gcloud run services describe spider-paint --region europe-west1 --format='value(status.url)'
77
+ ```
78
+
79
+ Use the returned service URL plus `/mcp` as the ChatGPT custom MCP server URL.
80
+ Test locally with `PORT=8080 node bin/cloud-run.mjs` and `node tests/cloud-run.mjs`.
81
+ A push starts CI; successful main CI starts the Cloud Run deploy workflow. Check the deploy run and live /api/version: do not equate a green CI run with a successful Cloud Run release.
82
+
83
+ `GET /api/version`, the main editor's build stamp, the MCP tool result, and
84
+ the embedded ChatGPT workshop now show the spider-paint package version followed by
85
+ the actual build's Git commit (shortened to 8 characters in UI). The full
86
+ hash is available in the JSON response and browser title/debug panel.
87
+ The multi-stage Dockerfile captures `git rev-parse HEAD` while the source checkout is present, stores it as a private `mcp/build-sha.txt`, then removes `.git` before producing the runtime image. A build from a source archive **without** `.git` must pass `--build-arg SPIDER_PAINT_GIT_SHA=<exact-source-commit>` to Docker, or set `SPIDER_PAINT_GIT_SHA` on the Cloud Run service (as in the command above). Never substitute the latest remote branch SHA: it might not match the deployed source. If the SHA truly is unavailable, the UI shows `git ?` instead of inventing an identity. Verify the deployed image at `GET /api/version` after redeploy.
88
+
89
+ ## MCP debugging and timeout correlation
90
+
91
+ The `open_workshop` response returns a random `trace_id` in `structuredContent`
92
+ and in the textual tool result; the HTTP response also supplies `x-spider-paint-trace-id`.
93
+ Use the MCP tool `debug_trace({trace_id})` to inspect a **recent** request.
94
+ Milestones include `request_received`, `steps_validated`, `response_ready`
95
+ and `request_failed`. Each event records elapsed milliseconds and response
96
+ size. **The MCP server does not know vertex/face counts:** those are determined
97
+ in the browser widget. No raw prompts, meshes, URLs or request bodies are logged.
98
+
99
+ The embedded widget optionally reports `widget_loaded`, `widget_rendered`,
100
+ `widget_empty`, or `widget_error` via `window.openai.callTool` when supported
101
+ by the host. **No widget feedback is not proof of a crash:** host sandboxes may
102
+ disallow callbacks, or rendering can time out before telemetry is delivered.
103
+ If the host times out before returning the response, inspect Cloud Run
104
+ structured logs for `component=spider-paint-mcp` around the failure time instead.
105
+ Correlate using the `traceId` field (Cloud Run may have multiple instances).
106
+
107
+ Traces are deliberately metadata-only, kept **in memory for at most 15 minutes**
108
+ and limited to 128 per instance. `debug_trace` requires the unguessable trace ID;
109
+ there is no public endpoint listing other users' requests. For durable debugging,
110
+ use private Google Cloud Logging access. This cannot observe ChatGPT's internal
111
+ timeouts, only the stages that the server or widget actually reports.
112
+
113
+ To smoke-test locally:
114
+
115
+ ```sh
116
+ npm run test:mcp-app
117
+ node tests/cloud-run.mjs
118
+ ```
119
+
120
+ ## npm
121
+
122
+ The package name is `spider-paint`, with a CLI that hosts the app locally. The project uses its existing date-based `YY.M.DNNN` version scheme (`scripts/bump.mjs`) for npm releases as well.
123
+
124
+ ```sh
125
+ npm run release -- --dry-run # preview next date-based version, no changes
126
+ npm run release # bump package.json, then npm publish
127
+ git add package.json
128
+ git commit -m "Release spider-paint"
129
+ git push
130
+ ```
131
+
132
+ Run `npm run release` instead of `npm publish`: direct publishing is guarded against accidentally reusing an existing version. The bump happens **before** npm constructs the tarball; npm's `prepublishOnly` hook runs too late to change the version npm has already chosen. Publication still requires your npm authentication and is not automatically triggered by a GitHub push. The project is licensed under MIT (see LICENSE).
133
+
134
+ ## Compatibility
135
+
136
+ - `?scene=globe`, `?scene=deepsky` or `?scene=game:lark` explicitly loads a scene.
137
+ - `?autovr` explicitly enables the previous automatic headset VR offer.
138
+ - Desktop starts empty; use **Enter XR** to enter VR manually.
139
+
140
+ Original source: https://github.com/Pengeszikra/five-percent
141
+
142
+
143
+ ## Legacy local Workshop 002 (diagnostics only)
144
+
145
+ ```sh
146
+ npm install
147
+ npm run workshop
148
+ # open http://localhost:5173/workshop.html
149
+ ```
150
+
151
+ This is a **local-first** shared scene with the existing 3Draft geometry kernel, not a second model format.
152
+
153
+ **Human in browser**: WebGL2 scene (drag to orbit, scroll to zoom, click to select), add/transform/rotate/remove named meshes, inspect deterministic SVG views, export JSON, and queue new instructions **while an agent is working**. The WebGL camera is *local to each browser*, not part of shared geometry.
154
+
155
+ **Agent in another terminal**: connect an MCP client to the same running Workshop instance through:
156
+
157
+ ```json
158
+ {
159
+ "mcpServers": {
160
+ "spider-paint-workshop": {
161
+ "command": "node",
162
+ "args": ["/ABSOLUTE/PATH/TO/spider-paint/bin/workshop-mcp.mjs"]
163
+ }
164
+ }
165
+ }
166
+ ```
167
+
168
+ This stdio proxy forwards all MCP calls into the **one** running HTTP workshop process. There is no second scene. On the same machine: `npm run mcp:workshop`. The proxy accepts `SPIDER_PAINT_WORKSHOP_URL` if the HTTP endpoint is not on port 5173.
169
+
170
+ The agent should invoke ordinary 3Draft tools (`add_box`, `transform`, `render`, `inspect`, `list`, etc.) and periodically call **`workshop_messages`** to read new human instructions; **`workshop_reply`** acknowledges/responds to them. The browser's instruction box can take additional messages immediately, without cancelling scene operations. These messages are **not** auto-executed by a model: the connected agent has to poll them explicitly.
171
+
172
+ HTTP interface:
173
+ - `GET /api/scene`: scene state with monotonic revision
174
+ - `POST /api/tool`: execute a 3Draft tool against that scene
175
+ - `GET /api/events`: SSE changes to the shared scene and instruction queue
176
+ - `GET /api/version`, `GET /api/inbox`, `POST /api/inbox`, `POST /api/presence`, `GET /api/participants`
177
+ - `POST /mcp`: minimal JSON-RPC over HTTP, **not a complete Streamable HTTP MCP** transport; use the stdio bridge for MCP clients.
178
+
179
+ **Test:** `npm run test:workshop` exercises MCP → scene → browser API, instruction acknowledgments, participant presence and static-file protection.
180
+
181
+ **Current boundaries:** one process / one in-memory shared scene, no persistence across restart; no realtime editing link to the full WebGL editor; no multi-user permission or concurrent edit locks; no agent background execution, no pause/resume coordinator; the HTTP MCP endpoint is a local prototype and is not authenticated. Only bind to 127.0.0.1. A host ChatGPT UI may not support embedding this external live viewer. No npm publish is implied by a Git commit.
182
+
183
+ Architecture and collaboration invariants live in `AGENTS.md`.