@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,72 @@
1
+ import { k as v, s as E, b as z } from "./scene-session-Cy6vDJ1l.js";
2
+ import { Group as q, Euler as G, BoxGeometry as N, SphereGeometry as P, CylinderGeometry as $, CapsuleGeometry as I, PlaneGeometry as X, Mesh as j } from "three";
3
+ function D(f) {
4
+ const y = f.extension.documents, l = new q();
5
+ l.name = f.name;
6
+ try {
7
+ if (y.size !== 1) throw new Error("MJCF 独立预览暂不支持 include");
8
+ const u = [...y.values()][0];
9
+ if (u.querySelector("default, include, attach, replicate, composite, flexcomp, skin, hfield, plugin")) throw new Error("MJCF 独立预览包含尚不支持的继承、组合或扩展语义");
10
+ const a = u.querySelector("compiler");
11
+ if ((a == null ? void 0 : a.getAttribute("coordinate")) === "global" || a != null && a.hasAttribute("eulerseq")) throw new Error("MJCF 独立预览不支持此坐标设置");
12
+ const g = (a == null ? void 0 : a.getAttribute("angle")) === "radian" ? 1 : Math.PI / 180, b = (c, m) => {
13
+ const e = c ? c.trim().split(/\s+/).map(Number) : m;
14
+ if (e.some((s) => !Number.isFinite(s))) throw new Error("MJCF 视觉坐标无效");
15
+ return e;
16
+ }, h = (c, m, e) => {
17
+ const s = b(c, m);
18
+ if (s.length !== e) throw new Error(`MJCF 视觉变换需要 ${e} 个分量`);
19
+ return s;
20
+ }, M = (c, m) => {
21
+ for (const e of c.children) {
22
+ if (!["body", "geom"].includes(e.tagName)) continue;
23
+ if (["class", "childclass", "fromto", "axisangle", "xyaxes", "zaxis"].some((t) => e.hasAttribute(t))) throw new Error("MJCF 独立预览不支持此变换或默认类");
24
+ const s = new q();
25
+ if (s.name = e.getAttribute("name") ?? e.tagName, s.position.fromArray(h(e.getAttribute("pos"), [0, 0, 0], 3)), e.hasAttribute("quat")) {
26
+ const t = h(e.getAttribute("quat"), [1, 0, 0, 0], 4);
27
+ if (Math.hypot(...t) === 0) throw new Error("MJCF 视觉四元数不能为零");
28
+ s.quaternion.set(t[1], t[2], t[3], t[0]).normalize();
29
+ } else {
30
+ const t = h(e.getAttribute("euler"), [0, 0, 0], 3);
31
+ s.quaternion.setFromEuler(new G(t[0] * g, t[1] * g, t[2] * g, "XYZ"));
32
+ }
33
+ if (m.add(s), e.tagName === "body") {
34
+ M(e, s);
35
+ continue;
36
+ }
37
+ const n = e.getAttribute("type") ?? (e.hasAttribute("mesh") ? "mesh" : "sphere"), r = b(e.getAttribute("size"), []);
38
+ if (r.length === 0) throw new Error("MJCF 独立预览缺少可直接解析的几何或材质");
39
+ const F = { box: 3, sphere: 1, cylinder: 2, capsule: 2, plane: 3 }[n];
40
+ if (F && (r.length < F || r.some((t) => n === "plane" ? t < 0 : t <= 0)))
41
+ throw new Error(`MJCF geom ${n} 的尺寸缺失或无效`);
42
+ let i;
43
+ if (n === "box") i = new N(2 * r[0], 2 * r[1], 2 * r[2]);
44
+ else if (n === "sphere") i = new P(r[0]);
45
+ else if (n === "cylinder")
46
+ i = new $(r[0], r[0], 2 * r[1]), i.rotateX(Math.PI / 2);
47
+ else if (n === "capsule")
48
+ i = new I(r[0], 2 * r[1]), i.rotateX(Math.PI / 2);
49
+ else if (n === "plane") i = new X(2 * (r[0] || 5), 2 * (r[1] || 5));
50
+ else throw new Error(`MJCF 独立预览暂不支持 geom ${n}`);
51
+ const p = e.getAttribute("material"), o = [...u.querySelectorAll("asset > material")].find((t) => t.getAttribute("name") === p);
52
+ if (p && !o) throw new Error(`Undefined MJCF material: ${p}`);
53
+ if (o != null && o.hasAttribute("texture") || o != null && o.querySelector("layer")) throw new Error("MJCF textured preview requires the compiled material pipeline");
54
+ const x = h(e.getAttribute("rgba"), [0.5, 0.5, 0.5, 1], 4), J = o && x.every((t, d) => t === [0.5, 0.5, 0.5, 1][d]) ? h(o.getAttribute("rgba"), [1, 1, 1, 1], 4) : x, w = (t, d) => o != null && o.hasAttribute(t) ? b(o.getAttribute(t), [d])[0] : d, S = v({
55
+ color: J,
56
+ roughness: o ? E(w("roughness", -1), w("shininess", 0.5)) : E(),
57
+ metalness: Math.max(0, w("metallic", 0)),
58
+ specular: w("specular", 0.5),
59
+ emission: w("emission", 0)
60
+ }), C = new j(i, S);
61
+ n === "plane" && m === l && (C.userData.excludeFromSimulationFit = !0), s.add(C);
62
+ }
63
+ }, A = u.querySelector("worldbody");
64
+ if (!A) throw new Error("MJCF 缺少 worldbody");
65
+ return M(A, l), l.updateMatrixWorld(!0), l;
66
+ } catch (u) {
67
+ throw z(l), u;
68
+ }
69
+ }
70
+ export {
71
+ D as compileMjcfPreview
72
+ };
@@ -0,0 +1,467 @@
1
+ var S = Object.defineProperty;
2
+ var A = (u, t, e) => t in u ? S(u, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[t] = e;
3
+ var p = (u, t, e) => A(u, typeof t != "symbol" ? t + "" : t, e);
4
+ import L from "@mujoco/mujoco";
5
+ import { Quaternion as x, Vector3 as y } from "three";
6
+ import R from "@mujoco/mujoco/mujoco.wasm?url";
7
+ import { i as D } from "./wasm-module-DZn2AM1W.js";
8
+ function B(u) {
9
+ return u ? new URL("mujoco.wasm", u).href : R;
10
+ }
11
+ let C = 0;
12
+ function U(u, t) {
13
+ const e = `/viewer-simulation-${++C}`;
14
+ u.mkdir(e);
15
+ const i = /* @__PURE__ */ new Set([e]), s = /* @__PURE__ */ new Set(), n = (o, r) => {
16
+ const m = o.replaceAll("\\", "/").split("/");
17
+ if (m[0] === "" || m.some((_) => _ === ".." || _.includes(":"))) throw N(`Invalid package path: ${o}`, "E_SIMULATION_PATH");
18
+ const l = m.filter((_) => _ && _ !== ".");
19
+ if (!l.length) throw N("Package path is empty.", "E_SIMULATION_PATH");
20
+ let h = e;
21
+ for (const _ of l.slice(0, -1))
22
+ h += `/${_}`, i.has(h) || (u.mkdir(h), i.add(h));
23
+ const c = `${e}/${l.join("/")}`;
24
+ return u.writeFile(c, r), s.add(c), c;
25
+ }, a = () => {
26
+ for (const o of s) u.unlink(o);
27
+ s.clear();
28
+ for (const o of [...i].reverse()) u.rmdir(o);
29
+ i.clear();
30
+ };
31
+ try {
32
+ for (const [o, r] of t) n(o, r);
33
+ return { writeEntry: (o) => n("__viewer_entry.xml", o), dispose: a };
34
+ } catch (o) {
35
+ throw a(), o;
36
+ }
37
+ }
38
+ function N(u, t) {
39
+ return Object.assign(new Error(u), { code: t });
40
+ }
41
+ function z({
42
+ target: u,
43
+ point: t,
44
+ velocity: e,
45
+ stiffness: i,
46
+ damping: s,
47
+ maxForce: n,
48
+ strength: a
49
+ }) {
50
+ const o = [
51
+ i * (u[0] - t[0]) - s * e[0],
52
+ i * (u[1] - t[1]) - s * e[1],
53
+ i * (u[2] - t[2]) - s * e[2]
54
+ ], r = Math.hypot(o[0], o[1], o[2]), m = n * a;
55
+ if (r > m && r > 0) {
56
+ const l = m / r;
57
+ o[0] *= l, o[1] *= l, o[2] *= l;
58
+ }
59
+ return o;
60
+ }
61
+ const v = 1 / 240, V = 1 / 960, P = 0.25, $ = 0.05, k = 80, Y = 0.7, H = 60, Z = 1e-4, G = 10, J = 3.5, F = 14;
62
+ class et {
63
+ constructor() {
64
+ p(this, "mujoco", null);
65
+ p(this, "model", null);
66
+ p(this, "data", null);
67
+ p(this, "grab", null);
68
+ p(this, "lastGrabForce", [0, 0, 0]);
69
+ p(this, "initialControls", []);
70
+ p(this, "initialJoints", {});
71
+ p(this, "accumulator", 0);
72
+ p(this, "stepTotal", 0);
73
+ p(this, "timestep", v);
74
+ /** Timestep compiled from the physics asset; grabs may temporarily refine it. */
75
+ p(this, "baseTimestep", v);
76
+ /** Authored ground pose, captured before any seating. Re-seats start here. */
77
+ p(this, "initialGround", null);
78
+ /** Ground pose currently in the model; restored verbatim by reset(). */
79
+ p(this, "seatedGround", null);
80
+ p(this, "worldRotation", new x());
81
+ p(this, "topLevelBodies", []);
82
+ p(this, "initialVelocities", []);
83
+ }
84
+ async initialize(t, e = {}) {
85
+ var l;
86
+ const i = e.wasmModule ? await e.wasmModule : void 0;
87
+ this.mujoco ?? (this.mujoco = await L({
88
+ locateFile: (h) => h.endsWith(".wasm") ? B(e.baseUrl) : h,
89
+ ...i ? {
90
+ instantiateWasm(h, c) {
91
+ return D(i, h, c);
92
+ }
93
+ } : {}
94
+ }));
95
+ const s = U(this.mujoco.FS, t.files);
96
+ let n = null, a = null, o = null, r = null, m = v;
97
+ try {
98
+ if (n = this.mujoco.MjModel.from_xml_path(s.writeEntry(t.xml)), m = n.opt.timestep, !Number.isFinite(m) || m <= 0)
99
+ throw new Error(`Invalid MuJoCo timestep: ${m}`);
100
+ for (const c of t.massOverrides ?? []) {
101
+ const _ = this.mujoco.mj_name2id(n, this.mujoco.mjtObj.mjOBJ_BODY.value, c.body);
102
+ if (_ <= 0 || !Number.isFinite(c.mass) || c.mass <= 0 || !(n.body_mass[_] > 0)) throw new Error(`Invalid mass override: ${c.body}`);
103
+ const f = c.mass / n.body_mass[_];
104
+ n.body_mass[_] = c.mass;
105
+ for (let j = 0; j < 3; j++) n.body_inertia[_ * 3 + j] *= f;
106
+ }
107
+ 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);
108
+ const h = this.mujoco.mj_name2id(n, this.mujoco.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
109
+ o = h < 0 ? null : { id: h, height: n.geom_pos[h * 3 + 2], sameFrame: n.geom_sameframe[h] }, r = this.seatDefaultGround(n, a);
110
+ } catch (h) {
111
+ throw a == null || a.delete(), n == null || n.delete(), M(h, "E_MUJOCO_INITIALIZE");
112
+ } finally {
113
+ s.dispose();
114
+ }
115
+ 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);
116
+ }
117
+ get defaultGroundHeight() {
118
+ if (!this.mujoco || !this.model) return;
119
+ const t = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
120
+ return t < 0 ? void 0 : this.model.geom_pos[t * 3 + 2];
121
+ }
122
+ get stepCount() {
123
+ return this.stepTotal;
124
+ }
125
+ /** Pin the viewer-owned floor to a world-frame height, overriding auto-seating. */
126
+ setDefaultGroundHeight(t) {
127
+ if (!Number.isFinite(t) || !this.mujoco || !this.model || !this.data) return !1;
128
+ const e = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
129
+ 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);
130
+ }
131
+ /**
132
+ * Re-orients the compiled physics to the given authored up axis by rotating
133
+ * every top-level body about the world origin. Gravity stays -Z and the
134
+ * viewer ground stays the authored horizontal plane, so a cup that was
135
+ * standing now genuinely topples and settles on its side — the alternative,
136
+ * rotating only the rendered scene graph, would leave the visuals and the
137
+ * simulation in different frames.
138
+ *
139
+ * The full current state (free-joint positions, orientations and velocities)
140
+ * is rotated by the same delta, so a paused or running simulation is carried
141
+ * over instead of being re-seeded.
142
+ */
143
+ setWorldRotation(t) {
144
+ var n;
145
+ if (!this.mujoco || !this.model || !this.data) return;
146
+ const e = this.model, i = this.data;
147
+ if (t.equals(this.worldRotation)) return;
148
+ const s = t.clone().multiply(this.worldRotation.clone().invert());
149
+ 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;
150
+ }
151
+ captureTopLevelBodies(t) {
152
+ const e = this.mujoco, i = [];
153
+ for (let s = 1; s < t.nbody; s++) {
154
+ if (t.body_parentid[s] !== 0) continue;
155
+ 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;
156
+ i.push({
157
+ id: s,
158
+ position: new y(t.body_pos[o], t.body_pos[o + 1], t.body_pos[o + 2]),
159
+ quaternion: new x(t.body_quat[r + 1], t.body_quat[r + 2], t.body_quat[r + 3], t.body_quat[r]),
160
+ freeJoint: a
161
+ });
162
+ }
163
+ return i;
164
+ }
165
+ /** Writes the rotated reference pose, which reset() and fixed bases follow. */
166
+ rotateReferenceFrames(t, e) {
167
+ const i = this.model;
168
+ for (const s of t) {
169
+ const n = s.position.clone().applyQuaternion(e), a = e.clone().multiply(s.quaternion), o = s.id * 3, r = s.id * 4;
170
+ 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;
171
+ const m = i.jnt_qposadr[s.freeJoint];
172
+ 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;
173
+ }
174
+ }
175
+ /** Rotates the live free-joint state so the simulation keeps its progress. */
176
+ rotateState(t, e, i, s) {
177
+ for (const n of t) {
178
+ if (n.freeJoint < 0) continue;
179
+ 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);
180
+ i.qpos[a] = r.x, i.qpos[a + 1] = r.y, i.qpos[a + 2] = r.z;
181
+ const m = new x(i.qpos[a + 4], i.qpos[a + 5], i.qpos[a + 6], i.qpos[a + 3]).premultiply(s);
182
+ i.qpos[a + 3] = m.w, i.qpos[a + 4] = m.x, i.qpos[a + 5] = m.y, i.qpos[a + 6] = m.z;
183
+ const l = new y(i.qvel[o], i.qvel[o + 1], i.qvel[o + 2]).applyQuaternion(s);
184
+ i.qvel[o] = l.x, i.qvel[o + 1] = l.y, i.qvel[o + 2] = l.z;
185
+ const h = new y(i.qvel[o + 3], i.qvel[o + 4], i.qvel[o + 5]).applyQuaternion(s);
186
+ i.qvel[o + 3] = h.x, i.qvel[o + 4] = h.y, i.qvel[o + 5] = h.z;
187
+ }
188
+ }
189
+ /** Lower only the viewer-owned plane, never authored bodies or authored floors.
190
+ * Run after forward kinematics, not during stepping (the floor must not follow falling bodies).
191
+ * `baseHeight` re-seats from a stable reference; omitting it lowers from the current pose.
192
+ */
193
+ seatDefaultGround(t, e, i) {
194
+ const s = this.mujoco, n = s.mj_name2id(t, s.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
195
+ if (n < 0 || t.geom_bodyid[n] !== 0 || t.geom_type[n] !== s.mjtGeom.mjGEOM_PLANE.value) return null;
196
+ let a = i ?? t.geom_pos[n * 3 + 2];
197
+ for (let o = 0; o < t.ngeom; o++) {
198
+ 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;
199
+ const r = this.geomBottom(t, e, o), m = Math.max(1e-3, t.geom_margin[o] + t.geom_margin[n]);
200
+ Number.isFinite(r) && r < a && (a = Math.min(a, r - m));
201
+ }
202
+ 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] };
203
+ }
204
+ /**
205
+ * Resolve the lowest world-space point directly from MuJoCo's primitive
206
+ * parameters. Rotating a mesh's local AABB into world space is conservative:
207
+ * for a long, rotated shape it can sit far below the actual geometry. Use the
208
+ * compiled vertices for mesh-backed geoms so the ground reflects the real
209
+ * lowest point rather than the corners of its local bounding box.
210
+ */
211
+ geomBottom(t, e, i) {
212
+ 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]);
213
+ if (r === s.mjtGeom.mjGEOM_SPHERE.value)
214
+ return n - m;
215
+ if (r === s.mjtGeom.mjGEOM_CAPSULE.value)
216
+ return n - m - Math.abs(e.geom_xmat[o + 8]) * l;
217
+ if (r === s.mjtGeom.mjGEOM_CYLINDER.value) {
218
+ const d = e.geom_xmat[o + 8];
219
+ return n - Math.abs(d) * l - Math.sqrt(Math.max(0, 1 - d * d)) * m;
220
+ }
221
+ if (r === s.mjtGeom.mjGEOM_ELLIPSOID.value)
222
+ return n - Math.hypot(
223
+ e.geom_xmat[o + 2] * m,
224
+ e.geom_xmat[o + 5] * l,
225
+ e.geom_xmat[o + 8] * h
226
+ );
227
+ if (r === s.mjtGeom.mjGEOM_BOX.value)
228
+ 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;
229
+ if (r === s.mjtGeom.mjGEOM_MESH.value || r === s.mjtGeom.mjGEOM_SDF.value) {
230
+ const d = t.geom_dataid[i];
231
+ if (d < 0 || d >= t.nmesh) return Number.POSITIVE_INFINITY;
232
+ const E = t.mesh_vertadr[d], T = t.mesh_vertnum[d];
233
+ if (!Number.isInteger(E) || !Number.isInteger(T) || E < 0 || T <= 0 || E + T > t.nmeshvert)
234
+ return Number.POSITIVE_INFINITY;
235
+ let I = Number.POSITIVE_INFINITY;
236
+ for (let O = E; O < E + T; O++) {
237
+ const w = O * 3, q = n + e.geom_xmat[o + 6] * t.mesh_vert[w] + e.geom_xmat[o + 7] * t.mesh_vert[w + 1] + e.geom_xmat[o + 8] * t.mesh_vert[w + 2];
238
+ Number.isFinite(q) && q < I && (I = q);
239
+ }
240
+ return I;
241
+ }
242
+ const c = i * 6, _ = t.geom_aabb[c + 3], f = t.geom_aabb[c + 4], j = t.geom_aabb[c + 5];
243
+ if (![_, f, j].every((d) => Number.isFinite(d) && d >= 0))
244
+ return Number.POSITIVE_INFINITY;
245
+ 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]) * _ + Math.abs(e.geom_xmat[o + 7]) * f + Math.abs(e.geom_xmat[o + 8]) * j;
246
+ return b - g;
247
+ }
248
+ beginGrab({
249
+ bodyId: t,
250
+ localPoint: e,
251
+ target: i,
252
+ stiffness: s,
253
+ damping: n,
254
+ maxForce: a,
255
+ dampingRatio: o = Y,
256
+ maxTargetSpeed: r = J,
257
+ targetResponse: m = F
258
+ }) {
259
+ var j, b, g;
260
+ const l = Math.max(((j = this.model) == null ? void 0 : j.body_mass[t]) ?? 1, 1e-6);
261
+ if ((b = this.data) != null && b.body_awake && (this.data.body_awake[t] = 1), (g = this.data) != null && g.tree_awake && this.model) {
262
+ const d = this.model.body_rootid[t] ?? t;
263
+ this.data.tree_awake[d] = 1;
264
+ }
265
+ const h = s ?? k, c = n ?? 2 * Math.sqrt(h * l) * o, _ = a ?? Math.max(Z, l * H);
266
+ this.setTimestep(this.grabTimestep(t, e, l, h));
267
+ const f = [i[0], i[1], i[2]];
268
+ this.grab = {
269
+ bodyId: t,
270
+ localPoint: [e[0], e[1], e[2]],
271
+ target: [...f],
272
+ requestedTarget: f,
273
+ stiffness: h,
274
+ damping: c,
275
+ maxForce: _,
276
+ strength: 1,
277
+ maxTargetSpeed: r,
278
+ targetResponse: m
279
+ };
280
+ }
281
+ updateGrabTarget(t) {
282
+ this.grab && (this.grab.requestedTarget = [t[0], t[1], t[2]]);
283
+ }
284
+ updateGrabStrength(t) {
285
+ this.grab && (this.grab.strength = t);
286
+ }
287
+ applyGrabForce() {
288
+ if (!this.grab || !this.model || !this.data || !this.mujoco) return;
289
+ 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 = [
290
+ m[0] + r[0] * e[0] + r[1] * e[1] + r[2] * e[2],
291
+ m[1] + r[3] * e[0] + r[4] * e[1] + r[5] * e[2],
292
+ m[2] + r[6] * e[0] + r[7] * e[1] + r[8] * e[2]
293
+ ], h = this.data.cvel.subarray(t * 6, t * 6 + 6), c = this.data.xipos.subarray(t * 3, t * 3 + 3), _ = [
294
+ l[0] - c[0],
295
+ l[1] - c[1],
296
+ l[2] - c[2]
297
+ ], f = [
298
+ h[3] + h[1] * _[2] - h[2] * _[1],
299
+ h[4] + h[2] * _[0] - h[0] * _[2],
300
+ h[5] + h[0] * _[1] - h[1] * _[0]
301
+ ], j = z({ target: i, point: l, velocity: f, stiffness: s, damping: n, maxForce: a, strength: o });
302
+ this.lastGrabForce = [...j], this.data.qfrc_applied.fill(0);
303
+ const b = Math.min(
304
+ Math.max(this.model.body_inertia[t * 3], 1e-9),
305
+ Math.max(this.model.body_inertia[t * 3 + 1], 1e-9),
306
+ Math.max(this.model.body_inertia[t * 3 + 2], 1e-9)
307
+ ), g = [
308
+ -b * G * h[0],
309
+ -b * G * h[1],
310
+ -b * G * h[2]
311
+ ];
312
+ this.mujoco.mj_applyFT(
313
+ this.model,
314
+ this.data,
315
+ j,
316
+ g,
317
+ l,
318
+ t,
319
+ this.data.qfrc_applied
320
+ );
321
+ }
322
+ endGrab() {
323
+ this.data && this.data.qfrc_applied.fill(0), this.lastGrabForce = [0, 0, 0], this.grab = null, this.setTimestep(this.baseTimestep);
324
+ }
325
+ step(t) {
326
+ if (!this.mujoco || !this.model || !this.data || t <= 0) return !1;
327
+ this.accumulator += Math.min(t, $);
328
+ let e = !1;
329
+ for (; this.accumulator >= this.timestep; )
330
+ this.updateGrabTargetForStep(), this.applyGrabForce(), this.mujoco.mj_step(this.model, this.data), this.stepTotal += 1, this.accumulator -= this.timestep, e = !0;
331
+ return e;
332
+ }
333
+ updateGrabTargetForStep() {
334
+ const t = this.grab;
335
+ if (!t) return;
336
+ 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;
337
+ for (let o = 0; o < 3; o++) {
338
+ const r = e[o] - t.target[o], m = Math.sign(r) * Math.min(Math.abs(r) * n, a);
339
+ t.target[o] += m;
340
+ }
341
+ }
342
+ setJointValues(t) {
343
+ if (!(!this.mujoco || !this.model || !this.data)) {
344
+ for (const [e, i] of Object.entries(t)) {
345
+ const s = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_JOINT.value, e);
346
+ if (s < 0 || !Number.isFinite(i)) continue;
347
+ const n = this.model.jnt_type[s], a = this.mujoco.mjtJoint.mjJNT_HINGE.value, o = this.mujoco.mjtJoint.mjJNT_SLIDE.value;
348
+ n !== a && n !== o || (this.data.qpos[this.model.jnt_qposadr[s]] = i);
349
+ }
350
+ this.mujoco.mj_forward(this.model, this.data), this.seatDefaultGround(this.model, this.data), this.accumulator = 0;
351
+ }
352
+ }
353
+ getJointValues(t) {
354
+ const e = {};
355
+ if (!this.mujoco || !this.model || !this.data) return e;
356
+ for (const i of t) {
357
+ const s = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_JOINT.value, i);
358
+ if (s < 0) continue;
359
+ const n = this.model.jnt_type[s], a = this.mujoco.mjtJoint.mjJNT_HINGE.value, o = this.mujoco.mjtJoint.mjJNT_SLIDE.value;
360
+ (n === a || n === o) && (e[i] = this.data.qpos[this.model.jnt_qposadr[s]]);
361
+ }
362
+ return e;
363
+ }
364
+ reset() {
365
+ if (!(!this.mujoco || !this.model || !this.data)) {
366
+ if (this.endGrab(), this.seatedGround) {
367
+ const { id: t, height: e, sameFrame: i } = this.seatedGround;
368
+ this.model.geom_pos[t * 3 + 2] = e, this.model.geom_sameframe[t] = i;
369
+ }
370
+ 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;
371
+ }
372
+ }
373
+ /**
374
+ * Runs an exact number of fixed-size steps for a deterministic probe. The
375
+ * compiled timestep is restored afterwards so the interactive runtime keeps
376
+ * its authored cadence.
377
+ */
378
+ advanceFixed(t, e) {
379
+ if (!this.mujoco || !this.model || !this.data || !Number.isFinite(t) || t <= 0 || !Number.isInteger(e) || e <= 0) return !1;
380
+ const i = this.timestep;
381
+ try {
382
+ this.setTimestep(t);
383
+ for (let s = 0; s < e; s += 1)
384
+ this.mujoco.mj_step(this.model, this.data), this.stepTotal += 1;
385
+ return this.accumulator = 0, !0;
386
+ } finally {
387
+ this.setTimestep(this.grab ? i : this.baseTimestep);
388
+ }
389
+ }
390
+ dispose() {
391
+ this.disposeModel(), this.mujoco = null;
392
+ }
393
+ applyInitialControls(t, e) {
394
+ if (e != null && e.length) {
395
+ 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");
396
+ t.ctrl.set(e);
397
+ }
398
+ }
399
+ applyCenterOfMassOverrides(t, e) {
400
+ for (const i of e ?? []) {
401
+ const s = this.mujoco.mj_name2id(
402
+ t,
403
+ this.mujoco.mjtObj.mjOBJ_BODY.value,
404
+ i.body
405
+ );
406
+ if (s <= 0 || i.position.length !== 3 || !i.position.every(Number.isFinite))
407
+ throw M(
408
+ new Error(`Invalid center-of-mass override: ${i.body}`),
409
+ "E_MUJOCO_INITIALIZE"
410
+ );
411
+ t.body_ipos.set(i.position, s * 3);
412
+ }
413
+ }
414
+ /**
415
+ * A point force on a light body can excite a much higher rotational
416
+ * frequency than its translational mass suggests. Refine physics only while
417
+ * that body is grabbed instead of adding global damping to hide the error.
418
+ */
419
+ grabTimestep(t, e, i, s) {
420
+ if (!this.model || !this.data) return v;
421
+ const n = Math.min(
422
+ Math.max(this.model.body_inertia[t * 3], 1e-9),
423
+ Math.max(this.model.body_inertia[t * 3 + 1], 1e-9),
424
+ Math.max(this.model.body_inertia[t * 3 + 2], 1e-9)
425
+ ), 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 = [
426
+ a[0] + r[0] * e[0] + r[1] * e[1] + r[2] * e[2],
427
+ a[1] + r[3] * e[0] + r[4] * e[1] + r[5] * e[2],
428
+ a[2] + r[6] * e[0] + r[7] * e[1] + r[8] * e[2]
429
+ ], 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 = P / Math.max(h, 1e-9);
430
+ return Math.min(this.baseTimestep, Math.max(V, c));
431
+ }
432
+ setTimestep(t) {
433
+ var e;
434
+ this.timestep = t, (e = this.model) != null && e.opt && (this.model.opt.timestep = t);
435
+ }
436
+ applyInitialJoints(t, e, i = {}) {
437
+ const s = this.mujoco;
438
+ for (const [n, a] of Object.entries(i)) {
439
+ const o = s.mj_name2id(t, s.mjtObj.mjOBJ_JOINT.value, n);
440
+ 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");
441
+ e.qpos[t.jnt_qposadr[o]] = a;
442
+ }
443
+ }
444
+ applyInitialVelocities(t, e, i) {
445
+ for (const s of i ?? []) {
446
+ if (s.velocity.length !== 6 || !s.velocity.every(Number.isFinite))
447
+ throw M(new Error(`Invalid free-body initial velocity: ${s.body}`), "E_MUJOCO_INITIALIZE");
448
+ if (s.velocity.every((l) => Math.abs(l) <= 1e-12)) continue;
449
+ const n = this.mujoco.mj_name2id(t, this.mujoco.mjtObj.mjOBJ_BODY.value, s.body), a = n >= 0 ? t.body_jntadr[n] : -1;
450
+ if (a < 0 || t.jnt_type[a] !== this.mujoco.mjtJoint.mjJNT_FREE.value)
451
+ throw M(new Error(`Invalid free-body initial velocity: ${s.body}`), "E_MUJOCO_INITIALIZE");
452
+ 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);
453
+ e.qvel.set([r.x, r.y, r.z, m.x, m.y, m.z], t.jnt_dofadr[a]);
454
+ }
455
+ }
456
+ disposeModel() {
457
+ var t, e;
458
+ 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;
459
+ }
460
+ }
461
+ function M(u, t) {
462
+ const e = u instanceof Error ? u : new Error(String(u));
463
+ return Object.assign(e, { code: t });
464
+ }
465
+ export {
466
+ et as MujocoRuntime
467
+ };
@@ -0,0 +1,11 @@
1
+ /** Content-addressed bytes used by IndexedDB and scene ZIP persistence. */
2
+ import type { SceneDocument } from '../doc/schema';
3
+ import type { StudioSourceBundle } from '../util/studio-source';
4
+ export interface ContentAddressedResource {
5
+ readonly sha256: string;
6
+ readonly mediaType: string;
7
+ readonly blob: Blob;
8
+ }
9
+ export declare function createContentAddressedResources(document: SceneDocument, sourceByRevisionId: ReadonlyMap<string, StudioSourceBundle>): Promise<readonly ContentAddressedResource[]>;
10
+ export declare function verifyContentAddressedResources(resources: readonly ContentAddressedResource[]): Promise<readonly ContentAddressedResource[]>;
11
+ export declare function sourceBundlesFromContentStore(document: SceneDocument, resources: readonly ContentAddressedResource[]): readonly StudioSourceBundle[];
@@ -0,0 +1,7 @@
1
+ import type { EditorialStateV1, ScenePackageArtifact, ScenePackageHostSource, ScenePackageInput, ScenePackageReadPorts } from '../project/contracts';
2
+ export declare function createScenePackageFromHost(host: ScenePackageHostSource, input: {
3
+ readonly editorial: EditorialStateV1;
4
+ readonly assetCatalog: ScenePackageInput['assetCatalog'];
5
+ readonly resourceManifest: ScenePackageInput['resourceManifest'];
6
+ readonly resources?: ScenePackageInput['resources'];
7
+ }, ports?: ScenePackageReadPorts): Promise<ScenePackageArtifact>;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * IndexedDB storage for canonical scene state and content-addressed resources.
3
+ * Scene state and resource bytes have separate contracts so local storage can
4
+ * implement the same boundaries as a remote asset platform.
5
+ */
6
+ import { type ContentAddressedResource } from './content-addressed';
7
+ import type { StudioStateSnapshot } from './snapshot';
8
+ import type { StudioAssetResourceLocator } from '../doc/schema';
9
+ export interface IndexedDbStudioStoreOptions {
10
+ readonly dbName?: string;
11
+ readonly indexedDB?: IDBFactory;
12
+ }
13
+ export declare const INDEXED_DB_STUDIO_NAME = "sim-studio.indexeddb";
14
+ export declare const INDEXED_DB_STUDIO_VERSION = 3;
15
+ export declare const INDEXED_DB_DOCUMENT_STORE = "documents";
16
+ export declare const INDEXED_DB_RESOURCE_STORE = "resources";
17
+ export declare const INDEXED_DB_SOURCE_STORE = "asset-sources";
18
+ export declare const INDEXED_DB_STORE_ERROR: {
19
+ readonly unavailable: "INDEXED_DB_STORE_UNAVAILABLE";
20
+ readonly openFailed: "INDEXED_DB_STORE_OPEN_FAILED";
21
+ readonly readFailed: "INDEXED_DB_STORE_READ_FAILED";
22
+ readonly writeFailed: "INDEXED_DB_STORE_WRITE_FAILED";
23
+ readonly invalidSnapshot: "INDEXED_DB_STORE_INVALID_SNAPSHOT";
24
+ readonly unsupportedFormat: "INDEXED_DB_STORE_UNSUPPORTED_FORMAT";
25
+ };
26
+ export declare class IndexedDbStoreError extends Error {
27
+ readonly code: string;
28
+ readonly cause?: unknown;
29
+ constructor(code: string, message: string, cause?: unknown);
30
+ }
31
+ export interface IndexedDbAssetSourceFile {
32
+ readonly locator: StudioAssetResourceLocator;
33
+ readonly mediaType?: string;
34
+ readonly byteSize?: number;
35
+ readonly sha256: string;
36
+ readonly blobSha256: string;
37
+ }
38
+ export interface IndexedDbLocalAssetSourceRecord {
39
+ readonly kind: 'local-package';
40
+ readonly revisionId: string;
41
+ readonly entryPath: string;
42
+ readonly files: readonly IndexedDbAssetSourceFile[];
43
+ }
44
+ export interface IndexedDbRemoteAssetSourceRecord {
45
+ readonly kind: 'remote-entry';
46
+ readonly revisionId: string;
47
+ readonly entryUrl: string;
48
+ readonly allowedScopes?: readonly {
49
+ readonly origin: string;
50
+ readonly pathPrefix: string;
51
+ }[];
52
+ }
53
+ export type IndexedDbAssetSourceRecord = IndexedDbLocalAssetSourceRecord | IndexedDbRemoteAssetSourceRecord;
54
+ export declare class IndexedDbStudioStore {
55
+ private readonly dbName;
56
+ private readonly factory;
57
+ private db;
58
+ private opening;
59
+ constructor(options?: IndexedDbStudioStoreOptions);
60
+ load(): Promise<StudioStateSnapshot | null>;
61
+ save(snapshot: StudioStateSnapshot): Promise<void>;
62
+ loadResources(hashes: readonly string[]): Promise<readonly ContentAddressedResource[]>;
63
+ saveResources(resources: readonly ContentAddressedResource[]): Promise<void>;
64
+ loadAssetSource(revisionId: string): Promise<IndexedDbAssetSourceRecord | null>;
65
+ saveAssetSource(source: IndexedDbAssetSourceRecord): Promise<void>;
66
+ deleteAssetSource(revisionId: string): Promise<void>;
67
+ close(): void;
68
+ private open;
69
+ }