@volter/game-editor 0.5.132 → 0.5.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/BUNDLED_NOTICES +22 -22
  2. package/catalog/entries/blender.json +2 -2
  3. package/catalog/entries/music.json +2 -2
  4. package/dist/.vite/manifest.json +2215 -2215
  5. package/dist/assets/{AssetBudgetPanel-CYes0IEg.js → AssetBudgetPanel-BnRU2kQB.js} +3 -3
  6. package/dist/assets/{AudioViewer-BO_jk5aG.js → AudioViewer-APY_kwxf.js} +1 -1
  7. package/dist/assets/{CanvasBoardDocument-Do6Tvy46.js → CanvasBoardDocument-C_UNDzXm.js} +1 -1
  8. package/dist/assets/{CanvasSceneViewport-BE_VvxxZ.js → CanvasSceneViewport-n-h94wHo.js} +1 -1
  9. package/dist/assets/{ColorInput-BGReDSPg.js → ColorInput-wbKatDDA.js} +1 -1
  10. package/dist/assets/{ColorPicker-CexGcDei.js → ColorPicker-CJ09zfEX.js} +1 -1
  11. package/dist/assets/{EntityModelDocument-s1qggj5n.js → EntityModelDocument-1iHP5Yws.js} +1 -1
  12. package/dist/assets/{EnvironmentAssetDocument-BS0oJypZ.js → EnvironmentAssetDocument-Cqj5d6_6.js} +1 -1
  13. package/dist/assets/{GameplaySessionTimeline-Bp4bmhwB.js → GameplaySessionTimeline-DykRF4LC.js} +1 -1
  14. package/dist/assets/{ImageViewer-DfZXdgaj.js → ImageViewer-DwbhIBCP.js} +1 -1
  15. package/dist/assets/InspectorObjectPreview-mo9bGLDT.js +1 -0
  16. package/dist/assets/{JsonAssetDocument-DfRCa3pU.js → JsonAssetDocument-B6gQHP_k.js} +1 -1
  17. package/dist/assets/{LiveModuleDocument-B1z_Xd3V.js → LiveModuleDocument-SBoCwIoE.js} +1 -1
  18. package/dist/assets/{LutAssetDocument-BrndEqtp.js → LutAssetDocument-BuWiW1Aw.js} +1 -1
  19. package/dist/assets/{ModelAssetDocument-eRTQFv4d.js → ModelAssetDocument-BXkgYOqI.js} +1 -1
  20. package/dist/assets/{NonThreeAuthoringBootstrap-bD0jqhw2.js → NonThreeAuthoringBootstrap-6pJucZf5.js} +1 -1
  21. package/dist/assets/{Object3DDocumentToolbar-BKzrVucz.js → Object3DDocumentToolbar-ALMB9mRe.js} +1 -1
  22. package/dist/assets/Object3DDocumentViewport-eDH3ZPyb.js +2 -0
  23. package/dist/assets/{Object3DPreview-BTXLkLUA.js → Object3DPreview-CJApeNHw.js} +1 -1
  24. package/dist/assets/{OnlineAssetDetail-B1oJAYqh.js → OnlineAssetDetail-Cd8JLsmA.js} +1 -1
  25. package/dist/assets/{PlayBar-bBGwzWU2.js → PlayBar-DGrUfgBZ.js} +1 -1
  26. package/dist/assets/{QuarksAssetDocument-CAGaGs_u.js → QuarksAssetDocument-C5v0bZtn.js} +1 -1
  27. package/dist/assets/{ReactCanvasControls-Bo56uyZL.js → ReactCanvasControls-M_9_8r5E.js} +1 -1
  28. package/dist/assets/{RootSelectionOverlay-DhiFKp3P.js → RootSelectionOverlay-D2hkUn8m.js} +1 -1
  29. package/dist/assets/{ShaderAssetDocument-BdkND-_p.js → ShaderAssetDocument-BmUKEHj6.js} +1 -1
  30. package/dist/assets/{ShadowEditor-BzqvU5sU.js → ShadowEditor-DS5CSZPa.js} +1 -1
  31. package/dist/assets/{SourceAssetViewer-DSzC_ulp.js → SourceAssetViewer-B2ZVLQeS.js} +1 -1
  32. package/dist/assets/{StageHost-GlSSCH7U.js → StageHost-DnZzSENp.js} +2 -2
  33. package/dist/assets/{StoryPreviewMount-DFSxkZPA.js → StoryPreviewMount-BKzvcFEZ.js} +1 -1
  34. package/dist/assets/{ThreeBoardDocument-DiraB0-B.js → ThreeBoardDocument-Cmnf4bFN.js} +2 -2
  35. package/dist/assets/{ThreeIsolationSceneContent-HmCqiQe1.js → ThreeIsolationSceneContent-Bvf6_SKQ.js} +1 -1
  36. package/dist/assets/{ToolObject3DPreview-BVter7Q5.js → ToolObject3DPreview-ODzhSGUY.js} +1 -1
  37. package/dist/assets/{Toolbar-DEUsPVtM.js → Toolbar-Q6UFDDfz.js} +1 -1
  38. package/dist/assets/{TransientHint-DIo3RQCu.js → TransientHint-nzWtXMB3.js} +1 -1
  39. package/dist/assets/{VideoViewer-CgnPQItf.js → VideoViewer-Yew5uBNv.js} +1 -1
  40. package/dist/assets/{ViewportShadingMenu-B3fHtFwv.js → ViewportShadingMenu-DzKK2NTI.js} +1 -1
  41. package/dist/assets/{active-ingest-De1C3GJy.js → active-ingest-B7Bx6Kjy.js} +2 -2
  42. package/dist/assets/{animation-clock-gv4lO0k0.js → animation-clock-ua6aqPSU.js} +1 -1
  43. package/dist/assets/{animation-mixers.service-DO7PaXtg.js → animation-mixers.service-CzIth3sy.js} +1 -1
  44. package/dist/assets/{animation-timeline.utility-Z6ZESpXA.js → animation-timeline.utility-DX06Ydcc.js} +1 -1
  45. package/dist/assets/{asset-budget-asset.menu-D8sM--w8.js → asset-budget-asset.menu-Dz9btntn.js} +1 -1
  46. package/dist/assets/{asset-budget.action-D_F90rjL.js → asset-budget.action-BaYK7AMY.js} +1 -1
  47. package/dist/assets/{asset-budget.document-rNPlXjgk.js → asset-budget.document-nfLfGypF.js} +1 -1
  48. package/dist/assets/{asset-budget.menu-CJbLv5ru.js → asset-budget.menu-ButY7KmH.js} +1 -1
  49. package/dist/assets/{asset-editor-persistence-MC-kjXrU.js → asset-editor-persistence-C02issMD.js} +1 -1
  50. package/dist/assets/{asset-loaders-DlAQGaTP.js → asset-loaders-DH3zQQyY.js} +1 -1
  51. package/dist/assets/{asset-preview-BgpppW0K.js → asset-preview-CUSDAKVD.js} +1 -1
  52. package/dist/assets/{audio-unlock.service-DW4L13F4.js → audio-unlock.service-BfHkRn4Q.js} +1 -1
  53. package/dist/assets/{audio.utility-DApwFrzp.js → audio.utility-DnYmvJaJ.js} +1 -1
  54. package/dist/assets/autoplay.service-dVunBDzc.js +1 -0
  55. package/dist/assets/{babylon-authoring-adapter-CtKDtAlC.js → babylon-authoring-adapter-CMds1oHl.js} +1 -1
  56. package/dist/assets/{binding-resolver-AJBTQdOB.js → binding-resolver-DAZbNLvl.js} +2 -2
  57. package/dist/assets/{blender-node-editor.document-Eki8BNrs.js → blender-node-editor.document-Cn_RaJd_.js} +1 -1
  58. package/dist/assets/{blender-properties-tab-CLqP7Xiq.js → blender-properties-tab-DRdodc8X.js} +1 -1
  59. package/dist/assets/{blender-runtime-host-C-ODv7jm.js → blender-runtime-host-BLx1pw_g.js} +1 -1
  60. package/dist/assets/{blender-runtime-skin-DFyXt3vm.js → blender-runtime-skin-cc-flxJ4.js} +38 -38
  61. package/dist/assets/{blender-runtime.document-BFQtCc9w.js → blender-runtime.document-D4Ay0UIU.js} +1 -1
  62. package/dist/assets/{blender-screenshot.menu-b-oPOmD2.js → blender-screenshot.menu-BKeeQIpY.js} +1 -1
  63. package/dist/assets/blender-timeline.document-VBQuZfml.js +1 -0
  64. package/dist/assets/{blender-uv-editor.document-BokuKH_u.js → blender-uv-editor.document-3P89aBqA.js} +1 -1
  65. package/dist/assets/{blender-version.status-DFdtM7wW.js → blender-version.status-DhwfFeCK.js} +1 -1
  66. package/dist/assets/{blender.command-C5ihpwWq.js → blender.command-wYCfmF07.js} +1 -1
  67. package/dist/assets/{board-guides-m20r2cVK.js → board-guides-DhqfTj5n.js} +1 -1
  68. package/dist/assets/{bridge.command-8mTJCY3X.js → bridge.command-DsDiqGCg.js} +3 -3
  69. package/dist/assets/{browserAll-u8qYn74-.js → browserAll-DOR1aAYd.js} +1 -1
  70. package/dist/assets/{build-player.document-GxOaxjaP.js → build-player.document-CjucTAel.js} +1 -1
  71. package/dist/assets/{build-profiles.document-C_H_jJWM.js → build-profiles.document-OSj4WtI6.js} +1 -1
  72. package/dist/assets/{build-progress.status-B_KJsTAk.js → build-progress.status-DpFB4xx7.js} +1 -1
  73. package/dist/assets/{build-session-MXmNrR4d.js → build-session-5PJwpLFV.js} +1 -1
  74. package/dist/assets/{build.action-Cgmy3CV8.js → build.action-KWfvGCPe.js} +1 -1
  75. package/dist/assets/{build.command-DQ513o1i.js → build.command-BDvxmPia.js} +1 -1
  76. package/dist/assets/{build.header-DjZC6-Rq.js → build.header-DZdsvA42.js} +1 -1
  77. package/dist/assets/{build.menu-Dzi2vwJm.js → build.menu-DnRnkEAP.js} +1 -1
  78. package/dist/assets/{build.service-BrDqnjDv.js → build.service-D4LFhhty.js} +1 -1
  79. package/dist/assets/{camera-BP8DJEuu.js → camera-C6YJy8Z5.js} +1 -1
  80. package/dist/assets/{camera-runtime.inspector-DNkcmcra.js → camera-runtime.inspector-CzHA8sdx.js} +1 -1
  81. package/dist/assets/{canvas-design-mount-DjgEhthW.js → canvas-design-mount-Csy3XYVZ.js} +3 -3
  82. package/dist/assets/{canvas-entry-runtime-DomDtmkf.js → canvas-entry-runtime-BO4oWzG7.js} +2 -2
  83. package/dist/assets/{canvas-preview-frames-DPB4jM38.js → canvas-preview-frames-D4WhZx86.js} +1 -1
  84. package/dist/assets/{canvas-story-capture.service-CH0V5qBt.js → canvas-story-capture.service-VWrbKO8n.js} +2 -2
  85. package/dist/assets/{capability-coverage-DWmGGq0E.js → capability-coverage-BVGLH6f3.js} +1 -1
  86. package/dist/assets/{collaboration-presence-B2ST9_HY.js → collaboration-presence-BxAjjabG.js} +1 -1
  87. package/dist/assets/{collider-CYh-GGAI.js → collider-D6Z5sU1J.js} +1 -1
  88. package/dist/assets/{component-board.service-CwkSCtj6.js → component-board.service-BN9KXIEI.js} +2 -2
  89. package/dist/assets/{component-board.service-ueks5d-6.js → component-board.service-BPJ1jCbB.js} +2 -2
  90. package/dist/assets/{component-board.service-XnP1glvg.js → component-board.service-FV3r_rY1.js} +2 -2
  91. package/dist/assets/{component-contracts.service-DwaJvihV.js → component-contracts.service-6QSOPpXN.js} +1 -1
  92. package/dist/assets/{component-instance-root-CJXaEHPU.js → component-instance-root-BoFJeP3p.js} +1 -1
  93. package/dist/assets/{component-verbs.command-CZDDJuEn.js → component-verbs.command-2-turNau.js} +1 -1
  94. package/dist/assets/{component-verbs.service-COVPMNuj.js → component-verbs.service-DfUDkdGk.js} +1 -1
  95. package/dist/assets/{config-B8FaCuZD.js → config-Bztkil1G.js} +2 -2
  96. package/dist/assets/{configurations-Cio2q_6v.js → configurations-DuojTa-o.js} +1 -1
  97. package/dist/assets/{connection.status-E9LMLVGe.js → connection.status-CGSGpay5.js} +1 -1
  98. package/dist/assets/{constraints.inspector-BmhmgeqN.js → constraints.inspector-CCdKAdlH.js} +1 -1
  99. package/dist/assets/{content-bounds-BT_CFO5V.js → content-bounds-Co-PYlfQ.js} +1 -1
  100. package/dist/assets/{contract-system-adapters-Do_W5his.js → contract-system-adapters-Dyt4JsZ2.js} +1 -1
  101. package/dist/assets/{coverage.service-BuVhBOBF.js → coverage.service-DkqUci3V.js} +1 -1
  102. package/dist/assets/{create-runtime-BkCETnZY.js → create-runtime-DNZHaW7E.js} +1 -1
  103. package/dist/assets/{curve-AXU7haE_.js → curve-Q4ixuhFA.js} +1 -1
  104. package/dist/assets/{data-asset-BDbFbHIy.js → data-asset-PPdHjKmp.js} +1 -1
  105. package/dist/assets/{data-ref-kf4APQd6.js → data-ref-C6iWA_I5.js} +1 -1
  106. package/dist/assets/{debug-bridge-CZPupYRz.js → debug-bridge-pOOsQYPl.js} +1 -1
  107. package/dist/assets/{debug-registry-CKw7CeUV.js → debug-registry-BMJTM1HD.js} +1 -1
  108. package/dist/assets/{deferred-ingest-play-BRA_gEtr.js → deferred-ingest-play-nOdDr56P.js} +2 -2
  109. package/dist/assets/{design-time-canvas-mount-DINx6VmU.js → design-time-canvas-mount-69gW0Lse.js} +2 -2
  110. package/dist/assets/{design-time-layers-B-bN4gwF.js → design-time-layers-e7s2mfFg.js} +1 -1
  111. package/dist/assets/{design-time-mount.service-B4hbzTgs.js → design-time-mount.service-BlVPZvQM.js} +2 -2
  112. package/dist/assets/{design-time-mount.service-DU6xc5bA.js → design-time-mount.service-XiqsUVLQ.js} +2 -2
  113. package/dist/assets/{design-time-react-mount-gmy2EFvn.js → design-time-react-mount-DEUIOsob.js} +1 -1
  114. package/dist/assets/{document-preview-three-CJGMIghI.js → document-preview-three-CJkokdk6.js} +1 -1
  115. package/dist/assets/{dom-authoring-adapter-CPdBJ2BL.js → dom-authoring-adapter-DcCpYSGq.js} +1 -1
  116. package/dist/assets/{draco3d-CRVpxGh6.js → draco3d-DZIK4PnL.js} +1 -1
  117. package/dist/assets/{edit-mode-audio.service-CH6EzqbQ.js → edit-mode-audio.service-D--lxJv-.js} +1 -1
  118. package/dist/assets/{edit-mode-authoring-CBZhukjS.js → edit-mode-authoring-DvttMmGa.js} +1 -1
  119. package/dist/assets/{edit-mode-networking.service-vdRvu3xe.js → edit-mode-networking.service-C2I6_G9e.js} +1 -1
  120. package/dist/assets/{editor-api-DQ5ut650.js → editor-api-C8B9DKXH.js} +1 -1
  121. package/dist/assets/{editor-layers-Rqx9b0j-.js → editor-layers-QQ71XEXw.js} +1 -1
  122. package/dist/assets/{editor-shell-store-D5YQF3t7.js → editor-shell-store-CaTC9o0j.js} +1 -1
  123. package/dist/assets/{entity-object-C73fFbZD.js → entity-object-gLXLhu07.js} +1 -1
  124. package/dist/assets/{extend-Cz-Z8F-t.js → extend-BAs8mBac.js} +1 -1
  125. package/dist/assets/{fork-menu-DCl-svx1.js → fork-menu-YtIgQlm6.js} +1 -1
  126. package/dist/assets/{frame-debugger-store-Cfld9MWU.js → frame-debugger-store-BCva72ZS.js} +1 -1
  127. package/dist/assets/{game-contract-seams-CibSTTBV.js → game-contract-seams-BpZs1yjv.js} +1 -1
  128. package/dist/assets/{game-css-scope-transform-BNwfzDMU.js → game-css-scope-transform-rixXd3RE.js} +1 -1
  129. package/dist/assets/{game-document.service-CvKj8K_3.js → game-document.service-BI067uXs.js} +1 -1
  130. package/dist/assets/{game-eval.command-DI4j7fd-.js → game-eval.command-BWsYFDdH.js} +1 -1
  131. package/dist/assets/{game-module-access-Cl-D-P7I.js → game-module-access-BVnu_YF6.js} +1 -1
  132. package/dist/assets/{game-network-BvDLoUzV.js → game-network-YNnA__rm.js} +3 -3
  133. package/dist/assets/{gameplay-export-DAT2x5RQ.js → gameplay-export-CYs9Zf28.js} +1 -1
  134. package/dist/assets/{gameplay-replay-cgU3mdmQ.js → gameplay-replay-onLTM9_v.js} +1 -1
  135. package/dist/assets/{gameplay.command-Q4DLRqho.js → gameplay.command-BL9yIUkk.js} +1 -1
  136. package/dist/assets/{generation-jobs-wxgCnKyf.js → generation-jobs-IpL1oPd3.js} +1 -1
  137. package/dist/assets/{generation.service-_axQFwVL.js → generation.service-B8Nhb_tQ.js} +1 -1
  138. package/dist/assets/{generations-DrC_jZAp.js → generations-IQHXLtg8.js} +1 -1
  139. package/dist/assets/{generations.status-W0fqd27H.js → generations.status-BkLggMhB.js} +1 -1
  140. package/dist/assets/{hierarchy-marks-cLXIF47A.js → hierarchy-marks-C9FKSQHH.js} +1 -1
  141. package/dist/assets/{hosted-asset-materialization-DXUTouMN.js → hosted-asset-materialization-sdG-aTgR.js} +1 -1
  142. package/dist/assets/{index-DZwzkDHN.js → index-6X2RM7YY.js} +1 -1
  143. package/dist/assets/{index-DuuG5Vks.js → index-B-vtuqkx.js} +1 -1
  144. package/dist/assets/{index-9sQHLCIf.js → index-BGKXoVeu.js} +1 -1
  145. package/dist/assets/{index-a0B9WdoQ.js → index-Bug1xbYx.js} +1 -1
  146. package/dist/assets/{index-Dc45_dU0.js → index-CcrH9u0V.js} +1 -1
  147. package/dist/assets/{index-yicXODZy.js → index-CkjrzX4P.js} +2 -2
  148. package/dist/assets/{index-B-3voSn5.js → index-DoSChd6Z.js} +1 -1
  149. package/dist/assets/{index-BlR8t-k_.js → index-Dw9Rpena.js} +1 -1
  150. package/dist/assets/{index-Bg3AEnyx.js → index-nySnA9Ug.js} +7 -7
  151. package/dist/assets/{inference-diagnostics-Dc6FeZ2p.js → inference-diagnostics-DuPm6O0g.js} +1 -1
  152. package/dist/assets/{ingest-boot-viewport-pl7yDfgl.js → ingest-boot-viewport-BlkNjuqD.js} +1 -1
  153. package/dist/assets/{ingest-siblings-CheNQoM8.js → ingest-siblings-B8-3Jax7.js} +1 -1
  154. package/dist/assets/{ingest-source-persistence-DIEj1x0V.js → ingest-source-persistence-Bgpi9aX2.js} +1 -1
  155. package/dist/assets/{ingest.service-DwYX9OtQ.js → ingest.service-CiB-mBHW.js} +1 -1
  156. package/dist/assets/{inspect-Xi6dNrJt.js → inspect-ecnGo6h9.js} +1 -1
  157. package/dist/assets/instances.command-BUjh8RK6.js +1 -0
  158. package/dist/assets/{json-history-resource-BNpWd_Y5.js → json-history-resource-Dp7Ra99p.js} +1 -1
  159. package/dist/assets/{layered-pick-CXJgTZ4-.js → layered-pick-B0x-Imc-.js} +1 -1
  160. package/dist/assets/{light-CBa0tJl3.js → light-CqVkPR2u.js} +1 -1
  161. package/dist/assets/{live-project-verbs-Bgqy-syg.js → live-project-verbs-BPKYAVhO.js} +1 -1
  162. package/dist/assets/{machine.document-Bszi_-Zz.js → machine.document-vhHf8j8j.js} +1 -1
  163. package/dist/assets/{machines.finder-DTpgz1d9.js → machines.finder-CYGcoUpx.js} +1 -1
  164. package/dist/assets/{material-DtEASi8u.js → material-C0kJ03PJ.js} +1 -1
  165. package/dist/assets/{material-factory-CSw3VfgO.js → material-factory-BYajdLke.js} +1 -1
  166. package/dist/assets/{mesh-DSxqXX07.js → mesh-CQC683US.js} +1 -1
  167. package/dist/assets/{model-asset-sections.service-DtlRu_Sn.js → model-asset-sections.service-Dh79mFYs.js} +1 -1
  168. package/dist/assets/{model-inspection-Cmuasl89.js → model-inspection-KJJ116pG.js} +1 -1
  169. package/dist/assets/{model-thumbnail-BP2zk33X.js → model-thumbnail-Cx5Eb_fd.js} +1 -1
  170. package/dist/assets/{models.finder-Iv0OrNg9.js → models.finder-DIkds1Nj.js} +1 -1
  171. package/dist/assets/{module-mode-BjL1xa5d.js → module-mode-CPoFoRzV.js} +2 -2
  172. package/dist/assets/{mount-canvas-ingest-root-c-UQySHD.js → mount-canvas-ingest-root-BrZ0PEjk.js} +2 -2
  173. package/dist/assets/{mount-dom-ingest-root-BIwiFQLD.js → mount-dom-ingest-root-BcP-acNo.js} +2 -2
  174. package/dist/assets/{mount-ingest-root-DLo2qI4K.js → mount-ingest-root-Wf5fhTMH.js} +2 -2
  175. package/dist/assets/{mount-manifest-BfHZpIcc.js → mount-manifest-CXdSgRBq.js} +1 -1
  176. package/dist/assets/{mount-three-ingest-root-SrjAquAI.js → mount-three-ingest-root-VINQZrMq.js} +1 -1
  177. package/dist/assets/{mounted-authoring-C1pAEBgT.js → mounted-authoring-D7_0P8Yg.js} +1 -1
  178. package/dist/assets/{mounted-story-viewport-source-CCBdpou-.js → mounted-story-viewport-source-esB5WiW7.js} +1 -1
  179. package/dist/assets/{native-debug-module-B2QeYAr2.js → native-debug-module-DiyEiCfH.js} +1 -1
  180. package/dist/assets/{navigation-B5vgJHXW.js → navigation-CCfxrKnm.js} +1 -1
  181. package/dist/assets/{navmesh.menu-39zXRWDE.js → navmesh.menu-3oJTvzhD.js} +1 -1
  182. package/dist/assets/{navmesh.service-BJ78wAVA.js → navmesh.service-CIqD64Ey.js} +1 -1
  183. package/dist/assets/network-observer.service-fJ2m395K.js +1 -0
  184. package/dist/assets/{network.utility-ckqL_XZ2.js → network.utility-CEASCNxw.js} +1 -1
  185. package/dist/assets/{object3d-document-session-registry-DApvRX_f.js → object3d-document-session-registry-B46cPnBb.js} +2 -2
  186. package/dist/assets/{oid-transform-5pjTypXJ.js → oid-transform-BzFi809X.js} +1 -1
  187. package/dist/assets/{particles-J_lZuIf_.js → particles-er7NMOfH.js} +1 -1
  188. package/dist/assets/{pixi-authoring-adapter-DuVLOvgq.js → pixi-authoring-adapter-DJcOr94r.js} +1 -1
  189. package/dist/assets/{pixi-live-write-target-DETS552o.js → pixi-live-write-target-DhHlW0I4.js} +1 -1
  190. package/dist/assets/{play.command-Sd2buonL.js → play.command-CMH6uH3C.js} +2 -2
  191. package/dist/assets/{presentation-B3iqNAZ7.js → presentation-DfHrJ94Q.js} +1 -1
  192. package/dist/assets/{product-BbPe8FAn.js → product-KBRPPO6a.js} +1 -1
  193. package/dist/assets/{profiler.action-DELlxeRB.js → profiler.action-Bc7TMkqb.js} +1 -1
  194. package/dist/assets/{profiler.menu-frKlY1Qe.js → profiler.menu-BcZq6Rmy.js} +1 -1
  195. package/dist/assets/{profiler.utility-DV3o5CXC.js → profiler.utility-CksJa-lj.js} +1 -1
  196. package/dist/assets/{project-authoring-session-xezkIvOt.js → project-authoring-session-C9_9Hb8-.js} +2 -2
  197. package/dist/assets/{properties-bone-constraints.inspector-C_G2c9VM.js → properties-bone-constraints.inspector-31lt8g6y.js} +1 -1
  198. package/dist/assets/{properties-bone.inspector-DYFDjAuo.js → properties-bone.inspector-FxL_XMOQ.js} +1 -1
  199. package/dist/assets/{properties-collection.inspector-Dxr9wpFF.js → properties-collection.inspector-DhcrjTYn.js} +1 -1
  200. package/dist/assets/{properties-constraints.inspector-DaUfUqwE.js → properties-constraints.inspector-Coe1A1Dd.js} +1 -1
  201. package/dist/assets/{properties-data.inspector-CRGFOh9i.js → properties-data.inspector-YKEhk2KI.js} +1 -1
  202. package/dist/assets/{properties-material.inspector-C-iO9MP6.js → properties-material.inspector-B2UhDK1n.js} +1 -1
  203. package/dist/assets/{properties-modifiers.inspector-bN39Wx4j.js → properties-modifiers.inspector-uOwwcmRf.js} +1 -1
  204. package/dist/assets/{properties-object.inspector-C2b-sP3b.js → properties-object.inspector-D8kiIU1x.js} +1 -1
  205. package/dist/assets/{properties-output.inspector-BHJw3uNE.js → properties-output.inspector-RaoeccQZ.js} +1 -1
  206. package/dist/assets/{properties-particles.inspector-DFd0Lb3j.js → properties-particles.inspector-D0Jb5Ts7.js} +1 -1
  207. package/dist/assets/{properties-physics.inspector-DfTBsjc9.js → properties-physics.inspector-BIubmBiu.js} +1 -1
  208. package/dist/assets/{properties-render.inspector-CMFUfqtg.js → properties-render.inspector-BPamVV35.js} +1 -1
  209. package/dist/assets/{properties-scene.inspector-C23LzqIe.js → properties-scene.inspector-B2mjYWyc.js} +1 -1
  210. package/dist/assets/{properties-texture.inspector-DSaICAQ9.js → properties-texture.inspector-iH7Hdsai.js} +1 -1
  211. package/dist/assets/{properties-view-layer.inspector-Bc8wIs-O.js → properties-view-layer.inspector-BXjmwWhZ.js} +1 -1
  212. package/dist/assets/{properties-world.inspector-Bud399V8.js → properties-world.inspector-CUhszQm_.js} +1 -1
  213. package/dist/assets/{r3f-design-session-Dd9FDWS5.js → r3f-design-session-BT_FNbxu.js} +2 -2
  214. package/dist/assets/{r3f-physics-binding-Ccv5byoU.js → r3f-physics-binding-BWdDgRxd.js} +1 -1
  215. package/dist/assets/{r3f-source-authoring-adapter-DuRyw91E.js → r3f-source-authoring-adapter-B0E5IqBw.js} +1 -1
  216. package/dist/assets/{react-canvas-navigation-D2pwbCQJ.js → react-canvas-navigation-Dr5dRfTS.js} +1 -1
  217. package/dist/assets/{react-inspector.service-Bz1C4n9i.js → react-inspector.service-BiPd_duU.js} +1 -1
  218. package/dist/assets/{react-story-board-CIDGN7cf.js → react-story-board-CdtjLDYv.js} +1 -1
  219. package/dist/assets/{react-three-rapier.esm-Cwq9RYsV.js → react-three-rapier.esm-BRNjkQwe.js} +1 -1
  220. package/dist/assets/{react-world-authoring-adapter-pqd1lPx9.js → react-world-authoring-adapter-BydYut9T.js} +1 -1
  221. package/dist/assets/{realm-services-JmzH4rcP.js → realm-services-BsB1S4Eh.js} +1 -1
  222. package/dist/assets/{reflection-probe-capture.inspector-DaBZu_cH.js → reflection-probe-capture.inspector-Ci5hFo5Q.js} +1 -1
  223. package/dist/assets/{registry-BaMQDa-A.js → registry-BiYDDckl.js} +1 -1
  224. package/dist/assets/{relative-import-specifier-Duuu4gXr.js → relative-import-specifier-CwidALJP.js} +1 -1
  225. package/dist/assets/{render-env-B5f-Bwwj.js → render-env-BchkLjDP.js} +1 -1
  226. package/dist/assets/{render-features-DwgMzBsk.js → render-features-BYXvPGUA.js} +1 -1
  227. package/dist/assets/{render-settings-DnmD9VcB.js → render-settings-DGLz2Ame.js} +1 -1
  228. package/dist/assets/{resolve-three-DaSv-3sP.js → resolve-three-DetBiJb1.js} +3 -3
  229. package/dist/assets/{root-seam-contract-DnEOLx--.js → root-seam-contract-bbvHIRf5.js} +1 -1
  230. package/dist/assets/{run-selection-DMb2aqC6.js → run-selection-BBeVaGgf.js} +1 -1
  231. package/dist/assets/{scene-capture-0V__UQfv.js → scene-capture-B1qVmZZy.js} +1 -1
  232. package/dist/assets/{scene-document.service-CyE0PY1i.js → scene-document.service-CkqKSFhN.js} +2 -2
  233. package/dist/assets/{scene-framing-CDeK7bJW.js → scene-framing-DmGFFnxb.js} +1 -1
  234. package/dist/assets/{seeded-random-B_3qcArj.js → seeded-random-DY3-ydOg.js} +1 -1
  235. package/dist/assets/{setup-renderer--3oKgA1Q.js → setup-renderer-C1HERM3i.js} +1 -1
  236. package/dist/assets/{source-object3d-authoring-adapter-bWA0uEKg.js → source-object3d-authoring-adapter-Deft82fS.js} +1 -1
  237. package/dist/assets/{source-persistence-backend-B2JWxYHZ.js → source-persistence-backend-DxRc3Vmw.js} +1 -1
  238. package/dist/assets/{stage-keyboard-BbKSjl5q.js → stage-keyboard-CtFcg-KZ.js} +1 -1
  239. package/dist/assets/{stage-overlay-set-D2KLN__e.js → stage-overlay-set-DSS29nHE.js} +1 -1
  240. package/dist/assets/{stage-presence-markers-Dt5pQJfu.js → stage-presence-markers-CCO8UamH.js} +1 -1
  241. package/dist/assets/{stage-transform-tools-Cu8Chxtl.js → stage-transform-tools-Kdg5eF5v.js} +1 -1
  242. package/dist/assets/{standard-viewport-dressing-C3pgAxCf.js → standard-viewport-dressing-DXhgWBOp.js} +1 -1
  243. package/dist/assets/{state-watch.action-CXw1fCCG.js → state-watch.action-fSIdJUGZ.js} +1 -1
  244. package/dist/assets/{state-watch.menu-CmU6wSSp.js → state-watch.menu-Bfww1_mP.js} +1 -1
  245. package/dist/assets/{state-watch.utility-BhbhF7z4.js → state-watch.utility-DUSmbc6X.js} +1 -1
  246. package/dist/assets/{story-capture-DU6Y_dTu.js → story-capture-BxgNeexV.js} +1 -1
  247. package/dist/assets/{story-documents-BndI08gH.js → story-documents-C1oR_8cj.js} +1 -1
  248. package/dist/assets/{story-documents.service-CVGxejoQ.js → story-documents.service-BS2hN2Ce.js} +1 -1
  249. package/dist/assets/{story-documents.service-C6A0mP3I.js → story-documents.service-uV8KFn9S.js} +1 -1
  250. package/dist/assets/{story-media-presence-DrkuAnbx.js → story-media-presence-COUd6cak.js} +1 -1
  251. package/dist/assets/{story-pixi-preview-Be2B5WxF.js → story-pixi-preview-C5xQCGuv.js} +1 -1
  252. package/dist/assets/{story-presentation-D8Cz3yPF.js → story-presentation-CMvpmKUb.js} +1 -1
  253. package/dist/assets/{story-three-preview-ClNgLffM.js → story-three-preview-e0faozfl.js} +2 -2
  254. package/dist/assets/{studio-environment-Ciy6Xndv.js → studio-environment-B2vsjqle.js} +1 -1
  255. package/dist/assets/{surface-state-CuV0QrwV.js → surface-state-tKDJ4ZAb.js} +1 -1
  256. package/dist/assets/{syntactic-prop-specs-EVmFV4zp.js → syntactic-prop-specs-jY7NkRtv.js} +1 -1
  257. package/dist/assets/{team-playtest.service-DjhPfVwM.js → team-playtest.service-BptLup8r.js} +1 -1
  258. package/dist/assets/{three-BPA0U1fq.js → three-DNjStL2y.js} +1 -1
  259. package/dist/assets/{three-authoring-adapter-xZrPluWJ.js → three-authoring-adapter-DFD9SKE4.js} +1 -1
  260. package/dist/assets/three-authoring.service-CssoVcQx.js +2 -0
  261. package/dist/assets/{three-ingest-runtime-DvCgdwtm.js → three-ingest-runtime-elb0lM0i.js} +1 -1
  262. package/dist/assets/{three-integration-gF6oAoPm.js → three-integration-D-x0z186.js} +2 -2
  263. package/dist/assets/three-integration.service-CVpXIvOr.js +1 -0
  264. package/dist/assets/{three-projection-core-CpFP5QXx.js → three-projection-core-C_GCcPfW.js} +1 -1
  265. package/dist/assets/{three-state-BAgCuEwH.js → three-state-BU_Et2fb.js} +1 -1
  266. package/dist/assets/{three-story-capture.service-C1JBsYHU.js → three-story-capture.service-BcBLj5Ns.js} +2 -2
  267. package/dist/assets/{three-story-model-DYydLycU.js → three-story-model-DvgpSf5W.js} +1 -1
  268. package/dist/assets/{three-viewport-presentation-CORJhQGc.js → three-viewport-presentation-DU4LbXCX.js} +1 -1
  269. package/dist/assets/{transform-mode-request-HmWoFuNh.js → transform-mode-request-C9geEmE8.js} +1 -1
  270. package/dist/assets/{transport-strip-BpIjWpk4.js → transport-strip-C8yTDVnw.js} +1 -1
  271. package/dist/assets/transport.header-CMkmHYNe.js +1 -0
  272. package/dist/assets/{tuples-DhJ9Ig0X.js → tuples-CHM9-MeZ.js} +1 -1
  273. package/dist/assets/{ui-board-document-DqdHY68P.js → ui-board-document-B2BrHCE_.js} +2 -2
  274. package/dist/assets/{user-data-CGIelFYa.js → user-data-BiloulL-.js} +1 -1
  275. package/dist/assets/{utility-view-state-BBI0-q8Y.js → utility-view-state-BHfsAN18.js} +1 -1
  276. package/dist/assets/{viewport-door-DZ3cC_Uo.js → viewport-door-CJXG2Jxo.js} +1 -1
  277. package/dist/assets/{viewport-root-presentation-DFOvnL-9.js → viewport-root-presentation-B13UVzkf.js} +1 -1
  278. package/dist/assets/{viewport-surface-status-Bd4eiqk2.js → viewport-surface-status-BfoaH0c4.js} +1 -1
  279. package/dist/assets/{webworkerAll-PXmnmqgc.js → webworkerAll-D0rFmNNP.js} +1 -1
  280. package/dist/assets/{workspace-arrangement-DpMktiaR.js → workspace-arrangement-BzOJBZHz.js} +1 -1
  281. package/dist/assets/{world-documents-CMH5LRtf.js → world-documents-SfK4cE7-.js} +1 -1
  282. package/dist/assets/{world-root-stage-binding-Cotsl1GE.js → world-root-stage-binding-B_eeaou9.js} +1 -1
  283. package/dist/assets/{xstate-animation-binding-alcvtuRy.js → xstate-animation-binding-CJyISi6P.js} +1 -1
  284. package/dist/assets/{xstate-animation-meta-DmGpbxCk.js → xstate-animation-meta-CphrXz7c.js} +1 -1
  285. package/dist-node/cli.js +16 -16
  286. package/package.json +16 -16
  287. package/dist/assets/InspectorObjectPreview-D-w1K_6C.js +0 -1
  288. package/dist/assets/Object3DDocumentViewport-S5cSTUVY.js +0 -2
  289. package/dist/assets/autoplay.service-Cpn0HTbq.js +0 -1
  290. package/dist/assets/blender-timeline.document-TjErifcH.js +0 -1
  291. package/dist/assets/instances.command-BulsZgip.js +0 -1
  292. package/dist/assets/network-observer.service-D28WOR_U.js +0 -1
  293. package/dist/assets/three-authoring.service-CGzi7is0.js +0 -2
  294. package/dist/assets/three-integration.service-CFEShqeQ.js +0 -1
  295. package/dist/assets/transport.header-CRn0vQt_.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 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-Bg3AEnyx.js";import{S as Ut}from"./three.module-BLhyNg0e.js";import{t as Ra}from"./blender-runtime-host-C-ODv7jm.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=`
2
+ import{a as ro,b as so,L as io}from"./LineSegments2-DN9pUfWA.js";import{bh as st,cl as lo,fo as x,cm as H,N as gn,a$ as Mt,em as me,b4 as Ho,co as Rt,ey as qo,cp as Rn,_ as Ot,ej as $t,fd as Gt,er as Go,M as dt,cj as xt,dp as At,aV as Xo,cW as fo,aE as co,c7 as vt,j as Yo,f6 as Zo,fp as Cn,au as kn,dw as $n,bi as de,aT as Qo,c1 as Xt,dd as Jn,eC as te,e7 as Pn,aw as cn,da as Bt,I as pn,as as Ko,e8 as Jo,b0 as uo,K as ta,B as na,b9 as ea,Y as _o,cw as nn,ed as oa,cA as aa,fx as ra,db as mo,el as sa,R as ia,e6 as la,c0 as ho,bX as fa,aI as ne,ao as ca,eG as ua,d3 as _a,cs as ma,b5 as he,bu as po,aM as vo,ex as go,cO as In,cY as da,eU as ha,cE as ee,c5 as xo,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 bo,d_ as Lt,x as W,kE as bt,e1 as yo,mC as U,dZ as Ea,mD as Na}from"./index-nySnA9Ug.js";import{S as Ut}from"./three.module-BLhyNg0e.js";import{t as Ra}from"./blender-runtime-host-BLx1pw_g.js";const oe=new Set;function wt(){for(const e of[...oe])e()}function Ia(e){return oe.add(e),()=>{oe.delete(e)}}function ae(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}const on=N().finite(),za=M({name:R(),parent:R().nullable(),connected:Q(),hide:Q(),length:on,matrix:F(L([on,on,on,on])).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(e){return new Ot(e.r*e.r*.1,e.g*e.g*.1,e.b*e.b*.1)}const Vn=[[0,0,0],[.1,.1,.1],[.1,.1,-.1],[-.1,.1,-.1],[-.1,.1,.1],[0,1,0]],Se=[[2,1,0],[3,2,0],[4,3,0],[1,4,0],[5,1,2],[5,2,3],[5,3,4],[5,4,1]],It=Math.SQRT1_2,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 Me(e){return e.select||e.active?2:1}const La=10,Va=4,ja=`
3
3
  attribute vec3 aSolid;
