/** * GameLib.D3.Effect * @param graphics GameLib.GraphicsRuntime * @param apiEffect GameLib.D3.API.Effect * @constructor */ GameLib.D3.Effect = function( graphics, apiEffect ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiEffect)) { apiEffect = {}; } GameLib.D3.API.Effect.call( this, apiEffect.id, apiEffect.name, apiEffect.effectType, apiEffect.parentEntity, apiEffect.renderer, apiEffect.width, apiEffect.height ); var linkedObjects = { renderer : GameLib.D3.Renderer }; GameLib.Component.call( this, linkedObjects ); }; GameLib.D3.Effect.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.Effect.prototype.constructor = GameLib.D3.Effect; GameLib.D3.Effect.prototype.createInstance = function() { if (!this.instance) { console.warn('call this child create instance first'); return; } var width = this.width; var height = this.height; if (this.renderer && this.renderer.instance) { var size = this.renderer.getSize(); width = size.width; height = size.height; } this.setSize( width, height ); GameLib.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ GameLib.D3.Effect.prototype.updateInstance = function(property) { if (GameLib.Utils.UndefinedOrNull(property)) { console.warn('no camera property specified for : ' + this.name); } if (property === 'effectType') { console.warn('todo: update effect type'); return; } if ( property === 'width' || property === 'height' ) { this.setSize( this.width, this.height ) } if (property === 'renderer') { if (property === 'renderer') { if ( GameLib.Utils.Defined(this.renderer) && GameLib.Utils.Defined(this.renderer.instance) ) { if (GameLib.Utils.UndefinedOrNull(this.instance)) { this.createInstance(); } else { this.instance.dispose(); this.createInstance(); } } } return; } GameLib.Component.prototype.updateInstance.call(this, property); }; /** * Convenience function to set effect size * @param width * @param height */ GameLib.D3.Effect.prototype.setSize = function(width, height) { this.instance.setSize( width, height ); }; /** * Convenience function to render a scene / camera with this effect * @param scene * @param camera */ GameLib.D3.Effect.prototype.render = function(scene, camera) { this.instance.render( scene.instance, camera.instance ); }; /** * Converts a GameLib.D3.Effect to a new GameLib.D3.API.Effect * @returns {GameLib.D3.API.Effect} */ GameLib.D3.Effect.prototype.toApiObject = function() { return new GameLib.D3.API.Effect( this.id, this.name, this.effectType, GameLib.Utils.IdOrNull(this.parentEntity), GameLib.Utils.IdOrNull(this.renderer), this.width, this.height ); };