@volter/game-editor 0.5.130 → 0.5.131

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 (296) 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 +2136 -2136
  5. package/dist/assets/{AssetBudgetPanel-qpkXbdeJ.js → AssetBudgetPanel-xh6RYB5z.js} +3 -3
  6. package/dist/assets/{AudioViewer-Diq9-n8F.js → AudioViewer-CGd4BxTl.js} +1 -1
  7. package/dist/assets/{CanvasBoardDocument-CBDQEyVH.js → CanvasBoardDocument-BuMpc0A-.js} +1 -1
  8. package/dist/assets/{CanvasSceneViewport-CoROtHru.js → CanvasSceneViewport-DMhu11L6.js} +1 -1
  9. package/dist/assets/{ColorInput-BibS1jDX.js → ColorInput-BRsj_y3k.js} +1 -1
  10. package/dist/assets/{ColorPicker-CjNV-7dt.js → ColorPicker-B6-MNUDk.js} +1 -1
  11. package/dist/assets/{EntityModelDocument-D_yh_bF3.js → EntityModelDocument-BPNraRWs.js} +1 -1
  12. package/dist/assets/{EnvironmentAssetDocument-C6oYSwMv.js → EnvironmentAssetDocument-rkElVVnV.js} +1 -1
  13. package/dist/assets/{GameplaySessionTimeline-BRSm8Se1.js → GameplaySessionTimeline-DBtAiEcP.js} +1 -1
  14. package/dist/assets/{ImageViewer-ni_DR2ux.js → ImageViewer-g2H7nQFG.js} +1 -1
  15. package/dist/assets/InspectorObjectPreview-D0fjTA2p.js +1 -0
  16. package/dist/assets/{JsonAssetDocument-BFpOv6Ri.js → JsonAssetDocument-DPxzhzE5.js} +1 -1
  17. package/dist/assets/{LiveModuleDocument-BBM_u142.js → LiveModuleDocument-dtJEsKe6.js} +1 -1
  18. package/dist/assets/{LutAssetDocument-DEm_pet8.js → LutAssetDocument-BdeqLBmd.js} +1 -1
  19. package/dist/assets/{ModelAssetDocument-CcJ0cdJN.js → ModelAssetDocument-DcmhvpMz.js} +1 -1
  20. package/dist/assets/{NonThreeAuthoringBootstrap-BI-2A7N2.js → NonThreeAuthoringBootstrap-DpCebDsm.js} +1 -1
  21. package/dist/assets/{Object3DDocumentToolbar-C64rqdsB.js → Object3DDocumentToolbar-3iQkN2n9.js} +1 -1
  22. package/dist/assets/Object3DDocumentViewport-B3uvK8Py.js +2 -0
  23. package/dist/assets/{Object3DPreview-CMaxxYtS.js → Object3DPreview-C7ZP4njx.js} +1 -1
  24. package/dist/assets/{OnlineAssetDetail-C0dCrrVt.js → OnlineAssetDetail-CwYCSC1S.js} +1 -1
  25. package/dist/assets/{PlayBar-B80scEvv.js → PlayBar-DQt9hxF8.js} +1 -1
  26. package/dist/assets/{QuarksAssetDocument-C3G0mGSZ.js → QuarksAssetDocument-B14F1jGm.js} +1 -1
  27. package/dist/assets/{ReactCanvasControls-abb1zGje.js → ReactCanvasControls-C2kGgPwR.js} +1 -1
  28. package/dist/assets/{RootSelectionOverlay-Bl6dBNQj.js → RootSelectionOverlay-yz6-YlXy.js} +1 -1
  29. package/dist/assets/{ShaderAssetDocument-BWHc9ibq.js → ShaderAssetDocument-CM2WthyM.js} +1 -1
  30. package/dist/assets/{ShadowEditor-B4LCKfSG.js → ShadowEditor-CLsIYscR.js} +1 -1
  31. package/dist/assets/{SourceAssetViewer-fVl0ydBm.js → SourceAssetViewer-CL378jDP.js} +1 -1
  32. package/dist/assets/{StageHost-B9vzNn1n.js → StageHost-DEb3AXsp.js} +2 -2
  33. package/dist/assets/{StoryPreviewMount-C_hNc2Ij.js → StoryPreviewMount-B0VNXCpC.js} +1 -1
  34. package/dist/assets/{ThreeBoardDocument-YogDDOIp.js → ThreeBoardDocument-BpDQyPmr.js} +2 -2
  35. package/dist/assets/{ThreeIsolationSceneContent-D-a3pLt7.js → ThreeIsolationSceneContent-DYnvlzc-.js} +1 -1
  36. package/dist/assets/{ToolObject3DPreview-D78iOtk5.js → ToolObject3DPreview-CvzAmxiI.js} +1 -1
  37. package/dist/assets/{Toolbar-BjG9vNYp.js → Toolbar-B8ter8wh.js} +1 -1
  38. package/dist/assets/{TransientHint-Cq50MQPL.js → TransientHint-CD8G5JQC.js} +1 -1
  39. package/dist/assets/{VideoViewer-DO_oytGm.js → VideoViewer-BFS_jlDX.js} +1 -1
  40. package/dist/assets/{ViewportShadingMenu-BHMlqkhF.js → ViewportShadingMenu-Cls3jchz.js} +1 -1
  41. package/dist/assets/{active-ingest-rcBACBHB.js → active-ingest-ZriS4I_t.js} +2 -2
  42. package/dist/assets/{animation-clock-Da3NGt-0.js → animation-clock-Brfm38Ur.js} +1 -1
  43. package/dist/assets/{animation-mixers.service-DxEKEOvF.js → animation-mixers.service-BuvR3YiA.js} +1 -1
  44. package/dist/assets/{animation-timeline.utility-fzyLKoSw.js → animation-timeline.utility-BQrDjQaJ.js} +1 -1
  45. package/dist/assets/{asset-budget-asset.menu-zQ4Geyg1.js → asset-budget-asset.menu-CIy2U9ES.js} +1 -1
  46. package/dist/assets/{asset-budget.action-eFkQrPAS.js → asset-budget.action-BfFcG_Pv.js} +1 -1
  47. package/dist/assets/{asset-budget.document-Ccfy3tCs.js → asset-budget.document-Lu6wPf4I.js} +1 -1
  48. package/dist/assets/{asset-budget.menu-jB4_X00E.js → asset-budget.menu-OxhgEttz.js} +1 -1
  49. package/dist/assets/{asset-editor-persistence-5ujpmT9M.js → asset-editor-persistence-B9ZLULJL.js} +1 -1
  50. package/dist/assets/{asset-loaders-BsFdZ-U4.js → asset-loaders-CjZyIn2t.js} +1 -1
  51. package/dist/assets/{asset-preview-agZh9kpZ.js → asset-preview-vNs8rQu7.js} +1 -1
  52. package/dist/assets/{audio-unlock.service-DYKj_NMi.js → audio-unlock.service-B31EGjEK.js} +1 -1
  53. package/dist/assets/{audio.utility-DEEsSpaF.js → audio.utility-CXnYeJsI.js} +1 -1
  54. package/dist/assets/autoplay.service-xWlK0aqA.js +1 -0
  55. package/dist/assets/{babylon-authoring-adapter-aQi2udfG.js → babylon-authoring-adapter-DnkMqiIH.js} +1 -1
  56. package/dist/assets/{binding-resolver-Cri8YpQo.js → binding-resolver-Ox60gB2F.js} +2 -2
  57. package/dist/assets/{blender-node-editor.document-BILuLRoc.js → blender-node-editor.document-Nc1C1NOM.js} +1 -1
  58. package/dist/assets/{blender-properties-tab-jDIlTzUD.js → blender-properties-tab-YjJu6VN1.js} +1 -1
  59. package/dist/assets/blender-runtime-host-D52Z7WD1.js +7 -0
  60. package/dist/assets/{blender-runtime-skin-Ddxh2pae.js → blender-runtime-skin-Dp1EUYXH.js} +33 -33
  61. package/dist/assets/{blender-runtime.document-D2iaxi5d.js → blender-runtime.document-BeVkeGjy.js} +1 -1
  62. package/dist/assets/{blender-screenshot.menu-u9N-Zr7D.js → blender-screenshot.menu-C0-noWRV.js} +1 -1
  63. package/dist/assets/{blender-timeline.document-BbVO_s4M.js → blender-timeline.document-DaFb7ktE.js} +1 -1
  64. package/dist/assets/{blender-uv-editor.document-C8PGmvv1.js → blender-uv-editor.document-CPndwhaM.js} +1 -1
  65. package/dist/assets/{blender-version.status-B3y-afep.js → blender-version.status-CAoqefhE.js} +1 -1
  66. package/dist/assets/blender.command-wi-NF5xl.js +1 -0
  67. package/dist/assets/{board-guides-BUF6uS04.js → board-guides-CKUsHmXR.js} +1 -1
  68. package/dist/assets/{bridge.command-UFUOG3Tw.js → bridge.command-D_NM2Q0z.js} +3 -3
  69. package/dist/assets/{browserAll-Dk8jnjcz.js → browserAll-BHRzZ7xo.js} +1 -1
  70. package/dist/assets/{build-player.document-DsrMMUJY.js → build-player.document-DA8AYORo.js} +1 -1
  71. package/dist/assets/{build-profiles.document-B8CHMTfM.js → build-profiles.document-D5Rr_aiV.js} +1 -1
  72. package/dist/assets/{build-progress.status-BhNf_U67.js → build-progress.status-Dnow0Q18.js} +1 -1
  73. package/dist/assets/{build-session-B8DvP_BQ.js → build-session-BaS8m6z_.js} +1 -1
  74. package/dist/assets/{build.action-DYur0Wge.js → build.action-CQFo7UVP.js} +1 -1
  75. package/dist/assets/{build.command-FuDA5B6W.js → build.command-DoLbJQKk.js} +1 -1
  76. package/dist/assets/{build.header-DVZMW019.js → build.header-C85_8qIX.js} +1 -1
  77. package/dist/assets/{build.menu-CoxrvW_I.js → build.menu-B7R2-w0i.js} +1 -1
  78. package/dist/assets/{build.service-CHKzqCRC.js → build.service-gi06EZaN.js} +1 -1
  79. package/dist/assets/{camera-Cv9S-xWW.js → camera-DIOsZ5V4.js} +1 -1
  80. package/dist/assets/{camera-runtime.inspector-D1DkFeuo.js → camera-runtime.inspector-BjE2fAo3.js} +1 -1
  81. package/dist/assets/{canvas-design-mount-CKKc-YGA.js → canvas-design-mount-DxATml9D.js} +3 -3
  82. package/dist/assets/{canvas-entry-runtime-C2kFpUqh.js → canvas-entry-runtime-F_qiHxZA.js} +2 -2
  83. package/dist/assets/{canvas-preview-frames-BDmAulpd.js → canvas-preview-frames-D3X5XV18.js} +1 -1
  84. package/dist/assets/{canvas-story-capture.service-fMRSHzJi.js → canvas-story-capture.service-DX04l_Qz.js} +2 -2
  85. package/dist/assets/{capability-coverage-BAQeb1sR.js → capability-coverage-D7oFXsIG.js} +1 -1
  86. package/dist/assets/{collaboration-presence-CignJxHj.js → collaboration-presence-CNRCnlr0.js} +1 -1
  87. package/dist/assets/{collider-DxPzwFDz.js → collider-QUcqLUgt.js} +1 -1
  88. package/dist/assets/{component-board.service-DxUhkQVs.js → component-board.service-CGHWEUtH.js} +2 -2
  89. package/dist/assets/{component-board.service-7TS6vRxH.js → component-board.service-Co_RPB76.js} +2 -2
  90. package/dist/assets/{component-board.service-D4U4JVVU.js → component-board.service-Df1ef2HX.js} +2 -2
  91. package/dist/assets/{component-contracts.service-UxbsTME6.js → component-contracts.service-DTW5qurI.js} +1 -1
  92. package/dist/assets/{component-instance-root-CL5qzF6u.js → component-instance-root-mnaUEFAg.js} +1 -1
  93. package/dist/assets/{component-verbs.command-DgnKZO4N.js → component-verbs.command-q9IdgQWj.js} +1 -1
  94. package/dist/assets/{component-verbs.service-D3kg65sr.js → component-verbs.service-Dnes6VyR.js} +1 -1
  95. package/dist/assets/{config-Cn372ZzU.js → config-BN4Lmq46.js} +2 -2
  96. package/dist/assets/{configurations-CTWBhTUf.js → configurations-DY2IiXpV.js} +1 -1
  97. package/dist/assets/{connection.status-wwxZQEAF.js → connection.status-D7I2dgv0.js} +1 -1
  98. package/dist/assets/{constraints.inspector-Di21JmyY.js → constraints.inspector-DAUjo3AH.js} +1 -1
  99. package/dist/assets/{content-bounds-wsarq3YV.js → content-bounds-D4k7pAaW.js} +1 -1
  100. package/dist/assets/{contract-system-adapters-B9apGOMQ.js → contract-system-adapters-BprRTe1B.js} +1 -1
  101. package/dist/assets/{coverage.service-_67ez0oy.js → coverage.service-BpYDL-1r.js} +1 -1
  102. package/dist/assets/{create-runtime-BbrWG3Dj.js → create-runtime-BGvJJko5.js} +1 -1
  103. package/dist/assets/{curve-DrdLYZPA.js → curve-VlX4I35S.js} +1 -1
  104. package/dist/assets/{data-asset-cZrqcPJc.js → data-asset-Dhn0-GTH.js} +1 -1
  105. package/dist/assets/{data-ref-XaI-aDOy.js → data-ref-VzHXG1c6.js} +1 -1
  106. package/dist/assets/{debug-bridge-CMNdajyG.js → debug-bridge-Z2gRt8Zc.js} +1 -1
  107. package/dist/assets/{debug-registry-DpJjXPu6.js → debug-registry-BkyhbW5o.js} +1 -1
  108. package/dist/assets/{deferred-ingest-play-B8zw5TXo.js → deferred-ingest-play-DaWGKxqL.js} +2 -2
  109. package/dist/assets/{design-time-canvas-mount-BWzhB7m2.js → design-time-canvas-mount--OqF2WkK.js} +2 -2
  110. package/dist/assets/{design-time-layers-MmuAEkk7.js → design-time-layers-ClmhMEAZ.js} +1 -1
  111. package/dist/assets/{design-time-mount.service-B6lQd1pk.js → design-time-mount.service-Dfu_ei5E.js} +2 -2
  112. package/dist/assets/{design-time-mount.service-DO5qbjP2.js → design-time-mount.service-HNdgYB2u.js} +2 -2
  113. package/dist/assets/{design-time-react-mount-Cco4ZPxC.js → design-time-react-mount-CE9REYmk.js} +1 -1
  114. package/dist/assets/{document-preview-three-6-rt0s3D.js → document-preview-three-BjLceB54.js} +1 -1
  115. package/dist/assets/{dom-authoring-adapter-DJME07nM.js → dom-authoring-adapter-2DC91mxf.js} +1 -1
  116. package/dist/assets/{draco3d-CxbStChw.js → draco3d-DIIaAJ6n.js} +1 -1
  117. package/dist/assets/{edit-mode-audio.service-Ct7Ldnuk.js → edit-mode-audio.service-2vi4I17L.js} +1 -1
  118. package/dist/assets/{edit-mode-authoring-D-2Ik7C9.js → edit-mode-authoring-BPsFGjzM.js} +1 -1
  119. package/dist/assets/{edit-mode-networking.service-BjDXGMHA.js → edit-mode-networking.service-Xz4iej7J.js} +1 -1
  120. package/dist/assets/{editor-api-DqL1Yaly.js → editor-api-BxHqt4Xt.js} +1 -1
  121. package/dist/assets/{editor-layers-DVuMw5f5.js → editor-layers-DmUg5T3_.js} +1 -1
  122. package/dist/assets/{editor-shell-store-CNt2zW0E.js → editor-shell-store-DPpSNDy1.js} +1 -1
  123. package/dist/assets/{entity-object-B_x2FCUW.js → entity-object-D_Xp6Gb3.js} +1 -1
  124. package/dist/assets/{extend-DM6br_Di.js → extend-hvT5slS9.js} +1 -1
  125. package/dist/assets/{fork-menu-Bl2ZuYie.js → fork-menu-DguGrW0h.js} +1 -1
  126. package/dist/assets/{frame-debugger-store-DYLys9S-.js → frame-debugger-store-DFC83QOT.js} +1 -1
  127. package/dist/assets/{game-contract-seams-B-7gb13c.js → game-contract-seams-gtbmw2C5.js} +1 -1
  128. package/dist/assets/{game-css-scope-transform-CNsIQ45a.js → game-css-scope-transform-D8WuwFPz.js} +1 -1
  129. package/dist/assets/{game-document.service-DQfrwN2I.js → game-document.service-15rgKKaG.js} +1 -1
  130. package/dist/assets/{game-eval.command-BqS_SLDG.js → game-eval.command-yJBOJP3U.js} +1 -1
  131. package/dist/assets/{game-module-access-Dr_jlctk.js → game-module-access-Ce87kvq0.js} +1 -1
  132. package/dist/assets/{game-network-CAMgSePs.js → game-network-JCyWQ_Z7.js} +3 -3
  133. package/dist/assets/{gameplay-export-CkUZ90s2.js → gameplay-export-CRgCGRmp.js} +1 -1
  134. package/dist/assets/{gameplay-replay-D9vOE3M2.js → gameplay-replay-BDCki9XM.js} +1 -1
  135. package/dist/assets/{gameplay.command-BdwYqSMB.js → gameplay.command-DGkj6-7b.js} +1 -1
  136. package/dist/assets/{generation-jobs-CDn7Ao6l.js → generation-jobs-CeDZdMpJ.js} +1 -1
  137. package/dist/assets/{generation.service-C8JvO6Ll.js → generation.service-CcyUj9tv.js} +1 -1
  138. package/dist/assets/{generations-BON32S2-.js → generations-DXSmdpTV.js} +1 -1
  139. package/dist/assets/{generations.status-mal_FOwh.js → generations.status-DnZmkvkf.js} +1 -1
  140. package/dist/assets/{hierarchy-marks-DDtpJ7PB.js → hierarchy-marks-D2716vL4.js} +1 -1
  141. package/dist/assets/{hosted-asset-materialization-DfkPbrUm.js → hosted-asset-materialization-CPAT5jBN.js} +1 -1
  142. package/dist/assets/{index-BXWC4w5R.js → index-BcKb2YwA.js} +2 -2
  143. package/dist/assets/{index-ihc3rASN.js → index-BdTSTs-f.js} +1 -1
  144. package/dist/assets/{index-SbBinYIF.js → index-BwKzWHt8.js} +1 -1
  145. package/dist/assets/{index-Y_P7AYV1.js → index-C67kVNvR.js} +1 -1
  146. package/dist/assets/{index-DK92FabE.js → index-CJaJOM8e.js} +1 -1
  147. package/dist/assets/{index-BszEW86b.js → index-Cl0YIFAW.js} +1 -1
  148. package/dist/assets/{index-DmNeCiAo.js → index-D-G1ZsCu.js} +7 -7
  149. package/dist/assets/{index-DAwnllXr.js → index-DhjCepUi.js} +1 -1
  150. package/dist/assets/{index-DNf8O3O1.js → index-yqhgogAt.js} +1 -1
  151. package/dist/assets/{inference-diagnostics-BCK7lzd-.js → inference-diagnostics-zGUPGK9h.js} +1 -1
  152. package/dist/assets/{ingest-boot-viewport-BSLuPz4r.js → ingest-boot-viewport-DIg0c-U7.js} +1 -1
  153. package/dist/assets/{ingest-siblings-CE2dKDAS.js → ingest-siblings-CGrE4H95.js} +1 -1
  154. package/dist/assets/{ingest-source-persistence-DXXd6X4G.js → ingest-source-persistence-BQO1KGrh.js} +1 -1
  155. package/dist/assets/{ingest.service-QPs7WiGX.js → ingest.service-BnFMUzdM.js} +1 -1
  156. package/dist/assets/{inspect-DA_mHIRo.js → inspect-DH57N9OW.js} +1 -1
  157. package/dist/assets/instances.command-RcLpbQDx.js +1 -0
  158. package/dist/assets/{json-history-resource-CZUrVLZF.js → json-history-resource-CqxeO7Gw.js} +1 -1
  159. package/dist/assets/{layered-pick-D-zS343_.js → layered-pick-DcU2SccC.js} +1 -1
  160. package/dist/assets/{light-BbgMtsRn.js → light-wrMW5sx4.js} +1 -1
  161. package/dist/assets/{live-project-verbs-CUKegag9.js → live-project-verbs-tgkB8w44.js} +1 -1
  162. package/dist/assets/{machine.document-DvN6BWU1.js → machine.document-Bb0luUXi.js} +1 -1
  163. package/dist/assets/{machines.finder-DT0HVk3x.js → machines.finder-DYtkwdqr.js} +1 -1
  164. package/dist/assets/{material-BnXxYmBZ.js → material-BXufoiSx.js} +1 -1
  165. package/dist/assets/{material-factory-D6TA-Ubu.js → material-factory-IKt-e70d.js} +1 -1
  166. package/dist/assets/{mesh-Cutx-5di.js → mesh-DADcxLdw.js} +1 -1
  167. package/dist/assets/{model-asset-sections.service-BRu2seCr.js → model-asset-sections.service-DZSSiLGM.js} +1 -1
  168. package/dist/assets/{model-inspection-BUTTeTpS.js → model-inspection-C2s3OYXl.js} +1 -1
  169. package/dist/assets/{model-thumbnail-BtcSrAMa.js → model-thumbnail-D5o-4B01.js} +1 -1
  170. package/dist/assets/{models.finder-SXNTijTt.js → models.finder-B95VsZ65.js} +1 -1
  171. package/dist/assets/{module-mode-Cnao3XAv.js → module-mode-CxLLk1w7.js} +2 -2
  172. package/dist/assets/{mount-canvas-ingest-root-BSPwlKi0.js → mount-canvas-ingest-root-CcURJlfy.js} +2 -2
  173. package/dist/assets/{mount-dom-ingest-root-Bju1wKWY.js → mount-dom-ingest-root-vFLT2G7J.js} +2 -2
  174. package/dist/assets/{mount-ingest-root-Cfb_hJuM.js → mount-ingest-root-BXXdHb3k.js} +2 -2
  175. package/dist/assets/{mount-manifest-C9v48bKT.js → mount-manifest-CFPSbrdR.js} +1 -1
  176. package/dist/assets/{mount-three-ingest-root-DV2IXb3k.js → mount-three-ingest-root-C7EvPLpq.js} +1 -1
  177. package/dist/assets/{mounted-authoring-xyBh_twE.js → mounted-authoring-JufMUAA7.js} +1 -1
  178. package/dist/assets/{mounted-story-viewport-source-hP2r14tz.js → mounted-story-viewport-source-CuAqEjCt.js} +1 -1
  179. package/dist/assets/{native-debug-module-a57esQxg.js → native-debug-module-D0JJ27BY.js} +1 -1
  180. package/dist/assets/{navigation-XoA70Bj5.js → navigation-D-RA7j4R.js} +1 -1
  181. package/dist/assets/{navmesh.menu-DYnmqbCJ.js → navmesh.menu-XArlggki.js} +1 -1
  182. package/dist/assets/{navmesh.service-BzHkiDfO.js → navmesh.service-CEqTZDij.js} +1 -1
  183. package/dist/assets/network-observer.service-D8qesWFc.js +1 -0
  184. package/dist/assets/{network.utility-DdSrG_G1.js → network.utility-HDe8PnKF.js} +1 -1
  185. package/dist/assets/{object3d-document-session-registry-jcgiK59f.js → object3d-document-session-registry-D704QLST.js} +2 -2
  186. package/dist/assets/{oid-transform--cph2k55.js → oid-transform-DnXrIY9C.js} +1 -1
  187. package/dist/assets/{particles-J5SjiKkG.js → particles-BFZUclym.js} +1 -1
  188. package/dist/assets/{pixi-authoring-adapter-BG8416OJ.js → pixi-authoring-adapter-Ben-hgbd.js} +1 -1
  189. package/dist/assets/{pixi-live-write-target-Ck9xhI_J.js → pixi-live-write-target-tWUq0M3X.js} +1 -1
  190. package/dist/assets/{play.command-C9QrjBqH.js → play.command-D2SoCCf3.js} +2 -2
  191. package/dist/assets/{presentation-CMWW6oC4.js → presentation-CZFcFjRY.js} +1 -1
  192. package/dist/assets/{product-CtuevsUE.js → product-CEzZzRzZ.js} +1 -1
  193. package/dist/assets/{profiler.action-CKL52CX8.js → profiler.action-DYnp-dIl.js} +1 -1
  194. package/dist/assets/{profiler.menu-Bx7sdJpH.js → profiler.menu-CB7AUXAU.js} +1 -1
  195. package/dist/assets/{profiler.utility-B9jMd0tG.js → profiler.utility-CPFc55To.js} +1 -1
  196. package/dist/assets/{project-authoring-session-Pa9mXNuZ.js → project-authoring-session-DrT2qJF0.js} +2 -2
  197. package/dist/assets/{properties-bone-constraints.inspector-b8cTlTwC.js → properties-bone-constraints.inspector-CfRTvy5p.js} +1 -1
  198. package/dist/assets/{properties-bone.inspector-BnLBufG0.js → properties-bone.inspector-54MKrR72.js} +1 -1
  199. package/dist/assets/{properties-collection.inspector-DBNlp_6i.js → properties-collection.inspector-O6LuSXOQ.js} +1 -1
  200. package/dist/assets/{properties-constraints.inspector-NloiUa9x.js → properties-constraints.inspector-DffyXZKu.js} +1 -1
  201. package/dist/assets/{properties-data.inspector-C59o5Llj.js → properties-data.inspector-DXaxMz2Y.js} +1 -1
  202. package/dist/assets/{properties-material.inspector-p8mh6kCW.js → properties-material.inspector-Cho8xdBI.js} +1 -1
  203. package/dist/assets/{properties-modifiers.inspector-fcqS8WO7.js → properties-modifiers.inspector-CpbbR4Om.js} +1 -1
  204. package/dist/assets/{properties-object.inspector-lil6UPt8.js → properties-object.inspector-4h6NxwoN.js} +1 -1
  205. package/dist/assets/{properties-output.inspector-DsF-nKdF.js → properties-output.inspector-DTRZDajI.js} +1 -1
  206. package/dist/assets/{properties-particles.inspector-q2Di84s0.js → properties-particles.inspector-BHMjkBKc.js} +1 -1
  207. package/dist/assets/{properties-physics.inspector-CNclwGwq.js → properties-physics.inspector-ghuF-m6r.js} +1 -1
  208. package/dist/assets/{properties-render.inspector-B9ZUvK6B.js → properties-render.inspector-Dfn5HEKA.js} +1 -1
  209. package/dist/assets/{properties-scene.inspector-cJWNTiko.js → properties-scene.inspector-CwBfzPo2.js} +1 -1
  210. package/dist/assets/{properties-texture.inspector-CWCdZSdQ.js → properties-texture.inspector-BMthDuQl.js} +1 -1
  211. package/dist/assets/{properties-view-layer.inspector-BHD2twq2.js → properties-view-layer.inspector-Chf8fDV5.js} +1 -1
  212. package/dist/assets/{properties-world.inspector-CMlj3XLq.js → properties-world.inspector-CBayv6ge.js} +1 -1
  213. package/dist/assets/{r3f-design-session-BeAS5PQl.js → r3f-design-session-CDJXwu2Y.js} +2 -2
  214. package/dist/assets/{r3f-physics-binding-t3rKYjMV.js → r3f-physics-binding-1iL3sKy9.js} +1 -1
  215. package/dist/assets/{r3f-source-authoring-adapter-sFxW7pRe.js → r3f-source-authoring-adapter-CLuLuxlA.js} +1 -1
  216. package/dist/assets/{react-canvas-navigation-D2r0gF5Q.js → react-canvas-navigation-CcSJcL6p.js} +1 -1
  217. package/dist/assets/{react-inspector.service-C1XIPYH0.js → react-inspector.service-XcygzXLc.js} +1 -1
  218. package/dist/assets/{react-story-board-2WEWRKNQ.js → react-story-board-CDFp2Cct.js} +1 -1
  219. package/dist/assets/{react-three-rapier.esm-B2uhShq_.js → react-three-rapier.esm-CxC2iZi1.js} +1 -1
  220. package/dist/assets/{react-world-authoring-adapter-BLNUCSeK.js → react-world-authoring-adapter-DEywdLYs.js} +1 -1
  221. package/dist/assets/{realm-services-CcfZc_W9.js → realm-services-beTbtAPk.js} +1 -1
  222. package/dist/assets/{reflection-probe-capture.inspector-BEGRAIcz.js → reflection-probe-capture.inspector-CT9GR2Qo.js} +1 -1
  223. package/dist/assets/{registry-C_pAsb1l.js → registry-vCBeP859.js} +1 -1
  224. package/dist/assets/{relative-import-specifier-D1iFwXli.js → relative-import-specifier-Bjlxchbq.js} +1 -1
  225. package/dist/assets/{render-env-CbXpOb9g.js → render-env-DayDp_Zd.js} +1 -1
  226. package/dist/assets/{render-features-DpJX9WCp.js → render-features-DBROmwn2.js} +1 -1
  227. package/dist/assets/{render-settings-DYlzijyk.js → render-settings-B0XqOFGb.js} +1 -1
  228. package/dist/assets/{resolve-three-Bp7EZT4O.js → resolve-three-DnH-tIDh.js} +3 -3
  229. package/dist/assets/{root-seam-contract-Cvxfcfmv.js → root-seam-contract-DLYN34u3.js} +1 -1
  230. package/dist/assets/{run-selection-BDbgDokC.js → run-selection-Dx1BGfLg.js} +1 -1
  231. package/dist/assets/{scene-capture-CGCpkmz_.js → scene-capture-1PoVj5hA.js} +1 -1
  232. package/dist/assets/{scene-document.service-BTOhPREd.js → scene-document.service-65WoShrF.js} +2 -2
  233. package/dist/assets/{scene-framing-B4Ynn1mk.js → scene-framing-4WatuvlF.js} +1 -1
  234. package/dist/assets/{seeded-random-wICYLJg6.js → seeded-random-fLlojV69.js} +1 -1
  235. package/dist/assets/{setup-renderer-BjhvKXG4.js → setup-renderer-so5gtgSO.js} +1 -1
  236. package/dist/assets/{source-object3d-authoring-adapter-CIEoS6Tj.js → source-object3d-authoring-adapter-ChS2o1Xx.js} +1 -1
  237. package/dist/assets/{source-persistence-backend-jB_B_qgt.js → source-persistence-backend-CkyQpGrG.js} +1 -1
  238. package/dist/assets/{stage-keyboard-3K38-Hw6.js → stage-keyboard-CU4X2l3G.js} +1 -1
  239. package/dist/assets/{stage-overlay-set-i7XlbOA8.js → stage-overlay-set-ODG73EVe.js} +1 -1
  240. package/dist/assets/{stage-presence-markers-CJ49-XME.js → stage-presence-markers-C9wbwDQm.js} +1 -1
  241. package/dist/assets/{stage-transform-tools-Bf_p8cJg.js → stage-transform-tools-fEMi3oOg.js} +1 -1
  242. package/dist/assets/{standard-viewport-dressing-8SWhTXK3.js → standard-viewport-dressing-Dk02sQp6.js} +1 -1
  243. package/dist/assets/{state-watch.action-DCsgcteq.js → state-watch.action-BjK2g-lO.js} +1 -1
  244. package/dist/assets/{state-watch.menu-BK7FGgVR.js → state-watch.menu-C_QVBV0s.js} +1 -1
  245. package/dist/assets/{state-watch.utility-B37tKCea.js → state-watch.utility-C7fzB-_q.js} +1 -1
  246. package/dist/assets/{story-capture-OjR2l-KU.js → story-capture-BnEt16UU.js} +1 -1
  247. package/dist/assets/{story-documents-Cwlnx5Xe.js → story-documents-B2G2lPjd.js} +1 -1
  248. package/dist/assets/{story-documents.service-DHuiVSJw.js → story-documents.service-8P8kl4Ql.js} +1 -1
  249. package/dist/assets/{story-documents.service-vNaYun8n.js → story-documents.service-DQFxdJmm.js} +1 -1
  250. package/dist/assets/{story-media-presence-629BeHAI.js → story-media-presence-kmZ-iwzZ.js} +1 -1
  251. package/dist/assets/{story-pixi-preview-B1mcJckV.js → story-pixi-preview-CtR3hhsS.js} +1 -1
  252. package/dist/assets/{story-presentation-Cv7oyJg2.js → story-presentation-BAVcRFqV.js} +1 -1
  253. package/dist/assets/{story-three-preview-CsLEpAYI.js → story-three-preview-D_gLQCac.js} +2 -2
  254. package/dist/assets/{studio-environment-DsQ4K1L8.js → studio-environment-WsKE4UBz.js} +1 -1
  255. package/dist/assets/{surface-state-DUClAKxh.js → surface-state-ByLry0WZ.js} +1 -1
  256. package/dist/assets/{syntactic-prop-specs-Bf8S-Hpl.js → syntactic-prop-specs-CwYOcdaw.js} +1 -1
  257. package/dist/assets/{team-playtest.service-8sDrJf5C.js → team-playtest.service-4LEw3aP4.js} +1 -1
  258. package/dist/assets/{three-Cgvnp1Nn.js → three-7K4VDgM2.js} +1 -1
  259. package/dist/assets/{three-authoring-adapter-DZ8eqcFP.js → three-authoring-adapter-C0tYXQIE.js} +1 -1
  260. package/dist/assets/three-authoring.service-BEtgEHMU.js +2 -0
  261. package/dist/assets/{three-ingest-runtime-CYWRwidS.js → three-ingest-runtime-DxkUEyMI.js} +1 -1
  262. package/dist/assets/{three-integration-DSN-gO72.js → three-integration-D9IUaLET.js} +2 -2
  263. package/dist/assets/three-integration.service-B-qYVbhZ.js +1 -0
  264. package/dist/assets/{three-projection-core-CSr5hmWB.js → three-projection-core-B2MqU5b7.js} +1 -1
  265. package/dist/assets/{three-state-BIe7PFbc.js → three-state-B8zvveUf.js} +1 -1
  266. package/dist/assets/{three-story-capture.service-gGvamise.js → three-story-capture.service-WoTH2p9_.js} +2 -2
  267. package/dist/assets/{three-story-model-CgIBLb2f.js → three-story-model-5YWSi42m.js} +1 -1
  268. package/dist/assets/{three-viewport-presentation-CEu9ox1U.js → three-viewport-presentation-BGKjVpHe.js} +1 -1
  269. package/dist/assets/{transform-mode-request-8EAetSXS.js → transform-mode-request-C58tmPGV.js} +1 -1
  270. package/dist/assets/{transport-strip-anvfvigR.js → transport-strip-B12CdJs_.js} +1 -1
  271. package/dist/assets/transport.header-CAZGRLxQ.js +1 -0
  272. package/dist/assets/{tuples-BOY_uUhw.js → tuples-fjpPndGz.js} +1 -1
  273. package/dist/assets/{ui-board-document-Bgdx8jTV.js → ui-board-document-CJbv1DAz.js} +2 -2
  274. package/dist/assets/{user-data-DvKLhMGu.js → user-data-DsFa4aua.js} +1 -1
  275. package/dist/assets/{utility-view-state-DHpqflFO.js → utility-view-state-DyaFLM90.js} +1 -1
  276. package/dist/assets/{viewport-door-CVX7GCz1.js → viewport-door-BMMTgy0S.js} +1 -1
  277. package/dist/assets/{viewport-root-presentation-m2H6uV6U.js → viewport-root-presentation-D9R2VFTh.js} +1 -1
  278. package/dist/assets/{viewport-surface-status-DKyxV0Lz.js → viewport-surface-status-D-2SRXNb.js} +1 -1
  279. package/dist/assets/{webworkerAll-B7PoBHDQ.js → webworkerAll-B7uFCDja.js} +1 -1
  280. package/dist/assets/{workspace-arrangement-Dinn7b-i.js → workspace-arrangement-CRcz3K9e.js} +1 -1
  281. package/dist/assets/{world-documents-BL7VdFaK.js → world-documents-B4omJ1Jx.js} +1 -1
  282. package/dist/assets/{world-root-stage-binding-DXzosgL9.js → world-root-stage-binding-KrsZeZnq.js} +1 -1
  283. package/dist/assets/{xstate-animation-binding-BAPmVeqO.js → xstate-animation-binding-DvxI3pM9.js} +1 -1
  284. package/dist/assets/{xstate-animation-meta-RUH2Lum3.js → xstate-animation-meta-IEXUsrpt.js} +1 -1
  285. package/dist-node/cli.js +16 -16
  286. package/package.json +16 -16
  287. package/dist/assets/InspectorObjectPreview-5l23L20j.js +0 -1
  288. package/dist/assets/Object3DDocumentViewport-ClruThDB.js +0 -2
  289. package/dist/assets/autoplay.service-CKlnZKMd.js +0 -1
  290. package/dist/assets/blender-runtime-host-C9hWsbh6.js +0 -7
  291. package/dist/assets/blender.command-C-n6jjz6.js +0 -1
  292. package/dist/assets/instances.command-C-vOAn13.js +0 -1
  293. package/dist/assets/network-observer.service-C75jUX8T.js +0 -1
  294. package/dist/assets/three-authoring.service-FA9fRV2t.js +0 -2
  295. package/dist/assets/three-integration.service--eR0_MqR.js +0 -1
  296. package/dist/assets/transport.header-CpOG4bUd.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 ae,b as re,L as ie}from"./LineSegments2-DN9pUfWA.js";import{bh as it,cl as se,fo as x,cm as q,N as vn,a$ as Mt,em as mo,b4 as We,co as Rt,ey as He,cp as Nn,_ as wt,ej as $t,fd as Gt,er as qe,M as dt,cj as xt,dp as At,aV as Ge,cW as le,aE as fe,c7 as vt,j as Xe,f6 as Ye,fp as Cn,au as kn,dw as $n,bi as ho,aT as Ze,c1 as Xt,dd as Jn,eC as to,e7 as Mn,aw as cn,da as Bt,I as hn,as as Qe,e8 as Ke,b0 as ce,K as Je,B as ta,b9 as na,Y as ue,cw as nn,ed as oa,cA as ea,fx as aa,db as _e,el as ra,R as ia,e6 as sa,c0 as me,bX as la,aI as no,ao as fa,eG as ca,d3 as ua,cs as _a,bu as de,aM as he,b5 as pe,ex as ve,cO as Rn,cY as ma,eU as da,cE as oo,c5 as ge,at as ha,ff as pa,eW as va,f7 as ga,F as xa,ev as ba,et as ya,dq as wa,fq as Oa,n as Aa,l as Ta,cf as Sa}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 Ma,mB as xe,d_ as Lt,x as W,kE as bt,e1 as be,mC as U,dZ as Pa,mD as Ea}from"./index-DmNeCiAo.js";import{S as Ut}from"./three.module-BLhyNg0e.js";import{t as Na}from"./blender-runtime-host-C9hWsbh6.js";const eo=new Set;function Ot(){for(const o of[...eo])o()}function Ra(o){return eo.add(o),()=>{eo.delete(o)}}function ao(o){const t=atob(o),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}const en=N().finite(),Ia=M({name:R(),parent:R().nullable(),connected:Q(),hide:Q(),length:en,matrix:D(L([en,en,en,en])).length(4),select:Q(),active:Q(),lockedWeight:Q()}).strict(),za=M({object:R(),displayType:H(["OCTAHEDRAL","STICK","BBONE","ENVELOPE","WIRE"]),showInFront:Q(),mode:R(),bones:D(Ia)}).strict(),St={solid:11711154,pose:5294335,poseActive:9240575,poseActiveUnsel:794150,wire:0,vertex:0,lockedWeight:16711680,lockedWeightFactor:128/255};function Fa(o){return new wt(o.r*o.r*.1,o.g*o.g*.1,o.b*o.b*.1)}const Vn=[[0,0,0],[.1,.1,.1],[.1,.1,-.1],[-.1,.1,-.1],[-.1,.1,.1],[0,1,0]],So=[[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,Da=[[It,-It,0],[0,-It,-It],[-It,-It,0],[0,-It,It],[.99388373,.11043154,0],[0,.11043154,-.99388373],[-.99388373,.11043154,0],[0,.11043154,.99388373]],Ca=[[0,1],[1,5],[5,3],[3,0],[0,4],[4,5],[5,2],[2,0],[1,2],[2,3],[3,4],[4,1]],ka=.05;function Mo(o){return o.select||o.active?2:1}const $a=10,La=4,Va=`
2
+ import{a as se,b as ie,L as le}from"./LineSegments2-DN9pUfWA.js";import{bh as st,cl as fe,fo as x,cm as H,N as gn,a$ as Mt,em as mo,b4 as He,co as Rt,ey as qe,cp as Rn,_ as Ot,ej as $t,fd as Gt,er as Ge,M as dt,cj as xt,dp as At,aV as Xe,cW as ce,aE as ue,c7 as vt,j as Ye,f6 as Ze,fp as Cn,au as kn,dw as $n,bi as ho,aT as Qe,c1 as Xt,dd as Jn,eC as to,e7 as Pn,aw as cn,da as Bt,I as pn,as as Ke,e8 as Je,b0 as _e,K as ta,B as na,b9 as oa,Y as me,cw as nn,ed as ea,cA as aa,fx as ra,db as de,el as sa,R as ia,e6 as la,c0 as he,bX as fa,aI as no,ao as ca,eG as ua,d3 as _a,cs as ma,b5 as po,bu as pe,aM as ve,ex as ge,cO as In,cY as da,eU as ha,cE as oo,c5 as xe,at as pa,ff as va,eW as ga,f7 as xa,F as ba,ev as ya,et as wa,dq as Oa,fq as Aa,n as Ta,l as Sa,cf as Ma}from"./three.core-3arARmh6.js";import{u as M,v as F,w as R,c5 as Q,c4 as q,c6 as N,e2 as L,_ as Pa,mB as be,d_ as Lt,x as W,kE as bt,e1 as ye,mC as U,dZ as Ea,mD as Na}from"./index-D-G1ZsCu.js";import{S as Ut}from"./three.module-BLhyNg0e.js";import{t as Ra}from"./blender-runtime-host-D52Z7WD1.js";const eo=new Set;function wt(){for(const o of[...eo])o()}function Ia(o){return eo.add(o),()=>{eo.delete(o)}}function ao(o){const t=atob(o),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}const en=N().finite(),za=M({name:R(),parent:R().nullable(),connected:Q(),hide:Q(),length:en,matrix:F(L([en,en,en,en])).length(4),select:Q(),active:Q(),lockedWeight:Q()}).strict(),Da=M({object:R(),displayType:q(["OCTAHEDRAL","STICK","BBONE","ENVELOPE","WIRE"]),showInFront:Q(),mode:R(),bones:F(za)}).strict(),St={solid:11711154,pose:5294335,poseActive:9240575,poseActiveUnsel:794150,wire:0,vertex:0,lockedWeight:16711680,lockedWeightFactor:128/255};function Fa(o){return new Ot(o.r*o.r*.1,o.g*o.g*.1,o.b*o.b*.1)}const Vn=[[0,0,0],[.1,.1,.1],[.1,.1,-.1],[-.1,.1,-.1],[-.1,.1,.1],[0,1,0]],Mo=[[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,Ca=[[It,-It,0],[0,-It,-It],[-It,-It,0],[0,-It,It],[.99388373,.11043154,0],[0,.11043154,-.99388373],[-.99388373,.11043154,0],[0,.11043154,.99388373]],ka=[[0,1],[1,5],[5,3],[3,0],[0,4],[4,5],[5,2],[2,0],[1,2],[2,3],[3,4],[4,1]],$a=.05;function Po(o){return o.select||o.active?2:1}const La=10,Va=4,ja=`
3
3
  attribute vec3 aSolid;
4
4
  attribute vec3 aHint;
5
5
  varying vec3 vColor;
@@ -10,13 +10,13 @@ import{a as ae,b as re,L as ie}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
- `,ja=`
13
+ `,Ba=`
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(o){return new wt().setHex(o,$t)}function Po(o,t){const n=o.mode==="POSE";let e;return n?t.active&&t.select?e=Ft(St.poseActive):t.active?e=Ft(St.poseActiveUnsel):t.select?e=Ft(St.pose):e=Ft(St.wire):e=Ft(St.vertex),n&&t.lockedWeight&&e.lerp(Ft(St.lockedWeight),St.lockedWeightFactor),e}function Eo(o,t){const n=Ft(St.solid);return o.mode==="POSE"&&t.lockedWeight&&n.lerp(Ft(St.lockedWeight),St.lockedWeightFactor),n}const Ba=new q,Ua=new x,No=new se;function Ro(o,t){return new q().set(...t.matrix.flat()).premultiply(o).scale(new x().setScalar(t.length))}class Wa{constructor(){this.group=new it,this.disposables=[],this.signature="",this.group.name="BlenderArmatureOverlay"}apply(t,n){const e=[],r=JSON.stringify(t);if(r===this.signature)return e;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"&&e.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"&&e.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(m=>!m.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(m=>{const l=m.material;l&&"depthTest"in l&&(l.depthTest=!1),m.renderOrder=10}),this.group.add(u)}return e}buildOctahedral(t,n,e){const r=new it;r.name=`${t.object}:bones`;const a=[],i=[],f=[],u=[],m=[],l=[],s=[],c=[],_=[],d=[];for(const h of n){const v=Ro(e,h),p=Eo(t,h),g=Fa(p),b=Po(t,h);No.setFromMatrix4(v).invert().transpose();for(let A=0;A<So.length;A++){const T=Ua.set(...Da[A]).applyMatrix3(No).normalize().clone();for(const O of So[A]){const E=new x(...Vn[O]).applyMatrix4(v);a.push(E.x,E.y,E.z),i.push(T.x,T.y,T.z),f.push(p.r,p.g,p.b),u.push(g.r,g.g,g.b)}}const y=Mo(h)===2?s:m,S=Mo(h)===2?c:l;for(const[A,T]of Ca){const O=new x(...Vn[A]).applyMatrix4(v),E=new x(...Vn[T]).applyMatrix4(v);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||(_.push(v.clone()),d.push(p)),_.push(v.clone().multiply(Ba.makeTranslation(0,1,0))),d.push(p)}r.add(this.solidMesh(a,i,f,u)),m.length&&r.add(this.lines(m,l,1)),s.length&&r.add(this.lines(s,c,2));for(let h=0;h<_.length;h++)r.add(this.point(_[h],d[h]));return r}buildStick(t,n,e){const r=new it;r.name=`${t.object}:bones`;const a=[],i=[],f=[],u=[];for(const m of n){const l=Ro(e,m),s=new x().setFromMatrixPosition(l),c=new x(0,1,0).applyMatrix4(l),_=Po(t,m),d=Eo(t,m);a.push(s.x,s.y,s.z,c.x,c.y,c.z),i.push(_.r,_.g,_.b,_.r,_.g,_.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,$a)),r.add(this.lines(f,u,La)),r}solidMesh(t,n,e,r){const a=new vn;a.setAttribute("position",new Mt(t,3)),a.setAttribute("normal",new Mt(n,3)),a.setAttribute("aSolid",new Mt(e,3)),a.setAttribute("aHint",new Mt(r,3));const i=new mo({vertexShader:Va,fragmentShader:ja,side:We});this.disposables.push(a,i);const f=new Rt(a,i);return f.frustumCulled=!1,f}lines(t,n,e){const r=new ae;r.setPositions(t),r.setColors(n);const a=new re({linewidth:e,vertexColors:!0});this.disposables.push(r,a);const i=new ie(r,a);return i.frustumCulled=!1,i}point(t,n){const e=new He(ka,12,8),r=new Nn({color:n});this.disposables.push(e,r);const a=new Rt(e,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 Io="RUNTIME_FRAME_UNKNOWN_GEOMETRY",an="RUNTIME_FRAME_UNKNOWN_IMAGE";function Ha(o){const t=Math.fround,n=t(t(t(o[0]*o[0])+t(o[1]*o[1]))+t(o[2]*o[2]));if(n>1e-35){const e=t(Math.sqrt(n)),r=t(1/e);return{unit:[t(o[0]*r),t(o[1]*r),t(o[2]*r)],length:e}}return{unit:[0,0,0],length:0}}const I=Math.fround,In=I(2*Math.PI),jn=I(1-1e-4),Wt=(o,t)=>I(I(I(o[0]*t[0])+I(o[1]*t[1]))+I(o[2]*t[2])),dn=(o,t,n=1)=>o.map((e,r)=>I(e+I(t[r]*n))),qa=(o,t)=>o.map((n,e)=>I(n-t[e]));function rn(o){const t=I(Math.sqrt(Wt(o,o)));return t>0?o.map(n=>I(n/t)):[0,0,0]}function sn(o){const t=Math.abs(o)<1?I(1-I(1-Math.abs(o))):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 e=I(I(Math.sqrt(I(1-t)))*n);return o<0?I(I(Math.PI)-e):e}function Ga(o){let t=o.at(-1);const n=[0,0,0];for(const e of o){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]-e[a])*I(t[i]+e[i])))}t=e}return n}function Xa(o){const t=[],n=[],e=(d,h)=>d<h?`${d}:${h}`:`${h}:${d}`,r=new Map((o.edge_order??[]).map(([d,h],v)=>[e(d,h),v])),a=new Set((o.sharp??[]).map(([d,h])=>e(d,h))),i=new Map;for(const[d,h]of o.f.entries()){const v=t.length,p=Ha(Ga(h.map(g=>o.v[g]))).unit;n.push(p.some(Boolean)?p:[0,0,1]);for(let g=0;g<h.length;g++){const b=e(h[g],h[(g+1)%h.length]);r.has(b)||r.set(b,r.size);const y=o.face_edges?.[d]?.[g]??r.get(b),S=t.length;t.push({vertex:h[g],face:d,edge:y,prev:v+(g+h.length-1)%h.length,next:v+(g+1)%h.length});const A=i.get(y)??[];A.push(S),i.set(y,A)}}const f=new Map,u=new Map;for(const[d,h]of i){if(h.length!==2||o.edge_sharp?.[d])continue;const[v,p]=h,g=t[v],b=t[p];!o.s?.[g.face]||!o.s?.[b.face]||g.vertex!==t[b.next].vertex||b.vertex!==t[g.next].vertex||!o.edge_sharp&&a.has(e(g.vertex,b.vertex))||(u.set(v,b.next),f.set(b.next,v),u.set(p,g.next),f.set(g.next,p))}const m=[],l=[],s=[],c=[],_=(d,h)=>rn(qa(o.v[t[t[d][h]].vertex],o.v[t[d].vertex]));for(let d=0;d<t.length;d++){if(l[d]!==void 0)continue;let h=d;const v=new Set([h]);for(;u.has(h)&&!v.has(u.get(h));)h=u.get(h),v.add(h);u.has(h)&&(h=Math.min(...v));const p=[h];for(;f.has(p.at(-1))&&f.get(p.at(-1))!==h;)p.push(f.get(p.at(-1)));let g=[0,0,0];if(p.length===1)g=n[t[h].face];else{for(const E of p)g=dn(g,n[t[E].face],sn(Wt(_(E,"prev"),_(E,"next"))));g=rn(g)}const b=_(h,"next"),y=p.at(-1),S=_(y,"prev"),A=Wt(b,g),T=Wt(S,g),O={normal:g,reference:[0,0,0],ortho:[0,0,0],alpha:0,beta:0};if(Math.abs(A)<jn&&Math.abs(T)<jn){const E=p.length>1?p.map(lt=>_(lt,"next")):[];E.length&&t[t[y].prev].edge!==t[h].edge&&E.push(S),O.alpha=E.length?I(E.reduce((lt,w)=>I(lt+sn(Wt(w,g))),0)/E.length):I(I(sn(A)+sn(T))/2),O.reference=rn(dn(b,g,-A));const k=g,j=O.reference;O.ortho=rn([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=rn(dn(S,g,-T)),K=Wt(O.reference,G),J=sn(K);O.beta=K<jn?Wt(O.ortho,G)<0?I(In-J):J:In}O.alpha===0&&(O.normal=[0,0,0]);for(const E of p)l[E]=m.length;m.push(p),s.push(O),c.push(g)}return{corners:t,fans:m,fanOf:l,spaces:s,faceNormals:n,fanNormals:c}}function Ya(o,t){if(!t[0]||o.alpha===0||o.beta===0)return o.normal;const n=I(t[0]/32767),e=I(t[1]/32767),r=I((n>0?o.alpha:I(In-o.alpha))*n),a=I((e>0?o.beta:I(In-o.beta))*e);let i=o.normal.map(f=>I(f*I(Math.cos(r))));return i=dn(i,o.reference,I(I(Math.sin(r))*I(Math.cos(a)))),e!==0&&(i=dn(i,o.ortho,I(I(Math.sin(r))*I(Math.sin(a))))),i}function ye(o,t){if(!t)return null;const{corners:n,fans:e,spaces:r}=Xa(o);if(t.type==="INT16_2D"&&t.domain==="CORNER"){const a=new Array(n.length);for(const[i,f]of e.entries()){const u=f.reduce((l,s)=>{const c=t.data[s];return[l[0]+c[0],l[1]+c[1]]},[0,0]),m=Ya(r[i],u.map(l=>Math.trunc(l/f.length)));for(const l of f)a[l]=m}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 Bn={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}},Za=1e-6;function Qa(o){const t=new x;for(let n=0;n<o.length;n++){const e=o[n],r=o[(n+1)%o.length];t.x+=(e.y-r.y)*(e.z+r.z),t.y+=(e.z-r.z)*(e.x+r.x),t.z+=(e.x-r.x)*(e.y+r.y)}return t.multiplyScalar(.5)}const Ka=(o,t,n)=>(t.x-o.x)*(n.y-o.y)-(t.y-o.y)*(n.x-o.x),zo=o=>Array.from({length:o-2},(t,n)=>[0,n+1,n+2]);function Ja(o){let t=0;for(let n=0;n<o.length;n++){const e=o[n],r=o[(n+1)%o.length];t+=e.x*r.y-r.x*e.y}return t}function Fo(o,t,n){if(o.length!==t.length-2||!(Math.abs(n)>0))return!1;const e=Math.sign(n);let r=0;for(const[a,i,f]of o){const u=Ka(t[a],t[i],t[f]);if(u*e<0)return!1;r+=Math.abs(u)}return Math.abs(r-Math.abs(n))<=Za*Math.abs(n)}function tr(o){const t=o.length;if(t<3)return{triangles:[],sound:!1,method:"fan"};if(t===3)return{triangles:[[0,1,2]],sound:!0,method:"fan"};const n=Qa(o),e=n.length();if(!(e>0)||!Number.isFinite(e))return{triangles:zo(t),sound:!1,method:"fan"};const r=n.clone().divideScalar(e),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=o[0],m=o.map(_=>{const d=_.clone().sub(u);return new Gt(d.dot(i),d.dot(f))}),l=Ja(m),s=zo(t);if(Fo(s,m,l))return{triangles:s,sound:!0,method:"fan"};let c=[];try{c=qe.triangulateShape(m,[]).map(_=>[_[0],_[1],_[2]])}catch{return{triangles:s,sound:!1,method:"fan"}}return Fo(c,m,l)?{triangles:c,sound:!0,method:"earcut"}:{triangles:c.length>0?c:s,sound:!1,method:c.length>0?"earcut":"fan"}}const nr=new Set(["FLOAT","FLOAT2","FLOAT_VECTOR","FLOAT_COLOR","BYTE_COLOR"]);function Un(o){const t=o/255;return t<.04045?t<0?0:t*(1/12.92):((t+.055)*(1/1.055))**2.4}function Wn(o,t,n){switch(o){case"FLOAT":{const e=Number(t[n]);return[e,e,e,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[Un(Number(t[n*4])),Un(Number(t[n*4+1])),Un(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 po(o,t){return o.filter(n=>nr.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 e=t(n.data,n.type),r=[0,0,0,0];return{name:n.name,domain:n.domain,read:(a,i,f)=>n.domain==="POINT"?Wn(n.type,e,a):n.domain==="CORNER"?i===void 0?r:Wn(n.type,e,i):f===void 0?r:Wn(n.type,e,f)}})}function we(o){const t=o.vertexCount,n=o.starts.length-1,e=o.starts,r=o.cornerVerts,a=e[n];let i=t;for(let w=0;w<n;w++)i+=(e[w+1]-e[w]-2)*3;const f=new Uint32Array(a),u=new Uint8Array(a),m=new Uint8Array(t),l=new Uint32Array(a);let s=!1;for(let w=0;w<n;w++)if(o.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)}`,_=new Map,d=new Set;for(const[w,V]of o.sharp)d.add(c(w,V));if(o.edges)for(const[w,V]of o.edges){if(w===V)throw new Error("Runtime mesh edge needs distinct vertices");_.set(c(w,V),-1)}const h=w=>{for(;l[w]!==w;)l[w]=l[l[w]],w=l[w];return w},v=(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=e[w],F=e[w+1]-V,Y=o.smooth(w)?1:0;for(let Z=0;Z<F;Z++){const $=V+Z;m[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),$=_.get(Z);if($!==void 0&&$>=0&&u[w]&&u[$]&&!d.has(Z)){const P=f[$];v(w,r[$]===F?$:P),v(V,r[$]===F?P:$)}($===void 0||$<0||!u[$]&&u[w])&&_.set(Z,w)}const p=o.uv,g=new Float32Array(i*3),b=new Float32Array(i*2),y=new Uint32Array(i),S=(o.uvLayers??[]).map(w=>({...w,data:new Float32Array(i*2)})),A=(o.attributeLayers??[]).map(w=>({...w,data:new Float32Array(i*4)})),T=o.orco?new Float32Array(i*3):null,O=new Uint32Array(i),E=new Map,k=[],j=o.normals||o.cornerNormal?new Float32Array(i*3):null;let G=0,K=0;const J=(w,V,F,Y,Z)=>{const $=G++;for(const P of A)P.data.set(P.read(w,Y,Z),$*4);if(T)for(let P=0;P<3;P++)T[$*3+P]=o.orco[w*3+P]*.5+.5;if(y[$]=w,o.co(w).toArray(g,$*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 $},lt=(w,V)=>{const F=p?.(w),Y=o.cornerNormal?[o.cornerNormal[w*3],o.cornerNormal[w*3+1],o.cornerNormal[w*3+2]]:o.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("")}${A.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=e[w],Y=e[w+1]-F,Z=[];for(let B=0;B<Y;B++)Z.push(o.co(r[F+B]));for(const B of tr(Z).triangles)for(const tt of B)O[K++]=lt(F+tt,w);const $=o.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++)m[w]||J(w);return{positions:g.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:A.map(w=>({name:w.name,data:w.data.slice(0,G*4)})),orco:T?T.slice(0,G*3):null,indices:O.slice(0,K),sourceVertex:y.slice(0,G),groups:k}}function kt(o){return`blenderA_${Array.from(new TextEncoder().encode(o),t=>t.toString(16).padStart(2,"0")).join("")}`}function Pn(o){const t=new vn;t.setAttribute("position",new dt(o.positions,3)),t.setAttribute("uv",new dt(o.uv??new Float32Array(o.positions.length/3*2),2)),t.setIndex(new dt(o.indices,1));const n=Object.create(null);for(const[e,r]of(o.uvLayers??[]).entries()){if(e>=8)throw new Error("A Blender mesh supports at most eight UV maps");n[r.name]=e+1,t.setAttribute(`uv${e+1}`,new dt(r.data,2))}t.userData.blenderUvChannels=n;for(const e of o.attributeLayers??[])t.setAttribute(kt(e.name),new dt(e.data,4));t.userData.blenderAttributes=(o.attributeLayers??[]).map(e=>e.name),o.orco&&(t.setAttribute("blenderOrco",new dt(o.orco,3)),t.userData.blenderOrcoFromDoor=!0);for(const e of o.groups)t.addGroup(e.start,e.count,e.materialIndex);return o.normals?t.setAttribute("normal",new dt(o.normals,3)):t.computeVertexNormals(),o.sourceVertex&&t.setAttribute("blenderVertex",new dt(o.sourceVertex,1)),t}function or(o,t){const n=o.cornerTri,e=o.cornerNormal,r=o.co.length/3,a=o.corner.length,i=o.faceStart.length-1,f=o.attributes.filter(P=>P.type==="FLOAT2"&&P.domain==="CORNER"),u=o.renderUv??o.activeUv??f[0]?.name,m=f.findIndex(P=>P.name===u);if(u&&m<0)throw new Error(`Runtime UV map ${u} is missing`);const l=po(o.attributes,P=>P),s=3+f.length*2+l.length*4,c=new Float32Array(s),_=new Float32Array(s),d=new Uint32Array(c.buffer),h=new Uint32Array(_.buffer),v=new Uint32Array(a),p=new Uint32Array(a),g=new Uint32Array(a),b=new Uint32Array(a),y=new Uint8Array(r);let S=1;for(;S<Math.max(1,a*2);)S*=2;const A=new Uint32Array(S),T=(P,B,tt,nt)=>{let ct=0;for(let rt=0;rt<3;rt++)nt[ct++]=e[P*3+rt];for(const rt of f)for(let st=0;st<2;st++)nt[ct++]=Number(rt.data[P*2+st]);for(const rt of l){const st=rt.read(tt,P,B);for(let Tt=0;Tt<4;Tt++)nt[ct++]=Number(st[Tt])}};let O=0;for(let P=0;P<i;P++)for(let B=o.faceStart[P];B<o.faceStart[P+1];B++){const tt=o.corner[B];if(tt>=r)throw new Error("Native mesh corner references a missing vertex");v[B]=P,y[tt]=1,T(B,P,tt,c);let nt=Math.imul(tt^2166136261,16777619);for(const st of d)nt=Math.imul(nt^st,16777619);const ct=nt>>>0&S-1;let rt=-1;for(let st=A[ct];st;st=b[st-1]){const Tt=st-1,Ln=g[Tt];if(o.corner[Ln]!==tt)continue;T(Ln,v[Ln],tt,_);let To=!0;for(let gn=0;gn<s;gn++)if(d[gn]!==h[gn]){To=!1;break}if(To){rt=Tt;break}}rt<0&&(rt=O++,g[rt]=B,b[rt]=A[ct],A[ct]=rt+1),p[B]=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)})),lt=l.map(P=>({name:P.name,data:new Float32Array(k*4)})),w=o.orco?new Float32Array(k*3):null,V=(P,B)=>{K[P]=B;for(let tt=0;tt<3;tt++)j[P*3+tt]=o.co[B*3+tt],w&&(w[P*3+tt]=o.orco[B*3+tt]*.5+.5)};for(let P=0;P<O;P++){const B=g[P],tt=o.corner[B];V(P,tt),T(B,v[B],tt,c),G.set(c.subarray(0,3),P*3);let nt=3;for(const ct of J)ct.data.set(c.subarray(nt,nt+2),P*2),nt+=2;for(const ct of lt)ct.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 B=0;B<l.length;B++)lt[B].data.set(l[B].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 B=o.faceStart[P],tt=o.faceStart[P+1],nt=Math.max(0,tt-B-2)*3;if($+nt>n.length)throw new Error("Native mesh triangulation is incomplete");for(let st=0;st<nt;st++){const Tt=n[$+st];if(Tt<B||Tt>=tt)throw new Error("Native triangle references a different face");Y[$+st]=p[Tt]}const ct=o.material[P],rt=Z.at(-1);rt?.materialIndex===ct?rt.count+=nt:Z.push({start:$,count:nt,materialIndex:ct}),$+=nt}if($!==n.length)throw new Error("Native mesh triangulation has extra triangles");return{positions:j,normals:G,sourceVertex:K,uv:m<0?null:J[m].data,uvLayers:J,attributeLayers:lt,orco:w,indices:Y,groups:Z,hash:t}}function Do(o,t){if(o.cornerTri&&o.cornerNormal)return or(o,t);const n=o.co.length/3,e=o.attributes.filter(h=>h.type==="FLOAT2"&&h.domain==="CORNER"),r=o.renderUv??o.activeUv??e[0]?.name,a=e.find(h=>h.name===r);if(r&&!a)throw new Error(`Runtime UV map ${r} is missing`);const i=a?a.data:null,f=o.edge.length/2,u=new Array(f);for(let h=0;h<f;h++)u[h]=[o.edge[h*2],o.edge[h*2+1]];const m=[];for(let h=0;h<f;h++)o.edgeSharp[h]===1&&m.push(u[h]);const l=o.cornerNormal?void 0:o.attributes.find(h=>h.name==="custom_normal"),s=l?{v:Array.from({length:n},(h,v)=>[o.co[v*3],o.co[v*3+1],o.co[v*3+2]]),f:Array.from({length:o.faceStart.length-1},(h,v)=>Array.from(o.corner.subarray(o.faceStart[v],o.faceStart[v+1]))),s:Array.from(o.smooth,Boolean),edge_order:u,sharp:m,face_edges:Array.from({length:o.faceStart.length-1},(h,v)=>Array.from(o.cornerEdge.subarray(o.faceStart[v],o.faceStart[v+1]))),edge_sharp:Array.from(o.edgeSharp,Boolean)}:null,c=l?{type:l.type,domain:l.domain,data:Array.from({length:l.data.length/Bn[l.type].size},(h,v)=>Array.from({length:Bn[l.type].size},(p,g)=>Number(l.data[v*Bn[l.type].size+g])))}:void 0,_=new x,d={vertexCount:n,normals:s?ye(s,c):null,cornerNormal:o.cornerNormal,orco:o.orco,co:h=>_.set(o.co[h*3],o.co[h*3+1],o.co[h*3+2]).clone(),starts:o.faceStart,cornerVerts:o.corner,smooth:h=>o.smooth[h]===1,material:h=>o.material[h],edges:u,sharp:m,uv:i?h=>[i[h*2],i[h*2+1]]:null,uvLayers:e.map(h=>({name:h.name,read:v=>[Number(h.data[v*2]),Number(h.data[v*2+1])]})),attributeLayers:po(o.attributes,h=>h)};return{...we(d),hash:t}}function er(o){const t=o.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},e=new Uint32Array(o.f.length+1);o.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");e[c+1]=e[c]+s.length});const r=new Uint32Array(e[o.f.length]);o.f.forEach((s,c)=>s.forEach((_,d)=>{n(_),r[e[c]+d]=_}));for(const[s,c]of o.edge_order??o.e??[])n(s),n(c);const a={POINT:t.length,EDGE:(o.edge_order??o.e??[]).length,FACE:o.f.length,CORNER:r.length};for(const s of o.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=(o.attributes??[]).filter(s=>s.type==="FLOAT2"&&s.domain==="CORNER"),f=o.render_uv??o.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 m=u?.data,l={vertexCount:t.length,normals:ye(o,o.attributes?.find(s=>s.name==="custom_normal")),co:n,starts:e,cornerVerts:r,smooth:s=>!!o.s?.[s],material:s=>o.m?.[s]??0,edges:o.edge_order??o.e??null,sharp:o.sharp??[],uv:m?s=>m[s]:null,uvLayers:i.map(s=>({name:s.name,read:c=>s.data[c]})),attributeLayers:po(o.attributes??[],s=>Array.from(s).flat())};return Pn(we(l))}const pn=1.5707963267948966,Ht=6.283185307179586,Oe=.3183098861837067,Ae=.0795774715459476,ar=.3,rr=Ae,ir=3/16*Oe,ro=.8,Co=ro*ro,qt=6371,Te=100,io=qt+Te,ko=64,$o=64,ft=256,Vt=64,sr=[1.679,1.828,1.986,1.307],lr=[.006605,.01067,.01842,.03156],fr=[3472e-28,3914e-28,1349e-28,1103e-29],cr=334.5,ur=[28722e-28,46168e-28,79706e-28,13578e-27],_r=[15908e-26,17711e-26,20942e-26,24033e-26],Lo=13681e16,mr=2e6,dr=.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]],zn=o=>o*o,un=o=>o<0?0:o>1?1:o,Nt=(o,t,n)=>o+n*(t-o),hr=o=>Math.sqrt(Math.max(o,0)),Se=o=>[-Math.sqrt(1-o*o),0,o];function so(o,t,n,e,r,a,i){const f=o*e+t*r+n*a,u=o*o+t*t+n*n-i*i;if(u>0&&f>0)return-1;const m=f*f-u;return m<0?-1:m>=f*f?-f+Math.sqrt(m):-f-Math.sqrt(m)}const pr=o=>ir*(1+zn(o));function vr(o){const t=1+Co+2*ro*o;return Ae*(1-Co)/(t*Math.sqrt(t))}const gr=o=>Lo*(Math.exp(-o/dr)+mr/Lo);function vo(o,t){let n=o%Ht;Math.abs(n)>=Math.PI&&(n-=Math.sign(n)*2*Math.PI);let e=t;return(n>=pn||n<=-pn)&&(n=Math.sign(n)*Math.PI-n,e+=Math.PI),e=e%Ht,e<0&&(e+=Ht),e=Ht-e,[n,e]}class xr{constructor(t,n,e){this.air=t,this.aerosol=n,this.ozone=e,this.lut=new Float32Array(Vt*ft*4)}coefficients(t,n){const e=gr(t)*this.aerosol,r=Math.log(Math.max(t,1e-4)),a=378547397e12*Math.exp(-zn(r-3.22261)*5.55555555-r),i=Math.exp(-.07771971*t**1.16364243);for(let f=0;f<4;f++)n[f]=ur[f]*e,n[4+f]=_r[f]*e,n[8+f]=fr[f]*cr*a*this.ozone,n[12+f]=lr[f]*i*this.air}transmittance(t,n,e){const[r,a,i]=Se(t),f=Nt(qt,io,n),m=so(0,0,f,r,a,i,io)/ko,l=[0,0,0,0],s=new Float64Array(16);for(let c=0;c<ko;c++){const _=(c+.5)*m,d=r*_,h=a*_,v=f+i*_,p=Math.max(Math.hypot(d,h,v)-qt,0);this.coefficients(p,s);for(let g=0;g<4;g++)l[g]+=(s[g]+s[4+g]+s[8+g]+s[12+g])*m}for(let c=0;c<4;c++)e[c]=Math.exp(-l[c])}precompute(){const t=new Float64Array(4);for(let n=0;n<Vt;n++)for(let e=0;e<ft;e++){const r=e/(ft-1),a=n/(Vt-1);this.transmittance(r*2-1,a,t);const i=(n*ft+e)*4;for(let f=0;f<4;f++)this.lut[i+f]=t[f]}}lookup(t,n,e){const r=(ft-1)*un(t*.5+.5),a=(Vt-1)*un(n),i=Math.trunc(r),f=Math.trunc(a),u=Math.min(i+1,ft-1),m=Math.min(f+1,Vt-1),l=r-i,s=a-f,c=(f*ft+i)*4,_=(f*ft+u)*4,d=(m*ft+i)*4,h=(m*ft+u)*4;for(let v=0;v<4;v++)e[v]=Nt(Nt(this.lut[c+v],this.lut[_+v],l),Nt(this.lut[d+v],this.lut[h+v],l),s)}lookupAtGround(t,n){const e=(ft-1)*un(t*.5+.5),r=Math.trunc(e),a=Math.min(r+1,ft-1),i=e-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 e=(Vt-1)*un(t),r=Math.trunc(e),a=Math.min(r+1,Vt-1),i=e-r,f=ft-1;for(let u=0;u<4;u++)n[u]=Nt(this.lut[(r*ft+f)*4+u],this.lut[(a*ft+f)*4+u],i)}inscattering(t,n,e,r,a,i,f,u,m){const l=-(a*t[0]+i*t[1]+f*t[2]),s=pr(l),c=vr(l),_=u/$o,d=new Float64Array(16),h=new Float64Array(4),v=new Float64Array(4),p=new Float64Array(4),g=new Float64Array(4),b=new Float64Array(4),y=[0,0,0,0],S=[1,1,1,1];for(let A=0;A<$o;A++){const T=(A+.5)*_,O=n+a*T,E=e+i*T,k=r+f*T,j=Math.hypot(O,E,k),G=Math.max(j-qt,0),K=G/Te,J=(O*t[0]+E*t[1]+k*t[2])/j;this.coefficients(G,d),this.lookup(J,K,h);const lt=Ht*(1-hr(1-zn(qt/j)));this.lookupAtGround(J,p),this.lookupToSun(0,g),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=g[F]/b[F],Z=rr*lt*(ar*Oe)*p[F]*Y*J;v[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=sr[F]*(d[12+F]*(s*h[F]+v[F])+d[4+F]*(c*h[F]+v[F])),$=Math.exp(-_*Y),P=Math.max(Y,1e-7);y[F]+=S[F]*((Z-Z*$)/P),S[F]*=$}}for(let A=0;A<4;A++)m[A]=y[A]}}const ht=512,Jt=256;function Me(o,t){const n=new xr(o.airDensity,o.aerosolDensity,o.ozoneDensity);n.precompute();const e=Math.min(Math.max(o.altitude,1),99999)/1e3,r=Se(Math.cos(pn-t)),a=new Float32Array(ht*Jt*3),i=ht/2,f=new Float64Array(4);for(let u=0;u<Jt;u++)for(let m=0;m<i;m++){const l=(m+.5)/ht,s=(u+.5)/Jt,c=Ht*l,_=s*2-1,d=Math.sign(_)*zn(_)*pn,h=Math.cos(d)*Math.cos(c),v=Math.cos(d)*Math.sin(c),p=Math.sin(d),g=qt+e,b=so(0,0,g,h,v,p,io),y=so(0,0,g,h,v,p,qt),S=y<0?b:y;n.inscattering(r,0,0,g,h,v,p,S,f);let A=0,T=0,O=0;for(let j=0;j<4;j++)A+=Hn[j][0]*f[j],T+=Hn[j][1]*f[j],O+=Hn[j][2]*f[j];const E=(u*ht+m)*3;a[E]=A,a[E+1]=T,a[E+2]=O;const k=(u*ht+(ht-m-1))*3;a[k]=A,a[k+1]=T,a[k+2]=O}return a}function br(o){const[t]=vo(o.sunElevation,o.sunRotation);return Me(o,t)}function go(o){const[t]=vo(o.sunElevation,o.sunRotation);return JSON.stringify([t,o.altitude,o.airDensity,o.aerosolDensity,o.ozoneDensity])}const yr=6,Qt=new Map;function wr(o){return Qt.has(go(o))}function Pe(o,t){Qt.set(go(o),t),Qt.size>yr&&Qt.delete(Qt.keys().next().value)}function Or(o){const[t,n]=vo(o.sunElevation,o.sunRotation),e=go(o);let r=Qt.get(e);r===void 0&&(r=Me(o,t),Pe(o,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=un(Math.sqrt(s/pn)*Math.sign(u)*.5+.5),_=l*ht-.5,d=c*Jt-.5,h=Math.floor(_),v=Math.floor(d),p=_-h,g=d-v,b=k=>(k%ht+ht)%ht,y=k=>k<0?0:k>Jt-1?Jt-1:k,S=b(h),A=b(h+1),T=y(v),O=y(v+1),E=[0,0,0];for(let k=0;k<3;k++){const j=Nt(r[(T*ht+S)*3+k],r[(T*ht+A)*3+k],p),G=Nt(r[(O*ht+S)*3+k],r[(O*ht+A)*3+k],p);E[k]=Nt(j,G,g)}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,xn=!1,Ar=0;const _n=new Map;function Tr(){if(zt||xn)return zt;if(typeof Worker>"u")return xn=!0,null;try{zt=new Worker(new URL("/assets/sky-precompute-worker-ChN7J87v.js",import.meta.url),{type:"module"})}catch{return xn=!0,null}return zt.onmessage=o=>{const{id:t,pixels:n,error:e}=o.data,r=_n.get(t);r&&(_n.delete(t),n?r.resolve(n):r.reject(new Error(e??"sky worker returned nothing")))},zt.onerror=o=>{const t=new Error(`sky worker failed: ${o.message||"unknown error"}`);for(const n of _n.values())n.reject(t);_n.clear(),zt?.terminate(),zt=null,xn=!0},zt}function Sr(o){const t=Tr();if(!t)return Promise.resolve(br(o));const n=Ar++,e={id:n,parameters:o};return new Promise((r,a)=>{_n.set(n,{resolve:r,reject:a}),t.postMessage(e)})}function Mr(o,t,n,e={}){switch(e.type??"LINEAR"){case"QUADRATIC":{const r=Math.max(o,0);return r*r}case"EASING":{const r=Math.min(1,Math.max(0,o));return r*r*(3-2*r)}case"DIAGONAL":return(o+t)/2;case"SPHERICAL":return Math.max(.999999-Math.hypot(o,t,n),0);case"QUADRATIC_SPHERE":{const r=Math.max(.999999-Math.hypot(o,t,n),0);return r*r}case"RADIAL":return Math.atan2(t,o)/(2*Math.PI)+.5;default:return o}}const qn=(o,t)=>t!==0?o/t:0,Vo=o=>Math.min(1,Math.max(-1,o)),jo=(o,t,n)=>{const e=n!==0?Math.max(n-Math.abs(o-t),0)/n:0;return Math.min(o,t)-e*e*e*n/6},Ee={ADD:(o,t)=>o+t,SUBTRACT:(o,t)=>o-t,MULTIPLY:(o,t)=>o*t,DIVIDE:qn,POWER:(o,t)=>t===0?1:o===0||o<0&&!Number.isInteger(t)?0:o**t,LOGARITHM:(o,t)=>o<=0||t<=0?0:qn(Math.log(o),Math.log(t)),SQRT:o=>Math.sqrt(Math.max(o,0)),INVERSE_SQRT:o=>o>0?1/Math.sqrt(o):0,ABSOLUTE:Math.abs,RADIANS:o=>o*Math.PI/180,DEGREES:o=>o*180/Math.PI,MINIMUM:(o,t)=>Math.min(o,t),MAXIMUM:(o,t)=>Math.max(o,t),LESS_THAN:(o,t)=>+(o<t),GREATER_THAN:(o,t)=>+(o>t),ROUND:o=>Math.floor(o+.5),FLOOR:Math.floor,CEIL:Math.ceil,FRACT:o=>o-Math.floor(o),MODULO:(o,t)=>t!==0?o%t:0,FLOORED_MODULO:(o,t)=>t!==0?o-Math.floor(o/t)*t:0,TRUNC:Math.trunc,SNAP:(o,t)=>Math.floor(qn(o,t))*t,WRAP:(o,t,n)=>t!==n?o-(t-n)*Math.floor((o-n)/(t-n)):n,PINGPONG:(o,t)=>{if(t===0)return 0;const n=(o-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:o=>Math.asin(Vo(o)),ARCCOSINE:o=>Math.acos(Vo(o)),ARCTANGENT:Math.atan,ARCTAN2:(o,t)=>o===0&&t===0?0:Math.atan2(o,t),SIGN:Math.sign,EXPONENT:Math.exp,COMPARE:(o,t,n)=>+(o===t||Math.abs(o-t)<=Math.max(n,2**-23)),MULTIPLY_ADD:(o,t,n)=>o*t+n,SMOOTH_MIN:jo,SMOOTH_MAX:(o,t,n)=>-jo(-o,-t,n)};function at(o,t){if(typeof o=="number")return()=>o;if(Array.isArray(o)){const r=new x(...o);return()=>r}if(o.kind==="direction")return r=>r;if(o.kind==="window"){if(!t)throw new Error("World Window coordinates need a render camera");return t}if(o.kind==="gradient"){const r=at(o.vector,t),a={type:o.gradient_type},i=new x;return f=>{const u=r(f),m=typeof u=="number"?u:u.x,l=typeof u=="number"?u:u.y,s=typeof u=="number"?u:u.z,c=xt.clamp(Mr(m,l,s,a),0,1);return o.output==="Fac"?c:i.setScalar(c)}}if(o.kind==="to_float"){const r=at(o.value,t);return a=>{const i=r(a);return typeof i=="number"?i:Math.fround(o.source_type==="RGBA"?i.x*.212639+i.y*.7151687+i.z*.0721923:(i.x+i.y+i.z)/3)}}if(o.kind==="math"){const r=o.inputs.map(f=>at(f,t)),a=Ee[o.operation],i=(f,u)=>{const m=r[f]?.(u)??0;if(typeof m!="number")throw new Error("World Math needs scalar inputs");return Math.fround(m)};return f=>{const u=Math.fround(a(i(0,f),i(1,f),i(2,f)));return o.clamp?xt.clamp(u,0,1):u}}if(o.kind==="mix_color"){const r=at(o.factor,t),a=at(o.a,t),i=at(o.b,t),f=new x,u=new x;return m=>{const l=r(m);if(typeof l!="number")throw new Error("World color Mix needs a scalar factor");const s=a(m);typeof s=="number"?f.setScalar(s):f.copy(s);const c=i(m);return typeof c=="number"?u.setScalar(c):u.copy(c),f.lerp(u,o.clamp_factor?xt.clamp(l,0,1):l),o.clamp_result&&f.clampScalar(0,1),f}}if(o.kind==="sky"){const r=Or({sunElevation:o.sun_elevation,sunRotation:o.sun_rotation,altitude:o.altitude,airDensity:o.air_density,aerosolDensity:o.aerosol_density,ozoneDensity:o.ozone_density});return a=>r(a)}if(o.kind==="mapping"){const r=at(o.vector,t),a=new x(...o.location),i=new x(...o.scale),f=new At().setFromEuler(new Ge(o.rotation[0],o.rotation[1],o.rotation[2],"ZYX")),u=f.clone().invert(),m=new x(...o.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),o.vector_type??"POINT"){case"TEXTURE":return l.sub(a).applyQuaternion(u).multiply(m);case"VECTOR":return l.multiply(i).applyQuaternion(f);case"NORMAL":return l.multiply(m).applyQuaternion(f).normalize();case"POINT":return l.multiply(i).applyQuaternion(f).add(a)}}}if(o.kind==="map_range"){const r=at(o.value,t),a=at(o.from_min,t),i=at(o.from_max,t),f=at(o.to_min,t),u=at(o.to_max,t),m=at(o.steps,t),l=(_,d)=>{const h=_(d);if(typeof h!="number")throw new Error("World Map Range needs scalar inputs");return h},s=o.interpolation,c=o.clamp;return _=>{const d=l(r,_),h=l(a,_),v=l(i,_),p=l(f,_),g=l(u,_);if(h===v)return 0;let b;if(s==="STEPPED"){const S=l(m,_),A=(d-h)/(v-h);b=S>0?Math.floor(A*(S+1))/S:0}else if(s==="SMOOTHSTEP"||s==="SMOOTHERSTEP"){const S=xt.clamp((d-Math.min(h,v))/(Math.max(h,v)-Math.min(h,v)),0,1),A=s==="SMOOTHSTEP"?S*S*(3-2*S):S*S*S*(S*(S*6-15)+10);b=h>v?1-A:A}else b=(d-h)/(v-h);const y=p+b*(g-p);return c?p>g?xt.clamp(y,g,p):xt.clamp(y,p,g):y}}if(o.kind==="separate"){const r=at(o.vector,t);return a=>{const i=r(a);return typeof i=="number"?i:i.getComponent(o.axis)}}const n=at(o.factor,t),e=new x;return r=>{const a=n(r);if(typeof a!="number")throw new Error("World ColorRamp needs a scalar factor");const i=xt.clamp(a,0,1)*256,f=Math.floor(i),u=o.colors[f],m=o.colors[Math.min(f+1,256)],l=o.interpolate?i-f:0;return e.set(xt.lerp(u[0],m[0],l),xt.lerp(u[1],m[1],l),xt.lerp(u[2],m[2],l))}}function Pr(o,t,n,e){const r=new Float32Array(t*n*3),a=at(o,e),i=new x;for(let f=0;f<n;f++){const u=((f+.5)/n-.5)*Math.PI;for(let m=0;m<t;m++){const l=((m+.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+m)*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 Bo(o){const t=[],n=e=>{if(!(typeof e=="number"||Array.isArray(e)))switch(e.kind){case"sky":t.push({sunElevation:e.sun_elevation,sunRotation:e.sun_rotation,altitude:e.altitude,airDensity:e.air_density,aerosolDensity:e.aerosol_density,ozoneDensity:e.ozone_density});return;case"mapping":case"gradient":case"separate":n(e.vector);return;case"ramp":n(e.factor);return;case"mix_color":n(e.factor),n(e.a),n(e.b);return;case"math":e.inputs.forEach(n);return;case"to_float":n(e.value);return;case"map_range":n(e.value),n(e.from_min),n(e.from_max),n(e.to_min),n(e.to_max),n(e.steps);return;default:return}};return n(o),t}function Dt(o){if(typeof o=="number"||Array.isArray(o))return!1;switch(o.kind){case"window":return!0;case"mapping":case"gradient":case"separate":return Dt(o.vector);case"ramp":return Dt(o.factor);case"mix_color":return[o.factor,o.a,o.b].some(Dt);case"math":return o.inputs.some(Dt);case"to_float":return Dt(o.value);case"map_range":return[o.value,o.from_min,o.from_max,o.to_min,o.to_max,o.steps].some(Dt);default:return!1}}function Er(o,t,n,e){e.updateMatrixWorld();const r=new Float32Array(t*n*3),a=new x,i=at(o,()=>a),f=new x,u=e.getWorldPosition(new x),m=e.getWorldDirection(new x);for(let l=0;l<n;l++)for(let s=0;s<t;s++){const c=(s+.5)/t,_=(l+.5)/n;a.set(c,_,0),e.isOrthographicCamera?f.copy(m):f.set(c*2-1,_*2-1,.5).unproject(e).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 et=N().finite(),Nr=M({type:H(["POINT","SUN","SPOT","AREA"]),color:L([et,et,et]),energy:et,use_shadow:Q().default(!0),radius:et.optional(),spot_size:et.optional(),spot_blend:et.optional(),shape:H(["SQUARE","RECTANGLE","DISK","ELLIPSE"]).optional(),size:et.optional(),size_y:et.optional()}).strict();let lo;function Rr(){return lo??=Ma(async()=>{const{RectAreaLightUniformsLib:o}=await import("./RectAreaLightUniformsLib-DpPyArRG.js");return{RectAreaLightUniformsLib:o}},__vite__mapDeps([0,1,2])).then(({RectAreaLightUniformsLib:o})=>{o.init(),Ot()}),lo}function Ir(){return lo??Promise.resolve()}const zr=o=>{const t=o.size??0,n=o.size_y??t;if(o.shape==="RECTANGLE")return[t,n];if(o.shape==="DISK"){const e=Math.sqrt(Math.PI*t*t/4);return[e,e]}if(o.shape==="ELLIPSE"){const e=Math.sqrt(Math.PI/4);return[t*e,n*e]}return[t,t]};function Fr(o,t){const n=(i,f)=>t&&f(t)?t:new i;if(o.type==="SUN"){const i=n(fe,f=>f.isDirectionalLight);return i.intensity=o.energy,i.color.setRGB(o.color[0],o.color[1],o.color[2],vt),i.castShadow=o.use_shadow,i}if(o.type==="POINT"){const i=n(Jn,f=>f.isPointLight);return i.intensity=o.energy/(4*Math.PI),i.distance=0,i.decay=2,i.color.setRGB(o.color[0],o.color[1],o.color[2],vt),i.castShadow=o.use_shadow,i}if(o.type==="SPOT"){const i=n(to,f=>f.isSpotLight);return i.intensity=o.energy/(4*Math.PI),i.distance=0,i.decay=2,i.angle=(o.spot_size??0)/2,i.penumbra=o.spot_blend??0,i.color.setRGB(o.color[0],o.color[1],o.color[2],vt),i.castShadow=o.use_shadow,i}Rr();const e=n(Mn,i=>i.isRectAreaLight),[r,a]=zr(o);return e.width=r,e.height=a,e.intensity=o.energy/(Math.max(r*a,Number.MIN_VALUE)*Math.PI),e.color.setRGB(o.color[0],o.color[1],o.color[2],vt),e}function Dr(o,t,n){if(!o.castShadow||n<=0)return;const r=o.getWorldPosition(new x).distanceTo(t),a=o.shadow;if(!a)return;const i=a.camera;i.near=Math.max(n*.001,r-n),i.far=r+n,o.isDirectionalLight&&(i.left=-n,i.right=n,i.top=n,i.bottom=-n),i.updateProjectionMatrix()}function Cr(o,t){o.position.set(0,0,0);const n=o;o.isRectAreaLight||n.target&&n.target.parent!==t&&(n.target.position.set(0,0,-1),t.add(n.target))}const xo=[{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}],Uo=.69;class kr{constructor(){this.group=new it,this.lights=[],this.group.name="BlenderSolidStudio";const t=new le;t.name="BlenderSolidStudioTarget",this.group.add(t);const n=new wt(0,0,0);for(const[r,a]of xo.entries()){const i=(1+a.smooth)**2,f=new fe(16777215,Math.PI*Uo/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 e=new Xe(16777215,Math.PI*Uo);e.name="BlenderSolidWrapFill",e.color.copy(n),this.group.add(e),this.lights.push(e)}setRendered(t){this.group.visible=!t}dispose(){for(const t of this.lights)t.dispose();this.group.clear()}}const Zt=L([et,et,et]),X=xe(()=>Lt([et,Zt,M({kind:W("direction")}).strict(),M({kind:W("window")}).strict(),M({kind:W("gradient"),gradient_type:H(["LINEAR","QUADRATIC","EASING","DIAGONAL","SPHERICAL","QUADRATIC_SPHERE","RADIAL"]),output:H(["Fac","Color"]),vector:X}).strict(),M({kind:W("to_float"),source_type:H(["RGBA","VECTOR"]),value:X}).strict(),M({kind:W("math"),operation:H(Object.keys(Ee)),clamp:Q(),inputs:D(X).min(1).max(3)}).strict(),M({kind:W("mix_color"),factor:X,a:X,b:X,clamp_factor:Q(),clamp_result:Q()}).strict(),M({kind:W("mapping"),vector_type:H(["POINT","TEXTURE","VECTOR","NORMAL"]).optional(),vector:X,location:Zt,rotation:Zt,scale:Zt}).strict(),M({kind:W("separate"),vector:X,axis:N().int().min(0).max(2)}).strict(),M({kind:W("ramp"),factor:X,colors:D(Zt).length(257),interpolate:Q()}).strict(),M({kind:W("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:W("sky"),sun_elevation:et,sun_rotation:et,altitude:et,air_density:et,aerosol_density:et,ozone_density:et}).strict()])),Wo=M({color:Zt,strength:et,shader:X.optional()}),$r=Wo.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:Wo.strict().optional()}).strict(),Lr=4,ln=new Map,Gn=new Set;function Ho(o,t,n){const a=Dt(o);if(a&&!n)throw new Error("World Window coordinates need a render camera");n?.updateMatrixWorld();const i=JSON.stringify([o,a?[n.matrixWorld.elements,n.projectionMatrix.elements]:null]),f=ln.get(i);if(f!==void 0)return fo(f,t,256,128);const u=new x,m=new Cn,l=n?new q().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse):null,s=n?.getWorldPosition(new x),_=Pr(o,256,128,a?d=>(u.set(d.x,d.z,-d.y),n.isPerspectiveCamera&&u.add(s),m.set(u.x,u.y,u.z,1).applyMatrix4(l),m.w===0?u.set(0,0,0):u.set(m.x/m.w*.5+.5,m.y/m.w*.5+.5,0)):void 0);return ln.set(i,_),ln.size>Lr&&ln.delete(ln.keys().next().value),fo(_,t,256,128)}function Vr(o,t,n,e){const r=cn.toHalfFloat(1);for(let a=0;a<e;a++)o[a*4]=cn.toHalfFloat(t[a*3]*n),o[a*4+1]=cn.toHalfFloat(t[a*3+1]*n),o[a*4+2]=cn.toHalfFloat(t[a*3+2]*n),o[a*4+3]=r}function fo(o,t,n,e){const r=new Uint16Array(n*e*4);Vr(r,o,t,n*e);const a=new kn(r,n,e,$n,ho);return a.mapping=Ze,a.colorSpace=vt,a.minFilter=Xt,a.magFilter=Xt,a.needsUpdate=!0,a}class bo{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,e){if(this.clear(),this.pending=null,!n)return;const r=bo.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=[...Bo(a),...n.lighting?Bo(n.lighting.shader??n.lighting.color):[]].filter(l=>!wr(l));if(u.length===0){this.compose(r,n,a,e);return}const m=(async()=>{const l=await Promise.all(u.map(Sr));u.forEach((s,c)=>{Pe(s,l[c])}),!(this.generation!==i||this.applied?.scene!==r)&&(this.compose(r,n,a,e),Ot())})();this.pending=m,Gn.add(m),m.then(()=>Gn.delete(m),()=>Gn.delete(m))}compose(t,n,e,r){if(this.texture=Ho(e,n.strength,r),Dt(e)){if(!r)throw new Error("World Window coordinates need a render camera");this.screenTexture=fo(Er(e,512,512,r),n.strength,512,512),this.screenTexture.mapping=Ye,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 wt().setRGB(f,f,f).multiplyScalar(n.strength):new wt().setRGB(f.x,f.y,f.z).multiplyScalar(n.strength)}else t.background=this.texture;const{lighting:a}=n;this.environmentTexture=a?Ho(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 Ne(o){return[o.min.x,o.max.x].flatMap(t=>[o.min.y,o.max.y].flatMap(n=>[o.min.z,o.max.z].map(e=>new x(t,n,e))))}function jr(o,t){if(o.isEmpty()||!t.intersectsBox(o))return[];const n=Ne(o);if(n.every(l=>t.containsPoint(l)))return n;const e=[...t.planes,new Bt(new x(1,0,0),-o.min.x),new Bt(new x(-1,0,0),o.max.x),new Bt(new x(0,1,0),-o.min.y),new Bt(new x(0,-1,0),o.max.y),new Bt(new x(0,0,1),-o.min.z),new Bt(new x(0,0,-1),o.max.z)],r=[],a=new x,i=new x,f=new x,u=new x,m=Math.max(1,o.min.length(),o.max.length())*1e-8;for(let l=0;l<e.length;l++)for(let s=l+1;s<e.length;s++)for(let c=s+1;c<e.length;c++){const _=e[l],d=e[s],h=e[c];a.crossVectors(d.normal,h.normal);const v=_.normal.dot(a);Math.abs(v)<1e-12||(i.crossVectors(h.normal,_.normal),f.crossVectors(_.normal,d.normal),u.copy(a).multiplyScalar(-_.constant).addScaledVector(i,-d.constant).addScaledVector(f,-h.constant).divideScalar(v),e.every(p=>p.distanceToPoint(u)>=-m)&&r.push(u.clone()))}return r}function Br(o,t,n){if(!o.castShadow||!t.length)return;o.shadow.updateMatrices(o);const e=o.shadow.camera,r=e.matrixWorldInverse,a=new hn().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,m=Math.max(i.x,i.y,f)/Math.max(1,Math.min(o.shadow.mapSize.x,o.shadow.mapSize.y)-2*u),l=2*Math.SQRT2*m,s=u*m;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 _=new hn().setFromPoints(Ne(c).map(d=>d.applyMatrix4(r)));_.max.x<a.min.x||_.min.x>a.max.x||_.max.y<a.min.y||_.min.y>a.max.y||(a.min.z=Math.min(a.min.z,_.min.z),a.max.z=Math.max(a.max.z,_.max.z))}e.left=a.min.x,e.right=a.max.x,e.bottom=a.min.y,e.top=a.max.y,e.near=-a.max.z-l-f,e.far=-a.min.z+l+f,e.updateProjectionMatrix(),o.shadow.normalBias=l}const tn=N().finite(),qo=L([tn,tn,tn]),Re=M({min:L([N().int(),N().int(),N().int()]),max:L([N().int(),N().int(),N().int()]),density:D(tn),voxelSize:tn.positive(),color:qo,emission:qo,densityScale:tn.nonnegative()}).strict();function Ur(o){const t=o.max.map((l,s)=>l-o.min[s]+1);if(t.some(l=>l<=0)||t.reduce((l,s)=>l*s,1)!==o.density.length)throw new Error("Volume density dimensions do not match the evaluated grid");const n=new Qe(new Float32Array(o.density),t[0],t[1],t[2]);n.format=Ke,n.type=ce,n.minFilter=n.magFilter=Xt,n.unpackAlignment=1,n.needsUpdate=!0;const e=new x(...o.min).addScalar(-.5).multiplyScalar(o.voxelSize),r=new x(t[0],t[1],t[2]).multiplyScalar(o.voxelSize),a=new Je(r.x,r.y,r.z),i=a.getAttribute("position");for(let l=0;l<i.count;l++)i.setXYZ(l,e.x+(i.getX(l)>0?r.x:0),e.y+(i.getY(l)>0?r.y:0),e.z+(i.getZ(l)>0?r.z:0));i.needsUpdate=!0,a.computeBoundingBox(),a.computeBoundingSphere();const f=new mo({glslVersion:na,side:ta,transparent:!0,depthWrite:!1,premultipliedAlpha:!0,uniforms:{densityGrid:{value:n},minimum:{value:e},extent:{value:r},voxelSize:{value:o.voxelSize},densityScale:{value:o.densityScale},volumeColor:{value:new x(...o.color)},emission:{value:new x(...o.emission)},cameraLocal:{value:new x},rayLocal:{value:new x},orthographic:{value:!1},worldScale:{value:new se}},vertexShader:`
19
+ `;function Dt(o){return new Ot().setHex(o,$t)}function Eo(o,t){const n=o.mode==="POSE";let e;return n?t.active&&t.select?e=Dt(St.poseActive):t.active?e=Dt(St.poseActiveUnsel):t.select?e=Dt(St.pose):e=Dt(St.wire):e=Dt(St.vertex),n&&t.lockedWeight&&e.lerp(Dt(St.lockedWeight),St.lockedWeightFactor),e}function No(o,t){const n=Dt(St.solid);return o.mode==="POSE"&&t.lockedWeight&&n.lerp(Dt(St.lockedWeight),St.lockedWeightFactor),n}const Ua=new H,Wa=new x,Ro=new fe;function Io(o,t){return new H().set(...t.matrix.flat()).premultiply(o).scale(new x().setScalar(t.length))}class Ha{constructor(){this.group=new st,this.disposables=[],this.signature="",this.group.name="BlenderArmatureOverlay"}apply(t,n){const e=[],r=JSON.stringify(t);if(r===this.signature)return e;this.signature=r,this.clear();for(const a of Object.values(t)){const s=n(a.object);if(s===null)continue;a.displayType!=="OCTAHEDRAL"&&a.displayType!=="STICK"&&e.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"&&e.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(m=>!m.hide);if(f.length===0)continue;const u=a.displayType==="STICK"?this.buildStick(a,f,s):this.buildOctahedral(a,f,s);a.showInFront&&u.traverse(m=>{const l=m.material;l&&"depthTest"in l&&(l.depthTest=!1),m.renderOrder=10}),this.group.add(u)}return e}buildOctahedral(t,n,e){const r=new st;r.name=`${t.object}:bones`;const a=[],s=[],f=[],u=[],m=[],l=[],i=[],c=[],_=[],d=[];for(const h of n){const v=Io(e,h),p=No(t,h),g=Fa(p),b=Eo(t,h);Ro.setFromMatrix4(v).invert().transpose();for(let A=0;A<Mo.length;A++){const T=Wa.set(...Ca[A]).applyMatrix3(Ro).normalize().clone();for(const O of Mo[A]){const E=new x(...Vn[O]).applyMatrix4(v);a.push(E.x,E.y,E.z),s.push(T.x,T.y,T.z),f.push(p.r,p.g,p.b),u.push(g.r,g.g,g.b)}}const y=Po(h)===2?i:m,S=Po(h)===2?c:l;for(const[A,T]of ka){const O=new x(...Vn[A]).applyMatrix4(v),E=new x(...Vn[T]).applyMatrix4(v);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||(_.push(v.clone()),d.push(p)),_.push(v.clone().multiply(Ua.makeTranslation(0,1,0))),d.push(p)}r.add(this.solidMesh(a,s,f,u)),m.length&&r.add(this.lines(m,l,1)),i.length&&r.add(this.lines(i,c,2));for(let h=0;h<_.length;h++)r.add(this.point(_[h],d[h]));return r}buildStick(t,n,e){const r=new st;r.name=`${t.object}:bones`;const a=[],s=[],f=[],u=[];for(const m of n){const l=Io(e,m),i=new x().setFromMatrixPosition(l),c=new x(0,1,0).applyMatrix4(l),_=Eo(t,m),d=No(t,m);a.push(i.x,i.y,i.z,c.x,c.y,c.z),s.push(_.r,_.g,_.b,_.r,_.g,_.b),f.push(i.x,i.y,i.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,s,La)),r.add(this.lines(f,u,Va)),r}solidMesh(t,n,e,r){const a=new gn;a.setAttribute("position",new Mt(t,3)),a.setAttribute("normal",new Mt(n,3)),a.setAttribute("aSolid",new Mt(e,3)),a.setAttribute("aHint",new Mt(r,3));const s=new mo({vertexShader:ja,fragmentShader:Ba,side:He});this.disposables.push(a,s);const f=new Rt(a,s);return f.frustumCulled=!1,f}lines(t,n,e){const r=new se;r.setPositions(t),r.setColors(n);const a=new ie({linewidth:e,vertexColors:!0});this.disposables.push(r,a);const s=new le(r,a);return s.frustumCulled=!1,s}point(t,n){const e=new qe($a,12,8),r=new Rn({color:n});this.disposables.push(e,r);const a=new Rt(e,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 zo="RUNTIME_FRAME_UNKNOWN_GEOMETRY",an="RUNTIME_FRAME_UNKNOWN_IMAGE";function qa(o){const t=Math.fround,n=t(t(t(o[0]*o[0])+t(o[1]*o[1]))+t(o[2]*o[2]));if(n>1e-35){const e=t(Math.sqrt(n)),r=t(1/e);return{unit:[t(o[0]*r),t(o[1]*r),t(o[2]*r)],length:e}}return{unit:[0,0,0],length:0}}const I=Math.fround,zn=I(2*Math.PI),jn=I(1-1e-4),Wt=(o,t)=>I(I(I(o[0]*t[0])+I(o[1]*t[1]))+I(o[2]*t[2])),dn=(o,t,n=1)=>o.map((e,r)=>I(e+I(t[r]*n))),Ga=(o,t)=>o.map((n,e)=>I(n-t[e]));function rn(o){const t=I(Math.sqrt(Wt(o,o)));return t>0?o.map(n=>I(n/t)):[0,0,0]}function sn(o){const t=Math.abs(o)<1?I(1-I(1-Math.abs(o))):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 e=I(I(Math.sqrt(I(1-t)))*n);return o<0?I(I(Math.PI)-e):e}function Xa(o){let t=o.at(-1);const n=[0,0,0];for(const e of o){for(let r=0;r<3;r++){const a=(r+1)%3,s=(r+2)%3;n[r]=I(n[r]+I(I(t[a]-e[a])*I(t[s]+e[s])))}t=e}return n}function Ya(o){const t=[],n=[],e=(d,h)=>d<h?`${d}:${h}`:`${h}:${d}`,r=new Map((o.edge_order??[]).map(([d,h],v)=>[e(d,h),v])),a=new Set((o.sharp??[]).map(([d,h])=>e(d,h))),s=new Map;for(const[d,h]of o.f.entries()){const v=t.length,p=qa(Xa(h.map(g=>o.v[g]))).unit;n.push(p.some(Boolean)?p:[0,0,1]);for(let g=0;g<h.length;g++){const b=e(h[g],h[(g+1)%h.length]);r.has(b)||r.set(b,r.size);const y=o.face_edges?.[d]?.[g]??r.get(b),S=t.length;t.push({vertex:h[g],face:d,edge:y,prev:v+(g+h.length-1)%h.length,next:v+(g+1)%h.length});const A=s.get(y)??[];A.push(S),s.set(y,A)}}const f=new Map,u=new Map;for(const[d,h]of s){if(h.length!==2||o.edge_sharp?.[d])continue;const[v,p]=h,g=t[v],b=t[p];!o.s?.[g.face]||!o.s?.[b.face]||g.vertex!==t[b.next].vertex||b.vertex!==t[g.next].vertex||!o.edge_sharp&&a.has(e(g.vertex,b.vertex))||(u.set(v,b.next),f.set(b.next,v),u.set(p,g.next),f.set(g.next,p))}const m=[],l=[],i=[],c=[],_=(d,h)=>rn(Ga(o.v[t[t[d][h]].vertex],o.v[t[d].vertex]));for(let d=0;d<t.length;d++){if(l[d]!==void 0)continue;let h=d;const v=new Set([h]);for(;u.has(h)&&!v.has(u.get(h));)h=u.get(h),v.add(h);u.has(h)&&(h=Math.min(...v));const p=[h];for(;f.has(p.at(-1))&&f.get(p.at(-1))!==h;)p.push(f.get(p.at(-1)));let g=[0,0,0];if(p.length===1)g=n[t[h].face];else{for(const E of p)g=dn(g,n[t[E].face],sn(Wt(_(E,"prev"),_(E,"next"))));g=rn(g)}const b=_(h,"next"),y=p.at(-1),S=_(y,"prev"),A=Wt(b,g),T=Wt(S,g),O={normal:g,reference:[0,0,0],ortho:[0,0,0],alpha:0,beta:0};if(Math.abs(A)<jn&&Math.abs(T)<jn){const E=p.length>1?p.map(lt=>_(lt,"next")):[];E.length&&t[t[y].prev].edge!==t[h].edge&&E.push(S),O.alpha=E.length?I(E.reduce((lt,w)=>I(lt+sn(Wt(w,g))),0)/E.length):I(I(sn(A)+sn(T))/2),O.reference=rn(dn(b,g,-A));const k=g,j=O.reference;O.ortho=rn([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=rn(dn(S,g,-T)),K=Wt(O.reference,G),J=sn(K);O.beta=K<jn?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]=m.length;m.push(p),i.push(O),c.push(g)}return{corners:t,fans:m,fanOf:l,spaces:i,faceNormals:n,fanNormals:c}}function Za(o,t){if(!t[0]||o.alpha===0||o.beta===0)return o.normal;const n=I(t[0]/32767),e=I(t[1]/32767),r=I((n>0?o.alpha:I(zn-o.alpha))*n),a=I((e>0?o.beta:I(zn-o.beta))*e);let s=o.normal.map(f=>I(f*I(Math.cos(r))));return s=dn(s,o.reference,I(I(Math.sin(r))*I(Math.cos(a)))),e!==0&&(s=dn(s,o.ortho,I(I(Math.sin(r))*I(Math.sin(a))))),s}function we(o,t){if(!t)return null;const{corners:n,fans:e,spaces:r}=Ya(o);if(t.type==="INT16_2D"&&t.domain==="CORNER"){const a=new Array(n.length);for(const[s,f]of e.entries()){const u=f.reduce((l,i)=>{const c=t.data[i];return[l[0]+c[0],l[1]+c[1]]},[0,0]),m=Za(r[s],u.map(l=>Math.trunc(l/f.length)));for(const l of f)a[l]=m}return a}if(t.type==="FLOAT_VECTOR")return n.map((a,s)=>{const f=t.domain==="POINT"?a.vertex:t.domain==="FACE"?a.face:s;return t.data[f]});throw new Error(`Unsupported custom_normal attribute: ${t.type}/${t.domain}`)}const Bn={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}},Qa=1e-6;function Ka(o){const t=new x;for(let n=0;n<o.length;n++){const e=o[n],r=o[(n+1)%o.length];t.x+=(e.y-r.y)*(e.z+r.z),t.y+=(e.z-r.z)*(e.x+r.x),t.z+=(e.x-r.x)*(e.y+r.y)}return t.multiplyScalar(.5)}const Ja=(o,t,n)=>(t.x-o.x)*(n.y-o.y)-(t.y-o.y)*(n.x-o.x),Do=o=>Array.from({length:o-2},(t,n)=>[0,n+1,n+2]);function tr(o){let t=0;for(let n=0;n<o.length;n++){const e=o[n],r=o[(n+1)%o.length];t+=e.x*r.y-r.x*e.y}return t}function Fo(o,t,n){if(o.length!==t.length-2||!(Math.abs(n)>0))return!1;const e=Math.sign(n);let r=0;for(const[a,s,f]of o){const u=Ja(t[a],t[s],t[f]);if(u*e<0)return!1;r+=Math.abs(u)}return Math.abs(r-Math.abs(n))<=Qa*Math.abs(n)}function nr(o){const t=o.length;if(t<3)return{triangles:[],sound:!1,method:"fan"};if(t===3)return{triangles:[[0,1,2]],sound:!0,method:"fan"};const n=Ka(o),e=n.length();if(!(e>0)||!Number.isFinite(e))return{triangles:Do(t),sound:!1,method:"fan"};const r=n.clone().divideScalar(e),a=Math.abs(r.x)<.9?new x(1,0,0):new x(0,1,0),s=new x().crossVectors(a,r).normalize(),f=new x().crossVectors(r,s),u=o[0],m=o.map(_=>{const d=_.clone().sub(u);return new Gt(d.dot(s),d.dot(f))}),l=tr(m),i=Do(t);if(Fo(i,m,l))return{triangles:i,sound:!0,method:"fan"};let c=[];try{c=Ge.triangulateShape(m,[]).map(_=>[_[0],_[1],_[2]])}catch{return{triangles:i,sound:!1,method:"fan"}}return Fo(c,m,l)?{triangles:c,sound:!0,method:"earcut"}:{triangles:c.length>0?c:i,sound:!1,method:c.length>0?"earcut":"fan"}}const or=new Set(["FLOAT","FLOAT2","FLOAT_VECTOR","FLOAT_COLOR","BYTE_COLOR"]);function Un(o){const t=o/255;return t<.04045?t<0?0:t*(1/12.92):((t+.055)*(1/1.055))**2.4}function Wn(o,t,n){switch(o){case"FLOAT":{const e=Number(t[n]);return[e,e,e,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[Un(Number(t[n*4])),Un(Number(t[n*4+1])),Un(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 vo(o,t){return o.filter(n=>or.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 e=t(n.data,n.type),r=[0,0,0,0];return{name:n.name,domain:n.domain,read:(a,s,f)=>n.domain==="POINT"?Wn(n.type,e,a):n.domain==="CORNER"?s===void 0?r:Wn(n.type,e,s):f===void 0?r:Wn(n.type,e,f)}})}function Oe(o){const t=o.vertexCount,n=o.starts.length-1,e=o.starts,r=o.cornerVerts,a=e[n];let s=t;for(let w=0;w<n;w++)s+=(e[w+1]-e[w]-2)*3;const f=new Uint32Array(a),u=new Uint8Array(a),m=new Uint8Array(t),l=new Uint32Array(a);let i=!1;for(let w=0;w<n;w++)if(o.smooth(w)){i=!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)}`,_=new Map,d=new Set;for(const[w,V]of o.sharp)d.add(c(w,V));if(o.edges)for(const[w,V]of o.edges){if(w===V)throw new Error("Runtime mesh edge needs distinct vertices");_.set(c(w,V),-1)}const h=w=>{for(;l[w]!==w;)l[w]=l[l[w]],w=l[w];return w},v=(w,V)=>{const D=h(w),Y=h(V);l[Math.max(D,Y)]=Math.min(D,Y)};for(let w=0;w<n;w++){const V=e[w],D=e[w+1]-V,Y=o.smooth(w)?1:0;for(let Z=0;Z<D;Z++){const $=V+Z;m[r[$]]=1,f[$]=V+(Z+1)%D,u[$]=Y,l[$]=$}}for(let w=0;w<a;w++){const V=f[w],D=r[w],Y=r[V],Z=c(D,Y),$=_.get(Z);if($!==void 0&&$>=0&&u[w]&&u[$]&&!d.has(Z)){const P=f[$];v(w,r[$]===D?$:P),v(V,r[$]===D?P:$)}($===void 0||$<0||!u[$]&&u[w])&&_.set(Z,w)}const p=o.uv,g=new Float32Array(s*3),b=new Float32Array(s*2),y=new Uint32Array(s),S=(o.uvLayers??[]).map(w=>({...w,data:new Float32Array(s*2)})),A=(o.attributeLayers??[]).map(w=>({...w,data:new Float32Array(s*4)})),T=o.orco?new Float32Array(s*3):null,O=new Uint32Array(s),E=new Map,k=[],j=o.normals||o.cornerNormal?new Float32Array(s*3):null;let G=0,K=0;const J=(w,V,D,Y,Z)=>{const $=G++;for(const P of A)P.data.set(P.read(w,Y,Z),$*4);if(T)for(let P=0;P<3;P++)T[$*3+P]=o.orco[w*3+P]*.5+.5;if(y[$]=w,o.co(w).toArray(g,$*3),V&&b.set(V,$*2),D&&j.set(D,$*3),Y!==void 0)for(const P of S)P.data.set(P.read(Y),$*2);return $},lt=(w,V)=>{const D=p?.(w),Y=o.cornerNormal?[o.cornerNormal[w*3],o.cornerNormal[w*3+1],o.cornerNormal[w*3+2]]:o.normals?.[w];if(!i)return J(r[w],D,Y,w,V);const Z=`${u[w]?h(w):w}${D?`:${D[0]}:${D[1]}`:""}${Y?`:n${Y.join(":")}`:""}${S.map(P=>":"+P.read(w).join(":")).join("")}${A.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],D,Y,w,V),E.set(Z,$)),$};for(let w=0;w<n;w++){const V=K,D=e[w],Y=e[w+1]-D,Z=[];for(let B=0;B<Y;B++)Z.push(o.co(r[D+B]));for(const B of nr(Z).triangles)for(const tt of B)O[K++]=lt(D+tt,w);const $=o.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++)m[w]||J(w);return{positions:g.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:A.map(w=>({name:w.name,data:w.data.slice(0,G*4)})),orco:T?T.slice(0,G*3):null,indices:O.slice(0,K),sourceVertex:y.slice(0,G),groups:k}}function kt(o){return`blenderA_${Array.from(new TextEncoder().encode(o),t=>t.toString(16).padStart(2,"0")).join("")}`}function En(o){const t=new gn;t.setAttribute("position",new dt(o.positions,3)),t.setAttribute("uv",new dt(o.uv??new Float32Array(o.positions.length/3*2),2)),t.setIndex(new dt(o.indices,1));const n=Object.create(null);for(const[e,r]of(o.uvLayers??[]).entries()){if(e>=8)throw new Error("A Blender mesh supports at most eight UV maps");n[r.name]=e+1,t.setAttribute(`uv${e+1}`,new dt(r.data,2))}t.userData.blenderUvChannels=n;for(const e of o.attributeLayers??[])t.setAttribute(kt(e.name),new dt(e.data,4));t.userData.blenderAttributes=(o.attributeLayers??[]).map(e=>e.name),o.orco&&(t.setAttribute("blenderOrco",new dt(o.orco,3)),t.userData.blenderOrcoFromDoor=!0);for(const e of o.groups)t.addGroup(e.start,e.count,e.materialIndex);return o.normals?t.setAttribute("normal",new dt(o.normals,3)):t.computeVertexNormals(),o.sourceVertex&&t.setAttribute("blenderVertex",new dt(o.sourceVertex,1)),t}function er(o,t){const n=o.cornerTri,e=o.cornerNormal,r=o.co.length/3,a=o.corner.length,s=o.faceStart.length-1,f=o.attributes.filter(P=>P.type==="FLOAT2"&&P.domain==="CORNER"),u=o.renderUv??o.activeUv??f[0]?.name,m=f.findIndex(P=>P.name===u);if(u&&m<0)throw new Error(`Runtime UV map ${u} is missing`);const l=vo(o.attributes,P=>P),i=3+f.length*2+l.length*4,c=new Float32Array(i),_=new Float32Array(i),d=new Uint32Array(c.buffer),h=new Uint32Array(_.buffer),v=new Uint32Array(a),p=new Uint32Array(a),g=new Uint32Array(a),b=new Uint32Array(a),y=new Uint8Array(r);let S=1;for(;S<Math.max(1,a*2);)S*=2;const A=new Uint32Array(S),T=(P,B,tt,nt)=>{let ct=0;for(let rt=0;rt<3;rt++)nt[ct++]=e[P*3+rt];for(const rt of f)for(let it=0;it<2;it++)nt[ct++]=Number(rt.data[P*2+it]);for(const rt of l){const it=rt.read(tt,P,B);for(let Tt=0;Tt<4;Tt++)nt[ct++]=Number(it[Tt])}};let O=0;for(let P=0;P<s;P++)for(let B=o.faceStart[P];B<o.faceStart[P+1];B++){const tt=o.corner[B];if(tt>=r)throw new Error("Native mesh corner references a missing vertex");v[B]=P,y[tt]=1,T(B,P,tt,c);let nt=Math.imul(tt^2166136261,16777619);for(const it of d)nt=Math.imul(nt^it,16777619);const ct=nt>>>0&S-1;let rt=-1;for(let it=A[ct];it;it=b[it-1]){const Tt=it-1,Ln=g[Tt];if(o.corner[Ln]!==tt)continue;T(Ln,v[Ln],tt,_);let So=!0;for(let xn=0;xn<i;xn++)if(d[xn]!==h[xn]){So=!1;break}if(So){rt=Tt;break}}rt<0&&(rt=O++,g[rt]=B,b[rt]=A[ct],A[ct]=rt+1),p[B]=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)})),lt=l.map(P=>({name:P.name,data:new Float32Array(k*4)})),w=o.orco?new Float32Array(k*3):null,V=(P,B)=>{K[P]=B;for(let tt=0;tt<3;tt++)j[P*3+tt]=o.co[B*3+tt],w&&(w[P*3+tt]=o.orco[B*3+tt]*.5+.5)};for(let P=0;P<O;P++){const B=g[P],tt=o.corner[B];V(P,tt),T(B,v[B],tt,c),G.set(c.subarray(0,3),P*3);let nt=3;for(const ct of J)ct.data.set(c.subarray(nt,nt+2),P*2),nt+=2;for(const ct of lt)ct.data.set(c.subarray(nt,nt+4),P*4),nt+=4}let D=O;for(let P=0;P<r;P++)if(!y[P]){V(D,P);for(let B=0;B<l.length;B++)lt[B].data.set(l[B].read(P,void 0,void 0),D*4);D++}const Y=new Uint32Array(n.length),Z=[];let $=0;for(let P=0;P<s;P++){const B=o.faceStart[P],tt=o.faceStart[P+1],nt=Math.max(0,tt-B-2)*3;if($+nt>n.length)throw new Error("Native mesh triangulation is incomplete");for(let it=0;it<nt;it++){const Tt=n[$+it];if(Tt<B||Tt>=tt)throw new Error("Native triangle references a different face");Y[$+it]=p[Tt]}const ct=o.material[P],rt=Z.at(-1);rt?.materialIndex===ct?rt.count+=nt:Z.push({start:$,count:nt,materialIndex:ct}),$+=nt}if($!==n.length)throw new Error("Native mesh triangulation has extra triangles");return{positions:j,normals:G,sourceVertex:K,uv:m<0?null:J[m].data,uvLayers:J,attributeLayers:lt,orco:w,indices:Y,groups:Z,hash:t}}function Co(o,t){if(o.cornerTri&&o.cornerNormal)return er(o,t);const n=o.co.length/3,e=o.attributes.filter(h=>h.type==="FLOAT2"&&h.domain==="CORNER"),r=o.renderUv??o.activeUv??e[0]?.name,a=e.find(h=>h.name===r);if(r&&!a)throw new Error(`Runtime UV map ${r} is missing`);const s=a?a.data:null,f=o.edge.length/2,u=new Array(f);for(let h=0;h<f;h++)u[h]=[o.edge[h*2],o.edge[h*2+1]];const m=[];for(let h=0;h<f;h++)o.edgeSharp[h]===1&&m.push(u[h]);const l=o.cornerNormal?void 0:o.attributes.find(h=>h.name==="custom_normal"),i=l?{v:Array.from({length:n},(h,v)=>[o.co[v*3],o.co[v*3+1],o.co[v*3+2]]),f:Array.from({length:o.faceStart.length-1},(h,v)=>Array.from(o.corner.subarray(o.faceStart[v],o.faceStart[v+1]))),s:Array.from(o.smooth,Boolean),edge_order:u,sharp:m,face_edges:Array.from({length:o.faceStart.length-1},(h,v)=>Array.from(o.cornerEdge.subarray(o.faceStart[v],o.faceStart[v+1]))),edge_sharp:Array.from(o.edgeSharp,Boolean)}:null,c=l?{type:l.type,domain:l.domain,data:Array.from({length:l.data.length/Bn[l.type].size},(h,v)=>Array.from({length:Bn[l.type].size},(p,g)=>Number(l.data[v*Bn[l.type].size+g])))}:void 0,_=new x,d={vertexCount:n,normals:i?we(i,c):null,cornerNormal:o.cornerNormal,orco:o.orco,co:h=>_.set(o.co[h*3],o.co[h*3+1],o.co[h*3+2]).clone(),starts:o.faceStart,cornerVerts:o.corner,smooth:h=>o.smooth[h]===1,material:h=>o.material[h],edges:u,sharp:m,uv:s?h=>[s[h*2],s[h*2+1]]:null,uvLayers:e.map(h=>({name:h.name,read:v=>[Number(h.data[v*2]),Number(h.data[v*2+1])]})),attributeLayers:vo(o.attributes,h=>h)};return{...Oe(d),hash:t}}function ar(o){const t=o.v.map(i=>new x(...i)),n=i=>{const c=t[i];if(!c)throw new Error(`Runtime mesh vertex ${i} is missing`);return c},e=new Uint32Array(o.f.length+1);o.f.forEach((i,c)=>{if(i.length<3||new Set(i).size!==i.length)throw new Error("Runtime mesh face needs at least three distinct vertices");e[c+1]=e[c]+i.length});const r=new Uint32Array(e[o.f.length]);o.f.forEach((i,c)=>i.forEach((_,d)=>{n(_),r[e[c]+d]=_}));for(const[i,c]of o.edge_order??o.e??[])n(i),n(c);const a={POINT:t.length,EDGE:(o.edge_order??o.e??[]).length,FACE:o.f.length,CORNER:r.length};for(const i of o.attributes??[])if(i.domain!=="EDGE"&&i.data.length!==a[i.domain])throw new Error(`Runtime attribute ${i.name} has ${i.data.length} values for ${a[i.domain]} ${i.domain} elements`);const s=(o.attributes??[]).filter(i=>i.type==="FLOAT2"&&i.domain==="CORNER"),f=o.render_uv??o.active_uv??s[0]?.name,u=s.find(i=>i.name===f);if(f&&!u)throw new Error(`Runtime UV map ${f} is missing`);const m=u?.data,l={vertexCount:t.length,normals:we(o,o.attributes?.find(i=>i.name==="custom_normal")),co:n,starts:e,cornerVerts:r,smooth:i=>!!o.s?.[i],material:i=>o.m?.[i]??0,edges:o.edge_order??o.e??null,sharp:o.sharp??[],uv:m?i=>m[i]:null,uvLayers:s.map(i=>({name:i.name,read:c=>i.data[c]})),attributeLayers:vo(o.attributes??[],i=>Array.from(i).flat())};return En(Oe(l))}const vn=1.5707963267948966,Ht=6.283185307179586,Ae=.3183098861837067,Te=.0795774715459476,rr=.3,sr=Te,ir=3/16*Ae,ro=.8,ko=ro*ro,qt=6371,Se=100,so=qt+Se,$o=64,Lo=64,ft=256,Vt=64,lr=[1.679,1.828,1.986,1.307],fr=[.006605,.01067,.01842,.03156],cr=[3472e-28,3914e-28,1349e-28,1103e-29],ur=334.5,_r=[28722e-28,46168e-28,79706e-28,13578e-27],mr=[15908e-26,17711e-26,20942e-26,24033e-26],Vo=13681e16,dr=2e6,hr=.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]],Dn=o=>o*o,un=o=>o<0?0:o>1?1:o,Nt=(o,t,n)=>o+n*(t-o),pr=o=>Math.sqrt(Math.max(o,0)),Me=o=>[-Math.sqrt(1-o*o),0,o];function io(o,t,n,e,r,a,s){const f=o*e+t*r+n*a,u=o*o+t*t+n*n-s*s;if(u>0&&f>0)return-1;const m=f*f-u;return m<0?-1:m>=f*f?-f+Math.sqrt(m):-f-Math.sqrt(m)}const vr=o=>ir*(1+Dn(o));function gr(o){const t=1+ko+2*ro*o;return Te*(1-ko)/(t*Math.sqrt(t))}const xr=o=>Vo*(Math.exp(-o/hr)+dr/Vo);function go(o,t){let n=o%Ht;Math.abs(n)>=Math.PI&&(n-=Math.sign(n)*2*Math.PI);let e=t;return(n>=vn||n<=-vn)&&(n=Math.sign(n)*Math.PI-n,e+=Math.PI),e=e%Ht,e<0&&(e+=Ht),e=Ht-e,[n,e]}class br{constructor(t,n,e){this.air=t,this.aerosol=n,this.ozone=e,this.lut=new Float32Array(Vt*ft*4)}coefficients(t,n){const e=xr(t)*this.aerosol,r=Math.log(Math.max(t,1e-4)),a=378547397e12*Math.exp(-Dn(r-3.22261)*5.55555555-r),s=Math.exp(-.07771971*t**1.16364243);for(let f=0;f<4;f++)n[f]=_r[f]*e,n[4+f]=mr[f]*e,n[8+f]=cr[f]*ur*a*this.ozone,n[12+f]=fr[f]*s*this.air}transmittance(t,n,e){const[r,a,s]=Me(t),f=Nt(qt,so,n),m=io(0,0,f,r,a,s,so)/$o,l=[0,0,0,0],i=new Float64Array(16);for(let c=0;c<$o;c++){const _=(c+.5)*m,d=r*_,h=a*_,v=f+s*_,p=Math.max(Math.hypot(d,h,v)-qt,0);this.coefficients(p,i);for(let g=0;g<4;g++)l[g]+=(i[g]+i[4+g]+i[8+g]+i[12+g])*m}for(let c=0;c<4;c++)e[c]=Math.exp(-l[c])}precompute(){const t=new Float64Array(4);for(let n=0;n<Vt;n++)for(let e=0;e<ft;e++){const r=e/(ft-1),a=n/(Vt-1);this.transmittance(r*2-1,a,t);const s=(n*ft+e)*4;for(let f=0;f<4;f++)this.lut[s+f]=t[f]}}lookup(t,n,e){const r=(ft-1)*un(t*.5+.5),a=(Vt-1)*un(n),s=Math.trunc(r),f=Math.trunc(a),u=Math.min(s+1,ft-1),m=Math.min(f+1,Vt-1),l=r-s,i=a-f,c=(f*ft+s)*4,_=(f*ft+u)*4,d=(m*ft+s)*4,h=(m*ft+u)*4;for(let v=0;v<4;v++)e[v]=Nt(Nt(this.lut[c+v],this.lut[_+v],l),Nt(this.lut[d+v],this.lut[h+v],l),i)}lookupAtGround(t,n){const e=(ft-1)*un(t*.5+.5),r=Math.trunc(e),a=Math.min(r+1,ft-1),s=e-r;for(let f=0;f<4;f++)n[f]=Nt(this.lut[r*4+f],this.lut[a*4+f],s)}lookupToSun(t,n){const e=(Vt-1)*un(t),r=Math.trunc(e),a=Math.min(r+1,Vt-1),s=e-r,f=ft-1;for(let u=0;u<4;u++)n[u]=Nt(this.lut[(r*ft+f)*4+u],this.lut[(a*ft+f)*4+u],s)}inscattering(t,n,e,r,a,s,f,u,m){const l=-(a*t[0]+s*t[1]+f*t[2]),i=vr(l),c=gr(l),_=u/Lo,d=new Float64Array(16),h=new Float64Array(4),v=new Float64Array(4),p=new Float64Array(4),g=new Float64Array(4),b=new Float64Array(4),y=[0,0,0,0],S=[1,1,1,1];for(let A=0;A<Lo;A++){const T=(A+.5)*_,O=n+a*T,E=e+s*T,k=r+f*T,j=Math.hypot(O,E,k),G=Math.max(j-qt,0),K=G/Se,J=(O*t[0]+E*t[1]+k*t[2])/j;this.coefficients(G,d),this.lookup(J,K,h);const lt=Ht*(1-pr(1-Dn(qt/j)));this.lookupAtGround(J,p),this.lookupToSun(0,g),this.lookupToSun(K,b);const w=1/(1+5*Math.exp(-17.92*J)),V=[.217,.347,.594,1];for(let D=0;D<4;D++){const Y=g[D]/b[D],Z=sr*lt*(rr*Ae)*p[D]*Y*J;v[D]=.02*V[D]*w+Z}for(let D=0;D<4;D++){const Y=d[D]+d[4+D]+d[8+D]+d[12+D],Z=lr[D]*(d[12+D]*(i*h[D]+v[D])+d[4+D]*(c*h[D]+v[D])),$=Math.exp(-_*Y),P=Math.max(Y,1e-7);y[D]+=S[D]*((Z-Z*$)/P),S[D]*=$}}for(let A=0;A<4;A++)m[A]=y[A]}}const ht=512,Jt=256;function Pe(o,t){const n=new br(o.airDensity,o.aerosolDensity,o.ozoneDensity);n.precompute();const e=Math.min(Math.max(o.altitude,1),99999)/1e3,r=Me(Math.cos(vn-t)),a=new Float32Array(ht*Jt*3),s=ht/2,f=new Float64Array(4);for(let u=0;u<Jt;u++)for(let m=0;m<s;m++){const l=(m+.5)/ht,i=(u+.5)/Jt,c=Ht*l,_=i*2-1,d=Math.sign(_)*Dn(_)*vn,h=Math.cos(d)*Math.cos(c),v=Math.cos(d)*Math.sin(c),p=Math.sin(d),g=qt+e,b=io(0,0,g,h,v,p,so),y=io(0,0,g,h,v,p,qt),S=y<0?b:y;n.inscattering(r,0,0,g,h,v,p,S,f);let A=0,T=0,O=0;for(let j=0;j<4;j++)A+=Hn[j][0]*f[j],T+=Hn[j][1]*f[j],O+=Hn[j][2]*f[j];const E=(u*ht+m)*3;a[E]=A,a[E+1]=T,a[E+2]=O;const k=(u*ht+(ht-m-1))*3;a[k]=A,a[k+1]=T,a[k+2]=O}return a}function yr(o){const[t]=go(o.sunElevation,o.sunRotation);return Pe(o,t)}function xo(o){const[t]=go(o.sunElevation,o.sunRotation);return JSON.stringify([t,o.altitude,o.airDensity,o.aerosolDensity,o.ozoneDensity])}const wr=6,Qt=new Map;function Or(o){return Qt.has(xo(o))}function Ee(o,t){Qt.set(xo(o),t),Qt.size>wr&&Qt.delete(Qt.keys().next().value)}function Ar(o){const[t,n]=go(o.sunElevation,o.sunRotation),e=xo(o);let r=Qt.get(e);r===void 0&&(r=Pe(o,t),Ee(o,r));const a=new x;return s=>{const f=Math.hypot(s.x,s.y),u=Math.atan2(s.z,f);let l=(Math.atan2(s.x,s.y)+Math.PI+n)/Ht;l-=Math.floor(l);const i=Math.abs(u),c=un(Math.sqrt(i/vn)*Math.sign(u)*.5+.5),_=l*ht-.5,d=c*Jt-.5,h=Math.floor(_),v=Math.floor(d),p=_-h,g=d-v,b=k=>(k%ht+ht)%ht,y=k=>k<0?0:k>Jt-1?Jt-1:k,S=b(h),A=b(h+1),T=y(v),O=y(v+1),E=[0,0,0];for(let k=0;k<3;k++){const j=Nt(r[(T*ht+S)*3+k],r[(T*ht+A)*3+k],p),G=Nt(r[(O*ht+S)*3+k],r[(O*ht+A)*3+k],p);E[k]=Nt(j,G,g)}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,Tr=0;const _n=new Map;function Sr(){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=o=>{const{id:t,pixels:n,error:e}=o.data,r=_n.get(t);r&&(_n.delete(t),n?r.resolve(n):r.reject(new Error(e??"sky worker returned nothing")))},zt.onerror=o=>{const t=new Error(`sky worker failed: ${o.message||"unknown error"}`);for(const n of _n.values())n.reject(t);_n.clear(),zt?.terminate(),zt=null,bn=!0},zt}function Mr(o){const t=Sr();if(!t)return Promise.resolve(yr(o));const n=Tr++,e={id:n,parameters:o};return new Promise((r,a)=>{_n.set(n,{resolve:r,reject:a}),t.postMessage(e)})}function Pr(o,t,n,e={}){switch(e.type??"LINEAR"){case"QUADRATIC":{const r=Math.max(o,0);return r*r}case"EASING":{const r=Math.min(1,Math.max(0,o));return r*r*(3-2*r)}case"DIAGONAL":return(o+t)/2;case"SPHERICAL":return Math.max(.999999-Math.hypot(o,t,n),0);case"QUADRATIC_SPHERE":{const r=Math.max(.999999-Math.hypot(o,t,n),0);return r*r}case"RADIAL":return Math.atan2(t,o)/(2*Math.PI)+.5;default:return o}}const qn=(o,t)=>t!==0?o/t:0,jo=o=>Math.min(1,Math.max(-1,o)),Bo=(o,t,n)=>{const e=n!==0?Math.max(n-Math.abs(o-t),0)/n:0;return Math.min(o,t)-e*e*e*n/6},Ne={ADD:(o,t)=>o+t,SUBTRACT:(o,t)=>o-t,MULTIPLY:(o,t)=>o*t,DIVIDE:qn,POWER:(o,t)=>t===0?1:o===0||o<0&&!Number.isInteger(t)?0:o**t,LOGARITHM:(o,t)=>o<=0||t<=0?0:qn(Math.log(o),Math.log(t)),SQRT:o=>Math.sqrt(Math.max(o,0)),INVERSE_SQRT:o=>o>0?1/Math.sqrt(o):0,ABSOLUTE:Math.abs,RADIANS:o=>o*Math.PI/180,DEGREES:o=>o*180/Math.PI,MINIMUM:(o,t)=>Math.min(o,t),MAXIMUM:(o,t)=>Math.max(o,t),LESS_THAN:(o,t)=>+(o<t),GREATER_THAN:(o,t)=>+(o>t),ROUND:o=>Math.floor(o+.5),FLOOR:Math.floor,CEIL:Math.ceil,FRACT:o=>o-Math.floor(o),MODULO:(o,t)=>t!==0?o%t:0,FLOORED_MODULO:(o,t)=>t!==0?o-Math.floor(o/t)*t:0,TRUNC:Math.trunc,SNAP:(o,t)=>Math.floor(qn(o,t))*t,WRAP:(o,t,n)=>t!==n?o-(t-n)*Math.floor((o-n)/(t-n)):n,PINGPONG:(o,t)=>{if(t===0)return 0;const n=(o-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:o=>Math.asin(jo(o)),ARCCOSINE:o=>Math.acos(jo(o)),ARCTANGENT:Math.atan,ARCTAN2:(o,t)=>o===0&&t===0?0:Math.atan2(o,t),SIGN:Math.sign,EXPONENT:Math.exp,COMPARE:(o,t,n)=>+(o===t||Math.abs(o-t)<=Math.max(n,2**-23)),MULTIPLY_ADD:(o,t,n)=>o*t+n,SMOOTH_MIN:Bo,SMOOTH_MAX:(o,t,n)=>-Bo(-o,-t,n)};function at(o,t){if(typeof o=="number")return()=>o;if(Array.isArray(o)){const r=new x(...o);return()=>r}if(o.kind==="direction")return r=>r;if(o.kind==="window"){if(!t)throw new Error("World Window coordinates need a render camera");return t}if(o.kind==="gradient"){const r=at(o.vector,t),a={type:o.gradient_type},s=new x;return f=>{const u=r(f),m=typeof u=="number"?u:u.x,l=typeof u=="number"?u:u.y,i=typeof u=="number"?u:u.z,c=xt.clamp(Pr(m,l,i,a),0,1);return o.output==="Fac"?c:s.setScalar(c)}}if(o.kind==="to_float"){const r=at(o.value,t);return a=>{const s=r(a);return typeof s=="number"?s:Math.fround(o.source_type==="RGBA"?s.x*.212639+s.y*.7151687+s.z*.0721923:(s.x+s.y+s.z)/3)}}if(o.kind==="math"){const r=o.inputs.map(f=>at(f,t)),a=Ne[o.operation],s=(f,u)=>{const m=r[f]?.(u)??0;if(typeof m!="number")throw new Error("World Math needs scalar inputs");return Math.fround(m)};return f=>{const u=Math.fround(a(s(0,f),s(1,f),s(2,f)));return o.clamp?xt.clamp(u,0,1):u}}if(o.kind==="mix_color"){const r=at(o.factor,t),a=at(o.a,t),s=at(o.b,t),f=new x,u=new x;return m=>{const l=r(m);if(typeof l!="number")throw new Error("World color Mix needs a scalar factor");const i=a(m);typeof i=="number"?f.setScalar(i):f.copy(i);const c=s(m);return typeof c=="number"?u.setScalar(c):u.copy(c),f.lerp(u,o.clamp_factor?xt.clamp(l,0,1):l),o.clamp_result&&f.clampScalar(0,1),f}}if(o.kind==="sky"){const r=Ar({sunElevation:o.sun_elevation,sunRotation:o.sun_rotation,altitude:o.altitude,airDensity:o.air_density,aerosolDensity:o.aerosol_density,ozoneDensity:o.ozone_density});return a=>r(a)}if(o.kind==="mapping"){const r=at(o.vector,t),a=new x(...o.location),s=new x(...o.scale),f=new At().setFromEuler(new Xe(o.rotation[0],o.rotation[1],o.rotation[2],"ZYX")),u=f.clone().invert(),m=new x(...o.scale.map(i=>i===0?0:1/i)),l=new x;return i=>{const c=r(i);switch(typeof c=="number"?l.setScalar(c):l.copy(c),o.vector_type??"POINT"){case"TEXTURE":return l.sub(a).applyQuaternion(u).multiply(m);case"VECTOR":return l.multiply(s).applyQuaternion(f);case"NORMAL":return l.multiply(m).applyQuaternion(f).normalize();case"POINT":return l.multiply(s).applyQuaternion(f).add(a)}}}if(o.kind==="map_range"){const r=at(o.value,t),a=at(o.from_min,t),s=at(o.from_max,t),f=at(o.to_min,t),u=at(o.to_max,t),m=at(o.steps,t),l=(_,d)=>{const h=_(d);if(typeof h!="number")throw new Error("World Map Range needs scalar inputs");return h},i=o.interpolation,c=o.clamp;return _=>{const d=l(r,_),h=l(a,_),v=l(s,_),p=l(f,_),g=l(u,_);if(h===v)return 0;let b;if(i==="STEPPED"){const S=l(m,_),A=(d-h)/(v-h);b=S>0?Math.floor(A*(S+1))/S:0}else if(i==="SMOOTHSTEP"||i==="SMOOTHERSTEP"){const S=xt.clamp((d-Math.min(h,v))/(Math.max(h,v)-Math.min(h,v)),0,1),A=i==="SMOOTHSTEP"?S*S*(3-2*S):S*S*S*(S*(S*6-15)+10);b=h>v?1-A:A}else b=(d-h)/(v-h);const y=p+b*(g-p);return c?p>g?xt.clamp(y,g,p):xt.clamp(y,p,g):y}}if(o.kind==="separate"){const r=at(o.vector,t);return a=>{const s=r(a);return typeof s=="number"?s:s.getComponent(o.axis)}}const n=at(o.factor,t),e=new x;return r=>{const a=n(r);if(typeof a!="number")throw new Error("World ColorRamp needs a scalar factor");const s=xt.clamp(a,0,1)*256,f=Math.floor(s),u=o.colors[f],m=o.colors[Math.min(f+1,256)],l=o.interpolate?s-f:0;return e.set(xt.lerp(u[0],m[0],l),xt.lerp(u[1],m[1],l),xt.lerp(u[2],m[2],l))}}function Er(o,t,n,e){const r=new Float32Array(t*n*3),a=at(o,e),s=new x;for(let f=0;f<n;f++){const u=((f+.5)/n-.5)*Math.PI;for(let m=0;m<t;m++){const l=((m+.5)/t-.5)*2*Math.PI;s.set(Math.cos(u)*Math.cos(l),-Math.cos(u)*Math.sin(l),Math.sin(u));const i=a(s),c=(f*t+m)*3;r[c]=typeof i=="number"?i:i.x,r[c+1]=typeof i=="number"?i:i.y,r[c+2]=typeof i=="number"?i:i.z}}return r}function Uo(o){const t=[],n=e=>{if(!(typeof e=="number"||Array.isArray(e)))switch(e.kind){case"sky":t.push({sunElevation:e.sun_elevation,sunRotation:e.sun_rotation,altitude:e.altitude,airDensity:e.air_density,aerosolDensity:e.aerosol_density,ozoneDensity:e.ozone_density});return;case"mapping":case"gradient":case"separate":n(e.vector);return;case"ramp":n(e.factor);return;case"mix_color":n(e.factor),n(e.a),n(e.b);return;case"math":e.inputs.forEach(n);return;case"to_float":n(e.value);return;case"map_range":n(e.value),n(e.from_min),n(e.from_max),n(e.to_min),n(e.to_max),n(e.steps);return;default:return}};return n(o),t}function Ft(o){if(typeof o=="number"||Array.isArray(o))return!1;switch(o.kind){case"window":return!0;case"mapping":case"gradient":case"separate":return Ft(o.vector);case"ramp":return Ft(o.factor);case"mix_color":return[o.factor,o.a,o.b].some(Ft);case"math":return o.inputs.some(Ft);case"to_float":return Ft(o.value);case"map_range":return[o.value,o.from_min,o.from_max,o.to_min,o.to_max,o.steps].some(Ft);default:return!1}}function Nr(o,t,n,e){e.updateMatrixWorld();const r=new Float32Array(t*n*3),a=new x,s=at(o,()=>a),f=new x,u=e.getWorldPosition(new x),m=e.getWorldDirection(new x);for(let l=0;l<n;l++)for(let i=0;i<t;i++){const c=(i+.5)/t,_=(l+.5)/n;a.set(c,_,0),e.isOrthographicCamera?f.copy(m):f.set(c*2-1,_*2-1,.5).unproject(e).sub(u).normalize(),f.set(f.x,-f.z,f.y);const d=s(f),h=(l*t+i)*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 et=N().finite(),Rr=M({type:q(["POINT","SUN","SPOT","AREA"]),color:L([et,et,et]),energy:et,use_shadow:Q().default(!0),radius:et.optional(),spot_size:et.optional(),spot_blend:et.optional(),shape:q(["SQUARE","RECTANGLE","DISK","ELLIPSE"]).optional(),size:et.optional(),size_y:et.optional()}).strict();let lo;function Ir(){return lo??=Pa(async()=>{const{RectAreaLightUniformsLib:o}=await import("./RectAreaLightUniformsLib-DpPyArRG.js");return{RectAreaLightUniformsLib:o}},__vite__mapDeps([0,1,2])).then(({RectAreaLightUniformsLib:o})=>{o.init(),wt()}),lo}function zr(){return lo??Promise.resolve()}const Dr=o=>{const t=o.size??0,n=o.size_y??t;if(o.shape==="RECTANGLE")return[t,n];if(o.shape==="DISK"){const e=Math.sqrt(Math.PI*t*t/4);return[e,e]}if(o.shape==="ELLIPSE"){const e=Math.sqrt(Math.PI/4);return[t*e,n*e]}return[t,t]};function Fr(o,t){const n=(s,f)=>t&&f(t)?t:new s;if(o.type==="SUN"){const s=n(ue,f=>f.isDirectionalLight);return s.intensity=o.energy,s.color.setRGB(o.color[0],o.color[1],o.color[2],vt),s.castShadow=o.use_shadow,s}if(o.type==="POINT"){const s=n(Jn,f=>f.isPointLight);return s.intensity=o.energy/(4*Math.PI),s.distance=0,s.decay=2,s.color.setRGB(o.color[0],o.color[1],o.color[2],vt),s.castShadow=o.use_shadow,s}if(o.type==="SPOT"){const s=n(to,f=>f.isSpotLight);return s.intensity=o.energy/(4*Math.PI),s.distance=0,s.decay=2,s.angle=(o.spot_size??0)/2,s.penumbra=o.spot_blend??0,s.color.setRGB(o.color[0],o.color[1],o.color[2],vt),s.castShadow=o.use_shadow,s}Ir();const e=n(Pn,s=>s.isRectAreaLight),[r,a]=Dr(o);return e.width=r,e.height=a,e.intensity=o.energy/(Math.max(r*a,Number.MIN_VALUE)*Math.PI),e.color.setRGB(o.color[0],o.color[1],o.color[2],vt),e}function Cr(o,t,n){if(!o.castShadow||n<=0)return;const r=o.getWorldPosition(new x).distanceTo(t),a=o.shadow;if(!a)return;const s=a.camera;s.near=Math.max(n*.001,r-n),s.far=r+n,o.isDirectionalLight&&(s.left=-n,s.right=n,s.top=n,s.bottom=-n),s.updateProjectionMatrix()}function kr(o,t){o.position.set(0,0,0);const n=o;o.isRectAreaLight||n.target&&n.target.parent!==t&&(n.target.position.set(0,0,-1),t.add(n.target))}const bo=[{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}],Wo=.69;class $r{constructor(){this.group=new st,this.lights=[],this.group.name="BlenderSolidStudio";const t=new ce;t.name="BlenderSolidStudioTarget",this.group.add(t);const n=new Ot(0,0,0);for(const[r,a]of bo.entries()){const s=(1+a.smooth)**2,f=new ue(16777215,Math.PI*Wo/s);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/s,n.g+=a.diffuse[1]*a.smooth/s,n.b+=a.diffuse[2]*a.smooth/s}const e=new Ye(16777215,Math.PI*Wo);e.name="BlenderSolidWrapFill",e.color.copy(n),this.group.add(e),this.lights.push(e)}setRendered(t){this.group.visible=!t}dispose(){for(const t of this.lights)t.dispose();this.group.clear()}}const Zt=L([et,et,et]),X=be(()=>Lt([et,Zt,M({kind:W("direction")}).strict(),M({kind:W("window")}).strict(),M({kind:W("gradient"),gradient_type:q(["LINEAR","QUADRATIC","EASING","DIAGONAL","SPHERICAL","QUADRATIC_SPHERE","RADIAL"]),output:q(["Fac","Color"]),vector:X}).strict(),M({kind:W("to_float"),source_type:q(["RGBA","VECTOR"]),value:X}).strict(),M({kind:W("math"),operation:q(Object.keys(Ne)),clamp:Q(),inputs:F(X).min(1).max(3)}).strict(),M({kind:W("mix_color"),factor:X,a:X,b:X,clamp_factor:Q(),clamp_result:Q()}).strict(),M({kind:W("mapping"),vector_type:q(["POINT","TEXTURE","VECTOR","NORMAL"]).optional(),vector:X,location:Zt,rotation:Zt,scale:Zt}).strict(),M({kind:W("separate"),vector:X,axis:N().int().min(0).max(2)}).strict(),M({kind:W("ramp"),factor:X,colors:F(Zt).length(257),interpolate:Q()}).strict(),M({kind:W("map_range"),interpolation:q(["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:W("sky"),sun_elevation:et,sun_rotation:et,altitude:et,air_density:et,aerosol_density:et,ozone_density:et}).strict()])),Ho=M({color:Zt,strength:et,shader:X.optional()}),Lr=Ho.extend({volume:F(M({kind:q(["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:Ho.strict().optional()}).strict(),Vr=4,ln=new Map,Gn=new Set;function qo(o,t,n){const a=Ft(o);if(a&&!n)throw new Error("World Window coordinates need a render camera");n?.updateMatrixWorld();const s=JSON.stringify([o,a?[n.matrixWorld.elements,n.projectionMatrix.elements]:null]),f=ln.get(s);if(f!==void 0)return fo(f,t,256,128);const u=new x,m=new Cn,l=n?new H().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse):null,i=n?.getWorldPosition(new x),_=Er(o,256,128,a?d=>(u.set(d.x,d.z,-d.y),n.isPerspectiveCamera&&u.add(i),m.set(u.x,u.y,u.z,1).applyMatrix4(l),m.w===0?u.set(0,0,0):u.set(m.x/m.w*.5+.5,m.y/m.w*.5+.5,0)):void 0);return ln.set(s,_),ln.size>Vr&&ln.delete(ln.keys().next().value),fo(_,t,256,128)}function jr(o,t,n,e){const r=cn.toHalfFloat(1);for(let a=0;a<e;a++)o[a*4]=cn.toHalfFloat(t[a*3]*n),o[a*4+1]=cn.toHalfFloat(t[a*3+1]*n),o[a*4+2]=cn.toHalfFloat(t[a*3+2]*n),o[a*4+3]=r}function fo(o,t,n,e){const r=new Uint16Array(n*e*4);jr(r,o,t,n*e);const a=new kn(r,n,e,$n,ho);return a.mapping=Qe,a.colorSpace=vt,a.minFilter=Xt,a.magFilter=Xt,a.needsUpdate=!0,a}class yo{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,e){if(this.clear(),this.pending=null,!n)return;const r=yo.sceneOf(t);if(!r)return;this.applied={scene:r,background:r.background,environment:r.environment};const a=n.shader??n.color,s=this.generation,u=[...Uo(a),...n.lighting?Uo(n.lighting.shader??n.lighting.color):[]].filter(l=>!Or(l));if(u.length===0){this.compose(r,n,a,e);return}const m=(async()=>{const l=await Promise.all(u.map(Mr));u.forEach((i,c)=>{Ee(i,l[c])}),!(this.generation!==s||this.applied?.scene!==r)&&(this.compose(r,n,a,e),wt())})();this.pending=m,Gn.add(m),m.then(()=>Gn.delete(m),()=>Gn.delete(m))}compose(t,n,e,r){if(this.texture=qo(e,n.strength,r),Ft(e)){if(!r)throw new Error("World Window coordinates need a render camera");this.screenTexture=fo(Nr(e,512,512,r),n.strength,512,512),this.screenTexture.mapping=Ze,t.background=this.screenTexture}else if(r&&r.isOrthographicCamera){const s=r.getWorldDirection(new x);s.set(s.x,-s.z,s.y);const f=at(n.shader??n.color)(s);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?qo(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 Re(o){return[o.min.x,o.max.x].flatMap(t=>[o.min.y,o.max.y].flatMap(n=>[o.min.z,o.max.z].map(e=>new x(t,n,e))))}function Br(o,t){if(o.isEmpty()||!t.intersectsBox(o))return[];const n=Re(o);if(n.every(l=>t.containsPoint(l)))return n;const e=[...t.planes,new Bt(new x(1,0,0),-o.min.x),new Bt(new x(-1,0,0),o.max.x),new Bt(new x(0,1,0),-o.min.y),new Bt(new x(0,-1,0),o.max.y),new Bt(new x(0,0,1),-o.min.z),new Bt(new x(0,0,-1),o.max.z)],r=[],a=new x,s=new x,f=new x,u=new x,m=Math.max(1,o.min.length(),o.max.length())*1e-8;for(let l=0;l<e.length;l++)for(let i=l+1;i<e.length;i++)for(let c=i+1;c<e.length;c++){const _=e[l],d=e[i],h=e[c];a.crossVectors(d.normal,h.normal);const v=_.normal.dot(a);Math.abs(v)<1e-12||(s.crossVectors(h.normal,_.normal),f.crossVectors(_.normal,d.normal),u.copy(a).multiplyScalar(-_.constant).addScaledVector(s,-d.constant).addScaledVector(f,-h.constant).divideScalar(v),e.every(p=>p.distanceToPoint(u)>=-m)&&r.push(u.clone()))}return r}function Ur(o,t,n){if(!o.castShadow||!t.length)return;o.shadow.updateMatrices(o);const e=o.shadow.camera,r=e.matrixWorldInverse,a=new pn().setFromPoints(t.map(c=>c.clone().applyMatrix4(r))),s=a.getSize(new x),f=Math.max(s.length()*1e-6,Number.EPSILON),u=2+2*Math.SQRT2,m=Math.max(s.x,s.y,f)/Math.max(1,Math.min(o.shadow.mapSize.x,o.shadow.mapSize.y)-2*u),l=2*Math.SQRT2*m,i=u*m;a.min.x-=i,a.min.y-=i,a.max.x+=i,a.max.y+=i;for(const c of n){if(c.isEmpty())continue;const _=new pn().setFromPoints(Re(c).map(d=>d.applyMatrix4(r)));_.max.x<a.min.x||_.min.x>a.max.x||_.max.y<a.min.y||_.min.y>a.max.y||(a.min.z=Math.min(a.min.z,_.min.z),a.max.z=Math.max(a.max.z,_.max.z))}e.left=a.min.x,e.right=a.max.x,e.bottom=a.min.y,e.top=a.max.y,e.near=-a.max.z-l-f,e.far=-a.min.z+l+f,e.updateProjectionMatrix(),o.shadow.normalBias=l}const tn=N().finite(),Go=L([tn,tn,tn]),Ie=M({min:L([N().int(),N().int(),N().int()]),max:L([N().int(),N().int(),N().int()]),density:F(tn),voxelSize:tn.positive(),color:Go,emission:Go,densityScale:tn.nonnegative()}).strict();function Wr(o){const t=o.max.map((l,i)=>l-o.min[i]+1);if(t.some(l=>l<=0)||t.reduce((l,i)=>l*i,1)!==o.density.length)throw new Error("Volume density dimensions do not match the evaluated grid");const n=new Ke(new Float32Array(o.density),t[0],t[1],t[2]);n.format=Je,n.type=_e,n.minFilter=n.magFilter=Xt,n.unpackAlignment=1,n.needsUpdate=!0;const e=new x(...o.min).addScalar(-.5).multiplyScalar(o.voxelSize),r=new x(t[0],t[1],t[2]).multiplyScalar(o.voxelSize),a=new ta(r.x,r.y,r.z),s=a.getAttribute("position");for(let l=0;l<s.count;l++)s.setXYZ(l,e.x+(s.getX(l)>0?r.x:0),e.y+(s.getY(l)>0?r.y:0),e.z+(s.getZ(l)>0?r.z:0));s.needsUpdate=!0,a.computeBoundingBox(),a.computeBoundingSphere();const f=new mo({glslVersion:oa,side:na,transparent:!0,depthWrite:!1,premultipliedAlpha:!0,uniforms:{densityGrid:{value:n},minimum:{value:e},extent:{value:r},voxelSize:{value:o.voxelSize},densityScale:{value:o.densityScale},volumeColor:{value:new x(...o.color)},emission:{value:new x(...o.emission)},cameraLocal:{value:new x},rayLocal:{value:new x},orthographic:{value:!1},worldScale:{value:new fe}},vertexShader:`
20
20
  out vec3 localPosition;
21
21
  void main() {
22
22
  localPosition = position;
@@ -58,7 +58,7 @@ import{a as ae,b as re,L as ie}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),m=new q;return u.onBeforeRender=(l,s,c)=>{m.copy(u.matrixWorld).invert(),f.uniforms.cameraLocal.value.setFromMatrixPosition(c.matrixWorld).applyMatrix4(m),c.getWorldDirection(f.uniforms.rayLocal.value).transformDirection(m),f.uniforms.orthographic.value=!!c.isOrthographicCamera,f.uniforms.worldScale.value.setFromMatrix4(u.matrixWorld)},f.addEventListener("dispose",()=>n.dispose()),u}const Wr=`#define constexpr const
61
+ }`}),u=new Rt(a,f),m=new H;return u.onBeforeRender=(l,i,c)=>{m.copy(u.matrixWorld).invert(),f.uniforms.cameraLocal.value.setFromMatrixPosition(c.matrixWorld).applyMatrix4(m),c.getWorldDirection(f.uniforms.rayLocal.value).transformDirection(m),f.uniforms.orthographic.value=!!c.isOrthographicCamera,f.uniforms.worldScale.value.setFromMatrix4(u.matrixWorld)},f.addEventListener("dispose",()=>n.dispose()),u}const Hr=`#define constexpr const
62
62
  #define bool32_t bool
63
63
  #define bool2 bvec2
64
64
  #define bool3 bvec3
@@ -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
- }`}},Go=N().finite(),Xn=H(["float","vec2","vec3","vec4"]),Ie=Lt([Go,D(Go)]),ze=L([R(),N().int().nonnegative()]),En=Lt([M({value:Ie}).strict(),M({link:ze}).strict()]),Hr=["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"],qr=M({type:H(Hr),props:bt(R(),be()),inputs:D(Lt([M({value:Ie,id:R(),gpu:Xn,enabled:Q()}).strict(),M({link:ze,id:R(),gpu:Xn,enabled:Q()}).strict()])),outputs:D(M({id:R(),gpu:Xn.or(W("closure")).nullable()}).strict())}).strict(),mn=xe(()=>Lt([M({principled:W(!0)}).strict(),M({emission:L([En,En])}).strict(),M({transparent:N()}).strict(),M({none:W(!0)}).strict(),M({mix:L([En,mn,mn])}).strict(),M({add:L([mn,mn])}).strict()])),Gr=M({surface:H(["ShaderNodeBsdfPrincipled","ShaderNodeEmission","closure"]),inputs:bt(R(),En),closure:mn.optional(),nodes:bt(R(),qr)}).strict();function Xr(o){const t=o.inputs.Alpha,n=e=>"transparent"in e||"mix"in e&&(n(e.mix[1])||n(e.mix[2]))||"add"in e&&(n(e.add[0])||n(e.add[1]));return t!==void 0&&"link"in t||o.closure!==void 0&&n(o.closure)}const Fe="vec3(0.2126729, 0.7151522, 0.0721750)",Yr=o=>o==="float"?1:Number(o[3]);function Zr(o,t){const n=typeof t=="number"?[t]:t,e=Yr(o);return Array.from({length:e},(r,a)=>n[a]??(a===3?1:0))}function Qr(o,t,n){if(t===n)return o;const e=a=>a==="float"?"float":`float${a[3]}`,r=t==="vec4"&&n==="float"?`, ${Fe}`:"";return`${e(n)}_from_${e(t)}(${o}${r})`}const Kr={INVERSE_SQRT:"math_inversesqrt",FRACT:"math_fraction",SMOOTH_MIN:"math_smoothmin",SMOOTH_MAX:"math_smoothmax"},Jr={CROSS_PRODUCT:"vector_math_cross",DOT_PRODUCT:"vector_math_dot"},Xo={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"},ti={MULTIFRACTAL:"multi_fractal",FBM:"fbm",HYBRID_MULTIFRACTAL:"hybrid_multi_fractal",RIDGED_MULTIFRACTAL:"ridged_multi_fractal",HETERO_TERRAIN:"hetero_terrain"},ni={F1:"f1",F2:"f2",SMOOTH_F1:"smooth_f1",DISTANCE_TO_EDGE:"distance_to_edge",N_SPHERE_RADIUS:"n_sphere_radius"},oi={EUCLIDEAN:0,MANHATTAN:1,CHEBYCHEV:2,MINKOWSKI:3},ei=(()=>{const o=new Map;for(const[t,n]of Object.entries(co))for(const e of n.code.matchAll(/^(?:void|float\d?)\s+([A-Za-z_]\w*)\s*\(/gm))o.has(e[1])||o.set(e[1],t);return o})();function C(o,t){if(!(t in o.props))throw new Error(`${o.type} arrived without its '${t}' property`);return o.props[t]}const ai=`
6882
+ }`}},Xo=N().finite(),Xn=q(["float","vec2","vec3","vec4"]),ze=Lt([Xo,F(Xo)]),De=L([R(),N().int().nonnegative()]),Nn=Lt([M({value:ze}).strict(),M({link:De}).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"],Gr=M({type:q(qr),props:bt(R(),ye()),inputs:F(Lt([M({value:ze,id:R(),gpu:Xn,enabled:Q()}).strict(),M({link:De,id:R(),gpu:Xn,enabled:Q()}).strict()])),outputs:F(M({id:R(),gpu:Xn.or(W("closure")).nullable()}).strict())}).strict(),mn=be(()=>Lt([M({principled:W(!0)}).strict(),M({emission:L([Nn,Nn])}).strict(),M({transparent:N()}).strict(),M({none:W(!0)}).strict(),M({mix:L([Nn,mn,mn])}).strict(),M({add:L([mn,mn])}).strict()])),Xr=M({surface:q(["ShaderNodeBsdfPrincipled","ShaderNodeEmission","closure"]),inputs:bt(R(),Nn),closure:mn.optional(),nodes:bt(R(),Gr)}).strict();function Yr(o){const t=o.inputs.Alpha,n=e=>"transparent"in e||"mix"in e&&(n(e.mix[1])||n(e.mix[2]))||"add"in e&&(n(e.add[0])||n(e.add[1]));return t!==void 0&&"link"in t||o.closure!==void 0&&n(o.closure)}const Fe="vec3(0.2126729, 0.7151522, 0.0721750)",Zr=o=>o==="float"?1:Number(o[3]);function Qr(o,t){const n=typeof t=="number"?[t]:t,e=Zr(o);return Array.from({length:e},(r,a)=>n[a]??(a===3?1:0))}function Kr(o,t,n){if(t===n)return o;const e=a=>a==="float"?"float":`float${a[3]}`,r=t==="vec4"&&n==="float"?`, ${Fe}`:"";return`${e(n)}_from_${e(t)}(${o}${r})`}const Jr={INVERSE_SQRT:"math_inversesqrt",FRACT:"math_fraction",SMOOTH_MIN:"math_smoothmin",SMOOTH_MAX:"math_smoothmax"},ts={CROSS_PRODUCT:"vector_math_cross",DOT_PRODUCT:"vector_math_dot"},Yo={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"},ns={MULTIFRACTAL:"multi_fractal",FBM:"fbm",HYBRID_MULTIFRACTAL:"hybrid_multi_fractal",RIDGED_MULTIFRACTAL:"ridged_multi_fractal",HETERO_TERRAIN:"hetero_terrain"},os={F1:"f1",F2:"f2",SMOOTH_F1:"smooth_f1",DISTANCE_TO_EDGE:"distance_to_edge",N_SPHERE_RADIUS:"n_sphere_radius"},es={EUCLIDEAN:0,MANHATTAN:1,CHEBYCHEV:2,MINKOWSKI:3},as=(()=>{const o=new Map;for(const[t,n]of Object.entries(co))for(const e of n.code.matchAll(/^(?:void|float\d?)\s+([A-Za-z_]\w*)\s*\(/gm))o.has(e[1])||o.set(e[1],t);return o})();function C(o,t){if(!(t in o.props))throw new Error(`${o.type} arrived without its '${t}' property`);return o.props[t]}const rs=`
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
- `,ri=`
6939
+ `,ss=`
6940
6940
  uniform vec2 blenderViewport;
6941
6941
  vec3 blender_orco() {
6942
6942
  // attr_load_orco: the orco attribute (\`orcoAttribute\`), interpolated.
@@ -7019,23 +7019,23 @@ vec3 blender_reflection() {
7019
7019
  : normalize(cameraPosition - vBlenderWorldPosition);
7020
7020
  return blender_from_three * -reflect(incident, normalize(vBlenderWorldNormal));
7021
7021
  }
7022
- `;class yo{constructor(t,n,e=!1,r="bgN"){this.graph=t,this.derivative=e,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 e=`bgU${this.s.uniforms.size}`,r=Zr(t,n);return this.s.uniforms.set(e,t==="float"?r[0]:r),this.s.uniformTypes.set(e,t),e}use(t){const n=ei.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[e,r]=t.link,a=this.graph.nodes[e];if(!a)throw new Error(`The graph links to ${e}, which it does not carry`);const f=this.node(e,a)[r];if(!f)throw new Error(`${e} has no output ${r}`);return this.s.structure.push(["l",e,r]),Qr(f.name,f.type,n)}input(t,n,e){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,e??r.gpu)}coordinate(t,n){const e=t.inputs[0];return"link"in e?this.source(e,"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 e=this.emitted.get(t);if(e)return e;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(", "),m=(s=[])=>[...n.inputs.map(_=>this.source(_,_.gpu)),...s,...a.map(_=>_.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,_)=>{a[_]&&l.push(`${a[_].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)}(${uo(s)}, ${u(a.map((_,d)=>d))});`);for(const _ of a)l.push(`${_.name} = ${this.d(_.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(Kr[s]??`math_${s.toLowerCase()}`);l.push(`${c}(${m()});`),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(Jr[s]??`vector_math_${s.toLowerCase()}`)}(${m()});`);break}case"ShaderNodeMapping":l.push(`${this.use(`mapping_${C(n,"vector_type").toLowerCase()}`)}(${m()});`);break;case"ShaderNodeInvert":l.push(`${this.use("invert")}(${m()});`);break;case"ShaderNodeSeparateXYZ":l.push(`${this.use("separate_xyz")}(${m()});`);break;case"ShaderNodeCombineXYZ":l.push(`${this.use("combine_xyz")}(${m()});`);break;case"ShaderNodeMix":{const s=C(n,"data_type"),c=C(n,"factor_mode")==="NON_UNIFORM",_={FLOAT:"Float",VECTOR:"Vector",RGBA:"Color",ROTATION:"Rotation"}[s];if(!_)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 g=`${r}_fac`;l.push(d?`vec3 ${g}; ${this.use("node_mix_clamp_vector")}(${h}, vec3(0.0), vec3(1.0), ${g});`:`float ${g}; ${this.use("node_mix_clamp_value")}(${h}, 0.0, 1.0, ${g});`),h=g}const v=s==="FLOAT"?"node_mix_float":s==="VECTOR"?c?"node_mix_vector_non_uniform":"node_mix_vector":s==="RGBA"?`node_mix_${Xo[C(n,"blend_type")]}`:"node_mix_rotation",p=n.outputs.findIndex(g=>g.id===`Result_${_}`);l.push(`${this.use(v)}(${h}, ${this.input(n,`A_${_}`)}, ${this.input(n,`B_${_}`)}, ${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(_=>this.source(_,_.gpu));l.push(`${this.use(`mix_${Xo[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"),[_,d]=s.elements,h=v=>this.uniform("vec4",v.slice(1,5));if(s.elements.length===1)l.push(`${u([0])} = ${h(_)}; ${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(_[0],d[0]))}, ${h(_)}, ${h(d)}, ${u([0,1])});`);else{const v=1/(d[0]-_[0]),p=s.interpolation==="EASE"?"valtorgb_opti_ease":"valtorgb_opti_linear";l.push(`${this.use(p)}(${c}, ${this.uniform("vec2",[v,-v*_[0]])}, ${h(_)}, ${h(d)}, ${u([0,1])});`)}else{const v=`bgRamp${this.s.ramps.length}`;this.s.ramps.push({uniform:v,table:s.table}),this.s.structure.push(["ramp",s.interpolation==="CONSTANT"]),l.push(s.interpolation==="CONSTANT"?`${u([0])} = texelFetch(${v}, ivec2(int(clamp(${c}, 0.0, 1.0) * 256.0), 0), 0);`:`${u([0])} = texture(${v}, 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 _=this.input(n,n.inputs.some(d=>d.id==="Factor")?"Factor":"Fac","float");n.type==="ShaderNodeRGBCurve"?l.push(`${this.use("curves_combined_rgb")}(${_}, ${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")}(${_}, ${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")}(${_}, ${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_${ti[C(n,"noise_type")]}_${s}d`),_=this.coordinate(n,"orco"),d=n.inputs.slice(1).map(v=>this.source(v,v.gpu)),h=C(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[_,...d,h,"1.0",u(a.map((v,p)=>p))].join(", ")});`);break}case"ShaderNodeTexVoronoi":{const s=Number(C(n,"voronoi_dimensions")[0]),c=this.use(`node_tex_voronoi_${ni[C(n,"feature")]}_${s}d`),_=this.coordinate(n,"orco"),d=n.inputs.slice(1).map(p=>this.source(p,p.gpu)),h=`${oi[C(n,"distance")].toFixed(1)}`,v=C(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[_,...d,h,v,u(a.map((p,g)=>g))].join(", ")});`);break}case"ShaderNodeTexChecker":{const s=this.coordinate(n,"orco"),c=n.inputs.slice(1).map(_=>this.source(_,_.gpu));l.push(`${this.use("node_tex_checker")}(${[s,...c,u(a.map((_,d)=>d))].join(", ")});`);break}case"ShaderNodeTexWhiteNoise":{const s=Number(C(n,"noise_dimensions")[0]);l.push(`${this.use(`node_white_noise_${s}d`)}(${m()});`);break}case"ShaderNodeTexWave":case"ShaderNodeTexGradient":case"ShaderNodeTexMagic":case"ShaderNodeTexBrick":{const s=this.coordinate(n,"orco"),c=n.inputs.slice(1).map(v=>this.source(v,v.gpu)),_=v=>C(n,`${v}#value`).toFixed(1),d=n.type==="ShaderNodeTexWave"?[_("wave_type"),_("bands_direction"),_("rings_direction"),_("wave_profile")]:n.type==="ShaderNodeTexGradient"?[_("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((v,p)=>p))].join(", ")});`);break}case"ShaderNodeMapRange":{const s=C(n,"data_type")==="FLOAT_VECTOR",c=C(n,"interpolation_type").toLowerCase(),_=C(n,"clamp");l.push(`${this.use(`${s?"vector_":""}map_range_${c}`)}(${m([_?"1.0":"0.0"])});`),_&&!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")}(${m()});`);break;case"ShaderNodeHueSaturation":l.push(`${this.use("hue_sat")}(${m()});`);break;case"ShaderNodeBrightContrast":l.push(`${this.use("brightness_contrast")}(${m()});`);break;case"ShaderNodeGamma":l.push(`${this.use("node_gamma")}(${m()});`);break;case"ShaderNodeRGBToBW":l.push(`${this.use("rgbtobw")}(${m([Fe])});`);break;case"ShaderNodeSeparateColor":l.push(`${this.use(`separate_color_${C(n,"mode").toLowerCase()}`)}(${m()});`);break;case"ShaderNodeCombineColor":l.push(`${this.use(`combine_color_${C(n,"mode").toLowerCase()}`)}(${m()});`);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}`)}(${m([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 _=this.source(n.inputs[0],"float"),d=n.type==="ShaderNodeFresnel"?"node_fresnel":"node_layer_weight";l.push(`${this.use(d)}(${[_,c,u(a.map((h,v)=>v))].join(", ")});`);break}case"ShaderNodeBump":{const s=n.inputs.find(b=>b.id==="Height"),c=n.inputs.find(b=>b.id==="Normal"),_=c&&"link"in c?this.source(c,"vec3"):"g_data.N";if(!s||!("link"in s)){l.push(`${u([0])} = ${_};`);break}const d=`bgHeight${this.s.functions.length}`;this.s.functions.push("");const h=new yo(this.graph,this.s,!0,`${d}_`),v=h.source(s,"float");this.s.functions[Number(d.slice(8))]=`float ${d}() {
7022
+ `;class wo{constructor(t,n,e=!1,r="bgN"){this.graph=t,this.derivative=e,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 e=`bgU${this.s.uniforms.size}`,r=Qr(t,n);return this.s.uniforms.set(e,t==="float"?r[0]:r),this.s.uniformTypes.set(e,t),e}use(t){const n=as.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[e,r]=t.link,a=this.graph.nodes[e];if(!a)throw new Error(`The graph links to ${e}, which it does not carry`);const f=this.node(e,a)[r];if(!f)throw new Error(`${e} has no output ${r}`);return this.s.structure.push(["l",e,r]),Kr(f.name,f.type,n)}input(t,n,e){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,e??r.gpu)}coordinate(t,n){const e=t.inputs[0];return"link"in e?this.source(e,"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 e=this.emitted.get(t);if(e)return e;const r=`${this.prefix}${this.emitted.size}`,a=n.outputs.map((i,c)=>({name:`${r}_${c}`,type:i.gpu==="closure"||i.gpu===null?"float":i.gpu}));this.emitted.set(t,a);const s=i=>`${a[i].type} ${a[i].name} = ${a[i].type}(0.0);`,f=a.map((i,c)=>s(c)).join(" "),u=i=>i.map(c=>a[c].name).join(", "),m=(i=[])=>[...n.inputs.map(_=>this.source(_,_.gpu)),...i,...a.map(_=>_.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 i=a[0].type;l.push(`${a[0].name} = ${this.uniform(i,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,_)=>{a[_]&&l.push(`${a[_].name} = ${this.d(c)};`)});break}case"ShaderNodeVertexColor":case"ShaderNodeAttribute":{const i=C(n,n.type==="ShaderNodeAttribute"?"attribute_name":"layer_name");this.s.attributes.add(i),this.s.structure.push(["a",i]);const c=n.type==="ShaderNodeAttribute"?"node_attribute":"node_vertex_color";l.push(`${this.use(c)}(${uo(i)}, ${u(a.map((_,d)=>d))});`);for(const _ of a)l.push(`${_.name} = ${this.d(_.name)};`);break}case"ShaderNodeUVMap":{const i=C(n,"uv_map");this.s.uvs.add(i),l.push(`${a[0].name} = ${this.d(`vec3(${Kt(i)}, 0.0)`)};`);break}case"ShaderNodeMath":{const i=C(n,"operation"),c=this.use(Jr[i]??`math_${i.toLowerCase()}`);l.push(`${c}(${m()});`),C(n,"use_clamp")&&l.push(`${this.use("clamp_value")}(${u([0])}, 0.0, 1.0, ${u([0])});`);break}case"ShaderNodeVectorMath":{const i=C(n,"operation");l.push(`${this.use(ts[i]??`vector_math_${i.toLowerCase()}`)}(${m()});`);break}case"ShaderNodeMapping":l.push(`${this.use(`mapping_${C(n,"vector_type").toLowerCase()}`)}(${m()});`);break;case"ShaderNodeInvert":l.push(`${this.use("invert")}(${m()});`);break;case"ShaderNodeSeparateXYZ":l.push(`${this.use("separate_xyz")}(${m()});`);break;case"ShaderNodeCombineXYZ":l.push(`${this.use("combine_xyz")}(${m()});`);break;case"ShaderNodeMix":{const i=C(n,"data_type"),c=C(n,"factor_mode")==="NON_UNIFORM",_={FLOAT:"Float",VECTOR:"Vector",RGBA:"Color",ROTATION:"Rotation"}[i];if(!_)throw new Error(`Mix has data type ${i}`);const d=i==="VECTOR"&&c;let h=this.input(n,d?"Factor_Vector":"Factor_Float");if(C(n,"clamp_factor")){const g=`${r}_fac`;l.push(d?`vec3 ${g}; ${this.use("node_mix_clamp_vector")}(${h}, vec3(0.0), vec3(1.0), ${g});`:`float ${g}; ${this.use("node_mix_clamp_value")}(${h}, 0.0, 1.0, ${g});`),h=g}const v=i==="FLOAT"?"node_mix_float":i==="VECTOR"?c?"node_mix_vector_non_uniform":"node_mix_vector":i==="RGBA"?`node_mix_${Yo[C(n,"blend_type")]}`:"node_mix_rotation",p=n.outputs.findIndex(g=>g.id===`Result_${_}`);l.push(`${this.use(v)}(${h}, ${this.input(n,`A_${_}`)}, ${this.input(n,`B_${_}`)}, ${u([p])});`),i==="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 i=`${r}_fac`;l.push(`float ${i}; ${this.use("clamp_value")}(${this.input(n,"Fac")}, 0.0, 1.0, ${i});`);const c=n.inputs.slice(1).map(_=>this.source(_,_.gpu));l.push(`${this.use(`mix_${Yo[C(n,"blend_type")]}`)}(${[i,...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 i=C(n,"color_ramp"),c=this.input(n,"Fac"),[_,d]=i.elements,h=v=>this.uniform("vec4",v.slice(1,5));if(i.elements.length===1)l.push(`${u([0])} = ${h(_)}; ${u([1])} = ${u([0])}.a;`);else if(i.elements.length===2&&i.color_mode==="RGB"&&d&&i.interpolation!=="B_SPLINE"&&i.interpolation!=="CARDINAL")if(i.interpolation==="CONSTANT")l.push(`${this.use("valtorgb_opti_constant")}(${c}, ${this.uniform("float",Math.max(_[0],d[0]))}, ${h(_)}, ${h(d)}, ${u([0,1])});`);else{const v=1/(d[0]-_[0]),p=i.interpolation==="EASE"?"valtorgb_opti_ease":"valtorgb_opti_linear";l.push(`${this.use(p)}(${c}, ${this.uniform("vec2",[v,-v*_[0]])}, ${h(_)}, ${h(d)}, ${u([0,1])});`)}else{const v=`bgRamp${this.s.ramps.length}`;this.s.ramps.push({uniform:v,table:i.table}),this.s.structure.push(["ramp",i.interpolation==="CONSTANT"]),l.push(i.interpolation==="CONSTANT"?`${u([0])} = texelFetch(${v}, ivec2(int(clamp(${c}, 0.0, 1.0) * 256.0), 0), 0);`:`${u([0])} = texture(${v}, 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 i=C(n,"curve_mapping"),c=`bgRamp${this.s.ramps.length}`;this.s.ramps.push({uniform:c,table:i.table}),this.s.structure.push(["curve"]);const _=this.input(n,n.inputs.some(d=>d.id==="Factor")?"Factor":"Fac","float");n.type==="ShaderNodeRGBCurve"?l.push(`${this.use("curves_combined_rgb")}(${_}, ${this.input(n,"Color","vec4")}, vec4(0.0, 0.0, 0.0, 1.0), vec4(1.0), ${c}, 0.5, ${this.uniform("vec4",i.minimums)}, ${this.uniform("vec4",i.dividers)}, ${this.uniform("vec4",i.starts)}, ${this.uniform("vec4",i.ends)}, ${u([0])});`):n.type==="ShaderNodeVectorCurve"?l.push(`${this.use("curves_vector_mixed")}(${_}, ${this.input(n,"Vector","vec3")}, ${c}, 0.5, ${this.uniform("vec3",i.minimums.slice(0,3))}, ${this.uniform("vec3",i.dividers.slice(0,3))}, ${this.uniform("vec3",i.starts.slice(0,3))}, ${this.uniform("vec3",i.ends.slice(0,3))}, ${u([0])});`):l.push(`${this.use("curves_float_mixed")}(${_}, ${this.input(n,"Value","float")}, ${c}, 0.5, ${this.uniform("float",i.minimums[0])}, ${this.uniform("float",i.dividers[0])}, ${this.uniform("float",i.starts[0])}, ${this.uniform("float",i.ends[0])}, ${u([0])});`);break}case"ShaderNodeTexNoise":{const i=Number(C(n,"noise_dimensions")[0]),c=this.use(`node_noise_tex_${ns[C(n,"noise_type")]}_${i}d`),_=this.coordinate(n,"orco"),d=n.inputs.slice(1).map(v=>this.source(v,v.gpu)),h=C(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[_,...d,h,"1.0",u(a.map((v,p)=>p))].join(", ")});`);break}case"ShaderNodeTexVoronoi":{const i=Number(C(n,"voronoi_dimensions")[0]),c=this.use(`node_tex_voronoi_${os[C(n,"feature")]}_${i}d`),_=this.coordinate(n,"orco"),d=n.inputs.slice(1).map(p=>this.source(p,p.gpu)),h=`${es[C(n,"distance")].toFixed(1)}`,v=C(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[_,...d,h,v,u(a.map((p,g)=>g))].join(", ")});`);break}case"ShaderNodeTexChecker":{const i=this.coordinate(n,"orco"),c=n.inputs.slice(1).map(_=>this.source(_,_.gpu));l.push(`${this.use("node_tex_checker")}(${[i,...c,u(a.map((_,d)=>d))].join(", ")});`);break}case"ShaderNodeTexWhiteNoise":{const i=Number(C(n,"noise_dimensions")[0]);l.push(`${this.use(`node_white_noise_${i}d`)}(${m()});`);break}case"ShaderNodeTexWave":case"ShaderNodeTexGradient":case"ShaderNodeTexMagic":case"ShaderNodeTexBrick":{const i=this.coordinate(n,"orco"),c=n.inputs.slice(1).map(v=>this.source(v,v.gpu)),_=v=>C(n,`${v}#value`).toFixed(1),d=n.type==="ShaderNodeTexWave"?[_("wave_type"),_("bands_direction"),_("rings_direction"),_("wave_profile")]:n.type==="ShaderNodeTexGradient"?[_("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)}(${[i,...c,...d,u(a.map((v,p)=>p))].join(", ")});`);break}case"ShaderNodeMapRange":{const i=C(n,"data_type")==="FLOAT_VECTOR",c=C(n,"interpolation_type").toLowerCase(),_=C(n,"clamp");l.push(`${this.use(`${i?"vector_":""}map_range_${c}`)}(${m([_?"1.0":"0.0"])});`),_&&!i&&(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")}(${m()});`);break;case"ShaderNodeHueSaturation":l.push(`${this.use("hue_sat")}(${m()});`);break;case"ShaderNodeBrightContrast":l.push(`${this.use("brightness_contrast")}(${m()});`);break;case"ShaderNodeGamma":l.push(`${this.use("node_gamma")}(${m()});`);break;case"ShaderNodeRGBToBW":l.push(`${this.use("rgbtobw")}(${m([Fe])});`);break;case"ShaderNodeSeparateColor":l.push(`${this.use(`separate_color_${C(n,"mode").toLowerCase()}`)}(${m()});`);break;case"ShaderNodeCombineColor":l.push(`${this.use(`combine_color_${C(n,"mode").toLowerCase()}`)}(${m()});`);break;case"ShaderNodeVectorRotate":{const i={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_${i}`)}(${m([C(n,"invert")?"-1.0":"1.0"])});`);break}case"ShaderNodeFresnel":case"ShaderNodeLayerWeight":{const i=n.inputs[1],c="link"in i?this.source(i,"vec3"):"g_data.N";"link"in i||this.s.structure.push("world-normal");const _=this.source(n.inputs[0],"float"),d=n.type==="ShaderNodeFresnel"?"node_fresnel":"node_layer_weight";l.push(`${this.use(d)}(${[_,c,u(a.map((h,v)=>v))].join(", ")});`);break}case"ShaderNodeBump":{const i=n.inputs.find(b=>b.id==="Height"),c=n.inputs.find(b=>b.id==="Normal"),_=c&&"link"in c?this.source(c,"vec3"):"g_data.N";if(!i||!("link"in i)){l.push(`${u([0])} = ${_};`);break}const d=`bgHeight${this.s.functions.length}`;this.s.functions.push("");const h=new wo(this.graph,this.s,!0,`${d}_`),v=h.source(i,"float");this.s.functions[Number(d.slice(8))]=`float ${d}() {
7023
7023
  ${h.lines.join(`
7024
7024
  `)}
7025
7025
  return ${v};
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 g=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, ${_}, vec2(${r}_hx, ${r}_hy), ${g}, ${u([0])});`);break}case"ShaderNodeNormalMap":{const s=C(n,"space"),c=this.input(n,"Strength","float"),_=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")}(${_}, ${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"),_=C(n,"interpolation"),d=_==="Cubic"||_==="Smart",h=C(n,"extension"),v=`bgImage${this.s.images.length}`;this.s.images.push({uniform:v,node:t,name:s.name,revision:s.revision,extension:h,closest:_==="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 g=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")}(${g}, ${O}, ${v}, ${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"}(${g}, ${v}, ${v}Map, ${b}, ${y});`);else{if(c==="SPHERE"||c==="TUBE"){const O=`${r}_co`;l.push(`vec3 ${O}; ${this.use("point_texco_remap_square")}(${g}, ${O});`,`${this.use(c==="SPHERE"?"point_map_to_sphere":"point_map_to_tube")}(${O}, ${O});`),g=O}l.push(`${this.use(d?"node_tex_image_cubic":"node_tex_image_linear")}(${g}, ${v}, ${b}, ${y});`),h==="CLIP"&&l.push(`if (any(lessThan(${g}.xy, vec2(0.0))) || any(greaterThan(${g}.xy, vec2(1.0)))) { ${b} = vec4(0.0); ${y} = 0.0; }`)}const S=C(n,"image_alpha_mode"),A=this.uses(t,1),T=u([0]);S==="NONE"||S==="CHANNEL_PACKED"||C(n,"image_is_data")?l.push(`${T}.a = 1.0;`):S==="PREMUL"?l.push(A?`if (${T}.a != 0.0 && ${T}.a != 1.0) ${T}.rgb /= ${T}.a;`:`${T}.a = 1.0;`):l.push(A?`${T}.a = 1.0;`:`${T}.rgb *= ${T}.a;`);break}}return this.lines.push(...l),a}uses(t,n){const e=a=>"link"in a&&a.link[0]===t&&a.link[1]===n,r=a=>a!==void 0&&("emission"in a?a.emission.some(e):"mix"in a?e(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(e)||Object.values(this.graph.nodes).some(a=>a.inputs.some(e))||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={},e=[];let r=0;for(const[s,c]of Object.entries(t)){const _=this.graph.inputs[s];if(!_||s==="Normal"&&!("link"in _))continue;const d=`bgOut${r++}`;n[s]={global:d,type:c},this.s.structure.push(["out",s]),e.push(`${d} = ${this.source(_,c)};`)}const a=this.graph.closure;if(a){let s=0;const c=(_,d)=>{if("principled"in _)this.s.structure.push("cP"),e.push(`bgClosureP += ${d};`);else if("emission"in _)this.s.structure.push("cE"),e.push(`bgClosureE += ${d} * ${this.source(_.emission[0],"vec4")}.rgb * ${this.source(_.emission[1],"float")};`);else if("transparent"in _)this.s.structure.push("cT"),e.push(`bgClosureT += ${d} * ${this.source({value:_.transparent},"float")};`);else if("mix"in _){this.s.structure.push("cM");const h=`bgClosureF${s++}`;e.push(`float ${h} = clamp(${this.source(_.mix[0],"float")}, 0.0, 1.0);`),c(_.mix[1],`${d} * (1.0 - ${h})`),c(_.mix[2],`${d} * ${h}`)}else"add"in _?(this.s.structure.push("cA"),c(_.add[0],d),c(_.add[1],d)):this.s.structure.push("c0")};e.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 co[s].deps)u(c);i.push(s)}};for(const s of this.s.files)u(s);const m=`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 g=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, ${_}, vec2(${r}_hx, ${r}_hy), ${g}, ${u([0])});`);break}case"ShaderNodeNormalMap":{const i=C(n,"space"),c=this.input(n,"Strength","float"),_=this.input(n,"Color","vec3"),d=`${r}_n`;if(l.push(`vec3 ${d}; ${this.use(i.startsWith("BLENDER_")?"color_to_blender_normal_new_shading":"color_to_normal_new_shading")}(${_}, ${d});`),n.props.convention==="DIRECTX"&&l.push(`${this.use("color_invert_green_channel")}(${d}, ${d});`),i==="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(i==="OBJECT"||i==="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((i,c)=>c))].join(", ")});`),a[0]&&l.push(`${a[0].name} = ${this.d(a[0].name)};`);for(const i of[1,2,4])a[i]&&l.push(`${a[i].name} = normalize(${a[i].name});`);break}case"ShaderNodeTexImage":{const i=C(n,"image");if(i===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"),_=C(n,"interpolation"),d=_==="Cubic"||_==="Smart",h=C(n,"extension"),v=`bgImage${this.s.images.length}`;this.s.images.push({uniform:v,node:t,name:i.name,revision:i.revision,extension:h,closest:_==="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 g=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")}(${g}, ${O}, ${v}, ${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"}(${g}, ${v}, ${v}Map, ${b}, ${y});`);else{if(c==="SPHERE"||c==="TUBE"){const O=`${r}_co`;l.push(`vec3 ${O}; ${this.use("point_texco_remap_square")}(${g}, ${O});`,`${this.use(c==="SPHERE"?"point_map_to_sphere":"point_map_to_tube")}(${O}, ${O});`),g=O}l.push(`${this.use(d?"node_tex_image_cubic":"node_tex_image_linear")}(${g}, ${v}, ${b}, ${y});`),h==="CLIP"&&l.push(`if (any(lessThan(${g}.xy, vec2(0.0))) || any(greaterThan(${g}.xy, vec2(1.0)))) { ${b} = vec4(0.0); ${y} = 0.0; }`)}const S=C(n,"image_alpha_mode"),A=this.uses(t,1),T=u([0]);S==="NONE"||S==="CHANNEL_PACKED"||C(n,"image_is_data")?l.push(`${T}.a = 1.0;`):S==="PREMUL"?l.push(A?`if (${T}.a != 0.0 && ${T}.a != 1.0) ${T}.rgb /= ${T}.a;`:`${T}.a = 1.0;`):l.push(A?`${T}.a = 1.0;`:`${T}.rgb *= ${T}.a;`);break}}return this.lines.push(...l),a}uses(t,n){const e=a=>"link"in a&&a.link[0]===t&&a.link[1]===n,r=a=>a!==void 0&&("emission"in a?a.emission.some(e):"mix"in a?e(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(e)||Object.values(this.graph.nodes).some(a=>a.inputs.some(e))||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={},e=[];let r=0;for(const[i,c]of Object.entries(t)){const _=this.graph.inputs[i];if(!_||i==="Normal"&&!("link"in _))continue;const d=`bgOut${r++}`;n[i]={global:d,type:c},this.s.structure.push(["out",i]),e.push(`${d} = ${this.source(_,c)};`)}const a=this.graph.closure;if(a){let i=0;const c=(_,d)=>{if("principled"in _)this.s.structure.push("cP"),e.push(`bgClosureP += ${d};`);else if("emission"in _)this.s.structure.push("cE"),e.push(`bgClosureE += ${d} * ${this.source(_.emission[0],"vec4")}.rgb * ${this.source(_.emission[1],"float")};`);else if("transparent"in _)this.s.structure.push("cT"),e.push(`bgClosureT += ${d} * ${this.source({value:_.transparent},"float")};`);else if("mix"in _){this.s.structure.push("cM");const h=`bgClosureF${i++}`;e.push(`float ${h} = clamp(${this.source(_.mix[0],"float")}, 0.0, 1.0);`),c(_.mix[1],`${d} * (1.0 - ${h})`),c(_.mix[2],`${d} * ${h}`)}else"add"in _?(this.s.structure.push("cA"),c(_.add[0],d),c(_.add[1],d)):this.s.structure.push("c0")};e.push("bgClosureP = 0.0;","bgClosureE = vec3(0.0);","bgClosureT = 0.0;"),c(a,"1.0")}const s=[],f=new Set,u=i=>{if(!f.has(i)){f.add(i);for(const c of co[i].deps)u(c);s.push(i)}};for(const i of this.s.files)u(i);const m=`void blenderGraph() {
7027
7027
  blender_init_globals();
7028
7028
  ${[...this.lines,...e].join(`
7029
7029
  `)}
7030
- }`,l=[Wr,ii(ai+i.map(s=>co[s].code).join(`
7030
+ }`,l=[Hr,is(rs+s.map(i=>co[i].code).join(`
7031
7031
  `)+`
7032
- `+ri,[...this.s.functions,m].join(`
7033
- `)),...[...this.s.uniformTypes].map(([s,c])=>`uniform ${c} ${s};`),...this.images.map(s=>s.tiled?`uniform highp sampler2DArray ${s.uniform};
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,m].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 ii(o,t){const n=[],e=/^[A-Za-z_][\w ]*?\b([A-Za-z_]\w*)\s*\(/gm;let r=0;for(let u;u=e.exec(o);){if(u.index<r)continue;let m=u.index+u[0].length;for(let _=1;m<o.length&&_>0;m++)_+=o[m]==="("?1:o[m]===")"?-1:0;const l=o.slice(m).match(/^\s*(\{|;)/);if(!l||/^\s*#/.test(o.slice(o.lastIndexOf(`
7032
+ `+ss,[...this.s.functions,m].join(`
7033
+ `)),...[...this.s.uniformTypes].map(([i,c])=>`uniform ${c} ${i};`),...this.images.map(i=>i.tiled?`uniform highp sampler2DArray ${i.uniform};
7034
+ uniform highp sampler2D ${i.uniform}Map;`:`uniform sampler2D ${i.uniform};`),...this.ramps.map(i=>`uniform sampler2D ${i.uniform};`),...Object.values(n).map(i=>`${i.type} ${i.global};`),...a?["float bgClosureP;","vec3 bgClosureE;","float bgClosureT;"]:[],...this.s.functions,m].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 is(o,t){const n=[],e=/^[A-Za-z_][\w ]*?\b([A-Za-z_]\w*)\s*\(/gm;let r=0;for(let u;u=e.exec(o);){if(u.index<r)continue;let m=u.index+u[0].length;for(let _=1;m<o.length&&_>0;m++)_+=o[m]==="("?1:o[m]===")"?-1:0;const l=o.slice(m).match(/^\s*(\{|;)/);if(!l||/^\s*#/.test(o.slice(o.lastIndexOf(`
7036
7036
  `,u.index)+1,u.index+1))||o.slice(Math.max(0,u.index-2),u.index).endsWith(`\\
7037
- `))continue;let c=m+l[0].length;if(l[1]==="{")for(let _=1;c<o.length&&_>0;c++)_+=o[c]==="{"?1:o[c]==="}"?-1:0;n.push({text:o.slice(r,u.index),name:null}),n.push({text:o.slice(u.index,c),name:u[1]}),r=c,e.lastIndex=c}n.push({text:o.slice(r),name:null});const a=new Set(n.filter(u=>u.name===null)),i=new Set,f=u=>{for(const m of u.matchAll(/[A-Za-z_]\w*/g))i.add(m[0])};f(t);for(const u of a)f(u.text);for(let u=!0;u;){u=!1;for(const m of n)a.has(m)||m.name===null||!i.has(m.name)||(a.add(m),f(m.text),u=!0)}return n.filter(u=>a.has(u)).map(u=>u.text).join("")}function uo(o){return`v${kt(o)}`}function Kt(o){return o===""?"vBlenderUvRender":`vBlenderUv_${[...o].map(t=>t.charCodeAt(0).toString(16)).join("")}`}function si(o){return new yo(o).compile()}function li(o){const t=new Uint16Array(o.length*4);o.forEach((e,r)=>t.set([e[0]??0,e[1]??0,e[2]??0,e[3]??1].map(a=>cn.toHalfFloat(a)),r*4));const n=new kn(t,o.length,1,$n,ho);return n.minFilter=n.magFilter=Xt,n.wrapS=n.wrapT=ue,n.needsUpdate=!0,n}const pt=new WeakMap,De=new Set,Ct=new WeakMap,bn=new WeakMap;function yn(o){const t=Ct.get(o);if(t){Ct.delete(o);for(const n of t.binding.ramps)n.dispose()}}function fi(o,t,n,e=!1){const r=pt.get(o);if(t&&De.has(t.key)&&(t=null),!t){if(yn(o),r){for(const f of r.ramps)f.dispose();pt.delete(o),o.needsUpdate=!0}return}if(r&&r.compiled.key===t.key){yn(o),wn(r,t,n);return}if(e){yn(o);for(const u of r?.ramps??[])u.dispose();const f={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};wn(f,t,n),pt.set(o,f),o.needsUpdate=!0;return}const a=Ct.get(o);if(a&&a.binding.compiled.key===t.key){wn(a.binding,t,n);return}yn(o);const i={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};wn(i,t,n),Ct.set(o,{binding:i,started:!1})}function wn(o,t,n){o.compiled=t;for(const[e,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=o.uniforms[e];i?i.value=a:o.uniforms[e]={value:a}}for(const e of o.ramps)e.dispose();o.ramps=t.ramps.map(e=>{const r=li(e.table);return(o.uniforms[e.uniform]??={value:null}).value=r,r});for(const e of t.images){const r=n(e);if(e.tiled){const a=r!==null&&"tiles"in r?r:null;(o.uniforms[e.uniform]??={value:null}).value=a?.tiles??null,(o.uniforms[`${e.uniform}Map`]??={value:null}).value=a?.map??null}else(o.uniforms[e.uniform]??={value:null}).value=r!==null&&"tiles"in r?null:r}}function ci(o){const t=pt.get(o);return t?`${t.compiled.key}|${JSON.stringify(t.channels)}`:""}function ui(o){return Object.values(pt.get(o)?.channels??{})}function Ce(o,t){const n=new Set(["position","normal","uv"]);if(t.hasAttribute("tangent")&&n.add("tangent"),o.vertexColors&&n.add("color"),!(o instanceof nn))return n;const e=t.userData.blenderUvChannels,r=a=>{const i=a===""?0:e?.[a]??9;n.add(i===0?"uv":`uv${i}`)};for(const a of[o.map,o.roughnessMap,o.normalMap])a&&r(a.userData.blenderUvName??"");for(const a of[pt.get(o),Ct.get(o)?.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 Yo(o,t){const n=t.userData.blenderUvChannels,e=t.getAttribute("position")?.count??0,r={};for(const a of o.uvs){let i=a===""?0:n?.[a];i===void 0&&(i=9,t.getAttribute("uv9")?.count!==e&&t.setAttribute("uv9",new dt(new Float32Array(e*2),2))),r[a]=i}return r}function _i(o,t,n,e,r,a,i){const f=bn.get(o);f&&++f.draws>1&&(f.shadow.dispose(),bn.delete(o));const u=Ct.get(o);if(u&&!u.started){u.started=!0,u.binding.channels=Yo(u.binding.compiled,t);const c=i(o);pt.set(c,u.binding);const _=new Rt(t,c);_.castShadow=a.castShadow,_.receiveShadow=a.receiveShadow;const d=()=>{if(Ct.get(o)!==u){c.dispose();return}Ct.delete(o);for(const h of pt.get(o)?.ramps??[])h.dispose();pt.set(o,u.binding),o.needsUpdate=!0,bn.get(o)?.shadow.dispose(),bn.set(o,{shadow:c,draws:0}),Ot()};n.compileAsync(_,r,e).then(d,d)}const m=pt.get(o);if(!m)return;const l=n.properties.get(o).currentProgram;if(l?.diagnostics?.runnable===!1&&l.cacheKey?.includes(m.compiled.key)){De.add(m.compiled.key),pt.delete(o),o.needsUpdate=!0;const c=l.diagnostics.fragmentShader.log.split(`
7038
- `).find(_=>_.startsWith("ERROR"))??"";console.warn(`Blender material "${o.name}": its node graph did not compile for WebGL, so it is drawn with its constant values. ${c}`);return}const s=Yo(m.compiled,t);JSON.stringify(s)!==JSON.stringify(m.channels)&&(m.channels=s,o.needsUpdate=!0)}function mi(o){const t=Array.isArray(o.material)?o.material:[o.material];if(!t.some(u=>u instanceof nn&&pt.has(u)))return;const n=o.geometry,e=o.userData.blenderTexspace??null,r=n.getAttribute("position"),a=JSON.stringify([e,r?.version??0,r?.count??0]);!n.userData.blenderOrcoFromDoor&&n.userData.blenderOrcoStamp!==a&&(n.setAttribute("blenderOrco",di(n,e)),n.userData.blenderOrcoStamp=a);const i=r?.count??0,f=o.userData.blenderDefaultColor;for(const u of t){const m=u instanceof nn?pt.get(u):void 0;for(const l of m?.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 dt(new Float32Array(i*4),4))}}}function di(o,t){const n=o.getAttribute("position");let e,r;if(t)e=[...t[0]],r=[...t[1]];else{o.computeBoundingBox();const i=o.boundingBox;e=[(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)-e[0])/r[0]*.5+.5,a[i*3+1]=(n.getY(i)-e[1])/r[1]*.5+.5,a[i*3+2]=(n.getZ(i)-e[2])/r[2]*.5+.5;return new dt(a,3)}function hi(o,t){const n=pt.get(o);if(!n)return;const{compiled:e,channels:r}=n;Object.assign(t.uniforms,n.uniforms,{blenderViewport:{value:ke}});const a=p=>p===0?"uv":`uv${p}`,i=`varying vec3 vBlenderObjectPosition;
7037
+ `))continue;let c=m+l[0].length;if(l[1]==="{")for(let _=1;c<o.length&&_>0;c++)_+=o[c]==="{"?1:o[c]==="}"?-1:0;n.push({text:o.slice(r,u.index),name:null}),n.push({text:o.slice(u.index,c),name:u[1]}),r=c,e.lastIndex=c}n.push({text:o.slice(r),name:null});const a=new Set(n.filter(u=>u.name===null)),s=new Set,f=u=>{for(const m of u.matchAll(/[A-Za-z_]\w*/g))s.add(m[0])};f(t);for(const u of a)f(u.text);for(let u=!0;u;){u=!1;for(const m of n)a.has(m)||m.name===null||!s.has(m.name)||(a.add(m),f(m.text),u=!0)}return n.filter(u=>a.has(u)).map(u=>u.text).join("")}function uo(o){return`v${kt(o)}`}function Kt(o){return o===""?"vBlenderUvRender":`vBlenderUv_${[...o].map(t=>t.charCodeAt(0).toString(16)).join("")}`}function ls(o){return new wo(o).compile()}function fs(o){const t=new Uint16Array(o.length*4);o.forEach((e,r)=>t.set([e[0]??0,e[1]??0,e[2]??0,e[3]??1].map(a=>cn.toHalfFloat(a)),r*4));const n=new kn(t,o.length,1,$n,ho);return n.minFilter=n.magFilter=Xt,n.wrapS=n.wrapT=me,n.needsUpdate=!0,n}const pt=new WeakMap,Ce=new Set,Ct=new WeakMap,yn=new WeakMap;function wn(o){const t=Ct.get(o);if(t){Ct.delete(o);for(const n of t.binding.ramps)n.dispose()}}function cs(o,t,n,e=!1){const r=pt.get(o);if(t&&Ce.has(t.key)&&(t=null),!t){if(wn(o),r){for(const f of r.ramps)f.dispose();pt.delete(o),o.needsUpdate=!0}return}if(r&&r.compiled.key===t.key){wn(o),On(r,t,n);return}if(e){wn(o);for(const u of r?.ramps??[])u.dispose();const f={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};On(f,t,n),pt.set(o,f),o.needsUpdate=!0;return}const a=Ct.get(o);if(a&&a.binding.compiled.key===t.key){On(a.binding,t,n);return}wn(o);const s={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};On(s,t,n),Ct.set(o,{binding:s,started:!1})}function On(o,t,n){o.compiled=t;for(const[e,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),s=o.uniforms[e];s?s.value=a:o.uniforms[e]={value:a}}for(const e of o.ramps)e.dispose();o.ramps=t.ramps.map(e=>{const r=fs(e.table);return(o.uniforms[e.uniform]??={value:null}).value=r,r});for(const e of t.images){const r=n(e);if(e.tiled){const a=r!==null&&"tiles"in r?r:null;(o.uniforms[e.uniform]??={value:null}).value=a?.tiles??null,(o.uniforms[`${e.uniform}Map`]??={value:null}).value=a?.map??null}else(o.uniforms[e.uniform]??={value:null}).value=r!==null&&"tiles"in r?null:r}}function us(o){const t=pt.get(o);return t?`${t.compiled.key}|${JSON.stringify(t.channels)}`:""}function _s(o){return Object.values(pt.get(o)?.channels??{})}function ke(o,t){const n=new Set(["position","normal","uv"]);if(t.hasAttribute("tangent")&&n.add("tangent"),o.vertexColors&&n.add("color"),!(o instanceof nn))return n;const e=t.userData.blenderUvChannels,r=a=>{const s=a===""?0:e?.[a]??9;n.add(s===0?"uv":`uv${s}`)};for(const a of[o.map,o.roughnessMap,o.normalMap])a&&r(a.userData.blenderUvName??"");for(const a of[pt.get(o),Ct.get(o)?.binding])if(a){n.add("blenderOrco");for(const s of a.compiled.uvs)r(s);for(const s of a.compiled.attributes)n.add(kt(s))}return n}function Zo(o,t){const n=t.userData.blenderUvChannels,e=t.getAttribute("position")?.count??0,r={};for(const a of o.uvs){let s=a===""?0:n?.[a];s===void 0&&(s=9,t.getAttribute("uv9")?.count!==e&&t.setAttribute("uv9",new dt(new Float32Array(e*2),2))),r[a]=s}return r}function ms(o,t,n,e,r,a,s){const f=yn.get(o);f&&++f.draws>1&&(f.shadow.dispose(),yn.delete(o));const u=Ct.get(o);if(u&&!u.started){u.started=!0,u.binding.channels=Zo(u.binding.compiled,t);const c=s(o);pt.set(c,u.binding);const _=new Rt(t,c);_.castShadow=a.castShadow,_.receiveShadow=a.receiveShadow;const d=()=>{if(Ct.get(o)!==u){c.dispose();return}Ct.delete(o);for(const h of pt.get(o)?.ramps??[])h.dispose();pt.set(o,u.binding),o.needsUpdate=!0,yn.get(o)?.shadow.dispose(),yn.set(o,{shadow:c,draws:0}),wt()};n.compileAsync(_,r,e).then(d,d)}const m=pt.get(o);if(!m)return;const l=n.properties.get(o).currentProgram;if(l?.diagnostics?.runnable===!1&&l.cacheKey?.includes(m.compiled.key)){Ce.add(m.compiled.key),pt.delete(o),o.needsUpdate=!0;const c=l.diagnostics.fragmentShader.log.split(`
7038
+ `).find(_=>_.startsWith("ERROR"))??"";console.warn(`Blender material "${o.name}": its node graph did not compile for WebGL, so it is drawn with its constant values. ${c}`);return}const i=Zo(m.compiled,t);JSON.stringify(i)!==JSON.stringify(m.channels)&&(m.channels=i,o.needsUpdate=!0)}function ds(o){const t=Array.isArray(o.material)?o.material:[o.material];if(!t.some(u=>u instanceof nn&&pt.has(u)))return;const n=o.geometry,e=o.userData.blenderTexspace??null,r=n.getAttribute("position"),a=JSON.stringify([e,r?.version??0,r?.count??0]);!n.userData.blenderOrcoFromDoor&&n.userData.blenderOrcoStamp!==a&&(n.setAttribute("blenderOrco",hs(n,e)),n.userData.blenderOrcoStamp=a);const s=r?.count??0,f=o.userData.blenderDefaultColor;for(const u of t){const m=u instanceof nn?pt.get(u):void 0;for(const l of m?.compiled.attributes??[]){const i=kt(l),c=l===""?f===void 0?void 0:n.getAttribute(kt(f)):n.getAttribute(i);c&&c.count===s?n.getAttribute(i)!==c&&n.setAttribute(i,c):n.getAttribute(i)?.count!==s&&n.setAttribute(i,new dt(new Float32Array(s*4),4))}}}function hs(o,t){const n=o.getAttribute("position");let e,r;if(t)e=[...t[0]],r=[...t[1]];else{o.computeBoundingBox();const s=o.boundingBox;e=[(s.min.x+s.max.x)/2,(s.min.y+s.max.y)/2,(s.min.z+s.max.z)/2],r=[(s.max.x-s.min.x)/2,(s.max.y-s.min.y)/2,(s.max.z-s.min.z)/2]}r=r.map(s=>s===0?1:s);const a=new Float32Array(n.count*3);for(let s=0;s<n.count;s++)a[s*3]=(n.getX(s)-e[0])/r[0]*.5+.5,a[s*3+1]=(n.getY(s)-e[1])/r[1]*.5+.5,a[s*3+2]=(n.getZ(s)-e[2])/r[2]*.5+.5;return new dt(a,3)}function ps(o,t){const n=pt.get(o);if(!n)return;const{compiled:e,channels:r}=n;Object.assign(t.uniforms,n.uniforms,{blenderViewport:{value:$e}});const a=p=>p===0?"uv":`uv${p}`,s=`varying vec3 vBlenderObjectPosition;
7039
7039
  varying vec3 vBlenderObjectNormal;
7040
7040
  varying vec3 vBlenderWorldPosition;
7041
7041
  varying vec3 vBlenderWorldNormal;
@@ -7046,7 +7046,7 @@ ${e.uvs.map(p=>`varying vec2 ${Kt(p)};`).join(`
7046
7046
  `)}`,f=e.attributes.map(p=>`attribute vec4 ${kt(p)};`).join(`
7047
7047
  `);t.vertexShader=`attribute vec3 blenderOrco;
7048
7048
  ${f}
7049
- ${i}
7049
+ ${s}
7050
7050
  ${t.vertexShader}`.replace("#include <project_vertex>",`vBlenderObjectPosition = transformed;
7051
7051
  vBlenderObjectNormal = objectNormal;
7052
7052
  mat4 blenderWorldMatrix = modelMatrix;
@@ -7070,17 +7070,17 @@ ${e.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,(g,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([...e.declarations.matchAll(/^[ \t]*#define[ \t]+(\w+)/gm)].map(p=>p[1]))].filter(p=>c.has(p)),h=[...d.map(p=>`#undef ${p}`),e.declarations,...d.flatMap(p=>[`#undef ${p}`,c.get(p)])].join(`
7074
- `);let v=t.fragmentShader.replace("void main() {",`${i}
7073
+ }`,!0]);const l=p=>p.replace(/^[ \t]*#include <(\w+)>/gm,(g,b)=>l(Ut[b]??"")),i=l(t.fragmentShader.slice(0,t.fragmentShader.indexOf("void main() {"))),c=new Map([...i.matchAll(/^[ \t]*#define[ \t]+(\w+).*$/gm)].map(p=>[p[1],p[0].trim()])),d=[...new Set([...e.declarations.matchAll(/^[ \t]*#define[ \t]+(\w+)/gm)].map(p=>p[1]))].filter(p=>c.has(p)),h=[...d.map(p=>`#undef ${p}`),e.declarations,...d.flatMap(p=>[`#undef ${p}`,c.get(p)])].join(`
7074
+ `);let v=t.fragmentShader.replace("void main() {",`${s}
7075
7075
  ${h}
7076
7076
  void main() {`).replace("#include <clipping_planes_fragment>",`#include <clipping_planes_fragment>
7077
7077
  blenderGraph();`);for(const[p,g,b]of m){if(!v.includes(p))throw new Error(`three's physical shader has no ${p}`);v=v.replace(p,b?`${g}
7078
7078
  ${p}`:`${p}
7079
- ${g}`)}t.fragmentShader=v}const ke=new Gt(1,1);function pi(o){o.getDrawingBufferSize(ke)}function vi(o,t){const n=t.userData.blenderUvChannels;for(const e of[o.map,o.roughnessMap,o.normalMap]){if(!e)continue;const r=e.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 dt(new Float32Array(i*2),2))}e.channel!==a&&(e.channel=a,o.needsUpdate=!0)}}class gi{constructor(){this.bindings=new Map}get(t,n,e,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 m=i;r&&r.then(()=>{m.disposed||(m.texture.needsUpdate=!0,m.version=n.version,Ot())},()=>{})}const f=e==="REPEAT"?oa:e==="MIRROR"?ea:ue,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 yt=N().finite(),Yn=L([yt,yt,yt]),xi=M({coat:yt,coat_roughness:yt,coat_ior:yt,coat_tint:Yn,sheen:yt,sheen_roughness:yt,sheen_tint:Yn,anisotropy:yt,anisotropy_rotation:yt,specular_level:yt,specular_tint:Yn,film_thickness:yt,film_ior:yt}).strict(),bi={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 yi(o,t){on.has(o)||wo(o),on.get(o).blenderWorldExtinction.value.copy(t)}function wi(o){const t=new nn,n=on.get(o);wo(t),t.copy(o);const e=on.get(t);return n&&(e.blenderCoatIor.value=n.blenderCoatIor.value,e.blenderCoatTint.value.copy(n.blenderCoatTint.value),e.blenderMapClip.value=n.blenderMapClip.value,e.blenderRoughnessClip.value=n.blenderRoughnessClip.value,e.blenderNormalClip.value=n.blenderNormalClip.value,e.blenderWorldExtinction.value.copy(n.blenderWorldExtinction.value)),t}function wo(o,t,n={}){const e=t??bi;o.clearcoat=e.coat,o.clearcoatRoughness=e.coat_roughness,o.sheen=e.sheen,o.sheenRoughness=e.sheen_roughness,o.sheenColor.setRGB(...e.sheen_tint,vt),o.anisotropy=e.anisotropy,o.anisotropyRotation=e.anisotropy_rotation*Math.PI*2,o.specularIntensity=e.specular_level*2,o.specularColor.setRGB(...e.specular_tint,vt),o.iridescence=e.film_thickness>0?1:0,o.iridescenceIOR=e.film_ior,o.iridescenceThicknessRange=[e.film_thickness,e.film_thickness];let r=on.get(o);if(!r){r={blenderCoatIor:{value:1.5},blenderCoatTint:{value:new wt(1,1,1)},blenderMapClip:{value:!1},blenderRoughnessClip:{value:!1},blenderNormalClip:{value:!1},blenderWorldExtinction:{value:new x}},on.set(o,r);const a=r;o.customProgramCacheKey=()=>`blender-principled-physical-v5${ci(o)}`,o.onBeforeRender=(i,f,u,m,l)=>{vi(o,m),_i(o,m,i,f,u,l,wi),pi(i)},o.onBeforeCompile=i=>{const f=new Set([o.map,o.roughnessMap,o.normalMap].flatMap(d=>d?[d.channel]:[]).concat(ui(o)));i.vertexShader=[...f].filter(d=>d>0).sort((d,h)=>d-h).map(d=>d<=3?`#ifndef USE_UV${d}
7079
+ ${g}`)}t.fragmentShader=v}const $e=new Gt(1,1);function vs(o){o.getDrawingBufferSize($e)}function gs(o,t){const n=t.userData.blenderUvChannels;for(const e of[o.map,o.roughnessMap,o.normalMap]){if(!e)continue;const r=e.userData.blenderUvName;let a=r?n?.[r]:0;if(a===void 0){a=9;const s=t.getAttribute("position")?.count;if(s===void 0)throw new Error("A textured Blender draw has no positions");t.getAttribute("uv9")?.count!==s&&t.setAttribute("uv9",new dt(new Float32Array(s*2),2))}e.channel!==a&&(e.channel=a,o.needsUpdate=!0)}}class xs{constructor(){this.bindings=new Map}get(t,n,e,r,a=""){let s=this.bindings.get(t);if(!s||s.source!==n){this.delete(t),s={source:n,texture:n.clone(),version:-1,disposed:!1},this.bindings.set(t,s);const m=s;r&&r.then(()=>{m.disposed||(m.texture.needsUpdate=!0,m.version=n.version,wt())},()=>{})}const f=e==="REPEAT"?ea:e==="MIRROR"?aa:me,u=s.texture.wrapS!==f||s.texture.wrapT!==f;return s.texture.wrapS=s.texture.wrapT=f,s.texture.userData.blenderUvName=a,n.image&&(u||s.version!==n.version)&&(s.texture.needsUpdate=!0,s.version=n.version),s.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 yt=N().finite(),Yn=L([yt,yt,yt]),bs=M({coat:yt,coat_roughness:yt,coat_ior:yt,coat_tint:Yn,sheen:yt,sheen_roughness:yt,sheen_tint:Yn,anisotropy:yt,anisotropy_rotation:yt,specular_level:yt,specular_tint:Yn,film_thickness:yt,film_ior:yt}).strict(),ys={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 ws(o,t){on.has(o)||Oo(o),on.get(o).blenderWorldExtinction.value.copy(t)}function Os(o){const t=new nn,n=on.get(o);Oo(t),t.copy(o);const e=on.get(t);return n&&(e.blenderCoatIor.value=n.blenderCoatIor.value,e.blenderCoatTint.value.copy(n.blenderCoatTint.value),e.blenderMapClip.value=n.blenderMapClip.value,e.blenderRoughnessClip.value=n.blenderRoughnessClip.value,e.blenderNormalClip.value=n.blenderNormalClip.value,e.blenderWorldExtinction.value.copy(n.blenderWorldExtinction.value)),t}function Oo(o,t,n={}){const e=t??ys;o.clearcoat=e.coat,o.clearcoatRoughness=e.coat_roughness,o.sheen=e.sheen,o.sheenRoughness=e.sheen_roughness,o.sheenColor.setRGB(...e.sheen_tint,vt),o.anisotropy=e.anisotropy,o.anisotropyRotation=e.anisotropy_rotation*Math.PI*2,o.specularIntensity=e.specular_level*2,o.specularColor.setRGB(...e.specular_tint,vt),o.iridescence=e.film_thickness>0?1:0,o.iridescenceIOR=e.film_ior,o.iridescenceThicknessRange=[e.film_thickness,e.film_thickness];let r=on.get(o);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(o,r);const a=r;o.customProgramCacheKey=()=>`blender-principled-physical-v5${us(o)}`,o.onBeforeRender=(s,f,u,m,l)=>{gs(o,m),ms(o,m,s,f,u,l,Os),vs(s)},o.onBeforeCompile=s=>{const f=new Set([o.map,o.roughnessMap,o.normalMap].flatMap(d=>d?[d.channel]:[]).concat(_s(o)));s.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
  `)+`
7083
- `+i.vertexShader,Object.assign(i.uniforms,a),i.fragmentShader=`uniform float blenderCoatIor;
7083
+ `+s.vertexShader,Object.assign(s.uniforms,a),s.fragmentShader=`uniform float blenderCoatIor;
7084
7084
  uniform vec3 blenderWorldExtinction;
7085
7085
  vec3 blenderInfiniteTransmission() { return vec3(
7086
7086
  blenderWorldExtinction.x>0.?0.:1., blenderWorldExtinction.y>0.?0.:1., blenderWorldExtinction.z>0.?0.:1.); }
@@ -7091,34 +7091,34 @@ 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 ) ) );"),m=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()"),_=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>",_).replace("#include <normal_fragment_maps>",m).replace("#include <map_fragment>",l).replace("#include <roughnessmap_fragment>",s).replace("vec3 Fcc = F_Schlick",`
7094
+ `+s.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 ) ) );"),m=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;"),i=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()"),_=Ut.lights_fragment_maps.replaceAll(/(getIBL(?:Irradiance|Radiance|AnisotropyRadiance)\([^;]+\))/g,"$1 * blenderInfiniteTransmission()");s.fragmentShader=s.fragmentShader.replace("#include <lights_physical_fragment>",u).replace("#include <lights_fragment_begin>",c).replace("#include <lights_fragment_maps>",_).replace("#include <normal_fragment_maps>",m).replace("#include <map_fragment>",l).replace("#include <roughnessmap_fragment>",i).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`),hi(o,i)},o.needsUpdate=!0}r.blenderCoatIor.value=Math.max(1,e.coat_ior),r.blenderCoatTint.value.setRGB(...e.coat_tint,vt),r.blenderMapClip.value=n.map===!0,r.blenderRoughnessClip.value=n.roughness===!0,r.blenderNormalClip.value=n.normal===!0}function Oo(o){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(o);const n=at(o)(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(o){const t=Oo(o);if(typeof t!="number")throw new Error("World volume scalar input resolved to a color");return Math.max(0,t)}function On(o){const t=Oo(o);return(typeof t=="number"?new x().setScalar(t):t.clone()).max(new x)}function Oi(o){if(o<800)return new x(5.413294490189271,0,0);if(o>=12e3)return new x(.8262954810464208,.9945080501520986,1.566307710274283);const t=[965,1167,1449,1902,3315,6365].filter(a=>o>=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],e=[[-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]/o+n[1]*o+n[2],e[0]/o+e[1]*o+e[2],((r[0]*o+r[1])*o+r[2])*o+r[3]).max(new x)}function Zo(o){if(!o?.volume?.length)return null;const t={extinction:new x,emission:new x,lobes:[]};for(const n of o.volume){const e=Yt(n.weight);if(e===0)continue;const r=On(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 m=Oo(n.anisotropy);if(typeof m!="number")throw new Error("World volume anisotropy must be scalar");t.lobes.push({coefficient:f.clone().multiplyScalar(e),g:u==="RAYLEIGH"?0:xt.clamp(m,-.999,.999),alpha:u==="RAYLEIGH"?1:u==="DRAINE"?Yt(n.alpha):0})}if(n.kind==="principled"){const u=On(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 m=Yt(n.blackbody_intensity);if(m>.001){const l=Yt(n.temperature),s=5670373e-20/Math.PI*(1+m*(l**4-1));t.emission.add(Oi(l).multiply(On(n.blackbody_tint)).multiplyScalar(s*e))}}(n.kind==="principled"||n.kind==="emission")&&t.emission.add((n.kind==="emission"?r:On(n.emission_color)).multiplyScalar(Yt(n.emission_strength)*e)),t.extinction.add(i.add(f).multiplyScalar(e))}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 Ai{constructor(t){this.medium=t,this.target=new aa(1,1,{type:ho,depthBuffer:!1}),this.geometry=new _e(2,2),this.scene=new ra,this.camera=new ia}render(t,n,e,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,m=2;e.traverseVisible(_=>{if(!(_ instanceof Jn||_ instanceof to||_ instanceof Mn))return;const d=_,h=u++,v=d.getWorldPosition(new x);a[`lp${h}`]={value:v},a[`lc${h}`]={value:d.color.clone().multiplyScalar(d.intensity)},i+=`uniform vec3 lp${h}, lc${h};
7101
- `;let p="1.0",g="1.0";if(d instanceof to&&(a[`ld${h}`]={value:d.target.getWorldPosition(new x).sub(v).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
- `,g=`smoothstep(cone${h}.x, max(cone${h}.x+1e-6,cone${h}.y),dot(-L,ld${h}))`),!(d instanceof Mn)&&d.castShadow&&d.shadow.map){if(++m>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 Jn?`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 Mn){const b=new q().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`),ps(o,s)},o.needsUpdate=!0}r.blenderCoatIor.value=Math.max(1,e.coat_ior),r.blenderCoatTint.value.setRGB(...e.coat_tint,vt),r.blenderMapClip.value=n.map===!0,r.blenderRoughnessClip.value=n.roughness===!0,r.blenderNormalClip.value=n.normal===!0}function Ao(o){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(o);const n=at(o)(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(o){const t=Ao(o);if(typeof t!="number")throw new Error("World volume scalar input resolved to a color");return Math.max(0,t)}function An(o){const t=Ao(o);return(typeof t=="number"?new x().setScalar(t):t.clone()).max(new x)}function As(o){if(o<800)return new x(5.413294490189271,0,0);if(o>=12e3)return new x(.8262954810464208,.9945080501520986,1.566307710274283);const t=[965,1167,1449,1902,3315,6365].filter(a=>o>=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],e=[[-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]/o+n[1]*o+n[2],e[0]/o+e[1]*o+e[2],((r[0]*o+r[1])*o+r[2])*o+r[3]).max(new x)}function Qo(o){if(!o?.volume?.length)return null;const t={extinction:new x,emission:new x,lobes:[]};for(const n of o.volume){const e=Yt(n.weight);if(e===0)continue;const r=An(n.color),a=Yt(n.density),s=new x,f=new x;if(n.kind==="absorption"&&s.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 m=Ao(n.anisotropy);if(typeof m!="number")throw new Error("World volume anisotropy must be scalar");t.lobes.push({coefficient:f.clone().multiplyScalar(e),g:u==="RAYLEIGH"?0:xt.clamp(m,-.999,.999),alpha:u==="RAYLEIGH"?1:u==="DRAINE"?Yt(n.alpha):0})}if(n.kind==="principled"){const u=An(n.absorption_color);s.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 m=Yt(n.blackbody_intensity);if(m>.001){const l=Yt(n.temperature),i=5670373e-20/Math.PI*(1+m*(l**4-1));t.emission.add(As(l).multiply(An(n.blackbody_tint)).multiplyScalar(i*e))}}(n.kind==="principled"||n.kind==="emission")&&t.emission.add((n.kind==="emission"?r:An(n.emission_color)).multiplyScalar(Yt(n.emission_strength)*e)),t.extinction.add(s.add(f).multiplyScalar(e))}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 Ts{constructor(t){this.medium=t,this.target=new ra(1,1,{type:ho,depthBuffer:!1}),this.geometry=new de(2,2),this.scene=new sa,this.camera=new ia}render(t,n,e,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 s="",f="",u=0,m=2;e.traverseVisible(_=>{if(!(_ instanceof Jn||_ instanceof to||_ instanceof Pn))return;const d=_,h=u++,v=d.getWorldPosition(new x);a[`lp${h}`]={value:v},a[`lc${h}`]={value:d.color.clone().multiplyScalar(d.intensity)},s+=`uniform vec3 lp${h}, lc${h};
7101
+ `;let p="1.0",g="1.0";if(d instanceof to&&(a[`ld${h}`]={value:d.target.getWorldPosition(new x).sub(v).normalize()},a[`cone${h}`]={value:new Gt(Math.cos(d.angle),Math.cos(d.angle*(1-d.penumbra)))},s+=`uniform vec3 ld${h}; uniform vec2 cone${h};
7102
+ `,g=`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(++m>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},s+=`uniform sampler2D sm${h}; uniform mat4 sx${h}; uniform vec2 ss${h}; uniform float sb${h},sn${h},sf${h};
7103
+ `,p=d instanceof Jn?`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 H().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)},s+=`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);
7107
7107
  sum+=lc${h}*exp(-sigma*d)*phase(dot(L,ray))*max(dot(-L,ln${h}),0.)*
7108
7108
  length(lx${h})*length(ly${h})/(16.*max(d*d,1e-4)); }
7109
- `}else a[`cut${h}`]={value:d.distance},a[`decay${h}`]={value:d.decay},i+=`uniform float cut${h},decay${h};
7109
+ `}else a[`cut${h}`]={value:d.distance},a[`decay${h}`]={value:d.decay},s+=`uniform float cut${h},decay${h};
7110
7110
  `,f+=`{ vec3 delta=lp${h}-p; float d=length(delta); vec3 L=delta/max(d,1e-6);
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))*${g}*${p}*cutoff/max(pow(d,decay${h}),.01); }
7113
- `});let l="vec3 result=vec3(0.);";this.medium.lobes.forEach((_,d)=>{a[`scatter${d}`]={value:_.coefficient},a[`g${d}`]={value:_.g},a[`a${d}`]={value:_.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(_=>_>0);a.range={value:s.length?20/Math.min(...s):1},this.material?.dispose(),this.material=new mo({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:`
7113
+ `});let l="vec3 result=vec3(0.);";this.medium.lobes.forEach((_,d)=>{a[`scatter${d}`]={value:_.coefficient},a[`g${d}`]={value:_.g},a[`a${d}`]={value:_.alpha},s+=`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 i=this.medium.extinction.toArray().filter(_=>_>0);a.range={value:i.length?20/Math.min(...i):1},this.material?.dispose(),this.material=new mo({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>
7118
7118
  varying vec2 vUv; uniform sampler2D surface,depth;
7119
7119
  uniform mat4 inverseProjection,cameraWorld; uniform bool orthographic;
7120
7120
  uniform vec3 sigma,emission; uniform float range;
7121
- ${i}
7121
+ ${s}
7122
7122
  vec3 phase(float c){${l} return result;}
7123
7123
  vec3 incident(vec3 p,vec3 ray){vec3 sum=vec3(0.);${f}return sum;}
7124
7124
  float integral(float s,float d){float x=s*d;return x<.001 ? d*(1.-x*.5+x*x/6.) : (1.-exp(-x))/s;}
@@ -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 Ti=M({object:R(),group:R(),groupIndex:N().int().nonnegative(),count:N().int().nonnegative(),digest:R(),alertMode:H(["NONE","ACTIVE","ALL"]),unchanged:W(!0).optional(),weightsBase64:R().optional(),alertBase64:R().optional()}).strict();function Si(o){const n=o<0?0:o>1?1:o,e=(.5+.5*n)**1.5,[r,a,i]=Mi(2/3*(1-n)),f=new wt;return f.setRGB((r*e)**(1/1.5),(a*e)**(1/1.5),(i*e)**(1/1.5),$t),f}function Mi(o){const t=(o%1+1)%1,n=Math.floor(t*6),e=t*6-n;switch(n%6){case 0:return[1,e,0];case 1:return[1-e,1,0];case 2:return[0,1,e];case 3:return[0,1-e,1];case 4:return[e,0,1];default:return[1,0,1-e]}}const Pi=0;function Qo(o){const t=atob(o),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}class Ei{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,e){if(t===null||n===null||!n.isMesh||e===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=Qo(t.weightsBase64);this.held={key:r,weights:new Float32Array(d.buffer,d.byteOffset,t.count),alerts:Qo(t.alertBase64)}}const a=this.held;if(a===null)return null;const i=`${r}:${t.digest}:${n.geometry.uuid}:${t.alertMode}:${e.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"),m=f.getAttribute("blenderVertex");if(m===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 wt().setHex(Pi,$t);for(let d=0;d<u.count;d++){const h=m.getX(d),p=t.alertMode!=="NONE"&&a.alerts[h]===1?s:Si(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 dt(l,3)),f.deleteAttribute("blenderVertex");const c=new Nn({vertexColors:!0,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1}),_=new Rt(f,c);return _.name=`${t.object}:weights`,_.frustumCulled=!1,_.matrixAutoUpdate=!1,_.matrix.copy(e),_.matrix.decompose(_.position,_.quaternion,_.scale),this.geometry=f,this.material=c,this.mesh=_,this.group.add(_),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(),Ni=D(L([An,An,An,An])).length(4),Ri=20,Ko=[16724818,9165824,2658559];function Ii(o){const t=n=>Math.min(255,Math.max(0,Math.floor(.75*n+63.75)-60))/255;return new wt().setRGB(t(o>>16&255),t(o>>8&255),t(o&255),$t)}function $e(){return new la({vertexColors:!0,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1})}function zi(){const o=[],t=[],n=new wt(0,0,0),e=(a,i,f,u,m)=>{for(const l of[a,i]){const s=[0,0,0];s[f]=l*u,o.push(...s),t.push(m.r,m.g,m.b)}};for(let a=0;a<3;a++){const i=new wt().setHex(Ko[a],$t);e(1,.85,a,1,i),e(.85,.25,a,1,n),e(1,.85,a,-1,Ii(Ko[a])),e(.85,.25,a,-1,n)}const r=new vn;return r.setAttribute("position",new Mt(o,3)),r.setAttribute("color",new Mt(t,3)),new me(r,$e())}function Fi(){const t=[],n=[],e=new wt(1,0,0),r=new wt(1,1,1);for(let i=0;i<12;i++){const f=(i+1)%2===0?r:e;for(const u of[i,i+1]){const m=2*Math.PI*u/12;t.push(.5*Math.cos(m),.5*Math.sin(m),0),n.push(f.r,f.g,f.b)}}const a=new vn;return a.setAttribute("position",new Mt(t,3)),a.setAttribute("color",new Mt(n,3)),new me(a,$e())}class Di{constructor(){this.group=new it,this.anchor=new it,this.lines=zi(),this.circle=Fi(),this.seen=null,this.size=new Gt,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,e)=>this.fit(t,e),this.circle.onBeforeRender=(t,n,e)=>this.fit(t,e)}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,e,r,a]=t.rotation;this.anchor.matrix.compose(new x(...t.location),new At(e,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 e=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/e}else{const f=n;a=2*Math.max(-r.applyMatrix4(n.matrixWorldInverse).z,1e-6)*Math.tan(xt.degToRad(f.fov)/2)/f.zoom/e}const i=a*Ri;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,e,r,a){const i=this.seen;if(i===null||e!==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),m=new sa;m.setFromCamera(u,i.camera);const l=h=>{for(let v=h;v!==null;v=v.parent)if(!v.visible)return!1;return!0},s=m.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),v=i.camera.getWorldDirection(new x),p=i.camera.getWorldPosition(new x),g=h.clone().sub(p).dot(v);g<=0&&h.addScaledVector(v,-2*g+(g===0?1:0)),c=m.ray.intersectPlane(new Bt().setFromNormalAndCoplanarPoint(v,h),new x)}if(c===null)return null;r.updateWorldMatrix(!0,!1);const _=r.worldToLocal(c),d=r.getWorldQuaternion(new At).invert().multiply(i.camera.getWorldQuaternion(new At));return{location:[_.x,_.y,_.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(),Ci=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},ki=1,ot=(o,t,n)=>o.push(t[0],t[1],t[2],n[0],n[1],n[2]);function ut(o,t){return Array.from({length:t},(n,e)=>{const r=2*Math.PI*e/t;return[o*Math.cos(r),o*Math.sin(r)]})}function gt(o,t,n=0,e=!1){const r=e?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(o,[i[0],i[1],n],[f[0],f[1],n])}}function $i(o){if(!o.isMesh||o.userData.volterOverrideStandDown)return;o.userData.volterOverrideStandDown=!0;const t=o.onBeforeRender.bind(o),n=o.onAfterRender.bind(o),e=new q;let r=!1;o.onBeforeRender=(a,i,f,u,m,l)=>{t(a,i,f,u,m,l),i.overrideMaterial&&(e.copy(o.matrixWorld),o.matrixWorld.makeScale(0,0,0),r=!0)},o.onAfterRender=(a,i,f,u,m,l)=>{r&&(o.matrixWorld.copy(e),r=!1),n(a,i,f,u,m,l)}}class Li{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 At,this.cameras.name="BlenderCameras",this.lights.name="BlenderLights",this.empties.name="BlenderEmpties"}apply(t){const n=new Set;for(const e of t.objects){const r=e.selected?e.name===t.active?Et.active:Et.selected:e.type==="CAMERA"?Et.camera:e.type==="LIGHT"?Et.light:Et.empty,a=e.type==="CAMERA"&&e.name!==t.lookingThrough?t.cameras[e.name]:void 0,i=e.type==="LIGHT"&&e.light?t.lights[e.light]:void 0,f=e.type==="EMPTY"?t.empties[e.name]:void 0;if(!a&&!i&&!f)continue;n.add(e.name);const u=i&&e.light?t.lightDistances[e.light]??null:null,m=f?.image?.name?t.image(f.image.name):null,l=JSON.stringify([m?[m.texture.uuid,m.width,m.height]:null,e.matrix,r,a,i,u,f,a?[e.name===t.sceneCamera,t.renderAspect]:null]),s=this.drawn.get(e.name),c=t.presented(e.name);if(s?.key===l){for(const p of s.parts)p.userData.volterPicksAs=c;continue}s&&this.remove(s.parts);const _=new q().set(...e.matrix.flat()),d=a?this.cameras:i?this.lights:this.empties,h=new Set(d.children);a?this.camera(a,_,r,e.name===t.sceneCamera,t.renderAspect):i?this.light(i,_,r,u):f&&this.empty(f,_,r,m);const v=d.children.filter(p=>!h.has(p));for(const p of v)p.userData.volterPicksAs=c,p.traverse($i);this.drawn.set(e.name,{key:l,parts:v})}for(const[e,r]of this.drawn)n.has(e)||(this.remove(r.parts),this.drawn.delete(e))}remove(t){for(const n of t)n.removeFromParent(),n.geometry?.dispose(),n.userData.volterOwnMaterial&&n.material.dispose()}camera(t,n,e,r,a){const i=t.display_size,u=(t.sensor_fit==="AUTO"?a>=1:t.sensor_fit==="HORIZONTAL")?[1,1/a]:[a,1];let m,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,m=.5*t.ortho_scale;else{const T=.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;m=i/2/((1/O.x+1/O.y+1/O.z)/3),l=m*t.lens/-T,s=[m*u[0],m*u[1]],c=[t.shift_x*m*2,t.shift_y*m*2]}const _=[[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 T=0;T<4;T++)ot(d,_[T],_[(T+1)%4]),ot(d,_[T],[0,0,0]);const h=.7*m,v=.1*m,p=c[1]+s[1]+v,g=[[c[0]-h,p,l],[c[0]+h,p,l],[c[0],p+h,l]],b=Zn(n);this.cameras.add(this.lines(d,e,1,b));let y;if(r){const T=new vn;T.setAttribute("position",new Mt(g.flat(),3)),y=new Rt(T,this.fill(e)),y.matrixAutoUpdate=!1,y.matrix.copy(b)}else{const T=[];for(let O=0;O<3;O++)ot(T,g[O],g[(O+1)%3]);y=this.lines(T,e,1,b)}const S=new x,A=y.onBeforeRender.bind(y);y.onBeforeRender=(T,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),A(T,O,E,k,j,G)},this.cameras.add(y)}light(t,n,e,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 q));const f=[];gt(f,ut(1.35,4)),this.lights.add(this.screen(f,Et.light,Et.lightAlpha,new x(a.x,a.y,0)));const u=[],m=9;if(gt(u,ut(m*.3,4)),gt(u,ut(m,16),0,!0),gt(u,ut(m*1.33,20),0,!0),t.type==="SUN")for(const[c,_]of ut(m,8))ot(u,[c*1.6,_*1.6,0],[c*1.9,_*1.9,0]),ot(u,[c*2.2,_*2.2,0],[c*2.5,_*2.5,0]);this.lights.add(this.screen(u,e,1,a));const l=Zn(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,_=(t.shape==="RECTANGLE"||t.shape==="ELLIPSE"?t.size_y??t.size??1:t.size??1)/2;t.shape==="DISK"||t.shape==="ELLIPSE"?gt(s,ut(1,32).map(([d,h])=>[d*c,h*_])):gt(s,[[c,_],[-c,_],[-c,-_],[c,-_]])}if(s.length>0&&this.lights.add(this.lines(s,e,1,n.clone())),r&&(t.type==="SPOT"||t.type==="AREA")){const c=new x(0,0,-1).transformDirection(n),_=p=>a.clone().addScaledVector(c,p),[d,h]=r,v=[];ot(v,_(d).toArray(),_(h).toArray()),this.lights.add(this.lines(v,e,1,new q));for(const p of[d,h]){const g=[];gt(g,ut(1.2,4)),this.lights.add(this.screen(g,e,1,_(p)))}}if(t.type==="SPOT"){const c=(t.spot_size??Math.PI/4)/2,_=Math.cos(c),d=t.spot_blend??.15,h=_*d-_-d,v=Math.sqrt((_*_-_*_*h*h)/(h*h-_*_*h*h)),p=Math.sqrt(1-_*_),g=Zn(n).multiply(new q().makeScale(10,10,10)),b=[];gt(b,ut(p,32),-_),gt(b,ut(p*v,32),-_),this.lights.add(this.lines(b,e,1,g.clone())),this.lights.add(this.silhouette(p,_,e,g))}if((t.type==="POINT"||t.type==="SPOT")&&(t.radius??0)>0){const c=[];gt(c,ut(t.radius,32)),this.lights.add(this.facing(c,e,new x().setFromMatrixPosition(l)))}}empty(t,n,e,r){const a=t.size,i=[],f=(m,l)=>{const s=ut(1,l);for(let c=0;c<l;c++){const[_,d]=s[c],[h,v]=s[(c+1)%l],p=(g,b)=>m==="xy"?[g,b,0]:m==="xz"?[g,0,b]:[0,g,b];ot(i,p(_,d),p(h,v))}};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[m,l]of[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]])ot(i,[0,0,1],[m,l,.75]);gt(i,[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]],.75);break}case"CUBE":for(const[m,l]of Vi)ot(i,Jo[m],Jo[l]);break;case"CIRCLE":f("xz",64);break;case"SPHERE":f("xy",32),f("xz",32),f("yz",32);break;case"CONE":{const m=ut(1,8);for(let l=0;l<8;l++){const[s,c]=m[l],[_,d]=m[(l+1)%8];ot(i,[s,0,c],[0,2,0]),ot(i,[s,0,c],[_,0,d])}break}case"ARROWS":for(let m=0;m<3;m++){const l=[0,0,0];l[m]=1,ot(i,[0,0,0],l)}break;case"IMAGE":this.imageEmpty(t,n,e,r);return}const u=n.clone().multiply(new q().makeScale(a,a,a));this.empties.add(this.lines(i,e,1,u)),t.display==="ARROWS"&&this.axisNames(n,a,e)}silhouette(t,n,e,r){const a=this.lines(new Array(192).fill(0),e,1,r);a.frustumCulled=!1;const i=a.geometry.getAttribute("instanceStart").data,f=ut(1,32).map(([_,d])=>new x(_*t,d*t,-n)),u=new x,m=new q,l=new x,s=new x,c=new x;return this.onDraw(a,(_,d)=>{m.copy(a.matrixWorld).invert();const h=d.isOrthographicCamera;h?d.getWorldDirection(u).negate().transformDirection(m):u.setFromMatrixPosition(d.matrixWorld).applyMatrix4(m);const v=i.array;let p=!1;for(let g=0;g<32;g++){const b=f[g];l.crossVectors(b,f[(g+31)%32]),s.crossVectors(f[(g+1)%32],b),h?c.copy(u):c.copy(u).sub(b);const y=l.dot(c)>0!=s.dot(c)>0;(v[g*6+3]!==0||v[g*6+5]!==0)!==y&&(p=!0),v.set([0,0,0,y?b.x:0,y?b.y:0,y?b.z:0],g*6)}p&&(i.needsUpdate=!0,Ot())}),a}imageEmpty(t,n,e,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],m=new x,l=new x,s=new x;n.extractBasis(m,l,s),m.multiplyScalar(u[0]*.5*t.size),l.multiplyScalar(u[1]*.5*t.size);const c=new x().setFromMatrixPosition(n).addScaledVector(m,a.offset[0]*2+1).addScaledVector(l,a.offset[1]*2+1),_=new q().makeBasis(m,l,s.clone()).setPosition(c),d=[];gt(d,[[-1,-1],[1,-1],[1,1],[-1,1]]);const h=this.lines(d,e,1,_),v=s.clone().normalize(),p=new x,g=new x,b=(E,k)=>{const j=E.isOrthographicCamera===!0;if(j?!a.orthographic:!a.perspective)return!1;if(!k)return!0;const G=v.clone().transformDirection(this.empties.matrixWorld);E.getWorldDirection(g);let K,J;if(j)K=G.dot(g.clone().negate()),J=1e-5;else{const lt=c.clone().applyMatrix4(this.empties.matrixWorld);K=G.dot(p.setFromMatrixPosition(E.matrixWorld).sub(lt)),J=0}return!(a.side==="FRONT"&&K<J||a.side==="BACK"&&K>-J||a.axis_aligned&&G.clone().projectOnPlane(g).lengthSq()>1e-5)},y=(E,k)=>{const j=E.onBeforeRender.bind(E);E.onBeforeRender=(G,K,J,lt,w,V)=>{E.matrix.copy(_),b(J,k)||E.matrix.scale(new x(0,0,0)),E.updateMatrixWorld(!0),j(G,K,J,lt,w,V)}};if(y(h,!1),this.empties.add(h),!r||a.opacity!==null&&a.opacity<=0)return;const S=a.opacity!==null,A=a.depth==="BACK",T=new Nn({map:r.texture,side:no,transparent:S&&!A,opacity:a.opacity??1,alphaTest:S?0:.05,toneMapped:!1,depthTest:a.depth==="DEFAULT",depthWrite:a.depth==="DEFAULT"&&!S});T.color.setRGB(...a.tint,vt),S&&A&&(T.blending=fa,T.blendSrc=ca,T.blendDst=ua),T.onBeforeCompile=E=>{const k=a.premultiplied?`if ( sampledDiffuseColor.a > 0.0 && sampledDiffuseColor.a < 1.0 ) sampledDiffuseColor.rgb /= sampledDiffuseColor.a;
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 Ss=M({object:R(),group:R(),groupIndex:N().int().nonnegative(),count:N().int().nonnegative(),digest:R(),alertMode:q(["NONE","ACTIVE","ALL"]),unchanged:W(!0).optional(),weightsBase64:R().optional(),alertBase64:R().optional()}).strict();function Ms(o){const n=o<0?0:o>1?1:o,e=(.5+.5*n)**1.5,[r,a,s]=Ps(2/3*(1-n)),f=new Ot;return f.setRGB((r*e)**(1/1.5),(a*e)**(1/1.5),(s*e)**(1/1.5),$t),f}function Ps(o){const t=(o%1+1)%1,n=Math.floor(t*6),e=t*6-n;switch(n%6){case 0:return[1,e,0];case 1:return[1-e,1,0];case 2:return[0,1,e];case 3:return[0,1-e,1];case 4:return[e,0,1];default:return[1,0,1-e]}}const Es=0;function Ko(o){const t=atob(o),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}class Ns{constructor(){this.group=new st,this.mesh=null,this.material=null,this.geometry=null,this.held=null,this.signature="",this.group.name="BlenderWeightOverlay"}apply(t,n,e){if(t===null||n===null||!n.isMesh||e===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=Ko(t.weightsBase64);this.held={key:r,weights:new Float32Array(d.buffer,d.byteOffset,t.count),alerts:Ko(t.alertBase64)}}const a=this.held;if(a===null)return null;const s=`${r}:${t.digest}:${n.geometry.uuid}:${t.alertMode}:${e.elements.join(",")}`;if(s===this.signature&&this.mesh!==null)return null;this.signature=s,this.clear();const f=n.geometry.clone(),u=f.getAttribute("position"),m=f.getAttribute("blenderVertex");if(m===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),i=new Ot().setHex(Es,$t);for(let d=0;d<u.count;d++){const h=m.getX(d),p=t.alertMode!=="NONE"&&a.alerts[h]===1?i:Ms(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 dt(l,3)),f.deleteAttribute("blenderVertex");const c=new Rn({vertexColors:!0,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1}),_=new Rt(f,c);return _.name=`${t.object}:weights`,_.frustumCulled=!1,_.matrixAutoUpdate=!1,_.matrix.copy(e),_.matrix.decompose(_.position,_.quaternion,_.scale),this.geometry=f,this.material=c,this.mesh=_,this.group.add(_),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 Tn=N().finite(),Rs=F(L([Tn,Tn,Tn,Tn])).length(4),Is=20,Jo=[16724818,9165824,2658559];function zs(o){const t=n=>Math.min(255,Math.max(0,Math.floor(.75*n+63.75)-60))/255;return new Ot().setRGB(t(o>>16&255),t(o>>8&255),t(o&255),$t)}function Le(){return new fa({vertexColors:!0,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1})}function Ds(){const o=[],t=[],n=new Ot(0,0,0),e=(a,s,f,u,m)=>{for(const l of[a,s]){const i=[0,0,0];i[f]=l*u,o.push(...i),t.push(m.r,m.g,m.b)}};for(let a=0;a<3;a++){const s=new Ot().setHex(Jo[a],$t);e(1,.85,a,1,s),e(.85,.25,a,1,n),e(1,.85,a,-1,zs(Jo[a])),e(.85,.25,a,-1,n)}const r=new gn;return r.setAttribute("position",new Mt(o,3)),r.setAttribute("color",new Mt(t,3)),new he(r,Le())}function Fs(){const t=[],n=[],e=new Ot(1,0,0),r=new Ot(1,1,1);for(let s=0;s<12;s++){const f=(s+1)%2===0?r:e;for(const u of[s,s+1]){const m=2*Math.PI*u/12;t.push(.5*Math.cos(m),.5*Math.sin(m),0),n.push(f.r,f.g,f.b)}}const a=new gn;return a.setAttribute("position",new Mt(t,3)),a.setAttribute("color",new Mt(n,3)),new he(a,Le())}class Cs{constructor(){this.group=new st,this.anchor=new st,this.lines=Ds(),this.circle=Fs(),this.seen=null,this.size=new Gt,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,e)=>this.fit(t,e),this.circle.onBeforeRender=(t,n,e)=>this.fit(t,e)}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,e,r,a]=t.rotation;this.anchor.matrix.compose(new x(...t.location),new At(e,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 e=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/e}else{const f=n;a=2*Math.max(-r.applyMatrix4(n.matrixWorldInverse).z,1e-6)*Math.tan(xt.degToRad(f.fov)/2)/f.zoom/e}const s=a*Is;this.lines.scale.setScalar(s),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(s),this.circle.updateMatrixWorld(!0)}placementAt(t,n,e,r,a){const s=this.seen;if(s===null||e!==s.canvas)return null;const f=s.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),m=new la;m.setFromCamera(u,s.camera);const l=h=>{for(let v=h;v!==null;v=v.parent)if(!v.visible)return!1;return!0},i=m.intersectObject(r,!0).find(h=>h.object.isMesh&&a(h.object)&&l(h.object));let c=i?i.point.clone():null;if(c===null){const h=new x().setFromMatrixPosition(this.anchor.matrixWorld),v=s.camera.getWorldDirection(new x),p=s.camera.getWorldPosition(new x),g=h.clone().sub(p).dot(v);g<=0&&h.addScaledVector(v,-2*g+(g===0?1:0)),c=m.ray.intersectPlane(new Bt().setFromNormalAndCoplanarPoint(v,h),new x)}if(c===null)return null;r.updateWorldMatrix(!0,!1);const _=r.worldToLocal(c),d=r.getWorldQuaternion(new At).invert().multiply(s.camera.getWorldQuaternion(new At));return{location:[_.x,_.y,_.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(),ks=M({display:q(["PLAIN_AXES","ARROWS","SINGLE_ARROW","CIRCLE","CUBE","SPHERE","CONE","IMAGE"]),size:jt,image:M({name:R().nullable(),offset:L([jt,jt]),depth:q(["DEFAULT","FRONT","BACK"]),side:q(["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},$s=1,ot=(o,t,n)=>o.push(t[0],t[1],t[2],n[0],n[1],n[2]);function ut(o,t){return Array.from({length:t},(n,e)=>{const r=2*Math.PI*e/t;return[o*Math.cos(r),o*Math.sin(r)]})}function gt(o,t,n=0,e=!1){const r=e?2:1;for(let a=0;a<Math.floor(t.length/r);a++){const s=t[a*r%t.length],f=t[(a*r+1)%t.length];ot(o,[s[0],s[1],n],[f[0],f[1],n])}}function Ls(o){if(!o.isMesh||o.userData.volterOverrideStandDown)return;o.userData.volterOverrideStandDown=!0;const t=o.onBeforeRender.bind(o),n=o.onAfterRender.bind(o),e=new H;let r=!1;o.onBeforeRender=(a,s,f,u,m,l)=>{t(a,s,f,u,m,l),s.overrideMaterial&&(e.copy(o.matrixWorld),o.matrixWorld.makeScale(0,0,0),r=!0)},o.onAfterRender=(a,s,f,u,m,l)=>{r&&(o.matrixWorld.copy(e),r=!1),n(a,s,f,u,m,l)}}class Vs{constructor(){this.cameras=new st,this.lights=new st,this.empties=new st,this.lineMaterials=new Map,this.drawn=new Map,this.fillMaterials=new Map,this.scratch=new x,this.size=new Gt,this.parentQuat=new At,this.cameras.name="BlenderCameras",this.lights.name="BlenderLights",this.empties.name="BlenderEmpties"}apply(t){const n=new Set;for(const e of t.objects){const r=e.selected?e.name===t.active?Et.active:Et.selected:e.type==="CAMERA"?Et.camera:e.type==="LIGHT"?Et.light:Et.empty,a=e.type==="CAMERA"&&e.name!==t.lookingThrough?t.cameras[e.name]:void 0,s=e.type==="LIGHT"&&e.light?t.lights[e.light]:void 0,f=e.type==="EMPTY"?t.empties[e.name]:void 0;if(!a&&!s&&!f)continue;n.add(e.name);const u=s&&e.light?t.lightDistances[e.light]??null:null,m=f?.image?.name?t.image(f.image.name):null,l=JSON.stringify([m?[m.texture.uuid,m.width,m.height]:null,e.matrix,r,a,s,u,f,a?[e.name===t.sceneCamera,t.renderAspect]:null]),i=this.drawn.get(e.name),c=t.presented(e.name);if(i?.key===l){for(const p of i.parts)p.userData.volterPicksAs=c;continue}i&&this.remove(i.parts);const _=new H().set(...e.matrix.flat()),d=a?this.cameras:s?this.lights:this.empties,h=new Set(d.children);a?this.camera(a,_,r,e.name===t.sceneCamera,t.renderAspect):s?this.light(s,_,r,u):f&&this.empty(f,_,r,m);const v=d.children.filter(p=>!h.has(p));for(const p of v)p.userData.volterPicksAs=c,p.traverse(Ls);this.drawn.set(e.name,{key:l,parts:v})}for(const[e,r]of this.drawn)n.has(e)||(this.remove(r.parts),this.drawn.delete(e))}remove(t){for(const n of t)n.removeFromParent(),n.geometry?.dispose(),n.userData.volterOwnMaterial&&n.material.dispose()}camera(t,n,e,r,a){const s=t.display_size,u=(t.sensor_fit==="AUTO"?a>=1:t.sensor_fit==="HORIZONTAL")?[1,1/a]:[a,1];let m,l,i,c;if(t.type==="ORTHO")i=[.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=-s,m=.5*t.ortho_scale;else{const T=.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;m=s/2/((1/O.x+1/O.y+1/O.z)/3),l=m*t.lens/-T,i=[m*u[0],m*u[1]],c=[t.shift_x*m*2,t.shift_y*m*2]}const _=[[c[0]+i[0],c[1]+i[1],l],[c[0]+i[0],c[1]-i[1],l],[c[0]-i[0],c[1]-i[1],l],[c[0]-i[0],c[1]+i[1],l]],d=[];for(let T=0;T<4;T++)ot(d,_[T],_[(T+1)%4]),ot(d,_[T],[0,0,0]);const h=.7*m,v=.1*m,p=c[1]+i[1]+v,g=[[c[0]-h,p,l],[c[0]+h,p,l],[c[0],p+h,l]],b=Zn(n);this.cameras.add(this.lines(d,e,1,b));let y;if(r){const T=new gn;T.setAttribute("position",new Mt(g.flat(),3)),y=new Rt(T,this.fill(e)),y.matrixAutoUpdate=!1,y.matrix.copy(b)}else{const T=[];for(let O=0;O<3;O++)ot(T,g[O],g[(O+1)%3]);y=this.lines(T,e,1,b)}const S=new x,A=y.onBeforeRender.bind(y);y.onBeforeRender=(T,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),A(T,O,E,k,j,G)},this.cameras.add(y)}light(t,n,e,r){const a=new x().setFromMatrixPosition(n),s=[];ot(s,[a.x,a.y,a.z],[a.x,a.y,0]),this.lights.add(this.lines(s,Et.light,Et.lightAlpha,new H));const f=[];gt(f,ut(1.35,4)),this.lights.add(this.screen(f,Et.light,Et.lightAlpha,new x(a.x,a.y,0)));const u=[],m=9;if(gt(u,ut(m*.3,4)),gt(u,ut(m,16),0,!0),gt(u,ut(m*1.33,20),0,!0),t.type==="SUN")for(const[c,_]of ut(m,8))ot(u,[c*1.6,_*1.6,0],[c*1.9,_*1.9,0]),ot(u,[c*2.2,_*2.2,0],[c*2.5,_*2.5,0]);this.lights.add(this.screen(u,e,1,a));const l=Zn(n),i=[];if(t.type==="SUN")ot(i,[0,0,0],[0,0,-20]);else if(t.type==="AREA"){const c=(t.size??1)/2,_=(t.shape==="RECTANGLE"||t.shape==="ELLIPSE"?t.size_y??t.size??1:t.size??1)/2;t.shape==="DISK"||t.shape==="ELLIPSE"?gt(i,ut(1,32).map(([d,h])=>[d*c,h*_])):gt(i,[[c,_],[-c,_],[-c,-_],[c,-_]])}if(i.length>0&&this.lights.add(this.lines(i,e,1,n.clone())),r&&(t.type==="SPOT"||t.type==="AREA")){const c=new x(0,0,-1).transformDirection(n),_=p=>a.clone().addScaledVector(c,p),[d,h]=r,v=[];ot(v,_(d).toArray(),_(h).toArray()),this.lights.add(this.lines(v,e,1,new H));for(const p of[d,h]){const g=[];gt(g,ut(1.2,4)),this.lights.add(this.screen(g,e,1,_(p)))}}if(t.type==="SPOT"){const c=(t.spot_size??Math.PI/4)/2,_=Math.cos(c),d=t.spot_blend??.15,h=_*d-_-d,v=Math.sqrt((_*_-_*_*h*h)/(h*h-_*_*h*h)),p=Math.sqrt(1-_*_),g=Zn(n).multiply(new H().makeScale(10,10,10)),b=[];gt(b,ut(p,32),-_),gt(b,ut(p*v,32),-_),this.lights.add(this.lines(b,e,1,g.clone())),this.lights.add(this.silhouette(p,_,e,g))}if((t.type==="POINT"||t.type==="SPOT")&&(t.radius??0)>0){const c=[];gt(c,ut(t.radius,32)),this.lights.add(this.facing(c,e,new x().setFromMatrixPosition(l)))}}empty(t,n,e,r){const a=t.size,s=[],f=(m,l)=>{const i=ut(1,l);for(let c=0;c<l;c++){const[_,d]=i[c],[h,v]=i[(c+1)%l],p=(g,b)=>m==="xy"?[g,b,0]:m==="xz"?[g,0,b]:[0,g,b];ot(s,p(_,d),p(h,v))}};switch(t.display){case"PLAIN_AXES":ot(s,[0,-1,0],[0,1,0]),ot(s,[-1,0,0],[1,0,0]),ot(s,[0,0,-1],[0,0,1]);break;case"SINGLE_ARROW":{ot(s,[0,0,0],[0,0,.75]);for(const[m,l]of[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]])ot(s,[0,0,1],[m,l,.75]);gt(s,[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]],.75);break}case"CUBE":for(const[m,l]of js)ot(s,te[m],te[l]);break;case"CIRCLE":f("xz",64);break;case"SPHERE":f("xy",32),f("xz",32),f("yz",32);break;case"CONE":{const m=ut(1,8);for(let l=0;l<8;l++){const[i,c]=m[l],[_,d]=m[(l+1)%8];ot(s,[i,0,c],[0,2,0]),ot(s,[i,0,c],[_,0,d])}break}case"ARROWS":for(let m=0;m<3;m++){const l=[0,0,0];l[m]=1,ot(s,[0,0,0],l)}break;case"IMAGE":this.imageEmpty(t,n,e,r);return}const u=n.clone().multiply(new H().makeScale(a,a,a));this.empties.add(this.lines(s,e,1,u)),t.display==="ARROWS"&&this.axisNames(n,a,e)}silhouette(t,n,e,r){const a=this.lines(new Array(192).fill(0),e,1,r);a.frustumCulled=!1;const s=a.geometry.getAttribute("instanceStart").data,f=ut(1,32).map(([_,d])=>new x(_*t,d*t,-n)),u=new x,m=new H,l=new x,i=new x,c=new x;return this.onDraw(a,(_,d)=>{m.copy(a.matrixWorld).invert();const h=d.isOrthographicCamera;h?d.getWorldDirection(u).negate().transformDirection(m):u.setFromMatrixPosition(d.matrixWorld).applyMatrix4(m);const v=s.array;let p=!1;for(let g=0;g<32;g++){const b=f[g];l.crossVectors(b,f[(g+31)%32]),i.crossVectors(f[(g+1)%32],b),h?c.copy(u):c.copy(u).sub(b);const y=l.dot(c)>0!=i.dot(c)>0;(v[g*6+3]!==0||v[g*6+5]!==0)!==y&&(p=!0),v.set([0,0,0,y?b.x:0,y?b.y:0,y?b.z:0],g*6)}p&&(s.needsUpdate=!0,wt())}),a}imageEmpty(t,n,e,r){const a=t.image;if(!a)return;const s=r?.width??0,f=r?.height??0,u=s>0&&f>0?s>=f?[1,f/s]:[s/f,1]:[1,1],m=new x,l=new x,i=new x;n.extractBasis(m,l,i),m.multiplyScalar(u[0]*.5*t.size),l.multiplyScalar(u[1]*.5*t.size);const c=new x().setFromMatrixPosition(n).addScaledVector(m,a.offset[0]*2+1).addScaledVector(l,a.offset[1]*2+1),_=new H().makeBasis(m,l,i.clone()).setPosition(c),d=[];gt(d,[[-1,-1],[1,-1],[1,1],[-1,1]]);const h=this.lines(d,e,1,_),v=i.clone().normalize(),p=new x,g=new x,b=(E,k)=>{const j=E.isOrthographicCamera===!0;if(j?!a.orthographic:!a.perspective)return!1;if(!k)return!0;const G=v.clone().transformDirection(this.empties.matrixWorld);E.getWorldDirection(g);let K,J;if(j)K=G.dot(g.clone().negate()),J=1e-5;else{const lt=c.clone().applyMatrix4(this.empties.matrixWorld);K=G.dot(p.setFromMatrixPosition(E.matrixWorld).sub(lt)),J=0}return!(a.side==="FRONT"&&K<J||a.side==="BACK"&&K>-J||a.axis_aligned&&G.clone().projectOnPlane(g).lengthSq()>1e-5)},y=(E,k)=>{const j=E.onBeforeRender.bind(E);E.onBeforeRender=(G,K,J,lt,w,V)=>{E.matrix.copy(_),b(J,k)||E.matrix.scale(new x(0,0,0)),E.updateMatrixWorld(!0),j(G,K,J,lt,w,V)}};if(y(h,!1),this.empties.add(h),!r||a.opacity!==null&&a.opacity<=0)return;const S=a.opacity!==null,A=a.depth==="BACK",T=new Rn({map:r.texture,side:no,transparent:S&&!A,opacity:a.opacity??1,alphaTest:S?0:.05,toneMapped:!1,depthTest:a.depth==="DEFAULT",depthWrite:a.depth==="DEFAULT"&&!S});T.color.setRGB(...a.tint,vt),S&&A&&(T.blending=ca,T.blendSrc=ua,T.blendDst=_a),T.onBeforeCompile=E=>{const k=a.premultiplied?`if ( sampledDiffuseColor.a > 0.0 && sampledDiffuseColor.a < 1.0 ) sampledDiffuseColor.rgb /= sampledDiffuseColor.a;
7145
7145
  `:"";E.fragmentShader=E.fragmentShader.replace("#include <map_fragment>",`vec4 sampledDiffuseColor = texture2D( map, vMapUv );
7146
7146
  ${k}diffuseColor *= sampledDiffuseColor;`).replace("#include <alphatest_fragment>",S?"#include <alphatest_fragment>":`#include <alphatest_fragment>
7147
- diffuseColor.a = 1.0;`)},T.customProgramCacheKey=()=>`volter-blender-image:${a.premultiplied}:${S}`;const O=new Rt(new _e(2,2),T);O.matrixAutoUpdate=!1,O.matrix.copy(_),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,e){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 m=[];for(let c=1;c<=6;c++)gt(m,ut(.007*(4*c/6)*i,4));this.empties.add(this.facing(m,e,u));const l=ji[a],s=[];for(let c=0;c+1<l.length;c+=2){const[_,d]=l[c],[h,v]=l[c+1];ot(s,[_*4*i,d*4*i,0],[h*4*i,v*4*i,0])}this.empties.add(this.facing(s,e,f))}}material(t,n){const e=`${t}:${n}`;let r=this.lineMaterials.get(e);return r||(r=new re({color:t,linewidth:ki,transparent:n<1,opacity:n,depthTest:!0,depthWrite:n>=1,toneMapped:!1}),this.lineMaterials.set(e,r)),r}fill(t){let n=this.fillMaterials.get(t);return n||(n=new Nn({color:t,side:no,toneMapped:!1}),this.fillMaterials.set(t,n)),n}lines(t,n,e,r){const a=new ae().setPositions(t),i=new ie(a,this.material(n,e));return i.matrixAutoUpdate=!1,i.matrix.copy(r),i.computeLineDistances(),i}screen(t,n,e,r){const a=this.lines(t,n,e,new q);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,e){const r=this.lines(t,n,1,new q);return r.matrixAutoUpdate=!0,r.position.copy(e),this.onDraw(r,(a,i)=>this.face(r,a,i,!1)),r}onDraw(t,n){const e=t,r=e.onBeforeRender.bind(e);e.onBeforeRender=(a,i,f,u,m,l)=>{n(a,f),r(a,i,f,u,m,l)}}face(t,n,e,r){t.parent?.getWorldQuaternion(this.parentQuat).invert(),e.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(e.isOrthographicCamera){const u=e;a=(u.top-u.bottom)/u.zoom/i}else{const u=e;a=2*Math.max(-f.applyMatrix4(e.matrixWorldInverse).z,1e-6)*Math.tan(xt.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 Zn(o){const t=new x,n=new At;return o.decompose(t,n,new x),new q().compose(t,n,new x(1,1,1))}const Jo=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],Vi=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],ji=[[[.9,1],[-1,-1],[-.9,1],[1,-1]].map(([o,t])=>[o*.0215,t*.025]),[[-1,1],[0,-.1],[1,1],[0,-.1],[0,-.1],[0,-1]].map(([o,t])=>[o*.0175,t*.025]),[[-.95,1],[.95,1],[.95,1],[.95,.9],[.95,.9],[-1,-.9],[-1,-.9],[-1,-1],[-1,-1],[1,-1]].map(([o,t])=>[o*.02,t*.025])],_t=N().finite(),te=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)}),Bi={opening:.5,min:.1657359312880715,max:44.98528137423857},Tn={passepartout:"#000000",back:"#3d3d3d",overlay:"#000000",redalert:"#991616"};function Ui(o,t,n,e){const r=a=>Math.min(1,Math.max(-1,a));return[r(o[0]-n/(2*t)),r(o[1]+e/(2*t))]}function ne(o,t,n,e){const r=o.type==="ORTHO",a=o.sensor_fit==="VERTICAL"?o.sensor_height:o.sensor_width,i=o.sensor_fit==="AUTO"?t>=n:o.sensor_fit==="HORIZONTAL",f=(r?o.ortho_scale:a/o.lens)/2*e;return i?[f,f*n/t]:[f*t/n,f]}function Wi(o,t,n,e,r,a){const i=Math.max(n.width,1),f=Math.max(n.height,1),[u,m]=ne(o,i,f,1/e),[l,s]=ne(o,a,1,1),_=2*((o.sensor_fit==="AUTO"?a>=1:o.sensor_fit==="HORIZONTAL")?l:s),d=l/u,h=s/m,v=-2*r[0]*e,p=2*r[1]*e,g=o.shift_x*_-v*2*u,b=o.shift_y*_+p*2*m,y=new q().set(...o.matrix.flat()).premultiply(t),S=new x,A=new At;return y.decompose(S,A,new x),{name:o.name,position:S.toArray(),quaternion:[A.x,A.y,A.z,A.w],projection:o.type==="ORTHO"?"orthographic":"perspective",window:{left:g-u,right:g+u,top:b+m,bottom:b-m},near:o.clip_start,far:o.clip_end,frame:{left:.5-d/2+v,top:.5-h/2+p,width:d,height:h},passepartout:{color:Tn.passepartout,opacity:o.passepartout},border:{solid:Tn.back,dashed:Tn.overlay,locked:Tn.redalert}}}const Hi={color:[.8,.8,.8,1],roughness:.5,metallic:0},qi=`
7147
+ diffuseColor.a = 1.0;`)},T.customProgramCacheKey=()=>`volter-blender-image:${a.premultiplied}:${S}`;const O=new Rt(new de(2,2),T);O.matrixAutoUpdate=!1,O.matrix.copy(_),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,e){const r=[new x,new x,new x];t.extractBasis(r[0],r[1],r[2]);for(let a=0;a<3;a++){const s=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 m=[];for(let c=1;c<=6;c++)gt(m,ut(.007*(4*c/6)*s,4));this.empties.add(this.facing(m,e,u));const l=Bs[a],i=[];for(let c=0;c+1<l.length;c+=2){const[_,d]=l[c],[h,v]=l[c+1];ot(i,[_*4*s,d*4*s,0],[h*4*s,v*4*s,0])}this.empties.add(this.facing(i,e,f))}}material(t,n){const e=`${t}:${n}`;let r=this.lineMaterials.get(e);return r||(r=new ie({color:t,linewidth:$s,transparent:n<1,opacity:n,depthTest:!0,depthWrite:n>=1,toneMapped:!1}),this.lineMaterials.set(e,r)),r}fill(t){let n=this.fillMaterials.get(t);return n||(n=new Rn({color:t,side:no,toneMapped:!1}),this.fillMaterials.set(t,n)),n}lines(t,n,e,r){const a=new se().setPositions(t),s=new le(a,this.material(n,e));return s.matrixAutoUpdate=!1,s.matrix.copy(r),s.computeLineDistances(),s}screen(t,n,e,r){const a=this.lines(t,n,e,new H);return a.matrixAutoUpdate=!0,a.position.copy(r),a.scale.setScalar(0),a.frustumCulled=!1,this.onDraw(a,(s,f)=>this.face(a,s,f,!0)),a}facing(t,n,e){const r=this.lines(t,n,1,new H);return r.matrixAutoUpdate=!0,r.position.copy(e),this.onDraw(r,(a,s)=>this.face(r,a,s,!1)),r}onDraw(t,n){const e=t,r=e.onBeforeRender.bind(e);e.onBeforeRender=(a,s,f,u,m,l)=>{n(a,f),r(a,s,f,u,m,l)}}face(t,n,e,r){t.parent?.getWorldQuaternion(this.parentQuat).invert(),e.getWorldQuaternion(t.quaternion).premultiply(this.parentQuat);let a=1;if(r){n.getSize(this.size);const s=Math.max(this.size.y,1),f=this.scratch.setFromMatrixPosition(t.matrixWorld);if(e.isOrthographicCamera){const u=e;a=(u.top-u.bottom)/u.zoom/s}else{const u=e;a=2*Math.max(-f.applyMatrix4(e.matrixWorldInverse).z,1e-6)*Math.tan(xt.degToRad(u.fov)/2)/u.zoom/s}}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 Zn(o){const t=new x,n=new At;return o.decompose(t,n,new x),new H().compose(t,n,new x(1,1,1))}const te=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],js=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],Bs=[[[.9,1],[-1,-1],[-.9,1],[1,-1]].map(([o,t])=>[o*.0215,t*.025]),[[-1,1],[0,-.1],[1,1],[0,-.1],[0,-.1],[0,-1]].map(([o,t])=>[o*.0175,t*.025]),[[-.95,1],[.95,1],[.95,1],[.95,.9],[.95,.9],[-1,-.9],[-1,-.9],[-1,-1],[-1,-1],[1,-1]].map(([o,t])=>[o*.02,t*.025])],_t=N().finite(),ne=M({name:R(),type:R(),lens:_t,sensor_width:_t,sensor_height:_t,sensor_fit:q(["AUTO","HORIZONTAL","VERTICAL"]),ortho_scale:_t,clip_start:_t,clip_end:_t,shift_x:_t,shift_y:_t,matrix:F(L([_t,_t,_t,_t])).length(4),passepartout:_t.default(0),display_size:_t.default(1)}),Us={opening:.5,min:.1657359312880715,max:44.98528137423857},Sn={passepartout:"#000000",back:"#3d3d3d",overlay:"#000000",redalert:"#991616"};function Ws(o,t,n,e){const r=a=>Math.min(1,Math.max(-1,a));return[r(o[0]-n/(2*t)),r(o[1]+e/(2*t))]}function oe(o,t,n,e){const r=o.type==="ORTHO",a=o.sensor_fit==="VERTICAL"?o.sensor_height:o.sensor_width,s=o.sensor_fit==="AUTO"?t>=n:o.sensor_fit==="HORIZONTAL",f=(r?o.ortho_scale:a/o.lens)/2*e;return s?[f,f*n/t]:[f*t/n,f]}function Hs(o,t,n,e,r,a){const s=Math.max(n.width,1),f=Math.max(n.height,1),[u,m]=oe(o,s,f,1/e),[l,i]=oe(o,a,1,1),_=2*((o.sensor_fit==="AUTO"?a>=1:o.sensor_fit==="HORIZONTAL")?l:i),d=l/u,h=i/m,v=-2*r[0]*e,p=2*r[1]*e,g=o.shift_x*_-v*2*u,b=o.shift_y*_+p*2*m,y=new H().set(...o.matrix.flat()).premultiply(t),S=new x,A=new At;return y.decompose(S,A,new x),{name:o.name,position:S.toArray(),quaternion:[A.x,A.y,A.z,A.w],projection:o.type==="ORTHO"?"orthographic":"perspective",window:{left:g-u,right:g+u,top:b+m,bottom:b-m},near:o.clip_start,far:o.clip_end,frame:{left:.5-d/2+v,top:.5-h/2+p,width:d,height:h},passepartout:{color:Sn.passepartout,opacity:o.passepartout},border:{solid:Sn.back,dashed:Sn.overlay,locked:Sn.redalert}}}const qs={color:[.8,.8,.8,1],roughness:.5,metallic:0},Gs=`
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
- `,Ao=o=>xo.map(t=>{const[n=0,e=0,r=0]=o(t);return new x(n,e,r)}),Gi=Ao(o=>o.direction).map(o=>o.normalize()),Xi=Ao(o=>o.diffuse),Yi=Ao(o=>o.specular),Zi=new Cn(...xo.map(o=>o.smooth));function Qi(o,t){const[n,e,r]=o.color,a=new _a({side:t});return a.color.setRGB(n,e,r,vt),a.name="volter:blender-solid",a.onBeforeCompile=i=>{i.uniforms.wbDir={value:Gi},i.uniforms.wbDiffuse={value:Xi},i.uniforms.wbSpecular={value:Yi},i.uniforms.wbWrap={value:Zi},i.uniforms.wbRoughness={value:o.roughness},i.uniforms.wbMetallic={value:o.metallic},i.fragmentShader=i.fragmentShader.replace("void main() {",`${qi}
7189
+ `,To=o=>bo.map(t=>{const[n=0,e=0,r=0]=o(t);return new x(n,e,r)}),Xs=To(o=>o.direction).map(o=>o.normalize()),Ys=To(o=>o.diffuse),Zs=To(o=>o.specular),Qs=new Cn(...bo.map(o=>o.smooth));function Ks(o,t){const[n,e,r]=o.color,a=new ma({side:t});return a.color.setRGB(n,e,r,vt),a.name="volter:blender-solid",a.onBeforeCompile=s=>{s.uniforms.wbDir={value:Xs},s.uniforms.wbDiffuse={value:Ys},s.uniforms.wbSpecular={value:Zs},s.uniforms.wbWrap={value:Qs},s.uniforms.wbRoughness={value:o.roughness},s.uniforms.wbMetallic={value:o.metallic},s.fragmentShader=s.fragmentShader.replace("void main() {",`${Gs}
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 Ki=64;function Ji(o,t){return Array.isArray(o)&&Array.isArray(t)?o.length===t.length&&o.every((n,e)=>n===t[e]):o===t}function Fn(o){for(let t=o;t;t=t.parent)if(!t.visible)return!1;return!0}function _o(o){if(o.determinant()<=0)return!1;const t=o.elements,n=Math.hypot(t[0],t[1],t[2]),e=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+e+r)&&Math.min(n,e,r)>0&&Math.abs(a(0,4))<=1e-7*n*e&&Math.abs(a(0,8))<=1e-7*n*r&&Math.abs(a(4,8))<=1e-7*e*r}class ts{constructor(t){this.root=t,this.batches=[],this.inverse=new q,this.matrix=new q,this.box=new hn,this.eligible=0,this.excluded={}}rebuild(t,n){if(this.clear(),!n)return;const e=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=>Ce(l,i.geometry).size>12)){r("attributeBudget");continue}if(this.matrix.multiplyMatrices(this.inverse,i.matrixWorld),!_o(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}`,m=e.get(u);m?m.push(i):e.set(u,[i])}for(const a of e.values()){if(a.length<2)continue;const i=f=>{if(f.length>Ki){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 _=Math.floor(f.length/2);i(f.slice(0,_)),i(f.slice(_));return}if(f.length<2)return;const u=f[0],m=new de(u.geometry,u.material,f.length);m.name="Blender repeated geometry",m.userData.engineInternal=!0,m.matrixAutoUpdate=!1,m.renderOrder=u.renderOrder,m.instanceMatrix.setUsage(he);const l={draw:m,members:f.map(s=>({mesh:s,layers:s.layers.mask}))};m.raycast=(s,c)=>{for(const{mesh:_}of l.members)_.layers.mask===0&&Fn(_)&&_.raycast(s,c)},this.root.add(m),m.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 e=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&&Ji(i.material,t.material)&&_o(this.matrix))){i.layers.mask|=a.layers;continue}if(i.layers.mask&=~a.layers,!Fn(i))continue;const u=e*16;this.matrix.elements.some((m,l)=>Math.fround(m)!==t.instanceMatrix.array[u+l])&&(t.setMatrixAt(e,this.matrix),r=!0),e++}r||=t.count!==e||t.boundingSphere===null,t.count=e,r&&(t.instanceMatrix.needsUpdate=!0,t.computeBoundingBox(),t.computeBoundingSphere())}}}clear(){for(const{draw:t,members:n}of this.batches){for(const{mesh:e,layers:r}of n)e.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 fn=64;class ns{constructor(t){this.root=t,this.objects=[],this.pools=new Map,this.hidden=[],this.inverse=new q,this.matrix=new q,this.projection=new q,this.frustum=new pe,this.centre=new x,this.depth=new Cn,this.batches=0,this.instances=0}setObjects(t){this.clear(),this.objects=[...t].filter(n=>n.isMesh===!0)}prepare(t){for(const a of this.hidden)a.layers.enable(0);this.hidden.length=0;for(const a of this.pools.values())for(const i of a)i.mesh.visible=!1,i.members.length=0;if(this.batches=this.instances=0,!this.objects.length)return;t.updateMatrixWorld(),this.projection.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projection),this.inverse.copy(this.root.matrixWorld).invert();const n=[],e=new Map;for(const a of this.objects){const i=Array.isArray(a.material)?a.material:[a.material];if(!i.some(_=>_.visible&&_.transparent)||!Fn(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(),m=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;if(c&&c.visible&&c.transparent&&!c.isShaderMaterial&&!(c.transmission>0)&&(c.side!==no||c.forceSinglePass)&&!a.isSkinnedMesh&&!a.morphTargetInfluences&&!a.isInstancedMesh&&a.layers.mask===1){const _=a.geometry,d=_.index?.count??_.getAttribute("position").count,h=!Array.isArray(a.material)||_.groups.length===1&&_.groups[0].start===0&&_.groups[0].count===d&&_.groups[0].materialIndex===0,v=`${_.id}:${c.uuid}:${a.renderOrder}`;let p=e.get(v);p===void 0&&(p=Ce(c,_).size<=12,e.set(v,p)),this.matrix.multiplyMatrices(this.inverse,a.matrixWorld),h&&p&&_o(this.matrix)&&(l=c,s=v)}n.push({mesh:a,material:l,key:s,z:m,centre:u})}n.sort((a,i)=>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],m=n[f],l=u?.z===i.z&&u.mesh.renderOrder===i.mesh.renderOrder||m?.z===n[f-1].z&&m.mesh.renderOrder===i.mesh.renderOrder;if(i.key!==null&&f-a>=2&&!l){let s=!0;for(let c=a+fn;c<f;c+=fn)n[c-1].z===n[c].z&&(s=!1);if(s)for(let c=a;c<f;c+=fn){const _=Math.min(fn,f-c);if(_<2)continue;const d=n[c],h=r.get(i.key)??0;r.set(i.key,h+1);let v=this.pools.get(i.key);v||(v=[],this.pools.set(i.key,v));let p=v[h];if(!p){const g=new de(i.mesh.geometry,i.material,fn);g.name="Blender ordered transparency",g.userData.engineInternal=!0,g.matrixAutoUpdate=!1,g.frustumCulled=!1,g.boundingSphere=new ve,g.instanceMatrix.setUsage(he),p={mesh:g,members:[]};const b=p;g.raycast=(y,S)=>{if(g.visible)for(const A of b.members)Fn(A)&&A.raycast(y,S)},v.push(p),this.root.add(g)}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 g=0;g<_;g++){const b=n[c+g].mesh;this.matrix.multiplyMatrices(this.inverse,b.matrixWorld),p.mesh.setMatrixAt(g,this.matrix),p.members.push(b),b.layers.disable(0),this.hidden.push(b)}p.mesh.count=_,p.mesh.instanceMatrix.needsUpdate=!0,this.batches++,this.instances+=_}}a=f}}inspect(){return{batches:this.batches,instances:this.instances}}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.objects=[],this.batches=this.instances=0}}const os={WIREFRAME:"wireframe",SOLID:"solid",MATERIAL:"preview",RENDERED:"rendered"},z=N().finite(),Le=L([z,z,z]),Sn=L([N().int().nonnegative(),N().int().nonnegative()]),mt={name:R(),domain:H(["POINT","EDGE","FACE","CORNER"])},es=Pa("type",[M({...mt,type:W("FLOAT2"),data:D(L([z,z]))}).strict(),M({...mt,type:W("FLOAT_VECTOR"),data:D(Le)}).strict(),M({...mt,type:W("FLOAT_COLOR"),data:D(L([z,z,z,z]))}).strict(),M({...mt,type:W("BYTE_COLOR"),data:D(L([z,z,z,z]))}).strict(),M({...mt,type:W("QUATERNION"),data:D(L([z,z,z,z]))}).strict(),M({...mt,type:W("FLOAT4"),data:D(L([z,z,z,z]))}).strict(),M({...mt,type:W("FLOAT4X4"),data:D(D(z).length(16))}).strict(),M({...mt,type:W("INT16_2D"),data:D(L([N().int(),N().int()]))}).strict(),M({...mt,type:W("INT32_2D"),data:D(L([N().int(),N().int()]))}).strict(),M({...mt,type:W("FLOAT"),data:D(z)}).strict(),M({...mt,type:W("INT"),data:D(N().int())}).strict(),M({...mt,type:W("INT8"),data:D(N().int())}).strict(),M({...mt,type:W("BOOLEAN"),data:D(Q())}).strict(),M({...mt,type:W("STRING"),data:D(R())}).strict()]),as=M({positions:U(Float32Array),normals:U(Float32Array).nullable(),uv:U(Float32Array).nullable(),uvLayers:D(M({name:R(),data:U(Float32Array)}).strict()).optional(),attributeLayers:D(M({name:R(),data:U(Float32Array)}).strict()).optional(),orco:U(Float32Array).nullable().optional(),indices:U(Uint32Array),groups:D(M({start:N().int().nonnegative(),count:N().int().nonnegative(),materialIndex:N().int().nonnegative()}).strict()),hash:R()}).strict(),rs=M({v:D(Le),f:D(D(N().int().nonnegative())),e:D(Sn).optional(),edge_order:D(Sn).optional(),m:D(N().int().nonnegative()).optional(),s:D(Q()).optional(),sharp:D(Sn).optional(),seams:D(Sn).optional(),creases:D(L([z,z,z])).optional(),attributes:D(es).optional(),active_uv:R().nullable().optional(),render_uv:R().nullable().optional()}).strict(),is=M({store:N().int().optional(),revision:N().int(),unchanged:W(!0)}).strict(),ss=M({co:Lt([U(Float32Array),U(Float64Array)]),cornerNormal:U(Float32Array).optional(),cornerTri:U(Uint32Array).optional(),orco:U(Float32Array).optional(),faceStart:U(Uint32Array),corner:U(Uint32Array),cornerEdge:U(Int32Array),edge:U(Uint32Array),edgeSharp:U(Uint8Array),edgeSeam:U(Uint8Array),edgeCrease:U(Float32Array),material:U(Uint32Array),smooth:U(Uint8Array),vertSelect:U(Uint8Array),vertHide:U(Uint8Array),edgeSelect:U(Uint8Array),edgeHide:U(Uint8Array),faceSelect:U(Uint8Array),faceHide:U(Uint8Array)}).strict(),ls=M({name:R(),domain:H(["POINT","EDGE","FACE","CORNER"]),type:R(),data:Ea(o=>ArrayBuffer.isView(o))}).strict(),Ve=M({columns:ss,attributes:D(ls),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(),fs=Lt([as,Ve,rs,is]),oe=new Set;function cs(o,t){const n=new Blob([o],{type:t}),e=new va;let r=!1;e.addEventListener("dispose",()=>{r=!0,e.image?.close?.()});const a=createImageBitmap(n,{imageOrientation:"flipY",premultiplyAlpha:"none",colorSpaceConversion:"none"}).then(i=>{if(r){i.close();return}e.image=i,e.needsUpdate=!0,Ot()}).finally(()=>{oe.delete(a)});return oe.add(a),a.catch(()=>{}),{texture:e,ready:a}}function us(o,t,n,e){const r=new kn(o,t,n,$n,pa);return r.flipY=!1,r.colorSpace=e==="data"?Rn:$t,r.needsUpdate=!0,r}function _s(o,t,n){if(t.length===0)throw new Error(`Runtime image ${o} is tiled with no tiles`);const e=Math.max(...t.map(l=>l.width)),r=Math.max(...t.map(l=>l.height)),a=new Uint8Array(e*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?ao(l.rgbaBase64):void 0);if(!c)throw new Error(`Runtime image ${o} 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)*e*4);const _=l.number-1001;f[_*4]=s,f.set([0,0,l.width/e,l.height/r],(i+_)*4)});const u=new ha(a,e,r,t.length);u.colorSpace=n==="data"?Rn:$t,u.magFilter=Xt,u.minFilter=ge,u.generateMipmaps=!0,u.needsUpdate=!0;const m=new kn(f,i,2,$n,ce);return m.magFilter=m.minFilter=oo,m.needsUpdate=!0,{tiles:u,map:m,frame:t}}const ms=M({width:N().int().positive(),height:N().int().positive(),revision:N().int().nonnegative(),rgba:U(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:U(Uint8Array).optional(),rgbaBase64:R().optional()}).strict()).optional()}).strict(),ds=M({revision:N().int().nonnegative(),encoded:U(Uint8Array).optional(),encodedBase64:R().optional(),mime:H(["image/png","image/jpeg"]),colorspace:H(["sRGB","data"]).optional()}).strict(),je=Lt([ms,ds]),Qn=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(),hs=M({name:R(),color:L([z,z,z,z]),roughness:z,metallic:z,transmission:z,ior:z,physical:xi.optional(),normal_texture:Qn.optional(),normal_strength:z.default(1),normal_space:H(["TANGENT","OBJECT"]).default("TANGENT"),normal_directx:Q().default(!1),texture:Qn.optional(),roughness_texture:Qn.optional(),emission:M({color:L([z,z,z]),strength:z}).strict().optional(),graph:Gr.optional(),viewport:M({color:L([z,z,z,z]),roughness:z,metallic:z}).strict().optional()}).strict(),ps=M({session:R(),revision:N().int().nonnegative(),volumes:bt(R(),Re).default({}),lights:bt(R(),Nr).default({}),world:$r.nullable().default(null),meshes:bt(R(),fs),materials:bt(R(),hs),images:bt(R(),je).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:bt(R(),bt(R(),be())).default({}),warnings:D(R()).default([]),updated:D(R()).default([]),frame:N().int().default(0),armatures:bt(R(),za).default({}),weights:Ti.nullable().default(null),cursor:Ni.optional(),camera_view:M({scene_camera:R().nullable(),view_layer_cameras:D(R()),aspect:N().finite().positive()}).optional(),light_distances:bt(R(),L([N().finite(),N().finite()])).default({}),empties:bt(R(),Ci).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 vs(o,t){for(let n=0,e=o.length-1;n<o.length&&e>=0;n++,e--){if(o[n][0]===t)return o[n][1];if(n===e)break;if(o[e][0]===t)return o[e][1]}return null}const gs={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 ts(this.root),this.transparentInstances=new ns(this.root),this.objects=new Map,this.meshes=new Map,this.volumes=new Map,this.materials=new Map,this.lights=new Map,this.lighting=new kr,this.world=new bo,this.armatureOverlay=new Wa,this.weightOverlay=new Ei,this.cursorOverlay=new Di,this.extrasOverlay=new Li,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 nn({color:12172998,roughness:.72}),this.textures=new Map,this.textureNames=new Map,this.roughnessTextureNames=new Map,this.textureSamplers=new gi,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=Bi,this.cameraViewPan=Ui,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,e]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(e),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 e=this.graphs.get(n);return e||(e=si(t),this.graphs.size>256&&this.graphs.clear(),this.graphs.set(n,e)),e}mirrorPose(t){let n=null;for(const[a,i]of this.objects)if(i===t){n=a;break}if(n===null)return;const e=this.leader?[this.leader,...this.leader.followers]:[...this.followers];let r=!1;for(const a of e){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&&Ot()}subscribeFrames(t){return this.frameListeners.add(t),()=>{this.frameListeners.delete(t)}}onChange(t){const n=this.subscribeFrames(t),e=Ra(t);return()=>{n(),e()}}blenderObjectName(t){for(const[n,e]of this.objects)if(e===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,e,r,a]=t.rotation,i=new At(e,r,a,n),f=new x(...t.location).applyMatrix4(this.root.matrix),u=m=>m.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?os[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(e=>t.cameras[e])??null}blenderPose(t,n){const e=new q().copy(this.root.matrix).invert(),r=new q().compose(new x(...t),new At(...n),new x(1,1,1)).premultiply(e),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,e,r){const a=this.frame,i=te.safeParse(a?.cameras[t]);return!a?.camera_view||!i.success?null:Wi(i.data,this.root.matrix,n,e,r,a.camera_view.aspect)}subjectLine(t){const n=this.frame?.subject;if(n===void 0)return null;const e=t??n.frame,r=vs(n.markers,e);return`(${e})${n.body}${r===null?"":` <${r}>`}`}gridUnitName(t){const n=this.frame?.units;if(n===void 0||n.system==="NONE")return null;const e=gs[n.system],r=6*t,a=1/(n.scale_length||1);return(e.find(([f])=>f*a>r)??e[e.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(e=>e.name===t);return n===void 0?null:this.objects.get(n.id)??null}replacePresentedObject(t,n){for(const[e,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(e,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,e){const r=new Set(this.objects.values()),a=this.cursorOverlay.placementAt(t,n,e,this.root,i=>r.has(i));return a!==null&&(this.cursorOverlay.show(a),Ot()),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 e=t.isOrthographicCamera?t.getWorldDirection(new x).toArray().map(r=>r.toFixed(1)).join(","):"";return`${t.uuid}:${e}:${this.worldKey}`}report(t){t.then(Ot,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(),Ot())}applyWorkbench(){const t=this.workbench&&!this.rendered,n=new Set;for(const e of this.frame?.objects??[]){if(e.mesh===null||e.volume)continue;const r=this.objects.get(e.id);if(!r?.isMesh)continue;const i=(e.materials.length?e.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=e.materials.length?i:i[0]}for(const[e,r]of this.workbenchMaterials)n.has(e)||(r.dispose(),this.workbenchMaterials.delete(e));this.rebuildInstances()}rebuildInstances(){this.transparentInstances.clear(),this.instances.rebuild(this.objects.values(),!this.rendered),this.rendered||this.transparentInstances.setObjects(this.objects.values())}prepareDraw(t){this.root.updateMatrixWorld(!0);try{this.transparentInstances.prepare(t)}catch(n){throw this.transparentInstances.finishDraw(),n}return()=>this.transparentInstances.finishDraw()}workbenchFor(t,n,e){const r=(t!==null?this.frame?.materials[t]?.viewport:void 0)??Hi,a=`${r.color.join(",")}|${r.roughness}|${r.metallic}|${n}`;e.add(a);let i=this.workbenchMaterials.get(a);return i||(i=Qi(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 e=(t?Zo(this.frame?.world)?.extinction:null)??new x;for(const a of[...this.materials.values(),this.fallback])yi(a,e);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 Ir(),await Promise.all([...this.textures.values()].map(a=>a.ready)),await this.world.ready())}applyShadows(t,n){this.root.updateMatrixWorld(!0);const e=[];for(const u of this.objects.values()){const m=u;if(m.isMesh&&(m.castShadow=t,m.receiveShadow=t,t&&m.visible)){const l=new hn().setFromObject(m);l.isEmpty()||e.push(l)}}if(!t||!e.length)return;const a=e.reduce((u,m)=>u.union(m),new hn).getBoundingSphere(new ve),i=n?new pe().setFromProjectionMatrix(new q().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse)):null,f=i?e.flatMap(u=>jr(u,i)):[];for(const u of this.lights.values())u.isDirectionalLight&&n?Br(u,f,e):Dr(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 q().set(...f.matrix.flat())},e=[...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&&e.push(a),this.cursorOverlay.apply(t.cursor),this.applyExtras(t),e}setCameraViewShowing(t){this.lookingThrough!==t&&(this.lookingThrough=t,this.frame&&this.applyExtras(this.frame),Ot())}applyExtras(t){const n={};for(const[e,r]of Object.entries(t.cameras)){const a=te.safeParse(r);a.success&&(n[e]=a.data)}this.extrasOverlay.apply({lookingThrough:this.lookingThrough,lightDistances:t.light_distances,objects:t.objects.filter(e=>e.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:e=>{const r=t.objects.find(a=>a.name===e);return r?this.objects.get(r.id)??null:null},image:e=>{const r=this.textures.get(e);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(e)&&(this.awaitedImages.add(e),r.ready.then(()=>{this.awaitedImages.delete(e),this.frame&&this.applyExtras(this.frame),Ot()},()=>this.awaitedImages.delete(e))),{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 e=this.lights.get(t.light);e&&(e.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 e of this.staged?.meshes.values()??[])e.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 e=Ve.parse(t.piece);if(n.meshes.has(t.mesh))throw new Error("Duplicate Blender mesh piece");const r=`revision:${e.revision}`;n.meshes.set(t.mesh,{signature:r,geometry:Pn(Do({...e.columns,attributes:e.attributes,activeUv:e.activeUv,renderUv:e.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,je.parse(t.piece))}}applyFrame(t){const n=this.frame===null?null:{session:this.frame.session,revision:this.frame.revision},e=ps.parse(t),r=this.staged;if(r&&(r.session!==e.session||r.revision!==e.revision))throw new Error("Blender frame manifest does not match its staged revision");if(r)for(const[l,s]of r.images)e.images[l]=s;if(this.retiredSessions.has(e.session))throw new Error("The runtime session was replaced; its delayed frame cannot overwrite the active model");if(this.frame?.session===e.session&&e.revision<this.frame.revision)throw new Error("The runtime frame is older than the displayed model");const a=new Set(e.objects.map(l=>l.id));if(a.size!==e.objects.length)throw new Error("Runtime object IDs must be unique");const i=new Map(e.objects.map(l=>[l.id,l]));for(const l of e.objects){if(l.mesh!==null&&!e.meshes[l.mesh])throw new Error(`Missing runtime mesh ${l.mesh}`);if(l.volume&&(!e.volumes[l.volume]||l.mesh!==null))throw new Error(`Invalid runtime volume ${l.volume}`);if(l.light&&(!e.lights[l.light]||l.mesh!==null))throw new Error(`Invalid runtime light ${l.light}`);for(const _ of l.materials)if(_!==null&&!e.materials[_])throw new Error(`Missing runtime material ${_}`);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 _=i.get(c);if(!_)throw new Error(`Missing runtime parent ${c}`);c=_.parent}}const f=new Map,u=new Map;try{for(const[l,s]of Object.entries(e.volumes)){const c=JSON.stringify(s);this.frame?.session===e.session&&this.volumes.get(l)?.signature===c||u.set(l,{signature:c,mesh:Ur(s)})}for(const[l,s]of Object.entries(e.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 v=this.meshes.get(l)?.signature;if(this.frame?.session===e.session&&v!==void 0&&(v===`revision:${s.revision}`||!v.startsWith("revision:")))continue;throw new Error(v===void 0?`${Io}: the presenter does not hold runtime mesh ${l} (store ${s.store}, revision ${s.revision})`:`${Io}: the presenter holds runtime mesh ${l} at ${v}, not revision ${s.revision}`)}const c="hash"in s,_="columns"in s,d=_?`revision:${s.revision}`:c?s.hash:JSON.stringify(s);this.frame?.session===e.session&&this.meshes.get(l)?.signature===d||f.set(l,{signature:d,geometry:_?Pn(Do({...s.columns,attributes:s.attributes,activeUv:s.activeUv,renderUv:s.renderUv},d)):c?Pn(s):er(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!==e.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(e.images)){const c=this.textures.get(l);if("width"in s){const p=s.rgba??(s.rgbaBase64?ao(s.rgbaBase64):void 0);if(!p)throw new Error(`Runtime image ${l} carries no raster`);const g=s.tiles?_s(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,g&&(c.udim=g);continue}}c?.texture.dispose(),this.textures.set(l,{texture:us(p,s.width,s.height,s.colorspace??"sRGB"),width:s.width,height:s.height,revision:s.revision,...g?{udim:g}:{}});continue}const _=s.encoded??(s.encodedBase64?ao(s.encodedBase64):void 0);if(!_)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:v}=cs(_,s.mime);h.colorSpace=d==="data"?Rn:$t,this.textures.set(l,{texture:h,ready:v,width:0,height:0,revision:s.revision,encoded:{bytes:_.slice(),mime:s.mime,colorspace:d}})}for(const[l,s]of Object.entries(e.materials)){const c=this.materials.get(l)??new nn;c.name=s.name;const _=s.texture?.tint;s.texture!==void 0?c.color.setRGB(_?.[0]??1,_?.[1]??1,_?.[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&&Xr(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,wo(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(`${an}: 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 A=s.normal_space==="OBJECT"?ma:da;c.normalMapType!==A&&(c.normalMapType=A,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 v=s.roughness_texture?.image.name??null;if(v===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(v);if(!y)throw new Error(`${an}: the presenter does not hold runtime image ${v} (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,v),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(`${an}: 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 g=s.graph?this.compiledGraph(s.graph):null,b=new Set;fi(c,g,y=>{const S=this.textures.get(y.name);if(!S)throw new Error(`${an}: the presenter does not hold runtime image ${y.name} (revision ${y.revision})`);if(y.tiled){if(!S.udim)throw new Error(`${an}: runtime image ${y.name} arrived without its UDIM tiles`);return S.udim}const A=`${l}:graph:${y.node}`;b.add(A);const T=this.textureSamplers.get(A,S.texture,y.extension,S.ready),O=y.closest?oo:Xt,E=y.closest?oo:y.mipmap?ge:Xt;return(T.magFilter!==O||T.minFilter!==E)&&(T.magFilter=O,T.minFilter=E,T.needsUpdate=!0),T},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 e.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 le),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 _=new q().set(...i.get(l.parent).matrix.flat());s.matrix.premultiply(_.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 _=s;_.geometry=this.meshes.get(l.mesh).geometry,_.material=l.materials.length?l.materials.map(d=>d===null?this.fallback:this.materials.get(d)):this.fallback,mi(_)}if(l.light){const _=this.lights.get(l.light)??null,d=Fr(e.lights[l.light],_);_&&_!==d&&(_.removeFromParent(),_.dispose()),d.parent!==s&&s.add(d),d.userData.volterOwnOverlay=!0,Cr(d,s),this.lights.set(l.light,d)}}for(const l of e.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)e.volumes[l]||(s.mesh.geometry.dispose(),s.mesh.material.dispose(),this.volumes.delete(l));for(const[l,s]of this.meshes)e.meshes[l]||(s.geometry.dispose(),this.meshes.delete(l));for(const[l,s]of this.materials)if(!e.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)e.lights[l]||(s.removeFromParent(),s.dispose(),this.lights.delete(l));this.root.updateMatrixWorld(!0),this.frame={...e,meshes:{},volumes:{},images:{}},this.worldKey=JSON.stringify(e.world??null);const m=this.applyOverlays(e);m.length&&(this.frame={...this.frame,warnings:[...this.frame.warnings,...m]}),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{opaque:this.instances.inspect(),transparent:this.transparentInstances.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 dt))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 m=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:m?new Uint32Array(m.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]=Re.parse(JSON.parse(a));const e=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 e){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===Rn?"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,e=this.createWorldVolumePass(),r=new Dn;r.photograph=!0;let a=!1;const i=()=>{a||(a=!0,e?.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:e,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=Zo(this.frame?.world);return t?new Ai(t):void 0}recordPresentation(t){if(typeof t!="object"||t===null)return;const n=t,e=n.meshes;if(typeof e!="object"||e===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=e;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.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 Ms=new Dn;function Be(o){const t=atob(o),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function Kn(o){const t=Be(o);return new Float32Array(t.buffer,t.byteOffset,t.byteLength>>2)}function xs(o){const t=Be(o);return new Uint16Array(t.buffer,t.byteOffset,t.byteLength>>1)}function bs(o){return new q().set(...o.flat())}function ee(o,t){return[o.object,o.mesh,o.armature,o.vertexCount,o.bones.length,t].join("|")}class ys{#n=new Map;#o=null;#a=null;#t=null;#s=null;#e=null;#i=null;#l=new Set;#u=0;#_=[];#r=0;get version(){return this.#u}get engineCalls(){return this.#r}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,e=t?.frameEnd??250,r=t?.fps??24;return{frame:this.frame(),start:n,end:e,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.#_,engineCalls:this.#r,blenderFrame:t?.frameCurrent??null}}playhead(){return this.#t?this.frame():null}frame(){const t=this.#t;return!t||!this.#a||t.clipStart===void 0?t?.frameCurrent??1:this.#s!==null?this.#s:t.clipStart+this.#a.time*t.fps}get playable(){return this.#a!==null}async bind(t,n){this.#r++;const e=await n.rig();if(!e)return;const r=[],a=new Set;let i=!1;for(const s of e.rigs){if(!s.object||!s.armature||!s.skinIndexBase64||!s.skinWeightBase64){s.reason&&r.push(s.reason);continue}a.add(s.object);const c=ee(s,e.frame);if(this.#n.get(s.object)?.signature===c)continue;const _=this.#d(t,s,e.frame,r);_&&(this.#n.get(s.object)?.skeleton.dispose(),this.#n.set(s.object,_),i=!0)}for(const[s,c]of[...this.#n])a.has(s)||(c.skeleton.dispose(),c.boneRoot.removeFromParent(),this.#n.delete(s),i=!0);this.#r++;const f=await n.clip(),u=this.#t,m=f?.action!==u?.action||f?.tracks.length!==u?.tracks.length||f?.clipStart!==u?.clipStart||f?.clipEnd!==u?.clipEnd;this.#t=f??null,f?.reason&&r.push(f.reason),f&&(m||i)&&this.#h(t,f,r);const l=this.#e?.snapshot().playbackState==="playing";f&&!l&&u?.frameCurrent!==f.frameCurrent&&(this.#c(f.frameCurrent),this.#e&&f.fps>0&&this.#e.seek(f.frameCurrent/f.fps)),this.#_=r,this.#f()}#d(t,n,e,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 m=u.getAttribute("blenderVertex");if(!m)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 A=0;A<m.count;A++)l=Math.max(l,m.getX(A));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=xs(n.skinIndexBase64??""),c=Kn(n.skinWeightBase64??""),_=m.count,d=new Uint16Array(_*4),h=new Float32Array(_*4);for(let A=0;A<_;A++){const T=m.getX(A);for(let O=0;O<4;O++)d[A*4+O]=s[T*4+O]??0,h[A*4+O]=c[T*4+O]??0}u.setAttribute("skinIndex",new ga(d,4)),u.setAttribute("skinWeight",new Mt(h,4));const v=new it;v.name=`${n.armature}:bones`;const p=[],g=n.bones.map(A=>bs(A.pose)),b=new Map(n.bones.map((A,T)=>[A.name,T]));n.bones.forEach((A,T)=>{const O=new xa;O.name=A.name,p.push(O);const E=A.parent===null?void 0:b.get(A.parent);(E===void 0?g[T].clone():g[E].clone().invert().multiply(g[T])).decompose(O.position,O.quaternion,O.scale),(E===void 0?v:p[E]).add(O)}),i.add(v);const y=new ba(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 ya(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:v,bones:p,skeleton:S,frame:e,signature:ee(n,e)}}#h(t,n,e){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 _=Kn(s.timeBase64),d=Kn(s.valueBase64),h=`${c.uuid}.${s.property}`;i.push(s.property==="quaternion"?new wa(h,Array.from(_),Array.from(d)):new Oa(h,Array.from(_),Array.from(d)))}if(f.size&&e.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,m=new Aa(r),l=m.clipAction(new Ta(n.action??"action",u,i));l.setLoop(Sa,Number.POSITIVE_INFINITY),l.play(),this.#o=m,this.#a=l,this.#c(n.frameCurrent),this.#m()}#c(t){const n=this.#t;if(!n||!this.#o||n.clipStart===void 0||n.clipEnd===void 0)return;const e=Math.min(n.clipEnd,Math.max(n.clipStart,t));this.#s=e;const r=(n.clipEnd-n.clipStart)/n.fps;this.#o.setTime(Math.min(r-1e-4,(e-n.clipStart)/n.fps)),this.#m()}#m(){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 e=n.scene;return!e||n.frameCurrent===t||(this.#r++,await Na(`bpy.data.scenes[${JSON.stringify(e)}]`,"frame_current",t,void 0,!1),this.#t={...n,frameCurrent:t},this.#f()),t}get transport(){return this.#e}attachTo(t){this.#i?.(),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)}),e=t.onSettled(()=>{this.writeBookmark()}),r=()=>{e(),n(),this.#e===t&&(this.#e=null),this.#i=null};this.#i=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.#i?.(),this.#o?.stopAllAction(),this.#o=null,this.#a=null;for(const t of this.#n.values())t.skeleton.dispose(),t.boneRoot.removeFromParent();this.#n.clear()}}const Ue=new ys;function Ps(o){return Ue.subscribe(o)}function Es(){return Ue.version}export{Ue as a,Es as b,Ms as c,Ps as s};
7191
+ #include <opaque_fragment>`)},a.customProgramCacheKey=()=>"volter-blender-workbench",a}const Js=64;function ti(o,t){return Array.isArray(o)&&Array.isArray(t)?o.length===t.length&&o.every((n,e)=>n===t[e]):o===t}function hn(o){for(let t=o;t;t=t.parent)if(!t.visible)return!1;return!0}function _o(o){if(o.determinant()<=0)return!1;const t=o.elements,n=Math.hypot(t[0],t[1],t[2]),e=Math.hypot(t[4],t[5],t[6]),r=Math.hypot(t[8],t[9],t[10]),a=(s,f)=>t[s]*t[f]+t[s+1]*t[f+1]+t[s+2]*t[f+2];return Number.isFinite(n+e+r)&&Math.min(n,e,r)>0&&Math.abs(a(0,4))<=1e-7*n*e&&Math.abs(a(0,8))<=1e-7*n*r&&Math.abs(a(4,8))<=1e-7*e*r}class ni{constructor(t){this.root=t,this.batches=[],this.inverse=new H,this.matrix=new H,this.box=new pn,this.projection=new H,this.frustum=new po,this.camera=null,this.eligible=0,this.excluded={}}rebuild(t,n){if(this.clear(),!n)return;const e=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 s=a;if(!s.isMesh)continue;if(s.isSkinnedMesh||s.isInstancedMesh||s.morphTargetInfluences||s.layers.mask!==1){r("deformationOrLayers");continue}const f=Array.isArray(s.material)?s.material:[s.material];if(f.some(l=>l.transparent||l.transmission>0||l.isShaderMaterial)){r("material");continue}if(f.some(l=>ke(l,s.geometry).size>12)){r("attributeBudget");continue}if(this.matrix.multiplyMatrices(this.inverse,s.matrixWorld),!_o(this.matrix)){r("transform");continue}this.eligible++;const u=`${s.geometry.id}:${Array.isArray(s.material)?"slots":"single"}:`+f.map(l=>l.uuid).join(",")+`:${s.renderOrder}`,m=e.get(u);m?m.push(s):e.set(u,[s])}for(const a of e.values()){if(a.length<2)continue;const s=f=>{if(f.length>Js){this.box.makeEmpty();for(const d of f)this.box.expandByPoint(new x().setFromMatrixPosition(d.matrixWorld));const i=this.box.getSize(new x),c=i.x>=i.y&&i.x>=i.z?12:i.y>=i.z?13:14;f.sort((d,h)=>d.matrixWorld.elements[c]-h.matrixWorld.elements[c]);const _=Math.floor(f.length/2);s(f.slice(0,_)),s(f.slice(_));return}if(f.length<2)return;const u=f[0],m=new pe(u.geometry,u.material,f.length);m.name="Blender repeated geometry",m.userData.engineInternal=!0,m.matrixAutoUpdate=!1,m.renderOrder=u.renderOrder,m.instanceMatrix.setUsage(ve);const l={draw:m,members:f.map(i=>({mesh:i,layers:i.layers.mask}))};m.raycast=(i,c)=>{for(const{mesh:_}of l.members)_.layers.mask===0&&hn(_)&&_.raycast(i,c)},this.root.add(m),m.updateMatrixWorld(!0),this.batches.push(l)};s(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 e=0,r=!1;for(const a of n){const{mesh:s}=a;if(this.matrix.multiplyMatrices(this.inverse,s.matrixWorld),!(s.parent!==null&&s.geometry===t.geometry&&ti(s.material,t.material)&&_o(this.matrix))){s.layers.mask|=a.layers;continue}if(s.layers.mask&=~a.layers,!hn(s)||this.camera&&(!this.camera.layers.isEnabled(0)||s.frustumCulled&&!this.frustum.intersectsObject(s)))continue;const u=e*16;this.matrix.elements.some((m,l)=>Math.fround(m)!==t.instanceMatrix.array[u+l])&&(t.setMatrixAt(e,this.matrix),r=!0),e++}r||=t.count!==e||t.boundingSphere===null,t.count=e,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:e,layers:r}of n)e.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 fn=64;function ee(o){for(let t=o.parent;t;t=t.parent)if(t.isGroup)return t.renderOrder;return 0}class oi{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 po,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 s of a.members)s.layers.disable(0),this.hidden.push(s)}return}this.planned.length=0;for(const a of this.pools.values())for(const s of a)s.mesh.visible=!1,s.members.length=0;this.batches=this.instances=0,this.frustum.setFromProjectionMatrix(this.projection),this.inverse.copy(this.root.matrixWorld).invert();const n=[],e=new Map;for(const a of this.objects){const s=Array.isArray(a.material)?a.material:[a.material];if(!s.some(d=>d.visible&&d.transparent)||!hn(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(),m=this.depth.set(u.x,u.y,u.z,1).applyMatrix4(this.projection).z;let l=null,i=null;const c=s.length===1?s[0]:null,_=ee(a);if(c&&c.visible&&c.transparent&&!c.isShaderMaterial&&!(c.transmission>0)&&(c.side!==no||c.forceSinglePass)&&!a.isSkinnedMesh&&!a.morphTargetInfluences&&!a.isInstancedMesh&&a.layers.mask===1&&_===this.root.renderOrder){const d=a.geometry,h=d.index?.count??d.getAttribute("position").count,v=!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 g=e.get(p);g===void 0&&(g=ke(c,d).size<=12,e.set(p,g)),this.matrix.multiplyMatrices(this.inverse,a.matrixWorld),v&&g&&_o(this.matrix)&&(l=c,i=p)}n.push({mesh:a,material:l,key:i,groupOrder:_,z:m,centre:u})}n.sort((a,s)=>a.groupOrder-s.groupOrder||a.mesh.renderOrder-s.mesh.renderOrder||s.z-a.z||a.mesh.id-s.mesh.id);const r=new Map;for(let a=0;a<n.length;){const s=n[a];let f=a+1;if(s.key!==null)for(;f<n.length&&n[f].key===s.key;)f++;const u=n[a-1],m=n[f],l=u?.z===s.z&&u.mesh.renderOrder===s.mesh.renderOrder||m?.z===n[f-1].z&&m.mesh.renderOrder===s.mesh.renderOrder;if(s.key!==null&&f-a>=2&&!l){let i=!0;for(let c=a+fn;c<f;c+=fn)n[c-1].z===n[c].z&&(i=!1);if(i)for(let c=a;c<f;c+=fn){const _=Math.min(fn,f-c);if(_<2)continue;const d=n[c],h=r.get(s.key)??0;r.set(s.key,h+1);let v=this.pools.get(s.key);v||(v=[],this.pools.set(s.key,v));let p=v[h];if(!p){const g=new pe(s.mesh.geometry,s.material,fn);g.name="Blender ordered transparency",g.userData.engineInternal=!0,g.matrixAutoUpdate=!1,g.frustumCulled=!1,g.boundingSphere=new ge,g.instanceMatrix.setUsage(ve),p={mesh:g,members:[]};const b=p;g.raycast=(y,S)=>{if(g.visible)for(const A of b.members)hn(A)&&A.raycast(y,S)},v.push(p),this.root.add(g)}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 g=0;g<_;g++){const b=n[c+g].mesh;this.matrix.multiplyMatrices(this.inverse,b.matrixWorld),p.mesh.setMatrixAt(g,this.matrix),p.members.push(b),b.layers.disable(0),this.hidden.push(b)}p.mesh.count=_,p.mesh.instanceMatrix.needsUpdate=!0,this.planned.push(p),this.batches++,this.instances+=_}}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(hn(n)?1:0),this.observe(n.layers.mask),this.observe(n.renderOrder),this.observe(ee(n)),this.observe(n.frustumCulled?1:0),this.observe(n.morphTargetInfluences?1:0);for(const s of n.matrixWorld.elements)this.observe(s);const e=n.geometry;this.observe(e.id),this.observe(e.drawRange.start),this.observe(e.drawRange.count),this.observe(e.index?.count??e.getAttribute("position").count),this.observe(e.groups.length);for(const s of e.groups)this.observe(s.start),this.observe(s.count),this.observe(s.materialIndex??0);const r=n.boundingSphere??e.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 s of a)this.observeMaterial(s);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 ei={WIREFRAME:"wireframe",SOLID:"solid",MATERIAL:"preview",RENDERED:"rendered"},z=N().finite(),Ve=L([z,z,z]),Mn=L([N().int().nonnegative(),N().int().nonnegative()]),mt={name:R(),domain:q(["POINT","EDGE","FACE","CORNER"])},ai=Ea("type",[M({...mt,type:W("FLOAT2"),data:F(L([z,z]))}).strict(),M({...mt,type:W("FLOAT_VECTOR"),data:F(Ve)}).strict(),M({...mt,type:W("FLOAT_COLOR"),data:F(L([z,z,z,z]))}).strict(),M({...mt,type:W("BYTE_COLOR"),data:F(L([z,z,z,z]))}).strict(),M({...mt,type:W("QUATERNION"),data:F(L([z,z,z,z]))}).strict(),M({...mt,type:W("FLOAT4"),data:F(L([z,z,z,z]))}).strict(),M({...mt,type:W("FLOAT4X4"),data:F(F(z).length(16))}).strict(),M({...mt,type:W("INT16_2D"),data:F(L([N().int(),N().int()]))}).strict(),M({...mt,type:W("INT32_2D"),data:F(L([N().int(),N().int()]))}).strict(),M({...mt,type:W("FLOAT"),data:F(z)}).strict(),M({...mt,type:W("INT"),data:F(N().int())}).strict(),M({...mt,type:W("INT8"),data:F(N().int())}).strict(),M({...mt,type:W("BOOLEAN"),data:F(Q())}).strict(),M({...mt,type:W("STRING"),data:F(R())}).strict()]),ri=M({positions:U(Float32Array),normals:U(Float32Array).nullable(),uv:U(Float32Array).nullable(),uvLayers:F(M({name:R(),data:U(Float32Array)}).strict()).optional(),attributeLayers:F(M({name:R(),data:U(Float32Array)}).strict()).optional(),orco:U(Float32Array).nullable().optional(),indices:U(Uint32Array),groups:F(M({start:N().int().nonnegative(),count:N().int().nonnegative(),materialIndex:N().int().nonnegative()}).strict()),hash:R()}).strict(),si=M({v:F(Ve),f:F(F(N().int().nonnegative())),e:F(Mn).optional(),edge_order:F(Mn).optional(),m:F(N().int().nonnegative()).optional(),s:F(Q()).optional(),sharp:F(Mn).optional(),seams:F(Mn).optional(),creases:F(L([z,z,z])).optional(),attributes:F(ai).optional(),active_uv:R().nullable().optional(),render_uv:R().nullable().optional()}).strict(),ii=M({store:N().int().optional(),revision:N().int(),unchanged:W(!0)}).strict(),li=M({co:Lt([U(Float32Array),U(Float64Array)]),cornerNormal:U(Float32Array).optional(),cornerTri:U(Uint32Array).optional(),orco:U(Float32Array).optional(),faceStart:U(Uint32Array),corner:U(Uint32Array),cornerEdge:U(Int32Array),edge:U(Uint32Array),edgeSharp:U(Uint8Array),edgeSeam:U(Uint8Array),edgeCrease:U(Float32Array),material:U(Uint32Array),smooth:U(Uint8Array),vertSelect:U(Uint8Array),vertHide:U(Uint8Array),edgeSelect:U(Uint8Array),edgeHide:U(Uint8Array),faceSelect:U(Uint8Array),faceHide:U(Uint8Array)}).strict(),fi=M({name:R(),domain:q(["POINT","EDGE","FACE","CORNER"]),type:R(),data:Na(o=>ArrayBuffer.isView(o))}).strict(),je=M({columns:li,attributes:F(fi),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(),ci=Lt([ri,je,si,ii]),ae=new Set;function ui(o,t){const n=new Blob([o],{type:t}),e=new ga;let r=!1;e.addEventListener("dispose",()=>{r=!0,e.image?.close?.()});const a=createImageBitmap(n,{imageOrientation:"flipY",premultiplyAlpha:"none",colorSpaceConversion:"none"}).then(s=>{if(r){s.close();return}e.image=s,e.needsUpdate=!0,wt()}).finally(()=>{ae.delete(a)});return ae.add(a),a.catch(()=>{}),{texture:e,ready:a}}function _i(o,t,n,e){const r=new kn(o,t,n,$n,va);return r.flipY=!1,r.colorSpace=e==="data"?In:$t,r.needsUpdate=!0,r}function mi(o,t,n){if(t.length===0)throw new Error(`Runtime image ${o} is tiled with no tiles`);const e=Math.max(...t.map(l=>l.width)),r=Math.max(...t.map(l=>l.height)),a=new Uint8Array(e*r*4*t.length),s=Math.max(...t.map(l=>l.number-1001))+1,f=new Float32Array(s*2*4);for(let l=0;l<s;l++)f[l*4]=-1;t.forEach((l,i)=>{const c=l.rgba??(l.rgbaBase64?ao(l.rgbaBase64):void 0);if(!c)throw new Error(`Runtime image ${o} 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),(i*r+d)*e*4);const _=l.number-1001;f[_*4]=i,f.set([0,0,l.width/e,l.height/r],(s+_)*4)});const u=new pa(a,e,r,t.length);u.colorSpace=n==="data"?In:$t,u.magFilter=Xt,u.minFilter=xe,u.generateMipmaps=!0,u.needsUpdate=!0;const m=new kn(f,s,2,$n,_e);return m.magFilter=m.minFilter=oo,m.needsUpdate=!0,{tiles:u,map:m,frame:t}}const di=M({width:N().int().positive(),height:N().int().positive(),revision:N().int().nonnegative(),rgba:U(Uint8Array).optional(),rgbaBase64:R().optional(),colorspace:q(["sRGB","data"]).optional(),tiles:F(M({number:N().int().min(1001),width:N().int().positive(),height:N().int().positive(),rgba:U(Uint8Array).optional(),rgbaBase64:R().optional()}).strict()).optional()}).strict(),hi=M({revision:N().int().nonnegative(),encoded:U(Uint8Array).optional(),encodedBase64:R().optional(),mime:q(["image/png","image/jpeg"]),colorspace:q(["sRGB","data"]).optional()}).strict(),Be=Lt([di,hi]),Qn=M({image:M({name:R(),revision:N().int().nonnegative()}).strict(),extension:q(["REPEAT","EXTEND","MIRROR","CLIP"]).default("REPEAT"),uv:R(),tint:L([z,z,z]).optional()}).strict(),pi=M({name:R(),color:L([z,z,z,z]),roughness:z,metallic:z,transmission:z,ior:z,physical:bs.optional(),normal_texture:Qn.optional(),normal_strength:z.default(1),normal_space:q(["TANGENT","OBJECT"]).default("TANGENT"),normal_directx:Q().default(!1),texture:Qn.optional(),roughness_texture:Qn.optional(),emission:M({color:L([z,z,z]),strength:z}).strict().optional(),graph:Xr.optional(),viewport:M({color:L([z,z,z,z]),roughness:z,metallic:z}).strict().optional()}).strict(),vi=M({session:R(),revision:N().int().nonnegative(),volumes:bt(R(),Ie).default({}),lights:bt(R(),Rr).default({}),world:Lr.nullable().default(null),meshes:bt(R(),ci),materials:bt(R(),pi),images:bt(R(),Be).default({}),objects:F(M({id:R(),name:R(),type:q(["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:F(R().nullable()),matrix:F(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:bt(R(),bt(R(),ye())).default({}),warnings:F(R()).default([]),updated:F(R()).default([]),frame:N().int().default(0),armatures:bt(R(),Da).default({}),weights:Ss.nullable().default(null),cursor:Rs.optional(),camera_view:M({scene_camera:R().nullable(),view_layer_cameras:F(R()),aspect:N().finite().positive()}).optional(),light_distances:bt(R(),L([N().finite(),N().finite()])).default({}),empties:bt(R(),ks).default({}),view:M({location:L([N(),N(),N()]),rotation:L([N(),N(),N(),N()]),distance:N().finite(),perspective:q(["PERSP","ORTHO","CAMERA"]),lens:N().finite().positive().default(50),shading:q(["WIREFRAME","SOLID","MATERIAL","RENDERED"]).optional()}).nullable().optional(),subject:M({frame:N().int(),body:R(),markers:F(L([N().int(),R()]))}).optional(),units:M({system:q(["NONE","METRIC","IMPERIAL"]),scale_length:N().finite()}).optional()}).strict();function gi(o,t){for(let n=0,e=o.length-1;n<o.length&&e>=0;n++,e--){if(o[n][0]===t)return o[n][1];if(n===e)break;if(o[e][0]===t)return o[e][1]}return null}const xi={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 Fn{constructor(){this.root=new st,this.instances=new ni(this.root),this.transparentInstances=new oi(this.root),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 $r,this.world=new yo,this.armatureOverlay=new Ha,this.weightOverlay=new Ns,this.cursorOverlay=new Cs,this.extrasOverlay=new Vs,this.armatureRoot=new st,this.weightRoot=new st,this.cursorRoot=new st,this.cameraExtrasRoot=new st,this.lightExtrasRoot=new st,this.emptyExtrasRoot=new st,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 nn({color:12172998,roughness:.72}),this.textures=new Map,this.textureNames=new Map,this.roughnessTextureNames=new Map,this.textureSamplers=new xs,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=Us,this.cameraViewPan=Ws,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,e]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(e),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 e=this.graphs.get(n);return e||(e=ls(t),this.graphs.size>256&&this.graphs.clear(),this.graphs.set(n,e)),e}mirrorPose(t){let n=null;for(const[a,s]of this.objects)if(s===t){n=a;break}if(n===null)return;const e=this.leader?[this.leader,...this.leader.followers]:[...this.followers];let r=!1;for(const a of e){if(a===this)continue;const s=a.objects.get(n);s!==void 0&&(s.matrix.copy(t.matrix),s.matrix.decompose(s.position,s.quaternion,s.scale),s.updateMatrixWorld(!0),r=!0)}r&&wt()}subscribeFrames(t){return this.frameListeners.add(t),()=>{this.frameListeners.delete(t)}}onChange(t){const n=this.subscribeFrames(t),e=Ia(t);return()=>{n(),e()}}blenderObjectName(t){for(const[n,e]of this.objects)if(e===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,e,r,a]=t.rotation,s=new At(e,r,a,n),f=new x(...t.location).applyMatrix4(this.root.matrix),u=m=>m.applyQuaternion(s).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?ei[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(e=>t.cameras[e])??null}blenderPose(t,n){const e=new H().copy(this.root.matrix).invert(),r=new H().compose(new x(...t),new At(...n),new x(1,1,1)).premultiply(e),a=new x,s=new At;return r.decompose(a,s,new x),{location:a.toArray(),rotation:[s.w,s.x,s.y,s.z]}}cameraView(t,n,e,r){const a=this.frame,s=ne.safeParse(a?.cameras[t]);return!a?.camera_view||!s.success?null:Hs(s.data,this.root.matrix,n,e,r,a.camera_view.aspect)}subjectLine(t){const n=this.frame?.subject;if(n===void 0)return null;const e=t??n.frame,r=gi(n.markers,e);return`(${e})${n.body}${r===null?"":` <${r}>`}`}gridUnitName(t){const n=this.frame?.units;if(n===void 0||n.system==="NONE")return null;const e=xi[n.system],r=6*t,a=1/(n.scale_length||1);return(e.find(([f])=>f*a>r)??e[e.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(e=>e.name===t);return n===void 0?null:this.objects.get(n.id)??null}replacePresentedObject(t,n){for(const[e,r]of this.objects)if(r===t){const a=t.parent,s=[...t.children];t.removeFromParent();for(const f of s)n.add(f);a?.add(n),this.objects.set(e,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,e){const r=new Set(this.objects.values()),a=this.cursorOverlay.placementAt(t,n,e,this.root,s=>r.has(s));return a!==null&&(this.cursorOverlay.show(a),wt()),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 e=t.isOrthographicCamera?t.getWorldDirection(new x).toArray().map(r=>r.toFixed(1)).join(","):"";return`${t.uuid}:${e}:${this.worldKey}`}report(t){t.then(wt,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(),wt())}applyWorkbench(){const t=this.workbench&&!this.rendered,n=new Set;for(const e of this.frame?.objects??[]){if(e.mesh===null||e.volume)continue;const r=this.objects.get(e.id);if(!r?.isMesh)continue;const s=(e.materials.length?e.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=e.materials.length?s:s[0]}for(const[e,r]of this.workbenchMaterials)n.has(e)||(r.dispose(),this.workbenchMaterials.delete(e));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())}setDrawBatching(t){t!==this.drawBatching&&(this.drawBatching=t,this.rebuildInstances(),wt())}prepareDraw(t){try{this.instances.prepareDraw(t),this.root.updateMatrixWorld(!0),this.transparentInstances.prepare(t)}catch(n){throw this.instances.finishDraw(),this.transparentInstances.finishDraw(),n}return()=>{this.instances.finishDraw(),this.transparentInstances.finishDraw()}}workbenchFor(t,n,e){const r=(t!==null?this.frame?.materials[t]?.viewport:void 0)??qs,a=`${r.color.join(",")}|${r.roughness}|${r.metallic}|${n}`;e.add(a);let s=this.workbenchMaterials.get(a);return s||(s=Ks(r,n),this.workbenchMaterials.set(a,s)),s}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 e=(t?Qo(this.frame?.world)?.extinction:null)??new x;for(const a of[...this.materials.values(),this.fallback])ws(a,e);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 zr(),await Promise.all([...this.textures.values()].map(a=>a.ready)),await this.world.ready())}applyShadows(t,n){this.root.updateMatrixWorld(!0);const e=[];for(const u of this.objects.values()){const m=u;if(m.isMesh&&(m.castShadow=t,m.receiveShadow=t,t&&m.visible)){const l=new pn().setFromObject(m);l.isEmpty()||e.push(l)}}if(!t||!e.length)return;const a=e.reduce((u,m)=>u.union(m),new pn).getBoundingSphere(new ge),s=n?new po().setFromProjectionMatrix(new H().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse)):null,f=s?e.flatMap(u=>Br(u,s)):[];for(const u of this.lights.values())u.isDirectionalLight&&n?Ur(u,f,e):Cr(u,a.center,a.radius)}applyOverlays(t){const n=s=>{const f=t.objects.find(u=>u.name===s);return f===void 0?null:new H().set(...f.matrix.flat())},e=[...this.armatureOverlay.apply(t.armatures,n)],r=t.weights?this.objects.get(t.objects.find(s=>s.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&&e.push(a),this.cursorOverlay.apply(t.cursor),this.applyExtras(t),e}setCameraViewShowing(t){this.lookingThrough!==t&&(this.lookingThrough=t,this.frame&&this.applyExtras(this.frame),wt())}applyExtras(t){const n={};for(const[e,r]of Object.entries(t.cameras)){const a=ne.safeParse(r);a.success&&(n[e]=a.data)}this.extrasOverlay.apply({lookingThrough:this.lookingThrough,lightDistances:t.light_distances,objects:t.objects.filter(e=>e.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:e=>{const r=t.objects.find(a=>a.name===e);return r?this.objects.get(r.id)??null:null},image:e=>{const r=this.textures.get(e);if(!r)return null;const a=r.texture.image,s=r.width||a?.width||0,f=r.height||a?.height||0;return(s===0||f===0)&&r.ready&&!this.awaitedImages.has(e)&&(this.awaitedImages.add(e),r.ready.then(()=>{this.awaitedImages.delete(e),this.frame&&this.applyExtras(this.frame),wt()},()=>this.awaitedImages.delete(e))),{texture:r.texture,width:s,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 e=this.lights.get(t.light);e&&(e.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 e of this.staged?.meshes.values()??[])e.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 e=je.parse(t.piece);if(n.meshes.has(t.mesh))throw new Error("Duplicate Blender mesh piece");const r=`revision:${e.revision}`;n.meshes.set(t.mesh,{signature:r,geometry:En(Co({...e.columns,attributes:e.attributes,activeUv:e.activeUv,renderUv:e.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,Be.parse(t.piece))}}applyFrame(t){const n=this.frame===null?null:{session:this.frame.session,revision:this.frame.revision},e=vi.parse(t),r=this.staged;if(r&&(r.session!==e.session||r.revision!==e.revision))throw new Error("Blender frame manifest does not match its staged revision");if(r)for(const[l,i]of r.images)e.images[l]=i;if(this.retiredSessions.has(e.session))throw new Error("The runtime session was replaced; its delayed frame cannot overwrite the active model");if(this.frame?.session===e.session&&e.revision<this.frame.revision)throw new Error("The runtime frame is older than the displayed model");const a=new Set(e.objects.map(l=>l.id));if(a.size!==e.objects.length)throw new Error("Runtime object IDs must be unique");const s=new Map(e.objects.map(l=>[l.id,l]));for(const l of e.objects){if(l.mesh!==null&&!e.meshes[l.mesh])throw new Error(`Missing runtime mesh ${l.mesh}`);if(l.volume&&(!e.volumes[l.volume]||l.mesh!==null))throw new Error(`Invalid runtime volume ${l.volume}`);if(l.light&&(!e.lights[l.light]||l.mesh!==null))throw new Error(`Invalid runtime light ${l.light}`);for(const _ of l.materials)if(_!==null&&!e.materials[_])throw new Error(`Missing runtime material ${_}`);const i=new Set([l.id]);let c=l.parent;for(;c!==null;){if(i.has(c))throw new Error("Runtime parent cycle");i.add(c);const _=s.get(c);if(!_)throw new Error(`Missing runtime parent ${c}`);c=_.parent}}const f=new Map,u=new Map;try{for(const[l,i]of Object.entries(e.volumes)){const c=JSON.stringify(i);this.frame?.session===e.session&&this.volumes.get(l)?.signature===c||u.set(l,{signature:c,mesh:Wr(i)})}for(const[l,i]of Object.entries(e.meshes)){if("unchanged"in i){const h=r?.meshes.get(l);if(h){if(h.signature!==`revision:${i.revision}`)throw new Error("Staged Blender mesh revision mismatch");f.set(l,h);continue}const v=this.meshes.get(l)?.signature;if(this.frame?.session===e.session&&v!==void 0&&(v===`revision:${i.revision}`||!v.startsWith("revision:")))continue;throw new Error(v===void 0?`${zo}: the presenter does not hold runtime mesh ${l} (store ${i.store}, revision ${i.revision})`:`${zo}: the presenter holds runtime mesh ${l} at ${v}, not revision ${i.revision}`)}const c="hash"in i,_="columns"in i,d=_?`revision:${i.revision}`:c?i.hash:JSON.stringify(i);this.frame?.session===e.session&&this.meshes.get(l)?.signature===d||f.set(l,{signature:d,geometry:_?En(Co({...i.columns,attributes:i.attributes,activeUv:i.activeUv,renderUv:i.renderUv},d)):c?En(i):ar(i)})}}catch(l){for(const i of f.values())i.geometry.dispose();for(const{mesh:i}of u.values())i.geometry.dispose(),i.material.dispose();throw l}if(r){for(const[l,i]of r.meshes)f.has(l)||i.geometry.dispose();this.staged=null}this.frame?.session!==e.session&&(this.frame&&this.retiredSessions.add(this.frame.session),this.clear());for(const[l,i]of u){const c=this.volumes.get(l)?.mesh;c&&(c.removeFromParent(),c.geometry.dispose(),c.material.dispose()),this.volumes.set(l,i)}for(const[l,i]of f)this.meshes.get(l)?.geometry.dispose(),this.meshes.set(l,i),this.geometryBuilds++;for(const[l,i]of Object.entries(e.images)){const c=this.textures.get(l);if("width"in i){const p=i.rgba??(i.rgbaBase64?ao(i.rgbaBase64):void 0);if(!p)throw new Error(`Runtime image ${l} carries no raster`);const g=i.tiles?mi(l,i.tiles,i.colorspace??"sRGB"):void 0;if(c?.udim&&(c.udim.tiles.dispose(),c.udim.map.dispose(),delete c.udim),c&&c.width===i.width&&c.height===i.height){const b=c.texture.image;if(b.data){b.data.set(p),c.texture.needsUpdate=!0,c.revision=i.revision,g&&(c.udim=g);continue}}c?.texture.dispose(),this.textures.set(l,{texture:_i(p,i.width,i.height,i.colorspace??"sRGB"),width:i.width,height:i.height,revision:i.revision,...g?{udim:g}:{}});continue}const _=i.encoded??(i.encodedBase64?ao(i.encodedBase64):void 0);if(!_)throw new Error(`Runtime image ${l} carries no bytes`);c?.texture.dispose(),c?.udim?.tiles.dispose(),c?.udim?.map.dispose();const d=i.colorspace??"sRGB",{texture:h,ready:v}=ui(_,i.mime);h.colorSpace=d==="data"?In:$t,this.textures.set(l,{texture:h,ready:v,width:0,height:0,revision:i.revision,encoded:{bytes:_.slice(),mime:i.mime,colorspace:d}})}for(const[l,i]of Object.entries(e.materials)){const c=this.materials.get(l)??new nn;c.name=i.name;const _=i.texture?.tint;i.texture!==void 0?c.color.setRGB(_?.[0]??1,_?.[1]??1,_?.[2]??1,vt):c.color.setRGB(i.color[0],i.color[1],i.color[2],vt),c.opacity=i.color[3];const d=c.opacity<1||i.graph!==void 0&&Yr(i.graph);c.transparent!==d&&(c.transparent=d,c.needsUpdate=!0),c.roughness=i.roughness,c.metalness=i.metallic,c.transmission=i.transmission,c.ior=i.ior,Oo(c,i.physical,{map:i.texture?.extension==="CLIP",roughness:i.roughness_texture?.extension==="CLIP",normal:i.normal_texture?.extension==="CLIP"});const h=i.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(`${an}: missing normal image ${h}`);const S=this.textureSamplers.get(`${l}:normal`,y.texture,i.normal_texture.extension,y.ready,i.normal_texture.uv);c.normalMap!==S&&(c.normalMap=S,c.needsUpdate=!0);const A=i.normal_space==="OBJECT"?da:ha;c.normalMapType!==A&&(c.normalMapType=A,c.needsUpdate=!0),c.normalScale.set(i.normal_strength,i.normal_strength*(i.normal_directx?-1:1))}i.emission?(c.emissive.setRGB(i.emission.color[0],i.emission.color[1],i.emission.color[2],vt),c.emissiveIntensity=i.emission.strength):(c.emissive.setRGB(0,0,0),c.emissiveIntensity=1);const v=i.roughness_texture?.image.name??null;if(v===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(v);if(!y)throw new Error(`${an}: the presenter does not hold runtime image ${v} (revision ${i.roughness_texture.image.revision})`);const S=this.textureSamplers.get(`${l}:roughness`,y.texture,i.roughness_texture.extension,y.ready,i.roughness_texture.uv);c.roughnessMap!==S&&(c.roughnessMap=S,this.roughnessTextureNames.set(l,v),c.needsUpdate=!0)}const p=i.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(`${an}: the presenter does not hold runtime image ${p} (revision ${i.texture.image.revision})`);const S=this.textureSamplers.get(`${l}:color`,y.texture,i.texture.extension,y.ready,i.texture.uv);c.map!==S&&(c.map=S,this.textureNames.set(l,p),c.needsUpdate=!0)}const g=i.graph?this.compiledGraph(i.graph):null,b=new Set;cs(c,g,y=>{const S=this.textures.get(y.name);if(!S)throw new Error(`${an}: the presenter does not hold runtime image ${y.name} (revision ${y.revision})`);if(y.tiled){if(!S.udim)throw new Error(`${an}: runtime image ${y.name} arrived without its UDIM tiles`);return S.udim}const A=`${l}:graph:${y.node}`;b.add(A);const T=this.textureSamplers.get(A,S.texture,y.extension,S.ready),O=y.closest?oo:Xt,E=y.closest?oo:y.mipmap?xe:Xt;return(T.magFilter!==O||T.minFilter!==E)&&(T.magFilter=O,T.minFilter=E,T.needsUpdate=!0),T},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 e.objects){let i=this.objects.get(l.id);const c=l.volume?this.volumes.get(l.volume).mesh:null;if((!i||(c?i!==c:!!i.isMesh!=(l.mesh!==null)))&&(i?.removeFromParent(),i=c??(l.mesh!==null?new Rt(this.meshes.get(l.mesh).geometry,this.fallback):new ce),this.objects.set(l.id,i)),i.name=l.name,l.type==="CAMERA"||l.type==="LIGHT"||l.type==="EMPTY"?i.userData.volterOwnOverlay=!0:delete i.userData.volterOwnOverlay,i.matrixAutoUpdate=!1,i.matrix.set(...l.matrix.flat()),l.parent){const _=new H().set(...s.get(l.parent).matrix.flat());i.matrix.premultiply(_.invert())}if(i.matrix.decompose(i.position,i.quaternion,i.scale),l.texspace?i.userData.blenderTexspace=l.texspace:delete i.userData.blenderTexspace,l.default_color!==void 0?i.userData.blenderDefaultColor=l.default_color:delete i.userData.blenderDefaultColor,l.mesh!==null){const _=i;_.geometry=this.meshes.get(l.mesh).geometry,_.material=l.materials.length?l.materials.map(d=>d===null?this.fallback:this.materials.get(d)):this.fallback,ds(_)}if(l.light){const _=this.lights.get(l.light)??null,d=Fr(e.lights[l.light],_);_&&_!==d&&(_.removeFromParent(),_.dispose()),d.parent!==i&&i.add(d),d.userData.volterOwnOverlay=!0,kr(d,i),this.lights.set(l.light,d)}}for(const l of e.objects){const i=this.objects.get(l.id),c=l.parent===null?this.root:this.objects.get(l.parent);i.parent!==c&&c.add(i)}for(const[l,i]of this.objects)a.has(l)||(i.removeFromParent(),this.objects.delete(l));for(const[l,i]of this.volumes)e.volumes[l]||(i.mesh.geometry.dispose(),i.mesh.material.dispose(),this.volumes.delete(l));for(const[l,i]of this.meshes)e.meshes[l]||(i.geometry.dispose(),this.meshes.delete(l));for(const[l,i]of this.materials)if(!e.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),i.dispose(),this.materials.delete(l)}for(const[l,i]of this.lights)e.lights[l]||(i.removeFromParent(),i.dispose(),this.lights.delete(l));this.root.updateMatrixWorld(!0),this.frame={...e,meshes:{},volumes:{},images:{}},this.worldKey=JSON.stringify(e.world??null);const m=this.applyOverlays(e);m.length&&(this.frame={...this.frame,warnings:[...this.frame.warnings,...m]}),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()}}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:s}]of this.meshes){const f=l=>{const i=s.getAttribute(l);if(!i)return null;if(!(i instanceof dt))throw new Error(`Blender capture cannot copy interleaved ${l}`);return new Float32Array(i.array)},u=f("position");if(!u)throw new Error(`Blender capture mesh ${r} has no positions`);const m=s.getIndex();n.meshes[r]={hash:a,positions:u,normals:f("normal"),uv:f("uv"),uvLayers:Object.entries(s.userData.blenderUvChannels??{}).map(([l,i])=>{const c=f(`uv${i}`);if(!c)throw new Error(`Blender capture mesh ${r} is missing UV layer ${l}`);return{name:l,data:c}}),orco:s.userData.blenderOrcoFromDoor?f("blenderOrco"):null,attributeLayers:(s.userData.blenderAttributes??[]).map(l=>{const i=f(kt(l));if(!i)throw new Error(`Blender capture mesh ${r} is missing attribute ${l}`);return{name:l,data:i}}),indices:m?new Uint32Array(m.array):Uint32Array.from({length:u.length/3},(l,i)=>i),groups:s.groups.map(l=>({start:l.start,count:l.count,materialIndex:l.materialIndex??0}))}}for(const[r,{signature:a}]of this.volumes)n.volumes[r]=Ie.parse(JSON.parse(a));const e=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 e){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 s=a.texture.image?.data;if(!(s 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:s.slice(),colorspace:a.texture.colorSpace===In?"data":"sRGB",...a.udim?{tiles:a.udim.frame}:{}}}}return n}follow(){const t=new Fn;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,e=this.createWorldVolumePass(),r=new Fn;r.photograph=!0;let a=!1;const s=()=>{a||(a=!0,e?.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 s(),f}return{effect:e,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:s}}createWorldVolumePass(){const t=Qo(this.frame?.world);return t?new Ts(t):void 0}recordPresentation(t){if(typeof t!="object"||t===null)return;const n=t,e=n.meshes;if(typeof e!="object"||e===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=e;for(const[s,f]of Object.entries(a))typeof f=="object"&&f!==null&&!("unchanged"in f)&&this.submittedMeshes.set(s,f);for(const s of[...this.submittedMeshes.keys()])s in a||this.submittedMeshes.delete(s);this.submitted={...n,meshes:Object.fromEntries(this.submittedMeshes)}}recordPhotograph(t){this.photographs.push(t)}observations(){return{presentation:this.submitted,photographs:this.photographs}}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 Pi=new Fn;function Ue(o){const t=atob(o),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function Kn(o){const t=Ue(o);return new Float32Array(t.buffer,t.byteOffset,t.byteLength>>2)}function bi(o){const t=Ue(o);return new Uint16Array(t.buffer,t.byteOffset,t.byteLength>>1)}function yi(o){return new H().set(...o.flat())}function re(o,t){return[o.object,o.mesh,o.armature,o.vertexCount,o.bones.length,t].join("|")}class wi{#n=new Map;#o=null;#a=null;#t=null;#i=null;#e=null;#s=null;#l=new Set;#u=0;#_=[];#r=0;get version(){return this.#u}get engineCalls(){return this.#r}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,e=t?.frameEnd??250,r=t?.fps??24;return{frame:this.frame(),start:n,end:e,fps:r,action:t?.action??null,object:t?.object??null,armature:t?.armature??null,bones:[...this.#n.values()].reduce((a,s)=>a+s.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.#_,engineCalls:this.#r,blenderFrame:t?.frameCurrent??null}}playhead(){return this.#t?this.frame():null}frame(){const t=this.#t;return!t||!this.#a||t.clipStart===void 0?t?.frameCurrent??1:this.#i!==null?this.#i:t.clipStart+this.#a.time*t.fps}get playable(){return this.#a!==null}async bind(t,n){this.#r++;const e=await n.rig();if(!e)return;const r=[],a=new Set;let s=!1;for(const i of e.rigs){if(!i.object||!i.armature||!i.skinIndexBase64||!i.skinWeightBase64){i.reason&&r.push(i.reason);continue}a.add(i.object);const c=re(i,e.frame);if(this.#n.get(i.object)?.signature===c)continue;const _=this.#d(t,i,e.frame,r);_&&(this.#n.get(i.object)?.skeleton.dispose(),this.#n.set(i.object,_),s=!0)}for(const[i,c]of[...this.#n])a.has(i)||(c.skeleton.dispose(),c.boneRoot.removeFromParent(),this.#n.delete(i),s=!0);this.#r++;const f=await n.clip(),u=this.#t,m=f?.action!==u?.action||f?.tracks.length!==u?.tracks.length||f?.clipStart!==u?.clipStart||f?.clipEnd!==u?.clipEnd;this.#t=f??null,f?.reason&&r.push(f.reason),f&&(m||s)&&this.#h(t,f,r);const l=this.#e?.snapshot().playbackState==="playing";f&&!l&&u?.frameCurrent!==f.frameCurrent&&(this.#c(f.frameCurrent),this.#e&&f.fps>0&&this.#e.seek(f.frameCurrent/f.fps)),this.#_=r,this.#f()}#d(t,n,e,r){const a=t.objectForBlenderName(n.object??""),s=t.objectForBlenderName(n.armature??"");if(!a||!s)return null;const f=a,u=f.geometry;if(!u)return null;const m=u.getAttribute("blenderVertex");if(!m)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 A=0;A<m.count;A++)l=Math.max(l,m.getX(A));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 i=bi(n.skinIndexBase64??""),c=Kn(n.skinWeightBase64??""),_=m.count,d=new Uint16Array(_*4),h=new Float32Array(_*4);for(let A=0;A<_;A++){const T=m.getX(A);for(let O=0;O<4;O++)d[A*4+O]=i[T*4+O]??0,h[A*4+O]=c[T*4+O]??0}u.setAttribute("skinIndex",new xa(d,4)),u.setAttribute("skinWeight",new Mt(h,4));const v=new st;v.name=`${n.armature}:bones`;const p=[],g=n.bones.map(A=>yi(A.pose)),b=new Map(n.bones.map((A,T)=>[A.name,T]));n.bones.forEach((A,T)=>{const O=new ba;O.name=A.name,p.push(O);const E=A.parent===null?void 0:b.get(A.parent);(E===void 0?g[T].clone():g[E].clone().invert().multiply(g[T])).decompose(O.position,O.quaternion,O.scale),(E===void 0?v:p[E]).add(O)}),s.add(v);const y=new ya(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 wa(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:v,bones:p,skeleton:S,frame:e,signature:re(n,e)}}#h(t,n,e){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 i of this.#n.values())if(i.armature===n.armature)for(const c of i.bones)a.set(c.name,c);const s=[],f=new Set;for(const i of n.tracks){const c=a.get(i.bone);if(!c){f.add(i.bone);continue}const _=Kn(i.timeBase64),d=Kn(i.valueBase64),h=`${c.uuid}.${i.property}`;s.push(i.property==="quaternion"?new Oa(h,Array.from(_),Array.from(d)):new Aa(h,Array.from(_),Array.from(d)))}if(f.size&&e.push(`${n.action} animates ${[...f].join(", ")}, which this binding has no bone for.`),!s.length)return;const u=n.duration??(n.clipEnd-n.clipStart)/n.fps,m=new Ta(r),l=m.clipAction(new Sa(n.action??"action",u,s));l.setLoop(Ma,Number.POSITIVE_INFINITY),l.play(),this.#o=m,this.#a=l,this.#c(n.frameCurrent),this.#m()}#c(t){const n=this.#t;if(!n||!this.#o||n.clipStart===void 0||n.clipEnd===void 0)return;const e=Math.min(n.clipEnd,Math.max(n.clipStart,t));this.#i=e;const r=(n.clipEnd-n.clipStart)/n.fps;this.#o.setTime(Math.min(r-1e-4,(e-n.clipStart)/n.fps)),this.#m()}#m(){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 e=n.scene;return!e||n.frameCurrent===t||(this.#r++,await Ra(`bpy.data.scenes[${JSON.stringify(e)}]`,"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 s=this.#t,f=s?.fps||24;return{start:(s?.frameStart??1)/f,end:(s?.frameEnd??250)/f,fps:f}},seek:s=>this.seekSeconds(s)}),e=t.onSettled(()=>{this.writeBookmark()}),r=()=>{e(),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;for(const t of this.#n.values())t.skeleton.dispose(),t.boneRoot.removeFromParent();this.#n.clear()}}const We=new wi;function Ei(o){return We.subscribe(o)}function Ni(){return We.version}export{We as a,Ni as b,Pi as c,Ei as s};