@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 2.66 kB
JavaScript
import{sortPriority as e}from"../../../core/sort.js";import{Color as r}from"../../../core/math/color.js";import{Vec4 as t}from"../../../core/math/vec4.js";import{Component as o}from"../component.js";import{ComponentSystem as a}from"../system.js";import{CameraComponent as s}from"./component.js";import{CameraComponentData as c}from"./data.js";const i=["enabled"];class n extends a{constructor(e){super(e),this.cameras=[],this.id="camera",this.ComponentType=s,this.DataType=c,this.schema=i,this.on("beforeremove",this.onBeforeRemove,this),this.app.on("prerender",this.onAppPrerender,this),this.app.systems.on("update",this.onUpdate,this)}initializeComponentData(e,o,a){a=["aspectRatio","aspectRatioMode","calculateProjection","calculateTransform","clearColor","clearColorBuffer","clearDepthBuffer","clearStencilBuffer","renderSceneColorMap","renderSceneDepthMap","cullFaces","farClip","flipFaces","fov","frustumCulling","horizontalFov","layers","renderTarget","nearClip","orthoHeight","projection","priority","rect","scissorRect","aperture","shutter","sensitivity"];for(let s=0;s<a.length;s++){const c=a[s];if(o.hasOwnProperty(c)){const a=o[c];switch(c){case"rect":case"scissorRect":Array.isArray(a)?e[c]=new t(a[0],a[1],a[2],a[3]):e[c]=a;break;case"clearColor":Array.isArray(a)?e[c]=new r(a[0],a[1],a[2],a[3]):e[c]=a;break;default:e[c]=a}}}super.initializeComponentData(e,o,["enabled"])}cloneComponent(e,r){const t=e.camera;return this.addComponent(r,{aspectRatio:t.aspectRatio,aspectRatioMode:t.aspectRatioMode,calculateProjection:t.calculateProjection,calculateTransform:t.calculateTransform,clearColor:t.clearColor,clearColorBuffer:t.clearColorBuffer,clearDepthBuffer:t.clearDepthBuffer,clearStencilBuffer:t.clearStencilBuffer,renderSceneDepthMap:t.renderSceneDepthMap,renderSceneColorMap:t.renderSceneColorMap,cullFaces:t.cullFaces,enabled:t.enabled,farClip:t.farClip,flipFaces:t.flipFaces,fov:t.fov,frustumCulling:t.frustumCulling,horizontalFov:t.horizontalFov,layers:t.layers,renderTarget:t.renderTarget,nearClip:t.nearClip,orthoHeight:t.orthoHeight,projection:t.projection,priority:t.priority,rect:t.rect,scissorRect:t.scissorRect,aperture:t.aperture,sensitivity:t.sensitivity,shutter:t.shutter})}onBeforeRemove(e,r){this.removeCamera(r),r.onRemove()}onUpdate(e){}onAppPrerender(){for(let e=0,r=this.cameras.length;e<r;e++)this.cameras[e].onAppPrerender()}addCamera(r){this.cameras.push(r),e(this.cameras)}removeCamera(r){const t=this.cameras.indexOf(r);t>=0&&(this.cameras.splice(t,1),e(this.cameras))}destroy(){super.destroy(),this.app.systems.off("update",this.onUpdate,this)}}o._buildAccessors(s.prototype,i);export{n as CameraComponentSystem};