@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,3231 @@
1
+ var dn = Object.defineProperty;
2
+ var pn = (n, t, i) => t in n ? dn(n, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[t] = i;
3
+ var F = (n, t, i) => pn(n, typeof t != "symbol" ? t + "" : t, i);
4
+ import { c as mn, a as hn, b as yn, w as ri, d as ai, p as gn } from "./asset-ir-DEOK9SqE.js";
5
+ import { n as ut, I as Oi, J as ci, p as wn, q as bn, s as li, K as xn, y as An, L as ui, S as fi } from "./index-ByBlfVc0.js";
6
+ import { Quaternion as tt, Euler as Zt, LoadingManager as Vi, Group as lt, Mesh as C, MeshLambertMaterial as vn, MeshPhongMaterial as di, MeshStandardMaterial as He, TextureLoader as Mn, SRGBColorSpace as Pn, RepeatWrapping as Sn, BoxGeometry as Ze, SphereGeometry as Qe, CylinderGeometry as Wi, CapsuleGeometry as Gi, Matrix4 as Z, Vector3 as U, MathUtils as Tn, Matrix3 as pi, Box3 as it, BufferAttribute as Xi, Line3 as ft, Plane as Ji, Vector2 as yt, Triangle as Ft, BackSide as Rn, DoubleSide as Bn, REVISION as Hi, Ray as _n, FrontSide as mi, LineSegments as Ye, LineLoop as Zi, Line as Ke, Points as Qi, Sphere as En, BatchedMesh as Un, AxesHelper as zn, ArrowHelper as hi, BufferGeometry as $n, LineBasicMaterial as yi, Float32BufferAttribute as Fn, MeshBasicMaterial as gi, EdgesGeometry as In } from "three";
7
+ import { GLTFLoader as Dn } from "three/examples/jsm/loaders/GLTFLoader.js";
8
+ import { ColladaLoader as Ln } from "three/examples/jsm/loaders/ColladaLoader.js";
9
+ import { OBJLoader as kn } from "three/examples/jsm/loaders/OBJLoader.js";
10
+ import { STLLoader as jn } from "three/examples/jsm/loaders/STLLoader.js";
11
+ function Yi(n) {
12
+ const t = new Map(n.map((o) => [o.id, o])), i = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Set(), s = (o) => {
13
+ throw Object.assign(new Error(`Invalid URDF mimic relationship: ${o}`), { code: "E_URDF_MIMIC" });
14
+ }, r = (o) => {
15
+ var f;
16
+ const l = i.get(o);
17
+ if (l) return l;
18
+ const a = t.get(o);
19
+ if (!a || e.has(o)) return s(o);
20
+ e.add(o);
21
+ let d = { root: o, multiplier: 1, offset: 0 };
22
+ if (a.mimic) {
23
+ const p = a.mimic;
24
+ if (![p.multiplier, p.offset].every(Number.isFinite) || !["revolute", "continuous", "prismatic"].includes(a.type) || !["revolute", "continuous", "prismatic"].includes(((f = t.get(p.joint)) == null ? void 0 : f.type) ?? "")) return s(o);
25
+ const c = r(p.joint);
26
+ if (d = { root: c.root, multiplier: p.multiplier * c.multiplier, offset: p.multiplier * c.offset + p.offset }, ![d.multiplier, d.offset].every(Number.isFinite)) return s(o);
27
+ }
28
+ return e.delete(o), i.set(o, d), d;
29
+ };
30
+ for (const o of n) r(o.id);
31
+ return i;
32
+ }
33
+ function Ae(n) {
34
+ const t = Yi(n), i = /* @__PURE__ */ new Map();
35
+ for (const e of n) {
36
+ const s = t.get(e.id);
37
+ if (i.has(s.root) || i.set(s.root, { lower: -1 / 0, upper: 1 / 0 }), e.type === "continuous" || !e.limits || e.limits.lower > e.limits.upper) continue;
38
+ const r = i.get(s.root);
39
+ if (s.multiplier === 0) {
40
+ if (s.offset < e.limits.lower || s.offset > e.limits.upper) throw new Error(`URDF mimic constant violates limits: ${e.id}`);
41
+ continue;
42
+ }
43
+ const o = (e.limits.lower - s.offset) / s.multiplier, l = (e.limits.upper - s.offset) / s.multiplier;
44
+ if (r.lower = Math.max(r.lower, Math.min(o, l)), r.upper = Math.min(r.upper, Math.max(o, l)), r.lower > r.upper) throw new Error(`URDF mimic limits have no feasible range: ${s.root}`);
45
+ }
46
+ return i;
47
+ }
48
+ function ti(n, t = {}) {
49
+ const i = Yi(n), e = Ae(n);
50
+ return Object.fromEntries(n.map((s) => {
51
+ const r = i.get(s.id), o = e.get(r.root), l = Math.max(o.lower, Math.min(o.upper, t[r.root] ?? 0));
52
+ return [s.id, l * r.multiplier + r.offset];
53
+ }));
54
+ }
55
+ function Qt(n) {
56
+ return n.rotationQuaternion ? new tt().fromArray(n.rotationQuaternion).normalize() : new tt().setFromEuler(new Zt(n.rotationRpy[0], n.rotationRpy[1], n.rotationRpy[2], "ZYX"));
57
+ }
58
+ function Cn(n) {
59
+ const t = /* @__PURE__ */ new Map(), i = (e) => {
60
+ if (!(e instanceof vn || e instanceof di)) return e;
61
+ const s = t.get(e);
62
+ if (s) return s;
63
+ const r = new He({
64
+ name: e.name,
65
+ color: e.color.clone(),
66
+ emissive: e.emissive.clone(),
67
+ emissiveIntensity: e.emissiveIntensity,
68
+ map: e.map,
69
+ emissiveMap: e.emissiveMap,
70
+ normalMap: e.normalMap,
71
+ bumpMap: e.bumpMap,
72
+ bumpScale: e.bumpScale,
73
+ alphaMap: e.alphaMap,
74
+ aoMap: e.aoMap,
75
+ aoMapIntensity: e.aoMapIntensity,
76
+ lightMap: e.lightMap,
77
+ lightMapIntensity: e.lightMapIntensity,
78
+ opacity: e.opacity,
79
+ transparent: e.transparent,
80
+ alphaTest: e.alphaTest,
81
+ side: e.side,
82
+ depthWrite: e.depthWrite,
83
+ vertexColors: e.vertexColors,
84
+ flatShading: e.flatShading,
85
+ roughness: e instanceof di ? Math.sqrt(2 / (Math.max(0, e.shininess) + 2)) : 0.5,
86
+ metalness: 0
87
+ });
88
+ return r.normalScale.copy(e.normalScale), r.normalMapType = e.normalMapType, r.userData = { ...e.userData, colladaSourceMaterial: e.type }, t.set(e, r), r;
89
+ };
90
+ n.traverse((e) => {
91
+ e instanceof C && (e.material = Array.isArray(e.material) ? e.material.map(i) : i(e.material));
92
+ });
93
+ for (const e of t.keys()) e.dispose();
94
+ }
95
+ async function Nn(n, t) {
96
+ var p, c, u;
97
+ const i = await t.text(n), e = new DOMParser().parseFromString(i, "application/xml");
98
+ if (e.querySelector("parsererror") || e.documentElement.localName !== "COLLADA")
99
+ throw new Error(`Invalid URDF COLLADA document: ${n}`);
100
+ const s = ((c = (p = e.querySelector("asset > up_axis")) == null ? void 0 : p.textContent) == null ? void 0 : c.trim()) ?? "Y_UP";
101
+ if (!["X_UP", "Y_UP", "Z_UP"].includes(s)) throw new Error(`Unsupported COLLADA up-axis: ${s}`);
102
+ const r = /* @__PURE__ */ new Map();
103
+ for (const y of e.querySelectorAll("library_images image init_from")) {
104
+ const g = (u = y.textContent) == null ? void 0 : u.trim();
105
+ if (!g || g.startsWith("data:")) continue;
106
+ const x = t.resolve(g, n);
107
+ await t.ensure(x), r.set(g, t.objectUrl(x));
108
+ }
109
+ const o = new Vi();
110
+ o.setURLModifier((y) => {
111
+ if (y.startsWith("data:")) return y;
112
+ const g = r.get(y);
113
+ if (!g) throw new Error(`Unresolved COLLADA image: ${y}`);
114
+ return g;
115
+ });
116
+ let l;
117
+ const a = new Promise((y) => {
118
+ l = y;
119
+ });
120
+ let d;
121
+ o.onLoad = l, o.onError = (y) => {
122
+ d = y;
123
+ }, o.itemStart("urdf-collada-parse");
124
+ const f = new lt();
125
+ try {
126
+ const y = new Ln(o).parse(i, "");
127
+ if (!(y != null && y.scene)) throw new Error(`COLLADA has no scene: ${n}`);
128
+ if (f.add(y.scene), s === "X_UP" ? y.scene.rotateY(-Math.PI / 2) : y.scene.rotateX(Math.PI / 2), o.itemEnd("urdf-collada-parse"), await a, d) throw new Error(`COLLADA texture failed to load: ${d}`);
129
+ let g = 0;
130
+ if (f.traverse((x) => {
131
+ x instanceof C && g++;
132
+ }), !g) throw new Error(`COLLADA has no visual meshes: ${n}`);
133
+ return Cn(f), f.updateMatrixWorld(!0), f;
134
+ } catch (y) {
135
+ throw ut(f), y;
136
+ }
137
+ }
138
+ function Lt(n, t) {
139
+ if (!n) return [...t];
140
+ const i = n.trim().split(/\s+/).map(Number);
141
+ if (i.some((e) => !Number.isFinite(e))) throw O(`Invalid numeric value: ${n}`, "E_URDF_PARSE");
142
+ return i;
143
+ }
144
+ function ye(n) {
145
+ const t = (n == null ? void 0 : n.querySelector("origin")) ?? null, i = Lt((t == null ? void 0 : t.getAttribute("quat_xyzw")) ?? null, []);
146
+ if (i.length !== 0 && i.length !== 4) throw O("URDF origin quat_xyzw requires four values.", "E_URDF_PARSE");
147
+ if (i.length && (t != null && t.hasAttribute("rpy"))) throw O("URDF origin cannot declare both rpy and quat_xyzw.", "E_URDF_PARSE");
148
+ return {
149
+ position: Lt((t == null ? void 0 : t.getAttribute("xyz")) ?? null, [0, 0, 0]),
150
+ rotationRpy: Lt((t == null ? void 0 : t.getAttribute("rpy")) ?? null, [0, 0, 0]),
151
+ ...i.length ? { rotationQuaternion: i } : {}
152
+ };
153
+ }
154
+ function wi(n, t, i) {
155
+ const e = n.querySelector("geometry"), s = e == null ? void 0 : e.querySelector("box");
156
+ if (s) return { type: "box", size: Zn(s.getAttribute("size"), 3, "box size") };
157
+ const r = e == null ? void 0 : e.querySelector("sphere");
158
+ if (r) return { type: "sphere", radius: jt(r.getAttribute("radius"), "sphere radius") };
159
+ const o = e == null ? void 0 : e.querySelector("cylinder");
160
+ if (o) return { type: "cylinder", radius: jt(o.getAttribute("radius"), "cylinder radius"), length: jt(o.getAttribute("length"), "cylinder length") };
161
+ const l = e == null ? void 0 : e.querySelector("capsule");
162
+ if (l) return { type: "capsule", radius: jt(l.getAttribute("radius"), "capsule radius"), length: jt(l.getAttribute("length"), "capsule length") };
163
+ const a = e == null ? void 0 : e.querySelector("mesh"), d = a == null ? void 0 : a.getAttribute("filename");
164
+ return d ? { type: "mesh", resourcePath: i.resolve(d, t), scale: Lt(a.getAttribute("scale"), [1, 1, 1]) } : null;
165
+ }
166
+ function qn(n, t, i) {
167
+ const s = Hn(n, "URDF").querySelector("robot");
168
+ if (!s) throw O("URDF requires a robot root element.", "E_URDF_PARSE");
169
+ const r = hn(), o = /* @__PURE__ */ new Map();
170
+ for (const d of s.children) if (d.tagName === "material" && d.getAttribute("name")) {
171
+ const f = d.getAttribute("name");
172
+ if (o.has(f)) throw O(`Duplicate URDF material: ${f}`, "E_URDF_MATERIAL");
173
+ o.set(f, d);
174
+ }
175
+ const l = [...s.querySelectorAll("link")].map((d) => ({
176
+ id: rt(d, "name"),
177
+ name: rt(d, "name"),
178
+ inertial: (() => {
179
+ const f = Qn(d);
180
+ return f && (!(f.mass > 0) || !Number.isFinite(f.mass) || !Oi(f.tensor)) && r.errors.push({ code: "E_URDF_INERTIA", message: `连杆 ${d.getAttribute("name")} 的质量或惯性张量无效。`, source: d.getAttribute("name") ?? void 0 }), f;
181
+ })(),
182
+ visuals: [...d.querySelectorAll("visual")].map((f) => {
183
+ const p = wi(f, t, i), c = f.querySelector("material"), u = c == null ? void 0 : c.getAttribute("name"), y = u ? o.get(u) : void 0, g = (c == null ? void 0 : c.querySelector("color")) ?? (y == null ? void 0 : y.querySelector("color")), x = (c == null ? void 0 : c.querySelector("texture")) ?? (y == null ? void 0 : y.querySelector("texture"));
184
+ u && !y && !g && !x && r.warnings.push({ code: "URDF_MATERIAL_UNRESOLVED", message: `Undefined material: ${u}`, source: d.getAttribute("name") ?? void 0 });
185
+ const b = g ? (g.getAttribute("rgba") ?? "").trim().split(/\s+/).map(Number) : x ? [1, 1, 1, 1] : void 0;
186
+ if (b && (b.length !== 4 || b.some((w) => !Number.isFinite(w) || w < 0 || w > 1))) throw O(`Invalid URDF material RGBA: ${u ?? ""}`, "E_URDF_MATERIAL");
187
+ const m = x == null ? void 0 : x.getAttribute("filename");
188
+ if (x && !m) throw O("URDF texture requires a filename", "E_URDF_MATERIAL");
189
+ const h = m ? i.resolve(m, t) : void 0;
190
+ return p ? { origin: ye(f), geometry: p, color: b, texturePath: h } : null;
191
+ }).filter((f) => !!f),
192
+ collisions: [...d.querySelectorAll("collision")].map((f) => {
193
+ const p = wi(f, t, i);
194
+ return p ? { origin: ye(f), geometry: p } : null;
195
+ }).filter((f) => !!f)
196
+ })), a = [...s.querySelectorAll("joint")].map((d) => {
197
+ var b;
198
+ const f = d.querySelector("limit"), p = d.querySelector("mimic"), c = p ? { joint: rt(p, "joint"), multiplier: Kt(p.getAttribute("multiplier"), "mimic multiplier") ?? 1, offset: Kt(p.getAttribute("offset"), "mimic offset") ?? 0 } : void 0, u = d.querySelector("dynamics"), y = u ? Ai(u.getAttribute("damping"), 0) : 0, g = u ? Ai(u.getAttribute("friction"), 0) : 0, x = u && (y > 0 || g > 0) ? { damping: y, friction: g } : void 0;
199
+ return {
200
+ id: rt(d, "name"),
201
+ type: d.getAttribute("type") ?? "fixed",
202
+ parent: rt(d.querySelector("parent"), "link"),
203
+ child: rt(d.querySelector("child"), "link"),
204
+ origin: ye(d),
205
+ axis: Lt(((b = d.querySelector("axis")) == null ? void 0 : b.getAttribute("xyz")) ?? null, [1, 0, 0]),
206
+ ...f ? {
207
+ limits: { lower: ke(f.getAttribute("lower"), `Joint ${rt(d, "name")} limit lower`), upper: ke(f.getAttribute("upper"), `Joint ${rt(d, "name")} limit upper`) },
208
+ effort: Kt(f.getAttribute("effort"), `Joint ${rt(d, "name")} limit effort`),
209
+ velocity: Kt(f.getAttribute("velocity"), `Joint ${rt(d, "name")} limit velocity`)
210
+ } : {},
211
+ ...x ? { dynamics: x } : {},
212
+ ...c ? { mimic: c } : {}
213
+ };
214
+ });
215
+ return Ae(a), s.querySelector("transmission, gazebo") && r.droppedFeatures.push({ code: "UNSUPPORTED_URDF_EXTENSION", message: "URDF transmission/gazebo extensions are not compiled." }), mn({ id: s.getAttribute("name") || t, name: s.getAttribute("name") || t, source: { format: "urdf", uri: t }, links: l, joints: a, diagnostics: r, extension: { files: i } }, { allowInvalidGraph: !0 });
216
+ }
217
+ function bi(n) {
218
+ const t = Qt(n);
219
+ return `quat="${t.w} ${t.x} ${t.y} ${t.z}"`;
220
+ }
221
+ function De(n) {
222
+ const t = new Z(), i = Qt(n);
223
+ return t.compose(new U().fromArray(n.position), i, new U(1, 1, 1));
224
+ }
225
+ function On(n) {
226
+ if (n.type === "continuous" || !n.limits) return 0;
227
+ const { lower: t, upper: i } = n.limits;
228
+ return !Number.isFinite(t) || !Number.isFinite(i) ? 0 : Tn.clamp(0, t, i);
229
+ }
230
+ function Vn(n) {
231
+ let t;
232
+ if (n.type === "box")
233
+ t = [n.size[0] / 2, n.size[1] / 2, n.size[2] / 2];
234
+ else if (n.type === "sphere")
235
+ t = [n.radius, n.radius, n.radius];
236
+ else if (n.type === "cylinder")
237
+ t = [n.radius, n.radius, n.length / 2];
238
+ else
239
+ return null;
240
+ const i = [];
241
+ for (const e of [-t[0], t[0]])
242
+ for (const s of [-t[1], t[1]])
243
+ for (const r of [-t[2], t[2]])
244
+ i.push(new U(e, s, r));
245
+ return i;
246
+ }
247
+ function Ki(n, t, i) {
248
+ let e = 0;
249
+ const s = new Map(n.links.map((f) => [f.id, f])), r = ti(n.joints), o = (f) => {
250
+ let p = 1 / 0;
251
+ const c = (u, y) => {
252
+ const g = s.get(u);
253
+ if (g) {
254
+ for (const x of g.collisions) {
255
+ const b = Vn(x.geometry);
256
+ if (!b) {
257
+ f && (e += 1);
258
+ continue;
259
+ }
260
+ const m = y.clone().multiply(De(x.origin));
261
+ for (const h of b)
262
+ p = Math.min(p, h.applyMatrix4(m).z);
263
+ }
264
+ for (const x of i.get(u) ?? []) {
265
+ const b = y.clone().multiply(De(x.origin)), m = f ? r[x.id] : 0;
266
+ m && x.type === "revolute" ? b.multiply(new Z().makeRotationAxis(new U().fromArray(x.axis).normalize(), m)) : m && x.type === "prismatic" && b.multiply(new Z().makeTranslation(x.axis[0] * m, x.axis[1] * m, x.axis[2] * m)), c(x.child, b);
267
+ }
268
+ }
269
+ };
270
+ return c(t, new Z()), p;
271
+ }, l = o(!0), a = o(!1), d = Math.min(l, a);
272
+ return e && n.diagnostics.warnings.push({
273
+ code: "GROUNDING_IGNORED_MESH_COLLIDERS",
274
+ message: `自动落地忽略了 ${e} 个网格碰撞体`
275
+ }), Number.isFinite(d) ? Math.max(0, 0.015 - d) : 0;
276
+ }
277
+ async function Wn(n) {
278
+ const t = n.extension.files, i = /* @__PURE__ */ new Map(), e = new Set(n.joints.map((b) => b.child));
279
+ for (const b of n.joints) i.set(b.parent, [...i.get(b.parent) ?? [], b]);
280
+ const s = n.links.filter((b) => !e.has(b.id));
281
+ if (s.length !== 1) throw O(`URDF requires exactly one root link; found ${s.length}.`, "E_URDF_COMPILE");
282
+ const r = Ki(n, s[0].id, i);
283
+ r > 0 && n.diagnostics.approximations.push({
284
+ code: "AUTO_GROUNDED_FREE_ROOT",
285
+ message: `自由根初始高度自动抬升 ${r.toFixed(4)} m`
286
+ });
287
+ const o = n.joints.filter((b) => On(b) !== 0);
288
+ o.length && n.diagnostics.approximations.push({
289
+ code: "JOINT_REFERENCE_CLAMPED",
290
+ message: `${o.length} 个关节的默认参考值已夹到合法限位`
291
+ });
292
+ const l = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), d = [], f = ti(n.joints), p = async (b) => {
293
+ var A;
294
+ if (b.type === "box") return `type="box" size="${b.size.map((P) => P / 2).join(" ")}"`;
295
+ if (b.type === "sphere") return `type="sphere" size="${b.radius}"`;
296
+ if (b.type === "cylinder") return `type="cylinder" size="${b.radius} ${b.length / 2}"`;
297
+ if (b.type === "capsule") return `type="capsule" size="${b.radius} ${b.length / 2}"`;
298
+ const m = (A = b.resourcePath.split(".").pop()) == null ? void 0 : A.toLowerCase();
299
+ if (m !== "stl" && m !== "obj") return null;
300
+ const h = `${b.resourcePath}|${b.scale.join(" ")}`;
301
+ let w = a.get(h);
302
+ if (!w) {
303
+ const P = { name: `mesh_${a.size}`, path: b.resourcePath, scale: b.scale };
304
+ a.set(h, P);
305
+ const v = await t.bytes(b.resourcePath);
306
+ l.set(`${P.name}.${m}`, v), w = P;
307
+ }
308
+ return `type="mesh" mesh="${w.name}"`;
309
+ }, c = async (b, m) => {
310
+ var v, T;
311
+ const h = n.links.find((R) => R.id === b), w = [...(m == null ? void 0 : m.origin.position) ?? [0, 0, 0]];
312
+ m || (w[2] += r);
313
+ const A = (m == null ? void 0 : m.origin) ?? { rotationRpy: [0, 0, 0] }, P = [`<body name="${St(b)}" pos="${w.join(" ")}" ${bi(A)}>`];
314
+ if (h.inertial) {
315
+ const { origin: R, mass: M, tensor: B } = h.inertial, S = new pi().setFromMatrix4(new Z().makeRotationFromQuaternion(Qt(R))), _ = new pi().set(B[0], B[3], B[4], B[3], B[1], B[5], B[4], B[5], B[2]);
316
+ _.premultiply(S).multiply(S.clone().transpose());
317
+ const E = _.elements;
318
+ P.push(`<inertial pos="${R.position.join(" ")}" mass="${M}" fullinertia="${[E[0], E[4], E[8], E[3], E[6], E[7]].join(" ")}"/>`);
319
+ }
320
+ if (!m) P.push("<freejoint/>");
321
+ else if (["fixed", "planar", "floating"].includes(m.type))
322
+ (m == null ? void 0 : m.type) === "floating" && (P.push("<freejoint/>"), d.push(0, 0, 0, 1, 0, 0, 0));
323
+ else {
324
+ const R = m.type === "prismatic" ? "slide" : "hinge", M = m.type !== "continuous" && !!m.limits && Number.isFinite(m.limits.lower) && Number.isFinite(m.limits.upper), B = f[m.id];
325
+ d.push(B);
326
+ const S = ((v = m.dynamics) == null ? void 0 : v.damping) ?? 0, _ = ((T = m.dynamics) == null ? void 0 : T.friction) ?? 0;
327
+ P.push(`<joint name="${St(m.id)}" type="${R}" axis="${m.axis.join(" ")}"${M ? ` limited="true" range="${m.limits.lower} ${m.limits.upper}" ref="0"` : ""} damping="${S}" frictionloss="${_}"/>`);
328
+ }
329
+ for (const R of h.collisions) {
330
+ const M = await p(R.geometry);
331
+ if (M) {
332
+ const B = ` ${bi(R.origin)}`;
333
+ P.push(`<geom ${M} pos="${R.origin.position.join(" ")}"${B} rgba="0.55 0.62 0.59 1"/>`);
334
+ }
335
+ }
336
+ for (const R of i.get(b) ?? []) P.push(await c(R.child, R));
337
+ return P.push("</body>"), P.join("");
338
+ }, u = await c(s[0].id), y = [...a.values()].map((b) => {
339
+ var m;
340
+ return `<mesh name="${b.name}" file="${b.name}.${(m = b.path.split(".").pop()) == null ? void 0 : m.toLowerCase()}" scale="${b.scale.join(" ")}"/>`;
341
+ }).join(""), g = `<keyframe><key name="home" qpos="0 0 ${r} 1 0 0 0 ${d.join(" ")}"/></keyframe>`, x = n.joints.filter((b) => b.mimic).map((b) => {
342
+ const m = b.mimic;
343
+ return `<joint name="mimic_${St(b.id)}" joint1="${St(b.id)}" joint2="${St(m.joint)}" polycoef="${m.offset} ${m.multiplier} 0 0 0"/>`;
344
+ }).join("");
345
+ return {
346
+ format: "mjcf",
347
+ files: l,
348
+ xml: `<mujoco model="${St(n.name)}"><compiler angle="radian" autolimits="true"/><option gravity="0 0 -9.81"/><asset>${y}</asset><worldbody><geom name="__viewer_default_ground__" type="plane" size="5 5 0.1" contype="1" conaffinity="1" friction="0.8 0.01 0.0002"/>${u}</worldbody>${x ? `<equality>${x}</equality>` : ""}${g}</mujoco>`
349
+ };
350
+ }
351
+ async function tn(n) {
352
+ const t = n.extension.files, i = new lt();
353
+ i.name = "URDF authored collisions";
354
+ const e = /* @__PURE__ */ new Map(), s = wn(), r = bn();
355
+ let o = 0;
356
+ for (const l of n.links) {
357
+ const a = new lt();
358
+ a.name = l.id, a.userData.urdfEntityId = `link:${l.id}`, e.set(l.id, a), i.add(a);
359
+ for (const d of l.collisions) {
360
+ const f = new lt();
361
+ if (f.matrixAutoUpdate = !1, f.matrix.copy(De(d.origin)), a.add(f), d.geometry.type === "mesh") {
362
+ const p = await Le(d.geometry, t, new He());
363
+ p.updateMatrixWorld(!0), p.traverse((c) => {
364
+ if (!(c instanceof C)) return;
365
+ const u = li(c.geometry, s, "mesh", r);
366
+ u.matrixAutoUpdate = !1, u.matrix.copy(c.matrixWorld), u.name = `Collision:${l.id}`, u.userData.urdfLink = l.id, f.add(u), o += 1;
367
+ }), ut(p);
368
+ } else {
369
+ const p = Xn(d.geometry);
370
+ if (!p) continue;
371
+ const c = li(p, s, "feature", r);
372
+ p.dispose(), c.name = `Collision:${l.id}`, c.userData.urdfLink = l.id, f.add(c), o += 1;
373
+ }
374
+ }
375
+ }
376
+ if (o === 0) {
377
+ s.dispose(), r.dispose(), ut(i);
378
+ return;
379
+ }
380
+ return { root: i, bindings: e, expectedLinkCount: e.size };
381
+ }
382
+ async function Gn(n, t) {
383
+ const i = await tn(n);
384
+ if (!i) return;
385
+ const e = () => {
386
+ t.root.updateMatrixWorld(!0);
387
+ for (const [s, r] of i.bindings) {
388
+ const o = t.bindings.get(s);
389
+ o && (r.matrixAutoUpdate = !1, r.matrix.copy(o.matrixWorld));
390
+ }
391
+ i.root.updateMatrixWorld(!0);
392
+ };
393
+ return e(), i.root.visible = !1, { root: i.root, sync: e, dispose() {
394
+ ut(i.root);
395
+ } };
396
+ }
397
+ function Xn(n) {
398
+ if (n.type === "box") return new Ze(...n.size);
399
+ if (n.type === "sphere") return new Qe(n.radius, 24, 16);
400
+ if (n.type === "cylinder") {
401
+ const t = new Wi(n.radius, n.radius, n.length, 24);
402
+ return t.rotateX(Math.PI / 2), t;
403
+ }
404
+ if (n.type === "capsule") {
405
+ const t = new Gi(n.radius, n.length, 8, 24);
406
+ return t.rotateX(Math.PI / 2), t;
407
+ }
408
+ return null;
409
+ }
410
+ async function xi(n) {
411
+ const t = n.extension.files, i = new lt();
412
+ i.name = n.name;
413
+ const e = /* @__PURE__ */ new Map();
414
+ try {
415
+ for (const s of n.links) {
416
+ const r = new lt();
417
+ r.name = s.id, r.userData.urdfEntityId = `link:${s.id}`, e.set(s.id, r), i.add(r);
418
+ for (const o of s.visuals) {
419
+ const l = await Jn(o, t, n.diagnostics), a = new lt();
420
+ a.position.fromArray(o.origin.position), a.quaternion.copy(Qt(o.origin)), a.add(l), r.add(a);
421
+ }
422
+ }
423
+ return { root: i, bindings: e, expectedLinkCount: n.links.length };
424
+ } catch (s) {
425
+ throw ut(i), s;
426
+ }
427
+ }
428
+ async function Jn(n, t, i) {
429
+ var r;
430
+ if (n.geometry.type === "mesh" && /\.gl(?:tf|b)$/i.test(n.geometry.resourcePath)) {
431
+ (n.color || n.texturePath) && i.warnings.push({ code: "URDF_EMBEDDED_MATERIAL_PRESERVED", message: "Embedded glTF materials take precedence over the URDF visual material.", source: n.geometry.resourcePath });
432
+ const o = ci();
433
+ try {
434
+ return await Le(n.geometry, t, o);
435
+ } finally {
436
+ o.dispose();
437
+ }
438
+ }
439
+ const e = ci({ color: n.color });
440
+ let s;
441
+ try {
442
+ if (n.texturePath && (await t.ensure(n.texturePath), e.map = await new Mn().loadAsync(t.objectUrl(n.texturePath)), e.transparent = !0, e.map.colorSpace = Pn, e.map.wrapS = e.map.wrapT = Sn), s = await Le(n.geometry, t, e), n.geometry.type === "mesh" && /\.dae$/i.test(n.geometry.resourcePath))
443
+ if (n.color || n.texturePath) {
444
+ const o = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
445
+ s.traverse((a) => {
446
+ if (a instanceof C) {
447
+ for (const d of Array.isArray(a.material) ? a.material : [a.material]) o.add(d);
448
+ a.material = e;
449
+ }
450
+ });
451
+ for (const a of o) {
452
+ for (const d of Object.values(a)) d != null && d.isTexture && l.add(d);
453
+ a.dispose();
454
+ }
455
+ for (const a of l) a.dispose();
456
+ } else e.dispose();
457
+ return e.map && s.traverse((o) => {
458
+ if (o instanceof C && !o.geometry.getAttribute("uv")) throw O(`URDF texture requires authored UVs: ${n.texturePath}`, "E_URDF_TEXTURE_UV");
459
+ }), s;
460
+ } catch (o) {
461
+ throw s ? ut(s) : ((r = e.map) == null || r.dispose(), e.dispose()), o;
462
+ }
463
+ }
464
+ async function Le(n, t, i) {
465
+ var r;
466
+ if (n.type === "box") return new C(new Ze(...n.size), i);
467
+ if (n.type === "sphere") return new C(new Qe(n.radius, 24, 16), i);
468
+ if (n.type === "cylinder") {
469
+ const o = new C(new Wi(n.radius, n.radius, n.length, 24), i);
470
+ return o.quaternion.copy(new tt().setFromEuler(new Zt(Math.PI / 2, 0, 0))), o;
471
+ }
472
+ if (n.type === "capsule") {
473
+ const o = new C(new Gi(n.radius, n.length, 8, 24), i);
474
+ return o.quaternion.copy(new tt().setFromEuler(new Zt(Math.PI / 2, 0, 0))), o;
475
+ }
476
+ const e = (r = n.resourcePath.split(".").pop()) == null ? void 0 : r.toLowerCase();
477
+ await t.ensure(n.resourcePath);
478
+ let s;
479
+ if (e === "stl") s = new C(new jn().parse(await t.getBlob(n.resourcePath).arrayBuffer()), i);
480
+ else if (e === "obj")
481
+ s = new kn().parse(await t.getBlob(n.resourcePath).text()), s.traverse((o) => {
482
+ if (o instanceof C) {
483
+ for (const l of Array.isArray(o.material) ? o.material : [o.material]) l.dispose();
484
+ o.material = i;
485
+ }
486
+ });
487
+ else if (e === "gltf" || e === "glb") {
488
+ const o = new Vi();
489
+ o.setURLModifier((l) => {
490
+ try {
491
+ return t.objectUrl(t.resolve(l, n.resourcePath));
492
+ } catch {
493
+ return l;
494
+ }
495
+ }), s = (await new Dn(o).parseAsync(await t.getBlob(n.resourcePath).arrayBuffer(), "")).scene;
496
+ } else if (e === "dae") s = await Nn(n.resourcePath, t);
497
+ else throw O(`Unsupported URDF visual mesh: .${e ?? ""}`, "E_URDF_VISUAL");
498
+ return s.scale.fromArray(n.scale), s;
499
+ }
500
+ function Hn(n, t) {
501
+ const i = new DOMParser().parseFromString(n, "application/xml"), e = i.querySelector("parsererror");
502
+ if (e) throw O(`${t} XML parse failed: ${e.textContent ?? ""}`, `E_${t}_PARSE`);
503
+ return i;
504
+ }
505
+ function rt(n, t) {
506
+ const i = n == null ? void 0 : n.getAttribute(t);
507
+ if (!i) throw O(`Missing ${t}.`, "E_URDF_PARSE");
508
+ return i;
509
+ }
510
+ function Ai(n, t) {
511
+ const i = Number(n);
512
+ return Number.isFinite(i) ? i : t;
513
+ }
514
+ function ke(n, t) {
515
+ if (n === null || n.trim() === "") throw O(`${t} is required.`, "E_URDF_PARSE");
516
+ const i = Number(n);
517
+ if (!Number.isFinite(i)) throw O(`${t} must be finite.`, "E_URDF_PARSE");
518
+ return i;
519
+ }
520
+ function jt(n, t) {
521
+ const i = ke(n, t);
522
+ if (!(i > 0)) throw O(`${t} must be greater than zero.`, "E_URDF_PARSE");
523
+ return i;
524
+ }
525
+ function Zn(n, t, i) {
526
+ if (n === null || n.trim() === "") throw O(`${i} is required.`, "E_URDF_PARSE");
527
+ const e = Lt(n, []);
528
+ if (e.length !== t || e.some((s) => !(s > 0))) throw O(`${i} requires ${t} values greater than zero.`, "E_URDF_PARSE");
529
+ return e;
530
+ }
531
+ function Kt(n, t) {
532
+ if (n === null || n.trim() === "") return;
533
+ const i = Number(n);
534
+ if (!Number.isFinite(i)) throw O(`${t} must be finite.`, "E_URDF_PARSE");
535
+ return i;
536
+ }
537
+ function St(n) {
538
+ return n.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
539
+ }
540
+ function O(n, t) {
541
+ return Object.assign(new Error(n), { code: t });
542
+ }
543
+ function Qn(n) {
544
+ var o;
545
+ const t = n.querySelector("inertial");
546
+ if (!t) return;
547
+ const i = t.querySelector("inertia"), e = (o = t.querySelector("mass")) == null ? void 0 : o.getAttribute("value"), s = e == null || e.trim() === "" ? Number.NaN : Number(e), r = ["ixx", "iyy", "izz", "ixy", "ixz", "iyz"].map((l) => {
548
+ const a = i == null ? void 0 : i.getAttribute(l);
549
+ return a == null || a.trim() === "" ? Number.NaN : Number(a);
550
+ });
551
+ return { origin: ye(t), mass: s, tensor: r };
552
+ }
553
+ const en = 0, Yn = 1, Kn = 2, vi = 2, Se = 1.25, Mi = 1, X = 6 * 4 + 4 + 4, N = X / 4, nn = 65535, ge = Math.pow(2, -24), ei = Symbol("SKIP_GENERATION"), sn = {
554
+ strategy: en,
555
+ maxDepth: 40,
556
+ maxLeafSize: 10,
557
+ useSharedArrayBuffer: !1,
558
+ setBoundingBox: !0,
559
+ onProgress: null,
560
+ indirect: !1,
561
+ verbose: !0,
562
+ range: null,
563
+ [ei]: !1
564
+ };
565
+ function k(n, t, i) {
566
+ return i.min.x = t[n], i.min.y = t[n + 1], i.min.z = t[n + 2], i.max.x = t[n + 3], i.max.y = t[n + 4], i.max.z = t[n + 5], i;
567
+ }
568
+ function Pi(n) {
569
+ let t = -1, i = -1 / 0;
570
+ for (let e = 0; e < 3; e++) {
571
+ const s = n[e + 3] - n[e];
572
+ s > i && (i = s, t = e);
573
+ }
574
+ return t;
575
+ }
576
+ function Si(n, t) {
577
+ t.set(n);
578
+ }
579
+ function Ti(n, t, i) {
580
+ let e, s;
581
+ for (let r = 0; r < 3; r++) {
582
+ const o = r + 3;
583
+ e = n[r], s = t[r], i[r] = e < s ? e : s, e = n[o], s = t[o], i[o] = e > s ? e : s;
584
+ }
585
+ }
586
+ function te(n, t, i) {
587
+ for (let e = 0; e < 3; e++) {
588
+ const s = t[n + 2 * e], r = t[n + 2 * e + 1], o = s - r, l = s + r;
589
+ o < i[e] && (i[e] = o), l > i[e + 3] && (i[e + 3] = l);
590
+ }
591
+ }
592
+ function Ct(n) {
593
+ const t = n[3] - n[0], i = n[4] - n[1], e = n[5] - n[2];
594
+ return 2 * (t * i + i * e + e * t);
595
+ }
596
+ function q(n, t) {
597
+ return t[n + 15] === nn;
598
+ }
599
+ function J(n, t) {
600
+ return t[n + 6];
601
+ }
602
+ function H(n, t) {
603
+ return t[n + 14];
604
+ }
605
+ function V(n) {
606
+ return n + N;
607
+ }
608
+ function W(n, t) {
609
+ const i = t[n + 6];
610
+ return n + i * N;
611
+ }
612
+ function ii(n, t) {
613
+ return t[n + 7];
614
+ }
615
+ function Te(n, t, i, e, s) {
616
+ let r = 1 / 0, o = 1 / 0, l = 1 / 0, a = -1 / 0, d = -1 / 0, f = -1 / 0, p = 1 / 0, c = 1 / 0, u = 1 / 0, y = -1 / 0, g = -1 / 0, x = -1 / 0;
617
+ const b = n.offset || 0;
618
+ for (let m = (t - b) * 6, h = (t + i - b) * 6; m < h; m += 6) {
619
+ const w = n[m + 0], A = n[m + 1], P = w - A, v = w + A;
620
+ P < r && (r = P), v > a && (a = v), w < p && (p = w), w > y && (y = w);
621
+ const T = n[m + 2], R = n[m + 3], M = T - R, B = T + R;
622
+ M < o && (o = M), B > d && (d = B), T < c && (c = T), T > g && (g = T);
623
+ const S = n[m + 4], _ = n[m + 5], E = S - _, $ = S + _;
624
+ E < l && (l = E), $ > f && (f = $), S < u && (u = S), S > x && (x = S);
625
+ }
626
+ e[0] = r, e[1] = o, e[2] = l, e[3] = a, e[4] = d, e[5] = f, s[0] = p, s[1] = c, s[2] = u, s[3] = y, s[4] = g, s[5] = x;
627
+ }
628
+ const at = 32, ts = (n, t) => n.candidate - t.candidate, pt = /* @__PURE__ */ new Array(at).fill().map(() => ({
629
+ count: 0,
630
+ bounds: new Float32Array(6),
631
+ rightCacheBounds: new Float32Array(6),
632
+ leftCacheBounds: new Float32Array(6),
633
+ candidate: 0
634
+ })), ee = /* @__PURE__ */ new Float32Array(6);
635
+ function es(n, t, i, e, s, r) {
636
+ let o = -1, l = 0;
637
+ if (r === en)
638
+ o = Pi(t), o !== -1 && (l = (t[o] + t[o + 3]) / 2);
639
+ else if (r === Yn)
640
+ o = Pi(n), o !== -1 && (l = is(i, e, s, o));
641
+ else if (r === Kn) {
642
+ const a = Ct(n);
643
+ let d = Se * s;
644
+ const f = i.offset || 0, p = (e - f) * 6, c = (e + s - f) * 6;
645
+ for (let u = 0; u < 3; u++) {
646
+ const y = t[u], b = (t[u + 3] - y) / at;
647
+ if (s < at / 4) {
648
+ const m = [...pt];
649
+ m.length = s;
650
+ let h = 0;
651
+ for (let A = p; A < c; A += 6, h++) {
652
+ const P = m[h];
653
+ P.candidate = i[A + 2 * u], P.count = 0;
654
+ const {
655
+ bounds: v,
656
+ leftCacheBounds: T,
657
+ rightCacheBounds: R
658
+ } = P;
659
+ for (let M = 0; M < 3; M++)
660
+ R[M] = 1 / 0, R[M + 3] = -1 / 0, T[M] = 1 / 0, T[M + 3] = -1 / 0, v[M] = 1 / 0, v[M + 3] = -1 / 0;
661
+ te(A, i, v);
662
+ }
663
+ m.sort(ts);
664
+ let w = s;
665
+ for (let A = 0; A < w; A++) {
666
+ const P = m[A];
667
+ for (; A + 1 < w && m[A + 1].candidate === P.candidate; )
668
+ m.splice(A + 1, 1), w--;
669
+ }
670
+ for (let A = p; A < c; A += 6) {
671
+ const P = i[A + 2 * u];
672
+ for (let v = 0; v < w; v++) {
673
+ const T = m[v];
674
+ P >= T.candidate ? te(A, i, T.rightCacheBounds) : (te(A, i, T.leftCacheBounds), T.count++);
675
+ }
676
+ }
677
+ for (let A = 0; A < w; A++) {
678
+ const P = m[A], v = P.count, T = s - P.count, R = P.leftCacheBounds, M = P.rightCacheBounds;
679
+ let B = 0;
680
+ v !== 0 && (B = Ct(R) / a);
681
+ let S = 0;
682
+ T !== 0 && (S = Ct(M) / a);
683
+ const _ = Mi + Se * (B * v + S * T);
684
+ _ < d && (o = u, d = _, l = P.candidate);
685
+ }
686
+ } else {
687
+ for (let w = 0; w < at; w++) {
688
+ const A = pt[w];
689
+ A.count = 0, A.candidate = y + b + w * b;
690
+ const P = A.bounds;
691
+ for (let v = 0; v < 3; v++)
692
+ P[v] = 1 / 0, P[v + 3] = -1 / 0;
693
+ }
694
+ for (let w = p; w < c; w += 6) {
695
+ let v = ~~((i[w + 2 * u] - y) / b);
696
+ v >= at && (v = at - 1);
697
+ const T = pt[v];
698
+ T.count++, te(w, i, T.bounds);
699
+ }
700
+ const m = pt[at - 1];
701
+ Si(m.bounds, m.rightCacheBounds);
702
+ for (let w = at - 2; w >= 0; w--) {
703
+ const A = pt[w], P = pt[w + 1];
704
+ Ti(A.bounds, P.rightCacheBounds, A.rightCacheBounds);
705
+ }
706
+ let h = 0;
707
+ for (let w = 0; w < at - 1; w++) {
708
+ const A = pt[w], P = A.count, v = A.bounds, R = pt[w + 1].rightCacheBounds;
709
+ P !== 0 && (h === 0 ? Si(v, ee) : Ti(v, ee, ee)), h += P;
710
+ let M = 0, B = 0;
711
+ h !== 0 && (M = Ct(ee) / a);
712
+ const S = s - h;
713
+ S !== 0 && (B = Ct(R) / a);
714
+ const _ = Mi + Se * (M * h + B * S);
715
+ _ < d && (o = u, d = _, l = A.candidate);
716
+ }
717
+ }
718
+ }
719
+ } else
720
+ console.warn(`BVH: Invalid build strategy value ${r} used.`);
721
+ return { axis: o, pos: l };
722
+ }
723
+ function is(n, t, i, e) {
724
+ let s = 0;
725
+ const r = n.offset;
726
+ for (let o = t, l = t + i; o < l; o++)
727
+ s += n[(o - r) * 6 + e * 2];
728
+ return s / i;
729
+ }
730
+ class Re {
731
+ constructor() {
732
+ this.boundingData = new Float32Array(6);
733
+ }
734
+ }
735
+ function ns(n, t, i, e, s, r) {
736
+ let o = e, l = e + s - 1;
737
+ const a = r.pos, d = r.axis * 2, f = i.offset || 0;
738
+ for (; ; ) {
739
+ for (; o <= l && i[(o - f) * 6 + d] < a; )
740
+ o++;
741
+ for (; o <= l && i[(l - f) * 6 + d] >= a; )
742
+ l--;
743
+ if (o < l) {
744
+ for (let p = 0; p < t; p++) {
745
+ let c = n[o * t + p];
746
+ n[o * t + p] = n[l * t + p], n[l * t + p] = c;
747
+ }
748
+ for (let p = 0; p < 6; p++) {
749
+ const c = o - f, u = l - f, y = i[c * 6 + p];
750
+ i[c * 6 + p] = i[u * 6 + p], i[u * 6 + p] = y;
751
+ }
752
+ o++, l--;
753
+ } else
754
+ return o;
755
+ }
756
+ }
757
+ let on, we, je, rn;
758
+ const ss = Math.pow(2, 32);
759
+ function Ce(n) {
760
+ return "count" in n ? 1 : 1 + Ce(n.left) + Ce(n.right);
761
+ }
762
+ function os(n, t, i) {
763
+ return on = new Float32Array(i), we = new Uint32Array(i), je = new Uint16Array(i), rn = new Uint8Array(i), Ne(n, t);
764
+ }
765
+ function Ne(n, t) {
766
+ const i = n / 4, e = n / 2, s = "count" in t, r = t.boundingData;
767
+ for (let o = 0; o < 6; o++)
768
+ on[i + o] = r[o];
769
+ if (s)
770
+ return t.buffer ? (rn.set(new Uint8Array(t.buffer), n), n + t.buffer.byteLength) : (we[i + 6] = t.offset, je[e + 14] = t.count, je[e + 15] = nn, n + X);
771
+ {
772
+ const { left: o, right: l, splitAxis: a } = t, d = n + X;
773
+ let f = Ne(d, o);
774
+ const p = n / X, u = f / X - p;
775
+ if (u > ss)
776
+ throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");
777
+ return we[i + 6] = u, we[i + 7] = a, Ne(f, l);
778
+ }
779
+ }
780
+ function rs(n, t, i, e, s, r) {
781
+ const {
782
+ maxDepth: o,
783
+ verbose: l,
784
+ maxLeafSize: a,
785
+ strategy: d,
786
+ onProgress: f
787
+ } = s, p = n.primitiveBuffer, c = n.primitiveBufferStride, u = new Float32Array(6);
788
+ let y = !1;
789
+ const g = new Re();
790
+ return Te(t, i, e, g.boundingData, u), b(g, i, e, u), g;
791
+ function x(m) {
792
+ f && f((m - r.offset) / r.count);
793
+ }
794
+ function b(m, h, w, A = null, P = 0) {
795
+ if (!y && P >= o && (y = !0, l && console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`)), w <= a || P >= o)
796
+ return x(h + w), m.offset = h, m.count = w, m;
797
+ const v = es(m.boundingData, A, t, h, w, d);
798
+ if (v.axis === -1)
799
+ return x(h + w), m.offset = h, m.count = w, m;
800
+ const T = ns(p, c, t, h, w, v);
801
+ if (T === h || T === h + w)
802
+ x(h + w), m.offset = h, m.count = w;
803
+ else {
804
+ m.splitAxis = v.axis;
805
+ const R = new Re(), M = h, B = T - h;
806
+ m.left = R, Te(t, M, B, R.boundingData, u), b(R, M, B, u, P + 1);
807
+ const S = new Re(), _ = T, E = w - B;
808
+ m.right = S, Te(t, _, E, S.boundingData, u), b(S, _, E, u, P + 1);
809
+ }
810
+ return m;
811
+ }
812
+ }
813
+ function as(n, t) {
814
+ const i = t.useSharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer, e = n.getRootRanges(t.range), s = e[0], r = e[e.length - 1], o = {
815
+ offset: s.offset,
816
+ count: r.offset + r.count - s.offset
817
+ }, l = new Float32Array(6 * o.count);
818
+ l.offset = o.offset, n.computePrimitiveBounds(o.offset, o.count, l), n._roots = e.map((a) => {
819
+ const d = rs(n, l, a.offset, a.count, t, o), f = Ce(d), p = new i(X * f);
820
+ return os(0, d, p), p;
821
+ });
822
+ }
823
+ class ni {
824
+ constructor(t) {
825
+ this._getNewPrimitive = t, this._primitives = [];
826
+ }
827
+ getPrimitive() {
828
+ const t = this._primitives;
829
+ return t.length === 0 ? this._getNewPrimitive() : t.pop();
830
+ }
831
+ releasePrimitive(t) {
832
+ this._primitives.push(t);
833
+ }
834
+ }
835
+ class cs {
836
+ constructor() {
837
+ this.float32Array = null, this.uint16Array = null, this.uint32Array = null;
838
+ const t = [];
839
+ let i = null;
840
+ this.setBuffer = (e) => {
841
+ i && t.push(i), i = e, this.float32Array = new Float32Array(e), this.uint16Array = new Uint16Array(e), this.uint32Array = new Uint32Array(e);
842
+ }, this.clearBuffer = () => {
843
+ i = null, this.float32Array = null, this.uint16Array = null, this.uint32Array = null, t.length !== 0 && this.setBuffer(t.pop());
844
+ };
845
+ }
846
+ }
847
+ const I = /* @__PURE__ */ new cs();
848
+ let ht, Dt;
849
+ const Tt = [], ie = /* @__PURE__ */ new ni(() => new it());
850
+ function ls(n, t, i, e, s, r) {
851
+ ht = ie.getPrimitive(), Dt = ie.getPrimitive(), Tt.push(ht, Dt), I.setBuffer(n._roots[t]);
852
+ const o = qe(0, n.geometry, i, e, s, r);
853
+ I.clearBuffer(), ie.releasePrimitive(ht), ie.releasePrimitive(Dt), Tt.pop(), Tt.pop();
854
+ const l = Tt.length;
855
+ return l > 0 && (Dt = Tt[l - 1], ht = Tt[l - 2]), o;
856
+ }
857
+ function qe(n, t, i, e, s = null, r = 0, o = 0) {
858
+ const { float32Array: l, uint16Array: a, uint32Array: d } = I;
859
+ let f = n * 2;
860
+ if (q(f, a)) {
861
+ const c = J(n, d), u = H(f, a);
862
+ return k(n, l, ht), e(c, u, !1, o, r + n / N, ht);
863
+ } else {
864
+ let M = function(S) {
865
+ const { uint16Array: _, uint32Array: E } = I;
866
+ let $ = S * 2;
867
+ for (; !q($, _); )
868
+ S = V(S), $ = S * 2;
869
+ return J(S, E);
870
+ }, B = function(S) {
871
+ const { uint16Array: _, uint32Array: E } = I;
872
+ let $ = S * 2;
873
+ for (; !q($, _); )
874
+ S = W(S, E), $ = S * 2;
875
+ return J(S, E) + H($, _);
876
+ };
877
+ const c = V(n), u = W(n, d);
878
+ let y = c, g = u, x, b, m, h;
879
+ if (s && (m = ht, h = Dt, k(y, l, m), k(g, l, h), x = s(m), b = s(h), b < x)) {
880
+ y = u, g = c;
881
+ const S = x;
882
+ x = b, b = S, m = h;
883
+ }
884
+ m || (m = ht, k(y, l, m));
885
+ const w = q(y * 2, a), A = i(m, w, x, o + 1, r + y / N);
886
+ let P;
887
+ if (A === vi) {
888
+ const S = M(y), E = B(y) - S;
889
+ P = e(S, E, !0, o + 1, r + y / N, m);
890
+ } else
891
+ P = A && qe(
892
+ y,
893
+ t,
894
+ i,
895
+ e,
896
+ s,
897
+ r,
898
+ o + 1
899
+ );
900
+ if (P) return !0;
901
+ h = Dt, k(g, l, h);
902
+ const v = q(g * 2, a), T = i(h, v, b, o + 1, r + g / N);
903
+ let R;
904
+ if (T === vi) {
905
+ const S = M(g), E = B(g) - S;
906
+ R = e(S, E, !0, o + 1, r + g / N, h);
907
+ } else
908
+ R = T && qe(
909
+ g,
910
+ t,
911
+ i,
912
+ e,
913
+ s,
914
+ r,
915
+ o + 1
916
+ );
917
+ return !!R;
918
+ }
919
+ }
920
+ const Ht = /* @__PURE__ */ new I.constructor(), be = /* @__PURE__ */ new I.constructor(), mt = /* @__PURE__ */ new ni(() => new it()), Rt = /* @__PURE__ */ new it(), Bt = /* @__PURE__ */ new it(), Be = /* @__PURE__ */ new it(), _e = /* @__PURE__ */ new it();
921
+ let Ee = !1;
922
+ function us(n, t, i, e) {
923
+ if (Ee)
924
+ throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");
925
+ Ee = !0;
926
+ const s = n._roots, r = t._roots;
927
+ let o, l = 0, a = 0;
928
+ const d = new Z().copy(i).invert();
929
+ for (let f = 0, p = s.length; f < p; f++) {
930
+ Ht.setBuffer(s[f]), a = 0;
931
+ const c = mt.getPrimitive();
932
+ k(0, Ht.float32Array, c), c.applyMatrix4(d);
933
+ for (let u = 0, y = r.length; u < y && (be.setBuffer(r[u]), o = st(
934
+ 0,
935
+ 0,
936
+ i,
937
+ d,
938
+ e,
939
+ l,
940
+ a,
941
+ 0,
942
+ 0,
943
+ c
944
+ ), be.clearBuffer(), a += r[u].byteLength / X, !o); u++)
945
+ ;
946
+ if (mt.releasePrimitive(c), Ht.clearBuffer(), l += s[f].byteLength / X, o)
947
+ break;
948
+ }
949
+ return Ee = !1, o;
950
+ }
951
+ function st(n, t, i, e, s, r = 0, o = 0, l = 0, a = 0, d = null, f = !1) {
952
+ let p, c;
953
+ f ? (p = be, c = Ht) : (p = Ht, c = be);
954
+ const u = p.float32Array, y = p.uint32Array, g = p.uint16Array, x = c.float32Array, b = c.uint32Array, m = c.uint16Array, h = n * 2, w = t * 2, A = q(h, g), P = q(w, m);
955
+ let v = !1;
956
+ if (P && A)
957
+ f ? v = s(
958
+ J(t, b),
959
+ H(t * 2, m),
960
+ J(n, y),
961
+ H(n * 2, g),
962
+ a,
963
+ o + t / N,
964
+ l,
965
+ r + n / N
966
+ ) : v = s(
967
+ J(n, y),
968
+ H(n * 2, g),
969
+ J(t, b),
970
+ H(t * 2, m),
971
+ l,
972
+ r + n / N,
973
+ a,
974
+ o + t / N
975
+ );
976
+ else if (P) {
977
+ const T = mt.getPrimitive();
978
+ k(t, x, T), T.applyMatrix4(i);
979
+ const R = V(n), M = W(n, y);
980
+ k(R, u, Rt), k(M, u, Bt);
981
+ const B = T.intersectsBox(Rt), S = T.intersectsBox(Bt);
982
+ v = B && st(
983
+ t,
984
+ R,
985
+ e,
986
+ i,
987
+ s,
988
+ o,
989
+ r,
990
+ a,
991
+ l + 1,
992
+ T,
993
+ !f
994
+ ) || S && st(
995
+ t,
996
+ M,
997
+ e,
998
+ i,
999
+ s,
1000
+ o,
1001
+ r,
1002
+ a,
1003
+ l + 1,
1004
+ T,
1005
+ !f
1006
+ ), mt.releasePrimitive(T);
1007
+ } else {
1008
+ const T = V(t), R = W(t, b);
1009
+ k(T, x, Be), k(R, x, _e);
1010
+ const M = d.intersectsBox(Be), B = d.intersectsBox(_e);
1011
+ if (M && B)
1012
+ v = st(
1013
+ n,
1014
+ T,
1015
+ i,
1016
+ e,
1017
+ s,
1018
+ r,
1019
+ o,
1020
+ l,
1021
+ a + 1,
1022
+ d,
1023
+ f
1024
+ ) || st(
1025
+ n,
1026
+ R,
1027
+ i,
1028
+ e,
1029
+ s,
1030
+ r,
1031
+ o,
1032
+ l,
1033
+ a + 1,
1034
+ d,
1035
+ f
1036
+ );
1037
+ else if (M)
1038
+ if (A)
1039
+ v = st(
1040
+ n,
1041
+ T,
1042
+ i,
1043
+ e,
1044
+ s,
1045
+ r,
1046
+ o,
1047
+ l,
1048
+ a + 1,
1049
+ d,
1050
+ f
1051
+ );
1052
+ else {
1053
+ const S = mt.getPrimitive();
1054
+ S.copy(Be).applyMatrix4(i);
1055
+ const _ = V(n), E = W(n, y);
1056
+ k(_, u, Rt), k(E, u, Bt);
1057
+ const $ = S.intersectsBox(Rt), D = S.intersectsBox(Bt);
1058
+ v = $ && st(
1059
+ T,
1060
+ _,
1061
+ e,
1062
+ i,
1063
+ s,
1064
+ o,
1065
+ r,
1066
+ a,
1067
+ l + 1,
1068
+ S,
1069
+ !f
1070
+ ) || D && st(
1071
+ T,
1072
+ E,
1073
+ e,
1074
+ i,
1075
+ s,
1076
+ o,
1077
+ r,
1078
+ a,
1079
+ l + 1,
1080
+ S,
1081
+ !f
1082
+ ), mt.releasePrimitive(S);
1083
+ }
1084
+ else if (B)
1085
+ if (A)
1086
+ v = st(
1087
+ n,
1088
+ R,
1089
+ i,
1090
+ e,
1091
+ s,
1092
+ r,
1093
+ o,
1094
+ l,
1095
+ a + 1,
1096
+ d,
1097
+ f
1098
+ );
1099
+ else {
1100
+ const S = mt.getPrimitive();
1101
+ S.copy(_e).applyMatrix4(i);
1102
+ const _ = V(n), E = W(n, y);
1103
+ k(_, u, Rt), k(E, u, Bt);
1104
+ const $ = S.intersectsBox(Rt), D = S.intersectsBox(Bt);
1105
+ v = $ && st(
1106
+ R,
1107
+ _,
1108
+ e,
1109
+ i,
1110
+ s,
1111
+ o,
1112
+ r,
1113
+ a,
1114
+ l + 1,
1115
+ S,
1116
+ !f
1117
+ ) || D && st(
1118
+ R,
1119
+ E,
1120
+ e,
1121
+ i,
1122
+ s,
1123
+ o,
1124
+ r,
1125
+ a,
1126
+ l + 1,
1127
+ S,
1128
+ !f
1129
+ ), mt.releasePrimitive(S);
1130
+ }
1131
+ }
1132
+ return v;
1133
+ }
1134
+ const Ri = /* @__PURE__ */ new it(), _t = /* @__PURE__ */ new Float32Array(6);
1135
+ class fs {
1136
+ constructor() {
1137
+ this._roots = null, this.primitiveBuffer = null, this.primitiveBufferStride = null;
1138
+ }
1139
+ init(t) {
1140
+ t = {
1141
+ ...sn,
1142
+ ...t
1143
+ }, as(this, t);
1144
+ }
1145
+ getRootRanges() {
1146
+ throw new Error("BVH: getRootRanges() not implemented");
1147
+ }
1148
+ // write the i-th primitive bounds in a 6-value min / max format to the buffer
1149
+ // starting at the given "writeOffset"
1150
+ writePrimitiveBounds() {
1151
+ throw new Error("BVH: writePrimitiveBounds() not implemented");
1152
+ }
1153
+ // writes the union bounds of all primitives in the given range in a min / max format
1154
+ // to the buffer
1155
+ writePrimitiveRangeBounds(t, i, e, s) {
1156
+ let r = 1 / 0, o = 1 / 0, l = 1 / 0, a = -1 / 0, d = -1 / 0, f = -1 / 0;
1157
+ for (let p = t, c = t + i; p < c; p++) {
1158
+ this.writePrimitiveBounds(p, _t, 0);
1159
+ const [u, y, g, x, b, m] = _t;
1160
+ u < r && (r = u), x > a && (a = x), y < o && (o = y), b > d && (d = b), g < l && (l = g), m > f && (f = m);
1161
+ }
1162
+ return e[s + 0] = r, e[s + 1] = o, e[s + 2] = l, e[s + 3] = a, e[s + 4] = d, e[s + 5] = f, e;
1163
+ }
1164
+ computePrimitiveBounds(t, i, e) {
1165
+ const s = e.offset || 0;
1166
+ for (let r = t, o = t + i; r < o; r++) {
1167
+ this.writePrimitiveBounds(r, _t, 0);
1168
+ const [l, a, d, f, p, c] = _t, u = (l + f) / 2, y = (a + p) / 2, g = (d + c) / 2, x = (f - l) / 2, b = (p - a) / 2, m = (c - d) / 2, h = (r - s) * 6;
1169
+ e[h + 0] = u, e[h + 1] = x + (Math.abs(u) + x) * ge, e[h + 2] = y, e[h + 3] = b + (Math.abs(y) + b) * ge, e[h + 4] = g, e[h + 5] = m + (Math.abs(g) + m) * ge;
1170
+ }
1171
+ return e;
1172
+ }
1173
+ shiftPrimitiveOffsets(t) {
1174
+ const i = this._indirectBuffer;
1175
+ if (i)
1176
+ for (let e = 0, s = i.length; e < s; e++)
1177
+ i[e] += t;
1178
+ else {
1179
+ const e = this._roots;
1180
+ for (let s = 0; s < e.length; s++) {
1181
+ const r = e[s], o = new Uint32Array(r), l = new Uint16Array(r), a = r.byteLength / X;
1182
+ for (let d = 0; d < a; d++) {
1183
+ const f = N * d, p = 2 * f;
1184
+ q(p, l) && (o[f + 6] += t);
1185
+ }
1186
+ }
1187
+ }
1188
+ }
1189
+ traverse(t, i = 0) {
1190
+ const e = this._roots[i], s = new Uint32Array(e), r = new Uint16Array(e);
1191
+ o(0);
1192
+ function o(l, a = 0) {
1193
+ const d = l * 2, f = q(d, r);
1194
+ if (f) {
1195
+ const p = s[l + 6], c = r[d + 14];
1196
+ t(a, f, new Float32Array(e, l * 4, 6), p, c);
1197
+ } else {
1198
+ const p = V(l), c = W(l, s), u = ii(l, s);
1199
+ t(a, f, new Float32Array(e, l * 4, 6), u) || (o(p, a + 1), o(c, a + 1));
1200
+ }
1201
+ }
1202
+ }
1203
+ refit() {
1204
+ const t = this._roots;
1205
+ for (let i = 0, e = t.length; i < e; i++) {
1206
+ const s = t[i], r = new Uint32Array(s), o = new Uint16Array(s), l = new Float32Array(s), a = s.byteLength / X;
1207
+ for (let d = a - 1; d >= 0; d--) {
1208
+ const f = d * N, p = f * 2;
1209
+ if (q(p, o)) {
1210
+ const u = J(f, r), y = H(p, o);
1211
+ this.writePrimitiveRangeBounds(u, y, _t, 0), l.set(_t, f);
1212
+ } else {
1213
+ const u = V(f), y = W(f, r);
1214
+ for (let g = 0; g < 3; g++) {
1215
+ const x = l[u + g], b = l[u + g + 3], m = l[y + g], h = l[y + g + 3];
1216
+ l[f + g] = x < m ? x : m, l[f + g + 3] = b > h ? b : h;
1217
+ }
1218
+ }
1219
+ }
1220
+ }
1221
+ }
1222
+ getBoundingBox(t) {
1223
+ return t.makeEmpty(), this._roots.forEach((e) => {
1224
+ k(0, new Float32Array(e), Ri), t.union(Ri);
1225
+ }), t;
1226
+ }
1227
+ // Base shapecast implementation that can be used by subclasses
1228
+ // TODO: see if we can get rid of "iterateFunc" here as well as the primitive so the function
1229
+ // API aligns with the "shapecast" implementation
1230
+ shapecast(t) {
1231
+ let {
1232
+ boundsTraverseOrder: i,
1233
+ intersectsBounds: e,
1234
+ intersectsRange: s,
1235
+ intersectsPrimitive: r,
1236
+ scratchPrimitive: o,
1237
+ iterate: l
1238
+ } = t;
1239
+ if (s && r) {
1240
+ const p = s;
1241
+ s = (c, u, y, g, x) => p(c, u, y, g, x) ? !0 : l(c, u, this, r, y, g, o);
1242
+ } else s || (r ? s = (p, c, u, y) => l(p, c, this, r, u, y, o) : s = (p, c, u) => u);
1243
+ let a = !1, d = 0;
1244
+ const f = this._roots;
1245
+ for (let p = 0, c = f.length; p < c; p++) {
1246
+ const u = f[p];
1247
+ if (a = ls(this, p, e, s, i, d), a)
1248
+ break;
1249
+ d += u.byteLength / X;
1250
+ }
1251
+ return a;
1252
+ }
1253
+ bvhcast(t, i, e) {
1254
+ let { intersectsRanges: s } = e;
1255
+ return us(this, t, i, s);
1256
+ }
1257
+ }
1258
+ function ds() {
1259
+ return typeof SharedArrayBuffer < "u";
1260
+ }
1261
+ function si(n) {
1262
+ return n.index ? n.index.count : n.attributes.position.count;
1263
+ }
1264
+ function ve(n) {
1265
+ return si(n) / 3;
1266
+ }
1267
+ function ps(n, t = ArrayBuffer) {
1268
+ return n > 65535 ? new Uint32Array(new t(4 * n)) : new Uint16Array(new t(2 * n));
1269
+ }
1270
+ function ms(n, t) {
1271
+ if (!n.index) {
1272
+ const i = n.attributes.position.count, e = t.useSharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer, s = ps(i, e);
1273
+ n.setIndex(new Xi(s, 1));
1274
+ for (let r = 0; r < i; r++)
1275
+ s[r] = r;
1276
+ }
1277
+ }
1278
+ function hs(n, t, i) {
1279
+ const e = si(n) / i, s = t || n.drawRange, r = s.start / i, o = (s.start + s.count) / i, l = Math.max(0, r), a = Math.min(e, o) - l;
1280
+ return {
1281
+ offset: Math.floor(l),
1282
+ count: Math.floor(a)
1283
+ };
1284
+ }
1285
+ function ys(n, t) {
1286
+ return n.groups.map((i) => ({
1287
+ offset: i.start / t,
1288
+ count: i.count / t
1289
+ }));
1290
+ }
1291
+ function Bi(n, t, i) {
1292
+ const e = hs(n, t, i), s = ys(n, i);
1293
+ if (!s.length)
1294
+ return [e];
1295
+ const r = [], o = e.offset, l = e.offset + e.count, a = si(n) / i, d = [];
1296
+ for (const c of s) {
1297
+ const { offset: u, count: y } = c, g = u, x = isFinite(y) ? y : a - u, b = u + x;
1298
+ g < l && b > o && (d.push({ pos: Math.max(o, g), isStart: !0 }), d.push({ pos: Math.min(l, b), isStart: !1 }));
1299
+ }
1300
+ d.sort((c, u) => c.pos !== u.pos ? c.pos - u.pos : c.type === "end" ? -1 : 1);
1301
+ let f = 0, p = null;
1302
+ for (const c of d) {
1303
+ const u = c.pos;
1304
+ f !== 0 && u !== p && r.push({
1305
+ offset: p,
1306
+ count: u - p
1307
+ }), f += c.isStart ? 1 : -1, p = u;
1308
+ }
1309
+ return r;
1310
+ }
1311
+ function gs(n, t) {
1312
+ const i = n[n.length - 1], e = i.offset + i.count > 2 ** 16, s = n.reduce((d, f) => d + f.count, 0), r = e ? 4 : 2, o = t ? new SharedArrayBuffer(s * r) : new ArrayBuffer(s * r), l = e ? new Uint32Array(o) : new Uint16Array(o);
1313
+ let a = 0;
1314
+ for (let d = 0; d < n.length; d++) {
1315
+ const { offset: f, count: p } = n[d];
1316
+ for (let c = 0; c < p; c++)
1317
+ l[a + c] = f + c;
1318
+ a += p;
1319
+ }
1320
+ return l;
1321
+ }
1322
+ class ws extends fs {
1323
+ get indirect() {
1324
+ return !!this._indirectBuffer;
1325
+ }
1326
+ get primitiveStride() {
1327
+ return null;
1328
+ }
1329
+ get primitiveBufferStride() {
1330
+ return this.indirect ? 1 : this.primitiveStride;
1331
+ }
1332
+ set primitiveBufferStride(t) {
1333
+ }
1334
+ get primitiveBuffer() {
1335
+ return this.indirect ? this._indirectBuffer : this.geometry.index.array;
1336
+ }
1337
+ set primitiveBuffer(t) {
1338
+ }
1339
+ constructor(t, i = {}) {
1340
+ if (t.isBufferGeometry) {
1341
+ if (t.index && t.index.isInterleavedBufferAttribute)
1342
+ throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.");
1343
+ } else throw new Error("BVH: Only BufferGeometries are supported.");
1344
+ if (i.useSharedArrayBuffer && !ds())
1345
+ throw new Error("BVH: SharedArrayBuffer is not available.");
1346
+ super(), this.geometry = t, this.resolvePrimitiveIndex = i.indirect ? (e) => this._indirectBuffer[e] : (e) => e, this.primitiveBuffer = null, this.primitiveBufferStride = null, this._indirectBuffer = null, i = {
1347
+ ...sn,
1348
+ ...i
1349
+ }, i[ei] || this.init(i);
1350
+ }
1351
+ init(t) {
1352
+ const { geometry: i, primitiveStride: e } = this;
1353
+ if (t.indirect) {
1354
+ const s = Bi(i, t.range, e), r = gs(s, t.useSharedArrayBuffer);
1355
+ this._indirectBuffer = r;
1356
+ } else
1357
+ ms(i, t);
1358
+ super.init(t), !i.boundingBox && t.setBoundingBox && (i.boundingBox = this.getBoundingBox(new it()));
1359
+ }
1360
+ // Abstract methods to be implemented by subclasses
1361
+ getRootRanges(t) {
1362
+ return this.indirect ? [{ offset: 0, count: this._indirectBuffer.length }] : Bi(this.geometry, t, this.primitiveStride);
1363
+ }
1364
+ raycastObject3D() {
1365
+ throw new Error("BVH: raycastObject3D() not implemented");
1366
+ }
1367
+ }
1368
+ class dt {
1369
+ constructor() {
1370
+ this.min = 1 / 0, this.max = -1 / 0;
1371
+ }
1372
+ setFromPointsField(t, i) {
1373
+ let e = 1 / 0, s = -1 / 0;
1374
+ for (let r = 0, o = t.length; r < o; r++) {
1375
+ const a = t[r][i];
1376
+ e = a < e ? a : e, s = a > s ? a : s;
1377
+ }
1378
+ this.min = e, this.max = s;
1379
+ }
1380
+ setFromPoints(t, i) {
1381
+ let e = 1 / 0, s = -1 / 0;
1382
+ for (let r = 0, o = i.length; r < o; r++) {
1383
+ const l = i[r], a = t.dot(l);
1384
+ e = a < e ? a : e, s = a > s ? a : s;
1385
+ }
1386
+ this.min = e, this.max = s;
1387
+ }
1388
+ isSeparated(t) {
1389
+ return this.min > t.max || t.min > this.max;
1390
+ }
1391
+ }
1392
+ dt.prototype.setFromBox = /* @__PURE__ */ function() {
1393
+ const n = /* @__PURE__ */ new U();
1394
+ return function(i, e) {
1395
+ const s = e.min, r = e.max;
1396
+ let o = 1 / 0, l = -1 / 0;
1397
+ for (let a = 0; a <= 1; a++)
1398
+ for (let d = 0; d <= 1; d++)
1399
+ for (let f = 0; f <= 1; f++) {
1400
+ n.x = s.x * a + r.x * (1 - a), n.y = s.y * d + r.y * (1 - d), n.z = s.z * f + r.z * (1 - f);
1401
+ const p = i.dot(n);
1402
+ o = Math.min(p, o), l = Math.max(p, l);
1403
+ }
1404
+ this.min = o, this.max = l;
1405
+ };
1406
+ }();
1407
+ const bs = /* @__PURE__ */ function() {
1408
+ const n = /* @__PURE__ */ new U(), t = /* @__PURE__ */ new U(), i = /* @__PURE__ */ new U();
1409
+ return function(s, r, o) {
1410
+ const l = s.start, a = n, d = r.start, f = t;
1411
+ i.subVectors(l, d), n.subVectors(s.end, s.start), t.subVectors(r.end, r.start);
1412
+ const p = i.dot(f), c = f.dot(a), u = f.dot(f), y = i.dot(a), x = a.dot(a) * u - c * c;
1413
+ let b, m;
1414
+ x !== 0 ? b = (p * c - y * u) / x : b = 0, m = (p + b * c) / u, o.x = b, o.y = m;
1415
+ };
1416
+ }(), oi = /* @__PURE__ */ function() {
1417
+ const n = /* @__PURE__ */ new yt(), t = /* @__PURE__ */ new U(), i = /* @__PURE__ */ new U();
1418
+ return function(s, r, o, l) {
1419
+ bs(s, r, n);
1420
+ let a = n.x, d = n.y;
1421
+ if (a >= 0 && a <= 1 && d >= 0 && d <= 1) {
1422
+ s.at(a, o), r.at(d, l);
1423
+ return;
1424
+ } else if (a >= 0 && a <= 1) {
1425
+ d < 0 ? r.at(0, l) : r.at(1, l), s.closestPointToPoint(l, !0, o);
1426
+ return;
1427
+ } else if (d >= 0 && d <= 1) {
1428
+ a < 0 ? s.at(0, o) : s.at(1, o), r.closestPointToPoint(o, !0, l);
1429
+ return;
1430
+ } else {
1431
+ let f;
1432
+ a < 0 ? f = s.start : f = s.end;
1433
+ let p;
1434
+ d < 0 ? p = r.start : p = r.end;
1435
+ const c = t, u = i;
1436
+ if (s.closestPointToPoint(p, !0, t), r.closestPointToPoint(f, !0, i), c.distanceToSquared(p) <= u.distanceToSquared(f)) {
1437
+ o.copy(c), l.copy(p);
1438
+ return;
1439
+ } else {
1440
+ o.copy(f), l.copy(u);
1441
+ return;
1442
+ }
1443
+ }
1444
+ };
1445
+ }(), xs = /* @__PURE__ */ function() {
1446
+ const n = /* @__PURE__ */ new U(), t = /* @__PURE__ */ new U(), i = /* @__PURE__ */ new Ji(), e = /* @__PURE__ */ new ft();
1447
+ return function(r, o) {
1448
+ const { radius: l, center: a } = r, { a: d, b: f, c: p } = o;
1449
+ if (e.start = d, e.end = f, e.closestPointToPoint(a, !0, n).distanceTo(a) <= l || (e.start = d, e.end = p, e.closestPointToPoint(a, !0, n).distanceTo(a) <= l) || (e.start = f, e.end = p, e.closestPointToPoint(a, !0, n).distanceTo(a) <= l)) return !0;
1450
+ const g = o.getPlane(i);
1451
+ if (Math.abs(g.distanceToPoint(a)) <= l) {
1452
+ const b = g.projectPoint(a, t);
1453
+ if (o.containsPoint(b)) return !0;
1454
+ }
1455
+ return !1;
1456
+ };
1457
+ }(), As = ["x", "y", "z"], ct = 1e-15, _i = ct * ct;
1458
+ function K(n) {
1459
+ return Math.abs(n) < ct;
1460
+ }
1461
+ class ot extends Ft {
1462
+ constructor(...t) {
1463
+ super(...t), this.isExtendedTriangle = !0, this.satAxes = new Array(4).fill().map(() => new U()), this.satBounds = new Array(4).fill().map(() => new dt()), this.points = [this.a, this.b, this.c], this.plane = new Ji(), this.isDegenerateIntoSegment = !1, this.isDegenerateIntoPoint = !1, this.degenerateSegment = new ft(), this.needsUpdate = !0;
1464
+ }
1465
+ intersectsSphere(t) {
1466
+ return xs(t, this);
1467
+ }
1468
+ update() {
1469
+ const t = this.a, i = this.b, e = this.c, s = this.points, r = this.satAxes, o = this.satBounds, l = r[0], a = o[0];
1470
+ this.getNormal(l), a.setFromPoints(l, s);
1471
+ const d = r[1], f = o[1];
1472
+ d.subVectors(t, i), f.setFromPoints(d, s);
1473
+ const p = r[2], c = o[2];
1474
+ p.subVectors(i, e), c.setFromPoints(p, s);
1475
+ const u = r[3], y = o[3];
1476
+ u.subVectors(e, t), y.setFromPoints(u, s);
1477
+ const g = d.length(), x = p.length(), b = u.length();
1478
+ this.isDegenerateIntoPoint = !1, this.isDegenerateIntoSegment = !1, g < ct ? x < ct || b < ct ? this.isDegenerateIntoPoint = !0 : (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(t), this.degenerateSegment.end.copy(e)) : x < ct ? b < ct ? this.isDegenerateIntoPoint = !0 : (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(i), this.degenerateSegment.end.copy(t)) : b < ct && (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(e), this.degenerateSegment.end.copy(i)), this.plane.setFromNormalAndCoplanarPoint(l, t), this.needsUpdate = !1;
1479
+ }
1480
+ }
1481
+ ot.prototype.closestPointToSegment = /* @__PURE__ */ function() {
1482
+ const n = /* @__PURE__ */ new U(), t = /* @__PURE__ */ new U(), i = /* @__PURE__ */ new ft();
1483
+ return function(s, r = null, o = null) {
1484
+ const { start: l, end: a } = s, d = this.points;
1485
+ let f, p = 1 / 0;
1486
+ for (let c = 0; c < 3; c++) {
1487
+ const u = (c + 1) % 3;
1488
+ i.start.copy(d[c]), i.end.copy(d[u]), oi(i, s, n, t), f = n.distanceToSquared(t), f < p && (p = f, r && r.copy(n), o && o.copy(t));
1489
+ }
1490
+ return this.closestPointToPoint(l, n), f = l.distanceToSquared(n), f < p && (p = f, r && r.copy(n), o && o.copy(l)), this.closestPointToPoint(a, n), f = a.distanceToSquared(n), f < p && (p = f, r && r.copy(n), o && o.copy(a)), Math.sqrt(p);
1491
+ };
1492
+ }();
1493
+ ot.prototype.intersectsTriangle = /* @__PURE__ */ function() {
1494
+ const n = /* @__PURE__ */ new ot(), t = /* @__PURE__ */ new dt(), i = /* @__PURE__ */ new dt(), e = /* @__PURE__ */ new U(), s = /* @__PURE__ */ new U(), r = /* @__PURE__ */ new U(), o = /* @__PURE__ */ new U(), l = /* @__PURE__ */ new ft(), a = /* @__PURE__ */ new ft(), d = /* @__PURE__ */ new U(), f = /* @__PURE__ */ new yt(), p = /* @__PURE__ */ new yt();
1495
+ function c(h, w, A, P) {
1496
+ const v = e;
1497
+ !h.isDegenerateIntoPoint && !h.isDegenerateIntoSegment ? v.copy(h.plane.normal) : v.copy(w.plane.normal);
1498
+ const T = h.satBounds, R = h.satAxes;
1499
+ for (let S = 1; S < 4; S++) {
1500
+ const _ = T[S], E = R[S];
1501
+ if (t.setFromPoints(E, w.points), _.isSeparated(t) || (o.copy(v).cross(E), t.setFromPoints(o, h.points), i.setFromPoints(o, w.points), t.isSeparated(i))) return !1;
1502
+ }
1503
+ const M = w.satBounds, B = w.satAxes;
1504
+ for (let S = 1; S < 4; S++) {
1505
+ const _ = M[S], E = B[S];
1506
+ if (t.setFromPoints(E, h.points), _.isSeparated(t) || (o.crossVectors(v, E), t.setFromPoints(o, h.points), i.setFromPoints(o, w.points), t.isSeparated(i))) return !1;
1507
+ }
1508
+ return A && (P || console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."), A.start.set(0, 0, 0), A.end.set(0, 0, 0)), !0;
1509
+ }
1510
+ function u(h, w, A, P, v, T, R, M, B, S, _) {
1511
+ let E = R / (R - M);
1512
+ S.x = P + (v - P) * E, _.start.subVectors(w, h).multiplyScalar(E).add(h), E = R / (R - B), S.y = P + (T - P) * E, _.end.subVectors(A, h).multiplyScalar(E).add(h);
1513
+ }
1514
+ function y(h, w, A, P, v, T, R, M, B, S, _) {
1515
+ if (v > 0)
1516
+ u(h.c, h.a, h.b, P, w, A, B, R, M, S, _);
1517
+ else if (T > 0)
1518
+ u(h.b, h.a, h.c, A, w, P, M, R, B, S, _);
1519
+ else if (M * B > 0 || R != 0)
1520
+ u(h.a, h.b, h.c, w, A, P, R, M, B, S, _);
1521
+ else if (M != 0)
1522
+ u(h.b, h.a, h.c, A, w, P, M, R, B, S, _);
1523
+ else if (B != 0)
1524
+ u(h.c, h.a, h.b, P, w, A, B, R, M, S, _);
1525
+ else
1526
+ return !0;
1527
+ return !1;
1528
+ }
1529
+ function g(h, w, A, P) {
1530
+ const v = w.degenerateSegment, T = h.plane.distanceToPoint(v.start), R = h.plane.distanceToPoint(v.end);
1531
+ return K(T) ? K(R) ? c(h, w, A, P) : (A && (A.start.copy(v.start), A.end.copy(v.start)), h.containsPoint(v.start)) : K(R) ? (A && (A.start.copy(v.end), A.end.copy(v.end)), h.containsPoint(v.end)) : h.plane.intersectLine(v, e) != null ? (A && (A.start.copy(e), A.end.copy(e)), h.containsPoint(e)) : !1;
1532
+ }
1533
+ function x(h, w, A) {
1534
+ const P = w.a;
1535
+ return K(h.plane.distanceToPoint(P)) && h.containsPoint(P) ? (A && (A.start.copy(P), A.end.copy(P)), !0) : !1;
1536
+ }
1537
+ function b(h, w, A) {
1538
+ const P = h.degenerateSegment, v = w.a;
1539
+ return P.closestPointToPoint(v, !0, e), v.distanceToSquared(e) < _i ? (A && (A.start.copy(v), A.end.copy(v)), !0) : !1;
1540
+ }
1541
+ function m(h, w, A, P) {
1542
+ if (h.isDegenerateIntoSegment)
1543
+ if (w.isDegenerateIntoSegment) {
1544
+ const v = h.degenerateSegment, T = w.degenerateSegment, R = s, M = r;
1545
+ v.delta(R), T.delta(M);
1546
+ const B = e.subVectors(T.start, v.start), S = R.x * M.y - R.y * M.x;
1547
+ if (K(S))
1548
+ return !1;
1549
+ const _ = (B.x * M.y - B.y * M.x) / S, E = -(R.x * B.y - R.y * B.x) / S;
1550
+ if (_ < 0 || _ > 1 || E < 0 || E > 1)
1551
+ return !1;
1552
+ const $ = v.start.z + R.z * _, D = T.start.z + M.z * E;
1553
+ return K($ - D) ? (A && (A.start.copy(v.start).addScaledVector(R, _), A.end.copy(v.start).addScaledVector(R, _)), !0) : !1;
1554
+ } else return w.isDegenerateIntoPoint ? b(h, w, A) : g(w, h, A, P);
1555
+ else {
1556
+ if (h.isDegenerateIntoPoint)
1557
+ return w.isDegenerateIntoPoint ? w.a.distanceToSquared(h.a) < _i ? (A && (A.start.copy(h.a), A.end.copy(h.a)), !0) : !1 : w.isDegenerateIntoSegment ? b(w, h, A) : x(w, h, A);
1558
+ if (w.isDegenerateIntoPoint)
1559
+ return x(h, w, A);
1560
+ if (w.isDegenerateIntoSegment)
1561
+ return g(h, w, A, P);
1562
+ }
1563
+ }
1564
+ return function(w, A = null, P = !1) {
1565
+ this.needsUpdate && this.update(), w.isExtendedTriangle ? w.needsUpdate && w.update() : (n.copy(w), n.update(), w = n);
1566
+ const v = m(this, w, A, P);
1567
+ if (v !== void 0)
1568
+ return v;
1569
+ const T = this.plane, R = w.plane;
1570
+ let M = R.distanceToPoint(this.a), B = R.distanceToPoint(this.b), S = R.distanceToPoint(this.c);
1571
+ K(M) && (M = 0), K(B) && (B = 0), K(S) && (S = 0);
1572
+ const _ = M * B, E = M * S;
1573
+ if (_ > 0 && E > 0)
1574
+ return !1;
1575
+ let $ = T.distanceToPoint(w.a), D = T.distanceToPoint(w.b), z = T.distanceToPoint(w.c);
1576
+ K($) && ($ = 0), K(D) && (D = 0), K(z) && (z = 0);
1577
+ const L = $ * D, Y = $ * z;
1578
+ if (L > 0 && Y > 0)
1579
+ return !1;
1580
+ s.copy(T.normal), r.copy(R.normal);
1581
+ const vt = s.cross(r);
1582
+ let Mt = 0, Pt = Math.abs(vt.x);
1583
+ const kt = Math.abs(vt.y);
1584
+ kt > Pt && (Pt = kt, Mt = 1), Math.abs(vt.z) > Pt && (Mt = 2);
1585
+ const nt = As[Mt], Yt = this.a[nt], an = this.b[nt], cn = this.c[nt], ln = w.a[nt], un = w.b[nt], fn = w.c[nt];
1586
+ if (y(this, Yt, an, cn, _, E, M, B, S, f, l))
1587
+ return c(this, w, A, P);
1588
+ if (y(w, ln, un, fn, L, Y, $, D, z, p, a))
1589
+ return c(this, w, A, P);
1590
+ if (f.y < f.x) {
1591
+ const Pe = f.y;
1592
+ f.y = f.x, f.x = Pe, d.copy(l.start), l.start.copy(l.end), l.end.copy(d);
1593
+ }
1594
+ if (p.y < p.x) {
1595
+ const Pe = p.y;
1596
+ p.y = p.x, p.x = Pe, d.copy(a.start), a.start.copy(a.end), a.end.copy(d);
1597
+ }
1598
+ return f.y < p.x || p.y < f.x ? !1 : (A && (p.x > f.x ? A.start.copy(a.start) : A.start.copy(l.start), p.y < f.y ? A.end.copy(a.end) : A.end.copy(l.end)), !0);
1599
+ };
1600
+ }();
1601
+ ot.prototype.distanceToPoint = /* @__PURE__ */ function() {
1602
+ const n = /* @__PURE__ */ new U();
1603
+ return function(i) {
1604
+ return this.closestPointToPoint(i, n), i.distanceTo(n);
1605
+ };
1606
+ }();
1607
+ ot.prototype.distanceToTriangle = /* @__PURE__ */ function() {
1608
+ const n = /* @__PURE__ */ new U(), t = /* @__PURE__ */ new U(), i = ["a", "b", "c"], e = /* @__PURE__ */ new ft(), s = /* @__PURE__ */ new ft();
1609
+ return function(o, l = null, a = null) {
1610
+ const d = l || a ? e : null;
1611
+ if (this.intersectsTriangle(o, d))
1612
+ return (l || a) && (l && d.getCenter(l), a && d.getCenter(a)), 0;
1613
+ let f = 1 / 0;
1614
+ for (let p = 0; p < 3; p++) {
1615
+ let c;
1616
+ const u = i[p], y = o[u];
1617
+ this.closestPointToPoint(y, n), c = y.distanceToSquared(n), c < f && (f = c, l && l.copy(n), a && a.copy(y));
1618
+ const g = this[u];
1619
+ o.closestPointToPoint(g, n), c = g.distanceToSquared(n), c < f && (f = c, l && l.copy(g), a && a.copy(n));
1620
+ }
1621
+ for (let p = 0; p < 3; p++) {
1622
+ const c = i[p], u = i[(p + 1) % 3];
1623
+ e.set(this[c], this[u]);
1624
+ for (let y = 0; y < 3; y++) {
1625
+ const g = i[y], x = i[(y + 1) % 3];
1626
+ s.set(o[g], o[x]), oi(e, s, n, t);
1627
+ const b = n.distanceToSquared(t);
1628
+ b < f && (f = b, l && l.copy(n), a && a.copy(t));
1629
+ }
1630
+ }
1631
+ return Math.sqrt(f);
1632
+ };
1633
+ }();
1634
+ class Q {
1635
+ constructor(t, i, e) {
1636
+ this.isOrientedBox = !0, this.min = new U(), this.max = new U(), this.matrix = new Z(), this.invMatrix = new Z(), this.points = new Array(8).fill().map(() => new U()), this.satAxes = new Array(3).fill().map(() => new U()), this.satBounds = new Array(3).fill().map(() => new dt()), this.alignedSatBounds = new Array(3).fill().map(() => new dt()), this.needsUpdate = !1, t && this.min.copy(t), i && this.max.copy(i), e && this.matrix.copy(e);
1637
+ }
1638
+ set(t, i, e) {
1639
+ this.min.copy(t), this.max.copy(i), this.matrix.copy(e), this.needsUpdate = !0;
1640
+ }
1641
+ copy(t) {
1642
+ this.min.copy(t.min), this.max.copy(t.max), this.matrix.copy(t.matrix), this.needsUpdate = !0;
1643
+ }
1644
+ }
1645
+ Q.prototype.update = /* @__PURE__ */ function() {
1646
+ return function() {
1647
+ const t = this.matrix, i = this.min, e = this.max, s = this.points;
1648
+ for (let d = 0; d <= 1; d++)
1649
+ for (let f = 0; f <= 1; f++)
1650
+ for (let p = 0; p <= 1; p++) {
1651
+ const c = 1 * d | 2 * f | 4 * p, u = s[c];
1652
+ u.x = d ? e.x : i.x, u.y = f ? e.y : i.y, u.z = p ? e.z : i.z, u.applyMatrix4(t);
1653
+ }
1654
+ const r = this.satBounds, o = this.satAxes, l = s[0];
1655
+ for (let d = 0; d < 3; d++) {
1656
+ const f = o[d], p = r[d], c = 1 << d, u = s[c];
1657
+ f.subVectors(l, u), p.setFromPoints(f, s);
1658
+ }
1659
+ const a = this.alignedSatBounds;
1660
+ a[0].setFromPointsField(s, "x"), a[1].setFromPointsField(s, "y"), a[2].setFromPointsField(s, "z"), this.invMatrix.copy(this.matrix).invert(), this.needsUpdate = !1;
1661
+ };
1662
+ }();
1663
+ Q.prototype.intersectsBox = /* @__PURE__ */ function() {
1664
+ const n = /* @__PURE__ */ new dt();
1665
+ return function(i) {
1666
+ this.needsUpdate && this.update();
1667
+ const e = i.min, s = i.max, r = this.satBounds, o = this.satAxes, l = this.alignedSatBounds;
1668
+ if (n.min = e.x, n.max = s.x, l[0].isSeparated(n) || (n.min = e.y, n.max = s.y, l[1].isSeparated(n)) || (n.min = e.z, n.max = s.z, l[2].isSeparated(n))) return !1;
1669
+ for (let a = 0; a < 3; a++) {
1670
+ const d = o[a], f = r[a];
1671
+ if (n.setFromBox(d, i), f.isSeparated(n)) return !1;
1672
+ }
1673
+ return !0;
1674
+ };
1675
+ }();
1676
+ Q.prototype.intersectsTriangle = /* @__PURE__ */ function() {
1677
+ const n = /* @__PURE__ */ new ot(), t = /* @__PURE__ */ new Array(3), i = /* @__PURE__ */ new dt(), e = /* @__PURE__ */ new dt(), s = /* @__PURE__ */ new U();
1678
+ return function(o) {
1679
+ this.needsUpdate && this.update(), o.isExtendedTriangle ? o.needsUpdate && o.update() : (n.copy(o), n.update(), o = n);
1680
+ const l = this.satBounds, a = this.satAxes;
1681
+ t[0] = o.a, t[1] = o.b, t[2] = o.c;
1682
+ for (let c = 0; c < 3; c++) {
1683
+ const u = l[c], y = a[c];
1684
+ if (i.setFromPoints(y, t), u.isSeparated(i)) return !1;
1685
+ }
1686
+ const d = o.satBounds, f = o.satAxes, p = this.points;
1687
+ for (let c = 0; c < 3; c++) {
1688
+ const u = d[c], y = f[c];
1689
+ if (i.setFromPoints(y, p), u.isSeparated(i)) return !1;
1690
+ }
1691
+ for (let c = 0; c < 3; c++) {
1692
+ const u = a[c];
1693
+ for (let y = 0; y < 4; y++) {
1694
+ const g = f[y];
1695
+ if (s.crossVectors(u, g), i.setFromPoints(s, t), e.setFromPoints(s, p), i.isSeparated(e)) return !1;
1696
+ }
1697
+ }
1698
+ return !0;
1699
+ };
1700
+ }();
1701
+ Q.prototype.closestPointToPoint = /* @__PURE__ */ function() {
1702
+ return function(t, i) {
1703
+ return this.needsUpdate && this.update(), i.copy(t).applyMatrix4(this.invMatrix).clamp(this.min, this.max).applyMatrix4(this.matrix), i;
1704
+ };
1705
+ }();
1706
+ Q.prototype.distanceToPoint = function() {
1707
+ const n = new U();
1708
+ return function(i) {
1709
+ return this.closestPointToPoint(i, n), i.distanceTo(n);
1710
+ };
1711
+ }();
1712
+ Q.prototype.distanceToBox = /* @__PURE__ */ function() {
1713
+ const n = ["x", "y", "z"], t = /* @__PURE__ */ new Array(12).fill().map(() => new ft()), i = /* @__PURE__ */ new Array(12).fill().map(() => new ft()), e = /* @__PURE__ */ new U(), s = /* @__PURE__ */ new U();
1714
+ return function(o, l = 0, a = null, d = null) {
1715
+ if (this.needsUpdate && this.update(), this.intersectsBox(o))
1716
+ return (a || d) && (o.getCenter(s), this.closestPointToPoint(s, e), o.closestPointToPoint(e, s), a && a.copy(e), d && d.copy(s)), 0;
1717
+ const f = l * l, p = o.min, c = o.max, u = this.points;
1718
+ let y = 1 / 0;
1719
+ for (let x = 0; x < 8; x++) {
1720
+ const b = u[x];
1721
+ s.copy(b).clamp(p, c);
1722
+ const m = b.distanceToSquared(s);
1723
+ if (m < y && (y = m, a && a.copy(b), d && d.copy(s), m < f))
1724
+ return Math.sqrt(m);
1725
+ }
1726
+ let g = 0;
1727
+ for (let x = 0; x < 3; x++)
1728
+ for (let b = 0; b <= 1; b++)
1729
+ for (let m = 0; m <= 1; m++) {
1730
+ const h = (x + 1) % 3, w = (x + 2) % 3, A = b << h | m << w, P = 1 << x | b << h | m << w, v = u[A], T = u[P];
1731
+ t[g].set(v, T);
1732
+ const M = n[x], B = n[h], S = n[w], _ = i[g], E = _.start, $ = _.end;
1733
+ E[M] = p[M], E[B] = b ? p[B] : c[B], E[S] = m ? p[S] : c[B], $[M] = c[M], $[B] = b ? p[B] : c[B], $[S] = m ? p[S] : c[B], g++;
1734
+ }
1735
+ for (let x = 0; x <= 1; x++)
1736
+ for (let b = 0; b <= 1; b++)
1737
+ for (let m = 0; m <= 1; m++) {
1738
+ s.x = x ? c.x : p.x, s.y = b ? c.y : p.y, s.z = m ? c.z : p.z, this.closestPointToPoint(s, e);
1739
+ const h = s.distanceToSquared(e);
1740
+ if (h < y && (y = h, a && a.copy(e), d && d.copy(s), h < f))
1741
+ return Math.sqrt(h);
1742
+ }
1743
+ for (let x = 0; x < 12; x++) {
1744
+ const b = t[x];
1745
+ for (let m = 0; m < 12; m++) {
1746
+ const h = i[m];
1747
+ oi(b, h, e, s);
1748
+ const w = e.distanceToSquared(s);
1749
+ if (w < y && (y = w, a && a.copy(e), d && d.copy(s), w < f))
1750
+ return Math.sqrt(w);
1751
+ }
1752
+ }
1753
+ return Math.sqrt(y);
1754
+ };
1755
+ }();
1756
+ class vs extends ni {
1757
+ constructor() {
1758
+ super(() => new ot());
1759
+ }
1760
+ }
1761
+ const et = /* @__PURE__ */ new vs(), Nt = /* @__PURE__ */ new U(), Ue = /* @__PURE__ */ new U();
1762
+ function Ms(n, t, i = {}, e = 0, s = 1 / 0) {
1763
+ const r = e * e, o = s * s;
1764
+ let l = 1 / 0, a = null;
1765
+ if (n.shapecast(
1766
+ {
1767
+ boundsTraverseOrder: (f) => (Nt.copy(t).clamp(f.min, f.max), Nt.distanceToSquared(t)),
1768
+ intersectsBounds: (f, p, c) => c < l && c < o,
1769
+ intersectsTriangle: (f, p) => {
1770
+ f.closestPointToPoint(t, Nt);
1771
+ const c = t.distanceToSquared(Nt);
1772
+ return c < l && (Ue.copy(Nt), l = c, a = p), c < r;
1773
+ }
1774
+ }
1775
+ ), l === 1 / 0) return null;
1776
+ const d = Math.sqrt(l);
1777
+ return i.point ? i.point.copy(Ue) : i.point = Ue.clone(), i.distance = d, i.faceIndex = a, i;
1778
+ }
1779
+ const ne = parseInt(Hi) >= 169, Ps = parseInt(Hi) <= 161, bt = /* @__PURE__ */ new U(), xt = /* @__PURE__ */ new U(), At = /* @__PURE__ */ new U(), se = /* @__PURE__ */ new yt(), oe = /* @__PURE__ */ new yt(), re = /* @__PURE__ */ new yt(), Ei = /* @__PURE__ */ new U(), Ui = /* @__PURE__ */ new U(), zi = /* @__PURE__ */ new U(), qt = /* @__PURE__ */ new U();
1780
+ function Ss(n, t, i, e, s, r, o, l) {
1781
+ let a;
1782
+ if (r === Rn ? a = n.intersectTriangle(e, i, t, !0, s) : a = n.intersectTriangle(t, i, e, r !== Bn, s), a === null) return null;
1783
+ const d = n.origin.distanceTo(s);
1784
+ return d < o || d > l ? null : {
1785
+ distance: d,
1786
+ point: s.clone()
1787
+ };
1788
+ }
1789
+ function $i(n, t, i, e, s, r, o, l, a, d, f) {
1790
+ bt.fromBufferAttribute(t, r), xt.fromBufferAttribute(t, o), At.fromBufferAttribute(t, l);
1791
+ const p = Ss(n, bt, xt, At, qt, a, d, f);
1792
+ if (p) {
1793
+ if (e) {
1794
+ se.fromBufferAttribute(e, r), oe.fromBufferAttribute(e, o), re.fromBufferAttribute(e, l), p.uv = new yt();
1795
+ const u = Ft.getInterpolation(qt, bt, xt, At, se, oe, re, p.uv);
1796
+ ne || (p.uv = u);
1797
+ }
1798
+ if (s) {
1799
+ se.fromBufferAttribute(s, r), oe.fromBufferAttribute(s, o), re.fromBufferAttribute(s, l), p.uv1 = new yt();
1800
+ const u = Ft.getInterpolation(qt, bt, xt, At, se, oe, re, p.uv1);
1801
+ ne || (p.uv1 = u), Ps && (p.uv2 = p.uv1);
1802
+ }
1803
+ if (i) {
1804
+ Ei.fromBufferAttribute(i, r), Ui.fromBufferAttribute(i, o), zi.fromBufferAttribute(i, l), p.normal = new U();
1805
+ const u = Ft.getInterpolation(qt, bt, xt, At, Ei, Ui, zi, p.normal);
1806
+ p.normal.dot(n.direction) > 0 && p.normal.multiplyScalar(-1), ne || (p.normal = u);
1807
+ }
1808
+ const c = {
1809
+ a: r,
1810
+ b: o,
1811
+ c: l,
1812
+ normal: new U(),
1813
+ materialIndex: 0
1814
+ };
1815
+ if (Ft.getNormal(bt, xt, At, c.normal), p.face = c, p.faceIndex = r, ne) {
1816
+ const u = new U();
1817
+ Ft.getBarycoord(qt, bt, xt, At, u), p.barycoord = u;
1818
+ }
1819
+ }
1820
+ return p;
1821
+ }
1822
+ function Fi(n) {
1823
+ return n && n.isMaterial ? n.side : n;
1824
+ }
1825
+ function Me(n, t, i, e, s, r, o) {
1826
+ const l = e * 3;
1827
+ let a = l + 0, d = l + 1, f = l + 2;
1828
+ const { index: p, groups: c } = n;
1829
+ n.index && (a = p.getX(a), d = p.getX(d), f = p.getX(f));
1830
+ const { position: u, normal: y, uv: g, uv1: x } = n.attributes;
1831
+ if (Array.isArray(t)) {
1832
+ const b = e * 3;
1833
+ for (let m = 0, h = c.length; m < h; m++) {
1834
+ const { start: w, count: A, materialIndex: P } = c[m];
1835
+ if (b >= w && b < w + A) {
1836
+ const v = Fi(t[P]), T = $i(i, u, y, g, x, a, d, f, v, r, o);
1837
+ if (T)
1838
+ if (T.faceIndex = e, T.face.materialIndex = P, s)
1839
+ s.push(T);
1840
+ else
1841
+ return T;
1842
+ }
1843
+ }
1844
+ } else {
1845
+ const b = Fi(t), m = $i(i, u, y, g, x, a, d, f, b, r, o);
1846
+ if (m)
1847
+ if (m.faceIndex = e, m.face.materialIndex = 0, s)
1848
+ s.push(m);
1849
+ else
1850
+ return m;
1851
+ }
1852
+ return null;
1853
+ }
1854
+ function j(n, t, i, e) {
1855
+ const s = n.a, r = n.b, o = n.c;
1856
+ let l = t, a = t + 1, d = t + 2;
1857
+ i && (l = i.getX(l), a = i.getX(a), d = i.getX(d)), s.x = e.getX(l), s.y = e.getY(l), s.z = e.getZ(l), r.x = e.getX(a), r.y = e.getY(a), r.z = e.getZ(a), o.x = e.getX(d), o.y = e.getY(d), o.z = e.getZ(d);
1858
+ }
1859
+ function Ts(n, t, i, e, s, r, o, l) {
1860
+ const { geometry: a, _indirectBuffer: d } = n;
1861
+ for (let f = e, p = e + s; f < p; f++)
1862
+ Me(a, t, i, f, r, o, l);
1863
+ }
1864
+ function Rs(n, t, i, e, s, r, o) {
1865
+ const { geometry: l, _indirectBuffer: a } = n;
1866
+ let d = 1 / 0, f = null;
1867
+ for (let p = e, c = e + s; p < c; p++) {
1868
+ let u;
1869
+ u = Me(l, t, i, p, null, r, o), u && u.distance < d && (f = u, d = u.distance);
1870
+ }
1871
+ return f;
1872
+ }
1873
+ function Bs(n, t, i, e, s, r, o) {
1874
+ const { geometry: l } = i, { index: a } = l, d = l.attributes.position;
1875
+ for (let f = n, p = t + n; f < p; f++) {
1876
+ let c;
1877
+ if (c = f, j(o, c * 3, a, d), o.needsUpdate = !0, e(o, c, s, r))
1878
+ return !0;
1879
+ }
1880
+ return !1;
1881
+ }
1882
+ function _s(n, t = null) {
1883
+ t && Array.isArray(t) && (t = new Set(t));
1884
+ const i = n.geometry, e = i.index ? i.index.array : null, s = i.attributes.position;
1885
+ let r, o, l, a, d = 0;
1886
+ const f = n._roots;
1887
+ for (let c = 0, u = f.length; c < u; c++)
1888
+ r = f[c], o = new Uint32Array(r), l = new Uint16Array(r), a = new Float32Array(r), p(0, d), d += r.byteLength;
1889
+ function p(c, u, y = !1) {
1890
+ const g = c * 2;
1891
+ if (q(g, l)) {
1892
+ const x = J(c, o), b = H(g, l);
1893
+ let m = 1 / 0, h = 1 / 0, w = 1 / 0, A = -1 / 0, P = -1 / 0, v = -1 / 0;
1894
+ for (let T = 3 * x, R = 3 * (x + b); T < R; T++) {
1895
+ let M = e[T];
1896
+ const B = s.getX(M), S = s.getY(M), _ = s.getZ(M);
1897
+ B < m && (m = B), B > A && (A = B), S < h && (h = S), S > P && (P = S), _ < w && (w = _), _ > v && (v = _);
1898
+ }
1899
+ return a[c + 0] !== m || a[c + 1] !== h || a[c + 2] !== w || a[c + 3] !== A || a[c + 4] !== P || a[c + 5] !== v ? (a[c + 0] = m, a[c + 1] = h, a[c + 2] = w, a[c + 3] = A, a[c + 4] = P, a[c + 5] = v, !0) : !1;
1900
+ } else {
1901
+ const x = V(c), b = W(c, o);
1902
+ let m = y, h = !1, w = !1;
1903
+ if (t) {
1904
+ if (!m) {
1905
+ const M = x / N + u / X, B = b / N + u / X;
1906
+ h = t.has(M), w = t.has(B), m = !h && !w;
1907
+ }
1908
+ } else
1909
+ h = !0, w = !0;
1910
+ const A = m || h, P = m || w;
1911
+ let v = !1;
1912
+ A && (v = p(x, u, m));
1913
+ let T = !1;
1914
+ P && (T = p(b, u, m));
1915
+ const R = v || T;
1916
+ if (R)
1917
+ for (let M = 0; M < 3; M++) {
1918
+ const B = x + M, S = b + M, _ = a[B], E = a[B + 3], $ = a[S], D = a[S + 3];
1919
+ a[c + M] = _ < $ ? _ : $, a[c + M + 3] = E > D ? E : D;
1920
+ }
1921
+ return R;
1922
+ }
1923
+ }
1924
+ }
1925
+ function gt(n, t, i, e, s) {
1926
+ let r, o, l, a, d, f;
1927
+ const p = 1 / i.direction.x, c = 1 / i.direction.y, u = 1 / i.direction.z, y = i.origin.x, g = i.origin.y, x = i.origin.z;
1928
+ let b = t[n], m = t[n + 3], h = t[n + 1], w = t[n + 3 + 1], A = t[n + 2], P = t[n + 3 + 2];
1929
+ return p >= 0 ? (r = (b - y) * p, o = (m - y) * p) : (r = (m - y) * p, o = (b - y) * p), c >= 0 ? (l = (h - g) * c, a = (w - g) * c) : (l = (w - g) * c, a = (h - g) * c), r > a || l > o || ((l > r || isNaN(r)) && (r = l), (a < o || isNaN(o)) && (o = a), u >= 0 ? (d = (A - x) * u, f = (P - x) * u) : (d = (P - x) * u, f = (A - x) * u), r > f || d > o) ? !1 : ((d > r || r !== r) && (r = d), (f < o || o !== o) && (o = f), r <= s && o >= e);
1930
+ }
1931
+ function Es(n, t, i, e, s, r, o, l) {
1932
+ const { geometry: a, _indirectBuffer: d } = n;
1933
+ for (let f = e, p = e + s; f < p; f++) {
1934
+ let c = d ? d[f] : f;
1935
+ Me(a, t, i, c, r, o, l);
1936
+ }
1937
+ }
1938
+ function Us(n, t, i, e, s, r, o) {
1939
+ const { geometry: l, _indirectBuffer: a } = n;
1940
+ let d = 1 / 0, f = null;
1941
+ for (let p = e, c = e + s; p < c; p++) {
1942
+ let u;
1943
+ u = Me(l, t, i, a ? a[p] : p, null, r, o), u && u.distance < d && (f = u, d = u.distance);
1944
+ }
1945
+ return f;
1946
+ }
1947
+ function zs(n, t, i, e, s, r, o) {
1948
+ const { geometry: l } = i, { index: a } = l, d = l.attributes.position;
1949
+ for (let f = n, p = t + n; f < p; f++) {
1950
+ let c;
1951
+ if (c = i.resolveTriangleIndex(f), j(o, c * 3, a, d), o.needsUpdate = !0, e(o, c, s, r))
1952
+ return !0;
1953
+ }
1954
+ return !1;
1955
+ }
1956
+ function $s(n, t, i, e, s, r, o) {
1957
+ I.setBuffer(n._roots[t]), Oe(0, n, i, e, s, r, o), I.clearBuffer();
1958
+ }
1959
+ function Oe(n, t, i, e, s, r, o) {
1960
+ const { float32Array: l, uint16Array: a, uint32Array: d } = I, f = n * 2;
1961
+ if (q(f, a)) {
1962
+ const c = J(n, d), u = H(f, a);
1963
+ Ts(t, i, e, c, u, s, r, o);
1964
+ } else {
1965
+ const c = V(n);
1966
+ gt(c, l, e, r, o) && Oe(c, t, i, e, s, r, o);
1967
+ const u = W(n, d);
1968
+ gt(u, l, e, r, o) && Oe(u, t, i, e, s, r, o);
1969
+ }
1970
+ }
1971
+ const Fs = ["x", "y", "z"];
1972
+ function Is(n, t, i, e, s, r) {
1973
+ I.setBuffer(n._roots[t]);
1974
+ const o = Ve(0, n, i, e, s, r);
1975
+ return I.clearBuffer(), o;
1976
+ }
1977
+ function Ve(n, t, i, e, s, r) {
1978
+ const { float32Array: o, uint16Array: l, uint32Array: a } = I;
1979
+ let d = n * 2;
1980
+ if (q(d, l)) {
1981
+ const p = J(n, a), c = H(d, l);
1982
+ return Rs(t, i, e, p, c, s, r);
1983
+ } else {
1984
+ const p = ii(n, a), c = Fs[p], y = e.direction[c] >= 0;
1985
+ let g, x;
1986
+ y ? (g = V(n), x = W(n, a)) : (g = W(n, a), x = V(n));
1987
+ const m = gt(g, o, e, s, r) ? Ve(g, t, i, e, s, r) : null;
1988
+ if (m) {
1989
+ const A = m.point[c];
1990
+ if (y ? A <= o[x + p] : (
1991
+ // min bounding data
1992
+ A >= o[x + p + 3]
1993
+ ))
1994
+ return m;
1995
+ }
1996
+ const w = gt(x, o, e, s, r) ? Ve(x, t, i, e, s, r) : null;
1997
+ return m && w ? m.distance <= w.distance ? m : w : m || w || null;
1998
+ }
1999
+ }
2000
+ const ae = /* @__PURE__ */ new it(), Et = /* @__PURE__ */ new ot(), Ut = /* @__PURE__ */ new ot(), Ot = /* @__PURE__ */ new Z(), Ii = /* @__PURE__ */ new Q(), ce = /* @__PURE__ */ new Q();
2001
+ function Ds(n, t, i, e) {
2002
+ I.setBuffer(n._roots[t]);
2003
+ const s = We(0, n, i, e);
2004
+ return I.clearBuffer(), s;
2005
+ }
2006
+ function We(n, t, i, e, s = null) {
2007
+ const { float32Array: r, uint16Array: o, uint32Array: l } = I;
2008
+ let a = n * 2;
2009
+ if (s === null && (i.boundingBox || i.computeBoundingBox(), Ii.set(i.boundingBox.min, i.boundingBox.max, e), s = Ii), q(a, o)) {
2010
+ const f = t.geometry, p = f.index, c = f.attributes.position, u = i.index, y = i.attributes.position, g = J(n, l), x = H(a, o);
2011
+ if (Ot.copy(e).invert(), i.boundsTree)
2012
+ return k(n, r, ce), ce.matrix.copy(Ot), ce.needsUpdate = !0, i.boundsTree.shapecast({
2013
+ intersectsBounds: (m) => ce.intersectsBox(m),
2014
+ intersectsTriangle: (m) => {
2015
+ m.a.applyMatrix4(e), m.b.applyMatrix4(e), m.c.applyMatrix4(e), m.needsUpdate = !0;
2016
+ for (let h = g * 3, w = (x + g) * 3; h < w; h += 3)
2017
+ if (j(Ut, h, p, c), Ut.needsUpdate = !0, m.intersectsTriangle(Ut))
2018
+ return !0;
2019
+ return !1;
2020
+ }
2021
+ });
2022
+ {
2023
+ const b = ve(i);
2024
+ for (let m = g * 3, h = (x + g) * 3; m < h; m += 3) {
2025
+ j(Et, m, p, c), Et.a.applyMatrix4(Ot), Et.b.applyMatrix4(Ot), Et.c.applyMatrix4(Ot), Et.needsUpdate = !0;
2026
+ for (let w = 0, A = b * 3; w < A; w += 3)
2027
+ if (j(Ut, w, u, y), Ut.needsUpdate = !0, Et.intersectsTriangle(Ut))
2028
+ return !0;
2029
+ }
2030
+ }
2031
+ } else {
2032
+ const f = V(n), p = W(n, l);
2033
+ return k(f, r, ae), !!(s.intersectsBox(ae) && We(f, t, i, e, s) || (k(p, r, ae), s.intersectsBox(ae) && We(p, t, i, e, s)));
2034
+ }
2035
+ }
2036
+ const le = /* @__PURE__ */ new Z(), ze = /* @__PURE__ */ new Q(), Vt = /* @__PURE__ */ new Q(), Ls = /* @__PURE__ */ new U(), ks = /* @__PURE__ */ new U(), js = /* @__PURE__ */ new U(), Cs = /* @__PURE__ */ new U();
2037
+ function Ns(n, t, i, e = {}, s = {}, r = 0, o = 1 / 0) {
2038
+ t.boundingBox || t.computeBoundingBox(), ze.set(t.boundingBox.min, t.boundingBox.max, i), ze.needsUpdate = !0;
2039
+ const l = n.geometry, a = l.attributes.position, d = l.index, f = t.attributes.position, p = t.index, c = et.getPrimitive(), u = et.getPrimitive();
2040
+ let y = Ls, g = ks, x = null, b = null;
2041
+ s && (x = js, b = Cs);
2042
+ let m = 1 / 0, h = null, w = null;
2043
+ return le.copy(i).invert(), Vt.matrix.copy(le), n.shapecast(
2044
+ {
2045
+ boundsTraverseOrder: (A) => ze.distanceToBox(A),
2046
+ intersectsBounds: (A, P, v) => v < m && v < o ? (P && (Vt.min.copy(A.min), Vt.max.copy(A.max), Vt.needsUpdate = !0), !0) : !1,
2047
+ intersectsRange: (A, P) => {
2048
+ if (t.boundsTree)
2049
+ return t.boundsTree.shapecast({
2050
+ boundsTraverseOrder: (T) => Vt.distanceToBox(T),
2051
+ intersectsBounds: (T, R, M) => M < m && M < o,
2052
+ intersectsRange: (T, R) => {
2053
+ for (let M = T, B = T + R; M < B; M++) {
2054
+ j(u, 3 * M, p, f), u.a.applyMatrix4(i), u.b.applyMatrix4(i), u.c.applyMatrix4(i), u.needsUpdate = !0;
2055
+ for (let S = A, _ = A + P; S < _; S++) {
2056
+ j(c, 3 * S, d, a), c.needsUpdate = !0;
2057
+ const E = c.distanceToTriangle(u, y, x);
2058
+ if (E < m && (g.copy(y), b && b.copy(x), m = E, h = S, w = M), E < r)
2059
+ return !0;
2060
+ }
2061
+ }
2062
+ }
2063
+ });
2064
+ {
2065
+ const v = ve(t);
2066
+ for (let T = 0, R = v; T < R; T++) {
2067
+ j(u, 3 * T, p, f), u.a.applyMatrix4(i), u.b.applyMatrix4(i), u.c.applyMatrix4(i), u.needsUpdate = !0;
2068
+ for (let M = A, B = A + P; M < B; M++) {
2069
+ j(c, 3 * M, d, a), c.needsUpdate = !0;
2070
+ const S = c.distanceToTriangle(u, y, x);
2071
+ if (S < m && (g.copy(y), b && b.copy(x), m = S, h = M, w = T), S < r)
2072
+ return !0;
2073
+ }
2074
+ }
2075
+ }
2076
+ }
2077
+ }
2078
+ ), et.releasePrimitive(c), et.releasePrimitive(u), m === 1 / 0 ? null : (e.point ? e.point.copy(g) : e.point = g.clone(), e.distance = m, e.faceIndex = h, s && (s.point ? s.point.copy(b) : s.point = b.clone(), s.point.applyMatrix4(le), g.applyMatrix4(le), s.distance = g.sub(s.point).length(), s.faceIndex = w), e);
2079
+ }
2080
+ function qs(n, t = null) {
2081
+ t && Array.isArray(t) && (t = new Set(t));
2082
+ const i = n.geometry, e = i.index ? i.index.array : null, s = i.attributes.position;
2083
+ let r, o, l, a, d = 0;
2084
+ const f = n._roots;
2085
+ for (let c = 0, u = f.length; c < u; c++)
2086
+ r = f[c], o = new Uint32Array(r), l = new Uint16Array(r), a = new Float32Array(r), p(0, d), d += r.byteLength;
2087
+ function p(c, u, y = !1) {
2088
+ const g = c * 2;
2089
+ if (q(g, l)) {
2090
+ const x = J(c, o), b = H(g, l);
2091
+ let m = 1 / 0, h = 1 / 0, w = 1 / 0, A = -1 / 0, P = -1 / 0, v = -1 / 0;
2092
+ for (let T = x, R = x + b; T < R; T++) {
2093
+ const M = 3 * n.resolveTriangleIndex(T);
2094
+ for (let B = 0; B < 3; B++) {
2095
+ let S = M + B;
2096
+ S = e ? e[S] : S;
2097
+ const _ = s.getX(S), E = s.getY(S), $ = s.getZ(S);
2098
+ _ < m && (m = _), _ > A && (A = _), E < h && (h = E), E > P && (P = E), $ < w && (w = $), $ > v && (v = $);
2099
+ }
2100
+ }
2101
+ return a[c + 0] !== m || a[c + 1] !== h || a[c + 2] !== w || a[c + 3] !== A || a[c + 4] !== P || a[c + 5] !== v ? (a[c + 0] = m, a[c + 1] = h, a[c + 2] = w, a[c + 3] = A, a[c + 4] = P, a[c + 5] = v, !0) : !1;
2102
+ } else {
2103
+ const x = V(c), b = W(c, o);
2104
+ let m = y, h = !1, w = !1;
2105
+ if (t) {
2106
+ if (!m) {
2107
+ const M = x / N + u / X, B = b / N + u / X;
2108
+ h = t.has(M), w = t.has(B), m = !h && !w;
2109
+ }
2110
+ } else
2111
+ h = !0, w = !0;
2112
+ const A = m || h, P = m || w;
2113
+ let v = !1;
2114
+ A && (v = p(x, u, m));
2115
+ let T = !1;
2116
+ P && (T = p(b, u, m));
2117
+ const R = v || T;
2118
+ if (R)
2119
+ for (let M = 0; M < 3; M++) {
2120
+ const B = x + M, S = b + M, _ = a[B], E = a[B + 3], $ = a[S], D = a[S + 3];
2121
+ a[c + M] = _ < $ ? _ : $, a[c + M + 3] = E > D ? E : D;
2122
+ }
2123
+ return R;
2124
+ }
2125
+ }
2126
+ }
2127
+ function Os(n, t, i, e, s, r, o) {
2128
+ I.setBuffer(n._roots[t]), Ge(0, n, i, e, s, r, o), I.clearBuffer();
2129
+ }
2130
+ function Ge(n, t, i, e, s, r, o) {
2131
+ const { float32Array: l, uint16Array: a, uint32Array: d } = I, f = n * 2;
2132
+ if (q(f, a)) {
2133
+ const c = J(n, d), u = H(f, a);
2134
+ Es(t, i, e, c, u, s, r, o);
2135
+ } else {
2136
+ const c = V(n);
2137
+ gt(c, l, e, r, o) && Ge(c, t, i, e, s, r, o);
2138
+ const u = W(n, d);
2139
+ gt(u, l, e, r, o) && Ge(u, t, i, e, s, r, o);
2140
+ }
2141
+ }
2142
+ const Vs = ["x", "y", "z"];
2143
+ function Ws(n, t, i, e, s, r) {
2144
+ I.setBuffer(n._roots[t]);
2145
+ const o = Xe(0, n, i, e, s, r);
2146
+ return I.clearBuffer(), o;
2147
+ }
2148
+ function Xe(n, t, i, e, s, r) {
2149
+ const { float32Array: o, uint16Array: l, uint32Array: a } = I;
2150
+ let d = n * 2;
2151
+ if (q(d, l)) {
2152
+ const p = J(n, a), c = H(d, l);
2153
+ return Us(t, i, e, p, c, s, r);
2154
+ } else {
2155
+ const p = ii(n, a), c = Vs[p], y = e.direction[c] >= 0;
2156
+ let g, x;
2157
+ y ? (g = V(n), x = W(n, a)) : (g = W(n, a), x = V(n));
2158
+ const m = gt(g, o, e, s, r) ? Xe(g, t, i, e, s, r) : null;
2159
+ if (m) {
2160
+ const A = m.point[c];
2161
+ if (y ? A <= o[x + p] : (
2162
+ // min bounding data
2163
+ A >= o[x + p + 3]
2164
+ ))
2165
+ return m;
2166
+ }
2167
+ const w = gt(x, o, e, s, r) ? Xe(x, t, i, e, s, r) : null;
2168
+ return m && w ? m.distance <= w.distance ? m : w : m || w || null;
2169
+ }
2170
+ }
2171
+ const ue = /* @__PURE__ */ new it(), zt = /* @__PURE__ */ new ot(), $t = /* @__PURE__ */ new ot(), Wt = /* @__PURE__ */ new Z(), Di = /* @__PURE__ */ new Q(), fe = /* @__PURE__ */ new Q();
2172
+ function Gs(n, t, i, e) {
2173
+ I.setBuffer(n._roots[t]);
2174
+ const s = Je(0, n, i, e);
2175
+ return I.clearBuffer(), s;
2176
+ }
2177
+ function Je(n, t, i, e, s = null) {
2178
+ const { float32Array: r, uint16Array: o, uint32Array: l } = I;
2179
+ let a = n * 2;
2180
+ if (s === null && (i.boundingBox || i.computeBoundingBox(), Di.set(i.boundingBox.min, i.boundingBox.max, e), s = Di), q(a, o)) {
2181
+ const f = t.geometry, p = f.index, c = f.attributes.position, u = i.index, y = i.attributes.position, g = J(n, l), x = H(a, o);
2182
+ if (Wt.copy(e).invert(), i.boundsTree)
2183
+ return k(n, r, fe), fe.matrix.copy(Wt), fe.needsUpdate = !0, i.boundsTree.shapecast({
2184
+ intersectsBounds: (m) => fe.intersectsBox(m),
2185
+ intersectsTriangle: (m) => {
2186
+ m.a.applyMatrix4(e), m.b.applyMatrix4(e), m.c.applyMatrix4(e), m.needsUpdate = !0;
2187
+ for (let h = g, w = x + g; h < w; h++)
2188
+ if (j($t, 3 * t.resolveTriangleIndex(h), p, c), $t.needsUpdate = !0, m.intersectsTriangle($t))
2189
+ return !0;
2190
+ return !1;
2191
+ }
2192
+ });
2193
+ {
2194
+ const b = ve(i);
2195
+ for (let m = g, h = x + g; m < h; m++) {
2196
+ const w = t.resolveTriangleIndex(m);
2197
+ j(zt, 3 * w, p, c), zt.a.applyMatrix4(Wt), zt.b.applyMatrix4(Wt), zt.c.applyMatrix4(Wt), zt.needsUpdate = !0;
2198
+ for (let A = 0, P = b * 3; A < P; A += 3)
2199
+ if (j($t, A, u, y), $t.needsUpdate = !0, zt.intersectsTriangle($t))
2200
+ return !0;
2201
+ }
2202
+ }
2203
+ } else {
2204
+ const f = V(n), p = W(n, l);
2205
+ return k(f, r, ue), !!(s.intersectsBox(ue) && Je(f, t, i, e, s) || (k(p, r, ue), s.intersectsBox(ue) && Je(p, t, i, e, s)));
2206
+ }
2207
+ }
2208
+ const de = /* @__PURE__ */ new Z(), $e = /* @__PURE__ */ new Q(), Gt = /* @__PURE__ */ new Q(), Xs = /* @__PURE__ */ new U(), Js = /* @__PURE__ */ new U(), Hs = /* @__PURE__ */ new U(), Zs = /* @__PURE__ */ new U();
2209
+ function Qs(n, t, i, e = {}, s = {}, r = 0, o = 1 / 0) {
2210
+ t.boundingBox || t.computeBoundingBox(), $e.set(t.boundingBox.min, t.boundingBox.max, i), $e.needsUpdate = !0;
2211
+ const l = n.geometry, a = l.attributes.position, d = l.index, f = t.attributes.position, p = t.index, c = et.getPrimitive(), u = et.getPrimitive();
2212
+ let y = Xs, g = Js, x = null, b = null;
2213
+ s && (x = Hs, b = Zs);
2214
+ let m = 1 / 0, h = null, w = null;
2215
+ return de.copy(i).invert(), Gt.matrix.copy(de), n.shapecast(
2216
+ {
2217
+ boundsTraverseOrder: (A) => $e.distanceToBox(A),
2218
+ intersectsBounds: (A, P, v) => v < m && v < o ? (P && (Gt.min.copy(A.min), Gt.max.copy(A.max), Gt.needsUpdate = !0), !0) : !1,
2219
+ intersectsRange: (A, P) => {
2220
+ if (t.boundsTree) {
2221
+ const v = t.boundsTree;
2222
+ return v.shapecast({
2223
+ boundsTraverseOrder: (T) => Gt.distanceToBox(T),
2224
+ intersectsBounds: (T, R, M) => M < m && M < o,
2225
+ intersectsRange: (T, R) => {
2226
+ for (let M = T, B = T + R; M < B; M++) {
2227
+ const S = v.resolveTriangleIndex(M);
2228
+ j(u, 3 * S, p, f), u.a.applyMatrix4(i), u.b.applyMatrix4(i), u.c.applyMatrix4(i), u.needsUpdate = !0;
2229
+ for (let _ = A, E = A + P; _ < E; _++) {
2230
+ const $ = n.resolveTriangleIndex(_);
2231
+ j(c, 3 * $, d, a), c.needsUpdate = !0;
2232
+ const D = c.distanceToTriangle(u, y, x);
2233
+ if (D < m && (g.copy(y), b && b.copy(x), m = D, h = _, w = M), D < r)
2234
+ return !0;
2235
+ }
2236
+ }
2237
+ }
2238
+ });
2239
+ } else {
2240
+ const v = ve(t);
2241
+ for (let T = 0, R = v; T < R; T++) {
2242
+ j(u, 3 * T, p, f), u.a.applyMatrix4(i), u.b.applyMatrix4(i), u.c.applyMatrix4(i), u.needsUpdate = !0;
2243
+ for (let M = A, B = A + P; M < B; M++) {
2244
+ const S = n.resolveTriangleIndex(M);
2245
+ j(c, 3 * S, d, a), c.needsUpdate = !0;
2246
+ const _ = c.distanceToTriangle(u, y, x);
2247
+ if (_ < m && (g.copy(y), b && b.copy(x), m = _, h = M, w = T), _ < r)
2248
+ return !0;
2249
+ }
2250
+ }
2251
+ }
2252
+ }
2253
+ }
2254
+ ), et.releasePrimitive(c), et.releasePrimitive(u), m === 1 / 0 ? null : (e.point ? e.point.copy(g) : e.point = g.clone(), e.distance = m, e.faceIndex = h, s && (s.point ? s.point.copy(b) : s.point = b.clone(), s.point.applyMatrix4(de), g.applyMatrix4(de), s.distance = g.sub(s.point).length(), s.faceIndex = w), e);
2255
+ }
2256
+ function Li(n, t, i) {
2257
+ return n === null ? null : (n.point.applyMatrix4(t.matrixWorld), n.distance = n.point.distanceTo(i.ray.origin), n.object = t, n);
2258
+ }
2259
+ const pe = /* @__PURE__ */ new Q(), me = /* @__PURE__ */ new _n(), ki = /* @__PURE__ */ new U(), ji = /* @__PURE__ */ new Z(), Ci = /* @__PURE__ */ new U(), Fe = ["getX", "getY", "getZ"];
2260
+ class xe extends ws {
2261
+ static serialize(t, i = {}) {
2262
+ i = {
2263
+ cloneBuffers: !0,
2264
+ ...i
2265
+ };
2266
+ const e = t.geometry, s = t._roots, r = t._indirectBuffer, o = e.getIndex(), l = {
2267
+ version: 1,
2268
+ roots: null,
2269
+ index: null,
2270
+ indirectBuffer: null
2271
+ };
2272
+ return i.cloneBuffers ? (l.roots = s.map((a) => a.slice()), l.index = o ? o.array.slice() : null, l.indirectBuffer = r ? r.slice() : null) : (l.roots = s, l.index = o ? o.array : null, l.indirectBuffer = r), l;
2273
+ }
2274
+ static deserialize(t, i, e = {}) {
2275
+ e = {
2276
+ setIndex: !0,
2277
+ indirect: !!t.indirectBuffer,
2278
+ ...e
2279
+ };
2280
+ const { index: s, roots: r, indirectBuffer: o } = t;
2281
+ t.version || (console.warn(
2282
+ "MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."
2283
+ ), a(r));
2284
+ const l = new xe(i, { ...e, [ei]: !0 });
2285
+ if (l._roots = r, l._indirectBuffer = o || null, e.setIndex) {
2286
+ const d = i.getIndex();
2287
+ if (d === null) {
2288
+ const f = new Xi(t.index, 1, !1);
2289
+ i.setIndex(f);
2290
+ } else d.array !== s && (d.array.set(s), d.needsUpdate = !0);
2291
+ }
2292
+ return l;
2293
+ function a(d) {
2294
+ for (let f = 0; f < d.length; f++) {
2295
+ const p = d[f], c = new Uint32Array(p), u = new Uint16Array(p);
2296
+ for (let y = 0, g = p.byteLength / X; y < g; y++) {
2297
+ const x = N * y, b = 2 * x;
2298
+ q(b, u) || (c[x + 6] = c[x + 6] / N - y);
2299
+ }
2300
+ }
2301
+ }
2302
+ }
2303
+ get primitiveStride() {
2304
+ return 3;
2305
+ }
2306
+ get resolveTriangleIndex() {
2307
+ return this.resolvePrimitiveIndex;
2308
+ }
2309
+ constructor(t, i = {}) {
2310
+ i.maxLeafTris && (console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'), i = {
2311
+ ...i,
2312
+ maxLeafSize: i.maxLeafTris
2313
+ }), super(t, i);
2314
+ }
2315
+ // implement abstract methods from BVH base class
2316
+ shiftTriangleOffsets(t) {
2317
+ return super.shiftPrimitiveOffsets(t);
2318
+ }
2319
+ // write primitive bounds to the buffer - used only for validateBounds at the moment
2320
+ writePrimitiveBounds(t, i, e) {
2321
+ const s = this.geometry, r = this._indirectBuffer, o = s.attributes.position, l = s.index ? s.index.array : null, d = (r ? r[t] : t) * 3;
2322
+ let f = d + 0, p = d + 1, c = d + 2;
2323
+ l && (f = l[f], p = l[p], c = l[c]);
2324
+ for (let u = 0; u < 3; u++) {
2325
+ const y = o[Fe[u]](f), g = o[Fe[u]](p), x = o[Fe[u]](c);
2326
+ let b = y;
2327
+ g < b && (b = g), x < b && (b = x);
2328
+ let m = y;
2329
+ g > m && (m = g), x > m && (m = x), i[e + u] = b, i[e + u + 3] = m;
2330
+ }
2331
+ return i;
2332
+ }
2333
+ // precomputes the bounding box for each triangle; required for quickly calculating tree splits.
2334
+ // result is an array of size count * 6 where triangle i maps to a
2335
+ // [x_center, x_delta, y_center, y_delta, z_center, z_delta] tuple starting at index (i - offset) * 6,
2336
+ // representing the center and half-extent in each dimension of triangle i
2337
+ computePrimitiveBounds(t, i, e) {
2338
+ const s = this.geometry, r = this._indirectBuffer, o = s.attributes.position, l = s.index ? s.index.array : null, a = o.normalized;
2339
+ if (t < 0 || i + t - e.offset > e.length / 6)
2340
+ throw new Error("MeshBVH: compute triangle bounds range is invalid.");
2341
+ const d = o.array, f = o.offset || 0;
2342
+ let p = 3;
2343
+ o.isInterleavedBufferAttribute && (p = o.data.stride);
2344
+ const c = ["getX", "getY", "getZ"], u = e.offset;
2345
+ for (let y = t, g = t + i; y < g; y++) {
2346
+ const b = (r ? r[y] : y) * 3, m = (y - u) * 6;
2347
+ let h = b + 0, w = b + 1, A = b + 2;
2348
+ l && (h = l[h], w = l[w], A = l[A]), a || (h = h * p + f, w = w * p + f, A = A * p + f);
2349
+ for (let P = 0; P < 3; P++) {
2350
+ let v, T, R;
2351
+ a ? (v = o[c[P]](h), T = o[c[P]](w), R = o[c[P]](A)) : (v = d[h + P], T = d[w + P], R = d[A + P]);
2352
+ let M = v;
2353
+ T < M && (M = T), R < M && (M = R);
2354
+ let B = v;
2355
+ T > B && (B = T), R > B && (B = R);
2356
+ const S = (B - M) / 2, _ = P * 2;
2357
+ e[m + _ + 0] = M + S, e[m + _ + 1] = S + (Math.abs(M) + S) * ge;
2358
+ }
2359
+ }
2360
+ return e;
2361
+ }
2362
+ raycastObject3D(t, i, e = []) {
2363
+ const { material: s } = t;
2364
+ if (s === void 0)
2365
+ return;
2366
+ ji.copy(t.matrixWorld).invert(), me.copy(i.ray).applyMatrix4(ji), Ci.setFromMatrixScale(t.matrixWorld), ki.copy(me.direction).multiply(Ci);
2367
+ const r = ki.length(), o = i.near / r, l = i.far / r;
2368
+ if (i.firstHitOnly === !0) {
2369
+ let a = this.raycastFirst(me, s, o, l);
2370
+ a = Li(a, t, i), a && e.push(a);
2371
+ } else {
2372
+ const a = this.raycast(me, s, o, l);
2373
+ for (let d = 0, f = a.length; d < f; d++) {
2374
+ const p = Li(a[d], t, i);
2375
+ p && e.push(p);
2376
+ }
2377
+ }
2378
+ return e;
2379
+ }
2380
+ refit(t = null) {
2381
+ return (this.indirect ? qs : _s)(this, t);
2382
+ }
2383
+ /* Core Cast Functions */
2384
+ raycast(t, i = mi, e = 0, s = 1 / 0) {
2385
+ const r = this._roots, o = [], l = this.indirect ? Os : $s;
2386
+ for (let a = 0, d = r.length; a < d; a++)
2387
+ l(this, a, i, t, o, e, s);
2388
+ return o;
2389
+ }
2390
+ raycastFirst(t, i = mi, e = 0, s = 1 / 0) {
2391
+ const r = this._roots;
2392
+ let o = null;
2393
+ const l = this.indirect ? Ws : Is;
2394
+ for (let a = 0, d = r.length; a < d; a++) {
2395
+ const f = l(this, a, i, t, e, s);
2396
+ f != null && (o == null || f.distance < o.distance) && (o = f);
2397
+ }
2398
+ return o;
2399
+ }
2400
+ intersectsGeometry(t, i) {
2401
+ let e = !1;
2402
+ const s = this._roots, r = this.indirect ? Gs : Ds;
2403
+ for (let o = 0, l = s.length; o < l && (e = r(this, o, t, i), !e); o++)
2404
+ ;
2405
+ return e;
2406
+ }
2407
+ shapecast(t) {
2408
+ const i = et.getPrimitive(), e = super.shapecast(
2409
+ {
2410
+ ...t,
2411
+ intersectsPrimitive: t.intersectsTriangle,
2412
+ scratchPrimitive: i,
2413
+ // TODO: is the performance significant enough for the added complexity here?
2414
+ // can we just use one function?
2415
+ iterate: this.indirect ? zs : Bs
2416
+ }
2417
+ );
2418
+ return et.releasePrimitive(i), e;
2419
+ }
2420
+ bvhcast(t, i, e) {
2421
+ let {
2422
+ intersectsRanges: s,
2423
+ intersectsTriangles: r
2424
+ } = e;
2425
+ const o = et.getPrimitive(), l = this.geometry.index, a = this.geometry.attributes.position, d = this.indirect ? (y) => {
2426
+ const g = this.resolveTriangleIndex(y);
2427
+ j(o, g * 3, l, a);
2428
+ } : (y) => {
2429
+ j(o, y * 3, l, a);
2430
+ }, f = et.getPrimitive(), p = t.geometry.index, c = t.geometry.attributes.position, u = t.indirect ? (y) => {
2431
+ const g = t.resolveTriangleIndex(y);
2432
+ j(f, g * 3, p, c);
2433
+ } : (y) => {
2434
+ j(f, y * 3, p, c);
2435
+ };
2436
+ if (r) {
2437
+ if (!(t instanceof xe))
2438
+ throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');
2439
+ const y = (g, x, b, m, h, w, A, P) => {
2440
+ for (let v = b, T = b + m; v < T; v++) {
2441
+ u(v), f.a.applyMatrix4(i), f.b.applyMatrix4(i), f.c.applyMatrix4(i), f.needsUpdate = !0;
2442
+ for (let R = g, M = g + x; R < M; R++)
2443
+ if (d(R), o.needsUpdate = !0, r(o, f, R, v, h, w, A, P))
2444
+ return !0;
2445
+ }
2446
+ return !1;
2447
+ };
2448
+ if (s) {
2449
+ const g = s;
2450
+ s = function(x, b, m, h, w, A, P, v) {
2451
+ return g(x, b, m, h, w, A, P, v) ? !0 : y(x, b, m, h, w, A, P, v);
2452
+ };
2453
+ } else
2454
+ s = y;
2455
+ }
2456
+ return super.bvhcast(t, i, { intersectsRanges: s });
2457
+ }
2458
+ /* Derived Cast Functions */
2459
+ intersectsBox(t, i) {
2460
+ return pe.set(t.min, t.max, i), pe.needsUpdate = !0, this.shapecast(
2461
+ {
2462
+ intersectsBounds: (e) => pe.intersectsBox(e),
2463
+ intersectsTriangle: (e) => pe.intersectsTriangle(e)
2464
+ }
2465
+ );
2466
+ }
2467
+ intersectsSphere(t) {
2468
+ return this.shapecast(
2469
+ {
2470
+ intersectsBounds: (i) => t.intersectsBox(i),
2471
+ intersectsTriangle: (i) => i.intersectsSphere(t)
2472
+ }
2473
+ );
2474
+ }
2475
+ closestPointToGeometry(t, i, e = {}, s = {}, r = 0, o = 1 / 0) {
2476
+ return (this.indirect ? Qs : Ns)(
2477
+ this,
2478
+ t,
2479
+ i,
2480
+ e,
2481
+ s,
2482
+ r,
2483
+ o
2484
+ );
2485
+ }
2486
+ closestPointToPoint(t, i = {}, e = 0, s = 1 / 0) {
2487
+ return Ms(
2488
+ this,
2489
+ t,
2490
+ i,
2491
+ e,
2492
+ s
2493
+ );
2494
+ }
2495
+ }
2496
+ const It = {
2497
+ Mesh: C.prototype.raycast,
2498
+ Line: Ke.prototype.raycast,
2499
+ LineSegments: Ye.prototype.raycast,
2500
+ LineLoop: Zi.prototype.raycast,
2501
+ Points: Qi.prototype.raycast,
2502
+ BatchedMesh: Un.prototype.raycast
2503
+ }, G = /* @__PURE__ */ new C(), he = [];
2504
+ function Ys(n, t) {
2505
+ if (this.isBatchedMesh)
2506
+ Ks.call(this, n, t);
2507
+ else {
2508
+ const { geometry: i } = this;
2509
+ if (i.boundsTree)
2510
+ i.boundsTree.raycastObject3D(this, n, t);
2511
+ else {
2512
+ let e;
2513
+ if (this instanceof C)
2514
+ e = It.Mesh;
2515
+ else if (this instanceof Ye)
2516
+ e = It.LineSegments;
2517
+ else if (this instanceof Zi)
2518
+ e = It.LineLoop;
2519
+ else if (this instanceof Ke)
2520
+ e = It.Line;
2521
+ else if (this instanceof Qi)
2522
+ e = It.Points;
2523
+ else
2524
+ throw new Error("BVH: Fallback raycast function not found.");
2525
+ e.call(this, n, t);
2526
+ }
2527
+ }
2528
+ }
2529
+ function Ks(n, t) {
2530
+ if (this.boundsTrees) {
2531
+ const i = this.boundsTrees, e = this._drawInfo || this._instanceInfo, s = this._drawRanges || this._geometryInfo, r = this.matrixWorld;
2532
+ G.material = this.material, G.geometry = this.geometry;
2533
+ const o = G.geometry.boundsTree, l = G.geometry.drawRange;
2534
+ G.geometry.boundingSphere === null && (G.geometry.boundingSphere = new En());
2535
+ for (let a = 0, d = e.length; a < d; a++) {
2536
+ if (!this.getVisibleAt(a))
2537
+ continue;
2538
+ const f = e[a].geometryIndex;
2539
+ if (G.geometry.boundsTree = i[f], this.getMatrixAt(a, G.matrixWorld).premultiply(r), !G.geometry.boundsTree) {
2540
+ this.getBoundingBoxAt(f, G.geometry.boundingBox), this.getBoundingSphereAt(f, G.geometry.boundingSphere);
2541
+ const p = s[f];
2542
+ G.geometry.setDrawRange(p.start, p.count);
2543
+ }
2544
+ G.raycast(n, he);
2545
+ for (let p = 0, c = he.length; p < c; p++) {
2546
+ const u = he[p];
2547
+ u.object = this, u.batchId = a, t.push(u);
2548
+ }
2549
+ he.length = 0;
2550
+ }
2551
+ G.geometry.boundsTree = o, G.geometry.drawRange = l, G.material = null, G.geometry = null;
2552
+ } else
2553
+ It.BatchedMesh.call(this, n, t);
2554
+ }
2555
+ function Ie(n) {
2556
+ return n.type === "continuous" || !n.limits ? 0 : Math.max(n.limits.lower, Math.min(n.limits.upper, 0));
2557
+ }
2558
+ class to {
2559
+ constructor(t, i) {
2560
+ F(this, "root");
2561
+ F(this, "visual");
2562
+ F(this, "joints", /* @__PURE__ */ new Map());
2563
+ F(this, "values", /* @__PURE__ */ new Map());
2564
+ F(this, "specs", /* @__PURE__ */ new Map());
2565
+ F(this, "pickMeshes", []);
2566
+ F(this, "disposed", !1);
2567
+ F(this, "initialRoots", /* @__PURE__ */ new Map());
2568
+ this.visual = i, this.root = i.root;
2569
+ const e = new Set(t.links.map((u) => u.id)), s = t.joints.filter((u) => e.has(u.parent) && e.has(u.child) && u.parent !== u.child), r = new Set(s.map((u) => u.child)), o = t.links.filter((u) => !r.has(u.id)), l = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set();
2570
+ for (const u of s)
2571
+ a.has(u.child) || (a.add(u.child), l.set(u.parent, [...l.get(u.parent) ?? [], u]));
2572
+ const d = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set(), p = (u) => {
2573
+ if (f.has(u)) return;
2574
+ f.add(u), d.add(u);
2575
+ const y = i.bindings.get(u);
2576
+ if (!y) {
2577
+ f.delete(u);
2578
+ return;
2579
+ }
2580
+ for (const g of l.get(u) ?? []) {
2581
+ if (f.has(g.child) || d.has(g.child)) continue;
2582
+ const x = i.bindings.get(g.child);
2583
+ if (!x) continue;
2584
+ y.add(x);
2585
+ const b = {
2586
+ joint: g,
2587
+ child: x,
2588
+ originPosition: new U().fromArray(g.origin.position),
2589
+ originQuaternion: Qt(g.origin),
2590
+ axis: new U().fromArray(g.axis).normalize()
2591
+ };
2592
+ this.joints.set(g.id, b), this.specs.set(g.id, g), this.values.set(g.id, Ie(g)), this.apply(b, this.values.get(g.id)), p(g.child);
2593
+ }
2594
+ f.delete(u);
2595
+ }, c = o.length ? o : t.links;
2596
+ for (const u of c) {
2597
+ if (d.has(u.id)) continue;
2598
+ const y = i.bindings.get(u.id);
2599
+ y && (this.root.add(y), p(u.id));
2600
+ }
2601
+ for (const u of t.links) {
2602
+ if (d.has(u.id)) continue;
2603
+ const y = i.bindings.get(u.id);
2604
+ y && (this.root.add(y), p(u.id));
2605
+ }
2606
+ if (o.length === 1) {
2607
+ const u = Ki(t, o[0].id, l), y = i.bindings.get(o[0].id);
2608
+ y && u > 0 && (y.position.z += u);
2609
+ }
2610
+ for (const u of i.bindings.values()) u.parent === this.root && this.initialRoots.set(u, { position: u.position.clone(), quaternion: u.quaternion.clone() });
2611
+ this.applyAll(), this.preparePicking(), this.root.updateMatrixWorld(!0);
2612
+ }
2613
+ pickRoots() {
2614
+ return this.pickMeshes;
2615
+ }
2616
+ value(t) {
2617
+ return this.values.get(t);
2618
+ }
2619
+ valuesSnapshot() {
2620
+ return Object.freeze(Object.fromEntries(this.values));
2621
+ }
2622
+ setJointValue(t, i) {
2623
+ if (this.disposed) throw Xt("URDF kinematic binding has been disposed.", "E_URDF_INACTIVE");
2624
+ const e = this.joints.get(t);
2625
+ if (!e) throw Xt(`Unknown URDF joint: ${t}`, "E_URDF_JOINT_UNKNOWN");
2626
+ if (!Number.isFinite(i)) throw Xt(`Joint value must be finite: ${t}`, "E_URDF_JOINT_VALUE");
2627
+ let s = i;
2628
+ if (e.joint.type !== "continuous" && e.joint.limits && (s = Math.max(e.joint.limits.lower, Math.min(e.joint.limits.upper, i))), ["revolute", "continuous", "prismatic"].includes(e.joint.type) || (s = 0), e.joint.mimic) throw Xt(`Mimic joint is controlled by ${e.joint.mimic.joint}: ${t}`, "E_URDF_MIMIC_READONLY");
2629
+ const r = Ae([...this.specs.values()]).get(t);
2630
+ return r && (s = Math.max(r.lower, Math.min(r.upper, s))), this.values.set(t, s), this.applyAll(), this.root.updateMatrixWorld(!0), s;
2631
+ }
2632
+ resetJoint(t) {
2633
+ const i = this.joints.get(t);
2634
+ if (!i) throw Xt(`Unknown URDF joint: ${t}`, "E_URDF_JOINT_UNKNOWN");
2635
+ this.setJointValue(t, Ie(i.joint));
2636
+ }
2637
+ syncPhysicsPose(t, i) {
2638
+ for (const [e, s] of Object.entries(t)) {
2639
+ const r = this.joints.get(e);
2640
+ r && Number.isFinite(s) && (this.values.set(e, s), this.apply(r, s));
2641
+ }
2642
+ for (const e of this.initialRoots.keys()) {
2643
+ const s = i.get(e.name);
2644
+ s && (e.position.copy(s.position), e.quaternion.copy(s.quaternion));
2645
+ }
2646
+ this.root.updateMatrixWorld(!0);
2647
+ }
2648
+ resetPose() {
2649
+ for (const [t, i] of this.initialRoots)
2650
+ t.position.copy(i.position), t.quaternion.copy(i.quaternion);
2651
+ for (const t of this.joints.values()) {
2652
+ const i = Ie(t.joint);
2653
+ t.joint.mimic || this.values.set(t.joint.id, i);
2654
+ }
2655
+ this.applyAll(), this.root.updateMatrixWorld(!0);
2656
+ }
2657
+ objectForEntity(t) {
2658
+ var i;
2659
+ return t.startsWith("link:") ? this.visual.bindings.get(t.slice(5)) ?? null : t.startsWith("joint:") ? ((i = this.joints.get(t.slice(6))) == null ? void 0 : i.child) ?? null : t.startsWith("robot:") ? this.root : null;
2660
+ }
2661
+ jointWorldFrame(t) {
2662
+ const i = this.joints.get(t);
2663
+ if (!i) return null;
2664
+ const e = i.child.parent;
2665
+ if (!e) return null;
2666
+ e.updateMatrixWorld(!0);
2667
+ const s = i.originPosition.clone().applyMatrix4(e.matrixWorld), r = e.getWorldQuaternion(new tt()).multiply(i.originQuaternion);
2668
+ return { position: s, quaternion: r, axis: i.axis.clone().applyQuaternion(r).normalize() };
2669
+ }
2670
+ dispose() {
2671
+ if (!this.disposed) {
2672
+ this.disposed = !0, this.joints.clear(), this.values.clear(), this.specs.clear();
2673
+ for (const t of this.pickMeshes) {
2674
+ const i = t.geometry;
2675
+ delete i.boundsTree;
2676
+ }
2677
+ this.pickMeshes.length = 0, ut(this.root);
2678
+ }
2679
+ }
2680
+ applyAll() {
2681
+ const t = ti([...this.specs.values()], Object.fromEntries(this.values));
2682
+ for (const [i, e] of this.joints)
2683
+ this.values.set(i, t[i]), this.apply(e, t[i]);
2684
+ }
2685
+ preparePicking() {
2686
+ const t = /* @__PURE__ */ new Set();
2687
+ this.root.traverse((i) => {
2688
+ if (!(i instanceof C) || !i.geometry) return;
2689
+ const e = i.geometry;
2690
+ !e.boundsTree && !t.has(e) && (e.boundsTree = new xe(e, { maxLeafSize: 20, indirect: !0, verbose: !1 }), t.add(e)), i.raycast = Ys, this.pickMeshes.push(i);
2691
+ });
2692
+ }
2693
+ apply(t, i) {
2694
+ t.child.position.copy(t.originPosition), t.child.quaternion.copy(t.originQuaternion), t.joint.type === "revolute" || t.joint.type === "continuous" ? t.child.quaternion.multiply(new tt().setFromAxisAngle(t.axis, i)) : t.joint.type === "prismatic" && t.child.position.addScaledVector(t.axis, i);
2695
+ }
2696
+ }
2697
+ function Xt(n, t) {
2698
+ return Object.assign(new Error(n), { code: t });
2699
+ }
2700
+ function eo(n, t, i = n.source.uri) {
2701
+ var m;
2702
+ const e = oo(t, i), s = new Set(n.links.map((h) => h.id)), r = n.joints.filter((h) => s.has(h.parent) && s.has(h.child) && h.parent !== h.child), o = /* @__PURE__ */ new Map();
2703
+ for (const h of r) o.has(h.child) || o.set(h.child, h);
2704
+ const l = n.links.filter((h) => !o.has(h.id)), a = /* @__PURE__ */ new Map();
2705
+ for (const h of o.values()) a.set(h.parent, [...a.get(h.parent) ?? [], h]);
2706
+ const d = [], f = /* @__PURE__ */ new Set(), p = (h) => {
2707
+ if (!f.has(h)) {
2708
+ f.add(h);
2709
+ for (const w of a.get(h) ?? []) p(w.child);
2710
+ }
2711
+ };
2712
+ for (const h of l)
2713
+ d.push(h), p(h.id);
2714
+ for (const h of n.links) f.has(h.id) || (d.push(h), p(h.id));
2715
+ const c = new Set(d.map((h) => h.id)), u = `robot:${n.name}`, y = /* @__PURE__ */ new Map();
2716
+ for (const h of n.joints) y.set(h.parent, [...y.get(h.parent) ?? [], `joint:${h.id}`]);
2717
+ const g = [], x = Object.freeze({
2718
+ id: u,
2719
+ kind: "robot",
2720
+ name: n.name,
2721
+ childIds: d.map((h) => `link:${h.id}`),
2722
+ rootLinkIds: d.map((h) => h.id),
2723
+ source: e.robot
2724
+ });
2725
+ g.push(x);
2726
+ for (const h of n.links) g.push(io(h, n, e.links.get(h.id), y, c, o));
2727
+ const b = Ae(n.joints);
2728
+ for (const h of n.joints) g.push(no({ ...h, controlLimits: b.get(h.id) }, e.joints.get(h.id), ((m = o.get(h.child)) == null ? void 0 : m.id) === h.id));
2729
+ return Object.freeze({
2730
+ robotName: n.name,
2731
+ sourcePath: i,
2732
+ sourceText: t,
2733
+ nodes: Object.freeze(g),
2734
+ rootEntityId: u,
2735
+ issues: Object.freeze(so(n, e))
2736
+ });
2737
+ }
2738
+ function io(n, t, i, e, s, r) {
2739
+ var l, a, d, f;
2740
+ const o = r.get(n.id);
2741
+ return Object.freeze({
2742
+ id: `link:${n.id}`,
2743
+ kind: "link",
2744
+ name: n.name,
2745
+ parentId: o ? `joint:${o.id}` : `robot:${t.name}`,
2746
+ childIds: Object.freeze(e.get(n.id) ?? []),
2747
+ source: i,
2748
+ mass: (l = n.inertial) == null ? void 0 : l.mass,
2749
+ centerOfMass: (a = n.inertial) == null ? void 0 : a.origin.position,
2750
+ inertiaTensor: (d = n.inertial) == null ? void 0 : d.tensor,
2751
+ inertiaMass: (f = n.inertial) == null ? void 0 : f.mass,
2752
+ inertialRotationRpy: n.inertial ? Object.freeze([...n.inertial.origin.rotationRpy]) : void 0,
2753
+ visualCount: n.visuals.length,
2754
+ collisionCount: n.collisions.length
2755
+ });
2756
+ }
2757
+ function no(n, t, i) {
2758
+ return Object.freeze({
2759
+ id: `joint:${n.id}`,
2760
+ kind: "joint",
2761
+ name: n.id,
2762
+ parentId: `link:${n.parent}`,
2763
+ childIds: Object.freeze([`link:${n.child}`]),
2764
+ source: t,
2765
+ jointType: n.type,
2766
+ parentLink: n.parent,
2767
+ childLink: n.child,
2768
+ axis: Object.freeze([...n.axis]),
2769
+ originPosition: Object.freeze([...n.origin.position]),
2770
+ originRotationRpy: Object.freeze([...n.origin.rotationRpy]),
2771
+ limits: n.limits,
2772
+ effort: n.effort,
2773
+ velocity: n.velocity,
2774
+ controlLimits: n.controlLimits,
2775
+ movable: ["revolute", "continuous", "prismatic"].includes(n.type),
2776
+ ...n.mimic ? { mimic: Object.freeze({ ...n.mimic }) } : {}
2777
+ });
2778
+ }
2779
+ function so(n, t) {
2780
+ const i = [], e = (c, u, y, g, x, b) => {
2781
+ i.push(Object.freeze({ id: `${c}:${g}`, ruleId: c, severity: "error", title: u, message: y, entityId: g, source: x, values: b ? Object.freeze(b) : void 0 }));
2782
+ }, s = new Set(n.links.map((c) => c.id));
2783
+ for (const c of n.joints)
2784
+ s.has(c.parent) || e("joint.parent.missing", "父连杆不存在", `${c.id} 引用了不存在的 parent link ${c.parent}。`, `joint:${c.id}`, t.joints.get(c.id), { parent: c.parent }), s.has(c.child) || e("joint.child.missing", "子连杆不存在", `${c.id} 引用了不存在的 child link ${c.child}。`, `joint:${c.id}`, t.joints.get(c.id), { child: c.child });
2785
+ const r = n.links.filter((c) => !n.joints.some((u) => s.has(u.parent) && u.child === c.id));
2786
+ r.length !== 1 && e("robot.root.count", "根连杆数量无效", `URDF 必须恰好有一个根连杆,当前为 ${r.length} 个。`, `robot:${n.name}`, t.robot, { roots: r.map((c) => c.id) });
2787
+ const o = /* @__PURE__ */ new Map();
2788
+ for (const c of n.joints) s.has(c.parent) && s.has(c.child) && o.set(c.parent, [...o.get(c.parent) ?? [], c.child]);
2789
+ const l = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
2790
+ let d = null;
2791
+ const f = (c, u) => {
2792
+ if (!d) {
2793
+ if (a.has(c)) {
2794
+ const y = u.indexOf(c);
2795
+ d = [...u.slice(Math.max(0, y)), c];
2796
+ return;
2797
+ }
2798
+ if (!l.has(c)) {
2799
+ a.add(c);
2800
+ for (const y of o.get(c) ?? []) f(y, [...u, c]);
2801
+ a.delete(c), l.add(c);
2802
+ }
2803
+ }
2804
+ };
2805
+ for (const c of n.links) f(c.id, []);
2806
+ d && e("robot.graph.cycle", "运动学结构存在环", `运动学链形成循环:${d.join(" → ")}。`, `robot:${n.name}`, t.robot, { cycle: d });
2807
+ const p = /* @__PURE__ */ new Map();
2808
+ for (const c of n.joints) {
2809
+ if (p.set(c.child, [...p.get(c.child) ?? [], c.id]), c.parent === c.child && e("joint.self-reference", "关节父子连杆相同", `${c.id} 的 parent 和 child 都是 ${c.parent}。`, `joint:${c.id}`, t.joints.get(c.id)), ["revolute", "continuous", "prismatic"].includes(c.type)) {
2810
+ const u = c.axis.reduce((y, g) => y + g * g, 0);
2811
+ (!Number.isFinite(u) || u <= Number.EPSILON) && e("joint.axis.zero", "关节轴无效", `${c.id} 的 axis 是零向量。`, `joint:${c.id}`, t.joints.get(c.id), { axis: c.axis });
2812
+ }
2813
+ c.type !== "continuous" && c.limits && c.limits.lower > c.limits.upper && e("joint.limit.order", "关节限位上下界无效", `${c.id} 的 lower ${c.limits.lower} 大于 upper ${c.limits.upper}。`, `joint:${c.id}`, t.joints.get(c.id), { ...c.limits });
2814
+ }
2815
+ for (const [c, u] of p) u.length > 1 && e("link.multiple-parents", "连杆存在多个父关节", `${c} 同时被 ${u.join("、")} 作为 child。`, `link:${c}`, t.links.get(c), { joints: u });
2816
+ for (const c of n.links) {
2817
+ const u = c.inertial;
2818
+ u && ((!(u.mass > 0) || !Number.isFinite(u.mass)) && e("inertial.mass.invalid", "质量无效", `${c.id} 的质量必须是大于零的有限数。`, `link:${c.id}`, t.links.get(c.id), { mass: u.mass }), Oi(u.tensor) || e("inertial.tensor.invalid", "惯性张量无效", `${c.id} 的惯性张量不是正定的物理惯性张量。`, `link:${c.id}`, t.links.get(c.id), { tensor: u.tensor }));
2819
+ }
2820
+ return i;
2821
+ }
2822
+ function oo(n, t) {
2823
+ const i = { robot: void 0, links: /* @__PURE__ */ new Map(), joints: /* @__PURE__ */ new Map() };
2824
+ i.robot = Ni(n, "robot", void 0, t);
2825
+ for (const e of ["link", "joint"]) {
2826
+ const s = new RegExp(`<${e}\\b[^>]*\\bname\\s*=\\s*(["'])(.*?)\\1[^>]*>`, "gi");
2827
+ for (const r of n.matchAll(s)) {
2828
+ const o = r[2], l = Ni(n, e, o, t, r.index);
2829
+ l && i[e === "link" ? "links" : "joints"].set(o, l);
2830
+ }
2831
+ }
2832
+ return i;
2833
+ }
2834
+ function Ni(n, t, i, e, s) {
2835
+ const r = s ?? n.search(new RegExp(`<${t}\\b`, "i"));
2836
+ if (r < 0) return;
2837
+ const o = n.indexOf(">", r);
2838
+ if (o < 0) return;
2839
+ const a = n.slice(r, o + 1).trimEnd().endsWith("/>") ? o + 1 : n.indexOf(`</${t}>`, o + 1), d = a < 0 ? o + 1 : a + t.length + 3, f = qi(n, r), p = qi(n, d);
2840
+ return Object.freeze({ file: e, startOffset: r, endOffset: d, startLine: f.line, startColumn: f.column, endLine: p.line, endColumn: p.column });
2841
+ }
2842
+ function qi(n, t) {
2843
+ const e = n.slice(0, t).split(/\r?\n/);
2844
+ return { line: e.length, column: e.at(-1).length + 1 };
2845
+ }
2846
+ class ro {
2847
+ constructor(t, i, e, s, r) {
2848
+ F(this, "kind", "urdf");
2849
+ F(this, "overlayRoot", new lt());
2850
+ F(this, "listeners", /* @__PURE__ */ new Set());
2851
+ F(this, "revision", 0);
2852
+ F(this, "selectedEntityId");
2853
+ F(this, "overlays", Object.freeze({ collision: !1, jointAxis: !1, centerOfMass: !1, inertia: !1 }));
2854
+ F(this, "mode");
2855
+ F(this, "dynamicsAvailable");
2856
+ F(this, "dynamicsMessage");
2857
+ F(this, "highlightedMaterials", /* @__PURE__ */ new Map());
2858
+ F(this, "selectionMaterials", /* @__PURE__ */ new Map());
2859
+ F(this, "guideBindings", []);
2860
+ F(this, "guideMatrix", new Z());
2861
+ F(this, "overlayInverse", new Z());
2862
+ F(this, "guideSizes", /* @__PURE__ */ new Map());
2863
+ F(this, "labelAnchors", /* @__PURE__ */ new Map());
2864
+ F(this, "modelSize", 1);
2865
+ F(this, "disposed", !1);
2866
+ var o, l;
2867
+ this.asset = t, this.document = i, this.binding = e, this.options = s, this.selectedEntityId = ((o = i.nodes.find((a) => a.kind === "joint")) == null ? void 0 : o.id) ?? ((l = i.nodes.find((a) => a.kind === "link")) == null ? void 0 : l.id) ?? i.rootEntityId, this.mode = "kinematic", this.dynamicsAvailable = r, this.overlayRoot.name = "URDF review overlays", this.measureGuideSizes(), this.rebuildOverlay();
2868
+ }
2869
+ getSnapshot() {
2870
+ return Object.freeze({
2871
+ revision: this.revision,
2872
+ kind: "urdf",
2873
+ robotName: this.document.robotName,
2874
+ sourcePath: this.document.sourcePath,
2875
+ sourceText: this.document.sourceText,
2876
+ nodes: this.document.nodes,
2877
+ rootEntityId: this.document.rootEntityId,
2878
+ selectedEntityId: this.selectedEntityId,
2879
+ jointValues: this.binding.valuesSnapshot(),
2880
+ overlays: this.overlays,
2881
+ issues: this.document.issues,
2882
+ mode: this.mode,
2883
+ dynamicsAvailable: this.dynamicsAvailable,
2884
+ ...this.dynamicsMessage ? { dynamicsMessage: this.dynamicsMessage } : {}
2885
+ });
2886
+ }
2887
+ subscribe(t) {
2888
+ return this.listeners.add(t), () => this.listeners.delete(t);
2889
+ }
2890
+ select(t) {
2891
+ if (!(this.mode === "dynamics-running" || this.mode === "dynamics-initializing")) {
2892
+ if (t !== null && !this.document.nodes.some((i) => i.id === t)) throw ao(`Unknown URDF entity: ${t}`, "E_URDF_ENTITY_UNKNOWN");
2893
+ this.selectedEntityId !== t && (this.selectedEntityId = t, this.rebuildOverlay(), this.publish());
2894
+ }
2895
+ }
2896
+ setJointValue(t, i) {
2897
+ this.mode === "dynamics-running" || this.mode === "dynamics-initializing" || (this.options.enterKinematicPreview(), this.binding.setJointValue(t, i), this.mode = "kinematic", this.rebuildGuides(), this.publish());
2898
+ }
2899
+ resetJoint(t) {
2900
+ this.mode === "dynamics-running" || this.mode === "dynamics-initializing" || (this.options.enterKinematicPreview(), this.binding.resetJoint(t), this.mode = "kinematic", this.rebuildOverlay(), this.publish());
2901
+ }
2902
+ resetPose() {
2903
+ this.options.enterKinematicPreview(), this.binding.resetPose(), this.mode = "kinematic", this.rebuildOverlay(), this.publish();
2904
+ }
2905
+ setOverlay(t, i) {
2906
+ this.overlays[t] !== i && (this.overlays = Object.freeze({ ...this.overlays, [t]: i }), t === "collision" && this.options.setCollisionVisible(i), this.rebuildOverlay(), this.publish());
2907
+ }
2908
+ enterKinematicPreview() {
2909
+ this.options.enterKinematicPreview(), this.mode = "kinematic", this.overlayRoot.visible = !0, this.publish();
2910
+ }
2911
+ setMode(t, i) {
2912
+ t === "dynamics-unavailable" ? (this.mode = "kinematic", this.dynamicsAvailable = !1) : this.mode = t, this.overlayRoot.visible = this.mode !== "dynamics-initializing", (t === "dynamics-running" || t === "dynamics-initializing") && (this.selectedEntityId = null), this.dynamicsMessage = i, this.rebuildOverlay(), this.publish();
2913
+ }
2914
+ jointWorldFrame(t) {
2915
+ return this.binding.jointWorldFrame(t);
2916
+ }
2917
+ pickRoots() {
2918
+ var t, i;
2919
+ return ((i = (t = this.options).pickRoots) == null ? void 0 : i.call(t)) ?? this.binding.pickRoots();
2920
+ }
2921
+ selectionObject() {
2922
+ return this.selectedEntityId ? this.binding.objectForEntity(this.selectedEntityId) : null;
2923
+ }
2924
+ dispose() {
2925
+ if (!this.disposed) {
2926
+ this.disposed = !0, this.listeners.clear(), this.restoreSelectionMaterials();
2927
+ for (const t of this.selectionMaterials.values()) t.dispose();
2928
+ this.selectionMaterials.clear(), ut(this.overlayRoot), this.overlayRoot.removeFromParent();
2929
+ }
2930
+ }
2931
+ publish() {
2932
+ if (this.disposed) return;
2933
+ this.revision += 1;
2934
+ const t = this.getSnapshot();
2935
+ for (const i of this.listeners) i(t);
2936
+ this.options.requestRender();
2937
+ }
2938
+ rebuildOverlay() {
2939
+ if (this.overlayRoot.visible = this.mode !== "dynamics-initializing", this.restoreSelectionMaterials(), this.clearGuides(), this.buildMassGuides(), this.buildJointGuides(), this.syncGuides(), !this.selectedEntityId) return;
2940
+ const t = this.document.nodes.find((e) => e.id === this.selectedEntityId);
2941
+ if (!t) return;
2942
+ const i = this.binding.objectForEntity(t.id);
2943
+ i && t.kind !== "robot" && this.applySelectionMaterials(i);
2944
+ }
2945
+ rebuildGuides() {
2946
+ this.overlayRoot.visible = this.mode !== "dynamics-initializing", this.clearGuides(), this.buildMassGuides(), this.buildJointGuides(), this.syncGuides(), this.selectedEntityId && this.document.nodes.find((t) => t.id === this.selectedEntityId);
2947
+ }
2948
+ /** Update transforms only: physics ticks must not rebuild geometry or publish UI state. */
2949
+ syncGuides() {
2950
+ if (!(this.disposed || !this.overlayRoot.visible || !this.guideBindings.length)) {
2951
+ this.overlayRoot.updateWorldMatrix(!0, !1), this.overlayInverse.copy(this.overlayRoot.matrixWorld).invert();
2952
+ for (const { guide: t, source: i, local: e } of this.guideBindings)
2953
+ i.updateWorldMatrix(!0, !1), this.guideMatrix.multiplyMatrices(this.overlayInverse, i.matrixWorld).multiply(e), this.guideMatrix.decompose(t.position, t.quaternion, t.scale), t.updateMatrixWorld(!0);
2954
+ }
2955
+ }
2956
+ linkObject(t) {
2957
+ var i, e;
2958
+ return ((e = (i = this.options).linkObject) == null ? void 0 : e.call(i, t)) ?? this.binding.objectForEntity(`link:${t}`);
2959
+ }
2960
+ trackGuide(t, i) {
2961
+ i.updateWorldMatrix(!0, !1), this.overlayRoot.updateWorldMatrix(!0, !1), t.updateWorldMatrix(!0, !1);
2962
+ const e = i.matrixWorld.clone().invert().multiply(t.matrixWorld);
2963
+ this.guideBindings.push({ guide: t, source: i, local: e });
2964
+ }
2965
+ clearGuides() {
2966
+ this.guideBindings.length = 0, ut(this.overlayRoot), this.overlayRoot.clear();
2967
+ }
2968
+ /** Cache own-link bounds once; exclude child links and never traverse meshes per physics tick. */
2969
+ measureGuideSizes() {
2970
+ const t = new it();
2971
+ for (const e of this.document.nodes) {
2972
+ if (e.kind !== "link") continue;
2973
+ const s = this.binding.objectForEntity(e.id);
2974
+ if (!s) continue;
2975
+ s.updateWorldMatrix(!0, !0);
2976
+ const r = new it(), o = (a) => {
2977
+ if (!(a !== s && typeof a.userData.urdfEntityId == "string")) {
2978
+ a instanceof C && (a.geometry.boundingBox || a.geometry.computeBoundingBox(), a.geometry.boundingBox && r.union(a.geometry.boundingBox.clone().applyMatrix4(a.matrixWorld)));
2979
+ for (const d of a.children) o(d);
2980
+ }
2981
+ };
2982
+ if (o(s), r.isEmpty()) continue;
2983
+ this.labelAnchors.set(e.name, r.getCenter(new U()).applyMatrix4(s.matrixWorld.clone().invert()));
2984
+ const l = r.getSize(new U()).length();
2985
+ Number.isFinite(l) && l > 0 && (this.guideSizes.set(e.name, l), t.union(r));
2986
+ }
2987
+ const i = t.getSize(new U()).length();
2988
+ Number.isFinite(i) && i > 0 && (this.modelSize = i);
2989
+ }
2990
+ linkWorldPosition(t, i) {
2991
+ const e = this.linkObject(t);
2992
+ return !e || this.disposed || this.mode === "dynamics-initializing" ? !1 : (e.updateWorldMatrix(!0, !1), i.copy(this.labelAnchors.get(t) ?? new U()).applyMatrix4(e.matrixWorld), !0);
2993
+ }
2994
+ guideSize(t) {
2995
+ const i = this.guideSizes.get(t) ?? this.modelSize * 0.1;
2996
+ return Math.max(this.modelSize * 3e-3, Math.min(i, this.modelSize * 0.35));
2997
+ }
2998
+ buildJointGuides() {
2999
+ const t = this.document.nodes.find((e) => e.id === this.selectedEntityId), i = (t == null ? void 0 : t.kind) === "joint" ? t : (t == null ? void 0 : t.kind) === "link" ? this.document.nodes.find((e) => e.kind === "joint" && e.childLink === t.name) : void 0;
3000
+ for (const e of this.document.nodes) {
3001
+ if (e.kind !== "joint" || !this.overlays.jointAxis && e.id !== (i == null ? void 0 : i.id)) continue;
3002
+ const s = this.linkObject(e.parentLink), r = s ? (() => {
3003
+ s.updateWorldMatrix(!0, !1);
3004
+ const d = s.getWorldQuaternion(new tt()).multiply(new tt().setFromEuler(new Zt(...e.originRotationRpy, "ZYX")));
3005
+ return { position: new U().fromArray(e.originPosition).applyMatrix4(s.matrixWorld), quaternion: d, axis: new U().fromArray(e.axis).applyQuaternion(d).normalize() };
3006
+ })() : this.binding.jointWorldFrame(e.name);
3007
+ if (!r) continue;
3008
+ const o = new lt();
3009
+ o.name = `Joint guide:${e.name}`;
3010
+ const l = this.guideSize(e.childLink), a = new zn(0.18 * l);
3011
+ if (a.name = `Joint frame:${e.name}`, a.position.copy(r.position), a.quaternion.copy(r.quaternion), o.add(a), ["revolute", "continuous", "prismatic"].includes(e.jointType)) {
3012
+ const d = r.axis.clone().normalize(), f = new hi(d, r.position, 0.28 * l, 5625523, 0.045 * l, 0.022 * l);
3013
+ if (f.name = `Joint axis:${e.name}`, o.add(f), e.jointType !== "prismatic") {
3014
+ const c = (Math.abs(d.z) < 0.9 ? new U(0, 0, 1) : new U(0, 1, 0)).cross(d).normalize(), u = d.clone().cross(c).normalize(), y = 0.09 * l, g = Math.PI * 1.65, x = r.position.clone().addScaledVector(d, 0.085 * l), b = Array.from({ length: 33 }, (A, P) => {
3015
+ const v = g * P / 32;
3016
+ return x.clone().addScaledVector(c, y * Math.cos(v)).addScaledVector(u, y * Math.sin(v));
3017
+ }), m = new Ke(new $n().setFromPoints(b), new yi({ color: 16761963 }));
3018
+ m.name = `Positive rotation:${e.name}`;
3019
+ const h = c.clone().multiplyScalar(-Math.sin(g)).addScaledVector(u, Math.cos(g)), w = new hi(h, b[32], 0.03 * l, 16761963, 0.03 * l, 0.022 * l);
3020
+ w.name = `Positive rotation arrow:${e.name}`, o.add(m, w);
3021
+ }
3022
+ }
3023
+ o.traverse((d) => {
3024
+ d.renderOrder = 1001;
3025
+ const f = d.material;
3026
+ for (const p of Array.isArray(f) ? f : f ? [f] : [])
3027
+ p.depthTest = !1, p.depthWrite = !1, p.transparent = !0;
3028
+ }), this.overlayRoot.add(o), s && this.trackGuide(o, s);
3029
+ }
3030
+ }
3031
+ buildMassGuides() {
3032
+ if (!this.overlays.centerOfMass && !this.overlays.inertia) return;
3033
+ const t = this.document.nodes.find((e) => e.id === this.selectedEntityId), i = (t == null ? void 0 : t.kind) === "link" ? t.name : (t == null ? void 0 : t.kind) === "joint" ? t.childLink : void 0;
3034
+ for (const e of this.asset.links) {
3035
+ const s = e.inertial, r = this.linkObject(e.id);
3036
+ if (!s || !r) continue;
3037
+ r.updateWorldMatrix(!0, !1);
3038
+ const o = new U().fromArray(s.origin.position).applyMatrix4(r.matrixWorld), l = e.id === i;
3039
+ if (this.overlays.centerOfMass) {
3040
+ const u = new Qe(0.025 * this.guideSize(e.id), 32, 16), y = u.toNonIndexed();
3041
+ u.dispose();
3042
+ const g = y.getAttribute("position"), x = new Float32Array(g.count * 3);
3043
+ for (let m = 0; m < g.count; m += 3) {
3044
+ let h = 0, w = 0, A = 0;
3045
+ for (let v = 0; v < 3; v++)
3046
+ h += g.getX(m + v), w += g.getY(m + v), A += g.getZ(m + v);
3047
+ const P = h * w * A >= 0 ? 1 : 0.015;
3048
+ for (let v = 0; v < 9; v++) x[m * 3 + v] = P;
3049
+ }
3050
+ y.setAttribute("color", new Fn(x, 3));
3051
+ const b = new C(y, new gi({ color: l ? 16739210 : 16777215, vertexColors: !0, depthTest: !1, depthWrite: !1 }));
3052
+ b.quaternion.copy(r.getWorldQuaternion(new tt())), b.position.copy(o), b.renderOrder = 1002, b.name = `Center of mass:${e.id}`, this.overlayRoot.add(b), this.trackGuide(b, r);
3053
+ }
3054
+ const a = this.overlays.inertia ? xn(s.tensor, s.mass) : null;
3055
+ if (!a) continue;
3056
+ const d = new Ze(1, 1, 1), f = new Ye(new In(d), new yi({ color: l ? 16736135 : 2211300, transparent: !0, opacity: l ? 0.98 : 0.82, depthTest: !0, depthWrite: !1 })), p = new C(d, new gi({ color: l ? 16739210 : 3262699, transparent: !0, opacity: l ? 0.28 : 0.16, depthTest: !0, depthWrite: !1 }));
3057
+ p.name = `Inertia fill:${e.id}`;
3058
+ const c = s.origin.rotationQuaternion ? new tt().fromArray(s.origin.rotationQuaternion) : new tt().setFromEuler(new Zt(...s.origin.rotationRpy, "ZYX"));
3059
+ f.position.copy(o), f.scale.fromArray(a.size), f.quaternion.copy(r.getWorldQuaternion(new tt())).multiply(c).multiply(a.rotation), f.renderOrder = 1001, f.name = `Inertia:${e.id}`, p.position.copy(f.position), p.quaternion.copy(f.quaternion), p.scale.copy(f.scale), p.renderOrder = 1e3, this.overlayRoot.add(p, f), this.trackGuide(p, r), this.trackGuide(f, r);
3060
+ }
3061
+ }
3062
+ applySelectionMaterials(t) {
3063
+ const i = (e, s) => {
3064
+ if (!(!s && typeof e.userData.urdfEntityId == "string")) {
3065
+ e instanceof C && e.material && (this.highlightedMaterials.set(e, e.material), e.material = Array.isArray(e.material) ? e.material.map((r) => this.createSelectionMaterial(r)) : this.createSelectionMaterial(e.material));
3066
+ for (const r of e.children) i(r, !1);
3067
+ }
3068
+ };
3069
+ i(t, !0);
3070
+ }
3071
+ createSelectionMaterial(t) {
3072
+ var r;
3073
+ const i = this.selectionMaterials.get(t);
3074
+ if (i) return i;
3075
+ const e = t.clone(), s = e;
3076
+ return (r = s.color) == null || r.set(9425919), s.emissive ? (s.emissive.set(2793430), s.emissiveIntensity = Math.max(s.emissiveIntensity ?? 0, 0.34)) : e instanceof He && (e.emissive.set(2793430), e.emissiveIntensity = 0.34), e.transparent = t.transparent, e.opacity = t.opacity, e.depthWrite = t.depthWrite, e.needsUpdate = !0, this.selectionMaterials.set(t, e), e;
3077
+ }
3078
+ restoreSelectionMaterials() {
3079
+ for (const [t, i] of this.highlightedMaterials) t.material = i;
3080
+ this.highlightedMaterials.clear();
3081
+ }
3082
+ }
3083
+ function ao(n, t) {
3084
+ return Object.assign(new Error(n), { code: t });
3085
+ }
3086
+ async function wo(n, t, i) {
3087
+ var _, E, $, D;
3088
+ const e = n.entryPath ?? n.filename ?? "asset.urdf";
3089
+ (_ = t.reportProgress) == null || _.call(t, "fetch", "正在读取模型描述与依赖资源...");
3090
+ let s = await yn(n, i);
3091
+ const r = t.format === "xacro";
3092
+ if (r) {
3093
+ (E = t.reportProgress) == null || E.call(t, "xacro", "正在展开 Xacro 宏与依赖文件...");
3094
+ const { expandXacro: z } = await import("./xacro-CYTPS7mh.js");
3095
+ s = await z(s, e, i, t.options.xacro, t.signal);
3096
+ }
3097
+ if (t.signal.aborted) throw Jt();
3098
+ ($ = t.reportProgress) == null || $.call(t, "parse", "正在解析 URDF 结构与连杆...");
3099
+ const o = qn(s, e, i);
3100
+ (D = t.reportProgress) == null || D.call(t, "visual", "正在构建运动学预览...");
3101
+ const l = await xi(o), a = new to(o, l), d = await Gn(o, l), f = o.diagnostics.errors.find((z) => z.code === "E_URDF_INERTIA"), p = o.links.some((z) => z.inertial), c = p && !f, u = new An(
3102
+ a.root,
3103
+ t.options.simulationTheme,
3104
+ void 0,
3105
+ "simulation",
3106
+ c ? "physics" : "visual"
3107
+ );
3108
+ d && (d.root.visible = !1, u.attachAuxiliary(d.root));
3109
+ let y = null, g = null, x = null;
3110
+ const b = o.diagnostics.warnings[0], m = b ? ri(b, "visual-material") : null;
3111
+ let h = f ? {
3112
+ code: f.code,
3113
+ message: f.message,
3114
+ stage: "physics-validation",
3115
+ notice: ai(f.code, f.source)
3116
+ } : m, w = f ? { status: "unavailable", issue: h } : p ? { status: "available" } : { status: "not-authored" }, A = !1, P = null, v = !1, T = !1;
3117
+ const R = () => {
3118
+ var L;
3119
+ const z = A || !a.root.visible;
3120
+ A = !1, u.setRuntime(void 0), g && (g.root.visible = !1), u.replaceModel(a.root, !1), a.root.visible = !0, d && d.sync(), d != null && d.root && (d.root.visible = M.getSnapshot().overlays.collision), x && (x.root.visible = !1), z && ((L = t.reportSessionState) == null || L.call(t)), t.requestRender();
3121
+ }, M = new ro(o, eo(o, s, r ? `${e} (expanded URDF)` : e), a, {
3122
+ requestRender() {
3123
+ a.root.visible && (d == null || d.sync()), t.requestRender();
3124
+ },
3125
+ setCollisionVisible(z) {
3126
+ d && (d.root.visible = z && a.root.visible), x && (x.root.visible = z && (g == null ? void 0 : g.root.visible) === !0);
3127
+ },
3128
+ enterKinematicPreview: R,
3129
+ linkObject: (z) => g != null && g.root.visible ? g.objectForLink(z) : a.objectForEntity(`link:${z}`),
3130
+ pickRoots: () => A || w.status === "initializing" ? [] : a.pickRoots()
3131
+ }, c);
3132
+ f && M.setMode(
3133
+ "dynamics-unavailable",
3134
+ ai(f.code, f.source).summary
3135
+ ), u.attachAuxiliary(M.overlayRoot);
3136
+ const B = () => !y || !g ? !1 : (y.setJointValues(M.getSnapshot().jointValues), u.replaceModel(g.root, !1), u.setRuntime(y), g.sync(), x == null || x.sync(), a.root.visible = !1, g.root.visible = !0, d && (d.root.visible = !1), x && (x.root.visible = M.getSnapshot().overlays.collision), !0), S = async () => {
3137
+ var vt, Mt, Pt, kt;
3138
+ if (y || v || !c) return;
3139
+ M.setMode("dynamics-initializing"), w = { status: "initializing" }, (vt = t.reportSessionState) == null || vt.call(t);
3140
+ let z = null, L = null, Y = null;
3141
+ try {
3142
+ const wt = await Wn(o);
3143
+ if (t.signal.aborted || v) throw Jt();
3144
+ const nt = await import("./mujoco-runtime-Dhx6Ua2u.js");
3145
+ if (z = new nt.MujocoRuntime(), await z.initialize(wt, {
3146
+ baseUrl: t.options.mujocoBaseUrl,
3147
+ wasmModule: t.options.mujocoWasmModule
3148
+ }), z.setWorldRotation(ui(u.getUpAxis())), t.signal.aborted || v || (L = new fi(z, await xi(o)), t.signal.aborted || v)) throw Jt();
3149
+ const Yt = await tn(o);
3150
+ if (Y = Yt ? new fi(z, Yt) : null, t.signal.aborted || v) throw Jt();
3151
+ y = z, z = null, g = L, L = null, g.root.visible = !1, x = Y, Y = null, x && (x.root.visible = !1, u.attachAuxiliary(x.root)), w = { status: "ready" }, h = m, T && (B(), A = !0, M.setMode("dynamics-running")), (Mt = t.reportSessionState) == null || Mt.call(t), t.requestRender();
3152
+ } catch (wt) {
3153
+ if (Y == null || Y.dispose(), L == null || L.dispose(), z == null || z.dispose(), v || t.signal.aborted || wt instanceof Error && wt.name === "AbortError") return;
3154
+ const nt = gn(wt, t.signal, "urdf-physics");
3155
+ u.setRuntime(void 0), u.setGroundPlacement("visual"), y == null || y.dispose(), y = null, g == null || g.dispose(), g = null, x && (u.detachAuxiliary(x.root), x.dispose(), x = null), R(), h = ri(nt, "physics-fallback"), w = { status: "unavailable", issue: h }, M.setMode("dynamics-unavailable", ((Pt = h.notice) == null ? void 0 : Pt.summary) ?? h.message), (kt = t.reportSessionState) == null || kt.call(t), t.reportError(wt, { fatal: !1, stage: "physics-start", code: nt.code });
3156
+ }
3157
+ };
3158
+ return {
3159
+ asset: o,
3160
+ stage: u,
3161
+ inspection: M,
3162
+ autoPlay: !1,
3163
+ root: u.root,
3164
+ get capabilities() {
3165
+ const z = w.status === "initializing", L = w.status === "unavailable" || w.status === "not-authored";
3166
+ return { canPlay: !z && !L, canPause: y !== null, canReset: !0, hasPhysics: y !== null, canToggleGround: !0, canToggleCollision: d !== void 0 || x !== null, canReorientUpAxis: !0 };
3167
+ },
3168
+ get physics() {
3169
+ return w;
3170
+ },
3171
+ get warning() {
3172
+ return h;
3173
+ },
3174
+ isPlaying: () => A,
3175
+ play() {
3176
+ var z;
3177
+ if (!(v || w.status === "unavailable" || w.status === "not-authored")) {
3178
+ if (T = !0, M.select(null), !y) {
3179
+ P ?? (P = S().finally(() => {
3180
+ P = null;
3181
+ }));
3182
+ return;
3183
+ }
3184
+ B() && (A = !0, M.setMode("dynamics-running"), (z = t.reportSessionState) == null || z.call(t));
3185
+ }
3186
+ },
3187
+ pause() {
3188
+ var z;
3189
+ T = !1, A = !1, u.endGrab(), y && (a.syncPhysicsPose(y.getJointValues(o.joints.map((L) => L.id)), co(g.bodyPoses(), ui(u.getUpAxis()))), R(), M.setMode("dynamics-paused")), (z = t.reportSessionState) == null || z.call(t), t.requestRender();
3190
+ },
3191
+ reset() {
3192
+ var z;
3193
+ T = !1, u.endGrab(), y && (y.reset(), g == null || g.sync(), x == null || x.sync()), M.resetPose(), u.resetGround(), (z = t.reportSessionState) == null || z.call(t), t.requestRender();
3194
+ },
3195
+ step(z) {
3196
+ if (!y || !A) return !1;
3197
+ const L = y.step(z);
3198
+ return L && (g == null || g.sync(), x == null || x.sync(), M.syncGuides(), u.updateForceLine()), L;
3199
+ },
3200
+ beginGrab(z, L, Y) {
3201
+ return !!(A && y && u.beginGrab(z, L, Y));
3202
+ },
3203
+ moveGrab(z, L, Y) {
3204
+ A && y && u.moveGrab(z, L, Y);
3205
+ },
3206
+ endGrab() {
3207
+ u.endGrab();
3208
+ },
3209
+ setCollisionVisible(z) {
3210
+ d && (d.root.visible = z && a.root.visible), x && (x.root.visible = z && (g == null ? void 0 : g.root.visible) === !0);
3211
+ },
3212
+ dispose() {
3213
+ v || (v = !0, A = !1, M.dispose(), d && (u.detachAuxiliary(d.root), d.dispose()), x && (u.detachAuxiliary(x.root), x.dispose()), u.setRuntime(void 0), g == null || g.dispose(), a.dispose(), y == null || y.dispose(), u.dispose());
3214
+ }
3215
+ };
3216
+ }
3217
+ function Jt() {
3218
+ return Object.assign(new Error("Simulation load aborted."), { name: "AbortError", code: "E_ABORTED" });
3219
+ }
3220
+ function co(n, t) {
3221
+ const i = t.clone().invert(), e = /* @__PURE__ */ new Map();
3222
+ for (const [s, r] of n)
3223
+ e.set(s, {
3224
+ position: r.position.clone().applyQuaternion(i),
3225
+ quaternion: i.clone().multiply(r.quaternion)
3226
+ });
3227
+ return e;
3228
+ }
3229
+ export {
3230
+ wo as loadUrdfSimulation
3231
+ };