@nebula-spatial/studio 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +206 -3
  2. package/dist/ai/contract.d.ts +73 -0
  3. package/dist/ai/host.d.ts +28 -0
  4. package/dist/asset/dependency-scan.d.ts +78 -0
  5. package/dist/asset/intake.d.ts +84 -0
  6. package/dist/asset/layout-detect.d.ts +40 -0
  7. package/dist/asset/media-type.d.ts +10 -0
  8. package/dist/asset/model-inspection.d.ts +127 -0
  9. package/dist/asset/record.d.ts +35 -0
  10. package/dist/asset/remote-asset-resolver.d.ts +36 -0
  11. package/dist/asset/repairs.d.ts +53 -0
  12. package/dist/asset/resource-locator.d.ts +15 -0
  13. package/dist/asset/revision-diff.d.ts +33 -0
  14. package/dist/asset/source-contracts.d.ts +21 -0
  15. package/dist/asset/source-paths.d.ts +15 -0
  16. package/dist/asset/usd-inspection.d.ts +39 -0
  17. package/dist/asset/usd-source-metadata.d.ts +142 -0
  18. package/dist/asset/visual-intake.d.ts +27 -0
  19. package/dist/asset/visual-record.d.ts +22 -0
  20. package/dist/asset/web-intake.d.ts +46 -0
  21. package/dist/asset-source-BExlEcRt.js +444 -0
  22. package/dist/assets/openusd_three_loader-DLiqJWUM.js +13769 -0
  23. package/dist/assets/usd-export-worker-BRxTLqer.js +182 -0
  24. package/dist/assets/usd-worker-DekqMsQv.js +1392 -0
  25. package/dist/builders-BAXRR5o5.js +1854 -0
  26. package/dist/core/asset-task.d.ts +105 -0
  27. package/dist/core/context.d.ts +23 -0
  28. package/dist/core/host.d.ts +432 -0
  29. package/dist/core/persistence-controller.d.ts +58 -0
  30. package/dist/core/plugins.d.ts +139 -0
  31. package/dist/core/scene-tree.d.ts +62 -0
  32. package/dist/core/versions.d.ts +2 -0
  33. package/dist/core/when.d.ts +13 -0
  34. package/dist/core/write-policy.d.ts +29 -0
  35. package/dist/delivery/build-plan.d.ts +2 -0
  36. package/dist/delivery/contracts.d.ts +362 -0
  37. package/dist/delivery/digest.d.ts +3 -0
  38. package/dist/delivery/evidence.d.ts +10 -0
  39. package/dist/delivery/export-evidence.d.ts +3 -0
  40. package/dist/delivery/index.d.ts +9 -0
  41. package/dist/delivery/prim-name.d.ts +17 -0
  42. package/dist/delivery/profile.d.ts +4 -0
  43. package/dist/doc/builders.d.ts +99 -0
  44. package/dist/doc/command.d.ts +195 -0
  45. package/dist/doc/domain-extensions.d.ts +34 -0
  46. package/dist/doc/node-facts.d.ts +87 -0
  47. package/dist/doc/physics-facts.d.ts +74 -0
  48. package/dist/doc/placement-policy.d.ts +71 -0
  49. package/dist/doc/random-placement.d.ts +30 -0
  50. package/dist/doc/scene-graph.d.ts +80 -0
  51. package/dist/doc/scene-regions.d.ts +29 -0
  52. package/dist/doc/schema.d.ts +452 -0
  53. package/dist/doc/task.d.ts +71 -0
  54. package/dist/doc/validate.d.ts +68 -0
  55. package/dist/editor/asset-source.d.ts +15 -0
  56. package/dist/editor/editor.d.ts +246 -0
  57. package/dist/editor/index.d.ts +22 -0
  58. package/dist/editor/shortcuts.d.ts +2 -0
  59. package/dist/editor/types.d.ts +143 -0
  60. package/dist/editor/ui-plugins.d.ts +64 -0
  61. package/dist/editor.js +1755 -0
  62. package/dist/editorial-BkAFWfbg.js +83 -0
  63. package/dist/export-evidence-DMNRhgL9.js +2705 -0
  64. package/dist/generalization/domain.d.ts +10 -0
  65. package/dist/generalization/generalization.d.ts +371 -0
  66. package/dist/generalization/index.d.ts +11 -0
  67. package/dist/generalization.js +1659 -0
  68. package/dist/history/undo-stack.d.ts +74 -0
  69. package/dist/index.d.ts +91 -0
  70. package/dist/index.js +2840 -0
  71. package/dist/mjcf-visual-Bt4bUxd1.js +72 -0
  72. package/dist/mujoco-runtime-BYZnrvbR.js +467 -0
  73. package/dist/persist/content-addressed.d.ts +11 -0
  74. package/dist/persist/create-scene-package-from-host.d.ts +7 -0
  75. package/dist/persist/indexeddb-store.d.ts +69 -0
  76. package/dist/persist/scene-file.d.ts +52 -0
  77. package/dist/persist/scene-package.d.ts +8 -0
  78. package/dist/persist/snapshot.d.ts +5 -0
  79. package/dist/physics-facts-tfQYyNTD.js +337 -0
  80. package/dist/placement-policy-DY_FNRDu.js +405 -0
  81. package/dist/ports/asset-ingestor.d.ts +41 -0
  82. package/dist/ports/asset-source.d.ts +57 -0
  83. package/dist/ports/delivery.d.ts +13 -0
  84. package/dist/ports/persistence.d.ts +29 -0
  85. package/dist/project/asset-catalog.d.ts +21 -0
  86. package/dist/project/contracts.d.ts +272 -0
  87. package/dist/project/editorial.d.ts +16 -0
  88. package/dist/project/identity.d.ts +20 -0
  89. package/dist/project/index.d.ts +9 -0
  90. package/dist/project/scene-document.d.ts +5 -0
  91. package/dist/project/source-dependencies.d.ts +7 -0
  92. package/dist/remote-asset-resolver-Cb8cfNmw.js +136 -0
  93. package/dist/scene/index.d.ts +12 -0
  94. package/dist/scene-graph-DBLKAhxa.js +681 -0
  95. package/dist/scene-session-Cy6vDJ1l.js +21981 -0
  96. package/dist/scene.js +244 -0
  97. package/dist/session-BRBrCLdd.js +963 -0
  98. package/dist/session-DI5tPJxn.js +825 -0
  99. package/dist/session-q3uuG7OP.js +296 -0
  100. package/dist/studio/delivery-catalog.d.ts +28 -0
  101. package/dist/studio/in-memory-asset-source.d.ts +15 -0
  102. package/dist/studio/index.d.ts +31 -0
  103. package/dist/studio/indexeddb-asset-source.d.ts +32 -0
  104. package/dist/studio/indexeddb-persistence.d.ts +13 -0
  105. package/dist/studio/remote-asset-importer.d.ts +56 -0
  106. package/dist/studio/source-package.d.ts +9 -0
  107. package/dist/studio/usd-export-client.d.ts +13 -0
  108. package/dist/studio/usd-export-protocol.d.ts +98 -0
  109. package/dist/studio/usd-export-worker.d.ts +1 -0
  110. package/dist/studio/usd-zip-reader.d.ts +14 -0
  111. package/dist/studio/web-asset-ingestor.d.ts +10 -0
  112. package/dist/studio/web-host.d.ts +8 -0
  113. package/dist/studio.js +5545 -0
  114. package/dist/urdf-session-CQir2nb2.js +1230 -0
  115. package/dist/usd-session-DZJnEEOs.js +7385 -0
  116. package/dist/util/asset-facts.d.ts +3 -0
  117. package/dist/util/data.d.ts +17 -0
  118. package/dist/util/diagnostics.d.ts +38 -0
  119. package/dist/util/geometry.d.ts +11 -0
  120. package/dist/util/hash.d.ts +9 -0
  121. package/dist/util/ids.d.ts +20 -0
  122. package/dist/util/math.d.ts +47 -0
  123. package/dist/util/ply-metadata.d.ts +19 -0
  124. package/dist/util/studio-source.d.ts +23 -0
  125. package/dist/version.d.ts +5 -0
  126. package/dist/view/appearance.d.ts +13 -0
  127. package/dist/view/authoring-appearance.d.ts +25 -0
  128. package/dist/view/bounds-preview.d.ts +34 -0
  129. package/dist/view/bounds.d.ts +11 -0
  130. package/dist/view/camera-zoom.d.ts +3 -0
  131. package/dist/view/geometry-anchors.d.ts +20 -0
  132. package/dist/view/gizmo-appearance.d.ts +5 -0
  133. package/dist/view/gizmo.d.ts +81 -0
  134. package/dist/view/group-selection.d.ts +13 -0
  135. package/dist/view/node-features.d.ts +39 -0
  136. package/dist/view/picking.d.ts +49 -0
  137. package/dist/view/placement.d.ts +48 -0
  138. package/dist/view/region-editing.d.ts +25 -0
  139. package/dist/view/rotation-guide.d.ts +36 -0
  140. package/dist/view/runtime-capabilities.d.ts +22 -0
  141. package/dist/view/scene-session.d.ts +258 -0
  142. package/dist/view/screen-bounds.d.ts +17 -0
  143. package/dist/view/selection-transform.d.ts +20 -0
  144. package/dist/wasm-module-DZn2AM1W.js +13 -0
  145. package/dist/xacro-DLRXyk60.js +76 -0
  146. package/node_modules/@nebula-spatial/cad-loader/CHANGELOG.md +48 -0
  147. package/node_modules/@nebula-spatial/cad-loader/README.md +108 -0
  148. package/node_modules/@nebula-spatial/cad-loader/dist/core/cad-types.d.ts +26 -0
  149. package/node_modules/@nebula-spatial/cad-loader/dist/core/errors.d.ts +5 -0
  150. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.d.ts +24 -0
  151. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.js +2354 -0
  152. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-group-reader.d.ts +9 -0
  153. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-parser.d.ts +78 -0
  154. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/dxbs-sidecar.d.ts +24 -0
  155. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/geometry-segments.d.ts +20 -0
  156. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/text-roundtrip.d.ts +4 -0
  157. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/types.d.ts +81 -0
  158. package/node_modules/@nebula-spatial/cad-loader/dist/core/runtime-text-decoder.d.ts +8 -0
  159. package/node_modules/@nebula-spatial/cad-loader/dist/core/types.d.ts +153 -0
  160. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/insert-bbox.d.ts +10 -0
  161. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/viewport-rect.d.ts +21 -0
  162. package/node_modules/@nebula-spatial/cad-loader/dist/index.d.ts +36 -0
  163. package/node_modules/@nebula-spatial/cad-loader/dist/index.js +5829 -0
  164. package/node_modules/@nebula-spatial/cad-loader/dist/loader/geo-loader.d.ts +59 -0
  165. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/automatic-external-resources.d.ts +26 -0
  166. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/external-variant-sidecar-fetch.d.ts +13 -0
  167. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/flow-control.d.ts +29 -0
  168. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/frame-budget-scheduler.d.ts +21 -0
  169. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-compact-executor.d.ts +19 -0
  170. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-local-adapter.d.ts +2 -0
  171. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-pipeline.d.ts +92 -0
  172. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-worker-adapter.d.ts +13 -0
  173. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-builder.d.ts +34 -0
  174. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-load-sink.d.ts +28 -0
  175. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node.d.ts +304 -0
  176. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare-worker-types.d.ts +94 -0
  177. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.d.ts +38 -0
  178. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.worker.d.ts +1 -0
  179. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-model-builder.d.ts +10 -0
  180. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-runtime-geometry.d.ts +15 -0
  181. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-canonical.d.ts +37 -0
  182. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-quality.d.ts +9 -0
  183. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/prepare-credit-gate.d.ts +20 -0
  184. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/transport.d.ts +2 -0
  185. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/cad-render-node.d.ts +80 -0
  186. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/geo-node-cad-render-node.d.ts +12 -0
  187. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-geometry.d.ts +28 -0
  188. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-material.d.ts +18 -0
  189. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/block-geometry-registry.d.ts +35 -0
  190. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/insert-instance-table.d.ts +23 -0
  191. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/viewport-instance-presenter.d.ts +66 -0
  192. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-insert-selection.d.ts +35 -0
  193. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-text-selection.d.ts +31 -0
  194. package/node_modules/@nebula-spatial/cad-loader/dist/session/annotation-idle-gate.d.ts +14 -0
  195. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-document-session.d.ts +187 -0
  196. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-font-runtime.d.ts +11 -0
  197. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-insert-id.d.ts +6 -0
  198. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-text-warmup.d.ts +38 -0
  199. package/node_modules/@nebula-spatial/cad-loader/dist/session/create-cad-document-session.d.ts +5 -0
  200. package/node_modules/@nebula-spatial/cad-loader/dist/session/load-session.d.ts +90 -0
  201. package/node_modules/@nebula-spatial/cad-loader/dist/session/viewport-coverage.d.ts +32 -0
  202. package/node_modules/@nebula-spatial/cad-loader/dist/shared/abort.d.ts +3 -0
  203. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-display-color.d.ts +55 -0
  204. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-load-source.d.ts +8 -0
  205. package/node_modules/@nebula-spatial/cad-loader/dist/shared/color-buffer.d.ts +6 -0
  206. package/node_modules/@nebula-spatial/cad-loader/dist/shared/constants.d.ts +11 -0
  207. package/node_modules/@nebula-spatial/cad-loader/dist/shared/display-color-buffer.d.ts +27 -0
  208. package/node_modules/@nebula-spatial/cad-loader/dist/shared/errors.d.ts +2 -0
  209. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-builder.d.ts +25 -0
  210. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-font.d.ts +12 -0
  211. package/node_modules/@nebula-spatial/cad-loader/dist/shared/types.d.ts +57 -0
  212. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/insert-bbox.d.ts +1 -0
  213. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/timing.d.ts +2 -0
  214. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/viewport-rect.d.ts +1 -0
  215. package/node_modules/@nebula-spatial/cad-loader/dist/shared/viewer-theme.d.ts +2 -0
  216. package/node_modules/@nebula-spatial/cad-loader/dist/workers/geo-prepare.worker.js +2264 -0
  217. package/node_modules/@nebula-spatial/cad-loader/package.json +62 -0
  218. package/node_modules/@nebula-spatial/viewer/CHANGELOG.md +426 -0
  219. package/node_modules/@nebula-spatial/viewer/FBX-MATERIAL-CONVERSION.md +97 -0
  220. package/node_modules/@nebula-spatial/viewer/README.md +1056 -0
  221. package/node_modules/@nebula-spatial/viewer/USD-VISUAL-MATERIAL-SUPPORT.md +89 -0
  222. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.js +19 -0
  223. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.wasm +0 -0
  224. package/node_modules/@nebula-spatial/viewer/dist/asset-ir-DEOK9SqE.js +382 -0
  225. package/node_modules/@nebula-spatial/viewer/dist/assets/ground-grid.d.ts +6 -0
  226. package/node_modules/@nebula-spatial/viewer/dist/assets/source-types.d.ts +19 -0
  227. package/node_modules/@nebula-spatial/viewer/dist/assets/types.d.ts +393 -0
  228. package/node_modules/@nebula-spatial/viewer/dist/assets/usd-worker-Bom5cjz3.js +1392 -0
  229. package/node_modules/@nebula-spatial/viewer/dist/cad/text.d.ts +2 -0
  230. package/node_modules/@nebula-spatial/viewer/dist/cad/types.d.ts +368 -0
  231. package/node_modules/@nebula-spatial/viewer/dist/index-ByBlfVc0.js +12132 -0
  232. package/node_modules/@nebula-spatial/viewer/dist/index.d.ts +32 -0
  233. package/node_modules/@nebula-spatial/viewer/dist/index.js +26 -0
  234. package/node_modules/@nebula-spatial/viewer/dist/inspection/types.d.ts +112 -0
  235. package/node_modules/@nebula-spatial/viewer/dist/mjcf-visual-DVRa0w90.js +72 -0
  236. package/node_modules/@nebula-spatial/viewer/dist/mujoco-runtime-Dhx6Ua2u.js +463 -0
  237. package/node_modules/@nebula-spatial/viewer/dist/plugins.d.ts +179 -0
  238. package/node_modules/@nebula-spatial/viewer/dist/scene/instances.d.ts +36 -0
  239. package/node_modules/@nebula-spatial/viewer/dist/scene/types.d.ts +258 -0
  240. package/node_modules/@nebula-spatial/viewer/dist/session-B-j6KdA-.js +389 -0
  241. package/node_modules/@nebula-spatial/viewer/dist/session-B4AICTeJ.js +963 -0
  242. package/node_modules/@nebula-spatial/viewer/dist/session-BAG5cDYe.js +9153 -0
  243. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-runtime.d.ts +118 -0
  244. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-wasm-module.d.ts +11 -0
  245. package/node_modules/@nebula-spatial/viewer/dist/simulation/openusd-wasm-module.d.ts +10 -0
  246. package/node_modules/@nebula-spatial/viewer/dist/simulation/physics-runtime-state.d.ts +75 -0
  247. package/node_modules/@nebula-spatial/viewer/dist/simulation/types.d.ts +129 -0
  248. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-inspection.d.ts +66 -0
  249. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-query.d.ts +50 -0
  250. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-resource-policy.d.ts +28 -0
  251. package/node_modules/@nebula-spatial/viewer/dist/types.d.ts +278 -0
  252. package/node_modules/@nebula-spatial/viewer/dist/ui/types.d.ts +48 -0
  253. package/node_modules/@nebula-spatial/viewer/dist/urdf-session-kemAnBn8.js +3231 -0
  254. package/node_modules/@nebula-spatial/viewer/dist/usd-session-QtwGKI7v.js +6771 -0
  255. package/node_modules/@nebula-spatial/viewer/dist/version.d.ts +5 -0
  256. package/node_modules/@nebula-spatial/viewer/dist/viewer.d.ts +2 -0
  257. package/node_modules/@nebula-spatial/viewer/dist/xacro-CYTPS7mh.js +1537 -0
  258. package/node_modules/@nebula-spatial/viewer/openusd/openusd-runtime-manifest.json +15 -0
  259. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.js +14 -0
  260. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.wasm +0 -0
  261. package/node_modules/@nebula-spatial/viewer/package.json +66 -0
  262. package/package.json +87 -6
