@hology/core 0.0.95 → 0.0.96

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.
Files changed (48) hide show
  1. package/dist/effects/vfx/initializsers.d.ts +6 -2
  2. package/dist/effects/vfx/initializsers.d.ts.map +1 -1
  3. package/dist/effects/vfx/initializsers.js +1 -1
  4. package/dist/effects/vfx/vfx-actor.d.ts +1 -1
  5. package/dist/effects/vfx/vfx-defs.d.ts +35 -0
  6. package/dist/effects/vfx/vfx-defs.d.ts.map +1 -1
  7. package/dist/effects/vfx/vfx-defs.js +1 -1
  8. package/dist/effects/vfx/vfx-materializer.d.ts +2 -1
  9. package/dist/effects/vfx/vfx-materializer.d.ts.map +1 -1
  10. package/dist/effects/vfx/vfx-materializer.js +1 -1
  11. package/dist/effects/vfx/vfx-renderers.d.ts +1 -0
  12. package/dist/effects/vfx/vfx-renderers.d.ts.map +1 -1
  13. package/dist/effects/vfx/vfx-renderers.js +1 -1
  14. package/dist/gameplay/actors/builtin/navmesh-actor.d.ts.map +1 -1
  15. package/dist/gameplay/actors/builtin/navmesh-actor.js +1 -1
  16. package/dist/gameplay/ai/behavior-tree/move.js +1 -1
  17. package/dist/gameplay/ai/navigation.d.ts +8 -0
  18. package/dist/gameplay/ai/navigation.d.ts.map +1 -1
  19. package/dist/gameplay/ai/navigation.js +1 -1
  20. package/dist/rendering.d.ts +1 -0
  21. package/dist/rendering.d.ts.map +1 -1
  22. package/dist/rendering.js +1 -1
  23. package/dist/scene/landscape/landscape-manager.d.ts.map +1 -1
  24. package/dist/scene/landscape/landscape-manager.js +1 -1
  25. package/dist/scene/materializer.d.ts.map +1 -1
  26. package/dist/scene/materializer.js +1 -1
  27. package/dist/scene/model.d.ts +1 -1
  28. package/dist/scene/model.d.ts.map +1 -1
  29. package/dist/shader/builtin/decal-standard-shader.d.ts +24 -0
  30. package/dist/shader/builtin/decal-standard-shader.d.ts.map +1 -0
  31. package/dist/shader/builtin/decal-standard-shader.js +4 -0
  32. package/dist/shader/builtin/decal-unlit-shader.d.ts +12 -0
  33. package/dist/shader/builtin/decal-unlit-shader.d.ts.map +1 -0
  34. package/dist/shader/builtin/decal-unlit-shader.js +4 -0
  35. package/dist/shader/decal-shader.d.ts +7 -0
  36. package/dist/shader/decal-shader.d.ts.map +1 -0
  37. package/dist/shader/decal-shader.js +4 -0
  38. package/dist/shader-nodes/decal.d.ts +8 -0
  39. package/dist/shader-nodes/decal.d.ts.map +1 -0
  40. package/dist/shader-nodes/decal.js +4 -0
  41. package/dist/shader-nodes/depth.d.ts +8 -0
  42. package/dist/shader-nodes/depth.d.ts.map +1 -1
  43. package/dist/shader-nodes/depth.js +1 -1
  44. package/dist/shader-nodes/index.d.ts +1 -0
  45. package/dist/shader-nodes/index.d.ts.map +1 -1
  46. package/dist/shader-nodes/index.js +1 -1
  47. package/package.json +3 -3
  48. package/tsconfig.tsbuildinfo +1 -1
