@hology/core 0.0.58 → 0.0.60
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/rendering.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as h,ShaderChunk as l,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as m,GammaCorrectionShader as u,RenderPass as p,ShaderPass as g,UnrealBloomPass as f,VRButton as v}from"three-stdlib";import{CSMShader as w,CSMUtil as x}from"./csm.js";import*as b from"stats.js";import{Reflector as C}from"three-stdlib";import{CSM as S}from"three/examples/jsm/csm/CSM.js";import{Service as y}from"typedi";import{depthUniformName as P,farUniformName as R,nearUniformName as M,resolutionUniformName as T,supportsDepthTextureExtension as W}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as E}from"./shader-nodes/time.js";import{DepthPass as L}from"./utils/three/depth-pass.js";import{GPUStatsPanel as H}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as B}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as D}from"./utils/three/traverse.js";(new s.Layers).set(9);const F=new s.MeshBasicMaterial({color:"black"}),V=new s.MeshDepthMaterial;V.depthPacking=s.RGBADepthPacking,V.blending=s.NoBlending;const j=/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||(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof h&&(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))}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=j?.5:1,this.maxPixelRatio=j?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new b,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={},null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.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(v.createButton(this.renderer)),this.composer=new c(this.renderer);var n=t.clientWidth/t.clientHeight;const a=new s.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,x.renderingView=this,x.patchThreeAdd(),this.isDepthTextureExtensionSupported=W(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container);const o=new p(this.scene,this.camera);this.composer.addPass(o);const h=new f(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=0,h.strength=.9,h.radius=1,this.renderer.info.autoReset=!1;const l=new c(this.renderer);l.renderToScreen=!1,l.addPass(o),l.addPass(h),this.bloomComposer=l;const d=new g(new s.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:l.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");if(d.needsSwap=!0,this.composer.addPass(d),this.outlinePass=new B(new s.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new g(m);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}var w=new g(u);w.clear=!1,this.composer.addPass(w),this.fixStatsStyle()}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"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof p?t.camera=e:t instanceof B?t.renderCamera=e:t instanceof L&&(t.camera=e)})),null==this.csm?(this.csm=new S({maxFar:250,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"logarithmic"}),l.lights_fragment_begin=w.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof h&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}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.csm.dispose(),this.container.replaceChildren()}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}loop(e,t=!1){const i=this.stats,r=i.addPanel(new b.Panel("Calls","#83f","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new H(this.renderer.getContext()),i.addPanel(h)),this.showStats=t;let l=10;const d=()=>{const e=this.renderer.info.render.calls;e>l&&(l=e,setTimeout((()=>l=10),5e3)),r.update(e,l)};performance.now();s.Ray.prototype.intersectTriangle;const c=[],m=[];let u=0;const p=new a,g=new a,f=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>f(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let a=(t*=.001)-u;if(u=t,p.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(z),t-=z;e(t)}else e(a);if(this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),g.copy(this.camera.matrixWorld),g.equals(p)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),c.length=0,m.length=0,this.scene.traverseVisible((e=>{(e instanceof o||e instanceof s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[P])?(e.visible=!1,c.push(e),this.initDepthUniform(e.material),e.renderOrder=100):(e instanceof C||(e instanceof o||e instanceof s.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,m.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[E]&&(e.material.uniforms[E].value=t)})),c.length>0){if(this.scene.overrideMaterial=V,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}c.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0));try{!this.paused&&this.running&&(h?.startQuery(),this.render(a),h?.endQuery(),this.showStats&&d(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(f)}),1e3/this.fpsCap):requestAnimationFrame(f))};!0===this.options.enableXR?this.renderer.setAnimationLoop(f):requestAnimationFrame(f)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){const t=this.hasBloom();if(t||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))),this.bloomComposer.render(),this.scene.traverse((e=>this.restoreMaterial(e))),this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=t,this.composer.render(e)}hasBloom(){return null!=D(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){e.isMesh&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)&&(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=F:e.visible=!1)}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[P].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[T]&&e.uniforms[T].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof h&&(e.uniforms[M].value=this.camera.near,e.uniforms[R].value=this.camera.far))}};k=e=t([y(),i("design:paramtypes",[HTMLElement,Object])],k);export{k as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const z=.05;
|
|
1
|
+
var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as h,ShaderChunk as l,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as m,GammaCorrectionShader as u,RenderPass as p,ShaderPass as g,UnrealBloomPass as f,VRButton as v}from"three-stdlib";import{CSMShader as w,CSMUtil as x}from"./csm.js";import b from"three/examples/jsm/libs/stats.module.js";import{Reflector as C}from"three-stdlib";import{CSM as S}from"three/examples/jsm/csm/CSM.js";import{Service as y}from"typedi";import{depthUniformName as P,farUniformName as R,nearUniformName as M,resolutionUniformName as T,supportsDepthTextureExtension as W}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as E}from"./shader-nodes/time.js";import{DepthPass as L}from"./utils/three/depth-pass.js";import{GPUStatsPanel as H}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as B}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as D}from"./utils/three/traverse.js";(new s.Layers).set(9);const F=new s.MeshBasicMaterial({color:"black"}),j=new s.MeshDepthMaterial;j.depthPacking=s.RGBADepthPacking,j.blending=s.NoBlending;const V=/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||(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof h&&(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))}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=V?.5:1,this.maxPixelRatio=V?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new b,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={},null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.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(v.createButton(this.renderer)),this.composer=new c(this.renderer);var n=t.clientWidth/t.clientHeight;const a=new s.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,x.renderingView=this,x.patchThreeAdd(),this.isDepthTextureExtensionSupported=W(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container);const o=new p(this.scene,this.camera);this.composer.addPass(o);const h=new f(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=0,h.strength=.9,h.radius=1,this.renderer.info.autoReset=!1;const l=new c(this.renderer);l.renderToScreen=!1,l.addPass(o),l.addPass(h),this.bloomComposer=l;const d=new g(new s.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:l.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");if(d.needsSwap=!0,this.composer.addPass(d),this.outlinePass=new B(new s.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new g(m);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}var w=new g(u);w.clear=!1,this.composer.addPass(w),this.fixStatsStyle()}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"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof p?t.camera=e:t instanceof B?t.renderCamera=e:t instanceof L&&(t.camera=e)})),null==this.csm?(this.csm=new S({maxFar:250,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"logarithmic"}),l.lights_fragment_begin=w.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof h&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}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.csm.dispose(),this.container.replaceChildren()}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}loop(e,t=!1){const i=this.stats,r=i.addPanel(new b.Panel("Calls","#83f","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new H(this.renderer.getContext()),i.addPanel(h)),this.showStats=t;let l=10;const d=()=>{const e=this.renderer.info.render.calls;e>l&&(l=e,setTimeout((()=>l=10),5e3)),r.update(e,l)};performance.now();s.Ray.prototype.intersectTriangle;const c=[],m=[];let u=0;const p=new a,g=new a,f=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>f(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let a=(t*=.001)-u;if(u=t,p.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(z),t-=z;e(t)}else e(a);if(this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),g.copy(this.camera.matrixWorld),g.equals(p)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),c.length=0,m.length=0,this.scene.traverseVisible((e=>{(e instanceof o||e instanceof s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[P])?(e.visible=!1,c.push(e),this.initDepthUniform(e.material),e.renderOrder=100):(e instanceof C||(e instanceof o||e instanceof s.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,m.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[E]&&(e.material.uniforms[E].value=t)})),c.length>0){if(this.scene.overrideMaterial=j,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}c.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0));try{!this.paused&&this.running&&(h?.startQuery(),this.render(a),h?.endQuery(),this.showStats&&d(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(f)}),1e3/this.fpsCap):requestAnimationFrame(f))};!0===this.options.enableXR?this.renderer.setAnimationLoop(f):requestAnimationFrame(f)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){const t=this.hasBloom();if(t||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))),this.bloomComposer.render(),this.scene.traverse((e=>this.restoreMaterial(e))),this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=t,this.composer.render(e)}hasBloom(){return null!=D(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){e.isMesh&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)&&(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=F:e.visible=!1)}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[P].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[T]&&e.uniforms[T].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof h&&(e.uniforms[M].value=this.camera.near,e.uniforms[R].value=this.camera.far))}};k=e=t([y(),i("design:paramtypes",[HTMLElement,Object])],k);export{k as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const z=.05;
|
|
2
2
|
/*
|
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
|
4
4
|
* See the LICENSE.md file for details.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Vector2 as e}from"three";import{dot as t,FloatExpressionNode as o,FloatNode as r,texture2d as n,uniformVec2 as
|
|
1
|
+
import{Vector2 as e}from"three";import{dot as t,FloatExpressionNode as o,FloatNode as r,texture2d as n,uniformVec2 as a,Vec2ExpressionNode as s,Vec4Node as c,uniformSampler2d as p,uniformFloat as i}from"three-shader-graph";import*as h from"three";export function supportsDepthTextureExtension(e){return!!e.extensions.get("WEBGL_depth_texture")}export const depthUniformName="hology_depth_map";export const resolutionUniformName="hology_resolution";export const nearUniformName="hology_camera_near";export const farUniformName="hology_camera_far";export const depthSampler=p(depthUniformName,new h.DepthTexture(1,1));const m=i(nearUniformName,.5),l=i(farUniformName,500);class u extends r{compile(e){const t=e.variable();var o=e.get(m),r=e.get(l);return{chunk:`\n float depth_${t} = 2.0 * ${o} * ${r} / (${r} + ${o} - (2.0 * ${e.get(this.depth)} - 1.0) * (${r} - ${o}));\n `,out:`depth_${t}`}}constructor(e){super(),this.depth=e}}function _(e){return new u(e)}const f=new class extends c{constructor(){super(...arguments),this.k="31u50"}compile(e){return{pars:`\n const float UnpackDownscale_${this.k} = 255. / 256.; // 0..1 -> fraction (excluding 1)\n const vec4 PackFactors_${this.k} = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\n const vec4 UnpackFactors_${this.k} = vec4( UnpackDownscale_${this.k} / PackFactors_${this.k}.rgb, 1.0 / PackFactors_${this.k}.a );\n `,out:`UnpackFactors_${this.k}`}}};const d=new o("gl_FragCoord.z");export const fragmentLinearEyeDepth=_(d);const g=a("hology_resolution",new e(250,1e3)),x=new s("gl_FragCoord.xy").divide(g);export const linearEyeDepth=_((k=x,$=n(depthSampler,k),t($,f)));var k,$;
|
|
2
2
|
/*
|
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
|
4
4
|
* See the LICENSE.md file for details.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from"three/examples/jsm/libs/stats.module.js";class t extends e.Panel{constructor(e,t="GPU MS"){super(t,"#f90","#210");let i=!0,n=e.getExtension("EXT_disjoint_timer_query_webgl2");null===n&&(i=!1,n=e.getExtension("EXT_disjoint_timer_query"),null===n&&console.warn("GPUStatsPanel: disjoint_time_query extension not available.")),this.context=e,this.extension=n,this.maxTime=30,this.activeQueries=0,this.startQuery=function(){const e=this.context,t=this.extension;if(null===t)return;let n;i?(n=e.createQuery(),e.beginQuery(t.TIME_ELAPSED_EXT,n)):(n=t.createQueryEXT(),t.beginQueryEXT(t.TIME_ELAPSED_EXT,n)),this.activeQueries++;const s=()=>{let r,E,a;i?(r=e.getQueryParameter(n,e.QUERY_RESULT_AVAILABLE),E=e.getParameter(t.GPU_DISJOINT_EXT),a=e.getQueryParameter(n,e.QUERY_RESULT)):(r=t.getQueryObjectEXT(n,t.QUERY_RESULT_AVAILABLE_EXT),E=e.getParameter(t.GPU_DISJOINT_EXT),a=t.getQueryObjectEXT(n,t.QUERY_RESULT_EXT));const u=1e-6*a;r?(E||this.update(u,this.maxTime),this.activeQueries--):requestAnimationFrame(s)};requestAnimationFrame(s)},this.endQuery=function(){const e=this.extension,t=this.context;null!==e&&(i?t.endQuery(e.TIME_ELAPSED_EXT):e.endQueryEXT(e.TIME_ELAPSED_EXT))}}}export{t as GPUStatsPanel};
|
|
2
2
|
/*
|
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
|
4
4
|
* See the LICENSE.md file for details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hology/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -82,6 +82,9 @@
|
|
|
82
82
|
},
|
|
83
83
|
"author": "",
|
|
84
84
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
85
|
+
"peerDependencies": {
|
|
86
|
+
"three": ">=0.169.0"
|
|
87
|
+
},
|
|
85
88
|
"dependencies": {
|
|
86
89
|
"@babel/runtime": "^7.24.8",
|
|
87
90
|
"@dimforge/rapier3d-compat": "^0.13.1",
|
|
@@ -89,13 +92,10 @@
|
|
|
89
92
|
"@types/three-nebula": "^10.0.3",
|
|
90
93
|
"recast-navigation": "^0.30.0",
|
|
91
94
|
"rxjs": "7.8.1",
|
|
92
|
-
"stats-gl": "^3.0.1",
|
|
93
|
-
"stats.js": "^0.17.0",
|
|
94
|
-
"three": "^0.169.0",
|
|
95
95
|
"three-csm": "^4.2.1",
|
|
96
96
|
"three-mesh-bvh": "^0.7.5",
|
|
97
97
|
"three-nebula": "^10.0.3",
|
|
98
|
-
"three-shader-graph": "0.2.
|
|
98
|
+
"three-shader-graph": "0.2.6",
|
|
99
99
|
"three-stdlib": "2.34.0",
|
|
100
100
|
"ts-key-enum": "^2.0.12",
|
|
101
101
|
"typedi": "^0.10.0"
|