@volter/model-editor 0.5.66 → 0.5.67
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.
- package/dist/.vite/manifest.json +1022 -1006
- package/dist/assets/AudioViewer-DVXaSSYC.js +1 -0
- package/dist/assets/{BVHLoader-xUHWsz84.js → BVHLoader-msuIvJVn.js} +1 -1
- package/dist/assets/ColladaLoader-BpvxwqkB.js +3 -0
- package/dist/assets/EntityModelDocument-BtlQZcoU.js +1 -0
- package/dist/assets/EnvironmentAssetDocument-BH3zT9rt.js +1 -0
- package/dist/assets/FBXLoader-CsdO937F.js +1 -0
- package/dist/assets/{GameplaySessionTimeline-HJLZUV4Q.js → GameplaySessionTimeline-Dko95kB7.js} +10 -10
- package/dist/assets/ImageViewer-CZ_RMER2.js +1 -0
- package/dist/assets/{InspectorCanvasPreview-CLDhscy0.js → InspectorCanvasPreview-BLecDHpc.js} +1 -1
- package/dist/assets/InspectorObjectPreview-CSIWwJQE.js +1 -0
- package/dist/assets/JsonAssetDocument-CGYSeJyl.js +2 -0
- package/dist/assets/{LineSegments2-C8H20K8w.js → LineSegments2-BKEsgiC8.js} +2 -2
- package/dist/assets/LiveModuleDocument-CIvS-SUT.js +2 -0
- package/dist/assets/LutAssetDocument-BA70uU3w.js +1 -0
- package/dist/assets/{MTLLoader-C-rA0fNF.js → MTLLoader-DNh2pFDc.js} +2 -2
- package/dist/assets/ModelAssetDocument-D0lNEhOg.js +1 -0
- package/dist/assets/NonThreeAuthoringBootstrap-C0pCfkJ4.js +2 -0
- package/dist/assets/OBJLoader-DPi99VIm.js +5 -0
- package/dist/assets/Object3DDocumentToolbar-PGYkZEwr.js +1 -0
- package/dist/assets/Object3DPreview-BROKXSTC.js +2 -0
- package/dist/assets/OnlineAssetDetail-lEHnhdUS.js +1 -0
- package/dist/assets/OrbitControls-smIenN60.js +1 -0
- package/dist/assets/PLYLoader-Cx9Yc9xe.js +2 -0
- package/dist/assets/QuarksAssetDocument-C_8eG4KG.js +2 -0
- package/dist/assets/RectAreaLightUniformsLib-Iam8rS8R.js +1 -0
- package/dist/assets/STLLoader-BaJkM-k1.js +1 -0
- package/dist/assets/{ShaderAssetDocument-qlLeb2S3.js → ShaderAssetDocument-Gdp7OCfv.js} +5 -5
- package/dist/assets/SourceAssetViewer-l72u0hOa.js +1 -0
- package/dist/assets/StageHost-CdzuP0NS.js +1179 -0
- package/dist/assets/TDSLoader-BskhMiUy.js +1 -0
- package/dist/assets/ToolObject3DPreview-CU5klD6l.js +1 -0
- package/dist/assets/Toolbar-DI0LGx25.js +1 -0
- package/dist/assets/TransientHint-myZtSdd6.js +1 -0
- package/dist/assets/VideoViewer-z0JPXPKa.js +1 -0
- package/dist/assets/ViewportShadingMenu-CVU2bU_3.js +1 -0
- package/dist/assets/animation-mixers.service-DSIsxWG5.js +1 -0
- package/dist/assets/animation-timeline.utility-BEgDQC04.js +1 -0
- package/dist/assets/asset-editor-persistence-BtRQI8t6.js +1 -0
- package/dist/assets/bitmap-label-Ct4k6ehY.js +1 -0
- package/dist/assets/{blender-emscripten-engine-CEsWgnR7.js → blender-emscripten-engine-BeWFjMn-.js} +1 -1
- package/dist/assets/blender-node-editor.document-C_kpsARB.js +1 -0
- package/dist/assets/{blender-properties-tab-C5tUuCSv.js → blender-properties-tab-B_XBg6S8.js} +3 -3
- package/dist/assets/blender-runtime-host-CYhl4T9S.js +4 -0
- package/dist/assets/{blender-runtime-skin-DMq0XAvO.js → blender-runtime-skin-Bk6uXECD.js} +98 -51
- package/dist/assets/blender-runtime.document-CAPDRCvN.js +12 -0
- package/dist/assets/blender-timeline.document-CcEymQyL.js +1 -0
- package/dist/assets/blender-uv-editor.document-DSPvSEuE.js +1 -0
- package/dist/assets/blender-version.status-CEu7vCi3.js +1 -0
- package/dist/assets/{blender-wali-engine-D3iKpzn9.js → blender-wali-engine-da698rDf.js} +1 -1
- package/dist/assets/blender.command-BCb_c9lw.js +1 -0
- package/dist/assets/blender.keymap-_rF_vRX8.js +1 -0
- package/dist/assets/{blender.status-ujwGU6dU.js → blender.status-DrasQhJV.js} +1 -1
- package/dist/assets/{blender.style-CxfbTFcE.js → blender.style-DaIh9SiA.js} +1 -1
- package/dist/assets/{client-DNXj_opT.js → client-mkWk8S65.js} +1 -1
- package/dist/assets/content-bounds-_QWiKD5_.js +85 -0
- package/dist/assets/{hosted-asset-materialization-BXM49Qkc.js → hosted-asset-materialization-hUS3IhTD.js} +2 -2
- package/dist/assets/index-0Lm0Nf1M.css +1 -0
- package/dist/assets/{index-CJbYy-CF.js → index-7vd2obXq.js} +2 -2
- package/dist/assets/{index-DgapqSPi.js → index-BRLA7zdc.js} +1 -1
- package/dist/assets/{index-BtfYaG4D.js → index-CQG6JOSy.js} +18 -18
- package/dist/assets/{index-CanA16PU.js → index-CnvSS9lU.js} +1 -1
- package/dist/assets/{index-Bge9JUr6.js → index-DYNMP0kE.js} +1 -1
- package/dist/assets/index-Dm_h-T4x.js +1406 -0
- package/dist/assets/{index-gHZae-lw.js → index-Dz8qGBZc.js} +1 -1
- package/dist/assets/{index-BncK9THk.js → index-Fv4R0cYr.js} +1 -1
- package/dist/assets/{index-IEjydI9d.js → index-f-MQ14bP.js} +1 -1
- package/dist/assets/{index-D2LwEE0L.js → index-jib6KJY8.js} +6 -6
- package/dist/assets/{index-DUqP1RMl.js → index-ux8XhRyW.js} +1 -1
- package/dist/assets/{jsx-runtime-DPjLkJKQ.js → jsx-runtime-CAUTK36e.js} +1 -1
- package/dist/assets/layered-pick-CT4HlEpW.js +1 -0
- package/dist/assets/live-mixers-B-bwLZ7c.js +1 -0
- package/dist/assets/model-inspection-DDZE59vp.js +1 -0
- package/dist/assets/models.finder-Caf-3Yix.js +1 -0
- package/dist/assets/product-DbFrUS6F.js +1 -0
- package/dist/assets/properties-bone-constraints.inspector-DB3Rc_Hf.js +1 -0
- package/dist/assets/properties-bone.inspector-B7f7H_Co.js +1 -0
- package/dist/assets/properties-collection.inspector-JCtV3h3Y.js +1 -0
- package/dist/assets/properties-constraints.inspector-Cs8MwS-1.js +1 -0
- package/dist/assets/properties-data.inspector-DKGiHu8O.js +1 -0
- package/dist/assets/properties-material.inspector-Dc18RI13.js +1 -0
- package/dist/assets/properties-modifiers.inspector-DvGvXq2v.js +1 -0
- package/dist/assets/properties-object.inspector-Bl9nrytP.js +1 -0
- package/dist/assets/properties-output.inspector-B6QsU94n.js +1 -0
- package/dist/assets/properties-particles.inspector-B1dMnZSA.js +1 -0
- package/dist/assets/properties-physics.inspector-BwfNykfW.js +1 -0
- package/dist/assets/properties-render.inspector-KrL2EiTH.js +1 -0
- package/dist/assets/properties-scene.inspector-CewQnyRt.js +1 -0
- package/dist/assets/properties-texture.inspector-BITMzY-f.js +1 -0
- package/dist/assets/properties-view-layer.inspector-BpkDbmcb.js +1 -0
- package/dist/assets/properties-world.inspector-DLRH45Oj.js +1 -0
- package/dist/assets/{react-18-DyywM-Z2.js → react-18-D335xReo.js} +1 -1
- package/dist/assets/{react-story-board-B9V-j_Y5.js → react-story-board-CkaP4mEG.js} +1 -1
- package/dist/assets/{session-CsR0lApe.js → session-CTXsU1lK.js} +176 -1
- package/dist/assets/{spark.module-gG1EsWx8.js → spark.module-DMQ9J7rT.js} +11 -11
- package/dist/assets/stage-keyboard-BY7u9_MB.js +1 -0
- package/dist/assets/stage-overlay-set-DRFcVd27.js +1 -0
- package/dist/assets/stage-presence-markers-D2IpuOAY.js +1 -0
- package/dist/assets/stage-transform-tools-BGcIULoe.js +1 -0
- package/dist/assets/story-capture-RSWY8I8h.js +1 -0
- package/dist/assets/three-integration.service-0EyPpd5f.js +4 -0
- package/dist/assets/{three.module-ZILb6uB7.js → three.module-CrYDk-Xr.js} +1 -1
- package/dist/assets/transform-mode-request-Cz6fzydi.js +1 -0
- package/dist/assets/transport-strip-Co-ZDkf-.js +1 -0
- package/dist/assets/{vgai-shared-fontawesome-CFSkqz69.js → vgai-shared-fontawesome-2ZSGa7vM.js} +1 -1
- package/dist/assets/vgai-shared-jsx-dev-runtime-hkPLeIJV.js +1 -0
- package/dist/assets/vgai-shared-jsx-runtime-CUvvjEqj.js +1 -0
- package/dist/assets/{vgai-shared-react-dom-client-S0ozfl6_.js → vgai-shared-react-dom-client-CS681GK2.js} +1 -1
- package/dist/assets/{vgai-shared-three-DzfWDqlp.js → vgai-shared-three-CLJ0K3jQ.js} +1 -1
- package/dist/assets/viewport-door-BdL0u5rd.js +1 -0
- package/dist/assets/viewport-editor-controls-BYaAZ_Ku.js +1 -0
- package/dist/assets/viewport-surface-status-yS6CrXH7.js +24 -0
- package/dist/assets/{worker-B7zhIsFh.js → worker-CC9Ug5Ei.js} +1 -1
- package/dist/assets/world-documents-B5IWN-ng.js +3 -0
- package/dist/vgai-shared-react.json +4 -4
- package/dist/vgai-shared-three.json +1 -1
- package/dist-node/cli.js +248 -209
- package/dist-node/create.js +77 -77
- package/package.json +10 -10
- package/src/index.ts +1 -0
- package/dist/assets/AudioViewer-CRWsJVYN.js +0 -1
- package/dist/assets/ColladaLoader-Ccy_gHsu.js +0 -3
- package/dist/assets/EntityModelDocument-Dal8YnLK.js +0 -1
- package/dist/assets/EnvironmentAssetDocument-DFOFYX5v.js +0 -1
- package/dist/assets/FBXLoader-Dh0pOBW2.js +0 -1
- package/dist/assets/ImageViewer-BzqBpqL-.js +0 -1
- package/dist/assets/InspectorObjectPreview-BUZEp4xS.js +0 -1
- package/dist/assets/JsonAssetDocument-DCkqRS0N.js +0 -2
- package/dist/assets/LiveModuleDocument-CuOBVz3A.js +0 -2
- package/dist/assets/LutAssetDocument-IyEir1rq.js +0 -1
- package/dist/assets/ModelAssetDocument-DNStNyCc.js +0 -1
- package/dist/assets/NonThreeAuthoringBootstrap-BE15Wpmw.js +0 -2
- package/dist/assets/OBJLoader-CopWRneC.js +0 -5
- package/dist/assets/Object3DDocumentToolbar-5Dv_8caG.js +0 -1
- package/dist/assets/Object3DPreview-C09u9uQZ.js +0 -2
- package/dist/assets/OnlineAssetDetail-DOPUI1iu.js +0 -1
- package/dist/assets/OrbitControls-DrFzvAAB.js +0 -1
- package/dist/assets/PLYLoader-D_esTZ2f.js +0 -2
- package/dist/assets/QuarksAssetDocument-BbSJ970L.js +0 -2
- package/dist/assets/RectAreaLightUniformsLib-u1ciScuw.js +0 -1
- package/dist/assets/STLLoader-Cl5I0sAi.js +0 -1
- package/dist/assets/SourceAssetViewer-DwhuqbA4.js +0 -1
- package/dist/assets/StageHost-D-o8MsFS.js +0 -1122
- package/dist/assets/TDSLoader-KKBg8ef1.js +0 -1
- package/dist/assets/ToolObject3DPreview-ILbch3kN.js +0 -1
- package/dist/assets/Toolbar-DYJjJKTt.js +0 -1
- package/dist/assets/TransientHint-D94hsJSR.js +0 -1
- package/dist/assets/VideoViewer-Bx3FPbgE.js +0 -1
- package/dist/assets/ViewportShadingMenu-B3N6hSdN.js +0 -1
- package/dist/assets/animation-mixers.service-N9HxGOMf.js +0 -1
- package/dist/assets/asset-editor-persistence-DGD05u26.js +0 -1
- package/dist/assets/blender-node-editor.document-BT2M622g.js +0 -1
- package/dist/assets/blender-runtime-host-4ufXy47O.js +0 -4
- package/dist/assets/blender-runtime.document-DeFQQsF6.js +0 -8
- package/dist/assets/blender-timeline.document-BnlSdxy0.js +0 -1
- package/dist/assets/blender-uv-editor.document-UC-XeNn0.js +0 -1
- package/dist/assets/blender-version.status-BZP39oH7.js +0 -1
- package/dist/assets/blender.command-IGP5wuda.js +0 -1
- package/dist/assets/blender.keymap-GAQgeklK.js +0 -1
- package/dist/assets/browserAll-2r3AVaAO.js +0 -14
- package/dist/assets/canvas-preview-frames-CO60PDM7.js +0 -5
- package/dist/assets/index-B4bmKkgY.css +0 -1
- package/dist/assets/index-cpXNKgvz.js +0 -1498
- package/dist/assets/live-mixers-BRkRHd6g.js +0 -1
- package/dist/assets/material-preview.view-DqNcpd_b.js +0 -1
- package/dist/assets/model-inspection-JC6gbV8Q.js +0 -1
- package/dist/assets/models.finder-BplPGS4I.js +0 -1
- package/dist/assets/product-CfZaqLpw.js +0 -1
- package/dist/assets/properties-bone-constraints.inspector-Di8kNtAi.js +0 -1
- package/dist/assets/properties-bone.inspector-CqAIKNsE.js +0 -1
- package/dist/assets/properties-collection.inspector-DpHC_fXW.js +0 -1
- package/dist/assets/properties-constraints.inspector-C7G7NOZU.js +0 -1
- package/dist/assets/properties-data.inspector-D1sUUst6.js +0 -1
- package/dist/assets/properties-material.inspector-BUSjc8tl.js +0 -1
- package/dist/assets/properties-modifiers.inspector-Sq9bcfFz.js +0 -1
- package/dist/assets/properties-object.inspector-BzqiU_29.js +0 -1
- package/dist/assets/properties-output.inspector-BWpFqvfT.js +0 -1
- package/dist/assets/properties-particles.inspector-DO1KoaTz.js +0 -1
- package/dist/assets/properties-physics.inspector-BgkrTNSA.js +0 -1
- package/dist/assets/properties-render.inspector-BU5NOVoQ.js +0 -1
- package/dist/assets/properties-scene.inspector-DbMErJ48.js +0 -1
- package/dist/assets/properties-texture.inspector-toPpEwqp.js +0 -1
- package/dist/assets/properties-view-layer.inspector-COpx9iEK.js +0 -1
- package/dist/assets/properties-world.inspector-CxU0DrYX.js +0 -1
- package/dist/assets/react-three-rapier.esm-CN6t4A7c.js +0 -1
- package/dist/assets/stage-keyboard-CzlqI0nh.js +0 -1
- package/dist/assets/stage-overlay-set-DQeskS16.js +0 -1
- package/dist/assets/stage-presence-markers-S1lMOwIa.js +0 -1
- package/dist/assets/stage-transform-tools-Cqtv-ZQ1.js +0 -1
- package/dist/assets/story-capture-DmIUyEQn.js +0 -1
- package/dist/assets/story-mount-turn-2IYGgHob.js +0 -1
- package/dist/assets/story-pixi-preview-aw8xQhvF.js +0 -1
- package/dist/assets/story-three-preview-DDmMjlI8.js +0 -37
- package/dist/assets/transform-mode-request-DSPwviXs.js +0 -1
- package/dist/assets/vgai-shared-jsx-dev-runtime-DFDKL7fx.js +0 -1
- package/dist/assets/vgai-shared-jsx-runtime-DIqBpTut.js +0 -1
- package/dist/assets/viewport-pick-context-DkawXbEi.js +0 -1
- package/dist/assets/viewport-surface-status-DuININWe.js +0 -20
- package/dist/assets/webworkerAll-CqQUotBj.js +0 -101
- package/dist/assets/world-documents-DkBqH8VU.js +0 -3
|
@@ -0,0 +1,1179 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/spark.module-DMQ9J7rT.js","assets/three.module-CrYDk-Xr.js","assets/content-bounds-_QWiKD5_.js","assets/index-CQG6JOSy.js","assets/stage-transform-tools-BGcIULoe.js","assets/jsx-runtime-CAUTK36e.js","assets/_commonjsHelpers-D6-XlEtG.js","assets/index-Dm_h-T4x.js","assets/index-DaQZGF7d.js","assets/index-D_NuPfjr.js","assets/index-CtzuWnCS.js","assets/index-CinJrH5C.js","assets/index-jib6KJY8.js","assets/client-mkWk8S65.js","assets/index-0Lm0Nf1M.css","assets/three-integration.service-0EyPpd5f.js","assets/layered-pick-CT4HlEpW.js","assets/viewport-door-BdL0u5rd.js","assets/bitmap-label-Ct4k6ehY.js","assets/Toolbar-DI0LGx25.js","assets/transform-mode-request-Cz6fzydi.js","assets/viewport-surface-status-yS6CrXH7.js","assets/live-mixers-B-bwLZ7c.js","assets/model-inspection-DDZE59vp.js","assets/clip-planes-CnAI6DZn.js","assets/OrbitControls-smIenN60.js","assets/LineSegments2-BKEsgiC8.js","assets/viewport-editor-controls-BYaAZ_Ku.js","assets/editor-presentation-activity-C7SNSmTd.js","assets/transport-strip-Co-ZDkf-.js","assets/stage-overlay-set-DRFcVd27.js","assets/TransientHint-myZtSdd6.js","assets/ViewportShadingMenu-CVU2bU_3.js","assets/stage-keyboard-BY7u9_MB.js","assets/stage-presence-markers-D2IpuOAY.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{bD as Xr,bE as Qe,bF as aa,bG as la,bH as ca,bI as qn,bJ as $c,bK as ha,bL as Kc,bM as Ze,bN as cs,b7 as et,ax as Oi,bO as yn,z as eh,bP as Jn,s as Rr,bQ as da,bR as ua,bS as pa,bT as fa,al as vt,bU as th,bV as ih,bW as ma,bX as ga,v as Ti,i as mi,bY as sh,T as rh,bZ as nh,b_ as Vl,b$ as zi,am as ri,an as Pt,c0 as oh,c1 as ah,aS as Mi,c2 as lh,c3 as ch,c4 as hh,ak as ya,c5 as _a,c6 as Ul,c7 as dh,c8 as uh,c9 as va,ca as ph,cb as fh,cc as mh,ao as Mt,K as gh,cd as yh,ce as _h,cf as vh,cg as wh,ch as xh,ci as bh,cj as Sh,b2 as Mh,ck as jl,aQ as Ch,cl as Ph,cm as wa,cn as xa,co as ba,bf as Sa,cp as Ah,S as Eh,cq as zh,D as Ma,cr as Oh,cs as Th,ct as kh,cu as Ca,cv as Rh,cw as Ih,cx as Lh,cy as Fh,cz as Bh,a7 as Nh,cA as Hh,cB as Dh,bC as Vh,cC as Pa,Q as Uh,cD as jh,cE as Gh}from"./index-Dm_h-T4x.js";import{j as O}from"./jsx-runtime-CAUTK36e.js";import{i as Oe,s as qe,E as Z,j as gt,k as Yn,n as Wh,v as yr,o as Xh,p as uo,q as qh,r as Jh,t as Yh,g as Zh,u as Qh,w as $h,x as qs,y as Kh,z as Gl,A as ed,B as Aa,C as Zn,D as td,F as id,G as sd,H as rd,I as Wl,J as nd,K as od}from"./three-integration.service-0EyPpd5f.js";import{S as Xl,i as K,V as ad,O as ld,a as cd,w as hd,c as dd,s as Ea}from"./viewport-surface-status-yS6CrXH7.js";import{r as k}from"./index-DaQZGF7d.js";import"./index-CtzuWnCS.js";import{f as ud,c as li,C as za,h as pd,j as fd,s as Qn,v as md,b as gd,a as yd}from"./content-bounds-_QWiKD5_.js";import{s as _d,a as ql}from"./live-mixers-B-bwLZ7c.js";import{an as Jl,bP as qr,f as rt,n as Ir,bQ as vd,e as Ce,a2 as di,bR as po,bS as wd,aw as Yl,C as V,bK as xd,V as v,Q as pe,$ as nt,O as ui,a1 as qt,bT as ke,x as xe,B as Et,F as ps,c as T,bU as ni,b7 as st,bV as ss,d as At,E as Zl,a as Xt,X as fo,bW as bd,ai as Sd,G as Ve,bF as $n,b9 as mo,a0 as Li,b8 as Ql,bG as Md,bX as Cd,t as wt,a7 as go,ax as Pd,aZ as Ct,aj as Ad,bY as Ed,bH as zd,p as Od,q as Td,o as kd,D as $l,A as Kl,at as Fi,P as yo,Y as Jr,bZ as Rd,b_ as Id,b$ as zr,bJ as Ld,c0 as Fd,c1 as De,aO as Bd,c2 as it,S as fs,i as mt,J as Nd,K as Hd,c3 as Dd,c4 as Vd,j as Le,c5 as _o,g as je,c6 as ec,as as Ud,aG as jd,av as Gd,aK as Wd,aJ as tc,L as vo,s as Oa,c7 as Xd,bL as Ie,aR as qd,c8 as Jd,c9 as Yd,ca as Zd,cb as Qd,cc as $d,cd as Kd,ce as Ta,b4 as ic,cf as ka,bN as eu,W as Ra,H as tu,bD as iu,y as su,ar as ru,ag as Ia}from"./three.module-CrYDk-Xr.js";import{t as oi,r as La,c as Fa}from"./viewport-door-BdL0u5rd.js";import{a as Bi,i as nu,c as ou,b as au,d as lu,e as cu}from"./model-inspection-DDZE59vp.js";import"./index-jib6KJY8.js";import{E as Ba,a as Na,f as hu}from"./clip-planes-CnAI6DZn.js";import{O as du}from"./OrbitControls-smIenN60.js";import{b as Lr,L as Fr,a as Br}from"./LineSegments2-BKEsgiC8.js";import{s as uu}from"./viewport-editor-controls-BYaAZ_Ku.js";import{s as pu,i as _n}from"./editor-presentation-activity-C7SNSmTd.js";import{T as fu}from"./transport-strip-Co-ZDkf-.js";const sc=30;function rc(o,e,t){return o<e?e:o>t?t:o}function mu(o,e){const t=o.animations;if(t.length===0)return null;const i=new Jl(o);let s=t[0];if(!s)return null;const r=a=>{i.stopAllAction();const l=i.clipAction(a);l.paused=!1,l.play(),s=a};r(s);const n=e.attach({id:o.uuid,label:o.name||s.name||"Clip",range:()=>({start:0,end:s?.duration??0,fps:sc}),seek:a=>{i.setTime(rc(a,0,s?.duration??0))},clips:()=>t.map(a=>({id:a.name,label:a.name})),setClip:a=>{const l=t.find(c=>c.name===a);l&&r(l)}});return()=>{n(),i.stopAllAction(),i.uncacheRoot(o)}}function gu(o,e){const t=ql(o);if(!t)return null;let i=t.clips.values().next().value;if(!i)return null;const s=n=>{t.mixer.stopAllAction();const a=t.mixer.clipAction(n);a.paused=!1,a.play(),i=n};return e.attach({id:o.uuid,label:o.name||i.name||"Animation",range:()=>({start:0,end:i?.duration??0,fps:sc}),seek:n=>{t.mixer.setTime(rc(n,0,i?.duration??0))},clips:()=>[...t.clips.entries()].map(([n,a])=>({id:n,label:a.name||n})),setClip:n=>{const a=t.clips.get(n);a&&s(a)}})}function Ha(o,e,t={}){const i=new Map,s=()=>{const a=new Set;(typeof o=="function"?o():o)?.traverse(c=>{if(i.has(c.uuid)){a.add(c.uuid);return}const h=gu(c,e)??mu(c,e);h&&(i.set(c.uuid,h),a.add(c.uuid))});for(const[c,h]of[...i])a.has(c)||(h(),i.delete(c))};s();const r=t.rescanOnLiveMixers,n=r?_d(()=>{r()&&s()}):()=>{};return{refresh:s,dispose:()=>{n();for(const a of i.values())a();i.clear()}}}let Ii=0,Kn=[];function yu(){Ii+=1}function _u(){if(Ii=Math.max(0,Ii-1),Ii===0){const o=Kn;Kn=[];for(const e of o)e()}}function vu(){return Ii>0}function wu(){return Ii===0?Promise.resolve():new Promise(o=>{Kn.push(o)})}const Dt=()=>globalThis.performance?.now()??Date.now();function xu(o,e){return o.length===0?0:o[Math.min(o.length-1,Math.floor((o.length-1)*e))]??0}function bu(o=!1){const e=new Set,t=[],i=new Map,s=new Map,r=new Map;let n=[],a=[],l=o,c=!1,h=!1,d=0,p=0,u=0;const f=[];let m=0,y=0,_={gpuMs:null,drawCalls:0,triangles:0,geometries:0,textures:0,renderPasses:null},x={enabled:l,recording:h,fps:0,cpuMs:0,p95Ms:0,p99Ms:0,frames:[],phases:[],systems:[],components:[],render:_};function S(){const w=t.at(-1),C=t.slice();let b;const M=P=>(b??=C.map(E=>E.intervalMs).filter(E=>E>0).sort((E,R)=>E-R),xu(b,P));x={enabled:l,recording:h,fps:w?.intervalMs?1e3/w.intervalMs:0,cpuMs:w?.cpuMs??0,get p95Ms(){return M(.95)},get p99Ms(){return M(.99)},frames:C,phases:w?.phases??[],systems:[...s].map(([P,E])=>({name:P,ms:E})).sort((P,E)=>E.ms-P.ms),components:[...r].map(([P,E])=>({name:P,ms:E})).sort((P,E)=>E.ms-P.ms),render:_};for(const P of e)P()}return{get enabled(){return l},set enabled(w){l!==w&&(l=w,w&&!c&&(u=0),S())},get telemetryEnabled(){return c},set telemetryEnabled(w){if(c===w)return;const C=!l&&!c;c=w,w&&C&&(u=0),S()},get recording(){return h},startRecording(){const w=!l&&!c;l=!0,w&&(u=0),h=!0,t.length=0,S()},stopRecording(){h=!1,S()},clear(){t.length=0,S()},beginFrame(){!l&&!c||(i.clear(),s.clear(),r.clear(),n=[],a=[],f.length=0,_={gpuMs:null,drawCalls:0,triangles:0,geometries:0,textures:0,renderPasses:null},p=Dt())},beginPhase(){l&&f.push(Dt())},endPhase(w){if(!l)return;const C=f.pop()??p,b=Dt()-C,M=i.get(w);i.set(w,{ms:(M?.ms??0)+b,startMs:M?.startMs??C-p}),h&&performance.measure(`vgai.phase.${w}`,{start:C,duration:b})},systemObserver:{beginSystem(){l&&(m=Dt())},endSystem(w,C,b){if(!l)return;const M=Dt(),P=`${w} / ${C} / ${b}`;s.set(P,(s.get(P)??0)+M-m),n.push({name:P,phase:C,startMs:m-p,ms:M-m})}},beginComponent(){h&&(y=Dt())},endComponent(w,C=""){if(!h)return;const b=Dt();r.set(w,(r.get(w)??0)+b-y),a.push({name:w,phase:C,startMs:y-p,ms:b-y})},reportRender(w){l&&(_={gpuMs:w.gpuMs??_.gpuMs,drawCalls:_.drawCalls+w.drawCalls,triangles:_.triangles+w.triangles,geometries:_.geometries+w.geometries,textures:_.textures+w.textures,renderPasses:w.renderPasses===void 0?_.renderPasses:(_.renderPasses??0)+w.renderPasses})},endFrame(){if(!l&&!c)return;const w=Dt(),C=u===0?0:p-u;u=p;const b={id:++d,timestamp:w,intervalMs:C,cpuMs:w-p,phases:[...i].map(([M,{ms:P,startMs:E}])=>({name:M,ms:P,startMs:E})).sort((M,P)=>P.ms-M.ms),systems:n.slice(),components:a.slice(),render:{..._}};t.push(b),t.length>600&&t.splice(0,t.length-600),h&&performance.measure("vgai.frame",{start:p,duration:b.cpuMs}),S()},subscribe(w){return e.add(w),()=>{e.delete(w)}},getSnapshot(){return x},exportJSON(){return JSON.stringify({version:2,capturedAt:new Date().toISOString(),frames:t},null,2)}}}const nc=256;function Su(o){const e=Math.min(1,Math.max(0,o));return e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055}function vn(o,e,t){const i=Math.hypot(o,e,t)||1;return[o/i,e/i,t/i]}function Mu(o=nc){const e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d");if(!t)return e;const i=t.createImageData(o,o),s=vn(-.45,.62,.64),r=vn(.65,-.35,.5),n=vn(s[0],s[1],s[2]+1),a=[.7,.69,.68],l=[.34,.4,.52],c=[.85,.88,1];for(let h=0;h<o;h++)for(let d=0;d<o;d++){const p=(d+.5)/o/.5-1,u=1-(h+.5)/o/.5,f=p*p+u*u,m=f>1,y=m?1/Math.sqrt(f):1,_=p*y,x=u*y,S=m?0:Math.sqrt(Math.max(0,1-f)),w=Math.max(0,_*s[0]+x*s[1]+S*s[2]),C=Math.max(0,_*r[0]+x*r[1]+S*r[2]),b=Math.max(0,_*n[0]+x*n[1]+S*n[2])**42*.5,M=(1-S)**3.2*.4,P=(h*o+d)*4;for(let E=0;E<3;E++){const R=a[E]*(.16+.8*w)+l[E]*.3*C+c[E]*M+b;i.data[P+E]=Math.round(Su(R)*255)}i.data[P+3]=255}return t.putImageData(i,0,0),e}function Cu(o=nc){const e=new qr(Mu(o));return e.colorSpace=rt,e.minFilter=Ir,e.magFilter=Ir,e.generateMipmaps=!1,e.needsUpdate=!0,e}function Pu(o){return o.color?.clone()??new V(12502993)}function wn(o,e){return o[e]??null}class Au{_derived=new Map;_normals=new vd;_matcap=null;_matcapTexture=null;_overdraw=new Ce({color:16777215,transparent:!0,opacity:.08,depthTest:!1,depthWrite:!1,blending:po,side:di,toneMapped:!1});render(e,t,i,s=()=>!0){if(t==="solid"||t==="preview"||t==="rendered"){i();return}const r=[];e.traverse(n=>{const a=n;!a.isMesh||!a.material||!s(a)||(r.push({mesh:a,material:a.material}),a.material=Array.isArray(a.material)?a.material.map(l=>this._materialFor(l,t)):this._materialFor(a.material,t))});try{i()}finally{for(const{mesh:n,material:a}of r)n.material=a}}dispose(){for(const e of this._derived.values())e.clay.dispose(),e.unlit.dispose(),e.wireframe.dispose();this._derived.clear(),this._normals.dispose(),this._overdraw.dispose(),this._matcap?.dispose(),this._matcapTexture?.dispose(),this._matcap=null,this._matcapTexture=null}_materialFor(e,t){if(t==="normals")return this._normals;if(t==="overdraw")return this._overdraw;if(t==="matcap")return this._matcap||(this._matcapTexture=Cu(),this._matcap=new wd({matcap:this._matcapTexture,toneMapped:!1})),this._matcap;let i=this._derived.get(e);if(!i){const s={color:Pu(e),map:wn(e,"map"),alphaMap:wn(e,"alphaMap"),alphaTest:e.alphaTest,opacity:e.opacity,transparent:e.transparent,side:e.side,depthTest:e.depthTest,depthWrite:e.depthWrite,vertexColors:!!e.vertexColors,fog:e.fog??!0};i={clay:new Yl({color:11450048,roughness:.82,metalness:0,flatShading:!0,alphaMap:wn(e,"alphaMap"),alphaTest:e.alphaTest,opacity:e.opacity,transparent:e.transparent,side:e.side,depthTest:e.depthTest,depthWrite:e.depthWrite}),unlit:new Ce(s),wireframe:new Ce({...s,wireframe:!0})},this._derived.set(e,i)}return i[t]}}function Nr(o){const e=Oe(o,"constraints");return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&typeof t.getSnapshot=="function"&&!!t.config):[]}function us(o){const e=Oe(o,"reflectionProbe");if(!e||typeof e!="object")return null;const t=e;return t.config&&typeof t.recapture=="function"&&typeof t.getSnapshot=="function"?e:null}function eo(o){const e=Oe(o,"triggerVolume");if(!e||typeof e!="object")return null;const{radius:t}=e;return typeof t=="number"&&Number.isFinite(t)&&t>0?{radius:t}:null}const ii=new nt,Re=new v,Vt=new v,ge=new pe,Da={X:new v(1,0,0),Y:new v(0,1,0),Z:new v(0,0,1)},xn={type:"change"},Va={type:"mouseDown",mode:null},Ua={type:"mouseUp",mode:null},ja={type:"objectChange"};let bn=class extends xd{constructor(e,t=null){super(void 0,t);const i=new Ru(this);this._root=i;const s=new Iu;this._gizmo=s,i.add(s);const r=new Lu;this._plane=r,i.add(r);const n=this;function a(S,w){let C=w;Object.defineProperty(n,S,{get:function(){return C!==void 0?C:w},set:function(b){C!==b&&(C=b,r[S]=b,s[S]=b,n.dispatchEvent({type:S+"-changed",value:b}),n.dispatchEvent(xn))}}),n[S]=w,r[S]=w,s[S]=w}a("camera",e),a("object",void 0),a("enabled",!0),a("axis",null),a("mode","translate"),a("translationSnap",null),a("rotationSnap",null),a("scaleSnap",null),a("space","world"),a("size",1),a("dragging",!1),a("showX",!0),a("showY",!0),a("showZ",!0),a("minX",-1/0),a("maxX",1/0),a("minY",-1/0),a("maxY",1/0),a("minZ",-1/0),a("maxZ",1/0);const l=new v,c=new v,h=new pe,d=new pe,p=new v,u=new pe,f=new v,m=new v,y=new v,_=0,x=new v;a("worldPosition",l),a("worldPositionStart",c),a("worldQuaternion",h),a("worldQuaternionStart",d),a("cameraPosition",p),a("cameraQuaternion",u),a("pointStart",f),a("pointEnd",m),a("rotationAxis",y),a("rotationAngle",_),a("eye",x),this._offset=new v,this._startNorm=new v,this._endNorm=new v,this._cameraScale=new v,this._parentPosition=new v,this._parentQuaternion=new pe,this._parentQuaternionInv=new pe,this._parentScale=new v,this._worldScaleStart=new v,this._worldQuaternionInv=new pe,this._worldScale=new v,this._positionStart=new v,this._quaternionStart=new pe,this._scaleStart=new v,this._getPointer=Eu.bind(this),this._onPointerDown=Ou.bind(this),this._onPointerHover=zu.bind(this),this._onPointerMove=Tu.bind(this),this._onPointerUp=ku.bind(this),t!==null&&this.connect(t)}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto"}getHelper(){return this._root}pointerHover(e){if(this.object===void 0||this.dragging===!0)return;e!==null&&ii.setFromCamera(e,this.camera);const t=Sn(this._gizmo.picker[this.mode],ii);t?this.axis=t.object.name:this.axis=null}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e!=null&&e.button!==0)&&this.axis!==null){e!==null&&ii.setFromCamera(e,this.camera);const t=Sn(this._plane,ii,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,Va.mode=this.mode,this.dispatchEvent(Va)}}pointerMove(e){const t=this.axis,i=this.mode,s=this.object;let r=this.space;if(i==="scale"?r="local":(t==="E"||t==="XYZE"||t==="XYZ")&&(r="world"),s===void 0||t===null||this.dragging===!1||e!==null&&e.button!==-1)return;e!==null&&ii.setFromCamera(e,this.camera);const n=Sn(this._plane,ii,!0);if(n){if(this.pointEnd.copy(n.point).sub(this.worldPositionStart),i==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),r==="local"&&t!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf("X")===-1&&(this._offset.x=0),t.indexOf("Y")===-1&&(this._offset.y=0),t.indexOf("Z")===-1&&(this._offset.z=0),r==="local"&&t!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),s.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(r==="local"&&(s.position.applyQuaternion(ge.copy(this._quaternionStart).invert()),t.search("X")!==-1&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.position.applyQuaternion(this._quaternionStart)),r==="world"&&(s.parent&&s.position.add(Re.setFromMatrixPosition(s.parent.matrixWorld)),t.search("X")!==-1&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.parent&&s.position.sub(Re.setFromMatrixPosition(s.parent.matrixWorld)))),s.position.x=Math.max(this.minX,Math.min(this.maxX,s.position.x)),s.position.y=Math.max(this.minY,Math.min(this.maxY,s.position.y)),s.position.z=Math.max(this.minZ,Math.min(this.maxZ,s.position.z));else if(i==="scale"){if(t.search("XYZ")!==-1){let a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),Vt.set(a,a,a)}else Re.copy(this.pointStart),Vt.copy(this.pointEnd),Re.applyQuaternion(this._worldQuaternionInv),Vt.applyQuaternion(this._worldQuaternionInv),Vt.divide(Re),t.search("X")===-1&&(Vt.x=1),t.search("Y")===-1&&(Vt.y=1),t.search("Z")===-1&&(Vt.z=1);s.scale.copy(this._scaleStart).multiply(Vt),this.scaleSnap&&(t.search("X")!==-1&&(s.scale.x=Math.round(s.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Y")!==-1&&(s.scale.y=Math.round(s.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Z")!==-1&&(s.scale.z=Math.round(s.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(i==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const a=20/this.worldPosition.distanceTo(Re.setFromMatrixPosition(this.camera.matrixWorld));let l=!1;t==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(Re.copy(this.rotationAxis).cross(this.eye))*a):(t==="X"||t==="Y"||t==="Z")&&(this.rotationAxis.copy(Da[t]),Re.copy(Da[t]),r==="local"&&Re.applyQuaternion(this.worldQuaternion),Re.cross(this.eye),Re.length()===0?l=!0:this.rotationAngle=this._offset.dot(Re.normalize())*a),(t==="E"||l)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),r==="local"&&t!=="E"&&t!=="XYZE"?(s.quaternion.copy(this._quaternionStart),s.quaternion.multiply(ge.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),s.quaternion.copy(ge.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),s.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(xn),this.dispatchEvent(ja)}}pointerUp(e){e!==null&&e.button!==0||(this.dragging&&this.axis!==null&&(Ua.mode=this.mode,this.dispatchEvent(Ua)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(e){return this.object=e,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(xn),this.dispatchEvent(ja),this.pointStart.copy(this.pointEnd))}getRaycaster(){return ii}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}setColors(e,t,i,s){const r=this._gizmo.materialLib;r.xAxis.color.set(e),r.yAxis.color.set(t),r.zAxis.color.set(i),r.active.color.set(s),r.xAxisTransparent.color.set(e),r.yAxisTransparent.color.set(t),r.zAxisTransparent.color.set(i),r.activeTransparent.color.set(s),r.xAxis._color&&r.xAxis._color.set(e),r.yAxis._color&&r.yAxis._color.set(t),r.zAxis._color&&r.zAxis._color.set(i),r.active._color&&r.active._color.set(s),r.xAxisTransparent._color&&r.xAxisTransparent._color.set(e),r.yAxisTransparent._color&&r.yAxisTransparent._color.set(t),r.zAxisTransparent._color&&r.zAxisTransparent._color.set(i),r.activeTransparent._color&&r.activeTransparent._color.set(s)}};function Eu(o){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:o.button};{const e=this.domElement.getBoundingClientRect();return{x:(o.clientX-e.left)/e.width*2-1,y:-(o.clientY-e.top)/e.height*2+1,button:o.button}}}function zu(o){if(this.enabled)switch(o.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(o));break}}function Ou(o){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(o.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(o)),this.pointerDown(this._getPointer(o)))}function Tu(o){this.enabled&&this.pointerMove(this._getPointer(o))}function ku(o){this.enabled&&(this.domElement.releasePointerCapture(o.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(o)))}function Sn(o,e,t){const i=e.intersectObject(o,!0);for(let s=0;s<i.length;s++)if(i[s].object.visible||t)return i[s];return!1}const _r=new Zl,ue=new v(0,1,0),Ga=new v(0,0,0),Wa=new Xt,vr=new pe,Or=new pe,ut=new v,Xa=new Xt,hs=new v(1,0,0),si=new v(0,1,0),ds=new v(0,0,1),wr=new v,rs=new v,ns=new v;class Ru extends ui{constructor(e){super(),this.isTransformControlsRoot=!0,this.controls=e,this.visible=!1}updateMatrixWorld(e){const t=this.controls;t.object!==void 0&&(t.object.updateMatrixWorld(),t.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):t.object.parent.matrixWorld.decompose(t._parentPosition,t._parentQuaternion,t._parentScale),t.object.matrixWorld.decompose(t.worldPosition,t.worldQuaternion,t._worldScale),t._parentQuaternionInv.copy(t._parentQuaternion).invert(),t._worldQuaternionInv.copy(t.worldQuaternion).invert()),t.camera.updateMatrixWorld(),t.camera.matrixWorld.decompose(t.cameraPosition,t.cameraQuaternion,t._cameraScale),t.camera.isOrthographicCamera?t.camera.getWorldDirection(t.eye).negate():t.eye.copy(t.cameraPosition).sub(t.worldPosition).normalize(),super.updateMatrixWorld(e)}dispose(){this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}}class Iu extends ui{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const e=new Ce({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new qt({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=e.clone();i.opacity=.15;const s=t.clone();s.opacity=.5;const r=e.clone();r.color.setHex(16711680);const n=e.clone();n.color.setHex(65280);const a=e.clone();a.color.setHex(255);const l=e.clone();l.color.setHex(16711680),l.opacity=.5;const c=e.clone();c.color.setHex(65280),c.opacity=.5;const h=e.clone();h.color.setHex(255),h.opacity=.5;const d=e.clone();d.opacity=.25;const p=e.clone();p.color.setHex(16776960),p.opacity=.25;const u=e.clone();u.color.setHex(16776960);const f=e.clone();f.color.setHex(7895160),this.materialLib={xAxis:r,yAxis:n,zAxis:a,active:u,xAxisTransparent:l,yAxisTransparent:c,zAxisTransparent:h,activeTransparent:p};const m=new ke(0,.04,.1,12);m.translate(0,.05,0);const y=new xe(.08,.08,.08);y.translate(0,.04,0);const _=new Et;_.setAttribute("position",new ps([0,0,0,1,0,0],3));const x=new ke(.0075,.0075,.5,3);x.translate(0,.25,0);function S(X,re){const j=new ss(X,.0075,3,64,re*Math.PI*2);return j.rotateY(Math.PI/2),j.rotateX(Math.PI/2),j}function w(){const X=new Et;return X.setAttribute("position",new ps([0,0,0,1,1,1],3)),X}const C={X:[[new T(m,r),[.5,0,0],[0,0,-Math.PI/2]],[new T(m,r),[-.5,0,0],[0,0,Math.PI/2]],[new T(x,r),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new T(m,n),[0,.5,0]],[new T(m,n),[0,-.5,0],[Math.PI,0,0]],[new T(x,n)]],Z:[[new T(m,a),[0,0,.5],[Math.PI/2,0,0]],[new T(m,a),[0,0,-.5],[-Math.PI/2,0,0]],[new T(x,a),null,[Math.PI/2,0,0]]],XYZ:[[new T(new ni(.1,0),d),[0,0,0]]],XY:[[new T(new xe(.15,.15,.01),h),[.15,.15,0]]],YZ:[[new T(new xe(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new T(new xe(.15,.15,.01),c),[.15,0,.15],[-Math.PI/2,0,0]]]},b={X:[[new T(new ke(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new T(new ke(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new T(new ke(.2,0,.6,4),i),[0,.3,0]],[new T(new ke(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new T(new ke(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new T(new ke(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new T(new ni(.2,0),i)]],XY:[[new T(new xe(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new T(new xe(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new T(new xe(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]]},M={START:[[new T(new ni(.01,2),s),null,null,null,"helper"]],END:[[new T(new ni(.01,2),s),null,null,null,"helper"]],DELTA:[[new st(w(),s),null,null,null,"helper"]],X:[[new st(_,s),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new st(_,s),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new st(_,s),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},P={XYZE:[[new T(S(.5,1),f),null,[0,Math.PI/2,0]]],X:[[new T(S(.5,.5),r)]],Y:[[new T(S(.5,.5),n),null,[0,0,-Math.PI/2]]],Z:[[new T(S(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new T(S(.75,1),p),null,[0,Math.PI/2,0]]]},E={AXIS:[[new st(_,s),[-1e3,0,0],null,[1e6,1,1],"helper"]]},R={XYZE:[[new T(new At(.25,10,8),i)]],X:[[new T(new ss(.5,.1,4,24),i),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new T(new ss(.5,.1,4,24),i),[0,0,0],[Math.PI/2,0,0]]],Z:[[new T(new ss(.5,.1,4,24),i),[0,0,0],[0,0,-Math.PI/2]]],E:[[new T(new ss(.75,.1,2,24),i)]]},N={X:[[new T(y,r),[.5,0,0],[0,0,-Math.PI/2]],[new T(x,r),[0,0,0],[0,0,-Math.PI/2]],[new T(y,r),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new T(y,n),[0,.5,0]],[new T(x,n)],[new T(y,n),[0,-.5,0],[0,0,Math.PI]]],Z:[[new T(y,a),[0,0,.5],[Math.PI/2,0,0]],[new T(x,a),[0,0,0],[Math.PI/2,0,0]],[new T(y,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new T(new xe(.15,.15,.01),h),[.15,.15,0]]],YZ:[[new T(new xe(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new T(new xe(.15,.15,.01),c),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new T(new xe(.1,.1,.1),d)]]},se={X:[[new T(new ke(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new T(new ke(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new T(new ke(.2,0,.6,4),i),[0,.3,0]],[new T(new ke(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new T(new ke(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new T(new ke(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new T(new xe(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new T(new xe(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new T(new xe(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new T(new xe(.2,.2,.2),i),[0,0,0]]]},ye={X:[[new st(_,s),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new st(_,s),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new st(_,s),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function q(X){const re=new ui;for(const j in X)for(let $=X[j].length;$--;){const J=X[j][$][0].clone(),ne=X[j][$][1],Q=X[j][$][2],fe=X[j][$][3],Ee=X[j][$][4];J.name=j,J.tag=Ee,ne&&J.position.set(ne[0],ne[1],ne[2]),Q&&J.rotation.set(Q[0],Q[1],Q[2]),fe&&J.scale.set(fe[0],fe[1],fe[2]),J.updateMatrix();const be=J.geometry.clone();be.applyMatrix4(J.matrix),J.geometry=be,J.renderOrder=1/0,J.position.set(0,0,0),J.rotation.set(0,0,0),J.scale.set(1,1,1),re.add(J)}return re}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=q(C)),this.add(this.gizmo.rotate=q(P)),this.add(this.gizmo.scale=q(N)),this.add(this.picker.translate=q(b)),this.add(this.picker.rotate=q(R)),this.add(this.picker.scale=q(se)),this.add(this.helper.translate=q(M)),this.add(this.helper.rotate=q(E)),this.add(this.helper.scale=q(ye)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){const i=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:Or;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let s=[];s=s.concat(this.picker[this.mode].children),s=s.concat(this.gizmo[this.mode].children),s=s.concat(this.helper[this.mode].children);for(let r=0;r<s.length;r++){const n=s[r];n.visible=!0,n.rotation.set(0,0,0),n.position.copy(this.worldPosition);let a;if(this.camera.isOrthographicCamera?a=(this.camera.top-this.camera.bottom)/this.camera.zoom:a=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),n.scale.set(1,1,1).multiplyScalar(a*this.size/4),n.tag==="helper"){n.visible=!1,n.name==="AXIS"?(n.visible=!!this.axis,this.axis==="X"&&(ge.setFromEuler(_r.set(0,0,0)),n.quaternion.copy(i).multiply(ge),Math.abs(ue.copy(hs).applyQuaternion(i).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Y"&&(ge.setFromEuler(_r.set(0,0,Math.PI/2)),n.quaternion.copy(i).multiply(ge),Math.abs(ue.copy(si).applyQuaternion(i).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Z"&&(ge.setFromEuler(_r.set(0,Math.PI/2,0)),n.quaternion.copy(i).multiply(ge),Math.abs(ue.copy(ds).applyQuaternion(i).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="XYZE"&&(ge.setFromEuler(_r.set(0,Math.PI/2,0)),ue.copy(this.rotationAxis),n.quaternion.setFromRotationMatrix(Wa.lookAt(Ga,ue,si)),n.quaternion.multiply(ge),n.visible=this.dragging),this.axis==="E"&&(n.visible=!1)):n.name==="START"?(n.position.copy(this.worldPositionStart),n.visible=this.dragging):n.name==="END"?(n.position.copy(this.worldPosition),n.visible=this.dragging):n.name==="DELTA"?(n.position.copy(this.worldPositionStart),n.quaternion.copy(this.worldQuaternionStart),Re.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),Re.applyQuaternion(this.worldQuaternionStart.clone().invert()),n.scale.copy(Re),n.visible=this.dragging):(n.quaternion.copy(i),this.dragging?n.position.copy(this.worldPositionStart):n.position.copy(this.worldPosition),this.axis&&(n.visible=this.axis.search(n.name)!==-1));continue}n.quaternion.copy(i),this.mode==="translate"||this.mode==="scale"?(n.name==="X"&&Math.abs(ue.copy(hs).applyQuaternion(i).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Y"&&Math.abs(ue.copy(si).applyQuaternion(i).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Z"&&Math.abs(ue.copy(ds).applyQuaternion(i).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XY"&&Math.abs(ue.copy(ds).applyQuaternion(i).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="YZ"&&Math.abs(ue.copy(hs).applyQuaternion(i).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XZ"&&Math.abs(ue.copy(si).applyQuaternion(i).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1)):this.mode==="rotate"&&(vr.copy(i),ue.copy(this.eye).applyQuaternion(ge.copy(i).invert()),n.name.search("E")!==-1&&n.quaternion.setFromRotationMatrix(Wa.lookAt(this.eye,Ga,si)),n.name==="X"&&(ge.setFromAxisAngle(hs,Math.atan2(-ue.y,ue.z)),ge.multiplyQuaternions(vr,ge),n.quaternion.copy(ge)),n.name==="Y"&&(ge.setFromAxisAngle(si,Math.atan2(ue.x,ue.z)),ge.multiplyQuaternions(vr,ge),n.quaternion.copy(ge)),n.name==="Z"&&(ge.setFromAxisAngle(ds,Math.atan2(ue.y,ue.x)),ge.multiplyQuaternions(vr,ge),n.quaternion.copy(ge))),n.visible=n.visible&&(n.name.indexOf("X")===-1||this.showX),n.visible=n.visible&&(n.name.indexOf("Y")===-1||this.showY),n.visible=n.visible&&(n.name.indexOf("Z")===-1||this.showZ),n.visible=n.visible&&(n.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),n.material._color=n.material._color||n.material.color.clone(),n.material._opacity=n.material._opacity||n.material.opacity,n.material.color.copy(n.material._color),n.material.opacity=n.material._opacity,this.enabled&&this.axis&&(n.name===this.axis?(n.material.color.copy(this.materialLib.active.color),n.material.opacity=1):this.axis.split("").some(function(l){return n.name===l})&&(n.material.color.copy(this.materialLib.active.color),n.material.opacity=1))}super.updateMatrixWorld(e)}}class Lu extends T{constructor(){super(new fo(1e5,1e5,2,2),new Ce({visible:!1,wireframe:!0,side:di,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(t="local"),wr.copy(hs).applyQuaternion(t==="local"?this.worldQuaternion:Or),rs.copy(si).applyQuaternion(t==="local"?this.worldQuaternion:Or),ns.copy(ds).applyQuaternion(t==="local"?this.worldQuaternion:Or),ue.copy(rs),this.mode){case"translate":case"scale":switch(this.axis){case"X":ue.copy(this.eye).cross(wr),ut.copy(wr).cross(ue);break;case"Y":ue.copy(this.eye).cross(rs),ut.copy(rs).cross(ue);break;case"Z":ue.copy(this.eye).cross(ns),ut.copy(ns).cross(ue);break;case"XY":ut.copy(ns);break;case"YZ":ut.copy(wr);break;case"XZ":ue.copy(ns),ut.copy(rs);break;case"XYZ":case"E":ut.set(0,0,0);break}break;case"rotate":default:ut.set(0,0,0)}ut.length()===0?this.quaternion.copy(this.cameraQuaternion):(Xa.lookAt(Re.set(0,0,0),ut,ue),this.quaternion.setFromRotationMatrix(Xa)),super.updateMatrixWorld(e)}}const Te=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let qa=1234567;const oc=Math.PI/180,ac=180/Math.PI;function Fu(){const o=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Te[o&255]+Te[o>>8&255]+Te[o>>16&255]+Te[o>>24&255]+"-"+Te[e&255]+Te[e>>8&255]+"-"+Te[e>>16&15|64]+Te[e>>24&255]+"-"+Te[t&63|128]+Te[t>>8&255]+"-"+Te[t>>16&255]+Te[t>>24&255]+Te[i&255]+Te[i>>8&255]+Te[i>>16&255]+Te[i>>24&255]).toLowerCase()}function yt(o,e,t){return Math.max(e,Math.min(t,o))}function lc(o,e){return(o%e+e)%e}function Bu(o,e,t,i,s){return i+(o-e)*(s-i)/(t-e)}function Nu(o,e,t){return o!==e?(t-o)/(e-o):0}function cc(o,e,t){return(1-t)*o+t*e}function Hu(o,e,t,i){return cc(o,e,1-Math.exp(-t*i))}function Du(o,e=1){return e-Math.abs(lc(o,e*2)-e)}function Vu(o,e,t){return o<=e?0:o>=t?1:(o=(o-e)/(t-e),o*o*(3-2*o))}function Uu(o,e,t){return o<=e?0:o>=t?1:(o=(o-e)/(t-e),o*o*o*(o*(o*6-15)+10))}function ju(o,e){return o+Math.floor(Math.random()*(e-o+1))}function Gu(o,e){return o+Math.random()*(e-o)}function Wu(o){return o*(.5-Math.random())}function Xu(o){o!==void 0&&(qa=o);let e=qa+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function qu(o){return o*oc}function Ju(o){return o*ac}function Yu(o){return(o&o-1)===0&&o!==0}function Zu(o){return Math.pow(2,Math.ceil(Math.log(o)/Math.LN2))}function Qu(o){return Math.pow(2,Math.floor(Math.log(o)/Math.LN2))}function $u(o,e,t,i,s){const r=Math.cos,n=Math.sin,a=r(t/2),l=n(t/2),c=r((e+i)/2),h=n((e+i)/2),d=r((e-i)/2),p=n((e-i)/2),u=r((i-e)/2),f=n((i-e)/2);switch(s){case"XYX":o.set(a*h,l*d,l*p,a*c);break;case"YZY":o.set(l*p,a*h,l*d,a*c);break;case"ZXZ":o.set(l*d,l*p,a*h,a*c);break;case"XZX":o.set(a*h,l*f,l*u,a*c);break;case"YXY":o.set(l*u,a*h,l*f,a*c);break;case"ZYZ":o.set(l*f,l*u,a*h,a*c);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function Ku(o,e){switch(e.constructor){case Float32Array:return o;case Uint32Array:return o/4294967295;case Uint16Array:return o/65535;case Uint8Array:return o/255;case Int32Array:return Math.max(o/2147483647,-1);case Int16Array:return Math.max(o/32767,-1);case Int8Array:return Math.max(o/127,-1);default:throw new Error("Invalid component type.")}}function ep(o,e){switch(e.constructor){case Float32Array:return o;case Uint32Array:return Math.round(o*4294967295);case Uint16Array:return Math.round(o*65535);case Uint8Array:return Math.round(o*255);case Int32Array:return Math.round(o*2147483647);case Int16Array:return Math.round(o*32767);case Int8Array:return Math.round(o*127);default:throw new Error("Invalid component type.")}}const Wi={DEG2RAD:oc,RAD2DEG:ac,generateUUID:Fu,clamp:yt,euclideanModulo:lc,mapLinear:Bu,inverseLerp:Nu,lerp:cc,damp:Hu,pingpong:Du,smoothstep:Vu,smootherstep:Uu,randInt:ju,randFloat:Gu,randFloatSpread:Wu,seededRandom:Xu,degToRad:qu,radToDeg:Ju,isPowerOfTwo:Yu,ceilPowerOfTwo:Zu,floorPowerOfTwo:Qu,setQuaternionFromProperEuler:$u,normalize:ep,denormalize:Ku};class te{constructor(e=0,t=0,i=0,s=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=s}static slerpFlat(e,t,i,s,r,n,a){let l=i[s+0],c=i[s+1],h=i[s+2],d=i[s+3];const p=r[n+0],u=r[n+1],f=r[n+2],m=r[n+3];if(a===0){e[t+0]=l,e[t+1]=c,e[t+2]=h,e[t+3]=d;return}if(a===1){e[t+0]=p,e[t+1]=u,e[t+2]=f,e[t+3]=m;return}if(d!==m||l!==p||c!==u||h!==f){let y=1-a;const _=l*p+c*u+h*f+d*m,x=_>=0?1:-1,S=1-_*_;if(S>Number.EPSILON){const C=Math.sqrt(S),b=Math.atan2(C,_*x);y=Math.sin(y*b)/C,a=Math.sin(a*b)/C}const w=a*x;if(l=l*y+p*w,c=c*y+u*w,h=h*y+f*w,d=d*y+m*w,y===1-a){const C=1/Math.sqrt(l*l+c*c+h*h+d*d);l*=C,c*=C,h*=C,d*=C}}e[t]=l,e[t+1]=c,e[t+2]=h,e[t+3]=d}static multiplyQuaternionsFlat(e,t,i,s,r,n){const a=i[s],l=i[s+1],c=i[s+2],h=i[s+3],d=r[n],p=r[n+1],u=r[n+2],f=r[n+3];return e[t]=a*f+h*d+l*u-c*p,e[t+1]=l*f+h*p+c*d-a*u,e[t+2]=c*f+h*u+a*p-l*d,e[t+3]=h*f-a*d-l*p-c*u,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,i,s){return this._x=e,this._y=t,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new te(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const i=e._x,s=e._y,r=e._z,n=e._order,a=Math.cos,l=Math.sin,c=a(i/2),h=a(s/2),d=a(r/2),p=l(i/2),u=l(s/2),f=l(r/2);switch(n){case"XYZ":this._x=p*h*d+c*u*f,this._y=c*u*d-p*h*f,this._z=c*h*f+p*u*d,this._w=c*h*d-p*u*f;break;case"YXZ":this._x=p*h*d+c*u*f,this._y=c*u*d-p*h*f,this._z=c*h*f-p*u*d,this._w=c*h*d+p*u*f;break;case"ZXY":this._x=p*h*d-c*u*f,this._y=c*u*d+p*h*f,this._z=c*h*f+p*u*d,this._w=c*h*d-p*u*f;break;case"ZYX":this._x=p*h*d-c*u*f,this._y=c*u*d+p*h*f,this._z=c*h*f-p*u*d,this._w=c*h*d+p*u*f;break;case"YZX":this._x=p*h*d+c*u*f,this._y=c*u*d+p*h*f,this._z=c*h*f-p*u*d,this._w=c*h*d-p*u*f;break;case"XZY":this._x=p*h*d-c*u*f,this._y=c*u*d-p*h*f,this._z=c*h*f+p*u*d,this._w=c*h*d+p*u*f;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const i=t/2,s=Math.sin(i);return this._x=e.x*s,this._y=e.y*s,this._z=e.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,i=t[0],s=t[4],r=t[8],n=t[1],a=t[5],l=t[9],c=t[2],h=t[6],d=t[10],p=i+a+d;if(p>0){const u=.5/Math.sqrt(p+1);this._w=.25/u,this._x=(h-l)*u,this._y=(r-c)*u,this._z=(n-s)*u}else if(i>a&&i>d){const u=2*Math.sqrt(1+i-a-d);this._w=(h-l)/u,this._x=.25*u,this._y=(s+n)/u,this._z=(r+c)/u}else if(a>d){const u=2*Math.sqrt(1+a-i-d);this._w=(r-c)/u,this._x=(s+n)/u,this._y=.25*u,this._z=(l+h)/u}else{const u=2*Math.sqrt(1+d-i-a);this._w=(n-s)/u,this._x=(r+c)/u,this._y=(l+h)/u,this._z=.25*u}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return i<Number.EPSILON?(i=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=i):(this._x=0,this._y=-e.z,this._z=e.y,this._w=i)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=i),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(yt(this.dot(e),-1,1)))}rotateTowards(e,t){const i=this.angleTo(e);if(i===0)return this;const s=Math.min(1,t/i);return this.slerp(e,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const i=e._x,s=e._y,r=e._z,n=e._w,a=t._x,l=t._y,c=t._z,h=t._w;return this._x=i*h+n*a+s*c-r*l,this._y=s*h+n*l+r*a-i*c,this._z=r*h+n*c+i*l-s*a,this._w=n*h-i*a-s*l-r*c,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const i=this._x,s=this._y,r=this._z,n=this._w;let a=n*e._w+i*e._x+s*e._y+r*e._z;if(a<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,a=-a):this.copy(e),a>=1)return this._w=n,this._x=i,this._y=s,this._z=r,this;const l=1-a*a;if(l<=Number.EPSILON){const u=1-t;return this._w=u*n+t*this._w,this._x=u*i+t*this._x,this._y=u*s+t*this._y,this._z=u*r+t*this._z,this.normalize(),this}const c=Math.sqrt(l),h=Math.atan2(c,a),d=Math.sin((1-t)*h)/c,p=Math.sin(t*h)/c;return this._w=n*d+this._w*p,this._x=i*d+this._x*p,this._y=s*d+this._y*p,this._z=r*d+this._z*p,this._onChangeCallback(),this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),r=Math.sqrt(i);return this.set(s*Math.sin(e),s*Math.cos(e),r*Math.sin(t),r*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class F{constructor(e=0,t=0,i=0){this.isVector3=!0,F.prototype.isVector3=!0,this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new F(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Ja.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Ja.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,s=this.z,r=e.elements;return this.x=r[0]*t+r[3]*i+r[6]*s,this.y=r[1]*t+r[4]*i+r[7]*s,this.z=r[2]*t+r[5]*i+r[8]*s,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,s=this.z,r=e.elements,n=1/(r[3]*t+r[7]*i+r[11]*s+r[15]);return this.x=(r[0]*t+r[4]*i+r[8]*s+r[12])*n,this.y=(r[1]*t+r[5]*i+r[9]*s+r[13])*n,this.z=(r[2]*t+r[6]*i+r[10]*s+r[14])*n,this}applyQuaternion(e){const t=this.x,i=this.y,s=this.z,r=e.x,n=e.y,a=e.z,l=e.w,c=2*(n*s-a*i),h=2*(a*t-r*s),d=2*(r*i-n*t);return this.x=t+l*c+n*d-a*h,this.y=i+l*h+a*c-r*d,this.z=s+l*d+r*h-n*c,this}transformDirection(e){const t=this.x,i=this.y,s=this.z,r=e.elements;return this.x=r[0]*t+r[4]*i+r[8]*s,this.y=r[1]*t+r[5]*i+r[9]*s,this.z=r[2]*t+r[6]*i+r[10]*s,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,s=e.y,r=e.z,n=t.x,a=t.y,l=t.z;return this.x=s*l-r*a,this.y=r*n-i*l,this.z=i*a-s*n,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return Mn.copy(this).projectOnVector(e),this.sub(Mn)}reflect(e){return this.sub(Mn.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(yt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return t*t+i*i+s*s}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSphericalCoords(e,t,i){const s=Math.sin(t)*e;return this.x=s*Math.sin(i),this.y=Math.cos(t)*e,this.z=s*Math.cos(i),this}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),s=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=s,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*Math.sin(e),this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Mn=new F,Ja=new te,xr=2e3,Ya=2001;class at{constructor(e,t,i,s,r,n,a,l,c,h,d,p,u,f,m,y){this.isMatrix4=!0,at.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,i,s,r,n,a,l,c,h,d,p,u,f,m,y)}extractPosition(e){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(e)}multiplyToArray(e,t,i){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(e){return this.makeRotationFromQuaternion(e)}set(e,t,i,s,r,n,a,l,c,h,d,p,u,f,m,y){const _=this.elements;return _[0]=e,_[4]=t,_[8]=i,_[12]=s,_[1]=r,_[5]=n,_[9]=a,_[13]=l,_[2]=c,_[6]=h,_[10]=d,_[14]=p,_[3]=u,_[7]=f,_[11]=m,_[15]=y,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new at().fromArray(this.elements)}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],this}copyPosition(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,i){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(e,t,i){return this.set(e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,i=e.elements,s=1/Ci.setFromMatrixColumn(e,0).length(),r=1/Ci.setFromMatrixColumn(e,1).length(),n=1/Ci.setFromMatrixColumn(e,2).length();return t[0]=i[0]*s,t[1]=i[1]*s,t[2]=i[2]*s,t[3]=0,t[4]=i[4]*r,t[5]=i[5]*r,t[6]=i[6]*r,t[7]=0,t[8]=i[8]*n,t[9]=i[9]*n,t[10]=i[10]*n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,i=e.x,s=e.y,r=e.z,n=Math.cos(i),a=Math.sin(i),l=Math.cos(s),c=Math.sin(s),h=Math.cos(r),d=Math.sin(r);if(e.order==="XYZ"){const p=n*h,u=n*d,f=a*h,m=a*d;t[0]=l*h,t[4]=-l*d,t[8]=c,t[1]=u+f*c,t[5]=p-m*c,t[9]=-a*l,t[2]=m-p*c,t[6]=f+u*c,t[10]=n*l}else if(e.order==="YXZ"){const p=l*h,u=l*d,f=c*h,m=c*d;t[0]=p+m*a,t[4]=f*a-u,t[8]=n*c,t[1]=n*d,t[5]=n*h,t[9]=-a,t[2]=u*a-f,t[6]=m+p*a,t[10]=n*l}else if(e.order==="ZXY"){const p=l*h,u=l*d,f=c*h,m=c*d;t[0]=p-m*a,t[4]=-n*d,t[8]=f+u*a,t[1]=u+f*a,t[5]=n*h,t[9]=m-p*a,t[2]=-n*c,t[6]=a,t[10]=n*l}else if(e.order==="ZYX"){const p=n*h,u=n*d,f=a*h,m=a*d;t[0]=l*h,t[4]=f*c-u,t[8]=p*c+m,t[1]=l*d,t[5]=m*c+p,t[9]=u*c-f,t[2]=-c,t[6]=a*l,t[10]=n*l}else if(e.order==="YZX"){const p=n*l,u=n*c,f=a*l,m=a*c;t[0]=l*h,t[4]=m-p*d,t[8]=f*d+u,t[1]=d,t[5]=n*h,t[9]=-a*h,t[2]=-c*h,t[6]=u*d+f,t[10]=p-m*d}else if(e.order==="XZY"){const p=n*l,u=n*c,f=a*l,m=a*c;t[0]=l*h,t[4]=-d,t[8]=c*h,t[1]=p*d+m,t[5]=n*h,t[9]=u*d-f,t[2]=f*d-u,t[6]=a*h,t[10]=m*d+p}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(tp,e,ip)}lookAt(e,t,i){const s=this.elements;return Xe.subVectors(e,t),Xe.lengthSq()===0&&(Xe.z=1),Xe.normalize(),Ut.crossVectors(i,Xe),Ut.lengthSq()===0&&(Math.abs(i.z)===1?Xe.x+=1e-4:Xe.z+=1e-4,Xe.normalize(),Ut.crossVectors(i,Xe)),Ut.normalize(),br.crossVectors(Xe,Ut),s[0]=Ut.x,s[4]=br.x,s[8]=Xe.x,s[1]=Ut.y,s[5]=br.y,s[9]=Xe.y,s[2]=Ut.z,s[6]=br.z,s[10]=Xe.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,s=t.elements,r=this.elements,n=i[0],a=i[4],l=i[8],c=i[12],h=i[1],d=i[5],p=i[9],u=i[13],f=i[2],m=i[6],y=i[10],_=i[14],x=i[3],S=i[7],w=i[11],C=i[15],b=s[0],M=s[4],P=s[8],E=s[12],R=s[1],N=s[5],se=s[9],ye=s[13],q=s[2],X=s[6],re=s[10],j=s[14],$=s[3],J=s[7],ne=s[11],Q=s[15];return r[0]=n*b+a*R+l*q+c*$,r[4]=n*M+a*N+l*X+c*J,r[8]=n*P+a*se+l*re+c*ne,r[12]=n*E+a*ye+l*j+c*Q,r[1]=h*b+d*R+p*q+u*$,r[5]=h*M+d*N+p*X+u*J,r[9]=h*P+d*se+p*re+u*ne,r[13]=h*E+d*ye+p*j+u*Q,r[2]=f*b+m*R+y*q+_*$,r[6]=f*M+m*N+y*X+_*J,r[10]=f*P+m*se+y*re+_*ne,r[14]=f*E+m*ye+y*j+_*Q,r[3]=x*b+S*R+w*q+C*$,r[7]=x*M+S*N+w*X+C*J,r[11]=x*P+S*se+w*re+C*ne,r[15]=x*E+S*ye+w*j+C*Q,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[4],s=e[8],r=e[12],n=e[1],a=e[5],l=e[9],c=e[13],h=e[2],d=e[6],p=e[10],u=e[14],f=e[3],m=e[7],y=e[11],_=e[15];return f*(+r*l*d-s*c*d-r*a*p+i*c*p+s*a*u-i*l*u)+m*(+t*l*u-t*c*p+r*n*p-s*n*u+s*c*h-r*l*h)+y*(+t*c*d-t*a*u-r*n*d+i*n*u+r*a*h-i*c*h)+_*(-s*a*h-t*l*d+t*a*p+s*n*d-i*n*p+i*l*h)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,i){const s=this.elements;return e.isVector3?(s[12]=e.x,s[13]=e.y,s[14]=e.z):(s[12]=e,s[13]=t,s[14]=i),this}invert(){const e=this.elements,t=e[0],i=e[1],s=e[2],r=e[3],n=e[4],a=e[5],l=e[6],c=e[7],h=e[8],d=e[9],p=e[10],u=e[11],f=e[12],m=e[13],y=e[14],_=e[15],x=d*y*c-m*p*c+m*l*u-a*y*u-d*l*_+a*p*_,S=f*p*c-h*y*c-f*l*u+n*y*u+h*l*_-n*p*_,w=h*m*c-f*d*c+f*a*u-n*m*u-h*a*_+n*d*_,C=f*d*l-h*m*l-f*a*p+n*m*p+h*a*y-n*d*y,b=t*x+i*S+s*w+r*C;if(b===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const M=1/b;return e[0]=x*M,e[1]=(m*p*r-d*y*r-m*s*u+i*y*u+d*s*_-i*p*_)*M,e[2]=(a*y*r-m*l*r+m*s*c-i*y*c-a*s*_+i*l*_)*M,e[3]=(d*l*r-a*p*r-d*s*c+i*p*c+a*s*u-i*l*u)*M,e[4]=S*M,e[5]=(h*y*r-f*p*r+f*s*u-t*y*u-h*s*_+t*p*_)*M,e[6]=(f*l*r-n*y*r-f*s*c+t*y*c+n*s*_-t*l*_)*M,e[7]=(n*p*r-h*l*r+h*s*c-t*p*c-n*s*u+t*l*u)*M,e[8]=w*M,e[9]=(f*d*r-h*m*r-f*i*u+t*m*u+h*i*_-t*d*_)*M,e[10]=(n*m*r-f*a*r+f*i*c-t*m*c-n*i*_+t*a*_)*M,e[11]=(h*a*r-n*d*r-h*i*c+t*d*c+n*i*u-t*a*u)*M,e[12]=C*M,e[13]=(h*m*s-f*d*s+f*i*p-t*m*p-h*i*y+t*d*y)*M,e[14]=(f*a*s-n*m*s-f*i*l+t*m*l+n*i*y-t*a*y)*M,e[15]=(n*d*s-h*a*s+h*i*l-t*d*l-n*i*p+t*a*p)*M,this}scale(e){const t=this.elements,i=e.x,s=e.y,r=e.z;return t[0]*=i,t[4]*=s,t[8]*=r,t[1]*=i,t[5]*=s,t[9]*=r,t[2]*=i,t[6]*=s,t[10]*=r,t[3]*=i,t[7]*=s,t[11]*=r,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],s=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,s))}makeTranslation(e,t,i){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,i,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const i=Math.cos(t),s=Math.sin(t),r=1-i,n=e.x,a=e.y,l=e.z,c=r*n,h=r*a;return this.set(c*n+i,c*a-s*l,c*l+s*a,0,c*a+s*l,h*a+i,h*l-s*n,0,c*l-s*a,h*l+s*n,r*l*l+i,0,0,0,0,1),this}makeScale(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this}makeShear(e,t,i,s,r,n){return this.set(1,i,r,0,e,1,n,0,t,s,1,0,0,0,0,1),this}compose(e,t,i){const s=this.elements,r=t._x,n=t._y,a=t._z,l=t._w,c=r+r,h=n+n,d=a+a,p=r*c,u=r*h,f=r*d,m=n*h,y=n*d,_=a*d,x=l*c,S=l*h,w=l*d,C=i.x,b=i.y,M=i.z;return s[0]=(1-(m+_))*C,s[1]=(u+w)*C,s[2]=(f-S)*C,s[3]=0,s[4]=(u-w)*b,s[5]=(1-(p+_))*b,s[6]=(y+x)*b,s[7]=0,s[8]=(f+S)*M,s[9]=(y-x)*M,s[10]=(1-(p+m))*M,s[11]=0,s[12]=e.x,s[13]=e.y,s[14]=e.z,s[15]=1,this}decompose(e,t,i){const s=this.elements;let r=Ci.set(s[0],s[1],s[2]).length();const n=Ci.set(s[4],s[5],s[6]).length(),a=Ci.set(s[8],s[9],s[10]).length();this.determinant()<0&&(r=-r),e.x=s[12],e.y=s[13],e.z=s[14],tt.copy(this);const c=1/r,h=1/n,d=1/a;return tt.elements[0]*=c,tt.elements[1]*=c,tt.elements[2]*=c,tt.elements[4]*=h,tt.elements[5]*=h,tt.elements[6]*=h,tt.elements[8]*=d,tt.elements[9]*=d,tt.elements[10]*=d,t.setFromRotationMatrix(tt),i.x=r,i.y=n,i.z=a,this}makePerspective(e,t,i,s,r,n,a=xr){const l=this.elements,c=2*r/(t-e),h=2*r/(i-s),d=(t+e)/(t-e),p=(i+s)/(i-s);let u,f;if(a===xr)u=-(n+r)/(n-r),f=-2*n*r/(n-r);else if(a===Ya)u=-n/(n-r),f=-n*r/(n-r);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+a);return l[0]=c,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=h,l[9]=p,l[13]=0,l[2]=0,l[6]=0,l[10]=u,l[14]=f,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(e,t,i,s,r,n,a=xr){const l=this.elements,c=1/(t-e),h=1/(i-s),d=1/(n-r),p=(t+e)*c,u=(i+s)*h;let f,m;if(a===xr)f=(n+r)*d,m=-2*d;else if(a===Ya)f=r*d,m=-1*d;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return l[0]=2*c,l[4]=0,l[8]=0,l[12]=-p,l[1]=0,l[5]=2*h,l[9]=0,l[13]=-u,l[2]=0,l[6]=0,l[10]=m,l[14]=-f,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(e){const t=this.elements,i=e.elements;for(let s=0;s<16;s++)if(t[s]!==i[s])return!1;return!0}fromArray(e,t=0){for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e[t+9]=i[9],e[t+10]=i[10],e[t+11]=i[11],e[t+12]=i[12],e[t+13]=i[13],e[t+14]=i[14],e[t+15]=i[15],e}}const Ci=new F,tt=new at,tp=new F(0,0,0),ip=new F(1,1,1),Ut=new F,br=new F,Xe=new F,Za=new at,Qa=new te;class ms{constructor(e=0,t=0,i=0,s=ms.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=i,this._order=s}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,i,s=this._order){return this._x=e,this._y=t,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new ms(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,i=!0){const s=e.elements,r=s[0],n=s[4],a=s[8],l=s[1],c=s[5],h=s[9],d=s[2],p=s[6],u=s[10];switch(t){case"XYZ":this._y=Math.asin(yt(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,u),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(p,c),this._z=0);break;case"YXZ":this._x=Math.asin(-yt(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,u),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-d,r),this._z=0);break;case"ZXY":this._x=Math.asin(yt(p,-1,1)),Math.abs(p)<.9999999?(this._y=Math.atan2(-d,u),this._z=Math.atan2(-n,c)):(this._y=0,this._z=Math.atan2(l,r));break;case"ZYX":this._y=Math.asin(-yt(d,-1,1)),Math.abs(d)<.9999999?(this._x=Math.atan2(p,u),this._z=Math.atan2(l,r)):(this._x=0,this._z=Math.atan2(-n,c));break;case"YZX":this._z=Math.asin(yt(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-d,r)):(this._x=0,this._y=Math.atan2(a,u));break;case"XZY":this._z=Math.asin(-yt(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(p,c),this._y=Math.atan2(a,r)):(this._x=Math.atan2(-h,u),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,i===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,i){return Za.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Za,t,i)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return Qa.setFromEuler(this),this.setFromQuaternion(Qa,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(e){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}ms.DEFAULT_ORDER="XYZ";class Ni{constructor(e=0,t=0){this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new Ni(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,i=this.y,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6],this.y=s[1]*t+s[4]*i+s[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(yt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}rotateAround(e,t){const i=Math.cos(t),s=Math.sin(t),r=this.x-e.x,n=this.y-e.y;return this.x=r*i-n*s+e.x,this.y=r*s+n*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}Ni.isVector2=!0;class Je{constructor(e=0,t=0,i=0,s=1){Je.prototype.isVector4=!0,this.x=e,this.y=t,this.z=i,this.w=s}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new Je(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,i=this.y,s=this.z,r=this.w,n=e.elements;return this.x=n[0]*t+n[4]*i+n[8]*s+n[12]*r,this.y=n[1]*t+n[5]*i+n[9]*s+n[13]*r,this.z=n[2]*t+n[6]*i+n[10]*s+n[14]*r,this.w=n[3]*t+n[7]*i+n[11]*s+n[15]*r,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,i,s,r;const l=e.elements,c=l[0],h=l[4],d=l[8],p=l[1],u=l[5],f=l[9],m=l[2],y=l[6],_=l[10];if(Math.abs(h-p)<.01&&Math.abs(d-m)<.01&&Math.abs(f-y)<.01){if(Math.abs(h+p)<.1&&Math.abs(d+m)<.1&&Math.abs(f+y)<.1&&Math.abs(c+u+_-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const S=(c+1)/2,w=(u+1)/2,C=(_+1)/2,b=(h+p)/4,M=(d+m)/4,P=(f+y)/4;return S>w&&S>C?S<.01?(i=0,s=.707106781,r=.707106781):(i=Math.sqrt(S),s=b/i,r=M/i):w>C?w<.01?(i=.707106781,s=0,r=.707106781):(s=Math.sqrt(w),i=b/s,r=P/s):C<.01?(i=.707106781,s=.707106781,r=0):(r=Math.sqrt(C),i=M/r,s=P/r),this.set(i,s,r,t),this}let x=Math.sqrt((y-f)*(y-f)+(d-m)*(d-m)+(p-h)*(p-h));return Math.abs(x)<.001&&(x=1),this.x=(y-f)/x,this.y=(d-m)/x,this.z=(p-h)/x,this.w=Math.acos((c+u+_-1)/2),this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this.w=e.w+(t.w-e.w)*i,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class xt{constructor(e,t,i,s,r,n,a,l,c){xt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,s,r,n,a,l,c)}set(e,t,i,s,r,n,a,l,c){const h=this.elements;return h[0]=e,h[1]=s,h[2]=a,h[3]=t,h[4]=r,h[5]=l,h[6]=i,h[7]=n,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,s=t.elements,r=this.elements,n=i[0],a=i[3],l=i[6],c=i[1],h=i[4],d=i[7],p=i[2],u=i[5],f=i[8],m=s[0],y=s[3],_=s[6],x=s[1],S=s[4],w=s[7],C=s[2],b=s[5],M=s[8];return r[0]=n*m+a*x+l*C,r[3]=n*y+a*S+l*b,r[6]=n*_+a*w+l*M,r[1]=c*m+h*x+d*C,r[4]=c*y+h*S+d*b,r[7]=c*_+h*w+d*M,r[2]=p*m+u*x+f*C,r[5]=p*y+u*S+f*b,r[8]=p*_+u*w+f*M,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[1],s=e[2],r=e[3],n=e[4],a=e[5],l=e[6],c=e[7],h=e[8];return t*n*h-t*a*c-i*r*h+i*a*l+s*r*c-s*n*l}invert(){const e=this.elements,t=e[0],i=e[1],s=e[2],r=e[3],n=e[4],a=e[5],l=e[6],c=e[7],h=e[8],d=h*n-a*c,p=a*l-h*r,u=c*r-n*l,f=t*d+i*p+s*u;if(f===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/f;return e[0]=d*m,e[1]=(s*c-h*i)*m,e[2]=(a*i-s*n)*m,e[3]=p*m,e[4]=(h*t-s*l)*m,e[5]=(s*r-a*t)*m,e[6]=u*m,e[7]=(i*l-c*t)*m,e[8]=(n*t-i*r)*m,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,s,r,n,a){const l=Math.cos(r),c=Math.sin(r);return this.set(i*l,i*c,-i*(l*n+c*a)+n+e,-s*c,s*l,-s*(-c*n+l*a)+a+t,0,0,1),this}scale(e,t){return this.premultiply(Cn.makeScale(e,t)),this}rotate(e){return this.premultiply(Cn.makeRotation(-e)),this}translate(e,t){return this.premultiply(Cn.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,i=e.elements;for(let s=0;s<9;s++)if(t[s]!==i[s])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new xt().fromArray(this.elements)}}const Cn=new xt;var Fe;(function(o){o[o.Random=0]="Random",o[o.Loop=1]="Loop",o[o.PingPong=2]="PingPong",o[o.Burst=3]="Burst"})(Fe||(Fe={}));function Xi(o,e,t,i){let s;switch(Fe.Random===o?e=Math.random():Fe.Burst===o&&i.isBursting&&(e=i.burstParticleIndex/i.burstParticleCount),t>0?s=Math.floor(e/t)*t:s=e,o){case Fe.Loop:s=s%1;break;case Fe.PingPong:s=Math.abs(s%2-1);break}return s}class ai{constructor(e,t,i,s){this.p=[e,t,i,s]}genValue(e){const t=e*e,i=e*e*e,s=1-e,r=s*s,n=r*s;return this.p[0]*n+this.p[1]*r*e*3+this.p[2]*s*t*3+this.p[3]*i}derivativeCoefficients(e){const t=[];for(let i=e,s=i.length-1;s>0;s--){const r=[];for(let n=0;n<s;n++){const a=s*(i[n+1]-i[n]);r.push(a)}t.push(r),i=r}return t}getSlope(e){const t=this.derivativeCoefficients(this.p)[0],i=1-e,s=i*i,r=i*e*2,n=e*e;return s*t[0]+r*t[1]+n*t[2]}controlCurve(e,t){this.p[1]=e/3+this.p[0],this.p[2]=this.p[3]-t/3}hull(e){let t=this.p,i=[],s,r=0,n=0,a=0;const l=[];for(l[r++]=t[0],l[r++]=t[1],l[r++]=t[2],l[r++]=t[3];t.length>1;){for(i=[],n=0,a=t.length-1;n<a;n++)s=e*t[n]+(1-e)*t[n+1],l[r++]=s,i.push(s);t=i}return l}split(e){const t=this.hull(e);return{left:new ai(t[0],t[4],t[7],t[9]),right:new ai(t[9],t[8],t[6],t[3]),span:t}}clone(){return new ai(this.p[0],this.p[1],this.p[2],this.p[3])}toJSON(){return{p0:this.p[0],p1:this.p[1],p2:this.p[2],p3:this.p[3]}}static fromJSON(e){return new ai(e.p0,e.p1,e.p2,e.p3)}}const gs=o=>({r:o.x,g:o.y,b:o.z,a:o.w}),ys=o=>new Je(o.r,o.g,o.b,o.a),sp=(o,e)=>{switch(e){case"Vector3":return new F(o.x,o.y,o.z);case"Vector4":return new Je(o.x,o.y,o.z,o.w);case"Color":return new F(o.r,o.g,o.b);case"Number":return o;default:return o}},rp=(o,e)=>{switch(e){case"Vector3":return{x:o.x,y:o.y,z:o.z};case"Vector4":return{x:o.x,y:o.y,z:o.z,w:o.w};case"Color":return{r:o.x,g:o.y,b:o.z};case"Number":return o;default:return o}};class Hr{constructor(e,t){this.a=e,this.b=t,this.type="value"}startGen(e){}genColor(e,t){const i=Math.random();return t.copy(this.a).lerp(this.b,i)}toJSON(){return{type:"RandomColor",a:gs(this.a),b:gs(this.b)}}static fromJSON(e){return new Hr(ys(e.a),ys(e.b))}clone(){return new Hr(this.a.clone(),this.b.clone())}}class Hi{constructor(e,t){this.a=e,this.b=t,this.indexCount=-1,this.type="value"}startGen(e){this.indexCount=e.length,e.push(Math.random())}genColor(e,t){return this.indexCount===-1&&this.startGen(e),t.copy(this.a).lerp(this.b,e[this.indexCount])}toJSON(){return{type:"ColorRange",a:gs(this.a),b:gs(this.b)}}static fromJSON(e){return new Hi(ys(e.a),ys(e.b))}clone(){return new Hi(this.a.clone(),this.b.clone())}}class Wt{constructor(e,t){this.subType=t,this.type="function",this.keys=e}findKey(e){let t=0,i=0,s=this.keys.length-1;for(;i+1<s;)if(t=Math.floor((i+s)/2),e<this.getStartX(t))s=t-1;else if(e>this.getEndX(t))i=t+1;else return t;for(let r=i;r<=s;r++)if(e>=this.getStartX(r)&&e<=this.getEndX(r))return r;return-1}getStartX(e){return this.keys[e][1]}getEndX(e){return e+1<this.keys.length?this.keys[e+1][1]:1}genValue(e,t){const i=this.findKey(t);return this.subType==="Number"?i===-1?this.keys[0][0]:i+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[i+1][0]-this.keys[i][0])*((t-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))+this.keys[i][0]:i===-1?e.copy(this.keys[0][0]):i+1>=this.keys.length?e.copy(this.keys[this.keys.length-1][0]):e.copy(this.keys[i][0]).lerp(this.keys[i+1][0],(t-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([e,t])=>({value:rp(e,this.subType),pos:t}))}}static fromJSON(e){return new Wt(e.keys.map(t=>[sp(t.value,e.subType),t.pos]),e.subType)}clone(){return this.subType==="Number"?new Wt(this.keys.map(([e,t])=>[e,t]),this.subType):new Wt(this.keys.map(([e,t])=>[e.clone(),t]),this.subType)}}const Sr=new F;class ci{constructor(e=[[new F(0,0,0),0],[new F(1,1,1),0]],t=[[1,0],[1,1]]){this.type="function",this.color=new Wt(e,"Color"),this.alpha=new Wt(t,"Number")}genColor(e,t,i){return this.color.genValue(Sr,i),t.set(Sr.x,Sr.y,Sr.z,this.alpha.genValue(1,i))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(e){if(e.functions){const t=e.functions.map(i=>[Hi.fromJSON(i.function).a,i.start]);return e.functions.length>0&&t.push([Hi.fromJSON(e.functions[e.functions.length-1].function).b,1]),new ci(t.map(i=>[new F(i[0].x,i[0].y,i[0].z),i[1]]),t.map(i=>[i[0].w,i[1]]))}else{const t=new ci;return t.alpha=Wt.fromJSON(e.alpha),t.color=Wt.fromJSON(e.color),t}}clone(){const e=new ci;return e.alpha=this.alpha.clone(),e.color=this.color.clone(),e}startGen(e){}}const Pn=new Je;class Dr{constructor(e,t){this.indexCount=0,this.type="function",this.gradient1=e,this.gradient2=t}startGen(e){this.indexCount=e.length,e.push(Math.random())}genColor(e,t,i){return this.gradient1.genColor(e,t,i),this.gradient2.genColor(e,Pn,i),e&&e[this.indexCount]!==void 0?t.lerp(Pn,e[this.indexCount]):t.lerp(Pn,Math.random()),t}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(e){return new Dr(ci.fromJSON(e.gradient1),ci.fromJSON(e.gradient2))}clone(){return new Dr(this.gradient1.clone(),this.gradient2.clone())}}class Di{constructor(e){this.color=e,this.type="value"}startGen(e){}genColor(e,t){return t.copy(this.color)}toJSON(){return{type:"ConstantColor",color:gs(this.color)}}static fromJSON(e){return new Di(ys(e.color))}clone(){return new Di(this.color.clone())}}function wo(o){switch(o.type){case"ConstantColor":return Di.fromJSON(o);case"ColorRange":return Hi.fromJSON(o);case"RandomColor":return Hr.fromJSON(o);case"Gradient":return ci.fromJSON(o);case"RandomColorBetweenGradient":return Dr.fromJSON(o);default:return new Di(new Je(1,1,1,1))}}class ie{constructor(e){this.value=e,this.type="value"}startGen(e){}genValue(e){return this.value}toJSON(){return{type:"ConstantValue",value:this.value}}static fromJSON(e){return new ie(e.value)}clone(){return new ie(this.value)}}class pi{constructor(e,t){this.a=e,this.b=t,this.indexCount=-1,this.type="value"}startGen(e){this.indexCount=e.length,e.push(Math.random())}genValue(e){return this.indexCount===-1&&this.startGen(e),Wi.lerp(this.a,this.b,e[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(e){return new pi(e.a,e.b)}clone(){return new pi(this.a,this.b)}}class np{constructor(){this.functions=new Array}findFunction(e){let t=0,i=0,s=this.functions.length-1;for(;i+1<s;)if(t=Math.floor((i+s)/2),e<this.getStartX(t))s=t-1;else if(e>this.getEndX(t))i=t+1;else return t;for(let r=i;r<=s;r++)if(e>=this.functions[r][1]&&e<=this.getEndX(r))return r;return-1}getStartX(e){return this.functions[e][1]}setStartX(e,t){e>0&&(this.functions[e][1]=t)}getEndX(e){return e+1<this.functions.length?this.functions[e+1][1]:1}setEndX(e,t){e+1<this.functions.length&&(this.functions[e+1][1]=t)}insertFunction(e,t){const i=this.findFunction(e);this.functions.splice(i+1,0,[t,e])}removeFunction(e){return this.functions.splice(e,1)[0][0]}getFunction(e){return this.functions[e][0]}setFunction(e,t){this.functions[e][0]=t}get numOfFunctions(){return this.functions.length}}class _s extends np{constructor(e=[[new ai(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=e}genValue(e,t=0){const i=this.findFunction(t);return i===-1?0:this.functions[i][0].genValue((t-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))}toSVG(e,t){if(t<1)return"";let i=["M",0,this.functions[0][0].p[0]].join(" ");for(let s=1/t;s<=1;s+=1/t)i=[i,"L",s*e,this.genValue(void 0,s)].join(" ");return i}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([e,t])=>({function:e.toJSON(),start:t}))}}static fromJSON(e){return new _s(e.functions.map(t=>[ai.fromJSON(t.function),t.start]))}clone(){return new _s(this.functions.map(([e,t])=>[e.clone(),t]))}startGen(e){}}function W(o){switch(o.type){case"ConstantValue":return ie.fromJSON(o);case"IntervalValue":return pi.fromJSON(o);case"PiecewiseBezier":return _s.fromJSON(o);default:return new ie(0)}}class vs{constructor(){this.indexCount=0,this.type="rotation"}startGen(e){this.indexCount=e.length,e.push(new te);let t,i,s,r,n,a;do t=Math.random()*2-1,i=Math.random()*2-1,s=t*t+i*i;while(s>1);do r=Math.random()*2-1,n=Math.random()*2-1,a=r*r+n*n;while(a>1);const l=Math.sqrt((1-s)/a);e[this.indexCount].set(t,i,l*r,l*n)}genValue(e,t,i,s){return this.indexCount===-1&&this.startGen(e),t.copy(e[this.indexCount]),t}toJSON(){return{type:"RandomQuat"}}static fromJSON(e){return new vs}clone(){return new vs}}class ws{constructor(e,t){this.axis=e,this.angle=t,this.type="rotation"}startGen(e){this.angle.startGen(e)}genValue(e,t,i,s){return t.setFromAxisAngle(this.axis,this.angle.genValue(e,s)*i)}toJSON(){return{type:"AxisAngle",axis:{x:this.axis.x,y:this.axis.y,z:this.axis.z},angle:this.angle.toJSON()}}static fromJSON(e){return new ws(new F(e.axis.x,e.axis.y,e.axis.z),W(e.angle))}clone(){return new ws(this.axis.clone(),this.angle.clone())}}class Vr{constructor(e,t,i,s){this.angleX=e,this.angleY=t,this.angleZ=i,this.type="rotation",this.eular=new ms(0,0,0,s)}startGen(e){this.angleX.startGen(e),this.angleY.startGen(e),this.angleZ.startGen(e)}genValue(e,t,i,s){return this.eular.set(this.angleX.genValue(e,s)*i,this.angleY.genValue(e,s)*i,this.angleZ.genValue(e,s)*i),t.setFromEuler(this.eular)}toJSON(){return{type:"Euler",angleX:this.angleX.toJSON(),angleY:this.angleY.toJSON(),angleZ:this.angleZ.toJSON(),eulerOrder:this.eular.order}}static fromJSON(e){return new Vr(W(e.angleX),W(e.angleY),W(e.angleZ),e.eulerOrder)}clone(){return new Vr(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function hc(o){switch(o.type){case"AxisAngle":return ws.fromJSON(o);case"Euler":return Vr.fromJSON(o);case"RandomQuat":return vs.fromJSON(o);default:return new vs}}class fi{constructor(e,t,i){this.x=e,this.y=t,this.z=i,this.type="vec3function"}startGen(e){this.x.startGen(e),this.y.startGen(e),this.z.startGen(e)}genValue(e,t,i){return t.set(this.x.genValue(e,i),this.y.genValue(e,i),this.z.genValue(e,i))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new fi(W(e.x),W(e.y),W(e.z))}clone(){return new fi(this.x,this.y,this.z)}}function op(o){switch(o.type){case"Vector3Function":return fi.fromJSON(o);default:return new fi(new ie(0),new ie(0),new ie(0))}}function Ur(o){switch(o.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return W(o);case"AxisAngle":case"RandomQuat":case"Euler":return hc(o);case"Vector3Function":return op(o);default:return new ie(0)}}class xs{constructor(e={}){this.type="cone",this.currentValue=0,this.radius=e.radius??10,this.arc=e.arc??2*Math.PI,this.thickness=e.thickness??1,this.angle=e.angle??Math.PI/6,this.mode=e.mode??Fe.Random,this.spread=e.spread??0,this.speed=e.speed??new ie(1),this.memory=[]}update(e,t){Fe.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const i=Xi(this.mode,this.currentValue,this.spread,t),s=Wi.lerp(1-this.thickness,1,Math.random()),r=i*this.arc,n=Math.sqrt(s),a=Math.sin(r),l=Math.cos(r);e.position.x=n*l,e.position.y=n*a,e.position.z=0;const c=this.angle*n;e.velocity.set(0,0,Math.cos(c)).addScaledVector(e.position,Math.sin(c)).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius)}toJSON(){return{type:"cone",radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new xs({radius:e.radius,arc:e.arc,thickness:e.thickness,angle:e.angle,mode:e.mode,speed:e.speed?W(e.speed):void 0,spread:e.spread})}clone(){return new xs({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class bs{constructor(e={}){this.type="circle",this.currentValue=0,this.radius=e.radius??10,this.arc=e.arc??2*Math.PI,this.thickness=e.thickness??1,this.mode=e.mode??Fe.Random,this.spread=e.spread??0,this.speed=e.speed??new ie(1),this.memory=[]}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const i=Xi(this.mode,this.currentValue,this.spread,t),s=Wi.lerp(1-this.thickness,1,Math.random()),r=i*this.arc;e.position.x=Math.cos(r),e.position.y=Math.sin(r),e.position.z=0,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new bs({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?W(e.speed):void 0,spread:e.spread})}clone(){return new bs({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function Mr(o,e){return Math.floor(Math.random()*(e-o))+o}const Js=new F(0,1,0),Ys=new F(0,0,0),ap=new F(1,1,1),$a=new F(0,0,1);class Ss{constructor(e={}){this.type="donut",this.currentValue=0,this.radius=e.radius??10,this.arc=e.arc??2*Math.PI,this.thickness=e.thickness??1,this.donutRadius=e.donutRadius??this.radius*.2,this.mode=e.mode??Fe.Random,this.spread=e.spread??0,this.speed=e.speed??new ie(1),this.memory=[],this._m1=new at}update(e,t){Fe.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const i=Xi(this.mode,this.currentValue,this.spread,t),s=Math.random(),r=Wi.lerp(1-this.thickness,1,Math.random()),n=i*this.arc,a=s*Math.PI*2,l=Math.sin(n),c=Math.cos(n);e.position.x=this.radius*c,e.position.y=this.radius*l,e.position.z=0,e.velocity.z=this.donutRadius*r*Math.sin(a),e.velocity.x=this.donutRadius*r*Math.cos(a)*c,e.velocity.y=this.donutRadius*r*Math.cos(a)*l,e.position.add(e.velocity),e.velocity.normalize().multiplyScalar(e.startSpeed),e.rotation instanceof te&&(this._m1.lookAt(Ys,e.velocity,Js),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"donut",radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Ss({radius:e.radius,arc:e.arc,thickness:e.thickness,donutRadius:e.donutRadius,mode:e.mode,speed:e.speed?W(e.speed):void 0,spread:e.spread})}clone(){return new Ss({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ms{constructor(){this.type="point",this._m1=new at}update(e,t){}initialize(e){const t=Math.random(),i=Math.random(),s=t*Math.PI*2,r=Math.acos(2*i-1),n=Math.cbrt(Math.random()),a=Math.sin(s),l=Math.cos(s),c=Math.sin(r),h=Math.cos(r);e.velocity.x=n*c*l,e.velocity.y=n*c*a,e.velocity.z=n*h,e.velocity.multiplyScalar(e.startSpeed),e.position.setScalar(0),e.rotation instanceof te&&(this._m1.lookAt(Ys,e.position,Js),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(e){return new Ms}clone(){return new Ms}}class Vi{constructor(e={}){this.type="sphere",this.currentValue=0,this.radius=e.radius??10,this.arc=e.arc??2*Math.PI,this.thickness=e.thickness??1,this.mode=e.mode??Fe.Random,this.spread=e.spread??0,this.speed=e.speed??new ie(1),this.memory=[],this._m1=new at}update(e,t){Fe.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const i=Xi(this.mode,this.currentValue,this.spread,t),s=Math.random(),r=Wi.lerp(1-this.thickness,1,Math.random()),n=i*this.arc,a=Math.acos(2*s-1),l=Math.sin(n),c=Math.cos(n),h=Math.sin(a),d=Math.cos(a);e.position.x=h*c,e.position.y=h*l,e.position.z=d,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*r),e.rotation instanceof te&&(this._m1.lookAt(Ys,e.position,Js),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"sphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Vi({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?W(e.speed):void 0,spread:e.spread})}clone(){return new Vi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Cs{constructor(e={}){this.type="hemisphere",this.currentValue=0,this.radius=e.radius??10,this.arc=e.arc??2*Math.PI,this.thickness=e.thickness??1,this.mode=e.mode??Fe.Random,this.spread=e.spread??0,this.speed=e.speed??new ie(1),this.memory=[],this._m1=new at}update(e,t){Fe.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const i=Xi(this.mode,this.currentValue,this.spread,t),s=Math.random(),r=Wi.lerp(1-this.thickness,1,Math.random()),n=i*this.arc,a=Math.acos(s),l=Math.sin(n),c=Math.cos(n),h=Math.sin(a),d=Math.cos(a);e.position.x=h*c,e.position.y=h*l,e.position.z=d,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*r),e.rotation instanceof te&&(this._m1.lookAt(Ys,e.position,Js),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"hemisphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Cs({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?W(e.speed):void 0,spread:e.spread})}clone(){return new Cs({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ps{constructor(e={}){this.type="grid",this.width=e.width??1,this.height=e.height??1,this.column=e.column??10,this.row=e.row??10}initialize(e){const t=Math.floor(Math.random()*this.row),i=Math.floor(Math.random()*this.column);e.position.x=i*this.width/this.column-this.width/2,e.position.y=t*this.height/this.row-this.height/2,e.position.z=0,e.velocity.set(0,0,e.startSpeed)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row}}static fromJSON(e){return new Ps(e)}clone(){return new Ps({width:this.width,height:this.height,column:this.column,row:this.row})}update(e,t){}}class As{constructor(e={}){this.type="rectangle",this.currentValue=0,this.width=e.width??10,this.height=e.height??10,this.thickness=e.thickness??1,this.mode=e.mode??Fe.Random,this.spread=e.spread??0,this.speed=e.speed??new ie(1),this.memory=[],this._m1=new at}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const i=Xi(this.mode,this.currentValue,this.spread,t),s=2*(this.width+this.height),r=i*s;let n,a;r<this.width?(n=r-this.width/2,a=-this.height/2):r<this.width+this.height?(n=this.width/2,a=r-this.width-this.height/2):r<2*this.width+this.height?(n=this.width/2-(r-this.width-this.height),a=this.height/2):(n=-this.width/2,a=this.height/2-(r-2*this.width-this.height));const l=Math.random(),c=1-this.thickness*l;e.position.x=n*c,e.position.y=a*c,e.position.z=0,e.velocity.x=n,e.velocity.y=a,e.velocity.z=0,e.velocity.normalize().multiplyScalar(e.startSpeed),e.rotation instanceof te&&(this._m1.lookAt(Ys,e.velocity,Js),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"rectangle",width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new As({width:e.width,height:e.height,thickness:e.thickness,mode:e.mode,speed:e.speed?W(e.speed):void 0,spread:e.spread})}clone(){return new As({width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}const to={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:bs,loadJSON:bs.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:xs,loadJSON:xs.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Ss,loadJSON:Ss.fromJSON},point:{type:"point",params:[],constructor:Ms,loadJSON:Ms.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Vi,loadJSON:Vi.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Cs,loadJSON:Cs.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:Ps,loadJSON:Ps.fromJSON},rectangle:{type:"rectangle",params:[["width",["number"]],["height",["number"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:As,loadJSON:As.fromJSON}};function lp(o,e){return to[o.type].loadJSON(o,e)}class Es{constructor(e){this.color=e,this.type="ColorOverLife"}initialize(e){this.color.startGen(e.memory)}update(e,t){this.color.genColor(e.memory,e.color,e.age/e.life),e.color.x*=e.startColor.x,e.color.y*=e.startColor.y,e.color.z*=e.startColor.z,e.color.w*=e.startColor.w}frameUpdate(e){}toJSON(){return{type:this.type,color:this.color.toJSON()}}static fromJSON(e){return new Es(wo(e.color))}clone(){return new Es(this.color.clone())}reset(){}}class zs{constructor(e){this.angularVelocity=e,this.type="RotationOverLife"}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){typeof e.rotation=="number"&&(e.rotation+=t*this.angularVelocity.genValue(e.memory,e.age/e.life))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(e){return new zs(W(e.angularVelocity))}frameUpdate(e){}clone(){return new zs(this.angularVelocity.clone())}reset(){}}class Os{constructor(e){this.angularVelocity=e,this.type="Rotation3DOverLife",this.tempQuat=new te,this.tempQuat2=new te}initialize(e){e.rotation instanceof te&&(e.angularVelocity=new te,this.angularVelocity.startGen(e.memory))}update(e,t){e.rotation instanceof te&&(this.angularVelocity.genValue(e.memory,this.tempQuat,t,e.age/e.life),e.rotation.multiply(this.tempQuat))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(e){return new Os(hc(e.angularVelocity))}frameUpdate(e){}clone(){return new Os(this.angularVelocity.clone())}reset(){}}class Ts{initialize(e,t){this.ps=t,this.x.startGen(e.memory),this.y.startGen(e.memory),this.z.startGen(e.memory)}constructor(e,t,i){this.x=e,this.y=t,this.z=i,this.type="ForceOverLife",this._temp=new F,this._tempScale=new F,this._tempQ=new te}update(e,t){this._temp.set(this.x.genValue(e.memory,e.age/e.life),this.y.genValue(e.memory,e.age/e.life),this.z.genValue(e.memory,e.age/e.life)),this.ps.worldSpace?e.velocity.addScaledVector(this._temp,t):(this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ),e.velocity.addScaledVector(this._temp,t))}toJSON(){return{type:this.type,x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new Ts(W(e.x),W(e.y),W(e.z))}frameUpdate(e){if(this.ps&&!this.ps.worldSpace){const t=this._temp,i=this._tempQ,s=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,i,s),i.invert(),s.set(1/s.x,1/s.y,1/s.z)}}clone(){return new Ts(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class ks{initialize(e){this.size.startGen(e.memory)}constructor(e){this.size=e,this.type="SizeOverLife"}update(e){this.size instanceof fi?this.size.genValue(e.memory,e.size,e.age/e.life).multiply(e.startSize):e.size.copy(e.startSize).multiplyScalar(this.size.genValue(e.memory,e.age/e.life))}toJSON(){return{type:this.type,size:this.size.toJSON()}}static fromJSON(e){return new ks(Ur(e.size))}frameUpdate(e){}clone(){return new ks(this.size.clone())}reset(){}}class Rs{initialize(e){this.speed.startGen(e.memory)}constructor(e){this.speed=e,this.type="SpeedOverLife"}update(e){e.speedModifier=this.speed.genValue(e.memory,e.age/e.life)}toJSON(){return{type:this.type,speed:this.speed.toJSON()}}static fromJSON(e){return new Rs(W(e.speed))}frameUpdate(e){}clone(){return new Rs(this.speed.clone())}reset(){}}class Is{constructor(e){this.frame=e,this.type="FrameOverLife"}initialize(e){this.frame.startGen(e.memory)}update(e,t){this.frame instanceof _s&&(e.uvTile=this.frame.genValue(e.memory,e.age/e.life))}frameUpdate(e){}toJSON(){return{type:this.type,frame:this.frame.toJSON()}}static fromJSON(e){return new Is(W(e.frame))}clone(){return new Is(this.frame.clone())}reset(){}}class Ls{constructor(e,t=new F(0,1,0)){this.orbitSpeed=e,this.axis=t,this.type="OrbitOverLife",this.temp=new F,this.rotation=new te}initialize(e){this.orbitSpeed.startGen(e.memory)}update(e,t){this.temp.copy(e.position).projectOnVector(this.axis),this.rotation.setFromAxisAngle(this.axis,this.orbitSpeed.genValue(e.memory,e.age/e.life)*t),e.position.sub(this.temp),e.position.applyQuaternion(this.rotation),e.position.add(this.temp)}frameUpdate(e){}toJSON(){return{type:this.type,orbitSpeed:this.orbitSpeed.toJSON(),axis:[this.axis.x,this.axis.y,this.axis.z]}}static fromJSON(e){return new Ls(W(e.orbitSpeed),e.axis?new F(e.axis[0],e.axis[1],e.axis[2]):void 0)}clone(){return new Ls(this.orbitSpeed.clone())}reset(){}}class An{constructor(e){this.data=e,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class cp{constructor(){this.length=0,this.head=this.tail=null}isEmpty(){return this.head===null}clear(){this.length=0,this.head=this.tail=null}front(){return this.head===null?null:this.head.data}back(){return this.tail===null?null:this.tail.data}dequeue(){if(this.head){const e=this.head.data;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,e}}pop(){if(this.tail){const e=this.tail.data;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,e}}queue(e){const t=new An(e);this.tail||(this.tail=t),this.head&&(this.head.prev=t,t.next=this.head),this.head=t,this.length++}push(e){const t=new An(e);this.head||(this.head=t),this.tail&&(this.tail.next=t,t.prev=this.tail),this.tail=t,this.length++}insertBefore(e,t){const i=new An(t);i.next=e,i.prev=e.prev,i.prev!==null&&(i.prev.next=i),i.next.prev=i,e==this.head&&(this.head=i),this.length++}remove(e){if(this.head===null||this.tail===null)return;let t=this.head;for(e===this.head.data&&(this.head=this.head.next),e===this.tail.data&&(this.tail=this.tail.prev);t.next!==null&&t.data!==e;)t=t.next;t.data===e&&(t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.length--)}*values(){let e=this.head;for(;e!==null;)yield e.data,e=e.next}}class hp{constructor(){this.startSpeed=0,this.startColor=new Je,this.startSize=new F(1,1,1),this.position=new F,this.velocity=new F,this.age=0,this.life=1,this.size=new F(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new Je,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class dp{constructor(e,t,i){this.position=e,this.size=t,this.color=i}}class io{constructor(){this.startSpeed=0,this.startColor=new Je,this.startSize=new F(1,1,1),this.position=new F,this.velocity=new F,this.age=0,this.life=1,this.size=new F(1,1,1),this.length=100,this.speedModifier=1,this.color=new Je,this.previous=new cp,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new dp(this.position.clone(),this.size.x,this.color.clone())):this.previous.length>0&&this.previous.dequeue();this.previous.length>this.length;)this.previous.dequeue()}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.previous.clear()}}class Fs{initialize(e){this.width.startGen(e.memory)}constructor(e){this.width=e,this.type="WidthOverLength"}update(e){if(e instanceof io){const t=e.previous.values();for(let i=0;i<e.previous.length;i++){const s=t.next();s.value.size=this.width.genValue(e.memory,(e.previous.length-i)/e.length)}}}frameUpdate(e){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(e){return new Fs(W(e.width))}clone(){return new Fs(this.width.clone())}reset(){}}class Bs{constructor(e,t){this.direction=e,this.magnitude=t,this.type="ApplyForce",this.memory={data:[],dataCount:0},this.magnitudeValue=this.magnitude.genValue(this.memory)}initialize(e){}update(e,t){e.velocity.addScaledVector(this.direction,this.magnitudeValue*t)}frameUpdate(e){this.magnitudeValue=this.magnitude.genValue(this.memory)}toJSON(){return{type:this.type,direction:[this.direction.x,this.direction.y,this.direction.z],magnitude:this.magnitude.toJSON()}}static fromJSON(e){return new Bs(new F(e.direction[0],e.direction[1],e.direction[2]),W(e.magnitude??e.force))}clone(){return new Bs(this.direction.clone(),this.magnitude.clone())}reset(){}}class Ns{constructor(e,t){this.center=e,this.magnitude=t,this.type="GravityForce",this.temp=new F}initialize(e){}update(e,t){this.temp.copy(this.center).sub(e.position).normalize(),e.velocity.addScaledVector(this.temp,this.magnitude/e.position.distanceToSquared(this.center)*t)}frameUpdate(e){}toJSON(){return{type:this.type,center:[this.center.x,this.center.y,this.center.z],magnitude:this.magnitude}}static fromJSON(e){return new Ns(new F(e.center[0],e.center[1],e.center[2]),e.magnitude)}clone(){return new Ns(this.center.clone(),this.magnitude)}reset(){}}class Hs{constructor(e){this.angle=e,this.type="ChangeEmitDirection",this._temp=new F,this._q=new te,this.memory={data:[],dataCount:0}}initialize(e){const t=e.velocity.length();t!=0&&(e.velocity.normalize(),e.velocity.x===0&&e.velocity.y===0?this._temp.set(0,e.velocity.z,0):this._temp.set(-e.velocity.y,e.velocity.x,0),this.angle.startGen(this.memory),this._q.setFromAxisAngle(this._temp.normalize(),this.angle.genValue(this.memory)),this._temp.copy(e.velocity),e.velocity.applyQuaternion(this._q),this._q.setFromAxisAngle(this._temp,Math.random()*Math.PI*2),e.velocity.applyQuaternion(this._q),e.velocity.setLength(t))}update(e,t){}frameUpdate(e){}toJSON(){return{type:this.type,angle:this.angle.toJSON()}}static fromJSON(e){return new Hs(W(e.angle))}clone(){return new Hs(this.angle)}reset(){}}var ki;(function(o){o[o.Death=0]="Death",o[o.Birth=1]="Birth",o[o.Frame=2]="Frame"})(ki||(ki={}));class Ui{constructor(e,t,i,s=ki.Frame,r=1){this.particleSystem=e,this.useVelocityAsBasis=t,this.subParticleSystem=i,this.mode=s,this.emitProbability=r,this.type="EmitSubParticleSystem",this.q_=new te,this.v_=new F,this.v2_=new F,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(e){}update(e,t){this.mode===ki.Frame?this.emit(e,t):this.mode===ki.Birth&&e.age===0?this.emit(e,t):this.mode===ki.Death&&e.age+t>=e.life&&this.emit(e,t)}emit(e,t){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const i=new at;this.setMatrixFromParticle(i,e),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:i,travelDistance:0,particle:e})}frameUpdate(e){if(this.subParticleSystem)for(let t=0;t<this.subEmissions.length;t++)if(this.subEmissions[t].time>=this.subParticleSystem.system.duration)this.subEmissions[t]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,t--;else{const i=this.subEmissions[t];i.particle&&i.particle.age<i.particle.life?this.setMatrixFromParticle(i.matrix,i.particle):i.particle=void 0,this.subParticleSystem.system.emit(e,i,i.matrix)}}toJSON(){return{type:this.type,subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(e,t){return new Ui(t,e.useVelocityAsBasis,e.subParticleSystem,e.mode,e.emitProbability)}clone(){return new Ui(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(e,t){let i;if(t.rotation===void 0||this.useVelocityAsBasis)if(t.velocity.x===0&&t.velocity.y===0&&(t.velocity.z===1||t.velocity.z===0))e.set(1,0,0,t.position.x,0,1,0,t.position.y,0,0,1,t.position.z,0,0,0,1);else{this.v_.copy($a).cross(t.velocity),this.v2_.copy(t.velocity).cross(this.v_);const s=this.v_.length(),r=this.v2_.length();e.set(this.v_.x/s,this.v2_.x/r,t.velocity.x,t.position.x,this.v_.y/s,this.v2_.y/r,t.velocity.y,t.position.y,this.v_.z/s,this.v2_.z/r,t.velocity.z,t.position.z,0,0,0,1)}else t.rotation instanceof te?i=t.rotation:(this.q_.setFromAxisAngle($a,t.rotation),i=this.q_),e.compose(t.position,i,ap);this.particleSystem.worldSpace||e.multiplyMatrices(this.particleSystem.emitter.matrixWorld,e)}}const up=.5*(Math.sqrt(3)-1),os=(3-Math.sqrt(3))/6,pp=1/3,pt=1/6,fp=(Math.sqrt(5)-1)/4,ze=(5-Math.sqrt(5))/20,Ae=new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),Se=new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);class dc{constructor(e=Math.random){const t=typeof e=="function"?e:gp(e);this.p=mp(t),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let i=0;i<512;i++)this.perm[i]=this.p[i&255],this.permMod12[i]=this.perm[i]%12}noise2D(e,t){const i=this.permMod12,s=this.perm;let r=0,n=0,a=0;const l=(e+t)*up,c=Math.floor(e+l),h=Math.floor(t+l),d=(c+h)*os,p=c-d,u=h-d,f=e-p,m=t-u;let y,_;f>m?(y=1,_=0):(y=0,_=1);const x=f-y+os,S=m-_+os,w=f-1+2*os,C=m-1+2*os,b=c&255,M=h&255;let P=.5-f*f-m*m;if(P>=0){const N=i[b+s[M]]*3;P*=P,r=P*P*(Ae[N]*f+Ae[N+1]*m)}let E=.5-x*x-S*S;if(E>=0){const N=i[b+y+s[M+_]]*3;E*=E,n=E*E*(Ae[N]*x+Ae[N+1]*S)}let R=.5-w*w-C*C;if(R>=0){const N=i[b+1+s[M+1]]*3;R*=R,a=R*R*(Ae[N]*w+Ae[N+1]*C)}return 70*(r+n+a)}noise3D(e,t,i){const s=this.permMod12,r=this.perm;let n,a,l,c;const h=(e+t+i)*pp,d=Math.floor(e+h),p=Math.floor(t+h),u=Math.floor(i+h),f=(d+p+u)*pt,m=d-f,y=p-f,_=u-f,x=e-m,S=t-y,w=i-_;let C,b,M,P,E,R;x>=S?S>=w?(C=1,b=0,M=0,P=1,E=1,R=0):x>=w?(C=1,b=0,M=0,P=1,E=0,R=1):(C=0,b=0,M=1,P=1,E=0,R=1):S<w?(C=0,b=0,M=1,P=0,E=1,R=1):x<w?(C=0,b=1,M=0,P=0,E=1,R=1):(C=0,b=1,M=0,P=1,E=1,R=0);const N=x-C+pt,se=S-b+pt,ye=w-M+pt,q=x-P+2*pt,X=S-E+2*pt,re=w-R+2*pt,j=x-1+3*pt,$=S-1+3*pt,J=w-1+3*pt,ne=d&255,Q=p&255,fe=u&255;let Ee=.6-x*x-S*S-w*w;if(Ee<0)n=0;else{const _e=s[ne+r[Q+r[fe]]]*3;Ee*=Ee,n=Ee*Ee*(Ae[_e]*x+Ae[_e+1]*S+Ae[_e+2]*w)}let be=.6-N*N-se*se-ye*ye;if(be<0)a=0;else{const _e=s[ne+C+r[Q+b+r[fe+M]]]*3;be*=be,a=be*be*(Ae[_e]*N+Ae[_e+1]*se+Ae[_e+2]*ye)}let Be=.6-q*q-X*X-re*re;if(Be<0)l=0;else{const _e=s[ne+P+r[Q+E+r[fe+R]]]*3;Be*=Be,l=Be*Be*(Ae[_e]*q+Ae[_e+1]*X+Ae[_e+2]*re)}let Ne=.6-j*j-$*$-J*J;if(Ne<0)c=0;else{const _e=s[ne+1+r[Q+1+r[fe+1]]]*3;Ne*=Ne,c=Ne*Ne*(Ae[_e]*j+Ae[_e+1]*$+Ae[_e+2]*J)}return 32*(n+a+l+c)}noise4D(e,t,i,s){const r=this.perm;let n,a,l,c,h;const d=(e+t+i+s)*fp,p=Math.floor(e+d),u=Math.floor(t+d),f=Math.floor(i+d),m=Math.floor(s+d),y=(p+u+f+m)*ze,_=p-y,x=u-y,S=f-y,w=m-y,C=e-_,b=t-x,M=i-S,P=s-w;let E=0,R=0,N=0,se=0;C>b?E++:R++,C>M?E++:N++,C>P?E++:se++,b>M?R++:N++,b>P?R++:se++,M>P?N++:se++;const ye=E>=3?1:0,q=R>=3?1:0,X=N>=3?1:0,re=se>=3?1:0,j=E>=2?1:0,$=R>=2?1:0,J=N>=2?1:0,ne=se>=2?1:0,Q=E>=1?1:0,fe=R>=1?1:0,Ee=N>=1?1:0,be=se>=1?1:0,Be=C-ye+ze,Ne=b-q+ze,_e=M-X+ze,Jt=P-re+ze,Yt=C-j+2*ze,he=b-$+2*ze,$e=M-J+2*ze,ce=P-ne+2*ze,lt=C-Q+3*ze,Zt=b-fe+3*ze,gi=M-Ee+3*ze,ct=P-be+3*ze,Qt=C-1+4*ze,$t=b-1+4*ze,yi=M-1+4*ze,Kt=P-1+4*ze,zt=p&255,Ot=u&255,Tt=f&255,bt=m&255;let kt=.6-C*C-b*b-M*M-P*P;if(kt<0)n=0;else{const oe=r[zt+r[Ot+r[Tt+r[bt]]]]%32*4;kt*=kt,n=kt*kt*(Se[oe]*C+Se[oe+1]*b+Se[oe+2]*M+Se[oe+3]*P)}let Rt=.6-Be*Be-Ne*Ne-_e*_e-Jt*Jt;if(Rt<0)a=0;else{const oe=r[zt+ye+r[Ot+q+r[Tt+X+r[bt+re]]]]%32*4;Rt*=Rt,a=Rt*Rt*(Se[oe]*Be+Se[oe+1]*Ne+Se[oe+2]*_e+Se[oe+3]*Jt)}let ht=.6-Yt*Yt-he*he-$e*$e-ce*ce;if(ht<0)l=0;else{const oe=r[zt+j+r[Ot+$+r[Tt+J+r[bt+ne]]]]%32*4;ht*=ht,l=ht*ht*(Se[oe]*Yt+Se[oe+1]*he+Se[oe+2]*$e+Se[oe+3]*ce)}let It=.6-lt*lt-Zt*Zt-gi*gi-ct*ct;if(It<0)c=0;else{const oe=r[zt+Q+r[Ot+fe+r[Tt+Ee+r[bt+be]]]]%32*4;It*=It,c=It*It*(Se[oe]*lt+Se[oe+1]*Zt+Se[oe+2]*gi+Se[oe+3]*ct)}let Lt=.6-Qt*Qt-$t*$t-yi*yi-Kt*Kt;if(Lt<0)h=0;else{const oe=r[zt+1+r[Ot+1+r[Tt+1+r[bt+1]]]]%32*4;Lt*=Lt,h=Lt*Lt*(Se[oe]*Qt+Se[oe+1]*$t+Se[oe+2]*yi+Se[oe+3]*Kt)}return 27*(n+a+l+c+h)}}function mp(o){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let t=0;t<255;t++){const i=t+~~(o()*(256-t)),s=e[t];e[t]=e[i],e[i]=s}return e}function gp(o){let e=0,t=0,i=0,s=1;const r=yp();return e=r(" "),t=r(" "),i=r(" "),e-=r(o),e<0&&(e+=1),t-=r(o),t<0&&(t+=1),i-=r(o),i<0&&(i+=1),function(){const n=2091639*e+s*23283064365386963e-26;return e=t,t=i,i=n-(s=n|0)}}function yp(){let o=4022871197;return function(e){e=e.toString();for(let t=0;t<e.length;t++){o+=e.charCodeAt(t);let i=.02519603282416938*o;o=i>>>0,i-=o,i*=o,o=i>>>0,i-=o,o+=i*4294967296}return(o>>>0)*23283064365386963e-26}}class Ds{constructor(e,t,i,s){this.scale=e,this.octaves=t,this.velocityMultiplier=i,this.timeScale=s,this.type="TurbulenceField",this.generator=new dc,this.timeOffset=new F,this.temp=new F,this.temp2=new F,this.timeOffset.x=Math.random()/this.scale.x*this.timeScale.x,this.timeOffset.y=Math.random()/this.scale.y*this.timeScale.y,this.timeOffset.z=Math.random()/this.scale.z*this.timeScale.z}initialize(e){}update(e,t){const i=e.position.x/this.scale.x,s=e.position.y/this.scale.y,r=e.position.z/this.scale.z;this.temp.set(0,0,0);let n=1;for(let a=0;a<this.octaves;a++)this.temp2.set(this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.x*n)/n,this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.y*n)/n,this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.z*n)/n),this.temp.add(this.temp2),n*=2;this.temp.multiply(this.velocityMultiplier),e.velocity.addScaledVector(this.temp,t)}toJSON(){return{type:this.type,scale:[this.scale.x,this.scale.y,this.scale.z],octaves:this.octaves,velocityMultiplier:[this.velocityMultiplier.x,this.velocityMultiplier.y,this.velocityMultiplier.z],timeScale:[this.timeScale.x,this.timeScale.y,this.timeScale.z]}}frameUpdate(e){this.timeOffset.x+=e*this.timeScale.x,this.timeOffset.y+=e*this.timeScale.y,this.timeOffset.z+=e*this.timeScale.z}static fromJSON(e){return new Ds(new F(e.scale[0],e.scale[1],e.scale[2]),e.octaves,new F(e.velocityMultiplier[0],e.velocityMultiplier[1],e.velocityMultiplier[2]),new F(e.timeScale[0],e.timeScale[1],e.timeScale[2]))}clone(){return new Ds(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const ft=[],En=new F,zn=new te;class Vs{constructor(e,t,i=new ie(1),s=new ie(0)){if(this.frequency=e,this.power=t,this.positionAmount=i,this.rotationAmount=s,this.type="Noise",this.duration=0,ft.length===0)for(let r=0;r<100;r++)ft.push(new dc)}initialize(e){e.lastPosNoise=new F,typeof e.rotation=="number"?e.lastRotNoise=0:e.lastRotNoise=new te,e.generatorIndex=[Mr(0,100),Mr(0,100),Mr(0,100),Mr(0,100)],this.positionAmount.startGen(e.memory),this.rotationAmount.startGen(e.memory),this.frequency.startGen(e.memory),this.power.startGen(e.memory)}update(e,t){let i=this.frequency.genValue(e.memory,e.age/e.life),s=this.power.genValue(e.memory,e.age/e.life),r=this.positionAmount.genValue(e.memory,e.age/e.life),n=this.rotationAmount.genValue(e.memory,e.age/e.life);r>0&&e.lastPosNoise!==void 0&&(e.position.sub(e.lastPosNoise),En.set(ft[e.generatorIndex[0]].noise2D(0,e.age*i)*s*r,ft[e.generatorIndex[1]].noise2D(0,e.age*i)*s*r,ft[e.generatorIndex[2]].noise2D(0,e.age*i)*s*r),e.position.add(En),e.lastPosNoise.copy(En)),n>0&&e.lastRotNoise!==void 0&&(typeof e.rotation=="number"?(e.rotation-=e.lastRotNoise,e.rotation+=ft[e.generatorIndex[3]].noise2D(0,e.age*i)*Math.PI*s*n):(e.lastRotNoise.invert(),e.rotation.multiply(e.lastRotNoise),zn.set(ft[e.generatorIndex[0]].noise2D(0,e.age*i)*s*n,ft[e.generatorIndex[1]].noise2D(0,e.age*i)*s*n,ft[e.generatorIndex[2]].noise2D(0,e.age*i)*s*n,ft[e.generatorIndex[3]].noise2D(0,e.age*i)*s*n).normalize(),e.rotation.multiply(zn),e.lastRotNoise.copy(zn)))}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON()}}frameUpdate(e){this.duration+=e}static fromJSON(e){return new Vs(W(e.frequency),W(e.power),W(e.positionAmount),W(e.rotationAmount))}clone(){return new Vs(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Us{constructor(e,t){this.color=e,this.speedRange=t,this.type="ColorBySpeed"}initialize(e){this.color.startGen(e.memory)}update(e,t){const i=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(e.memory,e.color,i),e.color.x*=e.startColor.x,e.color.y*=e.startColor.y,e.color.z*=e.startColor.z,e.color.w*=e.startColor.w}frameUpdate(e){}toJSON(){return{type:this.type,color:this.color.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Us(wo(e.color),pi.fromJSON(e.speedRange))}clone(){return new Us(this.color.clone(),this.speedRange.clone())}reset(){}}class js{initialize(e){this.size.startGen(e.memory)}constructor(e,t){this.size=e,this.speedRange=t,this.type="SizeBySpeed"}update(e){const t=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.size instanceof fi?this.size.genValue(e.memory,e.size,t).multiply(e.startSize):e.size.copy(e.startSize).multiplyScalar(this.size.genValue(e.memory,t))}toJSON(){return{type:this.type,size:this.size.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new js(Ur(e.size),pi.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new js(this.size.clone(),this.speedRange.clone())}reset(){}}class Gs{constructor(e,t){this.angularVelocity=e,this.speedRange=t,this.type="RotationBySpeed",this.tempQuat=new te}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){if(typeof e.rotation=="number"){const i=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);e.rotation+=t*this.angularVelocity.genValue(e.memory,i)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Gs(W(e.angularVelocity),pi.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Gs(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class Ws{initialize(e){this.speed.startGen(e.memory)}constructor(e,t){this.speed=e,this.dampen=t,this.type="LimitSpeedOverLife"}update(e,t){let i=e.velocity.length(),s=this.speed.genValue(e.memory,e.age/e.life);if(i>s){const r=(i-s)/i;e.velocity.multiplyScalar(1-r*this.dampen*t*20)}}toJSON(){return{type:this.type,speed:this.speed.toJSON(),dampen:this.dampen}}static fromJSON(e){return new Ws(W(e.speed),e.dampen)}frameUpdate(e){}clone(){return new Ws(this.speed.clone(),this.dampen)}reset(){}}const jr={ApplyForce:{type:"ApplyForce",constructor:Bs,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Bs.fromJSON},Noise:{type:"Noise",constructor:Vs,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Vs.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Ds,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Ds.fromJSON},GravityForce:{type:"GravityForce",constructor:Ns,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:Ns.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:Es,params:[["color",["colorFunc"]]],loadJSON:Es.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:zs,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:zs.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Os,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Os.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:ks,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:ks.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:Us,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:Us.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Gs,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Gs.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:js,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:js.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Rs,params:[["speed",["value","valueFunc"]]],loadJSON:Rs.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:Is,params:[["frame",["value","valueFunc"]]],loadJSON:Is.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:Ts,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:Ts.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:Ls,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:Ls.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Fs,params:[["width",["value","valueFunc"]]],loadJSON:Fs.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:Hs,params:[["angle",["value"]]],loadJSON:Hs.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:Ui,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:Ui.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:Ws,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:Ws.fromJSON}};function _p(o,e){return jr[o.type]?jr[o.type].loadJSON(o,e):null}const vp=[];function wp(o){if(!vp.find(t=>t.id===o.id)){for(const t of o.emitterShapes)to[t.type]||(to[t.type]=t);for(const t of o.behaviors)jr[t.type]||(jr[t.type]=t)}}class Xs{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new Dd;this._triangleIndexToArea.length=0;let i=0;if(!e.getIndex())return;const s=e.getIndex().array,r=s.length/3;this._triangleIndexToArea.push(0);for(let n=0;n<r;n++)t.setFromAttributeAndIndices(e.getAttribute("position"),s[n*3],s[n*3+1],s[n*3+2]),i+=t.getArea(),this._triangleIndexToArea.push(i);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new v,this._tempB=new v,this._tempC=new v,e&&(this.geometry=e)}initialize(e){const t=this._geometry;if(!t||t.getIndex()===null){e.position.set(0,0,0),e.velocity.set(0,0,1).multiplyScalar(e.startSpeed);return}const i=this._triangleIndexToArea.length-1;let s=0,r=i;const n=Math.random()*this._triangleIndexToArea[i];for(;s+1<r;){const u=Math.floor((s+r)/2);n<this._triangleIndexToArea[u]?r=u:s=u}let a=Math.random(),l=Math.random();a+l>1&&(a=1-a,l=1-l);const c=t.getIndex().array[s*3],h=t.getIndex().array[s*3+1],d=t.getIndex().array[s*3+2],p=t.getAttribute("position");this._tempA.fromBufferAttribute(p,c),this._tempB.fromBufferAttribute(p,h),this._tempC.fromBufferAttribute(p,d),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,a).addScaledVector(this._tempC,l),e.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),e.velocity.copy(this._tempA).normalize().multiplyScalar(e.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(e,t){return new Xs(t.geometries[e.geometry])}clone(){return new Xs(this._geometry)}update(e,t){}}const xp={id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Xs,loadJSON:Xs.fromJSON}],behaviors:[]};var bp=`
|
|
3
|
+
#ifdef SOFT_PARTICLES
|
|
4
|
+
|
|
5
|
+
/* #ifdef LOGDEPTH
|
|
6
|
+
float distSample = linearize_depth_log(sampleDepth, near, far);
|
|
7
|
+
#else
|
|
8
|
+
float distSample = ortho ? linearize_depth_ortho(sampleDepth, near, far) : linearize_depth(sampleDepth, near, far);
|
|
9
|
+
#endif */
|
|
10
|
+
|
|
11
|
+
vec2 p2 = projPosition.xy / projPosition.w;
|
|
12
|
+
|
|
13
|
+
p2 = 0.5 * p2 + 0.5;
|
|
14
|
+
|
|
15
|
+
float readDepth = texture2D(depthTexture, p2.xy).r;
|
|
16
|
+
float viewDepth = linearize_depth(readDepth);
|
|
17
|
+
|
|
18
|
+
float softParticlesFade = saturate(SOFT_INV_FADE_DISTANCE * ((viewDepth - SOFT_NEAR_FADE) - linearDepth));
|
|
19
|
+
|
|
20
|
+
gl_FragColor *= softParticlesFade;
|
|
21
|
+
|
|
22
|
+
//gl_FragColor = vec4(softParticlesFade , 0, 0, 1);
|
|
23
|
+
#endif
|
|
24
|
+
`,Sp=`
|
|
25
|
+
#ifdef SOFT_PARTICLES
|
|
26
|
+
|
|
27
|
+
uniform sampler2D depthTexture;
|
|
28
|
+
uniform vec4 projParams;
|
|
29
|
+
uniform vec2 softParams;
|
|
30
|
+
|
|
31
|
+
varying vec4 projPosition;
|
|
32
|
+
varying float linearDepth;
|
|
33
|
+
|
|
34
|
+
#define SOFT_NEAR_FADE softParams.x
|
|
35
|
+
#define SOFT_INV_FADE_DISTANCE softParams.y
|
|
36
|
+
|
|
37
|
+
#define zNear projParams.x
|
|
38
|
+
#define zFar projParams.y
|
|
39
|
+
|
|
40
|
+
float linearize_depth(float d)
|
|
41
|
+
{
|
|
42
|
+
return (zFar * zNear) / (zFar - d * (zFar - zNear));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#endif
|
|
46
|
+
`,Mp=`
|
|
47
|
+
#ifdef SOFT_PARTICLES
|
|
48
|
+
varying vec4 projPosition;
|
|
49
|
+
varying float linearDepth;
|
|
50
|
+
#endif
|
|
51
|
+
`,Cp=`
|
|
52
|
+
#ifdef SOFT_PARTICLES
|
|
53
|
+
projPosition = gl_Position;
|
|
54
|
+
linearDepth = -mvPosition.z;
|
|
55
|
+
#endif
|
|
56
|
+
`,Pp=`
|
|
57
|
+
#ifdef USE_MAP
|
|
58
|
+
vec4 texelColor = texture2D( map, vUv);
|
|
59
|
+
#ifdef TILE_BLEND
|
|
60
|
+
texelColor = mix( texelColor, texture2D( map, vUvNext ), vUvBlend );
|
|
61
|
+
#endif
|
|
62
|
+
diffuseColor *= texelColor;
|
|
63
|
+
#endif
|
|
64
|
+
`,Ap=`
|
|
65
|
+
#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
66
|
+
|
|
67
|
+
varying vec2 vUv;
|
|
68
|
+
#ifdef TILE_BLEND
|
|
69
|
+
varying vec2 vUvNext;
|
|
70
|
+
varying float vUvBlend;
|
|
71
|
+
#endif
|
|
72
|
+
|
|
73
|
+
#endif
|
|
74
|
+
#ifdef USE_MAP
|
|
75
|
+
|
|
76
|
+
uniform mat3 mapTransform;
|
|
77
|
+
varying vec2 vMapUv;
|
|
78
|
+
#ifdef TILE_BLEND
|
|
79
|
+
varying vec2 vMapUvNext;
|
|
80
|
+
#endif
|
|
81
|
+
|
|
82
|
+
#endif
|
|
83
|
+
#ifdef USE_ALPHAMAP
|
|
84
|
+
|
|
85
|
+
uniform mat3 alphaMapTransform;
|
|
86
|
+
varying vec2 vAlphaMapUv;
|
|
87
|
+
|
|
88
|
+
#endif
|
|
89
|
+
#ifdef USE_LIGHTMAP
|
|
90
|
+
|
|
91
|
+
uniform mat3 lightMapTransform;
|
|
92
|
+
varying vec2 vLightMapUv;
|
|
93
|
+
|
|
94
|
+
#endif
|
|
95
|
+
#ifdef USE_AOMAP
|
|
96
|
+
|
|
97
|
+
uniform mat3 aoMapTransform;
|
|
98
|
+
varying vec2 vAoMapUv;
|
|
99
|
+
|
|
100
|
+
#endif
|
|
101
|
+
#ifdef USE_BUMPMAP
|
|
102
|
+
|
|
103
|
+
uniform mat3 bumpMapTransform;
|
|
104
|
+
varying vec2 vBumpMapUv;
|
|
105
|
+
|
|
106
|
+
#endif
|
|
107
|
+
#ifdef USE_NORMALMAP
|
|
108
|
+
|
|
109
|
+
uniform mat3 normalMapTransform;
|
|
110
|
+
varying vec2 vNormalMapUv;
|
|
111
|
+
|
|
112
|
+
#endif
|
|
113
|
+
#ifdef USE_DISPLACEMENTMAP
|
|
114
|
+
|
|
115
|
+
uniform mat3 displacementMapTransform;
|
|
116
|
+
varying vec2 vDisplacementMapUv;
|
|
117
|
+
|
|
118
|
+
#endif
|
|
119
|
+
#ifdef USE_EMISSIVEMAP
|
|
120
|
+
|
|
121
|
+
uniform mat3 emissiveMapTransform;
|
|
122
|
+
varying vec2 vEmissiveMapUv;
|
|
123
|
+
|
|
124
|
+
#endif
|
|
125
|
+
#ifdef USE_METALNESSMAP
|
|
126
|
+
|
|
127
|
+
uniform mat3 metalnessMapTransform;
|
|
128
|
+
varying vec2 vMetalnessMapUv;
|
|
129
|
+
|
|
130
|
+
#endif
|
|
131
|
+
#ifdef USE_ROUGHNESSMAP
|
|
132
|
+
|
|
133
|
+
uniform mat3 roughnessMapTransform;
|
|
134
|
+
varying vec2 vRoughnessMapUv;
|
|
135
|
+
|
|
136
|
+
#endif
|
|
137
|
+
#ifdef USE_ANISOTROPYMAP
|
|
138
|
+
|
|
139
|
+
uniform mat3 anisotropyMapTransform;
|
|
140
|
+
varying vec2 vAnisotropyMapUv;
|
|
141
|
+
|
|
142
|
+
#endif
|
|
143
|
+
#ifdef USE_CLEARCOATMAP
|
|
144
|
+
|
|
145
|
+
uniform mat3 clearcoatMapTransform;
|
|
146
|
+
varying vec2 vClearcoatMapUv;
|
|
147
|
+
|
|
148
|
+
#endif
|
|
149
|
+
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
150
|
+
|
|
151
|
+
uniform mat3 clearcoatNormalMapTransform;
|
|
152
|
+
varying vec2 vClearcoatNormalMapUv;
|
|
153
|
+
|
|
154
|
+
#endif
|
|
155
|
+
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
156
|
+
|
|
157
|
+
uniform mat3 clearcoatRoughnessMapTransform;
|
|
158
|
+
varying vec2 vClearcoatRoughnessMapUv;
|
|
159
|
+
|
|
160
|
+
#endif
|
|
161
|
+
#ifdef USE_SHEEN_COLORMAP
|
|
162
|
+
|
|
163
|
+
uniform mat3 sheenColorMapTransform;
|
|
164
|
+
varying vec2 vSheenColorMapUv;
|
|
165
|
+
|
|
166
|
+
#endif
|
|
167
|
+
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
168
|
+
|
|
169
|
+
uniform mat3 sheenRoughnessMapTransform;
|
|
170
|
+
varying vec2 vSheenRoughnessMapUv;
|
|
171
|
+
|
|
172
|
+
#endif
|
|
173
|
+
#ifdef USE_IRIDESCENCEMAP
|
|
174
|
+
|
|
175
|
+
uniform mat3 iridescenceMapTransform;
|
|
176
|
+
varying vec2 vIridescenceMapUv;
|
|
177
|
+
|
|
178
|
+
#endif
|
|
179
|
+
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
180
|
+
|
|
181
|
+
uniform mat3 iridescenceThicknessMapTransform;
|
|
182
|
+
varying vec2 vIridescenceThicknessMapUv;
|
|
183
|
+
|
|
184
|
+
#endif
|
|
185
|
+
#ifdef USE_SPECULARMAP
|
|
186
|
+
|
|
187
|
+
uniform mat3 specularMapTransform;
|
|
188
|
+
varying vec2 vSpecularMapUv;
|
|
189
|
+
|
|
190
|
+
#endif
|
|
191
|
+
#ifdef USE_SPECULAR_COLORMAP
|
|
192
|
+
|
|
193
|
+
uniform mat3 specularColorMapTransform;
|
|
194
|
+
varying vec2 vSpecularColorMapUv;
|
|
195
|
+
|
|
196
|
+
#endif
|
|
197
|
+
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
198
|
+
|
|
199
|
+
uniform mat3 specularIntensityMapTransform;
|
|
200
|
+
varying vec2 vSpecularIntensityMapUv;
|
|
201
|
+
|
|
202
|
+
#endif
|
|
203
|
+
#ifdef USE_TRANSMISSIONMAP
|
|
204
|
+
|
|
205
|
+
uniform mat3 transmissionMapTransform;
|
|
206
|
+
varying vec2 vTransmissionMapUv;
|
|
207
|
+
|
|
208
|
+
#endif
|
|
209
|
+
#ifdef USE_THICKNESSMAP
|
|
210
|
+
|
|
211
|
+
uniform mat3 thicknessMapTransform;
|
|
212
|
+
varying vec2 vThicknessMapUv;
|
|
213
|
+
|
|
214
|
+
#endif
|
|
215
|
+
`,Ep=`
|
|
216
|
+
#ifdef UV_TILE
|
|
217
|
+
attribute float uvTile;
|
|
218
|
+
uniform vec2 tileCount;
|
|
219
|
+
|
|
220
|
+
mat3 makeTileTransform(float uvTile) {
|
|
221
|
+
float col = mod(uvTile, tileCount.x);
|
|
222
|
+
float row = (tileCount.y - floor(uvTile / tileCount.x) - 1.0);
|
|
223
|
+
|
|
224
|
+
return mat3(
|
|
225
|
+
1.0 / tileCount.x, 0.0, 0.0,
|
|
226
|
+
0.0, 1.0 / tileCount.y, 0.0,
|
|
227
|
+
col / tileCount.x, row / tileCount.y, 1.0);
|
|
228
|
+
}
|
|
229
|
+
#else
|
|
230
|
+
mat3 makeTileTransform(float uvTile) {
|
|
231
|
+
return mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
|
|
232
|
+
}
|
|
233
|
+
#endif
|
|
234
|
+
|
|
235
|
+
#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
236
|
+
|
|
237
|
+
varying vec2 vUv;
|
|
238
|
+
#ifdef TILE_BLEND
|
|
239
|
+
varying vec2 vUvNext;
|
|
240
|
+
varying float vUvBlend;
|
|
241
|
+
#endif
|
|
242
|
+
|
|
243
|
+
#endif
|
|
244
|
+
#ifdef USE_MAP
|
|
245
|
+
|
|
246
|
+
uniform mat3 mapTransform;
|
|
247
|
+
varying vec2 vMapUv;
|
|
248
|
+
#ifdef TILE_BLEND
|
|
249
|
+
varying vec2 vMapUvNext;
|
|
250
|
+
#endif
|
|
251
|
+
|
|
252
|
+
#endif
|
|
253
|
+
#ifdef USE_ALPHAMAP
|
|
254
|
+
|
|
255
|
+
uniform mat3 alphaMapTransform;
|
|
256
|
+
varying vec2 vAlphaMapUv;
|
|
257
|
+
|
|
258
|
+
#endif
|
|
259
|
+
#ifdef USE_LIGHTMAP
|
|
260
|
+
|
|
261
|
+
uniform mat3 lightMapTransform;
|
|
262
|
+
varying vec2 vLightMapUv;
|
|
263
|
+
|
|
264
|
+
#endif
|
|
265
|
+
#ifdef USE_AOMAP
|
|
266
|
+
|
|
267
|
+
uniform mat3 aoMapTransform;
|
|
268
|
+
varying vec2 vAoMapUv;
|
|
269
|
+
|
|
270
|
+
#endif
|
|
271
|
+
#ifdef USE_BUMPMAP
|
|
272
|
+
|
|
273
|
+
uniform mat3 bumpMapTransform;
|
|
274
|
+
varying vec2 vBumpMapUv;
|
|
275
|
+
|
|
276
|
+
#endif
|
|
277
|
+
#ifdef USE_NORMALMAP
|
|
278
|
+
|
|
279
|
+
uniform mat3 normalMapTransform;
|
|
280
|
+
varying vec2 vNormalMapUv;
|
|
281
|
+
|
|
282
|
+
#endif
|
|
283
|
+
#ifdef USE_DISPLACEMENTMAP
|
|
284
|
+
|
|
285
|
+
uniform mat3 displacementMapTransform;
|
|
286
|
+
varying vec2 vDisplacementMapUv;
|
|
287
|
+
|
|
288
|
+
#endif
|
|
289
|
+
#ifdef USE_EMISSIVEMAP
|
|
290
|
+
|
|
291
|
+
uniform mat3 emissiveMapTransform;
|
|
292
|
+
varying vec2 vEmissiveMapUv;
|
|
293
|
+
|
|
294
|
+
#endif
|
|
295
|
+
#ifdef USE_METALNESSMAP
|
|
296
|
+
|
|
297
|
+
uniform mat3 metalnessMapTransform;
|
|
298
|
+
varying vec2 vMetalnessMapUv;
|
|
299
|
+
|
|
300
|
+
#endif
|
|
301
|
+
#ifdef USE_ROUGHNESSMAP
|
|
302
|
+
|
|
303
|
+
uniform mat3 roughnessMapTransform;
|
|
304
|
+
varying vec2 vRoughnessMapUv;
|
|
305
|
+
|
|
306
|
+
#endif
|
|
307
|
+
#ifdef USE_ANISOTROPYMAP
|
|
308
|
+
|
|
309
|
+
uniform mat3 anisotropyMapTransform;
|
|
310
|
+
varying vec2 vAnisotropyMapUv;
|
|
311
|
+
|
|
312
|
+
#endif
|
|
313
|
+
#ifdef USE_CLEARCOATMAP
|
|
314
|
+
|
|
315
|
+
uniform mat3 clearcoatMapTransform;
|
|
316
|
+
varying vec2 vClearcoatMapUv;
|
|
317
|
+
|
|
318
|
+
#endif
|
|
319
|
+
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
320
|
+
|
|
321
|
+
uniform mat3 clearcoatNormalMapTransform;
|
|
322
|
+
varying vec2 vClearcoatNormalMapUv;
|
|
323
|
+
|
|
324
|
+
#endif
|
|
325
|
+
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
326
|
+
|
|
327
|
+
uniform mat3 clearcoatRoughnessMapTransform;
|
|
328
|
+
varying vec2 vClearcoatRoughnessMapUv;
|
|
329
|
+
|
|
330
|
+
#endif
|
|
331
|
+
#ifdef USE_SHEEN_COLORMAP
|
|
332
|
+
|
|
333
|
+
uniform mat3 sheenColorMapTransform;
|
|
334
|
+
varying vec2 vSheenColorMapUv;
|
|
335
|
+
|
|
336
|
+
#endif
|
|
337
|
+
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
338
|
+
|
|
339
|
+
uniform mat3 sheenRoughnessMapTransform;
|
|
340
|
+
varying vec2 vSheenRoughnessMapUv;
|
|
341
|
+
|
|
342
|
+
#endif
|
|
343
|
+
#ifdef USE_IRIDESCENCEMAP
|
|
344
|
+
|
|
345
|
+
uniform mat3 iridescenceMapTransform;
|
|
346
|
+
varying vec2 vIridescenceMapUv;
|
|
347
|
+
|
|
348
|
+
#endif
|
|
349
|
+
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
350
|
+
|
|
351
|
+
uniform mat3 iridescenceThicknessMapTransform;
|
|
352
|
+
varying vec2 vIridescenceThicknessMapUv;
|
|
353
|
+
|
|
354
|
+
#endif
|
|
355
|
+
#ifdef USE_SPECULARMAP
|
|
356
|
+
|
|
357
|
+
uniform mat3 specularMapTransform;
|
|
358
|
+
varying vec2 vSpecularMapUv;
|
|
359
|
+
|
|
360
|
+
#endif
|
|
361
|
+
#ifdef USE_SPECULAR_COLORMAP
|
|
362
|
+
|
|
363
|
+
uniform mat3 specularColorMapTransform;
|
|
364
|
+
varying vec2 vSpecularColorMapUv;
|
|
365
|
+
|
|
366
|
+
#endif
|
|
367
|
+
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
368
|
+
|
|
369
|
+
uniform mat3 specularIntensityMapTransform;
|
|
370
|
+
varying vec2 vSpecularIntensityMapUv;
|
|
371
|
+
|
|
372
|
+
#endif
|
|
373
|
+
#ifdef USE_TRANSMISSIONMAP
|
|
374
|
+
|
|
375
|
+
uniform mat3 transmissionMapTransform;
|
|
376
|
+
varying vec2 vTransmissionMapUv;
|
|
377
|
+
|
|
378
|
+
#endif
|
|
379
|
+
#ifdef USE_THICKNESSMAP
|
|
380
|
+
|
|
381
|
+
uniform mat3 thicknessMapTransform;
|
|
382
|
+
varying vec2 vThicknessMapUv;
|
|
383
|
+
|
|
384
|
+
#endif
|
|
385
|
+
`,zp=`
|
|
386
|
+
#ifdef UV_TILE
|
|
387
|
+
mat3 tileTransform = makeTileTransform(floor(uvTile));
|
|
388
|
+
#ifdef TILE_BLEND
|
|
389
|
+
mat3 nextTileTransform = makeTileTransform(ceil(uvTile));
|
|
390
|
+
vUvBlend = fract(uvTile);
|
|
391
|
+
#endif
|
|
392
|
+
#else
|
|
393
|
+
mat3 tileTransform = makeTileTransform(0.0);
|
|
394
|
+
#endif
|
|
395
|
+
|
|
396
|
+
#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
397
|
+
|
|
398
|
+
vUv = (tileTransform *vec3( uv, 1 )).xy;
|
|
399
|
+
#if defined( TILE_BLEND ) && defined( UV_TILE )
|
|
400
|
+
vUvNext = (nextTileTransform *vec3( uv, 1 )).xy;
|
|
401
|
+
#endif
|
|
402
|
+
|
|
403
|
+
#endif
|
|
404
|
+
#ifdef USE_MAP
|
|
405
|
+
|
|
406
|
+
vMapUv = ( tileTransform * (mapTransform * vec3( MAP_UV, 1 ) )).xy;
|
|
407
|
+
#if defined( TILE_BLEND ) && defined( UV_TILE )
|
|
408
|
+
vMapUvNext = (nextTileTransform * (mapTransform * vec3( MAP_UV, 1 ))).xy;
|
|
409
|
+
#endif
|
|
410
|
+
|
|
411
|
+
#endif
|
|
412
|
+
#ifdef USE_ALPHAMAP
|
|
413
|
+
|
|
414
|
+
vAlphaMapUv = ( tileTransform * (alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) )).xy;
|
|
415
|
+
|
|
416
|
+
#endif
|
|
417
|
+
#ifdef USE_LIGHTMAP
|
|
418
|
+
|
|
419
|
+
vLightMapUv = ( tileTransform * (lightMapTransform * vec3( LIGHTMAP_UV, 1 ) )).xy;
|
|
420
|
+
|
|
421
|
+
#endif
|
|
422
|
+
#ifdef USE_AOMAP
|
|
423
|
+
|
|
424
|
+
vAoMapUv = ( tileTransform * (aoMapTransform * vec3( AOMAP_UV, 1 ) )).xy;
|
|
425
|
+
|
|
426
|
+
#endif
|
|
427
|
+
#ifdef USE_BUMPMAP
|
|
428
|
+
|
|
429
|
+
vBumpMapUv = ( tileTransform * (bumpMapTransform * vec3( BUMPMAP_UV, 1 ) )).xy;
|
|
430
|
+
|
|
431
|
+
#endif
|
|
432
|
+
#ifdef USE_NORMALMAP
|
|
433
|
+
|
|
434
|
+
vNormalMapUv = ( tileTransform * (normalMapTransform * vec3( NORMALMAP_UV, 1 ) )).xy;
|
|
435
|
+
|
|
436
|
+
#endif
|
|
437
|
+
#ifdef USE_DISPLACEMENTMAP
|
|
438
|
+
|
|
439
|
+
vDisplacementMapUv = ( tileTransform * (displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) )).xy;
|
|
440
|
+
|
|
441
|
+
#endif
|
|
442
|
+
#ifdef USE_EMISSIVEMAP
|
|
443
|
+
|
|
444
|
+
vEmissiveMapUv = ( tileTransform * (emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) )).xy;
|
|
445
|
+
|
|
446
|
+
#endif
|
|
447
|
+
#ifdef USE_METALNESSMAP
|
|
448
|
+
|
|
449
|
+
vMetalnessMapUv = ( tileTransform * (metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) )).xy;
|
|
450
|
+
|
|
451
|
+
#endif
|
|
452
|
+
#ifdef USE_ROUGHNESSMAP
|
|
453
|
+
|
|
454
|
+
vRoughnessMapUv = ( tileTransform * (roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) )).xy;
|
|
455
|
+
|
|
456
|
+
#endif
|
|
457
|
+
#ifdef USE_ANISOTROPYMAP
|
|
458
|
+
|
|
459
|
+
vAnisotropyMapUv = ( tileTransform * (anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) )).xy;
|
|
460
|
+
|
|
461
|
+
#endif
|
|
462
|
+
#ifdef USE_CLEARCOATMAP
|
|
463
|
+
|
|
464
|
+
vClearcoatMapUv = ( tileTransform * (clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) )).xy;
|
|
465
|
+
|
|
466
|
+
#endif
|
|
467
|
+
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
468
|
+
|
|
469
|
+
vClearcoatNormalMapUv = ( tileTransform * (clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) )).xy;
|
|
470
|
+
|
|
471
|
+
#endif
|
|
472
|
+
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
473
|
+
|
|
474
|
+
vClearcoatRoughnessMapUv = ( tileTransform * (clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) )).xy;
|
|
475
|
+
|
|
476
|
+
#endif
|
|
477
|
+
#ifdef USE_IRIDESCENCEMAP
|
|
478
|
+
|
|
479
|
+
vIridescenceMapUv = ( tileTransform * (iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) )).xy;
|
|
480
|
+
|
|
481
|
+
#endif
|
|
482
|
+
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
483
|
+
|
|
484
|
+
vIridescenceThicknessMapUv = ( tileTransform * (iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) )).xy;
|
|
485
|
+
|
|
486
|
+
#endif
|
|
487
|
+
#ifdef USE_SHEEN_COLORMAP
|
|
488
|
+
|
|
489
|
+
vSheenColorMapUv = ( tileTransform * (sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) )).xy;
|
|
490
|
+
|
|
491
|
+
#endif
|
|
492
|
+
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
493
|
+
|
|
494
|
+
vSheenRoughnessMapUv = ( tileTransform * (sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) )).xy;
|
|
495
|
+
|
|
496
|
+
#endif
|
|
497
|
+
#ifdef USE_SPECULARMAP
|
|
498
|
+
|
|
499
|
+
vSpecularMapUv = ( tileTransform * (specularMapTransform * vec3( SPECULARMAP_UV, 1 ) )).xy;
|
|
500
|
+
|
|
501
|
+
#endif
|
|
502
|
+
#ifdef USE_SPECULAR_COLORMAP
|
|
503
|
+
|
|
504
|
+
vSpecularColorMapUv = ( tileTransform * (specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) )).xy;
|
|
505
|
+
|
|
506
|
+
#endif
|
|
507
|
+
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
508
|
+
|
|
509
|
+
vSpecularIntensityMapUv = ( tileTransform * (specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) )).xy;
|
|
510
|
+
|
|
511
|
+
#endif
|
|
512
|
+
#ifdef USE_TRANSMISSIONMAP
|
|
513
|
+
|
|
514
|
+
vTransmissionMapUv = ( tileTransform * transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) )).xy;
|
|
515
|
+
|
|
516
|
+
#endif
|
|
517
|
+
#ifdef USE_THICKNESSMAP
|
|
518
|
+
|
|
519
|
+
vThicknessMapUv = ( tileTransform * thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) )).xy;
|
|
520
|
+
|
|
521
|
+
#endif
|
|
522
|
+
|
|
523
|
+
`;const jt=Hd;function Op(){jt.tile_pars_vertex=Ep,jt.tile_vertex=zp,jt.tile_pars_fragment=Ap,jt.tile_fragment=Pp,jt.soft_pars_vertex=Mp,jt.soft_vertex=Cp,jt.soft_pars_fragment=Sp,jt.soft_fragment=bp}class Tp extends ui{constructor(e){super(),this.type="ParticleEmitter",this.system=e}clone(){const e=this.system.clone();return e.emitter.copy(this,!0),e.emitter}dispose(){}extractFromCache(e){const t=[];for(const i in e){const s=e[i];delete s.metadata,t.push(s)}return t}toJSON(e,t={}){const i=this.children;this.children=this.children.filter(r=>r.type!=="ParticleSystemPreview");const s=super.toJSON(e);return this.children=i,this.system!==null&&(s.object.ps=this.system.toJSON(e,t)),s}}var L;(function(o){o[o.BillBoard=0]="BillBoard",o[o.StretchedBillBoard=1]="StretchedBillBoard",o[o.Mesh=2]="Mesh",o[o.Trail=3]="Trail",o[o.HorizontalBillBoard=4]="HorizontalBillBoard",o[o.VerticalBillBoard=5]="VerticalBillBoard"})(L||(L={}));class uc extends T{constructor(e){super(),this.type="VFXBatch",this.maxParticles=1e3,this.systems=new Set;const t=new zr;t.mask=e.layers.mask;const i=e.material.clone();i.defines={},Object.assign(i.defines,e.material.defines),this.settings={instancingGeometry:e.instancingGeometry,renderMode:e.renderMode,renderOrder:e.renderOrder,material:i,uTileCount:e.uTileCount,vTileCount:e.vTileCount,blendTiles:e.blendTiles,softParticles:e.softParticles,softNearFade:e.softNearFade,softFarFade:e.softFarFade,layers:t},this.frustumCulled=!1,this.renderOrder=this.settings.renderOrder}addSystem(e){this.systems.add(e)}removeSystem(e){this.systems.delete(e)}applyDepthTexture(e){const t=this.material.uniforms.depthTexture;t&&t.value!==e&&(t.value=e,this.material.needsUpdate=!0)}getVisibleSystems(){return Array.from(this.systems).filter(e=>e.emitter.visible)}}const kp=new F(0,0,1),On=new te,Rp=new F,Ip=new F;new F;const Ka=60,Cr=new fo(1,1,1,1);class Gr{set time(e){this.emissionState.time=e}get time(){return this.emissionState.time}get layers(){return this.rendererSettings.layers}get texture(){return this.rendererSettings.material.map}set texture(e){this.rendererSettings.material.map=e,this.neededToUpdateRender=!0}get material(){return this.rendererSettings.material}set material(e){this.rendererSettings.material=e,this.neededToUpdateRender=!0}get uTileCount(){return this.rendererSettings.uTileCount}set uTileCount(e){this.rendererSettings.uTileCount=e,this.neededToUpdateRender=!0}get vTileCount(){return this.rendererSettings.vTileCount}set vTileCount(e){this.rendererSettings.vTileCount=e,this.neededToUpdateRender=!0}get blendTiles(){return this.rendererSettings.blendTiles}set blendTiles(e){this.rendererSettings.blendTiles=e,this.neededToUpdateRender=!0}get softParticles(){return this.rendererSettings.softParticles}set softParticles(e){this.rendererSettings.softParticles=e,this.neededToUpdateRender=!0}get softNearFade(){return this.rendererSettings.softNearFade}set softNearFade(e){this.rendererSettings.softNearFade=e,this.neededToUpdateRender=!0}get softFarFade(){return this.rendererSettings.softFarFade}set softFarFade(e){this.rendererSettings.softFarFade=e,this.neededToUpdateRender=!0}get instancingGeometry(){return this.rendererSettings.instancingGeometry}set instancingGeometry(e){this.restart(),this.particles.length=0,this.rendererSettings.instancingGeometry=e,this.neededToUpdateRender=!0}get renderMode(){return this.rendererSettings.renderMode}set renderMode(e){if(this.rendererSettings.renderMode!==e){let t=!1;switch(this.rendererSettings.renderMode===L.Trail&&(t=!0),this.rendererSettings.renderMode===L.Mesh&&(this.startRotation=new ie(0)),e){case L.Trail:this.rendererEmitterSettings={startLength:new ie(30),followLocalOrigin:!1},t=!0;break;case L.Mesh:this.rendererEmitterSettings={geometry:Cr},this.startRotation=new ws(new F(0,1,0),new ie(0));break;case L.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2},this.rendererSettings.instancingGeometry=Cr;break;case L.BillBoard:case L.VerticalBillBoard:case L.HorizontalBillBoard:this.rendererEmitterSettings={},this.rendererSettings.instancingGeometry=Cr;break}this.rendererSettings.renderMode=e,t&&(this.restart(),this.particles.length=0),this.neededToUpdateRender=!0}}get renderOrder(){return this.rendererSettings.renderOrder}set renderOrder(e){this.rendererSettings.renderOrder=e,this.neededToUpdateRender=!0}get blending(){return this.rendererSettings.material.blending}set blending(e){this.rendererSettings.material.blending=e,this.neededToUpdateRender=!0}constructor(e){if(this.temp=new F,this.travelDistance=0,this.normalMatrix=new xt,this.memory=[],this.listeners={},this.firstTimeUpdate=!0,this.autoDestroy=e.autoDestroy===void 0?!1:e.autoDestroy,this.duration=e.duration??1,this.looping=e.looping===void 0?!0:e.looping,this.prewarm=e.prewarm===void 0?!1:e.prewarm,this.startLife=e.startLife??new ie(5),this.startSpeed=e.startSpeed??new ie(0),this.startRotation=e.startRotation??new ie(0),this.startSize=e.startSize??new ie(1),this.startColor=e.startColor??new Di(new Je(1,1,1,1)),this.emissionOverTime=e.emissionOverTime??new ie(10),this.emissionOverDistance=e.emissionOverDistance??new ie(0),this.emissionBursts=e.emissionBursts??[],this.onlyUsedByOther=e.onlyUsedByOther??!1,this.emitterShape=e.shape??new Vi,this.behaviors=e.behaviors??new Array,this.worldSpace=e.worldSpace??!1,this.rendererEmitterSettings=e.rendererEmitterSettings??{},e.renderMode===L.StretchedBillBoard){const t=this.rendererEmitterSettings;e.speedFactor!==void 0&&(t.speedFactor=e.speedFactor),t.speedFactor=t.speedFactor??0,t.lengthFactor=t.lengthFactor??0}this.rendererSettings={instancingGeometry:e.instancingGeometry??Cr,renderMode:e.renderMode??L.BillBoard,renderOrder:e.renderOrder??0,material:e.material,uTileCount:e.uTileCount??1,vTileCount:e.vTileCount??1,blendTiles:e.blendTiles??!1,softParticles:e.softParticles??!1,softNearFade:e.softNearFade??0,softFarFade:e.softFarFade??0,layers:e.layers??new zr},this.neededToUpdateRender=!0,this.particles=new Array,this.startTileIndex=e.startTileIndex||new ie(0),this.emitter=new Tp(this),this.paused=!1,this.particleNum=0,this.emissionState={isBursting:!1,burstParticleIndex:0,burstParticleCount:0,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,travelDistance:0},this.emissionBursts.forEach(t=>t.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1}pause(){this.paused=!0}play(){this.paused=!1}stop(){this.restart(),this.pause()}spawn(e,t,i){On.setFromRotationMatrix(i);const s=Rp,r=On,n=Ip;i.decompose(s,r,n);for(let a=0;a<e;a++){for(t.burstParticleIndex=a,this.particleNum++;this.particles.length<this.particleNum;)this.rendererSettings.renderMode===L.Trail?this.particles.push(new io):this.particles.push(new hp);const l=this.particles[this.particleNum-1];if(l.reset(),l.speedModifier=1,this.startColor.startGen(l.memory),this.startColor.genColor(l.memory,l.startColor,this.emissionState.time),l.color.copy(l.startColor),this.startSpeed.startGen(l.memory),l.startSpeed=this.startSpeed.genValue(l.memory,t.time/this.duration),this.startLife.startGen(l.memory),l.life=this.startLife.genValue(l.memory,t.time/this.duration),l.age=0,this.startSize.startGen(l.memory),this.startSize.type==="vec3function")this.startSize.genValue(l.memory,l.startSize,t.time/this.duration);else{const c=this.startSize.genValue(l.memory,t.time/this.duration);l.startSize.set(c,c,c)}if(this.startTileIndex.startGen(l.memory),l.uvTile=this.startTileIndex.genValue(l.memory),l.size.copy(l.startSize),this.rendererSettings.renderMode===L.Mesh||this.rendererSettings.renderMode===L.BillBoard||this.rendererSettings.renderMode===L.VerticalBillBoard||this.rendererSettings.renderMode===L.HorizontalBillBoard||this.rendererSettings.renderMode===L.StretchedBillBoard){const c=l;this.startRotation.startGen(l.memory),this.rendererSettings.renderMode===L.Mesh?(c.rotation instanceof te||(c.rotation=new te),this.startRotation.type==="rotation"?this.startRotation.genValue(l.memory,c.rotation,1,t.time/this.duration):c.rotation.setFromAxisAngle(kp,this.startRotation.genValue(c.memory,t.time/this.duration))):this.startRotation.type==="rotation"?c.rotation=0:c.rotation=this.startRotation.genValue(c.memory,t.time/this.duration)}else if(this.rendererSettings.renderMode===L.Trail){const c=l;this.rendererEmitterSettings.startLength.startGen(c.memory),c.length=this.rendererEmitterSettings.startLength.genValue(c.memory,t.time/this.duration)}if(this.emitterShape.initialize(l,t),this.rendererSettings.renderMode===L.Trail&&this.rendererEmitterSettings.followLocalOrigin){const c=l;c.localPosition=new F().copy(c.position)}this.worldSpace?(l.position.applyMatrix4(i),l.startSize.multiply(n).abs(),l.size.copy(l.startSize),l.velocity.multiply(n).applyMatrix3(this.normalMatrix),l.rotation&&l.rotation instanceof te&&l.rotation.multiplyQuaternions(On,l.rotation)):this.onlyUsedByOther&&(l.parentMatrix=i);for(let c=0;c<this.behaviors.length;c++)this.behaviors[c].initialize(l,this)}}endEmit(){this.emitEnded=!0,this.autoDestroy&&(this.markForDestroy=!0),this.fire({type:"emitEnd",particleSystem:this})}dispose(){this._renderer&&this._renderer.deleteSystem(this),this.emitter.dispose(),this.emitter.parent&&this.emitter.parent.remove(this.emitter),this.fire({type:"destroy",particleSystem:this})}restart(){this.memory.length=0,this.paused=!1,this.particleNum=0,this.emissionState.isBursting=!1,this.emissionState.burstIndex=0,this.emissionState.burstWaveIndex=0,this.emissionState.time=0,this.emissionState.waitEmiting=0,this.behaviors.forEach(e=>{e.reset()}),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1,this.emissionBursts.forEach(e=>e.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory)}update(e){if(this.paused)return;let t=this.emitter;for(;t.parent;)t=t.parent;if(t.type!=="Scene"){this.dispose();return}if(this.firstTimeUpdate&&(this.firstTimeUpdate=!1,this.emitter.updateWorldMatrix(!0,!1)),this.emitEnded&&this.particleNum===0){this.markForDestroy&&this.emitter.parent&&this.dispose();return}if(this.looping&&this.prewarm&&!this.prewarmed){this.prewarmed=!0;for(let i=0;i<this.duration*Ka;i++)this.update(1/Ka)}e>.1&&(e=.1),this.neededToUpdateRender&&(this._renderer&&this._renderer.updateSystem(this),this.neededToUpdateRender=!1),this.onlyUsedByOther||this.emit(e,this.emissionState,this.emitter.matrixWorld),this.emitterShape.update(this,e);for(let i=0;i<this.behaviors.length;i++){this.behaviors[i].frameUpdate(e);for(let s=0;s<this.particleNum;s++)this.particles[s].died||this.behaviors[i].update(this.particles[s],e)}for(let i=0;i<this.particleNum;i++)this.rendererEmitterSettings.followLocalOrigin&&this.particles[i].localPosition?(this.particles[i].position.copy(this.particles[i].localPosition),this.particles[i].parentMatrix?this.particles[i].position.applyMatrix4(this.particles[i].parentMatrix):this.particles[i].position.applyMatrix4(this.emitter.matrixWorld)):this.particles[i].position.addScaledVector(this.particles[i].velocity,e*this.particles[i].speedModifier),this.particles[i].age+=e;if(this.rendererSettings.renderMode===L.Trail)for(let i=0;i<this.particleNum;i++)this.particles[i].update();for(let i=0;i<this.particleNum;i++){const s=this.particles[i];s.died&&(!(s instanceof io)||s.previous.length===0)&&(this.particles[i]=this.particles[this.particleNum-1],this.particles[this.particleNum-1]=s,this.particleNum--,i--,this.fire({type:"particleDied",particleSystem:this,particle:s}))}}emit(e,t,i){t.time>this.duration&&(this.looping?(t.time-=this.duration,t.burstIndex=0,this.behaviors.forEach(r=>{r.reset()})):!this.emitEnded&&!this.onlyUsedByOther&&this.endEmit()),this.normalMatrix.getNormalMatrix(i);const s=Math.ceil(t.waitEmiting);for(this.spawn(s,t,i),t.waitEmiting-=s;t.burstIndex<this.emissionBursts.length&&this.emissionBursts[t.burstIndex].time<=t.time;){if(Math.random()<this.emissionBursts[t.burstIndex].probability){const r=this.emissionBursts[t.burstIndex].count.genValue(this.memory,this.time);t.isBursting=!0,t.burstParticleCount=r,this.spawn(r,t,i),t.isBursting=!1}t.burstIndex++}if(!this.emitEnded&&(t.waitEmiting+=e*this.emissionOverTime.genValue(this.memory,t.time/this.duration),t.previousWorldPos!=null)){this.temp.set(i.elements[12],i.elements[13],i.elements[14]),t.travelDistance+=t.previousWorldPos.distanceTo(this.temp);const r=this.emissionOverDistance.genValue(this.memory,t.time/this.duration);if(t.travelDistance*r>0){const n=Math.floor(t.travelDistance*r);t.travelDistance-=n/r,t.waitEmiting+=n}}t.previousWorldPos===void 0&&(t.previousWorldPos=new F),t.previousWorldPos.set(i.elements[12],i.elements[13],i.elements[14]),t.time+=e}toJSON(e,t={}){if((e===void 0||typeof e=="string")&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}}),e.materials[this.rendererSettings.material.uuid]=this.rendererSettings.material.toJSON(e),t.useUrlForImage&&this.texture?.source!==void 0){const n=this.texture.source;e.images[n.uuid]={uuid:n.uuid,url:this.texture.image.url}}let s;this.renderMode===L.Trail?s={startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===L.Mesh?s={}:this.renderMode===L.StretchedBillBoard?s={speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:s={};const r=this.rendererSettings.instancingGeometry;return e.geometries&&!e.geometries[r.uuid]&&(e.geometries[r.uuid]=r.toJSON()),{version:"3.0",autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,shape:this.emitterShape.toJSON(),startLife:this.startLife.toJSON(),startSpeed:this.startSpeed.toJSON(),startRotation:this.startRotation.toJSON(),startSize:this.startSize.toJSON(),startColor:this.startColor.toJSON(),emissionOverTime:this.emissionOverTime.toJSON(),emissionOverDistance:this.emissionOverDistance.toJSON(),emissionBursts:this.emissionBursts.map(n=>({time:n.time,count:n.count.toJSON(),probability:n.probability,interval:n.interval,cycle:n.cycle})),onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry.uuid,renderOrder:this.renderOrder,renderMode:this.renderMode,rendererEmitterSettings:s,material:this.rendererSettings.material.uuid,layers:this.layers.mask,startTileIndex:this.startTileIndex.toJSON(),uTileCount:this.uTileCount,vTileCount:this.vTileCount,blendTiles:this.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,behaviors:this.behaviors.map(n=>n.toJSON()),worldSpace:this.worldSpace}}static fromJSON(e,t,i){const s=lp(e.shape,t);let r;if(e.renderMode===L.Trail){const l=e.rendererEmitterSettings;r={startLength:l.startLength!=null?W(l.startLength):new ie(30),followLocalOrigin:l.followLocalOrigin}}else e.renderMode===L.Mesh?r={}:e.renderMode===L.StretchedBillBoard?(r=e.rendererEmitterSettings,e.speedFactor!=null&&(r.speedFactor=e.speedFactor)):r={};const n=new zr;e.layers&&(n.mask=e.layers);const a=new Gr({autoDestroy:e.autoDestroy,looping:e.looping,prewarm:e.prewarm,duration:e.duration,shape:s,startLife:W(e.startLife),startSpeed:W(e.startSpeed),startRotation:Ur(e.startRotation),startSize:Ur(e.startSize),startColor:wo(e.startColor),emissionOverTime:W(e.emissionOverTime),emissionOverDistance:W(e.emissionOverDistance),emissionBursts:e.emissionBursts?.map(l=>({time:l.time,count:typeof l.count=="number"?new ie(l.count):W(l.count),probability:l.probability??1,interval:l.interval??.1,cycle:l.cycle??1})),onlyUsedByOther:e.onlyUsedByOther,instancingGeometry:t.geometries[e.instancingGeometry],renderMode:e.renderMode,rendererEmitterSettings:r,renderOrder:e.renderOrder,layers:n,material:e.material?t.materials[e.material]:e.texture?new Ce({map:t.textures[e.texture],transparent:e.transparent??!0,blending:e.blending,side:di}):new Ce({color:16777215,transparent:!0,blending:po,side:di}),startTileIndex:typeof e.startTileIndex=="number"?new ie(e.startTileIndex):W(e.startTileIndex),uTileCount:e.uTileCount,vTileCount:e.vTileCount,blendTiles:e.blendTiles,softParticles:e.softParticles,softFarFade:e.softFarFade,softNearFade:e.softNearFade,behaviors:[],worldSpace:e.worldSpace});return a.behaviors=e.behaviors.map(l=>{const c=_p(l,a);return c&&c.type==="EmitSubParticleSystem"&&(i[l.subParticleSystem]=c),c}).filter(l=>l!==null),a}addBehavior(e){this.behaviors.push(e)}getRendererSettings(){return this.rendererSettings}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeAllEventListeners(e){this.listeners[e]&&(this.listeners[e]=[])}removeEventListener(e,t){if(this.listeners[e]){const i=this.listeners[e].indexOf(t);i!==-1&&this.listeners[e].splice(i,1)}}fire(e){this.listeners[e.type]&&this.listeners[e.type].forEach(t=>t(e))}clone(){const e=[];for(const r of this.emissionBursts){const n={};Object.assign(n,r),e.push(n)}const t=[];for(const r of this.behaviors)t.push(r.clone());let i;this.renderMode===L.Trail?i={startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===L.StretchedBillBoard?i={lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:i={};const s=new zr;return s.mask=this.layers.mask,new Gr({autoDestroy:this.autoDestroy,looping:this.looping,duration:this.duration,shape:this.emitterShape.clone(),startLife:this.startLife.clone(),startSpeed:this.startSpeed.clone(),startRotation:this.startRotation.clone(),startSize:this.startSize.clone(),startColor:this.startColor.clone(),emissionOverTime:this.emissionOverTime.clone(),emissionOverDistance:this.emissionOverDistance.clone(),emissionBursts:e,onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry,renderMode:this.renderMode,renderOrder:this.renderOrder,rendererEmitterSettings:i,material:this.rendererSettings.material,startTileIndex:this.startTileIndex,uTileCount:this.uTileCount,vTileCount:this.vTileCount,blendTiles:this.blendTiles,softParticles:this.softParticles,softFarFade:this.softFarFade,softNearFade:this.softNearFade,behaviors:t,worldSpace:this.worldSpace,layers:s})}}var Tn=`
|
|
524
|
+
|
|
525
|
+
#include <common>
|
|
526
|
+
#include <color_pars_fragment>
|
|
527
|
+
#include <map_pars_fragment>
|
|
528
|
+
#include <logdepthbuf_pars_fragment>
|
|
529
|
+
#include <clipping_planes_pars_fragment>
|
|
530
|
+
#include <alphatest_pars_fragment>
|
|
531
|
+
|
|
532
|
+
#include <tile_pars_fragment>
|
|
533
|
+
#include <soft_pars_fragment>
|
|
534
|
+
|
|
535
|
+
void main() {
|
|
536
|
+
|
|
537
|
+
#include <clipping_planes_fragment>
|
|
538
|
+
|
|
539
|
+
vec3 outgoingLight = vec3( 0.0 );
|
|
540
|
+
vec4 diffuseColor = vColor;
|
|
541
|
+
|
|
542
|
+
#include <logdepthbuf_fragment>
|
|
543
|
+
|
|
544
|
+
#include <tile_fragment>
|
|
545
|
+
#include <alphatest_fragment>
|
|
546
|
+
|
|
547
|
+
outgoingLight = diffuseColor.rgb;
|
|
548
|
+
|
|
549
|
+
#ifdef USE_COLOR_AS_ALPHA
|
|
550
|
+
gl_FragColor = vec4( outgoingLight, diffuseColor.r );
|
|
551
|
+
#else
|
|
552
|
+
gl_FragColor = vec4( outgoingLight, diffuseColor.a );
|
|
553
|
+
#endif
|
|
554
|
+
|
|
555
|
+
#include <soft_fragment>
|
|
556
|
+
#include <tonemapping_fragment>
|
|
557
|
+
}
|
|
558
|
+
`,xo=`
|
|
559
|
+
#define STANDARD
|
|
560
|
+
|
|
561
|
+
#ifdef PHYSICAL
|
|
562
|
+
#define IOR
|
|
563
|
+
#define USE_SPECULAR
|
|
564
|
+
#endif
|
|
565
|
+
|
|
566
|
+
uniform vec3 diffuse;
|
|
567
|
+
uniform vec3 emissive;
|
|
568
|
+
uniform float roughness;
|
|
569
|
+
uniform float metalness;
|
|
570
|
+
uniform float opacity;
|
|
571
|
+
|
|
572
|
+
#ifdef IOR
|
|
573
|
+
uniform float ior;
|
|
574
|
+
#endif
|
|
575
|
+
|
|
576
|
+
#ifdef USE_SPECULAR
|
|
577
|
+
uniform float specularIntensity;
|
|
578
|
+
uniform vec3 specularColor;
|
|
579
|
+
|
|
580
|
+
#ifdef USE_SPECULAR_COLORMAP
|
|
581
|
+
uniform sampler2D specularColorMap;
|
|
582
|
+
#endif
|
|
583
|
+
|
|
584
|
+
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
585
|
+
uniform sampler2D specularIntensityMap;
|
|
586
|
+
#endif
|
|
587
|
+
#endif
|
|
588
|
+
|
|
589
|
+
#ifdef USE_CLEARCOAT
|
|
590
|
+
uniform float clearcoat;
|
|
591
|
+
uniform float clearcoatRoughness;
|
|
592
|
+
#endif
|
|
593
|
+
|
|
594
|
+
#ifdef USE_DISPERSION
|
|
595
|
+
uniform float dispersion;
|
|
596
|
+
#endif
|
|
597
|
+
|
|
598
|
+
#ifdef USE_IRIDESCENCE
|
|
599
|
+
uniform float iridescence;
|
|
600
|
+
uniform float iridescenceIOR;
|
|
601
|
+
uniform float iridescenceThicknessMinimum;
|
|
602
|
+
uniform float iridescenceThicknessMaximum;
|
|
603
|
+
#endif
|
|
604
|
+
|
|
605
|
+
#ifdef USE_SHEEN
|
|
606
|
+
uniform vec3 sheenColor;
|
|
607
|
+
uniform float sheenRoughness;
|
|
608
|
+
|
|
609
|
+
#ifdef USE_SHEEN_COLORMAP
|
|
610
|
+
uniform sampler2D sheenColorMap;
|
|
611
|
+
#endif
|
|
612
|
+
|
|
613
|
+
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
614
|
+
uniform sampler2D sheenRoughnessMap;
|
|
615
|
+
#endif
|
|
616
|
+
#endif
|
|
617
|
+
|
|
618
|
+
#ifdef USE_ANISOTROPY
|
|
619
|
+
uniform vec2 anisotropyVector;
|
|
620
|
+
|
|
621
|
+
#ifdef USE_ANISOTROPYMAP
|
|
622
|
+
uniform sampler2D anisotropyMap;
|
|
623
|
+
#endif
|
|
624
|
+
#endif
|
|
625
|
+
|
|
626
|
+
varying vec3 vViewPosition;
|
|
627
|
+
|
|
628
|
+
#include <common>
|
|
629
|
+
#include <packing>
|
|
630
|
+
#include <dithering_pars_fragment>
|
|
631
|
+
#include <color_pars_fragment>
|
|
632
|
+
#include <uv_pars_fragment>
|
|
633
|
+
#include <map_pars_fragment>
|
|
634
|
+
#include <alphamap_pars_fragment>
|
|
635
|
+
#include <alphatest_pars_fragment>
|
|
636
|
+
#include <alphahash_pars_fragment>
|
|
637
|
+
#include <aomap_pars_fragment>
|
|
638
|
+
#include <lightmap_pars_fragment>
|
|
639
|
+
#include <emissivemap_pars_fragment>
|
|
640
|
+
#include <iridescence_fragment>
|
|
641
|
+
#include <cube_uv_reflection_fragment>
|
|
642
|
+
#include <envmap_common_pars_fragment>
|
|
643
|
+
#include <envmap_physical_pars_fragment>
|
|
644
|
+
#include <fog_pars_fragment>
|
|
645
|
+
#include <lights_pars_begin>
|
|
646
|
+
#include <normal_pars_fragment>
|
|
647
|
+
#include <lights_physical_pars_fragment>
|
|
648
|
+
#include <transmission_pars_fragment>
|
|
649
|
+
#include <shadowmap_pars_fragment>
|
|
650
|
+
#include <bumpmap_pars_fragment>
|
|
651
|
+
#include <normalmap_pars_fragment>
|
|
652
|
+
#include <clearcoat_pars_fragment>
|
|
653
|
+
#include <iridescence_pars_fragment>
|
|
654
|
+
#include <roughnessmap_pars_fragment>
|
|
655
|
+
#include <metalnessmap_pars_fragment>
|
|
656
|
+
#include <logdepthbuf_pars_fragment>
|
|
657
|
+
#include <clipping_planes_pars_fragment>
|
|
658
|
+
|
|
659
|
+
void main() {
|
|
660
|
+
|
|
661
|
+
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
662
|
+
#include <clipping_planes_fragment>
|
|
663
|
+
|
|
664
|
+
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
665
|
+
vec3 totalEmissiveRadiance = emissive;
|
|
666
|
+
|
|
667
|
+
#include <logdepthbuf_fragment>
|
|
668
|
+
#include <map_fragment>
|
|
669
|
+
#include <color_fragment>
|
|
670
|
+
#include <alphamap_fragment>
|
|
671
|
+
#include <alphatest_fragment>
|
|
672
|
+
#include <alphahash_fragment>
|
|
673
|
+
#include <roughnessmap_fragment>
|
|
674
|
+
#include <metalnessmap_fragment>
|
|
675
|
+
#include <normal_fragment_begin>
|
|
676
|
+
#include <normal_fragment_maps>
|
|
677
|
+
#include <clearcoat_normal_fragment_begin>
|
|
678
|
+
#include <clearcoat_normal_fragment_maps>
|
|
679
|
+
#include <emissivemap_fragment>
|
|
680
|
+
|
|
681
|
+
// accumulation
|
|
682
|
+
#include <lights_physical_fragment>
|
|
683
|
+
#include <lights_fragment_begin>
|
|
684
|
+
#include <lights_fragment_maps>
|
|
685
|
+
#include <lights_fragment_end>
|
|
686
|
+
|
|
687
|
+
// modulation
|
|
688
|
+
#include <aomap_fragment>
|
|
689
|
+
|
|
690
|
+
vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
|
|
691
|
+
vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
|
|
692
|
+
|
|
693
|
+
#include <transmission_fragment>
|
|
694
|
+
|
|
695
|
+
vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
|
|
696
|
+
|
|
697
|
+
#ifdef USE_SHEEN
|
|
698
|
+
|
|
699
|
+
// Sheen energy compensation approximation calculation can be found at the end of
|
|
700
|
+
// https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing
|
|
701
|
+
float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
|
|
702
|
+
|
|
703
|
+
outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;
|
|
704
|
+
|
|
705
|
+
#endif
|
|
706
|
+
|
|
707
|
+
#ifdef USE_CLEARCOAT
|
|
708
|
+
|
|
709
|
+
float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
|
|
710
|
+
|
|
711
|
+
vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
|
|
712
|
+
|
|
713
|
+
outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
|
|
714
|
+
|
|
715
|
+
#endif
|
|
716
|
+
|
|
717
|
+
#include <opaque_fragment>
|
|
718
|
+
#include <tonemapping_fragment>
|
|
719
|
+
#include <colorspace_fragment>
|
|
720
|
+
#include <fog_fragment>
|
|
721
|
+
#include <premultiplied_alpha_fragment>
|
|
722
|
+
#include <dithering_fragment>
|
|
723
|
+
}`,Lp=`
|
|
724
|
+
#include <common>
|
|
725
|
+
#include <color_pars_vertex>
|
|
726
|
+
#include <logdepthbuf_pars_vertex>
|
|
727
|
+
#include <clipping_planes_pars_vertex>
|
|
728
|
+
|
|
729
|
+
#include <tile_pars_vertex>
|
|
730
|
+
#include <soft_pars_vertex>
|
|
731
|
+
|
|
732
|
+
attribute vec3 offset;
|
|
733
|
+
attribute float rotation;
|
|
734
|
+
attribute vec3 size;
|
|
735
|
+
|
|
736
|
+
void main() {
|
|
737
|
+
|
|
738
|
+
vec2 alignedPosition = position.xy * size.xy;
|
|
739
|
+
|
|
740
|
+
vec2 rotatedPosition;
|
|
741
|
+
rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
|
|
742
|
+
rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
|
|
743
|
+
#ifdef HORIZONTAL
|
|
744
|
+
vec4 mvPosition = modelMatrix * vec4( offset, 1.0 );
|
|
745
|
+
mvPosition.x += rotatedPosition.x;
|
|
746
|
+
mvPosition.z -= rotatedPosition.y;
|
|
747
|
+
mvPosition = viewMatrix * mvPosition;
|
|
748
|
+
#elif defined(VERTICAL)
|
|
749
|
+
vec4 mvPosition = modelMatrix * vec4( offset, 1.0 );
|
|
750
|
+
mvPosition.y += rotatedPosition.y;
|
|
751
|
+
mvPosition = viewMatrix * mvPosition;
|
|
752
|
+
mvPosition.x += rotatedPosition.x;
|
|
753
|
+
#else
|
|
754
|
+
vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
|
|
755
|
+
mvPosition.xy += rotatedPosition;
|
|
756
|
+
#endif
|
|
757
|
+
|
|
758
|
+
vColor = color;
|
|
759
|
+
|
|
760
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
761
|
+
|
|
762
|
+
#include <logdepthbuf_vertex>
|
|
763
|
+
|
|
764
|
+
#include <clipping_planes_vertex>
|
|
765
|
+
|
|
766
|
+
#include <tile_vertex>
|
|
767
|
+
#include <soft_vertex>
|
|
768
|
+
}
|
|
769
|
+
`,Fp=`
|
|
770
|
+
#include <common>
|
|
771
|
+
#include <color_pars_vertex>
|
|
772
|
+
#include <logdepthbuf_pars_vertex>
|
|
773
|
+
#include <clipping_planes_pars_vertex>
|
|
774
|
+
#include <tile_pars_vertex>
|
|
775
|
+
#include <soft_pars_vertex>
|
|
776
|
+
|
|
777
|
+
attribute vec3 offset;
|
|
778
|
+
attribute vec4 rotation;
|
|
779
|
+
attribute vec3 size;
|
|
780
|
+
// attribute vec4 color;
|
|
781
|
+
|
|
782
|
+
void main() {
|
|
783
|
+
|
|
784
|
+
float x2 = rotation.x + rotation.x, y2 = rotation.y + rotation.y, z2 = rotation.z + rotation.z;
|
|
785
|
+
float xx = rotation.x * x2, xy = rotation.x * y2, xz = rotation.x * z2;
|
|
786
|
+
float yy = rotation.y * y2, yz = rotation.y * z2, zz = rotation.z * z2;
|
|
787
|
+
float wx = rotation.w * x2, wy = rotation.w * y2, wz = rotation.w * z2;
|
|
788
|
+
float sx = size.x, sy = size.y, sz = size.z;
|
|
789
|
+
|
|
790
|
+
mat4 matrix = mat4(( 1.0 - ( yy + zz ) ) * sx, ( xy + wz ) * sx, ( xz - wy ) * sx, 0.0, // 1. column
|
|
791
|
+
( xy - wz ) * sy, ( 1.0 - ( xx + zz ) ) * sy, ( yz + wx ) * sy, 0.0, // 2. column
|
|
792
|
+
( xz + wy ) * sz, ( yz - wx ) * sz, ( 1.0 - ( xx + yy ) ) * sz, 0.0, // 3. column
|
|
793
|
+
offset.x, offset.y, offset.z, 1.0);
|
|
794
|
+
|
|
795
|
+
vec4 mvPosition = modelViewMatrix * (matrix * vec4( position, 1.0 ));
|
|
796
|
+
|
|
797
|
+
vColor = color;
|
|
798
|
+
|
|
799
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
800
|
+
|
|
801
|
+
#include <logdepthbuf_vertex>
|
|
802
|
+
#include <clipping_planes_vertex>
|
|
803
|
+
#include <tile_vertex>
|
|
804
|
+
#include <soft_vertex>
|
|
805
|
+
}
|
|
806
|
+
`,bo=`
|
|
807
|
+
#define STANDARD
|
|
808
|
+
varying vec3 vViewPosition;
|
|
809
|
+
#ifdef USE_TRANSMISSION
|
|
810
|
+
varying vec3 vWorldPosition;
|
|
811
|
+
#endif
|
|
812
|
+
#include <common>
|
|
813
|
+
|
|
814
|
+
attribute vec3 offset;
|
|
815
|
+
attribute vec4 rotation;
|
|
816
|
+
attribute vec3 size;
|
|
817
|
+
#include <tile_pars_vertex>
|
|
818
|
+
#include <displacementmap_pars_vertex>
|
|
819
|
+
#include <color_pars_vertex>
|
|
820
|
+
#include <fog_pars_vertex>
|
|
821
|
+
#include <normal_pars_vertex>
|
|
822
|
+
#include <morphtarget_pars_vertex>
|
|
823
|
+
#include <skinning_pars_vertex>
|
|
824
|
+
#include <shadowmap_pars_vertex>
|
|
825
|
+
#include <logdepthbuf_pars_vertex>
|
|
826
|
+
#include <clipping_planes_pars_vertex>
|
|
827
|
+
|
|
828
|
+
void main() {
|
|
829
|
+
|
|
830
|
+
#include <tile_vertex>
|
|
831
|
+
float x2 = rotation.x + rotation.x, y2 = rotation.y + rotation.y, z2 = rotation.z + rotation.z;
|
|
832
|
+
float xx = rotation.x * x2, xy = rotation.x * y2, xz = rotation.x * z2;
|
|
833
|
+
float yy = rotation.y * y2, yz = rotation.y * z2, zz = rotation.z * z2;
|
|
834
|
+
float wx = rotation.w * x2, wy = rotation.w * y2, wz = rotation.w * z2;
|
|
835
|
+
float sx = size.x, sy = size.y, sz = size.z;
|
|
836
|
+
|
|
837
|
+
mat4 particleMatrix = mat4(( 1.0 - ( yy + zz ) ) * sx, ( xy + wz ) * sx, ( xz - wy ) * sx, 0.0, // 1. column
|
|
838
|
+
( xy - wz ) * sy, ( 1.0 - ( xx + zz ) ) * sy, ( yz + wx ) * sy, 0.0, // 2. column
|
|
839
|
+
( xz + wy ) * sz, ( yz - wx ) * sz, ( 1.0 - ( xx + yy ) ) * sz, 0.0, // 3. column
|
|
840
|
+
offset.x, offset.y, offset.z, 1.0);
|
|
841
|
+
|
|
842
|
+
#include <color_vertex>
|
|
843
|
+
#include <morphinstance_vertex>
|
|
844
|
+
#include <morphcolor_vertex>
|
|
845
|
+
#include <batching_vertex>
|
|
846
|
+
|
|
847
|
+
#include <beginnormal_vertex>
|
|
848
|
+
#include <morphnormal_vertex>
|
|
849
|
+
#include <skinbase_vertex>
|
|
850
|
+
#include <skinnormal_vertex>
|
|
851
|
+
|
|
852
|
+
// replace defaultnormal_vertex
|
|
853
|
+
vec3 transformedNormal = objectNormal;
|
|
854
|
+
mat3 m = mat3( particleMatrix );
|
|
855
|
+
transformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );
|
|
856
|
+
transformedNormal = m * transformedNormal;
|
|
857
|
+
transformedNormal = normalMatrix * transformedNormal;
|
|
858
|
+
#ifdef FLIP_SIDED
|
|
859
|
+
transformedNormal = - transformedNormal;
|
|
860
|
+
#endif
|
|
861
|
+
#ifdef USE_TANGENT
|
|
862
|
+
vec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;
|
|
863
|
+
#ifdef FLIP_SIDED
|
|
864
|
+
transformedTangent = - transformedTangent;
|
|
865
|
+
#endif
|
|
866
|
+
#endif
|
|
867
|
+
|
|
868
|
+
#include <normal_vertex>
|
|
869
|
+
#include <begin_vertex>
|
|
870
|
+
#include <morphtarget_vertex>
|
|
871
|
+
#include <skinning_vertex>
|
|
872
|
+
#include <displacementmap_vertex>
|
|
873
|
+
|
|
874
|
+
// replace include <project_vertex>
|
|
875
|
+
vec4 mvPosition = vec4( transformed, 1.0 );
|
|
876
|
+
mvPosition = modelViewMatrix * (particleMatrix * mvPosition);
|
|
877
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
878
|
+
|
|
879
|
+
#include <logdepthbuf_vertex>
|
|
880
|
+
#include <clipping_planes_vertex>
|
|
881
|
+
|
|
882
|
+
vViewPosition = - mvPosition.xyz;
|
|
883
|
+
|
|
884
|
+
#include <worldpos_vertex>
|
|
885
|
+
#include <shadowmap_vertex>
|
|
886
|
+
#include <fog_vertex>
|
|
887
|
+
#ifdef USE_TRANSMISSION
|
|
888
|
+
vWorldPosition = worldPosition.xyz;
|
|
889
|
+
#endif
|
|
890
|
+
}
|
|
891
|
+
`,Bp=`
|
|
892
|
+
#include <common>
|
|
893
|
+
#include <color_pars_vertex>
|
|
894
|
+
#include <logdepthbuf_pars_vertex>
|
|
895
|
+
#include <clipping_planes_pars_vertex>
|
|
896
|
+
|
|
897
|
+
#include <tile_pars_vertex>
|
|
898
|
+
#include <soft_pars_vertex>
|
|
899
|
+
|
|
900
|
+
attribute vec3 offset;
|
|
901
|
+
attribute float rotation;
|
|
902
|
+
attribute vec3 size;
|
|
903
|
+
attribute vec4 velocity;
|
|
904
|
+
|
|
905
|
+
uniform float speedFactor;
|
|
906
|
+
|
|
907
|
+
void main() {
|
|
908
|
+
float lengthFactor = velocity.w;
|
|
909
|
+
float avgSize = (size.x + size.y) * 0.5;
|
|
910
|
+
#ifdef USE_SKEW
|
|
911
|
+
vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
|
|
912
|
+
vec3 viewVelocity = normalMatrix * velocity.xyz;
|
|
913
|
+
|
|
914
|
+
vec3 scaledPos = vec3(position.xy * size.xy, position.z);
|
|
915
|
+
float vlength = length(viewVelocity);
|
|
916
|
+
vec3 projVelocity = dot(scaledPos, viewVelocity) * viewVelocity / vlength;
|
|
917
|
+
mvPosition.xyz += scaledPos + projVelocity * (speedFactor / avgSize + lengthFactor / vlength);
|
|
918
|
+
#else
|
|
919
|
+
vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
|
|
920
|
+
vec3 viewVelocity = normalMatrix * velocity.xyz;
|
|
921
|
+
float vlength = length(viewVelocity);
|
|
922
|
+
mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize; // switch the cross to match unity implementation
|
|
923
|
+
mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize; // minus position.x to match unity implementation
|
|
924
|
+
#endif
|
|
925
|
+
vColor = color;
|
|
926
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
927
|
+
#include <logdepthbuf_vertex>
|
|
928
|
+
#include <clipping_planes_vertex>
|
|
929
|
+
#include <tile_vertex>
|
|
930
|
+
#include <soft_vertex>
|
|
931
|
+
}
|
|
932
|
+
`;function so(o){return o===0?"uv":`uv${o}`}class Np extends Yl{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=bo,e.fragmentShader=xo}}class Hp extends Nd{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=bo,e.fragmentShader=xo}}class Dp extends uc{constructor(e){super(e),this.vector_=new F,this.vector2_=new F,this.vector3_=new F,this.quaternion_=new te,this.quaternion2_=new te,this.quaternion3_=new te,this.rotationMat_=new xt,this.rotationMat2_=new xt,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new Ct(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(De),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new Ct(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(De),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===L.Mesh?(this.rotationBuffer=new Ct(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(De),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===L.BillBoard||this.settings.renderMode===L.HorizontalBillBoard||this.settings.renderMode===L.VerticalBillBoard||this.settings.renderMode===L.StretchedBillBoard)&&(this.rotationBuffer=new Ct(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(De),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new Ct(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(De),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new Ct(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(De),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===L.StretchedBillBoard&&(this.velocityBuffer=new Ct(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(De),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new Bd,this.geometry.setIndex(this.settings.instancingGeometry.getIndex()),this.settings.instancingGeometry.hasAttribute("normal")&&this.geometry.setAttribute("normal",this.settings.instancingGeometry.getAttribute("normal")),this.geometry.setAttribute("position",this.settings.instancingGeometry.getAttribute("position")),this.settings.instancingGeometry.hasAttribute("uv")&&this.geometry.setAttribute("uv",this.settings.instancingGeometry.getAttribute("uv")),this.buildExpandableBuffers()}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={},t={};this.settings.material.type!=="MeshStandardMaterial"&&this.settings.material.type!=="MeshPhysicalMaterial"&&(e.map=new it(this.settings.material.map)),this.settings.material.alphaTest&&(t.USE_ALPHATEST="",e.alphaTest=new it(this.settings.material.alphaTest)),t.USE_UV="";const i=this.settings.uTileCount,s=this.settings.vTileCount;(i>1||s>1)&&(t.UV_TILE="",e.tileCount=new it(new Ni(i,s))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.material.normalMap&&(t.USE_NORMALMAP="",t.NORMALMAP_UV=so(this.settings.material.normalMap.channel),e.normalMapTransform=new it(new xt().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(t.USE_MAP="",this.settings.blendTiles&&(t.TILE_BLEND=""),t.MAP_UV=so(this.settings.material.map.channel),e.mapTransform=new it(new xt().copy(this.settings.material.map.matrix))),t.USE_COLOR_ALPHA="";let r;if(this.settings.softParticles){t.SOFT_PARTICLES="";const a=this.settings.softNearFade,l=1/(this.settings.softFarFade-this.settings.softNearFade);e.softParams=new it(new Ni(a,l)),e.depthTexture=new it(null);const c=e.projParams=new it(new Je);r=(h,d,p)=>{c.value.set(p.near,p.far,0,0)}}let n=!1;if(this.settings.renderMode===L.BillBoard||this.settings.renderMode===L.VerticalBillBoard||this.settings.renderMode===L.HorizontalBillBoard||this.settings.renderMode===L.Mesh){let a,l;this.settings.renderMode===L.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(t.USE_COLOR="",a=bo,l=xo,n=!0):(a=Fp,l=Tn):(a=Lp,l=Tn),this.settings.renderMode===L.VerticalBillBoard?t.VERTICAL="":this.settings.renderMode===L.HorizontalBillBoard&&(t.HORIZONTAL="");let c=!1;this.settings.renderMode===L.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new Np({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,c=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new Hp({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,c=!0)),c||(this.material=new fs({uniforms:e,defines:t,vertexShader:a,fragmentShader:l,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest,lights:n}))}else if(this.settings.renderMode===L.StretchedBillBoard)e.speedFactor=new it(1),this.material=new fs({uniforms:e,defines:t,vertexShader:Bp,fragmentShader:Tn,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest});else throw new Error("render mode unavailable");this.material&&r&&(this.material.onBeforeRender=r)}update(){let e=0,t=0;const i=this.getVisibleSystems();for(const s of i)t+=s.particleNum;t>this.maxParticles&&this.expandBuffers(t);for(const s of i){s.emitter.updateMatrixWorld&&(s.emitter.updateWorldMatrix(!0,!1),s.emitter.updateMatrixWorld(!0));const r=s.particles,n=s.particleNum,a=this.quaternion2_,l=this.vector2_,c=this.vector3_;s.emitter.matrixWorld.decompose(l,a,c),this.rotationMat_.setFromMatrix4(s.emitter.matrixWorld);for(let h=0;h<n;h++,e++){const d=r[h];if(this.settings.renderMode===L.Mesh){let u;if(s.worldSpace)u=d.rotation;else{let f;d.parentMatrix?f=this.quaternion3_.setFromRotationMatrix(d.parentMatrix):f=a,u=this.quaternion_,u.copy(f).multiply(d.rotation)}this.rotationBuffer.setXYZW(e,u.x,u.y,u.z,u.w)}else(this.settings.renderMode===L.StretchedBillBoard||this.settings.renderMode===L.VerticalBillBoard||this.settings.renderMode===L.HorizontalBillBoard||this.settings.renderMode===L.BillBoard)&&this.rotationBuffer.setX(e,d.rotation);let p;if(s.worldSpace?p=d.position:(p=this.vector_,d.parentMatrix?p.copy(d.position).applyMatrix4(d.parentMatrix):p.copy(d.position).applyMatrix4(s.emitter.matrixWorld)),this.offsetBuffer.setXYZ(e,p.x,p.y,p.z),this.colorBuffer.setXYZW(e,d.color.x,d.color.y,d.color.z,d.color.w),s.worldSpace?this.sizeBuffer.setXYZ(e,d.size.x,d.size.y,d.size.z):d.parentMatrix?this.sizeBuffer.setXYZ(e,d.size.x,d.size.y,d.size.z):this.sizeBuffer.setXYZ(e,d.size.x*Math.abs(c.x),d.size.y*Math.abs(c.y),d.size.z*Math.abs(c.z)),this.uvTileBuffer.setX(e,d.uvTile),this.settings.renderMode===L.StretchedBillBoard&&this.velocityBuffer){let u=s.rendererEmitterSettings.speedFactor;u===0&&(u=.001);const f=s.rendererEmitterSettings.lengthFactor;let m;s.worldSpace?m=d.velocity:(m=this.vector_,d.parentMatrix?(this.rotationMat2_.setFromMatrix4(d.parentMatrix),m.copy(d.velocity).applyMatrix3(this.rotationMat2_)):m.copy(d.velocity).applyMatrix3(this.rotationMat_)),this.velocityBuffer.setXYZW(e,m.x*u,m.y*u,m.z*u,f)}}}this.geometry.instanceCount=e,e>0&&(this.offsetBuffer.clearUpdateRanges(),this.offsetBuffer.addUpdateRange(0,e*3),this.offsetBuffer.needsUpdate=!0,this.sizeBuffer.clearUpdateRanges(),this.sizeBuffer.addUpdateRange(0,e*3),this.sizeBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.uvTileBuffer.clearUpdateRanges(),this.uvTileBuffer.addUpdateRange(0,e),this.uvTileBuffer.needsUpdate=!0,this.settings.renderMode===L.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,e*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===L.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===L.StretchedBillBoard||this.settings.renderMode===L.HorizontalBillBoard||this.settings.renderMode===L.VerticalBillBoard||this.settings.renderMode===L.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var Vp=`
|
|
933
|
+
|
|
934
|
+
#include <common>
|
|
935
|
+
#include <tile_pars_fragment>
|
|
936
|
+
#include <map_pars_fragment>
|
|
937
|
+
#include <fog_pars_fragment>
|
|
938
|
+
#include <logdepthbuf_pars_fragment>
|
|
939
|
+
#include <clipping_planes_pars_fragment>
|
|
940
|
+
|
|
941
|
+
uniform sampler2D alphaMap;
|
|
942
|
+
uniform float useAlphaMap;
|
|
943
|
+
uniform float visibility;
|
|
944
|
+
uniform float alphaTest;
|
|
945
|
+
|
|
946
|
+
varying vec4 vColor;
|
|
947
|
+
|
|
948
|
+
void main() {
|
|
949
|
+
#include <clipping_planes_fragment>
|
|
950
|
+
#include <logdepthbuf_fragment>
|
|
951
|
+
|
|
952
|
+
vec4 diffuseColor = vColor;
|
|
953
|
+
|
|
954
|
+
#ifdef USE_MAP
|
|
955
|
+
#include <tile_fragment>
|
|
956
|
+
#ifndef USE_COLOR_AS_ALPHA
|
|
957
|
+
#endif
|
|
958
|
+
#endif
|
|
959
|
+
if( useAlphaMap == 1. ) diffuseColor.a *= texture2D( alphaMap, vUv).a;
|
|
960
|
+
if( diffuseColor.a < alphaTest ) discard;
|
|
961
|
+
gl_FragColor = diffuseColor;
|
|
962
|
+
|
|
963
|
+
#include <fog_fragment>
|
|
964
|
+
#include <tonemapping_fragment>
|
|
965
|
+
}`,Up=`
|
|
966
|
+
#include <common>
|
|
967
|
+
#include <tile_pars_vertex>
|
|
968
|
+
#include <color_pars_vertex>
|
|
969
|
+
#include <clipping_planes_pars_vertex>
|
|
970
|
+
#include <logdepthbuf_pars_vertex>
|
|
971
|
+
#include <fog_pars_vertex>
|
|
972
|
+
|
|
973
|
+
attribute vec3 previous;
|
|
974
|
+
attribute vec3 next;
|
|
975
|
+
attribute float side;
|
|
976
|
+
attribute float width;
|
|
977
|
+
|
|
978
|
+
uniform vec2 resolution;
|
|
979
|
+
uniform float lineWidth;
|
|
980
|
+
uniform float sizeAttenuation;
|
|
981
|
+
|
|
982
|
+
vec2 fix(vec4 i, float aspect) {
|
|
983
|
+
vec2 res = i.xy / i.w;
|
|
984
|
+
res.x *= aspect;
|
|
985
|
+
return res;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
void main() {
|
|
989
|
+
|
|
990
|
+
#include <tile_vertex>
|
|
991
|
+
|
|
992
|
+
float aspect = resolution.x / resolution.y;
|
|
993
|
+
|
|
994
|
+
vColor = color;
|
|
995
|
+
|
|
996
|
+
mat4 m = projectionMatrix * modelViewMatrix;
|
|
997
|
+
vec4 finalPosition = m * vec4( position, 1.0 );
|
|
998
|
+
vec4 prevPos = m * vec4( previous, 1.0 );
|
|
999
|
+
vec4 nextPos = m * vec4( next, 1.0 );
|
|
1000
|
+
|
|
1001
|
+
vec2 currentP = fix( finalPosition, aspect );
|
|
1002
|
+
vec2 prevP = fix( prevPos, aspect );
|
|
1003
|
+
vec2 nextP = fix( nextPos, aspect );
|
|
1004
|
+
|
|
1005
|
+
float w = lineWidth * width;
|
|
1006
|
+
|
|
1007
|
+
vec2 dir;
|
|
1008
|
+
if( nextP == currentP ) dir = normalize( currentP - prevP );
|
|
1009
|
+
else if( prevP == currentP ) dir = normalize( nextP - currentP );
|
|
1010
|
+
else {
|
|
1011
|
+
vec2 dir1 = normalize( currentP - prevP );
|
|
1012
|
+
vec2 dir2 = normalize( nextP - currentP );
|
|
1013
|
+
dir = normalize( dir1 + dir2 );
|
|
1014
|
+
|
|
1015
|
+
vec2 perp = vec2( -dir1.y, dir1.x );
|
|
1016
|
+
vec2 miter = vec2( -dir.y, dir.x );
|
|
1017
|
+
//w = clamp( w / dot( miter, perp ), 0., 4., * lineWidth * width );
|
|
1018
|
+
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
//vec2 normal = ( cross( vec3( dir, 0. ) vec3( 0., 0., 1. ) ) ).xy;
|
|
1022
|
+
vec4 normal = vec4( -dir.y, dir.x, 0., 1. );
|
|
1023
|
+
normal.xy *= .5 * w;
|
|
1024
|
+
normal *= projectionMatrix;
|
|
1025
|
+
if( sizeAttenuation == 0. ) {
|
|
1026
|
+
normal.xy *= finalPosition.w;
|
|
1027
|
+
normal.xy /= ( vec4( resolution, 0., 1. ) * projectionMatrix ).xy;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
finalPosition.xy += normal.xy * side;
|
|
1031
|
+
|
|
1032
|
+
gl_Position = finalPosition;
|
|
1033
|
+
|
|
1034
|
+
#include <logdepthbuf_vertex>
|
|
1035
|
+
#include <clipping_planes_vertex>
|
|
1036
|
+
|
|
1037
|
+
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
1038
|
+
|
|
1039
|
+
#include <fog_vertex>
|
|
1040
|
+
}`;class jp extends uc{constructor(e){super(e),this.vector_=new F,this.vector2_=new F,this.vector3_=new F,this.quaternion_=new te,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new Et,this.indexBuffer=new mt(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(De),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new mt(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(De),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new mt(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(De),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new mt(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(De),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new mt(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(De),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new mt(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(De),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new mt(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(De),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new mt(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(De),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new Ni(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},t={};if(t.USE_UV="",t.USE_COLOR_ALPHA="",this.settings.material.map&&(t.USE_MAP="",t.MAP_UV=so(this.settings.material.map.channel),e.map=new it(this.settings.material.map),e.mapTransform=new it(new xt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===L.Trail)this.material=new fs({uniforms:e,defines:t,vertexShader:Up,fragmentShader:Vp,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||po,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let e=0,t=0,i=0;const s=this.getVisibleSystems();for(const r of s)for(let n=0;n<r.particleNum;n++)i+=r.particles[n].previous.length*2;i>this.maxParticles&&this.expandBuffers(i);for(const r of s){r.emitter.updateMatrixWorld&&(r.emitter.updateWorldMatrix(!0,!1),r.emitter.updateMatrixWorld(!0));const n=this.quaternion_,a=this.vector2_,l=this.vector3_;r.emitter.matrixWorld.decompose(a,n,l);const c=r.particles,h=r.particleNum,d=this.settings.uTileCount,p=this.settings.vTileCount,u=1/d,f=1/p;for(let m=0;m<h;m++){const y=c[m],_=y.uvTile%p,x=Math.floor(y.uvTile/p+.001),S=y.previous.values();let w=S.next(),C=w.value,b=C;w.done||(w=S.next());let M;w.value!==void 0?M=w.value:M=b;for(let P=0;P<y.previous.length;P++,e+=2){if(this.positionBuffer.setXYZ(e,b.position.x,b.position.y,b.position.z),this.positionBuffer.setXYZ(e+1,b.position.x,b.position.y,b.position.z),r.worldSpace?(this.positionBuffer.setXYZ(e,b.position.x,b.position.y,b.position.z),this.positionBuffer.setXYZ(e+1,b.position.x,b.position.y,b.position.z)):(y.parentMatrix?this.vector_.copy(b.position).applyMatrix4(y.parentMatrix):this.vector_.copy(b.position).applyMatrix4(r.emitter.matrixWorld),this.positionBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.previousBuffer.setXYZ(e,C.position.x,C.position.y,C.position.z),this.previousBuffer.setXYZ(e+1,C.position.x,C.position.y,C.position.z)):(y.parentMatrix?this.vector_.copy(C.position).applyMatrix4(y.parentMatrix):this.vector_.copy(C.position).applyMatrix4(r.emitter.matrixWorld),this.previousBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.nextBuffer.setXYZ(e,M.position.x,M.position.y,M.position.z),this.nextBuffer.setXYZ(e+1,M.position.x,M.position.y,M.position.z)):(y.parentMatrix?this.vector_.copy(M.position).applyMatrix4(y.parentMatrix):this.vector_.copy(M.position).applyMatrix4(r.emitter.matrixWorld),this.nextBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(e,1),this.sideBuffer.setX(e+1,-1),r.worldSpace)this.widthBuffer.setX(e,b.size),this.widthBuffer.setX(e+1,b.size);else if(y.parentMatrix)this.widthBuffer.setX(e,b.size),this.widthBuffer.setX(e+1,b.size);else{const E=(Math.abs(l.x)+Math.abs(l.y)+Math.abs(l.z))/3;this.widthBuffer.setX(e,b.size*E),this.widthBuffer.setX(e+1,b.size*E)}this.uvBuffer.setXY(e,(P/y.previous.length+_)*u,(p-x-1)*f),this.uvBuffer.setXY(e+1,(P/y.previous.length+_)*u,(p-x)*f),this.colorBuffer.setXYZW(e,b.color.x,b.color.y,b.color.z,b.color.w),this.colorBuffer.setXYZW(e+1,b.color.x,b.color.y,b.color.z,b.color.w),P+1<y.previous.length&&(this.indexBuffer.setX(t*3,e),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+2),t++,this.indexBuffer.setX(t*3,e+2),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+3),t++),C=b,b=M,w.done||(w=S.next(),w.value!==void 0&&(M=w.value))}}}this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,e*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,e*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,e*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,e),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,e),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,e*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,t*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,t*3)}dispose(){this.geometry.dispose()}}class So extends ui{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(e,t){return e.material.side===t.material.side&&e.material.blending===t.material.blending&&e.material.blendSrc===t.material.blendSrc&&e.material.blendDst===t.material.blendDst&&e.material.blendEquation===t.material.blendEquation&&e.material.premultipliedAlpha===t.material.premultipliedAlpha&&e.material.transparent===t.material.transparent&&e.material.depthTest===t.material.depthTest&&e.material.type===t.material.type&&e.material.alphaTest===t.material.alphaTest&&e.material.map===t.material.map&&e.renderMode===t.renderMode&&e.blendTiles===t.blendTiles&&e.softParticles===t.softParticles&&e.softFarFade===t.softFarFade&&e.softNearFade===t.softNearFade&&e.uTileCount===t.uTileCount&&e.vTileCount===t.vTileCount&&e.instancingGeometry===t.instancingGeometry&&e.renderOrder===t.renderOrder&&e.layers.mask===t.layers.mask}addSystem(e){e._renderer=this;const t=e.getRendererSettings();for(let s=0;s<this.batches.length;s++)if(So.equals(this.batches[s].settings,t)){this.batches[s].addSystem(e),this.systemToBatchIndex.set(e,s);return}let i;switch(t.renderMode){case L.Trail:i=new jp(t);break;case L.Mesh:case L.BillBoard:case L.VerticalBillBoard:case L.HorizontalBillBoard:case L.StretchedBillBoard:i=new Dp(t);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(e),this.batches.push(i),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(i)}deleteSystem(e){const t=this.systemToBatchIndex.get(e);t!=null&&(this.batches[t].removeSystem(e),this.systemToBatchIndex.delete(e))}setDepthTexture(e){this.depthTexture=e;for(const t of this.batches)t.applyDepthTexture(e)}updateSystem(e){this.deleteSystem(e),this.addSystem(e)}update(e){this.systemToBatchIndex.forEach((t,i)=>{i.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}class Mo extends Ve{constructor(){super(),this.type="QuarksPrefab",this.animationData=[],this.isPlaying=!1,this.currentTime=-1e-5,this.timeScale=1,this.duration=0,this._mixers=new Map,this._tempAnimationJSON=[],this._clock=new Ld(!0)}registerBatchedRenderer(e){this._batchedRenderer=e}getOrCreateMixer(e){if(!this._mixers.has(e)){const t=new Jl(e);this._mixers.set(e,t)}return this._mixers.get(e)}addThreeAnimation(e,t,i=0,s=t.duration,r=!1){const n=this.getOrCreateMixer(e),a=n.clipAction(t);r||(a.setLoop(Fd,1),a.clampWhenFinished=!0);const l={startTime:i,duration:s,type:"three",loop:r,target:e,clip:t,mixer:n,action:a};return this.animationData.push(l),this.updateDuration(),l}addParticleSystemAnimation(e,t=0,i=0,s=!1){i<=0&&(i=e.system.duration);const r={startTime:t,duration:i,type:"ps",loop:s,target:e};return this.animationData.push(r),this.pause(),this.updateDuration(),r}removeAnimation(e){this.animationData.splice(e,1),this.updateDuration()}play(){this.isPlaying||(this.isPlaying=!0)}pause(){this.isPlaying&&(this.isPlaying=!1,this.animationData.forEach(e=>{e.target&&(e.type==="ps"&&!e.target.system.paused?e.target.system.pause():e.type==="three"&&e.action&&e.action.isRunning()&&(e.action.paused=!0))}))}stop(){this.pause(),this.currentTime=-1e-5,this.animationData.forEach(e=>{e.type==="ps"&&e.target?e.target.system.stop():e.type==="three"&&e.mixer&&e.action&&e.action.reset()})}update(e){if(!this.isPlaying)return;const t=e!==void 0?e:this._clock.getDelta();this.currentTime+=t*this.timeScale,this.currentTime>this.duration&&this.stop();const i=new Set;this.animationData.forEach(s=>{const{startTime:r,duration:n,type:a,loop:l,target:c,action:h,mixer:d}=s,p=r+n,u=this.currentTime>=r,f=this.currentTime>p,m=Math.abs(this.currentTime-r)<t;a==="three"&&h&&d?u&&!f?(m?(h.reset(),h.play()):h.paused&&(h.paused=!1,h.play()),this.currentTime-r,i.add(d)):f&&(h.paused=!0):a==="ps"&&c&&(u&&!f?m&&s.target.system.restart():f&&s.target.system.endEmit())}),i.forEach(s=>{s.update(t)})}setTime(e){const t=this.currentTime;this.currentTime=e,this.animationData.forEach(i=>{const{startTime:s,duration:r,type:n,target:a,action:l,mixer:c}=i;if(n==="three"&&l&&c){if(l.reset(),e>=s&&e<s+r){const h=e-s;l.time=h,l.play(),c.update(0),l.paused=!this.isPlaying}}else n==="ps"&&a&&(e>=s&&e<s+r?(t<s||t>=s+r)&&a.system.restart():a.system.endEmit())})}getDuration(){return this.duration}updateDuration(){let e=0;this.animationData.forEach(t=>{const i=t.startTime+t.duration;i>e&&(e=i)}),this.duration=e}resolveReferences(e){this._tempAnimationJSON.forEach(t=>{let i;if(e.traverse(s=>{s.uuid===t.targetUUID&&(i=s)}),i)if(t.type==="three"&&t.clipUUID){let s;i.animations&&(s=i.animations.find(r=>r.uuid===t.clipUUID)),s&&this.addThreeAnimation(i,s,t.startTime,t.duration,t.loop)}else t.type==="ps"&&this.addParticleSystemAnimation(i,t.startTime,t.duration,t.loop)}),this.updateDuration(),this._tempAnimationJSON=[]}toJSON(){const e=super.toJSON();return e.object.animationData=this.animationData.map(t=>({startTime:t.startTime,duration:t.duration,type:t.type,targetUUID:t.target.uuid,clipUUID:t.clip?.uuid,loop:t.loop})),e}static fromJSON(e){const t=new Mo;return e.animationData&&(t._tempAnimationJSON=e.animationData),t}}class Gg extends bd{constructor(e){super(e)}linkReference(e){const t={};e.traverse(function(i){t[i.uuid]=i}),e.traverse(function(i){if(i.type==="ParticleEmitter"){const s=i.system;s.emitterShape;for(let r=0;r<s.behaviors.length;r++)s.behaviors[r]instanceof Ui&&(s.behaviors[r].subParticleSystem=t[s.behaviors[r].subParticleSystem])}})}parse(e,t){const i=super.parse(e,t);return this.linkReference(i),i}parseObject(e,t,i,s,r){let n;function a(f){return t[f]===void 0&&console.warn("THREE.ObjectLoader: Undefined geometry",f),t[f]}function l(f){if(f!==void 0){if(Array.isArray(f)){const m=[];for(let y=0,_=f.length;y<_;y++){const x=f[y];i[x]===void 0&&console.warn("THREE.ObjectLoader: Undefined material",x),m.push(i[x])}return m}return i[f]===void 0&&console.warn("THREE.ObjectLoader: Undefined material",f),i[f]}}function c(f){return s[f]===void 0&&console.warn("THREE.ObjectLoader: Undefined texture",f),s[f]}let h,d;const p={textures:s,geometries:t,materials:i},u={};switch(e.type){case"QuarksPrefab":n=Mo.fromJSON(e);break;case"ParticleEmitter":n=Gr.fromJSON(e.ps,p,u).emitter;break;case"Scene":n=new Jr,e.background!==void 0&&(Number.isInteger(e.background)?n.background=new V(e.background):n.background=c(e.background)),e.environment!==void 0&&(n.environment=c(e.environment)),e.fog!==void 0&&(e.fog.type==="Fog"?n.fog=new Rd(e.fog.color,e.fog.near,e.fog.far):e.fog.type==="FogExp2"&&(n.fog=new Id(e.fog.color,e.fog.density)),e.fog.name!==""&&(n.fog.name=e.fog.name)),e.backgroundBlurriness!==void 0&&(n.backgroundBlurriness=e.backgroundBlurriness),e.backgroundIntensity!==void 0&&(n.backgroundIntensity=e.backgroundIntensity),e.backgroundRotation!==void 0&&n.backgroundRotation.fromArray(e.backgroundRotation),e.environmentIntensity!==void 0&&(n.environmentIntensity=e.environmentIntensity),e.environmentRotation!==void 0&&n.environmentRotation.fromArray(e.environmentRotation);break;case"PerspectiveCamera":n=new yo(e.fov,e.aspect,e.near,e.far),e.focus!==void 0&&(n.focus=e.focus),e.zoom!==void 0&&(n.zoom=e.zoom),e.filmGauge!==void 0&&(n.filmGauge=e.filmGauge),e.filmOffset!==void 0&&(n.filmOffset=e.filmOffset),e.view!==void 0&&(n.view=Object.assign({},e.view));break;case"OrthographicCamera":n=new Fi(e.left,e.right,e.top,e.bottom,e.near,e.far),e.zoom!==void 0&&(n.zoom=e.zoom),e.view!==void 0&&(n.view=Object.assign({},e.view));break;case"AmbientLight":n=new Kl(e.color,e.intensity);break;case"DirectionalLight":n=new $l(e.color,e.intensity);break;case"PointLight":n=new kd(e.color,e.intensity,e.distance,e.decay);break;case"RectAreaLight":n=new Td(e.color,e.intensity,e.width,e.height);break;case"SpotLight":n=new Od(e.color,e.intensity,e.distance,e.angle,e.penumbra,e.decay);break;case"HemisphereLight":n=new zd(e.color,e.groundColor,e.intensity);break;case"LightProbe":n=new Ed().fromJSON(e);break;case"SkinnedMesh":h=a(e.geometry),d=l(e.material),n=new Ad(h,d),e.bindMode!==void 0&&(n.bindMode=e.bindMode),e.bindMatrix!==void 0&&n.bindMatrix.fromArray(e.bindMatrix),e.skeleton!==void 0&&(n.skeleton=e.skeleton);break;case"Mesh":h=a(e.geometry),d=l(e.material),n=new T(h,d);break;case"InstancedMesh":{h=a(e.geometry),d=l(e.material);const f=e.count,m=e.instanceMatrix,y=e.instanceColor;n=new Pd(h,d,f),n.instanceMatrix=new Ct(new Float32Array(m.array),16),y!==void 0&&(n.instanceColor=new Ct(new Float32Array(y.array),y.itemSize));break}case"BatchedMesh":h=a(e.geometry),d=l(e.material),n=new Cd(e.maxGeometryCount,e.maxVertexCount,e.maxIndexCount,d),n.geometry=h,n.perObjectFrustumCulled=e.perObjectFrustumCulled,n.sortObjects=e.sortObjects,n._drawRanges=e.drawRanges,n._reservedRanges=e.reservedRanges,n._visibility=e.visibility,n._active=e.active,n._bounds=e.bounds.map(f=>{const m=new wt;m.min.fromArray(f.boxMin),m.max.fromArray(f.boxMax);const y=new go;return y.radius=f.sphereRadius,y.center.fromArray(f.sphereCenter),{boxInitialized:f.boxInitialized,box:m,sphereInitialized:f.sphereInitialized,sphere:y}}),n._maxGeometryCount=e.maxGeometryCount,n._maxVertexCount=e.maxVertexCount,n._maxIndexCount=e.maxIndexCount,n._geometryInitialized=e.geometryInitialized,n._geometryCount=e.geometryCount,n._matricesTexture=c(e.matricesTexture.uuid);break;case"LOD":n=new Md;break;case"Line":n=new st(a(e.geometry),l(e.material));break;case"LineLoop":n=new Ql(a(e.geometry),l(e.material));break;case"LineSegments":n=new Li(a(e.geometry),l(e.material));break;case"PointCloud":case"Points":n=new mo(a(e.geometry),l(e.material));break;case"Sprite":n=new $n(l(e.material));break;case"Group":n=new Ve;break;case"Bone":n=new Sd;break;default:n=new ui}if(n.uuid=e.uuid,e.name!==void 0&&(n.name=e.name),e.matrix!==void 0?(n.matrix.fromArray(e.matrix),e.matrixAutoUpdate!==void 0&&(n.matrixAutoUpdate=e.matrixAutoUpdate),n.matrixAutoUpdate&&(n.matrix.decompose(n.position,n.quaternion,n.scale),isNaN(n.quaternion.x)&&n.quaternion.set(0,0,0,1))):(e.position!==void 0&&n.position.fromArray(e.position),e.rotation!==void 0&&n.rotation.fromArray(e.rotation),e.quaternion!==void 0&&n.quaternion.fromArray(e.quaternion),e.scale!==void 0&&n.scale.fromArray(e.scale)),e.up!==void 0&&n.up.fromArray(e.up),e.castShadow!==void 0&&(n.castShadow=e.castShadow),e.receiveShadow!==void 0&&(n.receiveShadow=e.receiveShadow),e.shadow&&(e.shadow.bias!==void 0&&(n.shadow.bias=e.shadow.bias),e.shadow.normalBias!==void 0&&(n.normalBias=e.shadow.normalBias),e.shadow.radius!==void 0&&(n.radius=e.shadow.radius),e.shadow.mapSize!==void 0&&n.mapSize.fromArray(e.shadow.mapSize),e.shadow.camera!==void 0&&(n.camera=this.parseObject(e.shadow.camera))),e.visible!==void 0&&(n.visible=e.visible),e.frustumCulled!==void 0&&(n.frustumCulled=e.frustumCulled),e.renderOrder!==void 0&&(n.renderOrder=e.renderOrder),e.userData!==void 0&&(n.userData=e.userData),e.layers!==void 0&&(n.layers.mask=e.layers),e.children!==void 0){const f=e.children;for(let m=0;m<f.length;m++)n.add(this.parseObject(f[m],t,i,s,r))}if(e.animations!==void 0){const f=e.animations;for(let m=0;m<f.length;m++){const y=f[m];n.animations.push(r[y])}}if(e.type==="LOD"){e.autoUpdate!==void 0&&(n.autoUpdate=e.autoUpdate);const f=e.levels;for(let m=0;m<f.length;m++){const y=f[m],_=n.getObjectByProperty("uuid",y.object);_!==void 0&&n.addLevel(_,y.distance)}}else e.type==="QuarksPrefab"&&n.resolveReferences(n);return n}}Op();wp(xp);console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");let pc=null;function el(o){pc=o,uu(o?.editorControls??null)}function Gp(){return pc}const kn=new V(4441855),Pr=new V(16758858),Ar=new V(14185983),Wp=new V(16731496),tl=new V(16777215);function Rn(o){return new st(new Et,new qt({color:o,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1}))}function In(o,e){return new T(o,new Ce({color:e,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1}))}function Ln(o,e){if(o.visible=e.length>1,!o.visible)return;let t=o.geometry.getAttribute("position");(!t||t.count!==e.length)&&(t=new ps(e.length*3,3),o.geometry.setAttribute("position",t));for(let i=0;i<e.length;i++)t.setXYZ(i,e[i].x,e[i].y,e[i].z);t.needsUpdate=!0,o.geometry.computeBoundingSphere()}class Xp extends Ve{constructor(e){super(),this.source=e,this.name="Constraint Helper",this.renderOrder=999,qe(this,"editorHelper",!0),qe(this,"editorHelperType","constraints"),this.layers.set(Z),this.refreshStructure()}selected=!1;hoveredControl=null;selectedObjects=new Set;visuals=[];setSelected(e){this.selected=e}setSelectedObjects(e){this.selectedObjects=e}controlMeshes(){return this.visuals.flatMap(e=>[e.targetHit,e.poleHit].filter(t=>t.visible))}presents(e){return e===this.source?!0:this.visuals.some(t=>{const i=t.mark.getSnapshot();return e===i.target||e===i.pole})}controlFor(e){for(const t of this.visuals){const i=t.mark.getSnapshot();if((e===t.target||e===t.targetHit)&&i.target)return{kind:"target",label:i.target.name||`${t.mark.config.label} target`,object:i.target,mesh:t.target};if((e===t.pole||e===t.poleHit)&&i.pole)return{kind:"pole",label:i.pole.name||`${t.mark.config.label} pole`,object:i.pole,mesh:t.pole}}return null}setHoveredControl(e){this.hoveredControl=e}update(e){this.refreshStructure();for(const t of this.visuals)this.updateVisual(t,e)}dispose(){this.clearVisuals(),this.removeFromParent()}refreshStructure(){const e=Nr(this.source);e.length===this.visuals.length&&e.every((i,s)=>{const r=i.getSnapshot(),n=r.chain.length>0?r.chain.length:r.constrained?1:0;return this.visuals[s]?.mark===i&&this.visuals[s]?.positions.length===n})||(this.clearVisuals(),this.visuals=e.map(i=>this.makeVisual(i)))}makeVisual(e){const t=e.getSnapshot(),i=t.chain.length>0?t.chain:t.constrained?[t.constrained]:[],s=Rn(kn),r=Rn(Pr),n=Rn(Ar),a=i.map(()=>In(new At(.035,10,7),kn)),l=In(new ni(.085),Pr),c=In(new Vd(.075),Ar),h=new Ce({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,colorWrite:!1}),d=new T(new At(.16,10,7),h),p=new T(new At(.15,10,7),h.clone());for(const u of[s,r,n,...a,l,c,d,p])u.renderOrder=this.renderOrder,u.layers.set(Z),this.add(u);return{mark:e,chain:s,targetLine:r,poleLine:n,joints:a,target:l,pole:c,targetHit:d,poleHit:p,positions:i.map(()=>new v),targetPosition:new v,polePosition:new v}}updateVisual(e,t){const i=e.mark.getSnapshot(),s=i.chain.length>0?i.chain:i.constrained?[i.constrained]:[];for(let p=0;p<s.length;p++)s[p].getWorldPosition(e.positions[p]);Ln(e.chain,e.positions);for(let p=0;p<e.joints.length;p++){const u=e.joints[p],f=e.positions[p];u.visible=!!f,f&&(u.position.copy(f),u.scale.setScalar(this.handleScale(t,f)))}const r=e.positions.at(-1),n=i.target?.getWorldPosition(e.targetPosition)??null,a=i.pole?.getWorldPosition(e.polePosition)??null;Ln(e.targetLine,r&&n?[r,n]:[]),Ln(e.poleLine,e.positions[0]&&a?[e.positions[0],a]:[]),e.target.visible=n!==null,n&&(e.target.position.copy(n),e.target.scale.setScalar(this.handleScale(t,n)*(this.hoveredControl===e.target?1.22:1))),e.targetHit.visible=n!==null,n&&(e.targetHit.position.copy(n),e.targetHit.scale.copy(e.target.scale)),e.pole.visible=a!==null,a&&(e.pole.position.copy(a),e.pole.scale.setScalar(this.handleScale(t,a)*(this.hoveredControl===e.pole?1.22:1))),e.poleHit.visible=a!==null,a&&(e.poleHit.position.copy(a),e.poleHit.scale.copy(e.pole.scale));const l=i.status==="error"||i.status==="unresolved",c=this.selected?1:.52;for(const p of[e.chain,...e.joints]){const u=p.material;u.color.copy(l?Wp:kn),u.opacity=c}const h=this.hoveredControl===e.target||i.target!==null&&this.selectedObjects.has(i.target),d=this.hoveredControl===e.pole||i.pole!==null&&this.selectedObjects.has(i.pole);e.target.material.color.copy(h?tl:Pr),e.pole.material.color.copy(d?tl:Ar),e.targetLine.material.color.copy(Pr),e.poleLine.material.color.copy(Ar),e.targetLine.material.opacity=c,e.poleLine.material.opacity=c,e.target.material.opacity=h?1:c,e.pole.material.opacity=d?1:c}handleScale(e,t){return Le.clamp(e.position.distanceTo(t)/8,.65,4)}clearVisuals(){for(const e of[...this.children]){e.removeFromParent();const t=e;t.geometry.dispose();const i=Array.isArray(t.material)?t.material:[t.material];for(const s of i)s.dispose()}this.visuals=[],this.hoveredControl=null}}const qp=new V(4892927),Jp=new V(7718143),Yp=new V(16758858),Zp=new V(16777215);class Qp extends Ve{constructor(e){super(),this.source=e,this.name="Reflection Probe Helper",this.matrixAutoUpdate=!1,this.renderOrder=998,qe(this,"editorHelper",!0),qe(this,"editorHelperType","reflection-probes"),this.layers.set(Z),this.refresh(!0)}signature="";selected=!1;setSelected(e){this.selected!==e&&(this.selected=e,this.refresh(!0))}update(){this.refresh(!1),this.source.updateWorldMatrix(!0,!1),this.matrix.copy(this.source.matrixWorld),this.matrixWorldNeedsUpdate=!0}dispose(){this.clearVisuals(),this.removeFromParent()}refresh(e){const t=us(this.source);if(!t)return;const i=t.config,s=JSON.stringify(i);if(!e&&s===this.signature)return;this.signature=s,this.clearVisuals();const r=this.selected?Jp:qp,n=this.selected?1:.62,a=Math.max(0,i.blendDistance);if(i.shape==="sphere"){const c=Math.max(.01,i.radius);this.addWire(new At(c,24,16),r,n),a>0&&c-a>.01&&this.addWire(new At(c-a,20,12),r,this.selected?.55:.28)}else{const[c,h,d]=i.size.map(u=>Math.max(.01,u));this.addWire(new xe(c,h,d),r,n);const p=[c-a*2,h-a*2,d-a*2];a>0&&p.every(u=>u>.01)&&this.addWire(new xe(p[0],p[1],p[2]),r,this.selected?.55:.28)}if(i.parallaxProjection){const[c,h,d]=i.parallaxSize.map(u=>Math.max(.01,u));this.addWire(new xe(c,h,d),Yp,this.selected?.9:.45).position.fromArray(i.parallaxOffset)}this.addWire(new ni(this.selected?.16:.11),Zp,this.selected?1:.72).position.fromArray(i.captureOffset),this.traverse(c=>c.layers.set(Z))}addWire(e,t,i){const s=new _o(e);e.dispose();const r=new qt({color:t,depthTest:!1,transparent:!0,opacity:i,toneMapped:!1}),n=new Li(s,r);return n.renderOrder=this.renderOrder,this.add(n),n}clearVisuals(){for(const e of[...this.children]){e.removeFromParent();const t=e;t.geometry?.dispose();const i=Array.isArray(t.material)?t.material:[t.material];for(const s of i)s?.dispose()}}}const $p={maxOutlierFraction:.1,minGapFraction:.2,minSampleSize:8,maxPasses:8},Kp=10,ef=.01,tf=["x","y","z"];function il(o,e){const t=new wt;for(const i of e)t.union(o[i]);return t}function sf(o,e,t){let i=null;for(const s of tf)for(const r of["min","max"]){const n=[];for(const l of e)n.push({i:l,v:o[l][r][s]});n.sort((l,c)=>r==="min"?l.v-c.v:c.v-l.v);const a=Math.min(t,n.length-1);for(let l=0;l<a;l++){const c=Math.abs(n[l+1].v-n[l].v);i&&c<=i.gap||(i={gap:c,discard:n.slice(0,l+1).map(h=>h.i)})}}return i}function sl(o,e={}){const t={...$p,...e},i=o.filter(h=>!h.isEmpty()),s=i.map((h,d)=>d),r=il(i,s);if(i.length<t.minSampleSize)return r;let n=Math.floor(i.length*t.maxOutlierFraction);if(n<1)return r;const a=new Set(s);let l=r;const c=new v;for(let h=0;h<t.maxPasses&&n>0;h++){const d=l.getSize(c).length();if(!(d>0))break;const p=sf(i,a,n);if(!p||p.gap<=t.minGapFraction*d)break;for(const u of p.discard)a.delete(u);n-=p.discard.length,l=il(i,a)}return l.isEmpty()?r:l}function rf(o,e){const t=o.getWorldDirection(new v),i=new v().setFromMatrixPosition(o.matrixWorld);if(!Number.isFinite(i.lengthSq())||t.lengthSq()===0)return null;if(e.isEmpty())return{position:i,target:i.clone().addScaledVector(t,Kp)};const s=e.getBoundingSphere(new go),r=s.center.clone().sub(i).dot(t);return r>s.radius*ef?{position:i,target:i.clone().addScaledVector(t,r)}:null}const nf=[[0,0],[-.6,.6],[.6,.6],[-.6,-.6],[.6,-.6],[0,.6],[0,-.6],[-.6,0],[.6,0]],of=.02,rl=new nt,nl=new je;function af(o){for(let e=o;e;e=e.parent)if(!e.visible)return!1;return!0}function lf(o,e,t){if(!(t>0)||e.length===0)return!0;const i=t*of;for(const[s,r]of nf){nl.set(s,r),rl.setFromCamera(nl,o);const a=rl.intersectObjects(e,!0).find(l=>af(l.object));if(!a||a.distance>i)return!0}return!1}const Co=new WeakMap,fc=new At(1,12,8);function ji(o){return new v(o[0],o[1],o[2])}function Zs(o){const e={color:o.color,transparent:!0,opacity:o.opacity??.68,depthTest:!1};return o.dashed?new ec({...e,dashSize:.18,gapSize:.12}):new qt(e)}function ot(o,e,t,i=!1){const s=i&&e.length>0?[...e,e[0]]:[...e],r=new st(new Et().setFromPoints(s),t);r.renderOrder=997,r.layers.set(Z),t instanceof ec&&r.computeLineDistances(),o.add(r)}function Tr(o,e,t,i,s=64){const r=[];for(let n=0;n<s;n++){const a=n/s*Math.PI*2;r.push(o.clone().addScaledVector(t,Math.cos(a)*e).addScaledVector(i,Math.sin(a)*e))}return r}function cf(o){const e=new Ve,t=ji(o.center),i=Zs(o);return ot(e,Tr(t,o.radius,new v(1,0,0),new v(0,1,0)),i,!0),ot(e,Tr(t,o.radius,new v(1,0,0),new v(0,0,1)),i,!0),ot(e,Tr(t,o.radius,new v(0,1,0),new v(0,0,1)),i,!0),e}function hf(o){const e=new Ve;return ot(e,o.points.map(ji),Zs(o)),e}function df(o){const e=new Ve,t=ji(o.origin),i=ji(o.direction).normalize(),s=Math.abs(i.y)<.9?new v(0,1,0):new v(1,0,0),r=new v().crossVectors(s,i).normalize(),n=new v().crossVectors(i,r).normalize(),a=Le.degToRad(Math.max(0,Math.min(360,o.angle))/2),l=Zs(o),c=[];for(let h=0;h<64;h++){const d=h/64*Math.PI*2,p=r.clone().multiplyScalar(Math.cos(d)).addScaledVector(n,Math.sin(d));c.push(t.clone().addScaledVector(i,Math.cos(a)*o.length).addScaledVector(p,Math.sin(a)*o.length))}ot(e,c,l,!0);for(const h of[0,16,32,48])ot(e,[t,c[h]],l);return e}function uf(o,e,t){return o.applyQuaternion(new pe(...t)).add(new v(...e))}function pf(o){const e=new Ve,t=Zs(o),[i,s,r]=o.halfExtents,n=[[-i,-s,-r],[i,-s,-r],[i,s,-r],[-i,s,-r],[-i,-s,r],[i,-s,r],[i,s,r],[-i,s,r]].map(([a,l,c])=>uf(new v(a,l,c),o.center,o.rotation));for(const[a,l]of[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]])ot(e,[n[a],n[l]],t);return e}function ff(o){const e=new Ve,t=Zs(o),i=new pe(...o.rotation),s=ji(o.center),r=a=>a.applyQuaternion(i).add(s),n=(a,l,c)=>Tr(new v(0,a,0),o.radius,l,c).map(r);ot(e,n(o.halfHeight,new v(1,0,0),new v(0,0,1)),t,!0),ot(e,n(-o.halfHeight,new v(1,0,0),new v(0,0,1)),t,!0);for(const[a,l]of[[o.radius,0],[-o.radius,0],[0,o.radius],[0,-o.radius]])ot(e,[r(new v(a,-o.halfHeight,l)),r(new v(a,o.halfHeight,l))],t);for(const a of["x","z"]){const l=[];for(let c=0;c<=32;c++){const h=c/32*Math.PI,d=new v(0,o.halfHeight+Math.sin(h)*o.radius,0);d[a]=Math.cos(h)*o.radius,l.push(r(d))}for(let c=0;c<=32;c++){const h=Math.PI+c/32*Math.PI,d=new v(0,-o.halfHeight+Math.sin(h)*o.radius,0);d[a]=Math.cos(h)*o.radius,l.push(r(d))}ot(e,l,t)}return e}function mf(o){const e=o.kind==="line"?hf(o):o.kind==="sphere"?cf(o):o.kind==="cone"?df(o):o.kind==="box"?pf(o):ff(o);return e.layers.set(Z),e.traverse(t=>t.layers.set(Z)),e}function gf(o,e){const t=new Ce({color:e.color,depthTest:!1,transparent:!0,opacity:e.writable?.92:.35}),i=new T(fc,t);return Object.defineProperty(i,"isSpatialHandleMesh",{value:!0}),i.position.copy(ji(e.position)),i.renderOrder=998,i.layers.set(Z),Co.set(i,{nodeId:o,handle:e}),i}function yf(o,e){const t=[],i=[];for(const s of e){for(const r of s.guides)t.push(mf(r));for(const r of s.handles){const n=gf(o,r);t.push(n),i.push(n)}}return{roots:t,handles:i}}function ol(o){return Co.get(o)??null}function Fn(o,e){const t=Co.get(o);o.material.color.set(e&&t?.handle.writable?"#ffffff":t?.handle.color??"#ffffff")}function al(o,e){const t=o.position.distanceTo(e.position);o.scale.setScalar(Math.max(.025,t*.012))}function _f(o,e,t){const i=o,s=i.geometry;s&&s!==fc&&!e.has(s)&&(s.dispose(),e.add(s));const r=Array.isArray(i.material)?i.material:i.material?[i.material]:[];for(const n of r)t.has(n)||(n.dispose(),t.add(n))}function ll(o){const e=new Set,t=new Set;for(const i of o)i.removeFromParent(),i.traverse(s=>_f(s,e,t))}function hi(o,e,t,i=1.15){if(o.isEmpty())return 3;const s=t.clone().normalize(),r=Math.abs(s.dot(e.up))>.999?new v(0,0,1):e.up,n=new v().crossVectors(r,s).normalize(),a=new v().crossVectors(s,n).normalize(),l=o.getCenter(new v);let c=0,h=0,d=0;for(const m of[o.min.x,o.max.x])for(const y of[o.min.y,o.max.y])for(const _ of[o.min.z,o.max.z]){const x=new v(m,y,_).sub(l);d=Math.max(d,Math.abs(x.dot(n))),h=Math.max(h,Math.abs(x.dot(a))),c=Math.max(c,Math.abs(x.dot(s)))}const p=Le.degToRad(e.fov*.5),u=Math.atan(Math.tan(p)*Math.max(e.aspect,.01)),f=Math.max(h/Math.tan(p),d/Math.tan(u));return Math.max(f*i+c,e.near*4,.01)}const vf=3,wf=.05,xf=.03,bf=.6,Sf=.15,Mf=.08,Cf=3,Pf=.45,mc=.001,Af=24,Ef=6,zf=[[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]];function Of(o){const e=Le.clamp(o*Sf,Mf,Cf);return Math.max(Math.min(e,o*Pf),mc)}function Bn(o){return Le.clamp(o*wf,xf,bf)}function Tf(o,e,t=!1){const{min:i,max:s}=o,r=h=>t?Math.max(h/2,mc):Of(h),n=r(s.x-i.x),a=r(s.y-i.y),l=r(s.z-i.z);let c=0;for(const[h,d,p]of zf){const u=h===0?i.x:s.x,f=d===0?i.y:s.y,m=p===0?i.z:s.z,y=h===0?n:-n,_=d===0?a:-a,x=p===0?l:-l;e[c++]=u,e[c++]=f,e[c++]=m,e[c++]=u+y,e[c++]=f,e[c++]=m,e[c++]=u,e[c++]=f,e[c++]=m,e[c++]=u,e[c++]=f+_,e[c++]=m,e[c++]=u,e[c++]=f,e[c++]=m,e[c++]=u,e[c++]=f,e[c++]=m+x}}class Nn extends Lr{entityObject;_fixedSize;_edges;_objectFrame;_toObject=new Xt;_point=new v;_axisX=new v;_axisY=new v;_axisZ=new v;_scale=new v;_positions=new Float32Array(Af*Ef);_box=new wt;_worldPos=new v;_fixedExtent=new v;_standoff=new v;_lastRootMatrix=new Float32Array(16);_requiresContinuousBounds;constructor(e,t){const i=new Fr,s=new Br({color:t.color,linewidth:t.lineWidth??vf,worldUnits:!1,alphaToCoverage:!0,toneMapped:!1,depthTest:!1,depthWrite:!1});super(i,s),this.entityObject=e,this._fixedSize=t.fixedSize,this._edges=t.edges===!0,this._objectFrame=t.frame==="object";let r=!1;e.traverse(n=>{const a=n;(n.isSkinnedMesh||Array.isArray(a.morphTargetInfluences)&&a.morphTargetInfluences.length>0||ql(n)!==null)&&(r=!0)}),this._requiresContinuousBounds=r,this.renderOrder=1,this.frustumCulled=!1,i.setPositions(this._positions),this.update()}setColor(e){this.material.color.setHex(e)}updateIfNeeded(){this.entityObject.updateWorldMatrix(!0,!1);const e=this.entityObject.matrixWorld.elements;let t=!1;for(let i=0;i<e.length;i++)if(e[i]!==this._lastRootMatrix[i]){t=!0;break}(t||this._requiresContinuousBounds)&&this.update()}update(){this.entityObject.updateWorldMatrix(!0,!1);const e=this._objectFrame&&this._fixedSize===void 0&&Math.abs(this.entityObject.matrixWorld.determinant())>1e-30;this.entityObject.matrixWorld.extractBasis(this._axisX,this._axisY,this._axisZ);const t=e?this._scale.set(this._axisX.length(),this._axisY.length(),this._axisZ.length()):this._scale.set(1,1,1);if(this._fixedSize!==void 0)this.entityObject.getWorldPosition(this._worldPos),this._fixedExtent.setScalar(this._fixedSize),this._box.setFromCenterAndSize(this._worldPos,this._fixedExtent);else if(e?(this._toObject.copy(this.entityObject.matrixWorld).invert(),ud(this.entityObject,this._toObject,this._box)):li(this.entityObject,this._box),this._box.isEmpty())return;if(this._box.getSize(this._standoff).multiply(t),this._standoff.set(Bn(this._standoff.x),Bn(this._standoff.y),Bn(this._standoff.z)).divide(t),this._box.expandByVector(this._standoff),Tf(this._box,this._positions,this._edges),e){const s=this.entityObject.matrixWorld;for(let r=0;r<this._positions.length;r+=3)this._point.set(this._positions[r],this._positions[r+1],this._positions[r+2]).applyMatrix4(s),this._positions[r]=this._point.x,this._positions[r+1]=this._point.y,this._positions[r+2]=this._point.z}const i=this.geometry.getAttribute("instanceStart");i&&(i.data.needsUpdate=!0),this._lastRootMatrix.set(this.entityObject.matrixWorld.elements)}dispose(){this.geometry.dispose(),this.material.dispose()}}function kf({BlendFunction:o,KernelSize:e,OutlineEffect:t},i,s,r){const n=new t(i,s,{blendFunction:o.ALPHA,visibleEdgeColor:r.visible,hiddenEdgeColor:r.hidden,edgeStrength:5,pulseSpeed:0,blur:!0,kernelSize:e.MEDIUM,resolutionScale:.5,xRay:!0});n.selectionLayer=Yn,s.layers.disable(Yn);const a=n.getFragmentShader(),l="vec3 color=edge.x*visibleEdgeColor+edge.y*hiddenEdgeColor;",c="edge*=(edgeStrength*mask.x*pulse);";a.includes(l)&&a.includes(c)&&(n.setFragmentShader(a.replace("uniform float edgeStrength;","uniform float edgeStrength;uniform float vgaiCrisp;").replace(c,"edge*=(edgeStrength*(vgaiCrisp>0.5?1.0:mask.x)*pulse);").replace(l,`${l}if(vgaiCrisp>0.5){float vgaiSum=edge.x+edge.y;if(vgaiSum>0.0)color/=vgaiSum;edge=min(edge,vec2(1.0));}`)),n.uniforms.set("vgaiCrisp",{value:0}));const h=n.update.bind(n);return n.update=(d,p,u)=>{const f=n.camera,m=f.layers.isEnabled(Z);f.layers.disable(Z);try{h(d,p,u)}finally{m&&f.layers.enable(Z)}},Gi.set(n,{colors:r,roots:0}),Yr(n),n}const ro=new WeakMap;function Rf(o,e,t,i,s){const r=ro.get(e)?.pop();return r?(r.mainScene=t,r.mainCamera=i,i.layers.disable(Yn),Gi.set(r,{colors:s,roots:0}),Yr(r),r):kf(o,t,i,s)}function If(o,e,t){e.selection.clear(),t?.setEffects([]);const i=ro.get(o)??[];i.includes(e)||i.push(e),ro.set(o,i)}const Lf=`uniform lowp sampler2D inputBuffer;uniform vec2 texelSize;uniform float vgaiReach;
|
|
1041
|
+
varying vec2 vUv0;varying vec2 vUv1;varying vec2 vUv2;varying vec2 vUv3;
|
|
1042
|
+
void main(){
|
|
1043
|
+
vec2 uv=(vUv0+vUv1)*0.5;
|
|
1044
|
+
vec2 c=texture2D(inputBuffer,uv).rg;
|
|
1045
|
+
float edge=0.0;float visibility=1.0;
|
|
1046
|
+
for(int i=1;i<=2;i++){
|
|
1047
|
+
if(float(i)>vgaiReach||edge>0.0)break;
|
|
1048
|
+
vec2 o=texelSize*float(i);
|
|
1049
|
+
vec2 s0=texture2D(inputBuffer,uv+vec2(o.x,0.0)).rg;vec2 s1=texture2D(inputBuffer,uv-vec2(o.x,0.0)).rg;
|
|
1050
|
+
vec2 s2=texture2D(inputBuffer,uv+vec2(0.0,o.y)).rg;vec2 s3=texture2D(inputBuffer,uv-vec2(0.0,o.y)).rg;
|
|
1051
|
+
if(abs(s0.x-c.x)>0.5||abs(s1.x-c.x)>0.5||abs(s2.x-c.x)>0.5||abs(s3.x-c.x)>0.5)edge=1.0;
|
|
1052
|
+
visibility=min(min(s0.y,s1.y),min(s2.y,s3.y));
|
|
1053
|
+
}
|
|
1054
|
+
gl_FragColor.rg=(1.0-visibility>0.001)?vec2(edge,0.0):vec2(0.0,edge);
|
|
1055
|
+
}`,cl=new WeakMap,Gi=new WeakMap;function Yr(o){const e=Gi.get(o);if(!e)return;const t=e.roots===1&&e.colors.active?e.colors.active:e.colors;o.visibleEdgeColor.setHex(t.visible),o.hiddenEdgeColor.setHex(t.hidden);const i=e.colors.outline,s=i?.style==="crisp",r=i?.width??2;o.resolution.scale=s?1:.5,o.blurPass.enabled=!s,o.blurPass.kernelSize=2;const n=o.outlinePass.fullscreenMaterial,a=cl.get(n)??n.fragmentShader;cl.set(n,a);const l=s?Lf:a;n.fragmentShader!==l&&(n.fragmentShader=l,n.needsUpdate=!0),n.uniforms.vgaiReach={value:Math.max(1,Math.round(r/2))},o.edgeStrength=s?8:5;const c=o.uniforms.get("vgaiCrisp");c&&(c.value=s?1:0),o.xRay=i?.hidden??!0}function Ff(o,e){Gi.set(o,{colors:e,roots:Gi.get(o)?.roots??0}),Yr(o)}function Bf(o){return o.isBone?!1:o.isMesh||o.isLine||o.isPoints||o.isSprite}function gc(o){const e=[],t=new Set;for(const i of o)i.isBone||i.traverse(s=>{t.has(s)||gt(s)||!Bf(s)||(t.add(s),e.push(s))});return e}function hl(o,e){const t=[...e],i=t.filter(n=>!n.isBone).length,s=Gi.get(o);s&&s.roots!==i&&(s.roots=i,Yr(o));const r=gc(t);o.selection.size===r.length&&r.every(n=>o.selection.has(n))||o.selection.set(r)}function dl(o,e){const t=new V(o);if(!e||e.toneMapping===Ud)return t;const i=e.toneMappingExposure||1;if(e.toneMapping===jd)return t.multiplyScalar(1/i);if(e.toneMapping===Gd)return Nf(t,i);if(e.toneMapping===Wd)return Hf(t,i);if(e.toneMapping!==tc)return t;const s=[[.59719,.35458,.04823],[.076,.90834,.01566],[.0284,.13383,.83777]],r=[[1.60475,-.53108,-.07367],[-.10208,1.10813,-.00605],[-.00327,-.07276,1.07602]],n=d=>(d*(d+.0245786)-90537e-9)/(d*(.983729*d+.432951)+.238081),a=d=>{let p=0,u=64;for(let f=0;f<60;f++){const m=(p+u)/2;n(m)<d?p=m:u=m}return(p+u)/2},c=Ri(Wr(r),[t.r,t.g,t.b]).map(d=>d<=0?0:a(Math.min(d,.999))),h=Ri(Wr(s),c).map(d=>Math.max(0,d)*(.6/i));return new V().setRGB(h[0],h[1],h[2],vo)}function Nf(o,e){const t=[[.6274,.3293,.0433],[.0691,.9195,.0113],[.0164,.088,.8956]],i=[[1.6605,-.5876,-.0728],[-.1246,1.1329,-.0083],[-.0182,-.1006,1.1187]],s=[[.856627153315983,.0951212405381588,.0482516061458583],[.137318972929847,.761241990602591,.101439036467562],[.11189821299995,.0767994186031903,.811302368396859]],r=[[1.1271005818144368,-.11060664309660323,-.016493938717834573],[-.1413297634984383,1.157823702216272,-.016493938717834257],[-.14132976349843826,-.11060664309660294,1.2519364065950405]],n=-12.47393,a=4.026069,l=f=>{const m=f*f,y=m*m;return 15.5*y*m-40.14*y*f+31.96*y-6.868*m*f+.4298*m+.1191*f-.00232},c=f=>{let m=0,y=1;for(let _=0;_<60;_++){const x=(m+y)/2;l(x)<f?m=x:y=x}return(m+y)/2},h=Ri(t,[o.r,o.g,o.b]),p=Ri(Wr(r),h.map(f=>Math.max(0,f)**(1/2.2))).map(f=>2**(c(f)*(a-n)+n)),u=Ri(i,Ri(Wr(s),p)).map(f=>Math.max(0,f)/e);return new V().setRGB(u[0],u[1],u[2],vo)}function Ri(o,e){return[o[0][0]*e[0]+o[0][1]*e[1]+o[0][2]*e[2],o[1][0]*e[0]+o[1][1]*e[1]+o[1][2]*e[2],o[2][0]*e[0]+o[2][1]*e[1]+o[2][2]*e[2]]}function Wr(o){const[[e,t,i],[s,r,n],[a,l,c]]=o,h=r*c-n*l,d=-(s*c-n*a),p=s*l-r*a,u=e*h+t*d+i*p;return[[h/u,-(t*c-i*l)/u,(t*n-i*r)/u],[d/u,(e*c-i*a)/u,-(e*n-i*s)/u],[p/u,-(e*l-t*a)/u,(e*r-t*s)/u]]}function Hf(o,e){const t=n=>(n*(.88*n+.06)+.002)/(n*(.88*n+.6)+.06)-.03333333333333333,i=t(1),s=n=>t(n)/i,r=n=>{if(n<=0)return 0;let a=0,l=1;for(let c=0;c<60;c++){const h=(a+l)/2;s(h)<n?a=h:l=h}return(a+l)/2};return new V().setRGB(r(Math.min(o.r,.999))/e,r(Math.min(o.g,.999))/e,r(Math.min(o.b,.999))/e,vo)}const Df=new V(5231045),Vf=new V(10481896),ul=64,Uf=.6;class jf extends Ve{constructor(e){super(),this.source=e,this.name="Trigger Volume Helper",this.matrixAutoUpdate=!1,this.renderOrder=998,qe(this,"editorHelper",!0),qe(this,"editorHelperType","trigger-volumes"),this.layers.set(Z),this.refresh(!0)}signature="";selected=!1;setSelected(e){this.selected!==e&&(this.selected=e,this.refresh(!0))}update(){this.refresh(!1),this.source.updateWorldMatrix(!0,!1),this.matrix.copy(this.source.matrixWorld),this.matrixWorldNeedsUpdate=!0}dispose(){this.clearVisuals(),this.removeFromParent()}refresh(e){const t=eo(this.source);if(!t)return;const i=t.radius,s=String(i);if(!e&&s===this.signature)return;this.signature=s,this.clearVisuals();const r=this.selected?Vf:Df,n=this.selected?1:.62,a=[];for(let u=0;u<ul;u+=1){const f=u/ul*Math.PI*2;a.push(Math.cos(f)*i,0,Math.sin(f)*i)}const l=new Et;l.setAttribute("position",new ps(a,3));const c=new Ql(l,this.lineMaterial(r,n));c.renderOrder=this.renderOrder,this.add(c);const h=[];for(const[u,f]of[[i,0],[-i,0],[0,i],[0,-i]])h.push(u,0,f,u,Uf,f);const d=new Et;d.setAttribute("position",new ps(h,3));const p=new Li(d,this.lineMaterial(r,n));p.renderOrder=this.renderOrder,this.add(p),this.traverse(u=>u.layers.set(Z))}lineMaterial(e,t){return new qt({color:e,depthTest:!1,transparent:!0,opacity:t,toneMapped:!1})}clearVisuals(){for(const e of[...this.children]){e.removeFromParent();const t=e;t.geometry?.dispose();const i=Array.isArray(t.material)?t.material:[t.material];for(const s of i)s?.dispose()}}}function Gf(o){const e=new Set(o.values()),t=[];for(const i of e){let s=i.parent,r=!1;for(;s!==null;){if(e.has(s)){r=!0;break}s=s.parent}r||t.push(i)}return t}function Wf(o,e){const t=new Set;for(const i of e){const s=o.get(i);s&&t.add(s)}return[...t].filter(i=>{for(let s=i.parent;s!==null;s=s.parent)if(t.has(s))return!1;return!0})}const Er=.5,Xf=1e3,qf=new v(0,1,0),Jf=new v(0,0,1),Hn=new go,Yf=new v,pl=new v,Dn=new pe,fl=new v,Zf=1e-8,Qf=[new v(1,0,0),new v(-1,0,0),new v(0,1,0),new v(0,-1,0),new v(0,0,1),new v(0,0,-1)],Vn=[[.96,.2,.32],[.53,.84,.01],[.16,.55,.96]],ml=[[0,1],[1,1],[2,1]],$f=[[0,1],[2,1],[1,-1]],Kf=[[0,1],[2,1],[1,1]],gl=["X","Y","Z"],no={degrees:50,axis:"vertical"};function Un(o,e=no){const t=Number.isFinite(o)&&o>.01?o:1,i=Number.isFinite(e.degrees)&&e.degrees>0&&e.degrees<180?e.degrees:no.degrees,s=Le.degToRad(i/2),n=e.axis==="horizontal"||e.axis==="larger"&&t>=1||e.axis==="smaller"&&t<1?Math.atan(Math.tan(s)/t):s;return Le.radToDeg(n*2)}function em(o){const e=Math.max(o.r,o.g,o.b),t=Math.min(o.r,o.g,o.b),i=e-t;let s=0;return i>0&&(e===o.r?s=((o.g-o.b)/i+6)%6:e===o.g?s=(o.b-o.r)/i+2:s=(o.r-o.g)/i+4,s/=6),{h:s,s:e===0?0:i/e,v:e}}function tm(o,e,t,i){const s=Math.floor(o*6),r=o*6-s,n=t*(1-e),a=t*(1-r*e),l=t*(1-(1-r)*e),[c,h,d]=[[t,l,n],[a,t,n],[n,t,l],[n,a,t],[l,n,t],[t,n,a]][(s%6+6)%6];return i.setRGB(c,h,d)}const im=.356,sm=7.5/17.5;function rm(o,e){const i=document.createElement("canvas");i.width=32,i.height=32;const s=i.getContext("2d");s&&(s.fillStyle=`#${o.getHexString()}`,s.font=`bold ${Math.round(32*.8)}px system-ui, -apple-system, sans-serif`,s.textAlign="center",s.textBaseline="middle",s.fillText(e,32/2,32/2+1));const r=new qr(i);return r.generateMipmaps=!1,r.minFilter=Ir,r.colorSpace=rt,r}function Po(o){const t=document.createElement("canvas");t.width=32,t.height=32;const i=t.getContext("2d");i&&o(i,32,32/2-1);const s=new qr(t);return s.colorSpace=rt,s.generateMipmaps=!1,s.minFilter=Ir,s}function nm(){return Po((o,e,t)=>{o.beginPath(),o.arc(e/2,e/2,t,0,Math.PI*2),o.fillStyle="#ffffff",o.fill()})}function om(){return Po((o,e,t)=>{const i=ao/oo*e;o.beginPath(),o.arc(e/2,e/2,t-i/2,0,Math.PI*2),o.lineWidth=i,o.strokeStyle="#ffffff",o.stroke()})}function am(o){return Po((e,t,i)=>{const s=sm*(2*i),r=Math.round(s/.72);e.font=`bold ${r}px system-ui, -apple-system, sans-serif`,e.fillStyle="#ffffff",e.textAlign="center",e.textBaseline="middle",e.fillText(o,t/2,t/2+2,2*i*.86)})}const lm=new v(1,.72,1).normalize(),_t=90,cm=32,oo=15,hm=2.75,ao=2,dm=74.5,Ao=73.5,yc=8.5+dm/2-_t/2,Eo=38+Ao/2-_t/2,um=yc+_t/2,pm=Eo+_t/2+Ao/2,fm=Eo+_t/2+Ao/2+16-14.5,_c=`
|
|
1056
|
+
float vgaiGrazingFade(vec3 worldPosition, vec3 eye, vec3 planeNormal, float amount) {
|
|
1057
|
+
vec3 toEye = eye - worldPosition;
|
|
1058
|
+
float toEyeLength = max(length(toEye), 1e-6);
|
|
1059
|
+
float graze = 1.0 - abs(dot(toEye / toEyeLength, planeNormal));
|
|
1060
|
+
graze *= graze;
|
|
1061
|
+
return mix(1.0, 1.0 - graze * graze, amount);
|
|
1062
|
+
}
|
|
1063
|
+
`,zo=200,lo=2,co=zo*2/lo;function yl(o){const e=[];for(let t=0;t<co;t++){const i=-zo+t*lo,s=i+lo;o===0?e.push(i,.001,0,s,.001,0):o===2?e.push(0,.001,i,0,.001,s):e.push(0,i,0,0,s,0)}return e}function mm(o,e,t){o.onBeforeCompile=i=>{i.uniforms.uGrazingFade=e,i.uniforms.uPlaneNormal=t,i.vertexShader=i.vertexShader.replace("void main() {",`varying vec3 vAxisWorld;
|
|
1064
|
+
void main() {`).replace("vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );",`vAxisWorld = ( modelMatrix * vec4( position.y < 0.5 ? instanceStart : instanceEnd, 1.0 ) ).xyz;
|
|
1065
|
+
vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );`),i.fragmentShader=i.fragmentShader.replace("void main() {",`varying vec3 vAxisWorld;
|
|
1066
|
+
uniform float uGrazingFade;
|
|
1067
|
+
uniform vec3 uPlaneNormal;
|
|
1068
|
+
${_c}
|
|
1069
|
+
void main() {`).replace("gl_FragColor = vec4( diffuseColor.rgb, alpha );","gl_FragColor = vec4( diffuseColor.rgb, alpha * vgaiGrazingFade( vAxisWorld, cameraPosition, uPlaneNormal, uGrazingFade ) );")},o.customProgramCacheKey=()=>"vgai-axis-grazing-fade"}const as=new v,gm=new pe,Pi=new v,ym=new v(0,1,0);function _m(o){const e=new fo(o,o);e.rotateX(-Math.PI/2);const t=new fs({uniforms:{uColor:{value:new V(10066329)},uMajorColor:{value:new V(10066329)},uOpacity:{value:1},uLineWidth:{value:1},uMajorWidth:{value:1},uAligned:{value:0},uMajorEvery:{value:10},uFadeStart:{value:o/2*.55},uFadeEnd:{value:o/2},uGrazingFade:{value:0},uPlaneNormal:{value:new v(0,1,0)},uUnit:{value:1},uMinorFade:{value:1},uCenter:{value:new je},uReach:{value:1}},vertexShader:`
|
|
1070
|
+
varying vec3 vWorld;
|
|
1071
|
+
void main() {
|
|
1072
|
+
vWorld = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
1073
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
1074
|
+
}
|
|
1075
|
+
`,fragmentShader:`
|
|
1076
|
+
uniform vec3 uColor;
|
|
1077
|
+
uniform vec3 uMajorColor;
|
|
1078
|
+
uniform float uOpacity;
|
|
1079
|
+
uniform float uLineWidth;
|
|
1080
|
+
uniform float uMajorWidth;
|
|
1081
|
+
uniform float uAligned;
|
|
1082
|
+
uniform float uMajorEvery;
|
|
1083
|
+
uniform float uFadeStart;
|
|
1084
|
+
uniform float uFadeEnd;
|
|
1085
|
+
uniform float uGrazingFade;
|
|
1086
|
+
uniform vec3 uPlaneNormal;
|
|
1087
|
+
uniform float uUnit;
|
|
1088
|
+
uniform float uMinorFade;
|
|
1089
|
+
uniform vec2 uCenter;
|
|
1090
|
+
uniform float uReach;
|
|
1091
|
+
varying vec3 vWorld;
|
|
1092
|
+
${_c}
|
|
1093
|
+
// Coverage of a line WIDTH device pixels across, with a one-pixel
|
|
1094
|
+
// anti-aliased edge — so its core is FULL, the way Blender's is. The
|
|
1095
|
+
// earlier form (1 - distance/width) was a triangle with no plateau:
|
|
1096
|
+
// whether a line reached its own colour depended on where the nearest
|
|
1097
|
+
// fragment centre happened to fall, and the measured peak wandered
|
|
1098
|
+
// between 0.67 and 1 of it.
|
|
1099
|
+
float gridLine(vec2 coord, float width) {
|
|
1100
|
+
vec2 d = max(fwidth(coord), vec2(1e-6));
|
|
1101
|
+
vec2 dist = abs(fract(coord - 0.5) - 0.5) / d;
|
|
1102
|
+
vec2 cov = clamp(width * 0.5 - dist + 0.5, 0.0, 1.0);
|
|
1103
|
+
return max(cov.x, cov.y);
|
|
1104
|
+
}
|
|
1105
|
+
// One device pixel, the one nearest the line, and no anti-aliasing: Blender's lines in an
|
|
1106
|
+
// axis-aligned view (\`GRID_ALIGNED\`, which outputs no line-smoothing data for them).
|
|
1107
|
+
float alignedLine(vec2 coord) {
|
|
1108
|
+
vec2 dist = abs(fract(coord - 0.5) - 0.5) / max(fwidth(coord), vec2(1e-6));
|
|
1109
|
+
return max(step(dist.x, 0.5), step(dist.y, 0.5));
|
|
1110
|
+
}
|
|
1111
|
+
void main() {
|
|
1112
|
+
vec2 world = abs(uPlaneNormal.y) > 0.5 ? vWorld.xz : abs(uPlaneNormal.z) > 0.5 ? vWorld.xy : vWorld.zy;
|
|
1113
|
+
vec2 p = world / uUnit;
|
|
1114
|
+
if (uAligned > 0.5) {
|
|
1115
|
+
// BLENDER'S THREE LEVELS in an axis-aligned orthographic view
|
|
1116
|
+
// (\`overlay_grid_vert.glsl\`, \`OVERLAY_GRID_STEPS_DRAW\` 3): the unit, the next step and
|
|
1117
|
+
// the one after, with f the level's fraction (\`uMinorFade\` is 1 - f). Level 0 is the
|
|
1118
|
+
// grid colour at alpha 1 - f, further faded as its cells shrink toward a pixel
|
|
1119
|
+
// (\`smoothstep(step / 4, step / 64, pixel size)\`, written in increasing order); level 1 is opaque and 1 - f of the
|
|
1120
|
+
// way to the emphasis colour; level 2 is the emphasis colour. A line on a higher level
|
|
1121
|
+
// is that level's.
|
|
1122
|
+
float top = alignedLine(p / (uMajorEvery * uMajorEvery));
|
|
1123
|
+
float middle = alignedLine(p / uMajorEvery);
|
|
1124
|
+
float bottom = alignedLine(p);
|
|
1125
|
+
float pixel = max(fwidth(world).x, fwidth(world).y);
|
|
1126
|
+
float bottomAlpha = uMinorFade * (1.0 - smoothstep(uUnit * 0.015625, uUnit * 0.25, pixel));
|
|
1127
|
+
float emphasis = top > 0.5 ? 1.0 : middle > 0.5 ? uMinorFade : 0.0;
|
|
1128
|
+
// The theme's grid colour carries alpha 0x80 and its emphasis colour none, and the
|
|
1129
|
+
// two colours here were fitted to Blender's PERSPECTIVE frames, where four additive
|
|
1130
|
+
// passes (1 + 1/2 + 1/4 + 1/8) take that alpha to about 0.94. Drawn once, as an
|
|
1131
|
+
// aligned view draws it, the grid colour keeps 0.502 / 0.941 of that. (Measured: the
|
|
1132
|
+
// 10 cm lines +5 over the ground at 198 px per metre, predicted +5.4; the 1 m lines
|
|
1133
|
+
// 89 against 88. The 0.94 is inferred from the passes, not read off a frame.)
|
|
1134
|
+
float levelAlpha = (top > 0.5 || middle > 0.5 ? 1.0 : bottom * bottomAlpha) * mix(0.533, 1.0, emphasis);
|
|
1135
|
+
float edge = 1.0 - smoothstep(uFadeStart * uReach, uFadeEnd * uReach, length(world - uCenter));
|
|
1136
|
+
float alignedAlpha = levelAlpha * edge * uOpacity;
|
|
1137
|
+
if (alignedAlpha <= 0.002) discard;
|
|
1138
|
+
gl_FragColor = vec4(mix(uColor, uMajorColor, emphasis), alignedAlpha);
|
|
1139
|
+
#include <colorspace_fragment>
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
vec2 pixelsPerMetre = 1.0 / max(fwidth(p), vec2(1e-6));
|
|
1143
|
+
float minorVisible = smoothstep(4.0, 14.0, min(pixelsPerMetre.x, pixelsPerMetre.y)) * uMinorFade;
|
|
1144
|
+
// Both levels reach FULL strength in their own colour, as Blender's
|
|
1145
|
+
// do: the 1 m line is measured at exactly the palette's grid colour
|
|
1146
|
+
// and the 10 m line brighter than it (see uMajorColor). The minor
|
|
1147
|
+
// level's only attenuation is its own drop-out as cells shrink.
|
|
1148
|
+
float minor = gridLine(p, uLineWidth) * minorVisible;
|
|
1149
|
+
// The 10 m level is WIDER as well as brighter, which is what lets it
|
|
1150
|
+
// reach full coverage — and so its full colour. Measured across one
|
|
1151
|
+
// scanline of modeling-object-none.png at device resolution: the 1 m
|
|
1152
|
+
// line is 4 px at half rise and plateaus at 83, the 10 m line is 6 px
|
|
1153
|
+
// and plateaus at 101. At one shared width ours drew a 10 m line that
|
|
1154
|
+
// never exceeded 0.75 coverage and so measured 91, not 102.
|
|
1155
|
+
float major = gridLine(p / uMajorEvery, uMajorWidth);
|
|
1156
|
+
float line = max(minor, major);
|
|
1157
|
+
float fade = 1.0 - smoothstep(uFadeStart * uReach, uFadeEnd * uReach, length(world - uCenter));
|
|
1158
|
+
// The floor's DEPTH, beside the band that ends its finite extent:
|
|
1159
|
+
// Blender's own grazing-angle profile, transcribed from its frames
|
|
1160
|
+
// (see GRAZING_FADE_GLSL above). Without it this lattice reads the
|
|
1161
|
+
// same ink at the front of the frame and at the horizon.
|
|
1162
|
+
fade *= vgaiGrazingFade(vWorld, cameraPosition, uPlaneNormal, uGrazingFade);
|
|
1163
|
+
float alpha = line * fade * uOpacity;
|
|
1164
|
+
if (alpha <= 0.002) discard;
|
|
1165
|
+
// WHICH level a fragment belongs to is the major's SHARE of the
|
|
1166
|
+
// coverage being drawn, never a comparison of the two and never the
|
|
1167
|
+
// major's raw coverage. Every 10 m line is also a 1 m line, so there
|
|
1168
|
+
// the two are equal: a step() between them compares values equal to
|
|
1169
|
+
// within rounding and flips per fragment (photographed with the major
|
|
1170
|
+
// forced white: the 10 m lines came out DOTTED), and mixing by the raw
|
|
1171
|
+
// coverage dilutes the colour by the line's own anti-aliasing (the
|
|
1172
|
+
// same lines then measured 91 where Blender's is 102). As a share it
|
|
1173
|
+
// is exactly 1 wherever the major draws — core and skirt alike, and in
|
|
1174
|
+
// the far field where the minor has dropped out — and 0 on a 1 m line.
|
|
1175
|
+
float majorShare = clamp(major / max(line, 1e-6), 0.0, 1.0);
|
|
1176
|
+
gl_FragColor = vec4(mix(uColor, uMajorColor, majorShare), alpha);
|
|
1177
|
+
#include <colorspace_fragment>
|
|
1178
|
+
}
|
|
1179
|
+
`,transparent:!0,depthWrite:!1,side:di}),i=new T(e,t);return i.name="editor-floor-grid",i}class Oo{setTransformMode(e){this._store.shell.setTransformMode(e)}camera;orthographicCamera;orbitControls;transformControls;_auxRotateControls;_auxScaleControls;_activeGizmo;raycaster=(()=>{const e=new nt;return e.layers.enableAll(),e})();grid;_boxHelpers=new Map;_selectionMarks={outline:!0,wire:!1,box:!1};_unsubscribeSelectionTheme=()=>{};_constraintHelpers=new Map;_constraintControlRaycaster=(()=>{const e=new nt;return e.layers.enableAll(),e})();_hoveredConstraintControl=null;_constraintControlPointerSession=!1;_reflectionProbeHelpers=new Map;_triggerVolumeHelpers=new Map;_cameraHelpers=new Map;_lightHelpers=new Map;_audioHelpers=new Map;_spatialHandleRoots=[];_spatialHandleMeshes=[];_spatialHandleRaycaster=(()=>{const e=new nt;return e.layers.enableAll(),e})();_activeSpatialHandle=null;_hoveredSpatialHandle=null;_spatialHandleDragPlane=new Oa;_spatialHandleDragOffset=new v;_spatialHandleDragPoint=new v;_orbitEnabledBeforeHandleDrag=!0;_transformEnabledBeforeHandleDrag=!0;_gizmoHelper;_editorAmbient;_editorDirLight;_lightRig;_scene;_contentBoundsBox=new wt;_contentBoundsAt=0;_renderer;_sparkRenderer=null;_sparkRendererLoading=!1;_sparkRendererFailed=!1;_lastSparkDiscoveryAt=Number.NEGATIVE_INFINITY;_disposed=!1;_editorObjects=[];_presentation=null;_axisLines=null;_verticalAxisLine=null;_axisLineWidth=null;_axisLineCss(e){return e===null?2:e/(this._renderer?.getPixelRatio()??1)}_axesWanted=!1;_stageAxes="floor";_lookAxisHexes=[null,null,null];_lookGridHex=null;_lookBackgroundHex=null;_lookToneMapping=null;_lookExposure=null;_lookGizmoSizePx=null;_stageAxisFrame=ml;_appliedAxisSigns=[1,1,1];_gizmoLook={axes:null,navigation:null,hover:null,drag:null,opacity:null,arrowLength:null,arrowHead:null,ringWidth:null,navigationSize:null,navigationForm:"balls",background:null,navigationCorner:"top-right",highlightSaturation:null,highlightValue:null};_stageBoxSelect=null;_transformHandles={scale:!0,viewRotate:!0,freeMove:!0};_appliedArrow={length:1.2,head:1};_appliedRingWidth=1;_store;_objectMap=new Map;_canvas;_interactionElement;_onInteractionPointerUp;_onInteractionDblClick;_authoring;_pick;_drawCamera;get _screenCamera(){return this._drawCamera?.()??this.renderCamera}_standaloneAuthoring;_publishPickContext;_onlineAssetResolver;_onProjectionChange;_pointerDownPos=new je;_skipNextSync=!1;_marqueeActive=!1;_pointerSessionActive=!1;_marqueeDiv=null;_pointerDownButton=-1;_altDragOrbit=!1;_vcScene=new Jr;_vcCamera;_vcClickTargets=[];_vcBalls=[];_vcStalks=[];_vcSolids=[];_vcSize=_t;_navigation="interactive";_marksLook="";_presentationGrid=!0;_vcMarginRight=yc;_vcMarginTop=Eo;_chromeInsetPx=0;_vcDir=new v;_previewClearColor=new V;_cameraView=null;_projection="perspective";_pendingProjection=null;_viewportAspect=1;_fieldOfView=no;_orthographicHeight=10;_cameraViewMode=null;_orbitEnabledBeforeCameraView=!0;_orbitTargetBeforeCameraView=new v;_lastGizmoObjectMap=null;_lastGizmoSig="";_lastGizmoEpoch=-1;_threejsToolContextActive=!1;_threeSurfaceShowing=!1;_vcRaycaster=new nt;_dropOverlay=null;_groundPlane=new Oa(new v(0,1,0),0);_dragStartPos=new v;_dragStartQuat=new pe;_dragStartScale=new v;_attachedAuthoringId=null;_otherDragObjects=[];_allDragObjects=[];_preservedChildObjects=[];_activeTransformEditIds=[];_pivotDummy=new ui;_dummyIsPresentationAnchor=!1;_pivotPos=new v;_surfaceSnapRaycaster=new nt;_surfaceSnapIndicator;_vertexSnapTargets=[];_vertexSnapIndicator;_vertexSnapThreshold=20;batchedRenderer;_helpers=new Map;_snapAnimating=!1;_snapStartTime=0;_snapDuration=400;_snapQ1=new pe;_snapQ2=new pe;_snapDist=0;_flyActive=!1;_snapHold=!1;_flyKeys=new Set;_flySpeed=5;_flyEuler=new Zl(0,0,0,"YXZ");_rightMouseDown=!1;constructor(e,t,i,s=e,r={}){Wh(),this._canvas=e,this._interactionElement=s,this._scene=t,this._renderer=r.renderer,this._store=i,this._authoring=r.authoring??(()=>yr().activeAuthoring(this._store.shell)),this._pick=r.pick,this._drawCamera=r.drawCamera,this._standaloneAuthoring=r.authoring!==void 0,this._publishPickContext=r.publishPickContext??!0,this._chromeInsetPx=r.chromeInsetPx??0,this._onlineAssetResolver=r.onlineAssetResolver,this._onProjectionChange=r.onProjectionChange,this.camera=new yo(Un(e.clientWidth/Math.max(1,e.clientHeight)),e.clientWidth/e.clientHeight,Ba,Na),this.camera.position.copy(lm).multiplyScalar(17.32),this.camera.lookAt(0,0,0),this.camera.layers.enableAll(),this._viewportAspect=e.clientWidth/Math.max(1,e.clientHeight),this.orthographicCamera=new Fi(-5,5,5,-5,Ba,Na),this.orthographicCamera.layers.enableAll(),this._syncOrthographicFromPerspective(),this.grid=_m(400),this.grid.layers.set(Z),t.add(this.grid);const n=new Fr;n.setPositions(yl(0)),n.setColors(new Array(co*2*3).fill(1)),this._axisLines=new Lr(n,new Br({vertexColors:!0,linewidth:2,transparent:!0,opacity:1,depthWrite:!1,toneMapped:!1})),mm(this._axisLines.material,this.grid.material.uniforms.uGrazingFade,this.grid.material.uniforms.uPlaneNormal),this._axisLines.visible=!1,this._axisLines.layers.set(Z),t.add(this._axisLines),this._unsubscribeSelectionTheme=Xr(e,()=>{K();const l=JSON.stringify([Qe(e),aa(e),la(e)]);l!==this._marksLook&&(this._marksLook=l,this._boxHelpers.size>0&&this._syncBoxHelpers()),this._gizmoLook=ca(e),this._applyViewportLook(qn(e)),this._applyGridLines($c(e)),this._lookGizmoSizePx=ha(e),this._applyGizmoSize(),this._applyGizmoArrows(),this._readLookStage(e)}),this._lightRig=r?.lightRig!==!1,this._editorAmbient=new Kl(16777215,.5),this._editorAmbient.layers.set(Z),t.add(this._editorAmbient),this._editorDirLight=new $l(16777215,1),this._editorDirLight.position.set(10,20,10),this._editorDirLight.layers.set(Z),t.add(this._editorDirLight),this._editorAmbient.visible=this._lightRig,this._editorDirLight.visible=this._lightRig,this.batchedRenderer=new So,this.batchedRenderer.layers.set(Z),t.add(this.batchedRenderer),s.addEventListener("wheel",this._onTrackpadWheel,{passive:!1}),this.orbitControls=new du(this.camera,s),this.orbitControls.enableDamping=!0,this.orbitControls.dampingFactor=.1,this.applyKeymapNavigation(),this._unsubscribeKeymap=Kc(()=>this.applyKeymapNavigation()),this._installTurntable(),this.transformControls=new bn(this.camera,e),this._auxScaleControls=new bn(this.camera,e),this._auxScaleControls.setMode("scale"),this._auxRotateControls=new bn(this.camera,e),this._auxRotateControls.setMode("rotate"),this._activeGizmo=this.transformControls;const a=l=>{const c=l.pointerDown.bind(l);l.pointerDown=h=>{l.getHelper().updateMatrixWorld(!0),c(h)},l.getRaycaster().layers.enableAll(),l.addEventListener("dragging-changed",h=>{const d=h.value;if(d?yu():_u(),this.orbitControls.enabled=!d,d){this._activeGizmo=l;for(const y of this._allGizmos())y!==l&&(y.enabled=!1);const p=l.object,u=l.mode==="translate"?"position":l.mode==="rotate"?"rotation":"scale",f=y=>this._authoring().transforms?.editability?.(y,u).writable??!0,m=this._attachedAuthoringId??(p&&this._authoringIdForObject(p))??"";if(p){if(this._dragStartPos.copy(p.position),this._dragStartQuat.copy(p.quaternion),this._dragStartScale.copy(p.scale),this._otherDragObjects=[],this._allDragObjects=[],this._pivotPos.copy(p.position),p===this._pivotDummy?null:this._authoringIdForObject(p))for(const S of this._store.shell.selectedEntityIds){if(S===m||!f(S))continue;const w=this._objectForAuthoringId(S);w&&this._otherDragObjects.push({id:S,obj:w,startPos:w.position.clone(),startQuat:w.quaternion.clone(),startScale:w.scale.clone()})}else for(const S of this._store.shell.selectedEntityIds){if(!f(S))continue;const w=this._objectForAuthoringId(S);w&&this._allDragObjects.push({id:S,obj:w,startPos:w.position.clone(),startQuat:w.quaternion.clone(),startScale:w.scale.clone()})}const _=p===this._pivotDummy?this._allDragObjects.map(({id:S})=>S):[m,...this._otherDragObjects.map(({id:S})=>S)];this._preservedChildObjects=this._preparePreservedChildren(_.filter(Boolean)),this._activeTransformEditIds=[...new Set([..._.filter(Boolean),...this._preservedChildObjects.map(({id:S})=>S)])];const x=this._authoring();for(const S of this._activeTransformEditIds)da(x,S)}}else this._surfaceSnapIndicator.visible=!1,this._vertexSnapIndicator.visible=!1,this.syncFromStore()}),l.addEventListener("objectChange",()=>{const h=l.object;if(!h)return;const d=l.mode,p=this._store.shell.pivotMode==="individual-origins"||this._dummyIsPresentationAnchor,f=this._allDragObjects.length>0?this._allDragObjects:this._otherDragObjects;if(f.length>0){if(d==="translate"){const m=h.position.clone().sub(this._dragStartPos);for(const{obj:y,startPos:_}of f)y.position.copy(_).add(m)}else if(d==="rotate"){const m=h.quaternion.clone().multiply(this._dragStartQuat.clone().invert());if(p)for(const{obj:y,startQuat:_}of f)y.quaternion.copy(m).multiply(_);else for(const{obj:y,startPos:_,startQuat:x}of f){const S=_.clone().sub(this._pivotPos);S.applyQuaternion(m),y.position.copy(this._pivotPos).add(S),y.quaternion.copy(m).multiply(x)}}else if(d==="scale"){const m=new v(this._dragStartScale.x!==0?h.scale.x/this._dragStartScale.x:1,this._dragStartScale.y!==0?h.scale.y/this._dragStartScale.y:1,this._dragStartScale.z!==0?h.scale.z/this._dragStartScale.z:1);if(p)for(const{obj:y,startScale:_}of f)y.scale.copy(_).multiply(m);else for(const{obj:y,startPos:_,startScale:x}of f){const S=_.clone().sub(this._pivotPos);S.multiply(m),y.position.copy(this._pivotPos).add(S),y.scale.copy(x).multiply(m)}}}d==="translate"&&this._store.vertexSnapActive&&this._vertexSnapTargets.length>0?this._applyVertexSnap(h,f):d==="translate"&&this._store.shell.snapToSurface&&this._applySurfaceSnap(h,f),this._restorePreservedChildren();for(const m of this._boxHelpers.values())"update"in m&&m.update();this._flushGizmoToStoreLive()}),l.addEventListener("mouseUp",()=>{this._flushGizmoToStore()})};a(this.transformControls),a(this._auxRotateControls),a(this._auxScaleControls),this._gizmoHelper=this.transformControls.getHelper(),this._gizmoHelper.traverse(l=>l.layers.set(Z)),t.add(this._gizmoHelper);for(const l of[this._auxRotateControls,this._auxScaleControls]){const c=l.getHelper();c.traverse(h=>h.layers.set(Z)),c.visible=!1,t.add(c)}this._pivotDummy.layers.set(Z),t.add(this._pivotDummy),this._surfaceSnapIndicator=new T(new Xd(.08,.12,16),new Ce({color:65416,side:di,depthTest:!1})),this._surfaceSnapIndicator.rotation.x=-Math.PI/2,this._surfaceSnapIndicator.visible=!1,this._surfaceSnapIndicator.renderOrder=999,this._surfaceSnapIndicator.layers.set(Z),t.add(this._surfaceSnapIndicator),this._vertexSnapIndicator=new T(new At(1,8,8),new Ce({color:65450,depthTest:!1})),this._vertexSnapIndicator.visible=!1,this._vertexSnapIndicator.renderOrder=999,this._vertexSnapIndicator.layers.set(Z),t.add(this._vertexSnapIndicator),this._gizmoLook=ca(e),this._rebuildAxisLines();for(const l of this._allGizmos())this._installGizmoHighlight(l);this._patchGizmo(this._gizmoHelper),this._patchGizmo(this._auxRotateControls.getHelper()),this._patchGizmo(this._auxScaleControls.getHelper()),this._dropNegativeAxisHandles(this._gizmoHelper,["translate","scale"]),this._dropNegativeAxisHandles(this._auxScaleControls.getHelper(),["scale"]),this._patchCombinedScaleGizmo(this._auxScaleControls.getHelper()),this._applyGizmoArrows(),this._lookGizmoSizePx=ha(e),this._applyGizmoSize(),this._applyGizmoAxisFrame(),this._vcCamera=new Fi(-1.5,1.5,1.5,-1.5,.1,10),this._initOrientationGizmo(),window.addEventListener("keydown",this._onFlyKeyDown),window.addEventListener("keyup",this._onFlyKeyUp),s.addEventListener("pointerdown",this._onFlyPointerDown),s.addEventListener("pointerup",this._onFlyPointerUp),s.addEventListener("pointermove",this._onFlyPointerMove),s.addEventListener("wheel",this._onFlyWheel,{passive:!1}),e.addEventListener("pointerdown",this._onAltOrbitStart,{capture:!0}),window.addEventListener("pointerup",this._onAltOrbitRelease,{capture:!0}),window.addEventListener("pointercancel",this._onAltOrbitRelease,{capture:!0}),window.addEventListener("keydown",this._onSnapHoldKey),window.addEventListener("keyup",this._onSnapHoldKey),e.addEventListener("pointerdown",this._onPointerDown),s.addEventListener("pointermove",this._onPointerMove),this._onInteractionPointerUp=l=>{(l.target===e||l.target===s||this._pointerSessionActive)&&this._onPointerUp(l)},s.addEventListener("pointerup",this._onInteractionPointerUp),this._onInteractionDblClick=l=>{(l.target===e||l.target===s)&&this._onDoubleClick(l)},s.addEventListener("dblclick",this._onInteractionDblClick),e.addEventListener("dragover",this._onDragOver),e.addEventListener("dragleave",this._onDragLeave),e.addEventListener("drop",this._onDrop),this._editorObjects=[this.grid,...this._axisLines?[this._axisLines]:[],this._editorAmbient,this._editorDirLight,this.batchedRenderer,this._gizmoHelper,this._auxRotateControls.getHelper(),this._auxScaleControls.getHelper(),this._pivotDummy,this._surfaceSnapIndicator,this._vertexSnapIndicator],this._publishPickContext&&this._installPickContext(this.camera)}setScene(e){if(e===this._scene)return;for(const i of this._editorObjects)i.removeFromParent(),e.add(i);for(const i of this._boxHelpers.values())i.removeFromParent(),e.add(i);for(const i of this._constraintHelpers.values())i.removeFromParent(),e.add(i);for(const i of this._reflectionProbeHelpers.values())i.removeFromParent(),e.add(i);for(const i of this._triggerVolumeHelpers.values())i.removeFromParent(),e.add(i);for(const{helper:i}of this._cameraHelpers.values())i.removeFromParent(),e.add(i);for(const i of this._spatialHandleRoots)i.removeFromParent(),e.add(i);this._scene=e,this._contentBoundsAt=0;const t=this._lightRig&&!this._store.isAdoptedSceneActive&&this._presentation===null;this._editorAmbient.visible=t,this._editorDirLight.visible=t}get currentScene(){return this._scene}get renderCamera(){return this._cameraView??this.freeCamera}get freeCamera(){return this._projection==="orthographic"?this.orthographicCamera:this.camera}get projection(){return this._projection}_installPickContext(e){this._publishPickContext&&el({camera:e,canvas:this._canvas,editorControls:{activate:(t,i)=>this._selectConstraintControlAt({clientX:t,clientY:i},!1),hover:(t,i)=>this._hoverConstraintControlAt({clientX:t,clientY:i}),clearHover:()=>this._clearConstraintControlHover()}})}setProjection(e){if(this._cameraView){this._pendingProjection=e;return}if(this._projection===e)return;e==="orthographic"?this._syncOrthographicFromPerspective():this._syncPerspectiveFromOrthographic(),this._projection=e;const t=this.freeCamera;this.orbitControls.object=t;for(const i of this._allGizmos())i.camera=t;this._applyGizmoSize(),this.orbitControls.update(),this._installPickContext(t),this._onProjectionChange?.(e)}_syncOrthographicFromPerspective(e=!1){const t=Math.max(.01,this.camera.position.distanceTo(this.orbitControls?.target??new v));e||(this._orthographicHeight=2*t*Math.tan(Le.degToRad(this.camera.fov*.5))),this.orthographicCamera.position.copy(this.camera.position),this.orthographicCamera.quaternion.copy(this.camera.quaternion),this.orthographicCamera.up.copy(this.camera.up),this.orthographicCamera.zoom=1,this._applyOrthographicFrustum(),this.orthographicCamera.updateMatrixWorld(!0)}_syncPerspectiveFromOrthographic(){const t=this._orthographicHeight/Math.max(this.orthographicCamera.zoom,.01)/(2*Math.tan(Le.degToRad(this.camera.fov*.5))),i=this.orthographicCamera.position.clone().sub(this.orbitControls.target).normalize();this.camera.position.copy(this.orbitControls.target).add(i.multiplyScalar(t)),this.camera.quaternion.copy(this.orthographicCamera.quaternion),this.camera.up.copy(this.orthographicCamera.up),this.camera.updateMatrixWorld(!0)}_applyOrthographicFrustum(){const e=this._orthographicHeight*.5,t=e*this._viewportAspect;this.orthographicCamera.left=-t,this.orthographicCamera.right=t,this.orthographicCamera.top=e,this.orthographicCamera.bottom=-e,this.orthographicCamera.updateProjectionMatrix()}setGizmoCamera(e){const t=e??this.freeCamera;if(this.transformControls.camera!==t){for(const i of this._allGizmos())i.camera=t;this._applyGizmoSize()}}applyKeymapNavigation(){const{orbit:e,turntable:t}=Ze();!t&&this.camera.up.y<.9999&&Math.abs(this.camera.up.z)<.9999&&this.camera.up.set(0,1,0),this.orbitControls.mouseButtons={LEFT:this._altDragOrbit?Ie.ROTATE:-1,MIDDLE:e==="middle"?Ie.ROTATE:Ie.PAN,RIGHT:e==="middle"?-1:Ie.ROTATE}}_unsubscribeKeymap=()=>{};_installTurntable(){const e=this.orbitControls,t=e._handleMouseDownDolly.bind(this.orbitControls),i=e._handleMouseMoveDolly.bind(this.orbitControls);let s=null;e._handleMouseDownDolly=c=>{if(t(c),s=null,Ze().zoom?.drag!=="dolly")return;const h=this._canvas.getBoundingClientRect().top,d=this.orbitControls.object;s={len0:Math.max(5+c.clientY-h,1),offset:d.position.clone().sub(this.orbitControls.target),zoom0:d.zoom??1}},e._handleMouseMoveDolly=c=>{if(Ze().zoom?.drag!=="dolly"||!s){i(c);return}const h=this._canvas.getBoundingClientRect().top,d=Math.max(.01,2*((5+c.clientY-h)/s.len0-1)+1),p=this.orbitControls.object;p.isOrthographicCamera?(p.zoom=s.zoom0/d,p.updateProjectionMatrix(),this.orbitControls.dispatchEvent({type:"change"})):p.position.copy(this.orbitControls.target).addScaledVector(s.offset,d),this.orbitControls.update()};const r=e._handleTouchStartRotate.bind(this.orbitControls);e._handleTouchStartRotate=c=>{for(const h of[...this._rotateStartListeners])h();r(c)};const n=e._handleMouseDownRotate.bind(this.orbitControls),a=e._handleMouseMoveRotate.bind(this.orbitControls);let l=null;e._handleMouseDownRotate=c=>{n(c),l=null;for(const p of[...this._rotateStartListeners])p();if(!Ze().turntable)return;const h=this.orbitControls.object,d=new v(0,1,0).applyQuaternion(h.quaternion);l={x:c.clientX,y:c.clientY,reverse:d.y<0?-1:1}},e._handleMouseMoveRotate=c=>{const h=Ze().turntable;if(!h||!l){a(c);return}const d=c.clientX-l.x,p=c.clientY-l.y;l.x=c.clientX,l.y=c.clientY,this._turntableStep(d,p,l.reverse,Le.degToRad(h.degreesPerPixel))}}_rotateStartListeners=new Set([()=>{if(!Ze().autoPerspective||this._projection!=="orthographic")return;const e=this.camera.position.clone().sub(this.orbitControls.target),t=new v(0,1,0).applyQuaternion(this.camera.quaternion);Bi(e,t)!==null&&this.setProjection("perspective")}]);_axisViewListeners=[()=>(Ze().autoPerspective&&this.setProjection("orthographic"),!0)];onAxisView(e){return this._axisViewListeners.push(e),()=>{const t=this._axisViewListeners.indexOf(e);t!==-1&&this._axisViewListeners.splice(t,1)}}onRotateStart(e){return this._rotateStartListeners.add(e),()=>this._rotateStartListeners.delete(e)}stepView(e){const t=this.orbitControls.object,i=this.orbitControls.target,s=Le.degToRad(15),r=new v(0,1,0),n=new v(1,0,0).applyQuaternion(t.quaternion),a=new v(0,0,1).applyQuaternion(t.quaternion),l=new v(0,1,0).applyQuaternion(t.quaternion);this._snapAnimating=!1;const c=this.orbitControls;if(c._sphericalDelta.set(0,0,0),c._panOffset.set(0,0,0),this.orbitControls.dispatchEvent({type:"start"}),e==="opposite"&&Bi(a,l)!==null){const u=w=>w.y>.5?new v(0,0,-1):w.y<-.5?new v(0,0,1):new v(0,1,0),f=a.clone().round(),m=f.clone().negate(),y=u(f).angleTo(l)*Math.sign(u(f).cross(l).dot(f)||1),_=u(m).applyAxisAngle(m,y),x=new pe().setFromRotationMatrix(new Xt().lookAt(m,new v,_)),S=t.position.distanceTo(i);t.quaternion.copy(x),t.position.copy(i).addScaledVector(m,S),t.up.copy(_),this.orbitControls.update(),this.orbitControls.dispatchEvent({type:"end"});return}const h=new pe;switch(e){case"orbit-left":h.setFromAxisAngle(r,-s);break;case"orbit-right":h.setFromAxisAngle(r,s);break;case"orbit-up":h.setFromAxisAngle(n,-s);break;case"orbit-down":h.setFromAxisAngle(n,s);break;case"opposite":h.setFromAxisAngle(r,Math.PI);break;case"roll-left":h.setFromAxisAngle(a,-s);break;case"roll-right":h.setFromAxisAngle(a,s);break}const d=h.multiply(t.quaternion).normalize(),p=t.position.distanceTo(i);t.quaternion.copy(d),t.position.copy(i).addScaledVector(new v(0,0,1).applyQuaternion(d),p),t.up.set(0,1,0).applyQuaternion(d),this.orbitControls.update(),this.orbitControls.dispatchEvent({type:"end"})}zoomStep(e){const t=Ze().zoom?.step??1.2,i=e>0?1/t:t,s=this.orbitControls.object;if(this.orbitControls.dispatchEvent({type:"start"}),s.isOrthographicCamera)s.zoom/=i,s.updateProjectionMatrix(),this.orbitControls.dispatchEvent({type:"change"});else{const r=this.orbitControls.target;s.position.sub(r).multiplyScalar(i).add(r)}this.orbitControls.update(),this.orbitControls.dispatchEvent({type:"end"})}_turntableStep(e,t,i,s){const r=this.orbitControls.object,n=this.orbitControls.target,a=new v(0,1,0),l=new v(1,0,0).applyQuaternion(r.quaternion),c=new v(0,0,1).applyQuaternion(r.quaternion),h=new v;if(a.distanceToSquared(c)>.001){h.crossVectors(a,c),h.dot(l)<0&&h.negate();const m=(Math.abs(a.angleTo(c)/Math.PI-.5)*2)**2;h.lerp(l,m)}else h.copy(l);h.lengthSq()===0&&h.copy(l),h.normalize();const d=new pe().setFromAxisAngle(h,-s*t),u=new pe().setFromAxisAngle(a,-s*i*e).multiply(d).multiply(r.quaternion).normalize(),f=r.position.distanceTo(n);r.quaternion.copy(u),r.position.copy(n).addScaledVector(new v(0,0,1).applyQuaternion(u),f),r.up.set(0,1,0).applyQuaternion(u),this.orbitControls.update()}get cameraViewMode(){return this._cameraViewMode}setCameraView(e,t){if(this.clearCameraView(),this._cameraView=e,this._cameraViewMode=t,this._orbitEnabledBeforeCameraView=this.orbitControls.enabled,this._orbitTargetBeforeCameraView.copy(this.orbitControls.target),t==="pilot"){const i=e.getWorldPosition(new v),s=e.getWorldDirection(new v),r=Math.max(1,this.freeCamera.position.distanceTo(this.orbitControls.target));this.orbitControls.object=e,this.orbitControls.target.copy(i).add(s.multiplyScalar(r)),this.orbitControls.enabled=!0,this.orbitControls.update()}else this.orbitControls.enabled=!1;this._publishPickContext&&this._installPickContext(e)}clearCameraView(){if(!this._cameraView)return;this._flyActive&&this._exitFlyMode(),this.orbitControls.object=this.freeCamera,this.orbitControls.target.copy(this._orbitTargetBeforeCameraView),this.orbitControls.enabled=this._orbitEnabledBeforeCameraView,this.orbitControls.update(),this._cameraView=null,this._cameraViewMode=null;const e=this._pendingProjection;this._pendingProjection=null,e&&e!==this._projection&&this.setProjection(e),this._publishPickContext&&this._installPickContext(this.freeCamera)}get objectMap(){return this._objectMap}set objectMap(e){this._objectMap=e}attach(e){const t=this._objectForAuthoringId(e);t&&(this._attachedAuthoringId=e,this._attachGizmosTo(t))}detach(){this._attachedAuthoringId=null,this._detachGizmos()}_objectForAuthoringId(e){const t=this._authoring();return t.hierarchy.node(e)===null?null:Xh(t,this._objectMap,e)}_authoringIdForObject(e){return this._authoring().hierarchy.idForObject3D?.(e)??uo(e)??null}_hasBoundableGeometry(e){return gc([e]).length>0}_makeDiagnosticBounds(e){if(this._hasBoundableGeometry(e))return new za(e,Qe(this._canvas).visible);const t=new xe(Er,Er,Er),i=new _o(t);t.dispose();const s=new qt({color:new V(Qe(this._canvas).visible),toneMapped:!1}),r=new Li(i,s);return e.getWorldPosition(r.position),r.isBoxHelper=!0,r._entityObj=e,r}_syncBoxHelpers(){for(const t of this._boxHelpers.values())this._scene.remove(t),t.geometry.dispose(),t.material.dispose();this._boxHelpers.clear();const e=(t,i)=>{i.layers.set(Z),this._scene.add(i),this._boxHelpers.set(t,i)};if(this._store.shell.showHelpers&&this._store.shell.helperVisibility.bounds)for(const t of this._objectMap.keys()){const i=this._objectForAuthoringId(t);i&&e(`bounds:${t}`,this._makeDiagnosticBounds(i))}for(const t of this._store.shell.selectedEntityIds){const i=this._objectForAuthoringId(t);if(!i)continue;const s=this._hasBoundableGeometry(i);if(s&&this._selectionMarks.wire){let r=0;i.traverse(n=>{const a=n;if(!a.isMesh||!a.geometry||gt(a))return;const l=la(this._canvas),c=new Li(new qd(a.geometry),new qt({color:l.color??Qe(this._canvas).visible,transparent:!0,opacity:l.opacity??.5,depthTest:!0}));c.matrixAutoUpdate=!1,c._wireOf=a,e(`wire:${t}:${r++}`,c)})}if(!(s&&!this._selectionMarks.box)){if(s){const r=aa(this._canvas);e(`selection:${t}`,new Nn(i,{color:Qe(this._canvas).visible,edges:r.edges,frame:r.frame,...r.lineWidth===null?{}:{lineWidth:r.lineWidth}}));continue}this._standaloneAuthoring&&i.isBone||[...this._constraintHelpers.values()].some(r=>r.presents(i))||i.userData.vgaiOwnOverlay||e(`selection:${t}`,new Nn(i,{fixedSize:Er,color:Qe(this._canvas).visible}))}}}_syncReflectionProbeHelpers(e=null){if(e===null){const t=new Map,i=new Set;for(const[s,r]of this._objectMap)!r||i.has(r)||!us(r)||(i.add(r),t.set(s,r));for(const[s,r]of this._reflectionProbeHelpers)t.get(s)!==r.source&&(r.dispose(),this._reflectionProbeHelpers.delete(s));for(const[s,r]of t)this._ensureReflectionProbeHelper(s,r)}else{let t=!1;for(const i of e){const s=this._objectMap.get(i),r=s&&us(s)?s:null,n=this._reflectionProbeHelpers.get(i);n&&n.source!==r&&(r===null&&(t=!0),n.dispose(),this._reflectionProbeHelpers.delete(i)),r&&![...this._reflectionProbeHelpers.values()].some(a=>a.source===r)&&this._ensureReflectionProbeHelper(i,r)}if(t){this._syncReflectionProbeHelpers();return}}for(const[t,i]of this._reflectionProbeHelpers)i.setSelected(this._store.shell.selectedEntityIds.has(t)),i.visible=this._threejsToolContextActive&&this._store.shell.showHelpers&&this._store.shell.helperVisibility.reflectionProbes,i.update()}_ensureReflectionProbeHelper(e,t){if(this._reflectionProbeHelpers.has(e))return;const i=new Qp(t);this._reflectionProbeHelpers.set(e,i),this._scene.add(i)}_syncTriggerVolumeHelpers(e=null){if(e===null){const i=new Map,s=new Set;for(const[r,n]of this._objectMap)!n||s.has(n)||!eo(n)||(s.add(n),i.set(r,n));for(const[r,n]of this._triggerVolumeHelpers)i.get(r)!==n.source&&this._disposeTriggerVolumeHelper(r,n);for(const[r,n]of i)this._ensureTriggerVolumeHelper(r,n)}else{let i=!1;for(const s of e){const r=this._objectMap.get(s),n=r&&eo(r)?r:null,a=this._triggerVolumeHelpers.get(s);a&&a.source!==n&&(n===null&&(i=!0),this._disposeTriggerVolumeHelper(s,a)),n&&![...this._triggerVolumeHelpers.values()].some(l=>l.source===n)&&this._ensureTriggerVolumeHelper(s,n)}if(i){this._syncTriggerVolumeHelpers();return}}const t=this._threeSurfaceShowing&&this._store.shell.showHelpers&&this._store.shell.helperVisibility.triggerVolumes;for(const[i,s]of this._triggerVolumeHelpers)s.setSelected(this._store.shell.selectedEntityIds.has(i)),s.visible=t,s.update()}_ensureTriggerVolumeHelper(e,t){if(this._triggerVolumeHelpers.has(e))return;const i=new jf(t);this._triggerVolumeHelpers.set(e,i),this._scene.add(i)}_disposeTriggerVolumeHelper(e,t){t.dispose(),this._triggerVolumeHelpers.delete(e)}_syncConstraintHelpers(e=null){if(e===null){const i=new Map,s=new Set;for(const[r,n]of this._objectMap)!n||s.has(n)||Nr(n).length===0||(s.add(n),i.set(r,n));for(const[r,n]of this._constraintHelpers)i.get(r)!==n.source&&(this._disposeConstraintHelper(n),this._constraintHelpers.delete(r));for(const[r,n]of i)this._ensureConstraintHelper(r,n)}else{let i=!1;for(const s of e){const r=this._objectMap.get(s),n=r&&Nr(r).length>0?r:null,a=this._constraintHelpers.get(s);a&&a.source!==n&&(n===null&&(i=!0),this._disposeConstraintHelper(a),this._constraintHelpers.delete(s)),n&&![...this._constraintHelpers.values()].some(l=>l.source===n)&&this._ensureConstraintHelper(s,n)}if(i){this._syncConstraintHelpers();return}}const t=new Set;for(const i of this._store.shell.selectedEntityIds){const s=this._objectForAuthoringId(i);s&&t.add(s)}for(const[i,s]of this._constraintHelpers)s.setSelected(this._store.shell.selectedEntityIds.has(i)),s.setSelectedObjects(t),s.visible=this._threejsToolContextActive&&this._store.shell.showHelpers&&this._store.shell.helperVisibility.constraints,s.update(this.camera)}_ensureConstraintHelper(e,t){if(this._constraintHelpers.has(e))return;const i=new Xp(t);this._constraintHelpers.set(e,i),this._scene.add(i)}_disposeConstraintHelper(e){this._hoveredConstraintControl?.helper===e&&(this._hoveredConstraintControl=null),e.dispose()}_raycastConstraintControl(e){const t=[];for(const n of this._constraintHelpers.values())n.visible&&t.push(...n.controlMeshes());if(t.length===0)return null;const i=this._canvas.getBoundingClientRect(),s=new je((e.clientX-i.left)/i.width*2-1,-((e.clientY-i.top)/i.height)*2+1);this._constraintControlRaycaster.setFromCamera(s,this._screenCamera);const r=this._constraintControlRaycaster.intersectObjects(t,!1)[0]?.object;if(!r)return null;for(const n of this._constraintHelpers.values()){const a=n.controlFor(r);if(a)return{helper:n,control:a}}return null}_updateConstraintControlHover(e){if(e.buttons&1)return this._constraintControlPointerSession;const t=this._hoverConstraintControlAt(e);return t?(this._hoveredSpatialHandle&&(Fn(this._hoveredSpatialHandle,!1),this._hoveredSpatialHandle=null),this._canvas.style.cursor=t,!0):(this._canvas.style.cursor="",!1)}_hoverConstraintControlAt(e){const t=this._raycastConstraintControl(e),i=this._hoveredConstraintControl;return t?(i?.mesh!==t.control.mesh&&(i&&i.helper.setHoveredControl(null),t.helper.setHoveredControl(t.control.mesh),this._hoveredConstraintControl={helper:t.helper,mesh:t.control.mesh}),this._authoringIdForObject(t.control.object)?"pointer":"not-allowed"):(this._clearConstraintControlHover(),null)}_clearConstraintControlHover(){this._hoveredConstraintControl?.helper.setHoveredControl(null),this._hoveredConstraintControl=null}_selectConstraintControlAt(e,t=!0){const i=this._raycastConstraintControl(e);if(!i)return!1;this._constraintControlPointerSession=t;const s=this._authoringIdForObject(i.control.object);if(s){const r=this._authoring();cs(r,[s],{intent:"exact"})||this._store.shell.select(s),et(`${i.control.label} selected — move it with the gizmo.`)}else et(`${i.control.label} is a runtime-only constraint control.`);return!0}_syncCameraHelpers(e=null){if(e===null){const i=new Map;for(const[s,r]of this._objectMap){const n=this._nativeCamera(r);n&&i.set(s,n)}for(const[s,r]of this._cameraHelpers)i.get(s)!==r.source&&this._disposeCameraHelper(s,r);for(const[s,r]of i)this._ensureCameraHelper(s,r)}else{let i=!1;for(const s of e){const r=this._objectMap.get(s),n=r?this._nativeCamera(r):null,a=this._cameraHelpers.get(s);a&&a.source!==n&&(n===null&&(i=!0),this._disposeCameraHelper(s,a)),n&&![...this._cameraHelpers.values()].some(l=>l.source===n)&&this._ensureCameraHelper(s,n)}if(i){this._syncCameraHelpers();return}}const t=this._threeSurfaceShowing&&this._store.shell.showHelpers&&this._store.shell.helperVisibility.cameras;for(const i of this._cameraHelpers.values())i.helper.visible=t,i.helper.update()}_syncLightHelpers(e=null){if(e===null){const i=new Map;for(const[s,r]of this._objectMap){const n=this._nativeLight(r);n&&i.set(s,n)}for(const[s,r]of this._lightHelpers)i.get(s)!==r.source&&this._disposeLightHelper(s,r);for(const[s,r]of i)this._ensureLightHelper(s,r)}else{let i=!1;for(const s of e){const r=this._objectMap.get(s),n=r?this._nativeLight(r):null,a=this._lightHelpers.get(s);a&&a.source!==n&&(n===null&&(i=!0),this._disposeLightHelper(s,a)),n&&![...this._lightHelpers.values()].some(l=>l.source===n)&&this._ensureLightHelper(s,n)}if(i){this._syncLightHelpers();return}}const t=this._threeSurfaceShowing&&this._store.shell.showHelpers&&this._store.shell.helperVisibility.lights;for(const i of this._lightHelpers.values())i.helper.visible=t,i.helper.update?.()}_nativeLight(e){return e.userData.vgaiOwnOverlay?null:e.isLight?e:null}_disposeLightHelper(e,t){t.helper.removeFromParent(),t.helper.dispose?.(),this._lightHelpers.delete(e)}_ensureLightHelper(e,t){if(this._lightHelpers.has(e))return;const i=.5;let s=null;const r=t;try{r.isDirectionalLight?s=new Jd(t,i):r.isPointLight?s=new Yd(t,i):r.isSpotLight?s=new Zd(t):r.isHemisphereLight&&(s=new Qd(t,i))}catch{s=null}s&&(s.name=`Light helper: ${t.name||e}`,s.userData.editorOnly=!0,s.traverse(n=>n.layers.set(Z)),s.layers.set(Z),this._lightHelpers.set(e,{source:t,helper:s}),this._scene.add(s))}_syncAudioHelpers(e=null){if(e===null){const i=new Map;for(const[s,r]of this._objectMap){const n=this._nativeAudio(r);n&&i.set(s,n)}for(const[s,r]of this._audioHelpers)i.get(s)!==r.source&&this._disposeAudioHelper(s,r);for(const[s,r]of i)this._ensureAudioHelper(s,r)}else for(const i of e){const s=this._objectMap.get(i),r=s?this._nativeAudio(s):null,n=this._audioHelpers.get(i);n&&n.source!==r&&this._disposeAudioHelper(i,n),r&&![...this._audioHelpers.values()].some(a=>a.source===r)&&this._ensureAudioHelper(i,r)}const t=this._threeSurfaceShowing&&this._store.shell.showHelpers&&this._store.shell.helperVisibility.audio;for(const i of this._audioHelpers.values())i.helper.visible=t}_nativeAudio(e){const t=e.type;return t==="Audio"||t==="PositionalAudio"||t==="AudioListener"?e:null}_ensureAudioHelper(e,t){if(this._audioHelpers.has(e))return;const i=new Ve,s=t.type==="AudioListener"?8377599:16763274,r=new T(new ni(.16),new Ce({color:s,wireframe:!0,depthTest:!1}));i.add(r),i.name=`Audio helper: ${t.name||e}`,i.userData.editorOnly=!0,i.traverse(n=>n.layers.set(Z)),i.layers.set(Z),t.add(i),this._audioHelpers.set(e,{source:t,helper:i})}_disposeAudioHelper(e,t){t.helper.traverse(i=>{const s=i;s.geometry?.dispose?.(),s.material?.dispose?.()}),t.helper.removeFromParent(),this._audioHelpers.delete(e)}_disposeCameraHelper(e,t){t.helper.removeFromParent(),t.helper.dispose(),this._cameraHelpers.delete(e)}_ensureCameraHelper(e,t){if(this._cameraHelpers.has(e))return;let i;try{i=new $d(t)}catch(s){this._refuseCameraOverlay(e,t,s);return}i.name=`Camera frustum: ${t.name||e}`,i.userData.editorOnly=!0,i.layers.set(Z),this._cameraHelpers.set(e,{source:t,helper:i}),this._scene.add(i)}_refusedCameraOverlays=new Set;_refuseCameraOverlay(e,t,i){this._refusedCameraOverlays.has(e)||(this._refusedCameraOverlays.add(e),Oi.warn(`Helpers → Cameras draws no frustum for "${t.name||t.type}": ${i instanceof Error?i.message:String(i)}. This world's camera was constructed by the GAME's own copy of three, and \`THREE.CameraHelper\` is the editor's class reading fields off it that that revision does not define. Every other camera capability (framing, selection, inspection) is unaffected. It closes when the game resolves \`three\` to the host's instance — a bare, un-rewritten \`import 'three'\` in its own source.`,"authoring"))}_nativeCamera(e){if(e.userData.vgaiOwnOverlay)return null;if(e.isCamera)return e;const t=Oe(e,"_camera");return t?.isCamera?t:null}_syncSpatialHandles(){ll(this._spatialHandleRoots),this._spatialHandleRoots=[],this._spatialHandleMeshes=[],this._hoveredSpatialHandle=null;const e=yn(this._authoring());if(!e||!this._threejsToolContextActive||!this._store.shell.showHelpers)return;const t=this._store.shell.helperVisibility;for(const i of this._store.shell.selectedEntityIds){const s=e.layers(i).filter(n=>n.category in t?t[n.category]:!0),r=yf(i,s);for(const n of r.handles)al(n,this._screenCamera);for(const n of r.roots)this._scene.add(n);this._spatialHandleRoots.push(...r.roots),this._spatialHandleMeshes.push(...r.handles)}}_raycastSpatialHandle(e){if(this._spatialHandleMeshes.length===0)return null;const t=this._canvas.getBoundingClientRect(),i=new je((e.clientX-t.left)/t.width*2-1,-((e.clientY-t.top)/t.height)*2+1);return this._spatialHandleRaycaster.setFromCamera(i,this._screenCamera),this._spatialHandleRaycaster.intersectObjects(this._spatialHandleMeshes,!1)[0]?.object??null}_spatialHandleWorldPoint(e){const t=this._canvas.getBoundingClientRect(),i=new je((e.clientX-t.left)/t.width*2-1,-((e.clientY-t.top)/t.height)*2+1);this._spatialHandleRaycaster.setFromCamera(i,this._screenCamera);const s=new v;return this._spatialHandleRaycaster.ray.intersectPlane(this._spatialHandleDragPlane,s)?s.add(this._spatialHandleDragOffset):null}_finishSpatialHandleDrag(e){const t=this._activeSpatialHandle;this._activeSpatialHandle=null,this.orbitControls.enabled=this._orbitEnabledBeforeHandleDrag,this.transformControls.enabled=this._transformEnabledBeforeHandleDrag,this.syncFromStore(),this._canvas.style.cursor="",e&&t&&yn(this._authoring())?.commit(t.nodeId,t.handle.id,[this._spatialHandleDragPoint.x,this._spatialHandleDragPoint.y,this._spatialHandleDragPoint.z])}_updateSpatialHandleDrag(e){const t=this._activeSpatialHandle;if(!t)return!1;const i=this._spatialHandleWorldPoint(e);return i&&(this._spatialHandleDragPoint.copy(i),yn(this._authoring())?.preview(t.nodeId,t.handle.id,[i.x,i.y,i.z]),this._syncSpatialHandles(),this._canvas.style.cursor="grabbing"),!0}_updateSpatialHandleHover(e){if(e.buttons&1||this._spatialHandleMeshes.length===0)return;const t=this._raycastSpatialHandle(e);if(t===this._hoveredSpatialHandle)return;if(this._hoveredSpatialHandle&&Fn(this._hoveredSpatialHandle,!1),this._hoveredSpatialHandle=t,!t){this._canvas.style.cursor="";return}Fn(t,!0);const i=ol(t);this._canvas.style.cursor=i?.handle.writable?"grab":"not-allowed"}_updateEditorHandleInteraction(e){return this._updateSpatialHandleDrag(e)||this._updateConstraintControlHover(e)}_previewInfrastructure(){return[this.grid,...this._axisLines?[this._axisLines]:[],this._gizmoHelper,this._auxRotateControls.getHelper(),this._auxScaleControls.getHelper(),...this._boxHelpers.values(),...this._constraintHelpers.values(),...this._reflectionProbeHelpers.values(),...this._triggerVolumeHelpers.values(),...[...this._cameraHelpers.values()].map(({helper:e})=>e),...this._spatialHandleRoots]}_suspendPreviewInfrastructure(){const e=this._previewInfrastructure().map(t=>[t,t.visible]);for(const[t]of e)t.visible=!1;return()=>{for(const[t,i]of e)t.visible=i}}_allGizmos(){return[this.transformControls,this._auxRotateControls,this._auxScaleControls]}_anyGizmoDragging(){return this._allGizmos().some(e=>e.dragging)}_attachGizmosTo(e){this.transformControls.attach(e),this._auxRotateControls.attach(e),this._auxScaleControls.attach(e)}_detachGizmos(){for(const e of this._allGizmos())e.detach()}syncFromStore(){this._gizmoHelper.traverse(b=>b.layers.set(Z));const e=this._store.shell.transformMode,i=e==="combined"||e==="select"?"translate":e;this.transformControls.mode!==i&&this.transformControls.setMode(i),this._applySnapToGizmos();for(const b of this._allGizmos())b.setSpace(this._store.shell.transformSpace);const s=yr(),r=this._authoring(),n=s.toolOwner(r,this._store.shell.selectedEntityIds);this._threejsToolContextActive=(this._standaloneAuthoring||s.toolOwnerPainted(this._store.shell,n))&&n?.kind==="three";const a=this._standaloneAuthoring||s.threeSurfaceShowing(this._store.shell,r);this._threeSurfaceShowing=a,this.grid.visible=this._presentationGrid&&a,this._axisLines&&(this._axisLines.visible=this.grid.visible&&this._axesWanted);const l=this._store.shell.helperVisibility,c=this._standaloneAuthoring?null:s.threeViewportRootId(this._store.shell),h=c!==null&&eh(c);h&&s.applyRootHiddenVisibility(this._objectMap,c),h&&s.suppressRootEnvironment(this._scene);const d=this._store.gizmoEpoch,p=`${this._store.shell.showHelpers}|${JSON.stringify(l)}|${c??""}|${h}|${this._threejsToolContextActive}`,u=this._objectMap!==this._lastGizmoObjectMap,f=p!==this._lastGizmoSig,m=u?null:this._store.ingestObjectMapMembershipChangesSince(this._lastGizmoEpoch),y=u||f||m===null?null:m.changedIds,_=y===null||y.size>0;if(this._lastGizmoObjectMap=this._objectMap,this._lastGizmoSig=p,this._lastGizmoEpoch=d,_){s.applyRootHiddenVisibility(this._objectMap,c);const b=y===null?Gf(this._objectMap):Wf(this._objectMap,y);for(const M of b)M.traverse(P=>{if(Oe(P,"editorIcon")){P.visible=this._store.shell.showHelpers;return}if(!Oe(P,"editorHelper"))return;const E=Oe(P,"editorHelperType");if(E==="skeletons"){P.visible=this._store.shell.showHelpers&&(l.skeletons||!!Oe(P,"skeletonEnabled"));return}E&&E in l?P.visible=this._store.shell.showHelpers&&l[E]:P.visible=this._store.shell.showHelpers});for(const[M,P]of this._helpers)P.visible=this._store.shell.showHelpers&&(!(M in l)||l[M]);this._syncCameraHelpers(y),this._syncLightHelpers(y)}this._syncAudioHelpers(y),this._syncReflectionProbeHelpers(y),this._syncTriggerVolumeHelpers(y),this._syncConstraintHelpers(y);const x=this._threejsToolContextActive&&r.capabilities.transform&&e!=="select"?this._store.shell.selectedEntityId:null,S=e==="translate"||e==="combined"?"position":e==="rotate"?"rotation":"scale",C=x?e==="combined"?(b=>["position","rotation","scale"].some(M=>r.transforms?.editability?.(b,M).writable??!0))(x):r.transforms?.editability?.(x,S).writable??!0:!1;if(x&&C){if(!this._anyGizmoDragging())if(this._store.shell.pivotMode==="median-point"&&this._store.shell.selectedEntityIds.size>1){const b=new v;let M=0;for(const P of this._store.shell.selectedEntityIds){if(!(r.transforms?.editability?.(P,S).writable??!0))continue;const E=this._objectForAuthoringId(P);E&&(b.add(E.getWorldPosition(Yf)),M++)}M>0&&b.divideScalar(M),this._pivotDummy.position.copy(b),this._pivotDummy.quaternion.identity(),this._pivotDummy.scale.set(1,1,1),this._attachedAuthoringId=null,this._dummyIsPresentationAnchor=!1,this._attachGizmosTo(this._pivotDummy)}else{const b=this._objectForAuthoringId(x),M=Oe(b,"pivot"),P=M&&(M[0]!==0||M[1]!==0||M[2]!==0),E=P?null:this._centreAnchorFor(b);if(E&&b)this._pivotDummy.position.copy(E),this._pivotDummy.quaternion.copy(b.getWorldQuaternion(Dn)),this._pivotDummy.scale.copy(b.getWorldScale(fl)),this._attachedAuthoringId=x,this._dummyIsPresentationAnchor=!0,this._attachGizmosTo(this._pivotDummy);else if(P&&b){const R=new v(M[0],M[1],M[2]);R.applyQuaternion(b.getWorldQuaternion(Dn)),this._pivotDummy.position.copy(b.getWorldPosition(pl)).add(R),this._pivotDummy.quaternion.copy(Dn),this._pivotDummy.scale.copy(b.getWorldScale(fl)),this._attachedAuthoringId=x,this._dummyIsPresentationAnchor=!1,this._attachGizmosTo(this._pivotDummy)}else this._dummyIsPresentationAnchor=!1,this.attach(x)}}else this.detach();this._syncBoxHelpers(),this._syncSpatialHandles(),this._syncCombinedGizmoHalves()}_applySnapToGizmos(){const e=this._store.shell.snapEnabled||this._snapHold,t=this._store.shell.snapValues;for(const i of this._allGizmos())i.setTranslationSnap(e?t.translate:null),i.setRotationSnap(e?Le.degToRad(t.rotate):null),i.setScaleSnap(e?t.scale:null)}_modifiedZoom=!1;_onAltOrbitStart=e=>{e.button===1&&(e.ctrlKey||e.metaKey)&&Ze().orbit==="middle"&&(this._modifiedZoom=!0,this.orbitControls.mouseButtons.MIDDLE=Ie.DOLLY),e.altKey&&e.button===0&&(this._altDragOrbit=!0,this.orbitControls.mouseButtons.LEFT=Ie.ROTATE)};_onAltOrbitRelease=e=>{this._modifiedZoom&&(!e||e.type==="pointercancel"||e.button===1)&&(this._modifiedZoom=!1,this.applyKeymapNavigation()),this._altDragOrbit&&(this._altDragOrbit=!1,this.orbitControls.mouseButtons.LEFT=-1)};_onSnapHoldKey=e=>{const t=e.ctrlKey||e.metaKey;if(t!==this._snapHold&&(this._snapHold=t,this._applySnapToGizmos(),t&&this._anyGizmoDragging()&&!this._store.shell.snapEnabled)){const{translate:i,rotate:s,scale:r}=this._store.shell.snapValues;et(`Snapping while held: ${i} units · ${s}° · ×${r}`)}};_syncCombinedGizmoHalves(){if(this._anyGizmoDragging())return;const e=this._store.shell.transformMode==="combined",t=this._attachedAuthoringId,i=this._authoring().transforms?.editability,s=c=>t===null||(i?.(t,c).writable??!0),r=e&&this._auxRotateControls.object!==void 0&&s("rotation"),n=e&&this._transformHandles.scale&&this._auxScaleControls.object!==void 0&&s("scale");this._auxRotateControls.enabled=r,this._auxScaleControls.enabled=n;const a=this._auxRotateControls.getHelper(),l=this._auxScaleControls.getHelper();a.visible=r,l.visible=n;for(const c of[a,l])c.traverse(h=>h.layers.set(Z));this.transformControls.enabled=!0}moveGizmosTo(e){const t=this._gizmoObjects();for(const i of t)e.add(i)}restoreGizmos(){const e=this._gizmoObjects();for(const t of e)this._scene.add(t)}_gizmoObjects(){return[this.grid,...this._axisLines?[this._axisLines]:[],this._editorAmbient,this._editorDirLight,this.batchedRenderer,this._gizmoHelper,this._auxRotateControls.getHelper(),this._auxScaleControls.getHelper(),this._pivotDummy,this._surfaceSnapIndicator,...[...this._cameraHelpers.values()].map(({helper:e})=>e),...this._spatialHandleRoots]}_contentBounds(e=!1){const t=performance.now(),i=this._contentBoundsAt===0||t-this._contentBoundsAt>Xf;if(e||i){this._contentBoundsBox.makeEmpty();for(const s of this._scene.children)gt(s)||pd(this._contentBoundsBox,s);this._contentBoundsAt=t}return this._contentBoundsBox}_measureContentBounds(){const e=[];for(const t of this._scene.children)gt(t)||fd(t,e);this._contentBoundsBox.makeEmpty();for(const t of e)this._contentBoundsBox.union(t);return this._contentBoundsAt=performance.now(),e}_updateClipPlanes(){const e=this._contentBounds();let t=0,i=0;e.isEmpty()||(e.getBoundingSphere(Hn),t=this.freeCamera.position.distanceTo(Hn.center),i=Hn.radius);const{near:s,far:r}=hu(t,i);s===this.camera.near&&r===this.camera.far||(this.camera.near=s,this.camera.far=r,this.camera.updateProjectionMatrix(),this.orthographicCamera.near=s,this.orthographicCamera.far=r,this.orthographicCamera.updateProjectionMatrix())}seedFromGameCamera(e){const t=sl(this._measureContentBounds()),i=rf(e,t);if(!i)return!1;const s=this.camera.position.clone(),r=this.orbitControls.target.clone();this.camera.position.copy(i.position),this.orbitControls.target.copy(i.target),this.camera.lookAt(this.orbitControls.target),this.camera.updateMatrixWorld(!0);const n=this._scene.children.filter(a=>!gt(a));return lf(this.camera,n,i.position.distanceTo(i.target))?(this._updateClipPlanes(),this.orbitControls.update(),!0):(this.camera.position.copy(s),this.orbitControls.target.copy(r),this.camera.lookAt(this.orbitControls.target),this.camera.updateMatrixWorld(!0),!1)}focusOnScene(){const e=sl(this._measureContentBounds());if(e.isEmpty())return!1;const t=e.getCenter(new v),i=this.camera.position.clone().sub(this.orbitControls.target).normalize(),s=hi(e,this.camera,i);return Number.isFinite(s)?(this.camera.position.copy(t).add(i.multiplyScalar(s)),this.orbitControls.target.copy(t),this._orthographicHeight=Math.max(e.getSize(new v).y,e.getSize(new v).x/this._viewportAspect)*1.15,this._syncOrthographicFromPerspective(!0),this._updateClipPlanes(),!0):!1}focusOn(e){const t=this._contentOrProbeBounds(e),i=t.getCenter(new v),s=this.camera.position.clone().sub(this.orbitControls.target).normalize(),r=hi(t,this.camera,s);this.camera.position.copy(i).add(s.multiplyScalar(r)),this.orbitControls.target.copy(i);const n=t.getSize(new v);this._orthographicHeight=Math.max(n.y,n.x/this._viewportAspect,.01)*1.15,this._syncOrthographicFromPerspective(!0)}activateVertexSnap(){this._vertexSnapTargets=this._collectVertices(this._store.shell.selectedEntityIds)}deactivateVertexSnap(){this._vertexSnapTargets=[],this._vertexSnapIndicator.visible=!1}focusOnMultiple(e){if(e.length===0)return;if(e.length===1){this.focusOn(e[0]);return}const t=new wt;for(const a of e)t.union(this._contentOrProbeBounds(a));const i=t.getCenter(new v),s=this.camera.position.clone().sub(this.orbitControls.target).normalize(),r=hi(t,this.camera,s);this.camera.position.copy(i).add(s.multiplyScalar(r)),this.orbitControls.target.copy(i);const n=t.getSize(new v);this._orthographicHeight=Math.max(n.y,n.x/this._viewportAspect,.01)*1.15,this._syncOrthographicFromPerspective(!0)}_centreAnchorFor(e){const t=this._store.shell.gizmoAnchor;if(!e||t==="pivot"||t==="auto"&&qh(e)===0)return null;const i=li(e);if(i.isEmpty()||t==="auto"&&!Jh(e,i)?.worldAnchored)return null;const s=i.getCenter(new v);return e.updateWorldMatrix(!0,!1),s.distanceToSquared(e.getWorldPosition(pl))<Zf?null:s}_contentOrProbeBounds(e){const t=us(e);if(!t)return li(e);const i=t.config,[s,r,n]=i.size,a=i.shape==="sphere"?new v(1,1,1).multiplyScalar(Math.max(.01,i.radius)):new v(Math.max(.01,s),Math.max(.01,r),Math.max(.01,n)).multiplyScalar(.5);return e.updateWorldMatrix(!0,!1),new wt(a.clone().negate(),a).applyMatrix4(e.matrixWorld)}setHelper(e,t){K();const i=this._helpers.get(e);if(i&&(this._scene.remove(i),this._helpers.delete(e)),!t)return;qe(t,"editorHelper",!0),qe(t,"editorHelperType",e);const s=this._store.shell.helperVisibility;t.visible=this._store.shell.showHelpers&&(!(e in s)||s[e]),this._scene.add(t),this._helpers.set(e,t)}visibleHelpers(){return[...this._helpers.values()].filter(e=>e.visible&&e.parent!==null)}setViewPreset(e){this._projection==="orthographic"&&this.setProjection("perspective");const t=this.orbitControls.target.clone(),i=this.camera.position.distanceTo(t),s=new v;switch(e){case"top":s.set(0,1,0);break;case"front":s.set(0,0,1);break;case"right":s.set(1,0,0);break;case"bottom":s.set(0,-1,0);break;case"back":s.set(0,0,-1);break;case"left":s.set(-1,0,0);break;case"perspective":s.set(1,1,1).normalize();break}this.camera.position.copy(t).add(s.multiplyScalar(i)),e==="top"?this.camera.up.set(0,0,-1):e==="bottom"?this.camera.up.set(0,0,1):this.camera.up.set(0,1,0),this.camera.lookAt(t),e!=="perspective"&&this.setProjection("orthographic"),this.orbitControls.update()}setFieldOfView(e){if(!Number.isFinite(e.degrees)||e.degrees<=0||e.degrees>=180||e.degrees===this._fieldOfView.degrees&&e.axis===this._fieldOfView.axis)return;const t=s=>Math.tan(Le.degToRad(s*.5)),i=t(this.camera.fov);this._canvas.clientWidth>0&&this._canvas.clientHeight>0&&(this._viewportAspect=this._canvas.clientWidth/this._canvas.clientHeight,this.camera.aspect=this._viewportAspect),this._fieldOfView=e,this.camera.fov=Un(this._viewportAspect,e),this.camera.updateProjectionMatrix(),this._projection==="orthographic"&&(this._orthographicHeight*=t(this.camera.fov)/i),this._applyOrthographicFrustum()}setPose(e,t,i,s){this.setProjection("perspective"),s?this.camera.up.set(s.x,s.y,s.z):this.camera.up.set(0,1,0),this.camera.position.set(e.x,e.y,e.z),this.orbitControls.target.set(t.x,t.y,t.z),this.camera.lookAt(this.orbitControls.target),i!==void 0&&(this.camera.fov=i,this.camera.updateProjectionMatrix()),this.orbitControls.update()}resize(e,t){this._viewportAspect=Math.max(1,e)/Math.max(1,t),this.camera.aspect=this._viewportAspect,this.camera.fov=Un(this._viewportAspect,this._fieldOfView),this.camera.updateProjectionMatrix(),this._applyOrthographicFrustum(),this._applyGizmoSize()}update(e=0){this._ensureSparkRenderer(),this._syncLookBackground();const t=this.transformControls.object;if(t&&t!==this._pivotDummy&&!t.parent&&(this._detachGizmos(),this.syncFromStore()),this._updateFlyCamera(e),this.orbitControls.update(),this._snapAnimating){const i=performance.now()-this._snapStartTime;let s=Math.min(i/this._snapDuration,1);s=s<.5?4*s*s*s:1-(-2*s+2)**3/2;const r=new pe().slerpQuaternions(this._snapQ1,this._snapQ2,s),n=new v(0,0,1).applyQuaternion(r);this.freeCamera.position.copy(this.orbitControls.target).add(n.multiplyScalar(this._snapDist)),this.freeCamera.quaternion.copy(r),this.freeCamera.up.set(0,1,0).applyQuaternion(r),s>=1&&(this._snapAnimating=!1)}this._presentation&&(this._presentation.rig.resolveSource({light:this._store.isAdoptedSceneActive}),this._presentation.rig.update(this.camera));for(const i of this._boxHelpers.values()){const s=i._wireOf;if(s){i.matrix.copy(s.matrixWorld),i.matrixWorldNeedsUpdate=!0;continue}if(i instanceof Nn){i.updateIfNeeded();continue}const r=i;r._entityObj?r._entityObj.getWorldPosition(i.position):i instanceof za&&i.update()}for(const i of this._constraintHelpers.values())i.update(this.camera);for(const i of this._reflectionProbeHelpers.values())i.update();for(const i of this._triggerVolumeHelpers.values())i.update();for(const{helper:i}of this._cameraHelpers.values())i.update();for(const i of this._spatialHandleMeshes)al(i,this._screenCamera);this._enforceLodForcedLevels(),this.alignGridToView(this.renderCamera,this._renderer?.domElement.width??1),this._updateClipPlanes()}_enforceLodForcedLevels(){const e=new Set(this._objectMap.values());for(const[t,i]of this._store.lodForcedLevels){const s=this._objectMap.get(t),r=s?Yh(s,a=>e.has(a)):null;if(!r||r.levels.length===0)continue;r.autoUpdate=!1;const n=Math.min(Math.max(i,0),r.levels.length-1);for(let a=0;a<r.levels.length;a++)r.levels[a].object.visible=a===n}}renderWithInfrastructure(e){const t=this._sparkRenderer,i=this._cameraView?this._suspendPreviewInfrastructure():null;t&&this._scene.add(t);try{e()}finally{t?.removeFromParent(),i?.()}}renderViewCube(e){if(!this._threeSurfaceShowing||this._navigation==="hidden"||this._cameraView)return;const t=e.domElement.clientWidth,i=e.domElement.clientHeight,s=this._vcSize,r=this._vcDir.subVectors(this.freeCamera.position,this.orbitControls.target).normalize();this._vcCamera.position.copy(r.multiplyScalar(4)),this._vcCamera.up.copy(this.freeCamera.up),this._vcCamera.lookAt(0,0,0),this._syncOrientationGizmoDepth();const n=this._vcOrigin(t,i,this._chromeInsetPx),a=n.left,l=i-s-n.top,c=e.autoClear;try{e.setScissorTest(!0),e.setViewport(a,l,s,s),e.setScissor(a,l,s,s),e.clear(!1,!0,!1),e.autoClear=!1,e.render(this._vcScene,this._vcCamera)}finally{e.autoClear=c,e.setScissorTest(!1),e.setViewport(0,0,t,i)}}renderCameraPreview(e,t,i){if(!t||!i||this._cameraView)return;const s=e.domElement.clientWidth,r=e.domElement.clientHeight,n=e.domElement.getBoundingClientRect(),a=i.getBoundingClientRect(),l=Math.round(a.left-n.left),c=Math.round(n.bottom-a.bottom),h=Math.max(1,Math.round(a.width)),d=Math.max(1,Math.round(a.height));if(l>=s||c>=r||l+h<=0||c+d<=0)return;const p=this._suspendPreviewInfrastructure(),u=e.getClearColor(this._previewClearColor),f=e.getClearAlpha();try{e.setScissorTest(!0),e.setViewport(l,c,h,d),e.setScissor(l,c,h,d),e.setClearColor(1118740,1),e.clear(),e.render(this._scene,t)}finally{e.setScissorTest(!1),e.setViewport(0,0,s,r),e.setClearColor(u,f),p()}}get isFlying(){return this._flyActive}_inputDisconnected=!1;disconnectInput(){if(!this._inputDisconnected){this._inputDisconnected=!0,this._publishPickContext&&el(null),window.removeEventListener("keydown",this._onFlyKeyDown),window.removeEventListener("keyup",this._onFlyKeyUp),this._interactionElement.removeEventListener("pointerdown",this._onFlyPointerDown),this._canvas.removeEventListener("pointerdown",this._onAltOrbitStart,{capture:!0}),window.removeEventListener("pointerup",this._onAltOrbitRelease,{capture:!0}),window.removeEventListener("pointercancel",this._onAltOrbitRelease,{capture:!0}),window.removeEventListener("keydown",this._onSnapHoldKey),window.removeEventListener("keyup",this._onSnapHoldKey),this._interactionElement.removeEventListener("pointerup",this._onFlyPointerUp),this._interactionElement.removeEventListener("pointermove",this._onFlyPointerMove),this._interactionElement.removeEventListener("wheel",this._onFlyWheel),this._interactionElement.removeEventListener("wheel",this._onTrackpadWheel),this._canvas.removeEventListener("pointerdown",this._onPointerDown),this._interactionElement.removeEventListener("pointermove",this._onPointerMove),this._onInteractionPointerUp&&this._interactionElement.removeEventListener("pointerup",this._onInteractionPointerUp),this._onInteractionDblClick&&this._interactionElement.removeEventListener("dblclick",this._onInteractionDblClick),this._canvas.removeEventListener("dragover",this._onDragOver),this._canvas.removeEventListener("dragleave",this._onDragLeave),this._canvas.removeEventListener("drop",this._onDrop),this.orbitControls.dispose();for(const e of this._allGizmos())e.dispose()}}_applyViewportLook(e){this._lookGridHex=e.grid??10066329;const t=this.grid.material.uniforms.uGrazingFade;if(t&&(t.value=e.background!==null?1:0),this._paintLookGrid(),this._lookAxisHexes=[e.axisX,e.axisY,e.axisZ],this._axisLines&&(this._axisLines.material.linewidth=this._axisLineCss(e.axisLineWidth)),this._verticalAxisLine&&(this._verticalAxisLine.material.linewidth=this._axisLineCss(e.axisLineWidth)),this._axisLineWidth=e.axisLineWidth,this._rebuildAxisLines(),e.background!==null){const i=this._scene.background,s=i===null||i instanceof V&&[this._lookBackgroundHex,e.background].includes(i.getHex());this._lookBackgroundHex=e.background,s&&this._paintLookBackground()}else this._lookBackgroundHex=null}bindPresentation(e,t){this._presentation?.stop();const i=new Xl(this._scene),s=i.roots();this._editorObjects.push(...s),Jn(e,t);const r=()=>{const l=Ti(e);this._renderer&&i.apply(l,this._renderer,void 0,{tone:!1,sky:!1,floor:!1}),this.setStageFunction(l.world,l.interaction),this.setFieldOfView(l.camera.fov),this.setSelectionMarks(l.overlays.selection),this.setGridMajorEvery(l.overlays.grid.majorEvery),this.setAxisLines(l.overlays.axes),this.setNavigation(l.overlays.navigation),this.setGridVisible(l.overlays.grid.visible),K()},n=Rr(r),a={rig:i,stop:()=>{n(),i.dispose(),this._editorObjects=this._editorObjects.filter(c=>!s.includes(c)),this._presentation===a&&(this._presentation=null);const l=this._lightRig&&!this._store.isAdoptedSceneActive;this._editorAmbient.visible=l,this._editorDirLight.visible=l}};return this._presentation=a,this._editorAmbient.visible=!1,this._editorDirLight.visible=!1,r(),a.stop}setSelectionMarks(e){const t=this._selectionMarks;t.outline===e.outline&&t.wire===e.wire&&t.box===e.box||(this._selectionMarks={outline:e.outline,wire:e.wire,box:e.box},this._syncBoxHelpers())}alignGridToView(e,t){const i=this.grid.material.uniforms,s=i.uPlaneNormal.value;let r=-1;e.isOrthographicCamera&&(e.getWorldDirection(as),r=[Math.abs(as.x),Math.abs(as.y),Math.abs(as.z)].findIndex(d=>d>1-1e-4),r!==-1&&!nu(Pi.set(0,1,0).applyQuaternion(e.getWorldQuaternion(gm)))&&(r=-1)),s.set(r===0?1:0,r===-1||r===1?1:0,r===2?1:0),this.grid.quaternion.setFromUnitVectors(ym,s),this.grid.position.set(0,0,0),this.grid.scale.setScalar(1);const n=i.uCenter.value;if(n.set(0,0),i.uReach.value=1,this._axisLines?.position.set(0,0,0),this._axisLines?.scale.setScalar(1),r!==-1){const h=e;e.getWorldPosition(Pi);const d=Pi.clone().addScaledVector(s,-Pi.dot(s));n.set(r===1||r===2?d.x:d.z,r===1?d.z:d.y);const p=Math.hypot(h.right-h.left,h.top-h.bottom)/(2*h.zoom),u=Math.max(1,p/(this.grid.geometry.parameters.width*.5*.55));i.uReach.value=u,this.grid.scale.setScalar(u),Pi.addScaledVector(as,h.far*.98);const f=s.clone().multiplyScalar(Pi.dot(s));this.grid.position.copy(d).add(f),this._axisLines?.position.copy(f),this._axisLines?.scale.setScalar(Math.max(1,(n.length()+p)/zo))}let a=1,l=1;if(r!==-1){const h=e,p=60*((h.right-h.left)/h.zoom)/Math.max(t,1);a=10**Math.floor(Math.log10(p)),l=1-(p-a)/(a*10-a)}i.uUnit.value=a,i.uMinorFade.value=l,i.uAligned.value=r===-1?0:1;const c=this._axisLineCss(r===-1?this._axisLineWidth:1);for(const h of[this._axisLines,this._verticalAxisLine]){const d=h?.material;d&&d.linewidth!==c&&(d.linewidth=c)}}setGridMajorEvery(e){const t=this.grid.material.uniforms.uMajorEvery;t&&Number.isFinite(e)&&e>=1&&(t.value=e)}_gridMajorContrast=1;_applyGridLines(e){const t=this.grid.material.uniforms;t.uLineWidth&&(t.uLineWidth.value=e.lineWidth),t.uMajorWidth&&(t.uMajorWidth.value=e.majorWidth),this._gridMajorContrast=e.majorContrast,this._paintLookGrid()}_paintLookGrid(){const e=this._lookGridHex;if(e===null)return;const t=this._lookBackgroundHex??4144959,i=a=>{const l=e>>a&255,c=t>>a&255;return Math.round(Math.min(255,Math.max(0,c+(l-c)*this._gridMajorContrast)))},s=i(16)<<16|i(8)<<8|i(0),r=dl(e,this._renderer),n=dl(s,this._renderer);this.grid.material.uniforms.uColor?.value?.copy(r),this.grid.material.uniforms.uMajorColor?.value?.copy(n)}_rebuildAxisLines(){const e=this._axisLines;if(!e)return;const t=this._stageAxisFrame,i=this._stageAxes,s=[0,1,2].filter(l=>{const c=t[l][0];return i==="floor"?l!==1:["x","y","z"].some((h,d)=>d===c&&i[h])});if(this._axesWanted=s.length>0,e.visible=this.grid.visible&&this._axesWanted,!this._axesWanted)return;const r=l=>{const c=[],h=[];for(const p of l){const u=t[p][0],f=this._lookAxisHexes[u],m=f==null?this._gizmoAxisColor(u):new V(f);c.push(...yl(p));for(let y=0;y<co*2;y++)h.push(m.r,m.g,m.b)}const d=new Fr;return d.setPositions(c),d.setColors(h),d},n=s.filter(l=>l!==1),a=s.includes(1);if(e.material.visible=n.length>0,n.length>0&&(e.geometry.dispose(),e.geometry=r(n)),a&&!this._verticalAxisLine){const l=e.material;this._verticalAxisLine=new Lr(r([1]),new Br({vertexColors:!0,linewidth:l.linewidth,transparent:!0,opacity:1,depthWrite:!1,toneMapped:!1})),this._verticalAxisLine.layers.set(Z),e.add(this._verticalAxisLine)}else a&&this._verticalAxisLine&&(this._verticalAxisLine.geometry.dispose(),this._verticalAxisLine.geometry=r([1]));this._verticalAxisLine&&(this._verticalAxisLine.visible=a)}setAxisLines(e){e===this._stageAxes||typeof e=="object"&&typeof this._stageAxes=="object"&&e.x===this._stageAxes.x&&e.y===this._stageAxes.y&&e.z===this._stageAxes.z||(this._stageAxes=typeof e=="object"?{x:e.x,y:e.y,z:e.z}:e,this._rebuildAxisLines())}_paintLookBackground(){if(this._lookBackgroundHex===null)return;const e=this._scene.background;e instanceof V&&e.getHex()===this._lookBackgroundHex||(this._scene.background=new V(this._lookBackgroundHex))}_syncLookBackground(){this._renderer&&(this._renderer.toneMapping===this._lookToneMapping&&this._renderer.toneMappingExposure===this._lookExposure||(this._paintLookGrid(),this._lookToneMapping=this._renderer.toneMapping,this._lookExposure=this._renderer.toneMappingExposure))}dispose(){this._unsubscribeKeymap(),this._disposed=!0,this._unsubscribeSelectionTheme(),this._verticalAxisLine&&(this._verticalAxisLine.geometry.dispose(),this._verticalAxisLine.material.dispose(),this._verticalAxisLine=null),this._axisLines&&(this._scene.remove(this._axisLines),this._axisLines.geometry.dispose(),this._axisLines.material.dispose(),this._axisLines=null),this.clearCameraView(),this._sparkRenderer&&(this._scene.remove(this._sparkRenderer),Zh(this._sparkRenderer),this._sparkRenderer=null),this.disconnectInput(),this._hideDropOverlay();for(const e of this._helpers.values())this._scene.remove(e);this._helpers.clear();for(const e of this._boxHelpers.values())this._scene.remove(e),e.geometry.dispose(),e.material.dispose();this._boxHelpers.clear();for(const e of this._reflectionProbeHelpers.values())e.dispose();this._reflectionProbeHelpers.clear();for(const e of this._triggerVolumeHelpers.values())e.dispose();this._triggerVolumeHelpers.clear();for(const e of this._constraintHelpers.values())e.dispose();this._constraintHelpers.clear();for(const{helper:e}of this._cameraHelpers.values())e.dispose();this._cameraHelpers.clear(),ll(this._spatialHandleRoots),this._spatialHandleRoots=[],this._spatialHandleMeshes=[]}_ensureSparkRenderer(){if(!this._renderer||this._sparkRenderer||this._sparkRendererLoading||this._sparkRendererFailed)return;const e=performance.now();Qh(this._lastSparkDiscoveryAt,e)&&(this._lastSparkDiscoveryAt=e,$h(this._scene)&&(this._sparkRendererLoading=!0,mi(async()=>{const{SparkRenderer:t}=await import("./spark.module-DMQ9J7rT.js");return{SparkRenderer:t}},__vite__mapDeps([0,1,2])).then(({SparkRenderer:t})=>{if(this._disposed||!this._renderer)return;const i=new t({renderer:this._renderer,enableLod:!1});i.traverse(s=>qe(s,"engineInternal",!0)),this._sparkRenderer=i,K()}).catch(t=>{this._sparkRendererFailed=!0,console.error("Failed to install SparkRenderer in the editor viewport.",t)}).finally(()=>{this._sparkRendererLoading=!1})))}_buildOrientationGizmo(){if(this._vcScene!==void 0){for(const e of[...this._vcScene.children]){this._vcScene.remove(e);const t=e;t.isSprite||t.geometry?.dispose();const i=t.material;i?.map?.dispose(),i?.dispose()}this._vcBalls.length=0,this._vcStalks.length=0,this._vcSolids.length=0,this._vcClickTargets.length=0,this._initOrientationGizmo()}}_initOrientationGizmo(){const e=this._gizmoLook.navigationForm;if(e!=="balls"&&e!=="godot"){this._initNavigationForm(e);return}const t=_t/3,i=oo/t,s=cm/t,r=ao/t/2,n=[new v(1,0,0),new v(0,1,0),new v(0,0,1)],a=new At(i*.6,8,8),l=new Ce({visible:!1});for(let c=0;c<3;c++){const[h,d]=this._stageAxisFrame[c],p=this._gizmoLook.navigation??this._gizmoLook.axes,u=p===null?new V(...Vn[h]):new V(p[h]),f=gl[h],m=n[c].clone().multiplyScalar(d);for(const y of[1,-1]){const _=m.clone().multiplyScalar(y),x=new T(new ke(r,r,s,8),new Ce({color:u,transparent:!0,depthTest:!1,toneMapped:!1}));x.position.copy(_).multiplyScalar(s/2),x.quaternion.setFromUnitVectors(new v(0,1,0),_),this._vcScene.add(x),this._vcStalks.push({mesh:x,direction:_.clone(),positive:y>0,color:u});const S=P=>{const E=new $n(new Ta({map:P,transparent:!0,depthTest:!1,toneMapped:!1}));return E.position.copy(_).multiplyScalar(s),E.scale.setScalar(i),this._vcScene.add(E),E},w=S(nm()),C=S(om()),b=S(am(y>0?f:`-${f}`));this._vcBalls.push({fill:w,ring:C,letter:b,direction:_.clone(),positive:y>0,axis:c,color:u});const M=new T(a,l);M.position.copy(w.position),qe(M,"vcDirIdx",c*2+(d*y>0?0:1)),this._vcScene.add(M),this._vcClickTargets.push(M)}}}_initNavigationForm(e){const t=_t/3,i=new v(0,1,0),s=[new v(1,0,0),new v(0,1,0),new v(0,0,1)],r=this._gizmoLook.navigation??this._gizmoLook.axes,n=(a,l,c,h)=>{const d=new $n(new Ta({map:rm(a,l),transparent:!0,depthTest:!1,toneMapped:!1}));d.position.copy(c),d.scale.setScalar(h/t),d.renderOrder=200,this._vcScene.add(d)};for(let a=0;a<3;a++){const[l,c]=this._stageAxisFrame[a],h=r===null?new V(...Vn[l]):new V(r[l]),d=gl[l],p=s[a].clone().multiplyScalar(c);if(e==="triad"){const u=this._gizmoLook.navigationSize??1,f=24*u/t,m=ao*Math.sqrt(u)/t/2,y=new T(new ke(m,m,f,6),new Ce({color:h,transparent:!0,depthTest:!1,toneMapped:!1}));y.position.copy(p).multiplyScalar(f/2),y.quaternion.setFromUnitVectors(i,p),this._vcScene.add(y),this._vcSolids.push({mesh:y,direction:p.clone()}),n(h,d,p.clone().multiplyScalar(f+7*u/t),12*u);continue}for(const u of[1,-1]){const f=p.clone().multiplyScalar(u),m=new T(new Kd(6/t,15/t,20),new Ce({color:u>0?h:new V(14277081),transparent:!0,depthTest:!1,toneMapped:!1}));m.position.copy(f).multiplyScalar(19/t),m.quaternion.setFromUnitVectors(i,f.clone().negate()),qe(m,"vcDirIdx",a*2+(c*u>0?0:1)),this._vcScene.add(m),this._vcSolids.push({mesh:m,direction:f.clone()}),this._vcClickTargets.push(m),u>0&&n(h,d.toLowerCase(),f.clone().multiplyScalar(34/t),12)}}if(e==="cones"){const a=new T(new xe(11/t,11/t,11/t),new Ce({color:12434877,transparent:!0,depthTest:!1,toneMapped:!1}));a.renderOrder=50,this._vcScene.add(a)}}_syncOrientationGizmoDepth(){const e=_t/3,t=this._vcDir.copy(this._vcCamera.position).normalize();if(this._gizmoLook.navigationForm==="godot"){this._syncGodotNavigation(t);return}const i=new V(this._gizmoLook.background??4013373),s=new V(1,1,1),r=(c,h,d,p)=>{const u=c.getRGB({r:0,g:0,b:0},rt),f=h.getRGB({r:0,g:0,b:0},rt);return p.setRGB(u.r+(f.r-u.r)*d,u.g+(f.g-u.g)*d,u.b+(f.b-u.b)*d,rt)};let n=-1;for(const{direction:c,axis:h}of this._vcBalls)1-c.dot(t)**2<1e-6&&(n=h);const a=new V,l=new V(0,0,0);for(const{fill:c,ring:h,letter:d,direction:p,positive:u,axis:f,color:m}of this._vcBalls){const y=p.dot(t),_=(y+1)/2,x=y<=.01*(u?-1:1),S=f===n&&!x,w=f===n&&x,C=r(i,m,(y+1)*.25+.5,new V),b=c.material,M=h.material,P=d.material,E=Math.min(y+1,1);u||S?(b.color.copy(C),b.opacity=1):(b.color.copy(r(i,m,.25,a)),b.opacity=E),!u&&S?(M.color.copy(r(s,m,.5,a)),M.opacity=E):(M.color.copy(C),M.opacity=1),P.color.copy(r(l,b.color,im,a)),c.visible=!w,h.visible=!w,d.visible=(u||f===n)&&!w;const R=(oo+hm*_)/e,N=10+Math.round(_*100)*3;for(const[se,ye]of[[c,0],[h,1],[d,2]])se.scale.setScalar(R),se.renderOrder=N+ye}for(const{mesh:c,direction:h,positive:d,color:p}of this._vcStalks){const u=h.dot(t),f=(u+1)/2,m=c.material;r(i,p,(.75+(u+1)*.25+.5)/2,m.color),m.opacity=1,c.visible=d||n!==-1,c.renderOrder=10+Math.round(f*100)*3-1}for(const{mesh:c,direction:h}of this._vcSolids)c.renderOrder=Math.round((h.dot(t)+1)/2*100)}_syncGodotNavigation(e){const i=16/(_t/3),s=r=>{const n=r.getRGB({r:0,g:0,b:0},rt);return new V().setRGB(n.r*.6,n.g*.6,n.b*.6,rt)};for(const{fill:r,ring:n,letter:a,direction:l,positive:c,color:h}of this._vcBalls){const d=(l.dot(e)+1)/2,p=Math.min(1,.35+d/.5*.65),u=r.material,f=n.material,m=a.material;u.color.copy(c?h:s(h)),u.opacity=p,f.color.copy(h),f.opacity=p,m.color.setRGB(0,0,0),m.opacity=p*.6,r.visible=!0,n.visible=!0,a.visible=c;const y=10+Math.round(d*100)*3;for(const[_,x]of[[r,0],[n,1],[a,2]])_.scale.setScalar(i),_.renderOrder=y+x}for(const{mesh:r,direction:n,positive:a,color:l}of this._vcStalks){const c=(n.dot(e)+1)/2,h=r.material;h.color.copy(l),h.opacity=Math.min(1,.35+c/.5*.65),r.visible=a,r.renderOrder=10+Math.round(c*100)*3-1}}_isOverViewCube(e,t){if(this._navigation!=="interactive"||this._gizmoLook.navigationForm==="triad")return!1;const i=this._canvas.getBoundingClientRect(),s=e-i.left,r=t-i.top,{left:n,top:a}=this._vcOrigin(i.width,i.height,this._chromeInsetPx);return s>=n&&s<=n+this._vcSize&&r>=a&&r<=a+this._vcSize}_vcOrigin(e,t,i){return this._gizmoLook.navigationCorner==="bottom-left"?{left:4+i,top:t-this._vcSize-48-i}:{left:e-this._vcSize-this._vcMarginRight-i,top:this._vcMarginTop+i}}setGridVisible(e){e!==this._presentationGrid&&(this._presentationGrid=e,this._applyGridVisibility())}_applyGridVisibility(){this.grid.visible=this._presentationGrid&&this._threeSurfaceShowing,this._axisLines&&(this._axisLines.visible=this.grid.visible&&this._axesWanted),K()}setNavigation(e){e!==this._navigation&&(this._navigation=e,K())}_handleViewCubeClick(e){if(!this._isOverViewCube(e.clientX,e.clientY))return!1;const t=this._canvas.getBoundingClientRect(),i=e.clientX-t.left,s=e.clientY-t.top,{left:r,top:n}=this._vcOrigin(t.width,t.height,this._chromeInsetPx),a=(i-r)/this._vcSize*2-1,l=-((s-n)/this._vcSize*2-1);this._vcRaycaster.setFromCamera(new je(a,l),this._vcCamera);const c=this._vcRaycaster.intersectObjects(this._vcClickTargets);if(c.length===0)return!0;const h=Oe(c[0].object,"vcDirIdx"),d=Qf[h];for(const f of[...this._axisViewListeners].reverse())if(f())break;const p=this.orbitControls;p._sphericalDelta.set(0,0,0),p._panOffset.set(0,0,0);const u=d.y>.5?new v(0,0,-1):d.y<-.5?new v(0,0,1):new v(0,1,0);return this._snapDist=this.freeCamera.position.distanceTo(this.orbitControls.target),this._snapQ1.copy(this.freeCamera.quaternion),this._snapQ2.setFromRotationMatrix(new Xt().lookAt(d,new v,u)),this._snapStartTime=performance.now(),this._snapAnimating=!0,!0}_flushGizmoToStoreLive(){this._skipNextSync=!0;const e=this._authoring(),t=(s,r)=>{s&&ua(e,s,{position:r.position.toArray(),rotation:r.quaternion.toArray(),scale:r.scale.toArray()})},i=this._activeGizmo.object;i&&i!==this._pivotDummy&&t(this._attachedAuthoringId??this._authoringIdForObject(i),i);for(const{id:s,obj:r}of this._otherDragObjects)t(s,r);for(const{id:s,obj:r}of this._allDragObjects)t(s,r);for(const{id:s,obj:r}of this._preservedChildObjects)t(s,r)}_preparePreservedChildren(e){if(!this._store.shell.preserveChildrenTransform)return[];const t=this._authoring(),i=new Set(e),s=new Map;for(const r of i){const n=this._preservedChildrenForParent(t,r,i,s);if(typeof n=="string")return et(n),[];for(const a of n)s.set(a.id,a)}return[...s.values()]}_preservedChildrenForParent(e,t,i,s){const r=[];for(const n of e.hierarchy.node(t)?.childIds??[]){if(i.has(n)||s.has(n))continue;const a=this._objectForAuthoringId(n);if(!a?.parent)continue;const l=this._unwritableTransformChannel(e,n);if(l){const c=e.hierarchy.node(n)?.label??n;return`Preserve Children Transform needs writable ${l} on ${c}. The parent will transform normally.`}a.updateWorldMatrix(!0,!1),r.push({id:n,obj:a,worldMatrix:a.matrixWorld.clone()})}return r}_unwritableTransformChannel(e,t){return["position","rotation","scale"].find(i=>!(e.transforms?.editability?.(t,i).writable??!1))}_restorePreservedChildren(){const e=new Xt;for(const t of this._preservedChildObjects){const i=t.obj.parent;i&&(i.updateWorldMatrix(!0,!1),e.copy(i.matrixWorld).invert().multiply(t.worldMatrix),e.decompose(t.obj.position,t.obj.quaternion,t.obj.scale),t.obj.updateMatrix(),t.obj.updateWorldMatrix(!1,!0))}}_belongsToRoots(e,t){let i=e;for(;i;){if(t.has(i))return!0;i=i.parent}return!1}_floorSnapPosition(e,t){e.updateWorldMatrix(!0,!0);const i=li(e);if(i.isEmpty())return null;const s=Math.min((i.max.x-i.min.x)*.1,.05),r=Math.min((i.max.z-i.min.z)*.1,.05),n=[[(i.min.x+i.max.x)/2,(i.min.z+i.max.z)/2],[i.min.x+s,i.min.z+r],[i.max.x-s,i.min.z+r],[i.min.x+s,i.max.z-r],[i.max.x-s,i.max.z-r]],a=new nt;a.layers.enableAll();const l=i.min.y+Math.max((i.max.y-i.min.y)*.001,.001);let c=Number.NEGATIVE_INFINITY;for(const[p,u]of n){a.set(new v(p,l,u),new v(0,-1,0));const f=a.intersectObjects(this._scene.children,!0).find(m=>!this._belongsToRoots(m.object,t)&&!gt(m.object)&&m.point.y<=l);f&&(c=Math.max(c,f.point.y))}if(!Number.isFinite(c))return null;const h=c-i.min.y;if(Math.abs(h)<1e-6)return null;const d=e.getWorldPosition(new v);return d.y+=h,e.parent?(e.parent.updateWorldMatrix(!0,!1),e.parent.worldToLocal(d)):d}snapSelectionToFloor(){const e=this._authoring(),t=e.transforms;if(!t){et("This document does not expose writable transforms.");return}const i=[...this._store.shell.selectedEntityIds].map(l=>({id:l,obj:this._objectForAuthoringId(l)})).filter(l=>!!l.obj&&(t.editability?.(l.id,"position").writable??!0)),s=new Set(i.map(({obj:l})=>l)),r=i.filter(({obj:l})=>{let c=l.parent;for(;c;){if(s.has(c))return!1;c=c.parent}return!0});if(r.length===0){et("Select an object with a writable position first.");return}const n=new Set(r.map(({obj:l})=>l)),a=[];for(const l of r){const c=this._floorSnapPosition(l.obj,n);c&&a.push({...l,position:c})}if(a.length===0){et("No solid scene surface was found beneath the selection.");return}for(const{id:l}of a)da(e,l);for(const{obj:l,position:c}of a)l.position.copy(c);this._skipNextSync=!0;for(const{id:l,obj:c}of a)ua(e,l,{position:c.position.toArray(),rotation:c.quaternion.toArray(),scale:c.scale.toArray()});for(const{id:l}of a)pa(e,l);this.syncFromStore()}_applySurfaceSnap(e,t){const i=new Set,s=this._attachedAuthoringId??this._authoringIdForObject(e);s&&i.add(s);for(const{id:c}of t)i.add(c);const r=[];for(const[c,h]of this._objectMap)i.has(c)||r.push(h);if(r.push(this.grid),r.length===0){this._surfaceSnapIndicator.visible=!1;return}const n=e.position.clone();n.y+=50,this._surfaceSnapRaycaster.set(n,new v(0,-1,0)),this._surfaceSnapRaycaster.far=200;const l=this._surfaceSnapRaycaster.intersectObjects(r,!0).find(c=>c.object===this.grid||!gt(c.object));if(l){const c=l.point,h=c.y,d=h-e.position.y;e.position.y=h;for(const{obj:u}of t)u.position.y+=d;this._surfaceSnapIndicator.position.copy(c),this._surfaceSnapIndicator.position.y+=.01;const p=l.face?.normal;if(p){const u=p.clone().transformDirection(l.object.matrixWorld);this._surfaceSnapIndicator.quaternion.setFromUnitVectors(new v(0,1,0),u)}this._surfaceSnapIndicator.visible=!0}else this._surfaceSnapIndicator.visible=!1}_collectVertices(e){const t=[];for(const[s,r]of this._objectMap)e.has(s)||r.traverse(n=>{if(gt(n))return;const a=n;if(!a.isMesh||!a.geometry)return;const l=a.geometry.getAttribute("position");if(!l)return;const c=Math.min(l.count,1e3),h=a.matrixWorld;for(let d=0;d<c;d++){const p=new v(l.getX(d),l.getY(d),l.getZ(d));p.applyMatrix4(h),t.push(p)}});return t}_applyVertexSnap(e,t){const i=e.position,s=i.clone().project(this._screenCamera),r=this._canvas.getBoundingClientRect(),n=(s.x+1)/2*r.width,a=(-s.y+1)/2*r.height;let l=this._vertexSnapThreshold,c=null;for(const h of this._vertexSnapTargets){const d=h.clone().project(this._screenCamera);if(d.z>1)continue;const p=(d.x+1)/2*r.width,u=(-d.y+1)/2*r.height,f=n-p,m=a-u,y=Math.sqrt(f*f+m*m);y<l&&(l=y,c=h)}if(c){const h=c.clone().sub(i);e.position.copy(c);for(const{obj:p}of t)p.position.add(h);this._vertexSnapIndicator.position.copy(c),this._vertexSnapIndicator.visible=!0;const d=c.distanceTo(this._screenCamera.position);this._vertexSnapIndicator.scale.setScalar(d*.008)}else this._vertexSnapIndicator.visible=!1}_flushGizmoToStore(){this._flushGizmoToStoreLive();const e=this._activeTransformEditIds;this._activeTransformEditIds=[],this._otherDragObjects=[],this._allDragObjects=[],this._preservedChildObjects=[];const t=this._authoring();for(const i of e)pa(t,i)}consumeSkipSync(){return this._skipNextSync?(this._skipNextSync=!1,!0):!1}_applyGizmoSize(){if(this.transformControls===void 0)return;const e=this._lookGizmoSizePx,t=Math.max(1,this._canvas.clientHeight),i=e===null?null:2*e,s=i===null?1:this.transformControls.camera.isOrthographicCamera?4*i/t:i/(.2375*t);for(const r of this._allGizmos())r.size=s}_dropNegativeAxisHandles(e,t){const i=e.children.find(r=>r.isTransformControlsGizmo);if(!i)return;const s={X:new v(1,0,0),Y:new v(0,1,0),Z:new v(0,0,1)};for(const r of t)for(const n of[i.gizmo[r],i.picker[r]])if(n)for(const a of[...n.children]){const l=s[a.name];if(l===void 0)continue;const c=a;if(!c.geometry)continue;c.geometry.computeBoundingBox();const h=c.geometry.boundingBox;h&&h.getCenter(new v).dot(l)<0&&n.remove(a)}}_axisColorMap(){const e=r=>this._gizmoAxisColor(this._stageAxisFrame[r][0]),t=e(0),i=e(1),s=e(2);return{X:t,Y:i,Z:s,XY:s,YZ:t,XZ:i}}_readLookStage(e){this._applyGizmoAxisFrame(),this._buildOrientationGizmo()}setStageFunction(e,t){this._stageBoxSelect=t.boxSelect;const i=t.transformHandles;(i.scale!==this._transformHandles.scale||i.viewRotate!==this._transformHandles.viewRotate||i.freeMove!==this._transformHandles.freeMove)&&(this._transformHandles={scale:i.scale,viewRotate:i.viewRotate,freeMove:i.freeMove},this._syncCombinedGizmoHalves(),K());const s=e.upAxis==="z"?e.handedness==="left"?Kf:$f:ml;s!==this._stageAxisFrame&&(this._stageAxisFrame=s,this._applyGizmoAxisFrame(),this._buildOrientationGizmo(),this._rebuildAxisLines())}_applyGizmoAxisFrame(){if(this.transformControls===void 0)return;const e=this._stageAxisFrame.map(([,a])=>a),t=[0,1,2].map(a=>e[a]===this._appliedAxisSigns[a]?1:-1),i=t.some(a=>a===-1),s=this._axisColorMap(),r={X:this._gizmoAxisColor(0),Y:this._gizmoAxisColor(1),Z:this._gizmoAxisColor(2),XY:this._gizmoAxisColor(2),YZ:this._gizmoAxisColor(0),XZ:this._gizmoAxisColor(1)},n=(a,l,c,h,d)=>{a&&a.traverse(p=>{const u=p;c&&u.geometry&&u.geometry.scale(t[0],t[1],t[2]),h&&u.material&&!Array.isArray(u.material)&&!u.userData.vgaiOwnMaterial&&(u.material=u.material.clone(),u.userData.vgaiOwnMaterial=!0);const f=u.material;if(!f||Array.isArray(f))return;c&&(f.side=di);const m=l[p.name];if(m&&f.color){if(d){const y=f.userData.vgaiBaseOpacity??=f.opacity;f.opacity=y*(this._gizmoLook.opacity??1),f._opacity=void 0}f.color.copy(m),f._color=void 0}})};for(const a of this._allGizmos()){const l=a.getHelper().children.find(c=>c.isTransformControlsGizmo);if(l)for(const c of["gizmo","picker","helper"]){const h=c==="gizmo";n(l[c]?.translate,s,i,!1,h),n(l[c]?.rotate,s,!1,!1,h),n(l[c]?.scale,r,!1,!0,h)}}i&&(this._appliedAxisSigns=e)}_gizmoAxisColor(e){const t=this._gizmoLook.axes;return t===null?new V().setRGB(...Vn[e],rt):new V(t[e])}_installGizmoHighlight(e){const t=e.getHelper().children.find(s=>s.isTransformControlsGizmo);if(!t)return;const i=t.updateMatrixWorld.bind(t);t.updateMatrixWorld=s=>{i(s);const r=this._store.shell.transformMode==="combined",n=t.mode==="translate"&&!this._transformHandles.freeMove?"XYZ":r&&t.mode==="rotate"&&!this._transformHandles.viewRotate?"E":null;if(n!==null)for(const h of[t.gizmo,t.picker])for(const d of h[t.mode]?.children??[])d.name===n&&(d.visible=!1);const a=this._gizmoLook,l=t.axis;if(!t.enabled||!l||a.hover===null&&a.axes===null&&a.highlightSaturation===null&&a.highlightValue===null)return;const c=t.dragging?a.drag??a.hover:a.hover;for(const h of t.gizmo[t.mode]?.children??[]){if(h.name!==l&&!l.split("").some(y=>h.name===y))continue;const d=h.material;if(!d||Array.isArray(d)||!d.color)continue;if(c!==null){d.color.setHex(c);continue}const p=(d._color??d.color).clone().convertLinearToSRGB(),u=em(p),f=u.s*(a.highlightSaturation??1),m=a.highlightValue??u.v;tm(u.h,f,m,d.color).convertSRGBToLinear()}}}_applyGizmoArrows(){if(this.transformControls===void 0)return;this._applyGizmoRings();const e={length:this._gizmoLook.arrowLength??1.2,head:this._gizmoLook.arrowHead??1},t=this._appliedArrow;if(e.length===t.length&&e.head===t.head)return;const i=.5,s=.1,r=p=>i*p.length-s*p.head;if(r(e)<=.05)return;const n=r(e)/r(t),a=e.head/t.head,l=e.length/t.length,c=this.transformControls.getHelper().children.find(p=>p.isTransformControlsGizmo);if(!c)return;const h={X:0,Y:1,Z:2},d=(p,u)=>[0,1,2].map(f=>f===p?u:1);for(const p of c.gizmo.translate?.children??[]){const u=h[p.name],f=p.geometry;if(u===void 0||!f)continue;if(!(f.parameters?.radiusTop===0)){f.scale(...d(u,n));continue}f.computeBoundingBox();const _=f.boundingBox,x=[_.min.x,_.min.y,_.min.z][u],S=[_.max.x,_.max.y,_.max.z][u],w=Math.abs(x)<Math.abs(S)?x:S,C=[0,0,0];C[u]=-w,f.translate(...C),f.scale(a,a,a),C[u]=w*n,f.translate(...C)}for(const p of c.picker.translate?.children??[]){const u=h[p.name],f=p.geometry;u===void 0||!f||f.scale(...d(u,l))}this._appliedArrow=e}_applyGizmoRings(){const e=this._gizmoLook.ringWidth??1;if(e<=0||e===this._appliedRingWidth)return;const t=e/this._appliedRingWidth,i=new v,s=new v,r=new v;for(const n of[this.transformControls,this._auxRotateControls]){const a=n.getHelper().children.find(l=>l.isTransformControlsGizmo);for(const l of a?.gizmo.rotate?.children??[]){const c=l.geometry;if(!["X","Y","Z"].includes(l.name)||!c||c.type!=="TorusGeometry")continue;const h=c.parameters.radius;c.computeBoundingBox(),c.boundingBox.getSize(r);const d=r.x<=r.y&&r.x<=r.z?0:r.y<=r.z?1:2,p=c.getAttribute("position");for(let u=0;u<p.count;u++)i.fromBufferAttribute(p,u),s.copy(i).setComponent(d,0),s.lengthSq()!==0&&(s.setLength(h),i.sub(s).multiplyScalar(t).add(s),p.setXYZ(u,i.x,i.y,i.z));p.needsUpdate=!0,c.computeBoundingSphere()}}this._appliedRingWidth=e}_patchGizmo(e){const t=this._axisColorMap(),i={XY:[-.075,-.075,0],YZ:[0,-.075,-.075],XZ:[-.075,0,-.075]};e.traverse(s=>{const r=s,n=t[s.name];if(n&&r.material){const l=r.material;l.color&&l.color.copy(n)}const a=i[s.name];a&&r.geometry&&r.geometry.translate(a[0],a[1],a[2])})}_patchCombinedScaleGizmo(e){const i=e.children.find(a=>a.isTransformControlsGizmo);if(!i)return;const s={X:new v(1,0,0),Y:new v(0,1,0),Z:new v(0,0,1)},r=.54+.55,n=.3;for(const[a,l]of[[i.gizmo.scale,!1],[i.picker.scale,!0]])if(a)for(const c of[...a.children]){const h=c,d=s[c.name],p=d!==void 0&&h.geometry?.type==="CylinderGeometry"&&h.geometry.parameters.radiusTop<.05;if(d===void 0||p){a.remove(c);continue}h.geometry.computeBoundingBox();const u=h.geometry.boundingBox;if(!u)continue;const f=Math.sign(u.getCenter(new v).dot(d))||1;if(l){const y=d.clone().multiplyScalar(f*r);h.geometry.dispose(),h.geometry=new xe(n,n,n).translate(y.x,y.y,y.z);continue}const m=d.clone().multiplyScalar(f*.55);h.geometry.translate(m.x,m.y,m.z)}}_projectToScreen(e){const t=new v;e.getWorldPosition(t),t.project(this._screenCamera);const i=this._canvas.getBoundingClientRect();return new je((t.x+1)/2*i.width+i.left,(-t.y+1)/2*i.height+i.top)}static _FLY_KEYS=new Set(["w","a","s","d","q","e"]);_enterFlyMode(){this._flyActive||this._cameraViewMode!=="view"&&(this._flyActive=!0,this._snapAnimating=!1,this.orbitControls.enabled=!1,this._flyEuler.setFromQuaternion(this.renderCamera.quaternion,"YXZ"),this.orbitControls.dispatchEvent({type:"start"}),this._canvas.requestPointerLock?.())}_exitFlyMode(){if(!this._flyActive)return;this._flyActive=!1,this._flyKeys.clear(),this.orbitControls.enabled=this._cameraViewMode!=="view",document.exitPointerLock();const e=this.renderCamera,t=new v(0,0,-1).applyQuaternion(e.quaternion),i=e.position.distanceTo(this.orbitControls.target);this.orbitControls.target.copy(e.position).add(t.multiplyScalar(Math.max(i,5))),this.orbitControls.dispatchEvent({type:"end"})}_updateFlyCamera(e){if(!this._flyActive||this._flyKeys.size===0)return;const t=this.renderCamera,i=this._flySpeed*(this._flyKeys.has("shift")?3:1),s=new v(0,0,-1).applyQuaternion(t.quaternion),r=new v(1,0,0).applyQuaternion(t.quaternion),n=new v;this._flyKeys.has("w")&&n.add(s),this._flyKeys.has("s")&&n.sub(s),this._flyKeys.has("d")&&n.add(r),this._flyKeys.has("a")&&n.sub(r),this._flyKeys.has("e")&&(n.y+=1),this._flyKeys.has("q")&&(n.y-=1),n.lengthSq()>0&&(n.normalize().multiplyScalar(i*e),t.position.add(n),this.orbitControls.dispatchEvent({type:"change"}))}_onFlyKeyDown=e=>{if(!this._rightMouseDown||e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement)return;const t=e.key.toLowerCase();if(t==="shift"){this._flyKeys.add("shift");return}Oo._FLY_KEYS.has(t)&&(e.preventDefault(),e.stopPropagation(),this._flyKeys.add(t),this._flyActive||this._enterFlyMode())};_onFlyKeyUp=e=>{const t=e.key.toLowerCase();if(t==="shift"){this._flyKeys.delete("shift");return}this._flyKeys.delete(t)};_onFlyPointerDown=e=>{e.button===2&&(this._rightMouseDown=!0)};_onFlyPointerUp=e=>{e.button===2&&(this._rightMouseDown=!1,this._flyActive&&this._exitFlyMode())};_onFlyPointerMove=e=>{if(!this._flyActive)return;const t=.002;this._flyEuler.y-=e.movementX*t,this._flyEuler.x-=e.movementY*t,this._flyEuler.x=Math.max(-Math.PI/2+.01,Math.min(Math.PI/2-.01,this._flyEuler.x)),this.renderCamera.quaternion.setFromEuler(this._flyEuler),this.orbitControls.dispatchEvent({type:"change"})};_onTrackpadWheel=e=>{if(this._flyActive||!this.orbitControls.enabled||e.ctrlKey||Math.abs(e.deltaX)<.5&&!e.shiftKey)return;e.preventDefault(),e.stopImmediatePropagation();const t=this._interactionElement.clientHeight||1,i=this.camera.position.distanceTo(this.orbitControls.target),s=2*Math.tan(this.camera.fov/2*Math.PI/180)*i/t,r=e.deltaMode===1?16:1,n=h=>Math.sign(h)*Math.min(Math.abs(h*r),30),a=new v().setFromMatrixColumn(this.camera.matrix,0),l=new v().setFromMatrixColumn(this.camera.matrix,1),c=a.multiplyScalar(n(e.deltaX)*s).add(l.multiplyScalar(-n(e.deltaY)*s));this.camera.position.add(c),this.orbitControls.target.add(c),this.orbitControls.update()};_onFlyWheel=e=>{if(!this._flyActive)return;e.preventDefault();const t=e.deltaY>0?.85:1.18;this._flySpeed=Math.max(.5,Math.min(100,this._flySpeed*t))};_onPointerDown=e=>{if(this._pointerDownPos.set(e.clientX,e.clientY),this._pointerDownButton=e.button,this._marqueeActive=!1,this._pointerSessionActive=!0,this._constraintControlPointerSession=!1,e.button===0&&!e.altKey){if(this._selectConstraintControlAt(e))return;const t=this._raycastSpatialHandle(e),i=t?ol(t):null;if(t&&i?.handle.writable){e.stopPropagation(),this._activeSpatialHandle=i,this._spatialHandleDragPoint.copy(t.position),this._orbitEnabledBeforeHandleDrag=this.orbitControls.enabled,this._transformEnabledBeforeHandleDrag=this.transformControls.enabled,this.orbitControls.enabled=!1;for(const n of this._allGizmos())n.enabled=!1;const s=this._screenCamera.getWorldDirection(new v);this._spatialHandleDragPlane.setFromNormalAndCoplanarPoint(s,t.position),this._spatialHandleDragOffset.set(0,0,0);const r=this._spatialHandleWorldPoint(e);r&&this._spatialHandleDragOffset.subVectors(t.position,r),this._canvas.style.cursor="grabbing"}}};_onPointerMove=e=>{if(this._updateEditorHandleInteraction(e)||(this._updateSpatialHandleHover(e),!this._pointerSessionActive)||!(e.buttons&1)||this._pointerDownButton!==0||this._anyGizmoDragging()||this._altDragOrbit)return;const t=e.clientX-this._pointerDownPos.x,i=e.clientY-this._pointerDownPos.y;if(!this._marqueeActive&&Math.sqrt(t*t+i*i)>5){if(this._isOverViewCube(this._pointerDownPos.x,this._pointerDownPos.y))return;this._marqueeActive=!0,this.orbitControls.enabled=!1,this._marqueeDiv||(this._marqueeDiv=document.createElement("div"),Object.assign(this._marqueeDiv.style,{position:"fixed",border:`1px solid ${vt.accent.default}`,background:vt.accent.muted,pointerEvents:"none",zIndex:fa.sticky}),(document.getElementById("editor-chrome-root")??document.body).appendChild(this._marqueeDiv))}if(this._marqueeActive&&this._marqueeDiv){const s=Math.min(this._pointerDownPos.x,e.clientX),r=Math.min(this._pointerDownPos.y,e.clientY),n=Math.abs(e.clientX-this._pointerDownPos.x),a=Math.abs(e.clientY-this._pointerDownPos.y);Object.assign(this._marqueeDiv.style,{left:`${s}px`,top:`${r}px`,width:`${n}px`,height:`${a}px`,display:"block"})}};_onPointerUp=e=>{if(!this._pointerSessionActive)return;if(this._pointerSessionActive=!1,this._activeSpatialHandle){this._finishSpatialHandleDrag(!0);return}if(this._constraintControlPointerSession){this._constraintControlPointerSession=!1;return}if(this._marqueeActive){this._marqueeActive=!1,this.orbitControls.enabled=!0,this._marqueeDiv&&(this._marqueeDiv.style.display="none");const n=Math.min(this._pointerDownPos.x,e.clientX),a=Math.max(this._pointerDownPos.x,e.clientX),l=Math.min(this._pointerDownPos.y,e.clientY),c=Math.max(this._pointerDownPos.y,e.clientY),h=[],d=new v,p=new wt;for(const[u,f]of this._objectMap){if(!f.visible||f.isCamera===!0)continue;if(p.setFromObject(f),p.isEmpty()){const P=this._projectToScreen(f);P.x>=n&&P.x<=a&&P.y>=l&&P.y<=c&&h.push(u);continue}const m=this._stageBoxSelect==="touch",y=this._canvas.getBoundingClientRect(),_=this._screenCamera;let x=!0,S=Number.POSITIVE_INFINITY,w=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY,b=Number.NEGATIVE_INFINITY;for(let P=0;P<8;P++){if(d.set(P&1?p.max.x:p.min.x,P&2?p.max.y:p.min.y,P&4?p.max.z:p.min.z),d.project(_),d.z<-1||d.z>1){if(x=!1,!m)break;continue}const E=y.left+(d.x+1)*y.width/2,R=y.top+(1-d.y)*y.height/2;(E<n||E>a||R<l||R>c)&&(x=!1),S=Math.min(S,E),w=Math.max(w,E),C=Math.min(C,R),b=Math.max(b,R)}const M=S<=w&&w>=n&&S<=a&&b>=l&&C<=c;(m?M:x)&&h.push(u)}if(e.shiftKey)for(const u of h)this._store.shell.addToSelection(u);else cs(this._authoring(),h);return}if(e.button!==0)return;const t=e.clientX-this._pointerDownPos.x,i=e.clientY-this._pointerDownPos.y;if(Math.sqrt(t*t+i*i)>5||this._anyGizmoDragging()||this._threejsToolContextActive&&this._handleViewCubeClick(e))return;const s=e.shiftKey&&(e.metaKey||e.ctrlKey),r=th(this._scopeAuthoring(),()=>this._pickAt(e.clientX,e.clientY,s?"deep":"normal"));s?cs(this._authoring(),r?[r]:[]):e.shiftKey&&r?this._store.shell.toggleSelection(r):(e.metaKey||e.ctrlKey)&&r?this._store.shell.toggleSelection(r):cs(this._authoring(),r?[r]:[])};_scopeAuthoring(){return this._standaloneAuthoring?this._authoring():yr().panelAuthoring(this._store.shell)}_pickAt(e,t,i){return this._pick?this._pick(e,t):yr().pick(this._store.shell,e,t,i)}_onDoubleClick=e=>{if(e.button!==0||this._anyGizmoDragging()||this._marqueeActive||this._threejsToolContextActive&&this._isOverViewCube(e.clientX,e.clientY))return;const t=this._pickAt(e.clientX,e.clientY,"normal");t&&ih(this._scopeAuthoring(),t,()=>this._pickAt(e.clientX,e.clientY,"normal"))};_raycastGroundPlane(e){const t=this._canvas.getBoundingClientRect(),i=new je((e.clientX-t.left)/t.width*2-1,-((e.clientY-t.top)/t.height)*2+1);this.raycaster.setFromCamera(i,this._screenCamera);const s=ma("three");this._groundPlane.set(s.up==="z"?Jf:qf,-s.groundHeight);const r=new v;return this.raycaster.ray.intersectPlane(this._groundPlane,r)}_showDropOverlay(){if(this._dropOverlay)return;const e=document.createElement("div");Object.assign(e.style,{position:"fixed",inset:"0",pointerEvents:"none",border:`2px dashed ${vt.accent.default}`,background:vt.accent.muted,zIndex:fa.base}),(document.getElementById("editor-chrome-root")??document.body).appendChild(e),this._dropOverlay=e}_hideDropOverlay(){this._dropOverlay&&(this._dropOverlay.remove(),this._dropOverlay=null)}_onDragOver=e=>{e.dataTransfer?.types.includes("application/x-editor-asset")&&(e.preventDefault(),e.dataTransfer.dropEffect="copy",this._showDropOverlay())};_onDragLeave=e=>{this._hideDropOverlay()};_onDrop=e=>{this._hideDropOverlay();const t=e.dataTransfer?.getData("application/x-editor-asset");if(!t)return;e.preventDefault();let i;try{i=JSON.parse(t)}catch{return}const s=ma("three"),r=this._raycastGroundPlane(e),n=d=>Math.round(d*100)/100,a=s.up==="z"?[n(r?.x??0),n(r?.y??0),s.groundHeight]:[n(r?.x??0),s.groundHeight,n(r?.z??0)],l=this._authoring(),c=l.assetDrop,h=i.component??{kind:"file",name:i.name};if(!c){Oi.warn(`Dropped “${i.name}” was not placed: this document does not accept dropped assets.`,"editor");return}if(i.online){const d=i.online,p=this._onlineAssetResolver;if(!p){Oi.warn(`Dropped “${i.name}” was not placed: this viewport has no online-asset resolver installed.`,"editor");return}et(`Downloading ${d.name} from the library…`),p(d).then(u=>{u?(et(`${d.name} downloaded — placing it.`),ga(l,"",u,{position:a})):et(`Could not download ${d.name} — see the Console.`)}).catch(()=>{et(`Could not download ${d.name} — see the Console.`),Oi.error(`Could not download ${d.name}.`,"asset")});return}ga(l,"",i.path,{position:a,item:h})}}class vm extends Ve{constructor(e,t){super(),this.bones=e;const i=new Set;for(const a of e){const l=a.parent;l?.isBone&&this.addSegment(l,a,i);for(const c of a.children)c.isBone&&this.addSegment(a,c,i)}this.linePositions=new Float32Array(Math.max(this.segments.length*6,6));const s=new Fr;s.setPositions(this.linePositions),this.lineMaterial=new Br({color:t,linewidth:5,worldUnits:!1,depthTest:!1,depthWrite:!1,toneMapped:!1,alphaToCoverage:!0}),this.lines=new Lr(s,this.lineMaterial),this.lines.onBeforeRender=a=>{a.getSize(this.lineMaterial.resolution)},this.lines.frustumCulled=!1,this.lines.renderOrder=1001,this.add(this.lines),this.pointPositions=new Float32Array(Math.max(e.length*3,3));const r=new Et;r.setAttribute("position",new mt(this.pointPositions,3));const n=new ic({color:t,size:11,sizeAttenuation:!1,depthTest:!1,depthWrite:!1,toneMapped:!1});this.points=new mo(r,n),this.points.frustumCulled=!1,this.points.renderOrder=1002,this.add(this.points),this.name="__object3d_document_bone_selection",Qn(this,"editorHelper",!0),this.traverse(a=>a.layers.set(Z)),this.update()}segments=[];linePositions;pointPositions;lines;lineMaterial;points;worldPosition=new v;setColor(e){this.lineMaterial.color.setHex(e),this.points.material.color.setHex(e)}update(){let e=0;for(const[s,r]of this.segments)s.getWorldPosition(this.worldPosition),this.linePositions.set(this.worldPosition.toArray(),e),r.getWorldPosition(this.worldPosition),this.linePositions.set(this.worldPosition.toArray(),e+3),e+=6;const t=this.lines.geometry.getAttribute("instanceStart");t&&(t.data.needsUpdate=!0),e=0;for(const s of this.bones)s.getWorldPosition(this.worldPosition),this.pointPositions.set(this.worldPosition.toArray(),e),e+=3;const i=this.points.geometry.getAttribute("position");i&&(i.needsUpdate=!0)}dispose(){this.lines.geometry.dispose(),this.lineMaterial.dispose(),this.points.geometry.dispose(),this.points.material.dispose()}addSegment(e,t,i){const s=`${e.uuid}:${t.uuid}`;i.has(s)||(i.add(s),this.segments.push([e,t]))}}const wm="skeletons",jn=new V(58879),Gn=new V(16756736);function xm(o){const e=o.geometry.getAttribute("color");for(let i=0;i<e.count;i+=2)e.setXYZ(i,jn.r,jn.g,jn.b),i+1<e.count&&e.setXYZ(i+1,Gn.r,Gn.g,Gn.b);e.needsUpdate=!0,o.renderOrder=999;const t=o.material;t.depthTest=!1,t.depthWrite=!1,t.toneMapped=!1,Qn(o,"editorHelper",!0),Qn(o,"editorHelperType",wm),o.traverse(i=>i.layers.set(Z))}const _l=o=>!qs(o),bm=1,Sm=700,Mm=.001,Cm=Math.PI-.001,Pm=o=>o<.5?4*o*o*o:1-(-2*o+2)**3/2,Am=o=>o;function Ai(o,e){return typeof o=="number"&&Number.isFinite(o)?o:e}const vl={mode:"solid",background:"neutral",projection:"perspective",skeleton:!1,bounds:!1},wl=1119773;class Em{constructor(e,t,i,s,r,n,a=new V(2106410),l=null){this.documentId=e,this.root=t,this.scene=i,this.renderer=s,this.viewport=r,this.authoring=n,this.neutralBackground=a,this.frameBox=l,this.unsubscribeSelectionTheme=Xr(s.domElement,this.syncSelectionTheme),r.orbitControls.addEventListener("start",this.cancelLookForHuman),this.unsubscribeRotateStart=r.onRotateStart(this.autoPerspective),this.unsubscribeAxisView=r.onAxisView(this.axisView)}profiler=bu();shading=new Au;helpers=[];skeletonHelper=null;boundsHelper=null;boneSelectionHighlight=null;boneSelectionSignature="";composer=null;composerLoading=!1;disposed=!1;sceneRenderPass=null;selectionOutline=null;selectionOutlinePass=null;selectedObjects=[];selectionOrigins=null;renderWidth=1;renderHeight=1;orthographicCamera=new Fi;captureAspect=null;cameraOverride=null;cameraViewSource=null;through=null;leaving=!1;viewMemo=null;throughPerspective=new yo;throughOrthographic=new Fi;beforeRender=null;state=vl;version=0;listeners=new Set;unsubscribeSelectionTheme=()=>{};flight=null;flightPose=new v;topologyOverlay=null;topologyFollowers=[];unsubscribeRotateStart;unsubscribeAxisView;axisView=()=>(this.leaveCameraView(!1),this.settleFlight("superseded"),Ze().autoPerspective&&this.setProjection("orthographic"),!0);autoPerspective=()=>{if(!Ze().autoPerspective||this.cameraView()!==null||this.state.projection!=="orthographic")return;const e=this.viewport.camera,t=e.position.clone().sub(this.viewport.orbitControls.target),i=new v(0,1,0).applyQuaternion(e.quaternion);Bi(t,i)!==null&&this.setProjection("perspective")};replaceContent(e,t){K(),this.selectionOutline?.selection.clear(),this.selectedObjects=[],this.boneSelectionSignature="",this.clearBoneSelectionHighlight(),this.clearSkeletonHelper(),this.clearBoundsHelper(),this.clearTopologyOverlay(),this.root=e,this.authoring=t,this.state.mode==="wireframe"&&this.buildTopologyOverlay(),this.state.bounds&&(this.boundsHelper=new ka(e,16757844),this.addHelper(this.boundsHelper,"bounds")),this.syncSelectionPresentation(),this.refreshSkeletonHelper(),this.notify()}cancelLookForHuman=()=>{this.settleFlight("human")};selectionColors=null;syncSelectionTheme=()=>{this.selectionColors=Qe(this.renderer.domElement);const e=this.selectionColors.visible;this.selectionOutline&&Ff(this.selectionOutline,Qe(this.renderer.domElement)),this.boneSelectionHighlight?.setColor(e)};subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));getSnapshot=()=>this.version;presentation(){return this.state}resolveFrameBounds(e="selection"){const t=e==="all"?[]:this.authoring?.selection?.get()??[];if(t.length>0){const i=new wt;let s=!1;for(const r of t){const n=this.authoring?oi(this.authoring.hierarchy,r):null;if(!n)continue;const a=li(n);a.isEmpty()||(i.union(a),s=!0)}if(s)return i}return this.frameBox&&!this.frameBox.isEmpty()?this.frameBox:li(this.root)}frame(e=1,t="selection"){this.leaveCameraView(!1);const i=this.resolveFrameBounds(t);if(i.isEmpty()){let l=0,c=0;return this.root.traverse(h=>{const d=h.geometry;d&&(l+=1,c+=d.getAttribute("position")?.count??0)}),Oi.warn(`frame: nothing to frame — root "${this.root.name}" (${this.root.children.length} children, ${l} meshes, ${c} positions), selection ${JSON.stringify(this.authoring?.selection?.get()??[])}, frameBox ${this.frameBox?this.frameBox.isEmpty()?"empty":"set":"none"}`,"document"),!1}this.settleFlight("superseded");const s=i.getCenter(new v),r=this.viewport.camera.position.clone().sub(this.viewport.orbitControls.target).normalize();r.lengthSq()===0&&r.set(.8,.5,-1).normalize();const n=Math.min(10,Math.max(.1,Ai(e,1))),a=hi(i,this.viewport.camera,r)*n;return this.viewport.setPose(s.clone().addScaledVector(r,a),s),!0}orbit(e){return this.launchFlight(Ai(e.azimuth,0),Ai(e.elevation,0),Math.min(60,Math.max(0,Ai(e.duration,.6))),Pm)}turntable(e){const t=Ai(e.revolutions,1);return this.launchFlight(t*Math.PI*2,0,Math.min(60,Math.max(0,Ai(e.seconds,6))),Am)}looking(){return this.flight!==null}launchFlight(e,t,i,s){this.settleFlight("superseded");const r=this.viewport.camera,n=this.viewport.orbitControls.target.clone(),a=new eu().setFromVector3(r.position.clone().sub(n)),l=a.radius>1e-4?a.radius:Math.max(this.resolveFrameBounds().getSize(new v).length(),1),c={pivot:n,radius:l,startTheta:a.theta,startPhi:a.phi,deltaTheta:e,deltaPhi:-t,duration:i,ease:s,elapsed:0,theta:a.theta,phi:a.phi,settle:null};this.flight=c;const h=new Promise(d=>{c.settle=d});return this.applyFlightPose(c,0),i<=0&&this.settleFlight(null),h}applyFlightPose(e,t){const i=e.ease(t);e.theta=e.startTheta+e.deltaTheta*i,e.phi=Math.min(Cm,Math.max(Mm,e.startPhi+e.deltaPhi*i));const s=this.viewport.camera;s.position.setFromSphericalCoords(e.radius,e.phi,e.theta).add(e.pivot),this.viewport.orbitControls.target.copy(e.pivot),s.lookAt(e.pivot),s.updateMatrixWorld(),this.flightPose.copy(s.position)}advanceLook(e){const t=this.flight;if(!t)return;const i=Math.max(1e-4,t.radius*.001);if(this.viewport.camera.position.distanceToSquared(this.flightPose)>i*i){this.settleFlight("human");return}e>0&&Number.isFinite(e)&&(t.elapsed+=e);const s=t.duration<=0?1:Math.min(1,t.elapsed/t.duration);this.applyFlightPose(t,s),s>=1&&this.settleFlight(null)}settleFlight(e){const t=this.flight;if(!t)return;this.flight=null;const i={completed:e===null,azimuth:t.theta,elevation:Math.PI/2-t.phi,seconds:Math.min(t.elapsed,t.duration)};t.settle?.(e===null?i:{...i,cancelledBy:e})}select(e){K(),this.authoring&&cs(this.authoring,[...e])}selection(){return[...this.authoring?.selection?.get()??[]]}idForObject(e){return this.authoring?.hierarchy.idForObject3D?.(e)??null}syncSelectionPresentation(){K();const e=(this.authoring?.selection?.get()??[]).map(s=>this.authoring?oi(this.authoring.hierarchy,s):null).filter(s=>s!==null);if(this.selectedObjects=e,this.selectionOutline&&(hl(this.selectionOutline,this.selectionOutlineWanted?e:[]),this.syncComposerOutput()),this.selectionOrigins){const s=Qe(this.renderer.domElement);this.selectionOrigins.update(e,{visible:s.visible,...s.active?{active:s.active.visible}:{}})}const t=e.filter(s=>!!s.isBone),i=t.map(s=>s.uuid).join("\0");i!==this.boneSelectionSignature&&(this.boneSelectionSignature=i,this.clearBoneSelectionHighlight(),t.length>0&&(this.boneSelectionHighlight=new vm(t,Qe(this.renderer.domElement).visible),this.scene.add(this.boneSelectionHighlight)),this.refreshSkeletonHelper())}frameSelection(){return this.frameIds(this.authoring?.selection?.get()??[])}frameIds(e){this.leaveCameraView(!1),this.settleFlight("superseded");const t=e.map(i=>this.authoring?oi(this.authoring.hierarchy,i):null).filter(i=>i!==null);return t.length===0?!1:t.every(i=>i.isBone)?(this.frameBones(t),!0):(this.viewport.focusOnMultiple(t),!0)}setViewPreset(e,t="bounds"){K(),this.leaveCameraView(!1),this.settleFlight("superseded");const i=ou(e);let s,r;if(t==="view")s=this.viewport.orbitControls.target.clone(),r=this.viewport.camera.position.distanceTo(s);else{const l=this.resolveFrameBounds();if(l.isEmpty())return;s=l.getCenter(new v),r=hi(l,this.viewport.camera,i)}const n=s.clone().addScaledVector(i,r),a=e==="top"?{x:0,y:0,z:-1}:e==="bottom"?{x:0,y:0,z:1}:{x:0,y:1,z:0};this.viewport.setPose(n,s,void 0,a),this.setProjection(e==="isometric"?"perspective":"orthographic")}setCameraPose(e,t,i){K(),this.leaveCameraView(!1),this.settleFlight("superseded"),this.viewport.setPose(e,t,i)}cameraPose(){return{position:this.viewport.camera.position.toArray(),target:this.viewport.orbitControls.target.toArray(),fov:this.viewport.camera.fov}}camera(){if(this.cameraOverride)return this.cameraOverride;const e=this.drawnCamera();return this.viewport.setGizmoCamera(e===this.viewport.camera?null:e),e}drawnCamera(){const e=this.through?this.cameraView():null;return e?this.throughCamera(e):(this.through&&!this.leaving&&(this.leaving=!0,queueMicrotask(()=>{this.leaving=!1,this.through&&!this.cameraView()&&this.leaveCameraView(!1)})),this.state.projection==="perspective"?this.viewport.camera:(this.syncOrthographicCamera(),this.orthographicCamera))}setCameraViewSource(e){this.cameraViewSource!==e&&(this.cameraViewSource=e,e||this.leaveCameraView(!1),this.notify())}hasCameraView(){return this.cameraViewSource!==null}cameraView(){const e=this.through,t=this.cameraViewSource;if(!e||!t)return null;const i=this.renderer.domElement,s=this.captureAspect?{width:this.captureAspect,height:1}:{width:i.clientWidth,height:i.clientHeight},r=this.viewport.camera,n=e.locked?`${r.position.toArray().join(",")}|${r.quaternion.toArray().join(",")}`:"",a=`${e.camera}|${s.width}|${s.height}|${e.zoom}|${e.offset.join(",")}|${n}`;if(this.viewMemo?.key===a)return this.viewMemo.view;const l=t.view(e.camera,s,e.zoom,e.offset),c=l&&e.locked?{...l,position:r.position.toArray(),quaternion:r.quaternion.toArray()}:l;return this.viewMemo={key:a,view:c},queueMicrotask(()=>{this.viewMemo=null}),c}toggleCameraView(){if(this.through)return this.leaveCameraView(!0),!0;const e=this.cameraViewSource,t=e?.camera()??null;if(!e)return!1;if(t===null)return Oi.warn("camera view: No active camera — the scene has no camera to look through","document"),!1;K(),this.settleFlight("superseded");const i=this.viewport,s=i.orbitControls,r=s.enableDamping;return s.enableDamping=!1,s.update(),s.enableDamping=r,this.through={camera:t,zoom:e.zoom.opening,offset:[0,0],left:{position:i.camera.position.clone(),target:i.orbitControls.target.clone(),up:i.camera.up.clone(),projection:this.state.projection},release:this.captureCameraViewInput(),locked:!1},e.showing?.(t),this.notify(),!0}cameraViewLocked(){return!this.through||!this.cameraViewSource?.setPose?null:this.through.locked}toggleCameraViewLock(){const e=this.through,t=this.cameraViewSource;if(!(!e||!t?.setPose)){if(e.release(),e.locked=!e.locked,!e.locked)e.release=this.captureCameraViewInput();else{const i=this.cameraView(),s=this.viewport.orbitControls,r=this.viewport.camera;if(i){const y=new v(...i.position),_=new pe(...i.quaternion),x=e.left.position.distanceTo(e.left.target);r.up.set(0,1,0).applyQuaternion(_),r.position.copy(y),r.quaternion.copy(_),s.target.copy(y).addScaledVector(new v(0,0,-1).applyQuaternion(_),x),s.update()}const n=s.enabled;s.enabled=!0;const a=s.enableDamping;s.enableDamping=!1;const l=e.camera,c=y=>({position:r.position.toArray(),quaternion:r.quaternion.toArray(),final:y});let h=!1,d=null,p=!1;const u=y=>{if(h){d={...y,final:y.final||(d?.final??!1)};return}h=!0,d=null,Promise.resolve(t.setPose(l,y.position,y.quaternion,y.final)).catch(()=>{}).finally(()=>{h=!1,d&&u(d)})},f=()=>{p=!0,K(),this.notify(),u(c(!1))},m=()=>{p&&(p=!1,u(c(!0)))};s.addEventListener("change",f),s.addEventListener("end",m),e.release=()=>{m(),s.removeEventListener("change",f),s.removeEventListener("end",m),s.enabled=n,s.enableDamping=a}}this.viewMemo=null,K(),this.notify()}}cameraViewZoom(){return this.through?.zoom??null}setCameraViewZoom(e){const t=this.through,i=this.cameraViewSource;!t||!i||!Number.isFinite(e)||e<=0||(t.zoom=Math.min(i.zoom.max,Math.max(i.zoom.min,e)),K(),this.notify())}zoomCameraView(e){this.through&&this.setCameraViewZoom(this.through.zoom*e)}panCameraView(e,t){const i=this.through,s=this.cameraViewSource;if(!i||!s)return;const[r,n]=s.pan(i.offset,i.zoom,e,t);i.offset=[r,n],K(),this.notify()}leaveCameraView(e){const t=this.through;if(!t)return;const i=this.cameraView();t.release(),this.through=null,this.viewMemo=null,this.cameraViewSource?.showing?.(null),this.viewport.setGizmoCamera(null);const s=this.viewport;if(e)s.camera.position.copy(t.left.position),s.camera.up.copy(t.left.up),s.orbitControls.target.copy(t.left.target),this.state={...this.state,projection:t.left.projection};else if(i){const r=t.left.position.distanceTo(t.left.target),n=new v(...i.position),a=new pe(...i.quaternion),l=new v(0,0,-1).applyQuaternion(a);s.camera.up.set(0,1,0).applyQuaternion(a),s.camera.position.copy(n),s.orbitControls.target.copy(n).addScaledVector(l,r);const c=Bi(t.left.position.clone().sub(t.left.target),t.left.up)!==null,h=Ze().autoPerspective&&c?"perspective":t.left.projection;this.state={...this.state,projection:h}}s.camera.lookAt(s.orbitControls.target),s.orbitControls.update(),K(),this.notify()}throughCamera(e){const{left:t,right:i,top:s,bottom:r}=e.window,n=this.viewport.camera.layers.mask;if(e.projection==="orthographic"){const l=this.throughOrthographic;return Object.assign(l,{left:t,right:i,top:s,bottom:r,near:e.near,far:e.far,zoom:1}),l.position.set(...e.position),l.quaternion.set(...e.quaternion),l.layers.mask=n,l.updateProjectionMatrix(),l.updateMatrixWorld(!0),l}const a=this.throughPerspective;return a.near=e.near,a.far=e.far,a.fov=Le.radToDeg(2*Math.atan((s-r)/2)),a.aspect=(i-t)/(s-r),a.zoom=1,a.position.set(...e.position),a.quaternion.set(...e.quaternion),a.layers.mask=n,a.projectionMatrix.makePerspective(t*e.near,i*e.near,s*e.near,r*e.near,e.near,e.far),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),a.updateMatrixWorld(!0),a}captureCameraViewInput(){const e=this.viewport.orbitControls,t=this.renderer.domElement,i=t.parentElement??t,s=e.enabled;e.enabled=!1;const r=a=>{a.target!==t||a.deltaY===0||(a.preventDefault(),this.zoomCameraView(a.deltaY<0?1.2:1/1.2))},n=a=>{if(a.target!==t)return;const l=e.mouseButtons;let c=[l.LEFT,l.MIDDLE,l.RIGHT][a.button]??null;const h=a.ctrlKey||a.metaKey||a.shiftKey;if(a.button===1&&(a.ctrlKey||a.metaKey)&&c===Ie.ROTATE?c=Ie.DOLLY:h&&c===Ie.ROTATE?c=Ie.PAN:h&&c===Ie.PAN&&(c=Ie.ROTATE),c===Ie.ROTATE){this.leaveCameraView(!1);return}if(c!==Ie.PAN&&c!==Ie.DOLLY)return;a.preventDefault();const d=t.getBoundingClientRect();let p=a.clientX,u=a.clientY;const f=this.through?.zoom??1,m=Math.max(5+a.clientY-d.top,1),y=x=>{if(c===Ie.PAN){this.panCameraView((x.clientX-p)/Math.max(d.width,1),(x.clientY-u)/Math.max(d.height,1)),p=x.clientX,u=x.clientY;return}const S=Math.max(.01,2*((5+x.clientY-d.top)/m-1)+1);this.setCameraViewZoom(f/S)},_=()=>{window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",_),window.removeEventListener("pointercancel",_)};window.addEventListener("pointermove",y),window.addEventListener("pointerup",_),window.addEventListener("pointercancel",_)};return i.addEventListener("wheel",r,{capture:!0,passive:!1}),i.addEventListener("pointerdown",n,{capture:!0}),()=>{i.removeEventListener("wheel",r,{capture:!0}),i.removeEventListener("pointerdown",n,{capture:!0}),e.enabled=s}}projection(){return this.state.projection}setProjection(e){K(),this.state.projection!==e&&(this.state={...this.state,projection:e},this.notify())}setMode(e){K(),this.state.mode!==e&&(this.clearDiagnosticPresentation(),this.state={...this.state,mode:e},e==="uv"?this.scene.overrideMaterial=new fs({vertexShader:"varying vec2 vUv; void main(){ vUv=uv; gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0); }",fragmentShader:"varying vec2 vUv; void main(){ gl_FragColor=vec4(vUv,0.0,1.0); }"}):e==="vertex-colors"?this.scene.overrideMaterial=new Ce({vertexColors:!0}):e==="wireframe"&&this.buildTopologyOverlay(),this.notify())}buildTopologyOverlay(){const e=new Ve,t=[];this.root.updateMatrixWorld(!0),this.root.traverse(i=>{const s=i;if(!s.isMesh||!s.geometry)return;const r=new Li(new _o(s.geometry,bm),new qt({color:wl,toneMapped:!1,transparent:!0,opacity:.85,depthTest:!1,depthWrite:!1}));r.matrixAutoUpdate=!1,r.matrixWorldAutoUpdate=!1,r.matrixWorld.copy(s.matrixWorld),r.frustumCulled=!1,r.renderOrder=2,e.add(r),t.push({line:r,source:s})}),t.length!==0&&(this.topologyOverlay=e,this.topologyFollowers=t,this.addHelper(e,"topology"))}syncTopologyOverlay(){this.topologyFollowers.some(({source:s})=>s.parent===null)&&(this.clearTopologyOverlay(),this.buildTopologyOverlay()),this.selectionColors??=Qe(this.renderer.domElement);const e=this.selectionColors,t=this.selectedObjects.at(-1)??null,i=(s,r)=>{for(let n=s;n;n=n.parent)if(n===r)return!0;return!1};for(const{line:s,source:r}of this.topologyFollowers){s.matrixWorld.copy(r.matrixWorld),s.visible=r.visible;const n=s.material,a=t!==null&&i(r,t),l=a||this.selectedObjects.some(h=>i(r,h)),c=a?e.active?.visible??e.visible:l?e.visible:null;n.color.setHex(c??wl)}}clearTopologyOverlay(){for(const{line:i}of this.topologyFollowers.splice(0))i.geometry.dispose(),i.material.dispose();const e=this.topologyOverlay;if(this.topologyOverlay=null,!e)return;e.removeFromParent();const t=this.helpers.indexOf(e);t>=0&&this.helpers.splice(t,1)}setBounds(e){K(),this.state.bounds!==e&&(this.state={...this.state,bounds:e},e?(this.boundsHelper=new ka(this.root,16757844),this.addHelper(this.boundsHelper,"bounds")):this.clearBoundsHelper(),this.notify())}setSkeleton(e){K(),this.state.skeleton!==e&&(this.state={...this.state,skeleton:e},this.refreshSkeletonHelper(),this.notify())}neutralBackgroundTexture(){return this.neutralBackground}setNeutralBackground(e){K();const t=this.scene.background,i=this.neutralBackground,s=t===i||t instanceof V&&i instanceof V&&t.equals(i);this.neutralBackground=e,s&&(this.scene.background=e)}setBackground(e){K(),this.state.background!==e&&(this.scene.background=e==="transparent"?null:this.neutralBackground,this.state={...this.state,background:e},this.notify())}resetPresentation(){K(),sh(this.documentId),this.clearDiagnosticPresentation(),this.state=vl,this.refreshSkeletonHelper(),this.clearBoundsHelper(),this.scene.background=this.neutralBackground,this.viewport.camera.up.set(0,1,0),this.frame(),this.notify()}setBeforeRender(e){this.beforeRender=e}presentedFrameWaiters=[];presentsFrames=!1;setPresentsFrames(e){this.presentsFrames=e,e||this.resolvePresentedFrame(null)}requestPresentedFrame(){return this.presentsFrames?new Promise(e=>{let t=!1;const i=s=>{t||(t=!0,e(s))};this.presentedFrameWaiters.push(i),K(),setTimeout(()=>i(null),Sm)}):Promise.resolve(null)}needsFrame(){return this.flight!==null||this.presentedFrameWaiters.length>0}servePresentedFrame(){if(this.presentedFrameWaiters.length===0)return;const e=this.renderer.domElement,t=document.createElement("canvas");t.width=Math.max(1,e.width),t.height=Math.max(1,e.height);const i=t.getContext("2d");if(!i){this.resolvePresentedFrame(null);return}i.drawImage(e,0,0),this.resolvePresentedFrame(t)}resolvePresentedFrame(e){const t=this.presentedFrameWaiters;this.presentedFrameWaiters=[];for(const i of t)i(e)}render(e){this.beforeRender?.(),this.boneSelectionHighlight?.update();const t=this.camera(),i=this.state.mode;if(this.boundsHelper?.update(),this.selectionOrigins?.place(),i==="uv"||i==="vertex-colors"){e(t);return}if(i==="wireframe"&&this.topologyOverlay){if(this.syncTopologyOverlay(),this.xray.enabled&&this.xray.alpha<=0){const s=new Set;this.root.traverse(r=>{const n=r;if(n.isMesh)for(const a of Array.isArray(n.material)?n.material:[n.material])a?.visible&&(a.visible=!1,s.add(a))});try{e(t)}finally{for(const r of s)r.visible=!0}return}this.shading.render(this.scene,"clay",()=>e(t),_l);return}this.shading.render(this.scene,i,()=>e(t),_l)}renderViewport(e=0){this.advanceLook(e),this.ensureComposer(),this.render(t=>{const i=this.composer;if(!i){this.renderer.render(this.scene,t);return}i.setMainScene(this.scene),i.setMainCamera(t),i.render(e)})}resize(e,t){K(),this.renderWidth=Math.max(1,e),this.renderHeight=Math.max(1,t),this.composer?.setSize(this.renderWidth,this.renderHeight)}renderCapture(e,t){this.render(i=>{if(!t){e(i);return}const s=this.scene.background,r=this.renderer.getClearColor(new V),n=this.renderer.getClearAlpha();try{this.scene.background=null,this.renderer.setClearColor(0,0),e(i)}finally{this.scene.background=s,this.renderer.setClearColor(r,n)}})}captureImage(e=512){const t=typeof e=="number"?e:e.width,i=typeof e=="number"?e:e.height;if(!Number.isFinite(t)||t<1||!Number.isFinite(i)||i<1)return null;const s=Math.min(2048,Math.round(t)),r=Math.min(2048,Math.round(i)),n=s*2,a=r*2,l=new Ra(n,a,{type:tu}),c=new Ra(n,a),h=this.renderer.getRenderTarget(),d=this.renderer.getPixelRatio(),p=this.viewport.camera,u=p.aspect;try{this.captureAspect=s/r;const f=typeof e=="number"?void 0:e.camera;f?this.cameraOverride=f:(p.aspect=s/r,p.updateProjectionMatrix()),this.renderer.setPixelRatio(1),this.renderer.setRenderTarget(l),this.renderCapture(b=>this.renderSolidForCapture(b,l,n,a),typeof e!="number"&&e.transparent===!0),md(typeof e!="number"&&e.transparent===!0).render(this.renderer,c,l,0,!1);const m=n*4,y=new Uint8Array(m*a);this.renderer.readRenderTargetPixels(c,0,0,n,a,y);const _=document.createElement("canvas");_.width=n,_.height=a;const x=_.getContext("2d");if(!x)return null;const S=x.createImageData(n,a);for(let b=0;b<a;b++){const M=(a-1-b)*m,P=b*m;S.data.set(y.subarray(M,M+m),P)}x.putImageData(S,0,0);const w=document.createElement("canvas");w.width=s,w.height=r;const C=w.getContext("2d");return C?(C.drawImage(_,0,0,s,r),w.toDataURL("image/png")):null}finally{this.captureAspect=null,this.cameraOverride=null,p.aspect=u,p.updateProjectionMatrix(),this.renderer.setRenderTarget(h),this.renderer.setPixelRatio(d),this.composer?.setSize(this.renderWidth,this.renderHeight,!1),c.dispose(),l.dispose()}}dispose(){this.disposed=!0,this.leaveCameraView(!1),this.selectionOrigins?.dispose(),this.selectionOrigins=null,this.settleFlight("closed"),this.viewport.orbitControls.removeEventListener("start",this.cancelLookForHuman),this.unsubscribeRotateStart(),this.unsubscribeAxisView(),this.unsubscribeSelectionTheme(),this.clearDiagnosticPresentation(),this.clearBoneSelectionHighlight(),this.clearBoundsHelper(),this.clearSkeletonHelper(),this.selectionOutline&&If(this.renderer,this.selectionOutline,this.selectionOutlinePass),this.composer?.dispose(),this.sceneRenderPass=null,this.selectionOutline=null,this.selectionOutlinePass=null,this.composer=null,this.shading.dispose(),this.listeners.clear()}addHelper(e,t){e.name=`__object3d_document_${t}`,qe(e,"editorHelper",!0),this.scene.add(e),this.helpers.push(e)}get selectionOutlineEnabled(){return this.selectionOutlineWanted}set selectionOutlineEnabled(e){e!==this.selectionOutlineWanted&&(this.selectionOutlineWanted=e,e?this.syncSelectionPresentation():(this.selectionOutline?.selection.clear(),this.syncComposerOutput()))}selectionOutlineWanted=!0;xray={enabled:!1,alpha:1};setXray(e){this.xray.enabled===e.enabled&&this.xray.alpha===e.alpha||(this.xray=e,K())}set selectionOriginsEnabled(e){e!==(this.selectionOrigins!==null)&&(e?(this.selectionOrigins=new Tm,this.scene.add(this.selectionOrigins),this.syncSelectionPresentation()):(this.selectionOrigins?.dispose(),this.selectionOrigins=null,K()))}ensureComposer(){this.selectionOutlineWanted&&(this.composer||this.composerLoading||this.disposed||(this.composerLoading=!0,mi(()=>import("./index-CQG6JOSy.js"),__vite__mapDeps([3,1])).then(e=>{if(this.composerLoading=!1,this.disposed||this.composer)return;const t=this.camera(),i=new e.EffectComposer(this.renderer);this.sceneRenderPass=new e.RenderPass(this.scene,t),i.addPass(this.sceneRenderPass),this.selectionOutline=Rf(e,this.renderer,this.scene,t,Qe(this.renderer.domElement)),this.syncSelectionTheme(),hl(this.selectionOutline,this.selectedObjects),this.selectionOutlinePass=new e.EffectPass(t,this.selectionOutline),i.addPass(this.selectionOutlinePass),this.composer=i,this.syncComposerOutput(),i.setSize(this.renderWidth,this.renderHeight),K()}).catch(()=>{this.composerLoading=!1})))}renderSolidForCapture(e,t,i,s){const r=this.composer,n=(this.selectionOutline?.selection.size??0)>0;if(!r||!n||!this.sceneRenderPass||!this.selectionOutlinePass){this.renderer.render(this.scene,e);return}const a=this.renderWidth,l=this.renderHeight;try{this.sceneRenderPass.renderToScreen=!1,this.selectionOutlinePass.renderToScreen=!1,r.setSize(i,s,!1),this.sceneRenderPass.render(this.renderer,r.inputBuffer,r.outputBuffer,0),this.selectionOutlinePass.render(this.renderer,r.inputBuffer,t,0)}finally{r.setSize(a,l,!1),this.syncComposerOutput(),this.renderer.setRenderTarget(t)}}syncComposerOutput(){const e=(this.selectionOutline?.selection.size??0)>0;this.sceneRenderPass&&(this.sceneRenderPass.renderToScreen=!e),this.selectionOutlinePass&&(this.selectionOutlinePass.enabled=e,this.selectionOutlinePass.renderToScreen=e)}refreshSkeletonHelper(){const e=this.state.skeleton||this.boneSelectionHighlight!==null;e&&!this.skeletonHelper?(this.skeletonHelper=new iu(this.root),xm(this.skeletonHelper),this.scene.add(this.skeletonHelper)):e||this.clearSkeletonHelper()}clearSkeletonHelper(){this.skeletonHelper&&(this.skeletonHelper.removeFromParent(),this.skeletonHelper.dispose(),this.skeletonHelper=null)}clearBoneSelectionHighlight(){this.boneSelectionHighlight&&(this.boneSelectionHighlight.removeFromParent(),this.boneSelectionHighlight.dispose(),this.boneSelectionHighlight=null)}clearBoundsHelper(){if(!this.boundsHelper)return;const e=this.boundsHelper;this.boundsHelper=null;const t=this.helpers.indexOf(e);t>=0&&this.helpers.splice(t,1),e.removeFromParent(),e.geometry.dispose(),Array.isArray(e.material)?e.material.forEach(i=>{i.dispose()}):e.material.dispose()}frameBones(e){const t=new wt,i=new v;for(const l of e){t.expandByPoint(l.getWorldPosition(i)),l.parent?.isBone&&t.expandByPoint(l.parent.getWorldPosition(i));for(const c of l.children)c.isBone&&t.expandByPoint(c.getWorldPosition(i))}const s=t.getCenter(new v),r=Math.max(t.getSize(new v).length(),.2);t.expandByScalar(r*.35);const n=this.viewport.camera.position.clone().sub(this.viewport.orbitControls.target).normalize(),a=hi(t,this.viewport.camera,n);this.viewport.setPose(s.clone().addScaledVector(n,a),s)}syncOrthographicCamera(){const e=this.viewport.camera,t=this.viewport.orbitControls.target,i=Math.max(e.position.distanceTo(t),.001),s=Math.max(i*Math.tan(Le.degToRad(e.fov)/2),.001),r=Math.max(this.renderer.domElement.clientWidth,1),n=Math.max(this.renderer.domElement.clientHeight,1),a=this.captureAspect??r/n;this.orthographicCamera.left=-s*a,this.orthographicCamera.right=s*a,this.orthographicCamera.top=s,this.orthographicCamera.bottom=-s,this.orthographicCamera.near=e.near,this.orthographicCamera.far=e.far,this.orthographicCamera.position.copy(e.position),this.orthographicCamera.quaternion.copy(e.quaternion),this.orthographicCamera.up.copy(e.up),this.orthographicCamera.layers.mask=e.layers.mask,this.orthographicCamera.updateProjectionMatrix(),this.orthographicCamera.updateMatrixWorld(!0)}clearDiagnosticPresentation(){this.clearTopologyOverlay(),this.scene.overrideMaterial?.dispose(),this.scene.overrideMaterial=null;for(const e of this.helpers.splice(0)){e.removeFromParent();const t=e;t.geometry?.dispose();const i=t.material;Array.isArray(i)?i.forEach(s=>{s.dispose()}):i?.dispose()}}notify(){this.version++;for(const e of this.listeners)e()}}const zm=7;let ls=null;function Om(){if(ls)return ls;const o=64,e=document.createElement("canvas");e.width=o,e.height=o;const t=e.getContext("2d");return t.beginPath(),t.arc(o/2,o/2,o/2-1,0,Math.PI*2),t.fillStyle="rgba(0, 0, 0, 0.75)",t.fill(),t.beginPath(),t.arc(o/2,o/2,o/2-8,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),ls=new qr(e),ls.colorSpace=rt,ls}class Tm extends mo{objects=[];origin=new v;constructor(){super(new Et,new ic({map:Om(),size:zm,sizeAttenuation:!1,transparent:!0,alphaTest:.05,depthTest:!1,depthWrite:!1,toneMapped:!1})),this.name="vgai:selection-origins",this.userData.editorHelper=!0,this.renderOrder=1e3,this.frustumCulled=!1,this.raycast=()=>{}}update(e,t){this.objects=e,this.material.color.setHex(e.length===1&&t.active!==void 0?t.active:t.visible),this.visible=e.length>0}place(){const e=this.objects.length;let t=this.geometry.getAttribute("position");(t===void 0||t.count<e)&&(this.geometry.dispose(),t=new mt(new Float32Array(Math.max(e,8)*3),3),this.geometry.setAttribute("position",t)),this.geometry.setDrawRange(0,e),this.objects.forEach((i,s)=>{i.getWorldPosition(this.origin),t.setXYZ(s,this.origin.x,this.origin.y,this.origin.z)}),t.needsUpdate=!0}dispose(){this.removeFromParent(),this.geometry.dispose(),this.material.dispose()}}class km{constructor(e){this.options=e}active=null;settling=!1;idleWaiters=new Set;begin(e){if(this.active||this.settling)return!1;try{const t=this.options.begin(e);return t?(this.active={pointerId:e.pointerId,gesture:t},!0):!1}catch(t){return this.options.reportError(t),!1}}update(e){if(!(!this.active||this.active.pointerId!==e.pointerId))try{this.active.gesture.update(e)}catch(t){this.cancelWithError(t)}}async commit(e){const t=this.take(e.pointerId);if(!t)return!1;this.settling=!0;try{return await t.commit(e),await this.options.persist(t.label),!0}catch(i){try{await t.cancel()}catch(s){return this.options.reportError({operationError:i,rollbackError:s}),!1}return this.options.reportError(i),!1}finally{this.settling=!1;for(const i of this.idleWaiters)i();this.idleWaiters.clear()}}async cancel(e){const t=this.take(e);if(!t)return!1;this.settling=!0;try{return await t.cancel(),!0}catch(i){return this.options.reportError(i),!1}finally{this.settling=!1;for(const i of this.idleWaiters)i();this.idleWaiters.clear()}}async settle(){this.active&&await this.cancel(),this.settling&&await new Promise(e=>this.idleWaiters.add(e))}hasActiveGesture(){return this.active!==null}take(e){if(!this.active||e!==void 0&&this.active.pointerId!==e)return null;const t=this.active.gesture;return this.active=null,t}async cancelWithError(e){const t=this.take();if(t){this.settling=!0;try{await t.cancel(),this.options.reportError(e)}catch(i){this.options.reportError({operationError:e,rollbackError:i})}finally{this.settling=!1;for(const i of this.idleWaiters)i();this.idleWaiters.clear()}}}}function Gt(o){const e=Oe(o,"authoringSubject");return e&&typeof e.label=="string"&&typeof e.kind=="string"?e:null}function xl(o){return o.depthWrite===!1&&o.side===su}function Rm(o){const e=o.material;return e?Array.isArray(e)?e.length>0&&e.every(xl):xl(e):!1}function vc(o,e,t,i=()=>!1,s){const r=Gp();if(!r)return[];const n=r.canvas.getBoundingClientRect();if(n.width<=0||n.height<=0||!Number.isFinite(e)||!Number.isFinite(t)||e<n.left||t<n.top||e>=n.left+n.width||t>=n.top+n.height)return[];const a=new je((e-n.left)/n.width*2-1,-((t-n.top)/n.height)*2+1),l=new nt;l.layers.enableAll(),l.setFromCamera(a,r.camera);const c=new Set(s?.objects??o.objectMap.values()),h=[...c].filter(f=>{for(let m=f.parent;m;m=m.parent)if(c.has(m))return!1;return!0});for(const f of h)f.traverse(m=>{const y=m;y.isSkinnedMesh&&(y.boundingBox=null,y.boundingSphere=null)});const d=l.intersectObjects(h,!0),p=[],u=new Set;for(const f of d){if(gt(f.object)||Rm(f.object))continue;let m=f.object,y=null;if(s)for(;m&&y===null;)y=s.idForObject3D(m),m=m.parent;else{const _=Kh(m);y=_?uo(_)??null:null}y!==null&&!i(y)&&!u.has(y)&&(u.add(y),p.push(y))}return Im(p,h,d.length,e,t),p}function Im(o,e,t,i,s){o.length>0||i===0&&s===0||console.info(`[viewport-pick] click selected nothing (candidates ${e.length}, rayHits ${t}, resolvedIds 0)`)}function Lm(o,e,t,i=()=>!1,s){return vc(o,e,t,i,s)[0]??null}const bl={count:0,meshes:0,lights:0,instancedMeshes:0,instances:0};let Sl=0;function Fm(o){let e=0,t=0;for(const i of o.values()){const s=i.object;s.isInstancedMesh&&(e++,t+=typeof s.count=="number"?s.count:0)}return{instancedMeshes:e,instances:t}}function wc(o){let e=0,t=0;for(const i of o.values()){const s=i.object;s.isLight?t++:s.isMesh&&e++}return{count:o.size,meshes:e,lights:t,...Fm(o)}}function Bm(o,e){const t=new Map,i=[],s=e.skip??qs;e.begin?.(o);const r=(n,a,l,c)=>{if(s(n))return;const h=e.identify(n,{path:a,ownerId:l,ownedByAncestor:c});h!==null&&(Gl(n,h),t.set(h,{object:n,id:h,parentId:l,childIds:[]}),l===null?i.push(h):t.get(l)?.childIds.push(h));const d=c||h!==null;n.children.forEach((p,u)=>{r(p,[...a,u],h??l,d)}),e.leave?.(n,h)};return o.children.forEach((n,a)=>{r(n,[a],null,!1)}),{nodes:t,rootIds:i,stats:wc(t)}}const Nm="r3f:";function Hm(o,e){return`${Nm}${o}:${e}`}function Dm(o){return{project:e=>Bm(e,{skip:t=>!!Oe(t,"editorHelper")||t.isSkeletonHelper===!0,identify:(t,i)=>`source-object:${o}:${i.path.join(".")}`})}}function Vm(o){const e=Gt(o);return e?e.kind:Nr(o).length>0?"constraint-owner":us(o)?"reflection-probe":o.isSkinnedMesh?"skinned-mesh":o.isBone?"bone":o.isLight?"light":o.isCamera?"camera":o.type==="Audio"||o.type==="PositionalAudio"||o.type==="AudioListener"?"audio":o.isMesh?"mesh":o.children.length>0?"group":"object"}function Um(o,e){for(let t=o.parent;t!==null;t=t.parent)if(t===e)return!0;return!1}function Ml(o,e){if(o===e)return!0;for(let t=o.parent;t!==null;t=t.parent)if(t===e)return!0;return!1}class jm{constructor(e,t={}){this.identity=e,this.options=t}nodesById=new Map;objectsById=new Map;idsByObjectIndex=new Map;roots=[];walkStats=bl;project(e){if(!e)return this.nodesById=new Map,this.objectsById=new Map,this.idsByObjectIndex=new Map,this.roots=[],this.walkStats=bl,this.walkStats;const{nodes:t,rootIds:i,stats:s}=this.identity.project(e);return this.nodesById=t,this.objectsById=new Map([...t].map(([r,n])=>[r,n.object])),this.idsByObjectIndex=new Map([...t].map(([r,n])=>[n.object,r])),this.roots=i,this.walkStats=s,s}projectSubtrees(e,t){const i=this.identity.incremental;if(e===null||i?.kind!=="live-oid")return null;const s=t.filter((_,x)=>t.indexOf(_)===x&&!t.some(S=>S!==_&&Um(_,S))),r=this.roots,n=new Set,a=new Set,l=new Set;for(const _ of s)_.traverse(x=>{const S=this.idsByObjectIndex.get(x);if(S===void 0)return;const w=this.nodesById.get(S);w?.parentId!==null&&w?.parentId!==void 0&&l.add(w.parentId),n.add(S),this.nodesById.delete(S),this.objectsById.delete(S),this.idsByObjectIndex.delete(x)});const c=qs,h=(_,x)=>{const S=this.objectsById.get(_);return S===void 0||S===x},d=(_,x)=>{const S=uo(_);if(S!==void 0&&h(S,_))return S;const w=ed(_);if(w!==void 0){const C=Hm(i.worldId,w);let b=0,M=Aa(C,b);for(;!h(M,_);)M=Aa(C,++b);return M}if(!x||Oe(_,"authoringRoot")===!0){let C=`live:${i.worldId}:${Sl++}`;for(;!h(C,_);)C=`live:${i.worldId}:${Sl++}`;return C}return null},p=(_,x,S)=>{if(c(_))return;const w=d(_,S);w!==null&&(Gl(_,w),this.nodesById.set(w,{object:_,id:w,parentId:x,childIds:[]}),this.objectsById.set(w,_),this.idsByObjectIndex.set(_,w),a.add(w),x!==null&&l.add(x));const C=w??x,b=S||w!==null;for(const M of _.children)p(M,C,b)};for(const _ of s){if(!Ml(_,e))continue;let x=_.parent,S=null;for(;x!==null&&x!==e;){const w=this.idsByObjectIndex.get(x);if(w!==void 0){S=w;break}x=x.parent}p(_,S,S!==null)}const u=_=>{const x=[],S=w=>{if(c(w))return;const C=this.idsByObjectIndex.get(w);if(C!==void 0){x.push(C);return}for(const b of w.children)S(b)};for(const w of _.children)S(w);return x};for(const _ of l){const x=this.nodesById.get(_);x!==void 0&&x.childIds.splice(0,x.childIds.length,...u(x.object))}for(const _ of a){const x=this.nodesById.get(_);x!==void 0&&x.childIds.splice(0,x.childIds.length,...u(x.object))}const f=u(e),m=this.roots.filter(_=>{const x=this.objectsById.get(_);return x!==void 0&&!Ml(x,e)&&!n.has(_)});this.roots=[...f,...m],this.walkStats=wc(this.nodesById);const y=r.length!==this.roots.length||r.some((_,x)=>_!==this.roots[x]);return{removedIds:n,addedIds:a,changedParentIds:l,rootsChanged:y}}get nodes(){return this.nodesById}get objects(){return this.objectsById}get idsByObject(){return this.idsByObjectIndex}get rootIds(){return this.roots}get stats(){return this.walkStats}node(e){return this.nodesById.get(e)??null}rootNodes(){return this.roots.map(e=>this.nodesById.get(e)).filter(e=>e!==void 0)}objectOf(e){return this.objectsById.get(e)??null}idOf(e){return this.idsByObjectIndex.get(e)??null}childIdsOf(e){const t=[];for(const i of e){const s=this.idsByObjectIndex.get(i);s!==void 0&&t.push(s)}return t}objectMapSnapshot(){return new Map(this.objectsById)}pick(e,t,i,s){return Lm(e,t,i,s,this.pickProjection())}candidates(e,t,i,s){return vc(e,t,i,s,this.pickProjection())}pickProjection(){if(this.options.pickScope!=="store-object-map")return{objects:this.objectsById.values(),idForObject3D:e=>this.idOf(e)}}}const Cl=new v,Pl=new pe,Al=new v;function Gm(o){return o.matrixAutoUpdate===!1?(o.matrix.decompose(Cl,Pl,Al),{position:Cl.toArray(),quaternion:Pl.toArray(),scale:Al.toArray()}):{position:o.position.toArray(),quaternion:o.quaternion.toArray(),scale:o.scale.toArray()}}function Wm(o,e){return o.length===e.length&&o.every((t,i)=>t===e[i])}class Xm{constructor(e){this.options=e,this.selected=[...e.initial]}adopted=[];selected;current(){const e=[...this.options.store.selectedEntityIds].filter(this.options.owns);return Wm(e,this.adopted)||(this.adopted=e,this.selected=e,this.options.onChange?.(e)),[...this.selected]}publish(e){this.selected=[...e];const t=this.selected.filter(this.options.owns);this.adopted=t,this.options.onChange?.(t),this.options.store.selectMultiple(t)}}function qm(o){if(!o)return{position:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]};const e=Gm(o);return{position:e.position,rotation:e.quaternion,scale:e.scale}}function Wn(o){return o.type==="Object3D"&&o.name===""&&Gt(o)===null&&o.userData.oid===void 0&&Oe(o,"authoringInstance")===void 0&&Oe(o,"authoringRoot")!==!0&&Oe(o,"vgaiComponentRoot")===void 0}class Jm{constructor(e){this.options=e,this.rootIdSet=new Set(e.rootIds)}rootIdSet;childObjects(e){return e.children.flatMap(t=>qs(t)?[]:Wn(t)?this.childObjects(t):[t])}childIds(e){return this.options.projector.childIdsOf(this.childObjects(e))}rootObjects(){return this.options.rootIds.flatMap(e=>{const t=this.options.projector.objectOf(e);return t?Wn(t)?this.childObjects(t):[t]:[]})}rootIds(){return this.options.projector.childIdsOf(this.rootObjects())}parentId(e){const{projector:t,scene:i,documentNodeId:s}=this.options,r=t.idOf(e);if(r!==null&&this.rootIdSet.has(r))return s;let n=e.parent;for(;n&&n!==i&&Wn(n);)n=n.parent;return n&&n!==i?t.idOf(n)??s:s}node(e){const t=Gt(e);return{id:this.options.projector.idOf(e),label:t?.label||e.name||e.type||"Object3D",role:"entity",kind:Vm(e),...t?.typeLabel?{typeLabel:t.typeLabel}:{},parentId:this.parentId(e),childIds:this.childIds(e)}}}const El=new WeakMap;function Ym(o){let e=!1;if(o.traverse(s=>{Oe(s,"gaussianSplat")&&(e=!0)}),e)return"Gaussian splat";const t=au(o),i=lu(o);return{static:"Static model",animated:"Animated model",rigged:"Rigged model",skinned:"Skinned model"}[cu(t,i)]}function zl(o){const e=o.material;return Array.isArray(e)?e[0]??null:e??null}function Ol(o){return o?.color??null}class To{constructor(e,t,i){if(this.store=e,this.scene=t,this.options=i,this.provenance=i.provenance??(i.documentKind==="asset"?{source:"document",label:"derived asset",detail:"Loaded from an ordinary project asset. Edit its source or import recipe."}:{source:"source-code",label:"source",detail:"Instantiated from project TypeScript. Edit source or exposed parameters, then rebuild."}),this.documentNodeId=`object3d-document:${i.documentId}`,this.projector=new jm(Dm(i.documentId)),this.indexGraph(),i.hierarchyRoots&&new Set(i.hierarchyRoots).size!==i.hierarchyRoots.length)throw new Error(`Object3D document "${i.title}" declared the same hierarchy root twice.`);const s=new Set(i.hierarchyRoots??[]);for(const r of s){let n=r.parent;for(;n&&n!==t;){if(s.has(n))throw new Error(`Object3D document "${i.title}" declared nested hierarchy roots; roots must be non-overlapping.`);n=n.parent}}this.hierarchyRootIds=i.hierarchyRoots?i.hierarchyRoots.map(r=>{const n=this.idByObject.get(r);if(!n)throw new Error(`Object3D document "${i.title}" declared a hierarchy root outside its native graph.`);return n}):[...this.projector.rootIds],this.view=new Jm({projector:this.projector,scene:t,documentNodeId:this.documentNodeId,rootIds:this.hierarchyRootIds}),this.selectionState=new Xm({store:e.shell,owns:r=>this.byId.has(r),initial:[this.documentNodeId],onChange:r=>this.syncMarkedSelection(r)})}documentNodeId;projector;hierarchyRootIds;view;selectionState;markedSelection=new Set;capabilities={transform:!1,inspectorFields:!0,persist:!1};provenance;disposed=!1;dispose(){if(!this.disposed){this.disposed=!0;for(const e of this.watchedForStructure)e.removeEventListener("childadded",this.onStructureChanged),e.removeEventListener("childremoved",this.onStructureChanged);this.watchedForStructure=[]}}watchedForStructure=[];structureReindexQueued=!1;onStructureChanged=e=>{qs(e.child)||this.scheduleStructureReindex()};indexGraph(){this.projector.project(this.scene),this.watchStructure()}watchStructure(){const e=i=>i;for(const i of this.watchedForStructure)e(i).removeEventListener("childadded",this.onStructureChanged),e(i).removeEventListener("childremoved",this.onStructureChanged);this.watchedForStructure=[];const t=i=>{e(i).addEventListener("childadded",this.onStructureChanged),e(i).addEventListener("childremoved",this.onStructureChanged),this.watchedForStructure.push(i)};t(this.scene);for(const[,i]of this.byId)t(i)}scheduleStructureReindex(){this.disposed||this.structureReindexQueued||(this.structureReindexQueued=!0,queueMicrotask(()=>{if(this.structureReindexQueued=!1,this.disposed||(this.indexGraph(),this.store.scene!==this.scene))return;const e=this.store.objectMap;e.clear();for(const[i,s]of this.byId)e.set(i,s);const t=[...this.store.shell.selectedEntityIds].filter(i=>i===this.documentNodeId||this.byId.has(i));t.length!==this.store.shell.selectedEntityIds.size&&this.store.shell.selectMultiple(t),this.store.notifyIngestObjectMapEdit()}))}get byId(){return this.projector.objects}get idByObject(){return this.projector.idsByObject}documentTypeLabel(){if(this.options.documentKind!=="asset")return;const e=this.scene.children.find(s=>this.idByObject.has(s))??null;if(!e)return;const t=El.get(e);if(t!==void 0)return t;const i=Ym(e);return El.set(e,i),i}hierarchy={roots:()=>[this.hierarchy.node(this.documentNodeId)],node:e=>{if(e===this.documentNodeId){const i=this.documentTypeLabel();return{id:e,label:this.options.title,secondaryLabel:this.options.sourcePath,role:"document",kind:this.options.documentKind==="asset"?"model-asset":"three-source",...i?{typeLabel:i}:{},parentId:null,childIds:this.view.rootIds()}}const t=this.byId.get(e);return t?this.view.node(t):null},object3D:e=>this.byId.get(e)??null,idForObject3D:e=>this.idByObject.get(e)??null};selection={get:()=>this.selectionState.current(),set:e=>this.selectionState.publish(e.filter(t=>t===this.documentNodeId||this.byId.has(t)))};static READ_ONLY_REASON="This document shows what the module builds; its properties are read-only here. Edit the module.";readOnly=()=>({writable:!1,reason:To.READ_ONLY_REASON});transforms={get:e=>qm(this.byId.get(e)??null),beginEdit:()=>{},apply:()=>{},endEdit:()=>{}};inspector={properties:e=>{if(e===this.documentNodeId)return this.options.audit===!1?[]:[{path:"name",label:"Name",type:"string",readonly:!0},{path:"source.path",label:"Source",type:"string",readonly:!0}];const t=this.byId.get(e);if(!t)return[];const i=Gt(t);if(i?.fields)return i.fields().map(({value:l,...c})=>c);const s=[{path:"name",label:"Name",type:"string",readonly:!0},{path:"visible",label:"Visible",type:"boolean",readonly:!0},{path:"object.type",label:"Native type",type:"string",readonly:!0}],r=t;if(r.isMesh&&r.geometry){const l=r.geometry.getAttribute("position");s.push({path:"mesh.vertices",label:"Vertices",type:"number",readonly:!0,group:"Mesh"}),l&&s.push({path:"mesh.triangles",label:"Triangles",type:"number",readonly:!0,group:"Mesh"})}const n=zl(t);n&&(s.push({path:"material.type",label:"Material",type:"string",readonly:!0,group:"Material"}),Ol(n)&&s.push({path:"material.color",label:"Color",type:"color",readonly:!0,group:"Material"}));const a=t;return a.isSkinnedMesh&&a.skeleton&&s.push({path:"skin.bones",label:"Bones",type:"number",readonly:!0,group:"Skin"}),s},get:(e,t)=>{if(e===this.documentNodeId)return t==="name"?this.options.title:t==="source.path"?this.options.sourcePath:void 0;const i=this.byId.get(e);if(!i)return;const r=Gt(i)?.fields?.().find(l=>l.path===t);if(r)return r.value();if(t==="name")return i.name||i.type;if(t==="visible")return i.visible;if(t==="object.type")return i.type;const n=i;if(t==="mesh.vertices")return n.geometry?.getAttribute("position")?.count??0;if(t==="mesh.triangles"){const l=n.geometry;return(l?.index?.count??l?.getAttribute("position")?.count??0)/3}const a=zl(i);if(t==="material.type")return a?.type;if(t==="material.color"){const l=Ol(a);return l?`#${l.getHexString()}`:void 0}if(t==="skin.bones")return i.skeleton?.bones.length??0},set:()=>{},editability:()=>this.readOnly()};subscribe(e){return this.store.shell.subscribe(e)}get documentId(){return this.documentNodeId}get documentRootObject(){const e=this.hierarchy.node(this.documentNodeId)?.childIds[0];return e?this.byId.get(e)??null:null}syncMarkedSelection(e){const t=new Set(e.map(i=>this.byId.get(i)??null).filter(i=>i!==null).filter(i=>Gt(i)?.selectionChanged!==void 0));for(const i of this.markedSelection)t.has(i)||Gt(i)?.selectionChanged?.(!1);for(const i of t)this.markedSelection.has(i)||Gt(i)?.selectionChanged?.(!0);this.markedSelection=t}}class Zm{constructor(e,t){this.frame=e,this.releaseRenderer=t,this.unsubscribeActivity=pu(()=>this.syncActivity())}rafId=0;running=!1;disposed=!1;active=!1;unsubscribeActivity;get isDisposed(){return this.disposed}get isRunning(){return this.running}setActive(e){this.disposed||(this.active=e,this.syncActivity())}syncActivity(){this.active&&_n()?this.start():this.stop()}redraw(){this.running&&!this.disposed&&_n()&&this.guardedFrame(performance.now())}dispose(){this.stop(),!this.disposed&&(this.disposed=!0,this.unsubscribeActivity(),this.releaseRenderer())}start(){this.disposed||this.running||(this.running=!0,this.guardedFrame(performance.now(),!0),!(!this.running||this.disposed)&&(this.rafId=requestAnimationFrame(this.tick)))}lastFrameFailure=null;guardedFrame(e,t=!1){try{this.frame(e,t),this.lastFrameFailure=null}catch(i){const s=i instanceof Error?i.message:String(i);s!==this.lastFrameFailure&&(this.lastFrameFailure=s,console.error("[document renderer] a frame threw; the loop continues:",i))}}stop(){this.running=!1,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0)}tick=e=>{if(!(!this.running||this.disposed)){if(!_n()){this.stop();return}this.guardedFrame(e),!(!this.running||this.disposed)&&(this.rafId=requestAnimationFrame(this.tick))}}}const Qm=new Set(["solid","clay","unlit","wireframe","normals","overdraw"]);function $m(o,e){return{read:()=>{const t=o.cameraPose;if(!t)return null;const{position:i,target:s}=t;return{camera:{position:{x:i.x,y:i.y,z:i.z},target:{x:s.x,y:s.y,z:s.z},...t.fov?{fov:t.fov}:{}},diagnostic:o.shadingMode,grid:rh(e)}},setDiagnostic:t=>Qm.has(t)?(o.setShadingMode(t),!0):!1,setCamera:t=>typeof t!="string"?(o.shell.setCameraPose(t.position,t.target,t.fov),!0):t==="isometric"?!1:(o.shell.setViewPreset(t),!0),frame:t=>t==="document"?!1:(o.shell.focusOnSelection(),!0)}}function Km(o){const e=Zn();return e?nh(Vl(e.shell,o)):"none"}const eg=k.lazy(()=>mi(()=>import("./stage-transform-tools-BGcIULoe.js"),__vite__mapDeps([4,5,6,7,8,9,10,11,12,13,14,15,2,1,16,17,18,19,20,21,22,23,24,25,26,27,28,29])).then(o=>({default:o.ThreeStageTransformTools}))),tg=k.lazy(()=>mi(()=>import("./stage-transform-tools-BGcIULoe.js"),__vite__mapDeps([4,5,6,7,8,9,10,11,12,13,14,15,2,1,16,17,18,19,20,21,22,23,24,25,26,27,28,29])).then(o=>({default:o.ThreeStageTransformControls})));function Tl(o){return{transformTools:()=>Km(o),TransformTools:eg,TransformControls:tg}}class ig{constructor(e,t,i){this.create=e,this.isOpen=t,this.subscribe=i}states=new Map;generations=new WeakMap;unsubscribe=null;claim(e){const t=this.states.get(e)??[];let i=t.find(s=>!s.inUse);return i||(i=this.create(e),t.push(i),this.states.set(e,t)),i.inUse=!0,this.generations.set(i,this.generation(i)+1),this.unsubscribe??=this.subscribe(()=>this.discardClosed()),i}generation(e){return this.generations.get(e)??0}release(e,t=this.generation(e)){this.generation(e)===t&&(e.inUse=!1,queueMicrotask(()=>this.discardClosed()))}retain(e,t,i){if(!this.isOpen(e.documentId)||!this.states.get(e.documentId)?.includes(e)||this.generation(e)!==i){t.dispose();return}const s=e.source;e.source=t,s!==t&&s?.dispose()}discardClosed(){const e=[];for(const[i,s]of this.states){if(this.isOpen(i))continue;const r=s.filter(n=>n.inUse);e.push(...s.filter(n=>!n.inUse)),r.length?this.states.set(i,r):this.states.delete(i)}this.states.size===0&&(this.unsubscribe?.(),this.unsubscribe=null);const t=[];for(const i of e){const s=i.source;i.source=null;try{s?.dispose()}catch(r){t.push(r)}}if(t.length)throw new AggregateError(t,"Retained document cleanup failed")}}const sg=k.lazy(async()=>({default:(await mi(()=>import("./stage-overlay-set-DRFcVd27.js"),__vite__mapDeps([30,5,6,8,9,7,10,11,12,13,14,15,2,1,16,17,18,31,32,21,22,23,24,25,26,27,28,29]))).StageOverlaySet}));function rg(o){return O.jsx(k.Suspense,{fallback:null,children:O.jsx(sg,{...o})})}function kl(o,e,t){if(e==="orthographic"){const i=Bi(o.camera.position.clone().sub(o.orbitControls.target),new v(0,1,0).applyQuaternion(o.camera.quaternion));return i!==null?i:t==="short"?"Iso":"Orthographic"}return t==="short"?"Persp":"Perspective"}let kr={projection:"perspective"};const ho=new Set;function Rl(){return kr}function ng(o){return ho.add(o),()=>ho.delete(o)}function Il(o){if(kr.projection!==o){kr={...kr,projection:o};for(const e of ho)e()}}const og=()=>()=>{},Ll=()=>0;function ag({shell:o,documentId:e,label:t,kebab:i=!1}){const s=k.useSyncExternalStore(ng,Rl,Rl);k.useSyncExternalStore(td,id);const r=e?sd(e):null;k.useSyncExternalStore(r?.subscribe??og,r?.getSnapshot??Ll,r?.getSnapshot??Ll);const n=r?r.projection():s.projection,a=p=>{r?r.setProjection(p):Il(p)},[l,c]=k.useState(!1),h=k.useRef(null);k.useEffect(()=>{if(!l)return;const p=u=>{h.current?.contains(u.target)||c(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[l]);const d=p=>{if(r){r.setViewPreset(p,"view");return}Il("orthographic"),o.setViewPreset(p)};return O.jsxs("div",{ref:h,className:"vgai-viewport-popover-anchor",children:[t===void 0?O.jsx(zi,{text:n==="perspective"?"Perspective":"Orthographic",children:O.jsx(ri,{"aria-label":"Viewport views","aria-expanded":l,size:"comfortable",onClick:()=>c(p=>!p),children:O.jsx(Pt,{icon:l?oh:ah,size:"md"})})}):O.jsxs(Mi,{size:"comfortable",variant:"ghost","aria-label":"Viewport views","aria-expanded":l,"data-testid":"viewport-view-name",onClick:()=>c(p=>!p),children:[i?O.jsx(Pt,{icon:lh,size:"sm"}):null,t]}),l?O.jsx(ch,{style:{minWidth:230},children:O.jsxs(hh,{gap:3,children:[O.jsx(ya,{variant:"caption",tone:"muted",children:"Projection"}),O.jsxs(_a,{gap:1,children:[O.jsx(Mi,{size:"compact",variant:n==="perspective"?"primary":"ghost",onClick:()=>a("perspective"),children:"Perspective"}),O.jsx(Mi,{size:"compact",variant:n==="orthographic"?"primary":"ghost",onClick:()=>a("orthographic"),children:"Orthographic"})]}),O.jsx(ya,{variant:"caption",tone:"muted",children:"Axis View"}),O.jsxs(_a,{gap:1,children:[O.jsx(Mi,{size:"compact",variant:"ghost",onClick:()=>d("top"),children:"Top"}),O.jsx(Mi,{size:"compact",variant:"ghost",onClick:()=>d("front"),children:"Front"}),O.jsx(Mi,{size:"compact",variant:"ghost",onClick:()=>d("right"),children:"Right"})]})]})}):null]})}const lg=fm;function Fl(o){return Xr(null,o)}const cg=()=>()=>{},Bl=()=>0,hg=5,dg=58;function ug(o,e){const t=e?.camera()??o.renderCamera,i=o.camera.position,s=o.orbitControls.target,r=t.isOrthographicCamera?xc(t,o,e):0;return[i.x,i.y,i.z,s.x,s.y,s.z,r].map(n=>n.toPrecision(6)).join(",")}function xc(o,e,t){const i=e.orbitControls.domElement,s=Math.max(1,t?.renderer.domElement.height??(i?.clientHeight??1)*(i?.ownerDocument.defaultView?.devicePixelRatio??1));return(o.top-o.bottom)/o.zoom/s}function pg({viewport:o,documentId:e,session:t,store:i,projection:s,displayName:r,objectName:n,statistics:a,subject:l,gridScale:c}){k.useSyncExternalStore(i.subscribe,i.getShellSnapshot??i.getSnapshot),k.useSyncExternalStore(k.useCallback(R=>{const N=o?.orbitControls;return N?.addEventListener("change",R),()=>N?.removeEventListener("change",R)},[o]),()=>o?ug(o,t):""),k.useSyncExternalStore(t?.subscribe??cg,t?.getSnapshot??Bl,t?.getSnapshot??Bl);const h=k.useSyncExternalStore(Fl,Ul),d=k.useSyncExternalStore(Fl,dh),p=h&&!d?vt.content.onAccent:vt.content.primary,u=uh();k.useSyncExternalStore(Rr,va,va);const f=Ti(e).overlays.navigationControls;if(!o)return null;const m=Bi(o.camera.position.clone().sub(o.orbitControls.target),new v(0,1,0).applyQuaternion(o.camera.quaternion))??"User",y=t?.projection()??s,_=t?.cameraView()??null,x=_?`Camera ${_.projection==="perspective"?"Perspective":"Orthographic"}`:`${m} ${y==="perspective"?"Perspective":"Orthographic"}`,S=i.selectedEntityId,w=(S===null?null:n(S))||null,C=l??(w===null||w===r?r:`${r} | ${w}`),b=t?.camera()??o.renderCamera,M=c&&!_&&m!=="User"&&b.isOrthographicCamera?c(xc(b,o,t)):null,P=R=>{R.preventDefault();const N=R.currentTarget;N.setPointerCapture(R.pointerId);const se=o.orbitControls.domElement?.getBoundingClientRect().top??0,ye=Math.max(5+R.clientY-se,1),q=o.camera,X=o.orbitControls.target,re=q.position.clone().sub(X),j=!t&&o.renderCamera instanceof Fi?o.renderCamera:null,$=j?.zoom??1,J=t?.cameraViewZoom()??null,ne=fe=>{const Ee=5+fe.clientY-se,be=Math.max(.01,2*(Ee/ye-1)+1);J!==null&&t?.cameraView()?t.setCameraViewZoom(J/be):j?(j.zoom=$/be,j.updateProjectionMatrix()):q.position.copy(X).addScaledVector(re,be),o.orbitControls.update()},Q=()=>{N.removeEventListener("pointermove",ne),N.removeEventListener("pointerup",Q),N.removeEventListener("pointercancel",Q),N.removeEventListener("lostpointercapture",Q)};N.addEventListener("pointermove",ne),N.addEventListener("pointerup",Q),N.addEventListener("pointercancel",Q),N.addEventListener("lostpointercapture",Q)},E=R=>{R.preventDefault();const N=R.currentTarget;N.setPointerCapture(R.pointerId);let se=R.clientX,ye=R.clientY;const q=new v,X=new v,re=$=>{const J=$.clientX-se,ne=$.clientY-ye;if(se=$.clientX,ye=$.clientY,t?.cameraView()){const Ne=t.renderer.domElement;t.panCameraView(J/Math.max(Ne.clientWidth,1),ne/Math.max(Ne.clientHeight,1));return}const Q=o.camera,fe=o.orbitControls.target,Ee=Q.position.distanceTo(fe),be=Math.max(1,N.ownerDocument.defaultView?.innerHeight??1),Be=2*Ee*Math.tan(Le.degToRad(Q.fov/2))/be;q.setFromMatrixColumn(Q.matrixWorld,0).multiplyScalar(-J*Be),X.setFromMatrixColumn(Q.matrixWorld,1).multiplyScalar(ne*Be),Q.position.add(q).add(X),fe.add(q).add(X),o.orbitControls.update()},j=()=>{N.removeEventListener("pointermove",re),N.removeEventListener("pointerup",j),N.removeEventListener("pointercancel",j),N.removeEventListener("lostpointercapture",j)};N.addEventListener("pointermove",re),N.addEventListener("pointerup",j),N.addEventListener("pointercancel",j),N.addEventListener("lostpointercapture",j)};return O.jsxs(O.Fragment,{children:[u.viewName==="text"?O.jsxs("div",{"data-testid":"viewport-view-text","aria-hidden":"true",style:{position:"absolute",top:"var(--vgai-space-3)",left:"calc(var(--vgai-space-4) + var(--vgai-control-comfortable-height) * 2 + var(--vgai-space-4))",display:"flex",flexDirection:"column",gap:"var(--vgai-space-1)",fontSize:"var(--vgai-font-sm)",color:p,textShadow:"var(--vgai-content-text-shadow, none)",pointerEvents:"none",userSelect:"none"},children:[O.jsx("span",{children:x}),O.jsx("span",{children:C}),M?O.jsx("span",{"data-testid":"viewport-grid-scale",children:M}):null,a&&a.length>0?O.jsx("div",{"data-testid":"viewport-statistics",style:{display:"grid",gridTemplateColumns:`${dg}px auto`,rowGap:"var(--vgai-space-1)",marginTop:ph[hg]},children:a.map(R=>O.jsxs(k.Fragment,{children:[O.jsx("span",{children:R.label}),O.jsx("span",{children:R.value})]},R.id))}):null]}):null,u.viewName==="menu"?O.jsx("div",{className:"vgai-viewport-view-pill",style:{position:"absolute",top:"var(--vgai-viewport-overlay-top, var(--vgai-space-4))",left:"var(--vgai-stage-name-left, calc(var(--vgai-space-4) + var(--vgai-control-comfortable-height) * 2 + var(--vgai-space-4)))",zIndex:"calc(var(--vgai-z-dropdown, 1000) - 1)",pointerEvents:"auto"},children:O.jsx(ag,{shell:i,documentId:e,label:kl(o,y,"long"),kebab:!0})}):null,u.viewName==="gizmo"?O.jsxs("button",{type:"button","data-testid":"viewport-view-name",className:"vgai-viewport-gizmo-label","aria-label":y==="perspective"?"Switch to orthographic":"Switch to perspective",onClick:()=>{const R=y==="perspective"?"orthographic":"perspective";t?t.setProjection(R):o.setProjection(R)},style:{position:"absolute",top:pm+4,right:um,transform:"translateX(50%)",display:"inline-flex",alignItems:"center",gap:"var(--vgai-space-1)",padding:0,border:0,background:"none",fontSize:"var(--vgai-font-sm)",color:p,textShadow:"var(--vgai-content-text-shadow, none)",cursor:"pointer",pointerEvents:"auto"},children:[O.jsx(Pt,{size:"xs",icon:y==="perspective"?fh:mh}),kl(o,y,"short")]}):null,f?O.jsxs("div",{"data-testid":"viewport-navigation",role:"toolbar","aria-label":"Navigation","aria-orientation":"vertical",className:"vgai-chrome-island vgai-viewport-navigation",style:{position:"absolute",top:lg,right:"var(--vgai-space-6)",display:"flex",flexDirection:"column",gap:"var(--vgai-space-1)",padding:"var(--vgai-space-1) 0",borderRadius:"var(--vgai-radius-full)",background:"var(--vgai-island-surface, var(--vgai-surface-overlay))",pointerEvents:"auto"},children:[O.jsx(zi,{text:"Zoom (drag)",children:O.jsx(ri,{size:"comfortable","aria-label":"Zoom the view",onPointerDown:P,children:O.jsx(Pt,{size:"2xl",icon:Mt.viewport.zoomIn})})}),O.jsx(zi,{text:"Pan (drag)",children:O.jsx(ri,{size:"comfortable","aria-label":"Pan the view",onPointerDown:E,children:O.jsx(Pt,{size:"2xl",icon:Mt.viewport.pan})})}),t?.hasCameraView()?O.jsx(zi,{text:_?"Leave the camera view":"Look through the camera",children:O.jsx(ri,{size:"comfortable","aria-label":"Toggle the camera view",onClick:()=>t.toggleCameraView(),children:O.jsx(Pt,{size:"2xl",icon:_?Mt.viewport.cameraView:Mt.viewport.camera})})}):null,_&&t?.cameraViewLocked()!==null?O.jsx(zi,{text:t?.cameraViewLocked()?"Unlock the camera from the view":"Lock the camera to the view",children:O.jsx(ri,{size:"comfortable","aria-label":"Lock the camera to the view",onClick:()=>t?.toggleCameraViewLock(),children:O.jsx(Pt,{size:"2xl",icon:t?.cameraViewLocked()?Mt.viewport.cameraLocked:Mt.viewport.cameraUnlocked})})}):null,_||u.viewName==="gizmo"?null:O.jsx(zi,{text:y==="perspective"?"Orthographic":"Perspective",children:O.jsx(ri,{size:"comfortable","aria-label":"Toggle perspective and orthographic",onClick:()=>{const R=y==="perspective"?"orthographic":"perspective";t?t.setProjection(R):o.setProjection(R)},children:O.jsx(Pt,{size:"2xl",icon:y==="orthographic"?Mt.viewport.projectionOrthographic:Mt.viewport.projection})})})]}):null,_&&t?O.jsx(fg,{view:_,canvas:t.renderer.domElement,locked:t.cameraViewLocked()===!0}):null]})}function fg({view:o,canvas:e,locked:t}){const[i,s]=k.useState(null),[,r]=k.useState(0);k.useEffect(()=>{const y=new ResizeObserver(()=>r(_=>_+1));return y.observe(e),()=>y.disconnect()},[e]);const n=e.clientWidth,a=e.clientHeight,l=e.ownerDocument.defaultView?.devicePixelRatio??1,c=e.getBoundingClientRect(),h=i?.getBoundingClientRect(),d=1/l,p=o.frame.left*n-d,u=o.frame.top*a-d,f=o.frame.width*n+2*d,m=o.frame.height*a+2*d;return O.jsx("div",{ref:s,"aria-hidden":"true",style:{position:"absolute",inset:0,pointerEvents:"none"},children:h?O.jsxs("svg",{"data-testid":"viewport-camera-frame",width:n,height:a,style:{position:"absolute",left:c.left-h.left,top:c.top-h.top},children:[o.passepartout.opacity>0?O.jsx("path",{d:`M0 0H${n}V${a}H0Z M${p} ${u}V${u+m}H${p+f}V${u}Z`,fill:o.passepartout.color,fillOpacity:o.passepartout.opacity,fillRule:"evenodd"}):null,o.passepartout.opacity>0?O.jsx("rect",{x:p,y:u,width:f,height:m,fill:"none",stroke:o.border.solid,strokeWidth:d,shapeRendering:"crispEdges"}):null,O.jsx("rect",{x:p,y:u,width:f,height:m,fill:"none",stroke:o.border.dashed,strokeWidth:d,strokeDasharray:`${3*d} ${3*d}`,shapeRendering:"crispEdges"}),t?O.jsx("rect",{x:p-d,y:u-d,width:f+2*d,height:m+2*d,fill:"none",stroke:o.border.locked,strokeWidth:d,strokeDasharray:`${3*d} ${3*d}`,shapeRendering:"crispEdges"}):null]}):null})}const mg=k.lazy(async()=>({default:(await mi(()=>import("./stage-keyboard-BY7u9_MB.js"),__vite__mapDeps([33,8,6,9,7,5,10,11,12,13,14,15,2,1,16,17,18,20]))).StageKeyboardBinding})),gg=o=>{const e=o.split(":");return(e[0]==="document"?e[1]:e[0])??o},Nl=()=>Gh(),Xn=12;function Hl(o){if(!o)return null;const e=new wt(new v(o.min[0],o.min[1],o.min[2]),new v(o.max[0],o.max[1],o.max[2]));return e.isEmpty()?null:e}const yg=500;function _g(o){return Xr(null,o)}const vg=["solid","preview","rendered","clay","unlit","wireframe","matcap","normals","overdraw"];let wg=0;const Ei=new ig(o=>({documentId:o,store:Wl(new jl),inUse:!1,source:null,camera:null,presentation:null,transport:null,contentSeconds:0,transportAdvances:0}),o=>Ch().some(e=>e.descriptor.id===o),Ph);function xg({canvasHostRef:o}){return O.jsx("div",{ref:o,style:{position:"absolute",inset:0}})}function bg(o,e,t,i,s){if(e==="inspector-preview"){const l=yd();return l.canvas.setAttribute("aria-label",`${t} authoring viewport`),o.appendChild(l.canvas),{canvas:l.canvas,renderer:l.renderer,lease:l}}const r=od(i.width,i.height,s),{canvas:n,renderer:a}=r;return n.setAttribute("aria-label",`${t} authoring viewport`),o.appendChild(n),{canvas:n,renderer:a,lease:r}}class Dl{constructor(e,t,i){this.lane=e,this.surface=t,this.store=i??Wl(new jl),this.transport=new jh(this.store.shell)}scene=new Jr;store;cleanups=[];rendererSession=new Zm((e,t)=>this.frame?.(e,t),()=>{});viewport=null;session=null;dressing=null;presentationRig=null;applyPresentation=null;backdropOverridden=!1;documentStudio=null;contentLights=[];contentHas={light:!1,"directional-light":!1};darkened=[];darkenContentLights(){for(const t of this.contentLights)t.visible&&(t.visible=!1,this.darkened.push(t));if(this.darkened.length===0)return 0;const e=this.darkened.length;return this.scene.onAfterRender=()=>{for(const t of this.darkened)t.visible=!0;this.darkened=[],this.scene.onAfterRender=()=>{}},e}defaultEnvironment=null;defaultBackground=null;adapter=null;presentationAdapter=null;content=null;frame=null;syncHostScene=null;presence=null;initialized=!1;contentSeconds=0;transportAdvances=0;users=0;closed=!1;released=!1;get isClosed(){return this.closed}transport;borrow(){this.users++;let e=!1;return()=>{e||(e=!0,this.users--,this.releaseIfClosed())}}close(){this.closed=!0,this.frame=null,this.syncHostScene=null,this.session?.setBeforeRender(null),this.session?.setPresentsFrames(!1),this.rendererSession.setActive(!1),this.content?.dispose(),this.transport.dispose(),this.releaseIfClosed()}releaseIfClosed(){if(!this.closed||this.users!==0||this.released)return;this.released=!0;const{lease:e,renderer:t,canvas:i}=this.surface;for(const s of[...this.cleanups.splice(0),()=>this.session?.dispose(),()=>this.viewport?.dispose(),()=>this.rendererSession.dispose(),()=>this.dressing?.dispose(),...e?[()=>e.release()]:[()=>t.dispose(),()=>t.forceContextLoss(),()=>i.remove()]])try{s()}catch(r){console.error("Object3D document cleanup failed.",r)}}}function bc({documentId:o,sourcePath:e,build:t,displayName:i="Source Object3D",background:s,cameraDirection:r,persistence:n,documentSource:a,authoring:l,interaction:c,selectionOutline:h=!0,active:d=!0,audit:p=!0,chromeless:u=!1,modelSource:f,assetType:m,sourceAuthoring:y,dressing:_,rendererLane:x="own",onOpenNode:S,frameBounds:w,openingFrameBounds:C,openingFit:b,openingView:M,presentation:P,cameraView:E,stageKind:R,statistics:N,subject:se,gridScale:ye,content:q}){const X=R??gg(o);k.useEffect(()=>{if(!u)return gh(o)},[o,u]);const re=rd(yh()),j=re??Zn(),$=j?Vl(j.shell,o,u?"embedded":"document"):null,J=k.useSyncExternalStore(_g,Ul),ne=$!==null&&_h($,J),Q=k.useRef(ne);Q.current=ne;const fe=$!==null&&vh($),Ee=k.useRef(fe);Ee.current=fe;const be=$!==null&&wh($),Be=k.useRef(be);Be.current=be;const Ne=xh(),_e=k.useRef(Ne);_e.current=Ne;const Jt=k.useRef(null),Yt=k.useRef(null),he=k.useRef(null),$e=k.useRef(null);(!$e.current||$e.current.documentId!==o)&&($e.current&&Ei.release($e.current),$e.current=Ei.claim(o)),k.useEffect(()=>{const Y=$e.current,Ke=Ei.generation(Y);return()=>Ei.release(Y,Ke)},[o]);const ce=$e.current,lt=q?.kind==="world-root",Zt=d||lt,gi=k.useRef(q?.kind==="world-root"?q.load:null);gi.current=q?.kind==="world-root"?q.load:null;const[ct,Qt]=k.useState(Zt);k.useEffect(()=>Qt(Zt),[Zt]);const $t=k.useRef(h);k.useEffect(()=>{$t.current=h;const Y=he.current?.session;Y&&(Y.selectionOutlineEnabled=x!=="inspector-preview"&&h),he.current?.applyPresentation?.()},[h,x]);const yi=k.useRef(Promise.resolve()),Kt=k.useRef(!1);k.useEffect(()=>{if(ct)return qi.current=!1,$r("building"),()=>{const Y=he.current;if(Y&&!lt){Kt.current=!ht.current;const Ke=Y.store.cameraPose;ce.camera=Ke&&Y.viewport?{...Ke,up:Y.viewport.camera.up.clone()}:null,ce.presentation=Y.session?.presentation()??null,ce.transport=Y.transport.snapshot(),ce.contentSeconds=Y.contentSeconds,ce.transportAdvances=Y.transportAdvances}$s.current=null,Ks.current=null,Qs.current=null,oe.current=null,Y?.close(),he.current=null}},[o,x,ce,ct,lt]);const zt=k.useRef(S);zt.current=S;const Ot=k.useRef(w);Ot.current=w;const Tt=k.useRef(C);Tt.current=C;const bt=k.useRef(M);bt.current=M;const kt=k.useRef(P);kt.current=P;const Rt=k.useRef(E);Rt.current=E;const ht=k.useRef(d);ht.current=d;const It=k.useRef(d),Lt=k.useRef({build:t,sourcePath:e});k.useEffect(()=>{const Y=Lt.current;Lt.current={build:t,sourcePath:e},!(Y.build===t&&Y.sourcePath===e)&&!ct&&ce.source&&(ce.source.dispose(),ce.source=null)},[t,ce,e,ct]);const oe=k.useRef(null),qi=k.useRef(!1),Qs=k.useRef(null),$s=k.useRef(null),Ks=k.useRef(null),[Zr,Ge]=k.useState(null),[Qr,$r]=k.useState("building"),[ko,Sc]=k.useState(null),[Mc,Cc]=k.useState("mounting"),[Pc,Ac]=k.useState([]),Ro=k.useRef(null),[Io,Ec]=k.useState("perspective"),[zc,Lo]=k.useState(null),er=k.useRef(null);er.current=zc;const Kr=r?.[0],en=r?.[1],tn=r?.[2],Ji=f?.kind,sn=f?.kind==="project-file"?f.path:void 0,tr=f?.kind==="entity"?f.entityId:void 0,Fo=_?.environment,Bo=_?.background,No=_?.keyLight,rn=_?.grid,Yi=_?.viewLocked,nn=_?.toneMapping;d&&bh(o),k.useEffect(()=>{let Y=!1;if(!ct)return;const Ke=async Ft=>{const me=Jt.current,Zi=Yt.current;if(!me||!Zi||he.current)return;const G=_e.current;if(!G){Ge("The world root needs the editor shell above it; this host has none.");return}const Qi=await Ft();if(Y||he.current)return;Sc(()=>Qi),wa();const g=new Dl("own",Qi.mountWorldRootSurface(Zi,me,i),Zn()??void 0);he.current=g,g.cleanups.push(xa(o,g.store.shell)),g.cleanups.push(ba(o,g.transport)),g.cleanups.push(Uh(o,{...$m(g.store,o),...Tl(o)}));const We=Qi.installWorldRootStage({store:g.store,documentId:o,container:me,canvas:g.surface.canvas,renderer:g.surface.renderer,stats:G,cameraPreview:()=>Ro.current,onMountStatus:Cc,onRootIds:Ac,runFrame:Bt=>La(o,Bt)});g.viewport=We.viewport,g.frame=We.frame,g.content={scene:We.scene,settle:()=>Promise.resolve(),dispose:async()=>We.dispose()};const ae=Ha(()=>g.store.scene??We.scene,g.transport,{rescanOnLiveMixers:()=>g.store.shell.playState==="stopped"});let Ue=0;g.cleanups.push(()=>ae.dispose()),g.cleanups.push(g.store.shell.subscribe(()=>{if(g.store.shell.playState!=="stopped")return;const Bt=performance.now();Bt-Ue<yg||(Ue=Bt,ae.refresh())})),g.cleanups.push(Fa({camera:We.viewport.camera,drawCamera:()=>We.viewport.renderCamera,orbit:We.viewport.orbitControls,scene:We.scene},We.present,We.setHelper,{documentId:o})),oe.current=g.rendererSession,g.initialized=!0,Pa(),$r("ready"),g.rendererSession.setActive(!0)},Tc=async()=>{for(await he.current?.content?.settle();vu();)await wu();if(Y)return;const Ft=gi.current;if(Ft)return Ke(Ft);const me=Jt.current,Zi=Yt.current;if(!me||!Zi)return;if(!t||e===void 0){Ge("This stage shows `build` content and was given no `build()`/`sourcePath`.");return}let G;const Qi=Ei.generation(ce);try{G=ce.source??t(),ce.source=null}catch(He){Ge(He instanceof Error?He.message:String(He));return}try{he.current||(wa(),he.current=new Dl(x,bg(Zi,x,i,{width:Math.max(1,me.clientWidth),height:Math.max(1,me.clientHeight)},()=>{Qt(!1),window.setTimeout(()=>{ht.current&&Qt(!0)},0)}),ce.store),he.current.contentSeconds=ce.contentSeconds,he.current.transportAdvances=ce.transportAdvances)}catch(He){throw G.dispose(),He}const g=he.current,We=g.borrow(),{renderer:ae,canvas:Ue,lease:Bt}=g.surface,le=g.store;u||(g.cleanups.push(xa(o,le.shell)),g.cleanups.push(ba(o,g.transport)));const sr=Sa();sr&&le.shell.attachHistory(sr);const an=x==="inspector-preview",_i=Q.current,Do=Ee.current,Vo=Be.current,de=new Jr,rr=G.root.parent;de.add(G.root),G.animations&&(G.root.animations=[...G.animations]);const ln={root:G.root,animations:G.root.animations};let vi=null,wi=null,xi=null,Nt=null,Ye=null,nr=null,or=null,ar=null,lr=null,cr=null,cn=null,Uo=null,jo=null,Go=!1,hr=!1,dr=null;const hn={scene:de,settle:()=>Ye?.settle()??Promise.resolve(),dispose:()=>{if(dr)return dr;hr=!0;const He=Kt.current;return Kt.current=!1,nr&&me.removeEventListener("pointerdown",nr,!0),or&&me.removeEventListener("pointermove",or,!0),ar&&me.removeEventListener("pointerup",ar,!0),lr&&me.removeEventListener("pointercancel",lr,!0),cr&&window.removeEventListener("keydown",cr),cn?.(),cn=null,dr=(async()=>{await Ye?.settle();const $i=[];for(const ur of[()=>Nt?.dispose(),()=>wi?.dispose?.(),()=>vi?.dispose(),()=>de.removeFromParent(),()=>{He?Ei.retain(ce,G,Qi):G.dispose()},We])try{ur()}catch(dt){$i.push(dt)}$i.length&&console.error("Object3D source cleanup failed.",...$i)})(),dr}};try{const He=async A=>{try{const B=ln;if(a&&!n){if(!B)throw new Error("Project history is unavailable; the edit was not saved.");const z=Sa();if(!z)throw new Error("Project history is unavailable; the edit was not saved.");const I=a.serialize(B);if(I===null)return Ge(null),!1;const H=await Nl().replaceSource(z,{file:a.path,source:I,label:A??a.label??`Edit ${i}`});return Ge(null),H}if(!n)throw new Error("This Asset Lab document has no persistence binding.");if(!xi||!B)throw new Error("Project history is unavailable; the edit was not saved.");const{persisted:U}=await(await xi).commit(B,A);return Ge(null),U}catch(B){throw Ge(B instanceof Error?B.message:JSON.stringify(B)),B}};vi=new To(le,de,{documentId:o,title:i,sourcePath:e,documentKind:Vo?"asset":"source",audit:p,...G.hierarchyRoots?{hierarchyRoots:G.hierarchyRoots}:{},...Ji==="project-file"&&sn?{modelSource:{kind:Ji,path:sn}}:Ji==="entity"&&tr?{modelSource:{kind:Ji,entityId:tr}}:{}});const $i={documentId:o,sourcePath:e,root:G.root,animations:G.root.animations,scene:de,defaultAdapter:vi,commit:He};wi=l?.($i)??null;const ur=wi?vi:null;!wi&&y&&(wi=y({store:le,scene:de,...G.hierarchyRoots?{hierarchyRoots:G.hierarchyRoots}:{}}),vi.dispose()),xi=n&&sr?Nl().openPersistence({binding:n,document:ln,history:sr}):null,xi&&xi.catch(A=>{!hr&&he.current?.content===hn&&Ge(A instanceof Error?A.message:JSON.stringify(A))});const dt=wi?.adapter??vi;if(!g.dressing){ae.outputColorSpace=rt,ae.toneMapping=nn??tc,ae.shadowMap.enabled=!0,ae.shadowMap.type=ru,ae.info.autoReset=!1,ae.setPixelRatio(Math.min(window.devicePixelRatio,2)),_i&&ae.setClearColor(0,0);const A=Fo===!1?null:Bt&&"environment"in Bt?Bt.environment():gd(ae),B=qn(Ue);g.dressing=cd(g.scene,{environment:A,background:!_i&&s===void 0&&Bo!==!1,keyLight:!1,grid:rn===!0,content:G.root}),!_i&&s!==void 0?g.scene.background=new V(s):!_i&&B.background!==null&&(g.scene.background=new V(B.background)),g.defaultEnvironment=g.scene.environment,g.defaultBackground=g.scene.background;{const U=new Xl(g.scene,K);g.presentationRig=U,Jn(o,X);const z=()=>{const I=Ti(o);if(U.apply(I,ae,nn),g.viewport?.setStageFunction(I.world,I.interaction),g.viewport?.setFieldOfView(I.camera.fov),g.viewport?.setSelectionMarks(I.overlays.selection),g.viewport?.setGridMajorEvery(I.overlays.grid.majorEvery),g.viewport?.setAxisLines(I.overlays.axes),g.viewport?.setNavigation(I.overlays.navigation),g.viewport?.setGridVisible(I.overlays.grid.visible),g.session){const H=g.session.presentation().mode==="wireframe"&&I.xray.enabled&&I.xray.alpha<=0;g.session.selectionOutlineEnabled=!an&&$t.current&&I.overlays.selection.outline&&!H,g.session.selectionOriginsEnabled=!an&&I.overlays.selection.origins,g.session.setXray(I.xray)}K()};g.applyPresentation=z,z(),g.cleanups.push(Rr(z)),g.cleanups.push(Ah(()=>{U.forgetFailedImages(),z()})),g.cleanups.push(()=>{U.dispose(),g.presentationRig===U&&(g.presentationRig=null)})}g.cleanups.push(()=>{g.defaultBackground instanceof Ia&&g.defaultBackground!==g.dressing?.backgroundTexture&&g.defaultBackground.dispose()})}const Wo=(A,B)=>{const U=g.adapter,z=g.viewport;if(!U||!z)return null;const I=Ue.getBoundingClientRect(),H=new je((A-I.left)/Math.max(I.width,1)*2-1,-((B-I.top)/Math.max(I.height,1))*2+1),ee=new nt;ee.layers.enableAll(),ee.params.Line2={threshold:4},ee.setFromCamera(H,g.session?.camera()??z.camera);const Pe=g.presentationAdapter,St=we=>{for(let Me=we;Me;Me=Me.parent){const ts=Pe?.hierarchy.idForObject3D?.(Me)??U.hierarchy.idForObject3D?.(Me);if(ts)return ts}return null};let ti=null;for(const we of ee.intersectObjects([...le.objectMap.values()],!0)){if(gt(we.object))continue;const Me=St(we.object);if(Me){ti={distance:we.distance,id:Me};break}}const gr=z.visibleHelpers().filter(we=>we.userData.vgaiPickable===!0);for(const we of ee.intersectObjects(gr,!0)){let Me=null,ts=!0;for(let is=we.object;is;is=is.parent)is.visible||(ts=!1),Me??=is.userData.vgaiPicksAs??null;if(!ts)continue;const oa=Me?St(Me):null;if(oa){(!ti||we.distance<ti.distance)&&(ti={distance:we.distance,id:oa});break}}return ti?.id??null};if(!g.viewport){g.viewport=new Oo(Ue,g.scene,le,me,{renderer:ae,authoring:()=>g.adapter??dt,pick:Wo,drawCamera:()=>g.session?.camera()??g.viewport.camera,publishPickContext:!1,onProjectionChange:Ec,chromeInsetPx:u||Do?0:Xn,lightRig:!1}),rn===!0&&g.viewport.grid.removeFromParent();const A=B=>{const U=Wo(B.clientX,B.clientY),z=U&&g.adapter?oi(g.adapter.hierarchy,U):null;z&&zt.current?.(z)};me.addEventListener("dblclick",A),g.cleanups.push(()=>me.removeEventListener("dblclick",A))}const D=g.viewport;if(Yi){const A=D.camera;g.scene.add(A);const B=new Ve;B.name="vgai:document-studio",B.add(Yi),A.add(B),g.documentStudio=B,g.cleanups.push(()=>{Yi.removeFromParent(),B.removeFromParent(),g.documentStudio===B&&(g.documentStudio=null),A.removeFromParent()})}if(c){const A=new Ve;A.name="__object3d_document_overlay",qe(A,"editorHelper",!0),de.add(A),Nt=c.setup({root:G.root,scene:de,renderer:ae,overlay:A,camera:()=>g.session?.camera()??D.camera,writable:n!==void 0||a!==void 0});const B=z=>{const I=Ue.getBoundingClientRect(),H=new je((z.clientX-I.left)/Math.max(I.width,1)*2-1,-((z.clientY-I.top)/Math.max(I.height,1))*2+1),ee=new nt;return ee.layers.enableAll(),ee.setFromCamera(H,g.session?.camera()??D.camera),{pointerId:z.pointerId,button:z.button,buttons:z.buttons,clientX:z.clientX,clientY:z.clientY,altKey:z.altKey,ctrlKey:z.ctrlKey,metaKey:z.metaKey,shiftKey:z.shiftKey,ray:ee.ray.clone(),hits:ee.intersectObjects([G.root,A],!0)}};Ye=new km({begin:z=>{if(!n&&!a)throw new Error("This Asset Lab document has no persistence binding; project gestures are read-only.");return Nt.begin(z)},persist:async z=>{await He(z)},reportError:z=>Ge(z instanceof Error?z.message:JSON.stringify(z))});const U=z=>{z.preventDefault(),z.stopPropagation()};nr=z=>{z.target instanceof Element&&z.target.closest('[role="alert"], [role="toolbar"]')!==null||Ye?.begin(B(z))&&(U(z),z.isTrusted&&Ue.setPointerCapture?.(z.pointerId))},or=z=>{Ye?.hasActiveGesture()&&(U(z),Ye.update(B(z)))},ar=z=>{Ye?.hasActiveGesture()&&(U(z),Ue.hasPointerCapture?.(z.pointerId)&&Ue.releasePointerCapture?.(z.pointerId),Ye.commit(B(z)))},lr=z=>{Ye?.hasActiveGesture()&&(U(z),Ye.cancel(z.pointerId))},cr=z=>{z.key!=="Escape"||!Ye?.hasActiveGesture()||(z.preventDefault(),Ye.cancel())},Uo=()=>{me.addEventListener("pointerdown",nr,!0),me.addEventListener("pointermove",or,!0),me.addEventListener("pointerup",ar,!0),me.addEventListener("pointercancel",lr,!0),window.addEventListener("keydown",cr)}}const ei=g.content,Xo=[...le.shell.selectedEntityIds],Ki=g.adapter,Rc=g.presentationAdapter,Ic=new Map(le.objectMap),bi=g.session?.root,Lc=g.frame,Fc=g.syncHostScene,Bc=$s.current,Nc=Ks.current,Hc=Qs.current,qo=g.session?.neutralBackgroundTexture(),Dc=g.dressing.lights.map(A=>A.visible),Vc=g.cleanups.length,Uc=g.initialized;if(jo=()=>{de.removeFromParent(),rr&&rr.add(G.root),ei&&g.scene.add(ei.scene),g.adapter=Ki,g.presentationAdapter=Rc,g.content=ei,g.frame=Lc,g.syncHostScene=Fc,g.initialized=Uc;for(const A of g.cleanups.splice(Vc))A();!bi&&g.session&&(g.session.dispose(),g.session=null),le.objectMap.clear();for(const[A,B]of Ic)le.objectMap.set(A,B);ei&&le.bindScene(ei.scene,ae,D.batchedRenderer,D.camera),bi&&Ki&&g.session?.replaceContent(bi,Ki),$s.current=Bc,Ks.current=Nc,Qs.current=Hc,er.current=Ki,Lo(Ki),qo!==void 0&&g.session?.setNeutralBackground(qo),g.dressing?.lights.forEach((A,B)=>{A.visible=Dc[B]??!0}),bi&&(g.dressing?.frameContent(bi),g.presentationRig?.placeFloor(bi)),le.shell.selectMultiple(Xo),le.notifyIngestObjectMapEdit()},ei?.scene.removeFromParent(),g.scene.add(de),g.adapter=dt,g.presentationAdapter=ur,g.content=hn,le.bindScene(de,ae,D.batchedRenderer,D.camera),le.setOrbitTarget(D.orbitControls.target),le.objectMap.clear(),de.traverse(A=>{const B=ur?.hierarchy.idForObject3D?.(A)??dt.hierarchy.idForObject3D?.(A);B&&le.objectMap.set(B,A)}),g.session)g.session.replaceContent(G.root,dt);else{const A=Hl(Ot.current),B=Hl(Tt.current)??A,U=Ti(o).camera;D.setFieldOfView(U.fov);const z=bt.current,I=Kr!==void 0&&en!==void 0&&tn!==void 0;if(!z&&!I){const H=D.orbitControls.target,ee=D.camera.position.distanceTo(H);D.camera.position.copy(H).addScaledVector(new v(...U.opening).normalize(),ee)}if(B||D.focusOn(G.root),z){const H=new v(...z.target),ee=new v(...z.direction).normalize();D.camera.position.copy(H).addScaledVector(ee,z.distance),D.camera.up.set(0,1,0),z.up&&D.camera.up.set(...z.up),D.orbitControls.target.copy(H)}else if(I){const H=B??li(G.root),ee=H.getCenter(new v),Pe=new v(Kr,en,tn).normalize(),St=hi(H,D.camera,Pe)*Math.min(10,Math.max(.1,b??1));D.camera.position.copy(ee).add(Pe.multiplyScalar(St)),D.orbitControls.target.copy(ee)}if(g.session=new Em(o,G.root,g.scene,ae,D,dt,_i?null:s===void 0?g.dressing.backgroundTexture:new V(s),A),g.session.selectionOutlineEnabled=!an&&$t.current,g.session.setCameraViewSource(Rt.current??null),g.applyPresentation?.(),bt.current?.projection==="orthographic"&&g.session.setProjection("orthographic"),!_i&&s===void 0&&g.dressing.backgroundTexture){const H=g.session;g.cleanups.push(hd(()=>{const ee=qn(Ue).background,Pe=g.defaultBackground;g.defaultBackground=ee!==null?new V(ee):dd(),H.neutralBackgroundTexture()===Pe&&H.setNeutralBackground(g.defaultBackground),Pe instanceof Ia&&Pe!==g.dressing?.backgroundTexture&&Pe.dispose()}))}}const es=ce.camera;es&&(D.setPose(es.position,es.target,es.fov||void 0,es.up),D.setProjection(Io),ce.camera=null);const ve=g.session;$s.current=ln,Ks.current=xi,Qs.current=Nt,er.current=dt,Lo(dt);const dn=Eh(X)?.all?.lighting!==void 0||zh(X)?null:Yi?{all:{lighting:{source:"studio",studioPreset:Ma.id,auto:null}}}:No===!1?{all:{lighting:{source:"scene"}}}:null,un=kt.current??null;Jn(o,X,dn&&un?Oh(dn,un):un??dn);const pn=new Set(vg);let Jo;const Yo=()=>{const A=g.session?.presentation().mode;A!==Jo&&(Jo=A,g.applyPresentation?.()),!(A===void 0||!pn.has(A))&&Ti(o).drawMode!==A&&Th(o,{drawMode:A})},fn=kh(o).drawMode;fn!==void 0&&pn.has(fn)&&g.session?g.session.setMode(fn):Yo();const jc=g.session?.subscribe(Yo),Gc=Rr(()=>{const A=g.session,B=Ti(o).drawMode;A&&A.presentation().mode!==B&&pn.has(A.presentation().mode)&&A.setMode(B)});g.cleanups.push(()=>{jc?.(),Gc()});const pr=[];G.root.traverse(A=>{A.isLight&&pr.push(A)});const Wc={light:pr.length>0,"directional-light":pr.some(A=>A.isDirectionalLight)};g.contentLights=pr,g.contentHas=Wc,g.dressing.frameContent(G.root),g.presentationRig?.placeFloor(G.root),g.cleanups.push(le.shell.subscribe(()=>g.presentationRig?.placeFloor(G.root)));const Zo=new Set;le.shell.selectMultiple(Xo.filter(A=>{const B=le.objectMap.get(A)??oi(dt.hierarchy,A);if(B===null&&!le.objectMap.has(A))return!1;const U=B??A;return Zo.has(U)?!1:(Zo.add(U),!0)})),le.notifyIngestObjectMapEdit(),ve.syncSelectionPresentation(),Uo?.(),Ge(null),u||Ca(o);let fr=de.background;ve.setNeutralBackground(fr??g.defaultBackground);const Si=ce.presentation;Si&&(ve.setMode(Si.mode),ve.setBackground(Si.background),ve.setProjection(Si.projection),ve.setSkeleton(Si.skeleton),ve.setBounds(Si.bounds),ce.presentation=null);const Xc=()=>{g.viewport?.alignGridToView(ve.camera(),ae.domElement.width),g.scene.environment=de.environment??g.defaultEnvironment,g.scene.fog=de.fog,g.scene.environmentIntensity=de.environmentIntensity,g.scene.environmentRotation.copy(de.environmentRotation),g.scene.backgroundIntensity=de.backgroundIntensity,g.scene.backgroundBlurriness=de.backgroundBlurriness,g.scene.backgroundRotation.copy(de.backgroundRotation);const A=g.presentationRig;if(A){const B=A.resolveSource({...g.contentHas,environment:de.environment!==null}),U=A.environment();U&&(g.scene.environment=U.texture??g.defaultEnvironment,g.scene.environmentIntensity=U.intensity,g.scene.environmentRotation.set(0,U.rotation,0));const z=A.backdrop();z!=="keep"?(g.scene.background=z.value,g.scene.backgroundBlurriness=z.blur,g.scene.backgroundIntensity=z.intensity,g.scene.backgroundRotation.set(0,z.rotation,0),g.backdropOverridden=!0):g.backdropOverridden&&(g.scene.background=ve.neutralBackgroundTexture(),g.scene.backgroundBlurriness=de.backgroundBlurriness,g.scene.backgroundIntensity=de.backgroundIntensity,g.backdropOverridden=!1);const I=B==="studio"&&A.presetId()===Ma.id;g.documentStudio&&(g.documentStudio.visible=I);const H=B==="studio"&&!I||B==="preview"&&!A.sceneLightsShown()?g.darkenContentLights():0;A.update(ve.camera()),Rh(o,{source:B,presetId:A.presetId(),presetLights:A.lightsVisible(),documentStudio:g.documentStudio?g.documentStudio.visible:null,contentLights:g.contentLights.length,contentLightsDarkened:H,environmentIntensity:g.scene.environmentIntensity,environmentImage:A.imageReport().shown,environmentImagePending:A.imageReport().pending,toneMapping:String(ae.toneMapping)})}fr!==de.background&&(fr=de.background,ve.setNeutralBackground(fr??g.defaultBackground))};g.syncHostScene=Xc,ve.setBeforeRender(()=>g.syncHostScene?.()),ve.setPresentsFrames(!0);const qc=A=>{hr||!(A>0)||!Number.isFinite(A)||(g.contentSeconds+=A,g.transportAdvances++,G.update?.(A))},Jc=Ha(G.root,g.transport);g.cleanups.push(()=>Jc.dispose());const Ht=ce.transport;Ht&&(Ht.activeSubject&&g.transport.setActiveSubject(Ht.activeSubject),g.transport.setLoop(Ht.range.loop),g.transport.setTimeScale(Ht.timeScale),g.transport.seek(Ht.time),Ht.playbackState==="playing"?g.transport.play():Ht.playbackState==="paused"&&g.transport.pause(),ce.transport=null);let mn=performance.now();const Qo=typeof G.onChange=="function";let gn=!0;const mr=()=>{gn=!0};if(Qo){const A=G.onChange(mr),B=le.shell.subscribe(mr),U=["pointerdown","pointermove","pointerup","pointerleave","wheel","keydown","keyup"];for(const z of U)me.addEventListener(z,mr,{capture:!0,passive:!0});cn=()=>{A(),B();for(const z of U)me.removeEventListener(z,mr,{capture:!0})}}let $o=-1;const Ko=new Xt,ea=new Xt,ta=new je,ia=new je;let sa,ra=null,na=Number.NaN;const Yc=A=>{if(!Qo||gn||A>0||Ea()!==$o||ve.needsFrame()||g.presence?.live()||Nt?.prepareFrame||Nt?.update||(D.batchedRenderer.batches?.length??0)>0)return!0;const B=ve.camera();return B.updateMatrixWorld(),ae.getDrawingBufferSize(ia),!B.matrixWorld.equals(Ko)||!B.projectionMatrix.equals(ea)||!ia.equals(ta)||g.scene.background!==sa||ae.toneMapping!==ra||ae.toneMappingExposure!==na},Zc=()=>{gn=!1,$o=Ea();const A=ve.camera();Ko.copy(A.matrixWorld),ea.copy(A.projectionMatrix),ae.getDrawingBufferSize(ta),sa=g.scene.background,ra=ae.toneMapping,na=ae.toneMappingExposure},Qc=(A,B)=>{if(hr||!ae||!D)return;const U=ae,z=D,I=ve?.profiler;I?.beginFrame(),B&&(mn=A);const H=Math.min((A-mn)/1e3,.1);mn=A,I?.beginPhase();const ee=g.transport.tick(H);if(ee>0&&qc(ee),Nt?.prepareFrame?.(H),Nt?.update?.(H),I?.endPhase("animation"),I?.beginPhase(),g.presence?.syncMarkers(H),D.update(H),u||La(o,H),D.batchedRenderer.update(H),I?.endPhase("editor"),!B&&!Yc(ee)){I?.endFrame();return}I?.beginPhase(),U.info.reset();const Pe=!qi.current&&Ih()===o;Pe&&Lh(o);const St=Pe?Date.now():0,ti=g.scene.overrideMaterial,gr=ve.presentation().mode;gr!=="uv"&&gr!=="vertex-colors"&&(g.scene.overrideMaterial=de.overrideMaterial);try{z.renderWithInfrastructure(()=>{ve.renderViewport(H),z.renderViewCube(U)})}finally{g.scene.overrideMaterial=ti}ve.servePresentedFrame(),Zc(),qi.current||(qi.current=!0,Pe&&Fh("first-render",Date.now()-St),Bh(o),$r("ready")),I?.reportRender({gpuMs:null,drawCalls:U.info.render.calls,triangles:U.info.render.triangles,geometries:U.info.memory.geometries,textures:U.info.memory.textures}),I?.endPhase("render"),I?.endFrame();const we=_e.current;if(we&&re&&Nh(re.shell)===le.shell){const Me=ve.cameraPose();we.frameTime=H*1e3,we.fps=H>0?1/H:0,we.drawCalls=U.info.render.calls,we.triangles=U.info.render.triangles,we.cameraPosition.x=Me.position[0],we.cameraPosition.y=Me.position[1],we.cameraPosition.z=Me.position[2],we.cameraTarget.x=Me.target[0],we.cameraTarget.y=Me.target[1],we.cameraTarget.z=Me.target[2]}};if(g.frame=Qc,oe.current=g.rendererSession,!g.initialized){u||(g.cleanups.push(Fa({camera:D.camera,drawCamera:()=>g.session?.camera()??D.camera,orbit:D.orbitControls,scene:g.scene},()=>null,(I,H)=>D.setHelper(I,H),{documentId:o})),mi(()=>import("./stage-presence-markers-D2IpuOAY.js"),__vite__mapDeps([34,5,6,8,9,10,11,7,12,13,14,2,1])).then(I=>{if(g.isClosed||he.current!==g||g.presence)return;const H=I.bindStagePresenceMarkers({scene:g.scene,store:le,documentId:o,container:me,canvas:Ue,viewport:D,readVisibleCameraPose:()=>{const ee=g.session?.camera()??D.renderCamera,Pe=ee.getWorldPosition(new v),St=ee.fov;return{position:Pe,target:D.orbitControls.target,fov:typeof St=="number"?St:0}}});g.presence=H,g.cleanups.push(()=>H.dispose())}),g.cleanups.push(nd(ve,Tl(o))),g.cleanups.push(Hh({id:o,label:i,kind:Vo?"asset":"source",profiler:ve.profiler}))),!u&&!Do&&g.cleanups.push(Dh(o,()=>({adapter:g.adapter,nodeId:g.adapter?.selection?.get()[0]??null})));const A=u?`${o}#chromeless-${++wg}`:o;g.cleanups.push(Vh({id:A,label:i,contentClock:()=>g.contentSeconds,transportAdvances:()=>g.transportAdvances})),g.cleanups.push(le.shell.onViewportAction(I=>{switch(I.type){case"focus-selection":case"focus-scene":!g.session?.frame()&&g.session?.root&&D.focusOn(g.session.root);break;case"focus-entity":{const H=g.adapter?oi(g.adapter.hierarchy,I.id):null;H&&D.focusOn(H);break}case"snap-selection-to-floor":D.snapSelectionToFloor();break;case"set-view-preset":g.session?g.session.setViewPreset(I.preset==="perspective"?"isometric":I.preset,"view"):D.setViewPreset(I.preset);break;case"toggle-camera-view":g.session?.toggleCameraView();break;case"frame-all":!g.session?.frame(1,"all")&&g.session?.root?D.focusOn(g.session.root):g.session||D.focusOnScene();break;case"zoom-view":g.session?.cameraView()&&!g.session.cameraViewLocked()?g.session.zoomCameraView(I.direction>0?1.2:1/1.2):D.zoomStep(I.direction);break;case"step-view":if(g.session?.cameraView()&&!g.session.cameraViewLocked())break;D.stepView(I.step);break;case"toggle-projection":{const H=g.session;if(H?.cameraView())break;const Pe=(H?H.projection():D.projection)==="perspective"?"orthographic":"perspective";H?H.setProjection(Pe):D.setProjection(Pe);break}case"set-camera-pose":D.setPose(I.position,I.target,I.fov);break}}));let B="";g.cleanups.push(le.shell.subscribe(()=>{D.objectMap=le.objectMap,D.syncFromStore(),g.session?.syncSelectionPresentation();const I=(g.adapter?.selection?.get()??[]).join("\0");I!==B&&(B=I,u||Ca(o))}));const U=()=>{const I=Math.max(1,me.clientWidth),H=Math.max(1,me.clientHeight),ee=ae.getPixelRatio();(Ue.width!==Math.floor(I*ee)||Ue.height!==Math.floor(H*ee))&&ae.setSize(I,H,!1),D.resize(I,H),g.session?.resize(I,H),g.rendererSession.redraw()},z=new ResizeObserver(U);z.observe(me),g.cleanups.push(()=>z.disconnect()),U(),g.initialized=!0,Pa()}D.objectMap=le.objectMap,D.syncFromStore(),g.rendererSession.setActive(ht.current),g.rendererSession.redraw(),Go=!0,ei?.dispose()}catch(He){if(!Go)try{jo?.()}finally{rr&&G.root.parent===de&&rr.add(G.root),hn.dispose()}console.error(`[object3d document] ${i}: source update failed`,He),Ge(He instanceof Error?He.message:String(He))}},kc=yi.current.then(Tc);return yi.current=kc.catch(Ft=>{Y||Ge(Ft instanceof Error?Ft.message:String(Ft))}),()=>{Y=!0}},[l,s,t,Kr,en,tn,i,o,ne,Bo,Fo,rn,No,Yi,nn,u,tr,Ji,sn,c,n,a,x,ce,ct,y,e,lt]),k.useEffect(()=>{const Y=oe.current,Ke=d&&!It.current;It.current=d,Y&&(Ke&&(qi.current=!1,Sh(o)),Y.setActive(d||lt))},[d,o,lt]);const ir=he.current,on=Qr==="ready"&&ir?.viewport?{store:ir.store,viewport:ir.viewport,canvas:ir.surface.canvas}:null,Oc=k.useCallback(()=>{const Y=er.current;return Y?{adapter:Y,nodeId:Y.selection?.get()[0]??Y.hierarchy.roots()[0]?.id??null}:null},[]),Ho=O.jsx("div",{"data-testid":"tool-object3d-authoring","data-vgai-chromeless":u||void 0,className:ne?"vgai-object3d-studio-stage":void 0,style:{position:u||fe?"relative":"absolute",...u?{width:"100%",height:"100%"}:fe?{flex:1,minHeight:0}:{inset:-Xn},overflow:"hidden",background:ne?void 0:vt.surface.raised,pointerEvents:"auto"},children:O.jsxs("div",{ref:Jt,style:{position:"absolute",inset:0,minHeight:0,overflow:"hidden"},children:[O.jsx(xg,{canvasHostRef:Yt}),d&&on&&!u?O.jsx(k.Suspense,{fallback:null,children:O.jsx(mg,{stage:on})}):null,re&&!u?O.jsx(rg,{store:re,documentId:o,stage:on,active:d,chrome:"document"}):null,re&&ko?O.jsx(ko.Overlays,{store:re,documentId:o,cameraPreviewRef:Ro,mountStatus:Mc,rootIds:Pc}):null,Zr&&O.jsx("div",{role:"alert",style:{position:"absolute",insetInline:0,top:0,display:"flex",justifyContent:"center",padding:"var(--vgai-space-3)",pointerEvents:"none"},children:O.jsxs("div",{className:"vgai-chrome-island",style:{display:"flex",alignItems:"center",gap:"var(--vgai-space-3)",maxWidth:"80%",padding:"var(--vgai-space-2) var(--vgai-space-3)",borderRadius:"var(--vgai-radius-md)",border:`var(--vgai-stroke-resting) solid ${vt.semantic.danger}`,background:vt.surface.raised,color:vt.semantic.danger,pointerEvents:"auto"},children:[O.jsx("span",{children:Zr}),O.jsx(ri,{size:"compact","aria-label":"Dismiss",onClick:()=>Ge(null),"data-testid":"object3d-document-error-dismiss",children:O.jsx(Pt,{icon:Mt.action.close})})]})}),!Zr&&Qr==="building"&&O.jsx(ad,{testId:"object3d-document-status",children:ld}),O.jsx("div",{style:{position:"absolute",inset:u||fe?0:Xn,pointerEvents:"none"},children:!u&&Qr==="ready"&&he.current&&O.jsx(pg,{viewport:he.current.viewport,documentId:o,session:he.current.session,store:he.current.store.shell,projection:Io,displayName:i,...N?{statistics:N}:{},...se!==void 0?{subject:se}:{},...ye?{gridScale:ye}:{},objectName:Y=>(Ke=>Ke?oi(Ke.hierarchy,Y)?.name:void 0)(he.current?.adapter)??he.current?.store.objectMap.get(Y)?.name??null})})]})});return fe?O.jsx(Mh,{documentId:o,active:d,type:m??(tr?"entity":"model"),title:i,status:e,selection:Oc,fill:!0,children:O.jsxs("div",{className:"vgai-object3d-asset-workspace",children:[Ho,O.jsx(fu,{transport:he.current?.transport??null})]})}):Ho}function Sg(o){return O.jsx(bc,{...o})}const Wg=Object.freeze(Object.defineProperty({__proto__:null,Object3DDocumentViewport:bc,ToolObject3DAuthoring:Sg},Symbol.toStringTag,{value:"Module"}));export{wo as C,Ur as G,bc as O,Gg as Q,Wg as S,W as V,ag as a,kl as s,Km as t};
|