@threepipe/webgi-plugins 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/extras/AdvancedGroundPlugin.d.ts +1 -1
- package/dist/plugins/extras/AdvancedGroundPlugin.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -102,5 +102,5 @@ gl_FragColor = packDepthToRGBA(mix(last, shadow, opacity));
|
|
|
102
102
|
gl_FragColor = saturate(gl_FragColor);
|
|
103
103
|
//gl_FragColor.a = 0.5;
|
|
104
104
|
#endif
|
|
105
|
-
`))},computeCacheKey:()=>this.groundMapMode+"."+this.alphaVignette+"."+this.alphaVignetteAxis,onObjectRender:(e,t)=>{t.userData.gMapMode!==this.groundMapMode&&(t.userData.gMapMode=this.groundMapMode,t.needsUpdate=!0)},isCompatible:e=>e.isPhysicalMaterial},this._viewer=e;const i=new ue(16777215,10,{near:1.5,far:20,bias:0,frustumSize:4,width:1024,height:1024,enabled:!0,radius:10,normalBias:0},{direction:new t.Vector3(.2,1,.2).normalize(),spread:.9,focus:1,distanceScale:20,minDistanceScale:new t.Vector3(10,10,10),normalDirection:new t.Vector3(0,1,0)});i.shadow.camera.updateProjectionMatrix(),i.layers.disableAll(),i.layers.set(this._lightLayer),this._light=i,e.scene.addObject(this._light,{addToRoot:!0}),this._shadowMat=new pe({color:"#ffffff",toneMapped:!1,depthWrite:!1,depthTest:!1,premultipliedAlpha:!1,opacity:1,transparent:!1,blending:t.NoBlending}),this._shadowBlurMat=new t.ShaderMaterial2({uniforms:{colorTexture:{value:null},step:{value:.1},size:{value:new t.Vector2(.5,.5)},direction:{value:new t.Vector2(.5,.5)}},vertexShader:t.shaderUtils.defaultVertex,fragmentShader:"#include <packing>\nuniform sampler2D colorTexture;uniform vec2 size;uniform vec2 direction;uniform float step;varying vec2 vUv;void main(){float sum=0.0;vec2 uvDelta=step*direction/size;sum+=unpackRGBAToDepth(texture2D(colorTexture,vUv-1.*uvDelta))*0.3333;sum+=unpackRGBAToDepth(texture2D(colorTexture,vec2(vUv.x,vUv.y)))*0.3333;sum+=unpackRGBAToDepth(texture2D(colorTexture,vUv+1.*uvDelta))*0.3333;gl_FragColor=packDepthToRGBA(sum);}"})}get attachedMesh(){return this._attachedMesh}set attachedMesh(e){this._attachedMesh!==e&&(this._attachedMesh&&this.cleanupMaterial(),this._attachedMesh=e,this._attachedMesh&&this._updateMaterial())}get target(){return this._target}get light(){return this._light}dispose(){this._shadowMat.dispose(),this._target=void 0,this.reset()}cleanupMaterial(){this._updateMaterial(!0)}_groundMapModeChanged(){this._attachedMesh&&(this.cleanupMaterial(),this._updateMaterial(),"alphaMap"===this.groundMapMode?this._attachedMesh.material.transparent=!0:this._attachedMesh.material.transparent=!1),this.reset()}_alphaVignetteChanged(){this.materialExtension?.setDirty?.(),this._viewer?.setDirty()}fromJSON(e,i,r=!1){return r?(t.ThreeSerialization.Deserialize(e,this,i,!0),this.reset(),this):t.ThreeSerialization.Deserialize(e,this,i,!1)}reset(){this._frameNumber=0}get frameNumber(){return this._frameNumber}autoUpdateShadow(){return!!this.shadowAutoUpdate&&(!(this._bakeCounter>=this.maxBakeCount)&&(!!this.updateShadow()&&(this._frameNumber===this.maxFrameNumber?this.dispatchEvent({type:"shadowBaked",bakeCount:++this._bakeCounter}):this._frameNumber>0&&this._frameNumber<this.maxFrameNumber&&this.dispatchEvent({type:"shadowBaking",progress:this._frameNumber/this.maxFrameNumber,bakeCount:this._bakeCounter}),!0)))}updateShadow(){if(!this.enabled)return!1;const e=this._attachedMesh;if(!e)return!1;if(++this._frameNumber>this.maxFrameNumber)return!1;const i=1024;this._target||(this._target=this._viewer.renderManager.createTarget({type:t.UnsignedByteType,depthBuffer:!1,size:new t.Vector2(i,i),sizeMultiplier:void 0,colorSpace:t.NoColorSpace,format:t.RGBAFormat})),this._frameNumber<3?this._light.randomizePosition(0,1,0):this._light.randomizePosition(this._frameNumber),e.castShadow=!1;const r=this._viewer.renderManager.renderer,a=r.shadowMap,n=a.type,s=a.needsUpdate,o=a.autoUpdate;a.type=this.shadowMapType,a.needsUpdate=!0,a.autoUpdate=!1;const l=this._viewer.scene,c=new t.Layers;c.disableAll(),l.traverse(e=>{e.isLight&&e!==this._light&&(e.userData.__gp_layers=e.layers,e.layers=c)});const u=l.mainCamera;if(u.layers.mask&1<<this._lightLayer)throw"Camera can render pseudo directional light, check layers";u.layers.enable(this._lightLayer),e.layers.disable(this._lightLayer),r.renderWithModes({shadowMapRender:!0,backgroundRender:!1,sceneRender:!1},()=>r.render(l,l.mainCamera)),u.layers.disable(this._lightLayer);const d=u.layers.mask;u.layers.set(this._lightLayer),e.layers.enable(this._lightLayer);const h=this._viewer.renderManager.getTempTarget({type:t.UnsignedByteType,depthBuffer:!1,size:new t.Vector2(i,i),colorSpace:t.NoColorSpace,format:t.RGBAFormat}),p=h.texture,f=p.colorSpace;p.colorSpace=t.NoColorSpace,this._viewer.renderManager.blit(h,{clear:!0,source:this._target.texture});{const t=e.material,i=e.frustumCulled,a=r.getRenderTarget(),n=r.getActiveCubeFace(),s=r.getActiveMipmapLevel();e.material=this._shadowMat,e.frustumCulled=!1,r.setRenderTarget(this._target),this._shadowMat.opacity=Math.max(1/this.maxFrameNumber,1/this._frameNumber),this._shadowMat.lastFrameTexture=h.texture,this._shadowMat.needsUpdate=!0,r.renderWithModes({shadowMapRender:!1,backgroundRender:!1,opaqueRender:!0,transparentRender:!1,transmissionRender:!1},()=>r.render(l,l.mainCamera)),r.setRenderTarget(a,n,s),e.frustumCulled=i,e.material=t,this.smoothShadow&&this._applySmoothFilter(this._target,h)}return h.texture.colorSpace=f,this._viewer.renderManager.releaseTempTarget(h),e.layers.disable(this._lightLayer),u.layers.mask=d,l.modelObject.traverse(e=>{e.isLight&&e!==this._light.lightObject&&(e.layers=e.userData.__gp_layers,delete e.userData.__gp_layers)}),a.type=n,a.needsUpdate=s,a.autoUpdate=o,e.castShadow=!0,(this._frameNumber<3||this._frameNumber>Math.min(100,this.maxFrameNumber)&&this._frameNumber%4==0)&&(this._updateMaterial(),e.material.setDirty()),!0}_updateMaterial(e=!1){this._attachedMesh&&(e?(this._attachedMesh.material.alphaMap===this._target?.texture&&(this._attachedMesh.material.alphaMap=null),this._attachedMesh.material.aoMap===this._target?.texture&&(this._attachedMesh.material.aoMap=null),this._attachedMesh.material.map===this._target?.texture&&(this._attachedMesh.material.map=null)):this._target&&("alphaMap"===this.groundMapMode&&(this._attachedMesh.material.alphaMap=this._target.texture),"aoMap"===this.groundMapMode&&(this._attachedMesh.material.aoMap=this._target.texture),"map"===this.groundMapMode&&(this._attachedMesh.material.map=this._target.texture)),this._attachedMesh.material&&(this._attachedMesh.material.userData.ALPHA_I_RGBA_PACKING=!e&&"alphaMap"===this.groundMapMode,this._attachedMesh.material.alphaTest=e||"alphaMap"!==this.groundMapMode?0:.01,this._attachedMesh.material.needsUpdate=!0))}_applySmoothFilter(e,t){this._shadowBlurMat.uniforms.colorTexture.value=e.texture,this._shadowBlurMat.uniforms.direction.value.set(1,0),this._shadowBlurMat.uniforms.size.value.set(e.width,e.height),this._viewer.renderManager.blit(t,{material:this._shadowBlurMat}),this._shadowBlurMat.uniforms.colorTexture.value=t.texture,this._shadowBlurMat.uniforms.direction.value.set(0,1),this._shadowBlurMat.uniforms.size.value.set(t.width,t.height),this._viewer.renderManager.blit(e,{material:this._shadowBlurMat})}};ge([t.serialize("randomizedLight")],ve.prototype,"_light"),ge([t.onChange(ve.prototype.reset),t.serialize()],ve.prototype,"maxFrameNumber"),ge([t.onChange(ve.prototype.reset),t.serialize()],ve.prototype,"smoothShadow"),ge([t.serialize(),t.onChange(ve.prototype.reset)],ve.prototype,"shadowMapType"),ge([t.onChange(ve.prototype._groundMapModeChanged),t.serialize()],ve.prototype,"groundMapMode"),ge([t.serialize(),t.onChange(ve.prototype._alphaVignetteChanged)],ve.prototype,"alphaVignette"),ge([t.serialize(),t.onChange(ve.prototype._alphaVignetteChanged)],ve.prototype,"alphaVignetteAxis"),ge([t.serialize()],ve.prototype,"maxBakeCount");let _e=ve;var Se=Object.defineProperty,ye=(e,t,i,r)=>{for(var a,n=void 0,s=e.length-1;s>=0;s--)(a=e[s])&&(n=a(t,i,n)||n);return n&&Se(t,i,n),n};const xe=((r=class extends t.BaseGroundPlugin{constructor(){super(),this.bakedShadows=!0,this.groundReflection=!1,this.physicalReflections=!1,this.autoFrustumSize=!0,this.autoBakeShadows=!0,this.autoResetShadows=()=>{this.autoBakeShadows&&this._shadowBaker?.reset()},this._onSceneUpdate=this._onSceneUpdate.bind(this);const e=t.generateUiConfig(this),i=e.find(e=>"function"==typeof e);this.uiConfig={label:"Ground",type:"folder",children:[...e.filter(e=>e!==i),...this._extraUiConfig(),i]}}get shadowBaker(){return this._shadowBaker}_refresh3(){this.refresh()}bakeShadows(){this._shadowBaker?.reset()}_createMesh(e){if(e)throw new Error("AdvancedGroundPlugin - mesh should not be provided");const i=new ee(this._geometry,()=>this._viewer?.renderManager.createTarget({type:t.UnsignedByteType,format:t.RGBAFormat,colorSpace:t.NoColorSpace,size:{width:1024,height:1024},generateMipmaps:!0,depthBuffer:!0,minFilter:t.LinearMipmapLinearFilter,magFilter:t.LinearFilter}),0,this._createMaterial()),r=i.onBeforeRender;return i.onBeforeRender=(...e)=>{let t=this._viewer?.getPluginByType("SSReflectionPlugin");t&&t.isDisabled()&&(t=void 0),t&&t.disable(i.uuid,!1),r(...e),t&&t.enable(i.uuid,!1)},i}onAdded(e){super.onAdded(e)}_postFrame(){super._postFrame(),this._viewer&&this.enabled&&this._shadowBaker&&this.bakedShadows&&this._shadowBaker.autoUpdateShadow()}_preRender(){super._preRender(),this._viewer&&(this._mesh.reflectionTargetNeedsUpdate=this._viewer.renderManager.frameCount<1)}onRemove(e){return super.onRemove(e)}_removeMaterial(){if(this._material){if(this._shadowBaker&&this._material.groundMatExtension&&(this._material.unregisterMaterialExtensions?.([this._shadowBaker.materialExtension]),delete this._material.groundMatExtension),this._material.reflectorMatExtension){const e=this._mesh.materialExtension;e||this._viewer?.console.warn("AdavancedGroundPlugin: unable to find the extension to unregister"),this._material.unregisterMaterialExtensions?.([e]),delete this._material.reflectorMatExtension}super._removeMaterial()}}_onSceneUpdate(e){super._onSceneUpdate(e),!1!==e.geometryChanged&&this.autoResetShadows()}refresh(){if(this._viewer){if(!this.isDisabled()){this.bakedShadows&&!this._shadowBaker?(this._shadowBaker=new _e(this._viewer),this._shadowBaker.attachedMesh=this._mesh):!this.bakedShadows&&this._shadowBaker&&(this._shadowBaker.reset(),this._shadowBaker.cleanupMaterial());const e=this._mesh;e.isReflector2&&(e.enabled=this.groundReflection,e.reflectorModePhysical=this.physicalReflections)}super.refresh()}}_refreshTransform(){if(!super._refreshTransform())return!1;if(this.autoFrustumSize){const e=this.shadowBaker;if(e){const t=this.size/2;t!==e.light.shadowParams.frustumSize&&(e.light.shadowParams.frustumSize=t,e.light.updateShadowParams(),e.reset())}}return!0}fromJSON(e,t){return super.fromJSON(e,t)?(void 0===e.autoFrustumSize&&(this.autoFrustumSize=!1),this):null}_refreshMaterial(){if(!this._viewer)return!1;if(super._refreshMaterial(),this._material){if(this.groundReflection&&this._mesh.isReflector2&&!this._material.reflectorMatExtension){const e=this._mesh.materialExtension;e.updaters=[this._viewer.scene,this._viewer.renderManager],this._material.registerMaterialExtensions?.([e]),this._material.reflectorMatExtension=!0}this.bakedShadows&&this._shadowBaker&&!this._material.groundMatExtension&&(this._material.registerMaterialExtensions?.([this._shadowBaker.materialExtension]),this._material.groundMatExtension=!0),this._material.userData.ssreflDisabled=this.groundReflection,this._material.userData.ssreflNonPhysical=!this.physicalReflections,this._material.userData.ssaoDisabled=!0,this._material.userData.sscsDisabled=!0,this._viewer.setDirty(this)}}_extraUiConfig(){return[{label:"Shadow Frames",type:"input",hidden:()=>!this._shadowBaker,stepSize:1,bounds:[1,1e3],property:()=>[this._shadowBaker,"maxFrameNumber"]},{label:"Alpha Vignette",type:"checkbox",hidden:()=>!this._material||(this._material.transmission||0)<1e-4&&!this._material.transparent,property:()=>[this._shadowBaker,"alphaVignette"],limitedUi:!0,onChange:()=>this.uiConfig?.uiRefresh?.(!0,"postFrame")},{label:"Alpha Vignette Axis",type:"dropdown",hidden:()=>!this._shadowBaker?.alphaVignette||!this._material||(this._material.transmission||0)<1e-4&&!this._material.transparent,property:()=>[this._shadowBaker,"alphaVignetteAxis"],children:["x","y","xy"].map(e=>({label:e,value:e})),limitedUi:!0},{label:"Shadow type",type:"dropdown",hidden:()=>!this._shadowBaker,property:()=>[this._shadowBaker,"groundMapMode"],children:[{label:"aoMap"},{label:"map"},{label:"alphaMap"}],limitedUi:!0},{label:"Smooth Shadow",type:"checkbox",property:()=>[this._shadowBaker,"smoothShadow"]},{label:"Baked shadow type",type:"dropdown",children:[["Basic",t.BasicShadowMap],["PCF",t.PCFShadowMap],["PCFSoft",t.PCFSoftShadowMap],["VSM",t.VSMShadowMap]].map(e=>({label:e[0].toString(),value:e[1]})),property:()=>[this._shadowBaker,"shadowMapType"]},{type:"folder",label:"Randomized Light",hidden:()=>!this._shadowBaker,limitedUi:!0,children:[{type:"color",label:"Color",property:()=>[this._shadowBaker?.light,"color"]},{type:"slider",bounds:[0,1],property:()=>[this._shadowBaker?.light?.randomParams,"focus"],onChange:this.autoResetShadows},{type:"slider",bounds:[0,1],property:()=>[this._shadowBaker?.light?.randomParams,"spread"],onChange:this.autoResetShadows,limitedUi:!0},{type:"slider",bounds:[.01,60],property:()=>[this._shadowBaker?.light?.randomParams,"distanceScale"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"vec3",bounds:[-1,1],property:()=>[this._shadowBaker?.light?.randomParams,"direction"],onChange:this.autoResetShadows,limitedUi:!0},{type:"vec3",bounds:[-1,1],property:()=>[this._shadowBaker?.light?.randomParams,"normalDirection"],onChange:this.autoResetShadows,limitedUi:!0},{type:"slider",bounds:[.01,10],property:()=>[this._shadowBaker?.light?.shadowParams,"radius"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"input",property:()=>[this._shadowBaker?.light?.shadowParams,"frustumSize"],hidden:()=>this.autoFrustumSize,onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"slider",bounds:[-.1,.1],property:()=>[this._shadowBaker?.light?.shadowParams,"bias"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]}]}]}}).PluginType="AdvancedGroundPlugin",r);ye([t.onChange(xe.prototype._refresh3),t.uiToggle("Baked Shadows"),t.serialize()],xe.prototype,"bakedShadows"),ye([t.onChange(xe.prototype._refresh3),t.uiToggle("Planar Reflections"),t.serialize()],xe.prototype,"groundReflection"),ye([t.onChange(xe.prototype._refresh3),t.uiToggle("Physical Reflections"),t.serialize()],xe.prototype,"physicalReflections"),ye([t.onChange(xe.prototype._refresh3),t.uiToggle("Auto Shadow Frustum Size"),t.serialize()],xe.prototype,"autoFrustumSize"),ye([t.serialize("shadowBaker")],xe.prototype,"_shadowBaker"),ye([t.bindToValue({key:"groundReflection"})],xe.prototype,"planarReflections");let Pe=xe;var be=Object.defineProperty,we=Object.getOwnPropertyDescriptor,Te=(e,t,i,r)=>{for(var a,n=r>1?void 0:r?we(t,i):t,s=e.length-1;s>=0;s--)(a=e[s])&&(n=(r?a(t,i,n):a(n))||n);return r&&n&&be(t,i,n),n};e.WatchHandsPlugin=class extends t.AViewerPluginSync{constructor(){super(...arguments),this.enabled=!0,this.dependencies=[],this.axis="y",this.invertAxis=!1,this.analog=!0,this.hourOffset=0,this.minuteOffset=0,this.secondOffset=0,this.hour=".*hour.*",this.minute=".*minute.*",this.second=".*second.*",this.regex=!0,this.hands=[],this._lastEnabled=!0,this._preFrame=()=>{if(!this.enabled){if(this._lastEnabled){if(this._lastEnabled=!1,!this.hands.length)return;for(const e of this.hands)e.object.rotation.fromArray(e.object.userData.initRotation),e.object.updateMatrixWorld();this._viewer?.renderManager.resetShadows(),this._viewer?.setDirty()}return}if(this._lastEnabled=!0,!this.hands.length)return;const e=this._viewer?.getPlugin("ProgressivePlugin")?.postFrameConvergedRecordingDelta();if(0===e)return;const t=new Date,i=this.invertAxis?-1:1,r=i*(t.getSeconds()+(this.analog?t.getMilliseconds()/1e3:0)-this.secondOffset)*(2*Math.PI)/60,a=i*(t.getMinutes()-this.minuteOffset)*(2*Math.PI)/60+r/60,n=i*(t.getHours()-this.hourOffset)*(2*Math.PI)/12+a/12;if(this.hands.find(e=>"second"===e.type&&Math.abs(r-e.object.rotation[this.axis])>.001)){for(const e of this.hands)"second"===e.type&&(e.object.rotation[this.axis]=r),"minute"===e.type&&(e.object.rotation[this.axis]=a),"hour"===e.type&&(e.object.rotation[this.axis]=n);this._viewer?.renderManager.resetShadows(),this._viewer?.setDirty()}},this._addSceneObject=async e=>{e.object&&this.refresh()}}onAdded(e){super.onAdded(e),e.scene.addEventListener("addSceneObject",this._addSceneObject),e.addEventListener("preFrame",this._preFrame)}onRemove(e){e.scene.removeEventListener("addSceneObject",this._addSceneObject),e.removeEventListener("preFrame",this._preFrame),super.onRemove(e)}refresh(){this.hands=[],this._viewer?.scene.modelRoot.traverse(e=>{let t=!1;e.traverseAncestors(e=>{t||this.hands.find(t=>t.object===e)&&(t=!0)}),t||(e.name.match(this.regex?new RegExp(this.hour):this.hour)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"hour",object:e})),e.name.match(this.regex?new RegExp(this.minute):this.minute)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"minute",object:e})),e.name.match(this.regex?new RegExp(this.second):this.second)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"second",object:e})))})}},e.WatchHandsPlugin.PluginType="WatchHandsPlugin",Te([t.uiToggle(),t.serialize()],e.WatchHandsPlugin.prototype,"enabled",2),Te([t.uiDropdown(void 0,["x","y","z"].map(e=>({label:e}))),t.serialize()],e.WatchHandsPlugin.prototype,"axis",2),Te([t.uiToggle(),t.serialize()],e.WatchHandsPlugin.prototype,"invertAxis",2),Te([t.uiToggle(),t.serialize()],e.WatchHandsPlugin.prototype,"analog",2),Te([t.uiSlider(void 0,[0,12],.001),t.serialize()],e.WatchHandsPlugin.prototype,"hourOffset",2),Te([t.uiSlider(void 0,[0,60],.001),t.serialize()],e.WatchHandsPlugin.prototype,"minuteOffset",2),Te([t.uiSlider(void 0,[0,60],.001),t.serialize()],e.WatchHandsPlugin.prototype,"secondOffset",2),Te([t.uiInput(),t.serialize()],e.WatchHandsPlugin.prototype,"hour",2),Te([t.uiInput(),t.serialize()],e.WatchHandsPlugin.prototype,"minute",2),Te([t.uiInput(),t.serialize()],e.WatchHandsPlugin.prototype,"second",2),Te([t.uiToggle(),t.onChange("refresh"),t.serialize()],e.WatchHandsPlugin.prototype,"regex",2),Te([t.uiButton()],e.WatchHandsPlugin.prototype,"refresh",1),e.WatchHandsPlugin=Te([t.uiFolderContainer("Watch Hands Time")],e.WatchHandsPlugin);const De=[u,e.VelocityBufferPlugin,y,e.SSReflectionPlugin,e.SSContactShadowsPlugin,T,e.OutlinePlugin,e.SSGIPlugin,e.AnisotropyPlugin,Pe,e.WatchHandsPlugin];e.AdvancedGroundPlugin=Pe,e.BloomPlugin=y,e.DepthOfFieldPlugin=T,e.SSVelocityMaterial=g,e.TemporalAAPlugin=u,e.TemporalAAPluginPass=d,e.anisotropyGLTFExtension=Z,e.webgiPlugins=De,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
105
|
+
`))},computeCacheKey:()=>this.groundMapMode+"."+this.alphaVignette+"."+this.alphaVignetteAxis,onObjectRender:(e,t)=>{t.userData.gMapMode!==this.groundMapMode&&(t.userData.gMapMode=this.groundMapMode,t.needsUpdate=!0)},isCompatible:e=>e.isPhysicalMaterial},this._viewer=e;const i=new ue(16777215,10,{near:1.5,far:20,bias:0,frustumSize:4,width:1024,height:1024,enabled:!0,radius:10,normalBias:0},{direction:new t.Vector3(.2,1,.2).normalize(),spread:.9,focus:1,distanceScale:20,minDistanceScale:new t.Vector3(10,10,10),normalDirection:new t.Vector3(0,1,0)});i.shadow.camera.updateProjectionMatrix(),i.layers.disableAll(),i.layers.set(this._lightLayer),this._light=i,e.scene.addObject(this._light,{addToRoot:!0}),this._shadowMat=new pe({color:"#ffffff",toneMapped:!1,depthWrite:!1,depthTest:!1,premultipliedAlpha:!1,opacity:1,transparent:!1,blending:t.NoBlending}),this._shadowBlurMat=new t.ShaderMaterial2({uniforms:{colorTexture:{value:null},step:{value:.1},size:{value:new t.Vector2(.5,.5)},direction:{value:new t.Vector2(.5,.5)}},vertexShader:t.shaderUtils.defaultVertex,fragmentShader:"#include <packing>\nuniform sampler2D colorTexture;uniform vec2 size;uniform vec2 direction;uniform float step;varying vec2 vUv;void main(){float sum=0.0;vec2 uvDelta=step*direction/size;sum+=unpackRGBAToDepth(texture2D(colorTexture,vUv-1.*uvDelta))*0.3333;sum+=unpackRGBAToDepth(texture2D(colorTexture,vec2(vUv.x,vUv.y)))*0.3333;sum+=unpackRGBAToDepth(texture2D(colorTexture,vUv+1.*uvDelta))*0.3333;gl_FragColor=packDepthToRGBA(sum);}"})}get attachedMesh(){return this._attachedMesh}set attachedMesh(e){this._attachedMesh!==e&&(this._attachedMesh&&this.cleanupMaterial(),this._attachedMesh=e,this._attachedMesh&&this._updateMaterial())}get target(){return this._target}get light(){return this._light}dispose(){this._shadowMat.dispose(),this._target=void 0,this.reset()}cleanupMaterial(){this._updateMaterial(!0)}_groundMapModeChanged(){this._attachedMesh&&(this.cleanupMaterial(),this._updateMaterial(),"alphaMap"===this.groundMapMode?this._attachedMesh.material.transparent=!0:this._attachedMesh.material.transparent=!1),this.reset()}_alphaVignetteChanged(){this.materialExtension?.setDirty?.(),this._viewer?.setDirty()}fromJSON(e,i,r=!1){return r?(t.ThreeSerialization.Deserialize(e,this,i,!0),this.reset(),this):t.ThreeSerialization.Deserialize(e,this,i,!1)}reset(){this._frameNumber=0}get frameNumber(){return this._frameNumber}autoUpdateShadow(){return!!this.shadowAutoUpdate&&(!(this._bakeCounter>=this.maxBakeCount)&&(!!this.updateShadow()&&(this._frameNumber===this.maxFrameNumber?this.dispatchEvent({type:"shadowBaked",bakeCount:++this._bakeCounter}):this._frameNumber>0&&this._frameNumber<this.maxFrameNumber&&this.dispatchEvent({type:"shadowBaking",progress:this._frameNumber/this.maxFrameNumber,bakeCount:this._bakeCounter}),!0)))}updateShadow(){if(!this.enabled)return!1;const e=this._attachedMesh;if(!e)return!1;if(++this._frameNumber>this.maxFrameNumber)return!1;const i=1024;this._target||(this._target=this._viewer.renderManager.createTarget({type:t.UnsignedByteType,depthBuffer:!1,size:new t.Vector2(i,i),sizeMultiplier:void 0,colorSpace:t.NoColorSpace,format:t.RGBAFormat})),this._frameNumber<3?this._light.randomizePosition(0,1,0):this._light.randomizePosition(this._frameNumber),e.castShadow=!1;const r=this._viewer.renderManager.renderer,a=r.shadowMap,n=a.type,s=a.needsUpdate,o=a.autoUpdate;a.type=this.shadowMapType,a.needsUpdate=!0,a.autoUpdate=!1;const l=this._viewer.scene,c=new t.Layers;c.disableAll(),l.traverse(e=>{e.isLight&&e!==this._light&&(e.userData.__gp_layers=e.layers,e.layers=c)});const u=l.mainCamera;if(u.layers.mask&1<<this._lightLayer)throw"Camera can render pseudo directional light, check layers";u.layers.enable(this._lightLayer),e.layers.disable(this._lightLayer),r.renderWithModes({shadowMapRender:!0,backgroundRender:!1,sceneRender:!1},()=>r.render(l,l.mainCamera)),u.layers.disable(this._lightLayer);const d=u.layers.mask;u.layers.set(this._lightLayer),e.layers.enable(this._lightLayer);const h=this._viewer.renderManager.getTempTarget({type:t.UnsignedByteType,depthBuffer:!1,size:new t.Vector2(i,i),colorSpace:t.NoColorSpace,format:t.RGBAFormat}),p=h.texture,f=p.colorSpace;p.colorSpace=t.NoColorSpace,this._viewer.renderManager.blit(h,{clear:!0,source:this._target.texture});{const t=e.material,i=e.frustumCulled,a=r.getRenderTarget(),n=r.getActiveCubeFace(),s=r.getActiveMipmapLevel();e.material=this._shadowMat,e.frustumCulled=!1,r.setRenderTarget(this._target),this._shadowMat.opacity=Math.max(1/this.maxFrameNumber,1/this._frameNumber),this._shadowMat.lastFrameTexture=h.texture,this._shadowMat.needsUpdate=!0,r.renderWithModes({shadowMapRender:!1,backgroundRender:!1,opaqueRender:!0,transparentRender:!1,transmissionRender:!1},()=>r.render(l,l.mainCamera)),r.setRenderTarget(a,n,s),e.frustumCulled=i,e.material=t,this.smoothShadow&&this._applySmoothFilter(this._target,h)}return h.texture.colorSpace=f,this._viewer.renderManager.releaseTempTarget(h),e.layers.disable(this._lightLayer),u.layers.mask=d,l.modelObject.traverse(e=>{e.isLight&&e!==this._light.lightObject&&(e.layers=e.userData.__gp_layers,delete e.userData.__gp_layers)}),a.type=n,a.needsUpdate=s,a.autoUpdate=o,e.castShadow=!0,(this._frameNumber<3||this._frameNumber>Math.min(100,this.maxFrameNumber)&&this._frameNumber%4==0)&&(this._updateMaterial(),e.material.setDirty()),!0}_updateMaterial(e=!1){this._attachedMesh&&(e?(this._attachedMesh.material.alphaMap===this._target?.texture&&(this._attachedMesh.material.alphaMap=null),this._attachedMesh.material.aoMap===this._target?.texture&&(this._attachedMesh.material.aoMap=null),this._attachedMesh.material.map===this._target?.texture&&(this._attachedMesh.material.map=null)):this._target&&("alphaMap"===this.groundMapMode&&(this._attachedMesh.material.alphaMap=this._target.texture),"aoMap"===this.groundMapMode&&(this._attachedMesh.material.aoMap=this._target.texture),"map"===this.groundMapMode&&(this._attachedMesh.material.map=this._target.texture)),this._attachedMesh.material&&(this._attachedMesh.material.userData.ALPHA_I_RGBA_PACKING=!e&&"alphaMap"===this.groundMapMode,this._attachedMesh.material.alphaTest=e||"alphaMap"!==this.groundMapMode?0:.01,this._attachedMesh.material.needsUpdate=!0))}_applySmoothFilter(e,t){this._shadowBlurMat.uniforms.colorTexture.value=e.texture,this._shadowBlurMat.uniforms.direction.value.set(1,0),this._shadowBlurMat.uniforms.size.value.set(e.width,e.height),this._viewer.renderManager.blit(t,{material:this._shadowBlurMat}),this._shadowBlurMat.uniforms.colorTexture.value=t.texture,this._shadowBlurMat.uniforms.direction.value.set(0,1),this._shadowBlurMat.uniforms.size.value.set(t.width,t.height),this._viewer.renderManager.blit(e,{material:this._shadowBlurMat})}};ge([t.serialize("randomizedLight")],ve.prototype,"_light"),ge([t.onChange(ve.prototype.reset),t.serialize()],ve.prototype,"maxFrameNumber"),ge([t.onChange(ve.prototype.reset),t.serialize()],ve.prototype,"smoothShadow"),ge([t.serialize(),t.onChange(ve.prototype.reset)],ve.prototype,"shadowMapType"),ge([t.onChange(ve.prototype._groundMapModeChanged),t.serialize()],ve.prototype,"groundMapMode"),ge([t.serialize(),t.onChange(ve.prototype._alphaVignetteChanged)],ve.prototype,"alphaVignette"),ge([t.serialize(),t.onChange(ve.prototype._alphaVignetteChanged)],ve.prototype,"alphaVignetteAxis"),ge([t.serialize()],ve.prototype,"maxBakeCount");let _e=ve;var Se=Object.defineProperty,ye=(e,t,i,r)=>{for(var a,n=void 0,s=e.length-1;s>=0;s--)(a=e[s])&&(n=a(t,i,n)||n);return n&&Se(t,i,n),n};const xe=((r=class extends t.BaseGroundPlugin{constructor(){super(),this.bakedShadows=!0,this.groundReflection=!1,this.physicalReflections=!1,this.autoFrustumSize=!0,this.autoBakeShadows=!0,this.autoResetShadows=()=>{this.autoBakeShadows&&this._shadowBaker?.reset()},this._onSceneUpdate=this._onSceneUpdate.bind(this);const e=t.generateUiConfig(this),i=e.find(e=>"function"==typeof e);this.uiConfig={label:"Ground",type:"folder",children:[...e.filter(e=>e!==i),...this._extraUiConfig(),i]}}get shadowBaker(){return this._shadowBaker}_refresh3(){this.refresh()}bakeShadows(){this._shadowBaker?.reset()}_createMesh(e){if(e)throw new Error("AdvancedGroundPlugin - mesh should not be provided");const i=new ee(this._geometry,()=>this._viewer?.renderManager.createTarget({type:t.UnsignedByteType,format:t.RGBAFormat,colorSpace:t.NoColorSpace,size:{width:1024,height:1024},generateMipmaps:!0,depthBuffer:!0,minFilter:t.LinearMipmapLinearFilter,magFilter:t.LinearFilter}),0,this._createMaterial()),r=i.onBeforeRender;return i.onBeforeRender=(...e)=>{let t=this._viewer?.getPluginByType("SSReflectionPlugin");t&&t.isDisabled()&&(t=void 0),t&&t.disable(i.uuid,!1),r(...e),t&&t.enable(i.uuid,!1)},i}onAdded(e){super.onAdded(e)}_postFrame(){super._postFrame(),this._viewer&&this.enabled&&this._shadowBaker&&this.bakedShadows&&this._shadowBaker.autoUpdateShadow()}_preRender(){super._preRender(),this._viewer&&(this._mesh.reflectionTargetNeedsUpdate=this._viewer.renderManager.frameCount<1)}onRemove(e){return super.onRemove(e)}_removeMaterial(){if(this._material){if(this._shadowBaker&&this._material.groundMatExtension&&(this._material.unregisterMaterialExtensions?.([this._shadowBaker.materialExtension]),delete this._material.groundMatExtension),this._material.reflectorMatExtension){const e=this._mesh.materialExtension;e||this._viewer?.console.warn("AdavancedGroundPlugin: unable to find the extension to unregister"),this._material.unregisterMaterialExtensions?.([e]),delete this._material.reflectorMatExtension}super._removeMaterial()}}_onSceneUpdate(e){super._onSceneUpdate(e),"widget"===e?.object?.assetType||e?.object?.userData?.isWidgetRoot||!1!==e.geometryChanged&&this.autoResetShadows()}refresh(){if(this._viewer){if(!this.isDisabled()){this.bakedShadows&&!this._shadowBaker?(this._shadowBaker=new _e(this._viewer),this._shadowBaker.attachedMesh=this._mesh):!this.bakedShadows&&this._shadowBaker&&(this._shadowBaker.reset(),this._shadowBaker.cleanupMaterial());const e=this._mesh;e.isReflector2&&(e.enabled=this.groundReflection,e.reflectorModePhysical=this.physicalReflections)}super.refresh()}}_refreshTransform(){if(!super._refreshTransform())return!1;if(this.autoFrustumSize){const e=this.shadowBaker;if(e){const t=this.size/2;t!==e.light.shadowParams.frustumSize&&(e.light.shadowParams.frustumSize=t,e.light.updateShadowParams(),e.reset())}}return!0}fromJSON(e,t){return super.fromJSON(e,t)?(void 0===e.autoFrustumSize&&(this.autoFrustumSize=!1),this):null}_refreshMaterial(){if(!this._viewer)return!1;if(super._refreshMaterial(),this._material){if(this.groundReflection&&this._mesh.isReflector2&&!this._material.reflectorMatExtension){const e=this._mesh.materialExtension;e.updaters=[this._viewer.scene,this._viewer.renderManager],this._material.registerMaterialExtensions?.([e]),this._material.reflectorMatExtension=!0}this.bakedShadows&&this._shadowBaker&&!this._material.groundMatExtension&&(this._material.registerMaterialExtensions?.([this._shadowBaker.materialExtension]),this._material.groundMatExtension=!0),this._material.userData.ssreflDisabled=this.groundReflection,this._material.userData.ssreflNonPhysical=!this.physicalReflections,this._material.userData.ssaoDisabled=!0,this._material.userData.sscsDisabled=!0,this._viewer.setDirty(this)}}_extraUiConfig(){return[{label:"Shadow Frames",type:"input",hidden:()=>!this._shadowBaker,stepSize:1,bounds:[1,1e3],property:()=>[this._shadowBaker,"maxFrameNumber"]},{label:"Alpha Vignette",type:"checkbox",hidden:()=>!this._material||(this._material.transmission||0)<1e-4&&!this._material.transparent,property:()=>[this._shadowBaker,"alphaVignette"],limitedUi:!0,onChange:()=>this.uiConfig?.uiRefresh?.(!0,"postFrame")},{label:"Alpha Vignette Axis",type:"dropdown",hidden:()=>!this._shadowBaker?.alphaVignette||!this._material||(this._material.transmission||0)<1e-4&&!this._material.transparent,property:()=>[this._shadowBaker,"alphaVignetteAxis"],children:["x","y","xy"].map(e=>({label:e,value:e})),limitedUi:!0},{label:"Shadow type",type:"dropdown",hidden:()=>!this._shadowBaker,property:()=>[this._shadowBaker,"groundMapMode"],children:[{label:"aoMap"},{label:"map"},{label:"alphaMap"}],limitedUi:!0},{label:"Smooth Shadow",type:"checkbox",property:()=>[this._shadowBaker,"smoothShadow"]},{label:"Baked shadow type",type:"dropdown",children:[["Basic",t.BasicShadowMap],["PCF",t.PCFShadowMap],["PCFSoft",t.PCFSoftShadowMap],["VSM",t.VSMShadowMap]].map(e=>({label:e[0].toString(),value:e[1]})),property:()=>[this._shadowBaker,"shadowMapType"]},{type:"folder",label:"Randomized Light",hidden:()=>!this._shadowBaker,limitedUi:!0,children:[{type:"color",label:"Color",property:()=>[this._shadowBaker?.light,"color"]},{type:"slider",bounds:[0,1],property:()=>[this._shadowBaker?.light?.randomParams,"focus"],onChange:this.autoResetShadows},{type:"slider",bounds:[0,1],property:()=>[this._shadowBaker?.light?.randomParams,"spread"],onChange:this.autoResetShadows,limitedUi:!0},{type:"slider",bounds:[.01,60],property:()=>[this._shadowBaker?.light?.randomParams,"distanceScale"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"vec3",bounds:[-1,1],property:()=>[this._shadowBaker?.light?.randomParams,"direction"],onChange:this.autoResetShadows,limitedUi:!0},{type:"vec3",bounds:[-1,1],property:()=>[this._shadowBaker?.light?.randomParams,"normalDirection"],onChange:this.autoResetShadows,limitedUi:!0},{type:"slider",bounds:[.01,10],property:()=>[this._shadowBaker?.light?.shadowParams,"radius"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"input",property:()=>[this._shadowBaker?.light?.shadowParams,"frustumSize"],hidden:()=>this.autoFrustumSize,onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]},{type:"slider",bounds:[-.1,.1],property:()=>[this._shadowBaker?.light?.shadowParams,"bias"],onChange:[this._shadowBaker?.light?.updateShadowParams,this.autoResetShadows]}]}]}}).PluginType="AdvancedGroundPlugin",r);ye([t.onChange(xe.prototype._refresh3),t.uiToggle("Baked Shadows"),t.serialize()],xe.prototype,"bakedShadows"),ye([t.onChange(xe.prototype._refresh3),t.uiToggle("Planar Reflections"),t.serialize()],xe.prototype,"groundReflection"),ye([t.onChange(xe.prototype._refresh3),t.uiToggle("Physical Reflections"),t.serialize()],xe.prototype,"physicalReflections"),ye([t.onChange(xe.prototype._refresh3),t.uiToggle("Auto Shadow Frustum Size"),t.serialize()],xe.prototype,"autoFrustumSize"),ye([t.serialize("shadowBaker")],xe.prototype,"_shadowBaker"),ye([t.bindToValue({key:"groundReflection"})],xe.prototype,"planarReflections");let Pe=xe;var be=Object.defineProperty,we=Object.getOwnPropertyDescriptor,Te=(e,t,i,r)=>{for(var a,n=r>1?void 0:r?we(t,i):t,s=e.length-1;s>=0;s--)(a=e[s])&&(n=(r?a(t,i,n):a(n))||n);return r&&n&&be(t,i,n),n};e.WatchHandsPlugin=class extends t.AViewerPluginSync{constructor(){super(...arguments),this.enabled=!0,this.dependencies=[],this.axis="y",this.invertAxis=!1,this.analog=!0,this.hourOffset=0,this.minuteOffset=0,this.secondOffset=0,this.hour=".*hour.*",this.minute=".*minute.*",this.second=".*second.*",this.regex=!0,this.hands=[],this._lastEnabled=!0,this._preFrame=()=>{if(!this.enabled){if(this._lastEnabled){if(this._lastEnabled=!1,!this.hands.length)return;for(const e of this.hands)e.object.rotation.fromArray(e.object.userData.initRotation),e.object.updateMatrixWorld();this._viewer?.renderManager.resetShadows(),this._viewer?.setDirty()}return}if(this._lastEnabled=!0,!this.hands.length)return;const e=this._viewer?.getPlugin("ProgressivePlugin")?.postFrameConvergedRecordingDelta();if(0===e)return;const t=new Date,i=this.invertAxis?-1:1,r=i*(t.getSeconds()+(this.analog?t.getMilliseconds()/1e3:0)-this.secondOffset)*(2*Math.PI)/60,a=i*(t.getMinutes()-this.minuteOffset)*(2*Math.PI)/60+r/60,n=i*(t.getHours()-this.hourOffset)*(2*Math.PI)/12+a/12;if(this.hands.find(e=>"second"===e.type&&Math.abs(r-e.object.rotation[this.axis])>.001)){for(const e of this.hands)"second"===e.type&&(e.object.rotation[this.axis]=r),"minute"===e.type&&(e.object.rotation[this.axis]=a),"hour"===e.type&&(e.object.rotation[this.axis]=n);this._viewer?.renderManager.resetShadows(),this._viewer?.setDirty()}},this._addSceneObject=async e=>{e.object&&this.refresh()}}onAdded(e){super.onAdded(e),e.scene.addEventListener("addSceneObject",this._addSceneObject),e.addEventListener("preFrame",this._preFrame)}onRemove(e){e.scene.removeEventListener("addSceneObject",this._addSceneObject),e.removeEventListener("preFrame",this._preFrame),super.onRemove(e)}refresh(){this.hands=[],this._viewer?.scene.modelRoot.traverse(e=>{let t=!1;e.traverseAncestors(e=>{t||this.hands.find(t=>t.object===e)&&(t=!0)}),t||(e.name.match(this.regex?new RegExp(this.hour):this.hour)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"hour",object:e})),e.name.match(this.regex?new RegExp(this.minute):this.minute)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"minute",object:e})),e.name.match(this.regex?new RegExp(this.second):this.second)&&(e.userData.initRotation||(e.userData.initRotation=e.rotation.toArray()),this.hands.push({type:"second",object:e})))})}},e.WatchHandsPlugin.PluginType="WatchHandsPlugin",Te([t.uiToggle(),t.serialize()],e.WatchHandsPlugin.prototype,"enabled",2),Te([t.uiDropdown(void 0,["x","y","z"].map(e=>({label:e}))),t.serialize()],e.WatchHandsPlugin.prototype,"axis",2),Te([t.uiToggle(),t.serialize()],e.WatchHandsPlugin.prototype,"invertAxis",2),Te([t.uiToggle(),t.serialize()],e.WatchHandsPlugin.prototype,"analog",2),Te([t.uiSlider(void 0,[0,12],.001),t.serialize()],e.WatchHandsPlugin.prototype,"hourOffset",2),Te([t.uiSlider(void 0,[0,60],.001),t.serialize()],e.WatchHandsPlugin.prototype,"minuteOffset",2),Te([t.uiSlider(void 0,[0,60],.001),t.serialize()],e.WatchHandsPlugin.prototype,"secondOffset",2),Te([t.uiInput(),t.serialize()],e.WatchHandsPlugin.prototype,"hour",2),Te([t.uiInput(),t.serialize()],e.WatchHandsPlugin.prototype,"minute",2),Te([t.uiInput(),t.serialize()],e.WatchHandsPlugin.prototype,"second",2),Te([t.uiToggle(),t.onChange("refresh"),t.serialize()],e.WatchHandsPlugin.prototype,"regex",2),Te([t.uiButton()],e.WatchHandsPlugin.prototype,"refresh",1),e.WatchHandsPlugin=Te([t.uiFolderContainer("Watch Hands Time")],e.WatchHandsPlugin);const De=[u,e.VelocityBufferPlugin,y,e.SSReflectionPlugin,e.SSContactShadowsPlugin,T,e.OutlinePlugin,e.SSGIPlugin,e.AnisotropyPlugin,Pe,e.WatchHandsPlugin];e.AdvancedGroundPlugin=Pe,e.BloomPlugin=y,e.DepthOfFieldPlugin=T,e.SSVelocityMaterial=g,e.TemporalAAPlugin=u,e.TemporalAAPluginPass=d,e.anisotropyGLTFExtension=Z,e.webgiPlugins=De,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
106
106
|
//# sourceMappingURL=index.js.map
|