UNPKG

@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) 8.85 kB
import{bV as t,a8 as o,M as e,V as i,C as s,bu as r,u as h,v as n,R as a,bS as d,aH as u,bJ as f,bI as l}from"./index-Bw2N6w1y.esm.min.js";import{ArrayItem as c,GLTFLoader as m}from"./glTFLoader-DEYqxGxH.esm.min.js";import"./bone-BwMp7T0B.esm.min.js";import"./skeleton-CkTZwWbM.esm.min.js";import"./rawTexture-CPAqHIA7.esm.min.js";import"./assetContainer-21j7tcC8.esm.min.js";import"./objectModelMapping-DX92iJ8M.esm.min.js";r.AddNodeConstructor("Light_Type_1",((t,o)=>()=>new _(t,i.Zero(),o)));class _ extends t{get shadowFrustumSize(){return this._shadowFrustumSize}set shadowFrustumSize(t){this._shadowFrustumSize=t,this.forceProjectionMatrixCompute()}get shadowOrthoScale(){return this._shadowOrthoScale}set shadowOrthoScale(t){this._shadowOrthoScale=t,this.forceProjectionMatrixCompute()}get orthoLeft(){return this._orthoLeft}set orthoLeft(t){this._orthoLeft=t}get orthoRight(){return this._orthoRight}set orthoRight(t){this._orthoRight=t}get orthoTop(){return this._orthoTop}set orthoTop(t){this._orthoTop=t}get orthoBottom(){return this._orthoBottom}set orthoBottom(t){this._orthoBottom=t}constructor(t,o,e){super(t,e),this._shadowFrustumSize=0,this._shadowOrthoScale=.1,this.autoUpdateExtends=!0,this.autoCalcShadowZBounds=!1,this._orthoLeft=Number.MAX_VALUE,this._orthoRight=Number.MIN_VALUE,this._orthoTop=Number.MIN_VALUE,this._orthoBottom=Number.MAX_VALUE,this.position=o.scale(-1),this.direction=o}getClassName(){return"DirectionalLight"}getTypeID(){return o.LIGHTTYPEID_DIRECTIONALLIGHT}_setDefaultShadowProjectionMatrix(t,o,e){this.shadowFrustumSize>0?this._setDefaultFixedFrustumShadowProjectionMatrix(t):this._setDefaultAutoExtendShadowProjectionMatrix(t,o,e)}_setDefaultFixedFrustumShadowProjectionMatrix(t){const o=this.getScene().activeCamera;o&&e.OrthoLHToRef(this.shadowFrustumSize,this.shadowFrustumSize,void 0!==this.shadowMinZ?this.shadowMinZ:o.minZ,void 0!==this.shadowMaxZ?this.shadowMaxZ:o.maxZ,t,this.getScene().getEngine().isNDCHalfZRange)}_setDefaultAutoExtendShadowProjectionMatrix(t,o,r){const h=this.getScene().activeCamera;if(this.autoUpdateExtends||this._orthoLeft===Number.MAX_VALUE){const t=i.Zero();this._orthoLeft=Number.MAX_VALUE,this._orthoRight=-Number.MAX_VALUE,this._orthoTop=-Number.MAX_VALUE,this._orthoBottom=Number.MAX_VALUE;let e=Number.MAX_VALUE,s=-Number.MAX_VALUE;for(let h=0;h<r.length;h++){const n=r[h];if(!n)continue;const a=n.getBoundingInfo().boundingBox;for(let r=0;r<a.vectorsWorld.length;r++)i.TransformCoordinatesToRef(a.vectorsWorld[r],o,t),t.x<this._orthoLeft&&(this._orthoLeft=t.x),t.y<this._orthoBottom&&(this._orthoBottom=t.y),t.x>this._orthoRight&&(this._orthoRight=t.x),t.y>this._orthoTop&&(this._orthoTop=t.y),this.autoCalcShadowZBounds&&(t.z<e&&(e=t.z),t.z>s&&(s=t.z))}this.autoCalcShadowZBounds&&(this._shadowMinZ=e,this._shadowMaxZ=s)}const n=this._orthoRight-this._orthoLeft,a=this._orthoTop-this._orthoBottom,d=void 0!==this.shadowMinZ?this.shadowMinZ:h?.minZ||s.ShadowMinZ,u=void 0!==this.shadowMaxZ?this.shadowMaxZ:h?.maxZ||s.ShadowMaxZ,f=this.getScene().getEngine().useReverseDepthBuffer;e.OrthoOffCenterLHToRef(this._orthoLeft-n*this.shadowOrthoScale,this._orthoRight+n*this.shadowOrthoScale,this._orthoBottom-a*this.shadowOrthoScale,this._orthoTop+a*this.shadowOrthoScale,f?u:d,f?d:u,t,this.getScene().getEngine().isNDCHalfZRange)}_buildUniformLayout(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",4),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()}transferToEffect(t,o){return this.computeTransformedInformation()?(this._uniformBuffer.updateFloat4("vLightData",this.transformedDirection.x,this.transformedDirection.y,this.transformedDirection.z,1,o),this):(this._uniformBuffer.updateFloat4("vLightData",this.direction.x,this.direction.y,this.direction.z,1,o),this)}transferToNodeMaterialEffect(t,o){return this.computeTransformedInformation()?(t.setFloat3(o,this.transformedDirection.x,this.transformedDirection.y,this.transformedDirection.z),this):(t.setFloat3(o,this.direction.x,this.direction.y,this.direction.z),this)}getDepthMinZ(t){const o=this._scene.getEngine();return!o.useReverseDepthBuffer&&o.isNDCHalfZRange?0:1}getDepthMaxZ(t){const o=this._scene.getEngine();return o.useReverseDepthBuffer&&o.isNDCHalfZRange?0:1}prepareLightSpecificDefines(t,o){t["DIRLIGHT"+o]=!0}}h([n()],_.prototype,"shadowFrustumSize",null),h([n()],_.prototype,"shadowOrthoScale",null),h([n()],_.prototype,"autoUpdateExtends",void 0),h([n()],_.prototype,"autoCalcShadowZBounds",void 0),h([n("orthoLeft")],_.prototype,"_orthoLeft",void 0),h([n("orthoRight")],_.prototype,"_orthoRight",void 0),h([n("orthoTop")],_.prototype,"_orthoTop",void 0),h([n("orthoBottom")],_.prototype,"_orthoBottom",void 0),a("BABYLON.DirectionalLight",_),r.AddNodeConstructor("Light_Type_0",((t,o)=>()=>new g(t,i.Zero(),o)));class g extends t{get shadowAngle(){return this._shadowAngle}set shadowAngle(t){this._shadowAngle=t,this.forceProjectionMatrixCompute()}get direction(){return this._direction}set direction(t){const o=this.needCube();if(this._direction=t,this.needCube()!==o&&this._shadowGenerators){const t=this._shadowGenerators.values();for(let o=t.next();!0!==o.done;o=t.next()){o.value.recreateShadowMap()}}}constructor(t,o,e){super(t,e),this._shadowAngle=Math.PI/2,this.position=o}getClassName(){return"PointLight"}getTypeID(){return o.LIGHTTYPEID_POINTLIGHT}needCube(){return!this.direction}getShadowDirection(t){if(this.direction)return super.getShadowDirection(t);switch(t){case 0:return new i(1,0,0);case 1:return new i(-1,0,0);case 2:return new i(0,-1,0);case 3:return new i(0,1,0);case 4:return new i(0,0,1);case 5:return new i(0,0,-1)}return i.Zero()}_setDefaultShadowProjectionMatrix(t,o,i){const s=this.getScene().activeCamera;if(!s)return;const r=void 0!==this.shadowMinZ?this.shadowMinZ:s.minZ,h=void 0!==this.shadowMaxZ?this.shadowMaxZ:s.maxZ,n=this.getScene().getEngine().useReverseDepthBuffer;e.PerspectiveFovLHToRef(this.shadowAngle,1,n?h:r,n?r:h,t,!0,this._scene.getEngine().isNDCHalfZRange,void 0,n)}_buildUniformLayout(){this._uniformBuffer.addUniform("vLightData",4),this._uniformBuffer.addUniform("vLightDiffuse",4),this._uniformBuffer.addUniform("vLightSpecular",4),this._uniformBuffer.addUniform("vLightFalloff",4),this._uniformBuffer.addUniform("shadowsInfo",3),this._uniformBuffer.addUniform("depthValues",2),this._uniformBuffer.create()}transferToEffect(t,o){return this.computeTransformedInformation()?this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,0,o):this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,0,o),this._uniformBuffer.updateFloat4("vLightFalloff",this.range,this._inverseSquaredRange,0,0,o),this}transferToNodeMaterialEffect(t,o){return this.computeTransformedInformation()?t.setFloat3(o,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z):t.setFloat3(o,this.position.x,this.position.y,this.position.z),this}prepareLightSpecificDefines(t,o){t["POINTLIGHT"+o]=!0}}h([n()],g.prototype,"shadowAngle",null),a("BABYLON.PointLight",g);const p="KHR_lights_punctual";class w{constructor(t){this.name=p,this._loader=t,this.enabled=this._loader.isExtensionUsed(p)}dispose(){this._loader=null,delete this._lights}onLoading(){const t=this._loader.gltf.extensions;if(t&&t[this.name]){const o=t[this.name];this._lights=o.lights,c.Assign(this._lights)}}loadNodeAsync(t,e,s){return m.LoadExtensionAsync(t,e,this.name,(async(r,h)=>(this._loader._allMaterialsDirtyRequired=!0,await this._loader.loadNodeAsync(t,e,(t=>{let e;const n=c.Get(r,this._lights,h.light),a=n.name||t.name;switch(this._loader.babylonScene._blockEntityCollection=!!this._loader._assetContainer,n.type){case"directional":{const t=new _(a,i.Backward(),this._loader.babylonScene);t.position.setAll(0),e=t;break}case"point":e=new g(a,i.Zero(),this._loader.babylonScene);break;case"spot":{const t=new d(a,i.Zero(),i.Backward(),0,1,this._loader.babylonScene);t.angle=2*(n.spot&&n.spot.outerConeAngle||Math.PI/4),t.innerAngle=2*(n.spot&&n.spot.innerConeAngle||0),e=t;break}default:throw this._loader.babylonScene._blockEntityCollection=!1,new Error(`${r}: Invalid light type (${n.type})`)}e._parentContainer=this._loader._assetContainer,this._loader.babylonScene._blockEntityCollection=!1,n._babylonLight=e,e.falloffType=o.FALLOFF_GLTF,e.diffuse=n.color?u.FromArray(n.color):u.White(),e.intensity=null==n.intensity?1:n.intensity,e.range=null==n.range?Number.MAX_VALUE:n.range,e.parent=t,this._loader._babylonLights.push(e),m.AddPointerMetadata(e,r),s(t)})))))}}f(p),l(p,!0,(t=>new w(t)));export{w as KHR_lights}; //# sourceMappingURL=KHR_lights_punctual-8009Yu9B.esm.min.js.map