4
4
  attribute vec3 aHint;
5
5
  varying vec3 vColor;
@@ -16,7 +16,7 @@ import{a as se,b as ie,L as le}from"./LineSegments2-DN9pUfWA.js";import{bh as st
16
16
  gl_FragColor = vec4(vColor, 1.0);
17
17
  #include <colorspace_fragment>
18
18
  }
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:`
19
+ `;function Dt(e){return new Ot().setHex(e,$t)}function Pe(e,t){const n=e.mode==="POSE";let o;return n?t.active&&t.select?o=Dt(St.poseActive):t.active?o=Dt(St.poseActiveUnsel):t.select?o=Dt(St.pose):o=Dt(St.wire):o=Dt(St.vertex),n&&t.lockedWeight&&o.lerp(Dt(St.lockedWeight),St.lockedWeightFactor),o}function Ee(e,t){const n=Dt(St.solid);return e.mode==="POSE"&&t.lockedWeight&&n.lerp(Dt(St.lockedWeight),St.lockedWeightFactor),n}const Ua=new H,Wa=new x,Ne=new lo;function Re(e,t){return new H().set(...t.matrix.flat()).premultiply(e).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 o=[],r=JSON.stringify(t);if(r===this.signature)return o;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"&&o.push(`armature ${a.object}: Blender's ${a.displayType} bone display needs data this door does not carry (B-Bone segment matrices, envelope radii), so its bones are drawn octahedral`),a.mode==="EDIT"&&o.push(`armature ${a.object}: in Edit Mode Blender draws the EDIT bones, and this overlay draws the pose — the shapes are the rest pose, not the edited one`);const f=a.bones.filter(d=>!d.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(d=>{const l=d.material;l&&"depthTest"in l&&(l.depthTest=!1),d.renderOrder=10}),this.group.add(u)}return o}buildOctahedral(t,n,o){const r=new st;r.name=`${t.object}:bones`;const a=[],s=[],f=[],u=[],d=[],l=[],i=[],c=[],_=[],m=[];for(const h of n){const v=Re(o,h),p=Ee(t,h),g=Fa(p),b=Pe(t,h);Ne.setFromMatrix4(v).invert().transpose();for(let A=0;A<Se.length;A++){const T=Wa.set(...Ca[A]).applyMatrix3(Ne).normalize().clone();for(const O of Se[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=Me(h)===2?i:d,S=Me(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()),m.push(p)),_.push(v.clone().multiply(Ua.makeTranslation(0,1,0))),m.push(p)}r.add(this.solidMesh(a,s,f,u)),d.length&&r.add(this.lines(d,l,1)),i.length&&r.add(this.lines(i,c,2));for(let h=0;h<_.length;h++)r.add(this.point(_[h],m[h]));return r}buildStick(t,n,o){const r=new st;r.name=`${t.object}:bones`;const a=[],s=[],f=[],u=[];for(const d of n){const l=Re(o,d),i=new x().setFromMatrixPosition(l),c=new x(0,1,0).applyMatrix4(l),_=Pe(t,d),m=Ee(t,d);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(m.r,m.g,m.b,m.r,m.g,m.b)}return r.add(this.lines(a,s,La)),r.add(this.lines(f,u,Va)),r}solidMesh(t,n,o,r){const a=new gn;a.setAttribute("position",new Mt(t,3)),a.setAttribute("normal",new Mt(n,3)),a.setAttribute("aSolid",new Mt(o,3)),a.setAttribute("aHint",new Mt(r,3));const s=new me({vertexShader:ja,fragmentShader:Ba,side:Ho});this.disposables.push(a,s);const f=new Rt(a,s);return f.frustumCulled=!1,f}lines(t,n,o){const r=new ro;r.setPositions(t),r.setColors(n);const a=new so({linewidth:o,vertexColors:!0});this.disposables.push(r,a);const s=new io(r,a);return s.frustumCulled=!1,s}point(t,n){const o=new qo($a,12,8),r=new Rn({color:n});this.disposables.push(o,r);const a=new Rt(o,r);return a.applyMatrix4(t),a.frustumCulled=!1,a}clear(){for(const t of[...this.group.children])this.group.remove(t);for(const t of this.disposables)t.dispose();this.disposables.length=0}dispose(){this.clear(),this.signature=""}}const Ie="RUNTIME_FRAME_UNKNOWN_GEOMETRY",an="RUNTIME_FRAME_UNKNOWN_IMAGE";function qa(e){const t=Math.fround,n=t(t(t(e[0]*e[0])+t(e[1]*e[1]))+t(e[2]*e[2]));if(n>1e-35){const o=t(Math.sqrt(n)),r=t(1/o);return{unit:[t(e[0]*r),t(e[1]*r),t(e[2]*r)],length:o}}return{unit:[0,0,0],length:0}}const I=Math.fround,zn=I(2*Math.PI),jn=I(1-1e-4),Wt=(e,t)=>I(I(I(e[0]*t[0])+I(e[1]*t[1]))+I(e[2]*t[2])),dn=(e,t,n=1)=>e.map((o,r)=>I(o+I(t[r]*n))),Ga=(e,t)=>e.map((n,o)=>I(n-t[o]));function rn(e){const t=I(Math.sqrt(Wt(e,e)));return t>0?e.map(n=>I(n/t)):[0,0,0]}function sn(e){const t=Math.abs(e)<1?I(1-I(1-Math.abs(e))):1;let n=I(I(.077980478)+I(t*I(-.02164095)));n=I(I(-.213300989)+I(t*n)),n=I(I(1.5707963267)+I(t*n));const o=I(I(Math.sqrt(I(1-t)))*n);return e<0?I(I(Math.PI)-o):o}function Xa(e){let t=e.at(-1);const n=[0,0,0];for(const o of e){for(let r=0;r<3;r++){const a=(r+1)%3,s=(r+2)%3;n[r]=I(n[r]+I(I(t[a]-o[a])*I(t[s]+o[s])))}t=o}return n}function Ya(e){const t=[],n=[],o=(m,h)=>m<h?`${m}:${h}`:`${h}:${m}`,r=new Map((e.edge_order??[]).map(([m,h],v)=>[o(m,h),v])),a=new Set((e.sharp??[]).map(([m,h])=>o(m,h))),s=new Map;for(const[m,h]of e.f.entries()){const v=t.length,p=qa(Xa(h.map(g=>e.v[g]))).unit;n.push(p.some(Boolean)?p:[0,0,1]);for(let g=0;g<h.length;g++){const b=o(h[g],h[(g+1)%h.length]);r.has(b)||r.set(b,r.size);const y=e.face_edges?.[m]?.[g]??r.get(b),S=t.length;t.push({vertex:h[g],face:m,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[m,h]of s){if(h.length!==2||e.edge_sharp?.[m])continue;const[v,p]=h,g=t[v],b=t[p];!e.s?.[g.face]||!e.s?.[b.face]||g.vertex!==t[b.next].vertex||b.vertex!==t[g.next].vertex||!e.edge_sharp&&a.has(o(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 d=[],l=[],i=[],c=[],_=(m,h)=>rn(Ga(e.v[t[t[m][h]].vertex],e.v[t[m].vertex]));for(let m=0;m<t.length;m++){if(l[m]!==void 0)continue;let h=m;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]=d.length;d.push(p),i.push(O),c.push(g)}return{corners:t,fans:d,fanOf:l,spaces:i,faceNormals:n,fanNormals:c}}function Za(e,t){if(!t[0]||e.alpha===0||e.beta===0)return e.normal;const n=I(t[0]/32767),o=I(t[1]/32767),r=I((n>0?e.alpha:I(zn-e.alpha))*n),a=I((o>0?e.beta:I(zn-e.beta))*o);let s=e.normal.map(f=>I(f*I(Math.cos(r))));return s=dn(s,e.reference,I(I(Math.sin(r))*I(Math.cos(a)))),o!==0&&(s=dn(s,e.ortho,I(I(Math.sin(r))*I(Math.sin(a))))),s}function wo(e,t){if(!t)return null;const{corners:n,fans:o,spaces:r}=Ya(e);if(t.type==="INT16_2D"&&t.domain==="CORNER"){const a=new Array(n.length);for(const[s,f]of o.entries()){const u=f.reduce((l,i)=>{const c=t.data[i];return[l[0]+c[0],l[1]+c[1]]},[0,0]),d=Za(r[s],u.map(l=>Math.trunc(l/f.length)));for(const l of f)a[l]=d}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(e){const t=new x;for(let n=0;n<e.length;n++){const o=e[n],r=e[(n+1)%e.length];t.x+=(o.y-r.y)*(o.z+r.z),t.y+=(o.z-r.z)*(o.x+r.x),t.z+=(o.x-r.x)*(o.y+r.y)}return t.multiplyScalar(.5)}const Ja=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),ze=e=>Array.from({length:e-2},(t,n)=>[0,n+1,n+2]);function tr(e){let t=0;for(let n=0;n<e.length;n++){const o=e[n],r=e[(n+1)%e.length];t+=o.x*r.y-r.x*o.y}return t}function De(e,t,n){if(e.length!==t.length-2||!(Math.abs(n)>0))return!1;const o=Math.sign(n);let r=0;for(const[a,s,f]of e){const u=Ja(t[a],t[s],t[f]);if(u*o<0)return!1;r+=Math.abs(u)}return Math.abs(r-Math.abs(n))<=Qa*Math.abs(n)}function nr(e){const t=e.length;if(t<3)return{triangles:[],sound:!1,method:"fan"};if(t===3)return{triangles:[[0,1,2]],sound:!0,method:"fan"};const n=Ka(e),o=n.length();if(!(o>0)||!Number.isFinite(o))return{triangles:ze(t),sound:!1,method:"fan"};const r=n.clone().divideScalar(o),a=Math.abs(r.x)<.9?new x(1,0,0):new x(0,1,0),s=new x().crossVectors(a,r).normalize(),f=new x().crossVectors(r,s),u=e[0],d=e.map(_=>{const m=_.clone().sub(u);return new Gt(m.dot(s),m.dot(f))}),l=tr(d),i=ze(t);if(De(i,d,l))return{triangles:i,sound:!0,method:"fan"};let c=[];try{c=Go.triangulateShape(d,[]).map(_=>[_[0],_[1],_[2]])}catch{return{triangles:i,sound:!1,method:"fan"}}return De(c,d,l)?{triangles:c,sound:!0,method:"earcut"}:{triangles:c.length>0?c:i,sound:!1,method:c.length>0?"earcut":"fan"}}const er=new Set(["FLOAT","FLOAT2","FLOAT_VECTOR","FLOAT_COLOR","BYTE_COLOR"]);function Un(e){const t=e/255;return t<.04045?t<0?0:t*(1/12.92):((t+.055)*(1/1.055))**2.4}function Wn(e,t,n){switch(e){case"FLOAT":{const o=Number(t[n]);return[o,o,o,1]}case"FLOAT2":return[Number(t[n*2]),Number(t[n*2+1]),0,1];case"FLOAT_VECTOR":return[Number(t[n*3]),Number(t[n*3+1]),Number(t[n*3+2]),1];case"BYTE_COLOR":return[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 pe(e,t){return e.filter(n=>er.has(n.type)&&n.domain!=="EDGE"&&!n.name.startsWith(".")&&n.name!=="position"&&n.name!=="custom_normal"&&!(n.type==="FLOAT2"&&n.domain==="CORNER")).map(n=>{const o=t(n.data,n.type),r=[0,0,0,0];return{name:n.name,domain:n.domain,read:(a,s,f)=>n.domain==="POINT"?Wn(n.type,o,a):n.domain==="CORNER"?s===void 0?r:Wn(n.type,o,s):f===void 0?r:Wn(n.type,o,f)}})}function Oo(e){const t=e.vertexCount,n=e.starts.length-1,o=e.starts,r=e.cornerVerts,a=o[n];let s=t;for(let w=0;w<n;w++)s+=(o[w+1]-o[w]-2)*3;const f=new Uint32Array(a),u=new Uint8Array(a),d=new Uint8Array(t),l=new Uint32Array(a);let i=!1;for(let w=0;w<n;w++)if(e.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,m=new Set;for(const[w,V]of e.sharp)m.add(c(w,V));if(e.edges)for(const[w,V]of e.edges){if(w===V)throw new Error("Runtime mesh edge needs distinct vertices");_.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=o[w],D=o[w+1]-V,Y=e.smooth(w)?1:0;for(let Z=0;Z<D;Z++){const $=V+Z;d[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[$]&&!m.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=e.uv,g=new Float32Array(s*3),b=new Float32Array(s*2),y=new Uint32Array(s),S=(e.uvLayers??[]).map(w=>({...w,data:new Float32Array(s*2)})),A=(e.attributeLayers??[]).map(w=>({...w,data:new Float32Array(s*4)})),T=e.orco?new Float32Array(s*3):null,O=new Uint32Array(s),E=new Map,k=[],j=e.normals||e.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]=e.orco[w*3+P]*.5+.5;if(y[$]=w,e.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=e.cornerNormal?[e.cornerNormal[w*3],e.cornerNormal[w*3+1],e.cornerNormal[w*3+2]]:e.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=o[w],Y=o[w+1]-D,Z=[];for(let B=0;B<Y;B++)Z.push(e.co(r[D+B]));for(const B of nr(Z).triangles)for(const tt of B)O[K++]=lt(D+tt,w);const $=e.material(w),P=k.at(-1);P?.materialIndex===$?P.count+=K-V:k.push({start:V,count:K-V,materialIndex:$})}for(let w=0;w<t;w++)d[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(e){return`blenderA_${Array.from(new TextEncoder().encode(e),t=>t.toString(16).padStart(2,"0")).join("")}`}function En(e){const t=new gn;t.setAttribute("position",new dt(e.positions,3)),t.setAttribute("uv",new dt(e.uv??new Float32Array(e.positions.length/3*2),2)),t.setIndex(new dt(e.indices,1));const n=Object.create(null);for(const[o,r]of(e.uvLayers??[]).entries()){if(o>=8)throw new Error("A Blender mesh supports at most eight UV maps");n[r.name]=o+1,t.setAttribute(`uv${o+1}`,new dt(r.data,2))}t.userData.blenderUvChannels=n;for(const o of e.attributeLayers??[])t.setAttribute(kt(o.name),new dt(o.data,4));t.userData.blenderAttributes=(e.attributeLayers??[]).map(o=>o.name),e.orco&&(t.setAttribute("blenderOrco",new dt(e.orco,3)),t.userData.blenderOrcoFromDoor=!0);for(const o of e.groups)t.addGroup(o.start,o.count,o.materialIndex);return e.normals?t.setAttribute("normal",new dt(e.normals,3)):t.computeVertexNormals(),e.sourceVertex&&t.setAttribute("blenderVertex",new dt(e.sourceVertex,1)),t}function or(e,t){const n=e.cornerTri,o=e.cornerNormal,r=e.co.length/3,a=e.corner.length,s=e.faceStart.length-1,f=e.attributes.filter(P=>P.type==="FLOAT2"&&P.domain==="CORNER"),u=e.renderUv??e.activeUv??f[0]?.name,d=f.findIndex(P=>P.name===u);if(u&&d<0)throw new Error(`Runtime UV map ${u} is missing`);const l=pe(e.attributes,P=>P),i=3+f.length*2+l.length*4,c=new Float32Array(i),_=new Float32Array(i),m=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++]=o[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=e.faceStart[P];B<e.faceStart[P+1];B++){const tt=e.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 m)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(e.corner[Ln]!==tt)continue;T(Ln,v[Ln],tt,_);let Te=!0;for(let xn=0;xn<i;xn++)if(m[xn]!==h[xn]){Te=!1;break}if(Te){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=e.orco?new Float32Array(k*3):null,V=(P,B)=>{K[P]=B;for(let tt=0;tt<3;tt++)j[P*3+tt]=e.co[B*3+tt],w&&(w[P*3+tt]=e.orco[B*3+tt]*.5+.5)};for(let P=0;P<O;P++){const B=g[P],tt=e.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=e.faceStart[P],tt=e.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=e.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:d<0?null:J[d].data,uvLayers:J,attributeLayers:lt,orco:w,indices:Y,groups:Z,hash:t}}function Fe(e,t){if(e.cornerTri&&e.cornerNormal)return or(e,t);const n=e.co.length/3,o=e.attributes.filter(h=>h.type==="FLOAT2"&&h.domain==="CORNER"),r=e.renderUv??e.activeUv??o[0]?.name,a=o.find(h=>h.name===r);if(r&&!a)throw new Error(`Runtime UV map ${r} is missing`);const s=a?a.data:null,f=e.edge.length/2,u=new Array(f);for(let h=0;h<f;h++)u[h]=[e.edge[h*2],e.edge[h*2+1]];const d=[];for(let h=0;h<f;h++)e.edgeSharp[h]===1&&d.push(u[h]);const l=e.cornerNormal?void 0:e.attributes.find(h=>h.name==="custom_normal"),i=l?{v:Array.from({length:n},(h,v)=>[e.co[v*3],e.co[v*3+1],e.co[v*3+2]]),f:Array.from({length:e.faceStart.length-1},(h,v)=>Array.from(e.corner.subarray(e.faceStart[v],e.faceStart[v+1]))),s:Array.from(e.smooth,Boolean),edge_order:u,sharp:d,face_edges:Array.from({length:e.faceStart.length-1},(h,v)=>Array.from(e.cornerEdge.subarray(e.faceStart[v],e.faceStart[v+1]))),edge_sharp:Array.from(e.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,m={vertexCount:n,normals:i?wo(i,c):null,cornerNormal:e.cornerNormal,orco:e.orco,co:h=>_.set(e.co[h*3],e.co[h*3+1],e.co[h*3+2]).clone(),starts:e.faceStart,cornerVerts:e.corner,smooth:h=>e.smooth[h]===1,material:h=>e.material[h],edges:u,sharp:d,uv:s?h=>[s[h*2],s[h*2+1]]:null,uvLayers:o.map(h=>({name:h.name,read:v=>[Number(h.data[v*2]),Number(h.data[v*2+1])]})),attributeLayers:pe(e.attributes,h=>h)};return{...Oo(m),hash:t}}function ar(e){const t=e.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},o=new Uint32Array(e.f.length+1);e.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");o[c+1]=o[c]+i.length});const r=new Uint32Array(o[e.f.length]);e.f.forEach((i,c)=>i.forEach((_,m)=>{n(_),r[o[c]+m]=_}));for(const[i,c]of e.edge_order??e.e??[])n(i),n(c);const a={POINT:t.length,EDGE:(e.edge_order??e.e??[]).length,FACE:e.f.length,CORNER:r.length};for(const i of e.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=(e.attributes??[]).filter(i=>i.type==="FLOAT2"&&i.domain==="CORNER"),f=e.render_uv??e.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 d=u?.data,l={vertexCount:t.length,normals:wo(e,e.attributes?.find(i=>i.name==="custom_normal")),co:n,starts:o,cornerVerts:r,smooth:i=>!!e.s?.[i],material:i=>e.m?.[i]??0,edges:e.edge_order??e.e??null,sharp:e.sharp??[],uv:d?i=>d[i]:null,uvLayers:s.map(i=>({name:i.name,read:c=>i.data[c]})),attributeLayers:pe(e.attributes??[],i=>Array.from(i).flat())};return En(Oo(l))}const vn=1.5707963267948966,Ht=6.283185307179586,Ao=.3183098861837067,To=.0795774715459476,rr=.3,sr=To,ir=3/16*Ao,re=.8,Ce=re*re,qt=6371,So=100,se=qt+So,ke=64,$e=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],Le=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=e=>e*e,un=e=>e<0?0:e>1?1:e,Nt=(e,t,n)=>e+n*(t-e),pr=e=>Math.sqrt(Math.max(e,0)),Mo=e=>[-Math.sqrt(1-e*e),0,e];function ie(e,t,n,o,r,a,s){const f=e*o+t*r+n*a,u=e*e+t*t+n*n-s*s;if(u>0&&f>0)return-1;const d=f*f-u;return d<0?-1:d>=f*f?-f+Math.sqrt(d):-f-Math.sqrt(d)}const vr=e=>ir*(1+Dn(e));function gr(e){const t=1+Ce+2*re*e;return To*(1-Ce)/(t*Math.sqrt(t))}const xr=e=>Le*(Math.exp(-e/hr)+dr/Le);function ve(e,t){let n=e%Ht;Math.abs(n)>=Math.PI&&(n-=Math.sign(n)*2*Math.PI);let o=t;return(n>=vn||n<=-vn)&&(n=Math.sign(n)*Math.PI-n,o+=Math.PI),o=o%Ht,o<0&&(o+=Ht),o=Ht-o,[n,o]}class br{constructor(t,n,o){this.air=t,this.aerosol=n,this.ozone=o,this.lut=new Float32Array(Vt*ft*4)}coefficients(t,n){const o=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]*o,n[4+f]=mr[f]*o,n[8+f]=cr[f]*ur*a*this.ozone,n[12+f]=fr[f]*s*this.air}transmittance(t,n,o){const[r,a,s]=Mo(t),f=Nt(qt,se,n),d=ie(0,0,f,r,a,s,se)/ke,l=[0,0,0,0],i=new Float64Array(16);for(let c=0;c<ke;c++){const _=(c+.5)*d,m=r*_,h=a*_,v=f+s*_,p=Math.max(Math.hypot(m,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])*d}for(let c=0;c<4;c++)o[c]=Math.exp(-l[c])}precompute(){const t=new Float64Array(4);for(let n=0;n<Vt;n++)for(let o=0;o<ft;o++){const r=o/(ft-1),a=n/(Vt-1);this.transmittance(r*2-1,a,t);const s=(n*ft+o)*4;for(let f=0;f<4;f++)this.lut[s+f]=t[f]}}lookup(t,n,o){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),d=Math.min(f+1,Vt-1),l=r-s,i=a-f,c=(f*ft+s)*4,_=(f*ft+u)*4,m=(d*ft+s)*4,h=(d*ft+u)*4;for(let v=0;v<4;v++)o[v]=Nt(Nt(this.lut[c+v],this.lut[_+v],l),Nt(this.lut[m+v],this.lut[h+v],l),i)}lookupAtGround(t,n){const o=(ft-1)*un(t*.5+.5),r=Math.trunc(o),a=Math.min(r+1,ft-1),s=o-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 o=(Vt-1)*un(t),r=Math.trunc(o),a=Math.min(r+1,Vt-1),s=o-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,o,r,a,s,f,u,d){const l=-(a*t[0]+s*t[1]+f*t[2]),i=vr(l),c=gr(l),_=u/$e,m=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<$e;A++){const T=(A+.5)*_,O=n+a*T,E=o+s*T,k=r+f*T,j=Math.hypot(O,E,k),G=Math.max(j-qt,0),K=G/So,J=(O*t[0]+E*t[1]+k*t[2])/j;this.coefficients(G,m),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*Ao)*p[D]*Y*J;v[D]=.02*V[D]*w+Z}for(let D=0;D<4;D++){const Y=m[D]+m[4+D]+m[8+D]+m[12+D],Z=lr[D]*(m[12+D]*(i*h[D]+v[D])+m[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++)d[A]=y[A]}}const ht=512,Jt=256;function Po(e,t){const n=new br(e.airDensity,e.aerosolDensity,e.ozoneDensity);n.precompute();const o=Math.min(Math.max(e.altitude,1),99999)/1e3,r=Mo(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 d=0;d<s;d++){const l=(d+.5)/ht,i=(u+.5)/Jt,c=Ht*l,_=i*2-1,m=Math.sign(_)*Dn(_)*vn,h=Math.cos(m)*Math.cos(c),v=Math.cos(m)*Math.sin(c),p=Math.sin(m),g=qt+o,b=ie(0,0,g,h,v,p,se),y=ie(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+d)*3;a[E]=A,a[E+1]=T,a[E+2]=O;const k=(u*ht+(ht-d-1))*3;a[k]=A,a[k+1]=T,a[k+2]=O}return a}function yr(e){const[t]=ve(e.sunElevation,e.sunRotation);return Po(e,t)}function ge(e){const[t]=ve(e.sunElevation,e.sunRotation);return JSON.stringify([t,e.altitude,e.airDensity,e.aerosolDensity,e.ozoneDensity])}const wr=6,Qt=new Map;function Or(e){return Qt.has(ge(e))}function Eo(e,t){Qt.set(ge(e),t),Qt.size>wr&&Qt.delete(Qt.keys().next().value)}function Ar(e){const[t,n]=ve(e.sunElevation,e.sunRotation),o=ge(e);let r=Qt.get(o);r===void 0&&(r=Po(e,t),Eo(e,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,m=c*Jt-.5,h=Math.floor(_),v=Math.floor(m),p=_-h,g=m-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=e=>{const{id:t,pixels:n,error:o}=e.data,r=_n.get(t);r&&(_n.delete(t),n?r.resolve(n):r.reject(new Error(o??"sky worker returned nothing")))},zt.onerror=e=>{const t=new Error(`sky worker failed: ${e.message||"unknown error"}`);for(const n of _n.values())n.reject(t);_n.clear(),zt?.terminate(),zt=null,bn=!0},zt}function Mr(e){const t=Sr();if(!t)return Promise.resolve(yr(e));const n=Tr++,o={id:n,parameters:e};return new Promise((r,a)=>{_n.set(n,{resolve:r,reject:a}),t.postMessage(o)})}function Pr(e,t,n,o={}){switch(o.type??"LINEAR"){case"QUADRATIC":{const r=Math.max(e,0);return r*r}case"EASING":{const r=Math.min(1,Math.max(0,e));return r*r*(3-2*r)}case"DIAGONAL":return(e+t)/2;case"SPHERICAL":return Math.max(.999999-Math.hypot(e,t,n),0);case"QUADRATIC_SPHERE":{const r=Math.max(.999999-Math.hypot(e,t,n),0);return r*r}case"RADIAL":return Math.atan2(t,e)/(2*Math.PI)+.5;default:return e}}const qn=(e,t)=>t!==0?e/t:0,Ve=e=>Math.min(1,Math.max(-1,e)),je=(e,t,n)=>{const o=n!==0?Math.max(n-Math.abs(e-t),0)/n:0;return Math.min(e,t)-o*o*o*n/6},No={ADD:(e,t)=>e+t,SUBTRACT:(e,t)=>e-t,MULTIPLY:(e,t)=>e*t,DIVIDE:qn,POWER:(e,t)=>t===0?1:e===0||e<0&&!Number.isInteger(t)?0:e**t,LOGARITHM:(e,t)=>e<=0||t<=0?0:qn(Math.log(e),Math.log(t)),SQRT:e=>Math.sqrt(Math.max(e,0)),INVERSE_SQRT:e=>e>0?1/Math.sqrt(e):0,ABSOLUTE:Math.abs,RADIANS:e=>e*Math.PI/180,DEGREES:e=>e*180/Math.PI,MINIMUM:(e,t)=>Math.min(e,t),MAXIMUM:(e,t)=>Math.max(e,t),LESS_THAN:(e,t)=>+(e<t),GREATER_THAN:(e,t)=>+(e>t),ROUND:e=>Math.floor(e+.5),FLOOR:Math.floor,CEIL:Math.ceil,FRACT:e=>e-Math.floor(e),MODULO:(e,t)=>t!==0?e%t:0,FLOORED_MODULO:(e,t)=>t!==0?e-Math.floor(e/t)*t:0,TRUNC:Math.trunc,SNAP:(e,t)=>Math.floor(qn(e,t))*t,WRAP:(e,t,n)=>t!==n?e-(t-n)*Math.floor((e-n)/(t-n)):n,PINGPONG:(e,t)=>{if(t===0)return 0;const n=(e-t)/(t*2);return Math.abs((n-Math.floor(n))*t*2-t)},SINE:Math.sin,COSINE:Math.cos,TANGENT:Math.tan,SINH:Math.sinh,COSH:Math.cosh,TANH:Math.tanh,ARCSINE:e=>Math.asin(Ve(e)),ARCCOSINE:e=>Math.acos(Ve(e)),ARCTANGENT:Math.atan,ARCTAN2:(e,t)=>e===0&&t===0?0:Math.atan2(e,t),SIGN:Math.sign,EXPONENT:Math.exp,COMPARE:(e,t,n)=>+(e===t||Math.abs(e-t)<=Math.max(n,2**-23)),MULTIPLY_ADD:(e,t,n)=>e*t+n,SMOOTH_MIN:je,SMOOTH_MAX:(e,t,n)=>-je(-e,-t,n)};function at(e,t){if(typeof e=="number")return()=>e;if(Array.isArray(e)){const r=new x(...e);return()=>r}if(e.kind==="direction")return r=>r;if(e.kind==="window"){if(!t)throw new Error("World Window coordinates need a render camera");return t}if(e.kind==="gradient"){const r=at(e.vector,t),a={type:e.gradient_type},s=new x;return f=>{const u=r(f),d=typeof u=="number"?u:u.x,l=typeof u=="number"?u:u.y,i=typeof u=="number"?u:u.z,c=xt.clamp(Pr(d,l,i,a),0,1);return e.output==="Fac"?c:s.setScalar(c)}}if(e.kind==="to_float"){const r=at(e.value,t);return a=>{const s=r(a);return typeof s=="number"?s:Math.fround(e.source_type==="RGBA"?s.x*.212639+s.y*.7151687+s.z*.0721923:(s.x+s.y+s.z)/3)}}if(e.kind==="math"){const r=e.inputs.map(f=>at(f,t)),a=No[e.operation],s=(f,u)=>{const d=r[f]?.(u)??0;if(typeof d!="number")throw new Error("World Math needs scalar inputs");return Math.fround(d)};return f=>{const u=Math.fround(a(s(0,f),s(1,f),s(2,f)));return e.clamp?xt.clamp(u,0,1):u}}if(e.kind==="mix_color"){const r=at(e.factor,t),a=at(e.a,t),s=at(e.b,t),f=new x,u=new x;return d=>{const l=r(d);if(typeof l!="number")throw new Error("World color Mix needs a scalar factor");const i=a(d);typeof i=="number"?f.setScalar(i):f.copy(i);const c=s(d);return typeof c=="number"?u.setScalar(c):u.copy(c),f.lerp(u,e.clamp_factor?xt.clamp(l,0,1):l),e.clamp_result&&f.clampScalar(0,1),f}}if(e.kind==="sky"){const r=Ar({sunElevation:e.sun_elevation,sunRotation:e.sun_rotation,altitude:e.altitude,airDensity:e.air_density,aerosolDensity:e.aerosol_density,ozoneDensity:e.ozone_density});return a=>r(a)}if(e.kind==="mapping"){const r=at(e.vector,t),a=new x(...e.location),s=new x(...e.scale),f=new At().setFromEuler(new Xo(e.rotation[0],e.rotation[1],e.rotation[2],"ZYX")),u=f.clone().invert(),d=new x(...e.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),e.vector_type??"POINT"){case"TEXTURE":return l.sub(a).applyQuaternion(u).multiply(d);case"VECTOR":return l.multiply(s).applyQuaternion(f);case"NORMAL":return l.multiply(d).applyQuaternion(f).normalize();case"POINT":return l.multiply(s).applyQuaternion(f).add(a)}}}if(e.kind==="map_range"){const r=at(e.value,t),a=at(e.from_min,t),s=at(e.from_max,t),f=at(e.to_min,t),u=at(e.to_max,t),d=at(e.steps,t),l=(_,m)=>{const h=_(m);if(typeof h!="number")throw new Error("World Map Range needs scalar inputs");return h},i=e.interpolation,c=e.clamp;return _=>{const m=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(d,_),A=(m-h)/(v-h);b=S>0?Math.floor(A*(S+1))/S:0}else if(i==="SMOOTHSTEP"||i==="SMOOTHERSTEP"){const S=xt.clamp((m-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=(m-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(e.kind==="separate"){const r=at(e.vector,t);return a=>{const s=r(a);return typeof s=="number"?s:s.getComponent(e.axis)}}const n=at(e.factor,t),o=new x;return r=>{const a=n(r);if(typeof a!="number")throw new Error("World ColorRamp needs a scalar factor");const s=xt.clamp(a,0,1)*256,f=Math.floor(s),u=e.colors[f],d=e.colors[Math.min(f+1,256)],l=e.interpolate?s-f:0;return o.set(xt.lerp(u[0],d[0],l),xt.lerp(u[1],d[1],l),xt.lerp(u[2],d[2],l))}}function Er(e,t,n,o){const r=new Float32Array(t*n*3),a=at(e,o),s=new x;for(let f=0;f<n;f++){const u=((f+.5)/n-.5)*Math.PI;for(let d=0;d<t;d++){const l=((d+.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+d)*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 Be(e){const t=[],n=o=>{if(!(typeof o=="number"||Array.isArray(o)))switch(o.kind){case"sky":t.push({sunElevation:o.sun_elevation,sunRotation:o.sun_rotation,altitude:o.altitude,airDensity:o.air_density,aerosolDensity:o.aerosol_density,ozoneDensity:o.ozone_density});return;case"mapping":case"gradient":case"separate":n(o.vector);return;case"ramp":n(o.factor);return;case"mix_color":n(o.factor),n(o.a),n(o.b);return;case"math":o.inputs.forEach(n);return;case"to_float":n(o.value);return;case"map_range":n(o.value),n(o.from_min),n(o.from_max),n(o.to_min),n(o.to_max),n(o.steps);return;default:return}};return n(e),t}function Ft(e){if(typeof e=="number"||Array.isArray(e))return!1;switch(e.kind){case"window":return!0;case"mapping":case"gradient":case"separate":return Ft(e.vector);case"ramp":return Ft(e.factor);case"mix_color":return[e.factor,e.a,e.b].some(Ft);case"math":return e.inputs.some(Ft);case"to_float":return Ft(e.value);case"map_range":return[e.value,e.from_min,e.from_max,e.to_min,e.to_max,e.steps].some(Ft);default:return!1}}function Nr(e,t,n,o){o.updateMatrixWorld();const r=new Float32Array(t*n*3),a=new x,s=at(e,()=>a),f=new x,u=o.getWorldPosition(new x),d=o.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),o.isOrthographicCamera?f.copy(d):f.set(c*2-1,_*2-1,.5).unproject(o).sub(u).normalize(),f.set(f.x,-f.z,f.y);const m=s(f),h=(l*t+i)*3;r[h]=typeof m=="number"?m:m.x,r[h+1]=typeof m=="number"?m:m.y,r[h+2]=typeof m=="number"?m:m.z}return r}const ot=N().finite(),Rr=M({type:q(["POINT","SUN","SPOT","AREA"]),color:L([ot,ot,ot]),energy:ot,use_shadow:Q().default(!0),radius:ot.optional(),spot_size:ot.optional(),spot_blend:ot.optional(),shape:q(["SQUARE","RECTANGLE","DISK","ELLIPSE"]).optional(),size:ot.optional(),size_y:ot.optional()}).strict();let le;function Ir(){return le??=Pa(async()=>{const{RectAreaLightUniformsLib:e}=await import("./RectAreaLightUniformsLib-DpPyArRG.js");return{RectAreaLightUniformsLib:e}},__vite__mapDeps([0,1,2])).then(({RectAreaLightUniformsLib:e})=>{e.init(),wt()}),le}function zr(){return le??Promise.resolve()}const Dr=e=>{const t=e.size??0,n=e.size_y??t;if(e.shape==="RECTANGLE")return[t,n];if(e.shape==="DISK"){const o=Math.sqrt(Math.PI*t*t/4);return[o,o]}if(e.shape==="ELLIPSE"){const o=Math.sqrt(Math.PI/4);return[t*o,n*o]}return[t,t]};function Fr(e,t){const n=(s,f)=>t&&f(t)?t:new s;if(e.type==="SUN"){const s=n(co,f=>f.isDirectionalLight);return s.intensity=e.energy,s.color.setRGB(e.color[0],e.color[1],e.color[2],vt),s.castShadow=e.use_shadow,s}if(e.type==="POINT"){const s=n(Jn,f=>f.isPointLight);return s.intensity=e.energy/(4*Math.PI),s.distance=0,s.decay=2,s.color.setRGB(e.color[0],e.color[1],e.color[2],vt),s.castShadow=e.use_shadow,s}if(e.type==="SPOT"){const s=n(te,f=>f.isSpotLight);return s.intensity=e.energy/(4*Math.PI),s.distance=0,s.decay=2,s.angle=(e.spot_size??0)/2,s.penumbra=e.spot_blend??0,s.color.setRGB(e.color[0],e.color[1],e.color[2],vt),s.castShadow=e.use_shadow,s}Ir();const o=n(Pn,s=>s.isRectAreaLight),[r,a]=Dr(e);return o.width=r,o.height=a,o.intensity=e.energy/(Math.max(r*a,Number.MIN_VALUE)*Math.PI),o.color.setRGB(e.color[0],e.color[1],e.color[2],vt),o}function Cr(e,t,n){if(!e.castShadow||n<=0)return;const r=e.getWorldPosition(new x).distanceTo(t),a=e.shadow;if(!a)return;const s=a.camera;s.near=Math.max(n*.001,r-n),s.far=r+n,e.isDirectionalLight&&(s.left=-n,s.right=n,s.top=n,s.bottom=-n),s.updateProjectionMatrix()}function kr(e,t){e.position.set(0,0,0);const n=e;e.isRectAreaLight||n.target&&n.target.parent!==t&&(n.target.position.set(0,0,-1),t.add(n.target))}const xe=[{direction:[-.352546,.170931,-.920051],diffuse:[.033103,.033103,.033103],specular:[.266761,.266761,.266761],smooth:.52662},{direction:[-.408163,.346939,.844415],diffuse:[.521083,.538226,.538226],specular:[.59903,.59903,.59903],smooth:0},{direction:[.521739,.826087,.212999],diffuse:[.038403,.034357,.04953],specular:[.106102,.125981,.158523],smooth:.478261},{direction:[.624519,-.562067,-.542269],diffuse:[.090838,.08208,.072255],specular:[.106535,.084771,.06608],smooth:.2}],Ue=.69;class $r{constructor(){this.group=new st,this.lights=[],this.group.name="BlenderSolidStudio";const t=new fo;t.name="BlenderSolidStudioTarget",this.group.add(t);const n=new Ot(0,0,0);for(const[r,a]of xe.entries()){const s=(1+a.smooth)**2,f=new co(16777215,Math.PI*Ue/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 o=new Yo(16777215,Math.PI*Ue);o.name="BlenderSolidWrapFill",o.color.copy(n),this.group.add(o),this.lights.push(o)}setRendered(t){this.group.visible=!t}dispose(){for(const t of this.lights)t.dispose();this.group.clear()}}const Zt=L([ot,ot,ot]),X=bo(()=>Lt([ot,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(No)),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:ot,sun_rotation:ot,altitude:ot,air_density:ot,aerosol_density:ot,ozone_density:ot}).strict()])),We=M({color:Zt,strength:ot,shader:X.optional()}),Lr=We.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:We.strict().optional()}).strict(),Vr=4,ln=new Map,Gn=new Set;function He(e,t,n){const a=Ft(e);if(a&&!n)throw new Error("World Window coordinates need a render camera");n?.updateMatrixWorld();const s=JSON.stringify([e,a?[n.matrixWorld.elements,n.projectionMatrix.elements]:null]),f=ln.get(s);if(f!==void 0)return fe(f,t,256,128);const u=new x,d=new Cn,l=n?new H().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse):null,i=n?.getWorldPosition(new x),_=Er(e,256,128,a?m=>(u.set(m.x,m.z,-m.y),n.isPerspectiveCamera&&u.add(i),d.set(u.x,u.y,u.z,1).applyMatrix4(l),d.w===0?u.set(0,0,0):u.set(d.x/d.w*.5+.5,d.y/d.w*.5+.5,0)):void 0);return ln.set(s,_),ln.size>Vr&&ln.delete(ln.keys().next().value),fe(_,t,256,128)}function jr(e,t,n,o){const r=cn.toHalfFloat(1);for(let a=0;a<o;a++)e[a*4]=cn.toHalfFloat(t[a*3]*n),e[a*4+1]=cn.toHalfFloat(t[a*3+1]*n),e[a*4+2]=cn.toHalfFloat(t[a*3+2]*n),e[a*4+3]=r}function fe(e,t,n,o){const r=new Uint16Array(n*o*4);jr(r,e,t,n*o);const a=new kn(r,n,o,$n,de);return a.mapping=Qo,a.colorSpace=vt,a.minFilter=Xt,a.magFilter=Xt,a.needsUpdate=!0,a}class be{constructor(){this.pending=null,this.texture=null,this.environmentTexture=null,this.screenTexture=null,this.applied=null,this.generation=0}async ready(){await this.pending}static sceneOf(t){let n=t;for(;n;){if(n.isScene)return n;n=n.parent}return null}apply(t,n,o){if(this.clear(),this.pending=null,!n)return;const r=be.sceneOf(t);if(!r)return;this.applied={scene:r,background:r.background,environment:r.environment};const a=n.shader??n.color,s=this.generation,u=[...Be(a),...n.lighting?Be(n.lighting.shader??n.lighting.color):[]].filter(l=>!Or(l));if(u.length===0){this.compose(r,n,a,o);return}const d=(async()=>{const l=await Promise.all(u.map(Mr));u.forEach((i,c)=>{Eo(i,l[c])}),!(this.generation!==s||this.applied?.scene!==r)&&(this.compose(r,n,a,o),wt())})();this.pending=d,Gn.add(d),d.then(()=>Gn.delete(d),()=>Gn.delete(d))}compose(t,n,o,r){if(this.texture=He(o,n.strength,r),Ft(o)){if(!r)throw new Error("World Window coordinates need a render camera");this.screenTexture=fe(Nr(o,512,512,r),n.strength,512,512),this.screenTexture.mapping=Zo,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?He(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 Ro(e){return[e.min.x,e.max.x].flatMap(t=>[e.min.y,e.max.y].flatMap(n=>[e.min.z,e.max.z].map(o=>new x(t,n,o))))}function Br(e,t){if(e.isEmpty()||!t.intersectsBox(e))return[];const n=Ro(e);if(n.every(l=>t.containsPoint(l)))return n;const o=[...t.planes,new Bt(new x(1,0,0),-e.min.x),new Bt(new x(-1,0,0),e.max.x),new Bt(new x(0,1,0),-e.min.y),new Bt(new x(0,-1,0),e.max.y),new Bt(new x(0,0,1),-e.min.z),new Bt(new x(0,0,-1),e.max.z)],r=[],a=new x,s=new x,f=new x,u=new x,d=Math.max(1,e.min.length(),e.max.length())*1e-8;for(let l=0;l<o.length;l++)for(let i=l+1;i<o.length;i++)for(let c=i+1;c<o.length;c++){const _=o[l],m=o[i],h=o[c];a.crossVectors(m.normal,h.normal);const v=_.normal.dot(a);Math.abs(v)<1e-12||(s.crossVectors(h.normal,_.normal),f.crossVectors(_.normal,m.normal),u.copy(a).multiplyScalar(-_.constant).addScaledVector(s,-m.constant).addScaledVector(f,-h.constant).divideScalar(v),o.every(p=>p.distanceToPoint(u)>=-d)&&r.push(u.clone()))}return r}function Ur(e,t,n){if(!e.castShadow||!t.length)return;e.shadow.updateMatrices(e);const o=e.shadow.camera,r=o.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,d=Math.max(s.x,s.y,f)/Math.max(1,Math.min(e.shadow.mapSize.x,e.shadow.mapSize.y)-2*u),l=2*Math.SQRT2*d,i=u*d;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(Ro(c).map(m=>m.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))}o.left=a.min.x,o.right=a.max.x,o.bottom=a.min.y,o.top=a.max.y,o.near=-a.max.z-l-f,o.far=-a.min.z+l+f,o.updateProjectionMatrix(),e.shadow.normalBias=l}const tn=N().finite(),qe=L([tn,tn,tn]),Io=M({min:L([N().int(),N().int(),N().int()]),max:L([N().int(),N().int(),N().int()]),density:F(tn),voxelSize:tn.positive(),color:qe,emission:qe,densityScale:tn.nonnegative()}).strict();function Wr(e){const t=e.max.map((l,i)=>l-e.min[i]+1);if(t.some(l=>l<=0)||t.reduce((l,i)=>l*i,1)!==e.density.length)throw new Error("Volume density dimensions do not match the evaluated grid");const n=new Ko(new Float32Array(e.density),t[0],t[1],t[2]);n.format=Jo,n.type=uo,n.minFilter=n.magFilter=Xt,n.unpackAlignment=1,n.needsUpdate=!0;const o=new x(...e.min).addScalar(-.5).multiplyScalar(e.voxelSize),r=new x(t[0],t[1],t[2]).multiplyScalar(e.voxelSize),a=new ta(r.x,r.y,r.z),s=a.getAttribute("position");for(let l=0;l<s.count;l++)s.setXYZ(l,o.x+(s.getX(l)>0?r.x:0),o.y+(s.getY(l)>0?r.y:0),o.z+(s.getZ(l)>0?r.z:0));s.needsUpdate=!0,a.computeBoundingBox(),a.computeBoundingSphere();const f=new me({glslVersion:ea,side:na,transparent:!0,depthWrite:!1,premultipliedAlpha:!0,uniforms:{densityGrid:{value:n},minimum:{value:o},extent:{value:r},voxelSize:{value:e.voxelSize},densityScale:{value:e.densityScale},volumeColor:{value:new x(...e.color)},emission:{value:new x(...e.emission)},cameraLocal:{value:new x},rayLocal:{value:new x},orthographic:{value:!1},worldScale:{value:new lo}},vertexShader:`
20
20
  out vec3 localPosition;
21
21
  void main() {
22
22
  localPosition = position;
@@ -58,7 +58,7 @@ import{a as se,b as ie,L as le}from"./LineSegments2-DN9pUfWA.js";import{bh as st
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 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
61
+ }`}),u=new Rt(a,f),d=new H;return u.onBeforeRender=(l,i,c)=>{d.copy(u.matrixWorld).invert(),f.uniforms.cameraLocal.value.setFromMatrixPosition(c.matrixWorld).applyMatrix4(d),c.getWorldDirection(f.uniforms.rayLocal.value).transformDirection(d),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
@@ -200,7 +200,7 @@ mat3x3 to_float3x3(mat3x4 m) { return mat3x3(m); }
200
200
  #define float4_from_float(v) float4(float3(v), 1.0f)
201
201
  #define gpu_dfdx(x) dFdx(x)
202
202
  #define gpu_dfdy(x) dFdy(x)
203
- #define gpu_fwidth(x) fwidth(x)`,co={"gpu_shader_common_math.glsl":{deps:["gpu_shader_math_constants_lib.glsl","gpu_shader_math_base_lib.glsl","gpu_shader_math_safe_lib.glsl"],code:`void math_add(float a, float b, float c, _ref(float ,result))
203
+ #define gpu_fwidth(x) fwidth(x)`,ce={"gpu_shader_common_math.glsl":{deps:["gpu_shader_math_constants_lib.glsl","gpu_shader_math_base_lib.glsl","gpu_shader_math_safe_lib.glsl"],code:`void math_add(float a, float b, float c, _ref(float ,result))
204
204
  {
205
205
  result = a + b;
206
206
  }
@@ -6879,7 +6879,7 @@ void curves_float_mixed(float factor,
6879
6879
  curves_float(
6880
6880
  value, curve_map, layer, range_minimum, range_divider, start_slope, end_slope, result);
6881
6881
  result = mix(value, result, factor);
6882
- }`}},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=`
6882
+ }`}},Ge=N().finite(),Xn=q(["float","vec2","vec3","vec4"]),zo=Lt([Ge,F(Ge)]),Do=L([R(),N().int().nonnegative()]),Nn=Lt([M({value:zo}).strict(),M({link:Do}).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(),yo()),inputs:F(Lt([M({value:zo,id:R(),gpu:Xn,enabled:Q()}).strict(),M({link:Do,id:R(),gpu:Xn,enabled:Q()}).strict()])),outputs:F(M({id:R(),gpu:Xn.or(W("closure")).nullable()}).strict())}).strict(),mn=bo(()=>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(e){const t=e.inputs.Alpha,n=o=>"transparent"in o||"mix"in o&&(n(o.mix[1])||n(o.mix[2]))||"add"in o&&(n(o.add[0])||n(o.add[1]));return t!==void 0&&"link"in t||e.closure!==void 0&&n(e.closure)}const Fo="vec3(0.2126729, 0.7151522, 0.0721750)",Zr=e=>e==="float"?1:Number(e[3]);function Qr(e,t){const n=typeof t=="number"?[t]:t,o=Zr(e);return Array.from({length:o},(r,a)=>n[a]??(a===3?1:0))}function Kr(e,t,n){if(t===n)return e;const o=a=>a==="float"?"float":`float${a[3]}`,r=t==="vec4"&&n==="float"?`, ${Fo}`:"";return`${o(n)}_from_${o(t)}(${e}${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"},Xe={MIX:"blend",ADD:"add",MULTIPLY:"mult",SUBTRACT:"sub",SCREEN:"screen",DIVIDE:"div_fallback",DIFFERENCE:"diff",EXCLUSION:"exclusion",DARKEN:"dark",LIGHTEN:"light",OVERLAY:"overlay",DODGE:"dodge",BURN:"burn",HUE:"hue",SATURATION:"sat",VALUE:"val",COLOR:"color",SOFT_LIGHT:"soft",LINEAR_LIGHT:"linear"},ns={MULTIFRACTAL:"multi_fractal",FBM:"fbm",HYBRID_MULTIFRACTAL:"hybrid_multi_fractal",RIDGED_MULTIFRACTAL:"ridged_multi_fractal",HETERO_TERRAIN:"hetero_terrain"},es={F1:"f1",F2:"f2",SMOOTH_F1:"smooth_f1",DISTANCE_TO_EDGE:"distance_to_edge",N_SPHERE_RADIUS:"n_sphere_radius"},os={EUCLIDEAN:0,MANHATTAN:1,CHEBYCHEV:2,MINKOWSKI:3},as=(()=>{const e=new Map;for(const[t,n]of Object.entries(ce))for(const o of n.code.matchAll(/^(?:void|float\d?)\s+([A-Za-z_]\w*)\s*\(/gm))e.has(o[1])||e.set(o[1],t);return e})();function C(e,t){if(!(t in e.props))throw new Error(`${e.type} arrived without its '${t}' property`);return e.props[t]}const rs=`
6883
6883
  #define GPU_FRAGMENT_SHADER
6884
6884
  #define FrontFacing gl_FrontFacing
6885
6885
  #ifndef USE_TRANSMISSION
@@ -7019,31 +7019,31 @@ vec3 blender_reflection() {
7019
7019
  : normalize(cameraPosition - vBlenderWorldPosition);
7020
7020
  return blender_from_three * -reflect(incident, normalize(vBlenderWorldNormal));
7021
7021
  }
7022
- `;class 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}() {
7022
+ `;class ye{constructor(t,n,o=!1,r="bgN"){this.graph=t,this.derivative=o,this.prefix=r,this.lines=[],this.emitted=new Map,this.s=n??{files:new Set,uniforms:new Map,uniformTypes:new Map,images:[],ramps:[],uvs:new Set,attributes:new Set,structure:[],functions:[]}}get uniforms(){return this.s.uniforms}get images(){return this.s.images}get ramps(){return this.s.ramps}d(t){return this.derivative?`(${t} + dF_impl(${t}))`:t}uniform(t,n){const o=`bgU${this.s.uniforms.size}`,r=Qr(t,n);return this.s.uniforms.set(o,t==="float"?r[0]:r),this.s.uniformTypes.set(o,t),o}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[o,r]=t.link,a=this.graph.nodes[o];if(!a)throw new Error(`The graph links to ${o}, which it does not carry`);const f=this.node(o,a)[r];if(!f)throw new Error(`${o} has no output ${r}`);return this.s.structure.push(["l",o,r]),Kr(f.name,f.type,n)}input(t,n,o){const r=t.inputs.find(a=>a.id===n)??t.inputs.find(a=>a.id.replace(/_/g," ")===n);if(!r)throw new Error(`${t.type} arrived without its '${n}' input`);return this.source(r,o??r.gpu)}coordinate(t,n){const o=t.inputs[0];return"link"in o?this.source(o,"vec3"):(this.s.structure.push(["default",n]),n==="orco"?this.d("blender_orco()"):(this.s.uvs.add(""),this.d(`vec3(${Kt("")}, 0.0)`)))}node(t,n){const o=this.emitted.get(t);if(o)return o;const r=`${this.prefix}${this.emitted.size}`,a=n.outputs.map((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(", "),d=(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)}(${ue(i)}, ${u(a.map((_,m)=>m))});`);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}(${d()});`),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()}`)}(${d()});`);break}case"ShaderNodeMapping":l.push(`${this.use(`mapping_${C(n,"vector_type").toLowerCase()}`)}(${d()});`);break;case"ShaderNodeInvert":l.push(`${this.use("invert")}(${d()});`);break;case"ShaderNodeSeparateXYZ":l.push(`${this.use("separate_xyz")}(${d()});`);break;case"ShaderNodeCombineXYZ":l.push(`${this.use("combine_xyz")}(${d()});`);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 m=i==="VECTOR"&&c;let h=this.input(n,m?"Factor_Vector":"Factor_Float");if(C(n,"clamp_factor")){const g=`${r}_fac`;l.push(m?`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_${Xe[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_${Xe[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"),[_,m]=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"&&m&&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],m[0]))}, ${h(_)}, ${h(m)}, ${u([0,1])});`);else{const v=1/(m[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(m)}, ${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(m=>m.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"),m=n.inputs.slice(1).map(v=>this.source(v,v.gpu)),h=C(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[_,...m,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_${es[C(n,"feature")]}_${i}d`),_=this.coordinate(n,"orco"),m=n.inputs.slice(1).map(p=>this.source(p,p.gpu)),h=`${os[C(n,"distance")].toFixed(1)}`,v=C(n,"normalize")?"1.0":"0.0";l.push(`${c}(${[_,...m,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((_,m)=>m))].join(", ")});`);break}case"ShaderNodeTexWhiteNoise":{const i=Number(C(n,"noise_dimensions")[0]);l.push(`${this.use(`node_white_noise_${i}d`)}(${d()});`);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),m=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,...m,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}`)}(${d([_?"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")}(${d()});`);break;case"ShaderNodeHueSaturation":l.push(`${this.use("hue_sat")}(${d()});`);break;case"ShaderNodeBrightContrast":l.push(`${this.use("brightness_contrast")}(${d()});`);break;case"ShaderNodeGamma":l.push(`${this.use("node_gamma")}(${d()});`);break;case"ShaderNodeRGBToBW":l.push(`${this.use("rgbtobw")}(${d([Fo])});`);break;case"ShaderNodeSeparateColor":l.push(`${this.use(`separate_color_${C(n,"mode").toLowerCase()}`)}(${d()});`);break;case"ShaderNodeCombineColor":l.push(`${this.use(`combine_color_${C(n,"mode").toLowerCase()}`)}(${d()});`);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}`)}(${d([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"),m=n.type==="ShaderNodeFresnel"?"node_fresnel":"node_layer_weight";l.push(`${this.use(m)}(${[_,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 m=`bgHeight${this.s.functions.length}`;this.s.functions.push("");const h=new ye(this.graph,this.s,!0,`${m}_`),v=h.source(i,"float");this.s.functions[Number(m.slice(8))]=`float ${m}() {
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 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() {
7026
+ }`;const p=this.input(n,"Filter Width","float");l.push(`float ${r}_h = ${m}();`,`g_derivative_filter_width = ${p} * derivative_scale_get();`,`g_derivative_flag = 1; float ${r}_hx = ${m}();`,`g_derivative_flag = -1; float ${r}_hy = ${m}();`,"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"),m=`${r}_n`;if(l.push(`vec3 ${m}; ${this.use(i.startsWith("BLENDER_")?"color_to_blender_normal_new_shading":"color_to_normal_new_shading")}(${_}, ${m});`),n.props.convention==="DIRECTX"&&l.push(`${this.use("color_invert_green_channel")}(${m}, ${m});`),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}, ${m}, g_data.Ni, ${u([0])});`)}else(i==="OBJECT"||i==="BLENDER_OBJECT")&&l.push(`${this.use("normal_transform_object_to_world")}(${m}, ${m});`),l.push(`${this.use("node_normal_map_mix")}(${c}, ${m}, ${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"),m=_==="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,m,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(m?"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)m&&this.use("cubic_bspline_coefficients"),l.push(`${m?"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(m?"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 o=a=>"link"in a&&a.link[0]===t&&a.link[1]===n,r=a=>a!==void 0&&("emission"in a?a.emission.some(o):"mix"in a?o(a.mix[0])||r(a.mix[1])||r(a.mix[2]):"add"in a?r(a.add[0])||r(a.add[1]):!1);return Object.values(this.graph.inputs).some(o)||Object.values(this.graph.nodes).some(a=>a.inputs.some(o))||r(this.graph.closure)}compile(){const t=this.graph.surface==="ShaderNodeEmission"?{Color:"vec4",Strength:"float"}:{"Base Color":"vec4",Metallic:"float",Roughness:"float",Alpha:"float","Emission Color":"vec4","Emission Strength":"float",Normal:"vec3"},n={},o=[];let r=0;for(const[i,c]of Object.entries(t)){const _=this.graph.inputs[i];if(!_||i==="Normal"&&!("link"in _))continue;const m=`bgOut${r++}`;n[i]={global:m,type:c},this.s.structure.push(["out",i]),o.push(`${m} = ${this.source(_,c)};`)}const a=this.graph.closure;if(a){let i=0;const c=(_,m)=>{if("principled"in _)this.s.structure.push("cP"),o.push(`bgClosureP += ${m};`);else if("emission"in _)this.s.structure.push("cE"),o.push(`bgClosureE += ${m} * ${this.source(_.emission[0],"vec4")}.rgb * ${this.source(_.emission[1],"float")};`);else if("transparent"in _)this.s.structure.push("cT"),o.push(`bgClosureT += ${m} * ${this.source({value:_.transparent},"float")};`);else if("mix"in _){this.s.structure.push("cM");const h=`bgClosureF${i++}`;o.push(`float ${h} = clamp(${this.source(_.mix[0],"float")}, 0.0, 1.0);`),c(_.mix[1],`${m} * (1.0 - ${h})`),c(_.mix[2],`${m} * ${h}`)}else"add"in _?(this.s.structure.push("cA"),c(_.add[0],m),c(_.add[1],m)):this.s.structure.push("c0")};o.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 ce[i].deps)u(c);s.push(i)}};for(const i of this.s.files)u(i);const d=`void blenderGraph() {
7027
7027
  blender_init_globals();
7028
- ${[...this.lines,...e].join(`
7028
+ ${[...this.lines,...o].join(`
7029
7029
  `)}
7030
- }`,l=[Hr,is(rs+s.map(i=>co[i].code).join(`
7030
+ }`,l=[Hr,is(rs+s.map(i=>ce[i].code).join(`
7031
7031
  `)+`
7032
- `+ss,[...this.s.functions,m].join(`
7032
+ `+ss,[...this.s.functions,d].join(`
7033
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
- `,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)),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;
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,d].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(e,t){const n=[],o=/^[A-Za-z_][\w ]*?\b([A-Za-z_]\w*)\s*\(/gm;let r=0;for(let u;u=o.exec(e);){if(u.index<r)continue;let d=u.index+u[0].length;for(let _=1;d<e.length&&_>0;d++)_+=e[d]==="("?1:e[d]===")"?-1:0;const l=e.slice(d).match(/^\s*(\{|;)/);if(!l||/^\s*#/.test(e.slice(e.lastIndexOf(`
7036
+ `,u.index)+1,u.index+1))||e.slice(Math.max(0,u.index-2),u.index).endsWith(`\\
7037
+ `))continue;let c=d+l[0].length;if(l[1]==="{")for(let _=1;c<e.length&&_>0;c++)_+=e[c]==="{"?1:e[c]==="}"?-1:0;n.push({text:e.slice(r,u.index),name:null}),n.push({text:e.slice(u.index,c),name:u[1]}),r=c,o.lastIndex=c}n.push({text:e.slice(r),name:null});const a=new Set(n.filter(u=>u.name===null)),s=new Set,f=u=>{for(const d of u.matchAll(/[A-Za-z_]\w*/g))s.add(d[0])};f(t);for(const u of a)f(u.text);for(let u=!0;u;){u=!1;for(const d of n)a.has(d)||d.name===null||!s.has(d.name)||(a.add(d),f(d.text),u=!0)}return n.filter(u=>a.has(u)).map(u=>u.text).join("")}function ue(e){return`v${kt(e)}`}function Kt(e){return e===""?"vBlenderUvRender":`vBlenderUv_${[...e].map(t=>t.charCodeAt(0).toString(16)).join("")}`}function ls(e){return new ye(e).compile()}function fs(e){const t=new Uint16Array(e.length*4);e.forEach((o,r)=>t.set([o[0]??0,o[1]??0,o[2]??0,o[3]??1].map(a=>cn.toHalfFloat(a)),r*4));const n=new kn(t,e.length,1,$n,de);return n.minFilter=n.magFilter=Xt,n.wrapS=n.wrapT=_o,n.needsUpdate=!0,n}const pt=new WeakMap,Co=new Set,Ct=new WeakMap,yn=new WeakMap;function wn(e){const t=Ct.get(e);if(t){Ct.delete(e);for(const n of t.binding.ramps)n.dispose()}}function cs(e,t,n,o=!1){const r=pt.get(e);if(t&&Co.has(t.key)&&(t=null),!t){if(wn(e),r){for(const f of r.ramps)f.dispose();pt.delete(e),e.needsUpdate=!0}return}if(r&&r.compiled.key===t.key){wn(e),On(r,t,n);return}if(o){wn(e);for(const u of r?.ramps??[])u.dispose();const f={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};On(f,t,n),pt.set(e,f),e.needsUpdate=!0;return}const a=Ct.get(e);if(a&&a.binding.compiled.key===t.key){On(a.binding,t,n);return}wn(e);const s={compiled:t,uniforms:{},ramps:[],channels:r?.channels??{}};On(s,t,n),Ct.set(e,{binding:s,started:!1})}function On(e,t,n){e.compiled=t;for(const[o,r]of t.uniforms){const a=typeof r=="number"?r:r.length===2?new Gt(...r):r.length===3?new x(...r):new Cn(...r),s=e.uniforms[o];s?s.value=a:e.uniforms[o]={value:a}}for(const o of e.ramps)o.dispose();e.ramps=t.ramps.map(o=>{const r=fs(o.table);return(e.uniforms[o.uniform]??={value:null}).value=r,r});for(const o of t.images){const r=n(o);if(o.tiled){const a=r!==null&&"tiles"in r?r:null;(e.uniforms[o.uniform]??={value:null}).value=a?.tiles??null,(e.uniforms[`${o.uniform}Map`]??={value:null}).value=a?.map??null}else(e.uniforms[o.uniform]??={value:null}).value=r!==null&&"tiles"in r?null:r}}function us(e){const t=pt.get(e);return t?`${t.compiled.key}|${JSON.stringify(t.channels)}`:""}function _s(e){return Object.values(pt.get(e)?.channels??{})}function ko(e,t){const n=new Set(["position","normal","uv"]);if(t.hasAttribute("tangent")&&n.add("tangent"),e.vertexColors&&n.add("color"),!(e instanceof nn))return n;const o=t.userData.blenderUvChannels,r=a=>{const s=a===""?0:o?.[a]??9;n.add(s===0?"uv":`uv${s}`)};for(const a of[e.map,e.roughnessMap,e.normalMap])a&&r(a.userData.blenderUvName??"");for(const a of[pt.get(e),Ct.get(e)?.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 Ye(e,t){const n=t.userData.blenderUvChannels,o=t.getAttribute("position")?.count??0,r={};for(const a of e.uvs){let s=a===""?0:n?.[a];s===void 0&&(s=9,t.getAttribute("uv9")?.count!==o&&t.setAttribute("uv9",new dt(new Float32Array(o*2),2))),r[a]=s}return r}function ms(e,t,n,o,r,a,s){const f=yn.get(e);f&&++f.draws>1&&(f.shadow.dispose(),yn.delete(e));const u=Ct.get(e);if(u&&!u.started){u.started=!0,u.binding.channels=Ye(u.binding.compiled,t);const c=s(e);pt.set(c,u.binding);const _=new Rt(t,c);_.castShadow=a.castShadow,_.receiveShadow=a.receiveShadow;const m=()=>{if(Ct.get(e)!==u){c.dispose();return}Ct.delete(e);for(const h of pt.get(e)?.ramps??[])h.dispose();pt.set(e,u.binding),e.needsUpdate=!0,yn.get(e)?.shadow.dispose(),yn.set(e,{shadow:c,draws:0}),wt()};n.compileAsync(_,r,o).then(m,m)}const d=pt.get(e);if(!d)return;const l=n.properties.get(e).currentProgram;if(l?.diagnostics?.runnable===!1&&l.cacheKey?.includes(d.compiled.key)){Co.add(d.compiled.key),pt.delete(e),e.needsUpdate=!0;const c=l.diagnostics.fragmentShader.log.split(`
7038
+ `).find(_=>_.startsWith("ERROR"))??"";console.warn(`Blender material "${e.name}": its node graph did not compile for WebGL, so it is drawn with its constant values. ${c}`);return}const i=Ye(d.compiled,t);JSON.stringify(i)!==JSON.stringify(d.channels)&&(d.channels=i,e.needsUpdate=!0)}function ds(e){const t=Array.isArray(e.material)?e.material:[e.material];if(!t.some(u=>u instanceof nn&&pt.has(u)))return;const n=e.geometry,o=e.userData.blenderTexspace??null,r=n.getAttribute("position"),a=JSON.stringify([o,r?.version??0,r?.count??0]);!n.userData.blenderOrcoFromDoor&&n.userData.blenderOrcoStamp!==a&&(n.setAttribute("blenderOrco",hs(n,o)),n.userData.blenderOrcoStamp=a);const s=r?.count??0,f=e.userData.blenderDefaultColor;for(const u of t){const d=u instanceof nn?pt.get(u):void 0;for(const l of d?.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(e,t){const n=e.getAttribute("position");let o,r;if(t)o=[...t[0]],r=[...t[1]];else{e.computeBoundingBox();const s=e.boundingBox;o=[(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)-o[0])/r[0]*.5+.5,a[s*3+1]=(n.getY(s)-o[1])/r[1]*.5+.5,a[s*3+2]=(n.getZ(s)-o[2])/r[2]*.5+.5;return new dt(a,3)}function ps(e,t){const n=pt.get(e);if(!n)return;const{compiled:o,channels:r}=n;Object.assign(t.uniforms,n.uniforms,{blenderViewport:{value:$o}});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;
7042
7042
  varying vec3 vBlenderOrco;
7043
- ${e.attributes.map(p=>`varying vec4 ${uo(p)};`).join(`
7043
+ ${o.attributes.map(p=>`varying vec4 ${ue(p)};`).join(`
7044
7044
  `)}
7045
- ${e.uvs.map(p=>`varying vec2 ${Kt(p)};`).join(`
7046
- `)}`,f=e.attributes.map(p=>`attribute vec4 ${kt(p)};`).join(`
7045
+ ${o.uvs.map(p=>`varying vec2 ${Kt(p)};`).join(`
7046
+ `)}`,f=o.attributes.map(p=>`attribute vec4 ${kt(p)};`).join(`
7047
7047
  `);t.vertexShader=`attribute vec3 blenderOrco;
7048
7048
  ${f}
7049
7049
  ${s}
@@ -7056,11 +7056,11 @@ blenderWorldMatrix = modelMatrix * instanceMatrix;
7056
7056
  vBlenderWorldPosition = (blenderWorldMatrix * vec4(transformed, 1.0)).xyz;
7057
7057
  vBlenderWorldNormal = normalize(transpose(inverse(mat3(blenderWorldMatrix))) * objectNormal);
7058
7058
  vBlenderOrco = blenderOrco;
7059
- ${e.attributes.map(p=>`${uo(p)} = ${kt(p)};`).join(`
7059
+ ${o.attributes.map(p=>`${ue(p)} = ${kt(p)};`).join(`
7060
7060
  `)}
7061
- ${e.uvs.map(p=>`${Kt(p)} = ${a(r[p]??0)};`).join(`
7061
+ ${o.uvs.map(p=>`${Kt(p)} = ${a(r[p]??0)};`).join(`
7062
7062
  `)}
7063
- #include <project_vertex>`);const u=p=>e.outputs[p]?.global,m=[];e.surface==="ShaderNodeEmission"?(m.push(["#include <color_fragment>","diffuseColor = vec4(0.0, 0.0, 0.0, 1.0);",!1]),m.push(["#include <emissivemap_fragment>",`totalEmissiveRadiance = ${u("Color")}.rgb * ${u("Strength")};`,!1]),m.push(["#include <opaque_fragment>","outgoingLight = totalEmissiveRadiance;",!0])):e.surface==="closure"?(m.push(["#include <color_fragment>","diffuseColor = vec4(0.0, 0.0, 0.0, 1.0);",!1]),m.push(["#include <emissivemap_fragment>","totalEmissiveRadiance = vec3(0.0);",!1])):(m.push(["#include <color_fragment>",`diffuseColor.rgb = ${u("Base Color")}.rgb;`,!1]),m.push(["#include <alphamap_fragment>",`diffuseColor.a = ${u("Alpha")};`,!1]),m.push(["#include <metalnessmap_fragment>",`roughnessFactor = ${u("Roughness")};`,!0]),m.push(["#include <metalnessmap_fragment>",`metalnessFactor = ${u("Metallic")};`,!1]),m.push(["#include <emissivemap_fragment>",`totalEmissiveRadiance = ${u("Emission Color")}.rgb * ${u("Emission Strength")};`,!1]),u("Normal")&&m.push(["#include <clearcoat_normal_fragment_begin>",`normal = normalize((viewMatrix * vec4(transpose(blender_from_three) * ${u("Normal")}, 0.0)).xyz);`,!0])),e.closure&&m.push(["#include <opaque_fragment>",`{
7063
+ #include <project_vertex>`);const u=p=>o.outputs[p]?.global,d=[];o.surface==="ShaderNodeEmission"?(d.push(["#include <color_fragment>","diffuseColor = vec4(0.0, 0.0, 0.0, 1.0);",!1]),d.push(["#include <emissivemap_fragment>",`totalEmissiveRadiance = ${u("Color")}.rgb * ${u("Strength")};`,!1]),d.push(["#include <opaque_fragment>","outgoingLight = totalEmissiveRadiance;",!0])):o.surface==="closure"?(d.push(["#include <color_fragment>","diffuseColor = vec4(0.0, 0.0, 0.0, 1.0);",!1]),d.push(["#include <emissivemap_fragment>","totalEmissiveRadiance = vec3(0.0);",!1])):(d.push(["#include <color_fragment>",`diffuseColor.rgb = ${u("Base Color")}.rgb;`,!1]),d.push(["#include <alphamap_fragment>",`diffuseColor.a = ${u("Alpha")};`,!1]),d.push(["#include <metalnessmap_fragment>",`roughnessFactor = ${u("Roughness")};`,!0]),d.push(["#include <metalnessmap_fragment>",`metalnessFactor = ${u("Metallic")};`,!1]),d.push(["#include <emissivemap_fragment>",`totalEmissiveRadiance = ${u("Emission Color")}.rgb * ${u("Emission Strength")};`,!1]),u("Normal")&&d.push(["#include <clearcoat_normal_fragment_begin>",`normal = normalize((viewMatrix * vec4(transpose(blender_from_three) * ${u("Normal")}, 0.0)).xyz);`,!0])),o.closure&&d.push(["#include <opaque_fragment>",`{
7064
7064
  float blenderCoverage = diffuseColor.a;
7065
7065
  vec3 blenderRadiance = bgClosureP * blenderCoverage * outgoingLight + bgClosureE;
7066
7066
  float blenderAlpha = 1.0 - min(bgClosureT + bgClosureP * (1.0 - blenderCoverage), 1.0);
@@ -7070,15 +7070,15 @@ ${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]??"")),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(`
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()])),m=[...new Set([...o.declarations.matchAll(/^[ \t]*#define[ \t]+(\w+)/gm)].map(p=>p[1]))].filter(p=>c.has(p)),h=[...m.map(p=>`#undef ${p}`),o.declarations,...m.flatMap(p=>[`#undef ${p}`,c.get(p)])].join(`
7074
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
- 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}
7077
+ blenderGraph();`);for(const[p,g,b]of d){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 $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
- attribute vec2 uv${d};
7081
- #endif`:`attribute vec2 uv${d};`).join(`
7079
+ ${g}`)}t.fragmentShader=v}const $o=new Gt(1,1);function vs(e){e.getDrawingBufferSize($o)}function gs(e,t){const n=t.userData.blenderUvChannels;for(const o of[e.map,e.roughnessMap,e.normalMap]){if(!o)continue;const r=o.userData.blenderUvName;let a=r?n?.[r]:0;if(a===void 0){a=9;const 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))}o.channel!==a&&(o.channel=a,e.needsUpdate=!0)}}class xs{constructor(){this.bindings=new Map}get(t,n,o,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 d=s;r&&r.then(()=>{d.disposed||(d.texture.needsUpdate=!0,d.version=n.version,wt())},()=>{})}const f=o==="REPEAT"?oa:o==="MIRROR"?aa:_o,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},en=new WeakMap;function ws(e,t){en.has(e)||we(e),en.get(e).blenderWorldExtinction.value.copy(t)}function Os(e){const t=new nn,n=en.get(e);we(t),t.copy(e);const o=en.get(t);return n&&(o.blenderCoatIor.value=n.blenderCoatIor.value,o.blenderCoatTint.value.copy(n.blenderCoatTint.value),o.blenderMapClip.value=n.blenderMapClip.value,o.blenderRoughnessClip.value=n.blenderRoughnessClip.value,o.blenderNormalClip.value=n.blenderNormalClip.value,o.blenderWorldExtinction.value.copy(n.blenderWorldExtinction.value)),t}function we(e,t,n={}){const o=t??ys;e.clearcoat=o.coat,e.clearcoatRoughness=o.coat_roughness,e.sheen=o.sheen,e.sheenRoughness=o.sheen_roughness,e.sheenColor.setRGB(...o.sheen_tint,vt),e.anisotropy=o.anisotropy,e.anisotropyRotation=o.anisotropy_rotation*Math.PI*2,e.specularIntensity=o.specular_level*2,e.specularColor.setRGB(...o.specular_tint,vt),e.iridescence=o.film_thickness>0?1:0,e.iridescenceIOR=o.film_ior,e.iridescenceThicknessRange=[o.film_thickness,o.film_thickness];let r=en.get(e);if(!r){r={blenderCoatIor:{value:1.5},blenderCoatTint:{value:new Ot(1,1,1)},blenderMapClip:{value:!1},blenderRoughnessClip:{value:!1},blenderNormalClip:{value:!1},blenderWorldExtinction:{value:new x}},en.set(e,r);const a=r;e.customProgramCacheKey=()=>`blender-principled-physical-v5${us(e)}`,e.onBeforeRender=(s,f,u,d,l)=>{gs(e,d),ms(e,d,s,f,u,l,Os),vs(s)},e.onBeforeCompile=s=>{const f=new Set([e.map,e.roughnessMap,e.normalMap].flatMap(m=>m?[m.channel]:[]).concat(_s(e)));s.vertexShader=[...f].filter(m=>m>0).sort((m,h)=>m-h).map(m=>m<=3?`#ifndef USE_UV${m}
7080
+ attribute vec2 uv${m};
7081
+ #endif`:`attribute vec2 uv${m};`).join(`
7082
7082
  `)+`
7083
7083
  `+s.vertexShader,Object.assign(s.uniforms,a),s.fragmentShader=`uniform float blenderCoatIor;
7084
7084
  uniform vec3 blenderWorldExtinction;
@@ -7091,27 +7091,27 @@ 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
- `+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",`
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 ) ) );"),d=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>",d).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`),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};
7100
+ vec3 Fcc = F_Schlick`),ps(e,s)},e.needsUpdate=!0}r.blenderCoatIor.value=Math.max(1,o.coat_ior),r.blenderCoatTint.value.setRGB(...o.coat_tint,vt),r.blenderMapClip.value=n.map===!0,r.blenderRoughnessClip.value=n.roughness===!0,r.blenderNormalClip.value=n.normal===!0}function Oe(e){const t=r=>{if(!(!r||typeof r!="object")){if("kind"in r&&["direction","window","sky"].includes(String(r.kind)))throw new Error(`World volume spatial input ${r.kind} is not implemented`);for(const a of Object.values(r))t(a)}};t(e);const n=at(e)(new x);if(!(typeof n=="number"?[n]:n.toArray()).every(Number.isFinite))throw new Error("World volume input is not finite");return n}function Yt(e){const t=Oe(e);if(typeof t!="number")throw new Error("World volume scalar input resolved to a color");return Math.max(0,t)}function An(e){const t=Oe(e);return(typeof t=="number"?new x().setScalar(t):t.clone()).max(new x)}function As(e){if(e<800)return new x(5.413294490189271,0,0);if(e>=12e3)return new x(.8262954810464208,.9945080501520986,1.566307710274283);const t=[965,1167,1449,1902,3315,6365].filter(a=>e>=a).length,n=[[1619.19106,-.00205010916,5.02995757],[2488.45471,-.00111330907,3.22621544],[3341.43193,-.000486551192,1.76486769],[4094.61742,-.000127446582,.725731635],[4670.28036,291258199e-13,.126703442],[4595.09185,287495649e-13,.15034502],[3787.1745,935907826e-14,.399075871]][t],o=[[-488.999748,.000604330754,-.0755807526],[-755.994277,.000316730098,.478306139],[-1023.63977,.00012022347,.936662319],[-1265.71316,487340896e-14,1.27054498],[-1425.29332,-401150431e-13,1.43972784],[-1175.54822,-216378048e-13,1.30408023],[-500.799571,-459832026e-14,1.09098763]][t],r=[[596945309e-19,-485742887e-16,-970622247e-13,-.00407936148],[240430366e-19,555021075e-16,-.000198503712,.0289312858],[-140949732e-19,189878968e-15,-.000356632824,.0910767778],[-361460868e-19,284822009e-15,-.000493211319,.15672344],[-197075738e-19,175359352e-15,-.000250542825,-.0222783266],[-161997957e-21,-164216008e-16,.000386216271,-.738077418],[672650283e-21,-273078809e-16,.000424098264,-.752335691]][t];return new x(n[0]/e+n[1]*e+n[2],o[0]/e+o[1]*e+o[2],((r[0]*e+r[1])*e+r[2])*e+r[3]).max(new x)}function Ze(e){if(!e?.volume?.length)return null;const t={extinction:new x,emission:new x,lobes:[]};for(const n of e.volume){const o=Yt(n.weight);if(o===0)continue;const r=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 d=Oe(n.anisotropy);if(typeof d!="number")throw new Error("World volume anisotropy must be scalar");t.lobes.push({coefficient:f.clone().multiplyScalar(o),g:u==="RAYLEIGH"?0:xt.clamp(d,-.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 d=Yt(n.blackbody_intensity);if(d>.001){const l=Yt(n.temperature),i=5670373e-20/Math.PI*(1+d*(l**4-1));t.emission.add(As(l).multiply(An(n.blackbody_tint)).multiplyScalar(i*o))}}(n.kind==="principled"||n.kind==="emission")&&t.emission.add((n.kind==="emission"?r:An(n.emission_color)).multiplyScalar(Yt(n.emission_strength)*o)),t.extinction.add(s.add(f).multiplyScalar(o))}for(const n of["x","y","z"])if(t.extinction[n]===0&&t.emission[n]>0)throw new Error("Unbounded emissive World volume with zero extinction has divergent radiance");return t}class Ts{constructor(t){this.medium=t,this.target=new ra(1,1,{type:de,depthBuffer:!1}),this.geometry=new mo(2,2),this.scene=new sa,this.camera=new ia}render(t,n,o,r){if(!n.depthTexture)throw new Error("World volume render requires surface depth");const a={surface:{value:n.texture},depth:{value:n.depthTexture},inverseProjection:{value:r.projectionMatrixInverse},cameraWorld:{value:r.matrixWorld},orthographic:{value:r.isOrthographicCamera===!0},sigma:{value:this.medium.extinction},emission:{value:this.medium.emission}};let s="",f="",u=0,d=2;o.traverseVisible(_=>{if(!(_ instanceof Jn||_ instanceof te||_ instanceof Pn))return;const m=_,h=u++,v=m.getWorldPosition(new x);a[`lp${h}`]={value:v},a[`lc${h}`]={value:m.color.clone().multiplyScalar(m.intensity)},s+=`uniform vec3 lp${h}, lc${h};
7101
+ `;let p="1.0",g="1.0";if(m instanceof te&&(a[`ld${h}`]={value:m.target.getWorldPosition(new x).sub(v).normalize()},a[`cone${h}`]={value:new Gt(Math.cos(m.angle),Math.cos(m.angle*(1-m.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}))`),!(m instanceof Pn)&&m.castShadow&&m.shadow.map){if(++d>t.capabilities.maxTextures)throw new Error("World volume shadow samplers exceed this GPU texture-unit limit");a[`sm${h}`]={value:m.shadow.map.texture},a[`sx${h}`]={value:m.shadow.matrix},a[`ss${h}`]={value:m.shadow.mapSize},a[`sb${h}`]={value:m.shadow.bias},a[`sn${h}`]={value:m.shadow.camera.near},a[`sf${h}`]={value:m.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=m 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(m instanceof Pn){const b=new H().extractRotation(m.matrixWorld);a[`lx${h}`]={value:new x(m.width,0,0).applyMatrix4(b)},a[`ly${h}`]={value:new x(0,m.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},s+=`uniform float cut${h},decay${h};
7109
+ `}else a[`cut${h}`]={value:m.distance},a[`decay${h}`]={value:m.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},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:`
7113
+ `});let l="vec3 result=vec3(0.);";this.medium.lobes.forEach((_,m)=>{a[`scatter${m}`]={value:_.coefficient},a[`g${m}`]={value:_.g},a[`a${m}`]={value:_.alpha},s+=`uniform vec3 scatter${m}; uniform float g${m},a${m};
7114
+ `,l+=`result+=scatter${m}*(1.-g${m}*g${m})*(1.+a${m}*c*c)/(12.56637061436*(1.+a${m}*(1.+2.*g${m}*g${m})/3.)*pow(1.+g${m}*g${m}-2.*g${m}*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 me({uniforms:a,depthTest:!1,depthWrite:!1,toneMapped:!1,defines:{USE_SHADOWMAP:"",NUM_DIR_LIGHT_SHADOWS:0,NUM_SPOT_LIGHT_SHADOWS:0,NUM_POINT_LIGHT_SHADOWS:0,NUM_SPOT_LIGHT_COORDS:0},vertexShader:"varying vec2 vUv; void main(){vUv=uv;gl_Position=vec4(position.xy,0.,1.);}",fragmentShader:`
7115
7115
  #include <common>
7116
7116
  #include <packing>
7117
7117
  #include <shadowmap_pars_fragment>
@@ -7141,10 +7141,10 @@ attribute vec2 uv${d};
7141
7141
  radiance+=incident(origin+ray*t,ray)*exp(-sigma*t)*(hi-lo);
7142
7142
  }
7143
7143
  gl_FragColor=vec4(radiance,base.a+(1.-base.a)*(1.-dot(tr,vec3(1./3.))));
7144
- }`}),this.scene.clear(),this.scene.add(new Rt(this.geometry,this.material)),this.target.setSize(n.width,n.height);const c=t.getRenderTarget();try{t.setRenderTarget(this.target),t.render(this.scene,this.camera)}finally{t.setRenderTarget(c)}return this.target}dispose(){this.material?.dispose(),this.geometry.dispose(),this.target.dispose(),this.scene.clear()}}const 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;
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(e){const n=e<0?0:e>1?1:e,o=(.5+.5*n)**1.5,[r,a,s]=Ps(2/3*(1-n)),f=new Ot;return f.setRGB((r*o)**(1/1.5),(a*o)**(1/1.5),(s*o)**(1/1.5),$t),f}function Ps(e){const t=(e%1+1)%1,n=Math.floor(t*6),o=t*6-n;switch(n%6){case 0:return[1,o,0];case 1:return[1-o,1,0];case 2:return[0,1,o];case 3:return[0,1-o,1];case 4:return[o,0,1];default:return[1,0,1-o]}}const Es=0;function Qe(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}class 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,o){if(t===null||n===null||!n.isMesh||o===null)return this.clear(),this.signature="",null;const r=`${t.object}:${t.group}`;if(t.unchanged===!0){if(this.held?.key!==r)return this.clear(),`weights: the session sent a reference to ${r} that this overlay does not hold; the colours reappear on the next change to the mesh or the group`}else{if(t.weightsBase64===void 0||t.alertBase64===void 0)return this.clear(),`weights: ${r} carried neither an array nor a reference`;const m=Qe(t.weightsBase64);this.held={key:r,weights:new Float32Array(m.buffer,m.byteOffset,t.count),alerts:Qe(t.alertBase64)}}const a=this.held;if(a===null)return null;const s=`${r}:${t.digest}:${n.geometry.uuid}:${t.alertMode}:${o.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"),d=f.getAttribute("blenderVertex");if(d===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 m=0;m<u.count;m++){const h=d.getX(m),p=t.alertMode!=="NONE"&&a.alerts[h]===1?i:Ms(a.weights[h]??0);l[m*3]=p.r,l[m*3+1]=p.g,l[m*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(o),_.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,Ke=[16724818,9165824,2658559];function zs(e){const t=n=>Math.min(255,Math.max(0,Math.floor(.75*n+63.75)-60))/255;return new Ot().setRGB(t(e>>16&255),t(e>>8&255),t(e&255),$t)}function Lo(){return new fa({vertexColors:!0,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1})}function Ds(){const e=[],t=[],n=new Ot(0,0,0),o=(a,s,f,u,d)=>{for(const l of[a,s]){const i=[0,0,0];i[f]=l*u,e.push(...i),t.push(d.r,d.g,d.b)}};for(let a=0;a<3;a++){const s=new Ot().setHex(Ke[a],$t);o(1,.85,a,1,s),o(.85,.25,a,1,n),o(1,.85,a,-1,zs(Ke[a])),o(.85,.25,a,-1,n)}const r=new gn;return r.setAttribute("position",new Mt(e,3)),r.setAttribute("color",new Mt(t,3)),new ho(r,Lo())}function Fs(){const t=[],n=[],o=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:o;for(const u of[s,s+1]){const d=2*Math.PI*u/12;t.push(.5*Math.cos(d),.5*Math.sin(d),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 ho(a,Lo())}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,o)=>this.fit(t,o),this.circle.onBeforeRender=(t,n,o)=>this.fit(t,o)}apply(t){if(t===void 0){this.present(!1);return}this.anchor.matrix.set(...t.flat()),this.anchor.updateMatrixWorld(!0),this.present(!0)}present(t){this.anchor.visible=t,this.circle.visible=t}show(t){const[n,o,r,a]=t.rotation;this.anchor.matrix.compose(new x(...t.location),new At(o,r,a,n),new x(1,1,1)),this.anchor.updateMatrixWorld(!0),this.present(!0)}fit(t,n){this.seen={camera:n,canvas:t.domElement},t.getSize(this.size);const o=Math.max(this.size.y,1),r=this.scratch.setFromMatrixPosition(this.anchor.matrixWorld);let a;if(n.isOrthographicCamera){const f=n;a=(f.top-f.bottom)/f.zoom/o}else{const f=n;a=2*Math.max(-r.applyMatrix4(n.matrixWorldInverse).z,1e-6)*Math.tan(xt.degToRad(f.fov)/2)/f.zoom/o}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,o,r,a){const s=this.seen;if(s===null||o!==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),d=new la;d.setFromCamera(u,s.camera);const l=h=>{for(let v=h;v!==null;v=v.parent)if(!v.visible)return!1;return!0},i=d.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=d.ray.intersectPlane(new Bt().setFromNormalAndCoplanarPoint(v,h),new x)}if(c===null)return null;r.updateWorldMatrix(!0,!1);const _=r.worldToLocal(c),m=r.getWorldQuaternion(new At).invert().multiply(s.camera.getWorldQuaternion(new At));return{location:[_.x,_.y,_.z],rotation:[m.w,m.x,m.y,m.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,et=(e,t,n)=>e.push(t[0],t[1],t[2],n[0],n[1],n[2]);function ut(e,t){return Array.from({length:t},(n,o)=>{const r=2*Math.PI*o/t;return[e*Math.cos(r),e*Math.sin(r)]})}function gt(e,t,n=0,o=!1){const r=o?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];et(e,[s[0],s[1],n],[f[0],f[1],n])}}function Ls(e){if(!e.isMesh||e.userData.volterOverrideStandDown)return;e.userData.volterOverrideStandDown=!0;const t=e.onBeforeRender.bind(e),n=e.onAfterRender.bind(e),o=new H;let r=!1;e.onBeforeRender=(a,s,f,u,d,l)=>{t(a,s,f,u,d,l),s.overrideMaterial&&(o.copy(e.matrixWorld),e.matrixWorld.makeScale(0,0,0),r=!0)},e.onAfterRender=(a,s,f,u,d,l)=>{r&&(e.matrixWorld.copy(o),r=!1),n(a,s,f,u,d,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 o of t.objects){const r=o.selected?o.name===t.active?Et.active:Et.selected:o.type==="CAMERA"?Et.camera:o.type==="LIGHT"?Et.light:Et.empty,a=o.type==="CAMERA"&&o.name!==t.lookingThrough?t.cameras[o.name]:void 0,s=o.type==="LIGHT"&&o.light?t.lights[o.light]:void 0,f=o.type==="EMPTY"?t.empties[o.name]:void 0;if(!a&&!s&&!f)continue;n.add(o.name);const u=s&&o.light?t.lightDistances[o.light]??null:null,d=f?.image?.name?t.image(f.image.name):null,l=JSON.stringify([d?[d.texture.uuid,d.width,d.height]:null,o.matrix,r,a,s,u,f,a?[o.name===t.sceneCamera,t.renderAspect]:null]),i=this.drawn.get(o.name),c=t.presented(o.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(...o.matrix.flat()),m=a?this.cameras:s?this.lights:this.empties,h=new Set(m.children);a?this.camera(a,_,r,o.name===t.sceneCamera,t.renderAspect):s?this.light(s,_,r,u):f&&this.empty(f,_,r,d);const v=m.children.filter(p=>!h.has(p));for(const p of v)p.userData.volterPicksAs=c,p.traverse(Ls);this.drawn.set(o.name,{key:l,parts:v})}for(const[o,r]of this.drawn)n.has(o)||(this.remove(r.parts),this.drawn.delete(o))}remove(t){for(const n of t)n.removeFromParent(),n.geometry?.dispose(),n.userData.volterOwnMaterial&&n.material.dispose()}camera(t,n,o,r,a){const s=t.display_size,u=(t.sensor_fit==="AUTO"?a>=1:t.sensor_fit==="HORIZONTAL")?[1,1/a]:[a,1];let d,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,d=.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;d=s/2/((1/O.x+1/O.y+1/O.z)/3),l=d*t.lens/-T,i=[d*u[0],d*u[1]],c=[t.shift_x*d*2,t.shift_y*d*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]],m=[];for(let T=0;T<4;T++)et(m,_[T],_[(T+1)%4]),et(m,_[T],[0,0,0]);const h=.7*d,v=.1*d,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(m,o,1,b));let y;if(r){const T=new gn;T.setAttribute("position",new Mt(g.flat(),3)),y=new Rt(T,this.fill(o)),y.matrixAutoUpdate=!1,y.matrix.copy(b)}else{const T=[];for(let O=0;O<3;O++)et(T,g[O],g[(O+1)%3]);y=this.lines(T,o,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,o,r){const a=new x().setFromMatrixPosition(n),s=[];et(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=[],d=9;if(gt(u,ut(d*.3,4)),gt(u,ut(d,16),0,!0),gt(u,ut(d*1.33,20),0,!0),t.type==="SUN")for(const[c,_]of ut(d,8))et(u,[c*1.6,_*1.6,0],[c*1.9,_*1.9,0]),et(u,[c*2.2,_*2.2,0],[c*2.5,_*2.5,0]);this.lights.add(this.screen(u,o,1,a));const l=Zn(n),i=[];if(t.type==="SUN")et(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(([m,h])=>[m*c,h*_])):gt(i,[[c,_],[-c,_],[-c,-_],[c,-_]])}if(i.length>0&&this.lights.add(this.lines(i,o,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),[m,h]=r,v=[];et(v,_(m).toArray(),_(h).toArray()),this.lights.add(this.lines(v,o,1,new H));for(const p of[m,h]){const g=[];gt(g,ut(1.2,4)),this.lights.add(this.screen(g,o,1,_(p)))}}if(t.type==="SPOT"){const c=(t.spot_size??Math.PI/4)/2,_=Math.cos(c),m=t.spot_blend??.15,h=_*m-_-m,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,o,1,g.clone())),this.lights.add(this.silhouette(p,_,o,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,o,new x().setFromMatrixPosition(l)))}}empty(t,n,o,r){const a=t.size,s=[],f=(d,l)=>{const i=ut(1,l);for(let c=0;c<l;c++){const[_,m]=i[c],[h,v]=i[(c+1)%l],p=(g,b)=>d==="xy"?[g,b,0]:d==="xz"?[g,0,b]:[0,g,b];et(s,p(_,m),p(h,v))}};switch(t.display){case"PLAIN_AXES":et(s,[0,-1,0],[0,1,0]),et(s,[-1,0,0],[1,0,0]),et(s,[0,0,-1],[0,0,1]);break;case"SINGLE_ARROW":{et(s,[0,0,0],[0,0,.75]);for(const[d,l]of[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]])et(s,[0,0,1],[d,l,.75]);gt(s,[[.035,.035],[-.035,.035],[-.035,-.035],[.035,-.035]],.75);break}case"CUBE":for(const[d,l]of js)et(s,Je[d],Je[l]);break;case"CIRCLE":f("xz",64);break;case"SPHERE":f("xy",32),f("xz",32),f("yz",32);break;case"CONE":{const d=ut(1,8);for(let l=0;l<8;l++){const[i,c]=d[l],[_,m]=d[(l+1)%8];et(s,[i,0,c],[0,2,0]),et(s,[i,0,c],[_,0,m])}break}case"ARROWS":for(let d=0;d<3;d++){const l=[0,0,0];l[d]=1,et(s,[0,0,0],l)}break;case"IMAGE":this.imageEmpty(t,n,o,r);return}const u=n.clone().multiply(new H().makeScale(a,a,a));this.empties.add(this.lines(s,o,1,u)),t.display==="ARROWS"&&this.axisNames(n,a,o)}silhouette(t,n,o,r){const a=this.lines(new Array(192).fill(0),o,1,r);a.frustumCulled=!1;const s=a.geometry.getAttribute("instanceStart").data,f=ut(1,32).map(([_,m])=>new x(_*t,m*t,-n)),u=new x,d=new H,l=new x,i=new x,c=new x;return this.onDraw(a,(_,m)=>{d.copy(a.matrixWorld).invert();const h=m.isOrthographicCamera;h?m.getWorldDirection(u).negate().transformDirection(d):u.setFromMatrixPosition(m.matrixWorld).applyMatrix4(d);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,o,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],d=new x,l=new x,i=new x;n.extractBasis(d,l,i),d.multiplyScalar(u[0]*.5*t.size),l.multiplyScalar(u[1]*.5*t.size);const c=new x().setFromMatrixPosition(n).addScaledVector(d,a.offset[0]*2+1).addScaledVector(l,a.offset[1]*2+1),_=new H().makeBasis(d,l,i.clone()).setPosition(c),m=[];gt(m,[[-1,-1],[1,-1],[1,1],[-1,1]]);const h=this.lines(m,o,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:ne,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 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=`
7147
+ diffuseColor.a = 1.0;`)},T.customProgramCacheKey=()=>`volter-blender-image:${a.premultiplied}:${S}`;const O=new Rt(new mo(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,o){const r=[new x,new x,new x];t.extractBasis(r[0],r[1],r[2]);for(let a=0;a<3;a++){const 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 d=[];for(let c=1;c<=6;c++)gt(d,ut(.007*(4*c/6)*s,4));this.empties.add(this.facing(d,o,u));const l=Bs[a],i=[];for(let c=0;c+1<l.length;c+=2){const[_,m]=l[c],[h,v]=l[c+1];et(i,[_*4*s,m*4*s,0],[h*4*s,v*4*s,0])}this.empties.add(this.facing(i,o,f))}}material(t,n){const o=`${t}:${n}`;let r=this.lineMaterials.get(o);return r||(r=new so({color:t,linewidth:$s,transparent:n<1,opacity:n,depthTest:!0,depthWrite:n>=1,toneMapped:!1}),this.lineMaterials.set(o,r)),r}fill(t){let n=this.fillMaterials.get(t);return n||(n=new Rn({color:t,side:ne,toneMapped:!1}),this.fillMaterials.set(t,n)),n}lines(t,n,o,r){const a=new ro().setPositions(t),s=new io(a,this.material(n,o));return s.matrixAutoUpdate=!1,s.matrix.copy(r),s.computeLineDistances(),s}screen(t,n,o,r){const a=this.lines(t,n,o,new H);return a.matrixAutoUpdate=!0,a.position.copy(r),a.scale.setScalar(0),a.frustumCulled=!1,this.onDraw(a,(s,f)=>this.face(a,s,f,!0)),a}facing(t,n,o){const r=this.lines(t,n,1,new H);return r.matrixAutoUpdate=!0,r.position.copy(o),this.onDraw(r,(a,s)=>this.face(r,a,s,!1)),r}onDraw(t,n){const o=t,r=o.onBeforeRender.bind(o);o.onBeforeRender=(a,s,f,u,d,l)=>{n(a,f),r(a,s,f,u,d,l)}}face(t,n,o,r){t.parent?.getWorldQuaternion(this.parentQuat).invert(),o.getWorldQuaternion(t.quaternion).premultiply(this.parentQuat);let a=1;if(r){n.getSize(this.size);const s=Math.max(this.size.y,1),f=this.scratch.setFromMatrixPosition(t.matrixWorld);if(o.isOrthographicCamera){const u=o;a=(u.top-u.bottom)/u.zoom/s}else{const u=o;a=2*Math.max(-f.applyMatrix4(o.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(e){const t=new x,n=new At;return e.decompose(t,n,new x),new H().compose(t,n,new x(1,1,1))}const Je=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],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(([e,t])=>[e*.0215,t*.025]),[[-1,1],[0,-.1],[1,1],[0,-.1],[0,-.1],[0,-1]].map(([e,t])=>[e*.0175,t*.025]),[[-.95,1],[.95,1],[.95,1],[.95,.9],[.95,.9],[-1,-.9],[-1,-.9],[-1,-1],[-1,-1],[1,-1]].map(([e,t])=>[e*.02,t*.025])],_t=N().finite(),to=M({name:R(),type:R(),lens:_t,sensor_width:_t,sensor_height:_t,sensor_fit: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(e,t,n,o){const r=a=>Math.min(1,Math.max(-1,a));return[r(e[0]-n/(2*t)),r(e[1]+o/(2*t))]}function no(e,t,n,o){const r=e.type==="ORTHO",a=e.sensor_fit==="VERTICAL"?e.sensor_height:e.sensor_width,s=e.sensor_fit==="AUTO"?t>=n:e.sensor_fit==="HORIZONTAL",f=(r?e.ortho_scale:a/e.lens)/2*o;return s?[f,f*n/t]:[f*t/n,f]}function Hs(e,t,n,o,r,a){const s=Math.max(n.width,1),f=Math.max(n.height,1),[u,d]=no(e,s,f,1/o),[l,i]=no(e,a,1,1),_=2*((e.sensor_fit==="AUTO"?a>=1:e.sensor_fit==="HORIZONTAL")?l:i),m=l/u,h=i/d,v=-2*r[0]*o,p=2*r[1]*o,g=e.shift_x*_-v*2*u,b=e.shift_y*_+p*2*d,y=new H().set(...e.matrix.flat()).premultiply(t),S=new x,A=new At;return y.decompose(S,A,new x),{name:e.name,position:S.toArray(),quaternion:[A.x,A.y,A.z,A.w],projection:e.type==="ORTHO"?"orthographic":"perspective",window:{left:g-u,right:g+u,top:b+d,bottom:b-d},near:e.clip_start,far:e.clip_end,frame:{left:.5-m/2+v,top:.5-h/2+p,width:m,height:h},passepartout:{color:Sn.passepartout,opacity:e.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
- `,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}
7189
+ `,Ae=e=>xe.map(t=>{const[n=0,o=0,r=0]=e(t);return new x(n,o,r)}),Xs=Ae(e=>e.direction).map(e=>e.normalize()),Ys=Ae(e=>e.diffuse),Zs=Ae(e=>e.specular),Qs=new Cn(...xe.map(e=>e.smooth));function Ks(e,t){const[n,o,r]=e.color,a=new ma({side:t});return a.color.setRGB(n,o,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:e.roughness},s.uniforms.wbMetallic={value:e.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 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};
7191
+ #include <opaque_fragment>`)},a.customProgramCacheKey=()=>"volter-blender-workbench",a}const Js=64;function ti(e,t){return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>n===t[o]):e===t}function hn(e){for(let t=e;t;t=t.parent)if(!t.visible)return!1;return!0}function _e(e){if(e.determinant()<=0)return!1;const t=e.elements,n=Math.hypot(t[0],t[1],t[2]),o=Math.hypot(t[4],t[5],t[6]),r=Math.hypot(t[8],t[9],t[10]),a=(s,f)=>t[s]*t[f]+t[s+1]*t[f+1]+t[s+2]*t[f+2];return Number.isFinite(n+o+r)&&Math.min(n,o,r)>0&&Math.abs(a(0,4))<=1e-7*n*o&&Math.abs(a(0,8))<=1e-7*n*r&&Math.abs(a(4,8))<=1e-7*o*r}class 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 he,this.camera=null,this.eligible=0,this.excluded={}}rebuild(t,n){if(this.clear(),!n)return;const o=new Map,r=a=>{this.excluded[a]=(this.excluded[a]??0)+1};this.inverse.copy(this.root.matrixWorld).invert();for(const a of t){const 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=>ko(l,s.geometry).size>12)){r("attributeBudget");continue}if(this.matrix.multiplyMatrices(this.inverse,s.matrixWorld),!_e(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}`,d=o.get(u);d?d.push(s):o.set(u,[s])}for(const a of o.values()){if(a.length<2)continue;const s=f=>{if(f.length>Js){this.box.makeEmpty();for(const m of f)this.box.expandByPoint(new x().setFromMatrixPosition(m.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((m,h)=>m.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],d=new po(u.geometry,u.material,f.length);d.name="Blender repeated geometry",d.userData.engineInternal=!0,d.matrixAutoUpdate=!1,d.renderOrder=u.renderOrder,d.instanceMatrix.setUsage(vo);const l={draw:d,members:f.map(i=>({mesh:i,layers:i.layers.mask}))};d.raycast=(i,c)=>{for(const{mesh:_}of l.members)_.layers.mask===0&&hn(_)&&_.raycast(i,c)},this.root.add(d),d.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 o=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)&&_e(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=o*16;this.matrix.elements.some((d,l)=>Math.fround(d)!==t.instanceMatrix.array[u+l])&&(t.setMatrixAt(o,this.matrix),r=!0),o++}r||=t.count!==o||t.boundingSphere===null,t.count=o,r&&(t.instanceMatrix.needsUpdate=!0,t.computeBoundingBox(),t.computeBoundingSphere())}}}prepareDraw(t){t.updateMatrixWorld(),this.camera=t,this.projection.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projection)}finishDraw(){this.camera=null}clear(){this.camera=null;for(const{draw:t,members:n}of this.batches){for(const{mesh:o,layers:r}of n)o.layers.mask|=r;t.removeFromParent(),t.dispose()}this.batches.length=0,this.eligible=0,this.excluded={}}inspect(){return{batches:this.batches.length,instances:this.batches.reduce((t,{draw:n})=>t+n.count,0),eligible:this.eligible,excluded:{...this.excluded}}}}const fn=64;function eo(e){for(let t=e.parent;t;t=t.parent)if(t.isGroup)return t.renderOrder;return 0}class ei{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 he,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=[],o=new Map;for(const a of this.objects){const s=Array.isArray(a.material)?a.material:[a.material];if(!s.some(m=>m.visible&&m.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(),d=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,_=eo(a);if(c&&c.visible&&c.transparent&&!c.isShaderMaterial&&!(c.transmission>0)&&(c.side!==ne||c.forceSinglePass)&&!a.isSkinnedMesh&&!a.morphTargetInfluences&&!a.isInstancedMesh&&a.layers.mask===1&&_===this.root.renderOrder){const m=a.geometry,h=m.index?.count??m.getAttribute("position").count,v=!Array.isArray(a.material)||m.groups.length===1&&m.groups[0].start===0&&m.groups[0].count===h&&m.groups[0].materialIndex===0,p=`${m.id}:${c.uuid}:${a.renderOrder}`;let g=o.get(p);g===void 0&&(g=ko(c,m).size<=12,o.set(p,g)),this.matrix.multiplyMatrices(this.inverse,a.matrixWorld),v&&g&&_e(this.matrix)&&(l=c,i=p)}n.push({mesh:a,material:l,key:i,groupOrder:_,z:d,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],d=n[f],l=u?.z===s.z&&u.mesh.renderOrder===s.mesh.renderOrder||d?.z===n[f-1].z&&d.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 m=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 po(s.mesh.geometry,s.material,fn);g.name="Blender ordered transparency",g.userData.engineInternal=!0,g.matrixAutoUpdate=!1,g.frustumCulled=!1,g.boundingSphere=new go,g.instanceMatrix.setUsage(vo),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=m.mesh.renderOrder,p.mesh.boundingSphere.center.copy(m.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(eo(n)),this.observe(n.frustumCulled?1:0),this.observe(n.morphTargetInfluences?1:0);for(const s of n.matrixWorld.elements)this.observe(s);const o=n.geometry;this.observe(o.id),this.observe(o.drawRange.start),this.observe(o.drawRange.count),this.observe(o.index?.count??o.getAttribute("position").count),this.observe(o.groups.length);for(const s of o.groups)this.observe(s.start),this.observe(s.count),this.observe(s.materialIndex??0);const r=n.boundingSphere??o.boundingSphere;this.observe(r?.center.x??0),this.observe(r?.center.y??0),this.observe(r?.center.z??0),this.observe(r?.radius??-1);const a=Array.isArray(n.material)?n.material:null;if(this.observe(a?.length??-1),a)for(const 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 oi={WIREFRAME:"wireframe",SOLID:"solid",MATERIAL:"preview",RENDERED:"rendered"},z=N().finite(),Vo=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(Vo)}).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(Vo),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(e=>ArrayBuffer.isView(e))}).strict(),jo=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,jo,si,ii]),oo=new Set;function ui(e,t){const n=new Blob([e],{type:t}),o=new ga;let r=!1;o.addEventListener("dispose",()=>{r=!0,o.image?.close?.()});const a=createImageBitmap(n,{imageOrientation:"flipY",premultiplyAlpha:"none",colorSpaceConversion:"none"}).then(s=>{if(r){s.close();return}o.image=s,o.needsUpdate=!0,wt()}).finally(()=>{oo.delete(a)});return oo.add(a),a.catch(()=>{}),{texture:o,ready:a}}function _i(e,t,n,o){const r=new kn(e,t,n,$n,va);return r.flipY=!1,r.colorSpace=o==="data"?In:$t,r.needsUpdate=!0,r}function mi(e,t,n){if(t.length===0)throw new Error(`Runtime image ${e} is tiled with no tiles`);const o=Math.max(...t.map(l=>l.width)),r=Math.max(...t.map(l=>l.height)),a=new Uint8Array(o*r*4*t.length),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?ae(l.rgbaBase64):void 0);if(!c)throw new Error(`Runtime image ${e} tile ${l.number} carries no raster`);for(let m=0;m<l.height;m++)a.set(c.subarray(m*l.width*4,(m+1)*l.width*4),(i*r+m)*o*4);const _=l.number-1001;f[_*4]=i,f.set([0,0,l.width/o,l.height/r],(s+_)*4)});const u=new pa(a,o,r,t.length);u.colorSpace=n==="data"?In:$t,u.magFilter=Xt,u.minFilter=xo,u.generateMipmaps=!0,u.needsUpdate=!0;const d=new kn(f,s,2,$n,uo);return d.magFilter=d.minFilter=ee,d.needsUpdate=!0,{tiles:u,map:d,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(),Bo=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(),Io).default({}),lights:bt(R(),Rr).default({}),world:Lr.nullable().default(null),meshes:bt(R(),ci),materials:bt(R(),pi),images:bt(R(),Bo).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(),yo())).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(e,t){for(let n=0,o=e.length-1;n<e.length&&o>=0;n++,o--){if(e[n][0]===t)return e[n][1];if(n===o)break;if(e[o][0]===t)return e[o][1]}return null}const 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 ei(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 be,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,o]of[[this.armatureRoot,this.armatureOverlay.group],[this.weightRoot,this.weightOverlay.group],[this.cursorRoot,this.cursorOverlay.group],[this.cameraExtrasRoot,this.extrasOverlay.cameras],[this.lightExtrasRoot,this.extrasOverlay.lights],[this.emptyExtrasRoot,this.extrasOverlay.empties]])n.matrixAutoUpdate=!1,n.matrix.copy(this.root.matrix),n.add(o),n.updateMatrixWorld(!0);this.armatureRoot.name="BlenderBones",this.weightRoot.name="BlenderWeights",this.cursorRoot.name="Blender3DCursor",this.cameraExtrasRoot.name="BlenderCameraExtras";for(const n of[this.cameraExtrasRoot,this.lightExtrasRoot,this.emptyExtrasRoot])n.userData.volterPickable=!0;this.lightExtrasRoot.name="BlenderLightExtras",this.emptyExtrasRoot.name="BlenderEmptyExtras"}compiledGraph(t){const n=JSON.stringify(t);let o=this.graphs.get(n);return o||(o=ls(t),this.graphs.size>256&&this.graphs.clear(),this.graphs.set(n,o)),o}mirrorPose(t){let n=null;for(const[a,s]of this.objects)if(s===t){n=a;break}if(n===null)return;const o=this.leader?[this.leader,...this.leader.followers]:[...this.followers];let r=!1;for(const a of o){if(a===this)continue;const 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),o=Ia(t);return()=>{n(),o()}}blenderObjectName(t){for(const[n,o]of this.objects)if(o===t)return this.frame?.objects.find(r=>r.id===n)?.name??null;return null}noteSavedShading(t){this.frame?.view&&(this.frame.view.shading=t)}savedView(){const t=this.frame?.view;if(!t)return null;const[n,o,r,a]=t.rotation,s=new At(o,r,a,n),f=new x(...t.location).applyMatrix4(this.root.matrix),u=d=>d.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?oi[t.shading]:null}}cameraViewCamera(){const t=this.frame,n=t?.camera_view;return!t||!n?null:n.scene_camera!==null&&t.cameras[n.scene_camera]?n.scene_camera:t.active!==null&&t.cameras[t.active]?t.active:n.view_layer_cameras.find(o=>t.cameras[o])??null}blenderPose(t,n){const o=new H().copy(this.root.matrix).invert(),r=new H().compose(new x(...t),new At(...n),new x(1,1,1)).premultiply(o),a=new x,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,o,r){const a=this.frame,s=to.safeParse(a?.cameras[t]);return!a?.camera_view||!s.success?null:Hs(s.data,this.root.matrix,n,o,r,a.camera_view.aspect)}subjectLine(t){const n=this.frame?.subject;if(n===void 0)return null;const o=t??n.frame,r=gi(n.markers,o);return`(${o})${n.body}${r===null?"":` <${r}>`}`}gridUnitName(t){const n=this.frame?.units;if(n===void 0||n.system==="NONE")return null;const o=xi[n.system],r=6*t,a=1/(n.scale_length||1);return(o.find(([f])=>f*a>r)??o[o.length-1])[1]}blenderSelection(){const t=this.frame;return t===null?{selected:[],active:null}:{selected:t.objects.filter(n=>n.selected).map(n=>n.name),active:t.active}}setStageMode(t){this.mode=t}stageMode(){return this.mode}objectForBlenderName(t){const n=this.frame?.objects.find(o=>o.name===t);return n===void 0?null:this.objects.get(n.id)??null}replacePresentedObject(t,n){for(const[o,r]of this.objects)if(r===t){const a=t.parent,s=[...t.children];t.removeFromParent();for(const f of s)n.add(f);a?.add(n),this.objects.set(o,n),this.rebuildInstances();return}}studioLights(){return this.lighting.group}overlayGroups(){return[{kind:"skeletons",object:this.armatureRoot},{kind:"weights",object:this.weightRoot},{kind:"cursor",object:this.cursorRoot},{kind:"cameras",object:this.cameraExtrasRoot},{kind:"lights",object:this.lightExtrasRoot},{kind:"empties",object:this.emptyExtrasRoot}]}placeCursor(t,n,o){const r=new Set(this.objects.values()),a=this.cursorOverlay.placementAt(t,n,o,this.root,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 o=t.isOrthographicCamera?t.getWorldDirection(new x).toArray().map(r=>r.toFixed(1)).join(","):"";return`${t.uuid}:${o}:${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 o of this.frame?.objects??[]){if(o.mesh===null||o.volume)continue;const r=this.objects.get(o.id);if(!r?.isMesh)continue;const s=(o.materials.length?o.materials:[null]).map(f=>{const u=f===null?this.fallback:this.materials.get(f)??this.fallback;return t?this.workbenchFor(f,u.side,n):u});r.material=o.materials.length?s:s[0]}for(const[o,r]of this.workbenchMaterials)n.has(o)||(r.dispose(),this.workbenchMaterials.delete(o));this.rebuildInstances()}rebuildInstances(){this.transparentInstances.clear(),this.instances.rebuild(this.objects.values(),this.drawBatching&&!this.rendered),this.drawBatching&&!this.rendered&&this.transparentInstances.setObjects(this.objects.values())}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,o){const r=(t!==null?this.frame?.materials[t]?.viewport:void 0)??qs,a=`${r.color.join(",")}|${r.roughness}|${r.metallic}|${n}`;o.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 o=(t?Ze(this.frame?.world)?.extinction:null)??new x;for(const a of[...this.materials.values(),this.fallback])ws(a,o);this.rendered=t,this.lighting.setRendered(t);const r=t&&n?this.worldKeyFor(n):null;t?(this.capturing||r!==this.worldApplied)&&this.world.apply(this.root,this.frame?.world??null,n):this.world.clear(),this.worldApplied=this.capturing?null:r,this.applyVisibility(),this.applyWorkbench(),this.applyShadows(t,n),t&&(await zr(),await Promise.all([...this.textures.values()].map(a=>a.ready)),await this.world.ready())}applyShadows(t,n){this.root.updateMatrixWorld(!0);const o=[];for(const u of this.objects.values()){const d=u;if(d.isMesh&&(d.castShadow=t,d.receiveShadow=t,t&&d.visible)){const l=new pn().setFromObject(d);l.isEmpty()||o.push(l)}}if(!t||!o.length)return;const a=o.reduce((u,d)=>u.union(d),new pn).getBoundingSphere(new go),s=n?new he().setFromProjectionMatrix(new H().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse)):null,f=s?o.flatMap(u=>Br(u,s)):[];for(const u of this.lights.values())u.isDirectionalLight&&n?Ur(u,f,o):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())},o=[...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&&o.push(a),this.cursorOverlay.apply(t.cursor),this.applyExtras(t),o}setCameraViewShowing(t){this.lookingThrough!==t&&(this.lookingThrough=t,this.frame&&this.applyExtras(this.frame),wt())}applyExtras(t){const n={};for(const[o,r]of Object.entries(t.cameras)){const a=to.safeParse(r);a.success&&(n[o]=a.data)}this.extrasOverlay.apply({lookingThrough:this.lookingThrough,lightDistances:t.light_distances,objects:t.objects.filter(o=>o.visible),active:t.active,cameras:n,lights:t.lights,empties:t.empties,sceneCamera:t.camera_view?.scene_camera??null,renderAspect:t.camera_view?.aspect??1,presented:o=>{const r=t.objects.find(a=>a.name===o);return r?this.objects.get(r.id)??null:null},image:o=>{const r=this.textures.get(o);if(!r)return null;const a=r.texture.image,s=r.width||a?.width||0,f=r.height||a?.height||0;return(s===0||f===0)&&r.ready&&!this.awaitedImages.has(o)&&(this.awaitedImages.add(o),r.ready.then(()=>{this.awaitedImages.delete(o),this.frame&&this.applyExtras(this.frame),wt()},()=>this.awaitedImages.delete(o))),{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 o=this.lights.get(t.light);o&&(o.visible=this.rendered&&t.render_visible)}this.armatureOverlay.group.visible=!this.capturing,this.weightOverlay.group.visible=!this.capturing,this.cursorOverlay.group.visible=!this.capturing;for(const t of[this.extrasOverlay.cameras,this.extrasOverlay.lights,this.extrasOverlay.empties])t.visible=!this.capturing}stageFrame(t){if(t.abort||!t.mesh&&!t.image){for(const o of this.staged?.meshes.values()??[])o.geometry.dispose();this.staged=t.abort?null:{session:t.session,revision:t.revision,meshes:new Map,images:new Map};return}const n=this.staged;if(!n||n.session!==t.session||n.revision!==t.revision)throw new Error("Blender frame piece does not belong to the pending revision");if(t.mesh!==void 0){const o=jo.parse(t.piece);if(n.meshes.has(t.mesh))throw new Error("Duplicate Blender mesh piece");const r=`revision:${o.revision}`;n.meshes.set(t.mesh,{signature:r,geometry:En(Fe({...o.columns,attributes:o.attributes,activeUv:o.activeUv,renderUv:o.renderUv},r))})}else if(t.image!==void 0){if(n.images.has(t.image))throw new Error("Duplicate Blender image piece");n.images.set(t.image,Bo.parse(t.piece))}}applyFrame(t){const n=this.frame===null?null:{session:this.frame.session,revision:this.frame.revision},o=vi.parse(t),r=this.staged;if(r&&(r.session!==o.session||r.revision!==o.revision))throw new Error("Blender frame manifest does not match its staged revision");if(r)for(const[l,i]of r.images)o.images[l]=i;if(this.retiredSessions.has(o.session))throw new Error("The runtime session was replaced; its delayed frame cannot overwrite the active model");if(this.frame?.session===o.session&&o.revision<this.frame.revision)throw new Error("The runtime frame is older than the displayed model");const a=new Set(o.objects.map(l=>l.id));if(a.size!==o.objects.length)throw new Error("Runtime object IDs must be unique");const s=new Map(o.objects.map(l=>[l.id,l]));for(const l of o.objects){if(l.mesh!==null&&!o.meshes[l.mesh])throw new Error(`Missing runtime mesh ${l.mesh}`);if(l.volume&&(!o.volumes[l.volume]||l.mesh!==null))throw new Error(`Invalid runtime volume ${l.volume}`);if(l.light&&(!o.lights[l.light]||l.mesh!==null))throw new Error(`Invalid runtime light ${l.light}`);for(const _ of l.materials)if(_!==null&&!o.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(o.volumes)){const c=JSON.stringify(i);this.frame?.session===o.session&&this.volumes.get(l)?.signature===c||u.set(l,{signature:c,mesh:Wr(i)})}for(const[l,i]of Object.entries(o.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===o.session&&v!==void 0&&(v===`revision:${i.revision}`||!v.startsWith("revision:")))continue;throw new Error(v===void 0?`${Ie}: the presenter does not hold runtime mesh ${l} (store ${i.store}, revision ${i.revision})`:`${Ie}: the presenter holds runtime mesh ${l} at ${v}, not revision ${i.revision}`)}const c="hash"in i,_="columns"in i,m=_?`revision:${i.revision}`:c?i.hash:JSON.stringify(i);this.frame?.session===o.session&&this.meshes.get(l)?.signature===m||f.set(l,{signature:m,geometry:_?En(Fe({...i.columns,attributes:i.attributes,activeUv:i.activeUv,renderUv:i.renderUv},m)):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!==o.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(o.images)){const c=this.textures.get(l);if("width"in i){const p=i.rgba??(i.rgbaBase64?ae(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?ae(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 m=i.colorspace??"sRGB",{texture:h,ready:v}=ui(_,i.mime);h.colorSpace=m==="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:m}})}for(const[l,i]of Object.entries(o.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 m=c.opacity<1||i.graph!==void 0&&Yr(i.graph);c.transparent!==m&&(c.transparent=m,c.needsUpdate=!0),c.roughness=i.roughness,c.metalness=i.metallic,c.transmission=i.transmission,c.ior=i.ior,we(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?ee:Xt,E=y.closest?ee:y.mipmap?xo: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 o.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 fo),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(m=>m===null?this.fallback:this.materials.get(m)):this.fallback,ds(_)}if(l.light){const _=this.lights.get(l.light)??null,m=Fr(o.lights[l.light],_);_&&_!==m&&(_.removeFromParent(),_.dispose()),m.parent!==i&&i.add(m),m.userData.volterOwnOverlay=!0,kr(m,i),this.lights.set(l.light,m)}}for(const l of o.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)o.volumes[l]||(i.mesh.geometry.dispose(),i.mesh.material.dispose(),this.volumes.delete(l));for(const[l,i]of this.meshes)o.meshes[l]||(i.geometry.dispose(),this.meshes.delete(l));for(const[l,i]of this.materials)if(!o.materials[l]){for(const c of["normal","roughness","color"])this.textureSamplers.delete(`${l}:${c}`);for(const c of this.graphSamplers.get(l)??[])this.textureSamplers.delete(c);this.graphSamplers.delete(l),i.dispose(),this.materials.delete(l)}for(const[l,i]of this.lights)o.lights[l]||(i.removeFromParent(),i.dispose(),this.lights.delete(l));this.root.updateMatrixWorld(!0),this.frame={...o,meshes:{},volumes:{},images:{}},this.worldKey=JSON.stringify(o.world??null);const d=this.applyOverlays(o);d.length&&(this.frame={...this.frame,warnings:[...this.frame.warnings,...d]}),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 d=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:d?new Uint32Array(d.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]=Io.parse(JSON.parse(a));const o=new Set(Object.values(n.materials).flatMap(r=>[r.texture?.image.name,r.roughness_texture?.image.name,r.normal_texture?.image.name,...Object.values(r.graph?.nodes??{}).map(a=>a.props.image?.name)].filter(a=>a!==void 0)));for(const r of o){const a=this.textures.get(r);if(!a)throw new Error(`Blender capture image ${r} is not resident`);if(a.encoded)n.images[r]={revision:a.revision,encoded:a.encoded.bytes.slice(),mime:a.encoded.mime,colorspace:a.encoded.colorspace};else{const 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,o=this.createWorldVolumePass(),r=new Fn;r.photograph=!0;let a=!1;const s=()=>{a||(a=!0,o?.dispose(),r.dispose(),r.root.removeFromParent())};try{r.applyFrame(t),this.root.updateWorldMatrix(!0,!1),r.root.matrix.copy(this.root.matrixWorld),r.root.updateMatrixWorld(!0)}catch(f){throw s(),f}return{effect:o,root:r.root,session:n.session,revision:n.revision,prepare:f=>{if(a)throw new Error("Blender capture snapshot is disposed");return r.setRendered(!0,f)},dispose:s}}createWorldVolumePass(){const t=Ze(this.frame?.world);return t?new Ts(t):void 0}recordPresentation(t){if(typeof t!="object"||t===null)return;const n=t,o=n.meshes;if(typeof o!="object"||o===null)return;const r=typeof n.session=="string"?n.session:null;r!==this.submittedSession&&(this.submittedMeshes.clear(),this.photographs.length=0,this.submittedSession=r);const a=o;for(const[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 Uo(e){const t=atob(e),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}function Kn(e){const t=Uo(e);return new Float32Array(t.buffer,t.byteOffset,t.byteLength>>2)}function bi(e){const t=Uo(e);return new Uint16Array(t.buffer,t.byteOffset,t.byteLength>>1)}function yi(e){return new H().set(...e.flat())}function ao(e,t){return[e.object,e.mesh,e.armature,e.vertexCount,e.bones.length,t].join("|")}class wi{#n=new Map;#o=null;#a=null;#t=null;#r=null;#e=null;#i=null;#l=new Set;#u=0;#_=[];#s=0;get version(){return this.#u}get engineCalls(){return this.#s}subscribe(t){return this.#l.add(t),()=>this.#l.delete(t)}#f(){this.#u++;for(const t of[...this.#l])t()}state(){const t=this.#t,n=t?.frameStart??1,o=t?.frameEnd??250,r=t?.fps??24;return{frame:this.frame(),start:n,end:o,fps:r,action:t?.action??null,object:t?.object??null,armature:t?.armature??null,bones:[...this.#n.values()].reduce((a,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.#s,blenderFrame:t?.frameCurrent??null}}playhead(){return this.#t?this.frame():null}frame(){const t=this.#t;return this.#r!==null?this.#r:!t||!this.#a||t.clipStart===void 0?t?.frameCurrent??1:t.clipStart+this.#a.time*t.fps}get playable(){return this.#t!==null&&this.#e!==null}async bind(t,n){this.#s++;const o=await n.rig();if(!o)return;const r=[],a=new Set;let s=!1;for(const _ of o.rigs){if(!_.object||!_.armature||!_.skinIndexBase64||!_.skinWeightBase64){_.reason&&r.push(_.reason);continue}a.add(_.object);const m=ao(_,o.frame);if(this.#n.get(_.object)?.signature===m)continue;const h=this.#d(t,_,o.frame,r);h&&(this.#n.get(_.object)?.skeleton.dispose(),this.#n.set(_.object,h),s=!0)}for(const[_,m]of[...this.#n])a.has(_)||(m.skeleton.dispose(),m.boneRoot.removeFromParent(),this.#n.delete(_),s=!0);this.#s++;const f=await n.clip(),u=this.#t,d=f?.frameStart!==u?.frameStart||f?.frameEnd!==u?.frameEnd||f?.fps!==u?.fps,l=f?.action!==u?.action||f?.tracks.length!==u?.tracks.length||f?.clipStart!==u?.clipStart||f?.clipEnd!==u?.clipEnd;this.#t=f??null,(!f||f.scene!==u?.scene)&&(this.#r=null),f?.reason&&r.push(f.reason),f&&(l||s)&&this.#h(t,f,r);const i=this.#e?.snapshot().activeSubject;d&&i&&this.#e?.setActiveSubject(i);const c=this.#e?.snapshot().playbackState==="playing";f&&!c&&(d||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,o,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 d=u.getAttribute("blenderVertex");if(!d)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<d.count;A++)l=Math.max(l,d.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??""),_=d.count,m=new Uint16Array(_*4),h=new Float32Array(_*4);for(let A=0;A<_;A++){const T=d.getX(A);for(let O=0;O<4;O++)m[A*4+O]=i[T*4+O]??0,h[A*4+O]=c[T*4+O]??0}u.setAttribute("skinIndex",new xa(m,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:o,signature:ao(n,o)}}#h(t,n,o){if(this.#o?.stopAllAction(),this.#o=null,this.#a=null,!n.tracks.length||n.clipStart===void 0||n.clipEnd===void 0)return;const r=n.armature?t.objectForBlenderName(n.armature):null;if(!r)return;const a=new Map;for(const 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),m=Kn(i.valueBase64),h=`${c.uuid}.${i.property}`;s.push(i.property==="quaternion"?new Oa(h,Array.from(_),Array.from(m)):new Aa(h,Array.from(_),Array.from(m)))}if(f.size&&o.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,d=new Ta(r),l=d.clipAction(new Sa(n.action??"action",u,s));l.setLoop(Ma,Number.POSITIVE_INFINITY),l.play(),this.#o=d,this.#a=l,this.#c(n.frameCurrent),this.#m()}#c(t){const n=this.#t;if(!n)return;const o=Math.min(n.frameEnd,Math.max(n.frameStart,t));if(this.#r=o,!this.#o||n.clipStart===void 0||n.clipEnd===void 0)return;const r=(n.clipEnd-n.clipStart)/n.fps;this.#o.setTime(Math.max(0,Math.min(r-1e-4,(o-n.clipStart)/n.fps))),this.#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 o=n.scene;return!o||n.frameCurrent===t||(this.#s++,await Ra(`bpy.data.scenes[${JSON.stringify(o)}]`,"frame_current",t,void 0,!1),this.#t={...n,frameCurrent:t},this.#f()),t}get transport(){return this.#e}attachTo(t){this.#i?.(),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)}),o=t.onSettled(()=>{this.writeBookmark()}),r=()=>{o(),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,this.#t=null,this.#r=null;for(const t of this.#n.values())t.skeleton.dispose(),t.boneRoot.removeFromParent();this.#n.clear()}}const Wo=new wi;function Ei(e){return Wo.subscribe(e)}function Ni(){return Wo.version}export{Wo as a,Ni as b,Pi as c,Ei as s};