From e8eee563e13068f5e2a9e3f28ff0eb819e4246e2 Mon Sep 17 00:00:00 2001 From: mschuetz Date: Wed, 7 Oct 2015 20:19:34 +0200 Subject: [PATCH] add zoom to double clicked position on orbit controls --- examples/js/viewer.js | 114 ++++++++++++++++++++++------------------ libs/tween/LICENSE.txt | 21 ++++++++ libs/tween/README.txt | 9 ++++ libs/tween/tween.min.js | 2 + 4 files changed, 96 insertions(+), 50 deletions(-) create mode 100644 libs/tween/LICENSE.txt create mode 100644 libs/tween/README.txt create mode 100644 libs/tween/tween.min.js diff --git a/examples/js/viewer.js b/examples/js/viewer.js index c0d1e274..9deb2ad2 100644 --- a/examples/js/viewer.js +++ b/examples/js/viewer.js @@ -564,7 +564,7 @@ var intensityMax = null; var heightMin = null; var heightMax = null; -function update(){ +function update(delta, timestamp){ Potree.pointLoadLimit = pointCountTarget * 2 * 1000 * 1000; directionalLight.position.copy(camera.position); @@ -635,7 +635,7 @@ function update(){ camera.fov = fov; if(controls){ - controls.update(clock.getDelta()); + controls.update(delta); } // update progress bar @@ -692,21 +692,8 @@ function update(){ pointcloud.material.setClipBoxes(clipBoxes); } - //if(pointcloud){ - // - // var levels = new Uint32Array(20); - // - // var vn = pointcloud.visibleNodes; - // for(var i = 0; i < vn.length; i++){ - // var node = vn[i].node; - // var level = node.level; - // - // levels[level]++; - // } - // - // var a; - //} + TWEEN.update(timestamp); } function useEarthControls(){ @@ -768,6 +755,56 @@ function useOrbitControls(){ event.counterProposals.push(counterProposal); } }); + orbitControls.domElement.addEventListener("dblclick", function(event){ + if(!pointcloud){ + return; + } + + event.preventDefault(); + + var rect = orbitControls.domElement.getBoundingClientRect(); + + var mouse = { + x: ( (event.clientX - rect.left) / orbitControls.domElement.clientWidth ) * 2 - 1, + y: - ( (event.clientY - rect.top) / orbitControls.domElement.clientHeight ) * 2 + 1 + }; + + + var I = getMousePointCloudIntersection(mouse, camera, renderer, [pointcloud]); + if(I != null){ + + var camTargetDistance = camera.position.distanceTo(orbitControls.target); + + var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 ); + vector.unproject(camera); + + var direction = vector.sub(camera.position).normalize(); + var ray = new THREE.Ray(camera.position, direction); + + var nodes = pointcloud.nodesOnRay(pointcloud.visibleNodes, ray); + var lastNode = nodes[nodes.length - 1]; + var radius = lastNode.boundingSphere.radius; + var targetRadius = Math.min(camTargetDistance, radius); + + var d = camera.getWorldDirection().multiplyScalar(-1); + var cameraTargetPosition = new THREE.Vector3().addVectors(I, d.multiplyScalar(targetRadius)); + var controlsTargetPosition = I; + + var animationDuration = 400; + + var easing = TWEEN.Easing.Quartic.Out; + + // animate position + var tween = new TWEEN.Tween(camera.position).to(cameraTargetPosition, animationDuration); + tween.easing(easing); + tween.start(); + + // animate target + var tween = new TWEEN.Tween(controls.target).to(I, animationDuration); + tween.easing(easing); + tween.start(); + } + }); } controls = orbitControls; @@ -1045,15 +1082,6 @@ var EDLRenderer = function(){ //stencilBuffer: false } ); - //depthTexture = new THREE.Texture(); - //depthTexture.__webglInit = true; - //depthTexture.__webglTexture = gl.createTexture();; - //gl.bindTexture(gl.TEXTURE_2D, depthTexture.__webglTexture); - //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - //gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT, 1024, 1024, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_SHORT, null); }; var resize = function(){ @@ -1074,28 +1102,6 @@ var EDLRenderer = function(){ renderer.setSize(width, height); rtColor.setSize(width, height); - - //if(needsResize){ - // renderer.setRenderTarget(rtColor); - // var framebuffer = rtColor.__webglFramebuffer; - // gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); - // - // - // gl.bindRenderbuffer( gl.RENDERBUFFER, rtColor.__webglRenderbuffer ); - // gl.renderbufferStorage( gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, rtColor.width, rtColor.height ); - // gl.framebufferRenderbuffer( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null ); - // - // gl.bindTexture(gl.TEXTURE_2D, depthTexture.__webglTexture); - // gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - // gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - // gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - // gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - // gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT, width, height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null); - // - // gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTexture.__webglTexture, 0); - // - // renderer.setRenderTarget(null); - //} } this.render = function(){ @@ -1123,6 +1129,14 @@ var EDLRenderer = function(){ var originalMaterial = pointcloud.material; {// COLOR & DEPTH PASS + attributeMaterial = pointcloud.material; + attributeMaterial.pointShape = Potree.PointShape.CIRCLE; + attributeMaterial.interpolate = false; + attributeMaterial.weighted = false; + attributeMaterial.minSize = 2; + attributeMaterial.useLogarithmicDepthBuffer = false; + attributeMaterial.useEDL = true; + attributeMaterial.size = pointSize; attributeMaterial.pointSizeType = pointSizeType; attributeMaterial.screenWidth = width; @@ -1190,11 +1204,11 @@ var EDLRenderer = function(){ //var toggleMessage = 0; -function loop() { +function loop(timestamp) { requestAnimationFrame(loop); //var start = new Date().getTime(); - update(); + update(clock.getDelta(), timestamp); //var end = new Date().getTime(); //var duration = end - start; //toggleMessage++; @@ -1221,4 +1235,4 @@ function loop() { initThree(); -loop(); \ No newline at end of file +requestAnimationFrame(loop); \ No newline at end of file diff --git a/libs/tween/LICENSE.txt b/libs/tween/LICENSE.txt new file mode 100644 index 00000000..268787f6 --- /dev/null +++ b/libs/tween/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 gskinner.com, inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/libs/tween/README.txt b/libs/tween/README.txt new file mode 100644 index 00000000..1b0aef6a --- /dev/null +++ b/libs/tween/README.txt @@ -0,0 +1,9 @@ +This directory contains a compressed version of the TweenJS library. + +It also includes a minified version of EaselJS, and is included for the Ticker class, which TweenJS uses by default. If you don't wish to use EaselJS, you can implement your own ticking mechanism, or download the Ticker class on its own from http://github.com/createjs/easeljs/ + +It is recommended that you use this version in almost all cases, unless you need to modify the original code. It is much smaller, results in less http requests, and you don't have to worry about the order in which you include the js files. + +tween.js is a single file that contains compacted versions of all of the TweenJS classes (comments and white space stripped). + +You can also gzip the file to further reduce its size (by about 75%). Many servers do this automatically. diff --git a/libs/tween/tween.min.js b/libs/tween/tween.min.js new file mode 100644 index 00000000..2f2a9645 --- /dev/null +++ b/libs/tween/tween.min.js @@ -0,0 +1,2 @@ +// tween.js v.0.15.0 https://github.com/sole/tween.js +void 0===Date.now&&(Date.now=function(){return(new Date).valueOf()});var TWEEN=TWEEN||function(){var n=[];return{REVISION:"14",getAll:function(){return n},removeAll:function(){n=[]},add:function(t){n.push(t)},remove:function(t){var r=n.indexOf(t);-1!==r&&n.splice(r,1)},update:function(t){if(0===n.length)return!1;var r=0;for(t=void 0!==t?t:"undefined"!=typeof window&&void 0!==window.performance&&void 0!==window.performance.now?window.performance.now():Date.now();rn;n++)E[n].stop()},this.delay=function(n){return s=n,this},this.repeat=function(n){return e=n,this},this.yoyo=function(n){return a=n,this},this.easing=function(n){return l=n,this},this.interpolation=function(n){return p=n,this},this.chain=function(){return E=arguments,this},this.onStart=function(n){return d=n,this},this.onUpdate=function(n){return I=n,this},this.onComplete=function(n){return w=n,this},this.onStop=function(n){return M=n,this},this.update=function(n){var f;if(h>n)return!0;v===!1&&(null!==d&&d.call(t),v=!0);var M=(n-h)/o;M=M>1?1:M;var O=l(M);for(f in i){var m=r[f]||0,N=i[f];N instanceof Array?t[f]=p(N,O):("string"==typeof N&&(N=m+parseFloat(N,10)),"number"==typeof N&&(t[f]=m+(N-m)*O))}if(null!==I&&I.call(t,O),1==M){if(e>0){isFinite(e)&&e--;for(f in u){if("string"==typeof i[f]&&(u[f]=u[f]+parseFloat(i[f],10)),a){var T=u[f];u[f]=i[f],i[f]=T}r[f]=u[f]}return a&&(c=!c),h=n+s,!0}null!==w&&w.call(t);for(var g=0,W=E.length;W>g;g++)E[g].start(n);return!1}return!0}},TWEEN.Easing={Linear:{None:function(n){return n}},Quadratic:{In:function(n){return n*n},Out:function(n){return n*(2-n)},InOut:function(n){return(n*=2)<1?.5*n*n:-.5*(--n*(n-2)-1)}},Cubic:{In:function(n){return n*n*n},Out:function(n){return--n*n*n+1},InOut:function(n){return(n*=2)<1?.5*n*n*n:.5*((n-=2)*n*n+2)}},Quartic:{In:function(n){return n*n*n*n},Out:function(n){return 1- --n*n*n*n},InOut:function(n){return(n*=2)<1?.5*n*n*n*n:-.5*((n-=2)*n*n*n-2)}},Quintic:{In:function(n){return n*n*n*n*n},Out:function(n){return--n*n*n*n*n+1},InOut:function(n){return(n*=2)<1?.5*n*n*n*n*n:.5*((n-=2)*n*n*n*n+2)}},Sinusoidal:{In:function(n){return 1-Math.cos(n*Math.PI/2)},Out:function(n){return Math.sin(n*Math.PI/2)},InOut:function(n){return.5*(1-Math.cos(Math.PI*n))}},Exponential:{In:function(n){return 0===n?0:Math.pow(1024,n-1)},Out:function(n){return 1===n?1:1-Math.pow(2,-10*n)},InOut:function(n){return 0===n?0:1===n?1:(n*=2)<1?.5*Math.pow(1024,n-1):.5*(-Math.pow(2,-10*(n-1))+2)}},Circular:{In:function(n){return 1-Math.sqrt(1-n*n)},Out:function(n){return Math.sqrt(1- --n*n)},InOut:function(n){return(n*=2)<1?-.5*(Math.sqrt(1-n*n)-1):.5*(Math.sqrt(1-(n-=2)*n)+1)}},Elastic:{In:function(n){var t,r=.1,i=.4;return 0===n?0:1===n?1:(!r||1>r?(r=1,t=i/4):t=i*Math.asin(1/r)/(2*Math.PI),-(r*Math.pow(2,10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i)))},Out:function(n){var t,r=.1,i=.4;return 0===n?0:1===n?1:(!r||1>r?(r=1,t=i/4):t=i*Math.asin(1/r)/(2*Math.PI),r*Math.pow(2,-10*n)*Math.sin(2*(n-t)*Math.PI/i)+1)},InOut:function(n){var t,r=.1,i=.4;return 0===n?0:1===n?1:(!r||1>r?(r=1,t=i/4):t=i*Math.asin(1/r)/(2*Math.PI),(n*=2)<1?-.5*r*Math.pow(2,10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i):r*Math.pow(2,-10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i)*.5+1)}},Back:{In:function(n){var t=1.70158;return n*n*((t+1)*n-t)},Out:function(n){var t=1.70158;return--n*n*((t+1)*n+t)+1},InOut:function(n){var t=2.5949095;return(n*=2)<1?.5*n*n*((t+1)*n-t):.5*((n-=2)*n*((t+1)*n+t)+2)}},Bounce:{In:function(n){return 1-TWEEN.Easing.Bounce.Out(1-n)},Out:function(n){return 1/2.75>n?7.5625*n*n:2/2.75>n?7.5625*(n-=1.5/2.75)*n+.75:2.5/2.75>n?7.5625*(n-=2.25/2.75)*n+.9375:7.5625*(n-=2.625/2.75)*n+.984375},InOut:function(n){return.5>n?.5*TWEEN.Easing.Bounce.In(2*n):.5*TWEEN.Easing.Bounce.Out(2*n-1)+.5}}},TWEEN.Interpolation={Linear:function(n,t){var r=n.length-1,i=r*t,u=Math.floor(i),o=TWEEN.Interpolation.Utils.Linear;return 0>t?o(n[0],n[1],i):t>1?o(n[r],n[r-1],r-i):o(n[u],n[u+1>r?r:u+1],i-u)},Bezier:function(n,t){var r,i=0,u=n.length-1,o=Math.pow,e=TWEEN.Interpolation.Utils.Bernstein;for(r=0;u>=r;r++)i+=o(1-t,u-r)*o(t,r)*n[r]*e(u,r);return i},CatmullRom:function(n,t){var r=n.length-1,i=r*t,u=Math.floor(i),o=TWEEN.Interpolation.Utils.CatmullRom;return n[0]===n[r]?(0>t&&(u=Math.floor(i=r*(1+t))),o(n[(u-1+r)%r],n[u],n[(u+1)%r],n[(u+2)%r],i-u)):0>t?n[0]-(o(n[0],n[0],n[1],n[1],-i)-n[0]):t>1?n[r]-(o(n[r],n[r],n[r-1],n[r-1],i-r)-n[r]):o(n[u?u-1:0],n[u],n[u+1>r?r:u+1],n[u+2>r?r:u+2],i-u)},Utils:{Linear:function(n,t,r){return(t-n)*r+n},Bernstein:function(n,t){var r=TWEEN.Interpolation.Utils.Factorial;return r(n)/r(t)/r(n-t)},Factorial:function(){var n=[1];return function(t){var r,i=1;if(n[t])return n[t];for(r=t;r>1;r--)i*=r;return n[t]=i}}(),CatmullRom:function(n,t,r,i,u){var o=.5*(r-n),e=.5*(i-t),a=u*u,f=u*a;return(2*t-2*r+o+e)*f+(-3*t+3*r-2*o-e)*a+o*u+t}}},"undefined"!=typeof module&&module.exports&&(module.exports=TWEEN); \ No newline at end of file