in packages/miew/src/ui/ObjectControls.js [244:403]
function ObjectControls(object, objectPivot, camera, domElement, getAltObj) {
EventDispatcher.call(this);
const self = this;
this.object = object;
this.objectPivot = objectPivot;
this.camera = camera;
this.domElement = (typeof domElement !== 'undefined') ? domElement : document;
this.getAltObj = getAltObj;
// API
this.enabled = true;
this.hotkeysEnabled = true;
this.screen = {
left: 0, top: 0, width: 0, height: 0,
};
this.options = {
rotateFactor: Math.PI, // full screen slide (along short side) would roughly mean 180 deg. rotation
axisRotateFactor: 4 * Math.PI, // full screen slide (along short side) would roughly mean 720 deg. rotation
intertia: true,
dynamicDampingFactor: 0.1,
intertiaThreshold: 1e-3,
};
// internals
this._state = STATE.NONE;
this._mousePrevPos = new THREE.Vector2();
this._mouseCurPos = new THREE.Vector2();
this._mainObj = new ObjectHandler([this.object], this.camera, new THREE.Vector3(0, 0, 0), this.options);
this._altObj = new ObjectHandler([this.object], this.camera, new THREE.Vector3(0, 0, 0), this.options);
this._affectedObj = this._mainObj;
this._isAltObjFreeRotationAllowed = true;
this._isTranslationAllowed = true;
this._isKeysTranslatingObj = false;
this._pressedKeys = [];
this._clock = new Timer();
this._clock.start();
this._lastUpdateTime = this._clock.getElapsedTime();
// events
this._listeners = [
{
obj: self.domElement,
type: 'mousedown',
handler(e) {
self.mousedown(e);
},
},
{
obj: self.domElement,
type: 'mouseup',
handler(e) {
self.mouseup(e);
},
},
{
obj: self.domElement,
type: 'mousemove',
handler(e) {
self.mousemove(e);
},
},
{
obj: self.domElement,
type: 'mousewheel',
handler(e) {
self.mousewheel(e);
},
},
{
obj: self.domElement,
type: 'DOMMouseScroll',
handler(e) {
self.mousewheel(e);
},
},
{
obj: self.domElement,
type: 'mouseout',
handler(e) {
self.mouseup(e);
},
},
{
obj: self.domElement,
type: 'touchstart',
handler(e) {
self.touchstartend(e);
},
},
{
obj: self.domElement,
type: 'touchend',
handler(e) {
self.touchstartend(e);
},
},
{
obj: self.domElement,
type: 'touchmove',
handler(e) {
self.touchmove(e);
},
},
{
obj: self.getKeyBindObject(),
type: 'keydown',
handler(e) {
self.keydownup(e);
},
},
{
obj: self.getKeyBindObject(),
type: 'keyup',
handler(e) {
self.keydownup(e);
},
},
{
obj: window,
type: 'resize',
handler() {
self.handleResize();
},
},
{
obj: window,
type: 'blur',
handler() {
self.resetKeys();
},
},
{
obj: self.domElement,
type: 'contextmenu',
handler(e) {
self.contextmenu(e);
},
}];
for (let i = 0; i < this._listeners.length; i++) {
const l = this._listeners[i];
l.obj.addEventListener(l.type, l.handler);
}
this.handleResize();
this.resetKeys();
// force an update at start
this.update();
}