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) 4.4 kB
import{bR as e,bq as t,V as i,M as s,bs as n,u as o,v as r,R as a,bU as h,aB as l,bH as d,bG as f}from"./index-yNtOWHHe.esm.min.js";import{b as c}from"./objectModelMapping-DJGnHmCN.esm.min.js";import{ArrayItem as u,GLTFLoader as m}from"./glTFLoader-DrZpsmpQ.esm.min.js";import"./bone-WlJTsCYz.esm.min.js";import"./skeleton-DrI_Z0uE.esm.min.js";import"./rawTexture-BOCcQuA1.esm.min.js";import"./assetContainer-Dkk4zkgP.esm.min.js";n.AddNodeConstructor("Light_Type_0",((e,t)=>()=>new _(e,i.Zero(),t)));class _ extends e{get shadowAngle(){return this._shadowAngle}set shadowAngle(e){this._shadowAngle=e,this.forceProjectionMatrixCompute()}get direction(){return this._direction}set direction(e){const t=this.needCube();if(this._direction=e,this.needCube()!==t&&this._shadowGenerators){const e=this._shadowGenerators.values();for(let t=e.next();!0!==t.done;t=e.next()){t.value.recreateShadowMap()}}}constructor(e,t,i){super(e,i),this._shadowAngle=Math.PI/2,this.position=t}getClassName(){return"PointLight"}getTypeID(){return t.LIGHTTYPEID_POINTLIGHT}needCube(){return!this.direction}getShadowDirection(e){if(this.direction)return super.getShadowDirection(e);switch(e){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(e,t,i){const n=this.getScene().activeCamera;if(!n)return;const o=void 0!==this.shadowMinZ?this.shadowMinZ:n.minZ,r=void 0!==this.shadowMaxZ?this.shadowMaxZ:n.maxZ,a=this.getScene().getEngine().useReverseDepthBuffer;s.PerspectiveFovLHToRef(this.shadowAngle,1,a?r:o,a?o:r,e,!0,this._scene.getEngine().isNDCHalfZRange,void 0,a)}_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(e,t){return this.computeTransformedInformation()?this._uniformBuffer.updateFloat4("vLightData",this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,0,t):this._uniformBuffer.updateFloat4("vLightData",this.position.x,this.position.y,this.position.z,0,t),this._uniformBuffer.updateFloat4("vLightFalloff",this.range,this._inverseSquaredRange,0,0,t),this}transferToNodeMaterialEffect(e,t){return this.computeTransformedInformation()?e.setFloat3(t,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z):e.setFloat3(t,this.position.x,this.position.y,this.position.z),this}prepareLightSpecificDefines(e,t){e["POINTLIGHT"+t]=!0}}o([r()],_.prototype,"shadowAngle",null),a("BABYLON.PointLight",_);const g="KHR_lights_punctual";class p{constructor(e){this.name=g,this._loader=e,this.enabled=this._loader.isExtensionUsed(g)}dispose(){this._loader=null,delete this._lights}onLoading(){const e=this._loader.gltf.extensions;if(e&&e[this.name]){const t=e[this.name];this._lights=t.lights,u.Assign(this._lights)}}loadNodeAsync(e,s,n){return m.LoadExtensionAsync(e,s,this.name,(async(o,r)=>(this._loader._allMaterialsDirtyRequired=!0,await this._loader.loadNodeAsync(e,s,(e=>{let s;const a=u.Get(o,this._lights,r.light),d=a.name||e.name;switch(this._loader.babylonScene._blockEntityCollection=!!this._loader._assetContainer,a.type){case"directional":{const e=new h(d,i.Backward(),this._loader.babylonScene);e.position.setAll(0),s=e;break}case"point":s=new _(d,i.Zero(),this._loader.babylonScene);break;case"spot":{const e=new c(d,i.Zero(),i.Backward(),0,1,this._loader.babylonScene);e.angle=2*(a.spot&&a.spot.outerConeAngle||Math.PI/4),e.innerAngle=2*(a.spot&&a.spot.innerConeAngle||0),s=e;break}default:throw this._loader.babylonScene._blockEntityCollection=!1,new Error(`${o}: Invalid light type (${a.type})`)}s._parentContainer=this._loader._assetContainer,this._loader.babylonScene._blockEntityCollection=!1,a._babylonLight=s,s.falloffType=t.FALLOFF_GLTF,s.diffuse=a.color?l.FromArray(a.color):l.White(),s.intensity=null==a.intensity?1:a.intensity,s.range=null==a.range?Number.MAX_VALUE:a.range,s.parent=e,this._loader._babylonLights.push(s),m.AddPointerMetadata(s,o),n(e)})))))}}d(g),f(g,!0,(e=>new p(e)));export{p as KHR_lights}; //# sourceMappingURL=KHR_lights_punctual-D1pwxdLy.esm.min.js.map