@hology/core 0.0.153 → 0.0.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effects/vfx/vfx-materializer.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/rendering/bloom/LuminosityHighPassShader.d.ts +28 -0
- package/dist/rendering/bloom/LuminosityHighPassShader.d.ts.map +1 -0
- package/dist/rendering/bloom/LuminosityHighPassShader.js +4 -0
- package/dist/rendering/bloom/UnrealBloomPass.d.ts +89 -0
- package/dist/rendering/bloom/UnrealBloomPass.d.ts.map +1 -0
- package/dist/rendering/bloom/UnrealBloomPass.js +4 -0
- package/dist/rendering/bloom/types.d.ts +14 -0
- package/dist/rendering/bloom/types.d.ts.map +1 -0
- package/dist/rendering/bloom/types.js +4 -0
- package/dist/rendering/outline-effect.js +1 -1
- package/dist/rendering/ssr/SSRPass.d.ts +8 -1
- package/dist/rendering/ssr/SSRPass.d.ts.map +1 -1
- package/dist/rendering/ssr/SSRPass.js +1 -1
- package/dist/rendering/ssr/SSRShader.d.ts.map +1 -1
- package/dist/rendering/ssr/SSRShader.js +1 -1
- package/dist/rendering.d.ts +3 -0
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts.map +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/materializer.d.ts.map +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/shader/builtin/decal-unlit-shader.d.ts +2 -1
- package/dist/shader/builtin/decal-unlit-shader.d.ts.map +1 -1
- package/dist/shader/builtin/decal-unlit-shader.js +1 -1
- package/dist/shader/builtin/lambert-shader.d.ts +3 -1
- package/dist/shader/builtin/lambert-shader.d.ts.map +1 -1
- package/dist/shader/builtin/lambert-shader.js +1 -1
- package/dist/shader-nodes/depth.d.ts.map +1 -1
- package/dist/shader-nodes/depth.js +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
package/dist/rendering.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{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 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 A,nearUniformName as E,resolutionUniformName as I,supportsDepthTextureExtension as W}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as U}from"./shader-nodes/time.js";import{sceneMapUniformName as B}from"./shader-nodes/scene-sample.js";import{DepthPass as j}from"./utils/three/depth-pass.js";import{GPUStatsPanel as H}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as V}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as O}from"./utils/three/traverse.js";import{clamp as k}from"./utils/math.js";import{ColorPass as L}from"./rendering/color-pass.js";import{SSRPass as G}from"./rendering/ssr/SSRPass.js";import{SSRShader as z}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as _}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as N}from"./rendering/outline-effect.js";P.patchSetupMaterial();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.resolutionScale),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=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.pmremGeneratorResults=new WeakMap,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!1,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 N(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,this.isDepthTextureExtensionSupported=W(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container,this.resolutionScale),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container);const l=new i.Vector2(t.clientWidth,t.clientHeight),h=new g(this.scene,this.camera);this.composer.addPass(h);const d=new v(l,1.5,.4,.85);d.threshold=1,d.strength=.9,d.radius=.5,this.bloomPass=d;const b=new C(this.scene,this.camera,t.clientWidth,t.clientWidth);b.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},b.blendMaterial.uniforms.tAODepth={value:b.depthTexture},b.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 ",b.output=C.OUTPUT.Default,b.enabled=!1,this.aoPass=b,z.fragmentShader=z.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const T=new G({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[]});T.output=G.OUTPUT.Default,T.blur=!0,T.fresnel=!1,T.distanceAttenuation=!0,T.maxDistance=50,T.selective=!0,T.bouncing=!1,T.opacity=.4,T.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=T,this.composer.addPass(T),!1!==this.options.ao?.enabled&&this.composer.addPass(b),this.renderer.info.autoReset=!1;const y=new c(this.renderer);y.renderToScreen=!1,y.addPass(h),y.addPass(d),this.bloomComposer=y,Q||(y.renderTarget2.texture.type=i.HalfFloatType,this.composer.renderTarget1.texture.type=i.HalfFloatType);const R=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");R.needsSwap=!0,!1!==this.options.bloom?.enabled&&this.composer.addPass(R),this.volumetricFogPass=new _(l),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 L;this.composer.addPass(F),this.colorPass=F,F.vignetteEnabled=!1,this.outlinePass=new V(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 A=new M;this.composer.addPass(A)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){this.camera=e,this.composer.passes.forEach(t=>{t instanceof g?t.camera=e:t instanceof V?t.renderCamera=e:(t instanceof j||t instanceof C)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),null==this.csm?(this.csm=new R({maxFar:100,lightFar:250,lightMargin:20,cascades:Q?2:4,shadowMapSize:2048*(Q?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"}),this.csm.fade=!0,h.lights_fragment_begin=b.lights_fragment_begin):(this.csm.camera=this.camera,this.camera),this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse(e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)});this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t,s){var r=!!e.extensions.get("WEBGL_depth_texture");const n=new i.WebGLRenderTarget(t.clientWidth*s,t.clientHeight*s);return n.texture.minFilter=i.NearestFilter,n.texture.magFilter=i.NearestFilter,n.texture.type=i.FloatType,n.texture.generateMipmaps=!1,n.stencilBuffer=!1,!0===r&&(n.depthTexture=new i.DepthTexture(128,128),n.depthTexture.type=i.UnsignedShortType,n.depthTexture.minFilter=i.NearestFilter,n.depthTexture.magFilter=i.NearestFilter),n}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(),P.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){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)}setupCsm(e){if(e instanceof i.Mesh||e instanceof i.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)this.csm.setupMaterial(t);else this.csm.setupMaterial(e.material)}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 H(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;let b=this.paused;const P=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return setTimeout(()=>P(t),500),void(b=!0);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,b&&(a=.016,b=!1),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(),this.csm.update(),p.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(this.setupCsm(e),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,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[B]&&isObjectInFrustum(e,l)?(e.visible=!1,g.push(e),e.material.uniforms[B].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=Y,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear();const e=this.scene.matrixWorldAutoUpdate;this.scene.matrixWorldAutoUpdate=!1,this.renderer.render(this.scene,this.camera),this.scene.matrixWorldAutoUpdate=e}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=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&&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(P)},1e3/this.fpsCap):requestAnimationFrame(P))};!0===this.options.enableXR?this.renderer.setAnimationLoop(P):requestAnimationFrame(P)}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t}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;if(null==this.camera)return;const o=this.camera.getWorldPosition(ie);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*=k(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,null!=t.envTexture&&(this.scene.environment=this.getEnvTexture(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.traverseVisible(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!=O(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,this.bloomHidden.push(e))}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[D].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,this.camera instanceof l&&(null!=e.uniforms[E]&&(e.uniforms[E].value=this.camera.near),null!=e.uniforms[A]&&(e.uniforms[A].value=this.camera.far)))}initResolutionUniform(e){e instanceof d&&null!=e.uniforms[I]&&e.uniforms[I].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)}const ie=new i.Vector3;/*
|
|
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 c,WebGLRenderTarget as d}from"three";import{CopyShader as u,EffectComposer as p,FXAAShader as m,GammaCorrectionShader as g,LUTPass as f,RenderPass as v,ShaderPass as T,VRButton as P}from"three-stdlib";import{CSMShader as x,CSMUtil as b}from"./csm.js";import{bool as y,colorToNormal as M,float as w,NodeShaderMaterial as R,normalize as S,rgb as C,textureSampler2d as F,varyingAttributes as E,varyingTransformed as A,vec4 as I}from"three-shader-graph";import{Reflector as W}from"three-stdlib";import{BokehPass as B,OutputPass as j}from"three/examples/jsm/Addons.js";import{CSM as H}from"three/examples/jsm/csm/CSM.js";import D from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as L}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as U}from"typedi";import{depthUniformName as V,farUniformName as O,nearUniformName as G,resolutionUniformName as k,supportsDepthTextureExtension as N}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as z}from"./shader-nodes/time.js";import{sceneMapUniformName as _}from"./shader-nodes/scene-sample.js";import{DepthPass as q}from"./utils/three/depth-pass.js";import{GPUStatsPanel as X}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as Y}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as Q,traverseVisibleStop as K}from"./utils/three/traverse.js";import{clamp as J}from"./utils/math.js";import{ColorPass as Z}from"./rendering/color-pass.js";import{SSRPass as $}from"./rendering/ssr/SSRPass.js";import{SSRShader as ee}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as te}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as se}from"./rendering/outline-effect.js";import{UnrealBloomPass as ie}from"./rendering/bloom/UnrealBloomPass.js";b.patchSetupMaterial();const re=document.createElement("div");re.style.position="absolute",re.style.left="50%",re.style.top="50%",re.style.color="black",re.style.zIndex="999";(new i.Layers).set(9);const ne=new i.MeshBasicMaterial({color:"black"}),ae=new i.MeshDepthMaterial;ae.depthPacking=i.RGBADepthPacking,ae.blending=i.NoBlending,ae.side=i.DoubleSide;const oe=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let le=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.dofPass.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.gRenderTarget.depthTexture?.dispose(),this.gRenderTarget.depthTexture=new i.DepthTexture(this.container.clientWidth,this.container.clientHeight),this.gRenderTarget.depthTexture.type=i.UnsignedShortType,this.gRenderTarget.depthTexture.minFilter=i.NearestFilter,this.gRenderTarget.depthTexture.magFilter=i.NearestFilter,this.gRenderTarget.setSize(this.container.clientWidth,this.container.clientHeight),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[0]),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=1,this.maxPixelRatio=oe?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.onLoopCallbacks=[],this.stats=new D,this._showStats=!0,this.gbufferMaterialCache=new Map,this.pmremGeneratorResults=new WeakMap,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!1,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(P.createButton(this.renderer));const n=new se(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=n,this.gRenderTarget=new d(t.clientWidth,t.clientHeight,{count:2,minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat}),this.gRenderTarget.depthTexture=new i.DepthTexture(t.clientWidth,t.clientHeight),this.gRenderTarget.depthTexture.type=i.UnsignedShortType,this.gRenderTarget.depthTexture.minFilter=i.NearestFilter,this.gRenderTarget.depthTexture.magFilter=i.NearestFilter,this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1,this.composer=new p(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,b.renderingView=this,this.isDepthTextureExtensionSupported=N(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container);const l=new i.Vector2(t.clientWidth,t.clientHeight),h=new v(this.scene,this.camera);this.composer.addPass(h);const c=new ie(l,1.5,.4,.85);c.threshold=1,c.strength=.9,c.radius=.5,this.bloomPass=c;const x=new L(this.scene,this.camera,t.clientWidth,t.clientWidth,{});x.normalRenderTarget?.dispose(),x.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[0]),x.output=L.OUTPUT.Default,x.enabled=!1,this.aoPass=x,ee.fragmentShader=ee.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const y=new $({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[0]});y.output=$.OUTPUT.Default,y.blur=!0,y.fresnel=!1,y.distanceAttenuation=!0,y.maxDistance=50,y.selective=!0,y.bouncing=!1,y.opacity=.4,y.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=y,this.composer.addPass(y),!1!==this.options.ao?.enabled&&this.composer.addPass(x),this.composer.addPass(c),c.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.options.bloom,this.volumetricFogPass=new te(l),this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new B(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const M=new Z;this.composer.addPass(M),this.colorPass=M,M.vignetteEnabled=!1,this.outlinePass=new Y(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 w=new T(m);w.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(w),this.fxaaPass=w,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new T(g).clear=!1,this.fixStatsStyle(),this.lutPass=new f({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const R=new T(u,"prevtexture");R.enabled=!0,R.needsSwap=!1,R.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],R.renderToScreen=!0;const S=new j;this.composer.addPass(S)}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 v?t.camera=e:t instanceof Y?t.renderCamera=e:(t instanceof q||t instanceof L)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),null==this.csm?(this.csm=new H({maxFar:100,lightFar:250,lightMargin:20,cascades:oe?2:4,shadowMapSize:2048*(oe?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"}),this.csm&&Array.isArray(this.csm.lights),this.csm.fade=!0,h.lights_fragment_begin=x.lights_fragment_begin):(this.csm.camera=this.camera,this.camera),this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse(e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)});this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t,s){const r=new i.WebGLRenderTarget(t.clientWidth*s,t.clientHeight*s);return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,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.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren(),this.volumetricFogPass.dispose(),b.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof R&&(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)}setupCsm(e){if(e instanceof i.Mesh||e instanceof i.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)this.csm.setupMaterial(t);else this.csm.setupMaterial(e.material)}createGBufferMaterial(e){let t=this.gbufferMaterialCache.get(e);if(null==t){let r=A.normal;e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial?null!=e.normalMap&&(r=M(F(e.normalMap).sample(E.uv),e.normalScale.x??1)):e instanceof R&&null!=e.outputNormal&&(r=e.outputNormal);let n=e.userData?.reflective?w(0):w(1);e instanceof i.MeshStandardMaterial?n=null!=e.roughnessMap?F(e.roughnessMap).sample(E.uv).r.multiply(e.roughness??1):w(e.roughness??1):e instanceof R&&null!=e.outputRoughness&&(n=e.outputRoughness);const a=!0===e.userData.hasBloom;let o=C(0);a&&(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial?(o=null!=e.emissiveMap?F(e.emissiveMap).sample(E.uv).rgb.multiply(C(e.emissive??0)):C(e.emissive??0),o=o.multiplyScalar(e.emissiveIntensity)):e instanceof R&&(o=e.outputEmissive??e.outputColor.rgb.multiplyScalar(e.outputColor.a)));let l=w(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial?(null!=e.alphaMap&&(l=F(e.alphaMap).sample(E.uv).r),null!=e.map&&(l=l.multiply(F(e.map).sample(E.uv).a))):e instanceof R&&null!=e.opacity&&(l=e.outputOpacity.multiply(e.opacity??1));const h=e instanceof c&&null!=e.uniforms[V],d=e.transparent&&e.alphaTest<=0,u=e.alphaTest>0?l.lt(e.alphaTest):y(!1);let p;p=d?I(0,0,0,0):(s=r,S(s).multiplyScalar(.5).addScalar(.5)).rgba(n);let m=e instanceof R?e.outputPosition:void 0;t=new R({position:m,outputs:[p,o],outputEncoding:!1,fog:!1,transparent:!1,lights:!1,discard:u}),t.toneMapped=!1,t.side=i.FrontSide,d&&a&&(t.transparent=!0,t.blending=i.AdditiveBlending),d?(t.depthWrite=!1,t.depthTest=!0,t.visible=a):(t.depthWrite=!0,t.depthTest=!0),t.visible=!h&&t.visible,e instanceof c&&Object.assign(t.uniforms,e.uniforms),this.gbufferMaterialCache.set(e,t)}var s;if(e instanceof c)for(const s in e.uniforms)null!=t.uniforms[s]&&(t.uniforms[s].value=e.uniforms[s].value);return t}loop(e,t=!1){const s=this.stats,r=s.addPanel(new D.Panel("Calls","#83f","#002")),n=s.addPanel(new D.Panel("Triangles","#c32","#002"));let l;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(l=new X(this.renderer.getContext()),s.addPanel(l)),this.showStats=t;let h=10,d=1e3;const u=()=>{const e=this.renderer.info.render.calls;e>h&&(h=e,setTimeout(()=>h=10,5e3)),r.update(e,h);const t=this.renderer.info.render.triangles;t>d&&(d=t,setTimeout(()=>d=1e3,5e3)),n.update(t,d)};performance.now();i.Ray.prototype.intersectTriangle;const p=[],m=[],g=[];let f=0;const v=new a,T=new a;let P=this.paused;const x=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return setTimeout(()=>x(t),500),void(P=!0);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(),this.showStats&&l?.startQuery(),this.ssrPass.gpuPanel=l;let n=(t*=.001)-f;if(f=t,P&&(n=.016,P=!1),v.copy(this.camera.matrixWorld),n>1){let t=n;for(;t>.05;)e(he),t-=he;e(t)}else e(n);this.onLoopCallbacks.forEach(e=>e(n)),this.camera?.updateMatrixWorld(),T.copy(this.camera.matrixWorld),T.equals(v)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),this.csm.update(),p.length=0,m.length=0,g.length=0;const a=de;pe.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),a.setFromProjectionMatrix(pe),this.scene.traverseVisible(e=>{if(this.setupCsm(e),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[V])&&isObjectInFrustum(e,a)?this.initDepthUniform(e.material):e instanceof W&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[_]&&isObjectInFrustum(e,a)&&(e.visible=!1,g.push(e),e.material.uniforms[_].value=this.sceneColorRenderTarget.texture),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[z])e.material.uniforms[z].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[z]&&(s.uniforms[z].value=t)});const h=new Map,d=new Map;if(K(this.scene,e=>{if(e instanceof i.Sprite||e.isPoints||e.isLine||e.isTransformControls||e.isTransformControlsGizmo)return d.set(e,e.visible),e.visible=!1,!1;if(e instanceof o)if(h.set(e,e.material),Array.isArray(e.material)){e.material=e.material.slice();for(let s=0;s<e.material.length;s++)e.material[s]=this.createGBufferMaterial(e.material[s]),e.material[s]instanceof c&&null!=e.material[s].uniforms[z]&&(e.material[s].uniforms[z].value=t)}else e.material=this.createGBufferMaterial(e.material),e.material instanceof c&&null!=e.material.uniforms[z]&&(e.material.uniforms[z].value=t)}),this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderer.render(this.scene,this.camera),this.renderer.setRenderTarget(null),h.forEach((e,t)=>{t.material=e}),d.forEach((e,t)=>{t.visible=e}),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)}p.forEach(e=>e.visible=!0),m.forEach(e=>e.visible=!0),g.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=t),this.volumetricFogPass&&this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene);try{!this.paused&&this.running&&(this.render(n),this.showStats&&l?.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(x)},1e3/this.fpsCap):requestAnimationFrame(x))};!0===this.options.enableXR?this.renderer.setAnimationLoop(x):requestAnimationFrame(x)}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t}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;if(null==this.camera)return;const o=this.camera.getWorldPosition(me);let h=[];for(const e of this.postProcessVolumes){if(!ce(e.object))continue;let l=e.blendWeight??1;const c=e.distanceToPoint(o);c>e.blendRadius||(e.blendRadius>0&&(l*=J(1-c/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,null!=t.envTexture&&(this.scene.environment=this.getEnvTexture(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&&isObjectInFrustum(t,de)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.options.bloom,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1,this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=Q(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===ne.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=ne:(e.visible=!1,this.bloomHidden.push(e))}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof c&&(e.uniforms[V].value=this.gRenderTarget.depthTexture,this.camera instanceof l&&(null!=e.uniforms[G]&&(e.uniforms[G].value=this.camera.near),null!=e.uniforms[O]&&(e.uniforms[O].value=this.camera.far)))}initResolutionUniform(e){e instanceof c&&null!=e.uniforms[k]&&e.uniforms[k].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};le=e=t([U(),s("design:paramtypes",[HTMLElement,Object])],le);export{le as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const he=.05;function ce(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}L.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};const de=new i.Frustum,ue=new i.Box3,pe=new i.Matrix4;export function isObjectInFrustum(e,t){const s=ue.setFromObject(e);return t.intersectsBox(s)}const me=new i.Vector3;/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-resource-loader.d.ts","sourceRoot":"","sources":["../../src/scene/asset-resource-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6G,QAAQ,EAAE,OAAO,EAA+B,MAAM,OAAO,CAAC;AAIlL,OAAO,EAAE,KAAK,EAAY,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAY/D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,SAAS,CAAmE;IAEpF,OAAO,CAAC,SAAS,CAAsC;IACvD,OAAO,CAAC,SAAS,CAAsC;IACvD,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,UAAU,CAAyC;IAC3D,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,UAAU,CAAsC;IACxD,OAAO,CAAC,cAAc,CAAmD;IACzE,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,eAAe,CAAQ;IAE/B;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAiB;IACzC,OAAO,CAAC,kBAAkB,CAAgB;IAE1C,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;IAIhC,OAAO,C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,CAAC,mBAAmB,CAAsC;IACjE,OAAO,CAAC,sBAAsB;YAShB,QAAQ;IAuCtB,OAAO,CAAC,eAAe,CAAoB;IAC3C,OAAO,CAAC,kBAAkB;YAyEZ,WAAW;IAmCzB;;;;;OAKG;IACI,UAAU;CAOlB;AAgBD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,iBAAiB,CAAC;IACzB,UAAU,EAAE,KAAK,CAAC,aAAa,EAAE,CAAA;CAClC;AAED,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,eAAe,CAAC,EAAE,cAAc,EAAE,CAAA;IAClC,OAAO,CAAC,EAAE,0BAA0B,CAAA;CACrC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAInD;AAiFD,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{AudioLoader as e,BufferGeometry as t,Group as s,LoadingManager as i,Mesh as r,Object3D as a,TextureLoader as n}from"three";import{GLTFLoader as o,MTLLoader as h,OBJLoader as l,DRACOLoader as c,LUTCubeLoader as d}from"three-stdlib";import{FBXLoader as u}from"three-stdlib";import{cloneMesh as
|
|
1
|
+
import{AudioLoader as e,BufferGeometry as t,Group as s,LoadingManager as i,Mesh as r,Object3D as a,TextureLoader as n}from"three";import{GLTFLoader as o,MTLLoader as h,OBJLoader as l,DRACOLoader as c,LUTCubeLoader as d}from"three-stdlib";import{FBXLoader as u}from"three-stdlib";import{cloneMesh as p}from"../utils/mesh.js";import{pathJoin as m}from"../utils/files.js";import{Subject as f,firstValueFrom as g}from"rxjs";import{importCollisionShapes as w,isCollisionMesh as y}from"./collision/collision-shape-import.js";import*as x from"three";import{iterateMaterials as M}from"../utils/materials.js";import{BufferGeometryUtils as L,EXRLoader as b,KTX2Loader as v,TGALoader as A,UltraHDRLoader as T}from"three/examples/jsm/Addons.js";import{disposeScene as C}from"../utils/three/cleanup.js";const R=new c;R.setDecoderConfig({type:"js"}),R.setDecoderPath("/assets/draco/");const S=["glb","gltf","fbx","obj"];export class AssetResourceLoader{onError(e){console.error(e)}constructor(){this.cache=new Map,this.textureCache=new Map,this.loadingManager=new i,this.glbLoader=new o(this.loadingManager).setDRACOLoader(R),this.fbxLoader=new u(this.loadingManager),this.objLoader=new l(this.loadingManager),this.textureLoader=new n(this.loadingManager),this.tgaLoader=new A(this.loadingManager),this.exrLoader=new b(this.loadingManager),this.cubeLoader=new d(this.loadingManager),this.hdrLoader=new T(this.loadingManager),this.ktx2Loader=new v(this.loadingManager),this._textureLoader=new x.ImageBitmapLoader(this.loadingManager),this.audioLoader=new e(this.loadingManager),this.initialisedKtx2=!1,this._retrievedMeshes=[],this._retrievedTextures=[],this.makeReady=new f,this.ready=g(this.makeReady),this._texturePromises=new Map,this.asyncMeshResults=new Map,this.asyncAudioResults=new Map,this.collisionShapeCache=new Map,this.optimizedMeshes=new Set}initKtx2(e){this.initialisedKtx2=!0;null!=getElectronArg("windowId")||import.meta.url.includes(".vite")?this.ktx2Loader.setTranscoderPath("/assets/basis/"):this.ktx2Loader.setTranscoderPath(new URL("../assets/basis/",import.meta.url).href),this.ktx2Loader.detectSupport(e)}setDataDir(e){this.basePath=m(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){const t=getElectronArg("windowId");return null!=t||import.meta.url.includes(".vite")?m(this.basePath,e)+(null!=t?`?windowId=${t}`:""):new URL(m("..",this.basePath,e),import.meta.url).href}async getTexture(e){if(!e||!e.fileKey)return null;if(this._texturePromises.has(e.id))return this._texturePromises.get(e.id);const t=this._getTexture(e).finally(()=>{this._texturePromises.delete(e.id)});return this._texturePromises.set(e.id,t),t}async _getTexture(e){if(null==e||null==e.fileKey)return null;if(await this.ready,this.textureCache.has(e.id)){const t=this.textureCache.get(e.id);t.dispose(),null!=e.texture&&(t.flipY!==e.texture?.flipY?(t.needsUpdate=!0,t.flipY=e.texture?.flipY??!0):t.wrapS!==j(e.texture?.wrapS)?(t.needsUpdate=!0,t.wrapS=j(e.texture?.wrapS)):t.wrapT!==j(e.texture?.wrapT)&&(t.wrapT=j(e.texture?.wrapT),t.needsUpdate=!0))}else try{await this._getTextureLoader(e.fileKey).loadAsync(this.getUri(e.fileKey)).then(t=>(t.texture3D?t=t.texture3D:(t.wrapS=j(e.texture?.wrapS),t.wrapT=j(e.texture?.wrapT),t.flipY=e.texture?.flipY??!0),this.textureCache.set(e.id,t),this._retrievedTextures.push(t),t))}catch(t){return console.warn("Failed to load texture "+e.name,t),null}return this.textureCache.get(e.id)}_getTextureLoader(e){return e?.toLowerCase().endsWith(".tga")?this.tgaLoader:e?.toLowerCase().endsWith(".ktx2")?this.ktx2Loader:e?.toLowerCase().endsWith(".exr")?this.exrLoader:e?.toLowerCase().endsWith(".cube")?this.cubeLoader:this.textureLoader}clearCache(e){"mesh"===e.type&&Array.from(this.cache.keys()).forEach(t=>{t.startsWith(e.fileKey)&&this.cache.delete(t)})}async getMesh(e,t){if(await this.ready,null==e)return console.error("No asset was provided"),{scene:new s,animations:[]};if(!S.includes(e.fileFormat?.toLowerCase()))return console.error("Unsupported mesh file format "+e.fileFormat,e),{scene:new s,animations:[]};const i=e.fileKey+(!0===t?.mergeGeomtries?"1":"0");if(!this.cache.has(i))try{this.asyncMeshResults.has(i)||this.asyncMeshResults.set(i,this.loadMesh(e).finally(()=>this.asyncMeshResults.delete(i))),this.cache.set(i,await this.asyncMeshResults.get(i))}catch(e){return this.onError(e),{scene:new s,animations:[]}}const a=this.cache.get(i).scene,n=this.computeCollisionShapes(e,a);!0===t?.mergeGeomtries&&this.optimizeDrawGroups(a);const o=p(a),h=this.cache.get(i).animations;o.traverse(e=>{e instanceof r&&e.material instanceof Array&&(e.material=e.material.slice())});const l=new AssetMeshInstance;l.add(o),l.collisionShapes=n,l.animations=h;const c=e.receiveShadow??!0,d=e.castShadow??!1;return o.traverse(e=>{e.castShadow=d,e.receiveShadow=c}),{scene:l,animations:h}}async getAudio(e){await this.ready;const t=e.fileKey;if(this.asyncAudioResults.has(t))return await this.asyncAudioResults.get(t);const s=this.audioLoader.loadAsync(this.getUri(e.fileKey)).finally(()=>{setTimeout(()=>{this.asyncAudioResults.delete(t)},1e3)});return this.asyncAudioResults.set(t,s),s}computeCollisionShapes(e,t){const s=e.id+e.mesh?.collisions?.shapeType;return this.collisionShapeCache.has(s)||this.collisionShapeCache.set(s,w(t,e)),this.collisionShapeCache.get(s)}async loadMesh(e){return await this.ready,await this.loadByAsset(e).then(e=>(e.scene.traverse(e=>{e instanceof r&&e.material&&function(e){let t=e.material;if(null==t)return;Array.isArray(t)?e.material=t.map(P):e.material=P(t)}(e),y(e)?e.visible=!1:e instanceof r&&e.geometry instanceof t&&(e.geometry.hasAttribute("normal")||e.geometry.computeVertexNormals())}),this._retrievedMeshes.push(e.scene),e.scene=function(e,t){let s=!1;if(t.traverseVisible(e=>{D.test(e.name)&&(s=!0)}),!s)return t;const i=new x.LOD,r=[t];for(;r.length>0;){const e=r.shift(),t=e.name.match(D);if(null!=t){const s=parseInt(t[1]);0===s?i.addLevel(e,0):console.warn(`Skipping LOD level ${s} for now as LOD is not fully supported`)}else r.push(...e.children)}return i}(0,e.scene),e))}optimizeDrawGroups(e){if(this.optimizedMeshes.has(e.uuid))return;this.optimizedMeshes.add(e.uuid);let s=!0,i=0,a=0;if(e.traverse(e=>{if(e instanceof r&&e.geometry instanceof t&&!y(e)){i++;const t=Object.keys(e.geometry.attributes).length;t!==a&&0!==a&&(s=!1),a=t}else(e instanceof x.SkinnedMesh||e instanceof x.Bone)&&(s=!1)}),i>1&&s){const s=[],i=[],a=[];e.updateWorldMatrix(!0,!0),e.traverse(e=>{e instanceof r&&e.geometry instanceof t&&!y(e)&&!Array.isArray(e.material)&&(e.updateWorldMatrix(!0,!0),s.push(e.geometry.clone().applyMatrix4(e.matrixWorld)),i.push(e.material),a.push(e))});for(const e of a)e.removeFromParent();const n=L.mergeGeometries(s,!0),o=[];let h=0;e:for(const e of i){for(const t of o)if(t.m.id===e.id){t.indices.push(h),h++;continue e}o.push({m:e,indices:[h]}),h++}let l=0;for(const e of o){for(const t of e.indices)n.groups[t].materialIndex=l;l++}e.add(new r(n,o.map(e=>e.m)))}e.traverse(e=>{if(e instanceof r&&e.geometry instanceof t){const t=e.geometry;Array.isArray(e.material)&&t.groups.length>1&&t.groups.length>e.material.length&&L.mergeGroups(t)}})}async loadByAsset(e){this.fbxLoader;const t=this.getUri(e.fileKey);switch(e.fileFormat){case"glb":case"gltf":return this.glbLoader.loadAsync(t).then(e=>({scene:e.scene,animations:e.animations}));case"fbx":return this.fbxLoader.loadAsync(t).then(e=>({scene:e,animations:e.animations}));case"obj":if(null!=e.materialLib){const t=new h;t.materialOptions={normalizeRGB:!1};const s=await t.loadAsync(this.getUri(e.materialLib));this.objLoader.setMaterials(s)}return this.objLoader.loadAsync(t).then(e=>(_(e),e)).then(e=>({scene:e,animations:e.animations}))}}disposeAll(){this.cache.clear(),this._retrievedMeshes.forEach(e=>C(e)),this._retrievedTextures.forEach(e=>e.dispose()),this._retrievedMeshes.length=0,this._retrievedTextures.length=0}}function _(e){if(e instanceof r)for(const t of M(e.material))t instanceof x.MeshPhongMaterial&&!t.color.isLinear&&(t.color.isLinear=!0);e.children?.forEach(_)}export class AssetMeshInstance extends a{}export function getElectronArg(e){const t=`--${e}=`,s=window.process?.argv.find(e=>e.startsWith(t));return s?.substring(t.length)}function j(e){switch(e){case"clamp":return x.ClampToEdgeWrapping;case"repeat":return x.RepeatWrapping;case"mirror":return x.MirroredRepeatWrapping}return x.RepeatWrapping}new x.Matrix4;const D=/_LOD(\d+)$/;function P(e){if("MeshStandardMaterial"===e.type||"MeshPhongMaterial"===e.type||"MeshPhysicalMaterial"===e.type){const t=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","specularMap","alphaMap","envMap","combine","reflectivity","refractionRatio","wireframe","wireframeLinewidth","skinning","morphTargets","morphNormals","visible","opacity","transparent","side","depthTest","depthWrite","alphaTest"],s={};for(const i of t)void 0!==e[i]&&(s[i]=e[i]);!s.color||s.color instanceof x.Color||(s.color=new x.Color(s.color));const i=new x.MeshLambertMaterial(s);return i.userData={...e.userData??{}},i.name=e.name,i}return e}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"materializer.d.ts","sourceRoot":"","sources":["../../src/scene/materializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAGE,KAAK,EAEZ,QAAQ,EAMR,QAAQ,EAGR,KAAK,EAIL,OAAO,EAER,MAAM,OAAO,CAAA;AAad,OAAO,EAAC,iBAAiB,EAAU,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAEvD,OAAO,EAAkB,eAAe,EAA6D,MAAM,sBAAsB,CAAA;AACjI,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAO/C,OAAO,EAA2B,aAAa,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAClG,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAIlF,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAqB,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAQrD,OAAO,EAC0B,oBAAoB,EACpD,MAAM,0BAA0B,CAAA;AAMjC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,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CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,WA+C3E;AA0BD,eAAO,MAAM,iCAAiC,+BAa5C,CAAA;AAkDF,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,mBA8E9L;AAwED,KAAK,kBAAkB,GAAG;IACxB,gBAAgB,EAAE,aAAa,EAAE,CAAA;CAClC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{ConvexPolyhedronCollisionShape as a}from"@hology/core";import{Subject as s}from"rxjs";import*as r from"three";import{BoxGeometry as i,Color as n,Euler as o,Fog as l,FogExp2 as c,Group as h,Material as d,Matrix4 as m,Mesh as p,MeshLambertMaterial as u,MeshPhongMaterial as f,MeshStandardMaterial as g,Object3D as y,PointLight as w,Quaternion as v,Scene as b,Texture as A,Vector2 as S,Vector3 as M,Vector4 as j}from"three";import x,{SpriteRenderer as P}from"@hology/nebula";import{bool as I,BooleanNode as D,float as C,FloatNode as E,NodeShaderMaterial as V,rgb as O,RgbNode as k,Texture2dLookupNode as N,textureSampler2d as F,vec2 as T,Vec2Node as z,vec3 as B,Vec3Node as _,vec4 as L}from"three-shader-graph";import{Service as W}from"typedi";import{VfxActor as $}from"../effects/vfx/vfx-actor.js";import{VisualEffect as R}from"../effects/vfx/vfx-param.js";import{BaseActor as G}from"../gameplay/actors/actor.js";import U from"../gameplay/actors/builtin/index.js";import{PhysicsBodyType as H,ThreeBlendingMode as J,withInjectionContext as q}from"../gameplay/index.js";import{RenderingView as X}from"../rendering.js";import{Sampler2DNode as Y}from"../shader-nodes/index.js";import{LambertShader as Z}from"../shader/builtin/lambert-shader.js";import{LandscapeCompositeShader as K}from"../shader/builtin/landscape-composite-shader";import{LandscapeShader as Q}from"../shader/builtin/landscape-shader.js";import{StandardShader as ee}from"../shader/builtin/standard-shader.js";import{UnlitShader as te}from"../shader/builtin/unlit-shader.js";import{extractShaderParameters as ae}from"../shader/parameter.js";import{ArrayMap as se,groupBy as re}from"../utils/collections.js";import{iterateMaterials as ie}from"../utils/materials.js";import{filterChildrenShallow as ne,filterSceneShallow as oe,findFirstVisibleObject as le}from"../utils/three/traverse.js";import{AssetMeshInstance as ce,AssetResourceLoader as he}from"./asset-resource-loader.js";import{isCollisionMesh as de}from"./collision/collision-shape-import.js";import{BoxCollisionShape as me,PhysicalShapeMesh as pe}from"./collision/collision-shape.js";import{LandscapeManager as ue}from"./landscape/landscape-manager.js";import{initLandscape as fe}from"./landscape/landscape.js";import{SectionGrid as ge,smoothNormalsCrossMeshes as ye}from"./landscape/utils.js";import{createGrassFoliageMaterial as we}from"./materials/grass-foliage.js";import{createGrassMaterial as ve}from"./materials/grass.js";import{getMaterialAttribute as be}from"./materials/utils/material-painting.js";import{createWaterMaterial as Ae}from"./materials/water.js";import{SerializedParamType as Se}from"./model.js";import{ShapeLibrary as Me,ShapeLibraryKeys as je}from"./objects/shapes.js";import{ambientLightName as xe,createSky as Pe,defaultSkyMaterial as Ie}from"./sky.js";import{Curve2 as De}from"../utils/curve.js";import{DecalUnlitShader as Ce}from"../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as Ee}from"../shader/builtin/decal-standard-shader.js";import{ColorLayer as Ve,defaultValueColorLayer as Oe,defaultValueMaskLayer as ke,MaskLayer as Ne}from"../shader/color-layer.js";import{LayeredShader as Fe}from"../shader/builtin/layered-shader";import{isColorLayerSerialized as Te}from"../shader/color-layer";import{FogVolume as ze}from"../rendering/fog/fog-volume-actor.js";import{UnscaledSprite as Be}from"../utils/three/unscaled-sprite.js";import{ToonShader as _e}from"../shader/builtin/toon-shader.js";const Le={},We=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),$e=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPad"))&&!!navigator.userAgent.match(/AppleWebKit/)&&!navigator.userAgent.match(/CriOS/);export const shapeDefaultColor="#aaaaaa";export class SceneMaterializerLoader{constructor(e,t,a){this.dataProvider=e,this.assetsService=t,this.assetManagerService=a}get(e,t){return new Re(e,this.dataProvider,this.assetsService,this.assetManagerService,t,[],[],{create:()=>null,initActor:async()=>{}})}}let Re=class{constructor(e,t,a,i,n,o,l,c){this.scene=e,this.dataProvider=t,this.assetsService=a,this.assetManagerService=i,this.renderingView=n,this.shaders=o,this.actorTypes=l,this.actorProvider=c,this.objectMap=new Map,this.sceneObjectMap=new Map,this.components=[],this.landscapeManagers=[],this.materializedActors=new Map,this.inEditor=!0,this.updated$=new s,this.removed$=new s,this.error$=new s,this.editorActorParamSnapshot=new Map,this.assets=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.pmremGeneratorResults=new WeakMap,this.prefabInstanceChain=[],this.geometryCache=new Map,this.collisionShapeCache=new Map,this.originalFog=null,t.onCreate(e=>this.update(e)),t.onUpdate(e=>this.update(e)),t.onRemove(e=>this.remove(e)),this.createAssetSubscription=a.onCreate.subscribe(e=>{this.assets.set(e.id,e)}),this.updateSubscription=a.onUpdate.subscribe(async t=>{this.assets.set(t.id,t),"material"==t.type?e.traverse(e=>{if(e instanceof r.Mesh)if(Array.isArray(e.material))for(let a=0;a<e.material.length;a++)this.refreshMaterial(e,e.material[a],t,a);else this.refreshMaterial(e,e.material,t)}):"mesh"==t.type?(this.findByAssetId(t.id).forEach(e=>{this.remove(e.userData.src),this.materializeAndInitActor(e.userData.src)}),this.landscapeManagers.forEach(e=>{const a=e.source?.grass?.layers?.some(e=>e.meshes.some(e=>e.assetId===t.id));a&&e.queueRefreshScatter(this.renderingView?.camera.position??new M,!0)})):"prefab"===t.type?this.findByAssetId(t.id).forEach(e=>{const t=e.userData.src;this.remove(t),this.materializeAndInitActor(t)}):"vfx"===t.type&&this.dataProvider.getObjects().forEach(e=>{Qe(e,(e,a)=>{"vfx"===e.type&&e.assetId===t.id&&(this.remove(e),this.materializeAndInitActor(e))})})})}async refreshMaterial(e,t,a,s){const r=t?.userData?.assetId;if(r!==a.id){const e=this.assets.get(r);let t=!1;if(null!=e)for(const s of Object.values(e.material.shaderParams)){if(s.type===Se.Material&&s.value===a.id){t=!0;break}if(s.type===Se.Array&&"element"in s&&s.element===Se.Material&&s.value.includes(a.id)){t=!0;break}}if(!t)return}const i=await materialFromAsset(this.assets.get(r),this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1),n=i.userData;i.userData=t.userData,i.userData.hasBloom=n.hasBloom,i.userData.reflective=n.reflective,i.userData.outlineParameters=n.outlineParameters,null!=s?at(e.material[s],i)||(e.material[s]=i):at(e.material,i)||(e.material=i,e===this.sky&&this.applySkySettings(e.material))}getTopLevelActors(){return Array.from(this.materializedActors.entries()).filter(([e,t])=>!e.includes("/")).map(([,e])=>e)}get actorInstances(){return Array.from(this.materializedActors.values())}async initTextures(){const e=[];if(await Promise.all(this.dataProvider.getObjects().filter(e=>"shape_mesh"===e.type||"asset_mesh"===e.type).filter(e=>null!=e.materialAssignments).flatMap(e=>e.materialAssignments).map(async t=>{const a=this.assets.get(t.materialId);if(null!=a)for(const t of Object.values(a.material.shaderParams))if(t.type===Se.Texture&&"string"==typeof t.value){const a=this.assets.get(t.value),s=await this.assetManagerService.getTexture(a);null!=s&&e.push(s)}})),0!==e.length&&this.renderingView){console.log(`Initializing ${e.length} textures`),console.time("Init textures");for(const t of e)this.renderingView.renderer.initTexture(t);console.timeEnd("Init textures")}}async prefetchAssets(){const e=Array.from(new Set(this.dataProvider.getObjects().filter(e=>null!=e.assetId&&"asset_mesh"==e.type).filter(e=>e.assetId)));await Promise.all(e.map(e=>this.assetsService.getAsset(e.assetId).then(e=>{if(null!=e)return this.assetManagerService.getMesh(e)}))),this.initTextures()}async init(){await this.preInit(),Ue.clear(),He.clear(),await this.prefetchAssets(),await Promise.all(this.dataProvider.getObjects().map(e=>this.materialize(e))),await this.initActorsPostInit()}initActorsPostInit(e=this.getTopLevelActors(),t){const a=e.map(async e=>{const a=e.object.userData.src??e.object.userData._src;if("vfx"===a.type)return Promise.resolve();const s=await this.assetsService.getAsset(a.assetId),r={...s?.actor?.params??{},...a.actor?.params??{}},i=null!=t?new Map(Array.from(this.materializedActors.entries()).filter(([e,a])=>e.startsWith(t.sceneObjectChain.join("/"))&&e.split("/").length-1===t.sceneObjectChain.length).map(([e,t])=>[e.split("/").pop(),t])):this.materializedActors;for(const t of a.actor.innerParams??[])await this.applyActorComponentParams(e,t.path.slice(),t.params,i);const n=await prepareClassParameters(r,e.constructor,this.assetsService,this.assetManagerService,i,this.renderingView,this.shaders,this.actorProvider);Object.assign(e,n);try{return await this.actorProvider.initActor(e)}catch(e){console.error(`Failed to initiate actor (name="${a.name}", id=${a.id})`,e)}});return Promise.all(a)}addVfxChildActors(e,t=e){}async applyActorComponentParams(e,t,a,s){const r=t.length,i=t.shift();if(0==r){const t=await prepareClassParameters(a,null,this.assetsService,this.assetManagerService,s,this.renderingView,this.shaders,this.actorProvider);for(const[a,s]of Object.entries(t))null!=s&&(e[a]=s)}else null!=e[i]&&await this.applyActorComponentParams(e[i],t,a,s)}canObjectBeInstanced(e){return e.physics?.type!==H.dynamic&&"sky"!==e.type&&"global_fog"!==e.type&&"world_env"!==e.type}async canAssetBeInstanced(e){if(!this._canBeInstancedCache.has(e.assetId)){const t=await this.createFromAsset(e);if(null==t)return!1;const a=[];t.traverse(e=>{!de(e)&&e.isMesh&&a.push(e)});const s=1==a.length&&0==a[0].children.length,r=a[0]instanceof p&&null!=a[0].geometry.morphAttributes&&Object.keys(a[0].geometry.morphAttributes).length>0,i=!0;this._canBeInstancedCache.set(e.assetId,s&&i&&!r)}return this._canBeInstancedCache.get(e.assetId)}async preInit(){this.renderingView?.onLoop(()=>{null!=this.sky&&this.renderingView.camera.getWorldPosition(this.sky.position)}),this.assetsService.getAssets().then(e=>{for(const t of e)this.assets.set(t.id,t)})}shouldBeMaterialized(e){if(null!=this.detailTier&&"asset_mesh"===e.type&&null!=e.assetId){const t=this.assets.get(e.assetId);if(null!=t){const e=t.mesh?.detailTier;if(null!=e)return e<=this.detailTier}}return!0}async initWithInstancing(){await this.preInit(),await this.prefetchAssets(),Ue.clear(),He.clear();const e=[],t=new se,s=new se;for(const a of this.dataProvider.getObjects())await Qe(a,async(a,r,i)=>{if(!this.shouldBeMaterialized(a))return;const o="asset_mesh"==a.type&&this.canObjectBeInstanced(a)&&await this.canAssetBeInstanced(a),l="shape_mesh"===a.type&&"landscape"!==a.shape&&a.physics?.type!==H.dynamic;if(o||l){if(r&&r.children?.length>0){const e=r.children.findIndex(e=>e.id===a.id);e>=0&&r.children.splice(e,1)}if(l){let e=a.shape+JSON.stringify(a.shapeParams??{})+a.castShadow+a.receiveShadow;const t=a.materialAssignments?.at(0)?.materialId,r=null!=t?this.assets.get(t):null;let o=null;if(null!=r&&"shader"!==r.material.type){if(e+=r.material.type+r.material.shader,null!=r.material.shaderParams){if(e+=Object.entries(r.material.shaderParams).filter(([e,t])=>"color"!=e).map(e=>JSON.stringify(e)).join(),null!=r.material.shaderParams.color){const e=r.material.shaderParams.color;e.type===Se.Color&&null!=e.value&&(o=new n(e.value))}}}else e+=t;s.push(e,{object:{...a,parentTransform:i},color:o})}else{const e=a.assetId+JSON.stringify(a.materialAssignments??[]);t.push(e,{...a,parentTransform:i})}}else null==r&&e.push({...a,parentTransform:i})});for(const e of t.values()){if(0==e.length)continue;const t=await this.createFromAsset(e[0]);if(null==t)continue;const s=await this.createInstancedMesh(e,t),r=new ce;r.add(s),r.userData.src=e[0],t instanceof ce&&(r.collisionShapes=t.collisionShapes),r.collisionShapes.forEach(e=>{e instanceof a&&e.mesh instanceof p&&(e.mesh=e.mesh.geometry)}),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}for(const e of s.values()){if(0==e.length)continue;const t=e[0].object,a=await this.createFromShape(t),s=le(a,e=>!de(e)&&null!=e.geometry),i=s.material.clone();null!=e[0].color&&null!=i.color&&(i.color=new n(16777215));const l=s.geometry;let c,h;!($e||i instanceof V||null==l.index)?(c=new r.BatchedMesh(e.length,l.getAttribute("position").count,l.index.count,i),c.perObjectFrustumCulled=!0,h=c.addGeometry(l)):c=new r.InstancedMesh(l,i,e.length),c.castShadow=a.castShadow??!0,c.receiveShadow=s.receiveShadow??!0;for(let t=0;t<e.length;t++){const a=e[t],s=(new r.Matrix4).compose((new M).fromArray(a.object.position),(new v).setFromEuler((new o).fromArray(a.object.rotation)),(new M).fromArray(a.object.scale)),i=(new m).copy(a.object.parentTransform).multiply(s);let n;n=c instanceof r.BatchedMesh?c.addInstance(h):t,c.setMatrixAt(n,i),null!=a.color&&c.setColorAt(n,a.color)}for(let t=0;t<e.length;t++){const s=e[t],r=new ce;r.userData.src=e[0],a instanceof pe&&(r.collisionShapes=[a.collisionShape]),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r),r.add(c),null==c.userData.hasCollision&&(c.userData.hasCollision=[]),c.userData.hasCollision[t]=!!s.object.collisionDetection}}await Promise.all(e.map(e=>this.materialize(e))),await this.initActorsPostInit()}async createInstancedMesh(e,t){const a=le(t,e=>!de(e)&&null!=e.geometry),s=await this.assetsService.getAsset(e[0].assetId);await this.applyMaterials(t,et(e[0].materialAssignments,s.materialAssignments)),a.updateMatrix();const i=a.geometry.clone(),n=a.material;let l,c;if(!($e||n instanceof V||!(i.groups.length<2)||Array.isArray(n)&&1!=n.length)){const t=Array.isArray(n)?n[0]:n,a=i.getAttribute("position").count;l=new r.BatchedMesh(e.length,a,null!=i.index?i.index.count:a,t),l.perObjectFrustumCulled=!0,c=l.addGeometry(i)}else l=new r.InstancedMesh(i,n,e.length);for(let t=0;t<e.length;t++){let s=t;l instanceof r.BatchedMesh&&(s=l.addInstance(c));const i=(new r.Matrix4).compose((new M).fromArray(e[t].position),(new v).setFromEuler((new o).fromArray(e[t].rotation)),(new M).fromArray(e[t].scale)),n=(new m).copy(e[t].parentTransform).multiply(i).multiply(a.matrixWorld);l.setMatrixAt(s,n),null==l.userData.hasCollision&&(l.userData.hasCollision=[]),l.userData.hasCollision[t]=!!e[t].collisionDetection}if(l.castShadow=e[0].castShadow??s.castShadow??!0,l.receiveShadow=e[0].receiveShadow??s.receiveShadow??!0,a.material instanceof d&&l.castShadow&&l.receiveShadow)if(Array.isArray(n))for(const e of n)e.side=r.FrontSide;else n.side=r.FrontSide;return l}remove(e){if(console.log("Remove scene object",e),"global_fog"==e.type)return void(this.scene.fog=this.originalFog);if("world_env"===e.type)this.resetWorldEnv(),this.worldEnvObj=null;else if("actor"==e.type||"vfx"===e.type){const t=this.materializedActors.get(e.id);null!=t?(t.disposed.next(!0),t.onEndPlay()):console.warn("Failed to remove actor",e)}else"prefab"===e.type&&this.materializedActors.forEach((t,a)=>{a.startsWith(e.id)&&(t.disposed.next(!0),t.onEndPlay()),this.materializedActors.delete(a)});const t=this.sceneObjectMap.get(e.id);t?.parent.remove(t),this.sceneObjectMap.delete(e.id),this.components.filter(t=>t.object.userData.src?.id===e.id).forEach(e=>this.components.splice(this.components.indexOf(e,1))),this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(e=>{e.clear(),e.stop(),this.landscapeManagers.splice(this.landscapeManagers.indexOf(e,1))}),this.removed$.next({object:t,source:e})}deleteSceneObject(e){const t=this.sceneObjectMap.get(e.id);if(this.scene.remove(t),"landscape"==e.type){const t=this.landscapeManagers.findIndex(t=>t.source.id===e.id);if(t>-1){const e=this.landscapeManagers.splice(t,1)[0];e.clear(),e.stop()}}}findByAssetId(e){return oe(this.scene,t=>t.userData.src?.assetId==e,e=>null!=e.userData.src)}applyMaterials(e,t){return null==t?Promise.resolve([]):Promise.all(t.filter(e=>"null"!==e.materialId).map(t=>this.applyMaterial(e,t)))}async applyMaterial(e,t){await applyMaterial(e,t,e=>{const t=this.assets.get(e);if(null!=t)try{return materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders)}catch(e){console.error("Failed to apply material",e)}},this._originalMaterials)}unapplyMaterials(e){e.traverse(async e=>{if(e instanceof p)if(e.material instanceof Array)for(let t=0;t<e.material.length;t++)e.material[t]=this._originalMaterials.get(e.id+"#"+t)??e.material[t];else e.material=this._originalMaterials.get(e.id)??e.material})}updateActors(e){console.log("update actors"),this.actorTypes=e;const t=new Set(Object.values(U));oe(this.scene,e=>e.userData.src?.id&&"actor"===e.userData.src.type&&this.materializedActors.has(e.userData.src?.id)&&!t.has(e.userData.src.actor.type)).forEach(async e=>{this.remove(e.userData.src),await this.materializeAndInitActor(e.userData.src)})}updateShaders(e){this.shaders=e;for(const[e,t]of Ue.entries())t.userData.customShaderName&&Ue.delete(e);this.landscapeManagers.forEach(t=>t.updateShaders(e)),oe(this.scene,e=>!0).forEach(e=>{e.traverse(async e=>{if(e instanceof p)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++){const a=e.material[t].userData?.customShaderName;if(null!=a){const a=this.assets.get(e.material[t].userData.assetId);this.refreshMaterial(e,e.material[t],a,t)}}else{const t=e.material.userData?.customShaderName;if(null!=t){const t=this.assets.get(e.material.userData.assetId);this.refreshMaterial(e,e.material,t)}}})})}async update(e){if("sky"===e.type&&null!=this.sky&&null!=this.sky.parent)return void this.updateSky(e);if("world_env"===e.type&&null!=this.worldEnvObj)return void this.updateWorldEnv(e);const t=this.sceneObjectMap.get(e.id);if(t){let s=!1;if(t.traverseAncestors(e=>{"_hology_transform_group"===e.name&&(s=!0)}),!s){const a=this.findParent(e);null!=a&&a.uuid!=t.uuid?a.attach(t):console.error("Parent is wrong")}if("prefab"!==e.type&&"group"!==e.type){this.unapplyMaterials(t);this.inEditor&&e.hidden&&!1?t.traverse(e=>{e instanceof p&&(e.material.wireframe=!0)}):t.traverse(e=>{e instanceof p&&(e.material.wireframe=!1)})}if("asset_mesh"===e.type){const a=this.assets.get(e.assetId);et(e.materialAssignments,a.materialAssignments).forEach(e=>this.applyMaterial(t,e))}else"shape_mesh"===e.type&&this.applyMaterials(t,e.materialAssignments);if(s||(null!=e.position&&t.position.fromArray(e.position),null!=e.scale&&t.scale.fromArray(e.scale),null!=e.rotation&&t.rotation.fromArray(e.rotation)),this.applyVertexMaterials(e,t),"light"==e.type)if("point"==e.light.type){const a=t;a.color=new n(e.light.point.color),a.intensity=e.light.point.intensity,a.decay=e.light.point.decay,a.castShadow=e.light.point.castShadow,a.distance=Math.max(e.light.point.distance,0),a.userData.volumetricIntensity=e.light.point.volumetricIntensity}else if("spot"==e.light.type){const a=t;a.color=new n(e.light.spot.color),a.intensity=e.light.spot.intensity,a.decay=e.light.spot.decay,a.angle=e.light.spot.angle,a.penumbra=e.light.spot.penumbra,a.castShadow=e.light.spot.castShadow,a.distance=Math.max(e.light.spot.distance,0),a.userData.volumetricIntensity=e.light.spot.volumetricIntensity}else"directional"===e.light.type?this.applyDirectionalLight(e.light.directional,e):"ambient"===e.light.type&&this.applyDirectionalAmbientLight(t,e.light.ambient,e);else if("landscape"===e.shape){const a=this.landscapeManagers.find(t=>t.source.id===e.id).source.landscape.options.density!==e.landscape.options.density;if(this.inEditor&&a){this.remove(e);const t=await this.materializeAndInitActor(e);return void this.updated$.next({object:t,source:e})}this.applyHeightMaps(t,e.landscape.heightMaps),this.inEditor&&this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(t=>{t.updateSource(e),t.queueRefreshScatter(this.renderingView.camera.position,!0,e=>!0)})}else if("global_fog"===e.type){const t=(this.scene.fog instanceof c?"density":"linear")!==e.fog.type;this.scene.fog=Ze(e.fog),t&&(a=this.scene).traverse(e=>{if(e instanceof p){const t=e.material;t instanceof V&&(a.fog instanceof l?(t.uniforms.fogFar.value=a.fog.far,t.uniforms.fogNear.value=a.fog.near):a.fog instanceof c&&(t.uniforms.density={value:a.fog.density}),t.needsUpdate=!0,t.uniformsNeedUpdate=!0)}}),this.fixFogColor()}else if("actor"===e.type){if(this.materializedActors.has(e.id)){const t=this.materializedActors.get(e.id);if(t instanceof ze){const a=await prepareClassParameters(e.actor.params,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,[],this.actorProvider);return void Object.assign(t,a)}const a=this.editorActorParamSnapshot.get(e.id);null!=a&&a===JSON.stringify(e.actor)||s||(this.remove(e),await this.materializeAndInitActor(e))}}else if("shape_mesh"===e.type){const a=await this.createMeshByShape(e.shape,t.material,e.shapeParams);t instanceof pe&&(t.geometry=a.geometry,t.collisionShape=a.collisionShape)}("asset_mesh"===e.type||"shape_mesh"===e.type&&"landscape"!==e.shape)&&Ge(t,e.castShadow,e.receiveShadow),e.name&&e.name.length>0&&(t.name=e.name),this.updated$.next({object:t,source:e})}else{const t=await this.materializeAndInitActor(e);this.updated$.next({object:t,source:e})}var a;this.renderingView.renderer.shadowMap.needsUpdate=!0}async materializeAndInitActor(e,t=this.findParent(e)){const a=await this.materialize(e,t);return Qe(e,async e=>{if("actor"===e.type){const t=this.materializedActors.get(e.id);null!=t?await this.initActorsPostInit([t]):console.error(`Something went wrong when creating actor ${e.id}`)}}),a}findParent(e){const t=this.dataProvider.getObjects().flatMap(t=>t.id===e.id?null:ne(t,t=>t.children?.some(t=>t.id===e.id),()=>!0))[0];return null==t?this.scene:null!=t?oe(this.scene,e=>e.userData?.src?.id===t.id,e=>null!=e.userData?.src)[0]:void 0}fixFogColor(){!0===this.renderingView.options.enableOutlines&&(this.scene.fog.color=new n(this.scene.fog.color))}findMeshWithGeometry(e){let t;return e.traverse(e=>{e instanceof p&&e.geometry&&(t=e)}),t}applyVertexMaterials(e,t){if(null==e.vertexMaterials||0===e.vertexMaterials.length)return;let a=1;for(const t of e.vertexMaterials)a=Math.max(t.w.length,a);const s=re(e.vertexMaterials,e=>e.m);t.traverse(e=>{if(e instanceof p){if(null==e.geometry)return;if(st(be(e,0,!1)),a>0){st(be(e,0,!1))}}});const r=new Set;for(const[e,i]of s.entries()){const s=null!=e?t.getObjectByName(e):this.findMeshWithGeometry(t);let n=!1;if(null==s||null==s.geometry)return void console.warn(`Failed to apply vertex materials on mesh with name "${e}"`);const o=be(s,0,!0);st(o);for(const e of i)o.setX(e.i,e.w[0]??0),o.setY(e.i,e.w[1]??0),o.setZ(e.i,e.w[2]??0),o.setW(e.i,e.w[3]??0),n=!0;if(a>0){const e=be(s,4,!0);st(e);for(const t of i)e.setX(t.i,t.w[4]??0),e.setY(t.i,t.w[5]??0),e.setZ(t.i,t.w[6]??0),e.setW(t.i,t.w[7]??0),e.needsUpdate=!0,n=!0}n&&r.add(e)}this.inEditor&&this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,e=>r.has(e.name)))}async materialize(e,t,a=!1,s){if(!this.shouldBeMaterialized(e))return;let r,n;switch(e.type){case"asset_mesh":r=await this.createFromAsset(e);break;case"shape_mesh":r=await this.createFromShape(e);break;case"light":r=await this.createLight(e);break;case"particles":r=await this.createParticleSystem(e),e.collisionDetection=!1;break;case"global_fog":this.scene.fog=Ze(e.fog),this.fixFogColor(),r=new h;break;case"sky":this.sky=Pe(),this.updateSky(e),r=this.sky;break;case"world_env":this.updateWorldEnv(e),r=new h,this.worldEnvObj=r;break;case"actor":({object:r,actor:n}=await this.createFromActor(e,s));break;case"group":r=new h;break;case"prefab":r=await this.createFromPrefab(e,s);break;case"vfx":r=await this.createFromVfx(e,s);break;default:if(this.inEditor)throw new Error("unknown type "+e.type);console.warn(`Failed to materialize object. Unknown type '${e.type}'. This might be because the hology/core library is not compatible with the editor version.`)}if(null!=r){if(e.name&&e.name.length>0&&(r.name=e.name),null!=e.position&&r.position.fromArray(e.position),null!=e.scale&&r.scale.fromArray(e.scale),null!=e.rotation&&r.rotation.fromArray(e.rotation),a?r.userData._src=e:r.userData.src=e,null!=n&&(r.userData.actor=n),this.inEditor,this.inEditor){let e=null;r instanceof pe&&(e=function(e){if(e instanceof me)return new p(new i(...e.offset.toArray()),Ke);return null}(r.collisionShape)),null!=e&&(e.layers.disable(0),e.layers.enable(18),e.scale.multiplyScalar(1.1),r.add(e))}if(this.objectMap.set(r.uuid,e),this.sceneObjectMap.set(e.id,r),e.physics?.type!==H.dynamic||null==t||this.inEditor?null==t?this.scene.add(r):t?.add(r):(t.add(r),r.getWorldPosition(r.position),r.getWorldQuaternion(r.quaternion),r.getWorldScale(r.scale),this.scene?.attach(r)),null!=e.children&&await Promise.all(e.children?.map(e=>this.materialize(e,r,a))),this.inEditor||"asset_mesh"!=e.type&&"shape_mesh"!==e.type||"landscape"===e.shape||null!=e.physics?.type&&e.physics.type==H.dynamic||Ye(r),null!=this.renderingView)return this.renderingView.renderer.shadowMap.needsUpdate=!0,r;console.warn("RenderingView not found in materializer. No idea what called this")}}updateWorldEnv(e){this.renderingView.aoPass.enabled=e.worldEnv.ao.enabled,this.renderingView.aoPass.blendIntensity=e.worldEnv.ao.blendIntensity,this.renderingView.aoPass.updateGtaoMaterial(e.worldEnv.ao),this.renderingView.aoPass.output=!0===e.worldEnv.ao.onlyAO?5:0;const t=e.worldEnv.toneMapping;null!=t&&(this.renderingView.renderer.toneMapping=t.mapping??0,this.renderingView.renderer.toneMappingExposure=t.exposure??1);const a=e.worldEnv.environment;null!=a&&null!=a.textureId?this.assetManagerService.getTexture(this.assets.get(a.textureId)).then(e=>{null==this.pmremGenerator&&(this.pmremGenerator=new r.PMREMGenerator(this.renderingView.renderer),this.pmremGenerator.compileEquirectangularShader()),this.pmremGeneratorResults.has(e)||this.pmremGeneratorResults.set(e,this.pmremGenerator.fromEquirectangular(e).texture);const t=this.pmremGeneratorResults.get(e);this.renderingView.scene.environment=t,this.renderingView.scene.environmentIntensity=a.intensity??1}):this.renderingView.scene.environment=null}resetWorldEnv(){this.renderingView.aoPass.enabled=!1,this.renderingView.aoPass.blendIntensity=1,this.renderingView.aoPass.output=0,this.renderingView.renderer.toneMapping=0,this.renderingView.renderer.toneMappingExposure=1}async updateSky(e){if(null==e?.sky?.materialId)return void(this.sky.material=Ie);const t=await this.assetsService.getAsset(e.sky.materialId),a=await materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);this.applySkySettings(a),null!=this.sky?this.sky.material=a:console.warn("No sky has been created")}applySkySettings(e){e.side=r.BackSide,(e instanceof g||e instanceof r.MeshBasicMaterial||e instanceof r.ShaderMaterial)&&(e.fog=!1)}async createComponent(e,t,a,s){const r=new Le[a.path+"/"+a.className],i=t.id+s;r.id=i,r.object=e;for(const e of a.params)null!=e.value&&(r[e.name]=e.value);return this.components.push(r),i}async createFromActor(e,t){const a=this.actorTypes.find(t=>t.name===e.actor?.type)?.type??U[e.actor?.type];if(null==a)return{object:null,actor:null};this.inEditor&&this.editorActorParamSnapshot.set(e.id,JSON.stringify(e.actor));const s=await this.actorProvider.create(a,(new M).fromArray(e.position),(new o).fromArray(e.rotation),!0);return this.materializedActors.set(this.getNestedActorId(e.id,t),s),{object:s?.object,actor:s}}getNestedActorId(e,t){return null!=t?t.sceneObjectChain.join("/")+"/"+e:e}async createFromVfx(e,t){const a=await this.assetsService.getAsset(e.assetId);null==a&&console.error("Could not find asset",e);const s=await this.actorProvider.create($,(new M).fromArray(e.position),(new o).fromArray(e.rotation),!1);try{await s.fromAsset(a)}catch(e){return console.error("Failed to create VFX asset",e),null}return s.play(),this.materializedActors.set(this.getNestedActorId(e.id,t),s),null!=s&&(s.object.userData.actor=s),s?.object}async createFromShape(e){const t=this.inEditor&&e.hidden;let a;if("landscape"==e.shape)a=this.createLandscape(e),a.traverse(e=>{e instanceof p&&this._originalMaterials.set(e.id,e.material)});else{let s=new g({name:"Default",color:new n("#aaaaaa"),visible:this.inEditor||!e.hidden,wireframe:!!t});const r=await this.createMeshByShape(e.shape,s,e.shapeParams);r.castShadow=e.castShadow??!0,r.receiveShadow=e.castShadow??!1,e.collisionDetection||(r.collisionShape=null),r.physics=e.physics,a=r,this._originalMaterials.set(a.id,r.material),a.traverse(e=>{})}return t||(await Promise.all((e.materialAssignments??[]).filter(e=>null!=e.materialId).map(e=>this.applyMaterial(a,e))),this.applyVertexMaterials(e,a)),a}createLandscape(e){const t=e.landscape?.options;if(null==t)return console.error(`No landscape options exist on scene object ${e.id} ${e.name}`),new h;const a=fe(e.landscape.options);this.applyHeightMaps(a,e.landscape.heightMaps,!0);const s=new ue(e,this.renderingView,a,this.assetManagerService,this.assetsService,this.shaders,t=>{(e.materialAssignments??[]).filter(e=>null!=e.materialId).forEach(e=>this.applyMaterial(t,e))});return this.landscapeManagers.push(s),s.refreshGeometry(),a}applyHeightMaps(e,t,a=!1){const s=new ge(e.sections);for(const e of t??[]){const t=s.find(e.x,e.y);if(!t)return;const a=t.geometry.getAttribute("position");for(const t of e.points)a.setY(t.i,t.y);a.needsUpdate=!0}const r=e.sections;r.forEach(e=>{e.geometry.computeBoundsTree(),e.geometry.computeVertexNormals()}),this.inEditor&&!a||setTimeout(()=>ye(r),50)}async createMeshByShape(e,t,a={}){if("landscape"!==e&&je.includes(e)){const s=await prepareShapeParameters(a??{}),r=e+JSON.stringify(a);if(!this.geometryCache.has(r)){const t=Me[e].geometry(s);t.computeTangents(),this.geometryCache.set(r,t)}this.collisionShapeCache.has(r)||this.collisionShapeCache.set(r,Me[e].collision(s));return new pe(this.geometryCache.get(r),t,this.collisionShapeCache.get(r))}if(this.inEditor)throw new Error(`Unsupported shape '${e}'`);console.warn(`Failed to create shape. Unsupported shape '${e}'. This might be because the hology/core library is not compatible with the editor version.`)}async createFromAsset(e){const t=await this.assetsService.getAsset(e.assetId);if(null==t)return void console.warn(`Can not find asset with id ${e.assetId} and name ${e.name}`);let{scene:a}=await this.assetManagerService.getMesh(t,{mergeGeomtries:!0});et(e.materialAssignments,t.materialAssignments).forEach(e=>this.applyMaterial(a,e));const s=e.receiveShadow??!!t.receiveShadow??!0,r=e.castShadow??!!t.castShadow??!1;return a.receiveShadow=s,Ge(a,r,s),e.collisionDetection||(a.collisionShapes=[]),null!=e.physics&&!0!==this.inEditor&&(a.physics=e.physics),this.applyVertexMaterials(e,a),a.traverse(e=>{e instanceof p&&"computeBoundsTree"in e.geometry&&null==e.geometry.boundsTree&&e.geometry.computeBoundsTree()}),a}async createFromPrefab(e,t){const a=await this.assetsService.getAsset(e.assetId);if(null==a)return void console.warn(`Can not find asset with id ${e.assetId} and name ${e.name}`);null==t&&(t={sceneObjectChain:[]}),t.sceneObjectChain.push(e.id);const{object:s}=await this.createFromPrefabAsset(a,t);return t.sceneObjectChain.pop(),s}async createFromPrefabAsset(e,t){const a=new h;await Promise.all(e.prefab.objects.filter(e=>"global_fog"!==e.type&&"world_env"!==e.type).map(e=>this.materialize(e,a,!0,structuredClone(t))));const s=t.sceneObjectChain.join("/"),r=Array.from(this.materializedActors.entries()).filter(([e,a])=>e.startsWith(s)&&e.split("/").length-1===t.sceneObjectChain.length).map(([,e])=>e);r.forEach(e=>{a.add(e.object)}),this.initActorsPostInit(r,structuredClone(t));const i=Array.from(this.materializedActors.entries()).filter(([e,t])=>e.startsWith(s)).map(([,e])=>e);return{object:a,actors:i}}async createParticleSystem(e){const t=await this.assetsService.getAsset(e.assetId),a=new y;return await x.fromJSONAsync(t.particleSystem,r).then(e=>{const t=new P(a,r);e.addRenderer(t),this.renderingView.onLoop(t=>e.update())}),a}async createLight(e){if("point"===e.light.type){const t=new w(e.light.point.color,e.light.point.intensity,e.light.point.distance,e.light.point.decay);if(t.castShadow=e.light.point.castShadow??!0,this.inEditor){const e=(new r.TextureLoader).load("assets/light-bulb-icon.webp"),a=new r.SpriteMaterial({map:e,alphaTest:.5}),s=new Be(a);s.scale.multiplyScalar(.6),t.add(s)}return t}if("spot"===e.light.type){const t=new r.SpotLight(e.light.spot.color,e.light.spot.intensity,e.light.spot.distance,e.light.spot.angle,e.light.spot.penumbra,e.light.spot.decay);if(t.castShadow=e.light.spot.castShadow??!0,t.target=new y,t.target.position.set(0,-1,0),t.add(t.target),this.inEditor){const e=(new r.TextureLoader).load("assets/light-bulb-icon.webp"),a=new r.SpriteMaterial({map:e,alphaTest:.5}),s=new Be(a);s.scale.multiplyScalar(.6),t.add(s),t.add(new r.SpotLightHelper(t))}return t}return"directional"===e.light.type?(this.applyDirectionalLight(e.light.directional,e),new h):"ambient"===e.light.type?(this.applyDirectionalAmbientLight(null,e.light.ambient,e),new h):void 0}applyDirectionalAmbientLight(e,t,a){const s=this.scene.children.find(e=>e.name===xe);null!=s?(s.intensity=t.intensity,s.color.set(t.color),s.groundColor.set(t.color),s.userData.src=a,s.userData.volumetricIntensity=t.volumetricIntensity):console.warn("Couldn't find ambient light")}applyDirectionalLight(e,t){for(const a of this.renderingView.csm.lights)a.intensity=e.intensity,a.color.set(e.color),a.castShadow=e.castShadow,a.userData.src=t,a.userData.volumetricIntensity=e.volumetricIntensity;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe(),this.createAssetSubscription.unsubscribe(),this.materializedActors.forEach(e=>e.disposed.next(!0)),this.materializedActors.clear()}};Re=e([W(),t("design:paramtypes",[b,Object,Object,he,X,Array,Array,Object])],Re);export{Re as SceneMaterializer};function Ge(e,t,a){e.castShadow=t,e.receiveShadow=a,e.traverse(e=>{e.castShadow=t,e.receiveShadow=a})}const Ue=new Map,He=new Map,Je=new u({color:16711935}),qe=new Map;export async function materialFromAsset(e,t,a,s,r,i=!0){const n=JSON.stringify(e.material);return i&&Ue.has(n)?Ue.get(n):i&&He.has(n)?await He.get(n):He.set(n,_materialFromAsset(n,e,t,a,s,r,i)).get(n)}export async function _materialFromAsset(e,t,a,s,i,o,l=!0){const c={opacity:t.material.params.opacity,map:null,emissive:t.material.params.emissive??null,metalness:t.material.params.metalness??0,flatShading:t.material.params.flatShading??!1,color:new n(t.material.params.color),transparent:null!=t.material.params.opacity&&t.material.params.opacity<1},h={};if(null!=t.material.params.map){const e=t.material.params.map,a=await s.getAsset(e);null!=a&&(c.map=await i.getTexture(a))}let d;switch(t.material.type){case"phong":d=new f({...c,...h});break;case"water":d=Ae(c,a);break;case"grassFoliage":d=we({color:c.color,map:c.map},a);break;case"grass":d=ve({...c,colorTwo:new n(t.material.params.colorTwo),colorThree:new n(t.material.params.colorThree)},a);break;case"standard":case"unlit":case"toon":case"layered":case"lambert":case"shader":case"landscape":case"landscape-composite":case"decal-unlit":case"decal-standard":const e={standard:We?Z:ee,lambert:Z,unlit:te,toon:_e,layered:Fe,landscape:Q,"landscape-composite":K,"decal-unlit":Ce,"decal-standard":Ee}[t.material.type]??o.find(e=>e.name==t.material.shader)?.type;if(e){try{let r=new e;const n=await prepareClassParameters(t.material?.shaderParams??{},e,s,i,null,a,o);Object.assign(r,n),d=r.build()}catch(e){console.log("Shader runtime error: "+e),qe.has(t.material.shader)||qe.set(t.material.shader,Je.clone()),d=qe.get(t.material.shader)}d.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),d=Je;break;default:throw new Error("Unsupported material type"+t.material.type)}return a?.csm.setupMaterial(d),null!=a&&Ue.set(e,d),d.side=t.material.side??d.side??r.FrontSide,d.transparent=(t.material.transparent??c.transparent??!1)||d.transparent,d.alphaTest=t.material.alphaTest??d.alphaTest??0,null!=t.material.blending&&(d.blending=J[t.material.blending]??r.NormalBlending),t.material.bloom&&(d.userData.hasBloom=!0),t.material.reflective&&(d.userData.reflective=!0),!0===t.material.outlines&&(d.userData.outlineParameters={},null!=t.material.outlineParams&&(null!=t.material.outlineParams.color&&(d.userData.outlineParameters.color=new n(t.material.outlineParams.color).toArray()),null!=t.material.outlineParams.thickness&&(d.userData.outlineParameters.thickness=t.material.outlineParams.thickness))),d.userData.assetId=t.id,He.delete(e),d}export async function prepareClassParameters(e,t,a,s,r,i,n,o){const l={};for(const[t,c]of Object.entries(e)){const e=await Xe(t,c,a,s,r,i,n,o);null!=e&&(l[t]=e)}return l}export async function prepareShapeParameters(e){const t={};for(const[a,s]of Object.entries(e)){const e=await Xe(a,s,null,null,null);null!=e&&(t[a]=e)}return t}async function Xe(e,t,a,s,r,i,l,c,h=t.value,d=t.type){if(null==t||null==h||""===h)return null;switch(d){case Se.Array:if(Array.isArray(h)&&"element"in t)return await Promise.all(h.map(n=>Xe(e,t,a,s,r,i,l,c,n,t.element)));break;case Se.Number:case Se.FloatNode:let d="string"==typeof h?parseFloat(h):h;return t.type===Se.FloatNode?C(d):d;case Se.Texture:let m=await s.getTexture(await a.getAsset(h));return"envmap"===e.toLowerCase()&&null!=i&&(m=i.getEnvTexture(m)),m;case Se.Sampler2DNode:return F(await s.getTexture(await a.getAsset(h)));case Se.Boolean:return h;case Se.BooleanNode:return I(h);case Se.Vector2:case Se.Vec2Node:if("object"==typeof h){const e=h instanceof Array?(new S).fromArray(h):new S(h.x,h.y);return t.type===Se.Vec2Node?T(e):e}return null;case Se.Vector3:case Se.Vec3Node:if("object"==typeof h){const e=h instanceof Array?(new M).fromArray(h):new M(h.x,h.y,h.z);return t.type===Se.Vec3Node?B(e):e}return null;case Se.Color:case Se.RgbNode:const p=new n(h);return t.type===Se.RgbNode?O(p):p;case Se.String:return h;case Se.BaseActor:const u=h;return null==r&&console.warn("Class parameters can not be prepared as actors are not passed in"),r?.get(u);case Se.Euler:const f=h;return(new o).fromArray(f);case Se.Object3D:return(await s.getMesh(await a.getAsset(h))).scene;case Se.Material:return await materialFromAsset(await a.getAsset(h),i,a,s,l);case Se.AudioBuffer:return await s.getAudio(await a.getAsset(h));case Se.VisualEffect:const g=await a.getAsset(h);if(null==c){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in g)return new R(c,g);console.error("Using a non-vfx asset for visual effect parameter");break;case Se.Curve:return De.decode(h);case Se.ColorLayer:case Se.MaskLayer:if(Te(h)){const e=await Ve.decode(h,async e=>await s.getTexture(await a.getAsset(e))),t=await prepareClassParameters(h.params,null,a,s);return Object.assign(e,t),e}return console.warn("Expecting color layer but got",h),null}return null}function Ye(e){e.updateWorldMatrix(!0,!0),e.updateMatrix(),e.traverse(e=>{e.matrixAutoUpdate=!1,e.matrixWorldNeedsUpdate=!1});const t=e.updateMatrixWorld;e.updateMatrixWorld=function(){t.apply(e),e.updateMatrixWorld=function(){}}}function Ze(e){return"linear"===e.type?new l(new n(e.color),e.near??100,e.far??1e3):"density"===e.type?new c(e.color,e.density):void console.warn("Invalid fog type",e)}const Ke=new g({color:4229780});async function Qe(e,t,a,s){null==s&&(s=(new m).identity()),await t(e,a,s);const i=s.clone().multiply(function(e,t){if(null==e.position||null==e.rotation||null==e.scale)return t.identity();return t.compose((new M).fromArray(e.position),(new v).setFromEuler((new o).fromArray(e.rotation)),(new M).fromArray(e.scale))}(e,new r.Matrix4));return Promise.all((e.children??[]).map(a=>Qe(a,t,e,i)))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?Se.Number:t instanceof E||"function"==typeof e.prototype.isFloat?Se.FloatNode:t instanceof A||e===A||e.isTexture?Se.Texture:t instanceof Y||e===N?Se.Sampler2DNode:t instanceof Boolean||e===Boolean?Se.Boolean:t instanceof D?Se.BooleanNode:t instanceof n||e==n?Se.Color:t instanceof k||"function"==typeof e.prototype.isRgb?Se.RgbNode:t instanceof S||e==S?Se.Vector2:t instanceof z||"function"==typeof e.prototype.isVec2?Se.Vec2Node:t instanceof M||e==M?Se.Vector3:t instanceof _||"function"==typeof e.prototype.isVec3?Se.Vec3Node:t instanceof String||e===String?Se.String:t instanceof G||e==G||e.prototype instanceof G||e.prototype==G?Se.BaseActor:t instanceof o||e==o?Se.Euler:t instanceof y||e==y?Se.Object3D:t instanceof d||e==d?Se.Material:t instanceof AudioBuffer||e==AudioBuffer?Se.AudioBuffer:t instanceof R||e==R?Se.VisualEffect:t instanceof De||e==De?Se.Curve:t instanceof Ve||e==Ve?Se.ColorLayer:t instanceof Ne||e==Ne?Se.MaskLayer:void console.warn("Failed to map parameter type to serialized version",{type:e})}export function prepareCustomParams(e,t,a={}){return Object.fromEntries(e.map(e=>[e.name,{type:e.options.array?Se.Array:toSerializedParamType(e.type),...e.options.array?{element:toSerializedParamType(e.type)}:{},value:t[e.name]?.value??(!0!==e.options.array?a[e.name]??customParameterDefaultValueByType.get(toSerializedParamType(e.type)):[])}]))}export function prepareCustomParamsFromType(e,t,a=null){const s=ae(e);if(0===s.length)return{};let r;null!=a?q(a,()=>{r=a.get(e)}):r=new e;const i={};for(const e of s){const t=r[e.name];if(null!=t&&!0!==e.options.array){const a=serializeCustomParameter(e.type,t);null!=a&&(i[e.name]=a)}}return prepareCustomParams(s,t,i)}export function serializeCustomParameter(e,t){function a(){console.error("Failed to serialize value",{type:e,value:t})}switch(e){case Number:case Boolean:return t;case S:return t instanceof S?t.toArray():void a();case M:return t instanceof M?t.toArray():void a();case j:return t instanceof j?t.toArray():void a();case n:return t instanceof n?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new n(t).getHexString():void a();case String:return t;case o:return t instanceof o?t.toArray():void a()}}function et(e,t){return function(e,t,a){const s=[],r=new Set;for(const i of[...e??[],...t??[]]){const e=a(i);r.has(e)||(r.add(e),s.push(i))}return s}((e??[]).filter(e=>tt(e.materialId)),(t??[]).filter(e=>tt(e.materialId)),e=>e.color+e.name)}function tt(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[Se.RgbNode,"#000000"],[Se.Color,"#000000"],[Se.Vector4,[0,0,0,0]],[Se.Vec4Node,[0,0,0,0]],[Se.Vector3,[0,0,0]],[Se.Vec3Node,[0,0,0]],[Se.Vector2,[0,0]],[Se.Vec2Node,[0,0]],[Se.Euler,[0,0,0,"XYZ"]],[Se.Array,[]],[Se.ColorLayer,Oe],[Se.MaskLayer,ke]]);export function applyMaterial(e,t,a,s){const i=[];return e.traverse(async e=>{if(e instanceof p||e.isMesh||e instanceof r.SkinnedMesh||e.isSkinnedMesh)for(const t of ie(e.material))t.hasOwnProperty("color")&&i.push(e)}),Promise.all(i.map(async e=>{if(e.material instanceof Array)for(let r=0;r<e.material.length;r++){const i=e.material[r];if(null==i.color||!(i.color instanceof n))continue;const o="#"+i.color.getHexString(),l=i.name;if(o===t.color&&(i.name===t.name||null==t.name)||e.userData["originalColor_"+r]===t.color&&e.userData["originalMaterialName_"+r]===t.name){const i=await a(t.materialId),n=e.material[r];null!=i&&n.id!=i.id&&(e.material[r]=i,e.userData["originalColor_"+r]=e.userData["originalColor_"+r]??o,e.userData["originalMaterialName_"+r]=e.userData["originalMaterialName_"+r]??l,null!=s&&s.set(e.id+"#"+r,n))}}else if("color"in e.material){const r="#"+e.material.color.getHexString(),i=e.material.name;if(r===t.color&&(e.material.name===t.name||null==t.name)||e.userData.originalColor===t.color&&e.userData.originalName===t.name){const n=await a(t.materialId),o=e.material;null!=n&&(e.material=n,e.userData.originalColor=e.userData.originalColor??r,e.userData.originalMaterialName=e.userData.originalMaterialName??i,null!=s&&(s.has(e.id)||s.set(e.id,o)))}}}))}function at(e,t){if(e instanceof r.ShaderMaterial&&t instanceof r.ShaderMaterial){return e.fragmentShader+e.vertexShader==t.fragmentShader+t.vertexShader&&function(e,t){if(e instanceof r.ShaderMaterial&&t instanceof r.ShaderMaterial){for(const a in e.uniforms){if(null==t.uniforms[a])return!1;if(t.uniforms[a].value!==e.uniforms[a].value)return!1}return!0}return!1}(e,t)}return!1}function st(e){if(null!=e){for(let t=0;t<e.array.length;t++)e.setX(t,0);e.needsUpdate=!0}}/*
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{ConvexPolyhedronCollisionShape as a}from"@hology/core";import{Subject as s}from"rxjs";import*as r from"three";import{BoxGeometry as i,Color as n,Euler as o,Fog as l,FogExp2 as c,Group as h,Material as d,Matrix4 as p,Mesh as m,MeshLambertMaterial as u,MeshPhongMaterial as f,MeshStandardMaterial as g,Object3D as y,PointLight as w,Quaternion as v,Scene as b,Texture as A,Vector2 as S,Vector3 as M,Vector4 as j}from"three";import x,{SpriteRenderer as P}from"@hology/nebula";import{bool as I,BooleanNode as D,float as C,FloatNode as E,NodeShaderMaterial as V,rgb as O,RgbNode as k,Texture2dLookupNode as N,textureSampler2d as F,vec2 as T,Vec2Node as z,vec3 as B,Vec3Node as _,vec4 as L}from"three-shader-graph";import{Service as W}from"typedi";import{VfxActor as $}from"../effects/vfx/vfx-actor.js";import{VisualEffect as R}from"../effects/vfx/vfx-param.js";import{BaseActor as G}from"../gameplay/actors/actor.js";import U from"../gameplay/actors/builtin/index.js";import{PhysicsBodyType as H,ThreeBlendingMode as J,withInjectionContext as q}from"../gameplay/index.js";import{RenderingView as X}from"../rendering.js";import{Sampler2DNode as Y}from"../shader-nodes/index.js";import{LambertShader as Z}from"../shader/builtin/lambert-shader.js";import{LandscapeCompositeShader as K}from"../shader/builtin/landscape-composite-shader";import{LandscapeShader as Q}from"../shader/builtin/landscape-shader.js";import{StandardShader as ee}from"../shader/builtin/standard-shader.js";import{UnlitShader as te}from"../shader/builtin/unlit-shader.js";import{extractShaderParameters as ae}from"../shader/parameter.js";import{ArrayMap as se,groupBy as re}from"../utils/collections.js";import{iterateMaterials as ie}from"../utils/materials.js";import{filterChildrenShallow as ne,filterSceneShallow as oe,findFirstVisibleObject as le}from"../utils/three/traverse.js";import{AssetMeshInstance as ce,AssetResourceLoader as he}from"./asset-resource-loader.js";import{isCollisionMesh as de}from"./collision/collision-shape-import.js";import{BoxCollisionShape as pe,PhysicalShapeMesh as me}from"./collision/collision-shape.js";import{LandscapeManager as ue}from"./landscape/landscape-manager.js";import{initLandscape as fe}from"./landscape/landscape.js";import{SectionGrid as ge,smoothNormalsCrossMeshes as ye}from"./landscape/utils.js";import{createGrassFoliageMaterial as we}from"./materials/grass-foliage.js";import{createGrassMaterial as ve}from"./materials/grass.js";import{getMaterialAttribute as be}from"./materials/utils/material-painting.js";import{createWaterMaterial as Ae}from"./materials/water.js";import{SerializedParamType as Se}from"./model.js";import{ShapeLibrary as Me,ShapeLibraryKeys as je}from"./objects/shapes.js";import{ambientLightName as xe,createSky as Pe,defaultSkyMaterial as Ie}from"./sky.js";import{Curve2 as De}from"../utils/curve.js";import{DecalUnlitShader as Ce}from"../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as Ee}from"../shader/builtin/decal-standard-shader.js";import{ColorLayer as Ve,defaultValueColorLayer as Oe,defaultValueMaskLayer as ke,MaskLayer as Ne}from"../shader/color-layer.js";import{LayeredShader as Fe}from"../shader/builtin/layered-shader";import{isColorLayerSerialized as Te}from"../shader/color-layer";import{FogVolume as ze}from"../rendering/fog/fog-volume-actor.js";import{UnscaledSprite as Be}from"../utils/three/unscaled-sprite.js";import{ToonShader as _e}from"../shader/builtin/toon-shader.js";const Le={},We=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),$e=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPad"))&&!!navigator.userAgent.match(/AppleWebKit/)&&!navigator.userAgent.match(/CriOS/);export const shapeDefaultColor="#aaaaaa";export class SceneMaterializerLoader{constructor(e,t,a){this.dataProvider=e,this.assetsService=t,this.assetManagerService=a}get(e,t){return new Re(e,this.dataProvider,this.assetsService,this.assetManagerService,t,[],[],{create:()=>null,initActor:async()=>{}})}}let Re=class{constructor(e,t,a,i,n,o,l,c){this.scene=e,this.dataProvider=t,this.assetsService=a,this.assetManagerService=i,this.renderingView=n,this.shaders=o,this.actorTypes=l,this.actorProvider=c,this.objectMap=new Map,this.sceneObjectMap=new Map,this.components=[],this.landscapeManagers=[],this.materializedActors=new Map,this.inEditor=!0,this.updated$=new s,this.removed$=new s,this.error$=new s,this.editorActorParamSnapshot=new Map,this.assets=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.pmremGeneratorResults=new WeakMap,this.prefabInstanceChain=[],this.geometryCache=new Map,this.collisionShapeCache=new Map,this.originalFog=null,t.onCreate(e=>this.update(e)),t.onUpdate(e=>this.update(e)),t.onRemove(e=>this.remove(e)),this.createAssetSubscription=a.onCreate.subscribe(e=>{this.assets.set(e.id,e)}),this.updateSubscription=a.onUpdate.subscribe(async t=>{this.assets.set(t.id,t),"material"==t.type?e.traverse(e=>{if(e instanceof r.Mesh)if(Array.isArray(e.material))for(let a=0;a<e.material.length;a++)this.refreshMaterial(e,e.material[a],t,a);else this.refreshMaterial(e,e.material,t)}):"mesh"==t.type?(this.findByAssetId(t.id).forEach(e=>{this.remove(e.userData.src),this.materializeAndInitActor(e.userData.src)}),this.landscapeManagers.forEach(e=>{const a=e.source?.grass?.layers?.some(e=>e.meshes.some(e=>e.assetId===t.id));a&&e.queueRefreshScatter(this.renderingView?.camera.position??new M,!0)})):"prefab"===t.type?this.findByAssetId(t.id).forEach(e=>{const t=e.userData.src;this.remove(t),this.materializeAndInitActor(t)}):"vfx"===t.type&&this.dataProvider.getObjects().forEach(e=>{Qe(e,(e,a)=>{"vfx"===e.type&&e.assetId===t.id&&(this.remove(e),this.materializeAndInitActor(e))})})})}async refreshMaterial(e,t,a,s){const r=t?.userData?.assetId;if(r!==a.id){const e=this.assets.get(r);let t=!1;if(null!=e)for(const s of Object.values(e.material.shaderParams)){if(s.type===Se.Material&&s.value===a.id){t=!0;break}if(s.type===Se.Array&&"element"in s&&s.element===Se.Material&&s.value.includes(a.id)){t=!0;break}}if(!t)return}const i=await materialFromAsset(this.assets.get(r),this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1),n=i.userData;i.userData=t.userData,i.userData.hasBloom=n.hasBloom,i.userData.reflective=n.reflective,i.userData.outlineParameters=n.outlineParameters,null!=s?at(e.material[s],i)||(e.material[s]=i):at(e.material,i)||(e.material=i,e===this.sky&&this.applySkySettings(e.material))}getTopLevelActors(){return Array.from(this.materializedActors.entries()).filter(([e,t])=>!e.includes("/")).map(([,e])=>e)}get actorInstances(){return Array.from(this.materializedActors.values())}async initTextures(){const e=[];if(await Promise.all(this.dataProvider.getObjects().filter(e=>"shape_mesh"===e.type||"asset_mesh"===e.type).filter(e=>null!=e.materialAssignments).flatMap(e=>e.materialAssignments).map(async t=>{const a=this.assets.get(t.materialId);if(null!=a)for(const t of Object.values(a.material.shaderParams))if(t.type===Se.Texture&&"string"==typeof t.value){const a=this.assets.get(t.value),s=await this.assetManagerService.getTexture(a);null!=s&&e.push(s)}})),0!==e.length&&this.renderingView){console.log(`Initializing ${e.length} textures`),console.time("Init textures");for(const t of e)this.renderingView.renderer.initTexture(t);console.timeEnd("Init textures")}}async prefetchAssets(){const e=Array.from(new Set(this.dataProvider.getObjects().filter(e=>null!=e.assetId&&"asset_mesh"==e.type).filter(e=>e.assetId)));await Promise.all(e.map(e=>this.assetsService.getAsset(e.assetId).then(e=>{if(null!=e)return this.assetManagerService.getMesh(e)}))),this.initTextures()}async init(){await this.preInit(),Ue.clear(),He.clear(),await this.prefetchAssets(),await Promise.all(this.dataProvider.getObjects().map(e=>this.materialize(e))),await this.initActorsPostInit()}initActorsPostInit(e=this.getTopLevelActors(),t){const a=e.map(async e=>{const a=e.object.userData.src??e.object.userData._src;if("vfx"===a.type)return Promise.resolve();const s=await this.assetsService.getAsset(a.assetId),r={...s?.actor?.params??{},...a.actor?.params??{}},i=null!=t?new Map(Array.from(this.materializedActors.entries()).filter(([e,a])=>e.startsWith(t.sceneObjectChain.join("/"))&&e.split("/").length-1===t.sceneObjectChain.length).map(([e,t])=>[e.split("/").pop(),t])):this.materializedActors;for(const t of a.actor.innerParams??[])await this.applyActorComponentParams(e,t.path.slice(),t.params,i);const n=await prepareClassParameters(r,e.constructor,this.assetsService,this.assetManagerService,i,this.renderingView,this.shaders,this.actorProvider);Object.assign(e,n);try{return await this.actorProvider.initActor(e)}catch(e){console.error(`Failed to initiate actor (name="${a.name}", id=${a.id})`,e)}});return Promise.all(a)}addVfxChildActors(e,t=e){}async applyActorComponentParams(e,t,a,s){const r=t.length,i=t.shift();if(0==r){const t=await prepareClassParameters(a,null,this.assetsService,this.assetManagerService,s,this.renderingView,this.shaders,this.actorProvider);for(const[a,s]of Object.entries(t))null!=s&&(e[a]=s)}else null!=e[i]&&await this.applyActorComponentParams(e[i],t,a,s)}canObjectBeInstanced(e){return e.physics?.type!==H.dynamic&&"sky"!==e.type&&"global_fog"!==e.type&&"world_env"!==e.type}async canAssetBeInstanced(e){if(!this._canBeInstancedCache.has(e.assetId)){const t=await this.createFromAsset(e);if(null==t)return!1;const a=[];t.traverse(e=>{!de(e)&&e.isMesh&&a.push(e)});const s=1==a.length&&0==a[0].children.length,r=a[0]instanceof m&&null!=a[0].geometry.morphAttributes&&Object.keys(a[0].geometry.morphAttributes).length>0,i=!0;this._canBeInstancedCache.set(e.assetId,s&&i&&!r)}return this._canBeInstancedCache.get(e.assetId)}async preInit(){this.renderingView?.onLoop(()=>{null!=this.sky&&this.renderingView.camera.getWorldPosition(this.sky.position)}),this.assetsService.getAssets().then(e=>{for(const t of e)this.assets.set(t.id,t)})}shouldBeMaterialized(e){if(null!=this.detailTier&&"asset_mesh"===e.type&&null!=e.assetId){const t=this.assets.get(e.assetId);if(null!=t){const e=t.mesh?.detailTier;if(null!=e)return e<=this.detailTier}}return!0}async initWithInstancing(){await this.preInit(),await this.prefetchAssets(),Ue.clear(),He.clear();const e=[],t=new se,s=new se;let i=0,l=0;for(const a of this.dataProvider.getObjects())await Qe(a,async(a,r,o)=>{if(!this.shouldBeMaterialized(a))return;const c="asset_mesh"==a.type&&this.canObjectBeInstanced(a)&&await this.canAssetBeInstanced(a),h="shape_mesh"===a.type&&"landscape"!==a.shape&&a.physics?.type!==H.dynamic;if(c||h){if(r&&r.children?.length>0){const e=r.children.findIndex(e=>e.id===a.id);e>=0&&r.children.splice(e,1)}if(h){let e=a.shape+JSON.stringify(a.shapeParams??{})+a.castShadow+a.receiveShadow;const t=a.materialAssignments?.at(0)?.materialId,r=null!=t?this.assets.get(t):null;let i=null;if(null!=r&&"shader"!==r.material.type){if(e+=r.material.type+r.material.shader,null!=r.material.shaderParams){if(e+=Object.entries(r.material.shaderParams).filter(([e,t])=>"color"!=e).map(e=>JSON.stringify(e)).join(),null!=r.material.shaderParams.color){const e=r.material.shaderParams.color;e.type===Se.Color&&null!=e.value&&(i=new n(e.value))}}}else e+=t;s.push(e,{object:{...a,parentTransform:o},color:i}),l++}else{const e=a.assetId+JSON.stringify(a.materialAssignments??[]);t.push(e,{...a,parentTransform:o}),i++}}else null==r&&e.push({...a,parentTransform:o})});console.log(`Scene init stats: \n Assets: ${t.size} batch groups containing in total ${i} objects.\n Shapes: ${s.size} batch groups containing in total ${l} objects. \n ${e.length} objects can not be batched. \n `);for(const e of t.values()){if(0==e.length)continue;const t=await this.createFromAsset(e[0]);if(null==t)continue;const s=await this.createInstancedMesh(e,t),r=new ce;r.add(s),r.userData.src=e[0],t instanceof ce&&(r.collisionShapes=t.collisionShapes),r.collisionShapes.forEach(e=>{e instanceof a&&e.mesh instanceof m&&(e.mesh=e.mesh.geometry)}),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}for(const e of s.values()){if(0==e.length)continue;const t=e[0].object,a=await this.createFromShape(t),s=le(a,e=>!de(e)&&null!=e.geometry),i=s.material.clone();null!=e[0].color&&null!=i.color&&(i.color=new n(16777215));const l=s.geometry;let c,h;!($e||i instanceof V||null==l.index)?(c=new r.BatchedMesh(e.length,l.getAttribute("position").count,l.index.count,i),c.perObjectFrustumCulled=!0,h=c.addGeometry(l)):c=new r.InstancedMesh(l,i,e.length),c.castShadow=a.castShadow??!0,c.receiveShadow=s.receiveShadow??!0;for(let t=0;t<e.length;t++){const a=e[t],s=(new r.Matrix4).compose((new M).fromArray(a.object.position),(new v).setFromEuler((new o).fromArray(a.object.rotation)),(new M).fromArray(a.object.scale)),i=(new p).copy(a.object.parentTransform).multiply(s);let n;n=c instanceof r.BatchedMesh?c.addInstance(h):t,c.setMatrixAt(n,i),null!=a.color&&c.setColorAt(n,a.color)}for(let t=0;t<e.length;t++){const s=e[t],r=new ce;r.userData.src=e[0],a instanceof me&&(r.collisionShapes=[a.collisionShape]),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r),r.add(c),null==c.userData.hasCollision&&(c.userData.hasCollision=[]),c.userData.hasCollision[t]=!!s.object.collisionDetection}}await Promise.all(e.map(e=>this.materialize(e))),await this.initActorsPostInit()}async createInstancedMesh(e,t){const a=le(t,e=>!de(e)&&null!=e.geometry),s=await this.assetsService.getAsset(e[0].assetId);await this.applyMaterials(t,et(e[0].materialAssignments,s.materialAssignments)),a.updateMatrix();const i=a.geometry.clone(),n=a.material;let l,c;if(!($e||n instanceof V||!(i.groups.length<2)||Array.isArray(n)&&1!=n.length)){const t=Array.isArray(n)?n[0]:n,a=i.getAttribute("position").count;l=new r.BatchedMesh(e.length,a,null!=i.index?i.index.count:a,t),l.perObjectFrustumCulled=!0,c=l.addGeometry(i)}else l=new r.InstancedMesh(i,n,e.length);for(let t=0;t<e.length;t++){let s=t;l instanceof r.BatchedMesh&&(s=l.addInstance(c));const i=(new r.Matrix4).compose((new M).fromArray(e[t].position),(new v).setFromEuler((new o).fromArray(e[t].rotation)),(new M).fromArray(e[t].scale)),n=(new p).copy(e[t].parentTransform).multiply(i).multiply(a.matrixWorld);l.setMatrixAt(s,n),null==l.userData.hasCollision&&(l.userData.hasCollision=[]),l.userData.hasCollision[t]=!!e[t].collisionDetection}if(l.castShadow=e[0].castShadow??s.castShadow??!0,l.receiveShadow=e[0].receiveShadow??s.receiveShadow??!0,a.material instanceof d&&l.castShadow&&l.receiveShadow)if(Array.isArray(n))for(const e of n)e.side=r.FrontSide;else n.side=r.FrontSide;return l}remove(e){if(console.log("Remove scene object",e),"global_fog"==e.type)return void(this.scene.fog=this.originalFog);if("world_env"===e.type)this.resetWorldEnv(),this.worldEnvObj=null;else if("actor"==e.type||"vfx"===e.type){const t=this.materializedActors.get(e.id);null!=t?(t.disposed.next(!0),t.onEndPlay()):console.warn("Failed to remove actor",e)}else"prefab"===e.type&&this.materializedActors.forEach((t,a)=>{a.startsWith(e.id)&&(t.disposed.next(!0),t.onEndPlay()),this.materializedActors.delete(a)});const t=this.sceneObjectMap.get(e.id);t?.parent.remove(t),this.sceneObjectMap.delete(e.id),this.components.filter(t=>t.object.userData.src?.id===e.id).forEach(e=>this.components.splice(this.components.indexOf(e,1))),this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(e=>{e.clear(),e.stop(),this.landscapeManagers.splice(this.landscapeManagers.indexOf(e,1))}),this.removed$.next({object:t,source:e})}deleteSceneObject(e){const t=this.sceneObjectMap.get(e.id);if(this.scene.remove(t),"landscape"==e.type){const t=this.landscapeManagers.findIndex(t=>t.source.id===e.id);if(t>-1){const e=this.landscapeManagers.splice(t,1)[0];e.clear(),e.stop()}}}findByAssetId(e){return oe(this.scene,t=>t.userData.src?.assetId==e,e=>null!=e.userData.src)}applyMaterials(e,t){return null==t?Promise.resolve([]):Promise.all(t.filter(e=>"null"!==e.materialId).map(t=>this.applyMaterial(e,t)))}async applyMaterial(e,t){await applyMaterial(e,t,e=>{const t=this.assets.get(e);if(null!=t)try{return materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders)}catch(e){console.error("Failed to apply material",e)}},this._originalMaterials)}unapplyMaterials(e){e.traverse(async e=>{if(e instanceof m)if(e.material instanceof Array)for(let t=0;t<e.material.length;t++)e.material[t]=this._originalMaterials.get(e.id+"#"+t)??e.material[t];else e.material=this._originalMaterials.get(e.id)??e.material})}updateActors(e){console.log("update actors"),this.actorTypes=e;const t=new Set(Object.values(U));oe(this.scene,e=>e.userData.src?.id&&"actor"===e.userData.src.type&&this.materializedActors.has(e.userData.src?.id)&&!t.has(e.userData.src.actor.type)).forEach(async e=>{this.remove(e.userData.src),await this.materializeAndInitActor(e.userData.src)})}updateShaders(e){this.shaders=e;for(const[e,t]of Ue.entries())t.userData.customShaderName&&Ue.delete(e);this.landscapeManagers.forEach(t=>t.updateShaders(e)),oe(this.scene,e=>!0).forEach(e=>{e.traverse(async e=>{if(e instanceof m)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++){const a=e.material[t].userData?.customShaderName;if(null!=a){const a=this.assets.get(e.material[t].userData.assetId);this.refreshMaterial(e,e.material[t],a,t)}}else{const t=e.material.userData?.customShaderName;if(null!=t){const t=this.assets.get(e.material.userData.assetId);this.refreshMaterial(e,e.material,t)}}})})}async update(e){if("sky"===e.type&&null!=this.sky&&null!=this.sky.parent)return void this.updateSky(e);if("world_env"===e.type&&null!=this.worldEnvObj)return void this.updateWorldEnv(e);const t=this.sceneObjectMap.get(e.id);if(t){let s=!1;if(t.traverseAncestors(e=>{"_hology_transform_group"===e.name&&(s=!0)}),!s){const a=this.findParent(e);null!=a&&a.uuid!=t.uuid?a.attach(t):console.error("Parent is wrong")}if("prefab"!==e.type&&"group"!==e.type){this.unapplyMaterials(t);this.inEditor&&e.hidden&&!1?t.traverse(e=>{e instanceof m&&(e.material.wireframe=!0)}):t.traverse(e=>{e instanceof m&&(e.material.wireframe=!1)})}if("asset_mesh"===e.type){const a=this.assets.get(e.assetId);et(e.materialAssignments,a.materialAssignments).forEach(e=>this.applyMaterial(t,e))}else"shape_mesh"===e.type&&this.applyMaterials(t,e.materialAssignments);if(s||(null!=e.position&&t.position.fromArray(e.position),null!=e.scale&&t.scale.fromArray(e.scale),null!=e.rotation&&t.rotation.fromArray(e.rotation)),this.applyVertexMaterials(e,t),"light"==e.type)if("point"==e.light.type){const a=t;a.color=new n(e.light.point.color),a.intensity=e.light.point.intensity,a.decay=e.light.point.decay,a.castShadow=e.light.point.castShadow,a.distance=Math.max(e.light.point.distance,0),a.userData.volumetricIntensity=e.light.point.volumetricIntensity}else if("spot"==e.light.type){const a=t;a.color=new n(e.light.spot.color),a.intensity=e.light.spot.intensity,a.decay=e.light.spot.decay,a.angle=e.light.spot.angle,a.penumbra=e.light.spot.penumbra,a.castShadow=e.light.spot.castShadow,a.distance=Math.max(e.light.spot.distance,0),a.userData.volumetricIntensity=e.light.spot.volumetricIntensity}else"directional"===e.light.type?this.applyDirectionalLight(e.light.directional,e):"ambient"===e.light.type&&this.applyDirectionalAmbientLight(t,e.light.ambient,e);else if("landscape"===e.shape){const a=this.landscapeManagers.find(t=>t.source.id===e.id).source.landscape.options.density!==e.landscape.options.density;if(this.inEditor&&a){this.remove(e);const t=await this.materializeAndInitActor(e);return void this.updated$.next({object:t,source:e})}this.applyHeightMaps(t,e.landscape.heightMaps),this.inEditor&&this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(t=>{t.updateSource(e),t.queueRefreshScatter(this.renderingView.camera.position,!0,e=>!0)})}else if("global_fog"===e.type){const t=(this.scene.fog instanceof c?"density":"linear")!==e.fog.type;this.scene.fog=Ze(e.fog),t&&(a=this.scene).traverse(e=>{if(e instanceof m){const t=e.material;t instanceof V&&(a.fog instanceof l?(t.uniforms.fogFar.value=a.fog.far,t.uniforms.fogNear.value=a.fog.near):a.fog instanceof c&&(t.uniforms.density={value:a.fog.density}),t.needsUpdate=!0,t.uniformsNeedUpdate=!0)}}),this.fixFogColor()}else if("actor"===e.type){if(this.materializedActors.has(e.id)){const t=this.materializedActors.get(e.id);if(t instanceof ze){const a=await prepareClassParameters(e.actor.params,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,[],this.actorProvider);return void Object.assign(t,a)}const a=this.editorActorParamSnapshot.get(e.id);null!=a&&a===JSON.stringify(e.actor)||s||(this.remove(e),await this.materializeAndInitActor(e))}}else if("shape_mesh"===e.type){const a=await this.createMeshByShape(e.shape,t.material,e.shapeParams);t instanceof me&&(t.geometry=a.geometry,t.collisionShape=a.collisionShape)}("asset_mesh"===e.type||"shape_mesh"===e.type&&"landscape"!==e.shape)&&Ge(t,e.castShadow,e.receiveShadow),e.name&&e.name.length>0&&(t.name=e.name),this.updated$.next({object:t,source:e})}else{const t=await this.materializeAndInitActor(e);this.updated$.next({object:t,source:e})}var a;this.renderingView.renderer.shadowMap.needsUpdate=!0}async materializeAndInitActor(e,t=this.findParent(e)){const a=await this.materialize(e,t);return Qe(e,async e=>{if("actor"===e.type){const t=this.materializedActors.get(e.id);null!=t?await this.initActorsPostInit([t]):console.error(`Something went wrong when creating actor ${e.id}`)}}),a}findParent(e){const t=this.dataProvider.getObjects().flatMap(t=>t.id===e.id?null:ne(t,t=>t.children?.some(t=>t.id===e.id),()=>!0))[0];return null==t?this.scene:null!=t?oe(this.scene,e=>e.userData?.src?.id===t.id,e=>null!=e.userData?.src)[0]:void 0}fixFogColor(){!0===this.renderingView.options.enableOutlines&&(this.scene.fog.color=new n(this.scene.fog.color))}findMeshWithGeometry(e){let t;return e.traverse(e=>{e instanceof m&&e.geometry&&(t=e)}),t}applyVertexMaterials(e,t){if(null==e.vertexMaterials||0===e.vertexMaterials.length)return;let a=1;for(const t of e.vertexMaterials)a=Math.max(t.w.length,a);const s=re(e.vertexMaterials,e=>e.m);t.traverse(e=>{if(e instanceof m){if(null==e.geometry)return;if(st(be(e,0,!1)),a>0){st(be(e,0,!1))}}});const r=new Set;for(const[e,i]of s.entries()){const s=null!=e?t.getObjectByName(e):this.findMeshWithGeometry(t);let n=!1;if(null==s||null==s.geometry)return void console.warn(`Failed to apply vertex materials on mesh with name "${e}"`);const o=be(s,0,!0);st(o);for(const e of i)o.setX(e.i,e.w[0]??0),o.setY(e.i,e.w[1]??0),o.setZ(e.i,e.w[2]??0),o.setW(e.i,e.w[3]??0),n=!0;if(a>0){const e=be(s,4,!0);st(e);for(const t of i)e.setX(t.i,t.w[4]??0),e.setY(t.i,t.w[5]??0),e.setZ(t.i,t.w[6]??0),e.setW(t.i,t.w[7]??0),e.needsUpdate=!0,n=!0}n&&r.add(e)}this.inEditor&&this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,e=>r.has(e.name)))}async materialize(e,t,a=!1,s){if(!this.shouldBeMaterialized(e))return;let r,n;switch(e.type){case"asset_mesh":r=await this.createFromAsset(e);break;case"shape_mesh":r=await this.createFromShape(e);break;case"light":r=await this.createLight(e);break;case"particles":r=await this.createParticleSystem(e),e.collisionDetection=!1;break;case"global_fog":this.scene.fog=Ze(e.fog),this.fixFogColor(),r=new h;break;case"sky":this.sky=Pe(),this.updateSky(e),r=this.sky;break;case"world_env":this.updateWorldEnv(e),r=new h,this.worldEnvObj=r;break;case"actor":({object:r,actor:n}=await this.createFromActor(e,s));break;case"group":r=new h;break;case"prefab":r=await this.createFromPrefab(e,s);break;case"vfx":r=await this.createFromVfx(e,s);break;default:if(this.inEditor)throw new Error("unknown type "+e.type);console.warn(`Failed to materialize object. Unknown type '${e.type}'. This might be because the hology/core library is not compatible with the editor version.`)}if(null!=r){if(e.name&&e.name.length>0&&(r.name=e.name),null!=e.position&&r.position.fromArray(e.position),null!=e.scale&&r.scale.fromArray(e.scale),null!=e.rotation&&r.rotation.fromArray(e.rotation),a?r.userData._src=e:r.userData.src=e,null!=n&&(r.userData.actor=n),this.inEditor,this.inEditor){let e=null;r instanceof me&&(e=function(e){if(e instanceof pe)return new m(new i(...e.offset.toArray()),Ke);return null}(r.collisionShape)),null!=e&&(e.layers.disable(0),e.layers.enable(18),e.scale.multiplyScalar(1.1),r.add(e))}if(this.objectMap.set(r.uuid,e),this.sceneObjectMap.set(e.id,r),e.physics?.type!==H.dynamic||null==t||this.inEditor?null==t?this.scene.add(r):t?.add(r):(t.add(r),r.getWorldPosition(r.position),r.getWorldQuaternion(r.quaternion),r.getWorldScale(r.scale),this.scene?.attach(r)),null!=e.children&&await Promise.all(e.children?.map(e=>this.materialize(e,r,a))),this.inEditor||"asset_mesh"!=e.type&&"shape_mesh"!==e.type||"landscape"===e.shape||null!=e.physics?.type&&e.physics.type==H.dynamic||Ye(r),null!=this.renderingView)return this.renderingView.renderer.shadowMap.needsUpdate=!0,r;console.warn("RenderingView not found in materializer. No idea what called this")}}updateWorldEnv(e){this.renderingView.aoPass.enabled=e.worldEnv.ao.enabled,this.renderingView.aoPass.blendIntensity=e.worldEnv.ao.blendIntensity,this.renderingView.aoPass.updateGtaoMaterial(e.worldEnv.ao),this.renderingView.aoPass.output=!0===e.worldEnv.ao.onlyAO?5:0;const t=e.worldEnv.toneMapping;null!=t&&(this.renderingView.renderer.toneMapping=t.mapping??0,this.renderingView.renderer.toneMappingExposure=t.exposure??1);const a=e.worldEnv.environment;null!=a&&null!=a.textureId?this.assetManagerService.getTexture(this.assets.get(a.textureId)).then(e=>{null==this.pmremGenerator&&(this.pmremGenerator=new r.PMREMGenerator(this.renderingView.renderer),this.pmremGenerator.compileEquirectangularShader()),this.pmremGeneratorResults.has(e)||this.pmremGeneratorResults.set(e,this.pmremGenerator.fromEquirectangular(e).texture);const t=this.pmremGeneratorResults.get(e);this.renderingView.scene.environment=t,this.renderingView.scene.environmentIntensity=a.intensity??1}):this.renderingView.scene.environment=null}resetWorldEnv(){this.renderingView.aoPass.enabled=!1,this.renderingView.aoPass.blendIntensity=1,this.renderingView.aoPass.output=0,this.renderingView.renderer.toneMapping=0,this.renderingView.renderer.toneMappingExposure=1}async updateSky(e){if(null==e?.sky?.materialId)return void(this.sky.material=Ie);const t=await this.assetsService.getAsset(e.sky.materialId),a=await materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);this.applySkySettings(a),null!=this.sky?this.sky.material=a:console.warn("No sky has been created")}applySkySettings(e){e.side=r.BackSide,(e instanceof g||e instanceof r.MeshBasicMaterial||e instanceof r.ShaderMaterial)&&(e.fog=!1)}async createComponent(e,t,a,s){const r=new Le[a.path+"/"+a.className],i=t.id+s;r.id=i,r.object=e;for(const e of a.params)null!=e.value&&(r[e.name]=e.value);return this.components.push(r),i}async createFromActor(e,t){const a=this.actorTypes.find(t=>t.name===e.actor?.type)?.type??U[e.actor?.type];if(null==a)return{object:null,actor:null};this.inEditor&&this.editorActorParamSnapshot.set(e.id,JSON.stringify(e.actor));const s=await this.actorProvider.create(a,(new M).fromArray(e.position),(new o).fromArray(e.rotation),!0);return this.materializedActors.set(this.getNestedActorId(e.id,t),s),{object:s?.object,actor:s}}getNestedActorId(e,t){return null!=t?t.sceneObjectChain.join("/")+"/"+e:e}async createFromVfx(e,t){const a=await this.assetsService.getAsset(e.assetId);null==a&&console.error("Could not find asset",e);const s=await this.actorProvider.create($,(new M).fromArray(e.position),(new o).fromArray(e.rotation),!1);try{await s.fromAsset(a)}catch(e){return console.error("Failed to create VFX asset",e),null}return s.play(),this.materializedActors.set(this.getNestedActorId(e.id,t),s),null!=s&&(s.object.userData.actor=s),s?.object}async createFromShape(e){const t=this.inEditor&&e.hidden;let a;if("landscape"==e.shape)a=this.createLandscape(e),a.traverse(e=>{e instanceof m&&this._originalMaterials.set(e.id,e.material)});else{let s=new g({name:"Default",color:new n("#aaaaaa"),visible:this.inEditor||!e.hidden,wireframe:!!t});const r=await this.createMeshByShape(e.shape,s,e.shapeParams);r.castShadow=e.castShadow??!0,r.receiveShadow=e.castShadow??!1,e.collisionDetection||(r.collisionShape=null),r.physics=e.physics,a=r,this._originalMaterials.set(a.id,r.material),a.traverse(e=>{})}return t||(await Promise.all((e.materialAssignments??[]).filter(e=>null!=e.materialId).map(e=>this.applyMaterial(a,e))),this.applyVertexMaterials(e,a)),a}createLandscape(e){const t=e.landscape?.options;if(null==t)return console.error(`No landscape options exist on scene object ${e.id} ${e.name}`),new h;const a=fe(e.landscape.options);this.applyHeightMaps(a,e.landscape.heightMaps,!0);const s=new ue(e,this.renderingView,a,this.assetManagerService,this.assetsService,this.shaders,t=>{(e.materialAssignments??[]).filter(e=>null!=e.materialId).forEach(e=>this.applyMaterial(t,e))});return this.landscapeManagers.push(s),s.refreshGeometry(),a}applyHeightMaps(e,t,a=!1){const s=new ge(e.sections);for(const e of t??[]){const t=s.find(e.x,e.y);if(!t)return;const a=t.geometry.getAttribute("position");for(const t of e.points)a.setY(t.i,t.y);a.needsUpdate=!0}const r=e.sections;r.forEach(e=>{e.geometry.computeBoundsTree(),e.geometry.computeVertexNormals()}),this.inEditor&&!a||setTimeout(()=>ye(r),50)}async createMeshByShape(e,t,a={}){if("landscape"!==e&&je.includes(e)){const s=await prepareShapeParameters(a??{}),r=e+JSON.stringify(a);if(!this.geometryCache.has(r)){const t=Me[e].geometry(s);t.computeTangents(),this.geometryCache.set(r,t)}this.collisionShapeCache.has(r)||this.collisionShapeCache.set(r,Me[e].collision(s));return new me(this.geometryCache.get(r),t,this.collisionShapeCache.get(r))}if(this.inEditor)throw new Error(`Unsupported shape '${e}'`);console.warn(`Failed to create shape. Unsupported shape '${e}'. This might be because the hology/core library is not compatible with the editor version.`)}async createFromAsset(e){const t=await this.assetsService.getAsset(e.assetId);if(null==t)return void console.warn(`Can not find asset with id ${e.assetId} and name ${e.name}`);let{scene:a}=await this.assetManagerService.getMesh(t,{mergeGeomtries:!0});et(e.materialAssignments,t.materialAssignments).forEach(e=>this.applyMaterial(a,e));const s=e.receiveShadow??!!t.receiveShadow??!0,r=e.castShadow??!!t.castShadow??!1;return a.receiveShadow=s,Ge(a,r,s),e.collisionDetection||(a.collisionShapes=[]),null!=e.physics&&!0!==this.inEditor&&(a.physics=e.physics),this.applyVertexMaterials(e,a),a.traverse(e=>{e instanceof m&&"computeBoundsTree"in e.geometry&&null==e.geometry.boundsTree&&e.geometry.computeBoundsTree()}),a}async createFromPrefab(e,t){const a=await this.assetsService.getAsset(e.assetId);if(null==a)return void console.warn(`Can not find asset with id ${e.assetId} and name ${e.name}`);null==t&&(t={sceneObjectChain:[]}),t.sceneObjectChain.push(e.id);const{object:s}=await this.createFromPrefabAsset(a,t);return t.sceneObjectChain.pop(),s}async createFromPrefabAsset(e,t){const a=new h;await Promise.all(e.prefab.objects.filter(e=>"global_fog"!==e.type&&"world_env"!==e.type).map(e=>this.materialize(e,a,!0,structuredClone(t))));const s=t.sceneObjectChain.join("/"),r=Array.from(this.materializedActors.entries()).filter(([e,a])=>e.startsWith(s)&&e.split("/").length-1===t.sceneObjectChain.length).map(([,e])=>e);r.forEach(e=>{a.add(e.object)}),this.initActorsPostInit(r,structuredClone(t));const i=Array.from(this.materializedActors.entries()).filter(([e,t])=>e.startsWith(s)).map(([,e])=>e);return{object:a,actors:i}}async createParticleSystem(e){const t=await this.assetsService.getAsset(e.assetId),a=new y;return await x.fromJSONAsync(t.particleSystem,r).then(e=>{const t=new P(a,r);e.addRenderer(t),this.renderingView.onLoop(t=>e.update())}),a}async createLight(e){if("point"===e.light.type){const t=new w(e.light.point.color,e.light.point.intensity,e.light.point.distance,e.light.point.decay);if(t.castShadow=e.light.point.castShadow??!0,this.inEditor){const e=(new r.TextureLoader).load("assets/light-bulb-icon.webp"),a=new r.SpriteMaterial({map:e,alphaTest:.5}),s=new Be(a);s.scale.multiplyScalar(.6),t.add(s)}return t}if("spot"===e.light.type){const t=new r.SpotLight(e.light.spot.color,e.light.spot.intensity,e.light.spot.distance,e.light.spot.angle,e.light.spot.penumbra,e.light.spot.decay);if(t.castShadow=e.light.spot.castShadow??!0,t.target=new y,t.target.position.set(0,-1,0),t.add(t.target),this.inEditor){const e=(new r.TextureLoader).load("assets/light-bulb-icon.webp"),a=new r.SpriteMaterial({map:e,alphaTest:.5}),s=new Be(a);s.scale.multiplyScalar(.6),t.add(s),t.add(new r.SpotLightHelper(t))}return t}return"directional"===e.light.type?(this.applyDirectionalLight(e.light.directional,e),new h):"ambient"===e.light.type?(this.applyDirectionalAmbientLight(null,e.light.ambient,e),new h):void 0}applyDirectionalAmbientLight(e,t,a){const s=this.scene.children.find(e=>e.name===xe);null!=s?(s.intensity=t.intensity,s.color.set(t.color),s.groundColor.set(t.color),s.userData.src=a,s.userData.volumetricIntensity=t.volumetricIntensity):console.warn("Couldn't find ambient light")}applyDirectionalLight(e,t){for(const a of this.renderingView.csm.lights)a.intensity=e.intensity,a.color.set(e.color),a.castShadow=e.castShadow,a.userData.src=t,a.userData.volumetricIntensity=e.volumetricIntensity;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe(),this.createAssetSubscription.unsubscribe(),this.materializedActors.forEach(e=>e.disposed.next(!0)),this.materializedActors.clear()}};Re=e([W(),t("design:paramtypes",[b,Object,Object,he,X,Array,Array,Object])],Re);export{Re as SceneMaterializer};function Ge(e,t,a){e.castShadow=t,e.receiveShadow=a,e.traverse(e=>{e.castShadow=t,e.receiveShadow=a})}const Ue=new Map,He=new Map,Je=new u({color:16711935}),qe=new Map;export async function materialFromAsset(e,t,a,s,r,i=!0){const n=JSON.stringify(e.material);return i&&Ue.has(n)?Ue.get(n):i&&He.has(n)?await He.get(n):He.set(n,_materialFromAsset(n,e,t,a,s,r,i)).get(n)}export async function _materialFromAsset(e,t,a,s,i,o,l=!0){const c={opacity:t.material.params.opacity,map:null,emissive:t.material.params.emissive??null,metalness:t.material.params.metalness??0,flatShading:t.material.params.flatShading??!1,color:new n(t.material.params.color),transparent:null!=t.material.params.opacity&&t.material.params.opacity<1},h={};if(null!=t.material.params.map){const e=t.material.params.map,a=await s.getAsset(e);null!=a&&(c.map=await i.getTexture(a))}let d;switch(t.material.type){case"phong":d=new f({...c,...h});break;case"water":d=Ae(c,a);break;case"grassFoliage":d=we({color:c.color,map:c.map},a);break;case"grass":d=ve({...c,colorTwo:new n(t.material.params.colorTwo),colorThree:new n(t.material.params.colorThree)},a);break;case"standard":case"unlit":case"toon":case"layered":case"lambert":case"shader":case"landscape":case"landscape-composite":case"decal-unlit":case"decal-standard":const e={standard:We?Z:ee,lambert:Z,unlit:te,toon:_e,layered:Fe,landscape:Q,"landscape-composite":K,"decal-unlit":Ce,"decal-standard":Ee}[t.material.type]??o.find(e=>e.name==t.material.shader)?.type;if(e){try{let r=new e;const n=await prepareClassParameters(t.material?.shaderParams??{},e,s,i,null,a,o);Object.assign(r,n),d=r.build()}catch(e){console.log("Shader runtime error: "+e),qe.has(t.material.shader)||qe.set(t.material.shader,Je.clone()),d=qe.get(t.material.shader)}d.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),d=Je;break;default:throw new Error("Unsupported material type"+t.material.type)}return a?.csm.setupMaterial(d),null!=a&&Ue.set(e,d),d.side=t.material.side??d.side??r.FrontSide,d.transparent=(t.material.transparent??c.transparent??!1)||d.transparent,d.alphaTest=t.material.alphaTest??d.alphaTest??0,null!=t.material.blending&&(d.blending=J[t.material.blending]??r.NormalBlending),t.material.bloom&&(d.userData.hasBloom=!0),t.material.reflective&&(d.userData.reflective=!0),!0===t.material.outlines&&(d.userData.outlineParameters={},null!=t.material.outlineParams&&(null!=t.material.outlineParams.color&&(d.userData.outlineParameters.color=new n(t.material.outlineParams.color).toArray()),null!=t.material.outlineParams.thickness&&(d.userData.outlineParameters.thickness=t.material.outlineParams.thickness))),d.userData.assetId=t.id,He.delete(e),d}export async function prepareClassParameters(e,t,a,s,r,i,n,o){const l={};for(const[t,c]of Object.entries(e)){const e=await Xe(t,c,a,s,r,i,n,o);null!=e&&(l[t]=e)}return l}export async function prepareShapeParameters(e){const t={};for(const[a,s]of Object.entries(e)){const e=await Xe(a,s,null,null,null);null!=e&&(t[a]=e)}return t}async function Xe(e,t,a,s,r,i,l,c,h=t.value,d=t.type){if(null==t||null==h||""===h)return null;switch(d){case Se.Array:if(Array.isArray(h)&&"element"in t)return await Promise.all(h.map(n=>Xe(e,t,a,s,r,i,l,c,n,t.element)));break;case Se.Number:case Se.FloatNode:let d="string"==typeof h?parseFloat(h):h;return t.type===Se.FloatNode?C(d):d;case Se.Texture:let p=await s.getTexture(await a.getAsset(h));return"envmap"===e.toLowerCase()&&null!=i&&(p=i.getEnvTexture(p)),p;case Se.Sampler2DNode:return F(await s.getTexture(await a.getAsset(h)));case Se.Boolean:return h;case Se.BooleanNode:return I(h);case Se.Vector2:case Se.Vec2Node:if("object"==typeof h){const e=h instanceof Array?(new S).fromArray(h):new S(h.x,h.y);return t.type===Se.Vec2Node?T(e):e}return null;case Se.Vector3:case Se.Vec3Node:if("object"==typeof h){const e=h instanceof Array?(new M).fromArray(h):new M(h.x,h.y,h.z);return t.type===Se.Vec3Node?B(e):e}return null;case Se.Color:case Se.RgbNode:const m=new n(h);return t.type===Se.RgbNode?O(m):m;case Se.String:return h;case Se.BaseActor:const u=h;return null==r&&console.warn("Class parameters can not be prepared as actors are not passed in"),r?.get(u);case Se.Euler:const f=h;return(new o).fromArray(f);case Se.Object3D:return(await s.getMesh(await a.getAsset(h))).scene;case Se.Material:return await materialFromAsset(await a.getAsset(h),i,a,s,l);case Se.AudioBuffer:return await s.getAudio(await a.getAsset(h));case Se.VisualEffect:const g=await a.getAsset(h);if(null==c){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in g)return new R(c,g);console.error("Using a non-vfx asset for visual effect parameter");break;case Se.Curve:return De.decode(h);case Se.ColorLayer:case Se.MaskLayer:if(Te(h)){const e=await Ve.decode(h,async e=>await s.getTexture(await a.getAsset(e))),t=await prepareClassParameters(h.params,null,a,s);return Object.assign(e,t),e}return console.warn("Expecting color layer but got",h),null}return null}function Ye(e){e.updateWorldMatrix(!0,!0),e.updateMatrix(),e.traverse(e=>{e.matrixAutoUpdate=!1,e.matrixWorldNeedsUpdate=!1});const t=e.updateMatrixWorld;e.updateMatrixWorld=function(){t.apply(e),e.updateMatrixWorld=function(){}}}function Ze(e){return"linear"===e.type?new l(new n(e.color),e.near??100,e.far??1e3):"density"===e.type?new c(e.color,e.density):void console.warn("Invalid fog type",e)}const Ke=new g({color:4229780});async function Qe(e,t,a,s){null==s&&(s=(new p).identity()),await t(e,a,s);const i=s.clone().multiply(function(e,t){if(null==e.position||null==e.rotation||null==e.scale)return t.identity();return t.compose((new M).fromArray(e.position),(new v).setFromEuler((new o).fromArray(e.rotation)),(new M).fromArray(e.scale))}(e,new r.Matrix4));return Promise.all((e.children??[]).map(a=>Qe(a,t,e,i)))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?Se.Number:t instanceof E||"function"==typeof e.prototype.isFloat?Se.FloatNode:t instanceof A||e===A||e.isTexture?Se.Texture:t instanceof Y||e===N?Se.Sampler2DNode:t instanceof Boolean||e===Boolean?Se.Boolean:t instanceof D?Se.BooleanNode:t instanceof n||e==n?Se.Color:t instanceof k||"function"==typeof e.prototype.isRgb?Se.RgbNode:t instanceof S||e==S?Se.Vector2:t instanceof z||"function"==typeof e.prototype.isVec2?Se.Vec2Node:t instanceof M||e==M?Se.Vector3:t instanceof _||"function"==typeof e.prototype.isVec3?Se.Vec3Node:t instanceof String||e===String?Se.String:t instanceof G||e==G||e.prototype instanceof G||e.prototype==G?Se.BaseActor:t instanceof o||e==o?Se.Euler:t instanceof y||e==y?Se.Object3D:t instanceof d||e==d?Se.Material:t instanceof AudioBuffer||e==AudioBuffer?Se.AudioBuffer:t instanceof R||e==R?Se.VisualEffect:t instanceof De||e==De?Se.Curve:t instanceof Ve||e==Ve?Se.ColorLayer:t instanceof Ne||e==Ne?Se.MaskLayer:void console.warn("Failed to map parameter type to serialized version",{type:e})}export function prepareCustomParams(e,t,a={}){return Object.fromEntries(e.map(e=>[e.name,{type:e.options.array?Se.Array:toSerializedParamType(e.type),...e.options.array?{element:toSerializedParamType(e.type)}:{},value:t[e.name]?.value??(!0!==e.options.array?a[e.name]??customParameterDefaultValueByType.get(toSerializedParamType(e.type)):[])}]))}export function prepareCustomParamsFromType(e,t,a=null){const s=ae(e);if(0===s.length)return{};let r;null!=a?q(a,()=>{r=a.get(e)}):r=new e;const i={};for(const e of s){const t=r[e.name];if(null!=t&&!0!==e.options.array){const a=serializeCustomParameter(e.type,t);null!=a&&(i[e.name]=a)}}return prepareCustomParams(s,t,i)}export function serializeCustomParameter(e,t){function a(){console.error("Failed to serialize value",{type:e,value:t})}switch(e){case Number:case Boolean:return t;case S:return t instanceof S?t.toArray():void a();case M:return t instanceof M?t.toArray():void a();case j:return t instanceof j?t.toArray():void a();case n:return t instanceof n?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new n(t).getHexString():void a();case String:return t;case o:return t instanceof o?t.toArray():void a()}}function et(e,t){return function(e,t,a){const s=[],r=new Set;for(const i of[...e??[],...t??[]]){const e=a(i);r.has(e)||(r.add(e),s.push(i))}return s}((e??[]).filter(e=>tt(e.materialId)),(t??[]).filter(e=>tt(e.materialId)),e=>e.color+e.name)}function tt(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[Se.RgbNode,"#000000"],[Se.Color,"#000000"],[Se.Vector4,[0,0,0,0]],[Se.Vec4Node,[0,0,0,0]],[Se.Vector3,[0,0,0]],[Se.Vec3Node,[0,0,0]],[Se.Vector2,[0,0]],[Se.Vec2Node,[0,0]],[Se.Euler,[0,0,0,"XYZ"]],[Se.Array,[]],[Se.ColorLayer,Oe],[Se.MaskLayer,ke]]);export function applyMaterial(e,t,a,s){const i=[];return e.traverse(async e=>{if(e instanceof m||e.isMesh||e instanceof r.SkinnedMesh||e.isSkinnedMesh)for(const t of ie(e.material))t.hasOwnProperty("color")&&i.push(e)}),Promise.all(i.map(async e=>{if(e.material instanceof Array)for(let r=0;r<e.material.length;r++){const i=e.material[r];if(null==i.color||!(i.color instanceof n))continue;const o="#"+i.color.getHexString(),l=i.name;if(o===t.color&&(i.name===t.name||null==t.name)||e.userData["originalColor_"+r]===t.color&&e.userData["originalMaterialName_"+r]===t.name){const i=await a(t.materialId),n=e.material[r];null!=i&&n.id!=i.id&&(e.material[r]=i,e.userData["originalColor_"+r]=e.userData["originalColor_"+r]??o,e.userData["originalMaterialName_"+r]=e.userData["originalMaterialName_"+r]??l,null!=s&&s.set(e.id+"#"+r,n))}}else if("color"in e.material){const r="#"+e.material.color.getHexString(),i=e.material.name;if(r===t.color&&(e.material.name===t.name||null==t.name)||e.userData.originalColor===t.color&&e.userData.originalName===t.name){const n=await a(t.materialId),o=e.material;null!=n&&(e.material=n,e.userData.originalColor=e.userData.originalColor??r,e.userData.originalMaterialName=e.userData.originalMaterialName??i,null!=s&&(s.has(e.id)||s.set(e.id,o)))}}}))}function at(e,t){if(e instanceof r.ShaderMaterial&&t instanceof r.ShaderMaterial){return e.fragmentShader+e.vertexShader==t.fragmentShader+t.vertexShader&&function(e,t){if(e instanceof r.ShaderMaterial&&t instanceof r.ShaderMaterial){for(const a in e.uniforms){if(null==t.uniforms[a])return!1;if(t.uniforms[a].value!==e.uniforms[a].value)return!1}return!0}return!1}(e,t)}return!1}function st(e){if(null!=e){for(let t=0;t<e.array.length;t++)e.setX(t,0);e.needsUpdate=!0}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, Texture } from 'three';
|
|
1
|
+
import { Color, Material, Texture } from 'three';
|
|
2
2
|
import { DecalNodeShader } from '../decal-shader.js';
|
|
3
3
|
export declare class DecalUnlitShader extends DecalNodeShader {
|
|
4
4
|
color: Color;
|
|
@@ -9,5 +9,6 @@ export declare class DecalUnlitShader extends DecalNodeShader {
|
|
|
9
9
|
output(): {
|
|
10
10
|
color: import("three-shader-graph").RgbaNode;
|
|
11
11
|
};
|
|
12
|
+
build(): Material;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=decal-unlit-shader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decal-unlit-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/decal-unlit-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,
|
|
1
|
+
{"version":3,"file":"decal-unlit-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/decal-unlit-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,EAAE,QAAQ,EAA2D,OAAO,EAAqB,MAAM,OAAO,CAAC;AAI5K,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,qBAAa,gBAAiB,SAAQ,eAAe;IACtC,KAAK,EAAE,KAAK,CAAwB;IACtB,OAAO,EAAE,MAAM,CAAI;IAClB,SAAS,EAAE,MAAM,CAAI;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEhC,MAAM;;;IA4BN,KAAK;CAUN"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import{Color as
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{Color as r,Texture as o,BackSide as i}from"three";import{Parameter as a}from"../parameter.js";import{DecalNodeShader as l}from"../decal-shader.js";import{rgb as p,rgba as s,textureSampler2d as n,float as c,AttributeVec3Node as d,varying as h,ifDefApply as m,Vec3ExpressionNode as y}from"three-shader-graph";import{decalAlpha as u,decalUV as g}from"../../shader-nodes/decal.js";export class DecalUnlitShader extends l{constructor(){super(...arguments),this.color=new r("#FFFFFF"),this.opacity=1,this.intensity=1}output(){const t=g,e=h(new d("particleData"));let r=m("IS_PARTICLE",c(this.opacity),()=>e.x);null!=this.alphaMap&&(r=r.multiply(n(this.alphaMap).sample(t).r)),r=r.multiply(u);const o=h(m("IS_PARTICLE",p(this.color),()=>new y("instanceColor")));let i=m("IS_PARTICLE",p(this.color),()=>o.rgb),a=s(i,r);return null!=this.colorMap&&(a=a.multiply(n(this.colorMap).sample(t))),a=s(a.rgb.multiplyScalar(this.intensity),a.a),{color:a}}build(){const t=super.build();return t.depthTest=!0,t.depthWrite=!1,t.userData.isDecal=!0,t.side=i,t}}t([a(),e("design:type",r)],DecalUnlitShader.prototype,"color",void 0),t([a({range:[0,1]}),e("design:type",Number)],DecalUnlitShader.prototype,"opacity",void 0),t([a({range:[0,10]}),e("design:type",Number)],DecalUnlitShader.prototype,"intensity",void 0),t([a(),e("design:type",o)],DecalUnlitShader.prototype,"colorMap",void 0),t([a(),e("design:type",o)],DecalUnlitShader.prototype,"alphaMap",void 0);/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, Material, Texture } from 'three';
|
|
1
|
+
import { Color, Material, Texture, Vector2 } from 'three';
|
|
2
2
|
import { Shader } from '../shader.js';
|
|
3
3
|
export declare class LambertShader extends Shader {
|
|
4
4
|
color: Color;
|
|
@@ -12,6 +12,8 @@ export declare class LambertShader extends Shader {
|
|
|
12
12
|
lightMapIntensity?: number;
|
|
13
13
|
aoMap?: Texture;
|
|
14
14
|
aoMapIntensity?: number;
|
|
15
|
+
normalMap?: Texture;
|
|
16
|
+
normalScale?: Vector2;
|
|
15
17
|
specularMap?: Texture;
|
|
16
18
|
envMap?: Texture;
|
|
17
19
|
reflectivity?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambert-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/lambert-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAwC,OAAO,
|
|
1
|
+
{"version":3,"file":"lambert-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/lambert-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAwC,OAAO,EAAE,OAAO,EAAuB,MAAM,OAAO,CAAC;AACrH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKtC,qBAAa,aAAc,SAAQ,MAAM;IAC1B,KAAK,EAAE,KAAK,CAAwB;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,CAAI;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACzC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,WAAW,CAAC,EAAE,OAAO,CAAoB;IACzC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IAEH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGpD,KAAK,IAAI,QAAQ;CAuBlB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Color as
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Color as a,Texture as i,Vector2 as r,MeshLambertMaterial as p}from"three";import{Shader as o}from"../shader.js";import{Parameter as s}from"../parameter.js";import{removeObjectUndefined as n}from"../../utils/collections.js";export class LambertShader extends o{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.normalScale=new r(1,1)}build(){return new p(n({color:this.color,opacity:this.opacity,emissive:this.emissive,emissiveIntensity:this.emissiveIntensity,emissiveMap:this.emissiveMap,map:this.map,lightMap:this.lightMap,lightMapIntensity:this.lightMapIntensity,aoMap:this.aoMap,aoMapIntensity:this.aoMapIntensity,normalMap:this.normalMap,normalScale:this.normalScale,specularMap:this.specularMap,alphaMap:this.alphaMap,envMap:this.envMap,reflectivity:this.reflectivity,refractionRatio:this.refractionRatio}))}}e([s(),t("design:type",a)],LambertShader.prototype,"color",void 0),e([s({label:"Color Map"}),t("design:type",i)],LambertShader.prototype,"map",void 0),e([s({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"opacity",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"alphaMap",void 0),e([s(),t("design:type",a)],LambertShader.prototype,"emissive",void 0),e([s({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"emissiveIntensity",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"emissiveMap",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"lightMap",void 0),e([s(),t("design:type",Number)],LambertShader.prototype,"lightMapIntensity",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"aoMap",void 0),e([s(),t("design:type",Number)],LambertShader.prototype,"aoMapIntensity",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"normalMap",void 0),e([s(),t("design:type",r)],LambertShader.prototype,"normalScale",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"specularMap",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"envMap",void 0),e([s({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"reflectivity",void 0),e([s({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"refractionRatio",void 0);/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depth.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/depth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"depth.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/depth.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,aAAa,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAA0C,SAAS,EAA2H,QAAQ,EAAkB,MAAM,oBAAoB,CAAC;AAI1O,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,aAAa,WAGpE;AAID,eAAO,MAAM,gBAAgB,qBAAqB,CAAA;AAClD,eAAO,MAAM,qBAAqB,sBAAsB,CAAA;AACxD,eAAO,MAAM,eAAe,uBAAuB,CAAA;AACnD,eAAO,MAAM,cAAc,sBAAsB,CAAA;AAEjD,eAAO,MAAM,YAAY,+CAAkE,CAAA;AA6G3F,eAAO,MAAM,sBAAsB,WAAkB,CAAA;AAGrD,eAAO,MAAM,UAAU,8CAA4D,CAAA;AAEnF,eAAO,MAAM,QAAQ,UAA+D,CAAA;AAEpF,eAAO,MAAM,cAAc,WAA+B,CAAA;AAgB1D;;GAEG;AACH,eAAO,MAAM,kBAAkB,uCAAkC,CAAA;AASjE;;GAEG;AACH,eAAO,MAAM,WAAW,uCAAyF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import*as t from"three";import{Vector2 as e}from"three";import{cross as o,dot as r,float as n,FloatExpressionNode as s,FloatNode as c,inverse as a,normalize as i,texture2d as p,uniformFloat as l,uniforms as h,uniformSampler2d as u,uniformVec2 as d,varying as m,vec2 as x,Vec2ExpressionNode as f,vec4 as _,Vec4Node as U}from"three-shader-graph";export function supportsDepthTextureExtension(t){return!0}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=u(depthUniformName,new t.DepthTexture(1,1));const g=l(nearUniformName,.5),k=l(farUniformName,500);class y extends c{compile(t){const e=t.variable();var o=t.get(g),r=t.get(k);return{chunk:`\n float depth_${e} = 2.0 * ${o} * ${r} / (${r} + ${o} - (2.0 * ${t.get(this.depth)} - 1.0) * (${r} - ${o}));\n `,out:`depth_${e}`}}constructor(t){super(),this.depth=t}}function $(t){return new y(t)}new class extends U{constructor(){super(...arguments),this.k="31u50"}compile(t){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}`}}};function v(t){return p(depthSampler,t).r}const w=new s("gl_FragCoord.z");export const fragmentLinearEyeDepth=$(w);export const resolution=d("hology_resolution",new e(250,1e3));export const screenUV=new f("gl_FragCoord.xy").divide(resolution);export const linearEyeDepth=$(v(screenUV));const N=m(a(h.projectionMatrix)),V=m(a(h.viewMatrix));function F(t=screenUV){const e=v(t).multiply(2).subtract(1),o=t.multiplyScalar(2).subtractScalar(1),r=_(o.x,o.y,e,1),n=N.multiplyVec(r),s=n.xyz.divideScalar(n.w);return V.multiplyVec(_(s,1)).xyz}export const depthWorldPosition=F(screenUV);const b=n(1).divide(resolution.x),D=n(1).divide(resolution.y),P=F(screenUV.add(x(b,n(0)))),S=F(screenUV.add(x(n(0),D)));export const depthNormal=i(o(P.subtract(depthWorldPosition),S.subtract(depthWorldPosition)));/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|