aframe-leap-hands
Version:
Leap Motion components for A-Frame VR
1 lines • 93.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.aframeLeapHands={})}(this,function(t){!function(t,e,n){function i(n,o){if(!e[n]){if(!t[n]){var s="function"==typeof require&&require;if(!o&&s)return s(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var a=e[n]={exports:{}};t[n][0].call(a.exports,function(e){var r=t[n][1][e];return i(r||e)},a,a.exports)}return e[n].exports}for(var r="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o])}({1:[function(t,e,n){t("./pointable");var i=t("gl-matrix"),r=i.vec3,o=i.mat3,s=i.mat4,a=(t("underscore"),e.exports=function(t,e){this.finger=t,this._center=null,this._matrix=null,this.type=e.type,this.prevJoint=e.prevJoint,this.nextJoint=e.nextJoint,this.width=e.width;var n=new Array(3);r.sub(n,e.nextJoint,e.prevJoint),this.length=r.length(n),this.basis=e.basis});a.prototype.left=function(){return this._left?this._left:(this._left=o.determinant(this.basis[0].concat(this.basis[1]).concat(this.basis[2]))<0,this._left)},a.prototype.matrix=function(){if(this._matrix)return this._matrix;var t=this.basis,e=this._matrix=s.create();return e[0]=t[0][0],e[1]=t[0][1],e[2]=t[0][2],e[4]=t[1][0],e[5]=t[1][1],e[6]=t[1][2],e[8]=t[2][0],e[9]=t[2][1],e[10]=t[2][2],e[3]=this.center()[0],e[7]=this.center()[1],e[11]=this.center()[2],this.left()&&(e[0]*=-1,e[1]*=-1,e[2]*=-1),this._matrix},a.prototype.lerp=function(t,e){r.lerp(t,this.prevJoint,this.nextJoint,e)},a.prototype.center=function(){if(this._center)return this._center;var t=r.create();return this.lerp(t,.5),this._center=t,t},a.prototype.direction=function(){return[-1*this.basis[2][0],-1*this.basis[2][1],-1*this.basis[2][2]]}},{"./pointable":14,"gl-matrix":23,underscore:24}],2:[function(t,e,n){var i=e.exports=function(t){this.pos=0,this._buf=[],this.size=t};i.prototype.get=function(t){if(void 0==t&&(t=0),!(t>=this.size||t>=this._buf.length))return this._buf[(this.pos-t-1)%this.size]},i.prototype.push=function(t){return this._buf[this.pos%this.size]=t,this.pos++}},{}],3:[function(t,e,n){var i=t("../protocol").chooseProtocol,r=t("events").EventEmitter,o=t("underscore"),s=e.exports=function(t){this.opts=o.defaults(t||{},{host:"127.0.0.1",enableGestures:!1,scheme:this.getScheme(),port:this.getPort(),background:!1,optimizeHMD:!1,requestProtocolVersion:s.defaultProtocolVersion}),this.host=this.opts.host,this.port=this.opts.port,this.scheme=this.opts.scheme,this.protocolVersionVerified=!1,this.background=null,this.optimizeHMD=null,this.on("ready",function(){this.enableGestures(this.opts.enableGestures),this.setBackground(this.opts.background),this.setOptimizeHMD(this.opts.optimizeHMD),this.opts.optimizeHMD?console.log("Optimized for head mounted display usage."):console.log("Optimized for desktop usage.")})};s.defaultProtocolVersion=6,s.prototype.getUrl=function(){return this.scheme+"//"+this.host+":"+this.port+"/v"+this.opts.requestProtocolVersion+".json"},s.prototype.getScheme=function(){return"ws:"},s.prototype.getPort=function(){return 6437},s.prototype.setBackground=function(t){this.opts.background=t,this.protocol&&this.protocol.sendBackground&&this.background!==this.opts.background&&(this.background=this.opts.background,this.protocol.sendBackground(this,this.opts.background))},s.prototype.setOptimizeHMD=function(t){this.opts.optimizeHMD=t,this.protocol&&this.protocol.sendOptimizeHMD&&this.optimizeHMD!==this.opts.optimizeHMD&&(this.optimizeHMD=this.opts.optimizeHMD,this.protocol.sendOptimizeHMD(this,this.opts.optimizeHMD))},s.prototype.handleOpen=function(){this.connected||(this.connected=!0,this.emit("connect"))},s.prototype.enableGestures=function(t){this.gesturesEnabled=!!t,this.send(this.protocol.encode({enableGestures:this.gesturesEnabled}))},s.prototype.handleClose=function(t,e){this.connected&&(this.disconnect(),1001===t&&this.opts.requestProtocolVersion>1&&(this.protocolVersionVerified?this.protocolVersionVerified=!1:this.opts.requestProtocolVersion--),this.startReconnection())},s.prototype.startReconnection=function(){var t=this;this.reconnectionTimer||(this.reconnectionTimer=setInterval(function(){t.reconnect()},500))},s.prototype.stopReconnection=function(){this.reconnectionTimer=clearInterval(this.reconnectionTimer)},s.prototype.disconnect=function(t){if(t||this.stopReconnection(),this.socket)return this.socket.close(),delete this.socket,delete this.protocol,delete this.background,delete this.optimizeHMD,delete this.focusedState,this.connected&&(this.connected=!1,this.emit("disconnect")),!0},s.prototype.reconnect=function(){this.connected?this.stopReconnection():(this.disconnect(!0),this.connect())},s.prototype.handleData=function(t){var e,n=JSON.parse(t);void 0===this.protocol?(e=this.protocol=i(n),this.protocolVersionVerified=!0,this.emit("ready")):e=this.protocol(n),this.emit(e.type,e)},s.prototype.connect=function(){if(!this.socket)return this.socket=this.setupSocket(),!0},s.prototype.send=function(t){this.socket.send(t)},s.prototype.reportFocus=function(t){this.connected&&this.focusedState!==t&&(this.focusedState=t,this.emit(this.focusedState?"focus":"blur"),this.protocol&&this.protocol.sendFocused&&this.protocol.sendFocused(this,this.focusedState))},o.extend(s.prototype,r.prototype)},{"../protocol":15,events:21,underscore:24}],4:[function(t,e,n){var i=e.exports=t("./base"),r=t("underscore"),o=e.exports=function(t){i.call(this,t);var e=this;this.on("ready",function(){e.startFocusLoop()}),this.on("disconnect",function(){e.stopFocusLoop()})};r.extend(o.prototype,i.prototype),o.__proto__=i,o.prototype.useSecure=function(){return"https:"===location.protocol},o.prototype.getScheme=function(){return this.useSecure()?"wss:":"ws:"},o.prototype.getPort=function(){return this.useSecure()?6436:6437},o.prototype.setupSocket=function(){var t=this,e=new WebSocket(this.getUrl());return e.onopen=function(){t.handleOpen()},e.onclose=function(e){t.handleClose(e.code,e.reason)},e.onmessage=function(e){t.handleData(e.data)},e.onerror=function(e){t.useSecure()&&"wss:"===t.scheme&&(t.scheme="ws:",t.port=6437,t.disconnect(),t.connect())},e},o.prototype.startFocusLoop=function(){if(!this.focusDetectorTimer){var t=this,e=null;e=void 0!==document.hidden?"hidden":void 0!==document.mozHidden?"mozHidden":void 0!==document.msHidden?"msHidden":void 0!==document.webkitHidden?"webkitHidden":void 0,void 0===t.windowVisible&&(t.windowVisible=void 0===e||!1===document[e]);var n=window.addEventListener("focus",function(e){t.windowVisible=!0,r()}),i=window.addEventListener("blur",function(e){t.windowVisible=!1,r()});this.on("disconnect",function(){window.removeEventListener("focus",n),window.removeEventListener("blur",i)});var r=function(){var n=void 0===e||!1===document[e];t.reportFocus(n&&t.windowVisible)};r(),this.focusDetectorTimer=setInterval(r,100)}},o.prototype.stopFocusLoop=function(){this.focusDetectorTimer&&(clearTimeout(this.focusDetectorTimer),delete this.focusDetectorTimer)}},{"./base":3,underscore:24}],5:[function(t,e,n){var i=t("__browserify_process"),r=t("./frame"),o=t("./hand"),s=t("./pointable"),a=t("./finger"),c=t("./circular_buffer"),u=t("./pipeline"),h=t("events").EventEmitter,l=t("./gesture").gestureListener,p=t("./dialog"),d=t("underscore"),f=e.exports=function(e){var n=this;e=d.defaults(e||{},{inNode:void 0!==i&&i.versions&&i.versions.node}),this.inNode=e.inNode,e=d.defaults(e||{},{frameEventName:this.useAnimationLoop()?"animationFrame":"deviceFrame",suppressAnimationLoop:!this.useAnimationLoop(),loopWhileDisconnected:!0,useAllPlugins:!1,checkVersion:!0}),this.animationFrameRequested=!1,this.onAnimationFrame=function(t){n.lastConnectionFrame.valid&&n.emit("animationFrame",n.lastConnectionFrame),n.emit("frameEnd",t),n.loopWhileDisconnected&&(!1!==n.connection.focusedState||n.connection.opts.background)?window.requestAnimationFrame(n.onAnimationFrame):n.animationFrameRequested=!1},this.suppressAnimationLoop=e.suppressAnimationLoop,this.loopWhileDisconnected=e.loopWhileDisconnected,this.frameEventName=e.frameEventName,this.useAllPlugins=e.useAllPlugins,this.history=new c(200),this.lastFrame=r.Invalid,this.lastValidFrame=r.Invalid,this.lastConnectionFrame=r.Invalid,this.accumulatedGestures=[],this.checkVersion=e.checkVersion,this.connectionType=void 0===e.connectionType?this.inBrowser()?t("./connection/browser"):t("./connection/node"):e.connectionType,this.connection=new this.connectionType(e),this.streamingCount=0,this.devices={},this.plugins={},this._pluginPipelineSteps={},this._pluginExtendedMethods={},e.useAllPlugins&&this.useRegisteredPlugins(),this.setupFrameEvents(e),this.setupConnectionEvents(),this.startAnimationLoop()};f.prototype.gesture=function(t,e){var n=l(this,t);return void 0!==e&&n.stop(e),n},f.prototype.setBackground=function(t){return this.connection.setBackground(t),this},f.prototype.setOptimizeHMD=function(t){return this.connection.setOptimizeHMD(t),this},f.prototype.inBrowser=function(){return!this.inNode},f.prototype.useAnimationLoop=function(){return this.inBrowser()&&!this.inBackgroundPage()},f.prototype.inBackgroundPage=function(){return"undefined"!=typeof chrome&&chrome.extension&&chrome.extension.getBackgroundPage&&chrome.extension.getBackgroundPage()===window},f.prototype.connect=function(){return this.connection.connect(),this},f.prototype.streaming=function(){return this.streamingCount>0},f.prototype.connected=function(){return!!this.connection.connected},f.prototype.startAnimationLoop=function(){this.suppressAnimationLoop||this.animationFrameRequested||(this.animationFrameRequested=!0,window.requestAnimationFrame(this.onAnimationFrame))},f.prototype.disconnect=function(){return this.connection.disconnect(),this},f.prototype.frame=function(t){return this.history.get(t)||r.Invalid},f.prototype.loop=function(t){return t&&("function"==typeof t?this.on(this.frameEventName,t):this.setupFrameEvents(t)),this.connect()},f.prototype.addStep=function(t){this.pipeline||(this.pipeline=new u(this)),this.pipeline.addStep(t)},f.prototype.processFrame=function(t){t.gestures&&(this.accumulatedGestures=this.accumulatedGestures.concat(t.gestures)),this.lastConnectionFrame=t,this.startAnimationLoop(),this.emit("deviceFrame",t)},f.prototype.processFinishedFrame=function(t){if(this.lastFrame=t,t.valid&&(this.lastValidFrame=t),t.controller=this,t.historyIdx=this.history.push(t),t.gestures){t.gestures=this.accumulatedGestures,this.accumulatedGestures=[];for(var e=0;e!=t.gestures.length;e++)this.emit("gesture",t.gestures[e],t)}this.pipeline&&((t=this.pipeline.run(t))||(t=r.Invalid)),this.emit("frame",t),this.emitHandEvents(t)},f.prototype.emitHandEvents=function(t){for(var e=0;e<t.hands.length;e++)this.emit("hand",t.hands[e])},f.prototype.setupFrameEvents=function(t){t.frame&&this.on("frame",t.frame),t.hand&&this.on("hand",t.hand)},f.prototype.setupConnectionEvents=function(){var t=this;this.connection.on("frame",function(e){t.processFrame(e)}),this.on(this.frameEventName,function(e){t.processFinishedFrame(e)});var e=function(){if(t.connection.opts.requestProtocolVersion<5&&0==t.streamingCount){t.streamingCount=1;var n={attached:!0,streaming:!0,type:"unknown",id:"Lx00000000000"};t.devices[n.id]=n,t.emit("deviceAttached",n),t.emit("deviceStreaming",n),t.emit("streamingStarted",n),t.connection.removeListener("frame",e)}},n=function(){if(t.streamingCount>0){for(var e in t.devices)t.emit("deviceStopped",t.devices[e]),t.emit("deviceRemoved",t.devices[e]);for(var e in t.emit("streamingStopped",t.devices[e]),t.streamingCount=0,t.devices)delete t.devices[e]}};this.connection.on("focus",function(){t.loopWhileDisconnected&&t.startAnimationLoop(),t.emit("focus")}),this.connection.on("blur",function(){t.emit("blur")}),this.connection.on("protocol",function(e){e.on("beforeFrameCreated",function(e){t.emit("beforeFrameCreated",e)}),e.on("afterFrameCreated",function(e,n){t.emit("afterFrameCreated",e,n)}),t.emit("protocol",e)}),this.connection.on("ready",function(){t.checkVersion&&!t.inNode&&t.checkOutOfDate(),t.emit("ready")}),this.connection.on("connect",function(){t.emit("connect"),t.connection.removeListener("frame",e),t.connection.on("frame",e)}),this.connection.on("disconnect",function(){t.emit("disconnect"),n()}),this.connection.on("deviceConnect",function(i){i.state?(t.emit("deviceConnected"),t.connection.removeListener("frame",e),t.connection.on("frame",e)):(t.emit("deviceDisconnected"),n())}),this.connection.on("deviceEvent",function(e){var n=e.state,i=t.devices[n.id],r={};for(var o in n)i&&i.hasOwnProperty(o)&&i[o]==n[o]||(r[o]=!0);t.devices[n.id]=n,r.attached&&t.emit(n.attached?"deviceAttached":"deviceRemoved",n),r.streaming&&(n.streaming?(t.streamingCount++,t.emit("deviceStreaming",n),1==t.streamingCount&&t.emit("streamingStarted",n),r.attached||t.emit("deviceConnected")):r.attached&&n.attached||(t.streamingCount--,t.emit("deviceStopped",n),0==t.streamingCount&&t.emit("streamingStopped",n),t.emit("deviceDisconnected")))}),this.on("newListener",function(t,e){"deviceConnected"!=t&&"deviceDisconnected"!=t||console.warn(t+" events are depricated. Consider using 'streamingStarted/streamingStopped' or 'deviceStreaming/deviceStopped' instead")})},f.prototype.checkOutOfDate=function(){console.assert(this.connection&&this.connection.protocol);var t=this.connection.protocol.serviceVersion,e=this.connection.protocol.version,n=this.connectionType.defaultProtocolVersion;return n>e&&(console.warn("Your Protocol Version is v"+e+", this app was designed for v"+n),p.warnOutOfDate({sV:t,pV:e}),!0)},f._pluginFactories={},f.plugin=function(t,e){return this._pluginFactories[t]&&console.warn('Plugin "'+t+'" already registered'),this._pluginFactories[t]=e},f.plugins=function(){return d.keys(this._pluginFactories)};var m=function(t,e,n){-1!=["beforeFrameCreated","afterFrameCreated"].indexOf(e)?this.on(e,n):(this.pipeline||(this.pipeline=new u(this)),this._pluginPipelineSteps[t]||(this._pluginPipelineSteps[t]=[]),this._pluginPipelineSteps[t].push(this.pipeline.addWrappedStep(e,n)))},v=function(t,e,n){var i;switch(this._pluginExtendedMethods[t]||(this._pluginExtendedMethods[t]=[]),e){case"frame":i=r;break;case"hand":i=o;break;case"pointable":i=s,d.extend(a.prototype,n),d.extend(a.Invalid,n);break;case"finger":i=a;break;default:throw t+' specifies invalid object type "'+e+'" for prototypical extension'}d.extend(i.prototype,n),d.extend(i.Invalid,n),this._pluginExtendedMethods[t].push([i,n])};f.prototype.use=function(t,e){var n,i,r,o;if(!(i="function"==typeof t?t:f._pluginFactories[t]))throw"Leap Plugin "+t+" not found.";if(e||(e={}),this.plugins[t])return d.extend(this.plugins[t],e),this;for(r in this.plugins[t]=e,o=i.call(this,e))"function"==typeof(n=o[r])?m.call(this,t,r,n):v.call(this,t,r,n);return this},f.prototype.stopUsing=function(t){var e,n=this._pluginPipelineSteps[t],i=this._pluginExtendedMethods[t],r=0;if(this.plugins[t]){if(n)for(r=0;r<n.length;r++)this.pipeline.removeStep(n[r]);if(i)for(r=0;r<i.length;r++)for(var o in e=i[r][0],i[r][1])delete e.prototype[o],delete e.Invalid[o];return delete this.plugins[t],this}},f.prototype.useRegisteredPlugins=function(){for(var t in f._pluginFactories)this.use(t)},d.extend(f.prototype,h.prototype)},{"./circular_buffer":2,"./connection/browser":4,"./connection/node":20,"./dialog":6,"./finger":7,"./frame":8,"./gesture":9,"./hand":10,"./pipeline":13,"./pointable":14,__browserify_process:22,events:21,underscore:24}],6:[function(t,e,n){var i=t("__browserify_process"),r=e.exports=function(t,e){this.options=e||{},this.message=t,this.createElement()};r.prototype.createElement=function(){this.element=document.createElement("div"),this.element.className="leapjs-dialog",this.element.style.position="fixed",this.element.style.top="8px",this.element.style.left=0,this.element.style.right=0,this.element.style.textAlign="center",this.element.style.zIndex=1e3;var t=document.createElement("div");this.element.appendChild(t),t.style.className="leapjs-dialog",t.style.display="inline-block",t.style.margin="auto",t.style.padding="8px",t.style.color="#222",t.style.background="#eee",t.style.borderRadius="4px",t.style.border="1px solid #999",t.style.textAlign="left",t.style.cursor="pointer",t.style.whiteSpace="nowrap",t.style.transition="box-shadow 1s linear",t.innerHTML=this.message,this.options.onclick&&t.addEventListener("click",this.options.onclick),this.options.onmouseover&&t.addEventListener("mouseover",this.options.onmouseover),this.options.onmouseout&&t.addEventListener("mouseout",this.options.onmouseout),this.options.onmousemove&&t.addEventListener("mousemove",this.options.onmousemove)},r.prototype.show=function(){return document.body.appendChild(this.element),this},r.prototype.hide=function(){return document.body.removeChild(this.element),this},r.warnOutOfDate=function(t){t||(t={});var e="http://developer.leapmotion.com?";for(var n in t.returnTo=window.location.href,t)e+=n+"="+encodeURIComponent(t[n])+"&";var i;return(i=new r("This site requires Leap Motion Tracking V2.<button id='leapjs-accept-upgrade' style='color: #444; transition: box-shadow 100ms linear; cursor: pointer; vertical-align: baseline; margin-left: 16px;'>Upgrade</button><button id='leapjs-decline-upgrade' style='color: #444; transition: box-shadow 100ms linear; cursor: pointer; vertical-align: baseline; margin-left: 8px; '>Not Now</button>",{onclick:function(t){if("leapjs-decline-upgrade"!=t.target.id){var n=window.open(e,"_blank","height=800,width=1000,location=1,menubar=1,resizable=1,status=1,toolbar=1,scrollbars=1");window.focus&&n.focus()}return i.hide(),!0},onmousemove:function(t){t.target==document.getElementById("leapjs-decline-upgrade")?(document.getElementById("leapjs-decline-upgrade").style.color="#000",document.getElementById("leapjs-decline-upgrade").style.boxShadow="0px 0px 2px #5daa00",document.getElementById("leapjs-accept-upgrade").style.color="#444",document.getElementById("leapjs-accept-upgrade").style.boxShadow="none"):(document.getElementById("leapjs-accept-upgrade").style.color="#000",document.getElementById("leapjs-accept-upgrade").style.boxShadow="0px 0px 2px #5daa00",document.getElementById("leapjs-decline-upgrade").style.color="#444",document.getElementById("leapjs-decline-upgrade").style.boxShadow="none")},onmouseout:function(){document.getElementById("leapjs-decline-upgrade").style.color="#444",document.getElementById("leapjs-decline-upgrade").style.boxShadow="none",document.getElementById("leapjs-accept-upgrade").style.color="#444",document.getElementById("leapjs-accept-upgrade").style.boxShadow="none"}})).show()},r.hasWarnedBones=!1,r.warnBones=function(){this.hasWarnedBones||(this.hasWarnedBones=!0,console.warn("Your Leap Service is out of date"),void 0!==i&&i.versions&&i.versions.node||this.warnOutOfDate({reason:"bones"}))}},{__browserify_process:22}],7:[function(t,e,n){var i=t("./pointable"),r=t("./bone"),o=t("./dialog"),s=t("underscore"),a=e.exports=function(t){i.call(this,t),this.dipPosition=t.dipPosition,this.pipPosition=t.pipPosition,this.mcpPosition=t.mcpPosition,this.carpPosition=t.carpPosition,this.extended=t.extended,this.type=t.type,this.finger=!0,this.positions=[this.carpPosition,this.mcpPosition,this.pipPosition,this.dipPosition,this.tipPosition],t.bases?this.addBones(t):o.warnBones()};s.extend(a.prototype,i.prototype),a.prototype.addBones=function(t){this.metacarpal=new r(this,{type:0,width:this.width,prevJoint:this.carpPosition,nextJoint:this.mcpPosition,basis:t.bases[0]}),this.proximal=new r(this,{type:1,width:this.width,prevJoint:this.mcpPosition,nextJoint:this.pipPosition,basis:t.bases[1]}),this.medial=new r(this,{type:2,width:this.width,prevJoint:this.pipPosition,nextJoint:this.dipPosition,basis:t.bases[2]}),this.distal=new r(this,{type:3,width:this.width,prevJoint:this.dipPosition,nextJoint:t.btipPosition,basis:t.bases[3]}),this.bones=[this.metacarpal,this.proximal,this.medial,this.distal]},a.prototype.toString=function(){return"Finger [ id:"+this.id+" "+this.length+"mmx | width:"+this.width+"mm | direction:"+this.direction+" ]"},a.Invalid={valid:!1}},{"./bone":1,"./dialog":6,"./pointable":14,underscore:24}],8:[function(t,e,n){var i=t("./hand"),r=t("./pointable"),o=t("./gesture").createGesture,s=t("gl-matrix"),a=s.mat3,c=s.vec3,u=t("./interaction_box"),h=t("./finger"),l=t("underscore"),p=e.exports=function(t){if(this.valid=!0,this.id=t.id,this.timestamp=t.timestamp,this.hands=[],this.handsMap={},this.pointables=[],this.tools=[],this.fingers=[],t.interactionBox&&(this.interactionBox=new u(t.interactionBox)),this.gestures=[],this.pointablesMap={},this._translation=t.t,this._rotation=l.flatten(t.r),this._scaleFactor=t.s,this.data=t,this.type="frame",this.currentFrameRate=t.currentFrameRate,t.gestures)for(var e=0,n=t.gestures.length;e!=n;e++)this.gestures.push(o(t.gestures[e]));this.postprocessData(t)};p.prototype.postprocessData=function(t){t||(t=this.data);for(var e=0,n=t.hands.length;e!=n;e++){var o=new i(t.hands[e]);o.frame=this,this.hands.push(o),this.handsMap[o.id]=o}t.pointables=l.sortBy(t.pointables,function(t){return t.id});for(var s=0,a=t.pointables.length;s!=a;s++){var c=t.pointables[s],u=c.dipPosition?new h(c):new r(c);u.frame=this,this.addPointable(u)}},p.prototype.addPointable=function(t){if(this.pointables.push(t),this.pointablesMap[t.id]=t,(t.tool?this.tools:this.fingers).push(t),void 0!==t.handId&&this.handsMap.hasOwnProperty(t.handId)){var e=this.handsMap[t.handId];switch(e.pointables.push(t),(t.tool?e.tools:e.fingers).push(t),t.type){case 0:e.thumb=t;break;case 1:e.indexFinger=t;break;case 2:e.middleFinger=t;break;case 3:e.ringFinger=t;break;case 4:e.pinky=t}}},p.prototype.tool=function(t){var e=this.pointable(t);return e.tool?e:r.Invalid},p.prototype.pointable=function(t){return this.pointablesMap[t]||r.Invalid},p.prototype.finger=function(t){var e=this.pointable(t);return e.tool?r.Invalid:e},p.prototype.hand=function(t){return this.handsMap[t]||i.Invalid},p.prototype.rotationAngle=function(t,e){if(!this.valid||!t.valid)return 0;var n=this.rotationMatrix(t),i=Math.acos(.5*(n[0]+n[4]+n[8]-1));if(i=isNaN(i)?0:i,void 0!==e){var r=this.rotationAxis(t);i*=c.dot(r,c.normalize(c.create(),e))}return i},p.prototype.rotationAxis=function(t){return this.valid&&t.valid?c.normalize(c.create(),[this._rotation[7]-t._rotation[5],this._rotation[2]-t._rotation[6],this._rotation[3]-t._rotation[1]]):c.create()},p.prototype.rotationMatrix=function(t){if(!this.valid||!t.valid)return a.create();var e=a.transpose(a.create(),this._rotation);return a.multiply(a.create(),t._rotation,e)},p.prototype.scaleFactor=function(t){return this.valid&&t.valid?Math.exp(this._scaleFactor-t._scaleFactor):1},p.prototype.translation=function(t){return this.valid&&t.valid?c.subtract(c.create(),this._translation,t._translation):c.create()},p.prototype.toString=function(){var t="Frame [ id:"+this.id+" | timestamp:"+this.timestamp+" | Hand count:("+this.hands.length+") | Pointable count:("+this.pointables.length+")";return this.gestures&&(t+=" | Gesture count:("+this.gestures.length+")"),t+=" ]"},p.prototype.dump=function(){var t="";t+="Frame Info:<br/>",t+=this.toString(),t+="<br/><br/>Hands:<br/>";for(var e=0,n=this.hands.length;e!=n;e++)t+=" "+this.hands[e].toString()+"<br/>";t+="<br/><br/>Pointables:<br/>";for(var i=0,r=this.pointables.length;i!=r;i++)t+=" "+this.pointables[i].toString()+"<br/>";if(this.gestures){t+="<br/><br/>Gestures:<br/>";for(var o=0,s=this.gestures.length;o!=s;o++)t+=" "+this.gestures[o].toString()+"<br/>"}return t+="<br/><br/>Raw JSON:<br/>",t+=JSON.stringify(this.data)},p.Invalid={valid:!1,hands:[],fingers:[],tools:[],gestures:[],pointables:[],pointable:function(){return r.Invalid},finger:function(){return r.Invalid},hand:function(){return i.Invalid},toString:function(){return"invalid frame"},dump:function(){return this.toString()},rotationAngle:function(){return 0},rotationMatrix:function(){return a.create()},rotationAxis:function(){return c.create()},scaleFactor:function(){return 1},translation:function(){return c.create()}}},{"./finger":7,"./gesture":9,"./hand":10,"./interaction_box":12,"./pointable":14,"gl-matrix":23,underscore:24}],9:[function(t,e,n){var i=t("gl-matrix").vec3,r=t("events").EventEmitter,o=t("underscore"),s=(n.createGesture=function(t){var e;switch(t.type){case"circle":e=new a(t);break;case"swipe":e=new c(t);break;case"screenTap":e=new u(t);break;case"keyTap":e=new h(t);break;default:throw"unknown gesture type"}return e.id=t.id,e.handIds=t.handIds.slice(),e.pointableIds=t.pointableIds.slice(),e.duration=t.duration,e.state=t.state,e.type=t.type,e},n.gestureListener=function(t,e){var n={},i={};t.on("gesture",function(t,r){if(t.type==e){if(("start"==t.state||"stop"==t.state)&&void 0===i[t.id]){var a=new s(t,r);i[t.id]=a,o.each(n,function(t,e){a.on(e,t)})}i[t.id].update(t,r),"stop"==t.state&&delete i[t.id]}});var r={start:function(t){return n.start=t,r},stop:function(t){return n.stop=t,r},complete:function(t){return n.stop=t,r},update:function(t){return n.update=t,r}};return r},n.Gesture=function(t,e){this.gestures=[t],this.frames=[e]});s.prototype.update=function(t,e){this.lastGesture=t,this.lastFrame=e,this.gestures.push(t),this.frames.push(e),this.emit(t.state,this)},s.prototype.translation=function(){return i.subtract(i.create(),this.lastGesture.startPosition,this.lastGesture.position)},o.extend(s.prototype,r.prototype);var a=function(t){this.center=t.center,this.normal=t.normal,this.progress=t.progress,this.radius=t.radius};a.prototype.toString=function(){return"CircleGesture ["+JSON.stringify(this)+"]"};var c=function(t){this.startPosition=t.startPosition,this.position=t.position,this.direction=t.direction,this.speed=t.speed};c.prototype.toString=function(){return"SwipeGesture ["+JSON.stringify(this)+"]"};var u=function(t){this.position=t.position,this.direction=t.direction,this.progress=t.progress};u.prototype.toString=function(){return"ScreenTapGesture ["+JSON.stringify(this)+"]"};var h=function(t){this.position=t.position,this.direction=t.direction,this.progress=t.progress};h.prototype.toString=function(){return"KeyTapGesture ["+JSON.stringify(this)+"]"}},{events:21,"gl-matrix":23,underscore:24}],10:[function(t,e,n){var i=t("./pointable"),r=t("./bone"),o=t("gl-matrix"),s=o.mat3,a=o.vec3,c=t("underscore"),u=e.exports=function(t){this.id=t.id,this.palmPosition=t.palmPosition,this.direction=t.direction,this.palmVelocity=t.palmVelocity,this.palmNormal=t.palmNormal,this.sphereCenter=t.sphereCenter,this.sphereRadius=t.sphereRadius,this.valid=!0,this.pointables=[],this.fingers=[],this.arm=t.armBasis?new r(this,{type:4,width:t.armWidth,prevJoint:t.elbow,nextJoint:t.wrist,basis:t.armBasis}):null,this.tools=[],this._translation=t.t,this._rotation=c.flatten(t.r),this._scaleFactor=t.s,this.timeVisible=t.timeVisible,this.stabilizedPalmPosition=t.stabilizedPalmPosition,this.type=t.type,this.grabStrength=t.grabStrength,this.pinchStrength=t.pinchStrength,this.confidence=t.confidence};u.prototype.finger=function(t){var e=this.frame.finger(t);return e&&e.handId==this.id?e:i.Invalid},u.prototype.rotationAngle=function(t,e){if(!this.valid||!t.valid)return 0;if(!t.hand(this.id).valid)return 0;var n=this.rotationMatrix(t),i=Math.acos(.5*(n[0]+n[4]+n[8]-1));if(i=isNaN(i)?0:i,void 0!==e){var r=this.rotationAxis(t);i*=a.dot(r,a.normalize(a.create(),e))}return i},u.prototype.rotationAxis=function(t){if(!this.valid||!t.valid)return a.create();var e=t.hand(this.id);return e.valid?a.normalize(a.create(),[this._rotation[7]-e._rotation[5],this._rotation[2]-e._rotation[6],this._rotation[3]-e._rotation[1]]):a.create()},u.prototype.rotationMatrix=function(t){if(!this.valid||!t.valid)return s.create();var e=t.hand(this.id);if(!e.valid)return s.create();var n=s.transpose(s.create(),this._rotation);return s.multiply(s.create(),e._rotation,n)},u.prototype.scaleFactor=function(t){if(!this.valid||!t.valid)return 1;var e=t.hand(this.id);return e.valid?Math.exp(this._scaleFactor-e._scaleFactor):1},u.prototype.translation=function(t){if(!this.valid||!t.valid)return a.create();var e=t.hand(this.id);return e.valid?[this._translation[0]-e._translation[0],this._translation[1]-e._translation[1],this._translation[2]-e._translation[2]]:a.create()},u.prototype.toString=function(){return"Hand ("+this.type+") [ id: "+this.id+" | palm velocity:"+this.palmVelocity+" | sphere center:"+this.sphereCenter+" ] "},u.prototype.pitch=function(){return Math.atan2(this.direction[1],-this.direction[2])},u.prototype.yaw=function(){return Math.atan2(this.direction[0],-this.direction[2])},u.prototype.roll=function(){return Math.atan2(this.palmNormal[0],-this.palmNormal[1])},u.Invalid={valid:!1,fingers:[],tools:[],pointables:[],left:!1,pointable:function(){return i.Invalid},finger:function(){return i.Invalid},toString:function(){return"invalid frame"},dump:function(){return this.toString()},rotationAngle:function(){return 0},rotationMatrix:function(){return s.create()},rotationAxis:function(){return a.create()},scaleFactor:function(){return 1},translation:function(){return a.create()}}},{"./bone":1,"./pointable":14,"gl-matrix":23,underscore:24}],11:[function(t,e,n){e.exports={Controller:t("./controller"),Frame:t("./frame"),Gesture:t("./gesture"),Hand:t("./hand"),Pointable:t("./pointable"),Finger:t("./finger"),InteractionBox:t("./interaction_box"),CircularBuffer:t("./circular_buffer"),UI:t("./ui"),JSONProtocol:t("./protocol").JSONProtocol,glMatrix:t("gl-matrix"),mat3:t("gl-matrix").mat3,vec3:t("gl-matrix").vec3,loopController:void 0,version:t("./version.js"),_:t("underscore"),EventEmitter:t("events").EventEmitter,loop:function(t,e){return t&&void 0===e&&"[object Function]"==={}.toString.call(t)&&(e=t,t={}),this.loopController?t&&this.loopController.setupFrameEvents(t):this.loopController=new this.Controller(t),this.loopController.loop(e),this.loopController},plugin:function(t,e){this.Controller.plugin(t,e)}}},{"./circular_buffer":2,"./controller":5,"./finger":7,"./frame":8,"./gesture":9,"./hand":10,"./interaction_box":12,"./pointable":14,"./protocol":15,"./ui":16,"./version.js":19,events:21,"gl-matrix":23,underscore:24}],12:[function(t,e,n){var i=t("gl-matrix").vec3,r=e.exports=function(t){this.valid=!0,this.center=t.center,this.size=t.size,this.width=t.size[0],this.height=t.size[1],this.depth=t.size[2]};r.prototype.denormalizePoint=function(t){return i.fromValues((t[0]-.5)*this.size[0]+this.center[0],(t[1]-.5)*this.size[1]+this.center[1],(t[2]-.5)*this.size[2]+this.center[2])},r.prototype.normalizePoint=function(t,e){var n=i.fromValues((t[0]-this.center[0])/this.size[0]+.5,(t[1]-this.center[1])/this.size[1]+.5,(t[2]-this.center[2])/this.size[2]+.5);return e&&(n[0]=Math.min(Math.max(n[0],0),1),n[1]=Math.min(Math.max(n[1],0),1),n[2]=Math.min(Math.max(n[2],0),1)),n},r.prototype.toString=function(){return"InteractionBox [ width:"+this.width+" | height:"+this.height+" | depth:"+this.depth+" ]"},r.Invalid={valid:!1}},{"gl-matrix":23}],13:[function(t,e,n){var i=e.exports=function(t){this.steps=[],this.controller=t};i.prototype.addStep=function(t){this.steps.push(t)},i.prototype.run=function(t){for(var e=this.steps.length,n=0;n!=e&&t;n++)t=this.steps[n](t);return t},i.prototype.removeStep=function(t){var e=this.steps.indexOf(t);if(-1===e)throw"Step not found in pipeline";this.steps.splice(e,1)},i.prototype.addWrappedStep=function(t,e){var n=this.controller,i=function(i){var r,o,s;for(o=0,s=(r="frame"==t?[i]:i[t+"s"]||[]).length;o<s;o++)e.call(n,r[o]);return i};return this.addStep(i),i}},{}],14:[function(t,e,n){t("gl-matrix");var i=e.exports=function(t){this.valid=!0,this.id=t.id,this.handId=t.handId,this.length=t.length,this.tool=t.tool,this.width=t.width,this.direction=t.direction,this.stabilizedTipPosition=t.stabilizedTipPosition,this.tipPosition=t.tipPosition,this.tipVelocity=t.tipVelocity,this.touchZone=t.touchZone,this.touchDistance=t.touchDistance,this.timeVisible=t.timeVisible};i.prototype.toString=function(){return"Pointable [ id:"+this.id+" "+this.length+"mmx | width:"+this.width+"mm | direction:"+this.direction+" ]"},i.prototype.hand=function(){return this.frame.hand(this.handId)},i.Invalid={valid:!1}},{"gl-matrix":23}],15:[function(t,e,n){var i=t("./frame"),r=(t("./hand"),t("./pointable"),t("./finger"),t("underscore")),o=t("events").EventEmitter;n.chooseProtocol=function(t){var e;switch(t.version){case 1:case 2:case 3:case 4:case 5:case 6:(e=s(t)).sendBackground=function(t,n){t.send(e.encode({background:n}))},e.sendFocused=function(t,n){t.send(e.encode({focused:n}))},e.sendOptimizeHMD=function(t,n){t.send(e.encode({optimizeHMD:n}))};break;default:throw"unrecognized version"}return e};var s=n.JSONProtocol=function(t){var e=function(t){if(t.event)return new function(t){this.type=t.type,this.state=t.state}(t.event);e.emit("beforeFrameCreated",t);var n=new i(t);return e.emit("afterFrameCreated",n,t),n};return e.encode=function(t){return JSON.stringify(t)},e.version=t.version,e.serviceVersion=t.serviceVersion,e.versionLong="Version "+t.version,e.type="protocol",r.extend(e,o.prototype),e}},{"./finger":7,"./frame":8,"./hand":10,"./pointable":14,events:21,underscore:24}],16:[function(t,e,n){n.UI={Region:t("./ui/region"),Cursor:t("./ui/cursor")}},{"./ui/cursor":17,"./ui/region":18}],17:[function(t,e,n){e.exports=function(){return function(t){var e=t.pointables.sort(function(t,e){return t.z-e.z})[0];return e&&e.valid&&(t.cursorPosition=e.tipPosition),t}}},{}],18:[function(t,e,n){var i=t("events").EventEmitter,r=t("underscore"),o=e.exports=function(t,e){this.start=new Vector(t),this.end=new Vector(e),this.enteredFrame=null};o.prototype.hasPointables=function(t){for(var e=0;e!=t.pointables.length;e++){var n=t.pointables[e].tipPosition;if(n.x>=this.start.x&&n.x<=this.end.x&&n.y>=this.start.y&&n.y<=this.end.y&&n.z>=this.start.z&&n.z<=this.end.z)return!0}return!1},o.prototype.listener=function(t){var e=this;return t&&t.nearThreshold&&this.setupNearRegion(t.nearThreshold),function(t){return e.updatePosition(t)}},o.prototype.clipper=function(){var t=this;return function(e){return t.updatePosition(e),t.enteredFrame?e:null}},o.prototype.setupNearRegion=function(t){var e=this.nearRegion=new o([this.start.x-t,this.start.y-t,this.start.z-t],[this.end.x+t,this.end.y+t,this.end.z+t]),n=this;e.on("enter",function(t){n.emit("near",t)}),e.on("exit",function(t){n.emit("far",t)}),n.on("exit",function(t){n.emit("near",t)})},o.prototype.updatePosition=function(t){return this.nearRegion&&this.nearRegion.updatePosition(t),this.hasPointables(t)&&null==this.enteredFrame?(this.enteredFrame=t,this.emit("enter",this.enteredFrame)):this.hasPointables(t)||null==this.enteredFrame||(this.enteredFrame=null,this.emit("exit",this.enteredFrame)),t},o.prototype.normalize=function(t){return new Vector([(t.x-this.start.x)/(this.end.x-this.start.x),(t.y-this.start.y)/(this.end.y-this.start.y),(t.z-this.start.z)/(this.end.z-this.start.z)])},o.prototype.mapToXY=function(t,e,n){var i=this.normalize(t),r=i.x,o=i.y;return r>1?r=1:r<-1&&(r=-1),o>1?o=1:o<-1&&(o=-1),[(r+1)/2*e,(1-o)/2*n,i.z]},r.extend(o.prototype,i.prototype)},{events:21,underscore:24}],19:[function(t,e,n){e.exports={full:"0.6.4",major:0,minor:6,dot:4}},{}],20:[function(t,e,n){},{}],21:[function(t,e,n){var i=t("__browserify_process");i.EventEmitter||(i.EventEmitter=function(){});var r=n.EventEmitter=i.EventEmitter,o="function"==typeof Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};r.prototype.setMaxListeners=function(t){this._events||(this._events={}),this._events.maxListeners=t},r.prototype.emit=function(t){if("error"===t&&(!this._events||!this._events.error||o(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var e=this._events[t];if(!e)return!1;if("function"==typeof e){switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:var n=Array.prototype.slice.call(arguments,1);e.apply(this,n)}return!0}if(o(e)){n=Array.prototype.slice.call(arguments,1);for(var i=e.slice(),r=0,s=i.length;r<s;r++)i[r].apply(this,n);return!0}return!1},r.prototype.addListener=function(t,e){if("function"!=typeof e)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",t,e),this._events[t])if(o(this._events[t])){var n;if(!this._events[t].warned)(n=void 0!==this._events.maxListeners?this._events.maxListeners:10)&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace());this._events[t].push(e)}else this._events[t]=[this._events[t],e];else this._events[t]=e;return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(t,e){var n=this;return n.on(t,function i(){n.removeListener(t,i),e.apply(this,arguments)}),this},r.prototype.removeListener=function(t,e){if("function"!=typeof e)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var n=this._events[t];if(o(n)){var i=function(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0;n<t.length;n++)if(e===t[n])return n;return-1}(n,e);if(i<0)return this;n.splice(i,1),0==n.length&&delete this._events[t]}else this._events[t]===e&&delete this._events[t];return this},r.prototype.removeAllListeners=function(t){return 0===arguments.length?(this._events={},this):(t&&this._events&&this._events[t]&&(this._events[t]=null),this)},r.prototype.listeners=function(t){return this._events||(this._events={}),this._events[t]||(this._events[t]=[]),o(this._events[t])||(this._events[t]=[this._events[t]]),this._events[t]},r.listenerCount=function(t,e){return t._events&&t._events[e]?"function"==typeof t._events[e]?1:t._events[e].length:0}},{__browserify_process:22}],22:[function(t,e,n){var i=e.exports={};i.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){var e=t.source;e!==window&&null!==e||"process-tick"!==t.data||(t.stopPropagation(),n.length>0&&n.shift()())},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),i.title="browser",i.browser=!0,i.env={},i.argv=[],i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")}},{}],23:[function(t,e,n){var i,r;i=this,r={},void 0===n?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(r.exports={},define(function(){return r.exports})):r.exports="undefined"!=typeof window?window:i:r.exports=n,function(t){var e;if(!n)var n="undefined"!=typeof Float32Array?Float32Array:Array;if(!i)var i=Math.random;var r={setMatrixArrayType:function(t){n=t}};void 0!==t&&(t.glMatrix=r);var o=Math.PI/180;r.toRadian=function(t){return t*o};var s,a={create:function(){var t=new n(2);return t[0]=0,t[1]=0,t},clone:function(t){var e=new n(2);return e[0]=t[0],e[1]=t[1],e},fromValues:function(t,e){var i=new n(2);return i[0]=t,i[1]=e,i},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t},set:function(t,e,n){return t[0]=e,t[1]=n,t},add:function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t},subtract:function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t}};a.sub=a.subtract,a.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t},a.mul=a.multiply,a.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t},a.div=a.divide,a.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t},a.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t},a.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t},a.scaleAndAdd=function(t,e,n,i){return t[0]=e[0]+n[0]*i,t[1]=e[1]+n[1]*i,t},a.distance=function(t,e){var n=e[0]-t[0],i=e[1]-t[1];return Math.sqrt(n*n+i*i)},a.dist=a.distance,a.squaredDistance=function(t,e){var n=e[0]-t[0],i=e[1]-t[1];return n*n+i*i},a.sqrDist=a.squaredDistance,a.length=function(t){var e=t[0],n=t[1];return Math.sqrt(e*e+n*n)},a.len=a.length,a.squaredLength=function(t){var e=t[0],n=t[1];return e*e+n*n},a.sqrLen=a.squaredLength,a.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t},a.normalize=function(t,e){var n=e[0],i=e[1],r=n*n+i*i;return r>0&&(r=1/Math.sqrt(r),t[0]=e[0]*r,t[1]=e[1]*r),t},a.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},a.cross=function(t,e,n){var i=e[0]*n[1]-e[1]*n[0];return t[0]=t[1]=0,t[2]=i,t},a.lerp=function(t,e,n,i){var r=e[0],o=e[1];return t[0]=r+i*(n[0]-r),t[1]=o+i*(n[1]-o),t},a.random=function(t,e){e=e||1;var n=2*i()*Math.PI;return t[0]=Math.cos(n)*e,t[1]=Math.sin(n)*e,t},a.transformMat2=function(t,e,n){var i=e[0],r=e[1];return t[0]=n[0]*i+n[2]*r,t[1]=n[1]*i+n[3]*r,t},a.transformMat2d=function(t,e,n){var i=e[0],r=e[1];return t[0]=n[0]*i+n[2]*r+n[4],t[1]=n[1]*i+n[3]*r+n[5],t},a.transformMat3=function(t,e,n){var i=e[0],r=e[1];return t[0]=n[0]*i+n[3]*r+n[6],t[1]=n[1]*i+n[4]*r+n[7],t},a.transformMat4=function(t,e,n){var i=e[0],r=e[1];return t[0]=n[0]*i+n[4]*r+n[12],t[1]=n[1]*i+n[5]*r+n[13],t},a.forEach=(s=a.create(),function(t,e,n,i,r,o){var a,c;for(e||(e=2),n||(n=0),c=i?Math.min(i*e+n,t.length):t.length,a=n;a<c;a+=e)s[0]=t[a],s[1]=t[a+1],r(s,s,o),t[a]=s[0],t[a+1]=s[1];return t}),a.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},void 0!==t&&(t.vec2=a);var c={create:function(){var t=new n(3);return t[0]=0,t[1]=0,t[2]=0,t},clone:function(t){var e=new n(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},fromValues:function(t,e,i){var r=new n(3);return r[0]=t,r[1]=e,r[2]=i,r},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},set:function(t,e,n,i){return t[0]=e,t[1]=n,t[2]=i,t},add:function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t},subtract:function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t}};c.sub=c.subtract,c.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t},c.mul=c.multiply,c.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t},c.div=c.divide,c.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t},c.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t},c.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t},c.scaleAndAdd=function(t,e,n,i){return t[0]=e[0]+n[0]*i,t[1]=e[1]+n[1]*i,t[2]=e[2]+n[2]*i,t},c.distance=function(t,e){var n=e[0]-t[0],i=e[1]-t[1],r=e[2]-t[2];return Math.sqrt(n*n+i*i+r*r)},c.dist=c.distance,c.squaredDistance=function(t,e){var n=e[0]-t[0],i=e[1]-t[1],r=e[2]-t[2];return n*n+i*i+r*r},c.sqrDist=c.squaredDistance,c.length=function(t){var e=t[0],n=t[1],i=t[2];return Math.sqrt(e*e+n*n+i*i)},c.len=c.length,c.squaredLength=function(t){var e=t[0],n=t[1],i=t[2];return e*e+n*n+i*i},c.sqrLen=c.squaredLength,c.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},c.normalize=function(t,e){var n=e[0],i=e[1],r=e[2],o=n*n+i*i+r*r;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o),t},c.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},c.cross=function(t,e,n){var i=e[0],r=e[1],o=e[2],s=n[0],a=n[1],c=n[2];return t[0]=r*c-o*a,t[1]=o*s-i*c,t[2]=i*a-r*s,t},c.lerp=function(t,e,n,i){var r=e[0],o=e[1],s=e[2];return t[0]=r+i*(n[0]-r),t[1]=o+i*(n[1]-o),t[2]=s+i*(n[2]-s),t},c.random=function(t,e){e=e||1;var n=2*i()*Math.PI,r=2*i()-1,o=Math.sqrt(1-r*r)*e;return t[0]=Math.cos(n)*o,t[1]=Math.sin(n)*o,t[2]=r*e,t},c.transformMat4=function(t,e,n){var i=e[0],r=e[1],o=e[2];return t[0]=n[0]*i+n[4]*r+n[8]*o+n[12],t[1]=n[1]*i+n[5]*r+n[9]*o+n[13],t[2]=n[2]*i+n[6]*r+n[10]*o+n[14],t},c.transformMat3=function(t,e,n){var i=e[0],r=e[1],o=e[2];return t[0]=i*n[0]+r*n[3]+o*n[6],t[1]=i*n[1]+r*n[4]+o*n[7],t[2]=i*n[2]+r*n[5]+o*n[8],t},c.transformQuat=function(t,e,n){var i=e[0],r=e[1],o=e[2],s=n[0],a=n[1],c=n[2],u=n[3],h=u*i+a*o-c*r,l=u*r+c*i-s*o,p=u*o+s*r-a*i,d=-s*i-a*r-c*o;return t[0]=h*u+d*-s+l*-c-p*-a,t[1]=l*u+d*-a+p*-s-h*-c,t[2]=p*u+d*-c+h*-a-l*-s,t},c.rotateX=function(t,e,n,i){var r=[],o=[];return r[0]=e[0]-n[0],r[1]=e[1]-n[1],r[2]=e[2]-n[2],o[0]=r[0],o[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),o[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t},c.rotateY=function(t,e,n,i){var r=[],o=[];return r[0]=e[0]-n[0],r[1]=e[1]-n[1],r[2]=e[2]-n[2],o[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),o[1]=r[1],o[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t},c.rotateZ=function(t,e,n,i){var r=[],o=[];return r[0]=e[0]-n[0],r[1]=e[1]-n[1],r[2]=e[2]-n[2],o[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),o[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),o[2]=r[2],t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t},c.forEach=function(){var t=c.create();return function(e,n,i,r,o,s){var a,c;for(n||(n=3),i||(i=0),c=r?Math.min(r*n+i,e.length):e.length,a=i;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}}(),c.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},void 0!==t&&(t.vec3=c);var u={create:function(){var t=new n(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},clone:function(t){var e=new n(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},fromValues:function(t,e,i,r){var o=new n(4);return o[0]=t,o[1]=e,o[2]=i,o[3]=r,o},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},set:function(t,e,n,i,r){return t[0]=e,t[1]=n,t[2]=i,t[3]=r,t},add:function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t[3]=e[3]+n[3],t},subtract:function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t[3]=e[3]-n[3],t}};u.sub=u.subtract,u.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t[3]=e[3]*n[3],t},u.mul=u.multiply,u.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t[3]=e[3]/n[3],t},u.div=u.divide,u.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t[3]=Math.min(e[3],n[3]),t},u.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t[3]=Math.max(e[3],n[3]),t},u.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t},u.scaleAndAdd=function(t,e,n,i){return t[0]=e[0]+n[0]*i,t[1]=e[1]+n[1]*i,t[2]=e[2]+n[2]*i,t[3]=e[3]+n[3]*i,t},u.distance=function(t,e){var n=e[0]-t[0],i=e[1]-t[1],r=e[2]-t[2],o=e[3]-t[3];return Math.sqrt(n*n+i*i+r*r+o*o)},u.dist=u.distance,u.squaredDistance=function(t,e){var n=e[0]-t[0],i=e[1]-t[1],r=e[2]-t[2],o=e[3]-t[3];return n*n+i*i+r*r+o*o},u.sqrDist=u.squaredDistance,u.length=function(t){var e=t[0],n=t[1],i=t[2],r=t[3];return Math.sqrt(e*e+n*n+i*i+r*r)},u.len=u.length,u.squaredLength=function(t){var e=t[0],n=t[1],i=t[2],r=t[3];return e*e+n*n+i*i+r*r},u.sqrLen=u.squaredLength,u.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},u.normalize=function(t,e){var n=e[0],i=e[1],r=e[2],o=e[3],s=n*n+i*i+r*r+o*o;return s>0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t[3]=e[3]*s),t},u.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},u.lerp=function(t,e,n,i){var r=e[0],o=e[1],s=e[2],a=e[3];return t[0]=r+i*(n[0]-r),t[1]=o+i*(n[1]-o),t[2]=s+i*(n[2]-s),t[3]=a+i*(n[3]-a),t},u.random=function(t,e){return e=e||1,t[0]=i(),t[1]=i(),t[2]=i(),t[3]=i(),u.normalize(t,t),u.scale(t,t,e),t},u.transformMat4=function(t,e,n){var i=e[0],r=e[1],o=e[2],s=e[3];return t[0]=n[0]*i+n[4]*r+n[8]*o+n[12]*s,t[1]=n[1]*i+n[5]*r+n[9]*o+n[13]*s,t[2]=n[2]*i+n[6]*r+n[10]*o+n[14]*s,t[3]=n[3]*i+n[7]*r+n[11]*o+n[15]*s,t},u.transformQuat=function(t,e,n){var i=e[0],r=e[1],o=e[2],s=n[0],a=n[1],c=n[2],u=n[3],h=u*i+a*o-c*r,l=u*r+c*i-s*o,p=u*o+s*r-a*i,d=-s*i-a*r-c*o;return t[0]=h*u+d*-s+l*-c-p*-a,t[1]=l*u+d*-a+p*-s-h*-c,t[2]=p*u+d*-c+h*-a-l*-s,t},u.forEach=function(){var t=u.create();return function(e,n,i,r,o,s){var a,c;for(n||(n=4),i||(i=0),c=r?Math.min(r*n+i,e.length):e.length,a=i;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],t[3]=e[a+3],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2],e[a+3]=t[3];return e}}(),u.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},void 0!==t&&(t.vec4=u);var h={create:function(){var t=new n(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},clone:function(t){var e=new n(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},identity:function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},transpose:function(t,e){if(t===e){var n=e[1];t[1]=e[2],t[2]=n}else t[0]=e[0],t[1]=e[2],t[2]=e[1],t[3]=e[3];return t},invert:function(t,e){var n=e[0],i=e[1],r=e[2],o=e[3],s=n*o-r*i;return s?(t[0]=o*(s=1/s),t[1]=-i*s,t[2]=-r*s,t[3]=n*s,t):null},adjoint:function(t,e){var n=e[0];return t[0]=e[3],t[1]=-e[1],t[2]=-e[2],t[3]=n,t},determinant:function(t){return t[0]*t[3]-t[2]*t[1]},multiply:function(t,e,n){var i=e[0],r=e[1],o=e[2],s=e[3],a=n[0],c=n[1],u=n[2],h=n[3];return t[0]=i*a+o*c,t[1]=r*a+s*c,t[2]=i*u+o*h,t[3]=r*u+s*h,t}};h.mul=h.multiply,h.rotate=function(t,e,n){var i=e[0],r=e[1],o=e[2],s=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=i*c+o*a,t[1]=r*c+s*a,t[2]=i*-a+o*c,t[3]=r*-a+s*c,t},h.scale=function(t,e,n){var i=e[1],r=e[2],o=e[3],s=n[0],a=n[1];return t[0]=e[0]*s,t[1]=i*s,t[2]=r*a,t[3]=o*a,t},h.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},h.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2))},h.LDU=function(t,e,n,i){return t[2]=i[2]/i[0],n[0]=i[0],n[1]=i[1],n[3]=i[3]-t[2]*n[1],[t,e,n]},void 0!==t&&(t.mat2=h);var l={create:function(){var t=new n(6);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},clone:function(t){var e=new n(6);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e