@hology/core 0.0.259 → 0.0.261
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/sequence-actor.d.ts +3 -1
- package/dist/effects/sequence/sequence-actor.js +1 -1
- package/dist/effects/sequence/sequence-player.d.ts +11 -0
- package/dist/effects/sequence/sequence-player.js +1 -1
- package/dist/effects/vfx/gpu-sprite-compiler.js +1 -1
- package/dist/effects/vfx/gpu-sprite-runtime.d.ts +3 -1
- package/dist/effects/vfx/gpu-sprite-runtime.js +1 -1
- package/dist/effects/vfx/trail-renderer.d.ts +2 -0
- package/dist/effects/vfx/trail-renderer.js +1 -1
- package/dist/effects/vfx/vfx-actor.d.ts +11 -0
- package/dist/effects/vfx/vfx-actor.js +1 -1
- package/dist/effects/vfx/vfx-asset.d.ts +4 -0
- package/dist/effects/vfx/vfx-collision-behaviour.d.ts +4 -1
- package/dist/effects/vfx/vfx-collision-behaviour.js +1 -1
- package/dist/effects/vfx/vfx-defs.d.ts +1 -0
- package/dist/effects/vfx/vfx-defs.js +1 -1
- package/dist/effects/vfx/vfx-materializer.d.ts +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-renderers.d.ts +2 -0
- package/dist/effects/vfx/vfx-renderers.js +1 -1
- package/dist/gameplay/actors/actor.d.ts +4 -0
- package/dist/gameplay/actors/actor.js +1 -1
- package/dist/gameplay/actors/builtin/components/actor-transform-persistence.d.ts +29 -0
- package/dist/gameplay/actors/builtin/components/actor-transform-persistence.js +4 -0
- package/dist/gameplay/ai/navigation.js +1 -1
- package/dist/gameplay/index.d.ts +2 -0
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.d.ts +4 -0
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/net/service/net-decorator.d.ts +9 -5
- package/dist/gameplay/net/service/net-decorator.js +1 -1
- package/dist/gameplay/net/service/net-service.js +1 -1
- package/dist/gameplay/services/actor-persistence.d.ts +69 -0
- package/dist/gameplay/services/actor-persistence.js +4 -0
- package/dist/gameplay/services/render.d.ts +1 -1
- package/dist/gameplay/services/scene-transition.js +1 -1
- package/dist/gameplay/services/world.d.ts +10 -1
- package/dist/gameplay/services/world.js +1 -1
- package/dist/rendering/webgpu-experimental-backend.js +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/bootstrap.d.ts +2 -0
- package/dist/scene/bootstrap.js +1 -1
- package/dist/scene/materializer.d.ts +10 -0
- package/dist/scene/materializer.js +1 -1
- package/dist/shader-nodes/pom.js +1 -1
- package/dist/test/actor-persistence-runtime.test.d.ts +2 -0
- package/dist/test/actor-persistence-runtime.test.js +4 -0
- package/dist/test/actor-persistence.test.d.ts +2 -0
- package/dist/test/actor-persistence.test.js +4 -0
- package/dist/test/actor-transform-persistence.test.d.ts +2 -0
- package/dist/test/actor-transform-persistence.test.js +4 -0
- package/dist/test/gpu-sprite-compiler.test.js +1 -1
- package/dist/test/materializer-prefetch.test.js +1 -1
- package/dist/test/prefab-instance-params.test.js +1 -1
- package/dist/test/world-lifecycle.test.js +1 -1
- package/dist/test/world-prefab-spawn.test.js +1 -1
- package/docs/actor-persistence.md +87 -0
- package/package.json +1 -1
- 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{observeElementIntersection as a}from"./rendering/intersection-observer.js";import{Color as n,Material as r,Matrix4 as o,Mesh as l,PerspectiveCamera as h,ShaderChunk as c,ShaderMaterial as p,WebGLRenderTarget as u,Texture as d,Euler as m,MeshStandardMaterial as g}from"three";import{CopyShader as f,EffectComposer as b,FXAAShader as M,GammaCorrectionShader as w,LUTPass as v,RenderPass as x,ShaderPass as P}from"three-stdlib";import{CSMShader as y,CSMUtil as S}from"./csm.js";import{colorToNormal as T,float as G,NodeShaderMaterial as R,standardMaterial as E,uniformFloat as C,uniformVec3 as B,toonMaterial as W,lambertMaterial as O,normalize as U,rgb as D,rgba as A,transformed as k,varying as I,varyingAttributes as F,varyingTransformed as V,vec4 as j,BooleanExpression as L,select as _,ifDefApply as z,uniformSampler2d as q,RgbaNode as H,mix as N,attributes as $,uniformVec2 as Q,min 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 Z}from"three/examples/jsm/csm/CSM.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 ne,resolutionUniformName as re,sceneNormalUniformName as oe,screenUV as le,supportsDepthTextureExtension as he}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as ce}from"./shader-nodes/time.js";import{aoMapUniformName as pe,sceneMapUniformName as ue}from"./shader-nodes/scene-sample.js";import{waterVolumeCameraPositionUniformName as de,waterVolumeEnabledUniformName as me,waterVolumeInverseViewProjectionUniformName as ge,waterVolumeWorldToLocalUniformName as fe}from"./shader-nodes/water-volume.js";import{DepthPass as be}from"./utils/three/depth-pass.js";import{GPUStatsPanel as Me}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as we}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as ve,traverseVisibleStop as xe}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 Se,PostProcessEffectRegistration as Te,postProcessEffectStages as Ge,sanitizePostProcessEffectPriority as Re,sanitizePostProcessEffectStage as Ee}from"./rendering/post-process-effect.js";import{SSRPass as Ce}from"./rendering/ssr/SSRPass.js";import{SSRShader as Be}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as We}from"./rendering/fog/volumetric-fog-pass.js";import{UnrealBloomPass as Oe}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Ue}from"./shader-nodes/depth.js";import{packDepthToRGBA as De}from"three-shader-graph";import{FogVolumeObject as Ae}from"./rendering/fog/fog-volume-object.js";import{ParallaxStandardMaterial as ke}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as Ie}from"./shader-nodes/pom.js";import{FullScreenQuad as Fe}from"three-stdlib";import{edgeDepthEffect as Ve}from"./shader-nodes/effects.js";import{decalDiscard as je}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{resolvePostProcessMaterial as ze}from"./shader/post-process-shader.js";import{applyUvTiling as qe}from"./shader/uv-nodes.js";import{createPlaceholderTexture as He}from"./utils/three/placeholder-texture.js";import{getTemporalUpscalingJitter as Ne,getUpscalingMethod as $e,UpscaleOutputPass as Qe}from"./rendering/upscaling-pass.js";import{ExperimentalWebGpuBackend as Je,formatWebGpuSceneCapabilitySummary as Xe}from"./rendering/webgpu-experimental-backend.js";import{WebGlBackend as Ye}from"./rendering/webgl-backend.js";import{defaultGraphicsRuntime as Ke}from"./rendering/graphics-runtime.js";export{GraphicsRuntime}from"./rendering/graphics-runtime.js";function Ze(e){return{enabled:e?.enabled??!0,mapSize:Math.max(1,Math.floor(e?.mapSize??2048)),cascadeCount:Math.max(1,Math.min(4,Math.floor(e?.cascadeCount??4))),maxDistance:Math.max(1,e?.maxDistance??80)}}const et=new i.Vector3,tt=new i.Matrix4,st=(new i.Matrix4).set(1,0,0,0,0,1,0,0,0,0,.5,.5,0,0,0,1);S.patchSetupMaterial();const it=document.createElement("div");it.style.position="absolute",it.style.left="50%",it.style.top="50%",it.style.color="black",it.style.zIndex="999";(new i.Layers).set(9);new i.MeshBasicMaterial({color:"black"});const at=new i.MeshDepthMaterial;var nt;at.depthPacking=i.RGBADepthPacking,at.blending=i.NoBlending,at.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(nt||(nt={}));const rt=(()=>{const e=new Uint8Array([255,255,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),ot=(()=>{const e=new Uint8Array([0,0,0,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),lt=(()=>{const e=new Uint8Array([128,128,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),ht=new R({color:G(0),position:j(G(0))});ht.visible=!1;const ct=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let pt=0;let ut=e=class{get activeBackend(){return this.backendHandle?.kind??null}get canvas(){return this.backendHandle?.canvas??null}get initialized(){return null!=this.backendHandle}get requestedBackend(){return"webgpu"===(e=this.options.backend)||"webgpu-experimental"===e?"webgpu":"webgl";var e}get vfxBackendPreference(){return this.options.webgpuVfx??"cpu"}get webgpuVfxInstancesPerTemplate(){return Math.max(1,Math.floor(this.options.webgpuVfxInstancesPerTemplate??128))}get webgpuVfxTemplateMemoryBudgetBytes(){return 1024*Math.max(1,this.options.webgpuVfxTemplateMemoryBudgetMiB??512)*1024}get webgpuVfxWorldMemoryBudgetBytes(){return 1024*Math.max(1,this.options.webgpuVfxWorldMemoryBudgetMiB??1024)*1024}get webgpuVfxColdTemplateSeconds(){return Math.max(0,this.options.webgpuVfxColdTemplateSeconds??30)}get webGpuDevice(){return this.experimentalWebGpuBackend?.getDevice()??null}get experimentalWebGpuDevice(){return this.webGpuDevice}registerExperimentalStaticDrawSet(e,t,s=!1){if("webgpu"!==this.requestedBackend)return()=>{};const i={root:e,label:t,allowUnsortedLateDraws:s,sourceWasVisible:e.visible,staticDrawSet:null};return this.experimentalStaticDrawSetRegistrations.add(i),this.activateExperimentalStaticDrawSets(),()=>{this.experimentalStaticDrawSetRegistrations.delete(i)&&(i.staticDrawSet?.dispose(),null!=i.staticDrawSet&&(i.root.visible=i.sourceWasVisible),i.staticDrawSet=null)}}registerExperimentalWebGpuRenderGraphExtension(e){return"webgpu"!==this.requestedBackend?()=>{}:(this.experimentalWebGpuRenderGraphExtensions.add(e),()=>{this.experimentalWebGpuRenderGraphExtensions.delete(e)})}get webGlRenderer(){return"webgl"===this.activeBackend?this.renderer:null}registerWebGpuRenderGraphExtension(e){return this.registerExperimentalWebGpuRenderGraphExtension(e)}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++)}createAoblendQuad(){const e=j(1),t=He(),s=q("tAlphaTest",t).sample(le).a,a=q("tAO",t).sample(le),n=_(s.lt(.05),a,J(j(1,1,1,1),a.addScalar(.4))),r=new R({outputs:[n,e,e],transparent:!0});r.depthWrite=!1,r.depthTest=!1,r.blending=i.MultiplyBlending;return new Fe(r)}setPaused(e){this.paused=e}setResolutionScale(e){const t=Tt(e,1);St(t,this.resolutionScale)||(this.resolutionScale=t,this.dynamicResolutionScale=t,this.dynamicResolutionLastAdjustmentAt=0,this.resetDynamicResolutionAverage(),this.resizeRender(!0))}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()))}getClientSize(e=new i.Vector2){return e.set(Math.max(1,this.previousClientWith??1),Math.max(1,this.previousClientHeight??1))}isUpscalingEnabled(){return!0===this.options.upscaling?.enabled&&!0!==this.options.enableXR}isTemporalUpscalingEnabled(){if(!this.isUpscalingEnabled())return!1;const e=$e(this.options.upscaling);return"temporal"===e||"dlss"===e}resetUpscalingHistory(){this.hasPreviousTemporalViewProjection=!1,this.upscaleOutputPass?.resetHistory(),this.experimentalWebGpuBackend?.resetTemporalHistory()}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=Tt(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 h?(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=Tt(this.maxPixelRatio,1),t=Tt(window.devicePixelRatio,1);return Math.min(e,t)}getBaseResolutionScale(){return Tt(this.resolutionScale,1)}getDynamicResolutionMinScale(){const e=this.getBaseResolutionScale(),t=Tt(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(),n=Pe(this.dynamicResolutionScale,a,i);St(n,this.dynamicResolutionScale)||(this.dynamicResolutionScale=n);const r=Tt(s.targetFps,60),o=1e3/(null!=this.fpsCap?Math.min(r,this.fpsCap):r),l=1e3*e;this.dynamicResolutionFrameTimeAverage=null==this.dynamicResolutionFrameTimeAverage?l:.9*this.dynamicResolutionFrameTimeAverage+.1*l,this.dynamicResolutionFrameSamples++;const h=Math.max(1,Math.floor(Tt(s.sampleFrames,20)));if(this.dynamicResolutionFrameSamples<h)return;const c=Tt(s.decreaseCooldown,500),p=Tt(s.increaseCooldown,2e3),u=Tt(s.decreaseStep,.05),d=Tt(s.increaseStep,.025),m=this.dynamicResolutionFrameTimeAverage;let g=n;m>1.12*o&&n>a&&t-this.dynamicResolutionLastAdjustmentAt>=c?g=Math.max(a,n-u):m<.85*o&&n<i&&t-this.dynamicResolutionLastAdjustmentAt>=p&&(g=Math.min(i,n+d)),St(g,n)||(this.dynamicResolutionScale=g,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;if(this.previousClientWith=t,this.previousClientHeight=s,this.previousRenderPixelRatio=i,this.previousPresentationPixelRatio=a,this.camera instanceof h&&(this.camera.aspect=t/s,this.camera.updateProjectionMatrix()),!this.webGlInitialized)return this.experimentalWebGpuBackend?.setSize(t,s,this.getBasePixelRatio(),this.getEffectiveResolutionScale()),this.resetDynamicResolutionAverage(),void this.resetUpscalingHistory();this.renderer.setPixelRatio(a),this.renderer.setSize(t,s),this.composer.setPixelRatio(i),this.composer.setSize(t,s);const n=t*i,r=s*i;this.dofPass.setSize(n,r),this.fxaaPass.setSize(n,r),this.fxaaPass.uniforms.resolution.value.set(1/n,1/r),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.sceneDepthRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(),this.sceneDepthRenderTarget=this.createSceneDepthRenderTarget(),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0,this.experimentalWebGpuBackend?.setSize(t,s,this.getBasePixelRatio(),this.getEffectiveResolutionScale()),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)}}addWaterPostProcessVolume(e){this.waterPostProcessVolumes.includes(e)||this.waterPostProcessVolumes.push(e)}removeWaterPostProcessVolume(e){const t=this.waterPostProcessVolumes.indexOf(e);t>=0&&this.waterPostProcessVolumes.splice(t,1)}updateUnderwaterPostProcessing(){if(null==this.camera)return;const e=this.camera.getWorldPosition(et),t=this.waterPostProcessVolumes.filter(e=>e.underwater.enabled&&mt(e.object)).sort((e,t)=>t.underwater.priority-e.underwater.priority),s=t.find(t=>t.containsWaterPoint(e))??null,i=s??t.find(t=>null!=t.getWaterPostProcessWorldToLocal&&!0===t.isWaterPostProcessRelevant?.(e,t.underwater.transitionDistance))??null;this.activeWaterPostProcessVolume=i;const a=i?.underwater.postProcessMaterial;let n=null;if(!0===a?.isShaderMaterial&&(n=this.underwaterPostProcessEffects.get(a)??null,null==n&&(n=this.addPostProcessEffect(a,{stage:"beforeFog",priority:-100,enabled:!1}),this.underwaterPostProcessEffects.set(a,n))),n!==this.activeUnderwaterPostProcessEffect&&(null!=this.activeUnderwaterPostProcessEffect&&(this.activeUnderwaterPostProcessEffect.enabled=!1),this.activeUnderwaterPostProcessEffect=n),null!=n){n.enabled=null!=i;const t=n.material,a=t.uniforms[fe],r=t.uniforms[de],o=t.uniforms[me],l=t.uniforms[ge];if(null!=l){const e="webgpu"===this.activeBackend?tt.copy(st).multiply(this.camera.projectionMatrix):this.camera.projectionMatrix;l.value.copy(e).multiply(this.camera.matrixWorldInverse).invert()}null!=i?.getWaterPostProcessWorldToLocal&&null!=a?(i.getWaterPostProcessWorldToLocal(a.value,e),r?.value.copy(e),null!=o&&(o.value=1)):null!=o&&(o.value=null!=s?-1:0)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}addPostProcessEffect(e,t={}){const s=ze(e),i={id:++this.postProcessEffectId,material:s,pass:this.webGlInitialized?new Se(s):null,enabled:t.enabled??!0,priority:Re(t.priority),stage:Ee(t.stage)};return null!=i.pass&&(i.pass.enabled=i.enabled),this.postProcessEffects.push(i),this.refreshPostProcessEffectPassOrder(),new Te(this,i)}removePostProcessEffectEntry(e){const t=e,s=this.postProcessEffects.indexOf(t);-1!==s&&(this.postProcessEffects.splice(s,1),null!=t.pass&&(this.composer.removePass(t.pass),t.pass.dispose()),this.syncExperimentalWebGpuPostProcessEffects())}refreshPostProcessEffectPassOrder(){if(this.webGlInitialized){for(const e of this.postProcessEffects)e.pass??(e.pass=new Se(e.material)),e.pass.enabled=e.enabled,this.composer.removePass(e.pass);for(const e of Ge){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(gt);for(let e=0;e<i.length;e++)this.composer.insertPass(i[e].pass,s+e)}this.syncExperimentalWebGpuPostProcessEffects()}else this.syncExperimentalWebGpuPostProcessEffects()}syncExperimentalWebGpuPostProcessEffects(){this.experimentalWebGpuBackend?.setPostProcessEffects(this.postProcessEffects)}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.backendHandle=null,this.webGlBackend=null,this.experimentalWebGpuBackend=null,this.experimentalWebGpuBackendPoolKey=null,this.experimentalWebGpuFailed=!1,this.webGpuRuntimeErrorReported=!1,this.experimentalWebGpuCapabilityReported=!1,this.experimentalWebGpuTiledLightingEnabled=!0,this.experimentalWebGpuDynamicBatchingEnabled=!0,this.ambientOcclusionSettings={enabled:!1,blendIntensity:1,options:{}},this.experimentalWebGpuSelectedObjectInstances=[],this.outlinesEnabled=!1,this.selectedOutlineObjects=[],this.experimentalStaticDrawSetRegistrations=new Set,this.experimentalWebGpuRenderGraphExtensions=new Set,this.webGpuPresentationExtensions=new Set,this.worldEnvironment=null,this.isIntersecting=!1,this.stopIntersectionObservation=null,this.needsPausedRender=!1,this.wakePausedRenderer=null,this.resumeAnimationLoop=null,this.windowVisible=!0,this.queryScene=new i.Scene,this.running=!0,this.paused=!1,this._fpsCap=null,this.fpsCapRevision=0,this.postProcessVolumes=[],this.waterPostProcessVolumes=[],this.underwaterPostProcessEffects=new Map,this.activeUnderwaterPostProcessEffect=null,this.activeWaterPostProcessVolume=null,this.postProcessSettings={},this.baseToneMapping=i.NoToneMapping,this.baseToneMappingExposure=1,this.csmUpdateInvervals=this.options.shadows?.cascadeUpdateIntervals,this.webgpuDirectionalShadowOptions={enabled:!0,mapSize:2048,cascadeCount:4,maxDistance:80},this._id=pt++,this.postProcessEffectId=0,this.postProcessEffects=[],this.occlusionClusters=[],this.simulationTime=0,this.simulationTimeScale=1,this.lightProbeIntensity=2,this.resolutionScale=1,this.maxPixelRatio=ct?1:window.devicePixelRatio,this.dynamicResolutionScale=1,this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0,this.dynamicResolutionLastAdjustmentAt=0,this.upscaleOutputPass=null,this.unjitteredProjectionMatrix=new o,this.temporalJitter=new i.Vector2,this.temporalJitterUv=new i.Vector2,this.currentUnjitteredViewProjectionMatrix=new o,this.currentViewProjectionMatrix=new o,this.currentViewProjectionMatrixInverse=new o,this.previousViewProjectionMatrix=new o,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)this.needsPausedRender=!0,this.wakePausedRenderer?.();else try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.webGlInitialized=!1,this.onLoopCallbacks=[],this.stats=new ee,this.webGpuPassStatsDom=function(){const e=document.createElement("div");return e.dataset.hologyWebGpuPassStats="",e.setAttribute("aria-hidden","true"),e.style.cssText=["position:absolute","top:52px","left:12px","z-index:10000","width:min(520px,calc(100% - 24px))","pointer-events:none","color:white","font:12px/1.2 Arial,Helvetica,sans-serif","text-shadow:0 1px 2px black,0 0 3px black"].join(";"),e}(),this.webGpuVisibilityStatsDom=function(){const e=document.createElement("div");return e.style.cssText=["margin-bottom:10px","padding-bottom:6px","border-bottom:1px solid rgba(255,255,255,.4)"].join(";"),e.textContent="GPU visibility: awaiting readback",e}(),this.webGpuPassStatsRows=[],this._showStats=!1,this._profilingEnabled=!1,this.gbufferMaterialCache=new Map,this.gbufferDepthPrepassMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.depthPrepassMaterialCache=new WeakMap,this.depthPrepassCachedMaterials=new Map,this.depthPrepassCachedVisibility=[],this.frameGBufferMeshes=[],this.frameGBufferPhaseMasks=[],this.frameUnsupportedGBufferObjects=[],this.frameGBufferExcludedObjects=new Set,this.appliedGBufferMeshes=[],this.originalGBufferMaterials=[],this.originalGBufferOnBeforeRender=[],this.hiddenGBufferObjects=[],this.gBufferPhaseMaskCache=new WeakMap,this.gBufferMaterialArrayCache=new WeakMap,this.gBufferShadowUpdaterCache=new WeakMap,this._initiatedMaterialTextures=new Set,this._initiatedTextures=new Set,this.compileInProgress=!1,this.depthMaterialCachedMaterials=new Map,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 n,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],this._customDepthMaterialCache=new WeakMap,this.graphicsRuntime=s.graphicsRuntime??Ke,null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),this.resolutionScale=s.resolutionScale??1,this.dynamicResolutionScale=this.getBaseResolutionScale(),this.fpsCap=s.fpsCap,this.experimentalWebGpuDynamicBatchingEnabled=s.webgpuDynamicBatching??!0,this.experimentalWebGpuTiledLightingEnabled=s.webgpuTiledLighting??!0,this.outlinesEnabled=!0===s.enableOutlines,this.webgpuDirectionalShadowOptions=Ze(s.webgpuDirectionalShadows),"webgpu"===this.requestedBackend&&!0===s.enableXR&&(console.warn("[Hology WebGPU experiment] XR is not supported; using WebGL."),this.experimentalWebGpuFailed=!0),e.activeView=this,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);const a=t.clientWidth||1,r=t.clientHeight||1,h=new i.PerspectiveCamera(45,a/r,.1,800);h.layers.enable(19),this.camera=h,S.renderingView=this,this.setCamera(h),this.setupEventListeners(),this.setupWebGlPipeline=()=>{if(!this.webGlInitialized)try{this.webGlBackend=Ye.initialize({container:this.container,pixelRatio:this.getPresentationPixelRatio(),enableXR:this.options.enableXR??!1,shadows:{enabled:this.options.shadows?.enabled??!0,autoUpdate:this.options.shadows?.autoUpdate??!1}}),this.renderer=this.webGlBackend.renderer,this.outlineEffect=this.webGlBackend.outlineEffect,this.createGRenderTarget(),this.composer=new b(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),this.baseToneMapping=this.renderer.toneMapping,this.baseToneMappingExposure=this.renderer.toneMappingExposure,this.isDepthTextureExtensionSupported=he(this.renderer),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container,this.getRenderPixelRatio()),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(),this.sceneDepthRenderTarget=this.createSceneDepthRenderTarget(),this.postProcessEffectResolution=new i.Vector2(1,1),this.postProcessEffectUniformState={aoEnabled:!1,aoTexture:null,cameraFar:void 0,cameraNear:void 0,depthTexture:He(),normalTexture:He(128,128,255),resolution:this.postProcessEffectResolution,simulationTime:0},this.fquadCopySceneColor=new Fe(new p(f)),this.fquadCopySceneDepth=new Fe(new R({color:j(q("tDepthTexture",He()).sample(F.uv).r)})),this.fquadBlendAO=this.createAoblendQuad();const a=new i.Vector2(t.clientWidth,t.clientHeight),n=(new x(this.scene,this.camera),new P(f,"prevtexture"));n.enabled=!0,n.needsSwap=!0,n.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=n;const r=new Oe(a,1.5,.4,.85);r.threshold=1,r.strength=.9,r.radius=.2,this.bloomPass=r;const o=new te(this.scene,this.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});o.normalRenderTarget?.dispose(),o.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),o.output=te.OUTPUT.Off,o.enabled=!1,this.aoPass=o,o.enabled=this.ambientOcclusionSettings.enabled,o.blendIntensity=this.ambientOcclusionSettings.blendIntensity,o.updateGtaoMaterial(this.ambientOcclusionSettings.options),this.fquadBlendAO.material.uniforms.tAO.value=o.pdRenderTarget.texture,this.fquadBlendAO.material.uniforms.tAlphaTest.value=this.gRenderTarget.textures[1],Be.fragmentShader=Be.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const h=new Ce({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});h.output=Ce.OUTPUT.Default,h.blur=!0,h.fresnel=!1,h.distanceAttenuation=!0,h.maxDistance=50,h.selective=!0,h.bouncing=!1,h.opacity=.4,h.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=h,!1!==this.options.ao?.enabled&&this.composer.addPass(o);const c=new Ft((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(c);const u=new Ft((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(nt.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(u),this.composer.addPass(n),this.composer.addPass(h),this.phasedRenderPass=new It(this.scene,this.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(r),r.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.volumetricFogPass=new We(a),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 d=new ye;this.composer.addPass(d),this.colorPass=d,d.vignetteEnabled=!1,this.outlinePass=new we(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 m=new P(M);m.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(m),this.fxaaPass=m,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new P(w).clear=!1,this.fixStatsStyle(),this.lutPass=new v({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const g=new P(f,"prevtexture");g.enabled=!0,g.needsSwap=!1,g.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],g.renderToScreen=!0;const y=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)}(y),this.outputPass=y,this.upscaleOutputPass=y instanceof Qe?y:null,this.composer.addPass(y);const S=new i.MeshBasicMaterial({colorWrite:!1,depthWrite:!1,depthTest:!0,transparent:!1}),T=new l(new i.BoxGeometry(1,1,1),S);T.renderOrder=1/0,T.name="CLUSTER_BOUNDS_VOLUME",this.webGlInitialized=!0,this.backendHandle=this.webGlBackend,this.attachRendererDomElement(),this.refreshPostProcessEffectPassOrder()}catch(e){throw this.webGlInitialized=!1,this.webGlBackend?.dispose(),this.webGlBackend=null,this.backendHandle=null,e}},("webgpu"!==this.requestedBackend||this.experimentalWebGpuFailed)&&this.setupWebGlPipeline()}addCluster(e){if(!1===this.options.occlusionCulling?.enabled)return;if(!this.webGlInitialized)return;if(!this.renderer.capabilities.isWebGL2)return;const t=this.renderer.getContext(),s=t.createQuery();if(null==s)return;const i={query:s,visible:!0,awaitingResult:!1,cluster:e,lastTested:-1/0,distance:0,update:()=>{if(i.awaitingResult&&t.getQueryParameter(s,t.QUERY_RESULT_AVAILABLE)){const e=t.getQueryParameter(s,t.QUERY_RESULT);i.visible=!!e,i.awaitingResult=!1}}};e.boundsMesh.onBeforeRender=()=>{i.awaitingResult||t.beginQuery(t.ANY_SAMPLES_PASSED,s)},e.boundsMesh.onAfterRender=()=>{i.awaitingResult||(t.endQuery(t.ANY_SAMPLES_PASSED),i.awaitingResult=!0)},this.occlusionClusters.push(i)}updateRenderedOcclusionClusters(){this.queryScene.clear();const e=performance.now(),t=[];for(const s of this.occlusionClusters){if(s.awaitingResult)continue;const i=s.cluster.bounds.distanceToPoint(this.camera.position);if(s.distance=i,i<10){s.visible=!0,s.lastTested=e;continue}if(i>1e3)continue;const a=e-s.lastTested;if(!(s.visible&&a<4e3)&&((s.visible||!(a<100))&&bt.intersectsBox(s.cluster.bounds)))if(s.visible)t.push(s);else{let e=0;for(;e<t.length&&t[e].distance<s.distance;)e++;t.splice(e,0,s)}}if(t.length<50)for(const s of t)s.lastTested=e,this.queryScene.add(s.cluster.boundsMesh);else{const s=Math.max(Math.floor(Math.random()*t.length-50),0);for(let i=0;i<50;i++){const a=t[s+i];if(null==a)break;a.lastTested=e,this.queryScene.add(a.cluster.boundsMesh)}if(t.length>0){const s=t[0];s.lastTested=e,this.queryScene.add(s.cluster.boundsMesh)}}}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute",e.style.display="flex",e.style.flexWrap="nowrap",e.style.width="max-content";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.flex="none"}setEnableOutlines(e){this.outlinesEnabled=e,null!=this.outlinePass&&(this.outlinePass.enabled=e),null!=this.fxaaPass&&(this.fxaaPass.enabled=e),this.syncWebGpuOutlineState()}registerWebGpuPresentationExtension(e){return"webgpu"!==this.requestedBackend?()=>{}:(this.webGpuPresentationExtensions.add(e),this.experimentalWebGpuBackend?.setPresentationExtensions(this.webGpuPresentationExtensions),()=>{this.webGpuPresentationExtensions.delete(e),this.experimentalWebGpuBackend?.setPresentationExtensions(this.webGpuPresentationExtensions)})}get sharedGraphicsRuntime(){return this.graphicsRuntime}setCamera(e){if(this.camera=e,this.resetUpscalingHistory(),this.composer?.passes.forEach(t=>{t instanceof x?t.camera=e:t instanceof we?t.renderCamera=e:(t instanceof be||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){this.csm=new Z({maxFar:"webgpu"===this.requestedBackend?this.webgpuDirectionalShadowOptions.maxDistance:80,lightFar:250,lightMargin:20,shadowBias:-1e-4,cascades:"webgpu"===this.requestedBackend?this.webgpuDirectionalShadowOptions.cascadeCount:ct?2:3,shadowMapSize:"webgpu"===this.requestedBackend?this.webgpuDirectionalShadowOptions.mapSize:1024*(ct?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"});for(const e of this.csm.lights)e.shadow.normalBias=.01;if(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,c.lights_fragment_begin=y.lights_fragment_begin}else this.csm.camera=this.camera,this.camera;this.csm.updateFrustums()}setSelectedObjects(e){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.selectedOutlineObjects=Array.from(t.values()),this.experimentalWebGpuSelectedObjectInstances=[],this.syncWebGpuOutlineState(),null!=this.outlinePass&&(this.outlinePass.selectedObjects=this.selectedOutlineObjects)}setExperimentalWebGpuTiledLightingEnabled(e){this.experimentalWebGpuTiledLightingEnabled=e,this.experimentalWebGpuBackend?.setTiledLightingEnabled(e)}setExperimentalWebGpuDynamicBatchingEnabled(e){this.experimentalWebGpuDynamicBatchingEnabled=e,this.experimentalWebGpuBackend?.setDynamicBatchingEnabled(e)}setMotionBlurOptions(e){this.experimentalWebGpuBackend?.setMotionBlurOptions(e)}setDirectionalShadowOptions(e){if("webgpu"!==this.requestedBackend)return;const t=Ze(e),s=this.webgpuDirectionalShadowOptions,a=t.mapSize!==s.mapSize||t.cascadeCount!==s.cascadeCount||t.maxDistance!==s.maxDistance;if(a||t.enabled!==s.enabled){if(this.webgpuDirectionalShadowOptions=t,a&&null!=this.csm){const e=this.csm.lights[0],t={lightDirection:this.csm.lightDirection.clone(),lightIntensity:e?.intensity??this.csm.lightIntensity,lightColor:e?.color.clone()??new i.Color(16777215),castShadow:e?.castShadow??!0,userData:{...e?.userData??{}},shadowBias:e?.shadow.bias??this.csm.shadowBias,normalBias:e?.shadow.normalBias??.01,shadowRadius:e?.shadow.radius??1,shadowIntensity:e?.shadow.intensity??1};this.csm.remove(),this.csm.dispose(),this.csm=null,this.csmCascadeLastUpdate=void 0,this.setCamera(this.camera),this.csm.lightDirection.copy(t.lightDirection),this.csm.lightIntensity=t.lightIntensity,this.csm.shadowBias=t.shadowBias;for(const e of this.csm.lights)e.intensity=t.lightIntensity,e.color.copy(t.lightColor),e.castShadow=t.castShadow,e.userData={...t.userData},e.shadow.bias=t.shadowBias,e.shadow.normalBias=t.normalBias,e.shadow.radius=t.shadowRadius,e.shadow.intensity=t.shadowIntensity;this.csm.update()}this.experimentalWebGpuBackend?.setDirectionalShadowOptions(t.enabled,t.mapSize),this.syncExperimentalWebGpuCascades(),this.experimentalWebGpuBackend?.resetViewHistory()}}setGTAOOptions(e){this.experimentalWebGpuBackend?.setGTAOOptions(e)}configureAmbientOcclusion(e,t=1,s={}){this.ambientOcclusionSettings={enabled:e,blendIntensity:t,options:s},this.webGlInitialized&&(this.aoPass.enabled=e,this.aoPass.blendIntensity=t,this.aoPass.updateGtaoMaterial(s)),this.experimentalWebGpuBackend?.setGTAOOptions({...s,enabled:e})}invalidateShadows(){this.webGlInitialized&&(this.renderer.shadowMap.needsUpdate=!0)}initTexture(e){this._initTexture(e)}setBaseToneMapping(e,t){this.baseToneMapping=e,this.baseToneMappingExposure=t,this.webGlInitialized&&(this.renderer.toneMapping=e,this.renderer.toneMappingExposure=t)}get supportsWebGlDepthTexture(){return this.webGlInitialized&&this.isDepthTextureExtensionSupported}setAntiAliasingMode(e){this.experimentalWebGpuBackend?.setAntiAliasingMode(e)}setGTAOQuality(e){this.experimentalWebGpuBackend?.setGTAOQuality(e)}setVolumetricFogOptions(e){this.experimentalWebGpuBackend?.setVolumetricFogOptions(e)}setVolumetricFogQuality(e){this.experimentalWebGpuBackend?.setVolumetricFogQuality(e)}pushMotionBlurOverride(e){return this.experimentalWebGpuBackend?.pushMotionBlurOverride(e)??null}setObjectMotionBlur(e,t,s=1){e.traverse(e=>{e.userData.motionBlurMode=t,e.userData.motionBlurScale=Math.max(0,Math.min(s,8))})}invalidateObjectMotion(e){e.traverse(e=>{e.userData.motionBlurTeleported=!0,this.experimentalWebGpuBackend?.invalidateObjectMotion(e)})}setSelectedObjectInstances(e){this.experimentalWebGpuSelectedObjectInstances=[...e],this.syncWebGpuOutlineState()}static createDepthRenderTarget(e,t,s){const a=Math.max(1,Math.floor(t.clientWidth*s)),n=Math.max(1,Math.floor(t.clientHeight*s)),r=new i.WebGLRenderTarget(a,n);return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,r.depthTexture=new i.DepthTexture(a,n),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter,r}static createAOMaskDepthRenderTarget(e,t,s=e.getPixelRatio()){const a=Math.max(1,t.clientWidth*s),n=Math.max(1,t.clientHeight*s),r=new i.DepthTexture(a,n);r.type=i.UnsignedInt248Type,r.minFilter=i.NearestFilter,r.magFilter=i.NearestFilter;const o=new i.WebGLRenderTarget(a,n,{type:i.HalfFloatType,depthTexture:r});return o.texture.minFilter=i.NearestFilter,o.texture.magFilter=i.NearestFilter,o.texture.generateMipmaps=!1,o.stencilBuffer=!1,o}createSceneColorRenderTarget(){const e=this.gRenderTarget.width,t=this.gRenderTarget.height,s=new i.WebGLRenderTarget(e,t,{type:i.HalfFloatType,format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}createSceneDepthRenderTarget(){const e=new i.WebGLRenderTarget(this.gRenderTarget.width,this.gRenderTarget.height,{type:i.FloatType,format:i.RedFormat,minFilter:i.NearestFilter,magFilter:i.NearestFilter,depthBuffer:!1,stencilBuffer:!1});return e.texture.generateMipmaps=!1,e}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),n=new i.DepthTexture(s,a);n.type=i.UnsignedIntType,n.minFilter=i.NearestFilter,n.magFilter=i.NearestFilter,this.gRenderTarget=new u(s,a,{count:3,samples:this.options?.msaa??0,minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat,depthTexture:n}),this.gRenderTarget.textures[2].type=i.UnsignedByteType,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(t=!0){if(this.stopAnimationLoop(),this.stopIntersectionObservation?.(),this.stopIntersectionObservation=null,this.resumeAnimationLoop=null,this.onLoopCallbacks=[],this.disposeExperimentalStaticDrawSets(),e.experimentalWebGpuPresentationView===this&&(e.experimentalWebGpuPresentationView=null),this.wakePausedRenderer=null,this.lightVolume?.shTexture.dispose(),window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),t&&this.webGlInitialized&&this.renderer.dispose(),this.webGlInitialized){this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.sceneDepthRenderTarget.dispose();for(const e of this.postProcessEffects)null!=e.pass&&(this.composer.removePass(e.pass),e.pass.dispose());this.volumetricFogPass.dispose(),this.webGlBackend?.dispose(),this.webGlBackend=null}if(this.csm?.dispose(),this.postProcessEffects.length=0,this.detachOwnedDomElements(),this.releaseExperimentalWebGpuBackend(),this.experimentalWebGpuBackend=null,this.backendHandle=null,this.webGlInitialized&&this.occlusionClusters.length>0){const e=this.renderer.getContext();this.occlusionClusters.forEach(t=>{e.deleteQuery(t.query)})}S.clearSceneCache(this.scene)}stopAnimationLoop(){this.running=!1}suspendPresentation(){this.stopAnimationLoop(),this.detachOwnedDomElements()}activatePresentation(){if(e.activeView=this,null!=this.experimentalWebGpuBackend){const t=e.experimentalWebGpuPresentationView,s=t!==this;s&&t?.disposeExperimentalStaticDrawSets(),this.applyExperimentalWebGpuViewState(s),e.experimentalWebGpuPresentationView=this,this.activateExperimentalStaticDrawSets()}this.attachRendererDomElement(),this.resizeRender(!0)}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.experimentalWebGpuBackend?.setProfilingEnabled(e||this._profilingEnabled),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),this.syncWebGpuPassStatsDom()}get showStats(){return this._showStats}getLastFrameProfile(){return this.experimentalWebGpuBackend?.getLastFrameProfile()??null}setProfilingEnabled(e){this._profilingEnabled=e,this.experimentalWebGpuBackend?.setProfilingEnabled(e||this._showStats)}attachRendererDomElement(){const t=this.getActiveRendererCanvas();if("webgpu"===this.activeBackend&&null!=this.experimentalWebGpuBackend&&e.experimentalWebGpuPresentationView!==this){const t=e.experimentalWebGpuPresentationView;t?.disposeExperimentalStaticDrawSets(),e.experimentalWebGpuPresentationView=this,this.applyExperimentalWebGpuViewState(!0),this.activateExperimentalStaticDrawSets()}const s=this.webGlInitialized?this.renderer.domElement:null,i=t===s?this.experimentalWebGpuBackend?.canvas:s;i?.parentElement===this.container&&this.container.removeChild(i),t.parentElement===this.container&&t===this.container.firstChild||this.container.insertBefore(t,this.container.firstChild),this._showStats&&this.stats.dom.parentElement!==this.container&&this.container.appendChild(this.stats.dom),this.syncWebGpuPassStatsDom()}detachOwnedDomElements(){this.webGlInitialized&&this.renderer.domElement.parentElement===this.container&&this.container.removeChild(this.renderer.domElement);const e=this.experimentalWebGpuBackend?.canvas;e?.parentElement===this.container&&this.container.removeChild(e),this.stats.dom.parentElement===this.container&&this.container.removeChild(this.stats.dom),this.webGpuPassStatsDom.parentElement===this.container&&this.container.removeChild(this.webGpuPassStatsDom)}syncWebGpuPassStatsDom(){const e=this._showStats&&"webgpu"===this.requestedBackend;e&&this.webGpuPassStatsDom.parentElement!==this.container?this.container.appendChild(this.webGpuPassStatsDom):e||this.webGpuPassStatsDom.parentElement!==this.container||this.container.removeChild(this.webGpuPassStatsDom)}updateWebGpuPassStats(e){let t=this.webGpuPassStatsRows.length!==e.passes.length;for(let s=0;!t&&s<e.passes.length;s++)t=this.webGpuPassStatsRows[s].name!==e.passes[s].name;t&&(this.webGpuPassStatsDom.replaceChildren(this.webGpuVisibilityStatsDom),this.webGpuPassStatsRows=e.passes.map(e=>{const t=function(e){const t=document.createElement("div");t.style.cssText=["display:grid","grid-template-columns:minmax(0,1fr) 92px 92px","column-gap:12px","margin-bottom:7px"].join(";");const s=document.createElement("span");s.textContent=e,s.style.cssText="overflow:hidden;text-overflow:ellipsis;white-space:nowrap";const i=document.createElement("span"),a=document.createElement("span"),n=document.createElement("div");return n.style.cssText=["grid-column:1","height:4px","margin-top:4px","background:rgba(255,255,255,.78)","box-shadow:0 1px 2px rgba(0,0,0,.9)"].join(";"),t.append(s,i,a,n),{name:e,dom:t,gpu:i,cpu:a,bar:n}}(e.name);return this.webGpuPassStatsDom.appendChild(t.dom),t}));const s=e.visibility;if(null==s)this.webGpuVisibilityStatsDom.textContent=e.hiZOcclusionCullingActive?"GPU visibility: awaiting readback":"GPU visibility: inactive";else{const e=s.totalInstances>0?s.visibleInstances/s.totalInstances*100:100;this.webGpuVisibilityStatsDom.textContent=`GPU visibility: ${s.visibleInstances.toLocaleString()} / ${s.totalInstances.toLocaleString()} visible (${e.toFixed(1)}%), ${s.culledInstances.toLocaleString()} culled | dynamic ${s.dynamicVisibleInstances.toLocaleString()} / ${s.dynamicTotalInstances.toLocaleString()}, static ${s.staticVisibleInstances.toLocaleString()} / ${s.staticTotalInstances.toLocaleString()}`}let i=.01;for(const t of e.passes)i=Math.max(i,t.gpuTimeMs??t.cpuTimeMs);for(let t=0;t<e.passes.length;t++){const s=e.passes[t],a=this.webGpuPassStatsRows[t];a.gpu.textContent=null==s.gpuTimeMs?"GPU --":`GPU ${s.gpuTimeMs.toFixed(2)} ms`,a.cpu.textContent=`CPU ${s.cpuTimeMs.toFixed(2)} ms`;const n=s.gpuTimeMs??s.cpuTimeMs;a.bar.style.width=`${Math.max(n>0?2:0,n/i*100)}%`}}getActiveRendererCanvas(){if(null==this.backendHandle)throw new Error("Rendering backend is not initialized. Await compileAsync() before rendering.");return this.backendHandle.canvas}requireInitializedBackend(e){const t=this.backendHandle;if(null==t)throw new Error(`Cannot ${e}: the rendering backend has not finished initializing.`);return t}fallbackToWebGlForUnavailableWebGpu(t){const s=t instanceof Error?t.stack??t.message:String(t);console.warn(`[Hology WebGPU] WebGPU is unavailable. ${s}`);const i=this.experimentalWebGpuBackend;i?.canvas.parentElement===this.container&&this.container.removeChild(i.canvas),this.disposeExperimentalStaticDrawSets(),this.releaseExperimentalWebGpuBackend(),e.experimentalWebGpuPresentationView===this&&(e.experimentalWebGpuPresentationView=null),this.experimentalWebGpuBackend=null,this.experimentalWebGpuFailed=!0,this.backendHandle=null,this.webGpuPassStatsDom.remove(),this.setupWebGlPipeline(),this.applyWorldEnvironmentToWebGl(),this.attachRendererDomElement(),this.resizeRender(!0),console.warn("[Hology WebGPU] Falling back to WebGL because WebGPU is unavailable.")}activateExperimentalStaticDrawSets(){if("webgpu"!==this.activeBackend||null==this.experimentalWebGpuBackend)return;let e=0,t=0,s=0,i=0;for(const a of this.experimentalStaticDrawSetRegistrations)if(null==a.staticDrawSet)try{const i=this.experimentalWebGpuBackend.createStaticDrawSet(a.root,a.label,a.allowUnsortedLateDraws);if(null==i)continue;a.staticDrawSet=i,a.root.visible=!1,e++,t+=i.drawCount,s+=i.instanceCount}catch(e){i++,console.warn(`[Hology WebGPU experiment] Keeping static root "${a.label}" dynamic:`,e)}e>0&&console.info(`[Hology WebGPU experiment] Activated ${e} static draw set${1===e?"":"s"} (${t} draws, ${s} instances).`),i>0&&console.warn(`[Hology WebGPU experiment] ${i} static draw set${1===i?"":"s"} remain dynamic.`)}disposeExperimentalStaticDrawSets(){for(const e of this.experimentalStaticDrawSetRegistrations)e.staticDrawSet?.dispose(),null!=e.staticDrawSet&&(e.root.visible=e.sourceWasVisible),e.staticDrawSet=null}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof R&&(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:Ot(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 R||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}setWorldEnvironment(e){const t=this.worldEnvironment?.source!==e?.source;this.worldEnvironment=e,null==e?(this.scene.environment=null,this.scene.environmentIntensity=1):("webgpu"!==this.requestedBackend||this.experimentalWebGpuFailed)&&this.applyWorldEnvironmentToWebGl();const s=this.experimentalWebGpuBackend;if(null==s)return;const i=t&&"webgpu"===this.activeBackend;i&&this.disposeExperimentalStaticDrawSets(),s.setWorldEnvironment(e),i&&this.activateExperimentalStaticDrawSets()}applyWorldEnvironmentToWebGl(){const e=this.worldEnvironment;if(null==e)return this.scene.environment=null,void(this.scene.environmentIntensity=1);this.scene.environment=this.getEnvTexture(e.source),this.scene.environmentIntensity=e.intensity}hideOccluded(e){e.length=0;for(const t of this.occlusionClusters)if(!t.visible){let s=t.cluster.objects.length;for(;s--;){const i=t.cluster.objects[s];i.visible&&(i.visible=!1,e.push(i))}}}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 g||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 g||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 g&&(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 ke&&(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===Vt.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||Vt.includes(e)||jt.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 Vt){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(e,t,s=!1){const a=t===nt.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let n=a.get(e);if(!0===e.userData.isGBufferMaterial)return e;if(null==n){const s=this.usesShaderUniform(e,ie),o=this.usesShaderUniform(e,ue),l=this.usesShaderUniform(e,pe),h=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,c=t===nt.opaque?!(s||o||l||h):h||s||o||l;if(!c)return a.set(e,ht),ht;let u=F.uv;if(e instanceof ke&&null!=e.heightMap){const t=C("heightScale",e.heightScale??1);u=Ie(u,q("heightMap",e.heightMap),t)}let d=V.normal;if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=e.normalMap??lt,s=C("useNormalMap",null!=e.normalMap?1:0),i=C("normalScale",e.normalScale?.x??1),a=T(q("normalMap",t).sample(qe(u,e.normalMap)),i);d=N(V.normal,a,s)}else e instanceof R&&null!=e.outputNormal&&(d=e.outputNormal);!0!==e.userData.disableAO&&(d=z("DOUBLE_SIDED",d,e=>_(new L("gl_FrontFacing"),e,e.multiplyScalar(-1))));let m=e.userData?.reflective?G(0):G(1);if(e instanceof i.MeshStandardMaterial){const t=C("roughness",e.roughness??1),s=e.roughnessMap??rt,i=C("useRoughnessMap",null!=e.roughnessMap?1:0),a=q("roughnessMap",s).sample(qe(u,e.roughnessMap)).g.multiply(t);m=N(t,a,i)}else e instanceof R&&null!=e.outputRoughness&&(m=e.outputRoughness);let f=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,s=C("useLightMap",null!=e.lightMap?1:0),i=C("lightMapIntensity",e.lightMapIntensity??1),a=q("lightMap",t).sample(u).rgb.multiplyScalar(i);f=N(D(0),a,s)}let b=G(0);if(e instanceof i.MeshStandardMaterial){const t=C("metalness",e.metalness??0),s=e.metalnessMap??ot,i=C("useMetalnessMap",null!=e.metalnessMap?1:0),a=q("metalnessMap",s).sample(qe(u,e.metalnessMap)).b.multiply(t);b=N(t,a,i)}else e instanceof R&&e.outputRoughness;let M=null,w=G(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??rt,s=C("useAoMap",null!=e.aoMap?1:0);w=C("aoMapIntensity",e.aoMapIntensity??1);const i=q("aoMap",t).sample(qe(u,e.aoMap)).r;M=N(G(1),i,s)}else e instanceof R&&e.outputRoughness;const v=C("opacity",e.opacity??1);let x=G(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;x=q("alphaMap",t).sample(qe(u,e.alphaMap)).r}x=x.multiply(v)}else e instanceof R&&null!=e.outputOpacity&&(x=e.outputOpacity);let P=A(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=B("color",(new i.Vector3).setFromColor(e.color));const s=e.map??rt,a=C("useAlbedoMap",null!=e.map?1:0),n=q("map",s).sample(qe(u,e.map)),r=n.multiply(A(t,1)),o=A(t,1);P=N(o,r,a),e.vertexColors&&(P=P.multiply(j(I($.color.rgb),1)));const l=N(G(1),n.w,a);x=x.multiply(l)}const y=!0===e.userData.hasBloom;let S=D(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=B("emissive",(new i.Vector3).setFromColor(e.emissive)),s=C("emissiveIntensity",e.emissiveIntensity),a=e.emissiveMap??ot,n=C("useEmissiveMap",null!=e.emissiveMap?1:0),r=q("emissiveMap",a).sample(qe(u,e.emissiveMap)).rgb.multiply(t);S=N(t,r,n),S=S.multiplyScalar(s)}else e instanceof R&&null!=e.outputEmissive&&(S=e.outputEmissive);let k=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(k=B("sheenColor",(new i.Vector3).setFromColor(e.sheenColor).multiplyScalar(e.sheen)),e.sheen>0&&null!=e.sheenColorMap)){const t=q("sheenColorMap",e.sheenColorMap).sample(u).rgb;k=k.multiply(t)}let H=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(H=C("sheenRoughness",e.sheenRoughness),e.sheen>0&&null!=e.sheenRoughnessMap)){const t=q("sheenRoughnessMap",e.sheenRoughnessMap).sample(u).r;H=H.multiply(t)}let J=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0&&(J=C("anisotropy",e.anisotropy),e.anisotropy>0&&null!=e.anisotropyMap)){const t=q("anisotropyMap",e.anisotropyMap).sample(u).r;J=J.multiply(t)}let X=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0){const t=e.anisotropyRotation??0;X=Q("anisotropyDirection",new i.Vector2(Math.cos(t),Math.sin(t)))}const Y=C("alphaTest",e.alphaTest);let K,Z=e.alphaTest>0?x.lt(Y):h&&t===nt.opaque?x.lt(.8):null;!0===e.userData.isDecal&&(Z=Z?Z.or(je):je),K=h?j(0,0,0,0):(r=d,U(r).multiplyScalar(.5).addScalar(.5)).rgba(e.userData?.reflective?m:1);const ee=e instanceof R?e.outputPosition:void 0,te=e instanceof R?e.outputTransform:void 0;let se,ae=A("black",1);if(e instanceof R&&null!=e.outputColor)ae=e.outputColor;else if(e instanceof i.MeshStandardMaterial)ae=E({color:P,metalness:b,roughness:m,emissive:S.rgb,normal:d,ambientOcclusion:M,ambientOcclusionIntensity:w,bakedLight:f,sheenColor:k,sheenRoughness:H,anisotropy:J,anisotropyDirection:X});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)ae=O({color:P.rgb,ambientOcclusion:M,ambientOcclusionIntensity:w});else if(e instanceof i.MeshBasicMaterial){let e=P.rgb,t=f??D("black");null!=M&&(t=t.multiplyScalar(M.subtract(1).multiply(w).add(1))),e=e.add(t),ae=e.rgba(x)}else e instanceof i.MeshToonMaterial&&(ae=W({color:P,emissive:S.rgb,normal:d,ambientOcclusion:M,ambientOcclusionIntensity:w,bakedLight:f}));(e instanceof R||e instanceof i.MeshStandardMaterial)&&(se=e.envMap);let ne=!0;(e instanceof g||e instanceof i.MeshBasicMaterial||e instanceof i.ShaderMaterial)&&(ne=e.fog);let re=A(ae.rgb,x);ne&&(re=new FogNode(re)),n=new R({transform:te,position:null==te?ee:void 0,outputs:[re,S.rgba(t===nt.opaque?Y:y?1:0),K],opacity:x,outputEncoding:!1,fog:ne,transparent:e.transparent,lights:!0,envMap:se,alphaTest:e.alphaTest,uniformNodes:e.uniformNodes??{},discard:Z}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=n.uniforms.envMapIntensity&&(n.uniforms.envMapIntensity.value=e.envMapIntensity),"alphaMap"in e&&null!=e.alphaMap&&(n.alphaMap=e.alphaMap),(e instanceof R||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(n),e instanceof R&&(Object.assign(n.defines,e.defines),null!=n.uniforms[pe]&&(n.uniforms[pe].value=this.aoPass.pdRenderTarget.texture,n.defines.USE_SSAO_MAP="")),n.userData.mrtOutputs=3,n.forceSinglePass=e.forceSinglePass,n.side=e.side,n.blending=e.blending,h?(n.depthWrite=!e.transparent,n.depthTest=e.depthTest,n.colorWrite=t===nt.transparent):(n.depthWrite=e.depthWrite,n.depthTest=e.depthTest),n.visible=e.visible,n.alphaTest=e.alphaTest,n.alphaHash=e.alphaHash,n.vertexColors=e.vertexColors,n.premultipliedAlpha=e.premultipliedAlpha,n.toneMapped=e.toneMapped,n.blendAlpha=e.blendAlpha,n.blendColor=e.blendColor,n.polygonOffset=e.polygonOffset,n.polygonOffsetFactor=e.polygonOffsetFactor,n.polygonOffsetUnits=e.polygonOffsetUnits,n.blending=e.blending,n.wireframe=e.wireframe??!1,n.userData.isGBufferMaterial=!0,n.visible=c,Object.assign(n.userData,e.userData),n.visible&&(this.csm.setupMaterial(n),e instanceof p&&this.inheritCustomUniformBindings(e,n)),a.set(e,n)}var r;return n.visible&&(e instanceof p?this.updateUniformValues(e,n):this.updateMaterialProperties(e,n)),this.usesShaderUniform(n,ue)&&this.initSceneColorUniform(n),this.initLightVolumeUniform(n),n}isDepthPrepassEnabled(){return!0===this.options.depthPrepass?.enabled}usesSceneFeedbackUniforms(e){return e instanceof p&&(this.usesShaderUniform(e,ie)||this.usesShaderUniform(e,ue)||this.usesShaderUniform(e,pe))}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 R||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=G(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(a=C("opacity",e.opacity??1),null!=e.map&&(a=a.multiply(q("map",e.map).sample(F.uv).a)),null!=e.alphaMap&&(a=a.multiply(q("alphaMap",e.alphaMap).sample(F.uv).r))):e instanceof R&&(a=e.outputOpacity??G(1)),null!=e.alphaTest&&e.alphaTest>0&&(s=a.lt(e.alphaTest));const n=e instanceof R?e.outputPosition:void 0,r=e instanceof R?e.outputTransform:void 0;t=new R({outputs:[A(0,0),A(0,0),A(0,0)],opacity:a,transform:r,position:null==r?n: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 Vt)delete t.uniforms[e];for(const e of jt)delete t.uniforms[e];delete t.uniforms.receiveShadow,this.depthPrepassMaterialCache.set(e,t)}return e instanceof R?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,xe(this.scene,s=>{if(At(s))return t.push(s),s.visible=!1,!1;if(!(s instanceof l))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.webGlInitialized&&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()}syncExperimentalWebGpuCascades(){const e=this.experimentalWebGpuBackend,t=this.camera,s=this.csm;if(null==e||!(t instanceof h)||null==s)return void e?.setCascadedShadowRanges([]);const i=[];s.getExtendedBreaks(i);const a=Math.max(t.far-t.near,1e-4),n=Math.max(Math.min(t.far,s.maxFar),0)/a;e.setCascadedShadowRanges(i.map(({x:e,y:t})=>({x:e*n,y:t*n})),s.lights)}loop(t,s=!1){if(this.requireInitializedBackend("start the render loop"),null!=this.resumeAnimationLoop)return this.running=!0,void this.resumeAnimationLoop();this.running=!0;const n=this.stats,r=n.addPanel(new ee.Panel("Calls","#83f","#002")),h=n.addPanel(new ee.Panel("Triangles","#c32","#002")),c="webgpu"===this.requestedBackend,p=c?n.addPanel(new ee.Panel("WGPU CPU","#2cf","#013")):null,u=c?n.addPanel(new ee.Panel("WGPU GPU","#fc2","#310")):null,d=c?n.addPanel(new ee.Panel("Extract","#4f8","#021")):null,m=c?n.addPanel(new ee.Panel("Upload","#f8c","#301")):null,g=c?n.addPanel(new ee.Panel("Graph","#c8f","#201")):null;let f;s&&this.fixStatsStyle(),navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&"webgpu"!==this.requestedBackend&&(f=new Me(this.renderer.getContext()),n.addPanel(f)),this.showStats=s;let b=10,M=1e3,w=16,v=16,x=4,P=4,y=16;let S=-1/0;const T=e=>!(e-S<.25)&&(S=e,!0),G=()=>{const e=this.renderer.info.render.calls;e>b&&(b=e,setTimeout(()=>b=10,5e3)),r.update(e,b);const t=this.renderer.info.render.triangles;t>M&&(M=t,setTimeout(()=>M=1e3,5e3)),h.update(t,M)},E=()=>{const e=this.experimentalWebGpuBackend?.getLastFrameProfile();null!=e&&(b=Math.max(b,e.drawCallCount),M=Math.max(M,e.triangleCount),w=Math.max(w,e.cpuTimeMs),x=Math.max(x,e.cpuPhases.extractSceneMs),P=Math.max(P,e.cpuPhases.uploadMs),y=Math.max(y,e.cpuPhases.renderGraphMs),r.update(e.drawCallCount,b),h.update(e.triangleCount,M),p?.update(e.cpuTimeMs,w),d?.update(e.cpuPhases.extractSceneMs,x),m?.update(e.cpuPhases.uploadMs,P),g?.update(e.cpuPhases.renderGraphMs,y),null!=e.gpuTimeMs&&(v=Math.max(v,e.gpuTimeMs),u?.update(e.gpuTimeMs,v)),this.updateWebGpuPassStats(e))};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const C=[],B=[],W=[],O=[];let U=0;const D=new o,A=new o;let k=0;let I=this.paused,F=!1,V=0,j=null,L=this.fpsCapRevision;const _=()=>{this.running&&!0!==this.options.enableXR&&requestAnimationFrame(q)},z=()=>{this.running&&(e.activeView=this,F&&(F=!1,requestAnimationFrame(()=>q(V))))};this.wakePausedRenderer=z,this.stopIntersectionObservation?.(),this.isIntersecting=!1,this.stopIntersectionObservation=a(this.container,e=>{this.isIntersecting=e,e&&z()}),this.container.addEventListener("pointerdown",()=>{z()},{capture:!0});const q=s=>{if(F=!1,!this.running)return;const a=this.getActiveRendererCanvas(),r=this.needsPausedRender;if(!this.isIntersecting||this.paused&&!r&&a.height>1)return F=!0,V=s,setTimeout(()=>{this.running&&F&&q(s)},500),void(this.paused&&(I=!0));if(a.parentElement!==this.container){if(e.activeView!==this&&null!==e.activeView)return F=!0,void(V=s);this.attachRendererDomElement(),this.resizeRender()}if(!0!==this.options.enableXR){L!==this.fpsCapRevision&&(L=this.fpsCapRevision,j=null);const e=this.fpsCap;if(null!=e){const t=1e3/e;if(null!=j){const e=s-j;if(e<t)return void _();j=s-e%t}else j=s}else j=s}let o=(s*=.001)-U;U=s,I?(o=.016,I=!1,this.resetUpscalingHistory()):o>.25&&this.resetUpscalingHistory(),this.updateDynamicResolution(o,1e3*s);const h="webgpu"===this.activeBackend;if(h||(this.renderer.autoClear=!1,this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight)),n.begin(),!h&&this.showStats&&f?.startQuery(),h||(this.ssrPass.gpuPanel=f),D.copy(this.camera.matrixWorld),!this.paused){if(o>1){let e=o;for(;e>.05;)t(dt),e-=dt;t(e)}else t(o);this.onLoopCallbacks.forEach(e=>e(o))}this.paused||(this.simulationTime+=o*this.simulationTimeScale);const c=this.simulationTime;if(this.camera?.updateMatrixWorld(),this.updateUnderwaterPostProcessing(),this.applyPostProcessSettings(),A.copy(this.camera.matrixWorld),s-k>.08&&!A.equals(D)&&(this.webGlInitialized&&(this.renderer.shadowMap.needsUpdate=!0),k=s),this.updateCsm(),h){try{const e=this.experimentalWebGpuBackend;if(null==e||!Je.supportsCamera(this.camera))throw new Error(`Unsupported camera type: ${this.camera?.type??"unknown"}`);this.syncExperimentalWebGpuCascades(),e.setRenderGraphExtensions(this.experimentalWebGpuRenderGraphExtensions),e.setPresentationExtensions(this.webGpuPresentationExtensions),e.render(this.scene,this.camera,c),this.webGpuRuntimeErrorReported=!1,this.showStats&&T(s)&&E()}catch(e){if(!this.webGpuRuntimeErrorReported){const t=e instanceof Error?e.stack??e.message:String(e);console.error(`[Hology WebGPU] Frame rendering failed; the WebGPU backend remains active. ${t}`),this.webGpuRuntimeErrorReported=!0}}return n.end(),void _()}let p=!1;C.length=0,B.length=0,W.length=0;for(const e of O)e.visible=!0;O.length=0;const u=bt;wt.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),u.setFromProjectionMatrix(wt);let d=!1,m=!1,g=!1;const b=this.frameGBufferMeshes,M=this.frameGBufferPhaseMasks,w=this.frameUnsupportedGBufferObjects,v=this.frameGBufferExcludedObjects;if(b.length=0,M.length=0,w.length=0,v.clear(),this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Ae&&(d=!0),e instanceof l&&this.initCustomDepthMaterial(e),(e instanceof l||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&&ft(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(p=!0)),(e instanceof l||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ie])&&isObjectInFrustum(e,u)?(this.initDepthUniform(e.material),m=!0):e instanceof X&&(e.visible=!1,B.push(e)),(e instanceof l||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[pe]&&isObjectInFrustum(e,u)&&e.material instanceof R&&this.initAoUniform(e.material),e instanceof l||e instanceof i.Sprite){let t=!1;ft(e,e=>{this.usesShaderUniform(e,ue)&&(this.initSceneColorUniform(e),t=!0)}),t&&(W.push(e),g=!0)}if(e instanceof l&&e.material?.uniforms&&null!=e.material?.uniforms[ce])e.material.uniforms[ce].value=c;else if(e instanceof l&&Array.isArray(e.material))for(const t of e.material)t.uniforms&&null!=t.uniforms[ce]&&(t.uniforms[ce].value=c);if(v.has(e))for(let t=0;t<e.children.length;t++)v.add(e.children[t]);else if(At(e)){w.push(e);for(let t=0;t<e.children.length;t++)v.add(e.children[t])}else e instanceof l&&(b.push(e),M.push(this.getGBufferPhaseMask(e.material)))}),v.clear(),this.phasedRenderPass.enabled=w.length>0,this.bloomPass.enabled=p,!0===this.options.occlusionCulling?.enabled){for(const e of this.occlusionClusters)e.update();this.hideOccluded(O)}this.prepareUpscalingFrame(),this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderDepthPrepass(),this.renderScene(nt.opaque),this.updateRenderedOcclusionClusters(),this.renderer.render(this.queryScene,this.camera),this.aoPass.output=te.OUTPUT.Off;for(const e of this.postProcessEffects)if(e.pass?.enabled&&this.usesShaderUniform(e.pass.material,ie)){m=!0;break}g&&(this.fquadCopySceneColor.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.fquadCopySceneColor.render(this.renderer)),m&&(this.fquadCopySceneDepth.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.renderer.setRenderTarget(this.sceneDepthRenderTarget),this.fquadCopySceneDepth.render(this.renderer)),(m||g)&&this.renderer.setRenderTarget(this.gRenderTarget),W.length,C.forEach(e=>e.visible=!0),B.forEach(e=>e.visible=!0),W.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=s),this.volumetricFogPass&&d?(this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1),this.updatePostProcessEffectUniforms(c);try{this.paused&&!r||!this.running||(this.render(o),this.finishUpscalingFrame(),this.showStats&&f?.endQuery(),this.showStats&&T(s)&&G(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}finally{this.finishUpscalingFrame(),r&&(this.needsPausedRender=!1)}n.end(),this.csm?.update(),_()};this.resumeAnimationLoop=()=>{I=!0,F=!1,!0===this.options.enableXR?this.renderer.setAnimationLoop(q):requestAnimationFrame(q)},!0===this.options.enableXR?this.renderer.setAnimationLoop(q):requestAnimationFrame(q)}collectGBufferRenderables(e,t=this.frameGBufferMeshes,s=this.frameGBufferPhaseMasks,i=this.frameUnsupportedGBufferObjects){t.length=0,s.length=0,i.length=0,xe(e,e=>{if(At(e))return i.push(e),!1;e instanceof l&&(t.push(e),s.push(this.getGBufferPhaseMask(e.material)))})}getGBufferPhaseMask(e){if(Array.isArray(e)){let t=0;for(let s=0;s<e.length;s++)t|=this.getGBufferPhaseMask(e[s]);return t}if(null==e||!1===e.visible)return 0;let t=this.gBufferPhaseMaskCache.get(e);if(null!=t)return t;if(!0===e.userData.isGBufferMaterial)return t=1<<nt.opaque|1<<nt.transparent,this.gBufferPhaseMaskCache.set(e,t),t;const s=this.usesShaderUniform(e,ie),a=this.usesShaderUniform(e,ue),n=this.usesShaderUniform(e,pe),r=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,o=s||a||n;return t=0,o||r||(t|=1<<nt.opaque),(o||r)&&(t|=1<<nt.transparent),this.gBufferPhaseMaskCache.set(e,t),t}getGBufferMaterialArray(e,t){let s=this.gBufferMaterialArrayCache.get(e);null==s&&(s={opaque:[],transparent:[]},this.gBufferMaterialArrayCache.set(e,s));const i=t===nt.opaque?s.opaque:s.transparent;i.length=e.length;for(let s=0;s<e.length;s++)i[s]=this.createGBufferMaterial(e[s],t,!1);return i}applyGBufferMaterials(e,t=this.frameGBufferMeshes,s=this.frameGBufferPhaseMasks,i=this.frameUnsupportedGBufferObjects){const a=this.appliedGBufferMeshes,n=this.originalGBufferMaterials,r=this.originalGBufferOnBeforeRender,o=this.hiddenGBufferObjects;a.length=0,n.length=0,r.length=0,o.length=0;for(let e=0;e<i.length;e++){const t=i[e];t.visible&&(o.push(t),t.visible=!1)}const l=1<<e;for(let i=0;i<t.length;i++){const h=t[i];if(!h.visible)continue;const c=h.material;if(0!==(s[i]&l)||0!==h.children.length)if(a.push(h),n.push(c),r.push(h.onBeforeRender),0!==(s[i]&l)){if(Array.isArray(c)){const t=this.getGBufferMaterialArray(c,e);h.material=t;for(let e=0;e<t.length;e++)this.initShadowUniform(h,t[e])}else{const t=this.createGBufferMaterial(c,e,e===nt.opaque&&this.isDepthPrepassEligibleMesh(h));h.material=t,this.initShadowUniform(h,t)}this.applyGBufferShadowUniformUpdater(h)}else h.material=ht;else o.push(h),h.visible=!1}}unapplyGBufferMaterials(){const e=this.appliedGBufferMeshes;for(let t=0;t<e.length;t++){const s=e[t];s.material=this.originalGBufferMaterials[t],s.onBeforeRender=this.originalGBufferOnBeforeRender[t]}const t=this.hiddenGBufferObjects;for(let e=0;e<t.length;e++)t[e].visible=!0;e.length=0,this.originalGBufferMaterials.length=0,this.originalGBufferOnBeforeRender.length=0,t.length=0}applyGBufferShadowUniformUpdater(e){const t=e.onBeforeRender;let s=this.gBufferShadowUpdaterCache.get(e);if(null==s){const i=this,a={original:t,wrapper:null};a.wrapper=(t,s,n,r,o,l)=>{a.original.call(e,t,s,n,r,o,l),i.initShadowUniform(e,o)},s=a,this.gBufferShadowUpdaterCache.set(e,s)}s.original=t,e.onBeforeRender=s.wrapper}initTextures(e=this.scene){e.traverse(e=>{if(e instanceof l)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)this._initMaterialTextures(e.material[t]);else this._initMaterialTextures(e.material)})}async initTexturesAsync(e=this.scene){const t=[];e.traverse(e=>{e instanceof l&&(Array.isArray(e.material)?t.push(...e.material):t.push(e.material))});let s=performance.now();for(const e of t)this._initiatedMaterialTextures.has(e)||(this._initMaterialTextures(e),performance.now()-s>=4&&(await new Promise(e=>setTimeout(e,0)),s=performance.now()))}_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 d){if(this._initiatedTextures.has(s.value))continue;this._initTexture(s.value),this._initiatedTextures.add(s.value)}}else for(const[t,s]of Object.entries(e))if(s instanceof d){if(this._initiatedTextures.has(s))continue;this._initTexture(s),this._initiatedTextures.add(s)}}_initTexture(e){const t=this.backendHandle;if(null==t){if("webgpu"!==this.requestedBackend||this.experimentalWebGpuFailed)throw new Error("Cannot initialize a texture before the rendering backend is available.")}else t.initTexture(e)}async compileAsync(e=this.scene){if(this.compileInProgress)return;if("webgpu"===this.requestedBackend&&!this.experimentalWebGpuFailed&&e instanceof i.Scene){this.compileInProgress=!0;try{if(await this.compileExperimentalWebGpu(e))return}finally{this.compileInProgress=!1}}this.renderer.setRenderTarget(this.gRenderTarget),this.compileInProgress=!0;const t=[],s=[],a=[];this.collectGBufferRenderables(e,t,s,a),this.applyGBufferMaterials(nt.opaque,t,s,a),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(nt.transparent,t,s,a),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.fquadCopySceneColor.mesh,this.fquadCopySceneColor.camera),this.renderer.setRenderTarget(this.sceneDepthRenderTarget),this.renderer.compileAsync(this.fquadCopySceneDepth.mesh,this.fquadCopySceneDepth.camera));const n=this.csm.lights[0]?.shadow.camera;null!=n&&(this.applyDepthMaterial(),await this.renderer.compileAsync(e,n),this.unapplyDepthMaterial()),this.compileInProgress=!1,this.renderer.setRenderTarget(null)}async compileExperimentalWebGpu(t){if(!(t instanceof i.Scene))throw new Error("Only THREE.Scene roots are supported by the WebGPU renderer.");if(!Je.supportsCamera(this.camera))throw new Error(`Unsupported camera type: ${this.camera?.type??"unknown"}`);const s={smaa:{quality:"high",edgeDetection:"color",threshold:.05,localContrastAdaptation:.35,cornerRounding:.15,sharpness:0},fxaa:!1,taa:!1,nativeUpscaling:!0===this.options.upscaling?.enabled&&"dlss"===$e(this.options.upscaling)&&{method:"dlss",mode:this.options.upscaling?.dlss?.mode??"quality"},...this.options.webgpuPostProcessing};let a=this.experimentalWebGpuBackend;if(null==a){const e=await this.acquireWebGpuBackend(s);if(null==e.backend)return this.fallbackToWebGlForUnavailableWebGpu(e.reason),!1;a=e.backend}this.experimentalWebGpuBackend=a;const n=e.experimentalWebGpuPresentationView,r=n!==this;return r&&n?.disposeExperimentalStaticDrawSets(),this.applyExperimentalWebGpuViewState(r),e.experimentalWebGpuPresentationView=this,await a.compile(t,this.camera),this.backendHandle=a,t===this.scene&&this.activateExperimentalStaticDrawSets(),this.attachRendererDomElement(),t!==this.scene||this.experimentalWebGpuCapabilityReported||(console.info(Xe(a.inspect(t,this.camera))),this.experimentalWebGpuCapabilityReported=!0),!0}async acquireWebGpuBackend(e){const t=JSON.stringify(e),s=await Je.probeAvailability();if(!1===s.available)return{backend:null,reason:s.reason};const i=await this.graphicsRuntime.acquire("webgpu-renderer",t,()=>Je.create(e,s.adapter));return this.experimentalWebGpuBackendPoolKey=t,{backend:i}}releaseExperimentalWebGpuBackend(){const e=this.experimentalWebGpuBackendPoolKey;this.experimentalWebGpuBackendPoolKey=null,null!=e&&this.graphicsRuntime.release("webgpu-renderer",e,e=>e.destroy())}applyExperimentalWebGpuViewState(e){const t=this.experimentalWebGpuBackend;null!=t&&(e&&t.resetViewHistory(),t.setDynamicBatchingEnabled(this.experimentalWebGpuDynamicBatchingEnabled),t.setTiledLightingEnabled(this.experimentalWebGpuTiledLightingEnabled),t.setGTAOOptions({...this.ambientOcclusionSettings.options,enabled:this.ambientOcclusionSettings.enabled}),t.setDirectionalShadowOptions(this.webgpuDirectionalShadowOptions.enabled,this.webgpuDirectionalShadowOptions.mapSize),this.syncWebGpuOutlineState(t),this.syncExperimentalWebGpuPostProcessEffects(),t.setProfilingEnabled(this._showStats||this._profilingEnabled),t.setWorldEnvironment(this.worldEnvironment),t.setSize(this.container.clientWidth,this.container.clientHeight,this.getBasePixelRatio(),this.getEffectiveResolutionScale()))}syncWebGpuOutlineState(e=this.experimentalWebGpuBackend){null!=e&&(e.setEnableOutlines(this.outlinesEnabled),e.setSelectedObjects(this.selectedOutlineObjects),e.setSelectedObjectInstances(this.experimentalWebGpuSelectedObjectInstances))}applyDepthMaterial(){const e=this.depthMaterialCachedMaterials;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=_t:t.material=null)})}unapplyDepthMaterial(){this.depthMaterialCachedMaterials.forEach((e,t)=>{t.material=e})}renderScene(e){if(!this.running||this.paused&&!this.needsPausedRender)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!==nt.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)}if(e===nt.opaque){const e=this.appliedGBufferMeshes;for(let t=0;t<e.length;t++){const s=e[t],i=this.originalGBufferMaterials[t];!Array.isArray(i)&&!Array.isArray(s.material)&&i instanceof p&&this.updateLightUniformValues(s.material,i)}}this.unapplyGBufferMaterials(),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){if(e.mapping===i.CubeUVReflectionMapping)return e;if(null!=this.backendHandle)return this.backendHandle.getEnvironmentTexture(e);if("webgpu"===this.requestedBackend&&!this.experimentalWebGpuFailed)return e;throw new Error("Cannot prepare an environment texture before the rendering backend is available.")}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.experimentalWebGpuBackend?.setPostProcessState(null),"webgpu"===this.activeBackend?void this.experimentalWebGpuBackend?.setWorldEnvironment(this.worldEnvironment):(this.applyWorldEnvironmentToWebGl(),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=vt(e.globalSaturation,1,1,1),e.globalContrast=vt(e.globalContrast,1,1,1),e.globalGamma=vt(e.globalGamma,1,1,1),e.globalGain=vt(e.globalGain,1,1,1),e.globalOffset=vt(e.globalOffset,0,0,0),e.shadowsSaturation=vt(e.shadowsSaturation,1,1,1),e.shadowsContrast=vt(e.shadowsContrast,1,1,1),e.shadowsGamma=vt(e.shadowsGamma,1,1,1),e.shadowsGain=vt(e.shadowsGain,1,1,1),e.shadowsOffset=vt(e.shadowsOffset,0,0,0),e.shadowsMax=.09,e.midtonesSaturation=vt(e.midtonesSaturation,1,1,1),e.midtonesContrast=vt(e.midtonesContrast,1,1,1),e.midtonesGamma=vt(e.midtonesGamma,1,1,1),e.midtonesGain=vt(e.midtonesGain,1,1,1),e.midtonesOffset=vt(e.midtonesOffset,0,0,0),e.highlightsSaturation=vt(e.highlightsSaturation,1,1,1),e.highlightsContrast=vt(e.highlightsContrast,1,1,1),e.highlightsGamma=vt(e.highlightsGamma,1,1,1),e.highlightsGain=vt(e.highlightsGain,1,1,1),e.highlightsOffset=vt(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;null!=this.worldEnvironment&&(e.envTexture=this.worldEnvironment.source,e.envIntensity=this.worldEnvironment.intensity);let t,s=!1;if(null==this.camera)return;const a=this.camera.getWorldPosition(Rt);let n=[];for(const r of this.postProcessVolumes){if(!mt(r.object))continue;let o=r.blendWeight??1;const l=r.distanceToPoint(a);l>r.blendRadius||(r.blendRadius>0&&(o*=Pe(1-l/r.blendRadius,0,1)),o>1&&(o=1),o>0&&(n.push(r),void 0!==r.settings.tonemapMapping&&(e.tonemapMapping=r.settings.tonemapMapping),void 0!==r.settings.tonemapExposure&&(e.tonemapExposure=i.MathUtils.lerp(e.tonemapExposure,r.settings.tonemapExposure,o)),void 0!==r.settings.envTexture&&(e.envTexture=r.settings.envTexture),void 0!==r.settings.envIntensity&&(e.envIntensity=i.MathUtils.lerp(e.envIntensity,r.settings.envIntensity,o)),void 0!==r.settings.vignetteIntensity&&(e.vignetteIntensity=i.MathUtils.lerp(e.vignetteIntensity,r.settings.vignetteIntensity,o)),void 0!==r.settings.colorTint&&void 0!==r.settings.colorTintIntensity&&r.settings.colorTintIntensity>0&&(e.colorTint=e.colorTint.lerp(r.settings.colorTint,o)),void 0!==r.settings.colorTintIntensity&&(e.colorTintIntensity=i.MathUtils.lerp(e.colorTintIntensity,r.settings.colorTintIntensity,o)),void 0!==r.settings.depthFocus&&(s=!0,e.depthFocus=void 0!==e.depthFocus?i.MathUtils.lerp(e.depthFocus,r.settings.depthFocus,o):r.settings.depthFocus),void 0!==r.settings.depthAperture&&(s=!0,e.depthAperture=void 0!==e.depthAperture?i.MathUtils.lerp(e.depthAperture,r.settings.depthAperture,o):r.settings.depthAperture),void 0!==r.settings.depthMaxBlur&&(s=!0,e.depthMaxBlur=void 0!==e.depthMaxBlur?i.MathUtils.lerp(e.depthMaxBlur,r.settings.depthMaxBlur,o):r.settings.depthMaxBlur),void 0!==r.settings.temperature&&(e.temperature=i.MathUtils.lerp(e.temperature,r.settings.temperature,o)),void 0!==r.settings.temperatureTint&&(e.temperatureTint=i.MathUtils.lerp(e.temperatureTint,r.settings.temperatureTint,o)),void 0!==r.settings.globalSaturation&&e.globalSaturation.lerp(r.settings.globalSaturation,o),void 0!==r.settings.globalContrast&&e.globalContrast.lerp(r.settings.globalContrast,o),void 0!==r.settings.globalGamma&&e.globalGamma.lerp(r.settings.globalGamma,o),void 0!==r.settings.globalGain&&e.globalGain.lerp(r.settings.globalGain,o),void 0!==r.settings.globalOffset&&e.globalOffset.lerp(r.settings.globalOffset,o),void 0!==r.settings.shadowsSaturation&&e.shadowsSaturation.lerp(r.settings.shadowsSaturation,o),void 0!==r.settings.shadowsContrast&&e.shadowsContrast.lerp(r.settings.shadowsContrast,o),void 0!==r.settings.shadowsGamma&&e.shadowsGamma.lerp(r.settings.shadowsGamma,o),void 0!==r.settings.shadowsGain&&e.shadowsGain.lerp(r.settings.shadowsGain,o),void 0!==r.settings.shadowsOffset&&e.shadowsOffset.lerp(r.settings.shadowsOffset,o),void 0!==r.settings.shadowsMax&&(e.shadowsMax=i.MathUtils.lerp(e.shadowsMax,r.settings.shadowsMax,o)),void 0!==r.settings.midtonesSaturation&&e.midtonesSaturation.lerp(r.settings.midtonesSaturation,o),void 0!==r.settings.midtonesContrast&&e.midtonesContrast.lerp(r.settings.midtonesContrast,o),void 0!==r.settings.midtonesGamma&&e.midtonesGamma.lerp(r.settings.midtonesGamma,o),void 0!==r.settings.midtonesGain&&e.midtonesGain.lerp(r.settings.midtonesGain,o),void 0!==r.settings.midtonesOffset&&e.midtonesOffset.lerp(r.settings.midtonesOffset,o),void 0!==r.settings.highlightsSaturation&&e.highlightsSaturation.lerp(r.settings.highlightsSaturation,o),void 0!==r.settings.highlightsContrast&&e.highlightsContrast.lerp(r.settings.highlightsContrast,o),void 0!==r.settings.highlightsGamma&&e.highlightsGamma.lerp(r.settings.highlightsGamma,o),void 0!==r.settings.highlightsGain&&e.highlightsGain.lerp(r.settings.highlightsGain,o),void 0!==r.settings.highlightsOffset&&e.highlightsOffset.lerp(r.settings.highlightsOffset,o),void 0!==r.settings.highlightsMin&&(e.highlightsMin=i.MathUtils.lerp(e.highlightsMin,r.settings.highlightsMin,o)),void 0!==r.settings.lut&&(t=r.settings.lut),void 0!==r.settings.lutIntensity&&(e.lutIntensity=i.MathUtils.lerp(e.lutIntensity,r.settings.lutIntensity,o))))}if(0===n.length)return this.experimentalWebGpuBackend?.setPostProcessState(null),"webgpu"===this.activeBackend?void this.experimentalWebGpuBackend?.setWorldEnvironment(this.worldEnvironment):(this.applyWorldEnvironmentToWebGl(),this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure));if("webgpu"===this.activeBackend){const t=yt(Et,e.temperature,e.temperatureTint),i=e=>[e.x,e.y,e.z],a=n.some(e=>{return void 0!==(t=e.settings).tonemapMapping||void 0!==t.tonemapExposure||void 0!==t.vignetteIntensity||void 0!==t.colorTintIntensity||void 0!==t.temperature||void 0!==t.temperatureTint||void 0!==t.globalSaturation||void 0!==t.globalContrast||void 0!==t.globalGamma||void 0!==t.globalGain||void 0!==t.globalOffset||void 0!==t.shadowsSaturation||void 0!==t.shadowsContrast||void 0!==t.shadowsGamma||void 0!==t.shadowsGain||void 0!==t.shadowsOffset||void 0!==t.shadowsMax||void 0!==t.midtonesSaturation||void 0!==t.midtonesContrast||void 0!==t.midtonesGamma||void 0!==t.midtonesGain||void 0!==t.midtonesOffset||void 0!==t.highlightsSaturation||void 0!==t.highlightsContrast||void 0!==t.highlightsGamma||void 0!==t.highlightsGain||void 0!==t.highlightsOffset||void 0!==t.highlightsMin;var t}),r=n.some(e=>void 0!==e.settings.tonemapMapping||void 0!==e.settings.tonemapExposure);return this.experimentalWebGpuBackend?.setPostProcessState({enabled:a,exposure:r?e.tonemapExposure:1,toneMapping:r?xt(e.tonemapMapping):"none",vignetteIntensity:e.vignetteIntensity,whiteBalance:i(t),tint:[e.colorTint.r,e.colorTint.g,e.colorTint.b],tintIntensity:e.colorTintIntensity,saturation:i(e.globalSaturation),contrast:i(e.globalContrast),gamma:i(e.globalGamma),gain:i(e.globalGain),offset:i(e.globalOffset),shadows:{saturation:i(e.shadowsSaturation),contrast:i(e.shadowsContrast),gamma:i(e.shadowsGamma),gain:i(e.shadowsGain),offset:i(e.shadowsOffset)},midtones:{saturation:i(e.midtonesSaturation),contrast:i(e.midtonesContrast),gamma:i(e.midtonesGamma),gain:i(e.midtonesGain),offset:i(e.midtonesOffset)},highlights:{saturation:i(e.highlightsSaturation),contrast:i(e.highlightsContrast),gamma:i(e.highlightsGamma),gain:i(e.highlightsGain),offset:i(e.highlightsOffset)},shadowsMax:e.shadowsMax,highlightsMin:e.highlightsMin,depthFocus:s?e.depthFocus:void 0,depthAperture:s?e.depthAperture:void 0,depthMaxBlur:s?e.depthMaxBlur:void 0}),void this.experimentalWebGpuBackend?.setWorldEnvironment(null!=e.envTexture?{source:e.envTexture,intensity:e.envIntensity}:this.worldEnvironment)}const r=e.vignetteIntensity>Gt,o=(l=e.temperature,c=e.temperatureTint,!St(l,6500)||!St(c,0));var l,c;const p=(u=e.colorTint,e.colorTintIntensity>Gt&&(!St(u.r,1)||!St(u.g,1)||!St(u.b,1)));var u;const d=!(Pt((m=e).globalSaturation,1,1,1)&&Pt(m.globalContrast,1,1,1)&&Pt(m.globalGamma,1,1,1)&&Pt(m.globalGain,1,1,1)&&Pt(m.globalOffset,0,0,0)&&Pt(m.shadowsSaturation,1,1,1)&&Pt(m.shadowsContrast,1,1,1)&&Pt(m.shadowsGamma,1,1,1)&&Pt(m.shadowsGain,1,1,1)&&Pt(m.shadowsOffset,0,0,0)&&Pt(m.midtonesSaturation,1,1,1)&&Pt(m.midtonesContrast,1,1,1)&&Pt(m.midtonesGamma,1,1,1)&&Pt(m.midtonesGain,1,1,1)&&Pt(m.midtonesOffset,0,0,0)&&Pt(m.highlightsSaturation,1,1,1)&&Pt(m.highlightsContrast,1,1,1)&&Pt(m.highlightsGamma,1,1,1)&&Pt(m.highlightsGain,1,1,1)&&Pt(m.highlightsOffset,0,0,0));var m;const g=o||p||d||r,f=g&&e.tonemapMapping!==i.NoToneMapping,b=null!=t&&e.lutIntensity>Gt;g?(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,g?(this.colorPass.whiteBalanceEnabled=o,this.colorPass.whiteBalanceScale=o?yt(Et,e.temperature,e.temperatureTint):Et.set(1,1,1),this.colorPass.vignetteIntensity=e.vignetteIntensity,this.colorPass.vignetteEnabled=r,this.colorPass.colorTintEnabled=p,this.colorPass.colorTint=e.colorTint,this.colorPass.colorTintIntensity=e.colorTintIntensity,this.colorPass.colorGradingEnabled=d,this.colorPass.toneMapping=e.tonemapMapping,this.colorPass.toneMappingEnabled=f,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 h?(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=b,b&&(null!=t&&(t.flipY=!0,t.generateMipmaps=!1),this.lutPass.lut=t,this.lutPass.intensity=e.lutIntensity)}updatePostProcessEffectUniforms(e){if(!this.webGlInitialized||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 h?(t.cameraNear=this.camera.near,t.cameraFar=this.camera.far):(t.cameraNear=void 0,t.cameraFar=void 0),t.depthTexture=this.sceneDepthRenderTarget.texture,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(this.requireInitializedBackend("render"),"webgpu"===this.activeBackend){const e=this.experimentalWebGpuBackend;return void(null!=e&&Je.supportsCamera(this.camera)&&(this.syncExperimentalWebGpuCascades(),e.setRenderGraphExtensions(this.experimentalWebGpuRenderGraphExtensions),e.setPresentationExtensions(this.webGpuPresentationExtensions),e.render(this.scene,this.camera,this.simulationTime)))}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 l&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,bt)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=ve(this.scene,e=>e instanceof l&&!0===e.material?.userData?.hasBloom)}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.sceneDepthRenderTarget.texture,this.camera instanceof h&&(null!=e.uniforms[ne]&&(e.uniforms[ne].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 R&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof R&&(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[re]&&e.uniforms[re].value.set(this.gRenderTarget.width,this.gRenderTarget.height)}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[pe].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 R&&t.depthWrite&&t.alphaTest>0))return;let s=this._customDepthMaterialCache.get(t);if(null==s){const e=De(Ue);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new R({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}};ut.activeView=null,ut.experimentalWebGpuPresentationView=null,ut=e=t([se(),s("design:paramtypes",[HTMLElement,Object])],ut);export{ut as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const dt=.05;function mt(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}function gt(e,t){return e.priority!==t.priority?e.priority-t.priority:e.id-t.id}function ft(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)}})};new i.Box3;const bt=new i.Frustum,Mt=new i.Box3,wt=new i.Matrix4;export function isObjectInFrustum(e,t){const s=Mt.setFromObject(e);return t.intersectsBox(s)}function vt(e,t,s,a){return null==e?new i.Vector3(t,s,a):e.set(t,s,a)}function xt(e){switch(e){case i.LinearToneMapping:return"linear";case i.ReinhardToneMapping:return"reinhard";case i.CineonToneMapping:return"cineon";case i.ACESFilmicToneMapping:return"aces";case i.AgXToneMapping:return"agx";case i.NeutralToneMapping:return"neutral";default:return"none"}}function Pt(e,t,s,i){return null!=e&&St(e.x,t)&&St(e.y,s)&&St(e.z,i)}function yt(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 Ct.set(s,i,a)}(t),a=1+.2*Pe(s,-1,1),n=i.x,r=i.y*a,o=i.z,l=Math.max(r,1e-4);return e.set(1/Math.max(n/l,1e-4),1/Math.max(r/l,1e-4),1/Math.max(o/l,1e-4)),e}function St(e,t,s=Gt){return Math.abs(e-t)<=s}function Tt(e,t){return null!=e&&Number.isFinite(e)&&e>0?e:t}const Gt=1e-4,Rt=new i.Vector3,Et=new i.Vector3(1,1,1),Ct=new i.Vector3(1,1,1);const Bt=new o,Wt=new m;function Ot(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 Ut=new R({outputs:[j(0,0,0,0),j(0,0,0,0),A(D("white"),Ve(4))],transparent:!0}),Dt=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});Ut.depthWrite=!1;new l(new i.BoxGeometry(4,4,4),Dt);function At(e){return e instanceof i.Sprite||e.isPoints||e.isTransformControls||e.isTransformControlsGizmo||e instanceof l&&kt(e,e.material)}function kt(e,t){return null==t||(Array.isArray(t)?t.some(t=>kt(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof R))}class It 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 n=e.autoClear;e.autoClear=!1;const r=this.scene.matrixWorldAutoUpdate,o=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const c=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),this.cachedVisibility.length=0;let p=0,u=this.toRender;if(u.length=0,this.scene.traverseVisible(e=>{const t=At(e);e instanceof l&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(p++,u.push(e))}),p>0)for(const t of u)e.render(t,this.camera);this.cachedVisibility.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=n,s.depthTexture=c,this.scene.matrixWorldAutoUpdate=r,this.scene.matrixAutoUpdate=o,e.shadowMap.autoUpdate=h}}class Ft extends Le{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const Vt=["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"],jt=["directionalShadowMap","directionalShadowMatrix","pointLightShadows","pointShadowMap","pointShadowMatrix","spotLightShadows","spotShadowMap"],Lt=B("fogColor");export class FogNode extends H{constructor(e,t=Lt){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),n=e.get(C("fogFar")),r=e.get(C("fogNear")),o=e.get(C("fogDensity")),l=e.get(I(k.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( ${r}, ${n}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${a}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}const _t=new i.MeshDepthMaterial({depthPacking:i.RGBADepthPacking});/*
|
|
1
|
+
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{observeElementIntersection as a}from"./rendering/intersection-observer.js";import{Color as n,Material as r,Matrix4 as o,Mesh as l,PerspectiveCamera as h,ShaderChunk as c,ShaderMaterial as p,WebGLRenderTarget as u,Texture as d,Euler as m,MeshStandardMaterial as g}from"three";import{CopyShader as f,EffectComposer as b,FXAAShader as w,GammaCorrectionShader as M,LUTPass as v,RenderPass as x,ShaderPass as P}from"three-stdlib";import{CSMShader as y,CSMUtil as S}from"./csm.js";import{colorToNormal as T,float as G,NodeShaderMaterial as R,standardMaterial as E,uniformFloat as B,uniformVec3 as C,toonMaterial as W,lambertMaterial as O,normalize as U,rgb as D,rgba as A,transformed as k,varying as I,varyingAttributes as F,varyingTransformed as V,vec4 as j,BooleanExpression as L,select as _,ifDefApply as z,uniformSampler2d as q,RgbaNode as H,mix as N,attributes as $,uniformVec2 as Q,min 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 Z}from"three/examples/jsm/csm/CSM.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 ne,resolutionUniformName as re,sceneNormalUniformName as oe,screenUV as le,supportsDepthTextureExtension as he}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as ce}from"./shader-nodes/time.js";import{aoMapUniformName as pe,sceneMapUniformName as ue}from"./shader-nodes/scene-sample.js";import{waterVolumeCameraPositionUniformName as de,waterVolumeEnabledUniformName as me,waterVolumeInverseViewProjectionUniformName as ge,waterVolumeWorldToLocalUniformName as fe}from"./shader-nodes/water-volume.js";import{DepthPass as be}from"./utils/three/depth-pass.js";import{GPUStatsPanel as we}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as Me}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as ve,traverseVisibleStop as xe}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 Se,PostProcessEffectRegistration as Te,postProcessEffectStages as Ge,sanitizePostProcessEffectPriority as Re,sanitizePostProcessEffectStage as Ee}from"./rendering/post-process-effect.js";import{SSRPass as Be}from"./rendering/ssr/SSRPass.js";import{SSRShader as Ce}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as We}from"./rendering/fog/volumetric-fog-pass.js";import{UnrealBloomPass as Oe}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Ue}from"./shader-nodes/depth.js";import{packDepthToRGBA as De}from"three-shader-graph";import{FogVolumeObject as Ae}from"./rendering/fog/fog-volume-object.js";import{ParallaxStandardMaterial as ke}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as Ie}from"./shader-nodes/pom.js";import{FullScreenQuad as Fe}from"three-stdlib";import{edgeDepthEffect as Ve}from"./shader-nodes/effects.js";import{decalDiscard as je}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{resolvePostProcessMaterial as ze}from"./shader/post-process-shader.js";import{applyUvTiling as qe}from"./shader/uv-nodes.js";import{createPlaceholderTexture as He}from"./utils/three/placeholder-texture.js";import{getTemporalUpscalingJitter as Ne,getUpscalingMethod as $e,UpscaleOutputPass as Qe}from"./rendering/upscaling-pass.js";import{ExperimentalWebGpuBackend as Je,formatWebGpuSceneCapabilitySummary as Xe}from"./rendering/webgpu-experimental-backend.js";import{WebGlBackend as Ye}from"./rendering/webgl-backend.js";import{defaultGraphicsRuntime as Ke}from"./rendering/graphics-runtime.js";export{GraphicsRuntime}from"./rendering/graphics-runtime.js";function Ze(e){return{enabled:e?.enabled??!0,mapSize:Math.max(1,Math.floor(e?.mapSize??2048)),cascadeCount:Math.max(1,Math.min(4,Math.floor(e?.cascadeCount??4))),maxDistance:Math.max(1,e?.maxDistance??80)}}const et=new i.Vector3,tt=new i.Matrix4,st=(new i.Matrix4).set(1,0,0,0,0,1,0,0,0,0,.5,.5,0,0,0,1);S.patchSetupMaterial();const it=document.createElement("div");it.style.position="absolute",it.style.left="50%",it.style.top="50%",it.style.color="black",it.style.zIndex="999";(new i.Layers).set(9);new i.MeshBasicMaterial({color:"black"});const at=new i.MeshDepthMaterial;var nt;at.depthPacking=i.RGBADepthPacking,at.blending=i.NoBlending,at.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(nt||(nt={}));const rt=(()=>{const e=new Uint8Array([255,255,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),ot=(()=>{const e=new Uint8Array([0,0,0,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),lt=(()=>{const e=new Uint8Array([128,128,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),ht=new R({color:G(0),position:j(G(0))});ht.visible=!1;const ct=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let pt=0;let ut=e=class{get activeBackend(){return this.backendHandle?.kind??null}get canvas(){return this.backendHandle?.canvas??null}get initialized(){return null!=this.backendHandle}get requestedBackend(){return"webgpu"===(e=this.options.backend)||"webgpu-experimental"===e?"webgpu":"webgl";var e}get vfxBackendPreference(){return this.options.webgpuVfx??"cpu"}get webgpuVfxInstancesPerTemplate(){return Math.max(1,Math.floor(this.options.webgpuVfxInstancesPerTemplate??128))}get webgpuVfxTemplateMemoryBudgetBytes(){return 1024*Math.max(1,this.options.webgpuVfxTemplateMemoryBudgetMiB??512)*1024}get webgpuVfxWorldMemoryBudgetBytes(){return 1024*Math.max(1,this.options.webgpuVfxWorldMemoryBudgetMiB??1024)*1024}get webgpuVfxColdTemplateSeconds(){return Math.max(0,this.options.webgpuVfxColdTemplateSeconds??30)}get webGpuDevice(){return this.experimentalWebGpuBackend?.getDevice()??null}get experimentalWebGpuDevice(){return this.webGpuDevice}registerExperimentalStaticDrawSet(e,t,s=!1){if("webgpu"!==this.requestedBackend)return()=>{};const i={root:e,label:t,allowUnsortedLateDraws:s,sourceWasVisible:e.visible,staticDrawSet:null};return this.experimentalStaticDrawSetRegistrations.add(i),this.activateExperimentalStaticDrawSets(),()=>{this.experimentalStaticDrawSetRegistrations.delete(i)&&(i.staticDrawSet?.dispose(),null!=i.staticDrawSet&&(i.root.visible=i.sourceWasVisible),i.staticDrawSet=null)}}registerExperimentalWebGpuRenderGraphExtension(e){return"webgpu"!==this.requestedBackend?()=>{}:(this.experimentalWebGpuRenderGraphExtensions.add(e),()=>{this.experimentalWebGpuRenderGraphExtensions.delete(e)})}get webGlRenderer(){return"webgl"===this.activeBackend?this.renderer:null}registerWebGpuRenderGraphExtension(e){return this.registerExperimentalWebGpuRenderGraphExtension(e)}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++)}createAoblendQuad(){const e=j(1),t=He(),s=q("tAlphaTest",t).sample(le).a,a=q("tAO",t).sample(le),n=_(s.lt(.05),a,J(j(1,1,1,1),a.addScalar(.4))),r=new R({outputs:[n,e,e],transparent:!0});r.depthWrite=!1,r.depthTest=!1,r.blending=i.MultiplyBlending;return new Fe(r)}setPaused(e){this.paused=e}setResolutionScale(e){const t=Tt(e,1);St(t,this.resolutionScale)||(this.resolutionScale=t,this.dynamicResolutionScale=t,this.dynamicResolutionLastAdjustmentAt=0,this.resetDynamicResolutionAverage(),this.resizeRender(!0))}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()))}getClientSize(e=new i.Vector2){return e.set(Math.max(1,this.previousClientWith??1),Math.max(1,this.previousClientHeight??1))}isUpscalingEnabled(){return!0===this.options.upscaling?.enabled&&!0!==this.options.enableXR}isTemporalUpscalingEnabled(){if(!this.isUpscalingEnabled())return!1;const e=$e(this.options.upscaling);return"temporal"===e||"dlss"===e}resetUpscalingHistory(){this.hasPreviousTemporalViewProjection=!1,this.upscaleOutputPass?.resetHistory(),this.experimentalWebGpuBackend?.resetTemporalHistory()}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=Tt(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 h?(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=Tt(this.maxPixelRatio,1),t=Tt(window.devicePixelRatio,1);return Math.min(e,t)}getBaseResolutionScale(){return Tt(this.resolutionScale,1)}getDynamicResolutionMinScale(){const e=this.getBaseResolutionScale(),t=Tt(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(),n=Pe(this.dynamicResolutionScale,a,i);St(n,this.dynamicResolutionScale)||(this.dynamicResolutionScale=n);const r=Tt(s.targetFps,60),o=1e3/(null!=this.fpsCap?Math.min(r,this.fpsCap):r),l=1e3*e;this.dynamicResolutionFrameTimeAverage=null==this.dynamicResolutionFrameTimeAverage?l:.9*this.dynamicResolutionFrameTimeAverage+.1*l,this.dynamicResolutionFrameSamples++;const h=Math.max(1,Math.floor(Tt(s.sampleFrames,20)));if(this.dynamicResolutionFrameSamples<h)return;const c=Tt(s.decreaseCooldown,500),p=Tt(s.increaseCooldown,2e3),u=Tt(s.decreaseStep,.05),d=Tt(s.increaseStep,.025),m=this.dynamicResolutionFrameTimeAverage;let g=n;m>1.12*o&&n>a&&t-this.dynamicResolutionLastAdjustmentAt>=c?g=Math.max(a,n-u):m<.85*o&&n<i&&t-this.dynamicResolutionLastAdjustmentAt>=p&&(g=Math.min(i,n+d)),St(g,n)||(this.dynamicResolutionScale=g,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;if(this.previousClientWith=t,this.previousClientHeight=s,this.previousRenderPixelRatio=i,this.previousPresentationPixelRatio=a,this.camera instanceof h&&(this.camera.aspect=t/s,this.camera.updateProjectionMatrix()),!this.webGlInitialized)return this.experimentalWebGpuBackend?.setSize(t,s,this.getBasePixelRatio(),this.getEffectiveResolutionScale()),this.resetDynamicResolutionAverage(),void this.resetUpscalingHistory();this.renderer.setPixelRatio(a),this.renderer.setSize(t,s),this.composer.setPixelRatio(i),this.composer.setSize(t,s);const n=t*i,r=s*i;this.dofPass.setSize(n,r),this.fxaaPass.setSize(n,r),this.fxaaPass.uniforms.resolution.value.set(1/n,1/r),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.sceneDepthRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(),this.sceneDepthRenderTarget=this.createSceneDepthRenderTarget(),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0,this.experimentalWebGpuBackend?.setSize(t,s,this.getBasePixelRatio(),this.getEffectiveResolutionScale()),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)}}addWaterPostProcessVolume(e){this.waterPostProcessVolumes.includes(e)||this.waterPostProcessVolumes.push(e)}removeWaterPostProcessVolume(e){const t=this.waterPostProcessVolumes.indexOf(e);t>=0&&this.waterPostProcessVolumes.splice(t,1)}updateUnderwaterPostProcessing(){if(null==this.camera)return;const e=this.camera.getWorldPosition(et),t=this.waterPostProcessVolumes.filter(e=>e.underwater.enabled&&mt(e.object)).sort((e,t)=>t.underwater.priority-e.underwater.priority),s=t.find(t=>t.containsWaterPoint(e))??null,i=s??t.find(t=>null!=t.getWaterPostProcessWorldToLocal&&!0===t.isWaterPostProcessRelevant?.(e,t.underwater.transitionDistance))??null;this.activeWaterPostProcessVolume=i;const a=i?.underwater.postProcessMaterial;let n=null;if(!0===a?.isShaderMaterial&&(n=this.underwaterPostProcessEffects.get(a)??null,null==n&&(n=this.addPostProcessEffect(a,{stage:"beforeFog",priority:-100,enabled:!1}),this.underwaterPostProcessEffects.set(a,n))),n!==this.activeUnderwaterPostProcessEffect&&(null!=this.activeUnderwaterPostProcessEffect&&(this.activeUnderwaterPostProcessEffect.enabled=!1),this.activeUnderwaterPostProcessEffect=n),null!=n){n.enabled=null!=i;const t=n.material,a=t.uniforms[fe],r=t.uniforms[de],o=t.uniforms[me],l=t.uniforms[ge];if(null!=l){const e="webgpu"===this.activeBackend?tt.copy(st).multiply(this.camera.projectionMatrix):this.camera.projectionMatrix;l.value.copy(e).multiply(this.camera.matrixWorldInverse).invert()}null!=i?.getWaterPostProcessWorldToLocal&&null!=a?(i.getWaterPostProcessWorldToLocal(a.value,e),r?.value.copy(e),null!=o&&(o.value=1)):null!=o&&(o.value=null!=s?-1:0)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}addPostProcessEffect(e,t={}){const s=ze(e),i={id:++this.postProcessEffectId,material:s,pass:this.webGlInitialized?new Se(s):null,enabled:t.enabled??!0,priority:Re(t.priority),stage:Ee(t.stage)};return null!=i.pass&&(i.pass.enabled=i.enabled),this.postProcessEffects.push(i),this.refreshPostProcessEffectPassOrder(),new Te(this,i)}removePostProcessEffectEntry(e){const t=e,s=this.postProcessEffects.indexOf(t);-1!==s&&(this.postProcessEffects.splice(s,1),null!=t.pass&&(this.composer.removePass(t.pass),t.pass.dispose()),this.syncExperimentalWebGpuPostProcessEffects())}refreshPostProcessEffectPassOrder(){if(this.webGlInitialized){for(const e of this.postProcessEffects)e.pass??(e.pass=new Se(e.material)),e.pass.enabled=e.enabled,this.composer.removePass(e.pass);for(const e of Ge){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(gt);for(let e=0;e<i.length;e++)this.composer.insertPass(i[e].pass,s+e)}this.syncExperimentalWebGpuPostProcessEffects()}else this.syncExperimentalWebGpuPostProcessEffects()}syncExperimentalWebGpuPostProcessEffects(){this.experimentalWebGpuBackend?.setPostProcessEffects(this.postProcessEffects)}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.backendHandle=null,this.webGlBackend=null,this.experimentalWebGpuBackend=null,this.experimentalWebGpuBackendPoolKey=null,this.experimentalWebGpuFailed=!1,this.webGpuRuntimeErrorReported=!1,this.experimentalWebGpuCapabilityReported=!1,this.experimentalWebGpuTiledLightingEnabled=!0,this.experimentalWebGpuDynamicBatchingEnabled=!0,this.ambientOcclusionSettings={enabled:!1,blendIntensity:1,options:{}},this.experimentalWebGpuSelectedObjectInstances=[],this.outlinesEnabled=!1,this.selectedOutlineObjects=[],this.experimentalStaticDrawSetRegistrations=new Set,this.experimentalWebGpuRenderGraphExtensions=new Set,this.webGpuPresentationExtensions=new Set,this.worldEnvironment=null,this.isIntersecting=!1,this.stopIntersectionObservation=null,this.needsPausedRender=!1,this.wakePausedRenderer=null,this.resumeAnimationLoop=null,this.windowVisible=!0,this.queryScene=new i.Scene,this.running=!0,this.paused=!1,this._fpsCap=null,this.fpsCapRevision=0,this.postProcessVolumes=[],this.waterPostProcessVolumes=[],this.underwaterPostProcessEffects=new Map,this.activeUnderwaterPostProcessEffect=null,this.activeWaterPostProcessVolume=null,this.postProcessSettings={},this.baseToneMapping=i.NoToneMapping,this.baseToneMappingExposure=1,this.csmUpdateInvervals=this.options.shadows?.cascadeUpdateIntervals,this.webgpuDirectionalShadowOptions={enabled:!0,mapSize:2048,cascadeCount:4,maxDistance:80},this._id=pt++,this.postProcessEffectId=0,this.postProcessEffects=[],this.occlusionClusters=[],this.simulationTime=0,this.simulationTimeScale=1,this.lightProbeIntensity=2,this.resolutionScale=1,this.maxPixelRatio=ct?1:window.devicePixelRatio,this.dynamicResolutionScale=1,this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0,this.dynamicResolutionLastAdjustmentAt=0,this.upscaleOutputPass=null,this.unjitteredProjectionMatrix=new o,this.temporalJitter=new i.Vector2,this.temporalJitterUv=new i.Vector2,this.currentUnjitteredViewProjectionMatrix=new o,this.currentViewProjectionMatrix=new o,this.currentViewProjectionMatrixInverse=new o,this.previousViewProjectionMatrix=new o,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)this.needsPausedRender=!0,this.wakePausedRenderer?.();else try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.webGlInitialized=!1,this.onLoopCallbacks=[],this.stats=new ee,this.webGpuPassStatsDom=function(){const e=document.createElement("div");return e.dataset.hologyWebGpuPassStats="",e.setAttribute("aria-hidden","true"),e.style.cssText=["position:absolute","top:52px","left:12px","z-index:10000","width:min(520px,calc(100% - 24px))","pointer-events:none","color:white","font:12px/1.2 Arial,Helvetica,sans-serif","text-shadow:0 1px 2px black,0 0 3px black"].join(";"),e}(),this.webGpuVisibilityStatsDom=function(){const e=document.createElement("div");return e.style.cssText=["margin-bottom:10px","padding-bottom:6px","border-bottom:1px solid rgba(255,255,255,.4)"].join(";"),e.textContent="GPU visibility: awaiting readback",e}(),this.webGpuPassStatsRows=[],this._showStats=!1,this._profilingEnabled=!1,this.gbufferMaterialCache=new Map,this.gbufferDepthPrepassMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.depthPrepassMaterialCache=new WeakMap,this.depthPrepassCachedMaterials=new Map,this.depthPrepassCachedVisibility=[],this.frameGBufferMeshes=[],this.frameGBufferPhaseMasks=[],this.frameUnsupportedGBufferObjects=[],this.frameGBufferExcludedObjects=new Set,this.appliedGBufferMeshes=[],this.originalGBufferMaterials=[],this.originalGBufferOnBeforeRender=[],this.hiddenGBufferObjects=[],this.gBufferPhaseMaskCache=new WeakMap,this.gBufferMaterialArrayCache=new WeakMap,this.gBufferShadowUpdaterCache=new WeakMap,this._initiatedMaterialTextures=new Set,this._initiatedTextures=new Set,this.compileInProgress=!1,this.depthMaterialCachedMaterials=new Map,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 n,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],this._customDepthMaterialCache=new WeakMap,this.graphicsRuntime=s.graphicsRuntime??Ke,null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),this.resolutionScale=s.resolutionScale??1,this.dynamicResolutionScale=this.getBaseResolutionScale(),this.fpsCap=s.fpsCap,this.experimentalWebGpuDynamicBatchingEnabled=s.webgpuDynamicBatching??!0,this.experimentalWebGpuTiledLightingEnabled=s.webgpuTiledLighting??!0,this.outlinesEnabled=!0===s.enableOutlines,this.webgpuDirectionalShadowOptions=Ze(s.webgpuDirectionalShadows),"webgpu"===this.requestedBackend&&!0===s.enableXR&&(console.warn("[Hology WebGPU experiment] XR is not supported; using WebGL."),this.experimentalWebGpuFailed=!0),e.activeView=this,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);const a=t.clientWidth||1,r=t.clientHeight||1,h=new i.PerspectiveCamera(45,a/r,.1,800);h.layers.enable(19),this.camera=h,S.renderingView=this,this.setCamera(h),this.setupEventListeners(),this.setupWebGlPipeline=()=>{if(!this.webGlInitialized)try{this.webGlBackend=Ye.initialize({container:this.container,pixelRatio:this.getPresentationPixelRatio(),enableXR:this.options.enableXR??!1,shadows:{enabled:this.options.shadows?.enabled??!0,autoUpdate:this.options.shadows?.autoUpdate??!1}}),this.renderer=this.webGlBackend.renderer,this.outlineEffect=this.webGlBackend.outlineEffect,this.createGRenderTarget(),this.composer=new b(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),this.baseToneMapping=this.renderer.toneMapping,this.baseToneMappingExposure=this.renderer.toneMappingExposure,this.isDepthTextureExtensionSupported=he(this.renderer),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container,this.getRenderPixelRatio()),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(),this.sceneDepthRenderTarget=this.createSceneDepthRenderTarget(),this.postProcessEffectResolution=new i.Vector2(1,1),this.postProcessEffectUniformState={aoEnabled:!1,aoTexture:null,cameraFar:void 0,cameraNear:void 0,depthTexture:He(),normalTexture:He(128,128,255),resolution:this.postProcessEffectResolution,simulationTime:0},this.fquadCopySceneColor=new Fe(new p(f)),this.fquadCopySceneDepth=new Fe(new R({color:j(q("tDepthTexture",He()).sample(F.uv).r)})),this.fquadBlendAO=this.createAoblendQuad();const a=new i.Vector2(t.clientWidth,t.clientHeight),n=(new x(this.scene,this.camera),new P(f,"prevtexture"));n.enabled=!0,n.needsSwap=!0,n.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=n;const r=new Oe(a,1.5,.4,.85);r.threshold=1,r.strength=.9,r.radius=.2,this.bloomPass=r;const o=new te(this.scene,this.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});o.normalRenderTarget?.dispose(),o.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),o.output=te.OUTPUT.Off,o.enabled=!1,this.aoPass=o,o.enabled=this.ambientOcclusionSettings.enabled,o.blendIntensity=this.ambientOcclusionSettings.blendIntensity,o.updateGtaoMaterial(this.ambientOcclusionSettings.options),this.fquadBlendAO.material.uniforms.tAO.value=o.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 h=new Be({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});h.output=Be.OUTPUT.Default,h.blur=!0,h.fresnel=!1,h.distanceAttenuation=!0,h.maxDistance=50,h.selective=!0,h.bouncing=!1,h.opacity=.4,h.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=h,!1!==this.options.ao?.enabled&&this.composer.addPass(o);const c=new Ft((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(c);const u=new Ft((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(nt.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(u),this.composer.addPass(n),this.composer.addPass(h),this.phasedRenderPass=new It(this.scene,this.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(r),r.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.volumetricFogPass=new We(a),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 d=new ye;this.composer.addPass(d),this.colorPass=d,d.vignetteEnabled=!1,this.outlinePass=new Me(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 m=new P(w);m.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(m),this.fxaaPass=m,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new P(M).clear=!1,this.fixStatsStyle(),this.lutPass=new v({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const g=new P(f,"prevtexture");g.enabled=!0,g.needsSwap=!1,g.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],g.renderToScreen=!0;const y=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)}(y),this.outputPass=y,this.upscaleOutputPass=y instanceof Qe?y:null,this.composer.addPass(y);const S=new i.MeshBasicMaterial({colorWrite:!1,depthWrite:!1,depthTest:!0,transparent:!1}),T=new l(new i.BoxGeometry(1,1,1),S);T.renderOrder=1/0,T.name="CLUSTER_BOUNDS_VOLUME",this.webGlInitialized=!0,this.backendHandle=this.webGlBackend,this.attachRendererDomElement(),this.refreshPostProcessEffectPassOrder()}catch(e){throw this.webGlInitialized=!1,this.webGlBackend?.dispose(),this.webGlBackend=null,this.backendHandle=null,e}},("webgpu"!==this.requestedBackend||this.experimentalWebGpuFailed)&&this.setupWebGlPipeline()}addCluster(e){if(!1===this.options.occlusionCulling?.enabled)return;if(!this.webGlInitialized)return;if(!this.renderer.capabilities.isWebGL2)return;const t=this.renderer.getContext(),s=t.createQuery();if(null==s)return;const i={query:s,visible:!0,awaitingResult:!1,cluster:e,lastTested:-1/0,distance:0,update:()=>{if(i.awaitingResult&&t.getQueryParameter(s,t.QUERY_RESULT_AVAILABLE)){const e=t.getQueryParameter(s,t.QUERY_RESULT);i.visible=!!e,i.awaitingResult=!1}}};e.boundsMesh.onBeforeRender=()=>{i.awaitingResult||t.beginQuery(t.ANY_SAMPLES_PASSED,s)},e.boundsMesh.onAfterRender=()=>{i.awaitingResult||(t.endQuery(t.ANY_SAMPLES_PASSED),i.awaitingResult=!0)},this.occlusionClusters.push(i)}updateRenderedOcclusionClusters(){this.queryScene.clear();const e=performance.now(),t=[];for(const s of this.occlusionClusters){if(s.awaitingResult)continue;const i=s.cluster.bounds.distanceToPoint(this.camera.position);if(s.distance=i,i<10){s.visible=!0,s.lastTested=e;continue}if(i>1e3)continue;const a=e-s.lastTested;if(!(s.visible&&a<4e3)&&((s.visible||!(a<100))&&bt.intersectsBox(s.cluster.bounds)))if(s.visible)t.push(s);else{let e=0;for(;e<t.length&&t[e].distance<s.distance;)e++;t.splice(e,0,s)}}if(t.length<50)for(const s of t)s.lastTested=e,this.queryScene.add(s.cluster.boundsMesh);else{const s=Math.max(Math.floor(Math.random()*t.length-50),0);for(let i=0;i<50;i++){const a=t[s+i];if(null==a)break;a.lastTested=e,this.queryScene.add(a.cluster.boundsMesh)}if(t.length>0){const s=t[0];s.lastTested=e,this.queryScene.add(s.cluster.boundsMesh)}}}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute",e.style.display="flex",e.style.flexWrap="nowrap",e.style.width="max-content";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.flex="none"}setEnableOutlines(e){this.outlinesEnabled=e,null!=this.outlinePass&&(this.outlinePass.enabled=e),null!=this.fxaaPass&&(this.fxaaPass.enabled=e),this.syncWebGpuOutlineState()}registerWebGpuPresentationExtension(e){return"webgpu"!==this.requestedBackend?()=>{}:(this.webGpuPresentationExtensions.add(e),this.experimentalWebGpuBackend?.setPresentationExtensions(this.webGpuPresentationExtensions),()=>{this.webGpuPresentationExtensions.delete(e),this.experimentalWebGpuBackend?.setPresentationExtensions(this.webGpuPresentationExtensions)})}get sharedGraphicsRuntime(){return this.graphicsRuntime}setCamera(e){if(this.camera=e,this.resetUpscalingHistory(),this.composer?.passes.forEach(t=>{t instanceof x?t.camera=e:t instanceof Me?t.renderCamera=e:(t instanceof be||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){this.csm=new Z({maxFar:"webgpu"===this.requestedBackend?this.webgpuDirectionalShadowOptions.maxDistance:80,lightFar:250,lightMargin:20,shadowBias:-1e-4,cascades:"webgpu"===this.requestedBackend?this.webgpuDirectionalShadowOptions.cascadeCount:ct?2:3,shadowMapSize:"webgpu"===this.requestedBackend?this.webgpuDirectionalShadowOptions.mapSize:1024*(ct?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"});for(const e of this.csm.lights)e.shadow.normalBias=.01;if(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,c.lights_fragment_begin=y.lights_fragment_begin}else this.csm.camera=this.camera,this.camera;this.csm.updateFrustums()}setSelectedObjects(e){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.selectedOutlineObjects=Array.from(t.values()),this.experimentalWebGpuSelectedObjectInstances=[],this.syncWebGpuOutlineState(),null!=this.outlinePass&&(this.outlinePass.selectedObjects=this.selectedOutlineObjects)}setExperimentalWebGpuTiledLightingEnabled(e){this.experimentalWebGpuTiledLightingEnabled=e,this.experimentalWebGpuBackend?.setTiledLightingEnabled(e)}setExperimentalWebGpuDynamicBatchingEnabled(e){this.experimentalWebGpuDynamicBatchingEnabled=e,this.experimentalWebGpuBackend?.setDynamicBatchingEnabled(e)}setMotionBlurOptions(e){this.experimentalWebGpuBackend?.setMotionBlurOptions(e)}setDirectionalShadowOptions(e){if("webgpu"!==this.requestedBackend)return;const t=Ze(e),s=this.webgpuDirectionalShadowOptions,a=t.mapSize!==s.mapSize||t.cascadeCount!==s.cascadeCount||t.maxDistance!==s.maxDistance;if(a||t.enabled!==s.enabled){if(this.webgpuDirectionalShadowOptions=t,a&&null!=this.csm){const e=this.csm.lights[0],t={lightDirection:this.csm.lightDirection.clone(),lightIntensity:e?.intensity??this.csm.lightIntensity,lightColor:e?.color.clone()??new i.Color(16777215),castShadow:e?.castShadow??!0,userData:{...e?.userData??{}},shadowBias:e?.shadow.bias??this.csm.shadowBias,normalBias:e?.shadow.normalBias??.01,shadowRadius:e?.shadow.radius??1,shadowIntensity:e?.shadow.intensity??1};this.csm.remove(),this.csm.dispose(),this.csm=null,this.csmCascadeLastUpdate=void 0,this.setCamera(this.camera),this.csm.lightDirection.copy(t.lightDirection),this.csm.lightIntensity=t.lightIntensity,this.csm.shadowBias=t.shadowBias;for(const e of this.csm.lights)e.intensity=t.lightIntensity,e.color.copy(t.lightColor),e.castShadow=t.castShadow,e.userData={...t.userData},e.shadow.bias=t.shadowBias,e.shadow.normalBias=t.normalBias,e.shadow.radius=t.shadowRadius,e.shadow.intensity=t.shadowIntensity;this.csm.update()}this.experimentalWebGpuBackend?.setDirectionalShadowOptions(t.enabled,t.mapSize),this.syncExperimentalWebGpuCascades(),this.experimentalWebGpuBackend?.resetViewHistory()}}setGTAOOptions(e){this.experimentalWebGpuBackend?.setGTAOOptions(e)}configureAmbientOcclusion(e,t=1,s={}){this.ambientOcclusionSettings={enabled:e,blendIntensity:t,options:s},this.webGlInitialized&&(this.aoPass.enabled=e,this.aoPass.blendIntensity=t,this.aoPass.updateGtaoMaterial(s)),this.experimentalWebGpuBackend?.setGTAOOptions({...s,enabled:e})}invalidateShadows(){this.webGlInitialized&&(this.renderer.shadowMap.needsUpdate=!0)}initTexture(e){this._initTexture(e)}setBaseToneMapping(e,t){this.baseToneMapping=e,this.baseToneMappingExposure=t,this.webGlInitialized&&(this.renderer.toneMapping=e,this.renderer.toneMappingExposure=t)}get supportsWebGlDepthTexture(){return this.webGlInitialized&&this.isDepthTextureExtensionSupported}setAntiAliasingMode(e){this.experimentalWebGpuBackend?.setAntiAliasingMode(e)}setGTAOQuality(e){this.experimentalWebGpuBackend?.setGTAOQuality(e)}setVolumetricFogOptions(e){this.experimentalWebGpuBackend?.setVolumetricFogOptions(e)}setVolumetricFogQuality(e){this.experimentalWebGpuBackend?.setVolumetricFogQuality(e)}pushMotionBlurOverride(e){return this.experimentalWebGpuBackend?.pushMotionBlurOverride(e)??null}setObjectMotionBlur(e,t,s=1){e.traverse(e=>{e.userData.motionBlurMode=t,e.userData.motionBlurScale=Math.max(0,Math.min(s,8))})}invalidateObjectMotion(e){e.traverse(e=>{e.userData.motionBlurTeleported=!0,this.experimentalWebGpuBackend?.invalidateObjectMotion(e)})}setSelectedObjectInstances(e){this.experimentalWebGpuSelectedObjectInstances=[...e],this.syncWebGpuOutlineState()}static createDepthRenderTarget(e,t,s){const a=Math.max(1,Math.floor(t.clientWidth*s)),n=Math.max(1,Math.floor(t.clientHeight*s)),r=new i.WebGLRenderTarget(a,n);return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,r.depthTexture=new i.DepthTexture(a,n),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter,r}static createAOMaskDepthRenderTarget(e,t,s=e.getPixelRatio()){const a=Math.max(1,t.clientWidth*s),n=Math.max(1,t.clientHeight*s),r=new i.DepthTexture(a,n);r.type=i.UnsignedInt248Type,r.minFilter=i.NearestFilter,r.magFilter=i.NearestFilter;const o=new i.WebGLRenderTarget(a,n,{type:i.HalfFloatType,depthTexture:r});return o.texture.minFilter=i.NearestFilter,o.texture.magFilter=i.NearestFilter,o.texture.generateMipmaps=!1,o.stencilBuffer=!1,o}createSceneColorRenderTarget(){const e=this.gRenderTarget.width,t=this.gRenderTarget.height,s=new i.WebGLRenderTarget(e,t,{type:i.HalfFloatType,format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}createSceneDepthRenderTarget(){const e=new i.WebGLRenderTarget(this.gRenderTarget.width,this.gRenderTarget.height,{type:i.FloatType,format:i.RedFormat,minFilter:i.NearestFilter,magFilter:i.NearestFilter,depthBuffer:!1,stencilBuffer:!1});return e.texture.generateMipmaps=!1,e}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),n=new i.DepthTexture(s,a);n.type=i.UnsignedIntType,n.minFilter=i.NearestFilter,n.magFilter=i.NearestFilter,this.gRenderTarget=new u(s,a,{count:3,samples:this.options?.msaa??0,minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat,depthTexture:n}),this.gRenderTarget.textures[2].type=i.UnsignedByteType,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(t=!0){if(this.stopAnimationLoop(),this.stopIntersectionObservation?.(),this.stopIntersectionObservation=null,this.resumeAnimationLoop=null,this.onLoopCallbacks=[],this.disposeExperimentalStaticDrawSets(),e.experimentalWebGpuPresentationView===this&&(e.experimentalWebGpuPresentationView=null),this.wakePausedRenderer=null,this.lightVolume?.shTexture.dispose(),window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),t&&this.webGlInitialized&&this.renderer.dispose(),this.webGlInitialized){this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.sceneDepthRenderTarget.dispose();for(const e of this.postProcessEffects)null!=e.pass&&(this.composer.removePass(e.pass),e.pass.dispose());this.volumetricFogPass.dispose(),this.webGlBackend?.dispose(),this.webGlBackend=null}if(this.csm?.dispose(),this.postProcessEffects.length=0,this.detachOwnedDomElements(),this.releaseExperimentalWebGpuBackend(),this.experimentalWebGpuBackend=null,this.backendHandle=null,this.webGlInitialized&&this.occlusionClusters.length>0){const e=this.renderer.getContext();this.occlusionClusters.forEach(t=>{e.deleteQuery(t.query)})}S.clearSceneCache(this.scene)}stopAnimationLoop(){this.running=!1}suspendPresentation(){this.stopAnimationLoop(),this.detachOwnedDomElements()}activatePresentation(){if(e.activeView=this,null!=this.experimentalWebGpuBackend){const t=e.experimentalWebGpuPresentationView,s=t!==this;s&&t?.disposeExperimentalStaticDrawSets(),this.applyExperimentalWebGpuViewState(s),e.experimentalWebGpuPresentationView=this,this.activateExperimentalStaticDrawSets()}this.attachRendererDomElement(),this.resizeRender(!0)}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.experimentalWebGpuBackend?.setProfilingEnabled(e||this._profilingEnabled),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),this.syncWebGpuPassStatsDom()}get showStats(){return this._showStats}getLastFrameProfile(){return this.experimentalWebGpuBackend?.getLastFrameProfile()??null}setProfilingEnabled(e){this._profilingEnabled=e,this.experimentalWebGpuBackend?.setProfilingEnabled(e||this._showStats)}attachRendererDomElement(){const t=this.getActiveRendererCanvas();if("webgpu"===this.activeBackend&&null!=this.experimentalWebGpuBackend&&e.experimentalWebGpuPresentationView!==this){const t=e.experimentalWebGpuPresentationView;t?.disposeExperimentalStaticDrawSets(),e.experimentalWebGpuPresentationView=this,this.applyExperimentalWebGpuViewState(!0),this.activateExperimentalStaticDrawSets()}const s=this.webGlInitialized?this.renderer.domElement:null,i=t===s?this.experimentalWebGpuBackend?.canvas:s;i?.parentElement===this.container&&this.container.removeChild(i),t.parentElement===this.container&&t===this.container.firstChild||this.container.insertBefore(t,this.container.firstChild),this._showStats&&this.stats.dom.parentElement!==this.container&&this.container.appendChild(this.stats.dom),this.syncWebGpuPassStatsDom()}detachOwnedDomElements(){this.webGlInitialized&&this.renderer.domElement.parentElement===this.container&&this.container.removeChild(this.renderer.domElement);const e=this.experimentalWebGpuBackend?.canvas;e?.parentElement===this.container&&this.container.removeChild(e),this.stats.dom.parentElement===this.container&&this.container.removeChild(this.stats.dom),this.webGpuPassStatsDom.parentElement===this.container&&this.container.removeChild(this.webGpuPassStatsDom)}syncWebGpuPassStatsDom(){const e=this._showStats&&"webgpu"===this.requestedBackend;e&&this.webGpuPassStatsDom.parentElement!==this.container?this.container.appendChild(this.webGpuPassStatsDom):e||this.webGpuPassStatsDom.parentElement!==this.container||this.container.removeChild(this.webGpuPassStatsDom)}updateWebGpuPassStats(e){let t=this.webGpuPassStatsRows.length!==e.passes.length;for(let s=0;!t&&s<e.passes.length;s++)t=this.webGpuPassStatsRows[s].name!==e.passes[s].name;t&&(this.webGpuPassStatsDom.replaceChildren(this.webGpuVisibilityStatsDom),this.webGpuPassStatsRows=e.passes.map(e=>{const t=function(e){const t=document.createElement("div");t.style.cssText=["display:grid","grid-template-columns:minmax(0,1fr) 92px 92px","column-gap:12px","margin-bottom:7px"].join(";");const s=document.createElement("span");s.textContent=e,s.style.cssText="overflow:hidden;text-overflow:ellipsis;white-space:nowrap";const i=document.createElement("span"),a=document.createElement("span"),n=document.createElement("div");return n.style.cssText=["grid-column:1","height:4px","margin-top:4px","background:rgba(255,255,255,.78)","box-shadow:0 1px 2px rgba(0,0,0,.9)"].join(";"),t.append(s,i,a,n),{name:e,dom:t,gpu:i,cpu:a,bar:n}}(e.name);return this.webGpuPassStatsDom.appendChild(t.dom),t}));const s=e.visibility;if(null==s)this.webGpuVisibilityStatsDom.textContent=e.hiZOcclusionCullingActive?"GPU visibility: awaiting readback":"GPU visibility: inactive";else{const e=s.totalInstances>0?s.visibleInstances/s.totalInstances*100:100;this.webGpuVisibilityStatsDom.textContent=`GPU visibility: ${s.visibleInstances.toLocaleString()} / ${s.totalInstances.toLocaleString()} visible (${e.toFixed(1)}%), ${s.culledInstances.toLocaleString()} culled | dynamic ${s.dynamicVisibleInstances.toLocaleString()} / ${s.dynamicTotalInstances.toLocaleString()}, static ${s.staticVisibleInstances.toLocaleString()} / ${s.staticTotalInstances.toLocaleString()}`}let i=.01;for(const t of e.passes)i=Math.max(i,t.gpuTimeMs??t.cpuTimeMs);for(let t=0;t<e.passes.length;t++){const s=e.passes[t],a=this.webGpuPassStatsRows[t];a.gpu.textContent=null==s.gpuTimeMs?"GPU --":`GPU ${s.gpuTimeMs.toFixed(2)} ms`,a.cpu.textContent=`CPU ${s.cpuTimeMs.toFixed(2)} ms`;const n=s.gpuTimeMs??s.cpuTimeMs;a.bar.style.width=`${Math.max(n>0?2:0,n/i*100)}%`}}getActiveRendererCanvas(){if(null==this.backendHandle)throw new Error("Rendering backend is not initialized. Await compileAsync() before rendering.");return this.backendHandle.canvas}requireInitializedBackend(e){const t=this.backendHandle;if(null==t)throw new Error(`Cannot ${e}: the rendering backend has not finished initializing.`);return t}fallbackToWebGlForUnavailableWebGpu(t){const s=t instanceof Error?t.stack??t.message:String(t);console.warn(`[Hology WebGPU] WebGPU is unavailable. ${s}`);const i=this.experimentalWebGpuBackend;i?.canvas.parentElement===this.container&&this.container.removeChild(i.canvas),this.disposeExperimentalStaticDrawSets(),this.releaseExperimentalWebGpuBackend(),e.experimentalWebGpuPresentationView===this&&(e.experimentalWebGpuPresentationView=null),this.experimentalWebGpuBackend=null,this.experimentalWebGpuFailed=!0,this.backendHandle=null,this.webGpuPassStatsDom.remove(),this.setupWebGlPipeline(),this.applyWorldEnvironmentToWebGl(),this.attachRendererDomElement(),this.resizeRender(!0),console.warn("[Hology WebGPU] Falling back to WebGL because WebGPU is unavailable.")}activateExperimentalStaticDrawSets(){if("webgpu"!==this.activeBackend||null==this.experimentalWebGpuBackend)return;let e=0,t=0,s=0,i=0;for(const a of this.experimentalStaticDrawSetRegistrations)if(null==a.staticDrawSet)try{const i=this.experimentalWebGpuBackend.createStaticDrawSet(a.root,a.label,a.allowUnsortedLateDraws);if(null==i)continue;a.staticDrawSet=i,a.root.visible=!1,e++,t+=i.drawCount,s+=i.instanceCount}catch(e){i++,console.warn(`[Hology WebGPU experiment] Keeping static root "${a.label}" dynamic:`,e)}e>0&&console.info(`[Hology WebGPU experiment] Activated ${e} static draw set${1===e?"":"s"} (${t} draws, ${s} instances).`),i>0&&console.warn(`[Hology WebGPU experiment] ${i} static draw set${1===i?"":"s"} remain dynamic.`)}disposeExperimentalStaticDrawSets(){for(const e of this.experimentalStaticDrawSetRegistrations)e.staticDrawSet?.dispose(),null!=e.staticDrawSet&&(e.root.visible=e.sourceWasVisible),e.staticDrawSet=null}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof R&&(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:Ot(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 R||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}setWorldEnvironment(e){const t=this.worldEnvironment?.source!==e?.source;this.worldEnvironment=e,null==e?(this.scene.environment=null,this.scene.environmentIntensity=1):("webgpu"!==this.requestedBackend||this.experimentalWebGpuFailed)&&this.applyWorldEnvironmentToWebGl();const s=this.experimentalWebGpuBackend;if(null==s)return;const i=t&&"webgpu"===this.activeBackend;i&&this.disposeExperimentalStaticDrawSets(),s.setWorldEnvironment(e),i&&this.activateExperimentalStaticDrawSets()}applyWorldEnvironmentToWebGl(){const e=this.worldEnvironment;if(null==e)return this.scene.environment=null,void(this.scene.environmentIntensity=1);this.scene.environment=this.getEnvTexture(e.source),this.scene.environmentIntensity=e.intensity}hideOccluded(e){e.length=0;for(const t of this.occlusionClusters)if(!t.visible){let s=t.cluster.objects.length;for(;s--;){const i=t.cluster.objects[s];i.visible&&(i.visible=!1,e.push(i))}}}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 g||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 g||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 g&&(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 ke&&(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===Vt.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||Vt.includes(e)||jt.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 Vt){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(e,t,s=!1){const a=t===nt.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let n=a.get(e);if(!0===e.userData.isGBufferMaterial)return e;if(null==n){const s=this.usesShaderUniform(e,ie),o=this.usesShaderUniform(e,ue),l=this.usesShaderUniform(e,pe),h=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,c=t===nt.opaque?!(s||o||l||h):h||s||o||l;if(!c)return a.set(e,ht),ht;let u=F.uv;if(e instanceof ke&&null!=e.heightMap){const t=B("heightScale",e.heightScale??1);u=Ie(u,q("heightMap",e.heightMap),t)}let d=V.normal;if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=e.normalMap??lt,s=B("useNormalMap",null!=e.normalMap?1:0),i=B("normalScale",e.normalScale?.x??1),a=T(q("normalMap",t).sample(qe(u,e.normalMap)),i);d=N(V.normal,a,s)}else e instanceof R&&null!=e.outputNormal&&(d=e.outputNormal);!0!==e.userData.disableAO&&(d=z("DOUBLE_SIDED",d,e=>_(new L("gl_FrontFacing"),e,e.multiplyScalar(-1))));let m=e.userData?.reflective?G(0):G(1);if(e instanceof i.MeshStandardMaterial){const t=B("roughness",e.roughness??1),s=e.roughnessMap??rt,i=B("useRoughnessMap",null!=e.roughnessMap?1:0),a=q("roughnessMap",s).sample(qe(u,e.roughnessMap)).g.multiply(t);m=N(t,a,i)}else e instanceof R&&null!=e.outputRoughness&&(m=e.outputRoughness);let f=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,s=B("useLightMap",null!=e.lightMap?1:0),i=B("lightMapIntensity",e.lightMapIntensity??1),a=q("lightMap",t).sample(u).rgb.multiplyScalar(i);f=N(D(0),a,s)}let b=G(0);if(e instanceof i.MeshStandardMaterial){const t=B("metalness",e.metalness??0),s=e.metalnessMap??ot,i=B("useMetalnessMap",null!=e.metalnessMap?1:0),a=q("metalnessMap",s).sample(qe(u,e.metalnessMap)).b.multiply(t);b=N(t,a,i)}else e instanceof R&&e.outputRoughness;let w=null,M=G(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??rt,s=B("useAoMap",null!=e.aoMap?1:0);M=B("aoMapIntensity",e.aoMapIntensity??1);const i=q("aoMap",t).sample(qe(u,e.aoMap)).r;w=N(G(1),i,s)}else e instanceof R&&e.outputRoughness;const v=B("opacity",e.opacity??1);let x=G(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;x=q("alphaMap",t).sample(qe(u,e.alphaMap)).r}x=x.multiply(v)}else e instanceof R&&null!=e.outputOpacity&&(x=e.outputOpacity);let P=A(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=C("color",(new i.Vector3).setFromColor(e.color));const s=e.map??rt,a=B("useAlbedoMap",null!=e.map?1:0),n=q("map",s).sample(qe(u,e.map)),r=n.multiply(A(t,1)),o=A(t,1);P=N(o,r,a),e.vertexColors&&(P=P.multiply(j(I($.color.rgb),1)));const l=N(G(1),n.w,a);x=x.multiply(l)}const y=!0===e.userData.hasBloom;let S=D(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=C("emissive",(new i.Vector3).setFromColor(e.emissive)),s=B("emissiveIntensity",e.emissiveIntensity),a=e.emissiveMap??ot,n=B("useEmissiveMap",null!=e.emissiveMap?1:0),r=q("emissiveMap",a).sample(qe(u,e.emissiveMap)).rgb.multiply(t);S=N(t,r,n),S=S.multiplyScalar(s)}else e instanceof R&&null!=e.outputEmissive&&(S=e.outputEmissive);let k=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(k=C("sheenColor",(new i.Vector3).setFromColor(e.sheenColor).multiplyScalar(e.sheen)),e.sheen>0&&null!=e.sheenColorMap)){const t=q("sheenColorMap",e.sheenColorMap).sample(u).rgb;k=k.multiply(t)}let H=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(H=B("sheenRoughness",e.sheenRoughness),e.sheen>0&&null!=e.sheenRoughnessMap)){const t=q("sheenRoughnessMap",e.sheenRoughnessMap).sample(u).r;H=H.multiply(t)}let J=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0&&(J=B("anisotropy",e.anisotropy),e.anisotropy>0&&null!=e.anisotropyMap)){const t=q("anisotropyMap",e.anisotropyMap).sample(u).r;J=J.multiply(t)}let X=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0){const t=e.anisotropyRotation??0;X=Q("anisotropyDirection",new i.Vector2(Math.cos(t),Math.sin(t)))}const Y=B("alphaTest",e.alphaTest);let K,Z=e.alphaTest>0?x.lt(Y):h&&t===nt.opaque?x.lt(.8):null;!0===e.userData.isDecal&&(Z=Z?Z.or(je):je),K=h?j(0,0,0,0):(r=d,U(r).multiplyScalar(.5).addScalar(.5)).rgba(e.userData?.reflective?m:1);const ee=e instanceof R?e.outputPosition:void 0,te=e instanceof R?e.outputTransform:void 0;let se,ae=A("black",1);if(e instanceof R&&null!=e.outputColor)ae=e.outputColor;else if(e instanceof i.MeshStandardMaterial)ae=E({color:P,metalness:b,roughness:m,emissive:S.rgb,normal:d,ambientOcclusion:w,ambientOcclusionIntensity:M,bakedLight:f,sheenColor:k,sheenRoughness:H,anisotropy:J,anisotropyDirection:X});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)ae=O({color:P.rgb,ambientOcclusion:w,ambientOcclusionIntensity:M});else if(e instanceof i.MeshBasicMaterial){let e=P.rgb,t=f??D("black");null!=w&&(t=t.multiplyScalar(w.subtract(1).multiply(M).add(1))),e=e.add(t),ae=e.rgba(x)}else e instanceof i.MeshToonMaterial&&(ae=W({color:P,emissive:S.rgb,normal:d,ambientOcclusion:w,ambientOcclusionIntensity:M,bakedLight:f}));(e instanceof R||e instanceof i.MeshStandardMaterial)&&(se=e.envMap);let ne=!0;(e instanceof g||e instanceof i.MeshBasicMaterial||e instanceof i.ShaderMaterial)&&(ne=e.fog);let re=A(ae.rgb,x);ne&&(re=new FogNode(re)),n=new R({transform:te,position:null==te?ee:void 0,outputs:[re,S.rgba(t===nt.opaque?Y:y?1:0),K],opacity:x,outputEncoding:!1,fog:ne,transparent:e.transparent,lights:!0,envMap:se,alphaTest:e.alphaTest,uniformNodes:e.uniformNodes??{},discard:Z}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=n.uniforms.envMapIntensity&&(n.uniforms.envMapIntensity.value=e.envMapIntensity),"alphaMap"in e&&null!=e.alphaMap&&(n.alphaMap=e.alphaMap),(e instanceof R||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(n),e instanceof R&&(Object.assign(n.defines,e.defines),null!=n.uniforms[pe]&&(n.uniforms[pe].value=this.aoPass.pdRenderTarget.texture,n.defines.USE_SSAO_MAP="")),n.userData.mrtOutputs=3,n.forceSinglePass=e.forceSinglePass,n.side=e.side,n.blending=e.blending,h?(n.depthWrite=!e.transparent,n.depthTest=e.depthTest,n.colorWrite=t===nt.transparent):(n.depthWrite=e.depthWrite,n.depthTest=e.depthTest),n.visible=e.visible,n.alphaTest=e.alphaTest,n.alphaHash=e.alphaHash,n.vertexColors=e.vertexColors,n.premultipliedAlpha=e.premultipliedAlpha,n.toneMapped=e.toneMapped,n.blendAlpha=e.blendAlpha,n.blendColor=e.blendColor,n.polygonOffset=e.polygonOffset,n.polygonOffsetFactor=e.polygonOffsetFactor,n.polygonOffsetUnits=e.polygonOffsetUnits,n.blending=e.blending,n.wireframe=e.wireframe??!1,n.userData.isGBufferMaterial=!0,n.visible=c,Object.assign(n.userData,e.userData),n.visible&&(this.csm.setupMaterial(n),e instanceof p&&this.inheritCustomUniformBindings(e,n)),a.set(e,n)}var r;return n.visible&&(e instanceof p?this.updateUniformValues(e,n):this.updateMaterialProperties(e,n)),this.usesShaderUniform(n,ue)&&this.initSceneColorUniform(n),this.initLightVolumeUniform(n),n}isDepthPrepassEnabled(){return!0===this.options.depthPrepass?.enabled}usesSceneFeedbackUniforms(e){return e instanceof p&&(this.usesShaderUniform(e,ie)||this.usesShaderUniform(e,ue)||this.usesShaderUniform(e,pe))}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 R||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=G(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(a=B("opacity",e.opacity??1),null!=e.map&&(a=a.multiply(q("map",e.map).sample(F.uv).a)),null!=e.alphaMap&&(a=a.multiply(q("alphaMap",e.alphaMap).sample(F.uv).r))):e instanceof R&&(a=e.outputOpacity??G(1)),null!=e.alphaTest&&e.alphaTest>0&&(s=a.lt(e.alphaTest));const n=e instanceof R?e.outputPosition:void 0,r=e instanceof R?e.outputTransform:void 0;t=new R({outputs:[A(0,0),A(0,0),A(0,0)],opacity:a,transform:r,position:null==r?n: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 Vt)delete t.uniforms[e];for(const e of jt)delete t.uniforms[e];delete t.uniforms.receiveShadow,this.depthPrepassMaterialCache.set(e,t)}return e instanceof R?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,xe(this.scene,s=>{if(At(s))return t.push(s),s.visible=!1,!1;if(!(s instanceof l))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.webGlInitialized&&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()}syncExperimentalWebGpuCascades(){const e=this.experimentalWebGpuBackend,t=this.camera,s=this.csm;if(null==e||!(t instanceof h)||null==s)return void e?.setCascadedShadowRanges([]);const i=[];s.getExtendedBreaks(i);const a=Math.max(t.far-t.near,1e-4),n=Math.max(Math.min(t.far,s.maxFar),0)/a;e.setCascadedShadowRanges(i.map(({x:e,y:t})=>({x:e*n,y:t*n})),s.lights)}loop(t,s=!1){if(this.requireInitializedBackend("start the render loop"),null!=this.resumeAnimationLoop)return this.running=!0,void this.resumeAnimationLoop();this.running=!0;const n=this.stats,r=n.addPanel(new ee.Panel("Calls","#83f","#002")),h=n.addPanel(new ee.Panel("Triangles","#c32","#002")),c="webgpu"===this.requestedBackend,p=c?n.addPanel(new ee.Panel("WGPU CPU","#2cf","#013")):null,u=c?n.addPanel(new ee.Panel("WGPU GPU","#fc2","#310")):null,d=c?n.addPanel(new ee.Panel("Extract","#4f8","#021")):null,m=c?n.addPanel(new ee.Panel("Upload","#f8c","#301")):null,g=c?n.addPanel(new ee.Panel("Graph","#c8f","#201")):null;let f;s&&this.fixStatsStyle(),navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&"webgpu"!==this.requestedBackend&&(f=new we(this.renderer.getContext()),n.addPanel(f)),this.showStats=s;let b=10,w=1e3,M=16,v=16,x=4,P=4,y=16;let S=-1/0;const T=e=>!(e-S<.25)&&(S=e,!0),G=()=>{const e=this.renderer.info.render.calls;e>b&&(b=e,setTimeout(()=>b=10,5e3)),r.update(e,b);const t=this.renderer.info.render.triangles;t>w&&(w=t,setTimeout(()=>w=1e3,5e3)),h.update(t,w)},E=()=>{const e=this.experimentalWebGpuBackend?.getLastFrameProfile();null!=e&&(b=Math.max(b,e.drawCallCount),w=Math.max(w,e.triangleCount),M=Math.max(M,e.cpuTimeMs),x=Math.max(x,e.cpuPhases.extractSceneMs),P=Math.max(P,e.cpuPhases.uploadMs),y=Math.max(y,e.cpuPhases.renderGraphMs),r.update(e.drawCallCount,b),h.update(e.triangleCount,w),p?.update(e.cpuTimeMs,M),d?.update(e.cpuPhases.extractSceneMs,x),m?.update(e.cpuPhases.uploadMs,P),g?.update(e.cpuPhases.renderGraphMs,y),null!=e.gpuTimeMs&&(v=Math.max(v,e.gpuTimeMs),u?.update(e.gpuTimeMs,v)),this.updateWebGpuPassStats(e))};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const B=[],C=[],W=[],O=[];let U=0;const D=new o,A=new o;let k=0;let I=this.paused,F=!1,V=0,j=null,L=this.fpsCapRevision;const _=()=>{this.running&&!0!==this.options.enableXR&&requestAnimationFrame(q)},z=()=>{this.running&&(e.activeView=this,F&&(F=!1,requestAnimationFrame(()=>q(V))))};this.wakePausedRenderer=z,this.stopIntersectionObservation?.(),this.isIntersecting=!1,this.stopIntersectionObservation=a(this.container,e=>{this.isIntersecting=e,e&&z()}),this.container.addEventListener("pointerdown",()=>{z()},{capture:!0});const q=s=>{if(F=!1,!this.running)return;const a=this.getActiveRendererCanvas(),r=this.needsPausedRender;if(!this.isIntersecting||this.paused&&!r&&a.height>1)return F=!0,V=s,setTimeout(()=>{this.running&&F&&q(s)},500),void(this.paused&&(I=!0));if(a.parentElement!==this.container){if(e.activeView!==this&&null!==e.activeView)return F=!0,void(V=s);this.attachRendererDomElement(),this.resizeRender()}if(!0!==this.options.enableXR){L!==this.fpsCapRevision&&(L=this.fpsCapRevision,j=null);const e=this.fpsCap;if(null!=e){const t=1e3/e;if(null!=j){const e=s-j;if(e<t)return void _();j=s-e%t}else j=s}else j=s}let o=(s*=.001)-U;U=s,I?(o=.016,I=!1,this.resetUpscalingHistory()):o>.25&&this.resetUpscalingHistory(),this.updateDynamicResolution(o,1e3*s);const h="webgpu"===this.activeBackend;if(h||(this.renderer.autoClear=!1,this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight)),n.begin(),!h&&this.showStats&&f?.startQuery(),h||(this.ssrPass.gpuPanel=f),D.copy(this.camera.matrixWorld),!this.paused){if(o>1){let e=o;for(;e>.05;)t(dt),e-=dt;t(e)}else t(o);this.onLoopCallbacks.forEach(e=>e(o))}this.paused||(this.simulationTime+=o*this.simulationTimeScale);const c=this.simulationTime;if(this.camera?.updateMatrixWorld(),this.updateUnderwaterPostProcessing(),this.applyPostProcessSettings(),A.copy(this.camera.matrixWorld),s-k>.08&&!A.equals(D)&&(this.webGlInitialized&&(this.renderer.shadowMap.needsUpdate=!0),k=s),this.updateCsm(),h){try{const e=this.experimentalWebGpuBackend;if(null==e||!Je.supportsCamera(this.camera))throw new Error(`Unsupported camera type: ${this.camera?.type??"unknown"}`);this.syncExperimentalWebGpuCascades(),e.setRenderGraphExtensions(this.experimentalWebGpuRenderGraphExtensions),e.setPresentationExtensions(this.webGpuPresentationExtensions),e.render(this.scene,this.camera,c),this.webGpuRuntimeErrorReported=!1,this.showStats&&T(s)&&E()}catch(e){if(!this.webGpuRuntimeErrorReported){const t=e instanceof Error?e.stack??e.message:String(e);console.error(`[Hology WebGPU] Frame rendering failed; the WebGPU backend remains active. ${t}`),this.webGpuRuntimeErrorReported=!0}}return n.end(),void _()}let p=!1;B.length=0,C.length=0,W.length=0;for(const e of O)e.visible=!0;O.length=0;const u=bt;Mt.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),u.setFromProjectionMatrix(Mt);let d=!1,m=!1,g=!1;const b=this.frameGBufferMeshes,w=this.frameGBufferPhaseMasks,M=this.frameUnsupportedGBufferObjects,v=this.frameGBufferExcludedObjects;if(b.length=0,w.length=0,M.length=0,v.clear(),this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Ae&&(d=!0),e instanceof l&&this.initCustomDepthMaterial(e),(e instanceof l||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&&ft(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(p=!0)),(e instanceof l||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ie])&&isObjectInFrustum(e,u)?(this.initDepthUniform(e.material),m=!0):e instanceof X&&(e.visible=!1,C.push(e)),(e instanceof l||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[pe]&&isObjectInFrustum(e,u)&&e.material instanceof R&&this.initAoUniform(e.material),e instanceof l||e instanceof i.Sprite){let t=!1;ft(e,e=>{this.usesShaderUniform(e,ue)&&(this.initSceneColorUniform(e),t=!0)}),t&&(W.push(e),g=!0)}if(e instanceof l&&e.material?.uniforms&&null!=e.material?.uniforms[ce])e.material.uniforms[ce].value=c;else if(e instanceof l&&Array.isArray(e.material))for(const t of e.material)t.uniforms&&null!=t.uniforms[ce]&&(t.uniforms[ce].value=c);if(v.has(e))for(let t=0;t<e.children.length;t++)v.add(e.children[t]);else if(At(e)){M.push(e);for(let t=0;t<e.children.length;t++)v.add(e.children[t])}else e instanceof l&&(b.push(e),w.push(this.getGBufferPhaseMask(e.material)))}),v.clear(),this.phasedRenderPass.enabled=M.length>0,this.bloomPass.enabled=p,!0===this.options.occlusionCulling?.enabled){for(const e of this.occlusionClusters)e.update();this.hideOccluded(O)}this.prepareUpscalingFrame(),this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderDepthPrepass(),this.renderScene(nt.opaque),this.updateRenderedOcclusionClusters(),this.renderer.render(this.queryScene,this.camera),this.aoPass.output=te.OUTPUT.Off;for(const e of this.postProcessEffects)if(e.pass?.enabled&&this.usesShaderUniform(e.pass.material,ie)){m=!0;break}g&&(this.fquadCopySceneColor.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.fquadCopySceneColor.render(this.renderer)),m&&(this.fquadCopySceneDepth.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.renderer.setRenderTarget(this.sceneDepthRenderTarget),this.fquadCopySceneDepth.render(this.renderer)),(m||g)&&this.renderer.setRenderTarget(this.gRenderTarget),W.length,B.forEach(e=>e.visible=!0),C.forEach(e=>e.visible=!0),W.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=s),this.volumetricFogPass&&d?(this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1),this.updatePostProcessEffectUniforms(c);try{this.paused&&!r||!this.running||(this.render(o),this.finishUpscalingFrame(),this.showStats&&f?.endQuery(),this.showStats&&T(s)&&G(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}finally{this.finishUpscalingFrame(),r&&(this.needsPausedRender=!1)}n.end(),this.csm?.update(),_()};this.resumeAnimationLoop=()=>{I=!0,F=!1,!0===this.options.enableXR?this.renderer.setAnimationLoop(q):requestAnimationFrame(q)},!0===this.options.enableXR?this.renderer.setAnimationLoop(q):requestAnimationFrame(q)}collectGBufferRenderables(e,t=this.frameGBufferMeshes,s=this.frameGBufferPhaseMasks,i=this.frameUnsupportedGBufferObjects){t.length=0,s.length=0,i.length=0,xe(e,e=>{if(At(e))return i.push(e),!1;e instanceof l&&(t.push(e),s.push(this.getGBufferPhaseMask(e.material)))})}getGBufferPhaseMask(e){if(Array.isArray(e)){let t=0;for(let s=0;s<e.length;s++)t|=this.getGBufferPhaseMask(e[s]);return t}if(null==e||!1===e.visible)return 0;let t=this.gBufferPhaseMaskCache.get(e);if(null!=t)return t;if(!0===e.userData.isGBufferMaterial)return t=1<<nt.opaque|1<<nt.transparent,this.gBufferPhaseMaskCache.set(e,t),t;const s=this.usesShaderUniform(e,ie),a=this.usesShaderUniform(e,ue),n=this.usesShaderUniform(e,pe),r=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,o=s||a||n;return t=0,o||r||(t|=1<<nt.opaque),(o||r)&&(t|=1<<nt.transparent),this.gBufferPhaseMaskCache.set(e,t),t}getGBufferMaterialArray(e,t){let s=this.gBufferMaterialArrayCache.get(e);null==s&&(s={opaque:[],transparent:[]},this.gBufferMaterialArrayCache.set(e,s));const i=t===nt.opaque?s.opaque:s.transparent;i.length=e.length;for(let s=0;s<e.length;s++)i[s]=this.createGBufferMaterial(e[s],t,!1);return i}applyGBufferMaterials(e,t=this.frameGBufferMeshes,s=this.frameGBufferPhaseMasks,i=this.frameUnsupportedGBufferObjects){const a=this.appliedGBufferMeshes,n=this.originalGBufferMaterials,r=this.originalGBufferOnBeforeRender,o=this.hiddenGBufferObjects;a.length=0,n.length=0,r.length=0,o.length=0;for(let e=0;e<i.length;e++){const t=i[e];t.visible&&(o.push(t),t.visible=!1)}const l=1<<e;for(let i=0;i<t.length;i++){const h=t[i];if(!h.visible)continue;const c=h.material;if(0!==(s[i]&l)||0!==h.children.length)if(a.push(h),n.push(c),r.push(h.onBeforeRender),0!==(s[i]&l)){if(Array.isArray(c)){const t=this.getGBufferMaterialArray(c,e);h.material=t;for(let e=0;e<t.length;e++)this.initShadowUniform(h,t[e])}else{const t=this.createGBufferMaterial(c,e,e===nt.opaque&&this.isDepthPrepassEligibleMesh(h));h.material=t,this.initShadowUniform(h,t)}this.applyGBufferShadowUniformUpdater(h)}else h.material=ht;else o.push(h),h.visible=!1}}unapplyGBufferMaterials(){const e=this.appliedGBufferMeshes;for(let t=0;t<e.length;t++){const s=e[t];s.material=this.originalGBufferMaterials[t],s.onBeforeRender=this.originalGBufferOnBeforeRender[t]}const t=this.hiddenGBufferObjects;for(let e=0;e<t.length;e++)t[e].visible=!0;e.length=0,this.originalGBufferMaterials.length=0,this.originalGBufferOnBeforeRender.length=0,t.length=0}applyGBufferShadowUniformUpdater(e){const t=e.onBeforeRender;let s=this.gBufferShadowUpdaterCache.get(e);if(null==s){const i=this,a={original:t,wrapper:null};a.wrapper=(t,s,n,r,o,l)=>{a.original.call(e,t,s,n,r,o,l),i.initShadowUniform(e,o)},s=a,this.gBufferShadowUpdaterCache.set(e,s)}s.original=t,e.onBeforeRender=s.wrapper}initTextures(e=this.scene){e.traverse(e=>{if(e instanceof l)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)this._initMaterialTextures(e.material[t]);else this._initMaterialTextures(e.material)})}async initTexturesAsync(e=this.scene){if("webgpu"===this.activeBackend)return;const t=[];e.traverse(e=>{e instanceof l&&(Array.isArray(e.material)?t.push(...e.material):t.push(e.material))});let s=performance.now();for(const e of t)this._initiatedMaterialTextures.has(e)||(this._initMaterialTextures(e),performance.now()-s>=4&&(await new Promise(e=>setTimeout(e,0)),s=performance.now()))}_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 d){if(this._initiatedTextures.has(s.value))continue;this._initTexture(s.value),this._initiatedTextures.add(s.value)}}else for(const[t,s]of Object.entries(e))if(s instanceof d){if(this._initiatedTextures.has(s))continue;this._initTexture(s),this._initiatedTextures.add(s)}}_initTexture(e){const t=this.backendHandle;if(null==t){if("webgpu"!==this.requestedBackend||this.experimentalWebGpuFailed)throw new Error("Cannot initialize a texture before the rendering backend is available.")}else t.initTexture(e)}async compileAsync(e=this.scene){if(this.compileInProgress)return;if("webgpu"===this.requestedBackend&&!this.experimentalWebGpuFailed&&e instanceof i.Scene){this.compileInProgress=!0;try{if(await this.compileExperimentalWebGpu(e))return}finally{this.compileInProgress=!1}}this.renderer.setRenderTarget(this.gRenderTarget),this.compileInProgress=!0;const t=[],s=[],a=[];this.collectGBufferRenderables(e,t,s,a),this.applyGBufferMaterials(nt.opaque,t,s,a),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(nt.transparent,t,s,a),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.fquadCopySceneColor.mesh,this.fquadCopySceneColor.camera),this.renderer.setRenderTarget(this.sceneDepthRenderTarget),this.renderer.compileAsync(this.fquadCopySceneDepth.mesh,this.fquadCopySceneDepth.camera));const n=this.csm.lights[0]?.shadow.camera;null!=n&&(this.applyDepthMaterial(),await this.renderer.compileAsync(e,n),this.unapplyDepthMaterial()),this.compileInProgress=!1,this.renderer.setRenderTarget(null)}async compileExperimentalWebGpu(t){if(!(t instanceof i.Scene))throw new Error("Only THREE.Scene roots are supported by the WebGPU renderer.");if(!Je.supportsCamera(this.camera))throw new Error(`Unsupported camera type: ${this.camera?.type??"unknown"}`);const s={smaa:{quality:"high",edgeDetection:"color",threshold:.05,localContrastAdaptation:.35,cornerRounding:.15,sharpness:0},fxaa:!1,taa:!1,nativeUpscaling:!0===this.options.upscaling?.enabled&&"dlss"===$e(this.options.upscaling)&&{method:"dlss",mode:this.options.upscaling?.dlss?.mode??"quality"},...this.options.webgpuPostProcessing};let a=this.experimentalWebGpuBackend;if(null==a){const e=await this.acquireWebGpuBackend(s);if(null==e.backend)return this.fallbackToWebGlForUnavailableWebGpu(e.reason),!1;a=e.backend}this.experimentalWebGpuBackend=a;const n=e.experimentalWebGpuPresentationView,r=n!==this;r&&n?.disposeExperimentalStaticDrawSets(),this.applyExperimentalWebGpuViewState(r),e.experimentalWebGpuPresentationView=this,this.backendHandle=a,t===this.scene&&this.activateExperimentalStaticDrawSets();try{await a.compile(t,this.camera)}catch(e){throw t===this.scene&&this.disposeExperimentalStaticDrawSets(),e}return this.attachRendererDomElement(),t!==this.scene||this.experimentalWebGpuCapabilityReported||(console.info(Xe(a.inspect(t,this.camera))),this.experimentalWebGpuCapabilityReported=!0),!0}async acquireWebGpuBackend(e){const t=JSON.stringify(e),s=await Je.probeAvailability();if(!1===s.available)return{backend:null,reason:s.reason};const i=await this.graphicsRuntime.acquire("webgpu-renderer",t,()=>Je.create(e,s.adapter));return this.experimentalWebGpuBackendPoolKey=t,{backend:i}}releaseExperimentalWebGpuBackend(){const e=this.experimentalWebGpuBackendPoolKey;this.experimentalWebGpuBackendPoolKey=null,null!=e&&this.graphicsRuntime.release("webgpu-renderer",e,e=>e.destroy())}applyExperimentalWebGpuViewState(e){const t=this.experimentalWebGpuBackend;null!=t&&(e&&t.resetViewHistory(),t.setDynamicBatchingEnabled(this.experimentalWebGpuDynamicBatchingEnabled),t.setTiledLightingEnabled(this.experimentalWebGpuTiledLightingEnabled),t.setGTAOOptions({...this.ambientOcclusionSettings.options,enabled:this.ambientOcclusionSettings.enabled}),t.setDirectionalShadowOptions(this.webgpuDirectionalShadowOptions.enabled,this.webgpuDirectionalShadowOptions.mapSize),this.syncWebGpuOutlineState(t),this.syncExperimentalWebGpuPostProcessEffects(),t.setProfilingEnabled(this._showStats||this._profilingEnabled),t.setWorldEnvironment(this.worldEnvironment),t.setSize(this.container.clientWidth,this.container.clientHeight,this.getBasePixelRatio(),this.getEffectiveResolutionScale()))}syncWebGpuOutlineState(e=this.experimentalWebGpuBackend){null!=e&&(e.setEnableOutlines(this.outlinesEnabled),e.setSelectedObjects(this.selectedOutlineObjects),e.setSelectedObjectInstances(this.experimentalWebGpuSelectedObjectInstances))}applyDepthMaterial(){const e=this.depthMaterialCachedMaterials;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=_t:t.material=null)})}unapplyDepthMaterial(){this.depthMaterialCachedMaterials.forEach((e,t)=>{t.material=e})}renderScene(e){if(!this.running||this.paused&&!this.needsPausedRender)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!==nt.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)}if(e===nt.opaque){const e=this.appliedGBufferMeshes;for(let t=0;t<e.length;t++){const s=e[t],i=this.originalGBufferMaterials[t];!Array.isArray(i)&&!Array.isArray(s.material)&&i instanceof p&&this.updateLightUniformValues(s.material,i)}}this.unapplyGBufferMaterials(),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){if(e.mapping===i.CubeUVReflectionMapping)return e;if(null!=this.backendHandle)return this.backendHandle.getEnvironmentTexture(e);if("webgpu"===this.requestedBackend&&!this.experimentalWebGpuFailed)return e;throw new Error("Cannot prepare an environment texture before the rendering backend is available.")}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.experimentalWebGpuBackend?.setPostProcessState(null),"webgpu"===this.activeBackend?void this.experimentalWebGpuBackend?.setWorldEnvironment(this.worldEnvironment):(this.applyWorldEnvironmentToWebGl(),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=vt(e.globalSaturation,1,1,1),e.globalContrast=vt(e.globalContrast,1,1,1),e.globalGamma=vt(e.globalGamma,1,1,1),e.globalGain=vt(e.globalGain,1,1,1),e.globalOffset=vt(e.globalOffset,0,0,0),e.shadowsSaturation=vt(e.shadowsSaturation,1,1,1),e.shadowsContrast=vt(e.shadowsContrast,1,1,1),e.shadowsGamma=vt(e.shadowsGamma,1,1,1),e.shadowsGain=vt(e.shadowsGain,1,1,1),e.shadowsOffset=vt(e.shadowsOffset,0,0,0),e.shadowsMax=.09,e.midtonesSaturation=vt(e.midtonesSaturation,1,1,1),e.midtonesContrast=vt(e.midtonesContrast,1,1,1),e.midtonesGamma=vt(e.midtonesGamma,1,1,1),e.midtonesGain=vt(e.midtonesGain,1,1,1),e.midtonesOffset=vt(e.midtonesOffset,0,0,0),e.highlightsSaturation=vt(e.highlightsSaturation,1,1,1),e.highlightsContrast=vt(e.highlightsContrast,1,1,1),e.highlightsGamma=vt(e.highlightsGamma,1,1,1),e.highlightsGain=vt(e.highlightsGain,1,1,1),e.highlightsOffset=vt(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;null!=this.worldEnvironment&&(e.envTexture=this.worldEnvironment.source,e.envIntensity=this.worldEnvironment.intensity);let t,s=!1;if(null==this.camera)return;const a=this.camera.getWorldPosition(Rt);let n=[];for(const r of this.postProcessVolumes){if(!mt(r.object))continue;let o=r.blendWeight??1;const l=r.distanceToPoint(a);l>r.blendRadius||(r.blendRadius>0&&(o*=Pe(1-l/r.blendRadius,0,1)),o>1&&(o=1),o>0&&(n.push(r),void 0!==r.settings.tonemapMapping&&(e.tonemapMapping=r.settings.tonemapMapping),void 0!==r.settings.tonemapExposure&&(e.tonemapExposure=i.MathUtils.lerp(e.tonemapExposure,r.settings.tonemapExposure,o)),void 0!==r.settings.envTexture&&(e.envTexture=r.settings.envTexture),void 0!==r.settings.envIntensity&&(e.envIntensity=i.MathUtils.lerp(e.envIntensity,r.settings.envIntensity,o)),void 0!==r.settings.vignetteIntensity&&(e.vignetteIntensity=i.MathUtils.lerp(e.vignetteIntensity,r.settings.vignetteIntensity,o)),void 0!==r.settings.colorTint&&void 0!==r.settings.colorTintIntensity&&r.settings.colorTintIntensity>0&&(e.colorTint=e.colorTint.lerp(r.settings.colorTint,o)),void 0!==r.settings.colorTintIntensity&&(e.colorTintIntensity=i.MathUtils.lerp(e.colorTintIntensity,r.settings.colorTintIntensity,o)),void 0!==r.settings.depthFocus&&(s=!0,e.depthFocus=void 0!==e.depthFocus?i.MathUtils.lerp(e.depthFocus,r.settings.depthFocus,o):r.settings.depthFocus),void 0!==r.settings.depthAperture&&(s=!0,e.depthAperture=void 0!==e.depthAperture?i.MathUtils.lerp(e.depthAperture,r.settings.depthAperture,o):r.settings.depthAperture),void 0!==r.settings.depthMaxBlur&&(s=!0,e.depthMaxBlur=void 0!==e.depthMaxBlur?i.MathUtils.lerp(e.depthMaxBlur,r.settings.depthMaxBlur,o):r.settings.depthMaxBlur),void 0!==r.settings.temperature&&(e.temperature=i.MathUtils.lerp(e.temperature,r.settings.temperature,o)),void 0!==r.settings.temperatureTint&&(e.temperatureTint=i.MathUtils.lerp(e.temperatureTint,r.settings.temperatureTint,o)),void 0!==r.settings.globalSaturation&&e.globalSaturation.lerp(r.settings.globalSaturation,o),void 0!==r.settings.globalContrast&&e.globalContrast.lerp(r.settings.globalContrast,o),void 0!==r.settings.globalGamma&&e.globalGamma.lerp(r.settings.globalGamma,o),void 0!==r.settings.globalGain&&e.globalGain.lerp(r.settings.globalGain,o),void 0!==r.settings.globalOffset&&e.globalOffset.lerp(r.settings.globalOffset,o),void 0!==r.settings.shadowsSaturation&&e.shadowsSaturation.lerp(r.settings.shadowsSaturation,o),void 0!==r.settings.shadowsContrast&&e.shadowsContrast.lerp(r.settings.shadowsContrast,o),void 0!==r.settings.shadowsGamma&&e.shadowsGamma.lerp(r.settings.shadowsGamma,o),void 0!==r.settings.shadowsGain&&e.shadowsGain.lerp(r.settings.shadowsGain,o),void 0!==r.settings.shadowsOffset&&e.shadowsOffset.lerp(r.settings.shadowsOffset,o),void 0!==r.settings.shadowsMax&&(e.shadowsMax=i.MathUtils.lerp(e.shadowsMax,r.settings.shadowsMax,o)),void 0!==r.settings.midtonesSaturation&&e.midtonesSaturation.lerp(r.settings.midtonesSaturation,o),void 0!==r.settings.midtonesContrast&&e.midtonesContrast.lerp(r.settings.midtonesContrast,o),void 0!==r.settings.midtonesGamma&&e.midtonesGamma.lerp(r.settings.midtonesGamma,o),void 0!==r.settings.midtonesGain&&e.midtonesGain.lerp(r.settings.midtonesGain,o),void 0!==r.settings.midtonesOffset&&e.midtonesOffset.lerp(r.settings.midtonesOffset,o),void 0!==r.settings.highlightsSaturation&&e.highlightsSaturation.lerp(r.settings.highlightsSaturation,o),void 0!==r.settings.highlightsContrast&&e.highlightsContrast.lerp(r.settings.highlightsContrast,o),void 0!==r.settings.highlightsGamma&&e.highlightsGamma.lerp(r.settings.highlightsGamma,o),void 0!==r.settings.highlightsGain&&e.highlightsGain.lerp(r.settings.highlightsGain,o),void 0!==r.settings.highlightsOffset&&e.highlightsOffset.lerp(r.settings.highlightsOffset,o),void 0!==r.settings.highlightsMin&&(e.highlightsMin=i.MathUtils.lerp(e.highlightsMin,r.settings.highlightsMin,o)),void 0!==r.settings.lut&&(t=r.settings.lut),void 0!==r.settings.lutIntensity&&(e.lutIntensity=i.MathUtils.lerp(e.lutIntensity,r.settings.lutIntensity,o))))}if(0===n.length)return this.experimentalWebGpuBackend?.setPostProcessState(null),"webgpu"===this.activeBackend?void this.experimentalWebGpuBackend?.setWorldEnvironment(this.worldEnvironment):(this.applyWorldEnvironmentToWebGl(),this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure));if("webgpu"===this.activeBackend){const t=yt(Et,e.temperature,e.temperatureTint),i=e=>[e.x,e.y,e.z],a=n.some(e=>{return void 0!==(t=e.settings).tonemapMapping||void 0!==t.tonemapExposure||void 0!==t.vignetteIntensity||void 0!==t.colorTintIntensity||void 0!==t.temperature||void 0!==t.temperatureTint||void 0!==t.globalSaturation||void 0!==t.globalContrast||void 0!==t.globalGamma||void 0!==t.globalGain||void 0!==t.globalOffset||void 0!==t.shadowsSaturation||void 0!==t.shadowsContrast||void 0!==t.shadowsGamma||void 0!==t.shadowsGain||void 0!==t.shadowsOffset||void 0!==t.shadowsMax||void 0!==t.midtonesSaturation||void 0!==t.midtonesContrast||void 0!==t.midtonesGamma||void 0!==t.midtonesGain||void 0!==t.midtonesOffset||void 0!==t.highlightsSaturation||void 0!==t.highlightsContrast||void 0!==t.highlightsGamma||void 0!==t.highlightsGain||void 0!==t.highlightsOffset||void 0!==t.highlightsMin;var t}),r=n.some(e=>void 0!==e.settings.tonemapMapping||void 0!==e.settings.tonemapExposure);return this.experimentalWebGpuBackend?.setPostProcessState({enabled:a,exposure:r?e.tonemapExposure:1,toneMapping:r?xt(e.tonemapMapping):"none",vignetteIntensity:e.vignetteIntensity,whiteBalance:i(t),tint:[e.colorTint.r,e.colorTint.g,e.colorTint.b],tintIntensity:e.colorTintIntensity,saturation:i(e.globalSaturation),contrast:i(e.globalContrast),gamma:i(e.globalGamma),gain:i(e.globalGain),offset:i(e.globalOffset),shadows:{saturation:i(e.shadowsSaturation),contrast:i(e.shadowsContrast),gamma:i(e.shadowsGamma),gain:i(e.shadowsGain),offset:i(e.shadowsOffset)},midtones:{saturation:i(e.midtonesSaturation),contrast:i(e.midtonesContrast),gamma:i(e.midtonesGamma),gain:i(e.midtonesGain),offset:i(e.midtonesOffset)},highlights:{saturation:i(e.highlightsSaturation),contrast:i(e.highlightsContrast),gamma:i(e.highlightsGamma),gain:i(e.highlightsGain),offset:i(e.highlightsOffset)},shadowsMax:e.shadowsMax,highlightsMin:e.highlightsMin,depthFocus:s?e.depthFocus:void 0,depthAperture:s?e.depthAperture:void 0,depthMaxBlur:s?e.depthMaxBlur:void 0}),void this.experimentalWebGpuBackend?.setWorldEnvironment(null!=e.envTexture?{source:e.envTexture,intensity:e.envIntensity}:this.worldEnvironment)}const r=e.vignetteIntensity>Gt,o=(l=e.temperature,c=e.temperatureTint,!St(l,6500)||!St(c,0));var l,c;const p=(u=e.colorTint,e.colorTintIntensity>Gt&&(!St(u.r,1)||!St(u.g,1)||!St(u.b,1)));var u;const d=!(Pt((m=e).globalSaturation,1,1,1)&&Pt(m.globalContrast,1,1,1)&&Pt(m.globalGamma,1,1,1)&&Pt(m.globalGain,1,1,1)&&Pt(m.globalOffset,0,0,0)&&Pt(m.shadowsSaturation,1,1,1)&&Pt(m.shadowsContrast,1,1,1)&&Pt(m.shadowsGamma,1,1,1)&&Pt(m.shadowsGain,1,1,1)&&Pt(m.shadowsOffset,0,0,0)&&Pt(m.midtonesSaturation,1,1,1)&&Pt(m.midtonesContrast,1,1,1)&&Pt(m.midtonesGamma,1,1,1)&&Pt(m.midtonesGain,1,1,1)&&Pt(m.midtonesOffset,0,0,0)&&Pt(m.highlightsSaturation,1,1,1)&&Pt(m.highlightsContrast,1,1,1)&&Pt(m.highlightsGamma,1,1,1)&&Pt(m.highlightsGain,1,1,1)&&Pt(m.highlightsOffset,0,0,0));var m;const g=o||p||d||r,f=g&&e.tonemapMapping!==i.NoToneMapping,b=null!=t&&e.lutIntensity>Gt;g?(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,g?(this.colorPass.whiteBalanceEnabled=o,this.colorPass.whiteBalanceScale=o?yt(Et,e.temperature,e.temperatureTint):Et.set(1,1,1),this.colorPass.vignetteIntensity=e.vignetteIntensity,this.colorPass.vignetteEnabled=r,this.colorPass.colorTintEnabled=p,this.colorPass.colorTint=e.colorTint,this.colorPass.colorTintIntensity=e.colorTintIntensity,this.colorPass.colorGradingEnabled=d,this.colorPass.toneMapping=e.tonemapMapping,this.colorPass.toneMappingEnabled=f,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 h?(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=b,b&&(null!=t&&(t.flipY=!0,t.generateMipmaps=!1),this.lutPass.lut=t,this.lutPass.intensity=e.lutIntensity)}updatePostProcessEffectUniforms(e){if(!this.webGlInitialized||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 h?(t.cameraNear=this.camera.near,t.cameraFar=this.camera.far):(t.cameraNear=void 0,t.cameraFar=void 0),t.depthTexture=this.sceneDepthRenderTarget.texture,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(this.requireInitializedBackend("render"),"webgpu"===this.activeBackend){const e=this.experimentalWebGpuBackend;return void(null!=e&&Je.supportsCamera(this.camera)&&(this.syncExperimentalWebGpuCascades(),e.setRenderGraphExtensions(this.experimentalWebGpuRenderGraphExtensions),e.setPresentationExtensions(this.webGpuPresentationExtensions),e.render(this.scene,this.camera,this.simulationTime)))}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 l&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,bt)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=ve(this.scene,e=>e instanceof l&&!0===e.material?.userData?.hasBloom)}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.sceneDepthRenderTarget.texture,this.camera instanceof h&&(null!=e.uniforms[ne]&&(e.uniforms[ne].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 R&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof R&&(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[re]&&e.uniforms[re].value.set(this.gRenderTarget.width,this.gRenderTarget.height)}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[pe].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 R&&t.depthWrite&&t.alphaTest>0))return;let s=this._customDepthMaterialCache.get(t);if(null==s){const e=De(Ue);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new R({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}};ut.activeView=null,ut.experimentalWebGpuPresentationView=null,ut=e=t([se(),s("design:paramtypes",[HTMLElement,Object])],ut);export{ut as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const dt=.05;function mt(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}function gt(e,t){return e.priority!==t.priority?e.priority-t.priority:e.id-t.id}function ft(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)}})};new i.Box3;const bt=new i.Frustum,wt=new i.Box3,Mt=new i.Matrix4;export function isObjectInFrustum(e,t){const s=wt.setFromObject(e);return t.intersectsBox(s)}function vt(e,t,s,a){return null==e?new i.Vector3(t,s,a):e.set(t,s,a)}function xt(e){switch(e){case i.LinearToneMapping:return"linear";case i.ReinhardToneMapping:return"reinhard";case i.CineonToneMapping:return"cineon";case i.ACESFilmicToneMapping:return"aces";case i.AgXToneMapping:return"agx";case i.NeutralToneMapping:return"neutral";default:return"none"}}function Pt(e,t,s,i){return null!=e&&St(e.x,t)&&St(e.y,s)&&St(e.z,i)}function yt(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 Bt.set(s,i,a)}(t),a=1+.2*Pe(s,-1,1),n=i.x,r=i.y*a,o=i.z,l=Math.max(r,1e-4);return e.set(1/Math.max(n/l,1e-4),1/Math.max(r/l,1e-4),1/Math.max(o/l,1e-4)),e}function St(e,t,s=Gt){return Math.abs(e-t)<=s}function Tt(e,t){return null!=e&&Number.isFinite(e)&&e>0?e:t}const Gt=1e-4,Rt=new i.Vector3,Et=new i.Vector3(1,1,1),Bt=new i.Vector3(1,1,1);const Ct=new o,Wt=new m;function Ot(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(Ct.makeRotationFromEuler(Wt))}const Ut=new R({outputs:[j(0,0,0,0),j(0,0,0,0),A(D("white"),Ve(4))],transparent:!0}),Dt=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});Ut.depthWrite=!1;new l(new i.BoxGeometry(4,4,4),Dt);function At(e){return e instanceof i.Sprite||e.isPoints||e.isTransformControls||e.isTransformControlsGizmo||e instanceof l&&kt(e,e.material)}function kt(e,t){return null==t||(Array.isArray(t)?t.some(t=>kt(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof R))}class It 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 n=e.autoClear;e.autoClear=!1;const r=this.scene.matrixWorldAutoUpdate,o=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const c=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),this.cachedVisibility.length=0;let p=0,u=this.toRender;if(u.length=0,this.scene.traverseVisible(e=>{const t=At(e);e instanceof l&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(p++,u.push(e))}),p>0)for(const t of u)e.render(t,this.camera);this.cachedVisibility.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=n,s.depthTexture=c,this.scene.matrixWorldAutoUpdate=r,this.scene.matrixAutoUpdate=o,e.shadowMap.autoUpdate=h}}class Ft extends Le{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const Vt=["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"],jt=["directionalShadowMap","directionalShadowMatrix","pointLightShadows","pointShadowMap","pointShadowMatrix","spotLightShadows","spotShadowMap"],Lt=C("fogColor");export class FogNode extends H{constructor(e,t=Lt){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),n=e.get(B("fogFar")),r=e.get(B("fogNear")),o=e.get(B("fogDensity")),l=e.get(I(k.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( ${r}, ${n}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${a}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}const _t=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
|
*/
|
|
@@ -7,6 +7,7 @@ import type { RuntimeAssetsService } from './runtime-asset-service.js';
|
|
|
7
7
|
import type { ShaderType, ActorType, ActorComponentType } from '../shader/shader.js';
|
|
8
8
|
import type { DetailTier } from './model.js';
|
|
9
9
|
import { NetMode } from '../gameplay/net/net-session.js';
|
|
10
|
+
import type { ActorPersistence } from '../gameplay/services/actor-persistence.js';
|
|
10
11
|
export type ShaderDefinitions = {
|
|
11
12
|
[name: string]: ShaderType;
|
|
12
13
|
};
|
|
@@ -17,6 +18,7 @@ export type ComponentDefinitions = {
|
|
|
17
18
|
[name: string]: ActorComponentType;
|
|
18
19
|
};
|
|
19
20
|
export type LoadSceneConfig = {
|
|
21
|
+
persistence?: ActorPersistence;
|
|
20
22
|
detailTier: DetailTier;
|
|
21
23
|
nodeMode?: NetMode;
|
|
22
24
|
};
|
package/dist/scene/bootstrap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{polyfill as e}from"../utils/polyfill.js";import{SceneDataService as t}from"./scene-data-service.js";import{SceneMaterializer as n}from"./materializer.js";import{basicSceneSetup as i}from"./sky.js";import{NetMode as r}from"../gameplay/net/net-session.js";export async function loadScene(a,s,o,c,m,
|
|
1
|
+
import{polyfill as e}from"../utils/polyfill.js";import{SceneDataService as t}from"./scene-data-service.js";import{SceneMaterializer as n}from"./materializer.js";import{basicSceneSetup as i}from"./sky.js";import{NetMode as r}from"../gameplay/net/net-session.js";export async function loadScene(a,s,o,c,m,p,d,l,f,w,j){e();const{scene:y,renderer:h,camera:u}=a,S=new Set(y.children);i(y);const b=await l.getScene(s);if(null==b)throw Error(`Could not find scene with name ${s}`);const g=await l.getSceneData(b.id),v=new t,O=Object.entries(c).map(([e,t])=>({name:e,type:t})),z=Object.entries(m).map(([e,t])=>({name:e,type:t})),E=Object.entries(p).map(([e,t])=>({name:e,type:t})),I=new n(y,v,f,w,a,O,z,d,E);I.inEditor=!1,I.detailTier=j?.detailTier,I.netMode=j?.nodeMode??r.none;const M=j?.persistence?.enabled?await I.preparePersistence(j.persistence,b.id,g):g;return v.initiate(M),await I.initWithInstancing(),{scene:y,view:a,materializer:I,assetResourceLoader:w,assetsService:f,actors:I.actorInstances,sceneRoots:y.children.filter(e=>!S.has(e))}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -6,6 +6,7 @@ import { VisualEffect } from '../effects/vfx/vfx-param.js';
|
|
|
6
6
|
import { DataAssetRef } from './objects/data-asset.js';
|
|
7
7
|
import { GameComponent } from '../game-component/game-component.js';
|
|
8
8
|
import { BaseActor } from '../gameplay/actors/actor.js';
|
|
9
|
+
import type { ActorPersistence } from '../gameplay/services/actor-persistence.js';
|
|
9
10
|
import { ActorComponent } from '../gameplay/actors/component.js';
|
|
10
11
|
import { PhysicsBodyType } from '../gameplay/services/physics/physics-system.js';
|
|
11
12
|
import { NetMode } from '../gameplay/net/net-session.js';
|
|
@@ -363,6 +364,15 @@ export declare class SceneMaterializer {
|
|
|
363
364
|
private paintedScatterManager?;
|
|
364
365
|
private surfaceScatterManager?;
|
|
365
366
|
materializedActors: Map<string, BaseActor>;
|
|
367
|
+
private persistence?;
|
|
368
|
+
private persistenceSceneId?;
|
|
369
|
+
private readonly authoredPersistenceTargets;
|
|
370
|
+
private readonly authoredPersistenceParents;
|
|
371
|
+
/** Index prefab exposure and scene ancestry before filtering removed objects. */
|
|
372
|
+
preparePersistence(persistence: ActorPersistence, sceneId: string, objects: SceneObject[]): Promise<SceneObject[]>;
|
|
373
|
+
private persistenceActorPath;
|
|
374
|
+
private isPersistenceRemoved;
|
|
375
|
+
registerPersistentActors(): BaseActor[];
|
|
366
376
|
idToSceneObject: Map<string, SceneObject>;
|
|
367
377
|
inEditor: boolean;
|
|
368
378
|
netMode: NetMode;
|