@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.44 kB
JavaScript
import{Vec3 as e}from"../../core/math/vec3.js";import{SKYTYPE_INFINITE as t}from"../constants.js";import{GraphNode as s}from"../graph-node.js";import{SkyMesh as n}from"./sky-mesh.js";class r{constructor(n){this._type=t,this._center=new e(0,1,0),this.skyMesh=null,this.node=new s("SkyMeshNode"),this.device=n.device,this.scene=n,this.center=new e(0,1,0),this.centerArray=new Float32Array(3),this.projectedSkydomeCenterId=this.device.scope.resolve("projectedSkydomeCenter")}applySettings(s){var n,r,i,h;this.type=null!=(n=s.skyType)?n:t,this.node.setLocalPosition(new e(null!=(r=s.skyMeshPosition)?r:[0,0,0])),this.node.setLocalEulerAngles(new e(null!=(i=s.skyMeshRotation)?i:[0,0,0])),this.node.setLocalScale(new e(null!=(h=s.skyMeshScale)?h:[1,1,1])),s.skyCenter&&(this._center=new e(s.skyCenter))}set type(e){this._type!==e&&(this._type=e,this.scene.updateShaders=!0,this.updateSkyMesh())}get type(){return this._type}set center(e){this._center.copy(e)}get center(){return this._center}updateSkyMesh(){const e=this.scene._getSkyboxTex();e&&(this.resetSkyMesh(),this.skyMesh=new n(this.device,this.scene,this.node,e,this.type),this.scene.fire("set:skybox",e))}resetSkyMesh(){var e;null==(e=this.skyMesh)||e.destroy(),this.skyMesh=null}update(){if(this.type!==t){const{center:t,centerArray:s}=this,n=new e;this.node.getWorldTransform().transformPoint(t,n),s[0]=n.x,s[1]=n.y,s[2]=n.z,this.projectedSkydomeCenterId.setValue(s)}}}export{r as Sky};