@hology/core 0.0.127 → 0.0.128

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.
@@ -22,57 +22,18 @@ export class OutlineEffect {
22
22
  * @param {OutlineEffect~Options} [parameters] - The configuration parameter.
23
23
  */
24
24
  constructor(renderer: WebGLRenderer, parameters?: {});
25
+ applied: WeakSet<object>;
25
26
  enabled: boolean;
26
27
  createMaterial: () => ShaderMaterial;
28
+ getOutlineMaterial: (originalMaterial: any) => any;
29
+ updateUniforms: (material: any, originalMaterial: any) => void;
27
30
  /**
28
- * When using this effect, this method should be called instead of the
29
- * default {@link WebGLRenderer#render}.
30
31
  *
31
- * @param {Object3D} scene - The scene to render.
32
- * @param {Camera} camera - The camera.
32
+ * @param {Object3D} object
33
+ * @returns
33
34
  */
34
- render: (scene: Object3D, camera: Camera) => void;
35
- /**
36
- * This method can be used to render outlines in VR.
37
- *
38
- * ```js
39
- * const effect = new OutlineEffect( renderer );
40
- * let renderingOutline = false;
41
- *
42
- * scene.onAfterRender = function () {
43
- *
44
- * if ( renderingOutline ) return;
45
- *
46
- * renderingOutline = true;
47
- * effect.renderOutline( scene, camera );
48
- * renderingOutline = false;
49
- * };
50
- *
51
- * function render() {
52
- * renderer.render( scene, camera );
53
- * }
54
- * ```
55
- *
56
- * @param {Object3D} scene - The scene to render.
57
- * @param {Camera} camera - The camera.
58
- */
59
- renderOutline: (scene: Object3D, camera: Camera) => void;
60
- /**
61
- * Resizes the effect.
62
- *
63
- * @param {number} width - The width of the effect in logical pixels.
64
- * @param {number} height - The height of the effect in logical pixels.
65
- */
66
- setSize: (width: number, height: number) => void;
67
- }
68
- export class OutlineEffectPass extends Pass {
69
- constructor(outlineEffect: any, scene: any, camera: any, outlineOnly?: boolean);
70
- outlineEffect: any;
71
- scene: any;
72
- camera: any;
73
- outlineOnly: boolean;
74
- render(renderer: any, writeBuffer: any, readBuffer: any): void;
35
+ apply(object: Object3D): void;
75
36
  }
76
37
  import { ShaderMaterial } from 'three';
77
- import { Pass } from 'three/examples/jsm/Addons.js';
38
+ import { Object3D } from 'three';
78
39
  //# sourceMappingURL=outline-effect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"outline-effect.d.ts","sourceRoot":"","sources":["../../src/rendering/outline-effect.js"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;GAeG;AACH;IAEC;;;;;OAKG;IACH,sBAHW,aAAa,mBA0dvB;IArdA,iBAAmB;IAkInB,qCAAoC;IAwPpC;;;;;;OAMG;IACH,gBAHW,QAAQ,UACR,MAAM,UAoBhB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,uBAHW,QAAQ,UACR,MAAM,UA8BhB;IAED;;;;;OAKG;IACH,iBAHW,MAAM,UACN,MAAM,UAIhB;CAGF;AAGD;IACE,gFAOC;IALC,mBAAkC;IAClC,WAAkB;IAClB,YAAoB;IAEtB,qBAA8B;IAG9B,+DAIC;CACF;+BAtgBM,OAAO;qBACmC,8BAA8B"}
