bespoke-leapmotion
Version:
Leap Motion Support for Bespoke.js
3 lines • 82 kB
JavaScript
/*! bespoke-leapmotion v1.0.0 © 2015 Leo Liang, MIT License */
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self);var n=e;n=n.bespoke||(n.bespoke={}),n=n.plugins||(n.plugins={}),n.leapmotion=t()}}(function(){var t;return function e(t,n,i){function r(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var c=n[s]={exports:{}};t[s][0].call(c.exports,function(e){var n=t[s][1][e];return r(n?n:e)},c,c.exports,e,t,n,i)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<i.length;s++)r(i[s]);return r}({1:[function(t,e){var n=t("leapjs");e.exports=function(){return function(t){var e,i=0;new n.Controller({enableGestures:!0}).connect().on("frame",function(n){var r=n.gestures[0];if(e=(new Date).getTime(),n.gestures.length>0&&"swipe"===r.type&&e-i>300&&1===n.hands.length){var o=r.direction[0],s=r.direction[1],a=Math.abs(o)>Math.abs(s);a&&(o>0?t.prev():t.next(),i=e)}})}}},{leapjs:15}],2:[function(t,e){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(t){return"function"==typeof t}function r(t){return"number"==typeof t}function o(t){return"object"==typeof t&&null!==t}function s(t){return void 0===t}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(t){if(!r(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},n.prototype.emit=function(t){var e,n,r,a,u,c;if(this._events||(this._events={}),"error"===t&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[t],s(n))return!1;if(i(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(r=arguments.length,a=new Array(r-1),u=1;r>u;u++)a[u-1]=arguments[u];n.apply(this,a)}else if(o(n)){for(r=arguments.length,a=new Array(r-1),u=1;r>u;u++)a[u-1]=arguments[u];for(c=n.slice(),r=c.length,u=0;r>u;u++)c[u].apply(this,a)}return!0},n.prototype.addListener=function(t,e){var r;if(!i(e))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,i(e.listener)?e.listener:e),this._events[t]?o(this._events[t])?this._events[t].push(e):this._events[t]=[this._events[t],e]:this._events[t]=e,o(this._events[t])&&!this._events[t].warned){var r;r=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[t].length>r&&(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),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),r||(r=!0,e.apply(this,arguments))}if(!i(e))throw TypeError("listener must be a function");var r=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,r,s,a;if(!i(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,r=-1,n===e||i(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(o(n)){for(a=s;a-->0;)if(n[a]===e||n[a].listener&&n[a].listener===e){r=a;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],i(n))this.removeListener(t,n);else for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){var e;return e=this._events&&this._events[t]?i(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.listenerCount=function(t,e){var n;return n=t._events&&t._events[e]?i(t._events[e])?1:t._events[e].length:0}},{}],3:[function(t,e){function 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;if((e===window||null===e)&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var i=n.shift();i()}},!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.on=n,i.addListener=n,i.once=n,i.off=n,i.removeListener=n,i.removeAllListeners=n,i.emit=n,i.binding=function(){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(t,e){var n=(t("./pointable"),t("gl-matrix")),i=n.vec3,r=n.mat3,o=n.mat4,s=(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);i.sub(n,e.nextJoint,e.prevJoint),this.length=i.length(n),this.basis=e.basis});s.prototype.left=function(){return this._left?this._left:(this._left=r.determinant(this.basis[0].concat(this.basis[1]).concat(this.basis[2]))<0,this._left)},s.prototype.matrix=function(){if(this._matrix)return this._matrix;var t=this.basis,e=this._matrix=o.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},s.prototype.lerp=function(t,e){i.lerp(t,this.prevJoint,this.nextJoint,e)},s.prototype.center=function(){if(this._center)return this._center;var t=i.create();return this.lerp(t,.5),this._center=t,t},s.prototype.direction=function(){return[-1*this.basis[2][0],-1*this.basis[2][1],-1*this.basis[2][2]]}},{"./pointable":18,"gl-matrix":24,underscore:25}],5:[function(t,e){var n=e.exports=function(t){this.pos=0,this._buf=[],this.size=t};n.prototype.get=function(t){return void 0==t&&(t=0),t>=this.size?void 0:t>=this._buf.length?void 0:this._buf[(this.pos-t-1)%this.size]},n.prototype.push=function(t){return this._buf[this.pos%this.size]=t,this.pos++}},{}],6:[function(t,e){var n=t("../protocol").chooseProtocol,i=t("events").EventEmitter,r=t("underscore"),o=e.exports=function(t){this.opts=r.defaults(t||{},{host:"127.0.0.1",enableGestures:!1,scheme:this.getScheme(),port:this.getPort(),background:!1,optimizeHMD:!1,requestProtocolVersion:o.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.")})};o.defaultProtocolVersion=6,o.prototype.getUrl=function(){return this.scheme+"//"+this.host+":"+this.port+"/v"+this.opts.requestProtocolVersion+".json"},o.prototype.getScheme=function(){return"ws:"},o.prototype.getPort=function(){return 6437},o.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))},o.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))},o.prototype.handleOpen=function(){this.connected||(this.connected=!0,this.emit("connect"))},o.prototype.enableGestures=function(t){this.gesturesEnabled=t?!0:!1,this.send(this.protocol.encode({enableGestures:this.gesturesEnabled}))},o.prototype.handleClose=function(t){this.connected&&(this.disconnect(),1001===t&&this.opts.requestProtocolVersion>1&&(this.protocolVersionVerified?this.protocolVersionVerified=!1:this.opts.requestProtocolVersion--),this.startReconnection())},o.prototype.startReconnection=function(){var t=this;this.reconnectionTimer||(this.reconnectionTimer=setInterval(function(){t.reconnect()},500))},o.prototype.stopReconnection=function(){this.reconnectionTimer=clearInterval(this.reconnectionTimer)},o.prototype.disconnect=function(t){return t||this.stopReconnection(),this.socket?(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):void 0},o.prototype.reconnect=function(){this.connected?this.stopReconnection():(this.disconnect(!0),this.connect())},o.prototype.handleData=function(t){var e,i=JSON.parse(t);void 0===this.protocol?(e=this.protocol=n(i),this.protocolVersionVerified=!0,this.emit("ready")):e=this.protocol(i),this.emit(e.type,e)},o.prototype.connect=function(){return this.socket?void 0:(this.socket=this.setupSocket(),!0)},o.prototype.send=function(t){this.socket.send(t)},o.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))},r.extend(o.prototype,i.prototype)},{"../protocol":19,events:2,underscore:25}],7:[function(t,e){var n=e.exports=t("./base"),i=t("underscore"),r=e.exports=function(t){n.call(this,t);var e=this;this.on("ready",function(){e.startFocusLoop()}),this.on("disconnect",function(){e.stopFocusLoop()})};i.extend(r.prototype,n.prototype),r.__proto__=n,r.prototype.useSecure=function(){return"https:"===location.protocol},r.prototype.getScheme=function(){return this.useSecure()?"wss:":"ws:"},r.prototype.getPort=function(){return this.useSecure()?6436:6437},r.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(){t.useSecure()&&"wss:"===t.scheme&&(t.scheme="ws:",t.port=6437,t.disconnect(),t.connect())},e},r.prototype.startFocusLoop=function(){if(!this.focusDetectorTimer){var t=this,e=null;e="undefined"!=typeof document.hidden?"hidden":"undefined"!=typeof document.mozHidden?"mozHidden":"undefined"!=typeof document.msHidden?"msHidden":"undefined"!=typeof document.webkitHidden?"webkitHidden":void 0,void 0===t.windowVisible&&(t.windowVisible=void 0===e?!0:document[e]===!1);var n=window.addEventListener("focus",function(){t.windowVisible=!0,r()}),i=window.addEventListener("blur",function(){t.windowVisible=!1,r()});this.on("disconnect",function(){window.removeEventListener("focus",n),window.removeEventListener("blur",i)});var r=function(){var n=void 0===e?!0:document[e]===!1;t.reportFocus(n&&t.windowVisible)};r(),this.focusDetectorTimer=setInterval(r,100)}},r.prototype.stopFocusLoop=function(){this.focusDetectorTimer&&(clearTimeout(this.focusDetectorTimer),delete this.focusDetectorTimer)}},{"./base":6,underscore:25}],8:[function(t,e){var n=t("ws"),i=t("./base"),r=t("underscore"),o=e.exports=function(t){i.call(this,t);var e=this;this.on("ready",function(){e.reportFocus(!0)})};r.extend(o.prototype,i.prototype),o.__proto__=i,o.prototype.setupSocket=function(){var t=this,e=new n(this.getUrl());return e.on("open",function(){t.handleOpen()}),e.on("message",function(e){t.handleData(e)}),e.on("close",function(e,n){t.handleClose(e,n)}),e.on("error",function(){t.startReconnection()}),e}},{"./base":6,underscore:25,ws:26}],9:[function(t,e){(function(n){var i=t("./frame"),r=t("./hand"),o=t("./pointable"),s=t("./finger"),a=t("./circular_buffer"),u=t("./pipeline"),c=t("events").EventEmitter,l=t("./gesture").gestureListener,h=t("./dialog"),p=t("underscore"),f=e.exports=function(e){var r="undefined"!=typeof n&&n.versions&&n.versions.node,o=this;e=p.defaults(e||{},{inNode:r}),this.inNode=e.inNode,e=p.defaults(e||{},{frameEventName:this.useAnimationLoop()?"animationFrame":"deviceFrame",suppressAnimationLoop:!this.useAnimationLoop(),loopWhileDisconnected:!0,useAllPlugins:!1,checkVersion:!0}),this.animationFrameRequested=!1,this.onAnimationFrame=function(t){o.lastConnectionFrame.valid&&o.emit("animationFrame",o.lastConnectionFrame),o.emit("frameEnd",t),o.loopWhileDisconnected&&(o.connection.focusedState!==!1||o.connection.opts.background)?window.requestAnimationFrame(o.onAnimationFrame):o.animationFrameRequested=!1},this.suppressAnimationLoop=e.suppressAnimationLoop,this.loopWhileDisconnected=e.loopWhileDisconnected,this.frameEventName=e.frameEventName,this.useAllPlugins=e.useAllPlugins,this.history=new a(200),this.lastFrame=i.Invalid,this.lastValidFrame=i.Invalid,this.lastConnectionFrame=i.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)||i.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||(t=i.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]);t.emit("streamingStopped",t.devices[e]),t.streamingCount=0;for(var e in 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){("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),h.warnOutOfDate({sV:t,pV:e}),!0):!1},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 p.keys(this._pluginFactories)};var d=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)))},m=function(t,e,n){var a;switch(this._pluginExtendedMethods[t]||(this._pluginExtendedMethods[t]=[]),e){case"frame":a=i;break;case"hand":a=r;break;case"pointable":a=o,p.extend(s.prototype,n),p.extend(s.Invalid,n);break;case"finger":a=s;break;default:throw t+' specifies invalid object type "'+e+'" for prototypical extension'}p.extend(a.prototype,n),p.extend(a.Invalid,n),this._pluginExtendedMethods[t].push([a,n])};f.prototype.use=function(t,e){var n,i,r,o;if(i="function"==typeof t?t:f._pluginFactories[t],!i)throw"Leap Plugin "+t+" not found.";if(e||(e={}),this.plugins[t])return p.extend(this.plugins[t],e),this;this.plugins[t]=e,o=i.call(this,e);for(r in o)n=o[r],"function"==typeof n?d.call(this,t,r,n):m.call(this,t,r,n);return this},f.prototype.stopUsing=function(t){var e,n,i=this._pluginPipelineSteps[t],r=this._pluginExtendedMethods[t],o=0;if(this.plugins[t]){if(i)for(o=0;o<i.length;o++)this.pipeline.removeStep(i[o]);if(r)for(o=0;o<r.length;o++){e=r[o][0],n=r[o][1];for(var s in n)delete e.prototype[s],delete e.Invalid[s]}return delete this.plugins[t],this}},f.prototype.useRegisteredPlugins=function(){for(var t in f._pluginFactories)this.use(t)},p.extend(f.prototype,c.prototype)}).call(this,t("FWaASH"))},{"./circular_buffer":5,"./connection/browser":7,"./connection/node":8,"./dialog":10,"./finger":11,"./frame":12,"./gesture":13,"./hand":14,"./pipeline":17,"./pointable":18,FWaASH:3,events:2,underscore:25}],10:[function(t,e){(function(t){var n=e.exports=function(t,e){this.options=e||{},this.message=t,this.createElement()};n.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)},n.prototype.show=function(){return document.body.appendChild(this.element),this},n.prototype.hide=function(){return document.body.removeChild(this.element),this},n.warnOutOfDate=function(t){t||(t={});var e="http://developer.leapmotion.com?";t.returnTo=window.location.href;for(var i in t)e+=i+"="+encodeURIComponent(t[i])+"&";var r,o=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 r.hide(),!0},s="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>";return r=new n(s,{onclick:o,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"}}),r.show()},n.hasWarnedBones=!1,n.warnBones=function(){this.hasWarnedBones||(this.hasWarnedBones=!0,console.warn("Your Leap Service is out of date"),"undefined"!=typeof t&&t.versions&&t.versions.node||this.warnOutOfDate({reason:"bones"}))}}).call(this,t("FWaASH"))},{FWaASH:3}],11:[function(t,e){var n=t("./pointable"),i=t("./bone"),r=t("./dialog"),o=t("underscore"),s=e.exports=function(t){n.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):r.warnBones()};o.extend(s.prototype,n.prototype),s.prototype.addBones=function(t){this.metacarpal=new i(this,{type:0,width:this.width,prevJoint:this.carpPosition,nextJoint:this.mcpPosition,basis:t.bases[0]}),this.proximal=new i(this,{type:1,width:this.width,prevJoint:this.mcpPosition,nextJoint:this.pipPosition,basis:t.bases[1]}),this.medial=new i(this,{type:2,width:this.width,prevJoint:this.pipPosition,nextJoint:this.dipPosition,basis:t.bases[2]}),this.distal=new i(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]},s.prototype.toString=function(){return"Finger [ id:"+this.id+" "+this.length+"mmx | width:"+this.width+"mm | direction:"+this.direction+" ]"},s.Invalid={valid:!1}},{"./bone":4,"./dialog":10,"./pointable":18,underscore:25}],12:[function(t,e){var n=t("./hand"),i=t("./pointable"),r=t("./gesture").createGesture,o=t("gl-matrix"),s=o.mat3,a=o.vec3,u=t("./interaction_box"),c=t("./finger"),l=t("underscore"),h=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(r(t.gestures[e]));this.postprocessData(t)};h.prototype.postprocessData=function(t){t||(t=this.data);for(var e=0,r=t.hands.length;e!=r;e++){var o=new n(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 u=t.pointables[s],h=u.dipPosition?new c(u):new i(u);h.frame=this,this.addPointable(h)}},h.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}}},h.prototype.tool=function(t){var e=this.pointable(t);return e.tool?e:i.Invalid},h.prototype.pointable=function(t){return this.pointablesMap[t]||i.Invalid},h.prototype.finger=function(t){var e=this.pointable(t);return e.tool?i.Invalid:e},h.prototype.hand=function(t){return this.handsMap[t]||n.Invalid},h.prototype.rotationAngle=function(t,e){if(!this.valid||!t.valid)return 0;var n=this.rotationMatrix(t),i=.5*(n[0]+n[4]+n[8]-1),r=Math.acos(i);if(r=isNaN(r)?0:r,void 0!==e){var o=this.rotationAxis(t);r*=a.dot(o,a.normalize(a.create(),e))}return r},h.prototype.rotationAxis=function(t){return this.valid&&t.valid?a.normalize(a.create(),[this._rotation[7]-t._rotation[5],this._rotation[2]-t._rotation[6],this._rotation[3]-t._rotation[1]]):a.create()},h.prototype.rotationMatrix=function(t){if(!this.valid||!t.valid)return s.create();var e=s.transpose(s.create(),this._rotation);return s.multiply(s.create(),t._rotation,e)},h.prototype.scaleFactor=function(t){return this.valid&&t.valid?Math.exp(this._scaleFactor-t._scaleFactor):1},h.prototype.translation=function(t){return this.valid&&t.valid?a.subtract(a.create(),this._translation,t._translation):a.create()},h.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+=" ]"},h.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)},h.Invalid={valid:!1,hands:[],fingers:[],tools:[],gestures:[],pointables:[],pointable:function(){return i.Invalid},finger:function(){return i.Invalid},hand:function(){return n.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()}}},{"./finger":11,"./gesture":13,"./hand":14,"./interaction_box":16,"./pointable":18,"gl-matrix":24,underscore:25}],13:[function(t,e,n){var i=t("gl-matrix"),r=i.vec3,o=t("events").EventEmitter,s=t("underscore"),a=(n.createGesture=function(t){var e;switch(t.type){case"circle":e=new u(t);break;case"swipe":e=new c(t);break;case"screenTap":e=new l(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 o=new a(t,r);i[t.id]=o,s.each(n,function(t,e){o.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]});a.prototype.update=function(t,e){this.lastGesture=t,this.lastFrame=e,this.gestures.push(t),this.frames.push(e),this.emit(t.state,this)},a.prototype.translation=function(){return r.subtract(r.create(),this.lastGesture.startPosition,this.lastGesture.position)},s.extend(a.prototype,o.prototype);var u=function(t){this.center=t.center,this.normal=t.normal,this.progress=t.progress,this.radius=t.radius};u.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 l=function(t){this.position=t.position,this.direction=t.direction,this.progress=t.progress};l.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:2,"gl-matrix":24,underscore:25}],14:[function(t,e){var n=t("./pointable"),i=t("./bone"),r=t("gl-matrix"),o=r.mat3,s=r.vec3,a=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 i(this,{type:4,width:t.armWidth,prevJoint:t.elbow,nextJoint:t.wrist,basis:t.armBasis}):null,this.tools=[],this._translation=t.t,this._rotation=a.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:n.Invalid},u.prototype.rotationAngle=function(t,e){if(!this.valid||!t.valid)return 0;var n=t.hand(this.id);if(!n.valid)return 0;var i=this.rotationMatrix(t),r=.5*(i[0]+i[4]+i[8]-1),o=Math.acos(r);if(o=isNaN(o)?0:o,void 0!==e){var a=this.rotationAxis(t);o*=s.dot(a,s.normalize(s.create(),e))}return o},u.prototype.rotationAxis=function(t){if(!this.valid||!t.valid)return s.create();var e=t.hand(this.id);return e.valid?s.normalize(s.create(),[this._rotation[7]-e._rotation[5],this._rotation[2]-e._rotation[6],this._rotation[3]-e._rotation[1]]):s.create()},u.prototype.rotationMatrix=function(t){if(!this.valid||!t.valid)return o.create();var e=t.hand(this.id);if(!e.valid)return o.create();var n=o.transpose(o.create(),this._rotation),i=o.multiply(o.create(),e._rotation,n);return i},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 s.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]]:s.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 n.Invalid},finger:function(){return n.Invalid},toString:function(){return"invalid frame"},dump:function(){return this.toString()},rotationAngle:function(){return 0},rotationMatrix:function(){return o.create()},rotationAxis:function(){return s.create()},scaleFactor:function(){return 1},translation:function(){return s.create()}}},{"./bone":4,"./pointable":18,"gl-matrix":24,underscore:25}],15:[function(t,e){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":5,"./controller":9,"./finger":11,"./frame":12,"./gesture":13,"./hand":14,"./interaction_box":16,"./pointable":18,"./protocol":19,"./ui":20,"./version.js":23,events:2,"gl-matrix":24,underscore:25}],16:[function(t,e){var n=t("gl-matrix"),i=n.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":24}],17:[function(t,e){var n=e.exports=function(t){this.steps=[],this.controller=t};n.prototype.addStep=function(t){this.steps.push(t)},n.prototype.run=function(t){for(var e=this.steps.length,n=0;n!=e&&t;n++)t=this.steps[n](t);return t},n.prototype.removeStep=function(t){var e=this.steps.indexOf(t);if(-1===e)throw"Step not found in pipeline";this.steps.splice(e,1)},n.prototype.addWrappedStep=function(t,e){var n=this.controller,i=function(i){var r,o,s;for(r="frame"==t?[i]:i[t+"s"]||[],o=0,s=r.length;s>o;o++)e.call(n,r[o]);return i};return this.addStep(i),i}},{}],18:[function(t,e){var n=t("gl-matrix"),i=(n.vec3,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":24}],19:[function(t,e,n){var i=t("./frame"),r=(t("./hand"),t("./pointable"),t("./finger"),t("underscore")),o=t("events").EventEmitter,s=function(t){this.type=t.type,this.state=t.state};n.chooseProtocol=function(t){var e;switch(t.version){case 1:case 2:case 3:case 4:case 5:case 6:e=a(t),e.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 a=n.JSONProtocol=function(t){var e=function(t){if(t.event)return new s(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":11,"./frame":12,"./hand":14,"./pointable":18,events:2,underscore:25}],20:[function(t,e,n){n.UI={Region:t("./ui/region"),Cursor:t("./ui/cursor")}},{"./ui/cursor":21,"./ui/region":22}],21:[function(t,e){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}}},{}],22:[function(t,e){var n=t("events").EventEmitter,i=t("underscore"),r=e.exports=function(t,e){this.start=new Vector(t),this.end=new Vector(e),this.enteredFrame=null};r.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},r.prototype.listener=function(t){var e=this;return t&&t.nearThreshold&&this.setupNearRegion(t.nearThreshold),function(t){return e.updatePosition(t)}},r.prototype.clipper=function(){var t=this;return function(e){return t.updatePosition(e),t.enteredFrame?e:null}},r.prototype.setupNearRegion=function(t){var e=this.nearRegion=new r([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)})},r.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},r.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)])},r.prototype.mapToXY=function(t,e,n){var i=this.normalize(t),r=i.x,o=i.y;return r>1?r=1:-1>r&&(r=-1),o>1?o=1:-1>o&&(o=-1),[(r+1)/2*e,(1-o)/2*n,i.z]},i.extend(r.prototype,n.prototype)},{events:2,underscore:25}],23:[function(t,e){e.exports={full:"0.6.4",major:0,minor:6,dot:4}},{}],24:[function(e,n,i){!function(e){"use strict";var n={};"undefined"==typeof i?"function"==typeof t&&"object"==typeof t.amd&&t.amd?(n.exports={},t(function(){return n.exports})):n.exports="undefined"!=typeof window?window:e:n.exports=i,function(t){if(!e)var e=1e-6;if(!n)var n="undefined"!=typeof Float32Array?Float32Array:Array;if(!i)var i=Math.random;var r={};r.setMatrixArrayType=function(t){n=t},"undefined"!=typeof t&&(t.glMatrix=r);var o=Math.PI/180;r.toRadian=function(t){return t*o};var s={};s.create=function(){var t=new n(2);return t[0]=0,t[1]=0,t},s.clone=function(t){var e=new n(2);return e[0]=t[0],e[1]=t[1],e},s.fromValues=function(t,e){var i=new n(2);return i[0]=t,i[1]=e,i},s.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t},s.set=function(t,e,n){return t[0]=e,t[1]=n,t},s.add=function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t},s.subtract=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t},s.sub=s.subtract,s.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t},s.mul=s.multiply,s.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t},s.div=s.divide,s.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t},s.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t},s.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t},s.scaleAndAdd=function(t,e,n,i){return t[0]=e[0]+n[0]*i,t[1]=e[1]+n[1]*i,t},s.distance=function(t,e){var n=e[0]-t[0],i=e[1]-t[1];return Math.sqrt(n*n+i*i)},s.dist=s.distance,s.squaredDistance=function(t,e){var n=e[0]-t[0],i=e[1]-t[1];return n*n+i*i},s.sqrDist=s.squaredDistance,s.length=function(t){var e=t[0],n=t[1];return Math.sqrt(e*e+n*n)},s.len=s.length,s.squaredLength=function(t){var e=t[0],n=t[1];return e*e+n*n},s.sqrLen=s.squaredLength,s.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t},s.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},s.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},s.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},s.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},s.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},s.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},s.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},s.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},s.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},s.forEach=function(){var t=s.create();return function(e,n,i,r,o,s){var a,u;for(n||(n=2),i||(i=0),u=r?Math.min(r*n+i,e.length):e.length,a=i;u>a;a+=n)t[0]=e[a],t[1]=e[a+1],o(t,t,s),e[a]=t[0],e[a+1]=t[1];return e}}(),s.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},"undefined"!=typeof t&&(t.vec2=s);var a={};a.create=function(){var t=new n(3);return t[0]=0,t[1]=0,t[2]=0,t},a.clone=function(t){var e=new n(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},a.fromValues=function(t,e,i){var r=new n(3);return r[0]=t,r[1]=e,r[2]=i,r},a.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},a.set=function(t,e,n,i){return t[0]=e,t[1]=n,t[2]=i,t},a.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},a.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},a.sub=a.subtract,a.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},a.mul=a.multiply,a.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},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[2]=Math.min(e[2],n[2]),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[2]=Math.max(e[2],n[2]),t},a.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*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[2]=e[2]+n[2]*i,t},a.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)},a.dist=a.distance,a.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},a.sqrDist=a.squaredDistance,a.length=function(t){var e=t[0],n=t[1],i=t[2];return Math.sqrt(e*e+n*n+i*i)},a.len=a.length,a.squaredLength=function(t){var e=t[0],n=t[1],i=t[2];return e*e+n*n+i*i},a.sqrLen=a.squaredLength,a.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},a.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},a.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},a.cross=function(t,e,n){var i=e[0],r=e[1],o=e[2],s=n[0],a=n[1],u=n[2];return t[0]=r*u-o*a,t[1]=o*s-i*u,t[2]=i*a-r*s,t},a.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},a.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},a.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},a.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},a.transformQuat=function(t,e,n){var i=e[0],r=e[1],o=e[2],s=n[0],a=n[1],u=n[2],c=n[3],l=c*i+a*o-u*r,h=c*r+u*i-s*o,p=c*o+s*r-a*i,f=-s*i-a*r-u*o;return t[0]=l*c+f*-s+h*-u-p*-a,t[1]=h*c+f*-a+p*-s-l*-u,t[2]=p*c+f*-u+l*-a-h*-s,t},a.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},a.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},a.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},a.forEach=function(){var t=a.create();return function(e,n,i,r,o,s){var a,u;for(n||(n=3),i||(i=0),u=r?Math.min(r*n+i,e.length):e.length,a=i;u>a;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}}(),a.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},"undefined"!=typeof t&&(t.vec3=a);var u={};u.create=function(){var t=new n(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},u.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},u.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},u.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},u.set=function(t,e,n,i,r){return t[0]=e,t[1]=n,t[2]=i,t[3]=r,t},u.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},u.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.tran