@hology/core 0.0.193 → 0.0.195
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effects/sequence/index.d.ts +5 -0
- package/dist/effects/sequence/index.js +1 -1
- package/dist/effects/sequence/sequence-action.d.ts +2 -1
- package/dist/effects/sequence/sequence-actor.d.ts +9 -0
- package/dist/effects/sequence/sequence-actor.js +1 -1
- package/dist/effects/sequence/sequence-animation-retiming.d.ts +15 -0
- package/dist/effects/sequence/sequence-animation-retiming.js +4 -0
- package/dist/effects/sequence/sequence-data.d.ts +48 -2
- package/dist/effects/sequence/sequence-data.js +1 -1
- package/dist/effects/sequence/sequence-definitions.d.ts +53 -0
- package/dist/effects/sequence/sequence-definitions.js +4 -0
- package/dist/effects/sequence/sequence-event.d.ts +24 -1
- package/dist/effects/sequence/sequence-event.js +1 -1
- package/dist/effects/sequence/sequence-locator.d.ts +14 -0
- package/dist/effects/sequence/sequence-locator.js +4 -0
- package/dist/effects/sequence/sequence-ops.d.ts +48 -0
- package/dist/effects/sequence/sequence-ops.js +4 -0
- package/dist/effects/sequence/sequence-player.d.ts +37 -3
- package/dist/effects/sequence/sequence-player.js +1 -1
- package/dist/effects/sequence/sequence-value-lane.d.ts +21 -0
- package/dist/effects/sequence/sequence-value-lane.js +4 -0
- package/dist/gameplay/actors/builtin/components/character/character-animation.d.ts +1 -0
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/post-process-volume-actor.d.ts +25 -1
- package/dist/gameplay/actors/builtin/post-process-volume-actor.js +1 -1
- package/dist/gameplay/index.d.ts +1 -0
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.d.ts +4 -0
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/services/game-time-scheduler.d.ts +25 -0
- package/dist/gameplay/services/game-time-scheduler.js +4 -0
- package/dist/gameplay/services/render.d.ts +11 -2
- package/dist/gameplay/services/render.js +1 -1
- package/dist/rendering/color-pass.d.ts +62 -7
- package/dist/rendering/color-pass.js +1 -1
- package/dist/rendering.d.ts +25 -0
- package/dist/rendering.js +1 -1
- package/dist/scene/custom-param-deserialize.d.ts +18 -0
- package/dist/scene/custom-param-deserialize.js +4 -0
- package/dist/scene/materializer.d.ts +1 -0
- package/dist/scene/materializer.js +1 -1
- package/dist/shader/builtin/landscape-composite-shader.js +1 -1
- package/dist/shader/parameter.d.ts +5 -0
- package/dist/test/post-process-color-grading.test.d.ts +2 -0
- package/dist/test/post-process-color-grading.test.js +4 -0
- package/dist/test/sequence-animation-retiming.test.d.ts +2 -0
- package/dist/test/sequence-animation-retiming.test.js +4 -0
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { BaseActor } from "../actors/actor.js";
|
|
3
|
+
/**
|
|
4
|
+
* Handles gameplay timing primitives that need to cooperate with pause/resume
|
|
5
|
+
* and game-time progression without adding per-frame allocations.
|
|
6
|
+
*/
|
|
7
|
+
export declare class GameTimeScheduler {
|
|
8
|
+
private activeTimers;
|
|
9
|
+
private nextTimerId;
|
|
10
|
+
private activeIntervals;
|
|
11
|
+
private intervalIndices;
|
|
12
|
+
private nextIntervalId;
|
|
13
|
+
private isUpdatingIntervals;
|
|
14
|
+
private hasPendingIntervalRemovals;
|
|
15
|
+
update(deltaTimeMs: number): void;
|
|
16
|
+
pause(): void;
|
|
17
|
+
resume(): void;
|
|
18
|
+
setInterval(callback: () => void, intervalMs: number, owner?: BaseActor): number;
|
|
19
|
+
clearInterval(intervalId: number): void;
|
|
20
|
+
createTimer(durationMs: number): Observable<void>;
|
|
21
|
+
dispose(): void;
|
|
22
|
+
private cleanupInactiveIntervals;
|
|
23
|
+
private removeIntervalAt;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=game-time-scheduler.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{Observable as e}from"rxjs";export class GameTimeScheduler{constructor(){this.activeTimers=new Map,this.nextTimerId=0,this.activeIntervals=[],this.intervalIndices=new Map,this.nextIntervalId=0,this.isUpdatingIntervals=!1,this.hasPendingIntervalRemovals=!1}update(e){if(e<=0||0===this.activeIntervals.length)return;const t=this.activeIntervals;this.isUpdatingIntervals=!0;try{for(let i=0;i<t.length;){const s=t[i];if(!s.active){this.removeIntervalAt(i);continue}if(s.elapsedMs+=e,s.elapsedMs<s.intervalMs){i++;continue}const n=Math.floor(s.elapsedMs/s.intervalMs);s.elapsedMs-=n*s.intervalMs;for(let e=0;e<n&&(s.callback(),s.active);e++);s.active?i++:this.removeIntervalAt(i)}}finally{this.isUpdatingIntervals=!1,this.hasPendingIntervalRemovals&&this.cleanupInactiveIntervals()}}pause(){for(const e of this.activeTimers.values()){clearTimeout(e.timeoutId);const t=Date.now()-e.startTime;e.remainingMs=Math.max(0,e.remainingMs-t)}}resume(){for(const[e,t]of this.activeTimers)t.remainingMs>0&&(t.timeoutId=setTimeout(()=>{t.subscriber.next(),t.subscriber.complete(),this.activeTimers.delete(e)},t.remainingMs),t.startTime=Date.now())}setInterval(e,t,i){if(t<=0)throw new Error("intervalMs must be greater than 0");const s=this.nextIntervalId++,n={id:s,callback:e,intervalMs:t,elapsedMs:0,active:!0};return null!=i&&(n.ownerSubscription=i.disposed.subscribe(()=>{this.clearInterval(s)})),this.intervalIndices.set(s,this.activeIntervals.length),this.activeIntervals.push(n),s}clearInterval(e){const t=this.intervalIndices.get(e);if(null==t)return;const i=this.activeIntervals[t];i.active&&(i.active=!1,i.ownerSubscription?.unsubscribe(),i.ownerSubscription=void 0,this.isUpdatingIntervals?this.hasPendingIntervalRemovals=!0:this.removeIntervalAt(t))}createTimer(t){const i=this.nextTimerId++;return new e(e=>{const s=Date.now(),n=setTimeout(()=>{e.next(),e.complete(),this.activeTimers.delete(i)},t);return this.activeTimers.set(i,{timeoutId:n,remainingMs:t,startTime:s,subscriber:e}),()=>{clearTimeout(n),this.activeTimers.delete(i)}})}dispose(){for(const e of this.activeTimers.values())clearTimeout(e.timeoutId);this.activeTimers.clear();for(let e=this.activeIntervals.length-1;e>=0;e--)this.removeIntervalAt(e);this.hasPendingIntervalRemovals=!1,this.isUpdatingIntervals=!1}cleanupInactiveIntervals(){for(let e=this.activeIntervals.length-1;e>=0;e--)this.activeIntervals[e].active||this.removeIntervalAt(e);this.hasPendingIntervalRemovals=!1}removeIntervalAt(e){const t=this.activeIntervals,i=t[e];if(null==i)return;i.ownerSubscription?.unsubscribe(),i.ownerSubscription=void 0,this.intervalIndices.delete(i.id);const s=t.length-1;if(e!==s){const i=t[s];t[e]=i,this.intervalIndices.set(i.id,e)}t.pop()}}/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -15,8 +15,7 @@ export declare class ViewController {
|
|
|
15
15
|
private _muted;
|
|
16
16
|
private _timeScale;
|
|
17
17
|
private _hitStopRemaining;
|
|
18
|
-
private
|
|
19
|
-
private nextTimerId;
|
|
18
|
+
private scheduler;
|
|
20
19
|
constructor(view: RenderingView);
|
|
21
20
|
private handleFrame;
|
|
22
21
|
set timeScale(value: number);
|
|
@@ -54,6 +53,16 @@ export declare class ViewController {
|
|
|
54
53
|
set paused(value: boolean);
|
|
55
54
|
pauseRendering(): void;
|
|
56
55
|
unpauseRendering(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Register a callback that advances in game time rather than wall clock time.
|
|
58
|
+
* The interval uses the same effective delta time as `onUpdate()`, so it pauses
|
|
59
|
+
* while rendering is paused, during hit stop, and when `timeScale` is `0`.
|
|
60
|
+
*
|
|
61
|
+
* If a large frame delta occurs, the callback may run multiple times in one frame
|
|
62
|
+
* so game-time steps are not skipped.
|
|
63
|
+
*/
|
|
64
|
+
setInterval(callback: () => void, intervalMs: number, owner?: BaseActor): number;
|
|
65
|
+
clearInterval(intervalId: number): void;
|
|
57
66
|
dispose(): void;
|
|
58
67
|
/**
|
|
59
68
|
* Creates a timer that emits once after the specified duration (in milliseconds),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Service as i}from"typedi";import{Camera as s}from"three";import{RenderingView as n}from"../../rendering.js";import{BehaviorSubject as
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Service as i}from"typedi";import{Camera as s}from"three";import{RenderingView as n}from"../../rendering.js";import{BehaviorSubject as h,Subject as r,takeUntil as a}from"rxjs";import*as o from"three";import{GameTimeScheduler as l}from"./game-time-scheduler.js";let u=class{constructor(e){this.view=e,this.tick=new r,this.lateTick=new r,this.audioListener=new o.AudioListener,this.pausedChanged=new h(!1),this.mutedChanged=new h(!1),this._muted=!1,this._timeScale=1,this._hitStopRemaining=0,this.scheduler=new l,this.outlined=[],e.onLoop(e=>{this.handleFrame(e)}),e.camera.add(this.audioListener),window.hology_view=this}handleFrame(e){let t=this._timeScale,i=0;this._hitStopRemaining>0?(this._hitStopRemaining-=1e3*e,this._hitStopRemaining<=0&&(this._hitStopRemaining=0),t=0):i=e*this._timeScale,this.tick.next(i),this.scheduler.update(1e3*i),this.lateTick.next(i),this.view.simulationTimeScale=t}set timeScale(e){this._timeScale=Math.max(0,e)}get timeScale(){return this._timeScale}applyHitStop(e){this._hitStopRemaining=Math.max(this._hitStopRemaining,e)}set fpsCap(e){this.view.fpsCap=e}get fpsCap(){return this.view.fpsCap}set showStats(e){this.view.showStats=e}get showStats(){return this.view.showStats}setLightVolume(e){this.view.lightVolume=e}getLightVolume(){return this.view.lightVolume}addPostProcessVolume(e){this.view.addPostProcessVolume(e)}removePostProcessVolume(e){this.view.removePostProcessVolume(e)}onUpdate(e){return null!=e&&this.tick.pipe(a(e.disposed)),this.tick}onLateUpdate(e){return null!=e&&this.lateTick.pipe(a(e.disposed)),this.lateTick}setCamera(e){const t=e instanceof s?e:e.camera.instance;this.view.setCamera(t),t.add(this.audioListener)}getCamera(){return this.view.camera}setMuted(e){this._muted=e,this.audioListener.gain.gain.setValueAtTime(e?0:1,this.audioListener.context.currentTime),this.mutedChanged.next(e)}getMuted(){return this._muted}setOutlined(e){this.outlined.length=0;const t=this.outlined;for(let i=0;i<e.length;i++)t[i]=e[i];this.view.setSelectedObjects(t),this.view.setEnableOutlines(e.length>0)}getOutlined(){return this.outlined}addOutlined(e){this.outlined.includes(e)||(this.outlined.push(e),this.view.setSelectedObjects(this.outlined),this.view.setEnableOutlines(!0))}removeOutlined(e){const t=this.outlined.indexOf(e);-1!==t&&(this.outlined.splice(t,1),this.view.setSelectedObjects(this.outlined))}setOutlineColor(e){this.view.outlinePass?.visibleEdgeColor.copy(e)}getOutlineColor(){return this.view.outlinePass?.visibleEdgeColor}setOutlineThickness(e){this.view.outlinePass.edgeThickness=e}getOutlineThickness(){return this.view.outlinePass.edgeThickness}get htmlElement(){return this.view.container}get paused(){return this.view.paused}set paused(e){e!=this.paused&&(e?this.pauseRendering():this.unpauseRendering())}pauseRendering(){this.view.paused=!0,this.pausedChanged.next(this.view.paused),this.scheduler.pause()}unpauseRendering(){this.view.paused=!1,this.pausedChanged.next(this.view.paused),this.scheduler.resume()}setInterval(e,t,i){return this.scheduler.setInterval(e,t,i)}clearInterval(e){this.scheduler.clearInterval(e)}dispose(){this.view.running&&this.view.stop(),this.scheduler.dispose(),this.audioListener.removeFromParent(),this.tick.complete(),this.lateTick.complete(),this.paused=!0}createTimer(e){return this.scheduler.createTimer(e)}getScreenPosition(e,t=m){const i=this.getCamera();return d.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),i instanceof o.PerspectiveCamera&&(c.setFromProjectionMatrix(d),!c.containsPoint(e))?null:(t.copy(e),t.project(i),t.x=(t.x+1)/2*this.htmlElement.clientWidth,t.y=(1-t.y)/2*this.htmlElement.clientHeight,t)}};u=e([i(),t("design:paramtypes",[n])],u);export{u as ViewController};const d=new o.Matrix4,m=new o.Vector3,c=new o.Frustum;/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,19 +1,74 @@
|
|
|
1
|
-
import { Color } from 'three';
|
|
1
|
+
import { Color, Vector3 } from 'three';
|
|
2
2
|
import { ShaderPass } from 'three-stdlib';
|
|
3
3
|
export declare class ColorPass extends ShaderPass {
|
|
4
|
-
|
|
4
|
+
constructor();
|
|
5
5
|
set vignetteEnabled(value: boolean);
|
|
6
6
|
get vignetteEnabled(): boolean;
|
|
7
|
+
set whiteBalanceEnabled(value: boolean);
|
|
8
|
+
get whiteBalanceEnabled(): boolean;
|
|
9
|
+
set whiteBalanceScale(value: Vector3);
|
|
10
|
+
get whiteBalanceScale(): Vector3;
|
|
7
11
|
set vignetteIntensity(value: number);
|
|
8
12
|
get vignetteIntensity(): number;
|
|
13
|
+
set colorTintEnabled(value: boolean);
|
|
14
|
+
get colorTintEnabled(): boolean;
|
|
9
15
|
set colorTint(value: Color);
|
|
10
16
|
get colorTint(): Color;
|
|
11
17
|
set colorTintIntensity(value: number);
|
|
12
18
|
get colorTintIntensity(): number;
|
|
13
|
-
set
|
|
14
|
-
get
|
|
15
|
-
set
|
|
16
|
-
get
|
|
17
|
-
|
|
19
|
+
set colorGradingEnabled(value: boolean);
|
|
20
|
+
get colorGradingEnabled(): boolean;
|
|
21
|
+
set toneMapping(value: number);
|
|
22
|
+
get toneMapping(): number;
|
|
23
|
+
set toneMappingEnabled(value: boolean);
|
|
24
|
+
get toneMappingEnabled(): boolean;
|
|
25
|
+
set toneMappingExposure(value: number);
|
|
26
|
+
get toneMappingExposure(): number;
|
|
27
|
+
set globalSaturation(value: Vector3);
|
|
28
|
+
get globalSaturation(): Vector3;
|
|
29
|
+
set globalContrast(value: Vector3);
|
|
30
|
+
get globalContrast(): Vector3;
|
|
31
|
+
set globalGamma(value: Vector3);
|
|
32
|
+
get globalGamma(): Vector3;
|
|
33
|
+
set globalGain(value: Vector3);
|
|
34
|
+
get globalGain(): Vector3;
|
|
35
|
+
set globalOffset(value: Vector3);
|
|
36
|
+
get globalOffset(): Vector3;
|
|
37
|
+
set shadowsSaturation(value: Vector3);
|
|
38
|
+
get shadowsSaturation(): Vector3;
|
|
39
|
+
set shadowsContrast(value: Vector3);
|
|
40
|
+
get shadowsContrast(): Vector3;
|
|
41
|
+
set shadowsGamma(value: Vector3);
|
|
42
|
+
get shadowsGamma(): Vector3;
|
|
43
|
+
set shadowsGain(value: Vector3);
|
|
44
|
+
get shadowsGain(): Vector3;
|
|
45
|
+
set shadowsOffset(value: Vector3);
|
|
46
|
+
get shadowsOffset(): Vector3;
|
|
47
|
+
set shadowsMax(value: number);
|
|
48
|
+
get shadowsMax(): number;
|
|
49
|
+
set midtonesSaturation(value: Vector3);
|
|
50
|
+
get midtonesSaturation(): Vector3;
|
|
51
|
+
set midtonesContrast(value: Vector3);
|
|
52
|
+
get midtonesContrast(): Vector3;
|
|
53
|
+
set midtonesGamma(value: Vector3);
|
|
54
|
+
get midtonesGamma(): Vector3;
|
|
55
|
+
set midtonesGain(value: Vector3);
|
|
56
|
+
get midtonesGain(): Vector3;
|
|
57
|
+
set midtonesOffset(value: Vector3);
|
|
58
|
+
get midtonesOffset(): Vector3;
|
|
59
|
+
set highlightsSaturation(value: Vector3);
|
|
60
|
+
get highlightsSaturation(): Vector3;
|
|
61
|
+
set highlightsContrast(value: Vector3);
|
|
62
|
+
get highlightsContrast(): Vector3;
|
|
63
|
+
set highlightsGamma(value: Vector3);
|
|
64
|
+
get highlightsGamma(): Vector3;
|
|
65
|
+
set highlightsGain(value: Vector3);
|
|
66
|
+
get highlightsGain(): Vector3;
|
|
67
|
+
set highlightsOffset(value: Vector3);
|
|
68
|
+
get highlightsOffset(): Vector3;
|
|
69
|
+
set highlightsMin(value: number);
|
|
70
|
+
get highlightsMin(): number;
|
|
71
|
+
private setVec3Uniform;
|
|
72
|
+
private getVec3Uniform;
|
|
18
73
|
}
|
|
19
74
|
//# sourceMappingURL=color-pass.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Color as t,Texture as e,Vector3 as i}from"three";import{ShaderPass as n}from"three-stdlib";import{clamp as r,distance as s,float as u,ifDefApply as o,log as l,mix as a,NodeShaderMaterial as m,pow as c,select as p,smoothstep as f,uniformFloat as d,uniformSampler2d as v,uniformVec3 as g,varyingAttributes as T,vec2 as h,vec3 as y}from"../shader-nodes/index.js";export class ColorPass extends n{set vignetteEnabled(t){this.defines.USE_VIGNETTE=!!t}get vignetteEnabled(){return!!this.defines.USE_VIGNETTE}set vignetteIntensity(t){null!=this.material.uniforms.vignetteIntensity?this.material.uniforms.vignetteIntensity={value:t}:this.material.uniforms.vignetteIntensity.value=t}get vignetteIntensity(){return this.material.uniforms.vignetteIntensity?.value}set colorTint(t){this.uniforms.colorTint.value=t}get colorTint(){const e=this.uniforms.colorTint.value;return e instanceof t?e:(new t).setFromVector3(e)}set colorTintIntensity(t){this.uniforms.colorTintIntensity.value=t}get colorTintIntensity(){return this.uniforms.colorTintIntensity?.value}set temperature(t){this.uniforms.temperature&&(this.uniforms.temperature.value=t)}get temperature(){return this.uniforms.temperature?.value}set temperatureTint(t){this.uniforms.temperatureTint&&(this.uniforms.temperatureTint.value=t)}get temperatureTint(){return this.uniforms.temperatureTint?.value}constructor(){let t=v("tDiffuse",new e).sample(T.uv);const n=g("colorTint",new i(1,1,1)),I=d("colorTintIntensity",1);t=a(t.rgb,t.rgb.multiply(n),I).rgba(1);const E=d("temperature",6500),b=d("temperatureTint",0);t=function(t,e,i){function n(t){const e=t.divide(100),i=p(e.lte(66),u(1),r(u(1.292936186062745).multiply(c(e.subtract(60),-.1332047592)),0,1)),n=p(e.lte(66),r(u(.3900815787690196).multiply(l(e)).subtract(.6318414437886275),0,1),r(u(1.1298908608952942).multiply(c(e.subtract(60),-.0755148492)),0,1)),s=p(e.gte(66),u(1),p(e.lte(19),u(0),r(u(.543206789110196).multiply(l(e.subtract(10))).subtract(1.19625408914),0,1)));return y(i,n,s)}const s=n(r(e,1e3,4e4)),o=r(i,-1,1),a=y(1,u(1).add(o.multiply(.2)),1),m=s.multiply(a),f=m.divideScalar(m.y);return r(t.divide(f),y(0,0,0),y(1,1,1))}(t.rgb,E,b).rgba(1);const S=d("vignetteIntensity",.5),U=h(.5),V=s(T.uv,U),w=t.multiplyScalar(f(.8,.2*.799,V.multiply(S.add(.2))));t=o("USE_VIGNETTE",t,()=>w);const G=new m({fog:!1,outputEncoding:!1,color:t});G.lights=!1,super(G),this.defines={USE_VIGNETTE:!1},G.defines=this.defines,G.needsUpdate=!0}}/*
|
|
1
|
+
import{Color as t,NoToneMapping as n,Texture as e,Vector3 as i}from"three";import{ShaderPass as a}from"three-stdlib";export class ColorPass extends a{constructor(){super({uniforms:{tDiffuse:{value:new e},whiteBalanceEnabled:{value:!1},whiteBalanceScale:{value:new i(1,1,1)},vignetteEnabled:{value:!1},vignetteIntensity:{value:.5},colorTintEnabled:{value:!1},colorTint:{value:new i(1,1,1)},colorTintIntensity:{value:0},colorGradingEnabled:{value:!1},toneMappingMode:{value:n},toneMappingEnabled:{value:!1},toneMappingExposure:{value:1},globalSaturation:{value:new i(1,1,1)},globalContrast:{value:new i(1,1,1)},globalGamma:{value:new i(1,1,1)},globalGain:{value:new i(1,1,1)},globalOffset:{value:new i(0,0,0)},shadowsSaturation:{value:new i(1,1,1)},shadowsContrast:{value:new i(1,1,1)},shadowsGamma:{value:new i(1,1,1)},shadowsGain:{value:new i(1,1,1)},shadowsOffset:{value:new i(0,0,0)},shadowsMax:{value:.09},midtonesSaturation:{value:new i(1,1,1)},midtonesContrast:{value:new i(1,1,1)},midtonesGamma:{value:new i(1,1,1)},midtonesGain:{value:new i(1,1,1)},midtonesOffset:{value:new i(0,0,0)},highlightsSaturation:{value:new i(1,1,1)},highlightsContrast:{value:new i(1,1,1)},highlightsGamma:{value:new i(1,1,1)},highlightsGain:{value:new i(1,1,1)},highlightsOffset:{value:new i(0,0,0)},highlightsMin:{value:.5}},vertexShader:"\n varying vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D tDiffuse;\n uniform bool whiteBalanceEnabled;\n uniform vec3 whiteBalanceScale;\n uniform bool vignetteEnabled;\n uniform float vignetteIntensity;\n uniform bool colorTintEnabled;\n uniform vec3 colorTint;\n uniform float colorTintIntensity;\n uniform bool colorGradingEnabled;\n uniform int toneMappingMode;\n uniform bool toneMappingEnabled;\n uniform vec3 globalSaturation;\n uniform vec3 globalContrast;\n uniform vec3 globalGamma;\n uniform vec3 globalGain;\n uniform vec3 globalOffset;\n uniform vec3 shadowsSaturation;\n uniform vec3 shadowsContrast;\n uniform vec3 shadowsGamma;\n uniform vec3 shadowsGain;\n uniform vec3 shadowsOffset;\n uniform float shadowsMax;\n uniform vec3 midtonesSaturation;\n uniform vec3 midtonesContrast;\n uniform vec3 midtonesGamma;\n uniform vec3 midtonesGain;\n uniform vec3 midtonesOffset;\n uniform vec3 highlightsSaturation;\n uniform vec3 highlightsContrast;\n uniform vec3 highlightsGamma;\n uniform vec3 highlightsGain;\n uniform vec3 highlightsOffset;\n uniform float highlightsMin;\n\n varying vec2 vUv;\n\n #include <tonemapping_pars_fragment>\n\n const vec3 LUMA = vec3(0.2126, 0.7152, 0.0722);\n\n vec3 applySaturation(vec3 color, vec3 saturation) {\n vec3 luminanceColor = vec3(dot(color, LUMA));\n return mix(luminanceColor, color, saturation);\n }\n\n vec3 applyContrast(vec3 color, vec3 contrast) {\n return (color - vec3(0.18)) * contrast + vec3(0.18);\n }\n\n vec3 applyGamma(vec3 color, vec3 gammaValue) {\n return pow(max(color, vec3(0.0)), vec3(1.0) / max(gammaValue, vec3(1e-4)));\n }\n\n vec3 applyGain(vec3 color, vec3 gainValue) {\n return color * gainValue;\n }\n\n vec3 applyOffset(vec3 color, vec3 offsetValue) {\n return color + offsetValue;\n }\n\n vec3 applyGrade(vec3 color, vec3 saturation, vec3 contrast, vec3 gammaValue, vec3 gainValue, vec3 offsetValue) {\n color = applySaturation(color, saturation);\n color = applyContrast(color, contrast);\n color = applyGamma(color, gammaValue);\n color = applyGain(color, gainValue);\n color = applyOffset(color, offsetValue);\n return max(color, vec3(0.0));\n }\n\n vec3 applyToneMappingMode(vec3 color) {\n if (toneMappingMode == 1) return LinearToneMapping(color);\n if (toneMappingMode == 2) return ReinhardToneMapping(color);\n if (toneMappingMode == 3) return CineonToneMapping(color);\n if (toneMappingMode == 4) return ACESFilmicToneMapping(color);\n if (toneMappingMode == 6) return AgXToneMapping(color);\n if (toneMappingMode == 7) return NeutralToneMapping(color);\n return color;\n }\n\n void main() {\n vec3 color = texture2D(tDiffuse, vUv).rgb;\n\n if (whiteBalanceEnabled) {\n color *= whiteBalanceScale;\n }\n\n if (colorTintEnabled) {\n color = mix(color, color * colorTint, clamp(colorTintIntensity, 0.0, 1.0));\n }\n\n if (colorGradingEnabled) {\n float shadowLimit = clamp(shadowsMax, 0.0, 0.98);\n float highlightLimit = clamp(max(highlightsMin, shadowLimit + 0.02), 0.02, 1.0);\n float luminance = clamp(dot(color, LUMA), 0.0, 1.0);\n\n float shadowTransition = max(0.02, min(0.25, shadowLimit + 0.05));\n float highlightTransition = max(0.02, min(0.25, (1.0 - highlightLimit) + 0.05));\n\n float shadowWeight = 1.0 - smoothstep(shadowLimit, min(1.0, shadowLimit + shadowTransition), luminance);\n float highlightWeight = smoothstep(max(0.0, highlightLimit - highlightTransition), highlightLimit, luminance);\n float midtoneWeight = clamp(1.0 - shadowWeight - highlightWeight, 0.0, 1.0);\n\n vec3 saturation = globalSaturation;\n vec3 contrast = globalContrast;\n vec3 gammaValue = globalGamma;\n vec3 gainValue = globalGain;\n vec3 offsetValue = globalOffset;\n\n saturation *= mix(vec3(1.0), shadowsSaturation, shadowWeight);\n saturation *= mix(vec3(1.0), midtonesSaturation, midtoneWeight);\n saturation *= mix(vec3(1.0), highlightsSaturation, highlightWeight);\n\n contrast *= mix(vec3(1.0), shadowsContrast, shadowWeight);\n contrast *= mix(vec3(1.0), midtonesContrast, midtoneWeight);\n contrast *= mix(vec3(1.0), highlightsContrast, highlightWeight);\n\n gammaValue *= mix(vec3(1.0), shadowsGamma, shadowWeight);\n gammaValue *= mix(vec3(1.0), midtonesGamma, midtoneWeight);\n gammaValue *= mix(vec3(1.0), highlightsGamma, highlightWeight);\n\n gainValue *= mix(vec3(1.0), shadowsGain, shadowWeight);\n gainValue *= mix(vec3(1.0), midtonesGain, midtoneWeight);\n gainValue *= mix(vec3(1.0), highlightsGain, highlightWeight);\n\n offsetValue += shadowsOffset * shadowWeight;\n offsetValue += midtonesOffset * midtoneWeight;\n offsetValue += highlightsOffset * highlightWeight;\n\n color = applyGrade(color, saturation, contrast, gammaValue, gainValue, offsetValue);\n }\n\n if (toneMappingEnabled) {\n color = applyToneMappingMode(color);\n }\n\n if (vignetteEnabled) {\n float d = distance(vUv, vec2(0.5));\n float offset = 0.2;\n float vignette = smoothstep(0.8, offset * 0.799, d * (vignetteIntensity + offset));\n color *= vignette;\n }\n\n gl_FragColor = vec4(color, 1.0);\n }\n "});const t=this.material;t.toneMapped=!1,t.depthWrite=!1,t.depthTest=!1}set vignetteEnabled(t){this.uniforms.vignetteEnabled.value=t}get vignetteEnabled(){return this.uniforms.vignetteEnabled.value}set whiteBalanceEnabled(t){this.uniforms.whiteBalanceEnabled.value=t}get whiteBalanceEnabled(){return this.uniforms.whiteBalanceEnabled.value}set whiteBalanceScale(t){this.setVec3Uniform("whiteBalanceScale",t)}get whiteBalanceScale(){return this.getVec3Uniform("whiteBalanceScale")}set vignetteIntensity(t){this.uniforms.vignetteIntensity.value=t}get vignetteIntensity(){return this.uniforms.vignetteIntensity.value}set colorTintEnabled(t){this.uniforms.colorTintEnabled.value=t}get colorTintEnabled(){return this.uniforms.colorTintEnabled.value}set colorTint(t){this.setVec3Uniform("colorTint",t)}get colorTint(){return(new t).setFromVector3(this.getVec3Uniform("colorTint"))}set colorTintIntensity(t){this.uniforms.colorTintIntensity.value=t}get colorTintIntensity(){return this.uniforms.colorTintIntensity.value}set colorGradingEnabled(t){this.uniforms.colorGradingEnabled.value=t}get colorGradingEnabled(){return this.uniforms.colorGradingEnabled.value}set toneMapping(t){this.uniforms.toneMappingMode.value=t??n}get toneMapping(){return this.uniforms.toneMappingMode.value}set toneMappingEnabled(t){this.uniforms.toneMappingEnabled.value=t}get toneMappingEnabled(){return this.uniforms.toneMappingEnabled.value}set toneMappingExposure(t){this.uniforms.toneMappingExposure.value=t}get toneMappingExposure(){return this.uniforms.toneMappingExposure.value}set globalSaturation(t){this.setVec3Uniform("globalSaturation",t)}get globalSaturation(){return this.getVec3Uniform("globalSaturation")}set globalContrast(t){this.setVec3Uniform("globalContrast",t)}get globalContrast(){return this.getVec3Uniform("globalContrast")}set globalGamma(t){this.setVec3Uniform("globalGamma",t)}get globalGamma(){return this.getVec3Uniform("globalGamma")}set globalGain(t){this.setVec3Uniform("globalGain",t)}get globalGain(){return this.getVec3Uniform("globalGain")}set globalOffset(t){this.setVec3Uniform("globalOffset",t)}get globalOffset(){return this.getVec3Uniform("globalOffset")}set shadowsSaturation(t){this.setVec3Uniform("shadowsSaturation",t)}get shadowsSaturation(){return this.getVec3Uniform("shadowsSaturation")}set shadowsContrast(t){this.setVec3Uniform("shadowsContrast",t)}get shadowsContrast(){return this.getVec3Uniform("shadowsContrast")}set shadowsGamma(t){this.setVec3Uniform("shadowsGamma",t)}get shadowsGamma(){return this.getVec3Uniform("shadowsGamma")}set shadowsGain(t){this.setVec3Uniform("shadowsGain",t)}get shadowsGain(){return this.getVec3Uniform("shadowsGain")}set shadowsOffset(t){this.setVec3Uniform("shadowsOffset",t)}get shadowsOffset(){return this.getVec3Uniform("shadowsOffset")}set shadowsMax(t){this.uniforms.shadowsMax.value=t}get shadowsMax(){return this.uniforms.shadowsMax.value}set midtonesSaturation(t){this.setVec3Uniform("midtonesSaturation",t)}get midtonesSaturation(){return this.getVec3Uniform("midtonesSaturation")}set midtonesContrast(t){this.setVec3Uniform("midtonesContrast",t)}get midtonesContrast(){return this.getVec3Uniform("midtonesContrast")}set midtonesGamma(t){this.setVec3Uniform("midtonesGamma",t)}get midtonesGamma(){return this.getVec3Uniform("midtonesGamma")}set midtonesGain(t){this.setVec3Uniform("midtonesGain",t)}get midtonesGain(){return this.getVec3Uniform("midtonesGain")}set midtonesOffset(t){this.setVec3Uniform("midtonesOffset",t)}get midtonesOffset(){return this.getVec3Uniform("midtonesOffset")}set highlightsSaturation(t){this.setVec3Uniform("highlightsSaturation",t)}get highlightsSaturation(){return this.getVec3Uniform("highlightsSaturation")}set highlightsContrast(t){this.setVec3Uniform("highlightsContrast",t)}get highlightsContrast(){return this.getVec3Uniform("highlightsContrast")}set highlightsGamma(t){this.setVec3Uniform("highlightsGamma",t)}get highlightsGamma(){return this.getVec3Uniform("highlightsGamma")}set highlightsGain(t){this.setVec3Uniform("highlightsGain",t)}get highlightsGain(){return this.getVec3Uniform("highlightsGain")}set highlightsOffset(t){this.setVec3Uniform("highlightsOffset",t)}get highlightsOffset(){return this.getVec3Uniform("highlightsOffset")}set highlightsMin(t){this.uniforms.highlightsMin.value=t}get highlightsMin(){return this.uniforms.highlightsMin.value}setVec3Uniform(n,e){const i=this.uniforms[n].value;e instanceof t?i.set(e.r,e.g,e.b):i.copy(e)}getVec3Uniform(t){return this.uniforms[t].value}}/*
|
|
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
|
@@ -12,6 +12,10 @@ export type RenderingViewOptions = {
|
|
|
12
12
|
enableXR?: boolean;
|
|
13
13
|
maxPixelRatio?: number;
|
|
14
14
|
resolutionScale?: number;
|
|
15
|
+
msaa?: number;
|
|
16
|
+
depthPrepass?: {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
};
|
|
15
19
|
bloom?: {
|
|
16
20
|
enabled?: boolean;
|
|
17
21
|
};
|
|
@@ -55,6 +59,8 @@ export declare class RenderingView {
|
|
|
55
59
|
fpsCap: number | null;
|
|
56
60
|
postProcessVolumes: PostProcessVolume[];
|
|
57
61
|
postProcessSettings: PostProcessSettings;
|
|
62
|
+
baseToneMapping: THREE.ToneMapping;
|
|
63
|
+
baseToneMappingExposure: number;
|
|
58
64
|
/** Tracks last update time (ms) for each CSM cascade. */
|
|
59
65
|
private csmCascadeLastUpdate?;
|
|
60
66
|
private csmUpdateInvervals;
|
|
@@ -117,7 +123,11 @@ export declare class RenderingView {
|
|
|
117
123
|
private applyEnvMap;
|
|
118
124
|
private setupCsm;
|
|
119
125
|
private gbufferMaterialCache;
|
|
126
|
+
private gbufferDepthPrepassMaterialCache;
|
|
120
127
|
private tbufferMaterialCache;
|
|
128
|
+
private depthPrepassMaterialCache;
|
|
129
|
+
private depthPrepassCachedMaterials;
|
|
130
|
+
private depthPrepassCachedVisibility;
|
|
121
131
|
/**
|
|
122
132
|
* If the material such as a standard material has updated properties, then we need to update
|
|
123
133
|
* the corresponding g buffer material
|
|
@@ -130,6 +140,13 @@ export declare class RenderingView {
|
|
|
130
140
|
* Optimized for hot path execution in rendering loop.
|
|
131
141
|
*/
|
|
132
142
|
private updateUniformValues;
|
|
143
|
+
/**
|
|
144
|
+
* Creates target-local uniform wrapper objects for any source uniforms that the
|
|
145
|
+
* derived material does not already declare. We keep the underlying value
|
|
146
|
+
* references instead of deep-cloning them so render-target textures and other
|
|
147
|
+
* runtime-owned resources are not duplicated or warned about.
|
|
148
|
+
*/
|
|
149
|
+
private inheritCustomUniformBindings;
|
|
133
150
|
private updateMaterialCommonProperties;
|
|
134
151
|
/**
|
|
135
152
|
* After rendering the opaque scene, we will also calculate lights which updates uniforms.
|
|
@@ -137,6 +154,14 @@ export declare class RenderingView {
|
|
|
137
154
|
*/
|
|
138
155
|
private updateLightUniformValues;
|
|
139
156
|
private createGBufferMaterial;
|
|
157
|
+
private isDepthPrepassEnabled;
|
|
158
|
+
private usesSceneFeedbackUniforms;
|
|
159
|
+
private isDepthPrepassEligibleMaterial;
|
|
160
|
+
private isDepthPrepassEligibleMesh;
|
|
161
|
+
private createDepthPrepassMaterial;
|
|
162
|
+
private applyDepthPrepassMaterials;
|
|
163
|
+
private unapplyDepthPrepassMaterials;
|
|
164
|
+
private renderDepthPrepass;
|
|
140
165
|
private updateCsm;
|
|
141
166
|
loop(onFrame: (deltaTime: number) => any, showStats?: boolean): void;
|
|
142
167
|
private gBufferCachedMaterials;
|
package/dist/rendering.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as a,Material as r,Matrix4 as n,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as u,WebGLRenderTarget as d,Texture as c,Euler as p,MeshStandardMaterial as m}from"three";import{CopyShader as f,EffectComposer as g,FXAAShader as M,GammaCorrectionShader as v,LUTPass as y,RenderPass as T,ShaderPass as b,VRButton as P}from"three-stdlib";import{CSMShader as w,CSMUtil as x}from"./csm.js";import{colorToNormal as R,float as S,NodeShaderMaterial as C,standardMaterial as A,uniformFloat as U,uniformVec3 as F,toonMaterial as I,lambertMaterial as B,normalize as O,rgb as E,rgba as D,transformed as L,varying as V,varyingAttributes as _,varyingTransformed as j,vec4 as G,BooleanExpression as W,select as q,ifDefApply as N,uniformSampler2d as k,RgbaNode as H,mix as z,attributes as $,uniformVec2 as X}from"three-shader-graph";import{Reflector as Y}from"three-stdlib";import{BokehPass as Q,OutputPass as K}from"three/examples/jsm/Addons.js";import{CSM as J}from"three/examples/jsm/csm/CSM.js";import{RectAreaLightUniformsLib as Z}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import ee from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as te}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as se}from"typedi";import{depthUniformName as ie,farUniformName as ae,nearUniformName as re,resolutionUniformName as ne,sceneNormalUniformName as oe,screenUV as le,supportsDepthTextureExtension as he}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as ue}from"./shader-nodes/time.js";import{aoMapUniformName as de,sceneMapUniformName as ce}from"./shader-nodes/scene-sample.js";import{DepthPass as pe}from"./utils/three/depth-pass.js";import{GPUStatsPanel as me}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as fe}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as ge,traverseVisibleStop as Me}from"./utils/three/traverse.js";import{clamp as ve}from"./utils/math.js";import{ColorPass as ye}from"./rendering/color-pass.js";import{SSRPass as Te}from"./rendering/ssr/SSRPass.js";import{SSRShader as be}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as Pe}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as we}from"./rendering/outline-effect.js";import{UnrealBloomPass as xe}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Re}from"./shader-nodes/depth.js";import{packDepthToRGBA as Se}from"three-shader-graph";import{FogVolumeObject as Ce}from"./rendering/fog/fog-volume-object";import{ParallaxStandardMaterial as Ae}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as Ue}from"./shader-nodes/pom.js";import{FullScreenQuad as Fe}from"three-stdlib";import{edgeDepthEffect as Ie}from"./shader-nodes/effects";import{decalDiscard as Be}from"./shader-nodes/decal.js";import{Pass as Oe}from"three/examples/jsm/Addons.js";x.patchSetupMaterial();const Ee=document.createElement("div");Ee.style.position="absolute",Ee.style.left="50%",Ee.style.top="50%",Ee.style.color="black",Ee.style.zIndex="999";(new i.Layers).set(9);const De=new i.MeshBasicMaterial({color:"black"}),Le=new i.MeshDepthMaterial;var Ve;Le.depthPacking=i.RGBADepthPacking,Le.blending=i.NoBlending,Le.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(Ve||(Ve={}));const _e=(()=>{const e=new Uint8Array([255,255,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),je=(()=>{const e=new Uint8Array([0,0,0,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ge=(()=>{const e=new Uint8Array([128,128,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),We=new C({color:S(0),position:G(S(0))});We.visible=!1;const qe=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let Ne=0,ke=null;const He=new Map;function ze(){return null==ke&&(ke=new IntersectionObserver(e=>{for(const t of e){const e=He.get(t.target);e&&e(t.isIntersecting)}},{threshold:0})),ke}let $e=e=class{setPaused(e){this.paused=e}resizeRender(){if(!this.running)return;const e=this.container.clientWidth,t=this.container.clientHeight;this.previousClientWith===e&&this.previousClientHeight===t||0!==e&&0!==t&&(this.previousClientWith=e,this.previousClientHeight=t,this.camera instanceof l&&(this.camera.aspect=e/t,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(e,t),this.composer.setSize(e,t),this.dofPass.setSize(e*this.renderer.getPixelRatio(),t*this.renderer.getPixelRatio()),this.fxaaPass.setSize(e*this.renderer.getPixelRatio(),t*this.renderer.getPixelRatio()),this.fxaaPass.uniforms.resolution.value.set(1/(e*this.renderer.getPixelRatio()),1/(t*this.renderer.getPixelRatio())),this.createGRenderTarget(),this.phasedRenderPass.gRenderTarget=this.gRenderTarget,this.bloomPass.emissiveTexture=this.gRenderTarget.textures[1],this.ssrPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.ssrPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.aoPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0)}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)}constructor(t,s={}){this.container=t,this.options=s,this.isIntersecting=!1,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.csmUpdateInvervals=this.options.shadows?.cascadeUpdateIntervals,this._id=Ne++,this.fquadCopy=new Fe(new u(f)),this.fquadCopyOpaque=new Fe(new C({outputs:[k("tSceneColor",new c).sample(_.uv),G(k("tDepthTexture",new i.DepthTexture(1,1)).sample(_.uv).r)]})),this.simulationTime=0,this.simulationTimeScale=1,this.lightProbeIntensity=2,this.fquadBlendAO=(()=>{const e=G(1),t=new C({outputs:[k("tAO",new c).sample(le),e,e],transparent:!0});t.depthWrite=!1,t.depthTest=!1,t.blending=i.MultiplyBlending;return new Fe(t)})(),this.resolutionScale=1,this.maxPixelRatio=qe?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.onLoopCallbacks=[],this.stats=new ee,this._showStats=!0,this.gbufferMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.gBufferCachedMaterials=new Map,this.gBufferCachedVisibility=[],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,e.activeView=this,Z.init(),window.renderer=this.renderer=window.renderer??new i.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});new i.MeshStandardMaterial({color:"#ccc"});this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,this.scene.updateMatrixWorld=function(e){const t=this.children;for(let s=0,i=t.length;s<i;s++){t[s].updateMatrixWorld(e)}}.bind(this.scene),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(P.createButton(this.renderer));const r=new we(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=r,this.createGRenderTarget(),this.composer=new g(this.renderer),this.composer.setSize(t.clientWidth,t.clientHeight);var n=(t.clientWidth||1)/(t.clientHeight||1);const o=new i.PerspectiveCamera(45,n,.5,800);o.layers.enable(19),this.setCamera(o),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.renderer.gammaFactor=1.4,x.renderingView=this,this.isDepthTextureExtensionSupported=he(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container);const l=new i.Vector2(t.clientWidth,t.clientHeight),h=(new T(this.scene,this.camera),new b(f,"prevtexture"));h.enabled=!0,h.needsSwap=!0,h.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=h;const d=new xe(l,1.5,.4,.85);d.threshold=1,d.strength=.9,d.radius=.5,this.bloomPass=d;const p=new te(this.scene,this.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});p.normalRenderTarget?.dispose(),p.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),p.output=te.OUTPUT.Off,p.enabled=!1,this.aoPass=p,this.fquadBlendAO.material.uniforms.tAO.value=p.pdRenderTarget.texture,be.fragmentShader=be.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const m=new Te({renderer:this.renderer,scene:this.scene,camera:this.camera,width:this.gRenderTarget.width,height:this.gRenderTarget.height,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[2],depthTexture:this.gRenderTarget.depthTexture});m.output=Te.OUTPUT.Default,m.blur=!0,m.fresnel=!1,m.distanceAttenuation=!0,m.maxDistance=50,m.selective=!0,m.bouncing=!1,m.opacity=.4,m.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=m,!1!==this.options.ao?.enabled&&this.composer.addPass(p);const w=new lt((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(w);const R=new lt((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(Ve.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(R),this.composer.addPass(h),this.composer.addPass(m),this.phasedRenderPass=new ot(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 Pe(l),this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new Q(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const S=new ye;this.composer.addPass(S),this.colorPass=S,S.vignetteEnabled=!1,this.outlinePass=new fe(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const 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 y({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const U=new b(f,"prevtexture");U.enabled=!0,U.needsSwap=!1,U.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],U.renderToScreen=!0;const F=new K;this.composer.addPass(F)}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.composer.passes.forEach(t=>{t instanceof T?t.camera=e:t instanceof fe?t.renderCamera=e:(t instanceof pe||t instanceof te)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),this.phasedRenderPass&&(this.phasedRenderPass.camera=e),null==this.csm){if(this.csm=new J({maxFar:80,lightFar:250,lightMargin:20,cascades:qe?2:4,shadowMapSize:2048*(qe?.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=w.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){const s=Math.max(1,t.clientWidth*e.getPixelRatio()),a=Math.max(1,t.clientHeight*e.getPixelRatio()),r=new i.DepthTexture(s,a);r.type=i.UnsignedInt248Type,r.minFilter=i.NearestFilter,r.magFilter=i.NearestFilter;const n=new i.WebGLRenderTarget(s,a,{type:i.HalfFloatType,depthTexture:r});return n.texture.minFilter=i.NearestFilter,n.texture.magFilter=i.NearestFilter,n.texture.generateMipmaps=!1,n.stencilBuffer=!1,n}createSceneColorRenderTarget(e,t){const s=this.gRenderTarget.width,a=this.gRenderTarget.height,r=new i.WebGLRenderTarget(s,a,{count:2,type:i.FloatType,format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return r.texture.minFilter=i.LinearFilter,r.texture.magFilter=i.LinearFilter,r.texture.generateMipmaps=!1,r.textures[1].minFilter=i.NearestFilter,r.textures[1].magFilter=i.NearestFilter,r}createGRenderTarget(){const e=this.container;null!=this.gRenderTarget&&this.gRenderTarget.dispose();const t=Math.max(1,e.clientWidth*this.renderer.getPixelRatio()),s=Math.max(1,e.clientHeight*this.renderer.getPixelRatio()),a=new i.DepthTexture(t,s);a.type=i.UnsignedIntType,a.minFilter=i.NearestFilter,a.magFilter=i.NearestFilter,this.gRenderTarget=new d(t,s,{count:3,samples:2,minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat,depthTexture:a}),this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(e=!0){this.running=!1,this.lightVolume?.shTexture.dispose(),window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],e&&this.renderer.dispose(),this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren();ze().unobserve(this.container),He.delete(this.container),this.volumetricFogPass.dispose(),x.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}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:st(this.scene.environmentRotation,this.scene.environment,new i.Matrix3)}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1},e.uniformsNeedUpdate=!0),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment),e instanceof C||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}setupCsm(e){if(e instanceof i.Mesh||e instanceof i.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)this.csm.setupMaterial(t);else this.csm.setupMaterial(e.material)}updateMaterialProperties(e,t){(e instanceof i.MeshBasicMaterial||e instanceof m||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)&&(t.uniforms.color.value.setFromColor(e.color),t.uniforms.opacity.value=e.opacity,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&&(t.uniforms.roughnessMap.value=e.roughnessMap,t.uniforms.metalnessMap.value=e.metalnessMap,t.uniforms.roughness.value=e.roughness,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 Ae&&(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===ht.includes(e)&&(t.value=a)}this.updateMaterialCommonProperties(e,t)}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}updateLightUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e of ht){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(e,t){const s=t===Ve.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let a=s.get(e);if(!0===e.userData.isGBufferMaterial)return e;if(null==a){let n=_.uv;if(e instanceof Ae&&null!=e.heightMap){const t=U("heightScale",e.heightScale??1);n=Ue(n,k("heightMap",e.heightMap),t)}let o=j.normal;if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=e.normalMap??Ge,s=U("useNormalMap",null!=e.normalMap?1:0),i=U("normalScale",e.normalScale?.x??1),a=R(k("normalMap",t).sample(n),i);o=z(j.normal,a,s)}else e instanceof C&&null!=e.outputNormal&&(o=e.outputNormal);!0!==e.userData.disableAO&&(o=N("DOUBLE_SIDED",o,e=>q(new W("gl_FrontFacing"),e,e.multiplyScalar(-1))));let l=e.userData?.reflective?S(0):S(1);if(e instanceof i.MeshStandardMaterial){const t=U("roughness",e.roughness??1),s=e.roughnessMap??_e,i=U("useRoughnessMap",null!=e.roughnessMap?1:0),a=k("roughnessMap",s).sample(n).g.multiply(t);l=z(t,a,i)}else e instanceof C&&null!=e.outputRoughness&&(l=e.outputRoughness);let h=null;if((e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial)&&null!=e.lightMap){const t=e.lightMap,s=U("useLightMap",null!=e.lightMap?1:0),i=U("lightMapIntensity",e.lightMapIntensity??1),a=k("lightMap",t).sample(n).rgb.multiplyScalar(i);h=z(E(0),a,s)}let d=S(0);if(e instanceof i.MeshStandardMaterial){const t=U("metalness",e.metalness??0),s=e.metalnessMap??je,i=U("useMetalnessMap",null!=e.metalnessMap?1:0),a=k("metalnessMap",s).sample(n).b.multiply(t);d=z(t,a,i)}else e instanceof C&&e.outputRoughness;let c=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??_e,s=U("useAoMap",null!=e.aoMap?1:0);p=U("aoMapIntensity",e.aoMapIntensity??1);const i=k("aoMap",t).sample(n).r;c=z(S(1),i,s)}else e instanceof C&&e.outputRoughness;const f=U("opacity",e.opacity??1);let g=S(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){if(null!=e.alphaMap){const t=e.alphaMap;g=k("alphaMap",t).sample(n).r}g=g.multiply(f)}else e instanceof C&&null!=e.outputOpacity&&(g=e.outputOpacity);let M=D(0,1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){let t=F("color",(new i.Vector3).setFromColor(e.color));const s=e.map??_e,a=U("useAlbedoMap",null!=e.map?1:0),r=k("map",s).sample(n),o=r.multiply(D(t,1)),l=D(t,1);M=z(l,o,a),e.vertexColors&&(M=M.multiply(G(V($.color.rgb),1)));const h=z(S(1),r.w,a);g=g.multiply(h)}const v=!0===e.userData.hasBloom;let y=E(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=F("emissive",(new i.Vector3).setFromColor(e.emissive)),s=U("emissiveIntensity",e.emissiveIntensity),a=e.emissiveMap??je,r=U("useEmissiveMap",null!=e.emissiveMap?1:0),o=k("emissiveMap",a).sample(n).rgb.multiply(t);y=z(t,o,r),y=y.multiplyScalar(s)}else e instanceof C&&null!=e.outputEmissive&&(y=e.outputEmissive);let T=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(T=F("sheenColor",(new i.Vector3).setFromColor(e.sheenColor).multiplyScalar(e.sheen)),e.sheen>0&&null!=e.sheenColorMap)){const t=k("sheenColorMap",e.sheenColorMap).sample(n).rgb;T=T.multiply(t)}let b=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(b=U("sheenRoughness",e.sheenRoughness),e.sheen>0&&null!=e.sheenRoughnessMap)){const t=k("sheenRoughnessMap",e.sheenRoughnessMap).sample(n).r;b=b.multiply(t)}let P=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0&&(P=U("anisotropy",e.anisotropy),e.anisotropy>0&&null!=e.anisotropyMap)){const t=k("anisotropyMap",e.anisotropyMap).sample(n).r;P=P.multiply(t)}let w=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0){const t=e.anisotropyRotation??0;w=X("anisotropyDirection",new i.Vector2(Math.cos(t),Math.sin(t)))}const x=e instanceof u&&null!=e.uniforms[ie],L=e instanceof u&&null!=e.uniforms[ce],H=e instanceof u&&null!=e.uniforms[de],Y=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,Q=U("alphaTest",e.alphaTest);let K,J=e.alphaTest>0?g.lt(Q):Y&&t===Ve.opaque?g.lt(.8):null;!0===e.userData.isDecal&&(J=J?J.or(Be):Be),K=Y?G(0,0,0,0):(r=o,O(r).multiplyScalar(.5).addScalar(.5)).rgba(e.userData?.reflective?l:1);const Z=e instanceof C?e.outputPosition:void 0,ee=e instanceof C?e.outputTransform:void 0;let te,se=D("black",1);if(e instanceof C&&null!=e.outputColor)se=e.outputColor;else if(e instanceof i.MeshStandardMaterial)se=A({color:M,metalness:d,roughness:l,emissive:y.rgb,normal:o,ambientOcclusion:c,ambientOcclusionIntensity:p,bakedLight:h,sheenColor:T,sheenRoughness:b,anisotropy:P,anisotropyDirection:w});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)se=B({color:M.rgb,ambientOcclusion:c,ambientOcclusionIntensity:p});else if(e instanceof i.MeshBasicMaterial){let e=M.rgb,t=h??E("black");null!=c&&(t=t.multiplyScalar(c.subtract(1).multiply(p).add(1))),e=e.add(t),se=e.rgba(g)}else e instanceof i.MeshToonMaterial&&(se=I({color:M,emissive:y.rgb,normal:o,ambientOcclusion:c,ambientOcclusionIntensity:p,bakedLight:h}));(e instanceof C||e instanceof i.MeshStandardMaterial)&&(te=e.envMap);let ae=!0;(e instanceof m||e instanceof i.MeshBasicMaterial||e instanceof i.ShaderMaterial)&&(ae=e.fog);let re=D(se.rgb,g);ae&&(re=new FogNode(re));let ne=!0;if(t===Ve.opaque?(ne&&(ne=!x&&!L&&!H),ne&&(ne=!Y)):t===Ve.transparent&&ne&&(ne=Y||x||L||H),!ne)return a=We,s.set(e,a),a;a=new C({transform:ee,position:null==ee?Z:void 0,outputs:[re,y.rgba(t===Ve.opaque?Q:v?1:0),K],opacity:g,outputEncoding:!1,fog:ae,transparent:e.transparent,lights:!0,envMap:te,discard:J}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=a.uniforms.envMapIntensity&&(a.uniforms.envMapIntensity.value=e.envMapIntensity),"alphaMap"in e&&null!=e.alphaMap&&(a.alphaMap=e.alphaMap),(e instanceof C||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(a),e instanceof C&&(Object.assign(a.defines,e.defines),null!=a.uniforms[de]&&(a.uniforms[de].value=this.aoPass.pdRenderTarget.texture,a.defines.USE_SSAO_MAP="")),a.userData.mrtOutputs=3,a.forceSinglePass=e.forceSinglePass,a.side=e.side,a.blending=e.blending,Y?(a.depthWrite=!e.transparent,a.depthTest=e.depthTest,a.colorWrite=t===Ve.transparent):(a.depthWrite=e.depthWrite,a.depthTest=e.depthTest),a.visible=e.visible,a.alphaTest=e.alphaTest,a.alphaHash=e.alphaHash,a.vertexColors=e.vertexColors,a.premultipliedAlpha=e.premultipliedAlpha,a.toneMapped=e.toneMapped,a.blendAlpha=e.blendAlpha,a.blendColor=e.blendColor,a.polygonOffset=e.polygonOffset,a.polygonOffsetFactor=e.polygonOffsetFactor,a.polygonOffsetUnits=e.polygonOffsetUnits,a.blending=e.blending,a.wireframe=e.wireframe??!1,a.userData.isGBufferMaterial=!0,a.visible=ne,Object.assign(a.userData,e.userData),a.visible&&(this.csm.setupMaterial(a),e instanceof u&&Object.assign(a.uniforms,e.uniforms)),s.set(e,a)}var r;return a.visible&&(e instanceof u?this.updateUniformValues(e,a):this.updateMaterialProperties(e,a)),this.initLightVolumeUniform(a),a}updateCsm(){const e=this.csmUpdateInvervals;if(this.renderer.shadowMap.autoUpdate&&null!=this.csmCascadeLastUpdate&&Array.isArray(e)){const t=performance.now();for(let s=0;s<this.csm.lights.length;++s){const i=e[s]??e[e.length-1]??16;(t-this.csmCascadeLastUpdate[s]>=i||0===s)&&this.csm.lights[s].shadow&&(this.csm.lights[s].shadow.needsUpdate=!0,this.csmCascadeLastUpdate[s]=t)}}this.csm.update()}loop(t,s=!1){const a=this.stats,r=a.addPanel(new ee.Panel("Calls","#83f","#002")),l=a.addPanel(new ee.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new me(this.renderer.getContext()),a.addPanel(h)),this.showStats=s;let u=10,d=1e3;const c=()=>{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>d&&(d=t,setTimeout(()=>d=1e3,5e3)),l.update(t,d)};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const p=[],m=[],f=[];let g=0;const M=new n,v=new n;let y=0;let T=this.paused,b=!1,P=0;const w=()=>{e.activeView=this,b&&(b=!1,requestAnimationFrame(()=>R(P)))},x=ze();He.set(this.container,e=>{this.isIntersecting=e,e&&w()}),x.observe(this.container),this.container.addEventListener("pointerdown",()=>{w()},{capture:!0});const R=s=>{b=!1;const r=this.renderer.getContext();if(!this.running||null===this.container.offsetParent||this.paused&&r.drawingBufferHeight>1)return b=!0,P=s,setTimeout(()=>{b&&R(s)},500),void(this.paused&&(T=!0));if(this.renderer.domElement.parentElement!==this.container){if(e.activeView!==this&&null!==e.activeView)return b=!0,void(P=s);this.container.replaceChildren(this.renderer.domElement),this.resizeRender()}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;let n=(s*=.001)-g;if(g=s,T&&(n=.016,T=!1),M.copy(this.camera.matrixWorld),n>1){let e=n;for(;e>.05;)t(Xe),e-=Xe;t(e)}else t(n);this.onLoopCallbacks.forEach(e=>e(n)),this.paused||(this.simulationTime+=n*this.simulationTimeScale);const l=this.simulationTime;this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),s-y>.08&&!v.equals(M)&&(this.renderer.shadowMap.needsUpdate=!0,y=s),this.updateCsm();let u=!1;p.length=0,m.length=0,f.length=0;const d=Qe;Je.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),d.setFromProjectionMatrix(Je);let w=!1,x=!1,S=!1;this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Ce&&(w=!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&&function(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(u=!0)),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ie])&&isObjectInFrustum(e,d)?(this.initDepthUniform(e.material),x=!0):e instanceof Y&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[de]&&isObjectInFrustum(e,d)&&e.material instanceof C&&this.initAoUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[ce]&&isObjectInFrustum(e,d)&&(f.push(e),e.material.uniforms[ce].value=this.sceneColorRenderTarget.texture,S=!0),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[ue])e.material.uniforms[ue].value=l;else if(e instanceof o&&Array.isArray(e.material))for(const t of e.material)t.uniforms&&null!=t.uniforms[ue]&&(t.uniforms[ue].value=l)}),this.bloomPass.enabled=u,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderScene(Ve.opaque),this.aoPass.output=te.OUTPUT.Off,(x||S)&&(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,p.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&&w?(this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1);try{!this.paused&&this.running&&(this.render(n),this.showStats&&h?.endQuery(),this.showStats&&c(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}a.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout(()=>{requestAnimationFrame(R)},1e3/this.fpsCap):requestAnimationFrame(R))};!0===this.options.enableXR?this.renderer.setAnimationLoop(R):requestAnimationFrame(R)}applyGBufferMaterials(e){const t=this.gBufferCachedMaterials,s=this.gBufferCachedVisibility;t.clear(),s.length=0;Me(this.scene,i=>{if(rt(i))return s.push(i),i.visible=!1,!1;if(i instanceof o){t.set(i,i.material);let a=!1;if(Array.isArray(i.material)){i.material=i.material.slice();for(let t=0;t<i.material.length;t++)i.material[t]=this.createGBufferMaterial(i.material[t],e),a||(a=i.material[t].visible),this.initShadowUniform(i,i.material[t])}else i.material=this.createGBufferMaterial(i.material,e),a||(a=i.material.visible),this.initShadowUniform(i,i.material);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.gBufferCachedVisibility.forEach((e,t)=>{e.visible=!0,e.updateMatrixWorld(!0)})}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 c){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 c){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(Ve.opaque),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(Ve.transparent),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),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=dt:t.material=null)})}unapplyDepthMaterial(){this.gBufferCachedMaterials.forEach((e,t)=>{t.material=e})}renderScene(e){if(!this.running||this.paused)return;if(this.compileInProgress)return void console.error("Compile in progress, skipping render");this.applyGBufferMaterials(e);const t=this.scene.matrixWorldAutoUpdate,s=this.scene.matrixAutoUpdate,i=this.renderer.shadowMap.autoUpdate;e!==Ve.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===Ve.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,void(this.colorPass.enabled=!1);var e;(e=this.postProcessSettings).tonemapMapping=void 0,e.tonemapExposure=1,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=new i.Color("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.lut=void 0,e.lutIntensity=0;const t=this.postProcessSettings;let s,a=!1,r=!1,n=!1,o=!1;if(null==this.camera)return;const h=this.camera.getWorldPosition(Ze);let u=[];for(const e of this.postProcessVolumes){if(!Ye(e.object))continue;let l=e.blendWeight??1;const d=e.distanceToPoint(h);d>e.blendRadius||(e.blendRadius>0&&(l*=ve(1-d/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(u.push(e),void 0!==e.settings.tonemapMapping&&(t.tonemapMapping=e.settings.tonemapMapping),void 0!==e.settings.tonemapExposure&&(t.tonemapExposure=i.MathUtils.lerp(t.tonemapExposure,e.settings.tonemapExposure,l)),void 0!==e.settings.envTexture&&(t.envTexture=e.settings.envTexture),void 0!==e.settings.envIntensity&&(t.envIntensity=i.MathUtils.lerp(t.envIntensity,e.settings.envIntensity,l)),void 0!==e.settings.vignetteIntensity&&(t.vignetteIntensity=i.MathUtils.lerp(t.vignetteIntensity,e.settings.vignetteIntensity,l),r=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l),o=!0),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(a=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(a=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(a=!0,t.depthMaxBlur=void 0!==t.depthMaxBlur?i.MathUtils.lerp(t.depthMaxBlur,e.settings.depthMaxBlur,l):e.settings.depthMaxBlur),void 0!==e.settings.temperature&&(t.temperature=i.MathUtils.lerp(t.temperature,e.settings.temperature,l)),void 0!==e.settings.temperatureTint&&(t.temperatureTint=i.MathUtils.lerp(t.temperatureTint,e.settings.temperatureTint,l)),void 0!==e.settings.lut&&(s=e.settings.lut,n=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),n=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,null!=t.envTexture&&(this.scene.environment=this.getEnvTexture(t.envTexture)),this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=r,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,this.colorPass.enabled=r||o,a&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==t.depthFocus&&(this.dofPass.uniforms.focus.value=t.depthFocus),void 0!==t.depthAperture&&(this.dofPass.uniforms.aperture.value=t.depthAperture),void 0!==t.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=t.depthMaxBlur)):this.dofPass.enabled=!1,this.colorPass.temperature=t.temperature,this.colorPass.temperatureTint=t.temperatureTint,this.lutPass.enabled=n,n&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}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,Qe)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.options.bloom,this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=ge(this.scene,e=>e instanceof o&&!0===e.material?.userData?.hasBloom)}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===De.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=De:(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)}initDepthUniform(e){e instanceof u&&(e.uniforms[ie].value=this.sceneColorRenderTarget.textures[1],this.camera instanceof l&&(null!=e.uniforms[re]&&(e.uniforms[re].value=this.camera.near),null!=e.uniforms[ae]&&(e.uniforms[ae].value=this.camera.far)))}initNormalUniform(e){e instanceof u&&null!=e.uniforms[oe]&&(e.uniforms[oe].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof C&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof C&&(null!=this.lightVolume?null==e.uniforms.uSH?(e.defines.USE_LIGHT_PROBE_VOLUME="",e.uniforms.gridOrigin={value:this.lightVolume.gridOrigin},e.uniforms.gridSize={value:this.lightVolume.gridSize},e.uniforms.gridRes={value:this.lightVolume.gridResolution},e.uniforms.giIntensity={value:this.lightProbeIntensity},e.uniforms.uSH={value:this.lightVolume.shTexture},e.uniformsNeedUpdate=!0,e.needsUpdate=!0):e.uniforms.giIntensity.value=this.lightProbeIntensity:null!=e.uniforms.uSH&&(delete e.defines.USE_LIGHT_PROBE_VOLUME,delete e.uniforms.gridOrigin,delete e.uniforms.gridSize,delete e.uniforms.gridRes,delete e.uniforms.giIntensity,delete e.uniforms.uSH,e.uniformsNeedUpdate=!0,e.needsUpdate=!0))}initResolutionUniform(e){e instanceof u&&null!=e.uniforms[ne]&&e.uniforms[ne].value.set(this.gRenderTarget.width,this.gRenderTarget.height)}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[de].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.transparent&&t.depthWrite){let s=this._customDepthMaterialCache.get(t);if(null==s){const e=Se(Re);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}}};$e.activeView=null,$e=e=t([se(),s("design:paramtypes",[HTMLElement,Object])],$e);export{$e as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const Xe=.05;function Ye(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}te.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};const Qe=new i.Frustum,Ke=new i.Box3,Je=new i.Matrix4;export function isObjectInFrustum(e,t){const s=Ke.setFromObject(e);return t.intersectsBox(s)}const Ze=new i.Vector3;const et=new n,tt=new p;function st(e,t,s=new i.Matrix3){return tt.copy(e),tt.x*=-1,tt.y*=-1,tt.z*=-1,t.isCubeTexture&&!1===t.isRenderTargetTexture&&(tt.y*=-1,tt.z*=-1),s.setFromMatrix4(et.makeRotationFromEuler(tt))}const it=new C({outputs:[G(0,0,0,0),G(0,0,0,0),D(E("white"),Ie(4))],transparent:!0}),at=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});it.depthWrite=!1;new o(new i.BoxGeometry(4,4,4),at);function rt(e){return e instanceof i.Sprite||e.isPoints||e.isLine||e.isLineSegments2||e.isTransformControls||e.isTransformControlsGizmo||e instanceof o&&nt(e,e.material)}function nt(e,t){return null==t||(Array.isArray(t)?t.some(t=>nt(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof C))}class ot extends Oe{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 d=0,c=this.toRender;if(c.length=0,this.scene.traverseVisible(e=>{const t=rt(e);e instanceof o&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(d++,c.push(e))}),d>0)for(const t of c)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 lt extends Oe{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const ht=["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"],ut=F("fogColor");export class FogNode extends H{constructor(e,t=ut){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(U("fogFar")),n=e.get(U("fogNear")),o=e.get(U("fogDensity")),l=e.get(V(L.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 dt=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 n,Matrix4 as r,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as p,WebGLRenderTarget as d,Texture as u,Euler as c,MeshStandardMaterial as m}from"three";import{CopyShader as f,EffectComposer as g,FXAAShader as M,GammaCorrectionShader as v,LUTPass as b,RenderPass as y,ShaderPass as w,VRButton as P}from"three-stdlib";import{CSMShader as T,CSMUtil as x}from"./csm.js";import{colorToNormal as S,float as C,NodeShaderMaterial as R,standardMaterial as O,uniformFloat as U,uniformVec3 as A,toonMaterial as G,lambertMaterial as E,normalize as F,rgb as B,rgba as D,transformed as I,varying as L,varyingAttributes as V,varyingTransformed as W,vec4 as _,BooleanExpression as j,select as N,ifDefApply as q,uniformSampler2d as k,RgbaNode as z,mix as H,attributes as $,uniformVec2 as X,autoVarying as Y}from"three-shader-graph";import{Reflector as K}from"three-stdlib";import{BokehPass as Q,OutputPass as J}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 pe}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as de}from"./shader-nodes/time.js";import{aoMapUniformName as ue,sceneMapUniformName as ce}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 be}from"./utils/math.js";import{ColorPass as ye}from"./rendering/color-pass.js";import{SSRPass as we}from"./rendering/ssr/SSRPass.js";import{SSRShader as Pe}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as Te}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as xe}from"./rendering/outline-effect.js";import{UnrealBloomPass as Se}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Ce}from"./shader-nodes/depth.js";import{packDepthToRGBA as Re}from"three-shader-graph";import{FogVolumeObject as Oe}from"./rendering/fog/fog-volume-object";import{ParallaxStandardMaterial as Ue}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as Ae}from"./shader-nodes/pom.js";import{FullScreenQuad as Ge}from"three-stdlib";import{edgeDepthEffect as Ee}from"./shader-nodes/effects";import{decalDiscard as Fe}from"./shader-nodes/decal.js";import{Pass as Be}from"three/examples/jsm/Addons.js";import{BatchedMesh2 as De}from"./scene/batched-mesh-2.js";x.patchSetupMaterial();const Ie=document.createElement("div");Ie.style.position="absolute",Ie.style.left="50%",Ie.style.top="50%",Ie.style.color="black",Ie.style.zIndex="999";(new i.Layers).set(9);const Le=new i.MeshBasicMaterial({color:"black"}),Ve=new i.MeshDepthMaterial;var We;Ve.depthPacking=i.RGBADepthPacking,Ve.blending=i.NoBlending,Ve.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(We||(We={}));const _e=(()=>{const e=new Uint8Array([255,255,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),je=(()=>{const e=new Uint8Array([0,0,0,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),Ne=(()=>{const e=new Uint8Array([128,128,255,255]),t=new i.DataTexture(e,1,1,i.RGBAFormat);return t.needsUpdate=!0,t})(),qe=new R({color:C(0),position:_(C(0))});qe.visible=!1;const ke=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let ze=0,He=null;const $e=new Map;function Xe(){return null==He&&(He=new IntersectionObserver(e=>{for(const t of e){const e=$e.get(t.target);e&&e(t.isIntersecting)}},{threshold:0})),He}let Ye=e=class{setPaused(e){this.paused=e}resizeRender(){if(!this.running)return;const e=this.container.clientWidth,t=this.container.clientHeight;this.previousClientWith===e&&this.previousClientHeight===t||0!==e&&0!==t&&(this.previousClientWith=e,this.previousClientHeight=t,this.camera instanceof l&&(this.camera.aspect=e/t,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(e,t),this.composer.setSize(e,t),this.dofPass.setSize(e*this.renderer.getPixelRatio(),t*this.renderer.getPixelRatio()),this.fxaaPass.setSize(e*this.renderer.getPixelRatio(),t*this.renderer.getPixelRatio()),this.fxaaPass.uniforms.resolution.value.set(1/(e*this.renderer.getPixelRatio()),1/(t*this.renderer.getPixelRatio())),this.createGRenderTarget(),this.phasedRenderPass.gRenderTarget=this.gRenderTarget,this.bloomPass.emissiveTexture=this.gRenderTarget.textures[1],this.ssrPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.ssrPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.aoPass.setSize(this.gRenderTarget.width,this.gRenderTarget.height),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0)}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)}constructor(t,s={}){this.container=t,this.options=s,this.isIntersecting=!1,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.baseToneMapping=i.NoToneMapping,this.baseToneMappingExposure=1,this.csmUpdateInvervals=this.options.shadows?.cascadeUpdateIntervals,this._id=ze++,this.fquadCopy=new Ge(new p(f)),this.fquadCopyOpaque=new Ge(new R({outputs:[k("tSceneColor",new u).sample(V.uv),_(k("tDepthTexture",new i.DepthTexture(1,1)).sample(V.uv).r)]})),this.simulationTime=0,this.simulationTimeScale=1,this.lightProbeIntensity=2,this.fquadBlendAO=(()=>{const e=_(1),t=new R({outputs:[k("tAO",new u).sample(he),e,e],transparent:!0});t.depthWrite=!1,t.depthTest=!1,t.blending=i.MultiplyBlending;return new Ge(t)})(),this.resolutionScale=1,this.maxPixelRatio=ke?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.onLoopCallbacks=[],this.stats=new te,this._showStats=!0,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._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,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(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(P.createButton(this.renderer));const n=new xe(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=n,this.createGRenderTarget(),this.composer=new g(this.renderer),this.composer.setSize(t.clientWidth,t.clientHeight);var r=(t.clientWidth||1)/(t.clientHeight||1);const o=new i.PerspectiveCamera(45,r,.5,800);o.layers.enable(19),this.setCamera(o),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.baseToneMapping=this.renderer.toneMapping,this.baseToneMappingExposure=this.renderer.toneMappingExposure,this.renderer.gammaFactor=1.4,x.renderingView=this,this.isDepthTextureExtensionSupported=pe(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container);const l=new i.Vector2(t.clientWidth,t.clientHeight),h=(new y(this.scene,this.camera),new w(f,"prevtexture"));h.enabled=!0,h.needsSwap=!0,h.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=h;const d=new Se(l,1.5,.4,.85);d.threshold=1,d.strength=.9,d.radius=.5,this.bloomPass=d;const c=new se(this.scene,this.camera,this.gRenderTarget.width,this.gRenderTarget.height,{});c.normalRenderTarget?.dispose(),c.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),c.output=se.OUTPUT.Off,c.enabled=!1,this.aoPass=c,this.fquadBlendAO.material.uniforms.tAO.value=c.pdRenderTarget.texture,Pe.fragmentShader=Pe.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const m=new we({renderer:this.renderer,scene:this.scene,camera:this.camera,width:this.gRenderTarget.width,height:this.gRenderTarget.height,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[2],depthTexture:this.gRenderTarget.depthTexture});m.output=we.OUTPUT.Default,m.blur=!0,m.fresnel=!1,m.distanceAttenuation=!0,m.maxDistance=50,m.selective=!0,m.bouncing=!1,m.opacity=.4,m.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=m,!1!==this.options.ao?.enabled&&this.composer.addPass(c);const T=new gt((e,t,s,i,a)=>{this.aoPass.enabled&&(this.initResolutionUniform(this.fquadBlendAO.material),this.renderer.setRenderTarget(this.gRenderTarget),this.fquadBlendAO.render(this.renderer),this.renderer.setRenderTarget(null))});this.composer.addPass(T);const S=new gt((e,t,s,i,a)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(We.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(S),this.composer.addPass(h),this.composer.addPass(m),this.phasedRenderPass=new ft(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 Te(l),this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new Q(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const C=new ye;this.composer.addPass(C),this.colorPass=C,C.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 O=new w(M);O.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(O),this.fxaaPass=O,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new w(v).clear=!1,this.fixStatsStyle(),this.lutPass=new b({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const U=new w(f,"prevtexture");U.enabled=!0,U.needsSwap=!1,U.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],U.renderToScreen=!0;const A=new J;this.composer.addPass(A)}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.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:ke?2:4,shadowMapSize:2048*(ke?.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){const s=Math.max(1,t.clientWidth*e.getPixelRatio()),a=Math.max(1,t.clientHeight*e.getPixelRatio()),n=new i.DepthTexture(s,a);n.type=i.UnsignedInt248Type,n.minFilter=i.NearestFilter,n.magFilter=i.NearestFilter;const r=new i.WebGLRenderTarget(s,a,{type:i.HalfFloatType,depthTexture:n});return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,r}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=Math.max(1,e.clientWidth*this.renderer.getPixelRatio()),s=Math.max(1,e.clientHeight*this.renderer.getPixelRatio()),a=new i.DepthTexture(t,s);a.type=i.UnsignedIntType,a.minFilter=i.NearestFilter,a.magFilter=i.NearestFilter,this.gRenderTarget=new d(t,s,{count:3,samples:this.options?.msaa??(ke?void 0:2),minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat,depthTexture:a}),this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(e=!0){this.running=!1,this.lightVolume?.shTexture.dispose(),window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],e&&this.renderer.dispose(),this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren();Xe().unobserve(this.container),$e.delete(this.container),this.volumetricFogPass.dispose(),x.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof R&&(null==e.envMap||e.userData.useSceneEnv)&&(e.userData.useSceneEnv=!0,null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment},e.uniformsNeedUpdate=!0,e.uniforms.envMapRotation={value:pt(this.scene.environmentRotation,this.scene.environment,new i.Matrix3)}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1},e.uniformsNeedUpdate=!0),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment),e instanceof R||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}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 Ue&&(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===Mt.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||Mt.includes(e)||vt.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 Mt){const t=i[e],a=s[e];null!=a&&null!=t&&(t.value=a.value)}}createGBufferMaterial(e,t,s=!1){const a=t===We.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let n=a.get(e);if(!0===e.userData.isGBufferMaterial)return e;if(null==n){let s=V.uv;if(e instanceof Ue&&null!=e.heightMap){const t=U("heightScale",e.heightScale??1);s=Ae(s,k("heightMap",e.heightMap),t)}let o=W.normal;if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=e.normalMap??Ne,i=U("useNormalMap",null!=e.normalMap?1:0),a=U("normalScale",e.normalScale?.x??1),n=S(k("normalMap",t).sample(s),a);o=H(W.normal,n,i)}else e instanceof R&&null!=e.outputNormal&&(o=!0===e.outputNormal.isVarying?e.outputNormal:Y(e.outputNormal));!0!==e.userData.disableAO&&(o=q("DOUBLE_SIDED",o,e=>N(new j("gl_FrontFacing"),e,e.multiplyScalar(-1))));let l=e.userData?.reflective?C(0):C(1);if(e instanceof i.MeshStandardMaterial){const t=U("roughness",e.roughness??1),i=e.roughnessMap??_e,a=U("useRoughnessMap",null!=e.roughnessMap?1:0),n=k("roughnessMap",i).sample(s).g.multiply(t);l=H(t,n,a)}else e instanceof R&&null!=e.outputRoughness&&(l=e.outputRoughness);let h=null;if((e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial)&&null!=e.lightMap){const t=e.lightMap,i=U("useLightMap",null!=e.lightMap?1:0),a=U("lightMapIntensity",e.lightMapIntensity??1),n=k("lightMap",t).sample(s).rgb.multiplyScalar(a);h=H(B(0),n,i)}let d=C(0);if(e instanceof i.MeshStandardMaterial){const t=U("metalness",e.metalness??0),i=e.metalnessMap??je,a=U("useMetalnessMap",null!=e.metalnessMap?1:0),n=k("metalnessMap",i).sample(s).b.multiply(t);d=H(t,n,a)}else e instanceof R&&e.outputRoughness;let u=null,c=C(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??_e,i=U("useAoMap",null!=e.aoMap?1:0);c=U("aoMapIntensity",e.aoMapIntensity??1);const a=k("aoMap",t).sample(s).r;u=H(C(1),a,i)}else e instanceof R&&e.outputRoughness;const f=U("opacity",e.opacity??1);let g=C(1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){if(null!=e.alphaMap){const t=e.alphaMap;g=k("alphaMap",t).sample(s).r}g=g.multiply(f)}else e instanceof R&&null!=e.outputOpacity&&(g=e.outputOpacity);let M=D(0,1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){let t=A("color",(new i.Vector3).setFromColor(e.color));const a=e.map??_e,n=U("useAlbedoMap",null!=e.map?1:0),r=k("map",a).sample(s),o=r.multiply(D(t,1)),l=D(t,1);M=H(l,o,n),e.vertexColors&&(M=M.multiply(_(L($.color.rgb),1)));const h=H(C(1),r.w,n);g=g.multiply(h)}const v=!0===e.userData.hasBloom;let b=B(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=A("emissive",(new i.Vector3).setFromColor(e.emissive)),a=U("emissiveIntensity",e.emissiveIntensity),n=e.emissiveMap??je,r=U("useEmissiveMap",null!=e.emissiveMap?1:0),o=k("emissiveMap",n).sample(s).rgb.multiply(t);b=H(t,o,r),b=b.multiplyScalar(a)}else e instanceof R&&null!=e.outputEmissive&&(b=e.outputEmissive);let y=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(y=A("sheenColor",(new i.Vector3).setFromColor(e.sheenColor).multiplyScalar(e.sheen)),e.sheen>0&&null!=e.sheenColorMap)){const t=k("sheenColorMap",e.sheenColorMap).sample(s).rgb;y=y.multiply(t)}let w=null;if(e instanceof i.MeshPhysicalMaterial&&e.sheen>0&&(w=U("sheenRoughness",e.sheenRoughness),e.sheen>0&&null!=e.sheenRoughnessMap)){const t=k("sheenRoughnessMap",e.sheenRoughnessMap).sample(s).r;w=w.multiply(t)}let P=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0&&(P=U("anisotropy",e.anisotropy),e.anisotropy>0&&null!=e.anisotropyMap)){const t=k("anisotropyMap",e.anisotropyMap).sample(s).r;P=P.multiply(t)}let T=null;if(e instanceof i.MeshPhysicalMaterial&&e.anisotropy>0){const t=e.anisotropyRotation??0;T=X("anisotropyDirection",new i.Vector2(Math.cos(t),Math.sin(t)))}const x=e instanceof p&&null!=e.uniforms[ae],I=e instanceof p&&null!=e.uniforms[ce],z=e instanceof p&&null!=e.uniforms[ue],K=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,Q=U("alphaTest",e.alphaTest);let J,Z=e.alphaTest>0?g.lt(Q):K&&t===We.opaque?g.lt(.8):null;!0===e.userData.isDecal&&(Z=Z?Z.or(Fe):Fe),J=K?_(0,0,0,0):(r=o,F(r).multiplyScalar(.5).addScalar(.5)).rgba(e.userData?.reflective?l:1);const ee=e instanceof R?e.outputPosition:void 0,te=e instanceof R?e.outputTransform:void 0;let se,ie=D("black",1);if(e instanceof R&&null!=e.outputColor)ie=e.outputColor;else if(e instanceof i.MeshStandardMaterial)ie=O({color:M,metalness:d,roughness:l,emissive:b.rgb,normal:o,ambientOcclusion:u,ambientOcclusionIntensity:c,bakedLight:h,sheenColor:y,sheenRoughness:w,anisotropy:P,anisotropyDirection:T});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)ie=E({color:M.rgb,ambientOcclusion:u,ambientOcclusionIntensity:c});else if(e instanceof i.MeshBasicMaterial){let e=M.rgb,t=h??B("black");null!=u&&(t=t.multiplyScalar(u.subtract(1).multiply(c).add(1))),e=e.add(t),ie=e.rgba(g)}else e instanceof i.MeshToonMaterial&&(ie=G({color:M,emissive:b.rgb,normal:o,ambientOcclusion:u,ambientOcclusionIntensity:c,bakedLight:h}));(e instanceof R||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,g);ne&&(re=new FogNode(re));let oe=!0;if(t===We.opaque?(oe&&(oe=!x&&!I&&!z),oe&&(oe=!K)):t===We.transparent&&oe&&(oe=K||x||I||z),!oe)return n=qe,a.set(e,n),n;n=new R({transform:te,position:null==te?ee:void 0,outputs:[re,b.rgba(t===We.opaque?Q:v?1:0),J],opacity:g,outputEncoding:!1,fog:ne,transparent:e.transparent,lights:!0,envMap:se,alphaTest:e.alphaTest,discard:Z}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=n.uniforms.envMapIntensity&&(n.uniforms.envMapIntensity.value=e.envMapIntensity),"alphaMap"in e&&null!=e.alphaMap&&(n.alphaMap=e.alphaMap),(e instanceof R||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(n),e instanceof R&&(Object.assign(n.defines,e.defines),null!=n.uniforms[ue]&&(n.uniforms[ue].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,K?(n.depthWrite=!e.transparent,n.depthTest=e.depthTest,n.colorWrite=t===We.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=oe,Object.assign(n.userData,e.userData),n.visible&&(this.csm.setupMaterial(n),e instanceof p&&this.inheritCustomUniformBindings(e,n)),a.set(e,n)}var r;return n.visible&&(e instanceof p?this.updateUniformValues(e,n):this.updateMaterialProperties(e,n)),this.initLightVolumeUniform(n),n}isDepthPrepassEnabled(){return!0===this.options.depthPrepass?.enabled}usesSceneFeedbackUniforms(e){return e instanceof p&&(null!=e.uniforms[ae]||null!=e.uniforms[ce]||null!=e.uniforms[ue])}isDepthPrepassEligibleMaterial(e){return null!=e&&(!1!==e.visible&&!1!==e.depthTest&&!1!==e.depthWrite&&(!e.transparent&&e.blending!==i.AdditiveBlending&&(!this.usesSceneFeedbackUniforms(e)&&(e instanceof R||e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshBasicMaterial))))}isDepthPrepassEligibleMesh(e){return!!this.isDepthPrepassEnabled()&&((e instanceof i.InstancedMesh||e instanceof De)&&(!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=C(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(a=U("opacity",e.opacity??1),null!=e.map&&(a=a.multiply(k("map",e.map).sample(V.uv).a)),null!=e.alphaMap&&(a=a.multiply(k("alphaMap",e.alphaMap).sample(V.uv).r))):e instanceof R&&(a=e.outputOpacity??C(1)),null!=e.alphaTest&&e.alphaTest>0&&(s=a.lt(e.alphaTest));const n=e instanceof R?e.outputPosition:void 0,r=e instanceof R?e.outputTransform:void 0;t=new R({outputs:[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 Mt)delete t.uniforms[e];for(const e of vt)delete t.uniforms[e];delete t.uniforms.receiveShadow,this.depthPrepassMaterialCache.set(e,t)}return e instanceof R?this.updateUniformValues(e,t):this.updateMaterialProperties(e,t),t.depthWrite=!0,t.depthTest=e.depthTest,t.colorWrite=!1,t.transparent=!1,t.blending=i.NoBlending,t.visible=e.visible,t.alphaTest=e.alphaTest,t.side=e.side,t.polygonOffset=e.polygonOffset,t.polygonOffsetFactor=e.polygonOffsetFactor,t.polygonOffsetUnits=e.polygonOffsetUnits,t}applyDepthPrepassMaterials(){const e=this.depthPrepassCachedMaterials,t=this.depthPrepassCachedVisibility;e.clear(),t.length=0,ve(this.scene,s=>{if(ct(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 p=10,d=1e3;const u=()=>{const e=this.renderer.info.render.calls;e>p&&(p=e,setTimeout(()=>p=10,5e3)),n.update(e,p);const t=this.renderer.info.render.triangles;t>d&&(d=t,setTimeout(()=>d=1e3,5e3)),l.update(t,d)};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const c=[],m=[],f=[];let g=0;const M=new r,v=new r;let b=0;let y=this.paused,w=!1,P=0;const T=()=>{e.activeView=this,w&&(w=!1,requestAnimationFrame(()=>S(P)))},x=Xe();$e.set(this.container,e=>{this.isIntersecting=e,e&&T()}),x.observe(this.container),this.container.addEventListener("pointerdown",()=>{T()},{capture:!0});const S=s=>{w=!1;const n=this.renderer.getContext();if(!this.running||null===this.container.offsetParent||this.paused&&n.drawingBufferHeight>1)return w=!0,P=s,setTimeout(()=>{w&&S(s)},500),void(this.paused&&(y=!0));if(this.renderer.domElement.parentElement!==this.container){if(e.activeView!==this&&null!==e.activeView)return w=!0,void(P=s);this.container.replaceChildren(this.renderer.domElement),this.resizeRender()}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;let r=(s*=.001)-g;if(g=s,y&&(r=.016,y=!1),M.copy(this.camera.matrixWorld),r>1){let e=r;for(;e>.05;)t(Ke),e-=Ke;t(e)}else t(r);this.onLoopCallbacks.forEach(e=>e(r)),this.paused||(this.simulationTime+=r*this.simulationTimeScale);const l=this.simulationTime;this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),s-b>.08&&!v.equals(M)&&(this.renderer.shadowMap.needsUpdate=!0,b=s),this.updateCsm();let p=!1;c.length=0,m.length=0,f.length=0;const d=Je;et.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),d.setFromProjectionMatrix(et);let T=!1,x=!1,C=!1;this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Oe&&(T=!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&&function(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(p=!0)),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ae])&&isObjectInFrustum(e,d)?(this.initDepthUniform(e.material),x=!0):e instanceof K&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[ue]&&isObjectInFrustum(e,d)&&e.material instanceof R&&this.initAoUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[ce]&&isObjectInFrustum(e,d)&&(f.push(e),e.material.uniforms[ce].value=this.sceneColorRenderTarget.texture,C=!0),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[de])e.material.uniforms[de].value=l;else if(e instanceof o&&Array.isArray(e.material))for(const t of e.material)t.uniforms&&null!=t.uniforms[de]&&(t.uniforms[de].value=l)}),this.bloomPass.enabled=p,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderDepthPrepass(),this.renderScene(We.opaque),this.aoPass.output=se.OUTPUT.Off,(x||C)&&(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,c.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&&T?(this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene),this.volumetricFogPass.enabled=!0):this.volumetricFogPass&&(this.volumetricFogPass.enabled=!1);try{!this.paused&&this.running&&(this.render(r),this.showStats&&h?.endQuery(),this.showStats&&u(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}a.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout(()=>{requestAnimationFrame(S)},1e3/this.fpsCap):requestAnimationFrame(S))};!0===this.options.enableXR?this.renderer.setAnimationLoop(S):requestAnimationFrame(S)}applyGBufferMaterials(e){const t=this.gBufferCachedMaterials,s=this.gBufferCachedVisibility;t.clear(),s.length=0;ve(this.scene,i=>{if(ct(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===We.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===We.opaque&&this.isDepthPrepassEligibleMesh(i)),a||(a=i.material.visible),this.initShadowUniform(i,i.material);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.gBufferCachedVisibility.forEach((e,t)=>{e.visible=!0,e.updateMatrixWorld(!0)})}initTextures(e=this.scene){e.traverse(e=>{if(e instanceof o)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++)this._initMaterialTextures(e.material[t]);else this._initMaterialTextures(e.material)})}_initMaterialTextures(e){if(!this._initiatedMaterialTextures.has(e))if(this._initiatedMaterialTextures.add(e),e instanceof p){for(const[t,s]of Object.entries(e.uniforms))if(s.value instanceof u){if(this._initiatedTextures.has(s.value))continue;this.renderer.initTexture(s.value),this._initiatedTextures.add(s.value)}}else for(const[t,s]of Object.entries(e))if(s instanceof u){if(this._initiatedTextures.has(s))continue;this.renderer.initTexture(s),this._initiatedTextures.add(s)}}async compileAsync(e=this.scene){if(this.compileInProgress)return;this.renderer.setRenderTarget(this.gRenderTarget),this.compileInProgress=!0,this.applyGBufferMaterials(We.opaque),await this.renderer.compileAsync(e,this.camera),this.unapplyGBufferMaterials(),this.applyGBufferMaterials(We.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=yt:t.material=null)})}unapplyDepthMaterial(){this.gBufferCachedMaterials.forEach((e,t)=>{t.material=e})}renderScene(e){if(!this.running||this.paused)return;if(this.compileInProgress)return void console.error("Compile in progress, skipping render");this.applyGBufferMaterials(e);const t=this.scene.matrixWorldAutoUpdate,s=this.scene.matrixAutoUpdate,i=this.renderer.shadowMap.autoUpdate;e!==We.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===We.opaque&&this.gBufferCachedMaterials.forEach((e,t)=>{!Array.isArray(e)&&!Array.isArray(t.material)&&e instanceof p&&this.updateLightUniformValues(t.material,e)}),this.unapplyGBufferMaterials(),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t.colorSpace=i.SRGBColorSpace,t}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.lutPass.enabled=!1,this.colorPass.enabled=!1,this.dofPass.enabled=!1,this.renderer.toneMapping=this.baseToneMapping,void(this.renderer.toneMappingExposure=this.baseToneMappingExposure);!function(e,t=i.NoToneMapping,s=1){e.tonemapMapping=t,e.tonemapExposure=s,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=e.colorTint??new i.Color("white"),e.colorTint.set("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.globalSaturation=tt(e.globalSaturation,1,1,1),e.globalContrast=tt(e.globalContrast,1,1,1),e.globalGamma=tt(e.globalGamma,1,1,1),e.globalGain=tt(e.globalGain,1,1,1),e.globalOffset=tt(e.globalOffset,0,0,0),e.shadowsSaturation=tt(e.shadowsSaturation,1,1,1),e.shadowsContrast=tt(e.shadowsContrast,1,1,1),e.shadowsGamma=tt(e.shadowsGamma,1,1,1),e.shadowsGain=tt(e.shadowsGain,1,1,1),e.shadowsOffset=tt(e.shadowsOffset,0,0,0),e.shadowsMax=.09,e.midtonesSaturation=tt(e.midtonesSaturation,1,1,1),e.midtonesContrast=tt(e.midtonesContrast,1,1,1),e.midtonesGamma=tt(e.midtonesGamma,1,1,1),e.midtonesGain=tt(e.midtonesGain,1,1,1),e.midtonesOffset=tt(e.midtonesOffset,0,0,0),e.highlightsSaturation=tt(e.highlightsSaturation,1,1,1),e.highlightsContrast=tt(e.highlightsContrast,1,1,1),e.highlightsGamma=tt(e.highlightsGamma,1,1,1),e.highlightsGain=tt(e.highlightsGain,1,1,1),e.highlightsOffset=tt(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(nt);let n=[];for(const r of this.postProcessVolumes){if(!Qe(r.object))continue;let o=r.blendWeight??1;const l=r.distanceToPoint(a);l>r.blendRadius||(r.blendRadius>0&&(o*=be(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>at,o=(h=e.temperature,p=e.temperatureTint,!it(h,6500)||!it(p,0));var h,p;const d=(u=e.colorTint,e.colorTintIntensity>at&&(!it(u.r,1)||!it(u.g,1)||!it(u.b,1)));var u;const c=!(st((m=e).globalSaturation,1,1,1)&&st(m.globalContrast,1,1,1)&&st(m.globalGamma,1,1,1)&&st(m.globalGain,1,1,1)&&st(m.globalOffset,0,0,0)&&st(m.shadowsSaturation,1,1,1)&&st(m.shadowsContrast,1,1,1)&&st(m.shadowsGamma,1,1,1)&&st(m.shadowsGain,1,1,1)&&st(m.shadowsOffset,0,0,0)&&st(m.midtonesSaturation,1,1,1)&&st(m.midtonesContrast,1,1,1)&&st(m.midtonesGamma,1,1,1)&&st(m.midtonesGain,1,1,1)&&st(m.midtonesOffset,0,0,0)&&st(m.highlightsSaturation,1,1,1)&&st(m.highlightsContrast,1,1,1)&&st(m.highlightsGamma,1,1,1)&&st(m.highlightsGain,1,1,1)&&st(m.highlightsOffset,0,0,0));var m;const f=o||d||c||r,g=f&&e.tonemapMapping!==i.NoToneMapping,M=null!=t&&e.lutIntensity>at;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=be(e,1e3,4e4)/100,s=t<=66?1:be(1.292936186062745*Math.pow(t-60,-.1332047592),0,1),i=be(t<=66?.3900815787690196*Math.log(t)-.6318414437886275:1.129890860895294*Math.pow(t-60,-.0755148492),0,1),a=t>=66?1:t<=19?0:be(.5432067891101962*Math.log(t-10)-1.19625408914,0,1);return ot.set(s,i,a)}(t),a=1+.2*be(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}(rt,e.temperature,e.temperatureTint):rt.set(1,1,1),this.colorPass.vignetteIntensity=e.vignetteIntensity,this.colorPass.vignetteEnabled=r,this.colorPass.colorTintEnabled=d,this.colorPass.colorTint=e.colorTint,this.colorPass.colorTintIntensity=e.colorTintIntensity,this.colorPass.colorGradingEnabled=c,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)}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,Je)&&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===Le.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=Le:(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)}initDepthUniform(e){e instanceof p&&(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 p&&null!=e.uniforms[le]&&(e.uniforms[le].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof R&&(t.uniforms.receiveShadow?t.uniforms.receiveShadow.value=e.receiveShadow:t.uniforms.receiveShadow={value:e.receiveShadow})}initLightVolumeUniform(e){e instanceof R&&(null!=this.lightVolume?null==e.uniforms.uSH?(e.defines.USE_LIGHT_PROBE_VOLUME="",e.uniforms.gridOrigin={value:this.lightVolume.gridOrigin},e.uniforms.gridSize={value:this.lightVolume.gridSize},e.uniforms.gridRes={value:this.lightVolume.gridResolution},e.uniforms.giIntensity={value:this.lightProbeIntensity},e.uniforms.uSH={value:this.lightVolume.shTexture},e.uniformsNeedUpdate=!0,e.needsUpdate=!0):e.uniforms.giIntensity.value=this.lightProbeIntensity:null!=e.uniforms.uSH&&(delete e.defines.USE_LIGHT_PROBE_VOLUME,delete e.uniforms.gridOrigin,delete e.uniforms.gridSize,delete e.uniforms.gridRes,delete e.uniforms.giIntensity,delete e.uniforms.uSH,e.uniformsNeedUpdate=!0,e.needsUpdate=!0))}initResolutionUniform(e){e instanceof p&&null!=e.uniforms[oe]&&e.uniforms[oe].value.set(this.gRenderTarget.width,this.gRenderTarget.height)}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[ue].value=this.aoPass.pdRenderTarget.texture,null==e.defines.USE_SSAO_MAP&&(e.defines.USE_SSAO_MAP="",e.needsUpdate=!0),e.defines.USE_SSAO_MAP="";const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}else if(null!=e.defines.USE_SSAO_MAP){delete e.defines.USE_SSAO_MAP,e.needsUpdate=!0;const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}}initCustomDepthMaterial(e){if(null!=e.customDepthMaterial||!e.castShadow)return;const t=e.material;if(t instanceof R&&!t.transparent&&t.depthWrite){let s=this._customDepthMaterialCache.get(t);if(null==s){const e=Re(Ce);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new R({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}}};Ye.activeView=null,Ye=e=t([ie(),s("design:paramtypes",[HTMLElement,Object])],Ye);export{Ye as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const Ke=.05;function Qe(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}se.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};const Je=new i.Frustum,Ze=new i.Box3,et=new i.Matrix4;export function isObjectInFrustum(e,t){const s=Ze.setFromObject(e);return t.intersectsBox(s)}function tt(e,t,s,a){return null==e?new i.Vector3(t,s,a):e.set(t,s,a)}function st(e,t,s,i){return null!=e&&it(e.x,t)&&it(e.y,s)&&it(e.z,i)}function it(e,t,s=at){return Math.abs(e-t)<=s}const at=1e-4,nt=new i.Vector3,rt=new i.Vector3(1,1,1),ot=new i.Vector3(1,1,1);const lt=new r,ht=new c;function pt(e,t,s=new i.Matrix3){return ht.copy(e),ht.x*=-1,ht.y*=-1,ht.z*=-1,t.isCubeTexture&&!1===t.isRenderTargetTexture&&(ht.y*=-1,ht.z*=-1),s.setFromMatrix4(lt.makeRotationFromEuler(ht))}const dt=new R({outputs:[_(0,0,0,0),_(0,0,0,0),D(B("white"),Ee(4))],transparent:!0}),ut=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});dt.depthWrite=!1;new o(new i.BoxGeometry(4,4,4),ut);function ct(e){return e instanceof i.Sprite||e.isPoints||e.isLine||e.isLineSegments2||e.isTransformControls||e.isTransformControlsGizmo||e instanceof o&&mt(e,e.material)}function mt(e,t){return null==t||(Array.isArray(t)?t.some(t=>mt(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof R))}class ft extends Be{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 p=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),this.cachedVisibility.length=0;let d=0,u=this.toRender;if(u.length=0,this.scene.traverseVisible(e=>{const t=ct(e);e instanceof o&&!t?(this.cachedVisibility.push(e),e.visible=!1):t&&(d++,u.push(e))}),d>0)for(const t of u)e.render(t,this.camera);this.cachedVisibility.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=n,s.depthTexture=p,this.scene.matrixWorldAutoUpdate=r,this.scene.matrixAutoUpdate=l,e.shadowMap.autoUpdate=h}}class gt extends Be{constructor(e){super(),this.fn=e}render(e,t,s,i,a){this.fn(e,t,s,i,a)}}const Mt=["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"],vt=["directionalShadowMap","directionalShadowMatrix","pointLightShadows","pointShadowMap","pointShadowMatrix","spotLightShadows","spotShadowMap"],bt=A("fogColor");export class FogNode extends z{constructor(e,t=bt){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(U("fogFar")),r=e.get(U("fogNear")),o=e.get(U("fogDensity")),l=e.get(L(I.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 yt=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
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CustomParamValue } from './model.js';
|
|
2
|
+
export interface CustomParamValueResolvers {
|
|
3
|
+
actor?: (value: unknown) => unknown | null;
|
|
4
|
+
texture?: (value: unknown) => Promise<unknown> | unknown;
|
|
5
|
+
sampler2DNode?: (value: unknown) => Promise<unknown> | unknown;
|
|
6
|
+
object3D?: (value: unknown) => Promise<unknown> | unknown;
|
|
7
|
+
material?: (value: unknown) => Promise<unknown> | unknown;
|
|
8
|
+
audioBuffer?: (value: unknown) => Promise<unknown> | unknown;
|
|
9
|
+
visualEffect?: (value: unknown) => Promise<unknown> | unknown;
|
|
10
|
+
prefab?: (value: unknown) => Promise<unknown> | unknown;
|
|
11
|
+
prefabActor?: (value: unknown) => Promise<unknown> | unknown;
|
|
12
|
+
sequence?: (value: unknown) => Promise<unknown> | unknown;
|
|
13
|
+
animationClip?: (value: unknown) => Promise<unknown> | unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare function customParamValueNeedsAsyncResolution(param: CustomParamValue): boolean;
|
|
16
|
+
export declare function deserializeCustomParamValueSync(param: CustomParamValue, resolvers?: Pick<CustomParamValueResolvers, 'actor'>): unknown;
|
|
17
|
+
export declare function deserializeCustomParamValue(param: CustomParamValue, resolvers?: CustomParamValueResolvers): Promise<unknown>;
|
|
18
|
+
//# sourceMappingURL=custom-param-deserialize.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{Color as e,Euler as a,Vector2 as r,Vector3 as u,Vector4 as l}from"three";import{Curve2 as t}from"../utils/curve.js";import{SerializedParamType as n}from"./model.js";export function customParamValueNeedsAsyncResolution(e){if(null==e||null==e.value||""===e.value)return!1;if(s(e))return e.value.some(a=>customParamValueNeedsAsyncResolution({type:e.element,value:a}));switch(e.type){case n.Texture:case n.Sampler2DNode:case n.Object3D:case n.Material:case n.AudioBuffer:case n.VisualEffect:case n.Prefab:case n.PrefabActor:case n.Sequence:case n.AnimationClip:return!0;default:return!1}}export function deserializeCustomParamValueSync(c,o={}){if(null==c||null==c.value||""===c.value)return c?.value??null;switch(c.type){case n.Array:return s(c)&&Array.isArray(c.value)?c.value.map(e=>deserializeCustomParamValueSync({type:c.element,value:e},o)):[];case n.Number:case n.FloatNode:return"string"==typeof c.value?parseFloat(c.value):c.value;case n.Boolean:case n.BooleanNode:case n.String:return c.value;case n.Vector2:case n.Vec2Node:return"object"==typeof c.value?Array.isArray(c.value)?(new r).fromArray(c.value):new r(c.value.x,c.value.y):null;case n.Vector3:case n.Vec3Node:return"object"==typeof c.value?Array.isArray(c.value)?(new u).fromArray(c.value):new u(c.value.x,c.value.y,c.value.z):null;case n.Vector4:case n.Vec4Node:return"object"==typeof c.value?Array.isArray(c.value)?(new l).fromArray(c.value):new l(c.value.x,c.value.y,c.value.z,c.value.w):null;case n.Color:case n.RgbNode:return new e(c.value);case n.Euler:return Array.isArray(c.value)?(new a).fromArray(c.value):c.value;case n.BaseActor:return o.actor?.(c.value)??c.value;case n.Curve:return t.decode(c.value);default:return c.value}}export async function deserializeCustomParamValue(e,a={}){if(null==e||null==e.value||""===e.value)return e?.value??null;if(!customParamValueNeedsAsyncResolution(e))return deserializeCustomParamValueSync(e,a);switch(e.type){case n.Array:return s(e)&&Array.isArray(e.value)?Promise.all(e.value.map(r=>deserializeCustomParamValue({type:e.element,value:r},a))):[];case n.Texture:return a.texture?.(e.value)??null;case n.Sampler2DNode:return a.sampler2DNode?.(e.value)??null;case n.Object3D:return a.object3D?.(e.value)??null;case n.Material:return a.material?.(e.value)??null;case n.AudioBuffer:return a.audioBuffer?.(e.value)??null;case n.VisualEffect:return a.visualEffect?.(e.value)??null;case n.Prefab:return a.prefab?.(e.value)??null;case n.PrefabActor:return a.prefabActor?.(e.value)??null;case n.Sequence:return a.sequence?.(e.value)??null;case n.AnimationClip:return a.animationClip?.(e.value)??null;default:return deserializeCustomParamValueSync(e,a)}}function s(e){return e.type===n.Array}/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -377,6 +377,7 @@ export declare class SceneMaterializer {
|
|
|
377
377
|
private applyMaterials;
|
|
378
378
|
private _originalMaterials;
|
|
379
379
|
private applyMaterial;
|
|
380
|
+
private resolveMaterialForAssignments;
|
|
380
381
|
private unapplyMaterials;
|
|
381
382
|
updateActors(actors: ActorImpl[]): void;
|
|
382
383
|
updateComponents(components: ClassImpl<ActorComponent>[]): void;
|