@volter/game-editor 0.5.136 → 0.5.137

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 (295) hide show
  1. package/BUNDLED_NOTICES +22 -22
  2. package/catalog/entries/blender.json +2 -2
  3. package/catalog/entries/music.json +2 -2
  4. package/dist/.vite/manifest.json +2182 -2182
  5. package/dist/assets/{AssetBudgetPanel-DUQkGYYB.js → AssetBudgetPanel-BL_p9339.js} +3 -3
  6. package/dist/assets/{AudioViewer-qRXhLRwE.js → AudioViewer-DktnhlSH.js} +1 -1
  7. package/dist/assets/{CanvasBoardDocument-D0mfhQd7.js → CanvasBoardDocument-6x0UaNM_.js} +1 -1
  8. package/dist/assets/{CanvasSceneViewport-DnX-GLnW.js → CanvasSceneViewport-CXaAheg1.js} +1 -1
  9. package/dist/assets/{ColorInput-C2dTdkzX.js → ColorInput-Ck8ADXk4.js} +1 -1
  10. package/dist/assets/{ColorPicker-B9M81VNS.js → ColorPicker-BtcHqHyy.js} +1 -1
  11. package/dist/assets/{EntityModelDocument-FNj4tul5.js → EntityModelDocument-D4w8QNAC.js} +1 -1
  12. package/dist/assets/{EnvironmentAssetDocument-g08h3ZVB.js → EnvironmentAssetDocument-DhTi3IQ-.js} +1 -1
  13. package/dist/assets/{GameplaySessionTimeline-Yu5B-TG1.js → GameplaySessionTimeline-BLyAR9I-.js} +1 -1
  14. package/dist/assets/{ImageViewer-CBhkWbPG.js → ImageViewer-4LK68Mzp.js} +1 -1
  15. package/dist/assets/InspectorObjectPreview-9nlNQgIy.js +1 -0
  16. package/dist/assets/{JsonAssetDocument-CHqWLF2i.js → JsonAssetDocument-Ba3AARH9.js} +1 -1
  17. package/dist/assets/{LiveModuleDocument-BefkmGqY.js → LiveModuleDocument-B0v52dB_.js} +1 -1
  18. package/dist/assets/{LutAssetDocument-5-4NXXbe.js → LutAssetDocument-CnOyLKfL.js} +1 -1
  19. package/dist/assets/{ModelAssetDocument-CH7AlcCB.js → ModelAssetDocument-ASZdz4mQ.js} +1 -1
  20. package/dist/assets/{NonThreeAuthoringBootstrap-DMSO_4d4.js → NonThreeAuthoringBootstrap-CyJz_Uzg.js} +1 -1
  21. package/dist/assets/{Object3DDocumentToolbar-DN3G2o5s.js → Object3DDocumentToolbar-zfzaJ97n.js} +1 -1
  22. package/dist/assets/Object3DDocumentViewport-BMFELBeB.js +2 -0
  23. package/dist/assets/{Object3DPreview-D00LjDUS.js → Object3DPreview-BJx8e2ML.js} +1 -1
  24. package/dist/assets/{OnlineAssetDetail-C4v8n7RT.js → OnlineAssetDetail-DYP5Z4SJ.js} +1 -1
  25. package/dist/assets/{PlayBar-B90P5gYf.js → PlayBar-pY88toV-.js} +1 -1
  26. package/dist/assets/{QuarksAssetDocument-lPXyq5l-.js → QuarksAssetDocument-UpcHy-Ko.js} +1 -1
  27. package/dist/assets/{ReactCanvasControls-Dv6I06PQ.js → ReactCanvasControls-TrIfWJ2O.js} +1 -1
  28. package/dist/assets/{RootSelectionOverlay-D1-F1pmR.js → RootSelectionOverlay-DnjTD4TF.js} +1 -1
  29. package/dist/assets/{ShaderAssetDocument-B4JC-YGd.js → ShaderAssetDocument-BSaq0f1m.js} +1 -1
  30. package/dist/assets/{ShadowEditor-CEPGo1Mx.js → ShadowEditor-CQtZYOhd.js} +1 -1
  31. package/dist/assets/{SourceAssetViewer-T__F0aEm.js → SourceAssetViewer-Ouz_rsDR.js} +1 -1
  32. package/dist/assets/{StageHost-uNsORdZ-.js → StageHost-xOoPaNP8.js} +2 -2
  33. package/dist/assets/{StoryPreviewMount-DQO9k8-_.js → StoryPreviewMount-DGSG6_5s.js} +1 -1
  34. package/dist/assets/{ThreeBoardDocument-N5Ioo2co.js → ThreeBoardDocument-JliFAb0Z.js} +2 -2
  35. package/dist/assets/{ThreeIsolationSceneContent-BU7FO-Jl.js → ThreeIsolationSceneContent-CtoVkziE.js} +1 -1
  36. package/dist/assets/{ToolObject3DPreview-C2ztOXgP.js → ToolObject3DPreview-Bddd1uZf.js} +1 -1
  37. package/dist/assets/{Toolbar-BB0US3yx.js → Toolbar-Cgj6k55f.js} +1 -1
  38. package/dist/assets/{TransientHint-DaIUWu1T.js → TransientHint-D7vfvRJQ.js} +1 -1
  39. package/dist/assets/{VideoViewer-Bmt1yuET.js → VideoViewer-DzmUv4vH.js} +1 -1
  40. package/dist/assets/{ViewportShadingMenu-DYI5ACUV.js → ViewportShadingMenu-CrYRegjG.js} +1 -1
  41. package/dist/assets/{active-ingest-CQ-T424d.js → active-ingest-rfjYHzRY.js} +2 -2
  42. package/dist/assets/{animation-clock-BXTw2rPK.js → animation-clock-DKIhFcpc.js} +1 -1
  43. package/dist/assets/{animation-mixers.service-z0gvYdCG.js → animation-mixers.service-QJm98cl8.js} +1 -1
  44. package/dist/assets/{animation-timeline.utility-BVCzYk4v.js → animation-timeline.utility-DjyiOLlq.js} +1 -1
  45. package/dist/assets/{asset-budget-asset.menu-C86CqxCr.js → asset-budget-asset.menu-Bpuw4snR.js} +1 -1
  46. package/dist/assets/{asset-budget.action-Sp-f_6yD.js → asset-budget.action-DE1qa9UX.js} +1 -1
  47. package/dist/assets/{asset-budget.document-CIA7vyXr.js → asset-budget.document-PLvRNbkT.js} +1 -1
  48. package/dist/assets/{asset-budget.menu-CAOoYAxF.js → asset-budget.menu-P3WQXz-x.js} +1 -1
  49. package/dist/assets/{asset-editor-persistence-DG12Fgdp.js → asset-editor-persistence-BzU_i50i.js} +1 -1
  50. package/dist/assets/{asset-loaders-CBGTSrO3.js → asset-loaders-5P-I_WtO.js} +1 -1
  51. package/dist/assets/{asset-preview-mzDnf-wr.js → asset-preview-WRMmcji5.js} +1 -1
  52. package/dist/assets/{audio-unlock.service-JtF7_hg6.js → audio-unlock.service-fHheprK3.js} +1 -1
  53. package/dist/assets/{audio.utility-BQGu_Wcn.js → audio.utility-D_wgDrnF.js} +1 -1
  54. package/dist/assets/autoplay.service-0YppfrGb.js +1 -0
  55. package/dist/assets/{babylon-authoring-adapter-BPQkNwoK.js → babylon-authoring-adapter-7buVjhsC.js} +1 -1
  56. package/dist/assets/{binding-resolver-DPAGUIDr.js → binding-resolver-PJ-UzNU0.js} +2 -2
  57. package/dist/assets/{blender-motion-worker-ECrqnoHW.js → blender-motion-worker-Fh1GJrP5.js} +1 -1
  58. package/dist/assets/{blender-node-editor.document-22XO7Lp2.js → blender-node-editor.document-Cu-XDG-U.js} +1 -1
  59. package/dist/assets/{blender-properties-tab-DEuBRbX3.js → blender-properties-tab-CSIr_Xnv.js} +1 -1
  60. package/dist/assets/{blender-runtime-host-BMLm9VzO.js → blender-runtime-host-UnEz3oog.js} +1 -1
  61. package/dist/assets/{blender-runtime-skin-CIZQnoLS.js → blender-runtime-skin-BnlKizA9.js} +34 -34
  62. package/dist/assets/{blender-runtime.document-DP6FS4N1.js → blender-runtime.document-4nEvfoQT.js} +1 -1
  63. package/dist/assets/{blender-screenshot.menu-B3FtPogM.js → blender-screenshot.menu-BVgLdRPT.js} +1 -1
  64. package/dist/assets/{blender-timeline.document-DFTIq8nb.js → blender-timeline.document-C8Buhfyp.js} +1 -1
  65. package/dist/assets/{blender-uv-editor.document-Daf1MTF5.js → blender-uv-editor.document-B6aSgely.js} +1 -1
  66. package/dist/assets/{blender-version.status-DmgHglZY.js → blender-version.status-C-kPhqLX.js} +1 -1
  67. package/dist/assets/{blender.command-B9Czew77.js → blender.command-C3f4bw0p.js} +1 -1
  68. package/dist/assets/{board-guides-DYBtNbPZ.js → board-guides-Ml9DEFDa.js} +1 -1
  69. package/dist/assets/{bridge.command-BAk5KygP.js → bridge.command-D2GfRwUr.js} +3 -3
  70. package/dist/assets/{browserAll-DA-xHGNc.js → browserAll-CwzGZYUo.js} +1 -1
  71. package/dist/assets/{build-player.document-C1kAhyFB.js → build-player.document-DH8r8PeA.js} +1 -1
  72. package/dist/assets/{build-profiles.document-yWJonklQ.js → build-profiles.document-6SnHN25M.js} +1 -1
  73. package/dist/assets/{build-progress.status-BttuUqo0.js → build-progress.status-BQxNokOF.js} +1 -1
  74. package/dist/assets/{build-session-CwwdnfUw.js → build-session-CSbFMBF0.js} +1 -1
  75. package/dist/assets/{build.action-DpU8tuVs.js → build.action-D4MsL_eY.js} +1 -1
  76. package/dist/assets/{build.command-CP28zKNj.js → build.command-BZmpNto8.js} +1 -1
  77. package/dist/assets/{build.header-CURvxaeN.js → build.header-Syb9WDFM.js} +1 -1
  78. package/dist/assets/{build.menu-BRfZ65ZQ.js → build.menu-DvGfyNwX.js} +1 -1
  79. package/dist/assets/{build.service-BnFW1JAl.js → build.service-CJYTWRI5.js} +1 -1
  80. package/dist/assets/{camera-l_lLG6UC.js → camera-BdEYklj4.js} +1 -1
  81. package/dist/assets/{camera-runtime.inspector-Cs1bd5x2.js → camera-runtime.inspector-B9U5eaJU.js} +1 -1
  82. package/dist/assets/{canvas-design-mount-DvI7tUOE.js → canvas-design-mount-CfRTHR3_.js} +3 -3
  83. package/dist/assets/{canvas-entry-runtime-wfeFuS54.js → canvas-entry-runtime-Cz1IFMLY.js} +2 -2
  84. package/dist/assets/{canvas-preview-frames-D6dRfd0W.js → canvas-preview-frames-DlTC4_NO.js} +1 -1
  85. package/dist/assets/{canvas-story-capture.service-DhA9aXry.js → canvas-story-capture.service-8ytcJys1.js} +2 -2
  86. package/dist/assets/{capability-coverage-CfnXFlvF.js → capability-coverage-D9fdVGHT.js} +1 -1
  87. package/dist/assets/{collaboration-presence-ByEUUm3H.js → collaboration-presence-DLo5KG7N.js} +1 -1
  88. package/dist/assets/{collider-B7QSYf7O.js → collider-De19qQYt.js} +1 -1
  89. package/dist/assets/{component-board.service-CIWlnTYc.js → component-board.service-B7ZPTksI.js} +2 -2
  90. package/dist/assets/{component-board.service-Bk0MuQ6d.js → component-board.service-BZUdDL_6.js} +2 -2
  91. package/dist/assets/{component-board.service-DbUgtRcS.js → component-board.service-DKDFiWeQ.js} +2 -2
  92. package/dist/assets/{component-contracts.service-D6kldORM.js → component-contracts.service-BN6Ug2yr.js} +1 -1
  93. package/dist/assets/{component-instance-root-DogGpzkX.js → component-instance-root-BrhAlO40.js} +1 -1
  94. package/dist/assets/{component-verbs.command-JquNJPEM.js → component-verbs.command-CVLZeqca.js} +1 -1
  95. package/dist/assets/{component-verbs.service-BN92VcwU.js → component-verbs.service-DgLWf18f.js} +1 -1
  96. package/dist/assets/{config-DLSNw1sM.js → config-DR7dzlXU.js} +2 -2
  97. package/dist/assets/{configurations-CR0efxVB.js → configurations-DEDB_dKj.js} +1 -1
  98. package/dist/assets/{connection.status-DvN4Aboe.js → connection.status-BbkaF6UL.js} +1 -1
  99. package/dist/assets/{constraints.inspector-BV3mvQvj.js → constraints.inspector-fcxkrvCy.js} +1 -1
  100. package/dist/assets/{content-bounds-BQv2Oj0c.js → content-bounds-BEFyyUiy.js} +1 -1
  101. package/dist/assets/{contract-system-adapters-BIb8P25q.js → contract-system-adapters-iyIfvDkn.js} +1 -1
  102. package/dist/assets/{coverage.service-CFe9kFJN.js → coverage.service-BmqAe5c5.js} +1 -1
  103. package/dist/assets/{create-runtime-CPqM1E54.js → create-runtime-Da8OYAg-.js} +1 -1
  104. package/dist/assets/{curve-4qOrg0up.js → curve-Ddzez5Vr.js} +1 -1
  105. package/dist/assets/{data-asset-xN6CCTMA.js → data-asset-BV-pPrWA.js} +1 -1
  106. package/dist/assets/{data-ref-B4Seo9xi.js → data-ref-DOTCUhZo.js} +1 -1
  107. package/dist/assets/{debug-bridge-DRPYwu65.js → debug-bridge-CIkqXPzr.js} +1 -1
  108. package/dist/assets/{debug-registry-CJCtzDuS.js → debug-registry-415hd00O.js} +1 -1
  109. package/dist/assets/{deferred-ingest-play-DKOivHvJ.js → deferred-ingest-play-CZPBCGiW.js} +2 -2
  110. package/dist/assets/{design-time-canvas-mount-DGSt4UGj.js → design-time-canvas-mount-CfUqadSh.js} +2 -2
  111. package/dist/assets/{design-time-layers-CygqUHVO.js → design-time-layers-DvFAZiug.js} +1 -1
  112. package/dist/assets/{design-time-mount.service-CGDOOslL.js → design-time-mount.service-6O8QVOLk.js} +2 -2
  113. package/dist/assets/{design-time-mount.service-DrFOCYoJ.js → design-time-mount.service-DSpyKXsQ.js} +2 -2
  114. package/dist/assets/{design-time-react-mount-ubpRtEiV.js → design-time-react-mount-Dg3K5Vb7.js} +1 -1
  115. package/dist/assets/{document-preview-three-CpLhA9SR.js → document-preview-three-BPKflnyl.js} +1 -1
  116. package/dist/assets/{dom-authoring-adapter-bSx05xrh.js → dom-authoring-adapter-DYik4nhZ.js} +1 -1
  117. package/dist/assets/{draco3d-BE2uLkcN.js → draco3d-D16fVUb-.js} +1 -1
  118. package/dist/assets/{edit-mode-audio.service-IOvtRXzQ.js → edit-mode-audio.service-DJcJDwN2.js} +1 -1
  119. package/dist/assets/{edit-mode-authoring-Bsg27PMt.js → edit-mode-authoring-Xo-XlCo-.js} +1 -1
  120. package/dist/assets/{edit-mode-networking.service-Dw1bCbOF.js → edit-mode-networking.service-DL3gFnhh.js} +1 -1
  121. package/dist/assets/{editor-api-DjYNAvCB.js → editor-api-CgBS1q8m.js} +1 -1
  122. package/dist/assets/{editor-layers-FpsUBtDt.js → editor-layers-B2m320yv.js} +1 -1
  123. package/dist/assets/{editor-shell-store-Dh5KTmnF.js → editor-shell-store-KdxXpGn2.js} +1 -1
  124. package/dist/assets/{entity-object-WoH_5Pd5.js → entity-object-Fb_5ma2W.js} +1 -1
  125. package/dist/assets/{extend-BBGBYbzV.js → extend-Dg2-Yn4w.js} +1 -1
  126. package/dist/assets/{fork-menu-C1ya-RsC.js → fork-menu-2nyNwyH5.js} +1 -1
  127. package/dist/assets/{frame-debugger-store-BgwwsHOP.js → frame-debugger-store-BchZPtKz.js} +1 -1
  128. package/dist/assets/{game-contract-seams-Dp3JsvmQ.js → game-contract-seams-DsC0kgqW.js} +1 -1
  129. package/dist/assets/{game-css-scope-transform-BVH7CeZb.js → game-css-scope-transform-IwoTW2wL.js} +1 -1
  130. package/dist/assets/{game-document.service-YXBkOXqD.js → game-document.service-BPXrIDw7.js} +1 -1
  131. package/dist/assets/{game-eval.command-BzdgNduI.js → game-eval.command-9FpuxL8M.js} +1 -1
  132. package/dist/assets/{game-module-access-ClVTJ7jN.js → game-module-access-ILUGtYxr.js} +1 -1
  133. package/dist/assets/{game-network-Bbfm5CA3.js → game-network-XzrrmFxu.js} +3 -3
  134. package/dist/assets/{gameplay-export-DCGjuCRu.js → gameplay-export-Dspv1GeR.js} +1 -1
  135. package/dist/assets/{gameplay-replay-BuXtZE-A.js → gameplay-replay-CbXPo27d.js} +1 -1
  136. package/dist/assets/{gameplay.command-B7ibKFu8.js → gameplay.command-BKBSP3vj.js} +1 -1
  137. package/dist/assets/{generation-jobs-CpIv2bww.js → generation-jobs-DmvFJoGi.js} +1 -1
  138. package/dist/assets/{generation.service-D6vPcLAO.js → generation.service-OdP1uc_Z.js} +1 -1
  139. package/dist/assets/{generations-Ca19xCMv.js → generations-CDC0nCMp.js} +1 -1
  140. package/dist/assets/{generations.status-D-52M8Jc.js → generations.status-vLjKvn3M.js} +1 -1
  141. package/dist/assets/{hierarchy-marks-C1luVKmT.js → hierarchy-marks-CoHDypTm.js} +1 -1
  142. package/dist/assets/{hosted-asset-materialization-D84vocze.js → hosted-asset-materialization-Bu6ZSD3G.js} +1 -1
  143. package/dist/assets/{index-DQjM7urk.js → index-BGZtg4qx.js} +1 -1
  144. package/dist/assets/{index-pCSwNNkA.js → index-BO-5HjZp.js} +1 -1
  145. package/dist/assets/{index-DQ94-LSC.js → index-BbSc59SM.js} +2 -2
  146. package/dist/assets/{index-8IrqWSN5.js → index-CW-rFhM9.js} +1 -1
  147. package/dist/assets/{index-Bx21uKfv.js → index-CegDwrqy.js} +1 -1
  148. package/dist/assets/{index-CTxZs1N_.js → index-DTcp0csp.js} +1 -1
  149. package/dist/assets/{index-BeRzMLts.js → index-DtBoG1rj.js} +7 -7
  150. package/dist/assets/{index-BhZ_kPE2.js → index-f15YYxWL.js} +1 -1
  151. package/dist/assets/{index-DmYlostm.js → index-mZfhIfBo.js} +1 -1
  152. package/dist/assets/{inference-diagnostics-Bo2HtZUZ.js → inference-diagnostics-BwRAwBLo.js} +1 -1
  153. package/dist/assets/{ingest-boot-viewport-9IoGCxt9.js → ingest-boot-viewport-BwrmXq_Z.js} +1 -1
  154. package/dist/assets/{ingest-siblings-CuBZ108A.js → ingest-siblings-BHwW0Y6G.js} +1 -1
  155. package/dist/assets/{ingest-source-persistence-C4BYH_zC.js → ingest-source-persistence-Bxus4r_m.js} +1 -1
  156. package/dist/assets/{ingest.service-D8GtCgxN.js → ingest.service-BPmlNzzN.js} +1 -1
  157. package/dist/assets/{inspect-umGXOTDA.js → inspect-n7usfpI0.js} +1 -1
  158. package/dist/assets/instances.command-DyDJzCEI.js +1 -0
  159. package/dist/assets/{json-history-resource-DJS8D3mL.js → json-history-resource-PBHlLHjq.js} +1 -1
  160. package/dist/assets/{layered-pick-9tVs_fxD.js → layered-pick-zvehRB0r.js} +1 -1
  161. package/dist/assets/{light-DauxxWP1.js → light-C_3P4pkm.js} +1 -1
  162. package/dist/assets/{live-project-verbs-B0Wo9rKR.js → live-project-verbs-C66qL2o8.js} +1 -1
  163. package/dist/assets/{machine.document-bM0sw3Ng.js → machine.document-D_Z1ZtQu.js} +1 -1
  164. package/dist/assets/{machines.finder-74bWIpZv.js → machines.finder-DxdPh_ba.js} +1 -1
  165. package/dist/assets/{material-BlfSw48G.js → material-BRTLViDb.js} +1 -1
  166. package/dist/assets/{material-factory-Zr8UWBZc.js → material-factory-DmrPuGpc.js} +1 -1
  167. package/dist/assets/{mesh-CoeXBHtT.js → mesh-CEK9kyS-.js} +1 -1
  168. package/dist/assets/{model-asset-sections.service-CajObyai.js → model-asset-sections.service-C7pxh8o5.js} +1 -1
  169. package/dist/assets/{model-inspection-BObdjlyQ.js → model-inspection-C47zYRXN.js} +1 -1
  170. package/dist/assets/{model-thumbnail-BP2m4n70.js → model-thumbnail-alzUeGJW.js} +1 -1
  171. package/dist/assets/{models.finder-Ds53y7we.js → models.finder-BODg0nu3.js} +1 -1
  172. package/dist/assets/{module-mode-Bu8X2IA_.js → module-mode-DVD9yrV3.js} +2 -2
  173. package/dist/assets/{mount-canvas-ingest-root-B6U08RVE.js → mount-canvas-ingest-root-DRhaTu2f.js} +2 -2
  174. package/dist/assets/{mount-dom-ingest-root-Ds2pIKLw.js → mount-dom-ingest-root-BLmIOkea.js} +2 -2
  175. package/dist/assets/{mount-ingest-root-BuBJymEm.js → mount-ingest-root-BZiQxJ9V.js} +2 -2
  176. package/dist/assets/{mount-manifest-CtBzFuse.js → mount-manifest-DFzKOvfW.js} +1 -1
  177. package/dist/assets/{mount-three-ingest-root-BzFXgauN.js → mount-three-ingest-root-DUld8xJM.js} +1 -1
  178. package/dist/assets/{mounted-authoring-COxaZfrw.js → mounted-authoring-QoImH9NK.js} +1 -1
  179. package/dist/assets/{mounted-story-viewport-source-ObnP-qVu.js → mounted-story-viewport-source-8DJkHA5k.js} +1 -1
  180. package/dist/assets/{native-debug-module-ADnfXW8Y.js → native-debug-module-BAqd-dXr.js} +1 -1
  181. package/dist/assets/{navigation-C3N7fOUh.js → navigation-Bq1Z3-ir.js} +1 -1
  182. package/dist/assets/{navmesh.menu-C9gJO9ES.js → navmesh.menu-DgHzTiSs.js} +1 -1
  183. package/dist/assets/{navmesh.service-CSqj1XV5.js → navmesh.service-SVOGOUz2.js} +1 -1
  184. package/dist/assets/network-observer.service-BxbPYgIs.js +1 -0
  185. package/dist/assets/{network.utility-Xn3JPeph.js → network.utility-B_B3xy8l.js} +1 -1
  186. package/dist/assets/{object3d-document-session-registry-gD07I_EN.js → object3d-document-session-registry-CP4s5KB0.js} +2 -2
  187. package/dist/assets/{oid-transform-BJsRXpGE.js → oid-transform-DKHBA9o4.js} +1 -1
  188. package/dist/assets/{particles-DkR7Cnbq.js → particles-UXw5izQB.js} +1 -1
  189. package/dist/assets/{pixi-authoring-adapter-C5Us9AJl.js → pixi-authoring-adapter-BcxL0BYE.js} +1 -1
  190. package/dist/assets/{pixi-live-write-target-MK352-wm.js → pixi-live-write-target-DrzWsBEE.js} +1 -1
  191. package/dist/assets/{play.command-DzRlPp6K.js → play.command-fZVVrYk0.js} +2 -2
  192. package/dist/assets/{presentation-B_ZbsAMV.js → presentation-C6pRfr0U.js} +1 -1
  193. package/dist/assets/{product-CWNjZkXt.js → product-h0b06kAI.js} +1 -1
  194. package/dist/assets/{profiler.action-BxMytW3w.js → profiler.action-Y2ael4fH.js} +1 -1
  195. package/dist/assets/{profiler.menu-8RaGonCN.js → profiler.menu-CFuRCWtC.js} +1 -1
  196. package/dist/assets/{profiler.utility-BmOcweu3.js → profiler.utility-CzyPY0d9.js} +1 -1
  197. package/dist/assets/{project-authoring-session-DcHsu_CR.js → project-authoring-session-D-gOry2E.js} +2 -2
  198. package/dist/assets/{properties-bone-constraints.inspector-BzLBzXrp.js → properties-bone-constraints.inspector-DhC96Qoa.js} +1 -1
  199. package/dist/assets/{properties-bone.inspector-BbXsdlzz.js → properties-bone.inspector-VO_EqJyX.js} +1 -1
  200. package/dist/assets/{properties-collection.inspector-qEbvAYQk.js → properties-collection.inspector-BmMEhIUd.js} +1 -1
  201. package/dist/assets/{properties-constraints.inspector-XeHIdu0O.js → properties-constraints.inspector-DLeGNshb.js} +1 -1
  202. package/dist/assets/{properties-data.inspector-L88rP9l_.js → properties-data.inspector-Cwt6L5ZJ.js} +1 -1
  203. package/dist/assets/{properties-material.inspector-DIoiHUb7.js → properties-material.inspector-D_rajHnK.js} +1 -1
  204. package/dist/assets/{properties-modifiers.inspector-BtaK5uc2.js → properties-modifiers.inspector-g8dRw0AH.js} +1 -1
  205. package/dist/assets/{properties-object.inspector-Bk62G2R3.js → properties-object.inspector-BlWog9Nj.js} +1 -1
  206. package/dist/assets/{properties-output.inspector-Nlw_0LKD.js → properties-output.inspector-B6a0ypEj.js} +1 -1
  207. package/dist/assets/{properties-particles.inspector-Kvv9SpkL.js → properties-particles.inspector-BFx3A-Ut.js} +1 -1
  208. package/dist/assets/{properties-physics.inspector-DsEqyzoo.js → properties-physics.inspector-Dg14VcGF.js} +1 -1
  209. package/dist/assets/{properties-render.inspector-BYS2Opqb.js → properties-render.inspector-D7eL3b9i.js} +1 -1
  210. package/dist/assets/{properties-scene.inspector-CRqHdUfQ.js → properties-scene.inspector-Di1i5s2V.js} +1 -1
  211. package/dist/assets/{properties-texture.inspector-CTQ3r4iT.js → properties-texture.inspector-BpKUFkJU.js} +1 -1
  212. package/dist/assets/{properties-view-layer.inspector-CIelG77G.js → properties-view-layer.inspector-iRU1UCfp.js} +1 -1
  213. package/dist/assets/{properties-world.inspector-Bt4VadbP.js → properties-world.inspector-COriTCOM.js} +1 -1
  214. package/dist/assets/{r3f-design-session-xFwyS5gl.js → r3f-design-session-CyPRQPI4.js} +2 -2
  215. package/dist/assets/{r3f-physics-binding-DAKpj6Z_.js → r3f-physics-binding-lk3em8Wm.js} +1 -1
  216. package/dist/assets/{r3f-source-authoring-adapter-BK0TQ32g.js → r3f-source-authoring-adapter-Btc18riQ.js} +1 -1
  217. package/dist/assets/{react-canvas-navigation-CFVkX1rA.js → react-canvas-navigation-BUlrUBT_.js} +1 -1
  218. package/dist/assets/{react-inspector.service-DOZAQWk2.js → react-inspector.service-elcIxOZw.js} +1 -1
  219. package/dist/assets/{react-story-board-m8JLSSuQ.js → react-story-board-cY8HytUW.js} +1 -1
  220. package/dist/assets/{react-three-rapier.esm-CnLTTW1T.js → react-three-rapier.esm-C-5WZnSr.js} +1 -1
  221. package/dist/assets/{react-world-authoring-adapter-DQNpj4pL.js → react-world-authoring-adapter-C3vr2gLt.js} +1 -1
  222. package/dist/assets/{realm-services-DDvu3_Iv.js → realm-services-CsF_yUuF.js} +1 -1
  223. package/dist/assets/{reflection-probe-capture.inspector-CXHB2PyJ.js → reflection-probe-capture.inspector-UcJvFDvH.js} +1 -1
  224. package/dist/assets/{registry-BlAFZ_wU.js → registry-D1oavyje.js} +1 -1
  225. package/dist/assets/{relative-import-specifier-DmxFmPz2.js → relative-import-specifier-B29yTSkd.js} +1 -1
  226. package/dist/assets/{render-env-uJeu2ahE.js → render-env-Dpixh45P.js} +1 -1
  227. package/dist/assets/{render-features-B039O46a.js → render-features-gn44fKvh.js} +1 -1
  228. package/dist/assets/{render-settings-Gx2FJvLE.js → render-settings-DKGmm6kq.js} +1 -1
  229. package/dist/assets/{resolve-three-tkoL57hD.js → resolve-three-CAER2bjG.js} +3 -3
  230. package/dist/assets/{root-seam-contract-CXPjB9fM.js → root-seam-contract-B6eFnKke.js} +1 -1
  231. package/dist/assets/{run-selection-BoK66lYR.js → run-selection-DKYCyepK.js} +1 -1
  232. package/dist/assets/{scene-capture-DZAm8Xsb.js → scene-capture-Dg7EEuLE.js} +1 -1
  233. package/dist/assets/{scene-document.service-BIPUZVoR.js → scene-document.service-B2yASKIM.js} +2 -2
  234. package/dist/assets/{scene-framing-Y2cvLk94.js → scene-framing-SWsxPJBi.js} +1 -1
  235. package/dist/assets/{seeded-random-Ccte60N9.js → seeded-random-CEtBWcGM.js} +1 -1
  236. package/dist/assets/{setup-renderer-B5dPY6xF.js → setup-renderer-qGSTEOxf.js} +1 -1
  237. package/dist/assets/{source-object3d-authoring-adapter-qmF911Z2.js → source-object3d-authoring-adapter-DDf2LiHb.js} +1 -1
  238. package/dist/assets/{source-persistence-backend-CdMq8hmt.js → source-persistence-backend-n6iBHtCn.js} +1 -1
  239. package/dist/assets/{stage-keyboard-ZsT3ioxr.js → stage-keyboard-CEUI0aJF.js} +1 -1
  240. package/dist/assets/{stage-overlay-set-BUr2yJRP.js → stage-overlay-set-BMZNNFo7.js} +1 -1
  241. package/dist/assets/{stage-presence-markers-Bt2SjhvS.js → stage-presence-markers-Be-3uk2P.js} +1 -1
  242. package/dist/assets/{stage-transform-tools-B-GN798Q.js → stage-transform-tools-CwzL9Mrg.js} +1 -1
  243. package/dist/assets/{standard-viewport-dressing-Bgi0-gIs.js → standard-viewport-dressing-4sheVRrB.js} +1 -1
  244. package/dist/assets/{state-watch.action-CyAGDdZJ.js → state-watch.action-BMOgWw_r.js} +1 -1
  245. package/dist/assets/{state-watch.menu-9aJRht7S.js → state-watch.menu-DHz2lYB2.js} +1 -1
  246. package/dist/assets/{state-watch.utility-BaIpNdvh.js → state-watch.utility-BHvFSFqv.js} +1 -1
  247. package/dist/assets/{story-capture-Cx0h8vM4.js → story-capture-DhspmQHC.js} +1 -1
  248. package/dist/assets/{story-documents-MTv434od.js → story-documents-XcMOkMyc.js} +1 -1
  249. package/dist/assets/{story-documents.service-BBtt30iB.js → story-documents.service-D55EB4C8.js} +1 -1
  250. package/dist/assets/{story-documents.service-C6dNal8U.js → story-documents.service-DRYWr5hu.js} +1 -1
  251. package/dist/assets/{story-media-presence-lWDI0c6F.js → story-media-presence-B2yzrh2l.js} +1 -1
  252. package/dist/assets/{story-pixi-preview-VBNFxeQt.js → story-pixi-preview-Bx0Rm8cy.js} +1 -1
  253. package/dist/assets/{story-presentation-CZ2IKkKx.js → story-presentation-CbLklcbQ.js} +1 -1
  254. package/dist/assets/{story-three-preview-DcLK2pjy.js → story-three-preview-BzuEMwmb.js} +2 -2
  255. package/dist/assets/{studio-environment-CziYh-2x.js → studio-environment-CbxnE0zY.js} +1 -1
  256. package/dist/assets/{surface-state-Civ-vJIW.js → surface-state-Dzjt3A8F.js} +1 -1
  257. package/dist/assets/{syntactic-prop-specs-B_X3gxVf.js → syntactic-prop-specs-CoiAhDuA.js} +1 -1
  258. package/dist/assets/{team-playtest.service-Bac-gvP4.js → team-playtest.service-BWPuwLfQ.js} +1 -1
  259. package/dist/assets/{three-DCPw6MrV.js → three-YQlLm7Hb.js} +1 -1
  260. package/dist/assets/{three-authoring-adapter-BGWRWAZM.js → three-authoring-adapter-CF52vBGj.js} +1 -1
  261. package/dist/assets/three-authoring.service-CxhLAY2B.js +2 -0
  262. package/dist/assets/{three-ingest-runtime-RhgxgLSL.js → three-ingest-runtime-6f6Gp0Y-.js} +1 -1
  263. package/dist/assets/{three-integration-CJA9IL4X.js → three-integration-BL2B62jS.js} +2 -2
  264. package/dist/assets/three-integration.service-DR85cZzE.js +1 -0
  265. package/dist/assets/{three-projection-core-DA9s0oC2.js → three-projection-core-BQ1xGj2a.js} +1 -1
  266. package/dist/assets/{three-state-B_U7u3xS.js → three-state-D1y7vgTW.js} +1 -1
  267. package/dist/assets/{three-story-capture.service-C8avFEHO.js → three-story-capture.service-DkJBT2Hq.js} +2 -2
  268. package/dist/assets/{three-story-model-BBiPWAR3.js → three-story-model-BJUSLuUT.js} +1 -1
  269. package/dist/assets/{three-viewport-presentation-cBbDcMmj.js → three-viewport-presentation-D0OO-lGJ.js} +1 -1
  270. package/dist/assets/{transform-mode-request-Dio4iBjC.js → transform-mode-request-DIxkCD7e.js} +1 -1
  271. package/dist/assets/{transport-strip-m7a-u3Pt.js → transport-strip-YMlmStOb.js} +1 -1
  272. package/dist/assets/transport.header-CbZJlLY1.js +1 -0
  273. package/dist/assets/{tuples-Cn3DT6Tc.js → tuples-7Iv2poqO.js} +1 -1
  274. package/dist/assets/{ui-board-document-BdIXeT4X.js → ui-board-document-BL_1sf8L.js} +2 -2
  275. package/dist/assets/{user-data-jnGijikA.js → user-data-VvdppiN3.js} +1 -1
  276. package/dist/assets/{utility-view-state-CD8Q8-ve.js → utility-view-state-j8fWSxfE.js} +1 -1
  277. package/dist/assets/{viewport-door-DmEc8F8a.js → viewport-door-CzxBXviv.js} +1 -1
  278. package/dist/assets/{viewport-root-presentation-DkteTdAF.js → viewport-root-presentation-BHaFMAFg.js} +1 -1
  279. package/dist/assets/{viewport-surface-status-Cz4UGPVc.js → viewport-surface-status-Ekln2Geu.js} +1 -1
  280. package/dist/assets/{webworkerAll-C3_PezoL.js → webworkerAll-BIolANfO.js} +1 -1
  281. package/dist/assets/{workspace-arrangement-HE3ZO3qD.js → workspace-arrangement-Cnx-VVZC.js} +1 -1
  282. package/dist/assets/{world-documents-DRiBxR40.js → world-documents-DdvjqwxD.js} +1 -1
  283. package/dist/assets/{world-root-stage-binding-xnxZZGVC.js → world-root-stage-binding-BoU0XTOU.js} +1 -1
  284. package/dist/assets/{xstate-animation-binding-YElkNQyT.js → xstate-animation-binding-C9x3BMf5.js} +1 -1
  285. package/dist/assets/{xstate-animation-meta-oLuT24EQ.js → xstate-animation-meta-C3ijI6qG.js} +1 -1
  286. package/dist-node/cli.js +16 -16
  287. package/package.json +16 -16
  288. package/dist/assets/InspectorObjectPreview-Dk4sn8tZ.js +0 -1
  289. package/dist/assets/Object3DDocumentViewport-BR9kvz7I.js +0 -2
  290. package/dist/assets/autoplay.service-Be2RmF37.js +0 -1
  291. package/dist/assets/instances.command-DLRWiNRY.js +0 -1
  292. package/dist/assets/network-observer.service-HF3M8uBZ.js +0 -1
  293. package/dist/assets/three-authoring.service-CardXMHi.js +0 -2
  294. package/dist/assets/three-integration.service-Bb12a0HW.js +0 -1
  295. package/dist/assets/transport.header-OibOxdjK.js +0 -1
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/RectAreaLightUniformsLib-DpPyArRG.js","assets/three.module-BLhyNg0e.js","assets/three.core-3arARmh6.js"])))=>i.map(i=>d[i]);
2
- import{a as so,b as lo,L as fo}from"./LineSegments2-DN9pUfWA.js";import{bh as it,cl as co,fo as x,cm as B,N as an,a$ as Mt,em as de,b4 as Go,co as Rt,ey as Xo,cp as Rn,_ as Ot,ej as $t,fd as Gt,er as Yo,M as lt,cj as bt,dp as Tt,aV as Zo,cW as uo,aE as mo,c7 as vt,j as Qo,f6 as Ko,fp as Cn,au as kn,dw as $n,bi as he,aT as Jo,c1 as Xt,dd as te,eC as ne,e7 as Pn,aw as mn,da as Bt,I as gn,as as ta,e8 as na,b0 as _o,K as ea,B as oa,b9 as aa,Y as ho,cw as en,ed as ra,cA as ia,fx as sa,db as po,el as la,R as fa,e6 as ca,c0 as go,bX as ua,aI as ee,ao as ma,eG as _a,d3 as da,cs as ha,b5 as Ln,bu as vo,aM as xo,ex as bo,cO as In,cY as pa,eU as ga,cE as oe,c5 as yo,at as va,ff as xa,eW as ba,f7 as ya,F as wa,ev as Oa,et as Ta,dq as Aa,fq as Sa,n as Ma,l as Pa,cf as Ea}from"./three.core-3arARmh6.js";import{u as M,v as D,w as R,c5 as Q,c4 as H,c6 as N,e2 as L,_ as Na,mB as wo,d_ as Lt,x as q,kE as yt,e1 as Oo,mC as W,dZ as Ra,mD as Ia}from"./index-BeRzMLts.js";import{S as Ut}from"./three.module-BLhyNg0e.js";import{t as za}from"./blender-runtime-host-BMLm9VzO.js";const ae=new Set;function ht(){for(const e of[...ae])e()}function Fa(e){return ae.add(e),()=>{ae.delete(e)}}function re(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}const rn=N().finite(),Da=M({name:R(),parent:R().nullable(),connected:Q(),hide:Q(),length:rn,matrix:D(L([rn,rn,rn,rn])).length(4),select:Q(),active:Q(),lockedWeight:Q()}).strict(),Ca=M({object:R(),displayType:H(["OCTAHEDRAL","STICK","BBONE","ENVELOPE","WIRE"]),showInFront:Q(),mode:R(),bones:D(Da)}).strict(),St={solid:11711154,pose:5294335,poseActive:9240575,poseActiveUnsel:794150,wire:0,vertex:0,lockedWeight:16711680,lockedWeightFactor:128/255};function ka(e){return new Ot(e.r*e.r*.1,e.g*e.g*.1,e.b*e.b*.1)}const jn=[[0,0,0],[.1,.1,.1],[.1,.1,-.1],[-.1,.1,-.1],[-.1,.1,.1],[0,1,0]],Se=[[2,1,0],[3,2,0],[4,3,0],[1,4,0],[5,1,2],[5,2,3],[5,3,4],[5,4,1]],It=Math.SQRT1_2,$a=[[It,-It,0],[0,-It,-It],[-It,-It,0],[0,-It,It],[.99388373,.11043154,0],[0,.11043154,-.99388373],[-.99388373,.11043154,0],[0,.11043154,.99388373]],La=[[0,1],[1,5],[5,3],[3,0],[0,4],[4,5],[5,2],[2,0],[1,2],[2,3],[3,4],[4,1]],Va=.05;function Me(e){return e.select||e.active?2:1}const ja=10,Ba=4,Ua=`
2
+ import{a as co,b as uo,L as mo}from"./LineSegments2-DN9pUfWA.js";import{bh as lt,cl as _o,fo as x,cm as H,N as sn,a$ as Mt,em as pe,b4 as Zo,co as Rt,ey as Qo,cp as In,_ as Ot,ej as Lt,fd as Xt,er as Ko,M as ct,cj as bt,dp as At,aV as Jo,cW as ho,aE as po,c7 as vt,j as ta,f6 as na,fp as kn,au as $n,dw as Ln,bi as ge,aT as ea,c1 as Yt,dd as ee,eC as oe,e7 as En,aw as dn,da as Ut,I as on,as as oa,e8 as aa,b0 as go,K as ra,B as ia,b9 as sa,Y as vo,cw as an,ed as la,cA as fa,fx as ca,db as xo,el as ua,R as ma,e6 as _a,c0 as bo,bX as da,aI as ae,ao as ha,eG as pa,d3 as ga,cs as va,b5 as Vn,bu as yo,aM as wo,ex as Oo,cO as zn,cY as xa,eU as ba,cE as re,c5 as Ao,at as ya,ff as wa,eW as Oa,f7 as Aa,F as Ta,ev as Sa,et as Ma,dq as Pa,fq as Ea,n as Na,l as Ra,cf as Ia}from"./three.core-3arARmh6.js";import{u as N,v as $,w as I,c5 as et,c4 as K,c6 as R,e2 as U,_ as za,mB as To,d_ as Vt,x as Z,kE as yt,e1 as So,mC as Y,dZ as Fa,mD as Da}from"./index-DtBoG1rj.js";import{S as Wt}from"./three.module-BLhyNg0e.js";import{t as Ca}from"./blender-runtime-host-UnEz3oog.js";const ie=new Set;function ht(){for(const e of[...ie])e()}function ka(e){return ie.add(e),()=>{ie.delete(e)}}function se(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}const ln=R().finite(),$a=N({name:I(),parent:I().nullable(),connected:et(),hide:et(),length:ln,matrix:$(U([ln,ln,ln,ln])).length(4),select:et(),active:et(),lockedWeight:et()}).strict(),La=N({object:I(),displayType:K(["OCTAHEDRAL","STICK","BBONE","ENVELOPE","WIRE"]),showInFront:et(),mode:I(),bones:$($a)}).strict(),St={solid:11711154,pose:5294335,poseActive:9240575,poseActiveUnsel:794150,wire:0,vertex:0,lockedWeight:16711680,lockedWeightFactor:128/255};function Va(e){return new Ot(e.r*e.r*.1,e.g*e.g*.1,e.b*e.b*.1)}const Bn=[[0,0,0],[.1,.1,.1],[.1,.1,-.1],[-.1,.1,-.1],[-.1,.1,.1],[0,1,0]],Pe=[[2,1,0],[3,2,0],[4,3,0],[1,4,0],[5,1,2],[5,2,3],[5,3,4],[5,4,1]],It=Math.SQRT1_2,ja=[[It,-It,0],[0,-It,-It],[-It,-It,0],[0,-It,It],[.99388373,.11043154,0],[0,.11043154,-.99388373],[-.99388373,.11043154,0],[0,.11043154,.99388373]],Ba=[[0,1],[1,5],[5,3],[3,0],[0,4],[4,5],[5,2],[2,0],[1,2],[2,3],[3,4],[4,1]],Ua=.05;function Ee(e){return e.select||e.active?2:1}const Wa=10,qa=4,Ha=`
3
3
  attribute vec3 aSolid;
4
4
  attribute vec3 aHint;
5
5
  varying vec3 vColor;
@@ -10,13 +10,13 @@ import{a as so,b as lo,L as fo}from"./LineSegments2-DN9pUfWA.js";import{bh as it
10
10
  vColor = mix(aHint, aSolid, fac * fac);
11
11
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
12
12
  }
13
- `,Wa=`
13
+ `,Ga=`
14
14
  varying vec3 vColor;
15
15
  void main() {
16
16
  gl_FragColor = vec4(vColor, 1.0);
17
17
  #include <colorspace_fragment>
18
18
  }
19
- `;function Ft(e){return new Ot().setHex(e,$t)}function Pe(e,t){const n=e.mode==="POSE";let o;return n?t.active&&t.select?o=Ft(St.poseActive):t.active?o=Ft(St.poseActiveUnsel):t.select?o=Ft(St.pose):o=Ft(St.wire):o=Ft(St.vertex),n&&t.lockedWeight&&o.lerp(Ft(St.lockedWeight),St.lockedWeightFactor),o}function Ee(e,t){const n=Ft(St.solid);return e.mode==="POSE"&&t.lockedWeight&&n.lerp(Ft(St.lockedWeight),St.lockedWeightFactor),n}const qa=new B,Ha=new x,Ne=new co;function Re(e,t){return new B().set(...t.matrix.flat()).premultiply(e).scale(new x().setScalar(t.length))}class Ga{constructor(){this.group=new it,this.disposables=[],this.signature="",this.group.name="BlenderArmatureOverlay"}apply(t,n){const o=[],r=JSON.stringify(t);if(r===this.signature)return o;this.signature=r,this.clear();for(const a of Object.values(t)){const i=n(a.object);if(i===null)continue;a.displayType!=="OCTAHEDRAL"&&a.displayType!=="STICK"&&o.push(`armature ${a.object}: Blender's ${a.displayType} bone display needs data this door does not carry (B-Bone segment matrices, envelope radii), so its bones are drawn octahedral`),a.mode==="EDIT"&&o.push(`armature ${a.object}: in Edit Mode Blender draws the EDIT bones, and this overlay draws the pose — the shapes are the rest pose, not the edited one`);const f=a.bones.filter(_=>!_.hide);if(f.length===0)continue;const u=a.displayType==="STICK"?this.buildStick(a,f,i):this.buildOctahedral(a,f,i);a.showInFront&&u.traverse(_=>{const l=_.material;l&&"depthTest"in l&&(l.depthTest=!1),_.renderOrder=10}),this.group.add(u)}return o}buildOctahedral(t,n,o){const r=new it;r.name=`${t.object}:bones`;const a=[],i=[],f=[],u=[],_=[],l=[],s=[],c=[],m=[],d=[];for(const h of n){const g=Re(o,h),p=Ee(t,h),v=ka(p),b=Pe(t,h);Ne.setFromMatrix4(g).invert().transpose();for(let T=0;T<Se.length;T++){const A=Ha.set(...$a[T]).applyMatrix3(Ne).normalize().clone();for(const O of Se[T]){const E=new x(...jn[O]).applyMatrix4(g);a.push(E.x,E.y,E.z),i.push(A.x,A.y,A.z),f.push(p.r,p.g,p.b),u.push(v.r,v.g,v.b)}}const y=Me(h)===2?s:_,S=Me(h)===2?c:l;for(const[T,A]of La){const O=new x(...jn[T]).applyMatrix4(g),E=new x(...jn[A]).applyMatrix4(g);y.push(O.x,O.y,O.z,E.x,E.y,E.z),S.push(b.r,b.g,b.b,b.r,b.g,b.b)}h.parent!==null&&h.connected||(m.push(g.clone()),d.push(p)),m.push(g.clone().multiply(qa.makeTranslation(0,1,0))),d.push(p)}r.add(this.solidMesh(a,i,f,u)),_.length&&r.add(this.lines(_,l,1)),s.length&&r.add(this.lines(s,c,2));for(let h=0;h<m.length;h++)r.add(this.point(m[h],d[h]));return r}buildStick(t,n,o){const r=new it;r.name=`${t.object}:bones`;const a=[],i=[],f=[],u=[];for(const _ of n){const l=Re(o,_),s=new x().setFromMatrixPosition(l),c=new x(0,1,0).applyMatrix4(l),m=Pe(t,_),d=Ee(t,_);a.push(s.x,s.y,s.z,c.x,c.y,c.z),i.push(m.r,m.g,m.b,m.r,m.g,m.b),f.push(s.x,s.y,s.z,c.x,c.y,c.z),u.push(d.r,d.g,d.b,d.r,d.g,d.b)}return r.add(this.lines(a,i,ja)),r.add(this.lines(f,u,Ba)),r}solidMesh(t,n,o,r){const a=new an;a.setAttribute("position",new Mt(t,3)),a.setAttribute("normal",new Mt(n,3)),a.setAttribute("aSolid",new Mt(o,3)),a.setAttribute("aHint",new Mt(r,3));const i=new de({vertexShader:Ua,fragmentShader:Wa,side:Go});this.disposables.push(a,i);const f=new Rt(a,i);return f.frustumCulled=!1,f}lines(t,n,o){const r=new so;r.setPositions(t),r.setColors(n);const a=new lo({linewidth:o,vertexColors:!0});this.disposables.push(r,a);const i=new fo(r,a);return i.frustumCulled=!1,i}point(t,n){const o=new Xo(Va,12,8),r=new Rn({color:n});this.disposables.push(o,r);const a=new Rt(o,r);return a.applyMatrix4(t),a.frustumCulled=!1,a}clear(){for(const t of[...this.group.children])this.group.remove(t);for(const t of this.disposables)t.dispose();this.disposables.length=0}dispose(){this.clear(),this.signature=""}}const Ie="RUNTIME_FRAME_UNKNOWN_GEOMETRY",sn="RUNTIME_FRAME_UNKNOWN_IMAGE";function Xa(e){const t=Math.fround,n=t(t(t(e[0]*e[0])+t(e[1]*e[1]))+t(e[2]*e[2]));if(n>1e-35){const o=t(Math.sqrt(n)),r=t(1/o);return{unit:[t(e[0]*r),t(e[1]*r),t(e[2]*r)],length:o}}return{unit:[0,0,0],length:0}}const I=Math.fround,zn=I(2*Math.PI),Bn=I(1-1e-4),Wt=(e,t)=>I(I(I(e[0]*t[0])+I(e[1]*t[1]))+I(e[2]*t[2])),pn=(e,t,n=1)=>e.map((o,r)=>I(o+I(t[r]*n))),Ya=(e,t)=>e.map((n,o)=>I(n-t[o]));function ln(e){const t=I(Math.sqrt(Wt(e,e)));return t>0?e.map(n=>I(n/t)):[0,0,0]}function fn(e){const t=Math.abs(e)<1?I(1-I(1-Math.abs(e))):1;let n=I(I(.077980478)+I(t*I(-.02164095)));n=I(I(-.213300989)+I(t*n)),n=I(I(1.5707963267)+I(t*n));const o=I(I(Math.sqrt(I(1-t)))*n);return e<0?I(I(Math.PI)-o):o}function Za(e){let t=e.at(-1);const n=[0,0,0];for(const o of e){for(let r=0;r<3;r++){const a=(r+1)%3,i=(r+2)%3;n[r]=I(n[r]+I(I(t[a]-o[a])*I(t[i]+o[i])))}t=o}return n}function Qa(e){const t=[],n=[],o=(d,h)=>d<h?`${d}:${h}`:`${h}:${d}`,r=new Map((e.edge_order??[]).map(([d,h],g)=>[o(d,h),g])),a=new Set((e.sharp??[]).map(([d,h])=>o(d,h))),i=new Map;for(const[d,h]of e.f.entries()){const g=t.length,p=Xa(Za(h.map(v=>e.v[v]))).unit;n.push(p.some(Boolean)?p:[0,0,1]);for(let v=0;v<h.length;v++){const b=o(h[v],h[(v+1)%h.length]);r.has(b)||r.set(b,r.size);const y=e.face_edges?.[d]?.[v]??r.get(b),S=t.length;t.push({vertex:h[v],face:d,edge:y,prev:g+(v+h.length-1)%h.length,next:g+(v+1)%h.length});const T=i.get(y)??[];T.push(S),i.set(y,T)}}const f=new Map,u=new Map;for(const[d,h]of i){if(h.length!==2||e.edge_sharp?.[d])continue;const[g,p]=h,v=t[g],b=t[p];!e.s?.[v.face]||!e.s?.[b.face]||v.vertex!==t[b.next].vertex||b.vertex!==t[v.next].vertex||!e.edge_sharp&&a.has(o(v.vertex,b.vertex))||(u.set(g,b.next),f.set(b.next,g),u.set(p,v.next),f.set(v.next,p))}const _=[],l=[],s=[],c=[],m=(d,h)=>ln(Ya(e.v[t[t[d][h]].vertex],e.v[t[d].vertex]));for(let d=0;d<t.length;d++){if(l[d]!==void 0)continue;let h=d;const g=new Set([h]);for(;u.has(h)&&!g.has(u.get(h));)h=u.get(h),g.add(h);u.has(h)&&(h=Math.min(...g));const p=[h];for(;f.has(p.at(-1))&&f.get(p.at(-1))!==h;)p.push(f.get(p.at(-1)));let v=[0,0,0];if(p.length===1)v=n[t[h].face];else{for(const E of p)v=pn(v,n[t[E].face],fn(Wt(m(E,"prev"),m(E,"next"))));v=ln(v)}const b=m(h,"next"),y=p.at(-1),S=m(y,"prev"),T=Wt(b,v),A=Wt(S,v),O={normal:v,reference:[0,0,0],ortho:[0,0,0],alpha:0,beta:0};if(Math.abs(T)<Bn&&Math.abs(A)<Bn){const E=p.length>1?p.map(ft=>m(ft,"next")):[];E.length&&t[t[y].prev].edge!==t[h].edge&&E.push(S),O.alpha=E.length?I(E.reduce((ft,w)=>I(ft+fn(Wt(w,v))),0)/E.length):I(I(fn(T)+fn(A))/2),O.reference=ln(pn(b,v,-T));const k=v,j=O.reference;O.ortho=ln([I(I(k[1]*j[2])-I(k[2]*j[1])),I(I(k[2]*j[0])-I(k[0]*j[2])),I(I(k[0]*j[1])-I(k[1]*j[0]))]);const G=ln(pn(S,v,-A)),K=Wt(O.reference,G),J=fn(K);O.beta=K<Bn?Wt(O.ortho,G)<0?I(zn-J):J:zn}O.alpha===0&&(O.normal=[0,0,0]);for(const E of p)l[E]=_.length;_.push(p),s.push(O),c.push(v)}return{corners:t,fans:_,fanOf:l,spaces:s,faceNormals:n,fanNormals:c}}function Ka(e,t){if(!t[0]||e.alpha===0||e.beta===0)return e.normal;const n=I(t[0]/32767),o=I(t[1]/32767),r=I((n>0?e.alpha:I(zn-e.alpha))*n),a=I((o>0?e.beta:I(zn-e.beta))*o);let i=e.normal.map(f=>I(f*I(Math.cos(r))));return i=pn(i,e.reference,I(I(Math.sin(r))*I(Math.cos(a)))),o!==0&&(i=pn(i,e.ortho,I(I(Math.sin(r))*I(Math.sin(a))))),i}function To(e,t){if(!t)return null;const{corners:n,fans:o,spaces:r}=Qa(e);if(t.type==="INT16_2D"&&t.domain==="CORNER"){const a=new Array(n.length);for(const[i,f]of o.entries()){const u=f.reduce((l,s)=>{const c=t.data[s];return[l[0]+c[0],l[1]+c[1]]},[0,0]),_=Ka(r[i],u.map(l=>Math.trunc(l/f.length)));for(const l of f)a[l]=_}return a}if(t.type==="FLOAT_VECTOR")return n.map((a,i)=>{const f=t.domain==="POINT"?a.vertex:t.domain==="FACE"?a.face:i;return t.data[f]});throw new Error(`Unsupported custom_normal attribute: ${t.type}/${t.domain}`)}const Un={FLOAT:{size:1},INT:{size:1},INT8:{size:1},BOOLEAN:{size:1},FLOAT2:{size:2},FLOAT_VECTOR:{size:3},FLOAT_COLOR:{size:4},BYTE_COLOR:{size:4},INT16_2D:{size:2},INT32_2D:{size:2},QUATERNION:{size:4},FLOAT4X4:{size:16},FLOAT4:{size:4},STRING:{size:1}},Ja=1e-6;function tr(e){const t=new x;for(let n=0;n<e.length;n++){const o=e[n],r=e[(n+1)%e.length];t.x+=(o.y-r.y)*(o.z+r.z),t.y+=(o.z-r.z)*(o.x+r.x),t.z+=(o.x-r.x)*(o.y+r.y)}return t.multiplyScalar(.5)}const nr=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),ze=e=>Array.from({length:e-2},(t,n)=>[0,n+1,n+2]);function er(e){let t=0;for(let n=0;n<e.length;n++){const o=e[n],r=e[(n+1)%e.length];t+=o.x*r.y-r.x*o.y}return t}function Fe(e,t,n){if(e.length!==t.length-2||!(Math.abs(n)>0))return!1;const o=Math.sign(n);let r=0;for(const[a,i,f]of e){const u=nr(t[a],t[i],t[f]);if(u*o<0)return!1;r+=Math.abs(u)}return Math.abs(r-Math.abs(n))<=Ja*Math.abs(n)}function or(e){const t=e.length;if(t<3)return{triangles:[],sound:!1,method:"fan"};if(t===3)return{triangles:[[0,1,2]],sound:!0,method:"fan"};const n=tr(e),o=n.length();if(!(o>0)||!Number.isFinite(o))return{triangles:ze(t),sound:!1,method:"fan"};const r=n.clone().divideScalar(o),a=Math.abs(r.x)<.9?new x(1,0,0):new x(0,1,0),i=new x().crossVectors(a,r).normalize(),f=new x().crossVectors(r,i),u=e[0],_=e.map(m=>{const d=m.clone().sub(u);return new Gt(d.dot(i),d.dot(f))}),l=er(_),s=ze(t);if(Fe(s,_,l))return{triangles:s,sound:!0,method:"fan"};let c=[];try{c=Yo.triangulateShape(_,[]).map(m=>[m[0],m[1],m[2]])}catch{return{triangles:s,sound:!1,method:"fan"}}return Fe(c,_,l)?{triangles:c,sound:!0,method:"earcut"}:{triangles:c.length>0?c:s,sound:!1,method:c.length>0?"earcut":"fan"}}const ar=new Set(["FLOAT","FLOAT2","FLOAT_VECTOR","FLOAT_COLOR","BYTE_COLOR"]);function Wn(e){const t=e/255;return t<.04045?t<0?0:t*(1/12.92):((t+.055)*(1/1.055))**2.4}function qn(e,t,n){switch(e){case"FLOAT":{const o=Number(t[n]);return[o,o,o,1]}case"FLOAT2":return[Number(t[n*2]),Number(t[n*2+1]),0,1];case"FLOAT_VECTOR":return[Number(t[n*3]),Number(t[n*3+1]),Number(t[n*3+2]),1];case"BYTE_COLOR":return[Wn(Number(t[n*4])),Wn(Number(t[n*4+1])),Wn(Number(t[n*4+2])),Number(t[n*4+3])/255];default:return[Number(t[n*4]),Number(t[n*4+1]),Number(t[n*4+2]),Number(t[n*4+3])]}}function pe(e,t){return e.filter(n=>ar.has(n.type)&&n.domain!=="EDGE"&&!n.name.startsWith(".")&&n.name!=="position"&&n.name!=="custom_normal"&&!(n.type==="FLOAT2"&&n.domain==="CORNER")).map(n=>{const o=t(n.data,n.type),r=[0,0,0,0];return{name:n.name,domain:n.domain,read:(a,i,f)=>n.domain==="POINT"?qn(n.type,o,a):n.domain==="CORNER"?i===void 0?r:qn(n.type,o,i):f===void 0?r:qn(n.type,o,f)}})}function Ao(e){const t=e.vertexCount,n=e.starts.length-1,o=e.starts,r=e.cornerVerts,a=o[n];let i=t;for(let w=0;w<n;w++)i+=(o[w+1]-o[w]-2)*3;const f=new Uint32Array(a),u=new Uint8Array(a),_=new Uint8Array(t),l=new Uint32Array(a);let s=!1;for(let w=0;w<n;w++)if(e.smooth(w)){s=!0;break}const c=(w,V)=>t<94906265?Math.min(w,V)*t+Math.max(w,V):`${Math.min(w,V)}:${Math.max(w,V)}`,m=new Map,d=new Set;for(const[w,V]of e.sharp)d.add(c(w,V));if(e.edges)for(const[w,V]of e.edges){if(w===V)throw new Error("Runtime mesh edge needs distinct vertices");m.set(c(w,V),-1)}const h=w=>{for(;l[w]!==w;)l[w]=l[l[w]],w=l[w];return w},g=(w,V)=>{const F=h(w),Y=h(V);l[Math.max(F,Y)]=Math.min(F,Y)};for(let w=0;w<n;w++){const V=o[w],F=o[w+1]-V,Y=e.smooth(w)?1:0;for(let Z=0;Z<F;Z++){const $=V+Z;_[r[$]]=1,f[$]=V+(Z+1)%F,u[$]=Y,l[$]=$}}for(let w=0;w<a;w++){const V=f[w],F=r[w],Y=r[V],Z=c(F,Y),$=m.get(Z);if($!==void 0&&$>=0&&u[w]&&u[$]&&!d.has(Z)){const P=f[$];g(w,r[$]===F?$:P),g(V,r[$]===F?P:$)}($===void 0||$<0||!u[$]&&u[w])&&m.set(Z,w)}const p=e.uv,v=new Float32Array(i*3),b=new Float32Array(i*2),y=new Uint32Array(i),S=(e.uvLayers??[]).map(w=>({...w,data:new Float32Array(i*2)})),T=(e.attributeLayers??[]).map(w=>({...w,data:new Float32Array(i*4)})),A=e.orco?new Float32Array(i*3):null,O=new Uint32Array(i),E=new Map,k=[],j=e.normals||e.cornerNormal?new Float32Array(i*3):null;let G=0,K=0;const J=(w,V,F,Y,Z)=>{const $=G++;for(const P of T)P.data.set(P.read(w,Y,Z),$*4);if(A)for(let P=0;P<3;P++)A[$*3+P]=e.orco[w*3+P]*.5+.5;if(y[$]=w,e.co(w).toArray(v,$*3),V&&b.set(V,$*2),F&&j.set(F,$*3),Y!==void 0)for(const P of S)P.data.set(P.read(Y),$*2);return $},ft=(w,V)=>{const F=p?.(w),Y=e.cornerNormal?[e.cornerNormal[w*3],e.cornerNormal[w*3+1],e.cornerNormal[w*3+2]]:e.normals?.[w];if(!s)return J(r[w],F,Y,w,V);const Z=`${u[w]?h(w):w}${F?`:${F[0]}:${F[1]}`:""}${Y?`:n${Y.join(":")}`:""}${S.map(P=>":"+P.read(w).join(":")).join("")}${T.map(P=>P.domain==="POINT"?"":":"+Array.from(P.read(r[w],w,V)).join(":")).join("")}`;let $=E.get(Z);return $===void 0&&($=J(r[w],F,Y,w,V),E.set(Z,$)),$};for(let w=0;w<n;w++){const V=K,F=o[w],Y=o[w+1]-F,Z=[];for(let U=0;U<Y;U++)Z.push(e.co(r[F+U]));for(const U of or(Z).triangles)for(const tt of U)O[K++]=ft(F+tt,w);const $=e.material(w),P=k.at(-1);P?.materialIndex===$?P.count+=K-V:k.push({start:V,count:K-V,materialIndex:$})}for(let w=0;w<t;w++)_[w]||J(w);return{positions:v.slice(0,G*3),normals:j?.slice(0,G*3)??null,uv:p?b.slice(0,G*2):null,uvLayers:S.map(w=>({name:w.name,data:w.data.slice(0,G*2)})),attributeLayers:T.map(w=>({name:w.name,data:w.data.slice(0,G*4)})),orco:A?A.slice(0,G*3):null,indices:O.slice(0,K),sourceVertex:y.slice(0,G),groups:k}}function kt(e){return`blenderA_${Array.from(new TextEncoder().encode(e),t=>t.toString(16).padStart(2,"0")).join("")}`}function En(e){const t=new an;t.setAttribute("position",new lt(e.positions,3)),t.setAttribute("uv",new lt(e.uv??new Float32Array(e.positions.length/3*2),2)),t.setIndex(new lt(e.indices,1));const n=Object.create(null);for(const[o,r]of(e.uvLayers??[]).entries()){if(o>=8)throw new Error("A Blender mesh supports at most eight UV maps");n[r.name]=o+1,t.setAttribute(`uv${o+1}`,new lt(r.data,2))}t.userData.blenderUvChannels=n;for(const o of e.attributeLayers??[])t.setAttribute(kt(o.name),new lt(o.data,4));t.userData.blenderAttributes=(e.attributeLayers??[]).map(o=>o.name),e.orco&&(t.setAttribute("blenderOrco",new lt(e.orco,3)),t.userData.blenderOrcoFromDoor=!0);for(const o of e.groups)t.addGroup(o.start,o.count,o.materialIndex);return e.normals?t.setAttribute("normal",new lt(e.normals,3)):t.computeVertexNormals(),e.sourceVertex&&t.setAttribute("blenderVertex",new lt(e.sourceVertex,1)),t}function rr(e,t){const n=e.cornerTri,o=e.cornerNormal,r=e.co.length/3,a=e.corner.length,i=e.faceStart.length-1,f=e.attributes.filter(P=>P.type==="FLOAT2"&&P.domain==="CORNER"),u=e.renderUv??e.activeUv??f[0]?.name,_=f.findIndex(P=>P.name===u);if(u&&_<0)throw new Error(`Runtime UV map ${u} is missing`);const l=pe(e.attributes,P=>P),s=3+f.length*2+l.length*4,c=new Float32Array(s),m=new Float32Array(s),d=new Uint32Array(c.buffer),h=new Uint32Array(m.buffer),g=new Uint32Array(a),p=new Uint32Array(a),v=new Uint32Array(a),b=new Uint32Array(a),y=new Uint8Array(r);let S=1;for(;S<Math.max(1,a*2);)S*=2;const T=new Uint32Array(S),A=(P,U,tt,nt)=>{let ut=0;for(let rt=0;rt<3;rt++)nt[ut++]=o[P*3+rt];for(const rt of f)for(let st=0;st<2;st++)nt[ut++]=Number(rt.data[P*2+st]);for(const rt of l){const st=rt.read(tt,P,U);for(let At=0;At<4;At++)nt[ut++]=Number(st[At])}};let O=0;for(let P=0;P<i;P++)for(let U=e.faceStart[P];U<e.faceStart[P+1];U++){const tt=e.corner[U];if(tt>=r)throw new Error("Native mesh corner references a missing vertex");g[U]=P,y[tt]=1,A(U,P,tt,c);let nt=Math.imul(tt^2166136261,16777619);for(const st of d)nt=Math.imul(nt^st,16777619);const ut=nt>>>0&S-1;let rt=-1;for(let st=T[ut];st;st=b[st-1]){const At=st-1,Vn=v[At];if(e.corner[Vn]!==tt)continue;A(Vn,g[Vn],tt,m);let Ae=!0;for(let xn=0;xn<s;xn++)if(d[xn]!==h[xn]){Ae=!1;break}if(Ae){rt=At;break}}rt<0&&(rt=O++,v[rt]=U,b[rt]=T[ut],T[ut]=rt+1),p[U]=rt}let E=0;for(const P of y)P||E++;const k=O+E,j=new Float32Array(k*3),G=new Float32Array(k*3),K=new Uint32Array(k),J=f.map(P=>({name:P.name,data:new Float32Array(k*2)})),ft=l.map(P=>({name:P.name,data:new Float32Array(k*4)})),w=e.orco?new Float32Array(k*3):null,V=(P,U)=>{K[P]=U;for(let tt=0;tt<3;tt++)j[P*3+tt]=e.co[U*3+tt],w&&(w[P*3+tt]=e.orco[U*3+tt]*.5+.5)};for(let P=0;P<O;P++){const U=v[P],tt=e.corner[U];V(P,tt),A(U,g[U],tt,c),G.set(c.subarray(0,3),P*3);let nt=3;for(const ut of J)ut.data.set(c.subarray(nt,nt+2),P*2),nt+=2;for(const ut of ft)ut.data.set(c.subarray(nt,nt+4),P*4),nt+=4}let F=O;for(let P=0;P<r;P++)if(!y[P]){V(F,P);for(let U=0;U<l.length;U++)ft[U].data.set(l[U].read(P,void 0,void 0),F*4);F++}const Y=new Uint32Array(n.length),Z=[];let $=0;for(let P=0;P<i;P++){const U=e.faceStart[P],tt=e.faceStart[P+1],nt=Math.max(0,tt-U-2)*3;if($+nt>n.length)throw new Error("Native mesh triangulation is incomplete");for(let st=0;st<nt;st++){const At=n[$+st];if(At<U||At>=tt)throw new Error("Native triangle references a different face");Y[$+st]=p[At]}const ut=e.material[P],rt=Z.at(-1);rt?.materialIndex===ut?rt.count+=nt:Z.push({start:$,count:nt,materialIndex:ut}),$+=nt}if($!==n.length)throw new Error("Native mesh triangulation has extra triangles");return{positions:j,normals:G,sourceVertex:K,uv:_<0?null:J[_].data,uvLayers:J,attributeLayers:ft,orco:w,indices:Y,groups:Z,hash:t}}function De(e,t){if(e.cornerTri&&e.cornerNormal)return rr(e,t);const n=e.co.length/3,o=e.attributes.filter(h=>h.type==="FLOAT2"&&h.domain==="CORNER"),r=e.renderUv??e.activeUv??o[0]?.name,a=o.find(h=>h.name===r);if(r&&!a)throw new Error(`Runtime UV map ${r} is missing`);const i=a?a.data:null,f=e.edge.length/2,u=new Array(f);for(let h=0;h<f;h++)u[h]=[e.edge[h*2],e.edge[h*2+1]];const _=[];for(let h=0;h<f;h++)e.edgeSharp[h]===1&&_.push(u[h]);const l=e.cornerNormal?void 0:e.attributes.find(h=>h.name==="custom_normal"),s=l?{v:Array.from({length:n},(h,g)=>[e.co[g*3],e.co[g*3+1],e.co[g*3+2]]),f:Array.from({length:e.faceStart.length-1},(h,g)=>Array.from(e.corner.subarray(e.faceStart[g],e.faceStart[g+1]))),s:Array.from(e.smooth,Boolean),edge_order:u,sharp:_,face_edges:Array.from({length:e.faceStart.length-1},(h,g)=>Array.from(e.cornerEdge.subarray(e.faceStart[g],e.faceStart[g+1]))),edge_sharp:Array.from(e.edgeSharp,Boolean)}:null,c=l?{type:l.type,domain:l.domain,data:Array.from({length:l.data.length/Un[l.type].size},(h,g)=>Array.from({length:Un[l.type].size},(p,v)=>Number(l.data[g*Un[l.type].size+v])))}:void 0,m=new x,d={vertexCount:n,normals:s?To(s,c):null,cornerNormal:e.cornerNormal,orco:e.orco,co:h=>m.set(e.co[h*3],e.co[h*3+1],e.co[h*3+2]).clone(),starts:e.faceStart,cornerVerts:e.corner,smooth:h=>e.smooth[h]===1,material:h=>e.material[h],edges:u,sharp:_,uv:i?h=>[i[h*2],i[h*2+1]]:null,uvLayers:o.map(h=>({name:h.name,read:g=>[Number(h.data[g*2]),Number(h.data[g*2+1])]})),attributeLayers:pe(e.attributes,h=>h)};return{...Ao(d),hash:t}}function ir(e){const t=e.v.map(s=>new x(...s)),n=s=>{const c=t[s];if(!c)throw new Error(`Runtime mesh vertex ${s} is missing`);return c},o=new Uint32Array(e.f.length+1);e.f.forEach((s,c)=>{if(s.length<3||new Set(s).size!==s.length)throw new Error("Runtime mesh face needs at least three distinct vertices");o[c+1]=o[c]+s.length});const r=new Uint32Array(o[e.f.length]);e.f.forEach((s,c)=>s.forEach((m,d)=>{n(m),r[o[c]+d]=m}));for(const[s,c]of e.edge_order??e.e??[])n(s),n(c);const a={POINT:t.length,EDGE:(e.edge_order??e.e??[]).length,FACE:e.f.length,CORNER:r.length};for(const s of e.attributes??[])if(s.domain!=="EDGE"&&s.data.length!==a[s.domain])throw new Error(`Runtime attribute ${s.name} has ${s.data.length} values for ${a[s.domain]} ${s.domain} elements`);const i=(e.attributes??[]).filter(s=>s.type==="FLOAT2"&&s.domain==="CORNER"),f=e.render_uv??e.active_uv??i[0]?.name,u=i.find(s=>s.name===f);if(f&&!u)throw new Error(`Runtime UV map ${f} is missing`);const _=u?.data,l={vertexCount:t.length,normals:To(e,e.attributes?.find(s=>s.name==="custom_normal")),co:n,starts:o,cornerVerts:r,smooth:s=>!!e.s?.[s],material:s=>e.m?.[s]??0,edges:e.edge_order??e.e??null,sharp:e.sharp??[],uv:_?s=>_[s]:null,uvLayers:i.map(s=>({name:s.name,read:c=>s.data[c]})),attributeLayers:pe(e.attributes??[],s=>Array.from(s).flat())};return En(Ao(l))}const vn=1.5707963267948966,qt=6.283185307179586,So=.3183098861837067,Mo=.0795774715459476,sr=.3,lr=Mo,fr=3/16*So,ie=.8,Ce=ie*ie,Ht=6371,Po=100,se=Ht+Po,ke=64,$e=64,ct=256,Vt=64,cr=[1.679,1.828,1.986,1.307],ur=[.006605,.01067,.01842,.03156],mr=[3472e-28,3914e-28,1349e-28,1103e-29],_r=334.5,dr=[28722e-28,46168e-28,79706e-28,13578e-27],hr=[15908e-26,17711e-26,20942e-26,24033e-26],Le=13681e16,pr=2e6,gr=.73,Hn=[[53.38691773856467,22.981337506691023,0],[43.90484446636936,71.3477957000534,.10250686796574131],[1.6137278251608962,18.422960591455485,31.742921188390806],[20.762668673810577,2.361421352331437,110.4800964325214]],Pt=[[3.2409698963165283,-1.5373831987380981,-.49861079454421997],[-.969243586063385,1.8759675025939941,.041555099189281464],[.05563009902834892,-.20397700369358063,1.056971549987793]],Fn=e=>e*e,_n=e=>e<0?0:e>1?1:e,Nt=(e,t,n)=>e+n*(t-e),vr=e=>Math.sqrt(Math.max(e,0)),Eo=e=>[-Math.sqrt(1-e*e),0,e];function le(e,t,n,o,r,a,i){const f=e*o+t*r+n*a,u=e*e+t*t+n*n-i*i;if(u>0&&f>0)return-1;const _=f*f-u;return _<0?-1:_>=f*f?-f+Math.sqrt(_):-f-Math.sqrt(_)}const xr=e=>fr*(1+Fn(e));function br(e){const t=1+Ce+2*ie*e;return Mo*(1-Ce)/(t*Math.sqrt(t))}const yr=e=>Le*(Math.exp(-e/gr)+pr/Le);function ge(e,t){let n=e%qt;Math.abs(n)>=Math.PI&&(n-=Math.sign(n)*2*Math.PI);let o=t;return(n>=vn||n<=-vn)&&(n=Math.sign(n)*Math.PI-n,o+=Math.PI),o=o%qt,o<0&&(o+=qt),o=qt-o,[n,o]}class wr{constructor(t,n,o){this.air=t,this.aerosol=n,this.ozone=o,this.lut=new Float32Array(Vt*ct*4)}coefficients(t,n){const o=yr(t)*this.aerosol,r=Math.log(Math.max(t,1e-4)),a=378547397e12*Math.exp(-Fn(r-3.22261)*5.55555555-r),i=Math.exp(-.07771971*t**1.16364243);for(let f=0;f<4;f++)n[f]=dr[f]*o,n[4+f]=hr[f]*o,n[8+f]=mr[f]*_r*a*this.ozone,n[12+f]=ur[f]*i*this.air}transmittance(t,n,o){const[r,a,i]=Eo(t),f=Nt(Ht,se,n),_=le(0,0,f,r,a,i,se)/ke,l=[0,0,0,0],s=new Float64Array(16);for(let c=0;c<ke;c++){const m=(c+.5)*_,d=r*m,h=a*m,g=f+i*m,p=Math.max(Math.hypot(d,h,g)-Ht,0);this.coefficients(p,s);for(let v=0;v<4;v++)l[v]+=(s[v]+s[4+v]+s[8+v]+s[12+v])*_}for(let c=0;c<4;c++)o[c]=Math.exp(-l[c])}precompute(){const t=new Float64Array(4);for(let n=0;n<Vt;n++)for(let o=0;o<ct;o++){const r=o/(ct-1),a=n/(Vt-1);this.transmittance(r*2-1,a,t);const i=(n*ct+o)*4;for(let f=0;f<4;f++)this.lut[i+f]=t[f]}}lookup(t,n,o){const r=(ct-1)*_n(t*.5+.5),a=(Vt-1)*_n(n),i=Math.trunc(r),f=Math.trunc(a),u=Math.min(i+1,ct-1),_=Math.min(f+1,Vt-1),l=r-i,s=a-f,c=(f*ct+i)*4,m=(f*ct+u)*4,d=(_*ct+i)*4,h=(_*ct+u)*4;for(let g=0;g<4;g++)o[g]=Nt(Nt(this.lut[c+g],this.lut[m+g],l),Nt(this.lut[d+g],this.lut[h+g],l),s)}lookupAtGround(t,n){const o=(ct-1)*_n(t*.5+.5),r=Math.trunc(o),a=Math.min(r+1,ct-1),i=o-r;for(let f=0;f<4;f++)n[f]=Nt(this.lut[r*4+f],this.lut[a*4+f],i)}lookupToSun(t,n){const o=(Vt-1)*_n(t),r=Math.trunc(o),a=Math.min(r+1,Vt-1),i=o-r,f=ct-1;for(let u=0;u<4;u++)n[u]=Nt(this.lut[(r*ct+f)*4+u],this.lut[(a*ct+f)*4+u],i)}inscattering(t,n,o,r,a,i,f,u,_){const l=-(a*t[0]+i*t[1]+f*t[2]),s=xr(l),c=br(l),m=u/$e,d=new Float64Array(16),h=new Float64Array(4),g=new Float64Array(4),p=new Float64Array(4),v=new Float64Array(4),b=new Float64Array(4),y=[0,0,0,0],S=[1,1,1,1];for(let T=0;T<$e;T++){const A=(T+.5)*m,O=n+a*A,E=o+i*A,k=r+f*A,j=Math.hypot(O,E,k),G=Math.max(j-Ht,0),K=G/Po,J=(O*t[0]+E*t[1]+k*t[2])/j;this.coefficients(G,d),this.lookup(J,K,h);const ft=qt*(1-vr(1-Fn(Ht/j)));this.lookupAtGround(J,p),this.lookupToSun(0,v),this.lookupToSun(K,b);const w=1/(1+5*Math.exp(-17.92*J)),V=[.217,.347,.594,1];for(let F=0;F<4;F++){const Y=v[F]/b[F],Z=lr*ft*(sr*So)*p[F]*Y*J;g[F]=.02*V[F]*w+Z}for(let F=0;F<4;F++){const Y=d[F]+d[4+F]+d[8+F]+d[12+F],Z=cr[F]*(d[12+F]*(s*h[F]+g[F])+d[4+F]*(c*h[F]+g[F])),$=Math.exp(-m*Y),P=Math.max(Y,1e-7);y[F]+=S[F]*((Z-Z*$)/P),S[F]*=$}}for(let T=0;T<4;T++)_[T]=y[T]}}const pt=512,Jt=256;function No(e,t){const n=new wr(e.airDensity,e.aerosolDensity,e.ozoneDensity);n.precompute();const o=Math.min(Math.max(e.altitude,1),99999)/1e3,r=Eo(Math.cos(vn-t)),a=new Float32Array(pt*Jt*3),i=pt/2,f=new Float64Array(4);for(let u=0;u<Jt;u++)for(let _=0;_<i;_++){const l=(_+.5)/pt,s=(u+.5)/Jt,c=qt*l,m=s*2-1,d=Math.sign(m)*Fn(m)*vn,h=Math.cos(d)*Math.cos(c),g=Math.cos(d)*Math.sin(c),p=Math.sin(d),v=Ht+o,b=le(0,0,v,h,g,p,se),y=le(0,0,v,h,g,p,Ht),S=y<0?b:y;n.inscattering(r,0,0,v,h,g,p,S,f);let T=0,A=0,O=0;for(let j=0;j<4;j++)T+=Hn[j][0]*f[j],A+=Hn[j][1]*f[j],O+=Hn[j][2]*f[j];const E=(u*pt+_)*3;a[E]=T,a[E+1]=A,a[E+2]=O;const k=(u*pt+(pt-_-1))*3;a[k]=T,a[k+1]=A,a[k+2]=O}return a}function Or(e){const[t]=ge(e.sunElevation,e.sunRotation);return No(e,t)}function ve(e){const[t]=ge(e.sunElevation,e.sunRotation);return JSON.stringify([t,e.altitude,e.airDensity,e.aerosolDensity,e.ozoneDensity])}const Tr=6,Qt=new Map;function Ar(e){return Qt.has(ve(e))}function Ro(e,t){Qt.set(ve(e),t),Qt.size>Tr&&Qt.delete(Qt.keys().next().value)}function Sr(e){const[t,n]=ge(e.sunElevation,e.sunRotation),o=ve(e);let r=Qt.get(o);r===void 0&&(r=No(e,t),Ro(e,r));const a=new x;return i=>{const f=Math.hypot(i.x,i.y),u=Math.atan2(i.z,f);let l=(Math.atan2(i.x,i.y)+Math.PI+n)/qt;l-=Math.floor(l);const s=Math.abs(u),c=_n(Math.sqrt(s/vn)*Math.sign(u)*.5+.5),m=l*pt-.5,d=c*Jt-.5,h=Math.floor(m),g=Math.floor(d),p=m-h,v=d-g,b=k=>(k%pt+pt)%pt,y=k=>k<0?0:k>Jt-1?Jt-1:k,S=b(h),T=b(h+1),A=y(g),O=y(g+1),E=[0,0,0];for(let k=0;k<3;k++){const j=Nt(r[(A*pt+S)*3+k],r[(A*pt+T)*3+k],p),G=Nt(r[(O*pt+S)*3+k],r[(O*pt+T)*3+k],p);E[k]=Nt(j,G,v)}return a.set(Pt[0][0]*E[0]+Pt[0][1]*E[1]+Pt[0][2]*E[2],Pt[1][0]*E[0]+Pt[1][1]*E[1]+Pt[1][2]*E[2],Pt[2][0]*E[0]+Pt[2][1]*E[1]+Pt[2][2]*E[2])}}let zt=null,bn=!1,Mr=0;const dn=new Map;function Pr(){if(zt||bn)return zt;if(typeof Worker>"u")return bn=!0,null;try{zt=new Worker(new URL("/assets/sky-precompute-worker-ChN7J87v.js",import.meta.url),{type:"module"})}catch{return bn=!0,null}return zt.onmessage=e=>{const{id:t,pixels:n,error:o}=e.data,r=dn.get(t);r&&(dn.delete(t),n?r.resolve(n):r.reject(new Error(o??"sky worker returned nothing")))},zt.onerror=e=>{const t=new Error(`sky worker failed: ${e.message||"unknown error"}`);for(const n of dn.values())n.reject(t);dn.clear(),zt?.terminate(),zt=null,bn=!0},zt}function Er(e){const t=Pr();if(!t)return Promise.resolve(Or(e));const n=Mr++,o={id:n,parameters:e};return new Promise((r,a)=>{dn.set(n,{resolve:r,reject:a}),t.postMessage(o)})}function Nr(e,t,n,o={}){switch(o.type??"LINEAR"){case"QUADRATIC":{const r=Math.max(e,0);return r*r}case"EASING":{const r=Math.min(1,Math.max(0,e));return r*r*(3-2*r)}case"DIAGONAL":return(e+t)/2;case"SPHERICAL":return Math.max(.999999-Math.hypot(e,t,n),0);case"QUADRATIC_SPHERE":{const r=Math.max(.999999-Math.hypot(e,t,n),0);return r*r}case"RADIAL":return Math.atan2(t,e)/(2*Math.PI)+.5;default:return e}}const Gn=(e,t)=>t!==0?e/t:0,Ve=e=>Math.min(1,Math.max(-1,e)),je=(e,t,n)=>{const o=n!==0?Math.max(n-Math.abs(e-t),0)/n:0;return Math.min(e,t)-o*o*o*n/6},Io={ADD:(e,t)=>e+t,SUBTRACT:(e,t)=>e-t,MULTIPLY:(e,t)=>e*t,DIVIDE:Gn,POWER:(e,t)=>t===0?1:e===0||e<0&&!Number.isInteger(t)?0:e**t,LOGARITHM:(e,t)=>e<=0||t<=0?0:Gn(Math.log(e),Math.log(t)),SQRT:e=>Math.sqrt(Math.max(e,0)),INVERSE_SQRT:e=>e>0?1/Math.sqrt(e):0,ABSOLUTE:Math.abs,RADIANS:e=>e*Math.PI/180,DEGREES:e=>e*180/Math.PI,MINIMUM:(e,t)=>Math.min(e,t),MAXIMUM:(e,t)=>Math.max(e,t),LESS_THAN:(e,t)=>+(e<t),GREATER_THAN:(e,t)=>+(e>t),ROUND:e=>Math.floor(e+.5),FLOOR:Math.floor,CEIL:Math.ceil,FRACT:e=>e-Math.floor(e),MODULO:(e,t)=>t!==0?e%t:0,FLOORED_MODULO:(e,t)=>t!==0?e-Math.floor(e/t)*t:0,TRUNC:Math.trunc,SNAP:(e,t)=>Math.floor(Gn(e,t))*t,WRAP:(e,t,n)=>t!==n?e-(t-n)*Math.floor((e-n)/(t-n)):n,PINGPONG:(e,t)=>{if(t===0)return 0;const n=(e-t)/(t*2);return Math.abs((n-Math.floor(n))*t*2-t)},SINE:Math.sin,COSINE:Math.cos,TANGENT:Math.tan,SINH:Math.sinh,COSH:Math.cosh,TANH:Math.tanh,ARCSINE:e=>Math.asin(Ve(e)),ARCCOSINE:e=>Math.acos(Ve(e)),ARCTANGENT:Math.atan,ARCTAN2:(e,t)=>e===0&&t===0?0:Math.atan2(e,t),SIGN:Math.sign,EXPONENT:Math.exp,COMPARE:(e,t,n)=>+(e===t||Math.abs(e-t)<=Math.max(n,2**-23)),MULTIPLY_ADD:(e,t,n)=>e*t+n,SMOOTH_MIN:je,SMOOTH_MAX:(e,t,n)=>-je(-e,-t,n)};function at(e,t){if(typeof e=="number")return()=>e;if(Array.isArray(e)){const r=new x(...e);return()=>r}if(e.kind==="direction")return r=>r;if(e.kind==="window"){if(!t)throw new Error("World Window coordinates need a render camera");return t}if(e.kind==="gradient"){const r=at(e.vector,t),a={type:e.gradient_type},i=new x;return f=>{const u=r(f),_=typeof u=="number"?u:u.x,l=typeof u=="number"?u:u.y,s=typeof u=="number"?u:u.z,c=bt.clamp(Nr(_,l,s,a),0,1);return e.output==="Fac"?c:i.setScalar(c)}}if(e.kind==="to_float"){const r=at(e.value,t);return a=>{const i=r(a);return typeof i=="number"?i:Math.fround(e.source_type==="RGBA"?i.x*.212639+i.y*.7151687+i.z*.0721923:(i.x+i.y+i.z)/3)}}if(e.kind==="math"){const r=e.inputs.map(f=>at(f,t)),a=Io[e.operation],i=(f,u)=>{const _=r[f]?.(u)??0;if(typeof _!="number")throw new Error("World Math needs scalar inputs");return Math.fround(_)};return f=>{const u=Math.fround(a(i(0,f),i(1,f),i(2,f)));return e.clamp?bt.clamp(u,0,1):u}}if(e.kind==="mix_color"){const r=at(e.factor,t),a=at(e.a,t),i=at(e.b,t),f=new x,u=new x;return _=>{const l=r(_);if(typeof l!="number")throw new Error("World color Mix needs a scalar factor");const s=a(_);typeof s=="number"?f.setScalar(s):f.copy(s);const c=i(_);return typeof c=="number"?u.setScalar(c):u.copy(c),f.lerp(u,e.clamp_factor?bt.clamp(l,0,1):l),e.clamp_result&&f.clampScalar(0,1),f}}if(e.kind==="sky"){const r=Sr({sunElevation:e.sun_elevation,sunRotation:e.sun_rotation,altitude:e.altitude,airDensity:e.air_density,aerosolDensity:e.aerosol_density,ozoneDensity:e.ozone_density});return a=>r(a)}if(e.kind==="mapping"){const r=at(e.vector,t),a=new x(...e.location),i=new x(...e.scale),f=new Tt().setFromEuler(new Zo(e.rotation[0],e.rotation[1],e.rotation[2],"ZYX")),u=f.clone().invert(),_=new x(...e.scale.map(s=>s===0?0:1/s)),l=new x;return s=>{const c=r(s);switch(typeof c=="number"?l.setScalar(c):l.copy(c),e.vector_type??"POINT"){case"TEXTURE":return l.sub(a).applyQuaternion(u).multiply(_);case"VECTOR":return l.multiply(i).applyQuaternion(f);case"NORMAL":return l.multiply(_).applyQuaternion(f).normalize();case"POINT":return l.multiply(i).applyQuaternion(f).add(a)}}}if(e.kind==="map_range"){const r=at(e.value,t),a=at(e.from_min,t),i=at(e.from_max,t),f=at(e.to_min,t),u=at(e.to_max,t),_=at(e.steps,t),l=(m,d)=>{const h=m(d);if(typeof h!="number")throw new Error("World Map Range needs scalar inputs");return h},s=e.interpolation,c=e.clamp;return m=>{const d=l(r,m),h=l(a,m),g=l(i,m),p=l(f,m),v=l(u,m);if(h===g)return 0;let b;if(s==="STEPPED"){const S=l(_,m),T=(d-h)/(g-h);b=S>0?Math.floor(T*(S+1))/S:0}else if(s==="SMOOTHSTEP"||s==="SMOOTHERSTEP"){const S=bt.clamp((d-Math.min(h,g))/(Math.max(h,g)-Math.min(h,g)),0,1),T=s==="SMOOTHSTEP"?S*S*(3-2*S):S*S*S*(S*(S*6-15)+10);b=h>g?1-T:T}else b=(d-h)/(g-h);const y=p+b*(v-p);return c?p>v?bt.clamp(y,v,p):bt.clamp(y,p,v):y}}if(e.kind==="separate"){const r=at(e.vector,t);return a=>{const i=r(a);return typeof i=="number"?i:i.getComponent(e.axis)}}const n=at(e.factor,t),o=new x;return r=>{const a=n(r);if(typeof a!="number")throw new Error("World ColorRamp needs a scalar factor");const i=bt.clamp(a,0,1)*256,f=Math.floor(i),u=e.colors[f],_=e.colors[Math.min(f+1,256)],l=e.interpolate?i-f:0;return o.set(bt.lerp(u[0],_[0],l),bt.lerp(u[1],_[1],l),bt.lerp(u[2],_[2],l))}}function Rr(e,t,n,o){const r=new Float32Array(t*n*3),a=at(e,o),i=new x;for(let f=0;f<n;f++){const u=((f+.5)/n-.5)*Math.PI;for(let _=0;_<t;_++){const l=((_+.5)/t-.5)*2*Math.PI;i.set(Math.cos(u)*Math.cos(l),-Math.cos(u)*Math.sin(l),Math.sin(u));const s=a(i),c=(f*t+_)*3;r[c]=typeof s=="number"?s:s.x,r[c+1]=typeof s=="number"?s:s.y,r[c+2]=typeof s=="number"?s:s.z}}return r}function Be(e){const t=[],n=o=>{if(!(typeof o=="number"||Array.isArray(o)))switch(o.kind){case"sky":t.push({sunElevation:o.sun_elevation,sunRotation:o.sun_rotation,altitude:o.altitude,airDensity:o.air_density,aerosolDensity:o.aerosol_density,ozoneDensity:o.ozone_density});return;case"mapping":case"gradient":case"separate":n(o.vector);return;case"ramp":n(o.factor);return;case"mix_color":n(o.factor),n(o.a),n(o.b);return;case"math":o.inputs.forEach(n);return;case"to_float":n(o.value);return;case"map_range":n(o.value),n(o.from_min),n(o.from_max),n(o.to_min),n(o.to_max),n(o.steps);return;default:return}};return n(e),t}function Dt(e){if(typeof e=="number"||Array.isArray(e))return!1;switch(e.kind){case"window":return!0;case"mapping":case"gradient":case"separate":return Dt(e.vector);case"ramp":return Dt(e.factor);case"mix_color":return[e.factor,e.a,e.b].some(Dt);case"math":return e.inputs.some(Dt);case"to_float":return Dt(e.value);case"map_range":return[e.value,e.from_min,e.from_max,e.to_min,e.to_max,e.steps].some(Dt);default:return!1}}function Ir(e,t,n,o){o.updateMatrixWorld();const r=new Float32Array(t*n*3),a=new x,i=at(e,()=>a),f=new x,u=o.getWorldPosition(new x),_=o.getWorldDirection(new x);for(let l=0;l<n;l++)for(let s=0;s<t;s++){const c=(s+.5)/t,m=(l+.5)/n;a.set(c,m,0),o.isOrthographicCamera?f.copy(_):f.set(c*2-1,m*2-1,.5).unproject(o).sub(u).normalize(),f.set(f.x,-f.z,f.y);const d=i(f),h=(l*t+s)*3;r[h]=typeof d=="number"?d:d.x,r[h+1]=typeof d=="number"?d:d.y,r[h+2]=typeof d=="number"?d:d.z}return r}const ot=N().finite(),zr=M({type:H(["POINT","SUN","SPOT","AREA"]),color:L([ot,ot,ot]),energy:ot,use_shadow:Q().default(!0),radius:ot.optional(),spot_size:ot.optional(),spot_blend:ot.optional(),shape:H(["SQUARE","RECTANGLE","DISK","ELLIPSE"]).optional(),size:ot.optional(),size_y:ot.optional()}).strict();let fe;function Fr(){return fe??=Na(async()=>{const{RectAreaLightUniformsLib:e}=await import("./RectAreaLightUniformsLib-DpPyArRG.js");return{RectAreaLightUniformsLib:e}},__vite__mapDeps([0,1,2])).then(({RectAreaLightUniformsLib:e})=>{e.init(),ht()}),fe}function Dr(){return fe??Promise.resolve()}const Cr=e=>{const t=e.size??0,n=e.size_y??t;if(e.shape==="RECTANGLE")return[t,n];if(e.shape==="DISK"){const o=Math.sqrt(Math.PI*t*t/4);return[o,o]}if(e.shape==="ELLIPSE"){const o=Math.sqrt(Math.PI/4);return[t*o,n*o]}return[t,t]};function kr(e,t){const n=(i,f)=>t&&f(t)?t:new i;if(e.type==="SUN"){const i=n(mo,f=>f.isDirectionalLight);return i.intensity=e.energy,i.color.setRGB(e.color[0],e.color[1],e.color[2],vt),i.castShadow=e.use_shadow,i}if(e.type==="POINT"){const i=n(te,f=>f.isPointLight);return i.intensity=e.energy/(4*Math.PI),i.distance=0,i.decay=2,i.color.setRGB(e.color[0],e.color[1],e.color[2],vt),i.castShadow=e.use_shadow,i}if(e.type==="SPOT"){const i=n(ne,f=>f.isSpotLight);return i.intensity=e.energy/(4*Math.PI),i.distance=0,i.decay=2,i.angle=(e.spot_size??0)/2,i.penumbra=e.spot_blend??0,i.color.setRGB(e.color[0],e.color[1],e.color[2],vt),i.castShadow=e.use_shadow,i}Fr();const o=n(Pn,i=>i.isRectAreaLight),[r,a]=Cr(e);return o.width=r,o.height=a,o.intensity=e.energy/(Math.max(r*a,Number.MIN_VALUE)*Math.PI),o.color.setRGB(e.color[0],e.color[1],e.color[2],vt),o}function $r(e,t,n){if(!e.castShadow||n<=0)return;const r=e.getWorldPosition(new x).distanceTo(t),a=e.shadow;if(!a)return;const i=a.camera;i.near=Math.max(n*.001,r-n),i.far=r+n,e.isDirectionalLight&&(i.left=-n,i.right=n,i.top=n,i.bottom=-n),i.updateProjectionMatrix()}function Lr(e,t){e.position.set(0,0,0);const n=e;e.isRectAreaLight||n.target&&n.target.parent!==t&&(n.target.position.set(0,0,-1),t.add(n.target))}const xe=[{direction:[-.352546,.170931,-.920051],diffuse:[.033103,.033103,.033103],specular:[.266761,.266761,.266761],smooth:.52662},{direction:[-.408163,.346939,.844415],diffuse:[.521083,.538226,.538226],specular:[.59903,.59903,.59903],smooth:0},{direction:[.521739,.826087,.212999],diffuse:[.038403,.034357,.04953],specular:[.106102,.125981,.158523],smooth:.478261},{direction:[.624519,-.562067,-.542269],diffuse:[.090838,.08208,.072255],specular:[.106535,.084771,.06608],smooth:.2}],Ue=.69;class Vr{constructor(){this.group=new it,this.lights=[],this.group.name="BlenderSolidStudio";const t=new uo;t.name="BlenderSolidStudioTarget",this.group.add(t);const n=new Ot(0,0,0);for(const[r,a]of xe.entries()){const i=(1+a.smooth)**2,f=new mo(16777215,Math.PI*Ue/i);f.name=`BlenderSolidLight${r}`,f.color.setRGB(a.diffuse[0],a.diffuse[1],a.diffuse[2],vt),f.position.set(a.direction[0],a.direction[1],a.direction[2]),f.target=t,this.group.add(f),this.lights.push(f),n.r+=a.diffuse[0]*a.smooth/i,n.g+=a.diffuse[1]*a.smooth/i,n.b+=a.diffuse[2]*a.smooth/i}const o=new Qo(16777215,Math.PI*Ue);o.name="BlenderSolidWrapFill",o.color.copy(n),this.group.add(o),this.lights.push(o)}setRendered(t){this.group.visible=!t}dispose(){for(const t of this.lights)t.dispose();this.group.clear()}}const Zt=L([ot,ot,ot]),X=wo(()=>Lt([ot,Zt,M({kind:q("direction")}).strict(),M({kind:q("window")}).strict(),M({kind:q("gradient"),gradient_type:H(["LINEAR","QUADRATIC","EASING","DIAGONAL","SPHERICAL","QUADRATIC_SPHERE","RADIAL"]),output:H(["Fac","Color"]),vector:X}).strict(),M({kind:q("to_float"),source_type:H(["RGBA","VECTOR"]),value:X}).strict(),M({kind:q("math"),operation:H(Object.keys(Io)),clamp:Q(),inputs:D(X).min(1).max(3)}).strict(),M({kind:q("mix_color"),factor:X,a:X,b:X,clamp_factor:Q(),clamp_result:Q()}).strict(),M({kind:q("mapping"),vector_type:H(["POINT","TEXTURE","VECTOR","NORMAL"]).optional(),vector:X,location:Zt,rotation:Zt,scale:Zt}).strict(),M({kind:q("separate"),vector:X,axis:N().int().min(0).max(2)}).strict(),M({kind:q("ramp"),factor:X,colors:D(Zt).length(257),interpolate:Q()}).strict(),M({kind:q("map_range"),interpolation:H(["LINEAR","STEPPED","SMOOTHSTEP","SMOOTHERSTEP"]),clamp:Q(),value:X,from_min:X,from_max:X,to_min:X,to_max:X,steps:X}).strict(),M({kind:q("sky"),sun_elevation:ot,sun_rotation:ot,altitude:ot,air_density:ot,aerosol_density:ot,ozone_density:ot}).strict()])),We=M({color:Zt,strength:ot,shader:X.optional()}),jr=We.extend({volume:D(M({kind:H(["absorption","scatter","principled","emission"]),phase:R(),alpha:X,weight:X,color:X,density:X,anisotropy:X,absorption_color:X,emission_color:X,emission_strength:X,blackbody_intensity:X,temperature:X,blackbody_tint:X}).strict()).optional(),lighting:We.strict().optional()}).strict(),Br=4,cn=new Map,Xn=new Set;function qe(e,t,n){const a=Dt(e);if(a&&!n)throw new Error("World Window coordinates need a render camera");n?.updateMatrixWorld();const i=JSON.stringify([e,a?[n.matrixWorld.elements,n.projectionMatrix.elements]:null]),f=cn.get(i);if(f!==void 0)return ce(f,t,256,128);const u=new x,_=new Cn,l=n?new B().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse):null,s=n?.getWorldPosition(new x),m=Rr(e,256,128,a?d=>(u.set(d.x,d.z,-d.y),n.isPerspectiveCamera&&u.add(s),_.set(u.x,u.y,u.z,1).applyMatrix4(l),_.w===0?u.set(0,0,0):u.set(_.x/_.w*.5+.5,_.y/_.w*.5+.5,0)):void 0);return cn.set(i,m),cn.size>Br&&cn.delete(cn.keys().next().value),ce(m,t,256,128)}function Ur(e,t,n,o){const r=mn.toHalfFloat(1);for(let a=0;a<o;a++)e[a*4]=mn.toHalfFloat(t[a*3]*n),e[a*4+1]=mn.toHalfFloat(t[a*3+1]*n),e[a*4+2]=mn.toHalfFloat(t[a*3+2]*n),e[a*4+3]=r}function ce(e,t,n,o){const r=new Uint16Array(n*o*4);Ur(r,e,t,n*o);const a=new kn(r,n,o,$n,he);return a.mapping=Jo,a.colorSpace=vt,a.minFilter=Xt,a.magFilter=Xt,a.needsUpdate=!0,a}class be{constructor(){this.pending=null,this.texture=null,this.environmentTexture=null,this.screenTexture=null,this.applied=null,this.generation=0}async ready(){await this.pending}static sceneOf(t){let n=t;for(;n;){if(n.isScene)return n;n=n.parent}return null}apply(t,n,o){if(this.clear(),this.pending=null,!n)return;const r=be.sceneOf(t);if(!r)return;this.applied={scene:r,background:r.background,environment:r.environment};const a=n.shader??n.color,i=this.generation,u=[...Be(a),...n.lighting?Be(n.lighting.shader??n.lighting.color):[]].filter(l=>!Ar(l));if(u.length===0){this.compose(r,n,a,o);return}const _=(async()=>{const l=await Promise.all(u.map(Er));u.forEach((s,c)=>{Ro(s,l[c])}),!(this.generation!==i||this.applied?.scene!==r)&&(this.compose(r,n,a,o),ht())})();this.pending=_,Xn.add(_),_.then(()=>Xn.delete(_),()=>Xn.delete(_))}compose(t,n,o,r){if(this.texture=qe(o,n.strength,r),Dt(o)){if(!r)throw new Error("World Window coordinates need a render camera");this.screenTexture=ce(Ir(o,512,512,r),n.strength,512,512),this.screenTexture.mapping=Ko,t.background=this.screenTexture}else if(r&&r.isOrthographicCamera){const i=r.getWorldDirection(new x);i.set(i.x,-i.z,i.y);const f=at(n.shader??n.color)(i);t.background=typeof f=="number"?new Ot().setRGB(f,f,f).multiplyScalar(n.strength):new Ot().setRGB(f.x,f.y,f.z).multiplyScalar(n.strength)}else t.background=this.texture;const{lighting:a}=n;this.environmentTexture=a?qe(a.shader??a.color,a.strength,r):null,t.environment=this.environmentTexture??this.texture}clear(){this.generation++,this.applied&&(this.applied.scene.background=this.applied.background,this.applied.scene.environment=this.applied.environment,this.applied=null,this.texture?.dispose(),this.texture=null,this.environmentTexture?.dispose(),this.environmentTexture=null,this.screenTexture?.dispose(),this.screenTexture=null)}dispose(){this.clear()}}function zo(e){return[e.min.x,e.max.x].flatMap(t=>[e.min.y,e.max.y].flatMap(n=>[e.min.z,e.max.z].map(o=>new x(t,n,o))))}function Wr(e,t){if(e.isEmpty()||!t.intersectsBox(e))return[];const n=zo(e);if(n.every(l=>t.containsPoint(l)))return n;const o=[...t.planes,new Bt(new x(1,0,0),-e.min.x),new Bt(new x(-1,0,0),e.max.x),new Bt(new x(0,1,0),-e.min.y),new Bt(new x(0,-1,0),e.max.y),new Bt(new x(0,0,1),-e.min.z),new Bt(new x(0,0,-1),e.max.z)],r=[],a=new x,i=new x,f=new x,u=new x,_=Math.max(1,e.min.length(),e.max.length())*1e-8;for(let l=0;l<o.length;l++)for(let s=l+1;s<o.length;s++)for(let c=s+1;c<o.length;c++){const m=o[l],d=o[s],h=o[c];a.crossVectors(d.normal,h.normal);const g=m.normal.dot(a);Math.abs(g)<1e-12||(i.crossVectors(h.normal,m.normal),f.crossVectors(m.normal,d.normal),u.copy(a).multiplyScalar(-m.constant).addScaledVector(i,-d.constant).addScaledVector(f,-h.constant).divideScalar(g),o.every(p=>p.distanceToPoint(u)>=-_)&&r.push(u.clone()))}return r}function qr(e,t,n){if(!e.castShadow||!t.length)return;e.shadow.updateMatrices(e);const o=e.shadow.camera,r=o.matrixWorldInverse,a=new gn().setFromPoints(t.map(c=>c.clone().applyMatrix4(r))),i=a.getSize(new x),f=Math.max(i.length()*1e-6,Number.EPSILON),u=2+2*Math.SQRT2,_=Math.max(i.x,i.y,f)/Math.max(1,Math.min(e.shadow.mapSize.x,e.shadow.mapSize.y)-2*u),l=2*Math.SQRT2*_,s=u*_;a.min.x-=s,a.min.y-=s,a.max.x+=s,a.max.y+=s;for(const c of n){if(c.isEmpty())continue;const m=new gn().setFromPoints(zo(c).map(d=>d.applyMatrix4(r)));m.max.x<a.min.x||m.min.x>a.max.x||m.max.y<a.min.y||m.min.y>a.max.y||(a.min.z=Math.min(a.min.z,m.min.z),a.max.z=Math.max(a.max.z,m.max.z))}o.left=a.min.x,o.right=a.max.x,o.bottom=a.min.y,o.top=a.max.y,o.near=-a.max.z-l-f,o.far=-a.min.z+l+f,o.updateProjectionMatrix(),e.shadow.normalBias=l}const tn=N().finite(),He=L([tn,tn,tn]),Fo=M({min:L([N().int(),N().int(),N().int()]),max:L([N().int(),N().int(),N().int()]),density:D(tn),voxelSize:tn.positive(),color:He,emission:He,densityScale:tn.nonnegative()}).strict();function Hr(e){const t=e.max.map((l,s)=>l-e.min[s]+1);if(t.some(l=>l<=0)||t.reduce((l,s)=>l*s,1)!==e.density.length)throw new Error("Volume density dimensions do not match the evaluated grid");const n=new ta(new Float32Array(e.density),t[0],t[1],t[2]);n.format=na,n.type=_o,n.minFilter=n.magFilter=Xt,n.unpackAlignment=1,n.needsUpdate=!0;const o=new x(...e.min).addScalar(-.5).multiplyScalar(e.voxelSize),r=new x(t[0],t[1],t[2]).multiplyScalar(e.voxelSize),a=new ea(r.x,r.y,r.z),i=a.getAttribute("position");for(let l=0;l<i.count;l++)i.setXYZ(l,o.x+(i.getX(l)>0?r.x:0),o.y+(i.getY(l)>0?r.y:0),o.z+(i.getZ(l)>0?r.z:0));i.needsUpdate=!0,a.computeBoundingBox(),a.computeBoundingSphere();const f=new de({glslVersion:aa,side:oa,transparent:!0,depthWrite:!1,premultipliedAlpha:!0,uniforms:{densityGrid:{value:n},minimum:{value:o},extent:{value:r},voxelSize:{value:e.voxelSize},densityScale:{value:e.densityScale},volumeColor:{value:new x(...e.color)},emission:{value:new x(...e.emission)},cameraLocal:{value:new x},rayLocal:{value:new x},orthographic:{value:!1},worldScale:{value:new co}},vertexShader:`
19
+ `;function Dt(e){return new Ot().setHex(e,Lt)}function Ne(e,t){const n=e.mode==="POSE";let o;return n?t.active&&t.select?o=Dt(St.poseActive):t.active?o=Dt(St.poseActiveUnsel):t.select?o=Dt(St.pose):o=Dt(St.wire):o=Dt(St.vertex),n&&t.lockedWeight&&o.lerp(Dt(St.lockedWeight),St.lockedWeightFactor),o}function Re(e,t){const n=Dt(St.solid);return e.mode==="POSE"&&t.lockedWeight&&n.lerp(Dt(St.lockedWeight),St.lockedWeightFactor),n}const Xa=new H,Ya=new x,Ie=new _o;function ze(e,t){return new H().set(...t.matrix.flat()).premultiply(e).scale(new x().setScalar(t.length))}class Za{constructor(){this.group=new lt,this.disposables=[],this.signature="",this.group.name="BlenderArmatureOverlay"}apply(t,n){const o=[],r=JSON.stringify(t);if(r===this.signature)return o;this.signature=r,this.clear();for(const a of Object.values(t)){const i=n(a.object);if(i===null)continue;a.displayType!=="OCTAHEDRAL"&&a.displayType!=="STICK"&&o.push(`armature ${a.object}: Blender's ${a.displayType} bone display needs data this door does not carry (B-Bone segment matrices, envelope radii), so its bones are drawn octahedral`),a.mode==="EDIT"&&o.push(`armature ${a.object}: in Edit Mode Blender draws the EDIT bones, and this overlay draws the pose — the shapes are the rest pose, not the edited one`);const f=a.bones.filter(_=>!_.hide);if(f.length===0)continue;const u=a.displayType==="STICK"?this.buildStick(a,f,i):this.buildOctahedral(a,f,i);a.showInFront&&u.traverse(_=>{const l=_.material;l&&"depthTest"in l&&(l.depthTest=!1),_.renderOrder=10}),this.group.add(u)}return o}buildOctahedral(t,n,o){const r=new lt;r.name=`${t.object}:bones`;const a=[],i=[],f=[],u=[],_=[],l=[],s=[],c=[],m=[],d=[];for(const h of n){const g=ze(o,h),p=Re(t,h),v=Va(p),O=Ne(t,h);Ie.setFromMatrix4(g).invert().transpose();for(let T=0;T<Pe.length;T++){const M=Ya.set(...ja[T]).applyMatrix3(Ie).normalize().clone();for(const A of Pe[T]){const w=new x(...Bn[A]).applyMatrix4(g);a.push(w.x,w.y,w.z),i.push(M.x,M.y,M.z),f.push(p.r,p.g,p.b),u.push(v.r,v.g,v.b)}}const b=Ee(h)===2?s:_,P=Ee(h)===2?c:l;for(const[T,M]of Ba){const A=new x(...Bn[T]).applyMatrix4(g),w=new x(...Bn[M]).applyMatrix4(g);b.push(A.x,A.y,A.z,w.x,w.y,w.z),P.push(O.r,O.g,O.b,O.r,O.g,O.b)}h.parent!==null&&h.connected||(m.push(g.clone()),d.push(p)),m.push(g.clone().multiply(Xa.makeTranslation(0,1,0))),d.push(p)}r.add(this.solidMesh(a,i,f,u)),_.length&&r.add(this.lines(_,l,1)),s.length&&r.add(this.lines(s,c,2));for(let h=0;h<m.length;h++)r.add(this.point(m[h],d[h]));return r}buildStick(t,n,o){const r=new lt;r.name=`${t.object}:bones`;const a=[],i=[],f=[],u=[];for(const _ of n){const l=ze(o,_),s=new x().setFromMatrixPosition(l),c=new x(0,1,0).applyMatrix4(l),m=Ne(t,_),d=Re(t,_);a.push(s.x,s.y,s.z,c.x,c.y,c.z),i.push(m.r,m.g,m.b,m.r,m.g,m.b),f.push(s.x,s.y,s.z,c.x,c.y,c.z),u.push(d.r,d.g,d.b,d.r,d.g,d.b)}return r.add(this.lines(a,i,Wa)),r.add(this.lines(f,u,qa)),r}solidMesh(t,n,o,r){const a=new sn;a.setAttribute("position",new Mt(t,3)),a.setAttribute("normal",new Mt(n,3)),a.setAttribute("aSolid",new Mt(o,3)),a.setAttribute("aHint",new Mt(r,3));const i=new pe({vertexShader:Ha,fragmentShader:Ga,side:Zo});this.disposables.push(a,i);const f=new Rt(a,i);return f.frustumCulled=!1,f}lines(t,n,o){const r=new co;r.setPositions(t),r.setColors(n);const a=new uo({linewidth:o,vertexColors:!0});this.disposables.push(r,a);const i=new mo(r,a);return i.frustumCulled=!1,i}point(t,n){const o=new Qo(Ua,12,8),r=new In({color:n});this.disposables.push(o,r);const a=new Rt(o,r);return a.applyMatrix4(t),a.frustumCulled=!1,a}clear(){for(const t of[...this.group.children])this.group.remove(t);for(const t of this.disposables)t.dispose();this.disposables.length=0}dispose(){this.clear(),this.signature=""}}const Fe="RUNTIME_FRAME_UNKNOWN_GEOMETRY",fn="RUNTIME_FRAME_UNKNOWN_IMAGE";function Qa(e){const t=Math.fround,n=t(t(t(e[0]*e[0])+t(e[1]*e[1]))+t(e[2]*e[2]));if(n>1e-35){const o=t(Math.sqrt(n)),r=t(1/o);return{unit:[t(e[0]*r),t(e[1]*r),t(e[2]*r)],length:o}}return{unit:[0,0,0],length:0}}const F=Math.fround,Fn=F(2*Math.PI),Un=F(1-1e-4),qt=(e,t)=>F(F(F(e[0]*t[0])+F(e[1]*t[1]))+F(e[2]*t[2])),vn=(e,t,n=1)=>e.map((o,r)=>F(o+F(t[r]*n))),Ka=(e,t)=>e.map((n,o)=>F(n-t[o]));function cn(e){const t=F(Math.sqrt(qt(e,e)));return t>0?e.map(n=>F(n/t)):[0,0,0]}function un(e){const t=Math.abs(e)<1?F(1-F(1-Math.abs(e))):1;let n=F(F(.077980478)+F(t*F(-.02164095)));n=F(F(-.213300989)+F(t*n)),n=F(F(1.5707963267)+F(t*n));const o=F(F(Math.sqrt(F(1-t)))*n);return e<0?F(F(Math.PI)-o):o}function Ja(e){let t=e.at(-1);const n=[0,0,0];for(const o of e){for(let r=0;r<3;r++){const a=(r+1)%3,i=(r+2)%3;n[r]=F(n[r]+F(F(t[a]-o[a])*F(t[i]+o[i])))}t=o}return n}function tr(e){const t=[],n=[],o=(d,h)=>d<h?`${d}:${h}`:`${h}:${d}`,r=new Map((e.edge_order??[]).map(([d,h],g)=>[o(d,h),g])),a=new Set((e.sharp??[]).map(([d,h])=>o(d,h))),i=new Map;for(const[d,h]of e.f.entries()){const g=t.length,p=Qa(Ja(h.map(v=>e.v[v]))).unit;n.push(p.some(Boolean)?p:[0,0,1]);for(let v=0;v<h.length;v++){const O=o(h[v],h[(v+1)%h.length]);r.has(O)||r.set(O,r.size);const b=e.face_edges?.[d]?.[v]??r.get(O),P=t.length;t.push({vertex:h[v],face:d,edge:b,prev:g+(v+h.length-1)%h.length,next:g+(v+1)%h.length});const T=i.get(b)??[];T.push(P),i.set(b,T)}}const f=new Map,u=new Map;for(const[d,h]of i){if(h.length!==2||e.edge_sharp?.[d])continue;const[g,p]=h,v=t[g],O=t[p];!e.s?.[v.face]||!e.s?.[O.face]||v.vertex!==t[O.next].vertex||O.vertex!==t[v.next].vertex||!e.edge_sharp&&a.has(o(v.vertex,O.vertex))||(u.set(g,O.next),f.set(O.next,g),u.set(p,v.next),f.set(v.next,p))}const _=[],l=[],s=[],c=[],m=(d,h)=>cn(Ka(e.v[t[t[d][h]].vertex],e.v[t[d].vertex]));for(let d=0;d<t.length;d++){if(l[d]!==void 0)continue;let h=d;const g=new Set([h]);for(;u.has(h)&&!g.has(u.get(h));)h=u.get(h),g.add(h);u.has(h)&&(h=Math.min(...g));const p=[h];for(;f.has(p.at(-1))&&f.get(p.at(-1))!==h;)p.push(f.get(p.at(-1)));let v=[0,0,0];if(p.length===1)v=n[t[h].face];else{for(const w of p)v=vn(v,n[t[w].face],un(qt(m(w,"prev"),m(w,"next"))));v=cn(v)}const O=m(h,"next"),b=p.at(-1),P=m(b,"prev"),T=qt(O,v),M=qt(P,v),A={normal:v,reference:[0,0,0],ortho:[0,0,0],alpha:0,beta:0};if(Math.abs(T)<Un&&Math.abs(M)<Un){const w=p.length>1?p.map(nt=>m(nt,"next")):[];w.length&&t[t[b].prev].edge!==t[h].edge&&w.push(P),A.alpha=w.length?F(w.reduce((nt,y)=>F(nt+un(qt(y,v))),0)/w.length):F(F(un(T)+un(M))/2),A.reference=cn(vn(O,v,-T));const E=v,D=A.reference;A.ortho=cn([F(F(E[1]*D[2])-F(E[2]*D[1])),F(F(E[2]*D[0])-F(E[0]*D[2])),F(F(E[0]*D[1])-F(E[1]*D[0]))]);const W=cn(vn(P,v,-M)),V=qt(A.reference,W),G=un(V);A.beta=V<Un?qt(A.ortho,W)<0?F(Fn-G):G:Fn}A.alpha===0&&(A.normal=[0,0,0]);for(const w of p)l[w]=_.length;_.push(p),s.push(A),c.push(v)}return{corners:t,fans:_,fanOf:l,spaces:s,faceNormals:n,fanNormals:c}}function nr(e,t){if(!t[0]||e.alpha===0||e.beta===0)return e.normal;const n=F(t[0]/32767),o=F(t[1]/32767),r=F((n>0?e.alpha:F(Fn-e.alpha))*n),a=F((o>0?e.beta:F(Fn-e.beta))*o);let i=e.normal.map(f=>F(f*F(Math.cos(r))));return i=vn(i,e.reference,F(F(Math.sin(r))*F(Math.cos(a)))),o!==0&&(i=vn(i,e.ortho,F(F(Math.sin(r))*F(Math.sin(a))))),i}function Mo(e,t){if(!t)return null;const{corners:n,fans:o,spaces:r}=tr(e);if(t.type==="INT16_2D"&&t.domain==="CORNER"){const a=new Array(n.length);for(const[i,f]of o.entries()){const u=f.reduce((l,s)=>{const c=t.data[s];return[l[0]+c[0],l[1]+c[1]]},[0,0]),_=nr(r[i],u.map(l=>Math.trunc(l/f.length)));for(const l of f)a[l]=_}return a}if(t.type==="FLOAT_VECTOR")return n.map((a,i)=>{const f=t.domain==="POINT"?a.vertex:t.domain==="FACE"?a.face:i;return t.data[f]});throw new Error(`Unsupported custom_normal attribute: ${t.type}/${t.domain}`)}const Wn={FLOAT:{size:1},INT:{size:1},INT8:{size:1},BOOLEAN:{size:1},FLOAT2:{size:2},FLOAT_VECTOR:{size:3},FLOAT_COLOR:{size:4},BYTE_COLOR:{size:4},INT16_2D:{size:2},INT32_2D:{size:2},QUATERNION:{size:4},FLOAT4X4:{size:16},FLOAT4:{size:4},STRING:{size:1}},er=1e-6;function or(e){const t=new x;for(let n=0;n<e.length;n++){const o=e[n],r=e[(n+1)%e.length];t.x+=(o.y-r.y)*(o.z+r.z),t.y+=(o.z-r.z)*(o.x+r.x),t.z+=(o.x-r.x)*(o.y+r.y)}return t.multiplyScalar(.5)}const ar=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),De=e=>Array.from({length:e-2},(t,n)=>[0,n+1,n+2]);function rr(e){let t=0;for(let n=0;n<e.length;n++){const o=e[n],r=e[(n+1)%e.length];t+=o.x*r.y-r.x*o.y}return t}function Ce(e,t,n){if(e.length!==t.length-2||!(Math.abs(n)>0))return!1;const o=Math.sign(n);let r=0;for(const[a,i,f]of e){const u=ar(t[a],t[i],t[f]);if(u*o<0)return!1;r+=Math.abs(u)}return Math.abs(r-Math.abs(n))<=er*Math.abs(n)}function ir(e){const t=e.length;if(t<3)return{triangles:[],sound:!1,method:"fan"};if(t===3)return{triangles:[[0,1,2]],sound:!0,method:"fan"};const n=or(e),o=n.length();if(!(o>0)||!Number.isFinite(o))return{triangles:De(t),sound:!1,method:"fan"};const r=n.clone().divideScalar(o),a=Math.abs(r.x)<.9?new x(1,0,0):new x(0,1,0),i=new x().crossVectors(a,r).normalize(),f=new x().crossVectors(r,i),u=e[0],_=e.map(m=>{const d=m.clone().sub(u);return new Xt(d.dot(i),d.dot(f))}),l=rr(_),s=De(t);if(Ce(s,_,l))return{triangles:s,sound:!0,method:"fan"};let c=[];try{c=Ko.triangulateShape(_,[]).map(m=>[m[0],m[1],m[2]])}catch{return{triangles:s,sound:!1,method:"fan"}}return Ce(c,_,l)?{triangles:c,sound:!0,method:"earcut"}:{triangles:c.length>0?c:s,sound:!1,method:c.length>0?"earcut":"fan"}}const sr=new Set(["FLOAT","FLOAT2","FLOAT_VECTOR","FLOAT_COLOR","BYTE_COLOR"]);function qn(e){const t=e/255;return t<.04045?t<0?0:t*(1/12.92):((t+.055)*(1/1.055))**2.4}function Hn(e,t,n){switch(e){case"FLOAT":{const o=Number(t[n]);return[o,o,o,1]}case"FLOAT2":return[Number(t[n*2]),Number(t[n*2+1]),0,1];case"FLOAT_VECTOR":return[Number(t[n*3]),Number(t[n*3+1]),Number(t[n*3+2]),1];case"BYTE_COLOR":return[qn(Number(t[n*4])),qn(Number(t[n*4+1])),qn(Number(t[n*4+2])),Number(t[n*4+3])/255];default:return[Number(t[n*4]),Number(t[n*4+1]),Number(t[n*4+2]),Number(t[n*4+3])]}}function ve(e,t){return e.filter(n=>sr.has(n.type)&&n.domain!=="EDGE"&&!n.name.startsWith(".")&&n.name!=="position"&&n.name!=="custom_normal"&&!(n.type==="FLOAT2"&&n.domain==="CORNER")).map(n=>{const o=t(n.data,n.type),r=[0,0,0,0];return{name:n.name,domain:n.domain,read:(a,i,f)=>n.domain==="POINT"?Hn(n.type,o,a):n.domain==="CORNER"?i===void 0?r:Hn(n.type,o,i):f===void 0?r:Hn(n.type,o,f)}})}function Po(e){const t=e.vertexCount,n=e.starts.length-1,o=e.starts,r=e.cornerVerts,a=o[n];let i=t;for(let y=0;y<n;y++)i+=(o[y+1]-o[y]-2)*3;const f=new Uint32Array(a),u=new Uint8Array(a),_=new Uint8Array(t),l=new Uint32Array(a);let s=!1;for(let y=0;y<n;y++)if(e.smooth(y)){s=!0;break}const c=(y,j)=>t<94906265?Math.min(y,j)*t+Math.max(y,j):`${Math.min(y,j)}:${Math.max(y,j)}`,m=new Map,d=new Set;for(const[y,j]of e.sharp)d.add(c(y,j));if(e.edges)for(const[y,j]of e.edges){if(y===j)throw new Error("Runtime mesh edge needs distinct vertices");m.set(c(y,j),-1)}const h=y=>{for(;l[y]!==y;)l[y]=l[l[y]],y=l[y];return y},g=(y,j)=>{const k=h(y),q=h(j);l[Math.max(k,q)]=Math.min(k,q)};for(let y=0;y<n;y++){const j=o[y],k=o[y+1]-j,q=e.smooth(y)?1:0;for(let X=0;X<k;X++){const z=j+X;_[r[z]]=1,f[z]=j+(X+1)%k,u[z]=q,l[z]=z}}for(let y=0;y<a;y++){const j=f[y],k=r[y],q=r[j],X=c(k,q),z=m.get(X);if(z!==void 0&&z>=0&&u[y]&&u[z]&&!d.has(X)){const S=f[z];g(y,r[z]===k?z:S),g(j,r[z]===k?S:z)}(z===void 0||z<0||!u[z]&&u[y])&&m.set(X,y)}const p=e.uv,v=new Float32Array(i*3),O=new Float32Array(i*2),b=new Uint32Array(i),P=(e.uvLayers??[]).map(y=>({...y,data:new Float32Array(i*2)})),T=(e.attributeLayers??[]).map(y=>({...y,data:new Float32Array(i*4)})),M=e.orco?new Float32Array(i*3):null,A=new Uint32Array(i),w=new Map,E=[],D=e.normals||e.cornerNormal?new Float32Array(i*3):null;let W=0,V=0;const G=(y,j,k,q,X)=>{const z=W++;for(const S of T)S.data.set(S.read(y,q,X),z*4);if(M)for(let S=0;S<3;S++)M[z*3+S]=e.orco[y*3+S]*.5+.5;if(b[z]=y,e.co(y).toArray(v,z*3),j&&O.set(j,z*2),k&&D.set(k,z*3),q!==void 0)for(const S of P)S.data.set(S.read(q),z*2);return z},nt=(y,j)=>{const k=p?.(y),q=e.cornerNormal?[e.cornerNormal[y*3],e.cornerNormal[y*3+1],e.cornerNormal[y*3+2]]:e.normals?.[y];if(!s)return G(r[y],k,q,y,j);const X=`${u[y]?h(y):y}${k?`:${k[0]}:${k[1]}`:""}${q?`:n${q.join(":")}`:""}${P.map(S=>":"+S.read(y).join(":")).join("")}${T.map(S=>S.domain==="POINT"?"":":"+Array.from(S.read(r[y],y,j)).join(":")).join("")}`;let z=w.get(X);return z===void 0&&(z=G(r[y],k,q,y,j),w.set(X,z)),z};for(let y=0;y<n;y++){const j=V,k=o[y],q=o[y+1]-k,X=[];for(let B=0;B<q;B++)X.push(e.co(r[k+B]));for(const B of ir(X).triangles)for(const tt of B)A[V++]=nt(k+tt,y);const z=e.material(y),S=E.at(-1);S?.materialIndex===z?S.count+=V-j:E.push({start:j,count:V-j,materialIndex:z})}for(let y=0;y<t;y++)_[y]||G(y);return{positions:v.slice(0,W*3),normals:D?.slice(0,W*3)??null,uv:p?O.slice(0,W*2):null,uvLayers:P.map(y=>({name:y.name,data:y.data.slice(0,W*2)})),attributeLayers:T.map(y=>({name:y.name,data:y.data.slice(0,W*4)})),orco:M?M.slice(0,W*3):null,indices:A.slice(0,V),sourceVertex:b.slice(0,W),groups:E}}function $t(e){return`blenderA_${Array.from(new TextEncoder().encode(e),t=>t.toString(16).padStart(2,"0")).join("")}`}function Nn(e){const t=new sn;t.setAttribute("position",new ct(e.positions,3)),t.setAttribute("uv",new ct(e.uv??new Float32Array(e.positions.length/3*2),2)),t.setIndex(new ct(e.indices,1));const n=Object.create(null);for(const[o,r]of(e.uvLayers??[]).entries()){if(o>=8)throw new Error("A Blender mesh supports at most eight UV maps");n[r.name]=o+1,t.setAttribute(`uv${o+1}`,new ct(r.data,2))}t.userData.blenderUvChannels=n;for(const o of e.attributeLayers??[])t.setAttribute($t(o.name),new ct(o.data,4));t.userData.blenderAttributes=(e.attributeLayers??[]).map(o=>o.name),e.orco&&(t.setAttribute("blenderOrco",new ct(e.orco,3)),t.userData.blenderOrcoFromDoor=!0);for(const o of e.groups)t.addGroup(o.start,o.count,o.materialIndex);return e.normals?t.setAttribute("normal",new ct(e.normals,3)):t.computeVertexNormals(),e.sourceVertex&&t.setAttribute("blenderVertex",new ct(e.sourceVertex,1)),t}function lr(e,t){const n=e.cornerTri,o=e.cornerNormal,r=e.co.length/3,a=e.corner.length,i=e.faceStart.length-1,f=e.attributes.filter(S=>S.type==="FLOAT2"&&S.domain==="CORNER"),u=e.renderUv??e.activeUv??f[0]?.name,_=f.findIndex(S=>S.name===u);if(u&&_<0)throw new Error(`Runtime UV map ${u} is missing`);const l=ve(e.attributes,S=>S),s=3+f.length*2+l.length*4,c=new Float32Array(s),m=new Float32Array(s),d=new Uint32Array(c.buffer),h=new Uint32Array(m.buffer),g=new Uint32Array(a),p=new Uint32Array(a),v=new Uint32Array(a),O=new Uint32Array(a),b=new Uint8Array(r);let P=1;for(;P<Math.max(1,a*2);)P*=2;const T=new Uint32Array(P),M=(S,B,tt,Q)=>{let rt=0;for(let st=0;st<3;st++)Q[rt++]=o[S*3+st];for(const st of f)for(let ft=0;ft<2;ft++)Q[rt++]=Number(st.data[S*2+ft]);for(const st of l){const ft=st.read(tt,S,B);for(let Tt=0;Tt<4;Tt++)Q[rt++]=Number(ft[Tt])}};let A=0;for(let S=0;S<i;S++)for(let B=e.faceStart[S];B<e.faceStart[S+1];B++){const tt=e.corner[B];if(tt>=r)throw new Error("Native mesh corner references a missing vertex");g[B]=S,b[tt]=1,M(B,S,tt,c);let Q=Math.imul(tt^2166136261,16777619);for(const ft of d)Q=Math.imul(Q^ft,16777619);const rt=Q>>>0&P-1;let st=-1;for(let ft=T[rt];ft;ft=O[ft-1]){const Tt=ft-1,jn=v[Tt];if(e.corner[jn]!==tt)continue;M(jn,g[jn],tt,m);let Me=!0;for(let bn=0;bn<s;bn++)if(d[bn]!==h[bn]){Me=!1;break}if(Me){st=Tt;break}}st<0&&(st=A++,v[st]=B,O[st]=T[rt],T[rt]=st+1),p[B]=st}let w=0;for(const S of b)S||w++;const E=A+w,D=new Float32Array(E*3),W=new Float32Array(E*3),V=new Uint32Array(E),G=f.map(S=>({name:S.name,data:new Float32Array(E*2)})),nt=l.map(S=>({name:S.name,data:new Float32Array(E*4)})),y=e.orco?new Float32Array(E*3):null,j=(S,B)=>{V[S]=B;for(let tt=0;tt<3;tt++)D[S*3+tt]=e.co[B*3+tt],y&&(y[S*3+tt]=e.orco[B*3+tt]*.5+.5)};for(let S=0;S<A;S++){const B=v[S],tt=e.corner[B];j(S,tt),M(B,g[B],tt,c),W.set(c.subarray(0,3),S*3);let Q=3;for(const rt of G)rt.data.set(c.subarray(Q,Q+2),S*2),Q+=2;for(const rt of nt)rt.data.set(c.subarray(Q,Q+4),S*4),Q+=4}let k=A;for(let S=0;S<r;S++)if(!b[S]){j(k,S);for(let B=0;B<l.length;B++)nt[B].data.set(l[B].read(S,void 0,void 0),k*4);k++}const q=new Uint32Array(n.length),X=[];let z=0;for(let S=0;S<i;S++){const B=e.faceStart[S],tt=e.faceStart[S+1],Q=Math.max(0,tt-B-2)*3;if(z+Q>n.length)throw new Error("Native mesh triangulation is incomplete");for(let ft=0;ft<Q;ft++){const Tt=n[z+ft];if(Tt<B||Tt>=tt)throw new Error("Native triangle references a different face");q[z+ft]=p[Tt]}const rt=e.material[S],st=X.at(-1);st?.materialIndex===rt?st.count+=Q:X.push({start:z,count:Q,materialIndex:rt}),z+=Q}if(z!==n.length)throw new Error("Native mesh triangulation has extra triangles");return{positions:D,normals:W,sourceVertex:V,uv:_<0?null:G[_].data,uvLayers:G,attributeLayers:nt,orco:y,indices:q,groups:X,hash:t}}function ke(e,t){if(e.cornerTri&&e.cornerNormal)return lr(e,t);const n=e.co.length/3,o=e.attributes.filter(h=>h.type==="FLOAT2"&&h.domain==="CORNER"),r=e.renderUv??e.activeUv??o[0]?.name,a=o.find(h=>h.name===r);if(r&&!a)throw new Error(`Runtime UV map ${r} is missing`);const i=a?a.data:null,f=e.edge.length/2,u=new Array(f);for(let h=0;h<f;h++)u[h]=[e.edge[h*2],e.edge[h*2+1]];const _=[];for(let h=0;h<f;h++)e.edgeSharp[h]===1&&_.push(u[h]);const l=e.cornerNormal?void 0:e.attributes.find(h=>h.name==="custom_normal"),s=l?{v:Array.from({length:n},(h,g)=>[e.co[g*3],e.co[g*3+1],e.co[g*3+2]]),f:Array.from({length:e.faceStart.length-1},(h,g)=>Array.from(e.corner.subarray(e.faceStart[g],e.faceStart[g+1]))),s:Array.from(e.smooth,Boolean),edge_order:u,sharp:_,face_edges:Array.from({length:e.faceStart.length-1},(h,g)=>Array.from(e.cornerEdge.subarray(e.faceStart[g],e.faceStart[g+1]))),edge_sharp:Array.from(e.edgeSharp,Boolean)}:null,c=l?{type:l.type,domain:l.domain,data:Array.from({length:l.data.length/Wn[l.type].size},(h,g)=>Array.from({length:Wn[l.type].size},(p,v)=>Number(l.data[g*Wn[l.type].size+v])))}:void 0,m=new x,d={vertexCount:n,normals:s?Mo(s,c):null,cornerNormal:e.cornerNormal,orco:e.orco,co:h=>m.set(e.co[h*3],e.co[h*3+1],e.co[h*3+2]).clone(),starts:e.faceStart,cornerVerts:e.corner,smooth:h=>e.smooth[h]===1,material:h=>e.material[h],edges:u,sharp:_,uv:i?h=>[i[h*2],i[h*2+1]]:null,uvLayers:o.map(h=>({name:h.name,read:g=>[Number(h.data[g*2]),Number(h.data[g*2+1])]})),attributeLayers:ve(e.attributes,h=>h)};return{...Po(d),hash:t}}function fr(e){const t=e.v.map(s=>new x(...s)),n=s=>{const c=t[s];if(!c)throw new Error(`Runtime mesh vertex ${s} is missing`);return c},o=new Uint32Array(e.f.length+1);e.f.forEach((s,c)=>{if(s.length<3||new Set(s).size!==s.length)throw new Error("Runtime mesh face needs at least three distinct vertices");o[c+1]=o[c]+s.length});const r=new Uint32Array(o[e.f.length]);e.f.forEach((s,c)=>s.forEach((m,d)=>{n(m),r[o[c]+d]=m}));for(const[s,c]of e.edge_order??e.e??[])n(s),n(c);const a={POINT:t.length,EDGE:(e.edge_order??e.e??[]).length,FACE:e.f.length,CORNER:r.length};for(const s of e.attributes??[])if(s.domain!=="EDGE"&&s.data.length!==a[s.domain])throw new Error(`Runtime attribute ${s.name} has ${s.data.length} values for ${a[s.domain]} ${s.domain} elements`);const i=(e.attributes??[]).filter(s=>s.type==="FLOAT2"&&s.domain==="CORNER"),f=e.render_uv??e.active_uv??i[0]?.name,u=i.find(s=>s.name===f);if(f&&!u)throw new Error(`Runtime UV map ${f} is missing`);const _=u?.data,l={vertexCount:t.length,normals:Mo(e,e.attributes?.find(s=>s.name==="custom_normal")),co:n,starts:o,cornerVerts:r,smooth:s=>!!e.s?.[s],material:s=>e.m?.[s]??0,edges:e.edge_order??e.e??null,sharp:e.sharp??[],uv:_?s=>_[s]:null,uvLayers:i.map(s=>({name:s.name,read:c=>s.data[c]})),attributeLayers:ve(e.attributes??[],s=>Array.from(s).flat())};return Nn(Po(l))}const xn=1.5707963267948966,Ht=6.283185307179586,Eo=.3183098861837067,No=.0795774715459476,cr=.3,ur=No,mr=3/16*Eo,le=.8,$e=le*le,Gt=6371,Ro=100,fe=Gt+Ro,Le=64,Ve=64,ut=256,jt=64,_r=[1.679,1.828,1.986,1.307],dr=[.006605,.01067,.01842,.03156],hr=[3472e-28,3914e-28,1349e-28,1103e-29],pr=334.5,gr=[28722e-28,46168e-28,79706e-28,13578e-27],vr=[15908e-26,17711e-26,20942e-26,24033e-26],je=13681e16,xr=2e6,br=.73,Gn=[[53.38691773856467,22.981337506691023,0],[43.90484446636936,71.3477957000534,.10250686796574131],[1.6137278251608962,18.422960591455485,31.742921188390806],[20.762668673810577,2.361421352331437,110.4800964325214]],Pt=[[3.2409698963165283,-1.5373831987380981,-.49861079454421997],[-.969243586063385,1.8759675025939941,.041555099189281464],[.05563009902834892,-.20397700369358063,1.056971549987793]],Dn=e=>e*e,hn=e=>e<0?0:e>1?1:e,Nt=(e,t,n)=>e+n*(t-e),yr=e=>Math.sqrt(Math.max(e,0)),Io=e=>[-Math.sqrt(1-e*e),0,e];function ce(e,t,n,o,r,a,i){const f=e*o+t*r+n*a,u=e*e+t*t+n*n-i*i;if(u>0&&f>0)return-1;const _=f*f-u;return _<0?-1:_>=f*f?-f+Math.sqrt(_):-f-Math.sqrt(_)}const wr=e=>mr*(1+Dn(e));function Or(e){const t=1+$e+2*le*e;return No*(1-$e)/(t*Math.sqrt(t))}const Ar=e=>je*(Math.exp(-e/br)+xr/je);function xe(e,t){let n=e%Ht;Math.abs(n)>=Math.PI&&(n-=Math.sign(n)*2*Math.PI);let o=t;return(n>=xn||n<=-xn)&&(n=Math.sign(n)*Math.PI-n,o+=Math.PI),o=o%Ht,o<0&&(o+=Ht),o=Ht-o,[n,o]}class Tr{constructor(t,n,o){this.air=t,this.aerosol=n,this.ozone=o,this.lut=new Float32Array(jt*ut*4)}coefficients(t,n){const o=Ar(t)*this.aerosol,r=Math.log(Math.max(t,1e-4)),a=378547397e12*Math.exp(-Dn(r-3.22261)*5.55555555-r),i=Math.exp(-.07771971*t**1.16364243);for(let f=0;f<4;f++)n[f]=gr[f]*o,n[4+f]=vr[f]*o,n[8+f]=hr[f]*pr*a*this.ozone,n[12+f]=dr[f]*i*this.air}transmittance(t,n,o){const[r,a,i]=Io(t),f=Nt(Gt,fe,n),_=ce(0,0,f,r,a,i,fe)/Le,l=[0,0,0,0],s=new Float64Array(16);for(let c=0;c<Le;c++){const m=(c+.5)*_,d=r*m,h=a*m,g=f+i*m,p=Math.max(Math.hypot(d,h,g)-Gt,0);this.coefficients(p,s);for(let v=0;v<4;v++)l[v]+=(s[v]+s[4+v]+s[8+v]+s[12+v])*_}for(let c=0;c<4;c++)o[c]=Math.exp(-l[c])}precompute(){const t=new Float64Array(4);for(let n=0;n<jt;n++)for(let o=0;o<ut;o++){const r=o/(ut-1),a=n/(jt-1);this.transmittance(r*2-1,a,t);const i=(n*ut+o)*4;for(let f=0;f<4;f++)this.lut[i+f]=t[f]}}lookup(t,n,o){const r=(ut-1)*hn(t*.5+.5),a=(jt-1)*hn(n),i=Math.trunc(r),f=Math.trunc(a),u=Math.min(i+1,ut-1),_=Math.min(f+1,jt-1),l=r-i,s=a-f,c=(f*ut+i)*4,m=(f*ut+u)*4,d=(_*ut+i)*4,h=(_*ut+u)*4;for(let g=0;g<4;g++)o[g]=Nt(Nt(this.lut[c+g],this.lut[m+g],l),Nt(this.lut[d+g],this.lut[h+g],l),s)}lookupAtGround(t,n){const o=(ut-1)*hn(t*.5+.5),r=Math.trunc(o),a=Math.min(r+1,ut-1),i=o-r;for(let f=0;f<4;f++)n[f]=Nt(this.lut[r*4+f],this.lut[a*4+f],i)}lookupToSun(t,n){const o=(jt-1)*hn(t),r=Math.trunc(o),a=Math.min(r+1,jt-1),i=o-r,f=ut-1;for(let u=0;u<4;u++)n[u]=Nt(this.lut[(r*ut+f)*4+u],this.lut[(a*ut+f)*4+u],i)}inscattering(t,n,o,r,a,i,f,u,_){const l=-(a*t[0]+i*t[1]+f*t[2]),s=wr(l),c=Or(l),m=u/Ve,d=new Float64Array(16),h=new Float64Array(4),g=new Float64Array(4),p=new Float64Array(4),v=new Float64Array(4),O=new Float64Array(4),b=[0,0,0,0],P=[1,1,1,1];for(let T=0;T<Ve;T++){const M=(T+.5)*m,A=n+a*M,w=o+i*M,E=r+f*M,D=Math.hypot(A,w,E),W=Math.max(D-Gt,0),V=W/Ro,G=(A*t[0]+w*t[1]+E*t[2])/D;this.coefficients(W,d),this.lookup(G,V,h);const nt=Ht*(1-yr(1-Dn(Gt/D)));this.lookupAtGround(G,p),this.lookupToSun(0,v),this.lookupToSun(V,O);const y=1/(1+5*Math.exp(-17.92*G)),j=[.217,.347,.594,1];for(let k=0;k<4;k++){const q=v[k]/O[k],X=ur*nt*(cr*Eo)*p[k]*q*G;g[k]=.02*j[k]*y+X}for(let k=0;k<4;k++){const q=d[k]+d[4+k]+d[8+k]+d[12+k],X=_r[k]*(d[12+k]*(s*h[k]+g[k])+d[4+k]*(c*h[k]+g[k])),z=Math.exp(-m*q),S=Math.max(q,1e-7);b[k]+=P[k]*((X-X*z)/S),P[k]*=z}}for(let T=0;T<4;T++)_[T]=b[T]}}const pt=512,tn=256;function zo(e,t){const n=new Tr(e.airDensity,e.aerosolDensity,e.ozoneDensity);n.precompute();const o=Math.min(Math.max(e.altitude,1),99999)/1e3,r=Io(Math.cos(xn-t)),a=new Float32Array(pt*tn*3),i=pt/2,f=new Float64Array(4);for(let u=0;u<tn;u++)for(let _=0;_<i;_++){const l=(_+.5)/pt,s=(u+.5)/tn,c=Ht*l,m=s*2-1,d=Math.sign(m)*Dn(m)*xn,h=Math.cos(d)*Math.cos(c),g=Math.cos(d)*Math.sin(c),p=Math.sin(d),v=Gt+o,O=ce(0,0,v,h,g,p,fe),b=ce(0,0,v,h,g,p,Gt),P=b<0?O:b;n.inscattering(r,0,0,v,h,g,p,P,f);let T=0,M=0,A=0;for(let D=0;D<4;D++)T+=Gn[D][0]*f[D],M+=Gn[D][1]*f[D],A+=Gn[D][2]*f[D];const w=(u*pt+_)*3;a[w]=T,a[w+1]=M,a[w+2]=A;const E=(u*pt+(pt-_-1))*3;a[E]=T,a[E+1]=M,a[E+2]=A}return a}function Sr(e){const[t]=xe(e.sunElevation,e.sunRotation);return zo(e,t)}function be(e){const[t]=xe(e.sunElevation,e.sunRotation);return JSON.stringify([t,e.altitude,e.airDensity,e.aerosolDensity,e.ozoneDensity])}const Mr=6,Kt=new Map;function Pr(e){return Kt.has(be(e))}function Fo(e,t){Kt.set(be(e),t),Kt.size>Mr&&Kt.delete(Kt.keys().next().value)}function Er(e){const[t,n]=xe(e.sunElevation,e.sunRotation),o=be(e);let r=Kt.get(o);r===void 0&&(r=zo(e,t),Fo(e,r));const a=new x;return i=>{const f=Math.hypot(i.x,i.y),u=Math.atan2(i.z,f);let l=(Math.atan2(i.x,i.y)+Math.PI+n)/Ht;l-=Math.floor(l);const s=Math.abs(u),c=hn(Math.sqrt(s/xn)*Math.sign(u)*.5+.5),m=l*pt-.5,d=c*tn-.5,h=Math.floor(m),g=Math.floor(d),p=m-h,v=d-g,O=E=>(E%pt+pt)%pt,b=E=>E<0?0:E>tn-1?tn-1:E,P=O(h),T=O(h+1),M=b(g),A=b(g+1),w=[0,0,0];for(let E=0;E<3;E++){const D=Nt(r[(M*pt+P)*3+E],r[(M*pt+T)*3+E],p),W=Nt(r[(A*pt+P)*3+E],r[(A*pt+T)*3+E],p);w[E]=Nt(D,W,v)}return a.set(Pt[0][0]*w[0]+Pt[0][1]*w[1]+Pt[0][2]*w[2],Pt[1][0]*w[0]+Pt[1][1]*w[1]+Pt[1][2]*w[2],Pt[2][0]*w[0]+Pt[2][1]*w[1]+Pt[2][2]*w[2])}}let zt=null,yn=!1,Nr=0;const pn=new Map;function Rr(){if(zt||yn)return zt;if(typeof Worker>"u")return yn=!0,null;try{zt=new Worker(new URL("/assets/sky-precompute-worker-ChN7J87v.js",import.meta.url),{type:"module"})}catch{return yn=!0,null}return zt.onmessage=e=>{const{id:t,pixels:n,error:o}=e.data,r=pn.get(t);r&&(pn.delete(t),n?r.resolve(n):r.reject(new Error(o??"sky worker returned nothing")))},zt.onerror=e=>{const t=new Error(`sky worker failed: ${e.message||"unknown error"}`);for(const n of pn.values())n.reject(t);pn.clear(),zt?.terminate(),zt=null,yn=!0},zt}function Ir(e){const t=Rr();if(!t)return Promise.resolve(Sr(e));const n=Nr++,o={id:n,parameters:e};return new Promise((r,a)=>{pn.set(n,{resolve:r,reject:a}),t.postMessage(o)})}function zr(e,t,n,o={}){switch(o.type??"LINEAR"){case"QUADRATIC":{const r=Math.max(e,0);return r*r}case"EASING":{const r=Math.min(1,Math.max(0,e));return r*r*(3-2*r)}case"DIAGONAL":return(e+t)/2;case"SPHERICAL":return Math.max(.999999-Math.hypot(e,t,n),0);case"QUADRATIC_SPHERE":{const r=Math.max(.999999-Math.hypot(e,t,n),0);return r*r}case"RADIAL":return Math.atan2(t,e)/(2*Math.PI)+.5;default:return e}}const Xn=(e,t)=>t!==0?e/t:0,Be=e=>Math.min(1,Math.max(-1,e)),Ue=(e,t,n)=>{const o=n!==0?Math.max(n-Math.abs(e-t),0)/n:0;return Math.min(e,t)-o*o*o*n/6},Do={ADD:(e,t)=>e+t,SUBTRACT:(e,t)=>e-t,MULTIPLY:(e,t)=>e*t,DIVIDE:Xn,POWER:(e,t)=>t===0?1:e===0||e<0&&!Number.isInteger(t)?0:e**t,LOGARITHM:(e,t)=>e<=0||t<=0?0:Xn(Math.log(e),Math.log(t)),SQRT:e=>Math.sqrt(Math.max(e,0)),INVERSE_SQRT:e=>e>0?1/Math.sqrt(e):0,ABSOLUTE:Math.abs,RADIANS:e=>e*Math.PI/180,DEGREES:e=>e*180/Math.PI,MINIMUM:(e,t)=>Math.min(e,t),MAXIMUM:(e,t)=>Math.max(e,t),LESS_THAN:(e,t)=>+(e<t),GREATER_THAN:(e,t)=>+(e>t),ROUND:e=>Math.floor(e+.5),FLOOR:Math.floor,CEIL:Math.ceil,FRACT:e=>e-Math.floor(e),MODULO:(e,t)=>t!==0?e%t:0,FLOORED_MODULO:(e,t)=>t!==0?e-Math.floor(e/t)*t:0,TRUNC:Math.trunc,SNAP:(e,t)=>Math.floor(Xn(e,t))*t,WRAP:(e,t,n)=>t!==n?e-(t-n)*Math.floor((e-n)/(t-n)):n,PINGPONG:(e,t)=>{if(t===0)return 0;const n=(e-t)/(t*2);return Math.abs((n-Math.floor(n))*t*2-t)},SINE:Math.sin,COSINE:Math.cos,TANGENT:Math.tan,SINH:Math.sinh,COSH:Math.cosh,TANH:Math.tanh,ARCSINE:e=>Math.asin(Be(e)),ARCCOSINE:e=>Math.acos(Be(e)),ARCTANGENT:Math.atan,ARCTAN2:(e,t)=>e===0&&t===0?0:Math.atan2(e,t),SIGN:Math.sign,EXPONENT:Math.exp,COMPARE:(e,t,n)=>+(e===t||Math.abs(e-t)<=Math.max(n,2**-23)),MULTIPLY_ADD:(e,t,n)=>e*t+n,SMOOTH_MIN:Ue,SMOOTH_MAX:(e,t,n)=>-Ue(-e,-t,n)};function it(e,t){if(typeof e=="number")return()=>e;if(Array.isArray(e)){const r=new x(...e);return()=>r}if(e.kind==="direction")return r=>r;if(e.kind==="window"){if(!t)throw new Error("World Window coordinates need a render camera");return t}if(e.kind==="gradient"){const r=it(e.vector,t),a={type:e.gradient_type},i=new x;return f=>{const u=r(f),_=typeof u=="number"?u:u.x,l=typeof u=="number"?u:u.y,s=typeof u=="number"?u:u.z,c=bt.clamp(zr(_,l,s,a),0,1);return e.output==="Fac"?c:i.setScalar(c)}}if(e.kind==="to_float"){const r=it(e.value,t);return a=>{const i=r(a);return typeof i=="number"?i:Math.fround(e.source_type==="RGBA"?i.x*.212639+i.y*.7151687+i.z*.0721923:(i.x+i.y+i.z)/3)}}if(e.kind==="math"){const r=e.inputs.map(f=>it(f,t)),a=Do[e.operation],i=(f,u)=>{const _=r[f]?.(u)??0;if(typeof _!="number")throw new Error("World Math needs scalar inputs");return Math.fround(_)};return f=>{const u=Math.fround(a(i(0,f),i(1,f),i(2,f)));return e.clamp?bt.clamp(u,0,1):u}}if(e.kind==="mix_color"){const r=it(e.factor,t),a=it(e.a,t),i=it(e.b,t),f=new x,u=new x;return _=>{const l=r(_);if(typeof l!="number")throw new Error("World color Mix needs a scalar factor");const s=a(_);typeof s=="number"?f.setScalar(s):f.copy(s);const c=i(_);return typeof c=="number"?u.setScalar(c):u.copy(c),f.lerp(u,e.clamp_factor?bt.clamp(l,0,1):l),e.clamp_result&&f.clampScalar(0,1),f}}if(e.kind==="sky"){const r=Er({sunElevation:e.sun_elevation,sunRotation:e.sun_rotation,altitude:e.altitude,airDensity:e.air_density,aerosolDensity:e.aerosol_density,ozoneDensity:e.ozone_density});return a=>r(a)}if(e.kind==="mapping"){const r=it(e.vector,t),a=new x(...e.location),i=new x(...e.scale),f=new At().setFromEuler(new Jo(e.rotation[0],e.rotation[1],e.rotation[2],"ZYX")),u=f.clone().invert(),_=new x(...e.scale.map(s=>s===0?0:1/s)),l=new x;return s=>{const c=r(s);switch(typeof c=="number"?l.setScalar(c):l.copy(c),e.vector_type??"POINT"){case"TEXTURE":return l.sub(a).applyQuaternion(u).multiply(_);case"VECTOR":return l.multiply(i).applyQuaternion(f);case"NORMAL":return l.multiply(_).applyQuaternion(f).normalize();case"POINT":return l.multiply(i).applyQuaternion(f).add(a)}}}if(e.kind==="map_range"){const r=it(e.value,t),a=it(e.from_min,t),i=it(e.from_max,t),f=it(e.to_min,t),u=it(e.to_max,t),_=it(e.steps,t),l=(m,d)=>{const h=m(d);if(typeof h!="number")throw new Error("World Map Range needs scalar inputs");return h},s=e.interpolation,c=e.clamp;return m=>{const d=l(r,m),h=l(a,m),g=l(i,m),p=l(f,m),v=l(u,m);if(h===g)return 0;let O;if(s==="STEPPED"){const P=l(_,m),T=(d-h)/(g-h);O=P>0?Math.floor(T*(P+1))/P:0}else if(s==="SMOOTHSTEP"||s==="SMOOTHERSTEP"){const P=bt.clamp((d-Math.min(h,g))/(Math.max(h,g)-Math.min(h,g)),0,1),T=s==="SMOOTHSTEP"?P*P*(3-2*P):P*P*P*(P*(P*6-15)+10);O=h>g?1-T:T}else O=(d-h)/(g-h);const b=p+O*(v-p);return c?p>v?bt.clamp(b,v,p):bt.clamp(b,p,v):b}}if(e.kind==="separate"){const r=it(e.vector,t);return a=>{const i=r(a);return typeof i=="number"?i:i.getComponent(e.axis)}}const n=it(e.factor,t),o=new x;return r=>{const a=n(r);if(typeof a!="number")throw new Error("World ColorRamp needs a scalar factor");const i=bt.clamp(a,0,1)*256,f=Math.floor(i),u=e.colors[f],_=e.colors[Math.min(f+1,256)],l=e.interpolate?i-f:0;return o.set(bt.lerp(u[0],_[0],l),bt.lerp(u[1],_[1],l),bt.lerp(u[2],_[2],l))}}function Fr(e,t,n,o){const r=new Float32Array(t*n*3),a=it(e,o),i=new x;for(let f=0;f<n;f++){const u=((f+.5)/n-.5)*Math.PI;for(let _=0;_<t;_++){const l=((_+.5)/t-.5)*2*Math.PI;i.set(Math.cos(u)*Math.cos(l),-Math.cos(u)*Math.sin(l),Math.sin(u));const s=a(i),c=(f*t+_)*3;r[c]=typeof s=="number"?s:s.x,r[c+1]=typeof s=="number"?s:s.y,r[c+2]=typeof s=="number"?s:s.z}}return r}function We(e){const t=[],n=o=>{if(!(typeof o=="number"||Array.isArray(o)))switch(o.kind){case"sky":t.push({sunElevation:o.sun_elevation,sunRotation:o.sun_rotation,altitude:o.altitude,airDensity:o.air_density,aerosolDensity:o.aerosol_density,ozoneDensity:o.ozone_density});return;case"mapping":case"gradient":case"separate":n(o.vector);return;case"ramp":n(o.factor);return;case"mix_color":n(o.factor),n(o.a),n(o.b);return;case"math":o.inputs.forEach(n);return;case"to_float":n(o.value);return;case"map_range":n(o.value),n(o.from_min),n(o.from_max),n(o.to_min),n(o.to_max),n(o.steps);return;default:return}};return n(e),t}function Ct(e){if(typeof e=="number"||Array.isArray(e))return!1;switch(e.kind){case"window":return!0;case"mapping":case"gradient":case"separate":return Ct(e.vector);case"ramp":return Ct(e.factor);case"mix_color":return[e.factor,e.a,e.b].some(Ct);case"math":return e.inputs.some(Ct);case"to_float":return Ct(e.value);case"map_range":return[e.value,e.from_min,e.from_max,e.to_min,e.to_max,e.steps].some(Ct);default:return!1}}function Dr(e,t,n,o){o.updateMatrixWorld();const r=new Float32Array(t*n*3),a=new x,i=it(e,()=>a),f=new x,u=o.getWorldPosition(new x),_=o.getWorldDirection(new x);for(let l=0;l<n;l++)for(let s=0;s<t;s++){const c=(s+.5)/t,m=(l+.5)/n;a.set(c,m,0),o.isOrthographicCamera?f.copy(_):f.set(c*2-1,m*2-1,.5).unproject(o).sub(u).normalize(),f.set(f.x,-f.z,f.y);const d=i(f),h=(l*t+s)*3;r[h]=typeof d=="number"?d:d.x,r[h+1]=typeof d=="number"?d:d.y,r[h+2]=typeof d=="number"?d:d.z}return r}const at=R().finite(),Cr=N({type:K(["POINT","SUN","SPOT","AREA"]),color:U([at,at,at]),energy:at,use_shadow:et().default(!0),radius:at.optional(),spot_size:at.optional(),spot_blend:at.optional(),shape:K(["SQUARE","RECTANGLE","DISK","ELLIPSE"]).optional(),size:at.optional(),size_y:at.optional()}).strict();let ue;function kr(){return ue??=za(async()=>{const{RectAreaLightUniformsLib:e}=await import("./RectAreaLightUniformsLib-DpPyArRG.js");return{RectAreaLightUniformsLib:e}},__vite__mapDeps([0,1,2])).then(({RectAreaLightUniformsLib:e})=>{e.init(),ht()}),ue}function $r(){return ue??Promise.resolve()}const Lr=e=>{const t=e.size??0,n=e.size_y??t;if(e.shape==="RECTANGLE")return[t,n];if(e.shape==="DISK"){const o=Math.sqrt(Math.PI*t*t/4);return[o,o]}if(e.shape==="ELLIPSE"){const o=Math.sqrt(Math.PI/4);return[t*o,n*o]}return[t,t]};function Vr(e,t){const n=(i,f)=>t&&f(t)?t:new i;if(e.type==="SUN"){const i=n(po,f=>f.isDirectionalLight);return i.intensity=e.energy,i.color.setRGB(e.color[0],e.color[1],e.color[2],vt),i.castShadow=e.use_shadow,i}if(e.type==="POINT"){const i=n(ee,f=>f.isPointLight);return i.intensity=e.energy/(4*Math.PI),i.distance=0,i.decay=2,i.color.setRGB(e.color[0],e.color[1],e.color[2],vt),i.castShadow=e.use_shadow,i}if(e.type==="SPOT"){const i=n(oe,f=>f.isSpotLight);return i.intensity=e.energy/(4*Math.PI),i.distance=0,i.decay=2,i.angle=(e.spot_size??0)/2,i.penumbra=e.spot_blend??0,i.color.setRGB(e.color[0],e.color[1],e.color[2],vt),i.castShadow=e.use_shadow,i}kr();const o=n(En,i=>i.isRectAreaLight),[r,a]=Lr(e);return o.width=r,o.height=a,o.intensity=e.energy/(Math.max(r*a,Number.MIN_VALUE)*Math.PI),o.color.setRGB(e.color[0],e.color[1],e.color[2],vt),o}function jr(e,t,n){if(!e.castShadow||n<=0)return;const r=e.getWorldPosition(new x).distanceTo(t),a=e.shadow;if(!a)return;const i=a.camera;i.near=Math.max(n*.001,r-n),i.far=r+n,e.isDirectionalLight&&(i.left=-n,i.right=n,i.top=n,i.bottom=-n),i.updateProjectionMatrix()}function Br(e,t){e.position.set(0,0,0);const n=e;e.isRectAreaLight||n.target&&n.target.parent!==t&&(n.target.position.set(0,0,-1),t.add(n.target))}const ye=[{direction:[-.352546,.170931,-.920051],diffuse:[.033103,.033103,.033103],specular:[.266761,.266761,.266761],smooth:.52662},{direction:[-.408163,.346939,.844415],diffuse:[.521083,.538226,.538226],specular:[.59903,.59903,.59903],smooth:0},{direction:[.521739,.826087,.212999],diffuse:[.038403,.034357,.04953],specular:[.106102,.125981,.158523],smooth:.478261},{direction:[.624519,-.562067,-.542269],diffuse:[.090838,.08208,.072255],specular:[.106535,.084771,.06608],smooth:.2}],qe=.69;class Ur{constructor(){this.group=new lt,this.lights=[],this.group.name="BlenderSolidStudio";const t=new ho;t.name="BlenderSolidStudioTarget",this.group.add(t);const n=new Ot(0,0,0);for(const[r,a]of ye.entries()){const i=(1+a.smooth)**2,f=new po(16777215,Math.PI*qe/i);f.name=`BlenderSolidLight${r}`,f.color.setRGB(a.diffuse[0],a.diffuse[1],a.diffuse[2],vt),f.position.set(a.direction[0],a.direction[1],a.direction[2]),f.target=t,this.group.add(f),this.lights.push(f),n.r+=a.diffuse[0]*a.smooth/i,n.g+=a.diffuse[1]*a.smooth/i,n.b+=a.diffuse[2]*a.smooth/i}const o=new ta(16777215,Math.PI*qe);o.name="BlenderSolidWrapFill",o.color.copy(n),this.group.add(o),this.lights.push(o)}setRendered(t){this.group.visible=!t}dispose(){for(const t of this.lights)t.dispose();this.group.clear()}}const Qt=U([at,at,at]),J=To(()=>Vt([at,Qt,N({kind:Z("direction")}).strict(),N({kind:Z("window")}).strict(),N({kind:Z("gradient"),gradient_type:K(["LINEAR","QUADRATIC","EASING","DIAGONAL","SPHERICAL","QUADRATIC_SPHERE","RADIAL"]),output:K(["Fac","Color"]),vector:J}).strict(),N({kind:Z("to_float"),source_type:K(["RGBA","VECTOR"]),value:J}).strict(),N({kind:Z("math"),operation:K(Object.keys(Do)),clamp:et(),inputs:$(J).min(1).max(3)}).strict(),N({kind:Z("mix_color"),factor:J,a:J,b:J,clamp_factor:et(),clamp_result:et()}).strict(),N({kind:Z("mapping"),vector_type:K(["POINT","TEXTURE","VECTOR","NORMAL"]).optional(),vector:J,location:Qt,rotation:Qt,scale:Qt}).strict(),N({kind:Z("separate"),vector:J,axis:R().int().min(0).max(2)}).strict(),N({kind:Z("ramp"),factor:J,colors:$(Qt).length(257),interpolate:et()}).strict(),N({kind:Z("map_range"),interpolation:K(["LINEAR","STEPPED","SMOOTHSTEP","SMOOTHERSTEP"]),clamp:et(),value:J,from_min:J,from_max:J,to_min:J,to_max:J,steps:J}).strict(),N({kind:Z("sky"),sun_elevation:at,sun_rotation:at,altitude:at,air_density:at,aerosol_density:at,ozone_density:at}).strict()])),He=N({color:Qt,strength:at,shader:J.optional()}),Wr=He.extend({volume:$(N({kind:K(["absorption","scatter","principled","emission"]),phase:I(),alpha:J,weight:J,color:J,density:J,anisotropy:J,absorption_color:J,emission_color:J,emission_strength:J,blackbody_intensity:J,temperature:J,blackbody_tint:J}).strict()).optional(),lighting:He.strict().optional()}).strict(),qr=4,mn=new Map,Yn=new Set;function Ge(e,t,n){const a=Ct(e);if(a&&!n)throw new Error("World Window coordinates need a render camera");n?.updateMatrixWorld();const i=JSON.stringify([e,a?[n.matrixWorld.elements,n.projectionMatrix.elements]:null]),f=mn.get(i);if(f!==void 0)return me(f,t,256,128);const u=new x,_=new kn,l=n?new H().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse):null,s=n?.getWorldPosition(new x),m=Fr(e,256,128,a?d=>(u.set(d.x,d.z,-d.y),n.isPerspectiveCamera&&u.add(s),_.set(u.x,u.y,u.z,1).applyMatrix4(l),_.w===0?u.set(0,0,0):u.set(_.x/_.w*.5+.5,_.y/_.w*.5+.5,0)):void 0);return mn.set(i,m),mn.size>qr&&mn.delete(mn.keys().next().value),me(m,t,256,128)}function Hr(e,t,n,o){const r=dn.toHalfFloat(1);for(let a=0;a<o;a++)e[a*4]=dn.toHalfFloat(t[a*3]*n),e[a*4+1]=dn.toHalfFloat(t[a*3+1]*n),e[a*4+2]=dn.toHalfFloat(t[a*3+2]*n),e[a*4+3]=r}function me(e,t,n,o){const r=new Uint16Array(n*o*4);Hr(r,e,t,n*o);const a=new $n(r,n,o,Ln,ge);return a.mapping=ea,a.colorSpace=vt,a.minFilter=Yt,a.magFilter=Yt,a.needsUpdate=!0,a}class we{constructor(){this.pending=null,this.texture=null,this.environmentTexture=null,this.screenTexture=null,this.applied=null,this.generation=0}async ready(){await this.pending}static sceneOf(t){let n=t;for(;n;){if(n.isScene)return n;n=n.parent}return null}apply(t,n,o){if(this.clear(),this.pending=null,!n)return;const r=we.sceneOf(t);if(!r)return;this.applied={scene:r,background:r.background,environment:r.environment};const a=n.shader??n.color,i=this.generation,u=[...We(a),...n.lighting?We(n.lighting.shader??n.lighting.color):[]].filter(l=>!Pr(l));if(u.length===0){this.compose(r,n,a,o);return}const _=(async()=>{const l=await Promise.all(u.map(Ir));u.forEach((s,c)=>{Fo(s,l[c])}),!(this.generation!==i||this.applied?.scene!==r)&&(this.compose(r,n,a,o),ht())})();this.pending=_,Yn.add(_),_.then(()=>Yn.delete(_),()=>Yn.delete(_))}compose(t,n,o,r){if(this.texture=Ge(o,n.strength,r),Ct(o)){if(!r)throw new Error("World Window coordinates need a render camera");this.screenTexture=me(Dr(o,512,512,r),n.strength,512,512),this.screenTexture.mapping=na,t.background=this.screenTexture}else if(r&&r.isOrthographicCamera){const i=r.getWorldDirection(new x);i.set(i.x,-i.z,i.y);const f=it(n.shader??n.color)(i);t.background=typeof f=="number"?new Ot().setRGB(f,f,f).multiplyScalar(n.strength):new Ot().setRGB(f.x,f.y,f.z).multiplyScalar(n.strength)}else t.background=this.texture;const{lighting:a}=n;this.environmentTexture=a?Ge(a.shader??a.color,a.strength,r):null,t.environment=this.environmentTexture??this.texture}clear(){this.generation++,this.applied&&(this.applied.scene.background=this.applied.background,this.applied.scene.environment=this.applied.environment,this.applied=null,this.texture?.dispose(),this.texture=null,this.environmentTexture?.dispose(),this.environmentTexture=null,this.screenTexture?.dispose(),this.screenTexture=null)}dispose(){this.clear()}}function Co(e){return[e.min.x,e.max.x].flatMap(t=>[e.min.y,e.max.y].flatMap(n=>[e.min.z,e.max.z].map(o=>new x(t,n,o))))}function Gr(e,t){if(e.isEmpty()||!t.intersectsBox(e))return[];const n=Co(e);if(n.every(l=>t.containsPoint(l)))return n;const o=[...t.planes,new Ut(new x(1,0,0),-e.min.x),new Ut(new x(-1,0,0),e.max.x),new Ut(new x(0,1,0),-e.min.y),new Ut(new x(0,-1,0),e.max.y),new Ut(new x(0,0,1),-e.min.z),new Ut(new x(0,0,-1),e.max.z)],r=[],a=new x,i=new x,f=new x,u=new x,_=Math.max(1,e.min.length(),e.max.length())*1e-8;for(let l=0;l<o.length;l++)for(let s=l+1;s<o.length;s++)for(let c=s+1;c<o.length;c++){const m=o[l],d=o[s],h=o[c];a.crossVectors(d.normal,h.normal);const g=m.normal.dot(a);Math.abs(g)<1e-12||(i.crossVectors(h.normal,m.normal),f.crossVectors(m.normal,d.normal),u.copy(a).multiplyScalar(-m.constant).addScaledVector(i,-d.constant).addScaledVector(f,-h.constant).divideScalar(g),o.every(p=>p.distanceToPoint(u)>=-_)&&r.push(u.clone()))}return r}function Xr(e,t,n){if(!e.castShadow||!t.length)return;e.shadow.updateMatrices(e);const o=e.shadow.camera,r=o.matrixWorldInverse,a=new on().setFromPoints(t.map(c=>c.clone().applyMatrix4(r))),i=a.getSize(new x),f=Math.max(i.length()*1e-6,Number.EPSILON),u=2+2*Math.SQRT2,_=Math.max(i.x,i.y,f)/Math.max(1,Math.min(e.shadow.mapSize.x,e.shadow.mapSize.y)-2*u),l=2*Math.SQRT2*_,s=u*_;a.min.x-=s,a.min.y-=s,a.max.x+=s,a.max.y+=s;for(const c of n){if(c.isEmpty())continue;const m=new on().setFromPoints(Co(c).map(d=>d.applyMatrix4(r)));m.max.x<a.min.x||m.min.x>a.max.x||m.max.y<a.min.y||m.min.y>a.max.y||(a.min.z=Math.min(a.min.z,m.min.z),a.max.z=Math.max(a.max.z,m.max.z))}o.left=a.min.x,o.right=a.max.x,o.bottom=a.min.y,o.top=a.max.y,o.near=-a.max.z-l-f,o.far=-a.min.z+l+f,o.updateProjectionMatrix(),e.shadow.normalBias=l}const nn=R().finite(),Xe=U([nn,nn,nn]),ko=N({min:U([R().int(),R().int(),R().int()]),max:U([R().int(),R().int(),R().int()]),density:$(nn),voxelSize:nn.positive(),color:Xe,emission:Xe,densityScale:nn.nonnegative()}).strict();function Yr(e){const t=e.max.map((l,s)=>l-e.min[s]+1);if(t.some(l=>l<=0)||t.reduce((l,s)=>l*s,1)!==e.density.length)throw new Error("Volume density dimensions do not match the evaluated grid");const n=new oa(new Float32Array(e.density),t[0],t[1],t[2]);n.format=aa,n.type=go,n.minFilter=n.magFilter=Yt,n.unpackAlignment=1,n.needsUpdate=!0;const o=new x(...e.min).addScalar(-.5).multiplyScalar(e.voxelSize),r=new x(t[0],t[1],t[2]).multiplyScalar(e.voxelSize),a=new ra(r.x,r.y,r.z),i=a.getAttribute("position");for(let l=0;l<i.count;l++)i.setXYZ(l,o.x+(i.getX(l)>0?r.x:0),o.y+(i.getY(l)>0?r.y:0),o.z+(i.getZ(l)>0?r.z:0));i.needsUpdate=!0,a.computeBoundingBox(),a.computeBoundingSphere();const f=new pe({glslVersion:sa,side:ia,transparent:!0,depthWrite:!1,premultipliedAlpha:!0,uniforms:{densityGrid:{value:n},minimum:{value:o},extent:{value:r},voxelSize:{value:e.voxelSize},densityScale:{value:e.densityScale},volumeColor:{value:new x(...e.color)},emission:{value:new x(...e.emission)},cameraLocal:{value:new x},rayLocal:{value:new x},orthographic:{value:!1},worldScale:{value:new _o}},vertexShader:`
20
20
  out vec3 localPosition;
21
21
  void main() {
22
22
  localPosition = position;
@@ -58,7 +58,7 @@ import{a as so,b as lo,L as fo}from"./LineSegments2-DN9pUfWA.js";import{bh as it
58
58
  outputColor = vec4(radiance, 1.0 - transmission);
59
59
  #include <tonemapping_fragment>
60
60
  #include <colorspace_fragment>
61
- }`}),u=new Rt(a,f),_=new B;return u.onBeforeRender=(l,s,c)=>{_.copy(u.matrixWorld).invert(),f.uniforms.cameraLocal.value.setFromMatrixPosition(c.matrixWorld).applyMatrix4(_),c.getWorldDirection(f.uniforms.rayLocal.value).transformDirection(_),f.uniforms.orthographic.value=!!c.isOrthographicCamera,f.uniforms.worldScale.value.setFromMatrix4(u.matrixWorld)},f.addEventListener("dispose",()=>n.dispose()),u}const Gr=`#define constexpr const
61
+ }`}),u=new Rt(a,f),_=new H;return u.onBeforeRender=(l,s,c)=>{_.copy(u.matrixWorld).invert(),f.uniforms.cameraLocal.value.setFromMatrixPosition(c.matrixWorld).applyMatrix4(_),c.getWorldDirection(f.uniforms.rayLocal.value).transformDirection(_),f.uniforms.orthographic.value=!!c.isOrthographicCamera,f.uniforms.worldScale.value.setFromMatrix4(u.matrixWorld)},f.addEventListener("dispose",()=>n.dispose()),u}const Zr=`#define constexpr const
62
62
  #define bool32_t bool
63
63
  #define bool2 bvec2
64
64
  #define bool3 bvec3
@@ -200,7 +200,7 @@ mat3x3 to_float3x3(mat3x4 m) { return mat3x3(m); }
200
200
  #define float4_from_float(v) float4(float3(v), 1.0f)
201
201
  #define gpu_dfdx(x) dFdx(x)
202
202
  #define gpu_dfdy(x) dFdy(x)
203
- #define gpu_fwidth(x) fwidth(x)`,ue={"gpu_shader_common_math.glsl":{deps:["gpu_shader_math_constants_lib.glsl","gpu_shader_math_base_lib.glsl","gpu_shader_math_safe_lib.glsl"],code:`void math_add(float a, float b, float c, _ref(float ,result))
203
+ #define gpu_fwidth(x) fwidth(x)`,_e={"gpu_shader_common_math.glsl":{deps:["gpu_shader_math_constants_lib.glsl","gpu_shader_math_base_lib.glsl","gpu_shader_math_safe_lib.glsl"],code:`void math_add(float a, float b, float c, _ref(float ,result))
204
204
  {
205
205
  result = a + b;
206
206
  }
@@ -6879,7 +6879,7 @@ void curves_float_mixed(float factor,
6879
6879
  curves_float(
6880
6880
  value, curve_map, layer, range_minimum, range_divider, start_slope, end_slope, result);
6881
6881
  result = mix(value, result, factor);
6882
- }`}},Ge=N().finite(),Yn=H(["float","vec2","vec3","vec4"]),Do=Lt([Ge,D(Ge)]),Co=L([R(),N().int().nonnegative()]),Nn=Lt([M({value:Do}).strict(),M({link:Co}).strict()]),Xr=["ShaderNodeTexCoord","ShaderNodeUVMap","ShaderNodeValue","ShaderNodeRGB","ShaderNodeTexImage","ShaderNodeMapping","ShaderNodeMath","ShaderNodeVectorMath","ShaderNodeMix","ShaderNodeMixRGB","ShaderNodeValToRGB","ShaderNodeInvert","ShaderNodeSeparateXYZ","ShaderNodeCombineXYZ","ShaderNodeTexNoise","ShaderNodeTexVoronoi","ShaderNodeTexChecker","ShaderNodeTexWhiteNoise","ShaderNodeTexWave","ShaderNodeTexGradient","ShaderNodeTexMagic","ShaderNodeTexBrick","ShaderNodeMapRange","ShaderNodeClamp","ShaderNodeHueSaturation","ShaderNodeBrightContrast","ShaderNodeGamma","ShaderNodeRGBToBW","ShaderNodeSeparateColor","ShaderNodeCombineColor","ShaderNodeVectorRotate","ShaderNodeFresnel","ShaderNodeLayerWeight","ShaderNodeBump","ShaderNodeNormalMap","ShaderNodeNewGeometry","ShaderNodeVertexColor","ShaderNodeAttribute","ShaderNodeRGBCurve","ShaderNodeVectorCurve","ShaderNodeFloatCurve"],Yr=M({type:H(Xr),props:yt(R(),Oo()),inputs:D(Lt([M({value:Do,id:R(),gpu:Yn,enabled:Q()}).strict(),M({link:Co,id:R(),gpu:Yn,enabled:Q()}).strict()])),outputs:D(M({id:R(),gpu:Yn.or(q("closure")).nullable()}).strict())}).strict(),hn=wo(()=>Lt([M({principled:q(!0)}).strict(),M({emission:L([Nn,Nn])}).strict(),M({transparent:N()}).strict(),M({none:q(!0)}).strict(),M({mix:L([Nn,hn,hn])}).strict(),M({add:L([hn,hn])}).strict()])),Zr=M({surface:H(["ShaderNodeBsdfPrincipled","ShaderNodeEmission","closure"]),inputs:yt(R(),Nn),closure:hn.optional(),nodes:yt(R(),Yr)}).strict();function Qr(e){const t=e.inputs.Alpha,n=o=>"transparent"in o||"mix"in o&&(n(o.mix[1])||n(o.mix[2]))||"add"in o&&(n(o.add[0])||n(o.add[1]));return t!==void 0&&"link"in t||e.closure!==void 0&&n(e.closure)}const ko="vec3(0.2126729, 0.7151522, 0.0721750)",Kr=e=>e==="float"?1:Number(e[3]);function Jr(e,t){const n=typeof t=="number"?[t]:t,o=Kr(e);return Array.from({length:o},(r,a)=>n[a]??(a===3?1:0))}function ti(e,t,n){if(t===n)return e;const o=a=>a==="float"?"float":`float${a[3]}`,r=t==="vec4"&&n==="float"?`, ${ko}`:"";return`${o(n)}_from_${o(t)}(${e}${r})`}const ni={INVERSE_SQRT:"math_inversesqrt",FRACT:"math_fraction",SMOOTH_MIN:"math_smoothmin",SMOOTH_MAX:"math_smoothmax"},ei={CROSS_PRODUCT:"vector_math_cross",DOT_PRODUCT:"vector_math_dot"},Xe={MIX:"blend",ADD:"add",MULTIPLY:"mult",SUBTRACT:"sub",SCREEN:"screen",DIVIDE:"div_fallback",DIFFERENCE:"diff",EXCLUSION:"exclusion",DARKEN:"dark",LIGHTEN:"light",OVERLAY:"overlay",DODGE:"dodge",BURN:"burn",HUE:"hue",SATURATION:"sat",VALUE:"val",COLOR:"color",SOFT_LIGHT:"soft",LINEAR_LIGHT:"linear"},oi={MULTIFRACTAL:"multi_fractal",FBM:"fbm",HYBRID_MULTIFRACTAL:"hybrid_multi_fractal",RIDGED_MULTIFRACTAL:"ridged_multi_fractal",HETERO_TERRAIN:"hetero_terrain"},ai={F1:"f1",F2:"f2",SMOOTH_F1:"smooth_f1",DISTANCE_TO_EDGE:"distance_to_edge",N_SPHERE_RADIUS:"n_sphere_radius"},ri={EUCLIDEAN:0,MANHATTAN:1,CHEBYCHEV:2,MINKOWSKI:3},ii=(()=>{const e=new Map;for(const[t,n]of Object.entries(ue))for(const o of n.code.matchAll(/^(?:void|float\d?)\s+([A-Za-z_]\w*)\s*\(/gm))e.has(o[1])||e.set(o[1],t);return e})();function C(e,t){if(!(t in e.props))throw new Error(`${e.type} arrived without its '${t}' property`);return e.props[t]}const si=`
6882
+ }`}},Ye=R().finite(),Zn=K(["float","vec2","vec3","vec4"]),$o=Vt([Ye,$(Ye)]),Lo=U([I(),R().int().nonnegative()]),Rn=Vt([N({value:$o}).strict(),N({link:Lo}).strict()]),Qr=["ShaderNodeTexCoord","ShaderNodeUVMap","ShaderNodeValue","ShaderNodeRGB","ShaderNodeTexImage","ShaderNodeMapping","ShaderNodeMath","ShaderNodeVectorMath","ShaderNodeMix","ShaderNodeMixRGB","ShaderNodeValToRGB","ShaderNodeInvert","ShaderNodeSeparateXYZ","ShaderNodeCombineXYZ","ShaderNodeTexNoise","ShaderNodeTexVoronoi","ShaderNodeTexChecker","ShaderNodeTexWhiteNoise","ShaderNodeTexWave","ShaderNodeTexGradient","ShaderNodeTexMagic","ShaderNodeTexBrick","ShaderNodeMapRange","ShaderNodeClamp","ShaderNodeHueSaturation","ShaderNodeBrightContrast","ShaderNodeGamma","ShaderNodeRGBToBW","ShaderNodeSeparateColor","ShaderNodeCombineColor","ShaderNodeVectorRotate","ShaderNodeFresnel","ShaderNodeLayerWeight","ShaderNodeBump","ShaderNodeNormalMap","ShaderNodeNewGeometry","ShaderNodeVertexColor","ShaderNodeAttribute","ShaderNodeRGBCurve","ShaderNodeVectorCurve","ShaderNodeFloatCurve"],Kr=N({type:K(Qr),props:yt(I(),So()),inputs:$(Vt([N({value:$o,id:I(),gpu:Zn,enabled:et()}).strict(),N({link:Lo,id:I(),gpu:Zn,enabled:et()}).strict()])),outputs:$(N({id:I(),gpu:Zn.or(Z("closure")).nullable()}).strict())}).strict(),gn=To(()=>Vt([N({principled:Z(!0)}).strict(),N({emission:U([Rn,Rn])}).strict(),N({transparent:R()}).strict(),N({none:Z(!0)}).strict(),N({mix:U([Rn,gn,gn])}).strict(),N({add:U([gn,gn])}).strict()])),Jr=N({surface:K(["ShaderNodeBsdfPrincipled","ShaderNodeEmission","closure"]),inputs:yt(I(),Rn),closure:gn.optional(),nodes:yt(I(),Kr)}).strict();function ti(e){const t=e.inputs.Alpha,n=o=>"transparent"in o||"mix"in o&&(n(o.mix[1])||n(o.mix[2]))||"add"in o&&(n(o.add[0])||n(o.add[1]));return t!==void 0&&"link"in t||e.closure!==void 0&&n(e.closure)}const Vo="vec3(0.2126729, 0.7151522, 0.0721750)",ni=e=>e==="float"?1:Number(e[3]);function ei(e,t){const n=typeof t=="number"?[t]:t,o=ni(e);return Array.from({length:o},(r,a)=>n[a]??(a===3?1:0))}function oi(e,t,n){if(t===n)return e;const o=a=>a==="float"?"float":`float${a[3]}`,r=t==="vec4"&&n==="float"?`, ${Vo}`:"";return`${o(n)}_from_${o(t)}(${e}${r})`}const ai={INVERSE_SQRT:"math_inversesqrt",FRACT:"math_fraction",SMOOTH_MIN:"math_smoothmin",SMOOTH_MAX:"math_smoothmax"},ri={CROSS_PRODUCT:"vector_math_cross",DOT_PRODUCT:"vector_math_dot"},Ze={MIX:"blend",ADD:"add",MULTIPLY:"mult",SUBTRACT:"sub",SCREEN:"screen",DIVIDE:"div_fallback",DIFFERENCE:"diff",EXCLUSION:"exclusion",DARKEN:"dark",LIGHTEN:"light",OVERLAY:"overlay",DODGE:"dodge",BURN:"burn",HUE:"hue",SATURATION:"sat",VALUE:"val",COLOR:"color",SOFT_LIGHT:"soft",LINEAR_LIGHT:"linear"},ii={MULTIFRACTAL:"multi_fractal",FBM:"fbm",HYBRID_MULTIFRACTAL:"hybrid_multi_fractal",RIDGED_MULTIFRACTAL:"ridged_multi_fractal",HETERO_TERRAIN:"hetero_terrain"},si={F1:"f1",F2:"f2",SMOOTH_F1:"smooth_f1",DISTANCE_TO_EDGE:"distance_to_edge",N_SPHERE_RADIUS:"n_sphere_radius"},li={EUCLIDEAN:0,MANHATTAN:1,CHEBYCHEV:2,MINKOWSKI:3},fi=(()=>{const e=new Map;for(const[t,n]of Object.entries(_e))for(const o of n.code.matchAll(/^(?:void|float\d?)\s+([A-Za-z_]\w*)\s*\(/gm))e.has(o[1])||e.set(o[1],t);return e})();function L(e,t){if(!(t in e.props))throw new Error(`${e.type} arrived without its '${t}' property`);return e.props[t]}const ci=`
6883
6883
  #define GPU_FRAGMENT_SHADER
6884
6884
  #define FrontFacing gl_FrontFacing
6885
6885
  #ifndef USE_TRANSMISSION
@@ -6936,7 +6936,7 @@ void blender_init_globals() {
6936
6936
  g_data.curve_T = vec3(0.0);
6937
6937
  g_data.barycentric_coords = vec2(0.0);
6938
6938
  }
6939
- `,li=`
6939
+ `,ui=`
6940
6940
  uniform vec2 blenderViewport;
6941
6941
  vec3 blender_orco() {
6942
6942
  // attr_load_orco: the orco attribute (\`orcoAttribute\`), interpolated.
@@ -7019,31 +7019,31 @@ vec3 blender_reflection() {
7019
7019
  : normalize(cameraPosition - vBlenderWorldPosition);
7020
7020
  return blender_from_three * -reflect(incident, normalize(vBlenderWorldNormal));
7021
7021
  }
7022
- `;class ye{constructor(t,n,o=!1,r="bgN"){this.graph=t,this.derivative=o,this.prefix=r,this.lines=[],this.emitted=new Map,this.s=n??{files:new Set,uniforms:new Map,uniformTypes:new Map,images:[],ramps:[],uvs:new Set,attributes:new Set,structure:[],functions:[]}}get uniforms(){return this.s.uniforms}get images(){return this.s.images}get ramps(){return this.s.ramps}d(t){return this.derivative?`(${t} + dF_impl(${t}))`:t}uniform(t,n){const o=`bgU${this.s.uniforms.size}`,r=Jr(t,n);return this.s.uniforms.set(o,t==="float"?r[0]:r),this.s.uniformTypes.set(o,t),o}use(t){const n=ii.get(t);if(!n)throw new Error(`Blender's node library has no ${t}`);return this.s.files.add(n),t}source(t,n){if("value"in t)return this.s.structure.push("v"),this.uniform(n,t.value);const[o,r]=t.link,a=this.graph.nodes[o];if(!a)throw new Error(`The graph links to ${o}, which it does not carry`);const f=this.node(o,a)[r];if(!f)throw new Error(`${o} has no output ${r}`);return this.s.structure.push(["l",o,r]),ti(f.name,f.type,n)}input(t,n,o){const r=t.inputs.find(a=>a.id===n)??t.inputs.find(a=>a.id.replace(/_/g," ")===n);if(!r)throw new Error(`${t.type} arrived without its '${n}' input`);return this.source(r,o??r.gpu)}coordinate(t,n){const o=t.inputs[0];return"link"in o?this.source(o,"vec3"):(this.s.structure.push(["default",n]),n==="orco"?this.d("blender_orco()"):(this.s.uvs.add(""),this.d(`vec3(${Kt("")}, 0.0)`)))}node(t,n){const o=this.emitted.get(t);if(o)return o;const r=`${this.prefix}${this.emitted.size}`,a=n.outputs.map((s,c)=>({name:`${r}_${c}`,type:s.gpu==="closure"||s.gpu===null?"float":s.gpu}));this.emitted.set(t,a);const i=s=>`${a[s].type} ${a[s].name} = ${a[s].type}(0.0);`,f=a.map((s,c)=>i(c)).join(" "),u=s=>s.map(c=>a[c].name).join(", "),_=(s=[])=>[...n.inputs.map(m=>this.source(m,m.gpu)),...s,...a.map(m=>m.name)].join(", ");this.s.structure.push(["n",n.type,n.props.operation,n.props.blend_type,n.props.data_type,n.props.factor_mode,n.props.clamp_factor,n.props.clamp_result,n.props.use_clamp,n.props.noise_dimensions,n.props.noise_type,n.props.voronoi_dimensions,n.props.feature,n.props.distance,n.props.vector_type,n.props.uv_map,n.props.extension,n.props.interpolation,n.props.image_alpha_mode,n.props.image_is_data,n.props.color_ramp?.elements?.length,n.props.color_ramp?.interpolation]);const l=[f];switch(n.type){case"ShaderNodeValue":case"ShaderNodeRGB":{const s=a[0].type;l.push(`${a[0].name} = ${this.uniform(s,C(n,"value"))};`);break}case"ShaderNodeTexCoord":{this.s.uvs.add(""),["blender_orco()","blender_object_normal()",`vec3(${Kt("")}, 0.0)`,"vBlenderObjectPosition","blender_camera()","blender_window()","blender_reflection()"].forEach((c,m)=>{a[m]&&l.push(`${a[m].name} = ${this.d(c)};`)});break}case"ShaderNodeVertexColor":case"ShaderNodeAttribute":{const s=C(n,n.type==="ShaderNodeAttribute"?"attribute_name":"layer_name");this.s.attributes.add(s),this.s.structure.push(["a",s]);const c=n.type==="ShaderNodeAttribute"?"node_attribute":"node_vertex_color";l.push(`${this.use(c)}(${me(s)}, ${u(a.map((m,d)=>d))});`);for(const m of a)l.push(`${m.name} = ${this.d(m.name)};`);break}case"ShaderNodeUVMap":{const s=C(n,"uv_map");this.s.uvs.add(s),l.push(`${a[0].name} = ${this.d(`vec3(${Kt(s)}, 0.0)`)};`);break}case"ShaderNodeMath":{const s=C(n,"operation"),c=this.use(ni[s]??`math_${s.toLowerCase()}`);l.push(`${c}(${_()});`),C(n,"use_clamp")&&l.push(`${this.use("clamp_value")}(${u([0])}, 0.0, 1.0, ${u([0])});`);break}case"ShaderNodeVectorMath":{const s=C(n,"operation");l.push(`${this.use(ei[s]??`vector_math_${s.toLowerCase()}`)}(${_()});`);break}case"ShaderNodeMapping":l.push(`${this.use(`mapping_${C(n,"vector_type").toLowerCase()}`)}(${_()});`);break;case"ShaderNodeInvert":l.push(`${this.use("invert")}(${_()});`);break;case"ShaderNodeSeparateXYZ":l.push(`${this.use("separate_xyz")}(${_()});`);break;case"ShaderNodeCombineXYZ":l.push(`${this.use("combine_xyz")}(${_()});`);break;case"ShaderNodeMix":{const s=C(n,"data_type"),c=C(n,"factor_mode")==="NON_UNIFORM",m={FLOAT:"Float",VECTOR:"Vector",RGBA:"Color",ROTATION:"Rotation"}[s];if(!m)throw new Error(`Mix has data type ${s}`);const d=s==="VECTOR"&&c;let h=this.input(n,d?"Factor_Vector":"Factor_Float");if(C(n,"clamp_factor")){const v=`${r}_fac`;l.push(d?`vec3 ${v}; ${this.use("node_mix_clamp_vector")}(${h}, vec3(0.0), vec3(1.0), ${v});`:`float ${v}; ${this.use("node_mix_clamp_value")}(${h}, 0.0, 1.0, ${v});`),h=v}const g=s==="FLOAT"?"node_mix_float":s==="VECTOR"?c?"node_mix_vector_non_uniform":"node_mix_vector":s==="RGBA"?`node_mix_${Xe[C(n,"blend_type")]}`:"node_mix_rotation",p=n.outputs.findIndex(v=>v.id===`Result_${m}`);l.push(`${this.use(g)}(${h}, ${this.input(n,`A_${m}`)}, ${this.input(n,`B_${m}`)}, ${u([p])});`),s==="RGBA"&&C(n,"clamp_result")&&l.push(`${this.use("node_mix_clamp_color")}(${u([p])}, vec4(0.0), vec4(1.0), ${u([p])});`);break}case"ShaderNodeMixRGB":{const s=`${r}_fac`;l.push(`float ${s}; ${this.use("clamp_value")}(${this.input(n,"Fac")}, 0.0, 1.0, ${s});`);const c=n.inputs.slice(1).map(m=>this.source(m,m.gpu));l.push(`${this.use(`mix_${Xe[C(n,"blend_type")]}`)}(${[s,...c,u([0])].join(", ")});`),C(n,"use_clamp")&&l.push(`${this.use("clamp_color")}(${u([0])}, vec4(0.0), vec4(1.0), ${u([0])});`);break}case"ShaderNodeValToRGB":{const s=C(n,"color_ramp"),c=this.input(n,"Fac"),[m,d]=s.elements,h=g=>this.uniform("vec4",g.slice(1,5));if(s.elements.length===1)l.push(`${u([0])} = ${h(m)}; ${u([1])} = ${u([0])}.a;`);else if(s.elements.length===2&&s.color_mode==="RGB"&&d&&s.interpolation!=="B_SPLINE"&&s.interpolation!=="CARDINAL")if(s.interpolation==="CONSTANT")l.push(`${this.use("valtorgb_opti_constant")}(${c}, ${this.uniform("float",Math.max(m[0],d[0]))}, ${h(m)}, ${h(d)}, ${u([0,1])});`);else{const g=1/(d[0]-m[0]),p=s.interpolation==="EASE"?"valtorgb_opti_ease":"valtorgb_opti_linear";l.push(`${this.use(p)}(${c}, ${this.uniform("vec2",[g,-g*m[0]])}, ${h(m)}, ${h(d)}, ${u([0,1])});`)}else{const g=`bgRamp${this.s.ramps.length}`;this.s.ramps.push({uniform:g,table:s.table}),this.s.structure.push(["ramp",s.interpolation==="CONSTANT"]),l.push(s.interpolation==="CONSTANT"?`${u([0])} = texelFetch(${g}, ivec2(int(clamp(${c}, 0.0, 1.0) * 256.0), 0), 0);`:`${u([0])} = texture(${g}, vec2(clamp(${c}, 0.0, 1.0) * (256.0 / 257.0) + 0.5 / 257.0, 0.5));`),l.push(`${u([1])} = ${u([0])}.a;`)}break}case"ShaderNodeRGBCurve":case"ShaderNodeVectorCurve":case"ShaderNodeFloatCurve":{const s=C(n,"curve_mapping"),c=`bgRamp${this.s.ramps.length}`;this.s.ramps.push({uniform:c,table:s.table}),this.s.structure.push(["curve"]);const m=this.input(n,n.inputs.some(d=>d.id==="Factor")?"Factor":"Fac","float");n.type==="ShaderNodeRGBCurve"?l.push(`${this.use("curves_combined_rgb")}(${m}, ${this.input(n,"Color","vec4")}, vec4(0.0, 0.0, 0.0, 1.0), vec4(1.0), ${c}, 0.5, ${this.uniform("vec4",s.minimums)}, ${this.uniform("vec4",s.dividers)}, ${this.uniform("vec4",s.starts)}, ${this.uniform("vec4",s.ends)}, ${u([0])});`):n.type==="ShaderNodeVectorCurve"?l.push(`${this.use("curves_vector_mixed")}(${m}, ${this.input(n,"Vector","vec3")}, ${c}, 0.5, ${this.uniform("vec3",s.minimums.slice(0,3))}, ${this.uniform("vec3",s.dividers.slice(0,3))}, ${this.uniform("vec3",s.starts.slice(0,3))}, ${this.uniform("vec3",s.ends.slice(0,3))}, ${u([0])});`):l.push(`${this.use("curves_float_mixed")}(${m}, ${this.input(n,"Value","float")}, ${c}, 0.5, ${this.uniform("float",s.minimums[0])}, ${this.uniform("float",s.dividers[0])}, ${this.uniform("float",s.starts[0])}, ${this.uniform("float",s.ends[0])}, ${u([0])});`);break}case"ShaderNodeTexNoise":{const s=Number(C(n,"noise_dimensions")[0]),c=this.use(`node_noise_tex_${oi[C(n,"noise_type")]}_${s}d`),m=this.coordinate(n,"orco"),d=n.inputs.slice(1).map(g=>this.source(g,g.gpu)),h=C(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[m,...d,h,"1.0",u(a.map((g,p)=>p))].join(", ")});`);break}case"ShaderNodeTexVoronoi":{const s=Number(C(n,"voronoi_dimensions")[0]),c=this.use(`node_tex_voronoi_${ai[C(n,"feature")]}_${s}d`),m=this.coordinate(n,"orco"),d=n.inputs.slice(1).map(p=>this.source(p,p.gpu)),h=`${ri[C(n,"distance")].toFixed(1)}`,g=C(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[m,...d,h,g,u(a.map((p,v)=>v))].join(", ")});`);break}case"ShaderNodeTexChecker":{const s=this.coordinate(n,"orco"),c=n.inputs.slice(1).map(m=>this.source(m,m.gpu));l.push(`${this.use("node_tex_checker")}(${[s,...c,u(a.map((m,d)=>d))].join(", ")});`);break}case"ShaderNodeTexWhiteNoise":{const s=Number(C(n,"noise_dimensions")[0]);l.push(`${this.use(`node_white_noise_${s}d`)}(${_()});`);break}case"ShaderNodeTexWave":case"ShaderNodeTexGradient":case"ShaderNodeTexMagic":case"ShaderNodeTexBrick":{const s=this.coordinate(n,"orco"),c=n.inputs.slice(1).map(g=>this.source(g,g.gpu)),m=g=>C(n,`${g}#value`).toFixed(1),d=n.type==="ShaderNodeTexWave"?[m("wave_type"),m("bands_direction"),m("rings_direction"),m("wave_profile")]:n.type==="ShaderNodeTexGradient"?[m("gradient_type")]:n.type==="ShaderNodeTexMagic"?[C(n,"turbulence_depth").toFixed(1)]:[this.uniform("float",C(n,"offset")),C(n,"offset_frequency").toFixed(1),this.uniform("float",C(n,"squash")),C(n,"squash_frequency").toFixed(1)],h={ShaderNodeTexWave:"node_tex_wave",ShaderNodeTexGradient:"node_tex_gradient",ShaderNodeTexMagic:"node_tex_magic",ShaderNodeTexBrick:"node_tex_brick"}[n.type];l.push(`${this.use(h)}(${[s,...c,...d,u(a.map((g,p)=>p))].join(", ")});`);break}case"ShaderNodeMapRange":{const s=C(n,"data_type")==="FLOAT_VECTOR",c=C(n,"interpolation_type").toLowerCase(),m=C(n,"clamp");l.push(`${this.use(`${s?"vector_":""}map_range_${c}`)}(${_([m?"1.0":"0.0"])});`),m&&!s&&(c==="linear"||c==="stepped")&&l.push(`${this.use("clamp_range")}(${u([0])}, ${this.input(n,"To Min","float")}, ${this.input(n,"To Max","float")}, ${u([0])});`);break}case"ShaderNodeClamp":l.push(`${this.use(C(n,"clamp_type")==="MINMAX"?"clamp_minmax":"clamp_range")}(${_()});`);break;case"ShaderNodeHueSaturation":l.push(`${this.use("hue_sat")}(${_()});`);break;case"ShaderNodeBrightContrast":l.push(`${this.use("brightness_contrast")}(${_()});`);break;case"ShaderNodeGamma":l.push(`${this.use("node_gamma")}(${_()});`);break;case"ShaderNodeRGBToBW":l.push(`${this.use("rgbtobw")}(${_([ko])});`);break;case"ShaderNodeSeparateColor":l.push(`${this.use(`separate_color_${C(n,"mode").toLowerCase()}`)}(${_()});`);break;case"ShaderNodeCombineColor":l.push(`${this.use(`combine_color_${C(n,"mode").toLowerCase()}`)}(${_()});`);break;case"ShaderNodeVectorRotate":{const s={AXIS_ANGLE:"axis_angle",X_AXIS:"axis_x",Y_AXIS:"axis_y",Z_AXIS:"axis_z",EULER_XYZ:"euler_xyz"}[C(n,"rotation_type")];l.push(`${this.use(`node_vector_rotate_${s}`)}(${_([C(n,"invert")?"-1.0":"1.0"])});`);break}case"ShaderNodeFresnel":case"ShaderNodeLayerWeight":{const s=n.inputs[1],c="link"in s?this.source(s,"vec3"):"g_data.N";"link"in s||this.s.structure.push("world-normal");const m=this.source(n.inputs[0],"float"),d=n.type==="ShaderNodeFresnel"?"node_fresnel":"node_layer_weight";l.push(`${this.use(d)}(${[m,c,u(a.map((h,g)=>g))].join(", ")});`);break}case"ShaderNodeBump":{const s=n.inputs.find(b=>b.id==="Height"),c=n.inputs.find(b=>b.id==="Normal"),m=c&&"link"in c?this.source(c,"vec3"):"g_data.N";if(!s||!("link"in s)){l.push(`${u([0])} = ${m};`);break}const d=`bgHeight${this.s.functions.length}`;this.s.functions.push("");const h=new ye(this.graph,this.s,!0,`${d}_`),g=h.source(s,"float");this.s.functions[Number(d.slice(8))]=`float ${d}() {
7022
+ `;class Oe{constructor(t,n,o=!1,r="bgN"){this.graph=t,this.derivative=o,this.prefix=r,this.lines=[],this.emitted=new Map,this.s=n??{files:new Set,uniforms:new Map,uniformTypes:new Map,images:[],ramps:[],uvs:new Set,attributes:new Set,structure:[],functions:[]}}get uniforms(){return this.s.uniforms}get images(){return this.s.images}get ramps(){return this.s.ramps}d(t){return this.derivative?`(${t} + dF_impl(${t}))`:t}uniform(t,n){const o=`bgU${this.s.uniforms.size}`,r=ei(t,n);return this.s.uniforms.set(o,t==="float"?r[0]:r),this.s.uniformTypes.set(o,t),o}use(t){const n=fi.get(t);if(!n)throw new Error(`Blender's node library has no ${t}`);return this.s.files.add(n),t}source(t,n){if("value"in t)return this.s.structure.push("v"),this.uniform(n,t.value);const[o,r]=t.link,a=this.graph.nodes[o];if(!a)throw new Error(`The graph links to ${o}, which it does not carry`);const f=this.node(o,a)[r];if(!f)throw new Error(`${o} has no output ${r}`);return this.s.structure.push(["l",o,r]),oi(f.name,f.type,n)}input(t,n,o){const r=t.inputs.find(a=>a.id===n)??t.inputs.find(a=>a.id.replace(/_/g," ")===n);if(!r)throw new Error(`${t.type} arrived without its '${n}' input`);return this.source(r,o??r.gpu)}coordinate(t,n){const o=t.inputs[0];return"link"in o?this.source(o,"vec3"):(this.s.structure.push(["default",n]),n==="orco"?this.d("blender_orco()"):(this.s.uvs.add(""),this.d(`vec3(${Jt("")}, 0.0)`)))}node(t,n){const o=this.emitted.get(t);if(o)return o;const r=`${this.prefix}${this.emitted.size}`,a=n.outputs.map((s,c)=>({name:`${r}_${c}`,type:s.gpu==="closure"||s.gpu===null?"float":s.gpu}));this.emitted.set(t,a);const i=s=>`${a[s].type} ${a[s].name} = ${a[s].type}(0.0);`,f=a.map((s,c)=>i(c)).join(" "),u=s=>s.map(c=>a[c].name).join(", "),_=(s=[])=>[...n.inputs.map(m=>this.source(m,m.gpu)),...s,...a.map(m=>m.name)].join(", ");this.s.structure.push(["n",n.type,n.props.operation,n.props.blend_type,n.props.data_type,n.props.factor_mode,n.props.clamp_factor,n.props.clamp_result,n.props.use_clamp,n.props.noise_dimensions,n.props.noise_type,n.props.voronoi_dimensions,n.props.feature,n.props.distance,n.props.vector_type,n.props.uv_map,n.props.extension,n.props.interpolation,n.props.image_alpha_mode,n.props.image_is_data,n.props.color_ramp?.elements?.length,n.props.color_ramp?.interpolation]);const l=[f];switch(n.type){case"ShaderNodeValue":case"ShaderNodeRGB":{const s=a[0].type;l.push(`${a[0].name} = ${this.uniform(s,L(n,"value"))};`);break}case"ShaderNodeTexCoord":{this.s.uvs.add(""),["blender_orco()","blender_object_normal()",`vec3(${Jt("")}, 0.0)`,"vBlenderObjectPosition","blender_camera()","blender_window()","blender_reflection()"].forEach((c,m)=>{a[m]&&l.push(`${a[m].name} = ${this.d(c)};`)});break}case"ShaderNodeVertexColor":case"ShaderNodeAttribute":{const s=L(n,n.type==="ShaderNodeAttribute"?"attribute_name":"layer_name");this.s.attributes.add(s),this.s.structure.push(["a",s]);const c=n.type==="ShaderNodeAttribute"?"node_attribute":"node_vertex_color";l.push(`${this.use(c)}(${de(s)}, ${u(a.map((m,d)=>d))});`);for(const m of a)l.push(`${m.name} = ${this.d(m.name)};`);break}case"ShaderNodeUVMap":{const s=L(n,"uv_map");this.s.uvs.add(s),l.push(`${a[0].name} = ${this.d(`vec3(${Jt(s)}, 0.0)`)};`);break}case"ShaderNodeMath":{const s=L(n,"operation"),c=this.use(ai[s]??`math_${s.toLowerCase()}`);l.push(`${c}(${_()});`),L(n,"use_clamp")&&l.push(`${this.use("clamp_value")}(${u([0])}, 0.0, 1.0, ${u([0])});`);break}case"ShaderNodeVectorMath":{const s=L(n,"operation");l.push(`${this.use(ri[s]??`vector_math_${s.toLowerCase()}`)}(${_()});`);break}case"ShaderNodeMapping":l.push(`${this.use(`mapping_${L(n,"vector_type").toLowerCase()}`)}(${_()});`);break;case"ShaderNodeInvert":l.push(`${this.use("invert")}(${_()});`);break;case"ShaderNodeSeparateXYZ":l.push(`${this.use("separate_xyz")}(${_()});`);break;case"ShaderNodeCombineXYZ":l.push(`${this.use("combine_xyz")}(${_()});`);break;case"ShaderNodeMix":{const s=L(n,"data_type"),c=L(n,"factor_mode")==="NON_UNIFORM",m={FLOAT:"Float",VECTOR:"Vector",RGBA:"Color",ROTATION:"Rotation"}[s];if(!m)throw new Error(`Mix has data type ${s}`);const d=s==="VECTOR"&&c;let h=this.input(n,d?"Factor_Vector":"Factor_Float");if(L(n,"clamp_factor")){const v=`${r}_fac`;l.push(d?`vec3 ${v}; ${this.use("node_mix_clamp_vector")}(${h}, vec3(0.0), vec3(1.0), ${v});`:`float ${v}; ${this.use("node_mix_clamp_value")}(${h}, 0.0, 1.0, ${v});`),h=v}const g=s==="FLOAT"?"node_mix_float":s==="VECTOR"?c?"node_mix_vector_non_uniform":"node_mix_vector":s==="RGBA"?`node_mix_${Ze[L(n,"blend_type")]}`:"node_mix_rotation",p=n.outputs.findIndex(v=>v.id===`Result_${m}`);l.push(`${this.use(g)}(${h}, ${this.input(n,`A_${m}`)}, ${this.input(n,`B_${m}`)}, ${u([p])});`),s==="RGBA"&&L(n,"clamp_result")&&l.push(`${this.use("node_mix_clamp_color")}(${u([p])}, vec4(0.0), vec4(1.0), ${u([p])});`);break}case"ShaderNodeMixRGB":{const s=`${r}_fac`;l.push(`float ${s}; ${this.use("clamp_value")}(${this.input(n,"Fac")}, 0.0, 1.0, ${s});`);const c=n.inputs.slice(1).map(m=>this.source(m,m.gpu));l.push(`${this.use(`mix_${Ze[L(n,"blend_type")]}`)}(${[s,...c,u([0])].join(", ")});`),L(n,"use_clamp")&&l.push(`${this.use("clamp_color")}(${u([0])}, vec4(0.0), vec4(1.0), ${u([0])});`);break}case"ShaderNodeValToRGB":{const s=L(n,"color_ramp"),c=this.input(n,"Fac"),[m,d]=s.elements,h=g=>this.uniform("vec4",g.slice(1,5));if(s.elements.length===1)l.push(`${u([0])} = ${h(m)}; ${u([1])} = ${u([0])}.a;`);else if(s.elements.length===2&&s.color_mode==="RGB"&&d&&s.interpolation!=="B_SPLINE"&&s.interpolation!=="CARDINAL")if(s.interpolation==="CONSTANT")l.push(`${this.use("valtorgb_opti_constant")}(${c}, ${this.uniform("float",Math.max(m[0],d[0]))}, ${h(m)}, ${h(d)}, ${u([0,1])});`);else{const g=1/(d[0]-m[0]),p=s.interpolation==="EASE"?"valtorgb_opti_ease":"valtorgb_opti_linear";l.push(`${this.use(p)}(${c}, ${this.uniform("vec2",[g,-g*m[0]])}, ${h(m)}, ${h(d)}, ${u([0,1])});`)}else{const g=`bgRamp${this.s.ramps.length}`;this.s.ramps.push({uniform:g,table:s.table}),this.s.structure.push(["ramp",s.interpolation==="CONSTANT"]),l.push(s.interpolation==="CONSTANT"?`${u([0])} = texelFetch(${g}, ivec2(int(clamp(${c}, 0.0, 1.0) * 256.0), 0), 0);`:`${u([0])} = texture(${g}, vec2(clamp(${c}, 0.0, 1.0) * (256.0 / 257.0) + 0.5 / 257.0, 0.5));`),l.push(`${u([1])} = ${u([0])}.a;`)}break}case"ShaderNodeRGBCurve":case"ShaderNodeVectorCurve":case"ShaderNodeFloatCurve":{const s=L(n,"curve_mapping"),c=`bgRamp${this.s.ramps.length}`;this.s.ramps.push({uniform:c,table:s.table}),this.s.structure.push(["curve"]);const m=this.input(n,n.inputs.some(d=>d.id==="Factor")?"Factor":"Fac","float");n.type==="ShaderNodeRGBCurve"?l.push(`${this.use("curves_combined_rgb")}(${m}, ${this.input(n,"Color","vec4")}, vec4(0.0, 0.0, 0.0, 1.0), vec4(1.0), ${c}, 0.5, ${this.uniform("vec4",s.minimums)}, ${this.uniform("vec4",s.dividers)}, ${this.uniform("vec4",s.starts)}, ${this.uniform("vec4",s.ends)}, ${u([0])});`):n.type==="ShaderNodeVectorCurve"?l.push(`${this.use("curves_vector_mixed")}(${m}, ${this.input(n,"Vector","vec3")}, ${c}, 0.5, ${this.uniform("vec3",s.minimums.slice(0,3))}, ${this.uniform("vec3",s.dividers.slice(0,3))}, ${this.uniform("vec3",s.starts.slice(0,3))}, ${this.uniform("vec3",s.ends.slice(0,3))}, ${u([0])});`):l.push(`${this.use("curves_float_mixed")}(${m}, ${this.input(n,"Value","float")}, ${c}, 0.5, ${this.uniform("float",s.minimums[0])}, ${this.uniform("float",s.dividers[0])}, ${this.uniform("float",s.starts[0])}, ${this.uniform("float",s.ends[0])}, ${u([0])});`);break}case"ShaderNodeTexNoise":{const s=Number(L(n,"noise_dimensions")[0]),c=this.use(`node_noise_tex_${ii[L(n,"noise_type")]}_${s}d`),m=this.coordinate(n,"orco"),d=n.inputs.slice(1).map(g=>this.source(g,g.gpu)),h=L(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[m,...d,h,"1.0",u(a.map((g,p)=>p))].join(", ")});`);break}case"ShaderNodeTexVoronoi":{const s=Number(L(n,"voronoi_dimensions")[0]),c=this.use(`node_tex_voronoi_${si[L(n,"feature")]}_${s}d`),m=this.coordinate(n,"orco"),d=n.inputs.slice(1).map(p=>this.source(p,p.gpu)),h=`${li[L(n,"distance")].toFixed(1)}`,g=L(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[m,...d,h,g,u(a.map((p,v)=>v))].join(", ")});`);break}case"ShaderNodeTexChecker":{const s=this.coordinate(n,"orco"),c=n.inputs.slice(1).map(m=>this.source(m,m.gpu));l.push(`${this.use("node_tex_checker")}(${[s,...c,u(a.map((m,d)=>d))].join(", ")});`);break}case"ShaderNodeTexWhiteNoise":{const s=Number(L(n,"noise_dimensions")[0]);l.push(`${this.use(`node_white_noise_${s}d`)}(${_()});`);break}case"ShaderNodeTexWave":case"ShaderNodeTexGradient":case"ShaderNodeTexMagic":case"ShaderNodeTexBrick":{const s=this.coordinate(n,"orco"),c=n.inputs.slice(1).map(g=>this.source(g,g.gpu)),m=g=>L(n,`${g}#value`).toFixed(1),d=n.type==="ShaderNodeTexWave"?[m("wave_type"),m("bands_direction"),m("rings_direction"),m("wave_profile")]:n.type==="ShaderNodeTexGradient"?[m("gradient_type")]:n.type==="ShaderNodeTexMagic"?[L(n,"turbulence_depth").toFixed(1)]:[this.uniform("float",L(n,"offset")),L(n,"offset_frequency").toFixed(1),this.uniform("float",L(n,"squash")),L(n,"squash_frequency").toFixed(1)],h={ShaderNodeTexWave:"node_tex_wave",ShaderNodeTexGradient:"node_tex_gradient",ShaderNodeTexMagic:"node_tex_magic",ShaderNodeTexBrick:"node_tex_brick"}[n.type];l.push(`${this.use(h)}(${[s,...c,...d,u(a.map((g,p)=>p))].join(", ")});`);break}case"ShaderNodeMapRange":{const s=L(n,"data_type")==="FLOAT_VECTOR",c=L(n,"interpolation_type").toLowerCase(),m=L(n,"clamp");l.push(`${this.use(`${s?"vector_":""}map_range_${c}`)}(${_([m?"1.0":"0.0"])});`),m&&!s&&(c==="linear"||c==="stepped")&&l.push(`${this.use("clamp_range")}(${u([0])}, ${this.input(n,"To Min","float")}, ${this.input(n,"To Max","float")}, ${u([0])});`);break}case"ShaderNodeClamp":l.push(`${this.use(L(n,"clamp_type")==="MINMAX"?"clamp_minmax":"clamp_range")}(${_()});`);break;case"ShaderNodeHueSaturation":l.push(`${this.use("hue_sat")}(${_()});`);break;case"ShaderNodeBrightContrast":l.push(`${this.use("brightness_contrast")}(${_()});`);break;case"ShaderNodeGamma":l.push(`${this.use("node_gamma")}(${_()});`);break;case"ShaderNodeRGBToBW":l.push(`${this.use("rgbtobw")}(${_([Vo])});`);break;case"ShaderNodeSeparateColor":l.push(`${this.use(`separate_color_${L(n,"mode").toLowerCase()}`)}(${_()});`);break;case"ShaderNodeCombineColor":l.push(`${this.use(`combine_color_${L(n,"mode").toLowerCase()}`)}(${_()});`);break;case"ShaderNodeVectorRotate":{const s={AXIS_ANGLE:"axis_angle",X_AXIS:"axis_x",Y_AXIS:"axis_y",Z_AXIS:"axis_z",EULER_XYZ:"euler_xyz"}[L(n,"rotation_type")];l.push(`${this.use(`node_vector_rotate_${s}`)}(${_([L(n,"invert")?"-1.0":"1.0"])});`);break}case"ShaderNodeFresnel":case"ShaderNodeLayerWeight":{const s=n.inputs[1],c="link"in s?this.source(s,"vec3"):"g_data.N";"link"in s||this.s.structure.push("world-normal");const m=this.source(n.inputs[0],"float"),d=n.type==="ShaderNodeFresnel"?"node_fresnel":"node_layer_weight";l.push(`${this.use(d)}(${[m,c,u(a.map((h,g)=>g))].join(", ")});`);break}case"ShaderNodeBump":{const s=n.inputs.find(O=>O.id==="Height"),c=n.inputs.find(O=>O.id==="Normal"),m=c&&"link"in c?this.source(c,"vec3"):"g_data.N";if(!s||!("link"in s)){l.push(`${u([0])} = ${m};`);break}const d=`bgHeight${this.s.functions.length}`;this.s.functions.push("");const h=new Oe(this.graph,this.s,!0,`${d}_`),g=h.source(s,"float");this.s.functions[Number(d.slice(8))]=`float ${d}() {
7023
7023
  ${h.lines.join(`
7024
7024
  `)}
7025
7025
  return ${g};
7026
- }`;const p=this.input(n,"Filter Width","float");l.push(`float ${r}_h = ${d}();`,`g_derivative_filter_width = ${p} * derivative_scale_get();`,`g_derivative_flag = 1; float ${r}_hx = ${d}();`,`g_derivative_flag = -1; float ${r}_hy = ${d}();`,"g_derivative_flag = 0;");const v=C(n,"invert")?"-1.0":"1.0";l.push(`${this.use("node_bump")}(${this.input(n,"Strength","float")}, ${this.input(n,"Distance","float")}, ${p}, ${r}_h, ${m}, vec2(${r}_hx, ${r}_hy), ${v}, ${u([0])});`);break}case"ShaderNodeNormalMap":{const s=C(n,"space"),c=this.input(n,"Strength","float"),m=this.input(n,"Color","vec3"),d=`${r}_n`;if(l.push(`vec3 ${d}; ${this.use(s.startsWith("BLENDER_")?"color_to_blender_normal_new_shading":"color_to_normal_new_shading")}(${m}, ${d});`),n.props.convention==="DIRECTX"&&l.push(`${this.use("color_invert_green_channel")}(${d}, ${d});`),s==="TANGENT"){const h=C(n,"uv_map");this.s.uvs.add(h),l.push(`${this.use("node_normal_map")}(blender_uv_tangent(${Kt(h)}), ${c}, ${d}, g_data.Ni, ${u([0])});`)}else(s==="OBJECT"||s==="BLENDER_OBJECT")&&l.push(`${this.use("normal_transform_object_to_world")}(${d}, ${d});`),l.push(`${this.use("node_normal_map_mix")}(${c}, ${d}, ${u([0])});`);break}case"ShaderNodeNewGeometry":{l.push(`${this.use("node_geometry")}(${["blender_orco()",u(a.map((s,c)=>c))].join(", ")});`),a[0]&&l.push(`${a[0].name} = ${this.d(a[0].name)};`);for(const s of[1,2,4])a[s]&&l.push(`${a[s].name} = normalize(${a[s].name});`);break}case"ShaderNodeTexImage":{const s=C(n,"image");if(s===null){l.push(n.props.image_missing===!0?`${u([0])} = vec4(1.0, 0.0, 1.0, 1.0); ${u([1])} = 1.0;`:`${u([0])} = vec4(0.0); ${u([1])} = 0.0;`);break}const c=C(n,"projection"),m=C(n,"interpolation"),d=m==="Cubic"||m==="Smart",h=C(n,"extension"),g=`bgImage${this.s.images.length}`;this.s.images.push({uniform:g,node:t,name:s.name,revision:s.revision,extension:h,closest:m==="Closest",mipmap:c!=="SPHERE"&&c!=="TUBE",tiled:c==="FLAT"&&n.props.image_tiled===!0});const p=this.s.images.at(-1).tiled;this.s.structure.push(["img",c,d,p]);let v=this.coordinate(n,"uv");const b=u([0]),y=u([1]);if(c==="BOX"){const O=`${r}_n`;l.push(`vec3 ${O}; ${this.use("world_normals_get")}(${O}); ${this.use("normal_transform_world_to_object")}(${O}, ${O});`,`vec4 ${r}_c1, ${r}_c2, ${r}_c3;`,`${this.use(d?"tex_box_sample_cubic":"tex_box_sample_linear")}(${v}, ${O}, ${g}, ${r}_c1, ${r}_c2, ${r}_c3);`,`${this.use("tex_box_blend")}(${O}, ${r}_c1, ${r}_c2, ${r}_c3, ${this.uniform("float",C(n,"projection_blend"))}, ${b}, ${y});`)}else if(p)d&&this.use("cubic_bspline_coefficients"),l.push(`${d?"blender_tex_tile_cubic":"blender_tex_tile_linear"}(${v}, ${g}, ${g}Map, ${b}, ${y});`);else{if(c==="SPHERE"||c==="TUBE"){const O=`${r}_co`;l.push(`vec3 ${O}; ${this.use("point_texco_remap_square")}(${v}, ${O});`,`${this.use(c==="SPHERE"?"point_map_to_sphere":"point_map_to_tube")}(${O}, ${O});`),v=O}l.push(`${this.use(d?"node_tex_image_cubic":"node_tex_image_linear")}(${v}, ${g}, ${b}, ${y});`),h==="CLIP"&&l.push(`if (any(lessThan(${v}.xy, vec2(0.0))) || any(greaterThan(${v}.xy, vec2(1.0)))) { ${b} = vec4(0.0); ${y} = 0.0; }`)}const S=C(n,"image_alpha_mode"),T=this.uses(t,1),A=u([0]);S==="NONE"||S==="CHANNEL_PACKED"||C(n,"image_is_data")?l.push(`${A}.a = 1.0;`):S==="PREMUL"?l.push(T?`if (${A}.a != 0.0 && ${A}.a != 1.0) ${A}.rgb /= ${A}.a;`:`${A}.a = 1.0;`):l.push(T?`${A}.a = 1.0;`:`${A}.rgb *= ${A}.a;`);break}}return this.lines.push(...l),a}uses(t,n){const o=a=>"link"in a&&a.link[0]===t&&a.link[1]===n,r=a=>a!==void 0&&("emission"in a?a.emission.some(o):"mix"in a?o(a.mix[0])||r(a.mix[1])||r(a.mix[2]):"add"in a?r(a.add[0])||r(a.add[1]):!1);return Object.values(this.graph.inputs).some(o)||Object.values(this.graph.nodes).some(a=>a.inputs.some(o))||r(this.graph.closure)}compile(){const t=this.graph.surface==="ShaderNodeEmission"?{Color:"vec4",Strength:"float"}:{"Base Color":"vec4",Metallic:"float",Roughness:"float",Alpha:"float","Emission Color":"vec4","Emission Strength":"float",Normal:"vec3"},n={},o=[];let r=0;for(const[s,c]of Object.entries(t)){const m=this.graph.inputs[s];if(!m||s==="Normal"&&!("link"in m))continue;const d=`bgOut${r++}`;n[s]={global:d,type:c},this.s.structure.push(["out",s]),o.push(`${d} = ${this.source(m,c)};`)}const a=this.graph.closure;if(a){let s=0;const c=(m,d)=>{if("principled"in m)this.s.structure.push("cP"),o.push(`bgClosureP += ${d};`);else if("emission"in m)this.s.structure.push("cE"),o.push(`bgClosureE += ${d} * ${this.source(m.emission[0],"vec4")}.rgb * ${this.source(m.emission[1],"float")};`);else if("transparent"in m)this.s.structure.push("cT"),o.push(`bgClosureT += ${d} * ${this.source({value:m.transparent},"float")};`);else if("mix"in m){this.s.structure.push("cM");const h=`bgClosureF${s++}`;o.push(`float ${h} = clamp(${this.source(m.mix[0],"float")}, 0.0, 1.0);`),c(m.mix[1],`${d} * (1.0 - ${h})`),c(m.mix[2],`${d} * ${h}`)}else"add"in m?(this.s.structure.push("cA"),c(m.add[0],d),c(m.add[1],d)):this.s.structure.push("c0")};o.push("bgClosureP = 0.0;","bgClosureE = vec3(0.0);","bgClosureT = 0.0;"),c(a,"1.0")}const i=[],f=new Set,u=s=>{if(!f.has(s)){f.add(s);for(const c of ue[s].deps)u(c);i.push(s)}};for(const s of this.s.files)u(s);const _=`void blenderGraph() {
7026
+ }`;const p=this.input(n,"Filter Width","float");l.push(`float ${r}_h = ${d}();`,`g_derivative_filter_width = ${p} * derivative_scale_get();`,`g_derivative_flag = 1; float ${r}_hx = ${d}();`,`g_derivative_flag = -1; float ${r}_hy = ${d}();`,"g_derivative_flag = 0;");const v=L(n,"invert")?"-1.0":"1.0";l.push(`${this.use("node_bump")}(${this.input(n,"Strength","float")}, ${this.input(n,"Distance","float")}, ${p}, ${r}_h, ${m}, vec2(${r}_hx, ${r}_hy), ${v}, ${u([0])});`);break}case"ShaderNodeNormalMap":{const s=L(n,"space"),c=this.input(n,"Strength","float"),m=this.input(n,"Color","vec3"),d=`${r}_n`;if(l.push(`vec3 ${d}; ${this.use(s.startsWith("BLENDER_")?"color_to_blender_normal_new_shading":"color_to_normal_new_shading")}(${m}, ${d});`),n.props.convention==="DIRECTX"&&l.push(`${this.use("color_invert_green_channel")}(${d}, ${d});`),s==="TANGENT"){const h=L(n,"uv_map");this.s.uvs.add(h),l.push(`${this.use("node_normal_map")}(blender_uv_tangent(${Jt(h)}), ${c}, ${d}, g_data.Ni, ${u([0])});`)}else(s==="OBJECT"||s==="BLENDER_OBJECT")&&l.push(`${this.use("normal_transform_object_to_world")}(${d}, ${d});`),l.push(`${this.use("node_normal_map_mix")}(${c}, ${d}, ${u([0])});`);break}case"ShaderNodeNewGeometry":{l.push(`${this.use("node_geometry")}(${["blender_orco()",u(a.map((s,c)=>c))].join(", ")});`),a[0]&&l.push(`${a[0].name} = ${this.d(a[0].name)};`);for(const s of[1,2,4])a[s]&&l.push(`${a[s].name} = normalize(${a[s].name});`);break}case"ShaderNodeTexImage":{const s=L(n,"image");if(s===null){l.push(n.props.image_missing===!0?`${u([0])} = vec4(1.0, 0.0, 1.0, 1.0); ${u([1])} = 1.0;`:`${u([0])} = vec4(0.0); ${u([1])} = 0.0;`);break}const c=L(n,"projection"),m=L(n,"interpolation"),d=m==="Cubic"||m==="Smart",h=L(n,"extension"),g=`bgImage${this.s.images.length}`;this.s.images.push({uniform:g,node:t,name:s.name,revision:s.revision,extension:h,closest:m==="Closest",mipmap:c!=="SPHERE"&&c!=="TUBE",tiled:c==="FLAT"&&n.props.image_tiled===!0});const p=this.s.images.at(-1).tiled;this.s.structure.push(["img",c,d,p]);let v=this.coordinate(n,"uv");const O=u([0]),b=u([1]);if(c==="BOX"){const A=`${r}_n`;l.push(`vec3 ${A}; ${this.use("world_normals_get")}(${A}); ${this.use("normal_transform_world_to_object")}(${A}, ${A});`,`vec4 ${r}_c1, ${r}_c2, ${r}_c3;`,`${this.use(d?"tex_box_sample_cubic":"tex_box_sample_linear")}(${v}, ${A}, ${g}, ${r}_c1, ${r}_c2, ${r}_c3);`,`${this.use("tex_box_blend")}(${A}, ${r}_c1, ${r}_c2, ${r}_c3, ${this.uniform("float",L(n,"projection_blend"))}, ${O}, ${b});`)}else if(p)d&&this.use("cubic_bspline_coefficients"),l.push(`${d?"blender_tex_tile_cubic":"blender_tex_tile_linear"}(${v}, ${g}, ${g}Map, ${O}, ${b});`);else{if(c==="SPHERE"||c==="TUBE"){const A=`${r}_co`;l.push(`vec3 ${A}; ${this.use("point_texco_remap_square")}(${v}, ${A});`,`${this.use(c==="SPHERE"?"point_map_to_sphere":"point_map_to_tube")}(${A}, ${A});`),v=A}l.push(`${this.use(d?"node_tex_image_cubic":"node_tex_image_linear")}(${v}, ${g}, ${O}, ${b});`),h==="CLIP"&&l.push(`if (any(lessThan(${v}.xy, vec2(0.0))) || any(greaterThan(${v}.xy, vec2(1.0)))) { ${O} = vec4(0.0); ${b} = 0.0; }`)}const P=L(n,"image_alpha_mode"),T=this.uses(t,1),M=u([0]);P==="NONE"||P==="CHANNEL_PACKED"||L(n,"image_is_data")?l.push(`${M}.a = 1.0;`):P==="PREMUL"?l.push(T?`if (${M}.a != 0.0 && ${M}.a != 1.0) ${M}.rgb /= ${M}.a;`:`${M}.a = 1.0;`):l.push(T?`${M}.a = 1.0;`:`${M}.rgb *= ${M}.a;`);break}}return this.lines.push(...l),a}uses(t,n){const o=a=>"link"in a&&a.link[0]===t&&a.link[1]===n,r=a=>a!==void 0&&("emission"in a?a.emission.some(o):"mix"in a?o(a.mix[0])||r(a.mix[1])||r(a.mix[2]):"add"in a?r(a.add[0])||r(a.add[1]):!1);return Object.values(this.graph.inputs).some(o)||Object.values(this.graph.nodes).some(a=>a.inputs.some(o))||r(this.graph.closure)}compile(){const t=this.graph.surface==="ShaderNodeEmission"?{Color:"vec4",Strength:"float"}:{"Base Color":"vec4",Metallic:"float",Roughness:"float",Alpha:"float","Emission Color":"vec4","Emission Strength":"float",Normal:"vec3"},n={},o=[];let r=0;for(const[s,c]of Object.entries(t)){const m=this.graph.inputs[s];if(!m||s==="Normal"&&!("link"in m))continue;const d=`bgOut${r++}`;n[s]={global:d,type:c},this.s.structure.push(["out",s]),o.push(`${d} = ${this.source(m,c)};`)}const a=this.graph.closure;if(a){let s=0;const c=(m,d)=>{if("principled"in m)this.s.structure.push("cP"),o.push(`bgClosureP += ${d};`);else if("emission"in m)this.s.structure.push("cE"),o.push(`bgClosureE += ${d} * ${this.source(m.emission[0],"vec4")}.rgb * ${this.source(m.emission[1],"float")};`);else if("transparent"in m)this.s.structure.push("cT"),o.push(`bgClosureT += ${d} * ${this.source({value:m.transparent},"float")};`);else if("mix"in m){this.s.structure.push("cM");const h=`bgClosureF${s++}`;o.push(`float ${h} = clamp(${this.source(m.mix[0],"float")}, 0.0, 1.0);`),c(m.mix[1],`${d} * (1.0 - ${h})`),c(m.mix[2],`${d} * ${h}`)}else"add"in m?(this.s.structure.push("cA"),c(m.add[0],d),c(m.add[1],d)):this.s.structure.push("c0")};o.push("bgClosureP = 0.0;","bgClosureE = vec3(0.0);","bgClosureT = 0.0;"),c(a,"1.0")}const i=[],f=new Set,u=s=>{if(!f.has(s)){f.add(s);for(const c of _e[s].deps)u(c);i.push(s)}};for(const s of this.s.files)u(s);const _=`void blenderGraph() {
7027
7027
  blender_init_globals();
7028
7028
  ${[...this.lines,...o].join(`
7029
7029
  `)}
7030
- }`,l=[Gr,fi(si+i.map(s=>ue[s].code).join(`
7030
+ }`,l=[Zr,mi(ci+i.map(s=>_e[s].code).join(`
7031
7031
  `)+`
7032
- `+li,[...this.s.functions,_].join(`
7032
+ `+ui,[...this.s.functions,_].join(`
7033
7033
  `)),...[...this.s.uniformTypes].map(([s,c])=>`uniform ${c} ${s};`),...this.images.map(s=>s.tiled?`uniform highp sampler2DArray ${s.uniform};
7034
7034
  uniform highp sampler2D ${s.uniform}Map;`:`uniform sampler2D ${s.uniform};`),...this.ramps.map(s=>`uniform sampler2D ${s.uniform};`),...Object.values(n).map(s=>`${s.type} ${s.global};`),...a?["float bgClosureP;","vec3 bgClosureE;","float bgClosureT;"]:[],...this.s.functions,_].join(`
7035
- `);return{key:JSON.stringify([this.graph.surface,this.s.structure,[...this.s.uvs].sort()]),declarations:l,uniforms:this.uniforms,images:this.images,ramps:this.ramps,uvs:[...this.s.uvs],attributes:[...this.s.attributes],outputs:n,surface:this.graph.surface,closure:a!==void 0}}}function fi(e,t){const n=[],o=/^[A-Za-z_][\w ]*?\b([A-Za-z_]\w*)\s*\(/gm;let r=0;for(let u;u=o.exec(e);){if(u.index<r)continue;let _=u.index+u[0].length;for(let m=1;_<e.length&&m>0;_++)m+=e[_]==="("?1:e[_]===")"?-1:0;const l=e.slice(_).match(/^\s*(\{|;)/);if(!l||/^\s*#/.test(e.slice(e.lastIndexOf(`
7035
+ `);return{key:JSON.stringify([this.graph.surface,this.s.structure,[...this.s.uvs].sort()]),declarations:l,uniforms:this.uniforms,images:this.images,ramps:this.ramps,uvs:[...this.s.uvs],attributes:[...this.s.attributes],outputs:n,surface:this.graph.surface,closure:a!==void 0}}}function mi(e,t){const n=[],o=/^[A-Za-z_][\w ]*?\b([A-Za-z_]\w*)\s*\(/gm;let r=0;for(let u;u=o.exec(e);){if(u.index<r)continue;let _=u.index+u[0].length;for(let m=1;_<e.length&&m>0;_++)m+=e[_]==="("?1:e[_]===")"?-1:0;const l=e.slice(_).match(/^\s*(\{|;)/);if(!l||/^\s*#/.test(e.slice(e.lastIndexOf(`
7036
7036
  `,u.index)+1,u.index+1))||e.slice(Math.max(0,u.index-2),u.index).endsWith(`\\
7037
- `))continue;let c=_+l[0].length;if(l[1]==="{")for(let m=1;c<e.length&&m>0;c++)m+=e[c]==="{"?1:e[c]==="}"?-1:0;n.push({text:e.slice(r,u.index),name:null}),n.push({text:e.slice(u.index,c),name:u[1]}),r=c,o.lastIndex=c}n.push({text:e.slice(r),name:null});const a=new Set(n.filter(u=>u.name===null)),i=new Set,f=u=>{for(const _ of u.matchAll(/[A-Za-z_]\w*/g))i.add(_[0])};f(t);for(const u of a)f(u.text);for(let u=!0;u;){u=!1;for(const _ of n)a.has(_)||_.name===null||!i.has(_.name)||(a.add(_),f(_.text),u=!0)}return n.filter(u=>a.has(u)).map(u=>u.text).join("")}function me(e){return`v${kt(e)}`}function Kt(e){return e===""?"vBlenderUvRender":`vBlenderUv_${[...e].map(t=>t.charCodeAt(0).toString(16)).join("")}`}function ci(e){return new ye(e).compile()}function ui(e){const t=new Uint16Array(e.length*4);e.forEach((o,r)=>t.set([o[0]??0,o[1]??0,o[2]??0,o[3]??1].map(a=>mn.toHalfFloat(a)),r*4));const n=new kn(t,e.length,1,$n,he);return n.minFilter=n.magFilter=Xt,n.wrapS=n.wrapT=ho,n.needsUpdate=!0,n}const gt=new WeakMap,$o=new Set,Ct=new WeakMap,yn=new WeakMap;function wn(e){const t=Ct.get(e);if(t){Ct.delete(e);for(const n of t.binding.ramps)n.dispose()}}function mi(e,t,n,o=!1){const r=gt.get(e);if(t&&$o.has(t.key)&&(t=null),!t){if(wn(e),r){for(const f of r.ramps)f.dispose();gt.delete(e),e.needsUpdate=!0}return}if(r&&r.compiled.key===t.key){wn(e),On(r,t,n);return}if(o){wn(e);for(const u of r?.ramps??[])u.dispose();const f={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};On(f,t,n),gt.set(e,f),e.needsUpdate=!0;return}const a=Ct.get(e);if(a&&a.binding.compiled.key===t.key){On(a.binding,t,n);return}wn(e);const i={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};On(i,t,n),Ct.set(e,{binding:i,started:!1})}function On(e,t,n){e.compiled=t;for(const[o,r]of t.uniforms){const a=typeof r=="number"?r:r.length===2?new Gt(...r):r.length===3?new x(...r):new Cn(...r),i=e.uniforms[o];i?i.value=a:e.uniforms[o]={value:a}}for(const o of e.ramps)o.dispose();e.ramps=t.ramps.map(o=>{const r=ui(o.table);return(e.uniforms[o.uniform]??={value:null}).value=r,r});for(const o of t.images){const r=n(o);if(o.tiled){const a=r!==null&&"tiles"in r?r:null;(e.uniforms[o.uniform]??={value:null}).value=a?.tiles??null,(e.uniforms[`${o.uniform}Map`]??={value:null}).value=a?.map??null}else(e.uniforms[o.uniform]??={value:null}).value=r!==null&&"tiles"in r?null:r}}function _i(e){const t=gt.get(e);return t?`${t.compiled.key}|${JSON.stringify(t.channels)}`:""}function di(e){return Object.values(gt.get(e)?.channels??{})}function Lo(e,t){const n=new Set(["position","normal","uv"]);if(t.hasAttribute("tangent")&&n.add("tangent"),e.vertexColors&&n.add("color"),!(e instanceof en))return n;const o=t.userData.blenderUvChannels,r=a=>{const i=a===""?0:o?.[a]??9;n.add(i===0?"uv":`uv${i}`)};for(const a of[e.map,e.roughnessMap,e.normalMap])a&&r(a.userData.blenderUvName??"");for(const a of[gt.get(e),Ct.get(e)?.binding])if(a){n.add("blenderOrco");for(const i of a.compiled.uvs)r(i);for(const i of a.compiled.attributes)n.add(kt(i))}return n}function Ye(e,t){const n=t.userData.blenderUvChannels,o=t.getAttribute("position")?.count??0,r={};for(const a of e.uvs){let i=a===""?0:n?.[a];i===void 0&&(i=9,t.getAttribute("uv9")?.count!==o&&t.setAttribute("uv9",new lt(new Float32Array(o*2),2))),r[a]=i}return r}function hi(e,t,n,o,r,a,i){const f=yn.get(e);f&&++f.draws>1&&(f.shadow.dispose(),yn.delete(e));const u=Ct.get(e);if(u&&!u.started){u.started=!0,u.binding.channels=Ye(u.binding.compiled,t);const c=i(e);gt.set(c,u.binding);const m=new Rt(t,c);m.castShadow=a.castShadow,m.receiveShadow=a.receiveShadow;const d=()=>{if(Ct.get(e)!==u){c.dispose();return}Ct.delete(e);for(const h of gt.get(e)?.ramps??[])h.dispose();gt.set(e,u.binding),e.needsUpdate=!0,yn.get(e)?.shadow.dispose(),yn.set(e,{shadow:c,draws:0}),ht()};n.compileAsync(m,r,o).then(d,d)}const _=gt.get(e);if(!_)return;const l=n.properties.get(e).currentProgram;if(l?.diagnostics?.runnable===!1&&l.cacheKey?.includes(_.compiled.key)){$o.add(_.compiled.key),gt.delete(e),e.needsUpdate=!0;const c=l.diagnostics.fragmentShader.log.split(`
7038
- `).find(m=>m.startsWith("ERROR"))??"";console.warn(`Blender material "${e.name}": its node graph did not compile for WebGL, so it is drawn with its constant values. ${c}`);return}const s=Ye(_.compiled,t);JSON.stringify(s)!==JSON.stringify(_.channels)&&(_.channels=s,e.needsUpdate=!0)}function pi(e){const t=Array.isArray(e.material)?e.material:[e.material];if(!t.some(u=>u instanceof en&&gt.has(u)))return;const n=e.geometry,o=e.userData.blenderTexspace??null,r=n.getAttribute("position"),a=JSON.stringify([o,r?.version??0,r?.count??0]);!n.userData.blenderOrcoFromDoor&&n.userData.blenderOrcoStamp!==a&&(n.setAttribute("blenderOrco",gi(n,o)),n.userData.blenderOrcoStamp=a);const i=r?.count??0,f=e.userData.blenderDefaultColor;for(const u of t){const _=u instanceof en?gt.get(u):void 0;for(const l of _?.compiled.attributes??[]){const s=kt(l),c=l===""?f===void 0?void 0:n.getAttribute(kt(f)):n.getAttribute(s);c&&c.count===i?n.getAttribute(s)!==c&&n.setAttribute(s,c):n.getAttribute(s)?.count!==i&&n.setAttribute(s,new lt(new Float32Array(i*4),4))}}}function gi(e,t){const n=e.getAttribute("position");let o,r;if(t)o=[...t[0]],r=[...t[1]];else{e.computeBoundingBox();const i=e.boundingBox;o=[(i.min.x+i.max.x)/2,(i.min.y+i.max.y)/2,(i.min.z+i.max.z)/2],r=[(i.max.x-i.min.x)/2,(i.max.y-i.min.y)/2,(i.max.z-i.min.z)/2]}r=r.map(i=>i===0?1:i);const a=new Float32Array(n.count*3);for(let i=0;i<n.count;i++)a[i*3]=(n.getX(i)-o[0])/r[0]*.5+.5,a[i*3+1]=(n.getY(i)-o[1])/r[1]*.5+.5,a[i*3+2]=(n.getZ(i)-o[2])/r[2]*.5+.5;return new lt(a,3)}function vi(e,t){const n=gt.get(e);if(!n)return;const{compiled:o,channels:r}=n;Object.assign(t.uniforms,n.uniforms,{blenderViewport:{value:Vo}});const a=p=>p===0?"uv":`uv${p}`,i=`varying vec3 vBlenderObjectPosition;
7037
+ `))continue;let c=_+l[0].length;if(l[1]==="{")for(let m=1;c<e.length&&m>0;c++)m+=e[c]==="{"?1:e[c]==="}"?-1:0;n.push({text:e.slice(r,u.index),name:null}),n.push({text:e.slice(u.index,c),name:u[1]}),r=c,o.lastIndex=c}n.push({text:e.slice(r),name:null});const a=new Set(n.filter(u=>u.name===null)),i=new Set,f=u=>{for(const _ of u.matchAll(/[A-Za-z_]\w*/g))i.add(_[0])};f(t);for(const u of a)f(u.text);for(let u=!0;u;){u=!1;for(const _ of n)a.has(_)||_.name===null||!i.has(_.name)||(a.add(_),f(_.text),u=!0)}return n.filter(u=>a.has(u)).map(u=>u.text).join("")}function de(e){return`v${$t(e)}`}function Jt(e){return e===""?"vBlenderUvRender":`vBlenderUv_${[...e].map(t=>t.charCodeAt(0).toString(16)).join("")}`}function _i(e){return new Oe(e).compile()}function di(e){const t=new Uint16Array(e.length*4);e.forEach((o,r)=>t.set([o[0]??0,o[1]??0,o[2]??0,o[3]??1].map(a=>dn.toHalfFloat(a)),r*4));const n=new $n(t,e.length,1,Ln,ge);return n.minFilter=n.magFilter=Yt,n.wrapS=n.wrapT=vo,n.needsUpdate=!0,n}const gt=new WeakMap,jo=new Set,kt=new WeakMap,wn=new WeakMap;function On(e){const t=kt.get(e);if(t){kt.delete(e);for(const n of t.binding.ramps)n.dispose()}}function hi(e,t,n,o=!1){const r=gt.get(e);if(t&&jo.has(t.key)&&(t=null),!t){if(On(e),r){for(const f of r.ramps)f.dispose();gt.delete(e),e.needsUpdate=!0}return}if(r&&r.compiled.key===t.key){On(e),An(r,t,n);return}if(o){On(e);for(const u of r?.ramps??[])u.dispose();const f={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};An(f,t,n),gt.set(e,f),e.needsUpdate=!0;return}const a=kt.get(e);if(a&&a.binding.compiled.key===t.key){An(a.binding,t,n);return}On(e);const i={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};An(i,t,n),kt.set(e,{binding:i,started:!1})}function An(e,t,n){e.compiled=t;for(const[o,r]of t.uniforms){const a=typeof r=="number"?r:r.length===2?new Xt(...r):r.length===3?new x(...r):new kn(...r),i=e.uniforms[o];i?i.value=a:e.uniforms[o]={value:a}}for(const o of e.ramps)o.dispose();e.ramps=t.ramps.map(o=>{const r=di(o.table);return(e.uniforms[o.uniform]??={value:null}).value=r,r});for(const o of t.images){const r=n(o);if(o.tiled){const a=r!==null&&"tiles"in r?r:null;(e.uniforms[o.uniform]??={value:null}).value=a?.tiles??null,(e.uniforms[`${o.uniform}Map`]??={value:null}).value=a?.map??null}else(e.uniforms[o.uniform]??={value:null}).value=r!==null&&"tiles"in r?null:r}}function pi(e){const t=gt.get(e);return t?`${t.compiled.key}|${JSON.stringify(t.channels)}`:""}function gi(e){return Object.values(gt.get(e)?.channels??{})}function Bo(e,t){const n=new Set(["position","normal","uv"]);if(t.hasAttribute("tangent")&&n.add("tangent"),e.vertexColors&&n.add("color"),!(e instanceof an))return n;const o=t.userData.blenderUvChannels,r=a=>{const i=a===""?0:o?.[a]??9;n.add(i===0?"uv":`uv${i}`)};for(const a of[e.map,e.roughnessMap,e.normalMap])a&&r(a.userData.blenderUvName??"");for(const a of[gt.get(e),kt.get(e)?.binding])if(a){n.add("blenderOrco");for(const i of a.compiled.uvs)r(i);for(const i of a.compiled.attributes)n.add($t(i))}return n}function Qe(e,t){const n=t.userData.blenderUvChannels,o=t.getAttribute("position")?.count??0,r={};for(const a of e.uvs){let i=a===""?0:n?.[a];i===void 0&&(i=9,t.getAttribute("uv9")?.count!==o&&t.setAttribute("uv9",new ct(new Float32Array(o*2),2))),r[a]=i}return r}function vi(e,t,n,o,r,a,i){const f=wn.get(e);f&&++f.draws>1&&(f.shadow.dispose(),wn.delete(e));const u=kt.get(e);if(u&&!u.started){u.started=!0,u.binding.channels=Qe(u.binding.compiled,t);const c=i(e);gt.set(c,u.binding);const m=new Rt(t,c);m.castShadow=a.castShadow,m.receiveShadow=a.receiveShadow;const d=()=>{if(kt.get(e)!==u){c.dispose();return}kt.delete(e);for(const h of gt.get(e)?.ramps??[])h.dispose();gt.set(e,u.binding),e.needsUpdate=!0,wn.get(e)?.shadow.dispose(),wn.set(e,{shadow:c,draws:0}),ht()};n.compileAsync(m,r,o).then(d,d)}const _=gt.get(e);if(!_)return;const l=n.properties.get(e).currentProgram;if(l?.diagnostics?.runnable===!1&&l.cacheKey?.includes(_.compiled.key)){jo.add(_.compiled.key),gt.delete(e),e.needsUpdate=!0;const c=l.diagnostics.fragmentShader.log.split(`
7038
+ `).find(m=>m.startsWith("ERROR"))??"";console.warn(`Blender material "${e.name}": its node graph did not compile for WebGL, so it is drawn with its constant values. ${c}`);return}const s=Qe(_.compiled,t);JSON.stringify(s)!==JSON.stringify(_.channels)&&(_.channels=s,e.needsUpdate=!0)}function xi(e){const t=Array.isArray(e.material)?e.material:[e.material];if(!t.some(u=>u instanceof an&&gt.has(u)))return;const n=e.geometry,o=e.userData.blenderTexspace??null,r=n.getAttribute("position"),a=JSON.stringify([o,r?.version??0,r?.count??0]);!n.userData.blenderOrcoFromDoor&&n.userData.blenderOrcoStamp!==a&&(n.setAttribute("blenderOrco",bi(n,o)),n.userData.blenderOrcoStamp=a);const i=r?.count??0,f=e.userData.blenderDefaultColor;for(const u of t){const _=u instanceof an?gt.get(u):void 0;for(const l of _?.compiled.attributes??[]){const s=$t(l),c=l===""?f===void 0?void 0:n.getAttribute($t(f)):n.getAttribute(s);c&&c.count===i?n.getAttribute(s)!==c&&n.setAttribute(s,c):n.getAttribute(s)?.count!==i&&n.setAttribute(s,new ct(new Float32Array(i*4),4))}}}function bi(e,t){const n=e.getAttribute("position");let o,r;if(t)o=[...t[0]],r=[...t[1]];else{e.computeBoundingBox();const i=e.boundingBox;o=[(i.min.x+i.max.x)/2,(i.min.y+i.max.y)/2,(i.min.z+i.max.z)/2],r=[(i.max.x-i.min.x)/2,(i.max.y-i.min.y)/2,(i.max.z-i.min.z)/2]}r=r.map(i=>i===0?1:i);const a=new Float32Array(n.count*3);for(let i=0;i<n.count;i++)a[i*3]=(n.getX(i)-o[0])/r[0]*.5+.5,a[i*3+1]=(n.getY(i)-o[1])/r[1]*.5+.5,a[i*3+2]=(n.getZ(i)-o[2])/r[2]*.5+.5;return new ct(a,3)}function yi(e,t){const n=gt.get(e);if(!n)return;const{compiled:o,channels:r}=n;Object.assign(t.uniforms,n.uniforms,{blenderViewport:{value:Uo}});const a=p=>p===0?"uv":`uv${p}`,i=`varying vec3 vBlenderObjectPosition;
7039
7039
  varying vec3 vBlenderObjectNormal;
7040
7040
  varying vec3 vBlenderWorldPosition;
7041
7041
  varying vec3 vBlenderWorldNormal;
7042
7042
  varying vec3 vBlenderOrco;
7043
- ${o.attributes.map(p=>`varying vec4 ${me(p)};`).join(`
7043
+ ${o.attributes.map(p=>`varying vec4 ${de(p)};`).join(`
7044
7044
  `)}
7045
- ${o.uvs.map(p=>`varying vec2 ${Kt(p)};`).join(`
7046
- `)}`,f=o.attributes.map(p=>`attribute vec4 ${kt(p)};`).join(`
7045
+ ${o.uvs.map(p=>`varying vec2 ${Jt(p)};`).join(`
7046
+ `)}`,f=o.attributes.map(p=>`attribute vec4 ${$t(p)};`).join(`
7047
7047
  `);t.vertexShader=`attribute vec3 blenderOrco;
7048
7048
  ${f}
7049
7049
  ${i}
@@ -7056,9 +7056,9 @@ blenderWorldMatrix = modelMatrix * instanceMatrix;
7056
7056
  vBlenderWorldPosition = (blenderWorldMatrix * vec4(transformed, 1.0)).xyz;
7057
7057
  vBlenderWorldNormal = normalize(transpose(inverse(mat3(blenderWorldMatrix))) * objectNormal);
7058
7058
  vBlenderOrco = blenderOrco;
7059
- ${o.attributes.map(p=>`${me(p)} = ${kt(p)};`).join(`
7059
+ ${o.attributes.map(p=>`${de(p)} = ${$t(p)};`).join(`
7060
7060
  `)}
7061
- ${o.uvs.map(p=>`${Kt(p)} = ${a(r[p]??0)};`).join(`
7061
+ ${o.uvs.map(p=>`${Jt(p)} = ${a(r[p]??0)};`).join(`
7062
7062
  `)}
7063
7063
  #include <project_vertex>`);const u=p=>o.outputs[p]?.global,_=[];o.surface==="ShaderNodeEmission"?(_.push(["#include <color_fragment>","diffuseColor = vec4(0.0, 0.0, 0.0, 1.0);",!1]),_.push(["#include <emissivemap_fragment>",`totalEmissiveRadiance = ${u("Color")}.rgb * ${u("Strength")};`,!1]),_.push(["#include <opaque_fragment>","outgoingLight = totalEmissiveRadiance;",!0])):o.surface==="closure"?(_.push(["#include <color_fragment>","diffuseColor = vec4(0.0, 0.0, 0.0, 1.0);",!1]),_.push(["#include <emissivemap_fragment>","totalEmissiveRadiance = vec3(0.0);",!1])):(_.push(["#include <color_fragment>",`diffuseColor.rgb = ${u("Base Color")}.rgb;`,!1]),_.push(["#include <alphamap_fragment>",`diffuseColor.a = ${u("Alpha")};`,!1]),_.push(["#include <metalnessmap_fragment>",`roughnessFactor = ${u("Roughness")};`,!0]),_.push(["#include <metalnessmap_fragment>",`metalnessFactor = ${u("Metallic")};`,!1]),_.push(["#include <emissivemap_fragment>",`totalEmissiveRadiance = ${u("Emission Color")}.rgb * ${u("Emission Strength")};`,!1]),u("Normal")&&_.push(["#include <clearcoat_normal_fragment_begin>",`normal = normalize((viewMatrix * vec4(transpose(blender_from_three) * ${u("Normal")}, 0.0)).xyz);`,!0])),o.closure&&_.push(["#include <opaque_fragment>",`{
7064
7064
  float blenderCoverage = diffuseColor.a;
@@ -7070,13 +7070,13 @@ ${o.uvs.map(p=>`${Kt(p)} = ${a(r[p]??0)};`).join(`
7070
7070
  outgoingLight = blenderRadiance / max(blenderAlpha, 1e-4);
7071
7071
  #endif
7072
7072
  diffuseColor.a = blenderAlpha;
7073
- }`,!0]);const l=p=>p.replace(/^[ \t]*#include <(\w+)>/gm,(v,b)=>l(Ut[b]??"")),s=l(t.fragmentShader.slice(0,t.fragmentShader.indexOf("void main() {"))),c=new Map([...s.matchAll(/^[ \t]*#define[ \t]+(\w+).*$/gm)].map(p=>[p[1],p[0].trim()])),d=[...new Set([...o.declarations.matchAll(/^[ \t]*#define[ \t]+(\w+)/gm)].map(p=>p[1]))].filter(p=>c.has(p)),h=[...d.map(p=>`#undef ${p}`),o.declarations,...d.flatMap(p=>[`#undef ${p}`,c.get(p)])].join(`
7073
+ }`,!0]);const l=p=>p.replace(/^[ \t]*#include <(\w+)>/gm,(v,O)=>l(Wt[O]??"")),s=l(t.fragmentShader.slice(0,t.fragmentShader.indexOf("void main() {"))),c=new Map([...s.matchAll(/^[ \t]*#define[ \t]+(\w+).*$/gm)].map(p=>[p[1],p[0].trim()])),d=[...new Set([...o.declarations.matchAll(/^[ \t]*#define[ \t]+(\w+)/gm)].map(p=>p[1]))].filter(p=>c.has(p)),h=[...d.map(p=>`#undef ${p}`),o.declarations,...d.flatMap(p=>[`#undef ${p}`,c.get(p)])].join(`
7074
7074
  `);let g=t.fragmentShader.replace("void main() {",`${i}
7075
7075
  ${h}
7076
7076
  void main() {`).replace("#include <clipping_planes_fragment>",`#include <clipping_planes_fragment>
7077
- blenderGraph();`);for(const[p,v,b]of _){if(!g.includes(p))throw new Error(`three's physical shader has no ${p}`);g=g.replace(p,b?`${v}
7077
+ blenderGraph();`);for(const[p,v,O]of _){if(!g.includes(p))throw new Error(`three's physical shader has no ${p}`);g=g.replace(p,O?`${v}
7078
7078
  ${p}`:`${p}
7079
- ${v}`)}t.fragmentShader=g}const Vo=new Gt(1,1);function xi(e){e.getDrawingBufferSize(Vo)}function bi(e,t){const n=t.userData.blenderUvChannels;for(const o of[e.map,e.roughnessMap,e.normalMap]){if(!o)continue;const r=o.userData.blenderUvName;let a=r?n?.[r]:0;if(a===void 0){a=9;const i=t.getAttribute("position")?.count;if(i===void 0)throw new Error("A textured Blender draw has no positions");t.getAttribute("uv9")?.count!==i&&t.setAttribute("uv9",new lt(new Float32Array(i*2),2))}o.channel!==a&&(o.channel=a,e.needsUpdate=!0)}}class yi{constructor(){this.bindings=new Map}get(t,n,o,r,a=""){let i=this.bindings.get(t);if(!i||i.source!==n){this.delete(t),i={source:n,texture:n.clone(),version:-1,disposed:!1},this.bindings.set(t,i);const _=i;r&&r.then(()=>{_.disposed||(_.texture.needsUpdate=!0,_.version=n.version,ht())},()=>{})}const f=o==="REPEAT"?ra:o==="MIRROR"?ia:ho,u=i.texture.wrapS!==f||i.texture.wrapT!==f;return i.texture.wrapS=i.texture.wrapT=f,i.texture.userData.blenderUvName=a,n.image&&(u||i.version!==n.version)&&(i.texture.needsUpdate=!0,i.version=n.version),i.texture}delete(t){const n=this.bindings.get(t);n&&(n.disposed=!0,n.texture.dispose(),this.bindings.delete(t))}clear(){for(const t of this.bindings.keys())this.delete(t)}}const wt=N().finite(),Zn=L([wt,wt,wt]),wi=M({coat:wt,coat_roughness:wt,coat_ior:wt,coat_tint:Zn,sheen:wt,sheen_roughness:wt,sheen_tint:Zn,anisotropy:wt,anisotropy_rotation:wt,specular_level:wt,specular_tint:Zn,film_thickness:wt,film_ior:wt}).strict(),Oi={coat:0,coat_roughness:.03,coat_ior:1.5,coat_tint:[1,1,1],sheen:0,sheen_roughness:.5,sheen_tint:[1,1,1],anisotropy:0,anisotropy_rotation:0,specular_level:.5,specular_tint:[1,1,1],film_thickness:0,film_ior:1.33},on=new WeakMap;function Ti(e,t){on.has(e)||we(e),on.get(e).blenderWorldExtinction.value.copy(t)}function Ai(e){const t=new en,n=on.get(e);we(t),t.copy(e);const o=on.get(t);return n&&(o.blenderCoatIor.value=n.blenderCoatIor.value,o.blenderCoatTint.value.copy(n.blenderCoatTint.value),o.blenderMapClip.value=n.blenderMapClip.value,o.blenderRoughnessClip.value=n.blenderRoughnessClip.value,o.blenderNormalClip.value=n.blenderNormalClip.value,o.blenderWorldExtinction.value.copy(n.blenderWorldExtinction.value)),t}function we(e,t,n={}){const o=t??Oi;e.clearcoat=o.coat,e.clearcoatRoughness=o.coat_roughness,e.sheen=o.sheen,e.sheenRoughness=o.sheen_roughness,e.sheenColor.setRGB(...o.sheen_tint,vt),e.anisotropy=o.anisotropy,e.anisotropyRotation=o.anisotropy_rotation*Math.PI*2,e.specularIntensity=o.specular_level*2,e.specularColor.setRGB(...o.specular_tint,vt),e.iridescence=o.film_thickness>0?1:0,e.iridescenceIOR=o.film_ior,e.iridescenceThicknessRange=[o.film_thickness,o.film_thickness];let r=on.get(e);if(!r){r={blenderCoatIor:{value:1.5},blenderCoatTint:{value:new Ot(1,1,1)},blenderMapClip:{value:!1},blenderRoughnessClip:{value:!1},blenderNormalClip:{value:!1},blenderWorldExtinction:{value:new x}},on.set(e,r);const a=r;e.customProgramCacheKey=()=>`blender-principled-physical-v5${_i(e)}`,e.onBeforeRender=(i,f,u,_,l)=>{bi(e,_),hi(e,_,i,f,u,l,Ai),xi(i)},e.onBeforeCompile=i=>{const f=new Set([e.map,e.roughnessMap,e.normalMap].flatMap(d=>d?[d.channel]:[]).concat(di(e)));i.vertexShader=[...f].filter(d=>d>0).sort((d,h)=>d-h).map(d=>d<=3?`#ifndef USE_UV${d}
7079
+ ${v}`)}t.fragmentShader=g}const Uo=new Xt(1,1);function wi(e){e.getDrawingBufferSize(Uo)}function Oi(e,t){const n=t.userData.blenderUvChannels;for(const o of[e.map,e.roughnessMap,e.normalMap]){if(!o)continue;const r=o.userData.blenderUvName;let a=r?n?.[r]:0;if(a===void 0){a=9;const i=t.getAttribute("position")?.count;if(i===void 0)throw new Error("A textured Blender draw has no positions");t.getAttribute("uv9")?.count!==i&&t.setAttribute("uv9",new ct(new Float32Array(i*2),2))}o.channel!==a&&(o.channel=a,e.needsUpdate=!0)}}class Ai{constructor(){this.bindings=new Map}get(t,n,o,r,a=""){let i=this.bindings.get(t);if(!i||i.source!==n){this.delete(t),i={source:n,texture:n.clone(),version:-1,disposed:!1},this.bindings.set(t,i);const _=i;r&&r.then(()=>{_.disposed||(_.texture.needsUpdate=!0,_.version=n.version,ht())},()=>{})}const f=o==="REPEAT"?la:o==="MIRROR"?fa:vo,u=i.texture.wrapS!==f||i.texture.wrapT!==f;return i.texture.wrapS=i.texture.wrapT=f,i.texture.userData.blenderUvName=a,n.image&&(u||i.version!==n.version)&&(i.texture.needsUpdate=!0,i.version=n.version),i.texture}delete(t){const n=this.bindings.get(t);n&&(n.disposed=!0,n.texture.dispose(),this.bindings.delete(t))}clear(){for(const t of this.bindings.keys())this.delete(t)}}const wt=R().finite(),Qn=U([wt,wt,wt]),Ti=N({coat:wt,coat_roughness:wt,coat_ior:wt,coat_tint:Qn,sheen:wt,sheen_roughness:wt,sheen_tint:Qn,anisotropy:wt,anisotropy_rotation:wt,specular_level:wt,specular_tint:Qn,film_thickness:wt,film_ior:wt}).strict(),Si={coat:0,coat_roughness:.03,coat_ior:1.5,coat_tint:[1,1,1],sheen:0,sheen_roughness:.5,sheen_tint:[1,1,1],anisotropy:0,anisotropy_rotation:0,specular_level:.5,specular_tint:[1,1,1],film_thickness:0,film_ior:1.33},rn=new WeakMap;function Mi(e,t){rn.has(e)||Ae(e),rn.get(e).blenderWorldExtinction.value.copy(t)}function Pi(e){const t=new an,n=rn.get(e);Ae(t),t.copy(e);const o=rn.get(t);return n&&(o.blenderCoatIor.value=n.blenderCoatIor.value,o.blenderCoatTint.value.copy(n.blenderCoatTint.value),o.blenderMapClip.value=n.blenderMapClip.value,o.blenderRoughnessClip.value=n.blenderRoughnessClip.value,o.blenderNormalClip.value=n.blenderNormalClip.value,o.blenderWorldExtinction.value.copy(n.blenderWorldExtinction.value)),t}function Ae(e,t,n={}){const o=t??Si;e.clearcoat=o.coat,e.clearcoatRoughness=o.coat_roughness,e.sheen=o.sheen,e.sheenRoughness=o.sheen_roughness,e.sheenColor.setRGB(...o.sheen_tint,vt),e.anisotropy=o.anisotropy,e.anisotropyRotation=o.anisotropy_rotation*Math.PI*2,e.specularIntensity=o.specular_level*2,e.specularColor.setRGB(...o.specular_tint,vt),e.iridescence=o.film_thickness>0?1:0,e.iridescenceIOR=o.film_ior,e.iridescenceThicknessRange=[o.film_thickness,o.film_thickness];let r=rn.get(e);if(!r){r={blenderCoatIor:{value:1.5},blenderCoatTint:{value:new Ot(1,1,1)},blenderMapClip:{value:!1},blenderRoughnessClip:{value:!1},blenderNormalClip:{value:!1},blenderWorldExtinction:{value:new x}},rn.set(e,r);const a=r;e.customProgramCacheKey=()=>`blender-principled-physical-v5${pi(e)}`,e.onBeforeRender=(i,f,u,_,l)=>{Oi(e,_),vi(e,_,i,f,u,l,Pi),wi(i)},e.onBeforeCompile=i=>{const f=new Set([e.map,e.roughnessMap,e.normalMap].flatMap(d=>d?[d.channel]:[]).concat(gi(e)));i.vertexShader=[...f].filter(d=>d>0).sort((d,h)=>d-h).map(d=>d<=3?`#ifndef USE_UV${d}
7080
7080
  attribute vec2 uv${d};
7081
7081
  #endif`:`attribute vec2 uv${d};`).join(`
7082
7082
  `)+`
@@ -7091,16 +7091,16 @@ attribute vec2 uv${d};
7091
7091
  if (clipImage && (any(lessThan(uv, vec2(0.0))) || any(greaterThan(uv, vec2(1.0))))) pixel = vec4(0.0);
7092
7092
  return pixel;
7093
7093
  }
7094
- `+i.fragmentShader;const u=Ut.lights_physical_fragment.replace("material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );","material.specularF90 = 1.0;").replace("material.clearcoatF0 = vec3( 0.04 );","material.clearcoatF0 = vec3( pow2( ( blenderCoatIor - 1.0 ) / ( blenderCoatIor + 1.0 ) ) );"),_=Ut.normal_fragment_maps.replace("normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;","vec3 blenderBaseNormal = normal; normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; normal.y *= normalScale.y < 0.0 ? -1.0 : 1.0;").replace("normal = normalize( normalMatrix * normal );","normal = normalize(mix(blenderBaseNormal, normalize(normalMatrix * normal), max(0.0, normalScale.x)));").replace("mapN.xy *= normalScale;","mapN.xy *= normalScale; mapN.z = mix(1.0, mapN.z, clamp(normalScale.x, 0.0, 1.0));").replaceAll("texture2D( normalMap, vNormalMapUv )","blenderImageSample(normalMap, vNormalMapUv, blenderNormalClip)"),l=Ut.map_fragment.replace("texture2D( map, vMapUv )","blenderImageSample(map, vMapUv, blenderMapClip)").replace("diffuseColor *= sampledDiffuseColor;","diffuseColor.rgb *= sampledDiffuseColor.rgb;"),s=Ut.roughnessmap_fragment.replace("texture2D( roughnessMap, vRoughnessMapUv )","blenderImageSample(roughnessMap, vRoughnessMapUv, blenderRoughnessClip)"),c=Ut.lights_fragment_begin.replace("getPointLightInfo( pointLight, geometryPosition, directLight );","getPointLightInfo( pointLight, geometryPosition, directLight ); directLight.color *= exp(-blenderWorldExtinction * length(pointLight.position-geometryPosition));").replace("getSpotLightInfo( spotLight, geometryPosition, directLight );","getSpotLightInfo( spotLight, geometryPosition, directLight ); directLight.color *= exp(-blenderWorldExtinction * length(spotLight.position-geometryPosition));").replace("getDirectionalLightInfo( directionalLight, directLight );","getDirectionalLightInfo( directionalLight, directLight ); directLight.color *= blenderInfiniteTransmission();").replace("rectAreaLight = rectAreaLights[ i ];","rectAreaLight = rectAreaLights[ i ]; rectAreaLight.color *= exp(-blenderWorldExtinction * length(rectAreaLight.position-geometryPosition));").replace("getAmbientLightIrradiance( ambientLightColor )","getAmbientLightIrradiance( ambientLightColor ) * blenderInfiniteTransmission()"),m=Ut.lights_fragment_maps.replaceAll(/(getIBL(?:Irradiance|Radiance|AnisotropyRadiance)\([^;]+\))/g,"$1 * blenderInfiniteTransmission()");i.fragmentShader=i.fragmentShader.replace("#include <lights_physical_fragment>",u).replace("#include <lights_fragment_begin>",c).replace("#include <lights_fragment_maps>",m).replace("#include <normal_fragment_maps>",_).replace("#include <map_fragment>",l).replace("#include <roughnessmap_fragment>",s).replace("vec3 Fcc = F_Schlick",`
7094
+ `+i.fragmentShader;const u=Wt.lights_physical_fragment.replace("material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );","material.specularF90 = 1.0;").replace("material.clearcoatF0 = vec3( 0.04 );","material.clearcoatF0 = vec3( pow2( ( blenderCoatIor - 1.0 ) / ( blenderCoatIor + 1.0 ) ) );"),_=Wt.normal_fragment_maps.replace("normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;","vec3 blenderBaseNormal = normal; normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; normal.y *= normalScale.y < 0.0 ? -1.0 : 1.0;").replace("normal = normalize( normalMatrix * normal );","normal = normalize(mix(blenderBaseNormal, normalize(normalMatrix * normal), max(0.0, normalScale.x)));").replace("mapN.xy *= normalScale;","mapN.xy *= normalScale; mapN.z = mix(1.0, mapN.z, clamp(normalScale.x, 0.0, 1.0));").replaceAll("texture2D( normalMap, vNormalMapUv )","blenderImageSample(normalMap, vNormalMapUv, blenderNormalClip)"),l=Wt.map_fragment.replace("texture2D( map, vMapUv )","blenderImageSample(map, vMapUv, blenderMapClip)").replace("diffuseColor *= sampledDiffuseColor;","diffuseColor.rgb *= sampledDiffuseColor.rgb;"),s=Wt.roughnessmap_fragment.replace("texture2D( roughnessMap, vRoughnessMapUv )","blenderImageSample(roughnessMap, vRoughnessMapUv, blenderRoughnessClip)"),c=Wt.lights_fragment_begin.replace("getPointLightInfo( pointLight, geometryPosition, directLight );","getPointLightInfo( pointLight, geometryPosition, directLight ); directLight.color *= exp(-blenderWorldExtinction * length(pointLight.position-geometryPosition));").replace("getSpotLightInfo( spotLight, geometryPosition, directLight );","getSpotLightInfo( spotLight, geometryPosition, directLight ); directLight.color *= exp(-blenderWorldExtinction * length(spotLight.position-geometryPosition));").replace("getDirectionalLightInfo( directionalLight, directLight );","getDirectionalLightInfo( directionalLight, directLight ); directLight.color *= blenderInfiniteTransmission();").replace("rectAreaLight = rectAreaLights[ i ];","rectAreaLight = rectAreaLights[ i ]; rectAreaLight.color *= exp(-blenderWorldExtinction * length(rectAreaLight.position-geometryPosition));").replace("getAmbientLightIrradiance( ambientLightColor )","getAmbientLightIrradiance( ambientLightColor ) * blenderInfiniteTransmission()"),m=Wt.lights_fragment_maps.replaceAll(/(getIBL(?:Irradiance|Radiance|AnisotropyRadiance)\([^;]+\))/g,"$1 * blenderInfiniteTransmission()");i.fragmentShader=i.fragmentShader.replace("#include <lights_physical_fragment>",u).replace("#include <lights_fragment_begin>",c).replace("#include <lights_fragment_maps>",m).replace("#include <normal_fragment_maps>",_).replace("#include <map_fragment>",l).replace("#include <roughnessmap_fragment>",s).replace("vec3 Fcc = F_Schlick",`
7095
7095
  // Blender's slab_transmittance_at_angle (gpu_shader_material_principled.glsl):
7096
7096
  // Beer-Lambert attenuation through a refracting coat at this view angle.
7097
7097
  float coatPath = blenderCoatIor * inversesqrt(max(1e-8,
7098
7098
  blenderCoatIor * blenderCoatIor - (1.0 - dotNVcc * dotNVcc)));
7099
7099
  outgoingLight *= mix(vec3(1.0), pow(max(blenderCoatTint, vec3(0.0)), vec3(coatPath)), material.clearcoat);
7100
- vec3 Fcc = F_Schlick`),vi(e,i)},e.needsUpdate=!0}r.blenderCoatIor.value=Math.max(1,o.coat_ior),r.blenderCoatTint.value.setRGB(...o.coat_tint,vt),r.blenderMapClip.value=n.map===!0,r.blenderRoughnessClip.value=n.roughness===!0,r.blenderNormalClip.value=n.normal===!0}function Oe(e){const t=r=>{if(!(!r||typeof r!="object")){if("kind"in r&&["direction","window","sky"].includes(String(r.kind)))throw new Error(`World volume spatial input ${r.kind} is not implemented`);for(const a of Object.values(r))t(a)}};t(e);const n=at(e)(new x);if(!(typeof n=="number"?[n]:n.toArray()).every(Number.isFinite))throw new Error("World volume input is not finite");return n}function Yt(e){const t=Oe(e);if(typeof t!="number")throw new Error("World volume scalar input resolved to a color");return Math.max(0,t)}function Tn(e){const t=Oe(e);return(typeof t=="number"?new x().setScalar(t):t.clone()).max(new x)}function Si(e){if(e<800)return new x(5.413294490189271,0,0);if(e>=12e3)return new x(.8262954810464208,.9945080501520986,1.566307710274283);const t=[965,1167,1449,1902,3315,6365].filter(a=>e>=a).length,n=[[1619.19106,-.00205010916,5.02995757],[2488.45471,-.00111330907,3.22621544],[3341.43193,-.000486551192,1.76486769],[4094.61742,-.000127446582,.725731635],[4670.28036,291258199e-13,.126703442],[4595.09185,287495649e-13,.15034502],[3787.1745,935907826e-14,.399075871]][t],o=[[-488.999748,.000604330754,-.0755807526],[-755.994277,.000316730098,.478306139],[-1023.63977,.00012022347,.936662319],[-1265.71316,487340896e-14,1.27054498],[-1425.29332,-401150431e-13,1.43972784],[-1175.54822,-216378048e-13,1.30408023],[-500.799571,-459832026e-14,1.09098763]][t],r=[[596945309e-19,-485742887e-16,-970622247e-13,-.00407936148],[240430366e-19,555021075e-16,-.000198503712,.0289312858],[-140949732e-19,189878968e-15,-.000356632824,.0910767778],[-361460868e-19,284822009e-15,-.000493211319,.15672344],[-197075738e-19,175359352e-15,-.000250542825,-.0222783266],[-161997957e-21,-164216008e-16,.000386216271,-.738077418],[672650283e-21,-273078809e-16,.000424098264,-.752335691]][t];return new x(n[0]/e+n[1]*e+n[2],o[0]/e+o[1]*e+o[2],((r[0]*e+r[1])*e+r[2])*e+r[3]).max(new x)}function Ze(e){if(!e?.volume?.length)return null;const t={extinction:new x,emission:new x,lobes:[]};for(const n of e.volume){const o=Yt(n.weight);if(o===0)continue;const r=Tn(n.color),a=Yt(n.density),i=new x,f=new x;if(n.kind==="absorption"&&i.set(1-r.x,1-r.y,1-r.z).max(new x).multiplyScalar(a),n.kind==="scatter"||n.kind==="principled"){f.copy(r).multiplyScalar(a);const u=n.kind==="principled"?"HENYEY_GREENSTEIN":n.phase;if(!["HENYEY_GREENSTEIN","DRAINE","RAYLEIGH"].includes(u))throw new Error(`World volume ${u} phase is not implemented`);const _=Oe(n.anisotropy);if(typeof _!="number")throw new Error("World volume anisotropy must be scalar");t.lobes.push({coefficient:f.clone().multiplyScalar(o),g:u==="RAYLEIGH"?0:bt.clamp(_,-.999,.999),alpha:u==="RAYLEIGH"?1:u==="DRAINE"?Yt(n.alpha):0})}if(n.kind==="principled"){const u=Tn(n.absorption_color);i.set(Math.max(1-r.x,0)*Math.max(1-Math.sqrt(u.x),0),Math.max(1-r.y,0)*Math.max(1-Math.sqrt(u.y),0),Math.max(1-r.z,0)*Math.max(1-Math.sqrt(u.z),0)).multiplyScalar(a);const _=Yt(n.blackbody_intensity);if(_>.001){const l=Yt(n.temperature),s=5670373e-20/Math.PI*(1+_*(l**4-1));t.emission.add(Si(l).multiply(Tn(n.blackbody_tint)).multiplyScalar(s*o))}}(n.kind==="principled"||n.kind==="emission")&&t.emission.add((n.kind==="emission"?r:Tn(n.emission_color)).multiplyScalar(Yt(n.emission_strength)*o)),t.extinction.add(i.add(f).multiplyScalar(o))}for(const n of["x","y","z"])if(t.extinction[n]===0&&t.emission[n]>0)throw new Error("Unbounded emissive World volume with zero extinction has divergent radiance");return t}class Mi{constructor(t){this.medium=t,this.target=new sa(1,1,{type:he,depthBuffer:!1}),this.geometry=new po(2,2),this.scene=new la,this.camera=new fa}render(t,n,o,r){if(!n.depthTexture)throw new Error("World volume render requires surface depth");const a={surface:{value:n.texture},depth:{value:n.depthTexture},inverseProjection:{value:r.projectionMatrixInverse},cameraWorld:{value:r.matrixWorld},orthographic:{value:r.isOrthographicCamera===!0},sigma:{value:this.medium.extinction},emission:{value:this.medium.emission}};let i="",f="",u=0,_=2;o.traverseVisible(m=>{if(!(m instanceof te||m instanceof ne||m instanceof Pn))return;const d=m,h=u++,g=d.getWorldPosition(new x);a[`lp${h}`]={value:g},a[`lc${h}`]={value:d.color.clone().multiplyScalar(d.intensity)},i+=`uniform vec3 lp${h}, lc${h};
7101
- `;let p="1.0",v="1.0";if(d instanceof ne&&(a[`ld${h}`]={value:d.target.getWorldPosition(new x).sub(g).normalize()},a[`cone${h}`]={value:new Gt(Math.cos(d.angle),Math.cos(d.angle*(1-d.penumbra)))},i+=`uniform vec3 ld${h}; uniform vec2 cone${h};
7102
- `,v=`smoothstep(cone${h}.x, max(cone${h}.x+1e-6,cone${h}.y),dot(-L,ld${h}))`),!(d instanceof Pn)&&d.castShadow&&d.shadow.map){if(++_>t.capabilities.maxTextures)throw new Error("World volume shadow samplers exceed this GPU texture-unit limit");a[`sm${h}`]={value:d.shadow.map.texture},a[`sx${h}`]={value:d.shadow.matrix},a[`ss${h}`]={value:d.shadow.mapSize},a[`sb${h}`]={value:d.shadow.bias},a[`sn${h}`]={value:d.shadow.camera.near},a[`sf${h}`]={value:d.shadow.camera.far},i+=`uniform sampler2D sm${h}; uniform mat4 sx${h}; uniform vec2 ss${h}; uniform float sb${h},sn${h},sf${h};
7103
- `,p=d instanceof te?`getPointShadow(sm${h},ss${h},1.0,sb${h},1.0,sx${h}*vec4(p,1.0),sn${h},sf${h})`:`getShadow(sm${h},ss${h},1.0,sb${h},1.0,sx${h}*vec4(p,1.0))`}if(d instanceof Pn){const b=new B().extractRotation(d.matrixWorld);a[`lx${h}`]={value:new x(d.width,0,0).applyMatrix4(b)},a[`ly${h}`]={value:new x(0,d.height,0).applyMatrix4(b)},a[`ln${h}`]={value:new x(0,0,-1).transformDirection(b)},i+=`uniform vec3 lx${h},ly${h},ln${h};
7100
+ vec3 Fcc = F_Schlick`),yi(e,i)},e.needsUpdate=!0}r.blenderCoatIor.value=Math.max(1,o.coat_ior),r.blenderCoatTint.value.setRGB(...o.coat_tint,vt),r.blenderMapClip.value=n.map===!0,r.blenderRoughnessClip.value=n.roughness===!0,r.blenderNormalClip.value=n.normal===!0}function Te(e){const t=r=>{if(!(!r||typeof r!="object")){if("kind"in r&&["direction","window","sky"].includes(String(r.kind)))throw new Error(`World volume spatial input ${r.kind} is not implemented`);for(const a of Object.values(r))t(a)}};t(e);const n=it(e)(new x);if(!(typeof n=="number"?[n]:n.toArray()).every(Number.isFinite))throw new Error("World volume input is not finite");return n}function Zt(e){const t=Te(e);if(typeof t!="number")throw new Error("World volume scalar input resolved to a color");return Math.max(0,t)}function Tn(e){const t=Te(e);return(typeof t=="number"?new x().setScalar(t):t.clone()).max(new x)}function Ei(e){if(e<800)return new x(5.413294490189271,0,0);if(e>=12e3)return new x(.8262954810464208,.9945080501520986,1.566307710274283);const t=[965,1167,1449,1902,3315,6365].filter(a=>e>=a).length,n=[[1619.19106,-.00205010916,5.02995757],[2488.45471,-.00111330907,3.22621544],[3341.43193,-.000486551192,1.76486769],[4094.61742,-.000127446582,.725731635],[4670.28036,291258199e-13,.126703442],[4595.09185,287495649e-13,.15034502],[3787.1745,935907826e-14,.399075871]][t],o=[[-488.999748,.000604330754,-.0755807526],[-755.994277,.000316730098,.478306139],[-1023.63977,.00012022347,.936662319],[-1265.71316,487340896e-14,1.27054498],[-1425.29332,-401150431e-13,1.43972784],[-1175.54822,-216378048e-13,1.30408023],[-500.799571,-459832026e-14,1.09098763]][t],r=[[596945309e-19,-485742887e-16,-970622247e-13,-.00407936148],[240430366e-19,555021075e-16,-.000198503712,.0289312858],[-140949732e-19,189878968e-15,-.000356632824,.0910767778],[-361460868e-19,284822009e-15,-.000493211319,.15672344],[-197075738e-19,175359352e-15,-.000250542825,-.0222783266],[-161997957e-21,-164216008e-16,.000386216271,-.738077418],[672650283e-21,-273078809e-16,.000424098264,-.752335691]][t];return new x(n[0]/e+n[1]*e+n[2],o[0]/e+o[1]*e+o[2],((r[0]*e+r[1])*e+r[2])*e+r[3]).max(new x)}function Ke(e){if(!e?.volume?.length)return null;const t={extinction:new x,emission:new x,lobes:[]};for(const n of e.volume){const o=Zt(n.weight);if(o===0)continue;const r=Tn(n.color),a=Zt(n.density),i=new x,f=new x;if(n.kind==="absorption"&&i.set(1-r.x,1-r.y,1-r.z).max(new x).multiplyScalar(a),n.kind==="scatter"||n.kind==="principled"){f.copy(r).multiplyScalar(a);const u=n.kind==="principled"?"HENYEY_GREENSTEIN":n.phase;if(!["HENYEY_GREENSTEIN","DRAINE","RAYLEIGH"].includes(u))throw new Error(`World volume ${u} phase is not implemented`);const _=Te(n.anisotropy);if(typeof _!="number")throw new Error("World volume anisotropy must be scalar");t.lobes.push({coefficient:f.clone().multiplyScalar(o),g:u==="RAYLEIGH"?0:bt.clamp(_,-.999,.999),alpha:u==="RAYLEIGH"?1:u==="DRAINE"?Zt(n.alpha):0})}if(n.kind==="principled"){const u=Tn(n.absorption_color);i.set(Math.max(1-r.x,0)*Math.max(1-Math.sqrt(u.x),0),Math.max(1-r.y,0)*Math.max(1-Math.sqrt(u.y),0),Math.max(1-r.z,0)*Math.max(1-Math.sqrt(u.z),0)).multiplyScalar(a);const _=Zt(n.blackbody_intensity);if(_>.001){const l=Zt(n.temperature),s=5670373e-20/Math.PI*(1+_*(l**4-1));t.emission.add(Ei(l).multiply(Tn(n.blackbody_tint)).multiplyScalar(s*o))}}(n.kind==="principled"||n.kind==="emission")&&t.emission.add((n.kind==="emission"?r:Tn(n.emission_color)).multiplyScalar(Zt(n.emission_strength)*o)),t.extinction.add(i.add(f).multiplyScalar(o))}for(const n of["x","y","z"])if(t.extinction[n]===0&&t.emission[n]>0)throw new Error("Unbounded emissive World volume with zero extinction has divergent radiance");return t}class Ni{constructor(t){this.medium=t,this.target=new ca(1,1,{type:ge,depthBuffer:!1}),this.geometry=new xo(2,2),this.scene=new ua,this.camera=new ma}render(t,n,o,r){if(!n.depthTexture)throw new Error("World volume render requires surface depth");const a={surface:{value:n.texture},depth:{value:n.depthTexture},inverseProjection:{value:r.projectionMatrixInverse},cameraWorld:{value:r.matrixWorld},orthographic:{value:r.isOrthographicCamera===!0},sigma:{value:this.medium.extinction},emission:{value:this.medium.emission}};let i="",f="",u=0,_=2;o.traverseVisible(m=>{if(!(m instanceof ee||m instanceof oe||m instanceof En))return;const d=m,h=u++,g=d.getWorldPosition(new x);a[`lp${h}`]={value:g},a[`lc${h}`]={value:d.color.clone().multiplyScalar(d.intensity)},i+=`uniform vec3 lp${h}, lc${h};
7101
+ `;let p="1.0",v="1.0";if(d instanceof oe&&(a[`ld${h}`]={value:d.target.getWorldPosition(new x).sub(g).normalize()},a[`cone${h}`]={value:new Xt(Math.cos(d.angle),Math.cos(d.angle*(1-d.penumbra)))},i+=`uniform vec3 ld${h}; uniform vec2 cone${h};
7102
+ `,v=`smoothstep(cone${h}.x, max(cone${h}.x+1e-6,cone${h}.y),dot(-L,ld${h}))`),!(d instanceof En)&&d.castShadow&&d.shadow.map){if(++_>t.capabilities.maxTextures)throw new Error("World volume shadow samplers exceed this GPU texture-unit limit");a[`sm${h}`]={value:d.shadow.map.texture},a[`sx${h}`]={value:d.shadow.matrix},a[`ss${h}`]={value:d.shadow.mapSize},a[`sb${h}`]={value:d.shadow.bias},a[`sn${h}`]={value:d.shadow.camera.near},a[`sf${h}`]={value:d.shadow.camera.far},i+=`uniform sampler2D sm${h}; uniform mat4 sx${h}; uniform vec2 ss${h}; uniform float sb${h},sn${h},sf${h};
7103
+ `,p=d instanceof ee?`getPointShadow(sm${h},ss${h},1.0,sb${h},1.0,sx${h}*vec4(p,1.0),sn${h},sf${h})`:`getShadow(sm${h},ss${h},1.0,sb${h},1.0,sx${h}*vec4(p,1.0))`}if(d instanceof En){const O=new H().extractRotation(d.matrixWorld);a[`lx${h}`]={value:new x(d.width,0,0).applyMatrix4(O)},a[`ly${h}`]={value:new x(0,d.height,0).applyMatrix4(O)},a[`ln${h}`]={value:new x(0,0,-1).transformDirection(O)},i+=`uniform vec3 lx${h},ly${h},ln${h};
7104
7104
  `,f+=`for(int ax=0;ax<4;ax++) for(int ay=0;ay<4;ay++) {
7105
7105
  vec3 delta=lp${h}+lx${h}*((float(ax)+.5)/4.-.5)+ly${h}*((float(ay)+.5)/4.-.5)-p;
7106
7106
  float d=length(delta); vec3 L=delta/max(d,1e-6);
@@ -7111,7 +7111,7 @@ attribute vec2 uv${d};
7111
7111
  float cutoff=cut${h}>0.?pow(clamp(1.-pow(d/cut${h},4.),0.,1.),2.):1.;
7112
7112
  sum+=lc${h}*exp(-sigma*d)*phase(dot(L,ray))*${v}*${p}*cutoff/max(pow(d,decay${h}),.01); }
7113
7113
  `});let l="vec3 result=vec3(0.);";this.medium.lobes.forEach((m,d)=>{a[`scatter${d}`]={value:m.coefficient},a[`g${d}`]={value:m.g},a[`a${d}`]={value:m.alpha},i+=`uniform vec3 scatter${d}; uniform float g${d},a${d};
7114
- `,l+=`result+=scatter${d}*(1.-g${d}*g${d})*(1.+a${d}*c*c)/(12.56637061436*(1.+a${d}*(1.+2.*g${d}*g${d})/3.)*pow(1.+g${d}*g${d}-2.*g${d}*c,1.5));`});const s=this.medium.extinction.toArray().filter(m=>m>0);a.range={value:s.length?20/Math.min(...s):1},this.material?.dispose(),this.material=new de({uniforms:a,depthTest:!1,depthWrite:!1,toneMapped:!1,defines:{USE_SHADOWMAP:"",NUM_DIR_LIGHT_SHADOWS:0,NUM_SPOT_LIGHT_SHADOWS:0,NUM_POINT_LIGHT_SHADOWS:0,NUM_SPOT_LIGHT_COORDS:0},vertexShader:"varying vec2 vUv; void main(){vUv=uv;gl_Position=vec4(position.xy,0.,1.);}",fragmentShader:`
7114
+ `,l+=`result+=scatter${d}*(1.-g${d}*g${d})*(1.+a${d}*c*c)/(12.56637061436*(1.+a${d}*(1.+2.*g${d}*g${d})/3.)*pow(1.+g${d}*g${d}-2.*g${d}*c,1.5));`});const s=this.medium.extinction.toArray().filter(m=>m>0);a.range={value:s.length?20/Math.min(...s):1},this.material?.dispose(),this.material=new pe({uniforms:a,depthTest:!1,depthWrite:!1,toneMapped:!1,defines:{USE_SHADOWMAP:"",NUM_DIR_LIGHT_SHADOWS:0,NUM_SPOT_LIGHT_SHADOWS:0,NUM_POINT_LIGHT_SHADOWS:0,NUM_SPOT_LIGHT_COORDS:0},vertexShader:"varying vec2 vUv; void main(){vUv=uv;gl_Position=vec4(position.xy,0.,1.);}",fragmentShader:`
7115
7115
  #include <common>
7116
7116
  #include <packing>
7117
7117
  #include <shadowmap_pars_fragment>
@@ -7141,10 +7141,10 @@ attribute vec2 uv${d};
7141
7141
  radiance+=incident(origin+ray*t,ray)*exp(-sigma*t)*(hi-lo);
7142
7142
  }
7143
7143
  gl_FragColor=vec4(radiance,base.a+(1.-base.a)*(1.-dot(tr,vec3(1./3.))));
7144
- }`}),this.scene.clear(),this.scene.add(new Rt(this.geometry,this.material)),this.target.setSize(n.width,n.height);const c=t.getRenderTarget();try{t.setRenderTarget(this.target),t.render(this.scene,this.camera)}finally{t.setRenderTarget(c)}return this.target}dispose(){this.material?.dispose(),this.geometry.dispose(),this.target.dispose(),this.scene.clear()}}const Pi=M({object:R(),group:R(),groupIndex:N().int().nonnegative(),count:N().int().nonnegative(),digest:R(),alertMode:H(["NONE","ACTIVE","ALL"]),unchanged:q(!0).optional(),weightsBase64:R().optional(),alertBase64:R().optional()}).strict();function Ei(e){const n=e<0?0:e>1?1:e,o=(.5+.5*n)**1.5,[r,a,i]=Ni(2/3*(1-n)),f=new Ot;return f.setRGB((r*o)**(1/1.5),(a*o)**(1/1.5),(i*o)**(1/1.5),$t),f}function Ni(e){const t=(e%1+1)%1,n=Math.floor(t*6),o=t*6-n;switch(n%6){case 0:return[1,o,0];case 1:return[1-o,1,0];case 2:return[0,1,o];case 3:return[0,1-o,1];case 4:return[o,0,1];default:return[1,0,1-o]}}const Ri=0;function Qe(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}class Ii{constructor(){this.group=new it,this.mesh=null,this.material=null,this.geometry=null,this.held=null,this.signature="",this.group.name="BlenderWeightOverlay"}apply(t,n,o){if(t===null||n===null||!n.isMesh||o===null)return this.clear(),this.signature="",null;const r=`${t.object}:${t.group}`;if(t.unchanged===!0){if(this.held?.key!==r)return this.clear(),`weights: the session sent a reference to ${r} that this overlay does not hold; the colours reappear on the next change to the mesh or the group`}else{if(t.weightsBase64===void 0||t.alertBase64===void 0)return this.clear(),`weights: ${r} carried neither an array nor a reference`;const d=Qe(t.weightsBase64);this.held={key:r,weights:new Float32Array(d.buffer,d.byteOffset,t.count),alerts:Qe(t.alertBase64)}}const a=this.held;if(a===null)return null;const i=`${r}:${t.digest}:${n.geometry.uuid}:${t.alertMode}:${o.elements.join(",")}`;if(i===this.signature&&this.mesh!==null)return null;this.signature=i,this.clear();const f=n.geometry.clone(),u=f.getAttribute("position"),_=f.getAttribute("blenderVertex");if(_===void 0)return f.dispose(),"weights: the presented geometry carries no per-vertex Blender index (`blenderVertex`), so the weights cannot be laid over it";const l=new Float32Array(u.count*3),s=new Ot().setHex(Ri,$t);for(let d=0;d<u.count;d++){const h=_.getX(d),p=t.alertMode!=="NONE"&&a.alerts[h]===1?s:Ei(a.weights[h]??0);l[d*3]=p.r,l[d*3+1]=p.g,l[d*3+2]=p.b}f.setAttribute("color",new lt(l,3)),f.deleteAttribute("blenderVertex");const c=new Rn({vertexColors:!0,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1}),m=new Rt(f,c);return m.name=`${t.object}:weights`,m.frustumCulled=!1,m.matrixAutoUpdate=!1,m.matrix.copy(o),m.matrix.decompose(m.position,m.quaternion,m.scale),this.geometry=f,this.material=c,this.mesh=m,this.group.add(m),null}clear(){this.mesh&&this.group.remove(this.mesh),this.geometry?.dispose(),this.material?.dispose(),this.mesh=null,this.geometry=null,this.material=null}dispose(){this.clear(),this.held=null,this.signature=""}}const An=N().finite(),zi=D(L([An,An,An,An])).length(4),Fi=20,Ke=[16724818,9165824,2658559];function Di(e){const t=n=>Math.min(255,Math.max(0,Math.floor(.75*n+63.75)-60))/255;return new Ot().setRGB(t(e>>16&255),t(e>>8&255),t(e&255),$t)}function jo(){return new ua({vertexColors:!0,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1})}function Ci(){const e=[],t=[],n=new Ot(0,0,0),o=(a,i,f,u,_)=>{for(const l of[a,i]){const s=[0,0,0];s[f]=l*u,e.push(...s),t.push(_.r,_.g,_.b)}};for(let a=0;a<3;a++){const i=new Ot().setHex(Ke[a],$t);o(1,.85,a,1,i),o(.85,.25,a,1,n),o(1,.85,a,-1,Di(Ke[a])),o(.85,.25,a,-1,n)}const r=new an;return r.setAttribute("position",new Mt(e,3)),r.setAttribute("color",new Mt(t,3)),new go(r,jo())}function ki(){const t=[],n=[],o=new Ot(1,0,0),r=new Ot(1,1,1);for(let i=0;i<12;i++){const f=(i+1)%2===0?r:o;for(const u of[i,i+1]){const _=2*Math.PI*u/12;t.push(.5*Math.cos(_),.5*Math.sin(_),0),n.push(f.r,f.g,f.b)}}const a=new an;return a.setAttribute("position",new Mt(t,3)),a.setAttribute("color",new Mt(n,3)),new go(a,jo())}class $i{constructor(){this.group=new it,this.anchor=new it,this.lines=Ci(),this.circle=ki(),this.seen=null,this.size=new Gt,this.scratch=new x,this.parentQuat=new Tt,this.group.name="BlenderCursor",this.present(!1),this.anchor.matrixAutoUpdate=!1,this.group.add(this.anchor,this.circle),this.anchor.add(this.lines);for(const t of[this.lines,this.circle])t.renderOrder=1001,t.frustumCulled=!1;this.lines.onBeforeRender=(t,n,o)=>this.fit(t,o),this.circle.onBeforeRender=(t,n,o)=>this.fit(t,o)}apply(t){if(t===void 0){this.present(!1);return}this.anchor.matrix.set(...t.flat()),this.anchor.updateMatrixWorld(!0),this.present(!0)}present(t){this.anchor.visible=t,this.circle.visible=t}show(t){const[n,o,r,a]=t.rotation;this.anchor.matrix.compose(new x(...t.location),new Tt(o,r,a,n),new x(1,1,1)),this.anchor.updateMatrixWorld(!0),this.present(!0)}fit(t,n){this.seen={camera:n,canvas:t.domElement},t.getSize(this.size);const o=Math.max(this.size.y,1),r=this.scratch.setFromMatrixPosition(this.anchor.matrixWorld);let a;if(n.isOrthographicCamera){const f=n;a=(f.top-f.bottom)/f.zoom/o}else{const f=n;a=2*Math.max(-r.applyMatrix4(n.matrixWorldInverse).z,1e-6)*Math.tan(bt.degToRad(f.fov)/2)/f.zoom/o}const i=a*Fi;this.lines.scale.setScalar(i),this.lines.updateMatrixWorld(!0),this.circle.position.setFromMatrixPosition(this.anchor.matrix),this.group.getWorldQuaternion(this.parentQuat).invert(),n.getWorldQuaternion(this.circle.quaternion).premultiply(this.parentQuat),this.circle.scale.setScalar(i),this.circle.updateMatrixWorld(!0)}placementAt(t,n,o,r,a){const i=this.seen;if(i===null||o!==i.canvas)return null;const f=i.canvas.getBoundingClientRect(),u=new Gt((t-f.left)/Math.max(f.width,1)*2-1,-((n-f.top)/Math.max(f.height,1))*2+1),_=new ca;_.setFromCamera(u,i.camera);const l=h=>{for(let g=h;g!==null;g=g.parent)if(!g.visible)return!1;return!0},s=_.intersectObject(r,!0).find(h=>h.object.isMesh&&a(h.object)&&l(h.object));let c=s?s.point.clone():null;if(c===null){const h=new x().setFromMatrixPosition(this.anchor.matrixWorld),g=i.camera.getWorldDirection(new x),p=i.camera.getWorldPosition(new x),v=h.clone().sub(p).dot(g);v<=0&&h.addScaledVector(g,-2*v+(v===0?1:0)),c=_.ray.intersectPlane(new Bt().setFromNormalAndCoplanarPoint(g,h),new x)}if(c===null)return null;r.updateWorldMatrix(!0,!1);const m=r.worldToLocal(c),d=r.getWorldQuaternion(new Tt).invert().multiply(i.camera.getWorldQuaternion(new Tt));return{location:[m.x,m.y,m.z],rotation:[d.w,d.x,d.y,d.z]}}dispose(){for(const t of[this.lines,this.circle])t.geometry.dispose(),t.material.dispose();this.seen=null}}const jt=N().finite(),Li=M({display:H(["PLAIN_AXES","ARROWS","SINGLE_ARROW","CIRCLE","CUBE","SPHERE","CONE","IMAGE"]),size:jt,image:M({name:R().nullable(),offset:L([jt,jt]),depth:H(["DEFAULT","FRONT","BACK"]),side:H(["DOUBLE_SIDED","FRONT","BACK"]),perspective:Q(),orthographic:Q(),axis_aligned:Q(),opacity:jt.nullable(),tint:L([jt,jt,jt]).default([1,1,1]),premultiplied:Q().default(!1)}).optional()}),Et={selected:15554304,active:16752680,camera:0,light:0,lightAlpha:80/255,empty:0},Vi=1,et=(e,t,n)=>e.push(t[0],t[1],t[2],n[0],n[1],n[2]);function mt(e,t){return Array.from({length:t},(n,o)=>{const r=2*Math.PI*o/t;return[e*Math.cos(r),e*Math.sin(r)]})}function xt(e,t,n=0,o=!1){const r=o?2:1;for(let a=0;a<Math.floor(t.length/r);a++){const i=t[a*r%t.length],f=t[(a*r+1)%t.length];et(e,[i[0],i[1],n],[f[0],f[1],n])}}function ji(e){if(!e.isMesh||e.userData.volterOverrideStandDown)return;e.userData.volterOverrideStandDown=!0;const t=e.onBeforeRender.bind(e),n=e.onAfterRender.bind(e),o=new B;let r=!1;e.onBeforeRender=(a,i,f,u,_,l)=>{t(a,i,f,u,_,l),i.overrideMaterial&&(o.copy(e.matrixWorld),e.matrixWorld.makeScale(0,0,0),r=!0)},e.onAfterRender=(a,i,f,u,_,l)=>{r&&(e.matrixWorld.copy(o),r=!1),n(a,i,f,u,_,l)}}class Bi{constructor(){this.cameras=new it,this.lights=new it,this.empties=new it,this.lineMaterials=new Map,this.drawn=new Map,this.fillMaterials=new Map,this.scratch=new x,this.size=new Gt,this.parentQuat=new Tt,this.cameras.name="BlenderCameras",this.lights.name="BlenderLights",this.empties.name="BlenderEmpties"}apply(t){const n=new Set;for(const o of t.objects){const r=o.selected?o.name===t.active?Et.active:Et.selected:o.type==="CAMERA"?Et.camera:o.type==="LIGHT"?Et.light:Et.empty,a=o.type==="CAMERA"&&o.name!==t.lookingThrough?t.cameras[o.name]:void 0,i=o.type==="LIGHT"&&o.light?t.lights[o.light]:void 0,f=o.type==="EMPTY"?t.empties[o.name]:void 0;if(!a&&!i&&!f)continue;n.add(o.name);const u=i&&o.light?t.lightDistances[o.light]??null:null,_=f?.image?.name?t.image(f.image.name):null,l=JSON.stringify([_?[_.texture.uuid,_.width,_.height]:null,o.matrix,r,a,i,u,f,a?[o.name===t.sceneCamera,t.renderAspect]:null]),s=this.drawn.get(o.name),c=t.presented(o.name);if(s?.key===l){for(const p of s.parts)p.userData.volterPicksAs=c;continue}s&&this.remove(s.parts);const m=new B().set(...o.matrix.flat()),d=a?this.cameras:i?this.lights:this.empties,h=new Set(d.children);a?this.camera(a,m,r,o.name===t.sceneCamera,t.renderAspect):i?this.light(i,m,r,u):f&&this.empty(f,m,r,_);const g=d.children.filter(p=>!h.has(p));for(const p of g)p.userData.volterPicksAs=c,p.traverse(ji);this.drawn.set(o.name,{key:l,parts:g})}for(const[o,r]of this.drawn)n.has(o)||(this.remove(r.parts),this.drawn.delete(o))}remove(t){for(const n of t)n.removeFromParent(),n.geometry?.dispose(),n.userData.volterOwnMaterial&&n.material.dispose()}camera(t,n,o,r,a){const i=t.display_size,u=(t.sensor_fit==="AUTO"?a>=1:t.sensor_fit==="HORIZONTAL")?[1,1/a]:[a,1];let _,l,s,c;if(t.type==="ORTHO")s=[.5*t.ortho_scale*u[0],.5*t.ortho_scale*u[1]],c=[t.shift_x*t.ortho_scale,t.shift_y*t.ortho_scale],l=-i,_=.5*t.ortho_scale;else{const A=.5*(t.sensor_fit==="VERTICAL"?t.sensor_height:t.sensor_width),O=new x().setFromMatrixScale(n);if(O.x===0||O.y===0||O.z===0)return;_=i/2/((1/O.x+1/O.y+1/O.z)/3),l=_*t.lens/-A,s=[_*u[0],_*u[1]],c=[t.shift_x*_*2,t.shift_y*_*2]}const m=[[c[0]+s[0],c[1]+s[1],l],[c[0]+s[0],c[1]-s[1],l],[c[0]-s[0],c[1]-s[1],l],[c[0]-s[0],c[1]+s[1],l]],d=[];for(let A=0;A<4;A++)et(d,m[A],m[(A+1)%4]),et(d,m[A],[0,0,0]);const h=.7*_,g=.1*_,p=c[1]+s[1]+g,v=[[c[0]-h,p,l],[c[0]+h,p,l],[c[0],p+h,l]],b=Qn(n);this.cameras.add(this.lines(d,o,1,b));let y;if(r){const A=new an;A.setAttribute("position",new Mt(v.flat(),3)),y=new Rt(A,this.fill(o)),y.matrixAutoUpdate=!1,y.matrix.copy(b)}else{const A=[];for(let O=0;O<3;O++)et(A,v[O],v[(O+1)%3]);y=this.lines(A,o,1,b)}const S=new x,T=y.onBeforeRender.bind(y);y.onBeforeRender=(A,O,E,k,j,G)=>{S.setFromMatrixPosition(b).applyMatrix4(this.cameras.matrixWorld);const K=E.getWorldPosition(this.scratch).distanceToSquared(S)>1e-8;y.matrix.copy(b),K||y.matrix.scale(new x(0,0,0)),y.updateMatrixWorld(!0),T(A,O,E,k,j,G)},this.cameras.add(y)}light(t,n,o,r){const a=new x().setFromMatrixPosition(n),i=[];et(i,[a.x,a.y,a.z],[a.x,a.y,0]),this.lights.add(this.lines(i,Et.light,Et.lightAlpha,new B));const f=[];xt(f,mt(1.35,4)),this.lights.add(this.screen(f,Et.light,Et.lightAlpha,new x(a.x,a.y,0)));const u=[],_=9;if(xt(u,mt(_*.3,4)),xt(u,mt(_,16),0,!0),xt(u,mt(_*1.33,20),0,!0),t.type==="SUN")for(const[c,m]of mt(_,8))et(u,[c*1.6,m*1.6,0],[c*1.9,m*1.9,0]),et(u,[c*2.2,m*2.2,0],[c*2.5,m*2.5,0]);this.lights.add(this.screen(u,o,1,a));const l=Qn(n),s=[];if(t.type==="SUN")et(s,[0,0,0],[0,0,-20]);else if(t.type==="AREA"){const c=(t.size??1)/2,m=(t.shape==="RECTANGLE"||t.shape==="ELLIPSE"?t.size_y??t.size??1:t.size??1)/2;t.shape==="DISK"||t.shape==="ELLIPSE"?xt(s,mt(1,32).map(([d,h])=>[d*c,h*m])):xt(s,[[c,m],[-c,m],[-c,-m],[c,-m]])}if(s.length>0&&this.lights.add(this.lines(s,o,1,n.clone())),r&&(t.type==="SPOT"||t.type==="AREA")){const c=new x(0,0,-1).transformDirection(n),m=p=>a.clone().addScaledVector(c,p),[d,h]=r,g=[];et(g,m(d).toArray(),m(h).toArray()),this.lights.add(this.lines(g,o,1,new B));for(const p of[d,h]){const v=[];xt(v,mt(1.2,4)),this.lights.add(this.screen(v,o,1,m(p)))}}if(t.type==="SPOT"){const c=(t.spot_size??Math.PI/4)/2,m=Math.cos(c),d=t.spot_blend??.15,h=m*d-m-d,g=Math.sqrt((m*m-m*m*h*h)/(h*h-m*m*h*h)),p=Math.sqrt(1-m*m),v=Qn(n).multiply(new B().makeScale(10,10,10)),b=[];xt(b,mt(p,32),-m),xt(b,mt(p*g,32),-m),this.lights.add(this.lines(b,o,1,v.clone())),this.lights.add(this.silhouette(p,m,o,v))}if((t.type==="POINT"||t.type==="SPOT")&&(t.radius??0)>0){const c=[];xt(c,mt(t.radius,32)),this.lights.add(this.facing(c,o,new x().setFromMatrixPosition(l)))}}empty(t,n,o,r){const a=t.size,i=[],f=(_,l)=>{const s=mt(1,l);for(let c=0;c<l;c++){const[m,d]=s[c],[h,g]=s[(c+1)%l],p=(v,b)=>_==="xy"?[v,b,0]:_==="xz"?[v,0,b]:[0,v,b];et(i,p(m,d),p(h,g))}};switch(t.display){case"PLAIN_AXES":et(i,[0,-1,0],[0,1,0]),et(i,[-1,0,0],[1,0,0]),et(i,[0,0,-1],[0,0,1]);break;case"SINGLE_ARROW":{et(i,[0,0,0],[0,0,.75]);for(const[_,l]of[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]])et(i,[0,0,1],[_,l,.75]);xt(i,[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]],.75);break}case"CUBE":for(const[_,l]of Ui)et(i,Je[_],Je[l]);break;case"CIRCLE":f("xz",64);break;case"SPHERE":f("xy",32),f("xz",32),f("yz",32);break;case"CONE":{const _=mt(1,8);for(let l=0;l<8;l++){const[s,c]=_[l],[m,d]=_[(l+1)%8];et(i,[s,0,c],[0,2,0]),et(i,[s,0,c],[m,0,d])}break}case"ARROWS":for(let _=0;_<3;_++){const l=[0,0,0];l[_]=1,et(i,[0,0,0],l)}break;case"IMAGE":this.imageEmpty(t,n,o,r);return}const u=n.clone().multiply(new B().makeScale(a,a,a));this.empties.add(this.lines(i,o,1,u)),t.display==="ARROWS"&&this.axisNames(n,a,o)}silhouette(t,n,o,r){const a=this.lines(new Array(192).fill(0),o,1,r);a.frustumCulled=!1;const i=a.geometry.getAttribute("instanceStart").data,f=mt(1,32).map(([m,d])=>new x(m*t,d*t,-n)),u=new x,_=new B,l=new x,s=new x,c=new x;return this.onDraw(a,(m,d)=>{_.copy(a.matrixWorld).invert();const h=d.isOrthographicCamera;h?d.getWorldDirection(u).negate().transformDirection(_):u.setFromMatrixPosition(d.matrixWorld).applyMatrix4(_);const g=i.array;let p=!1;for(let v=0;v<32;v++){const b=f[v];l.crossVectors(b,f[(v+31)%32]),s.crossVectors(f[(v+1)%32],b),h?c.copy(u):c.copy(u).sub(b);const y=l.dot(c)>0!=s.dot(c)>0;(g[v*6+3]!==0||g[v*6+5]!==0)!==y&&(p=!0),g.set([0,0,0,y?b.x:0,y?b.y:0,y?b.z:0],v*6)}p&&(i.needsUpdate=!0,ht())}),a}imageEmpty(t,n,o,r){const a=t.image;if(!a)return;const i=r?.width??0,f=r?.height??0,u=i>0&&f>0?i>=f?[1,f/i]:[i/f,1]:[1,1],_=new x,l=new x,s=new x;n.extractBasis(_,l,s),_.multiplyScalar(u[0]*.5*t.size),l.multiplyScalar(u[1]*.5*t.size);const c=new x().setFromMatrixPosition(n).addScaledVector(_,a.offset[0]*2+1).addScaledVector(l,a.offset[1]*2+1),m=new B().makeBasis(_,l,s.clone()).setPosition(c),d=[];xt(d,[[-1,-1],[1,-1],[1,1],[-1,1]]);const h=this.lines(d,o,1,m),g=s.clone().normalize(),p=new x,v=new x,b=(E,k)=>{const j=E.isOrthographicCamera===!0;if(j?!a.orthographic:!a.perspective)return!1;if(!k)return!0;const G=g.clone().transformDirection(this.empties.matrixWorld);E.getWorldDirection(v);let K,J;if(j)K=G.dot(v.clone().negate()),J=1e-5;else{const ft=c.clone().applyMatrix4(this.empties.matrixWorld);K=G.dot(p.setFromMatrixPosition(E.matrixWorld).sub(ft)),J=0}return!(a.side==="FRONT"&&K<J||a.side==="BACK"&&K>-J||a.axis_aligned&&G.clone().projectOnPlane(v).lengthSq()>1e-5)},y=(E,k)=>{const j=E.onBeforeRender.bind(E);E.onBeforeRender=(G,K,J,ft,w,V)=>{E.matrix.copy(m),b(J,k)||E.matrix.scale(new x(0,0,0)),E.updateMatrixWorld(!0),j(G,K,J,ft,w,V)}};if(y(h,!1),this.empties.add(h),!r||a.opacity!==null&&a.opacity<=0)return;const S=a.opacity!==null,T=a.depth==="BACK",A=new Rn({map:r.texture,side:ee,transparent:S&&!T,opacity:a.opacity??1,alphaTest:S?0:.05,toneMapped:!1,depthTest:a.depth==="DEFAULT",depthWrite:a.depth==="DEFAULT"&&!S});A.color.setRGB(...a.tint,vt),S&&T&&(A.blending=ma,A.blendSrc=_a,A.blendDst=da),A.onBeforeCompile=E=>{const k=a.premultiplied?`if ( sampledDiffuseColor.a > 0.0 && sampledDiffuseColor.a < 1.0 ) sampledDiffuseColor.rgb /= sampledDiffuseColor.a;
7145
- `:"";E.fragmentShader=E.fragmentShader.replace("#include <map_fragment>",`vec4 sampledDiffuseColor = texture2D( map, vMapUv );
7146
- ${k}diffuseColor *= sampledDiffuseColor;`).replace("#include <alphatest_fragment>",S?"#include <alphatest_fragment>":`#include <alphatest_fragment>
7147
- diffuseColor.a = 1.0;`)},A.customProgramCacheKey=()=>`volter-blender-image:${a.premultiplied}:${S}`;const O=new Rt(new po(2,2),A);O.matrixAutoUpdate=!1,O.matrix.copy(m),O.renderOrder=a.depth==="FRONT"?1e3:a.depth==="BACK"?-1e3:0,O.userData.volterOwnMaterial=!0,y(O,!0),this.empties.add(O)}axisNames(t,n,o){const r=[new x,new x,new x];t.extractBasis(r[0],r[1],r[2]);for(let a=0;a<3;a++){const i=r[a].length()*n,f=new x(0,0,0);f.setComponent(a,1.25*n),f.applyMatrix4(t);const u=new x(0,0,0);u.setComponent(a,n),u.applyMatrix4(t);const _=[];for(let c=1;c<=6;c++)xt(_,mt(.007*(4*c/6)*i,4));this.empties.add(this.facing(_,o,u));const l=Wi[a],s=[];for(let c=0;c+1<l.length;c+=2){const[m,d]=l[c],[h,g]=l[c+1];et(s,[m*4*i,d*4*i,0],[h*4*i,g*4*i,0])}this.empties.add(this.facing(s,o,f))}}material(t,n){const o=`${t}:${n}`;let r=this.lineMaterials.get(o);return r||(r=new lo({color:t,linewidth:Vi,transparent:n<1,opacity:n,depthTest:!0,depthWrite:n>=1,toneMapped:!1}),this.lineMaterials.set(o,r)),r}fill(t){let n=this.fillMaterials.get(t);return n||(n=new Rn({color:t,side:ee,toneMapped:!1}),this.fillMaterials.set(t,n)),n}lines(t,n,o,r){const a=new so().setPositions(t),i=new fo(a,this.material(n,o));return i.matrixAutoUpdate=!1,i.matrix.copy(r),i.computeLineDistances(),i}screen(t,n,o,r){const a=this.lines(t,n,o,new B);return a.matrixAutoUpdate=!0,a.position.copy(r),a.scale.setScalar(0),a.frustumCulled=!1,this.onDraw(a,(i,f)=>this.face(a,i,f,!0)),a}facing(t,n,o){const r=this.lines(t,n,1,new B);return r.matrixAutoUpdate=!0,r.position.copy(o),this.onDraw(r,(a,i)=>this.face(r,a,i,!1)),r}onDraw(t,n){const o=t,r=o.onBeforeRender.bind(o);o.onBeforeRender=(a,i,f,u,_,l)=>{n(a,f),r(a,i,f,u,_,l)}}face(t,n,o,r){t.parent?.getWorldQuaternion(this.parentQuat).invert(),o.getWorldQuaternion(t.quaternion).premultiply(this.parentQuat);let a=1;if(r){n.getSize(this.size);const i=Math.max(this.size.y,1),f=this.scratch.setFromMatrixPosition(t.matrixWorld);if(o.isOrthographicCamera){const u=o;a=(u.top-u.bottom)/u.zoom/i}else{const u=o;a=2*Math.max(-f.applyMatrix4(o.matrixWorldInverse).z,1e-6)*Math.tan(bt.degToRad(u.fov)/2)/u.zoom/i}}t.scale.setScalar(a),t.updateMatrixWorld(!0)}dispose(){for(const t of this.drawn.values())this.remove(t.parts);this.drawn.clear();for(const t of this.lineMaterials.values())t.dispose();for(const t of this.fillMaterials.values())t.dispose();this.lineMaterials.clear(),this.fillMaterials.clear()}}function Qn(e){const t=new x,n=new Tt;return e.decompose(t,n,new x),new B().compose(t,n,new x(1,1,1))}const Je=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],Ui=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],Wi=[[[.9,1],[-1,-1],[-.9,1],[1,-1]].map(([e,t])=>[e*.0215,t*.025]),[[-1,1],[0,-.1],[1,1],[0,-.1],[0,-.1],[0,-1]].map(([e,t])=>[e*.0175,t*.025]),[[-.95,1],[.95,1],[.95,1],[.95,.9],[.95,.9],[-1,-.9],[-1,-.9],[-1,-1],[-1,-1],[1,-1]].map(([e,t])=>[e*.02,t*.025])],_t=N().finite(),to=M({name:R(),type:R(),lens:_t,sensor_width:_t,sensor_height:_t,sensor_fit:H(["AUTO","HORIZONTAL","VERTICAL"]),ortho_scale:_t,clip_start:_t,clip_end:_t,shift_x:_t,shift_y:_t,matrix:D(L([_t,_t,_t,_t])).length(4),passepartout:_t.default(0),display_size:_t.default(1)}),qi={opening:.5,min:.1657359312880715,max:44.98528137423857},Sn={passepartout:"#000000",back:"#3d3d3d",overlay:"#000000",redalert:"#991616"};function Hi(e,t,n,o){const r=a=>Math.min(1,Math.max(-1,a));return[r(e[0]-n/(2*t)),r(e[1]+o/(2*t))]}function no(e,t,n,o){const r=e.type==="ORTHO",a=e.sensor_fit==="VERTICAL"?e.sensor_height:e.sensor_width,i=e.sensor_fit==="AUTO"?t>=n:e.sensor_fit==="HORIZONTAL",f=(r?e.ortho_scale:a/e.lens)/2*o;return i?[f,f*n/t]:[f*t/n,f]}function Gi(e,t,n,o,r,a){const i=Math.max(n.width,1),f=Math.max(n.height,1),[u,_]=no(e,i,f,1/o),[l,s]=no(e,a,1,1),m=2*((e.sensor_fit==="AUTO"?a>=1:e.sensor_fit==="HORIZONTAL")?l:s),d=l/u,h=s/_,g=-2*r[0]*o,p=2*r[1]*o,v=e.shift_x*m-g*2*u,b=e.shift_y*m+p*2*_,y=new B().set(...e.matrix.flat()).premultiply(t),S=new x,T=new Tt;return y.decompose(S,T,new x),{name:e.name,position:S.toArray(),quaternion:[T.x,T.y,T.z,T.w],projection:e.type==="ORTHO"?"orthographic":"perspective",window:{left:v-u,right:v+u,top:b+_,bottom:b-_},near:e.clip_start,far:e.clip_end,frame:{left:.5-d/2+g,top:.5-h/2+p,width:d,height:h},passepartout:{color:Sn.passepartout,opacity:e.passepartout},border:{solid:Sn.back,dashed:Sn.overlay,locked:Sn.redalert}}}const Xi={color:[.8,.8,.8,1],roughness:.5,metallic:0},Yi=`
7144
+ }`}),this.scene.clear(),this.scene.add(new Rt(this.geometry,this.material)),this.target.setSize(n.width,n.height);const c=t.getRenderTarget();try{t.setRenderTarget(this.target),t.render(this.scene,this.camera)}finally{t.setRenderTarget(c)}return this.target}dispose(){this.material?.dispose(),this.geometry.dispose(),this.target.dispose(),this.scene.clear()}}const Ri=N({object:I(),group:I(),groupIndex:R().int().nonnegative(),count:R().int().nonnegative(),digest:I(),alertMode:K(["NONE","ACTIVE","ALL"]),unchanged:Z(!0).optional(),weightsBase64:I().optional(),alertBase64:I().optional()}).strict();function Ii(e){const n=e<0?0:e>1?1:e,o=(.5+.5*n)**1.5,[r,a,i]=zi(2/3*(1-n)),f=new Ot;return f.setRGB((r*o)**(1/1.5),(a*o)**(1/1.5),(i*o)**(1/1.5),Lt),f}function zi(e){const t=(e%1+1)%1,n=Math.floor(t*6),o=t*6-n;switch(n%6){case 0:return[1,o,0];case 1:return[1-o,1,0];case 2:return[0,1,o];case 3:return[0,1-o,1];case 4:return[o,0,1];default:return[1,0,1-o]}}const Fi=0;function Je(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}class Di{constructor(){this.group=new lt,this.mesh=null,this.material=null,this.geometry=null,this.held=null,this.signature="",this.group.name="BlenderWeightOverlay"}apply(t,n,o){if(t===null||n===null||!n.isMesh||o===null)return this.clear(),this.signature="",null;const r=`${t.object}:${t.group}`;if(t.unchanged===!0){if(this.held?.key!==r)return this.clear(),`weights: the session sent a reference to ${r} that this overlay does not hold; the colours reappear on the next change to the mesh or the group`}else{if(t.weightsBase64===void 0||t.alertBase64===void 0)return this.clear(),`weights: ${r} carried neither an array nor a reference`;const d=Je(t.weightsBase64);this.held={key:r,weights:new Float32Array(d.buffer,d.byteOffset,t.count),alerts:Je(t.alertBase64)}}const a=this.held;if(a===null)return null;const i=`${r}:${t.digest}:${n.geometry.uuid}:${t.alertMode}:${o.elements.join(",")}`;if(i===this.signature&&this.mesh!==null)return null;this.signature=i,this.clear();const f=n.geometry.clone(),u=f.getAttribute("position"),_=f.getAttribute("blenderVertex");if(_===void 0)return f.dispose(),"weights: the presented geometry carries no per-vertex Blender index (`blenderVertex`), so the weights cannot be laid over it";const l=new Float32Array(u.count*3),s=new Ot().setHex(Fi,Lt);for(let d=0;d<u.count;d++){const h=_.getX(d),p=t.alertMode!=="NONE"&&a.alerts[h]===1?s:Ii(a.weights[h]??0);l[d*3]=p.r,l[d*3+1]=p.g,l[d*3+2]=p.b}f.setAttribute("color",new ct(l,3)),f.deleteAttribute("blenderVertex");const c=new In({vertexColors:!0,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1}),m=new Rt(f,c);return m.name=`${t.object}:weights`,m.frustumCulled=!1,m.matrixAutoUpdate=!1,m.matrix.copy(o),m.matrix.decompose(m.position,m.quaternion,m.scale),this.geometry=f,this.material=c,this.mesh=m,this.group.add(m),null}clear(){this.mesh&&this.group.remove(this.mesh),this.geometry?.dispose(),this.material?.dispose(),this.mesh=null,this.geometry=null,this.material=null}dispose(){this.clear(),this.held=null,this.signature=""}}const Sn=R().finite(),Ci=$(U([Sn,Sn,Sn,Sn])).length(4),ki=20,to=[16724818,9165824,2658559];function $i(e){const t=n=>Math.min(255,Math.max(0,Math.floor(.75*n+63.75)-60))/255;return new Ot().setRGB(t(e>>16&255),t(e>>8&255),t(e&255),Lt)}function Wo(){return new da({vertexColors:!0,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1})}function Li(){const e=[],t=[],n=new Ot(0,0,0),o=(a,i,f,u,_)=>{for(const l of[a,i]){const s=[0,0,0];s[f]=l*u,e.push(...s),t.push(_.r,_.g,_.b)}};for(let a=0;a<3;a++){const i=new Ot().setHex(to[a],Lt);o(1,.85,a,1,i),o(.85,.25,a,1,n),o(1,.85,a,-1,$i(to[a])),o(.85,.25,a,-1,n)}const r=new sn;return r.setAttribute("position",new Mt(e,3)),r.setAttribute("color",new Mt(t,3)),new bo(r,Wo())}function Vi(){const t=[],n=[],o=new Ot(1,0,0),r=new Ot(1,1,1);for(let i=0;i<12;i++){const f=(i+1)%2===0?r:o;for(const u of[i,i+1]){const _=2*Math.PI*u/12;t.push(.5*Math.cos(_),.5*Math.sin(_),0),n.push(f.r,f.g,f.b)}}const a=new sn;return a.setAttribute("position",new Mt(t,3)),a.setAttribute("color",new Mt(n,3)),new bo(a,Wo())}class ji{constructor(){this.group=new lt,this.anchor=new lt,this.lines=Li(),this.circle=Vi(),this.seen=null,this.size=new Xt,this.scratch=new x,this.parentQuat=new At,this.group.name="BlenderCursor",this.present(!1),this.anchor.matrixAutoUpdate=!1,this.group.add(this.anchor,this.circle),this.anchor.add(this.lines);for(const t of[this.lines,this.circle])t.renderOrder=1001,t.frustumCulled=!1;this.lines.onBeforeRender=(t,n,o)=>this.fit(t,o),this.circle.onBeforeRender=(t,n,o)=>this.fit(t,o)}apply(t){if(t===void 0){this.present(!1);return}this.anchor.matrix.set(...t.flat()),this.anchor.updateMatrixWorld(!0),this.present(!0)}present(t){this.anchor.visible=t,this.circle.visible=t}show(t){const[n,o,r,a]=t.rotation;this.anchor.matrix.compose(new x(...t.location),new At(o,r,a,n),new x(1,1,1)),this.anchor.updateMatrixWorld(!0),this.present(!0)}fit(t,n){this.seen={camera:n,canvas:t.domElement},t.getSize(this.size);const o=Math.max(this.size.y,1),r=this.scratch.setFromMatrixPosition(this.anchor.matrixWorld);let a;if(n.isOrthographicCamera){const f=n;a=(f.top-f.bottom)/f.zoom/o}else{const f=n;a=2*Math.max(-r.applyMatrix4(n.matrixWorldInverse).z,1e-6)*Math.tan(bt.degToRad(f.fov)/2)/f.zoom/o}const i=a*ki;this.lines.scale.setScalar(i),this.lines.updateMatrixWorld(!0),this.circle.position.setFromMatrixPosition(this.anchor.matrix),this.group.getWorldQuaternion(this.parentQuat).invert(),n.getWorldQuaternion(this.circle.quaternion).premultiply(this.parentQuat),this.circle.scale.setScalar(i),this.circle.updateMatrixWorld(!0)}placementAt(t,n,o,r,a){const i=this.seen;if(i===null||o!==i.canvas)return null;const f=i.canvas.getBoundingClientRect(),u=new Xt((t-f.left)/Math.max(f.width,1)*2-1,-((n-f.top)/Math.max(f.height,1))*2+1),_=new _a;_.setFromCamera(u,i.camera);const l=h=>{for(let g=h;g!==null;g=g.parent)if(!g.visible)return!1;return!0},s=_.intersectObject(r,!0).find(h=>h.object.isMesh&&a(h.object)&&l(h.object));let c=s?s.point.clone():null;if(c===null){const h=new x().setFromMatrixPosition(this.anchor.matrixWorld),g=i.camera.getWorldDirection(new x),p=i.camera.getWorldPosition(new x),v=h.clone().sub(p).dot(g);v<=0&&h.addScaledVector(g,-2*v+(v===0?1:0)),c=_.ray.intersectPlane(new Ut().setFromNormalAndCoplanarPoint(g,h),new x)}if(c===null)return null;r.updateWorldMatrix(!0,!1);const m=r.worldToLocal(c),d=r.getWorldQuaternion(new At).invert().multiply(i.camera.getWorldQuaternion(new At));return{location:[m.x,m.y,m.z],rotation:[d.w,d.x,d.y,d.z]}}dispose(){for(const t of[this.lines,this.circle])t.geometry.dispose(),t.material.dispose();this.seen=null}}const Bt=R().finite(),Bi=N({display:K(["PLAIN_AXES","ARROWS","SINGLE_ARROW","CIRCLE","CUBE","SPHERE","CONE","IMAGE"]),size:Bt,image:N({name:I().nullable(),offset:U([Bt,Bt]),depth:K(["DEFAULT","FRONT","BACK"]),side:K(["DOUBLE_SIDED","FRONT","BACK"]),perspective:et(),orthographic:et(),axis_aligned:et(),opacity:Bt.nullable(),tint:U([Bt,Bt,Bt]).default([1,1,1]),premultiplied:et().default(!1)}).optional()}),Et={selected:15554304,active:16752680,camera:0,light:0,lightAlpha:80/255,empty:0},Ui=1,ot=(e,t,n)=>e.push(t[0],t[1],t[2],n[0],n[1],n[2]);function mt(e,t){return Array.from({length:t},(n,o)=>{const r=2*Math.PI*o/t;return[e*Math.cos(r),e*Math.sin(r)]})}function xt(e,t,n=0,o=!1){const r=o?2:1;for(let a=0;a<Math.floor(t.length/r);a++){const i=t[a*r%t.length],f=t[(a*r+1)%t.length];ot(e,[i[0],i[1],n],[f[0],f[1],n])}}function Wi(e){if(!e.isMesh||e.userData.volterOverrideStandDown)return;e.userData.volterOverrideStandDown=!0;const t=e.onBeforeRender.bind(e),n=e.onAfterRender.bind(e),o=new H;let r=!1;e.onBeforeRender=(a,i,f,u,_,l)=>{t(a,i,f,u,_,l),i.overrideMaterial&&(o.copy(e.matrixWorld),e.matrixWorld.makeScale(0,0,0),r=!0)},e.onAfterRender=(a,i,f,u,_,l)=>{r&&(e.matrixWorld.copy(o),r=!1),n(a,i,f,u,_,l)}}class qi{constructor(){this.cameras=new lt,this.lights=new lt,this.empties=new lt,this.lineMaterials=new Map,this.drawn=new Map,this.fillMaterials=new Map,this.scratch=new x,this.size=new Xt,this.parentQuat=new At,this.cameras.name="BlenderCameras",this.lights.name="BlenderLights",this.empties.name="BlenderEmpties"}apply(t){const n=new Set;for(const o of t.objects){const r=o.selected?o.name===t.active?Et.active:Et.selected:o.type==="CAMERA"?Et.camera:o.type==="LIGHT"?Et.light:Et.empty,a=o.type==="CAMERA"&&o.name!==t.lookingThrough?t.cameras[o.name]:void 0,i=o.type==="LIGHT"&&o.light?t.lights[o.light]:void 0,f=o.type==="EMPTY"?t.empties[o.name]:void 0;if(!a&&!i&&!f)continue;n.add(o.name);const u=i&&o.light?t.lightDistances[o.light]??null:null,_=f?.image?.name?t.image(f.image.name):null,l=JSON.stringify([_?[_.texture.uuid,_.width,_.height]:null,o.matrix,r,a,i,u,f,a?[o.name===t.sceneCamera,t.renderAspect]:null]),s=this.drawn.get(o.name),c=t.presented(o.name);if(s?.key===l){for(const p of s.parts)p.userData.volterPicksAs=c;continue}s&&this.remove(s.parts);const m=new H().set(...o.matrix.flat()),d=a?this.cameras:i?this.lights:this.empties,h=new Set(d.children);a?this.camera(a,m,r,o.name===t.sceneCamera,t.renderAspect):i?this.light(i,m,r,u):f&&this.empty(f,m,r,_);const g=d.children.filter(p=>!h.has(p));for(const p of g)p.userData.volterPicksAs=c,p.traverse(Wi);this.drawn.set(o.name,{key:l,parts:g})}for(const[o,r]of this.drawn)n.has(o)||(this.remove(r.parts),this.drawn.delete(o))}remove(t){for(const n of t)n.removeFromParent(),n.geometry?.dispose(),n.userData.volterOwnMaterial&&n.material.dispose()}camera(t,n,o,r,a){const i=t.display_size,u=(t.sensor_fit==="AUTO"?a>=1:t.sensor_fit==="HORIZONTAL")?[1,1/a]:[a,1];let _,l,s,c;if(t.type==="ORTHO")s=[.5*t.ortho_scale*u[0],.5*t.ortho_scale*u[1]],c=[t.shift_x*t.ortho_scale,t.shift_y*t.ortho_scale],l=-i,_=.5*t.ortho_scale;else{const M=.5*(t.sensor_fit==="VERTICAL"?t.sensor_height:t.sensor_width),A=new x().setFromMatrixScale(n);if(A.x===0||A.y===0||A.z===0)return;_=i/2/((1/A.x+1/A.y+1/A.z)/3),l=_*t.lens/-M,s=[_*u[0],_*u[1]],c=[t.shift_x*_*2,t.shift_y*_*2]}const m=[[c[0]+s[0],c[1]+s[1],l],[c[0]+s[0],c[1]-s[1],l],[c[0]-s[0],c[1]-s[1],l],[c[0]-s[0],c[1]+s[1],l]],d=[];for(let M=0;M<4;M++)ot(d,m[M],m[(M+1)%4]),ot(d,m[M],[0,0,0]);const h=.7*_,g=.1*_,p=c[1]+s[1]+g,v=[[c[0]-h,p,l],[c[0]+h,p,l],[c[0],p+h,l]],O=Kn(n);this.cameras.add(this.lines(d,o,1,O));let b;if(r){const M=new sn;M.setAttribute("position",new Mt(v.flat(),3)),b=new Rt(M,this.fill(o)),b.matrixAutoUpdate=!1,b.matrix.copy(O)}else{const M=[];for(let A=0;A<3;A++)ot(M,v[A],v[(A+1)%3]);b=this.lines(M,o,1,O)}const P=new x,T=b.onBeforeRender.bind(b);b.onBeforeRender=(M,A,w,E,D,W)=>{P.setFromMatrixPosition(O).applyMatrix4(this.cameras.matrixWorld);const V=w.getWorldPosition(this.scratch).distanceToSquared(P)>1e-8;b.matrix.copy(O),V||b.matrix.scale(new x(0,0,0)),b.updateMatrixWorld(!0),T(M,A,w,E,D,W)},this.cameras.add(b)}light(t,n,o,r){const a=new x().setFromMatrixPosition(n),i=[];ot(i,[a.x,a.y,a.z],[a.x,a.y,0]),this.lights.add(this.lines(i,Et.light,Et.lightAlpha,new H));const f=[];xt(f,mt(1.35,4)),this.lights.add(this.screen(f,Et.light,Et.lightAlpha,new x(a.x,a.y,0)));const u=[],_=9;if(xt(u,mt(_*.3,4)),xt(u,mt(_,16),0,!0),xt(u,mt(_*1.33,20),0,!0),t.type==="SUN")for(const[c,m]of mt(_,8))ot(u,[c*1.6,m*1.6,0],[c*1.9,m*1.9,0]),ot(u,[c*2.2,m*2.2,0],[c*2.5,m*2.5,0]);this.lights.add(this.screen(u,o,1,a));const l=Kn(n),s=[];if(t.type==="SUN")ot(s,[0,0,0],[0,0,-20]);else if(t.type==="AREA"){const c=(t.size??1)/2,m=(t.shape==="RECTANGLE"||t.shape==="ELLIPSE"?t.size_y??t.size??1:t.size??1)/2;t.shape==="DISK"||t.shape==="ELLIPSE"?xt(s,mt(1,32).map(([d,h])=>[d*c,h*m])):xt(s,[[c,m],[-c,m],[-c,-m],[c,-m]])}if(s.length>0&&this.lights.add(this.lines(s,o,1,n.clone())),r&&(t.type==="SPOT"||t.type==="AREA")){const c=new x(0,0,-1).transformDirection(n),m=p=>a.clone().addScaledVector(c,p),[d,h]=r,g=[];ot(g,m(d).toArray(),m(h).toArray()),this.lights.add(this.lines(g,o,1,new H));for(const p of[d,h]){const v=[];xt(v,mt(1.2,4)),this.lights.add(this.screen(v,o,1,m(p)))}}if(t.type==="SPOT"){const c=(t.spot_size??Math.PI/4)/2,m=Math.cos(c),d=t.spot_blend??.15,h=m*d-m-d,g=Math.sqrt((m*m-m*m*h*h)/(h*h-m*m*h*h)),p=Math.sqrt(1-m*m),v=Kn(n).multiply(new H().makeScale(10,10,10)),O=[];xt(O,mt(p,32),-m),xt(O,mt(p*g,32),-m),this.lights.add(this.lines(O,o,1,v.clone())),this.lights.add(this.silhouette(p,m,o,v))}if((t.type==="POINT"||t.type==="SPOT")&&(t.radius??0)>0){const c=[];xt(c,mt(t.radius,32)),this.lights.add(this.facing(c,o,new x().setFromMatrixPosition(l)))}}empty(t,n,o,r){const a=t.size,i=[],f=(_,l)=>{const s=mt(1,l);for(let c=0;c<l;c++){const[m,d]=s[c],[h,g]=s[(c+1)%l],p=(v,O)=>_==="xy"?[v,O,0]:_==="xz"?[v,0,O]:[0,v,O];ot(i,p(m,d),p(h,g))}};switch(t.display){case"PLAIN_AXES":ot(i,[0,-1,0],[0,1,0]),ot(i,[-1,0,0],[1,0,0]),ot(i,[0,0,-1],[0,0,1]);break;case"SINGLE_ARROW":{ot(i,[0,0,0],[0,0,.75]);for(const[_,l]of[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]])ot(i,[0,0,1],[_,l,.75]);xt(i,[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]],.75);break}case"CUBE":for(const[_,l]of Hi)ot(i,no[_],no[l]);break;case"CIRCLE":f("xz",64);break;case"SPHERE":f("xy",32),f("xz",32),f("yz",32);break;case"CONE":{const _=mt(1,8);for(let l=0;l<8;l++){const[s,c]=_[l],[m,d]=_[(l+1)%8];ot(i,[s,0,c],[0,2,0]),ot(i,[s,0,c],[m,0,d])}break}case"ARROWS":for(let _=0;_<3;_++){const l=[0,0,0];l[_]=1,ot(i,[0,0,0],l)}break;case"IMAGE":this.imageEmpty(t,n,o,r);return}const u=n.clone().multiply(new H().makeScale(a,a,a));this.empties.add(this.lines(i,o,1,u)),t.display==="ARROWS"&&this.axisNames(n,a,o)}silhouette(t,n,o,r){const a=this.lines(new Array(192).fill(0),o,1,r);a.frustumCulled=!1;const i=a.geometry.getAttribute("instanceStart").data,f=mt(1,32).map(([m,d])=>new x(m*t,d*t,-n)),u=new x,_=new H,l=new x,s=new x,c=new x;return this.onDraw(a,(m,d)=>{_.copy(a.matrixWorld).invert();const h=d.isOrthographicCamera;h?d.getWorldDirection(u).negate().transformDirection(_):u.setFromMatrixPosition(d.matrixWorld).applyMatrix4(_);const g=i.array;let p=!1;for(let v=0;v<32;v++){const O=f[v];l.crossVectors(O,f[(v+31)%32]),s.crossVectors(f[(v+1)%32],O),h?c.copy(u):c.copy(u).sub(O);const b=l.dot(c)>0!=s.dot(c)>0;(g[v*6+3]!==0||g[v*6+5]!==0)!==b&&(p=!0),g.set([0,0,0,b?O.x:0,b?O.y:0,b?O.z:0],v*6)}p&&(i.needsUpdate=!0,ht())}),a}imageEmpty(t,n,o,r){const a=t.image;if(!a)return;const i=r?.width??0,f=r?.height??0,u=i>0&&f>0?i>=f?[1,f/i]:[i/f,1]:[1,1],_=new x,l=new x,s=new x;n.extractBasis(_,l,s),_.multiplyScalar(u[0]*.5*t.size),l.multiplyScalar(u[1]*.5*t.size);const c=new x().setFromMatrixPosition(n).addScaledVector(_,a.offset[0]*2+1).addScaledVector(l,a.offset[1]*2+1),m=new H().makeBasis(_,l,s.clone()).setPosition(c),d=[];xt(d,[[-1,-1],[1,-1],[1,1],[-1,1]]);const h=this.lines(d,o,1,m),g=s.clone().normalize(),p=new x,v=new x,O=(w,E)=>{const D=w.isOrthographicCamera===!0;if(D?!a.orthographic:!a.perspective)return!1;if(!E)return!0;const W=g.clone().transformDirection(this.empties.matrixWorld);w.getWorldDirection(v);let V,G;if(D)V=W.dot(v.clone().negate()),G=1e-5;else{const nt=c.clone().applyMatrix4(this.empties.matrixWorld);V=W.dot(p.setFromMatrixPosition(w.matrixWorld).sub(nt)),G=0}return!(a.side==="FRONT"&&V<G||a.side==="BACK"&&V>-G||a.axis_aligned&&W.clone().projectOnPlane(v).lengthSq()>1e-5)},b=(w,E)=>{const D=w.onBeforeRender.bind(w);w.onBeforeRender=(W,V,G,nt,y,j)=>{w.matrix.copy(m),O(G,E)||w.matrix.scale(new x(0,0,0)),w.updateMatrixWorld(!0),D(W,V,G,nt,y,j)}};if(b(h,!1),this.empties.add(h),!r||a.opacity!==null&&a.opacity<=0)return;const P=a.opacity!==null,T=a.depth==="BACK",M=new In({map:r.texture,side:ae,transparent:P&&!T,opacity:a.opacity??1,alphaTest:P?0:.05,toneMapped:!1,depthTest:a.depth==="DEFAULT",depthWrite:a.depth==="DEFAULT"&&!P});M.color.setRGB(...a.tint,vt),P&&T&&(M.blending=ha,M.blendSrc=pa,M.blendDst=ga),M.onBeforeCompile=w=>{const E=a.premultiplied?`if ( sampledDiffuseColor.a > 0.0 && sampledDiffuseColor.a < 1.0 ) sampledDiffuseColor.rgb /= sampledDiffuseColor.a;
7145
+ `:"";w.fragmentShader=w.fragmentShader.replace("#include <map_fragment>",`vec4 sampledDiffuseColor = texture2D( map, vMapUv );
7146
+ ${E}diffuseColor *= sampledDiffuseColor;`).replace("#include <alphatest_fragment>",P?"#include <alphatest_fragment>":`#include <alphatest_fragment>
7147
+ diffuseColor.a = 1.0;`)},M.customProgramCacheKey=()=>`volter-blender-image:${a.premultiplied}:${P}`;const A=new Rt(new xo(2,2),M);A.matrixAutoUpdate=!1,A.matrix.copy(m),A.renderOrder=a.depth==="FRONT"?1e3:a.depth==="BACK"?-1e3:0,A.userData.volterOwnMaterial=!0,b(A,!0),this.empties.add(A)}axisNames(t,n,o){const r=[new x,new x,new x];t.extractBasis(r[0],r[1],r[2]);for(let a=0;a<3;a++){const i=r[a].length()*n,f=new x(0,0,0);f.setComponent(a,1.25*n),f.applyMatrix4(t);const u=new x(0,0,0);u.setComponent(a,n),u.applyMatrix4(t);const _=[];for(let c=1;c<=6;c++)xt(_,mt(.007*(4*c/6)*i,4));this.empties.add(this.facing(_,o,u));const l=Gi[a],s=[];for(let c=0;c+1<l.length;c+=2){const[m,d]=l[c],[h,g]=l[c+1];ot(s,[m*4*i,d*4*i,0],[h*4*i,g*4*i,0])}this.empties.add(this.facing(s,o,f))}}material(t,n){const o=`${t}:${n}`;let r=this.lineMaterials.get(o);return r||(r=new uo({color:t,linewidth:Ui,transparent:n<1,opacity:n,depthTest:!0,depthWrite:n>=1,toneMapped:!1}),this.lineMaterials.set(o,r)),r}fill(t){let n=this.fillMaterials.get(t);return n||(n=new In({color:t,side:ae,toneMapped:!1}),this.fillMaterials.set(t,n)),n}lines(t,n,o,r){const a=new co().setPositions(t),i=new mo(a,this.material(n,o));return i.matrixAutoUpdate=!1,i.matrix.copy(r),i.computeLineDistances(),i}screen(t,n,o,r){const a=this.lines(t,n,o,new H);return a.matrixAutoUpdate=!0,a.position.copy(r),a.scale.setScalar(0),a.frustumCulled=!1,this.onDraw(a,(i,f)=>this.face(a,i,f,!0)),a}facing(t,n,o){const r=this.lines(t,n,1,new H);return r.matrixAutoUpdate=!0,r.position.copy(o),this.onDraw(r,(a,i)=>this.face(r,a,i,!1)),r}onDraw(t,n){const o=t,r=o.onBeforeRender.bind(o);o.onBeforeRender=(a,i,f,u,_,l)=>{n(a,f),r(a,i,f,u,_,l)}}face(t,n,o,r){t.parent?.getWorldQuaternion(this.parentQuat).invert(),o.getWorldQuaternion(t.quaternion).premultiply(this.parentQuat);let a=1;if(r){n.getSize(this.size);const i=Math.max(this.size.y,1),f=this.scratch.setFromMatrixPosition(t.matrixWorld);if(o.isOrthographicCamera){const u=o;a=(u.top-u.bottom)/u.zoom/i}else{const u=o;a=2*Math.max(-f.applyMatrix4(o.matrixWorldInverse).z,1e-6)*Math.tan(bt.degToRad(u.fov)/2)/u.zoom/i}}t.scale.setScalar(a),t.updateMatrixWorld(!0)}dispose(){for(const t of this.drawn.values())this.remove(t.parts);this.drawn.clear();for(const t of this.lineMaterials.values())t.dispose();for(const t of this.fillMaterials.values())t.dispose();this.lineMaterials.clear(),this.fillMaterials.clear()}}function Kn(e){const t=new x,n=new At;return e.decompose(t,n,new x),new H().compose(t,n,new x(1,1,1))}const no=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],Hi=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],Gi=[[[.9,1],[-1,-1],[-.9,1],[1,-1]].map(([e,t])=>[e*.0215,t*.025]),[[-1,1],[0,-.1],[1,1],[0,-.1],[0,-.1],[0,-1]].map(([e,t])=>[e*.0175,t*.025]),[[-.95,1],[.95,1],[.95,1],[.95,.9],[.95,.9],[-1,-.9],[-1,-.9],[-1,-1],[-1,-1],[1,-1]].map(([e,t])=>[e*.02,t*.025])],_t=R().finite(),eo=N({name:I(),type:I(),lens:_t,sensor_width:_t,sensor_height:_t,sensor_fit:K(["AUTO","HORIZONTAL","VERTICAL"]),ortho_scale:_t,clip_start:_t,clip_end:_t,shift_x:_t,shift_y:_t,matrix:$(U([_t,_t,_t,_t])).length(4),passepartout:_t.default(0),display_size:_t.default(1)}),Xi={opening:.5,min:.1657359312880715,max:44.98528137423857},Mn={passepartout:"#000000",back:"#3d3d3d",overlay:"#000000",redalert:"#991616"};function Yi(e,t,n,o){const r=a=>Math.min(1,Math.max(-1,a));return[r(e[0]-n/(2*t)),r(e[1]+o/(2*t))]}function oo(e,t,n,o){const r=e.type==="ORTHO",a=e.sensor_fit==="VERTICAL"?e.sensor_height:e.sensor_width,i=e.sensor_fit==="AUTO"?t>=n:e.sensor_fit==="HORIZONTAL",f=(r?e.ortho_scale:a/e.lens)/2*o;return i?[f,f*n/t]:[f*t/n,f]}function Zi(e,t,n,o,r,a){const i=Math.max(n.width,1),f=Math.max(n.height,1),[u,_]=oo(e,i,f,1/o),[l,s]=oo(e,a,1,1),m=2*((e.sensor_fit==="AUTO"?a>=1:e.sensor_fit==="HORIZONTAL")?l:s),d=l/u,h=s/_,g=-2*r[0]*o,p=2*r[1]*o,v=e.shift_x*m-g*2*u,O=e.shift_y*m+p*2*_,b=new H().set(...e.matrix.flat()).premultiply(t),P=new x,T=new At;return b.decompose(P,T,new x),{name:e.name,position:P.toArray(),quaternion:[T.x,T.y,T.z,T.w],projection:e.type==="ORTHO"?"orthographic":"perspective",window:{left:v-u,right:v+u,top:O+_,bottom:O-_},near:e.clip_start,far:e.clip_end,frame:{left:.5-d/2+g,top:.5-h/2+p,width:d,height:h},passepartout:{color:Mn.passepartout,opacity:e.passepartout},border:{solid:Mn.back,dashed:Mn.overlay,locked:Mn.redalert}}}const Qi={color:[.8,.8,.8,1],roughness:.5,metallic:0},Ki=`
7148
7148
  uniform vec3 wbDir[4];
7149
7149
  uniform vec3 wbDiffuse[4];
7150
7150
  uniform vec3 wbSpecular[4];
@@ -7186,6 +7186,6 @@ vec3 volterWorkbenchLighting(vec3 baseColor, vec3 N, vec3 I) {
7186
7186
  diffuseLight *= diffuseColor * (1.0 - specEnergy);
7187
7187
  return diffuseLight + specularLight;
7188
7188
  }
7189
- `,Te=e=>xe.map(t=>{const[n=0,o=0,r=0]=e(t);return new x(n,o,r)}),Zi=Te(e=>e.direction).map(e=>e.normalize()),Qi=Te(e=>e.diffuse),Ki=Te(e=>e.specular),Ji=new Cn(...xe.map(e=>e.smooth));function ts(e,t){const[n,o,r]=e.color,a=new ha({side:t});return a.color.setRGB(n,o,r,vt),a.name="volter:blender-solid",a.onBeforeCompile=i=>{i.uniforms.wbDir={value:Zi},i.uniforms.wbDiffuse={value:Qi},i.uniforms.wbSpecular={value:Ki},i.uniforms.wbWrap={value:Ji},i.uniforms.wbRoughness={value:e.roughness},i.uniforms.wbMetallic={value:e.metallic},i.fragmentShader=i.fragmentShader.replace("void main() {",`${Yi}
7189
+ `,Se=e=>ye.map(t=>{const[n=0,o=0,r=0]=e(t);return new x(n,o,r)}),Ji=Se(e=>e.direction).map(e=>e.normalize()),ts=Se(e=>e.diffuse),ns=Se(e=>e.specular),es=new kn(...ye.map(e=>e.smooth));function os(e,t){const[n,o,r]=e.color,a=new va({side:t});return a.color.setRGB(n,o,r,vt),a.name="volter:blender-solid",a.onBeforeCompile=i=>{i.uniforms.wbDir={value:Ji},i.uniforms.wbDiffuse={value:ts},i.uniforms.wbSpecular={value:ns},i.uniforms.wbWrap={value:es},i.uniforms.wbRoughness={value:e.roughness},i.uniforms.wbMetallic={value:e.metallic},i.fragmentShader=i.fragmentShader.replace("void main() {",`${Ki}
7190
7190
  void main() {`).replace("#include <opaque_fragment>",`outgoingLight = volterWorkbenchLighting(diffuseColor.rgb, normal, isOrthographic ? vec3(0.0, 0.0, 1.0) : normalize(vViewPosition));
7191
- #include <opaque_fragment>`)},a.customProgramCacheKey=()=>"volter-blender-workbench",a}const ns=64;function es(e,t){return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>n===t[o]):e===t}function nn(e){for(let t=e;t;t=t.parent)if(!t.visible)return!1;return!0}function _e(e){if(e.determinant()<=0)return!1;const t=e.elements,n=Math.hypot(t[0],t[1],t[2]),o=Math.hypot(t[4],t[5],t[6]),r=Math.hypot(t[8],t[9],t[10]),a=(i,f)=>t[i]*t[f]+t[i+1]*t[f+1]+t[i+2]*t[f+2];return Number.isFinite(n+o+r)&&Math.min(n,o,r)>0&&Math.abs(a(0,4))<=1e-7*n*o&&Math.abs(a(0,8))<=1e-7*n*r&&Math.abs(a(4,8))<=1e-7*o*r}class os{constructor(t){this.root=t,this.batches=[],this.inverse=new B,this.matrix=new B,this.box=new gn,this.projection=new B,this.frustum=new Ln,this.camera=null,this.eligible=0,this.excluded={}}rebuild(t,n){if(this.clear(),!n)return;const o=new Map,r=a=>{this.excluded[a]=(this.excluded[a]??0)+1};this.inverse.copy(this.root.matrixWorld).invert();for(const a of t){const i=a;if(!i.isMesh)continue;if(i.isSkinnedMesh||i.isInstancedMesh||i.morphTargetInfluences||i.layers.mask!==1){r("deformationOrLayers");continue}const f=Array.isArray(i.material)?i.material:[i.material];if(f.some(l=>l.transparent||l.transmission>0||l.isShaderMaterial)){r("material");continue}if(f.some(l=>Lo(l,i.geometry).size>12)){r("attributeBudget");continue}if(this.matrix.multiplyMatrices(this.inverse,i.matrixWorld),!_e(this.matrix)){r("transform");continue}this.eligible++;const u=`${i.geometry.id}:${Array.isArray(i.material)?"slots":"single"}:`+f.map(l=>l.uuid).join(",")+`:${i.renderOrder}`,_=o.get(u);_?_.push(i):o.set(u,[i])}for(const a of o.values()){if(a.length<2)continue;const i=f=>{if(f.length>ns){this.box.makeEmpty();for(const d of f)this.box.expandByPoint(new x().setFromMatrixPosition(d.matrixWorld));const s=this.box.getSize(new x),c=s.x>=s.y&&s.x>=s.z?12:s.y>=s.z?13:14;f.sort((d,h)=>d.matrixWorld.elements[c]-h.matrixWorld.elements[c]);const m=Math.floor(f.length/2);i(f.slice(0,m)),i(f.slice(m));return}if(f.length<2)return;const u=f[0],_=new vo(u.geometry,u.material,f.length);_.name="Blender repeated geometry",_.userData.engineInternal=!0,_.matrixAutoUpdate=!1,_.renderOrder=u.renderOrder,_.instanceMatrix.setUsage(xo);const l={draw:_,members:f.map(s=>({mesh:s,layers:s.layers.mask}))};_.raycast=(s,c)=>{for(const{mesh:m}of l.members)m.layers.mask===0&&nn(m)&&m.raycast(s,c)},this.root.add(_),_.updateMatrixWorld(!0),this.batches.push(l)};i(a)}this.sync()}sync(){if(this.batches.length){this.inverse.copy(this.root.matrixWorld).invert();for(const{draw:t,members:n}of this.batches){let o=0,r=!1;for(const a of n){const{mesh:i}=a;if(this.matrix.multiplyMatrices(this.inverse,i.matrixWorld),!(i.parent!==null&&i.geometry===t.geometry&&es(i.material,t.material)&&_e(this.matrix))){i.layers.mask|=a.layers;continue}if(i.layers.mask&=~a.layers,!nn(i)||this.camera&&(!this.camera.layers.isEnabled(0)||i.frustumCulled&&!this.frustum.intersectsObject(i)))continue;const u=o*16;this.matrix.elements.some((_,l)=>Math.fround(_)!==t.instanceMatrix.array[u+l])&&(t.setMatrixAt(o,this.matrix),r=!0),o++}r||=t.count!==o||t.boundingSphere===null,t.count=o,r&&(t.instanceMatrix.needsUpdate=!0,t.computeBoundingBox(),t.computeBoundingSphere())}}}prepareDraw(t){t.updateMatrixWorld(),this.camera=t,this.projection.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projection)}finishDraw(){this.camera=null}clear(){this.camera=null;for(const{draw:t,members:n}of this.batches){for(const{mesh:o,layers:r}of n)o.layers.mask|=r;t.removeFromParent(),t.dispose()}this.batches.length=0,this.eligible=0,this.excluded={}}inspect(){return{batches:this.batches.length,instances:this.batches.reduce((t,{draw:n})=>t+n.count,0),eligible:this.eligible,excluded:{...this.excluded}}}}const un=64;function eo(e){for(let t=e.parent;t;t=t.parent)if(t.isGroup)return t.renderOrder;return 0}class as{constructor(t){this.root=t,this.objects=[],this.pools=new Map,this.hidden=[],this.inverse=new B,this.matrix=new B,this.projection=new B,this.frustum=new Ln,this.centre=new x,this.depth=new Cn,this.batches=0,this.instances=0,this.planState=[],this.planned=[],this.stateIndex=0,this.stateChanged=!1}setObjects(t){this.clear(),this.objects=[...t].filter(n=>n.isMesh===!0)}prepare(t){if(this.finishDraw(),!this.objects.length)return;if(t.updateMatrixWorld(),this.projection.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),!this.planChanged(t)){for(const a of this.planned){a.mesh.visible=!0;for(const i of a.members)i.layers.disable(0),this.hidden.push(i)}return}this.planned.length=0;for(const a of this.pools.values())for(const i of a)i.mesh.visible=!1,i.members.length=0;this.batches=this.instances=0,this.frustum.setFromProjectionMatrix(this.projection),this.inverse.copy(this.root.matrixWorld).invert();const n=[],o=new Map;for(const a of this.objects){const i=Array.isArray(a.material)?a.material:[a.material];if(!i.some(d=>d.visible&&d.transparent)||!nn(a)||!a.layers.test(t.layers)||a.frustumCulled&&!this.frustum.intersectsObject(a))continue;const f=a;f.boundingSphere!==void 0?(f.boundingSphere===null&&f.computeBoundingSphere?.(),this.centre.copy(f.boundingSphere.center)):(a.geometry.boundingSphere||a.geometry.computeBoundingSphere(),this.centre.copy(a.geometry.boundingSphere.center)),this.centre.applyMatrix4(a.matrixWorld);const u=this.centre.clone(),_=this.depth.set(u.x,u.y,u.z,1).applyMatrix4(this.projection).z;let l=null,s=null;const c=i.length===1?i[0]:null,m=eo(a);if(c&&c.visible&&c.transparent&&!c.isShaderMaterial&&!(c.transmission>0)&&(c.side!==ee||c.forceSinglePass)&&!a.isSkinnedMesh&&!a.morphTargetInfluences&&!a.isInstancedMesh&&a.layers.mask===1&&m===this.root.renderOrder){const d=a.geometry,h=d.index?.count??d.getAttribute("position").count,g=!Array.isArray(a.material)||d.groups.length===1&&d.groups[0].start===0&&d.groups[0].count===h&&d.groups[0].materialIndex===0,p=`${d.id}:${c.uuid}:${a.renderOrder}`;let v=o.get(p);v===void 0&&(v=Lo(c,d).size<=12,o.set(p,v)),this.matrix.multiplyMatrices(this.inverse,a.matrixWorld),g&&v&&_e(this.matrix)&&(l=c,s=p)}n.push({mesh:a,material:l,key:s,groupOrder:m,z:_,centre:u})}n.sort((a,i)=>a.groupOrder-i.groupOrder||a.mesh.renderOrder-i.mesh.renderOrder||i.z-a.z||a.mesh.id-i.mesh.id);const r=new Map;for(let a=0;a<n.length;){const i=n[a];let f=a+1;if(i.key!==null)for(;f<n.length&&n[f].key===i.key;)f++;const u=n[a-1],_=n[f],l=u?.z===i.z&&u.mesh.renderOrder===i.mesh.renderOrder||_?.z===n[f-1].z&&_.mesh.renderOrder===i.mesh.renderOrder;if(i.key!==null&&f-a>=2&&!l){let s=!0;for(let c=a+un;c<f;c+=un)n[c-1].z===n[c].z&&(s=!1);if(s)for(let c=a;c<f;c+=un){const m=Math.min(un,f-c);if(m<2)continue;const d=n[c],h=r.get(i.key)??0;r.set(i.key,h+1);let g=this.pools.get(i.key);g||(g=[],this.pools.set(i.key,g));let p=g[h];if(!p){const v=new vo(i.mesh.geometry,i.material,un);v.name="Blender ordered transparency",v.userData.engineInternal=!0,v.matrixAutoUpdate=!1,v.frustumCulled=!1,v.boundingSphere=new bo,v.instanceMatrix.setUsage(xo),p={mesh:v,members:[]};const b=p;v.raycast=(y,S)=>{if(v.visible)for(const T of b.members)nn(T)&&T.raycast(y,S)},g.push(p),this.root.add(v)}p.mesh.visible=!0,p.mesh.renderOrder=d.mesh.renderOrder,p.mesh.boundingSphere.center.copy(d.centre).applyMatrix4(this.inverse),p.mesh.updateMatrixWorld(!0);for(let v=0;v<m;v++){const b=n[c+v].mesh;this.matrix.multiplyMatrices(this.inverse,b.matrixWorld),p.mesh.setMatrixAt(v,this.matrix),p.members.push(b),b.layers.disable(0),this.hidden.push(b)}p.mesh.count=m,p.mesh.instanceMatrix.needsUpdate=!0,this.planned.push(p),this.batches++,this.instances+=m}}a=f}}inspect(){return{batches:this.batches,instances:this.instances}}observe(t){this.planState[this.stateIndex]!==t&&(this.planState[this.stateIndex]=t,this.stateChanged=!0),this.stateIndex++}planChanged(t){this.stateIndex=0,this.stateChanged=this.planState.length===0,this.observe(t.layers.mask);for(const n of this.projection.elements)this.observe(n);for(const n of this.root.matrixWorld.elements)this.observe(n);for(const n of this.objects){this.observe(n.parent?.id??-1),this.observe(nn(n)?1:0),this.observe(n.layers.mask),this.observe(n.renderOrder),this.observe(eo(n)),this.observe(n.frustumCulled?1:0),this.observe(n.morphTargetInfluences?1:0);for(const i of n.matrixWorld.elements)this.observe(i);const o=n.geometry;this.observe(o.id),this.observe(o.drawRange.start),this.observe(o.drawRange.count),this.observe(o.index?.count??o.getAttribute("position").count),this.observe(o.groups.length);for(const i of o.groups)this.observe(i.start),this.observe(i.count),this.observe(i.materialIndex??0);const r=n.boundingSphere??o.boundingSphere;this.observe(r?.center.x??0),this.observe(r?.center.y??0),this.observe(r?.center.z??0),this.observe(r?.radius??-1);const a=Array.isArray(n.material)?n.material:null;if(this.observe(a?.length??-1),a)for(const i of a)this.observeMaterial(i);else this.observeMaterial(n.material)}return this.stateChanged||=this.planState.length!==this.stateIndex,this.planState.length=this.stateIndex,this.stateChanged}observeMaterial(t){this.observe(t.uuid),this.observe(t.version),this.observe(t.visible?1:0),this.observe(t.transparent?1:0),this.observe(t.side),this.observe(t.forceSinglePass?1:0),this.observe(t.transmission??0)}finishDraw(){for(const t of this.hidden)t.layers.enable(0);this.hidden.length=0;for(const t of this.pools.values())for(const{mesh:n}of t)n.visible=!1}clear(){this.finishDraw();for(const t of this.pools.values())for(const{mesh:n}of t)n.removeFromParent(),n.dispose();this.pools.clear(),this.planned.length=0,this.planState.length=0,this.objects=[],this.batches=this.instances=0}}const oo=64*1024*1024,ao=150;class rs{constructor(t){this.invalidate=t,this.groups=new Map,this.cache=new Map,this.swapped=[],this.queue=[],this.worker=null,this.pending=null,this.nextId=0,this.signature="",this.identities=new WeakMap,this.nextIdentity=0,this.bytes=0,this.unavailable=null,this.timer=null,this.cameraWorld=new B,this.cameraProjection=new B,this.cameraKnown=!1,this.movedAt=-1/0,this.projection=new B,this.frustum=new Ln,this.centre=new x,this.drawnMeshes=0,this.fullTriangles=0,this.motionTriangles=0,this.lastNavigation={meshes:0,fullTriangles:0,motionTriangles:0,tooClose:0},this.quietTimer=null}setObjects(t){const n=new Map;for(const i of t){const f=i;if(!f.isMesh||f.isSkinnedMesh||f.isInstancedMesh||f.morphTargetInfluences)continue;const u=f.geometry,_=u.getAttribute("position");if(!u.index||u.index.count<6144||!_||_.count>2e5||Object.values(u.attributes).some(s=>!(s instanceof lt)||s.isFloat16BufferAttribute||s.isInstancedBufferAttribute)||Object.keys(u.morphAttributes).length||u.drawRange.start!==0||u.drawRange.count<u.index.count||Array.isArray(f.material)&&(f.material.length!==1||u.groups.length!==1||u.groups[0].start!==0||u.groups[0].count!==u.index.count||u.groups[0].materialIndex!==0))continue;const l=n.get(u);l?l.push(f):n.set(u,[f])}this.groups=n;const o=i=>{let f=this.identities.get(i);return f===void 0&&(f=++this.nextIdentity,this.identities.set(i,f)),f},r=[...n].map(([i])=>`${i.id}:${o(i.index)}:${i.index.version}:`+Object.entries(i.attributes).map(([f,u])=>`${f}:${o(u)}:${u.version}`).join(",")).join(";");if(r===this.signature)return;this.releaseCopies(),this.signature=r,this.unavailable=null;const a=[...n].filter(([,i])=>i.length>=3);a.reduce((i,[f,u])=>i+f.index.count*u.length,0)<6e6||(a.sort(([i,f],[u,_])=>u.index.count*_.length-i.index.count*f.length),this.queue=a.map(([i])=>i),this.next())}next(){if(this.pending||this.unavailable||this.bytes>=oo)return;const t=this.queue.shift();if(!t){this.worker?.terminate(),this.worker=null;return}if(!this.worker)try{this.worker=new Worker(new URL("/assets/blender-motion-worker-ECrqnoHW.js",import.meta.url),{type:"module"}),this.worker.onmessage=c=>this.receive(c.data),this.worker.onerror=c=>{this.unavailable=c.message||"Navigation geometry worker unavailable",this.worker?.terminate(),this.worker=null,this.pending=null,this.queue.length=0}}catch(c){this.unavailable=String(c);return}const n=t.getAttribute("position"),o=new Float32Array(n.count*3);for(let c=0;c<n.count;c++)o[c*3]=n.getX(c),o[c*3+1]=n.getY(c),o[c*3+2]=n.getZ(c);const r=Object.entries(t.attributes).filter(([c])=>c==="normal"||/^uv\d*$/.test(c)),a=r.reduce((c,[,m])=>c+m.itemSize,0),i=new Float32Array(n.count*a),f=[];let u=0;for(const[c,m]of r){for(let d=0;d<m.itemSize;d++)f.push(c==="normal"?.5:1);for(let d=0;d<n.count;d++)for(let h=0;h<m.itemSize;h++)i[d*a+u+h]=m.getComponent(d,h);u+=m.itemSize}const _=new Uint32Array(t.index.array),l=++this.nextId;this.pending={id:l,geometry:t};const s={id:l,positions:o,indices:_,attributes:i,stride:a,weights:f};this.worker.postMessage(s,[o.buffer,_.buffer,i.buffer])}receive(t){const n=this.pending;if(!n||n.id!==t.id)return;this.pending=null;const{geometry:o}=n,r=t.indices;if(t.refusal&&(this.unavailable=t.refusal,this.worker?.terminate(),this.worker=null,this.queue.length=0),r&&t.error!==void 0&&Number.isFinite(t.error)&&r.length>0&&r.length<o.index.count*.75){const a=[],i=new Map;for(let u=0;u<r.length;u++){const _=r[u];let l=i.get(_);l===void 0&&(l=a.length,a.push(_),i.set(_,l)),r[u]=l}const f=r.byteLength+Object.values(o.attributes).reduce((u,_)=>u+a.length*_.itemSize*_.array.BYTES_PER_ELEMENT,0);if(this.bytes+f<=oo){const u=new an;u.setIndex(new lt(r,1));for(const[_,l]of Object.entries(o.attributes)){const s=l,c=s.array.constructor,m=new c(a.length*s.itemSize);for(let d=0;d<a.length;d++)for(let h=0;h<s.itemSize;h++)m[d*s.itemSize+h]=s.array[a[d]*s.itemSize+h];u.setAttribute(_,new lt(m,s.itemSize,s.normalized))}o.boundingSphere||o.computeBoundingSphere(),u.boundingSphere=o.boundingSphere.clone(),u.boundingBox=o.boundingBox?.clone()??null,o.groups.length===1&&u.addGroup(0,r.length,o.groups[0].materialIndex),u.userData={...o.userData},this.cache.set(o,{geometry:u,error:t.error,bytes:f}),this.bytes+=f}}this.timer=setTimeout(()=>{this.timer=null,this.next()},0)}prepare(t,n,o){if(this.finish(),this.drawnMeshes=this.fullTriangles=this.motionTriangles=0,!n||!(o>0))return!1;const r=performance.now(),a=this.cameraKnown&&(!t.matrixWorld.equals(this.cameraWorld)||!t.projectionMatrix.equals(this.cameraProjection));if(this.cameraKnown=!0,this.cameraWorld.copy(t.matrixWorld),this.cameraProjection.copy(t.projectionMatrix),a&&(this.movedAt=r,this.quietTimer&&clearTimeout(this.quietTimer),this.quietTimer=setTimeout(()=>{this.quietTimer=null,this.invalidate()},ao+1)),r-this.movedAt>ao)return!1;this.projection.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projection);let i=0;for(const[f,u]of this.cache)for(const _ of this.groups.get(f)??[]){if(!nn(_)||_.frustumCulled&&!this.frustum.intersectsObject(_))continue;const l=_.matrixWorld.elements,s=Math.hypot(l[0],l[1],l[2],l[4],l[5],l[6],l[8],l[9],l[10]),c=f.boundingSphere;this.centre.copy(c.center).applyMatrix4(_.matrixWorld).applyMatrix4(t.matrixWorldInverse);const m=t.isPerspectiveCamera?-this.centre.z-c.radius*s:1,d=u.error*s*Math.abs(t.projectionMatrix.elements[5])*o/(2*m);if(!(m>0)||d>1){i++;continue}this.swapped.push({mesh:_,geometry:f}),_.geometry=u.geometry,this.drawnMeshes++,this.fullTriangles+=f.index.count/3,this.motionTriangles+=u.geometry.index.count/3}return this.lastNavigation={meshes:this.drawnMeshes,fullTriangles:this.fullTriangles,motionTriangles:this.motionTriangles,tooClose:i},this.swapped.length>0}finish(){for(const{mesh:t,geometry:n}of this.swapped)t.geometry=n;this.swapped.length=0}inspect(){return{copies:this.cache.size,bytes:this.bytes,queued:this.queue.length,pending:this.pending!==null,unavailable:this.unavailable,lastNavigation:{...this.lastNavigation}}}releaseCopies(){this.finish(),this.timer&&clearTimeout(this.timer),this.timer=null,this.worker?.terminate(),this.worker=null,this.pending=null,this.queue=[];for(const t of this.cache.values())t.geometry.dispose();this.cache.clear(),this.bytes=0}clear(){this.releaseCopies(),this.quietTimer&&clearTimeout(this.quietTimer),this.quietTimer=null,this.groups.clear(),this.signature="",this.cameraKnown=!1,this.movedAt=-1/0}}const is={WIREFRAME:"wireframe",SOLID:"solid",MATERIAL:"preview",RENDERED:"rendered"},z=N().finite(),Bo=L([z,z,z]),Mn=L([N().int().nonnegative(),N().int().nonnegative()]),dt={name:R(),domain:H(["POINT","EDGE","FACE","CORNER"])},ss=Ra("type",[M({...dt,type:q("FLOAT2"),data:D(L([z,z]))}).strict(),M({...dt,type:q("FLOAT_VECTOR"),data:D(Bo)}).strict(),M({...dt,type:q("FLOAT_COLOR"),data:D(L([z,z,z,z]))}).strict(),M({...dt,type:q("BYTE_COLOR"),data:D(L([z,z,z,z]))}).strict(),M({...dt,type:q("QUATERNION"),data:D(L([z,z,z,z]))}).strict(),M({...dt,type:q("FLOAT4"),data:D(L([z,z,z,z]))}).strict(),M({...dt,type:q("FLOAT4X4"),data:D(D(z).length(16))}).strict(),M({...dt,type:q("INT16_2D"),data:D(L([N().int(),N().int()]))}).strict(),M({...dt,type:q("INT32_2D"),data:D(L([N().int(),N().int()]))}).strict(),M({...dt,type:q("FLOAT"),data:D(z)}).strict(),M({...dt,type:q("INT"),data:D(N().int())}).strict(),M({...dt,type:q("INT8"),data:D(N().int())}).strict(),M({...dt,type:q("BOOLEAN"),data:D(Q())}).strict(),M({...dt,type:q("STRING"),data:D(R())}).strict()]),ls=M({positions:W(Float32Array),normals:W(Float32Array).nullable(),uv:W(Float32Array).nullable(),uvLayers:D(M({name:R(),data:W(Float32Array)}).strict()).optional(),attributeLayers:D(M({name:R(),data:W(Float32Array)}).strict()).optional(),orco:W(Float32Array).nullable().optional(),indices:W(Uint32Array),groups:D(M({start:N().int().nonnegative(),count:N().int().nonnegative(),materialIndex:N().int().nonnegative()}).strict()),hash:R()}).strict(),fs=M({v:D(Bo),f:D(D(N().int().nonnegative())),e:D(Mn).optional(),edge_order:D(Mn).optional(),m:D(N().int().nonnegative()).optional(),s:D(Q()).optional(),sharp:D(Mn).optional(),seams:D(Mn).optional(),creases:D(L([z,z,z])).optional(),attributes:D(ss).optional(),active_uv:R().nullable().optional(),render_uv:R().nullable().optional()}).strict(),cs=M({store:N().int().optional(),revision:N().int(),unchanged:q(!0)}).strict(),us=M({co:Lt([W(Float32Array),W(Float64Array)]),cornerNormal:W(Float32Array).optional(),cornerTri:W(Uint32Array).optional(),orco:W(Float32Array).optional(),faceStart:W(Uint32Array),corner:W(Uint32Array),cornerEdge:W(Int32Array),edge:W(Uint32Array),edgeSharp:W(Uint8Array),edgeSeam:W(Uint8Array),edgeCrease:W(Float32Array),material:W(Uint32Array),smooth:W(Uint8Array),vertSelect:W(Uint8Array),vertHide:W(Uint8Array),edgeSelect:W(Uint8Array),edgeHide:W(Uint8Array),faceSelect:W(Uint8Array),faceHide:W(Uint8Array)}).strict(),ms=M({name:R(),domain:H(["POINT","EDGE","FACE","CORNER"]),type:R(),data:Ia(e=>ArrayBuffer.isView(e))}).strict(),Uo=M({columns:us,attributes:D(ms),activeUv:R().nullable(),renderUv:R().nullable(),counts:M({verts:N().int().nonnegative(),edges:N().int().nonnegative(),faces:N().int().nonnegative(),corners:N().int().nonnegative()}).strict(),revision:N().int().nonnegative()}).strict(),_s=Lt([ls,Uo,fs,cs]),ro=new Set;function ds(e,t){const n=new Blob([e],{type:t}),o=new ba;let r=!1;o.addEventListener("dispose",()=>{r=!0,o.image?.close?.()});const a=createImageBitmap(n,{imageOrientation:"flipY",premultiplyAlpha:"none",colorSpaceConversion:"none"}).then(i=>{if(r){i.close();return}o.image=i,o.needsUpdate=!0,ht()}).finally(()=>{ro.delete(a)});return ro.add(a),a.catch(()=>{}),{texture:o,ready:a}}function hs(e,t,n,o){const r=new kn(e,t,n,$n,xa);return r.flipY=!1,r.colorSpace=o==="data"?In:$t,r.needsUpdate=!0,r}function ps(e,t,n){if(t.length===0)throw new Error(`Runtime image ${e} is tiled with no tiles`);const o=Math.max(...t.map(l=>l.width)),r=Math.max(...t.map(l=>l.height)),a=new Uint8Array(o*r*4*t.length),i=Math.max(...t.map(l=>l.number-1001))+1,f=new Float32Array(i*2*4);for(let l=0;l<i;l++)f[l*4]=-1;t.forEach((l,s)=>{const c=l.rgba??(l.rgbaBase64?re(l.rgbaBase64):void 0);if(!c)throw new Error(`Runtime image ${e} tile ${l.number} carries no raster`);for(let d=0;d<l.height;d++)a.set(c.subarray(d*l.width*4,(d+1)*l.width*4),(s*r+d)*o*4);const m=l.number-1001;f[m*4]=s,f.set([0,0,l.width/o,l.height/r],(i+m)*4)});const u=new va(a,o,r,t.length);u.colorSpace=n==="data"?In:$t,u.magFilter=Xt,u.minFilter=yo,u.generateMipmaps=!0,u.needsUpdate=!0;const _=new kn(f,i,2,$n,_o);return _.magFilter=_.minFilter=oe,_.needsUpdate=!0,{tiles:u,map:_,frame:t}}const gs=M({width:N().int().positive(),height:N().int().positive(),revision:N().int().nonnegative(),rgba:W(Uint8Array).optional(),rgbaBase64:R().optional(),colorspace:H(["sRGB","data"]).optional(),tiles:D(M({number:N().int().min(1001),width:N().int().positive(),height:N().int().positive(),rgba:W(Uint8Array).optional(),rgbaBase64:R().optional()}).strict()).optional()}).strict(),vs=M({revision:N().int().nonnegative(),encoded:W(Uint8Array).optional(),encodedBase64:R().optional(),mime:H(["image/png","image/jpeg"]),colorspace:H(["sRGB","data"]).optional()}).strict(),Wo=Lt([gs,vs]),Kn=M({image:M({name:R(),revision:N().int().nonnegative()}).strict(),extension:H(["REPEAT","EXTEND","MIRROR","CLIP"]).default("REPEAT"),uv:R(),tint:L([z,z,z]).optional()}).strict(),xs=M({name:R(),color:L([z,z,z,z]),roughness:z,metallic:z,transmission:z,ior:z,physical:wi.optional(),normal_texture:Kn.optional(),normal_strength:z.default(1),normal_space:H(["TANGENT","OBJECT"]).default("TANGENT"),normal_directx:Q().default(!1),texture:Kn.optional(),roughness_texture:Kn.optional(),emission:M({color:L([z,z,z]),strength:z}).strict().optional(),graph:Zr.optional(),viewport:M({color:L([z,z,z,z]),roughness:z,metallic:z}).strict().optional()}).strict(),bs=M({session:R(),revision:N().int().nonnegative(),volumes:yt(R(),Fo).default({}),lights:yt(R(),zr).default({}),world:jr.nullable().default(null),meshes:yt(R(),_s),materials:yt(R(),xs),images:yt(R(),Wo).default({}),objects:D(M({id:R(),name:R(),type:H(["MESH","CURVE","SURFACE","FONT","META","ARMATURE","LATTICE","VOLUME","EMPTY","CAMERA","LIGHT","SPEAKER","GREASEPENCIL","POINTCLOUD","LIGHT_PROBE"]),mesh:R().nullable(),volume:R().nullable().optional(),light:R().nullable().optional(),materials:D(R().nullable()),matrix:D(L([z,z,z,z])).length(4),visible:Q(),render_visible:Q().default(!0),selected:Q(),parent:R().nullable(),texspace:L([L([z,z,z]),L([z,z,z])]).optional(),default_color:R().optional()}).strict()),active:R().nullable(),mode:R(),cameras:yt(R(),yt(R(),Oo())).default({}),warnings:D(R()).default([]),updated:D(R()).default([]),frame:N().int().default(0),armatures:yt(R(),Ca).default({}),weights:Pi.nullable().default(null),cursor:zi.optional(),camera_view:M({scene_camera:R().nullable(),view_layer_cameras:D(R()),aspect:N().finite().positive()}).optional(),light_distances:yt(R(),L([N().finite(),N().finite()])).default({}),empties:yt(R(),Li).default({}),view:M({location:L([N(),N(),N()]),rotation:L([N(),N(),N(),N()]),distance:N().finite(),perspective:H(["PERSP","ORTHO","CAMERA"]),lens:N().finite().positive().default(50),shading:H(["WIREFRAME","SOLID","MATERIAL","RENDERED"]).optional()}).nullable().optional(),subject:M({frame:N().int(),body:R(),markers:D(L([N().int(),R()]))}).optional(),units:M({system:H(["NONE","METRIC","IMPERIAL"]),scale_length:N().finite()}).optional()}).strict();function ys(e,t){for(let n=0,o=e.length-1;n<e.length&&o>=0;n++,o--){if(e[n][0]===t)return e[n][1];if(n===o)break;if(e[o][0]===t)return e[o][1]}return null}const ws={METRIC:[[1e-6,"Micrometers"],[.001,"Millimeters"],[.01,"Centimeters"],[.1,"10 Centimeters"],[1,"Meters"],[10,"10 Meters"],[100,"100 Meters"],[1e3,"Kilometers"]],IMPERIAL:[[254e-7,"Thou"],[.0254,"Inches"],[.3048,"Feet"],[.9144,"Yards"],[20.1168,"Chains"],[201.168,"Furlongs"],[1609.344,"Miles"]]};class Dn{constructor(){this.root=new it,this.instances=new os(this.root),this.transparentInstances=new as(this.root),this.motionGeometry=new rs(ht),this.drawBatching=!0,this.objects=new Map,this.meshes=new Map,this.volumes=new Map,this.materials=new Map,this.lights=new Map,this.lighting=new Vr,this.world=new be,this.armatureOverlay=new Ga,this.weightOverlay=new Ii,this.cursorOverlay=new $i,this.extrasOverlay=new Bi,this.armatureRoot=new it,this.weightRoot=new it,this.cursorRoot=new it,this.cameraExtrasRoot=new it,this.lightExtrasRoot=new it,this.emptyExtrasRoot=new it,this.rendered=!1,this.heldRendered=null,this.worldApplied=null,this.worldKey="null",this.capturing=!1,this.workbench=!1,this.workbenchMaterials=new Map,this.fallback=new en({color:12172998,roughness:.72}),this.textures=new Map,this.textureNames=new Map,this.roughnessTextureNames=new Map,this.textureSamplers=new yi,this.graphSamplers=new Map,this.photograph=!1,this.graphs=new Map,this.frame=null,this.retiredSessions=new Set,this.geometryBuilds=0,this.submittedMeshes=new Map,this.submitted=null,this.submittedSession=null,this.photographs=[],this.frameListeners=new Set,this.followers=new Set,this.leader=null,this.cameraViewZoom=qi,this.cameraViewPan=Hi,this.mode=null,this.awaitedImages=new Set,this.lookingThrough=null,this.staged=null;const t=this.root.updateMatrixWorld.bind(this.root);this.root.updateMatrixWorld=n=>{t(n),this.instances.sync()},this.root.name="Model",this.root.matrixAutoUpdate=!1,this.root.matrix.set(1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1),this.root.updateMatrixWorld(!0);for(const[n,o]of[[this.armatureRoot,this.armatureOverlay.group],[this.weightRoot,this.weightOverlay.group],[this.cursorRoot,this.cursorOverlay.group],[this.cameraExtrasRoot,this.extrasOverlay.cameras],[this.lightExtrasRoot,this.extrasOverlay.lights],[this.emptyExtrasRoot,this.extrasOverlay.empties]])n.matrixAutoUpdate=!1,n.matrix.copy(this.root.matrix),n.add(o),n.updateMatrixWorld(!0);this.armatureRoot.name="BlenderBones",this.weightRoot.name="BlenderWeights",this.cursorRoot.name="Blender3DCursor",this.cameraExtrasRoot.name="BlenderCameraExtras";for(const n of[this.cameraExtrasRoot,this.lightExtrasRoot,this.emptyExtrasRoot])n.userData.volterPickable=!0;this.lightExtrasRoot.name="BlenderLightExtras",this.emptyExtrasRoot.name="BlenderEmptyExtras"}compiledGraph(t){const n=JSON.stringify(t);let o=this.graphs.get(n);return o||(o=ci(t),this.graphs.size>256&&this.graphs.clear(),this.graphs.set(n,o)),o}mirrorPose(t){let n=null;for(const[a,i]of this.objects)if(i===t){n=a;break}if(n===null)return;const o=this.leader?[this.leader,...this.leader.followers]:[...this.followers];let r=!1;for(const a of o){if(a===this)continue;const i=a.objects.get(n);i!==void 0&&(i.matrix.copy(t.matrix),i.matrix.decompose(i.position,i.quaternion,i.scale),i.updateMatrixWorld(!0),r=!0)}r&&ht()}subscribeFrames(t){return this.frameListeners.add(t),()=>{this.frameListeners.delete(t)}}onChange(t){const n=this.subscribeFrames(t),o=Fa(t);return()=>{n(),o()}}blenderObjectName(t){for(const[n,o]of this.objects)if(o===t)return this.frame?.objects.find(r=>r.id===n)?.name??null;return null}noteSavedShading(t){this.frame?.view&&(this.frame.view.shading=t)}savedView(){const t=this.frame?.view;if(!t)return null;const[n,o,r,a]=t.rotation,i=new Tt(o,r,a,n),f=new x(...t.location).applyMatrix4(this.root.matrix),u=_=>_.applyQuaternion(i).applyMatrix4(this.root.matrix).normalize();return{target:f.toArray(),direction:u(new x(0,0,1)).toArray(),up:u(new x(0,1,0)).toArray(),distance:t.distance,projection:t.perspective==="ORTHO"?"orthographic":"perspective",lens:t.lens,drawMode:t.shading?is[t.shading]:null}}cameraViewCamera(){const t=this.frame,n=t?.camera_view;return!t||!n?null:n.scene_camera!==null&&t.cameras[n.scene_camera]?n.scene_camera:t.active!==null&&t.cameras[t.active]?t.active:n.view_layer_cameras.find(o=>t.cameras[o])??null}blenderPose(t,n){const o=new B().copy(this.root.matrix).invert(),r=new B().compose(new x(...t),new Tt(...n),new x(1,1,1)).premultiply(o),a=new x,i=new Tt;return r.decompose(a,i,new x),{location:a.toArray(),rotation:[i.w,i.x,i.y,i.z]}}cameraView(t,n,o,r){const a=this.frame,i=to.safeParse(a?.cameras[t]);return!a?.camera_view||!i.success?null:Gi(i.data,this.root.matrix,n,o,r,a.camera_view.aspect)}subjectLine(t){const n=this.frame?.subject;if(n===void 0)return null;const o=t??n.frame,r=ys(n.markers,o);return`(${o})${n.body}${r===null?"":` <${r}>`}`}gridUnitName(t){const n=this.frame?.units;if(n===void 0||n.system==="NONE")return null;const o=ws[n.system],r=6*t,a=1/(n.scale_length||1);return(o.find(([f])=>f*a>r)??o[o.length-1])[1]}blenderSelection(){const t=this.frame;return t===null?{selected:[],active:null}:{selected:t.objects.filter(n=>n.selected).map(n=>n.name),active:t.active}}setStageMode(t){this.mode=t}stageMode(){return this.mode}objectForBlenderName(t){const n=this.frame?.objects.find(o=>o.name===t);return n===void 0?null:this.objects.get(n.id)??null}replacePresentedObject(t,n){for(const[o,r]of this.objects)if(r===t){const a=t.parent,i=[...t.children];t.removeFromParent();for(const f of i)n.add(f);a?.add(n),this.objects.set(o,n),this.rebuildInstances();return}}studioLights(){return this.lighting.group}overlayGroups(){return[{kind:"skeletons",object:this.armatureRoot},{kind:"weights",object:this.weightRoot},{kind:"cursor",object:this.cursorRoot},{kind:"cameras",object:this.cameraExtrasRoot},{kind:"lights",object:this.lightExtrasRoot},{kind:"empties",object:this.emptyExtrasRoot}]}placeCursor(t,n,o){const r=new Set(this.objects.values()),a=this.cursorOverlay.placementAt(t,n,o,this.root,i=>r.has(i));return a!==null&&(this.cursorOverlay.show(a),ht()),a}holdRendered(t){t!==this.heldRendered&&(this.heldRendered=t,!this.capturing&&this.report(t===null?this.applyRendered(!1):this.applyRendered(!0,t())))}refreshRendered(){if(this.heldRendered===null||this.capturing)return;const t=this.heldRendered();this.worldKeyFor(t)!==this.worldApplied&&this.report(this.applyRendered(!0,t))}worldKeyFor(t){const o=t.isOrthographicCamera?t.getWorldDirection(new x).toArray().map(r=>r.toFixed(1)).join(","):"";return`${t.uuid}:${o}:${this.worldKey}`}report(t){t.then(ht,n=>console.error(`Rendered shading could not be applied: ${n instanceof Error?n.message:String(n)}`))}setWorkbench(t){t!==this.workbench&&(this.workbench=t,this.applyWorkbench(),ht())}applyWorkbench(){const t=this.workbench&&!this.rendered,n=new Set;for(const o of this.frame?.objects??[]){if(o.mesh===null||o.volume)continue;const r=this.objects.get(o.id);if(!r?.isMesh)continue;const i=(o.materials.length?o.materials:[null]).map(f=>{const u=f===null?this.fallback:this.materials.get(f)??this.fallback;return t?this.workbenchFor(f,u.side,n):u});r.material=o.materials.length?i:i[0]}for(const[o,r]of this.workbenchMaterials)n.has(o)||(r.dispose(),this.workbenchMaterials.delete(o));this.rebuildInstances()}rebuildInstances(){this.transparentInstances.clear(),this.instances.rebuild(this.objects.values(),this.drawBatching&&!this.rendered),this.drawBatching&&!this.rendered&&this.transparentInstances.setObjects(this.objects.values()),this.motionGeometry.setObjects(this.objects.values())}setDrawBatching(t){t!==this.drawBatching&&(this.drawBatching=t,this.rebuildInstances(),ht())}prepareDraw(t,n){try{this.instances.prepareDraw(t),this.root.updateMatrixWorld(!0),this.motionGeometry.prepare(t,!this.rendered&&(this.mode??this.frame?.mode)==="OBJECT"&&n?.interactive===!0,n?.height??0)&&this.instances.sync(),this.transparentInstances.prepare(t)}catch(o){throw this.motionGeometry.finish(),this.instances.finishDraw(),this.transparentInstances.finishDraw(),o}return()=>{this.motionGeometry.finish(),this.instances.finishDraw(),this.transparentInstances.finishDraw()}}workbenchFor(t,n,o){const r=(t!==null?this.frame?.materials[t]?.viewport:void 0)??Xi,a=`${r.color.join(",")}|${r.roughness}|${r.metallic}|${n}`;o.add(a);let i=this.workbenchMaterials.get(a);return i||(i=ts(r,n),this.workbenchMaterials.set(a,i)),i}renderedHeld(){return this.heldRendered!==null}async setRendered(t,n){return this.capturing=t,!t&&this.heldRendered!==null?this.applyRendered(!0,this.heldRendered()):this.applyRendered(t,n)}async applyRendered(t,n){const o=(t?Ze(this.frame?.world)?.extinction:null)??new x;for(const a of[...this.materials.values(),this.fallback])Ti(a,o);this.rendered=t,this.lighting.setRendered(t);const r=t&&n?this.worldKeyFor(n):null;t?(this.capturing||r!==this.worldApplied)&&this.world.apply(this.root,this.frame?.world??null,n):this.world.clear(),this.worldApplied=this.capturing?null:r,this.applyVisibility(),this.applyWorkbench(),this.applyShadows(t,n),t&&(await Dr(),await Promise.all([...this.textures.values()].map(a=>a.ready)),await this.world.ready())}applyShadows(t,n){this.root.updateMatrixWorld(!0);const o=[];for(const u of this.objects.values()){const _=u;if(_.isMesh&&(_.castShadow=t,_.receiveShadow=t,t&&_.visible)){const l=new gn().setFromObject(_);l.isEmpty()||o.push(l)}}if(!t||!o.length)return;const a=o.reduce((u,_)=>u.union(_),new gn).getBoundingSphere(new bo),i=n?new Ln().setFromProjectionMatrix(new B().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse)):null,f=i?o.flatMap(u=>Wr(u,i)):[];for(const u of this.lights.values())u.isDirectionalLight&&n?qr(u,f,o):$r(u,a.center,a.radius)}applyOverlays(t){const n=i=>{const f=t.objects.find(u=>u.name===i);return f===void 0?null:new B().set(...f.matrix.flat())},o=[...this.armatureOverlay.apply(t.armatures,n)],r=t.weights?this.objects.get(t.objects.find(i=>i.name===t.weights?.object)?.id??""):void 0,a=this.weightOverlay.apply(t.weights,r??null,t.weights?n(t.weights.object):null);return a!==null&&o.push(a),this.cursorOverlay.apply(t.cursor),this.applyExtras(t),o}setCameraViewShowing(t){this.lookingThrough!==t&&(this.lookingThrough=t,this.frame&&this.applyExtras(this.frame),ht())}applyExtras(t){const n={};for(const[o,r]of Object.entries(t.cameras)){const a=to.safeParse(r);a.success&&(n[o]=a.data)}this.extrasOverlay.apply({lookingThrough:this.lookingThrough,lightDistances:t.light_distances,objects:t.objects.filter(o=>o.visible),active:t.active,cameras:n,lights:t.lights,empties:t.empties,sceneCamera:t.camera_view?.scene_camera??null,renderAspect:t.camera_view?.aspect??1,presented:o=>{const r=t.objects.find(a=>a.name===o);return r?this.objects.get(r.id)??null:null},image:o=>{const r=this.textures.get(o);if(!r)return null;const a=r.texture.image,i=r.width||a?.width||0,f=r.height||a?.height||0;return(i===0||f===0)&&r.ready&&!this.awaitedImages.has(o)&&(this.awaitedImages.add(o),r.ready.then(()=>{this.awaitedImages.delete(o),this.frame&&this.applyExtras(this.frame),ht()},()=>this.awaitedImages.delete(o))),{texture:r.texture,width:i,height:f}}})}applyVisibility(){for(const t of this.frame?.objects??[]){const n=this.objects.get(t.id);if(n&&(n.visible=this.rendered?t.render_visible:t.visible),!t.light)continue;const o=this.lights.get(t.light);o&&(o.visible=this.rendered&&t.render_visible)}this.armatureOverlay.group.visible=!this.capturing,this.weightOverlay.group.visible=!this.capturing,this.cursorOverlay.group.visible=!this.capturing;for(const t of[this.extrasOverlay.cameras,this.extrasOverlay.lights,this.extrasOverlay.empties])t.visible=!this.capturing}stageFrame(t){if(t.abort||!t.mesh&&!t.image){for(const o of this.staged?.meshes.values()??[])o.geometry.dispose();this.staged=t.abort?null:{session:t.session,revision:t.revision,meshes:new Map,images:new Map};return}const n=this.staged;if(!n||n.session!==t.session||n.revision!==t.revision)throw new Error("Blender frame piece does not belong to the pending revision");if(t.mesh!==void 0){const o=Uo.parse(t.piece);if(n.meshes.has(t.mesh))throw new Error("Duplicate Blender mesh piece");const r=`revision:${o.revision}`;n.meshes.set(t.mesh,{signature:r,geometry:En(De({...o.columns,attributes:o.attributes,activeUv:o.activeUv,renderUv:o.renderUv},r))})}else if(t.image!==void 0){if(n.images.has(t.image))throw new Error("Duplicate Blender image piece");n.images.set(t.image,Wo.parse(t.piece))}}applyFrame(t){const n=this.frame===null?null:{session:this.frame.session,revision:this.frame.revision},o=bs.parse(t),r=this.staged;if(r&&(r.session!==o.session||r.revision!==o.revision))throw new Error("Blender frame manifest does not match its staged revision");if(r)for(const[l,s]of r.images)o.images[l]=s;if(this.retiredSessions.has(o.session))throw new Error("The runtime session was replaced; its delayed frame cannot overwrite the active model");if(this.frame?.session===o.session&&o.revision<this.frame.revision)throw new Error("The runtime frame is older than the displayed model");const a=new Set(o.objects.map(l=>l.id));if(a.size!==o.objects.length)throw new Error("Runtime object IDs must be unique");const i=new Map(o.objects.map(l=>[l.id,l]));for(const l of o.objects){if(l.mesh!==null&&!o.meshes[l.mesh])throw new Error(`Missing runtime mesh ${l.mesh}`);if(l.volume&&(!o.volumes[l.volume]||l.mesh!==null))throw new Error(`Invalid runtime volume ${l.volume}`);if(l.light&&(!o.lights[l.light]||l.mesh!==null))throw new Error(`Invalid runtime light ${l.light}`);for(const m of l.materials)if(m!==null&&!o.materials[m])throw new Error(`Missing runtime material ${m}`);const s=new Set([l.id]);let c=l.parent;for(;c!==null;){if(s.has(c))throw new Error("Runtime parent cycle");s.add(c);const m=i.get(c);if(!m)throw new Error(`Missing runtime parent ${c}`);c=m.parent}}const f=new Map,u=new Map;try{for(const[l,s]of Object.entries(o.volumes)){const c=JSON.stringify(s);this.frame?.session===o.session&&this.volumes.get(l)?.signature===c||u.set(l,{signature:c,mesh:Hr(s)})}for(const[l,s]of Object.entries(o.meshes)){if("unchanged"in s){const h=r?.meshes.get(l);if(h){if(h.signature!==`revision:${s.revision}`)throw new Error("Staged Blender mesh revision mismatch");f.set(l,h);continue}const g=this.meshes.get(l)?.signature;if(this.frame?.session===o.session&&g!==void 0&&(g===`revision:${s.revision}`||!g.startsWith("revision:")))continue;throw new Error(g===void 0?`${Ie}: the presenter does not hold runtime mesh ${l} (store ${s.store}, revision ${s.revision})`:`${Ie}: the presenter holds runtime mesh ${l} at ${g}, not revision ${s.revision}`)}const c="hash"in s,m="columns"in s,d=m?`revision:${s.revision}`:c?s.hash:JSON.stringify(s);this.frame?.session===o.session&&this.meshes.get(l)?.signature===d||f.set(l,{signature:d,geometry:m?En(De({...s.columns,attributes:s.attributes,activeUv:s.activeUv,renderUv:s.renderUv},d)):c?En(s):ir(s)})}}catch(l){for(const s of f.values())s.geometry.dispose();for(const{mesh:s}of u.values())s.geometry.dispose(),s.material.dispose();throw l}if(r){for(const[l,s]of r.meshes)f.has(l)||s.geometry.dispose();this.staged=null}this.frame?.session!==o.session&&(this.frame&&this.retiredSessions.add(this.frame.session),this.clear());for(const[l,s]of u){const c=this.volumes.get(l)?.mesh;c&&(c.removeFromParent(),c.geometry.dispose(),c.material.dispose()),this.volumes.set(l,s)}for(const[l,s]of f)this.meshes.get(l)?.geometry.dispose(),this.meshes.set(l,s),this.geometryBuilds++;for(const[l,s]of Object.entries(o.images)){const c=this.textures.get(l);if("width"in s){const p=s.rgba??(s.rgbaBase64?re(s.rgbaBase64):void 0);if(!p)throw new Error(`Runtime image ${l} carries no raster`);const v=s.tiles?ps(l,s.tiles,s.colorspace??"sRGB"):void 0;if(c?.udim&&(c.udim.tiles.dispose(),c.udim.map.dispose(),delete c.udim),c&&c.width===s.width&&c.height===s.height){const b=c.texture.image;if(b.data){b.data.set(p),c.texture.needsUpdate=!0,c.revision=s.revision,v&&(c.udim=v);continue}}c?.texture.dispose(),this.textures.set(l,{texture:hs(p,s.width,s.height,s.colorspace??"sRGB"),width:s.width,height:s.height,revision:s.revision,...v?{udim:v}:{}});continue}const m=s.encoded??(s.encodedBase64?re(s.encodedBase64):void 0);if(!m)throw new Error(`Runtime image ${l} carries no bytes`);c?.texture.dispose(),c?.udim?.tiles.dispose(),c?.udim?.map.dispose();const d=s.colorspace??"sRGB",{texture:h,ready:g}=ds(m,s.mime);h.colorSpace=d==="data"?In:$t,this.textures.set(l,{texture:h,ready:g,width:0,height:0,revision:s.revision,encoded:{bytes:m.slice(),mime:s.mime,colorspace:d}})}for(const[l,s]of Object.entries(o.materials)){const c=this.materials.get(l)??new en;c.name=s.name;const m=s.texture?.tint;s.texture!==void 0?c.color.setRGB(m?.[0]??1,m?.[1]??1,m?.[2]??1,vt):c.color.setRGB(s.color[0],s.color[1],s.color[2],vt),c.opacity=s.color[3];const d=c.opacity<1||s.graph!==void 0&&Qr(s.graph);c.transparent!==d&&(c.transparent=d,c.needsUpdate=!0),c.roughness=s.roughness,c.metalness=s.metallic,c.transmission=s.transmission,c.ior=s.ior,we(c,s.physical,{map:s.texture?.extension==="CLIP",roughness:s.roughness_texture?.extension==="CLIP",normal:s.normal_texture?.extension==="CLIP"});const h=s.normal_texture?.image.name;if(h===void 0)c.normalMap&&(this.textureSamplers.delete(`${l}:normal`),c.normalMap=null,c.needsUpdate=!0);else{const y=this.textures.get(h);if(!y)throw new Error(`${sn}: missing normal image ${h}`);const S=this.textureSamplers.get(`${l}:normal`,y.texture,s.normal_texture.extension,y.ready,s.normal_texture.uv);c.normalMap!==S&&(c.normalMap=S,c.needsUpdate=!0);const T=s.normal_space==="OBJECT"?pa:ga;c.normalMapType!==T&&(c.normalMapType=T,c.needsUpdate=!0),c.normalScale.set(s.normal_strength,s.normal_strength*(s.normal_directx?-1:1))}s.emission?(c.emissive.setRGB(s.emission.color[0],s.emission.color[1],s.emission.color[2],vt),c.emissiveIntensity=s.emission.strength):(c.emissive.setRGB(0,0,0),c.emissiveIntensity=1);const g=s.roughness_texture?.image.name??null;if(g===null)this.roughnessTextureNames.has(l)&&(this.textureSamplers.delete(`${l}:roughness`),c.roughnessMap=null,this.roughnessTextureNames.delete(l),c.needsUpdate=!0);else{const y=this.textures.get(g);if(!y)throw new Error(`${sn}: the presenter does not hold runtime image ${g} (revision ${s.roughness_texture.image.revision})`);const S=this.textureSamplers.get(`${l}:roughness`,y.texture,s.roughness_texture.extension,y.ready,s.roughness_texture.uv);c.roughnessMap!==S&&(c.roughnessMap=S,this.roughnessTextureNames.set(l,g),c.needsUpdate=!0)}const p=s.texture?.image.name??null;if(p===null)this.textureNames.has(l)&&(this.textureSamplers.delete(`${l}:color`),c.map=null,this.textureNames.delete(l),c.needsUpdate=!0);else{const y=this.textures.get(p);if(!y)throw new Error(`${sn}: the presenter does not hold runtime image ${p} (revision ${s.texture.image.revision})`);const S=this.textureSamplers.get(`${l}:color`,y.texture,s.texture.extension,y.ready,s.texture.uv);c.map!==S&&(c.map=S,this.textureNames.set(l,p),c.needsUpdate=!0)}const v=s.graph?this.compiledGraph(s.graph):null,b=new Set;mi(c,v,y=>{const S=this.textures.get(y.name);if(!S)throw new Error(`${sn}: the presenter does not hold runtime image ${y.name} (revision ${y.revision})`);if(y.tiled){if(!S.udim)throw new Error(`${sn}: runtime image ${y.name} arrived without its UDIM tiles`);return S.udim}const T=`${l}:graph:${y.node}`;b.add(T);const A=this.textureSamplers.get(T,S.texture,y.extension,S.ready),O=y.closest?oe:Xt,E=y.closest?oe:y.mipmap?yo:Xt;return(A.magFilter!==O||A.minFilter!==E)&&(A.magFilter=O,A.minFilter=E,A.needsUpdate=!0),A},this.photograph);for(const y of this.graphSamplers.get(l)??[])b.has(y)||this.textureSamplers.delete(y);this.graphSamplers.set(l,b),this.materials.set(l,c)}for(const l of o.objects){let s=this.objects.get(l.id);const c=l.volume?this.volumes.get(l.volume).mesh:null;if((!s||(c?s!==c:!!s.isMesh!=(l.mesh!==null)))&&(s?.removeFromParent(),s=c??(l.mesh!==null?new Rt(this.meshes.get(l.mesh).geometry,this.fallback):new uo),this.objects.set(l.id,s)),s.name=l.name,l.type==="CAMERA"||l.type==="LIGHT"||l.type==="EMPTY"?s.userData.volterOwnOverlay=!0:delete s.userData.volterOwnOverlay,s.matrixAutoUpdate=!1,s.matrix.set(...l.matrix.flat()),l.parent){const m=new B().set(...i.get(l.parent).matrix.flat());s.matrix.premultiply(m.invert())}if(s.matrix.decompose(s.position,s.quaternion,s.scale),l.texspace?s.userData.blenderTexspace=l.texspace:delete s.userData.blenderTexspace,l.default_color!==void 0?s.userData.blenderDefaultColor=l.default_color:delete s.userData.blenderDefaultColor,l.mesh!==null){const m=s;m.geometry=this.meshes.get(l.mesh).geometry,m.material=l.materials.length?l.materials.map(d=>d===null?this.fallback:this.materials.get(d)):this.fallback,pi(m)}if(l.light){const m=this.lights.get(l.light)??null,d=kr(o.lights[l.light],m);m&&m!==d&&(m.removeFromParent(),m.dispose()),d.parent!==s&&s.add(d),d.userData.volterOwnOverlay=!0,Lr(d,s),this.lights.set(l.light,d)}}for(const l of o.objects){const s=this.objects.get(l.id),c=l.parent===null?this.root:this.objects.get(l.parent);s.parent!==c&&c.add(s)}for(const[l,s]of this.objects)a.has(l)||(s.removeFromParent(),this.objects.delete(l));for(const[l,s]of this.volumes)o.volumes[l]||(s.mesh.geometry.dispose(),s.mesh.material.dispose(),this.volumes.delete(l));for(const[l,s]of this.meshes)o.meshes[l]||(s.geometry.dispose(),this.meshes.delete(l));for(const[l,s]of this.materials)if(!o.materials[l]){for(const c of["normal","roughness","color"])this.textureSamplers.delete(`${l}:${c}`);for(const c of this.graphSamplers.get(l)??[])this.textureSamplers.delete(c);this.graphSamplers.delete(l),s.dispose(),this.materials.delete(l)}for(const[l,s]of this.lights)o.lights[l]||(s.removeFromParent(),s.dispose(),this.lights.delete(l));this.root.updateMatrixWorld(!0),this.frame={...o,meshes:{},volumes:{},images:{}},this.worldKey=JSON.stringify(o.world??null);const _=this.applyOverlays(o);_.length&&(this.frame={...this.frame,warnings:[...this.frame.warnings,..._]}),this.applyVisibility(),this.applyWorkbench(),this.heldRendered!==null&&!this.capturing&&this.report(this.applyRendered(!0,this.heldRendered()));for(const l of[...this.frameListeners])l();for(const l of this.followers)try{l.applyFrame(t)}catch{l.applyFrame(this.fullFrame())}return{...this.inspect(),held:n}}inspect(){return{session:this.frame?.session,revision:this.frame?.revision,active:this.frame?.active,mode:this.frame?.mode,geometryBuilds:this.geometryBuilds,instancing:this.drawStatistics(),objects:[...this.objects].map(([t,n])=>({id:t,name:n.name,uuid:n.uuid,geometry:n.geometry?.uuid,visible:n.visible}))}}drawStatistics(){return{enabled:this.drawBatching,opaque:this.instances.inspect(),transparent:this.transparentInstances.inspect(),motion:this.motionGeometry.inspect()}}snapshot(){return this.frame}fullFrame(){const t=this.frame;if(!t)throw new Error("Blender capture requires a presented frame");const n=structuredClone({...t,images:{},armatures:{},weights:null});for(const[r,{signature:a,geometry:i}]of this.meshes){const f=l=>{const s=i.getAttribute(l);if(!s)return null;if(!(s instanceof lt))throw new Error(`Blender capture cannot copy interleaved ${l}`);return new Float32Array(s.array)},u=f("position");if(!u)throw new Error(`Blender capture mesh ${r} has no positions`);const _=i.getIndex();n.meshes[r]={hash:a,positions:u,normals:f("normal"),uv:f("uv"),uvLayers:Object.entries(i.userData.blenderUvChannels??{}).map(([l,s])=>{const c=f(`uv${s}`);if(!c)throw new Error(`Blender capture mesh ${r} is missing UV layer ${l}`);return{name:l,data:c}}),orco:i.userData.blenderOrcoFromDoor?f("blenderOrco"):null,attributeLayers:(i.userData.blenderAttributes??[]).map(l=>{const s=f(kt(l));if(!s)throw new Error(`Blender capture mesh ${r} is missing attribute ${l}`);return{name:l,data:s}}),indices:_?new Uint32Array(_.array):Uint32Array.from({length:u.length/3},(l,s)=>s),groups:i.groups.map(l=>({start:l.start,count:l.count,materialIndex:l.materialIndex??0}))}}for(const[r,{signature:a}]of this.volumes)n.volumes[r]=Fo.parse(JSON.parse(a));const o=new Set(Object.values(n.materials).flatMap(r=>[r.texture?.image.name,r.roughness_texture?.image.name,r.normal_texture?.image.name,...Object.values(r.graph?.nodes??{}).map(a=>a.props.image?.name)].filter(a=>a!==void 0)));for(const r of o){const a=this.textures.get(r);if(!a)throw new Error(`Blender capture image ${r} is not resident`);if(a.encoded)n.images[r]={revision:a.revision,encoded:a.encoded.bytes.slice(),mime:a.encoded.mime,colorspace:a.encoded.colorspace};else{const i=a.texture.image?.data;if(!(i instanceof Uint8Array))throw new Error(`Blender capture image ${r} has no resident raster`);n.images[r]={revision:a.revision,width:a.width,height:a.height,rgba:i.slice(),colorspace:a.texture.colorSpace===In?"data":"sRGB",...a.udim?{tiles:a.udim.frame}:{}}}}return n}follow(){const t=new Dn;this.frame&&t.applyFrame(this.fullFrame()),this.followers.add(t),t.leader=this;let n=!1;return{view:t,dispose:()=>{n||(n=!0,this.followers.delete(t),t.leader=null,t.dispose(),t.root.removeFromParent())}}}captureSnapshot(){const t=this.fullFrame(),n=this.frame,o=this.createWorldVolumePass(),r=new Dn;r.photograph=!0;let a=!1;const i=()=>{a||(a=!0,o?.dispose(),r.dispose(),r.root.removeFromParent())};try{r.applyFrame(t),this.root.updateWorldMatrix(!0,!1),r.root.matrix.copy(this.root.matrixWorld),r.root.updateMatrixWorld(!0)}catch(f){throw i(),f}return{effect:o,root:r.root,session:n.session,revision:n.revision,prepare:f=>{if(a)throw new Error("Blender capture snapshot is disposed");return r.setRendered(!0,f)},dispose:i}}createWorldVolumePass(){const t=Ze(this.frame?.world);return t?new Mi(t):void 0}recordPresentation(t){if(typeof t!="object"||t===null)return;const n=t,o=n.meshes;if(typeof o!="object"||o===null)return;const r=typeof n.session=="string"?n.session:null;r!==this.submittedSession&&(this.submittedMeshes.clear(),this.photographs.length=0,this.submittedSession=r);const a=o;for(const[i,f]of Object.entries(a))typeof f=="object"&&f!==null&&!("unchanged"in f)&&this.submittedMeshes.set(i,f);for(const i of[...this.submittedMeshes.keys()])i in a||this.submittedMeshes.delete(i);this.submitted={...n,meshes:Object.fromEntries(this.submittedMeshes)}}recordPhotograph(t){this.photographs.push(t)}observations(){return{presentation:this.submitted,photographs:this.photographs}}clear(){this.motionGeometry.clear(),this.transparentInstances.clear(),this.instances.clear();for(const t of this.staged?.meshes.values()??[])t.geometry.dispose();this.staged=null;for(const t of this.lights.values())t.removeFromParent(),t.dispose();this.lights.clear();for(const t of this.objects.values())t.removeFromParent();for(const t of this.meshes.values())t.geometry.dispose();for(const t of this.materials.values())t.dispose();for(const{mesh:t}of this.volumes.values())t.geometry.dispose(),t.material.dispose();for(const{texture:t,udim:n}of this.textures.values())t.dispose(),n?.tiles.dispose(),n?.map.dispose();this.textures.clear(),this.textureNames.clear(),this.roughnessTextureNames.clear(),this.textureSamplers.clear(),this.volumes.clear(),this.objects.clear(),this.meshes.clear(),this.materials.clear()}dispose(){this.clear(),this.fallback.dispose(),this.lighting.dispose(),this.world.dispose(),this.armatureOverlay.dispose(),this.weightOverlay.dispose(),this.cursorOverlay.dispose(),this.extrasOverlay.dispose();for(const t of this.workbenchMaterials.values())t.dispose();this.workbenchMaterials.clear(),this.frame=null,this.retiredSessions.clear(),this.submittedMeshes.clear(),this.submitted=null,this.submittedSession=null,this.photographs.length=0}}const Rs=new Dn;function qo(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}function Jn(e){const t=qo(e);return new Float32Array(t.buffer,t.byteOffset,t.byteLength>>2)}function Os(e){const t=qo(e);return new Uint16Array(t.buffer,t.byteOffset,t.byteLength>>1)}function Ts(e){return new B().set(...e.flat())}function io(e,t){return[e.object,e.mesh,e.armature,e.vertexCount,e.bones.length,t].join("|")}class As{#n=new Map;#o=null;#a=null;#t=null;#r=null;#e=null;#s=null;#l=new Set;#u=0;#m=[];#i=0;get version(){return this.#u}get engineCalls(){return this.#i}subscribe(t){return this.#l.add(t),()=>this.#l.delete(t)}#f(){this.#u++;for(const t of[...this.#l])t()}state(){const t=this.#t,n=t?.frameStart??1,o=t?.frameEnd??250,r=t?.fps??24;return{frame:this.frame(),start:n,end:o,fps:r,action:t?.action??null,object:t?.object??null,armature:t?.armature??null,bones:[...this.#n.values()].reduce((a,i)=>a+i.bones.length,0),keyframes:t?.keyframes??[],summary:t?.summary??[],clipStart:t?.clipStart??null,clipEnd:t?.clipEnd??null,tracks:t?.tracks.length??0,bound:[...this.#n.keys()],warnings:this.#m,engineCalls:this.#i,blenderFrame:t?.frameCurrent??null}}playhead(){return this.#t?this.frame():null}frame(){const t=this.#t;return this.#r!==null?this.#r:!t||!this.#a||t.clipStart===void 0?t?.frameCurrent??1:t.clipStart+this.#a.time*t.fps}get playable(){return this.#t!==null&&this.#e!==null}async bind(t,n){this.#i++;const o=await n.rig();if(!o)return;const r=[],a=new Set;let i=!1;for(const m of o.rigs){if(!m.object||!m.armature||!m.skinIndexBase64||!m.skinWeightBase64){m.reason&&r.push(m.reason);continue}a.add(m.object);const d=io(m,o.frame);if(this.#n.get(m.object)?.signature===d)continue;const h=this.#d(t,m,o.frame,r);h&&(this.#n.get(m.object)?.skeleton.dispose(),this.#n.set(m.object,h),i=!0)}for(const[m,d]of[...this.#n])a.has(m)||(d.skeleton.dispose(),d.boneRoot.removeFromParent(),this.#n.delete(m),i=!0);this.#i++;const f=await n.clip(),u=this.#t,_=f?.frameStart!==u?.frameStart||f?.frameEnd!==u?.frameEnd||f?.fps!==u?.fps,l=f?.action!==u?.action||f?.tracks.length!==u?.tracks.length||f?.clipStart!==u?.clipStart||f?.clipEnd!==u?.clipEnd;this.#t=f??null,(!f||f.scene!==u?.scene)&&(this.#r=null),f?.reason&&r.push(f.reason),f&&(l||i)&&this.#h(t,f,r);const s=this.#e?.snapshot().activeSubject;_&&s&&this.#e?.setActiveSubject(s);const c=this.#e?.snapshot().playbackState==="playing";f&&!c&&(_||u?.frameCurrent!==f.frameCurrent)&&(this.#c(f.frameCurrent),this.#e&&f.fps>0&&this.#e.seek(f.frameCurrent/f.fps)),this.#m=r,this.#f()}#d(t,n,o,r){const a=t.objectForBlenderName(n.object??""),i=t.objectForBlenderName(n.armature??"");if(!a||!i)return null;const f=a,u=f.geometry;if(!u)return null;const _=u.getAttribute("blenderVertex");if(!_)return r.push(`"${n.object}" cannot be skinned: its presented geometry carries no \`blenderVertex\` attribute, so a per-Blender-vertex weight cannot be expanded onto its drawn vertices.`),null;if(n.vertexCount===0)return null;let l=0;for(let T=0;T<_.count;T++)l=Math.max(l,_.getX(T));if(l>=n.vertexCount)return r.push(`"${n.object}" is not skinned here: its presented geometry references Blender vertex ${l} while the mesh declares ${n.vertexCount}, which is a generative modifier (Subdivision, Mirror, Array…) between the two. Blender's own viewport shows the evaluated result; this presenter shows the exported columns unskinned.`),null;const s=Os(n.skinIndexBase64??""),c=Jn(n.skinWeightBase64??""),m=_.count,d=new Uint16Array(m*4),h=new Float32Array(m*4);for(let T=0;T<m;T++){const A=_.getX(T);for(let O=0;O<4;O++)d[T*4+O]=s[A*4+O]??0,h[T*4+O]=c[A*4+O]??0}u.setAttribute("skinIndex",new ya(d,4)),u.setAttribute("skinWeight",new Mt(h,4));const g=new it;g.name=`${n.armature}:bones`;const p=[],v=n.bones.map(T=>Ts(T.pose)),b=new Map(n.bones.map((T,A)=>[T.name,A]));n.bones.forEach((T,A)=>{const O=new wa;O.name=T.name,p.push(O);const E=T.parent===null?void 0:b.get(T.parent);(E===void 0?v[A].clone():v[E].clone().invert().multiply(v[A])).decompose(O.position,O.quaternion,O.scale),(E===void 0?g:p[E]).add(O)}),i.add(g);const y=new Oa(u,f.material);y.name=f.name,y.matrixAutoUpdate=!1,y.matrix.copy(f.matrix),y.matrix.decompose(y.position,y.quaternion,y.scale),y.userData=f.userData,y.frustumCulled=!1,t.replacePresentedObject(f,y),t.root.updateMatrixWorld(!0);const S=new Ta(p);return y.bind(S,y.matrixWorld.clone()),n.constrainedBones?.length&&r.push(`Bone constraints on ${n.constrainedBones.join(", ")}: the clip is derived from the F-Curves alone, so those bones play their channels rather than Blender's solved pose.`),n.unmappedGroups?.length&&r.push(`${n.object} carries vertex groups no bone is named for (${n.unmappedGroups.join(", ")}); they weight nothing here, exactly as they deform nothing in Blender.`),{object:n.object??"",armature:n.armature??"",mesh:y,boneRoot:g,bones:p,skeleton:S,frame:o,signature:io(n,o)}}#h(t,n,o){if(this.#o?.stopAllAction(),this.#o=null,this.#a=null,!n.tracks.length||n.clipStart===void 0||n.clipEnd===void 0)return;const r=n.armature?t.objectForBlenderName(n.armature):null;if(!r)return;const a=new Map;for(const s of this.#n.values())if(s.armature===n.armature)for(const c of s.bones)a.set(c.name,c);const i=[],f=new Set;for(const s of n.tracks){const c=a.get(s.bone);if(!c){f.add(s.bone);continue}const m=Jn(s.timeBase64),d=Jn(s.valueBase64),h=`${c.uuid}.${s.property}`;i.push(s.property==="quaternion"?new Aa(h,Array.from(m),Array.from(d)):new Sa(h,Array.from(m),Array.from(d)))}if(f.size&&o.push(`${n.action} animates ${[...f].join(", ")}, which this binding has no bone for.`),!i.length)return;const u=n.duration??(n.clipEnd-n.clipStart)/n.fps,_=new Ma(r),l=_.clipAction(new Pa(n.action??"action",u,i));l.setLoop(Ea,Number.POSITIVE_INFINITY),l.play(),this.#o=_,this.#a=l,this.#c(n.frameCurrent),this.#_()}#c(t){const n=this.#t;if(!n)return;const o=Math.min(n.frameEnd,Math.max(n.frameStart,t));if(this.#r=o,!this.#o||n.clipStart===void 0||n.clipEnd===void 0)return;const r=(n.clipEnd-n.clipStart)/n.fps;this.#o.setTime(Math.max(0,Math.min(r-1e-4,(o-n.clipStart)/n.fps))),this.#_()}#_(){for(const t of this.#n.values())t.boneRoot.updateMatrixWorld(!0),t.skeleton.update()}get scene(){return this.#t?.scene??null}async writeBookmark(){const t=Math.round(this.frame()),n=this.#t;if(!n)return t;const o=n.scene;return!o||n.frameCurrent===t||(this.#i++,await za(`bpy.data.scenes[${JSON.stringify(o)}]`,"frame_current",t,void 0,!1),this.#t={...n,frameCurrent:t},this.#f()),t}get transport(){return this.#e}attachTo(t){this.#s?.(),this.#e=t;const n=t.attach({id:this.#t?.action??"blender-action",label:this.#t?.action??"Action",range:()=>{const i=this.#t,f=i?.fps||24;return{start:(i?.frameStart??1)/f,end:(i?.frameEnd??250)/f,fps:f}},seek:i=>this.seekSeconds(i)}),o=t.onSettled(()=>{this.writeBookmark()}),r=()=>{o(),n(),this.#e===t&&(this.#e=null),this.#s=null};this.#s=r;const a=this.#t;return a&&a.fps>0&&t.seek(a.frameCurrent/a.fps),r}seekSeconds(t){const n=this.#t?.fps||24;this.#c(Math.round(t*n)),this.#f()}keyframes(){return(this.#t?.keyframes??[]).map(t=>t.frame)}dispose(){this.#s?.(),this.#o?.stopAllAction(),this.#o=null,this.#a=null,this.#t=null,this.#r=null;for(const t of this.#n.values())t.skeleton.dispose(),t.boneRoot.removeFromParent();this.#n.clear()}}const Ho=new As;function Is(e){return Ho.subscribe(e)}function zs(){return Ho.version}export{Ho as a,zs as b,Rs as c,Is as s};
7191
+ #include <opaque_fragment>`)},a.customProgramCacheKey=()=>"volter-blender-workbench",a}const as=64;function rs(e,t){return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>n===t[o]):e===t}function en(e){for(let t=e;t;t=t.parent)if(!t.visible)return!1;return!0}function he(e){if(e.determinant()<=0)return!1;const t=e.elements,n=Math.hypot(t[0],t[1],t[2]),o=Math.hypot(t[4],t[5],t[6]),r=Math.hypot(t[8],t[9],t[10]),a=(i,f)=>t[i]*t[f]+t[i+1]*t[f+1]+t[i+2]*t[f+2];return Number.isFinite(n+o+r)&&Math.min(n,o,r)>0&&Math.abs(a(0,4))<=1e-7*n*o&&Math.abs(a(0,8))<=1e-7*n*r&&Math.abs(a(4,8))<=1e-7*o*r}class is{constructor(t){this.root=t,this.batches=[],this.inverse=new H,this.matrix=new H,this.box=new on,this.projection=new H,this.frustum=new Vn,this.camera=null,this.eligible=0,this.excluded={}}rebuild(t,n){if(this.clear(),!n)return;const o=new Map,r=a=>{this.excluded[a]=(this.excluded[a]??0)+1};this.inverse.copy(this.root.matrixWorld).invert();for(const a of t){const i=a;if(!i.isMesh)continue;if(i.isSkinnedMesh||i.isInstancedMesh||i.morphTargetInfluences||i.layers.mask!==1){r("deformationOrLayers");continue}const f=Array.isArray(i.material)?i.material:[i.material];if(f.some(l=>l.transparent||l.transmission>0||l.isShaderMaterial)){r("material");continue}if(f.some(l=>Bo(l,i.geometry).size>12)){r("attributeBudget");continue}if(this.matrix.multiplyMatrices(this.inverse,i.matrixWorld),!he(this.matrix)){r("transform");continue}this.eligible++;const u=`${i.geometry.id}:${Array.isArray(i.material)?"slots":"single"}:`+f.map(l=>l.uuid).join(",")+`:${i.renderOrder}`,_=o.get(u);_?_.push(i):o.set(u,[i])}for(const a of o.values()){if(a.length<2)continue;const i=f=>{if(f.length>as){this.box.makeEmpty();for(const d of f)this.box.expandByPoint(new x().setFromMatrixPosition(d.matrixWorld));const s=this.box.getSize(new x),c=s.x>=s.y&&s.x>=s.z?12:s.y>=s.z?13:14;f.sort((d,h)=>d.matrixWorld.elements[c]-h.matrixWorld.elements[c]);const m=Math.floor(f.length/2);i(f.slice(0,m)),i(f.slice(m));return}if(f.length<2)return;const u=f[0],_=new yo(u.geometry,u.material,f.length);_.name="Blender repeated geometry",_.userData.engineInternal=!0,_.matrixAutoUpdate=!1,_.renderOrder=u.renderOrder,_.instanceMatrix.setUsage(wo);const l={draw:_,members:f.map(s=>({mesh:s,layers:s.layers.mask}))};_.raycast=(s,c)=>{for(const{mesh:m}of l.members)m.layers.mask===0&&en(m)&&m.raycast(s,c)},this.root.add(_),_.updateMatrixWorld(!0),this.batches.push(l)};i(a)}this.sync()}sync(){if(this.batches.length){this.inverse.copy(this.root.matrixWorld).invert();for(const{draw:t,members:n}of this.batches){let o=0,r=!1;for(const a of n){const{mesh:i}=a;if(this.matrix.multiplyMatrices(this.inverse,i.matrixWorld),!(i.parent!==null&&i.geometry===t.geometry&&rs(i.material,t.material)&&he(this.matrix))){i.layers.mask|=a.layers;continue}if(i.layers.mask&=~a.layers,!en(i)||this.camera&&(!this.camera.layers.isEnabled(0)||i.frustumCulled&&!this.frustum.intersectsObject(i)))continue;const u=o*16;this.matrix.elements.some((_,l)=>Math.fround(_)!==t.instanceMatrix.array[u+l])&&(t.setMatrixAt(o,this.matrix),r=!0),o++}r||=t.count!==o||t.boundingSphere===null,t.count=o,r&&(t.instanceMatrix.needsUpdate=!0,t.computeBoundingBox(),t.computeBoundingSphere())}}}prepareDraw(t){t.updateMatrixWorld(),this.camera=t,this.projection.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projection)}finishDraw(){this.camera=null}clear(){this.camera=null;for(const{draw:t,members:n}of this.batches){for(const{mesh:o,layers:r}of n)o.layers.mask|=r;t.removeFromParent(),t.dispose()}this.batches.length=0,this.eligible=0,this.excluded={}}inspect(){return{batches:this.batches.length,instances:this.batches.reduce((t,{draw:n})=>t+n.count,0),eligible:this.eligible,excluded:{...this.excluded}}}}const _n=64;function ao(e){for(let t=e.parent;t;t=t.parent)if(t.isGroup)return t.renderOrder;return 0}class ss{constructor(t){this.root=t,this.objects=[],this.pools=new Map,this.hidden=[],this.inverse=new H,this.matrix=new H,this.projection=new H,this.frustum=new Vn,this.centre=new x,this.depth=new kn,this.batches=0,this.instances=0,this.planState=[],this.planned=[],this.stateIndex=0,this.stateChanged=!1}setObjects(t){this.clear(),this.objects=[...t].filter(n=>n.isMesh===!0)}prepare(t){if(this.finishDraw(),!this.objects.length)return;if(t.updateMatrixWorld(),this.projection.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),!this.planChanged(t)){for(const a of this.planned){a.mesh.visible=!0;for(const i of a.members)i.layers.disable(0),this.hidden.push(i)}return}this.planned.length=0;for(const a of this.pools.values())for(const i of a)i.mesh.visible=!1,i.members.length=0;this.batches=this.instances=0,this.frustum.setFromProjectionMatrix(this.projection),this.inverse.copy(this.root.matrixWorld).invert();const n=[],o=new Map;for(const a of this.objects){const i=Array.isArray(a.material)?a.material:[a.material];if(!i.some(d=>d.visible&&d.transparent)||!en(a)||!a.layers.test(t.layers)||a.frustumCulled&&!this.frustum.intersectsObject(a))continue;const f=a;f.boundingSphere!==void 0?(f.boundingSphere===null&&f.computeBoundingSphere?.(),this.centre.copy(f.boundingSphere.center)):(a.geometry.boundingSphere||a.geometry.computeBoundingSphere(),this.centre.copy(a.geometry.boundingSphere.center)),this.centre.applyMatrix4(a.matrixWorld);const u=this.centre.clone(),_=this.depth.set(u.x,u.y,u.z,1).applyMatrix4(this.projection).z;let l=null,s=null;const c=i.length===1?i[0]:null,m=ao(a);if(c&&c.visible&&c.transparent&&!c.isShaderMaterial&&!(c.transmission>0)&&(c.side!==ae||c.forceSinglePass)&&!a.isSkinnedMesh&&!a.morphTargetInfluences&&!a.isInstancedMesh&&a.layers.mask===1&&m===this.root.renderOrder){const d=a.geometry,h=d.index?.count??d.getAttribute("position").count,g=!Array.isArray(a.material)||d.groups.length===1&&d.groups[0].start===0&&d.groups[0].count===h&&d.groups[0].materialIndex===0,p=`${d.id}:${c.uuid}:${a.renderOrder}`;let v=o.get(p);v===void 0&&(v=Bo(c,d).size<=12,o.set(p,v)),this.matrix.multiplyMatrices(this.inverse,a.matrixWorld),g&&v&&he(this.matrix)&&(l=c,s=p)}n.push({mesh:a,material:l,key:s,groupOrder:m,z:_,centre:u})}n.sort((a,i)=>a.groupOrder-i.groupOrder||a.mesh.renderOrder-i.mesh.renderOrder||i.z-a.z||a.mesh.id-i.mesh.id);const r=new Map;for(let a=0;a<n.length;){const i=n[a];let f=a+1;if(i.key!==null)for(;f<n.length&&n[f].key===i.key;)f++;const u=n[a-1],_=n[f],l=u?.z===i.z&&u.mesh.renderOrder===i.mesh.renderOrder||_?.z===n[f-1].z&&_.mesh.renderOrder===i.mesh.renderOrder;if(i.key!==null&&f-a>=2&&!l){let s=!0;for(let c=a+_n;c<f;c+=_n)n[c-1].z===n[c].z&&(s=!1);if(s)for(let c=a;c<f;c+=_n){const m=Math.min(_n,f-c);if(m<2)continue;const d=n[c],h=r.get(i.key)??0;r.set(i.key,h+1);let g=this.pools.get(i.key);g||(g=[],this.pools.set(i.key,g));let p=g[h];if(!p){const v=new yo(i.mesh.geometry,i.material,_n);v.name="Blender ordered transparency",v.userData.engineInternal=!0,v.matrixAutoUpdate=!1,v.frustumCulled=!1,v.boundingSphere=new Oo,v.instanceMatrix.setUsage(wo),p={mesh:v,members:[]};const O=p;v.raycast=(b,P)=>{if(v.visible)for(const T of O.members)en(T)&&T.raycast(b,P)},g.push(p),this.root.add(v)}p.mesh.visible=!0,p.mesh.renderOrder=d.mesh.renderOrder,p.mesh.boundingSphere.center.copy(d.centre).applyMatrix4(this.inverse),p.mesh.updateMatrixWorld(!0);for(let v=0;v<m;v++){const O=n[c+v].mesh;this.matrix.multiplyMatrices(this.inverse,O.matrixWorld),p.mesh.setMatrixAt(v,this.matrix),p.members.push(O),O.layers.disable(0),this.hidden.push(O)}p.mesh.count=m,p.mesh.instanceMatrix.needsUpdate=!0,this.planned.push(p),this.batches++,this.instances+=m}}a=f}}inspect(){return{batches:this.batches,instances:this.instances}}observe(t){this.planState[this.stateIndex]!==t&&(this.planState[this.stateIndex]=t,this.stateChanged=!0),this.stateIndex++}planChanged(t){this.stateIndex=0,this.stateChanged=this.planState.length===0,this.observe(t.layers.mask);for(const n of this.projection.elements)this.observe(n);for(const n of this.root.matrixWorld.elements)this.observe(n);for(const n of this.objects){this.observe(n.parent?.id??-1),this.observe(en(n)?1:0),this.observe(n.layers.mask),this.observe(n.renderOrder),this.observe(ao(n)),this.observe(n.frustumCulled?1:0),this.observe(n.morphTargetInfluences?1:0);for(const i of n.matrixWorld.elements)this.observe(i);const o=n.geometry;this.observe(o.id),this.observe(o.drawRange.start),this.observe(o.drawRange.count),this.observe(o.index?.count??o.getAttribute("position").count),this.observe(o.groups.length);for(const i of o.groups)this.observe(i.start),this.observe(i.count),this.observe(i.materialIndex??0);const r=n.boundingSphere??o.boundingSphere;this.observe(r?.center.x??0),this.observe(r?.center.y??0),this.observe(r?.center.z??0),this.observe(r?.radius??-1);const a=Array.isArray(n.material)?n.material:null;if(this.observe(a?.length??-1),a)for(const i of a)this.observeMaterial(i);else this.observeMaterial(n.material)}return this.stateChanged||=this.planState.length!==this.stateIndex,this.planState.length=this.stateIndex,this.stateChanged}observeMaterial(t){this.observe(t.uuid),this.observe(t.version),this.observe(t.visible?1:0),this.observe(t.transparent?1:0),this.observe(t.side),this.observe(t.forceSinglePass?1:0),this.observe(t.transmission??0)}finishDraw(){for(const t of this.hidden)t.layers.enable(0);this.hidden.length=0;for(const t of this.pools.values())for(const{mesh:n}of t)n.visible=!1}clear(){this.finishDraw();for(const t of this.pools.values())for(const{mesh:n}of t)n.removeFromParent(),n.dispose();this.pools.clear(),this.planned.length=0,this.planState.length=0,this.objects=[],this.batches=this.instances=0}}const Jn=64*1024*1024,ro=150,io=49152,Ft=8192,so=Symbol("navigation geometry replaced");class ls{constructor(t){this.invalidate=t,this.groups=new Map,this.cache=new Map,this.swapped=[],this.queue=[],this.worker=null,this.pending=null,this.generation=0,this.building=!1,this.nextId=0,this.signature="",this.identities=new WeakMap,this.nextIdentity=0,this.bytes=0,this.unavailable=null,this.reductions=[],this.timer=null,this.cameraWorld=new H,this.cameraProjection=new H,this.cameraKnown=!1,this.movedAt=-1/0,this.projection=new H,this.frustum=new Vn,this.centre=new x,this.drawnMeshes=0,this.fullTriangles=0,this.motionTriangles=0,this.lastNavigation={meshes:0,fullTriangles:0,motionTriangles:0,tooClose:0},this.quietTimer=null}setObjects(t){const n=new Map;for(const i of t){const f=i;if(!f.isMesh||f.isSkinnedMesh||f.isInstancedMesh||f.morphTargetInfluences)continue;const u=f.geometry,_=u.getAttribute("position");if(!u.index||u.index.count<6144||!_||_.count>8e6||Object.values(u.attributes).some(s=>!(s instanceof ct)||s.isFloat16BufferAttribute||s.isInstancedBufferAttribute)||Object.keys(u.morphAttributes).length||u.drawRange.start!==0||u.drawRange.count<u.index.count)continue;if(Array.isArray(f.material)){let s=0;if(!u.groups.length||u.groups.some(c=>{const m=c.start===s&&c.count>0&&c.count%3===0&&Number.isInteger(c.materialIndex)&&c.materialIndex>=0&&c.materialIndex<f.material.length;return s=c.start+c.count,!m})||s!==u.index.count)continue}const l=n.get(u);l?l.push(f):n.set(u,[f])}this.groups=n;const o=i=>{let f=this.identities.get(i);return f===void 0&&(f=++this.nextIdentity,this.identities.set(i,f)),f},r=[...n].map(([i,f])=>`${i.id}:${o(i.index)}:${i.index.version}:${Array.isArray(f[0].material)}:${JSON.stringify(i.groups)}:`+Object.entries(i.attributes).map(([u,_])=>`${u}:${o(_)}:${_.version}`).join(",")).join(";");if(r===this.signature)return;this.releaseCopies(),this.signature=r,this.unavailable=null;const a=[...n].filter(([,i])=>i.length>=3);a.reduce((i,[f,u])=>i+f.index.count*u.length,0)<6e6||(a.sort(([i,f],[u,_])=>u.index.count*_.length-i.index.count*f.length),this.queue=a.map(([i])=>i),this.next())}async next(){if(this.building||this.unavailable||this.bytes>=Jn)return;const t=this.queue.shift();if(!t){this.worker?.terminate(),this.worker=null;return}this.building=!0;const n=this.generation,o=()=>{if(n!==this.generation)throw so;if(this.unavailable)throw new Error(this.unavailable)},r=async()=>{await new Promise(a=>setTimeout(a,0)),o()};try{this.worker||(this.worker=new Worker(new URL("/assets/blender-motion-worker-Fh1GJrP5.js",import.meta.url),{type:"module"}),this.worker.onmessage=w=>{if(this.pending?.id===w.data.id){const E=this.pending;this.pending=null,E.resolve(w.data)}},this.worker.onerror=w=>{this.unavailable=w.message||"Navigation geometry worker unavailable",this.worker?.terminate(),this.worker=null;const E=this.pending;this.pending=null,E?.resolve({id:E.id,refusal:this.unavailable})});const a=t.getAttribute("position"),i=this.groups.get(t),f=Array.isArray(i[0].material);if(i.some(w=>Array.isArray(w.material)!==f))return;const u=f?t.groups:[{start:0,count:t.index.count}],_=Object.entries(t.attributes).filter(([w])=>w==="normal"||/^uv\d*$/.test(w)),l=_.reduce((w,[,E])=>w+E.itemSize,0),s=_.flatMap(([w,E])=>Array(E.itemSize).fill(w==="normal"?.5:1)),c=t.boundingBox?.clone()??new on;if(!t.boundingBox){const w=new x;for(let E=0;E<a.count;E+=Ft){await r();for(let D=E;D<Math.min(E+Ft,a.count);D++)c.expandByPoint(w.fromBufferAttribute(a,D))}}if(!t.boundingSphere)return;const m=Math.max(c.max.x-c.min.x,c.max.y-c.min.y,c.max.z-c.min.z)*.002,d=[],h=[];let g=0,p=0;for(const w of u){const E=g;for(let D=w.start;D<w.start+w.count;D+=io){await r();const W=Math.min(D+io,w.start+w.count),V=[],G=new Map,nt=new Uint32Array(W-D);for(let z=D;z<W;z++){const S=t.index.getX(z);let B=G.get(S);B===void 0&&(B=V.length,V.push(S),G.set(S,B)),nt[z-D]=B}const y=new Float32Array(V.length*3),j=new Float32Array(V.length*l);for(let z=0;z<V.length;z+=Ft){await r();for(let S=z;S<Math.min(z+Ft,V.length);S++){const B=V[S];for(let Q=0;Q<3;Q++)y[S*3+Q]=a.getComponent(B,Q);let tt=0;for(const[,Q]of _){for(let rt=0;rt<Q.itemSize;rt++)j[S*l+tt+rt]=Q.getComponent(B,rt);tt+=Q.itemSize}}}const k=++this.nextId,q=await new Promise(z=>{this.pending={id:k,resolve:z};const S={id:k,positions:y,indices:nt,attributes:j,stride:l,weights:s,absoluteError:m};this.worker.postMessage(S,[y.buffer,nt.buffer,j.buffer])});if(o(),q.refusal)throw new Error(q.refusal);if(!q.indices||!Number.isFinite(q.error))throw new Error("Invalid navigation geometry response");const X=q.indices;for(let z=0;z<X.length;z++)X[z]=V[X[z]];if(g+=X.length,g*4>Jn-this.bytes)return;d.push(X),p=Math.max(p,q.error)}f&&h.push({start:E,count:g-E,materialIndex:w.materialIndex})}const v={vertices:a.count,fullTriangles:t.index.count/3,reducedTriangles:g/3,error:p,accepted:!1};if(this.reductions.length<32&&this.reductions.push(v),!g||g>=t.index.count*.75)return;const O=new Int32Array(a.count).fill(-1),b=[],P=new Uint32Array(g);let T=0;for(const w of d){for(let E=0;E<w.length;E+=Ft){await r();for(let D=E;D<Math.min(E+Ft,w.length);D++){const W=w[D];let V=O[W];V<0&&(V=b.length,b.push(W),O[W]=V),P[T+D]=V}}T+=w.length}const M=P.byteLength+Object.values(t.attributes).reduce((w,E)=>w+b.length*E.itemSize*E.array.BYTES_PER_ELEMENT,0);if(this.bytes+M>Jn)return;const A=new sn;A.setIndex(new ct(P,1));for(const[w,E]of Object.entries(t.attributes)){const D=E,W=D.array.constructor,V=new W(b.length*D.itemSize);for(let G=0;G<b.length;G+=Ft){await r();for(let nt=G;nt<Math.min(G+Ft,b.length);nt++)for(let y=0;y<D.itemSize;y++)V[nt*D.itemSize+y]=D.array[b[nt]*D.itemSize+y]}A.setAttribute(w,new ct(V,D.itemSize,D.normalized))}A.boundingSphere=t.boundingSphere.clone(),A.boundingBox=c.clone();for(const w of h)A.addGroup(w.start,w.count,w.materialIndex);A.userData={...t.userData},v.accepted=!0,this.cache.set(t,{geometry:A,error:p,bytes:M}),this.bytes+=M}catch(a){if(a===so)return;this.unavailable=String(a),this.worker?.terminate(),this.worker=null,this.pending=null,this.queue.length=0}finally{n===this.generation&&(this.building=!1,this.timer=setTimeout(()=>{this.timer=null,this.next()},0))}}prepare(t,n,o){if(this.finish(),this.drawnMeshes=this.fullTriangles=this.motionTriangles=0,!n||!(o>0))return!1;const r=performance.now(),a=this.cameraKnown&&(!t.matrixWorld.equals(this.cameraWorld)||!t.projectionMatrix.equals(this.cameraProjection));if(this.cameraKnown=!0,this.cameraWorld.copy(t.matrixWorld),this.cameraProjection.copy(t.projectionMatrix),a&&(this.movedAt=r,this.quietTimer&&clearTimeout(this.quietTimer),this.quietTimer=setTimeout(()=>{this.quietTimer=null,this.invalidate()},ro+1)),r-this.movedAt>ro)return!1;this.projection.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projection);let i=0;for(const[f,u]of this.cache)for(const _ of this.groups.get(f)??[]){if(!en(_)||_.frustumCulled&&!this.frustum.intersectsObject(_))continue;const l=_.matrixWorld.elements,s=Math.hypot(l[0],l[1],l[2],l[4],l[5],l[6],l[8],l[9],l[10]),c=f.boundingSphere;this.centre.copy(c.center).applyMatrix4(_.matrixWorld).applyMatrix4(t.matrixWorldInverse);const m=t.isPerspectiveCamera?-this.centre.z-c.radius*s:1,d=u.error*s*Math.abs(t.projectionMatrix.elements[5])*o/(2*m);if(!(m>0)||d>1){i++;continue}this.swapped.push({mesh:_,geometry:f}),_.geometry=u.geometry,this.drawnMeshes++,this.fullTriangles+=f.index.count/3,this.motionTriangles+=u.geometry.index.count/3}return this.lastNavigation={meshes:this.drawnMeshes,fullTriangles:this.fullTriangles,motionTriangles:this.motionTriangles,tooClose:i},this.swapped.length>0}finish(){for(const{mesh:t,geometry:n}of this.swapped)t.geometry=n;this.swapped.length=0}inspect(){return{copies:this.cache.size,bytes:this.bytes,queued:this.queue.length,pending:this.building,unavailable:this.unavailable,reductions:this.reductions.map(t=>({...t})),lastNavigation:{...this.lastNavigation}}}releaseCopies(){this.finish(),this.timer&&clearTimeout(this.timer),this.timer=null,this.generation++,this.worker?.terminate(),this.worker=null,this.pending?.resolve({id:this.pending.id,refusal:"Navigation geometry replaced"}),this.pending=null,this.building=!1,this.queue=[];for(const t of this.cache.values())t.geometry.dispose();this.cache.clear(),this.bytes=0,this.reductions=[]}clear(){this.releaseCopies(),this.quietTimer&&clearTimeout(this.quietTimer),this.quietTimer=null,this.groups.clear(),this.signature="",this.cameraKnown=!1,this.movedAt=-1/0}}const fs={WIREFRAME:"wireframe",SOLID:"solid",MATERIAL:"preview",RENDERED:"rendered"},C=R().finite(),qo=U([C,C,C]),Pn=U([R().int().nonnegative(),R().int().nonnegative()]),dt={name:I(),domain:K(["POINT","EDGE","FACE","CORNER"])},cs=Fa("type",[N({...dt,type:Z("FLOAT2"),data:$(U([C,C]))}).strict(),N({...dt,type:Z("FLOAT_VECTOR"),data:$(qo)}).strict(),N({...dt,type:Z("FLOAT_COLOR"),data:$(U([C,C,C,C]))}).strict(),N({...dt,type:Z("BYTE_COLOR"),data:$(U([C,C,C,C]))}).strict(),N({...dt,type:Z("QUATERNION"),data:$(U([C,C,C,C]))}).strict(),N({...dt,type:Z("FLOAT4"),data:$(U([C,C,C,C]))}).strict(),N({...dt,type:Z("FLOAT4X4"),data:$($(C).length(16))}).strict(),N({...dt,type:Z("INT16_2D"),data:$(U([R().int(),R().int()]))}).strict(),N({...dt,type:Z("INT32_2D"),data:$(U([R().int(),R().int()]))}).strict(),N({...dt,type:Z("FLOAT"),data:$(C)}).strict(),N({...dt,type:Z("INT"),data:$(R().int())}).strict(),N({...dt,type:Z("INT8"),data:$(R().int())}).strict(),N({...dt,type:Z("BOOLEAN"),data:$(et())}).strict(),N({...dt,type:Z("STRING"),data:$(I())}).strict()]),us=N({positions:Y(Float32Array),normals:Y(Float32Array).nullable(),uv:Y(Float32Array).nullable(),uvLayers:$(N({name:I(),data:Y(Float32Array)}).strict()).optional(),attributeLayers:$(N({name:I(),data:Y(Float32Array)}).strict()).optional(),orco:Y(Float32Array).nullable().optional(),indices:Y(Uint32Array),groups:$(N({start:R().int().nonnegative(),count:R().int().nonnegative(),materialIndex:R().int().nonnegative()}).strict()),hash:I()}).strict(),ms=N({v:$(qo),f:$($(R().int().nonnegative())),e:$(Pn).optional(),edge_order:$(Pn).optional(),m:$(R().int().nonnegative()).optional(),s:$(et()).optional(),sharp:$(Pn).optional(),seams:$(Pn).optional(),creases:$(U([C,C,C])).optional(),attributes:$(cs).optional(),active_uv:I().nullable().optional(),render_uv:I().nullable().optional()}).strict(),_s=N({store:R().int().optional(),revision:R().int(),unchanged:Z(!0)}).strict(),ds=N({co:Vt([Y(Float32Array),Y(Float64Array)]),cornerNormal:Y(Float32Array).optional(),cornerTri:Y(Uint32Array).optional(),orco:Y(Float32Array).optional(),faceStart:Y(Uint32Array),corner:Y(Uint32Array),cornerEdge:Y(Int32Array),edge:Y(Uint32Array),edgeSharp:Y(Uint8Array),edgeSeam:Y(Uint8Array),edgeCrease:Y(Float32Array),material:Y(Uint32Array),smooth:Y(Uint8Array),vertSelect:Y(Uint8Array),vertHide:Y(Uint8Array),edgeSelect:Y(Uint8Array),edgeHide:Y(Uint8Array),faceSelect:Y(Uint8Array),faceHide:Y(Uint8Array)}).strict(),hs=N({name:I(),domain:K(["POINT","EDGE","FACE","CORNER"]),type:I(),data:Da(e=>ArrayBuffer.isView(e))}).strict(),Ho=N({columns:ds,attributes:$(hs),activeUv:I().nullable(),renderUv:I().nullable(),counts:N({verts:R().int().nonnegative(),edges:R().int().nonnegative(),faces:R().int().nonnegative(),corners:R().int().nonnegative()}).strict(),revision:R().int().nonnegative()}).strict(),ps=Vt([us,Ho,ms,_s]),lo=new Set;function gs(e,t){const n=new Blob([e],{type:t}),o=new Oa;let r=!1;o.addEventListener("dispose",()=>{r=!0,o.image?.close?.()});const a=createImageBitmap(n,{imageOrientation:"flipY",premultiplyAlpha:"none",colorSpaceConversion:"none"}).then(i=>{if(r){i.close();return}o.image=i,o.needsUpdate=!0,ht()}).finally(()=>{lo.delete(a)});return lo.add(a),a.catch(()=>{}),{texture:o,ready:a}}function vs(e,t,n,o){const r=new $n(e,t,n,Ln,wa);return r.flipY=!1,r.colorSpace=o==="data"?zn:Lt,r.needsUpdate=!0,r}function xs(e,t,n){if(t.length===0)throw new Error(`Runtime image ${e} is tiled with no tiles`);const o=Math.max(...t.map(l=>l.width)),r=Math.max(...t.map(l=>l.height)),a=new Uint8Array(o*r*4*t.length),i=Math.max(...t.map(l=>l.number-1001))+1,f=new Float32Array(i*2*4);for(let l=0;l<i;l++)f[l*4]=-1;t.forEach((l,s)=>{const c=l.rgba??(l.rgbaBase64?se(l.rgbaBase64):void 0);if(!c)throw new Error(`Runtime image ${e} tile ${l.number} carries no raster`);for(let d=0;d<l.height;d++)a.set(c.subarray(d*l.width*4,(d+1)*l.width*4),(s*r+d)*o*4);const m=l.number-1001;f[m*4]=s,f.set([0,0,l.width/o,l.height/r],(i+m)*4)});const u=new ya(a,o,r,t.length);u.colorSpace=n==="data"?zn:Lt,u.magFilter=Yt,u.minFilter=Ao,u.generateMipmaps=!0,u.needsUpdate=!0;const _=new $n(f,i,2,Ln,go);return _.magFilter=_.minFilter=re,_.needsUpdate=!0,{tiles:u,map:_,frame:t}}const bs=N({width:R().int().positive(),height:R().int().positive(),revision:R().int().nonnegative(),rgba:Y(Uint8Array).optional(),rgbaBase64:I().optional(),colorspace:K(["sRGB","data"]).optional(),tiles:$(N({number:R().int().min(1001),width:R().int().positive(),height:R().int().positive(),rgba:Y(Uint8Array).optional(),rgbaBase64:I().optional()}).strict()).optional()}).strict(),ys=N({revision:R().int().nonnegative(),encoded:Y(Uint8Array).optional(),encodedBase64:I().optional(),mime:K(["image/png","image/jpeg"]),colorspace:K(["sRGB","data"]).optional()}).strict(),Go=Vt([bs,ys]),te=N({image:N({name:I(),revision:R().int().nonnegative()}).strict(),extension:K(["REPEAT","EXTEND","MIRROR","CLIP"]).default("REPEAT"),uv:I(),tint:U([C,C,C]).optional()}).strict(),ws=N({name:I(),color:U([C,C,C,C]),roughness:C,metallic:C,transmission:C,ior:C,physical:Ti.optional(),normal_texture:te.optional(),normal_strength:C.default(1),normal_space:K(["TANGENT","OBJECT"]).default("TANGENT"),normal_directx:et().default(!1),texture:te.optional(),roughness_texture:te.optional(),emission:N({color:U([C,C,C]),strength:C}).strict().optional(),graph:Jr.optional(),viewport:N({color:U([C,C,C,C]),roughness:C,metallic:C}).strict().optional()}).strict(),Os=N({session:I(),revision:R().int().nonnegative(),volumes:yt(I(),ko).default({}),lights:yt(I(),Cr).default({}),world:Wr.nullable().default(null),meshes:yt(I(),ps),materials:yt(I(),ws),images:yt(I(),Go).default({}),objects:$(N({id:I(),name:I(),type:K(["MESH","CURVE","SURFACE","FONT","META","ARMATURE","LATTICE","VOLUME","EMPTY","CAMERA","LIGHT","SPEAKER","GREASEPENCIL","POINTCLOUD","LIGHT_PROBE"]),mesh:I().nullable(),volume:I().nullable().optional(),light:I().nullable().optional(),materials:$(I().nullable()),matrix:$(U([C,C,C,C])).length(4),visible:et(),render_visible:et().default(!0),selected:et(),parent:I().nullable(),texspace:U([U([C,C,C]),U([C,C,C])]).optional(),default_color:I().optional()}).strict()),active:I().nullable(),mode:I(),cameras:yt(I(),yt(I(),So())).default({}),warnings:$(I()).default([]),updated:$(I()).default([]),frame:R().int().default(0),armatures:yt(I(),La).default({}),weights:Ri.nullable().default(null),cursor:Ci.optional(),camera_view:N({scene_camera:I().nullable(),view_layer_cameras:$(I()),aspect:R().finite().positive()}).optional(),light_distances:yt(I(),U([R().finite(),R().finite()])).default({}),empties:yt(I(),Bi).default({}),view:N({location:U([R(),R(),R()]),rotation:U([R(),R(),R(),R()]),distance:R().finite(),perspective:K(["PERSP","ORTHO","CAMERA"]),lens:R().finite().positive().default(50),shading:K(["WIREFRAME","SOLID","MATERIAL","RENDERED"]).optional()}).nullable().optional(),subject:N({frame:R().int(),body:I(),markers:$(U([R().int(),I()]))}).optional(),units:N({system:K(["NONE","METRIC","IMPERIAL"]),scale_length:R().finite()}).optional()}).strict();function As(e,t){for(let n=0,o=e.length-1;n<e.length&&o>=0;n++,o--){if(e[n][0]===t)return e[n][1];if(n===o)break;if(e[o][0]===t)return e[o][1]}return null}const Ts={METRIC:[[1e-6,"Micrometers"],[.001,"Millimeters"],[.01,"Centimeters"],[.1,"10 Centimeters"],[1,"Meters"],[10,"10 Meters"],[100,"100 Meters"],[1e3,"Kilometers"]],IMPERIAL:[[254e-7,"Thou"],[.0254,"Inches"],[.3048,"Feet"],[.9144,"Yards"],[20.1168,"Chains"],[201.168,"Furlongs"],[1609.344,"Miles"]]};class Cn{constructor(){this.root=new lt,this.instances=new is(this.root),this.transparentInstances=new ss(this.root),this.motionGeometry=new ls(ht),this.drawBatching=!0,this.objects=new Map,this.meshes=new Map,this.volumes=new Map,this.materials=new Map,this.lights=new Map,this.lighting=new Ur,this.world=new we,this.armatureOverlay=new Za,this.weightOverlay=new Di,this.cursorOverlay=new ji,this.extrasOverlay=new qi,this.armatureRoot=new lt,this.weightRoot=new lt,this.cursorRoot=new lt,this.cameraExtrasRoot=new lt,this.lightExtrasRoot=new lt,this.emptyExtrasRoot=new lt,this.rendered=!1,this.heldRendered=null,this.worldApplied=null,this.worldKey="null",this.capturing=!1,this.workbench=!1,this.workbenchMaterials=new Map,this.fallback=new an({color:12172998,roughness:.72}),this.textures=new Map,this.textureNames=new Map,this.roughnessTextureNames=new Map,this.textureSamplers=new Ai,this.graphSamplers=new Map,this.photograph=!1,this.graphs=new Map,this.frame=null,this.retiredSessions=new Set,this.geometryBuilds=0,this.submittedMeshes=new Map,this.submitted=null,this.submittedSession=null,this.photographs=[],this.frameListeners=new Set,this.followers=new Set,this.leader=null,this.cameraViewZoom=Xi,this.cameraViewPan=Yi,this.mode=null,this.awaitedImages=new Set,this.lookingThrough=null,this.staged=null;const t=this.root.updateMatrixWorld.bind(this.root);this.root.updateMatrixWorld=n=>{t(n),this.instances.sync()},this.root.name="Model",this.root.matrixAutoUpdate=!1,this.root.matrix.set(1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1),this.root.updateMatrixWorld(!0);for(const[n,o]of[[this.armatureRoot,this.armatureOverlay.group],[this.weightRoot,this.weightOverlay.group],[this.cursorRoot,this.cursorOverlay.group],[this.cameraExtrasRoot,this.extrasOverlay.cameras],[this.lightExtrasRoot,this.extrasOverlay.lights],[this.emptyExtrasRoot,this.extrasOverlay.empties]])n.matrixAutoUpdate=!1,n.matrix.copy(this.root.matrix),n.add(o),n.updateMatrixWorld(!0);this.armatureRoot.name="BlenderBones",this.weightRoot.name="BlenderWeights",this.cursorRoot.name="Blender3DCursor",this.cameraExtrasRoot.name="BlenderCameraExtras";for(const n of[this.cameraExtrasRoot,this.lightExtrasRoot,this.emptyExtrasRoot])n.userData.volterPickable=!0;this.lightExtrasRoot.name="BlenderLightExtras",this.emptyExtrasRoot.name="BlenderEmptyExtras"}compiledGraph(t){const n=JSON.stringify(t);let o=this.graphs.get(n);return o||(o=_i(t),this.graphs.size>256&&this.graphs.clear(),this.graphs.set(n,o)),o}mirrorPose(t){let n=null;for(const[a,i]of this.objects)if(i===t){n=a;break}if(n===null)return;const o=this.leader?[this.leader,...this.leader.followers]:[...this.followers];let r=!1;for(const a of o){if(a===this)continue;const i=a.objects.get(n);i!==void 0&&(i.matrix.copy(t.matrix),i.matrix.decompose(i.position,i.quaternion,i.scale),i.updateMatrixWorld(!0),r=!0)}r&&ht()}subscribeFrames(t){return this.frameListeners.add(t),()=>{this.frameListeners.delete(t)}}onChange(t){const n=this.subscribeFrames(t),o=ka(t);return()=>{n(),o()}}blenderObjectName(t){for(const[n,o]of this.objects)if(o===t)return this.frame?.objects.find(r=>r.id===n)?.name??null;return null}noteSavedShading(t){this.frame?.view&&(this.frame.view.shading=t)}savedView(){const t=this.frame?.view;if(!t)return null;const[n,o,r,a]=t.rotation,i=new At(o,r,a,n),f=new x(...t.location).applyMatrix4(this.root.matrix),u=_=>_.applyQuaternion(i).applyMatrix4(this.root.matrix).normalize();return{target:f.toArray(),direction:u(new x(0,0,1)).toArray(),up:u(new x(0,1,0)).toArray(),distance:t.distance,projection:t.perspective==="ORTHO"?"orthographic":"perspective",lens:t.lens,drawMode:t.shading?fs[t.shading]:null}}cameraViewCamera(){const t=this.frame,n=t?.camera_view;return!t||!n?null:n.scene_camera!==null&&t.cameras[n.scene_camera]?n.scene_camera:t.active!==null&&t.cameras[t.active]?t.active:n.view_layer_cameras.find(o=>t.cameras[o])??null}blenderPose(t,n){const o=new H().copy(this.root.matrix).invert(),r=new H().compose(new x(...t),new At(...n),new x(1,1,1)).premultiply(o),a=new x,i=new At;return r.decompose(a,i,new x),{location:a.toArray(),rotation:[i.w,i.x,i.y,i.z]}}cameraView(t,n,o,r){const a=this.frame,i=eo.safeParse(a?.cameras[t]);return!a?.camera_view||!i.success?null:Zi(i.data,this.root.matrix,n,o,r,a.camera_view.aspect)}subjectLine(t){const n=this.frame?.subject;if(n===void 0)return null;const o=t??n.frame,r=As(n.markers,o);return`(${o})${n.body}${r===null?"":` <${r}>`}`}gridUnitName(t){const n=this.frame?.units;if(n===void 0||n.system==="NONE")return null;const o=Ts[n.system],r=6*t,a=1/(n.scale_length||1);return(o.find(([f])=>f*a>r)??o[o.length-1])[1]}blenderSelection(){const t=this.frame;return t===null?{selected:[],active:null}:{selected:t.objects.filter(n=>n.selected).map(n=>n.name),active:t.active}}setStageMode(t){this.mode=t}stageMode(){return this.mode}objectForBlenderName(t){const n=this.frame?.objects.find(o=>o.name===t);return n===void 0?null:this.objects.get(n.id)??null}replacePresentedObject(t,n){for(const[o,r]of this.objects)if(r===t){const a=t.parent,i=[...t.children];t.removeFromParent();for(const f of i)n.add(f);a?.add(n),this.objects.set(o,n),this.rebuildInstances();return}}studioLights(){return this.lighting.group}overlayGroups(){return[{kind:"skeletons",object:this.armatureRoot},{kind:"weights",object:this.weightRoot},{kind:"cursor",object:this.cursorRoot},{kind:"cameras",object:this.cameraExtrasRoot},{kind:"lights",object:this.lightExtrasRoot},{kind:"empties",object:this.emptyExtrasRoot}]}placeCursor(t,n,o){const r=new Set(this.objects.values()),a=this.cursorOverlay.placementAt(t,n,o,this.root,i=>r.has(i));return a!==null&&(this.cursorOverlay.show(a),ht()),a}holdRendered(t){t!==this.heldRendered&&(this.heldRendered=t,!this.capturing&&this.report(t===null?this.applyRendered(!1):this.applyRendered(!0,t())))}refreshRendered(){if(this.heldRendered===null||this.capturing)return;const t=this.heldRendered();this.worldKeyFor(t)!==this.worldApplied&&this.report(this.applyRendered(!0,t))}worldKeyFor(t){const o=t.isOrthographicCamera?t.getWorldDirection(new x).toArray().map(r=>r.toFixed(1)).join(","):"";return`${t.uuid}:${o}:${this.worldKey}`}report(t){t.then(ht,n=>console.error(`Rendered shading could not be applied: ${n instanceof Error?n.message:String(n)}`))}setWorkbench(t){t!==this.workbench&&(this.workbench=t,this.applyWorkbench(),ht())}applyWorkbench(){const t=this.workbench&&!this.rendered,n=new Set;for(const o of this.frame?.objects??[]){if(o.mesh===null||o.volume)continue;const r=this.objects.get(o.id);if(!r?.isMesh)continue;const i=(o.materials.length?o.materials:[null]).map(f=>{const u=f===null?this.fallback:this.materials.get(f)??this.fallback;return t?this.workbenchFor(f,u.side,n):u});r.material=o.materials.length?i:i[0]}for(const[o,r]of this.workbenchMaterials)n.has(o)||(r.dispose(),this.workbenchMaterials.delete(o));this.rebuildInstances()}rebuildInstances(){this.transparentInstances.clear(),this.instances.rebuild(this.objects.values(),this.drawBatching&&!this.rendered),this.drawBatching&&!this.rendered&&this.transparentInstances.setObjects(this.objects.values()),this.motionGeometry.setObjects(this.objects.values())}setDrawBatching(t){t!==this.drawBatching&&(this.drawBatching=t,this.rebuildInstances(),ht())}prepareDraw(t,n){try{this.instances.prepareDraw(t),this.root.updateMatrixWorld(!0),this.motionGeometry.prepare(t,!this.rendered&&(this.mode??this.frame?.mode)==="OBJECT"&&n?.interactive===!0,n?.height??0)&&this.instances.sync(),this.transparentInstances.prepare(t)}catch(o){throw this.motionGeometry.finish(),this.instances.finishDraw(),this.transparentInstances.finishDraw(),o}return()=>{this.motionGeometry.finish(),this.instances.finishDraw(),this.transparentInstances.finishDraw()}}workbenchFor(t,n,o){const r=(t!==null?this.frame?.materials[t]?.viewport:void 0)??Qi,a=`${r.color.join(",")}|${r.roughness}|${r.metallic}|${n}`;o.add(a);let i=this.workbenchMaterials.get(a);return i||(i=os(r,n),this.workbenchMaterials.set(a,i)),i}renderedHeld(){return this.heldRendered!==null}async setRendered(t,n){return this.capturing=t,!t&&this.heldRendered!==null?this.applyRendered(!0,this.heldRendered()):this.applyRendered(t,n)}async applyRendered(t,n){const o=(t?Ke(this.frame?.world)?.extinction:null)??new x;for(const a of[...this.materials.values(),this.fallback])Mi(a,o);this.rendered=t,this.lighting.setRendered(t);const r=t&&n?this.worldKeyFor(n):null;t?(this.capturing||r!==this.worldApplied)&&this.world.apply(this.root,this.frame?.world??null,n):this.world.clear(),this.worldApplied=this.capturing?null:r,this.applyVisibility(),this.applyWorkbench(),this.applyShadows(t,n),t&&(await $r(),await Promise.all([...this.textures.values()].map(a=>a.ready)),await this.world.ready())}applyShadows(t,n){this.root.updateMatrixWorld(!0);const o=[];for(const u of this.objects.values()){const _=u;if(_.isMesh&&(_.castShadow=t,_.receiveShadow=t,t&&_.visible)){const l=new on().setFromObject(_);l.isEmpty()||o.push(l)}}if(!t||!o.length)return;const a=o.reduce((u,_)=>u.union(_),new on).getBoundingSphere(new Oo),i=n?new Vn().setFromProjectionMatrix(new H().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse)):null,f=i?o.flatMap(u=>Gr(u,i)):[];for(const u of this.lights.values())u.isDirectionalLight&&n?Xr(u,f,o):jr(u,a.center,a.radius)}applyOverlays(t){const n=i=>{const f=t.objects.find(u=>u.name===i);return f===void 0?null:new H().set(...f.matrix.flat())},o=[...this.armatureOverlay.apply(t.armatures,n)],r=t.weights?this.objects.get(t.objects.find(i=>i.name===t.weights?.object)?.id??""):void 0,a=this.weightOverlay.apply(t.weights,r??null,t.weights?n(t.weights.object):null);return a!==null&&o.push(a),this.cursorOverlay.apply(t.cursor),this.applyExtras(t),o}setCameraViewShowing(t){this.lookingThrough!==t&&(this.lookingThrough=t,this.frame&&this.applyExtras(this.frame),ht())}applyExtras(t){const n={};for(const[o,r]of Object.entries(t.cameras)){const a=eo.safeParse(r);a.success&&(n[o]=a.data)}this.extrasOverlay.apply({lookingThrough:this.lookingThrough,lightDistances:t.light_distances,objects:t.objects.filter(o=>o.visible),active:t.active,cameras:n,lights:t.lights,empties:t.empties,sceneCamera:t.camera_view?.scene_camera??null,renderAspect:t.camera_view?.aspect??1,presented:o=>{const r=t.objects.find(a=>a.name===o);return r?this.objects.get(r.id)??null:null},image:o=>{const r=this.textures.get(o);if(!r)return null;const a=r.texture.image,i=r.width||a?.width||0,f=r.height||a?.height||0;return(i===0||f===0)&&r.ready&&!this.awaitedImages.has(o)&&(this.awaitedImages.add(o),r.ready.then(()=>{this.awaitedImages.delete(o),this.frame&&this.applyExtras(this.frame),ht()},()=>this.awaitedImages.delete(o))),{texture:r.texture,width:i,height:f}}})}applyVisibility(){for(const t of this.frame?.objects??[]){const n=this.objects.get(t.id);if(n&&(n.visible=this.rendered?t.render_visible:t.visible),!t.light)continue;const o=this.lights.get(t.light);o&&(o.visible=this.rendered&&t.render_visible)}this.armatureOverlay.group.visible=!this.capturing,this.weightOverlay.group.visible=!this.capturing,this.cursorOverlay.group.visible=!this.capturing;for(const t of[this.extrasOverlay.cameras,this.extrasOverlay.lights,this.extrasOverlay.empties])t.visible=!this.capturing}stageFrame(t){if(t.abort||!t.mesh&&!t.image){for(const o of this.staged?.meshes.values()??[])o.geometry.dispose();this.staged=t.abort?null:{session:t.session,revision:t.revision,meshes:new Map,images:new Map};return}const n=this.staged;if(!n||n.session!==t.session||n.revision!==t.revision)throw new Error("Blender frame piece does not belong to the pending revision");if(t.mesh!==void 0){const o=Ho.parse(t.piece);if(n.meshes.has(t.mesh))throw new Error("Duplicate Blender mesh piece");const r=`revision:${o.revision}`;n.meshes.set(t.mesh,{signature:r,geometry:Nn(ke({...o.columns,attributes:o.attributes,activeUv:o.activeUv,renderUv:o.renderUv},r))})}else if(t.image!==void 0){if(n.images.has(t.image))throw new Error("Duplicate Blender image piece");n.images.set(t.image,Go.parse(t.piece))}}applyFrame(t){const n=this.frame===null?null:{session:this.frame.session,revision:this.frame.revision},o=Os.parse(t),r=this.staged;if(r&&(r.session!==o.session||r.revision!==o.revision))throw new Error("Blender frame manifest does not match its staged revision");if(r)for(const[l,s]of r.images)o.images[l]=s;if(this.retiredSessions.has(o.session))throw new Error("The runtime session was replaced; its delayed frame cannot overwrite the active model");if(this.frame?.session===o.session&&o.revision<this.frame.revision)throw new Error("The runtime frame is older than the displayed model");const a=new Set(o.objects.map(l=>l.id));if(a.size!==o.objects.length)throw new Error("Runtime object IDs must be unique");const i=new Map(o.objects.map(l=>[l.id,l]));for(const l of o.objects){if(l.mesh!==null&&!o.meshes[l.mesh])throw new Error(`Missing runtime mesh ${l.mesh}`);if(l.volume&&(!o.volumes[l.volume]||l.mesh!==null))throw new Error(`Invalid runtime volume ${l.volume}`);if(l.light&&(!o.lights[l.light]||l.mesh!==null))throw new Error(`Invalid runtime light ${l.light}`);for(const m of l.materials)if(m!==null&&!o.materials[m])throw new Error(`Missing runtime material ${m}`);const s=new Set([l.id]);let c=l.parent;for(;c!==null;){if(s.has(c))throw new Error("Runtime parent cycle");s.add(c);const m=i.get(c);if(!m)throw new Error(`Missing runtime parent ${c}`);c=m.parent}}const f=new Map,u=new Map;try{for(const[l,s]of Object.entries(o.volumes)){const c=JSON.stringify(s);this.frame?.session===o.session&&this.volumes.get(l)?.signature===c||u.set(l,{signature:c,mesh:Yr(s)})}for(const[l,s]of Object.entries(o.meshes)){if("unchanged"in s){const h=r?.meshes.get(l);if(h){if(h.signature!==`revision:${s.revision}`)throw new Error("Staged Blender mesh revision mismatch");f.set(l,h);continue}const g=this.meshes.get(l)?.signature;if(this.frame?.session===o.session&&g!==void 0&&(g===`revision:${s.revision}`||!g.startsWith("revision:")))continue;throw new Error(g===void 0?`${Fe}: the presenter does not hold runtime mesh ${l} (store ${s.store}, revision ${s.revision})`:`${Fe}: the presenter holds runtime mesh ${l} at ${g}, not revision ${s.revision}`)}const c="hash"in s,m="columns"in s,d=m?`revision:${s.revision}`:c?s.hash:JSON.stringify(s);this.frame?.session===o.session&&this.meshes.get(l)?.signature===d||f.set(l,{signature:d,geometry:m?Nn(ke({...s.columns,attributes:s.attributes,activeUv:s.activeUv,renderUv:s.renderUv},d)):c?Nn(s):fr(s)})}}catch(l){for(const s of f.values())s.geometry.dispose();for(const{mesh:s}of u.values())s.geometry.dispose(),s.material.dispose();throw l}if(r){for(const[l,s]of r.meshes)f.has(l)||s.geometry.dispose();this.staged=null}this.frame?.session!==o.session&&(this.frame&&this.retiredSessions.add(this.frame.session),this.clear());for(const[l,s]of u){const c=this.volumes.get(l)?.mesh;c&&(c.removeFromParent(),c.geometry.dispose(),c.material.dispose()),this.volumes.set(l,s)}for(const[l,s]of f)this.meshes.get(l)?.geometry.dispose(),this.meshes.set(l,s),this.geometryBuilds++;for(const[l,s]of Object.entries(o.images)){const c=this.textures.get(l);if("width"in s){const p=s.rgba??(s.rgbaBase64?se(s.rgbaBase64):void 0);if(!p)throw new Error(`Runtime image ${l} carries no raster`);const v=s.tiles?xs(l,s.tiles,s.colorspace??"sRGB"):void 0;if(c?.udim&&(c.udim.tiles.dispose(),c.udim.map.dispose(),delete c.udim),c&&c.width===s.width&&c.height===s.height){const O=c.texture.image;if(O.data){O.data.set(p),c.texture.needsUpdate=!0,c.revision=s.revision,v&&(c.udim=v);continue}}c?.texture.dispose(),this.textures.set(l,{texture:vs(p,s.width,s.height,s.colorspace??"sRGB"),width:s.width,height:s.height,revision:s.revision,...v?{udim:v}:{}});continue}const m=s.encoded??(s.encodedBase64?se(s.encodedBase64):void 0);if(!m)throw new Error(`Runtime image ${l} carries no bytes`);c?.texture.dispose(),c?.udim?.tiles.dispose(),c?.udim?.map.dispose();const d=s.colorspace??"sRGB",{texture:h,ready:g}=gs(m,s.mime);h.colorSpace=d==="data"?zn:Lt,this.textures.set(l,{texture:h,ready:g,width:0,height:0,revision:s.revision,encoded:{bytes:m.slice(),mime:s.mime,colorspace:d}})}for(const[l,s]of Object.entries(o.materials)){const c=this.materials.get(l)??new an;c.name=s.name;const m=s.texture?.tint;s.texture!==void 0?c.color.setRGB(m?.[0]??1,m?.[1]??1,m?.[2]??1,vt):c.color.setRGB(s.color[0],s.color[1],s.color[2],vt),c.opacity=s.color[3];const d=c.opacity<1||s.graph!==void 0&&ti(s.graph);c.transparent!==d&&(c.transparent=d,c.needsUpdate=!0),c.roughness=s.roughness,c.metalness=s.metallic,c.transmission=s.transmission,c.ior=s.ior,Ae(c,s.physical,{map:s.texture?.extension==="CLIP",roughness:s.roughness_texture?.extension==="CLIP",normal:s.normal_texture?.extension==="CLIP"});const h=s.normal_texture?.image.name;if(h===void 0)c.normalMap&&(this.textureSamplers.delete(`${l}:normal`),c.normalMap=null,c.needsUpdate=!0);else{const b=this.textures.get(h);if(!b)throw new Error(`${fn}: missing normal image ${h}`);const P=this.textureSamplers.get(`${l}:normal`,b.texture,s.normal_texture.extension,b.ready,s.normal_texture.uv);c.normalMap!==P&&(c.normalMap=P,c.needsUpdate=!0);const T=s.normal_space==="OBJECT"?xa:ba;c.normalMapType!==T&&(c.normalMapType=T,c.needsUpdate=!0),c.normalScale.set(s.normal_strength,s.normal_strength*(s.normal_directx?-1:1))}s.emission?(c.emissive.setRGB(s.emission.color[0],s.emission.color[1],s.emission.color[2],vt),c.emissiveIntensity=s.emission.strength):(c.emissive.setRGB(0,0,0),c.emissiveIntensity=1);const g=s.roughness_texture?.image.name??null;if(g===null)this.roughnessTextureNames.has(l)&&(this.textureSamplers.delete(`${l}:roughness`),c.roughnessMap=null,this.roughnessTextureNames.delete(l),c.needsUpdate=!0);else{const b=this.textures.get(g);if(!b)throw new Error(`${fn}: the presenter does not hold runtime image ${g} (revision ${s.roughness_texture.image.revision})`);const P=this.textureSamplers.get(`${l}:roughness`,b.texture,s.roughness_texture.extension,b.ready,s.roughness_texture.uv);c.roughnessMap!==P&&(c.roughnessMap=P,this.roughnessTextureNames.set(l,g),c.needsUpdate=!0)}const p=s.texture?.image.name??null;if(p===null)this.textureNames.has(l)&&(this.textureSamplers.delete(`${l}:color`),c.map=null,this.textureNames.delete(l),c.needsUpdate=!0);else{const b=this.textures.get(p);if(!b)throw new Error(`${fn}: the presenter does not hold runtime image ${p} (revision ${s.texture.image.revision})`);const P=this.textureSamplers.get(`${l}:color`,b.texture,s.texture.extension,b.ready,s.texture.uv);c.map!==P&&(c.map=P,this.textureNames.set(l,p),c.needsUpdate=!0)}const v=s.graph?this.compiledGraph(s.graph):null,O=new Set;hi(c,v,b=>{const P=this.textures.get(b.name);if(!P)throw new Error(`${fn}: the presenter does not hold runtime image ${b.name} (revision ${b.revision})`);if(b.tiled){if(!P.udim)throw new Error(`${fn}: runtime image ${b.name} arrived without its UDIM tiles`);return P.udim}const T=`${l}:graph:${b.node}`;O.add(T);const M=this.textureSamplers.get(T,P.texture,b.extension,P.ready),A=b.closest?re:Yt,w=b.closest?re:b.mipmap?Ao:Yt;return(M.magFilter!==A||M.minFilter!==w)&&(M.magFilter=A,M.minFilter=w,M.needsUpdate=!0),M},this.photograph);for(const b of this.graphSamplers.get(l)??[])O.has(b)||this.textureSamplers.delete(b);this.graphSamplers.set(l,O),this.materials.set(l,c)}for(const l of o.objects){let s=this.objects.get(l.id);const c=l.volume?this.volumes.get(l.volume).mesh:null;if((!s||(c?s!==c:!!s.isMesh!=(l.mesh!==null)))&&(s?.removeFromParent(),s=c??(l.mesh!==null?new Rt(this.meshes.get(l.mesh).geometry,this.fallback):new ho),this.objects.set(l.id,s)),s.name=l.name,l.type==="CAMERA"||l.type==="LIGHT"||l.type==="EMPTY"?s.userData.volterOwnOverlay=!0:delete s.userData.volterOwnOverlay,s.matrixAutoUpdate=!1,s.matrix.set(...l.matrix.flat()),l.parent){const m=new H().set(...i.get(l.parent).matrix.flat());s.matrix.premultiply(m.invert())}if(s.matrix.decompose(s.position,s.quaternion,s.scale),l.texspace?s.userData.blenderTexspace=l.texspace:delete s.userData.blenderTexspace,l.default_color!==void 0?s.userData.blenderDefaultColor=l.default_color:delete s.userData.blenderDefaultColor,l.mesh!==null){const m=s;m.geometry=this.meshes.get(l.mesh).geometry,m.material=l.materials.length?l.materials.map(d=>d===null?this.fallback:this.materials.get(d)):this.fallback,xi(m)}if(l.light){const m=this.lights.get(l.light)??null,d=Vr(o.lights[l.light],m);m&&m!==d&&(m.removeFromParent(),m.dispose()),d.parent!==s&&s.add(d),d.userData.volterOwnOverlay=!0,Br(d,s),this.lights.set(l.light,d)}}for(const l of o.objects){const s=this.objects.get(l.id),c=l.parent===null?this.root:this.objects.get(l.parent);s.parent!==c&&c.add(s)}for(const[l,s]of this.objects)a.has(l)||(s.removeFromParent(),this.objects.delete(l));for(const[l,s]of this.volumes)o.volumes[l]||(s.mesh.geometry.dispose(),s.mesh.material.dispose(),this.volumes.delete(l));for(const[l,s]of this.meshes)o.meshes[l]||(s.geometry.dispose(),this.meshes.delete(l));for(const[l,s]of this.materials)if(!o.materials[l]){for(const c of["normal","roughness","color"])this.textureSamplers.delete(`${l}:${c}`);for(const c of this.graphSamplers.get(l)??[])this.textureSamplers.delete(c);this.graphSamplers.delete(l),s.dispose(),this.materials.delete(l)}for(const[l,s]of this.lights)o.lights[l]||(s.removeFromParent(),s.dispose(),this.lights.delete(l));this.root.updateMatrixWorld(!0),this.frame={...o,meshes:{},volumes:{},images:{}},this.worldKey=JSON.stringify(o.world??null);const _=this.applyOverlays(o);_.length&&(this.frame={...this.frame,warnings:[...this.frame.warnings,..._]}),this.applyVisibility(),this.applyWorkbench(),this.heldRendered!==null&&!this.capturing&&this.report(this.applyRendered(!0,this.heldRendered()));for(const l of[...this.frameListeners])l();for(const l of this.followers)try{l.applyFrame(t)}catch{l.applyFrame(this.fullFrame())}return{...this.inspect(),held:n}}inspect(){return{session:this.frame?.session,revision:this.frame?.revision,active:this.frame?.active,mode:this.frame?.mode,geometryBuilds:this.geometryBuilds,instancing:this.drawStatistics(),objects:[...this.objects].map(([t,n])=>({id:t,name:n.name,uuid:n.uuid,geometry:n.geometry?.uuid,visible:n.visible}))}}drawStatistics(){return{enabled:this.drawBatching,opaque:this.instances.inspect(),transparent:this.transparentInstances.inspect(),motion:this.motionGeometry.inspect()}}snapshot(){return this.frame}fullFrame(){const t=this.frame;if(!t)throw new Error("Blender capture requires a presented frame");const n=structuredClone({...t,images:{},armatures:{},weights:null});for(const[r,{signature:a,geometry:i}]of this.meshes){const f=l=>{const s=i.getAttribute(l);if(!s)return null;if(!(s instanceof ct))throw new Error(`Blender capture cannot copy interleaved ${l}`);return new Float32Array(s.array)},u=f("position");if(!u)throw new Error(`Blender capture mesh ${r} has no positions`);const _=i.getIndex();n.meshes[r]={hash:a,positions:u,normals:f("normal"),uv:f("uv"),uvLayers:Object.entries(i.userData.blenderUvChannels??{}).map(([l,s])=>{const c=f(`uv${s}`);if(!c)throw new Error(`Blender capture mesh ${r} is missing UV layer ${l}`);return{name:l,data:c}}),orco:i.userData.blenderOrcoFromDoor?f("blenderOrco"):null,attributeLayers:(i.userData.blenderAttributes??[]).map(l=>{const s=f($t(l));if(!s)throw new Error(`Blender capture mesh ${r} is missing attribute ${l}`);return{name:l,data:s}}),indices:_?new Uint32Array(_.array):Uint32Array.from({length:u.length/3},(l,s)=>s),groups:i.groups.map(l=>({start:l.start,count:l.count,materialIndex:l.materialIndex??0}))}}for(const[r,{signature:a}]of this.volumes)n.volumes[r]=ko.parse(JSON.parse(a));const o=new Set(Object.values(n.materials).flatMap(r=>[r.texture?.image.name,r.roughness_texture?.image.name,r.normal_texture?.image.name,...Object.values(r.graph?.nodes??{}).map(a=>a.props.image?.name)].filter(a=>a!==void 0)));for(const r of o){const a=this.textures.get(r);if(!a)throw new Error(`Blender capture image ${r} is not resident`);if(a.encoded)n.images[r]={revision:a.revision,encoded:a.encoded.bytes.slice(),mime:a.encoded.mime,colorspace:a.encoded.colorspace};else{const i=a.texture.image?.data;if(!(i instanceof Uint8Array))throw new Error(`Blender capture image ${r} has no resident raster`);n.images[r]={revision:a.revision,width:a.width,height:a.height,rgba:i.slice(),colorspace:a.texture.colorSpace===zn?"data":"sRGB",...a.udim?{tiles:a.udim.frame}:{}}}}return n}follow(){const t=new Cn;this.frame&&t.applyFrame(this.fullFrame()),this.followers.add(t),t.leader=this;let n=!1;return{view:t,dispose:()=>{n||(n=!0,this.followers.delete(t),t.leader=null,t.dispose(),t.root.removeFromParent())}}}captureSnapshot(){const t=this.fullFrame(),n=this.frame,o=this.createWorldVolumePass(),r=new Cn;r.photograph=!0;let a=!1;const i=()=>{a||(a=!0,o?.dispose(),r.dispose(),r.root.removeFromParent())};try{r.applyFrame(t),this.root.updateWorldMatrix(!0,!1),r.root.matrix.copy(this.root.matrixWorld),r.root.updateMatrixWorld(!0)}catch(f){throw i(),f}return{effect:o,root:r.root,session:n.session,revision:n.revision,prepare:f=>{if(a)throw new Error("Blender capture snapshot is disposed");return r.setRendered(!0,f)},dispose:i}}createWorldVolumePass(){const t=Ke(this.frame?.world);return t?new Ni(t):void 0}recordPresentation(t){if(typeof t!="object"||t===null)return;const n=t,o=n.meshes;if(typeof o!="object"||o===null)return;const r=typeof n.session=="string"?n.session:null;r!==this.submittedSession&&(this.submittedMeshes.clear(),this.photographs.length=0,this.submittedSession=r);const a=o;for(const[i,f]of Object.entries(a))typeof f=="object"&&f!==null&&!("unchanged"in f)&&this.submittedMeshes.set(i,f);for(const i of[...this.submittedMeshes.keys()])i in a||this.submittedMeshes.delete(i);this.submitted={...n,meshes:Object.fromEntries(this.submittedMeshes)}}recordPhotograph(t){this.photographs.push(t)}observations(){return{presentation:this.submitted,photographs:this.photographs}}clear(){this.motionGeometry.clear(),this.transparentInstances.clear(),this.instances.clear();for(const t of this.staged?.meshes.values()??[])t.geometry.dispose();this.staged=null;for(const t of this.lights.values())t.removeFromParent(),t.dispose();this.lights.clear();for(const t of this.objects.values())t.removeFromParent();for(const t of this.meshes.values())t.geometry.dispose();for(const t of this.materials.values())t.dispose();for(const{mesh:t}of this.volumes.values())t.geometry.dispose(),t.material.dispose();for(const{texture:t,udim:n}of this.textures.values())t.dispose(),n?.tiles.dispose(),n?.map.dispose();this.textures.clear(),this.textureNames.clear(),this.roughnessTextureNames.clear(),this.textureSamplers.clear(),this.volumes.clear(),this.objects.clear(),this.meshes.clear(),this.materials.clear()}dispose(){this.clear(),this.fallback.dispose(),this.lighting.dispose(),this.world.dispose(),this.armatureOverlay.dispose(),this.weightOverlay.dispose(),this.cursorOverlay.dispose(),this.extrasOverlay.dispose();for(const t of this.workbenchMaterials.values())t.dispose();this.workbenchMaterials.clear(),this.frame=null,this.retiredSessions.clear(),this.submittedMeshes.clear(),this.submitted=null,this.submittedSession=null,this.photographs.length=0}}const Fs=new Cn;function Xo(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}function ne(e){const t=Xo(e);return new Float32Array(t.buffer,t.byteOffset,t.byteLength>>2)}function Ss(e){const t=Xo(e);return new Uint16Array(t.buffer,t.byteOffset,t.byteLength>>1)}function Ms(e){return new H().set(...e.flat())}function fo(e,t){return[e.object,e.mesh,e.armature,e.vertexCount,e.bones.length,t].join("|")}class Ps{#n=new Map;#o=null;#a=null;#t=null;#r=null;#e=null;#s=null;#l=new Set;#u=0;#m=[];#i=0;get version(){return this.#u}get engineCalls(){return this.#i}subscribe(t){return this.#l.add(t),()=>this.#l.delete(t)}#f(){this.#u++;for(const t of[...this.#l])t()}state(){const t=this.#t,n=t?.frameStart??1,o=t?.frameEnd??250,r=t?.fps??24;return{frame:this.frame(),start:n,end:o,fps:r,action:t?.action??null,object:t?.object??null,armature:t?.armature??null,bones:[...this.#n.values()].reduce((a,i)=>a+i.bones.length,0),keyframes:t?.keyframes??[],summary:t?.summary??[],clipStart:t?.clipStart??null,clipEnd:t?.clipEnd??null,tracks:t?.tracks.length??0,bound:[...this.#n.keys()],warnings:this.#m,engineCalls:this.#i,blenderFrame:t?.frameCurrent??null}}playhead(){return this.#t?this.frame():null}frame(){const t=this.#t;return this.#r!==null?this.#r:!t||!this.#a||t.clipStart===void 0?t?.frameCurrent??1:t.clipStart+this.#a.time*t.fps}get playable(){return this.#t!==null&&this.#e!==null}async bind(t,n){this.#i++;const o=await n.rig();if(!o)return;const r=[],a=new Set;let i=!1;for(const m of o.rigs){if(!m.object||!m.armature||!m.skinIndexBase64||!m.skinWeightBase64){m.reason&&r.push(m.reason);continue}a.add(m.object);const d=fo(m,o.frame);if(this.#n.get(m.object)?.signature===d)continue;const h=this.#d(t,m,o.frame,r);h&&(this.#n.get(m.object)?.skeleton.dispose(),this.#n.set(m.object,h),i=!0)}for(const[m,d]of[...this.#n])a.has(m)||(d.skeleton.dispose(),d.boneRoot.removeFromParent(),this.#n.delete(m),i=!0);this.#i++;const f=await n.clip(),u=this.#t,_=f?.frameStart!==u?.frameStart||f?.frameEnd!==u?.frameEnd||f?.fps!==u?.fps,l=f?.action!==u?.action||f?.tracks.length!==u?.tracks.length||f?.clipStart!==u?.clipStart||f?.clipEnd!==u?.clipEnd;this.#t=f??null,(!f||f.scene!==u?.scene)&&(this.#r=null),f?.reason&&r.push(f.reason),f&&(l||i)&&this.#h(t,f,r);const s=this.#e?.snapshot().activeSubject;_&&s&&this.#e?.setActiveSubject(s);const c=this.#e?.snapshot().playbackState==="playing";f&&!c&&(_||u?.frameCurrent!==f.frameCurrent)&&(this.#c(f.frameCurrent),this.#e&&f.fps>0&&this.#e.seek(f.frameCurrent/f.fps)),this.#m=r,this.#f()}#d(t,n,o,r){const a=t.objectForBlenderName(n.object??""),i=t.objectForBlenderName(n.armature??"");if(!a||!i)return null;const f=a,u=f.geometry;if(!u)return null;const _=u.getAttribute("blenderVertex");if(!_)return r.push(`"${n.object}" cannot be skinned: its presented geometry carries no \`blenderVertex\` attribute, so a per-Blender-vertex weight cannot be expanded onto its drawn vertices.`),null;if(n.vertexCount===0)return null;let l=0;for(let T=0;T<_.count;T++)l=Math.max(l,_.getX(T));if(l>=n.vertexCount)return r.push(`"${n.object}" is not skinned here: its presented geometry references Blender vertex ${l} while the mesh declares ${n.vertexCount}, which is a generative modifier (Subdivision, Mirror, Array…) between the two. Blender's own viewport shows the evaluated result; this presenter shows the exported columns unskinned.`),null;const s=Ss(n.skinIndexBase64??""),c=ne(n.skinWeightBase64??""),m=_.count,d=new Uint16Array(m*4),h=new Float32Array(m*4);for(let T=0;T<m;T++){const M=_.getX(T);for(let A=0;A<4;A++)d[T*4+A]=s[M*4+A]??0,h[T*4+A]=c[M*4+A]??0}u.setAttribute("skinIndex",new Aa(d,4)),u.setAttribute("skinWeight",new Mt(h,4));const g=new lt;g.name=`${n.armature}:bones`;const p=[],v=n.bones.map(T=>Ms(T.pose)),O=new Map(n.bones.map((T,M)=>[T.name,M]));n.bones.forEach((T,M)=>{const A=new Ta;A.name=T.name,p.push(A);const w=T.parent===null?void 0:O.get(T.parent);(w===void 0?v[M].clone():v[w].clone().invert().multiply(v[M])).decompose(A.position,A.quaternion,A.scale),(w===void 0?g:p[w]).add(A)}),i.add(g);const b=new Sa(u,f.material);b.name=f.name,b.matrixAutoUpdate=!1,b.matrix.copy(f.matrix),b.matrix.decompose(b.position,b.quaternion,b.scale),b.userData=f.userData,b.frustumCulled=!1,t.replacePresentedObject(f,b),t.root.updateMatrixWorld(!0);const P=new Ma(p);return b.bind(P,b.matrixWorld.clone()),n.constrainedBones?.length&&r.push(`Bone constraints on ${n.constrainedBones.join(", ")}: the clip is derived from the F-Curves alone, so those bones play their channels rather than Blender's solved pose.`),n.unmappedGroups?.length&&r.push(`${n.object} carries vertex groups no bone is named for (${n.unmappedGroups.join(", ")}); they weight nothing here, exactly as they deform nothing in Blender.`),{object:n.object??"",armature:n.armature??"",mesh:b,boneRoot:g,bones:p,skeleton:P,frame:o,signature:fo(n,o)}}#h(t,n,o){if(this.#o?.stopAllAction(),this.#o=null,this.#a=null,!n.tracks.length||n.clipStart===void 0||n.clipEnd===void 0)return;const r=n.armature?t.objectForBlenderName(n.armature):null;if(!r)return;const a=new Map;for(const s of this.#n.values())if(s.armature===n.armature)for(const c of s.bones)a.set(c.name,c);const i=[],f=new Set;for(const s of n.tracks){const c=a.get(s.bone);if(!c){f.add(s.bone);continue}const m=ne(s.timeBase64),d=ne(s.valueBase64),h=`${c.uuid}.${s.property}`;i.push(s.property==="quaternion"?new Pa(h,Array.from(m),Array.from(d)):new Ea(h,Array.from(m),Array.from(d)))}if(f.size&&o.push(`${n.action} animates ${[...f].join(", ")}, which this binding has no bone for.`),!i.length)return;const u=n.duration??(n.clipEnd-n.clipStart)/n.fps,_=new Na(r),l=_.clipAction(new Ra(n.action??"action",u,i));l.setLoop(Ia,Number.POSITIVE_INFINITY),l.play(),this.#o=_,this.#a=l,this.#c(n.frameCurrent),this.#_()}#c(t){const n=this.#t;if(!n)return;const o=Math.min(n.frameEnd,Math.max(n.frameStart,t));if(this.#r=o,!this.#o||n.clipStart===void 0||n.clipEnd===void 0)return;const r=(n.clipEnd-n.clipStart)/n.fps;this.#o.setTime(Math.max(0,Math.min(r-1e-4,(o-n.clipStart)/n.fps))),this.#_()}#_(){for(const t of this.#n.values())t.boneRoot.updateMatrixWorld(!0),t.skeleton.update()}get scene(){return this.#t?.scene??null}async writeBookmark(){const t=Math.round(this.frame()),n=this.#t;if(!n)return t;const o=n.scene;return!o||n.frameCurrent===t||(this.#i++,await Ca(`bpy.data.scenes[${JSON.stringify(o)}]`,"frame_current",t,void 0,!1),this.#t={...n,frameCurrent:t},this.#f()),t}get transport(){return this.#e}attachTo(t){this.#s?.(),this.#e=t;const n=t.attach({id:this.#t?.action??"blender-action",label:this.#t?.action??"Action",range:()=>{const i=this.#t,f=i?.fps||24;return{start:(i?.frameStart??1)/f,end:(i?.frameEnd??250)/f,fps:f}},seek:i=>this.seekSeconds(i)}),o=t.onSettled(()=>{this.writeBookmark()}),r=()=>{o(),n(),this.#e===t&&(this.#e=null),this.#s=null};this.#s=r;const a=this.#t;return a&&a.fps>0&&t.seek(a.frameCurrent/a.fps),r}seekSeconds(t){const n=this.#t?.fps||24;this.#c(Math.round(t*n)),this.#f()}keyframes(){return(this.#t?.keyframes??[]).map(t=>t.frame)}dispose(){this.#s?.(),this.#o?.stopAllAction(),this.#o=null,this.#a=null,this.#t=null,this.#r=null;for(const t of this.#n.values())t.skeleton.dispose(),t.boneRoot.removeFromParent();this.#n.clear()}}const Yo=new Ps;function Ds(e){return Yo.subscribe(e)}function Cs(){return Yo.version}export{Yo as a,Cs as b,Fs as c,Ds as s};