/** * GameLib.D3.Shadow * @param graphics GameLib.GraphicsRuntime * @param apiShadow GameLib.D3.API.Shadow * @constructor */ GameLib.D3.Shadow = function( graphics, apiShadow ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiShadow)) { apiShadow = { shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL }; } GameLib.D3.API.Shadow.call( this, apiShadow.id, apiShadow.name, apiShadow.shadowType, apiShadow.camera, apiShadow.bias, apiShadow.mapSize, apiShadow.radius, apiShadow.parentEntity ); if (this.camera instanceof GameLib.D3.API.Camera.Perspective) { this.camera = new GameLib.D3.Camera.Perspective( this.graphics, this.camera ) } GameLib.Component.call(this); }; GameLib.D3.Shadow.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.Shadow.prototype.constructor = GameLib.D3.Shadow; /** * Creates a light instance * @returns {*} */ GameLib.D3.Shadow.prototype.createInstance = function() { /** * Shadow objects are not responsible for creating their instances right now - * They are implicitly created through threejs light instances. This means, * they only update their instances. * @type {Object} */ this.instance = {}; GameLib.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ GameLib.D3.Shadow.prototype.updateInstance = function(property) { if (typeof this.instance !== 'object') { console.warn('this shadow instance is not ready for an update: ' + this.name); return; } if (GameLib.Utils.UndefinedOrNull(property)) { console.warn('no property for light: ' + this.name); } if (property === 'shadowType') { console.warn('changing shadowType has no effect'); } if (property === 'camera') { this.instance.camera = this.camera.instance; } if (property === 'bias') { this.instance.bias = this.bias; } if (property === 'mapSize') { this.instance.mapSize.x = this.mapSize.x; this.instance.mapSize.y = this.mapSize.y; } if (property === 'radius') { this.instance.radius = this.radius; } if (property === 'parentEntity') { console.warn('todo: implement parentEntity change for light') } }; /** * Converts a GameLib.D3.Shadow to a GameLib.D3.API.Shadow * @returns {GameLib.D3.API.Shadow} */ GameLib.D3.Shadow.prototype.toApiObject = function() { return new GameLib.D3.API.Shadow( this.id, this.name, this.shadowType, GameLib.Utils.IdOrNull(this.camera), this.bias, this.mapSize.toApiObject(), this.radius, GameLib.Utils.IdOrNull(this.parentEntity) ); }; GameLib.D3.Shadow.prototype.updateFromInstance = function() { this.bias = this.instance.bias; this.mapSize = this.instance.mapSize; this.radius = this.instance.radius; this.camera.instance = this.instance.camera; this.camera.updateFromInstance(); };