@nebula-spatial/studio 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) 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/usd-export-worker-BsGubtAE.js +1 -0
  23. package/dist/builders-BAXRR5o5.js +1854 -0
  24. package/dist/core/asset-task.d.ts +105 -0
  25. package/dist/core/context.d.ts +23 -0
  26. package/dist/core/host.d.ts +432 -0
  27. package/dist/core/persistence-controller.d.ts +58 -0
  28. package/dist/core/plugins.d.ts +139 -0
  29. package/dist/core/scene-tree.d.ts +62 -0
  30. package/dist/core/versions.d.ts +2 -0
  31. package/dist/core/when.d.ts +13 -0
  32. package/dist/core/write-policy.d.ts +29 -0
  33. package/dist/delivery/build-plan.d.ts +2 -0
  34. package/dist/delivery/contracts.d.ts +362 -0
  35. package/dist/delivery/digest.d.ts +3 -0
  36. package/dist/delivery/evidence.d.ts +10 -0
  37. package/dist/delivery/export-evidence.d.ts +3 -0
  38. package/dist/delivery/index.d.ts +9 -0
  39. package/dist/delivery/prim-name.d.ts +17 -0
  40. package/dist/delivery/profile.d.ts +4 -0
  41. package/dist/doc/builders.d.ts +99 -0
  42. package/dist/doc/command.d.ts +195 -0
  43. package/dist/doc/domain-extensions.d.ts +34 -0
  44. package/dist/doc/node-facts.d.ts +87 -0
  45. package/dist/doc/physics-facts.d.ts +74 -0
  46. package/dist/doc/placement-policy.d.ts +71 -0
  47. package/dist/doc/random-placement.d.ts +30 -0
  48. package/dist/doc/scene-graph.d.ts +80 -0
  49. package/dist/doc/scene-regions.d.ts +29 -0
  50. package/dist/doc/schema.d.ts +452 -0
  51. package/dist/doc/task.d.ts +71 -0
  52. package/dist/doc/validate.d.ts +68 -0
  53. package/dist/editor/asset-source.d.ts +15 -0
  54. package/dist/editor/editor.d.ts +246 -0
  55. package/dist/editor/index.d.ts +22 -0
  56. package/dist/editor/shortcuts.d.ts +2 -0
  57. package/dist/editor/types.d.ts +143 -0
  58. package/dist/editor/ui-plugins.d.ts +64 -0
  59. package/dist/editor.js +1755 -0
  60. package/dist/editorial-BkAFWfbg.js +83 -0
  61. package/dist/export-evidence-B_0zRmb8.js +5027 -0
  62. package/dist/generalization/domain.d.ts +10 -0
  63. package/dist/generalization/generalization.d.ts +371 -0
  64. package/dist/generalization/index.d.ts +11 -0
  65. package/dist/generalization.js +1659 -0
  66. package/dist/history/undo-stack.d.ts +74 -0
  67. package/dist/index.d.ts +91 -0
  68. package/dist/index.js +2839 -0
  69. package/dist/persist/content-addressed.d.ts +11 -0
  70. package/dist/persist/create-scene-package-from-host.d.ts +7 -0
  71. package/dist/persist/indexeddb-store.d.ts +69 -0
  72. package/dist/persist/scene-file.d.ts +52 -0
  73. package/dist/persist/scene-package.d.ts +8 -0
  74. package/dist/persist/snapshot.d.ts +5 -0
  75. package/dist/physics-facts-tfQYyNTD.js +337 -0
  76. package/dist/placement-policy-DY_FNRDu.js +405 -0
  77. package/dist/ports/asset-ingestor.d.ts +41 -0
  78. package/dist/ports/asset-source.d.ts +57 -0
  79. package/dist/ports/delivery.d.ts +13 -0
  80. package/dist/ports/persistence.d.ts +29 -0
  81. package/dist/project/asset-catalog.d.ts +21 -0
  82. package/dist/project/contracts.d.ts +272 -0
  83. package/dist/project/editorial.d.ts +16 -0
  84. package/dist/project/identity.d.ts +20 -0
  85. package/dist/project/index.d.ts +9 -0
  86. package/dist/project/scene-document.d.ts +5 -0
  87. package/dist/project/source-dependencies.d.ts +7 -0
  88. package/dist/remote-asset-resolver-Cb8cfNmw.js +136 -0
  89. package/dist/scene/index.d.ts +12 -0
  90. package/dist/scene-graph-DBLKAhxa.js +681 -0
  91. package/dist/scene-session-BV1HnxNh.js +3506 -0
  92. package/dist/scene.js +244 -0
  93. package/dist/studio/delivery-catalog.d.ts +28 -0
  94. package/dist/studio/in-memory-asset-source.d.ts +15 -0
  95. package/dist/studio/index.d.ts +31 -0
  96. package/dist/studio/indexeddb-asset-source.d.ts +32 -0
  97. package/dist/studio/indexeddb-persistence.d.ts +13 -0
  98. package/dist/studio/remote-asset-importer.d.ts +56 -0
  99. package/dist/studio/source-package.d.ts +9 -0
  100. package/dist/studio/usd-export-client.d.ts +13 -0
  101. package/dist/studio/usd-export-protocol.d.ts +98 -0
  102. package/dist/studio/usd-export-worker.d.ts +1 -0
  103. package/dist/studio/usd-zip-reader.d.ts +14 -0
  104. package/dist/studio/web-asset-ingestor.d.ts +10 -0
  105. package/dist/studio/web-host.d.ts +8 -0
  106. package/dist/studio.js +5544 -0
  107. package/dist/util/asset-facts.d.ts +3 -0
  108. package/dist/util/data.d.ts +17 -0
  109. package/dist/util/diagnostics.d.ts +38 -0
  110. package/dist/util/geometry.d.ts +11 -0
  111. package/dist/util/hash.d.ts +9 -0
  112. package/dist/util/ids.d.ts +20 -0
  113. package/dist/util/math.d.ts +47 -0
  114. package/dist/util/ply-metadata.d.ts +19 -0
  115. package/dist/util/studio-source.d.ts +23 -0
  116. package/dist/version.d.ts +5 -0
  117. package/dist/view/appearance.d.ts +13 -0
  118. package/dist/view/authoring-appearance.d.ts +25 -0
  119. package/dist/view/bounds-preview.d.ts +34 -0
  120. package/dist/view/bounds.d.ts +11 -0
  121. package/dist/view/camera-zoom.d.ts +3 -0
  122. package/dist/view/geometry-anchors.d.ts +20 -0
  123. package/dist/view/gizmo-appearance.d.ts +5 -0
  124. package/dist/view/gizmo.d.ts +81 -0
  125. package/dist/view/group-selection.d.ts +13 -0
  126. package/dist/view/node-features.d.ts +39 -0
  127. package/dist/view/picking.d.ts +49 -0
  128. package/dist/view/placement.d.ts +48 -0
  129. package/dist/view/region-editing.d.ts +25 -0
  130. package/dist/view/rotation-guide.d.ts +36 -0
  131. package/dist/view/runtime-capabilities.d.ts +22 -0
  132. package/dist/view/scene-session.d.ts +258 -0
  133. package/dist/view/screen-bounds.d.ts +17 -0
  134. package/dist/view/selection-transform.d.ts +20 -0
  135. package/node_modules/@nebula-spatial/cad-loader/CHANGELOG.md +48 -0
  136. package/node_modules/@nebula-spatial/cad-loader/README.md +108 -0
  137. package/node_modules/@nebula-spatial/cad-loader/dist/core/cad-types.d.ts +26 -0
  138. package/node_modules/@nebula-spatial/cad-loader/dist/core/errors.d.ts +5 -0
  139. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.d.ts +24 -0
  140. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.js +2354 -0
  141. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-group-reader.d.ts +9 -0
  142. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-parser.d.ts +78 -0
  143. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/dxbs-sidecar.d.ts +24 -0
  144. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/geometry-segments.d.ts +20 -0
  145. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/text-roundtrip.d.ts +4 -0
  146. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/types.d.ts +81 -0
  147. package/node_modules/@nebula-spatial/cad-loader/dist/core/runtime-text-decoder.d.ts +8 -0
  148. package/node_modules/@nebula-spatial/cad-loader/dist/core/types.d.ts +153 -0
  149. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/insert-bbox.d.ts +10 -0
  150. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/viewport-rect.d.ts +21 -0
  151. package/node_modules/@nebula-spatial/cad-loader/dist/index.d.ts +36 -0
  152. package/node_modules/@nebula-spatial/cad-loader/dist/index.js +5829 -0
  153. package/node_modules/@nebula-spatial/cad-loader/dist/loader/geo-loader.d.ts +59 -0
  154. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/automatic-external-resources.d.ts +26 -0
  155. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/external-variant-sidecar-fetch.d.ts +13 -0
  156. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/flow-control.d.ts +29 -0
  157. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/frame-budget-scheduler.d.ts +21 -0
  158. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-compact-executor.d.ts +19 -0
  159. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-local-adapter.d.ts +2 -0
  160. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-pipeline.d.ts +92 -0
  161. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-worker-adapter.d.ts +13 -0
  162. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-builder.d.ts +34 -0
  163. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-load-sink.d.ts +28 -0
  164. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node.d.ts +304 -0
  165. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare-worker-types.d.ts +94 -0
  166. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.d.ts +38 -0
  167. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.worker.d.ts +1 -0
  168. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-model-builder.d.ts +10 -0
  169. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-runtime-geometry.d.ts +15 -0
  170. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-canonical.d.ts +37 -0
  171. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-quality.d.ts +9 -0
  172. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/prepare-credit-gate.d.ts +20 -0
  173. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/transport.d.ts +2 -0
  174. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/cad-render-node.d.ts +80 -0
  175. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/geo-node-cad-render-node.d.ts +12 -0
  176. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-geometry.d.ts +28 -0
  177. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-material.d.ts +18 -0
  178. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/block-geometry-registry.d.ts +35 -0
  179. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/insert-instance-table.d.ts +23 -0
  180. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/viewport-instance-presenter.d.ts +66 -0
  181. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-insert-selection.d.ts +35 -0
  182. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-text-selection.d.ts +31 -0
  183. package/node_modules/@nebula-spatial/cad-loader/dist/session/annotation-idle-gate.d.ts +14 -0
  184. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-document-session.d.ts +187 -0
  185. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-font-runtime.d.ts +11 -0
  186. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-insert-id.d.ts +6 -0
  187. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-text-warmup.d.ts +38 -0
  188. package/node_modules/@nebula-spatial/cad-loader/dist/session/create-cad-document-session.d.ts +5 -0
  189. package/node_modules/@nebula-spatial/cad-loader/dist/session/load-session.d.ts +90 -0
  190. package/node_modules/@nebula-spatial/cad-loader/dist/session/viewport-coverage.d.ts +32 -0
  191. package/node_modules/@nebula-spatial/cad-loader/dist/shared/abort.d.ts +3 -0
  192. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-display-color.d.ts +55 -0
  193. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-load-source.d.ts +8 -0
  194. package/node_modules/@nebula-spatial/cad-loader/dist/shared/color-buffer.d.ts +6 -0
  195. package/node_modules/@nebula-spatial/cad-loader/dist/shared/constants.d.ts +11 -0
  196. package/node_modules/@nebula-spatial/cad-loader/dist/shared/display-color-buffer.d.ts +27 -0
  197. package/node_modules/@nebula-spatial/cad-loader/dist/shared/errors.d.ts +2 -0
  198. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-builder.d.ts +25 -0
  199. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-font.d.ts +12 -0
  200. package/node_modules/@nebula-spatial/cad-loader/dist/shared/types.d.ts +57 -0
  201. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/insert-bbox.d.ts +1 -0
  202. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/timing.d.ts +2 -0
  203. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/viewport-rect.d.ts +1 -0
  204. package/node_modules/@nebula-spatial/cad-loader/dist/shared/viewer-theme.d.ts +2 -0
  205. package/node_modules/@nebula-spatial/cad-loader/dist/workers/geo-prepare.worker.js +2264 -0
  206. package/node_modules/@nebula-spatial/cad-loader/package.json +62 -0
  207. package/node_modules/@nebula-spatial/viewer/CHANGELOG.md +426 -0
  208. package/node_modules/@nebula-spatial/viewer/FBX-MATERIAL-CONVERSION.md +97 -0
  209. package/node_modules/@nebula-spatial/viewer/README.md +1056 -0
  210. package/node_modules/@nebula-spatial/viewer/USD-VISUAL-MATERIAL-SUPPORT.md +89 -0
  211. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.js +19 -0
  212. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.wasm +0 -0
  213. package/node_modules/@nebula-spatial/viewer/dist/asset-ir-DEOK9SqE.js +382 -0
  214. package/node_modules/@nebula-spatial/viewer/dist/assets/ground-grid.d.ts +6 -0
  215. package/node_modules/@nebula-spatial/viewer/dist/assets/source-types.d.ts +19 -0
  216. package/node_modules/@nebula-spatial/viewer/dist/assets/types.d.ts +393 -0
  217. package/node_modules/@nebula-spatial/viewer/dist/assets/usd-worker-Bom5cjz3.js +1392 -0
  218. package/node_modules/@nebula-spatial/viewer/dist/cad/text.d.ts +2 -0
  219. package/node_modules/@nebula-spatial/viewer/dist/cad/types.d.ts +368 -0
  220. package/node_modules/@nebula-spatial/viewer/dist/index-ByBlfVc0.js +12132 -0
  221. package/node_modules/@nebula-spatial/viewer/dist/index.d.ts +32 -0
  222. package/node_modules/@nebula-spatial/viewer/dist/index.js +26 -0
  223. package/node_modules/@nebula-spatial/viewer/dist/inspection/types.d.ts +112 -0
  224. package/node_modules/@nebula-spatial/viewer/dist/mjcf-visual-DVRa0w90.js +72 -0
  225. package/node_modules/@nebula-spatial/viewer/dist/mujoco-runtime-Dhx6Ua2u.js +463 -0
  226. package/node_modules/@nebula-spatial/viewer/dist/plugins.d.ts +179 -0
  227. package/node_modules/@nebula-spatial/viewer/dist/scene/instances.d.ts +36 -0
  228. package/node_modules/@nebula-spatial/viewer/dist/scene/types.d.ts +258 -0
  229. package/node_modules/@nebula-spatial/viewer/dist/session-B-j6KdA-.js +389 -0
  230. package/node_modules/@nebula-spatial/viewer/dist/session-B4AICTeJ.js +963 -0
  231. package/node_modules/@nebula-spatial/viewer/dist/session-BAG5cDYe.js +9153 -0
  232. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-runtime.d.ts +118 -0
  233. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-wasm-module.d.ts +11 -0
  234. package/node_modules/@nebula-spatial/viewer/dist/simulation/openusd-wasm-module.d.ts +10 -0
  235. package/node_modules/@nebula-spatial/viewer/dist/simulation/physics-runtime-state.d.ts +75 -0
  236. package/node_modules/@nebula-spatial/viewer/dist/simulation/types.d.ts +129 -0
  237. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-inspection.d.ts +66 -0
  238. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-query.d.ts +50 -0
  239. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-resource-policy.d.ts +28 -0
  240. package/node_modules/@nebula-spatial/viewer/dist/types.d.ts +278 -0
  241. package/node_modules/@nebula-spatial/viewer/dist/ui/types.d.ts +48 -0
  242. package/node_modules/@nebula-spatial/viewer/dist/urdf-session-kemAnBn8.js +3231 -0
  243. package/node_modules/@nebula-spatial/viewer/dist/usd-session-QtwGKI7v.js +6771 -0
  244. package/node_modules/@nebula-spatial/viewer/dist/version.d.ts +5 -0
  245. package/node_modules/@nebula-spatial/viewer/dist/viewer.d.ts +2 -0
  246. package/node_modules/@nebula-spatial/viewer/dist/xacro-CYTPS7mh.js +1537 -0
  247. package/node_modules/@nebula-spatial/viewer/openusd/openusd-runtime-manifest.json +15 -0
  248. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.js +14 -0
  249. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.wasm +0 -0
  250. package/node_modules/@nebula-spatial/viewer/package.json +66 -0
  251. package/package.json +87 -6
