topotopo 0.4.0 → 0.5.1

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 (336) hide show
  1. package/NOTICE +10 -10
  2. package/README.md +460 -117
  3. package/dist/cli.js +327 -147
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/bake.d.ts +14 -3
  7. package/dist/core/bake.js +153 -4
  8. package/dist/core/bevel.d.ts +3 -1
  9. package/dist/core/bevel.js +76 -3
  10. package/dist/core/decimate.d.ts +65 -0
  11. package/dist/core/decimate.js +409 -3
  12. package/dist/core/erosion.d.ts +37 -0
  13. package/dist/core/erosion.js +41 -1
  14. package/dist/core/geometry.d.ts +5 -1
  15. package/dist/core/geometry.js +203 -3
  16. package/dist/core/heightfield.d.ts +27 -4
  17. package/dist/core/heightfield.js +54 -16
  18. package/dist/core/intrinsics.d.ts +7 -0
  19. package/dist/core/intrinsics.js +94 -0
  20. package/dist/core/manifold.d.ts +12 -1
  21. package/dist/core/manifold.js +78 -6
  22. package/dist/core/materials.d.ts +7 -0
  23. package/dist/core/materials.js +45 -0
  24. package/dist/core/noise.d.ts +9 -0
  25. package/dist/core/noise.js +10 -1
  26. package/dist/core/polymerge.d.ts +21 -0
  27. package/dist/core/polymerge.js +327 -0
  28. package/dist/core/repair.d.ts +2 -0
  29. package/dist/core/repair.js +2 -0
  30. package/dist/core/report.d.ts +70 -0
  31. package/dist/core/report.js +275 -0
  32. package/dist/core/scene.js +2 -1
  33. package/dist/core/sha256.d.ts +4 -0
  34. package/dist/core/sha256.js +69 -0
  35. package/dist/core/shapes.d.ts +3 -0
  36. package/dist/core/shapes.js +34 -0
  37. package/dist/core/snippet-lib.d.ts +14 -1
  38. package/dist/core/snippet-lib.js +39 -13
  39. package/dist/core/tangents.d.ts +2 -0
  40. package/dist/core/tangents.js +5 -1
  41. package/dist/core/texnoise.d.ts +6 -1
  42. package/dist/core/texnoise.js +6 -2
  43. package/dist/core/texsdf.d.ts +131 -0
  44. package/dist/core/texsdf.js +637 -0
  45. package/dist/core/texture.d.ts +163 -9
  46. package/dist/core/texture.js +844 -20
  47. package/dist/core/topology.d.ts +10 -0
  48. package/dist/core/topology.js +168 -0
  49. package/dist/core/unwrap.d.ts +72 -0
  50. package/dist/core/unwrap.js +800 -0
  51. package/dist/core/usercode.d.ts +27 -0
  52. package/dist/core/usercode.js +87 -0
  53. package/dist/core/uv.d.ts +4 -18
  54. package/dist/core/uv.js +35 -188
  55. package/dist/core/uvislands.d.ts +62 -0
  56. package/dist/core/uvislands.js +574 -0
  57. package/dist/core/uvoverlap.d.ts +58 -0
  58. package/dist/core/uvoverlap.js +220 -0
  59. package/dist/core/uvpack.d.ts +64 -0
  60. package/dist/core/uvpack.js +628 -0
  61. package/dist/core/uvreport.d.ts +61 -0
  62. package/dist/core/uvreport.js +207 -143
  63. package/dist/core/wrangle.d.ts +6 -1
  64. package/dist/core/wrangle.js +27 -16
  65. package/dist/core/xatlas.d.ts +16 -1
  66. package/dist/core/xatlas.js +66 -62
  67. package/dist/engines.d.ts +63 -0
  68. package/dist/engines.js +180 -0
  69. package/dist/explain.d.ts +4 -3
  70. package/dist/explain.js +129 -12
  71. package/dist/graph/engine.d.ts +92 -29
  72. package/dist/graph/engine.js +298 -148
  73. package/dist/graph/expr.d.ts +6 -3
  74. package/dist/graph/expr.js +18 -8
  75. package/dist/graph/outputs.d.ts +23 -0
  76. package/dist/graph/outputs.js +41 -0
  77. package/dist/graph/packages.d.ts +72 -0
  78. package/dist/graph/packages.js +261 -0
  79. package/dist/graph/parallel.d.ts +3 -1
  80. package/dist/graph/parallel.js +4 -1
  81. package/dist/graph/params.d.ts +6 -0
  82. package/dist/graph/params.js +34 -7
  83. package/dist/graph/scope.d.ts +55 -0
  84. package/dist/graph/scope.js +14 -0
  85. package/dist/graph/types.d.ts +75 -12
  86. package/dist/graph/types.js +4 -2
  87. package/dist/graph/vars.d.ts +16 -0
  88. package/dist/graph/vars.js +80 -0
  89. package/dist/host/artifacts.d.ts +10 -1
  90. package/dist/host/artifacts.js +37 -6
  91. package/dist/host/cook.d.ts +241 -0
  92. package/dist/host/cook.js +844 -0
  93. package/dist/host/export-targets.d.ts +42 -5
  94. package/dist/host/export-targets.js +72 -13
  95. package/dist/host/godot-commands.d.ts +4 -0
  96. package/dist/host/godot-commands.js +21 -0
  97. package/dist/host/godot.d.ts +183 -0
  98. package/dist/host/godot.js +916 -0
  99. package/dist/host/node.d.ts +12 -7
  100. package/dist/host/node.js +27 -9
  101. package/dist/host/pool.js +51 -2
  102. package/dist/host/sidecars.d.ts +8 -0
  103. package/dist/host/sidecars.js +50 -0
  104. package/dist/host/types.d.ts +19 -6
  105. package/dist/host/version.d.ts +1 -0
  106. package/dist/host/version.js +3 -0
  107. package/dist/host/worker.js +5 -2
  108. package/dist/index.d.ts +2 -2
  109. package/dist/index.js +1 -1
  110. package/dist/inspect.d.ts +80 -2
  111. package/dist/inspect.js +265 -30
  112. package/dist/io/common.d.ts +25 -5
  113. package/dist/io/export.js +2 -1
  114. package/dist/io/files.d.ts +23 -4
  115. package/dist/io/files.js +60 -8
  116. package/dist/io/gltf.js +134 -47
  117. package/dist/io/heightmap.d.ts +3 -0
  118. package/dist/io/heightmap.js +1 -0
  119. package/dist/io/import.js +10 -0
  120. package/dist/io/inspect-scene.d.ts +55 -0
  121. package/dist/io/inspect-scene.js +155 -0
  122. package/dist/io/kinds.d.ts +81 -0
  123. package/dist/io/kinds.js +163 -0
  124. package/dist/io/points.d.ts +2 -1
  125. package/dist/io/points.js +3 -1
  126. package/dist/io/sidecars.d.ts +24 -0
  127. package/dist/io/sidecars.js +57 -0
  128. package/dist/io/source.d.ts +65 -0
  129. package/dist/io/source.js +112 -0
  130. package/dist/io/targets.d.ts +47 -3
  131. package/dist/io/targets.js +148 -13
  132. package/dist/io/textures.js +21 -1
  133. package/dist/io/unreal.js +5 -1
  134. package/dist/mcp/docs.d.ts +10 -1
  135. package/dist/mcp/docs.js +786 -143
  136. package/dist/mcp/inputs.d.ts +12 -5
  137. package/dist/mcp/inputs.js +50 -13
  138. package/dist/mcp/server.js +56 -27
  139. package/dist/mcp/tools.d.ts +14 -7
  140. package/dist/mcp/tools.js +198 -103
  141. package/dist/mcp/verify.d.ts +2 -2
  142. package/dist/mcp/verify.js +1 -1
  143. package/dist/mcp/workspace.d.ts +15 -0
  144. package/dist/mcp/workspace.js +349 -0
  145. package/dist/nodes/attributes.js +198 -1
  146. package/dist/nodes/bake.js +151 -47
  147. package/dist/nodes/beam.d.ts +1 -0
  148. package/dist/nodes/beam.js +201 -0
  149. package/dist/nodes/bevel.js +51 -3
  150. package/dist/nodes/cloth.js +2 -0
  151. package/dist/nodes/code.js +21 -9
  152. package/dist/nodes/curves.js +433 -93
  153. package/dist/nodes/flow.js +53 -33
  154. package/dist/nodes/generate.js +12 -38
  155. package/dist/nodes/heightfield.js +248 -77
  156. package/dist/nodes/imageops.js +16 -19
  157. package/dist/nodes/index.d.ts +1 -0
  158. package/dist/nodes/index.js +1 -0
  159. package/dist/nodes/material.js +89 -24
  160. package/dist/nodes/measure.js +43 -17
  161. package/dist/nodes/particles.js +2 -0
  162. package/dist/nodes/pcg.js +6 -5
  163. package/dist/nodes/procedural.js +4 -3
  164. package/dist/nodes/remesh.js +71 -15
  165. package/dist/nodes/scene.js +4 -2
  166. package/dist/nodes/sdf.js +10 -5
  167. package/dist/nodes/solid.js +20 -5
  168. package/dist/nodes/splines.d.ts +15 -1
  169. package/dist/nodes/splines.js +112 -105
  170. package/dist/nodes/texture.d.ts +21 -6
  171. package/dist/nodes/texture.js +1318 -185
  172. package/dist/nodes/topology.d.ts +7 -0
  173. package/dist/nodes/topology.js +133 -6
  174. package/dist/nodes/transform.js +6 -2
  175. package/dist/nodes/uv.js +192 -174
  176. package/dist/nodes/wasmcall.js +5 -1
  177. package/dist/open.d.ts +19 -0
  178. package/dist/open.js +12 -0
  179. package/dist/package.d.ts +288 -0
  180. package/dist/package.js +772 -0
  181. package/dist/packages/check.d.ts +32 -0
  182. package/dist/packages/check.js +169 -0
  183. package/dist/packages/commands.d.ts +57 -0
  184. package/dist/packages/commands.js +537 -0
  185. package/dist/packages/registry.d.ts +796 -0
  186. package/dist/packages/registry.js +2998 -0
  187. package/dist/packages/update.d.ts +124 -0
  188. package/dist/packages/update.js +476 -0
  189. package/dist/render/options.d.ts +2 -0
  190. package/dist/render/options.js +57 -5
  191. package/dist/render/preview.d.ts +17 -4
  192. package/dist/render/preview.js +6 -4
  193. package/dist/render/raster.d.ts +74 -5
  194. package/dist/render/raster.js +527 -143
  195. package/dist/render/texview.d.ts +6 -0
  196. package/dist/render/texview.js +27 -0
  197. package/dist/scan.d.ts +61 -0
  198. package/dist/scan.js +228 -0
  199. package/dist/session.d.ts +311 -0
  200. package/dist/session.js +849 -0
  201. package/dist/viewer/app/api.js +48 -6
  202. package/dist/viewer/app/cooking.js +78 -0
  203. package/dist/viewer/app/embed.js +27 -7
  204. package/dist/viewer/app/export-popover.js +118 -16
  205. package/dist/viewer/app/grid.js +5 -1
  206. package/dist/viewer/app/guides.js +122 -0
  207. package/dist/viewer/app/keymap.js +6 -3
  208. package/dist/viewer/app/layers.js +4 -4
  209. package/dist/viewer/app/main.js +185 -52
  210. package/dist/viewer/app/markers.js +60 -0
  211. package/dist/viewer/app/outliner.js +72 -27
  212. package/dist/viewer/app/output-info.js +45 -0
  213. package/dist/viewer/app/outputs.css +147 -8
  214. package/dist/viewer/app/outputs.js +168 -54
  215. package/dist/viewer/app/packages.js +614 -0
  216. package/dist/viewer/app/props.js +176 -52
  217. package/dist/viewer/app/scene.js +30 -5
  218. package/dist/viewer/app/select.js +4 -3
  219. package/dist/viewer/app/status.js +12 -15
  220. package/dist/viewer/app/style.css +65 -7
  221. package/dist/viewer/app/vars.js +47 -0
  222. package/dist/viewer/app/welcome.js +72 -0
  223. package/dist/viewer/graph-file.d.ts +62 -0
  224. package/dist/viewer/graph-file.js +175 -0
  225. package/dist/viewer/index.html +23 -10
  226. package/dist/viewer/json-edit.d.ts +13 -0
  227. package/dist/viewer/json-edit.js +274 -0
  228. package/dist/viewer/outputs.d.ts +49 -5
  229. package/dist/viewer/outputs.js +264 -56
  230. package/dist/viewer/packages.d.ts +121 -0
  231. package/dist/viewer/packages.js +584 -0
  232. package/dist/viewer/server.d.ts +14 -9
  233. package/dist/viewer/server.js +266 -28
  234. package/dist/web/app/web.css +419 -0
  235. package/dist/web/app/web.js +188 -0
  236. package/dist/{gallery → web}/bake.d.ts +4 -4
  237. package/dist/{gallery → web}/bake.js +24 -15
  238. package/dist/web/folder-page.d.ts +101 -0
  239. package/dist/web/folder-page.js +146 -0
  240. package/dist/web/folders.d.ts +280 -0
  241. package/dist/web/folders.js +970 -0
  242. package/dist/web/library.d.ts +91 -0
  243. package/dist/web/library.js +228 -0
  244. package/dist/web/markdown.d.ts +45 -0
  245. package/dist/web/markdown.js +677 -0
  246. package/dist/web/pages.d.ts +258 -0
  247. package/dist/web/pages.js +301 -0
  248. package/dist/web/server.d.ts +24 -0
  249. package/dist/web/server.js +1068 -0
  250. package/dist/workspace.d.ts +88 -118
  251. package/dist/workspace.js +358 -460
  252. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  253. package/integrations/godot/addons/topotopo/README.md +57 -0
  254. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  255. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  256. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  257. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  258. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  259. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  260. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  261. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  262. package/integrations/godot/addons/topotopo/package.gd +23 -0
  263. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  264. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  265. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  266. package/integrations/godot/addons/topotopo/record.gd +435 -0
  267. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  268. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  269. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  270. package/kernels/pkg/README.md +2 -1
  271. package/kernels/pkg-simd/README.md +2 -1
  272. package/library/architecture/versions/1.0/architecture.topo +12 -0
  273. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  274. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  275. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  276. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  277. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  278. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  279. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  280. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  281. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  282. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  283. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  284. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  285. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  286. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  287. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  288. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  289. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  290. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  291. package/library/architecture/versions/1.0/version.json +1119 -0
  292. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  293. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  294. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  295. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  296. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  297. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  298. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  299. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  300. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  301. package/library/nature/versions/1.0/nature.topo +12 -0
  302. package/library/nature/versions/1.0/version.json +534 -0
  303. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  304. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  305. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  306. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  307. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  308. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  309. package/library/props/versions/1.0/props.topo +12 -0
  310. package/library/props/versions/1.0/version.json +336 -0
  311. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  312. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  313. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  314. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  315. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  316. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  317. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  318. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  319. package/library/street/versions/1.0/street.topo +12 -0
  320. package/library/street/versions/1.0/version.json +421 -0
  321. package/package.json +13 -8
  322. package/dist/gallery/app/gallery.css +0 -100
  323. package/dist/gallery/app/gallery.js +0 -80
  324. package/dist/gallery/cli.d.ts +0 -4
  325. package/dist/gallery/cli.js +0 -157
  326. package/dist/gallery/library.d.ts +0 -124
  327. package/dist/gallery/library.js +0 -366
  328. package/dist/gallery/pages.d.ts +0 -94
  329. package/dist/gallery/pages.js +0 -148
  330. package/dist/gallery/server.d.ts +0 -21
  331. package/dist/gallery/server.js +0 -391
  332. package/dist/graph/migrate.d.ts +0 -23
  333. package/dist/graph/migrate.js +0 -58
  334. package/dist/mcp/library.d.ts +0 -12
  335. package/dist/mcp/library.js +0 -159
  336. package/shelf/index.json +0 -190
