@nebula-spatial/studio 0.0.0-stage → 0.1.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 (262) hide show
  1. package/README.md +206 -3
  2. package/dist/ai/contract.d.ts +73 -0
  3. package/dist/ai/host.d.ts +28 -0
  4. package/dist/asset/dependency-scan.d.ts +78 -0
  5. package/dist/asset/intake.d.ts +84 -0
  6. package/dist/asset/layout-detect.d.ts +40 -0
  7. package/dist/asset/media-type.d.ts +10 -0
  8. package/dist/asset/model-inspection.d.ts +127 -0
  9. package/dist/asset/record.d.ts +35 -0
  10. package/dist/asset/remote-asset-resolver.d.ts +36 -0
  11. package/dist/asset/repairs.d.ts +53 -0
  12. package/dist/asset/resource-locator.d.ts +15 -0
  13. package/dist/asset/revision-diff.d.ts +33 -0
  14. package/dist/asset/source-contracts.d.ts +21 -0
  15. package/dist/asset/source-paths.d.ts +15 -0
  16. package/dist/asset/usd-inspection.d.ts +39 -0
  17. package/dist/asset/usd-source-metadata.d.ts +142 -0
  18. package/dist/asset/visual-intake.d.ts +27 -0
  19. package/dist/asset/visual-record.d.ts +22 -0
  20. package/dist/asset/web-intake.d.ts +46 -0
  21. package/dist/asset-source-BExlEcRt.js +444 -0
  22. package/dist/assets/openusd_three_loader-DLiqJWUM.js +13769 -0
  23. package/dist/assets/usd-export-worker-BRxTLqer.js +182 -0
  24. package/dist/assets/usd-worker-DekqMsQv.js +1392 -0
  25. package/dist/builders-BAXRR5o5.js +1854 -0
  26. package/dist/core/asset-task.d.ts +105 -0
  27. package/dist/core/context.d.ts +23 -0
  28. package/dist/core/host.d.ts +432 -0
  29. package/dist/core/persistence-controller.d.ts +58 -0
  30. package/dist/core/plugins.d.ts +139 -0
  31. package/dist/core/scene-tree.d.ts +62 -0
  32. package/dist/core/versions.d.ts +2 -0
  33. package/dist/core/when.d.ts +13 -0
  34. package/dist/core/write-policy.d.ts +29 -0
  35. package/dist/delivery/build-plan.d.ts +2 -0
  36. package/dist/delivery/contracts.d.ts +362 -0
  37. package/dist/delivery/digest.d.ts +3 -0
  38. package/dist/delivery/evidence.d.ts +10 -0
  39. package/dist/delivery/export-evidence.d.ts +3 -0
  40. package/dist/delivery/index.d.ts +9 -0
  41. package/dist/delivery/prim-name.d.ts +17 -0
  42. package/dist/delivery/profile.d.ts +4 -0
  43. package/dist/doc/builders.d.ts +99 -0
  44. package/dist/doc/command.d.ts +195 -0
  45. package/dist/doc/domain-extensions.d.ts +34 -0
  46. package/dist/doc/node-facts.d.ts +87 -0
  47. package/dist/doc/physics-facts.d.ts +74 -0
  48. package/dist/doc/placement-policy.d.ts +71 -0
  49. package/dist/doc/random-placement.d.ts +30 -0
  50. package/dist/doc/scene-graph.d.ts +80 -0
  51. package/dist/doc/scene-regions.d.ts +29 -0
  52. package/dist/doc/schema.d.ts +452 -0
  53. package/dist/doc/task.d.ts +71 -0
  54. package/dist/doc/validate.d.ts +68 -0
  55. package/dist/editor/asset-source.d.ts +15 -0
  56. package/dist/editor/editor.d.ts +246 -0
  57. package/dist/editor/index.d.ts +22 -0
  58. package/dist/editor/shortcuts.d.ts +2 -0
  59. package/dist/editor/types.d.ts +143 -0
  60. package/dist/editor/ui-plugins.d.ts +64 -0
  61. package/dist/editor.js +1755 -0
  62. package/dist/editorial-BkAFWfbg.js +83 -0
  63. package/dist/export-evidence-DMNRhgL9.js +2705 -0
  64. package/dist/generalization/domain.d.ts +10 -0
  65. package/dist/generalization/generalization.d.ts +371 -0
  66. package/dist/generalization/index.d.ts +11 -0
  67. package/dist/generalization.js +1659 -0
  68. package/dist/history/undo-stack.d.ts +74 -0
  69. package/dist/index.d.ts +91 -0
  70. package/dist/index.js +2840 -0
  71. package/dist/mjcf-visual-Bt4bUxd1.js +72 -0
  72. package/dist/mujoco-runtime-BYZnrvbR.js +467 -0
  73. package/dist/persist/content-addressed.d.ts +11 -0
  74. package/dist/persist/create-scene-package-from-host.d.ts +7 -0
  75. package/dist/persist/indexeddb-store.d.ts +69 -0
  76. package/dist/persist/scene-file.d.ts +52 -0
  77. package/dist/persist/scene-package.d.ts +8 -0
  78. package/dist/persist/snapshot.d.ts +5 -0
  79. package/dist/physics-facts-tfQYyNTD.js +337 -0
  80. package/dist/placement-policy-DY_FNRDu.js +405 -0
  81. package/dist/ports/asset-ingestor.d.ts +41 -0
  82. package/dist/ports/asset-source.d.ts +57 -0
  83. package/dist/ports/delivery.d.ts +13 -0
  84. package/dist/ports/persistence.d.ts +29 -0
  85. package/dist/project/asset-catalog.d.ts +21 -0
  86. package/dist/project/contracts.d.ts +272 -0
  87. package/dist/project/editorial.d.ts +16 -0
  88. package/dist/project/identity.d.ts +20 -0
  89. package/dist/project/index.d.ts +9 -0
  90. package/dist/project/scene-document.d.ts +5 -0
  91. package/dist/project/source-dependencies.d.ts +7 -0
  92. package/dist/remote-asset-resolver-Cb8cfNmw.js +136 -0
  93. package/dist/scene/index.d.ts +12 -0
  94. package/dist/scene-graph-DBLKAhxa.js +681 -0
  95. package/dist/scene-session-Cy6vDJ1l.js +21981 -0
  96. package/dist/scene.js +244 -0
  97. package/dist/session-BRBrCLdd.js +963 -0
  98. package/dist/session-DI5tPJxn.js +825 -0
  99. package/dist/session-q3uuG7OP.js +296 -0
  100. package/dist/studio/delivery-catalog.d.ts +28 -0
  101. package/dist/studio/in-memory-asset-source.d.ts +15 -0
  102. package/dist/studio/index.d.ts +31 -0
  103. package/dist/studio/indexeddb-asset-source.d.ts +32 -0
  104. package/dist/studio/indexeddb-persistence.d.ts +13 -0
  105. package/dist/studio/remote-asset-importer.d.ts +56 -0
  106. package/dist/studio/source-package.d.ts +9 -0
  107. package/dist/studio/usd-export-client.d.ts +13 -0
  108. package/dist/studio/usd-export-protocol.d.ts +98 -0
  109. package/dist/studio/usd-export-worker.d.ts +1 -0
  110. package/dist/studio/usd-zip-reader.d.ts +14 -0
  111. package/dist/studio/web-asset-ingestor.d.ts +10 -0
  112. package/dist/studio/web-host.d.ts +8 -0
  113. package/dist/studio.js +5545 -0
  114. package/dist/urdf-session-CQir2nb2.js +1230 -0
  115. package/dist/usd-session-DZJnEEOs.js +7385 -0
  116. package/dist/util/asset-facts.d.ts +3 -0
  117. package/dist/util/data.d.ts +17 -0
  118. package/dist/util/diagnostics.d.ts +38 -0
  119. package/dist/util/geometry.d.ts +11 -0
  120. package/dist/util/hash.d.ts +9 -0
  121. package/dist/util/ids.d.ts +20 -0
  122. package/dist/util/math.d.ts +47 -0
  123. package/dist/util/ply-metadata.d.ts +19 -0
  124. package/dist/util/studio-source.d.ts +23 -0
  125. package/dist/version.d.ts +5 -0
  126. package/dist/view/appearance.d.ts +13 -0
  127. package/dist/view/authoring-appearance.d.ts +25 -0
  128. package/dist/view/bounds-preview.d.ts +34 -0
  129. package/dist/view/bounds.d.ts +11 -0
  130. package/dist/view/camera-zoom.d.ts +3 -0
  131. package/dist/view/geometry-anchors.d.ts +20 -0
  132. package/dist/view/gizmo-appearance.d.ts +5 -0
  133. package/dist/view/gizmo.d.ts +81 -0
  134. package/dist/view/group-selection.d.ts +13 -0
  135. package/dist/view/node-features.d.ts +39 -0
  136. package/dist/view/picking.d.ts +49 -0
  137. package/dist/view/placement.d.ts +48 -0
  138. package/dist/view/region-editing.d.ts +25 -0
  139. package/dist/view/rotation-guide.d.ts +36 -0
  140. package/dist/view/runtime-capabilities.d.ts +22 -0
  141. package/dist/view/scene-session.d.ts +258 -0
  142. package/dist/view/screen-bounds.d.ts +17 -0
  143. package/dist/view/selection-transform.d.ts +20 -0
  144. package/dist/wasm-module-DZn2AM1W.js +13 -0
  145. package/dist/xacro-DLRXyk60.js +76 -0
  146. package/node_modules/@nebula-spatial/cad-loader/CHANGELOG.md +48 -0
  147. package/node_modules/@nebula-spatial/cad-loader/README.md +108 -0
  148. package/node_modules/@nebula-spatial/cad-loader/dist/core/cad-types.d.ts +26 -0
  149. package/node_modules/@nebula-spatial/cad-loader/dist/core/errors.d.ts +5 -0
  150. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.d.ts +24 -0
  151. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.js +2354 -0
  152. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-group-reader.d.ts +9 -0
  153. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-parser.d.ts +78 -0
  154. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/dxbs-sidecar.d.ts +24 -0
  155. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/geometry-segments.d.ts +20 -0
  156. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/text-roundtrip.d.ts +4 -0
  157. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/types.d.ts +81 -0
  158. package/node_modules/@nebula-spatial/cad-loader/dist/core/runtime-text-decoder.d.ts +8 -0
  159. package/node_modules/@nebula-spatial/cad-loader/dist/core/types.d.ts +153 -0
  160. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/insert-bbox.d.ts +10 -0
  161. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/viewport-rect.d.ts +21 -0
  162. package/node_modules/@nebula-spatial/cad-loader/dist/index.d.ts +36 -0
  163. package/node_modules/@nebula-spatial/cad-loader/dist/index.js +5829 -0
  164. package/node_modules/@nebula-spatial/cad-loader/dist/loader/geo-loader.d.ts +59 -0
  165. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/automatic-external-resources.d.ts +26 -0
  166. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/external-variant-sidecar-fetch.d.ts +13 -0
  167. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/flow-control.d.ts +29 -0
  168. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/frame-budget-scheduler.d.ts +21 -0
  169. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-compact-executor.d.ts +19 -0
  170. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-local-adapter.d.ts +2 -0
  171. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-pipeline.d.ts +92 -0
  172. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-worker-adapter.d.ts +13 -0
  173. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-builder.d.ts +34 -0
  174. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-load-sink.d.ts +28 -0
  175. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node.d.ts +304 -0
  176. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare-worker-types.d.ts +94 -0
  177. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.d.ts +38 -0
  178. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.worker.d.ts +1 -0
  179. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-model-builder.d.ts +10 -0
  180. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-runtime-geometry.d.ts +15 -0
  181. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-canonical.d.ts +37 -0
  182. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-quality.d.ts +9 -0
  183. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/prepare-credit-gate.d.ts +20 -0
  184. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/transport.d.ts +2 -0
  185. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/cad-render-node.d.ts +80 -0
  186. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/geo-node-cad-render-node.d.ts +12 -0
  187. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-geometry.d.ts +28 -0
  188. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-material.d.ts +18 -0
  189. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/block-geometry-registry.d.ts +35 -0
  190. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/insert-instance-table.d.ts +23 -0
  191. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/viewport-instance-presenter.d.ts +66 -0
  192. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-insert-selection.d.ts +35 -0
  193. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-text-selection.d.ts +31 -0
  194. package/node_modules/@nebula-spatial/cad-loader/dist/session/annotation-idle-gate.d.ts +14 -0
  195. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-document-session.d.ts +187 -0
  196. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-font-runtime.d.ts +11 -0
  197. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-insert-id.d.ts +6 -0
  198. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-text-warmup.d.ts +38 -0
  199. package/node_modules/@nebula-spatial/cad-loader/dist/session/create-cad-document-session.d.ts +5 -0
  200. package/node_modules/@nebula-spatial/cad-loader/dist/session/load-session.d.ts +90 -0
  201. package/node_modules/@nebula-spatial/cad-loader/dist/session/viewport-coverage.d.ts +32 -0
  202. package/node_modules/@nebula-spatial/cad-loader/dist/shared/abort.d.ts +3 -0
  203. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-display-color.d.ts +55 -0
  204. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-load-source.d.ts +8 -0
  205. package/node_modules/@nebula-spatial/cad-loader/dist/shared/color-buffer.d.ts +6 -0
  206. package/node_modules/@nebula-spatial/cad-loader/dist/shared/constants.d.ts +11 -0
  207. package/node_modules/@nebula-spatial/cad-loader/dist/shared/display-color-buffer.d.ts +27 -0
  208. package/node_modules/@nebula-spatial/cad-loader/dist/shared/errors.d.ts +2 -0
  209. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-builder.d.ts +25 -0
  210. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-font.d.ts +12 -0
  211. package/node_modules/@nebula-spatial/cad-loader/dist/shared/types.d.ts +57 -0
  212. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/insert-bbox.d.ts +1 -0
  213. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/timing.d.ts +2 -0
  214. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/viewport-rect.d.ts +1 -0
  215. package/node_modules/@nebula-spatial/cad-loader/dist/shared/viewer-theme.d.ts +2 -0
  216. package/node_modules/@nebula-spatial/cad-loader/dist/workers/geo-prepare.worker.js +2264 -0
  217. package/node_modules/@nebula-spatial/cad-loader/package.json +62 -0
  218. package/node_modules/@nebula-spatial/viewer/CHANGELOG.md +426 -0
  219. package/node_modules/@nebula-spatial/viewer/FBX-MATERIAL-CONVERSION.md +97 -0
  220. package/node_modules/@nebula-spatial/viewer/README.md +1056 -0
  221. package/node_modules/@nebula-spatial/viewer/USD-VISUAL-MATERIAL-SUPPORT.md +89 -0
  222. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.js +19 -0
  223. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.wasm +0 -0
  224. package/node_modules/@nebula-spatial/viewer/dist/asset-ir-DEOK9SqE.js +382 -0
  225. package/node_modules/@nebula-spatial/viewer/dist/assets/ground-grid.d.ts +6 -0
  226. package/node_modules/@nebula-spatial/viewer/dist/assets/source-types.d.ts +19 -0
  227. package/node_modules/@nebula-spatial/viewer/dist/assets/types.d.ts +393 -0
  228. package/node_modules/@nebula-spatial/viewer/dist/assets/usd-worker-Bom5cjz3.js +1392 -0
  229. package/node_modules/@nebula-spatial/viewer/dist/cad/text.d.ts +2 -0
  230. package/node_modules/@nebula-spatial/viewer/dist/cad/types.d.ts +368 -0
  231. package/node_modules/@nebula-spatial/viewer/dist/index-ByBlfVc0.js +12132 -0
  232. package/node_modules/@nebula-spatial/viewer/dist/index.d.ts +32 -0
  233. package/node_modules/@nebula-spatial/viewer/dist/index.js +26 -0
  234. package/node_modules/@nebula-spatial/viewer/dist/inspection/types.d.ts +112 -0
  235. package/node_modules/@nebula-spatial/viewer/dist/mjcf-visual-DVRa0w90.js +72 -0
  236. package/node_modules/@nebula-spatial/viewer/dist/mujoco-runtime-Dhx6Ua2u.js +463 -0
  237. package/node_modules/@nebula-spatial/viewer/dist/plugins.d.ts +179 -0
  238. package/node_modules/@nebula-spatial/viewer/dist/scene/instances.d.ts +36 -0
  239. package/node_modules/@nebula-spatial/viewer/dist/scene/types.d.ts +258 -0
  240. package/node_modules/@nebula-spatial/viewer/dist/session-B-j6KdA-.js +389 -0
  241. package/node_modules/@nebula-spatial/viewer/dist/session-B4AICTeJ.js +963 -0
  242. package/node_modules/@nebula-spatial/viewer/dist/session-BAG5cDYe.js +9153 -0
  243. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-runtime.d.ts +118 -0
  244. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-wasm-module.d.ts +11 -0
  245. package/node_modules/@nebula-spatial/viewer/dist/simulation/openusd-wasm-module.d.ts +10 -0
  246. package/node_modules/@nebula-spatial/viewer/dist/simulation/physics-runtime-state.d.ts +75 -0
  247. package/node_modules/@nebula-spatial/viewer/dist/simulation/types.d.ts +129 -0
  248. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-inspection.d.ts +66 -0
  249. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-query.d.ts +50 -0
  250. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-resource-policy.d.ts +28 -0
  251. package/node_modules/@nebula-spatial/viewer/dist/types.d.ts +278 -0
  252. package/node_modules/@nebula-spatial/viewer/dist/ui/types.d.ts +48 -0
  253. package/node_modules/@nebula-spatial/viewer/dist/urdf-session-kemAnBn8.js +3231 -0
  254. package/node_modules/@nebula-spatial/viewer/dist/usd-session-QtwGKI7v.js +6771 -0
  255. package/node_modules/@nebula-spatial/viewer/dist/version.d.ts +5 -0
  256. package/node_modules/@nebula-spatial/viewer/dist/viewer.d.ts +2 -0
  257. package/node_modules/@nebula-spatial/viewer/dist/xacro-CYTPS7mh.js +1537 -0
  258. package/node_modules/@nebula-spatial/viewer/openusd/openusd-runtime-manifest.json +15 -0
  259. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.js +14 -0
  260. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.wasm +0 -0
  261. package/node_modules/@nebula-spatial/viewer/package.json +66 -0
  262. package/package.json +87 -6
