forked from RobotWebTools/ros3djs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ros3d.min.js
3 lines (3 loc) · 73.3 KB
/
ros3d.min.js
1
2
3
function setFrame(a,b){null===a.sn&&(a.sn=new ROS3D.SceneNode({frameID:b,tfClient:a.tfClient,object:a.ps}),a.rootObject.add(a.sn))}function finishedUpdate(a,b){null===a.first_size&&(a.first_size=b,a.max_pts=Math.max(a.max_pts,b));for(var c=b;c<a.prev_pts;c++)a.alpha[c]=0;a.prev_pts=b,a.geom.verticesNeedUpdate=!0,a.points.needsUpdate=!0,a.colors.needsUpdate=!0,a.alpha.needsUpdate=!0,b>a.max_pts&&console.error("Attempted to draw more points than max_pts allows")}function read_point(a,b,c){for(var d=[],e=a.point_step*b,f=0;f<a.fields.length;f++){var g=e+a.fields[f].offset;"rgb"===a.fields[f].name?d.rgb=c.getInt32(g,1):d[a.fields[f].name]=c.getFloat32(g,1)}return d}function decode64(a){for(var b=[],c=0,d=0,e=0,f=a.length;e<f;e++)c+=BASE64.indexOf(a[e]),d+=6,d>=8&&(d-=8,b.push(c>>d),c&=Math.pow(2,d)-1),c<<=6;return b}var ROS3D=ROS3D||{REVISION:"0.18.0"};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),d<=.99?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.MeshPhongMaterial({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)<a.precision)){var g=c.dot(d)/f;return e.addVectors(a.origin,a.direction.clone().multiplyScalar(g)),e}},ROS3D.findClosestPoint=function(a,b){var c=new THREE.Vector3;c.subVectors(a.origin,b.origin);var d=b.direction.clone(),e=a.direction.clone(),f=c.dot(d),g=d.dot(e),h=c.dot(e),i=d.dot(d),j=e.dot(e),k=j*i-g*g;if(!(Math.abs(k)<=1e-4)){return(f*g-h*i)/k}},ROS3D.closestAxisPoint=function(a,b,c){var d=a.origin.clone();d.project(b);var e=a.direction.clone().add(a.origin);e.project(b);var f=e.clone().sub(d),g=new THREE.Vector2,h=g.subVectors(c,d).dot(f)/f.dot(f),i=new THREE.Vector2;i.addVectors(d,f.clone().multiplyScalar(h));var j=new THREE.Vector3(i.x,i.y,.5);j.unproject(b);var k=new THREE.Ray(b.position,j.sub(b.position).normalize());return ROS3D.findClosestPoint(a,k)},ROS3D.DepthCloud=function(a){a=a||{},THREE.Object3D.call(this),this.url=a.url,this.streamType=a.streamType||"vp8",this.f=a.f||526,this.pointSize=a.pointSize||3,this.width=a.width||1024,this.height=a.height||1024,this.whiteness=a.whiteness||0,this.varianceThreshold=a.varianceThreshold||16667e-9;this.isMjpeg="mjpeg"===this.streamType.toLowerCase(),this.video=document.createElement(this.isMjpeg?"img":"video"),this.video.addEventListener(this.isMjpeg?"load":"loadedmetadata",this.metaLoaded.bind(this),!1),this.isMjpeg||(this.video.loop=!0),this.video.src=this.url,this.video.crossOrigin="Anonymous",this.video.setAttribute("crossorigin","Anonymous"),this.vertex_shader=["uniform sampler2D map;","","uniform float width;","uniform float height;","uniform float nearClipping, farClipping;","","uniform float pointSize;","uniform float zOffset;","","uniform float focallength;","","varying vec2 vUvP;","varying vec2 colorP;","","varying float depthVariance;","varying float maskVal;","","float sampleDepth(vec2 pos)"," {"," float depth;"," "," vec2 vUv = vec2( pos.x / (width*2.0), pos.y / (height*2.0)+0.5 );"," vec2 vUv2 = vec2( pos.x / (width*2.0)+0.5, pos.y / (height*2.0)+0.5 );"," "," vec4 depthColor = texture2D( map, vUv );"," "," depth = ( depthColor.r + depthColor.g + depthColor.b ) / 3.0 ;"," "," if (depth>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 ( (a<b) && (b<c) )"," {"," r = b;"," }"," if ( (a<c) && (c<b) )"," {"," r = c;"," }"," return r;"," }","","float variance(float d1, float d2, float d3, float d4, float d5, float d6, float d7, float d8, float d9)"," {"," float mean = (d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9) / 9.0;"," float t1 = (d1-mean);"," float t2 = (d2-mean);"," float t3 = (d3-mean);"," float t4 = (d4-mean);"," float t5 = (d5-mean);"," float t6 = (d6-mean);"," float t7 = (d7-mean);"," float t8 = (d8-mean);"," float t9 = (d9-mean);"," float v = (t1*t1+t2*t2+t3*t3+t4*t4+t5*t5+t6*t6+t7*t7+t8*t8+t9*t9)/9.0;"," return v;"," }","","vec2 decodeDepth(vec2 pos)"," {"," vec2 ret;"," "," "," float depth1 = sampleDepth(vec2(position.x-1.0, position.y-1.0));"," float depth2 = sampleDepth(vec2(position.x, position.y-1.0));"," float depth3 = sampleDepth(vec2(position.x+1.0, position.y-1.0));"," float depth4 = sampleDepth(vec2(position.x-1.0, position.y));"," float depth5 = sampleDepth(vec2(position.x, position.y));"," float depth6 = sampleDepth(vec2(position.x+1.0, position.y));"," float depth7 = sampleDepth(vec2(position.x-1.0, position.y+1.0));"," float depth8 = sampleDepth(vec2(position.x, position.y+1.0));"," float depth9 = sampleDepth(vec2(position.x+1.0, position.y+1.0));"," "," float median1 = median(depth1, depth2, depth3);"," float median2 = median(depth4, depth5, depth6);"," float median3 = median(depth7, depth8, depth9);"," "," ret.x = median(median1, median2, median3);"," ret.y = variance(depth1, depth2, depth3, depth4, depth5, depth6, depth7, depth8, depth9);"," "," return ret;"," "," }","","","void main() {"," "," vUvP = vec2( position.x / (width*2.0), position.y / (height*2.0)+0.5 );"," colorP = vec2( position.x / (width*2.0)+0.5 , position.y / (height*2.0) );"," "," vec4 pos = vec4(0.0,0.0,0.0,0.0);"," depthVariance = 0.0;"," "," if ( (vUvP.x<0.0)|| (vUvP.x>0.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;a<b;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.isMjpeg||d.video.readyState===d.video.HAVE_ENOUGH_DATA)&&(d.texture.needsUpdate=!0)},1e3/30)}},ROS3D.DepthCloud.prototype.startStream=function(){this.isMjpeg||this.video.play()},ROS3D.DepthCloud.prototype.stopStream=function(){this.isMjpeg||this.video.pause()},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||"/",f=a.loader||ROS3D.COLLADA_LOADER_2;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,handle:c,message:a,camera:d,path:e,loader:f}))}),c.menuEntries.length>0&&(this.menu=new ROS3D.InteractiveMarkerMenu({menuEntries:c.menuEntries,menuFontSize:c.menuFontSize}),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.copy(b),this.feedbackEvent("user-pose-change",a)},ROS3D.InteractiveMarker.prototype.setOrientation=function(a,b){b.normalize(),this.quaternion.copy(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.copy(b.position),this.quaternion.copy(b.orientation),this.updateMatrixWorld(!0)}},ROS3D.InteractiveMarker.prototype.dispose=function(){var a=this;this.children.forEach(function(b){b.children.forEach(function(a){a.dispose(),b.remove(a)}),a.remove(b)})},Object.assign(ROS3D.InteractiveMarker.prototype,THREE.EventDispatcher.prototype),ROS3D.InteractiveMarkerClient=function(a){a=a||{},this.ros=a.ros,this.tfClient=a.tfClient,this.topicName=a.topic,this.path=a.path||"/",this.camera=a.camera,this.rootObject=a.rootObject||new THREE.Object3D,this.loader=a.loader||ROS3D.COLLADA_LOADER_2,this.menuFontSize=a.menuFontSize||"0.8em",this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.topicName&&this.subscribe(this.topicName)},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,menuFontSize:b.menuFontSize});b.interactiveMarkers[a.name]=d;var e=new ROS3D.InteractiveMarker({handle:d,camera:b.camera,path:b.path,loader:b.loader});e.name=a.name,b.rootObject.add(e),d.on("pose",function(a){e.onServerSetPose({pose:a})}),e.addEventListener("user-pose-change",d.setPoseFromClientBound),e.addEventListener("user-mousedown",d.onMouseDownBound),e.addEventListener("user-mouseup",d.onMouseUpBound),e.addEventListener("user-button-click",d.onButtonClickBound),e.addEventListener("menu-select",d.onMenuSelectBound),d.subscribeTf()})},ROS3D.InteractiveMarkerClient.prototype.eraseIntMarker=function(a){if(this.interactiveMarkers[a]){var b=this.rootObject.getObjectByName(a);this.rootObject.remove(b);var c=this.interactiveMarkers[a];c.unsubscribeTf(),b.removeEventListener("user-pose-change",c.setPoseFromClientBound),b.removeEventListener("user-mousedown",c.onMouseDownBound),b.removeEventListener("user-mouseup",c.onMouseUpBound),b.removeEventListener("user-button-click",c.onButtonClickBound),b.removeEventListener("menu-select",c.onMenuSelectBound),delete this.interactiveMarkers[a],b.dispose()}},ROS3D.InteractiveMarkerControl=function(a){function b(a){a.stopPropagation()}var c=this;THREE.Object3D.call(this),a=a||{},this.parent=a.parent;var d=a.handle,e=a.message;this.name=e.name,this.camera=a.camera,this.path=a.path||"/",this.loader=a.loader||ROS3D.COLLADA_LOADER_2,this.dragging=!1,this.startMousePos=new THREE.Vector2;var f=new THREE.Quaternion(e.orientation.x,e.orientation.y,e.orientation.z,e.orientation.w);f.normalize();var g=new THREE.Vector3(1,0,0);switch(g.applyQuaternion(f),this.currentControlOri=new THREE.Quaternion,e.interaction_mode){case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:this.addEventListener("mousemove",this.parent.moveAxis.bind(this.parent,this,g)),this.addEventListener("touchmove",this.parent.moveAxis.bind(this.parent,this,g));break;case ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS:this.addEventListener("mousemove",this.parent.rotateAxis.bind(this.parent,this,f));break;case ROS3D.INTERACTIVE_MARKER_MOVE_PLANE:this.addEventListener("mousemove",this.parent.movePlane.bind(this.parent,this,g));break;case ROS3D.INTERACTIVE_MARKER_BUTTON:this.addEventListener("click",this.parent.buttonClick.bind(this.parent,this))}e.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("mouseup",function(a){0===c.startMousePos.distanceToSquared(a.mousePos)&&(a.type="contextmenu",c.dispatchEvent(a))}),this.addEventListener("mouseover",b),this.addEventListener("mouseout",b),this.addEventListener("click",b),this.addEventListener("mousedown",function(a){c.startMousePos=a.mousePos}),this.addEventListener("touchstart",function(a){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&&(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 h=new THREE.Quaternion,i=this.parent.position.clone().multiplyScalar(-1);switch(e.orientation_mode){case ROS3D.INTERACTIVE_MARKER_INHERIT:h=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.quaternion.copy(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 j=e.independent_marker_orientation;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.Euler(-e,0,e);d.makeRotationFromEuler(f);var g=new THREE.Matrix4;g.getInverse(c.parent.matrixWorld),b.multiplyMatrices(b,d),b.multiplyMatrices(g,b),c.currentControlOri.setFromRotationMatrix(b),j||(c.quaternion.copy(c.currentControlOri),c.updateMatrix(),c.matrixWorldNeedsUpdate=!0),ROS3D.InteractiveMarkerControl.prototype.updateMatrixWorld.call(c,a)};break;default:console.error("Unkown orientation mode: "+e.orientation_mode)}var k=new ROSLIB.TFClient({ros:d.tfClient.ros,fixedFrame:d.message.header.frame_id,serverName:d.tfClient.serverName});e.markers.forEach(function(a){var b=function(b){var d=new ROS3D.Marker({message:a,path:c.path,loader:c.loader});if(null!==b){var e=new ROSLIB.Pose({position:d.position,orientation:d.quaternion});e.applyTransform(new ROSLIB.Transform(b));var f=new ROS3D.Marker({message:a,path:c.path,loader:c.loader});f.position.add(i),f.position.applyQuaternion(h),f.quaternion.multiplyQuaternions(h,f.quaternion);var g=new THREE.Vector3(f.position.x,f.position.y,f.position.z),j=new ROSLIB.Transform({translation:g,orientation:f.quaternion});e.applyTransform(j),d.setPose(e),d.updateMatrixWorld(),k.unsubscribe(a.header.frame_id)}c.add(d)};""!==a.header.frame_id?k.subscribe(a.header.frame_id,b):b(null)})},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.menuFontSize=a.menuFontSize||"0.8em",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.setPoseFromClientBound=this.setPoseFromClient.bind(this),this.onMouseDownBound=this.onMouseDown.bind(this),this.onMouseUpBound=this.onMouseUp.bind(this),this.onButtonClickBound=this.onButtonClick.bind(this),this.onMenuSelectBound=this.onMenuSelect.bind(this),this.setPoseFromServer(this.message.pose),this.tfUpdateBound=this.tfUpdate.bind(this)},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.tfUpdateBound)},ROS3D.InteractiveMarkerHandle.prototype.unsubscribeTf=function(){this.tfClient.unsubscribe(this.message.header.frame_id,this.tfUpdateBound)},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(),b.translation.multiplyQuaternion(b.rotation),b.translation.x*=-1,b.translation.y*=-1,b.translation.z*=-1,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;h<g.length;h++){var i=document.createElement("li"),j=document.createElement("div");j.appendChild(document.createTextNode(g[h].title)),f.appendChild(i),i.appendChild(j),g[h].children.length>0?(c(i,g[h]),j.addEventListener("click",d.hide.bind(d)),j.addEventListener("touchstart",d.hide.bind(d))):(j.addEventListener("click",b.bind(d,g[h])),j.addEventListener("touchstart",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",g=(a.entryClassName,a.overlayClassName||"default-interactive-marker-overlay"),h=a.menuFontSize||"0.8em",i=[];if(i[0]={children:[]},THREE.EventDispatcher.call(this),null===document.getElementById("default-interactive-marker-menu-css")){var j=document.createElement("style");j.id="default-interactive-marker-menu-css",j.type="text/css",j.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: "+h+";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(j)}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),this.overlayDomElem.addEventListener("touchstart",this.hideListener);var k,l,m;for(k=0;k<e.length;k++)l=e[k],m=l.id,i[m]={title:l.title,id:m,children:[]};for(k=0;k<e.length;k++){l=e[k],m=l.id;var n=i[m];i[l.parent_id].children.push(n)}c(this.menuDomElem,i[0])},ROS3D.InteractiveMarkerMenu.prototype.show=function(a,b){b&&b.preventDefault&&b.preventDefault(),this.controlName=a.name,void 0!==b.domEvent.changedTouches?(this.menuDomElem.style.left=b.domEvent.changedTouches[0].pageX+"px",this.menuDomElem.style.top=b.domEvent.changedTouches[0].pageY+"px"):(this.menuDomElem.style.left=b.domEvent.clientX+"px",this.menuDomElem.style.top=b.domEvent.clientY+"px"),document.body.appendChild(this.overlayDomElem),document.body.appendChild(this.menuDomElem)},ROS3D.InteractiveMarkerMenu.prototype.hide=function(a){a&&a.preventDefault&&a.preventDefault(),document.body.removeChild(this.overlayDomElem),document.body.removeChild(this.menuDomElem)},Object.assign(ROS3D.InteractiveMarkerMenu.prototype,THREE.EventDispatcher.prototype),ROS3D.Marker=function(a){a=a||{};var b=a.path||"/",c=a.message;"/"!==b.substr(b.length-1)&&(b+="/"),THREE.Object3D.call(this),c.scale?this.msgScale=[c.scale.x,c.scale.y,c.scale.z]:this.msgScale=[1,1,1],this.msgColor=c.color,this.msgMesh=void 0,this.setPose(c.pose);var d=ROS3D.makeColorMaterial(this.msgColor.r,this.msgColor.g,this.msgColor.b,this.msgColor.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.BoxGeometry(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.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI),p.scale.set(c.scale.x,c.scale.z,c.scale.y),this.add(p);break;case ROS3D.MARKER_LINE_STRIP:var q,r=new THREE.Geometry,s=new THREE.LineBasicMaterial({size:c.scale.x});for(q=0;q<c.points.length;q++){var t=new THREE.Vector3;t.x=c.points[q].x,t.y=c.points[q].y,t.z=c.points[q].z,r.vertices.push(t)}if(c.colors.length===c.points.length)for(s.vertexColors=!0,q=0;q<c.points.length;q++){var u=new THREE.Color;u.setRGB(c.colors[q].r,c.colors[q].g,c.colors[q].b),r.colors.push(u)}else s.color.setRGB(c.color.r,c.color.g,c.color.b);this.add(new THREE.Line(r,s));break;case ROS3D.MARKER_LINE_LIST:var v,w=new THREE.Geometry,x=new THREE.LineBasicMaterial({size:c.scale.x});for(v=0;v<c.points.length;v++){var y=new THREE.Vector3;y.x=c.points[v].x,y.y=c.points[v].y,y.z=c.points[v].z,w.vertices.push(y)}if(c.colors.length===c.points.length)for(x.vertexColors=!0,v=0;v<c.points.length;v++){var z=new THREE.Color;z.setRGB(c.colors[v].r,c.colors[v].g,c.colors[v].b),w.colors.push(z)}else x.color.setRGB(c.color.r,c.color.g,c.color.b);this.add(new THREE.Line(w,x,THREE.LinePieces));break;case ROS3D.MARKER_CUBE_LIST:var A,B,C,D,E=new THREE.Object3D,F=c.points.length,G=F===c.colors.length,H=Math.ceil(F/1250);for(A=0;A<F;A+=H)B=new THREE.BoxGeometry(c.scale.x,c.scale.y,c.scale.z),C=G?ROS3D.makeColorMaterial(c.colors[A].r,c.colors[A].g,c.colors[A].b,c.colors[A].a):d,D=new THREE.Mesh(B,C),D.position.x=c.points[A].x,D.position.y=c.points[A].y,D.position.z=c.points[A].z,E.add(D);this.add(E);break;case ROS3D.MARKER_SPHERE_LIST:var I,J,K,L,M=new THREE.Object3D,N=c.points.length,O=N===c.colors.length,P=Math.ceil(N/1250);for(I=0;I<N;I+=P)J=new THREE.SphereGeometry(.5,8,8),K=O?ROS3D.makeColorMaterial(c.colors[I].r,c.colors[I].g,c.colors[I].b,c.colors[I].a):d,L=new THREE.Mesh(J,K),L.scale.x=c.scale.x,L.scale.y=c.scale.y,L.scale.z=c.scale.z,L.position.x=c.points[I].x,L.position.y=c.points[I].y,L.position.z=c.points[I].z,M.add(L);this.add(M);break;case ROS3D.MARKER_POINTS:var Q,R=new THREE.Geometry,S=new THREE.ParticleBasicMaterial({size:c.scale.x});for(Q=0;Q<c.points.length;Q++){var T=new THREE.Vector3;T.x=c.points[Q].x,T.y=c.points[Q].y,T.z=c.points[Q].z,R.vertices.push(T)}if(c.colors.length===c.points.length)for(S.vertexColors=!0,Q=0;Q<c.points.length;Q++){var U=new THREE.Color;U.setRGB(c.colors[Q].r,c.colors[Q].g,c.colors[Q].b),R.colors.push(U)}else S.color.setRGB(c.color.r,c.color.g,c.color.b);this.add(new THREE.ParticleSystem(R,S));break;case ROS3D.MARKER_TEXT_VIEW_FACING:if(c.text.length>0){
var V=this.msgColor,W=document.createElement("canvas"),X=W.getContext("2d");X.font="normal 100px sans-serif";var Y=X.measureText(c.text),Z=Y.width;W.width=Z,W.height=150,X.font="normal 100px sans-serif",X.fillStyle="rgba("+Math.round(255*V.r)+", "+Math.round(255*V.g)+", "+Math.round(255*V.b)+", "+V.a+")",X.textAlign="left",X.textBaseline="middle",X.fillText(c.text,0,W.height/2);var $=new THREE.Texture(W);$.needsUpdate=!0;var _=new THREE.SpriteMaterial({map:$,useScreenCoordinates:!1}),aa=new THREE.Sprite(_),ba=c.scale.x;aa.scale.set(Z/W.height*ba,ba,1),this.add(aa)}break;case ROS3D.MARKER_MESH_RESOURCE:var ca=null;0===c.color.r&&0===c.color.g&&0===c.color.b&&0===c.color.a||(ca=d),this.msgMesh=c.mesh_resource.substr(10);var da=new ROS3D.MeshResource({path:b,resource:this.msgMesh,material:ca});this.add(da);break;case ROS3D.MARKER_TRIANGLE_LIST:var ea=new ROS3D.TriangleList({material:d,vertices:c.points,colors:c.colors});ea.scale.set(c.scale.x,c.scale.y,c.scale.z),this.add(ea);break;default:console.error("Currently unsupported marker type: "+c.type)}},ROS3D.Marker.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Marker.prototype.setPose=function(a){this.position.x=a.position.x,this.position.y=a.position.y,this.position.z=a.position.z,this.quaternion.set(a.orientation.x,a.orientation.y,a.orientation.z,a.orientation.w),this.quaternion.normalize(),this.updateMatrixWorld()},ROS3D.Marker.prototype.update=function(a){if(this.setPose(a.pose),a.color.r!==this.msgColor.r||a.color.g!==this.msgColor.g||a.color.b!==this.msgColor.b||a.color.a!==this.msgColor.a){var b=ROS3D.makeColorMaterial(a.color.r,a.color.g,a.color.b,a.color.a);switch(a.type){case ROS3D.MARKER_LINE_STRIP:case ROS3D.MARKER_LINE_LIST:case ROS3D.MARKER_POINTS:break;case ROS3D.MARKER_ARROW:case ROS3D.MARKER_CUBE:case ROS3D.MARKER_SPHERE:case ROS3D.MARKER_CYLINDER:case ROS3D.MARKER_TRIANGLE_LIST:case ROS3D.MARKER_TEXT_VIEW_FACING:this.traverse(function(a){a instanceof THREE.Mesh&&(a.material=b)});break;case ROS3D.MARKER_MESH_RESOURCE:var c=null;0===a.color.r&&0===a.color.g&&0===a.color.b&&0===a.color.a||(c=this.colorMaterial),this.traverse(function(a){a instanceof THREE.Mesh&&(a.material=c)});break;case ROS3D.MARKER_CUBE_LIST:case ROS3D.MARKER_SPHERE_LIST:default:return!1}this.msgColor=a.color}var d=Math.abs(this.msgScale[0]-a.scale.x)>1e-6||Math.abs(this.msgScale[1]-a.scale.y)>1e-6||Math.abs(this.msgScale[2]-a.scale.z)>1e-6;switch(this.msgScale=[a.scale.x,a.scale.y,a.scale.z],a.type){case ROS3D.MARKER_CUBE:case ROS3D.MARKER_SPHERE:case ROS3D.MARKER_CYLINDER:if(d)return!1;break;case ROS3D.MARKER_TEXT_VIEW_FACING:if(d||this.text!==a.text)return!1;break;case ROS3D.MARKER_MESH_RESOURCE:if(a.mesh_resource.substr(10)!==this.msgMesh)return!1;if(d)return!1;break;case ROS3D.MARKER_ARROW:case ROS3D.MARKER_LINE_STRIP:case ROS3D.MARKER_LINE_LIST:case ROS3D.MARKER_CUBE_LIST:case ROS3D.MARKER_SPHERE_LIST:case ROS3D.MARKER_POINTS:case ROS3D.MARKER_TRIANGLE_LIST:return!1}return!0},ROS3D.Marker.prototype.dispose=function(){this.children.forEach(function(a){a instanceof ROS3D.MeshResource?a.children.forEach(function(b){void 0!==b.material&&b.material.dispose(),b.children.forEach(function(a){void 0!==a.geometry&&a.geometry.dispose(),void 0!==a.material&&a.material.dispose(),b.remove(a)}),a.remove(b)}):(void 0!==a.geometry&&a.geometry.dispose(),void 0!==a.material&&a.material.dispose()),a.parent.remove(a)})},ROS3D.MarkerArrayClient=function(a){a=a||{},this.ros=a.ros,this.topicName=a.topic,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.path=a.path||"/",this.markers={},this.rosTopic=void 0,this.subscribe()},ROS3D.MarkerArrayClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.MarkerArrayClient.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"visualization_msgs/MarkerArray",compression:"png"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.MarkerArrayClient.prototype.processMessage=function(a){a.markers.forEach(function(a){if(0===a.action){var b=!1;if(a.ns+a.id in this.markers&&((b=this.markers[a.ns+a.id].children[0].update(a))||(this.markers[a.ns+a.id].unsubscribeTf(),this.rootObject.remove(this.markers[a.ns+a.id]))),!b){var c=new ROS3D.Marker({message:a,path:this.path});this.markers[a.ns+a.id]=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:c}),this.rootObject.add(this.markers[a.ns+a.id])}}else if(1===a.action)console.warn('Received marker message with deprecated action identifier "1"');else if(2===a.action)this.markers[a.ns+a.id].unsubscribeTf(),this.rootObject.remove(this.markers[a.ns+a.id]),delete this.markers[a.ns+a.id];else if(3===a.action){for(var d in this.markers)this.markers[d].unsubscribeTf(),this.rootObject.remove(this.markers[d]);this.markers={}}else console.warn('Received marker message with unknown action identifier "'+a.action+'"')}.bind(this)),this.emit("change")},ROS3D.MarkerArrayClient.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.MarkerClient=function(a){a=a||{},this.ros=a.ros,this.topicName=a.topic,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.path=a.path||"/",this.markers={},this.rosTopic=void 0,this.subscribe()},ROS3D.MarkerClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.MarkerClient.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.MarkerClient.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"visualization_msgs/Marker",compression:"png"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.MarkerClient.prototype.processMessage=function(a){var b=new ROS3D.Marker({message:a,path:this.path}),c=this.markers[a.ns+a.id];c&&(c.unsubscribeTf(),this.rootObject.remove(c)),this.markers[a.ns+a.id]=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:b}),this.rootObject.add(this.markers[a.ns+a.id]),this.emit("change")},ROS3D.Arrow=function(a){a=a||{};var b=a.origin||new THREE.Vector3(0,0,0),c=a.direction||new THREE.Vector3(1,0,0),d=a.length||1,e=a.headLength||.2,f=a.shaftDiameter||.05,g=a.headDiameter||.1,h=a.material||new THREE.MeshBasicMaterial,i=d-e,j=new THREE.CylinderGeometry(.5*f,.5*f,i,12,1),k=new THREE.Matrix4;k.setPosition(new THREE.Vector3(0,.5*i,0)),j.applyMatrix(k);var l=new THREE.CylinderGeometry(0,.5*g,e,12,1);k.setPosition(new THREE.Vector3(0,i+.5*e,0)),l.applyMatrix(k),j.merge(l),THREE.Mesh.call(this,j,h),this.position.copy(b),this.setDirection(c)},ROS3D.Arrow.prototype.__proto__=THREE.Mesh.prototype,ROS3D.Arrow.prototype.setDirection=function(a){var b=new THREE.Vector3(0,1,0).cross(a),c=Math.acos(new THREE.Vector3(0,1,0).dot(a.clone().normalize()));this.matrix=(new THREE.Matrix4).makeRotationAxis(b.normalize(),c),this.rotation.setFromRotationMatrix(this.matrix,this.rotation.order)},ROS3D.Arrow.prototype.setLength=function(a){this.scale.set(a,a,a)},ROS3D.Arrow.prototype.setColor=function(a){this.material.color.setHex(a)},ROS3D.Arrow.prototype.dispose=function(){void 0!==this.geometry&&this.geometry.dispose(),void 0!==this.material&&this.material.dispose()},ROS3D.Arrow2=function(a){a=a||{};var b=a.origin||new THREE.Vector3(0,0,0),c=a.direction||new THREE.Vector3(1,0,0),d=a.length||1;a.headLength,a.shaftDiameter,a.headDiameter,a.material||new THREE.MeshBasicMaterial;THREE.ArrowHelper.call(this,c,b,d,16711680)},ROS3D.Arrow2.prototype.__proto__=THREE.ArrowHelper.prototype,ROS3D.Arrow2.prototype.dispose=function(){void 0!==this.line&&(this.line.material.dispose(),this.line.geometry.dispose()),void 0!==this.cone&&(this.cone.material.dispose(),this.cone.geometry.dispose())},ROS3D.Axes=function(a){function b(a){var b=new THREE.Color;b.setRGB(a.x,a.y,a.z);var d=new THREE.MeshBasicMaterial({color:b.getHex()}),e=new THREE.Vector3;e.crossVectors(a,new THREE.Vector3(0,-1,0));var f=new THREE.Quaternion;f.setFromAxisAngle(e,.5*Math.PI);var g=new THREE.Mesh(c.headGeom,d);g.position.copy(a),g.position.multiplyScalar(.95),g.quaternion.copy(f),g.updateMatrix(),c.add(g);var h=new THREE.Mesh(c.lineGeom,d);h.position.copy(a),h.position.multiplyScalar(.45),h.quaternion.copy(f),h.updateMatrix(),c.add(h)}var c=this;a=a||{};var d=a.shaftRadius||.008,e=a.headRadius||.023,f=a.headLength||.1;THREE.Object3D.call(this),this.lineGeom=new THREE.CylinderGeometry(d,d,1-f),this.headGeom=new THREE.CylinderGeometry(0,e,f),b(new THREE.Vector3(1,0,0)),b(new THREE.Vector3(0,1,0)),b(new THREE.Vector3(0,0,1))},ROS3D.Axes.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Grid=function(a){a=a||{};var b=a.num_cells||10,c=a.color||"#cccccc",d=a.lineWidth||1,e=a.cellSize||1;THREE.Object3D.call(this);for(var f=new THREE.LineBasicMaterial({color:c,linewidth:d}),g=0;g<=b;++g){var h=e*b/2,i=h-g*e,j=new THREE.Geometry;j.vertices.push(new THREE.Vector3(-h,i,0),new THREE.Vector3(h,i,0));var k=new THREE.Geometry;k.vertices.push(new THREE.Vector3(i,-h,0),new THREE.Vector3(i,h,0)),this.add(new THREE.Line(j,f)),this.add(new THREE.Line(k,f))}},ROS3D.Grid.prototype.__proto__=THREE.Object3D.prototype,ROS3D.MeshResource=function(a){var b=this;a=a||{};var c=a.path||"/",d=a.resource,e=a.material||null;this.warnings=a.warnings,THREE.Object3D.call(this),"/"!==c.substr(c.length-1)&&(c+="/");var f,g=c+d,h=g.substr(-4).toLowerCase();".dae"===h?(f=new THREE.ColladaLoader,f.log=function(a){b.warnings&&console.warn(a)},f.load(g,function(a){null!==e&&a.scene.traverse(function(a){a instanceof THREE.Mesh&&void 0===a.material&&(a.material=e)}),b.add(a.scene)},null,function(a){console.error(a)})):".stl"===h&&(f=new THREE.STLLoader,f.load(g,function(a){a.computeFaceNormals();var c;c=null!==e?new THREE.Mesh(a,e):new THREE.Mesh(a,new THREE.MeshBasicMaterial({color:10066329})),b.add(c)},null,function(a){console.error(a)}))},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;f<c.length;f++)e.vertices.push(new THREE.Vector3(c[f].x,c[f].y,c[f].z));var f,g;if(d.length===c.length){for(f=0;f<c.length;f+=3){var h=new THREE.Face3(f,f+1,f+2);for(g=3*f;g<3*f+3;f++){var i=new THREE.Color;i.setRGB(d[f].r,d[f].g,d[f].b),h.vertexColors.push(i)}e.faces.push(h)}b.vertexColors=THREE.VertexColors}else if(d.length===c.length/3){for(f=0;f<c.length;f+=3){var j=new THREE.Face3(f,f+1,f+2);j.color.setRGB(d[f/3].r,d[f/3].g,d[f/3].b),e.faces.push(j)}b.vertexColors=THREE.FaceColors}else for(f=0;f<c.length;f+=3){var k=new THREE.Face3(f,f+1,f+2);e.faces.push(k)}e.computeBoundingBox(),e.computeBoundingSphere(),e.computeFaceNormals(),this.add(new THREE.Mesh(e,b))},ROS3D.TriangleList.prototype.__proto__=THREE.Object3D.prototype,ROS3D.TriangleList.prototype.setColor=function(a){this.mesh.material.color.setHex(a)},ROS3D.OccupancyGrid=function(a){a=a||{};var b=a.message,c=a.color||{r:255,g:255,b:255},d=a.opacity||1,e=b.info.width,f=b.info.height,g=new THREE.PlaneGeometry(e,f),h=document.createElement("canvas");h.width=e,h.height=f;for(var i=h.getContext("2d"),j=i.createImageData(e,f),k=0;k<f;k++)for(var l=0;l<e;l++){var m,n=l+(f-k-1)*e,o=b.data[n];m=100===o?0:0===o?255:127;var p=4*(l+k*e);j.data[p]=m*c.r/255,j.data[++p]=m*c.g/255,j.data[++p]=m*c.b/255,j.data[++p]=255}i.putImageData(j,0,0);var q=new THREE.Texture(h);q.needsUpdate=!0;var r=new THREE.MeshBasicMaterial({map:q,transparent:d<1,opacity:d});r.side=THREE.DoubleSide,THREE.Mesh.call(this,g,r),this.quaternion=new THREE.Quaternion(b.info.origin.orientation.x,b.info.origin.orientation.y,b.info.origin.orientation.z,b.info.origin.orientation.w),this.position.x=e*b.info.resolution/2+b.info.origin.position.x,this.position.y=f*b.info.resolution/2+b.info.origin.position.y,this.position.z=b.info.origin.position.z,this.scale.x=b.info.resolution,this.scale.y=b.info.resolution},ROS3D.OccupancyGrid.prototype.__proto__=THREE.Mesh.prototype,ROS3D.OccupancyGridClient=function(a){a=a||{},this.ros=a.ros,this.topicName=a.topic||"/map",this.continuous=a.continuous,this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.offsetPose=a.offsetPose||new ROSLIB.Pose,this.color=a.color||{r:255,g:255,b:255},this.opacity=a.opacity||1,this.currentGrid=null,this.rosTopic=void 0,this.subscribe()},ROS3D.OccupancyGridClient.prototype.__proto__=EventEmitter2.prototype,ROS3D.OccupancyGridClient.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.OccupancyGridClient.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"nav_msgs/OccupancyGrid",compression:"png"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.OccupancyGridClient.prototype.processMessage=function(a){this.currentGrid&&(this.currentGrid.tfClient&&this.currentGrid.unsubscribeTf(),this.rootObject.remove(this.currentGrid));var b=new ROS3D.OccupancyGrid({message:a,color:this.color,opacity:this.opacity});this.tfClient?(this.currentGrid=b,this.sceneNode=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:b,pose:this.offsetPose})):this.sceneNode=this.currentGrid=b,this.rootObject.add(this.sceneNode),this.emit("change"),this.continuous||this.rosTopic.unsubscribe()},ROS3D.Odometry=function(a){this.options=a||{},this.ros=a.ros,this.topicName=a.topic||"/particlecloud",this.tfClient=a.tfClient,this.color=a.color||13369599,this.length=a.length||1,this.rootObject=a.rootObject||new THREE.Object3D,this.keep=a.keep||1,THREE.Object3D.call(this),this.sns=[],this.rosTopic=void 0,this.subscribe()},ROS3D.Odometry.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Odometry.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.Odometry.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"nav_msgs/Odometry"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.Odometry.prototype.processMessage=function(a){this.sns.length>=this.keep&&(this.sns[0].unsubscribeTf(),this.rootObject.remove(this.sns[0]),this.sns.shift()),this.options.origin=new THREE.Vector3(a.pose.pose.position.x,a.pose.pose.position.y,a.pose.pose.position.z);var b=new THREE.Quaternion(a.pose.pose.orientation.x,a.pose.pose.orientation.y,a.pose.pose.orientation.z,a.pose.pose.orientation.w);this.options.direction=new THREE.Vector3(1,0,0),this.options.direction.applyQuaternion(b),this.options.material=new THREE.MeshBasicMaterial({color:this.color});var c=new ROS3D.Arrow(this.options);this.sns.push(new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:c})),this.rootObject.add(this.sns[this.sns.length-1])},ROS3D.Path=function(a){a=a||{},this.ros=a.ros,this.topicName=a.topic||"/path",this.tfClient=a.tfClient,this.color=a.color||13369599,this.rootObject=a.rootObject||new THREE.Object3D,THREE.Object3D.call(this),this.sn=null,this.line=null,this.rosTopic=void 0,this.subscribe()},ROS3D.Path.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Path.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.Path.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"nav_msgs/Path"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.Path.prototype.processMessage=function(a){null!==this.sn&&(this.sn.unsubscribeTf(),this.rootObject.remove(this.sn));for(var b=new THREE.Geometry,c=0;c<a.poses.length;c++){var d=new THREE.Vector3(a.poses[c].pose.position.x,a.poses[c].pose.position.y,a.poses[c].pose.position.z);b.vertices.push(d)}b.computeLineDistances();var e=new THREE.LineBasicMaterial({color:this.color}),f=new THREE.Line(b,e);this.sn=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:f}),this.rootObject.add(this.sn)},ROS3D.Point=function(a){this.options=a||{},this.ros=a.ros,this.topicName=a.topic||"/point",this.tfClient=a.tfClient,this.color=a.color||13369599,this.rootObject=a.rootObject||new THREE.Object3D,this.radius=a.radius||.2,THREE.Object3D.call(this),this.sn=null,this.rosTopic=void 0,this.subscribe()},ROS3D.Point.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Point.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.Point.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"geometry_msgs/PointStamped"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.Point.prototype.processMessage=function(a){null!==this.sn&&(this.sn.unsubscribeTf(),this.rootObject.remove(this.sn));var b=new THREE.SphereGeometry(this.radius),c=new THREE.MeshBasicMaterial({color:this.color}),d=new THREE.Mesh(b,c);d.position.set(a.point.x,a.point.y,a.point.z),this.sn=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:d}),this.rootObject.add(this.sn)},ROS3D.Polygon=function(a){a=a||{},this.ros=a.ros,this.topicName=a.topic||"/path",this.tfClient=a.tfClient,this.color=a.color||13369599,this.rootObject=a.rootObject||new THREE.Object3D,THREE.Object3D.call(this),this.sn=null,this.line=null,this.rosTopic=void 0,this.subscribe()},ROS3D.Polygon.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Polygon.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.Polygon.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"geometry_msgs/PolygonStamped"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.Polygon.prototype.processMessage=function(a){null!==this.sn&&(this.sn.unsubscribeTf(),this.rootObject.remove(this.sn));for(var b,c=new THREE.Geometry,d=0;d<a.polygon.points.length;d++)b=new THREE.Vector3(a.polygon.points[d].x,a.polygon.points[d].y,a.polygon.points[d].z),c.vertices.push(b);b=new THREE.Vector3(a.polygon.points[0].x,a.polygon.points[0].y,a.polygon.points[0].z),c.vertices.push(b),c.computeLineDistances();var e=new THREE.LineBasicMaterial({color:this.color}),f=new THREE.Line(c,e);this.sn=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:f}),this.rootObject.add(this.sn)},ROS3D.Pose=function(a){this.options=a||{},this.ros=a.ros,this.topicName=a.topic||"/pose",this.tfClient=a.tfClient,this.color=a.color||13369599,this.rootObject=a.rootObject||new THREE.Object3D,THREE.Object3D.call(this),this.sn=null,this.rosTopic=void 0,this.subscribe()},ROS3D.Pose.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Pose.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.Pose.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"geometry_msgs/PoseStamped"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.Pose.prototype.processMessage=function(a){null!==this.sn&&(this.sn.unsubscribeTf(),this.rootObject.remove(this.sn)),this.options.origin=new THREE.Vector3(a.pose.position.x,a.pose.position.y,a.pose.position.z);var b=new THREE.Quaternion(a.pose.orientation.x,a.pose.orientation.y,a.pose.orientation.z,a.pose.orientation.w);this.options.direction=new THREE.Vector3(1,0,0),this.options.direction.applyQuaternion(b),this.options.material=new THREE.MeshBasicMaterial({color:this.color});var c=new ROS3D.Arrow(this.options);this.sn=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:c}),this.rootObject.add(this.sn)},ROS3D.PoseArray=function(a){this.options=a||{},this.ros=a.ros,this.topicName=a.topic||"/particlecloud",this.tfClient=a.tfClient,this.color=a.color||13369599,this.length=a.length||1,this.rootObject=a.rootObject||new THREE.Object3D,THREE.Object3D.call(this),this.sn=null,this.rosTopic=void 0,this.subscribe()},ROS3D.PoseArray.prototype.__proto__=THREE.Object3D.prototype,ROS3D.PoseArray.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.PoseArray.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"geometry_msgs/PoseArray"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.PoseArray.prototype.processMessage=function(a){null!==this.sn&&(this.sn.unsubscribeTf(),this.rootObject.remove(this.sn));for(var b,c=new THREE.Object3D,d=0;d<a.poses.length;d++){var e=new THREE.Geometry,f=new THREE.Vector3(a.poses[d].position.x,a.poses[d].position.y,a.poses[d].position.z);e.vertices.push(f);var g=new THREE.Quaternion(a.poses[d].orientation.x,a.poses[d].orientation.y,a.poses[d].orientation.z,a.poses[d].orientation.w),h=new THREE.Vector3(this.length,0,0),i=new THREE.Vector3(.8*this.length,.2*this.length,0),j=new THREE.Vector3(.8*this.length,.2*-this.length,0);h.applyQuaternion(g),i.applyQuaternion(g),j.applyQuaternion(g),e.vertices.push(h.add(f)),e.vertices.push(i.add(f)),e.vertices.push(j.add(f)),e.vertices.push(h),e.computeLineDistances();var k=new THREE.LineBasicMaterial({color:this.color});b=new THREE.Line(e,k),c.add(b)}this.sn=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:c}),this.rootObject.add(this.sn)},ROS3D.PoseWithCovariance=function(a){this.options=a||{},this.ros=a.ros,this.topicName=a.topic||"/PoseWithCovariance",this.tfClient=a.tfClient,this.color=a.color||13369599,this.rootObject=a.rootObject||new THREE.Object3D,THREE.Object3D.call(this),this.sn=null,this.rosTopic=void 0,this.subscribe()},ROS3D.PoseWithCovariance.prototype.__proto__=THREE.Object3D.prototype,ROS3D.PoseWithCovariance.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.PoseWithCovariance.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"geometry_msgs/PoseWithCovarianceStamped"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.PoseWithCovariance.prototype.processMessage=function(a){null!==this.sn&&(this.sn.unsubscribeTf(),this.rootObject.remove(this.sn)),this.options.origin=new THREE.Vector3(a.pose.pose.position.x,a.pose.pose.position.y,a.pose.pose.position.z);var b=new THREE.Quaternion(a.pose.pose.orientation.x,a.pose.pose.orientation.y,a.pose.pose.orientation.z,a.pose.pose.orientation.w);this.options.direction=new THREE.Vector3(1,0,0),this.options.direction.applyQuaternion(b),this.options.material=new THREE.MeshBasicMaterial({color:this.color});var c=new ROS3D.Arrow(this.options);this.sn=new ROS3D.SceneNode({frameID:a.header.frame_id,tfClient:this.tfClient,object:c}),this.rootObject.add(this.sn)},ROS3D.LaserScan=function(a){a=a||{},this.ros=a.ros,this.topicName=a.topic||"/scan",this.color=a.color||16753920,this.particles=new ROS3D.Particles(a),this.rosTopic=void 0,this.subscribe()},ROS3D.LaserScan.prototype.__proto__=THREE.Object3D.prototype,ROS3D.LaserScan.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.LaserScan.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"sensor_msgs/LaserScan"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.LaserScan.prototype.processMessage=function(a){setFrame(this.particles,a.header.frame_id);for(var b=a.ranges.length,c=0;c<b;c++){var d=a.ranges[c];if(d<a.range_min||d>a.range_max)this.particles.alpha[c]=0;else{var e=a.angle_min+c*a.angle_increment;this.particles.points[c]=new THREE.Vector3(d*Math.cos(e),d*Math.sin(e),0),this.particles.alpha[c]=1}this.particles.colors[c]=new THREE.Color(this.color)}finishedUpdate(this.particles,b)},ROS3D.Particles=function(a){a=a||{},this.tfClient=a.tfClient;var b=a.texture||"https://upload.wikimedia.org/wikipedia/commons/a/a2/Pixel-white.png",c=a.size||.05;this.max_pts=a.max_pts||1e4,this.first_size=null,this.prev_pts=0,this.rootObject=a.rootObject||new THREE.Object3D;THREE.Object3D.call(this),this.vertex_shader=["attribute vec3 customColor;","attribute float alpha;","varying vec3 vColor;","varying float falpha;","void main() ","{"," vColor = customColor; // set color associated to vertex; use later in fragment shader"," vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );"," falpha = alpha; ",""," // option (1): draw particles at constant size on screen"," // gl_PointSize = size;"," // option (2): scale particles as objects in 3D space"," gl_PointSize = ",c,"* ( 300.0 / length( mvPosition.xyz ) );"," gl_Position = projectionMatrix * mvPosition;","}"].join("\n"),this.fragment_shader=["uniform sampler2D texture;","varying vec3 vColor; // colors associated to vertices; assigned by vertex shader","varying float falpha;","void main() ","{"," // THREE.Material.alphaTest is not evaluated for ShaderMaterial, so we"," // have to take care of this ourselves."," if (falpha < 0.5) discard;"," // calculates a color for the particle"," gl_FragColor = vec4( vColor, falpha );"," // sets particle texture to desired color"," gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );","}"].join("\n");var d={texture:{type:"t",value:(new THREE.TextureLoader).load(b)}};this.shaderMaterial=new THREE.ShaderMaterial({uniforms:d,vertexShader:this.vertex_shader,fragmentShader:this.fragment_shader,transparent:!0}),this.geom=new THREE.BufferGeometry;for(var e=[],f=[],g=[],h=0;h<this.max_pts;h++)e.push(0),e.push(0),e.push(0);this.geom.addAttribute("points",new THREE.Float32BufferAttribute(e,3)),this.geom.addAttribute("colors",new THREE.Float32BufferAttribute(f,3)),this.geom.addAttribute("alpha",new THREE.Float32BufferAttribute(g,1)),this.ps=new THREE.Points(this.geom,this.shaderMaterial),this.sn=null,this.points=this.geom.attributes.points,this.colors=this.geom.attributes.colors,this.alpha=this.geom.attributes.alpha};var BASE64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";ROS3D.PointCloud2=function(a){a=a||{},this.ros=a.ros,this.topicName=a.topic||"/points",this.color=a.color,this.particles=new ROS3D.Particles(a),this.rosTopic=void 0,this.subscribe()},ROS3D.PointCloud2.prototype.__proto__=THREE.Object3D.prototype,ROS3D.PointCloud2.prototype.unsubscribe=function(){this.rosTopic&&this.rosTopic.unsubscribe()},ROS3D.PointCloud2.prototype.subscribe=function(){this.unsubscribe(),this.rosTopic=new ROSLIB.Topic({ros:this.ros,name:this.topicName,messageType:"sensor_msgs/PointCloud2"}),this.rosTopic.subscribe(this.processMessage.bind(this))},ROS3D.PointCloud2.prototype.processMessage=function(a){setFrame(this.particles,a.header.frame_id);var b,c=a.height*a.width;b=a.data.buffer?a.data.buffer.buffer:Uint8Array.from(decode64(a.data)).buffer;var d,e=new DataView(b);void 0!==this.color&&(d=new THREE.Color(this.color));for(var f=0;f<c;f++){var g=read_point(a,f,e);this.particles.points[f]=new THREE.Vector3(g.x,g.y,g.z),this.particles.points.array[3*f]=g.x,this.particles.points.array[3*f+1]=g.y,this.particles.points.array[3*f+2]=g.z,this.particles.colors[f]=d||new THREE.Color(g.rgb),this.particles.alpha[f]=1}finishedUpdate(this.particles,c)},ROS3D.Urdf=function(a){a=a||{};var b=a.urdfModel,c=a.path||"/",d=a.tfClient,e=a.tfPrefix||"",f=a.loader||ROS3D.COLLADA_LOADER_2;THREE.Object3D.call(this);var g=b.links;for(var h in g)for(var i=g[h],j=0;j<i.visuals.length;j++){var k=i.visuals[j];if(k&&k.geometry){var l=e+"/"+i.name,m=null;if(k.material&&k.material.color){var n=k.material&&k.material.color;m=ROS3D.makeColorMaterial(n.r,n.g,n.b,n.a)}if(k.geometry.type===ROSLIB.URDF_MESH){var o=k.geometry.filename,p=o.indexOf("package://");-1!==p&&(o=o.substr(p+"package://".length));var q=o.substr(-4).toLowerCase();if(".dae"===q||".stl"===q){var r=new ROS3D.MeshResource({path:c,resource:o,loader:f,material:m});i.visuals[j].geometry.scale&&r.scale.copy(k.geometry.scale);var s=new ROS3D.SceneNode({frameID:l,pose:k.origin,tfClient:d,object:r});this.add(s)}else console.warn("Could not load geometry mesh: "+o)}else{m||(m=ROS3D.makeColorMaterial(0,0,0,1));var t;switch(k.geometry.type){case ROSLIB.URDF_BOX:var u=k.geometry.dimension,v=new THREE.BoxGeometry(u.x,u.y,u.z);t=new THREE.Mesh(v,m);break;case ROSLIB.URDF_CYLINDER:var w=k.geometry.radius,x=k.geometry.length,y=new THREE.CylinderGeometry(w,w,x,16,1,!1);t=new THREE.Mesh(y,m),t.quaternion.setFromAxisAngle(new THREE.Vector3(1,0,0),.5*Math.PI);break;case ROSLIB.URDF_SPHERE:var z=new THREE.SphereGeometry(k.geometry.radius,16);t=new THREE.Mesh(z,m)}var A=new ROS3D.SceneNode({frameID:l,pose:k.origin,tfClient:d,object:t});this.add(A)}}}},ROS3D.Urdf.prototype.__proto__=THREE.Object3D.prototype,ROS3D.Urdf.prototype.unsubscribeTf=function(){this.children.forEach(function(a){"function"==typeof a.unsubscribeTf&&a.unsubscribeTf()})},ROS3D.UrdfClient=function(a){var b=this;a=a||{};var c=a.ros;this.param=a.param||"robot_description",this.path=a.path||"/",this.tfClient=a.tfClient,this.rootObject=a.rootObject||new THREE.Object3D,this.tfPrefix=a.tfPrefix||"",this.loader=a.loader||ROS3D.COLLADA_LOADER_2,new ROSLIB.Param({ros:c,name:this.param}).get(function(a){var c=new ROSLIB.UrdfModel({string:a});b.urdf=new ROS3D.Urdf({urdfModel:c,path:b.path,tfClient:b.tfClient,tfPrefix:b.tfPrefix,loader:b.loader}),b.rootObject.add(b.urdf)})},ROS3D.Highlighter=function(a){a=a||{},this.mouseHandler=a.mouseHandler,this.hoverObjs={},this.mouseHandler.addEventListener("mouseover",this.onMouseOver.bind(this)),this.mouseHandler.addEventListener("mouseout",this.onMouseOut.bind(this))},ROS3D.Highlighter.prototype.onMouseOver=function(a){this.hoverObjs[a.currentTarget.uuid]=a.currentTarget},ROS3D.Highlighter.prototype.onMouseOut=function(a){var b=a.currentTarget.uuid;b in this.hoverObjs&&delete this.hoverObjs[b]},ROS3D.Highlighter.prototype.renderHighlights=function(a,b,c){this.makeEverythingInvisible(a),this.makeHighlightedVisible(a);var d=a.overrideMaterial;a.overrideMaterial=new THREE.MeshBasicMaterial({fog:!1,opacity:.5,transparent:!0,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetUnits:-1,side:THREE.DoubleSide}),b.render(a,c),a.overrideMaterial=d,this.restoreVisibility(a)},ROS3D.Highlighter.prototype.makeEverythingInvisible=function(a){a.traverse(function(a){(a instanceof THREE.Mesh||a instanceof THREE.Line||a instanceof THREE.Sprite)&&(a.previousVisibility=a.visible,a.visible=!1)})},ROS3D.Highlighter.prototype.makeHighlightedVisible=function(a){var b=function(a){(a instanceof THREE.Mesh||a instanceof THREE.Line||a instanceof THREE.Sprite)&&(a.visible=!0)};for(var c in this.hoverObjs){var d=this.hoverObjs[c];d.visible=!0,d.traverse(b)}},ROS3D.Highlighter.prototype.restoreVisibility=function(a){a.traverse(function(a){a.hasOwnProperty("previousVisibility")&&(a.visible=a.previousVisibility)}.bind(this))},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;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();if(-1!==a.type.indexOf("touch")){b=0,c=0;for(var f=0;f<a.touches.length;++f)b+=a.touches[f].clientX,c+=a.touches[f].clientY;b/=a.touches.length,c/=a.touches.length}else b=a.clientX,c=a.clientY;var g=b-e.left-d.clientLeft+d.scrollLeft,h=c-e.top-d.clientTop+d.scrollTop,i=g/d.clientWidth*2-1,j=-h/d.clientHeight*2+1,k=new THREE.Vector3(i,j,.5);k.unproject(this.camera);var l=new THREE.Raycaster(this.camera.position.clone(),k.sub(this.camera.position).normalize());l.linePrecision=.001;var m=l.ray,n={
mousePos:new THREE.Vector2(i,j),mouseRay:m,domEvent:a,camera:this.camera,intersection:this.lastIntersection};if("mouseout"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",n),this.dragging=!1),this.notify(this.lastTarget,"mouseout",n),void(this.lastTarget=null);if("touchleave"===a.type||"touchend"===a.type)return this.dragging&&(this.notify(this.lastTarget,"mouseup",n),this.dragging=!1),this.notify(this.lastTarget,"touchend",n),void(this.lastTarget=null);if(this.dragging)return this.notify(this.lastTarget,a.type,n),void(("mouseup"===a.type&&2===a.button||"click"===a.type||"touchend"===a.type)&&(this.dragging=!1));d=this.lastTarget;var o=[];if(o=l.intersectObject(this.rootObject,!0),o.length>0?(d=o[0].object,n.intersection=this.lastIntersection=o[0]):d=this.fallbackTarget,d!==this.lastTarget&&a.type.match(/mouse/)){var p=this.notify(d,"mouseover",n);0===p?this.notify(this.lastTarget,"mouseout",n):1===p&&(d=this.fallbackTarget)!==this.lastTarget&&(this.notify(d,"mouseover",n),this.notify(this.lastTarget,"mouseout",n))}if(d!==this.lastTarget&&a.type.match(/touch/)){this.notify(d,a.type,n)?(this.notify(this.lastTarget,"touchleave",n),this.notify(this.lastTarget,"touchend",n)):(d=this.fallbackTarget)!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",n),this.notify(this.lastTarget,"touchend",n))}this.notify(d,a.type,n),"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.continueBubble=!1,c.stopPropagation=function(){c.cancelBubble=!0},c.continuePropagation=function(){c.continueBubble=!0},c.currentTarget=a;c.currentTarget;){if(c.currentTarget.dispatchEvent&&c.currentTarget.dispatchEvent instanceof Function){if(c.currentTarget.dispatchEvent(c),c.cancelBubble)return this.dispatchEvent(c),0;if(c.continueBubble)return 2}c.currentTarget=c.currentTarget.parent}return 1},Object.assign(ROS3D.MouseHandler.prototype,THREE.EventDispatcher.prototype),ROS3D.OrbitControls=function(a){function b(a){var b=a.domEvent;switch(b.preventDefault(),b.button){case 0:A=z.ROTATE,n.set(b.clientX,b.clientY);break;case 1:A=z.MOVE,u=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);u.applyMatrix4(c),t=j.center.clone(),v=j.camera.position.clone(),w=d(a.mouseRay,t,u);break;case 2:A=z.ZOOM,q.set(b.clientX,b.clientY)}this.showAxes()}function c(a){var b=a.domEvent;if(A===z.ROTATE)o.set(b.clientX,b.clientY),p.subVectors(o,n),j.rotateLeft(2*Math.PI*p.x/l*j.userRotateSpeed),j.rotateUp(2*Math.PI*p.y/l*j.userRotateSpeed),n.copy(o),this.showAxes();else if(A===z.ZOOM)r.set(b.clientX,b.clientY),s.subVectors(r,q),s.y>0?j.zoomIn():j.zoomOut(),q.copy(r),this.showAxes();else if(A===z.MOVE){var c=d(a.mouseRay,j.center,u);if(!c)return;var e=(new THREE.Vector3).subVectors(w.clone(),c.clone());j.center.addVectors(t.clone(),e.clone()),j.camera.position.addVectors(v.clone(),e.clone()),j.update(),j.camera.updateMatrixWorld(),this.showAxes()}}function d(a,b,c){var d=new THREE.Vector3;new THREE.Vector3;d.subVectors(b,a.origin);var e=a.direction.dot(c);if(Math.abs(e)<a.precision)return null;var f=c.dot(d)/e;return a.direction.clone().multiplyScalar(f)}function e(a){j.userRotate&&(A=z.NONE)}function f(a){if(j.userZoom){var b,c=a.domEvent;b=void 0!==c.wheelDelta?c.wheelDelta:-c.detail,b>0?j.zoomIn():j.zoomOut(),this.showAxes()}}function g(a){var b=a.domEvent;switch(b.touches.length){case 1:A=z.ROTATE,n.set(b.touches[0].pageX-window.scrollX,b.touches[0].pageY-window.scrollY);break;case 2:A=z.NONE,u=new THREE.Vector3(0,0,1);var c=(new THREE.Matrix4).extractRotation(this.camera.matrix);u.applyMatrix4(c),t=j.center.clone(),v=j.camera.position.clone(),w=d(a.mouseRay,t,u),x[0]=new THREE.Vector2(b.touches[0].pageX,b.touches[0].pageY),x[1]=new THREE.Vector2(b.touches[1].pageX,b.touches[1].pageY),y[0]=new THREE.Vector2(0,0),y[1]=new THREE.Vector2(0,0)}this.showAxes(),b.preventDefault()}function h(a){var b=a.domEvent;if(A===z.ROTATE)o.set(b.touches[0].pageX-window.scrollX,b.touches[0].pageY-window.scrollY),p.subVectors(o,n),j.rotateLeft(2*Math.PI*p.x/l*j.userRotateSpeed),j.rotateUp(2*Math.PI*p.y/l*j.userRotateSpeed),n.copy(o),this.showAxes();else{if(y[0].set(x[0].x-b.touches[0].pageX,x[0].y-b.touches[0].pageY),y[1].set(x[1].x-b.touches[1].pageX,x[1].y-b.touches[1].pageY),y[0].lengthSq()>m&&y[1].lengthSq()>m&&(x[0].set(b.touches[0].pageX,b.touches[0].pageY),x[1].set(b.touches[1].pageX,b.touches[1].pageY),y[0].dot(y[1])>0&&A!==z.ZOOM?A=z.MOVE:y[0].dot(y[1])<0&&A!==z.MOVE&&(A=z.ZOOM),A===z.ZOOM)){var c=new THREE.Vector2;c.subVectors(x[0],x[1]),y[0].dot(c)<0&&y[1].dot(c)>0?j.zoomOut():y[0].dot(c)>0&&y[1].dot(c)<0&&j.zoomIn()}if(A===z.MOVE){var e=d(a.mouseRay,j.center,u);if(!e)return;var f=(new THREE.Vector3).subVectors(w.clone(),e.clone());j.center.addVectors(t.clone(),f.clone()),j.camera.position.addVectors(v.clone(),f.clone()),j.update(),j.camera.updateMatrixWorld()}this.showAxes(),b.preventDefault()}}function i(a){var b=a.domEvent;1===b.touches.length&&A!==z.ROTATE?(A=z.ROTATE,n.set(b.touches[0].pageX-window.scrollX,b.touches[0].pageY-window.scrollY)):A=z.NONE}THREE.EventDispatcher.call(this);var j=this;a=a||{};var k=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 l=1800,m=10,n=new THREE.Vector2,o=new THREE.Vector2,p=new THREE.Vector2,q=new THREE.Vector2,r=new THREE.Vector2,s=new THREE.Vector2,t=new THREE.Vector3,u=new THREE.Vector3,v=new THREE.Vector3,w=new THREE.Vector3,x=new Array(2),y=new Array(2);this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new THREE.Vector3;var z={NONE:-1,ROTATE:0,ZOOM:1,MOVE:2},A=z.NONE;this.axes=new ROS3D.Axes({shaftRadius:.025,headRadius:.07,headLength:.2}),k.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",i),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;d=Math.max(1e-6,Math.min(Math.PI-1e-6,d));var e=b.length();b.set(e*Math.sin(d)*Math.cos(c),e*Math.sin(d)*Math.sin(c),e*Math.cos(d)),b.multiplyScalar(this.scale),a.copy(this.center).add(b),this.camera.lookAt(this.center),e=b.length(),this.axes.position.copy(this.center),this.axes.scale.set(.05*e,.05*e,.05*e),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))},Object.assign(ROS3D.OrbitControls.prototype,THREE.EventDispatcher.prototype),ROS3D.SceneNode=function(a){a=a||{};var b=this;this.tfClient=a.tfClient,this.frameID=a.frameID;var c=a.object;this.pose=a.pose||new ROSLIB.Pose,THREE.Object3D.call(this),this.visible=!1,this.add(c),this.updatePose(this.pose),this.tfUpdate=function(a){var c=new ROSLIB.Transform(a),d=new ROSLIB.Pose(b.pose);d.applyTransform(c),b.updatePose(d),b.visible=!0},this.tfClient.subscribe(this.frameID,this.tfUpdate)},ROS3D.SceneNode.prototype.__proto__=THREE.Object3D.prototype,ROS3D.SceneNode.prototype.updatePose=function(a){this.position.set(a.position.x,a.position.y,a.position.z),this.quaternion.set(a.orientation.x,a.orientation.y,a.orientation.z,a.orientation.w),this.updateMatrixWorld(!0)},ROS3D.SceneNode.prototype.unsubscribeTf=function(){this.tfClient.unsubscribe(this.frameID,this.tfUpdate)},ROS3D.Viewer=function(a){a=a||{};var b=a.divID,c=a.width,d=a.height,e=a.background||"#111111",f=a.antialias,g=a.intensity||.66,h=a.near||.01,i=a.far||1e3,j=a.alpha||1,k=a.cameraPose||{x:3,y:3,z:3},l=a.cameraZoomSpeed||.5;this.renderer=new THREE.WebGLRenderer({antialias:f,alpha:!0}),this.renderer.setClearColor(parseInt(e.replace("#","0x"),16),j),this.renderer.sortObjects=!1,this.renderer.setSize(c,d),this.renderer.shadowMap.enabled=!1,this.renderer.autoClear=!1,this.scene=new THREE.Scene,this.camera=new THREE.PerspectiveCamera(40,c/d,h,i),this.camera.position.x=k.x,this.camera.position.y=k.y,this.camera.position.z=k.z,this.cameraControls=new ROS3D.OrbitControls({scene:this.scene,camera:this.camera}),this.cameraControls.userZoomSpeed=l,this.scene.add(new THREE.AmbientLight(5592405)),this.directionalLight=new THREE.DirectionalLight(16777215,g),this.scene.add(this.directionalLight),this.selectableObjects=new THREE.Object3D,this.scene.add(this.selectableObjects);var m=new ROS3D.MouseHandler({renderer:this.renderer,camera:this.camera,rootObject:this.selectableObjects,fallbackTarget:this.cameraControls});this.highlighter=new ROS3D.Highlighter({mouseHandler:m}),this.stopped=!0,this.animationRequestId=void 0,document.getElementById(b).appendChild(this.renderer.domElement),this.start()},ROS3D.Viewer.prototype.start=function(){this.stopped=!1,this.draw()},ROS3D.Viewer.prototype.draw=function(){this.stopped||(this.cameraControls.update(),this.directionalLight.position=this.camera.localToWorld(new THREE.Vector3(-1,1,0)),this.directionalLight.position.normalize(),this.renderer.clear(!0,!0,!0),this.renderer.render(this.scene,this.camera),this.highlighter.renderHighlights(this.scene,this.renderer,this.camera),this.animationRequestId=requestAnimationFrame(this.draw.bind(this)))},ROS3D.Viewer.prototype.stop=function(){this.stopped||cancelAnimationFrame(this.animationRequestId),this.stopped=!0},ROS3D.Viewer.prototype.addObject=function(a,b){b?this.selectableObjects.add(a):this.scene.add(a)},ROS3D.Viewer.prototype.resize=function(a,b){this.camera.aspect=a/b,this.camera.updateProjectionMatrix(),this.renderer.setSize(a,b)};