@@ -2,22 +2,26 @@
2
2
  // the status bar and the server's event stream. The camera moves only when the person moves it or frames: loading,
3
3
  // cooking, saving and placing never frame (the one exception is the very first view, when nothing is remembered).
4
4
  import * as THREE from 'three';
5
- import { api } from './api.js';
5
+ import { api, coalesce } from './api.js';
6
6
  import { createViews, CAMERA_NAMES, SHADINGS } from './camera.js';
7
7
  import { createGrid, createOverlays, cursorText } from './grid.js';
8
- import { MeshObject, parseGLB, createLights, LINE_MATERIALS } from './scene.js';
8
+ import { MeshObject, parseGLB, createLights, LINE_MATERIALS, recede } from './scene.js';
9
9
  import { createLayers } from './layers.js';
10
- import { createGuides, PLACE_KINDS } from './guides.js';
10
+ import { createGuides, PLACE_KINDS, guideId } from './guides.js';
11
11
  import { createSelect } from './select.js';
12
12
  import { createOutliner } from './outliner.js';
13
13
  import { createProps } from './props.js';
14
14
  import { createOutputPanel } from './outputs.js';
15
+ import { createPackagesPanel } from './packages.js';
15
16
  import { createSelection, parseId } from './selection.js';
16
17
  import { createUndo } from './undo.js';
