134 lines
3.2 KiB
JavaScript
134 lines
3.2 KiB
JavaScript
/**
|
|
* 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 camera
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.Controls.Editor = function (
|
|
graphics,
|
|
apiControls,
|
|
raycaster,
|
|
camera
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
|
raycaster = null;
|
|
}
|
|
this.raycaster = raycaster;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
|
camera = null;
|
|
}
|
|
this.camera = camera;
|
|
|
|
if (this.raycaster instanceof GameLib.D3.API.Raycaster) {
|
|
this.raycaster = new GameLib.D3.Raycaster(
|
|
this.graphics,
|
|
this.raycaster
|
|
);
|
|
}
|
|
|
|
if (this.camera instanceof GameLib.D3.API.Camera) {
|
|
this.camera = new GameLib.D3.Camera(
|
|
this.graphics,
|
|
this.camera
|
|
)
|
|
}
|
|
|
|
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.camera || !this.camera.instance) {
|
|
throw new Error('No camera at time of instance');
|
|
}
|
|
|
|
if (!this.domElement || !this.domElement.instance) {
|
|
throw new Error('No dom element at time of instance');
|
|
}
|
|
|
|
var instance = new THREE.EditorControls(
|
|
this.camera.instance,
|
|
this.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.Controls.Editor to a GameLib.D3.API.Mesh
|
|
* @returns {GameLib.D3.API.Controls}
|
|
*/
|
|
GameLib.D3.Controls.Editor.prototype.toApiObject = function() {
|
|
|
|
var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this);
|
|
|
|
apiControls.raycaster = GameLib.Utils.IdOrNull(this.raycaster);
|
|
apiControls.camera = GameLib.Utils.IdOrNull(this.camera);
|
|
|
|
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 apiControls = GameLib.D3.API.Controls.FromObject(objectControls);
|
|
|
|
return new GameLib.D3.Controls.Editor(
|
|
graphics,
|
|
apiControls,
|
|
apiControls.raycaster,
|
|
apiControls.camera
|
|
);
|
|
|
|
}; |