diff --git a/build/Three.js b/build/Three.js index 9c049382eb03df31789435a6b3d9abc60a3833b9..f11042e350571246bc994c41f7cd73cbc271974f 100644 --- a/build/Three.js +++ b/build/Three.js @@ -520,14 +520,14 @@ this.object.matrix.n24=this.object.position.y;this.object.matrix.n34=this.object a;this.object.position.y-=this.object.matrix.n23*a;this.object.position.z-=this.object.matrix.n33*a};this.rotateHorizontally=function(a){c.set(this.object.matrix.n11,this.object.matrix.n21,this.object.matrix.n31);c.multiplyScalar(a);this.forward.subSelf(c);this.forward.normalize()};this.rotateVertically=function(a){d.set(this.object.matrix.n12,this.object.matrix.n22,this.object.matrix.n32);d.multiplyScalar(a);this.forward.addSelf(d);this.forward.normalize()};this.domElement.addEventListener("contextmenu", function(a){a.preventDefault()},!1);this.domElement.addEventListener("mousemove",function(a){p=(a.clientX-n)/window.innerWidth;o=(a.clientY-q)/window.innerHeight},!1);this.domElement.addEventListener("mousedown",function(a){a.preventDefault();a.stopPropagation();switch(a.button){case 0:i=1;break;case 2:i=-1}},!1);this.domElement.addEventListener("mouseup",function(a){a.preventDefault();a.stopPropagation();switch(a.button){case 0:i=0;break;case 2:i=0}},!1);this.domElement.addEventListener("keydown", function(a){switch(a.keyCode){case 38:case 87:i=1;break;case 37:case 65:l=-1;break;case 40:case 83:i=-1;break;case 39:case 68:l=1;break;case 81:f=!0;h=1;break;case 69:f=!0;h=-1;break;case 82:k=1;break;case 70:k=-1}},!1);this.domElement.addEventListener("keyup",function(a){switch(a.keyCode){case 38:case 87:i=0;break;case 37:case 65:l=0;break;case 40:case 83:i=0;break;case 39:case 68:l=0;break;case 81:f=!1;break;case 69:f=!1;break;case 82:k=0;break;case 70:k=0}},!1)}; -THREE.TrackballControls=function(a,b){function c(){f.copy(d.object.position).subSelf(d.target);d.noRotate||d.rotateCamera();d.noZoom||d.zoomCamera();d.noPan||d.panCamera();d.object.position.add(d.target,f);d.checkDistances();d.object.lookAt(d.target);d.dispatchEvent({type:"update"})}THREE.EventTarget.call(this);var d=this;this.object=a;this.domElement=void 0!==b?b:document;this.enabled=!0;this.screen={width:window.innerWidth,height:window.innerHeight,offsetLeft:0,offsetTop:0};this.radius=(this.screen.width+ -this.screen.height)/4;this.rotateSpeed=1;this.zoomSpeed=1.2;this.panSpeed=0.3;this.staticMoving=this.noPan=this.noZoom=this.noRotate=!1;this.dynamicDampingFactor=0.2;this.minDistance=0;this.maxDistance=Infinity;this.keys=[65,83,68];this.target=new THREE.Vector3(0,0,0);var e=!1,g=-1,f=new THREE.Vector3,h=new THREE.Vector3,i=new THREE.Vector3,l=new THREE.Vector2,k=new THREE.Vector2,p=new THREE.Vector2,o=new THREE.Vector2;this.handleEvent=function(a){if("function"==typeof this[a.type])this[a.type](a)}; -this.getMouseOnScreen=function(a,b){return new THREE.Vector2(0.5*((a-d.screen.offsetLeft)/d.radius),0.5*((b-d.screen.offsetTop)/d.radius))};this.getMouseProjectionOnBall=function(a,b){var c=new THREE.Vector3((a-0.5*d.screen.width-d.screen.offsetLeft)/d.radius,(0.5*d.screen.height+d.screen.offsetTop-b)/d.radius,0),e=c.length();1d.maxDistance*d.maxDistance&&d.object.position.setLength(d.maxDistance), -f.lengthSq()c.maxDistance*c.maxDistance&&c.object.position.setLength(c.maxDistance),f.lengthSq()n;n++)this.materials.push(f)}n=0;r=1;q=2;s= 3;m=4;t=5}else this.materials=[];this.sides={px:!0,nx:!0,py:!0,ny:!0,pz:!0,nz:!0};if(void 0!=h)for(var w in h)void 0!==this.sides[w]&&(this.sides[w]=h[w]);this.sides.px&&i("z","y",-1,-1,c,b,k,n);this.sides.nx&&i("z","y",1,-1,c,b,-k,r);this.sides.py&&i("x","z",1,1,a,c,p,q);this.sides.ny&&i("x","z",1,-1,a,c,-p,s);this.sides.pz&&i("x","y",1,-1,a,b,o,m);this.sides.nz&&i("x","y",-1,-1,a,b,-o,t);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=new THREE.Geometry; diff --git a/build/custom/ThreeExtras.js b/build/custom/ThreeExtras.js index c22e089559c14e623c3ace18a35cfd7ff2678f98..ccd16540148d29a2b927f4e154ea75c314b32806 100644 --- a/build/custom/ThreeExtras.js +++ b/build/custom/ThreeExtras.js @@ -151,14 +151,14 @@ this.object.matrix.n24=this.object.position.y;this.object.matrix.n34=this.object a;this.object.position.y-=this.object.matrix.n23*a;this.object.position.z-=this.object.matrix.n33*a};this.rotateHorizontally=function(a){c.set(this.object.matrix.n11,this.object.matrix.n21,this.object.matrix.n31);c.multiplyScalar(a);this.forward.subSelf(c);this.forward.normalize()};this.rotateVertically=function(a){d.set(this.object.matrix.n12,this.object.matrix.n22,this.object.matrix.n32);d.multiplyScalar(a);this.forward.addSelf(d);this.forward.normalize()};this.domElement.addEventListener("contextmenu", function(a){a.preventDefault()},!1);this.domElement.addEventListener("mousemove",function(a){q=(a.clientX-n)/window.innerWidth;l=(a.clientY-r)/window.innerHeight},!1);this.domElement.addEventListener("mousedown",function(a){a.preventDefault();a.stopPropagation();switch(a.button){case 0:i=1;break;case 2:i=-1}},!1);this.domElement.addEventListener("mouseup",function(a){a.preventDefault();a.stopPropagation();switch(a.button){case 0:i=0;break;case 2:i=0}},!1);this.domElement.addEventListener("keydown", function(a){switch(a.keyCode){case 38:case 87:i=1;break;case 37:case 65:j=-1;break;case 40:case 83:i=-1;break;case 39:case 68:j=1;break;case 81:e=!0;h=1;break;case 69:e=!0;h=-1;break;case 82:k=1;break;case 70:k=-1}},!1);this.domElement.addEventListener("keyup",function(a){switch(a.keyCode){case 38:case 87:i=0;break;case 37:case 65:j=0;break;case 40:case 83:i=0;break;case 39:case 68:j=0;break;case 81:e=!1;break;case 69:e=!1;break;case 82:k=0;break;case 70:k=0}},!1)}; -THREE.TrackballControls=function(a,b){function c(){e.copy(d.object.position).subSelf(d.target);d.noRotate||d.rotateCamera();d.noZoom||d.zoomCamera();d.noPan||d.panCamera();d.object.position.add(d.target,e);d.checkDistances();d.object.lookAt(d.target);d.dispatchEvent({type:"update"})}THREE.EventTarget.call(this);var d=this;this.object=a;this.domElement=void 0!==b?b:document;this.enabled=!0;this.screen={width:window.innerWidth,height:window.innerHeight,offsetLeft:0,offsetTop:0};this.radius=(this.screen.width+ -this.screen.height)/4;this.rotateSpeed=1;this.zoomSpeed=1.2;this.panSpeed=0.3;this.staticMoving=this.noPan=this.noZoom=this.noRotate=!1;this.dynamicDampingFactor=0.2;this.minDistance=0;this.maxDistance=Infinity;this.keys=[65,83,68];this.target=new THREE.Vector3(0,0,0);var f=!1,g=-1,e=new THREE.Vector3,h=new THREE.Vector3,i=new THREE.Vector3,j=new THREE.Vector2,k=new THREE.Vector2,q=new THREE.Vector2,l=new THREE.Vector2;this.handleEvent=function(a){if("function"==typeof this[a.type])this[a.type](a)}; -this.getMouseOnScreen=function(a,b){return new THREE.Vector2(0.5*((a-d.screen.offsetLeft)/d.radius),0.5*((b-d.screen.offsetTop)/d.radius))};this.getMouseProjectionOnBall=function(a,b){var c=new THREE.Vector3((a-0.5*d.screen.width-d.screen.offsetLeft)/d.radius,(0.5*d.screen.height+d.screen.offsetTop-b)/d.radius,0),f=c.length();1d.maxDistance*d.maxDistance&&d.object.position.setLength(d.maxDistance), -e.lengthSq()c.maxDistance*c.maxDistance&&c.object.position.setLength(c.maxDistance),e.lengthSq()n;n++)this.materials.push(e)}n=0;p=1;r=2;o= 3;m=4;s=5}else this.materials=[];this.sides={px:!0,nx:!0,py:!0,ny:!0,pz:!0,nz:!0};if(void 0!=h)for(var t in h)void 0!==this.sides[t]&&(this.sides[t]=h[t]);this.sides.px&&i("z","y",-1,-1,c,b,k,n);this.sides.nx&&i("z","y",1,-1,c,b,-k,p);this.sides.py&&i("x","z",1,1,a,c,q,r);this.sides.ny&&i("x","z",1,-1,a,c,-q,o);this.sides.pz&&i("x","y",1,-1,a,b,l,m);this.sides.nz&&i("x","y",-1,-1,a,b,-l,s);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=new THREE.Geometry; diff --git a/examples/misc_camera_trackball.html b/examples/misc_camera_trackball.html index a4536c7c0f697972d050219b22fa8853571d3360..3e8afed9502496fef222c28fcfb07f23d5ab425b 100644 --- a/examples/misc_camera_trackball.html +++ b/examples/misc_camera_trackball.html @@ -40,19 +40,20 @@ + - + + diff --git a/examples/webgl_morphtargets_md2.html b/examples/webgl_morphtargets_md2.html index 03939e74078c0608143216305e423d97979eba61..c17989d6ed807b8ad966911aed12512fb0e73545 100644 --- a/examples/webgl_morphtargets_md2.html +++ b/examples/webgl_morphtargets_md2.html @@ -381,9 +381,9 @@ function render() { - var delta = clock.getDelta(); + controls.update(); - character.update( delta ); + character.update( clock.getDelta() ); renderer.render( scene, camera ); diff --git a/examples/webgl_shading_physical.html b/examples/webgl_shading_physical.html index 9af542f5fffc56c41ac16a29cde86d7ec6bcb2a4..3575c34b7bb713d7fd1613104b27bf4ffd5a7362 100644 --- a/examples/webgl_shading_physical.html +++ b/examples/webgl_shading_physical.html @@ -550,6 +550,7 @@ var delta = 1000 * clock.getDelta(); TWEEN.update(); + controls.update(); if ( morph ) morph.updateAnimation( delta ); diff --git a/examples/webgl_terrain_dynamic.html b/examples/webgl_terrain_dynamic.html index 7dba023f70d2c51273bfcd0618e69cedc2a73b95..fa92c4f29d2eda322b59076fc565bbf3e3767837 100644 --- a/examples/webgl_terrain_dynamic.html +++ b/examples/webgl_terrain_dynamic.html @@ -683,6 +683,8 @@ if ( terrain.visible ) { + controls.update(); + var time = Date.now() * 0.001; var fLow = 0.4, fHigh = 0.825; diff --git a/examples/webgl_trackballcamera_earth.html b/examples/webgl_trackballcamera_earth.html index b68654c240997758472e230464261789534aa741..6949bfaedc72404f61df48397196d2691f8bde9e 100644 --- a/examples/webgl_trackballcamera_earth.html +++ b/examples/webgl_trackballcamera_earth.html @@ -287,6 +287,8 @@ ); meshMoon.rotation.y -= angle; + controls.update(); + renderer.clear(); renderer.render( scene, camera ); diff --git a/src/extras/controls/TrackballControls.js b/src/extras/controls/TrackballControls.js index d32c08e6276a61a1bcffbc325eb268401493b795..018aea5762a0c792bc585c2c304fe86d0fdd00d5 100644 --- a/src/extras/controls/TrackballControls.js +++ b/src/extras/controls/TrackballControls.js @@ -37,7 +37,9 @@ THREE.TrackballControls = function ( object, domElement ) { // internals - this.target = new THREE.Vector3( 0, 0, 0 ); + this.target = new THREE.Vector3(); + + var lastPosition = new THREE.Vector3(); var _keyPressed = false, _state = STATE.NONE, @@ -208,6 +210,44 @@ THREE.TrackballControls = function ( object, domElement ) { }; + this.update = function() { + + _eye.copy( _this.object.position ).subSelf( _this.target ); + + if ( !_this.noRotate ) { + + _this.rotateCamera(); + + } + + if ( !_this.noZoom ) { + + _this.zoomCamera(); + + } + + if ( !_this.noPan ) { + + _this.panCamera(); + + } + + _this.object.position.add( _this.target, _eye ); + + _this.checkDistances(); + + _this.object.lookAt( _this.target ); + + if ( lastPosition.distanceTo( _this.object.position ) > 0 ) { + + _this.dispatchEvent( { type: 'change' } ); + + lastPosition.copy( _this.object.position ); + + } + + }; + // listeners function keydown( event ) { @@ -313,8 +353,6 @@ THREE.TrackballControls = function ( object, domElement ) { } - update(); - }; function mouseup( event ) { @@ -328,40 +366,6 @@ THREE.TrackballControls = function ( object, domElement ) { }; - // - - function update() { - - _eye.copy( _this.object.position ).subSelf( _this.target ); - - if ( !_this.noRotate ) { - - _this.rotateCamera(); - - } - - if ( !_this.noZoom ) { - - _this.zoomCamera(); - - } - - if ( !_this.noPan ) { - - _this.panCamera(); - - } - - _this.object.position.add( _this.target, _eye ); - - _this.checkDistances(); - - _this.object.lookAt( _this.target ); - - _this.dispatchEvent( { type: 'update' } ); - - }; - this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false ); this.domElement.addEventListener( 'mousemove', mousemove, false ); @@ -371,7 +375,4 @@ THREE.TrackballControls = function ( object, domElement ) { window.addEventListener( 'keydown', keydown, false ); window.addEventListener( 'keyup', keyup, false ); - // TODO: Clean up the code so this isn't needed. - update(); - };