17
18
  import { EDITOR_NAMES } from './markers.js';
18
19
  import * as KM from './keymap.js';
19
20
  import { fmtStep, fmtSize, fmtNum } from './units.js';
20
- import { connectedLine, graphsLine } from './status.js';
21
+ import { DISCONNECTED_LINE, RECONNECTED_LINE, messageLife } from './status.js';
22
+ import { compareLine, cookLine, isRunning } from './cooking.js';
23
+ import { pageTitle, defaultGraph, renderWelcome } from './welcome.js';
24
+ import { kindLine } from './output-info.js';
21
25
 
22
26
  const $ = (id) => document.getElementById(id);
23
27
  const BG = new THREE.Color('#2b2d31');
@@ -38,32 +42,71 @@ const ctx = {
38
42
  on(type, f) { if (!listeners.has(type)) listeners.set(type, new Set()); listeners.get(type).add(f); },
39
43
  emit(type) { if (type !== 'hover') version++; for (const f of listeners.get(type) ?? []) f(); for (const f of listeners.get('*') ?? []) f(type); },
40
44
  version: () => version,
41
- /** At most one run of fn at a time; calls during a run ask for one more run after it, and wait for that. */
42
- coalesce(fn) {
43
- let busy = null, again = false;
44
- return () => {
45
- if (busy) { again = true; return busy; }
46
- busy = (async () => { try { do { again = false; await fn(); } while (again); } finally { busy = null; } })();
47
- return busy;
48
- };
49
- },
45
+ coalesce,
50
46
  };
51
47
 
