Skip to content

Commit c490eb8

Browse files
Merge pull request #3 from zlot/master
Update to r73 w/ extras also updated
2 parents a5b3245 + 5426c2b commit c490eb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+16582
-14811
lines changed

Diff for: extras/controls/OrbitControls.js

100755100644
+653-247
Large diffs are not rendered by default.

Diff for: extras/controls/TrackballControls.js

100755100644
+66-37
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
THREE.TrackballControls = function ( object, domElement ) {
99

1010
var _this = this;
11-
var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
11+
var STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
1212

1313
this.object = object;
1414
this.domElement = ( domElement !== undefined ) ? domElement : document;
@@ -115,7 +115,7 @@ THREE.TrackballControls = function ( object, domElement ) {
115115

116116
var vector = new THREE.Vector2();
117117

118-
return function ( pageX, pageY ) {
118+
return function getMouseOnScreen( pageX, pageY ) {
119119

120120
vector.set(
121121
( pageX - _this.screen.left ) / _this.screen.width,
@@ -132,19 +132,20 @@ THREE.TrackballControls = function ( object, domElement ) {
132132

133133
var vector = new THREE.Vector2();
134134

135-
return function ( pageX, pageY ) {
135+
return function getMouseOnCircle( pageX, pageY ) {
136136

137137
vector.set(
138138
( ( pageX - _this.screen.width * 0.5 - _this.screen.left ) / ( _this.screen.width * 0.5 ) ),
139139
( ( _this.screen.height + 2 * ( _this.screen.top - pageY ) ) / _this.screen.width ) // screen.width intentional
140140
);
141141

142142
return vector;
143+
143144
};
144145

145146
}() );
146147

147-
this.rotateCamera = (function() {
148+
this.rotateCamera = ( function() {
148149

149150
var axis = new THREE.Vector3(),
150151
quaternion = new THREE.Quaternion(),
@@ -154,7 +155,7 @@ THREE.TrackballControls = function ( object, domElement ) {
154155
moveDirection = new THREE.Vector3(),
155156
angle;
156157

157-
return function () {
158+
return function rotateCamera() {
158159

159160
moveDirection.set( _moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0 );
160161
angle = moveDirection.length();
@@ -183,9 +184,7 @@ THREE.TrackballControls = function ( object, domElement ) {
183184
_lastAxis.copy( axis );
184185
_lastAngle = angle;
185186

186-
}
187-
188-
else if ( !_this.staticMoving && _lastAngle ) {
187+
} else if ( ! _this.staticMoving && _lastAngle ) {
189188

190189
_lastAngle *= Math.sqrt( 1.0 - _this.dynamicDampingFactor );
191190
_eye.copy( _this.object.position ).sub( _this.target );
@@ -199,7 +198,7 @@ THREE.TrackballControls = function ( object, domElement ) {
199198

200199
};
201200

202-
}());
201+
}() );
203202

204203

205204
this.zoomCamera = function () {
@@ -236,13 +235,13 @@ THREE.TrackballControls = function ( object, domElement ) {
236235

237236
};
238237

239-
this.panCamera = (function() {
238+
this.panCamera = ( function() {
240239

241240
var mouseChange = new THREE.Vector2(),
242241
objectUp = new THREE.Vector3(),
243242
pan = new THREE.Vector3();
244243

245-
return function () {
244+
return function panCamera() {
246245

247246
mouseChange.copy( _panEnd ).sub( _panStart );
248247

@@ -267,23 +266,26 @@ THREE.TrackballControls = function ( object, domElement ) {
267266
}
268267

269268
}
269+
270270
};
271271

272-
}());
272+
}() );
273273

274274
this.checkDistances = function () {
275275

276-
if ( !_this.noZoom || !_this.noPan ) {
276+
if ( ! _this.noZoom || ! _this.noPan ) {
277277

278278
if ( _eye.lengthSq() > _this.maxDistance * _this.maxDistance ) {
279279

280280
_this.object.position.addVectors( _this.target, _eye.setLength( _this.maxDistance ) );
281+
_zoomStart.copy( _zoomEnd );
281282

282283
}
283284

284285
if ( _eye.lengthSq() < _this.minDistance * _this.minDistance ) {
285286

286287
_this.object.position.addVectors( _this.target, _eye.setLength( _this.minDistance ) );
288+
_zoomStart.copy( _zoomEnd );
287289

288290
}
289291

@@ -295,19 +297,19 @@ THREE.TrackballControls = function ( object, domElement ) {
295297

296298
_eye.subVectors( _this.object.position, _this.target );
297299

298-
if ( !_this.noRotate ) {
300+
if ( ! _this.noRotate ) {
299301

300302
_this.rotateCamera();
301303

302304
}
303305

304-
if ( !_this.noZoom ) {
306+
if ( ! _this.noZoom ) {
305307

306308
_this.zoomCamera();
307309

308310
}
309311

310-
if ( !_this.noPan ) {
312+
if ( ! _this.noPan ) {
311313

312314
_this.panCamera();
313315

@@ -362,15 +364,15 @@ THREE.TrackballControls = function ( object, domElement ) {
362364

363365
return;
364366

365-
} else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && !_this.noRotate ) {
367+
} else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && ! _this.noRotate ) {
366368

367369
_state = STATE.ROTATE;
368370

369-
} else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && !_this.noZoom ) {
371+
} else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && ! _this.noZoom ) {
370372

371373
_state = STATE.ZOOM;
372374

373-
} else if ( event.keyCode === _this.keys[ STATE.PAN ] && !_this.noPan ) {
375+
} else if ( event.keyCode === _this.keys[ STATE.PAN ] && ! _this.noPan ) {
374376

375377
_state = STATE.PAN;
376378

@@ -401,20 +403,20 @@ THREE.TrackballControls = function ( object, domElement ) {
401403

402404
}
403405

404-
if ( _state === STATE.ROTATE && !_this.noRotate ) {
406+
if ( _state === STATE.ROTATE && ! _this.noRotate ) {
405407

406408
_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
407-
_movePrev.copy(_moveCurr);
409+
_movePrev.copy( _moveCurr );
408410

409-
} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
411+
} else if ( _state === STATE.ZOOM && ! _this.noZoom ) {
410412

411413
_zoomStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
412-
_zoomEnd.copy(_zoomStart);
414+
_zoomEnd.copy( _zoomStart );
413415

414-
} else if ( _state === STATE.PAN && !_this.noPan ) {
416+
} else if ( _state === STATE.PAN && ! _this.noPan ) {
415417

416418
_panStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
417-
_panEnd.copy(_panStart);
419+
_panEnd.copy( _panStart );
418420

419421
}
420422

@@ -432,16 +434,16 @@ THREE.TrackballControls = function ( object, domElement ) {
432434
event.preventDefault();
433435
event.stopPropagation();
434436

435-
if ( _state === STATE.ROTATE && !_this.noRotate ) {
437+
if ( _state === STATE.ROTATE && ! _this.noRotate ) {
436438

437-
_movePrev.copy(_moveCurr);
439+
_movePrev.copy( _moveCurr );
438440
_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
439441

440-
} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
442+
} else if ( _state === STATE.ZOOM && ! _this.noZoom ) {
441443

442444
_zoomEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
443445

444-
} else if ( _state === STATE.PAN && !_this.noPan ) {
446+
} else if ( _state === STATE.PAN && ! _this.noPan ) {
445447

446448
_panEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
447449

@@ -473,11 +475,15 @@ THREE.TrackballControls = function ( object, domElement ) {
473475

474476
var delta = 0;
475477

476-
if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
478+
if ( event.wheelDelta ) {
479+
480+
// WebKit / Opera / Explorer 9
477481

478482
delta = event.wheelDelta / 40;
479483

480-
} else if ( event.detail ) { // Firefox
484+
} else if ( event.detail ) {
485+
486+
// Firefox
481487

482488
delta = - event.detail / 3;
483489

@@ -498,7 +504,7 @@ THREE.TrackballControls = function ( object, domElement ) {
498504
case 1:
499505
_state = STATE.TOUCH_ROTATE;
500506
_moveCurr.copy( getMouseOnCircle( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
501-
_movePrev.copy(_moveCurr);
507+
_movePrev.copy( _moveCurr );
502508
break;
503509

504510
case 2:
@@ -532,7 +538,7 @@ THREE.TrackballControls = function ( object, domElement ) {
532538
switch ( event.touches.length ) {
533539

534540
case 1:
535-
_movePrev.copy(_moveCurr);
541+
_movePrev.copy( _moveCurr );
536542
_moveCurr.copy( getMouseOnCircle( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
537543
break;
538544

@@ -560,7 +566,7 @@ THREE.TrackballControls = function ( object, domElement ) {
560566
switch ( event.touches.length ) {
561567

562568
case 1:
563-
_movePrev.copy(_moveCurr);
569+
_movePrev.copy( _moveCurr );
564570
_moveCurr.copy( getMouseOnCircle( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
565571
break;
566572

@@ -580,12 +586,35 @@ THREE.TrackballControls = function ( object, domElement ) {
580586

581587
}
582588

583-
this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
589+
function contextmenu( event ) {
584590

585-
this.domElement.addEventListener( 'mousedown', mousedown, false );
591+
event.preventDefault();
592+
593+
}
594+
595+
this.dispose = function() {
596+
597+
this.domElement.removeEventListener( 'contextmenu', contextmenu, false );
598+
this.domElement.removeEventListener( 'mousedown', mousedown, false );
599+
this.domElement.removeEventListener( 'mousewheel', mousewheel, false );
600+
this.domElement.removeEventListener( 'MozMousePixelScroll', mousewheel, false ); // firefox
601+
602+
this.domElement.removeEventListener( 'touchstart', touchstart, false );
603+
this.domElement.removeEventListener( 'touchend', touchend, false );
604+
this.domElement.removeEventListener( 'touchmove', touchmove, false );
586605

606+
document.removeEventListener( 'mousemove', mousemove, false );
607+
document.removeEventListener( 'mouseup', mouseup, false );
608+
609+
window.removeEventListener( 'keydown', keydown, false );
610+
window.removeEventListener( 'keyup', keyup, false );
611+
612+
}
613+
614+
this.domElement.addEventListener( 'contextmenu', contextmenu, false );
615+
this.domElement.addEventListener( 'mousedown', mousedown, false );
587616
this.domElement.addEventListener( 'mousewheel', mousewheel, false );
588-
this.domElement.addEventListener( 'DOMMouseScroll', mousewheel, false ); // firefox
617+
this.domElement.addEventListener( 'MozMousePixelScroll', mousewheel, false ); // firefox
589618

590619
this.domElement.addEventListener( 'touchstart', touchstart, false );
591620
this.domElement.addEventListener( 'touchend', touchend, false );

0 commit comments

Comments
 (0)