From c90fea219c80f1a902ce878dbbd9631f677c9558 Mon Sep 17 00:00:00 2001 From: Shohei Fujii Date: Sat, 6 Jul 2013 18:52:53 +0900 Subject: [PATCH 1/7] 3djs tries to start rotate...? --- build/ros3d.js | 117 ++++++++++++++++-- build/ros3d.min.js | 2 +- src/visualization/interaction/MouseHandler.js | 39 +++++- .../interaction/OrbitControls.js | 78 +++++++++++- 4 files changed, 221 insertions(+), 15 deletions(-) diff --git a/build/ros3d.js b/build/ros3d.js index 28cec71a..10a353f7 100644 --- a/build/ros3d.js +++ b/build/ros3d.js @@ -2678,6 +2678,12 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { intersection : this.lastIntersection }; + console.log('------------------------------------'); + console.log(domEvent.type); + console.log(' Dragging?: ' + this.dragging); + console.log(' lastTarget: ' + this.lastTarget); + console.log(' Target: ' + target); + // if the mouse leaves the dom element, stop everything if (domEvent.type === 'mouseout') { if (this.dragging) { @@ -2689,11 +2695,22 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { return; } + // if the touch leaves the dom element, stop everything + if (domEvent.type === 'touchleave' || domEvent.type === 'touchend') { + if (this.dragging) { + this.notify(this.lastTarget, 'mouseup', event3D); + this.dragging = false; + } + this.notify(this.lastTarget, 'touchend', event3D); + this.lastTarget = null; + return; + } + // while the user is holding the mouse down, stay on the same target if (this.dragging) { this.notify(this.lastTarget, domEvent.type, event3D); // for check for right or left mouse button - if ((domEvent.type === 'mouseup' && domEvent.button === 2) || domEvent.type === 'click') { + if ((domEvent.type === 'mouseup' && domEvent.button === 2) || domEvent.type === 'click' || domEvent.type === 'touchend') { this.dragging = false; } return; @@ -2711,7 +2728,7 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { } // if the mouse moves from one object to another (or from/to the 'null' object), notify both - if (target !== this.lastTarget) { + if (target !== this.lastTarget && domEvent.type.match(/mouse/)) { var eventAccepted = this.notify(target, 'mouseover', event3D); if (eventAccepted) { this.notify(this.lastTarget, 'mouseout', event3D); @@ -2725,9 +2742,25 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { } } + // if the finger moves from one object to another (or from/to the 'null' object), notify both + if (target !== this.lastTarget && domEvent.type.match(/touch/)) { + var toucheventAccepted = this.notify(target, 'touchmove', event3D); + if (toucheventAccepted) { + this.notify(this.lastTarget, 'touchleave', event3D); + this.notify(this.lastTarget, 'touchend', event3D); + } else { + // if target was null or no target has caught our event, fall back + target = this.fallbackTarget; + if (target !== this.lastTarget) { + this.notify(this.lastTarget, 'touchmove', event3D); + this.notify(this.lastTarget, 'touchend', event3D); + } + } + } + // pass through event this.notify(target, domEvent.type, event3D); - if (domEvent.type === 'mousedown') { + if (domEvent.type === 'mousedown' || domEvent.type === 'touchstart' || domEvent.type === 'touchmove') { this.dragging = true; } this.lastTarget = target; @@ -2996,8 +3029,37 @@ ROS3D.OrbitControls = function(options) { * * @param event3D - the 3D event to handle */ - function onTouchDown(event) { - onMouseDown(event); + function onTouchDown(event3D) { + var event = event3D.domEvent; + event.preventDefault(); + + console.log('>> button: ' + event.button); + switch (event.button) { + case 0: + state = STATE.ROTATE; + rotateStart.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + break; + case 1: + state = STATE.MOVE; + + moveStartNormal = new THREE.Vector3(0, 0, 1); + var rMat = new THREE.Matrix4().extractRotation(this.camera.matrix); + moveStartNormal.applyMatrix4(rMat); + + moveStartCenter = that.center.clone(); + moveStartPosition = that.camera.position.clone(); + moveStartIntersection = intersectViewPlane(event3D.mouseRay, moveStartCenter, + moveStartNormal); + break; + case 2: + state = STATE.ZOOM; + zoomStart.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + break; + } + + this.showAxes(); + + //onMouseDown(event); event.preventDefault(); } @@ -3006,8 +3068,49 @@ ROS3D.OrbitControls = function(options) { * * @param event3D - the 3D event to handle */ - function onTouchMove(event) { - onMouseMove(event); + function onTouchMove(event3D) { + var event = event3D.domEvent; + if (state === STATE.ROTATE) { + + rotateEnd.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + rotateDelta.subVectors(rotateEnd, rotateStart); + + that.rotateLeft(2 * Math.PI * rotateDelta.x / pixlesPerRound * that.userRotateSpeed); + that.rotateUp(2 * Math.PI * rotateDelta.y / pixlesPerRound * that.userRotateSpeed); + + rotateStart.copy(rotateEnd); + this.showAxes(); + } else if (state === STATE.ZOOM) { + zoomEnd.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + zoomDelta.subVectors(zoomEnd, zoomStart); + + if (zoomDelta.y > 0) { + that.zoomIn(); + } else { + that.zoomOut(); + } + + zoomStart.copy(zoomEnd); + this.showAxes(); + + } else if (state === STATE.MOVE) { + var intersection = intersectViewPlane(event3D.mouseRay, that.center, moveStartNormal); + + if (!intersection) { + return; + } + + var delta = new THREE.Vector3().subVectors(moveStartIntersection.clone(), intersection + .clone()); + + that.center.addVectors(moveStartCenter.clone(), delta.clone()); + that.camera.position.addVectors(moveStartPosition.clone(), delta.clone()); + that.update(); + that.camera.updateMatrixWorld(); + this.showAxes(); + } + + //onMouseMove(event); event.preventDefault(); } diff --git a/build/ros3d.min.js b/build/ros3d.min.js index 68f7197c..76a26dee 100644 --- a/build/ros3d.min.js +++ b/build/ros3d.min.js @@ -1,2 +1,2 @@ var ROS3D=ROS3D||{REVISION:"6"};ROS3D.MARKER_ARROW=0,ROS3D.MARKER_CUBE=1,ROS3D.MARKER_SPHERE=2,ROS3D.MARKER_CYLINDER=3,ROS3D.MARKER_LINE_STRIP=4,ROS3D.MARKER_LINE_LIST=5,ROS3D.MARKER_CUBE_LIST=6,ROS3D.MARKER_SPHERE_LIST=7,ROS3D.MARKER_POINTS=8,ROS3D.MARKER_TEXT_VIEW_FACING=9,ROS3D.MARKER_MESH_RESOURCE=10,ROS3D.MARKER_TRIANGLE_LIST=11,ROS3D.INTERACTIVE_MARKER_KEEP_ALIVE=0,ROS3D.INTERACTIVE_MARKER_POSE_UPDATE=1,ROS3D.INTERACTIVE_MARKER_MENU_SELECT=2,ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK=3,ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN=4,ROS3D.INTERACTIVE_MARKER_MOUSE_UP=5,ROS3D.INTERACTIVE_MARKER_NONE=0,ROS3D.INTERACTIVE_MARKER_MENU=1,ROS3D.INTERACTIVE_MARKER_BUTTON=2,ROS3D.INTERACTIVE_MARKER_MOVE_AXIS=3,ROS3D.INTERACTIVE_MARKER_MOVE_PLANE=4,ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS=5,ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE=6,ROS3D.INTERACTIVE_MARKER_INHERIT=0,ROS3D.INTERACTIVE_MARKER_FIXED=1,ROS3D.INTERACTIVE_MARKER_VIEW_FACING=2,ROS3D.makeColorMaterial=function(a,b,c,d){var e=new THREE.Color;return e.setRGB(a,b,c),.99>=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.y,c.scale.z),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;yg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b=a.target,c=b.getBoundingClientRect(),d=a.clientX-c.left-b.clientLeft+b.scrollLeft,e=a.clientY-c.top-b.clientTop+b.scrollTop,f=2*(d/b.clientWidth)-1,g=2*(-e/b.clientHeight)+1,h=new THREE.Vector3(f,g,.5);this.projector.unprojectVector(h,this.camera);var i=new THREE.Raycaster(this.camera.position.clone(),h.sub(this.camera.position).normalize()),j=i.ray,k={mousePos:new THREE.Vector2(f,g),mouseRay:j,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if("mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",k),this.dragging=!1),this.notify(this.lastTarget,"mouseout",k),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,k),("mouseup"===a.type&&2===a.button||"click"===a.type)&&(this.dragging=!1),void 0;b=this.lastTarget;var l=[];if(l=i.intersectObject(this.rootObject,!0),l.length>0?(b=l[0].object,k.intersection=this.lastIntersection=l[0]):b=this.fallbackTarget,b!==this.lastTarget){var m=this.notify(b,"mouseover",k);m?this.notify(this.lastTarget,"mouseout",k):(b=this.fallbackTarget,b!==this.lastTarget&&(this.notify(b,"mouseover",k),this.notify(this.lastTarget,"mouseout",k)))}this.notify(b,a.type,k),"mousedown"===a.type&&(this.dragging=!0),this.lastTarget=b},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomOut():i.zoomIn(),this.showAxes()}}function g(a){b(a),a.preventDefault()}function h(a){c(a),a.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file +},ROS3D.Axes.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Grid=function(a){a=a||{};var b=a.size||50,c=a.color||"#cccccc",d=a.lineWidth||1;THREE.Mesh.call(this,new THREE.PlaneGeometry(b,b,b,b),new THREE.MeshBasicMaterial({color:c,wireframe:!0,wireframeLinewidth:d,transparent:!0}))},ROS3D.Grid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.MeshResource=function(a){var b=this;a=a||{};var c=a.path||"/",d=a.resource;this.warnings=a.warnings,THREE.Object3D.call(this),"/"!==c.substr(c.length-1)&&(this.path+="/");var e=c+d;if(e.substr(-4).toLowerCase(),".dae"===e.substr(-4).toLowerCase()){var f=new ColladaLoader2;f.log=function(a){b.warnings&&console.warn(a)},f.load(e,function(a){if(a.dae.asset.unit){var c=a.dae.asset.unit;a.scene.scale=new THREE.Vector3(c,c,c)}b.add(a.scene)})}},ROS3D.MeshResource.prototype.__proto__=THREE.Object3D.prototype,ROS3D.TriangleList=function(a){a=a||{};var b=a.material||new THREE.MeshBasicMaterial,c=a.vertices,d=a.colors;THREE.Object3D.call(this),b.side=THREE.DoubleSide;var e=new THREE.Geometry;for(f=0;fg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b=a.target,c=b.getBoundingClientRect(),d=a.clientX-c.left-b.clientLeft+b.scrollLeft,e=a.clientY-c.top-b.clientTop+b.scrollTop,f=2*(d/b.clientWidth)-1,g=2*(-e/b.clientHeight)+1,h=new THREE.Vector3(f,g,.5);this.projector.unprojectVector(h,this.camera);var i=new THREE.Raycaster(this.camera.position.clone(),h.sub(this.camera.position).normalize()),j=i.ray,k={mousePos:new THREE.Vector2(f,g),mouseRay:j,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+b),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",k),this.dragging=!1),this.notify(this.lastTarget,"mouseout",k),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",k),this.dragging=!1),this.notify(this.lastTarget,"touchend",k),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,k),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;b=this.lastTarget;var l=[];if(l=i.intersectObject(this.rootObject,!0),l.length>0?(b=l[0].object,k.intersection=this.lastIntersection=l[0]):b=this.fallbackTarget,b!==this.lastTarget&&a.type.match(/mouse/)){var m=this.notify(b,"mouseover",k);m?this.notify(this.lastTarget,"mouseout",k):(b=this.fallbackTarget,b!==this.lastTarget&&(this.notify(b,"mouseover",k),this.notify(this.lastTarget,"mouseout",k)))}if(b!==this.lastTarget&&a.type.match(/touch/)){var n=this.notify(b,"touchmove",k);n?(this.notify(this.lastTarget,"touchleave",k),this.notify(this.lastTarget,"touchend",k)):(b=this.fallbackTarget,b!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",k),this.notify(this.lastTarget,"touchend",k)))}this.notify(b,a.type,k),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=b},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomOut():i.zoomIn(),this.showAxes()}}function g(a){var b=a.domEvent;switch(b.preventDefault(),console.log(">> button: "+b.button),b.button){case 0:w=v.ROTATE,l.set(b.pageX-window.scrollX,b.pageY-window.scrollY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.pageX-window.scrollX,b.pageY-window.scrollY)}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.pageX-window.scrollX,b.pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.pageX-window.scrollX,b.pageY-window.scrollY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file diff --git a/src/visualization/interaction/MouseHandler.js b/src/visualization/interaction/MouseHandler.js index 5cb249ea..b69d1292 100644 --- a/src/visualization/interaction/MouseHandler.js +++ b/src/visualization/interaction/MouseHandler.js @@ -67,6 +67,12 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { intersection : this.lastIntersection }; + console.log('------------------------------------'); + console.log(domEvent.type); + console.log(' Dragging?: ' + this.dragging); + console.log(' lastTarget: ' + this.lastTarget); + console.log(' Target: ' + target); + // if the mouse leaves the dom element, stop everything if (domEvent.type === 'mouseout') { if (this.dragging) { @@ -78,11 +84,22 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { return; } + // if the touch leaves the dom element, stop everything + if (domEvent.type === 'touchleave' || domEvent.type === 'touchend') { + if (this.dragging) { + this.notify(this.lastTarget, 'mouseup', event3D); + this.dragging = false; + } + this.notify(this.lastTarget, 'touchend', event3D); + this.lastTarget = null; + return; + } + // while the user is holding the mouse down, stay on the same target if (this.dragging) { this.notify(this.lastTarget, domEvent.type, event3D); // for check for right or left mouse button - if ((domEvent.type === 'mouseup' && domEvent.button === 2) || domEvent.type === 'click') { + if ((domEvent.type === 'mouseup' && domEvent.button === 2) || domEvent.type === 'click' || domEvent.type === 'touchend') { this.dragging = false; } return; @@ -100,7 +117,7 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { } // if the mouse moves from one object to another (or from/to the 'null' object), notify both - if (target !== this.lastTarget) { + if (target !== this.lastTarget && domEvent.type.match(/mouse/)) { var eventAccepted = this.notify(target, 'mouseover', event3D); if (eventAccepted) { this.notify(this.lastTarget, 'mouseout', event3D); @@ -114,9 +131,25 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { } } + // if the finger moves from one object to another (or from/to the 'null' object), notify both + if (target !== this.lastTarget && domEvent.type.match(/touch/)) { + var toucheventAccepted = this.notify(target, 'touchmove', event3D); + if (toucheventAccepted) { + this.notify(this.lastTarget, 'touchleave', event3D); + this.notify(this.lastTarget, 'touchend', event3D); + } else { + // if target was null or no target has caught our event, fall back + target = this.fallbackTarget; + if (target !== this.lastTarget) { + this.notify(this.lastTarget, 'touchmove', event3D); + this.notify(this.lastTarget, 'touchend', event3D); + } + } + } + // pass through event this.notify(target, domEvent.type, event3D); - if (domEvent.type === 'mousedown') { + if (domEvent.type === 'mousedown' || domEvent.type === 'touchstart' || domEvent.type === 'touchmove') { this.dragging = true; } this.lastTarget = target; diff --git a/src/visualization/interaction/OrbitControls.js b/src/visualization/interaction/OrbitControls.js index b6f71470..3d9dd9e7 100644 --- a/src/visualization/interaction/OrbitControls.js +++ b/src/visualization/interaction/OrbitControls.js @@ -226,8 +226,37 @@ ROS3D.OrbitControls = function(options) { * * @param event3D - the 3D event to handle */ - function onTouchDown(event) { - onMouseDown(event); + function onTouchDown(event3D) { + var event = event3D.domEvent; + event.preventDefault(); + + console.log('>> button: ' + event.button); + switch (event.button) { + case 0: + state = STATE.ROTATE; + rotateStart.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + break; + case 1: + state = STATE.MOVE; + + moveStartNormal = new THREE.Vector3(0, 0, 1); + var rMat = new THREE.Matrix4().extractRotation(this.camera.matrix); + moveStartNormal.applyMatrix4(rMat); + + moveStartCenter = that.center.clone(); + moveStartPosition = that.camera.position.clone(); + moveStartIntersection = intersectViewPlane(event3D.mouseRay, moveStartCenter, + moveStartNormal); + break; + case 2: + state = STATE.ZOOM; + zoomStart.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + break; + } + + this.showAxes(); + + //onMouseDown(event); event.preventDefault(); } @@ -236,8 +265,49 @@ ROS3D.OrbitControls = function(options) { * * @param event3D - the 3D event to handle */ - function onTouchMove(event) { - onMouseMove(event); + function onTouchMove(event3D) { + var event = event3D.domEvent; + if (state === STATE.ROTATE) { + + rotateEnd.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + rotateDelta.subVectors(rotateEnd, rotateStart); + + that.rotateLeft(2 * Math.PI * rotateDelta.x / pixlesPerRound * that.userRotateSpeed); + that.rotateUp(2 * Math.PI * rotateDelta.y / pixlesPerRound * that.userRotateSpeed); + + rotateStart.copy(rotateEnd); + this.showAxes(); + } else if (state === STATE.ZOOM) { + zoomEnd.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + zoomDelta.subVectors(zoomEnd, zoomStart); + + if (zoomDelta.y > 0) { + that.zoomIn(); + } else { + that.zoomOut(); + } + + zoomStart.copy(zoomEnd); + this.showAxes(); + + } else if (state === STATE.MOVE) { + var intersection = intersectViewPlane(event3D.mouseRay, that.center, moveStartNormal); + + if (!intersection) { + return; + } + + var delta = new THREE.Vector3().subVectors(moveStartIntersection.clone(), intersection + .clone()); + + that.center.addVectors(moveStartCenter.clone(), delta.clone()); + that.camera.position.addVectors(moveStartPosition.clone(), delta.clone()); + that.update(); + that.camera.updateMatrixWorld(); + this.showAxes(); + } + + //onMouseMove(event); event.preventDefault(); } From d30078a581acc0dec5aa5fdc82c54a5b57db4947 Mon Sep 17 00:00:00 2001 From: murase Date: Mon, 8 Jul 2013 15:14:19 +0900 Subject: [PATCH 2/7] 3djs can rotate/slide/pinch --- build/ros3d.js | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/build/ros3d.js b/build/ros3d.js index 10a353f7..3afead64 100644 --- a/build/ros3d.js +++ b/build/ros3d.js @@ -2,7 +2,6 @@ * @author Russell Toris - rctoris@wpi.edu * @author David Gossow - dgossow@willowgarage.com */ - var ROS3D = ROS3D || { REVISION : '6' }; @@ -2658,8 +2657,18 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { // compute normalized device coords and 3D mouse ray var target = domEvent.target; var rect = target.getBoundingClientRect(); - var left = domEvent.clientX - rect.left - target.clientLeft + target.scrollLeft; - var top = domEvent.clientY - rect.top - target.clientTop + target.scrollTop; + var pos_x, pos_y; + + if(domEvent.type.indexOf("touch") != -1) { + pos_x = domEvent.changedTouches[0].clientX; + pos_y = domEvent.changedTouches[0].clientY; + } + else { + pos_x = domEvent.clientX; + pos_y = domEvent.clientY; + } + var left = pos_x - rect.left - target.clientLeft + target.scrollLeft; + var top = pos_y - rect.top - target.clientTop + target.scrollTop; var deviceX = left / target.clientWidth * 2 - 1; var deviceY = -top / target.clientHeight * 2 + 1; var vector = new THREE.Vector3(deviceX, deviceY, 0.5); @@ -2668,7 +2677,6 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { var mouseRaycaster = new THREE.Raycaster(this.camera.position.clone(), vector.sub( this.camera.position).normalize()); var mouseRay = mouseRaycaster.ray; - // make our 3d mouse event var event3D = { mousePos : new THREE.Vector2(deviceX, deviceY), @@ -2881,7 +2889,6 @@ ROS3D.OrbitControls = function(options) { function onMouseDown(event3D) { var event = event3D.domEvent; event.preventDefault(); - switch (event.button) { case 0: state = STATE.ROTATE; @@ -2926,7 +2933,7 @@ ROS3D.OrbitControls = function(options) { rotateStart.copy(rotateEnd); this.showAxes(); } else if (state === STATE.ZOOM) { - zoomEnd.set(event.clientX, event.clientY); + zoomEnd.set(event.clientX, event.clientY); zoomDelta.subVectors(zoomEnd, zoomStart); if (zoomDelta.y > 0) { @@ -3031,17 +3038,19 @@ ROS3D.OrbitControls = function(options) { */ function onTouchDown(event3D) { var event = event3D.domEvent; - event.preventDefault(); - console.log('>> button: ' + event.button); - switch (event.button) { - case 0: + switch (event.touches.length) { + case 1: state = STATE.ROTATE; - rotateStart.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + rotateStart.set(event.changedTouches[0].pageX - window.scrollX, event.changedTouches[0].pageY - window.scrollY); break; - case 1: + case 2: + state = STATE.ZOOM; + zoomStart.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); + break; + case 3: state = STATE.MOVE; - + moveStartNormal = new THREE.Vector3(0, 0, 1); var rMat = new THREE.Matrix4().extractRotation(this.camera.matrix); moveStartNormal.applyMatrix4(rMat); @@ -3051,10 +3060,7 @@ ROS3D.OrbitControls = function(options) { moveStartIntersection = intersectViewPlane(event3D.mouseRay, moveStartCenter, moveStartNormal); break; - case 2: - state = STATE.ZOOM; - zoomStart.set(event.pageX - window.scrollX, event.pageY - window.scrollY); - break; + } this.showAxes(); @@ -3069,19 +3075,20 @@ ROS3D.OrbitControls = function(options) { * @param event3D - the 3D event to handle */ function onTouchMove(event3D) { + var event = event3D.domEvent; + console.log(state); if (state === STATE.ROTATE) { - rotateEnd.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + rotateEnd.set(event.changedTouches[0].pageX - window.scrollX, event.changedTouches[0].pageY - window.scrollY); rotateDelta.subVectors(rotateEnd, rotateStart); that.rotateLeft(2 * Math.PI * rotateDelta.x / pixlesPerRound * that.userRotateSpeed); that.rotateUp(2 * Math.PI * rotateDelta.y / pixlesPerRound * that.userRotateSpeed); - rotateStart.copy(rotateEnd); this.showAxes(); } else if (state === STATE.ZOOM) { - zoomEnd.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + zoomEnd.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); zoomDelta.subVectors(zoomEnd, zoomStart); if (zoomDelta.y > 0) { From 45a2dc19567ef0dc211b23ebe58244b205bb5331 Mon Sep 17 00:00:00 2001 From: Shohei Fujii Date: Mon, 8 Jul 2013 15:58:39 +0900 Subject: [PATCH 3/7] apply murase's change to src files --- build/ros3d.js | 19 ++++++++------- build/ros3d.min.js | 2 +- src/visualization/interaction/MouseHandler.js | 14 +++++++++-- .../interaction/OrbitControls.js | 24 +++++++++---------- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/build/ros3d.js b/build/ros3d.js index 3afead64..5436615f 100644 --- a/build/ros3d.js +++ b/build/ros3d.js @@ -2,6 +2,7 @@ * @author Russell Toris - rctoris@wpi.edu * @author David Gossow - dgossow@willowgarage.com */ + var ROS3D = ROS3D || { REVISION : '6' }; @@ -2659,7 +2660,7 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { var rect = target.getBoundingClientRect(); var pos_x, pos_y; - if(domEvent.type.indexOf("touch") != -1) { + if(domEvent.type.indexOf('touch') !== -1) { pos_x = domEvent.changedTouches[0].clientX; pos_y = domEvent.changedTouches[0].clientY; } @@ -2677,6 +2678,7 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { var mouseRaycaster = new THREE.Raycaster(this.camera.position.clone(), vector.sub( this.camera.position).normalize()); var mouseRay = mouseRaycaster.ray; + // make our 3d mouse event var event3D = { mousePos : new THREE.Vector2(deviceX, deviceY), @@ -2889,6 +2891,7 @@ ROS3D.OrbitControls = function(options) { function onMouseDown(event3D) { var event = event3D.domEvent; event.preventDefault(); + switch (event.button) { case 0: state = STATE.ROTATE; @@ -2933,7 +2936,7 @@ ROS3D.OrbitControls = function(options) { rotateStart.copy(rotateEnd); this.showAxes(); } else if (state === STATE.ZOOM) { - zoomEnd.set(event.clientX, event.clientY); + zoomEnd.set(event.clientX, event.clientY); zoomDelta.subVectors(zoomEnd, zoomStart); if (zoomDelta.y > 0) { @@ -3039,18 +3042,18 @@ ROS3D.OrbitControls = function(options) { function onTouchDown(event3D) { var event = event3D.domEvent; console.log('>> button: ' + event.button); - switch (event.touches.length) { + switch (event.touches.length) { case 1: state = STATE.ROTATE; rotateStart.set(event.changedTouches[0].pageX - window.scrollX, event.changedTouches[0].pageY - window.scrollY); break; case 2: state = STATE.ZOOM; - zoomStart.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); + zoomStart.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); break; case 3: state = STATE.MOVE; - + moveStartNormal = new THREE.Vector3(0, 0, 1); var rMat = new THREE.Matrix4().extractRotation(this.camera.matrix); moveStartNormal.applyMatrix4(rMat); @@ -3075,9 +3078,8 @@ ROS3D.OrbitControls = function(options) { * @param event3D - the 3D event to handle */ function onTouchMove(event3D) { - var event = event3D.domEvent; - console.log(state); + console.log(state); if (state === STATE.ROTATE) { rotateEnd.set(event.changedTouches[0].pageX - window.scrollX, event.changedTouches[0].pageY - window.scrollY); @@ -3085,10 +3087,11 @@ ROS3D.OrbitControls = function(options) { that.rotateLeft(2 * Math.PI * rotateDelta.x / pixlesPerRound * that.userRotateSpeed); that.rotateUp(2 * Math.PI * rotateDelta.y / pixlesPerRound * that.userRotateSpeed); + rotateStart.copy(rotateEnd); this.showAxes(); } else if (state === STATE.ZOOM) { - zoomEnd.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); + zoomEnd.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); zoomDelta.subVectors(zoomEnd, zoomStart); if (zoomDelta.y > 0) { diff --git a/build/ros3d.min.js b/build/ros3d.min.js index 76a26dee..43882584 100644 --- a/build/ros3d.min.js +++ b/build/ros3d.min.js @@ -1,2 +1,2 @@ var ROS3D=ROS3D||{REVISION:"6"};ROS3D.MARKER_ARROW=0,ROS3D.MARKER_CUBE=1,ROS3D.MARKER_SPHERE=2,ROS3D.MARKER_CYLINDER=3,ROS3D.MARKER_LINE_STRIP=4,ROS3D.MARKER_LINE_LIST=5,ROS3D.MARKER_CUBE_LIST=6,ROS3D.MARKER_SPHERE_LIST=7,ROS3D.MARKER_POINTS=8,ROS3D.MARKER_TEXT_VIEW_FACING=9,ROS3D.MARKER_MESH_RESOURCE=10,ROS3D.MARKER_TRIANGLE_LIST=11,ROS3D.INTERACTIVE_MARKER_KEEP_ALIVE=0,ROS3D.INTERACTIVE_MARKER_POSE_UPDATE=1,ROS3D.INTERACTIVE_MARKER_MENU_SELECT=2,ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK=3,ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN=4,ROS3D.INTERACTIVE_MARKER_MOUSE_UP=5,ROS3D.INTERACTIVE_MARKER_NONE=0,ROS3D.INTERACTIVE_MARKER_MENU=1,ROS3D.INTERACTIVE_MARKER_BUTTON=2,ROS3D.INTERACTIVE_MARKER_MOVE_AXIS=3,ROS3D.INTERACTIVE_MARKER_MOVE_PLANE=4,ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS=5,ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE=6,ROS3D.INTERACTIVE_MARKER_INHERIT=0,ROS3D.INTERACTIVE_MARKER_FIXED=1,ROS3D.INTERACTIVE_MARKER_VIEW_FACING=2,ROS3D.makeColorMaterial=function(a,b,c,d){var e=new THREE.Color;return e.setRGB(a,b,c),.99>=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.y,c.scale.z),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;yg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b=a.target,c=b.getBoundingClientRect(),d=a.clientX-c.left-b.clientLeft+b.scrollLeft,e=a.clientY-c.top-b.clientTop+b.scrollTop,f=2*(d/b.clientWidth)-1,g=2*(-e/b.clientHeight)+1,h=new THREE.Vector3(f,g,.5);this.projector.unprojectVector(h,this.camera);var i=new THREE.Raycaster(this.camera.position.clone(),h.sub(this.camera.position).normalize()),j=i.ray,k={mousePos:new THREE.Vector2(f,g),mouseRay:j,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+b),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",k),this.dragging=!1),this.notify(this.lastTarget,"mouseout",k),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",k),this.dragging=!1),this.notify(this.lastTarget,"touchend",k),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,k),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;b=this.lastTarget;var l=[];if(l=i.intersectObject(this.rootObject,!0),l.length>0?(b=l[0].object,k.intersection=this.lastIntersection=l[0]):b=this.fallbackTarget,b!==this.lastTarget&&a.type.match(/mouse/)){var m=this.notify(b,"mouseover",k);m?this.notify(this.lastTarget,"mouseout",k):(b=this.fallbackTarget,b!==this.lastTarget&&(this.notify(b,"mouseover",k),this.notify(this.lastTarget,"mouseout",k)))}if(b!==this.lastTarget&&a.type.match(/touch/)){var n=this.notify(b,"touchmove",k);n?(this.notify(this.lastTarget,"touchleave",k),this.notify(this.lastTarget,"touchend",k)):(b=this.fallbackTarget,b!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",k),this.notify(this.lastTarget,"touchend",k)))}this.notify(b,a.type,k),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=b},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomOut():i.zoomIn(),this.showAxes()}}function g(a){var b=a.domEvent;switch(b.preventDefault(),console.log(">> button: "+b.button),b.button){case 0:w=v.ROTATE,l.set(b.pageX-window.scrollX,b.pageY-window.scrollY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.pageX-window.scrollX,b.pageY-window.scrollY)}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.pageX-window.scrollX,b.pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.pageX-window.scrollX,b.pageY-window.scrollY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file +},ROS3D.Axes.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Grid=function(a){a=a||{};var b=a.size||50,c=a.color||"#cccccc",d=a.lineWidth||1;THREE.Mesh.call(this,new THREE.PlaneGeometry(b,b,b,b),new THREE.MeshBasicMaterial({color:c,wireframe:!0,wireframeLinewidth:d,transparent:!0}))},ROS3D.Grid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.MeshResource=function(a){var b=this;a=a||{};var c=a.path||"/",d=a.resource;this.warnings=a.warnings,THREE.Object3D.call(this),"/"!==c.substr(c.length-1)&&(this.path+="/");var e=c+d;if(e.substr(-4).toLowerCase(),".dae"===e.substr(-4).toLowerCase()){var f=new ColladaLoader2;f.log=function(a){b.warnings&&console.warn(a)},f.load(e,function(a){if(a.dae.asset.unit){var c=a.dae.asset.unit;a.scene.scale=new THREE.Vector3(c,c,c)}b.add(a.scene)})}},ROS3D.MeshResource.prototype.__proto__=THREE.Object3D.prototype,ROS3D.TriangleList=function(a){a=a||{};var b=a.material||new THREE.MeshBasicMaterial,c=a.vertices,d=a.colors;THREE.Object3D.call(this),b.side=THREE.DoubleSide;var e=new THREE.Geometry;for(f=0;fg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b,c,d=a.target,e=d.getBoundingClientRect();-1!==a.type.indexOf("touch")?(b=a.changedTouches[0].clientX,c=a.changedTouches[0].clientY):(b=a.clientX,c=a.clientY);var f=b-e.left-d.clientLeft+d.scrollLeft,g=c-e.top-d.clientTop+d.scrollTop,h=2*(f/d.clientWidth)-1,i=2*(-g/d.clientHeight)+1,j=new THREE.Vector3(h,i,.5);this.projector.unprojectVector(j,this.camera);var k=new THREE.Raycaster(this.camera.position.clone(),j.sub(this.camera.position).normalize()),l=k.ray,m={mousePos:new THREE.Vector2(h,i),mouseRay:l,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+d),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"mouseout",m),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"touchend",m),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,m),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;d=this.lastTarget;var n=[];if(n=k.intersectObject(this.rootObject,!0),n.length>0?(d=n[0].object,m.intersection=this.lastIntersection=n[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var o=this.notify(d,"mouseover",m);o?this.notify(this.lastTarget,"mouseout",m):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(d,"mouseover",m),this.notify(this.lastTarget,"mouseout",m)))}if(d!==this.lastTarget&&a.type.match(/touch/)){var p=this.notify(d,"touchmove",m);p?(this.notify(this.lastTarget,"touchleave",m),this.notify(this.lastTarget,"touchend",m)):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",m),this.notify(this.lastTarget,"touchend",m)))}this.notify(d,a.type,m),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=d},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomOut():i.zoomIn(),this.showAxes()}}function g(a){var b=a.domEvent;switch(console.log(">> button: "+b.button),b.touches.length){case 1:w=v.ROTATE,l.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY);break;case 2:w=v.ZOOM,o.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY));break;case 3:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s)}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(console.log(w),w===v.ROTATE)m.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY)),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file diff --git a/src/visualization/interaction/MouseHandler.js b/src/visualization/interaction/MouseHandler.js index b69d1292..cb662937 100644 --- a/src/visualization/interaction/MouseHandler.js +++ b/src/visualization/interaction/MouseHandler.js @@ -47,8 +47,18 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { // compute normalized device coords and 3D mouse ray var target = domEvent.target; var rect = target.getBoundingClientRect(); - var left = domEvent.clientX - rect.left - target.clientLeft + target.scrollLeft; - var top = domEvent.clientY - rect.top - target.clientTop + target.scrollTop; + var pos_x, pos_y; + + if(domEvent.type.indexOf('touch') !== -1) { + pos_x = domEvent.changedTouches[0].clientX; + pos_y = domEvent.changedTouches[0].clientY; + } + else { + pos_x = domEvent.clientX; + pos_y = domEvent.clientY; + } + var left = pos_x - rect.left - target.clientLeft + target.scrollLeft; + var top = pos_y - rect.top - target.clientTop + target.scrollTop; var deviceX = left / target.clientWidth * 2 - 1; var deviceY = -top / target.clientHeight * 2 + 1; var vector = new THREE.Vector3(deviceX, deviceY, 0.5); diff --git a/src/visualization/interaction/OrbitControls.js b/src/visualization/interaction/OrbitControls.js index 3d9dd9e7..fdcc1c82 100644 --- a/src/visualization/interaction/OrbitControls.js +++ b/src/visualization/interaction/OrbitControls.js @@ -228,15 +228,17 @@ ROS3D.OrbitControls = function(options) { */ function onTouchDown(event3D) { var event = event3D.domEvent; - event.preventDefault(); - console.log('>> button: ' + event.button); - switch (event.button) { - case 0: + switch (event.touches.length) { + case 1: state = STATE.ROTATE; - rotateStart.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + rotateStart.set(event.changedTouches[0].pageX - window.scrollX, event.changedTouches[0].pageY - window.scrollY); break; - case 1: + case 2: + state = STATE.ZOOM; + zoomStart.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); + break; + case 3: state = STATE.MOVE; moveStartNormal = new THREE.Vector3(0, 0, 1); @@ -248,10 +250,7 @@ ROS3D.OrbitControls = function(options) { moveStartIntersection = intersectViewPlane(event3D.mouseRay, moveStartCenter, moveStartNormal); break; - case 2: - state = STATE.ZOOM; - zoomStart.set(event.pageX - window.scrollX, event.pageY - window.scrollY); - break; + } this.showAxes(); @@ -267,9 +266,10 @@ ROS3D.OrbitControls = function(options) { */ function onTouchMove(event3D) { var event = event3D.domEvent; + console.log(state); if (state === STATE.ROTATE) { - rotateEnd.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + rotateEnd.set(event.changedTouches[0].pageX - window.scrollX, event.changedTouches[0].pageY - window.scrollY); rotateDelta.subVectors(rotateEnd, rotateStart); that.rotateLeft(2 * Math.PI * rotateDelta.x / pixlesPerRound * that.userRotateSpeed); @@ -278,7 +278,7 @@ ROS3D.OrbitControls = function(options) { rotateStart.copy(rotateEnd); this.showAxes(); } else if (state === STATE.ZOOM) { - zoomEnd.set(event.pageX - window.scrollX, event.pageY - window.scrollY); + zoomEnd.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); zoomDelta.subVectors(zoomEnd, zoomStart); if (zoomDelta.y > 0) { From bbce9d253f776e31de6e28ec0c92cc6e8a3856e1 Mon Sep 17 00:00:00 2001 From: KazutoMurase Date: Thu, 8 Aug 2013 13:02:09 +0900 Subject: [PATCH 4/7] fix the initial position for move action --- build/ros3d.js | 28 +++++++++---------- build/ros3d.min.js | 2 +- .../interaction/OrbitControls.js | 28 +++++++++---------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/build/ros3d.js b/build/ros3d.js index 5436615f..b6b26558 100644 --- a/build/ros3d.js +++ b/build/ros3d.js @@ -3026,9 +3026,9 @@ ROS3D.OrbitControls = function(options) { delta = -event.detail; } if (delta > 0) { - that.zoomOut(); - } else { that.zoomIn(); + } else { + that.zoomOut(); } this.showAxes(); @@ -3046,29 +3046,28 @@ ROS3D.OrbitControls = function(options) { case 1: state = STATE.ROTATE; rotateStart.set(event.changedTouches[0].pageX - window.scrollX, event.changedTouches[0].pageY - window.scrollY); - break; - case 2: - state = STATE.ZOOM; - zoomStart.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); - break; - case 3: - state = STATE.MOVE; - + /* ready for move */ moveStartNormal = new THREE.Vector3(0, 0, 1); var rMat = new THREE.Matrix4().extractRotation(this.camera.matrix); moveStartNormal.applyMatrix4(rMat); - moveStartCenter = that.center.clone(); moveStartPosition = that.camera.position.clone(); moveStartIntersection = intersectViewPlane(event3D.mouseRay, moveStartCenter, moveStartNormal); + + break; + case 2: + state = STATE.ZOOM; + zoomStart.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); break; + case 3: + state = STATE.MOVE; + break; } this.showAxes(); - //onMouseDown(event); event.preventDefault(); } @@ -3095,9 +3094,9 @@ ROS3D.OrbitControls = function(options) { zoomDelta.subVectors(zoomEnd, zoomStart); if (zoomDelta.y > 0) { - that.zoomIn(); - } else { that.zoomOut(); + } else { + that.zoomIn(); } zoomStart.copy(zoomEnd); @@ -3120,7 +3119,6 @@ ROS3D.OrbitControls = function(options) { this.showAxes(); } - //onMouseMove(event); event.preventDefault(); } diff --git a/build/ros3d.min.js b/build/ros3d.min.js index 43882584..ba4ed394 100644 --- a/build/ros3d.min.js +++ b/build/ros3d.min.js @@ -1,2 +1,2 @@ var ROS3D=ROS3D||{REVISION:"6"};ROS3D.MARKER_ARROW=0,ROS3D.MARKER_CUBE=1,ROS3D.MARKER_SPHERE=2,ROS3D.MARKER_CYLINDER=3,ROS3D.MARKER_LINE_STRIP=4,ROS3D.MARKER_LINE_LIST=5,ROS3D.MARKER_CUBE_LIST=6,ROS3D.MARKER_SPHERE_LIST=7,ROS3D.MARKER_POINTS=8,ROS3D.MARKER_TEXT_VIEW_FACING=9,ROS3D.MARKER_MESH_RESOURCE=10,ROS3D.MARKER_TRIANGLE_LIST=11,ROS3D.INTERACTIVE_MARKER_KEEP_ALIVE=0,ROS3D.INTERACTIVE_MARKER_POSE_UPDATE=1,ROS3D.INTERACTIVE_MARKER_MENU_SELECT=2,ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK=3,ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN=4,ROS3D.INTERACTIVE_MARKER_MOUSE_UP=5,ROS3D.INTERACTIVE_MARKER_NONE=0,ROS3D.INTERACTIVE_MARKER_MENU=1,ROS3D.INTERACTIVE_MARKER_BUTTON=2,ROS3D.INTERACTIVE_MARKER_MOVE_AXIS=3,ROS3D.INTERACTIVE_MARKER_MOVE_PLANE=4,ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS=5,ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE=6,ROS3D.INTERACTIVE_MARKER_INHERIT=0,ROS3D.INTERACTIVE_MARKER_FIXED=1,ROS3D.INTERACTIVE_MARKER_VIEW_FACING=2,ROS3D.makeColorMaterial=function(a,b,c,d){var e=new THREE.Color;return e.setRGB(a,b,c),.99>=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.y,c.scale.z),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;yg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b,c,d=a.target,e=d.getBoundingClientRect();-1!==a.type.indexOf("touch")?(b=a.changedTouches[0].clientX,c=a.changedTouches[0].clientY):(b=a.clientX,c=a.clientY);var f=b-e.left-d.clientLeft+d.scrollLeft,g=c-e.top-d.clientTop+d.scrollTop,h=2*(f/d.clientWidth)-1,i=2*(-g/d.clientHeight)+1,j=new THREE.Vector3(h,i,.5);this.projector.unprojectVector(j,this.camera);var k=new THREE.Raycaster(this.camera.position.clone(),j.sub(this.camera.position).normalize()),l=k.ray,m={mousePos:new THREE.Vector2(h,i),mouseRay:l,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+d),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"mouseout",m),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"touchend",m),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,m),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;d=this.lastTarget;var n=[];if(n=k.intersectObject(this.rootObject,!0),n.length>0?(d=n[0].object,m.intersection=this.lastIntersection=n[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var o=this.notify(d,"mouseover",m);o?this.notify(this.lastTarget,"mouseout",m):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(d,"mouseover",m),this.notify(this.lastTarget,"mouseout",m)))}if(d!==this.lastTarget&&a.type.match(/touch/)){var p=this.notify(d,"touchmove",m);p?(this.notify(this.lastTarget,"touchleave",m),this.notify(this.lastTarget,"touchend",m)):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",m),this.notify(this.lastTarget,"touchend",m)))}this.notify(d,a.type,m),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=d},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomOut():i.zoomIn(),this.showAxes()}}function g(a){var b=a.domEvent;switch(console.log(">> button: "+b.button),b.touches.length){case 1:w=v.ROTATE,l.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY);break;case 2:w=v.ZOOM,o.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY));break;case 3:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s)}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(console.log(w),w===v.ROTATE)m.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY)),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file +},ROS3D.Axes.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Grid=function(a){a=a||{};var b=a.size||50,c=a.color||"#cccccc",d=a.lineWidth||1;THREE.Mesh.call(this,new THREE.PlaneGeometry(b,b,b,b),new THREE.MeshBasicMaterial({color:c,wireframe:!0,wireframeLinewidth:d,transparent:!0}))},ROS3D.Grid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.MeshResource=function(a){var b=this;a=a||{};var c=a.path||"/",d=a.resource;this.warnings=a.warnings,THREE.Object3D.call(this),"/"!==c.substr(c.length-1)&&(this.path+="/");var e=c+d;if(e.substr(-4).toLowerCase(),".dae"===e.substr(-4).toLowerCase()){var f=new ColladaLoader2;f.log=function(a){b.warnings&&console.warn(a)},f.load(e,function(a){if(a.dae.asset.unit){var c=a.dae.asset.unit;a.scene.scale=new THREE.Vector3(c,c,c)}b.add(a.scene)})}},ROS3D.MeshResource.prototype.__proto__=THREE.Object3D.prototype,ROS3D.TriangleList=function(a){a=a||{};var b=a.material||new THREE.MeshBasicMaterial,c=a.vertices,d=a.colors;THREE.Object3D.call(this),b.side=THREE.DoubleSide;var e=new THREE.Geometry;for(f=0;fg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b,c,d=a.target,e=d.getBoundingClientRect();-1!==a.type.indexOf("touch")?(b=a.changedTouches[0].clientX,c=a.changedTouches[0].clientY):(b=a.clientX,c=a.clientY);var f=b-e.left-d.clientLeft+d.scrollLeft,g=c-e.top-d.clientTop+d.scrollTop,h=2*(f/d.clientWidth)-1,i=2*(-g/d.clientHeight)+1,j=new THREE.Vector3(h,i,.5);this.projector.unprojectVector(j,this.camera);var k=new THREE.Raycaster(this.camera.position.clone(),j.sub(this.camera.position).normalize()),l=k.ray,m={mousePos:new THREE.Vector2(h,i),mouseRay:l,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+d),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"mouseout",m),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"touchend",m),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,m),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;d=this.lastTarget;var n=[];if(n=k.intersectObject(this.rootObject,!0),n.length>0?(d=n[0].object,m.intersection=this.lastIntersection=n[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var o=this.notify(d,"mouseover",m);o?this.notify(this.lastTarget,"mouseout",m):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(d,"mouseover",m),this.notify(this.lastTarget,"mouseout",m)))}if(d!==this.lastTarget&&a.type.match(/touch/)){var p=this.notify(d,"touchmove",m);p?(this.notify(this.lastTarget,"touchleave",m),this.notify(this.lastTarget,"touchend",m)):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",m),this.notify(this.lastTarget,"touchend",m)))}this.notify(d,a.type,m),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=d},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomIn():i.zoomOut(),this.showAxes()}}function g(a){var b=a.domEvent;switch(console.log(">> button: "+b.button),b.touches.length){case 1:w=v.ROTATE,l.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY));break;case 3:w=v.MOVE}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(console.log(w),w===v.ROTATE)m.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY)),q.subVectors(p,o),q.y>0?i.zoomOut():i.zoomIn(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file diff --git a/src/visualization/interaction/OrbitControls.js b/src/visualization/interaction/OrbitControls.js index fdcc1c82..fef6125e 100644 --- a/src/visualization/interaction/OrbitControls.js +++ b/src/visualization/interaction/OrbitControls.js @@ -213,9 +213,9 @@ ROS3D.OrbitControls = function(options) { delta = -event.detail; } if (delta > 0) { - that.zoomOut(); - } else { that.zoomIn(); + } else { + that.zoomOut(); } this.showAxes(); @@ -233,29 +233,28 @@ ROS3D.OrbitControls = function(options) { case 1: state = STATE.ROTATE; rotateStart.set(event.changedTouches[0].pageX - window.scrollX, event.changedTouches[0].pageY - window.scrollY); - break; - case 2: - state = STATE.ZOOM; - zoomStart.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); - break; - case 3: - state = STATE.MOVE; - + /* ready for move */ moveStartNormal = new THREE.Vector3(0, 0, 1); var rMat = new THREE.Matrix4().extractRotation(this.camera.matrix); moveStartNormal.applyMatrix4(rMat); - moveStartCenter = that.center.clone(); moveStartPosition = that.camera.position.clone(); moveStartIntersection = intersectViewPlane(event3D.mouseRay, moveStartCenter, moveStartNormal); + + break; + case 2: + state = STATE.ZOOM; + zoomStart.set((event.changedTouches[0].pageX - event.changedTouches[1].pageX)*(event.changedTouches[0].pageX - event.changedTouches[1].pageX), (event.changedTouches[0].pageY - event.changedTouches[1].pageY)*(event.changedTouches[0].pageY - event.changedTouches[1].pageY)); break; + case 3: + state = STATE.MOVE; + break; } this.showAxes(); - //onMouseDown(event); event.preventDefault(); } @@ -282,9 +281,9 @@ ROS3D.OrbitControls = function(options) { zoomDelta.subVectors(zoomEnd, zoomStart); if (zoomDelta.y > 0) { - that.zoomIn(); - } else { that.zoomOut(); + } else { + that.zoomIn(); } zoomStart.copy(zoomEnd); @@ -307,7 +306,6 @@ ROS3D.OrbitControls = function(options) { this.showAxes(); } - //onMouseMove(event); event.preventDefault(); } From a556d6fe26bb1a49a11feae404609be84020b784 Mon Sep 17 00:00:00 2001 From: KazutoMurase Date: Thu, 8 Aug 2013 22:38:37 +0900 Subject: [PATCH 5/7] fix the scale of cylinder marker --- build/ros3d.js | 2 +- build/ros3d.min.js | 2 +- src/markers/Marker.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/ros3d.js b/build/ros3d.js index b6b26558..6576a18f 100644 --- a/build/ros3d.js +++ b/build/ros3d.js @@ -1713,7 +1713,7 @@ ROS3D.Marker = function(options) { var cylinderMesh = new THREE.Mesh(cylinderGeom, colorMaterial); cylinderMesh.useQuaternion = true; cylinderMesh.quaternion.setFromAxisAngle(new THREE.Vector3(1, 0, 0), Math.PI * 0.5); - cylinderMesh.scale = new THREE.Vector3(message.scale.x, message.scale.y, message.scale.z); + cylinderMesh.scale = new THREE.Vector3(message.scale.x, message.scale.z, message.scale.y); this.add(cylinderMesh); break; case ROS3D.MARKER_CUBE_LIST: diff --git a/build/ros3d.min.js b/build/ros3d.min.js index ba4ed394..efc5ef93 100644 --- a/build/ros3d.min.js +++ b/build/ros3d.min.js @@ -1,2 +1,2 @@ -var ROS3D=ROS3D||{REVISION:"6"};ROS3D.MARKER_ARROW=0,ROS3D.MARKER_CUBE=1,ROS3D.MARKER_SPHERE=2,ROS3D.MARKER_CYLINDER=3,ROS3D.MARKER_LINE_STRIP=4,ROS3D.MARKER_LINE_LIST=5,ROS3D.MARKER_CUBE_LIST=6,ROS3D.MARKER_SPHERE_LIST=7,ROS3D.MARKER_POINTS=8,ROS3D.MARKER_TEXT_VIEW_FACING=9,ROS3D.MARKER_MESH_RESOURCE=10,ROS3D.MARKER_TRIANGLE_LIST=11,ROS3D.INTERACTIVE_MARKER_KEEP_ALIVE=0,ROS3D.INTERACTIVE_MARKER_POSE_UPDATE=1,ROS3D.INTERACTIVE_MARKER_MENU_SELECT=2,ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK=3,ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN=4,ROS3D.INTERACTIVE_MARKER_MOUSE_UP=5,ROS3D.INTERACTIVE_MARKER_NONE=0,ROS3D.INTERACTIVE_MARKER_MENU=1,ROS3D.INTERACTIVE_MARKER_BUTTON=2,ROS3D.INTERACTIVE_MARKER_MOVE_AXIS=3,ROS3D.INTERACTIVE_MARKER_MOVE_PLANE=4,ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS=5,ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE=6,ROS3D.INTERACTIVE_MARKER_INHERIT=0,ROS3D.INTERACTIVE_MARKER_FIXED=1,ROS3D.INTERACTIVE_MARKER_VIEW_FACING=2,ROS3D.makeColorMaterial=function(a,b,c,d){var e=new THREE.Color;return e.setRGB(a,b,c),.99>=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.y,c.scale.z),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;y=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.z,c.scale.y),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;yg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b,c,d=a.target,e=d.getBoundingClientRect();-1!==a.type.indexOf("touch")?(b=a.changedTouches[0].clientX,c=a.changedTouches[0].clientY):(b=a.clientX,c=a.clientY);var f=b-e.left-d.clientLeft+d.scrollLeft,g=c-e.top-d.clientTop+d.scrollTop,h=2*(f/d.clientWidth)-1,i=2*(-g/d.clientHeight)+1,j=new THREE.Vector3(h,i,.5);this.projector.unprojectVector(j,this.camera);var k=new THREE.Raycaster(this.camera.position.clone(),j.sub(this.camera.position).normalize()),l=k.ray,m={mousePos:new THREE.Vector2(h,i),mouseRay:l,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+d),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"mouseout",m),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"touchend",m),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,m),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;d=this.lastTarget;var n=[];if(n=k.intersectObject(this.rootObject,!0),n.length>0?(d=n[0].object,m.intersection=this.lastIntersection=n[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var o=this.notify(d,"mouseover",m);o?this.notify(this.lastTarget,"mouseout",m):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(d,"mouseover",m),this.notify(this.lastTarget,"mouseout",m)))}if(d!==this.lastTarget&&a.type.match(/touch/)){var p=this.notify(d,"touchmove",m);p?(this.notify(this.lastTarget,"touchleave",m),this.notify(this.lastTarget,"touchend",m)):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",m),this.notify(this.lastTarget,"touchend",m)))}this.notify(d,a.type,m),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=d},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomIn():i.zoomOut(),this.showAxes()}}function g(a){var b=a.domEvent;switch(console.log(">> button: "+b.button),b.touches.length){case 1:w=v.ROTATE,l.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY));break;case 3:w=v.MOVE}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(console.log(w),w===v.ROTATE)m.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY)),q.subVectors(p,o),q.y>0?i.zoomOut():i.zoomIn(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file diff --git a/src/markers/Marker.js b/src/markers/Marker.js index 35c5caf8..8112386a 100644 --- a/src/markers/Marker.js +++ b/src/markers/Marker.js @@ -85,7 +85,7 @@ ROS3D.Marker = function(options) { var cylinderMesh = new THREE.Mesh(cylinderGeom, colorMaterial); cylinderMesh.useQuaternion = true; cylinderMesh.quaternion.setFromAxisAngle(new THREE.Vector3(1, 0, 0), Math.PI * 0.5); - cylinderMesh.scale = new THREE.Vector3(message.scale.x, message.scale.y, message.scale.z); + cylinderMesh.scale = new THREE.Vector3(message.scale.x, message.scale.z, message.scale.y); this.add(cylinderMesh); break; case ROS3D.MARKER_CUBE_LIST: From bd1752d1b49658c5460758a7cc004a3e77e8012c Mon Sep 17 00:00:00 2001 From: KazutoMurase Date: Fri, 9 Aug 2013 00:43:02 +0900 Subject: [PATCH 6/7] fixed the bug of touch event of interactiver marker --- build/ros3d.js | 7 +++++-- build/ros3d.min.js | 4 ++-- src/visualization/interaction/MouseHandler.js | 2 +- src/visualization/interaction/OrbitControls.js | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/build/ros3d.js b/build/ros3d.js index 6576a18f..23aae55f 100644 --- a/build/ros3d.js +++ b/build/ros3d.js @@ -1039,6 +1039,7 @@ ROS3D.InteractiveMarkerControl = function(options) { // touch support this.addEventListener('touchstart', function(event3d) { + console.log('touch end start start '); console.log(event3d.domEvent); if (event3d.domEvent.touches.length === 1) { event3d.type = 'mousedown'; @@ -1047,6 +1048,7 @@ ROS3D.InteractiveMarkerControl = function(options) { } }); this.addEventListener('touchmove', function(event3d) { + console.log('touch move move move '); if (event3d.domEvent.touches.length === 1) { console.log(event3d.domEvent); event3d.type = 'mousemove'; @@ -1055,6 +1057,7 @@ ROS3D.InteractiveMarkerControl = function(options) { } }); this.addEventListener('touchend', function(event3d) { + console.log('touch end end end '); if (event3d.domEvent.touches.length === 0) { event3d.domEvent.button = 0; event3d.type = 'mouseup'; @@ -2754,7 +2757,7 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { // if the finger moves from one object to another (or from/to the 'null' object), notify both if (target !== this.lastTarget && domEvent.type.match(/touch/)) { - var toucheventAccepted = this.notify(target, 'touchmove', event3D); + var toucheventAccepted = this.notify(target, domEvent.type, event3D); if (toucheventAccepted) { this.notify(this.lastTarget, 'touchleave', event3D); this.notify(this.lastTarget, 'touchend', event3D); @@ -3003,7 +3006,6 @@ ROS3D.OrbitControls = function(options) { if (!that.userRotate) { return; } - state = STATE.NONE; } @@ -3128,6 +3130,7 @@ ROS3D.OrbitControls = function(options) { this.addEventListener('mousemove', onMouseMove); this.addEventListener('touchstart', onTouchDown); this.addEventListener('touchmove', onTouchMove); + this.addEventListener('touchend', onMouseUp); // Chrome/Firefox have different events here this.addEventListener('mousewheel', onMouseWheel); this.addEventListener('DOMMouseScroll', onMouseWheel); diff --git a/build/ros3d.min.js b/build/ros3d.min.js index efc5ef93..fbac5ee5 100644 --- a/build/ros3d.min.js +++ b/build/ros3d.min.js @@ -1,2 +1,2 @@ -var ROS3D=ROS3D||{REVISION:"6"};ROS3D.MARKER_ARROW=0,ROS3D.MARKER_CUBE=1,ROS3D.MARKER_SPHERE=2,ROS3D.MARKER_CYLINDER=3,ROS3D.MARKER_LINE_STRIP=4,ROS3D.MARKER_LINE_LIST=5,ROS3D.MARKER_CUBE_LIST=6,ROS3D.MARKER_SPHERE_LIST=7,ROS3D.MARKER_POINTS=8,ROS3D.MARKER_TEXT_VIEW_FACING=9,ROS3D.MARKER_MESH_RESOURCE=10,ROS3D.MARKER_TRIANGLE_LIST=11,ROS3D.INTERACTIVE_MARKER_KEEP_ALIVE=0,ROS3D.INTERACTIVE_MARKER_POSE_UPDATE=1,ROS3D.INTERACTIVE_MARKER_MENU_SELECT=2,ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK=3,ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN=4,ROS3D.INTERACTIVE_MARKER_MOUSE_UP=5,ROS3D.INTERACTIVE_MARKER_NONE=0,ROS3D.INTERACTIVE_MARKER_MENU=1,ROS3D.INTERACTIVE_MARKER_BUTTON=2,ROS3D.INTERACTIVE_MARKER_MOVE_AXIS=3,ROS3D.INTERACTIVE_MARKER_MOVE_PLANE=4,ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS=5,ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE=6,ROS3D.INTERACTIVE_MARKER_INHERIT=0,ROS3D.INTERACTIVE_MARKER_FIXED=1,ROS3D.INTERACTIVE_MARKER_VIEW_FACING=2,ROS3D.makeColorMaterial=function(a,b,c,d){var e=new THREE.Color;return e.setRGB(a,b,c),.99>=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.z,c.scale.y),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;yg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b,c,d=a.target,e=d.getBoundingClientRect();-1!==a.type.indexOf("touch")?(b=a.changedTouches[0].clientX,c=a.changedTouches[0].clientY):(b=a.clientX,c=a.clientY);var f=b-e.left-d.clientLeft+d.scrollLeft,g=c-e.top-d.clientTop+d.scrollTop,h=2*(f/d.clientWidth)-1,i=2*(-g/d.clientHeight)+1,j=new THREE.Vector3(h,i,.5);this.projector.unprojectVector(j,this.camera);var k=new THREE.Raycaster(this.camera.position.clone(),j.sub(this.camera.position).normalize()),l=k.ray,m={mousePos:new THREE.Vector2(h,i),mouseRay:l,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+d),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"mouseout",m),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"touchend",m),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,m),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;d=this.lastTarget;var n=[];if(n=k.intersectObject(this.rootObject,!0),n.length>0?(d=n[0].object,m.intersection=this.lastIntersection=n[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var o=this.notify(d,"mouseover",m);o?this.notify(this.lastTarget,"mouseout",m):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(d,"mouseover",m),this.notify(this.lastTarget,"mouseout",m)))}if(d!==this.lastTarget&&a.type.match(/touch/)){var p=this.notify(d,"touchmove",m);p?(this.notify(this.lastTarget,"touchleave",m),this.notify(this.lastTarget,"touchend",m)):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",m),this.notify(this.lastTarget,"touchend",m)))}this.notify(d,a.type,m),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=d},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomIn():i.zoomOut(),this.showAxes()}}function g(a){var b=a.domEvent;switch(console.log(">> button: "+b.button),b.touches.length){case 1:w=v.ROTATE,l.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY));break;case 3:w=v.MOVE}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(console.log(w),w===v.ROTATE)m.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY)),q.subVectors(p,o),q.y>0?i.zoomOut():i.zoomIn(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file +var ROS3D=ROS3D||{REVISION:"6"};ROS3D.MARKER_ARROW=0,ROS3D.MARKER_CUBE=1,ROS3D.MARKER_SPHERE=2,ROS3D.MARKER_CYLINDER=3,ROS3D.MARKER_LINE_STRIP=4,ROS3D.MARKER_LINE_LIST=5,ROS3D.MARKER_CUBE_LIST=6,ROS3D.MARKER_SPHERE_LIST=7,ROS3D.MARKER_POINTS=8,ROS3D.MARKER_TEXT_VIEW_FACING=9,ROS3D.MARKER_MESH_RESOURCE=10,ROS3D.MARKER_TRIANGLE_LIST=11,ROS3D.INTERACTIVE_MARKER_KEEP_ALIVE=0,ROS3D.INTERACTIVE_MARKER_POSE_UPDATE=1,ROS3D.INTERACTIVE_MARKER_MENU_SELECT=2,ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK=3,ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN=4,ROS3D.INTERACTIVE_MARKER_MOUSE_UP=5,ROS3D.INTERACTIVE_MARKER_NONE=0,ROS3D.INTERACTIVE_MARKER_MENU=1,ROS3D.INTERACTIVE_MARKER_BUTTON=2,ROS3D.INTERACTIVE_MARKER_MOVE_AXIS=3,ROS3D.INTERACTIVE_MARKER_MOVE_PLANE=4,ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS=5,ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE=6,ROS3D.INTERACTIVE_MARKER_INHERIT=0,ROS3D.INTERACTIVE_MARKER_FIXED=1,ROS3D.INTERACTIVE_MARKER_VIEW_FACING=2,ROS3D.makeColorMaterial=function(a,b,c,d){var e=new THREE.Color;return e.setRGB(a,b,c),.99>=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log("touch end start start "),console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){console.log("touch move move move "),1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){console.log("touch end end end "),0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.z,c.scale.y),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;yg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b,c,d=a.target,e=d.getBoundingClientRect();-1!==a.type.indexOf("touch")?(b=a.changedTouches[0].clientX,c=a.changedTouches[0].clientY):(b=a.clientX,c=a.clientY);var f=b-e.left-d.clientLeft+d.scrollLeft,g=c-e.top-d.clientTop+d.scrollTop,h=2*(f/d.clientWidth)-1,i=2*(-g/d.clientHeight)+1,j=new THREE.Vector3(h,i,.5);this.projector.unprojectVector(j,this.camera);var k=new THREE.Raycaster(this.camera.position.clone(),j.sub(this.camera.position).normalize()),l=k.ray,m={mousePos:new THREE.Vector2(h,i),mouseRay:l,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+d),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"mouseout",m),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"touchend",m),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,m),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;d=this.lastTarget;var n=[];if(n=k.intersectObject(this.rootObject,!0),n.length>0?(d=n[0].object,m.intersection=this.lastIntersection=n[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var o=this.notify(d,"mouseover",m);o?this.notify(this.lastTarget,"mouseout",m):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(d,"mouseover",m),this.notify(this.lastTarget,"mouseout",m)))}if(d!==this.lastTarget&&a.type.match(/touch/)){var p=this.notify(d,a.type,m);p?(this.notify(this.lastTarget,"touchleave",m),this.notify(this.lastTarget,"touchend",m)):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",m),this.notify(this.lastTarget,"touchend",m)))}this.notify(d,a.type,m),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=d},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomIn():i.zoomOut(),this.showAxes()}}function g(a){var b=a.domEvent;switch(console.log(">> button: "+b.button),b.touches.length){case 1:w=v.ROTATE,l.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY));break;case 3:w=v.MOVE}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(console.log(w),w===v.ROTATE)m.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY)),q.subVectors(p,o),q.y>0?i.zoomOut():i.zoomIn(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("touchend",e),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file diff --git a/src/visualization/interaction/MouseHandler.js b/src/visualization/interaction/MouseHandler.js index cb662937..037bac8a 100644 --- a/src/visualization/interaction/MouseHandler.js +++ b/src/visualization/interaction/MouseHandler.js @@ -143,7 +143,7 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { // if the finger moves from one object to another (or from/to the 'null' object), notify both if (target !== this.lastTarget && domEvent.type.match(/touch/)) { - var toucheventAccepted = this.notify(target, 'touchmove', event3D); + var toucheventAccepted = this.notify(target, domEvent.type, event3D); if (toucheventAccepted) { this.notify(this.lastTarget, 'touchleave', event3D); this.notify(this.lastTarget, 'touchend', event3D); diff --git a/src/visualization/interaction/OrbitControls.js b/src/visualization/interaction/OrbitControls.js index fef6125e..95059390 100644 --- a/src/visualization/interaction/OrbitControls.js +++ b/src/visualization/interaction/OrbitControls.js @@ -190,7 +190,6 @@ ROS3D.OrbitControls = function(options) { if (!that.userRotate) { return; } - state = STATE.NONE; } @@ -315,6 +314,7 @@ ROS3D.OrbitControls = function(options) { this.addEventListener('mousemove', onMouseMove); this.addEventListener('touchstart', onTouchDown); this.addEventListener('touchmove', onTouchMove); + this.addEventListener('touchend', onMouseUp); // Chrome/Firefox have different events here this.addEventListener('mousewheel', onMouseWheel); this.addEventListener('DOMMouseScroll', onMouseWheel); From 1020efef8436760411c7a7f017efd46533007535 Mon Sep 17 00:00:00 2001 From: KazutoMurase Date: Fri, 23 Aug 2013 21:08:17 +0900 Subject: [PATCH 7/7] delete some debug lines --- build/ros3d.js | 10 +--------- build/ros3d.min.js | 4 ++-- src/visualization/interaction/MouseHandler.js | 6 ------ src/visualization/interaction/OrbitControls.js | 1 + 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/build/ros3d.js b/build/ros3d.js index 23aae55f..26c495c3 100644 --- a/build/ros3d.js +++ b/build/ros3d.js @@ -1039,7 +1039,6 @@ ROS3D.InteractiveMarkerControl = function(options) { // touch support this.addEventListener('touchstart', function(event3d) { - console.log('touch end start start '); console.log(event3d.domEvent); if (event3d.domEvent.touches.length === 1) { event3d.type = 'mousedown'; @@ -1048,7 +1047,6 @@ ROS3D.InteractiveMarkerControl = function(options) { } }); this.addEventListener('touchmove', function(event3d) { - console.log('touch move move move '); if (event3d.domEvent.touches.length === 1) { console.log(event3d.domEvent); event3d.type = 'mousemove'; @@ -1057,7 +1055,6 @@ ROS3D.InteractiveMarkerControl = function(options) { } }); this.addEventListener('touchend', function(event3d) { - console.log('touch end end end '); if (event3d.domEvent.touches.length === 0) { event3d.domEvent.button = 0; event3d.type = 'mouseup'; @@ -2691,12 +2688,6 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { intersection : this.lastIntersection }; - console.log('------------------------------------'); - console.log(domEvent.type); - console.log(' Dragging?: ' + this.dragging); - console.log(' lastTarget: ' + this.lastTarget); - console.log(' Target: ' + target); - // if the mouse leaves the dom element, stop everything if (domEvent.type === 'mouseout') { if (this.dragging) { @@ -3006,6 +2997,7 @@ ROS3D.OrbitControls = function(options) { if (!that.userRotate) { return; } + state = STATE.NONE; } diff --git a/build/ros3d.min.js b/build/ros3d.min.js index fbac5ee5..827b6f6b 100644 --- a/build/ros3d.min.js +++ b/build/ros3d.min.js @@ -1,2 +1,2 @@ -var ROS3D=ROS3D||{REVISION:"6"};ROS3D.MARKER_ARROW=0,ROS3D.MARKER_CUBE=1,ROS3D.MARKER_SPHERE=2,ROS3D.MARKER_CYLINDER=3,ROS3D.MARKER_LINE_STRIP=4,ROS3D.MARKER_LINE_LIST=5,ROS3D.MARKER_CUBE_LIST=6,ROS3D.MARKER_SPHERE_LIST=7,ROS3D.MARKER_POINTS=8,ROS3D.MARKER_TEXT_VIEW_FACING=9,ROS3D.MARKER_MESH_RESOURCE=10,ROS3D.MARKER_TRIANGLE_LIST=11,ROS3D.INTERACTIVE_MARKER_KEEP_ALIVE=0,ROS3D.INTERACTIVE_MARKER_POSE_UPDATE=1,ROS3D.INTERACTIVE_MARKER_MENU_SELECT=2,ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK=3,ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN=4,ROS3D.INTERACTIVE_MARKER_MOUSE_UP=5,ROS3D.INTERACTIVE_MARKER_NONE=0,ROS3D.INTERACTIVE_MARKER_MENU=1,ROS3D.INTERACTIVE_MARKER_BUTTON=2,ROS3D.INTERACTIVE_MARKER_MOVE_AXIS=3,ROS3D.INTERACTIVE_MARKER_MOVE_PLANE=4,ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS=5,ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE=6,ROS3D.INTERACTIVE_MARKER_INHERIT=0,ROS3D.INTERACTIVE_MARKER_FIXED=1,ROS3D.INTERACTIVE_MARKER_VIEW_FACING=2,ROS3D.makeColorMaterial=function(a,b,c,d){var e=new THREE.Color;return e.setRGB(a,b,c),.99>=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log("touch end start start "),console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){console.log("touch move move move "),1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){console.log("touch end end end "),0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.z,c.scale.y),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;yg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b,c,d=a.target,e=d.getBoundingClientRect();-1!==a.type.indexOf("touch")?(b=a.changedTouches[0].clientX,c=a.changedTouches[0].clientY):(b=a.clientX,c=a.clientY);var f=b-e.left-d.clientLeft+d.scrollLeft,g=c-e.top-d.clientTop+d.scrollTop,h=2*(f/d.clientWidth)-1,i=2*(-g/d.clientHeight)+1,j=new THREE.Vector3(h,i,.5);this.projector.unprojectVector(j,this.camera);var k=new THREE.Raycaster(this.camera.position.clone(),j.sub(this.camera.position).normalize()),l=k.ray,m={mousePos:new THREE.Vector2(h,i),mouseRay:l,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if(console.log("------------------------------------"),console.log(a.type),console.log(" Dragging?: "+this.dragging),console.log(" lastTarget: "+this.lastTarget),console.log(" Target: "+d),"mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"mouseout",m),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"touchend",m),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,m),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;d=this.lastTarget;var n=[];if(n=k.intersectObject(this.rootObject,!0),n.length>0?(d=n[0].object,m.intersection=this.lastIntersection=n[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var o=this.notify(d,"mouseover",m);o?this.notify(this.lastTarget,"mouseout",m):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(d,"mouseover",m),this.notify(this.lastTarget,"mouseout",m)))}if(d!==this.lastTarget&&a.type.match(/touch/)){var p=this.notify(d,a.type,m);p?(this.notify(this.lastTarget,"touchleave",m),this.notify(this.lastTarget,"touchend",m)):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",m),this.notify(this.lastTarget,"touchend",m)))}this.notify(d,a.type,m),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=d},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomIn():i.zoomOut(),this.showAxes()}}function g(a){var b=a.domEvent;switch(console.log(">> button: "+b.button),b.touches.length){case 1:w=v.ROTATE,l.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY));break;case 3:w=v.MOVE}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(console.log(w),w===v.ROTATE)m.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY)),q.subVectors(p,o),q.y>0?i.zoomOut():i.zoomIn(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("touchend",e),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file +var ROS3D=ROS3D||{REVISION:"6"};ROS3D.MARKER_ARROW=0,ROS3D.MARKER_CUBE=1,ROS3D.MARKER_SPHERE=2,ROS3D.MARKER_CYLINDER=3,ROS3D.MARKER_LINE_STRIP=4,ROS3D.MARKER_LINE_LIST=5,ROS3D.MARKER_CUBE_LIST=6,ROS3D.MARKER_SPHERE_LIST=7,ROS3D.MARKER_POINTS=8,ROS3D.MARKER_TEXT_VIEW_FACING=9,ROS3D.MARKER_MESH_RESOURCE=10,ROS3D.MARKER_TRIANGLE_LIST=11,ROS3D.INTERACTIVE_MARKER_KEEP_ALIVE=0,ROS3D.INTERACTIVE_MARKER_POSE_UPDATE=1,ROS3D.INTERACTIVE_MARKER_MENU_SELECT=2,ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK=3,ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN=4,ROS3D.INTERACTIVE_MARKER_MOUSE_UP=5,ROS3D.INTERACTIVE_MARKER_NONE=0,ROS3D.INTERACTIVE_MARKER_MENU=1,ROS3D.INTERACTIVE_MARKER_BUTTON=2,ROS3D.INTERACTIVE_MARKER_MOVE_AXIS=3,ROS3D.INTERACTIVE_MARKER_MOVE_PLANE=4,ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS=5,ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE=6,ROS3D.INTERACTIVE_MARKER_INHERIT=0,ROS3D.INTERACTIVE_MARKER_FIXED=1,ROS3D.INTERACTIVE_MARKER_VIEW_FACING=2,ROS3D.makeColorMaterial=function(a,b,c,d){var e=new THREE.Color;return e.setRGB(a,b,c),.99>=d?new THREE.MeshBasicMaterial({color:e.getHex(),opacity:d+.1,transparent:!0,depthWrite:!0,blendSrc:THREE.SrcAlphaFactor,blendDst:THREE.OneMinusSrcAlphaFactor,blendEquation:THREE.ReverseSubtractEquation,blending:THREE.NormalBlending}):new THREE.MeshLambertMaterial({color:e.getHex(),opacity:d,blending:THREE.NormalBlending})},ROS3D.intersectPlane=function(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0.99)"," {"," vec4 depthColor2 = texture2D( map, vUv2 );"," float depth2 = ( depthColor2.r + depthColor2.g + depthColor2.b ) / 3.0 ;"," depth = 0.99+depth2;"," }"," "," return depth;"," }","","float median(float a, float b, float c)"," {"," float r=a;"," "," if ( (a0.5) || (vUvP.y<0.5) || (vUvP.y>0.0))"," {"," vec2 smp = decodeDepth(vec2(position.x, position.y));"," float depth = smp.x;"," depthVariance = smp.y;"," "," float z = -depth;"," "," pos = vec4("," ( position.x / width - 0.5 ) * z * (1000.0/focallength) * -1.0,"," ( position.y / height - 0.5 ) * z * (1000.0/focallength),"," (- z + zOffset / 1000.0) * 2.0,"," 1.0);"," "," vec2 maskP = vec2( position.x / (width*2.0), position.y / (height*2.0) );"," vec4 maskColor = texture2D( map, maskP );"," maskVal = ( maskColor.r + maskColor.g + maskColor.b ) / 3.0 ;"," }"," "," gl_PointSize = pointSize;"," gl_Position = projectionMatrix * modelViewMatrix * pos;"," ","}"].join("\n"),this.fragment_shader=["uniform sampler2D map;","uniform float varianceThreshold;","uniform float whiteness;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","","void main() {"," "," vec4 color;"," "," if ( (depthVariance>varianceThreshold) || (maskVal>0.5) ||(vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>1.0))"," { "," discard;"," }"," else "," {"," color = texture2D( map, colorP );"," "," float fader = whiteness /100.0;"," "," color.r = color.r * (1.0-fader)+ fader;"," "," color.g = color.g * (1.0-fader)+ fader;"," "," color.b = color.b * (1.0-fader)+ fader;"," "," color.a = 1.0;//smoothstep( 20000.0, -20000.0, gl_FragCoord.z / gl_FragCoord.w );"," }"," "," gl_FragColor = vec4( color.r, color.g, color.b, color.a );"," ","}"].join("\n")},ROS3D.DepthCloud.prototype.__proto__=THREE.Object3D.prototype,ROS3D.DepthCloud.prototype.metaLoaded=function(){this.metaLoaded=!0,this.initStreamer()},ROS3D.DepthCloud.prototype.initStreamer=function(){if(this.metaLoaded){this.texture=new THREE.Texture(this.video),this.geometry=new THREE.Geometry;for(var a=0,b=this.width*this.height;b>a;a++){var c=new THREE.Vector3;c.x=a%this.width,c.y=Math.floor(a/this.width),this.geometry.vertices.push(c)}this.material=new THREE.ShaderMaterial({uniforms:{map:{type:"t",value:this.texture},width:{type:"f",value:this.width},height:{type:"f",value:this.height},focallength:{type:"f",value:this.f},pointSize:{type:"f",value:this.pointSize},zOffset:{type:"f",value:0},whiteness:{type:"f",value:this.whiteness},varianceThreshold:{type:"f",value:this.varianceThreshold}},vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader}),this.mesh=new THREE.ParticleSystem(this.geometry,this.material),this.mesh.position.x=0,this.mesh.position.y=0,this.add(this.mesh);var d=this;setInterval(function(){d.video.readyState===d.video.HAVE_ENOUGH_DATA&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.video.stop()},ROS3D.InteractiveMarker=function(a){THREE.Object3D.call(this),THREE.EventDispatcher.call(this);var b=this;a=a||{};var c=a.handle;this.name=c.name;var d=a.camera,e=a.path||"/";this.dragging=!1,this.onServerSetPose({pose:c.pose}),this.dragStart={position:new THREE.Vector3,orientation:new THREE.Quaternion,positionWorld:new THREE.Vector3,orientationWorld:new THREE.Quaternion,event3d:{}},c.controls.forEach(function(a){b.add(new ROS3D.InteractiveMarkerControl({parent:b,message:a,camera:d,path:e}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries}),this.menu.addEventListener("menu-select",function(a){b.dispatchEvent(a)}))},ROS3D.InteractiveMarker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarker.prototype.showMenu=function(a,b){this.menu&&this.menu.show(a,b)},ROS3D.InteractiveMarker.prototype.moveAxis=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld.clone()),h=new THREE.Ray(f,g),i=ROS3D.closestAxisPoint(h,c.camera,c.mousePos),j=new THREE.Vector3;j.addVectors(this.dragStart.position,e.clone().applyQuaternion(this.dragStart.orientation).multiplyScalar(i)),this.setPosition(a,j),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.movePlane=function(a,b,c){if(this.dragging){var d=a.currentControlOri,e=b.clone().applyQuaternion(d),f=this.dragStart.event3d.intersection.point,g=e.clone().applyQuaternion(this.dragStart.orientationWorld),h=ROS3D.intersectPlane(c.mouseRay,f,g),i=new THREE.Vector3;i.subVectors(h,f),i.add(this.dragStart.positionWorld),this.setPosition(a,i),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.rotateAxis=function(a,b,c){if(this.dragging){a.updateMatrixWorld();var d=a.currentControlOri,e=d.clone().multiply(b.clone()),f=new THREE.Vector3(1,0,0).applyQuaternion(e),g=this.dragStart.event3d.intersection.point,h=f.applyQuaternion(this.dragStart.orientationWorld),i=ROS3D.intersectPlane(c.mouseRay,g,h),j=new THREE.Ray(this.dragStart.positionWorld,h),k=ROS3D.intersectPlane(j,g,h),l=this.dragStart.orientationWorld.clone().multiply(e),m=l.clone().inverse();i.sub(k),i.applyQuaternion(m);var n=this.dragStart.event3d.intersection.point.clone();n.sub(k),n.applyQuaternion(m);var o=Math.atan2(i.y,i.z),p=Math.atan2(n.y,n.z),q=p-o,r=new THREE.Quaternion;r.setFromAxisAngle(f,q),this.setOrientation(a,r.multiply(this.dragStart.orientationWorld)),c.stopPropagation()}},ROS3D.InteractiveMarker.prototype.feedbackEvent=function(a,b){this.dispatchEvent({type:a,position:this.position.clone(),orientation:this.quaternion.clone(),controlName:b.name})},ROS3D.InteractiveMarker.prototype.startDrag=function(a,b){if(0===b.domEvent.button){b.stopPropagation(),this.dragging=!0,this.updateMatrixWorld(!0);var c=new THREE.Vector3;this.matrixWorld.decompose(this.dragStart.positionWorld,this.dragStart.orientationWorld,c),this.dragStart.position=this.position.clone(),this.dragStart.orientation=this.quaternion.clone(),this.dragStart.event3d=b,this.feedbackEvent("user-mousedown",a)}},ROS3D.InteractiveMarker.prototype.stopDrag=function(a,b){0===b.domEvent.button&&(b.stopPropagation(),this.dragging=!1,this.dragStart.event3d={},this.onServerSetPose(this.bufferedPoseEvent),this.bufferedPoseEvent=void 0,this.feedbackEvent("user-mouseup",a))},ROS3D.InteractiveMarker.prototype.buttonClick=function(a,b){b.stopPropagation(),this.feedbackEvent("user-button-click",a)},ROS3D.InteractiveMarker.prototype.setPosition=function(a,b){this.position=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion=b,this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.onServerSetPose=function(a){if(void 0!==a)if(this.dragging)this.bufferedPoseEvent=a;else{var b=a.pose;this.position.x=b.position.x,this.position.y=b.position.y,this.position.z=b.position.z,this.useQuaternion=!0,this.quaternion=new THREE.Quaternion(b.orientation.x,b.orientation.y,b.orientation.z,b.orientation.w),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topic=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topic&&this.subscribe(this.topic)},ROS3D.InteractiveMarkerClient.prototype.subscribe=function(a){this.unsubscribe(),this.updateTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdate.bind(this)),this.feedbackTopic=new ROSLIB.Topic({ros:this.ros,name:a+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new ROSLIB.Service({ros:this.ros,name:a+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var b=new ROSLIB.ServiceRequest({});this.initService.callService(b,this.processInit.bind(this))},ROS3D.InteractiveMarkerClient.prototype.unsubscribe=function(){this.updateTopic&&this.updateTopic.unsubscribe(),this.feedbackTopic&&this.feedbackTopic.unadvertise();for(var a in this.interactiveMarkers)this.eraseIntMarker(a);this.interactiveMarkers={}},ROS3D.InteractiveMarkerClient.prototype.processInit=function(a){var b=a.msg;b.erases=[];for(var c in this.interactiveMarkers)b.erases.push(c);b.poses=[],this.processUpdate(b)},ROS3D.InteractiveMarkerClient.prototype.processUpdate=function(a){var b=this;a.erases.forEach(function(a){b.eraseIntMarker(a)}),a.poses.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&c.setPoseFromServer(a.pose)}),a.markers.forEach(function(a){var c=b.interactiveMarkers[a.name];c&&b.eraseIntMarker(c.name);var d=new ROS3D.InteractiveMarkerHandle({message:a,feedbackTopic:b.feedbackTopic,tfClient:b.tfClient});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClient.bind(d)),e.addEventListener("user-mousedown",d.onMouseDown.bind(d)),e.addEventListener("user-mouseup",d.onMouseUp.bind(d)),e.addEventListener("user-button-click",d.onButtonClick.bind(d)),e.addEventListener("menu-select",d.onMenuSelect.bind(d)),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){this.interactiveMarkers[a]&&(this.rootObject.remove(this.rootObject.getChildByName(a)),delete this.interactiveMarkers[a])},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),THREE.EventDispatcher.call(this),a=a||{},this.parent=a.parent;var d=a.message;this.name=d.name,this.camera=a.camera,this.path=a.path||"/",this.dragging=!1;var e=new THREE.Quaternion(d.orientation.x,d.orientation.y,d.orientation.z,d.orientation.w);e.normalize();var f=new THREE.Vector3(1,0,0);switch(f.applyQuaternion(e),this.currentControlOri=new THREE.Quaternion,d.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,f)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,e));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}d.interaction_mode!==ROS3D.INTERACTIVE_MARKER_NONE&&(this.addEventListener("mousedown",this.parent.startDrag.bind(this.parent,this)),this.addEventListener("mouseup",this.parent.stopDrag.bind(this.parent,this)),this.addEventListener("contextmenu",this.parent.showMenu.bind(this.parent,this)),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("touchstart",function(a){console.log(a.domEvent),1===a.domEvent.touches.length&&(a.type="mousedown",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchmove",function(a){1===a.domEvent.touches.length&&(console.log(a.domEvent),a.type="mousemove",a.domEvent.button=0,c.dispatchEvent(a))}),this.addEventListener("touchend",function(a){0===a.domEvent.touches.length&&(a.domEvent.button=0,a.type="mouseup",c.dispatchEvent(a),a.type="click",c.dispatchEvent(a))}));var g=new THREE.Quaternion,h=this.parent.position.clone().multiplyScalar(-1);switch(d.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:g=this.parent.quaternion.clone().inverse(),this.updateMatrixWorld=function(a){ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion),c.currentControlOri.normalize()};break;case ROS3D.INTERACTIVE_MARKER_FIXED:this.updateMatrixWorld=function(a){c.useQuaternion=!0,c.quaternion=c.parent.quaternion.clone().inverse(),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0,ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a),c.currentControlOri.copy(c.quaternion)};break;case ROS3D.INTERACTIVE_MARKER_VIEW_FACING:var i=d.independentMarkerOrientation;this.updateMatrixWorld=function(a){c.camera.updateMatrixWorld();var b=(new THREE.Matrix4).extractRotation(c.camera.matrixWorld),d=new THREE.Matrix4,e=.5*Math.PI,f=new THREE.Vector3(-e,0,e);d.setRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),i||(c.useQuaternion=!0,c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+d.orientation_mode)}d.markers.forEach(function(a){var b=new ROS3D.Marker({message:a,path:c.path});""!==a.header.frame_id&&(b.position.add(h),b.position.applyQuaternion(g),b.quaternion.multiplyQuaternions(g,b.quaternion),b.updateMatrixWorld()),c.add(b)})},ROS3D.InteractiveMarkerControl.prototype.__proto__=THREE.Object3D.prototype,ROS3D.InteractiveMarkerHandle=function(a){a=a||{},this.message=a.message,this.feedbackTopic=a.feedbackTopic,this.tfClient=a.tfClient,this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new ROSLIB.Transform,this.pose=new ROSLIB.Pose,this.setPoseFromServer(this.message.pose)},ROS3D.InteractiveMarkerHandle.prototype.__proto__=EventEmitter2.prototype,ROS3D.InteractiveMarkerHandle.prototype.subscribeTf=function(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdate.bind(this))},ROS3D.InteractiveMarkerHandle.prototype.emitServerPoseUpdate=function(){var a=new ROSLIB.Pose(this.pose);a.applyTransform(this.tfTransform),this.emit("pose",a)},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromServer=function(a){this.pose=new ROSLIB.Pose(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.tfUpdate=function(a){this.tfTransform=new ROSLIB.Transform(a),this.emitServerPoseUpdate()},ROS3D.InteractiveMarkerHandle.prototype.setPoseFromClient=function(a){this.pose=new ROSLIB.Pose(a);var b=this.tfTransform.clone();b.rotation.invert(),this.pose.applyTransform(b),this.sendFeedback(ROS3D.INTERACTIVE_MARKER_POSE_UPDATE,void 0,0,a.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,a),250))},ROS3D.InteractiveMarkerHandle.prototype.onButtonClick=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_BUTTON_CLICK,a.clickPosition,0,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.onMouseDown=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_DOWN,a.clickPosition,0,a.controlName),this.dragging=!0},ROS3D.InteractiveMarkerHandle.prototype.onMouseUp=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MOUSE_UP,a.clickPosition,0,a.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)},ROS3D.InteractiveMarkerHandle.prototype.onMenuSelect=function(a){this.sendFeedback(ROS3D.INTERACTIVE_MARKER_MENU_SELECT,void 0,a.id,a.controlName)},ROS3D.InteractiveMarkerHandle.prototype.sendFeedback=function(a,b,c,d){var e=void 0!==b;b=b||{x:0,y:0,z:0};var f={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:d,event_type:a,pose:this.pose,mouse_point:b,mouse_point_valid:e,menu_entry_id:c};this.feedbackTopic.publish(f)},ROS3D.InteractiveMarkerMenu=function(a){function b(a,b){this.dispatchEvent({type:"menu-select",domEvent:b,id:a.id,controlName:this.controlName}),this.hide(b)}function c(a,e){var f=document.createElement("ul");a.appendChild(f);for(var g=e.children,h=0;h0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.className="default-interactive-marker-menu-entry")}}var d=this;a=a||{};var e=a.menuEntries,f=a.className||"default-interactive-marker-menu";a.entryClassName||"default-interactive-marker-menu-entry";var g=a.overlayClassName||"default-interactive-marker-overlay",h=[];if(h[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var i=document.createElement("style");i.id="default-interactive-marker-menu-css",i.type="text/css",i.innerHTML=".default-interactive-marker-menu {background-color: #444444;border: 1px solid #888888;border: 1px solid #888888;padding: 0px 0px 0px 0px;color: #FFFFFF;font-family: sans-serif;font-size: 0.8em;z-index: 1002;}.default-interactive-marker-menu ul {padding: 0px 0px 5px 0px;margin: 0px;list-style-type: none;}.default-interactive-marker-menu ul li div {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;cursor: default;padding: 3px 10px 3px 10px;}.default-interactive-marker-menu-entry:hover { background-color: #666666; cursor: pointer;}.default-interactive-marker-menu ul ul { font-style: italic; padding-left: 10px;}.default-interactive-marker-overlay { position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.0; opacity: .0; filter: alpha(opacity = 0);}",document.getElementsByTagName("head")[0].appendChild(i)}this.menuDomElem=document.createElement("div"),this.menuDomElem.style.position="absolute",this.menuDomElem.className=f,this.menuDomElem.addEventListener("contextmenu",function(a){a.preventDefault()}),this.overlayDomElem=document.createElement("div"),this.overlayDomElem.className=g,this.hideListener=this.hide.bind(this),this.overlayDomElem.addEventListener("contextmenu",this.hideListener),this.overlayDomElem.addEventListener("click",this.hideListener);var j,k,l;for(j=0;ji;i++)for(var j=0;c>j;j++){var k,l=j+(d-i-1)*c,m=b.data[l];k=100===m?0:0===m?255:127;var n=4*(j+i*c);h.data[n]=k,h.data[++n]=k,h.data[++n]=k,h.data[++n]=255}g.putImageData(h,0,0);var o=new THREE.Texture(f);o.needsUpdate=!0;var p=new THREE.MeshBasicMaterial({map:o});p.side=THREE.DoubleSide,THREE.Mesh.call(this,e,p),this.position.x=c*b.info.resolution/2,this.position.y=d*b.info.resolution/2,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){var b=this;a=a||{};var c=a.ros,d=a.topic||"/map";this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.currentGrid=null;var e=new ROSLIB.Topic({ros:c,name:d,messageType:"nav_msgs/OccupancyGrid",compression:"png"});e.subscribe(function(a){b.currentGrid&&b.rootObject.remove(b.currentGrid);var c=new ROS3D.OccupancyGrid({message:a});b.currentGrid=b.tfClient?new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:b.tfClient,object:c,pose:a.info.origin}):c,b.rootObject.add(b.currentGrid),b.emit("change"),b.continuous||e.unsubscribe()})},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),this.useQuaternion=!0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(c.color.r,c.color.g,c.color.b,c.color.a);switch(c.type){case ROS3D.MARKER_ARROW:var e,f=c.scale.x,g=.23*f,h=c.scale.y,i=.5*h,j=null;if(2===c.points.length){j=new THREE.Vector3(c.points[0].x,c.points[0].y,c.points[0].z);var k=new THREE.Vector3(c.points[1].x,c.points[1].y,c.points[1].z);e=j.clone().negate().add(k),f=e.length(),h=c.scale.y,i=c.scale.x,0!==c.scale.z&&(g=c.scale.z)}this.add(new ROS3D.Arrow({direction:e,origin:j,length:f,headLength:g,shaftDiameter:i,headDiameter:h,material:d}));break;case ROS3D.MARKER_CUBE:var l=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z);this.add(new THREE.Mesh(l,d));break;case ROS3D.MARKER_SPHERE:var m=new THREE.SphereGeometry(.5),n=new THREE.Mesh(m,d);n.scale.x=c.scale.x,n.scale.y=c.scale.y,n.scale.z=c.scale.z,this.add(n);break;case ROS3D.MARKER_CYLINDER:var o=new THREE.CylinderGeometry(.5,.5,1,16,1,!1),p=new THREE.Mesh(o,d);p.useQuaternion=!0,p.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale=new THREE.Vector3(c.scale.x,c.scale.z,c.scale.y),this.add(p);break;case ROS3D.MARKER_CUBE_LIST:var q,r,s,t,u=new THREE.Object3D,v=c.points.length,w=v===c.colors.length,x=Math.ceil(v/1250);for(q=0;v>q;q+=x)r=new THREE.CubeGeometry(c.scale.x,c.scale.y,c.scale.z),s=w?ROS3D.makeColorMaterial(c.colors[q].r,c.colors[q].g,c.colors[q].b,c.colors[q].a):d,t=new THREE.Mesh(r,s),t.position.x=c.points[q].x,t.position.y=c.points[q].y,t.position.z=c.points[q].z,u.add(t);this.add(u);break;case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:var y,z=new THREE.Geometry,A=new THREE.ParticleBasicMaterial({size:c.scale.x});for(y=0;yg;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(k)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f=0;f--)if(d[f].object===b[e]){c.push(d[f]);break}this.getWebglObjects(a,b[e].children,c)}},ROS3D.Highlighter.prototype.renderHighlight=function(a,b,c){var d=[];this.getWebglObjects(b,this.hoverObjs,d),b.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide});var e=b.__webglObjects;b.__webglObjects=d,a.render(b,c),b.__webglObjects=e,b.overrideMaterial=null},ROS3D.MouseHandler=function(a){THREE.EventDispatcher.call(this),this.renderer=a.renderer,this.camera=a.camera,this.rootObject=a.rootObject,this.fallbackTarget=a.fallbackTarget,this.lastTarget=this.fallbackTarget,this.dragging=!1,this.projector=new THREE.Projector;var b=["contextmenu","click","dblclick","mouseout","mousedown","mouseup","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchcancel","touchleave","touchmove"];this.listeners={},b.forEach(function(a){this.listeners[a]=this.processDomEvent.bind(this),this.renderer.domElement.addEventListener(a,this.listeners[a],!1)},this)},ROS3D.MouseHandler.prototype.processDomEvent=function(a){a.preventDefault();var b,c,d=a.target,e=d.getBoundingClientRect();-1!==a.type.indexOf("touch")?(b=a.changedTouches[0].clientX,c=a.changedTouches[0].clientY):(b=a.clientX,c=a.clientY);var f=b-e.left-d.clientLeft+d.scrollLeft,g=c-e.top-d.clientTop+d.scrollTop,h=2*(f/d.clientWidth)-1,i=2*(-g/d.clientHeight)+1,j=new THREE.Vector3(h,i,.5);this.projector.unprojectVector(j,this.camera);var k=new THREE.Raycaster(this.camera.position.clone(),j.sub(this.camera.position).normalize()),l=k.ray,m={mousePos:new THREE.Vector2(h,i),mouseRay:l,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if("mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"mouseout",m),this.lastTarget=null,void 0;if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",m),this.dragging=!1),this.notify(this.lastTarget,"touchend",m),this.lastTarget=null,void 0;if(this.dragging)return this.notify(this.lastTarget,a.type,m),("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1),void 0;d=this.lastTarget;var n=[];if(n=k.intersectObject(this.rootObject,!0),n.length>0?(d=n[0].object,m.intersection=this.lastIntersection=n[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var o=this.notify(d,"mouseover",m);o?this.notify(this.lastTarget,"mouseout",m):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(d,"mouseover",m),this.notify(this.lastTarget,"mouseout",m)))}if(d!==this.lastTarget&&a.type.match(/touch/)){var p=this.notify(d,a.type,m);p?(this.notify(this.lastTarget,"touchleave",m),this.notify(this.lastTarget,"touchend",m)):(d=this.fallbackTarget,d!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",m),this.notify(this.lastTarget,"touchend",m)))}this.notify(d,a.type,m),("mousedown"===a.type||"touchstart"===a.type||"touchmove"===a.type)&&(this.dragging=!0),this.lastTarget=d},ROS3D.MouseHandler.prototype.notify=function(a,b,c){for(c.type=b,c.cancelBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function&&(c.currentTarget.dispatchEvent(c),c.cancelBubble))return this.dispatchEvent(c),!0;c.currentTarget=c.currentTarget.parent}return!1},ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:w=v.ROTATE,l.set(b.clientX,b.clientY);break;case 1:w=v.MOVE,s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(w===v.ROTATE)m.set(b.clientX,b.clientY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set(b.clientX,b.clientY),q.subVectors(p,o),q.y>0?i.zoomIn():i.zoomOut(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3,e=new THREE.Vector3;d.subVectors(b,a.origin);var f=a.direction.dot(c);if(Math.abs(f)0?i.zoomIn():i.zoomOut(),this.showAxes()}}function g(a){var b=a.domEvent;switch(console.log(">> button: "+b.button),b.touches.length){case 1:w=v.ROTATE,l.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),s=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);s.applyMatrix4(c),r=i.center.clone(),t=i.camera.position.clone(),u=d(a.mouseRay,r,s);break;case 2:w=v.ZOOM,o.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY));break;case 3:w=v.MOVE}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(console.log(w),w===v.ROTATE)m.set(b.changedTouches[0].pageX-window.scrollX,b.changedTouches[0].pageY-window.scrollY),n.subVectors(m,l),i.rotateLeft(2*Math.PI*n.x/k*i.userRotateSpeed),i.rotateUp(2*Math.PI*n.y/k*i.userRotateSpeed),l.copy(m),this.showAxes();else if(w===v.ZOOM)p.set((b.changedTouches[0].pageX-b.changedTouches[1].pageX)*(b.changedTouches[0].pageX-b.changedTouches[1].pageX),(b.changedTouches[0].pageY-b.changedTouches[1].pageY)*(b.changedTouches[0].pageY-b.changedTouches[1].pageY)),q.subVectors(p,o),q.y>0?i.zoomOut():i.zoomIn(),o.copy(p),this.showAxes();else if(w===v.MOVE){var c=d(a.mouseRay,i.center,s);if(!c)return;var e=(new THREE.Vector3).subVectors(u.clone(),c.clone());i.center.addVectors(r.clone(),e.clone()),i.camera.position.addVectors(t.clone(),e.clone()),i.update(),i.camera.updateMatrixWorld(),this.showAxes()}b.preventDefault()}THREE.EventDispatcher.call(this);var i=this;a=a||{};var j=a.scene;this.camera=a.camera,this.center=new THREE.Vector3,this.userZoom=!0,this.userZoomSpeed=a.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=a.userRotateSpeed||1,this.autoRotate=a.autoRotate,this.autoRotateSpeed=a.autoRotateSpeed||2,this.camera.up=new THREE.Vector3(0,0,1);var k=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,u=new THREE.Vector3;this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var v={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},w=v.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),j.add(this.axes),this.axes.traverse(function(a){a.visible=!1}),this.addEventListener("mousedown",b),this.addEventListener("mouseup",e),this.addEventListener("mousemove",c),this.addEventListener("touchstart",g),this.addEventListener("touchmove",h),this.addEventListener("touchend",e),this.addEventListener("mousewheel",f),this.addEventListener("DOMMouseScroll",f)},ROS3D.OrbitControls.prototype.showAxes=function(){var a=this;this.axes.traverse(function(a){a.visible=!0}),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(function(){a.axes.traverse(function(a){a.visible=!1}),a.hideTimeout=!1},1e3)},ROS3D.OrbitControls.prototype.rotateLeft=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=a},ROS3D.OrbitControls.prototype.rotateRight=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=a},ROS3D.OrbitControls.prototype.rotateUp=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=a},ROS3D.OrbitControls.prototype.rotateDown=function(a){void 0===a&&(a=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=a},ROS3D.OrbitControls.prototype.zoomIn=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale/=a},ROS3D.OrbitControls.prototype.zoomOut=function(a){void 0===a&&(a=Math.pow(.95,this.userZoomSpeed)),this.scale*=a},ROS3D.OrbitControls.prototype.update=function(){var a=this.camera.position,b=a.clone().sub(this.center),c=Math.atan2(b.y,b.x),d=Math.atan2(Math.sqrt(b.y*b.y+b.x*b.x),b.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),c+=this.thetaDelta,d+=this.phiDelta;var e=1e-6;d=Math.max(e,Math.min(Math.PI-e,d));var f=b.length();b.y=f*Math.sin(d)*Math.sin(c),b.z=f*Math.cos(d),b.x=f*Math.sin(d)*Math.cos(c),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),f=b.length(),this.axes.position=this.center.clone(),this.axes.scale.x=this.axes.scale.y=this.axes.scale.z=.05*f,this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}; \ No newline at end of file diff --git a/src/visualization/interaction/MouseHandler.js b/src/visualization/interaction/MouseHandler.js index 037bac8a..d2ea107f 100644 --- a/src/visualization/interaction/MouseHandler.js +++ b/src/visualization/interaction/MouseHandler.js @@ -77,12 +77,6 @@ ROS3D.MouseHandler.prototype.processDomEvent = function(domEvent) { intersection : this.lastIntersection }; - console.log('------------------------------------'); - console.log(domEvent.type); - console.log(' Dragging?: ' + this.dragging); - console.log(' lastTarget: ' + this.lastTarget); - console.log(' Target: ' + target); - // if the mouse leaves the dom element, stop everything if (domEvent.type === 'mouseout') { if (this.dragging) { diff --git a/src/visualization/interaction/OrbitControls.js b/src/visualization/interaction/OrbitControls.js index 95059390..81fb7c59 100644 --- a/src/visualization/interaction/OrbitControls.js +++ b/src/visualization/interaction/OrbitControls.js @@ -190,6 +190,7 @@ ROS3D.OrbitControls = function(options) { if (!that.userRotate) { return; } + state = STATE.NONE; }