52
- // ------------------------------------------------------------------------------------------- status bar
53
- const msgEl = $('msg');
54
- let heldUntil = 0;
55
- /** A line in the status bar; `hold` ms keeps it over routine lines (an undo over the save that follows it). */
48
+ // ------------------------------------------------------------------------------------------- messages
49
+ // What something the person did came to, over the view's lower left; it clears itself (status.js messageLife). The
50
+ // status bar keeps the cook line and what is shown.
51
+ const notesEl = $('notes'), msgEl = $('msg');
52
+ let heldUntil = 0, noteTimer = 0;
53
+ /** A message; `hold` ms keeps it over routine ones (an undo over the save that follows it); '' clears it. */
56
54
  ctx.message = (text, kind = '', hold = 0) => {
57
55
  const now = performance.now();
58
- if (!hold && kind !== 'err' && now < heldUntil) return;
56
+ if (text && !hold && kind !== 'err' && now < heldUntil) return;
59
57
  heldUntil = hold ? now + hold : 0;
60
- msgEl.textContent = text; msgEl.className = kind; msgEl.title = text;
58
+ clearTimeout(noteTimer);
59
+ msgEl.textContent = text; msgEl.title = text; notesEl.className = kind;
60
+ notesEl.hidden = !text && $('ask').hidden;
61
+ const life = messageLife(text, kind, hold);
62
+ if (text && Number.isFinite(life)) noteTimer = setTimeout(() => { if (!notesEl.matches(':hover')) ctx.message(''); else noteTimer = setTimeout(() => ctx.message(''), 3000); }, life);
63
+ };
64
+ $('msg-close').onclick = () => { $('msg-close').blur(); ctx.message(''); };
65
+ // ------------------------------------------------------------------------------------------- cook state
66
+ // What is cooking for each graph (the server's {cook} events, and /api/graphs), shown in the status bar and above the
67
+ // Controls: the node, the time (counted on here between events), how the last cook ended. Stop stops it. While the
68
+ // before/after of a package update runs (packages.js), the lines show its progress and Stop stops it.
69
+ const cooks = new Map(), cookLines = [$('status-cook'), $('controls-cook')];
70
+ let cookTick = 0;
71
+ ctx.cookState = (graph) => cooks.get(graph)?.state ?? null;
72
+ function setCook(graph, state) { cooks.set(graph, { state, at: performance.now() }); renderCook(); }
73
+ function renderCook() {
74
+ const c = cooks.get(ctx.graph?.name), compare = ctx.packages?.running;
75
+ const line = compare ? compareLine(compare, performance.now() - compare.at) : cookLine(c?.state, c ? performance.now() - c.at : 0);
76
+ for (const el of cookLines) {
77
+ el.className = `cookline ${line.kind}`;
78
+ const t = el.querySelector('.ctext');
79
+ if (t.textContent !== line.text) t.textContent = line.text;
80
+ el.title = line.title;
81
+ }
82
+ $('props').classList.toggle('cooking', line.kind === 'running' || line.kind === 'stopping');
83
+ ctx.packages?.renderLine();
84
+ const running = isRunning(c?.state) || !!compare;
85
+ if (running && !cookTick) cookTick = setInterval(renderCook, 200);
86
+ else if (!running && cookTick) { clearInterval(cookTick); cookTick = 0; }
87
+ }
88
+ ctx.renderCook = renderCook;
89
+ // one Stop, in the status bar
90
+ $('status-cook').querySelector('.cstop').onclick = async (e) => {
91
+ e.currentTarget.blur();
92
+ // the cooks of an update's comparison are not the graph's: they stop on their own
93
+ if (ctx.packages?.running) { ctx.packages.stop(); return; }
94
+ const graph = ctx.graph.name;
95
+ if (!graph) return;
96
+ // at once: the server hears the stop only when the node it is on lets it (see the line's title)
97
+ const c = cooks.get(graph);
98
+ if (c?.state?.running) { c.state = { ...c.state, running: { ...c.state.running, stopping: true } }; renderCook(); }
99
+ const j = await api.stop(graph);
100
+ if (!j.ok) ctx.message(j.error, 'err');
101
+ else ctx.message(j.stopping ? 'stopping: the cook ends when the node it is on has finished' : 'nothing is cooking');
61
102
  };