1
+ {"version":3,"file":"outline-effect.d.ts","sourceRoot":"","sources":["../../src/rendering/outline-effect.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;GAeG;AACH;IAEC;;;;;OAKG;IACH,sBAHW,aAAa,mBAiTvB;IA5SA,yBAA4B;IAE5B,iBAAmB;IAoInB,qCAAoC;IAqCpC,mDAA4C;IAyB5C,+DAAoC;IA4GrC;;;;OAIG;IACH,cAHW,QAAQ,QA0ClB;CACD;+BAzXM,OAAO;yBAAP,OAAO"}
@@ -1,4 +1,4 @@
1
- import{BackSide as e,Color as t,ShaderMaterial as i,UniformsLib as n,UniformsUtils as a,WebGLRenderTarget as l,RGBAFormat as r,HalfFloatType as o}from"three";import{CopyShader as s,FullScreenQuad as u,Pass as c}from"three/examples/jsm/Addons.js";export class OutlineEffect{constructor(l,r={}){this.enabled=!0;const o=void 0!==r.defaultThickness?r.defaultThickness:.003,s=(new t).fromArray(void 0!==r.defaultColor?r.defaultColor:[0,0,0]),u=void 0!==r.defaultAlpha?r.defaultAlpha:1,c=void 0!==r.defaultKeepAlive&&r.defaultKeepAlive,d={},p={},m={},f={outlineThickness:{value:o},outlineColor:{value:s},outlineAlpha:{value:u}},v=["#include <common>","#include <uv_pars_vertex>","#include <displacementmap_pars_vertex>","#include <fog_pars_vertex>","#include <morphtarget_pars_vertex>","#include <skinning_pars_vertex>","#include <logdepthbuf_pars_vertex>","#include <clipping_planes_pars_vertex>","uniform float outlineThickness;","vec4 calculateOutline( vec4 pos, vec3 normal, vec4 skinned ) {","\tfloat thickness = outlineThickness;","\tconst float ratio = 1.0;","\tvec4 pos2 = projectionMatrix * modelViewMatrix * vec4( skinned.xyz + normal, 1.0 );"," float viewDistance = length((modelViewMatrix * vec4(skinned.xyz, 1.0)).xyz);"," float scale = pow(viewDistance, 0.5); // sqrt, or any exponent","\tvec4 norm = normalize( pos - pos2 );","\treturn pos + norm * thickness * scale * ratio;","}","void main() {","\t#include <uv_vertex>","\t#include <beginnormal_vertex>","\t#include <morphnormal_vertex>","\t#include <skinbase_vertex>","\t#include <skinnormal_vertex>","\t#include <begin_vertex>","\t#include <morphtarget_vertex>","\t#include <skinning_vertex>","\t#include <displacementmap_vertex>","\t#include <project_vertex>","\tvec3 outlineNormal = - objectNormal;","\tgl_Position = calculateOutline( gl_Position, outlineNormal, vec4( transformed, 1.0 ) );","\t#include <logdepthbuf_vertex>","\t#include <clipping_planes_vertex>","\t#include <fog_vertex>","}"].join("\n"),h=["#include <common>","#include <fog_pars_fragment>","#include <logdepthbuf_pars_fragment>","#include <clipping_planes_pars_fragment>","uniform vec3 outlineColor;","uniform float outlineAlpha;","void main() {","\t#include <clipping_planes_fragment>","\t#include <logdepthbuf_fragment>","\tgl_FragColor = vec4( outlineColor, outlineAlpha );","\t#include <tonemapping_fragment>","\t#include <colorspace_fragment>","\t#include <fog_fragment>","\t#include <premultiplied_alpha_fragment>","}"].join("\n");function g(){return new i({type:"OutlineEffect",uniforms:a.merge([n.fog,n.displacementmap,f]),vertexShader:v,fragmentShader:h,side:e,depthTest:!0,depthWrite:!1,transparent:!0})}function _(e){const t=function(e){let t=d[e.uuid];return void 0===t&&(t={material:g(),used:!0,keepAlive:c,count:0},d[e.uuid]=t),t.used=!0,t.material}(e);return p[t.uuid]=e,function(e,t){if("invisible"===e.name)return;const i=t.userData.outlineParameters;e.fog=t.fog,e.toneMapped=t.toneMapped,e.premultipliedAlpha=t.premultipliedAlpha,e.displacementMap=t.displacementMap,void 0!==i?(!1===t.visible?e.visible=!1:e.visible=void 0===i.visible||i.visible,e.transparent=void 0!==i.alpha&&i.alpha<1||t.transparent,void 0!==i.keepAlive&&(d[t.uuid].keepAlive=i.keepAlive)):(e.transparent=t.transparent,e.visible=t.visible);!0!==t.wireframe&&!1!==t.depthTest||(e.visible=!1);t.clippingPlanes&&(e.clipping=!0,e.clippingPlanes=t.clippingPlanes,e.clipIntersection=t.clipIntersection,e.clipShadows=t.clipShadows);e.version=t.version}(t,e),t}this.createMaterial=g;const x=[],b=[];function k(e){if(!1===e.material?.depthTest&&1===e.material?.side)return e.visible=!1,void b.push(e);if(!1!==function(e){const t=e.geometry,i=void 0!==t&&void 0!==t.attributes.normal,n=!0===e.isMesh&&void 0!==e.material;let a=e.material,l=!1;return Array.isArray(a)?l=a.some((e=>e&&e.userData&&e.userData.outlineParameters)):a&&a.userData&&a.userData.outlineParameters&&(l=!0),n&&!0===i&&l}(e)){if(x.push(e),Array.isArray(e.material))for(let t=0,i=e.material.length;t<i;t++)e.material[t]=_(e.material[t]);else e.material=_(e.material);m[e.uuid]=e.onBeforeRender,e.onBeforeRender=A}}function A(e,t,i,n,a){const l=p[a.uuid];void 0!==l&&function(e,t){const i=t.userData.outlineParameters;e.uniforms.outlineAlpha.value=t.opacity,void 0!==i&&(void 0!==i.thickness&&(e.uniforms.outlineThickness.value=i.thickness),void 0!==i.color&&e.uniforms.outlineColor.value.fromArray(i.color),void 0!==i.alpha&&(e.uniforms.outlineAlpha.value=i.alpha));t.displacementMap&&(e.uniforms.displacementMap.value=t.displacementMap,e.uniforms.displacementScale.value=t.displacementScale,e.uniforms.displacementBias.value=t.displacementBias)}(a,l)}this.render=function(e,t){if(!1===this.enabled)return void l.render(e,t);const i=l.autoClear;l.autoClear=this.autoClear,l.autoClear=i,this.renderOutline(e,t)},this.renderOutline=function(e,t){const i=l.autoClear,n=e.matrixWorldAutoUpdate,a=e.background,r=l.shadowMap.enabled;e.matrixWorldAutoUpdate=!1,e.background=null,l.autoClear=!1,l.shadowMap.enabled=!1,e.traverseVisible(k),l.render(e,t),b.forEach((e=>e.visible=!0)),b.length=0,x.forEach((e=>function(e){if(Array.isArray(e.material))for(let t=0,i=e.material.length;t<i;t++)e.material[t]=p[e.material[t].uuid];else e.material=p[e.material.uuid];e.onBeforeRender=m[e.uuid]}(e))),x.length=0,function(){let e;e=Object.keys(p);for(let t=0,i=e.length;t<i;t++)p[e[t]]=void 0;e=Object.keys(m);for(let t=0,i=e.length;t<i;t++)m[e[t]]=void 0;e=Object.keys(d);for(let t=0,i=e.length;t<i;t++){const i=e[t];!1===d[i].used?(d[i].count++,!1===d[i].keepAlive&&d[i].count>60&&delete d[i]):(d[i].used=!1,d[i].count=0)}}(),e.matrixWorldAutoUpdate=n,e.background=a,l.autoClear=i,l.shadowMap.enabled=r},this.setSize=function(e,t){l.setSize(e,t)}}}export class OutlineEffectPass extends c{constructor(e,t,i,n=!1){super(),this.outlineEffect=e,this.scene=t,this.camera=i,this.enabled=!0,this.outlineOnly=n}render(e,t,i){e.setRenderTarget(this.renderToScreen?null:t),this.outlineEffect.renderOutline(this.scene,this.camera)}}/*
1
+ import{BackSide as e,Color as i,ShaderMaterial as t,UniformsLib as n,UniformsUtils as a,Object3D as l,Mesh as r,InstancedMesh as o,BatchedMesh as s}from"three";export class OutlineEffect{constructor(l,r={}){this.applied=new WeakSet,this.enabled=!0;const o=void 0!==r.defaultThickness?r.defaultThickness:.003,s=(new i).fromArray(void 0!==r.defaultColor?r.defaultColor:[0,0,0]),u=void 0!==r.defaultAlpha?r.defaultAlpha:1,p=void 0!==r.defaultKeepAlive&&r.defaultKeepAlive,c={},d={},m={outlineThickness:{value:o},outlineColor:{value:s},outlineAlpha:{value:u}},v=["#include <common>","#include <uv_pars_vertex>","#include <displacementmap_pars_vertex>","#include <fog_pars_vertex>","#include <morphtarget_pars_vertex>","#include <skinning_pars_vertex>","#include <logdepthbuf_pars_vertex>","#include <clipping_planes_pars_vertex>","uniform float outlineThickness;","vec4 calculateOutline( vec4 pos, vec3 normal, vec4 skinned ) {","\tfloat thickness = outlineThickness;","\tconst float ratio = 1.0;","\tvec4 pos2 = projectionMatrix * modelViewMatrix * vec4( skinned.xyz + normal, 1.0 );"," float viewDistance = length((modelViewMatrix * vec4(skinned.xyz, 1.0)).xyz);"," float scale = pow(viewDistance, 0.5); // sqrt, or any exponent","\tvec4 norm = normalize( pos - pos2 );","\treturn pos + norm * thickness * scale * ratio;","}","void main() {","\t#include <uv_vertex>","\t#include <beginnormal_vertex>","\t#include <morphnormal_vertex>","\t#include <skinbase_vertex>","\t#include <skinnormal_vertex>","\t#include <begin_vertex>","\t#include <morphtarget_vertex>","\t#include <skinning_vertex>","\t#include <displacementmap_vertex>","\t#include <project_vertex>","\tvec3 outlineNormal = - objectNormal;","\tgl_Position = calculateOutline( gl_Position, outlineNormal, vec4( transformed, 1.0 ) );","\t#include <logdepthbuf_vertex>","\t#include <clipping_planes_vertex>","\t#include <fog_vertex>","}"].join("\n"),f=["#include <common>","#include <fog_pars_fragment>","#include <logdepthbuf_pars_fragment>","#include <clipping_planes_pars_fragment>","uniform vec3 outlineColor;","uniform float outlineAlpha;","void main() {","\t#include <clipping_planes_fragment>","\t#include <logdepthbuf_fragment>","\tgl_FragColor = vec4( outlineColor, outlineAlpha );","\t#include <tonemapping_fragment>","\t#include <colorspace_fragment>","\t#include <fog_fragment>","\t#include <premultiplied_alpha_fragment>","}"].join("\n");function h(){return new t({type:"OutlineEffect",uniforms:a.merge([n.fog,n.displacementmap,m]),vertexShader:v,fragmentShader:f,side:e,depthTest:!0,depthWrite:!1,transparent:!0})}this.createMaterial=h,this.getOutlineMaterial=function(e){const i=function(e){let i=c[e.uuid];return void 0===i&&(i={material:h(),used:!0,keepAlive:p,count:0},c[e.uuid]=i),i.used=!0,i.material}(e);return d[i.uuid]=e,function(e,i){if("invisible"===e.name)return;const t=i.userData.outlineParameters;e.fog=i.fog,e.toneMapped=i.toneMapped,e.premultipliedAlpha=i.premultipliedAlpha,e.displacementMap=i.displacementMap,void 0!==t?(!1===i.visible?e.visible=!1:e.visible=void 0===t.visible||t.visible,e.transparent=void 0!==t.alpha&&t.alpha<1||i.transparent,void 0!==t.keepAlive&&(c[i.uuid].keepAlive=t.keepAlive)):(e.transparent=i.transparent,e.visible=i.visible);!0!==i.wireframe&&!1!==i.depthTest||(e.visible=!1);i.clippingPlanes&&(e.clipping=!0,e.clippingPlanes=i.clippingPlanes,e.clipIntersection=i.clipIntersection,e.clipShadows=i.clipShadows);e.version=i.version}(i,e),i},this.updateUniforms=function(e,i){const t=i.userData.outlineParameters;e.uniforms.outlineAlpha.value=i.opacity,void 0!==t&&(void 0!==t.thickness&&(e.uniforms.outlineThickness.value=t.thickness),void 0!==t.color&&e.uniforms.outlineColor.value.fromArray(t.color),void 0!==t.alpha&&(e.uniforms.outlineAlpha.value=t.alpha)),i.displacementMap&&(e.uniforms.displacementMap.value=i.displacementMap,e.uniforms.displacementScale.value=i.displacementScale,e.uniforms.displacementBias.value=i.displacementBias)}}apply(e){if(!(e instanceof r)||e instanceof s||e instanceof o)return;if(this.applied.has(e))return;this.applied.add(e);const i=e.onAfterRender;e.onAfterRender=(t,n,a,l,r,o)=>{i(t,n,a,l,r);let s=!1;if(Array.isArray(r)?s=r.some((e=>e&&e.userData&&e.userData.outlineParameters)):r&&r.userData&&r.userData.outlineParameters&&(s=!0),!s)return;const u=e.material,p=this.getOutlineMaterial(u);e.material=p,this.updateUniforms(p,r),t.renderBufferDirect(a,n,l,p,e,o),e.material=u}}}/*
2
2
  * Copyright (©) 2025 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -5,7 +5,6 @@ import { CSM } from "three/examples/jsm/csm/CSM.js";
5
5
  import { GTAOPass } from "three/examples/jsm/postprocessing/GTAOPass.js";
6
6
  import { OutlinePass } from './utils/three/outline-pass.js';
7
7
  import { type PostProcessSettings, type PostProcessVolume } from "./gameplay/actors/builtin/post-process-volume-actor.js";
8
- import { OutlineEffectPass } from "./rendering/outline-effect.js";
9
8
  export type RenderingViewOptions = {
10
9
  enableOutlines?: boolean;
11
10
  enableXR?: boolean;
@@ -63,7 +62,6 @@ export declare class RenderingView {
63
62
  private onVisiblityChane;
64
63
  private isDepthTextureExtensionSupported;
65
64
  private outlineEffect;
66
- toonOutlinePass: OutlineEffectPass;
67
65
  constructor(container: HTMLElement, options?: RenderingViewOptions);
68
66
  private fixStatsStyle;
69
67
  setEnableOutlines(enabled: boolean): void;
@@ -1 +1 @@
1
- {"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../src/rendering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,MAAM,EAKN,QAAQ,EAIR,aAAa,EACb,iBAAiB,EAClB,MAAM,OAAO,CAAC;AACf,OAAO,EAA0E,UAAU,EAA6B,MAAM,cAAc,CAAC;AAM7I,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAazE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAM1H,OAAO,EAAiB,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAsCjF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,CAAC,EAAE,OAAO,CAA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,OAAO,CAU3B;IAED,OAAO,CAAC,WAAW;IAsBZ,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG,EAAE,SAAS,UAAQ;IAsTlE,OAAO,CAAC,wBAAwB;IAkMhC,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,UAAU,CAA8B;IAChD,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,eAAe,CAAI;IAE3B,OAAO,CAAC,cAAc,CAAyB;IAE/C,OAAO,CAAC,aAAa;IAyBd,gBAAgB,CAAC,MAAM,EAAE,MAAM;IAI/B,mBAAmB;IAInB,mBAAmB,CAAC,MAAM,EAAE,MAAM;IAIzC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAQ;IAEjB,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM;IAiFhC,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,WAAW,CAAiB;IAEpC,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,qBAAqB;CAe9B;AAgBD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,QAIhD;AAiHD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,OAAO,CAIzF"}
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 r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as u,GammaCorrectionShader as p,LUTPass as m,RenderPass as g,ShaderPass as f,UnrealBloomPass as v,VRButton as x}from"three-stdlib";import{CSMShader as b,CSMUtil as P}from"./csm.js";import{NodeShaderMaterial as T}from"three-shader-graph";import{Reflector as y}from"three-stdlib";import{BokehPass as w,OutputPass as M}from"three/examples/jsm/Addons.js";import{CSM as S}from"three/examples/jsm/csm/CSM.js";import R from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as C}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as F}from"typedi";import{depthUniformName as D,farUniformName as I,nearUniformName as A,resolutionUniformName as E,supportsDepthTextureExtension as O}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as U}from"./shader-nodes/time.js";import{sceneMapUniformName as W}from"./shader-nodes/scene-sample.js";import{DepthPass as B}from"./utils/three/depth-pass.js";import{GPUStatsPanel as j}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as H}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as V}from"./utils/three/traverse.js";import{clamp as L}from"./utils/math.js";import{ColorPass as k}from"./rendering/color-pass.js";import{SSRPass as z}from"./rendering/ssr/SSRPass.js";import{SSRShader as _}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as N}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as G,OutlineEffectPass as q}from"./rendering/outline-effect.js";const X=document.createElement("div");X.style.position="absolute",X.style.left="50%",X.style.top="50%",X.style.color="black",X.style.zIndex="999";(new i.Layers).set(9);const Y=new i.MeshBasicMaterial({color:"black"}),Q=new i.MeshDepthMaterial;Q.depthPacking=i.RGBADepthPacking,Q.blending=i.NoBlending,Q.side=i.DoubleSide;const K=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let J=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||0!==this.container.clientWidth&&0!==this.container.clientHeight&&(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof l&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.bloomComposer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.dofPass.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture,this.depthRenderTarget.dispose(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container))}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.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.resolutionScale=K?.5:1,this.maxPixelRatio=K?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new R,this._showStats=!0,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 r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,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(x.createButton(this.renderer));const n=new G(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=n,this.composer=new c(this.renderer);var a=(t.clientWidth||1)/(t.clientHeight||1);const o=new i.PerspectiveCamera(45,a,.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,P.renderingView=this,P.patchThreeAdd(),this.isDepthTextureExtensionSupported=O(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container);const l=new g(this.scene,this.camera);this.composer.addPass(l);const h=new v(new i.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=1,h.strength=.9,h.radius=.5,this.bloomPass=h;const d=new C(this.scene,this.camera,t.clientWidth,t.clientWidth);d.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},d.blendMaterial.uniforms.tAODepth={value:d.depthTexture},d.blendMaterial.fragmentShader="\n uniform float intensity;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D tAODepth;\n varying vec2 vUv;\n\n void main() {\n vec4 texel = texture2D( tDiffuse, vUv );\n float d = textureLod(tDepth, vUv.xy, 0.0).x;\n float d2 = textureLod(tAODepth, vUv.xy, 0.0).x;\n\n float depth = 2.0 * 1.0 * 500.0 / (500.0 + 1.0 - (2.0 * d - 1.0) * (500.0 - 1.0));\n gl_FragColor = vec4(mix(vec3(1.), texel.rgb, d2 > d ? 0.0 : intensity), texel.a);\n }\n ",d.output=C.OUTPUT.Default,d.enabled=!1,this.aoPass=d,_.fragmentShader=_.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const b=!1!==this.options?.reflection?.enabled,T=new z({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[]});if(T.output=b?z.OUTPUT.SSR:z.OUTPUT.Default,T.blur=!0,T.fresnel=!1,T.distanceAttenuation=!0,T.maxDistance=50,T.selective=!0,T.bouncing=!1,T.opacity=.4,T.enabled=!1!==this.options?.reflection?.enabled||b,this.ssrPass=T,this.composer.addPass(T),b){this.toonOutlinePass=new q(this.outlineEffect,this.scene,this.camera,!0),this.composer.addPass(this.toonOutlinePass),this.toonOutlinePass.enabled=!0,this.toonOutlinePass.clear=!0,this.toonOutlinePass.renderToScreen=!1;const e=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},ssrTexture:{value:T.ssrRenderTarget.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D ssrTexture;\n uniform float ssrOpacity;\n varying vec2 vUv;\n void main() {\n vec4 base = texture2D(baseTexture, vUv);\n vec4 ssr = texture2D(ssrTexture, vUv);\n // Blend SSR on top of base using opacity\n gl_FragColor = mix(base, ssr, ssr.a);\n }\n ",defines:{}}),"baseTexture");e.needsSwap=!0,this.composer.addPass(e)}!1!==this.options.ao?.enabled&&this.composer.addPass(d),this.renderer.info.autoReset=!1;const y=new c(this.renderer);y.renderToScreen=!1,y.addPass(l),y.addPass(h),this.bloomComposer=y,K||(y.renderTarget2.texture.type=i.HalfFloatType,this.composer.renderTarget1.texture.type=i.HalfFloatType);const S=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:y.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");S.needsSwap=!0,!1!==this.options.bloom?.enabled&&this.composer.addPass(S),this.volumetricFogPass=new N,this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new w(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const F=new k;this.colorPass=F,F.vignetteEnabled=!1,this.outlinePass=new H(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 D=new f(u);D.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(D),this.fxaaPass=D,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new f(p).clear=!1,this.fixStatsStyle(),this.lutPass=new m({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const I=new M;this.composer.addPass(I)}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){this.camera=e,this.composer.passes.forEach((t=>{t instanceof g?t.camera=e:t instanceof H?t.renderCamera=e:(t instanceof B||t instanceof C)&&(t.camera=e)})),null==this.csm?(this.csm=new S({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),h.lights_fragment_begin=b.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),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){var s=!!e.extensions.get("WEBGL_depth_texture");const r=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.type=i.FloatType,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===s&&(r.depthTexture=new i.DepthTexture(128,128),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:i.HalfFloatType});return s.texture.minFilter=i.NearestFilter,s.texture.magFilter=i.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,s.depthTexture=new i.DepthTexture(128,128),s.depthTexture.type=i.UnsignedInt248Type,s.depthTexture.minFilter=i.NearestFilter,s.depthTexture.magFilter=i.NearestFilter,s}static createSceneColorRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio()*.5,t.clientHeight*e.getPixelRatio()*.5,{format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren(),this.volumetricFogPass.dispose()}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){null!=this.scene.environment&&e instanceof T&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const s=this.stats,r=s.addPanel(new R.Panel("Calls","#83f","#002")),l=s.addPanel(new R.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new j(this.renderer.getContext()),s.addPanel(h)),this.showStats=t;let d=10,c=1e3;const u=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;const p=[],m=[],g=[];let f=0;const v=new a,x=new a,b=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>b(t)),500);this.renderer.clear(),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,s.begin();let a=(t*=.001)-f;if(f=t,v.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e($),t-=$;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),x.copy(this.camera.matrixWorld),x.equals(v)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),p.length=0,m.length=0,g.length=0;const l=te;if(ie.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),l.setFromProjectionMatrix(ie),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof i.Sprite)&&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))),(e instanceof o||e instanceof i.Sprite)&&this.initResolutionUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[D])&&isObjectInFrustum(e,l)?(e.visible=!1,p.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof y&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[W]&&isObjectInFrustum(e,l)?(e.visible=!1,g.push(e),e.material.uniforms[W].value=this.sceneColorRenderTarget.texture):(e instanceof o||e instanceof i.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e)&&(e.visible=!1,e.layers.enable(5),m.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[U])e.material.uniforms[U].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[U]&&(s.uniforms[U].value=t)})),p.length>0){if(this.scene.overrideMaterial=Q,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(g.length>0){if(this.renderer.setRenderTarget(this.sceneColorRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(!0,!0,!1);try{this.renderer.render(this.scene,this.camera)}catch(e){}}catch(e){console.warn("Error rendering scene color:",e)}this.renderer.setRenderTarget(null)}if(p.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0)),g.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=Q,this.camera.layers.set(5),this.renderer.setRenderTarget(this.aoMaskDepthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.camera.layers.enableAll(),this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}this.ssrPass&&(this.ssrPass.elapsedTime=t),this.volumetricFogPass&&this.volumetricFogPass.update(this.camera,this.ssrPass.beautyRenderTarget,this.csm,this.scene);try{!this.paused&&this.running&&(this.showStats&&h?.startQuery(),this.render(a),this.showStats&&h?.endQuery(),this.showStats&&u(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}s.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(b)}),1e3/this.fpsCap):requestAnimationFrame(b))};!0===this.options.enableXR?this.renderer.setAnimationLoop(b):requestAnimationFrame(b)}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return;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,r=!1,n=!1,a=!1;const o=this.camera?.position;if(null==o)return;let h=[];for(const e of this.postProcessVolumes){if(!ee(e.object))continue;let l=e.blendWeight??1;const d=e.distanceToPoint(o);d>e.blendRadius||(e.blendRadius>0&&(l*=L(1-d/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(h.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),n=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l)),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(r=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(r=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(r=!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,a=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),a=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,this.scene.environment=t.envTexture,this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,r&&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=a,a&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/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&&e.push(t)})),this.ssrPass.selects=e,0==e.length&&null==this.toonOutlinePass&&!1===this.volumetricFogPass.enabled&&(this.ssrPass.enabled=!1),t=!0}else null==this.toonOutlinePass&&!1===this.volumetricFogPass.enabled&&(this.ssrPass.enabled=!1,t=!0);if(!1!==this.options.bloom?.enabled){const e=this.hasBloom();if(e||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e)));try{this.bloomComposer.render()}catch(e){Z||(console.error(e),Z=!0)}this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=e}this.composer.render(e),t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=V(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===Y.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=Y:e.visible=!1}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 d&&(e.uniforms[D].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,this.camera instanceof l&&(null!=e.uniforms[A]&&(e.uniforms[A].value=this.camera.near),null!=e.uniforms[I]&&(e.uniforms[I].value=this.camera.far)))}initResolutionUniform(e){e instanceof d&&null!=e.uniforms[E]&&e.uniforms[E].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};J=e=t([F(),s("design:paramtypes",[HTMLElement,Object])],J);export{J as RenderingView};let Z=!1;export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const $=.05;function ee(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}C.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.visible=!1),null!=e.material){let t=!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);t&&(e.visible=!1)}}))};const te=new i.Frustum,se=new i.Box3,ie=new i.Matrix4;export function isObjectInFrustum(e,t){const s=se.setFromObject(e);return t.intersectsBox(s)}/*
1
+ var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as p,GammaCorrectionShader as u,LUTPass as m,RenderPass as g,ShaderPass as f,UnrealBloomPass as v,VRButton as x}from"three-stdlib";import{CSMShader as b,CSMUtil as P}from"./csm.js";import{NodeShaderMaterial as T}from"three-shader-graph";import{Reflector as y}from"three-stdlib";import{BokehPass as w,OutputPass as M}from"three/examples/jsm/Addons.js";import{CSM as R}from"three/examples/jsm/csm/CSM.js";import S from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as C}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as F}from"typedi";import{depthUniformName as D,farUniformName as I,nearUniformName as A,resolutionUniformName as E,supportsDepthTextureExtension as W}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as B}from"./shader-nodes/time.js";import{sceneMapUniformName as j}from"./shader-nodes/scene-sample.js";import{DepthPass as H}from"./utils/three/depth-pass.js";import{GPUStatsPanel as U}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as O}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as V}from"./utils/three/traverse.js";import{clamp as L}from"./utils/math.js";import{ColorPass as k}from"./rendering/color-pass.js";import{SSRPass as z}from"./rendering/ssr/SSRPass.js";import{SSRShader as _}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as N}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as G}from"./rendering/outline-effect.js";const q=document.createElement("div");q.style.position="absolute",q.style.left="50%",q.style.top="50%",q.style.color="black",q.style.zIndex="999";(new i.Layers).set(9);const X=new i.MeshBasicMaterial({color:"black"}),Y=new i.MeshDepthMaterial;Y.depthPacking=i.RGBADepthPacking,Y.blending=i.NoBlending,Y.side=i.DoubleSide;const Q=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let K=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||0!==this.container.clientWidth&&0!==this.container.clientHeight&&(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof l&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.bloomComposer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.dofPass.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture,this.depthRenderTarget.dispose(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container))}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.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.resolutionScale=Q?.5:1,this.maxPixelRatio=Q?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new S,this._showStats=!0,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 r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,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(x.createButton(this.renderer));const n=new G(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=n,this.composer=new c(this.renderer);var a=(t.clientWidth||1)/(t.clientHeight||1);const o=new i.PerspectiveCamera(45,a,.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,P.renderingView=this,P.patchThreeAdd(),this.isDepthTextureExtensionSupported=W(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container);const l=new g(this.scene,this.camera);this.composer.addPass(l);const h=new v(new i.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=1,h.strength=.9,h.radius=.5,this.bloomPass=h;const d=new C(this.scene,this.camera,t.clientWidth,t.clientWidth);d.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},d.blendMaterial.uniforms.tAODepth={value:d.depthTexture},d.blendMaterial.fragmentShader="\n uniform float intensity;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D tAODepth;\n varying vec2 vUv;\n\n void main() {\n vec4 texel = texture2D( tDiffuse, vUv );\n float d = textureLod(tDepth, vUv.xy, 0.0).x;\n float d2 = textureLod(tAODepth, vUv.xy, 0.0).x;\n\n float depth = 2.0 * 1.0 * 500.0 / (500.0 + 1.0 - (2.0 * d - 1.0) * (500.0 - 1.0));\n gl_FragColor = vec4(mix(vec3(1.), texel.rgb, d2 > d ? 0.0 : intensity), texel.a);\n }\n ",d.output=C.OUTPUT.Default,d.enabled=!1,this.aoPass=d,_.fragmentShader=_.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const b=new z({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[]});b.output=z.OUTPUT.Default,b.blur=!0,b.fresnel=!1,b.distanceAttenuation=!0,b.maxDistance=50,b.selective=!0,b.bouncing=!1,b.opacity=.4,b.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=b,this.composer.addPass(b),!1!==this.options.ao?.enabled&&this.composer.addPass(d),this.renderer.info.autoReset=!1;const T=new c(this.renderer);T.renderToScreen=!1,T.addPass(l),T.addPass(h),this.bloomComposer=T,Q||(T.renderTarget2.texture.type=i.HalfFloatType,this.composer.renderTarget1.texture.type=i.HalfFloatType);const y=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:T.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");y.needsSwap=!0,!1!==this.options.bloom?.enabled&&this.composer.addPass(y),this.volumetricFogPass=new N,this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new w(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const R=new k;this.colorPass=R,R.vignetteEnabled=!1,this.outlinePass=new O(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 F=new f(p);F.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(F),this.fxaaPass=F,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new f(u).clear=!1,this.fixStatsStyle(),this.lutPass=new m({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const D=new M;this.composer.addPass(D)}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){this.camera=e,this.composer.passes.forEach((t=>{t instanceof g?t.camera=e:t instanceof O?t.renderCamera=e:(t instanceof H||t instanceof C)&&(t.camera=e)})),null==this.csm?(this.csm=new R({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),h.lights_fragment_begin=b.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),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){var s=!!e.extensions.get("WEBGL_depth_texture");const r=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.type=i.FloatType,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===s&&(r.depthTexture=new i.DepthTexture(128,128),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:i.HalfFloatType});return s.texture.minFilter=i.NearestFilter,s.texture.magFilter=i.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,s.depthTexture=new i.DepthTexture(128,128),s.depthTexture.type=i.UnsignedInt248Type,s.depthTexture.minFilter=i.NearestFilter,s.depthTexture.magFilter=i.NearestFilter,s}static createSceneColorRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio()*.5,t.clientHeight*e.getPixelRatio()*.5,{format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren(),this.volumetricFogPass.dispose()}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){null!=this.scene.environment&&e instanceof T&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const s=this.stats,r=s.addPanel(new S.Panel("Calls","#83f","#002")),l=s.addPanel(new S.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new U(this.renderer.getContext()),s.addPanel(h)),this.showStats=t;let d=10,c=1e3;const p=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;const u=[],m=[],g=[];let f=0;const v=new a,x=new a,b=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>b(t)),500);this.renderer.clear(),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,s.begin();let a=(t*=.001)-f;if(f=t,v.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(Z),t-=Z;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),x.copy(this.camera.matrixWorld),x.equals(v)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),u.length=0,m.length=0,g.length=0;const l=ee;if(se.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),l.setFromProjectionMatrix(se),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof i.Sprite)&&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))),this.outlineEffect.apply(e),(e instanceof o||e instanceof i.Sprite)&&this.initResolutionUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[D])&&isObjectInFrustum(e,l)?(e.visible=!1,u.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof y&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[j]&&isObjectInFrustum(e,l)?(e.visible=!1,g.push(e),e.material.uniforms[j].value=this.sceneColorRenderTarget.texture):(e instanceof o||e instanceof i.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e)&&(e.visible=!1,e.layers.enable(5),m.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[B])e.material.uniforms[B].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[B]&&(s.uniforms[B].value=t)})),u.length>0){if(this.scene.overrideMaterial=Y,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(g.length>0){if(this.renderer.setRenderTarget(this.sceneColorRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(!0,!0,!1);try{this.renderer.render(this.scene,this.camera)}catch(e){}}catch(e){console.warn("Error rendering scene color:",e)}this.renderer.setRenderTarget(null)}if(u.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0)),g.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=Y,this.camera.layers.set(5),this.renderer.setRenderTarget(this.aoMaskDepthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.camera.layers.enableAll(),this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}this.ssrPass&&(this.ssrPass.elapsedTime=t),this.volumetricFogPass&&this.volumetricFogPass.update(this.camera,this.ssrPass.beautyRenderTarget,this.csm,this.scene);try{!this.paused&&this.running&&(this.showStats&&h?.startQuery(),this.render(a),this.showStats&&h?.endQuery(),this.showStats&&p(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}s.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(b)}),1e3/this.fpsCap):requestAnimationFrame(b))};!0===this.options.enableXR?this.renderer.setAnimationLoop(b):requestAnimationFrame(b)}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return;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,r=!1,n=!1,a=!1;const o=this.camera?.position;if(null==o)return;let h=[];for(const e of this.postProcessVolumes){if(!$(e.object))continue;let l=e.blendWeight??1;const d=e.distanceToPoint(o);d>e.blendRadius||(e.blendRadius>0&&(l*=L(1-d/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(h.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),n=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l)),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(r=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(r=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(r=!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,a=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),a=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,this.scene.environment=t.envTexture,this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,r&&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=a,a&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/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&&e.push(t)})),this.ssrPass.selects=e,0==e.length&&!1===this.volumetricFogPass.enabled&&(this.ssrPass.enabled=!1),t=!0}else!1===this.volumetricFogPass.enabled&&(this.ssrPass.enabled=!1,t=!0);if(!1!==this.options.bloom?.enabled){const e=this.hasBloom();if(e||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e)));try{this.bloomComposer.render()}catch(e){J||(console.error(e),J=!0)}this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=e}this.composer.render(e),t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=V(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===X.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=X:e.visible=!1}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 d&&(e.uniforms[D].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,this.camera instanceof l&&(null!=e.uniforms[A]&&(e.uniforms[A].value=this.camera.near),null!=e.uniforms[I]&&(e.uniforms[I].value=this.camera.far)))}initResolutionUniform(e){e instanceof d&&null!=e.uniforms[E]&&e.uniforms[E].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};K=e=t([F(),s("design:paramtypes",[HTMLElement,Object])],K);export{K as RenderingView};let J=!1;export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const Z=.05;function $(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}C.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.visible=!1),null!=e.material){let t=!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);t&&(e.visible=!1)}}))};const ee=new i.Frustum,te=new i.Box3,se=new i.Matrix4;export function isObjectInFrustum(e,t){const s=te.setFromObject(e);return t.intersectsBox(s)}/*
2
2
  * Copyright (©) 2025 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hology/core",
3
- "version": "0.0.127",
3
+ "version": "0.0.128",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -168,7 +168,7 @@
168
168
  "dependencies": {
169
169
  "@babel/runtime": "^7.24.8",
170
170
  "@dimforge/rapier3d-compat": "^0.14.0",
171
- "@hology/nebula": "^0.0.127",
171
+ "@hology/nebula": "^0.0.128",
172
172
  "@plumier/reflect": "^1.1.0",
173
173
  "@recast-navigation/three": "0.39.0",
174
174
  "recast-navigation": "0.39.0",