@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.66 kB
JavaScript
import{extends as e}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{Color as o}from"../../../core/math/color.js";import{Vec2 as t}from"../../../core/math/vec2.js";import{LIGHTSHAPE_PUNCTUAL as r}from"../../../scene/constants.js";import{Light as n,lightTypes as s}from"../../../scene/light.js";import{ComponentSystem as a}from"../system.js";import{LightComponent as i}from"./component.js";import{LightComponentData as c,properties as l}from"./data.js";class p extends a{constructor(e){super(e),this.id="light",this.ComponentType=i,this.DataType=c,this.on("beforeremove",this._onRemoveComponent,this)}initializeComponentData(a,i){const c=e({},i);c.type||(c.type=a.data.type),a.data.type=c.type,c.layers&&Array.isArray(c.layers)&&(c.layers=c.layers.slice(0)),c.color&&Array.isArray(c.color)&&(c.color=new o(c.color[0],c.color[1],c.color[2])),c.cookieOffset&&c.cookieOffset instanceof Array&&(c.cookieOffset=new t(c.cookieOffset[0],c.cookieOffset[1])),c.cookieScale&&c.cookieScale instanceof Array&&(c.cookieScale=new t(c.cookieScale[0],c.cookieScale[1])),c.enable&&(console.warn("WARNING: enable: Property is deprecated. Set enabled property instead."),c.enabled=c.enable),c.shape||(c.shape=r);const p=new n(this.app.graphicsDevice,this.app.scene.clusteredLightingEnabled);p.type=s[c.type],p._node=a.entity,a.data.light=p,super.initializeComponentData(a,c,l)}_onRemoveComponent(e,o){o.onRemove()}cloneComponent(e,o){const t=e.light,r=[];let n;for(let e=0;e<l.length;e++)n=l[e],"light"!==n&&(t[n]&&t[n].clone?r[n]=t[n].clone():r[n]=t[n]);return this.addComponent(o,r)}changeType(e,o,t){o!==t&&(e.light.type=s[t])}}export{p as LightComponentSystem};