@hology/core 0.0.223 → 0.0.224
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/LICENSE.md +14 -14
- package/README.md +2 -2
- package/dist/gameplay/actors/camera/third-person-camera-component.d.ts +1 -0
- package/dist/gameplay/actors/camera/third-person-camera-component.js +1 -1
- package/dist/rendering.d.ts +19 -5
- package/dist/rendering.js +1 -1
- package/dist/shader/graph/compiler.d.ts +1 -0
- package/dist/shader/graph/compiler.js +1 -1
- package/dist/test/first-person-camera-component.test.js +1 -1
- package/dist/test/shader-graph.test.js +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/LICENSE.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# Hology Interactive AB Limited License
|
|
2
|
-
|
|
3
|
-
This software package, including all associated files and documentation (the "Software"), is licensed to you (the "Licensee") by Hology Interactive AB for use exclusively with the product "Hology Engine."
|
|
4
|
-
|
|
5
|
-
By using, copying, modifying, or distributing the Software, Licensee agrees to be bound by the terms of this license.
|
|
6
|
-
|
|
7
|
-
1. License Grant: Hology Interactive AB grants Licensee a limited, non-exclusive, non-transferable license to use the Software solely for the purpose of developing and running software developed with "Hology Engine."
|
|
8
|
-
|
|
9
|
-
2. Restrictions: Licensee may not use, copy, modify, or distribute the Software for any other purpose, including but not limited to the creation of derivative works, standalone applications, or any products not directly associated with "Hology Engine."
|
|
10
|
-
|
|
11
|
-
3. Ownership: Hology Interactive AB retains all intellectual property rights to the Software. This license does not transfer ownership of the Software to Licensee.
|
|
12
|
-
|
|
13
|
-
4. Warranty Disclaimer: THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE CREATOR OF THIS PACKAGE BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE.
|
|
14
|
-
|
|
1
|
+
# Hology Interactive AB Limited License
|
|
2
|
+
|
|
3
|
+
This software package, including all associated files and documentation (the "Software"), is licensed to you (the "Licensee") by Hology Interactive AB for use exclusively with the product "Hology Engine."
|
|
4
|
+
|
|
5
|
+
By using, copying, modifying, or distributing the Software, Licensee agrees to be bound by the terms of this license.
|
|
6
|
+
|
|
7
|
+
1. License Grant: Hology Interactive AB grants Licensee a limited, non-exclusive, non-transferable license to use the Software solely for the purpose of developing and running software developed with "Hology Engine."
|
|
8
|
+
|
|
9
|
+
2. Restrictions: Licensee may not use, copy, modify, or distribute the Software for any other purpose, including but not limited to the creation of derivative works, standalone applications, or any products not directly associated with "Hology Engine."
|
|
10
|
+
|
|
11
|
+
3. Ownership: Hology Interactive AB retains all intellectual property rights to the Software. This license does not transfer ownership of the Software to Licensee.
|
|
12
|
+
|
|
13
|
+
4. Warranty Disclaimer: THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE CREATOR OF THIS PACKAGE BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE.
|
|
14
|
+
|
|
15
15
|
6. Contact: For any inquiries regarding this license, please email hello@hology.app
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# Hology Engine Core
|
|
2
|
-
|
|
1
|
+
# Hology Engine Core
|
|
2
|
+
|
|
3
3
|
For the development with Hology Engine (https://hology.app/)
|
|
@@ -33,6 +33,7 @@ export declare class ThirdPersonCameraComponent extends ActorComponent {
|
|
|
33
33
|
autoActivate: boolean;
|
|
34
34
|
bounceBackSpeed: number;
|
|
35
35
|
private restrictedDistance;
|
|
36
|
+
private hasCollisionRestriction;
|
|
36
37
|
readonly rotationInput: RestrictedRotationInput;
|
|
37
38
|
readonly zoomInput: DecimalInput;
|
|
38
39
|
private readonly offset;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as o}from"tslib";import{ActorComponent as e,Component as i}from"../component.js";import{Vector3 as s,MathUtils as r,PerspectiveCamera as n,Object3D as h}from"three";import{ViewController as a}from"../../services/render.js";import{DecimalInput as l,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as m}from"../../services/physics/physics-system.js";import{Parameter as p}from"../../../shader/parameter.js";import{World as d}from"../../services/world.js";import{inject as u}from"../../inject.js";import{ease as y}from"@hology/nebula";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let v=class extends e{constructor(){super(),this.viewController=u(a),this.physicsSystem=u(m),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.collision=!0,this.collisionSphereRadius=.25,this.smoothCamera=!1,this.smoothSpeed=10,this.teleportSnapDistance=5,this.camera=new n(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetY=2,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=3,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new l(1,0,1),this.offset=new s,this.lookAtOffset=new s(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(d),this.activated=!1,this.isMouseLocked=!1,this.prevFixedBehind=!1,this.blendDurationLeft=0,this.pointerEventsRegistered=!1,this.temporaryControlActive=!1,this.temporaryControlWeight=0,this.temporaryControlTargetWeight=0,this.temporaryControlBlendInDuration=.5,this.temporaryControlBlendOutDuration=.5,this.temporaryControlPositionEnabled=!1,this.temporaryControlBaseFieldOfView=this.camera.fov,this.temporaryControlFieldOfView=null,this.temporaryControlPosition=new s,this.temporaryControlLookAt=new s,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.element.style.cursor=this.isMouseLocked?"none":"default",this.isMouseLocked||(this.pointerLockInactivatedAt=performance.now())},this.prevLookAt=new s,this.smoothedLookAt=new s,this.previousTargetLookAt=new s,this.hasSmoothedLookAt=!1,this.smoothedRotX=0,this.smoothedRotY=0,this.smoothZoom=0}async onInit(){this.prevFixedBehind=this.fixedBehind,this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.smoothedRotX=this.rotationInput.rotation.x,this.smoothedRotY=this.rotationInput.rotation.y,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.smoothZoom=this.zoomInput.value,this.autoActivate&&this.activate(),this.disposed.subscribe(()=>{this.unregisterPointerEvents()})}activate(){this.activated=!0,this.hasSmoothedLookAt=!1,this.viewController.setCamera(this.camera),this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.registerPointerEvents()}deactivate(){this.activated=!1,this.isMouseLocked=!1,this.unregisterPointerEvents()}setTemporaryControl(t,o,e={}){this.temporaryControlPosition.copy(t),this.temporaryControlLookAt.copy(o),this.temporaryControlPositionEnabled=!0,this.activateTemporaryControl(e)}setTemporaryLookAt(t,o={}){this.temporaryControlLookAt.copy(t),this.temporaryControlPositionEnabled=!1,this.activateTemporaryControl(o)}activateTemporaryControl(t){this.temporaryControlActive||(this.temporaryControlBaseFieldOfView=this.camera.fov),this.temporaryControlFieldOfView=null==t.fieldOfView?null:r.clamp(t.fieldOfView,1,179),null!=t.blendInDuration&&(this.temporaryControlBlendInDuration=Math.max(0,t.blendInDuration)),null!=t.blendOutDuration&&(this.temporaryControlBlendOutDuration=Math.max(0,t.blendOutDuration)),this.temporaryControlActive=!0,this.temporaryControlTargetWeight=1}clearTemporaryControl(t){this.temporaryControlActive&&(null!=t&&(this.temporaryControlBlendOutDuration=Math.max(0,t)),this.temporaryControlTargetWeight=0)}registerPointerEvents(){if(this.pointerEventsRegistered||null==document.body.requestPointerLock)return;const t=this.element;t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!0}unregisterPointerEvents(){if(!this.pointerEventsRegistered)return;const t=this.element;t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!1}onLateUpdate(t){this.activated&&this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor({ignoreRecentUnlock:t=!1}={}){!t&&null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&this.canvas.requestPointerLock&&this.requestPointerLock())}requestPointerLock(){try{const t=this.canvas.requestPointerLock({unadjustedMovement:!0});t?.catch(()=>this.onPointerLockChange())}catch{this.onPointerLockChange()}}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",null==document.pointerLockElement&&null==document.mozPointerLockElement||window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.fixedBehind!==this.prevFixedBehind?(this.blendDurationLeft=1,this.prevFixedBehind=this.fixedBehind):this.blendDurationLeft>0&&(this.blendDurationLeft-=t),this.collision&&this.checkForCollision(t);let o=this.zoomInput.value,e=this.rotationInput.rotation.x,i=this.rotationInput.rotation.y;if(this.smoothCamera){const s=1-Math.exp(-this.smoothSpeed*t*2);this.smoothedRotX=r.lerp(this.smoothedRotX,e,s),this.smoothedRotY=r.lerp(this.smoothedRotY,i,s),e=this.smoothedRotX,i=this.smoothedRotY,this.smoothZoom=r.lerp(this.smoothZoom,o,.4*s),o=this.smoothZoom}else this.smoothedRotX=e,this.smoothedRotY=i;const s=r.clamp(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*o,this.minDistance)),n=Math.cos(e)*s,h=this.fixedBehind?0:i;this.offset.x=Math.sin(-h)*n,this.offset.y=Math.sin(e)*s+this.offsetY,this.offset.z=Math.cos(-h)*-n,this.fixedBehind&&this.offset.add(this.lookAtOffset),this.updateCameraPosition(t)}checkForCollision(t){const o=this.getLookAtPosition(),e=this.camera.getWorldPosition(A),i=L.subVectors(e,o),s=i.length();if(s<.001)return;i.divideScalar(s);const n=this.physicsSystem.sphereCast(o,this.collisionSphereRadius,i,this.distance,void 0,{excludeActor:this.actor,excludeTriggers:!0,collisionFilter:-2});if(n.hasHit){const o=Math.max(this.minDistance,n.distance-.05);o<this.restrictedDistance?this.restrictedDistance=o:this.restrictedDistance=r.lerp(this.restrictedDistance,o,r.clamp(this.bounceBackSpeed*t,0,1))}else this.restrictedDistance=r.lerp(this.restrictedDistance,this.distance,r.clamp(this.bounceBackSpeed*t,0,1))}getLookAtPosition(){const t=k;return t.set(0,0,0),t.y=this.height,this.fixedBehind&&t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(t){this.actor.object.updateWorldMatrix(!0,!1),this.fixedBehind?(C.position.set(this.offset.x,this.offset.y,this.offset.z),C.rotation.set(0,0,0),C.scale.set(1,1,1),C.applyMatrix4(this.actor.object.matrix)):C.position.copy(this.actor.position).add(this.offset);const o=y.easeInOutCubic(1-this.blendDurationLeft);if(this.blendDurationLeft>0){const t=this.getLookAtPosition();this.prevLookAt.lerp(t,o),this.camera.lookAt(this.prevLookAt),this.camera.position.lerp(C.position,o),this.smoothedLookAt.copy(this.prevLookAt),this.previousTargetLookAt.copy(t),this.hasSmoothedLookAt=!0}else{const o=this.getLookAtPosition();if(this.smoothCamera){const e=1-Math.exp(-this.smoothSpeed*t),i=Math.max(0,this.teleportSnapDistance);!this.hasSmoothedLookAt||this.previousTargetLookAt.distanceToSquared(o)>i*i?this.smoothedLookAt.copy(o):this.smoothedLookAt.lerp(o,e)}else this.smoothedLookAt.copy(o);this.previousTargetLookAt.copy(o),this.hasSmoothedLookAt=!0,g.subVectors(C.position,o),this.camera.position.copy(this.smoothedLookAt).add(g),this.camera.lookAt(this.smoothedLookAt),this.prevLookAt.copy(this.smoothedLookAt)}this.applyTemporaryControl(t)}applyTemporaryControl(t){if(!this.temporaryControlActive)return;this.temporaryControlTargetWeight>this.temporaryControlWeight?this.temporaryControlWeight=0===this.temporaryControlBlendInDuration?1:Math.min(1,this.temporaryControlWeight+t/this.temporaryControlBlendInDuration):this.temporaryControlTargetWeight<this.temporaryControlWeight&&(this.temporaryControlWeight=0===this.temporaryControlBlendOutDuration?0:Math.max(0,this.temporaryControlWeight-t/this.temporaryControlBlendOutDuration));const o=y.easeInOutCubic(this.temporaryControlWeight);this.temporaryControlPositionEnabled&&this.camera.position.lerp(this.getTemporaryControlPosition(),o),D.position.copy(this.camera.position),D.up.copy(this.camera.up),D.lookAt(this.temporaryControlLookAt),this.camera.quaternion.slerp(D.quaternion,o);const e=this.temporaryControlFieldOfView??this.temporaryControlBaseFieldOfView,i=r.lerp(this.temporaryControlBaseFieldOfView,e,o);this.camera.fov!==i&&(this.camera.fov=i,this.camera.updateProjectionMatrix()),0===this.temporaryControlTargetWeight&&0===this.temporaryControlWeight&&(this.temporaryControlActive=!1)}getTemporaryControlPosition(){if(!this.collision)return this.temporaryControlPosition;w.subVectors(this.temporaryControlPosition,this.temporaryControlLookAt);const t=w.length();if(t<.001)return this.temporaryControlPosition;w.divideScalar(t);const o=this.physicsSystem.sphereCast(this.temporaryControlLookAt,this.collisionSphereRadius,w,t,void 0,{excludeActor:this.actor,excludeTriggers:!0,collisionFilter:-2});return!o.hasHit||o.distance>=t?this.temporaryControlPosition:x.copy(this.temporaryControlLookAt).addScaledVector(w,Math.max(0,o.distance-.05))}};t([p(),o("design:type",Number)],v.prototype,"near",void 0),t([p(),o("design:type",Number)],v.prototype,"far",void 0),t([p(),o("design:type",Number)],v.prototype,"viewAngle",void 0),t([p(),o("design:type",Boolean)],v.prototype,"collision",void 0),t([p(),o("design:type",Number)],v.prototype,"collisionSphereRadius",void 0),t([p(),o("design:type",Boolean)],v.prototype,"smoothCamera",void 0),t([p(),o("design:type",Number)],v.prototype,"smoothSpeed",void 0),t([p(),o("design:type",Number)],v.prototype,"teleportSnapDistance",void 0),v=t([i(),o("design:paramtypes",[])],v);export{v as ThirdPersonCameraComponent};const C=new h,k=new s,g=new s,L=new s,A=(new s,new s),w=new s,x=new s,D=new n;export class ThirdPartyCameraComponent extends v{}/*
|
|
1
|
+
import{__decorate as t,__metadata as o}from"tslib";import{ActorComponent as e,Component as i}from"../component.js";import{Vector3 as s,MathUtils as r,PerspectiveCamera as n,Object3D as h}from"three";import{ViewController as a}from"../../services/render.js";import{DecimalInput as l,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as p}from"../../services/physics/physics-system.js";import{Parameter as m}from"../../../shader/parameter.js";import{World as d}from"../../services/world.js";import{inject as u}from"../../inject.js";import{ease as y}from"@hology/nebula";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let v=class extends e{constructor(){super(),this.viewController=u(a),this.physicsSystem=u(p),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.collision=!0,this.collisionSphereRadius=.25,this.smoothCamera=!1,this.smoothSpeed=10,this.teleportSnapDistance=5,this.camera=new n(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetY=2,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=3,this.restrictedDistance=0,this.hasCollisionRestriction=!1,this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new l(1,0,1),this.offset=new s,this.lookAtOffset=new s(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(d),this.activated=!1,this.isMouseLocked=!1,this.prevFixedBehind=!1,this.blendDurationLeft=0,this.pointerEventsRegistered=!1,this.temporaryControlActive=!1,this.temporaryControlWeight=0,this.temporaryControlTargetWeight=0,this.temporaryControlBlendInDuration=.5,this.temporaryControlBlendOutDuration=.5,this.temporaryControlPositionEnabled=!1,this.temporaryControlBaseFieldOfView=this.camera.fov,this.temporaryControlFieldOfView=null,this.temporaryControlPosition=new s,this.temporaryControlLookAt=new s,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.element.style.cursor=this.isMouseLocked?"none":"default",this.isMouseLocked||(this.pointerLockInactivatedAt=performance.now())},this.prevLookAt=new s,this.smoothedLookAt=new s,this.previousTargetLookAt=new s,this.hasSmoothedLookAt=!1,this.smoothedRotX=0,this.smoothedRotY=0,this.smoothZoom=0}async onInit(){this.prevFixedBehind=this.fixedBehind,this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.smoothedRotX=this.rotationInput.rotation.x,this.smoothedRotY=this.rotationInput.rotation.y,this.hasCollisionRestriction=!1,this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.smoothZoom=this.zoomInput.value,this.autoActivate&&this.activate(),this.disposed.subscribe(()=>{this.unregisterPointerEvents()})}activate(){this.activated=!0,this.hasSmoothedLookAt=!1,this.viewController.setCamera(this.camera),this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.registerPointerEvents()}deactivate(){this.activated=!1,this.isMouseLocked=!1,this.unregisterPointerEvents()}setTemporaryControl(t,o,e={}){this.temporaryControlPosition.copy(t),this.temporaryControlLookAt.copy(o),this.temporaryControlPositionEnabled=!0,this.activateTemporaryControl(e)}setTemporaryLookAt(t,o={}){this.temporaryControlLookAt.copy(t),this.temporaryControlPositionEnabled=!1,this.activateTemporaryControl(o)}activateTemporaryControl(t){this.temporaryControlActive||(this.temporaryControlBaseFieldOfView=this.camera.fov),this.temporaryControlFieldOfView=null==t.fieldOfView?null:r.clamp(t.fieldOfView,1,179),null!=t.blendInDuration&&(this.temporaryControlBlendInDuration=Math.max(0,t.blendInDuration)),null!=t.blendOutDuration&&(this.temporaryControlBlendOutDuration=Math.max(0,t.blendOutDuration)),this.temporaryControlActive=!0,this.temporaryControlTargetWeight=1}clearTemporaryControl(t){this.temporaryControlActive&&(null!=t&&(this.temporaryControlBlendOutDuration=Math.max(0,t)),this.temporaryControlTargetWeight=0)}registerPointerEvents(){if(this.pointerEventsRegistered||null==document.body.requestPointerLock)return;const t=this.element;t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!0}unregisterPointerEvents(){if(!this.pointerEventsRegistered)return;const t=this.element;t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!1}onLateUpdate(t){this.activated&&this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor({ignoreRecentUnlock:t=!1}={}){!t&&null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&this.canvas.requestPointerLock&&this.requestPointerLock())}requestPointerLock(){try{const t=this.canvas.requestPointerLock({unadjustedMovement:!0});t?.catch(()=>this.onPointerLockChange())}catch{this.onPointerLockChange()}}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",null==document.pointerLockElement&&null==document.mozPointerLockElement||window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.fixedBehind!==this.prevFixedBehind?(this.blendDurationLeft=1,this.prevFixedBehind=this.fixedBehind):this.blendDurationLeft>0&&(this.blendDurationLeft-=t);let o=this.zoomInput.value,e=this.rotationInput.rotation.x,i=this.rotationInput.rotation.y;if(this.smoothCamera){const s=1-Math.exp(-this.smoothSpeed*t*2);this.smoothedRotX=r.lerp(this.smoothedRotX,e,s),this.smoothedRotY=r.lerp(this.smoothedRotY,i,s),e=this.smoothedRotX,i=this.smoothedRotY,this.smoothZoom=r.lerp(this.smoothZoom,o,.4*s),o=this.smoothZoom}else this.smoothedRotX=e,this.smoothedRotY=i;const s=r.clamp(this.distance,this.minDistance,Math.max(this.distance*o,this.minDistance)),n=Math.cos(e)*s,h=this.fixedBehind?0:i;this.offset.x=Math.sin(-h)*n,this.offset.y=Math.sin(e)*s+this.offsetY,this.offset.z=Math.cos(-h)*-n,this.fixedBehind&&this.offset.add(this.lookAtOffset),this.updateCameraPosition(t)}checkForCollision(t,o){const e=g.subVectors(this.camera.position,t),i=e.length();if(i<.001)return;e.divideScalar(i);const s=this.physicsSystem.sphereCast(t,this.collisionSphereRadius,e,i,void 0,{excludeActor:this.actor,excludeTriggers:!0,collisionFilter:-2}),n=s.hasHit?Math.max(this.minDistance,s.distance-.05):i;if(!this.hasCollisionRestriction||n<=this.restrictedDistance)this.restrictedDistance=n,this.hasCollisionRestriction=!0;else{const t=1-Math.exp(-this.bounceBackSpeed*o);this.restrictedDistance=r.lerp(this.restrictedDistance,n,t)}this.camera.position.copy(t).addScaledVector(e,Math.min(i,this.restrictedDistance))}getLookAtPosition(){const t=k;return t.set(0,0,0),t.y=this.height,this.fixedBehind&&t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(t){this.actor.object.updateWorldMatrix(!0,!1),this.fixedBehind?(C.position.set(this.offset.x,this.offset.y,this.offset.z),C.rotation.set(0,0,0),C.scale.set(1,1,1),C.applyMatrix4(this.actor.object.matrix)):C.position.copy(this.actor.position).add(this.offset);const o=y.easeInOutCubic(1-this.blendDurationLeft);if(this.blendDurationLeft>0){const t=this.getLookAtPosition();this.prevLookAt.lerp(t,o),this.camera.lookAt(this.prevLookAt),this.camera.position.lerp(C.position,o),this.smoothedLookAt.copy(this.prevLookAt),this.previousTargetLookAt.copy(t),this.hasSmoothedLookAt=!0}else{const o=this.getLookAtPosition();if(this.smoothCamera){const e=1-Math.exp(-this.smoothSpeed*t),i=Math.max(0,this.teleportSnapDistance);!this.hasSmoothedLookAt||this.previousTargetLookAt.distanceToSquared(o)>i*i?this.smoothedLookAt.copy(o):this.smoothedLookAt.lerp(o,e)}else this.smoothedLookAt.copy(o);this.previousTargetLookAt.copy(o),this.hasSmoothedLookAt=!0,L.subVectors(C.position,o),this.camera.position.copy(this.smoothedLookAt).add(L),this.camera.lookAt(this.smoothedLookAt),this.prevLookAt.copy(this.smoothedLookAt)}this.collision&&(this.checkForCollision(this.prevLookAt,t),this.camera.lookAt(this.prevLookAt)),this.applyTemporaryControl(t)}applyTemporaryControl(t){if(!this.temporaryControlActive)return;this.temporaryControlTargetWeight>this.temporaryControlWeight?this.temporaryControlWeight=0===this.temporaryControlBlendInDuration?1:Math.min(1,this.temporaryControlWeight+t/this.temporaryControlBlendInDuration):this.temporaryControlTargetWeight<this.temporaryControlWeight&&(this.temporaryControlWeight=0===this.temporaryControlBlendOutDuration?0:Math.max(0,this.temporaryControlWeight-t/this.temporaryControlBlendOutDuration));const o=y.easeInOutCubic(this.temporaryControlWeight);this.temporaryControlPositionEnabled&&this.camera.position.lerp(this.getTemporaryControlPosition(),o),x.position.copy(this.camera.position),x.up.copy(this.camera.up),x.lookAt(this.temporaryControlLookAt),this.camera.quaternion.slerp(x.quaternion,o);const e=this.temporaryControlFieldOfView??this.temporaryControlBaseFieldOfView,i=r.lerp(this.temporaryControlBaseFieldOfView,e,o);this.camera.fov!==i&&(this.camera.fov=i,this.camera.updateProjectionMatrix()),0===this.temporaryControlTargetWeight&&0===this.temporaryControlWeight&&(this.temporaryControlActive=!1)}getTemporaryControlPosition(){if(!this.collision)return this.temporaryControlPosition;A.subVectors(this.temporaryControlPosition,this.temporaryControlLookAt);const t=A.length();if(t<.001)return this.temporaryControlPosition;A.divideScalar(t);const o=this.physicsSystem.sphereCast(this.temporaryControlLookAt,this.collisionSphereRadius,A,t,void 0,{excludeActor:this.actor,excludeTriggers:!0,collisionFilter:-2});return!o.hasHit||o.distance>=t?this.temporaryControlPosition:w.copy(this.temporaryControlLookAt).addScaledVector(A,Math.max(0,o.distance-.05))}};t([m(),o("design:type",Number)],v.prototype,"near",void 0),t([m(),o("design:type",Number)],v.prototype,"far",void 0),t([m(),o("design:type",Number)],v.prototype,"viewAngle",void 0),t([m(),o("design:type",Boolean)],v.prototype,"collision",void 0),t([m(),o("design:type",Number)],v.prototype,"collisionSphereRadius",void 0),t([m(),o("design:type",Boolean)],v.prototype,"smoothCamera",void 0),t([m(),o("design:type",Number)],v.prototype,"smoothSpeed",void 0),t([m(),o("design:type",Number)],v.prototype,"teleportSnapDistance",void 0),v=t([i(),o("design:paramtypes",[])],v);export{v as ThirdPersonCameraComponent};const C=new h,k=new s,L=new s,g=new s,A=new s,w=new s,x=new n;export class ThirdPartyCameraComponent extends v{}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
package/dist/rendering.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ export declare class RenderingView {
|
|
|
105
105
|
aoMaskDepthRenderTarget: WebGLRenderTarget;
|
|
106
106
|
depthRenderTarget: WebGLRenderTarget;
|
|
107
107
|
sceneColorRenderTarget: WebGLRenderTarget;
|
|
108
|
+
sceneDepthRenderTarget: WebGLRenderTarget;
|
|
108
109
|
csm: CSM | null;
|
|
109
110
|
private _fpsCap;
|
|
110
111
|
private fpsCapRevision;
|
|
@@ -129,8 +130,8 @@ export declare class RenderingView {
|
|
|
129
130
|
private postProcessEffects;
|
|
130
131
|
private readonly postProcessEffectResolution;
|
|
131
132
|
private readonly postProcessEffectUniformState;
|
|
132
|
-
private
|
|
133
|
-
private
|
|
133
|
+
private fquadCopySceneColor;
|
|
134
|
+
private fquadCopySceneDepth;
|
|
134
135
|
private occlusionClusters;
|
|
135
136
|
simulationTime: number;
|
|
136
137
|
simulationTimeScale: number;
|
|
@@ -214,6 +215,7 @@ export declare class RenderingView {
|
|
|
214
215
|
/** */
|
|
215
216
|
private static createAOMaskDepthRenderTarget;
|
|
216
217
|
private createSceneColorRenderTarget;
|
|
218
|
+
private createSceneDepthRenderTarget;
|
|
217
219
|
private createGRenderTarget;
|
|
218
220
|
private setupEventListeners;
|
|
219
221
|
stop(dispose?: boolean): void;
|
|
@@ -272,9 +274,20 @@ export declare class RenderingView {
|
|
|
272
274
|
private renderDepthPrepass;
|
|
273
275
|
private updateCsm;
|
|
274
276
|
loop(onFrame: (deltaTime: number) => any, showStats?: boolean): void;
|
|
275
|
-
private
|
|
276
|
-
private
|
|
277
|
-
private
|
|
277
|
+
private frameGBufferMeshes;
|
|
278
|
+
private frameGBufferPhaseMasks;
|
|
279
|
+
private frameUnsupportedGBufferObjects;
|
|
280
|
+
private frameGBufferExcludedObjects;
|
|
281
|
+
private appliedGBufferMeshes;
|
|
282
|
+
private originalGBufferMaterials;
|
|
283
|
+
private originalGBufferOnBeforeRender;
|
|
284
|
+
private hiddenGBufferObjects;
|
|
285
|
+
private gBufferPhaseMaskCache;
|
|
286
|
+
private gBufferMaterialArrayCache;
|
|
287
|
+
private gBufferShadowUpdaterCache;
|
|
288
|
+
private collectGBufferRenderables;
|
|
289
|
+
private getGBufferPhaseMask;
|
|
290
|
+
private getGBufferMaterialArray;
|
|
278
291
|
private applyGBufferMaterials;
|
|
279
292
|
private unapplyGBufferMaterials;
|
|
280
293
|
private applyGBufferShadowUniformUpdater;
|
|
@@ -284,6 +297,7 @@ export declare class RenderingView {
|
|
|
284
297
|
private _initMaterialTextures;
|
|
285
298
|
private compileInProgress;
|
|
286
299
|
compileAsync(scene?: Object3D): Promise<void>;
|
|
300
|
+
private depthMaterialCachedMaterials;
|
|
287
301
|
private applyDepthMaterial;
|
|
288
302
|
private unapplyDepthMaterial;
|
|
289
303
|
private renderScene;
|
package/dist/rendering.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as a,Material as n,Matrix4 as r,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as u,WebGLRenderTarget as c,Texture as p,Euler as d,MeshStandardMaterial as m}from"three";import{CopyShader as f,EffectComposer as g,FXAAShader as M,GammaCorrectionShader as v,LUTPass as P,RenderPass as y,ShaderPass as b,VRButton as w}from"three-stdlib";import{CSMShader as T,CSMUtil as x}from"./csm.js";import{colorToNormal as R,float as S,NodeShaderMaterial as C,standardMaterial as U,uniformFloat as A,uniformVec3 as E,toonMaterial as O,lambertMaterial as F,normalize as B,rgb as G,rgba as D,transformed as j,varying as I,varyingAttributes as V,varyingTransformed as L,vec4 as _,BooleanExpression as W,select as N,ifDefApply as q,uniformSampler2d as H,RgbaNode as k,mix as z,attributes as $,uniformVec2 as J,min as Q}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{RectAreaLightUniformsLib as ee}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import te from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as se}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as ie}from"typedi";import{depthUniformName as ae,farUniformName as ne,nearUniformName as re,resolutionUniformName as oe,sceneNormalUniformName as le,screenUV as he,supportsDepthTextureExtension as ue}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as ce}from"./shader-nodes/time.js";import{aoMapUniformName as pe,sceneMapUniformName as de}from"./shader-nodes/scene-sample.js";import{DepthPass as me}from"./utils/three/depth-pass.js";import{GPUStatsPanel as fe}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as ge}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as Me,traverseVisibleStop as ve}from"./utils/three/traverse.js";import{clamp as Pe}from"./utils/math.js";import{ColorPass as ye}from"./rendering/color-pass.js";import{PostProcessEffectPass as be,PostProcessEffectRegistration as we,postProcessEffectStages as Te,sanitizePostProcessEffectPriority as xe,sanitizePostProcessEffectStage as Re}from"./rendering/post-process-effect.js";import{SSRPass as Se}from"./rendering/ssr/SSRPass.js";import{SSRShader as Ce}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as Ue}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as Ae}from"./rendering/outline-effect.js";import{UnrealBloomPass as Ee}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Oe}from"./shader-nodes/depth.js";import{packDepthToRGBA as Fe}from"three-shader-graph";import{FogVolumeObject as Be}from"./rendering/fog/fog-volume-object";import{ParallaxStandardMaterial as Ge}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as De}from"./shader-nodes/pom.js";import{FullScreenQuad as je}from"three-stdlib";import{edgeDepthEffect as Ie}from"./shader-nodes/effects";import{decalDiscard as Ve}from"./shader-nodes/decal.js";import{Pass as Le}from"three/examples/jsm/Addons.js";import{BatchedMesh2 as _e}from"./scene/batched-mesh-2.js";import{applyUvTiling as We}from"./shader/uv-nodes.js";import{createPlaceholderTexture as Ne}from"./utils/three/placeholder-texture.js";import{getTemporalUpscalingJitter as qe,getUpscalingMethod as He,UpscaleOutputPass as ke}from"./rendering/upscaling-pass.js";x.patchSetupMaterial();const ze=document.createElement("div");ze.style.position="absolute",ze.style.left="50%",ze.style.top="50%",ze.style.color="black",ze.style.zIndex="999";(new i.Layers).set(9);const $e=new i.MeshBasicMaterial({color:"black"}),Je=new i.MeshDepthMaterial;var Qe;Je.depthPacking=i.RGBADepthPacking,Je.blending=i.NoBlending,Je.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(Qe||(Qe={}));const Xe=(()=>{const e=new Uint8Array([255,255,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ye=(()=>{const e=new Uint8Array([0,0,0,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ke=(()=>{const e=new Uint8Array([128,128,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ze=new C({color:S(0),position:_(S(0))});Ze.visible=!1;const et=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let tt=0,st=null;const it=new Map;function at(){return null==st&&(st=new IntersectionObserver(e=>{for(const t of e){const e=it.get(t.target);e&&e(t.isIntersecting)}},{threshold:0})),st}let nt=e=class{get fpsCap(){return this._fpsCap}set fpsCap(e){const t=null!=e&&Number.isFinite(e)&&e>0?e:null;t!==this._fpsCap&&(this._fpsCap=t,this.fpsCapRevision++)}setPaused(e){this.paused=e}setResolutionScale(e){const t=gt(e,1);ft(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()))}isUpscalingEnabled(){return!0===this.options.upscaling?.enabled&&!0!==this.options.enableXR}isTemporalUpscalingEnabled(){return this.isUpscalingEnabled()&&"temporal"===He(this.options.upscaling)}resetUpscalingHistory(){this.hasPreviousTemporalViewProjection=!1,this.upscaleOutputPass?.resetHistory()}prepareUpscalingFrame(){if(!this.isTemporalUpscalingEnabled()||null==this.upscaleOutputPass)return void this.upscaleOutputPass?.setFrameState(null);this.unjitteredProjectionMatrix.copy(this.camera.projectionMatrix),this.currentUnjitteredViewProjectionMatrix.multiplyMatrices(this.unjitteredProjectionMatrix,this.camera.matrixWorldInverse),this.hasPreviousTemporalViewProjection||(this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.upscaleOutputPass.resetHistory());const e=gt(this.options.upscaling?.temporal?.jitterScale,1);qe(this.temporalUpscalingFrameIndex++,this.temporalJitter,e),this.temporalJitterUv.set(this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),this.temporalJitter.y/Math.max(1,this.gRenderTarget.height));const t=2*this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),s=2*this.temporalJitter.y/Math.max(1,this.gRenderTarget.height);this.camera instanceof l?(this.camera.projectionMatrix.elements[8]+=t,this.camera.projectionMatrix.elements[9]+=s):(this.camera.projectionMatrix.elements[12]+=t,this.camera.projectionMatrix.elements[13]+=s),this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert(),this.projectionJitterApplied=!0,this.currentViewProjectionMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.currentViewProjectionMatrixInverse.copy(this.currentViewProjectionMatrix).invert(),this.temporalUpscalingFrameState.depthTexture=this.gRenderTarget.depthTexture,this.upscaleOutputPass.setFrameState(this.temporalUpscalingFrameState)}finishUpscalingFrame(){this.projectionJitterApplied&&(this.camera.projectionMatrix.copy(this.unjitteredProjectionMatrix),this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert(),this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.hasPreviousTemporalViewProjection=!0,this.projectionJitterApplied=!1)}getBasePixelRatio(){const e=gt(this.maxPixelRatio,1),t=gt(window.devicePixelRatio,1);return Math.min(e,t)}getBaseResolutionScale(){return gt(this.resolutionScale,1)}getDynamicResolutionMinScale(){const e=this.getBaseResolutionScale(),t=gt(this.options.dynamicResolution?.minScale,.7);return Math.min(e,t)}getEffectiveResolutionScale(){const e=this.getBaseResolutionScale();return!0!==this.options.dynamicResolution?.enabled?e:Pe(this.dynamicResolutionScale,this.getDynamicResolutionMinScale(),e)}getRenderPixelRatio(){return this.getBasePixelRatio()*this.getEffectiveResolutionScale()}getPresentationPixelRatio(){const e=this.getBasePixelRatio();return this.isUpscalingEnabled()?e:e*this.getEffectiveResolutionScale()}resetDynamicResolutionAverage(){this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0}updateDynamicResolution(e,t){const s=this.options.dynamicResolution;if(!0!==s?.enabled)return;if(!Number.isFinite(e)||e<=0||e>.25)return void this.resetDynamicResolutionAverage();const i=this.getBaseResolutionScale(),a=this.getDynamicResolutionMinScale(),n=Pe(this.dynamicResolutionScale,a,i);ft(n,this.dynamicResolutionScale)||(this.dynamicResolutionScale=n);const r=gt(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(gt(s.sampleFrames,20)));if(this.dynamicResolutionFrameSamples<h)return;const u=gt(s.decreaseCooldown,500),c=gt(s.increaseCooldown,2e3),p=gt(s.decreaseStep,.05),d=gt(s.increaseStep,.025),m=this.dynamicResolutionFrameTimeAverage;let f=n;m>1.12*o&&n>a&&t-this.dynamicResolutionLastAdjustmentAt>=u?f=Math.max(a,n-p):m<.85*o&&n<i&&t-this.dynamicResolutionLastAdjustmentAt>=c&&(f=Math.min(i,n+d)),ft(f,n)||(this.dynamicResolutionScale=f,this.dynamicResolutionLastAdjustmentAt=t,this.resetDynamicResolutionAverage(),this.resizeRender(!0))}resizeRender(e=!1){if(!this.running)return;const t=this.container.clientWidth,s=this.container.clientHeight,i=this.getRenderPixelRatio(),a=this.getPresentationPixelRatio();if(!e&&this.previousClientWith===t&&this.previousClientHeight===s&&this.previousRenderPixelRatio===i&&this.previousPresentationPixelRatio===a)return;if(0===t||0===s)return;this.previousClientWith=t,this.previousClientHeight=s,this.previousRenderPixelRatio=i,this.previousPresentationPixelRatio=a,this.camera instanceof l&&(this.camera.aspect=t/s,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(a),this.renderer.setSize(t,s),this.composer.setPixelRatio(i),this.composer.setSize(t,s);const 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.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0,this.resetDynamicResolutionAverage(),this.resetUpscalingHistory()}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}addPostProcessEffect(e,t={}){const s={id:++this.postProcessEffectId,pass:new be(e),priority:xe(t.priority),stage:Re(t.stage)};return s.pass.enabled=t.enabled??!0,this.postProcessEffects.push(s),this.refreshPostProcessEffectPassOrder(),new we(this,s)}removePostProcessEffectEntry(e){const t=e,s=this.postProcessEffects.indexOf(t);-1!==s&&(this.postProcessEffects.splice(s,1),this.composer.removePass(t.pass),t.pass.dispose())}refreshPostProcessEffectPassOrder(){for(const e of this.postProcessEffects)this.composer.removePass(e.pass);for(const e of Te){const t=this.getPostProcessEffectStageAnchorPass(e),s=null!=t?this.composer.passes.indexOf(t):this.composer.passes.length,i=this.postProcessEffects.filter(t=>t.stage===e).sort(lt);for(let e=0;e<i.length;e++)this.composer.insertPass(i[e].pass,s+e)}}getPostProcessEffectStageAnchorPass(e){switch(e){case"beforeFog":return this.volumetricFogPass;case"beforeDepthOfField":return this.dofPass;case"beforeColorAdjustment":return this.colorPass;case"beforeOutline":return this.outlinePass;case"beforeAntiAliasing":return this.fxaaPass;case"beforeLut":return this.lutPass;case"beforeOutput":return this.outputPass}}constructor(t,s={}){this.container=t,this.options=s,this.isIntersecting=!1,this.needsPausedRender=!1,this.wakePausedRenderer=null,this.windowVisible=!0,this.queryScene=new i.Scene,this.running=!0,this.paused=!1,this._fpsCap=null,this.fpsCapRevision=0,this.postProcessVolumes=[],this.postProcessSettings={},this.baseToneMapping=i.NoToneMapping,this.baseToneMappingExposure=1,this.csmUpdateInvervals=this.options.shadows?.cascadeUpdateIntervals,this._id=tt++,this.postProcessEffectId=0,this.postProcessEffects=[],this.postProcessEffectResolution=new i.Vector2(1,1),this.postProcessEffectUniformState={aoEnabled:!1,aoTexture:null,cameraFar:void 0,cameraNear:void 0,depthTexture:Ne(),normalTexture:Ne(128,128,255),resolution:this.postProcessEffectResolution,simulationTime:0},this.fquadCopy=new je(new u(f)),this.fquadCopyOpaque=new je(new C({outputs:[H("tSceneColor",Ne()).sample(V.uv),_(H("tDepthTexture",new i.DepthTexture(1,1)).sample(V.uv).r)]})),this.occlusionClusters=[],this.simulationTime=0,this.simulationTimeScale=1,this.lightProbeIntensity=2,this.fquadBlendAO=(()=>{const e=_(1),t=Ne(),s=H("tAlphaTest",t).sample(he).a,a=H("tAO",t).sample(he),n=N(s.lt(.05),a,Q(_(1,1,1,1),a.addScalar(.4))),r=new C({outputs:[n,e,e],transparent:!0});r.depthWrite=!1,r.depthTest=!1,r.blending=i.MultiplyBlending;return new je(r)})(),this.resolutionScale=1,this.maxPixelRatio=et?1:window.devicePixelRatio,this.dynamicResolutionScale=1,this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0,this.dynamicResolutionLastAdjustmentAt=0,this.upscaleOutputPass=null,this.unjitteredProjectionMatrix=new r,this.temporalJitter=new i.Vector2,this.temporalJitterUv=new i.Vector2,this.currentUnjitteredViewProjectionMatrix=new r,this.currentViewProjectionMatrix=new r,this.currentViewProjectionMatrixInverse=new r,this.previousViewProjectionMatrix=new r,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.onLoopCallbacks=[],this.stats=new te,this._showStats=!1,this.gbufferMaterialCache=new Map,this.gbufferDepthPrepassMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.depthPrepassMaterialCache=new WeakMap,this.depthPrepassCachedMaterials=new Map,this.depthPrepassCachedVisibility=[],this.gBufferCachedMaterials=new Map,this.gBufferCachedVisibility=[],this.gBufferCachedOnBeforeRender=new Map,this._initiatedMaterialTextures=new Set,this._initiatedTextures=new Set,this.compileInProgress=!1,this.pmremGeneratorResults=new WeakMap,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new a,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],this._customDepthMaterialCache=new WeakMap,null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),this.resolutionScale=s.resolutionScale??1,this.dynamicResolutionScale=this.getBaseResolutionScale(),this.fpsCap=s.fpsCap,e.activeView=this,ee.init(),window.renderer=this.renderer=window.renderer??new i.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});new i.MeshStandardMaterial({color:"#ccc"});this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,this.scene.updateMatrixWorld=function(e){const t=this.children;for(let s=0,i=t.length;s<i;s++){t[s].updateMatrixWorld(e)}}.bind(this.scene),this.renderer.setPixelRatio(this.getPresentationPixelRatio()),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(w.createButton(this.renderer));const n=new Ae(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=n,this.createGRenderTarget(),this.composer=new g(this.renderer,function(e,t){const s=new i.WebGLRenderTarget(Math.max(1,e),Math.max(1,t),{minFilter:i.LinearFilter,magFilter:i.LinearFilter,format:i.RGBAFormat,type:i.HalfFloatType});return s.texture.name="EffectComposer.rt1",s.texture.generateMipmaps=!1,s}(t.clientWidth,t.clientHeight)),this.composer.setPixelRatio(this.getRenderPixelRatio()),this.composer.setSize(t.clientWidth,t.clientHeight);var l=(t.clientWidth||1)/(t.clientHeight||1);const h=new i.PerspectiveCamera(45,l,.5,800);h.layers.enable(19),this.setCamera(h),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.baseToneMapping=this.renderer.toneMapping,this.baseToneMappingExposure=this.renderer.toneMappingExposure,this.renderer.gammaFactor=1.4,x.renderingView=this,this.isDepthTextureExtensionSupported=ue(this.renderer),this.attachRendererDomElement(),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container,this.getRenderPixelRatio()),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container);const c=new i.Vector2(t.clientWidth,t.clientHeight),p=(new y(this.scene,this.camera),new b(f,"prevtexture"));p.enabled=!0,p.needsSwap=!0,p.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=p;const d=new Ee(c,1.5,.4,.85);d.threshold=1,d.strength=.9,d.radius=.2,this.bloomPass=d;const m=new se(this.scene,this.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});m.normalRenderTarget?.dispose(),m.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),m.output=se.OUTPUT.Off,m.enabled=!1,this.aoPass=m,this.fquadBlendAO.material.uniforms.tAO.value=m.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 T=new Se({renderer:this.renderer,scene:this.scene,camera:this.camera,width:this.gRenderTarget.width,height:this.gRenderTarget.height,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[2],depthTexture:this.gRenderTarget.depthTexture});T.output=Se.OUTPUT.Default,T.blur=!0,T.fresnel=!1,T.distanceAttenuation=!0,T.maxDistance=50,T.selective=!0,T.bouncing=!1,T.opacity=.4,T.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=T,!1!==this.options.ao?.enabled&&this.composer.addPass(m);const R=new At((e,t,s,i,a)=>{this.aoPass.enabled&&(this.initResolutionUniform(this.fquadBlendAO.material),this.renderer.setRenderTarget(this.gRenderTarget),this.fquadBlendAO.render(this.renderer),this.renderer.setRenderTarget(null))});this.composer.addPass(R);const S=new At((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(Qe.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(S),this.composer.addPass(p),this.composer.addPass(T),this.phasedRenderPass=new Ut(this.scene,this.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(d),d.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.volumetricFogPass=new Ue(c),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 U=new ye;this.composer.addPass(U),this.colorPass=U,U.vignetteEnabled=!1,this.outlinePass=new ge(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const A=new b(M);A.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(A),this.fxaaPass=A,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new b(v).clear=!1,this.fixStatsStyle(),this.lutPass=new P({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const E=new b(f,"prevtexture");E.enabled=!0,E.needsSwap=!1,E.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],E.renderToScreen=!0;const O=this.isUpscalingEnabled()?new ke(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)}(O),this.outputPass=O,this.upscaleOutputPass=O instanceof ke?O:null,this.composer.addPass(O);const F=new i.MeshBasicMaterial({colorWrite:!1,depthWrite:!1,depthTest:!0,transparent:!1}),B=new o(new i.BoxGeometry(1,1,1),F);B.renderOrder=1/0,B.name="CLUSTER_BOUNDS_VOLUME"}addCluster(e){if(!1===this.options.occlusionCulling?.enabled)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))&&ut.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";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){if(this.camera=e,this.resetUpscalingHistory(),this.composer.passes.forEach(t=>{t instanceof y?t.camera=e:t instanceof ge?t.renderCamera=e:(t instanceof me||t instanceof se)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),this.phasedRenderPass&&(this.phasedRenderPass.camera=e),null==this.csm){if(this.csm=new Z({maxFar:80,lightFar:250,lightMargin:20,cascades:et?2:3,shadowMapSize:1024*(et?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"}),null!=this.csmUpdateInvervals){this.csmCascadeLastUpdate=new Array(this.csm.lights.length).fill(0);for(const e of this.csm.lights)e.shadow.autoUpdate=!1}this.csm&&Array.isArray(this.csm.lights),this.csm.fade=!0,h.lights_fragment_begin=T.lights_fragment_begin}else this.csm.camera=this.camera,this.camera;this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse(e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)});this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t,s){const a=Math.max(1,Math.floor(t.clientWidth*s)),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(e,t){const s=this.gRenderTarget.width,a=this.gRenderTarget.height,n=new i.WebGLRenderTarget(s,a,{count:2,type:i.FloatType,format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return n.texture.minFilter=i.LinearFilter,n.texture.magFilter=i.LinearFilter,n.texture.generateMipmaps=!1,n.textures[1].minFilter=i.NearestFilter,n.textures[1].magFilter=i.NearestFilter,n}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 c(s,a,{count:3,samples:this.options?.msaa??(et?void 0:2),minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat,depthTexture:n}),this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(e=!0){this.running=!1,this.wakePausedRenderer=null,this.lightVolume?.shTexture.dispose(),window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],e&&this.renderer.dispose(),this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose();for(const e of this.postProcessEffects)this.composer.removePass(e.pass),e.pass.dispose();this.postProcessEffects.length=0,this.detachOwnedDomElements();if(at().unobserve(this.container),it.delete(this.container),this.occlusionClusters.length>0){const e=this.renderer.getContext();this.occlusionClusters.forEach(t=>{e.deleteQuery(t.query)})}this.volumetricFogPass.dispose(),x.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.findIndex(t=>t===e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&this.stats.dom.parentElement!==this.container?this.container.appendChild(this.stats.dom):this._showStats||this.stats.dom.parentElement!==this.container||this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}attachRendererDomElement(){const e=this.renderer.domElement;e.parentElement===this.container&&e===this.container.firstChild||this.container.insertBefore(e,this.container.firstChild),this._showStats&&this.stats.dom.parentElement!==this.container&&this.container.appendChild(this.stats.dom)}detachOwnedDomElements(){this.renderer.domElement.parentElement===this.container&&this.container.removeChild(this.renderer.domElement),this.stats.dom.parentElement===this.container&&this.container.removeChild(this.stats.dom)}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof C&&(null==e.envMap||e.userData.useSceneEnv)&&(e.userData.useSceneEnv=!0,null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment},e.uniformsNeedUpdate=!0,e.uniforms.envMapRotation={value:Tt(this.scene.environmentRotation,this.scene.environment,new i.Matrix3)}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1},e.uniformsNeedUpdate=!0),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment),e instanceof C||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}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 m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(null!=t.uniforms.color&&t.uniforms.color.value.setFromColor(e.color),null!=t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),null!=t.uniforms.map&&(t.uniforms.map.value=e.map),null!=t.uniforms.alphaMap&&(t.uniforms.alphaMap.value=e.alphaMap),null!=t.uniforms.lightMap&&(t.uniforms.lightMap.value=e.lightMap,t.uniforms.lightMapIntensity.value=e.lightMapIntensity),null!=t.uniforms.aoMap&&(t.uniforms.aoMap.value=e.aoMap,t.uniforms.aoMapIntensity.value=e.aoMapIntensity),null!=t.uniforms.alphaTest&&(t.uniforms.alphaTest.value=e.alphaTest)),(e instanceof m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(t.uniforms.normalMap&&(t.uniforms.normalMap.value=e.normalMap,t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.emissiveMap&&(t.uniforms.emissiveMap.value=e.emissiveMap,t.uniforms.emissive.value.setFromColor(e.emissive),t.uniforms.emissiveIntensity.value=e.emissiveIntensity)),e instanceof m&&(null!=t.uniforms.roughnessMap&&(t.uniforms.roughnessMap.value=e.roughnessMap),null!=t.uniforms.metalnessMap&&(t.uniforms.metalnessMap.value=e.metalnessMap),null!=t.uniforms.roughness&&(t.uniforms.roughness.value=e.roughness),null!=t.uniforms.metalness&&(t.uniforms.metalness.value=e.metalness)),e instanceof i.MeshPhysicalMaterial&&(t.uniforms.sheenColor&&t.uniforms.sheenColor.value.setFromColor(e.sheenColor).multiplyScalar(e.sheen),t.uniforms.sheenColorMap&&(t.uniforms.sheenColorMap.value=e.sheenColorMap),t.uniforms.sheenRoughness&&(t.uniforms.sheenRoughness.value=e.sheenRoughness),t.uniforms.sheenRoughnessMap&&(t.uniforms.sheenRoughnessMap.value=e.sheenRoughnessMap)),e instanceof Ge&&(t.uniforms.heightMap.value=e.heightMap,t.uniforms.heightScale.value=e.heightScale),this.updateMaterialCommonProperties(e,t)}updateUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s){const t=i[e],a=s[e].value;null!=t&&t.value!==a&&"receiveShadow"!==e&&!1===Et.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||Et.includes(e)||Ot.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 Et){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(e,t,s=!1){const a=t===Qe.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,ae),o=this.usesShaderUniform(e,de),l=this.usesShaderUniform(e,pe),h=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,c=t===Qe.opaque?!(s||o||l||h):h||s||o||l;if(!c)return a.set(e,Ze),Ze;let p=V.uv;if(e instanceof Ge&&null!=e.heightMap){const t=A("heightScale",e.heightScale??1);p=De(p,H("heightMap",e.heightMap),t)}let d=L.normal;if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=e.normalMap??Ke,s=A("useNormalMap",null!=e.normalMap?1:0),i=A("normalScale",e.normalScale?.x??1),a=R(H("normalMap",t).sample(We(p,e.normalMap)),i);d=z(L.normal,a,s)}else e instanceof C&&null!=e.outputNormal&&(d=e.outputNormal);!0!==e.userData.disableAO&&(d=q("DOUBLE_SIDED",d,e=>N(new W("gl_FrontFacing"),e,e.multiplyScalar(-1))));let f=e.userData?.reflective?S(0):S(1);if(e instanceof i.MeshStandardMaterial){const t=A("roughness",e.roughness??1),s=e.roughnessMap??Xe,i=A("useRoughnessMap",null!=e.roughnessMap?1:0),a=H("roughnessMap",s).sample(We(p,e.roughnessMap)).g.multiply(t);f=z(t,a,i)}else e instanceof C&&null!=e.outputRoughness&&(f=e.outputRoughness);let g=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=A("useLightMap",null!=e.lightMap?1:0),i=A("lightMapIntensity",e.lightMapIntensity??1),a=H("lightMap",t).sample(p).rgb.multiplyScalar(i);g=z(G(0),a,s)}let M=S(0);if(e instanceof i.MeshStandardMaterial){const t=A("metalness",e.metalness??0),s=e.metalnessMap??Ye,i=A("useMetalnessMap",null!=e.metalnessMap?1:0),a=H("metalnessMap",s).sample(We(p,e.metalnessMap)).b.multiply(t);M=z(t,a,i)}else e instanceof C&&e.outputRoughness;let v=null,P=S(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){const t=e.aoMap??Xe,s=A("useAoMap",null!=e.aoMap?1:0);P=A("aoMapIntensity",e.aoMapIntensity??1);const i=H("aoMap",t).sample(We(p,e.aoMap)).r;v=z(S(1),i,s)}else e instanceof C&&e.outputRoughness;const y=A("opacity",e.opacity??1);let b=S(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){if(null!=e.alphaMap){const t=e.alphaMap;b=H("alphaMap",t).sample(We(p,e.alphaMap)).r}b=b.multiply(y)}else e instanceof C&&null!=e.outputOpacity&&(b=e.outputOpacity);let w=D(0,1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){let t=E("color",(new i.Vector3).setFromColor(e.color));const s=e.map??Xe,a=A("useAlbedoMap",null!=e.map?1:0),n=H("map",s).sample(We(p,e.map)),r=n.multiply(D(t,1)),o=D(t,1);w=z(o,r,a),e.vertexColors&&(w=w.multiply(_(I($.color.rgb),1)));const l=z(S(1),n.w,a);b=b.multiply(l)}const T=!0===e.userData.hasBloom;let x=G(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=E("emissive",(new i.Vector3).setFromColor(e.emissive)),s=A("emissiveIntensity",e.emissiveIntensity),a=e.emissiveMap??Ye,n=A("useEmissiveMap",null!=e.emissiveMap?1:0),r=H("emissiveMap",a).sample(We(p,e.emissiveMap)).rgb.multiply(t);x=z(t,r,n),x=x.multiplyScalar(s)}else e instanceof C&&null!=e.outputEmissive&&(x=e.outputEmissive);let j=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(j=E("sheenColor",(new i.Vector3).setFromColor(e.sheenColor).multiplyScalar(e.sheen)),e.sheen>0&&null!=e.sheenColorMap)){const t=H("sheenColorMap",e.sheenColorMap).sample(p).rgb;j=j.multiply(t)}let k=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(k=A("sheenRoughness",e.sheenRoughness),e.sheen>0&&null!=e.sheenRoughnessMap)){const t=H("sheenRoughnessMap",e.sheenRoughnessMap).sample(p).r;k=k.multiply(t)}let Q=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0&&(Q=A("anisotropy",e.anisotropy),e.anisotropy>0&&null!=e.anisotropyMap)){const t=H("anisotropyMap",e.anisotropyMap).sample(p).r;Q=Q.multiply(t)}let X=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0){const t=e.anisotropyRotation??0;X=J("anisotropyDirection",new i.Vector2(Math.cos(t),Math.sin(t)))}const Y=A("alphaTest",e.alphaTest);let K,Z=e.alphaTest>0?b.lt(Y):h&&t===Qe.opaque?b.lt(.8):null;!0===e.userData.isDecal&&(Z=Z?Z.or(Ve):Ve),K=h?_(0,0,0,0):(r=d,B(r).multiplyScalar(.5).addScalar(.5)).rgba(e.userData?.reflective?f:1);const ee=e instanceof C?e.outputPosition:void 0,te=e instanceof C?e.outputTransform:void 0;let se,ie=D("black",1);if(e instanceof C&&null!=e.outputColor)ie=e.outputColor;else if(e instanceof i.MeshStandardMaterial)ie=U({color:w,metalness:M,roughness:f,emissive:x.rgb,normal:d,ambientOcclusion:v,ambientOcclusionIntensity:P,bakedLight:g,sheenColor:j,sheenRoughness:k,anisotropy:Q,anisotropyDirection:X});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)ie=F({color:w.rgb,ambientOcclusion:v,ambientOcclusionIntensity:P});else if(e instanceof i.MeshBasicMaterial){let e=w.rgb,t=g??G("black");null!=v&&(t=t.multiplyScalar(v.subtract(1).multiply(P).add(1))),e=e.add(t),ie=e.rgba(b)}else e instanceof i.MeshToonMaterial&&(ie=O({color:w,emissive:x.rgb,normal:d,ambientOcclusion:v,ambientOcclusionIntensity:P,bakedLight:g}));(e instanceof C||e instanceof i.MeshStandardMaterial)&&(se=e.envMap);let ne=!0;(e instanceof m||e instanceof i.MeshBasicMaterial||e instanceof i.ShaderMaterial)&&(ne=e.fog);let re=D(ie.rgb,b);ne&&(re=new FogNode(re)),n=new C({transform:te,position:null==te?ee:void 0,outputs:[re,x.rgba(t===Qe.opaque?Y:T?1:0),K],opacity:b,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 C||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(n),e instanceof C&&(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===Qe.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 u&&this.inheritCustomUniformBindings(e,n)),a.set(e,n)}var r;return n.visible&&(e instanceof u?this.updateUniformValues(e,n):this.updateMaterialProperties(e,n)),this.usesShaderUniform(n,de)&&this.initSceneColorUniform(n),this.initLightVolumeUniform(n),n}isDepthPrepassEnabled(){return!0===this.options.depthPrepass?.enabled}usesSceneFeedbackUniforms(e){return e instanceof u&&(this.usesShaderUniform(e,ae)||this.usesShaderUniform(e,de)||this.usesShaderUniform(e,pe))}usesShaderUniform(e,t){return e instanceof u&&null!=e.uniforms[t]}isDepthPrepassEligibleMaterial(e){return null!=e&&(!1!==e.visible&&!1!==e.depthTest&&!1!==e.depthWrite&&(!e.transparent&&e.blending!==i.AdditiveBlending&&(!this.usesSceneFeedbackUniforms(e)&&(e instanceof C||e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshBasicMaterial))))}isDepthPrepassEligibleMesh(e){return!!this.isDepthPrepassEnabled()&&((e instanceof i.InstancedMesh||e instanceof _e)&&(!Array.isArray(e.material)&&this.isDepthPrepassEligibleMaterial(e.material)))}createDepthPrepassMaterial(e){if(!this.isDepthPrepassEligibleMaterial(e))return null;let t=this.depthPrepassMaterialCache.get(e);if(null==t){let s,a=S(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(a=A("opacity",e.opacity??1),null!=e.map&&(a=a.multiply(H("map",e.map).sample(V.uv).a)),null!=e.alphaMap&&(a=a.multiply(H("alphaMap",e.alphaMap).sample(V.uv).r))):e instanceof C&&(a=e.outputOpacity??S(1)),null!=e.alphaTest&&e.alphaTest>0&&(s=a.lt(e.alphaTest));const n=e instanceof C?e.outputPosition:void 0,r=e instanceof C?e.outputTransform:void 0;t=new C({outputs:[D(0,0),D(0,0),D(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 Et)delete t.uniforms[e];for(const e of Ot)delete t.uniforms[e];delete t.uniforms.receiveShadow,this.depthPrepassMaterialCache.set(e,t)}return e instanceof C?this.updateUniformValues(e,t):this.updateMaterialProperties(e,t),t.depthWrite=!0,t.depthTest=e.depthTest,t.colorWrite=!1,t.transparent=!1,t.blending=i.NoBlending,t.visible=e.visible,t.alphaTest=e.alphaTest,t.side=e.side,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t}applyDepthPrepassMaterials(){const e=this.depthPrepassCachedMaterials,t=this.depthPrepassCachedVisibility;e.clear(),t.length=0,ve(this.scene,s=>{if(St(s))return t.push(s),s.visible=!1,!1;if(!(s instanceof o))return;if(e.set(s,s.material),!this.isDepthPrepassEligibleMesh(s))return t.push(s),void(s.visible=!1);const i=this.createDepthPrepassMaterial(s.material);if(null==i)return t.push(s),void(s.visible=!1);s.material=i,s.visible=!0})}unapplyDepthPrepassMaterials(){this.depthPrepassCachedMaterials.forEach((e,t)=>{t.material=e}),this.depthPrepassCachedVisibility.forEach(e=>{e.visible=!0})}renderDepthPrepass(){if(!this.isDepthPrepassEnabled())return;this.applyDepthPrepassMaterials();const e=this.scene.matrixWorldAutoUpdate,t=this.scene.matrixAutoUpdate,s=this.renderer.shadowMap.autoUpdate;this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clearDepth();try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Depth prepass render failed",e)}this.unapplyDepthPrepassMaterials(),this.renderer.shadowMap.autoUpdate=s,this.scene.matrixWorldAutoUpdate=e,this.scene.matrixAutoUpdate=t}updateCsm(){const e=this.csmUpdateInvervals;if(this.renderer.shadowMap.autoUpdate&&null!=this.csmCascadeLastUpdate&&Array.isArray(e)){const t=performance.now();for(let s=0;s<this.csm.lights.length;++s){const i=e[s]??e[e.length-1]??16;(t-this.csmCascadeLastUpdate[s]>=i||0===s)&&this.csm.lights[s].shadow&&(this.csm.lights[s].shadow.needsUpdate=!0,this.csmCascadeLastUpdate[s]=t)}}this.csm.update()}loop(t,s=!1){const a=this.stats,n=a.addPanel(new te.Panel("Calls","#83f","#002")),l=a.addPanel(new te.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new fe(this.renderer.getContext()),a.addPanel(h)),this.showStats=s;let u=10,c=1e3;const p=()=>{const e=this.renderer.info.render.calls;e>u&&(u=e,setTimeout(()=>u=10,5e3)),n.update(e,u);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout(()=>c=1e3,5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const d=[],m=[],f=[],g=[];let M=0;const v=new r,P=new r;let y=0;let b=this.paused,w=!1,T=0,x=null,R=this.fpsCapRevision;const S=()=>{this.running&&!0!==this.options.enableXR&&requestAnimationFrame(E)},U=()=>{e.activeView=this,w&&(w=!1,requestAnimationFrame(()=>E(T)))};this.wakePausedRenderer=U;const A=at();it.set(this.container,e=>{this.isIntersecting=e,e&&U()}),A.observe(this.container),this.container.addEventListener("pointerdown",()=>{U()},{capture:!0});const E=s=>{w=!1;const n=this.renderer.getContext(),r=this.needsPausedRender;if(!this.running||null===this.container.offsetParent||this.paused&&!r&&n.drawingBufferHeight>1)return w=!0,T=s,setTimeout(()=>{w&&E(s)},500),void(this.paused&&(b=!0));if(this.renderer.domElement.parentElement!==this.container){if(e.activeView!==this&&null!==e.activeView)return w=!0,void(T=s);this.attachRendererDomElement(),this.resizeRender()}if(!0!==this.options.enableXR){R!==this.fpsCapRevision&&(R=this.fpsCapRevision,x=null);const e=this.fpsCap;if(null!=e){const t=1e3/e;if(null!=x){const e=s-x;if(e<t)return void S();x=s-e%t}else x=s}else x=s}let l=(s*=.001)-M;if(M=s,b?(l=.016,b=!1,this.resetUpscalingHistory()):l>.25&&this.resetUpscalingHistory(),this.updateDynamicResolution(l,1e3*s),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),a.begin(),this.showStats&&h?.startQuery(),this.ssrPass.gpuPanel=h,v.copy(this.camera.matrixWorld),!this.paused){if(l>1){let e=l;for(;e>.05;)t(rt),e-=rt;t(e)}else t(l);this.onLoopCallbacks.forEach(e=>e(l))}this.paused||(this.simulationTime+=l*this.simulationTimeScale);const u=this.simulationTime;this.camera?.updateMatrixWorld(),P.copy(this.camera.matrixWorld),s-y>.08&&!P.equals(v)&&(this.renderer.shadowMap.needsUpdate=!0,y=s),this.updateCsm();let c=!1;d.length=0,m.length=0,f.length=0;for(const e of g)e.visible=!0;g.length=0;const U=ut;pt.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),U.setFromProjectionMatrix(pt);let A=!1,O=!1,F=!1;if(this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Be&&(A=!0),e instanceof o&&this.initCustomDepthMaterial(e),(e instanceof o||e instanceof i.Sprite)&&(this.initResolutionUniform(e.material),this.initNormalUniform(e.material),this.initShadowUniform(e,e.material),this.initLightVolumeUniform(e.material),null!=this.scene.environment&&ht(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(c=!0)),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ae])&&isObjectInFrustum(e,U)?(this.initDepthUniform(e.material),O=!0):e instanceof X&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[pe]&&isObjectInFrustum(e,U)&&e.material instanceof C&&this.initAoUniform(e.material),e instanceof o||e instanceof i.Sprite){let t=!1;ht(e,e=>{this.usesShaderUniform(e,de)&&(this.initSceneColorUniform(e),t=!0)}),t&&(f.push(e),F=!0)}if(e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[ce])e.material.uniforms[ce].value=u;else if(e instanceof o&&Array.isArray(e.material))for(const t of e.material)t.uniforms&&null!=t.uniforms[ce]&&(t.uniforms[ce].value=u)}),this.bloomPass.enabled=c,!0===this.options.occlusionCulling?.enabled){for(const e of this.occlusionClusters)e.update();this.hideOccluded(g)}this.prepareUpscalingFrame(),this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderDepthPrepass(),this.renderScene(Qe.opaque),this.updateRenderedOcclusionClusters(),this.renderer.render(this.queryScene,this.camera),this.aoPass.output=se.OUTPUT.Off,(O||F)&&(this.fquadCopyOpaque.material.uniforms.tSceneColor.value=this.gRenderTarget.textures[0],this.fquadCopyOpaque.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.initResolutionUniform(this.fquadCopyOpaque.material),this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.renderer.clear(),this.fquadCopyOpaque.render(this.renderer),this.renderer.setRenderTarget(this.gRenderTarget)),f.length,d.forEach(e=>e.visible=!0),m.forEach(e=>e.visible=!0),f.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=s),this.volumetricFogPass&&A?(this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1),this.updatePostProcessEffectUniforms(u);try{this.paused&&!r||!this.running||(this.render(l),this.finishUpscalingFrame(),this.showStats&&h?.endQuery(),this.showStats&&p(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}finally{this.finishUpscalingFrame(),r&&(this.needsPausedRender=!1)}a.end(),this.csm?.update(),S()};!0===this.options.enableXR?this.renderer.setAnimationLoop(E):requestAnimationFrame(E)}applyGBufferMaterials(e){const t=this.gBufferCachedMaterials,s=this.gBufferCachedVisibility,i=this.gBufferCachedOnBeforeRender;t.clear(),s.length=0,i.clear();ve(this.scene,i=>{if(St(i))return s.push(i),i.visible=!1,!1;if(i instanceof o){t.set(i,i.material);let a=!1;if(Array.isArray(i.material)){i.material=i.material.slice();for(let t=0;t<i.material.length;t++)i.material[t]=this.createGBufferMaterial(i.material[t],e,e===Qe.opaque&&this.isDepthPrepassEligibleMesh(i)),a||(a=i.material[t].visible),this.initShadowUniform(i,i.material[t])}else i.material=this.createGBufferMaterial(i.material,e,e===Qe.opaque&&this.isDepthPrepassEligibleMesh(i)),a||(a=i.material.visible),this.initShadowUniform(i,i.material);this.applyGBufferShadowUniformUpdater(i),a?i.visible=!0:null!=i.children&&0!=i.children.length||(s.push(i),i.visible=!1)}})}unapplyGBufferMaterials(){this.gBufferCachedMaterials.forEach((e,t)=>{t.material=e}),this.gBufferCachedOnBeforeRender.forEach((e,t)=>{t.onBeforeRender=e}),this.gBufferCachedOnBeforeRender.clear(),this.gBufferCachedVisibility.forEach((e,t)=>{e.visible=!0,e.updateMatrixWorld(!0)})}applyGBufferShadowUniformUpdater(e){const t=e.onBeforeRender;this.gBufferCachedOnBeforeRender.set(e,t),e.onBeforeRender=(s,i,a,n,r,o)=>{t.call(e,s,i,a,n,r,o),this.initShadowUniform(e,r)}}initTextures(e=this.scene){e.traverse(e=>{if(e instanceof o)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)this._initMaterialTextures(e.material[t]);else this._initMaterialTextures(e.material)})}_initMaterialTextures(e){if(!this._initiatedMaterialTextures.has(e))if(this._initiatedMaterialTextures.add(e),e instanceof u){for(const[t,s]of Object.entries(e.uniforms))if(s.value instanceof p){if(this._initiatedTextures.has(s.value))continue;this.renderer.initTexture(s.value),this._initiatedTextures.add(s.value)}}else for(const[t,s]of Object.entries(e))if(s instanceof p){if(this._initiatedTextures.has(s))continue;this.renderer.initTexture(s),this._initiatedTextures.add(s)}}async compileAsync(e=this.scene){if(this.compileInProgress)return;this.renderer.setRenderTarget(this.gRenderTarget),this.compileInProgress=!0,this.applyGBufferMaterials(Qe.opaque),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(Qe.transparent),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.isDepthPrepassEnabled()&&(this.renderer.setRenderTarget(this.gRenderTarget),this.applyDepthPrepassMaterials(),await this.renderer.compileAsync(e,this.camera),this.unapplyDepthPrepassMaterials()),e===this.scene&&(this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.compileAsync(this.fquadBlendAO.mesh,this.fquadBlendAO.camera),this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.renderer.compileAsync(this.fquadCopyOpaque.mesh,this.fquadCopyOpaque.camera));const t=this.csm.lights[0]?.shadow.camera;null!=t&&(this.applyDepthMaterial(),await this.renderer.compileAsync(e,t),this.unapplyDepthMaterial()),this.compileInProgress=!1,this.renderer.setRenderTarget(null)}applyDepthMaterial(){const e=this.gBufferCachedMaterials;e.clear(),this.scene.traverse(t=>{(t.isMesh||t.isPoints||t.isLine||t.isSprite)&&(this.initCustomDepthMaterial(t),e.set(t,t.material),t.castShadow?null!=t.customDepthMaterial?t.material=t.customDepthMaterial:t.material=Bt:t.material=null)})}unapplyDepthMaterial(){this.gBufferCachedMaterials.forEach((e,t)=>{t.material=e})}renderScene(e){if(!this.running||this.paused&&!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!==Qe.opaque&&(this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1);try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Render failed",e)}e===Qe.opaque&&this.gBufferCachedMaterials.forEach((e,t)=>{!Array.isArray(e)&&!Array.isArray(t.material)&&e instanceof u&&this.updateLightUniformValues(t.material,e)}),this.unapplyGBufferMaterials(),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t.colorSpace=i.SRGBColorSpace,t}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);!function(e,t=i.NoToneMapping,s=1){e.tonemapMapping=t,e.tonemapExposure=s,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=e.colorTint??new i.Color("white"),e.colorTint.set("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.globalSaturation=dt(e.globalSaturation,1,1,1),e.globalContrast=dt(e.globalContrast,1,1,1),e.globalGamma=dt(e.globalGamma,1,1,1),e.globalGain=dt(e.globalGain,1,1,1),e.globalOffset=dt(e.globalOffset,0,0,0),e.shadowsSaturation=dt(e.shadowsSaturation,1,1,1),e.shadowsContrast=dt(e.shadowsContrast,1,1,1),e.shadowsGamma=dt(e.shadowsGamma,1,1,1),e.shadowsGain=dt(e.shadowsGain,1,1,1),e.shadowsOffset=dt(e.shadowsOffset,0,0,0),e.shadowsMax=.09,e.midtonesSaturation=dt(e.midtonesSaturation,1,1,1),e.midtonesContrast=dt(e.midtonesContrast,1,1,1),e.midtonesGamma=dt(e.midtonesGamma,1,1,1),e.midtonesGain=dt(e.midtonesGain,1,1,1),e.midtonesOffset=dt(e.midtonesOffset,0,0,0),e.highlightsSaturation=dt(e.highlightsSaturation,1,1,1),e.highlightsContrast=dt(e.highlightsContrast,1,1,1),e.highlightsGamma=dt(e.highlightsGamma,1,1,1),e.highlightsGain=dt(e.highlightsGain,1,1,1),e.highlightsOffset=dt(e.highlightsOffset,0,0,0),e.highlightsMin=.5,e.lut=void 0,e.lutIntensity=0}(this.postProcessSettings,this.baseToneMapping,this.baseToneMappingExposure);const e=this.postProcessSettings;let t,s=!1;if(null==this.camera)return;const a=this.camera.getWorldPosition(vt);let n=[];for(const r of this.postProcessVolumes){if(!ot(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.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);const r=e.vignetteIntensity>Mt,o=(h=e.temperature,u=e.temperatureTint,!ft(h,6500)||!ft(u,0));var h,u;const c=(p=e.colorTint,e.colorTintIntensity>Mt&&(!ft(p.r,1)||!ft(p.g,1)||!ft(p.b,1)));var p;const d=!(mt((m=e).globalSaturation,1,1,1)&&mt(m.globalContrast,1,1,1)&&mt(m.globalGamma,1,1,1)&&mt(m.globalGain,1,1,1)&&mt(m.globalOffset,0,0,0)&&mt(m.shadowsSaturation,1,1,1)&&mt(m.shadowsContrast,1,1,1)&&mt(m.shadowsGamma,1,1,1)&&mt(m.shadowsGain,1,1,1)&&mt(m.shadowsOffset,0,0,0)&&mt(m.midtonesSaturation,1,1,1)&&mt(m.midtonesContrast,1,1,1)&&mt(m.midtonesGamma,1,1,1)&&mt(m.midtonesGain,1,1,1)&&mt(m.midtonesOffset,0,0,0)&&mt(m.highlightsSaturation,1,1,1)&&mt(m.highlightsContrast,1,1,1)&&mt(m.highlightsGamma,1,1,1)&&mt(m.highlightsGain,1,1,1)&&mt(m.highlightsOffset,0,0,0));var m;const f=o||c||d||r,g=f&&e.tonemapMapping!==i.NoToneMapping,M=null!=t&&e.lutIntensity>Mt;f?(this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1):(this.renderer.toneMapping=e.tonemapMapping,this.renderer.toneMappingExposure=e.tonemapExposure),null!=e.envTexture&&(this.scene.environment=this.getEnvTexture(e.envTexture)),this.scene.environmentIntensity=e.envIntensity,f?(this.colorPass.whiteBalanceEnabled=o,this.colorPass.whiteBalanceScale=o?function(e,t,s){const i=function(e){const t=Pe(e,1e3,4e4)/100,s=t<=66?1:Pe(1.292936186062745*Math.pow(t-60,-.1332047592),0,1),i=Pe(t<=66?.3900815787690196*Math.log(t)-.6318414437886275:1.129890860895294*Math.pow(t-60,-.0755148492),0,1),a=t>=66?1:t<=19?0:Pe(.5432067891101962*Math.log(t-10)-1.19625408914,0,1);return yt.set(s,i,a)}(t),a=1+.2*Pe(s,-1,1),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}(Pt,e.temperature,e.temperatureTint):Pt.set(1,1,1),this.colorPass.vignetteIntensity=e.vignetteIntensity,this.colorPass.vignetteEnabled=r,this.colorPass.colorTintEnabled=c,this.colorPass.colorTint=e.colorTint,this.colorPass.colorTintIntensity=e.colorTintIntensity,this.colorPass.colorGradingEnabled=d,this.colorPass.toneMapping=e.tonemapMapping,this.colorPass.toneMappingEnabled=g,this.colorPass.toneMappingExposure=e.tonemapExposure,this.colorPass.globalSaturation=e.globalSaturation,this.colorPass.globalContrast=e.globalContrast,this.colorPass.globalGamma=e.globalGamma,this.colorPass.globalGain=e.globalGain,this.colorPass.globalOffset=e.globalOffset,this.colorPass.shadowsSaturation=e.shadowsSaturation,this.colorPass.shadowsContrast=e.shadowsContrast,this.colorPass.shadowsGamma=e.shadowsGamma,this.colorPass.shadowsGain=e.shadowsGain,this.colorPass.shadowsOffset=e.shadowsOffset,this.colorPass.shadowsMax=e.shadowsMax,this.colorPass.midtonesSaturation=e.midtonesSaturation,this.colorPass.midtonesContrast=e.midtonesContrast,this.colorPass.midtonesGamma=e.midtonesGamma,this.colorPass.midtonesGain=e.midtonesGain,this.colorPass.midtonesOffset=e.midtonesOffset,this.colorPass.highlightsSaturation=e.highlightsSaturation,this.colorPass.highlightsContrast=e.highlightsContrast,this.colorPass.highlightsGamma=e.highlightsGamma,this.colorPass.highlightsGain=e.highlightsGain,this.colorPass.highlightsOffset=e.highlightsOffset,this.colorPass.highlightsMin=e.highlightsMin,this.colorPass.enabled=!0):this.colorPass.enabled=!1,s&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==e.depthFocus&&(this.dofPass.uniforms.focus.value=e.depthFocus),void 0!==e.depthAperture&&(this.dofPass.uniforms.aperture.value=e.depthAperture),void 0!==e.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=e.depthMaxBlur)):this.dofPass.enabled=!1,this.lutPass.enabled=M,M&&(null!=t&&(t.flipY=!0,t.generateMipmaps=!1),this.lutPass.lut=t,this.lutPass.intensity=e.lutIntensity)}updatePostProcessEffectUniforms(e){if(0===this.postProcessEffects.length)return;const t=this.postProcessEffectUniformState;t.aoEnabled=this.aoPass.enabled,t.aoTexture=this.aoPass.enabled?this.aoPass.pdRenderTarget.texture:null,this.camera instanceof l?(t.cameraNear=this.camera.near,t.cameraFar=this.camera.far):(t.cameraNear=void 0,t.cameraFar=void 0),t.depthTexture=this.sceneColorRenderTarget.textures[1],t.normalTexture=this.gRenderTarget.textures[2],t.resolution.set(this.gRenderTarget.width,this.gRenderTarget.height),t.simulationTime=e;for(const e of this.postProcessEffects)e.pass.updateUniformState(t)}renderOverlay(){if(!this.running)return;if(0===this.overlayCameras.size)return;const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.previousClientWith/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled&&!1!==this.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible(t=>{t instanceof o&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,ut)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.options.bloom,this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=Me(this.scene,e=>e instanceof o&&!0===e.material?.userData?.hasBloom)}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===$e.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=$e:(e.visible=!1,this.bloomHidden.push(e))}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initSceneColorUniform(e){if(e instanceof u)return null==e.uniforms[de]?(e.uniforms[de]={value:this.sceneColorRenderTarget.texture},void(e.uniformsNeedUpdate=!0)):void(e.uniforms[de].value!==this.sceneColorRenderTarget.texture&&(e.uniforms[de].value=this.sceneColorRenderTarget.texture,e.uniformsNeedUpdate=!0))}initDepthUniform(e){e instanceof u&&(e.uniforms[ae].value=this.sceneColorRenderTarget.textures[1],this.camera instanceof l&&(null!=e.uniforms[re]&&(e.uniforms[re].value=this.camera.near),null!=e.uniforms[ne]&&(e.uniforms[ne].value=this.camera.far)))}initNormalUniform(e){e instanceof u&&null!=e.uniforms[le]&&(e.uniforms[le].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof C&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof C&&(null!=this.lightVolume?null==e.uniforms.uSH?(e.defines.USE_LIGHT_PROBE_VOLUME="",e.uniforms.gridOrigin={value:this.lightVolume.gridOrigin},e.uniforms.gridSize={value:this.lightVolume.gridSize},e.uniforms.gridRes={value:this.lightVolume.gridResolution},e.uniforms.giIntensity={value:this.lightProbeIntensity},e.uniforms.uSH={value:this.lightVolume.shTexture},e.uniformsNeedUpdate=!0,e.needsUpdate=!0):e.uniforms.giIntensity.value=this.lightProbeIntensity:null!=e.uniforms.uSH&&(delete e.defines.USE_LIGHT_PROBE_VOLUME,delete e.uniforms.gridOrigin,delete e.uniforms.gridSize,delete e.uniforms.gridRes,delete e.uniforms.giIntensity,delete e.uniforms.uSH,e.uniformsNeedUpdate=!0,e.needsUpdate=!0))}initResolutionUniform(e){e instanceof u&&null!=e.uniforms[oe]&&e.uniforms[oe].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 C&&t.depthWrite&&t.alphaTest>0))return;let s=this._customDepthMaterialCache.get(t);if(null==s){const e=Fe(Oe);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new C({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}};nt.activeView=null,nt=e=t([ie(),s("design:paramtypes",[HTMLElement,Object])],nt);export{nt as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const rt=.05;function ot(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}function lt(e,t){return e.priority!==t.priority?e.priority-t.priority:e.id-t.id}function ht(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}se.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};new i.Box3;const ut=new i.Frustum,ct=new i.Box3,pt=new i.Matrix4;export function isObjectInFrustum(e,t){const s=ct.setFromObject(e);return t.intersectsBox(s)}function dt(e,t,s,a){return null==e?new i.Vector3(t,s,a):e.set(t,s,a)}function mt(e,t,s,i){return null!=e&&ft(e.x,t)&&ft(e.y,s)&&ft(e.z,i)}function ft(e,t,s=Mt){return Math.abs(e-t)<=s}function gt(e,t){return null!=e&&Number.isFinite(e)&&e>0?e:t}const Mt=1e-4,vt=new i.Vector3,Pt=new i.Vector3(1,1,1),yt=new i.Vector3(1,1,1);const bt=new r,wt=new d;function Tt(e,t,s=new i.Matrix3){return wt.copy(e),wt.x*=-1,wt.y*=-1,wt.z*=-1,t.isCubeTexture&&!1===t.isRenderTargetTexture&&(wt.y*=-1,wt.z*=-1),s.setFromMatrix4(bt.makeRotationFromEuler(wt))}const xt=new C({outputs:[_(0,0,0,0),_(0,0,0,0),D(G("white"),Ie(4))],transparent:!0}),Rt=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});xt.depthWrite=!1;new o(new i.BoxGeometry(4,4,4),Rt);function St(e){return e instanceof i.Sprite||e.isPoints||e.isLine||e.isLineSegments2||e.isTransformControls||e.isTransformControlsGizmo||e instanceof o&&Ct(e,e.material)}function Ct(e,t){return null==t||(Array.isArray(t)?t.some(t=>Ct(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof C))}class Ut extends Le{constructor(e,t,s){super(),this.scene=e,this.camera=t,this.gRenderTarget=s,this.cachedVisibility=[],this.toRender=[],this.needsSwap=!1}render(e,t,s,i,a){const n=e.autoClear;e.autoClear=!1;const r=this.scene.matrixWorldAutoUpdate,l=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const u=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),this.cachedVisibility.length=0;let c=0,p=this.toRender;if(p.length=0,this.scene.traverseVisible(e=>{const t=St(e);e instanceof o&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(c++,p.push(e))}),c>0)for(const t of p)e.render(t,this.camera);this.cachedVisibility.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=n,s.depthTexture=u,this.scene.matrixWorldAutoUpdate=r,this.scene.matrixAutoUpdate=l,e.shadowMap.autoUpdate=h}}class At extends Le{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const Et=["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"],Ot=["directionalShadowMap","directionalShadowMatrix","pointLightShadows","pointShadowMap","pointShadowMatrix","spotLightShadows","spotShadowMap"],Ft=E("fogColor");export class FogNode extends k{constructor(e,t=Ft){super(),this.source=e,this.fogColor=t}compile(e){const t=e.variable(),s=e.get(this.source.rgb),i=e.get(this.source.a),a=e.get(this.fogColor),n=e.get(A("fogFar")),r=e.get(A("fogNear")),o=e.get(A("fogDensity")),l=e.get(I(j.mvPosition.z));return{pars:"\n ",chunk:`\n #ifdef FOG_EXP2\n float fogFactor_${t} = 1.0 - exp( - ${o} * ${o} * ${l} * ${l} );\n #else\n float fogFactor_${t} = smoothstep( ${r}, ${n}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${a}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}const Bt=new i.MeshDepthMaterial({depthPacking:i.RGBADepthPacking});/*
|
|
1
|
+
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as a,Material as r,Matrix4 as n,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as u,WebGLRenderTarget as c,Texture as p,Euler as d,MeshStandardMaterial as m}from"three";import{CopyShader as f,EffectComposer as g,FXAAShader as M,GammaCorrectionShader as v,LUTPass as P,RenderPass as y,ShaderPass as b,VRButton as w}from"three-stdlib";import{CSMShader as T,CSMUtil as R}from"./csm.js";import{colorToNormal as S,float as x,NodeShaderMaterial as C,standardMaterial as U,uniformFloat as A,uniformVec3 as B,toonMaterial as O,lambertMaterial as E,normalize as G,rgb as F,rgba as D,transformed as j,varying as I,varyingAttributes as L,varyingTransformed as V,vec4 as _,BooleanExpression as W,select as k,ifDefApply as N,uniformSampler2d as q,RgbaNode as H,mix as z,attributes as $,uniformVec2 as J,min as Q}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{RectAreaLightUniformsLib as ee}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import te from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as se}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as ie}from"typedi";import{depthUniformName as ae,farUniformName as re,nearUniformName as ne,resolutionUniformName as oe,sceneNormalUniformName as le,screenUV as he,supportsDepthTextureExtension as ue}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as ce}from"./shader-nodes/time.js";import{aoMapUniformName as pe,sceneMapUniformName as de}from"./shader-nodes/scene-sample.js";import{DepthPass as me}from"./utils/three/depth-pass.js";import{GPUStatsPanel as fe}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as ge}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as Me,traverseVisibleStop as ve}from"./utils/three/traverse.js";import{clamp as Pe}from"./utils/math.js";import{ColorPass as ye}from"./rendering/color-pass.js";import{PostProcessEffectPass as be,PostProcessEffectRegistration as we,postProcessEffectStages as Te,sanitizePostProcessEffectPriority as Re,sanitizePostProcessEffectStage as Se}from"./rendering/post-process-effect.js";import{SSRPass as xe}from"./rendering/ssr/SSRPass.js";import{SSRShader as Ce}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as Ue}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as Ae}from"./rendering/outline-effect.js";import{UnrealBloomPass as Be}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Oe}from"./shader-nodes/depth.js";import{packDepthToRGBA as Ee}from"three-shader-graph";import{FogVolumeObject as Ge}from"./rendering/fog/fog-volume-object";import{ParallaxStandardMaterial as Fe}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as De}from"./shader-nodes/pom.js";import{FullScreenQuad as je}from"three-stdlib";import{edgeDepthEffect as Ie}from"./shader-nodes/effects";import{decalDiscard as Le}from"./shader-nodes/decal.js";import{Pass as Ve}from"three/examples/jsm/Addons.js";import{BatchedMesh2 as _e}from"./scene/batched-mesh-2.js";import{applyUvTiling as We}from"./shader/uv-nodes.js";import{createPlaceholderTexture as ke}from"./utils/three/placeholder-texture.js";import{getTemporalUpscalingJitter as Ne,getUpscalingMethod as qe,UpscaleOutputPass as He}from"./rendering/upscaling-pass.js";R.patchSetupMaterial();const ze=document.createElement("div");ze.style.position="absolute",ze.style.left="50%",ze.style.top="50%",ze.style.color="black",ze.style.zIndex="999";(new i.Layers).set(9);const $e=new i.MeshBasicMaterial({color:"black"}),Je=new i.MeshDepthMaterial;var Qe;Je.depthPacking=i.RGBADepthPacking,Je.blending=i.NoBlending,Je.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(Qe||(Qe={}));const Xe=(()=>{const e=new Uint8Array([255,255,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ye=(()=>{const e=new Uint8Array([0,0,0,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ke=(()=>{const e=new Uint8Array([128,128,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ze=new C({color:x(0),position:_(x(0))});Ze.visible=!1;const et=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let tt=0,st=null;const it=new Map;function at(){return null==st&&(st=new IntersectionObserver(e=>{for(const t of e){const e=it.get(t.target);e&&e(t.isIntersecting)}},{threshold:0})),st}let rt=e=class{get fpsCap(){return this._fpsCap}set fpsCap(e){const t=null!=e&&Number.isFinite(e)&&e>0?e:null;t!==this._fpsCap&&(this._fpsCap=t,this.fpsCapRevision++)}setPaused(e){this.paused=e}setResolutionScale(e){const t=gt(e,1);ft(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()))}isUpscalingEnabled(){return!0===this.options.upscaling?.enabled&&!0!==this.options.enableXR}isTemporalUpscalingEnabled(){return this.isUpscalingEnabled()&&"temporal"===qe(this.options.upscaling)}resetUpscalingHistory(){this.hasPreviousTemporalViewProjection=!1,this.upscaleOutputPass?.resetHistory()}prepareUpscalingFrame(){if(!this.isTemporalUpscalingEnabled()||null==this.upscaleOutputPass)return void this.upscaleOutputPass?.setFrameState(null);this.unjitteredProjectionMatrix.copy(this.camera.projectionMatrix),this.currentUnjitteredViewProjectionMatrix.multiplyMatrices(this.unjitteredProjectionMatrix,this.camera.matrixWorldInverse),this.hasPreviousTemporalViewProjection||(this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.upscaleOutputPass.resetHistory());const e=gt(this.options.upscaling?.temporal?.jitterScale,1);Ne(this.temporalUpscalingFrameIndex++,this.temporalJitter,e),this.temporalJitterUv.set(this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),this.temporalJitter.y/Math.max(1,this.gRenderTarget.height));const t=2*this.temporalJitter.x/Math.max(1,this.gRenderTarget.width),s=2*this.temporalJitter.y/Math.max(1,this.gRenderTarget.height);this.camera instanceof l?(this.camera.projectionMatrix.elements[8]+=t,this.camera.projectionMatrix.elements[9]+=s):(this.camera.projectionMatrix.elements[12]+=t,this.camera.projectionMatrix.elements[13]+=s),this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert(),this.projectionJitterApplied=!0,this.currentViewProjectionMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.currentViewProjectionMatrixInverse.copy(this.currentViewProjectionMatrix).invert(),this.temporalUpscalingFrameState.depthTexture=this.gRenderTarget.depthTexture,this.upscaleOutputPass.setFrameState(this.temporalUpscalingFrameState)}finishUpscalingFrame(){this.projectionJitterApplied&&(this.camera.projectionMatrix.copy(this.unjitteredProjectionMatrix),this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert(),this.previousViewProjectionMatrix.copy(this.currentUnjitteredViewProjectionMatrix),this.hasPreviousTemporalViewProjection=!0,this.projectionJitterApplied=!1)}getBasePixelRatio(){const e=gt(this.maxPixelRatio,1),t=gt(window.devicePixelRatio,1);return Math.min(e,t)}getBaseResolutionScale(){return gt(this.resolutionScale,1)}getDynamicResolutionMinScale(){const e=this.getBaseResolutionScale(),t=gt(this.options.dynamicResolution?.minScale,.7);return Math.min(e,t)}getEffectiveResolutionScale(){const e=this.getBaseResolutionScale();return!0!==this.options.dynamicResolution?.enabled?e:Pe(this.dynamicResolutionScale,this.getDynamicResolutionMinScale(),e)}getRenderPixelRatio(){return this.getBasePixelRatio()*this.getEffectiveResolutionScale()}getPresentationPixelRatio(){const e=this.getBasePixelRatio();return this.isUpscalingEnabled()?e:e*this.getEffectiveResolutionScale()}resetDynamicResolutionAverage(){this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0}updateDynamicResolution(e,t){const s=this.options.dynamicResolution;if(!0!==s?.enabled)return;if(!Number.isFinite(e)||e<=0||e>.25)return void this.resetDynamicResolutionAverage();const i=this.getBaseResolutionScale(),a=this.getDynamicResolutionMinScale(),r=Pe(this.dynamicResolutionScale,a,i);ft(r,this.dynamicResolutionScale)||(this.dynamicResolutionScale=r);const n=gt(s.targetFps,60),o=1e3/(null!=this.fpsCap?Math.min(n,this.fpsCap):n),l=1e3*e;this.dynamicResolutionFrameTimeAverage=null==this.dynamicResolutionFrameTimeAverage?l:.9*this.dynamicResolutionFrameTimeAverage+.1*l,this.dynamicResolutionFrameSamples++;const h=Math.max(1,Math.floor(gt(s.sampleFrames,20)));if(this.dynamicResolutionFrameSamples<h)return;const u=gt(s.decreaseCooldown,500),c=gt(s.increaseCooldown,2e3),p=gt(s.decreaseStep,.05),d=gt(s.increaseStep,.025),m=this.dynamicResolutionFrameTimeAverage;let f=r;m>1.12*o&&r>a&&t-this.dynamicResolutionLastAdjustmentAt>=u?f=Math.max(a,r-p):m<.85*o&&r<i&&t-this.dynamicResolutionLastAdjustmentAt>=c&&(f=Math.min(i,r+d)),ft(f,r)||(this.dynamicResolutionScale=f,this.dynamicResolutionLastAdjustmentAt=t,this.resetDynamicResolutionAverage(),this.resizeRender(!0))}resizeRender(e=!1){if(!this.running)return;const t=this.container.clientWidth,s=this.container.clientHeight,i=this.getRenderPixelRatio(),a=this.getPresentationPixelRatio();if(!e&&this.previousClientWith===t&&this.previousClientHeight===s&&this.previousRenderPixelRatio===i&&this.previousPresentationPixelRatio===a)return;if(0===t||0===s)return;this.previousClientWith=t,this.previousClientHeight=s,this.previousRenderPixelRatio=i,this.previousPresentationPixelRatio=a,this.camera instanceof l&&(this.camera.aspect=t/s,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(a),this.renderer.setSize(t,s),this.composer.setPixelRatio(i),this.composer.setSize(t,s);const r=t*i,n=s*i;this.dofPass.setSize(r,n),this.fxaaPass.setSize(r,n),this.fxaaPass.uniforms.resolution.value.set(1/r,1/n),this.createGRenderTarget(),this.phasedRenderPass.gRenderTarget=this.gRenderTarget,this.bloomPass.emissiveTexture=this.gRenderTarget.textures[1],this.ssrPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.ssrPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.aoPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.fquadBlendAO.material.uniforms.tAlphaTest.value=this.gRenderTarget.textures[1],this.sceneColorRenderTarget.dispose(),this.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.resetDynamicResolutionAverage(),this.resetUpscalingHistory()}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}addPostProcessEffect(e,t={}){const s={id:++this.postProcessEffectId,pass:new be(e),priority:Re(t.priority),stage:Se(t.stage)};return s.pass.enabled=t.enabled??!0,this.postProcessEffects.push(s),this.refreshPostProcessEffectPassOrder(),new we(this,s)}removePostProcessEffectEntry(e){const t=e,s=this.postProcessEffects.indexOf(t);-1!==s&&(this.postProcessEffects.splice(s,1),this.composer.removePass(t.pass),t.pass.dispose())}refreshPostProcessEffectPassOrder(){for(const e of this.postProcessEffects)this.composer.removePass(e.pass);for(const e of Te){const t=this.getPostProcessEffectStageAnchorPass(e),s=null!=t?this.composer.passes.indexOf(t):this.composer.passes.length,i=this.postProcessEffects.filter(t=>t.stage===e).sort(lt);for(let e=0;e<i.length;e++)this.composer.insertPass(i[e].pass,s+e)}}getPostProcessEffectStageAnchorPass(e){switch(e){case"beforeFog":return this.volumetricFogPass;case"beforeDepthOfField":return this.dofPass;case"beforeColorAdjustment":return this.colorPass;case"beforeOutline":return this.outlinePass;case"beforeAntiAliasing":return this.fxaaPass;case"beforeLut":return this.lutPass;case"beforeOutput":return this.outputPass}}constructor(t,s={}){this.container=t,this.options=s,this.isIntersecting=!1,this.needsPausedRender=!1,this.wakePausedRenderer=null,this.windowVisible=!0,this.queryScene=new i.Scene,this.running=!0,this.paused=!1,this._fpsCap=null,this.fpsCapRevision=0,this.postProcessVolumes=[],this.postProcessSettings={},this.baseToneMapping=i.NoToneMapping,this.baseToneMappingExposure=1,this.csmUpdateInvervals=this.options.shadows?.cascadeUpdateIntervals,this._id=tt++,this.postProcessEffectId=0,this.postProcessEffects=[],this.postProcessEffectResolution=new i.Vector2(1,1),this.postProcessEffectUniformState={aoEnabled:!1,aoTexture:null,cameraFar:void 0,cameraNear:void 0,depthTexture:ke(),normalTexture:ke(128,128,255),resolution:this.postProcessEffectResolution,simulationTime:0},this.fquadCopySceneColor=new je(new u(f)),this.fquadCopySceneDepth=new je(new C({color:_(q("tDepthTexture",new i.DepthTexture(1,1)).sample(L.uv).r)})),this.occlusionClusters=[],this.simulationTime=0,this.simulationTimeScale=1,this.lightProbeIntensity=2,this.fquadBlendAO=(()=>{const e=_(1),t=ke(),s=q("tAlphaTest",t).sample(he).a,a=q("tAO",t).sample(he),r=k(s.lt(.05),a,Q(_(1,1,1,1),a.addScalar(.4))),n=new C({outputs:[r,e,e],transparent:!0});n.depthWrite=!1,n.depthTest=!1,n.blending=i.MultiplyBlending;return new je(n)})(),this.resolutionScale=1,this.maxPixelRatio=et?1:window.devicePixelRatio,this.dynamicResolutionScale=1,this.dynamicResolutionFrameTimeAverage=null,this.dynamicResolutionFrameSamples=0,this.dynamicResolutionLastAdjustmentAt=0,this.upscaleOutputPass=null,this.unjitteredProjectionMatrix=new n,this.temporalJitter=new i.Vector2,this.temporalJitterUv=new i.Vector2,this.currentUnjitteredViewProjectionMatrix=new n,this.currentViewProjectionMatrix=new n,this.currentViewProjectionMatrixInverse=new n,this.previousViewProjectionMatrix=new n,this.temporalUpscalingFrameState={depthTexture:null,currentJitterUv:this.temporalJitterUv,currentViewProjectionInverse:this.currentViewProjectionMatrixInverse,previousViewProjection:this.previousViewProjectionMatrix},this.temporalUpscalingFrameIndex=0,this.hasPreviousTemporalViewProjection=!1,this.projectionJitterApplied=!1,this.onResize=()=>{if(this.resizeRender(),this.paused)this.needsPausedRender=!0,this.wakePausedRenderer?.();else try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.onLoopCallbacks=[],this.stats=new te,this._showStats=!1,this.gbufferMaterialCache=new Map,this.gbufferDepthPrepassMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.depthPrepassMaterialCache=new WeakMap,this.depthPrepassCachedMaterials=new Map,this.depthPrepassCachedVisibility=[],this.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.pmremGeneratorResults=new WeakMap,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new a,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],this._customDepthMaterialCache=new WeakMap,null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),this.resolutionScale=s.resolutionScale??1,this.dynamicResolutionScale=this.getBaseResolutionScale(),this.fpsCap=s.fpsCap,e.activeView=this,ee.init(),window.renderer=this.renderer=window.renderer??new i.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});new i.MeshStandardMaterial({color:"#ccc"});this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,this.scene.updateMatrixWorld=function(e){const t=this.children;for(let s=0,i=t.length;s<i;s++){t[s].updateMatrixWorld(e)}}.bind(this.scene),this.renderer.setPixelRatio(this.getPresentationPixelRatio()),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(w.createButton(this.renderer));const r=new Ae(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=r,this.createGRenderTarget(),this.composer=new g(this.renderer,function(e,t){const s=new i.WebGLRenderTarget(Math.max(1,e),Math.max(1,t),{minFilter:i.LinearFilter,magFilter:i.LinearFilter,format:i.RGBAFormat,type:i.HalfFloatType});return s.texture.name="EffectComposer.rt1",s.texture.generateMipmaps=!1,s}(t.clientWidth,t.clientHeight)),this.composer.setPixelRatio(this.getRenderPixelRatio()),this.composer.setSize(t.clientWidth,t.clientHeight);var l=(t.clientWidth||1)/(t.clientHeight||1);const h=new i.PerspectiveCamera(45,l,.5,800);h.layers.enable(19),this.setCamera(h),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.baseToneMapping=this.renderer.toneMapping,this.baseToneMappingExposure=this.renderer.toneMappingExposure,this.renderer.gammaFactor=1.4,R.renderingView=this,this.isDepthTextureExtensionSupported=ue(this.renderer),this.attachRendererDomElement(),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container,this.getRenderPixelRatio()),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(),this.sceneDepthRenderTarget=this.createSceneDepthRenderTarget();const c=new i.Vector2(t.clientWidth,t.clientHeight),p=(new y(this.scene,this.camera),new b(f,"prevtexture"));p.enabled=!0,p.needsSwap=!0,p.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=p;const d=new Be(c,1.5,.4,.85);d.threshold=1,d.strength=.9,d.radius=.2,this.bloomPass=d;const m=new se(this.scene,this.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});m.normalRenderTarget?.dispose(),m.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),m.output=se.OUTPUT.Off,m.enabled=!1,this.aoPass=m,this.fquadBlendAO.material.uniforms.tAO.value=m.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 T=new xe({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});T.output=xe.OUTPUT.Default,T.blur=!0,T.fresnel=!1,T.distanceAttenuation=!0,T.maxDistance=50,T.selective=!0,T.bouncing=!1,T.opacity=.4,T.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=T,!1!==this.options.ao?.enabled&&this.composer.addPass(m);const S=new At((e,t,s,i,a)=>{this.aoPass.enabled&&(this.initResolutionUniform(this.fquadBlendAO.material),this.renderer.setRenderTarget(this.gRenderTarget),this.fquadBlendAO.render(this.renderer),this.renderer.setRenderTarget(null))});this.composer.addPass(S);const x=new At((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(Qe.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(x),this.composer.addPass(p),this.composer.addPass(T),this.phasedRenderPass=new Ut(this.scene,this.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(d),d.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.volumetricFogPass=new Ue(c),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 U=new ye;this.composer.addPass(U),this.colorPass=U,U.vignetteEnabled=!1,this.outlinePass=new ge(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const A=new b(M);A.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(A),this.fxaaPass=A,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new b(v).clear=!1,this.fixStatsStyle(),this.lutPass=new P({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const B=new b(f,"prevtexture");B.enabled=!0,B.needsSwap=!1,B.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],B.renderToScreen=!0;const O=this.isUpscalingEnabled()?new He(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)}(O),this.outputPass=O,this.upscaleOutputPass=O instanceof He?O:null,this.composer.addPass(O);const E=new i.MeshBasicMaterial({colorWrite:!1,depthWrite:!1,depthTest:!0,transparent:!1}),G=new o(new i.BoxGeometry(1,1,1),E);G.renderOrder=1/0,G.name="CLUSTER_BOUNDS_VOLUME"}addCluster(e){if(!1===this.options.occlusionCulling?.enabled)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))&&ut.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";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){if(this.camera=e,this.resetUpscalingHistory(),this.composer.passes.forEach(t=>{t instanceof y?t.camera=e:t instanceof ge?t.renderCamera=e:(t instanceof me||t instanceof se)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),this.phasedRenderPass&&(this.phasedRenderPass.camera=e),null==this.csm){if(this.csm=new Z({maxFar:80,lightFar:250,lightMargin:20,cascades:et?2:3,shadowMapSize:1024*(et?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"}),null!=this.csmUpdateInvervals){this.csmCascadeLastUpdate=new Array(this.csm.lights.length).fill(0);for(const e of this.csm.lights)e.shadow.autoUpdate=!1}this.csm&&Array.isArray(this.csm.lights),this.csm.fade=!0,h.lights_fragment_begin=T.lights_fragment_begin}else this.csm.camera=this.camera,this.camera;this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse(e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)});this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t,s){const a=Math.max(1,Math.floor(t.clientWidth*s)),r=Math.max(1,Math.floor(t.clientHeight*s)),n=new i.WebGLRenderTarget(a,r);return n.texture.minFilter=i.NearestFilter,n.texture.magFilter=i.NearestFilter,n.texture.generateMipmaps=!1,n.stencilBuffer=!1,n.depthTexture=new i.DepthTexture(a,r),n.depthTexture.type=i.UnsignedShortType,n.depthTexture.minFilter=i.NearestFilter,n.depthTexture.magFilter=i.NearestFilter,n}static createAOMaskDepthRenderTarget(e,t,s=e.getPixelRatio()){const a=Math.max(1,t.clientWidth*s),r=Math.max(1,t.clientHeight*s),n=new i.DepthTexture(a,r);n.type=i.UnsignedInt248Type,n.minFilter=i.NearestFilter,n.magFilter=i.NearestFilter;const o=new i.WebGLRenderTarget(a,r,{type:i.HalfFloatType,depthTexture:n});return o.texture.minFilter=i.NearestFilter,o.texture.magFilter=i.NearestFilter,o.texture.generateMipmaps=!1,o.stencilBuffer=!1,o}createSceneColorRenderTarget(){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),r=new i.DepthTexture(s,a);r.type=i.UnsignedIntType,r.minFilter=i.NearestFilter,r.magFilter=i.NearestFilter,this.gRenderTarget=new c(s,a,{count:3,samples:this.options?.msaa??0,minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat,depthTexture:r}),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(e=!0){this.running=!1,this.wakePausedRenderer=null,this.lightVolume?.shTexture.dispose(),window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],e&&this.renderer.dispose(),this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.sceneDepthRenderTarget.dispose(),this.csm.dispose();for(const e of this.postProcessEffects)this.composer.removePass(e.pass),e.pass.dispose();this.postProcessEffects.length=0,this.detachOwnedDomElements();if(at().unobserve(this.container),it.delete(this.container),this.occlusionClusters.length>0){const e=this.renderer.getContext();this.occlusionClusters.forEach(t=>{e.deleteQuery(t.query)})}this.volumetricFogPass.dispose(),R.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.findIndex(t=>t===e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&this.stats.dom.parentElement!==this.container?this.container.appendChild(this.stats.dom):this._showStats||this.stats.dom.parentElement!==this.container||this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}attachRendererDomElement(){const e=this.renderer.domElement;e.parentElement===this.container&&e===this.container.firstChild||this.container.insertBefore(e,this.container.firstChild),this._showStats&&this.stats.dom.parentElement!==this.container&&this.container.appendChild(this.stats.dom)}detachOwnedDomElements(){this.renderer.domElement.parentElement===this.container&&this.container.removeChild(this.renderer.domElement),this.stats.dom.parentElement===this.container&&this.container.removeChild(this.stats.dom)}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof C&&(null==e.envMap||e.userData.useSceneEnv)&&(e.userData.useSceneEnv=!0,null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment},e.uniformsNeedUpdate=!0,e.uniforms.envMapRotation={value:Tt(this.scene.environmentRotation,this.scene.environment,new i.Matrix3)}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1},e.uniformsNeedUpdate=!0),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment),e instanceof C||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}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 m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(null!=t.uniforms.color&&t.uniforms.color.value.setFromColor(e.color),null!=t.uniforms.opacity&&(t.uniforms.opacity.value=e.opacity),null!=t.uniforms.map&&(t.uniforms.map.value=e.map),null!=t.uniforms.alphaMap&&(t.uniforms.alphaMap.value=e.alphaMap),null!=t.uniforms.lightMap&&(t.uniforms.lightMap.value=e.lightMap,t.uniforms.lightMapIntensity.value=e.lightMapIntensity),null!=t.uniforms.aoMap&&(t.uniforms.aoMap.value=e.aoMap,t.uniforms.aoMapIntensity.value=e.aoMapIntensity),null!=t.uniforms.alphaTest&&(t.uniforms.alphaTest.value=e.alphaTest)),(e instanceof m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(t.uniforms.normalMap&&(t.uniforms.normalMap.value=e.normalMap,t.uniforms.normalScale.value=e.normalScale.x),t.uniforms.emissiveMap&&(t.uniforms.emissiveMap.value=e.emissiveMap,t.uniforms.emissive.value.setFromColor(e.emissive),t.uniforms.emissiveIntensity.value=e.emissiveIntensity)),e instanceof m&&(null!=t.uniforms.roughnessMap&&(t.uniforms.roughnessMap.value=e.roughnessMap),null!=t.uniforms.metalnessMap&&(t.uniforms.metalnessMap.value=e.metalnessMap),null!=t.uniforms.roughness&&(t.uniforms.roughness.value=e.roughness),null!=t.uniforms.metalness&&(t.uniforms.metalness.value=e.metalness)),e instanceof i.MeshPhysicalMaterial&&(t.uniforms.sheenColor&&t.uniforms.sheenColor.value.setFromColor(e.sheenColor).multiplyScalar(e.sheen),t.uniforms.sheenColorMap&&(t.uniforms.sheenColorMap.value=e.sheenColorMap),t.uniforms.sheenRoughness&&(t.uniforms.sheenRoughness.value=e.sheenRoughness),t.uniforms.sheenRoughnessMap&&(t.uniforms.sheenRoughnessMap.value=e.sheenRoughnessMap)),e instanceof Fe&&(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===Bt.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||Bt.includes(e)||Ot.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 Bt){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(e,t,s=!1){const a=t===Qe.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let r=a.get(e);if(!0===e.userData.isGBufferMaterial)return e;if(null==r){const s=this.usesShaderUniform(e,ae),o=this.usesShaderUniform(e,de),l=this.usesShaderUniform(e,pe),h=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,c=t===Qe.opaque?!(s||o||l||h):h||s||o||l;if(!c)return a.set(e,Ze),Ze;let p=L.uv;if(e instanceof Fe&&null!=e.heightMap){const t=A("heightScale",e.heightScale??1);p=De(p,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??Ke,s=A("useNormalMap",null!=e.normalMap?1:0),i=A("normalScale",e.normalScale?.x??1),a=S(q("normalMap",t).sample(We(p,e.normalMap)),i);d=z(V.normal,a,s)}else e instanceof C&&null!=e.outputNormal&&(d=e.outputNormal);!0!==e.userData.disableAO&&(d=N("DOUBLE_SIDED",d,e=>k(new W("gl_FrontFacing"),e,e.multiplyScalar(-1))));let f=e.userData?.reflective?x(0):x(1);if(e instanceof i.MeshStandardMaterial){const t=A("roughness",e.roughness??1),s=e.roughnessMap??Xe,i=A("useRoughnessMap",null!=e.roughnessMap?1:0),a=q("roughnessMap",s).sample(We(p,e.roughnessMap)).g.multiply(t);f=z(t,a,i)}else e instanceof C&&null!=e.outputRoughness&&(f=e.outputRoughness);let g=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=A("useLightMap",null!=e.lightMap?1:0),i=A("lightMapIntensity",e.lightMapIntensity??1),a=q("lightMap",t).sample(p).rgb.multiplyScalar(i);g=z(F(0),a,s)}let M=x(0);if(e instanceof i.MeshStandardMaterial){const t=A("metalness",e.metalness??0),s=e.metalnessMap??Ye,i=A("useMetalnessMap",null!=e.metalnessMap?1:0),a=q("metalnessMap",s).sample(We(p,e.metalnessMap)).b.multiply(t);M=z(t,a,i)}else e instanceof C&&e.outputRoughness;let v=null,P=x(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){const t=e.aoMap??Xe,s=A("useAoMap",null!=e.aoMap?1:0);P=A("aoMapIntensity",e.aoMapIntensity??1);const i=q("aoMap",t).sample(We(p,e.aoMap)).r;v=z(x(1),i,s)}else e instanceof C&&e.outputRoughness;const y=A("opacity",e.opacity??1);let b=x(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;b=q("alphaMap",t).sample(We(p,e.alphaMap)).r}b=b.multiply(y)}else e instanceof C&&null!=e.outputOpacity&&(b=e.outputOpacity);let w=D(0,1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){let t=B("color",(new i.Vector3).setFromColor(e.color));const s=e.map??Xe,a=A("useAlbedoMap",null!=e.map?1:0),r=q("map",s).sample(We(p,e.map)),n=r.multiply(D(t,1)),o=D(t,1);w=z(o,n,a),e.vertexColors&&(w=w.multiply(_(I($.color.rgb),1)));const l=z(x(1),r.w,a);b=b.multiply(l)}const T=!0===e.userData.hasBloom;let R=F(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=A("emissiveIntensity",e.emissiveIntensity),a=e.emissiveMap??Ye,r=A("useEmissiveMap",null!=e.emissiveMap?1:0),n=q("emissiveMap",a).sample(We(p,e.emissiveMap)).rgb.multiply(t);R=z(t,n,r),R=R.multiplyScalar(s)}else e instanceof C&&null!=e.outputEmissive&&(R=e.outputEmissive);let j=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(j=B("sheenColor",(new i.Vector3).setFromColor(e.sheenColor).multiplyScalar(e.sheen)),e.sheen>0&&null!=e.sheenColorMap)){const t=q("sheenColorMap",e.sheenColorMap).sample(p).rgb;j=j.multiply(t)}let H=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(H=A("sheenRoughness",e.sheenRoughness),e.sheen>0&&null!=e.sheenRoughnessMap)){const t=q("sheenRoughnessMap",e.sheenRoughnessMap).sample(p).r;H=H.multiply(t)}let Q=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0&&(Q=A("anisotropy",e.anisotropy),e.anisotropy>0&&null!=e.anisotropyMap)){const t=q("anisotropyMap",e.anisotropyMap).sample(p).r;Q=Q.multiply(t)}let X=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0){const t=e.anisotropyRotation??0;X=J("anisotropyDirection",new i.Vector2(Math.cos(t),Math.sin(t)))}const Y=A("alphaTest",e.alphaTest);let K,Z=e.alphaTest>0?b.lt(Y):h&&t===Qe.opaque?b.lt(.8):null;!0===e.userData.isDecal&&(Z=Z?Z.or(Le):Le),K=h?_(0,0,0,0):(n=d,G(n).multiplyScalar(.5).addScalar(.5)).rgba(e.userData?.reflective?f:1);const ee=e instanceof C?e.outputPosition:void 0,te=e instanceof C?e.outputTransform:void 0;let se,ie=D("black",1);if(e instanceof C&&null!=e.outputColor)ie=e.outputColor;else if(e instanceof i.MeshStandardMaterial)ie=U({color:w,metalness:M,roughness:f,emissive:R.rgb,normal:d,ambientOcclusion:v,ambientOcclusionIntensity:P,bakedLight:g,sheenColor:j,sheenRoughness:H,anisotropy:Q,anisotropyDirection:X});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)ie=E({color:w.rgb,ambientOcclusion:v,ambientOcclusionIntensity:P});else if(e instanceof i.MeshBasicMaterial){let e=w.rgb,t=g??F("black");null!=v&&(t=t.multiplyScalar(v.subtract(1).multiply(P).add(1))),e=e.add(t),ie=e.rgba(b)}else e instanceof i.MeshToonMaterial&&(ie=O({color:w,emissive:R.rgb,normal:d,ambientOcclusion:v,ambientOcclusionIntensity:P,bakedLight:g}));(e instanceof C||e instanceof i.MeshStandardMaterial)&&(se=e.envMap);let re=!0;(e instanceof m||e instanceof i.MeshBasicMaterial||e instanceof i.ShaderMaterial)&&(re=e.fog);let ne=D(ie.rgb,b);re&&(ne=new FogNode(ne)),r=new C({transform:te,position:null==te?ee:void 0,outputs:[ne,R.rgba(t===Qe.opaque?Y:T?1:0),K],opacity:b,outputEncoding:!1,fog:re,transparent:e.transparent,lights:!0,envMap:se,alphaTest:e.alphaTest,uniformNodes:e.uniformNodes??{},discard:Z}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=r.uniforms.envMapIntensity&&(r.uniforms.envMapIntensity.value=e.envMapIntensity),"alphaMap"in e&&null!=e.alphaMap&&(r.alphaMap=e.alphaMap),(e instanceof C||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(r),e instanceof C&&(Object.assign(r.defines,e.defines),null!=r.uniforms[pe]&&(r.uniforms[pe].value=this.aoPass.pdRenderTarget.texture,r.defines.USE_SSAO_MAP="")),r.userData.mrtOutputs=3,r.forceSinglePass=e.forceSinglePass,r.side=e.side,r.blending=e.blending,h?(r.depthWrite=!e.transparent,r.depthTest=e.depthTest,r.colorWrite=t===Qe.transparent):(r.depthWrite=e.depthWrite,r.depthTest=e.depthTest),r.visible=e.visible,r.alphaTest=e.alphaTest,r.alphaHash=e.alphaHash,r.vertexColors=e.vertexColors,r.premultipliedAlpha=e.premultipliedAlpha,r.toneMapped=e.toneMapped,r.blendAlpha=e.blendAlpha,r.blendColor=e.blendColor,r.polygonOffset=e.polygonOffset,r.polygonOffsetFactor=e.polygonOffsetFactor,r.polygonOffsetUnits=e.polygonOffsetUnits,r.blending=e.blending,r.wireframe=e.wireframe??!1,r.userData.isGBufferMaterial=!0,r.visible=c,Object.assign(r.userData,e.userData),r.visible&&(this.csm.setupMaterial(r),e instanceof u&&this.inheritCustomUniformBindings(e,r)),a.set(e,r)}var n;return r.visible&&(e instanceof u?this.updateUniformValues(e,r):this.updateMaterialProperties(e,r)),this.usesShaderUniform(r,de)&&this.initSceneColorUniform(r),this.initLightVolumeUniform(r),r}isDepthPrepassEnabled(){return!0===this.options.depthPrepass?.enabled}usesSceneFeedbackUniforms(e){return e instanceof u&&(this.usesShaderUniform(e,ae)||this.usesShaderUniform(e,de)||this.usesShaderUniform(e,pe))}usesShaderUniform(e,t){return e instanceof u&&null!=e.uniforms[t]}isDepthPrepassEligibleMaterial(e){return null!=e&&(!1!==e.visible&&!1!==e.depthTest&&!1!==e.depthWrite&&(!e.transparent&&e.blending!==i.AdditiveBlending&&(!this.usesSceneFeedbackUniforms(e)&&(e instanceof C||e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshBasicMaterial))))}isDepthPrepassEligibleMesh(e){return!!this.isDepthPrepassEnabled()&&((e instanceof i.InstancedMesh||e instanceof _e)&&(!Array.isArray(e.material)&&this.isDepthPrepassEligibleMaterial(e.material)))}createDepthPrepassMaterial(e){if(!this.isDepthPrepassEligibleMaterial(e))return null;let t=this.depthPrepassMaterialCache.get(e);if(null==t){let s,a=x(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(a=A("opacity",e.opacity??1),null!=e.map&&(a=a.multiply(q("map",e.map).sample(L.uv).a)),null!=e.alphaMap&&(a=a.multiply(q("alphaMap",e.alphaMap).sample(L.uv).r))):e instanceof C&&(a=e.outputOpacity??x(1)),null!=e.alphaTest&&e.alphaTest>0&&(s=a.lt(e.alphaTest));const r=e instanceof C?e.outputPosition:void 0,n=e instanceof C?e.outputTransform:void 0;t=new C({outputs:[D(0,0),D(0,0),D(0,0)],opacity:a,transform:n,position:null==n?r:void 0,discard:s,lights:!1,fog:!1,outputEncoding:!1,transparent:!1,alphaTest:e.alphaTest}),t.depthWrite=!0,t.depthTest=e.depthTest,t.colorWrite=!1,t.transparent=!1,t.blending=i.NoBlending,t.lights=!1,t.fog=!1,t.toneMapped=!1,t.side=e.side,t.alphaTest=e.alphaTest,t.visible=e.visible,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t.onBeforeCompile=()=>{},t.customProgramCacheKey=()=>`depth-prepass:${e.id}:${e.version}:${e.alphaTest}:${e.side}`;for(const e of Bt)delete t.uniforms[e];for(const e of Ot)delete t.uniforms[e];delete t.uniforms.receiveShadow,this.depthPrepassMaterialCache.set(e,t)}return e instanceof C?this.updateUniformValues(e,t):this.updateMaterialProperties(e,t),t.depthWrite=!0,t.depthTest=e.depthTest,t.colorWrite=!1,t.transparent=!1,t.blending=i.NoBlending,t.visible=e.visible,t.alphaTest=e.alphaTest,t.side=e.side,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t}applyDepthPrepassMaterials(){const e=this.depthPrepassCachedMaterials,t=this.depthPrepassCachedVisibility;e.clear(),t.length=0,ve(this.scene,s=>{if(xt(s))return t.push(s),s.visible=!1,!1;if(!(s instanceof o))return;if(e.set(s,s.material),!this.isDepthPrepassEligibleMesh(s))return t.push(s),void(s.visible=!1);const i=this.createDepthPrepassMaterial(s.material);if(null==i)return t.push(s),void(s.visible=!1);s.material=i,s.visible=!0})}unapplyDepthPrepassMaterials(){this.depthPrepassCachedMaterials.forEach((e,t)=>{t.material=e}),this.depthPrepassCachedVisibility.forEach(e=>{e.visible=!0})}renderDepthPrepass(){if(!this.isDepthPrepassEnabled())return;this.applyDepthPrepassMaterials();const e=this.scene.matrixWorldAutoUpdate,t=this.scene.matrixAutoUpdate,s=this.renderer.shadowMap.autoUpdate;this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clearDepth();try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Depth prepass render failed",e)}this.unapplyDepthPrepassMaterials(),this.renderer.shadowMap.autoUpdate=s,this.scene.matrixWorldAutoUpdate=e,this.scene.matrixAutoUpdate=t}updateCsm(){const e=this.csmUpdateInvervals;if(this.renderer.shadowMap.autoUpdate&&null!=this.csmCascadeLastUpdate&&Array.isArray(e)){const t=performance.now();for(let s=0;s<this.csm.lights.length;++s){const i=e[s]??e[e.length-1]??16;(t-this.csmCascadeLastUpdate[s]>=i||0===s)&&this.csm.lights[s].shadow&&(this.csm.lights[s].shadow.needsUpdate=!0,this.csmCascadeLastUpdate[s]=t)}}this.csm.update()}loop(t,s=!1){const a=this.stats,r=a.addPanel(new te.Panel("Calls","#83f","#002")),l=a.addPanel(new te.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new fe(this.renderer.getContext()),a.addPanel(h)),this.showStats=s;let u=10,c=1e3;const p=()=>{const e=this.renderer.info.render.calls;e>u&&(u=e,setTimeout(()=>u=10,5e3)),r.update(e,u);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout(()=>c=1e3,5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const d=[],m=[],f=[],g=[];let M=0;const v=new n,P=new n;let y=0;let b=this.paused,w=!1,T=0,R=null,S=this.fpsCapRevision;const x=()=>{this.running&&!0!==this.options.enableXR&&requestAnimationFrame(B)},U=()=>{e.activeView=this,w&&(w=!1,requestAnimationFrame(()=>B(T)))};this.wakePausedRenderer=U;const A=at();it.set(this.container,e=>{this.isIntersecting=e,e&&U()}),A.observe(this.container),this.container.addEventListener("pointerdown",()=>{U()},{capture:!0});const B=s=>{w=!1;const r=this.renderer.getContext(),n=this.needsPausedRender;if(!this.running||null===this.container.offsetParent||this.paused&&!n&&r.drawingBufferHeight>1)return w=!0,T=s,setTimeout(()=>{w&&B(s)},500),void(this.paused&&(b=!0));if(this.renderer.domElement.parentElement!==this.container){if(e.activeView!==this&&null!==e.activeView)return w=!0,void(T=s);this.attachRendererDomElement(),this.resizeRender()}if(!0!==this.options.enableXR){S!==this.fpsCapRevision&&(S=this.fpsCapRevision,R=null);const e=this.fpsCap;if(null!=e){const t=1e3/e;if(null!=R){const e=s-R;if(e<t)return void x();R=s-e%t}else R=s}else R=s}let l=(s*=.001)-M;if(M=s,b?(l=.016,b=!1,this.resetUpscalingHistory()):l>.25&&this.resetUpscalingHistory(),this.updateDynamicResolution(l,1e3*s),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),a.begin(),this.showStats&&h?.startQuery(),this.ssrPass.gpuPanel=h,v.copy(this.camera.matrixWorld),!this.paused){if(l>1){let e=l;for(;e>.05;)t(nt),e-=nt;t(e)}else t(l);this.onLoopCallbacks.forEach(e=>e(l))}this.paused||(this.simulationTime+=l*this.simulationTimeScale);const u=this.simulationTime;this.camera?.updateMatrixWorld(),P.copy(this.camera.matrixWorld),s-y>.08&&!P.equals(v)&&(this.renderer.shadowMap.needsUpdate=!0,y=s),this.updateCsm();let c=!1;d.length=0,m.length=0,f.length=0;for(const e of g)e.visible=!0;g.length=0;const U=ut;pt.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),U.setFromProjectionMatrix(pt);let A=!1,O=!1,E=!1;const G=this.frameGBufferMeshes,F=this.frameGBufferPhaseMasks,D=this.frameUnsupportedGBufferObjects,j=this.frameGBufferExcludedObjects;if(G.length=0,F.length=0,D.length=0,j.clear(),this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Ge&&(A=!0),e instanceof o&&this.initCustomDepthMaterial(e),(e instanceof o||e instanceof i.Sprite)&&(this.initResolutionUniform(e.material),this.initNormalUniform(e.material),this.initShadowUniform(e,e.material),this.initLightVolumeUniform(e.material),null!=this.scene.environment&&ht(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(c=!0)),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ae])&&isObjectInFrustum(e,U)?(this.initDepthUniform(e.material),O=!0):e instanceof X&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[pe]&&isObjectInFrustum(e,U)&&e.material instanceof C&&this.initAoUniform(e.material),e instanceof o||e instanceof i.Sprite){let t=!1;ht(e,e=>{this.usesShaderUniform(e,de)&&(this.initSceneColorUniform(e),t=!0)}),t&&(f.push(e),E=!0)}if(e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[ce])e.material.uniforms[ce].value=u;else if(e instanceof o&&Array.isArray(e.material))for(const t of e.material)t.uniforms&&null!=t.uniforms[ce]&&(t.uniforms[ce].value=u);if(j.has(e))for(let t=0;t<e.children.length;t++)j.add(e.children[t]);else if(xt(e)){D.push(e);for(let t=0;t<e.children.length;t++)j.add(e.children[t])}else e instanceof o&&(G.push(e),F.push(this.getGBufferPhaseMask(e.material)))}),j.clear(),this.phasedRenderPass.enabled=D.length>0,this.bloomPass.enabled=c,!0===this.options.occlusionCulling?.enabled){for(const e of this.occlusionClusters)e.update();this.hideOccluded(g)}this.prepareUpscalingFrame(),this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderDepthPrepass(),this.renderScene(Qe.opaque),this.updateRenderedOcclusionClusters(),this.renderer.render(this.queryScene,this.camera),this.aoPass.output=se.OUTPUT.Off;for(const e of this.postProcessEffects)if(e.pass.enabled&&this.usesShaderUniform(e.pass.material,ae)){O=!0;break}E&&(this.fquadCopySceneColor.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.fquadCopySceneColor.render(this.renderer)),O&&(this.fquadCopySceneDepth.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.renderer.setRenderTarget(this.sceneDepthRenderTarget),this.fquadCopySceneDepth.render(this.renderer)),(O||E)&&this.renderer.setRenderTarget(this.gRenderTarget),f.length,d.forEach(e=>e.visible=!0),m.forEach(e=>e.visible=!0),f.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=s),this.volumetricFogPass&&A?(this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1),this.updatePostProcessEffectUniforms(u);try{this.paused&&!n||!this.running||(this.render(l),this.finishUpscalingFrame(),this.showStats&&h?.endQuery(),this.showStats&&p(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}finally{this.finishUpscalingFrame(),n&&(this.needsPausedRender=!1)}a.end(),this.csm?.update(),x()};!0===this.options.enableXR?this.renderer.setAnimationLoop(B):requestAnimationFrame(B)}collectGBufferRenderables(e,t=this.frameGBufferMeshes,s=this.frameGBufferPhaseMasks,i=this.frameUnsupportedGBufferObjects){t.length=0,s.length=0,i.length=0,ve(e,e=>{if(xt(e))return i.push(e),!1;e instanceof o&&(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<<Qe.opaque|1<<Qe.transparent,this.gBufferPhaseMaskCache.set(e,t),t;const s=this.usesShaderUniform(e,ae),a=this.usesShaderUniform(e,de),r=this.usesShaderUniform(e,pe),n=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,o=s||a||r;return t=0,o||n||(t|=1<<Qe.opaque),(o||n)&&(t|=1<<Qe.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===Qe.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,r=this.originalGBufferMaterials,n=this.originalGBufferOnBeforeRender,o=this.hiddenGBufferObjects;a.length=0,r.length=0,n.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 u=h.material;if(0!==(s[i]&l)||0!==h.children.length)if(a.push(h),r.push(u),n.push(h.onBeforeRender),0!==(s[i]&l)){if(Array.isArray(u)){const t=this.getGBufferMaterialArray(u,e);h.material=t;for(let e=0;e<t.length;e++)this.initShadowUniform(h,t[e])}else{const t=this.createGBufferMaterial(u,e,e===Qe.opaque&&this.isDepthPrepassEligibleMesh(h));h.material=t,this.initShadowUniform(h,t)}this.applyGBufferShadowUniformUpdater(h)}else h.material=Ze;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,r,n,o,l)=>{a.original.call(e,t,s,r,n,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 o)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)this._initMaterialTextures(e.material[t]);else this._initMaterialTextures(e.material)})}_initMaterialTextures(e){if(!this._initiatedMaterialTextures.has(e))if(this._initiatedMaterialTextures.add(e),e instanceof u){for(const[t,s]of Object.entries(e.uniforms))if(s.value instanceof p){if(this._initiatedTextures.has(s.value))continue;this.renderer.initTexture(s.value),this._initiatedTextures.add(s.value)}}else for(const[t,s]of Object.entries(e))if(s instanceof p){if(this._initiatedTextures.has(s))continue;this.renderer.initTexture(s),this._initiatedTextures.add(s)}}async compileAsync(e=this.scene){if(this.compileInProgress)return;this.renderer.setRenderTarget(this.gRenderTarget),this.compileInProgress=!0;const t=[],s=[],i=[];this.collectGBufferRenderables(e,t,s,i),this.applyGBufferMaterials(Qe.opaque,t,s,i),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(Qe.transparent,t,s,i),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 a=this.csm.lights[0]?.shadow.camera;null!=a&&(this.applyDepthMaterial(),await this.renderer.compileAsync(e,a),this.unapplyDepthMaterial()),this.compileInProgress=!1,this.renderer.setRenderTarget(null)}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=Gt: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!==Qe.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===Qe.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 u&&this.updateLightUniformValues(s.material,i)}}this.unapplyGBufferMaterials(),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t.colorSpace=i.SRGBColorSpace,t}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);!function(e,t=i.NoToneMapping,s=1){e.tonemapMapping=t,e.tonemapExposure=s,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=e.colorTint??new i.Color("white"),e.colorTint.set("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.globalSaturation=dt(e.globalSaturation,1,1,1),e.globalContrast=dt(e.globalContrast,1,1,1),e.globalGamma=dt(e.globalGamma,1,1,1),e.globalGain=dt(e.globalGain,1,1,1),e.globalOffset=dt(e.globalOffset,0,0,0),e.shadowsSaturation=dt(e.shadowsSaturation,1,1,1),e.shadowsContrast=dt(e.shadowsContrast,1,1,1),e.shadowsGamma=dt(e.shadowsGamma,1,1,1),e.shadowsGain=dt(e.shadowsGain,1,1,1),e.shadowsOffset=dt(e.shadowsOffset,0,0,0),e.shadowsMax=.09,e.midtonesSaturation=dt(e.midtonesSaturation,1,1,1),e.midtonesContrast=dt(e.midtonesContrast,1,1,1),e.midtonesGamma=dt(e.midtonesGamma,1,1,1),e.midtonesGain=dt(e.midtonesGain,1,1,1),e.midtonesOffset=dt(e.midtonesOffset,0,0,0),e.highlightsSaturation=dt(e.highlightsSaturation,1,1,1),e.highlightsContrast=dt(e.highlightsContrast,1,1,1),e.highlightsGamma=dt(e.highlightsGamma,1,1,1),e.highlightsGain=dt(e.highlightsGain,1,1,1),e.highlightsOffset=dt(e.highlightsOffset,0,0,0),e.highlightsMin=.5,e.lut=void 0,e.lutIntensity=0}(this.postProcessSettings,this.baseToneMapping,this.baseToneMappingExposure);const e=this.postProcessSettings;let t,s=!1;if(null==this.camera)return;const a=this.camera.getWorldPosition(vt);let r=[];for(const n of this.postProcessVolumes){if(!ot(n.object))continue;let o=n.blendWeight??1;const l=n.distanceToPoint(a);l>n.blendRadius||(n.blendRadius>0&&(o*=Pe(1-l/n.blendRadius,0,1)),o>1&&(o=1),o>0&&(r.push(n),void 0!==n.settings.tonemapMapping&&(e.tonemapMapping=n.settings.tonemapMapping),void 0!==n.settings.tonemapExposure&&(e.tonemapExposure=i.MathUtils.lerp(e.tonemapExposure,n.settings.tonemapExposure,o)),void 0!==n.settings.envTexture&&(e.envTexture=n.settings.envTexture),void 0!==n.settings.envIntensity&&(e.envIntensity=i.MathUtils.lerp(e.envIntensity,n.settings.envIntensity,o)),void 0!==n.settings.vignetteIntensity&&(e.vignetteIntensity=i.MathUtils.lerp(e.vignetteIntensity,n.settings.vignetteIntensity,o)),void 0!==n.settings.colorTint&&void 0!==n.settings.colorTintIntensity&&n.settings.colorTintIntensity>0&&(e.colorTint=e.colorTint.lerp(n.settings.colorTint,o)),void 0!==n.settings.colorTintIntensity&&(e.colorTintIntensity=i.MathUtils.lerp(e.colorTintIntensity,n.settings.colorTintIntensity,o)),void 0!==n.settings.depthFocus&&(s=!0,e.depthFocus=void 0!==e.depthFocus?i.MathUtils.lerp(e.depthFocus,n.settings.depthFocus,o):n.settings.depthFocus),void 0!==n.settings.depthAperture&&(s=!0,e.depthAperture=void 0!==e.depthAperture?i.MathUtils.lerp(e.depthAperture,n.settings.depthAperture,o):n.settings.depthAperture),void 0!==n.settings.depthMaxBlur&&(s=!0,e.depthMaxBlur=void 0!==e.depthMaxBlur?i.MathUtils.lerp(e.depthMaxBlur,n.settings.depthMaxBlur,o):n.settings.depthMaxBlur),void 0!==n.settings.temperature&&(e.temperature=i.MathUtils.lerp(e.temperature,n.settings.temperature,o)),void 0!==n.settings.temperatureTint&&(e.temperatureTint=i.MathUtils.lerp(e.temperatureTint,n.settings.temperatureTint,o)),void 0!==n.settings.globalSaturation&&e.globalSaturation.lerp(n.settings.globalSaturation,o),void 0!==n.settings.globalContrast&&e.globalContrast.lerp(n.settings.globalContrast,o),void 0!==n.settings.globalGamma&&e.globalGamma.lerp(n.settings.globalGamma,o),void 0!==n.settings.globalGain&&e.globalGain.lerp(n.settings.globalGain,o),void 0!==n.settings.globalOffset&&e.globalOffset.lerp(n.settings.globalOffset,o),void 0!==n.settings.shadowsSaturation&&e.shadowsSaturation.lerp(n.settings.shadowsSaturation,o),void 0!==n.settings.shadowsContrast&&e.shadowsContrast.lerp(n.settings.shadowsContrast,o),void 0!==n.settings.shadowsGamma&&e.shadowsGamma.lerp(n.settings.shadowsGamma,o),void 0!==n.settings.shadowsGain&&e.shadowsGain.lerp(n.settings.shadowsGain,o),void 0!==n.settings.shadowsOffset&&e.shadowsOffset.lerp(n.settings.shadowsOffset,o),void 0!==n.settings.shadowsMax&&(e.shadowsMax=i.MathUtils.lerp(e.shadowsMax,n.settings.shadowsMax,o)),void 0!==n.settings.midtonesSaturation&&e.midtonesSaturation.lerp(n.settings.midtonesSaturation,o),void 0!==n.settings.midtonesContrast&&e.midtonesContrast.lerp(n.settings.midtonesContrast,o),void 0!==n.settings.midtonesGamma&&e.midtonesGamma.lerp(n.settings.midtonesGamma,o),void 0!==n.settings.midtonesGain&&e.midtonesGain.lerp(n.settings.midtonesGain,o),void 0!==n.settings.midtonesOffset&&e.midtonesOffset.lerp(n.settings.midtonesOffset,o),void 0!==n.settings.highlightsSaturation&&e.highlightsSaturation.lerp(n.settings.highlightsSaturation,o),void 0!==n.settings.highlightsContrast&&e.highlightsContrast.lerp(n.settings.highlightsContrast,o),void 0!==n.settings.highlightsGamma&&e.highlightsGamma.lerp(n.settings.highlightsGamma,o),void 0!==n.settings.highlightsGain&&e.highlightsGain.lerp(n.settings.highlightsGain,o),void 0!==n.settings.highlightsOffset&&e.highlightsOffset.lerp(n.settings.highlightsOffset,o),void 0!==n.settings.highlightsMin&&(e.highlightsMin=i.MathUtils.lerp(e.highlightsMin,n.settings.highlightsMin,o)),void 0!==n.settings.lut&&(t=n.settings.lut),void 0!==n.settings.lutIntensity&&(e.lutIntensity=i.MathUtils.lerp(e.lutIntensity,n.settings.lutIntensity,o))))}if(0===r.length)return this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);const n=e.vignetteIntensity>Mt,o=(h=e.temperature,u=e.temperatureTint,!ft(h,6500)||!ft(u,0));var h,u;const c=(p=e.colorTint,e.colorTintIntensity>Mt&&(!ft(p.r,1)||!ft(p.g,1)||!ft(p.b,1)));var p;const d=!(mt((m=e).globalSaturation,1,1,1)&&mt(m.globalContrast,1,1,1)&&mt(m.globalGamma,1,1,1)&&mt(m.globalGain,1,1,1)&&mt(m.globalOffset,0,0,0)&&mt(m.shadowsSaturation,1,1,1)&&mt(m.shadowsContrast,1,1,1)&&mt(m.shadowsGamma,1,1,1)&&mt(m.shadowsGain,1,1,1)&&mt(m.shadowsOffset,0,0,0)&&mt(m.midtonesSaturation,1,1,1)&&mt(m.midtonesContrast,1,1,1)&&mt(m.midtonesGamma,1,1,1)&&mt(m.midtonesGain,1,1,1)&&mt(m.midtonesOffset,0,0,0)&&mt(m.highlightsSaturation,1,1,1)&&mt(m.highlightsContrast,1,1,1)&&mt(m.highlightsGamma,1,1,1)&&mt(m.highlightsGain,1,1,1)&&mt(m.highlightsOffset,0,0,0));var m;const f=o||c||d||n,g=f&&e.tonemapMapping!==i.NoToneMapping,M=null!=t&&e.lutIntensity>Mt;f?(this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1):(this.renderer.toneMapping=e.tonemapMapping,this.renderer.toneMappingExposure=e.tonemapExposure),null!=e.envTexture&&(this.scene.environment=this.getEnvTexture(e.envTexture)),this.scene.environmentIntensity=e.envIntensity,f?(this.colorPass.whiteBalanceEnabled=o,this.colorPass.whiteBalanceScale=o?function(e,t,s){const i=function(e){const t=Pe(e,1e3,4e4)/100,s=t<=66?1:Pe(1.292936186062745*Math.pow(t-60,-.1332047592),0,1),i=Pe(t<=66?.3900815787690196*Math.log(t)-.6318414437886275:1.129890860895294*Math.pow(t-60,-.0755148492),0,1),a=t>=66?1:t<=19?0:Pe(.5432067891101962*Math.log(t-10)-1.19625408914,0,1);return yt.set(s,i,a)}(t),a=1+.2*Pe(s,-1,1),r=i.x,n=i.y*a,o=i.z,l=Math.max(n,1e-4);return e.set(1/Math.max(r/l,1e-4),1/Math.max(n/l,1e-4),1/Math.max(o/l,1e-4)),e}(Pt,e.temperature,e.temperatureTint):Pt.set(1,1,1),this.colorPass.vignetteIntensity=e.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTintEnabled=c,this.colorPass.colorTint=e.colorTint,this.colorPass.colorTintIntensity=e.colorTintIntensity,this.colorPass.colorGradingEnabled=d,this.colorPass.toneMapping=e.tonemapMapping,this.colorPass.toneMappingEnabled=g,this.colorPass.toneMappingExposure=e.tonemapExposure,this.colorPass.globalSaturation=e.globalSaturation,this.colorPass.globalContrast=e.globalContrast,this.colorPass.globalGamma=e.globalGamma,this.colorPass.globalGain=e.globalGain,this.colorPass.globalOffset=e.globalOffset,this.colorPass.shadowsSaturation=e.shadowsSaturation,this.colorPass.shadowsContrast=e.shadowsContrast,this.colorPass.shadowsGamma=e.shadowsGamma,this.colorPass.shadowsGain=e.shadowsGain,this.colorPass.shadowsOffset=e.shadowsOffset,this.colorPass.shadowsMax=e.shadowsMax,this.colorPass.midtonesSaturation=e.midtonesSaturation,this.colorPass.midtonesContrast=e.midtonesContrast,this.colorPass.midtonesGamma=e.midtonesGamma,this.colorPass.midtonesGain=e.midtonesGain,this.colorPass.midtonesOffset=e.midtonesOffset,this.colorPass.highlightsSaturation=e.highlightsSaturation,this.colorPass.highlightsContrast=e.highlightsContrast,this.colorPass.highlightsGamma=e.highlightsGamma,this.colorPass.highlightsGain=e.highlightsGain,this.colorPass.highlightsOffset=e.highlightsOffset,this.colorPass.highlightsMin=e.highlightsMin,this.colorPass.enabled=!0):this.colorPass.enabled=!1,s&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==e.depthFocus&&(this.dofPass.uniforms.focus.value=e.depthFocus),void 0!==e.depthAperture&&(this.dofPass.uniforms.aperture.value=e.depthAperture),void 0!==e.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=e.depthMaxBlur)):this.dofPass.enabled=!1,this.lutPass.enabled=M,M&&(null!=t&&(t.flipY=!0,t.generateMipmaps=!1),this.lutPass.lut=t,this.lutPass.intensity=e.lutIntensity)}updatePostProcessEffectUniforms(e){if(0===this.postProcessEffects.length)return;const t=this.postProcessEffectUniformState;t.aoEnabled=this.aoPass.enabled,t.aoTexture=this.aoPass.enabled?this.aoPass.pdRenderTarget.texture:null,this.camera instanceof l?(t.cameraNear=this.camera.near,t.cameraFar=this.camera.far):(t.cameraNear=void 0,t.cameraFar=void 0),t.depthTexture=this.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(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled&&!1!==this.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible(t=>{t instanceof o&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,ut)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.options.bloom,this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=Me(this.scene,e=>e instanceof o&&!0===e.material?.userData?.hasBloom)}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===$e.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=$e:(e.visible=!1,this.bloomHidden.push(e))}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initSceneColorUniform(e){if(e instanceof u)return null==e.uniforms[de]?(e.uniforms[de]={value:this.sceneColorRenderTarget.texture},void(e.uniformsNeedUpdate=!0)):void(e.uniforms[de].value!==this.sceneColorRenderTarget.texture&&(e.uniforms[de].value=this.sceneColorRenderTarget.texture,e.uniformsNeedUpdate=!0))}initDepthUniform(e){e instanceof u&&(e.uniforms[ae].value=this.sceneDepthRenderTarget.texture,this.camera instanceof l&&(null!=e.uniforms[ne]&&(e.uniforms[ne].value=this.camera.near),null!=e.uniforms[re]&&(e.uniforms[re].value=this.camera.far)))}initNormalUniform(e){e instanceof u&&null!=e.uniforms[le]&&(e.uniforms[le].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof C&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof C&&(null!=this.lightVolume?null==e.uniforms.uSH?(e.defines.USE_LIGHT_PROBE_VOLUME="",e.uniforms.gridOrigin={value:this.lightVolume.gridOrigin},e.uniforms.gridSize={value:this.lightVolume.gridSize},e.uniforms.gridRes={value:this.lightVolume.gridResolution},e.uniforms.giIntensity={value:this.lightProbeIntensity},e.uniforms.uSH={value:this.lightVolume.shTexture},e.uniformsNeedUpdate=!0,e.needsUpdate=!0):e.uniforms.giIntensity.value=this.lightProbeIntensity:null!=e.uniforms.uSH&&(delete e.defines.USE_LIGHT_PROBE_VOLUME,delete e.uniforms.gridOrigin,delete e.uniforms.gridSize,delete e.uniforms.gridRes,delete e.uniforms.giIntensity,delete e.uniforms.uSH,e.uniformsNeedUpdate=!0,e.needsUpdate=!0))}initResolutionUniform(e){e instanceof u&&null!=e.uniforms[oe]&&e.uniforms[oe].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 C&&t.depthWrite&&t.alphaTest>0))return;let s=this._customDepthMaterialCache.get(t);if(null==s){const e=Ee(Oe);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new C({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}};rt.activeView=null,rt=e=t([ie(),s("design:paramtypes",[HTMLElement,Object])],rt);export{rt as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const nt=.05;function ot(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}function lt(e,t){return e.priority!==t.priority?e.priority-t.priority:e.id-t.id}function ht(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}se.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};new i.Box3;const ut=new i.Frustum,ct=new i.Box3,pt=new i.Matrix4;export function isObjectInFrustum(e,t){const s=ct.setFromObject(e);return t.intersectsBox(s)}function dt(e,t,s,a){return null==e?new i.Vector3(t,s,a):e.set(t,s,a)}function mt(e,t,s,i){return null!=e&&ft(e.x,t)&&ft(e.y,s)&&ft(e.z,i)}function ft(e,t,s=Mt){return Math.abs(e-t)<=s}function gt(e,t){return null!=e&&Number.isFinite(e)&&e>0?e:t}const Mt=1e-4,vt=new i.Vector3,Pt=new i.Vector3(1,1,1),yt=new i.Vector3(1,1,1);const bt=new n,wt=new d;function Tt(e,t,s=new i.Matrix3){return wt.copy(e),wt.x*=-1,wt.y*=-1,wt.z*=-1,t.isCubeTexture&&!1===t.isRenderTargetTexture&&(wt.y*=-1,wt.z*=-1),s.setFromMatrix4(bt.makeRotationFromEuler(wt))}const Rt=new C({outputs:[_(0,0,0,0),_(0,0,0,0),D(F("white"),Ie(4))],transparent:!0}),St=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});Rt.depthWrite=!1;new o(new i.BoxGeometry(4,4,4),St);function xt(e){return e instanceof i.Sprite||e.isPoints||e.isLine||e.isLineSegments2||e.isTransformControls||e.isTransformControlsGizmo||e instanceof o&&Ct(e,e.material)}function Ct(e,t){return null==t||(Array.isArray(t)?t.some(t=>Ct(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof C))}class Ut extends Ve{constructor(e,t,s){super(),this.scene=e,this.camera=t,this.gRenderTarget=s,this.cachedVisibility=[],this.toRender=[],this.needsSwap=!1}render(e,t,s,i,a){const r=e.autoClear;e.autoClear=!1;const n=this.scene.matrixWorldAutoUpdate,l=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const u=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),this.cachedVisibility.length=0;let c=0,p=this.toRender;if(p.length=0,this.scene.traverseVisible(e=>{const t=xt(e);e instanceof o&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(c++,p.push(e))}),c>0)for(const t of p)e.render(t,this.camera);this.cachedVisibility.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=r,s.depthTexture=u,this.scene.matrixWorldAutoUpdate=n,this.scene.matrixAutoUpdate=l,e.shadowMap.autoUpdate=h}}class At extends Ve{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const Bt=["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"],Ot=["directionalShadowMap","directionalShadowMatrix","pointLightShadows","pointShadowMap","pointShadowMatrix","spotLightShadows","spotShadowMap"],Et=B("fogColor");export class FogNode extends H{constructor(e,t=Et){super(),this.source=e,this.fogColor=t}compile(e){const t=e.variable(),s=e.get(this.source.rgb),i=e.get(this.source.a),a=e.get(this.fogColor),r=e.get(A("fogFar")),n=e.get(A("fogNear")),o=e.get(A("fogDensity")),l=e.get(I(j.mvPosition.z));return{pars:"\n ",chunk:`\n #ifdef FOG_EXP2\n float fogFactor_${t} = 1.0 - exp( - ${o} * ${o} * ${l} * ${l} );\n #else\n float fogFactor_${t} = smoothstep( ${n}, ${r}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${a}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}const Gt=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
|
*/
|