@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
3 lines (2 loc) • 9.96 kB
JavaScript
import{l as e,M as t,V as i,aL as r,m as o,C as s,aM as n,q as a,s as h,J as u}from"./index-BPURObVq.esm.min.js";let c=(()=>{var c;let x,l,p,g,T,_,f,j,d=n,m=[],L=[],P=[],D=[],M=[];return c=class extends d{get iesProfileTexture(){return this._iesProfileTexture}set iesProfileTexture(e){this._iesProfileTexture!==e&&(this._iesProfileTexture=e,this._iesProfileTexture&&c._IsTexture(this._iesProfileTexture)&&this._iesProfileTexture.onLoadObservable.addOnce(()=>{this._markMeshesAsLightDirty()}))}get angle(){return this._angle}set angle(e){this._angle=e,this._cosHalfAngle=Math.cos(.5*e),this._projectionTextureProjectionLightDirty=!0,this.forceProjectionMatrixCompute(),this._computeAngleValues()}get innerAngle(){return this._innerAngle}set innerAngle(e){this._innerAngle=e,this._computeAngleValues()}get shadowAngleScale(){return this._shadowAngleScale}set shadowAngleScale(e){this._shadowAngleScale=e,this.forceProjectionMatrixCompute()}get projectionTextureMatrix(){return this._projectionTextureMatrix}get projectionTextureLightNear(){return this._projectionTextureLightNear}set projectionTextureLightNear(e){this._projectionTextureLightNear=e,this._projectionTextureProjectionLightDirty=!0}get projectionTextureLightFar(){return this._projectionTextureLightFar}set projectionTextureLightFar(e){this._projectionTextureLightFar=e,this._projectionTextureProjectionLightDirty=!0}get projectionTextureUpDirection(){return this._projectionTextureUpDirection}set projectionTextureUpDirection(e){this._projectionTextureUpDirection=e,this._projectionTextureProjectionLightDirty=!0}get projectionTexture(){return this._projectionTexture}set projectionTexture(e){this._projectionTexture!==e&&(this._projectionTexture=e,this._projectionTextureDirty=!0,this._projectionTexture&&!this._projectionTexture.isReady()&&(c._IsProceduralTexture(this._projectionTexture)?this._projectionTexture.getEffect().executeWhenCompiled(()=>{this._markMeshesAsLightDirty()}):c._IsTexture(this._projectionTexture)&&this._projectionTexture.onLoadObservable.addOnce(()=>{this._markMeshesAsLightDirty()})))}static _IsProceduralTexture(e){return void 0!==e.onGeneratedObservable}static _IsTexture(e){return void 0!==e.onLoadObservable}get projectionTextureProjectionLightMatrix(){return this._projectionTextureProjectionLightMatrix}set projectionTextureProjectionLightMatrix(e){this._projectionTextureProjectionLightMatrix=e,this._projectionTextureProjectionLightDirty=!1,this._projectionTextureDirty=!0}constructor(r,o,s,n,a,h,u){super(r,h,u),this._angle=e(this,m),this._innerAngle=0,this._iesProfileTexture=null,this.exponent=e(this,L,void 0),this._projectionTextureMatrix=(e(this,P),t.Zero()),this._projectionTextureLightNear=1e-6,this._projectionTextureLightFar=1e3,this._projectionTextureUpDirection=i.Up(),this._projectionTexture=e(this,D,void 0),this._projectionTextureViewLightDirty=(e(this,M),!0),this._projectionTextureProjectionLightDirty=!0,this._projectionTextureDirty=!0,this._projectionTextureViewTargetVector=i.Zero(),this._projectionTextureViewLightMatrix=t.Zero(),this._projectionTextureProjectionLightMatrix=t.Zero(),this._projectionTextureScalingMatrix=t.FromValues(.5,0,0,0,0,.5,0,0,0,0,.5,0,.5,.5,.5,1),this.position=o,this.direction=s,this.angle=n,this.exponent=a}getClassName(){return"SpotLight"}getTypeID(){return r.LIGHTTYPEID_SPOTLIGHT}_setDirection(e){super._setDirection(e),this._projectionTextureViewLightDirty=!0}_setPosition(e){super._setPosition(e),this._projectionTextureViewLightDirty=!0}_setDefaultShadowProjectionMatrix(e,i,r){const o=this.getScene().activeCamera;if(!o)return;this._shadowAngleScale=this._shadowAngleScale||1;const s=this._shadowAngleScale*this._angle,n=void 0!==this.shadowMinZ?this.shadowMinZ:o.minZ,a=void 0!==this.shadowMaxZ?this.shadowMaxZ:o.maxZ,h=this.getScene().getEngine().useReverseDepthBuffer;t.PerspectiveFovLHToRef(s,1,h?a:n,h?n:a,e,!0,this._scene.getEngine().isNDCHalfZRange,void 0,h)}_computeProjectionTextureViewLightMatrix(){this._projectionTextureViewLightDirty=!1,this._projectionTextureDirty=!0,this.getAbsolutePosition().addToRef(this.getShadowDirection(),this._projectionTextureViewTargetVector),t.LookAtLHToRef(this.getAbsolutePosition(),this._projectionTextureViewTargetVector,this._projectionTextureUpDirection,this._projectionTextureViewLightMatrix)}_computeProjectionTextureProjectionLightMatrix(){this._projectionTextureProjectionLightDirty=!1,this._projectionTextureDirty=!0;const e=this.projectionTextureLightFar,i=this.projectionTextureLightNear,r=e/(e-i),o=-r*i,s=1/Math.tan(this._angle/2);t.FromValuesToRef(s/1,0,0,0,0,s,0,0,0,0,r,1,0,0,o,0,this._projectionTextureProjectionLightMatrix)}_computeProjectionTextureMatrix(){if(this._projectionTextureDirty=!1,this._projectionTextureViewLightMatrix.multiplyToRef(this._projectionTextureProjectionLightMatrix,this._projectionTextureMatrix),this._projectionTexture instanceof o){const e=this._projectionTexture.uScale/2,i=this._projectionTexture.vScale/2;t.FromValuesToRef(e,0,0,0,0,i,0,0,0,0,.5,0,.5,.5,.5,1,this._projectionTextureScalingMatrix)}this._projectionTextureMatrix.multiplyToRef(this._projectionTextureScalingMatrix,this._projectionTextureMatrix)}_buildUniformLayout(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",4),this._uniformBuffer.addUniform("vLightDirection",3),this._uniformBuffer.addUniform("vLightFalloff",4),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()}_computeAngleValues(){this._lightAngleScale=1/Math.max(.001,Math.cos(.5*this._innerAngle)-this._cosHalfAngle),this._lightAngleOffset=-this._cosHalfAngle*this._lightAngleScale}transferTexturesToEffect(e,t){return this.projectionTexture&&this.projectionTexture.isReady()&&(this._projectionTextureViewLightDirty&&this._computeProjectionTextureViewLightMatrix(),this._projectionTextureProjectionLightDirty&&this._computeProjectionTextureProjectionLightMatrix(),this._projectionTextureDirty&&this._computeProjectionTextureMatrix(),e.setMatrix("textureProjectionMatrix"+t,this._projectionTextureMatrix),e.setTexture("projectionLightTexture"+t,this.projectionTexture)),this._iesProfileTexture&&this._iesProfileTexture.isReady()&&e.setTexture("iesLightTexture"+t,this._iesProfileTexture),this}transferToEffect(e,t){let r;const o=this._scene.floatingOriginOffset;return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x-o.x,this.transformedPosition.y-o.y,this.transformedPosition.z-o.z,this.exponent,t),r=i.Normalize(this.transformedDirection)):(this._uniformBuffer.updateFloat4("vLightData",this.position.x-o.x,this.position.y-o.y,this.position.z-o.z,this.exponent,t),r=i.Normalize(this.direction)),this._uniformBuffer.updateFloat4("vLightDirection",r.x,r.y,r.z,this._cosHalfAngle,t),this._uniformBuffer.updateFloat4("vLightFalloff",this.range,this._inverseSquaredRange,this._lightAngleScale,this._lightAngleOffset,t),this}transferToNodeMaterialEffect(e,t){let r;return r=this.computeTransformedInformation()?i.Normalize(this.transformedDirection):i.Normalize(this.direction),this.getScene().useRightHandedSystem?e.setFloat3(t,-r.x,-r.y,-r.z):e.setFloat3(t,r.x,r.y,r.z),this}dispose(){super.dispose(),this._projectionTexture&&this._projectionTexture.dispose(),this._iesProfileTexture&&(this._iesProfileTexture.dispose(),this._iesProfileTexture=null)}getDepthMinZ(e){const t=this._scene.getEngine(),i=void 0!==this.shadowMinZ?this.shadowMinZ:e?.minZ??s.ShadowMinZ;return t.useReverseDepthBuffer&&t.isNDCHalfZRange?i:this._scene.getEngine().isNDCHalfZRange?0:i}getDepthMaxZ(e){const t=this._scene.getEngine(),i=void 0!==this.shadowMaxZ?this.shadowMaxZ:e?.maxZ??s.ShadowMaxZ;return t.useReverseDepthBuffer&&t.isNDCHalfZRange?0:i}areLightTexturesReady(){return!(this._projectionTexture&&!this._projectionTexture.isReadyOrNotBlocking())&&!(this._iesProfileTexture&&!this._iesProfileTexture.isReadyOrNotBlocking())}prepareLightSpecificDefines(e,t){e["SPOTLIGHT"+t]=!0,e["PROJECTEDLIGHTTEXTURE"+t]=!(!this.projectionTexture||!this.projectionTexture.isReady()),e["IESLIGHTTEXTURE"+t]=!(!this._iesProfileTexture||!this._iesProfileTexture.isReady())}},(()=>{const e="function"==typeof Symbol&&Symbol.metadata?Object.create(d[Symbol.metadata]??null):void 0;x=[h()],l=[h()],p=[h()],g=[h()],T=[h()],_=[h()],f=[h()],j=[u("projectedLightTexture")],a(c,null,x,{kind:"getter",name:"angle",static:!1,private:!1,access:{has:e=>"angle"in e,get:e=>e.angle},metadata:e},null,m),a(c,null,l,{kind:"getter",name:"innerAngle",static:!1,private:!1,access:{has:e=>"innerAngle"in e,get:e=>e.innerAngle},metadata:e},null,m),a(c,null,p,{kind:"getter",name:"shadowAngleScale",static:!1,private:!1,access:{has:e=>"shadowAngleScale"in e,get:e=>e.shadowAngleScale},metadata:e},null,m),a(c,null,T,{kind:"getter",name:"projectionTextureLightNear",static:!1,private:!1,access:{has:e=>"projectionTextureLightNear"in e,get:e=>e.projectionTextureLightNear},metadata:e},null,m),a(c,null,_,{kind:"getter",name:"projectionTextureLightFar",static:!1,private:!1,access:{has:e=>"projectionTextureLightFar"in e,get:e=>e.projectionTextureLightFar},metadata:e},null,m),a(c,null,f,{kind:"getter",name:"projectionTextureUpDirection",static:!1,private:!1,access:{has:e=>"projectionTextureUpDirection"in e,get:e=>e.projectionTextureUpDirection},metadata:e},null,m),a(null,null,g,{kind:"field",name:"exponent",static:!1,private:!1,access:{has:e=>"exponent"in e,get:e=>e.exponent,set:(e,t)=>{e.exponent=t}},metadata:e},L,P),a(null,null,j,{kind:"field",name:"_projectionTexture",static:!1,private:!1,access:{has:e=>"_projectionTexture"in e,get:e=>e._projectionTexture,set:(e,t)=>{e._projectionTexture=t}},metadata:e},D,M),e&&Object.defineProperty(c,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:e})})(),c})();export{c as S};
//# sourceMappingURL=spotLight.pure-5s2DDDIt.esm.min.js.map