62
- /** A small question in the status bar; resolves to the answer. */
103
+
104
+ /** A small question with the messages; resolves to the answer. */
63
105
  ctx.ask = (text, yes = 'Yes', no = 'No') => new Promise((resolve) => {
106
+ ctx.message('');
64
107
  $('ask-text').textContent = text; $('ask-yes').textContent = yes; $('ask-no').textContent = no;
65
- $('ask').hidden = false;
66
- const done = (v) => { $('ask').hidden = true; $('ask-yes').onclick = $('ask-no').onclick = null; resolve(v); };
108
+ $('ask').hidden = false; notesEl.hidden = false;
109
+ const done = (v) => { $('ask').hidden = true; notesEl.hidden = !msgEl.textContent; $('ask-yes').onclick = $('ask-no').onclick = null; resolve(v); };
67
110
  $('ask-yes').onclick = () => done(true);
68
111
  $('ask-no').onclick = () => done(false);
69
112
  $('ask-yes').focus();
@@ -137,12 +180,17 @@ ctx.select = createSelect(ctx);
137
180
  ctx.surfacePoint = ctx.select.surfacePoint;
138
181
  ctx.planePoint = ctx.select.planePoint;
139
182
  const outliner = createOutliner(ctx, { scene: $('tree'), inputs: $('inputs-list') });
183
+ ctx.setTabShown = outliner.setTabShown;
184
+ ctx.showTab = (name) => outliner.showTab(name);
140
185
  const props = createProps(ctx);
141
186
 
142
187
  // ------------------------------------------------------------------------------------------- graphs and the output
143
188
  ctx.graph = {
144
- list: [], name: null, node: null,
189
+ /** the graphs as last read (/api/graphs), and when that read was asked for: values the page sent later stand */
190
+ list: [], fetched: -1e9, name: null, node: null,
145
191
  current() { return this.list.find((g) => g.name === this.name) ?? null; },
192
+ /** the Controls for the graph shown, from the list as last read (never as if it had just been read) */
193
+ renderControls() { props.controls.render(this.current(), this.fetched); },
146
194
  /** the node whose result is shown: the chosen one, else the graph's output */
147
195
  shownNode() { const g = this.current(); return this.node ?? g?.output ?? null; },
148
196
  show(node) {
@@ -158,29 +206,49 @@ const refreshGraphs = ctx.coalesce(async () => {
158
206
  const list = await api.graphs();
159
207
  if (!list) return;
160
208
  const G = ctx.graph;
161
- G.list = list;
209
+ G.list = list; G.fetched = issued;
162
210
  const names = list.map((g) => g.name);
163
211
  const sel = $('graph');
164
212
  // the options are rebuilt only when the graphs change, so an open list stays open
165
213
  if (names.join('\n') !== [...sel.options].map((o) => o.value).join('\n')) sel.replaceChildren(...names.map((n) => new Option(n, n)));
166
- if (!names.includes(G.name)) { G.name = local.get('graph', null); if (!names.includes(G.name)) G.name = names[0] ?? null; G.node = null; }
214
+ if (!names.includes(G.name)) { G.name = local.get('graph', null); if (!names.includes(G.name)) G.name = defaultGraph(ctx.package, names); G.node = null; }
167
215
  sel.value = G.name ?? '';
168
216
  const g = G.current();
169
217
  if (G.node && !g?.nodes.some((n) => n.name === G.node)) G.node = null;
218
+ // the cook states the list carries, unless an event brought a newer one while it was fetched
219
+ for (const x of list) if (x.cook && !((cooks.get(x.name)?.at ?? -1) > issued)) cooks.set(x.name, { state: x.cook, at: performance.now() });
220
+ renderCook();
170
221
  props.controls.render(g, issued);
171
- const line = graphsLine(msgEl.textContent, list.length);
172
- if (line) ctx.message(line);
222
+ renderWelcome($('welcome'), ctx.package, !list.length);
173
223
  ctx.emit('graphs');
174
224
  });
225
+ // the package shown: the tab's title, the graph shown first, the welcome while there is no graph
226
+ ctx.package = null;
227
+ const refreshPackage = async () => {
228
+ const info = await api.package();
229
+ if (!info) return;
230
+ ctx.package = info;
231
+ document.title = pageTitle(info);
232
+ renderWelcome($('welcome'), info, !ctx.graph.list.length);
233
+ };
175
234
  $('graph').onchange = (e) => {
176
235
  if (ctx.outputs?.active) ctx.outputs.scene();
177
236
  ctx.graph.name = e.target.value; ctx.graph.node = null;
178
237
  local.set('graph', ctx.graph.name);
179
- props.controls.render(ctx.graph.current());
238
+ ctx.graph.renderControls();
239
+ renderCook();
180
240
  ctx.emit('graphs');
181
241
  loadGeo();
182
242
  };
183
243
 
244
+ // the heightfield layer the scene's output shows in red (the picker in Properties), per graph and node
245
+ const sceneLayers = local.get('scene.layers', {});
246
+ const sceneKey = () => `${ctx.graph.name}/${ctx.graph.shownNode() ?? ''}`;
247
+ ctx.sceneLayer = {
248
+ get: () => sceneLayers[sceneKey()] ?? null,
249
+ set(v) { sceneLayers[sceneKey()] = v; local.set('scene.layers', sceneLayers); loadGeo(); },
250
+ };
251
+
184
252
  let firstFrame = !views.placed;
185
253
  const loadGeo = ctx.coalesce(async () => {
186
254
  if (ctx.outputs?.active) { await ctx.outputs.refresh(); return; }
@@ -188,12 +256,12 @@ const loadGeo = ctx.coalesce(async () => {
188
256
  if (!G.name) return;
189
257
  const graph = G.name, node = G.node ?? '';
190
258
  o.loading = true; ctx.emit('output');
191
- const r = await api.geo(graph, node);
259
+ const r = await api.geo(graph, node, ctx.sceneLayer.get());
192
260
  o.loading = false;
193
- if (graph !== G.name || node !== (G.node ?? '') || ctx.outputs?.active) return;
261
+ if (graph !== G.name || node !== (G.node ?? '') || ctx.outputs?.active) { ctx.emit('output'); return; }
194
262
  if (!r.ok) {
195
- // the last good geometry stays
196
- o.error = r.error;
263
+ // the last good geometry stays; a stopped cook is no error (the cook line says where it stopped)
264
+ if (!r.stopped) o.error = r.error;
197
265
  ctx.emit('output'); updateCook();
198
266
  return;
199
267
  }
@@ -216,21 +284,27 @@ const loadGeo = ctx.coalesce(async () => {
216
284
  const [info, report] = await Promise.all([api.info(graph, node), api.report(graph)]);
217
285
  if (graph !== G.name) return;
218
286
  o.summary = info?.summary ?? '';
287
+ o.about = info?.about ?? null;
219
288
  o.report = report;
220
289
  ctx.emit('output'); updateCook();
221
290
  });
222
291
 
292
+ /** The status bar's right side: what the view shows, its kind and size (a terrain says its samples, not "0 points"). */
223
293
  function updateCook() {
224
- const el = $('cook'), o = ctx.output, g = ctx.graph.current();
225
- if (ctx.outputs?.active?.kind === 'image') {
226
- const image = ctx.outputs.active; el.textContent = image.width ? `${image.width} × ${image.height} · ${image.layers?.length ?? 1} layer(s)` : image.label; return;
294
+ const el = $('cook'), o = ctx.output, g = ctx.graph.current(), shown = ctx.outputs?.active;
295
+ if (shown) {
296
+ // an output alone in the view (or a place of an update): its name and what it is
297
+ const what = shown.view === 'image' && shown.width ? `${shown.width} × ${shown.height} px · ${shown.layers?.length ?? 1} layer${(shown.layers?.length ?? 1) === 1 ? '' : 's'}` : kindLine(shown);
298
+ el.textContent = [shown.graph && shown.graph !== shown.label ? `${shown.graph} › ${shown.label}` : shown.label, what].filter(Boolean).join(' · ');
299
+ el.title = el.textContent;
300
+ return;
227
301
  }
228
302
  if (!g) { el.textContent = ''; return; }
229
- const m = /geometry: ([\d,]+) points, ([\d,]+) prims/.exec(o.summary ?? '');
230
303
  const parts = [`${g.name}/${ctx.graph.shownNode() ?? ''}`];
231
- if (m) parts.push(`${m[1]} points`, `${m[2]} prims`);
232
- if (o.report?.cooked) parts.push(`cook ${fmtNum(o.report.ms, 0)} ms`);
233
- const err = o.error ?? (o.report?.errors?.length ? o.report.errors[0] : null) ?? g.nodes.find((n) => n.error)?.error;
304
+ if (o.about) parts.push(kindLine({ kind: o.about.published ?? 'empty', about: o.about.text }));
305
+ // a failed cook of the graph is told by the cook line beside this (its node and message); this tells the rest
306
+ const told = cookLine(ctx.cookState(g.name)).kind === 'failed';
307
+ const err = o.error ?? (told ? null : (o.report?.errors?.length ? o.report.errors[0] : null) ?? g.nodes.find((n) => n.error)?.error);
234
308
  el.replaceChildren(document.createTextNode(parts.join(' · ')));
235
309
  if (err) { const e = document.createElement('span'); e.className = 'err'; e.textContent = ` · ${String(err).split('\n')[0]}`; el.append(e); el.title = String(err); }
236
310
  else el.title = parts.join(' · ');
@@ -358,6 +432,16 @@ $('view-cam').onchange = (e) => { views.setCam(views.active, e.target.value); sa
358
432
  $('view-shading').replaceChildren(...SHADINGS.map(([v, t]) => new Option(t, v)));
359
433
  $('view-shading').onchange = (e) => { views.slots[views.active].shading = e.target.value; saveViews(); e.target.blur(); ctx.requestRender(); };
360
434
  $('quad').onclick = () => { toggleQuad(); $('quad').blur(); };
435
+ // the edge check: an overlay, off until the person turns it on (remembered in this browser)
436
+ MeshObject.edgeCheck = browser.get('edgeCheck', false);
437
+ const syncEdgeCheck = () => { $('edge-check').classList.toggle('on', MeshObject.edgeCheck); $('edge-check').setAttribute('aria-pressed', String(MeshObject.edgeCheck)); };
438
+ $('edge-check').onclick = () => {
439
+ $('edge-check').blur();
440
+ MeshObject.edgeCheck = !MeshObject.edgeCheck; browser.set('edgeCheck', MeshObject.edgeCheck); syncEdgeCheck();
441
+ for (const e of ctx.objects.values()) if (e.mesh) e.mesh.mode = null;
442
+ ctx.emit('output'); ctx.requestRender();
443
+ };
444
+ syncEdgeCheck();
361
445
  $('help').onclick = () => { KM.toggleOverlay(document.body, preset); $('help').blur(); };
362
446
  function syncTop() {
363
447
  const s = views.slots[views.active];
@@ -367,7 +451,13 @@ function syncTop() {
367
451
  $('quad').textContent = views.quad ? 'single' : 'quad';
368
452
  const mode = ctx.guides.mode;
369
453
  $('mode').textContent = mode ? `placing ${EDITOR_NAMES[mode]}` : '';
454
+ for (const b of $('guide-tools').querySelectorAll('button')) b.classList.toggle('on', (PLACE_KINDS[b.dataset.tool] ?? null) === mode);
370
455
  }
456
+ for (const b of $('guide-tools').querySelectorAll('button')) b.addEventListener('click', () => {
457
+ // the tools work on the guides, which the scene shows (a result shown alone hides them)
458
+ if (b.dataset.tool === 'selectMode' && ctx.outputs?.active) ctx.outputs.scene();
459
+ run(b.dataset.tool); b.blur();
460
+ });
371
461
  function setActive(i) { if (i >= 0 && views.active !== i) { views.active = i; syncTop(); requestOverlays(); } }
372
462
  function toggleQuad(at = cursor.slot) {
373
463
  if (views.quad && at >= 0) views.active = at;
@@ -395,7 +485,7 @@ for (const g of document.querySelectorAll('.grip')) {
395
485
  const move = (ev) => {
396
486
  if (kind === 'left') layout.left = Math.round(Math.max(160, Math.min(innerWidth * 0.45, ev.clientX)));
397
487
  else if (kind === 'right') layout.right = Math.round(Math.max(220, Math.min(innerWidth * 0.5, innerWidth - ev.clientX)));
398
- else layout.split = Math.round(Math.max(10, Math.min(90, ((ev.clientY - props0.top - 26) / Math.max(1, props0.height - 52)) * 100)));
488
+ else layout.split = Math.round(Math.max(10, Math.min(85, ((ev.clientY - props0.top - 60) / Math.max(1, props0.height - 52)) * 100)));
399
489
  applyLayout(); ctx.requestRender();
400
490
  };
401
491
  const up = () => { g.classList.remove('drag'); g.removeEventListener('pointermove', move); g.removeEventListener('pointerup', up); browser.set('layout', layout); };
@@ -425,11 +515,15 @@ function run(action) {
425
515
  slot.shading = { displayWire: 'wire', displayShaded: 'shaded', displayShadedWire: 'shadedWire' }[action]; break;
426
516
  case 'displayCycle': slot.shading = DISPLAY_CYCLE[(DISPLAY_CYCLE.indexOf(slot.shading) + 1) % 3]; break;
427
517
  case 'wireToggle': slot.lastShading = slot.shading === 'wire' ? slot.lastShading : slot.shading; slot.shading = slot.shading === 'wire' ? slot.lastShading ?? 'shaded' : 'wire'; break;
428
- case 'placeNull': case 'placeCurve': case 'placeArea': case 'placeVolume': ctx.guides.setMode(PLACE_KINDS[action]); return syncTop();
518
+ case 'placeNull': case 'placeCurve': case 'placeArea': case 'placeVolume':
519
+ // guides are drawn in the scene, not over a result shown alone
520
+ if (ctx.outputs?.active) ctx.outputs.scene();
521
+ ctx.guides.setMode(PLACE_KINDS[action]); return syncTop();
429
522
  case 'finish': case 'removeLast': ctx.guides.key(action); return;
430
523
  case 'cancel': {
431
524
  if (document.querySelector('.keymap-overlay')) return KM.toggleOverlay(document.body, preset);
432
525
  if (ctx.select.press) return ctx.select.cancel();
526
+ if (drag?.kind === 'guide') { const d = drag; drag = null; ctx.guides.dragEnd(true); try { canvas.releasePointerCapture(d.id); } catch { /* gone */ } return; }
433
527
  if (ctx.guides.key('cancel')) return;
434
528
  ctx.guides.setMode(null); ctx.selection.clear(); return syncTop();
435
529
  }
@@ -516,8 +610,11 @@ canvas.addEventListener('pointerdown', (e) => {
516
610
  return;
517
611
  }
518
612
  if (e.button !== 0) return;
519
- if (ctx.guides.mode) { drag = { kind: 'place', slot, id: e.pointerId }; ctx.guides.pointerDown(slot, x, y); }
520
- else { drag = { kind: 'select', slot, id: e.pointerId }; ctx.select.down(slot, x, y, e); }
613
+ if (ctx.guides.mode) { drag = { kind: 'place', slot, id: e.pointerId }; ctx.guides.pointerDown(slot, x, y); return; }
614
+ // a plain press on a guide grabs it (Shift and Ctrl presses add to and take from the selection, as ever)
615
+ const h = !e.shiftKey && !e.ctrlKey && !e.metaKey && !e.altKey ? ctx.guides.handleAt(slot, x, y) : null;
616
+ if (h) { drag = { kind: 'guide', slot, x, y, id: e.pointerId, h }; ctx.guides.dragStart(slot, x, y, h); return; }
617
+ drag = { kind: 'select', slot, id: e.pointerId }; ctx.select.down(slot, x, y, e);
521
618
  });
522
619
  canvas.addEventListener('pointermove', (e) => {
523
620
  const { x, y } = at(e);
@@ -530,6 +627,7 @@ canvas.addEventListener('pointermove', (e) => {
530
627
  else views.dolly(drag.slot, Math.exp(-(dx - dy) * 0.006));
531
628
  ctx.requestRender();
532
629
  } else if (drag.kind === 'place') ctx.guides.pointerMove(drag.slot, x, y);
630
+ else if (drag.kind === 'guide') ctx.guides.dragMove(drag.slot, x, y);
533
631
  else ctx.select.move(x, y);
534
632
  return;
535
633
  }
@@ -538,7 +636,12 @@ canvas.addEventListener('pointermove', (e) => {
538
636
  cursor.slot = slot; cursor.x = x; cursor.y = y;
539
637
  if (slot >= 0 && views.cam(slot).ortho) requestOverlays();
540
638
  if (ctx.guides.mode) { if (slot >= 0) ctx.guides.pointerMove(slot, x, y); }
541
- else ctx.select.hover(slot, x, y);
639
+ else {
640
+ ctx.select.hover(slot, x, y);
641
+ // what a press would grab: a point (CV, null, corner) or a whole guide
642
+ const h = slot >= 0 ? ctx.guides.handleAt(slot, x, y) : null;
643
+ canvas.style.cursor = h ? (h.part === 'body' ? 'move' : 'crosshair') : '';
644
+ }
542
645
  });
543
646
  const endDrag = (e, cancel = false) => {
544
647
  if (!drag || e.pointerId !== drag.id) return;
@@ -548,8 +651,17 @@ const endDrag = (e, cancel = false) => {
548
651
  const { x, y } = at(e);
549
652
  if (d.kind === 'nav') saveViews();
550
653
  else if (d.kind === 'place') { if (!cancel) ctx.guides.pointerUp(d.slot, x, y); }
654
+ else if (d.kind === 'guide') {
655
+ // a press that did not move is a click: it selects the guide
656
+ if (!ctx.guides.dragEnd(cancel) && !cancel) ctx.selection.apply([guideId(d.h.id)]);
657
+ }
551
658
  else if (cancel) ctx.select.cancel(); else ctx.select.up(x, y);
552
659
  };
660
+ canvas.addEventListener('dblclick', (e) => {
661
+ if (ctx.guides.mode || drag) return;
662
+ const { x, y } = at(e), slot = views.slotAt(x, y);
663
+ if (slot >= 0) ctx.guides.doubleClick(slot, x, y);
664
+ });
553
665
  canvas.addEventListener('pointerup', (e) => endDrag(e));
554
666
  canvas.addEventListener('pointercancel', (e) => endDrag(e, true));
555
667
  canvas.addEventListener('lostpointercapture', (e) => endDrag(e, true));
@@ -591,15 +703,17 @@ ctx.hideModelPreview = () => { previewSerial++; ctx.previewEmpty = true; ctx.sel
591
703
  ctx.outputGraph = (item) => {
592
704
  if (item.graph && ctx.graph.list.some((g) => g.name === item.graph)) {
593
705
  ctx.graph.name = item.graph; ctx.graph.node = item.node; $('graph').value = item.graph;
594
- props.controls.render(ctx.graph.current());
706
+ ctx.graph.renderControls();
595
707
  }
596
708
  };
597
709
  ctx.previewOutput = async (item, bytes, update) => {
598
710
  const serial = ++previewSerial, src = await parseGLB(bytes);
599
711
  if (serial !== previewSerial || ctx.outputs.active?.id !== item.id) { new MeshObject('', src).dispose(); return; }
600
712
  const mesh = new MeshObject('out', src); mesh.onReady = () => ctx.requestRender();
713
+ // an update's overlay: the old version's polygons a sliver behind the new one's (no stripes where they meet)
714
+ if (item.overlay) src.traverse((o) => { for (const m of [o.material ?? []].flat()) if (m.name === 'overlay_a') recede(m); });
601
715
  ctx.output.mesh?.dispose(); ctx.output.mesh = mesh; ctx.outputRoot.add(mesh.root); ctx.previewEmpty = false;
602
- ctx.output.summary = item.summary ?? ''; ctx.output.error = item.error ?? null;
716
+ ctx.output.summary = item.summary ?? ''; ctx.output.error = item.error ?? null; ctx.output.about = null;
603
717
  ctx.outputGraph(item);
604
718
  outEntry(); ctx.selection.clear();
605
719
  if (!update || !outputViews.has(item.id)) {
@@ -610,23 +724,40 @@ ctx.previewOutput = async (item, bytes, update) => {
610
724
  }
611
725
  firstFrame = false; ctx.emit('output'); ctx.requestRender(); syncTop();
612
726
  };
613
- ctx.restoreScene = () => { previewSerial++; ctx.previewEmpty = false; if (sceneView) views.load(sceneView); else firstFrame = true; if (sceneGraph) { ctx.graph.name = sceneGraph.name; ctx.graph.node = sceneGraph.node; $('graph').value = ctx.graph.name; props.controls.render(ctx.graph.current()); } loadGeo(); ctx.requestRender(); };
727
+ ctx.restoreScene = () => { previewSerial++; ctx.previewEmpty = false; if (sceneView) views.load(sceneView); else firstFrame = true; if (sceneGraph) { ctx.graph.name = sceneGraph.name; ctx.graph.node = sceneGraph.node; $('graph').value = ctx.graph.name; ctx.graph.renderControls(); } loadGeo(); ctx.requestRender(); };
614
728
  ctx.frameOutput = frameAll;
729
+ /** Show a node of a graph (the Packages tab's "used by"): that graph, the node's result, the Scene tab. */
730
+ ctx.showNode = (graph, node) => {
731
+ if (!ctx.graph.list.some((g) => g.name === graph)) return;
732
+ if (ctx.outputs?.active) ctx.outputs.scene();
733
+ if (ctx.graph.name !== graph) { ctx.graph.name = graph; $('graph').value = graph; local.set('graph', graph); ctx.graph.renderControls(); renderCook(); }
734
+ ctx.graph.show(node);
735
+ ctx.showTab('scene');
736
+ };
615
737
  ctx.outputs = createOutputPanel(ctx);
738
+ ctx.packages = createPackagesPanel(ctx, $('packages'));
616
739
 
617
740
  const es = api.events({
618
741
  open() {
619
- ctx.message(connectedLine(ctx.graph.list.length));
620
742
  // after a reconnect the server may have restarted: fetch everything again
621
- if (es.opened) { refreshGraphs().then(loadGeo); ctx.outputs.refresh(); ctx.layers.refresh(); ctx.layers.loadWhere(); ctx.guides.load(); }
743
+ if (es.opened) {
744
+ if (msgEl.textContent === DISCONNECTED_LINE) ctx.message(RECONNECTED_LINE, 'ok');
745
+ refreshPackage().then(refreshGraphs).then(loadGeo); ctx.outputs.refresh(); ctx.packages.refresh(); ctx.layers.refresh(); ctx.layers.loadWhere(); ctx.guides.load();
746
+ }
622
747
  es.opened = true;
623
748
  },
624
- error() { ctx.message('disconnected (server stopped?)', 'err'); },
749
+ error() { ctx.message(DISCONNECTED_LINE, 'err'); },
625
750
  async message(ev) {
751
+ if (ev.cook !== undefined) { setCook(ev.cook.graph, ev.cook); if (ev.cook.graph === ctx.graph.name) updateCook(); return; }
626
752
  if (ev.outputs !== undefined) { ctx.outputs.refresh(); return; }
627
- if (ev.inputs !== undefined) { ctx.layers.refresh(); ctx.outputs.refresh(); return; }
753
+ // the scene's result too: a graph that reads inputs/ (the guides in markers.json) cooks again; one that does not
754
+ // answers from its cache
755
+ if (ev.inputs !== undefined) { ctx.layers.refresh(); ctx.outputs.refresh(); if (!ctx.isolated) loadGeo(); return; }
756
+ if (ev.compare !== undefined) { await ctx.packages.onCompare(ev.compare); renderCook(); return; }
757
+ if (ev.packages !== undefined) { ctx.packages.onEvent(ev); return; }
628
758
  await refreshGraphs();
629
- if (ev.graph === ctx.graph.name) loadGeo();
759
+ // after a stop the geometry in view stays: fetching it would cook what was just stopped
760
+ if (ev.graph === ctx.graph.name && !ev.stopped) loadGeo();
630
761
  ctx.outputs.refresh();
631
762
  },
632
763
  });
@@ -635,8 +766,10 @@ syncTop();
635
766
  outliner.render();
636
767
  props.render();
637
768
  ctx.requestRender();
769
+ await refreshPackage();
638
770
  await refreshGraphs();
639
771
  await ctx.outputs.refresh();
772
+ ctx.packages.refresh();
640
773
  loadGeo();
641
774
  ctx.layers.refresh();
642
775
  ctx.layers.loadWhere();
@@ -204,3 +204,63 @@ export function hatchSegments(pts, spacing) {
204
204
  }
205
205
  return out;
206
206
  }
207
+
208
+ // ------------------------------------------------------------------ direct edits (dragging in the view)
209
+ // Each takes a marker and returns a new one (the input is left alone), points kept to the millimetre; null when the
210
+ // edit would break the kind's rules (MARKER_POINTS, a volume's corners differing in x and z).
211
+ const mm3 = (p) => [mm(p[0]), mm(p[1]), mm(p[2])];
212
+ const withPoints = (m, points) => ({ ...m, points });
213
+
214
+ /** Point `k` (a null's point, a CV, a volume's ground corner as stored) moved to `p`. */
215
+ export function movePoint(m, k, p) {
216
+ if (!(k >= 0 && k < m.points.length)) return null;
217
+ const points = m.points.map((q, i) => (i === k ? mm3(p) : q.slice()));
218
+ if (m.kind === 'volume' && (points[0][0] === points[1][0] || points[0][2] === points[1][2])) return null;
219
+ return withPoints(m, points);
220
+ }
221
+
222
+ /** The whole guide moved by `d` [dx, dy, dz]. */
223
+ export const translateMarker = (m, d) => withPoints(m, m.points.map((p) => mm3([p[0] + d[0], p[1] + d[1], p[2] + d[2]])));
224
+
225
+ /**
226
+ * The segments of a curve or an area as pairs of point indices: a curve's k → k+1, an area's also its closing edge
227
+ * (last → 0). Nulls and volumes have none.
228
+ */
229
+ export function segmentsOf(m) {
230
+ if (m.kind !== 'path' && m.kind !== 'zone') return [];
231
+ const n = m.points.length, out = [];
232
+ for (let k = 0; k + 1 < n; k++) out.push([k, k + 1]);
233
+ if (m.kind === 'zone' && n >= 3) out.push([n - 1, 0]);
234
+ return out;
235
+ }
236
+
237
+ /** A new CV at `p` on segment `s` (segmentsOf's index): it lands between the segment's two ends. */
238
+ export function insertPoint(m, s, p) {
239
+ const seg = segmentsOf(m)[s];
240
+ if (!seg) return null;
241
+ const points = m.points.map((q) => q.slice());
242
+ // the closing edge of an area (last → 0) takes its new corner at the end
243
+ points.splice(seg[1] === 0 ? points.length : seg[1], 0, mm3(p));
244
+ return withPoints(m, points);
245
+ }
246
+
247
+ /** CV `k` removed; null when the guide would have fewer points than its kind needs (a curve 2, an area 3). */
248
+ export function removePoint(m, k) {
249
+ if (m.kind !== 'path' && m.kind !== 'zone') return null;
250
+ if (!(k >= 0 && k < m.points.length) || m.points.length - 1 < minPoints(m.kind)) return null;
251
+ return withPoints(m, m.points.filter((_, i) => i !== k).map((q) => q.slice()));
252
+ }
253
+
254
+ /** A volume's four ground corners [x, lo y, z], walked around the box: (lo x, lo z), (hi x, lo z), (hi x, hi z), (lo x, hi z). */
255
+ export function volumeCorners(m) {
256
+ const { lo, hi } = boxOf(m);
257
+ return [[lo[0], lo[1], lo[2]], [hi[0], lo[1], lo[2]], [hi[0], lo[1], hi[2]], [lo[0], lo[1], hi[2]]];
258
+ }
259
+
260
+ /** A volume with ground corner `k` (volumeCorners' order) dragged to `p` in x and z; the opposite corner stays. */
261
+ export function resizeVolume(m, k, p) {
262
+ const c = volumeCorners(m), fixed = c[(k + 2) % 4], y = c[0][1];
263
+ const a = mm3([fixed[0], y, fixed[2]]), b = mm3([p[0], y, p[2]]);
264
+ if (a[0] === b[0] || a[2] === b[2]) return null;
265
+ return withPoints(m, [a, b]);
266
+ }