/** * Renders a scene with a camera * @param graphics GameLib.D3.Graphics * @param apiRenderer GameLib.D3.API.Renderer * @constructor */ GameLib.D3.Renderer = function ( graphics, apiRenderer ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); GameLib.D3.API.Renderer.call( this, apiRenderer.id, apiRenderer.name, apiRenderer.scene, apiRenderer.camera, apiRenderer.autoClear, apiRenderer.localClipping, apiRenderer.width, apiRenderer.height, apiRenderer.parentEntity ); this.instance = this.createInstance(); }; GameLib.D3.Renderer.prototype = Object.create(GameLib.D3.API.Renderer.prototype); GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer; GameLib.D3.Renderer.prototype.createInstance = function(update) { var instance = null; if (update) { instance = this.instance; } else { instance = new THREE.WebGLRenderer(); } instance.localClippingEnabled = this.localClipping; instance.setSize(this.width, this.height); instance.autoClear = this.autoClear; if (this.camera && this.camera.instance) { this.camera.instance.aspect = this.width / this.height; this.camera.instance.updateProjectionMatrix(); } this.instance = instance; return instance; }; GameLib.D3.Renderer.prototype.updateInstance = function() { this.instance = this.createInstance(true); }; GameLib.D3.Renderer.prototype.toApiComponent = function() { var apiRenderer = new GameLib.D3.API.Renderer( this.id, this.name, GameLib.Utils.IdOrNull(this.scene), GameLib.Utils.IdOrNull(this.camera), this.autoClear, this.localClipping, this.width, this.height, GameLib.Utils.IdOrNull(this.parentEntity) ); return apiRenderer; }; GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) { var apiRenderer = GameLib.D3.API.Renderer.FromObjectComponent(objectComponent); return new GameLib.D3.Renderer( graphics, this, apiRenderer ); }; GameLib.D3.Renderer.prototype.render = function() { this.instance.render(this.scene.instance, this.camera.instance); };