package/dist/rendering.js CHANGED
@@ -1,4 +1,4 @@
1
- var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as h,ShaderChunk as l,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as m,GammaCorrectionShader as p,RenderPass as u,ShaderPass as f,UnrealBloomPass as g,VRButton as v}from"three-stdlib";import{CSMShader as x,CSMUtil as w}from"./csm.js";import{NodeShaderMaterial as b}from"three-shader-graph";import{Reflector as y}from"three-stdlib";import{OutputPass as T}from"three/examples/jsm/Addons.js";import{CSM as M}from"three/examples/jsm/csm/CSM.js";import C from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as P}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as R}from"typedi";import{depthUniformName as S,farUniformName as D,nearUniformName as F,resolutionUniformName as W,supportsDepthTextureExtension as A}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as H}from"./shader-nodes/time.js";import{DepthPass as L}from"./utils/three/depth-pass.js";import{GPUStatsPanel as k}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as O}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as j}from"./utils/three/traverse.js";(new s.Layers).set(9);const E=new s.MeshBasicMaterial({color:"black"}),B=new s.MeshDepthMaterial;B.depthPacking=s.RGBADepthPacking,B.blending=s.NoBlending,B.side=s.DoubleSide;const U=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let V=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof h&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture)}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=U?.5:1,this.maxPixelRatio=U?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new C,this._showStats=!0,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(v.createButton(this.renderer)),this.composer=new c(this.renderer);var n=t.clientWidth/t.clientHeight;const a=new s.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=A(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container);const o=new u(this.scene,this.camera);this.composer.addPass(o);const h=new g(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=0,h.strength=.9,h.radius=1;const l=new P(this.scene,this.camera,t.clientWidth,t.clientWidth);l.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},l.blendMaterial.uniforms.tAODepth={value:l.depthTexture},l.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 ",l.output=P.OUTPUT.Default,l.enabled=!1,this.aoPass=l,!1!==this.options.ao?.enabled&&this.composer.addPass(l),this.renderer.info.autoReset=!1;const d=new c(this.renderer);d.renderToScreen=!1,d.addPass(o),d.addPass(h),this.bloomComposer=d;const x=new f(new s.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");if(x.needsSwap=!0,this.composer.addPass(x),this.outlinePass=new O(new s.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new f(m);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}new f(p).clear=!1,this.fixStatsStyle();const b=new T;this.composer.addPass(b)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof u?t.camera=e:t instanceof O?t.renderCamera=e:(t instanceof L||t instanceof P)&&(t.camera=e)})),null==this.csm?(this.csm=new M({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),l.lights_fragment_begin=x.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof h&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const i=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:s.HalfFloatType});return i.texture.minFilter=s.NearestFilter,i.texture.magFilter=s.NearestFilter,i.texture.generateMipmaps=!1,i.stencilBuffer=!1,i.depthTexture=new s.DepthTexture(128,128),i.depthTexture.type=s.UnsignedInt248Type,i.depthTexture.minFilter=s.NearestFilter,i.depthTexture.magFilter=s.NearestFilter,i}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.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof b&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const i=this.stats,r=i.addPanel(new C.Panel("Calls","#83f","#002")),h=i.addPanel(new C.Panel("Triangles","#c32","#002"));let l;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(l=new k(this.renderer.getContext()),i.addPanel(l)),this.showStats=t;let d=10,c=1e3;const m=()=>{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)),h.update(t,c)};performance.now();s.Ray.prototype.intersectTriangle;const p=[],u=[];let f=0;const g=new a,v=new a,x=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>x(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let a=(t*=.001)-f;if(f=t,g.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(),v.copy(this.camera.matrixWorld),v.equals(g)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),p.length=0,u.length=0;const h=_;if(this.camera.updateMatrixWorld(),N.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(N),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof s.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const i of e.material)t(i);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[S])&&isObjectInFrustum(e,h)?(e.visible=!1,p.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof y?(e.visible=!1,u.push(e)):(e instanceof o||e instanceof s.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e)&&(e.visible=!1,e.layers.enable(5),u.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[H])e.material.uniforms[H].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const i of e.material)i.uniforms&&null!=i.uniforms[H]&&(i.uniforms[H].value=t)})),p.length>0){if(this.scene.overrideMaterial=B,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(p.forEach((e=>e.visible=!0)),u.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=B,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}try{!this.paused&&this.running&&(this.showStats&&l?.startQuery(),this.render(a),this.showStats&&l?.endQuery(),this.showStats&&m(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(x)}),1e3/this.fpsCap):requestAnimationFrame(x))};!0===this.options.enableXR?this.renderer.setAnimationLoop(x):requestAnimationFrame(x)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){const t=this.hasBloom();if(t||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e))),this.bloomComposer.render(),this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=t,this.composer.render(e)}hasBloom(){return null!=j(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){(e instanceof o||e instanceof s.Sprite||e instanceof s.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)?(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=E:e.visible=!1):"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[S].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof h&&(e.uniforms[F].value=this.camera.near,e.uniforms[D].value=this.camera.far))}};V=e=t([R(),i("design:paramtypes",[HTMLElement,Object])],V);export{V as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const z=.05;P.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 i of e.material)if(null!=i.alphaTest&&i.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const _=new s.Frustum,I=new s.Box3,N=new s.Matrix4;export function isObjectInFrustum(e,t){const i=I.setFromObject(e);return t.intersectsBox(i)}/*
1
+ var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as h,ShaderChunk as l,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as m,GammaCorrectionShader as p,RenderPass as u,ShaderPass as f,UnrealBloomPass as g,VRButton as v}from"three-stdlib";import{CSMShader as x,CSMUtil as w}from"./csm.js";import{NodeShaderMaterial as b}from"three-shader-graph";import{Reflector as T}from"three-stdlib";import{OutputPass as y}from"three/examples/jsm/Addons.js";import{CSM as M}from"three/examples/jsm/csm/CSM.js";import C from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as R}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as P}from"typedi";import{depthUniformName as S,farUniformName as D,nearUniformName as F,resolutionUniformName as W,supportsDepthTextureExtension as A}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as H}from"./shader-nodes/time.js";import{DepthPass as L}from"./utils/three/depth-pass.js";import{GPUStatsPanel as k}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as O}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as j}from"./utils/three/traverse.js";(new s.Layers).set(9);const E=new s.MeshBasicMaterial({color:"black"}),B=new s.MeshDepthMaterial;B.depthPacking=s.RGBADepthPacking,B.blending=s.NoBlending,B.side=s.DoubleSide;const U=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let z=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof h&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.bloomComposer.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))}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=U?.5:1,this.maxPixelRatio=U?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new C,this._showStats=!0,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(v.createButton(this.renderer)),this.composer=new c(this.renderer);var n=t.clientWidth/t.clientHeight;const a=new s.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=A(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container);const o=new u(this.scene,this.camera);this.composer.addPass(o);const h=new g(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=0,h.strength=.9,h.radius=1,this.bloomPass=h;const l=new R(this.scene,this.camera,t.clientWidth,t.clientWidth);l.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},l.blendMaterial.uniforms.tAODepth={value:l.depthTexture},l.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 ",l.output=R.OUTPUT.Default,l.enabled=!1,this.aoPass=l,!1!==this.options.ao?.enabled&&this.composer.addPass(l),this.renderer.info.autoReset=!1;const d=new c(this.renderer);d.renderToScreen=!1,d.addPass(o),d.addPass(h),this.bloomComposer=d;const x=new f(new s.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");if(x.needsSwap=!0,this.composer.addPass(x),this.outlinePass=new O(new s.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new f(m);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}new f(p).clear=!1,this.fixStatsStyle();const b=new y;this.composer.addPass(b)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof u?t.camera=e:t instanceof O?t.renderCamera=e:(t instanceof L||t instanceof R)&&(t.camera=e)})),null==this.csm?(this.csm=new M({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),l.lights_fragment_begin=x.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof h&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const i=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:s.HalfFloatType});return i.texture.minFilter=s.NearestFilter,i.texture.magFilter=s.NearestFilter,i.texture.generateMipmaps=!1,i.stencilBuffer=!1,i.depthTexture=new s.DepthTexture(128,128),i.depthTexture.type=s.UnsignedInt248Type,i.depthTexture.minFilter=s.NearestFilter,i.depthTexture.magFilter=s.NearestFilter,i}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.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof b&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const i=this.stats,r=i.addPanel(new C.Panel("Calls","#83f","#002")),h=i.addPanel(new C.Panel("Triangles","#c32","#002"));let l;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(l=new k(this.renderer.getContext()),i.addPanel(l)),this.showStats=t;let d=10,c=1e3;const m=()=>{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)),h.update(t,c)};performance.now();s.Ray.prototype.intersectTriangle;const p=[],u=[];let f=0;const g=new a,v=new a,x=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>x(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let a=(t*=.001)-f;if(f=t,g.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(V),t-=V;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),v.equals(g)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),p.length=0,u.length=0;const h=_;if(this.camera.updateMatrixWorld(),N.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(N),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof s.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const i of e.material)t(i);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[S])&&isObjectInFrustum(e,h)?(e.visible=!1,p.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof T?(e.visible=!1,u.push(e)):(e instanceof o||e instanceof s.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e)&&(e.visible=!1,e.layers.enable(5),u.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[H])e.material.uniforms[H].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const i of e.material)i.uniforms&&null!=i.uniforms[H]&&(i.uniforms[H].value=t)})),p.length>0){if(this.scene.overrideMaterial=B,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(p.forEach((e=>e.visible=!0)),u.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=B,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}try{!this.paused&&this.running&&(this.showStats&&l?.startQuery(),this.render(a),this.showStats&&l?.endQuery(),this.showStats&&m(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(x)}),1e3/this.fpsCap):requestAnimationFrame(x))};!0===this.options.enableXR?this.renderer.setAnimationLoop(x):requestAnimationFrame(x)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){const t=this.hasBloom();if(t||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e))),this.bloomComposer.render(),this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=t,this.composer.render(e)}hasBloom(){return null!=j(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){(e instanceof o||e instanceof s.Sprite||e instanceof s.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)?(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=E:e.visible=!1):"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[S].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof h&&(null!=e.uniforms[F]&&(e.uniforms[F].value=this.camera.near),null!=e.uniforms[D]&&(e.uniforms[D].value=this.camera.far)))}};z=e=t([P(),i("design:paramtypes",[HTMLElement,Object])],z);export{z as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const V=.05;R.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 i of e.material)if(null!=i.alphaTest&&i.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const _=new s.Frustum,I=new s.Box3,N=new s.Matrix4;export function isObjectInFrustum(e,t){const i=I.setFromObject(e);return t.intersectsBox(i)}/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"landscape-manager.d.ts","sourceRoot":"","sources":["../../../src/scene/landscape/landscape-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,eAAe,EAA+D,IAAI,EAA8G,OAAO,EAAE,MAAM,OAAO,CAAC;AACtO,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAmB,WAAW,EAAqB,MAAM,6BAA6B,CAAC;AAE9F,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIpD,OAAO,EAAE,mBAAmB,EAAc,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAiE,MAAM,gBAAgB,CAAC;AAK/G,eAAO,MAAM,0BAA0B,MAAM,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AmB,EAAU,YAAY,EAAE,cAAc,EAAU,OAAO,EAAE,UAAU,EAAE,EAAU,aAAa,EAAE,CAAC,MAAM,EAAE,IAAI,KAAK,IAAI;IAgC9P,YAAY,CAAC,MAAM,EAAE,WAAW;IAIhC,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE;IAI1C,OAAO,CAAC,YAAY,CAAmC;IAEvD,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,aAAa,CAAU;YAGjB,SAAS;IAkBhB,eAAe;IAiGtB,OAAO,CAAC,cAAc;IA0BtB,OAAO,CAAC,sBAAsB;IAsB9B,OAAO,CAAC,OAAO,CAAgB;IAExB,mBAAmB,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,GAAE,OAAe,EAAE,SAAS,GAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAoB;IAKnH,OAAO,CAAC,oBAAoB,CAAoC;IAGnD,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,GAAE,OAAe,EAAE,SAAS,GAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAoB;IAsb7G,IAAI;IAKX,OAAO,CAAC,mBAAmB,CAAgB;IAC3C,OAAO,CAAC,eAAe,CAAgB;IAEvC,OAAO,CAAC,MAAM;IAaP,KAAK;IAIZ,OAAO,CAAC,mBAAmB;CA0C5B;AAGD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,UAAQ,GAAG,eAAe,CAM9E"}
@@ -1,4 +1,4 @@
1
- import{Subject as e,debounceTime as t}from"rxjs";import{Box3 as s,BufferAttribute as n,InstancedMesh as o,MathUtils as i,Matrix4 as a,Mesh as r,MeshStandardMaterial as c,PerspectiveCamera as l,PlaneGeometry as h,ShaderMaterial as u,Triangle as f,Vector2 as p,Vector3 as m}from"three";import{materialFromAsset as d}from"../../scene/materializer.js";import{getMaterialAttribute as w}from"../../scene/materials/utils/material-painting";import{whenIdle as g}from"../../utils/async.js";import{indexBy as y}from"../../utils/collections.js";import{meanVectors3withWeight as M}from"../../utils/math.js";import{LandscapeMesh as x,defaultLandscapeMaterial as b}from"./landscape.js";import{smoothNormalsCrossMeshes as S}from"./utils.js";export const grassGeometryTriangleLimit=400;new m,new m;const v=new m,A=new m,z=new m;export class LandscapeManager{constructor(s,n,o,i,r,c,l){this.view=n,this.landscape=o,this.assetManagerService=i,this.assetService=r,this.shaders=c,this.applyMaterial=l,this.scatterMeshes=new Map,this.loadedScatterSquares=new Set,this.refreshRequests=new e,this.defaultLandscapeMaterial=b.clone(),this.scatterMeshPool=[],this.onLoopHandler=()=>this.update(),this.sectionCache=new Map,this._matrix=new a,this.scatterGeometryCache=new Map,this._lastUpdatePosition=new m,this._cameraPosition=new m,this.source=JSON.parse(JSON.stringify(s)),this.view.onLoop(this.onLoopHandler),this.defaultLandscapeMaterial.name=b.name,this.defaultLandscapeMaterial.color=b.color,this.refreshRequests.pipe(t(500)).subscribe((e=>this.refreshScatter(e.origin,e.force,e.predicate)))}updateSource(e){this.source=JSON.parse(JSON.stringify(e))}updateShaders(e){this.shaders=e}async loadGrass(){const e=await this.assetService.getAsset("6ij937n72g");await this.assetManagerService.getMesh(e);this.grassGeometry=new h(2,2,3,3);const t=this.grassGeometry.getAttribute("normal");for(let e=0;e<t.count;e++)t.setXYZ(e,0,1,0);t.needsUpdate=!0,this.grassMaterial=new c({color:3765785})}refreshGeometry(){const e=this.source.landscape.options,t=(new m,new m);this.view.camera.getWorldPosition(t);const s=[];z.fromArray(this.source.position);const n=this.view.camera instanceof l?Math.min(this.view.camera.far,1e3):1e3,o=1.1*n,i=e.sections.y*e.sectionSize/-2,a=e.sections.x*e.sectionSize/-2;for(let r=0;r<e.sections.x;r++)if(v.x=a+r*e.sectionSize,!(Math.abs(t.x-v.x)>o))for(let c=0;c<e.sections.y;c++){v.z=i+c*e.sectionSize,A.copy(z).add(v);const l=A.distanceTo(t),h=`${r},${c}`,u=this.landscape.sections.find((e=>e.x===r&&e.y===c));if(l<=n){if(null==u){this.sectionCache.has(h)||this.sectionCache.set(h,this.createLandscapeMesh(this.source,e,a,i,r,c));const t=this.sectionCache.get(h);this.applyMaterial(t),this.landscape.add(t),s.push(t)}}else l>o&&this.landscape.remove(u)}S(s)}applyHeightMap(e,t,s,n=1){const o=Math.pow(s+1,2),i=e.getAttribute("position");if(1===n)for(const e of t.points)i.setY(e.i,e.y);else{const e=y(t.points??[],(e=>e.i));for(let t=0;t<i.count;t++){const s=P(t,i.count,o);let n=0;n=s%1==0?e.get(s)?.y??0:Math.floor(e.get(s)?.y),i.setY(t,n)}}i.needsUpdate=!0,e.computeVertexNormals()}deleteOldScatterMeshes(){const e=new Set;for(const[t,s]of this.source.grass?.layers.entries()??[])for(const[n,o]of s.meshes.entries()){const s=`${t}-${n}`;e.add(s)}for(const t of this.scatterMeshes.keys())if(!e.has(t)){this.scatterMeshes.get(t).forEach((e=>{e.parent?.remove(e),e.dispose()})),this.scatterMeshes.delete(t)}}queueRefreshScatter(e,t=!1,s=()=>!0){this.refreshRequests.next({origin:e,force:t,predicate:s})}async refreshScatter(e,t=!1,s=()=>!0){t&&this.scatterGeometryCache.clear(),this.deleteOldScatterMeshes();for(const[n,a]of this.source.grass?.layers.entries()??[])for(const[c,l]of a.meshes.entries()){const a=`${n}-${c}`;this.scatterMeshes.has(a)||this.scatterMeshes.set(a,new Map);const h=this.scatterMeshes.get(a),u=await this.assetService.getAsset(l.assetId);if(null==u){console.error(`Can not find asset with id ${l.assetId}`);continue}let p;try{p=await this.assetManagerService.getMesh(u)}catch(e){console.error(`Failed to load mesh in landscape manager for asset with name ${u.name}`,e);continue}const w=[];if(p.scene.traverse((e=>{e instanceof r&&w.push(e)})),1!==w.length){console.log(p),console.warn("Dynamic grass only works for meshes with a single geometry.");continue}if(!(w[0]instanceof r)){console.warn("Only meshes can be used for dynamic grass. Found:",p.scene);continue}const x=w[0];let b=x.geometry;this.scatterGeometryCache.has(x.geometry.uuid)?b=this.scatterGeometryCache.get(x.geometry.uuid):(b=x.geometry.clone(),!0===l.normalsUp&&F(b),null==b.userData.updatedMatrix&&(p.scene.updateMatrixWorld(),b.applyMatrix4(x.matrixWorld),b.userData.updatedMatrix=!0));const S=b.getIndex()??b.getAttribute("position"),v=null!=S?S.count/3:0;if(v>400){console.warn(`The triangle count of ${u.name} is too big ${v}. Keep it below 400`);continue}const A=null!=u.materialAssignments&&u.materialAssignments.length>0?u.materialAssignments[0].materialId:null,z=null!=A&&"null"!==A?await d(await this.assetService.getAsset(A),null,this.assetService,this.assetManagerService,this.shaders,!1):null;let P=null!=z?z:x.material;const L=i.degToRad(l.maxSlope??90),_=Math.cos(L),T=this.landscape.sections,q=T.filter(j(e,l.viewDistance)),I=q.filter((e=>!h.has(e.uuid)||t)).filter((e=>s(e)));T.filter($(e,2*l.viewDistance)).forEach((e=>{const t=h.get(e.uuid);null!=t&&(t.visible=!1)}));for(const e of q){const t=h.get(e.uuid);null!=t&&(t.visible=!0)}performance.now();const R=this.source.landscape.options,k=R.sectionSize,D=l.density??1??1,H=R.density,X=k/H,Y=D,E=X/Math.sqrt(Y),J=Math.pow(H,2),Z=E/X,K=Math.floor(J*Y),V=[0,0,0];for(const e of I)await g((async()=>{e.updateWorldMatrix(!0,!1);const s=this._matrix,i=new m,a=e.geometry.getAttribute("position"),r=e.geometry.getAttribute("normal"),c=(this.source.vertexMaterials??[]).filter((t=>t.m===e.name)),p=y(c,(e=>e.i));let d=h.get(e.uuid);if(null==d||d.count==K&&!t||(d.parent?.remove(d),this.scatterMeshPool.push(d),h.delete(e.uuid),d=null),null==d){const e=this.scatterMeshPool.findIndex((e=>e.count>=K));e>-1?(d=this.scatterMeshPool[e],d.geometry=b,d.material=P,this.scatterMeshPool.splice(e,1)):d=new o(b,P,K),d.raycast=()=>{},d.receiveShadow=!0}d.visible=!0;const w=new f(new m,new m,new m);let[g,x,S,v]=[new m,new m,new m,new m],[A,z,L]=[[],[],[]],[$,j,T]=[new m,new m,new m,new m];const q=new m,I=new m,R=new m,k=new m,D=new f(new m,new m,new m),F=new f(new m,new m,new m),X=new f(new m,new m,new m),E=new f(new m,new m,new m);let Q=0;e:for(let t=0;t<J;t++){const o=Math.floor(t/H);g.fromBufferAttribute(a,t+o),k.copy(g).applyMatrix4(e.matrixWorld),D.a.copy(g),D.b.fromBufferAttribute(a,t+1+o),D.c.fromBufferAttribute(a,t+H+1+o),F.a.copy(D.b),F.b.copy(D.c),F.c.fromBufferAttribute(a,t+H+2+o),X.a.fromBufferAttribute(r,t+o),X.b.fromBufferAttribute(r,t+1+o),X.c.fromBufferAttribute(r,t+H+1+o),E.a.copy(X.b),E.b.copy(X.c),E.c.fromBufferAttribute(r,t+H+2+o);const c=[];c[0]=p.get(t+o)?.w,c[1]=p.get(t+1+o)?.w,c[2]=p.get(t+H+1+o)?.w,c[3]=p.get(t+H+2+o)?.w;let h=0;for(let e=0;e<=1+Z;e+=Z)for(let t=0;t<=1+Z;t+=Z){if(Q>K)break e;if(h++,h>Y)continue e;1-e>t?(x=D.a,S=D.b,v=D.c,$=X.a,j=X.b,T=X.c,A=c[0],z=c[1],L=c[2]):(x=F.a,S=F.b,v=F.c,$=E.a,j=E.b,T=E.c,A=c[1],z=c[2],L=c[3]),w.a.copy(x),w.b.copy(S),w.c.copy(v),B(w),q.set(g.x,0,g.z),U(w,q),w.getBarycoord(q,i).toArray(V),C[0]=A,C[1]=z,C[2]=L;if(G(C,V,.2)!==n-1)continue;if(M([x,S,v],V,I),M([$,j,T],V,R),null!=l.maxSlope&&l.maxSlope<90&&R.y<_)continue;const o=I;o.y+=O(l.offsetMin,l.offsetMax);const a=O(l.scaleMin,l.scaleMax)*(u.mesh.rescale??1);s.makeScale(a,a,a);const r=s.elements;r[12]=o.x,r[13]=o.y,r[14]=o.z,!1!==l.randomRotation&&N(s,a),l.alignToNormal&&W(s,o,d.matrixWorld,R);const f=d.instanceMatrix.array,p=16*Q;f[p]=r[0],f[p+1]=r[1],f[p+2]=r[2],f[p+3]=r[3],f[p+4]=r[4],f[p+5]=r[5],f[p+6]=r[6],f[p+7]=r[7],f[p+8]=r[8],f[p+9]=r[9],f[p+10]=r[10],f[p+11]=r[11],f[p+12]=r[12],f[p+13]=r[13],f[p+14]=r[14],f[p+15]=r[15],Q++}}d.count=Q,d.instanceMatrix.needsUpdate=!0,d.position.copy(e.position),d.updateMatrix(),h.has(e.uuid)||this.landscape?.add(d),h.set(e.uuid,d),d.userData.meshConfig=l}));performance.now()}}stop(){this.view.removeOnLoop(this.onLoopHandler)}update(){this.view.camera&&(this.view.camera.getWorldPosition(this._cameraPosition),this._cameraPosition.distanceTo(this._lastUpdatePosition)>10&&(this._lastUpdatePosition.copy(this._cameraPosition),this.refreshGeometry(),this.refreshScatter(this._cameraPosition)))}clear(){this.scatterMeshes.forEach((e=>e.forEach((e=>e.parent?.remove(e)))))}createLandscapeMesh(e,t,s,n,o,i){const a=new h(t.sectionSize,t.sectionSize,t.density,t.density);a.rotateX(Math.PI/-2);const r=this.defaultLandscapeMaterial,c=new x(a,r);c.position.x=s+o*t.sectionSize,c.position.z=n+i*t.sectionSize,c.receiveShadow=!0,c.castShadow=!1,c.userData.landscape={x:o,y:i},c.x=o,c.y=i,c.name=`${o},${i}`,w(c,0,!0),w(c,4,!0);const l=e.landscape.heightMaps.find((e=>e.x===o&&e.y===i));if(null!=l&&this.applyHeightMap(a,l,t.density,1),a.computeBoundsTree(),null!=e.landscape.holes&&e.landscape.holes.length>0){const t=getHoleAttribute(c,!0);for(const s of e.landscape.holes)s.m===c.name&&t.setX(s.i,s.w[0])}return c}}export function getHoleAttribute(e,t=!1){if(!e.geometry.hasAttribute("hole")||t){const t=new Float32Array(e.geometry.getAttribute("position").array.length);e.geometry.setAttribute("hole",new n(t,1))}return e.geometry.getAttribute("hole")}function P(e,t,s){const n=Math.sqrt(t),o=Math.floor(e/n)/(n-1),i=e%n/(n-1),a=Math.sqrt(s);return(s-1)*o-(a-1)*o+(a-1)*i}new Map,new p(0,0),new p(1,0),new p(0,1),new p(1,0),new p(0,1),new p(1,1),new m;const L=new s;function $(e,t){return function(s){return L.setFromObject(s).distanceToPoint(e)>t}}function j(e,t){return function(s){return L.setFromObject(s).distanceToPoint(e)<t}}function B(e){e.a.y=0,e.b.y=0,e.c.y=0}const C=[];function G(e,t,s=.5){const n=C;let o=-1,i=-1;for(let e=0;e<n.length;e++)if(null!=n[e])for(let a=0;a<n[e].length;a++){const r=n[e][a]*t[e];r>s&&r>i&&(i=r,o=a)}return o}function O(e,t){let s=t-e,n=q();return n*=s,n+=e,n}const _=[];let T=1e3;for(;T--;)_.push(Math.random());function q(){return++T>=_.length?_[T=0]:_[T]}const I=[];let R=20;for(;R--;)I.push((new a).makeRotationY(q()*Math.PI/2));function U(e,t){let s=q(),n=q();s+n>1&&(s=1-s,n=1-n);const o=e.a,i=e.b,a=e.c;t.x=o.x+s*(i.x-o.x)+n*(a.x-o.x),t.z=o.z+s*(i.z-o.z)+n*(a.z-o.z)}new m;new m;const k=new m,D=new m(0,1,0),H=(new a).makeRotationX(Math.PI/-2);function W(e,t,s,n){e.lookAt(k,n,D).multiply(H)}new a;function N(e,t=1){const s=(++R>=I.length?I[R=0]:I[R]).elements,n=e.elements;n[0]=s[0]*t,n[4]=s[4]*t,n[8]=s[8]*t,n[1]=s[1]*t,n[5]=s[5]*t,n[9]=s[9]*t,n[2]=s[2]*t,n[6]=s[6]*t,n[10]=s[10]*t}function F(e){const t=e.getAttribute("normal");for(let e=0;e<t.count;e++)t.setXYZ(e,0,1,0);t.normalized=!0,t.needsUpdate=!0}/*
1
+ import{Subject as e,debounceTime as t}from"rxjs";import{Box3 as s,BufferAttribute as n,InstancedMesh as o,MathUtils as i,Matrix4 as a,Mesh as r,MeshStandardMaterial as c,PerspectiveCamera as l,PlaneGeometry as h,ShaderMaterial as u,Triangle as f,Vector2 as p,Vector3 as m}from"three";import{materialFromAsset as d}from"../../scene/materializer.js";import{getMaterialAttribute as w}from"../../scene/materials/utils/material-painting";import{whenIdle as g}from"../../utils/async.js";import{indexBy as y}from"../../utils/collections.js";import{meanVectors3withWeight as M}from"../../utils/math.js";import{LandscapeMesh as x,defaultLandscapeMaterial as b}from"./landscape.js";import{smoothNormalsCrossMeshes as S}from"./utils.js";export const grassGeometryTriangleLimit=400;new m,new m;const v=new m,A=new m,z=new m;export class LandscapeManager{constructor(s,n,o,i,r,c,l){this.view=n,this.landscape=o,this.assetManagerService=i,this.assetService=r,this.shaders=c,this.applyMaterial=l,this.scatterMeshes=new Map,this.loadedScatterSquares=new Set,this.refreshRequests=new e,this.defaultLandscapeMaterial=b.clone(),this.scatterMeshPool=[],this.onLoopHandler=()=>this.update(),this.sectionCache=new Map,this._matrix=new a,this.scatterGeometryCache=new Map,this._lastUpdatePosition=new m,this._cameraPosition=new m,this.source=JSON.parse(JSON.stringify(s)),this.view.onLoop(this.onLoopHandler),this.defaultLandscapeMaterial.name=b.name,this.defaultLandscapeMaterial.color=b.color,this.refreshRequests.pipe(t(500)).subscribe((e=>this.refreshScatter(e.origin,e.force,e.predicate)))}updateSource(e){this.source=JSON.parse(JSON.stringify(e))}updateShaders(e){this.shaders=e}async loadGrass(){const e=await this.assetService.getAsset("6ij937n72g");await this.assetManagerService.getMesh(e);this.grassGeometry=new h(2,2,3,3);const t=this.grassGeometry.getAttribute("normal");for(let e=0;e<t.count;e++)t.setXYZ(e,0,1,0);t.needsUpdate=!0,this.grassMaterial=new c({color:3765785})}refreshGeometry(){const e=this.source.landscape.options,t=(new m,new m);this.view.camera.getWorldPosition(t);const s=[];z.fromArray(this.source.position);const n=this.view.camera instanceof l?Math.min(this.view.camera.far,1e3):1e3,o=1.1*n,i=e.sections.y*e.sectionSize/-2,a=e.sections.x*e.sectionSize/-2;for(let r=0;r<e.sections.x;r++)if(v.x=a+r*e.sectionSize,!(Math.abs(t.x-v.x)>o))for(let c=0;c<e.sections.y;c++){v.z=i+c*e.sectionSize,A.copy(z).add(v);const l=A.distanceTo(t),h=`${r},${c}`,u=this.landscape.sections.find((e=>e.x===r&&e.y===c));if(l<=n){if(null==u){this.sectionCache.has(h)||this.sectionCache.set(h,this.createLandscapeMesh(this.source,e,a,i,r,c));const t=this.sectionCache.get(h);this.applyMaterial(t),this.landscape.add(t),s.push(t)}}else l>o&&this.landscape.remove(u)}S(s)}applyHeightMap(e,t,s,n=1){const o=Math.pow(s+1,2),i=e.getAttribute("position");if(1===n)for(const e of t.points)i.setY(e.i,e.y);else{const e=y(t.points??[],(e=>e.i));for(let t=0;t<i.count;t++){const s=P(t,i.count,o);let n=0;n=s%1==0?e.get(s)?.y??0:Math.floor(e.get(s)?.y),i.setY(t,n)}}i.needsUpdate=!0,e.computeVertexNormals()}deleteOldScatterMeshes(){const e=new Set;for(const[t,s]of this.source.grass?.layers.entries()??[])for(const[n,o]of s.meshes.entries()){const s=`${t}-${n}`;e.add(s)}for(const t of this.scatterMeshes.keys())if(!e.has(t)){this.scatterMeshes.get(t).forEach((e=>{e.parent?.remove(e),e.dispose()})),this.scatterMeshes.delete(t)}}queueRefreshScatter(e,t=!1,s=()=>!0){this.refreshRequests.next({origin:e,force:t,predicate:s})}async refreshScatter(e,t=!1,s=()=>!0){t&&this.scatterGeometryCache.clear(),this.deleteOldScatterMeshes();for(const[n,a]of this.source.grass?.layers.entries()??[])for(const[c,l]of a.meshes.entries()){const a=`${n}-${c}`;this.scatterMeshes.has(a)||this.scatterMeshes.set(a,new Map);const h=this.scatterMeshes.get(a),u=await this.assetService.getAsset(l.assetId);if(null==u){console.error(`Can not find asset with id ${l.assetId}`);continue}let p;try{p=await this.assetManagerService.getMesh(u)}catch(e){console.error(`Failed to load mesh in landscape manager for asset with name ${u.name}`,e);continue}const w=[];if(p.scene.traverse((e=>{e instanceof r&&w.push(e)})),1!==w.length){console.log(p),console.warn("Dynamic grass only works for meshes with a single geometry.");continue}if(!(w[0]instanceof r)){console.warn("Only meshes can be used for dynamic grass. Found:",p.scene);continue}const x=w[0];let b=x.geometry;if(this.scatterGeometryCache.has(x.geometry.uuid))b=this.scatterGeometryCache.get(x.geometry.uuid);else if(b=x.geometry.clone(),!0===l.normalsUp&&F(b),null==b.userData.updatedMatrix){p.scene.updateMatrixWorld(),b.applyMatrix4(x.matrixWorld),b.userData.updatedMatrix=!0;const e=u.mesh?.rescale??1;1!==e&&b.scale(e,e,e)}const S=b.getIndex()??b.getAttribute("position"),v=null!=S?S.count/3:0;if(v>400){console.warn(`The triangle count of ${u.name} is too big ${v}. Keep it below 400`);continue}const A=null!=u.materialAssignments&&u.materialAssignments.length>0?u.materialAssignments[0].materialId:null,z=null!=A&&"null"!==A?await d(await this.assetService.getAsset(A),null,this.assetService,this.assetManagerService,this.shaders,!1):null;let P=null!=z?z:x.material;const L=i.degToRad(l.maxSlope??90),_=Math.cos(L),T=this.landscape.sections,q=T.filter(j(e,l.viewDistance)),I=q.filter((e=>!h.has(e.uuid)||t)).filter((e=>s(e)));T.filter($(e,2*l.viewDistance)).forEach((e=>{const t=h.get(e.uuid);null!=t&&(t.visible=!1)}));for(const e of q){const t=h.get(e.uuid);null!=t&&(t.visible=!0)}performance.now();const R=this.source.landscape.options,k=R.sectionSize,D=l.density??1??1,H=R.density,X=k/H,Y=D,E=X/Math.sqrt(Y),J=Math.pow(H,2),Z=E/X,K=Math.floor(J*Y),V=[0,0,0];for(const e of I)await g((async()=>{e.updateWorldMatrix(!0,!1);const s=this._matrix,i=new m,a=e.geometry.getAttribute("position"),r=e.geometry.getAttribute("normal"),c=(this.source.vertexMaterials??[]).filter((t=>t.m===e.name)),u=y(c,(e=>e.i));let p=h.get(e.uuid);if(null==p||p.count==K&&!t||(p.parent?.remove(p),this.scatterMeshPool.push(p),h.delete(e.uuid),p=null),null==p){const e=this.scatterMeshPool.findIndex((e=>e.count>=K));e>-1?(p=this.scatterMeshPool[e],p.geometry=b,p.material=P,this.scatterMeshPool.splice(e,1)):p=new o(b,P,K),p.raycast=()=>{},p.receiveShadow=!0}p.visible=!0;const d=new f(new m,new m,new m);let[w,g,x,S]=[new m,new m,new m,new m],[v,A,z]=[[],[],[]],[L,$,j]=[new m,new m,new m,new m];const T=new m,q=new m,I=new m,R=new m,k=new f(new m,new m,new m),D=new f(new m,new m,new m),F=new f(new m,new m,new m),X=new f(new m,new m,new m);let E=0;e:for(let t=0;t<J;t++){const o=Math.floor(t/H);w.fromBufferAttribute(a,t+o),R.copy(w).applyMatrix4(e.matrixWorld),k.a.copy(w),k.b.fromBufferAttribute(a,t+1+o),k.c.fromBufferAttribute(a,t+H+1+o),D.a.copy(k.b),D.b.copy(k.c),D.c.fromBufferAttribute(a,t+H+2+o),F.a.fromBufferAttribute(r,t+o),F.b.fromBufferAttribute(r,t+1+o),F.c.fromBufferAttribute(r,t+H+1+o),X.a.copy(F.b),X.b.copy(F.c),X.c.fromBufferAttribute(r,t+H+2+o);const c=[];c[0]=u.get(t+o)?.w,c[1]=u.get(t+1+o)?.w,c[2]=u.get(t+H+1+o)?.w,c[3]=u.get(t+H+2+o)?.w;let h=0;for(let e=0;e<=1+Z;e+=Z)for(let t=0;t<=1+Z;t+=Z){if(E>K)break e;if(h++,h>Y)continue e;1-e>t?(g=k.a,x=k.b,S=k.c,L=F.a,$=F.b,j=F.c,v=c[0],A=c[1],z=c[2]):(g=D.a,x=D.b,S=D.c,L=X.a,$=X.b,j=X.c,v=c[1],A=c[2],z=c[3]),d.a.copy(g),d.b.copy(x),d.c.copy(S),B(d),T.set(w.x,0,w.z),U(d,T),d.getBarycoord(T,i).toArray(V),C[0]=v,C[1]=A,C[2]=z;if(G(C,V,.2)!==n-1)continue;if(M([g,x,S],V,q),M([L,$,j],V,I),null!=l.maxSlope&&l.maxSlope<90&&I.y<_)continue;const o=q;o.y+=O(l.offsetMin,l.offsetMax);const a=O(l.scaleMin??1,l.scaleMax??1);s.makeScale(a,a,a);const r=s.elements;r[12]=o.x,r[13]=o.y,r[14]=o.z,!1!==l.randomRotation&&N(s,a),l.alignToNormal&&W(s,o,p.matrixWorld,I);const u=p.instanceMatrix.array,f=16*E;u[f]=r[0],u[f+1]=r[1],u[f+2]=r[2],u[f+3]=r[3],u[f+4]=r[4],u[f+5]=r[5],u[f+6]=r[6],u[f+7]=r[7],u[f+8]=r[8],u[f+9]=r[9],u[f+10]=r[10],u[f+11]=r[11],u[f+12]=r[12],u[f+13]=r[13],u[f+14]=r[14],u[f+15]=r[15],E++}}p.count=E,p.instanceMatrix.needsUpdate=!0,p.position.copy(e.position),p.updateMatrix(),h.has(e.uuid)||this.landscape?.add(p),h.set(e.uuid,p),p.userData.meshConfig=l}));performance.now()}}stop(){this.view.removeOnLoop(this.onLoopHandler)}update(){this.view.camera&&(this.view.camera.getWorldPosition(this._cameraPosition),this._cameraPosition.distanceTo(this._lastUpdatePosition)>10&&(this._lastUpdatePosition.copy(this._cameraPosition),this.refreshGeometry(),this.refreshScatter(this._cameraPosition)))}clear(){this.scatterMeshes.forEach((e=>e.forEach((e=>e.parent?.remove(e)))))}createLandscapeMesh(e,t,s,n,o,i){const a=new h(t.sectionSize,t.sectionSize,t.density,t.density);a.rotateX(Math.PI/-2);const r=this.defaultLandscapeMaterial,c=new x(a,r);c.position.x=s+o*t.sectionSize,c.position.z=n+i*t.sectionSize,c.receiveShadow=!0,c.castShadow=!1,c.userData.landscape={x:o,y:i},c.x=o,c.y=i,c.name=`${o},${i}`,w(c,0,!0),w(c,4,!0);const l=e.landscape.heightMaps.find((e=>e.x===o&&e.y===i));if(null!=l&&this.applyHeightMap(a,l,t.density,1),a.computeBoundsTree(),null!=e.landscape.holes&&e.landscape.holes.length>0){const t=getHoleAttribute(c,!0);for(const s of e.landscape.holes)s.m===c.name&&t.setX(s.i,s.w[0])}return c}}export function getHoleAttribute(e,t=!1){if(!e.geometry.hasAttribute("hole")||t){const t=new Float32Array(e.geometry.getAttribute("position").array.length);e.geometry.setAttribute("hole",new n(t,1))}return e.geometry.getAttribute("hole")}function P(e,t,s){const n=Math.sqrt(t),o=Math.floor(e/n)/(n-1),i=e%n/(n-1),a=Math.sqrt(s);return(s-1)*o-(a-1)*o+(a-1)*i}new Map,new p(0,0),new p(1,0),new p(0,1),new p(1,0),new p(0,1),new p(1,1),new m;const L=new s;function $(e,t){return function(s){return L.setFromObject(s).distanceToPoint(e)>t}}function j(e,t){return function(s){return L.setFromObject(s).distanceToPoint(e)<t}}function B(e){e.a.y=0,e.b.y=0,e.c.y=0}const C=[];function G(e,t,s=.5){const n=C;let o=-1,i=-1;for(let e=0;e<n.length;e++)if(null!=n[e])for(let a=0;a<n[e].length;a++){const r=n[e][a]*t[e];r>s&&r>i&&(i=r,o=a)}return o}function O(e,t){let s=t-e,n=q();return n*=s,n+=e,n}const _=[];let T=1e3;for(;T--;)_.push(Math.random());function q(){return++T>=_.length?_[T=0]:_[T]}const I=[];let R=20;for(;R--;)I.push((new a).makeRotationY(q()*Math.PI/2));function U(e,t){let s=q(),n=q();s+n>1&&(s=1-s,n=1-n);const o=e.a,i=e.b,a=e.c;t.x=o.x+s*(i.x-o.x)+n*(a.x-o.x),t.z=o.z+s*(i.z-o.z)+n*(a.z-o.z)}new m;new m;const k=new m,D=new m(0,1,0),H=(new a).makeRotationX(Math.PI/-2);function W(e,t,s,n){e.lookAt(k,n,D).multiply(H)}new a;function N(e,t=1){const s=(++R>=I.length?I[R=0]:I[R]).elements,n=e.elements;n[0]=s[0]*t,n[4]=s[4]*t,n[8]=s[8]*t,n[1]=s[1]*t,n[5]=s[5]*t,n[9]=s[9]*t,n[2]=s[2]*t,n[6]=s[6]*t,n[10]=s[10]*t}function F(e){const t=e.getAttribute("normal");for(let e=0;e<t.count;e++)t.setXYZ(e,0,1,0);t.normalized=!0,t.needsUpdate=!0}/*
2
2
  * Copyright (©) 2023. 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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BAAmB,CAAC,CAAC,EAAE,cAAc,EAAE,iBAAiB,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAMhM;AAED,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,WAAW,GAAE,iBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CA4BjL;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,WA+C3E;AA0BD,eAAO,MAAM,iCAAiC,+BAW5C,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"}
@@ -1,4 +1,4 @@
1
- import{ConvexPolyhedronCollisionShape as e}from"@hology/core";import{Subject as t}from"rxjs";import*as a from"three";import{BoxGeometry as s,Color as r,Euler as i,Fog as n,FogExp2 as o,Group as l,Material as c,Matrix4 as h,Mesh as d,MeshLambertMaterial as m,MeshPhongMaterial as p,MeshStandardMaterial as u,Object3D as f,PointLight as y,Quaternion as g,SphereGeometry as w,Texture as v,Vector2 as S,Vector3 as A,Vector4 as b}from"three";import M,{SpriteRenderer as x}from"@hology/nebula";import{bool as j,BooleanNode as P,float as I,FloatNode as E,NodeShaderMaterial as V,rgb as D,RgbNode as N,Texture2dLookupNode as C,textureSampler2d as k,vec2 as _,Vec2Node as F,vec3 as O,Vec3Node as T,vec4 as z}from"three-shader-graph";import{VfxActor as B}from"../effects/vfx/vfx-actor.js";import{VisualEffect as W}from"../effects/vfx/vfx-param.js";import{BaseActor as $}from"../gameplay/actors/actor.js";import R from"../gameplay/actors/builtin/index.js";import{PhysicsBodyType as U,withInjectionContext as G}from"../gameplay/index.js";import{Sampler2DNode as L}from"../shader-nodes/index.js";import{LambertShader as J}from"../shader/builtin/lambert-shader.js";import{LandscapeCompositeShader as H}from"../shader/builtin/landscape-composite-shader";import{LandscapeShader as q}from"../shader/builtin/landscape-shader.js";import{StandardShader as X}from"../shader/builtin/standard-shader.js";import{UnlitShader as Y}from"../shader/builtin/unlit-shader.js";import{extractShaderParameters as Z}from"../shader/parameter.js";import{ArrayMap as Q,groupBy as K}from"../utils/collections.js";import{iterateMaterials as ee}from"../utils/materials.js";import{filterChildrenShallow as te,filterSceneShallow as ae,findFirstVisibleObject as se}from"../utils/three/traverse.js";import{AssetMeshInstance as re}from"./asset-resource-loader.js";import{isCollisionMesh as ie}from"./collision/collision-shape-import.js";import{BoxCollisionShape as ne,PhysicalShapeMesh as oe}from"./collision/collision-shape.js";import{LandscapeManager as le}from"./landscape/landscape-manager.js";import{initLandscape as ce}from"./landscape/landscape.js";import{SectionGrid as he,smoothNormalsCrossMeshes as de}from"./landscape/utils.js";import{createGrassFoliageMaterial as me}from"./materials/grass-foliage.js";import{createGrassMaterial as pe}from"./materials/grass.js";import{getMaterialAttribute as ue}from"./materials/utils/material-painting.js";import{createWaterMaterial as fe}from"./materials/water.js";import{SerializedParamType as ye}from"./model.js";import{ShapeLibrary as ge,ShapeLibraryKeys as we}from"./objects/shapes.js";import{ambientLightName as ve,createSky as Se,defaultSkyMaterial as Ae}from"./sky.js";import{Curve2 as be}from"../utils/curve.js";const Me={};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 SceneMaterializer(e,this.dataProvider,this.assetsService,this.assetManagerService,t,[],[],{create:()=>null,initActor:async()=>{}})}}export class SceneMaterializer{constructor(e,s,r,i,n,o,l,c){this.scene=e,this.dataProvider=s,this.assetsService=r,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 t,this.removed$=new t,this.error$=new t,this.editorActorParamSnapshot=new Map,this.assets=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.pmremGeneratorResults=new WeakMap,this.geometryCache=new Map,this.collisionShapeCache=new Map,this.originalFog=null,s.onCreate((e=>this.update(e))),s.onUpdate((e=>this.update(e))),s.onRemove((e=>this.remove(e))),this.createAssetSubscription=r.onCreate.subscribe((e=>{this.assets.set(e.id,e)})),this.updateSubscription=r.onUpdate.subscribe((async t=>{this.assets.set(t.id,t),"material"==t.type?e.traverse((e=>{if(e instanceof a.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=>{Fe(e.userData.src.materialAssignments,t.materialAssignments).forEach((t=>{this.applyMaterial(e,t)}))})),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 A,!0)}))):"prefab"===t.type&&this.findByAssetId(t.id).forEach((e=>{const t=e.userData.src;this.remove(t),this.materializeAndInitActor(t)}))}))}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===ye.Material&&s.value===a.id){t=!0;break}if(s.type===ye.Array&&"element"in s&&s.element===ye.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);i.userData=t.userData,null!=s?Te(e.material[s],i)||(e.material[s]=i):Te(e.material,i)||(e.material=i)}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===ye.Texture&&"string"==typeof t.value){const a=this.assets.get(t.value),s=await this.assetManagerService.getTexture(a);null!=s&&e.push(s)}}))),await Promise.all(Array.from(this.assets.values()).map((async t=>{if("texture"===t.type){const a=await this.assetManagerService.getTexture(t);e.push(a)}}))),0!==e.length){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(),je.clear(),await this.prefetchAssets(),await Promise.all(this.dataProvider.getObjects().map((e=>this.materialize(e)))),await this.initActorsPostInit()}initActorsPostInit(e=this.actorInstances){const t=e.map((async e=>{const t=e.object.userData.src??e.object.userData._src;if("vfx"===t.type)return Promise.resolve();const a=await this.assetsService.getAsset(t.assetId),s={...a?.actor?.params??{},...t.actor?.params??{}};for(const a of t.actor.innerParams??[])await this.applyActorComponentParams(e,a.path.slice(),a.params);const r=await Ve(s,e.constructor,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders,this.actorProvider);Object.assign(e,r);try{return await this.actorProvider.initActor(e)}catch(e){console.error(`Failed to initiate actor (name="${t.name}", id=${t.id})`,e)}}));return Promise.all(t)}addVfxChildActors(e,t=e){}async applyActorComponentParams(e,t,a){const s=t.length,r=t.shift();if(0==s){const t=await Ve(a,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);for(const[a,s]of Object.entries(t))null!=s&&(e[a]=s)}else null!=e[r]&&await this.applyActorComponentParams(e[r],t,a)}canObjectBeInstanced(e){return e.physics?.type!==U.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=>{!ie(e)&&e.isMesh&&a.push(e)}));const s=1==a.length&&0==a[0].children.length,r=a[0]instanceof d&&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)}))}async initWithInstancing(){await this.preInit(),await this.prefetchAssets();const t=[],s=new Q,n=new Q;for(const e of this.dataProvider.getObjects())await _e(e,(async(e,a,i)=>{const o="asset_mesh"==e.type&&this.canObjectBeInstanced(e)&&await this.canAssetBeInstanced(e),l="shape_mesh"===e.type&&"landscape"!==e.shape&&e.physics?.type!==U.dynamic;if(o||l){if(a&&a.children?.length>0){const t=a.children.findIndex((t=>t.id===e.id));t>=0&&a.children.splice(t,1)}if(l){let t=e.shape+JSON.stringify(e.shapeParams??{})+e.castShadow+e.receiveShadow;const a=e.materialAssignments?.at(0)?.materialId,s=null!=a?this.assets.get(a):null;let o=null;if(null!=s&&"shader"!==s.material.type){if(t+=s.material.type+s.material.shader,null!=s.material.shaderParams){if(t+=Object.entries(s.material.shaderParams).filter((([e,t])=>"color"!=e)).map((e=>JSON.stringify(e))).join(),null!=s.material.shaderParams.color){const e=s.material.shaderParams.color;e.type===ye.Color&&null!=e.value&&(o=new r(e.value))}}}else t+=a;n.push(t,{object:{...e,parentTransform:i},color:o})}else{const t=e.assetId+JSON.stringify(e.materialAssignments??[]);s.push(t,{...e,parentTransform:i})}}else null==a&&t.push({...e,parentTransform:i})}));for(const t of s.values()){if(0==t.length)continue;const a=await this.createFromAsset(t[0]);if(null==a)continue;const s=await this.createInstancedMesh(t,a),r=new re;r.add(s),r.userData.src=t[0],a instanceof re&&(r.collisionShapes=a.collisionShapes),r.collisionShapes.forEach((t=>{t instanceof e&&t.mesh instanceof d&&(t.mesh=t.mesh.geometry)})),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}for(const e of n.values()){if(0==e.length)continue;const t=e[0].object,s=await this.createFromShape(t),n=se(s,(e=>!ie(e)&&null!=e.geometry)),o=n.material.clone();null!=e[0].color&&null!=o.color&&(o.color=new r(16777215));const l=n.geometry,c=new a.InstancedMesh(l,o,e.length);for(let t=0;t<e.length;t++){const r=e[t],o=(new a.Matrix4).compose((new A).fromArray(r.object.position),(new g).setFromEuler((new i).fromArray(r.object.rotation)),(new A).fromArray(r.object.scale)),l=(new h).copy(r.object.parentTransform).multiply(o);c.setMatrixAt(t,l),null!=r.color&&c.setColorAt(t,r.color),c.castShadow=s.castShadow??!0,c.receiveShadow=n.receiveShadow??!0;const d=new re;d.add(c),d.userData.src=e[0],s instanceof oe&&(d.collisionShapes=[s.collisionShape]),d.castShadow=!1,d.receiveShadow=!1,this.scene.add(d)}}await Promise.all(t.map((e=>this.materialize(e)))),await this.initActorsPostInit()}async createInstancedMesh(e,t){const s=se(t,(e=>!ie(e)&&null!=e.geometry)),r=await this.assetsService.getAsset(e[0].assetId);await this.applyMaterials(t,Fe(e[0].materialAssignments,r.materialAssignments)),s.updateMatrix();const n=s.geometry.clone(),o=new a.InstancedMesh(n,s.material,e.length);for(let t=0;t<e.length;t++){const r=(new a.Matrix4).compose((new A).fromArray(e[t].position),(new g).setFromEuler((new i).fromArray(e[t].rotation)),(new A).fromArray(e[t].scale)),n=(new h).copy(e[t].parentTransform).multiply(r).multiply(s.matrixWorld);o.setMatrixAt(t,n)}return o.castShadow=e[0].castShadow??r.castShadow??!0,o.receiveShadow=e[0].receiveShadow??r.receiveShadow??!0,s.material instanceof c&&o.castShadow&&o.receiveShadow&&(o.material.side=a.FrontSide),o}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){const t=this.materializedActors.get(e.id);null!=t?(t.disposed.next(!0),t.onEndPlay()):console.warn("Failed to remove actor",e)}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 ae(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 d)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(R));ae(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 je.entries())t.userData.customShaderName&&je.delete(e);this.landscapeManagers.forEach((t=>t.updateShaders(e))),ae(this.scene,(e=>!0)).forEach((e=>{e.traverse((async e=>{if(e instanceof d)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 d&&(e.material.wireframe=!0)})):t.traverse((e=>{e instanceof d&&(e.material.wireframe=!1)}))}if("asset_mesh"===e.type){const a=this.assets.get(e.assetId);Fe(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 r(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)}else"directional"===e.light.type?this.applyDirectionalLight(e.light.directional):"ambient"===e.light.type&&this.applyDirectionalAmbientLight(t,e.light.ambient);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 o?"density":"linear")!==e.fog.type;this.scene.fog=Ce(e.fog),t&&(a=this.scene).traverse((e=>{if(e instanceof d){const t=e.material;t instanceof V&&(a.fog instanceof n?(t.uniforms.fogFar.value=a.fog.far,t.uniforms.fogNear.value=a.fog.near):a.fog instanceof o&&(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.editorActorParamSnapshot.get(e.id);null!=t&&t===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 oe&&(t.geometry=a.geometry,t.collisionShape=a.collisionShape)}("asset_mesh"===e.type||"shape_mesh"===e.type&&"landscape"!==e.shape)&&xe(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)){console.log("materialize actor and init");const a=await this.materialize(e,t);return _e(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:te(t,(t=>t.children?.some((t=>t.id===e.id))),(()=>!0))))[0];return null==t?this.scene:null!=t?ae(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 r(this.scene.fog.color))}findMeshWithGeometry(e){let t;return e.traverse((e=>{e instanceof d&&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=K(e.vertexMaterials,(e=>e.m));t.traverse((e=>{if(e instanceof d){if(null==e.geometry)return;if(ze(ue(e,0,!1)),a>0){ze(ue(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=ue(s,0,!0);ze(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=ue(s,4,!0);ze(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){let r;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=Ce(e.fog),this.fixFogColor(),r=new l;break;case"sky":this.sky=Se(),this.updateSky(e),r=this.sky;break;case"world_env":this.updateWorldEnv(e),r=new l,this.worldEnvObj=r;break;case"actor":r=await this.createFromActor(e);break;case"group":r=new l;break;case"prefab":r=await this.createFromPrefabAsset(e);break;case"vfx":r=await this.createFromVfx(e);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,this.inEditor,this.inEditor){let e=null;r instanceof oe&&(e=function(e){if(e instanceof ne)return new d(new s(...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))}return this.objectMap.set(r.uuid,e),this.sceneObjectMap.set(e.id,r),e.physics?.type!==U.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==U.dynamic||Ne(r),this.renderingView.renderer.shadowMap.needsUpdate=!0,r}}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 s=e.worldEnv.environment;null!=s&&null!=s.textureId?this.assetManagerService.getTexture(this.assets.get(s.textureId)).then((e=>{null==this.pmremGenerator&&(this.pmremGenerator=new a.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=s.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=Ae);const t=await this.assetsService.getAsset(e.sky.materialId),s=await materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);s.side=a.BackSide,(s instanceof u||s instanceof a.MeshBasicMaterial||s instanceof a.ShaderMaterial)&&(s.fog=!1),null!=this.sky?this.sky.material=s:console.warn("No sky has been created")}async createComponent(e,t,a,s){const r=new Me[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){const t=this.actorTypes.find((t=>t.name===e.actor?.type))?.type??R[e.actor?.type];if(null==t)return null;this.inEditor&&this.editorActorParamSnapshot.set(e.id,JSON.stringify(e.actor));const a=await this.actorProvider.create(t,(new A).fromArray(e.position),(new i).fromArray(e.rotation),!0);return this.materializedActors.set(e.id,a),a?.object}async createFromVfx(e){const t=await this.assetsService.getAsset(e.assetId);null==t&&console.error("Could not find asset",e);const a=await this.actorProvider.create(B,(new A).fromArray(e.position),(new i).fromArray(e.rotation),!1);return await a.fromAsset(t),a.play(),this.materializedActors.set(e.id,a),a?.object}cleanup(){this.materializedActors.clear()}async createFromShape(e){const t=this.inEditor&&e.hidden;let a;if("landscape"==e.shape)a=this.createLandscape(e),a.traverse((e=>{e instanceof d&&this._originalMaterials.set(e.id,e.material)}));else{let s=new u({name:"Default",color:new r("#aaaaaa"),visible:this.inEditor||!e.hidden,wireframe:!!t});const i=await this.createMeshByShape(e.shape,s,e.shapeParams);i.castShadow=e.castShadow??!0,i.receiveShadow=e.castShadow??!1,e.collisionDetection||(i.collisionShape=null),i.physics=e.physics,a=i,this._originalMaterials.set(a.id,i.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 l;const a=ce(e.landscape.options);this.applyHeightMaps(a,e.landscape.heightMaps,!0);const s=new le(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 he(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((()=>de(r)),50)}async createMeshByShape(e,t,a={}){if("landscape"!==e&&we.includes(e)){const s=await prepareShapeParameters(a??{}),r=e+JSON.stringify(a);return this.geometryCache.has(r)||this.geometryCache.set(r,ge[e].geometry(s)),this.collisionShapeCache.has(r)||this.collisionShapeCache.set(r,ge[e].collision(s)),new oe(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});Fe(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,xe(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 d&&"computeBoundsTree"in e.geometry&&null==e.geometry.boundsTree&&e.geometry.computeBoundsTree()})),a}async createFromPrefabAsset(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}`);const a=new l;return t.prefab.objects.filter((e=>"global_fog"!==e.type&&"world_env"!==e.type)).forEach((e=>this.materialize(e,a,!0))),a}async createParticleSystem(e){const t=await this.assetsService.getAsset(e.assetId),s=new f;return await M.fromJSONAsync(t.particleSystem,a).then((e=>{const t=new x(s,a);e.addRenderer(t),this.renderingView.onLoop((t=>e.update()))})),s}async createLight(e){if("point"===e.light.type){const t=new y(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 w(.3,10,10),a=new u({color:new r(16771709)}),s=new d(e,a);t.add(s)}return t}return"directional"===e.light.type?(this.applyDirectionalLight(e.light.directional),new l):"ambient"===e.light.type?(this.applyDirectionalAmbientLight(null,e.light.ambient),new l):void 0}applyDirectionalAmbientLight(e,t){const a=this.scene.children.find((e=>e.name===ve));null!=a?(a.intensity=t.intensity,a.color.set(t.color),a.groundColor.set(t.color)):console.warn("Couldn't find ambient light")}applyDirectionalLight(e){for(const t of this.renderingView.csm.lights)t.intensity=e.intensity,t.color.set(e.color),t.castShadow=e.castShadow;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe(),this.createAssetSubscription.unsubscribe(),this.materializedActors.forEach((e=>e.disposed.next(!0)))}}function xe(e,t,a){e.castShadow=t,e.receiveShadow=a,e.traverse((e=>{e.castShadow=t,e.receiveShadow=a}))}const je=new Map,Pe=new Map,Ie=new m({color:16711935}),Ee=new Map;export async function materialFromAsset(e,t,a,s,r,i=!0){const n=JSON.stringify(e.material);return i&&je.has(n)?je.get(n):i&&Pe.has(n)?await Pe.get(n):Pe.set(n,_materialFromAsset(n,e,t,a,s,r,i)).get(n)}export async function _materialFromAsset(e,t,s,i,n,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 r(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 i.getAsset(e);null!=a&&(c.map=await n.getTexture(a))}let d;switch(t.material.type){case"phong":d=new p({...c,...h});break;case"water":d=fe(c,s);break;case"grassFoliage":d=me({color:c.color,map:c.map},s);break;case"grass":d=pe({...c,colorTwo:new r(t.material.params.colorTwo),colorThree:new r(t.material.params.colorThree)},s);break;case"standard":case"unlit":case"lambert":case"shader":case"landscape":case"landscape-composite":const e={standard:X,lambert:J,unlit:Y,landscape:q,"landscape-composite":H}[t.material.type]??o.find((e=>e.name==t.material.shader))?.type;if(e){try{let a=new e;const r=await Ve(t.material?.shaderParams??{},e,i,n,null,s,o);Object.assign(a,r),d=a.build()}catch(e){console.log("Shader runtime error: "+e),Ee.has(t.material.shader)||Ee.set(t.material.shader,Ie.clone()),d=Ee.get(t.material.shader)}d.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),d=Ie;break;default:throw new Error("Unsupported material type"+t.material.type)}return s?.csm.setupMaterial(d),null!=s&&je.set(e,d),d.side=t.material.side??d.side??a.FrontSide,d.transparent=(t.material.transparent??c.transparent??!1)||d.transparent,d.alphaTest=t.material.alphaTest??d.alphaTest??0,t.material.bloom&&(d.userData.hasBloom=!0),d.userData.assetId=t.id,Pe.delete(e),d}async function Ve(e,t,a,s,r,i,n,o){const l={};for(const[t,c]of Object.entries(e)){const e=await De(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 De(s,null,null,null);null!=e&&(t[a]=e)}return t}async function De(e,t,a,s,n,o,l,c=e.value,h=e.type){if(null==e||null==c||""===c)return null;switch(h){case ye.Array:if(Array.isArray(c)&&"element"in e)return await Promise.all(c.map((r=>De(e,t,a,s,n,o,l,r,e.element))));break;case ye.Number:case ye.FloatNode:let h="string"==typeof c?parseFloat(c):c;return e.type===ye.FloatNode?I(h):h;case ye.Texture:return await a.getTexture(await t.getAsset(c));case ye.Sampler2DNode:return k(await a.getTexture(await t.getAsset(c)));case ye.Boolean:return c;case ye.BooleanNode:return j(c);case ye.Vector2:case ye.Vec2Node:if("object"==typeof c){const t=c instanceof Array?(new S).fromArray(c):new S(c.x,c.y);return e.type===ye.Vec2Node?_(t):t}return null;case ye.Vector3:case ye.Vec3Node:if("object"==typeof c){const t=c instanceof Array?(new A).fromArray(c):new A(c.x,c.y,c.z);return e.type===ye.Vec3Node?O(t):t}return null;case ye.Color:case ye.RgbNode:const d=new r(c);return e.type===ye.RgbNode?D(d):d;case ye.String:return c;case ye.BaseActor:const m=c;return null==s&&console.warn("Class parameters can not be prepared as actors are not passed in"),s?.get(m);case ye.Euler:const p=c;return(new i).fromArray(p);case ye.Object3D:return(await a.getMesh(await t.getAsset(c))).scene;case ye.Material:return await materialFromAsset(await t.getAsset(c),n,t,a,o);case ye.AudioBuffer:return await a.getAudio(await t.getAsset(c));case ye.VisualEffect:const u=await t.getAsset(c);if(null==l){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in u)return new W(l,u);console.error("Using a non-vfx asset for visual effect parameter");break;case ye.Curve:return be.decode(c)}return null}function Ne(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 Ce(e){return"linear"===e.type?new n(new r(e.color),e.near??100,e.far??1e3):"density"===e.type?new o(e.color,e.density):void console.warn("Invalid fog type",e)}const ke=new u({color:4229780});async function _e(e,t,s,r){null==r&&(r=(new h).identity()),await t(e,s,r);const n=r.clone().multiply(function(e,t){if(null==e.position||null==e.rotation||null==e.scale)return t.identity();return t.compose((new A).fromArray(e.position),(new g).setFromEuler((new i).fromArray(e.rotation)),(new A).fromArray(e.scale))}(e,new a.Matrix4));return Promise.all((e.children??[]).map((a=>_e(a,t,e,n))))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?ye.Number:t instanceof E||"function"==typeof e.prototype.isFloat?ye.FloatNode:t instanceof v||e===v||e.isTexture?ye.Texture:t instanceof L||e===C?ye.Sampler2DNode:t instanceof Boolean||e===Boolean?ye.Boolean:t instanceof P?ye.BooleanNode:t instanceof r||e==r?ye.Color:t instanceof N||"function"==typeof e.prototype.isRgb?ye.RgbNode:t instanceof S||e==S?ye.Vector2:t instanceof F||"function"==typeof e.prototype.isVec2?ye.Vec2Node:t instanceof A||e==A?ye.Vector3:t instanceof T||"function"==typeof e.prototype.isVec3?ye.Vec3Node:t instanceof String||e===String?ye.String:t instanceof $||e==$||e.prototype instanceof $||e.prototype==$?ye.BaseActor:t instanceof i||e==i?ye.Euler:t instanceof f||e==f?ye.Object3D:t instanceof c||e==c?ye.Material:t instanceof AudioBuffer||e==AudioBuffer?ye.AudioBuffer:t instanceof W||e==W?ye.VisualEffect:t instanceof be||e==be?ye.Curve: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?ye.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=Z(e);if(0===s.length)return{};let r;null!=a?G(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 A:return t instanceof A?t.toArray():void a();case b:return t instanceof b?t.toArray():void a();case r:return t instanceof r?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new r(t).getHexString():void a();case String:return t;case i:return t instanceof i?t.toArray():void a()}}function Fe(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=>Oe(e.materialId))),(t??[]).filter((e=>Oe(e.materialId))),(e=>e.color+e.name))}function Oe(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[ye.RgbNode,"#000000"],[ye.Color,"#000000"],[ye.Vector4,[0,0,0,0]],[ye.Vec4Node,[0,0,0,0]],[ye.Vector3,[0,0,0]],[ye.Vec3Node,[0,0,0]],[ye.Vector2,[0,0]],[ye.Vec2Node,[0,0]],[ye.Euler,[0,0,0,"XYZ"]],[ye.Array,[]]]);export function applyMaterial(e,t,s,i){const n=[];return e.traverse((async e=>{if(e instanceof d||e.isMesh||e instanceof a.SkinnedMesh||e.isSkinnedMesh)for(const t of ee(e.material))t.hasOwnProperty("color")&&n.push(e)})),Promise.all(n.map((async e=>{if(e.material instanceof Array)for(let a=0;a<e.material.length;a++){const n=e.material[a];if(null==n.color||!(n.color instanceof r))continue;const o="#"+n.color.getHexString(),l=n.name;if(o===t.color&&(n.name===t.name||null==t.name)||e.userData["originalColor_"+a]===t.color&&e.userData["originalMaterialName_"+a]===t.name){const r=await s(t.materialId),n=e.material[a];null!=r&&n.id!=r.id&&(e.material[a]=r,e.userData["originalColor_"+a]=e.userData["originalColor_"+a]??o,e.userData["originalMaterialName_"+a]=e.userData["originalMaterialName_"+a]??l,null!=i&&i.set(e.id+"#"+a,n))}}else if("color"in e.material){const a="#"+e.material.color.getHexString(),r=e.material.name;if(a===t.color&&(e.material.name===t.name||null==t.name)||e.userData.originalColor===t.color&&e.userData.originalName===t.name){const n=await s(t.materialId),o=e.material;null!=n&&(e.material=n,e.userData.originalColor=e.userData.originalColor??a,e.userData.originalMaterialName=e.userData.originalMaterialName??r,null!=i&&(i.has(e.id)||i.set(e.id,o)))}}})))}function Te(e,t){if(e instanceof a.ShaderMaterial&&t instanceof a.ShaderMaterial){return e.fragmentShader+e.vertexShader==t.fragmentShader+t.vertexShader&&function(e,t){if(e instanceof a.ShaderMaterial&&t instanceof a.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 ze(e){if(null!=e){for(let t=0;t<e.array.length;t++)e.setX(t,0);e.needsUpdate=!0}}/*
1
+ import{ConvexPolyhedronCollisionShape as e}from"@hology/core";import{Subject as t}from"rxjs";import*as a from"three";import{BoxGeometry as s,Color as r,Euler as i,Fog as n,FogExp2 as o,Group as l,Material as c,Matrix4 as h,Mesh as d,MeshLambertMaterial as m,MeshPhongMaterial as p,MeshStandardMaterial as u,Object3D as f,PointLight as y,Quaternion as g,SphereGeometry as w,Texture as v,Vector2 as S,Vector3 as A,Vector4 as b}from"three";import M,{SpriteRenderer as x}from"@hology/nebula";import{bool as j,BooleanNode as P,float as I,FloatNode as E,NodeShaderMaterial as V,rgb as D,RgbNode as N,Texture2dLookupNode as C,textureSampler2d as k,vec2 as _,Vec2Node as F,vec3 as O,Vec3Node as T,vec4 as z}from"three-shader-graph";import{VfxActor as B}from"../effects/vfx/vfx-actor.js";import{VisualEffect as W}from"../effects/vfx/vfx-param.js";import{BaseActor as $}from"../gameplay/actors/actor.js";import R from"../gameplay/actors/builtin/index.js";import{PhysicsBodyType as U,withInjectionContext as G}from"../gameplay/index.js";import{Sampler2DNode as L}from"../shader-nodes/index.js";import{LambertShader as J}from"../shader/builtin/lambert-shader.js";import{LandscapeCompositeShader as H}from"../shader/builtin/landscape-composite-shader";import{LandscapeShader as q}from"../shader/builtin/landscape-shader.js";import{StandardShader as X}from"../shader/builtin/standard-shader.js";import{UnlitShader as Y}from"../shader/builtin/unlit-shader.js";import{extractShaderParameters as Z}from"../shader/parameter.js";import{ArrayMap as Q,groupBy as K}from"../utils/collections.js";import{iterateMaterials as ee}from"../utils/materials.js";import{filterChildrenShallow as te,filterSceneShallow as ae,findFirstVisibleObject as se}from"../utils/three/traverse.js";import{AssetMeshInstance as re}from"./asset-resource-loader.js";import{isCollisionMesh as ie}from"./collision/collision-shape-import.js";import{BoxCollisionShape as ne,PhysicalShapeMesh as oe}from"./collision/collision-shape.js";import{LandscapeManager as le}from"./landscape/landscape-manager.js";import{initLandscape as ce}from"./landscape/landscape.js";import{SectionGrid as he,smoothNormalsCrossMeshes as de}from"./landscape/utils.js";import{createGrassFoliageMaterial as me}from"./materials/grass-foliage.js";import{createGrassMaterial as pe}from"./materials/grass.js";import{getMaterialAttribute as ue}from"./materials/utils/material-painting.js";import{createWaterMaterial as fe}from"./materials/water.js";import{SerializedParamType as ye}from"./model.js";import{ShapeLibrary as ge,ShapeLibraryKeys as we}from"./objects/shapes.js";import{ambientLightName as ve,createSky as Se,defaultSkyMaterial as Ae}from"./sky.js";import{Curve2 as be}from"../utils/curve.js";import{DecalUnlitShader as Me}from"../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as xe}from"../shader/builtin/decal-standard-shader.js";const je={};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 SceneMaterializer(e,this.dataProvider,this.assetsService,this.assetManagerService,t,[],[],{create:()=>null,initActor:async()=>{}})}}export class SceneMaterializer{constructor(e,s,r,i,n,o,l,c){this.scene=e,this.dataProvider=s,this.assetsService=r,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 t,this.removed$=new t,this.error$=new t,this.editorActorParamSnapshot=new Map,this.assets=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.pmremGeneratorResults=new WeakMap,this.geometryCache=new Map,this.collisionShapeCache=new Map,this.originalFog=null,s.onCreate((e=>this.update(e))),s.onUpdate((e=>this.update(e))),s.onRemove((e=>this.remove(e))),this.createAssetSubscription=r.onCreate.subscribe((e=>{this.assets.set(e.id,e)})),this.updateSubscription=r.onUpdate.subscribe((async t=>{this.assets.set(t.id,t),"material"==t.type?e.traverse((e=>{if(e instanceof a.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=>{Te(e.userData.src.materialAssignments,t.materialAssignments).forEach((t=>{this.applyMaterial(e,t)}))})),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 A,!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=>{Oe(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===ye.Material&&s.value===a.id){t=!0;break}if(s.type===ye.Array&&"element"in s&&s.element===ye.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,null!=s?Be(e.material[s],i)||(e.material[s]=i):Be(e.material,i)||(e.material=i)}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===ye.Texture&&"string"==typeof t.value){const a=this.assets.get(t.value),s=await this.assetManagerService.getTexture(a);null!=s&&e.push(s)}}))),await Promise.all(Array.from(this.assets.values()).map((async t=>{if("texture"===t.type){const a=await this.assetManagerService.getTexture(t);e.push(a)}}))),0!==e.length){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(),Ie.clear(),await this.prefetchAssets(),await Promise.all(this.dataProvider.getObjects().map((e=>this.materialize(e)))),await this.initActorsPostInit()}initActorsPostInit(e=this.actorInstances){const t=e.map((async e=>{const t=e.object.userData.src??e.object.userData._src;if("vfx"===t.type)return Promise.resolve();const a=await this.assetsService.getAsset(t.assetId),s={...a?.actor?.params??{},...t.actor?.params??{}};for(const a of t.actor.innerParams??[])await this.applyActorComponentParams(e,a.path.slice(),a.params);const r=await Ne(s,e.constructor,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders,this.actorProvider);Object.assign(e,r);try{return await this.actorProvider.initActor(e)}catch(e){console.error(`Failed to initiate actor (name="${t.name}", id=${t.id})`,e)}}));return Promise.all(t)}addVfxChildActors(e,t=e){}async applyActorComponentParams(e,t,a){const s=t.length,r=t.shift();if(0==s){const t=await Ne(a,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);for(const[a,s]of Object.entries(t))null!=s&&(e[a]=s)}else null!=e[r]&&await this.applyActorComponentParams(e[r],t,a)}canObjectBeInstanced(e){return e.physics?.type!==U.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=>{!ie(e)&&e.isMesh&&a.push(e)}));const s=1==a.length&&0==a[0].children.length,r=a[0]instanceof d&&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)}))}async initWithInstancing(){await this.preInit(),await this.prefetchAssets();const t=[],s=new Q,n=new Q;for(const e of this.dataProvider.getObjects())await Oe(e,(async(e,a,i)=>{const o="asset_mesh"==e.type&&this.canObjectBeInstanced(e)&&await this.canAssetBeInstanced(e),l="shape_mesh"===e.type&&"landscape"!==e.shape&&e.physics?.type!==U.dynamic;if(o||l){if(a&&a.children?.length>0){const t=a.children.findIndex((t=>t.id===e.id));t>=0&&a.children.splice(t,1)}if(l){let t=e.shape+JSON.stringify(e.shapeParams??{})+e.castShadow+e.receiveShadow;const a=e.materialAssignments?.at(0)?.materialId,s=null!=a?this.assets.get(a):null;let o=null;if(null!=s&&"shader"!==s.material.type){if(t+=s.material.type+s.material.shader,null!=s.material.shaderParams){if(t+=Object.entries(s.material.shaderParams).filter((([e,t])=>"color"!=e)).map((e=>JSON.stringify(e))).join(),null!=s.material.shaderParams.color){const e=s.material.shaderParams.color;e.type===ye.Color&&null!=e.value&&(o=new r(e.value))}}}else t+=a;n.push(t,{object:{...e,parentTransform:i},color:o})}else{const t=e.assetId+JSON.stringify(e.materialAssignments??[]);s.push(t,{...e,parentTransform:i})}}else null==a&&t.push({...e,parentTransform:i})}));for(const t of s.values()){if(0==t.length)continue;const a=await this.createFromAsset(t[0]);if(null==a)continue;const s=await this.createInstancedMesh(t,a),r=new re;r.add(s),r.userData.src=t[0],a instanceof re&&(r.collisionShapes=a.collisionShapes),r.collisionShapes.forEach((t=>{t instanceof e&&t.mesh instanceof d&&(t.mesh=t.mesh.geometry)})),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}for(const e of n.values()){if(0==e.length)continue;const t=e[0].object,s=await this.createFromShape(t),n=se(s,(e=>!ie(e)&&null!=e.geometry)),o=n.material.clone();null!=e[0].color&&null!=o.color&&(o.color=new r(16777215));const l=n.geometry,c=new a.InstancedMesh(l,o,e.length);for(let t=0;t<e.length;t++){const r=e[t],o=(new a.Matrix4).compose((new A).fromArray(r.object.position),(new g).setFromEuler((new i).fromArray(r.object.rotation)),(new A).fromArray(r.object.scale)),l=(new h).copy(r.object.parentTransform).multiply(o);c.setMatrixAt(t,l),null!=r.color&&c.setColorAt(t,r.color),c.castShadow=s.castShadow??!0,c.receiveShadow=n.receiveShadow??!0;const d=new re;d.add(c),d.userData.src=e[0],s instanceof oe&&(d.collisionShapes=[s.collisionShape]),d.castShadow=!1,d.receiveShadow=!1,this.scene.add(d)}}await Promise.all(t.map((e=>this.materialize(e)))),await this.initActorsPostInit()}async createInstancedMesh(e,t){const s=se(t,(e=>!ie(e)&&null!=e.geometry)),r=await this.assetsService.getAsset(e[0].assetId);await this.applyMaterials(t,Te(e[0].materialAssignments,r.materialAssignments)),s.updateMatrix();const n=s.geometry.clone(),o=new a.InstancedMesh(n,s.material,e.length);for(let t=0;t<e.length;t++){const r=(new a.Matrix4).compose((new A).fromArray(e[t].position),(new g).setFromEuler((new i).fromArray(e[t].rotation)),(new A).fromArray(e[t].scale)),n=(new h).copy(e[t].parentTransform).multiply(r).multiply(s.matrixWorld);o.setMatrixAt(t,n)}return o.castShadow=e[0].castShadow??r.castShadow??!0,o.receiveShadow=e[0].receiveShadow??r.receiveShadow??!0,s.material instanceof c&&o.castShadow&&o.receiveShadow&&(o.material.side=a.FrontSide),o}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)}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 ae(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 d)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(R));ae(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 Ie.entries())t.userData.customShaderName&&Ie.delete(e);this.landscapeManagers.forEach((t=>t.updateShaders(e))),ae(this.scene,(e=>!0)).forEach((e=>{e.traverse((async e=>{if(e instanceof d)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 d&&(e.material.wireframe=!0)})):t.traverse((e=>{e instanceof d&&(e.material.wireframe=!1)}))}if("asset_mesh"===e.type){const a=this.assets.get(e.assetId);Te(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 r(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)}else"directional"===e.light.type?this.applyDirectionalLight(e.light.directional):"ambient"===e.light.type&&this.applyDirectionalAmbientLight(t,e.light.ambient);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 o?"density":"linear")!==e.fog.type;this.scene.fog=_e(e.fog),t&&(a=this.scene).traverse((e=>{if(e instanceof d){const t=e.material;t instanceof V&&(a.fog instanceof n?(t.uniforms.fogFar.value=a.fog.far,t.uniforms.fogNear.value=a.fog.near):a.fog instanceof o&&(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.editorActorParamSnapshot.get(e.id);null!=t&&t===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 oe&&(t.geometry=a.geometry,t.collisionShape=a.collisionShape)}("asset_mesh"===e.type||"shape_mesh"===e.type&&"landscape"!==e.shape)&&Pe(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)){console.log("materialize actor and init");const a=await this.materialize(e,t);return Oe(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:te(t,(t=>t.children?.some((t=>t.id===e.id))),(()=>!0))))[0];return null==t?this.scene:null!=t?ae(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 r(this.scene.fog.color))}findMeshWithGeometry(e){let t;return e.traverse((e=>{e instanceof d&&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=K(e.vertexMaterials,(e=>e.m));t.traverse((e=>{if(e instanceof d){if(null==e.geometry)return;if(We(ue(e,0,!1)),a>0){We(ue(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=ue(s,0,!0);We(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=ue(s,4,!0);We(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){let r;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=_e(e.fog),this.fixFogColor(),r=new l;break;case"sky":this.sky=Se(),this.updateSky(e),r=this.sky;break;case"world_env":this.updateWorldEnv(e),r=new l,this.worldEnvObj=r;break;case"actor":r=await this.createFromActor(e);break;case"group":r=new l;break;case"prefab":r=await this.createFromPrefabAsset(e);break;case"vfx":r=await this.createFromVfx(e);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,this.inEditor,this.inEditor){let e=null;r instanceof oe&&(e=function(e){if(e instanceof ne)return new d(new s(...e.offset.toArray()),Fe);return null}(r.collisionShape)),null!=e&&(e.layers.disable(0),e.layers.enable(18),e.scale.multiplyScalar(1.1),r.add(e))}return this.objectMap.set(r.uuid,e),this.sceneObjectMap.set(e.id,r),e.physics?.type!==U.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==U.dynamic||ke(r),this.renderingView.renderer.shadowMap.needsUpdate=!0,r}}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 s=e.worldEnv.environment;null!=s&&null!=s.textureId?this.assetManagerService.getTexture(this.assets.get(s.textureId)).then((e=>{null==this.pmremGenerator&&(this.pmremGenerator=new a.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=s.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=Ae);const t=await this.assetsService.getAsset(e.sky.materialId),s=await materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);s.side=a.BackSide,(s instanceof u||s instanceof a.MeshBasicMaterial||s instanceof a.ShaderMaterial)&&(s.fog=!1),null!=this.sky?this.sky.material=s:console.warn("No sky has been created")}async createComponent(e,t,a,s){const r=new je[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){const t=this.actorTypes.find((t=>t.name===e.actor?.type))?.type??R[e.actor?.type];if(null==t)return null;this.inEditor&&this.editorActorParamSnapshot.set(e.id,JSON.stringify(e.actor));const a=await this.actorProvider.create(t,(new A).fromArray(e.position),(new i).fromArray(e.rotation),!0);return this.materializedActors.set(e.id,a),a?.object}async createFromVfx(e){const t=await this.assetsService.getAsset(e.assetId);null==t&&console.error("Could not find asset",e);const a=await this.actorProvider.create(B,(new A).fromArray(e.position),(new i).fromArray(e.rotation),!1);return await a.fromAsset(t),a.play(),this.materializedActors.set(e.id,a),a?.object}cleanup(){this.materializedActors.clear()}async createFromShape(e){const t=this.inEditor&&e.hidden;let a;if("landscape"==e.shape)a=this.createLandscape(e),a.traverse((e=>{e instanceof d&&this._originalMaterials.set(e.id,e.material)}));else{let s=new u({name:"Default",color:new r("#aaaaaa"),visible:this.inEditor||!e.hidden,wireframe:!!t});const i=await this.createMeshByShape(e.shape,s,e.shapeParams);i.castShadow=e.castShadow??!0,i.receiveShadow=e.castShadow??!1,e.collisionDetection||(i.collisionShape=null),i.physics=e.physics,a=i,this._originalMaterials.set(a.id,i.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 l;const a=ce(e.landscape.options);this.applyHeightMaps(a,e.landscape.heightMaps,!0);const s=new le(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 he(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((()=>de(r)),50)}async createMeshByShape(e,t,a={}){if("landscape"!==e&&we.includes(e)){const s=await prepareShapeParameters(a??{}),r=e+JSON.stringify(a);return this.geometryCache.has(r)||this.geometryCache.set(r,ge[e].geometry(s)),this.collisionShapeCache.has(r)||this.collisionShapeCache.set(r,ge[e].collision(s)),new oe(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});Te(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,Pe(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 d&&"computeBoundsTree"in e.geometry&&null==e.geometry.boundsTree&&e.geometry.computeBoundsTree()})),a}async createFromPrefabAsset(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}`);const a=new l;return t.prefab.objects.filter((e=>"global_fog"!==e.type&&"world_env"!==e.type)).forEach((e=>this.materialize(e,a,!0))),a}async createParticleSystem(e){const t=await this.assetsService.getAsset(e.assetId),s=new f;return await M.fromJSONAsync(t.particleSystem,a).then((e=>{const t=new x(s,a);e.addRenderer(t),this.renderingView.onLoop((t=>e.update()))})),s}async createLight(e){if("point"===e.light.type){const t=new y(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 w(.3,10,10),a=new u({color:new r(16771709)}),s=new d(e,a);t.add(s)}return t}return"directional"===e.light.type?(this.applyDirectionalLight(e.light.directional),new l):"ambient"===e.light.type?(this.applyDirectionalAmbientLight(null,e.light.ambient),new l):void 0}applyDirectionalAmbientLight(e,t){const a=this.scene.children.find((e=>e.name===ve));null!=a?(a.intensity=t.intensity,a.color.set(t.color),a.groundColor.set(t.color)):console.warn("Couldn't find ambient light")}applyDirectionalLight(e){for(const t of this.renderingView.csm.lights)t.intensity=e.intensity,t.color.set(e.color),t.castShadow=e.castShadow;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe(),this.createAssetSubscription.unsubscribe(),this.materializedActors.forEach((e=>e.disposed.next(!0)))}}function Pe(e,t,a){e.castShadow=t,e.receiveShadow=a,e.traverse((e=>{e.castShadow=t,e.receiveShadow=a}))}const Ie=new Map,Ee=new Map,Ve=new m({color:16711935}),De=new Map;export async function materialFromAsset(e,t,a,s,r,i=!0){const n=JSON.stringify(e.material);return i&&Ie.has(n)?Ie.get(n):i&&Ee.has(n)?await Ee.get(n):Ee.set(n,_materialFromAsset(n,e,t,a,s,r,i)).get(n)}export async function _materialFromAsset(e,t,s,i,n,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 r(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 i.getAsset(e);null!=a&&(c.map=await n.getTexture(a))}let d;switch(t.material.type){case"phong":d=new p({...c,...h});break;case"water":d=fe(c,s);break;case"grassFoliage":d=me({color:c.color,map:c.map},s);break;case"grass":d=pe({...c,colorTwo:new r(t.material.params.colorTwo),colorThree:new r(t.material.params.colorThree)},s);break;case"standard":case"unlit":case"lambert":case"shader":case"landscape":case"landscape-composite":case"decal-unlit":case"decal-standard":const e={standard:X,lambert:J,unlit:Y,landscape:q,"landscape-composite":H,"decal-unlit":Me,"decal-standard":xe}[t.material.type]??o.find((e=>e.name==t.material.shader))?.type;if(e){try{let a=new e;const r=await Ne(t.material?.shaderParams??{},e,i,n,null,s,o);Object.assign(a,r),d=a.build()}catch(e){console.log("Shader runtime error: "+e),De.has(t.material.shader)||De.set(t.material.shader,Ve.clone()),d=De.get(t.material.shader)}d.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),d=Ve;break;default:throw new Error("Unsupported material type"+t.material.type)}return s?.csm.setupMaterial(d),null!=s&&Ie.set(e,d),d.side=t.material.side??d.side??a.FrontSide,d.transparent=(t.material.transparent??c.transparent??!1)||d.transparent,d.alphaTest=t.material.alphaTest??d.alphaTest??0,t.material.bloom&&(d.userData.hasBloom=!0),d.userData.assetId=t.id,Ee.delete(e),d}async function Ne(e,t,a,s,r,i,n,o){const l={};for(const[t,c]of Object.entries(e)){const e=await Ce(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 Ce(s,null,null,null);null!=e&&(t[a]=e)}return t}async function Ce(e,t,a,s,n,o,l,c=e.value,h=e.type){if(null==e||null==c||""===c)return null;switch(h){case ye.Array:if(Array.isArray(c)&&"element"in e)return await Promise.all(c.map((r=>Ce(e,t,a,s,n,o,l,r,e.element))));break;case ye.Number:case ye.FloatNode:let h="string"==typeof c?parseFloat(c):c;return e.type===ye.FloatNode?I(h):h;case ye.Texture:return await a.getTexture(await t.getAsset(c));case ye.Sampler2DNode:return k(await a.getTexture(await t.getAsset(c)));case ye.Boolean:return c;case ye.BooleanNode:return j(c);case ye.Vector2:case ye.Vec2Node:if("object"==typeof c){const t=c instanceof Array?(new S).fromArray(c):new S(c.x,c.y);return e.type===ye.Vec2Node?_(t):t}return null;case ye.Vector3:case ye.Vec3Node:if("object"==typeof c){const t=c instanceof Array?(new A).fromArray(c):new A(c.x,c.y,c.z);return e.type===ye.Vec3Node?O(t):t}return null;case ye.Color:case ye.RgbNode:const d=new r(c);return e.type===ye.RgbNode?D(d):d;case ye.String:return c;case ye.BaseActor:const m=c;return null==s&&console.warn("Class parameters can not be prepared as actors are not passed in"),s?.get(m);case ye.Euler:const p=c;return(new i).fromArray(p);case ye.Object3D:return(await a.getMesh(await t.getAsset(c))).scene;case ye.Material:return await materialFromAsset(await t.getAsset(c),n,t,a,o);case ye.AudioBuffer:return await a.getAudio(await t.getAsset(c));case ye.VisualEffect:const u=await t.getAsset(c);if(null==l){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in u)return new W(l,u);console.error("Using a non-vfx asset for visual effect parameter");break;case ye.Curve:return be.decode(c)}return null}function ke(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 _e(e){return"linear"===e.type?new n(new r(e.color),e.near??100,e.far??1e3):"density"===e.type?new o(e.color,e.density):void console.warn("Invalid fog type",e)}const Fe=new u({color:4229780});async function Oe(e,t,s,r){null==r&&(r=(new h).identity()),await t(e,s,r);const n=r.clone().multiply(function(e,t){if(null==e.position||null==e.rotation||null==e.scale)return t.identity();return t.compose((new A).fromArray(e.position),(new g).setFromEuler((new i).fromArray(e.rotation)),(new A).fromArray(e.scale))}(e,new a.Matrix4));return Promise.all((e.children??[]).map((a=>Oe(a,t,e,n))))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?ye.Number:t instanceof E||"function"==typeof e.prototype.isFloat?ye.FloatNode:t instanceof v||e===v||e.isTexture?ye.Texture:t instanceof L||e===C?ye.Sampler2DNode:t instanceof Boolean||e===Boolean?ye.Boolean:t instanceof P?ye.BooleanNode:t instanceof r||e==r?ye.Color:t instanceof N||"function"==typeof e.prototype.isRgb?ye.RgbNode:t instanceof S||e==S?ye.Vector2:t instanceof F||"function"==typeof e.prototype.isVec2?ye.Vec2Node:t instanceof A||e==A?ye.Vector3:t instanceof T||"function"==typeof e.prototype.isVec3?ye.Vec3Node:t instanceof String||e===String?ye.String:t instanceof $||e==$||e.prototype instanceof $||e.prototype==$?ye.BaseActor:t instanceof i||e==i?ye.Euler:t instanceof f||e==f?ye.Object3D:t instanceof c||e==c?ye.Material:t instanceof AudioBuffer||e==AudioBuffer?ye.AudioBuffer:t instanceof W||e==W?ye.VisualEffect:t instanceof be||e==be?ye.Curve: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?ye.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=Z(e);if(0===s.length)return{};let r;null!=a?G(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 A:return t instanceof A?t.toArray():void a();case b:return t instanceof b?t.toArray():void a();case r:return t instanceof r?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new r(t).getHexString():void a();case String:return t;case i:return t instanceof i?t.toArray():void a()}}function Te(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=>ze(e.materialId))),(t??[]).filter((e=>ze(e.materialId))),(e=>e.color+e.name))}function ze(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[ye.RgbNode,"#000000"],[ye.Color,"#000000"],[ye.Vector4,[0,0,0,0]],[ye.Vec4Node,[0,0,0,0]],[ye.Vector3,[0,0,0]],[ye.Vec3Node,[0,0,0]],[ye.Vector2,[0,0]],[ye.Vec2Node,[0,0]],[ye.Euler,[0,0,0,"XYZ"]],[ye.Array,[]]]);export function applyMaterial(e,t,s,i){const n=[];return e.traverse((async e=>{if(e instanceof d||e.isMesh||e instanceof a.SkinnedMesh||e.isSkinnedMesh)for(const t of ee(e.material))t.hasOwnProperty("color")&&n.push(e)})),Promise.all(n.map((async e=>{if(e.material instanceof Array)for(let a=0;a<e.material.length;a++){const n=e.material[a];if(null==n.color||!(n.color instanceof r))continue;const o="#"+n.color.getHexString(),l=n.name;if(o===t.color&&(n.name===t.name||null==t.name)||e.userData["originalColor_"+a]===t.color&&e.userData["originalMaterialName_"+a]===t.name){const r=await s(t.materialId),n=e.material[a];null!=r&&n.id!=r.id&&(e.material[a]=r,e.userData["originalColor_"+a]=e.userData["originalColor_"+a]??o,e.userData["originalMaterialName_"+a]=e.userData["originalMaterialName_"+a]??l,null!=i&&i.set(e.id+"#"+a,n))}}else if("color"in e.material){const a="#"+e.material.color.getHexString(),r=e.material.name;if(a===t.color&&(e.material.name===t.name||null==t.name)||e.userData.originalColor===t.color&&e.userData.originalName===t.name){const n=await s(t.materialId),o=e.material;null!=n&&(e.material=n,e.userData.originalColor=e.userData.originalColor??a,e.userData.originalMaterialName=e.userData.originalMaterialName??r,null!=i&&(i.has(e.id)||i.set(e.id,o)))}}})))}function Be(e,t){if(e instanceof a.ShaderMaterial&&t instanceof a.ShaderMaterial){return e.fragmentShader+e.vertexShader==t.fragmentShader+t.vertexShader&&function(e,t){if(e instanceof a.ShaderMaterial&&t instanceof a.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 We(e){if(null!=e){for(let t=0;t<e.array.length;t++)e.setX(t,0);e.needsUpdate=!0}}/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -92,7 +92,7 @@ export type Asset = {
92
92
  export type VfxAsset = Asset & {
93
93
  vfx: VfxAssetData;
94
94
  };
95
- export type MaterialType = 'standard' | 'phong' | 'lambert' | 'shader' | 'water' | 'grass' | 'grassFoliage' | 'unlit' | 'landscape' | 'landscape-composite';
95
+ export type MaterialType = 'standard' | 'phong' | 'lambert' | 'shader' | 'water' | 'grass' | 'grassFoliage' | 'unlit' | 'landscape' | 'landscape-composite' | 'decal-unlit' | 'decal-standard';
96
96
  export type MaterialParameters = {
97
97
  opacity: number;
98
98
  transparent: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scene/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,MAAM,MAAM,SAAS,GAAG,MAAM,GAAC,UAAU,GAAC,OAAO,GAAC,WAAW,GAAC,OAAO,GAAC,SAAS,GAAC,OAAO,GAAC,OAAO,GAAC,QAAQ,GAAC,KAAK,CAAA;AAC9G,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAC,WAAW,CAAA;AACpD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAC,aAAa,GAAC,SAAS,CAAA;AAKvD,oBAAY,mBAAmB;IAC7B,SAAS,IAAI;IACb,MAAM,IAAI;IACV,OAAO,IAAI;IACX,aAAa,IAAI;IACjB,OAAO,IAAI;IACX,WAAW,IAAI;IACf,OAAO,IAAI;IACX,QA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AAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,EAAE,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,WAAW,CAAA;AAEf,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB"}
@@ -0,0 +1,24 @@
1
+ import { Color, Texture, Vector2 } from 'three';
2
+ import { DecalNodeShader } from '../decal-shader.js';
3
+ export declare class DecalStandardShader extends DecalNodeShader {
4
+ color: Color;
5
+ opacity: number;
6
+ colorMap?: Texture;
7
+ alphaMap?: Texture;
8
+ roughness?: number;
9
+ roughnessMap?: Texture;
10
+ metalness?: number;
11
+ metalnessMap?: Texture;
12
+ aoMap?: Texture;
13
+ aoMapIntensity?: number;
14
+ emissive?: Color;
15
+ emissiveIntensity?: number;
16
+ emissiveMap?: Texture;
17
+ normalMap?: Texture;
18
+ normalScale?: Vector2;
19
+ output(): {
20
+ color: import("three-shader-graph").RgbaNode;
21
+ };
22
+ build(): import("three").Material;
23
+ }
24
+ //# sourceMappingURL=decal-standard-shader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decal-standard-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/decal-standard-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAIhD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,qBAAa,mBAAoB,SAAQ,eAAe;IACzC,KAAK,EAAE,KAAK,CAAwB;IACtB,OAAO,EAAE,MAAM,CAAI;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEL,SAAS,CAAC,EAAE,MAAM,CAAK;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IAET,SAAS,CAAC,EAAE,MAAM,CAAK;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,EAAE,KAAK,CAAC;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACzC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,WAAW,CAAC,EAAE,OAAO,CAAC;IAInC,MAAM;;;IA4DN,KAAK;CASN"}
@@ -0,0 +1,4 @@
1
+ import{__decorate as e,__metadata as t}from"tslib";import{Color as a,Texture as s,Vector2 as r}from"three";import{colorToNormal as o,float as i,rgba as p,standardMaterial as l,textureSampler2d as d,uniforms as n,normalize as h,varying as m}from"three-shader-graph";import{decalAlpha as y,decalNormal as c,decalUV as u}from"../../shader-nodes/decal.js";import{depthWorldPosition as S}from"../../shader-nodes/depth.js";import{DecalNodeShader as g}from"../decal-shader.js";import{Parameter as v}from"../parameter.js";export class DecalStandardShader extends g{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0}output(){const e=u;let t=i(this.opacity);null!=this.alphaMap&&(t=t.multiply(d(this.alphaMap).sample(e).r)),t=t.multiply(y);let a=p(this.color,t);null!=this.colorMap&&(a=a.multiply(d(this.colorMap).sample(e)));let s=p(this.emissive,t);null!=this.emissiveMap&&(s=s.multiply(d(this.emissiveMap).sample(e)));let r=i(this.roughness);null!=this.roughnessMap&&(r=r.multiply(d(this.roughnessMap).sample(e).g));let g=i(this.metalness);null!=this.metalnessMap&&(g=g.multiply(d(this.metalnessMap).sample(e).b));let v=h(m(n.normalMatrix).multiplyVec(c));null!=this.normalMap&&(v=o(d(this.normalMap).sample(e),this.normalScale?.x??1,v,S,e));let M=null;return null!=this.aoMap&&(M=d(this.aoMap).sample(e).r),{color:l({color:a,emissive:s,emissiveIntensity:i(this.emissiveIntensity??1),roughness:r,metalness:g,normal:v,ambientOcclusion:M,ambientOcclusionIntensity:i(this.aoMapIntensity??1),worldPosition:S})}}build(){const e=super.build();return e.depthTest=!0,e.depthWrite=!1,e.userData.isDecal=!0,e}}e([v(),t("design:type",a)],DecalStandardShader.prototype,"color",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"opacity",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"colorMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"alphaMap",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"roughness",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"roughnessMap",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"metalness",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"metalnessMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"aoMap",void 0),e([v(),t("design:type",Number)],DecalStandardShader.prototype,"aoMapIntensity",void 0),e([v(),t("design:type",a)],DecalStandardShader.prototype,"emissive",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"emissiveIntensity",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"emissiveMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"normalMap",void 0),e([v(),t("design:type",r)],DecalStandardShader.prototype,"normalScale",void 0);/*
2
+ * Copyright (©) 2023. All rights reserved.
3
+ * See the LICENSE.md file for details.
4
+ */
@@ -0,0 +1,12 @@
1
+ import { Color, Texture } from 'three';
2
+ import { DecalNodeShader } from '../decal-shader.js';
3
+ export declare class DecalUnlitShader extends DecalNodeShader {
4
+ color: Color;
5
+ opacity: number;
6
+ colorMap?: Texture;
7
+ alphaMap?: Texture;
8
+ output(): {
9
+ color: import("three-shader-graph").RgbaNode;
10
+ };
11
+ }
12
+ //# sourceMappingURL=decal-unlit-shader.d.ts.map
@@ -0,0 +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,EAAqE,OAAO,EAAW,MAAM,OAAO,CAAC;AAIlK,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,qBAAa,gBAAiB,SAAQ,eAAe;IACtC,KAAK,EAAE,KAAK,CAAwB;IACtB,OAAO,EAAE,MAAM,CAAI;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEhC,MAAM;;;CAoBP"}
@@ -0,0 +1,4 @@
1
+ import{__decorate as t,__metadata as o}from"tslib";import{Color as e,Texture as r}from"three";import{Parameter as p}from"../parameter.js";import{DecalNodeShader as l}from"../decal-shader.js";import{rgba as a,textureSampler2d as i,float as s}from"three-shader-graph";import{decalAlpha as h,decalUV as c}from"../../shader-nodes/decal.js";export class DecalUnlitShader extends l{constructor(){super(...arguments),this.color=new e("#FFFFFF"),this.opacity=1}output(){const t=c;let o=s(this.opacity);null!=this.alphaMap&&(o=o.multiply(i(this.alphaMap).sample(t).r)),o=o.multiply(h);let e=a(this.color,o);return null!=this.colorMap&&(e=e.multiply(i(this.colorMap).sample(t))),{color:e}}}t([p(),o("design:type",e)],DecalUnlitShader.prototype,"color",void 0),t([p({range:[0,1]}),o("design:type",Number)],DecalUnlitShader.prototype,"opacity",void 0),t([p(),o("design:type",r)],DecalUnlitShader.prototype,"colorMap",void 0),t([p(),o("design:type",r)],DecalUnlitShader.prototype,"alphaMap",void 0);/*
2
+ * Copyright (©) 2023. All rights reserved.
3
+ * See the LICENSE.md file for details.
4
+ */
@@ -0,0 +1,7 @@
1
+ import { Material } from "three";
2
+ import { NodeShaderOutput } from "./shader.js";
3
+ export declare abstract class DecalNodeShader {
4
+ build(): Material;
5
+ abstract output(): NodeShaderOutput;
6
+ }
7
+ //# sourceMappingURL=decal-shader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decal-shader.d.ts","sourceRoot":"","sources":["../../src/shader/decal-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C,8BAAsB,eAAe;IACnC,KAAK,IAAI,QAAQ;IAejB,QAAQ,CAAC,MAAM,IAAI,gBAAgB;CACpC"}
@@ -0,0 +1,4 @@
1
+ import{NodeShaderMaterial as r}from"../shader-nodes/index.js";import{decalDiscard as d}from"../shader-nodes/decal.js";export class DecalNodeShader{build(){const e=this.output();let s=d;return null!=e.discard&&(s=s.or(e.discard)),new r({transparent:!1,...e,discard:s})}}/*
2
+ * Copyright (©) 2023. All rights reserved.
3
+ * See the LICENSE.md file for details.
4
+ */
@@ -0,0 +1,8 @@
1
+ export declare const decalNormal: import("three-shader-graph").Vec3Node;
2
+ export declare const decalDiscard: import("three-shader-graph").BoolOrNode;
3
+ export declare const decalUV: import("three-shader-graph").Vec2Node;
4
+ /**
5
+ * Fade away decal when close to the edges.
6
+ */
7
+ export declare const decalAlpha: import("three-shader-graph").FloatNode;
8
+ //# sourceMappingURL=decal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decal.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/decal.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,WAAW,uCAA2D,CAAA;AAEnF,eAAO,MAAM,YAAY,yCAAwF,CAAA;AACjH,eAAO,MAAM,OAAO,uCAA+B,CAAA;AAInD;;GAEG;AACH,eAAO,MAAM,UAAU,wCAGqC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import{abs as t,inverse as r,min as o,smoothstep as e,uniforms as a,varying as c,vec4 as l}from"three-shader-graph";import{depthNormal as p,depthWorldPosition as x}from"./depth";const d=c(r(a.instanceMatrix.multiply(a.modelMatrix))),i=d.multiplyVec(l(x,1)).xyz;export const decalNormal=d.multiplyVec(l(p,0)).xyz;export const decalDiscard=t(i.x).gt(.5).or(t(i.y).gt(.5)).or(t(i.z).gt(.5));export const decalUV=i.xz.addScalar(.5);export const decalAlpha=o(e(.5,.4,t(i.x)),o(e(.5,.4,t(i.y)),e(.5,.4,t(i.z))));/*
2
+ * Copyright (©) 2023. All rights reserved.
3
+ * See the LICENSE.md file for details.
4
+ */
@@ -8,4 +8,12 @@ export declare const farUniformName = "hology_camera_far";
8
8
  export declare const depthSampler: import("three-shader-graph").UniformSampler2d;
9
9
  export declare const fragmentLinearEyeDepth: FloatNode;
10
10
  export declare const linearEyeDepth: FloatNode;
11
+ /**
12
+ * The position of the fragment closest behind the surface.
13
+ */
14
+ export declare const depthWorldPosition: import("three-shader-graph").Vec3Node;
15
+ /**
16
+ * An approximated normal created by taking multiple samples using a depth texture
17
+ */
18
+ export declare const depthNormal: import("three-shader-graph").Vec3Node;
11
19
  //# sourceMappingURL=depth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"depth.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/depth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAmC,SAAS,EAAoH,MAAM,oBAAoB,CAAC;AAKlM,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,aAAa,WAEpE;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;AA2G3F,eAAO,MAAM,sBAAsB,WAAkB,CAAA;AAOrD,eAAO,MAAM,cAAc,WAA+B,CAAA"}
1
+ {"version":3,"file":"depth.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/depth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAmC,SAAS,EAAuK,MAAM,oBAAoB,CAAC;AAKrP,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,aAAa,WAEpE;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;AA2G3F,eAAO,MAAM,sBAAsB,WAAkB,CAAA;AAOrD,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{Vector2 as e}from"three";import{dot as t,FloatExpressionNode as o,FloatNode as r,texture2d as n,uniformVec2 as a,Vec2ExpressionNode as s,Vec4Node as c,uniformSampler2d as p,uniformFloat as i}from"three-shader-graph";import*as h from"three";export function supportsDepthTextureExtension(e){return!!e.extensions.get("WEBGL_depth_texture")}export const depthUniformName="hology_depth_map";export const resolutionUniformName="hology_resolution";export const nearUniformName="hology_camera_near";export const farUniformName="hology_camera_far";export const depthSampler=p(depthUniformName,new h.DepthTexture(1,1));const m=i(nearUniformName,.5),l=i(farUniformName,500);class u extends r{compile(e){const t=e.variable();var o=e.get(m),r=e.get(l);return{chunk:`\n float depth_${t} = 2.0 * ${o} * ${r} / (${r} + ${o} - (2.0 * ${e.get(this.depth)} - 1.0) * (${r} - ${o}));\n `,out:`depth_${t}`}}constructor(e){super(),this.depth=e}}function _(e){return new u(e)}const f=new class extends c{constructor(){super(...arguments),this.k="31u50"}compile(e){return{pars:`\n const float UnpackDownscale_${this.k} = 255. / 256.; // 0..1 -> fraction (excluding 1)\n const vec4 PackFactors_${this.k} = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\n const vec4 UnpackFactors_${this.k} = vec4( UnpackDownscale_${this.k} / PackFactors_${this.k}.rgb, 1.0 / PackFactors_${this.k}.a );\n `,out:`UnpackFactors_${this.k}`}}};const d=new o("gl_FragCoord.z");export const fragmentLinearEyeDepth=_(d);const g=a("hology_resolution",new e(250,1e3)),x=new s("gl_FragCoord.xy").divide(g);export const linearEyeDepth=_((k=x,$=n(depthSampler,k),t($,f)));var k,$;/*
1
+ import{Vector2 as t}from"three";import{dot as e,float as o,FloatExpressionNode as r,FloatNode as n,texture2d as a,uniformVec2 as c,vec2 as s,Vec2ExpressionNode as i,vec4 as p,Vec4Node as h,uniformSampler2d as l,uniformFloat as d,varying as u,inverse as m,uniforms as x,cross as f,normalize as _}from"three-shader-graph";import*as g from"three";export function supportsDepthTextureExtension(t){return!!t.extensions.get("WEBGL_depth_texture")}export const depthUniformName="hology_depth_map";export const resolutionUniformName="hology_resolution";export const nearUniformName="hology_camera_near";export const farUniformName="hology_camera_far";export const depthSampler=l(depthUniformName,new g.DepthTexture(1,1));const k=d(nearUniformName,.5),y=d(farUniformName,500);class $ extends n{compile(t){const e=t.variable();var o=t.get(k),r=t.get(y);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 v(t){return new $(t)}const U=new class extends h{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 w(t){return o=a(depthSampler,t),e(o,U);var o}const N=new r("gl_FragCoord.z");export const fragmentLinearEyeDepth=v(N);const F=c("hology_resolution",new t(250,1e3)),b=new i("gl_FragCoord.xy").divide(F);export const linearEyeDepth=v(w(b));const D=u(m(x.projectionMatrix)),P=u(m(x.viewMatrix));function S(t=b){const e=w(t).multiply(2).subtract(1),o=t.multiplyScalar(2).subtractScalar(1),r=p(o.x,o.y,e,1),n=D.multiplyVec(r),a=n.xyz.divideScalar(n.w);return P.multiplyVec(p(a,1)).xyz}export const depthWorldPosition=S(b);const E=o(1).divide(F.x),W=o(1).divide(F.y),z=S(b.add(s(E,o(0)))),C=S(b.add(s(o(0),W)));export const depthNormal=_(f(z.subtract(depthWorldPosition),C.subtract(depthWorldPosition)));/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -10,4 +10,5 @@ export * from './effects.js';
10
10
  export * from './math.js';
11
11
  export * from './bulge.js';
12
12
  export * from './texture-sequence.js';
13
+ export * from './decal.js';
13
14
  //# sourceMappingURL=index.d.ts.map