/** * Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created * @param graphics GameLib.D3.Graphics * @param apiControls GameLib.D3.API.Controls * @param raycaster * @param renderer * @constructor */ GameLib.D3.Controls.Editor = function ( graphics, apiControls, raycaster, renderer ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(raycaster)) { raycaster = null; } this.raycaster = raycaster; if (GameLib.Utils.UndefinedOrNull(renderer)) { renderer = null; } this.renderer = renderer; if (this.raycaster instanceof GameLib.D3.API.Raycaster) { this.raycaster = new GameLib.D3.Raycaster( this.graphics, this.raycaster ); } if (this.renderer instanceof GameLib.D3.API.Renderer) { this.renderer = new GameLib.D3.Renderer( this.graphics, this.renderer ) } GameLib.D3.Controls.call( this, this.graphics, apiControls ); }; /** * Inheritance * @type {GameLib.D3.Controls} */ GameLib.D3.Controls.Editor.prototype = Object.create(GameLib.D3.Controls.prototype); GameLib.D3.Controls.Editor.prototype.constructor = GameLib.D3.Controls.Editor; /** * Create Instance * @returns {THREE.EditorControls} */ GameLib.D3.Controls.Editor.prototype.createInstance = function() { console.log('delaying controls instance creation - call GameLib.D3.Controls.Editor.delayInstance() to create the instance'); }; GameLib.D3.Controls.Editor.prototype.delayedInstance = function() { console.log('GameLib.D3.Controls.Editor.delayedInstance() called'); if (!this.renderer) { throw new Error('No renderer at time of creating instance'); } if (!this.renderer.camera) { throw new Error('No camera at time of instance'); } if (!this.renderer.domElement) { throw new Error('No dom element at time of instance'); } if (!this.renderer.camera.instance) { throw new Error('No camera instance at time of instance'); } if (!this.renderer.domElement.instance) { throw new Error('No dom element instance at time of instance'); } var instance = new THREE.EditorControls( this.renderer.camera.instance, this.renderer.domElement.instance ); return instance; }; /** * Update Instance */ GameLib.D3.Controls.Editor.prototype.updateInstance = function() { console.warn('an update instance was called on editor controls - which, if not called from within a running system at the right time will affect the order of input event handling and cause system instability'); if (this.instance) { this.instance.dispose(); delete this.instance; } this.instance = this.delayedInstance(); GameLib.D3.Controls.prototype.updateInstance.call(this); }; /** * Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh * @returns {GameLib.D3.API.Mesh} */ GameLib.D3.Controls.Editor.prototype.toApiObject = function() { var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this); apiControls.raycaster = GameLib.Utils.IdOrNull(this.raycaster); apiControls.renderer = GameLib.Utils.IdOrNull(this.renderer); return apiControls; }; /** * Construct an Editor Controls object from data * @param graphics * @param objectControls * @returns {GameLib.D3.Controls.Editor} * @constructor */ GameLib.D3.Controls.Editor.FromObject = function(graphics, objectControls) { var apiMesh = GameLib.D3.API.Controls.FromObject(objectControls); apiMesh.renderer = objectControls.renderer; apiMesh.raycaster = objectControls.raycaster; return new GameLib.D3.Controls.Editor( graphics, apiMesh ); };