@@ -0,0 +1,3506 @@
1
+ var ji = Object.defineProperty;
2
+ var Li = (n, a, l) => a in n ? ji(n, a, { enumerable: !0, configurable: !0, writable: !0, value: l }) : n[a] = l;
3
+ var fe = (n, a, l) => Li(n, typeof a != "symbol" ? a + "" : a, l);
4
+ import { Matrix4 as _e, Vector3 as p, Mesh as Z, InstancedMesh as wn, LinearSRGBColorSpace as Bi, Color as Vo, Quaternion as se, Shape as kr, ShapeGeometry as Ho, BufferGeometry as Ln, RingGeometry as Go, SphereGeometry as $o, Plane as mn, CircleGeometry as Fi, MeshBasicMaterial as pn, TorusGeometry as Zo, DoubleSide as Uo, Box3Helper as Pr, Box3 as K, Object3D as qo, SkinnedMesh as Yi, InterleavedBufferAttribute as _i, Group as ot, SpriteMaterial as So, Raycaster as St, Vector2 as sn, DataTexture as Qo, RGBAFormat as Ko, SRGBColorSpace as Xi, LinearFilter as Bn, Sprite as Ao, LineSegments as an, EdgesGeometry as mr, LineBasicMaterial as Eo, ArrowHelper as Vi, Float32BufferAttribute as Hi, PlaneGeometry as Gi, BoxGeometry as Jo, ExtrudeGeometry as $i, Matrix3 as Zi } from "three";
5
+ import { TransformControls as Po } from "three/examples/jsm/controls/TransformControls.js";
6
+ import { createViewer as Ui, findInstanceId as pr } from "@nebula-spatial/viewer";
7
+ import { w as Co, l as qi, U as Rn, L as Qi, K as Ki, z as ln, a3 as cn, Z as hr, Y as Ye, W as Oo, a0 as ko, k as gr } from "./scene-graph-DBLKAhxa.js";
8
+ import { c as yr, a as Tn, b as Ji, h as Wn } from "./physics-facts-tfQYyNTD.js";
9
+ import { o as Yt, a as it, r as dn, t as es, w as ts, b as Ro, x as ns, S as rs, l as os, j as is, p as ss } from "./placement-policy-DY_FNRDu.js";
10
+ import { LineMaterial as as } from "three/examples/jsm/lines/LineMaterial.js";
11
+ import { LineSegments2 as ls } from "three/examples/jsm/lines/LineSegments2.js";
12
+ import { LineSegmentsGeometry as cs } from "three/examples/jsm/lines/LineSegmentsGeometry.js";
13
+ const ds = Object.freeze({
14
+ median: null,
15
+ surfaceCenterOfMass: null,
16
+ volumeCenterOfMass: null,
17
+ source: "runtime",
18
+ vertexCount: 0,
19
+ triangleCount: 0,
20
+ surfaceAreaM2: 0,
21
+ volumeM3: 0
22
+ });
23
+ function us(n, a) {
24
+ n.updateWorldMatrix(!0, !0);
25
+ const l = new _e().copy(n.matrixWorld).invert(), m = new p().fromArray(a), y = new p(), M = new p(), v = new p();
26
+ let f = 0, x = 0, S = 0, w = 0;
27
+ const E = new p(), j = new p(), k = new p(), T = new p(), b = new p(), C = new p(), B = new p(), ae = new p(), J = new p(), X = new p(), at = new p(), ee = new p(), P = new _e(), lt = new _e();
28
+ if (n.traverseVisible((Ne) => {
29
+ if (!(Ne instanceof Z)) return;
30
+ const De = Ne.geometry, Ee = De.getAttribute("position");
31
+ if (!Ee || Ee.count === 0) return;
32
+ const L = De.getIndex(), Me = Ne instanceof wn ? Ne.count : 1;
33
+ for (let ce = 0; ce < Me; ce += 1) {
34
+ Ne instanceof wn ? (Ne.getMatrixAt(ce, P), lt.multiplyMatrices(l, Ne.matrixWorld).multiply(P)) : lt.multiplyMatrices(l, Ne.matrixWorld);
35
+ const ge = (ne, G) => (ne.fromBufferAttribute(Ee, G).applyMatrix4(lt).add(m), ne);
36
+ for (let ne = 0; ne < Ee.count; ne += 1)
37
+ y.add(ge(E, ne));
38
+ f += Ee.count;
39
+ const Ve = (L == null ? void 0 : L.count) ?? Ee.count, V = Math.floor(Ve / 3);
40
+ for (let ne = 0; ne < V; ne += 1) {
41
+ const G = L ? L.getX(ne * 3) : ne * 3, At = L ? L.getX(ne * 3 + 1) : ne * 3 + 1, I = L ? L.getX(ne * 3 + 2) : ne * 3 + 2;
42
+ ge(E, G), ge(j, At), ge(k, I), T.subVectors(j, E), b.subVectors(k, E);
43
+ const re = C.crossVectors(T, b).length() * 0.5;
44
+ if (!Number.isFinite(re) || re <= 1e-14) continue;
45
+ B.copy(E).add(j).add(k).multiplyScalar(1 / 3), M.addScaledVector(B, re), S += re, ae.subVectors(E, m), J.subVectors(j, m), X.subVectors(k, m);
46
+ const ct = ae.dot(ee.crossVectors(J, X)) / 6;
47
+ Number.isFinite(ct) && (at.copy(ae).add(J).add(X).multiplyScalar(0.25), v.addScaledVector(at, ct), w += ct), x += 1;
48
+ }
49
+ }
50
+ }), f === 0) return ds;
51
+ const Xe = y.multiplyScalar(1 / f).toArray(), xt = S > 1e-14 ? M.multiplyScalar(1 / S).toArray() : null, _t = (Math.abs(w) > 1e-14 ? v.multiplyScalar(1 / w).add(m).toArray() : null) ?? xt ?? Xe;
52
+ return Object.freeze({
53
+ median: wr(Xe),
54
+ surfaceCenterOfMass: wr(xt),
55
+ volumeCenterOfMass: wr(_t),
56
+ source: "runtime",
57
+ vertexCount: f,
58
+ triangleCount: x,
59
+ surfaceAreaM2: S,
60
+ volumeM3: Math.abs(w)
61
+ });
62
+ }
63
+ function wr(n) {
64
+ return n ? Object.freeze([n[0], n[1], n[2]]) : null;
65
+ }
66
+ function To(n, a, l = 1.2) {
67
+ if (!n || !Number.isFinite(l) || l <= 1) return null;
68
+ if (n.viewMode === "3d" && n.orbit) {
69
+ const m = a === "in" ? n.orbit.distance / l : n.orbit.distance * l;
70
+ return !Number.isFinite(m) || m <= 0 ? null : { ...n, orbit: { ...n.orbit, distance: m } };
71
+ }
72
+ if (n.viewMode === "2d" && n.orthographic) {
73
+ const m = a === "in" ? n.orthographic.zoom * l : n.orthographic.zoom / l;
74
+ return !Number.isFinite(m) || m <= 0 ? null : { ...n, orthographic: { ...n.orthographic, zoom: m } };
75
+ }
76
+ return null;
77
+ }
78
+ const fs = 0.01, ms = [
79
+ [-1, -1],
80
+ [1, -1],
81
+ [1, 1],
82
+ [-1, 1]
83
+ ];
84
+ function Wo(n) {
85
+ return n.kind === "rectangle" ? ms.map(([a, l]) => ({
86
+ id: `corner:${a}:${l}`,
87
+ mode: "corner",
88
+ position: [a * n.widthM / 2, l * n.heightM / 2, 0]
89
+ })) : n.kind === "box" ? [
90
+ { id: "axis:x:-", mode: "axis", axis: "x", sign: -1, position: [-n.widthM / 2, 0, 0] },
91
+ { id: "axis:x:+", mode: "axis", axis: "x", sign: 1, position: [n.widthM / 2, 0, 0] },
92
+ { id: "axis:y:-", mode: "axis", axis: "y", sign: -1, position: [0, -n.depthM / 2, 0] },
93
+ { id: "axis:y:+", mode: "axis", axis: "y", sign: 1, position: [0, n.depthM / 2, 0] },
94
+ { id: "axis:z:-", mode: "axis", axis: "z", sign: -1, position: [0, 0, -n.heightM / 2] },
95
+ { id: "axis:z:+", mode: "axis", axis: "z", sign: 1, position: [0, 0, n.heightM / 2] }
96
+ ] : n.points.map((a, l) => ({
97
+ id: `vertex:${l}`,
98
+ mode: "vertex",
99
+ index: l,
100
+ position: [a[0], a[1], 0]
101
+ }));
102
+ }
103
+ function ps(n, a, l = 0) {
104
+ return n.kind !== "rectangle" ? n : {
105
+ ...n,
106
+ widthM: yn(Math.abs(a[0]) * 2, l),
107
+ heightM: yn(Math.abs(a[1]) * 2, l)
108
+ };
109
+ }
110
+ function hs(n, a, l, m = 0) {
111
+ if (n.kind !== "polygon" || !n.points[a]) return n;
112
+ const y = [
113
+ Yt(l[0], m),
114
+ Yt(l[1], m)
115
+ ];
116
+ return {
117
+ ...n,
118
+ points: n.points.map((M, v) => v === a ? y : M)
119
+ };
120
+ }
121
+ function gs(n, a, l, m = 0) {
122
+ return n.kind !== "box" ? n : a === "x" ? { ...n, widthM: yn(n.widthM + l * 2, m) } : a === "y" ? { ...n, depthM: yn(n.depthM + l * 2, m) } : { ...n, heightM: yn(n.heightM + l * 2, m) };
123
+ }
124
+ function zo(n, a) {
125
+ return n.kind !== a.kind ? !1 : n.kind === "rectangle" && a.kind === "rectangle" ? yt(n.widthM, a.widthM) && yt(n.heightM, a.heightM) : n.kind === "box" && a.kind === "box" ? yt(n.widthM, a.widthM) && yt(n.depthM, a.depthM) && yt(n.heightM, a.heightM) : n.kind !== "polygon" || a.kind !== "polygon" ? !1 : yt(n.heightM, a.heightM) && n.points.length === a.points.length && n.points.every((l, m) => yt(l[0], a.points[m][0]) && yt(l[1], a.points[m][1]));
126
+ }
127
+ function No(n) {
128
+ return n.shape.kind === "rectangle" ? Math.max(n.shape.widthM, n.shape.heightM) : n.shape.kind === "box" ? Math.max(n.shape.widthM, n.shape.depthM, n.shape.heightM) : Math.max(
129
+ n.shape.heightM,
130
+ ...n.shape.points.flatMap((a) => [a[0], a[1]])
131
+ );
132
+ }
133
+ function yn(n, a) {
134
+ return Math.max(fs, Yt(n, a));
135
+ }
136
+ function yt(n, a) {
137
+ return Math.abs(n - a) < 1e-9;
138
+ }
139
+ class ys {
140
+ constructor() {
141
+ fe(this, "instances", /* @__PURE__ */ new Map());
142
+ }
143
+ apply(a, l, m) {
144
+ if (!m || m.color === void 0 && m.opacity === void 0) {
145
+ this.remove(a);
146
+ return;
147
+ }
148
+ let y = this.instances.get(a);
149
+ y && (y.root !== l || [...y.bindings.values()].some((S) => S.mesh.material !== S.applied)) && (this.remove(a), y = void 0), y || (y = { root: l, bindings: /* @__PURE__ */ new Map(), clones: /* @__PURE__ */ new Map() }, this.instances.set(a, y));
150
+ const M = xs(l), v = new Set(M);
151
+ for (const [S, w] of y.bindings)
152
+ v.has(S) || (S.material === w.applied && (S.material = w.original), y.bindings.delete(S));
153
+ const f = (S) => {
154
+ let w = y.clones.get(S);
155
+ return w || (w = S.clone(), y.clones.set(S, w)), w;
156
+ };
157
+ for (const S of M) {
158
+ if (y.bindings.has(S)) continue;
159
+ const w = S.material, E = Array.isArray(w) ? w.map(f) : f(w);
160
+ y.bindings.set(S, { mesh: S, original: w, applied: E }), S.material = E;
161
+ }
162
+ const x = /* @__PURE__ */ new Set();
163
+ for (const S of y.bindings.values())
164
+ for (const w of ws(S.original)) x.add(w);
165
+ for (const [S, w] of y.clones) {
166
+ if (!x.has(S)) {
167
+ w.dispose(), y.clones.delete(S);
168
+ continue;
169
+ }
170
+ const E = Do(S), j = Do(w);
171
+ j && (m.color ? j.setRGB(m.color[0], m.color[1], m.color[2], Bi) : E && j.copy(E));
172
+ const k = S.transparent || m.opacity !== void 0 && m.opacity < 1, T = w.transparent !== k;
173
+ w.opacity = m.opacity ?? S.opacity, w.transparent = k, w.depthWrite = m.opacity !== void 0 && m.opacity < 1 ? !1 : S.depthWrite, T && (w.needsUpdate = !0);
174
+ }
175
+ }
176
+ remove(a) {
177
+ const l = this.instances.get(a);
178
+ if (l) {
179
+ this.instances.delete(a);
180
+ for (const m of l.bindings.values())
181
+ m.mesh.material === m.applied && (m.mesh.material = m.original);
182
+ for (const m of l.clones.values()) m.dispose();
183
+ }
184
+ }
185
+ dispose() {
186
+ for (const a of this.instances.keys()) this.remove(a);
187
+ }
188
+ }
189
+ function ws(n) {
190
+ return Array.isArray(n) ? n : [n];
191
+ }
192
+ function Do(n) {
193
+ const a = n.color;
194
+ return a instanceof Vo ? a : null;
195
+ }
196
+ function xs(n) {
197
+ const a = [], l = (m) => {
198
+ if (!(m !== n && !m.visible)) {
199
+ m instanceof Z && a.push(m);
200
+ for (const y of m.children) l(y);
201
+ }
202
+ };
203
+ return l(n), a;
204
+ }
205
+ function bs(n, a, l, m = {}) {
206
+ const y = n.find((C) => C.nodeId === a);
207
+ if (!y || !jo(y, m) || !xr(y.localTransform) || !xr(l)) return [];
208
+ const M = y.localTransform, v = new p().fromArray(M.position), f = new p().fromArray(l.position), x = new se().fromArray(M.rotation).normalize(), S = x.clone().invert(), w = new se().fromArray(l.rotation).normalize().multiply(S), E = new p().fromArray(l.scale).divide(new p().fromArray(M.scale)), j = Math.hypot(w.x, w.y, w.z) > 1e-12, k = E.x !== 1 || E.y !== 1 || E.z !== 1, T = [], b = /* @__PURE__ */ new Set();
209
+ for (const C of n) {
210
+ if (b.has(C.nodeId) || (b.add(C.nodeId), !jo(C, m) || !xr(C.localTransform))) continue;
211
+ if (C.nodeId === a) {
212
+ T.push({ nodeId: a, localTransform: vs(l) });
213
+ continue;
214
+ }
215
+ const B = C.localTransform, ae = new p().fromArray(B.position).sub(v);
216
+ k && ae.applyQuaternion(S).multiply(E).applyQuaternion(x), j && ae.applyQuaternion(w);
217
+ const J = j ? w.clone().multiply(new se().fromArray(B.rotation)).normalize().toArray() : [...B.rotation];
218
+ T.push({
219
+ nodeId: C.nodeId,
220
+ localTransform: {
221
+ position: ae.add(f).toArray(),
222
+ rotation: J,
223
+ scale: k ? new p().fromArray(B.scale).multiply(E).toArray() : [...B.scale]
224
+ }
225
+ });
226
+ }
227
+ return T;
228
+ }
229
+ function jo(n, a) {
230
+ const l = a[n.nodeId];
231
+ return n.visible && !(l != null && l.hidden) && !(l != null && l.locked);
232
+ }
233
+ function xr(n) {
234
+ return [...n.position, ...n.rotation, ...n.scale].every(Number.isFinite) && n.scale.every((a) => a > 0) && Math.hypot(...n.rotation) > 1e-12;
235
+ }
236
+ function vs(n) {
237
+ return { position: [...n.position], rotation: [...n.rotation], scale: [...n.scale] };
238
+ }
239
+ const ei = 0.73, ti = 0.98, hn = 8e-3, Cr = 0.047, ni = 0.1;
240
+ function Ms(n, a) {
241
+ const l = n.getHelper().children.find((m) => "gizmo" in m);
242
+ l && (a === "horizontal-rotation" ? Es(l) : (Is(l), As(l), Ss(l.picker.scale)));
243
+ }
244
+ function st(n, a) {
245
+ n.geometry.dispose(), n.geometry = a;
246
+ }
247
+ function Is(n) {
248
+ const a = { X: new p(1, 0, 0), Y: new p(0, 1, 0), Z: new p(0, 0, 1) };
249
+ for (const [M, v] of Object.entries(a)) {
250
+ const f = n.gizmo.translate.children.filter((x) => x.name === M && x instanceof Z);
251
+ for (const x of f) {
252
+ if (x.geometry.computeBoundingBox(), x.geometry.boundingBox.getCenter(new p()).dot(v) <= 0.35) {
253
+ st(x, new Ln());
254
+ continue;
255
+ }
256
+ const w = new kr();
257
+ w.moveTo(-hn, 0), w.lineTo(hn, 0), w.lineTo(hn, 0.49), w.lineTo(Cr, 0.49), w.lineTo(0, 0.49 + ni), w.lineTo(-Cr, 0.49), w.lineTo(-hn, 0.49), w.closePath(), st(x, new Ho(w));
258
+ const E = new p(), j = new se(), k = new se(), T = new p(), b = new p(), C = new p(), B = new p(), ae = new p(), J = new _e();
259
+ x.onBeforeRender = (X, at, ee) => {
260
+ var P;
261
+ x.matrixWorld.decompose(E, j, T), (P = x.parent) == null || P.getWorldQuaternion(k), C.copy(v).applyQuaternion(x.quaternion).applyQuaternion(k).normalize(), ee.getWorldPosition(b), B.crossVectors(C, b.sub(E)).normalize(), !(B.lengthSq() < 1e-8) && (ae.crossVectors(B, C).normalize(), J.makeBasis(B, C, ae), x.matrixWorld.compose(E, j.setFromRotationMatrix(J), T));
262
+ };
263
+ }
264
+ for (const x of n.picker.translate.children)
265
+ !(x instanceof Z) || x.name !== M || (x.geometry.computeBoundingBox(), x.geometry.boundingBox.getCenter(new p()).dot(v) < -0.1 ? st(x, new Ln()) : ri(x));
266
+ }
267
+ const l = {
268
+ XY: new p(0.1, 0.1, 0),
269
+ YZ: new p(0, 0.1, 0.1),
270
+ XZ: new p(0.1, 0, 0.1)
271
+ };
272
+ for (const M of [n.gizmo.translate, n.picker.translate])
273
+ for (const v of M.children) {
274
+ if (!(v instanceof Z) || !l[v.name]) continue;
275
+ const f = v.geometry;
276
+ f.scale(0.7, 0.7, 0.7);
277
+ const x = l[v.name];
278
+ f.translate(x.x, x.y, x.z);
279
+ }
280
+ const m = n.gizmo.translate.children.find((M) => M instanceof Z && M.name === "XYZ"), y = n.picker.translate.children.find((M) => M instanceof Z && M.name === "XYZ");
281
+ if (m && y) {
282
+ st(m, new Go(0.092, 0.103, 48)), st(y, new $o(0.115, 16, 10));
283
+ const M = new p(), v = new p(), f = new p(), x = new mn();
284
+ y.raycast = (k, T) => {
285
+ if (M.setFromMatrixPosition(y.matrixWorld), k.camera ? k.camera.getWorldDirection(v) : v.copy(k.ray.direction), x.setFromNormalAndCoplanarPoint(v, M), !k.ray.intersectPlane(x, f)) return;
286
+ const b = y.matrixWorld.getMaxScaleOnAxis(), C = f.distanceTo(M) / b;
287
+ if (C > 0.03 && (C < 0.08 || C > 0.115)) return;
288
+ const B = Math.max(0, k.ray.origin.distanceTo(f) - 0.12 * b);
289
+ B < k.near || B > k.far || T.push({ distance: B, point: k.ray.at(B, new p()), object: y });
290
+ }, Rr(m);
291
+ const S = new p(), w = new se(), E = new p();
292
+ m.onBeforeRender = (k, T, b) => {
293
+ m.matrixWorld.decompose(S, w, E), b.getWorldQuaternion(w), m.matrixWorld.compose(S, w, E);
294
+ };
295
+ const j = new Z(new Fi(0.018, 24), new pn({
296
+ color: 2017471,
297
+ depthTest: !1,
298
+ depthWrite: !1,
299
+ toneMapped: !1
300
+ }));
301
+ j.name = "sim-studio:gizmo-center-dot", j.renderOrder = 1, j.onBeforeRender = (k, T, b) => {
302
+ j.matrixWorld.decompose(S, w, E), b.getWorldQuaternion(w), j.matrixWorld.compose(S, w, E);
303
+ }, m.add(j);
304
+ }
305
+ }
306
+ function Ss(n) {
307
+ for (const a of n.children)
308
+ a instanceof Z && ["X", "Y", "Z"].includes(a.name) && ri(a);
309
+ }
310
+ function ri(n) {
311
+ n.geometry.scale(n.name === "X" ? 1 : 0.25, n.name === "Y" ? 1 : 0.25, n.name === "Z" ? 1 : 0.25);
312
+ }
313
+ function Rr(n) {
314
+ for (const a of Array.isArray(n.material) ? n.material : [n.material])
315
+ a.side = Uo;
316
+ }
317
+ function As(n) {
318
+ for (const a of n.gizmo.rotate.children) {
319
+ if (!(a instanceof Z)) continue;
320
+ const l = a.name === "E" ? 0.75 : 0.5, m = ["X", "Y", "Z"].includes(a.name) ? Math.PI : Math.PI * 2, y = new Go(l - 75e-4, l + 75e-4, 64, 1, 0, m);
321
+ y.rotateY(Math.PI / 2), y.rotateX(Math.PI / 2), a.name === "Y" && y.rotateZ(-Math.PI / 2), (a.name === "Z" || a.name === "E" || a.name === "XYZE") && y.rotateY(Math.PI / 2), st(a, y), Rr(a);
322
+ }
323
+ for (const a of n.picker.rotate.children) {
324
+ if (!(a instanceof Z)) continue;
325
+ const l = a.name === "E" ? 0.75 : 0.5, m = ["X", "Y", "Z"].includes(a.name) ? Math.PI : Math.PI * 2, y = new Zo(l, 0.035, 8, 64, m);
326
+ y.rotateY(Math.PI / 2), y.rotateX(Math.PI / 2), a.name === "Y" && y.rotateZ(-Math.PI / 2), (a.name === "Z" || a.name === "E" || a.name === "XYZE") && y.rotateY(Math.PI / 2), st(a, y);
327
+ }
328
+ }
329
+ function Es(n) {
330
+ const a = Math.PI * 0.22, l = 0.55, m = ei / ti, y = hn * m, M = Cr * m, v = ni * m, f = (C, B) => {
331
+ const ae = new Zo(l, C, 8, 48, B);
332
+ return ae.rotateZ(-B / 2), ae;
333
+ }, x = n.gizmo.rotate.children.find((C) => C instanceof Z && C.name === "Z"), S = n.picker.rotate.children.find((C) => C instanceof Z && C.name === "Z");
334
+ if (!x || !S) return;
335
+ const w = (C, B) => new p(B * Math.cos(C), B * Math.sin(C), 0), E = -a / 2, j = a / 2, k = new kr(), T = (C) => {
336
+ k.lineTo(C.x, C.y);
337
+ }, b = w(E, l - y);
338
+ k.moveTo(b.x, b.y), T(w(E, l - M)), T(w(E, l).add(new p(Math.sin(E), -Math.cos(E), 0).multiplyScalar(v))), T(w(E, l + M));
339
+ for (let C = 0; C <= 48; C += 1) T(w(E + a * C / 48, l + y));
340
+ T(w(j, l + M)), T(w(j, l).add(new p(-Math.sin(j), Math.cos(j), 0).multiplyScalar(v))), T(w(j, l - M));
341
+ for (let C = 48; C >= 0; C -= 1) T(w(E + a * C / 48, l - y));
342
+ k.closePath(), st(x, new Ho(k)), Rr(x), st(S, f(0.035, a + 0.3));
343
+ }
344
+ function Lo(n, a = "default") {
345
+ n.setColors("#ff3653", "#15df67", "#287dff", "#ffffff"), Ms(n, a);
346
+ const l = n.getHelper().children.find((M) => "gizmo" in M);
347
+ if (!l) return;
348
+ for (const M of Object.values(l.gizmo))
349
+ for (const v of M.children)
350
+ v instanceof Z && (v.material = Array.isArray(v.material) ? v.material.map((f) => f.clone()) : v.material.clone());
351
+ const m = /* @__PURE__ */ new Set();
352
+ n.getHelper().traverse((M) => {
353
+ if (!("material" in M)) return;
354
+ const v = Array.isArray(M.material) ? M.material : [M.material];
355
+ for (const f of v)
356
+ !f || m.has(f) || f.opacity <= 0 || !f.visible || (m.add(f), f.transparent = !0, f.opacity = 0.7, f._opacity = f.opacity);
357
+ });
358
+ const y = l.updateMatrixWorld;
359
+ l.updateMatrixWorld = function(M) {
360
+ y.call(this, M);
361
+ const v = n.getMode(), f = v === "translate" && n.dragging && n.getHelper().userData.simStudioCenterDrag === !0;
362
+ for (const x of this.gizmo[v].children) {
363
+ if (!("material" in x)) continue;
364
+ const S = Array.isArray(x.material) ? x.material : [x.material];
365
+ for (const w of S)
366
+ w.color && w._color && w.color.copy(w._color), f && x.name === "XYZ" && (w.opacity = 1);
367
+ n.dragging && x.name !== (f ? "XYZ" : n.axis) && (x.visible = !1);
368
+ }
369
+ n.dragging && (this.helper[v].visible = !1);
370
+ };
371
+ }
372
+ class Ps extends Pr {
373
+ constructor(l, m = {}) {
374
+ super(new K(), l);
375
+ fe(this, "stroke");
376
+ fe(this, "localBoundsMatrix", new _e());
377
+ fe(this, "parentInverse", new _e());
378
+ for (const w of Array.isArray(this.material) ? this.material : [this.material]) w.visible = !1;
379
+ const y = this.geometry, M = y.getIndex(), v = y.getAttribute("position"), f = [];
380
+ for (let w = 0; w < M.count; w += 1) {
381
+ const E = M.getX(w);
382
+ f.push(v.getX(E), v.getY(E), v.getZ(E));
383
+ }
384
+ const x = new cs();
385
+ x.setPositions(f);
386
+ const S = new as({ color: new Vo(l), linewidth: m.linewidth ?? 2.5, transparent: !0, opacity: m.opacity ?? 0.95, depthTest: !1, depthWrite: !1, toneMapped: !1 });
387
+ this.stroke = new ls(x, S), this.stroke.renderOrder = 1e3, this.stroke.frustumCulled = !1, this.add(this.stroke), this.matrixAutoUpdate = !1;
388
+ }
389
+ /** Keep the bounds in instance space, then follow its complete world matrix. */
390
+ updateFromObject(l) {
391
+ l.updateWorldMatrix(!0, !0);
392
+ const m = new _e().copy(l.matrixWorld).invert(), y = new _e();
393
+ if (this.box.makeEmpty(), l.traverseVisible((f) => {
394
+ if (!(f instanceof Z)) return;
395
+ const x = f.geometry;
396
+ x.boundingBox || x.computeBoundingBox(), x.boundingBox && (y.multiplyMatrices(m, f.matrixWorld), this.box.union(x.boundingBox.clone().applyMatrix4(y)));
397
+ }), this.box.isEmpty()) return;
398
+ const M = this.box.getCenter(new p()), v = this.box.getSize(new p()).multiplyScalar(0.5);
399
+ this.localBoundsMatrix.compose(M, new se(), v), this.followObject(l);
400
+ }
401
+ /**
402
+ * Translation-only updates reuse the measured instance-local box and only
403
+ * refresh its world matrix. This keeps high-frequency drags in sync without
404
+ * walking every mesh and recomputing each geometry bound.
405
+ */
406
+ followObject(l) {
407
+ this.box.isEmpty() || (this.parent ? (this.parent.updateWorldMatrix(!0, !1), this.parentInverse.copy(this.parent.matrixWorld).invert()) : this.parentInverse.identity(), this.matrix.multiplyMatrices(this.parentInverse, l.matrixWorld).multiply(this.localBoundsMatrix), this.matrixWorldNeedsUpdate = !0);
408
+ }
409
+ setColor(l) {
410
+ this.stroke.material.color.setHex(l);
411
+ }
412
+ updateMatrixWorld(l) {
413
+ qo.prototype.updateMatrixWorld.call(this, l);
414
+ }
415
+ dispose() {
416
+ this.stroke.geometry.dispose(), this.stroke.material.dispose(), super.dispose();
417
+ }
418
+ }
419
+ const br = /* @__PURE__ */ new WeakMap();
420
+ function he(n) {
421
+ const a = new K(), l = new K(), m = new p();
422
+ return n.updateWorldMatrix(!0, !0), n.traverseVisible((y) => {
423
+ if (y instanceof Z) {
424
+ if (y instanceof wn) {
425
+ y.boundingBox === null && y.computeBoundingBox(), y.boundingBox && a.union(l.copy(y.boundingBox).applyMatrix4(y.matrixWorld));
426
+ return;
427
+ }
428
+ a.union(Cs(y, m));
429
+ }
430
+ }), a;
431
+ }
432
+ function Cs(n, a) {
433
+ const l = n.geometry, m = l.getAttribute("position");
434
+ if (!m) return ks;
435
+ const y = l.morphAttributes.position ?? [], M = n.morphTargetInfluences ?? [], v = !(n instanceof Yi) && !M.some((S) => S !== 0), f = br.get(n);
436
+ if (v && f && Os(f, n, m, y, M)) return f.bounds;
437
+ const x = new K();
438
+ for (let S = 0; S < m.count; S += 1)
439
+ n.getVertexPosition(S, a), x.expandByPoint(a.applyMatrix4(n.matrixWorld));
440
+ return v ? br.set(n, {
441
+ matrixWorld: n.matrixWorld.clone(),
442
+ geometry: l,
443
+ positionAttribute: m,
444
+ positionVersion: Fn(m),
445
+ morphAttributes: [...y],
446
+ morphVersions: y.map(Fn),
447
+ morphWeights: [...M],
448
+ bounds: x.clone()
449
+ }) : br.delete(n), x;
450
+ }
451
+ function Os(n, a, l, m, y) {
452
+ if (n.geometry !== a.geometry || n.positionAttribute !== l || n.positionVersion !== Fn(l) || !n.matrixWorld.equals(a.matrixWorld) || n.morphAttributes.length !== m.length || n.morphWeights.length !== y.length) return !1;
453
+ for (let M = 0; M < m.length; M += 1)
454
+ if (n.morphAttributes[M] !== m[M] || n.morphVersions[M] !== Fn(m[M])) return !1;
455
+ for (let M = 0; M < y.length; M += 1)
456
+ if (n.morphWeights[M] !== y[M]) return !1;
457
+ return !0;
458
+ }
459
+ function Fn(n) {
460
+ return n instanceof _i ? n.data.version : n.version;
461
+ }
462
+ const ks = new K();
463
+ function zn(n) {
464
+ n.updateWorldMatrix(!0, !0);
465
+ const a = n.matrixWorld.clone().invert(), l = new K(), m = new p(), y = (M) => {
466
+ if (M !== n && !M.visible) return;
467
+ for (const x of M.children) y(x);
468
+ if (!(M instanceof Z)) return;
469
+ const v = a.clone().multiply(M.matrixWorld);
470
+ if (M instanceof wn) {
471
+ M.boundingBox || M.computeBoundingBox(), M.boundingBox && l.union(M.boundingBox.clone().applyMatrix4(v));
472
+ return;
473
+ }
474
+ const f = M.geometry.getAttribute("position");
475
+ if (f)
476
+ for (let x = 0; x < f.count; x++) l.expandByPoint(M.getVertexPosition(x, m).applyMatrix4(v));
477
+ };
478
+ return y(n), l;
479
+ }
480
+ const vr = "http://www.w3.org/2000/svg", Nn = Math.PI * 2;
481
+ function Rs(n, a) {
482
+ return Math.atan2(Math.sin(a - n), Math.cos(a - n));
483
+ }
484
+ function Ts(n, a) {
485
+ if (!Number.isFinite(a) || a <= 0) return n;
486
+ const l = a * Math.PI / 180;
487
+ return Math.round(n / l) * l;
488
+ }
489
+ function Or(n, a) {
490
+ return n.center.clone().addScaledVector(n.axisX, Math.cos(a) * n.radius).addScaledVector(n.axisY, Math.sin(a) * n.radius);
491
+ }
492
+ class Ws {
493
+ constructor(a, l) {
494
+ fe(this, "element");
495
+ fe(this, "handleElement");
496
+ fe(this, "badge");
497
+ fe(this, "trackShadow");
498
+ fe(this, "track");
499
+ fe(this, "ticks");
500
+ fe(this, "sector");
501
+ fe(this, "startLine");
502
+ fe(this, "endLine");
503
+ fe(this, "sweep");
504
+ fe(this, "centerDot");
505
+ fe(this, "startDot");
506
+ fe(this, "knob");
507
+ fe(this, "hit");
508
+ var m, y, M, v, f, x;
509
+ this.element = l.createElementNS(vr, "svg"), this.element.setAttribute("class", "studio-rotation-guide"), this.element.setAttribute("role", "group"), this.element.setAttribute("aria-label", "旋转角度圆环"), this.element.setAttribute("hidden", ""), Object.assign(this.element.style, {
510
+ position: "absolute",
511
+ inset: "0",
512
+ width: "100%",
513
+ height: "100%",
514
+ zIndex: "4",
515
+ overflow: "visible",
516
+ pointerEvents: "none",
517
+ touchAction: "none",
518
+ color: "#e4edf2"
519
+ }), this.trackShadow = this.path("studio-rotation-track-shadow", {
520
+ stroke: "rgba(5, 12, 14, .72)",
521
+ strokeWidth: "4"
522
+ }), this.track = this.path("studio-rotation-track", {
523
+ stroke: "currentColor",
524
+ strokeWidth: "1",
525
+ opacity: ".58"
526
+ }), this.ticks = this.path("studio-rotation-ticks", {
527
+ stroke: "currentColor",
528
+ strokeWidth: "1",
529
+ opacity: ".34"
530
+ }), this.sector = this.path("studio-rotation-sector", {
531
+ fill: "rgba(228, 237, 242, .075)",
532
+ stroke: "none"
533
+ }), this.startLine = this.path("studio-rotation-start", {
534
+ stroke: "currentColor",
535
+ strokeWidth: "1",
536
+ strokeDasharray: "3 4",
537
+ opacity: ".72"
538
+ }), this.endLine = this.path("studio-rotation-end", {
539
+ stroke: "currentColor",
540
+ strokeWidth: "1.25",
541
+ opacity: ".94"
542
+ }), this.sweep = this.path("studio-rotation-sweep", {
543
+ stroke: "currentColor",
544
+ strokeWidth: "2.5",
545
+ opacity: ".96"
546
+ }), this.centerDot = this.circle("studio-rotation-center", "2", {
547
+ fill: "currentColor",
548
+ opacity: ".72",
549
+ stroke: "none"
550
+ }), this.startDot = this.circle("studio-rotation-origin", "2.5", {
551
+ fill: "#5e6d76",
552
+ stroke: "currentColor",
553
+ strokeWidth: "1"
554
+ }), this.knob = this.circle("studio-rotation-knob", "4.5", {
555
+ fill: "#ffffff",
556
+ stroke: "#3d4d57",
557
+ strokeWidth: "2"
558
+ }), this.hit = this.path("studio-rotation-hit", {
559
+ stroke: "transparent",
560
+ strokeWidth: "18",
561
+ pointerEvents: "stroke",
562
+ cursor: "ew-resize"
563
+ }), this.hit.setAttribute("tabindex", "0"), this.hit.setAttribute("aria-label", "拖动旋转对象"), this.handleElement = l.createElement("button"), this.handleElement.type = "button", this.handleElement.className = "studio-rotation-handle", this.handleElement.setAttribute("aria-label", "拖动旋转对象"), this.handleElement.title = "拖动旋转", this.handleElement.innerHTML = '<svg viewBox="0 0 32 28" aria-hidden="true"><path d="M8.5 17.5C5.1 16.4 3.3 14.8 3.3 13c0-3.7 5.6-6.6 12.7-6.6S28.7 9.3 28.7 13c0 3.6-5.6 6.5-12.7 6.5h-2.5"/><path d="m17 16-3.7 3.5L17 23"/></svg>', Object.assign(this.handleElement.style, {
564
+ position: "absolute",
565
+ zIndex: "7",
566
+ display: "grid",
567
+ placeItems: "center",
568
+ width: "32px",
569
+ height: "32px",
570
+ padding: "0",
571
+ transform: "translate(-50%, -50%)",
572
+ border: "0",
573
+ borderRadius: "50%",
574
+ background: "transparent",
575
+ color: "#f4f8fa",
576
+ cursor: "grab",
577
+ filter: "drop-shadow(0 2px 3px rgba(0, 0, 0, .55))",
578
+ pointerEvents: "auto",
579
+ touchAction: "none"
580
+ }), (m = this.handleElement.firstElementChild) == null || m.setAttribute("fill", "none"), (y = this.handleElement.firstElementChild) == null || y.setAttribute("stroke", "currentColor"), (M = this.handleElement.firstElementChild) == null || M.setAttribute("stroke-width", "1.9"), (v = this.handleElement.firstElementChild) == null || v.setAttribute("stroke-linecap", "round"), (f = this.handleElement.firstElementChild) == null || f.setAttribute("stroke-linejoin", "round"), (x = this.handleElement.firstElementChild) == null || x.setAttribute("style", "width:24px;height:22px;overflow:visible"), this.badge = l.createElement("output"), this.badge.className = "studio-rotation-angle", this.badge.setAttribute("aria-label", "旋转角度"), this.badge.hidden = !0, Object.assign(this.badge.style, {
581
+ position: "absolute",
582
+ zIndex: "7",
583
+ minWidth: "44px",
584
+ padding: "4px 7px",
585
+ transform: "translate(-50%, -50%)",
586
+ border: "1px solid rgba(228, 237, 242, .16)",
587
+ borderRadius: "4px",
588
+ background: "rgba(15, 20, 22, .94)",
589
+ boxShadow: "0 3px 12px rgba(0, 0, 0, .32)",
590
+ color: "#f7fafc",
591
+ font: '600 17px/22px "JetBrains Mono", "SF Mono", Consolas, monospace',
592
+ letterSpacing: "-.5px",
593
+ textAlign: "center",
594
+ pointerEvents: "none",
595
+ fontVariantNumeric: "tabular-nums"
596
+ }), a.append(this.element, this.handleElement, this.badge);
597
+ }
598
+ path(a, l) {
599
+ const m = this.element.ownerDocument.createElementNS(vr, "path");
600
+ m.setAttribute("class", a), m.setAttribute("fill", l.fill ?? "none"), m.setAttribute("stroke-linecap", "round"), m.setAttribute("stroke-linejoin", "round"), m.setAttribute("vector-effect", "non-scaling-stroke");
601
+ for (const [y, M] of Object.entries(l))
602
+ y !== "fill" && m.style.setProperty(Bo(y), M);
603
+ return this.element.append(m), m;
604
+ }
605
+ circle(a, l, m) {
606
+ const y = this.element.ownerDocument.createElementNS(vr, "circle");
607
+ y.setAttribute("class", a), y.setAttribute("r", l);
608
+ for (const [M, v] of Object.entries(m))
609
+ y.style.setProperty(Bo(M), v);
610
+ return this.element.append(y), y;
611
+ }
612
+ render(a) {
613
+ const { width: l, height: m, project: y, startAngle: M, delta: v } = a;
614
+ if (l <= 0 || m <= 0) {
615
+ this.hide();
616
+ return;
617
+ }
618
+ if (!a.showRing) {
619
+ this.element.setAttribute("hidden", ""), this.badge.hidden = !0, this.renderHandle(a);
620
+ return;
621
+ }
622
+ const f = (J) => Or(a, J), x = (J) => y(f(J)), S = y(a.center), w = x(M), E = x(M + v);
623
+ if (![S.x, S.y, w.x, w.y, E.x, E.y].every(Number.isFinite)) {
624
+ this.hide();
625
+ return;
626
+ }
627
+ const j = this.arcPath(x, 0, Nn, 112), k = Math.max(-Nn, Math.min(Nn, v)), T = this.arcPath(
628
+ x,
629
+ M,
630
+ k,
631
+ Math.max(2, Math.ceil(Math.abs(k) * 28))
632
+ ), b = this.linePath(S, w), C = this.linePath(S, E);
633
+ this.element.setAttribute("viewBox", `0 0 ${l} ${m}`), this.trackShadow.setAttribute("d", j), this.track.setAttribute("d", j), this.hit.setAttribute("d", j), this.sector.setAttribute("d", T ? `M${this.coord(S)}L${this.coord(w)}${T.replace(/^M/, "L")}Z` : ""), this.startLine.setAttribute("d", b), this.endLine.setAttribute("d", C), this.sweep.setAttribute("d", T);
634
+ let B = "";
635
+ for (let J = 0; J < 24; J += 1) {
636
+ const X = M + J * Nn / 24;
637
+ B += this.linePath(
638
+ x(X),
639
+ y(Or(a, X).sub(a.center).multiplyScalar(J % 3 === 0 ? 0.92 : 0.96).add(a.center))
640
+ );
641
+ }
642
+ this.ticks.setAttribute("d", B);
643
+ for (const [J, X] of [
644
+ [this.centerDot, S],
645
+ [this.startDot, w],
646
+ [this.knob, E]
647
+ ])
648
+ J.setAttribute("cx", X.x.toFixed(2)), J.setAttribute("cy", X.y.toFixed(2));
649
+ const ae = Math.round(v * 180 / Math.PI);
650
+ this.badge.textContent = `${ae}°`, this.badge.setAttribute("aria-label", `旋转角度 ${ae} 度`), this.badge.style.left = `${Math.max(34, Math.min(l - 34, E.x + 34))}px`, this.badge.style.top = `${Math.max(70, Math.min(m - 66, E.y + 26))}px`, this.badge.hidden = !1, this.element.removeAttribute("hidden"), this.renderHandle(a);
651
+ }
652
+ hide() {
653
+ this.element.setAttribute("hidden", ""), this.handleElement.hidden = !0, this.badge.hidden = !0;
654
+ }
655
+ dispose() {
656
+ this.element.remove(), this.handleElement.remove(), this.badge.remove();
657
+ }
658
+ coord(a) {
659
+ return `${a.x.toFixed(2)} ${a.y.toFixed(2)}`;
660
+ }
661
+ linePath(a, l) {
662
+ return `M${this.coord(a)}L${this.coord(l)}`;
663
+ }
664
+ arcPath(a, l, m, y) {
665
+ let M = "";
666
+ for (let v = 0; v <= y; v += 1) {
667
+ const f = a(l + m * v / y);
668
+ M += `${v === 0 ? "M" : "L"}${this.coord(f)}`;
669
+ }
670
+ return M;
671
+ }
672
+ renderHandle(a) {
673
+ if (!a.showHandle || !a.handlePoint) {
674
+ this.handleElement.hidden = !0;
675
+ return;
676
+ }
677
+ this.handleElement.hidden = !1, this.handleElement.style.left = `${a.handlePoint.x}px`, this.handleElement.style.top = `${a.handlePoint.y}px`;
678
+ }
679
+ }
680
+ function zs(n, a) {
681
+ return !a || typeof a.createElementNS != "function" || typeof n.append != "function" ? null : new Ws(n, a);
682
+ }
683
+ function Bo(n) {
684
+ return n.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
685
+ }
686
+ function Ns() {
687
+ return Object.freeze({
688
+ localWorldTransforms: {
689
+ status: "applied",
690
+ reason: "SceneSession projects group hierarchy into world-space viewer placements."
691
+ },
692
+ visibility: {
693
+ status: "applied",
694
+ reason: "Document visibility and editorial hidden state control mounted instances."
695
+ },
696
+ appearance: {
697
+ status: "applied",
698
+ reason: "SceneSession applies asset color/opacity overrides to mounted instances."
699
+ },
700
+ variantSelections: {
701
+ status: "applied",
702
+ reason: "Variant changes invalidate the mounted source and reload the revision with selections."
703
+ },
704
+ physicsOverride: {
705
+ status: "applied",
706
+ reason: "Rigid motion, collider selection, mass, center of mass and scalar joint drives project into the unified MuJoCo world; invalid or ambiguous targets fail explicitly."
707
+ },
708
+ physicsMaterial: {
709
+ status: "partial",
710
+ reason: "Density on geometry-authored inertia and a shared sliding friction value apply. Restitution and distinct static/dynamic friction have no exact scalar MuJoCo equivalent and are rejected instead of approximated."
711
+ },
712
+ initialPose: {
713
+ status: "applied",
714
+ reason: "Scalar joint initial poses are applied at compilation and every reset; unknown joints fail explicitly."
715
+ },
716
+ environment: {
717
+ status: "not-applied",
718
+ reason: "SceneSession currently uses the Viewer room environment regardless of authored preset/HDR."
719
+ },
720
+ placeholder: {
721
+ status: "applied",
722
+ reason: "Placeholders render as temporary in-session bounds geometry and block USD export."
723
+ }
724
+ });
725
+ }
726
+ const Mr = "sim-studio:authoring", wt = 2017471, Fo = 14900582, Yo = 0.012, Ds = 0.06, js = 14, un = 1e-4, Ls = 0.01, Bs = 16762967, Fs = 6000111, Dn = 5363408, fn = 14713731, Ir = 5629657, Ys = 13238264, _s = 3, Sr = {
727
+ x: 14777725,
728
+ y: 7522190,
729
+ z: 8168927
730
+ };
731
+ function ua(n, a = {}) {
732
+ var vo, Mo;
733
+ const l = (a.createViewer ?? Ui)({
734
+ viewport: n.viewport,
735
+ canvas: n.canvas,
736
+ initialViewMode: "3d",
737
+ clearColor: "#080C0F",
738
+ environment: "room",
739
+ previewDragPreset: "studio",
740
+ autoSelectOnPick: !1,
741
+ pointerPick: !1,
742
+ cadInteraction: "disabled",
743
+ cameraStateStore: !1,
744
+ ui: { root: n.viewport, preset: "none" }
745
+ }), m = new AbortController(), y = (vo = n.sceneOptions) == null ? void 0 : vo.signal, M = () => m.abort(y == null ? void 0 : y.reason);
746
+ y != null && y.aborted ? M() : y == null || y.addEventListener("abort", M, { once: !0 });
747
+ const v = l.openScene([], { ...n.sceneOptions, signal: m.signal, simulationTheme: "dark" }), f = (a.createControls ?? ((e) => new Po(e)))(l.getActiveCamera());
748
+ f.domElement = n.canvas, f.setSpace("world"), f.setSize(ei), Lo(f), f.enabled = !1;
749
+ const x = new Po(l.getActiveCamera());
750
+ x.domElement = n.canvas, x.setSpace("world"), x.setSize(ti), x.setMode("rotate"), x.showX = !1, x.showY = !1, Lo(x, "horizontal-rotation"), x.enabled = !1;
751
+ let S = f;
752
+ const w = ((Mo = a.createRotationGuide) == null ? void 0 : Mo.call(a, n.viewport)) ?? zs(n.viewport, n.canvas.ownerDocument), E = new ot();
753
+ E.name = Mr;
754
+ const j = new ot();
755
+ j.name = "sim-studio:regions", E.add(j), E.add(f.getHelper()), E.add(x.getHelper());
756
+ const k = new Pr(new K(), Bs);
757
+ k.name = "sim-studio:snap-target";
758
+ for (const e of Array.isArray(k.material) ? k.material : [k.material])
759
+ e.depthTest = !1, e.transparent = !0, e.opacity = 0.95;
760
+ k.renderOrder = 1001, k.visible = !1, E.add(k);
761
+ const T = new Pr(new K(), Fs);
762
+ T.name = "sim-studio:prim-focus", T.visible = !1;
763
+ for (const e of Array.isArray(T.material) ? T.material : [T.material])
764
+ e.depthTest = !1, e.transparent = !0, e.opacity = 1;
765
+ T.renderOrder = 1002, E.add(T), l.overlays.set(Mr, E);
766
+ let b = !1, C = null;
767
+ const B = () => {
768
+ C !== null && cancelAnimationFrame(C), C = null;
769
+ };
770
+ let ae = null, J = 0, X = 0, at = -1, ee = [], P = null, lt = [], Xe = {}, xt = /* @__PURE__ */ new Map(), bt = /* @__PURE__ */ new Map(), _t = !1, Ne = !1, De = null, Ee = null, L = [], Me = null, ce = null;
771
+ const ge = /* @__PURE__ */ new Map(), Ve = /* @__PURE__ */ new Map();
772
+ let V = !1, ne = /* @__PURE__ */ new Set(), G = !0, At = !1, I = null, re = null, ct = null, vt = null, dt = !1, Qe = !1, le = null, U = null, He = null, Ie = null, _ = null, je = !1, ut = null, Re = null, ft = !1, te = null, H = null, Xt = !1, Tr = !0, Ge = !1, Ke = it.translate, Vt = !1, Ht = !0, Le = [], Ae = null, Pe = !1, ye = null;
773
+ const _n = 0.35, Xn = 0.08, oi = 0.02;
774
+ let Wr = null, Be = null, Fe = null, $e = null, Vn = !1, xn = 0, Ze = null, Hn = Promise.resolve();
775
+ const Ue = (e) => {
776
+ const t = Hn.then(e);
777
+ return Hn = t.then(() => {
778
+ }, () => {
779
+ }), t;
780
+ }, Et = /* @__PURE__ */ new Map(), Gt = /* @__PURE__ */ new Map(), $t = /* @__PURE__ */ new Map(), Zt = /* @__PURE__ */ new Map(), bn = /* @__PURE__ */ new Map(), Pt = /* @__PURE__ */ new Map(), qe = /* @__PURE__ */ new Map();
781
+ let Gn = 0;
782
+ const Ut = new ys(), Je = /* @__PURE__ */ new Map(), et = /* @__PURE__ */ new Map(), $n = /* @__PURE__ */ new Map(), zr = Us(), Nr = new So({
783
+ map: zr,
784
+ depthTest: !1,
785
+ depthWrite: !1,
786
+ transparent: !0,
787
+ alphaTest: 0.02,
788
+ toneMapped: !1
789
+ }), ke = /* @__PURE__ */ new Map(), Zn = new p(), Dr = new p(), tt = /* @__PURE__ */ new Map(), vn = /* @__PURE__ */ new Map(), qt = /* @__PURE__ */ new Map(), Qt = /* @__PURE__ */ new Map();
790
+ let Ct = null;
791
+ const Mn = [], mt = [], Te = /* @__PURE__ */ new Map(), Y = (e) => {
792
+ var t;
793
+ return ee.find((r) => r.nodeId === e) ?? ((t = Te.get(e)) == null ? void 0 : t.node);
794
+ }, Kt = (e) => e.nodeType === "visual" ? e.visualRevisionId : e.nodeType === "placeholder" ? `placeholder:${e.placeholderVersion}:${e.size.join("x")}` : e.assetRevisionId, Ot = (e) => e.nodeType === "visual" ? JSON.stringify({
795
+ selectionMode: e.selectionMode,
796
+ renderLayer: e.renderLayer,
797
+ appearance: e.appearance ?? null
798
+ }) : e.nodeType === "placeholder" ? JSON.stringify({ size: e.size }) : JSON.stringify({ variantSelections: e.variantSelections }), jr = (e, t) => t === Kt(e) && (e.nodeType === "visual" ? $t.get(e.nodeId) === Ot(e) : e.nodeType === "placeholder" ? Zt.get(e.nodeId) === Ot(e) : Gt.get(e.nodeId) === Ot(e)), In = (e) => xt.get(e.nodeId) ?? e.visible, We = (e) => !!e && In(e) && !(bt.get(e.nodeId) ?? !1), R = (e) => {
799
+ var t;
800
+ return ((t = Te.get(e)) == null ? void 0 : t.object) ?? v.root.getObjectByName(`scene-instance:${e}`);
801
+ }, ii = (e) => {
802
+ const t = R(e);
803
+ t && (t.removeFromParent(), t.traverse((r) => {
804
+ (r instanceof Z || r instanceof an) && (r.geometry.dispose(), (Array.isArray(r.material) ? r.material : [r.material]).forEach((s) => s.dispose()));
805
+ }), N());
806
+ }, si = (e) => {
807
+ const t = new ot();
808
+ t.name = `scene-instance:${e.nodeId}`;
809
+ const r = new ot();
810
+ r.name = `scene-content:${e.nodeId}`;
811
+ const o = Ye(e);
812
+ r.position.set(-o[0], -o[1], -o[2]);
813
+ const s = new pn({
814
+ color: 7252168,
815
+ transparent: !0,
816
+ opacity: 0.32,
817
+ depthWrite: !1
818
+ }), i = new Jo(...e.size), c = new Z(i, s);
819
+ c.userData.studioPlaceholder = !0;
820
+ const u = new an(
821
+ new mr(i),
822
+ new Eo({
823
+ color: 9423080,
824
+ transparent: !0,
825
+ opacity: 0.9,
826
+ depthWrite: !1
827
+ })
828
+ );
829
+ return u.raycast = () => {
830
+ }, r.add(c, u), t.add(r), ze(t, e.localTransform), t.visible = me(e), v.root.add(t), N(), t;
831
+ }, Un = async () => {
832
+ const e = Ze;
833
+ e && (Ze = null, oe(), Ut.remove(e.id), await v.removeInstance(e.id), N());
834
+ }, me = (e) => In(e), Lr = () => {
835
+ if (xt = /* @__PURE__ */ new Map(), bt = /* @__PURE__ */ new Map(), !!P)
836
+ for (const e of ee)
837
+ xt.set(
838
+ e.nodeId,
839
+ Oo(P.root, e.nodeId, Xe)
840
+ ), bt.set(
841
+ e.nodeId,
842
+ ko(P.root, e.nodeId, Xe)
843
+ );
844
+ }, qn = (e) => {
845
+ const t = v.getInstanceBounds(e.nodeId);
846
+ if (t)
847
+ return new K(
848
+ new p().fromArray(t.min),
849
+ new p().fromArray(t.max)
850
+ );
851
+ const r = R(e.nodeId);
852
+ return r ? he(r) : new K();
853
+ }, Qn = (e) => {
854
+ const t = ee.find((c) => c.nodeId === e), r = Te.get(e);
855
+ if (!t && !r) return null;
856
+ const o = R(e), s = o ? zn(o) : null;
857
+ if (!s || s.isEmpty()) return null;
858
+ const i = Ye(t ?? r.node);
859
+ return {
860
+ min: s.min.clone().add(new p().fromArray(i)).toArray(),
861
+ max: s.max.clone().add(new p().fromArray(i)).toArray()
862
+ };
863
+ }, kt = (e) => {
864
+ const t = ee.find((o) => o.nodeId === e);
865
+ if (!t) {
866
+ const o = Te.get(e);
867
+ if (!o) return null;
868
+ const s = he(o.object);
869
+ return s.isEmpty() ? null : { min: s.min.toArray(), max: s.max.toArray() };
870
+ }
871
+ const r = qn(t);
872
+ return r.isEmpty() ? null : { min: r.min.toArray(), max: r.max.toArray() };
873
+ }, Kn = async (e, t) => {
874
+ t.visible = !0;
875
+ try {
876
+ for (let r = 0; r < 5; r += 1) {
877
+ const o = v.getInstanceBounds(e);
878
+ if (o)
879
+ return new K(
880
+ new p().fromArray(o.min),
881
+ new p().fromArray(o.max)
882
+ );
883
+ const s = he(t);
884
+ if (!s.isEmpty()) return s;
885
+ await new Promise((i) => setTimeout(i, 16));
886
+ }
887
+ return new K();
888
+ } finally {
889
+ t.visible = !1;
890
+ }
891
+ }, Rt = (e) => !!e && me(e), Br = (e) => {
892
+ const t = [], r = (o, s) => {
893
+ if (!o.visible) return;
894
+ const i = "material" in o ? o.material : void 0, c = !i || (Array.isArray(i) ? i.some((u) => u.visible && u.opacity > 0) : i.visible && i.opacity > 0);
895
+ o.raycast !== qo.prototype.raycast && c && t.push(o), o.children.forEach((u) => r(u));
896
+ };
897
+ return e.forEach((o) => r(o)), t;
898
+ }, Fr = () => {
899
+ const e = ee.flatMap((t) => {
900
+ const r = qe.get(t.nodeId);
901
+ return r ? [r] : [];
902
+ });
903
+ return {
904
+ revision: J,
905
+ phase: b ? "disposed" : Ee ? "failed" : _t || !Ne ? "loading" : e.length > 0 && e.every((t) => t.phase === "failed") ? "failed" : "ready",
906
+ instances: e,
907
+ physics: v.getScenePhysicsState(),
908
+ error: Ee
909
+ };
910
+ }, Mt = () => {
911
+ var e;
912
+ J += 1, (e = n.onStatus) == null || e.call(n, Fr());
913
+ }, Sn = (e) => e.nodeType === "visual" ? "visual" : e.nodeType === "placeholder" ? "placeholder" : "asset", An = (e) => e.nodeType === "placeholder" ? null : Kt(e), Jn = (e, t = !1) => {
914
+ var r;
915
+ qe.set(e.nodeId, e), Mt(), (r = n.onAssetLoadStatus) == null || r.call(n, e), t && qe.delete(e.nodeId);
916
+ }, nt = (e, t) => {
917
+ const r = qe.get(e.nodeId), o = (/* @__PURE__ */ new Date()).toISOString(), s = {
918
+ sequence: ++Gn,
919
+ nodeId: e.nodeId,
920
+ sourceRevisionId: An(e),
921
+ kind: Sn(e),
922
+ phase: (r == null ? void 0 : r.phase) ?? "queued",
923
+ stage: (r == null ? void 0 : r.stage) ?? null,
924
+ outcome: (r == null ? void 0 : r.outcome) ?? null,
925
+ message: (r == null ? void 0 : r.message) ?? null,
926
+ progress: (r == null ? void 0 : r.progress) ?? null,
927
+ warning: (r == null ? void 0 : r.warning) ?? null,
928
+ error: (r == null ? void 0 : r.error) ?? null,
929
+ startedAt: (r == null ? void 0 : r.startedAt) ?? o,
930
+ updatedAt: o,
931
+ ...t
932
+ };
933
+ return r && Xs(r, s) ? r : (Jn(s), s);
934
+ }, ai = (e) => {
935
+ const t = qe.get(e.nodeId), r = An(e);
936
+ if ((t == null ? void 0 : t.sourceRevisionId) === r && t.kind === Sn(e)) return;
937
+ const o = (/* @__PURE__ */ new Date()).toISOString();
938
+ Jn({
939
+ sequence: ++Gn,
940
+ nodeId: e.nodeId,
941
+ sourceRevisionId: r,
942
+ kind: Sn(e),
943
+ phase: "queued",
944
+ stage: null,
945
+ outcome: null,
946
+ message: null,
947
+ progress: null,
948
+ warning: null,
949
+ error: null,
950
+ startedAt: o,
951
+ updatedAt: o
952
+ });
953
+ }, En = (e) => {
954
+ const t = qe.get(e);
955
+ if (!t) return;
956
+ const r = (/* @__PURE__ */ new Date()).toISOString();
957
+ Jn({
958
+ ...t,
959
+ sequence: ++Gn,
960
+ phase: "closed",
961
+ stage: null,
962
+ outcome: null,
963
+ message: null,
964
+ progress: null,
965
+ warning: null,
966
+ error: null,
967
+ updatedAt: r
968
+ }, !0);
969
+ }, li = (e) => ({
970
+ stage(t, r) {
971
+ b || nt(e, {
972
+ phase: "loading",
973
+ stage: t,
974
+ outcome: null,
975
+ message: r ?? null
976
+ });
977
+ },
978
+ progress(t) {
979
+ b || nt(e, {
980
+ phase: "loading",
981
+ progress: { ...t }
982
+ });
983
+ }
984
+ }), It = (e) => {
985
+ var t;
986
+ b || (t = n.onError) == null || t.call(n, e);
987
+ }, Yr = (e) => {
988
+ var i, c, u;
989
+ const t = Y(e.id), r = t ? qe.get(e.id) : void 0;
990
+ if (!t || !r || r.sourceRevisionId !== An(t)) return;
991
+ if (e.phase === "closed") {
992
+ En(e.id);
993
+ return;
994
+ }
995
+ const o = Hs(e.warning);
996
+ if (e.phase === "pending") {
997
+ r.phase !== "queued" && nt(t, { phase: "queued" });
998
+ return;
999
+ }
1000
+ if (e.phase === "loading") {
1001
+ nt(t, {
1002
+ phase: "loading",
1003
+ stage: Vs(e.stage),
1004
+ outcome: null,
1005
+ message: e.message ?? r.message,
1006
+ progress: e.progress ? { ...e.progress } : r.progress,
1007
+ warning: o,
1008
+ error: null
1009
+ });
1010
+ return;
1011
+ }
1012
+ if (e.phase === "ready") {
1013
+ const d = o !== null || ((i = e.physics) == null ? void 0 : i.status) === "unavailable";
1014
+ nt(t, {
1015
+ phase: "ready",
1016
+ stage: null,
1017
+ outcome: d ? "degraded" : "full",
1018
+ message: e.message ?? null,
1019
+ progress: null,
1020
+ warning: o,
1021
+ error: null
1022
+ });
1023
+ return;
1024
+ }
1025
+ const s = r.stage ?? "parsing-visual";
1026
+ nt(t, {
1027
+ phase: "failed",
1028
+ stage: null,
1029
+ outcome: null,
1030
+ message: null,
1031
+ progress: null,
1032
+ warning: o,
1033
+ error: {
1034
+ code: ((c = e.error) == null ? void 0 : c.code) ?? "ASSET_LOAD_FAILED",
1035
+ message: ((u = e.error) == null ? void 0 : u.message) ?? "Asset loading failed.",
1036
+ stage: s
1037
+ }
1038
+ });
1039
+ }, N = () => {
1040
+ b || l.requestRender();
1041
+ }, er = (e) => {
1042
+ const t = n.canvas.ownerDocument.defaultView;
1043
+ return typeof (t == null ? void 0 : t.requestAnimationFrame) == "function" ? t.requestAnimationFrame(e) : typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : (e(0), null);
1044
+ }, Tt = (e) => {
1045
+ if (e === null) return;
1046
+ const t = n.canvas.ownerDocument.defaultView;
1047
+ if (typeof (t == null ? void 0 : t.cancelAnimationFrame) == "function") {
1048
+ t.cancelAnimationFrame(e);
1049
+ return;
1050
+ }
1051
+ typeof cancelAnimationFrame == "function" && cancelAnimationFrame(e);
1052
+ }, _r = (e, t, r) => {
1053
+ var c;
1054
+ if (!r.length) return null;
1055
+ const o = n.canvas.getBoundingClientRect();
1056
+ if (o.width <= 0 || o.height <= 0) return null;
1057
+ const s = l.getActiveCamera();
1058
+ s.updateMatrixWorld(!0), E.updateMatrixWorld(!0);
1059
+ const i = new St();
1060
+ return i.setFromCamera(new sn(
1061
+ (e - o.left) / o.width * 2 - 1,
1062
+ -(t - o.top) / o.height * 2 + 1
1063
+ ), s), ((c = i.intersectObjects([...r], !1)[0]) == null ? void 0 : c.object) ?? null;
1064
+ }, Xr = (e, t) => {
1065
+ const r = _r(e, t, [...tt.values()]);
1066
+ return (r == null ? void 0 : r.userData.simStudioRegionId) ?? null;
1067
+ }, Vr = (e, t) => {
1068
+ const r = [...qt.values()];
1069
+ if (!r.length) return null;
1070
+ const o = _r(e, t, r), s = o == null ? void 0 : o.userData.simStudioRegionId, i = o == null ? void 0 : o.userData.simStudioRegionShapeHandle;
1071
+ return s && i ? { regionId: s, handle: i } : null;
1072
+ }, ci = (e) => {
1073
+ if (Ct) {
1074
+ for (const t of Wo(e)) {
1075
+ const r = qt.get(t.id);
1076
+ r && r.position.fromArray(t.position);
1077
+ }
1078
+ Ct.updateMatrixWorld(!0);
1079
+ }
1080
+ }, tr = (e, t) => {
1081
+ const r = _o({ shape: t });
1082
+ e.geometry !== r && (e.geometry.dispose(), e.geometry = r);
1083
+ const o = e.children.find((s) => s instanceof an);
1084
+ o && (o.geometry.dispose(), o.geometry = new mr(r, 20)), ci(t), e.updateMatrixWorld(!0), N();
1085
+ }, Hr = () => {
1086
+ Ie && en(), Ct = null, qt.clear(), Qt.clear(), j.clear();
1087
+ for (const e of Mn.splice(0)) e.dispose();
1088
+ tt.clear(), vn.clear();
1089
+ }, di = (e, t) => {
1090
+ if (ce !== e.regionId || !G) return;
1091
+ const r = new ot();
1092
+ r.name = `sim-studio:region-handles:${e.regionId}`;
1093
+ const o = Math.max(0.08, Math.min(0.14, No(e) * 0.04)), s = o * 1.45, i = new $o(o, 10, 6), c = new pn({
1094
+ colorWrite: !1,
1095
+ depthTest: !1,
1096
+ depthWrite: !1,
1097
+ transparent: !0,
1098
+ opacity: 0
1099
+ }), u = Zs();
1100
+ Mn.push(
1101
+ { dispose: () => i.dispose() },
1102
+ { dispose: () => c.dispose() },
1103
+ { dispose: () => u.dispose() }
1104
+ );
1105
+ for (const d of Wo(e.shape)) {
1106
+ const g = d.axis ? Sr[d.axis] : Ir, h = new Z(i, c);
1107
+ h.name = `sim-studio:region-handle-target:${e.regionId}:${d.id}`, h.position.fromArray(d.position), h.userData.simStudioRegionId = e.regionId, h.userData.simStudioRegionShapeHandle = d;
1108
+ const A = new So({
1109
+ map: u,
1110
+ color: g,
1111
+ depthTest: !1,
1112
+ depthWrite: !1,
1113
+ transparent: !0,
1114
+ alphaTest: 0.02,
1115
+ toneMapped: !1
1116
+ }), O = new Ao(A);
1117
+ O.name = `sim-studio:region-handle-visual:${e.regionId}:${d.id}`, O.scale.set(s, s, 1), O.renderOrder = 950, O.raycast = () => {
1118
+ }, h.add(O), r.add(h), qt.set(d.id, h), Qt.set(d.id, O), Mn.push({ dispose: () => A.dispose() });
1119
+ }
1120
+ t.add(r), Ct = r;
1121
+ }, nr = () => {
1122
+ if (!b && (Hr(), !!P)) {
1123
+ for (const e of lt) {
1124
+ const t = $s(P.root, e.parentNodeId);
1125
+ if (!t) continue;
1126
+ const r = new ot();
1127
+ r.name = `sim-studio:region-parent:${e.parentNodeId}`, r.matrixAutoUpdate = !1, r.matrix.copy(t), r.matrixWorldNeedsUpdate = !0;
1128
+ const o = new ot();
1129
+ o.name = `sim-studio:region:${e.regionId}`, o.userData.simStudioRegionId = e.regionId, ze(o, e.frame);
1130
+ const s = _o(e), i = new pn({
1131
+ color: ne.has(e.regionId) ? fn : ce === e.regionId ? wt : Dn,
1132
+ transparent: !0,
1133
+ opacity: ce === e.regionId ? 0.34 : 0.2,
1134
+ depthWrite: !1,
1135
+ side: Uo
1136
+ }), c = new Z(s, i);
1137
+ c.name = `scene-region:${e.regionId}`, c.userData.simStudioRegionId = e.regionId, c.renderOrder = 900, c.quaternion.copy(Ks(e.normalAxis));
1138
+ const u = new mr(s, 20), d = new Eo({
1139
+ color: ne.has(e.regionId) ? fn : ce === e.regionId ? wt : Dn,
1140
+ transparent: !0,
1141
+ opacity: ce === e.regionId ? 1 : 0.72,
1142
+ depthTest: !1
1143
+ }), g = new an(u, d);
1144
+ g.renderOrder = 901, g.raycast = () => {
1145
+ }, c.add(g);
1146
+ const h = new Vi(
1147
+ Js(e.normalAxis),
1148
+ new p(0, 0, 0),
1149
+ Math.max(0.15, Math.min(0.6, No(e) * 0.35)),
1150
+ ne.has(e.regionId) ? fn : wt,
1151
+ 0.1,
1152
+ 0.05
1153
+ );
1154
+ h.renderOrder = 902, h.traverse((A) => {
1155
+ A.raycast = () => {
1156
+ };
1157
+ }), o.add(c, h), r.add(o), j.add(r), tt.set(e.regionId, c), vn.set(e.regionId, o), Mn.push(
1158
+ { dispose: () => c.geometry.dispose() },
1159
+ { dispose: () => i.dispose() },
1160
+ { dispose: () => g.geometry.dispose() },
1161
+ { dispose: () => d.dispose() }
1162
+ ), di(e, c);
1163
+ }
1164
+ j.visible = V, N();
1165
+ }
1166
+ }, ui = () => {
1167
+ const e = I;
1168
+ if (!e || e.kind !== "instance") return;
1169
+ const t = Oe(e.group), r = Math.min(1, Math.abs(
1170
+ t.rotation[0] * e.base.rotation[0] + t.rotation[1] * e.base.rotation[1] + t.rotation[2] * e.base.rotation[2] + t.rotation[3] * e.base.rotation[3]
1171
+ ));
1172
+ return {
1173
+ mode: e.mode,
1174
+ space: S.space,
1175
+ axis: U ? "Z" : S.axis ?? null,
1176
+ translationDelta: t.position.map(
1177
+ (o, s) => o - e.base.position[s]
1178
+ ),
1179
+ rotationDeltaRadians: 2 * Math.acos(r),
1180
+ scaleRatio: t.scale.map(
1181
+ (o, s) => o / e.base.scale[s]
1182
+ )
1183
+ };
1184
+ }, we = () => {
1185
+ if (b) {
1186
+ w == null || w.hide();
1187
+ return;
1188
+ }
1189
+ if (Jt(), !n.onSelectionOverlayChange) return;
1190
+ const e = !!I || !!Ie, t = {
1191
+ x: 0,
1192
+ y: 0,
1193
+ visible: !1,
1194
+ transforming: e,
1195
+ hiddenReason: te ? "selecting" : e ? "transforming" : G ? !Me && !ce ? "no-selection" : "anchor-unavailable" : "editing-disabled"
1196
+ }, r = V && ce ? tt.get(ce) : void 0, o = Me ? Y(Me) : void 0, s = V ? r : Me ? R(Me) : void 0, i = !V && (!Me || !L.includes(Me) || !Rt(o));
1197
+ if (te || !G || i || !s) {
1198
+ n.onSelectionOverlayChange(t);
1199
+ return;
1200
+ }
1201
+ const c = V ? new K().setFromObject(s, !0) : he(s);
1202
+ if (!V) for (const W of L) {
1203
+ const $ = Y(W), ie = R(W);
1204
+ $ && ie && Rt($) && c.union(he(ie));
1205
+ }
1206
+ const u = n.canvas.getBoundingClientRect(), d = n.viewport.getBoundingClientRect();
1207
+ if (c.isEmpty() || u.width <= 0 || u.height <= 0) {
1208
+ n.onSelectionOverlayChange(t);
1209
+ return;
1210
+ }
1211
+ const g = l.getActiveCamera();
1212
+ g.updateMatrixWorld(!0);
1213
+ let h = 1 / 0, A = -1 / 0, O = 1 / 0, D = -1 / 0, z = !1;
1214
+ for (const W of [c.min.x, c.max.x]) for (const $ of [c.min.y, c.max.y]) for (const ie of [c.min.z, c.max.z]) {
1215
+ const F = new p(W, $, ie).project(g);
1216
+ [F.x, F.y, F.z].every(Number.isFinite) && (F.z >= -1 && F.z <= 1 && (z = !0), h = Math.min(h, F.x), A = Math.max(A, F.x), O = Math.min(O, F.y), D = Math.max(D, F.y));
1217
+ }
1218
+ if (!(z && A >= -1 && h <= 1 && D >= -1 && O <= 1)) {
1219
+ n.onSelectionOverlayChange(t);
1220
+ return;
1221
+ }
1222
+ const be = ui(), ue = Le.length > 0 && !Pe, Se = (I == null ? void 0 : I.kind) === "instance" ? {
1223
+ valid: !ue && !Ae,
1224
+ conflictIds: Le,
1225
+ message: ue ? "与其他资产重叠,不可放置" : Ae,
1226
+ allowOverlap: Pe
1227
+ } : void 0;
1228
+ n.onSelectionOverlayChange({
1229
+ x: u.left - d.left + (Math.max(-1, Math.min(1, (h + A) / 2)) + 1) * u.width / 2,
1230
+ y: u.top - d.top + (1 - Math.max(-1, Math.min(1, D))) * u.height / 2,
1231
+ visible: !0,
1232
+ transforming: !!I || !!Ie,
1233
+ hiddenReason: e ? "transforming" : null,
1234
+ ...be ? { feedback: be } : {},
1235
+ ...Se ? { placement: Se } : {}
1236
+ });
1237
+ }, rt = () => {
1238
+ var t;
1239
+ if (b) return;
1240
+ const e = (G || At) && !V;
1241
+ for (const r of ke.values())
1242
+ r.visible = e && r.userData.simStudioOriginBaseVisible === !0;
1243
+ for (const [r, o] of Je) {
1244
+ const s = Y(r), i = R(r);
1245
+ o.setColor(
1246
+ Le.length > 0 && !Pe || Ae !== null ? Fo : wt
1247
+ ), o.visible = !V && !!i && !!s && me(s), o.visible && ((t = o.parent) == null || t.updateWorldMatrix(!0, !1), o.updateFromObject(i), o.visible = !o.box.isEmpty(), o.updateMatrixWorld(!0));
1248
+ }
1249
+ we(), N();
1250
+ }, Wt = (e) => {
1251
+ const t = ke.get(e), r = R(e), o = t == null ? void 0 : t.userData.simStudioOriginLocal;
1252
+ !t || !r || !o || (r.updateWorldMatrix(!0, !1), r.localToWorld(Zn.fromArray(o)), t.parent ? (t.parent.updateWorldMatrix(!0, !1), t.parent.worldToLocal(Dr.copy(Zn)), t.position.copy(Dr)) : t.position.copy(Zn), t.updateWorldMatrix(!0, !1));
1253
+ }, pt = (e, t, r) => {
1254
+ t.updateWorldMatrix(!0, !1);
1255
+ const o = t.localToWorld(r.clone());
1256
+ Ft(e, o);
1257
+ const s = t.getWorldQuaternion(new se()), i = t.getWorldScale(new p());
1258
+ Xo(e, s), ea(e, i), e.updateMatrixWorld(!0);
1259
+ }, fi = (e, t, r) => {
1260
+ t.updateWorldMatrix(!0, !1);
1261
+ const o = t.worldToLocal(r.clone());
1262
+ e.userData.simStudioPivotLocal = o.toArray(), pt(e, t, o);
1263
+ }, Gr = (e, t, r) => {
1264
+ const o = e.getWorldPosition(new p()), s = e.getWorldQuaternion(new se()).normalize(), i = e.getWorldScale(new p()), c = r.clone().multiply(i).applyQuaternion(s), u = o.sub(c), d = t.parent, g = (d == null ? void 0 : d.getWorldQuaternion(new se()).normalize()) ?? new se(), h = (d == null ? void 0 : d.getWorldScale(new p())) ?? new p(1, 1, 1), A = d ? d.worldToLocal(u) : u, O = g.invert().multiply(s).normalize(), D = i.divide(h);
1265
+ return {
1266
+ position: A.toArray(),
1267
+ rotation: O.toArray(),
1268
+ scale: D.toArray()
1269
+ };
1270
+ }, $r = (e, t) => {
1271
+ const r = e.parent;
1272
+ if (!r) {
1273
+ e.position.add(t), e.updateMatrixWorld(!0);
1274
+ return;
1275
+ }
1276
+ r.updateWorldMatrix(!0, !1);
1277
+ const o = new p(), s = t.clone();
1278
+ r.worldToLocal(o), r.worldToLocal(s), e.position.add(s.sub(o)), e.updateMatrixWorld(!0);
1279
+ }, ht = () => {
1280
+ var t, r, o;
1281
+ const e = _;
1282
+ _ = null, e !== null && ((t = ut == null ? void 0 : ut.hasPointerCapture) != null && t.call(ut, e) ? ut.releasePointerCapture(e) : (o = (r = n.canvas).hasPointerCapture) != null && o.call(r, e) && n.canvas.releasePointerCapture(e)), ut = null;
1283
+ }, zt = (e) => {
1284
+ const t = l.getActiveCamera();
1285
+ t.updateMatrixWorld(!0);
1286
+ const r = e.clone().project(t), o = n.canvas.getBoundingClientRect();
1287
+ return {
1288
+ x: o.left + (r.x + 1) * o.width / 2,
1289
+ y: o.top + (1 - r.y) * o.height / 2
1290
+ };
1291
+ }, Nt = (e) => {
1292
+ const t = zt(e), r = n.viewport.getBoundingClientRect();
1293
+ return { x: t.x - r.left, y: t.y - r.top };
1294
+ }, Zr = () => {
1295
+ if (!w || b || !G || V || !f.object) return null;
1296
+ if (U)
1297
+ return {
1298
+ center: U.center.clone(),
1299
+ axisX: U.axisX.clone(),
1300
+ axisY: U.axisY.clone(),
1301
+ normal: U.normal.clone(),
1302
+ radius: U.radius,
1303
+ startAngle: U.startAngle,
1304
+ delta: U.delta,
1305
+ active: !0
1306
+ };
1307
+ if ((le == null ? void 0 : le.object) === f.object)
1308
+ return {
1309
+ center: le.center.clone(),
1310
+ axisX: le.axisX.clone(),
1311
+ axisY: le.axisY.clone(),
1312
+ normal: le.normal.clone(),
1313
+ radius: le.radius,
1314
+ startAngle: le.startAngle,
1315
+ delta: le.delta,
1316
+ active: !1
1317
+ };
1318
+ const e = new K();
1319
+ for (const pe of L) {
1320
+ const on = Y(pe), Io = R(pe);
1321
+ on && Io && me(on) && e.union(he(Io));
1322
+ }
1323
+ if (e.isEmpty()) return null;
1324
+ f.object.updateWorldMatrix(!0, !1);
1325
+ const t = f.object.getWorldPosition(new p()), r = f.object.getWorldQuaternion(new se()).normalize();
1326
+ let o = new p(1, 0, 0), s = new p(0, 1, 0), i = new p(0, 0, 1);
1327
+ f.space === "local" && (o = o.applyQuaternion(r).normalize(), s = s.applyQuaternion(r).normalize(), i = i.applyQuaternion(r).normalize());
1328
+ const c = e.getSize(new p()), u = Math.max(0.55, Math.max(c.x, c.y) * 0.68, c.z * 0.36), d = n.viewport.getBoundingClientRect(), g = Nt(t), h = Wn({
1329
+ min: e.min.toArray(),
1330
+ max: e.max.toArray()
1331
+ }).map((pe) => Nt(new p().fromArray(pe))), A = Math.min(...h.map((pe) => pe.x)), O = Math.max(...h.map((pe) => pe.x)), D = Math.min(...h.map((pe) => pe.y)), z = Math.max(...h.map((pe) => pe.y)), de = Math.max(O - A, z - D) * 0.5, be = Math.min(d.width, d.height), ue = be * 0.3, Se = be * 0.46, W = Math.min(
1332
+ g.x,
1333
+ d.width - g.x,
1334
+ g.y,
1335
+ d.height - g.y
1336
+ ) - 24, $ = Math.min(
1337
+ Se,
1338
+ Math.max(96, W),
1339
+ Math.max(
1340
+ ue,
1341
+ Number.isFinite(de) ? de * 1.25 + 24 : ue
1342
+ )
1343
+ ), ie = Nt(t.clone().add(o)), F = Nt(t.clone().add(s)), Ce = Math.max(
1344
+ Math.hypot(ie.x - g.x, ie.y - g.y),
1345
+ Math.hypot(F.x - g.x, F.y - g.y)
1346
+ ), ve = Ce > 1e-6 ? $ / Ce : u;
1347
+ return {
1348
+ center: t,
1349
+ axisX: o,
1350
+ axisY: s,
1351
+ normal: i,
1352
+ radius: ve,
1353
+ startAngle: -Math.PI / 2,
1354
+ delta: 0,
1355
+ active: !1
1356
+ };
1357
+ }, Ur = () => {
1358
+ if (!w || b || !G || !f.object || f.getMode() !== "translate" || V) return null;
1359
+ const e = new K();
1360
+ for (const u of L) {
1361
+ const d = Y(u), g = R(u);
1362
+ d && g && me(d) && e.union(he(g));
1363
+ }
1364
+ if (e.isEmpty()) return null;
1365
+ const t = l.getActiveCamera();
1366
+ t.updateMatrixWorld(!0);
1367
+ const r = n.viewport.getBoundingClientRect(), o = n.canvas.getBoundingClientRect(), s = Wn({
1368
+ min: e.min.toArray(),
1369
+ max: e.max.toArray()
1370
+ }).map((u) => {
1371
+ const d = new p().fromArray(u).project(t);
1372
+ return {
1373
+ x: o.left - r.left + (d.x + 1) * o.width / 2,
1374
+ y: o.top - r.top + (1 - d.y) * o.height / 2
1375
+ };
1376
+ }), i = Math.min(...s.map((u) => u.x)), c = s.filter((u) => u.x <= i + 18).reduce((u, d) => d.y > u.y ? d : u, s[0]);
1377
+ return {
1378
+ x: Math.max(24, Math.min(r.width - 24, c.x - 22)),
1379
+ y: Math.max(30, Math.min(r.height - 30, c.y - 2))
1380
+ };
1381
+ }, Jt = () => {
1382
+ if (!w) return;
1383
+ if (!G) {
1384
+ ct = null, vt = null, dt = !1, Qe = !1, le = null, w.hide();
1385
+ return;
1386
+ }
1387
+ const e = n.viewport.getBoundingClientRect(), t = f.getMode() === "rotate" || dt || Qe || !!U, r = f.getMode() === "translate" && !U && !Qe;
1388
+ if (!t) {
1389
+ if (ct = null, vt = r ? Ur() : null, !vt) {
1390
+ w.hide();
1391
+ return;
1392
+ }
1393
+ w.render({
1394
+ ...mi,
1395
+ width: e.width,
1396
+ height: e.height,
1397
+ project: Nt,
1398
+ showRing: !1,
1399
+ showHandle: !0,
1400
+ handlePoint: vt
1401
+ });
1402
+ return;
1403
+ }
1404
+ const o = Zr();
1405
+ if (ct = o, vt = Ur(), !o) {
1406
+ w.hide();
1407
+ return;
1408
+ }
1409
+ w.render({
1410
+ ...o,
1411
+ width: e.width,
1412
+ height: e.height,
1413
+ project: Nt,
1414
+ showRing: t,
1415
+ showHandle: r,
1416
+ ...vt ? { handlePoint: vt } : {}
1417
+ });
1418
+ }, qr = new St(), Qr = new sn(), mi = {
1419
+ center: new p(),
1420
+ axisX: new p(1, 0, 0),
1421
+ axisY: new p(0, 1, 0),
1422
+ normal: new p(0, 0, 1),
1423
+ radius: 0,
1424
+ startAngle: 0,
1425
+ delta: 0,
1426
+ active: !1
1427
+ }, rr = (e, t, r, o) => {
1428
+ const s = n.canvas.getBoundingClientRect();
1429
+ if (s.width <= 0 || s.height <= 0) return null;
1430
+ const i = l.getActiveCamera();
1431
+ return i.updateMatrixWorld(!0), Qr.set(
1432
+ (e - s.left) / s.width * 2 - 1,
1433
+ -(t - s.top) / s.height * 2 + 1
1434
+ ), qr.setFromCamera(Qr, i), qr.ray.intersectPlane(r, o);
1435
+ }, Kr = (e, t, r, o, s, i, c) => {
1436
+ const u = rr(e, t, i, c);
1437
+ if (!u) return null;
1438
+ const d = u.sub(r), g = d.dot(o), h = d.dot(s);
1439
+ return Math.hypot(g, h) < 1e-5 ? null : Math.atan2(h, g);
1440
+ }, pi = (e, t, r) => {
1441
+ const o = n.canvas.getBoundingClientRect();
1442
+ if (o.width <= 0 || o.height <= 0) return null;
1443
+ e.updateWorldMatrix(!0, !1);
1444
+ const s = l.getActiveCamera();
1445
+ s.updateMatrixWorld(!0);
1446
+ const i = new St();
1447
+ i.setFromCamera(new sn(
1448
+ (t - o.left) / o.width * 2 - 1,
1449
+ -(r - o.top) / o.height * 2 + 1
1450
+ ), s);
1451
+ const c = new p(0, 0, 1).applyQuaternion(e.getWorldQuaternion(new se()).normalize()).normalize(), u = e.getWorldPosition(new p()), d = i.ray.intersectPlane(
1452
+ new mn().setFromNormalAndCoplanarPoint(c, u),
1453
+ new p()
1454
+ );
1455
+ return d ? e.worldToLocal(d) : null;
1456
+ }, hi = (e, t, r, o) => {
1457
+ const s = lt.find((d) => d.regionId === e), i = tt.get(e);
1458
+ if (!s || !i) return !1;
1459
+ let c = null;
1460
+ if (t.mode === "axis" && t.axis && t.sign) {
1461
+ i.updateWorldMatrix(!0, !1);
1462
+ const d = i.localToWorld(new p().fromArray(t.position)), g = new p(
1463
+ t.axis === "x" ? t.sign : 0,
1464
+ t.axis === "y" ? t.sign : 0,
1465
+ t.axis === "z" ? t.sign : 0
1466
+ ).applyQuaternion(i.getWorldQuaternion(new se()).normalize()).normalize(), h = zt(d), A = zt(d.clone().addScaledVector(g, 0.1)), O = A.x - h.x, D = A.y - h.y, z = Math.hypot(O, D);
1467
+ z > 0.5 && (c = {
1468
+ x: O / z,
1469
+ y: D / z,
1470
+ pixelsPerMetre: z / 0.1
1471
+ });
1472
+ }
1473
+ Ie = {
1474
+ regionId: e,
1475
+ mesh: i,
1476
+ handle: t,
1477
+ baseShape: s.shape,
1478
+ startClient: { x: r, y: o },
1479
+ axisScreen: c,
1480
+ currentShape: s.shape,
1481
+ moved: !1
1482
+ };
1483
+ const u = Qt.get(t.id);
1484
+ return u && u.material.color.setHex(Ys), n.canvas.style.cursor = "grabbing", l.setNavigationEnabled(!1), we(), !0;
1485
+ }, en = () => {
1486
+ const e = Ie;
1487
+ if (Ie = null, !e) return;
1488
+ const t = Qt.get(e.handle.id);
1489
+ t && t.material.color.setHex(
1490
+ e.handle.axis ? Sr[e.handle.axis] : Ir
1491
+ ), tr(e.mesh, e.baseShape), n.canvas.style.cursor = "", l.setNavigationEnabled(!0), we(), ht();
1492
+ }, tn = () => {
1493
+ const e = !!w && (f.getMode() === "translate" || f.getMode() === "rotate");
1494
+ f.getHelper().visible = !e && !!f.object && (!I || S === f), x.getHelper().visible = !w && !!x.object && (!I || S === x), Jt();
1495
+ }, Dt = (e, t) => {
1496
+ const r = Object.fromEntries(e.instances.map((o) => [
1497
+ o.nodeId,
1498
+ {
1499
+ hidden: !me(o),
1500
+ locked: bt.get(o.nodeId) ?? !1
1501
+ }
1502
+ ]));
1503
+ for (const o of bs(e.instances, e.id, t, r)) {
1504
+ const s = R(o.nodeId);
1505
+ if (!s) continue;
1506
+ ze(s, o.localTransform), Wt(o.nodeId);
1507
+ const i = Y(o.nodeId);
1508
+ v.previewInstancePlacement(o.nodeId, {
1509
+ ...o.localTransform,
1510
+ ...i ? { pivot: Ye(i) } : {}
1511
+ });
1512
+ }
1513
+ }, oe = () => {
1514
+ je = !1, Pi(), te = null, Tt((re == null ? void 0 : re.frameId) ?? null), Tt((U == null ? void 0 : U.frameId) ?? null), re = null, U = null, H && (H.hidden = !0), Ie && en(), Re = null;
1515
+ const e = I;
1516
+ if (I = null, Be = null, Fe = null, $e = null, Ae = null, nn(null), e) {
1517
+ if (e.kind === "region")
1518
+ ze(e.group, e.base);
1519
+ else
1520
+ for (const t of e.instances) {
1521
+ const r = R(t.nodeId);
1522
+ r && (ze(r, t.localTransform), Wt(t.nodeId), v.previewInstancePlacement(t.nodeId, {
1523
+ ...t.localTransform,
1524
+ pivot: Ye(t)
1525
+ }));
1526
+ }
1527
+ pt(e.object, e.group, e.pivotLocal);
1528
+ }
1529
+ S.dragging && S.pointerUp({ button: 0 }), f.getHelper().userData.simStudioCenterDrag = !1, tn(), l.setNavigationEnabled(!0), ht(), rt();
1530
+ }, gi = () => {
1531
+ var r;
1532
+ if (!P || I) return;
1533
+ const e = Co(P.root).filter(
1534
+ (o) => o.nodeType === "group" && o.nodeId !== P.root.nodeId
1535
+ ), t = new Set(e.map((o) => o.nodeId));
1536
+ for (const [o, s] of Te)
1537
+ t.has(o) || (s.object.traverse((i) => {
1538
+ i instanceof Z && (i.geometry.dispose(), i.material.dispose());
1539
+ }), Te.delete(o));
1540
+ for (const o of e) {
1541
+ const s = Rn(P.root, o.nodeId);
1542
+ if (!s) continue;
1543
+ const i = ee.filter(
1544
+ (h) => cn(P.root, h.nodeId).some(
1545
+ (A) => A.nodeId === o.nodeId
1546
+ )
1547
+ ), c = new K();
1548
+ for (const h of i)
1549
+ In(h) && c.union(qn(h));
1550
+ if (c.isEmpty()) {
1551
+ const h = (r = Tn(P, o.nodeId)) == null ? void 0 : r.worldBounds;
1552
+ h && c.set(new p().fromArray(h.min), new p().fromArray(h.max));
1553
+ }
1554
+ let u = Te.get(o.nodeId);
1555
+ if (!u) {
1556
+ const h = new ot();
1557
+ h.name = "sim-studio:group-proxy:" + o.nodeId;
1558
+ const A = new Z(new Ln(), new pn({ visible: !1 }));
1559
+ A.raycast = () => {
1560
+ }, h.add(A), u = {
1561
+ object: h,
1562
+ node: {
1563
+ nodeType: "placeholder",
1564
+ placeholderVersion: 1,
1565
+ nodeId: o.nodeId,
1566
+ label: o.label,
1567
+ size: [0, 0, 0],
1568
+ role: "object",
1569
+ visible: !0,
1570
+ localTransform: s
1571
+ }
1572
+ }, Te.set(o.nodeId, u);
1573
+ }
1574
+ u.node = { ...u.node, label: o.label, localTransform: s }, ze(u.object, s), u.object.updateWorldMatrix(!0, !0);
1575
+ const d = u.object.children[0], g = [];
1576
+ for (const h of i) {
1577
+ if (!In(h)) continue;
1578
+ const A = R(h.nodeId);
1579
+ if (!A) continue;
1580
+ const O = zn(A);
1581
+ if (!O.isEmpty())
1582
+ for (const D of Wn({ min: O.min.toArray(), max: O.max.toArray() }))
1583
+ g.push(
1584
+ ...u.object.worldToLocal(A.localToWorld(new p().fromArray(D))).toArray()
1585
+ );
1586
+ }
1587
+ if (!g.length && !c.isEmpty())
1588
+ for (const h of Wn({ min: c.min.toArray(), max: c.max.toArray() }))
1589
+ g.push(...u.object.worldToLocal(new p().fromArray(h)).toArray());
1590
+ d.geometry.dispose(), d.geometry = new Ln().setAttribute(
1591
+ "position",
1592
+ new Hi(g, 3)
1593
+ ), xt.set(
1594
+ o.nodeId,
1595
+ Oo(P.root, o.nodeId, Xe)
1596
+ ), bt.set(
1597
+ o.nodeId,
1598
+ ko(P.root, o.nodeId, Xe) || i.some((h) => bt.get(h.nodeId))
1599
+ );
1600
+ }
1601
+ }, xe = () => {
1602
+ if (b) return;
1603
+ gi();
1604
+ const e = (G || At) && !V, t = new Set(e ? L.filter((d) => Y(d) && R(d)) : []), r = /* @__PURE__ */ new Set();
1605
+ if (e && P)
1606
+ for (const d of t) {
1607
+ const g = ln(P.root, d);
1608
+ if ((g == null ? void 0 : g.nodeType) !== "group") {
1609
+ r.add(d);
1610
+ continue;
1611
+ }
1612
+ for (const h of ee)
1613
+ me(h) && cn(P.root, h.nodeId).some((A) => A.nodeId === d) && r.add(h.nodeId);
1614
+ }
1615
+ const o = new K();
1616
+ if (G && !V)
1617
+ for (const d of L) {
1618
+ const g = Y(d), h = R(d);
1619
+ We(g) && h && o.union(he(h));
1620
+ }
1621
+ const i = (L.length === 1 && P ? (() => {
1622
+ const d = L[0], g = ge.get(d);
1623
+ if (g) {
1624
+ const A = hr(P.root, d);
1625
+ if (A) return new p(...g).applyMatrix4(jn(A));
1626
+ }
1627
+ const h = Tn(
1628
+ P,
1629
+ d,
1630
+ kt,
1631
+ Qn
1632
+ );
1633
+ return h != null && h.origin.world ? new p().fromArray(h.origin.world) : null;
1634
+ })() : null) ?? (o.isEmpty() ? null : o.getCenter(new p()));
1635
+ for (const d of /* @__PURE__ */ new Set([...r, ...t])) {
1636
+ if (r.has(d) && !Je.has(d)) {
1637
+ const h = new Ps(wt);
1638
+ h.renderOrder = 1e3, Je.set(d, h), E.add(h);
1639
+ }
1640
+ if (G && t.has(d) && !et.has(d)) {
1641
+ const h = new ot();
1642
+ h.name = "sim-studio:gizmo-anchor", h.userData.simStudioInstanceId = d, et.set(d, h), E.add(h);
1643
+ }
1644
+ const g = P ? Tn(
1645
+ P,
1646
+ d,
1647
+ kt,
1648
+ Qn
1649
+ ) : null;
1650
+ if (g != null && g.origin.world && g.origin.local) {
1651
+ let h = ke.get(d);
1652
+ h || (h = new Ao(Nr), h.name = `sim-studio:origin-marker:${d}`, h.userData.simStudioOriginNodeId = d, h.raycast = () => {
1653
+ }, h.frustumCulled = !1, h.renderOrder = 1003, ke.set(d, h), E.add(h));
1654
+ const A = Y(d);
1655
+ h.userData.simStudioOriginBaseVisible = !!A && me(A), h.userData.simStudioOriginLocal = [0, 0, 0], Wt(d);
1656
+ const O = Qs(g.worldBounds);
1657
+ h.scale.set(O, O, 1);
1658
+ } else {
1659
+ const h = ke.get(d);
1660
+ h && (E.remove(h), ke.delete(d));
1661
+ }
1662
+ if (G && t.has(d) && (I == null ? void 0 : I.object) !== et.get(d)) {
1663
+ const h = R(d), A = et.get(d);
1664
+ if (L.length === 1 && ge.has(d) && P) {
1665
+ const O = hr(P.root, d);
1666
+ if (O) {
1667
+ h.updateWorldMatrix(!0, !1);
1668
+ const D = new p(...ge.get(d)).applyMatrix4(jn(O)), z = h.worldToLocal(D);
1669
+ A.userData.simStudioPivotLocal = z.toArray(), pt(A, h, z);
1670
+ continue;
1671
+ }
1672
+ }
1673
+ fi(A, h, i ?? h.getWorldPosition(new p()));
1674
+ }
1675
+ }
1676
+ const c = G && !V ? Me && L.includes(Me) && We(Y(Me)) && et.has(Me) ? Me : L.find((d) => We(Y(d)) && et.has(d)) : void 0, u = V ? G && ce ? vn.get(ce) : void 0 : c ? et.get(c) : void 0;
1677
+ (le == null ? void 0 : le.object) !== u && (le = null), I && I.object !== u && oe();
1678
+ for (const [d, g] of Je)
1679
+ r.has(d) || (E.remove(g), g.dispose(), Je.delete(d));
1680
+ for (const [d, g] of et)
1681
+ t.has(d) || (E.remove(g), et.delete(d));
1682
+ for (const [d, g] of ke)
1683
+ t.has(d) || (E.remove(g), ke.delete(d));
1684
+ u ? (f.object !== u && f.attach(u), f.enabled = G, !V && f.getMode() === "translate" ? (x.object !== u && x.attach(u), x.enabled = G) : (x.detach(), x.enabled = !1)) : (f.detach(), f.enabled = !1, x.detach(), x.enabled = !1);
1685
+ for (const [d, g] of tt) {
1686
+ const h = ne.has(d), A = ce === d, O = g.material;
1687
+ O.color.setHex(h ? fn : A ? wt : Dn), O.opacity = A ? 0.34 : 0.2;
1688
+ const D = g.children.find((z) => z instanceof an);
1689
+ if (D) {
1690
+ const z = D.material;
1691
+ z.color.setHex(h ? fn : A ? wt : Dn), z.opacity = A ? 1 : 0.72;
1692
+ }
1693
+ }
1694
+ Ct && (Ct.visible = G), tn(), rt();
1695
+ }, or = () => {
1696
+ const e = new K();
1697
+ for (const t of L) {
1698
+ const r = Y(t), o = R(t);
1699
+ r && o && me(r) && e.union(he(o));
1700
+ }
1701
+ return e.isEmpty() ? it.translate : Ro({
1702
+ min: e.min.toArray(),
1703
+ max: e.max.toArray()
1704
+ });
1705
+ }, ir = (e, t = !1, r = S.object) => {
1706
+ const o = r == null ? void 0 : r.userData.simStudioRegionId;
1707
+ if (V && r && o)
1708
+ return I = {
1709
+ kind: "region",
1710
+ id: o,
1711
+ object: r,
1712
+ group: r,
1713
+ base: Oe(r),
1714
+ pivotLocal: new p(),
1715
+ instances: [],
1716
+ mode: e,
1717
+ horizontal: t,
1718
+ moved: !1
1719
+ }, tn(), we(), l.setNavigationEnabled(!1), I;
1720
+ const s = r == null ? void 0 : r.userData.simStudioInstanceId, i = s ? R(s) : void 0;
1721
+ if (!r || !i || !s || !We(Y(s))) return null;
1722
+ const c = new p().fromArray(r.userData.simStudioPivotLocal ?? [0, 0, 0]);
1723
+ if (Ke = or(), f.setTranslationSnap(Ge ? Ke : null), Le = [], Ae = null, ye = null, Ht || (Pe = !1), Be = null, Fe = null, $e = null, Ge && e === "translate") {
1724
+ const g = On(i), h = g ? dn(g, sr(s), Xn) : null;
1725
+ Be = (h == null ? void 0 : h.targetId) ?? null, nn((h == null ? void 0 : h.targetId) ?? null);
1726
+ }
1727
+ const u = new Set(L);
1728
+ for (const g of L) if (Te.has(g))
1729
+ for (const h of ee) P && cn(P.root, h.nodeId).some((A) => A.nodeId === g) && u.add(h.nodeId);
1730
+ const d = [...u].flatMap((g) => {
1731
+ const h = Y(g), A = R(g);
1732
+ return We(h) && A ? [{ ...h, localTransform: Oe(A) }] : [];
1733
+ });
1734
+ return I = { kind: "instance", id: s, object: r, group: i, base: Oe(i), pivotLocal: c, instances: d, mode: e, horizontal: t, moved: !1 }, tn(), we(), l.setNavigationEnabled(!1), I;
1735
+ }, Pn = () => {
1736
+ ir(
1737
+ S.getMode(),
1738
+ S === x || S === f && f.getMode() === "translate" && f.axis === "XY"
1739
+ );
1740
+ }, Cn = (e) => {
1741
+ e.updateMatrixWorld(!0);
1742
+ const t = he(e);
1743
+ t.isEmpty() || t.min.z >= -1e-6 || (e.position.z -= t.min.z, e.updateMatrixWorld(!0));
1744
+ }, On = (e) => {
1745
+ const t = he(e);
1746
+ return t.isEmpty() || !Number.isFinite(t.min.x) ? null : { min: [t.min.x, t.min.y], max: [t.max.x, t.max.y] };
1747
+ }, sr = (e) => {
1748
+ const t = [];
1749
+ for (const r of v.getSnapshot().instances) {
1750
+ if (r.id === e || L.includes(r.id) || r.phase !== "ready" || !We(Y(r.id))) continue;
1751
+ const o = R(r.id), s = o ? On(o) : null;
1752
+ s && t.push({ id: r.id, min: s.min, max: s.max });
1753
+ }
1754
+ return t;
1755
+ }, Jr = (e) => {
1756
+ const t = P;
1757
+ if (!t) return [];
1758
+ const r = new Set(e);
1759
+ return ee.filter((o) => me(o) && !cn(t.root, o.nodeId).some((s) => r.has(s.nodeId))).flatMap((o) => {
1760
+ const s = R(o.nodeId);
1761
+ return s ? [s] : [];
1762
+ });
1763
+ }, ar = (e) => {
1764
+ const t = v.getInstanceCollisionRoot(e);
1765
+ return t == null || t.updateWorldMatrix(!0, !0), t;
1766
+ }, lr = (e) => {
1767
+ if (!e.face)
1768
+ return { kind: "none", surface: null, point: null, nodeId: null };
1769
+ const t = e.object.matrixWorld.clone();
1770
+ if (e.object instanceof wn && e.instanceId !== void 0) {
1771
+ const i = new _e();
1772
+ e.object.getMatrixAt(e.instanceId, i), t.multiply(i);
1773
+ }
1774
+ const r = e.face.normal.clone().applyMatrix3(new Zi().getNormalMatrix(t)).normalize(), o = pr(e.object), s = e.point.toArray();
1775
+ return is(r.toArray()) ? {
1776
+ kind: "support-surface",
1777
+ surface: { nodeId: o, point: s, normal: r.toArray() },
1778
+ point: s,
1779
+ nodeId: o
1780
+ } : { kind: "unsupported-surface", surface: null, point: s, nodeId: o };
1781
+ }, yi = (e) => {
1782
+ const t = lr(e);
1783
+ return t.kind === "support-surface" ? t : null;
1784
+ }, eo = (e, t, r, o = 1 / 0, s = (c, u) => !1, i = /* @__PURE__ */ new Set()) => {
1785
+ if (!t.length) return null;
1786
+ for (const c of e.intersectObjects([...t], !0)) {
1787
+ if (!c.face || !(c.object instanceof Z)) continue;
1788
+ let u = c.object, d = !0;
1789
+ for (; u && !i.has(u); ) {
1790
+ if (!u.visible) {
1791
+ d = !1;
1792
+ break;
1793
+ }
1794
+ u = u.parent;
1795
+ }
1796
+ if (!d) continue;
1797
+ const g = yi(c);
1798
+ if (g && !(g.point && g.point[2] > o + un && !s(g.nodeId, g.point[2])))
1799
+ return g;
1800
+ }
1801
+ return null;
1802
+ }, wi = (e) => {
1803
+ const t = e.min.x, r = e.max.x, o = e.min.y, s = e.max.y, i = r - t, c = s - o, u = Math.max(0, Math.min(i * 0.08, 0.08)), d = Math.max(0, Math.min(c * 0.08, 0.08)), g = i > 1e-8 ? [t + u, (t + r) / 2, r - u] : [(t + r) / 2], h = c > 1e-8 ? [o + d, (o + s) / 2, s - d] : [(o + s) / 2];
1804
+ return g.flatMap((A) => h.map((O) => [A, O]));
1805
+ }, xi = (e, t, r = null) => {
1806
+ const o = wi(e);
1807
+ if (!Jr(t).length || o.length === 0)
1808
+ return {
1809
+ kind: "ground",
1810
+ surface: { nodeId: null, point: [e.getCenter(new p()).x, e.getCenter(new p()).y, 0], normal: [0, 0, 1] },
1811
+ point: [e.getCenter(new p()).x, e.getCenter(new p()).y, 0],
1812
+ nodeId: null
1813
+ };
1814
+ const i = new K().setFromObject(v.root, !0), c = i.isEmpty() ? 1e3 : i.max.z + 1e3, u = e.min.z + un, d = (W, $) => {
1815
+ if (!W) return !1;
1816
+ const ie = R(W), F = ar(W);
1817
+ if (!ie && !F) return !1;
1818
+ const Ce = F ? new K().setFromObject(F, !0) : he(ie);
1819
+ return Ce.isEmpty() ? !1 : Ce.min.z <= u + un ? !0 : (r == null ? void 0 : r.nodeId) === W && $ <= r.point[2] + Ls + un;
1820
+ };
1821
+ v.root.updateWorldMatrix(!0, !0);
1822
+ const g = [], h = [], A = P;
1823
+ if (A) {
1824
+ const W = new Set(t);
1825
+ for (const $ of ee) {
1826
+ if (!me($) || cn(A.root, $.nodeId).some((Ce) => W.has(Ce.nodeId)))
1827
+ continue;
1828
+ const ie = R($.nodeId);
1829
+ if (!ie) continue;
1830
+ const F = ar($.nodeId);
1831
+ F ? g.push(F) : h.push(ie);
1832
+ }
1833
+ }
1834
+ const O = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), z = new Set(g);
1835
+ for (const [W, $] of o) {
1836
+ const ie = new St(
1837
+ new p(W, $, c),
1838
+ new p(0, 0, -1)
1839
+ ), F = eo(
1840
+ ie,
1841
+ h,
1842
+ !0,
1843
+ u,
1844
+ d
1845
+ );
1846
+ if (F != null && F.nodeId) {
1847
+ const Ce = O.get(F.nodeId);
1848
+ (!Ce || F.point[2] > Ce.point[2]) && O.set(F.nodeId, F);
1849
+ }
1850
+ if (g.length) {
1851
+ const Ce = new St(
1852
+ new p(W, $, c),
1853
+ new p(0, 0, -1)
1854
+ ), ve = eo(
1855
+ Ce,
1856
+ g,
1857
+ !0,
1858
+ u,
1859
+ d,
1860
+ z
1861
+ );
1862
+ if (ve != null && ve.nodeId) {
1863
+ const pe = D.get(ve.nodeId);
1864
+ (!pe || ve.point[2] > pe.point[2]) && D.set(ve.nodeId, ve);
1865
+ }
1866
+ }
1867
+ }
1868
+ const de = new Map([
1869
+ ...O,
1870
+ ...D
1871
+ ]), be = r != null && r.nodeId ? de.get(r.nodeId) : void 0;
1872
+ let ue = null;
1873
+ for (const W of be ? [be] : de.values())
1874
+ (!ue || W.point[2] > ue.point[2]) && (ue = W);
1875
+ if (ue) return ue;
1876
+ const Se = e.getCenter(new p());
1877
+ return {
1878
+ kind: "ground",
1879
+ surface: { nodeId: null, point: [Se.x, Se.y, 0], normal: [0, 0, 1] },
1880
+ point: [Se.x, Se.y, 0],
1881
+ nodeId: null
1882
+ };
1883
+ }, bi = (e, t, r = []) => {
1884
+ if (b || !P)
1885
+ return { kind: "none", surface: null, point: null, nodeId: null };
1886
+ const o = Jr(r), s = n.canvas.getBoundingClientRect();
1887
+ if (s.width <= 0 || s.height <= 0)
1888
+ return { kind: "none", surface: null, point: null, nodeId: null };
1889
+ const i = new St();
1890
+ i.setFromCamera(
1891
+ new sn(
1892
+ (e - s.left) / s.width * 2 - 1,
1893
+ -(t - s.top) / s.height * 2 + 1
1894
+ ),
1895
+ l.getActiveCamera()
1896
+ ), v.root.updateWorldMatrix(!0, !0);
1897
+ const c = i.intersectObjects(o, !0).find((d) => d.face && d.object instanceof Z);
1898
+ if (!(c != null && c.face)) {
1899
+ const d = l.screenToWorldOnPlane(e, t, 0), g = d && [d.x, d.y, d.z].every(Number.isFinite) ? [d.x, d.y, d.z] : null;
1900
+ return g ? {
1901
+ kind: "ground",
1902
+ surface: { nodeId: null, point: g, normal: [0, 0, 1] },
1903
+ point: g,
1904
+ nodeId: null
1905
+ } : { kind: "none", surface: null, point: null, nodeId: null };
1906
+ }
1907
+ const u = pr(c.object);
1908
+ if (u) {
1909
+ const d = ar(u);
1910
+ if (d) {
1911
+ const g = i.intersectObject(d, !0).find((h) => h.face && h.object instanceof Z);
1912
+ if (g) return lr(g);
1913
+ }
1914
+ }
1915
+ return lr(c);
1916
+ }, vi = (e) => {
1917
+ const t = new K();
1918
+ for (const r of e.instances) {
1919
+ const o = R(r.nodeId);
1920
+ o && me(r) && t.union(he(o));
1921
+ }
1922
+ return t;
1923
+ }, to = (e) => {
1924
+ const t = ye;
1925
+ if (Ae = null, ye = null, !Vt || e.mode !== "translate" || e.horizontal) return null;
1926
+ const r = vi(e);
1927
+ if (r.isEmpty())
1928
+ return Ae = "仅可放置在地面或水平承托面", null;
1929
+ const o = xi(
1930
+ r,
1931
+ e.instances.map((i) => i.nodeId),
1932
+ t
1933
+ ), s = o.point;
1934
+ return o.kind !== "ground" && o.kind !== "support-surface" ? (Ae = "仅可放置在地面或水平承托面", null) : !s || s.some((i) => !Number.isFinite(i)) ? (Ae = "未找到可用的承托面", null) : (ye = o.surface, {
1935
+ target: o,
1936
+ correctionZ: s[2] + un - r.min.z
1937
+ });
1938
+ }, no = (e) => {
1939
+ const t = to(e);
1940
+ !t || Math.abs(t.correctionZ) <= 1e-9 || $r(e.group, new p(0, 0, t.correctionZ));
1941
+ };
1942
+ let cr = /* @__PURE__ */ new WeakMap();
1943
+ const ro = (e, t) => {
1944
+ var d, g;
1945
+ let r = cr.get(t);
1946
+ if (r || (r = zn(t), r.isEmpty() || cr.set(t, r.clone())), !r || r.isEmpty()) return null;
1947
+ t.updateWorldMatrix(!0, !1);
1948
+ const o = new p(), s = new se(), i = new p();
1949
+ t.matrixWorld.decompose(o, s, i);
1950
+ const c = Y(e), u = (c == null ? void 0 : c.nodeType) === "asset" && P ? P.assets.find((h) => h.revisionId === c.assetRevisionId) : void 0;
1951
+ return {
1952
+ nodeId: e,
1953
+ bounds: {
1954
+ min: r.min.toArray(),
1955
+ max: r.max.toArray()
1956
+ },
1957
+ transform: {
1958
+ position: o.toArray(),
1959
+ rotation: s.normalize().toArray(),
1960
+ scale: i.toArray()
1961
+ },
1962
+ container: (u == null ? void 0 : u.category) === "container" || ((g = (d = u == null ? void 0 : u.semantic) == null ? void 0 : d.tags) == null ? void 0 : g.some((h) => /^(container|receptacle|集装箱|容器|可容纳)$/i.test(h))) === !0
1963
+ };
1964
+ }, dr = (e = I) => {
1965
+ if (!Ht || !e || e.kind !== "instance") {
1966
+ Le = [];
1967
+ return;
1968
+ }
1969
+ const t = new Set(e.instances.map((i) => i.nodeId)), r = e.instances.flatMap((i) => {
1970
+ const c = R(i.nodeId), u = c ? ro(i.nodeId, c) : null;
1971
+ return u ? [u] : [];
1972
+ }), o = ee.flatMap((i) => {
1973
+ if (t.has(i.nodeId) || Te.has(i.nodeId) || !me(i)) return [];
1974
+ const c = R(i.nodeId), u = c ? ro(i.nodeId, c) : null;
1975
+ return u ? [u] : [];
1976
+ }), s = /* @__PURE__ */ new Set();
1977
+ if (!Pe)
1978
+ for (const i of r)
1979
+ for (const c of o)
1980
+ c.nodeId === (ye == null ? void 0 : ye.nodeId) && ns(
1981
+ i,
1982
+ c,
1983
+ {
1984
+ movedNodeId: i.nodeId,
1985
+ supportNodeId: c.nodeId,
1986
+ surfaceZ: ye.point[2]
1987
+ },
1988
+ { clearanceM: 0, toleranceM: rs }
1989
+ ) || os(i, c) && s.add(c.nodeId);
1990
+ Le = [...s];
1991
+ }, Mi = () => {
1992
+ const e = Le.length > 0 && !Pe || Ae !== null;
1993
+ for (const t of Je.values()) t.setColor(e ? Fo : wt);
1994
+ we();
1995
+ }, nn = (e) => {
1996
+ var o;
1997
+ if (Wr === e) return;
1998
+ Wr = e, (o = n.onSnapHint) == null || o.call(n, e);
1999
+ const t = e ? Y(e) : void 0, r = e ? R(e) : void 0;
2000
+ k.visible = !!r && !!t && me(t), k.visible && r && (k.box.copy(he(r)), k.visible = !k.box.isEmpty(), k.updateMatrixWorld(!0)), N();
2001
+ }, jt = () => {
2002
+ if (I) {
2003
+ I.moved = !0;
2004
+ const e = I.object;
2005
+ if (e.scale.set(Math.max(1e-4, e.scale.x), Math.max(1e-4, e.scale.y), Math.max(1e-4, e.scale.z)), e.quaternion.normalize(), I.kind === "region") {
2006
+ ze(I.group, Gr(e, I.group, I.pivotLocal)), pt(e, I.group, I.pivotLocal), N();
2007
+ return;
2008
+ }
2009
+ if (ze(I.group, Gr(e, I.group, I.pivotLocal)), I.horizontal || Cn(I.group), Vt && I.mode === "translate" && (Dt(I, Oe(I.group)), no(I)), Ge && I.mode === "translate") {
2010
+ const t = On(I.group), r = sr(I.id), o = Be ? r.find((u) => u.id === Be) : void 0, s = t && o ? dn(t, [o], Number.POSITIVE_INFINITY) : null;
2011
+ if (Be && s && s.distance > Xn && (Fe = Be, $e = s.distance, Be = null), Fe && t) {
2012
+ const u = r.find((g) => g.id === Fe), d = u ? dn(t, [u], Number.POSITIVE_INFINITY) : null;
2013
+ !u || !d || d.distance > _n + 1e-6 || $e !== null && d.distance < $e - oi ? (Fe = null, $e = null) : $e = Math.max($e ?? d.distance, d.distance);
2014
+ }
2015
+ const i = Fe ? r.filter((u) => u.id !== Fe) : r, c = t ? dn(t, i, _n) : null;
2016
+ c && c.distance <= Xn && (Be = c.targetId), nn((c == null ? void 0 : c.targetId) ?? null);
2017
+ } else
2018
+ Be = null, nn(null);
2019
+ Dt(I, Oe(I.group)), dr(), pt(e, I.group, I.pivotLocal);
2020
+ }
2021
+ rt();
2022
+ }, oo = (e, t) => {
2023
+ var r;
2024
+ ze(e.group, e.base), Dt(e, e.base), pt(e.object, e.group, e.pivotLocal), Le = [], Ae = null, Pe = !1, ye = null, rt(), (r = n.onPlacementBlocked) == null || r.call(n, t);
2025
+ }, Lt = () => {
2026
+ var d, g, h;
2027
+ const e = I, t = Fe;
2028
+ if (I = null, tn(), Be = null, Fe = null, $e = null, l.setNavigationEnabled(!0), nn(null), !e) return;
2029
+ if (e.kind === "region") {
2030
+ const A = Oe(e.group);
2031
+ pt(e.object, e.group, e.pivotLocal), Ar(A, e.base) || (d = n.onRegionTransform) == null || d.call(n, e.id, A), rt();
2032
+ return;
2033
+ }
2034
+ let r = Oe(e.group), o = !1;
2035
+ if (Ge && e.moved && e.mode === "translate") {
2036
+ const A = On(e.group), O = sr(e.id).filter((z) => z.id !== t), D = A ? dn(A, O, _n) : null;
2037
+ if (D) {
2038
+ const z = he(e.group).getCenter(new p());
2039
+ $r(e.group, new p(D.position[0] - z.x, D.position[1] - z.y, 0)), e.horizontal || Cn(e.group), r = Oe(e.group), o = !0;
2040
+ }
2041
+ }
2042
+ let s = Ge ? es(r, e.mode === "translate" ? { ...it, translate: o ? 0 : Ke } : { rotate: e.mode === "rotate" ? it.rotate : 0, scale: e.mode === "scale" ? it.scale : 0 }) : r;
2043
+ e.horizontal && (s = { ...s, position: [s.position[0], s.position[1], e.base.position[2]] }), ze(e.group, s), e.horizontal || Cn(e.group), Dt(e, Oe(e.group)), Vt && e.mode === "translate" && (no(e), Dt(e, Oe(e.group)), Math.abs(Oe(e.group).position[2] - s.position[2]) > 1e-9 && (s = Oe(e.group)));
2044
+ const i = he(e.group);
2045
+ if (!Vt && !e.horizontal && !i.isEmpty() && (s = ts(s, {
2046
+ min: i.min.toArray(),
2047
+ max: i.max.toArray()
2048
+ }), ze(e.group, s)), dr(e), Le.length > 0 && !Pe) {
2049
+ oo(e, "与其他资产重叠,不可放置");
2050
+ return;
2051
+ }
2052
+ if (Ae) {
2053
+ oo(e, Ae);
2054
+ return;
2055
+ }
2056
+ const u = !Ar(s, e.base);
2057
+ if (u && n.onTransform)
2058
+ for (const A of e.instances) bn.set(A.nodeId, X);
2059
+ Dt(e, u && n.onTransform ? s : e.base), pt(e.object, e.group, e.pivotLocal);
2060
+ try {
2061
+ u && (Pe || ye ? (g = n.onTransform) == null || g.call(n, e.id, s, {
2062
+ allowOverlap: Pe,
2063
+ supportNodeId: (ye == null ? void 0 : ye.nodeId) ?? null,
2064
+ supportSurfaceZ: (ye == null ? void 0 : ye.point[2]) ?? null
2065
+ }) : (h = n.onTransform) == null || h.call(n, e.id, s));
2066
+ } finally {
2067
+ Le = [], Ae = null, Pe = !1, ye = null, rt();
2068
+ }
2069
+ };
2070
+ f.addEventListener("mouseDown", Pn), f.addEventListener("objectChange", jt), f.addEventListener("mouseUp", Lt), f.addEventListener("change", N), x.addEventListener("mouseDown", Pn), x.addEventListener("objectChange", jt), x.addEventListener("mouseUp", Lt), x.addEventListener("change", N);
2071
+ const Ii = (e) => {
2072
+ const t = Ie;
2073
+ if (!t) return;
2074
+ const r = Ge ? Ke : 0;
2075
+ let o = t.currentShape;
2076
+ if (t.handle.mode === "axis" && t.handle.axis) {
2077
+ if (!t.axisScreen) return;
2078
+ const s = (e.clientX - t.startClient.x) * t.axisScreen.x + (e.clientY - t.startClient.y) * t.axisScreen.y;
2079
+ o = gs(
2080
+ t.baseShape,
2081
+ t.handle.axis,
2082
+ s / t.axisScreen.pixelsPerMetre,
2083
+ r
2084
+ );
2085
+ } else {
2086
+ const s = pi(t.mesh, e.clientX, e.clientY);
2087
+ if (!s) return;
2088
+ t.handle.mode === "corner" ? o = ps(t.baseShape, [s.x, s.y], r) : t.handle.mode === "vertex" && t.handle.index !== void 0 && (o = hs(t.baseShape, t.handle.index, [s.x, s.y], r));
2089
+ }
2090
+ zo(o, t.currentShape) || (t.currentShape = o, t.moved = !0, tr(t.mesh, o));
2091
+ }, ur = (e) => {
2092
+ const t = n.canvas.getBoundingClientRect();
2093
+ return t.width <= 0 || t.height <= 0 ? null : {
2094
+ x: (e.clientX - t.left) / t.width * 2 - 1,
2095
+ y: -(e.clientY - t.top) / t.height * 2 + 1,
2096
+ button: e.button
2097
+ };
2098
+ }, q = (e) => {
2099
+ e.preventDefault(), e.stopImmediatePropagation();
2100
+ }, io = (e, t) => {
2101
+ if (!G || V) return null;
2102
+ const r = l.getActiveCamera();
2103
+ r.updateMatrixWorld(!0);
2104
+ const o = n.canvas.getBoundingClientRect();
2105
+ for (const s of [...L].reverse()) {
2106
+ const i = ke.get(s);
2107
+ if (!(i != null && i.visible)) continue;
2108
+ i.updateWorldMatrix(!0, !1);
2109
+ const c = i.getWorldPosition(new p()).project(r);
2110
+ if (![c.x, c.y, c.z].every(Number.isFinite) || c.z < -1 || c.z > 1) continue;
2111
+ const u = o.left + (c.x + 1) * o.width / 2, d = o.top + (1 - c.y) * o.height / 2;
2112
+ if (Math.hypot(e - u, t - d) <= js)
2113
+ return s;
2114
+ }
2115
+ return null;
2116
+ }, Si = (e, t) => {
2117
+ var g, h;
2118
+ const r = R(e), o = P ? ln(P.root, e) : null, s = P ? hr(P.root, e) : null;
2119
+ if (!r || !o || !s || !We(Y(e))) return !1;
2120
+ const i = l.getActiveCamera();
2121
+ i.updateMatrixWorld(!0);
2122
+ const c = ke.get(e), u = (c == null ? void 0 : c.getWorldPosition(new p())) ?? r.getWorldPosition(new p()), d = i.getWorldDirection(new p()).normalize();
2123
+ return He = {
2124
+ nodeId: e,
2125
+ group: r,
2126
+ previousLocal: Ye(o),
2127
+ contentInverse: jn(s).invert(),
2128
+ plane: new mn().setFromNormalAndCoplanarPoint(d, u),
2129
+ currentLocal: Ye(o),
2130
+ latestClientX: t.clientX,
2131
+ latestClientY: t.clientY,
2132
+ frameId: null,
2133
+ dirty: !1,
2134
+ moved: !1
2135
+ }, _ = t.pointerId, (h = (g = n.canvas).setPointerCapture) == null || h.call(g, t.pointerId), n.canvas.style.cursor = "grabbing", l.setNavigationEnabled(!1), !0;
2136
+ }, so = (e) => {
2137
+ var d;
2138
+ const t = ur({
2139
+ clientX: e.latestClientX,
2140
+ clientY: e.latestClientY
2141
+ });
2142
+ if (!t) return;
2143
+ const r = l.getActiveCamera();
2144
+ r.updateMatrixWorld(!0);
2145
+ const o = new St();
2146
+ o.setFromCamera(new sn(t.x, t.y), r);
2147
+ const i = ((d = o.intersectObjects(Br([e.group]), !1)[0]) == null ? void 0 : d.point.clone()) ?? o.ray.intersectPlane(e.plane, new p());
2148
+ if (!i) return;
2149
+ const c = i.applyMatrix4(e.contentInverse).toArray();
2150
+ if (c.some((g) => !Number.isFinite(g)) || c.every((g, h) => Math.abs(g - e.currentLocal[h]) <= 1e-9))
2151
+ return;
2152
+ e.currentLocal = c, e.moved = !0;
2153
+ const u = ke.get(e.nodeId);
2154
+ u && (u.userData.simStudioOriginLocal = c.map(
2155
+ (g, h) => g - e.previousLocal[h]
2156
+ ), Wt(e.nodeId), N());
2157
+ }, Ai = (e) => {
2158
+ const t = He;
2159
+ t && (t.latestClientX = e.clientX, t.latestClientY = e.clientY, t.dirty = !0, t.frameId === null && (t.frameId = er(() => {
2160
+ t.frameId = null, !(He !== t || !t.dirty) && (t.dirty = !1, so(t));
2161
+ })));
2162
+ }, Ei = (e) => {
2163
+ var r;
2164
+ const t = He;
2165
+ t && (Tt(t.frameId), t.frameId = null, t.latestClientX = e.clientX, t.latestClientY = e.clientY, t.dirty && (t.dirty = !1, so(t)), He = null, n.canvas.style.cursor = "grab", l.setNavigationEnabled(!0), ht(), N(), t.moved && ((r = n.onNodeOriginChange) == null || r.call(n, t.nodeId, t.currentLocal)));
2166
+ }, Pi = () => {
2167
+ const e = He;
2168
+ if (!e) return;
2169
+ Tt(e.frameId), He = null;
2170
+ const t = ke.get(e.nodeId);
2171
+ t && (t.userData.simStudioOriginLocal = [0, 0, 0]), Wt(e.nodeId), n.canvas.style.cursor = "", N();
2172
+ }, Ci = (e) => {
2173
+ const t = I;
2174
+ if (Ge || (t == null ? void 0 : t.kind) !== "instance") return !1;
2175
+ const r = e.nextPosition.clone().sub(e.center);
2176
+ for (const c of e.movedObjects)
2177
+ Ft(c.object, c.startWorldPosition.clone().add(r)), c.object.updateMatrixWorld(!0);
2178
+ t.moved = !0;
2179
+ const o = t.group.getWorldPosition(new p()).z;
2180
+ Cn(t.group);
2181
+ const s = t.group.getWorldPosition(new p()).z - o;
2182
+ if (Math.abs(s) > 1e-9) {
2183
+ const c = new p(0, 0, s);
2184
+ for (const u of e.movedObjects)
2185
+ u.object !== t.group && (Ft(u.object, u.object.getWorldPosition(new p()).add(c)), u.object.updateMatrixWorld(!0));
2186
+ e.object.position.z += s, e.object.updateMatrixWorld(!0);
2187
+ }
2188
+ const i = to(t);
2189
+ if (i && Math.abs(i.correctionZ) > 1e-9) {
2190
+ const c = new p(0, 0, i.correctionZ);
2191
+ for (const u of e.movedObjects)
2192
+ Ft(
2193
+ u.object,
2194
+ u.object.getWorldPosition(new p()).add(c)
2195
+ ), u.object.updateMatrixWorld(!0);
2196
+ Ft(
2197
+ e.object,
2198
+ e.object.getWorldPosition(new p()).add(c)
2199
+ ), e.object.updateMatrixWorld(!0);
2200
+ }
2201
+ dr(), Mi();
2202
+ for (const c of e.movedObjects) {
2203
+ const u = Je.get(c.nodeId);
2204
+ u != null && u.visible && (u.followObject(c.object), u.updateMatrixWorld(!0)), Wt(c.nodeId);
2205
+ const d = Y(c.nodeId);
2206
+ v.previewInstancePlacement(c.nodeId, {
2207
+ ...Oe(c.object),
2208
+ ...d ? { pivot: Ye(d) } : {}
2209
+ });
2210
+ }
2211
+ return N(), !0;
2212
+ }, ao = () => {
2213
+ const e = re;
2214
+ if (!e || (I == null ? void 0 : I.kind) !== "instance") return;
2215
+ const t = rr(
2216
+ e.latestClientX,
2217
+ e.latestClientY,
2218
+ e.plane,
2219
+ e.pointOnPlane
2220
+ );
2221
+ t && (e.nextPosition.copy(e.center).add(t).sub(e.startPoint), Ge && e.nextPosition.set(
2222
+ Yt(e.nextPosition.x, Ke),
2223
+ Yt(e.nextPosition.y, Ke),
2224
+ Yt(e.nextPosition.z, Ke)
2225
+ ), Ft(e.object, e.nextPosition), e.object.updateMatrixWorld(!0), !Ci(e) && jt());
2226
+ }, lo = (e) => {
2227
+ const t = re;
2228
+ !t || _ !== e.pointerId || (t.latestClientX = e.clientX, t.latestClientY = e.clientY, t.dirty = !0, t.frameId === null && (t.frameId = er(() => {
2229
+ re === t && (t.frameId = null, t.dirty && (t.dirty = !1, ao()));
2230
+ })));
2231
+ }, Oi = (e, t) => {
2232
+ const r = re;
2233
+ r && (Tt(r.frameId), r.frameId = null, r.latestClientX = e, r.latestClientY = t, r.dirty && (r.dirty = !1, ao()));
2234
+ }, ki = (e) => {
2235
+ const t = Re;
2236
+ if (!w || !t || I || !L.includes(t.id) || !f.object) return !1;
2237
+ f.object.updateWorldMatrix(!0, !1);
2238
+ const r = f.object.getWorldPosition(new p()), o = l.getActiveCamera();
2239
+ o.updateMatrixWorld(!0);
2240
+ const s = o.getWorldDirection(new p()).normalize();
2241
+ if (s.lengthSq() < 1e-8) return !1;
2242
+ const i = new mn().setFromNormalAndCoplanarPoint(s, r), c = rr(e.clientX, e.clientY, i, new p());
2243
+ if (!c) return !1;
2244
+ const u = ir("translate", !1, f.object);
2245
+ if (!u || u.kind !== "instance") return !1;
2246
+ const d = [...new Map(u.instances.flatMap((g) => {
2247
+ const h = R(g.nodeId);
2248
+ return h ? [[g.nodeId, {
2249
+ object: h,
2250
+ nodeId: g.nodeId,
2251
+ startWorldPosition: h.getWorldPosition(new p())
2252
+ }]] : [];
2253
+ })).values()];
2254
+ return re = {
2255
+ pointerId: e.pointerId,
2256
+ object: f.object,
2257
+ center: r,
2258
+ plane: i,
2259
+ startPoint: c,
2260
+ pointOnPlane: new p(),
2261
+ nextPosition: new p(),
2262
+ movedObjects: d,
2263
+ latestClientX: e.clientX,
2264
+ latestClientY: e.clientY,
2265
+ frameId: null,
2266
+ dirty: !1
2267
+ }, Re = null, we(), lo(e), !0;
2268
+ }, co = (e) => {
2269
+ var c;
2270
+ const t = ct;
2271
+ if (!w || !t || b || e.button !== 0 || e.isPrimary === !1 || I || _ !== null) return;
2272
+ const r = new mn().setFromNormalAndCoplanarPoint(t.normal, t.center), o = new p(), s = Kr(
2273
+ e.clientX,
2274
+ e.clientY,
2275
+ t.center,
2276
+ t.axisX,
2277
+ t.axisY,
2278
+ r,
2279
+ o
2280
+ );
2281
+ if (s === null || (S = f, ir("rotate", !0, f.object), !I || !f.object)) return;
2282
+ dt = !0, Qe = !0, le = null, U = {
2283
+ pointerId: e.pointerId,
2284
+ object: f.object,
2285
+ center: t.center.clone(),
2286
+ axisX: t.axisX.clone(),
2287
+ axisY: t.axisY.clone(),
2288
+ normal: t.normal.clone(),
2289
+ plane: r,
2290
+ pointOnPlane: o,
2291
+ radius: t.radius,
2292
+ baseWorldQuaternion: f.object.getWorldQuaternion(new se()).normalize(),
2293
+ startAngle: s,
2294
+ previousAngle: s,
2295
+ rawDelta: 0,
2296
+ delta: 0,
2297
+ latestClientX: e.clientX,
2298
+ latestClientY: e.clientY,
2299
+ frameId: null,
2300
+ dirty: !1
2301
+ }, _ = e.pointerId;
2302
+ const i = e.currentTarget && "setPointerCapture" in e.currentTarget ? e.currentTarget : w.element;
2303
+ ut = i, (c = i.setPointerCapture) == null || c.call(i, e.pointerId), q(e), we(), N();
2304
+ }, uo = (e) => {
2305
+ const t = Kr(
2306
+ e.latestClientX,
2307
+ e.latestClientY,
2308
+ e.center,
2309
+ e.axisX,
2310
+ e.axisY,
2311
+ e.plane,
2312
+ e.pointOnPlane
2313
+ );
2314
+ if (t === null) return;
2315
+ e.rawDelta += Rs(e.previousAngle, t), e.previousAngle = t, e.delta = Ge ? Ts(e.rawDelta, it.rotate) : e.rawDelta;
2316
+ const r = new se().setFromAxisAngle(e.normal, e.delta).normalize();
2317
+ Xo(
2318
+ e.object,
2319
+ e.baseWorldQuaternion.clone().premultiply(r).normalize()
2320
+ ), e.object.updateMatrixWorld(!0), jt();
2321
+ }, Ri = (e) => {
2322
+ const t = U;
2323
+ !t || _ !== e.pointerId || (t.latestClientX = e.clientX, t.latestClientY = e.clientY, t.dirty = !0, t.frameId === null && (t.frameId = er(() => {
2324
+ U === t && (t.frameId = null, t.dirty && (t.dirty = !1, uo(t)));
2325
+ })));
2326
+ }, fo = (e) => {
2327
+ !U || _ !== e.pointerId || (Ri(e), q(e));
2328
+ }, mo = (e) => {
2329
+ const t = U;
2330
+ !t || _ !== e.pointerId || (Tt(t.frameId), t.frameId = null, t.latestClientX = e.clientX, t.latestClientY = e.clientY, t.dirty && (t.dirty = !1, uo(t)), le = {
2331
+ object: t.object,
2332
+ center: t.center.clone(),
2333
+ axisX: t.axisX.clone(),
2334
+ axisY: t.axisY.clone(),
2335
+ normal: t.normal.clone(),
2336
+ radius: t.radius,
2337
+ startAngle: t.startAngle,
2338
+ delta: t.delta,
2339
+ active: !1
2340
+ }, U = null, Lt(), ht(), we(), N(), q(e));
2341
+ };
2342
+ let rn = null;
2343
+ const kn = (e, t) => {
2344
+ rn = null;
2345
+ const r = l.getActiveCamera();
2346
+ r.updateMatrixWorld(!0), v.root.updateMatrixWorld(!0);
2347
+ const o = v.pickUnifiedInstance(e, t, r, n.canvas);
2348
+ if (o) return Rt(Y(o)) ? o : null;
2349
+ const s = ee.filter(Rt).map((d) => R(d.nodeId)).filter((d) => !!d), i = Br(s), c = i.length ? l.pick(e, t, { roots: i, recursive: !1, includeInvisible: !1, firstHitOnly: !0 }) : null, u = c ? pr(c.object) : null;
2350
+ return rn = c ? Er(c.object) : null, u && Rt(Y(u)) ? u : null;
2351
+ }, po = (e, t) => {
2352
+ const r = kn(e, t);
2353
+ return !r || !We(Y(r)) || !R(r) ? "" : L.includes(r) ? "move" : "pointer";
2354
+ }, fr = (e) => {
2355
+ var r, o;
2356
+ te = {
2357
+ x: e.clientX,
2358
+ y: e.clientY,
2359
+ lastX: e.clientX,
2360
+ lastY: e.clientY,
2361
+ additive: !!(e.shiftKey || e.ctrlKey || e.metaKey),
2362
+ moved: !1
2363
+ }, _ = e.pointerId, l.setNavigationEnabled(!1), (o = (r = n.canvas).setPointerCapture) == null || o.call(r, e.pointerId), H || (H = n.canvas.ownerDocument.createElement("div"), H.style.cssText = "position:absolute;pointer-events:none;z-index:30;border:1px solid #1ec8bf;background:rgba(30,200,191,.12);box-sizing:border-box;", H.setAttribute("aria-hidden", "true"), n.viewport.append(H));
2364
+ const t = n.viewport.getBoundingClientRect();
2365
+ H.hidden = !0, H.style.left = `${e.clientX - t.left}px`, H.style.top = `${e.clientY - t.top}px`, H.style.width = "0px", H.style.height = "0px", n.canvas.style.cursor = "crosshair", we();
2366
+ }, Ti = (e) => {
2367
+ var c, u, d, g, h, A, O, D;
2368
+ if (b || e.isPrimary === !1) return;
2369
+ if (e.button !== 0) {
2370
+ je = !0;
2371
+ return;
2372
+ }
2373
+ if (je = !1, !G || _ !== null) return;
2374
+ if (Xt && !V) {
2375
+ je = !0, n.canvas.style.cursor = "grab";
2376
+ return;
2377
+ }
2378
+ if (Pe = Ht && e.altKey, dt = !1, Qe = !1, le = null, Jt(), ft && !V) {
2379
+ fr(e), q(e);
2380
+ return;
2381
+ }
2382
+ if (e.shiftKey || e.ctrlKey || e.metaKey) {
2383
+ !V && !kn(e.clientX, e.clientY) && (fr(e), q(e));
2384
+ return;
2385
+ }
2386
+ const t = e.altKey ? io(e.clientX, e.clientY) : null;
2387
+ if (t && Si(t, e)) {
2388
+ q(e);
2389
+ return;
2390
+ }
2391
+ const r = ur(e);
2392
+ if (!r) return;
2393
+ if (V && G) {
2394
+ const z = Vr(e.clientX, e.clientY);
2395
+ if (z && hi(z.regionId, z.handle, e.clientX, e.clientY)) {
2396
+ _ = e.pointerId, (u = (c = n.canvas).setPointerCapture) == null || u.call(c, e.pointerId), q(e);
2397
+ return;
2398
+ }
2399
+ }
2400
+ const o = !!w && (f.getMode() === "translate" || f.getMode() === "rotate");
2401
+ if (f.enabled && !o && (f.camera = l.getActiveCamera(), f.camera.updateMatrixWorld(!0), f.getHelper().updateMatrixWorld(!0), f.pointerHover(r), w || (x.camera = f.camera, x.getHelper().updateMatrixWorld(!0), x.enabled && x.pointerHover(r)), S = !w && f.axis ? f : !w && x.enabled && x.axis ? x : f, f.getHelper().userData.simStudioCenterDrag = S === f && f.getMode() === "translate" && f.axis === "XYZ", S.pointerDown(r), S.dragging && I)) {
2402
+ _ = e.pointerId, (g = (d = n.canvas).setPointerCapture) == null || g.call(d, e.pointerId), q(e);
2403
+ return;
2404
+ }
2405
+ if (V) {
2406
+ const z = Xr(e.clientX, e.clientY), de = z ? vn.get(z) : void 0;
2407
+ z && de && (ce = z, (h = n.onRegionPick) == null || h.call(n, z), xe());
2408
+ return;
2409
+ }
2410
+ const s = kn(e.clientX, e.clientY);
2411
+ if (!s || !R(s)) {
2412
+ V || (fr(e), q(e));
2413
+ return;
2414
+ }
2415
+ const i = !L.includes(s);
2416
+ i && ((A = n.onPick) == null || A.call(n, s, !1, rn)), We(Y(s)) && (n.canvas.style.cursor = L.includes(s) ? "move" : "pointer", Re = { id: s, x: e.clientX, y: e.clientY, pickedOnDown: i }, _ = e.pointerId, (D = (O = n.canvas).setPointerCapture) == null || D.call(O, e.pointerId), q(e));
2417
+ }, Wi = (e) => {
2418
+ if (b) return;
2419
+ if (_ !== null && (Pe = Ht && e.altKey), te && e.pointerId === _) {
2420
+ te.lastX = e.clientX, te.lastY = e.clientY, !te.moved && Math.hypot(e.clientX - te.x, e.clientY - te.y) >= _s && (te.moved = !0, H && (H.hidden = !1));
2421
+ const r = n.viewport.getBoundingClientRect();
2422
+ te.moved && H && (H.style.left = `${Math.min(te.x, e.clientX) - r.left}px`, H.style.top = `${Math.min(te.y, e.clientY) - r.top}px`, H.style.width = `${Math.abs(e.clientX - te.x)}px`, H.style.height = `${Math.abs(e.clientY - te.y)}px`), q(e);
2423
+ return;
2424
+ }
2425
+ if (He && e.pointerId === _) {
2426
+ Ai(e), q(e);
2427
+ return;
2428
+ }
2429
+ if (Ie && _ !== null && e.pointerId === _) {
2430
+ Ii(e), q(e);
2431
+ return;
2432
+ }
2433
+ if (b || !f.enabled && !Re) return;
2434
+ const t = ur(e);
2435
+ if (t) {
2436
+ if (_ === null && e.buttons === 0 && e.altKey && io(e.clientX, e.clientY)) {
2437
+ n.canvas.style.cursor = "grab";
2438
+ return;
2439
+ }
2440
+ if (_ !== null) {
2441
+ if (e.pointerId !== _) return;
2442
+ if (Re) {
2443
+ if (Math.hypot(e.clientX - Re.x, e.clientY - Re.y) >= 4 && ki(e)) {
2444
+ n.canvas.style.cursor = "move", q(e);
2445
+ return;
2446
+ }
2447
+ q(e);
2448
+ return;
2449
+ }
2450
+ if (re) {
2451
+ n.canvas.style.cursor = "move", lo(e), q(e);
2452
+ return;
2453
+ }
2454
+ S.pointerMove({ ...t, button: -1 }), q(e);
2455
+ } else e.buttons === 0 && V && G ? n.canvas.style.cursor = Vr(e.clientX, e.clientY) ? "grab" : "" : e.buttons === 0 && !(w && (f.getMode() === "translate" || f.getMode() === "rotate")) ? (f.pointerHover(t), !w && x.enabled && (x.camera = l.getActiveCamera(), x.getHelper().updateMatrixWorld(!0), x.pointerHover(t), f.axis && (x.axis = null))) : e.buttons === 0 && G && !V && w && f.getMode() === "translate" && (n.canvas.style.cursor = po(e.clientX, e.clientY));
2456
+ }
2457
+ }, zi = (e) => {
2458
+ var t, r, o, s;
2459
+ if (e.pointerId === _) {
2460
+ if (He) {
2461
+ Ei(e), q(e);
2462
+ return;
2463
+ }
2464
+ if (te) {
2465
+ const i = te;
2466
+ if (te = null, H && (H.hidden = !0), l.setNavigationEnabled(!0), n.canvas.style.cursor = ft ? "crosshair" : "", ht(), !i.moved) {
2467
+ (t = n.onBoxSelect) == null || t.call(n, [], i.additive), we(), q(e);
2468
+ return;
2469
+ }
2470
+ const c = l.getActiveCamera();
2471
+ c.updateMatrixWorld(!0);
2472
+ const u = n.canvas.getBoundingClientRect(), d = Math.min(i.x, e.clientX), g = Math.max(i.x, e.clientX), h = Math.min(i.y, e.clientY), A = Math.max(i.y, e.clientY), O = ee.filter(Rt).filter((D) => {
2473
+ const z = R(D.nodeId);
2474
+ if (!z) return !1;
2475
+ const de = he(z);
2476
+ if (de.isEmpty()) return !1;
2477
+ let be = 1 / 0, ue = -1 / 0, Se = 1 / 0, W = -1 / 0, $ = !1;
2478
+ for (const ie of [de.min.x, de.max.x]) for (const F of [de.min.y, de.max.y]) for (const Ce of [de.min.z, de.max.z]) {
2479
+ const ve = new p(ie, F, Ce).project(c);
2480
+ if (![ve.x, ve.y, ve.z].every(Number.isFinite)) continue;
2481
+ ve.z >= -1 && ve.z <= 1 && ($ = !0);
2482
+ const pe = u.left + (ve.x + 1) * u.width / 2, on = u.top + (1 - ve.y) * u.height / 2;
2483
+ be = Math.min(be, pe), ue = Math.max(ue, pe), Se = Math.min(Se, on), W = Math.max(W, on);
2484
+ }
2485
+ return $ && ue >= d && be <= g && W >= h && Se <= A;
2486
+ }).map((D) => D.nodeId);
2487
+ (r = n.onBoxSelect) == null || r.call(n, O, i.additive), we(), q(e);
2488
+ return;
2489
+ }
2490
+ if (Ie) {
2491
+ const i = Ie;
2492
+ Ie = null;
2493
+ const c = Qt.get(i.handle.id);
2494
+ c && c.material.color.setHex(
2495
+ i.handle.axis ? Sr[i.handle.axis] : Ir
2496
+ ), n.canvas.style.cursor = "", l.setNavigationEnabled(!0), ht(), i.moved && !zo(i.currentShape, i.baseShape) ? (o = n.onRegionShapeChange) == null || o.call(n, i.regionId, i.currentShape) : tr(i.mesh, i.baseShape), we(), q(e);
2497
+ return;
2498
+ }
2499
+ if (re) {
2500
+ Oi(e.clientX, e.clientY), re = null, n.canvas.style.cursor = po(e.clientX, e.clientY), Lt(), ht(), we(), N(), q(e);
2501
+ return;
2502
+ }
2503
+ if (Re) {
2504
+ const i = Re;
2505
+ Re = null, !i.pickedOnDown && Math.hypot(e.clientX - i.x, e.clientY - i.y) < 4 && ((s = n.onPick) == null || s.call(n, i.id, !1, rn));
2506
+ } else S.pointerUp({ button: 0 });
2507
+ f.getHelper().userData.simStudioCenterDrag = !1, ht(), q(e);
2508
+ }
2509
+ }, ho = (e) => {
2510
+ e.pointerId === _ && (te && (te = null, H && (H.hidden = !0), n.canvas.style.cursor = ft ? "crosshair" : "", l.setNavigationEnabled(!0)), oe(), q(e));
2511
+ }, go = () => {
2512
+ je = !1;
2513
+ }, yo = (e) => {
2514
+ const t = e.target, r = typeof (t == null ? void 0 : t.closest) == "function" && !!t.closest('input,textarea,select,[contenteditable]:not([contenteditable="false"])'), o = typeof n.canvas.matches == "function" && n.canvas.matches(":hover");
2515
+ if ((n.canvas.ownerDocument.activeElement === n.canvas || o && !r) && (e.code === "Space" || e.key === " ")) {
2516
+ Xt = e.type === "keydown", n.canvas.style.cursor = Xt ? "grab" : ft ? "crosshair" : "", q(e);
2517
+ return;
2518
+ }
2519
+ e.key !== "Escape" || !I && !Re && !Ie && !te && !He || (te && (te = null, H && (H.hidden = !0), n.canvas.style.cursor = ft ? "crosshair" : "", l.setNavigationEnabled(!0)), oe(), q(e));
2520
+ }, Q = (e, t, r, o = !1) => {
2521
+ e.addEventListener(t, r, o), mt.push(() => e.removeEventListener(t, r, o));
2522
+ };
2523
+ Q(n.canvas, "pointerdown", () => B(), !0), Q(n.canvas, "wheel", () => B(), !0), Q(n.canvas, "pointerdown", Ti, !0), Q(n.canvas, "pointermove", Wi, !0), Q(n.canvas, "pointerleave", () => {
2524
+ _ === null && (n.canvas.style.cursor = "");
2525
+ }), Q(n.canvas, "pointerup", zi, !0), Q(n.canvas, "pointercancel", ho, !0), Q(n.canvas.ownerDocument, "pointerup", go, !0), Q(n.canvas.ownerDocument, "pointercancel", go, !0), Q(n.canvas, "lostpointercapture", ho), w && (Q(w.element, "pointerdown", co, !0), Q(w.element, "pointermove", fo, !0), Q(w.element, "pointerup", mo, !0), Q(w.element, "pointercancel", () => {
2526
+ U && oe();
2527
+ }, !0), Q(w.element, "lostpointercapture", () => {
2528
+ U && oe();
2529
+ }), Q(w.handleElement, "pointerenter", () => {
2530
+ !U && !Qe && (dt = !0, Jt());
2531
+ }), Q(w.handleElement, "pointerleave", () => {
2532
+ !U && !Qe && (dt = !1, Jt());
2533
+ }), Q(w.handleElement, "pointerdown", co, !0), Q(w.handleElement, "pointermove", fo, !0), Q(w.handleElement, "pointerup", mo, !0), Q(w.handleElement, "pointercancel", () => {
2534
+ U && oe();
2535
+ }, !0)), Q(n.canvas.ownerDocument, "keydown", yo, !0), Q(n.canvas.ownerDocument, "keyup", yo, !0);
2536
+ const Ni = (e) => {
2537
+ b || e.preventDefault();
2538
+ };
2539
+ if (Q(n.canvas, "contextmenu", Ni, !0), n.canvas.ownerDocument.defaultView && Q(n.canvas.ownerDocument.defaultView, "blur", () => {
2540
+ Xt = !1, n.canvas.style.cursor = ft ? "crosshair" : "", oe();
2541
+ }), mt.push(l.on("camera-change", () => {
2542
+ f.camera = l.getActiveCamera(), x.camera = f.camera, we(), N();
2543
+ })), mt.push(l.on("camera-change", () => {
2544
+ var t;
2545
+ const e = l.getActiveCamera().quaternion;
2546
+ (t = n.onCameraChange) == null || t.call(n, [e.x, e.y, e.z, e.w]);
2547
+ })), mt.push(l.on("pointer-click", (e) => {
2548
+ var r, o;
2549
+ if (b || I || _ !== null || ft || Xt) return;
2550
+ if (V) {
2551
+ const s = Xr(e.clientX, e.clientY);
2552
+ if (s) {
2553
+ (r = n.onRegionPick) == null || r.call(n, s);
2554
+ return;
2555
+ }
2556
+ }
2557
+ const t = kn(e.clientX, e.clientY);
2558
+ (o = n.onPick) == null || o.call(n, t, e.shiftKey || e.ctrlKey || e.metaKey, rn);
2559
+ })), n.onSelectionOverlayChange) {
2560
+ const e = n.canvas.ownerDocument.defaultView;
2561
+ e && Q(e, "resize", we);
2562
+ const t = e == null ? void 0 : e.ResizeObserver;
2563
+ if (t) {
2564
+ const r = new t(we);
2565
+ r.observe(n.viewport), n.canvas !== n.viewport && r.observe(n.canvas), mt.push(() => r.disconnect());
2566
+ }
2567
+ }
2568
+ mt.push(l.on("asset-error", (e) => It(e.message))), mt.push(v.subscribe((e) => {
2569
+ if (!b) {
2570
+ for (const t of e.instances) Yr(t);
2571
+ xe(), Mt();
2572
+ }
2573
+ }));
2574
+ const gt = v.ready.then(() => {
2575
+ b || (Ne = !0, v.setGroundVisible(Tr), Mt());
2576
+ });
2577
+ gt.catch((e) => {
2578
+ b || (Ee = gn(e), It(Ee), Mt());
2579
+ });
2580
+ const wo = () => {
2581
+ const e = new K();
2582
+ for (const t of ee)
2583
+ me(t) && e.union(qn(t));
2584
+ return e;
2585
+ }, Di = () => {
2586
+ const e = wo();
2587
+ return e.isEmpty() ? null : {
2588
+ min: e.min.toArray(),
2589
+ max: e.max.toArray()
2590
+ };
2591
+ }, xo = () => {
2592
+ if (b) return !1;
2593
+ B();
2594
+ const e = wo();
2595
+ return !e.isEmpty() && l.fitView(e, { padding: 1.2, viewMode: "3d" });
2596
+ }, bo = async () => {
2597
+ var e;
2598
+ _t = !0, Ee = null, Mt();
2599
+ try {
2600
+ for (await gt; !b && at !== X; ) {
2601
+ const t = X, r = ee;
2602
+ for (const [o, s] of [...qe])
2603
+ r.some((c) => c.nodeId === o && An(c) === s.sourceRevisionId && Sn(c) === s.kind) || En(o);
2604
+ for (const [o, s] of Et)
2605
+ if (!r.some((i) => i.nodeId === o && jr(i, s)) && (oe(), Ut.remove(o), Zt.has(o) ? ii(o) : await v.removeInstance(o), Et.delete(o), Gt.delete(o), $t.delete(o), Zt.delete(o), bn.delete(o), Pt.delete(o), En(o), b || t !== X))
2606
+ break;
2607
+ if (b) break;
2608
+ if (t === X) {
2609
+ for (const o of r) {
2610
+ if (b || t !== X) break;
2611
+ if (ai(o), !Et.has(o.nodeId)) {
2612
+ if (o.nodeType === "placeholder") {
2613
+ si(o), Et.set(o.nodeId, Kt(o)), Zt.set(o.nodeId, Ot(o)), Gt.delete(o.nodeId), $t.delete(o.nodeId), Pt.delete(o.nodeId), nt(o, {
2614
+ phase: "ready",
2615
+ stage: null,
2616
+ outcome: "placeholder",
2617
+ message: null,
2618
+ progress: null,
2619
+ warning: null,
2620
+ error: null
2621
+ }), xe();
2622
+ continue;
2623
+ }
2624
+ const c = li(o);
2625
+ c.stage("resolving-source", "正在解析资产来源...");
2626
+ let u;
2627
+ try {
2628
+ u = o.nodeType === "visual" ? n.resolveVisualSource ? await n.resolveVisualSource(o.visualRevisionId, o, m.signal, c) : null : await n.resolveSource(o.assetRevisionId, o, m.signal, c);
2629
+ } catch (g) {
2630
+ u = null, nt(o, {
2631
+ phase: "failed",
2632
+ stage: null,
2633
+ outcome: null,
2634
+ message: null,
2635
+ progress: null,
2636
+ warning: null,
2637
+ error: Gs(g, "resolving-source")
2638
+ }), !b && t === X && It(gn(g));
2639
+ }
2640
+ if (b || t !== X) break;
2641
+ if (!u) {
2642
+ const g = `Asset source unavailable: ${Kt(o)}`;
2643
+ Pt.set(o.nodeId, { code: "E_STUDIO_SOURCE_UNAVAILABLE", message: g }), nt(o, {
2644
+ phase: "failed",
2645
+ stage: null,
2646
+ outcome: null,
2647
+ message: null,
2648
+ progress: null,
2649
+ warning: null,
2650
+ error: {
2651
+ code: "E_STUDIO_SOURCE_UNAVAILABLE",
2652
+ message: g,
2653
+ stage: "resolving-source"
2654
+ }
2655
+ }), It(g);
2656
+ continue;
2657
+ }
2658
+ Pt.delete(o.nodeId), c.stage("parsing-visual", "正在加载资产...");
2659
+ const d = await v.addInstance({
2660
+ ...u,
2661
+ id: o.nodeId,
2662
+ ...o.nodeType === "asset" ? {
2663
+ physics: {
2664
+ override: o.physics,
2665
+ initialJoints: (e = o.initialPose) == null ? void 0 : e.joints
2666
+ }
2667
+ } : {},
2668
+ placement: {
2669
+ ...o.localTransform,
2670
+ pivot: Ye(o),
2671
+ visible: me(o)
2672
+ }
2673
+ });
2674
+ if (Yr(d), d.phase !== "ready") {
2675
+ d.error && (Pt.set(o.nodeId, { ...d.error }), !b && t === X && It(d.error.message));
2676
+ continue;
2677
+ }
2678
+ if (Et.set(o.nodeId, Kt(o)), o.nodeType === "visual" ? ($t.set(o.nodeId, Ot(o)), Gt.delete(o.nodeId)) : ($t.delete(o.nodeId), Gt.set(o.nodeId, Ot(o))), Zt.delete(o.nodeId), b || t !== X) break;
2679
+ }
2680
+ const s = bn.get(o.nodeId);
2681
+ if (!(I != null && I.instances.some((c) => c.nodeId === o.nodeId)) && (s === void 0 || t > s)) {
2682
+ const c = R(o.nodeId), u = o.nodeType === "placeholder" && c ? (() => {
2683
+ ze(c, o.localTransform);
2684
+ const d = c.children.find(
2685
+ (h) => h.name === `scene-content:${o.nodeId}`
2686
+ ), g = Ye(o);
2687
+ return d == null || d.position.set(-g[0], -g[1], -g[2]), c.visible = me(o), N(), Promise.resolve(!0);
2688
+ })() : v.setInstancePlacement(o.nodeId, {
2689
+ ...o.localTransform,
2690
+ pivot: Ye(o),
2691
+ visible: me(o)
2692
+ });
2693
+ bn.delete(o.nodeId), xe(), await u;
2694
+ }
2695
+ if (b || t !== X) break;
2696
+ const i = R(o.nodeId);
2697
+ i && o.nodeType === "asset" && Ut.apply(o.nodeId, i, o.appearance);
2698
+ }
2699
+ if (!b && t === X) {
2700
+ const o = P == null ? void 0 : P.environment.physics;
2701
+ if (o && (o.solver.kind === "physx" || o.solver.kind === "unsupported")) throw Object.assign(new Error("This session runs MuJoCo; the authored solver is unsupported."), { code: "PHYSICS_SOLVER_UNSUPPORTED" });
2702
+ if (await v.setPhysicsConfiguration({
2703
+ ...o ? { environment: { gravity: o.gravity, timeStepSeconds: o.timeStepSeconds, integrator: o.solver.integrator, solverIterations: o.solver.solverIterations } } : {},
2704
+ instances: Object.fromEntries(ee.filter((s) => s.nodeType === "asset").map((s) => {
2705
+ var i;
2706
+ return [s.nodeId, { override: s.physics, initialJoints: (i = s.initialPose) == null ? void 0 : i.joints }];
2707
+ }))
2708
+ }), b || t !== X) continue;
2709
+ at = t, xe(), ee.length === 0 && (Vn = !1), Vn || (Vn = xo());
2710
+ }
2711
+ }
2712
+ }
2713
+ } catch (t) {
2714
+ if (!b)
2715
+ throw Ee = gn(t), It(Ee), t;
2716
+ } finally {
2717
+ _t = !1, b || Mt();
2718
+ }
2719
+ };
2720
+ return {
2721
+ ready: gt,
2722
+ getRuntimeProjectionCapabilities() {
2723
+ return Ns();
2724
+ },
2725
+ getTransformOrigin(e) {
2726
+ if (b) return null;
2727
+ const t = ge.get(e);
2728
+ return t ? [...t] : null;
2729
+ },
2730
+ setTransformOrigin(e, t) {
2731
+ if (b) return !1;
2732
+ const r = P ? ln(P.root, e) : null;
2733
+ if (t !== null && (!r || r.nodeType === "domain" || e === (P == null ? void 0 : P.root.nodeId))) return !1;
2734
+ if (!r && t === null)
2735
+ return ge.delete(e), !0;
2736
+ if (t && (t.length !== 3 || t.some((i) => !Number.isFinite(i)))) return !1;
2737
+ const o = ge.get(e) ?? null;
2738
+ return (o === null ? t === null : t !== null && o.every((i, c) => i === t[c])) || (oe(), t ? ge.set(e, [...t]) : ge.delete(e), xe(), N()), !0;
2739
+ },
2740
+ setNodeDisplay(e, t) {
2741
+ if (b || !Y(e)) return !1;
2742
+ const o = { ...Ve.get(e) ?? {} };
2743
+ for (const s of ["transformControls", "selectionOutline", "originMarker"]) {
2744
+ const i = t[s];
2745
+ i === null ? delete o[s] : i !== void 0 && (o[s] = i);
2746
+ }
2747
+ return Object.keys(o).length ? Ve.set(e, o) : Ve.delete(e), xe(), N(), !0;
2748
+ },
2749
+ getNodeDisplay(e) {
2750
+ if (!Y(e)) return null;
2751
+ const t = Ve.get(e) ?? {};
2752
+ return {
2753
+ transformControls: t.transformControls ?? !0,
2754
+ selectionOutline: t.selectionOutline ?? !0,
2755
+ originMarker: t.originMarker ?? !0
2756
+ };
2757
+ },
2758
+ sync(e, t = Xe, r = lt) {
2759
+ if (b) return Promise.reject(new Error("Studio scene session is disposed."));
2760
+ const o = P, s = (o == null ? void 0 : o.sceneId) !== e.sceneId;
2761
+ if (s && I && oe(), s)
2762
+ ge.clear(), Ve.clear();
2763
+ else {
2764
+ const i = new Set(Co(e.root).map((c) => c.nodeId));
2765
+ for (const c of ge.keys()) i.has(c) || ge.delete(c);
2766
+ for (const c of Ve.keys()) i.has(c) || Ve.delete(c);
2767
+ }
2768
+ if (J += 1, P = e, lt = [...r], Xe = { ...t }, cr = /* @__PURE__ */ new WeakMap(), ee = [
2769
+ ...qi(e).map((i) => ({
2770
+ ...i,
2771
+ localTransform: Bt(
2772
+ Rn(e.root, i.nodeId) ?? i.localTransform
2773
+ ),
2774
+ variantSelections: { ...i.variantSelections },
2775
+ ...i.appearance ? {
2776
+ appearance: {
2777
+ ...i.appearance,
2778
+ ...i.appearance.color ? { color: [...i.appearance.color] } : {}
2779
+ }
2780
+ } : {},
2781
+ physics: { ...i.physics },
2782
+ ...i.initialPose ? { initialPose: { joints: { ...i.initialPose.joints } } } : {}
2783
+ })),
2784
+ ...Qi(e).map((i) => ({
2785
+ ...i,
2786
+ localTransform: Bt(
2787
+ Rn(e.root, i.nodeId) ?? i.localTransform
2788
+ ),
2789
+ ...i.appearance ? {
2790
+ appearance: {
2791
+ ...i.appearance,
2792
+ ...i.appearance.color ? { color: [...i.appearance.color] } : {}
2793
+ }
2794
+ } : {}
2795
+ })),
2796
+ ...Ki(e).map((i) => ({
2797
+ ...i,
2798
+ localTransform: Bt(
2799
+ Rn(e.root, i.nodeId) ?? i.localTransform
2800
+ ),
2801
+ size: [...i.size],
2802
+ ...i.semantic ? { semantic: { ...i.semantic } } : {}
2803
+ }))
2804
+ ], Lr(), X += 1, Pt.clear(), nr(), (I == null ? void 0 : I.kind) === "instance") {
2805
+ const i = Y(I.id);
2806
+ (!We(i) || !Ar(i.localTransform, I.base) || !jr(i, Et.get(I.id)) || I.instances.some((c) => !We(Y(c.nodeId)))) && oe();
2807
+ }
2808
+ return xe(), De || (De = Ue(async () => {
2809
+ do
2810
+ await bo();
2811
+ while (!b && at !== X);
2812
+ }).finally(() => {
2813
+ De = null;
2814
+ })), De;
2815
+ },
2816
+ pickPlacementTarget(e, t, r = []) {
2817
+ return bi(e, t, r);
2818
+ },
2819
+ pickPlacementSurface(e, t, r = []) {
2820
+ const o = this.pickPlacementTarget(e, t, r);
2821
+ return o.kind === "support-surface" || o.kind === "ground" ? o.surface : null;
2822
+ },
2823
+ captureViewport(e = {}) {
2824
+ return b ? Promise.reject(
2825
+ Object.assign(new Error("Scene session disposed."), { code: "SESSION_DISPOSED" })
2826
+ ) : Ue(async () => {
2827
+ var i, c;
2828
+ if (await gt, (i = e.signal) == null || i.throwIfAborted(), b)
2829
+ throw Object.assign(new Error("Scene session disposed."), { code: "SESSION_DISPOSED" });
2830
+ const t = X, r = E.visible, o = e.width ?? Math.max(1, n.canvas.width), s = e.height ?? Math.max(1, n.canvas.height);
2831
+ try {
2832
+ const u = e.scope === "selection" && P ? ((c = yr(P, L, kt)) == null ? void 0 : c.worldBounds) ?? null : e.scope === "scene" ? Di() : null;
2833
+ if (e.scope === "selection" && !u)
2834
+ throw Object.assign(new Error("Selection has no bounds."), {
2835
+ code: "CAPTURE_SELECTION_EMPTY"
2836
+ });
2837
+ if (e.scope === "scene" && !u)
2838
+ throw Object.assign(new Error("Scene has no visible model bounds."), {
2839
+ code: "CAPTURE_SCENE_EMPTY"
2840
+ });
2841
+ e.includeOverlays || (E.visible = !1);
2842
+ const d = AbortSignal.any(
2843
+ e.signal ? [m.signal, e.signal] : [m.signal]
2844
+ ), g = await l.captureFrame({
2845
+ ...e,
2846
+ signal: d,
2847
+ width: o,
2848
+ height: s,
2849
+ ...u ? { frameBounds: u, padding: e.padding ?? 1.2 } : {}
2850
+ });
2851
+ if (b)
2852
+ throw Object.assign(new Error("Scene session disposed."), { code: "SESSION_DISPOSED" });
2853
+ if (t !== X)
2854
+ throw Object.assign(new Error("Scene changed while capturing."), {
2855
+ code: "CONTEXT_STALE"
2856
+ });
2857
+ return g;
2858
+ } finally {
2859
+ E.visible = r, b || N();
2860
+ }
2861
+ });
2862
+ },
2863
+ getPhysicsFacts(e) {
2864
+ return P ? Ji(P, e, v.getInstanceRuntime(e)) : null;
2865
+ },
2866
+ getNodeFrame(e) {
2867
+ return P ? Tn(P, e, kt, Qn) : null;
2868
+ },
2869
+ measureNodeOriginAnchors(e) {
2870
+ if (b || !P) return null;
2871
+ const t = ln(P.root, e), r = R(e);
2872
+ if (!t || !r) return null;
2873
+ const o = qs(t, r.uuid), s = $n.get(e);
2874
+ if ((s == null ? void 0 : s.signature) === o) return s.anchors;
2875
+ const i = us(r, Ye(t));
2876
+ return $n.set(e, { signature: o, anchors: i }), i;
2877
+ },
2878
+ getSelectionFrame() {
2879
+ return P ? yr(P, L, kt) : null;
2880
+ },
2881
+ focusNodes(e, t = {}) {
2882
+ if (b || !P) return !1;
2883
+ const r = yr(P, e, kt);
2884
+ return r.worldBounds ? l.fitView(
2885
+ new K(
2886
+ new p().fromArray(r.worldBounds.min),
2887
+ new p().fromArray(r.worldBounds.max)
2888
+ ),
2889
+ t
2890
+ ) : !1;
2891
+ },
2892
+ setTransformSpace(e) {
2893
+ oe(), le = null, f.setSpace(e), x.setSpace(e), N();
2894
+ },
2895
+ setEditorial(e) {
2896
+ Xe = { ...e }, Lr(), X += 1, (I == null ? void 0 : I.kind) === "instance" && I.instances.some((t) => !We(Y(t.nodeId))) && oe(), xe(), N(), De || (De = Ue(async () => {
2897
+ do
2898
+ await bo();
2899
+ while (!b && at !== X);
2900
+ }).catch((t) => {
2901
+ b || It(gn(t));
2902
+ }).finally(() => {
2903
+ De = null;
2904
+ }));
2905
+ },
2906
+ measureAssetBounds(e) {
2907
+ return Ue(async () => {
2908
+ if (await gt, b) throw Object.assign(new Error("Scene session disposed."), { code: "SESSION_DISPOSED" });
2909
+ const t = await n.resolveSource(e, void 0, m.signal);
2910
+ if (!t) throw Object.assign(new Error("Asset source unavailable: " + e), { code: "ASSET_SOURCE_UNAVAILABLE" });
2911
+ let r;
2912
+ do
2913
+ r = "__studio-bounds-" + ++xn;
2914
+ while (Y(r) || R(r));
2915
+ try {
2916
+ const o = await v.addInstance({ ...t, id: r, placement: { ...gr(), visible: !1 } });
2917
+ if (o.error) throw Object.assign(new Error(o.error.message), { code: o.error.code });
2918
+ const s = R(r);
2919
+ if (!s) throw Object.assign(new Error("Asset geometry unavailable."), { code: "PLACEMENT_BOUNDS_UNAVAILABLE" });
2920
+ await Kn(r, s);
2921
+ const i = zn(s);
2922
+ if (i.isEmpty()) throw Object.assign(new Error("Asset geometry has no measurable bounds."), { code: "PLACEMENT_BOUNDS_UNAVAILABLE" });
2923
+ return { min: i.min.toArray(), max: i.max.toArray() };
2924
+ } finally {
2925
+ await v.removeInstance(r);
2926
+ }
2927
+ });
2928
+ },
2929
+ measureAssets(e) {
2930
+ const t = [...new Set(e.filter((r) => typeof r == "string" && r))];
2931
+ return b || !t.length ? Promise.resolve({}) : Ue(async () => {
2932
+ const r = {};
2933
+ for (const o of t) {
2934
+ if (b) break;
2935
+ await gt;
2936
+ const s = await n.resolveSource(
2937
+ o,
2938
+ ee.find((c) => c.nodeType === "asset" && c.assetRevisionId === o),
2939
+ m.signal
2940
+ );
2941
+ if (b || !s) continue;
2942
+ let i;
2943
+ do
2944
+ i = `__studio-measure-${++xn}`;
2945
+ while (Y(i) || R(i));
2946
+ try {
2947
+ const c = await v.addInstance({ ...s, id: i, placement: { ...gr(), visible: !1 } });
2948
+ if (b || c.error) continue;
2949
+ const u = R(i);
2950
+ if (!u) continue;
2951
+ const d = await Kn(i, u);
2952
+ d.isEmpty() || (r[o] = d.max.clone().sub(d.min).toArray());
2953
+ } catch {
2954
+ } finally {
2955
+ await v.removeInstance(i);
2956
+ }
2957
+ }
2958
+ return b || N(), r;
2959
+ });
2960
+ },
2961
+ preparePlacement(e, t, r = "adaptive") {
2962
+ if (b) return Promise.reject(new Error("Studio scene session is disposed."));
2963
+ if (!t.every(Number.isFinite)) return Promise.reject(new Error("Placement point must contain finite coordinates."));
2964
+ const o = [...t];
2965
+ return Ue(async () => {
2966
+ if (b) throw new Error("Studio scene session is disposed.");
2967
+ await gt;
2968
+ const s = await n.resolveSource(
2969
+ e,
2970
+ ee.find((u) => u.nodeType === "asset" && u.assetRevisionId === e),
2971
+ m.signal
2972
+ );
2973
+ if (b) throw new Error("Studio scene session is disposed.");
2974
+ if (!s) throw new Error(`Asset source unavailable: ${e}`);
2975
+ let i;
2976
+ do
2977
+ i = `__studio-placement-${++xn}`;
2978
+ while (Y(i) || R(i));
2979
+ const c = gr();
2980
+ try {
2981
+ const u = await v.addInstance({ ...s, id: i, placement: { ...c, visible: !1 } });
2982
+ if (b) throw new Error("Studio scene session is disposed.");
2983
+ if (u.error) throw new Error(u.error.message);
2984
+ const d = R(i);
2985
+ if (!d) throw new Error(`Asset has no measurable geometry: ${e}`);
2986
+ const g = await Kn(i, d);
2987
+ if (g.isEmpty()) throw new Error(`Asset has no measurable geometry: ${e}`);
2988
+ const h = r === "adaptive" ? Ro({
2989
+ min: g.min.toArray(),
2990
+ max: g.max.toArray()
2991
+ }) : r;
2992
+ return ss(c, { min: g.min.toArray(), max: g.max.toArray() }, [o[0], o[1]], { floorZ: o[2], snap: h });
2993
+ } finally {
2994
+ await v.removeInstance(i), N();
2995
+ }
2996
+ });
2997
+ },
2998
+ beginPlacementPreview(e, t) {
2999
+ return b ? Promise.reject(new Error("Studio scene session is disposed.")) : Ue(async () => {
3000
+ if (await gt, b) throw new Error("Studio scene session is disposed.");
3001
+ await Un();
3002
+ const r = await n.resolveSource(e, void 0, m.signal);
3003
+ if (!r) throw new Error(`Asset source unavailable: ${e}`);
3004
+ let o;
3005
+ do
3006
+ o = `__studio-ghost-${++xn}`;
3007
+ while (Y(o) || R(o));
3008
+ const s = await v.addInstance({
3009
+ ...r,
3010
+ id: o,
3011
+ placement: { ...t, visible: !0 }
3012
+ });
3013
+ if (s.error) throw new Error(s.error.message);
3014
+ const i = R(o);
3015
+ if (!i)
3016
+ throw await v.removeInstance(o), new Error(`Asset has no preview geometry: ${e}`);
3017
+ return Ut.apply(o, i, {
3018
+ color: [0.35, 0.75, 0.9],
3019
+ opacity: 0.38
3020
+ }), Ze = {
3021
+ id: o,
3022
+ assetId: e,
3023
+ transform: Bt(t)
3024
+ }, N(), !0;
3025
+ });
3026
+ },
3027
+ updatePlacementPreview(e) {
3028
+ if (b) return Promise.reject(new Error("Studio scene session is disposed."));
3029
+ const t = Ze;
3030
+ return t ? Ue(async () => {
3031
+ if (!Ze || Ze.id !== t.id) return !1;
3032
+ const r = await v.setInstancePlacement(t.id, {
3033
+ ...e,
3034
+ visible: !0
3035
+ });
3036
+ return r && (Ze = { ...Ze, transform: Bt(e) }), N(), r;
3037
+ }) : Promise.resolve(!1);
3038
+ },
3039
+ confirmPlacementPreview() {
3040
+ return b ? Promise.resolve(null) : Ue(async () => {
3041
+ const e = Ze;
3042
+ if (!e) return null;
3043
+ const t = Bt(e.transform);
3044
+ return await Un(), t;
3045
+ });
3046
+ },
3047
+ cancelPlacementPreview() {
3048
+ return b ? Promise.resolve() : Ue(Un);
3049
+ },
3050
+ select(e, t) {
3051
+ if (b) return;
3052
+ const r = [...new Set(e)], o = P, s = o ? r.find((c) => {
3053
+ var u;
3054
+ return ((u = ln(o.root, c)) == null ? void 0 : u.nodeType) === "group";
3055
+ }) : void 0, i = t === void 0 ? s ?? r[r.length - 1] ?? null : t;
3056
+ i === Me && r.length === L.length && r.every((c, u) => c === L[u]) || (Ie && en(), I && oe(), dt = !1, Qe = !1, le = null, L = r, Me = i, T.visible = !1, xe());
3057
+ },
3058
+ selectRegion(e) {
3059
+ b || ce === e || (Ie && en(), I && oe(), ce = e, nr(), xe());
3060
+ },
3061
+ setRegionMode(e) {
3062
+ b || V === e || (Ie && en(), I && oe(), V = e, j.visible = e, T.visible = !1, e || (ce = null), rt(), xe(), N());
3063
+ },
3064
+ setRegionIssues(e) {
3065
+ if (b) return;
3066
+ const t = new Set(e);
3067
+ t.size === ne.size && [...t].every((r) => ne.has(r)) || (ne = t, nr(), xe());
3068
+ },
3069
+ focusRegion(e) {
3070
+ if (b || I || re || _ !== null || je) return !1;
3071
+ const t = tt.get(e);
3072
+ if (!t) return !1;
3073
+ const r = new K().setFromObject(t, !0);
3074
+ return !r.isEmpty() && l.fitView(r, { padding: 1.8, viewMode: "3d" });
3075
+ },
3076
+ getRegionOverlayIds() {
3077
+ return b ? [] : [...tt.keys()].sort();
3078
+ },
3079
+ getRegionOverlayScreenRect(e) {
3080
+ if (b) return null;
3081
+ const t = tt.get(e);
3082
+ if (!t) return null;
3083
+ const r = new K().setFromObject(t, !0);
3084
+ if (r.isEmpty()) return null;
3085
+ const o = l.getActiveCamera();
3086
+ o.updateMatrixWorld(!0);
3087
+ const s = n.canvas.getBoundingClientRect(), i = [
3088
+ new p(r.min.x, r.min.y, r.min.z),
3089
+ new p(r.min.x, r.min.y, r.max.z),
3090
+ new p(r.min.x, r.max.y, r.min.z),
3091
+ new p(r.min.x, r.max.y, r.max.z),
3092
+ new p(r.max.x, r.min.y, r.min.z),
3093
+ new p(r.max.x, r.min.y, r.max.z),
3094
+ new p(r.max.x, r.max.y, r.min.z),
3095
+ new p(r.max.x, r.max.y, r.max.z)
3096
+ ].map((h) => {
3097
+ const A = h.project(o);
3098
+ return {
3099
+ x: s.left + (A.x + 1) * s.width / 2,
3100
+ y: s.top + (1 - A.y) * s.height / 2
3101
+ };
3102
+ }), c = i.map((h) => h.x), u = i.map((h) => h.y), d = Math.min(...c), g = Math.min(...u);
3103
+ return { left: d, top: g, width: Math.max(...c) - d, height: Math.max(...u) - g };
3104
+ },
3105
+ getRegionShapeHandleScreenPoints(e) {
3106
+ return b || ce !== e ? [] : [...qt.entries()].map(([t, r]) => ({
3107
+ id: t,
3108
+ ...zt(r.getWorldPosition(new p()))
3109
+ }));
3110
+ },
3111
+ getTransformControlScreenPoint(e) {
3112
+ if (w && f.getMode() === "translate" && f.object)
3113
+ return f.object.updateWorldMatrix(!0, !1), zt(f.object.getWorldPosition(new p()));
3114
+ if (w && f.getMode() === "rotate") {
3115
+ const W = Zr();
3116
+ if (!W) return null;
3117
+ const $ = e === "X" ? W.startAngle : e === "Y" ? W.startAngle + W.delta * 0.5 : W.startAngle + W.delta;
3118
+ return zt(Or(W, $));
3119
+ }
3120
+ if (b || !f.object) return null;
3121
+ const t = l.getActiveCamera();
3122
+ t.updateMatrixWorld(!0), f.object.updateWorldMatrix(!0, !1), f.camera = t, f.getHelper().updateMatrixWorld(!0);
3123
+ const r = f.object.getWorldPosition(new p()), o = f.getMode() === "rotate" ? e === "X" ? new p(0, 1, 0) : new p(1, 0, 0) : new p(
3124
+ e === "X" ? 1 : 0,
3125
+ e === "Y" ? 1 : 0,
3126
+ e === "Z" ? 1 : 0
3127
+ );
3128
+ (f.getMode() === "scale" ? "local" : f.space) === "local" && o.applyQuaternion(
3129
+ f.object.getWorldQuaternion(new se()).normalize()
3130
+ );
3131
+ const i = r.clone().add(o), c = r.project(t), u = i.project(t), d = n.canvas.getBoundingClientRect(), g = {
3132
+ x: d.left + (c.x + 1) * d.width / 2,
3133
+ y: d.top + (1 - c.y) * d.height / 2
3134
+ }, h = {
3135
+ x: d.left + (u.x + 1) * d.width / 2,
3136
+ y: d.top + (1 - u.y) * d.height / 2
3137
+ }, A = h.x - g.x, O = h.y - g.y, D = Math.hypot(A, O);
3138
+ if (!Number.isFinite(D) || D < 1e-6) return null;
3139
+ const z = {
3140
+ x: g.x + A / D * 46,
3141
+ y: g.y + O / D * 46
3142
+ };
3143
+ if (f.getMode() !== "rotate") return z;
3144
+ const de = (W) => (f.pointerHover({
3145
+ x: (W.x - d.left) / d.width * 2 - 1,
3146
+ y: -(W.y - d.top) / d.height * 2 + 1,
3147
+ button: 0
3148
+ }), f.axis === e), be = [];
3149
+ de(z) && be.push(z);
3150
+ for (let W = 20; W <= 96; W += 4)
3151
+ for (let $ = 0; $ < 64; $ += 1) {
3152
+ const ie = $ / 64 * Math.PI * 2, F = {
3153
+ x: g.x + Math.cos(ie) * W,
3154
+ y: g.y + Math.sin(ie) * W
3155
+ };
3156
+ de(F) && be.push(F);
3157
+ }
3158
+ let ue = null, Se = -1;
3159
+ for (const W of be) {
3160
+ const $ = be.reduce((ie, F) => ie + (Math.hypot(F.x - W.x, F.y - W.y) <= 7 ? 1 : 0), 0);
3161
+ $ > Se && (ue = W, Se = $);
3162
+ }
3163
+ return ue ? (de(ue), ue) : z;
3164
+ },
3165
+ setMode(e) {
3166
+ b || (I && oe(), dt = !1, Qe = !1, le = null, f.setMode(e), xe(), N());
3167
+ },
3168
+ setBoxSelectionEnabled(e) {
3169
+ b || (oe(), ft = e, n.canvas.style.cursor = e ? "crosshair" : "", xe());
3170
+ },
3171
+ cancelActiveGesture() {
3172
+ b || oe();
3173
+ },
3174
+ setSnap(e) {
3175
+ b || (Ge = e, Ke = or(), f.setTranslationSnap(e ? Ke : null), f.setRotationSnap(e ? it.rotate : null), x.setRotationSnap(e ? it.rotate : null), f.setScaleSnap(e ? it.scale : null), N());
3176
+ },
3177
+ getSnapStepM() {
3178
+ return or();
3179
+ },
3180
+ setSurfaceSnap(e) {
3181
+ b || (Vt = e, e || (Ae = null, rt()));
3182
+ },
3183
+ setOverlapPrevention(e) {
3184
+ b || (Ht = e, e || (Pe = !1, Le = [], rt()));
3185
+ },
3186
+ fit() {
3187
+ return I || re || _ !== null || je ? !1 : xo();
3188
+ },
3189
+ focus(e = L, t) {
3190
+ return I || re || _ !== null || je ? !1 : this.focusNodes(e, t);
3191
+ },
3192
+ zoomIn(e = 1.2) {
3193
+ if (I || re || _ !== null || je) return !1;
3194
+ const t = To(l.camera.getState(), "in", e);
3195
+ return t ? l.camera.setState(t) : !1;
3196
+ },
3197
+ zoomOut(e = 1.2) {
3198
+ if (I || re || _ !== null || je) return !1;
3199
+ const t = To(l.camera.getState(), "out", e);
3200
+ return t ? l.camera.setState(t) : !1;
3201
+ },
3202
+ groundPoint(e, t) {
3203
+ if (b) return null;
3204
+ const r = l.screenToWorldOnPlane(e, t, 0);
3205
+ return r && [r.x, r.y, r.z].every(Number.isFinite) ? [r.x, r.y, r.z] : null;
3206
+ },
3207
+ setGroundVisible(e) {
3208
+ b || (Tr = e, v.setGroundVisible(e), N());
3209
+ },
3210
+ setCollisionVisible(e) {
3211
+ b || (v.setCollisionVisible(e), N());
3212
+ },
3213
+ setGrabEnabled(e) {
3214
+ b || v.setGrabEnabled(e);
3215
+ },
3216
+ setTheme(e) {
3217
+ b || (l.setTheme(e), v.setTheme(e), N());
3218
+ },
3219
+ setEditingEnabled(e) {
3220
+ b || G === e || (G = e, G || oe(), xe(), N());
3221
+ },
3222
+ setSelectionInspectionEnabled(e) {
3223
+ b || At === e || (At = e, xe(), N());
3224
+ },
3225
+ getCameraState() {
3226
+ return b ? null : l.camera.getState();
3227
+ },
3228
+ setCameraState(e) {
3229
+ return b ? !1 : (B(), l.camera.setState(e));
3230
+ },
3231
+ setAxisView(e, t) {
3232
+ if (b || I || re || _ !== null || je) return !1;
3233
+ const r = l.camera.getState();
3234
+ if (!r || r.viewMode !== "3d" || !r.orbit) return !1;
3235
+ const o = Math.PI / 2 - 1e-4, s = e === "x" ? t === 1 ? 0 : Math.PI : e === "y" ? t * Math.PI / 2 : -Math.PI / 2, i = e === "z" ? t * o : 0;
3236
+ B();
3237
+ const c = r.orbit, u = Math.atan2(Math.sin(s - c.yaw), Math.cos(s - c.yaw));
3238
+ if (typeof requestAnimationFrame != "function")
3239
+ return l.camera.setState({ ...r, orbit: { ...c, yaw: s, pitch: i } });
3240
+ let d = null;
3241
+ const g = (h) => {
3242
+ if (b) return;
3243
+ d ?? (d = h);
3244
+ const A = Math.min((h - d) / 350, 1), O = A * A * (3 - 2 * A), D = A === 1 ? s : c.yaw + u * O;
3245
+ if (!l.camera.setState({ ...r, orbit: { ...c, yaw: D, pitch: c.pitch + (i - c.pitch) * O } })) {
3246
+ C = null;
3247
+ return;
3248
+ }
3249
+ C = A < 1 ? requestAnimationFrame(g) : null;
3250
+ };
3251
+ return C = requestAnimationFrame(g), !0;
3252
+ },
3253
+ resetCamera() {
3254
+ return b ? !1 : (B(), l.camera.reset());
3255
+ },
3256
+ getCameraQuaternion() {
3257
+ const e = l.getActiveCamera().quaternion;
3258
+ return [e.x, e.y, e.z, e.w];
3259
+ },
3260
+ getRuntime(e) {
3261
+ return b ? null : v.getInstanceRuntime(e);
3262
+ },
3263
+ getInstanceBounds(e) {
3264
+ if (b) return null;
3265
+ const t = Y(e);
3266
+ if ((t == null ? void 0 : t.nodeType) === "placeholder") {
3267
+ const r = R(e);
3268
+ if (!r) return null;
3269
+ const o = he(r);
3270
+ if (o.isEmpty()) return null;
3271
+ const s = o.min.toArray(), i = o.max.toArray();
3272
+ return {
3273
+ min: s,
3274
+ max: i,
3275
+ size: [i[0] - s[0], i[1] - s[1], i[2] - s[2]]
3276
+ };
3277
+ }
3278
+ return v.getInstanceBounds(e);
3279
+ },
3280
+ focusPrim(e, t) {
3281
+ if (b) return !1;
3282
+ const r = R(e);
3283
+ if (!r || !t) return !1;
3284
+ let o = null;
3285
+ return r.traverse((s) => {
3286
+ Er(s) === t && (o = s);
3287
+ }), o || r.traverse((s) => {
3288
+ const i = Er(s);
3289
+ !o && (i != null && i.startsWith(`${t}/`)) && (o = s);
3290
+ }), !o || (T.box.setFromObject(o, !0), T.box.isEmpty()) ? !1 : (T.visible = !0, T.updateMatrixWorld(!0), N(), !0);
3291
+ },
3292
+ getScenePhysicsState() {
3293
+ return v.getScenePhysicsState();
3294
+ },
3295
+ getScenePhysicsRuntime() {
3296
+ return b ? null : v.getScenePhysicsRuntime();
3297
+ },
3298
+ runDeterministicCheck(e) {
3299
+ if (b)
3300
+ return {
3301
+ status: "unavailable",
3302
+ reason: "Studio scene session is disposed.",
3303
+ checkedAt: (/* @__PURE__ */ new Date()).toISOString(),
3304
+ timestep: null,
3305
+ steps: 0,
3306
+ initial: null,
3307
+ final: null,
3308
+ bounds: {},
3309
+ overlaps: [],
3310
+ bodyMotion: {}
3311
+ };
3312
+ const t = v.runDeterministicCheck(e);
3313
+ return N(), t;
3314
+ },
3315
+ play(e) {
3316
+ return !b && v.playInstance(e);
3317
+ },
3318
+ pause(e) {
3319
+ return !b && v.pauseInstance(e);
3320
+ },
3321
+ resetPhysics(e) {
3322
+ return !b && v.resetInstance(e);
3323
+ },
3324
+ playScene() {
3325
+ return !b && v.playScene();
3326
+ },
3327
+ pauseScene() {
3328
+ return !b && v.pauseScene();
3329
+ },
3330
+ stepScene(e) {
3331
+ const t = !b && v.stepScene(e);
3332
+ return t && N(), t;
3333
+ },
3334
+ resetScene() {
3335
+ return !b && v.resetScene();
3336
+ },
3337
+ isSimulationRunning() {
3338
+ return !b && v.isSimulationRunning();
3339
+ },
3340
+ getStatus: Fr,
3341
+ getAssetLoadStatus(e) {
3342
+ return qe.get(e) ?? null;
3343
+ },
3344
+ dispose() {
3345
+ if (ae) return ae;
3346
+ B(), oe(), Ze = null, H == null || H.remove(), H = null, w == null || w.dispose(), Hr();
3347
+ for (const t of [...qe.keys()]) En(t);
3348
+ b = !0, m.abort(), y == null || y.removeEventListener("abort", M);
3349
+ for (const t of mt.splice(0)) t();
3350
+ f.removeEventListener("mouseDown", Pn), f.removeEventListener("objectChange", jt), f.removeEventListener("mouseUp", Lt), f.removeEventListener("change", N), f.detach();
3351
+ for (const t of Te.values()) t.object.traverse((r) => {
3352
+ r instanceof Z && (r.geometry.dispose(), r.material.dispose());
3353
+ });
3354
+ Te.clear(), f.dispose(), x.removeEventListener("mouseDown", Pn), x.removeEventListener("objectChange", jt), x.removeEventListener("mouseUp", Lt), x.removeEventListener("change", N), x.detach(), x.dispose(), l.overlays.remove(Mr, { dispose: !1 });
3355
+ for (const t of Je.values()) t.dispose();
3356
+ Je.clear(), $n.clear(), ge.clear(), Ve.clear(), ke.clear(), Nr.dispose(), zr.dispose(), k.dispose(), T.dispose(), Ut.dispose(), Mt();
3357
+ const e = l.closeScene();
3358
+ return ae = Promise.allSettled([De, Hn, e]).then(() => {
3359
+ l.dispose();
3360
+ }), ae;
3361
+ }
3362
+ };
3363
+ }
3364
+ function Xs(n, a) {
3365
+ return n.sourceRevisionId === a.sourceRevisionId && n.kind === a.kind && n.phase === a.phase && n.stage === a.stage && n.outcome === a.outcome && n.message === a.message && JSON.stringify(n.progress) === JSON.stringify(a.progress) && JSON.stringify(n.warning) === JSON.stringify(a.warning) && JSON.stringify(n.error) === JSON.stringify(a.error);
3366
+ }
3367
+ function Vs(n) {
3368
+ switch (n) {
3369
+ case "usd-physics":
3370
+ case "compile":
3371
+ case "runtime":
3372
+ return "preparing-physics";
3373
+ case "resolving-source":
3374
+ case "downloading":
3375
+ case "validating":
3376
+ return n;
3377
+ default:
3378
+ return "parsing-visual";
3379
+ }
3380
+ }
3381
+ function Hs(n) {
3382
+ return n ? { code: n.code, message: n.message, stage: n.stage } : null;
3383
+ }
3384
+ function Gs(n, a) {
3385
+ return { code: typeof n == "object" && n !== null && "code" in n && typeof n.code == "string" ? n.code : "ASSET_LOAD_FAILED", message: gn(n), stage: a };
3386
+ }
3387
+ function Bt(n) {
3388
+ return { position: [...n.position], rotation: [...n.rotation], scale: [...n.scale] };
3389
+ }
3390
+ function $s(n, a) {
3391
+ const l = (m, y) => {
3392
+ const M = y.clone().multiply(jn(m.localTransform));
3393
+ if (m.nodeId === a) return M;
3394
+ if (m.nodeType !== "group") return null;
3395
+ for (const v of m.children) {
3396
+ const f = l(v, M);
3397
+ if (f) return f;
3398
+ }
3399
+ return null;
3400
+ };
3401
+ return l(n, new _e());
3402
+ }
3403
+ function jn(n) {
3404
+ return new _e().compose(
3405
+ new p().fromArray(n.position),
3406
+ new se().fromArray(n.rotation).normalize(),
3407
+ new p().fromArray(n.scale)
3408
+ );
3409
+ }
3410
+ function _o(n) {
3411
+ if (n.shape.kind === "rectangle")
3412
+ return new Gi(n.shape.widthM, n.shape.heightM);
3413
+ if (n.shape.kind === "box")
3414
+ return new Jo(n.shape.widthM, n.shape.depthM, n.shape.heightM);
3415
+ const a = new kr();
3416
+ n.shape.points.forEach((m, y) => {
3417
+ y === 0 ? a.moveTo(m[0], m[1]) : a.lineTo(m[0], m[1]);
3418
+ }), a.closePath();
3419
+ const l = new $i(a, { depth: n.shape.heightM, bevelEnabled: !1 });
3420
+ return l.translate(0, 0, -n.shape.heightM / 2), l;
3421
+ }
3422
+ function Zs() {
3423
+ const a = new Uint8Array(16384), l = 63 / 2;
3424
+ for (let y = 0; y < 64; y += 1)
3425
+ for (let M = 0; M < 64; M += 1) {
3426
+ const v = Math.hypot(M - l, y - l), f = 1 - Yn((v - 5.2) / 1.2), x = Math.pow(1 - Yn(v / 24), 2) * 0.38, S = Math.round(Math.max(f, x) * 255), w = (y * 64 + M) * 4;
3427
+ a[w] = 255, a[w + 1] = 255, a[w + 2] = 255, a[w + 3] = S;
3428
+ }
3429
+ const m = new Qo(a, 64, 64, Ko);
3430
+ return m.magFilter = Bn, m.minFilter = Bn, m.generateMipmaps = !1, m.needsUpdate = !0, m;
3431
+ }
3432
+ function Us() {
3433
+ const a = new Uint8Array(16384), l = 63 / 2;
3434
+ for (let y = 0; y < 64; y += 1)
3435
+ for (let M = 0; M < 64; M += 1) {
3436
+ const v = Math.hypot(M - l, y - l), f = (y * 64 + M) * 4;
3437
+ let x = 255, S = 158, w = 35, E = 0;
3438
+ v <= 9.5 ? E = 255 : v <= 12.5 ? (x = 255, S = 250, w = 236, E = 255) : v <= 15.5 ? (x = 8, S = 16, w = 18, E = Math.round(Yn((15.5 - v) / 1.4) * 230)) : E = Math.round(Math.pow(1 - Yn((v - 15.5) / 10), 2) * 46), a[f] = x, a[f + 1] = S, a[f + 2] = w, a[f + 3] = E;
3439
+ }
3440
+ const m = new Qo(a, 64, 64, Ko);
3441
+ return m.colorSpace = Xi, m.magFilter = Bn, m.minFilter = Bn, m.generateMipmaps = !1, m.needsUpdate = !0, m;
3442
+ }
3443
+ function qs(n, a) {
3444
+ return `${a}:${JSON.stringify(n, (l, m) => l === "origin" || l === "label" ? void 0 : m)}`;
3445
+ }
3446
+ function Qs(n) {
3447
+ if (!n) return Yo;
3448
+ const a = Math.max(
3449
+ n.max[0] - n.min[0],
3450
+ n.max[1] - n.min[1],
3451
+ n.max[2] - n.min[2]
3452
+ );
3453
+ return Math.max(
3454
+ Yo,
3455
+ Math.min(Ds, a * 0.025)
3456
+ );
3457
+ }
3458
+ function Yn(n) {
3459
+ return Math.max(0, Math.min(1, n));
3460
+ }
3461
+ function Ks(n) {
3462
+ const a = new se();
3463
+ return n === "-Z" ? a.setFromAxisAngle(new p(1, 0, 0), Math.PI) : n === "+X" ? a.setFromAxisAngle(new p(0, 1, 0), Math.PI / 2) : n === "-X" ? a.setFromAxisAngle(new p(0, 1, 0), -Math.PI / 2) : n === "+Y" ? a.setFromAxisAngle(new p(1, 0, 0), -Math.PI / 2) : n === "-Y" && a.setFromAxisAngle(new p(1, 0, 0), Math.PI / 2), a;
3464
+ }
3465
+ function Js(n) {
3466
+ return n === "+X" ? new p(1, 0, 0) : n === "-X" ? new p(-1, 0, 0) : n === "+Y" ? new p(0, 1, 0) : n === "-Y" ? new p(0, -1, 0) : n === "-Z" ? new p(0, 0, -1) : new p(0, 0, 1);
3467
+ }
3468
+ function Oe(n) {
3469
+ return { position: n.position.toArray(), rotation: n.quaternion.toArray(), scale: n.scale.toArray() };
3470
+ }
3471
+ function ze(n, a) {
3472
+ n.position.fromArray(a.position), n.quaternion.fromArray(a.rotation), n.scale.fromArray(a.scale), n.updateMatrixWorld(!0);
3473
+ }
3474
+ function Ft(n, a) {
3475
+ n.position.copy(n.parent ? n.parent.worldToLocal(a.clone()) : a);
3476
+ }
3477
+ function Xo(n, a) {
3478
+ var m;
3479
+ const l = ((m = n.parent) == null ? void 0 : m.getWorldQuaternion(new se()).normalize()) ?? new se();
3480
+ n.quaternion.copy(l.invert().multiply(a)).normalize();
3481
+ }
3482
+ function ea(n, a) {
3483
+ var m;
3484
+ const l = ((m = n.parent) == null ? void 0 : m.getWorldScale(new p())) ?? new p(1, 1, 1);
3485
+ n.scale.copy(a).divide(l);
3486
+ }
3487
+ function Ar(n, a) {
3488
+ return [...n.position, ...n.rotation, ...n.scale].every((l, m) => Math.abs(l - [...a.position, ...a.rotation, ...a.scale][m]) < 1e-9);
3489
+ }
3490
+ function Er(n) {
3491
+ var l, m;
3492
+ let a = n;
3493
+ for (; a; ) {
3494
+ const y = (m = (l = a.userData) == null ? void 0 : l.usd) == null ? void 0 : m.path;
3495
+ if (typeof y == "string" && y.startsWith("/")) return y;
3496
+ a = a.parent;
3497
+ }
3498
+ return null;
3499
+ }
3500
+ function gn(n) {
3501
+ return n instanceof Error ? n.message : String(n);
3502
+ }
3503
+ export {
3504
+ ua as c,
3505
+ bs as t
3506
+ };