@hology/core 0.0.212 → 0.0.214
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/effects/sequence/index.d.ts +1 -0
- package/dist/effects/sequence/index.js +1 -1
- package/dist/effects/sequence/sequence-action.d.ts +5 -0
- package/dist/effects/sequence/sequence-actor.d.ts +7 -0
- package/dist/effects/sequence/sequence-actor.js +1 -1
- package/dist/effects/sequence/sequence-animation-retiming.js +1 -1
- package/dist/effects/sequence/sequence-data.d.ts +9 -0
- package/dist/effects/sequence/sequence-data.js +1 -1
- package/dist/effects/sequence/sequence-player.d.ts +12 -1
- package/dist/effects/sequence/sequence-player.js +1 -1
- package/dist/effects/sequence/sequence-transform.d.ts +10 -0
- package/dist/effects/sequence/sequence-transform.js +4 -0
- package/dist/effects/sequence/sequence-value-lane.d.ts +2 -0
- package/dist/effects/sequence/sequence-value-lane.js +1 -1
- package/dist/effects/vfx/initializsers.d.ts +4 -0
- package/dist/effects/vfx/initializsers.js +1 -1
- package/dist/effects/vfx/vfx-actor.d.ts +5 -0
- package/dist/effects/vfx/vfx-actor.js +1 -1
- package/dist/effects/vfx/vfx-asset.d.ts +2 -1
- package/dist/effects/vfx/vfx-asset.js +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-renderers.d.ts +1 -0
- package/dist/effects/vfx/vfx-renderers.js +1 -1
- package/dist/gameplay/actors/actor.d.ts +9 -5
- package/dist/gameplay/actors/actor.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-animation.d.ts +3 -0
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement-like.d.ts +2 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +13 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.d.ts +4 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.js +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.d.ts +1 -0
- package/dist/gameplay/actors/builtin/components/mesh-component.js +1 -1
- package/dist/gameplay/actors/builtin/components/tween-component.js +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.d.ts +2 -0
- package/dist/gameplay/actors/builtin/navmesh-actor.js +1 -1
- package/dist/gameplay/actors/builtin/trigger-volume.d.ts +3 -3
- package/dist/gameplay/actors/builtin/trigger-volume.js +1 -1
- package/dist/gameplay/actors/camera/camera-component.d.ts +1 -3
- package/dist/gameplay/actors/camera/camera-component.js +1 -1
- package/dist/gameplay/actors/component.d.ts +9 -0
- package/dist/gameplay/actors/component.js +1 -1
- package/dist/gameplay/actors/type-registry.d.ts +10 -0
- package/dist/gameplay/actors/type-registry.js +4 -0
- package/dist/gameplay/animation/retarget.d.ts +50 -0
- package/dist/gameplay/animation/retarget.js +4 -0
- package/dist/gameplay/animation/root-motion.js +1 -1
- package/dist/gameplay/event-graph/actor-transform-properties.d.ts +6 -0
- package/dist/gameplay/event-graph/actor-transform-properties.js +4 -0
- package/dist/gameplay/event-graph/asset-actor-types.d.ts +3 -0
- package/dist/gameplay/event-graph/asset-actor-types.js +4 -0
- package/dist/gameplay/event-graph/asset-references.d.ts +12 -0
- package/dist/gameplay/event-graph/asset-references.js +4 -0
- package/dist/gameplay/event-graph/compiler.d.ts +107 -0
- package/dist/gameplay/event-graph/compiler.js +4 -0
- package/dist/gameplay/event-graph/decorators.d.ts +74 -0
- package/dist/gameplay/event-graph/decorators.js +4 -0
- package/dist/gameplay/event-graph/document-compiler.d.ts +107 -0
- package/dist/gameplay/event-graph/document-compiler.js +4 -0
- package/dist/gameplay/event-graph/event-graph-demo.d.ts +2 -0
- package/dist/gameplay/event-graph/event-graph-demo.js +4 -0
- package/dist/gameplay/event-graph/graph.d.ts +106 -0
- package/dist/gameplay/event-graph/graph.js +4 -0
- package/dist/gameplay/event-graph/index.d.ts +13 -0
- package/dist/gameplay/event-graph/index.js +4 -0
- package/dist/gameplay/event-graph/model.d.ts +71 -0
- package/dist/gameplay/event-graph/model.js +4 -0
- package/dist/gameplay/event-graph/nodes/execution-nodes.d.ts +115 -0
- package/dist/gameplay/event-graph/nodes/execution-nodes.js +4 -0
- package/dist/gameplay/event-graph/nodes/gameplay-nodes.d.ts +208 -0
- package/dist/gameplay/event-graph/nodes/gameplay-nodes.js +4 -0
- package/dist/gameplay/event-graph/nodes/index.d.ts +4 -0
- package/dist/gameplay/event-graph/nodes/index.js +4 -0
- package/dist/gameplay/event-graph/nodes/value-nodes.d.ts +53 -0
- package/dist/gameplay/event-graph/nodes/value-nodes.js +4 -0
- package/dist/gameplay/event-graph/registry.d.ts +33 -0
- package/dist/gameplay/event-graph/registry.js +4 -0
- package/dist/gameplay/event-graph/runtime-assets.d.ts +21 -0
- package/dist/gameplay/event-graph/runtime-assets.js +4 -0
- package/dist/gameplay/event-graph/runtime.d.ts +160 -0
- package/dist/gameplay/event-graph/runtime.js +4 -0
- package/dist/gameplay/event-graph/type-inference.d.ts +41 -0
- package/dist/gameplay/event-graph/type-inference.js +4 -0
- package/dist/gameplay/event-graph/types.d.ts +77 -0
- package/dist/gameplay/event-graph/types.js +4 -0
- package/dist/gameplay/index.d.ts +15 -2
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/input/input.d.ts +22 -17
- package/dist/gameplay/input/input.js +1 -1
- package/dist/gameplay/net/service/net-decorator.d.ts +1 -1
- package/dist/gameplay/net/service/net-decorator.js +1 -1
- package/dist/gameplay/net/service/net-serializer.js +1 -1
- package/dist/gameplay/net/service/net-service.d.ts +6 -6
- package/dist/gameplay/net/service/net-service.js +1 -1
- package/dist/gameplay/net/service/rpc-decorator.js +1 -1
- package/dist/gameplay/services/asset-loader.d.ts +7 -0
- package/dist/gameplay/services/asset-loader.js +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts +14 -0
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/gameplay/services/world.d.ts +12 -0
- package/dist/gameplay/services/world.js +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts +7 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/assets-provider.d.ts +1 -0
- package/dist/scene/assets-provider.js +1 -1
- package/dist/scene/custom-param-deserialize.js +1 -1
- package/dist/scene/custom-param-runtime-types.js +1 -1
- package/dist/scene/materializer.d.ts +32 -0
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/model.d.ts +114 -2
- package/dist/scene/model.js +1 -1
- package/dist/scene/objects/prefab.js +1 -1
- package/dist/scene/runtime-asset-service.d.ts +7 -1
- package/dist/scene/runtime-asset-service.js +1 -1
- package/dist/shader/graph/compiler.d.ts +3 -0
- package/dist/shader/graph/compiler.js +1 -1
- package/dist/shader/graph/model.d.ts +1 -1
- package/dist/shader/graph/registry.js +1 -1
- package/dist/test/animation-retarget.test.d.ts +2 -0
- package/dist/test/animation-retarget.test.js +4 -0
- package/dist/test/event-graph-generated-code.test.d.ts +2 -0
- package/dist/test/event-graph-generated-code.test.js +4 -0
- package/dist/test/event-graph-types.test.d.ts +2 -0
- package/dist/test/event-graph-types.test.js +4 -0
- package/dist/test/event-graph.test.d.ts +2 -0
- package/dist/test/event-graph.test.js +4 -0
- package/dist/test/input.test.d.ts +2 -0
- package/dist/test/input.test.js +4 -0
- package/dist/test/net-character-movement.test.js +1 -1
- package/dist/test/prefab-instance-params.test.js +1 -1
- package/dist/test/runtime-asset-service.test.js +1 -1
- package/dist/test/sequence-camera-control.test.js +1 -1
- package/dist/test/sequence-scene-binding.test.d.ts +2 -0
- package/dist/test/sequence-scene-binding.test.js +4 -0
- package/dist/test/sequence-transform.test.d.ts +2 -0
- package/dist/test/sequence-transform.test.js +4 -0
- package/dist/test/shader-graph.test.js +1 -1
- package/dist/test/vfx-world-space-emitter-rotation.test.d.ts +2 -0
- package/dist/test/vfx-world-space-emitter-rotation.test.js +4 -0
- package/dist/test/world-prefab-spawn.test.js +1 -1
- package/package.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
package/dist/rendering.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as a,Material as r,Matrix4 as n,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as p,WebGLRenderTarget as c,Texture as u,Euler as d,MeshStandardMaterial as m}from"three";import{CopyShader as f,EffectComposer as g,FXAAShader as M,GammaCorrectionShader as v,LUTPass as P,RenderPass as y,ShaderPass as b,VRButton as w}from"three-stdlib";import{CSMShader as x,CSMUtil as T}from"./csm.js";import{colorToNormal as R,float as S,NodeShaderMaterial as C,standardMaterial as U,uniformFloat as O,uniformVec3 as E,toonMaterial as A,lambertMaterial as F,normalize as B,rgb as G,rgba as D,transformed as j,varying as I,varyingAttributes as V,varyingTransformed as L,vec4 as _,BooleanExpression as W,select as N,ifDefApply as H,uniformSampler2d as q,RgbaNode as k,mix as z,attributes as $,uniformVec2 as J}from"three-shader-graph";import{Reflector as X}from"three-stdlib";import{BokehPass as Y,OutputPass as K}from"three/examples/jsm/Addons.js";import{CSM as Q}from"three/examples/jsm/csm/CSM.js";import{RectAreaLightUniformsLib as Z}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import ee from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as te}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as se}from"typedi";import{depthUniformName as ie,farUniformName as ae,nearUniformName as re,resolutionUniformName as ne,sceneNormalUniformName as oe,screenUV as le,supportsDepthTextureExtension as he}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as pe}from"./shader-nodes/time.js";import{aoMapUniformName as ce,sceneMapUniformName as ue}from"./shader-nodes/scene-sample.js";import{DepthPass as de}from"./utils/three/depth-pass.js";import{GPUStatsPanel as me}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as fe}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as ge,traverseVisibleStop as Me}from"./utils/three/traverse.js";import{clamp as ve}from"./utils/math.js";import{ColorPass as Pe}from"./rendering/color-pass.js";import{PostProcessEffectPass as ye,PostProcessEffectRegistration as be,postProcessEffectStages as we,sanitizePostProcessEffectPriority as xe,sanitizePostProcessEffectStage as Te}from"./rendering/post-process-effect.js";import{SSRPass as Re}from"./rendering/ssr/SSRPass.js";import{SSRShader as Se}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as Ce}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as Ue}from"./rendering/outline-effect.js";import{UnrealBloomPass as Oe}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Ee}from"./shader-nodes/depth.js";import{packDepthToRGBA as Ae}from"three-shader-graph";import{FogVolumeObject as Fe}from"./rendering/fog/fog-volume-object";import{ParallaxStandardMaterial as Be}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as Ge}from"./shader-nodes/pom.js";import{FullScreenQuad as De}from"three-stdlib";import{edgeDepthEffect as je}from"./shader-nodes/effects";import{decalDiscard as Ie}from"./shader-nodes/decal.js";import{Pass as Ve}from"three/examples/jsm/Addons.js";import{BatchedMesh2 as Le}from"./scene/batched-mesh-2.js";import{applyUvTiling as _e}from"./shader/uv-nodes.js";import{createPlaceholderTexture as We}from"./utils/three/placeholder-texture.js";import{getTemporalUpscalingJitter as Ne,getUpscalingMethod as He,UpscaleOutputPass as qe}from"./rendering/upscaling-pass.js";T.patchSetupMaterial();const ke=document.createElement("div");ke.style.position="absolute",ke.style.left="50%",ke.style.top="50%",ke.style.color="black",ke.style.zIndex="999";(new i.Layers).set(9);const ze=new i.MeshBasicMaterial({color:"black"}),$e=new i.MeshDepthMaterial;var Je;$e.depthPacking=i.RGBADepthPacking,$e.blending=i.NoBlending,$e.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(Je||(Je={}));const Xe=(()=>{const e=new Uint8Array([255,255,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ye=(()=>{const e=new Uint8Array([0,0,0,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ke=(()=>{const e=new Uint8Array([128,128,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Qe=new C({color:S(0),position:_(S(0))});Qe.visible=!1;const Ze=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let et=0,tt=null;const st=new Map;function it(){return null==tt&&(tt=new IntersectionObserver(e=>{for(const t of e){const e=st.get(t.target);e&&e(t.isIntersecting)}},{threshold:0})),tt}let at=e=class{get fpsCap(){return this._fpsCap}set fpsCap(e){const t=null!=e&&Number.isFinite(e)&&e>0?e:null;t!==this._fpsCap&&(this._fpsCap=t,this.fpsCapRevision++)}setPaused(e){this.paused=e}get currentResolutionScale(){return this.getEffectiveResolutionScale()}get currentRenderPixelRatio(){return this.getRenderPixelRatio()}get currentPresentationPixelRatio(){return this.getPresentationPixelRatio()}getRenderSize(e=new i.Vector2){return e.set(Math.max(1,this.container.clientWidth*this.getRenderPixelRatio()),Math.max(1,this.container.clientHeight*this.getRenderPixelRatio()))}isUpscalingEnabled(){return!0===this.options.upscaling?.enabled&&!0!==this.options.enableXR}isTemporalUpscalingEnabled(){return this.isUpscalingEnabled()&&"temporal"===He(this.options.upscaling)}resetUpscalingHistory(){this.hasPreviousTemporalViewProjection=!1,this.upscaleOutputPass?.resetHistory()}prepareUpscalingFrame(){if(!this.isTemporalUpscalingEnabled()||null==this.upscaleOutputPass)return void this.upscaleOutputPass?.setFrameState(null);this.unjitteredProjectionMatrix.copy(this.camera.projectionMatrix),this.currentUnjitteredViewProjectionMatrix.multiplyMatrices(this.unjitteredProjectionMatrix,this.camera.matrixWorldInverse),this.hasPreviousTemporalViewProjection||(this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.upscaleOutputPass.resetHistory());const e=ft(this.options.upscaling?.temporal?.jitterScale,1);Ne(this.temporalUpscalingFrameIndex++,this.temporalJitter,e),this.temporalJitterUv.set(this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),this.temporalJitter.y/Math.max(1,this.gRenderTarget.height));const t=2*this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),s=2*this.temporalJitter.y/Math.max(1,this.gRenderTarget.height);this.camera instanceof l?(this.camera.projectionMatrix.elements[8]+=t,this.camera.projectionMatrix.elements[9]+=s):(this.camera.projectionMatrix.elements[12]+=t,this.camera.projectionMatrix.elements[13]+=s),this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert(),this.projectionJitterApplied=!0,this.currentViewProjectionMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.currentViewProjectionMatrixInverse.copy(this.currentViewProjectionMatrix).invert(),this.temporalUpscalingFrameState.depthTexture=this.gRenderTarget.depthTexture,this.upscaleOutputPass.setFrameState(this.temporalUpscalingFrameState)}finishUpscalingFrame(){this.projectionJitterApplied&&(this.camera.projectionMatrix.copy(this.unjitteredProjectionMatrix),this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert(),this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.hasPreviousTemporalViewProjection=!0,this.projectionJitterApplied=!1)}getBasePixelRatio(){const e=ft(this.maxPixelRatio,1),t=ft(window.devicePixelRatio,1);return Math.min(e,t)}getBaseResolutionScale(){return ft(this.resolutionScale,1)}getDynamicResolutionMinScale(){const e=this.getBaseResolutionScale(),t=ft(this.options.dynamicResolution?.minScale,.7);return Math.min(e,t)}getEffectiveResolutionScale(){const e=this.getBaseResolutionScale();return!0!==this.options.dynamicResolution?.enabled?e:ve(this.dynamicResolutionScale,this.getDynamicResolutionMinScale(),e)}getRenderPixelRatio(){return this.getBasePixelRatio()*this.getEffectiveResolutionScale()}getPresentationPixelRatio(){const e=this.getBasePixelRatio();return this.isUpscalingEnabled()?e:e*this.getEffectiveResolutionScale()}resetDynamicResolutionAverage(){this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0}updateDynamicResolution(e,t){const s=this.options.dynamicResolution;if(!0!==s?.enabled)return;if(!Number.isFinite(e)||e<=0||e>.25)return void this.resetDynamicResolutionAverage();const i=this.getBaseResolutionScale(),a=this.getDynamicResolutionMinScale(),r=ve(this.dynamicResolutionScale,a,i);mt(r,this.dynamicResolutionScale)||(this.dynamicResolutionScale=r);const n=ft(s.targetFps,60),o=1e3/(null!=this.fpsCap?Math.min(n,this.fpsCap):n),l=1e3*e;this.dynamicResolutionFrameTimeAverage=null==this.dynamicResolutionFrameTimeAverage?l:.9*this.dynamicResolutionFrameTimeAverage+.1*l,this.dynamicResolutionFrameSamples++;const h=Math.max(1,Math.floor(ft(s.sampleFrames,20)));if(this.dynamicResolutionFrameSamples<h)return;const p=ft(s.decreaseCooldown,500),c=ft(s.increaseCooldown,2e3),u=ft(s.decreaseStep,.05),d=ft(s.increaseStep,.025),m=this.dynamicResolutionFrameTimeAverage;let f=r;m>1.12*o&&r>a&&t-this.dynamicResolutionLastAdjustmentAt>=p?f=Math.max(a,r-u):m<.85*o&&r<i&&t-this.dynamicResolutionLastAdjustmentAt>=c&&(f=Math.min(i,r+d)),mt(f,r)||(this.dynamicResolutionScale=f,this.dynamicResolutionLastAdjustmentAt=t,this.resetDynamicResolutionAverage(),this.resizeRender(!0))}resizeRender(e=!1){if(!this.running)return;const t=this.container.clientWidth,s=this.container.clientHeight,i=this.getRenderPixelRatio(),a=this.getPresentationPixelRatio();if(!e&&this.previousClientWith===t&&this.previousClientHeight===s&&this.previousRenderPixelRatio===i&&this.previousPresentationPixelRatio===a)return;if(0===t||0===s)return;this.previousClientWith=t,this.previousClientHeight=s,this.previousRenderPixelRatio=i,this.previousPresentationPixelRatio=a,this.camera instanceof l&&(this.camera.aspect=t/s,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(a),this.renderer.setSize(t,s),this.composer.setPixelRatio(i),this.composer.setSize(t,s);const r=t*i,n=s*i;this.dofPass.setSize(r,n),this.fxaaPass.setSize(r,n),this.fxaaPass.uniforms.resolution.value.set(1/r,1/n),this.createGRenderTarget(),this.phasedRenderPass.gRenderTarget=this.gRenderTarget,this.bloomPass.emissiveTexture=this.gRenderTarget.textures[1],this.ssrPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.ssrPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.aoPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0,this.resetDynamicResolutionAverage(),this.resetUpscalingHistory()}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}addPostProcessEffect(e,t={}){const s={id:++this.postProcessEffectId,pass:new ye(e),priority:xe(t.priority),stage:Te(t.stage)};return s.pass.enabled=t.enabled??!0,this.postProcessEffects.push(s),this.refreshPostProcessEffectPassOrder(),new be(this,s)}removePostProcessEffectEntry(e){const t=e,s=this.postProcessEffects.indexOf(t);-1!==s&&(this.postProcessEffects.splice(s,1),this.composer.removePass(t.pass),t.pass.dispose())}refreshPostProcessEffectPassOrder(){for(const e of this.postProcessEffects)this.composer.removePass(e.pass);for(const e of we){const t=this.getPostProcessEffectStageAnchorPass(e),s=null!=t?this.composer.passes.indexOf(t):this.composer.passes.length,i=this.postProcessEffects.filter(t=>t.stage===e).sort(ot);for(let e=0;e<i.length;e++)this.composer.insertPass(i[e].pass,s+e)}}getPostProcessEffectStageAnchorPass(e){switch(e){case"beforeFog":return this.volumetricFogPass;case"beforeDepthOfField":return this.dofPass;case"beforeColorAdjustment":return this.colorPass;case"beforeOutline":return this.outlinePass;case"beforeAntiAliasing":return this.fxaaPass;case"beforeLut":return this.lutPass;case"beforeOutput":return this.outputPass}}constructor(t,s={}){this.container=t,this.options=s,this.isIntersecting=!1,this.windowVisible=!0,this.running=!0,this.paused=!1,this._fpsCap=null,this.fpsCapRevision=0,this.postProcessVolumes=[],this.postProcessSettings={},this.baseToneMapping=i.NoToneMapping,this.baseToneMappingExposure=1,this.csmUpdateInvervals=this.options.shadows?.cascadeUpdateIntervals,this._id=et++,this.postProcessEffectId=0,this.postProcessEffects=[],this.postProcessEffectResolution=new i.Vector2(1,1),this.postProcessEffectUniformState={aoEnabled:!1,aoTexture:null,cameraFar:void 0,cameraNear:void 0,depthTexture:We(),normalTexture:We(128,128,255),resolution:this.postProcessEffectResolution,simulationTime:0},this.fquadCopy=new De(new p(f)),this.fquadCopyOpaque=new De(new C({outputs:[q("tSceneColor",We()).sample(V.uv),_(q("tDepthTexture",new i.DepthTexture(1,1)).sample(V.uv).r)]})),this.simulationTime=0,this.simulationTimeScale=1,this.lightProbeIntensity=2,this.fquadBlendAO=(()=>{const e=_(1),t=new C({outputs:[q("tAO",We()).sample(le),e,e],transparent:!0});t.depthWrite=!1,t.depthTest=!1,t.blending=i.MultiplyBlending;return new De(t)})(),this.resolutionScale=1,this.maxPixelRatio=Ze?1:window.devicePixelRatio,this.dynamicResolutionScale=1,this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0,this.dynamicResolutionLastAdjustmentAt=0,this.upscaleOutputPass=null,this.unjitteredProjectionMatrix=new n,this.temporalJitter=new i.Vector2,this.temporalJitterUv=new i.Vector2,this.currentUnjitteredViewProjectionMatrix=new n,this.currentViewProjectionMatrix=new n,this.currentViewProjectionMatrixInverse=new n,this.previousViewProjectionMatrix=new n,this.temporalUpscalingFrameState={depthTexture:null,currentJitterUv:this.temporalJitterUv,currentViewProjectionInverse:this.currentViewProjectionMatrixInverse,previousViewProjection:this.previousViewProjectionMatrix},this.temporalUpscalingFrameIndex=0,this.hasPreviousTemporalViewProjection=!1,this.projectionJitterApplied=!1,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.onLoopCallbacks=[],this.stats=new ee,this._showStats=!1,this.gbufferMaterialCache=new Map,this.gbufferDepthPrepassMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.depthPrepassMaterialCache=new WeakMap,this.depthPrepassCachedMaterials=new Map,this.depthPrepassCachedVisibility=[],this.gBufferCachedMaterials=new Map,this.gBufferCachedVisibility=[],this.gBufferCachedOnBeforeRender=new Map,this._initiatedMaterialTextures=new Set,this._initiatedTextures=new Set,this.compileInProgress=!1,this.pmremGeneratorResults=new WeakMap,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new a,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],this._customDepthMaterialCache=new WeakMap,null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),this.resolutionScale=s.resolutionScale??1,this.dynamicResolutionScale=this.getBaseResolutionScale(),this.fpsCap=s.fpsCap,e.activeView=this,Z.init(),window.renderer=this.renderer=window.renderer??new i.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});new i.MeshStandardMaterial({color:"#ccc"});this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,this.scene.updateMatrixWorld=function(e){const t=this.children;for(let s=0,i=t.length;s<i;s++){t[s].updateMatrixWorld(e)}}.bind(this.scene),this.renderer.setPixelRatio(this.getPresentationPixelRatio()),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(w.createButton(this.renderer));const r=new Ue(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=r,this.createGRenderTarget(),this.composer=new g(this.renderer,function(e,t){const s=new i.WebGLRenderTarget(Math.max(1,e),Math.max(1,t),{minFilter:i.LinearFilter,magFilter:i.LinearFilter,format:i.RGBAFormat,type:i.HalfFloatType});return s.texture.name="EffectComposer.rt1",s.texture.generateMipmaps=!1,s}(t.clientWidth,t.clientHeight)),this.composer.setPixelRatio(this.getRenderPixelRatio()),this.composer.setSize(t.clientWidth,t.clientHeight);var o=(t.clientWidth||1)/(t.clientHeight||1);const l=new i.PerspectiveCamera(45,o,.5,800);l.layers.enable(19),this.setCamera(l),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.baseToneMapping=this.renderer.toneMapping,this.baseToneMappingExposure=this.renderer.toneMappingExposure,this.renderer.gammaFactor=1.4,T.renderingView=this,this.isDepthTextureExtensionSupported=he(this.renderer),this.attachRendererDomElement(),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container,this.getRenderPixelRatio()),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container);const h=new i.Vector2(t.clientWidth,t.clientHeight),c=(new y(this.scene,this.camera),new b(f,"prevtexture"));c.enabled=!0,c.needsSwap=!0,c.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=c;const u=new Oe(h,1.5,.4,.85);u.threshold=1,u.strength=.9,u.radius=.2,this.bloomPass=u;const d=new te(this.scene,this.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});d.normalRenderTarget?.dispose(),d.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),d.output=te.OUTPUT.Off,d.enabled=!1,this.aoPass=d,this.fquadBlendAO.material.uniforms.tAO.value=d.pdRenderTarget.texture,Se.fragmentShader=Se.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const m=new Re({renderer:this.renderer,scene:this.scene,camera:this.camera,width:this.gRenderTarget.width,height:this.gRenderTarget.height,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[2],depthTexture:this.gRenderTarget.depthTexture});m.output=Re.OUTPUT.Default,m.blur=!0,m.fresnel=!1,m.distanceAttenuation=!0,m.maxDistance=50,m.selective=!0,m.bouncing=!1,m.opacity=.4,m.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=m,!1!==this.options.ao?.enabled&&this.composer.addPass(d);const x=new Ut((e,t,s,i,a)=>{this.aoPass.enabled&&(this.initResolutionUniform(this.fquadBlendAO.material),this.renderer.setRenderTarget(this.gRenderTarget),this.fquadBlendAO.render(this.renderer),this.renderer.setRenderTarget(null))});this.composer.addPass(x);const R=new Ut((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(Je.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(R),this.composer.addPass(c),this.composer.addPass(m),this.phasedRenderPass=new Ct(this.scene,this.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(u),u.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.volumetricFogPass=new Ce(h),this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new Y(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const S=new Pe;this.composer.addPass(S),this.colorPass=S,S.vignetteEnabled=!1,this.outlinePass=new fe(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const U=new b(M);U.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(U),this.fxaaPass=U,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new b(v).clear=!1,this.fixStatsStyle(),this.lutPass=new P({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const O=new b(f,"prevtexture");O.enabled=!0,O.needsSwap=!1,O.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],O.renderToScreen=!0;const E=this.isUpscalingEnabled()?new qe(this.options.upscaling):new K;!function(e){const t=e.material;if(t.dithering=!0,t.fragmentShader.includes("<dithering_fragment>"))return;const s="#include <colorspace_pars_fragment>";if(!t.fragmentShader.includes(s))return;t.fragmentShader=t.fragmentShader.replace(s,`${s}\n #include <common>\n #include <dithering_pars_fragment>`);const i=t.fragmentShader.lastIndexOf("}");i<0||(t.fragmentShader=`${t.fragmentShader.slice(0,i)}\n #include <dithering_fragment>\n${t.fragmentShader.slice(i)}`,t.needsUpdate=!0)}(E),this.outputPass=E,this.upscaleOutputPass=E instanceof qe?E:null,this.composer.addPass(E)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){if(this.camera=e,this.resetUpscalingHistory(),this.composer.passes.forEach(t=>{t instanceof y?t.camera=e:t instanceof fe?t.renderCamera=e:(t instanceof de||t instanceof te)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),this.phasedRenderPass&&(this.phasedRenderPass.camera=e),null==this.csm){if(this.csm=new Q({maxFar:80,lightFar:250,lightMargin:20,cascades:Ze?2:3,shadowMapSize:1024*(Ze?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"}),null!=this.csmUpdateInvervals){this.csmCascadeLastUpdate=new Array(this.csm.lights.length).fill(0);for(const e of this.csm.lights)e.shadow.autoUpdate=!1}this.csm&&Array.isArray(this.csm.lights),this.csm.fade=!0,h.lights_fragment_begin=x.lights_fragment_begin}else this.csm.camera=this.camera,this.camera;this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse(e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)});this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t,s){const a=Math.max(1,Math.floor(t.clientWidth*s)),r=Math.max(1,Math.floor(t.clientHeight*s)),n=new i.WebGLRenderTarget(a,r);return n.texture.minFilter=i.NearestFilter,n.texture.magFilter=i.NearestFilter,n.texture.generateMipmaps=!1,n.stencilBuffer=!1,n.depthTexture=new i.DepthTexture(a,r),n.depthTexture.type=i.UnsignedShortType,n.depthTexture.minFilter=i.NearestFilter,n.depthTexture.magFilter=i.NearestFilter,n}static createAOMaskDepthRenderTarget(e,t,s=e.getPixelRatio()){const a=Math.max(1,t.clientWidth*s),r=Math.max(1,t.clientHeight*s),n=new i.DepthTexture(a,r);n.type=i.UnsignedInt248Type,n.minFilter=i.NearestFilter,n.magFilter=i.NearestFilter;const o=new i.WebGLRenderTarget(a,r,{type:i.HalfFloatType,depthTexture:n});return o.texture.minFilter=i.NearestFilter,o.texture.magFilter=i.NearestFilter,o.texture.generateMipmaps=!1,o.stencilBuffer=!1,o}createSceneColorRenderTarget(e,t){const s=this.gRenderTarget.width,a=this.gRenderTarget.height,r=new i.WebGLRenderTarget(s,a,{count:2,type:i.FloatType,format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return r.texture.minFilter=i.LinearFilter,r.texture.magFilter=i.LinearFilter,r.texture.generateMipmaps=!1,r.textures[1].minFilter=i.NearestFilter,r.textures[1].magFilter=i.NearestFilter,r}createGRenderTarget(){const e=this.container;null!=this.gRenderTarget&&this.gRenderTarget.dispose();const t=this.getRenderPixelRatio(),s=Math.max(1,e.clientWidth*t),a=Math.max(1,e.clientHeight*t),r=new i.DepthTexture(s,a);r.type=i.UnsignedIntType,r.minFilter=i.NearestFilter,r.magFilter=i.NearestFilter,this.gRenderTarget=new c(s,a,{count:3,samples:this.options?.msaa??(Ze?void 0:2),minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat,depthTexture:r}),this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(e=!0){this.running=!1,this.lightVolume?.shTexture.dispose(),window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],e&&this.renderer.dispose(),this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose();for(const e of this.postProcessEffects)this.composer.removePass(e.pass),e.pass.dispose();this.postProcessEffects.length=0,this.detachOwnedDomElements();it().unobserve(this.container),st.delete(this.container),this.volumetricFogPass.dispose(),T.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.findIndex(t=>t===e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&this.stats.dom.parentElement!==this.container?this.container.appendChild(this.stats.dom):this._showStats||this.stats.dom.parentElement!==this.container||this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}attachRendererDomElement(){const e=this.renderer.domElement;e.parentElement===this.container&&e===this.container.firstChild||this.container.insertBefore(e,this.container.firstChild),this._showStats&&this.stats.dom.parentElement!==this.container&&this.container.appendChild(this.stats.dom)}detachOwnedDomElements(){this.renderer.domElement.parentElement===this.container&&this.container.removeChild(this.renderer.domElement),this.stats.dom.parentElement===this.container&&this.container.removeChild(this.stats.dom)}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof C&&(null==e.envMap||e.userData.useSceneEnv)&&(e.userData.useSceneEnv=!0,null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment},e.uniformsNeedUpdate=!0,e.uniforms.envMapRotation={value:wt(this.scene.environmentRotation,this.scene.environment,new i.Matrix3)}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1},e.uniformsNeedUpdate=!0),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment),e instanceof C||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}setupCsm(e){if(e instanceof i.Mesh||e instanceof i.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)this.csm.setupMaterial(t);else this.csm.setupMaterial(e.material)}updateMaterialProperties(e,t){(e instanceof i.MeshBasicMaterial||e instanceof m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(null!=t.uniforms.color&&t.uniforms.color.value.setFromColor(e.color),null!=t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),null!=t.uniforms.map&&(t.uniforms.map.value=e.map),null!=t.uniforms.alphaMap&&(t.uniforms.alphaMap.value=e.alphaMap),null!=t.uniforms.lightMap&&(t.uniforms.lightMap.value=e.lightMap,t.uniforms.lightMapIntensity.value=e.lightMapIntensity),null!=t.uniforms.aoMap&&(t.uniforms.aoMap.value=e.aoMap,t.uniforms.aoMapIntensity.value=e.aoMapIntensity),null!=t.uniforms.alphaTest&&(t.uniforms.alphaTest.value=e.alphaTest)),(e instanceof m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(t.uniforms.normalMap&&(t.uniforms.normalMap.value=e.normalMap,t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.emissiveMap&&(t.uniforms.emissiveMap.value=e.emissiveMap,t.uniforms.emissive.value.setFromColor(e.emissive),t.uniforms.emissiveIntensity.value=e.emissiveIntensity)),e instanceof m&&(null!=t.uniforms.roughnessMap&&(t.uniforms.roughnessMap.value=e.roughnessMap),null!=t.uniforms.metalnessMap&&(t.uniforms.metalnessMap.value=e.metalnessMap),null!=t.uniforms.roughness&&(t.uniforms.roughness.value=e.roughness),null!=t.uniforms.metalness&&(t.uniforms.metalness.value=e.metalness)),e instanceof i.MeshPhysicalMaterial&&(t.uniforms.sheenColor&&t.uniforms.sheenColor.value.setFromColor(e.sheenColor).multiplyScalar(e.sheen),t.uniforms.sheenColorMap&&(t.uniforms.sheenColorMap.value=e.sheenColorMap),t.uniforms.sheenRoughness&&(t.uniforms.sheenRoughness.value=e.sheenRoughness),t.uniforms.sheenRoughnessMap&&(t.uniforms.sheenRoughnessMap.value=e.sheenRoughnessMap)),e instanceof Be&&(t.uniforms.heightMap.value=e.heightMap,t.uniforms.heightScale.value=e.heightScale),this.updateMaterialCommonProperties(e,t)}updateUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s){const t=i[e],a=s[e].value;null!=t&&t.value!==a&&"receiveShadow"!==e&&!1===Ot.includes(e)&&(t.value=a)}this.updateMaterialCommonProperties(e,t)}inheritCustomUniformBindings(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s)null==i[e]&&("receiveShadow"===e||Ot.includes(e)||Et.includes(e)||(i[e]={value:s[e].value}))}updateMaterialCommonProperties(e,t){t.alphaTest=e.alphaTest,t.side=e.side,t.depthTest=e.depthTest,t.blending=e.blending,t.colorWrite=e.colorWrite,t.premultipliedAlpha=e.premultipliedAlpha,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t.visible=e.visible}updateLightUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e of Ot){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(e,t,s=!1){const a=t===Je.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let r=a.get(e);if(!0===e.userData.isGBufferMaterial)return e;if(null==r){let s=V.uv;if(e instanceof Be&&null!=e.heightMap){const t=O("heightScale",e.heightScale??1);s=Ge(s,q("heightMap",e.heightMap),t)}let o=L.normal;if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=e.normalMap??Ke,i=O("useNormalMap",null!=e.normalMap?1:0),a=O("normalScale",e.normalScale?.x??1),r=R(q("normalMap",t).sample(_e(s,e.normalMap)),a);o=z(L.normal,r,i)}else e instanceof C&&null!=e.outputNormal&&(o=e.outputNormal);!0!==e.userData.disableAO&&(o=H("DOUBLE_SIDED",o,e=>N(new W("gl_FrontFacing"),e,e.multiplyScalar(-1))));let l=e.userData?.reflective?S(0):S(1);if(e instanceof i.MeshStandardMaterial){const t=O("roughness",e.roughness??1),i=e.roughnessMap??Xe,a=O("useRoughnessMap",null!=e.roughnessMap?1:0),r=q("roughnessMap",i).sample(_e(s,e.roughnessMap)).g.multiply(t);l=z(t,r,a)}else e instanceof C&&null!=e.outputRoughness&&(l=e.outputRoughness);let h=null;if((e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial)&&null!=e.lightMap){const t=e.lightMap,i=O("useLightMap",null!=e.lightMap?1:0),a=O("lightMapIntensity",e.lightMapIntensity??1),r=q("lightMap",t).sample(s).rgb.multiplyScalar(a);h=z(G(0),r,i)}let c=S(0);if(e instanceof i.MeshStandardMaterial){const t=O("metalness",e.metalness??0),i=e.metalnessMap??Ye,a=O("useMetalnessMap",null!=e.metalnessMap?1:0),r=q("metalnessMap",i).sample(_e(s,e.metalnessMap)).b.multiply(t);c=z(t,r,a)}else e instanceof C&&e.outputRoughness;let u=null,d=S(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){const t=e.aoMap??Xe,i=O("useAoMap",null!=e.aoMap?1:0);d=O("aoMapIntensity",e.aoMapIntensity??1);const a=q("aoMap",t).sample(_e(s,e.aoMap)).r;u=z(S(1),a,i)}else e instanceof C&&e.outputRoughness;const f=O("opacity",e.opacity??1);let g=S(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){if(null!=e.alphaMap){const t=e.alphaMap;g=q("alphaMap",t).sample(_e(s,e.alphaMap)).r}g=g.multiply(f)}else e instanceof C&&null!=e.outputOpacity&&(g=e.outputOpacity);let M=D(0,1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){let t=E("color",(new i.Vector3).setFromColor(e.color));const a=e.map??Xe,r=O("useAlbedoMap",null!=e.map?1:0),n=q("map",a).sample(_e(s,e.map)),o=n.multiply(D(t,1)),l=D(t,1);M=z(l,o,r),e.vertexColors&&(M=M.multiply(_(I($.color.rgb),1)));const h=z(S(1),n.w,r);g=g.multiply(h)}const v=!0===e.userData.hasBloom;let P=G(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=E("emissive",(new i.Vector3).setFromColor(e.emissive)),a=O("emissiveIntensity",e.emissiveIntensity),r=e.emissiveMap??Ye,n=O("useEmissiveMap",null!=e.emissiveMap?1:0),o=q("emissiveMap",r).sample(_e(s,e.emissiveMap)).rgb.multiply(t);P=z(t,o,n),P=P.multiplyScalar(a)}else e instanceof C&&null!=e.outputEmissive&&(P=e.outputEmissive);let y=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(y=E("sheenColor",(new i.Vector3).setFromColor(e.sheenColor).multiplyScalar(e.sheen)),e.sheen>0&&null!=e.sheenColorMap)){const t=q("sheenColorMap",e.sheenColorMap).sample(s).rgb;y=y.multiply(t)}let b=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(b=O("sheenRoughness",e.sheenRoughness),e.sheen>0&&null!=e.sheenRoughnessMap)){const t=q("sheenRoughnessMap",e.sheenRoughnessMap).sample(s).r;b=b.multiply(t)}let w=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0&&(w=O("anisotropy",e.anisotropy),e.anisotropy>0&&null!=e.anisotropyMap)){const t=q("anisotropyMap",e.anisotropyMap).sample(s).r;w=w.multiply(t)}let x=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0){const t=e.anisotropyRotation??0;x=J("anisotropyDirection",new i.Vector2(Math.cos(t),Math.sin(t)))}const T=this.usesShaderUniform(e,ie),j=this.usesShaderUniform(e,ue),k=this.usesShaderUniform(e,ce),X=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,Y=O("alphaTest",e.alphaTest);let K,Q=e.alphaTest>0?g.lt(Y):X&&t===Je.opaque?g.lt(.8):null;!0===e.userData.isDecal&&(Q=Q?Q.or(Ie):Ie),K=X?_(0,0,0,0):(n=o,B(n).multiplyScalar(.5).addScalar(.5)).rgba(e.userData?.reflective?l:1);const Z=e instanceof C?e.outputPosition:void 0,ee=e instanceof C?e.outputTransform:void 0;let te,se=D("black",1);if(e instanceof C&&null!=e.outputColor)se=e.outputColor;else if(e instanceof i.MeshStandardMaterial)se=U({color:M,metalness:c,roughness:l,emissive:P.rgb,normal:o,ambientOcclusion:u,ambientOcclusionIntensity:d,bakedLight:h,sheenColor:y,sheenRoughness:b,anisotropy:w,anisotropyDirection:x});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)se=F({color:M.rgb,ambientOcclusion:u,ambientOcclusionIntensity:d});else if(e instanceof i.MeshBasicMaterial){let e=M.rgb,t=h??G("black");null!=u&&(t=t.multiplyScalar(u.subtract(1).multiply(d).add(1))),e=e.add(t),se=e.rgba(g)}else e instanceof i.MeshToonMaterial&&(se=A({color:M,emissive:P.rgb,normal:o,ambientOcclusion:u,ambientOcclusionIntensity:d,bakedLight:h}));(e instanceof C||e instanceof i.MeshStandardMaterial)&&(te=e.envMap);let ae=!0;(e instanceof m||e instanceof i.MeshBasicMaterial||e instanceof i.ShaderMaterial)&&(ae=e.fog);let re=D(se.rgb,g);ae&&(re=new FogNode(re));let ne=!0;if(t===Je.opaque?(ne&&(ne=!T&&!j&&!k),ne&&(ne=!X)):t===Je.transparent&&ne&&(ne=X||T||j||k),!ne)return r=Qe,a.set(e,r),r;r=new C({transform:ee,position:null==ee?Z:void 0,outputs:[re,P.rgba(t===Je.opaque?Y:v?1:0),K],opacity:g,outputEncoding:!1,fog:ae,transparent:e.transparent,lights:!0,envMap:te,alphaTest:e.alphaTest,uniformNodes:e.uniformNodes??{},discard:Q}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=r.uniforms.envMapIntensity&&(r.uniforms.envMapIntensity.value=e.envMapIntensity),"alphaMap"in e&&null!=e.alphaMap&&(r.alphaMap=e.alphaMap),(e instanceof C||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(r),e instanceof C&&(Object.assign(r.defines,e.defines),null!=r.uniforms[ce]&&(r.uniforms[ce].value=this.aoPass.pdRenderTarget.texture,r.defines.USE_SSAO_MAP="")),r.userData.mrtOutputs=3,r.forceSinglePass=e.forceSinglePass,r.side=e.side,r.blending=e.blending,X?(r.depthWrite=!e.transparent,r.depthTest=e.depthTest,r.colorWrite=t===Je.transparent):(r.depthWrite=e.depthWrite,r.depthTest=e.depthTest),r.visible=e.visible,r.alphaTest=e.alphaTest,r.alphaHash=e.alphaHash,r.vertexColors=e.vertexColors,r.premultipliedAlpha=e.premultipliedAlpha,r.toneMapped=e.toneMapped,r.blendAlpha=e.blendAlpha,r.blendColor=e.blendColor,r.polygonOffset=e.polygonOffset,r.polygonOffsetFactor=e.polygonOffsetFactor,r.polygonOffsetUnits=e.polygonOffsetUnits,r.blending=e.blending,r.wireframe=e.wireframe??!1,r.userData.isGBufferMaterial=!0,r.visible=ne,Object.assign(r.userData,e.userData),r.visible&&(this.csm.setupMaterial(r),e instanceof p&&this.inheritCustomUniformBindings(e,r)),a.set(e,r)}var n;return r.visible&&(e instanceof p?this.updateUniformValues(e,r):this.updateMaterialProperties(e,r)),this.usesShaderUniform(r,ue)&&this.initSceneColorUniform(r),this.initLightVolumeUniform(r),r}isDepthPrepassEnabled(){return!0===this.options.depthPrepass?.enabled}usesSceneFeedbackUniforms(e){return e instanceof p&&(this.usesShaderUniform(e,ie)||this.usesShaderUniform(e,ue)||this.usesShaderUniform(e,ce))}usesShaderUniform(e,t){return e instanceof p&&null!=e.uniforms[t]}isDepthPrepassEligibleMaterial(e){return null!=e&&(!1!==e.visible&&!1!==e.depthTest&&!1!==e.depthWrite&&(!e.transparent&&e.blending!==i.AdditiveBlending&&(!this.usesSceneFeedbackUniforms(e)&&(e instanceof C||e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshBasicMaterial))))}isDepthPrepassEligibleMesh(e){return!!this.isDepthPrepassEnabled()&&((e instanceof i.InstancedMesh||e instanceof Le)&&(!Array.isArray(e.material)&&this.isDepthPrepassEligibleMaterial(e.material)))}createDepthPrepassMaterial(e){if(!this.isDepthPrepassEligibleMaterial(e))return null;let t=this.depthPrepassMaterialCache.get(e);if(null==t){let s,a=S(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(a=O("opacity",e.opacity??1),null!=e.map&&(a=a.multiply(q("map",e.map).sample(V.uv).a)),null!=e.alphaMap&&(a=a.multiply(q("alphaMap",e.alphaMap).sample(V.uv).r))):e instanceof C&&(a=e.outputOpacity??S(1)),null!=e.alphaTest&&e.alphaTest>0&&(s=a.lt(e.alphaTest));const r=e instanceof C?e.outputPosition:void 0,n=e instanceof C?e.outputTransform:void 0;t=new C({outputs:[D(0,0),D(0,0),D(0,0)],opacity:a,transform:n,position:null==n?r:void 0,discard:s,lights:!1,fog:!1,outputEncoding:!1,transparent:!1,alphaTest:e.alphaTest}),t.depthWrite=!0,t.depthTest=e.depthTest,t.colorWrite=!1,t.transparent=!1,t.blending=i.NoBlending,t.lights=!1,t.fog=!1,t.toneMapped=!1,t.side=e.side,t.alphaTest=e.alphaTest,t.visible=e.visible,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t.onBeforeCompile=()=>{},t.customProgramCacheKey=()=>`depth-prepass:${e.id}:${e.version}:${e.alphaTest}:${e.side}`;for(const e of Ot)delete t.uniforms[e];for(const e of Et)delete t.uniforms[e];delete t.uniforms.receiveShadow,this.depthPrepassMaterialCache.set(e,t)}return e instanceof C?this.updateUniformValues(e,t):this.updateMaterialProperties(e,t),t.depthWrite=!0,t.depthTest=e.depthTest,t.colorWrite=!1,t.transparent=!1,t.blending=i.NoBlending,t.visible=e.visible,t.alphaTest=e.alphaTest,t.side=e.side,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t}applyDepthPrepassMaterials(){const e=this.depthPrepassCachedMaterials,t=this.depthPrepassCachedVisibility;e.clear(),t.length=0,Me(this.scene,s=>{if(Rt(s))return t.push(s),s.visible=!1,!1;if(!(s instanceof o))return;if(e.set(s,s.material),!this.isDepthPrepassEligibleMesh(s))return t.push(s),void(s.visible=!1);const i=this.createDepthPrepassMaterial(s.material);if(null==i)return t.push(s),void(s.visible=!1);s.material=i,s.visible=!0})}unapplyDepthPrepassMaterials(){this.depthPrepassCachedMaterials.forEach((e,t)=>{t.material=e}),this.depthPrepassCachedVisibility.forEach(e=>{e.visible=!0})}renderDepthPrepass(){if(!this.isDepthPrepassEnabled())return;this.applyDepthPrepassMaterials();const e=this.scene.matrixWorldAutoUpdate,t=this.scene.matrixAutoUpdate,s=this.renderer.shadowMap.autoUpdate;this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clearDepth();try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Depth prepass render failed",e)}this.unapplyDepthPrepassMaterials(),this.renderer.shadowMap.autoUpdate=s,this.scene.matrixWorldAutoUpdate=e,this.scene.matrixAutoUpdate=t}updateCsm(){const e=this.csmUpdateInvervals;if(this.renderer.shadowMap.autoUpdate&&null!=this.csmCascadeLastUpdate&&Array.isArray(e)){const t=performance.now();for(let s=0;s<this.csm.lights.length;++s){const i=e[s]??e[e.length-1]??16;(t-this.csmCascadeLastUpdate[s]>=i||0===s)&&this.csm.lights[s].shadow&&(this.csm.lights[s].shadow.needsUpdate=!0,this.csmCascadeLastUpdate[s]=t)}}this.csm.update()}loop(t,s=!1){const a=this.stats,r=a.addPanel(new ee.Panel("Calls","#83f","#002")),l=a.addPanel(new ee.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new me(this.renderer.getContext()),a.addPanel(h)),this.showStats=s;let p=10,c=1e3;const u=()=>{const e=this.renderer.info.render.calls;e>p&&(p=e,setTimeout(()=>p=10,5e3)),r.update(e,p);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout(()=>c=1e3,5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const d=[],m=[],f=[];let g=0;const M=new n,v=new n;let P=0;let y=this.paused,b=!1,w=0,x=null,T=this.fpsCapRevision;const R=()=>{this.running&&!0!==this.options.enableXR&&requestAnimationFrame(O)},S=()=>{e.activeView=this,b&&(b=!1,requestAnimationFrame(()=>O(w)))},U=it();st.set(this.container,e=>{this.isIntersecting=e,e&&S()}),U.observe(this.container),this.container.addEventListener("pointerdown",()=>{S()},{capture:!0});const O=s=>{b=!1;const r=this.renderer.getContext();if(!this.running||null===this.container.offsetParent||this.paused&&r.drawingBufferHeight>1)return b=!0,w=s,setTimeout(()=>{b&&O(s)},500),void(this.paused&&(y=!0));if(this.renderer.domElement.parentElement!==this.container){if(e.activeView!==this&&null!==e.activeView)return b=!0,void(w=s);this.attachRendererDomElement(),this.resizeRender()}if(!0!==this.options.enableXR){T!==this.fpsCapRevision&&(T=this.fpsCapRevision,x=null);const e=this.fpsCap;if(null!=e){const t=1e3/e;if(null!=x){const e=s-x;if(e<t)return void R();x=s-e%t}else x=s}else x=s}let n=(s*=.001)-g;if(g=s,y?(n=.016,y=!1,this.resetUpscalingHistory()):n>.25&&this.resetUpscalingHistory(),this.updateDynamicResolution(n,1e3*s),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),a.begin(),this.showStats&&h?.startQuery(),this.ssrPass.gpuPanel=h,M.copy(this.camera.matrixWorld),n>1){let e=n;for(;e>.05;)t(rt),e-=rt;t(e)}else t(n);this.onLoopCallbacks.forEach(e=>e(n)),this.paused||(this.simulationTime+=n*this.simulationTimeScale);const l=this.simulationTime;this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),s-P>.08&&!v.equals(M)&&(this.renderer.shadowMap.needsUpdate=!0,P=s),this.updateCsm();let p=!1;d.length=0,m.length=0,f.length=0;const c=ht;ct.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),c.setFromProjectionMatrix(ct);let S=!1,U=!1,E=!1;this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Fe&&(S=!0),e instanceof o&&this.initCustomDepthMaterial(e),(e instanceof o||e instanceof i.Sprite)&&(this.initResolutionUniform(e.material),this.initNormalUniform(e.material),this.initShadowUniform(e,e.material),this.initLightVolumeUniform(e.material),null!=this.scene.environment&<(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(p=!0)),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ie])&&isObjectInFrustum(e,c)?(this.initDepthUniform(e.material),U=!0):e instanceof X&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[ce]&&isObjectInFrustum(e,c)&&e.material instanceof C&&this.initAoUniform(e.material),e instanceof o||e instanceof i.Sprite){let t=!1;lt(e,e=>{this.usesShaderUniform(e,ue)&&(this.initSceneColorUniform(e),t=!0)}),t&&(f.push(e),E=!0)}if(e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[pe])e.material.uniforms[pe].value=l;else if(e instanceof o&&Array.isArray(e.material))for(const t of e.material)t.uniforms&&null!=t.uniforms[pe]&&(t.uniforms[pe].value=l)}),this.bloomPass.enabled=p,this.prepareUpscalingFrame(),this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderDepthPrepass(),this.renderScene(Je.opaque),this.aoPass.output=te.OUTPUT.Off,(U||E)&&(this.fquadCopyOpaque.material.uniforms.tSceneColor.value=this.gRenderTarget.textures[0],this.fquadCopyOpaque.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.initResolutionUniform(this.fquadCopyOpaque.material),this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.renderer.clear(),this.fquadCopyOpaque.render(this.renderer),this.renderer.setRenderTarget(this.gRenderTarget)),f.length,d.forEach(e=>e.visible=!0),m.forEach(e=>e.visible=!0),f.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=s),this.volumetricFogPass&&S?(this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1),this.updatePostProcessEffectUniforms(l);try{!this.paused&&this.running&&(this.render(n),this.finishUpscalingFrame(),this.showStats&&h?.endQuery(),this.showStats&&u(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}finally{this.finishUpscalingFrame()}a.end(),this.csm?.update(),R()};!0===this.options.enableXR?this.renderer.setAnimationLoop(O):requestAnimationFrame(O)}applyGBufferMaterials(e){const t=this.gBufferCachedMaterials,s=this.gBufferCachedVisibility,i=this.gBufferCachedOnBeforeRender;t.clear(),s.length=0,i.clear();Me(this.scene,i=>{if(Rt(i))return s.push(i),i.visible=!1,!1;if(i instanceof o){t.set(i,i.material);let a=!1;if(Array.isArray(i.material)){i.material=i.material.slice();for(let t=0;t<i.material.length;t++)i.material[t]=this.createGBufferMaterial(i.material[t],e,e===Je.opaque&&this.isDepthPrepassEligibleMesh(i)),a||(a=i.material[t].visible),this.initShadowUniform(i,i.material[t])}else i.material=this.createGBufferMaterial(i.material,e,e===Je.opaque&&this.isDepthPrepassEligibleMesh(i)),a||(a=i.material.visible),this.initShadowUniform(i,i.material);this.applyGBufferShadowUniformUpdater(i),a?i.visible=!0:null!=i.children&&0!=i.children.length||(s.push(i),i.visible=!1)}})}unapplyGBufferMaterials(){this.gBufferCachedMaterials.forEach((e,t)=>{t.material=e}),this.gBufferCachedOnBeforeRender.forEach((e,t)=>{t.onBeforeRender=e}),this.gBufferCachedOnBeforeRender.clear(),this.gBufferCachedVisibility.forEach((e,t)=>{e.visible=!0,e.updateMatrixWorld(!0)})}applyGBufferShadowUniformUpdater(e){const t=e.onBeforeRender;this.gBufferCachedOnBeforeRender.set(e,t),e.onBeforeRender=(s,i,a,r,n,o)=>{t.call(e,s,i,a,r,n,o),this.initShadowUniform(e,n)}}initTextures(e=this.scene){e.traverse(e=>{if(e instanceof o)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)this._initMaterialTextures(e.material[t]);else this._initMaterialTextures(e.material)})}_initMaterialTextures(e){if(!this._initiatedMaterialTextures.has(e))if(this._initiatedMaterialTextures.add(e),e instanceof p){for(const[t,s]of Object.entries(e.uniforms))if(s.value instanceof u){if(this._initiatedTextures.has(s.value))continue;this.renderer.initTexture(s.value),this._initiatedTextures.add(s.value)}}else for(const[t,s]of Object.entries(e))if(s instanceof u){if(this._initiatedTextures.has(s))continue;this.renderer.initTexture(s),this._initiatedTextures.add(s)}}async compileAsync(e=this.scene){if(this.compileInProgress)return;this.renderer.setRenderTarget(this.gRenderTarget),this.compileInProgress=!0,this.applyGBufferMaterials(Je.opaque),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(Je.transparent),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.isDepthPrepassEnabled()&&(this.renderer.setRenderTarget(this.gRenderTarget),this.applyDepthPrepassMaterials(),await this.renderer.compileAsync(e,this.camera),this.unapplyDepthPrepassMaterials()),e===this.scene&&(this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.compileAsync(this.fquadBlendAO.mesh,this.fquadBlendAO.camera),this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.renderer.compileAsync(this.fquadCopyOpaque.mesh,this.fquadCopyOpaque.camera));const t=this.csm.lights[0]?.shadow.camera;null!=t&&(this.applyDepthMaterial(),await this.renderer.compileAsync(e,t),this.unapplyDepthMaterial()),this.compileInProgress=!1,this.renderer.setRenderTarget(null)}applyDepthMaterial(){const e=this.gBufferCachedMaterials;e.clear(),this.scene.traverse(t=>{(t.isMesh||t.isPoints||t.isLine||t.isSprite)&&(this.initCustomDepthMaterial(t),e.set(t,t.material),t.castShadow?null!=t.customDepthMaterial?t.material=t.customDepthMaterial:t.material=Ft:t.material=null)})}unapplyDepthMaterial(){this.gBufferCachedMaterials.forEach((e,t)=>{t.material=e})}renderScene(e){if(!this.running||this.paused)return;if(this.compileInProgress)return void console.error("Compile in progress, skipping render");this.applyGBufferMaterials(e);const t=this.scene.matrixWorldAutoUpdate,s=this.scene.matrixAutoUpdate,i=this.renderer.shadowMap.autoUpdate;e!==Je.opaque&&(this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1);try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Render failed",e)}e===Je.opaque&&this.gBufferCachedMaterials.forEach((e,t)=>{!Array.isArray(e)&&!Array.isArray(t.material)&&e instanceof p&&this.updateLightUniformValues(t.material,e)}),this.unapplyGBufferMaterials(),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t.colorSpace=i.SRGBColorSpace,t}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);!function(e,t=i.NoToneMapping,s=1){e.tonemapMapping=t,e.tonemapExposure=s,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=e.colorTint??new i.Color("white"),e.colorTint.set("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.globalSaturation=ut(e.globalSaturation,1,1,1),e.globalContrast=ut(e.globalContrast,1,1,1),e.globalGamma=ut(e.globalGamma,1,1,1),e.globalGain=ut(e.globalGain,1,1,1),e.globalOffset=ut(e.globalOffset,0,0,0),e.shadowsSaturation=ut(e.shadowsSaturation,1,1,1),e.shadowsContrast=ut(e.shadowsContrast,1,1,1),e.shadowsGamma=ut(e.shadowsGamma,1,1,1),e.shadowsGain=ut(e.shadowsGain,1,1,1),e.shadowsOffset=ut(e.shadowsOffset,0,0,0),e.shadowsMax=.09,e.midtonesSaturation=ut(e.midtonesSaturation,1,1,1),e.midtonesContrast=ut(e.midtonesContrast,1,1,1),e.midtonesGamma=ut(e.midtonesGamma,1,1,1),e.midtonesGain=ut(e.midtonesGain,1,1,1),e.midtonesOffset=ut(e.midtonesOffset,0,0,0),e.highlightsSaturation=ut(e.highlightsSaturation,1,1,1),e.highlightsContrast=ut(e.highlightsContrast,1,1,1),e.highlightsGamma=ut(e.highlightsGamma,1,1,1),e.highlightsGain=ut(e.highlightsGain,1,1,1),e.highlightsOffset=ut(e.highlightsOffset,0,0,0),e.highlightsMin=.5,e.lut=void 0,e.lutIntensity=0}(this.postProcessSettings,this.baseToneMapping,this.baseToneMappingExposure);const e=this.postProcessSettings;let t,s=!1;if(null==this.camera)return;const a=this.camera.getWorldPosition(Mt);let r=[];for(const n of this.postProcessVolumes){if(!nt(n.object))continue;let o=n.blendWeight??1;const l=n.distanceToPoint(a);l>n.blendRadius||(n.blendRadius>0&&(o*=ve(1-l/n.blendRadius,0,1)),o>1&&(o=1),o>0&&(r.push(n),void 0!==n.settings.tonemapMapping&&(e.tonemapMapping=n.settings.tonemapMapping),void 0!==n.settings.tonemapExposure&&(e.tonemapExposure=i.MathUtils.lerp(e.tonemapExposure,n.settings.tonemapExposure,o)),void 0!==n.settings.envTexture&&(e.envTexture=n.settings.envTexture),void 0!==n.settings.envIntensity&&(e.envIntensity=i.MathUtils.lerp(e.envIntensity,n.settings.envIntensity,o)),void 0!==n.settings.vignetteIntensity&&(e.vignetteIntensity=i.MathUtils.lerp(e.vignetteIntensity,n.settings.vignetteIntensity,o)),void 0!==n.settings.colorTint&&void 0!==n.settings.colorTintIntensity&&n.settings.colorTintIntensity>0&&(e.colorTint=e.colorTint.lerp(n.settings.colorTint,o)),void 0!==n.settings.colorTintIntensity&&(e.colorTintIntensity=i.MathUtils.lerp(e.colorTintIntensity,n.settings.colorTintIntensity,o)),void 0!==n.settings.depthFocus&&(s=!0,e.depthFocus=void 0!==e.depthFocus?i.MathUtils.lerp(e.depthFocus,n.settings.depthFocus,o):n.settings.depthFocus),void 0!==n.settings.depthAperture&&(s=!0,e.depthAperture=void 0!==e.depthAperture?i.MathUtils.lerp(e.depthAperture,n.settings.depthAperture,o):n.settings.depthAperture),void 0!==n.settings.depthMaxBlur&&(s=!0,e.depthMaxBlur=void 0!==e.depthMaxBlur?i.MathUtils.lerp(e.depthMaxBlur,n.settings.depthMaxBlur,o):n.settings.depthMaxBlur),void 0!==n.settings.temperature&&(e.temperature=i.MathUtils.lerp(e.temperature,n.settings.temperature,o)),void 0!==n.settings.temperatureTint&&(e.temperatureTint=i.MathUtils.lerp(e.temperatureTint,n.settings.temperatureTint,o)),void 0!==n.settings.globalSaturation&&e.globalSaturation.lerp(n.settings.globalSaturation,o),void 0!==n.settings.globalContrast&&e.globalContrast.lerp(n.settings.globalContrast,o),void 0!==n.settings.globalGamma&&e.globalGamma.lerp(n.settings.globalGamma,o),void 0!==n.settings.globalGain&&e.globalGain.lerp(n.settings.globalGain,o),void 0!==n.settings.globalOffset&&e.globalOffset.lerp(n.settings.globalOffset,o),void 0!==n.settings.shadowsSaturation&&e.shadowsSaturation.lerp(n.settings.shadowsSaturation,o),void 0!==n.settings.shadowsContrast&&e.shadowsContrast.lerp(n.settings.shadowsContrast,o),void 0!==n.settings.shadowsGamma&&e.shadowsGamma.lerp(n.settings.shadowsGamma,o),void 0!==n.settings.shadowsGain&&e.shadowsGain.lerp(n.settings.shadowsGain,o),void 0!==n.settings.shadowsOffset&&e.shadowsOffset.lerp(n.settings.shadowsOffset,o),void 0!==n.settings.shadowsMax&&(e.shadowsMax=i.MathUtils.lerp(e.shadowsMax,n.settings.shadowsMax,o)),void 0!==n.settings.midtonesSaturation&&e.midtonesSaturation.lerp(n.settings.midtonesSaturation,o),void 0!==n.settings.midtonesContrast&&e.midtonesContrast.lerp(n.settings.midtonesContrast,o),void 0!==n.settings.midtonesGamma&&e.midtonesGamma.lerp(n.settings.midtonesGamma,o),void 0!==n.settings.midtonesGain&&e.midtonesGain.lerp(n.settings.midtonesGain,o),void 0!==n.settings.midtonesOffset&&e.midtonesOffset.lerp(n.settings.midtonesOffset,o),void 0!==n.settings.highlightsSaturation&&e.highlightsSaturation.lerp(n.settings.highlightsSaturation,o),void 0!==n.settings.highlightsContrast&&e.highlightsContrast.lerp(n.settings.highlightsContrast,o),void 0!==n.settings.highlightsGamma&&e.highlightsGamma.lerp(n.settings.highlightsGamma,o),void 0!==n.settings.highlightsGain&&e.highlightsGain.lerp(n.settings.highlightsGain,o),void 0!==n.settings.highlightsOffset&&e.highlightsOffset.lerp(n.settings.highlightsOffset,o),void 0!==n.settings.highlightsMin&&(e.highlightsMin=i.MathUtils.lerp(e.highlightsMin,n.settings.highlightsMin,o)),void 0!==n.settings.lut&&(t=n.settings.lut),void 0!==n.settings.lutIntensity&&(e.lutIntensity=i.MathUtils.lerp(e.lutIntensity,n.settings.lutIntensity,o))))}if(0===r.length)return this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);const n=e.vignetteIntensity>gt,o=(h=e.temperature,p=e.temperatureTint,!mt(h,6500)||!mt(p,0));var h,p;const c=(u=e.colorTint,e.colorTintIntensity>gt&&(!mt(u.r,1)||!mt(u.g,1)||!mt(u.b,1)));var u;const d=!(dt((m=e).globalSaturation,1,1,1)&&dt(m.globalContrast,1,1,1)&&dt(m.globalGamma,1,1,1)&&dt(m.globalGain,1,1,1)&&dt(m.globalOffset,0,0,0)&&dt(m.shadowsSaturation,1,1,1)&&dt(m.shadowsContrast,1,1,1)&&dt(m.shadowsGamma,1,1,1)&&dt(m.shadowsGain,1,1,1)&&dt(m.shadowsOffset,0,0,0)&&dt(m.midtonesSaturation,1,1,1)&&dt(m.midtonesContrast,1,1,1)&&dt(m.midtonesGamma,1,1,1)&&dt(m.midtonesGain,1,1,1)&&dt(m.midtonesOffset,0,0,0)&&dt(m.highlightsSaturation,1,1,1)&&dt(m.highlightsContrast,1,1,1)&&dt(m.highlightsGamma,1,1,1)&&dt(m.highlightsGain,1,1,1)&&dt(m.highlightsOffset,0,0,0));var m;const f=o||c||d||n,g=f&&e.tonemapMapping!==i.NoToneMapping,M=null!=t&&e.lutIntensity>gt;f?(this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1):(this.renderer.toneMapping=e.tonemapMapping,this.renderer.toneMappingExposure=e.tonemapExposure),null!=e.envTexture&&(this.scene.environment=this.getEnvTexture(e.envTexture)),this.scene.environmentIntensity=e.envIntensity,f?(this.colorPass.whiteBalanceEnabled=o,this.colorPass.whiteBalanceScale=o?function(e,t,s){const i=function(e){const t=ve(e,1e3,4e4)/100,s=t<=66?1:ve(1.292936186062745*Math.pow(t-60,-.1332047592),0,1),i=ve(t<=66?.3900815787690196*Math.log(t)-.6318414437886275:1.129890860895294*Math.pow(t-60,-.0755148492),0,1),a=t>=66?1:t<=19?0:ve(.5432067891101962*Math.log(t-10)-1.19625408914,0,1);return Pt.set(s,i,a)}(t),a=1+.2*ve(s,-1,1),r=i.x,n=i.y*a,o=i.z,l=Math.max(n,1e-4);return e.set(1/Math.max(r/l,1e-4),1/Math.max(n/l,1e-4),1/Math.max(o/l,1e-4)),e}(vt,e.temperature,e.temperatureTint):vt.set(1,1,1),this.colorPass.vignetteIntensity=e.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTintEnabled=c,this.colorPass.colorTint=e.colorTint,this.colorPass.colorTintIntensity=e.colorTintIntensity,this.colorPass.colorGradingEnabled=d,this.colorPass.toneMapping=e.tonemapMapping,this.colorPass.toneMappingEnabled=g,this.colorPass.toneMappingExposure=e.tonemapExposure,this.colorPass.globalSaturation=e.globalSaturation,this.colorPass.globalContrast=e.globalContrast,this.colorPass.globalGamma=e.globalGamma,this.colorPass.globalGain=e.globalGain,this.colorPass.globalOffset=e.globalOffset,this.colorPass.shadowsSaturation=e.shadowsSaturation,this.colorPass.shadowsContrast=e.shadowsContrast,this.colorPass.shadowsGamma=e.shadowsGamma,this.colorPass.shadowsGain=e.shadowsGain,this.colorPass.shadowsOffset=e.shadowsOffset,this.colorPass.shadowsMax=e.shadowsMax,this.colorPass.midtonesSaturation=e.midtonesSaturation,this.colorPass.midtonesContrast=e.midtonesContrast,this.colorPass.midtonesGamma=e.midtonesGamma,this.colorPass.midtonesGain=e.midtonesGain,this.colorPass.midtonesOffset=e.midtonesOffset,this.colorPass.highlightsSaturation=e.highlightsSaturation,this.colorPass.highlightsContrast=e.highlightsContrast,this.colorPass.highlightsGamma=e.highlightsGamma,this.colorPass.highlightsGain=e.highlightsGain,this.colorPass.highlightsOffset=e.highlightsOffset,this.colorPass.highlightsMin=e.highlightsMin,this.colorPass.enabled=!0):this.colorPass.enabled=!1,s&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==e.depthFocus&&(this.dofPass.uniforms.focus.value=e.depthFocus),void 0!==e.depthAperture&&(this.dofPass.uniforms.aperture.value=e.depthAperture),void 0!==e.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=e.depthMaxBlur)):this.dofPass.enabled=!1,this.lutPass.enabled=M,M&&(null!=t&&(t.flipY=!0,t.generateMipmaps=!1),this.lutPass.lut=t,this.lutPass.intensity=e.lutIntensity)}updatePostProcessEffectUniforms(e){if(0===this.postProcessEffects.length)return;const t=this.postProcessEffectUniformState;t.aoEnabled=this.aoPass.enabled,t.aoTexture=this.aoPass.enabled?this.aoPass.pdRenderTarget.texture:null,this.camera instanceof l?(t.cameraNear=this.camera.near,t.cameraFar=this.camera.far):(t.cameraNear=void 0,t.cameraFar=void 0),t.depthTexture=this.sceneColorRenderTarget.textures[1],t.normalTexture=this.gRenderTarget.textures[2],t.resolution.set(this.gRenderTarget.width,this.gRenderTarget.height),t.simulationTime=e;for(const e of this.postProcessEffects)e.pass.updateUniformState(t)}renderOverlay(){if(!this.running)return;if(0===this.overlayCameras.size)return;const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.previousClientWith/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled&&!1!==this.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible(t=>{t instanceof o&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,ht)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.options.bloom,this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=ge(this.scene,e=>e instanceof o&&!0===e.material?.userData?.hasBloom)}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===ze.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=ze:(e.visible=!1,this.bloomHidden.push(e))}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initSceneColorUniform(e){if(e instanceof p)return null==e.uniforms[ue]?(e.uniforms[ue]={value:this.sceneColorRenderTarget.texture},void(e.uniformsNeedUpdate=!0)):void(e.uniforms[ue].value!==this.sceneColorRenderTarget.texture&&(e.uniforms[ue].value=this.sceneColorRenderTarget.texture,e.uniformsNeedUpdate=!0))}initDepthUniform(e){e instanceof p&&(e.uniforms[ie].value=this.sceneColorRenderTarget.textures[1],this.camera instanceof l&&(null!=e.uniforms[re]&&(e.uniforms[re].value=this.camera.near),null!=e.uniforms[ae]&&(e.uniforms[ae].value=this.camera.far)))}initNormalUniform(e){e instanceof p&&null!=e.uniforms[oe]&&(e.uniforms[oe].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof C&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof C&&(null!=this.lightVolume?null==e.uniforms.uSH?(e.defines.USE_LIGHT_PROBE_VOLUME="",e.uniforms.gridOrigin={value:this.lightVolume.gridOrigin},e.uniforms.gridSize={value:this.lightVolume.gridSize},e.uniforms.gridRes={value:this.lightVolume.gridResolution},e.uniforms.giIntensity={value:this.lightProbeIntensity},e.uniforms.uSH={value:this.lightVolume.shTexture},e.uniformsNeedUpdate=!0,e.needsUpdate=!0):e.uniforms.giIntensity.value=this.lightProbeIntensity:null!=e.uniforms.uSH&&(delete e.defines.USE_LIGHT_PROBE_VOLUME,delete e.uniforms.gridOrigin,delete e.uniforms.gridSize,delete e.uniforms.gridRes,delete e.uniforms.giIntensity,delete e.uniforms.uSH,e.uniformsNeedUpdate=!0,e.needsUpdate=!0))}initResolutionUniform(e){e instanceof p&&null!=e.uniforms[ne]&&e.uniforms[ne].value.set(this.gRenderTarget.width,this.gRenderTarget.height)}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[ce].value=this.aoPass.pdRenderTarget.texture,null==e.defines.USE_SSAO_MAP&&(e.defines.USE_SSAO_MAP="",e.needsUpdate=!0),e.defines.USE_SSAO_MAP="";const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}else if(null!=e.defines.USE_SSAO_MAP){delete e.defines.USE_SSAO_MAP,e.needsUpdate=!0;const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}}initCustomDepthMaterial(e){if(null!=e.customDepthMaterial||!e.castShadow)return;const t=e.material;if(!(t instanceof C&&t.depthWrite&&t.alphaTest>0))return;let s=this._customDepthMaterialCache.get(t);if(null==s){const e=Ae(Ee);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new C({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}};at.activeView=null,at=e=t([se(),s("design:paramtypes",[HTMLElement,Object])],at);export{at as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const rt=.05;function nt(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}function ot(e,t){return e.priority!==t.priority?e.priority-t.priority:e.id-t.id}function lt(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}te.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};const ht=new i.Frustum,pt=new i.Box3,ct=new i.Matrix4;export function isObjectInFrustum(e,t){const s=pt.setFromObject(e);return t.intersectsBox(s)}function ut(e,t,s,a){return null==e?new i.Vector3(t,s,a):e.set(t,s,a)}function dt(e,t,s,i){return null!=e&&mt(e.x,t)&&mt(e.y,s)&&mt(e.z,i)}function mt(e,t,s=gt){return Math.abs(e-t)<=s}function ft(e,t){return null!=e&&Number.isFinite(e)&&e>0?e:t}const gt=1e-4,Mt=new i.Vector3,vt=new i.Vector3(1,1,1),Pt=new i.Vector3(1,1,1);const yt=new n,bt=new d;function wt(e,t,s=new i.Matrix3){return bt.copy(e),bt.x*=-1,bt.y*=-1,bt.z*=-1,t.isCubeTexture&&!1===t.isRenderTargetTexture&&(bt.y*=-1,bt.z*=-1),s.setFromMatrix4(yt.makeRotationFromEuler(bt))}const xt=new C({outputs:[_(0,0,0,0),_(0,0,0,0),D(G("white"),je(4))],transparent:!0}),Tt=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});xt.depthWrite=!1;new o(new i.BoxGeometry(4,4,4),Tt);function Rt(e){return e instanceof i.Sprite||e.isPoints||e.isLine||e.isLineSegments2||e.isTransformControls||e.isTransformControlsGizmo||e instanceof o&&St(e,e.material)}function St(e,t){return null==t||(Array.isArray(t)?t.some(t=>St(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof C))}class Ct extends Ve{constructor(e,t,s){super(),this.scene=e,this.camera=t,this.gRenderTarget=s,this.cachedVisibility=[],this.toRender=[],this.needsSwap=!1}render(e,t,s,i,a){const r=e.autoClear;e.autoClear=!1;const n=this.scene.matrixWorldAutoUpdate,l=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const p=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),this.cachedVisibility.length=0;let c=0,u=this.toRender;if(u.length=0,this.scene.traverseVisible(e=>{const t=Rt(e);e instanceof o&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(c++,u.push(e))}),c>0)for(const t of u)e.render(t,this.camera);this.cachedVisibility.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=r,s.depthTexture=p,this.scene.matrixWorldAutoUpdate=n,this.scene.matrixAutoUpdate=l,e.shadowMap.autoUpdate=h}}class Ut extends Ve{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const Ot=["ambientLightColor","cameraNear","directionalLightShadows","directionalLights","directionalShadowMap","directionalShadowMatrix","fogColor","fogDensity","fogFar","fogNear","hemisphereLights","lightProbe","ltc_1","ltc_2","pointLightShadows","pointLights","pointShadowMap","pointShadowMatrix","rectAreaLights","shadowFar","spotLightMap","spotLightMatrix","spotLightShadows","spotLights","spotShadowMap"],Et=["directionalShadowMap","directionalShadowMatrix","pointLightShadows","pointShadowMap","pointShadowMatrix","spotLightShadows","spotShadowMap"],At=E("fogColor");export class FogNode extends k{constructor(e,t=At){super(),this.source=e,this.fogColor=t}compile(e){const t=e.variable(),s=e.get(this.source.rgb),i=e.get(this.source.a),a=e.get(this.fogColor),r=e.get(O("fogFar")),n=e.get(O("fogNear")),o=e.get(O("fogDensity")),l=e.get(I(j.mvPosition.z));return{pars:"\n ",chunk:`\n #ifdef FOG_EXP2\n float fogFactor_${t} = 1.0 - exp( - ${o} * ${o} * ${l} * ${l} );\n #else\n float fogFactor_${t} = smoothstep( ${n}, ${r}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${a}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}const Ft=new i.MeshDepthMaterial({depthPacking:i.RGBADepthPacking});/*
|
|
1
|
+
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as a,Material as r,Matrix4 as n,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as p,WebGLRenderTarget as c,Texture as u,Euler as d,MeshStandardMaterial as m}from"three";import{CopyShader as f,EffectComposer as g,FXAAShader as M,GammaCorrectionShader as v,LUTPass as P,RenderPass as y,ShaderPass as b,VRButton as w}from"three-stdlib";import{CSMShader as T,CSMUtil as x}from"./csm.js";import{colorToNormal as R,float as S,NodeShaderMaterial as C,standardMaterial as U,uniformFloat as A,uniformVec3 as O,toonMaterial as E,lambertMaterial as F,normalize as B,rgb as G,rgba as D,transformed as j,varying as I,varyingAttributes as V,varyingTransformed as L,vec4 as _,BooleanExpression as W,select as N,ifDefApply as H,uniformSampler2d as q,RgbaNode as k,mix as z,attributes as $,uniformVec2 as J,min as X}from"three-shader-graph";import{Reflector as Y}from"three-stdlib";import{BokehPass as K,OutputPass as Q}from"three/examples/jsm/Addons.js";import{CSM as Z}from"three/examples/jsm/csm/CSM.js";import{RectAreaLightUniformsLib as ee}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import te from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as se}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as ie}from"typedi";import{depthUniformName as ae,farUniformName as re,nearUniformName as ne,resolutionUniformName as oe,sceneNormalUniformName as le,screenUV as he,supportsDepthTextureExtension as pe}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as ce}from"./shader-nodes/time.js";import{aoMapUniformName as ue,sceneMapUniformName as de}from"./shader-nodes/scene-sample.js";import{DepthPass as me}from"./utils/three/depth-pass.js";import{GPUStatsPanel as fe}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as ge}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as Me,traverseVisibleStop as ve}from"./utils/three/traverse.js";import{clamp as Pe}from"./utils/math.js";import{ColorPass as ye}from"./rendering/color-pass.js";import{PostProcessEffectPass as be,PostProcessEffectRegistration as we,postProcessEffectStages as Te,sanitizePostProcessEffectPriority as xe,sanitizePostProcessEffectStage as Re}from"./rendering/post-process-effect.js";import{SSRPass as Se}from"./rendering/ssr/SSRPass.js";import{SSRShader as Ce}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as Ue}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as Ae}from"./rendering/outline-effect.js";import{UnrealBloomPass as Oe}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Ee}from"./shader-nodes/depth.js";import{packDepthToRGBA as Fe}from"three-shader-graph";import{FogVolumeObject as Be}from"./rendering/fog/fog-volume-object";import{ParallaxStandardMaterial as Ge}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as De}from"./shader-nodes/pom.js";import{FullScreenQuad as je}from"three-stdlib";import{edgeDepthEffect as Ie}from"./shader-nodes/effects";import{decalDiscard as Ve}from"./shader-nodes/decal.js";import{Pass as Le}from"three/examples/jsm/Addons.js";import{BatchedMesh2 as _e}from"./scene/batched-mesh-2.js";import{applyUvTiling as We}from"./shader/uv-nodes.js";import{createPlaceholderTexture as Ne}from"./utils/three/placeholder-texture.js";import{getTemporalUpscalingJitter as He,getUpscalingMethod as qe,UpscaleOutputPass as ke}from"./rendering/upscaling-pass.js";x.patchSetupMaterial();const ze=document.createElement("div");ze.style.position="absolute",ze.style.left="50%",ze.style.top="50%",ze.style.color="black",ze.style.zIndex="999";(new i.Layers).set(9);const $e=new i.MeshBasicMaterial({color:"black"}),Je=new i.MeshDepthMaterial;var Xe;Je.depthPacking=i.RGBADepthPacking,Je.blending=i.NoBlending,Je.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(Xe||(Xe={}));const Ye=(()=>{const e=new Uint8Array([255,255,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ke=(()=>{const e=new Uint8Array([0,0,0,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Qe=(()=>{const e=new Uint8Array([128,128,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ze=new C({color:S(0),position:_(S(0))});Ze.visible=!1;const et=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let tt=0,st=null;const it=new Map;function at(){return null==st&&(st=new IntersectionObserver(e=>{for(const t of e){const e=it.get(t.target);e&&e(t.isIntersecting)}},{threshold:0})),st}let rt=e=class{get fpsCap(){return this._fpsCap}set fpsCap(e){const t=null!=e&&Number.isFinite(e)&&e>0?e:null;t!==this._fpsCap&&(this._fpsCap=t,this.fpsCapRevision++)}setPaused(e){this.paused=e}get currentResolutionScale(){return this.getEffectiveResolutionScale()}get currentRenderPixelRatio(){return this.getRenderPixelRatio()}get currentPresentationPixelRatio(){return this.getPresentationPixelRatio()}getRenderSize(e=new i.Vector2){return e.set(Math.max(1,this.container.clientWidth*this.getRenderPixelRatio()),Math.max(1,this.container.clientHeight*this.getRenderPixelRatio()))}isUpscalingEnabled(){return!0===this.options.upscaling?.enabled&&!0!==this.options.enableXR}isTemporalUpscalingEnabled(){return this.isUpscalingEnabled()&&"temporal"===qe(this.options.upscaling)}resetUpscalingHistory(){this.hasPreviousTemporalViewProjection=!1,this.upscaleOutputPass?.resetHistory()}prepareUpscalingFrame(){if(!this.isTemporalUpscalingEnabled()||null==this.upscaleOutputPass)return void this.upscaleOutputPass?.setFrameState(null);this.unjitteredProjectionMatrix.copy(this.camera.projectionMatrix),this.currentUnjitteredViewProjectionMatrix.multiplyMatrices(this.unjitteredProjectionMatrix,this.camera.matrixWorldInverse),this.hasPreviousTemporalViewProjection||(this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.upscaleOutputPass.resetHistory());const e=gt(this.options.upscaling?.temporal?.jitterScale,1);He(this.temporalUpscalingFrameIndex++,this.temporalJitter,e),this.temporalJitterUv.set(this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),this.temporalJitter.y/Math.max(1,this.gRenderTarget.height));const t=2*this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),s=2*this.temporalJitter.y/Math.max(1,this.gRenderTarget.height);this.camera instanceof l?(this.camera.projectionMatrix.elements[8]+=t,this.camera.projectionMatrix.elements[9]+=s):(this.camera.projectionMatrix.elements[12]+=t,this.camera.projectionMatrix.elements[13]+=s),this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert(),this.projectionJitterApplied=!0,this.currentViewProjectionMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.currentViewProjectionMatrixInverse.copy(this.currentViewProjectionMatrix).invert(),this.temporalUpscalingFrameState.depthTexture=this.gRenderTarget.depthTexture,this.upscaleOutputPass.setFrameState(this.temporalUpscalingFrameState)}finishUpscalingFrame(){this.projectionJitterApplied&&(this.camera.projectionMatrix.copy(this.unjitteredProjectionMatrix),this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert(),this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.hasPreviousTemporalViewProjection=!0,this.projectionJitterApplied=!1)}getBasePixelRatio(){const e=gt(this.maxPixelRatio,1),t=gt(window.devicePixelRatio,1);return Math.min(e,t)}getBaseResolutionScale(){return gt(this.resolutionScale,1)}getDynamicResolutionMinScale(){const e=this.getBaseResolutionScale(),t=gt(this.options.dynamicResolution?.minScale,.7);return Math.min(e,t)}getEffectiveResolutionScale(){const e=this.getBaseResolutionScale();return!0!==this.options.dynamicResolution?.enabled?e:Pe(this.dynamicResolutionScale,this.getDynamicResolutionMinScale(),e)}getRenderPixelRatio(){return this.getBasePixelRatio()*this.getEffectiveResolutionScale()}getPresentationPixelRatio(){const e=this.getBasePixelRatio();return this.isUpscalingEnabled()?e:e*this.getEffectiveResolutionScale()}resetDynamicResolutionAverage(){this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0}updateDynamicResolution(e,t){const s=this.options.dynamicResolution;if(!0!==s?.enabled)return;if(!Number.isFinite(e)||e<=0||e>.25)return void this.resetDynamicResolutionAverage();const i=this.getBaseResolutionScale(),a=this.getDynamicResolutionMinScale(),r=Pe(this.dynamicResolutionScale,a,i);ft(r,this.dynamicResolutionScale)||(this.dynamicResolutionScale=r);const n=gt(s.targetFps,60),o=1e3/(null!=this.fpsCap?Math.min(n,this.fpsCap):n),l=1e3*e;this.dynamicResolutionFrameTimeAverage=null==this.dynamicResolutionFrameTimeAverage?l:.9*this.dynamicResolutionFrameTimeAverage+.1*l,this.dynamicResolutionFrameSamples++;const h=Math.max(1,Math.floor(gt(s.sampleFrames,20)));if(this.dynamicResolutionFrameSamples<h)return;const p=gt(s.decreaseCooldown,500),c=gt(s.increaseCooldown,2e3),u=gt(s.decreaseStep,.05),d=gt(s.increaseStep,.025),m=this.dynamicResolutionFrameTimeAverage;let f=r;m>1.12*o&&r>a&&t-this.dynamicResolutionLastAdjustmentAt>=p?f=Math.max(a,r-u):m<.85*o&&r<i&&t-this.dynamicResolutionLastAdjustmentAt>=c&&(f=Math.min(i,r+d)),ft(f,r)||(this.dynamicResolutionScale=f,this.dynamicResolutionLastAdjustmentAt=t,this.resetDynamicResolutionAverage(),this.resizeRender(!0))}resizeRender(e=!1){if(!this.running)return;const t=this.container.clientWidth,s=this.container.clientHeight,i=this.getRenderPixelRatio(),a=this.getPresentationPixelRatio();if(!e&&this.previousClientWith===t&&this.previousClientHeight===s&&this.previousRenderPixelRatio===i&&this.previousPresentationPixelRatio===a)return;if(0===t||0===s)return;this.previousClientWith=t,this.previousClientHeight=s,this.previousRenderPixelRatio=i,this.previousPresentationPixelRatio=a,this.camera instanceof l&&(this.camera.aspect=t/s,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(a),this.renderer.setSize(t,s),this.composer.setPixelRatio(i),this.composer.setSize(t,s);const r=t*i,n=s*i;this.dofPass.setSize(r,n),this.fxaaPass.setSize(r,n),this.fxaaPass.uniforms.resolution.value.set(1/r,1/n),this.createGRenderTarget(),this.phasedRenderPass.gRenderTarget=this.gRenderTarget,this.bloomPass.emissiveTexture=this.gRenderTarget.textures[1],this.ssrPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.ssrPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.aoPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.fquadBlendAO.material.uniforms.tAlphaTest.value=this.gRenderTarget.textures[1],this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0,this.resetDynamicResolutionAverage(),this.resetUpscalingHistory()}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}addPostProcessEffect(e,t={}){const s={id:++this.postProcessEffectId,pass:new be(e),priority:xe(t.priority),stage:Re(t.stage)};return s.pass.enabled=t.enabled??!0,this.postProcessEffects.push(s),this.refreshPostProcessEffectPassOrder(),new we(this,s)}removePostProcessEffectEntry(e){const t=e,s=this.postProcessEffects.indexOf(t);-1!==s&&(this.postProcessEffects.splice(s,1),this.composer.removePass(t.pass),t.pass.dispose())}refreshPostProcessEffectPassOrder(){for(const e of this.postProcessEffects)this.composer.removePass(e.pass);for(const e of Te){const t=this.getPostProcessEffectStageAnchorPass(e),s=null!=t?this.composer.passes.indexOf(t):this.composer.passes.length,i=this.postProcessEffects.filter(t=>t.stage===e).sort(lt);for(let e=0;e<i.length;e++)this.composer.insertPass(i[e].pass,s+e)}}getPostProcessEffectStageAnchorPass(e){switch(e){case"beforeFog":return this.volumetricFogPass;case"beforeDepthOfField":return this.dofPass;case"beforeColorAdjustment":return this.colorPass;case"beforeOutline":return this.outlinePass;case"beforeAntiAliasing":return this.fxaaPass;case"beforeLut":return this.lutPass;case"beforeOutput":return this.outputPass}}constructor(t,s={}){this.container=t,this.options=s,this.isIntersecting=!1,this.windowVisible=!0,this.running=!0,this.paused=!1,this._fpsCap=null,this.fpsCapRevision=0,this.postProcessVolumes=[],this.postProcessSettings={},this.baseToneMapping=i.NoToneMapping,this.baseToneMappingExposure=1,this.csmUpdateInvervals=this.options.shadows?.cascadeUpdateIntervals,this._id=tt++,this.postProcessEffectId=0,this.postProcessEffects=[],this.postProcessEffectResolution=new i.Vector2(1,1),this.postProcessEffectUniformState={aoEnabled:!1,aoTexture:null,cameraFar:void 0,cameraNear:void 0,depthTexture:Ne(),normalTexture:Ne(128,128,255),resolution:this.postProcessEffectResolution,simulationTime:0},this.fquadCopy=new je(new p(f)),this.fquadCopyOpaque=new je(new C({outputs:[q("tSceneColor",Ne()).sample(V.uv),_(q("tDepthTexture",new i.DepthTexture(1,1)).sample(V.uv).r)]})),this.simulationTime=0,this.simulationTimeScale=1,this.lightProbeIntensity=2,this.fquadBlendAO=(()=>{const e=_(1),t=Ne(),s=q("tAlphaTest",t).sample(he).a,a=q("tAO",t).sample(he),r=N(s.lt(.05),a,X(_(1,1,1,1),a.addScalar(.4))),n=new C({outputs:[r,e,e],transparent:!0});n.depthWrite=!1,n.depthTest=!1,n.blending=i.MultiplyBlending;return new je(n)})(),this.resolutionScale=1,this.maxPixelRatio=et?1:window.devicePixelRatio,this.dynamicResolutionScale=1,this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0,this.dynamicResolutionLastAdjustmentAt=0,this.upscaleOutputPass=null,this.unjitteredProjectionMatrix=new n,this.temporalJitter=new i.Vector2,this.temporalJitterUv=new i.Vector2,this.currentUnjitteredViewProjectionMatrix=new n,this.currentViewProjectionMatrix=new n,this.currentViewProjectionMatrixInverse=new n,this.previousViewProjectionMatrix=new n,this.temporalUpscalingFrameState={depthTexture:null,currentJitterUv:this.temporalJitterUv,currentViewProjectionInverse:this.currentViewProjectionMatrixInverse,previousViewProjection:this.previousViewProjectionMatrix},this.temporalUpscalingFrameIndex=0,this.hasPreviousTemporalViewProjection=!1,this.projectionJitterApplied=!1,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.onLoopCallbacks=[],this.stats=new te,this._showStats=!1,this.gbufferMaterialCache=new Map,this.gbufferDepthPrepassMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.depthPrepassMaterialCache=new WeakMap,this.depthPrepassCachedMaterials=new Map,this.depthPrepassCachedVisibility=[],this.gBufferCachedMaterials=new Map,this.gBufferCachedVisibility=[],this.gBufferCachedOnBeforeRender=new Map,this._initiatedMaterialTextures=new Set,this._initiatedTextures=new Set,this.compileInProgress=!1,this.pmremGeneratorResults=new WeakMap,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new a,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],this._customDepthMaterialCache=new WeakMap,null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),this.resolutionScale=s.resolutionScale??1,this.dynamicResolutionScale=this.getBaseResolutionScale(),this.fpsCap=s.fpsCap,e.activeView=this,ee.init(),window.renderer=this.renderer=window.renderer??new i.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});new i.MeshStandardMaterial({color:"#ccc"});this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,this.scene.updateMatrixWorld=function(e){const t=this.children;for(let s=0,i=t.length;s<i;s++){t[s].updateMatrixWorld(e)}}.bind(this.scene),this.renderer.setPixelRatio(this.getPresentationPixelRatio()),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(w.createButton(this.renderer));const r=new Ae(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=r,this.createGRenderTarget(),this.composer=new g(this.renderer,function(e,t){const s=new i.WebGLRenderTarget(Math.max(1,e),Math.max(1,t),{minFilter:i.LinearFilter,magFilter:i.LinearFilter,format:i.RGBAFormat,type:i.HalfFloatType});return s.texture.name="EffectComposer.rt1",s.texture.generateMipmaps=!1,s}(t.clientWidth,t.clientHeight)),this.composer.setPixelRatio(this.getRenderPixelRatio()),this.composer.setSize(t.clientWidth,t.clientHeight);var o=(t.clientWidth||1)/(t.clientHeight||1);const l=new i.PerspectiveCamera(45,o,.5,800);l.layers.enable(19),this.setCamera(l),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.baseToneMapping=this.renderer.toneMapping,this.baseToneMappingExposure=this.renderer.toneMappingExposure,this.renderer.gammaFactor=1.4,x.renderingView=this,this.isDepthTextureExtensionSupported=pe(this.renderer),this.attachRendererDomElement(),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container,this.getRenderPixelRatio()),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container);const h=new i.Vector2(t.clientWidth,t.clientHeight),c=(new y(this.scene,this.camera),new b(f,"prevtexture"));c.enabled=!0,c.needsSwap=!0,c.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=c;const u=new Oe(h,1.5,.4,.85);u.threshold=1,u.strength=.9,u.radius=.2,this.bloomPass=u;const d=new se(this.scene,this.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});d.normalRenderTarget?.dispose(),d.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),d.output=se.OUTPUT.Off,d.enabled=!1,this.aoPass=d,this.fquadBlendAO.material.uniforms.tAO.value=d.pdRenderTarget.texture,this.fquadBlendAO.material.uniforms.tAlphaTest.value=this.gRenderTarget.textures[1],Ce.fragmentShader=Ce.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const m=new Se({renderer:this.renderer,scene:this.scene,camera:this.camera,width:this.gRenderTarget.width,height:this.gRenderTarget.height,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[2],depthTexture:this.gRenderTarget.depthTexture});m.output=Se.OUTPUT.Default,m.blur=!0,m.fresnel=!1,m.distanceAttenuation=!0,m.maxDistance=50,m.selective=!0,m.bouncing=!1,m.opacity=.4,m.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=m,!1!==this.options.ao?.enabled&&this.composer.addPass(d);const T=new At((e,t,s,i,a)=>{this.aoPass.enabled&&(this.initResolutionUniform(this.fquadBlendAO.material),this.renderer.setRenderTarget(this.gRenderTarget),this.fquadBlendAO.render(this.renderer),this.renderer.setRenderTarget(null))});this.composer.addPass(T);const R=new At((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(Xe.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(R),this.composer.addPass(c),this.composer.addPass(m),this.phasedRenderPass=new Ut(this.scene,this.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(u),u.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.volumetricFogPass=new Ue(h),this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new K(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const S=new ye;this.composer.addPass(S),this.colorPass=S,S.vignetteEnabled=!1,this.outlinePass=new ge(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const U=new b(M);U.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(U),this.fxaaPass=U,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new b(v).clear=!1,this.fixStatsStyle(),this.lutPass=new P({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const A=new b(f,"prevtexture");A.enabled=!0,A.needsSwap=!1,A.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],A.renderToScreen=!0;const O=this.isUpscalingEnabled()?new ke(this.options.upscaling):new Q;!function(e){const t=e.material;if(t.dithering=!0,t.fragmentShader.includes("<dithering_fragment>"))return;const s="#include <colorspace_pars_fragment>";if(!t.fragmentShader.includes(s))return;t.fragmentShader=t.fragmentShader.replace(s,`${s}\n #include <common>\n #include <dithering_pars_fragment>`);const i=t.fragmentShader.lastIndexOf("}");i<0||(t.fragmentShader=`${t.fragmentShader.slice(0,i)}\n #include <dithering_fragment>\n${t.fragmentShader.slice(i)}`,t.needsUpdate=!0)}(O),this.outputPass=O,this.upscaleOutputPass=O instanceof ke?O:null,this.composer.addPass(O)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){if(this.camera=e,this.resetUpscalingHistory(),this.composer.passes.forEach(t=>{t instanceof y?t.camera=e:t instanceof ge?t.renderCamera=e:(t instanceof me||t instanceof se)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),this.phasedRenderPass&&(this.phasedRenderPass.camera=e),null==this.csm){if(this.csm=new Z({maxFar:80,lightFar:250,lightMargin:20,cascades:et?2:3,shadowMapSize:1024*(et?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"}),null!=this.csmUpdateInvervals){this.csmCascadeLastUpdate=new Array(this.csm.lights.length).fill(0);for(const e of this.csm.lights)e.shadow.autoUpdate=!1}this.csm&&Array.isArray(this.csm.lights),this.csm.fade=!0,h.lights_fragment_begin=T.lights_fragment_begin}else this.csm.camera=this.camera,this.camera;this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse(e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)});this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t,s){const a=Math.max(1,Math.floor(t.clientWidth*s)),r=Math.max(1,Math.floor(t.clientHeight*s)),n=new i.WebGLRenderTarget(a,r);return n.texture.minFilter=i.NearestFilter,n.texture.magFilter=i.NearestFilter,n.texture.generateMipmaps=!1,n.stencilBuffer=!1,n.depthTexture=new i.DepthTexture(a,r),n.depthTexture.type=i.UnsignedShortType,n.depthTexture.minFilter=i.NearestFilter,n.depthTexture.magFilter=i.NearestFilter,n}static createAOMaskDepthRenderTarget(e,t,s=e.getPixelRatio()){const a=Math.max(1,t.clientWidth*s),r=Math.max(1,t.clientHeight*s),n=new i.DepthTexture(a,r);n.type=i.UnsignedInt248Type,n.minFilter=i.NearestFilter,n.magFilter=i.NearestFilter;const o=new i.WebGLRenderTarget(a,r,{type:i.HalfFloatType,depthTexture:n});return o.texture.minFilter=i.NearestFilter,o.texture.magFilter=i.NearestFilter,o.texture.generateMipmaps=!1,o.stencilBuffer=!1,o}createSceneColorRenderTarget(e,t){const s=this.gRenderTarget.width,a=this.gRenderTarget.height,r=new i.WebGLRenderTarget(s,a,{count:2,type:i.FloatType,format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return r.texture.minFilter=i.LinearFilter,r.texture.magFilter=i.LinearFilter,r.texture.generateMipmaps=!1,r.textures[1].minFilter=i.NearestFilter,r.textures[1].magFilter=i.NearestFilter,r}createGRenderTarget(){const e=this.container;null!=this.gRenderTarget&&this.gRenderTarget.dispose();const t=this.getRenderPixelRatio(),s=Math.max(1,e.clientWidth*t),a=Math.max(1,e.clientHeight*t),r=new i.DepthTexture(s,a);r.type=i.UnsignedIntType,r.minFilter=i.NearestFilter,r.magFilter=i.NearestFilter,this.gRenderTarget=new c(s,a,{count:3,samples:this.options?.msaa??(et?void 0:2),minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat,depthTexture:r}),this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(e=!0){this.running=!1,this.lightVolume?.shTexture.dispose(),window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],e&&this.renderer.dispose(),this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose();for(const e of this.postProcessEffects)this.composer.removePass(e.pass),e.pass.dispose();this.postProcessEffects.length=0,this.detachOwnedDomElements();at().unobserve(this.container),it.delete(this.container),this.volumetricFogPass.dispose(),x.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.findIndex(t=>t===e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&this.stats.dom.parentElement!==this.container?this.container.appendChild(this.stats.dom):this._showStats||this.stats.dom.parentElement!==this.container||this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}attachRendererDomElement(){const e=this.renderer.domElement;e.parentElement===this.container&&e===this.container.firstChild||this.container.insertBefore(e,this.container.firstChild),this._showStats&&this.stats.dom.parentElement!==this.container&&this.container.appendChild(this.stats.dom)}detachOwnedDomElements(){this.renderer.domElement.parentElement===this.container&&this.container.removeChild(this.renderer.domElement),this.stats.dom.parentElement===this.container&&this.container.removeChild(this.stats.dom)}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof C&&(null==e.envMap||e.userData.useSceneEnv)&&(e.userData.useSceneEnv=!0,null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment},e.uniformsNeedUpdate=!0,e.uniforms.envMapRotation={value:Tt(this.scene.environmentRotation,this.scene.environment,new i.Matrix3)}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1},e.uniformsNeedUpdate=!0),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment),e instanceof C||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}setupCsm(e){if(e instanceof i.Mesh||e instanceof i.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)this.csm.setupMaterial(t);else this.csm.setupMaterial(e.material)}updateMaterialProperties(e,t){(e instanceof i.MeshBasicMaterial||e instanceof m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(null!=t.uniforms.color&&t.uniforms.color.value.setFromColor(e.color),null!=t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),null!=t.uniforms.map&&(t.uniforms.map.value=e.map),null!=t.uniforms.alphaMap&&(t.uniforms.alphaMap.value=e.alphaMap),null!=t.uniforms.lightMap&&(t.uniforms.lightMap.value=e.lightMap,t.uniforms.lightMapIntensity.value=e.lightMapIntensity),null!=t.uniforms.aoMap&&(t.uniforms.aoMap.value=e.aoMap,t.uniforms.aoMapIntensity.value=e.aoMapIntensity),null!=t.uniforms.alphaTest&&(t.uniforms.alphaTest.value=e.alphaTest)),(e instanceof m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(t.uniforms.normalMap&&(t.uniforms.normalMap.value=e.normalMap,t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.emissiveMap&&(t.uniforms.emissiveMap.value=e.emissiveMap,t.uniforms.emissive.value.setFromColor(e.emissive),t.uniforms.emissiveIntensity.value=e.emissiveIntensity)),e instanceof m&&(null!=t.uniforms.roughnessMap&&(t.uniforms.roughnessMap.value=e.roughnessMap),null!=t.uniforms.metalnessMap&&(t.uniforms.metalnessMap.value=e.metalnessMap),null!=t.uniforms.roughness&&(t.uniforms.roughness.value=e.roughness),null!=t.uniforms.metalness&&(t.uniforms.metalness.value=e.metalness)),e instanceof i.MeshPhysicalMaterial&&(t.uniforms.sheenColor&&t.uniforms.sheenColor.value.setFromColor(e.sheenColor).multiplyScalar(e.sheen),t.uniforms.sheenColorMap&&(t.uniforms.sheenColorMap.value=e.sheenColorMap),t.uniforms.sheenRoughness&&(t.uniforms.sheenRoughness.value=e.sheenRoughness),t.uniforms.sheenRoughnessMap&&(t.uniforms.sheenRoughnessMap.value=e.sheenRoughnessMap)),e instanceof Ge&&(t.uniforms.heightMap.value=e.heightMap,t.uniforms.heightScale.value=e.heightScale),this.updateMaterialCommonProperties(e,t)}updateUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s){const t=i[e],a=s[e].value;null!=t&&t.value!==a&&"receiveShadow"!==e&&!1===Ot.includes(e)&&(t.value=a)}this.updateMaterialCommonProperties(e,t)}inheritCustomUniformBindings(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s)null==i[e]&&("receiveShadow"===e||Ot.includes(e)||Et.includes(e)||(i[e]={value:s[e].value}))}updateMaterialCommonProperties(e,t){t.alphaTest=e.alphaTest,t.side=e.side,t.depthTest=e.depthTest,t.blending=e.blending,t.colorWrite=e.colorWrite,t.premultipliedAlpha=e.premultipliedAlpha,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t.visible=e.visible}updateLightUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e of Ot){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(e,t,s=!1){const a=t===Xe.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let r=a.get(e);if(!0===e.userData.isGBufferMaterial)return e;if(null==r){let s=V.uv;if(e instanceof Ge&&null!=e.heightMap){const t=A("heightScale",e.heightScale??1);s=De(s,q("heightMap",e.heightMap),t)}let o=L.normal;if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=e.normalMap??Qe,i=A("useNormalMap",null!=e.normalMap?1:0),a=A("normalScale",e.normalScale?.x??1),r=R(q("normalMap",t).sample(We(s,e.normalMap)),a);o=z(L.normal,r,i)}else e instanceof C&&null!=e.outputNormal&&(o=e.outputNormal);!0!==e.userData.disableAO&&(o=H("DOUBLE_SIDED",o,e=>N(new W("gl_FrontFacing"),e,e.multiplyScalar(-1))));let l=e.userData?.reflective?S(0):S(1);if(e instanceof i.MeshStandardMaterial){const t=A("roughness",e.roughness??1),i=e.roughnessMap??Ye,a=A("useRoughnessMap",null!=e.roughnessMap?1:0),r=q("roughnessMap",i).sample(We(s,e.roughnessMap)).g.multiply(t);l=z(t,r,a)}else e instanceof C&&null!=e.outputRoughness&&(l=e.outputRoughness);let h=null;if((e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial)&&null!=e.lightMap){const t=e.lightMap,i=A("useLightMap",null!=e.lightMap?1:0),a=A("lightMapIntensity",e.lightMapIntensity??1),r=q("lightMap",t).sample(s).rgb.multiplyScalar(a);h=z(G(0),r,i)}let c=S(0);if(e instanceof i.MeshStandardMaterial){const t=A("metalness",e.metalness??0),i=e.metalnessMap??Ke,a=A("useMetalnessMap",null!=e.metalnessMap?1:0),r=q("metalnessMap",i).sample(We(s,e.metalnessMap)).b.multiply(t);c=z(t,r,a)}else e instanceof C&&e.outputRoughness;let u=null,d=S(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){const t=e.aoMap??Ye,i=A("useAoMap",null!=e.aoMap?1:0);d=A("aoMapIntensity",e.aoMapIntensity??1);const a=q("aoMap",t).sample(We(s,e.aoMap)).r;u=z(S(1),a,i)}else e instanceof C&&e.outputRoughness;const f=A("opacity",e.opacity??1);let g=S(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){if(null!=e.alphaMap){const t=e.alphaMap;g=q("alphaMap",t).sample(We(s,e.alphaMap)).r}g=g.multiply(f)}else e instanceof C&&null!=e.outputOpacity&&(g=e.outputOpacity);let M=D(0,1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){let t=O("color",(new i.Vector3).setFromColor(e.color));const a=e.map??Ye,r=A("useAlbedoMap",null!=e.map?1:0),n=q("map",a).sample(We(s,e.map)),o=n.multiply(D(t,1)),l=D(t,1);M=z(l,o,r),e.vertexColors&&(M=M.multiply(_(I($.color.rgb),1)));const h=z(S(1),n.w,r);g=g.multiply(h)}const v=!0===e.userData.hasBloom;let P=G(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=O("emissive",(new i.Vector3).setFromColor(e.emissive)),a=A("emissiveIntensity",e.emissiveIntensity),r=e.emissiveMap??Ke,n=A("useEmissiveMap",null!=e.emissiveMap?1:0),o=q("emissiveMap",r).sample(We(s,e.emissiveMap)).rgb.multiply(t);P=z(t,o,n),P=P.multiplyScalar(a)}else e instanceof C&&null!=e.outputEmissive&&(P=e.outputEmissive);let y=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(y=O("sheenColor",(new i.Vector3).setFromColor(e.sheenColor).multiplyScalar(e.sheen)),e.sheen>0&&null!=e.sheenColorMap)){const t=q("sheenColorMap",e.sheenColorMap).sample(s).rgb;y=y.multiply(t)}let b=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(b=A("sheenRoughness",e.sheenRoughness),e.sheen>0&&null!=e.sheenRoughnessMap)){const t=q("sheenRoughnessMap",e.sheenRoughnessMap).sample(s).r;b=b.multiply(t)}let w=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0&&(w=A("anisotropy",e.anisotropy),e.anisotropy>0&&null!=e.anisotropyMap)){const t=q("anisotropyMap",e.anisotropyMap).sample(s).r;w=w.multiply(t)}let T=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0){const t=e.anisotropyRotation??0;T=J("anisotropyDirection",new i.Vector2(Math.cos(t),Math.sin(t)))}const x=this.usesShaderUniform(e,ae),j=this.usesShaderUniform(e,de),k=this.usesShaderUniform(e,ue),X=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,Y=A("alphaTest",e.alphaTest);let K,Q=e.alphaTest>0?g.lt(Y):X&&t===Xe.opaque?g.lt(.8):null;!0===e.userData.isDecal&&(Q=Q?Q.or(Ve):Ve),K=X?_(0,0,0,0):(n=o,B(n).multiplyScalar(.5).addScalar(.5)).rgba(e.userData?.reflective?l:1);const Z=e instanceof C?e.outputPosition:void 0,ee=e instanceof C?e.outputTransform:void 0;let te,se=D("black",1);if(e instanceof C&&null!=e.outputColor)se=e.outputColor;else if(e instanceof i.MeshStandardMaterial)se=U({color:M,metalness:c,roughness:l,emissive:P.rgb,normal:o,ambientOcclusion:u,ambientOcclusionIntensity:d,bakedLight:h,sheenColor:y,sheenRoughness:b,anisotropy:w,anisotropyDirection:T});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)se=F({color:M.rgb,ambientOcclusion:u,ambientOcclusionIntensity:d});else if(e instanceof i.MeshBasicMaterial){let e=M.rgb,t=h??G("black");null!=u&&(t=t.multiplyScalar(u.subtract(1).multiply(d).add(1))),e=e.add(t),se=e.rgba(g)}else e instanceof i.MeshToonMaterial&&(se=E({color:M,emissive:P.rgb,normal:o,ambientOcclusion:u,ambientOcclusionIntensity:d,bakedLight:h}));(e instanceof C||e instanceof i.MeshStandardMaterial)&&(te=e.envMap);let ie=!0;(e instanceof m||e instanceof i.MeshBasicMaterial||e instanceof i.ShaderMaterial)&&(ie=e.fog);let re=D(se.rgb,g);ie&&(re=new FogNode(re));let ne=!0;if(t===Xe.opaque?(ne&&(ne=!x&&!j&&!k),ne&&(ne=!X)):t===Xe.transparent&&ne&&(ne=X||x||j||k),!ne)return r=Ze,a.set(e,r),r;r=new C({transform:ee,position:null==ee?Z:void 0,outputs:[re,P.rgba(t===Xe.opaque?Y:v?1:0),K],opacity:g,outputEncoding:!1,fog:ie,transparent:e.transparent,lights:!0,envMap:te,alphaTest:e.alphaTest,uniformNodes:e.uniformNodes??{},discard:Q}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=r.uniforms.envMapIntensity&&(r.uniforms.envMapIntensity.value=e.envMapIntensity),"alphaMap"in e&&null!=e.alphaMap&&(r.alphaMap=e.alphaMap),(e instanceof C||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(r),e instanceof C&&(Object.assign(r.defines,e.defines),null!=r.uniforms[ue]&&(r.uniforms[ue].value=this.aoPass.pdRenderTarget.texture,r.defines.USE_SSAO_MAP="")),r.userData.mrtOutputs=3,r.forceSinglePass=e.forceSinglePass,r.side=e.side,r.blending=e.blending,X?(r.depthWrite=!e.transparent,r.depthTest=e.depthTest,r.colorWrite=t===Xe.transparent):(r.depthWrite=e.depthWrite,r.depthTest=e.depthTest),r.visible=e.visible,r.alphaTest=e.alphaTest,r.alphaHash=e.alphaHash,r.vertexColors=e.vertexColors,r.premultipliedAlpha=e.premultipliedAlpha,r.toneMapped=e.toneMapped,r.blendAlpha=e.blendAlpha,r.blendColor=e.blendColor,r.polygonOffset=e.polygonOffset,r.polygonOffsetFactor=e.polygonOffsetFactor,r.polygonOffsetUnits=e.polygonOffsetUnits,r.blending=e.blending,r.wireframe=e.wireframe??!1,r.userData.isGBufferMaterial=!0,r.visible=ne,Object.assign(r.userData,e.userData),r.visible&&(this.csm.setupMaterial(r),e instanceof p&&this.inheritCustomUniformBindings(e,r)),a.set(e,r)}var n;return r.visible&&(e instanceof p?this.updateUniformValues(e,r):this.updateMaterialProperties(e,r)),this.usesShaderUniform(r,de)&&this.initSceneColorUniform(r),this.initLightVolumeUniform(r),r}isDepthPrepassEnabled(){return!0===this.options.depthPrepass?.enabled}usesSceneFeedbackUniforms(e){return e instanceof p&&(this.usesShaderUniform(e,ae)||this.usesShaderUniform(e,de)||this.usesShaderUniform(e,ue))}usesShaderUniform(e,t){return e instanceof p&&null!=e.uniforms[t]}isDepthPrepassEligibleMaterial(e){return null!=e&&(!1!==e.visible&&!1!==e.depthTest&&!1!==e.depthWrite&&(!e.transparent&&e.blending!==i.AdditiveBlending&&(!this.usesSceneFeedbackUniforms(e)&&(e instanceof C||e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshBasicMaterial))))}isDepthPrepassEligibleMesh(e){return!!this.isDepthPrepassEnabled()&&((e instanceof i.InstancedMesh||e instanceof _e)&&(!Array.isArray(e.material)&&this.isDepthPrepassEligibleMaterial(e.material)))}createDepthPrepassMaterial(e){if(!this.isDepthPrepassEligibleMaterial(e))return null;let t=this.depthPrepassMaterialCache.get(e);if(null==t){let s,a=S(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(a=A("opacity",e.opacity??1),null!=e.map&&(a=a.multiply(q("map",e.map).sample(V.uv).a)),null!=e.alphaMap&&(a=a.multiply(q("alphaMap",e.alphaMap).sample(V.uv).r))):e instanceof C&&(a=e.outputOpacity??S(1)),null!=e.alphaTest&&e.alphaTest>0&&(s=a.lt(e.alphaTest));const r=e instanceof C?e.outputPosition:void 0,n=e instanceof C?e.outputTransform:void 0;t=new C({outputs:[D(0,0),D(0,0),D(0,0)],opacity:a,transform:n,position:null==n?r:void 0,discard:s,lights:!1,fog:!1,outputEncoding:!1,transparent:!1,alphaTest:e.alphaTest}),t.depthWrite=!0,t.depthTest=e.depthTest,t.colorWrite=!1,t.transparent=!1,t.blending=i.NoBlending,t.lights=!1,t.fog=!1,t.toneMapped=!1,t.side=e.side,t.alphaTest=e.alphaTest,t.visible=e.visible,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t.onBeforeCompile=()=>{},t.customProgramCacheKey=()=>`depth-prepass:${e.id}:${e.version}:${e.alphaTest}:${e.side}`;for(const e of Ot)delete t.uniforms[e];for(const e of Et)delete t.uniforms[e];delete t.uniforms.receiveShadow,this.depthPrepassMaterialCache.set(e,t)}return e instanceof C?this.updateUniformValues(e,t):this.updateMaterialProperties(e,t),t.depthWrite=!0,t.depthTest=e.depthTest,t.colorWrite=!1,t.transparent=!1,t.blending=i.NoBlending,t.visible=e.visible,t.alphaTest=e.alphaTest,t.side=e.side,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t}applyDepthPrepassMaterials(){const e=this.depthPrepassCachedMaterials,t=this.depthPrepassCachedVisibility;e.clear(),t.length=0,ve(this.scene,s=>{if(St(s))return t.push(s),s.visible=!1,!1;if(!(s instanceof o))return;if(e.set(s,s.material),!this.isDepthPrepassEligibleMesh(s))return t.push(s),void(s.visible=!1);const i=this.createDepthPrepassMaterial(s.material);if(null==i)return t.push(s),void(s.visible=!1);s.material=i,s.visible=!0})}unapplyDepthPrepassMaterials(){this.depthPrepassCachedMaterials.forEach((e,t)=>{t.material=e}),this.depthPrepassCachedVisibility.forEach(e=>{e.visible=!0})}renderDepthPrepass(){if(!this.isDepthPrepassEnabled())return;this.applyDepthPrepassMaterials();const e=this.scene.matrixWorldAutoUpdate,t=this.scene.matrixAutoUpdate,s=this.renderer.shadowMap.autoUpdate;this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clearDepth();try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Depth prepass render failed",e)}this.unapplyDepthPrepassMaterials(),this.renderer.shadowMap.autoUpdate=s,this.scene.matrixWorldAutoUpdate=e,this.scene.matrixAutoUpdate=t}updateCsm(){const e=this.csmUpdateInvervals;if(this.renderer.shadowMap.autoUpdate&&null!=this.csmCascadeLastUpdate&&Array.isArray(e)){const t=performance.now();for(let s=0;s<this.csm.lights.length;++s){const i=e[s]??e[e.length-1]??16;(t-this.csmCascadeLastUpdate[s]>=i||0===s)&&this.csm.lights[s].shadow&&(this.csm.lights[s].shadow.needsUpdate=!0,this.csmCascadeLastUpdate[s]=t)}}this.csm.update()}loop(t,s=!1){const a=this.stats,r=a.addPanel(new te.Panel("Calls","#83f","#002")),l=a.addPanel(new te.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new fe(this.renderer.getContext()),a.addPanel(h)),this.showStats=s;let p=10,c=1e3;const u=()=>{const e=this.renderer.info.render.calls;e>p&&(p=e,setTimeout(()=>p=10,5e3)),r.update(e,p);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout(()=>c=1e3,5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const d=[],m=[],f=[];let g=0;const M=new n,v=new n;let P=0;let y=this.paused,b=!1,w=0,T=null,x=this.fpsCapRevision;const R=()=>{this.running&&!0!==this.options.enableXR&&requestAnimationFrame(A)},S=()=>{e.activeView=this,b&&(b=!1,requestAnimationFrame(()=>A(w)))},U=at();it.set(this.container,e=>{this.isIntersecting=e,e&&S()}),U.observe(this.container),this.container.addEventListener("pointerdown",()=>{S()},{capture:!0});const A=s=>{b=!1;const r=this.renderer.getContext();if(!this.running||null===this.container.offsetParent||this.paused&&r.drawingBufferHeight>1)return b=!0,w=s,setTimeout(()=>{b&&A(s)},500),void(this.paused&&(y=!0));if(this.renderer.domElement.parentElement!==this.container){if(e.activeView!==this&&null!==e.activeView)return b=!0,void(w=s);this.attachRendererDomElement(),this.resizeRender()}if(!0!==this.options.enableXR){x!==this.fpsCapRevision&&(x=this.fpsCapRevision,T=null);const e=this.fpsCap;if(null!=e){const t=1e3/e;if(null!=T){const e=s-T;if(e<t)return void R();T=s-e%t}else T=s}else T=s}let n=(s*=.001)-g;if(g=s,y?(n=.016,y=!1,this.resetUpscalingHistory()):n>.25&&this.resetUpscalingHistory(),this.updateDynamicResolution(n,1e3*s),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),a.begin(),this.showStats&&h?.startQuery(),this.ssrPass.gpuPanel=h,M.copy(this.camera.matrixWorld),n>1){let e=n;for(;e>.05;)t(nt),e-=nt;t(e)}else t(n);this.onLoopCallbacks.forEach(e=>e(n)),this.paused||(this.simulationTime+=n*this.simulationTimeScale);const l=this.simulationTime;this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),s-P>.08&&!v.equals(M)&&(this.renderer.shadowMap.needsUpdate=!0,P=s),this.updateCsm();let p=!1;d.length=0,m.length=0,f.length=0;const c=pt;ut.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),c.setFromProjectionMatrix(ut);let S=!1,U=!1,O=!1;this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Be&&(S=!0),e instanceof o&&this.initCustomDepthMaterial(e),(e instanceof o||e instanceof i.Sprite)&&(this.initResolutionUniform(e.material),this.initNormalUniform(e.material),this.initShadowUniform(e,e.material),this.initLightVolumeUniform(e.material),null!=this.scene.environment&&ht(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(p=!0)),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ae])&&isObjectInFrustum(e,c)?(this.initDepthUniform(e.material),U=!0):e instanceof Y&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[ue]&&isObjectInFrustum(e,c)&&e.material instanceof C&&this.initAoUniform(e.material),e instanceof o||e instanceof i.Sprite){let t=!1;ht(e,e=>{this.usesShaderUniform(e,de)&&(this.initSceneColorUniform(e),t=!0)}),t&&(f.push(e),O=!0)}if(e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[ce])e.material.uniforms[ce].value=l;else if(e instanceof o&&Array.isArray(e.material))for(const t of e.material)t.uniforms&&null!=t.uniforms[ce]&&(t.uniforms[ce].value=l)}),this.bloomPass.enabled=p,this.prepareUpscalingFrame(),this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderDepthPrepass(),this.renderScene(Xe.opaque),this.aoPass.output=se.OUTPUT.Off,(U||O)&&(this.fquadCopyOpaque.material.uniforms.tSceneColor.value=this.gRenderTarget.textures[0],this.fquadCopyOpaque.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.initResolutionUniform(this.fquadCopyOpaque.material),this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.renderer.clear(),this.fquadCopyOpaque.render(this.renderer),this.renderer.setRenderTarget(this.gRenderTarget)),f.length,d.forEach(e=>e.visible=!0),m.forEach(e=>e.visible=!0),f.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=s),this.volumetricFogPass&&S?(this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1),this.updatePostProcessEffectUniforms(l);try{!this.paused&&this.running&&(this.render(n),this.finishUpscalingFrame(),this.showStats&&h?.endQuery(),this.showStats&&u(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}finally{this.finishUpscalingFrame()}a.end(),this.csm?.update(),R()};!0===this.options.enableXR?this.renderer.setAnimationLoop(A):requestAnimationFrame(A)}applyGBufferMaterials(e){const t=this.gBufferCachedMaterials,s=this.gBufferCachedVisibility,i=this.gBufferCachedOnBeforeRender;t.clear(),s.length=0,i.clear();ve(this.scene,i=>{if(St(i))return s.push(i),i.visible=!1,!1;if(i instanceof o){t.set(i,i.material);let a=!1;if(Array.isArray(i.material)){i.material=i.material.slice();for(let t=0;t<i.material.length;t++)i.material[t]=this.createGBufferMaterial(i.material[t],e,e===Xe.opaque&&this.isDepthPrepassEligibleMesh(i)),a||(a=i.material[t].visible),this.initShadowUniform(i,i.material[t])}else i.material=this.createGBufferMaterial(i.material,e,e===Xe.opaque&&this.isDepthPrepassEligibleMesh(i)),a||(a=i.material.visible),this.initShadowUniform(i,i.material);this.applyGBufferShadowUniformUpdater(i),a?i.visible=!0:null!=i.children&&0!=i.children.length||(s.push(i),i.visible=!1)}})}unapplyGBufferMaterials(){this.gBufferCachedMaterials.forEach((e,t)=>{t.material=e}),this.gBufferCachedOnBeforeRender.forEach((e,t)=>{t.onBeforeRender=e}),this.gBufferCachedOnBeforeRender.clear(),this.gBufferCachedVisibility.forEach((e,t)=>{e.visible=!0,e.updateMatrixWorld(!0)})}applyGBufferShadowUniformUpdater(e){const t=e.onBeforeRender;this.gBufferCachedOnBeforeRender.set(e,t),e.onBeforeRender=(s,i,a,r,n,o)=>{t.call(e,s,i,a,r,n,o),this.initShadowUniform(e,n)}}initTextures(e=this.scene){e.traverse(e=>{if(e instanceof o)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)this._initMaterialTextures(e.material[t]);else this._initMaterialTextures(e.material)})}_initMaterialTextures(e){if(!this._initiatedMaterialTextures.has(e))if(this._initiatedMaterialTextures.add(e),e instanceof p){for(const[t,s]of Object.entries(e.uniforms))if(s.value instanceof u){if(this._initiatedTextures.has(s.value))continue;this.renderer.initTexture(s.value),this._initiatedTextures.add(s.value)}}else for(const[t,s]of Object.entries(e))if(s instanceof u){if(this._initiatedTextures.has(s))continue;this.renderer.initTexture(s),this._initiatedTextures.add(s)}}async compileAsync(e=this.scene){if(this.compileInProgress)return;this.renderer.setRenderTarget(this.gRenderTarget),this.compileInProgress=!0,this.applyGBufferMaterials(Xe.opaque),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(Xe.transparent),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.isDepthPrepassEnabled()&&(this.renderer.setRenderTarget(this.gRenderTarget),this.applyDepthPrepassMaterials(),await this.renderer.compileAsync(e,this.camera),this.unapplyDepthPrepassMaterials()),e===this.scene&&(this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.compileAsync(this.fquadBlendAO.mesh,this.fquadBlendAO.camera),this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.renderer.compileAsync(this.fquadCopyOpaque.mesh,this.fquadCopyOpaque.camera));const t=this.csm.lights[0]?.shadow.camera;null!=t&&(this.applyDepthMaterial(),await this.renderer.compileAsync(e,t),this.unapplyDepthMaterial()),this.compileInProgress=!1,this.renderer.setRenderTarget(null)}applyDepthMaterial(){const e=this.gBufferCachedMaterials;e.clear(),this.scene.traverse(t=>{(t.isMesh||t.isPoints||t.isLine||t.isSprite)&&(this.initCustomDepthMaterial(t),e.set(t,t.material),t.castShadow?null!=t.customDepthMaterial?t.material=t.customDepthMaterial:t.material=Bt:t.material=null)})}unapplyDepthMaterial(){this.gBufferCachedMaterials.forEach((e,t)=>{t.material=e})}renderScene(e){if(!this.running||this.paused)return;if(this.compileInProgress)return void console.error("Compile in progress, skipping render");this.applyGBufferMaterials(e);const t=this.scene.matrixWorldAutoUpdate,s=this.scene.matrixAutoUpdate,i=this.renderer.shadowMap.autoUpdate;e!==Xe.opaque&&(this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1);try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Render failed",e)}e===Xe.opaque&&this.gBufferCachedMaterials.forEach((e,t)=>{!Array.isArray(e)&&!Array.isArray(t.material)&&e instanceof p&&this.updateLightUniformValues(t.material,e)}),this.unapplyGBufferMaterials(),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t.colorSpace=i.SRGBColorSpace,t}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);!function(e,t=i.NoToneMapping,s=1){e.tonemapMapping=t,e.tonemapExposure=s,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=e.colorTint??new i.Color("white"),e.colorTint.set("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.globalSaturation=dt(e.globalSaturation,1,1,1),e.globalContrast=dt(e.globalContrast,1,1,1),e.globalGamma=dt(e.globalGamma,1,1,1),e.globalGain=dt(e.globalGain,1,1,1),e.globalOffset=dt(e.globalOffset,0,0,0),e.shadowsSaturation=dt(e.shadowsSaturation,1,1,1),e.shadowsContrast=dt(e.shadowsContrast,1,1,1),e.shadowsGamma=dt(e.shadowsGamma,1,1,1),e.shadowsGain=dt(e.shadowsGain,1,1,1),e.shadowsOffset=dt(e.shadowsOffset,0,0,0),e.shadowsMax=.09,e.midtonesSaturation=dt(e.midtonesSaturation,1,1,1),e.midtonesContrast=dt(e.midtonesContrast,1,1,1),e.midtonesGamma=dt(e.midtonesGamma,1,1,1),e.midtonesGain=dt(e.midtonesGain,1,1,1),e.midtonesOffset=dt(e.midtonesOffset,0,0,0),e.highlightsSaturation=dt(e.highlightsSaturation,1,1,1),e.highlightsContrast=dt(e.highlightsContrast,1,1,1),e.highlightsGamma=dt(e.highlightsGamma,1,1,1),e.highlightsGain=dt(e.highlightsGain,1,1,1),e.highlightsOffset=dt(e.highlightsOffset,0,0,0),e.highlightsMin=.5,e.lut=void 0,e.lutIntensity=0}(this.postProcessSettings,this.baseToneMapping,this.baseToneMappingExposure);const e=this.postProcessSettings;let t,s=!1;if(null==this.camera)return;const a=this.camera.getWorldPosition(vt);let r=[];for(const n of this.postProcessVolumes){if(!ot(n.object))continue;let o=n.blendWeight??1;const l=n.distanceToPoint(a);l>n.blendRadius||(n.blendRadius>0&&(o*=Pe(1-l/n.blendRadius,0,1)),o>1&&(o=1),o>0&&(r.push(n),void 0!==n.settings.tonemapMapping&&(e.tonemapMapping=n.settings.tonemapMapping),void 0!==n.settings.tonemapExposure&&(e.tonemapExposure=i.MathUtils.lerp(e.tonemapExposure,n.settings.tonemapExposure,o)),void 0!==n.settings.envTexture&&(e.envTexture=n.settings.envTexture),void 0!==n.settings.envIntensity&&(e.envIntensity=i.MathUtils.lerp(e.envIntensity,n.settings.envIntensity,o)),void 0!==n.settings.vignetteIntensity&&(e.vignetteIntensity=i.MathUtils.lerp(e.vignetteIntensity,n.settings.vignetteIntensity,o)),void 0!==n.settings.colorTint&&void 0!==n.settings.colorTintIntensity&&n.settings.colorTintIntensity>0&&(e.colorTint=e.colorTint.lerp(n.settings.colorTint,o)),void 0!==n.settings.colorTintIntensity&&(e.colorTintIntensity=i.MathUtils.lerp(e.colorTintIntensity,n.settings.colorTintIntensity,o)),void 0!==n.settings.depthFocus&&(s=!0,e.depthFocus=void 0!==e.depthFocus?i.MathUtils.lerp(e.depthFocus,n.settings.depthFocus,o):n.settings.depthFocus),void 0!==n.settings.depthAperture&&(s=!0,e.depthAperture=void 0!==e.depthAperture?i.MathUtils.lerp(e.depthAperture,n.settings.depthAperture,o):n.settings.depthAperture),void 0!==n.settings.depthMaxBlur&&(s=!0,e.depthMaxBlur=void 0!==e.depthMaxBlur?i.MathUtils.lerp(e.depthMaxBlur,n.settings.depthMaxBlur,o):n.settings.depthMaxBlur),void 0!==n.settings.temperature&&(e.temperature=i.MathUtils.lerp(e.temperature,n.settings.temperature,o)),void 0!==n.settings.temperatureTint&&(e.temperatureTint=i.MathUtils.lerp(e.temperatureTint,n.settings.temperatureTint,o)),void 0!==n.settings.globalSaturation&&e.globalSaturation.lerp(n.settings.globalSaturation,o),void 0!==n.settings.globalContrast&&e.globalContrast.lerp(n.settings.globalContrast,o),void 0!==n.settings.globalGamma&&e.globalGamma.lerp(n.settings.globalGamma,o),void 0!==n.settings.globalGain&&e.globalGain.lerp(n.settings.globalGain,o),void 0!==n.settings.globalOffset&&e.globalOffset.lerp(n.settings.globalOffset,o),void 0!==n.settings.shadowsSaturation&&e.shadowsSaturation.lerp(n.settings.shadowsSaturation,o),void 0!==n.settings.shadowsContrast&&e.shadowsContrast.lerp(n.settings.shadowsContrast,o),void 0!==n.settings.shadowsGamma&&e.shadowsGamma.lerp(n.settings.shadowsGamma,o),void 0!==n.settings.shadowsGain&&e.shadowsGain.lerp(n.settings.shadowsGain,o),void 0!==n.settings.shadowsOffset&&e.shadowsOffset.lerp(n.settings.shadowsOffset,o),void 0!==n.settings.shadowsMax&&(e.shadowsMax=i.MathUtils.lerp(e.shadowsMax,n.settings.shadowsMax,o)),void 0!==n.settings.midtonesSaturation&&e.midtonesSaturation.lerp(n.settings.midtonesSaturation,o),void 0!==n.settings.midtonesContrast&&e.midtonesContrast.lerp(n.settings.midtonesContrast,o),void 0!==n.settings.midtonesGamma&&e.midtonesGamma.lerp(n.settings.midtonesGamma,o),void 0!==n.settings.midtonesGain&&e.midtonesGain.lerp(n.settings.midtonesGain,o),void 0!==n.settings.midtonesOffset&&e.midtonesOffset.lerp(n.settings.midtonesOffset,o),void 0!==n.settings.highlightsSaturation&&e.highlightsSaturation.lerp(n.settings.highlightsSaturation,o),void 0!==n.settings.highlightsContrast&&e.highlightsContrast.lerp(n.settings.highlightsContrast,o),void 0!==n.settings.highlightsGamma&&e.highlightsGamma.lerp(n.settings.highlightsGamma,o),void 0!==n.settings.highlightsGain&&e.highlightsGain.lerp(n.settings.highlightsGain,o),void 0!==n.settings.highlightsOffset&&e.highlightsOffset.lerp(n.settings.highlightsOffset,o),void 0!==n.settings.highlightsMin&&(e.highlightsMin=i.MathUtils.lerp(e.highlightsMin,n.settings.highlightsMin,o)),void 0!==n.settings.lut&&(t=n.settings.lut),void 0!==n.settings.lutIntensity&&(e.lutIntensity=i.MathUtils.lerp(e.lutIntensity,n.settings.lutIntensity,o))))}if(0===r.length)return this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);const n=e.vignetteIntensity>Mt,o=(h=e.temperature,p=e.temperatureTint,!ft(h,6500)||!ft(p,0));var h,p;const c=(u=e.colorTint,e.colorTintIntensity>Mt&&(!ft(u.r,1)||!ft(u.g,1)||!ft(u.b,1)));var u;const d=!(mt((m=e).globalSaturation,1,1,1)&&mt(m.globalContrast,1,1,1)&&mt(m.globalGamma,1,1,1)&&mt(m.globalGain,1,1,1)&&mt(m.globalOffset,0,0,0)&&mt(m.shadowsSaturation,1,1,1)&&mt(m.shadowsContrast,1,1,1)&&mt(m.shadowsGamma,1,1,1)&&mt(m.shadowsGain,1,1,1)&&mt(m.shadowsOffset,0,0,0)&&mt(m.midtonesSaturation,1,1,1)&&mt(m.midtonesContrast,1,1,1)&&mt(m.midtonesGamma,1,1,1)&&mt(m.midtonesGain,1,1,1)&&mt(m.midtonesOffset,0,0,0)&&mt(m.highlightsSaturation,1,1,1)&&mt(m.highlightsContrast,1,1,1)&&mt(m.highlightsGamma,1,1,1)&&mt(m.highlightsGain,1,1,1)&&mt(m.highlightsOffset,0,0,0));var m;const f=o||c||d||n,g=f&&e.tonemapMapping!==i.NoToneMapping,M=null!=t&&e.lutIntensity>Mt;f?(this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1):(this.renderer.toneMapping=e.tonemapMapping,this.renderer.toneMappingExposure=e.tonemapExposure),null!=e.envTexture&&(this.scene.environment=this.getEnvTexture(e.envTexture)),this.scene.environmentIntensity=e.envIntensity,f?(this.colorPass.whiteBalanceEnabled=o,this.colorPass.whiteBalanceScale=o?function(e,t,s){const i=function(e){const t=Pe(e,1e3,4e4)/100,s=t<=66?1:Pe(1.292936186062745*Math.pow(t-60,-.1332047592),0,1),i=Pe(t<=66?.3900815787690196*Math.log(t)-.6318414437886275:1.129890860895294*Math.pow(t-60,-.0755148492),0,1),a=t>=66?1:t<=19?0:Pe(.5432067891101962*Math.log(t-10)-1.19625408914,0,1);return yt.set(s,i,a)}(t),a=1+.2*Pe(s,-1,1),r=i.x,n=i.y*a,o=i.z,l=Math.max(n,1e-4);return e.set(1/Math.max(r/l,1e-4),1/Math.max(n/l,1e-4),1/Math.max(o/l,1e-4)),e}(Pt,e.temperature,e.temperatureTint):Pt.set(1,1,1),this.colorPass.vignetteIntensity=e.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTintEnabled=c,this.colorPass.colorTint=e.colorTint,this.colorPass.colorTintIntensity=e.colorTintIntensity,this.colorPass.colorGradingEnabled=d,this.colorPass.toneMapping=e.tonemapMapping,this.colorPass.toneMappingEnabled=g,this.colorPass.toneMappingExposure=e.tonemapExposure,this.colorPass.globalSaturation=e.globalSaturation,this.colorPass.globalContrast=e.globalContrast,this.colorPass.globalGamma=e.globalGamma,this.colorPass.globalGain=e.globalGain,this.colorPass.globalOffset=e.globalOffset,this.colorPass.shadowsSaturation=e.shadowsSaturation,this.colorPass.shadowsContrast=e.shadowsContrast,this.colorPass.shadowsGamma=e.shadowsGamma,this.colorPass.shadowsGain=e.shadowsGain,this.colorPass.shadowsOffset=e.shadowsOffset,this.colorPass.shadowsMax=e.shadowsMax,this.colorPass.midtonesSaturation=e.midtonesSaturation,this.colorPass.midtonesContrast=e.midtonesContrast,this.colorPass.midtonesGamma=e.midtonesGamma,this.colorPass.midtonesGain=e.midtonesGain,this.colorPass.midtonesOffset=e.midtonesOffset,this.colorPass.highlightsSaturation=e.highlightsSaturation,this.colorPass.highlightsContrast=e.highlightsContrast,this.colorPass.highlightsGamma=e.highlightsGamma,this.colorPass.highlightsGain=e.highlightsGain,this.colorPass.highlightsOffset=e.highlightsOffset,this.colorPass.highlightsMin=e.highlightsMin,this.colorPass.enabled=!0):this.colorPass.enabled=!1,s&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==e.depthFocus&&(this.dofPass.uniforms.focus.value=e.depthFocus),void 0!==e.depthAperture&&(this.dofPass.uniforms.aperture.value=e.depthAperture),void 0!==e.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=e.depthMaxBlur)):this.dofPass.enabled=!1,this.lutPass.enabled=M,M&&(null!=t&&(t.flipY=!0,t.generateMipmaps=!1),this.lutPass.lut=t,this.lutPass.intensity=e.lutIntensity)}updatePostProcessEffectUniforms(e){if(0===this.postProcessEffects.length)return;const t=this.postProcessEffectUniformState;t.aoEnabled=this.aoPass.enabled,t.aoTexture=this.aoPass.enabled?this.aoPass.pdRenderTarget.texture:null,this.camera instanceof l?(t.cameraNear=this.camera.near,t.cameraFar=this.camera.far):(t.cameraNear=void 0,t.cameraFar=void 0),t.depthTexture=this.sceneColorRenderTarget.textures[1],t.normalTexture=this.gRenderTarget.textures[2],t.resolution.set(this.gRenderTarget.width,this.gRenderTarget.height),t.simulationTime=e;for(const e of this.postProcessEffects)e.pass.updateUniformState(t)}renderOverlay(){if(!this.running)return;if(0===this.overlayCameras.size)return;const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.previousClientWith/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled&&!1!==this.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible(t=>{t instanceof o&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,pt)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.options.bloom,this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=Me(this.scene,e=>e instanceof o&&!0===e.material?.userData?.hasBloom)}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===$e.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=$e:(e.visible=!1,this.bloomHidden.push(e))}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initSceneColorUniform(e){if(e instanceof p)return null==e.uniforms[de]?(e.uniforms[de]={value:this.sceneColorRenderTarget.texture},void(e.uniformsNeedUpdate=!0)):void(e.uniforms[de].value!==this.sceneColorRenderTarget.texture&&(e.uniforms[de].value=this.sceneColorRenderTarget.texture,e.uniformsNeedUpdate=!0))}initDepthUniform(e){e instanceof p&&(e.uniforms[ae].value=this.sceneColorRenderTarget.textures[1],this.camera instanceof l&&(null!=e.uniforms[ne]&&(e.uniforms[ne].value=this.camera.near),null!=e.uniforms[re]&&(e.uniforms[re].value=this.camera.far)))}initNormalUniform(e){e instanceof p&&null!=e.uniforms[le]&&(e.uniforms[le].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof C&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof C&&(null!=this.lightVolume?null==e.uniforms.uSH?(e.defines.USE_LIGHT_PROBE_VOLUME="",e.uniforms.gridOrigin={value:this.lightVolume.gridOrigin},e.uniforms.gridSize={value:this.lightVolume.gridSize},e.uniforms.gridRes={value:this.lightVolume.gridResolution},e.uniforms.giIntensity={value:this.lightProbeIntensity},e.uniforms.uSH={value:this.lightVolume.shTexture},e.uniformsNeedUpdate=!0,e.needsUpdate=!0):e.uniforms.giIntensity.value=this.lightProbeIntensity:null!=e.uniforms.uSH&&(delete e.defines.USE_LIGHT_PROBE_VOLUME,delete e.uniforms.gridOrigin,delete e.uniforms.gridSize,delete e.uniforms.gridRes,delete e.uniforms.giIntensity,delete e.uniforms.uSH,e.uniformsNeedUpdate=!0,e.needsUpdate=!0))}initResolutionUniform(e){e instanceof p&&null!=e.uniforms[oe]&&e.uniforms[oe].value.set(this.gRenderTarget.width,this.gRenderTarget.height)}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[ue].value=this.aoPass.pdRenderTarget.texture,null==e.defines.USE_SSAO_MAP&&(e.defines.USE_SSAO_MAP="",e.needsUpdate=!0),e.defines.USE_SSAO_MAP="";const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}else if(null!=e.defines.USE_SSAO_MAP){delete e.defines.USE_SSAO_MAP,e.needsUpdate=!0;const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}}initCustomDepthMaterial(e){if(null!=e.customDepthMaterial||!e.castShadow)return;const t=e.material;if(!(t instanceof C&&t.depthWrite&&t.alphaTest>0))return;let s=this._customDepthMaterialCache.get(t);if(null==s){const e=Fe(Ee);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new C({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}};rt.activeView=null,rt=e=t([ie(),s("design:paramtypes",[HTMLElement,Object])],rt);export{rt as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const nt=.05;function ot(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}function lt(e,t){return e.priority!==t.priority?e.priority-t.priority:e.id-t.id}function ht(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}se.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};const pt=new i.Frustum,ct=new i.Box3,ut=new i.Matrix4;export function isObjectInFrustum(e,t){const s=ct.setFromObject(e);return t.intersectsBox(s)}function dt(e,t,s,a){return null==e?new i.Vector3(t,s,a):e.set(t,s,a)}function mt(e,t,s,i){return null!=e&&ft(e.x,t)&&ft(e.y,s)&&ft(e.z,i)}function ft(e,t,s=Mt){return Math.abs(e-t)<=s}function gt(e,t){return null!=e&&Number.isFinite(e)&&e>0?e:t}const Mt=1e-4,vt=new i.Vector3,Pt=new i.Vector3(1,1,1),yt=new i.Vector3(1,1,1);const bt=new n,wt=new d;function Tt(e,t,s=new i.Matrix3){return wt.copy(e),wt.x*=-1,wt.y*=-1,wt.z*=-1,t.isCubeTexture&&!1===t.isRenderTargetTexture&&(wt.y*=-1,wt.z*=-1),s.setFromMatrix4(bt.makeRotationFromEuler(wt))}const xt=new C({outputs:[_(0,0,0,0),_(0,0,0,0),D(G("white"),Ie(4))],transparent:!0}),Rt=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});xt.depthWrite=!1;new o(new i.BoxGeometry(4,4,4),Rt);function St(e){return e instanceof i.Sprite||e.isPoints||e.isLine||e.isLineSegments2||e.isTransformControls||e.isTransformControlsGizmo||e instanceof o&&Ct(e,e.material)}function Ct(e,t){return null==t||(Array.isArray(t)?t.some(t=>Ct(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof C))}class Ut extends Le{constructor(e,t,s){super(),this.scene=e,this.camera=t,this.gRenderTarget=s,this.cachedVisibility=[],this.toRender=[],this.needsSwap=!1}render(e,t,s,i,a){const r=e.autoClear;e.autoClear=!1;const n=this.scene.matrixWorldAutoUpdate,l=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const p=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),this.cachedVisibility.length=0;let c=0,u=this.toRender;if(u.length=0,this.scene.traverseVisible(e=>{const t=St(e);e instanceof o&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(c++,u.push(e))}),c>0)for(const t of u)e.render(t,this.camera);this.cachedVisibility.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=r,s.depthTexture=p,this.scene.matrixWorldAutoUpdate=n,this.scene.matrixAutoUpdate=l,e.shadowMap.autoUpdate=h}}class At extends Le{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const Ot=["ambientLightColor","cameraNear","directionalLightShadows","directionalLights","directionalShadowMap","directionalShadowMatrix","fogColor","fogDensity","fogFar","fogNear","hemisphereLights","lightProbe","ltc_1","ltc_2","pointLightShadows","pointLights","pointShadowMap","pointShadowMatrix","rectAreaLights","shadowFar","spotLightMap","spotLightMatrix","spotLightShadows","spotLights","spotShadowMap"],Et=["directionalShadowMap","directionalShadowMatrix","pointLightShadows","pointShadowMap","pointShadowMatrix","spotLightShadows","spotShadowMap"],Ft=O("fogColor");export class FogNode extends k{constructor(e,t=Ft){super(),this.source=e,this.fogColor=t}compile(e){const t=e.variable(),s=e.get(this.source.rgb),i=e.get(this.source.a),a=e.get(this.fogColor),r=e.get(A("fogFar")),n=e.get(A("fogNear")),o=e.get(A("fogDensity")),l=e.get(I(j.mvPosition.z));return{pars:"\n ",chunk:`\n #ifdef FOG_EXP2\n float fogFactor_${t} = 1.0 - exp( - ${o} * ${o} * ${l} * ${l} );\n #else\n float fogFactor_${t} = smoothstep( ${n}, ${r}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${a}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}const Bt=new i.MeshDepthMaterial({depthPacking:i.RGBADepthPacking});/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Material, Object3D, Texture } from 'three';
|
|
2
|
-
import { Asset, AssetId, ModelColliderData } from './model.js';
|
|
2
|
+
import { AnimationRigData, Asset, AssetId, ModelColliderData } from './model.js';
|
|
3
3
|
import { CollisionShape } from './collision/collision-shape.js';
|
|
4
4
|
import * as THREE from 'three';
|
|
5
5
|
import { SceneObjectPhysicsSettings } from './materializer.js';
|
|
@@ -21,6 +21,7 @@ export declare class AssetResourceLoader {
|
|
|
21
21
|
private audioLoader;
|
|
22
22
|
private initialisedKtx2;
|
|
23
23
|
materialProvider?: (id: AssetId) => Promise<Material>;
|
|
24
|
+
animationRigProvider?: (id: AssetId) => Promise<AnimationRigData | undefined>;
|
|
24
25
|
/**
|
|
25
26
|
* Keeping track of all resources ever loaded
|
|
26
27
|
* so that they can be cleaned up.
|
|
@@ -117,6 +118,11 @@ export type GetMeshOptions = {
|
|
|
117
118
|
* @default false
|
|
118
119
|
*/
|
|
119
120
|
rescale?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Whether to apply the assigned animation rig's coordinate-basis correction.
|
|
123
|
+
* @default true
|
|
124
|
+
*/
|
|
125
|
+
applyRigBasis?: boolean;
|
|
120
126
|
/**
|
|
121
127
|
* Whether to apply asset materials to the mesh.
|
|
122
128
|
* @default false
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{AudioLoader as e,BufferGeometry as t,Euler as r,Group as s,LoadingManager as a,Mesh as i,Object3D as n,Texture as o,TextureLoader as l,Vector3 as c}from"three";import{MTLLoader as h,OBJLoader as u,LUTCubeLoader as m}from"three-stdlib";import{cloneMesh as p}from"../utils/mesh.js";import{pathJoin as d}from"../utils/files.js";import{Subject as f,firstValueFrom as y}from"rxjs";import{BoxCollisionShape as g,CapsuleCollisionShape as w,CollisionShapeSource as x,CylinderCollisionShape as M,SphereCollisionShape as A}from"./collision/collision-shape.js";import{importCollisionShapes as b,isCollisionMesh as _}from"./collision/collision-shape-import.js";import*as S from"three";import{iterateMaterials as L}from"../utils/materials.js";import{applyMaterial as T,getConvertedFbxToGlbAssignedMaterialTextureFlipY as v}from"./materializer.js";import{BufferGeometryUtils as C,DRACOLoader as K,EXRLoader as P,FBXLoader as R,GLTFLoader as k,KTX2Loader as B,TGALoader as F,UltraHDRLoader as I}from"three/examples/jsm/Addons.js";import{disposeScene as W}from"../utils/three/cleanup.js";(()=>{const e=new Uint8Array([255,0,0,255]),t=new S.DataTexture(e,1,1,S.RGBAFormat);t.needsUpdate=!0})();const j=new K;j.setDecoderConfig({type:"js"}),j.setDecoderPath("/assets/draco/");const D=["glb","gltf","fbx","obj"];export class AssetResourceLoader{onError(e){console.error(e)}constructor(){this.cache=new Map,this.textureCache=new Map,this.loadingManager=new a,this.glbLoader=new k(this.loadingManager).setDRACOLoader(j),this.fbxLoader=new R(this.loadingManager),this.objLoader=new u(this.loadingManager),this.textureLoader=new l(this.loadingManager),this.tgaLoader=new F(this.loadingManager),this.exrLoader=new P(this.loadingManager),this.cubeLoader=new m(this.loadingManager),this.hdrLoader=new I(this.loadingManager),this.ktx2Loader=new B(this.loadingManager),this._textureLoader=new S.ImageBitmapLoader(this.loadingManager),this.audioLoader=new e(this.loadingManager),this.initialisedKtx2=!1,this._retrievedMeshes=[],this._retrievedTextures=[],this.makeReady=new f,this.ready=y(this.makeReady),this._texturePromises=new Map,this._arrayTexturesByFileKey=new Map,this._arrayTextureSettingsByFileKey=new Map,this._animationPromises=new Map,this._animationCache=new Map,this.asyncMeshResults=new Map,this.asyncAudioResults=new Map,this.collisionShapeCache=new Map,this.optimizedMeshes=new Set}initKtx2(e){this.initialisedKtx2=!0;null!=getElectronArg("windowId")||import.meta.url.includes(".vite")||import.meta.url.includes("hology/packages/core")?this.ktx2Loader.setTranscoderPath("/assets/basis/"):this.ktx2Loader.setTranscoderPath(new URL("../assets/basis/",import.meta.url).href),this.ktx2Loader.detectSupport(e),this.ktx2Loader.setWorkerLimit(6)}setDataDir(e){this.basePath=d(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){const t=function(e){return U.get(e)}(e),r=getElectronArg("windowId");return null!=r||import.meta.url.includes(".vite")||import.meta.url.includes("hology/packages/core")?d(this.basePath,e)+(null!=r?`?windowId=${r}${null!=t?`&v=${t}`:""}`:""):new URL(d("..",this.basePath,e),import.meta.url).href}async getTexture(e){if(!e||!e.fileKey)return null;if("png"===e.fileFormat||e.fileFormat,this._texturePromises.has(e.id))return this._texturePromises.get(e.id);const t=this._getTexture(e).finally(()=>{this._texturePromises.delete(e.id)});return this._texturePromises.set(e.id,t),t}async _getTexture(e){if(null==e||null==e.fileKey)return null;if(await this.ready,this.textureCache.has(e.id)){const t=this.textureCache.get(e.id);if(null!=e.texture){const r=$(t,e);t.flipY!==r?(t.needsUpdate=!0,t.flipY=r):t.wrapS!==z(e.texture?.wrapS)?(t.needsUpdate=!0,t.wrapS=z(e.texture?.wrapS)):t.wrapT!==z(e.texture?.wrapT)&&(t.wrapT=z(e.texture?.wrapT),t.needsUpdate=!0)}const r=O(Y(e));t.colorSpace!==r&&(t.colorSpace=r,t.needsUpdate=!0)}else try{await this._getTextureLoader(e.fileKey).loadAsync(this.getUri(e.fileKey)).then(t=>(t.texture3D?t=t.texture3D:(t.wrapS=z(e.texture?.wrapS),t.wrapT=z(e.texture?.wrapT),t.flipY=$(t,e),t.colorSpace=O(Y(e))),this.textureCache.set(e.id,t),this._retrievedTextures.push(t),t))}catch(t){return console.warn("Failed to load texture "+e.name,t),null}const t=this.textureCache.get(e.id);return null!=t&&(t.userData.assetId=e.id),t}async getTextureArray(e){const t=e.texture?.textureArrayFileKey,r=e.texture?.textureArrayLayer;if(!t||null==r)return{texture:null,layerIndex:null};if(this._arrayTexturesByFileKey.has(t))this.applyTextureArraySettings(t,this._arrayTexturesByFileKey.get(t),e);else{const r=this._getTextureLoader(t);let s=await r.loadAsync(this.getUri(t));s instanceof o||(s=s.texture3D),this.applyTextureArraySettings(t,s,e),this._arrayTexturesByFileKey.set(t,s),this._retrievedTextures.push(s)}return{texture:this._arrayTexturesByFileKey.get(t),layerIndex:r}}applyTextureArraySettings(e,t,r){const s=function(e){return{wrapS:z(e.texture?.wrapS),wrapT:z(e.texture?.wrapT)}}(r),a=this._arrayTextureSettingsByFileKey.get(e);if(null!=a&&(n=s,(i=a).wrapS!==n.wrapS||i.wrapT!==n.wrapT))return void console.warn(`Texture array ${e} is used with incompatible texture settings. Texture arrays share wrapping; rebuild arrays so incompatible textures are grouped separately.`);var i,n;null==a&&this._arrayTextureSettingsByFileKey.set(e,s);let o=!1;t.wrapS!==s.wrapS&&(t.wrapS=s.wrapS,o=!0),t.wrapT!==s.wrapT&&(t.wrapT=s.wrapT,o=!0),!1!==t.flipY&&(t.flipY=!1,o=!0),o&&(t.needsUpdate=!0)}_getTextureLoader(e){return e?.toLowerCase().endsWith(".tga")?this.tgaLoader:e?.toLowerCase().endsWith(".ktx2")?this.ktx2Loader:e?.toLowerCase().endsWith(".exr")?this.exrLoader:e?.toLowerCase().endsWith(".cube")?this.cubeLoader:this.textureLoader}clearCache(e){this.clearCacheByAsset(e)}clearCacheByAsset(e){null!=e&&(this.clearCacheById(e.id),null!=e.fileKey&&(Array.from(this.cache.keys()).forEach(t=>{t.startsWith(e.fileKey)&&this.cache.delete(t)}),Array.from(this.asyncMeshResults.keys()).forEach(t=>{t.startsWith(e.fileKey)&&this.asyncMeshResults.delete(t)}),Array.from(this._animationCache.keys()).forEach(t=>{t.startsWith(e.fileKey+"|")&&this._animationCache.delete(t)}),Array.from(this._animationPromises.keys()).forEach(t=>{t.startsWith(e.fileKey+"|")&&this._animationPromises.delete(t)}),E(e.fileKey)),null!=e.materialLib&&E(e.materialLib))}clearCacheById(e){const t=Array.from(this.cache.values()).find(t=>t.scene.userData.assetId===e);t&&Array.from(this.cache.keys()).forEach(e=>{this.cache.get(e)===t&&this.cache.delete(e)}),this.textureCache.delete(e),this._texturePromises.delete(e),Array.from(this.collisionShapeCache.keys()).forEach(t=>{t.startsWith(e+"|")&&this.collisionShapeCache.delete(t)})}async getMesh(e,t){if(await this.ready,null==e)return console.error("No asset was provided"),{scene:new s,animations:[]};if(!D.includes(e.fileFormat?.toLowerCase()))return console.error("Unsupported mesh file format "+e.fileFormat,e),{scene:new s,animations:[]};const r=e.fileKey+(!0===t?.mergeGeomtries?"1":"0");if(!this.cache.has(r))try{this.asyncMeshResults.has(r)||this.asyncMeshResults.set(r,this.loadMesh(e).finally(()=>this.asyncMeshResults.delete(r))),this.cache.set(r,await this.asyncMeshResults.get(r))}catch(e){return this.onError(e),{scene:new s,animations:[]}}const a=this.cache.get(r).scene,n=this.computeCollisionShapes(e,a);!0===t?.mergeGeomtries&&this.optimizeDrawGroups(a);const o=p(a),l=this.cache.get(r).animations;o.traverse(e=>{e instanceof i&&e.material instanceof Array&&(e.material=e.material.slice())});const c=new AssetMeshInstance;c.add(o),c.collisionShapes=n,c.animations=l;const h=e.receiveShadow??!1,u=e.castShadow??!1;if(o.traverse(e=>{e.castShadow=u,e.receiveShadow=h}),!0===t?.rescale&&"number"==typeof e.mesh?.rescale&&c.scale.setScalar(e.mesh?.rescale),!0===t?.applyMaterials){const r=t?.materialResolver??this.materialProvider;if(null!=r)for(const t of e.materialAssignments??[])await T(c,t,r,void 0,{textureFlipY:v(e)});else console.warn(`applyMaterials was set to true for ${e.name} but no material resolver was provided.`)}return{scene:c,animations:l}}async getAudio(e){await this.ready;const t=e.fileKey;if(this.asyncAudioResults.has(t))return await this.asyncAudioResults.get(t);const r=this.audioLoader.loadAsync(this.getUri(e.fileKey)).finally(()=>{setTimeout(()=>{this.asyncAudioResults.delete(t)},1e3)});return this.asyncAudioResults.set(t,r),r}async getAnimationClip(e){if(null==e||null==e.fileKey||null==e.anim?.clip)return console.warn("Asset or animation clip name is not defined",e),null;const t=e.anim.clip,r=e.fileKey+"|"+t;if(this._animationCache.has(r))return this._animationCache.get(r);if(this._animationPromises.has(r))return this._animationPromises.get(r);const s=(async()=>{try{const s=await this.getMesh(e),a=s.animations.find(e=>e.name===t);return null!=a&&this._animationCache.set(r,a),a}catch(e){return this.onError(e),null}finally{setTimeout(()=>this._animationPromises.delete(r),1e3)}})();return this._animationPromises.set(r,s),s}computeCollisionShapes(e,t){if(!0!==e.collisionDetection)return[];const r=e.id+"|"+(e.mesh?.collisions?.shapeType??"")+"|"+(e.mesh?.rescale??1)+"|"+JSON.stringify(e.mesh?.colliders??[]);if(!this.collisionShapeCache.has(r)){const s=e.mesh?.colliders??[],a=s.length>0?createAuthoredCollisionShapes(s,e.mesh?.rescale):b(t,e);this.collisionShapeCache.set(r,a)}return this.collisionShapeCache.get(r)}async loadMesh(e){return await this.ready,await this.loadByAsset(e).then(r=>(r.scene.traverse(e=>{e instanceof i&&e.material&&function(e){let t=e.material;if(null==t)return;Array.isArray(t)?e.material=t.map(J):e.material=J(t)}(e),_(e)?e.visible=!1:e instanceof i&&e.geometry instanceof t&&(e.geometry.hasAttribute("normal")||e.geometry.computeVertexNormals())}),this._retrievedMeshes.push(r.scene),r.scene=function(e,t){let r=!1;if(t.traverseVisible(e=>{X.test(e.name)&&(r=!0)}),!r)return t;const s=[],a=[t];for(;a.length>0;){const e=a.shift(),t=e.name.match(X);if(null!=t){const r=parseInt(t[1]);if(0!==r){console.warn(`Skipping LOD level ${r} for now as LOD is not fully supported`),s.push(e);continue}}a.push(...e.children)}for(const e of s)e.removeFromParent();return t}(0,r.scene),function(e){const t=V;V.length=0,e.traverse(e=>{(e instanceof S.Camera||e instanceof S.Light)&&t.push(e)}),t.forEach(e=>e.removeFromParent())}(r.scene),r.scene.userData.assetId=e.id,r))}optimizeDrawGroups(e){if(this.optimizedMeshes.has(e.uuid))return;this.optimizedMeshes.add(e.uuid),e.updateWorldMatrix(!0,!0);const r=[];e.traverse(e=>{e instanceof i&&!(e instanceof S.SkinnedMesh)&&e.geometry instanceof t&&Array.isArray(e.material)&&!_(e)&&r.push({mesh:e,geometry:e.geometry,materialArray:e.material,parent:e.parent})});for(const{mesh:t,geometry:s,materialArray:a,parent:n}of r){t.removeFromParent();for(let r=0;r<a.length;r++){const o=a[r],l=s.groups.filter(e=>e.materialIndex===r);if(0===l.length)continue;const c=this.extractGeometryGroups(s,l);c.groups.length>1&&C.mergeGroups(c);const h=new i(c,o);h.copy(t,!1),h.geometry=c,h.material=o,n?n.add(h):e.add(h)}s.dispose()}let s=!0,a=0,n=0;if(e.traverse(e=>{if(e instanceof i&&e.geometry instanceof t&&!_(e)){a++;const t=Object.keys(e.geometry.attributes).length;t!==n&&0!==n&&(s=!1),n=t}else(e instanceof S.SkinnedMesh||e instanceof S.Bone)&&(s=!1)}),a>1&&s){const r=new Map;e.traverse(s=>{if(s instanceof i&&s.geometry instanceof t&&!_(s)){if(Array.isArray(s.material))return;s.updateWorldMatrix(!0,!0);const t=s.material?.uuid||"default";r.has(t)||r.set(t,{material:s.material,geometries:[],objects:[]});const a=r.get(t),i=e.matrixWorld.clone().invert().multiply(s.matrixWorld);a.geometries.push(s.geometry.clone().applyMatrix4(i)),a.objects.push(s)}});for(const e of r.values())for(const t of e.objects)t.removeFromParent();for(const t of r.values()){let r;r=1===t.geometries.length?t.geometries[0]:C.mergeGeometries(t.geometries,!0),r.groups.length>1&&C.mergeGroups(r),e.add(new i(r,t.material))}}e.traverse(e=>{if(e instanceof i&&e.geometry instanceof t&&!_(e)){const t=e.geometry;!Array.isArray(e.material)&&t.groups.length>1&&C.mergeGroups(t)}})}extractGeometryGroups(e,r){const s=e.index;if(!s){const s=new t;let a=0;for(const e of r)a+=e.count;if(0===a)return s;for(const t in e.attributes){const i=e.attributes[t],n=i.itemSize,o=i.array,l=new(0,o.constructor)(a*n);let c=0;for(const e of r){const t=e.start*n,r=e.count*n;for(let e=0;e<r;e++)l[c+e]=o[t+e];c+=r}const h=new S.BufferAttribute(l,n,i.normalized);s.setAttribute(t,h)}return s.groups=[{start:0,count:a,materialIndex:0}],s}const a=[];for(const e of r)for(let t=0;t<e.count;t++){const r=s.getX(e.start+t);a.push(r)}if(0===a.length)return new t;const i=new Map,n=[];let o=0;for(const e of a)i.has(e)||(i.set(e,o),o++),n.push(i.get(e));if(0===n.length||0===i.size)return new t;const l=new t;for(const t in e.attributes){const r=e.attributes[t],s=r.itemSize,a=r.array,n=new(0,a.constructor)(i.size*s);for(const[e,t]of i)for(let r=0;r<s;r++)n[t*s+r]=a[e*s+r];const o=new S.BufferAttribute(n,s,r.normalized);l.setAttribute(t,o)}const c=new((n.length>0?Math.max(...n):0)>65535?Uint32Array:Uint16Array)(n.length);for(let e=0;e<n.length;e++)c[e]=n[e];return l.setIndex(new S.BufferAttribute(c,1)),l.groups=[{start:0,count:n.length,materialIndex:0}],l}async loadByAsset(e){this.fbxLoader;const t=this.getUri(e.fileKey);switch(e.fileFormat){case"glb":case"gltf":return this.glbLoader.loadAsync(t).then(e=>({scene:e.scene,animations:e.animations}));case"fbx":return this.fbxLoader.loadAsync(t).then(e=>({scene:e,animations:e.animations}));case"obj":if(null!=e.materialLib){const t=new h;t.materialOptions={normalizeRGB:!1};const r=await t.loadAsync(this.getUri(e.materialLib));this.objLoader.setMaterials(r)}return this.objLoader.loadAsync(t).then(e=>(G(e),e)).then(e=>({scene:e,animations:e.animations}))}}disposeAll(){this.cache.clear(),this._retrievedMeshes.forEach(e=>W(e)),this._retrievedTextures.forEach(e=>e.dispose()),this._retrievedMeshes.length=0,this._retrievedTextures.length=0}}const U=new Map;function E(e){U.set(e,(U.get(e)??0)+1)}function G(e){if(e instanceof i)for(const t of L(e.material))t instanceof S.MeshPhongMaterial&&!t.color.isLinear&&(t.color.isLinear=!0);e.children?.forEach(G)}export class AssetMeshInstance extends n{}export function createAuthoredCollisionShapes(e,t=1){const s=null!=t&&0!==t?1/t:1;return e.map(e=>{let t;switch(e.type){case"box":t=new g((new c).fromArray(e.size).multiplyScalar(s));break;case"sphere":t=new A(e.radius*s);break;case"capsule":t=new w(e.length*s,e.radius*s);break;case"cylinder":t=new M(e.radius*s,e.radius*s,e.height*s,16,new r)}return t.source=x.custom,t.offset.fromArray(e.position??[0,0,0]).multiplyScalar(s),t.rotation.fromArray(e.rotation??[0,0,0,"XYZ"]),t})}export function getElectronArg(e){const t=`--${e}=`,r=window.process?.argv.find(e=>e.startsWith(t));return r?.substring(t.length)}function z(e){switch(e){case"clamp":return S.ClampToEdgeWrapping;case"repeat":return S.RepeatWrapping;case"mirror":return S.MirroredRepeatWrapping}return S.RepeatWrapping}function $(e,t){const r=e;return!0!==r.isCompressedTexture&&!0!==r.isCompressedArrayTexture&&(t.texture?.flipY??!0)}function Y(e){return e.texture?.colorSpace??function(e){if("exr"===e.fileFormat||e.fileKey?.toLowerCase().endsWith(".exr"))return"linear";const t=`${e.name} ${e.fileKey??""}`.toLowerCase();if(N.some(e=>t.includes(e)))return"linear";return"srgb"}(e)}function O(e){return"linear"===e?S.LinearSRGBColorSpace:S.SRGBColorSpace}const N=["_normal","_nrm","_nor","_norm","_roughness","_rough","_metalness","_metallic","_metal","_ao","_ambient","_occlusion","_mask","_height","_disp","_displacement","_bump","_opacity"];new S.Matrix4;const V=[];const X=/_LOD(\d+)/;function J(e){let t=e instanceof S.MeshPhysicalMaterial&&0===e.sheen&&0===e.anisotropy;if("MeshLambertMaterial"===e.type||"MeshPhongMaterial"===e.type||t){let t={};(e instanceof S.MeshLambertMaterial||e instanceof S.MeshPhongMaterial||e instanceof S.MeshPhysicalMaterial)&&(t.color=e.color,t.map=e.map,t.bumpMap=e.bumpMap,t.bumpScale=e.bumpScale,t.lightMap=e.lightMap,t.lightMapIntensity=e.lightMapIntensity,t.aoMap=e.aoMap,t.aoMapIntensity=e.aoMapIntensity,t.emissiveMap=e.emissiveMap,t.alphaMap=e.alphaMap,t.envMap=e.envMap,t.envMapRotation=e.envMapRotation,t.wireframe=e.wireframe,t.wireframeLinewidth=e.wireframeLinewidth,t.fog=e.fog,t.opacity=e.opacity,t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t.alphaTest=e.alphaTest,t.displacementMap=e.displacementMap,t.displacementScale=e.displacementScale,t.displacementBias=e.displacementBias);const r=new S.MeshStandardMaterial(t);return r.userData={...e.userData??{}},r.name=e.name,r}return e}/*
|
|
1
|
+
import{AudioLoader as e,BufferGeometry as t,Euler as r,Group as a,LoadingManager as s,Mesh as i,Object3D as n,Texture as o,TextureLoader as l,Vector3 as c}from"three";import{MTLLoader as h,OBJLoader as u,LUTCubeLoader as m}from"three-stdlib";import{cloneMesh as p}from"../utils/mesh.js";import{pathJoin as d}from"../utils/files.js";import{Subject as f,firstValueFrom as y}from"rxjs";import{BoxCollisionShape as g,CapsuleCollisionShape as w,CollisionShapeSource as x,CylinderCollisionShape as M,SphereCollisionShape as A}from"./collision/collision-shape.js";import{importCollisionShapes as b,isCollisionMesh as _}from"./collision/collision-shape-import.js";import*as S from"three";import{iterateMaterials as L}from"../utils/materials.js";import{applyMaterial as T,getConvertedFbxToGlbAssignedMaterialTextureFlipY as v}from"./materializer.js";import{BufferGeometryUtils as C,DRACOLoader as R,EXRLoader as P,FBXLoader as K,GLTFLoader as I,KTX2Loader as k,TGALoader as B,UltraHDRLoader as D}from"three/examples/jsm/Addons.js";import{disposeScene as F}from"../utils/three/cleanup.js";import{resolveAnimationRigBasisRotation as W,setAnimationClipRigId as j}from"../gameplay/animation/retarget.js";(()=>{const e=new Uint8Array([255,0,0,255]),t=new S.DataTexture(e,1,1,S.RGBAFormat);t.needsUpdate=!0})();const U=new R;U.setDecoderConfig({type:"js"}),U.setDecoderPath("/assets/draco/");const E=["glb","gltf","fbx","obj"];export class AssetResourceLoader{onError(e){console.error(e)}constructor(){this.cache=new Map,this.textureCache=new Map,this.loadingManager=new s,this.glbLoader=new I(this.loadingManager).setDRACOLoader(U),this.fbxLoader=new K(this.loadingManager),this.objLoader=new u(this.loadingManager),this.textureLoader=new l(this.loadingManager),this.tgaLoader=new B(this.loadingManager),this.exrLoader=new P(this.loadingManager),this.cubeLoader=new m(this.loadingManager),this.hdrLoader=new D(this.loadingManager),this.ktx2Loader=new k(this.loadingManager),this._textureLoader=new S.ImageBitmapLoader(this.loadingManager),this.audioLoader=new e(this.loadingManager),this.initialisedKtx2=!1,this._retrievedMeshes=[],this._retrievedTextures=[],this.makeReady=new f,this.ready=y(this.makeReady),this._texturePromises=new Map,this._arrayTexturesByFileKey=new Map,this._arrayTextureSettingsByFileKey=new Map,this._animationPromises=new Map,this._animationCache=new Map,this.asyncMeshResults=new Map,this.asyncAudioResults=new Map,this.collisionShapeCache=new Map,this.optimizedMeshes=new Set}initKtx2(e){this.initialisedKtx2=!0;null!=getElectronArg("windowId")||import.meta.url.includes(".vite")||import.meta.url.includes("hology/packages/core")?this.ktx2Loader.setTranscoderPath("/assets/basis/"):this.ktx2Loader.setTranscoderPath(new URL("../assets/basis/",import.meta.url).href),this.ktx2Loader.detectSupport(e),this.ktx2Loader.setWorkerLimit(6)}setDataDir(e){this.basePath=d(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){const t=function(e){return G.get(e)}(e),r=getElectronArg("windowId");return null!=r||import.meta.url.includes(".vite")||import.meta.url.includes("hology/packages/core")?d(this.basePath,e)+(null!=r?`?windowId=${r}${null!=t?`&v=${t}`:""}`:""):new URL(d("..",this.basePath,e),import.meta.url).href}async getTexture(e){if(!e||!e.fileKey)return null;if("png"===e.fileFormat||e.fileFormat,this._texturePromises.has(e.id))return this._texturePromises.get(e.id);const t=this._getTexture(e).finally(()=>{this._texturePromises.delete(e.id)});return this._texturePromises.set(e.id,t),t}async _getTexture(e){if(null==e||null==e.fileKey)return null;if(await this.ready,this.textureCache.has(e.id)){const t=this.textureCache.get(e.id);if(null!=e.texture){const r=O(t,e);t.flipY!==r?(t.needsUpdate=!0,t.flipY=r):t.wrapS!==Y(e.texture?.wrapS)?(t.needsUpdate=!0,t.wrapS=Y(e.texture?.wrapS)):t.wrapT!==Y(e.texture?.wrapT)&&(t.wrapT=Y(e.texture?.wrapT),t.needsUpdate=!0)}const r=V(N(e));t.colorSpace!==r&&(t.colorSpace=r,t.needsUpdate=!0)}else try{await this._getTextureLoader(e.fileKey).loadAsync(this.getUri(e.fileKey)).then(t=>(t.texture3D?t=t.texture3D:(t.wrapS=Y(e.texture?.wrapS),t.wrapT=Y(e.texture?.wrapT),t.flipY=O(t,e),t.colorSpace=V(N(e))),this.textureCache.set(e.id,t),this._retrievedTextures.push(t),t))}catch(t){return console.warn("Failed to load texture "+e.name,t),null}const t=this.textureCache.get(e.id);return null!=t&&(t.userData.assetId=e.id),t}async getTextureArray(e){const t=e.texture?.textureArrayFileKey,r=e.texture?.textureArrayLayer;if(!t||null==r)return{texture:null,layerIndex:null};if(this._arrayTexturesByFileKey.has(t))this.applyTextureArraySettings(t,this._arrayTexturesByFileKey.get(t),e);else{const r=this._getTextureLoader(t);let a=await r.loadAsync(this.getUri(t));a instanceof o||(a=a.texture3D),this.applyTextureArraySettings(t,a,e),this._arrayTexturesByFileKey.set(t,a),this._retrievedTextures.push(a)}return{texture:this._arrayTexturesByFileKey.get(t),layerIndex:r}}applyTextureArraySettings(e,t,r){const a=function(e){return{wrapS:Y(e.texture?.wrapS),wrapT:Y(e.texture?.wrapT)}}(r),s=this._arrayTextureSettingsByFileKey.get(e);if(null!=s&&(n=a,(i=s).wrapS!==n.wrapS||i.wrapT!==n.wrapT))return void console.warn(`Texture array ${e} is used with incompatible texture settings. Texture arrays share wrapping; rebuild arrays so incompatible textures are grouped separately.`);var i,n;null==s&&this._arrayTextureSettingsByFileKey.set(e,a);let o=!1;t.wrapS!==a.wrapS&&(t.wrapS=a.wrapS,o=!0),t.wrapT!==a.wrapT&&(t.wrapT=a.wrapT,o=!0),!1!==t.flipY&&(t.flipY=!1,o=!0),o&&(t.needsUpdate=!0)}_getTextureLoader(e){return e?.toLowerCase().endsWith(".tga")?this.tgaLoader:e?.toLowerCase().endsWith(".ktx2")?this.ktx2Loader:e?.toLowerCase().endsWith(".exr")?this.exrLoader:e?.toLowerCase().endsWith(".cube")?this.cubeLoader:this.textureLoader}clearCache(e){this.clearCacheByAsset(e)}clearCacheByAsset(e){null!=e&&(this.clearCacheById(e.id),null!=e.fileKey&&(Array.from(this.cache.keys()).forEach(t=>{t.startsWith(e.fileKey)&&this.cache.delete(t)}),Array.from(this.asyncMeshResults.keys()).forEach(t=>{t.startsWith(e.fileKey)&&this.asyncMeshResults.delete(t)}),Array.from(this._animationCache.keys()).forEach(t=>{t.startsWith(e.fileKey+"|")&&this._animationCache.delete(t)}),Array.from(this._animationPromises.keys()).forEach(t=>{t.startsWith(e.fileKey+"|")&&this._animationPromises.delete(t)}),z(e.fileKey)),null!=e.materialLib&&z(e.materialLib))}clearCacheById(e){const t=Array.from(this.cache.values()).find(t=>t.scene.userData.assetId===e);t&&Array.from(this.cache.keys()).forEach(e=>{this.cache.get(e)===t&&this.cache.delete(e)}),this.textureCache.delete(e),this._texturePromises.delete(e),Array.from(this.collisionShapeCache.keys()).forEach(t=>{t.startsWith(e+"|")&&this.collisionShapeCache.delete(t)})}async getMesh(e,t){if(await this.ready,null==e)return console.error("No asset was provided"),{scene:new a,animations:[]};if(!E.includes(e.fileFormat?.toLowerCase()))return console.error("Unsupported mesh file format "+e.fileFormat,e),{scene:new a,animations:[]};const r=e.fileKey+(!0===t?.mergeGeomtries?"1":"0");if(!this.cache.has(r))try{this.asyncMeshResults.has(r)||this.asyncMeshResults.set(r,this.loadMesh(e).finally(()=>this.asyncMeshResults.delete(r))),this.cache.set(r,await this.asyncMeshResults.get(r))}catch(e){return this.onError(e),{scene:new a,animations:[]}}const s=this.cache.get(r).scene,n=this.computeCollisionShapes(e,s);!0===t?.mergeGeomtries&&this.optimizeDrawGroups(s);const o=p(s),l=this.cache.get(r).animations;o.traverse(e=>{e instanceof i&&e.material instanceof Array&&(e.material=e.material.slice())});const c=new AssetMeshInstance;c.add(o),c.collisionShapes=n,c.animations=l,c.userData.assetId=e.id;const h=e.mesh?.animationRigId??e.anim?.rigId;if(c.userData.animationRigId=h,o.userData.animationRigId=h,null!=h&&null!=this.animationRigProvider){const e=await this.animationRigProvider(h);c.userData.animationRig=e,o.userData.animationRig=e,null!=e&&!1!==t?.applyRigBasis&&c.quaternion.copy(W(e))}const u=e.receiveShadow??!1,m=e.castShadow??!1;if(o.traverse(e=>{e.castShadow=m,e.receiveShadow=u}),!0===t?.rescale&&"number"==typeof e.mesh?.rescale&&c.scale.setScalar(e.mesh?.rescale),!0===t?.applyMaterials){const r=t?.materialResolver??this.materialProvider;if(null!=r)for(const t of e.materialAssignments??[])await T(c,t,r,void 0,{textureFlipY:v(e)});else console.warn(`applyMaterials was set to true for ${e.name} but no material resolver was provided.`)}return{scene:c,animations:l}}async getAudio(e){await this.ready;const t=e.fileKey;if(this.asyncAudioResults.has(t))return await this.asyncAudioResults.get(t);const r=this.audioLoader.loadAsync(this.getUri(e.fileKey)).finally(()=>{setTimeout(()=>{this.asyncAudioResults.delete(t)},1e3)});return this.asyncAudioResults.set(t,r),r}async getAnimationClip(e){if(null==e||null==e.fileKey||null==e.anim?.clip)return console.warn("Asset or animation clip name is not defined",e),null;const t=e.anim.clip,r=e.fileKey+"|"+t;if(this._animationCache.has(r))return this._animationCache.get(r);if(this._animationPromises.has(r))return this._animationPromises.get(r);const a=(async()=>{try{const a=await this.getMesh(e),s=a.animations.find(e=>e.name===t);return null!=s&&(j(s,e.anim?.rigId),this._animationCache.set(r,s)),s}catch(e){return this.onError(e),null}finally{setTimeout(()=>this._animationPromises.delete(r),1e3)}})();return this._animationPromises.set(r,a),a}computeCollisionShapes(e,t){if(!0!==e.collisionDetection)return[];const r=e.id+"|"+(e.mesh?.collisions?.shapeType??"")+"|"+(e.mesh?.rescale??1)+"|"+JSON.stringify(e.mesh?.colliders??[]);if(!this.collisionShapeCache.has(r)){const a=e.mesh?.colliders??[],s=a.length>0?createAuthoredCollisionShapes(a,e.mesh?.rescale):b(t,e);this.collisionShapeCache.set(r,s)}return this.collisionShapeCache.get(r)}async loadMesh(e){return await this.ready,await this.loadByAsset(e).then(r=>(r.scene.traverse(e=>{e instanceof i&&e.material&&function(e){let t=e.material;if(null==t)return;Array.isArray(t)?e.material=t.map(Z):e.material=Z(t)}(e),_(e)?e.visible=!1:e instanceof i&&e.geometry instanceof t&&(e.geometry.hasAttribute("normal")||e.geometry.computeVertexNormals())}),this._retrievedMeshes.push(r.scene),r.scene=function(e,t){let r=!1;if(t.traverseVisible(e=>{J.test(e.name)&&(r=!0)}),!r)return t;const a=[],s=[t];for(;s.length>0;){const e=s.shift(),t=e.name.match(J);if(null!=t){const r=parseInt(t[1]);if(0!==r){console.warn(`Skipping LOD level ${r} for now as LOD is not fully supported`),a.push(e);continue}}s.push(...e.children)}for(const e of a)e.removeFromParent();return t}(0,r.scene),function(e){const t=q;q.length=0,e.traverse(e=>{(e instanceof S.Camera||e instanceof S.Light)&&t.push(e)}),t.forEach(e=>e.removeFromParent())}(r.scene),r.scene.userData.assetId=e.id,r))}optimizeDrawGroups(e){if(this.optimizedMeshes.has(e.uuid))return;this.optimizedMeshes.add(e.uuid),e.updateWorldMatrix(!0,!0);const r=[];e.traverse(e=>{e instanceof i&&!(e instanceof S.SkinnedMesh)&&e.geometry instanceof t&&Array.isArray(e.material)&&!_(e)&&r.push({mesh:e,geometry:e.geometry,materialArray:e.material,parent:e.parent})});for(const{mesh:t,geometry:a,materialArray:s,parent:n}of r){t.removeFromParent();for(let r=0;r<s.length;r++){const o=s[r],l=a.groups.filter(e=>e.materialIndex===r);if(0===l.length)continue;const c=this.extractGeometryGroups(a,l);c.groups.length>1&&C.mergeGroups(c);const h=new i(c,o);h.copy(t,!1),h.geometry=c,h.material=o,n?n.add(h):e.add(h)}a.dispose()}let a=!0,s=0,n=0;if(e.traverse(e=>{if(e instanceof i&&e.geometry instanceof t&&!_(e)){s++;const t=Object.keys(e.geometry.attributes).length;t!==n&&0!==n&&(a=!1),n=t}else(e instanceof S.SkinnedMesh||e instanceof S.Bone)&&(a=!1)}),s>1&&a){const r=new Map;e.traverse(a=>{if(a instanceof i&&a.geometry instanceof t&&!_(a)){if(Array.isArray(a.material))return;a.updateWorldMatrix(!0,!0);const t=a.material?.uuid||"default";r.has(t)||r.set(t,{material:a.material,geometries:[],objects:[]});const s=r.get(t),i=e.matrixWorld.clone().invert().multiply(a.matrixWorld);s.geometries.push(a.geometry.clone().applyMatrix4(i)),s.objects.push(a)}});for(const e of r.values())for(const t of e.objects)t.removeFromParent();for(const t of r.values()){let r;r=1===t.geometries.length?t.geometries[0]:C.mergeGeometries(t.geometries,!0),r.groups.length>1&&C.mergeGroups(r),e.add(new i(r,t.material))}}e.traverse(e=>{if(e instanceof i&&e.geometry instanceof t&&!_(e)){const t=e.geometry;!Array.isArray(e.material)&&t.groups.length>1&&C.mergeGroups(t)}})}extractGeometryGroups(e,r){const a=e.index;if(!a){const a=new t;let s=0;for(const e of r)s+=e.count;if(0===s)return a;for(const t in e.attributes){const i=e.attributes[t],n=i.itemSize,o=i.array,l=new(0,o.constructor)(s*n);let c=0;for(const e of r){const t=e.start*n,r=e.count*n;for(let e=0;e<r;e++)l[c+e]=o[t+e];c+=r}const h=new S.BufferAttribute(l,n,i.normalized);a.setAttribute(t,h)}return a.groups=[{start:0,count:s,materialIndex:0}],a}const s=[];for(const e of r)for(let t=0;t<e.count;t++){const r=a.getX(e.start+t);s.push(r)}if(0===s.length)return new t;const i=new Map,n=[];let o=0;for(const e of s)i.has(e)||(i.set(e,o),o++),n.push(i.get(e));if(0===n.length||0===i.size)return new t;const l=new t;for(const t in e.attributes){const r=e.attributes[t],a=r.itemSize,s=r.array,n=new(0,s.constructor)(i.size*a);for(const[e,t]of i)for(let r=0;r<a;r++)n[t*a+r]=s[e*a+r];const o=new S.BufferAttribute(n,a,r.normalized);l.setAttribute(t,o)}const c=new((n.length>0?Math.max(...n):0)>65535?Uint32Array:Uint16Array)(n.length);for(let e=0;e<n.length;e++)c[e]=n[e];return l.setIndex(new S.BufferAttribute(c,1)),l.groups=[{start:0,count:n.length,materialIndex:0}],l}async loadByAsset(e){this.fbxLoader;const t=this.getUri(e.fileKey);switch(e.fileFormat){case"glb":case"gltf":return this.glbLoader.loadAsync(t).then(e=>({scene:e.scene,animations:e.animations}));case"fbx":return this.fbxLoader.loadAsync(t).then(e=>({scene:e,animations:e.animations}));case"obj":if(null!=e.materialLib){const t=new h;t.materialOptions={normalizeRGB:!1};const r=await t.loadAsync(this.getUri(e.materialLib));this.objLoader.setMaterials(r)}return this.objLoader.loadAsync(t).then(e=>($(e),e)).then(e=>({scene:e,animations:e.animations}))}}disposeAll(){this.cache.clear(),this._retrievedMeshes.forEach(e=>F(e)),this._retrievedTextures.forEach(e=>e.dispose()),this._retrievedMeshes.length=0,this._retrievedTextures.length=0}}const G=new Map;function z(e){G.set(e,(G.get(e)??0)+1)}function $(e){if(e instanceof i)for(const t of L(e.material))t instanceof S.MeshPhongMaterial&&!t.color.isLinear&&(t.color.isLinear=!0);e.children?.forEach($)}export class AssetMeshInstance extends n{}export function createAuthoredCollisionShapes(e,t=1){const a=null!=t&&0!==t?1/t:1;return e.map(e=>{let t;switch(e.type){case"box":t=new g((new c).fromArray(e.size).multiplyScalar(a));break;case"sphere":t=new A(e.radius*a);break;case"capsule":t=new w(e.length*a,e.radius*a);break;case"cylinder":t=new M(e.radius*a,e.radius*a,e.height*a,16,new r)}return t.source=x.custom,t.offset.fromArray(e.position??[0,0,0]).multiplyScalar(a),t.rotation.fromArray(e.rotation??[0,0,0,"XYZ"]),t})}export function getElectronArg(e){const t=`--${e}=`,r=window.process?.argv.find(e=>e.startsWith(t));return r?.substring(t.length)}function Y(e){switch(e){case"clamp":return S.ClampToEdgeWrapping;case"repeat":return S.RepeatWrapping;case"mirror":return S.MirroredRepeatWrapping}return S.RepeatWrapping}function O(e,t){const r=e;return!0!==r.isCompressedTexture&&!0!==r.isCompressedArrayTexture&&(t.texture?.flipY??!0)}function N(e){return e.texture?.colorSpace??function(e){if("exr"===e.fileFormat||e.fileKey?.toLowerCase().endsWith(".exr"))return"linear";const t=`${e.name} ${e.fileKey??""}`.toLowerCase();if(X.some(e=>t.includes(e)))return"linear";return"srgb"}(e)}function V(e){return"linear"===e?S.LinearSRGBColorSpace:S.SRGBColorSpace}const X=["_normal","_nrm","_nor","_norm","_roughness","_rough","_metalness","_metallic","_metal","_ao","_ambient","_occlusion","_mask","_height","_disp","_displacement","_bump","_opacity"];new S.Matrix4;const q=[];const J=/_LOD(\d+)/;function Z(e){let t=e instanceof S.MeshPhysicalMaterial&&0===e.sheen&&0===e.anisotropy;if("MeshLambertMaterial"===e.type||"MeshPhongMaterial"===e.type||t){let t={};(e instanceof S.MeshLambertMaterial||e instanceof S.MeshPhongMaterial||e instanceof S.MeshPhysicalMaterial)&&(t.color=e.color,t.map=e.map,t.bumpMap=e.bumpMap,t.bumpScale=e.bumpScale,t.lightMap=e.lightMap,t.lightMapIntensity=e.lightMapIntensity,t.aoMap=e.aoMap,t.aoMapIntensity=e.aoMapIntensity,t.emissiveMap=e.emissiveMap,t.alphaMap=e.alphaMap,t.envMap=e.envMap,t.envMapRotation=e.envMapRotation,t.wireframe=e.wireframe,t.wireframeLinewidth=e.wireframeLinewidth,t.fog=e.fog,t.opacity=e.opacity,t.transparent=e.transparent,t.side=e.side,t.depthTest=e.depthTest,t.depthWrite=e.depthWrite,t.alphaTest=e.alphaTest,t.displacementMap=e.displacementMap,t.displacementScale=e.displacementScale,t.displacementBias=e.displacementBias);const r=new S.MeshStandardMaterial(t);return r.userData={...e.userData??{}},r.name=e.name,r}return e}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Color as e,Euler as a,Vector2 as r,Vector3 as u,Vector4 as t}from"three";import{getParameterDefinitionType as l,isParameterDefinitionAbstract as n}from"../shader/parameter.js";import{Curve2 as s}from"../utils/curve.js";import{
|
|
1
|
+
import{Color as e,Euler as a,Vector2 as r,Vector3 as u,Vector4 as t}from"three";import{getParameterDefinitionType as l,isParameterDefinitionAbstract as n}from"../shader/parameter.js";import{Curve2 as s}from"../utils/curve.js";import{isSequenceData as c,Sequence as o}from"../effects/sequence/sequence-data.js";import{SerializedParamType as v}from"./model.js";export function customParamValueNeedsAsyncResolution(e){if(null==e||null==e.value||""===e.value)return!1;if(i(e))return e.value.some(a=>customParamValueNeedsAsyncResolution(f(e,a)));switch(e.type){case v.Texture:case v.Sampler2DNode:case v.Object3D:case v.Material:case v.AudioBuffer:case v.VisualEffect:case v.Prefab:case v.PrefabActor:case v.DataAsset:case v.AnimationClip:return!0;case v.Sequence:return!c(e.value);case v.SequenceData:return!1;case v.Struct:return Object.values(y(e.value)).some(e=>customParamValueNeedsAsyncResolution(e));default:return!1}}export function deserializeCustomParamValueSync(l,n={}){if(null==l||null==l.value||""===l.value)return l?.value??null;switch(l.type){case v.Array:return i(l)&&Array.isArray(l.value)?l.value.map(e=>deserializeCustomParamValueSync(f(l,e),n)):[];case v.Number:case v.FloatNode:return"string"==typeof l.value?parseFloat(l.value):l.value;case v.Boolean:case v.BooleanNode:case v.String:return l.value;case v.Vector2:case v.Vec2Node:return"object"==typeof l.value?Array.isArray(l.value)?(new r).fromArray(l.value):new r(l.value.x,l.value.y):null;case v.Vector3:case v.Vec3Node:return"object"==typeof l.value?Array.isArray(l.value)?(new u).fromArray(l.value):new u(l.value.x,l.value.y,l.value.z):null;case v.Vector4:case v.Vec4Node:return"object"==typeof l.value?Array.isArray(l.value)?(new t).fromArray(l.value):new t(l.value.x,l.value.y,l.value.z,l.value.w):null;case v.Color:case v.RgbNode:return new e(l.value);case v.Euler:return Array.isArray(l.value)?(new a).fromArray(l.value):l.value;case v.BaseActor:return n.actor?.(l.value)??l.value;case v.Sequence:return c(l.value)?new o(l.value):l.value;case v.SequenceData:return c(l.value)?l.value:null;case v.Curve:return s.decode(l.value);case v.Struct:return function(e,a){const r=A(e.value),u=m(r?.struct??e.struct);for(const[t,l]of Object.entries(r?.value??y(e.value)))u[t]=deserializeCustomParamValueSync(l,a);return u}(l,n);default:return l.value}}export async function deserializeCustomParamValue(e,a={}){if(null==e||null==e.value||""===e.value)return e?.value??null;if(!customParamValueNeedsAsyncResolution(e))return deserializeCustomParamValueSync(e,a);switch(e.type){case v.Array:return i(e)&&Array.isArray(e.value)?Promise.all(e.value.map(r=>deserializeCustomParamValue(f(e,r),a))):[];case v.Texture:return a.texture?.(e.value)??null;case v.Sampler2DNode:return a.sampler2DNode?.(e.value)??null;case v.Object3D:return a.object3D?.(e.value)??null;case v.Material:return a.material?.(e.value)??null;case v.AudioBuffer:return a.audioBuffer?.(e.value)??null;case v.VisualEffect:return a.visualEffect?.(e.value)??null;case v.Prefab:return a.prefab?.(e.value)??null;case v.PrefabActor:return a.prefabActor?.(e.value)??null;case v.DataAsset:return a.dataAsset?.(e.value)??null;case v.Sequence:return c(e.value)?new o(e.value):a.sequence?.(e.value)??null;case v.SequenceData:return c(e.value)?e.value:null;case v.AnimationClip:return a.animationClip?.(e.value)??null;case v.Struct:return async function(e,a){const r=A(e.value),u=m(r?.struct??e.struct);for(const[t,l]of Object.entries(r?.value??y(e.value)))u[t]=await deserializeCustomParamValue(l,a);return u}(e,a);default:return deserializeCustomParamValueSync(e,a)}}function i(e){return e.type===v.Array}function f(e,a){const r=A(a);return{type:e.element,...null!=r?.struct||null!=e.elementStruct?{struct:r?.struct??e.elementStruct}:{},value:r?.value??a}}function m(e){const a=null!=e?l(e):void 0;if(null==a||n(e))return{};try{return new a}catch{return{}}}function y(e){const a=A(e);return null!=a?a.value:p(e)?e:null!=e&&"object"==typeof e&&p(e.params)?e.params:{}}function A(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)&&"string"==typeof e.struct&&p(e.value)?e:null}function p(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)&&Object.values(e).every(e=>null!=e&&"object"==typeof e&&"type"in e)}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Color as e,Euler as r,Material as t,Object3D as n,Texture as u,Vector2 as o,Vector3 as a,Vector4 as c,AnimationClip as l}from"three";import{BooleanNode as i,FloatNode as s,RgbNode as f,Sampler2DNode as y,Texture2dLookupNode as p,Vec2Node as m,Vec3Node as d,Vec4Node as b}from"three-shader-graph";import{getParameterDefinitionId as A,getParameterDefinitionType as g,isParameterDefinitionStructAssignableTo as S}from"../shader/parameter.js";import{Curve2 as N}from"../utils/curve.js";import{SerializedParamType as V}from"./model.js";export const applyRuntimeParamTypeInference=!0;export function convertConfiguredParamsToRuntimeTypes(e,r={}){const t={},n=[],u=Object.entries(e),o=r.applyRuntimeParamTypeInference??true;if(0===u.length||!o)return o?{params:t,skipped:n}:{params:e,skipped:n};const a=getRuntimeParameterTypeHints(e,r);for(const[e,r]of u){if(!1===r.override){t[e]=r;continue}const u=a.get(e),o=null!=u?convertConfiguredParamValueToRuntimeType(r,u):r;null!=o?t[e]=o:n.push({key:e,sourceType:r.type,targetType:u.type})}return{params:t,skipped:n}}export function getRuntimeParameterTypeHints(e,r={}){const t=new Map,n=Object.keys(e).filter(r=>!1!==e[r]?.override);if(0===n.length)return t;const u=new Set(n),o=r.parameterTarget??function(e){if(null==e)return null;try{return new e}catch{return null}}(r.parameterType),a=function(e,r){if(null!=r.propertyParams)return r.propertyParams;if(null==r.extractPropertyParameters)return[];if(null!=r.parameterType)return h(r.parameterType,r.extractPropertyParameters);if(null!=e)return h(e.constructor,r.extractPropertyParameters);return[]}(o,r);for(const e of a){if(!u.has(e.name))continue;const n=R(e,r.toSerializedParamType);null!=n&&t.set(e.name,n);const a=inferRuntimeSerializedParamTypeHint(C(o,e.name))??inferRuntimeSerializedParamTypeHint(e.options.defaultValue);null!=a&&t.set(e.name,x(a,n))}if(null!=o)for(const e of n){const r=inferRuntimeSerializedParamTypeHint(C(o,e));if(null!=r){const n=t.get(e);t.set(e,x(r,n))}}return t}const v=new WeakMap,P=new WeakMap,T=Symbol("noCachedSerializedParamType");function h(e,r){let t=v.get(r);null==t&&(t=new WeakMap,v.set(r,t));const n=t.get(e);if(null!=n)return n;const u=function(e,r){try{return r(e)}catch{return[]}}(e,r);return t.set(e,u),u}function C(e,r){return null!=e?e[r]:void 0}function R(e,r){const t=function(e,r){if(null==e||null==r)return;const t=function(e,r){const t=P.get(r);if(null==t||!t.has(e))return T;const n=t.get(e);return null===n?void 0:n}(e,r);if(t!==T)return t;try{const t=r(e);return w(e,r,t),t}catch{return void w(e,r,void 0)}}(e.type,r),n=t===V.Struct?A(e.type):void 0;return!0===e.options.array?{type:V.Array,...null!=t?{element:t}:{},...null!=n?{elementStruct:n}:{}}:null!=t?{type:t,...null!=n?{struct:n}:{}}:void 0}function w(e,r,t){let n=P.get(r);null==n&&(n=new WeakMap,P.set(r,n)),n.set(e,t??null)}function x(e,r){return e.type!==V.Array?e:{type:V.Array,element:e.element??r?.element,elementStruct:e.elementStruct??r?.elementStruct}}export function inferRuntimeSerializedParamTypeHint(g){if(null==g)return;if(Array.isArray(g)){const e=g.map(e=>inferRuntimeSerializedParamTypeHint(e)).find(e=>null!=e);return{type:V.Array,...null!=e&&e.type!==V.Array?{element:e.type}:{},...null!=e?.struct?{elementStruct:e.struct}:{}}}switch(typeof g){case"number":return{type:V.Number};case"boolean":return{type:V.Boolean};case"string":return{type:V.String}}const S=function(e){const r=e;if(e instanceof s||"function"==typeof r?.isFloat||!0===r?.isFloat)return V.FloatNode;if(e instanceof i||"function"==typeof r?.isBool||!0===r?.isBool)return V.BooleanNode;if(e instanceof f||"function"==typeof r?.isRgb||!0===r?.isRgb)return V.RgbNode;if(e instanceof m||"function"==typeof r?.isVec2||!0===r?.isVec2)return V.Vec2Node;if(e instanceof d||"function"==typeof r?.isVec3||!0===r?.isVec3)return V.Vec3Node;if(e instanceof b||"function"==typeof r?.isVec4||!0===r?.isVec4)return V.Vec4Node;if(e instanceof y||e instanceof p||"function"==typeof r?.isSampler2D||!0===r?.isSampler2D)return V.Sampler2DNode;return}(g);if(null!=S)return{type:S};if(g instanceof o)return{type:V.Vector2};if(g instanceof a)return{type:V.Vector3};if(g instanceof c)return{type:V.Vector4};if(g instanceof e)return{type:V.Color};if(g instanceof r)return{type:V.Euler};if(g instanceof u)return{type:V.Texture};if(g instanceof t)return{type:V.Material};if(g instanceof n)return{type:V.Object3D};if("undefined"!=typeof AudioBuffer&&g instanceof AudioBuffer)return{type:V.AudioBuffer};if(W(g,"VisualEffect"))return{type:V.VisualEffect};if(W(g,"PrefabOf"))return{type:V.PrefabActor};if(W(g,"Prefab"))return{type:V.Prefab};if(W(g,"DataAssetRef"))return{type:V.DataAsset};if(g instanceof N)return{type:V.Curve};if(W(g,"ColorLayer"))return{type:V.ColorLayer};if(W(g,"MaskLayer"))return{type:V.MaskLayer};if(g instanceof l)return{type:V.AnimationClip};if(W(g,"Sequence"))return{type:V.Sequence};const v=A(g.constructor);return null!=v?{type:V.Struct,struct:v}:void 0}export function convertConfiguredParamValueToRuntimeType(e,r){if(null==e||null==r)return e;if(e.type===V.Array||r.type===V.Array)return function(e,r){if(r.type===V.Array){const t=B(e),n=r.element??(t?e.element:e.type);if(null==n)return t?e:null;const u=t?e.element:e.type,o=(t?Array.isArray(e.value)?e.value:[]:[e.value]).map(e=>F(e,u,n));return o.some(e=>e===D)?null:{...e,type:V.Array,element:n,...k(e,r),value:o}}if(!B(e))return null;const t=Array.isArray(e.value)?e.value[0]:void 0;if(null==t)return null;const n=F(t,e.element,r.type);if(n===D)return null;return{...e,type:r.type,...j(e,r),value:n}}(e,r);const t=F(e.value,e.type,r.type);return t===D?null:{...e,type:r.type,...j(e,r),value:t}}function B(e){return e.type===V.Array}function j(e,r){if(r.type!==V.Struct&&e.type!==V.Struct)return{};const t=function(e,r){if(null==r)return e;if(null==e)return r;if(e===r||S(e,r))return e;const t=g(e),n=g(r);if(null==t||null==n)return e;return r}(e.type===V.Struct?e.struct:void 0,r.struct);return null!=t?{struct:t}:{}}function k(e,r){if(r.type!==V.Array)return{};const t=B(e)?e.elementStruct:void 0,n=r.elementStruct??t;return null!=n?{elementStruct:n}:{}}const D=Symbol("skippedParamValue");function F(e,r,t){if(function(e,r){if(e===r)return!0;const t=z(e);return null!=t&&t===z(r)}(r,t)&&function(e,r){switch(r){case V.Number:return"number"==typeof e||"string"==typeof e&&Number.isFinite(parseFloat(e));case V.FloatNode:return"number"==typeof e||"string"==typeof e&&Number.isFinite(parseFloat(e))||function(e){if(null==e||"object"!=typeof e||Array.isArray(e))return!1;const r=e;return"particle"===r.time&&"string"==typeof r.easing&&null!=L(r.a)&&null!=L(r.b)}(e);case V.Boolean:case V.BooleanNode:return"boolean"==typeof e;case V.Vector2:case V.Vec2Node:return M(e,2);case V.Vector3:case V.Vec3Node:return M(e,3);case V.Vector4:case V.Vec4Node:return M(e,4);case V.Euler:return Array.isArray(e)&&e.length>=3&&null!=E(e,3);case V.Color:case V.RgbNode:return null!=q(e);case V.String:return"string"==typeof e;case V.Array:return Array.isArray(e);case V.Texture:case V.Sampler2DNode:case V.BaseActor:case V.Object3D:case V.Material:case V.AudioBuffer:case V.VisualEffect:case V.Prefab:case V.PrefabActor:case V.DataAsset:case V.AnimationClip:case V.Sequence:return null==e||"string"==typeof e||"object"==typeof e;case V.Struct:return null!=e&&"object"==typeof e&&!Array.isArray(e);case V.Curve:case V.ColorLayer:case V.MaskLayer:return null!=e}return!0}(e,t))return e;switch(t){case V.Number:case V.FloatNode:{const r=L(e);return null!=r?r:D}case V.Boolean:case V.BooleanNode:{const r=function(e){if("boolean"==typeof e)return e;if("number"==typeof e)return 0!==e;if("string"==typeof e){const r=e.trim().toLowerCase();if(["true","1","yes","on"].includes(r))return!0;if(["false","0","no","off"].includes(r))return!1}return null}(e);return null!=r?r:D}case V.Vector2:case V.Vec2Node:return H(e,2,r)??D;case V.Vector3:case V.Vec3Node:return H(e,3,r)??D;case V.Vector4:case V.Vec4Node:return H(e,4,r)??D;case V.Color:case V.RgbNode:return function(e,r){if(r===V.Color||r===V.RgbNode)return"string"==typeof e||"number"==typeof e?e:O(e);return O(e)}(e,r)??D;case V.Euler:return function(e,r){if(Array.isArray(e)){const r=E(e,3);if(null==r)return null;const t="string"==typeof e[3]?e[3]:"XYZ";return[r[0],r[1],r[2],t]}const t=H(e,3,r);return null!=t?[t[0],t[1],t[2],"XYZ"]:null}(e,r)??D;case V.String:return"string"==typeof e?e:String(e);case V.Texture:case V.Sampler2DNode:case V.BaseActor:case V.Object3D:case V.Material:case V.AudioBuffer:case V.VisualEffect:case V.Curve:case V.ColorLayer:case V.MaskLayer:case V.Prefab:case V.PrefabActor:case V.DataAsset:case V.AnimationClip:case V.Sequence:case V.Struct:return D}return D}function M(e,r){if(Array.isArray(e))return e.length>=r&&null!=E(e,r);if(null!=e&&"object"==typeof e){const t=e;return["x","y","z","w"].slice(0,r).every(e=>null!=L(t[e]))}return!1}function z(e){switch(e){case V.Number:case V.FloatNode:return"number";case V.Boolean:case V.BooleanNode:return"boolean";case V.Vector2:case V.Vec2Node:return"vector2";case V.Vector3:case V.Vec3Node:return"vector3";case V.Vector4:case V.Vec4Node:return"vector4";case V.Color:case V.RgbNode:return"color";case V.Texture:case V.Sampler2DNode:return"texture";case V.Prefab:case V.PrefabActor:return"prefab";case V.DataAsset:return"dataAsset";case V.Struct:return"struct"}}function L(e){if("number"==typeof e)return Number.isFinite(e)?e:null;if("string"==typeof e){const r=parseFloat(e);return Number.isFinite(r)?r:null}if("boolean"==typeof e)return e?1:0;if(Array.isArray(e))return L(e[0]);if(null!=e&&"object"==typeof e){const r=e;return L(r.x??r.r??r.value)}return null}function H(e,r,t){if(t===V.Color||t===V.RgbNode){const t=q(e);if(null!=t)return E(t.toArray(),r,4===r?1:0)}if(Array.isArray(e))return E(e,r);if("number"==typeof e||"string"==typeof e||"boolean"==typeof e){const t=L(e);return null!=t?new Array(r).fill(t):null}if(null!=e&&"object"==typeof e){const t=e,n=["x","y","z","w"].slice(0,r).map(e=>t[e]);if(n.some(e=>null!=e))return E(n,r);const u=["r","g","b","a"].slice(0,r).map(e=>t[e]);if(u.some(e=>null!=e))return E(u,r,4===r?1:0)}return null}function E(e,r,t=0){const n=[];for(let u=0;u<r;u++){const r=L(e[u]??t);if(null==r)return null;n.push(r)}return n}function O(e){const r=q(e);return null!=r?"#"+r.getHexString():null}function q(r){try{if(r instanceof e)return r.clone();if("string"==typeof r)return function(e){return/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e.trim())||/^(rgb|hsl)a?\(/i.test(e.trim())}(r)?new e(r):null;if("number"==typeof r)return Number.isInteger(r)&&r>=0?new e(r):null;if(Array.isArray(r)){const t=E(r,3);return null!=t?(new e).fromArray(t):null}if(null!=r&&"object"==typeof r){const t=r;if(null!=t.r||null!=t.g||null!=t.b){const r=E([t.r,t.g,t.b],3);return null!=r?(new e).fromArray(r):null}if(null!=t.x||null!=t.y||null!=t.z){const r=E([t.x,t.y,t.z],3);return null!=r?(new e).fromArray(r):null}}}catch{return null}return null}function W(e,r){return null!=e&&"object"==typeof e&&e.constructor?.name===r}/*
|
|
1
|
+
import{Color as e,Euler as r,Material as t,Object3D as n,Texture as u,Vector2 as o,Vector3 as a,Vector4 as c,AnimationClip as l}from"three";import{BooleanNode as i,FloatNode as s,RgbNode as f,Sampler2DNode as y,Texture2dLookupNode as p,Vec2Node as m,Vec3Node as d,Vec4Node as b}from"three-shader-graph";import{getParameterDefinitionId as A,getParameterDefinitionType as g,isParameterDefinitionStructAssignableTo as S}from"../shader/parameter.js";import{Curve2 as N}from"../utils/curve.js";import{isSequenceData as V}from"../effects/sequence/sequence-data.js";import{SerializedParamType as v}from"./model.js";export const applyRuntimeParamTypeInference=!0;export function convertConfiguredParamsToRuntimeTypes(e,r={}){const t={},n=[],u=Object.entries(e),o=r.applyRuntimeParamTypeInference??true;if(0===u.length||!o)return o?{params:t,skipped:n}:{params:e,skipped:n};const a=getRuntimeParameterTypeHints(e,r);for(const[e,r]of u){const u=a.get(e),o=P(r,u);if(null==o)continue;if(!1===o.override){t[e]=o;continue}const c=null!=u?convertConfiguredParamValueToRuntimeType(o,u):o;null!=c?t[e]=c:n.push({key:e,sourceType:o.type,targetType:u.type})}return{params:t,skipped:n}}function P(e,r){return function(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)&&"number"==typeof e.type&&"value"in e}(e)?e:r?.type===v.SequenceData&&V(e)?{type:v.SequenceData,value:e}:null}export function getRuntimeParameterTypeHints(e,r={}){const t=new Map,n=Object.keys(e).filter(r=>!1!==e[r]?.override);if(0===n.length)return t;const u=new Set(n),o=r.parameterTarget??function(e){if(null==e)return null;try{return new e}catch{return null}}(r.parameterType),a=function(e,r){if(null!=r.propertyParams)return r.propertyParams;if(null==r.extractPropertyParameters)return[];if(null!=r.parameterType)return R(r.parameterType,r.extractPropertyParameters);if(null!=e)return R(e.constructor,r.extractPropertyParameters);return[]}(o,r);for(const e of a){if(!u.has(e.name))continue;const n=D(e,r.toSerializedParamType);null!=n&&t.set(e.name,n);const a=inferRuntimeSerializedParamTypeHint(w(o,e.name))??inferRuntimeSerializedParamTypeHint(e.options.defaultValue);null!=a&&t.set(e.name,j(a,n))}if(null!=o)for(const e of n){const r=inferRuntimeSerializedParamTypeHint(w(o,e));if(null!=r){const n=t.get(e);t.set(e,j(r,n))}}return t}const T=new WeakMap,h=new WeakMap,C=Symbol("noCachedSerializedParamType");function R(e,r){let t=T.get(r);null==t&&(t=new WeakMap,T.set(r,t));const n=t.get(e);if(null!=n)return n;const u=function(e,r){try{return r(e)}catch{return[]}}(e,r);return t.set(e,u),u}function w(e,r){return null!=e?e[r]:void 0}function D(e,r){const t=function(e,r){if(null==e||null==r)return;const t=function(e,r){const t=h.get(r);if(null==t||!t.has(e))return C;const n=t.get(e);return null===n?void 0:n}(e,r);if(t!==C)return t;try{const t=r(e);return x(e,r,t),t}catch{return void x(e,r,void 0)}}(e.type,r),n=t===v.Struct?A(e.type):void 0;return!0===e.options.array?{type:v.Array,...null!=t?{element:t}:{},...null!=n?{elementStruct:n}:{}}:null!=t?{type:t,...null!=n?{struct:n}:{}}:void 0}function x(e,r,t){let n=h.get(r);null==n&&(n=new WeakMap,h.set(r,n)),n.set(e,t??null)}function j(e,r){return e.type!==v.Array?e:{type:v.Array,element:e.element??r?.element,elementStruct:e.elementStruct??r?.elementStruct}}export function inferRuntimeSerializedParamTypeHint(g){if(null==g)return;if(Array.isArray(g)){const e=g.map(e=>inferRuntimeSerializedParamTypeHint(e)).find(e=>null!=e);return{type:v.Array,...null!=e&&e.type!==v.Array?{element:e.type}:{},...null!=e?.struct?{elementStruct:e.struct}:{}}}switch(typeof g){case"number":return{type:v.Number};case"boolean":return{type:v.Boolean};case"string":return{type:v.String}}const S=function(e){const r=e;if(e instanceof s||"function"==typeof r?.isFloat||!0===r?.isFloat)return v.FloatNode;if(e instanceof i||"function"==typeof r?.isBool||!0===r?.isBool)return v.BooleanNode;if(e instanceof f||"function"==typeof r?.isRgb||!0===r?.isRgb)return v.RgbNode;if(e instanceof m||"function"==typeof r?.isVec2||!0===r?.isVec2)return v.Vec2Node;if(e instanceof d||"function"==typeof r?.isVec3||!0===r?.isVec3)return v.Vec3Node;if(e instanceof b||"function"==typeof r?.isVec4||!0===r?.isVec4)return v.Vec4Node;if(e instanceof y||e instanceof p||"function"==typeof r?.isSampler2D||!0===r?.isSampler2D)return v.Sampler2DNode;return}(g);if(null!=S)return{type:S};if(g instanceof o)return{type:v.Vector2};if(g instanceof a)return{type:v.Vector3};if(g instanceof c)return{type:v.Vector4};if(g instanceof e)return{type:v.Color};if(g instanceof r)return{type:v.Euler};if(g instanceof u)return{type:v.Texture};if(g instanceof t)return{type:v.Material};if(g instanceof n)return{type:v.Object3D};if("undefined"!=typeof AudioBuffer&&g instanceof AudioBuffer)return{type:v.AudioBuffer};if(X(g,"VisualEffect"))return{type:v.VisualEffect};if(X(g,"PrefabOf"))return{type:v.PrefabActor};if(X(g,"Prefab"))return{type:v.Prefab};if(X(g,"DataAssetRef"))return{type:v.DataAsset};if(g instanceof N)return{type:v.Curve};if(X(g,"ColorLayer"))return{type:v.ColorLayer};if(X(g,"MaskLayer"))return{type:v.MaskLayer};if(g instanceof l)return{type:v.AnimationClip};if(X(g,"Sequence"))return{type:v.Sequence};if(V(g))return{type:v.SequenceData};const P=A(g.constructor);return null!=P?{type:v.Struct,struct:P}:void 0}export function convertConfiguredParamValueToRuntimeType(e,r){if(null==e||null==r)return e;if(e.type===v.Array||r.type===v.Array)return function(e,r){if(r.type===v.Array){const t=B(e),n=r.element??(t?e.element:e.type);if(null==n)return t?e:null;const u=t?e.element:e.type,o=(t?Array.isArray(e.value)?e.value:[]:[e.value]).map(e=>M(e,u,n));return o.some(e=>e===q)?null:{...e,type:v.Array,element:n,...F(e,r),value:o}}if(!B(e))return null;const t=Array.isArray(e.value)?e.value[0]:void 0;if(null==t)return null;const n=M(t,e.element,r.type);if(n===q)return null;return{...e,type:r.type,...k(e,r),value:n}}(e,r);const t=M(e.value,e.type,r.type);return t===q?null:{...e,type:r.type,...k(e,r),value:t}}function B(e){return e.type===v.Array}function k(e,r){if(r.type!==v.Struct&&e.type!==v.Struct)return{};const t=function(e,r){if(null==r)return e;if(null==e)return r;if(e===r||S(e,r))return e;const t=g(e),n=g(r);if(null==t||null==n)return e;return r}(e.type===v.Struct?e.struct:void 0,r.struct);return null!=t?{struct:t}:{}}function F(e,r){if(r.type!==v.Array)return{};const t=B(e)?e.elementStruct:void 0,n=r.elementStruct??t;return null!=n?{elementStruct:n}:{}}const q=Symbol("skippedParamValue");function M(e,r,t){if(function(e,r){if(e===r)return!0;const t=L(e);return null!=t&&t===L(r)}(r,t)&&function(e,r){switch(r){case v.Number:return"number"==typeof e||"string"==typeof e&&Number.isFinite(parseFloat(e));case v.FloatNode:return"number"==typeof e||"string"==typeof e&&Number.isFinite(parseFloat(e))||function(e){if(null==e||"object"!=typeof e||Array.isArray(e))return!1;const r=e;return"particle"===r.time&&"string"==typeof r.easing&&null!=H(r.a)&&null!=H(r.b)}(e);case v.Boolean:case v.BooleanNode:return"boolean"==typeof e;case v.Vector2:case v.Vec2Node:return z(e,2);case v.Vector3:case v.Vec3Node:return z(e,3);case v.Vector4:case v.Vec4Node:return z(e,4);case v.Euler:return Array.isArray(e)&&e.length>=3&&null!=O(e,3);case v.Color:case v.RgbNode:return null!=I(e);case v.String:return"string"==typeof e;case v.Array:return Array.isArray(e);case v.Texture:case v.Sampler2DNode:case v.BaseActor:case v.Object3D:case v.Material:case v.AudioBuffer:case v.VisualEffect:case v.Prefab:case v.PrefabActor:case v.DataAsset:case v.AnimationClip:case v.Sequence:return null==e||"string"==typeof e||"object"==typeof e;case v.SequenceData:return null==e||V(e);case v.Struct:return null!=e&&"object"==typeof e&&!Array.isArray(e);case v.Curve:case v.ColorLayer:case v.MaskLayer:return null!=e}return!0}(e,t))return e;switch(t){case v.Number:case v.FloatNode:{const r=H(e);return null!=r?r:q}case v.Boolean:case v.BooleanNode:{const r=function(e){if("boolean"==typeof e)return e;if("number"==typeof e)return 0!==e;if("string"==typeof e){const r=e.trim().toLowerCase();if(["true","1","yes","on"].includes(r))return!0;if(["false","0","no","off"].includes(r))return!1}return null}(e);return null!=r?r:q}case v.Vector2:case v.Vec2Node:return E(e,2,r)??q;case v.Vector3:case v.Vec3Node:return E(e,3,r)??q;case v.Vector4:case v.Vec4Node:return E(e,4,r)??q;case v.Color:case v.RgbNode:return function(e,r){if(r===v.Color||r===v.RgbNode)return"string"==typeof e||"number"==typeof e?e:W(e);return W(e)}(e,r)??q;case v.Euler:return function(e,r){if(Array.isArray(e)){const r=O(e,3);if(null==r)return null;const t="string"==typeof e[3]?e[3]:"XYZ";return[r[0],r[1],r[2],t]}const t=E(e,3,r);return null!=t?[t[0],t[1],t[2],"XYZ"]:null}(e,r)??q;case v.String:return"string"==typeof e?e:String(e);case v.Texture:case v.Sampler2DNode:case v.BaseActor:case v.Object3D:case v.Material:case v.AudioBuffer:case v.VisualEffect:case v.Curve:case v.ColorLayer:case v.MaskLayer:case v.Prefab:case v.PrefabActor:case v.DataAsset:case v.AnimationClip:case v.Sequence:case v.SequenceData:case v.Struct:return t===v.SequenceData&&V(e)?e:q}return q}function z(e,r){if(Array.isArray(e))return e.length>=r&&null!=O(e,r);if(null!=e&&"object"==typeof e){const t=e;return["x","y","z","w"].slice(0,r).every(e=>null!=H(t[e]))}return!1}function L(e){switch(e){case v.Number:case v.FloatNode:return"number";case v.Boolean:case v.BooleanNode:return"boolean";case v.Vector2:case v.Vec2Node:return"vector2";case v.Vector3:case v.Vec3Node:return"vector3";case v.Vector4:case v.Vec4Node:return"vector4";case v.Color:case v.RgbNode:return"color";case v.Texture:case v.Sampler2DNode:return"texture";case v.Prefab:case v.PrefabActor:return"prefab";case v.DataAsset:return"dataAsset";case v.Struct:return"struct"}}function H(e){if("number"==typeof e)return Number.isFinite(e)?e:null;if("string"==typeof e){const r=parseFloat(e);return Number.isFinite(r)?r:null}if("boolean"==typeof e)return e?1:0;if(Array.isArray(e))return H(e[0]);if(null!=e&&"object"==typeof e){const r=e;return H(r.x??r.r??r.value)}return null}function E(e,r,t){if(t===v.Color||t===v.RgbNode){const t=I(e);if(null!=t)return O(t.toArray(),r,4===r?1:0)}if(Array.isArray(e))return O(e,r);if("number"==typeof e||"string"==typeof e||"boolean"==typeof e){const t=H(e);return null!=t?new Array(r).fill(t):null}if(null!=e&&"object"==typeof e){const t=e,n=["x","y","z","w"].slice(0,r).map(e=>t[e]);if(n.some(e=>null!=e))return O(n,r);const u=["r","g","b","a"].slice(0,r).map(e=>t[e]);if(u.some(e=>null!=e))return O(u,r,4===r?1:0)}return null}function O(e,r,t=0){const n=[];for(let u=0;u<r;u++){const r=H(e[u]??t);if(null==r)return null;n.push(r)}return n}function W(e){const r=I(e);return null!=r?"#"+r.getHexString():null}function I(r){try{if(r instanceof e)return r.clone();if("string"==typeof r)return function(e){return/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e.trim())||/^(rgb|hsl)a?\(/i.test(e.trim())}(r)?new e(r):null;if("number"==typeof r)return Number.isInteger(r)&&r>=0?new e(r):null;if(Array.isArray(r)){const t=O(r,3);return null!=t?(new e).fromArray(t):null}if(null!=r&&"object"==typeof r){const t=r;if(null!=t.r||null!=t.g||null!=t.b){const r=O([t.r,t.g,t.b],3);return null!=r?(new e).fromArray(r):null}if(null!=t.x||null!=t.y||null!=t.z){const r=O([t.x,t.y,t.z],3);return null!=r?(new e).fromArray(r):null}}}catch{return null}return null}function X(e,r){return null!=e&&"object"==typeof e&&e.constructor?.name===r}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|