@@ -0,0 +1,463 @@
1
+ var S = Object.defineProperty;
2
+ var A = (_, t, e) => t in _ ? S(_, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : _[t] = e;
3
+ var p = (_, t, e) => A(_, typeof t != "symbol" ? t + "" : t, e);
4
+ import L from "@mujoco/mujoco";
5
+ import { Quaternion as w, Vector3 as y } from "three";
6
+ import { b as R, H as B } from "./index-ByBlfVc0.js";
7
+ let D = 0;
8
+ function C(_, t) {
9
+ const e = `/viewer-simulation-${++D}`;
10
+ _.mkdir(e);
11
+ const i = /* @__PURE__ */ new Set([e]), s = /* @__PURE__ */ new Set(), n = (o, r) => {
12
+ const m = o.replaceAll("\\", "/").split("/");
13
+ if (m[0] === "" || m.some((u) => u === ".." || u.includes(":"))) throw N(`Invalid package path: ${o}`, "E_SIMULATION_PATH");
14
+ const l = m.filter((u) => u && u !== ".");
15
+ if (!l.length) throw N("Package path is empty.", "E_SIMULATION_PATH");
16
+ let h = e;
17
+ for (const u of l.slice(0, -1))
18
+ h += `/${u}`, i.has(h) || (_.mkdir(h), i.add(h));
19
+ const c = `${e}/${l.join("/")}`;
20
+ return _.writeFile(c, r), s.add(c), c;
21
+ }, a = () => {
22
+ for (const o of s) _.unlink(o);
23
+ s.clear();
24
+ for (const o of [...i].reverse()) _.rmdir(o);
25
+ i.clear();
26
+ };
27
+ try {
28
+ for (const [o, r] of t) n(o, r);
29
+ return { writeEntry: (o) => n("__viewer_entry.xml", o), dispose: a };
30
+ } catch (o) {
31
+ throw a(), o;
32
+ }
33
+ }
34
+ function N(_, t) {
35
+ return Object.assign(new Error(_), { code: t });
36
+ }
37
+ function z({
38
+ target: _,
39
+ point: t,
40
+ velocity: e,
41
+ stiffness: i,
42
+ damping: s,
43
+ maxForce: n,
44
+ strength: a
45
+ }) {
46
+ const o = [
47
+ i * (_[0] - t[0]) - s * e[0],
48
+ i * (_[1] - t[1]) - s * e[1],
49
+ i * (_[2] - t[2]) - s * e[2]
50
+ ], r = Math.hypot(o[0], o[1], o[2]), m = n * a;
51
+ if (r > m && r > 0) {
52
+ const l = m / r;
53
+ o[0] *= l, o[1] *= l, o[2] *= l;
54
+ }
55
+ return o;
56
+ }
57
+ const v = 1 / 240, U = 1 / 960, V = 0.25, P = 0.05, $ = 80, k = 0.7, H = 60, Y = 1e-4, G = 10, J = 3.5, F = 14;
58
+ class K {
59
+ constructor() {
60
+ p(this, "mujoco", null);
61
+ p(this, "model", null);
62
+ p(this, "data", null);
63
+ p(this, "grab", null);
64
+ p(this, "lastGrabForce", [0, 0, 0]);
65
+ p(this, "initialControls", []);
66
+ p(this, "initialJoints", {});
67
+ p(this, "accumulator", 0);
68
+ p(this, "stepTotal", 0);
69
+ p(this, "timestep", v);
70
+ /** Timestep compiled from the physics asset; grabs may temporarily refine it. */
71
+ p(this, "baseTimestep", v);
72
+ /** Authored ground pose, captured before any seating. Re-seats start here. */
73
+ p(this, "initialGround", null);
74
+ /** Ground pose currently in the model; restored verbatim by reset(). */
75
+ p(this, "seatedGround", null);
76
+ p(this, "worldRotation", new w());
77
+ p(this, "topLevelBodies", []);
78
+ p(this, "initialVelocities", []);
79
+ }
80
+ async initialize(t, e = {}) {
81
+ var l;
82
+ const i = e.wasmModule ? await e.wasmModule : void 0;
83
+ this.mujoco ?? (this.mujoco = await L({
84
+ locateFile: (h) => h.endsWith(".wasm") ? B(e.baseUrl) : h,
85
+ ...i ? {
86
+ instantiateWasm(h, c) {
87
+ return R(i, h, c);
88
+ }
89
+ } : {}
90
+ }));
91
+ const s = C(this.mujoco.FS, t.files);
92
+ let n = null, a = null, o = null, r = null, m = v;
93
+ try {
94
+ if (n = this.mujoco.MjModel.from_xml_path(s.writeEntry(t.xml)), m = n.opt.timestep, !Number.isFinite(m) || m <= 0)
95
+ throw new Error(`Invalid MuJoCo timestep: ${m}`);
96
+ for (const c of t.massOverrides ?? []) {
97
+ const u = this.mujoco.mj_name2id(n, this.mujoco.mjtObj.mjOBJ_BODY.value, c.body);
98
+ if (u <= 0 || !Number.isFinite(c.mass) || c.mass <= 0 || !(n.body_mass[u] > 0)) throw new Error(`Invalid mass override: ${c.body}`);
99
+ const f = c.mass / n.body_mass[u];
100
+ n.body_mass[u] = c.mass;
101
+ for (let j = 0; j < 3; j++) n.body_inertia[u * 3 + j] *= f;
102
+ }
103
+ a = new this.mujoco.MjData(n), (l = t.massOverrides) != null && l.length && this.mujoco.mj_setConst(n, a), this.applyCenterOfMassOverrides(n, t.centerOfMassOverrides), this.worldRotation.identity(), this.applyInitialJoints(n, a, t.initialJoints), this.applyInitialControls(a, t.initialControls), this.applyInitialVelocities(n, a, t.initialVelocities), this.mujoco.mj_forward(n, a);
104
+ const h = this.mujoco.mj_name2id(n, this.mujoco.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
105
+ o = h < 0 ? null : { id: h, height: n.geom_pos[h * 3 + 2], sameFrame: n.geom_sameframe[h] }, r = this.seatDefaultGround(n, a);
106
+ } catch (h) {
107
+ throw a == null || a.delete(), n == null || n.delete(), M(h, "E_MUJOCO_INITIALIZE");
108
+ } finally {
109
+ s.dispose();
110
+ }
111
+ this.disposeModel(), this.model = n, this.data = a, this.initialControls = t.initialControls ?? [], this.initialJoints = t.initialJoints ?? {}, this.initialVelocities = t.initialVelocities ?? [], this.accumulator = 0, this.stepTotal = 0, this.baseTimestep = m, this.timestep = m, this.initialGround = o, this.seatedGround = r, this.topLevelBodies = this.captureTopLevelBodies(n);
112
+ }
113
+ get defaultGroundHeight() {
114
+ if (!this.mujoco || !this.model) return;
115
+ const t = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
116
+ return t < 0 ? void 0 : this.model.geom_pos[t * 3 + 2];
117
+ }
118
+ get stepCount() {
119
+ return this.stepTotal;
120
+ }
121
+ /** Pin the viewer-owned floor to a world-frame height, overriding auto-seating. */
122
+ setDefaultGroundHeight(t) {
123
+ if (!Number.isFinite(t) || !this.mujoco || !this.model || !this.data) return !1;
124
+ const e = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
125
+ return e < 0 || this.model.geom_bodyid[e] !== 0 || this.model.geom_type[e] !== this.mujoco.mjtGeom.mjGEOM_PLANE.value ? !1 : (this.model.geom_pos[e * 3 + 2] = t, this.model.geom_sameframe[e] = 0, this.seatedGround = { id: e, height: t, sameFrame: 0 }, this.mujoco.mj_forward(this.model, this.data), !0);
126
+ }
127
+ /**
128
+ * Re-orients the compiled physics to the given authored up axis by rotating
129
+ * every top-level body about the world origin. Gravity stays -Z and the
130
+ * viewer ground stays the authored horizontal plane, so a cup that was
131
+ * standing now genuinely topples and settles on its side — the alternative,
132
+ * rotating only the rendered scene graph, would leave the visuals and the
133
+ * simulation in different frames.
134
+ *
135
+ * The full current state (free-joint positions, orientations and velocities)
136
+ * is rotated by the same delta, so a paused or running simulation is carried
137
+ * over instead of being re-seeded.
138
+ */
139
+ setWorldRotation(t) {
140
+ var n;
141
+ if (!this.mujoco || !this.model || !this.data) return;
142
+ const e = this.model, i = this.data;
143
+ if (t.equals(this.worldRotation)) return;
144
+ const s = t.clone().multiply(this.worldRotation.clone().invert());
145
+ this.rotateReferenceFrames(this.topLevelBodies, t), this.rotateState(this.topLevelBodies, e, i, s), this.worldRotation.copy(t), this.mujoco.mj_forward(e, i), this.seatedGround = this.seatDefaultGround(e, i, (n = this.initialGround) == null ? void 0 : n.height), this.accumulator = 0;
146
+ }
147
+ captureTopLevelBodies(t) {
148
+ const e = this.mujoco, i = [];
149
+ for (let s = 1; s < t.nbody; s++) {
150
+ if (t.body_parentid[s] !== 0) continue;
151
+ const n = t.body_jntadr[s], a = t.body_jntnum[s] === 1 && n >= 0 && t.jnt_type[n] === e.mjtJoint.mjJNT_FREE.value ? n : -1, o = s * 3, r = s * 4;
152
+ i.push({
153
+ id: s,
154
+ position: new y(t.body_pos[o], t.body_pos[o + 1], t.body_pos[o + 2]),
155
+ quaternion: new w(t.body_quat[r + 1], t.body_quat[r + 2], t.body_quat[r + 3], t.body_quat[r]),
156
+ freeJoint: a
157
+ });
158
+ }
159
+ return i;
160
+ }
161
+ /** Writes the rotated reference pose, which reset() and fixed bases follow. */
162
+ rotateReferenceFrames(t, e) {
163
+ const i = this.model;
164
+ for (const s of t) {
165
+ const n = s.position.clone().applyQuaternion(e), a = e.clone().multiply(s.quaternion), o = s.id * 3, r = s.id * 4;
166
+ if (i.body_pos[o] = n.x, i.body_pos[o + 1] = n.y, i.body_pos[o + 2] = n.z, i.body_quat[r] = a.w, i.body_quat[r + 1] = a.x, i.body_quat[r + 2] = a.y, i.body_quat[r + 3] = a.z, i.body_sameframe[s.id] && (i.body_sameframe[s.id] = 0), s.freeJoint < 0) continue;
167
+ const m = i.jnt_qposadr[s.freeJoint];
168
+ i.qpos0[m] = n.x, i.qpos0[m + 1] = n.y, i.qpos0[m + 2] = n.z, i.qpos0[m + 3] = a.w, i.qpos0[m + 4] = a.x, i.qpos0[m + 5] = a.y, i.qpos0[m + 6] = a.z;
169
+ }
170
+ }
171
+ /** Rotates the live free-joint state so the simulation keeps its progress. */
172
+ rotateState(t, e, i, s) {
173
+ for (const n of t) {
174
+ if (n.freeJoint < 0) continue;
175
+ const a = e.jnt_qposadr[n.freeJoint], o = e.jnt_dofadr[n.freeJoint], r = new y(i.qpos[a], i.qpos[a + 1], i.qpos[a + 2]).applyQuaternion(s);
176
+ i.qpos[a] = r.x, i.qpos[a + 1] = r.y, i.qpos[a + 2] = r.z;
177
+ const m = new w(i.qpos[a + 4], i.qpos[a + 5], i.qpos[a + 6], i.qpos[a + 3]).premultiply(s);
178
+ i.qpos[a + 3] = m.w, i.qpos[a + 4] = m.x, i.qpos[a + 5] = m.y, i.qpos[a + 6] = m.z;
179
+ const l = new y(i.qvel[o], i.qvel[o + 1], i.qvel[o + 2]).applyQuaternion(s);
180
+ i.qvel[o] = l.x, i.qvel[o + 1] = l.y, i.qvel[o + 2] = l.z;
181
+ const h = new y(i.qvel[o + 3], i.qvel[o + 4], i.qvel[o + 5]).applyQuaternion(s);
182
+ i.qvel[o + 3] = h.x, i.qvel[o + 4] = h.y, i.qvel[o + 5] = h.z;
183
+ }
184
+ }
185
+ /** Lower only the viewer-owned plane, never authored bodies or authored floors.
186
+ * Run after forward kinematics, not during stepping (the floor must not follow falling bodies).
187
+ * `baseHeight` re-seats from a stable reference; omitting it lowers from the current pose.
188
+ */
189
+ seatDefaultGround(t, e, i) {
190
+ const s = this.mujoco, n = s.mj_name2id(t, s.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
191
+ if (n < 0 || t.geom_bodyid[n] !== 0 || t.geom_type[n] !== s.mjtGeom.mjGEOM_PLANE.value) return null;
192
+ let a = i ?? t.geom_pos[n * 3 + 2];
193
+ for (let o = 0; o < t.ngeom; o++) {
194
+ if (o === n || t.geom_type[o] === s.mjtGeom.mjGEOM_PLANE.value || !(t.geom_contype[o] & t.geom_conaffinity[n]) && !(t.geom_conaffinity[o] & t.geom_contype[n])) continue;
195
+ const r = this.geomBottom(t, e, o), m = Math.max(1e-3, t.geom_margin[o] + t.geom_margin[n]);
196
+ Number.isFinite(r) && r < a && (a = Math.min(a, r - m));
197
+ }
198
+ return a !== t.geom_pos[n * 3 + 2] && (t.geom_pos[n * 3 + 2] = a, t.geom_sameframe[n] = 0, s.mj_forward(t, e)), { id: n, height: a, sameFrame: t.geom_sameframe[n] };
199
+ }
200
+ /**
201
+ * Resolve the lowest world-space point directly from MuJoCo's primitive
202
+ * parameters. Rotating a mesh's local AABB into world space is conservative:
203
+ * for a long, rotated shape it can sit far below the actual geometry. Use the
204
+ * compiled vertices for mesh-backed geoms so the ground reflects the real
205
+ * lowest point rather than the corners of its local bounding box.
206
+ */
207
+ geomBottom(t, e, i) {
208
+ const s = this.mujoco, n = e.geom_xpos[i * 3 + 2], a = i * 3, o = i * 9, r = t.geom_type[i], m = Math.abs(t.geom_size[a]), l = Math.abs(t.geom_size[a + 1]), h = Math.abs(t.geom_size[a + 2]);
209
+ if (r === s.mjtGeom.mjGEOM_SPHERE.value)
210
+ return n - m;
211
+ if (r === s.mjtGeom.mjGEOM_CAPSULE.value)
212
+ return n - m - Math.abs(e.geom_xmat[o + 8]) * l;
213
+ if (r === s.mjtGeom.mjGEOM_CYLINDER.value) {
214
+ const d = e.geom_xmat[o + 8];
215
+ return n - Math.abs(d) * l - Math.sqrt(Math.max(0, 1 - d * d)) * m;
216
+ }
217
+ if (r === s.mjtGeom.mjGEOM_ELLIPSOID.value)
218
+ return n - Math.hypot(
219
+ e.geom_xmat[o + 2] * m,
220
+ e.geom_xmat[o + 5] * l,
221
+ e.geom_xmat[o + 8] * h
222
+ );
223
+ if (r === s.mjtGeom.mjGEOM_BOX.value)
224
+ return n - Math.abs(e.geom_xmat[o + 2]) * m - Math.abs(e.geom_xmat[o + 5]) * l - Math.abs(e.geom_xmat[o + 8]) * h;
225
+ if (r === s.mjtGeom.mjGEOM_MESH.value || r === s.mjtGeom.mjGEOM_SDF.value) {
226
+ const d = t.geom_dataid[i];
227
+ if (d < 0 || d >= t.nmesh) return Number.POSITIVE_INFINITY;
228
+ const E = t.mesh_vertadr[d], T = t.mesh_vertnum[d];
229
+ if (!Number.isInteger(E) || !Number.isInteger(T) || E < 0 || T <= 0 || E + T > t.nmeshvert)
230
+ return Number.POSITIVE_INFINITY;
231
+ let I = Number.POSITIVE_INFINITY;
232
+ for (let O = E; O < E + T; O++) {
233
+ const q = O * 3, x = n + e.geom_xmat[o + 6] * t.mesh_vert[q] + e.geom_xmat[o + 7] * t.mesh_vert[q + 1] + e.geom_xmat[o + 8] * t.mesh_vert[q + 2];
234
+ Number.isFinite(x) && x < I && (I = x);
235
+ }
236
+ return I;
237
+ }
238
+ const c = i * 6, u = t.geom_aabb[c + 3], f = t.geom_aabb[c + 4], j = t.geom_aabb[c + 5];
239
+ if (![u, f, j].every((d) => Number.isFinite(d) && d >= 0))
240
+ return Number.POSITIVE_INFINITY;
241
+ const b = n + e.geom_xmat[o + 6] * t.geom_aabb[c] + e.geom_xmat[o + 7] * t.geom_aabb[c + 1] + e.geom_xmat[o + 8] * t.geom_aabb[c + 2], g = Math.abs(e.geom_xmat[o + 6]) * u + Math.abs(e.geom_xmat[o + 7]) * f + Math.abs(e.geom_xmat[o + 8]) * j;
242
+ return b - g;
243
+ }
244
+ beginGrab({
245
+ bodyId: t,
246
+ localPoint: e,
247
+ target: i,
248
+ stiffness: s,
249
+ damping: n,
250
+ maxForce: a,
251
+ dampingRatio: o = k,
252
+ maxTargetSpeed: r = J,
253
+ targetResponse: m = F
254
+ }) {
255
+ var j, b, g;
256
+ const l = Math.max(((j = this.model) == null ? void 0 : j.body_mass[t]) ?? 1, 1e-6);
257
+ if ((b = this.data) != null && b.body_awake && (this.data.body_awake[t] = 1), (g = this.data) != null && g.tree_awake && this.model) {
258
+ const d = this.model.body_rootid[t] ?? t;
259
+ this.data.tree_awake[d] = 1;
260
+ }
261
+ const h = s ?? $, c = n ?? 2 * Math.sqrt(h * l) * o, u = a ?? Math.max(Y, l * H);
262
+ this.setTimestep(this.grabTimestep(t, e, l, h));
263
+ const f = [i[0], i[1], i[2]];
264
+ this.grab = {
265
+ bodyId: t,
266
+ localPoint: [e[0], e[1], e[2]],
267
+ target: [...f],
268
+ requestedTarget: f,
269
+ stiffness: h,
270
+ damping: c,
271
+ maxForce: u,
272
+ strength: 1,
273
+ maxTargetSpeed: r,
274
+ targetResponse: m
275
+ };
276
+ }
277
+ updateGrabTarget(t) {
278
+ this.grab && (this.grab.requestedTarget = [t[0], t[1], t[2]]);
279
+ }
280
+ updateGrabStrength(t) {
281
+ this.grab && (this.grab.strength = t);
282
+ }
283
+ applyGrabForce() {
284
+ if (!this.grab || !this.model || !this.data || !this.mujoco) return;
285
+ const { bodyId: t, localPoint: e, target: i, stiffness: s, damping: n, maxForce: a, strength: o } = this.grab, r = this.data.xmat.subarray(t * 9, t * 9 + 9), m = this.data.xpos.subarray(t * 3, t * 3 + 3), l = [
286
+ m[0] + r[0] * e[0] + r[1] * e[1] + r[2] * e[2],
287
+ m[1] + r[3] * e[0] + r[4] * e[1] + r[5] * e[2],
288
+ m[2] + r[6] * e[0] + r[7] * e[1] + r[8] * e[2]
289
+ ], h = this.data.cvel.subarray(t * 6, t * 6 + 6), c = this.data.xipos.subarray(t * 3, t * 3 + 3), u = [
290
+ l[0] - c[0],
291
+ l[1] - c[1],
292
+ l[2] - c[2]
293
+ ], f = [
294
+ h[3] + h[1] * u[2] - h[2] * u[1],
295
+ h[4] + h[2] * u[0] - h[0] * u[2],
296
+ h[5] + h[0] * u[1] - h[1] * u[0]
297
+ ], j = z({ target: i, point: l, velocity: f, stiffness: s, damping: n, maxForce: a, strength: o });
298
+ this.lastGrabForce = [...j], this.data.qfrc_applied.fill(0);
299
+ const b = Math.min(
300
+ Math.max(this.model.body_inertia[t * 3], 1e-9),
301
+ Math.max(this.model.body_inertia[t * 3 + 1], 1e-9),
302
+ Math.max(this.model.body_inertia[t * 3 + 2], 1e-9)
303
+ ), g = [
304
+ -b * G * h[0],
305
+ -b * G * h[1],
306
+ -b * G * h[2]
307
+ ];
308
+ this.mujoco.mj_applyFT(
309
+ this.model,
310
+ this.data,
311
+ j,
312
+ g,
313
+ l,
314
+ t,
315
+ this.data.qfrc_applied
316
+ );
317
+ }
318
+ endGrab() {
319
+ this.data && this.data.qfrc_applied.fill(0), this.lastGrabForce = [0, 0, 0], this.grab = null, this.setTimestep(this.baseTimestep);
320
+ }
321
+ step(t) {
322
+ if (!this.mujoco || !this.model || !this.data || t <= 0) return !1;
323
+ this.accumulator += Math.min(t, P);
324
+ let e = !1;
325
+ for (; this.accumulator >= this.timestep; )
326
+ this.updateGrabTargetForStep(), this.applyGrabForce(), this.mujoco.mj_step(this.model, this.data), this.stepTotal += 1, this.accumulator -= this.timestep, e = !0;
327
+ return e;
328
+ }
329
+ updateGrabTargetForStep() {
330
+ const t = this.grab;
331
+ if (!t) return;
332
+ const e = t.requestedTarget ?? t.target, i = (t.maxTargetSpeed ?? J) * Math.max(1, Math.sqrt(t.strength)), s = t.targetResponse ?? F, n = 1 - Math.exp(-s * this.timestep), a = i * this.timestep;
333
+ for (let o = 0; o < 3; o++) {
334
+ const r = e[o] - t.target[o], m = Math.sign(r) * Math.min(Math.abs(r) * n, a);
335
+ t.target[o] += m;
336
+ }
337
+ }
338
+ setJointValues(t) {
339
+ if (!(!this.mujoco || !this.model || !this.data)) {
340
+ for (const [e, i] of Object.entries(t)) {
341
+ const s = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_JOINT.value, e);
342
+ if (s < 0 || !Number.isFinite(i)) continue;
343
+ const n = this.model.jnt_type[s], a = this.mujoco.mjtJoint.mjJNT_HINGE.value, o = this.mujoco.mjtJoint.mjJNT_SLIDE.value;
344
+ n !== a && n !== o || (this.data.qpos[this.model.jnt_qposadr[s]] = i);
345
+ }
346
+ this.mujoco.mj_forward(this.model, this.data), this.seatDefaultGround(this.model, this.data), this.accumulator = 0;
347
+ }
348
+ }
349
+ getJointValues(t) {
350
+ const e = {};
351
+ if (!this.mujoco || !this.model || !this.data) return e;
352
+ for (const i of t) {
353
+ const s = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_JOINT.value, i);
354
+ if (s < 0) continue;
355
+ const n = this.model.jnt_type[s], a = this.mujoco.mjtJoint.mjJNT_HINGE.value, o = this.mujoco.mjtJoint.mjJNT_SLIDE.value;
356
+ (n === a || n === o) && (e[i] = this.data.qpos[this.model.jnt_qposadr[s]]);
357
+ }
358
+ return e;
359
+ }
360
+ reset() {
361
+ if (!(!this.mujoco || !this.model || !this.data)) {
362
+ if (this.endGrab(), this.seatedGround) {
363
+ const { id: t, height: e, sameFrame: i } = this.seatedGround;
364
+ this.model.geom_pos[t * 3 + 2] = e, this.model.geom_sameframe[t] = i;
365
+ }
366
+ this.mujoco.mj_resetData(this.model, this.data), this.applyInitialJoints(this.model, this.data, this.initialJoints), this.applyInitialControls(this.data, this.initialControls), this.applyInitialVelocities(this.model, this.data, this.initialVelocities), this.mujoco.mj_forward(this.model, this.data), this.accumulator = 0, this.stepTotal = 0;
367
+ }
368
+ }
369
+ /**
370
+ * Runs an exact number of fixed-size steps for a deterministic probe. The
371
+ * compiled timestep is restored afterwards so the interactive runtime keeps
372
+ * its authored cadence.
373
+ */
374
+ advanceFixed(t, e) {
375
+ if (!this.mujoco || !this.model || !this.data || !Number.isFinite(t) || t <= 0 || !Number.isInteger(e) || e <= 0) return !1;
376
+ const i = this.timestep;
377
+ try {
378
+ this.setTimestep(t);
379
+ for (let s = 0; s < e; s += 1)
380
+ this.mujoco.mj_step(this.model, this.data), this.stepTotal += 1;
381
+ return this.accumulator = 0, !0;
382
+ } finally {
383
+ this.setTimestep(this.grab ? i : this.baseTimestep);
384
+ }
385
+ }
386
+ dispose() {
387
+ this.disposeModel(), this.mujoco = null;
388
+ }
389
+ applyInitialControls(t, e) {
390
+ if (e != null && e.length) {
391
+ if (e.length !== t.ctrl.length) throw M(new Error(`Initial control count ${e.length} does not match MuJoCo actuator count ${t.ctrl.length}.`), "E_MUJOCO_INITIALIZE");
392
+ t.ctrl.set(e);
393
+ }
394
+ }
395
+ applyCenterOfMassOverrides(t, e) {
396
+ for (const i of e ?? []) {
397
+ const s = this.mujoco.mj_name2id(
398
+ t,
399
+ this.mujoco.mjtObj.mjOBJ_BODY.value,
400
+ i.body
401
+ );
402
+ if (s <= 0 || i.position.length !== 3 || !i.position.every(Number.isFinite))
403
+ throw M(
404
+ new Error(`Invalid center-of-mass override: ${i.body}`),
405
+ "E_MUJOCO_INITIALIZE"
406
+ );
407
+ t.body_ipos.set(i.position, s * 3);
408
+ }
409
+ }
410
+ /**
411
+ * A point force on a light body can excite a much higher rotational
412
+ * frequency than its translational mass suggests. Refine physics only while
413
+ * that body is grabbed instead of adding global damping to hide the error.
414
+ */
415
+ grabTimestep(t, e, i, s) {
416
+ if (!this.model || !this.data) return v;
417
+ const n = Math.min(
418
+ Math.max(this.model.body_inertia[t * 3], 1e-9),
419
+ Math.max(this.model.body_inertia[t * 3 + 1], 1e-9),
420
+ Math.max(this.model.body_inertia[t * 3 + 2], 1e-9)
421
+ ), a = this.data.xpos.subarray(t * 3, t * 3 + 3), o = this.data.xipos.subarray(t * 3, t * 3 + 3), r = this.data.xmat.subarray(t * 9, t * 9 + 9), m = [
422
+ a[0] + r[0] * e[0] + r[1] * e[1] + r[2] * e[2],
423
+ a[1] + r[3] * e[0] + r[4] * e[1] + r[5] * e[2],
424
+ a[2] + r[6] * e[0] + r[7] * e[1] + r[8] * e[2]
425
+ ], l = (m[0] - o[0]) ** 2 + (m[1] - o[1]) ** 2 + (m[2] - o[2]) ** 2, h = Math.sqrt(s * (1 / i + l / n)), c = V / Math.max(h, 1e-9);
426
+ return Math.min(this.baseTimestep, Math.max(U, c));
427
+ }
428
+ setTimestep(t) {
429
+ var e;
430
+ this.timestep = t, (e = this.model) != null && e.opt && (this.model.opt.timestep = t);
431
+ }
432
+ applyInitialJoints(t, e, i = {}) {
433
+ const s = this.mujoco;
434
+ for (const [n, a] of Object.entries(i)) {
435
+ const o = s.mj_name2id(t, s.mjtObj.mjOBJ_JOINT.value, n);
436
+ if (o < 0 || !Number.isFinite(a) || ![s.mjtJoint.mjJNT_HINGE.value, s.mjtJoint.mjJNT_SLIDE.value].includes(t.jnt_type[o])) throw M(new Error("Initial pose requires a known scalar joint: " + n), "E_INITIAL_POSE_JOINT_INVALID");
437
+ e.qpos[t.jnt_qposadr[o]] = a;
438
+ }
439
+ }
440
+ applyInitialVelocities(t, e, i) {
441
+ for (const s of i ?? []) {
442
+ if (s.velocity.length !== 6 || !s.velocity.every(Number.isFinite))
443
+ throw M(new Error(`Invalid free-body initial velocity: ${s.body}`), "E_MUJOCO_INITIALIZE");
444
+ if (s.velocity.every((l) => Math.abs(l) <= 1e-12)) continue;
445
+ const n = this.mujoco.mj_name2id(t, this.mujoco.mjtObj.mjOBJ_BODY.value, s.body), a = n >= 0 ? t.body_jntadr[n] : -1;
446
+ if (a < 0 || t.jnt_type[a] !== this.mujoco.mjtJoint.mjJNT_FREE.value)
447
+ throw M(new Error(`Invalid free-body initial velocity: ${s.body}`), "E_MUJOCO_INITIALIZE");
448
+ const { worldRotation: o } = this, r = new y(s.velocity[0], s.velocity[1], s.velocity[2]).applyQuaternion(o), m = new y(s.velocity[3], s.velocity[4], s.velocity[5]).applyQuaternion(o);
449
+ e.qvel.set([r.x, r.y, r.z, m.x, m.y, m.z], t.jnt_dofadr[a]);
450
+ }
451
+ }
452
+ disposeModel() {
453
+ var t, e;
454
+ this.endGrab(), (t = this.data) == null || t.delete(), (e = this.model) == null || e.delete(), this.data = null, this.model = null, this.initialGround = null, this.seatedGround = null, this.topLevelBodies = [], this.initialControls = [], this.initialJoints = {}, this.initialVelocities = [], this.accumulator = 0, this.stepTotal = 0, this.baseTimestep = v, this.timestep = v;
455
+ }
456
+ }
457
+ function M(_, t) {
458
+ const e = _ instanceof Error ? _ : new Error(String(_));
459
+ return Object.assign(e, { code: t });
460
+ }
461
+ export {
462
+ K as MujocoRuntime
463
+ };
@@ -0,0 +1,179 @@
1
+ import type { Box3, Object3D } from 'three';
2
+ import type { CadHit, CadSelection, CadViewerSnapshot, CadViewerEventMap } from './cad/types';
3
+ import type { ViewerEventMap, ViewerViewMode, ViewerUiTheme } from './types';
4
+ import type { AssetControlState, AssetLoaderContribution, AssetPreviewSnapshot, AssetUpAxis } from './assets/types';
5
+ import type { AssetInspection } from './inspection/types';
6
+ export interface Disposable {
7
+ dispose(): void;
8
+ }
9
+ export interface ToolbarItem {
10
+ readonly id: string;
11
+ readonly label: string;
12
+ readonly title?: string;
13
+ readonly disabled?: boolean;
14
+ readonly pressed?: boolean;
15
+ /** Inline SVG markup (24x24 viewBox, `currentColor` stroke). */
16
+ readonly icon?: string;
17
+ readonly onClick: () => void;
18
+ }
19
+ export interface ViewerState {
20
+ readonly viewMode: ViewerViewMode;
21
+ readonly selectedObject: Object3D | null;
22
+ readonly highlightedObject: Object3D | null;
23
+ readonly isDisposed: boolean;
24
+ }
25
+ /** Read-only view of the active asset. Never exposes the mutable `AssetPreview` handle. */
26
+ export interface ViewerAssetReadApi {
27
+ /** Snapshot of the active asset; `null` when no asset is open. */
28
+ $read(): AssetPreviewSnapshot | null;
29
+ /** Authoritative control state, safe to bind button pressed states to. */
30
+ $readControl(): AssetControlState;
31
+ $inspection(): AssetInspection | null;
32
+ }
33
+ export interface ViewerPluginContext {
34
+ readonly cad: {
35
+ $read(): CadViewerSnapshot;
36
+ };
37
+ readonly asset: ViewerAssetReadApi;
38
+ readonly viewer: {
39
+ $getState(): ViewerState;
40
+ };
41
+ readonly commands: {
42
+ setLayerVisible(index: number, visible: boolean): boolean;
43
+ setSelection(selection: CadSelection | null): void;
44
+ fitDocument(): boolean;
45
+ setViewMode(mode: ViewerViewMode): void;
46
+ play(): boolean;
47
+ pause(): boolean;
48
+ reset(): boolean;
49
+ fitView(): boolean;
50
+ setUpAxis(axis: AssetUpAxis): boolean;
51
+ setGroundVisible(visible: boolean): boolean;
52
+ setCollisionVisible(visible: boolean): boolean;
53
+ setTheme(theme: ViewerUiTheme): boolean;
54
+ };
55
+ readonly events: {
56
+ on<K extends keyof (ViewerEventMap & CadViewerEventMap)>(type: K, listener: (event: (ViewerEventMap & CadViewerEventMap)[K]) => void): () => void;
57
+ };
58
+ readonly layout: {
59
+ mount(node: Node, options?: {
60
+ position?: 'left' | 'right' | 'top' | 'bottom' | 'overlay';
61
+ }): Disposable;
62
+ onInsetsChange(listener: (insets: ViewerEventMap['ui-layout-change']['contentInsets']) => void): () => void;
63
+ };
64
+ contribute(point: ViewerContributionPoint): Disposable;
65
+ dispose(): void;
66
+ }
67
+ export interface ViewerInteractionHooks {
68
+ /** Return false to consume the interaction and stop the managed pipeline. */
69
+ onPick?: (hit: CadHit | null) => boolean | void;
70
+ onHover?: (hit: CadHit | null) => void;
71
+ onSelect?: (selection: CadSelection | null) => void;
72
+ onClear?: () => void;
73
+ }
74
+ export type ViewerContributionPoint = {
75
+ readonly kind: 'panel';
76
+ readonly id: string;
77
+ readonly factory: (ctx: ViewerPluginContext) => Node;
78
+ } | {
79
+ readonly kind: 'toolbar';
80
+ readonly id: string;
81
+ readonly items: readonly ToolbarItem[];
82
+ } | {
83
+ readonly kind: 'hud';
84
+ readonly id: string;
85
+ readonly factory: (ctx: ViewerPluginContext) => Node;
86
+ } | {
87
+ readonly kind: 'statusbar';
88
+ readonly id: string;
89
+ readonly factory: (ctx: ViewerPluginContext) => Node;
90
+ } | {
91
+ readonly kind: 'inspector';
92
+ readonly id: string;
93
+ readonly matcher: (selection: CadSelection) => boolean;
94
+ readonly render: (ctx: ViewerPluginContext, selection: CadSelection) => Node;
95
+ } | {
96
+ readonly kind: 'interaction';
97
+ readonly id: string;
98
+ readonly hooks: ViewerInteractionHooks;
99
+ } | {
100
+ readonly kind: 'command';
101
+ readonly id: string;
102
+ readonly handler: (ctx: ViewerPluginContext, args?: unknown) => void;
103
+ } | {
104
+ readonly kind: 'fit-policy';
105
+ readonly id: string;
106
+ readonly resolve: (ctx: ViewerPluginContext) => Box3 | null;
107
+ } | AssetLoaderContribution;
108
+ export interface ViewerPlugin {
109
+ readonly id: string;
110
+ activate(context: ViewerPluginContext): void | Promise<void>;
111
+ deactivate?(): void | Promise<void>;
112
+ }
113
+ type SnapshotReader = () => CadViewerSnapshot;
114
+ type StateReader = () => ViewerState;
115
+ type AssetReader = () => AssetPreviewSnapshot | null;
116
+ type ControlStateReader = () => AssetControlState;
117
+ type InspectionReader = () => AssetInspection | null;
118
+ type PluginEventMap = ViewerEventMap & CadViewerEventMap;
119
+ type EventSubscriber = <K extends keyof PluginEventMap>(type: K, listener: (event: PluginEventMap[K]) => void) => () => void;
120
+ type CommandApi = ViewerPluginContext['commands'];
121
+ /**
122
+ * Layout channel the plugin manager delegates to. The engine owns zone
123
+ * containers, insets computation and the `ui-layout-change` broadcast; the
124
+ * manager only forwards contribution nodes into it.
125
+ */
126
+ export interface PluginLayoutPort {
127
+ mountPlugin(node: Node, position?: 'left' | 'right' | 'top' | 'bottom' | 'overlay'): Disposable;
128
+ /** Built-in UI path: the package owns the styling of nodes mounted this way. */
129
+ mountBuiltin(node: Node, options: {
130
+ zone: 'left' | 'right' | 'top' | 'bottom' | 'overlay';
131
+ group?: string;
132
+ }): Disposable;
133
+ }
134
+ export declare class ViewerPluginManager implements ViewerPluginRegistry {
135
+ private readonly readCad;
136
+ private readonly readState;
137
+ private readonly readAsset;
138
+ private readonly readControlState;
139
+ private readonly subscribe;
140
+ private readonly commands;
141
+ private readonly hostElement;
142
+ private readonly layout;
143
+ private readonly readInspection;
144
+ private readonly pluginsById;
145
+ private readonly contributions;
146
+ private readonly commandContributions;
147
+ private readonly builtinPlugins;
148
+ private readonly contributionRemovedListeners;
149
+ private refreshingInspectors;
150
+ private disposed;
151
+ constructor(readCad: SnapshotReader, readState: StateReader, readAsset: AssetReader, readControlState: ControlStateReader, subscribe: EventSubscriber, commands: CommandApi, hostElement: HTMLElement, layout?: PluginLayoutPort | null, readInspection?: InspectionReader);
152
+ register(plugin: ViewerPlugin): Disposable;
153
+ use(plugins: readonly ViewerPlugin[], options?: {
154
+ replace?: boolean;
155
+ }): void;
156
+ registerBuiltin(plugin: ViewerPlugin): Disposable;
157
+ getAssetLoaders(): readonly AssetLoaderContribution[];
158
+ onAssetLoaderRemoved(listener: (loader: AssetLoaderContribution) => void): Disposable;
159
+ private onContributionRemoved;
160
+ private deactivate;
161
+ disposeAll(): void;
162
+ dispose(): void;
163
+ dispatchInteraction(kind: keyof ViewerInteractionHooks, value: CadHit | CadSelection | null): boolean;
164
+ findFitPolicy(): Box3 | null;
165
+ executeCommand(id: string, args?: unknown): boolean;
166
+ hasCommand(id: string): boolean;
167
+ private removeContribution;
168
+ private mountContribution;
169
+ private isFirstMatchingInspector;
170
+ private refreshInspectorContributions;
171
+ private assertActive;
172
+ }
173
+ export interface ViewerPluginRegistry {
174
+ register(plugin: ViewerPlugin): Disposable;
175
+ use(plugins: readonly ViewerPlugin[], options?: {
176
+ replace?: boolean;
177
+ }): void;
178
+ }
179
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Builds a `THREE.Group` scene root holding one child group per placed asset.
3
+ *
4
+ * Each child keeps the asset's own session alive so format-specific behaviour
5
+ * (USD staging, MuJoCo step, animation mixers) is never reimplemented here. The
6
+ * scene only owns placement, readiness bookkeeping and disposal.
7
+ */
8
+ import { Group, Object3D } from 'three';
9
+ import type { AssetLoaderContext, AssetSession, NormalizedAssetSource } from '../assets/types';
10
+ import type { SceneEntry, SceneInstanceSnapshot, ScenePlacement } from './types';
11
+ /** Result of mounting one entry: the group plus the session that owns it. */
12
+ export interface MountedSceneInstance {
13
+ readonly entryId: string;
14
+ readonly assetId: string;
15
+ readonly group: Group;
16
+ readonly content: Group;
17
+ readonly session: AssetSession;
18
+ readonly source: NormalizedAssetSource;
19
+ }
20
+ export interface SceneAssetResolver {
21
+ /** Per-entry detection using the same loaders the single-asset path uses. */
22
+ detect(entry: SceneEntry, source: NormalizedAssetSource, signal: AbortSignal): Promise<{
23
+ readonly create: (context: AssetLoaderContext) => AssetSession | Promise<AssetSession>;
24
+ } | {
25
+ readonly error: Error;
26
+ }>;
27
+ }
28
+ export declare function applyPlacement(object: Object3D, placement: ScenePlacement | undefined): void;
29
+ /** Applies source-content pivot compensation below the posed instance root. */
30
+ export declare function applyContentPivot(object: Object3D, pivot: ScenePlacement['pivot']): void;
31
+ export declare function toPlacementSnapshot(group: Object3D, pivot?: ScenePlacement['pivot']): ScenePlacement;
32
+ export declare function instanceSnapshot(entry: Pick<SceneEntry, 'id'>, phase: SceneInstanceSnapshot['phase'], error?: SceneInstanceSnapshot['error']): SceneInstanceSnapshot;
33
+ /** Name used for the child group so host-side picking can map back to an id. */
34
+ export declare function instanceGroupName(entryId: string): string;
35
+ /** Reads the owning entry id from an object, walking up to the scene root. */
36
+ export declare function findInstanceId(object: Object3D | null): string | null;