117 lines
2.9 KiB
JavaScript
117 lines
2.9 KiB
JavaScript
/**
|
|
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
|
|
* @param graphics R3.GraphicsRuntime
|
|
* @param apiEditorControls
|
|
* @constructor
|
|
*/
|
|
R3.Controls.D3.Editor = function (
|
|
graphics,
|
|
apiEditorControls
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiEditorControls)) {
|
|
apiEditorControls = {
|
|
controlsType : R3.API.Controls.CONTROLS_TYPE_EDITOR
|
|
};
|
|
}
|
|
|
|
if (R3.Utils.UndefinedOrNull()) {
|
|
apiEditorControls.controlsType = R3.API.Controls.CONTROLS_TYPE_EDITOR;
|
|
}
|
|
|
|
R3.API.Controls.D3.Editor.call(
|
|
this,
|
|
apiEditorControls,
|
|
apiEditorControls.raycaster,
|
|
apiEditorControls.camera
|
|
);
|
|
|
|
if (this.raycaster instanceof R3.D3.API.Raycaster) {
|
|
this.raycaster = new R3.D3.Raycaster(
|
|
this.graphics,
|
|
this.raycaster
|
|
);
|
|
}
|
|
|
|
R3.Controls.call(
|
|
this,
|
|
apiEditorControls
|
|
);
|
|
|
|
};
|
|
|
|
/**
|
|
* Inheritance
|
|
* @type {R3.Controls}
|
|
*/
|
|
R3.Controls.D3.Editor.prototype = Object.create(R3.Controls.D3.prototype);
|
|
R3.Controls.D3.Editor.prototype.constructor = R3.Controls.D3.Editor;
|
|
|
|
/**
|
|
* Create Instance
|
|
*/
|
|
R3.Controls.D3.Editor.prototype.createInstance = function() {
|
|
|
|
if (
|
|
R3.Utils.UndefinedOrNull(this.camera) ||
|
|
R3.Utils.UndefinedOrNull(this.camera.instance)
|
|
) {
|
|
console.warn('no camera at time of editor-controls create instance');
|
|
return;
|
|
}
|
|
|
|
if (
|
|
R3.Utils.UndefinedOrNull(this.canvas) ||
|
|
R3.Utils.UndefinedOrNull(this.canvas.instance)
|
|
) {
|
|
console.warn('no canvas at time of editor-controls create instance');
|
|
return;
|
|
}
|
|
|
|
this.instance = new THREE.EditorControls(
|
|
this.camera.instance,
|
|
this.canvas.instance
|
|
);
|
|
|
|
R3.Controls.prototype.createInstance.call(this);
|
|
};
|
|
|
|
/**
|
|
* Update Instance
|
|
*/
|
|
R3.Controls.D3.Editor.prototype.updateInstance = function(property) {
|
|
|
|
if (
|
|
property === 'canvas' ||
|
|
property === 'camera'
|
|
) {
|
|
if (R3.Utils.UndefinedOrNull(this.instance)) {
|
|
this.createInstance();
|
|
} else {
|
|
this.instance.dispose();
|
|
this.createInstance();
|
|
}
|
|
}
|
|
|
|
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');
|
|
|
|
R3.Controls.prototype.updateInstance.call(this, property);
|
|
};
|
|
|
|
/**
|
|
* Converts a R3.Controls.D3.Editor to a R3.D3.API.Mesh
|
|
* @returns {R3.API.Controls}
|
|
*/
|
|
R3.Controls.D3.Editor.prototype.toApiObject = function() {
|
|
|
|
var apiControls = R3.Controls.prototype.toApiObject.call(this);
|
|
|
|
apiControls.raycaster = R3.Utils.IdOrNull(this.raycaster);
|
|
apiControls.camera = R3.Utils.IdOrNull(this.camera);
|
|
|
|
return apiControls;
|
|
};
|