@@ -0,0 +1,963 @@
1
+ import { DataTexture as N, LinearMipmapLinearFilter as re, LinearFilter as se, LoadingManager as oe, Loader as ae, Texture as C, TextureLoader as ie, LinearSRGBColorSpace as V, SRGBColorSpace as le, RGBAFormat as K, UnsignedByteType as J, NoColorSpace as ce, Mesh as ue, MeshPhysicalMaterial as Z, MeshPhongMaterial as k, MeshLambertMaterial as fe, Color as _, Group as pe, Box3 as de, Vector3 as he } from "three";
2
+ import { DRACOLoader as me } from "three/examples/jsm/loaders/DRACOLoader.js";
3
+ import { GLTFLoader as ge } from "three/examples/jsm/loaders/GLTFLoader.js";
4
+ import { d as Y, a as q, S as ye, b as j, D as we } from "./scene-session-Cy6vDJ1l.js";
5
+ import { TGALoader as be } from "three/examples/jsm/loaders/TGALoader.js";
6
+ import { FBXLoader as xe } from "three/examples/jsm/loaders/FBXLoader.js";
7
+ import { unzlibSync as Ee } from "three/examples/jsm/libs/fflate.module.js";
8
+ const Me = 16 * 1024 * 1024;
9
+ function Q(e, t) {
10
+ if (!e || !t || e * t > Me) throw new Error("Invalid or oversized image dimensions (maximum 16M pixels).");
11
+ }
12
+ function B(e, t, n) {
13
+ if (t < 0 || n < 0 || t + n > e.length) throw new Error("Truncated image payload.");
14
+ }
15
+ function ve(e) {
16
+ const t = new Uint8Array(e);
17
+ B(t, 0, 18);
18
+ const n = new DataView(e), s = t[2], r = t[16], c = n.getUint16(12, !0), i = n.getUint16(14, !0);
19
+ if (Q(c, i), t[1] !== 0 || ![2, 3, 10, 11].includes(s) || !([3, 11].includes(s) ? [8, 16] : [24, 32]).includes(r) || t[17] & 192)
20
+ throw new Error("Unsupported TGA: require non-interleaved 24/32-bit true-color or 8/16-bit grayscale.");
21
+ let f = 18 + t[0];
22
+ B(t, 18, t[0]);
23
+ const h = r / 8, g = c * i;
24
+ if (s === 2 || s === 3) B(t, f, g * h);
25
+ else {
26
+ let o = 0;
27
+ for (; o < g; ) {
28
+ B(t, f, 1);
29
+ const a = t[f++], l = (a & 127) + 1;
30
+ if (o + l > g) throw new Error("Invalid TGA RLE packet length.");
31
+ const d = (a & 128 ? 1 : l) * h;
32
+ B(t, f, d), f += d, o += l;
33
+ }
34
+ }
35
+ return { data: new be().parse(e).data, width: c, height: i };
36
+ }
37
+ function z(e) {
38
+ const t = e >>> 11 & 31, n = e >>> 5 & 63, s = e & 31;
39
+ return [t << 3 | t >>> 2, n << 2 | n >>> 4, s << 3 | s >>> 2, 255];
40
+ }
41
+ function Se(e) {
42
+ const t = new Uint8Array(e);
43
+ B(t, 0, 128);
44
+ const n = new DataView(e), s = (l) => n.getUint32(l, !0);
45
+ if (s(0) !== 542327876 || s(4) !== 124 || s(76) !== 32) throw new Error("Invalid DDS header.");
46
+ const r = s(16), c = s(12);
47
+ if (Q(r, c), s(112) & 2162176 || s(24) > 1) throw new Error("DDS cubemap/volume textures are unsupported.");
48
+ const i = s(80), f = String.fromCharCode(...t.subarray(84, 88)), h = (i & 4) !== 0;
49
+ if (h && !["DXT1", "DXT3", "DXT5"].includes(f)) throw new Error(`Unsupported DDS FourCC: ${f}. Require DXT1/DXT3/DXT5.`);
50
+ const g = new Uint8Array(r * c * 4);
51
+ if (!h) {
52
+ const l = s(88), d = s(92), w = s(96), u = s(100), E = s(104);
53
+ if (!(i & 64) || ![24, 32].includes(l) || w !== 65280 || !(d === 16711680 && u === 255 || d === 255 && u === 16711680) || (l === 24 ? E !== 0 : E !== 0 && E !== 4278190080)) throw new Error("Unsupported DDS RGB bit masks.");
54
+ const U = l / 8, M = s(8) & 8 ? s(20) : r * U;
55
+ if (M < r * U) throw new Error("Invalid DDS row pitch.");
56
+ B(t, 128, M * c);
57
+ for (let b = 0; b < c; b++) for (let I = 0; I < r; I++) {
58
+ const A = 128 + b * M + I * U, S = (b * r + I) * 4;
59
+ g[S] = t[A + (d === 255 ? 0 : 2)], g[S + 1] = t[A + 1], g[S + 2] = t[A + (u === 255 ? 0 : 2)], g[S + 3] = E && i & 1 ? t[A + 3] : 255;
60
+ }
61
+ return { data: g, width: r, height: c };
62
+ }
63
+ const y = f === "DXT1" ? 8 : 16, o = Math.ceil(r / 4), a = Math.ceil(c / 4);
64
+ B(t, 128, o * a * y);
65
+ for (let l = 0; l < a; l++) for (let d = 0; d < o; d++) {
66
+ const w = 128 + (l * o + d) * y, u = w + (y === 8 ? 0 : 8), E = n.getUint16(u, !0), U = n.getUint16(u + 2, !0), M = [z(E), z(U)], b = f !== "DXT1" || E > U;
67
+ M.push([0, 1, 2].map((S) => Math.floor(b ? (2 * M[0][S] + M[1][S]) / 3 : (M[0][S] + M[1][S]) / 2)).concat(255)), M.push(b ? [0, 1, 2].map((S) => Math.floor((M[0][S] + 2 * M[1][S]) / 3)).concat(255) : [0, 0, 0, 0]);
68
+ const I = s(u + 4), A = [t[w], t[w + 1]];
69
+ if (f === "DXT5") {
70
+ const S = A[0] > A[1] ? 6 : 4;
71
+ for (let m = 1; m <= S; m++) A.push(Math.floor(((S + 1 - m) * A[0] + m * A[1]) / (S + 1)));
72
+ S === 4 && A.push(0, 255);
73
+ }
74
+ for (let S = 0; S < 16; S++) {
75
+ const m = d * 4 + S % 4, v = l * 4 + Math.floor(S / 4);
76
+ if (m >= r || v >= c) continue;
77
+ const x = M[I >>> 2 * S & 3], T = (v * r + m) * 4;
78
+ if (g.set(x, T), f === "DXT3" && (g[T + 3] = (t[w + Math.floor(S / 2)] >>> S % 2 * 4 & 15) * 17), f === "DXT5") {
79
+ const D = S * 3, p = w + 2 + Math.floor(D / 8), F = t[p] | (p + 1 < w + 8 ? t[p + 1] : 0) << 8;
80
+ g[T + 3] = A[F >>> D % 8 & 7];
81
+ }
82
+ }
83
+ }
84
+ return { data: g, width: r, height: c };
85
+ }
86
+ function Te(e, t) {
87
+ const n = t === "tga" ? ve(e) : Se(e), s = new Uint8Array(n.data.length), r = n.width * 4;
88
+ for (let i = 0; i < n.height; i++) s.set(n.data.subarray(i * r, (i + 1) * r), (n.height - 1 - i) * r);
89
+ const c = new N(s, n.width, n.height);
90
+ return c.flipY = !1, c.generateMipmaps = !0, c.minFilter = re, c.magFilter = se, c.needsUpdate = !0, c;
91
+ }
92
+ async function Ae(e, t, n) {
93
+ t.signal.throwIfAborted();
94
+ const s = new AbortController(), r = s.signal, c = () => s.abort(t.signal.reason);
95
+ t.signal.addEventListener("abort", c, { once: !0 });
96
+ const i = (w, u) => new Promise((E, U) => {
97
+ let M = !1;
98
+ const b = () => {
99
+ M || (M = !0, U(r.reason));
100
+ };
101
+ r.aborted ? b() : r.addEventListener("abort", b, { once: !0 }), w.then((I) => {
102
+ r.removeEventListener("abort", b), M ? u == null || u(I) : (M = !0, E(I));
103
+ }, (I) => {
104
+ r.removeEventListener("abort", b), M || (M = !0, U(I));
105
+ });
106
+ }), f = [], h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), y = [], o = new oe(), a = async (w) => {
107
+ var A;
108
+ if (/^(blob:|data:)/i.test(w))
109
+ return w.startsWith("blob:") && g.add(w), w;
110
+ const u = [...new Set([...n.textures.values()].map((S) => S.path).filter(Boolean))], E = (S) => S.replaceAll("\\", "/").replace(/^\.\//, ""), U = E(w);
111
+ let M = u.filter((S) => E(S) === U);
112
+ if (M.length || (M = u.filter((S) => E(S).split("/").pop() === U.split("/").pop())), M.length > 1) throw new Error(`FBX texture path is ambiguous: ${w}`);
113
+ const b = E(M[0] ?? w), I = t.original;
114
+ if (typeof I == "object" && I !== null && "kind" in I && I.kind === "files") {
115
+ const S = ((A = t.entryPath) == null ? void 0 : A.replace(/[^/]*$/, "")) ?? "", m = (T) => {
116
+ const D = [];
117
+ for (const p of E(T).split("/"))
118
+ p === ".." ? D.pop() : p && p !== "." && D.push(p);
119
+ return D.join("/");
120
+ }, v = I.files.filter((T) => m(T.path) === m(S + b));
121
+ if (v.length === 1) return t.resolve(v[0].path);
122
+ const x = I.files.filter((T) => m(T.path).split("/").pop() === b.split("/").pop());
123
+ if (x.length === 1) return t.resolve(x[0].path);
124
+ if (x.length > 1) throw new Error(`FBX texture path is ambiguous: ${b}`);
125
+ if (!t.hasResourceResolver) throw new Error(`FBX texture is missing from the selected files: ${b}`);
126
+ }
127
+ if (/^[A-Za-z]:\//.test(b) && !t.hasResourceResolver) throw new Error(`FBX texture uses an unavailable local path: ${b}`);
128
+ if (!t.baseUrl && !t.hasResourceResolver && !/^https?:/i.test(b)) throw new Error(`FBX external texture requires a file package or baseUrl: ${b}`);
129
+ return t.resolve(b);
130
+ };
131
+ class l extends ae {
132
+ constructor(u) {
133
+ super(o), this.binaryFormat = u;
134
+ }
135
+ load(u, E, U, M) {
136
+ const b = this.binaryFormat ? new N() : new C();
137
+ h.add(b);
138
+ const I = (async () => {
139
+ const A = await i(a(u));
140
+ r.throwIfAborted();
141
+ const S = await fetch(A, { signal: r });
142
+ if (!S.ok) throw new Error(`FBX texture request failed (${S.status}): ${u}`);
143
+ if (this.binaryFormat) {
144
+ const v = await S.arrayBuffer();
145
+ r.throwIfAborted();
146
+ let x;
147
+ try {
148
+ x = Te(v, this.binaryFormat);
149
+ } catch (T) {
150
+ throw new Error(`FBX texture decode failed (${this.binaryFormat}): ${u}: ${String(T)}`, { cause: T });
151
+ }
152
+ b.image = x.image, b.flipY = x.flipY, b.generateMipmaps = x.generateMipmaps, b.minFilter = x.minFilter, b.magFilter = x.magFilter, b.format = x.format, b.type = x.type, x.dispose(), b.needsUpdate = !0, E == null || E(b);
153
+ return;
154
+ }
155
+ const m = URL.createObjectURL(await S.blob());
156
+ try {
157
+ const v = new ie().loadAsync(m).catch((T) => {
158
+ const D = T instanceof Error ? `: ${T.message}` : "";
159
+ throw new Error(`FBX texture decode failed: ${u}${D}`, { cause: T });
160
+ }), x = await i(v, (T) => {
161
+ T.dispose();
162
+ });
163
+ b.image = x.image, x.dispose(), r.throwIfAborted(), b.needsUpdate = !0, E == null || E(b);
164
+ } finally {
165
+ URL.revokeObjectURL(m);
166
+ }
167
+ })().catch((A) => {
168
+ if (r.aborted) throw A;
169
+ y.push(A instanceof Error ? A.message : String(A)), console.warn(`[viewer] FBX texture skipped: ${u}`, A), M == null || M(A);
170
+ });
171
+ return I.catch(() => {
172
+ }), f.push(I), b;
173
+ }
174
+ }
175
+ o.addHandler(/\.tga$/i, new l("tga")), o.addHandler(/\.dds$/i, new l("dds")), o.addHandler(/.*/, new l());
176
+ let d;
177
+ try {
178
+ return d = new xe(o).parse(e, ""), await Promise.all(f), t.signal.throwIfAborted(), { root: d, textures: h, textureFailures: y };
179
+ } catch (w) {
180
+ if (s.abort(w), await Promise.allSettled(f), d) {
181
+ const { disposeModelResources: u } = await import("./scene-session-Cy6vDJ1l.js").then((E) => E.r);
182
+ u(d, h);
183
+ } else for (const u of h) u.dispose();
184
+ throw w;
185
+ } finally {
186
+ t.signal.removeEventListener("abort", c);
187
+ for (const w of g) URL.revokeObjectURL(w);
188
+ }
189
+ }
190
+ const P = "Kaydara FBX Binary \0", Fe = /(?:^|[\r\n])\s*P:\s*"UpAxis"\s*,\s*"int"\s*,\s*"Integer"\s*,\s*""\s*,\s*(-?\d+)/i, Re = /(?:^|[\r\n])\s*P:\s*"UpAxisSign"\s*,\s*"int"\s*,\s*"Integer"\s*,\s*""\s*,\s*(-?\d+)/i;
191
+ function Ue(e) {
192
+ try {
193
+ const t = new Uint8Array(e), n = Ie(t) ? Oe(e) : De(new TextDecoder().decode(t));
194
+ return !n || n.sign !== 1 ? null : n.axis === 1 ? "y" : n.axis === 2 ? "z" : null;
195
+ } catch {
196
+ return null;
197
+ }
198
+ }
199
+ function Ie(e) {
200
+ if (e.byteLength < P.length) return !1;
201
+ for (let t = 0; t < P.length; t += 1)
202
+ if (e[t] !== P.charCodeAt(t)) return !1;
203
+ return !0;
204
+ }
205
+ function De(e) {
206
+ var r, c;
207
+ const t = Number.parseInt(((r = Fe.exec(e)) == null ? void 0 : r[1]) ?? "", 10);
208
+ if (!Number.isInteger(t)) return null;
209
+ const n = (c = Re.exec(e)) == null ? void 0 : c[1], s = n === void 0 ? 1 : Number.parseInt(n, 10);
210
+ return Number.isInteger(s) ? { axis: t, sign: s } : null;
211
+ }
212
+ function Oe(e) {
213
+ const t = new DataView(e);
214
+ if (t.byteLength < 27) return null;
215
+ const n = t.getUint32(23, !0) >= 7500;
216
+ let s = 27;
217
+ for (; s < t.byteLength; ) {
218
+ const r = X(t, s, n, !1);
219
+ if (!r) break;
220
+ if (r.name === "GlobalSettings") return ee(t, r.childrenOffset, r.endOffset, n);
221
+ s = r.endOffset;
222
+ }
223
+ return null;
224
+ }
225
+ function ee(e, t, n, s) {
226
+ let r = t, c = null, i = 1;
227
+ for (; r < n; ) {
228
+ const f = X(e, r, s, !0);
229
+ if (!f) break;
230
+ if (f.name === "P") {
231
+ const [h, , , , g] = f.properties;
232
+ h === "UpAxis" && typeof g == "number" && (c = g), h === "UpAxisSign" && typeof g == "number" && (i = g);
233
+ }
234
+ if (f.childrenOffset < f.endOffset) {
235
+ const h = ee(e, f.childrenOffset, f.endOffset, s);
236
+ h && (c ?? (c = h.axis), i = h.sign);
237
+ }
238
+ r = f.endOffset;
239
+ }
240
+ return c === null ? null : { axis: c, sign: i };
241
+ }
242
+ function X(e, t, n, s) {
243
+ const r = n ? 25 : 13;
244
+ if (t + r > e.byteLength) return null;
245
+ const c = $(e, t, n), i = $(e, t + (n ? 8 : 4), n), f = $(e, t + (n ? 16 : 8), n), h = e.getUint8(t + (n ? 24 : 12));
246
+ if (c === 0) return null;
247
+ const g = t + r, y = g + h, o = y + f;
248
+ if (c <= t || c > e.byteLength || o > c) throw new Error("Invalid FBX node bounds.");
249
+ const a = new TextDecoder().decode(new Uint8Array(e.buffer, e.byteOffset + g, h)), l = [];
250
+ if (s) {
251
+ let d = y;
252
+ for (let w = 0; w < i; w += 1) {
253
+ const u = Be(e, d);
254
+ if (l.push(u.value), d = u.nextOffset, d > o) return null;
255
+ }
256
+ }
257
+ return { name: a, endOffset: c, childrenOffset: o, properties: l };
258
+ }
259
+ function $(e, t, n) {
260
+ if (!n) return e.getUint32(t, !0);
261
+ const s = e.getBigUint64(t, !0);
262
+ if (s > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error("FBX offset exceeds the safe integer range.");
263
+ return Number(s);
264
+ }
265
+ function Be(e, t) {
266
+ const n = String.fromCharCode(e.getUint8(t));
267
+ switch (n) {
268
+ case "Y":
269
+ return { value: e.getInt16(t + 1, !0), nextOffset: t + 3 };
270
+ case "C":
271
+ return { value: e.getUint8(t + 1) !== 0, nextOffset: t + 2 };
272
+ case "I":
273
+ return { value: e.getInt32(t + 1, !0), nextOffset: t + 5 };
274
+ case "F":
275
+ return { value: e.getFloat32(t + 1, !0), nextOffset: t + 5 };
276
+ case "D":
277
+ return { value: e.getFloat64(t + 1, !0), nextOffset: t + 9 };
278
+ case "L":
279
+ return { value: Number(e.getBigInt64(t + 1, !0)), nextOffset: t + 9 };
280
+ case "S":
281
+ case "R": {
282
+ const s = e.getUint32(t + 1, !0), r = t + 5, c = new Uint8Array(e.buffer, e.byteOffset + r, s);
283
+ return { value: n === "S" ? new TextDecoder().decode(c) : c, nextOffset: r + s };
284
+ }
285
+ case "f":
286
+ case "d":
287
+ case "l":
288
+ case "i":
289
+ case "b":
290
+ case "c": {
291
+ const s = e.getUint32(t + 9, !0);
292
+ return { value: null, nextOffset: t + 13 + s };
293
+ }
294
+ default:
295
+ throw new Error(`Unsupported FBX property type: ${n}`);
296
+ }
297
+ }
298
+ const L = /* @__PURE__ */ new Set(["Definitions", "ObjectType", "PropertyTemplate", "Objects", "Material", "Properties70", "Connections", "Texture", "Video", "Geometry", "LayerElementUV", "LayeredTexture", "BlendModes", "Alphas"]), te = /* @__PURE__ */ new Set(["P", "C", "RelativeFilename", "FileName", "Filename", "ShadingModel", "UVSet", "Scaling", "Translation", "Rotation", "RotationPivot", "ScalingPivot", "Name", "UV", "a"]);
299
+ function _e(e) {
300
+ var U, M, b, I, A, S;
301
+ const t = new Uint8Array(e), s = new TextDecoder().decode(t.subarray(0, 21)) === "Kaydara FBX Binary \0" ? Xe(e) : Ce(new TextDecoder().decode(t)), r = (m) => {
302
+ var v;
303
+ return new Map(
304
+ (((v = m == null ? void 0 : m.children.find((x) => x.name === "Properties70")) == null ? void 0 : v.children) ?? []).filter((x) => x.name === "P" && typeof x.values[0] == "string").map((x) => [x.values[0], x.values.slice(4)])
305
+ );
306
+ }, c = s.find((m) => m.name === "Definitions"), i = c == null ? void 0 : c.children.find((m) => m.name === "ObjectType" && m.values[0] === "Material"), f = (i == null ? void 0 : i.children.filter((m) => m.name === "PropertyTemplate")) ?? [], h = ((U = s.find((m) => m.name === "Connections")) == null ? void 0 : U.children.filter((m) => m.name === "C")) ?? [], g = ((M = s.find((m) => m.name === "Objects")) == null ? void 0 : M.children) ?? [], y = /* @__PURE__ */ new Map(), o = (m, v) => {
307
+ var x;
308
+ return (x = m == null ? void 0 : m.children.find((T) => T.name === v)) == null ? void 0 : x.values[0];
309
+ };
310
+ for (const m of g.filter((v) => v.name === "Texture")) {
311
+ const v = Number(m.values[0]), x = (b = h.find((R) => R.values[0] === "OO" && R.values[2] === v)) == null ? void 0 : b.values[1], T = g.find((R) => R.name === "Video" && R.values[0] === x), D = String(o(T, "RelativeFilename") || o(m, "RelativeFilename") || o(T, "Filename") || o(m, "FileName") || ""), p = r(m);
312
+ for (const R of ["Scaling", "Translation", "Rotation", "RotationPivot", "ScalingPivot"]) {
313
+ const O = (I = m.children.find((ne) => ne.name === R)) == null ? void 0 : I.values;
314
+ O && p.set(R, O);
315
+ }
316
+ const F = o(m, "UVSet") ?? ((A = p.get("UVSet")) == null ? void 0 : A[0]);
317
+ y.set(v, { id: v, path: D, values: p, uvSet: typeof F == "string" ? F : null });
318
+ }
319
+ const a = /* @__PURE__ */ new Map(), l = (m, v) => {
320
+ var D;
321
+ const x = m.children.find((p) => p.name === v), T = ((D = x == null ? void 0 : x.children.find((p) => p.name === "a")) == null ? void 0 : D.values) ?? (x == null ? void 0 : x.values) ?? [];
322
+ if (T.some((p) => typeof p != "number" || !Number.isFinite(p))) throw new Error(`Invalid FBX layered ${v}.`);
323
+ return T;
324
+ };
325
+ for (const m of g.filter((v) => v.name === "LayeredTexture")) {
326
+ const v = Number(m.values[0]);
327
+ if (!Number.isSafeInteger(v)) throw new Error("Invalid FBX layered texture ID.");
328
+ a.set(v, {
329
+ id: v,
330
+ name: String(m.values[1] ?? ""),
331
+ textureIds: h.filter((x) => x.values[0] === "OO" && x.values[2] === v).map((x) => Number(x.values[1])),
332
+ blendModes: l(m, "BlendModes"),
333
+ alphas: l(m, "Alphas")
334
+ });
335
+ }
336
+ const d = /* @__PURE__ */ new Map();
337
+ for (const m of ((S = s.find((v) => v.name === "Objects")) == null ? void 0 : S.children) ?? []) {
338
+ if (m.name !== "Material") continue;
339
+ const v = m.values[0];
340
+ if (typeof v != "number" || !Number.isSafeInteger(v)) throw new Error("Invalid FBX material ID.");
341
+ const x = r(m), T = h.filter((R) => R.values[0] === "OP" && R.values[2] === v).map((R) => String(R.values[3])), D = h.filter((R) => R.values[0] === "OP" && R.values[2] === v).map((R) => ({ id: Number(R.values[1]), role: String(R.values[3]) })), p = String(o(m, "ShadingModel") ?? "phong").toLowerCase(), F = r(f.find((R) => String(R.values[0]).toLowerCase() === `fbxsurface${p}`));
342
+ d.set(v, {
343
+ textureConnections: D,
344
+ shadingModel: p,
345
+ id: v,
346
+ name: String(m.values[1] ?? ""),
347
+ ownValues: x,
348
+ values: new Map([...F, ...x]),
349
+ textureRoles: T
350
+ });
351
+ }
352
+ const w = /* @__PURE__ */ new Map();
353
+ for (const m of h) {
354
+ const [v, x, T] = m.values;
355
+ if (v !== "OO" || typeof x != "number" || typeof T != "number" || !d.has(x)) continue;
356
+ const D = w.get(T) ?? [];
357
+ D.push(x), w.set(T, D);
358
+ }
359
+ const u = /* @__PURE__ */ new Map();
360
+ for (const m of g.filter((v) => v.name === "Geometry")) {
361
+ const v = new Map(m.children.filter((T) => T.name === "LayerElementUV").map((T) => [Number(T.values[0]), T])), x = [];
362
+ for (let T = 0; v.has(T); T++) {
363
+ const D = v.get(T);
364
+ D.children.some((p) => p.name === "UV") && x.push(String(o(D, "Name") ?? ""));
365
+ }
366
+ u.set(Number(m.values[0]), x);
367
+ }
368
+ const E = /* @__PURE__ */ new Map();
369
+ for (const m of h) {
370
+ const [v, x, T] = m.values;
371
+ v === "OO" && typeof x == "number" && typeof T == "number" && u.has(x) && E.set(T, u.get(x));
372
+ }
373
+ return { materials: d, modelMaterials: w, textures: y, modelUvSets: E, layeredTextures: a };
374
+ }
375
+ function Xe(e) {
376
+ const t = new DataView(e);
377
+ if (t.byteLength < 27) throw new Error("Truncated FBX header.");
378
+ const n = t.getUint32(23, !0) >= 7500, s = (r, c, i) => {
379
+ if (i > 16) throw new Error("Excessive FBX metadata nesting.");
380
+ const f = [];
381
+ let h = r;
382
+ for (; h < c; ) {
383
+ const g = X(t, h, n, !1);
384
+ if (!g) break;
385
+ if (g.endOffset > c) throw new Error("FBX child extends past its parent.");
386
+ if (L.has(g.name) || te.has(g.name)) {
387
+ const y = X(t, h, n, g.name !== "UV");
388
+ f.push({ name: y.name, values: ["BlendModes", "Alphas"].includes(y.name) ? Le(t, h, n, y.childrenOffset) : [...y.properties], children: L.has(y.name) ? s(y.childrenOffset, y.endOffset, i + 1) : [] });
389
+ }
390
+ h = g.endOffset;
391
+ }
392
+ return f;
393
+ };
394
+ return s(27, t.byteLength, 0);
395
+ }
396
+ function Ce(e) {
397
+ const t = /"(?:\\.|[^"\\])*"|;[^\r\n]*|\r?\n|[^\S\r\n]+|[{}:,]|[^\s{}:,;]+/g;
398
+ let n = null;
399
+ const s = () => {
400
+ var i;
401
+ if (n !== null) {
402
+ const f = n;
403
+ return n = null, f;
404
+ }
405
+ for (; ; ) {
406
+ const f = ((i = t.exec(e)) == null ? void 0 : i[0]) ?? null;
407
+ if (f === null) return null;
408
+ if (!(f.startsWith(";") || /^[^\S\r\n]+$/.test(f)))
409
+ return f;
410
+ }
411
+ }, r = (i) => i.startsWith('"') ? i.slice(1, -1).replace(/\\(["\\])/g, "$1") : Number.isFinite(Number(i)) ? Number(i) : i, c = (i) => {
412
+ if (i > 16) throw new Error("Excessive FBX metadata nesting.");
413
+ const f = [];
414
+ for (; ; ) {
415
+ const h = s();
416
+ if (h === null) {
417
+ if (i) throw new Error("Unclosed FBX block.");
418
+ return f;
419
+ }
420
+ if (h === "}") {
421
+ if (!i) throw new Error("Unexpected FBX closing brace.");
422
+ return f;
423
+ }
424
+ if (h === `
425
+ ` || h === `\r
426
+ `) continue;
427
+ if (s() !== ":") throw new Error("Malformed ASCII FBX metadata.");
428
+ const g = L.has(h) || te.has(h), y = [];
429
+ let o = [];
430
+ for (; ; ) {
431
+ const a = s();
432
+ if (a === null || a === `
433
+ ` || a === `\r
434
+ `) break;
435
+ if (a === "}") {
436
+ n = a;
437
+ break;
438
+ }
439
+ if (a === "{") {
440
+ if (L.has(h)) o = c(i + 1);
441
+ else {
442
+ let l = 1;
443
+ for (; l; ) {
444
+ const d = s();
445
+ if (d === null) throw new Error("Unclosed FBX block.");
446
+ d === "{" && l++, d === "}" && l--;
447
+ }
448
+ }
449
+ break;
450
+ }
451
+ g && a !== "," && y.push(r(a));
452
+ }
453
+ g && f.push({ name: h, values: y, children: o });
454
+ }
455
+ };
456
+ return c(0);
457
+ }
458
+ function Le(e, t, n, s) {
459
+ const r = n ? 25 : 13;
460
+ let c = t + r + e.getUint8(t + r - 1);
461
+ if (c === s) return [];
462
+ const i = String.fromCharCode(e.getUint8(c));
463
+ if (!["i", "d", "f"].includes(i)) return [...X(e, t, n, !0).properties];
464
+ if (c + 13 > s) throw new Error("Truncated FBX layered array header.");
465
+ const f = e.getUint32(c + 1, !0), h = e.getUint32(c + 5, !0), g = e.getUint32(c + 9, !0), y = i === "d" ? 8 : 4;
466
+ if (f > 4096 || c + 13 + g !== s || ![0, 1].includes(h)) throw new Error("Invalid FBX layered array bounds.");
467
+ const o = new Uint8Array(e.buffer, e.byteOffset + c + 13, g), a = h === 1 ? Ee(o, { out: new Uint8Array(f * y) }) : o;
468
+ if (a.length !== f * y) throw new Error("Invalid FBX layered array size.");
469
+ const l = new DataView(a.buffer, a.byteOffset, a.byteLength);
470
+ return Array.from({ length: f }, (d, w) => i === "i" ? l.getInt32(w * y, !0) : i === "d" ? l.getFloat64(w * y, !0) : l.getFloat32(w * y, !0));
471
+ }
472
+ const H = (e) => e <= 0.04045 ? e / 12.92 : ((e + 0.055) / 1.055) ** 2.4, Ne = (e) => e <= 31308e-7 ? e * 12.92 : 1.055 * e ** (1 / 2.4) - 0.055, Pe = /* @__PURE__ */ new Set([0, 1, 2, 4, 5]), $e = 4 * 1024 * 1024;
473
+ function W(e) {
474
+ const t = e.image, n = (t == null ? void 0 : t.naturalWidth) || (t == null ? void 0 : t.width), s = (t == null ? void 0 : t.naturalHeight) || (t == null ? void 0 : t.height);
475
+ if (!n || !s || n * s > $e) throw new Error("missing image or image exceeds 4M pixels");
476
+ let r;
477
+ if (t.data) {
478
+ if (e.format !== K || e.type !== J || !(t.data instanceof Uint8Array) || t.data.length !== n * s * 4) throw new Error("require RGBA8 source");
479
+ r = t.data;
480
+ } else {
481
+ const i = document.createElement("canvas");
482
+ i.width = n, i.height = s;
483
+ const f = i.getContext("2d", { willReadFrequently: !0 });
484
+ if (!f) throw new Error("canvas readback unavailable");
485
+ f.drawImage(e.image, 0, 0), r = f.getImageData(0, 0, n, s).data;
486
+ }
487
+ const c = new Uint8Array(n * s * 4);
488
+ for (let i = 0; i < s; i++) for (let f = 0; f < n * 4; f++) c[(e.flipY ? s - i - 1 : i) * n * 4 + f] = r[i * n * 4 + f];
489
+ return { data: c, width: n, height: s };
490
+ }
491
+ function Ge(e, t, n) {
492
+ if (e.issues.some((o) => o.code !== "LAYERED_TEXTURE_NOT_COMPOSITED")) throw new Error("incompatible layer graph or coordinates");
493
+ if (e.layers.length < 1 || e.layers.length > 8) throw new Error("require 1–8 layers");
494
+ if (!e.layers.every((o) => o.blendMode !== null && Pe.has(o.blendMode))) throw new Error("unsupported blend mode");
495
+ const s = e.layers.map((o) => {
496
+ const a = [...n].find((l) => l.ID === o.textureId);
497
+ if (!a) throw new Error(`missing decoded texture ${o.textureId}`);
498
+ return a;
499
+ }), r = s[0], c = (o) => JSON.stringify([
500
+ o.wrapS,
501
+ o.wrapT,
502
+ o.minFilter,
503
+ o.magFilter,
504
+ o.anisotropy,
505
+ o.channel,
506
+ o.mapping,
507
+ o.matrixAutoUpdate,
508
+ o.offset.toArray(),
509
+ o.repeat.toArray(),
510
+ o.center.toArray(),
511
+ o.rotation,
512
+ o.matrix.elements
513
+ ]);
514
+ if (s.some((o) => c(o) !== c(r))) throw new Error("incompatible sampling state");
515
+ if (e.layers.some((o) => !t.textures.has(o.textureId))) throw new Error("missing source metadata");
516
+ const i = W(r), f = i.width * i.height;
517
+ if (e.layers[0].alpha !== 1 || i.data.some((o, a) => a % 4 === 3 && o !== 255)) throw new Error("base layer must be fully opaque with weight 1");
518
+ const h = new Float32Array(f * 3);
519
+ for (let o = 0; o < f; o++) for (let a = 0; a < 3; a++) h[o * 3 + a] = r.colorSpace === V ? i.data[o * 4 + a] / 255 : H(i.data[o * 4 + a] / 255);
520
+ for (let o = 1; o < s.length; o++) {
521
+ const a = s[o], l = W(a), d = e.layers[o];
522
+ if (l.width !== i.width || l.height !== i.height) throw new Error("layer dimensions differ");
523
+ for (let w = 0; w < f; w++) {
524
+ const u = d.alpha * l.data[w * 4 + 3] / 255;
525
+ for (let E = 0; E < 3; E++) {
526
+ const U = h[w * 3 + E], M = l.data[w * 4 + E] / 255, b = a.colorSpace === V ? M : H(M), I = d.blendMode === 1 ? Math.min(1, U + b) : d.blendMode === 2 ? U * b : b;
527
+ h[w * 3 + E] = U + (I - U) * u;
528
+ }
529
+ }
530
+ }
531
+ const g = new Uint8Array(f * 4);
532
+ for (let o = 0; o < f; o++) g[o * 4 + 3] = 255;
533
+ for (let o = 0; o < f; o++) for (let a = 0; a < 3; a++) g[o * 4 + a] = Math.round(255 * Math.min(1, Math.max(0, Ne(h[o * 3 + a]))));
534
+ const y = new N(g, i.width, i.height);
535
+ return y.colorSpace = le, y.generateMipmaps = r.generateMipmaps, y.wrapS = r.wrapS, y.wrapT = r.wrapT, y.minFilter = r.minFilter, y.magFilter = r.magFilter, y.anisotropy = r.anisotropy, y.offset.copy(r.offset), y.repeat.copy(r.repeat), y.center.copy(r.center), y.rotation = r.rotation, y.matrix.copy(r.matrix), y.matrixAutoUpdate = r.matrixAutoUpdate, y.channel = r.channel, y.mapping = r.mapping, y.userData.fbxLayerBaseId = e.layers[0].textureId, y.needsUpdate = !0, y;
536
+ }
537
+ function Ve(e, t) {
538
+ return e.textureConnections.flatMap((n) => {
539
+ var o;
540
+ const s = (o = t.layeredTextures) == null ? void 0 : o.get(n.id);
541
+ if (!s) return [];
542
+ const r = [], c = (a, l) => r.push({ status: "unsupported", code: a, source: `layered:${s.id}:${l}`, target: n.role });
543
+ c("LAYERED_TEXTURE_NOT_COMPOSITED", "preview uses loader fallback; layers have not been composited");
544
+ const i = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set(), h = [], g = (a, l) => {
545
+ var w;
546
+ if (i.has(a)) {
547
+ c("LAYERED_TEXTURE_CYCLE", String(a));
548
+ return;
549
+ }
550
+ if (l > 32 || f.size >= 4096) {
551
+ c("LAYERED_TEXTURE_GRAPH_LIMIT", String(a));
552
+ return;
553
+ }
554
+ if (f.has(a)) return;
555
+ const d = (w = t.layeredTextures) == null ? void 0 : w.get(a);
556
+ if (!d) {
557
+ t.textures.has(a) ? h.push(a) : c("LAYERED_TEXTURE_MISSING_SOURCE", String(a)), f.add(a);
558
+ return;
559
+ }
560
+ l && c("LAYERED_TEXTURE_NESTED", String(a)), d.textureIds.length || c("LAYERED_TEXTURE_EMPTY", String(a)), (d.blendModes.length !== d.textureIds.length || d.alphas.length !== d.textureIds.length) && c("LAYERED_TEXTURE_METADATA_MISMATCH", `${a}:sources=${d.textureIds.length},modes=${d.blendModes.length},alphas=${d.alphas.length}`), d.blendModes.some((u) => !Number.isInteger(u) || u < 0) && c("LAYERED_TEXTURE_INVALID_MODE", String(a)), d.alphas.some((u) => !Number.isFinite(u) || u < 0 || u > 1) && c("LAYERED_TEXTURE_INVALID_ALPHA", String(a)), i.add(a);
561
+ for (const u of d.textureIds) g(u, l + 1);
562
+ i.delete(a), f.add(a);
563
+ };
564
+ return g(s.id, 0), new Set(h.map((a) => {
565
+ const l = t.textures.get(a);
566
+ return JSON.stringify([l.uvSet ?? "default", ...["Translation", "Scaling", "Rotation", "RotationPivot", "ScalingPivot"].map((d) => l.values.get(d) ?? null)]);
567
+ })).size > 1 && c("LAYERED_TEXTURE_COORDINATES_DIFFER", "UV sets or transforms differ; direct pixel blending is unsafe"), [{ id: s.id, role: n.role, layers: s.textureIds.map((a, l) => ({ textureId: a, blendMode: s.blendModes[l] ?? null, alpha: s.alphas[l] ?? null })), issues: r }];
568
+ });
569
+ }
570
+ const ke = {
571
+ DiffuseColor: "map",
572
+ "Maya|TEX_color_map": "map",
573
+ NormalMap: "normalMap",
574
+ "Maya|TEX_normal_map": "normalMap",
575
+ Bump: "bumpMap",
576
+ EmissiveColor: "emissiveMap",
577
+ DisplacementColor: "displacementMap",
578
+ "Maya|TEX_ao_map": "aoMap",
579
+ ReflectionFactor: "metalnessMap",
580
+ ReflectionColor: "metalnessMap",
581
+ ShininessExponent: "roughnessMap",
582
+ SpecularFactor: "specularIntensityMap",
583
+ SpecularColor: "specularIntensityMap",
584
+ TransparentColor: "alphaMap",
585
+ TransparencyFactor: "alphaMap"
586
+ };
587
+ function Ye(e, t, n, s, r, c) {
588
+ var a;
589
+ const i = (a = s.modelUvSets) == null ? void 0 : a.get(e.ID ?? NaN), f = [], h = [], g = /* @__PURE__ */ new Set();
590
+ for (const l of n.textureConnections) {
591
+ const d = ke[l.role], w = d ? t[d] : void 0, u = s.textures.get(l.id) ?? (w instanceof C ? s.textures.get(w.userData.fbxLayerBaseId) : void 0);
592
+ if (!d || !u || g.has(d)) continue;
593
+ g.add(d);
594
+ const E = t[d];
595
+ if (!(E instanceof C)) continue;
596
+ const U = (D, p) => h.push({ status: "unsupported", code: D, source: `texture:${l.id}:${p}`, target: String(d) });
597
+ let M = 0;
598
+ if (u.uvSet) {
599
+ const D = (i == null ? void 0 : i.flatMap((p, F) => p === u.uvSet ? [F] : [])) ?? [];
600
+ if (D.length === 1) M = D[0];
601
+ else if (D.length > 1 || u.uvSet !== "default") {
602
+ U("UV_SET_UNRESOLVED", `UVSet:${u.uvSet}:${D.length > 1 ? "ambiguous" : "missing"}`);
603
+ continue;
604
+ }
605
+ }
606
+ if (M > 3 || !e.geometry.hasAttribute(M === 0 ? "uv" : `uv${M}`)) {
607
+ U("UV_CHANNEL_UNAVAILABLE", `channel:${M}`);
608
+ continue;
609
+ }
610
+ const b = (D, p) => {
611
+ const F = u.values.get(D);
612
+ return F ? F.length < 2 || !F.every((R) => typeof R == "number" && Number.isFinite(R)) ? (U("TEXTURE_TRANSFORM_INVALID", D), p) : F : p;
613
+ }, I = b("Translation", [E.offset.x, E.offset.y, 0]), A = b("Scaling", [E.repeat.x, E.repeat.y, 1]), S = b("Rotation", [0, 0, 0]), m = b("RotationPivot", [0, 0, 0]), v = b("ScalingPivot", [0, 0, 0]), x = S[0] !== 0 || S[1] !== 0 || m.some((D) => D !== 0) || v.some((D) => D !== 0);
614
+ x && U("TEXTURE_TRANSFORM_UNSUPPORTED", "3D-rotation-or-pivot"), (I[2] || A[2] !== void 0 && A[2] !== 1) && U("TEXTURE_TRANSFORM_UNSUPPORTED", "3D-translation-or-scale");
615
+ const T = x ? 0 : -(S[2] ?? 0) * Math.PI / 180;
616
+ T && h.push({ status: "approximate", code: "TEXTURE_ROTATION_PROFILE", source: `texture:${l.id}:Rotation`, target: "T * Rccw * S; origin pivot" }), (M !== E.channel || I[0] !== E.offset.x || I[1] !== E.offset.y || A[0] !== E.repeat.x || A[1] !== E.repeat.y || T !== E.rotation) && f.push({ slot: d, source: E, channel: M, offset: I, scale: A, rotation: T });
617
+ }
618
+ if (!f.length && !h.length) return t;
619
+ const y = t.clone();
620
+ r(y);
621
+ const o = y.userData.fbxConversionReport;
622
+ o.issues.push(...h);
623
+ for (const l of f) {
624
+ const d = l.source.clone();
625
+ c(d), d.channel = l.channel, d.offset.set(l.offset[0], l.offset[1]), d.repeat.set(l.scale[0], l.scale[1]), d.center.set(0, 0), d.rotation = l.rotation;
626
+ const w = -l.rotation, u = Math.cos(w), E = Math.sin(w);
627
+ d.matrixAutoUpdate = !1, d.matrix.set(
628
+ u * l.scale[0],
629
+ -E * l.scale[1],
630
+ l.offset[0],
631
+ E * l.scale[0],
632
+ u * l.scale[1],
633
+ l.offset[1],
634
+ 0,
635
+ 0,
636
+ 1
637
+ ), y[l.slot] = d, o.mappings.push({ source: `${l.slot}:UV`, target: `uv${l.channel || ""}`, rule: "geometry UV name binding; T * Rccw * S" });
638
+ }
639
+ return y.needsUpdate = !0, y;
640
+ }
641
+ function qe(e, t) {
642
+ return Math.min(1, Math.max(0, e));
643
+ }
644
+ function je(e, t, n, s, r = "r", c = !1) {
645
+ if (!Number.isInteger(t) || !Number.isInteger(n) || t <= 0 || n <= 0 || e.length !== t * n * 4)
646
+ throw new Error("Invalid FBX scalar RGBA dimensions.");
647
+ const i = new Uint8Array(e.length), f = { r: 0, g: 1, b: 2, a: 3 }[r];
648
+ for (let h = 0; h < n; h++) for (let g = 0; g < t; g++) {
649
+ const y = (h * t + g) * 4, o = ((c ? n - h - 1 : h) * t + g) * 4, a = Math.round(255 * qe(e[y + f] / 255));
650
+ i.fill(a, o, o + 4);
651
+ }
652
+ return i;
653
+ }
654
+ function ze(e, t) {
655
+ const n = e.image;
656
+ if (!n) throw new Error("FBX scalar texture has no decoded image.");
657
+ const s = n.naturalWidth || n.width, r = n.naturalHeight || n.height;
658
+ if (!s || !r) throw new Error("FBX scalar texture has no decoded image.");
659
+ let c;
660
+ if (n.data) {
661
+ if (!(n.data instanceof Uint8Array || n.data instanceof Uint8ClampedArray) || e.format !== K || e.type !== J)
662
+ throw new Error("FBX scalar conversion requires 8-bit RGBA pixels.");
663
+ c = n.data;
664
+ } else {
665
+ const f = document.createElement("canvas");
666
+ f.width = s, f.height = r;
667
+ const h = f.getContext("2d", { willReadFrequently: !0 });
668
+ if (!h) throw new Error("FBX scalar texture conversion requires a 2D canvas.");
669
+ h.drawImage(n, 0, 0), c = h.getImageData(0, 0, s, r).data;
670
+ }
671
+ const i = new N(je(c, s, r, t, "r", e.flipY), s, r);
672
+ return i.wrapS = e.wrapS, i.wrapT = e.wrapT, i.offset.copy(e.offset), i.repeat.copy(e.repeat), i.center.copy(e.center), i.rotation = e.rotation, i.matrix.copy(e.matrix), i.matrixAutoUpdate = e.matrixAutoUpdate, i.channel = e.channel, i.magFilter = e.magFilter, i.minFilter = e.minFilter, i.generateMipmaps = e.generateMipmaps, i.anisotropy = e.anisotropy, i.colorSpace = ce, i.needsUpdate = !0, i;
673
+ }
674
+ function He(e, t, n) {
675
+ const s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set(), h = [];
676
+ try {
677
+ e.traverse((a) => {
678
+ if (!(a instanceof ue)) return;
679
+ const l = t == null ? void 0 : t.modelMaterials.get(a.ID ?? NaN), d = (u) => l ? t == null ? void 0 : t.materials.get(l[u]) : void 0, w = (u, E) => {
680
+ const U = d(E), M = We(u, s, U, n, t, r, c);
681
+ return M instanceof Z && U && t ? Ye(a, M, U, t, (b) => i.add(b), (b) => f.add(b)) : M;
682
+ };
683
+ h.push({ mesh: a, material: Array.isArray(a.material) ? a.material.map(w) : w(a.material, 0) });
684
+ });
685
+ } catch (a) {
686
+ for (const [l, d] of s) l !== d && d.dispose();
687
+ for (const l of r.values()) l.dispose();
688
+ for (const l of i) l.dispose();
689
+ for (const l of f) l.dispose();
690
+ for (const l of c.values()) l.dispose();
691
+ throw a;
692
+ }
693
+ for (const { mesh: a, material: l } of h) a.material = l;
694
+ const g = new Set(h.flatMap((a) => Array.isArray(a.material) ? a.material : [a.material]));
695
+ for (const [a, l] of s)
696
+ a !== l && (a.dispose(), g.has(l) || l.dispose());
697
+ const y = /* @__PURE__ */ new Set();
698
+ for (const a of g) for (const l of Object.values(a)) l instanceof C && y.add(l);
699
+ for (const a of r.values()) y.has(a) || a.dispose();
700
+ for (const a of c.values()) y.has(a) || a.dispose();
701
+ const o = [...g].flatMap((a) => a.userData.fbxConversionReport ? [a.userData.fbxConversionReport] : []);
702
+ return e.userData.fbxConversionReports = o, o;
703
+ }
704
+ function We(e, t, n, s, r, c = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map()) {
705
+ var x, T, D;
706
+ const f = t.get(e);
707
+ if (f) return f;
708
+ if (!(e instanceof k) && !(e instanceof fe))
709
+ return t.set(e, e), e;
710
+ const h = e instanceof k ? e : null, g = (p, F) => {
711
+ var O;
712
+ const R = (O = n == null ? void 0 : n.values.get(p)) == null ? void 0 : O[0];
713
+ return typeof R == "number" && Number.isFinite(R) ? R : F;
714
+ }, y = (p, F) => {
715
+ const R = n == null ? void 0 : n.values.get(p);
716
+ return R && R.length >= 3 && R.slice(0, 3).every((O) => typeof O == "number" && Number.isFinite(O)) ? new _().setRGB(R[0], R[1], R[2]) : F.clone();
717
+ }, o = (p) => Math.min(1, Math.max(0, p)), a = o(g("SpecularFactor", 0.25) * 2), l = Math.sqrt(0.08 * a), d = (1 + l) / (1 - l);
718
+ let w = e.opacity;
719
+ if (n && (w = 1 - g("TransparencyFactor", 0), w === 0 || w === 1)) {
720
+ const p = (x = n.ownValues.get("Opacity")) == null ? void 0 : x[0];
721
+ w = typeof p == "number" && Number.isFinite(p) ? p : 1 - y("TransparentColor", new _(0)).r;
722
+ }
723
+ const u = new Z({
724
+ name: e.name,
725
+ // FBX diffuse textures supply the base color (as in Blender's importer),
726
+ // not an additional tint. Multiplying the atlas by DiffuseColor can turn
727
+ // blue atlas regions black when the material's constant color is red.
728
+ color: e.map ? new _(16777215) : y("DiffuseColor", n ? new _(1, 1, 1) : e.color),
729
+ map: e.map,
730
+ emissive: e.emissiveMap ? new _(16777215) : y("EmissiveColor", n ? new _(0) : e.emissive),
731
+ emissiveMap: e.emissiveMap,
732
+ emissiveIntensity: g("EmissiveFactor", n ? 1 : e.emissiveIntensity),
733
+ normalMap: e.normalMap,
734
+ normalMapType: e.normalMapType,
735
+ normalScale: e.normalScale.clone().setScalar(g("BumpFactor", 1)),
736
+ bumpMap: e.bumpMap,
737
+ bumpScale: e.bumpScale,
738
+ displacementMap: e.displacementMap,
739
+ displacementScale: e.displacementScale,
740
+ displacementBias: e.displacementBias,
741
+ aoMap: e.aoMap,
742
+ aoMapIntensity: e.aoMapIntensity,
743
+ alphaMap: e.alphaMap,
744
+ opacity: o(w),
745
+ transparent: e.transparent || w < 1,
746
+ alphaTest: e.alphaTest,
747
+ side: e.side,
748
+ depthTest: e.depthTest,
749
+ depthWrite: e.depthWrite,
750
+ vertexColors: e.vertexColors,
751
+ wireframe: e.wireframe,
752
+ flatShading: e.flatShading,
753
+ metalness: o(g("ReflectionFactor", 0)),
754
+ ior: d,
755
+ specularIntensity: 1,
756
+ // Match Blender's empirical FBX Shininess -> Principled roughness mapping.
757
+ // This is an importer convention, not an exact BRDF conversion.
758
+ roughness: n || h ? o(1 - Math.sqrt(Math.max(0, g("Shininess", n ? 20 : h.shininess))) / 10) : 1
759
+ });
760
+ t.set(e, u);
761
+ const E = (p) => {
762
+ let F = c.get(p);
763
+ return F || (F = ze(p, "identity"), c.set(p, F)), F;
764
+ }, U = n && r ? Ve(n, r) : [], M = [];
765
+ for (const p of U)
766
+ if (!(!["DiffuseColor", "EmissiveColor"].includes(p.role) || !r || !s) && n.textureConnections.filter((F) => F.role === p.role).length === 1)
767
+ try {
768
+ let F = i.get(p.id);
769
+ F || (F = Ge(p, r, s), i.set(p.id, F)), p.role === "DiffuseColor" ? (u.map = F, u.color.setRGB(1, 1, 1)) : (u.emissiveMap = F, u.emissive.setRGB(1, 1, 1)), p.issues = [], M.push(p.id);
770
+ } catch (F) {
771
+ p.issues.push({ status: "unsupported", code: "LAYERED_TEXTURE_BAKE_REJECTED", source: `layered:${p.id}:${F instanceof Error ? F.message : String(F)}`, target: p.role });
772
+ }
773
+ const b = /* @__PURE__ */ new Set(), I = [], A = /* @__PURE__ */ new Set(), S = {
774
+ ReflectionFactor: "metalnessMap",
775
+ ReflectionColor: "metalnessMap",
776
+ ShininessExponent: "roughnessMap",
777
+ SpecularFactor: "specularIntensityMap",
778
+ SpecularColor: "specularIntensityMap",
779
+ TransparentColor: "alphaMap",
780
+ TransparencyFactor: "alphaMap"
781
+ };
782
+ for (const p of (n == null ? void 0 : n.textureConnections) ?? []) {
783
+ if ((T = r == null ? void 0 : r.layeredTextures) != null && T.has(p.id)) continue;
784
+ const F = [...s ?? []].find((O) => O.ID === p.id);
785
+ if (!F) {
786
+ I.push(`texture:${p.id}:unresolved:${p.role}`);
787
+ continue;
788
+ }
789
+ const R = S[p.role];
790
+ if (R && A.has(R)) {
791
+ I.push(`conflicting-input:${p.role}:${R}`);
792
+ continue;
793
+ }
794
+ switch (R && A.add(R), p.role) {
795
+ case "ReflectionFactor":
796
+ case "ReflectionColor":
797
+ u.metalnessMap = E(F), u.metalness = 1, b.add(p.role);
798
+ break;
799
+ case "ShininessExponent":
800
+ u.roughnessMap = E(F), u.roughness = 1, b.add(p.role);
801
+ break;
802
+ case "SpecularFactor":
803
+ case "SpecularColor":
804
+ u.specularIntensityMap = E(F), u.ior = (1 + Math.sqrt(0.08)) / (1 - Math.sqrt(0.08)), u.specularIntensity = 1, b.add(p.role);
805
+ break;
806
+ case "TransparentColor":
807
+ case "TransparencyFactor":
808
+ u.alphaMap = E(F), u.opacity = 1, u.transparent = !0, b.add(p.role);
809
+ break;
810
+ }
811
+ }
812
+ u.userData = { ...e.userData, fbxMaterialId: n == null ? void 0 : n.id };
813
+ const m = (n == null ? void 0 : n.textureRoles.filter((p) => ![
814
+ "DiffuseColor",
815
+ "Maya|TEX_color_map",
816
+ "NormalMap",
817
+ "Maya|TEX_normal_map",
818
+ "Bump",
819
+ "EmissiveColor",
820
+ "DisplacementColor",
821
+ "TransparentColor",
822
+ "TransparencyFactor",
823
+ "Maya|TEX_ao_map"
824
+ ].includes(p) && !b.has(p))) ?? [];
825
+ m.push(...I);
826
+ for (const p of (n == null ? void 0 : n.textureConnections) ?? [])
827
+ !(r == null ? void 0 : r.textures.get(p.id)) && !((D = r == null ? void 0 : r.layeredTextures) != null && D.has(p.id)) && m.push(`texture:${p.id}:layered-or-unknown`);
828
+ n && !["phong", "lambert"].includes(n.shadingModel) && m.push(`shader:${n.shadingModel}`), m.length && (u.userData.fbxUnsupportedTextureRoles = m, console.warn(`[viewer] FBX material ${e.name}: unsupported texture semantics: ${m.join(", ")}`));
829
+ const v = {
830
+ layerStacks: U,
831
+ strategy: "blender-compatible-v1",
832
+ materialId: n == null ? void 0 : n.id,
833
+ materialName: e.name,
834
+ mappings: [
835
+ { source: "DiffuseColor", target: "color/map", rule: "texture replaces constant; raw constant RGB otherwise" },
836
+ { source: "Shininess", target: "roughness", rule: "clamp(1-sqrt(max(0,s))/10); empirical approximation" },
837
+ { source: "ReflectionFactor", target: "metalness", rule: "clamp(value); importer convention" },
838
+ { source: "SpecularFactor", target: "ior", rule: "match normal-incidence F0 only" },
839
+ ...[...b].map((p) => ({ source: p, target: S[p], rule: "raw R; identity; replaces scalar constant" }))
840
+ ],
841
+ issues: [
842
+ ...U.flatMap((p) => p.issues),
843
+ ...M.map((p) => ({ status: "approximate", code: "LAYERED_TEXTURE_BAKED", source: `layered:${p}:linear-color-v1; opaque base; first connection bottom`, target: "RGBA8 color texture" })),
844
+ { status: "approximate", code: "PHONG_TO_PBR", source: (n == null ? void 0 : n.shadingModel) ?? e.type, target: "MeshPhysicalMaterial" },
845
+ ...m.map((p) => ({ status: "unsupported", code: "UNSUPPORTED_SEMANTICS", source: p }))
846
+ ]
847
+ };
848
+ return u.userData.fbxConversionReport = v, u.visible = e.visible, u.toneMapped = e.toneMapped, u.clippingPlanes = e.clippingPlanes, u.clipIntersection = e.clipIntersection, u.clipShadows = e.clipShadows, u.polygonOffset = e.polygonOffset, u.polygonOffsetFactor = e.polygonOffsetFactor, u.polygonOffsetUnits = e.polygonOffsetUnits, u.dithering = e.dithering, u.needsUpdate = !0, t.set(e, u), u;
849
+ }
850
+ function st(e, t) {
851
+ let n = !1, s = null, r = null, c = "z", i, f = null, h;
852
+ const g = () => {
853
+ n = !0;
854
+ }, y = (async () => {
855
+ c = t.options.upAxis ?? Y(t.format);
856
+ let o = null;
857
+ try {
858
+ if (n || t.signal.aborted) throw G();
859
+ const a = e.url ?? await e.resolve(e.entryPath ?? "");
860
+ if (o = new pe(), o.name = "viewer-model-root", t.format === "fbx") {
861
+ const d = await fetch(a, { signal: t.signal });
862
+ if (!d.ok) throw new Error(`FBX request failed: ${d.status} ${d.statusText}`);
863
+ const w = await d.arrayBuffer();
864
+ c = t.options.upAxis ?? Ue(w) ?? Y(t.format);
865
+ const u = _e(w), E = await Ae(w, e, u);
866
+ h = E.textures, o.add(E.root);
867
+ const M = He(o, u, h).flatMap((I) => I.issues.filter((A) => A.status === "unsupported" || A.code === "TEXTURE_ROTATION_PROFILE" || A.code === "LAYERED_TEXTURE_BAKED").map((A) => `${I.materialName || I.materialId || "material"}: ${A.source}`));
868
+ M.length && (f = {
869
+ code: "W_FBX_MATERIAL_APPROXIMATED",
870
+ stage: "material-conversion",
871
+ message: `FBX 材质存在未支持或按兼容规则近似处理的语义:${[...new Set(M)].join("、")}。当前为近似预览。`
872
+ });
873
+ const b = [...new Set(E.textureFailures)];
874
+ b.length && (f = {
875
+ code: "W_FBX_TEXTURE_UNAVAILABLE",
876
+ stage: "material-conversion",
877
+ message: `FBX 贴图缺失或加载失败,已按无贴图降级显示:${b.join("、")}。${f ? `另有材质近似处理:${f.message}` : ""}`
878
+ });
879
+ } else {
880
+ const d = new me(), w = new ge();
881
+ try {
882
+ t.options.dracoDecoderPath && d.setDecoderPath(t.options.dracoDecoderPath), w.setDRACOLoader(d);
883
+ const u = await w.loadAsync(a), E = u.scenes.filter((U) => U !== u.scene);
884
+ if (o.add(u.scene), n || t.signal.aborted) {
885
+ for (const U of E) o.add(U);
886
+ throw G();
887
+ }
888
+ } finally {
889
+ d.dispose();
890
+ }
891
+ }
892
+ if (n || t.signal.aborted) throw G();
893
+ q(o, c), Ke(o);
894
+ const l = new ye(o, t.options.simulationTheme, void 0, "model");
895
+ s = o, r = l, o = null;
896
+ } finally {
897
+ o && (j(o, h), h = void 0);
898
+ }
899
+ })();
900
+ return y.catch(() => {
901
+ }), {
902
+ id: `model-${Math.random().toString(36).slice(2)}`,
903
+ opened: y,
904
+ get warning() {
905
+ return f;
906
+ },
907
+ get root() {
908
+ return (r == null ? void 0 : r.root) ?? null;
909
+ },
910
+ getFitBounds() {
911
+ return (r == null ? void 0 : r.getModelBounds()) ?? null;
912
+ },
913
+ beforeRender(o, a, l) {
914
+ return r == null ? void 0 : r.beforeRender(o, a, l);
915
+ },
916
+ capabilities: { canPlay: !1, canPause: !1, canReset: !1, hasPhysics: !1, canReorientUpAxis: !0, canToggleGround: !0 },
917
+ // Session presentation overrides are only consulted for `interactionMode`
918
+ // and `fitPolicy`; the UI group comes from the loader descriptor. Keep the
919
+ // two in sync so the override never reads as a contradictory value.
920
+ presentation: { preferredViewMode: "3d", interactionMode: "object", uiProfile: "model", fitPolicy: "fit-on-ready" },
921
+ getUpAxis() {
922
+ return s ? c : null;
923
+ },
924
+ setTheme(o) {
925
+ r == null || r.setTheme(o);
926
+ },
927
+ setGroundVisible(o) {
928
+ r == null || r.setGroundVisible(o);
929
+ },
930
+ getGroundVisible() {
931
+ return (r == null ? void 0 : r.getGroundVisible()) ?? !0;
932
+ },
933
+ getGroundGridScale() {
934
+ return (r == null ? void 0 : r.getGroundGridScale()) ?? we;
935
+ },
936
+ setUpAxis(o) {
937
+ if (n || !s || !r || !q(s, o)) return;
938
+ c = o, r.reseatGround();
939
+ const a = r.getModelBounds();
940
+ t.requestRender(), t.fit(a, { padding: 1.15 });
941
+ },
942
+ beginDispose: g,
943
+ dispose() {
944
+ return g(), i ?? (i = y.catch(() => {
945
+ }).then(() => {
946
+ r == null || r.dispose(), r = null, s && j(s, h), s = null, h = void 0;
947
+ })), i;
948
+ }
949
+ };
950
+ }
951
+ function Ke(e) {
952
+ e.updateMatrixWorld(!0);
953
+ const t = new de().setFromObject(e);
954
+ if (t.isEmpty()) throw new Error("模型不包含可显示的几何内容。");
955
+ const n = t.getSize(new he()), s = Math.max(n.x, n.y, n.z);
956
+ if (!Number.isFinite(s) || s <= 0) throw new Error("模型尺寸无效。");
957
+ }
958
+ function G() {
959
+ return Object.assign(new Error("Model load aborted."), { name: "AbortError", code: "E_ABORTED" });
960
+ }
961
+ export {
962
+ st as createModelSession
963
+ };