aframe-extras.controls.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. require('./src/controls');
  4. },{"./src/controls":7}],2:[function(require,module,exports){
  5. "use strict";
  6. module.exports = Object.assign(function GamepadButton() {}, {
  7. FACE_1: 0,
  8. FACE_2: 1,
  9. FACE_3: 2,
  10. FACE_4: 3,
  11. L_SHOULDER_1: 4,
  12. R_SHOULDER_1: 5,
  13. L_SHOULDER_2: 6,
  14. R_SHOULDER_2: 7,
  15. SELECT: 8,
  16. START: 9,
  17. DPAD_UP: 12,
  18. DPAD_DOWN: 13,
  19. DPAD_LEFT: 14,
  20. DPAD_RIGHT: 15,
  21. VENDOR: 16
  22. });
  23. },{}],3:[function(require,module,exports){
  24. "use strict";
  25. function GamepadButtonEvent(type, index, details) {
  26. this.type = type;
  27. this.index = index;
  28. this.pressed = details.pressed;
  29. this.value = details.value;
  30. }
  31. module.exports = GamepadButtonEvent;
  32. },{}],4:[function(require,module,exports){
  33. 'use strict';
  34. /**
  35. * Polyfill for the additional KeyboardEvent properties defined in the D3E and
  36. * D4E draft specifications, by @inexorabletash.
  37. *
  38. * See: https://github.com/inexorabletash/polyfill
  39. */
  40. (function (global) {
  41. var nativeKeyboardEvent = 'KeyboardEvent' in global;
  42. if (!nativeKeyboardEvent) global.KeyboardEvent = function KeyboardEvent() {
  43. throw TypeError('Illegal constructor');
  44. };
  45. if (!('DOM_KEY_LOCATION_STANDARD' in global.KeyboardEvent)) global.KeyboardEvent.DOM_KEY_LOCATION_STANDARD = 0x00; // Default or unknown location
  46. if (!('DOM_KEY_LOCATION_LEFT' in global.KeyboardEvent)) global.KeyboardEvent.DOM_KEY_LOCATION_LEFT = 0x01; // e.g. Left Alt key
  47. if (!('DOM_KEY_LOCATION_RIGHT' in global.KeyboardEvent)) global.KeyboardEvent.DOM_KEY_LOCATION_RIGHT = 0x02; // e.g. Right Alt key
  48. if (!('DOM_KEY_LOCATION_NUMPAD' in global.KeyboardEvent)) global.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD = 0x03; // e.g. Numpad 0 or +
  49. var STANDARD = window.KeyboardEvent.DOM_KEY_LOCATION_STANDARD,
  50. LEFT = window.KeyboardEvent.DOM_KEY_LOCATION_LEFT,
  51. RIGHT = window.KeyboardEvent.DOM_KEY_LOCATION_RIGHT,
  52. NUMPAD = window.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD;
  53. //--------------------------------------------------------------------
  54. //
  55. // Utilities
  56. //
  57. //--------------------------------------------------------------------
  58. function contains(s, ss) {
  59. return String(s).indexOf(ss) !== -1;
  60. }
  61. var os = function () {
  62. if (contains(navigator.platform, 'Win')) {
  63. return 'win';
  64. }
  65. if (contains(navigator.platform, 'Mac')) {
  66. return 'mac';
  67. }
  68. if (contains(navigator.platform, 'CrOS')) {
  69. return 'cros';
  70. }
  71. if (contains(navigator.platform, 'Linux')) {
  72. return 'linux';
  73. }
  74. if (contains(navigator.userAgent, 'iPad') || contains(navigator.platform, 'iPod') || contains(navigator.platform, 'iPhone')) {
  75. return 'ios';
  76. }
  77. return '';
  78. }();
  79. var browser = function () {
  80. if (contains(navigator.userAgent, 'Chrome/')) {
  81. return 'chrome';
  82. }
  83. if (contains(navigator.vendor, 'Apple')) {
  84. return 'safari';
  85. }
  86. if (contains(navigator.userAgent, 'MSIE')) {
  87. return 'ie';
  88. }
  89. if (contains(navigator.userAgent, 'Gecko/')) {
  90. return 'moz';
  91. }
  92. if (contains(navigator.userAgent, 'Opera/')) {
  93. return 'opera';
  94. }
  95. return '';
  96. }();
  97. var browser_os = browser + '-' + os;
  98. function mergeIf(baseTable, select, table) {
  99. if (browser_os === select || browser === select || os === select) {
  100. Object.keys(table).forEach(function (keyCode) {
  101. baseTable[keyCode] = table[keyCode];
  102. });
  103. }
  104. }
  105. function remap(o, key) {
  106. var r = {};
  107. Object.keys(o).forEach(function (k) {
  108. var item = o[k];
  109. if (key in item) {
  110. r[item[key]] = item;
  111. }
  112. });
  113. return r;
  114. }
  115. function invert(o) {
  116. var r = {};
  117. Object.keys(o).forEach(function (k) {
  118. r[o[k]] = k;
  119. });
  120. return r;
  121. }
  122. //--------------------------------------------------------------------
  123. //
  124. // Generic Mappings
  125. //
  126. //--------------------------------------------------------------------
  127. // "keyInfo" is a dictionary:
  128. // code: string - name from DOM Level 3 KeyboardEvent code Values
  129. // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3Events-code.html
  130. // location (optional): number - one of the DOM_KEY_LOCATION values
  131. // keyCap (optional): string - keyboard label in en-US locale
  132. // USB code Usage ID from page 0x07 unless otherwise noted (Informative)
  133. // Map of keyCode to keyInfo
  134. var keyCodeToInfoTable = {
  135. // 0x01 - VK_LBUTTON
  136. // 0x02 - VK_RBUTTON
  137. 0x03: { code: 'Cancel' }, // [USB: 0x9b] char \x0018 ??? (Not in D3E)
  138. // 0x04 - VK_MBUTTON
  139. // 0x05 - VK_XBUTTON1
  140. // 0x06 - VK_XBUTTON2
  141. 0x06: { code: 'Help' }, // [USB: 0x75] ???
  142. // 0x07 - undefined
  143. 0x08: { code: 'Backspace' }, // [USB: 0x2a] Labelled Delete on Macintosh keyboards.
  144. 0x09: { code: 'Tab' }, // [USB: 0x2b]
  145. // 0x0A-0x0B - reserved
  146. 0X0C: { code: 'Clear' }, // [USB: 0x9c] NumPad Center (Not in D3E)
  147. 0X0D: { code: 'Enter' }, // [USB: 0x28]
  148. // 0x0E-0x0F - undefined
  149. 0x10: { code: 'Shift' },
  150. 0x11: { code: 'Control' },
  151. 0x12: { code: 'Alt' },
  152. 0x13: { code: 'Pause' }, // [USB: 0x48]
  153. 0x14: { code: 'CapsLock' }, // [USB: 0x39]
  154. 0x15: { code: 'KanaMode' }, // [USB: 0x88] - "HangulMode" for Korean layout
  155. 0x16: { code: 'HangulMode' }, // [USB: 0x90] 0x15 as well in MSDN VK table ???
  156. 0x17: { code: 'JunjaMode' }, // (Not in D3E)
  157. 0x18: { code: 'FinalMode' }, // (Not in D3E)
  158. 0x19: { code: 'KanjiMode' }, // [USB: 0x91] - "HanjaMode" for Korean layout
  159. // 0x1A - undefined
  160. 0x1B: { code: 'Escape' }, // [USB: 0x29]
  161. 0x1C: { code: 'Convert' }, // [USB: 0x8a]
  162. 0x1D: { code: 'NonConvert' }, // [USB: 0x8b]
  163. 0x1E: { code: 'Accept' }, // (Not in D3E)
  164. 0x1F: { code: 'ModeChange' }, // (Not in D3E)
  165. 0x20: { code: 'Space' }, // [USB: 0x2c]
  166. 0x21: { code: 'PageUp' }, // [USB: 0x4b]
  167. 0x22: { code: 'PageDown' }, // [USB: 0x4e]
  168. 0x23: { code: 'End' }, // [USB: 0x4d]
  169. 0x24: { code: 'Home' }, // [USB: 0x4a]
  170. 0x25: { code: 'ArrowLeft' }, // [USB: 0x50]
  171. 0x26: { code: 'ArrowUp' }, // [USB: 0x52]
  172. 0x27: { code: 'ArrowRight' }, // [USB: 0x4f]
  173. 0x28: { code: 'ArrowDown' }, // [USB: 0x51]
  174. 0x29: { code: 'Select' }, // (Not in D3E)
  175. 0x2A: { code: 'Print' }, // (Not in D3E)
  176. 0x2B: { code: 'Execute' }, // [USB: 0x74] (Not in D3E)
  177. 0x2C: { code: 'PrintScreen' }, // [USB: 0x46]
  178. 0x2D: { code: 'Insert' }, // [USB: 0x49]
  179. 0x2E: { code: 'Delete' }, // [USB: 0x4c]
  180. 0x2F: { code: 'Help' }, // [USB: 0x75] ???
  181. 0x30: { code: 'Digit0', keyCap: '0' }, // [USB: 0x27] 0)
  182. 0x31: { code: 'Digit1', keyCap: '1' }, // [USB: 0x1e] 1!
  183. 0x32: { code: 'Digit2', keyCap: '2' }, // [USB: 0x1f] 2@
  184. 0x33: { code: 'Digit3', keyCap: '3' }, // [USB: 0x20] 3#
  185. 0x34: { code: 'Digit4', keyCap: '4' }, // [USB: 0x21] 4$
  186. 0x35: { code: 'Digit5', keyCap: '5' }, // [USB: 0x22] 5%
  187. 0x36: { code: 'Digit6', keyCap: '6' }, // [USB: 0x23] 6^
  188. 0x37: { code: 'Digit7', keyCap: '7' }, // [USB: 0x24] 7&
  189. 0x38: { code: 'Digit8', keyCap: '8' }, // [USB: 0x25] 8*
  190. 0x39: { code: 'Digit9', keyCap: '9' }, // [USB: 0x26] 9(
  191. // 0x3A-0x40 - undefined
  192. 0x41: { code: 'KeyA', keyCap: 'a' }, // [USB: 0x04]
  193. 0x42: { code: 'KeyB', keyCap: 'b' }, // [USB: 0x05]
  194. 0x43: { code: 'KeyC', keyCap: 'c' }, // [USB: 0x06]
  195. 0x44: { code: 'KeyD', keyCap: 'd' }, // [USB: 0x07]
  196. 0x45: { code: 'KeyE', keyCap: 'e' }, // [USB: 0x08]
  197. 0x46: { code: 'KeyF', keyCap: 'f' }, // [USB: 0x09]
  198. 0x47: { code: 'KeyG', keyCap: 'g' }, // [USB: 0x0a]
  199. 0x48: { code: 'KeyH', keyCap: 'h' }, // [USB: 0x0b]
  200. 0x49: { code: 'KeyI', keyCap: 'i' }, // [USB: 0x0c]
  201. 0x4A: { code: 'KeyJ', keyCap: 'j' }, // [USB: 0x0d]
  202. 0x4B: { code: 'KeyK', keyCap: 'k' }, // [USB: 0x0e]
  203. 0x4C: { code: 'KeyL', keyCap: 'l' }, // [USB: 0x0f]
  204. 0x4D: { code: 'KeyM', keyCap: 'm' }, // [USB: 0x10]
  205. 0x4E: { code: 'KeyN', keyCap: 'n' }, // [USB: 0x11]
  206. 0x4F: { code: 'KeyO', keyCap: 'o' }, // [USB: 0x12]
  207. 0x50: { code: 'KeyP', keyCap: 'p' }, // [USB: 0x13]
  208. 0x51: { code: 'KeyQ', keyCap: 'q' }, // [USB: 0x14]
  209. 0x52: { code: 'KeyR', keyCap: 'r' }, // [USB: 0x15]
  210. 0x53: { code: 'KeyS', keyCap: 's' }, // [USB: 0x16]
  211. 0x54: { code: 'KeyT', keyCap: 't' }, // [USB: 0x17]
  212. 0x55: { code: 'KeyU', keyCap: 'u' }, // [USB: 0x18]
  213. 0x56: { code: 'KeyV', keyCap: 'v' }, // [USB: 0x19]
  214. 0x57: { code: 'KeyW', keyCap: 'w' }, // [USB: 0x1a]
  215. 0x58: { code: 'KeyX', keyCap: 'x' }, // [USB: 0x1b]
  216. 0x59: { code: 'KeyY', keyCap: 'y' }, // [USB: 0x1c]
  217. 0x5A: { code: 'KeyZ', keyCap: 'z' }, // [USB: 0x1d]
  218. 0x5B: { code: 'OSLeft', location: LEFT }, // [USB: 0xe3]
  219. 0x5C: { code: 'OSRight', location: RIGHT }, // [USB: 0xe7]
  220. 0x5D: { code: 'ContextMenu' }, // [USB: 0x65] Context Menu
  221. // 0x5E - reserved
  222. 0x5F: { code: 'Standby' }, // [USB: 0x82] Sleep
  223. 0x60: { code: 'Numpad0', keyCap: '0', location: NUMPAD }, // [USB: 0x62]
  224. 0x61: { code: 'Numpad1', keyCap: '1', location: NUMPAD }, // [USB: 0x59]
  225. 0x62: { code: 'Numpad2', keyCap: '2', location: NUMPAD }, // [USB: 0x5a]
  226. 0x63: { code: 'Numpad3', keyCap: '3', location: NUMPAD }, // [USB: 0x5b]
  227. 0x64: { code: 'Numpad4', keyCap: '4', location: NUMPAD }, // [USB: 0x5c]
  228. 0x65: { code: 'Numpad5', keyCap: '5', location: NUMPAD }, // [USB: 0x5d]
  229. 0x66: { code: 'Numpad6', keyCap: '6', location: NUMPAD }, // [USB: 0x5e]
  230. 0x67: { code: 'Numpad7', keyCap: '7', location: NUMPAD }, // [USB: 0x5f]
  231. 0x68: { code: 'Numpad8', keyCap: '8', location: NUMPAD }, // [USB: 0x60]
  232. 0x69: { code: 'Numpad9', keyCap: '9', location: NUMPAD }, // [USB: 0x61]
  233. 0x6A: { code: 'NumpadMultiply', keyCap: '*', location: NUMPAD }, // [USB: 0x55]
  234. 0x6B: { code: 'NumpadAdd', keyCap: '+', location: NUMPAD }, // [USB: 0x57]
  235. 0x6C: { code: 'NumpadComma', keyCap: ',', location: NUMPAD }, // [USB: 0x85]
  236. 0x6D: { code: 'NumpadSubtract', keyCap: '-', location: NUMPAD }, // [USB: 0x56]
  237. 0x6E: { code: 'NumpadDecimal', keyCap: '.', location: NUMPAD }, // [USB: 0x63]
  238. 0x6F: { code: 'NumpadDivide', keyCap: '/', location: NUMPAD }, // [USB: 0x54]
  239. 0x70: { code: 'F1' }, // [USB: 0x3a]
  240. 0x71: { code: 'F2' }, // [USB: 0x3b]
  241. 0x72: { code: 'F3' }, // [USB: 0x3c]
  242. 0x73: { code: 'F4' }, // [USB: 0x3d]
  243. 0x74: { code: 'F5' }, // [USB: 0x3e]
  244. 0x75: { code: 'F6' }, // [USB: 0x3f]
  245. 0x76: { code: 'F7' }, // [USB: 0x40]
  246. 0x77: { code: 'F8' }, // [USB: 0x41]
  247. 0x78: { code: 'F9' }, // [USB: 0x42]
  248. 0x79: { code: 'F10' }, // [USB: 0x43]
  249. 0x7A: { code: 'F11' }, // [USB: 0x44]
  250. 0x7B: { code: 'F12' }, // [USB: 0x45]
  251. 0x7C: { code: 'F13' }, // [USB: 0x68]
  252. 0x7D: { code: 'F14' }, // [USB: 0x69]
  253. 0x7E: { code: 'F15' }, // [USB: 0x6a]
  254. 0x7F: { code: 'F16' }, // [USB: 0x6b]
  255. 0x80: { code: 'F17' }, // [USB: 0x6c]
  256. 0x81: { code: 'F18' }, // [USB: 0x6d]
  257. 0x82: { code: 'F19' }, // [USB: 0x6e]
  258. 0x83: { code: 'F20' }, // [USB: 0x6f]
  259. 0x84: { code: 'F21' }, // [USB: 0x70]
  260. 0x85: { code: 'F22' }, // [USB: 0x71]
  261. 0x86: { code: 'F23' }, // [USB: 0x72]
  262. 0x87: { code: 'F24' }, // [USB: 0x73]
  263. // 0x88-0x8F - unassigned
  264. 0x90: { code: 'NumLock', location: NUMPAD }, // [USB: 0x53]
  265. 0x91: { code: 'ScrollLock' }, // [USB: 0x47]
  266. // 0x92-0x96 - OEM specific
  267. // 0x97-0x9F - unassigned
  268. // NOTE: 0xA0-0xA5 usually mapped to 0x10-0x12 in browsers
  269. 0xA0: { code: 'ShiftLeft', location: LEFT }, // [USB: 0xe1]
  270. 0xA1: { code: 'ShiftRight', location: RIGHT }, // [USB: 0xe5]
  271. 0xA2: { code: 'ControlLeft', location: LEFT }, // [USB: 0xe0]
  272. 0xA3: { code: 'ControlRight', location: RIGHT }, // [USB: 0xe4]
  273. 0xA4: { code: 'AltLeft', location: LEFT }, // [USB: 0xe2]
  274. 0xA5: { code: 'AltRight', location: RIGHT }, // [USB: 0xe6]
  275. 0xA6: { code: 'BrowserBack' }, // [USB: 0x0c/0x0224]
  276. 0xA7: { code: 'BrowserForward' }, // [USB: 0x0c/0x0225]
  277. 0xA8: { code: 'BrowserRefresh' }, // [USB: 0x0c/0x0227]
  278. 0xA9: { code: 'BrowserStop' }, // [USB: 0x0c/0x0226]
  279. 0xAA: { code: 'BrowserSearch' }, // [USB: 0x0c/0x0221]
  280. 0xAB: { code: 'BrowserFavorites' }, // [USB: 0x0c/0x0228]
  281. 0xAC: { code: 'BrowserHome' }, // [USB: 0x0c/0x0222]
  282. 0xAD: { code: 'VolumeMute' }, // [USB: 0x7f]
  283. 0xAE: { code: 'VolumeDown' }, // [USB: 0x81]
  284. 0xAF: { code: 'VolumeUp' }, // [USB: 0x80]
  285. 0xB0: { code: 'MediaTrackNext' }, // [USB: 0x0c/0x00b5]
  286. 0xB1: { code: 'MediaTrackPrevious' }, // [USB: 0x0c/0x00b6]
  287. 0xB2: { code: 'MediaStop' }, // [USB: 0x0c/0x00b7]
  288. 0xB3: { code: 'MediaPlayPause' }, // [USB: 0x0c/0x00cd]
  289. 0xB4: { code: 'LaunchMail' }, // [USB: 0x0c/0x018a]
  290. 0xB5: { code: 'MediaSelect' },
  291. 0xB6: { code: 'LaunchApp1' },
  292. 0xB7: { code: 'LaunchApp2' },
  293. // 0xB8-0xB9 - reserved
  294. 0xBA: { code: 'Semicolon', keyCap: ';' }, // [USB: 0x33] ;: (US Standard 101)
  295. 0xBB: { code: 'Equal', keyCap: '=' }, // [USB: 0x2e] =+
  296. 0xBC: { code: 'Comma', keyCap: ',' }, // [USB: 0x36] ,<
  297. 0xBD: { code: 'Minus', keyCap: '-' }, // [USB: 0x2d] -_
  298. 0xBE: { code: 'Period', keyCap: '.' }, // [USB: 0x37] .>
  299. 0xBF: { code: 'Slash', keyCap: '/' }, // [USB: 0x38] /? (US Standard 101)
  300. 0xC0: { code: 'Backquote', keyCap: '`' }, // [USB: 0x35] `~ (US Standard 101)
  301. // 0xC1-0xCF - reserved
  302. // 0xD0-0xD7 - reserved
  303. // 0xD8-0xDA - unassigned
  304. 0xDB: { code: 'BracketLeft', keyCap: '[' }, // [USB: 0x2f] [{ (US Standard 101)
  305. 0xDC: { code: 'Backslash', keyCap: '\\' }, // [USB: 0x31] \| (US Standard 101)
  306. 0xDD: { code: 'BracketRight', keyCap: ']' }, // [USB: 0x30] ]} (US Standard 101)
  307. 0xDE: { code: 'Quote', keyCap: '\'' }, // [USB: 0x34] '" (US Standard 101)
  308. // 0xDF - miscellaneous/varies
  309. // 0xE0 - reserved
  310. // 0xE1 - OEM specific
  311. 0xE2: { code: 'IntlBackslash', keyCap: '\\' }, // [USB: 0x64] \| (UK Standard 102)
  312. // 0xE3-0xE4 - OEM specific
  313. 0xE5: { code: 'Process' }, // (Not in D3E)
  314. // 0xE6 - OEM specific
  315. // 0xE7 - VK_PACKET
  316. // 0xE8 - unassigned
  317. // 0xE9-0xEF - OEM specific
  318. // 0xF0-0xF5 - OEM specific
  319. 0xF6: { code: 'Attn' }, // [USB: 0x9a] (Not in D3E)
  320. 0xF7: { code: 'CrSel' }, // [USB: 0xa3] (Not in D3E)
  321. 0xF8: { code: 'ExSel' }, // [USB: 0xa4] (Not in D3E)
  322. 0xF9: { code: 'EraseEof' }, // (Not in D3E)
  323. 0xFA: { code: 'Play' }, // (Not in D3E)
  324. 0xFB: { code: 'ZoomToggle' }, // (Not in D3E)
  325. // 0xFC - VK_NONAME - reserved
  326. // 0xFD - VK_PA1
  327. 0xFE: { code: 'Clear' // [USB: 0x9c] (Not in D3E)
  328. } };
  329. // No legacy keyCode, but listed in D3E:
  330. // code: usb
  331. // 'IntlHash': 0x070032,
  332. // 'IntlRo': 0x070087,
  333. // 'IntlYen': 0x070089,
  334. // 'NumpadBackspace': 0x0700bb,
  335. // 'NumpadClear': 0x0700d8,
  336. // 'NumpadClearEntry': 0x0700d9,
  337. // 'NumpadMemoryAdd': 0x0700d3,
  338. // 'NumpadMemoryClear': 0x0700d2,
  339. // 'NumpadMemoryRecall': 0x0700d1,
  340. // 'NumpadMemoryStore': 0x0700d0,
  341. // 'NumpadMemorySubtract': 0x0700d4,
  342. // 'NumpadParenLeft': 0x0700b6,
  343. // 'NumpadParenRight': 0x0700b7,
  344. //--------------------------------------------------------------------
  345. //
  346. // Browser/OS Specific Mappings
  347. //
  348. //--------------------------------------------------------------------
  349. mergeIf(keyCodeToInfoTable, 'moz', {
  350. 0x3B: { code: 'Semicolon', keyCap: ';' }, // [USB: 0x33] ;: (US Standard 101)
  351. 0x3D: { code: 'Equal', keyCap: '=' }, // [USB: 0x2e] =+
  352. 0x6B: { code: 'Equal', keyCap: '=' }, // [USB: 0x2e] =+
  353. 0x6D: { code: 'Minus', keyCap: '-' }, // [USB: 0x2d] -_
  354. 0xBB: { code: 'NumpadAdd', keyCap: '+', location: NUMPAD }, // [USB: 0x57]
  355. 0xBD: { code: 'NumpadSubtract', keyCap: '-', location: NUMPAD // [USB: 0x56]
  356. } });
  357. mergeIf(keyCodeToInfoTable, 'moz-mac', {
  358. 0x0C: { code: 'NumLock', location: NUMPAD }, // [USB: 0x53]
  359. 0xAD: { code: 'Minus', keyCap: '-' // [USB: 0x2d] -_
  360. } });
  361. mergeIf(keyCodeToInfoTable, 'moz-win', {
  362. 0xAD: { code: 'Minus', keyCap: '-' // [USB: 0x2d] -_
  363. } });
  364. mergeIf(keyCodeToInfoTable, 'chrome-mac', {
  365. 0x5D: { code: 'OSRight', location: RIGHT // [USB: 0xe7]
  366. } });
  367. // Windows via Bootcamp (!)
  368. if (0) {
  369. mergeIf(keyCodeToInfoTable, 'chrome-win', {
  370. 0xC0: { code: 'Quote', keyCap: '\'' }, // [USB: 0x34] '" (US Standard 101)
  371. 0xDE: { code: 'Backslash', keyCap: '\\' }, // [USB: 0x31] \| (US Standard 101)
  372. 0xDF: { code: 'Backquote', keyCap: '`' // [USB: 0x35] `~ (US Standard 101)
  373. } });
  374. mergeIf(keyCodeToInfoTable, 'ie', {
  375. 0xC0: { code: 'Quote', keyCap: '\'' }, // [USB: 0x34] '" (US Standard 101)
  376. 0xDE: { code: 'Backslash', keyCap: '\\' }, // [USB: 0x31] \| (US Standard 101)
  377. 0xDF: { code: 'Backquote', keyCap: '`' // [USB: 0x35] `~ (US Standard 101)
  378. } });
  379. }
  380. mergeIf(keyCodeToInfoTable, 'safari', {
  381. 0x03: { code: 'Enter' }, // [USB: 0x28] old Safari
  382. 0x19: { code: 'Tab' // [USB: 0x2b] old Safari for Shift+Tab
  383. } });
  384. mergeIf(keyCodeToInfoTable, 'ios', {
  385. 0x0A: { code: 'Enter', location: STANDARD // [USB: 0x28]
  386. } });
  387. mergeIf(keyCodeToInfoTable, 'safari-mac', {
  388. 0x5B: { code: 'OSLeft', location: LEFT }, // [USB: 0xe3]
  389. 0x5D: { code: 'OSRight', location: RIGHT }, // [USB: 0xe7]
  390. 0xE5: { code: 'KeyQ', keyCap: 'Q' // [USB: 0x14] On alternate presses, Ctrl+Q sends this
  391. } });
  392. //--------------------------------------------------------------------
  393. //
  394. // Identifier Mappings
  395. //
  396. //--------------------------------------------------------------------
  397. // Cases where newer-ish browsers send keyIdentifier which can be
  398. // used to disambiguate keys.
  399. // keyIdentifierTable[keyIdentifier] -> keyInfo
  400. var keyIdentifierTable = {};
  401. if ('cros' === os) {
  402. keyIdentifierTable['U+00A0'] = { code: 'ShiftLeft', location: LEFT };
  403. keyIdentifierTable['U+00A1'] = { code: 'ShiftRight', location: RIGHT };
  404. keyIdentifierTable['U+00A2'] = { code: 'ControlLeft', location: LEFT };
  405. keyIdentifierTable['U+00A3'] = { code: 'ControlRight', location: RIGHT };
  406. keyIdentifierTable['U+00A4'] = { code: 'AltLeft', location: LEFT };
  407. keyIdentifierTable['U+00A5'] = { code: 'AltRight', location: RIGHT };
  408. }
  409. if ('chrome-mac' === browser_os) {
  410. keyIdentifierTable['U+0010'] = { code: 'ContextMenu' };
  411. }
  412. if ('safari-mac' === browser_os) {
  413. keyIdentifierTable['U+0010'] = { code: 'ContextMenu' };
  414. }
  415. if ('ios' === os) {
  416. // These only generate keyup events
  417. keyIdentifierTable['U+0010'] = { code: 'Function' };
  418. keyIdentifierTable['U+001C'] = { code: 'ArrowLeft' };
  419. keyIdentifierTable['U+001D'] = { code: 'ArrowRight' };
  420. keyIdentifierTable['U+001E'] = { code: 'ArrowUp' };
  421. keyIdentifierTable['U+001F'] = { code: 'ArrowDown' };
  422. keyIdentifierTable['U+0001'] = { code: 'Home' }; // [USB: 0x4a] Fn + ArrowLeft
  423. keyIdentifierTable['U+0004'] = { code: 'End' }; // [USB: 0x4d] Fn + ArrowRight
  424. keyIdentifierTable['U+000B'] = { code: 'PageUp' }; // [USB: 0x4b] Fn + ArrowUp
  425. keyIdentifierTable['U+000C'] = { code: 'PageDown' }; // [USB: 0x4e] Fn + ArrowDown
  426. }
  427. //--------------------------------------------------------------------
  428. //
  429. // Location Mappings
  430. //
  431. //--------------------------------------------------------------------
  432. // Cases where newer-ish browsers send location/keyLocation which
  433. // can be used to disambiguate keys.
  434. // locationTable[location][keyCode] -> keyInfo
  435. var locationTable = [];
  436. locationTable[LEFT] = {
  437. 0x10: { code: 'ShiftLeft', location: LEFT }, // [USB: 0xe1]
  438. 0x11: { code: 'ControlLeft', location: LEFT }, // [USB: 0xe0]
  439. 0x12: { code: 'AltLeft', location: LEFT // [USB: 0xe2]
  440. } };
  441. locationTable[RIGHT] = {
  442. 0x10: { code: 'ShiftRight', location: RIGHT }, // [USB: 0xe5]
  443. 0x11: { code: 'ControlRight', location: RIGHT }, // [USB: 0xe4]
  444. 0x12: { code: 'AltRight', location: RIGHT // [USB: 0xe6]
  445. } };
  446. locationTable[NUMPAD] = {
  447. 0x0D: { code: 'NumpadEnter', location: NUMPAD // [USB: 0x58]
  448. } };
  449. mergeIf(locationTable[NUMPAD], 'moz', {
  450. 0x6D: { code: 'NumpadSubtract', location: NUMPAD }, // [USB: 0x56]
  451. 0x6B: { code: 'NumpadAdd', location: NUMPAD // [USB: 0x57]
  452. } });
  453. mergeIf(locationTable[LEFT], 'moz-mac', {
  454. 0xE0: { code: 'OSLeft', location: LEFT // [USB: 0xe3]
  455. } });
  456. mergeIf(locationTable[RIGHT], 'moz-mac', {
  457. 0xE0: { code: 'OSRight', location: RIGHT // [USB: 0xe7]
  458. } });
  459. mergeIf(locationTable[RIGHT], 'moz-win', {
  460. 0x5B: { code: 'OSRight', location: RIGHT // [USB: 0xe7]
  461. } });
  462. mergeIf(locationTable[RIGHT], 'mac', {
  463. 0x5D: { code: 'OSRight', location: RIGHT // [USB: 0xe7]
  464. } });
  465. mergeIf(locationTable[NUMPAD], 'chrome-mac', {
  466. 0x0C: { code: 'NumLock', location: NUMPAD // [USB: 0x53]
  467. } });
  468. mergeIf(locationTable[NUMPAD], 'safari-mac', {
  469. 0x0C: { code: 'NumLock', location: NUMPAD }, // [USB: 0x53]
  470. 0xBB: { code: 'NumpadAdd', location: NUMPAD }, // [USB: 0x57]
  471. 0xBD: { code: 'NumpadSubtract', location: NUMPAD }, // [USB: 0x56]
  472. 0xBE: { code: 'NumpadDecimal', location: NUMPAD }, // [USB: 0x63]
  473. 0xBF: { code: 'NumpadDivide', location: NUMPAD // [USB: 0x54]
  474. } });
  475. //--------------------------------------------------------------------
  476. //
  477. // Key Values
  478. //
  479. //--------------------------------------------------------------------
  480. // Mapping from `code` values to `key` values. Values defined at:
  481. // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3Events-key.html
  482. // Entries are only provided when `key` differs from `code`. If
  483. // printable, `shiftKey` has the shifted printable character. This
  484. // assumes US Standard 101 layout
  485. var codeToKeyTable = {
  486. // Modifier Keys
  487. ShiftLeft: { key: 'Shift' },
  488. ShiftRight: { key: 'Shift' },
  489. ControlLeft: { key: 'Control' },
  490. ControlRight: { key: 'Control' },
  491. AltLeft: { key: 'Alt' },
  492. AltRight: { key: 'Alt' },
  493. OSLeft: { key: 'OS' },
  494. OSRight: { key: 'OS' },
  495. // Whitespace Keys
  496. NumpadEnter: { key: 'Enter' },
  497. Space: { key: ' ' },
  498. // Printable Keys
  499. Digit0: { key: '0', shiftKey: ')' },
  500. Digit1: { key: '1', shiftKey: '!' },
  501. Digit2: { key: '2', shiftKey: '@' },
  502. Digit3: { key: '3', shiftKey: '#' },
  503. Digit4: { key: '4', shiftKey: '$' },
  504. Digit5: { key: '5', shiftKey: '%' },
  505. Digit6: { key: '6', shiftKey: '^' },
  506. Digit7: { key: '7', shiftKey: '&' },
  507. Digit8: { key: '8', shiftKey: '*' },
  508. Digit9: { key: '9', shiftKey: '(' },
  509. KeyA: { key: 'a', shiftKey: 'A' },
  510. KeyB: { key: 'b', shiftKey: 'B' },
  511. KeyC: { key: 'c', shiftKey: 'C' },
  512. KeyD: { key: 'd', shiftKey: 'D' },
  513. KeyE: { key: 'e', shiftKey: 'E' },
  514. KeyF: { key: 'f', shiftKey: 'F' },
  515. KeyG: { key: 'g', shiftKey: 'G' },
  516. KeyH: { key: 'h', shiftKey: 'H' },
  517. KeyI: { key: 'i', shiftKey: 'I' },
  518. KeyJ: { key: 'j', shiftKey: 'J' },
  519. KeyK: { key: 'k', shiftKey: 'K' },
  520. KeyL: { key: 'l', shiftKey: 'L' },
  521. KeyM: { key: 'm', shiftKey: 'M' },
  522. KeyN: { key: 'n', shiftKey: 'N' },
  523. KeyO: { key: 'o', shiftKey: 'O' },
  524. KeyP: { key: 'p', shiftKey: 'P' },
  525. KeyQ: { key: 'q', shiftKey: 'Q' },
  526. KeyR: { key: 'r', shiftKey: 'R' },
  527. KeyS: { key: 's', shiftKey: 'S' },
  528. KeyT: { key: 't', shiftKey: 'T' },
  529. KeyU: { key: 'u', shiftKey: 'U' },
  530. KeyV: { key: 'v', shiftKey: 'V' },
  531. KeyW: { key: 'w', shiftKey: 'W' },
  532. KeyX: { key: 'x', shiftKey: 'X' },
  533. KeyY: { key: 'y', shiftKey: 'Y' },
  534. KeyZ: { key: 'z', shiftKey: 'Z' },
  535. Numpad0: { key: '0' },
  536. Numpad1: { key: '1' },
  537. Numpad2: { key: '2' },
  538. Numpad3: { key: '3' },
  539. Numpad4: { key: '4' },
  540. Numpad5: { key: '5' },
  541. Numpad6: { key: '6' },
  542. Numpad7: { key: '7' },
  543. Numpad8: { key: '8' },
  544. Numpad9: { key: '9' },
  545. NumpadMultiply: { key: '*' },
  546. NumpadAdd: { key: '+' },
  547. NumpadComma: { key: ',' },
  548. NumpadSubtract: { key: '-' },
  549. NumpadDecimal: { key: '.' },
  550. NumpadDivide: { key: '/' },
  551. Semicolon: { key: ';', shiftKey: ':' },
  552. Equal: { key: '=', shiftKey: '+' },
  553. Comma: { key: ',', shiftKey: '<' },
  554. Minus: { key: '-', shiftKey: '_' },
  555. Period: { key: '.', shiftKey: '>' },
  556. Slash: { key: '/', shiftKey: '?' },
  557. Backquote: { key: '`', shiftKey: '~' },
  558. BracketLeft: { key: '[', shiftKey: '{' },
  559. Backslash: { key: '\\', shiftKey: '|' },
  560. BracketRight: { key: ']', shiftKey: '}' },
  561. Quote: { key: '\'', shiftKey: '"' },
  562. IntlBackslash: { key: '\\', shiftKey: '|' }
  563. };
  564. mergeIf(codeToKeyTable, 'mac', {
  565. OSLeft: { key: 'Meta' },
  566. OSRight: { key: 'Meta' }
  567. });
  568. // Corrections for 'key' names in older browsers (e.g. FF36-)
  569. // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.key#Key_values
  570. var keyFixTable = {
  571. Esc: 'Escape',
  572. Nonconvert: 'NonConvert',
  573. Left: 'ArrowLeft',
  574. Up: 'ArrowUp',
  575. Right: 'ArrowRight',
  576. Down: 'ArrowDown',
  577. Del: 'Delete',
  578. Menu: 'ContextMenu',
  579. MediaNextTrack: 'MediaTrackNext',
  580. MediaPreviousTrack: 'MediaTrackPrevious',
  581. SelectMedia: 'MediaSelect',
  582. HalfWidth: 'Hankaku',
  583. FullWidth: 'Zenkaku',
  584. RomanCharacters: 'Romaji',
  585. Crsel: 'CrSel',
  586. Exsel: 'ExSel',
  587. Zoom: 'ZoomToggle'
  588. };
  589. //--------------------------------------------------------------------
  590. //
  591. // Exported Functions
  592. //
  593. //--------------------------------------------------------------------
  594. var codeTable = remap(keyCodeToInfoTable, 'code');
  595. try {
  596. var nativeLocation = nativeKeyboardEvent && 'location' in new KeyboardEvent('');
  597. } catch (_) {}
  598. function keyInfoForEvent(event) {
  599. var keyCode = 'keyCode' in event ? event.keyCode : 'which' in event ? event.which : 0;
  600. var keyInfo = function () {
  601. if (nativeLocation || 'keyLocation' in event) {
  602. var location = nativeLocation ? event.location : event.keyLocation;
  603. if (location && keyCode in locationTable[location]) {
  604. return locationTable[location][keyCode];
  605. }
  606. }
  607. if ('keyIdentifier' in event && event.keyIdentifier in keyIdentifierTable) {
  608. return keyIdentifierTable[event.keyIdentifier];
  609. }
  610. if (keyCode in keyCodeToInfoTable) {
  611. return keyCodeToInfoTable[keyCode];
  612. }
  613. return null;
  614. }();
  615. // TODO: Track these down and move to general tables
  616. if (0) {
  617. // TODO: Map these for newerish browsers?
  618. // TODO: iOS only?
  619. // TODO: Override with more common keyIdentifier name?
  620. switch (event.keyIdentifier) {
  621. case 'U+0010':
  622. keyInfo = { code: 'Function' };break;
  623. case 'U+001C':
  624. keyInfo = { code: 'ArrowLeft' };break;
  625. case 'U+001D':
  626. keyInfo = { code: 'ArrowRight' };break;
  627. case 'U+001E':
  628. keyInfo = { code: 'ArrowUp' };break;
  629. case 'U+001F':
  630. keyInfo = { code: 'ArrowDown' };break;
  631. }
  632. }
  633. if (!keyInfo) return null;
  634. var key = function () {
  635. var entry = codeToKeyTable[keyInfo.code];
  636. if (!entry) return keyInfo.code;
  637. return event.shiftKey && 'shiftKey' in entry ? entry.shiftKey : entry.key;
  638. }();
  639. return {
  640. code: keyInfo.code,
  641. key: key,
  642. location: keyInfo.location,
  643. keyCap: keyInfo.keyCap
  644. };
  645. }
  646. function queryKeyCap(code, locale) {
  647. code = String(code);
  648. if (!codeTable.hasOwnProperty(code)) return 'Undefined';
  649. if (locale && String(locale).toLowerCase() !== 'en-us') throw Error('Unsupported locale');
  650. var keyInfo = codeTable[code];
  651. return keyInfo.keyCap || keyInfo.code || 'Undefined';
  652. }
  653. if ('KeyboardEvent' in global && 'defineProperty' in Object) {
  654. (function () {
  655. function define(o, p, v) {
  656. if (p in o) return;
  657. Object.defineProperty(o, p, v);
  658. }
  659. define(KeyboardEvent.prototype, 'code', { get: function get() {
  660. var keyInfo = keyInfoForEvent(this);
  661. return keyInfo ? keyInfo.code : '';
  662. } });
  663. // Fix for nonstandard `key` values (FF36-)
  664. if ('key' in KeyboardEvent.prototype) {
  665. var desc = Object.getOwnPropertyDescriptor(KeyboardEvent.prototype, 'key');
  666. Object.defineProperty(KeyboardEvent.prototype, 'key', { get: function get() {
  667. var key = desc.get.call(this);
  668. return keyFixTable.hasOwnProperty(key) ? keyFixTable[key] : key;
  669. } });
  670. }
  671. define(KeyboardEvent.prototype, 'key', { get: function get() {
  672. var keyInfo = keyInfoForEvent(this);
  673. return keyInfo && 'key' in keyInfo ? keyInfo.key : 'Unidentified';
  674. } });
  675. define(KeyboardEvent.prototype, 'location', { get: function get() {
  676. var keyInfo = keyInfoForEvent(this);
  677. return keyInfo && 'location' in keyInfo ? keyInfo.location : STANDARD;
  678. } });
  679. define(KeyboardEvent.prototype, 'locale', { get: function get() {
  680. return '';
  681. } });
  682. })();
  683. }
  684. if (!('queryKeyCap' in global.KeyboardEvent)) global.KeyboardEvent.queryKeyCap = queryKeyCap;
  685. // Helper for IE8-
  686. global.identifyKey = function (event) {
  687. if ('code' in event) return;
  688. var keyInfo = keyInfoForEvent(event);
  689. event.code = keyInfo ? keyInfo.code : '';
  690. event.key = keyInfo && 'key' in keyInfo ? keyInfo.key : 'Unidentified';
  691. event.location = 'location' in event ? event.location : 'keyLocation' in event ? event.keyLocation : keyInfo && 'location' in keyInfo ? keyInfo.location : STANDARD;
  692. event.locale = '';
  693. };
  694. })(window);
  695. },{}],5:[function(require,module,exports){
  696. 'use strict';
  697. var EPS = 0.1;
  698. module.exports = AFRAME.registerComponent('checkpoint-controls', {
  699. schema: {
  700. enabled: { default: true },
  701. mode: { default: 'teleport', oneOf: ['teleport', 'animate'] },
  702. animateSpeed: { default: 3.0 }
  703. },
  704. init: function init() {
  705. this.active = true;
  706. this.checkpoint = null;
  707. this.isNavMeshConstrained = false;
  708. this.offset = new THREE.Vector3();
  709. this.position = new THREE.Vector3();
  710. this.targetPosition = new THREE.Vector3();
  711. },
  712. play: function play() {
  713. this.active = true;
  714. },
  715. pause: function pause() {
  716. this.active = false;
  717. },
  718. setCheckpoint: function setCheckpoint(checkpoint) {
  719. var el = this.el;
  720. if (!this.active) return;
  721. if (this.checkpoint === checkpoint) return;
  722. if (this.checkpoint) {
  723. el.emit('navigation-end', { checkpoint: this.checkpoint });
  724. }
  725. this.checkpoint = checkpoint;
  726. this.sync();
  727. // Ignore new checkpoint if we're already there.
  728. if (this.position.distanceTo(this.targetPosition) < EPS) {
  729. this.checkpoint = null;
  730. return;
  731. }
  732. el.emit('navigation-start', { checkpoint: checkpoint });
  733. if (this.data.mode === 'teleport') {
  734. this.el.setAttribute('position', this.targetPosition);
  735. this.checkpoint = null;
  736. el.emit('navigation-end', { checkpoint: checkpoint });
  737. el.components['movement-controls'].updateNavNode();
  738. }
  739. },
  740. isVelocityActive: function isVelocityActive() {
  741. return !!(this.active && this.checkpoint);
  742. },
  743. getVelocity: function getVelocity() {
  744. if (!this.active) return;
  745. var data = this.data;
  746. var offset = this.offset;
  747. var position = this.position;
  748. var targetPosition = this.targetPosition;
  749. var checkpoint = this.checkpoint;
  750. this.sync();
  751. if (position.distanceTo(targetPosition) < EPS) {
  752. this.checkpoint = null;
  753. this.el.emit('navigation-end', { checkpoint: checkpoint });
  754. return offset.set(0, 0, 0);
  755. }
  756. offset.setLength(data.animateSpeed);
  757. return offset;
  758. },
  759. sync: function sync() {
  760. var offset = this.offset;
  761. var position = this.position;
  762. var targetPosition = this.targetPosition;
  763. position.copy(this.el.getAttribute('position'));
  764. targetPosition.copy(this.checkpoint.object3D.getWorldPosition());
  765. targetPosition.add(this.checkpoint.components.checkpoint.getOffset());
  766. offset.copy(targetPosition).sub(position);
  767. }
  768. });
  769. },{}],6:[function(require,module,exports){
  770. 'use strict';
  771. /**
  772. * Gamepad controls for A-Frame.
  773. *
  774. * Stripped-down version of: https://github.com/donmccurdy/aframe-gamepad-controls
  775. *
  776. * For more information about the Gamepad API, see:
  777. * https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API
  778. */
  779. var GamepadButton = require('../../lib/GamepadButton'),
  780. GamepadButtonEvent = require('../../lib/GamepadButtonEvent');
  781. var JOYSTICK_EPS = 0.2;
  782. module.exports = AFRAME.registerComponent('gamepad-controls', {
  783. /*******************************************************************
  784. * Statics
  785. */
  786. GamepadButton: GamepadButton,
  787. /*******************************************************************
  788. * Schema
  789. */
  790. schema: {
  791. // Controller 0-3
  792. controller: { default: 0, oneOf: [0, 1, 2, 3] },
  793. // Enable/disable features
  794. enabled: { default: true },
  795. // Debugging
  796. debug: { default: false },
  797. // Heading element for rotation
  798. camera: { default: '[camera]', type: 'selector' },
  799. // Rotation sensitivity
  800. rotationSensitivity: { default: 0.05 // radians/frame, ish
  801. } },
  802. /*******************************************************************
  803. * Core
  804. */
  805. /**
  806. * Called once when component is attached. Generally for initial setup.
  807. */
  808. init: function init() {
  809. var scene = this.el.sceneEl;
  810. this.prevTime = window.performance.now();
  811. // Button state
  812. this.buttons = {};
  813. // Rotation
  814. var rotation = this.el.object3D.rotation;
  815. this.pitch = new THREE.Object3D();
  816. this.pitch.rotation.x = THREE.Math.degToRad(rotation.x);
  817. this.yaw = new THREE.Object3D();
  818. this.yaw.position.y = 10;
  819. this.yaw.rotation.y = THREE.Math.degToRad(rotation.y);
  820. this.yaw.add(this.pitch);
  821. scene.addBehavior(this);
  822. },
  823. /**
  824. * Called when component is attached and when component data changes.
  825. * Generally modifies the entity based on the data.
  826. */
  827. update: function update() {
  828. this.tick();
  829. },
  830. /**
  831. * Called on each iteration of main render loop.
  832. */
  833. tick: function tick(t, dt) {
  834. this.updateButtonState();
  835. this.updateRotation(dt);
  836. },
  837. /**
  838. * Called when a component is removed (e.g., via removeAttribute).
  839. * Generally undoes all modifications to the entity.
  840. */
  841. remove: function remove() {},
  842. /*******************************************************************
  843. * Movement
  844. */
  845. isVelocityActive: function isVelocityActive() {
  846. if (!this.data.enabled || !this.isConnected()) return false;
  847. var dpad = this.getDpad(),
  848. joystick0 = this.getJoystick(0),
  849. inputX = dpad.x || joystick0.x,
  850. inputY = dpad.y || joystick0.y;
  851. return Math.abs(inputX) > JOYSTICK_EPS || Math.abs(inputY) > JOYSTICK_EPS;
  852. },
  853. getVelocityDelta: function getVelocityDelta() {
  854. var dpad = this.getDpad(),
  855. joystick0 = this.getJoystick(0),
  856. inputX = dpad.x || joystick0.x,
  857. inputY = dpad.y || joystick0.y,
  858. dVelocity = new THREE.Vector3();
  859. if (Math.abs(inputX) > JOYSTICK_EPS) {
  860. dVelocity.x += inputX;
  861. }
  862. if (Math.abs(inputY) > JOYSTICK_EPS) {
  863. dVelocity.z += inputY;
  864. }
  865. return dVelocity;
  866. },
  867. /*******************************************************************
  868. * Rotation
  869. */
  870. isRotationActive: function isRotationActive() {
  871. if (!this.data.enabled || !this.isConnected()) return false;
  872. var joystick1 = this.getJoystick(1);
  873. return Math.abs(joystick1.x) > JOYSTICK_EPS || Math.abs(joystick1.y) > JOYSTICK_EPS;
  874. },
  875. updateRotation: function updateRotation(dt) {
  876. if (!this.isRotationActive()) return;
  877. var lookVector = this.getJoystick(1);
  878. if (Math.abs(lookVector.x) <= JOYSTICK_EPS) lookVector.x = 0;
  879. if (Math.abs(lookVector.y) <= JOYSTICK_EPS) lookVector.y = 0;
  880. var data = this.data;
  881. var yaw = this.yaw;
  882. var pitch = this.pitch;
  883. lookVector.multiplyScalar(data.rotationSensitivity * dt / 1000);
  884. yaw.rotation.y -= lookVector.x;
  885. pitch.rotation.x -= lookVector.y;
  886. pitch.rotation.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, pitch.rotation.x));
  887. data.camera.object3D.rotation.set(THREE.Math.radToDeg(pitch.rotation.x), THREE.Math.radToDeg(yaw.rotation.y), 0);
  888. },
  889. /*******************************************************************
  890. * Button events
  891. */
  892. updateButtonState: function updateButtonState() {
  893. var gamepad = this.getGamepad();
  894. if (this.data.enabled && gamepad) {
  895. // Fire DOM events for button state changes.
  896. for (var i = 0; i < gamepad.buttons.length; i++) {
  897. if (gamepad.buttons[i].pressed && !this.buttons[i]) {
  898. this.emit(new GamepadButtonEvent('gamepadbuttondown', i, gamepad.buttons[i]));
  899. } else if (!gamepad.buttons[i].pressed && this.buttons[i]) {
  900. this.emit(new GamepadButtonEvent('gamepadbuttonup', i, gamepad.buttons[i]));
  901. }
  902. this.buttons[i] = gamepad.buttons[i].pressed;
  903. }
  904. } else if (Object.keys(this.buttons)) {
  905. // Reset state if controls are disabled or controller is lost.
  906. this.buttons = {};
  907. }
  908. },
  909. emit: function emit(event) {
  910. // Emit original event.
  911. this.el.emit(event.type, event);
  912. // Emit convenience event, identifying button index.
  913. this.el.emit(event.type + ':' + event.index, new GamepadButtonEvent(event.type, event.index, event));
  914. },
  915. /*******************************************************************
  916. * Gamepad state
  917. */
  918. /**
  919. * Returns the Gamepad instance attached to the component. If connected,
  920. * a proxy-controls component may provide access to Gamepad input from a
  921. * remote device.
  922. *
  923. * @return {Gamepad}
  924. */
  925. getGamepad: function getGamepad() {
  926. var localGamepad = navigator.getGamepads && navigator.getGamepads()[this.data.controller],
  927. proxyControls = this.el.sceneEl.components['proxy-controls'],
  928. proxyGamepad = proxyControls && proxyControls.isConnected() && proxyControls.getGamepad(this.data.controller);
  929. return proxyGamepad || localGamepad;
  930. },
  931. /**
  932. * Returns the state of the given button.
  933. * @param {number} index The button (0-N) for which to find state.
  934. * @return {GamepadButton}
  935. */
  936. getButton: function getButton(index) {
  937. return this.getGamepad().buttons[index];
  938. },
  939. /**
  940. * Returns state of the given axis. Axes are labelled 0-N, where 0-1 will
  941. * represent X/Y on the first joystick, and 2-3 X/Y on the second.
  942. * @param {number} index The axis (0-N) for which to find state.
  943. * @return {number} On the interval [-1,1].
  944. */
  945. getAxis: function getAxis(index) {
  946. return this.getGamepad().axes[index];
  947. },
  948. /**
  949. * Returns the state of the given joystick (0 or 1) as a THREE.Vector2.
  950. * @param {number} id The joystick (0, 1) for which to find state.
  951. * @return {THREE.Vector2}
  952. */
  953. getJoystick: function getJoystick(index) {
  954. var gamepad = this.getGamepad();
  955. switch (index) {
  956. case 0:
  957. return new THREE.Vector2(gamepad.axes[0], gamepad.axes[1]);
  958. case 1:
  959. return new THREE.Vector2(gamepad.axes[2], gamepad.axes[3]);
  960. default:
  961. throw new Error('Unexpected joystick index "%d".', index);
  962. }
  963. },
  964. /**
  965. * Returns the state of the dpad as a THREE.Vector2.
  966. * @return {THREE.Vector2}
  967. */
  968. getDpad: function getDpad() {
  969. var gamepad = this.getGamepad();
  970. if (!gamepad.buttons[GamepadButton.DPAD_RIGHT]) {
  971. return new THREE.Vector2();
  972. }
  973. return new THREE.Vector2((gamepad.buttons[GamepadButton.DPAD_RIGHT].pressed ? 1 : 0) + (gamepad.buttons[GamepadButton.DPAD_LEFT].pressed ? -1 : 0), (gamepad.buttons[GamepadButton.DPAD_UP].pressed ? -1 : 0) + (gamepad.buttons[GamepadButton.DPAD_DOWN].pressed ? 1 : 0));
  974. },
  975. /**
  976. * Returns true if the gamepad is currently connected to the system.
  977. * @return {boolean}
  978. */
  979. isConnected: function isConnected() {
  980. var gamepad = this.getGamepad();
  981. return !!(gamepad && gamepad.connected);
  982. },
  983. /**
  984. * Returns a string containing some information about the controller. Result
  985. * may vary across browsers, for a given controller.
  986. * @return {string}
  987. */
  988. getID: function getID() {
  989. return this.getGamepad().id;
  990. }
  991. });
  992. },{"../../lib/GamepadButton":2,"../../lib/GamepadButtonEvent":3}],7:[function(require,module,exports){
  993. 'use strict';
  994. require('./checkpoint-controls');
  995. require('./gamepad-controls');
  996. require('./keyboard-controls');
  997. require('./touch-controls');
  998. require('./movement-controls');
  999. require('./trackpad-controls');
  1000. },{"./checkpoint-controls":5,"./gamepad-controls":6,"./keyboard-controls":8,"./movement-controls":9,"./touch-controls":10,"./trackpad-controls":11}],8:[function(require,module,exports){
  1001. 'use strict';
  1002. require('../../lib/keyboard.polyfill');
  1003. var MAX_DELTA = 0.2,
  1004. PROXY_FLAG = '__keyboard-controls-proxy';
  1005. var KeyboardEvent = window.KeyboardEvent;
  1006. /**
  1007. * Keyboard Controls component.
  1008. *
  1009. * Stripped-down version of: https://github.com/donmccurdy/aframe-keyboard-controls
  1010. *
  1011. * Bind keyboard events to components, or control your entities with the WASD keys.
  1012. *
  1013. * Why use KeyboardEvent.code? "This is set to a string representing the key that was pressed to
  1014. * generate the KeyboardEvent, without taking the current keyboard layout (e.g., QWERTY vs.
  1015. * Dvorak), locale (e.g., English vs. French), or any modifier keys into account. This is useful
  1016. * when you care about which physical key was pressed, rather thanwhich character it corresponds
  1017. * to. For example, if you’re a writing a game, you might want a certain set of keys to move the
  1018. * player in different directions, and that mapping should ideally be independent of keyboard
  1019. * layout. See: https://developers.google.com/web/updates/2016/04/keyboardevent-keys-codes
  1020. *
  1021. * @namespace wasd-controls
  1022. * keys the entity moves and if you release it will stop. Easing simulates friction.
  1023. * to the entity when pressing the keys.
  1024. * @param {bool} [enabled=true] - To completely enable or disable the controls
  1025. */
  1026. module.exports = AFRAME.registerComponent('keyboard-controls', {
  1027. schema: {
  1028. enabled: { default: true },
  1029. debug: { default: false }
  1030. },
  1031. init: function init() {
  1032. this.dVelocity = new THREE.Vector3();
  1033. this.localKeys = {};
  1034. this.listeners = {
  1035. keydown: this.onKeyDown.bind(this),
  1036. keyup: this.onKeyUp.bind(this),
  1037. blur: this.onBlur.bind(this)
  1038. };
  1039. this.attachEventListeners();
  1040. },
  1041. /*******************************************************************
  1042. * Movement
  1043. */
  1044. isVelocityActive: function isVelocityActive() {
  1045. return this.data.enabled && !!Object.keys(this.getKeys()).length;
  1046. },
  1047. getVelocityDelta: function getVelocityDelta() {
  1048. var data = this.data,
  1049. keys = this.getKeys();
  1050. this.dVelocity.set(0, 0, 0);
  1051. if (data.enabled) {
  1052. if (keys.KeyW || keys.ArrowUp) {
  1053. this.dVelocity.z -= 1;
  1054. }
  1055. if (keys.KeyA || keys.ArrowLeft) {
  1056. this.dVelocity.x -= 1;
  1057. }
  1058. if (keys.KeyS || keys.ArrowDown) {
  1059. this.dVelocity.z += 1;
  1060. }
  1061. if (keys.KeyD || keys.ArrowRight) {
  1062. this.dVelocity.x += 1;
  1063. }
  1064. }
  1065. return this.dVelocity.clone();
  1066. },
  1067. /*******************************************************************
  1068. * Events
  1069. */
  1070. play: function play() {
  1071. this.attachEventListeners();
  1072. },
  1073. pause: function pause() {
  1074. this.removeEventListeners();
  1075. },
  1076. remove: function remove() {
  1077. this.pause();
  1078. },
  1079. attachEventListeners: function attachEventListeners() {
  1080. window.addEventListener('keydown', this.listeners.keydown, false);
  1081. window.addEventListener('keyup', this.listeners.keyup, false);
  1082. window.addEventListener('blur', this.listeners.blur, false);
  1083. },
  1084. removeEventListeners: function removeEventListeners() {
  1085. window.removeEventListener('keydown', this.listeners.keydown);
  1086. window.removeEventListener('keyup', this.listeners.keyup);
  1087. window.removeEventListener('blur', this.listeners.blur);
  1088. },
  1089. onKeyDown: function onKeyDown(event) {
  1090. if (AFRAME.utils.shouldCaptureKeyEvent(event)) {
  1091. this.localKeys[event.code] = true;
  1092. this.emit(event);
  1093. }
  1094. },
  1095. onKeyUp: function onKeyUp(event) {
  1096. if (AFRAME.utils.shouldCaptureKeyEvent(event)) {
  1097. delete this.localKeys[event.code];
  1098. this.emit(event);
  1099. }
  1100. },
  1101. onBlur: function onBlur() {
  1102. for (var code in this.localKeys) {
  1103. if (this.localKeys.hasOwnProperty(code)) {
  1104. delete this.localKeys[code];
  1105. }
  1106. }
  1107. },
  1108. emit: function emit(event) {
  1109. // TODO - keydown only initially?
  1110. // TODO - where the f is the spacebar
  1111. // Emit original event.
  1112. if (PROXY_FLAG in event) {
  1113. // TODO - Method never triggered.
  1114. this.el.emit(event.type, event);
  1115. }
  1116. // Emit convenience event, identifying key.
  1117. this.el.emit(event.type + ':' + event.code, new KeyboardEvent(event.type, event));
  1118. if (this.data.debug) console.log(event.type + ':' + event.code);
  1119. },
  1120. /*******************************************************************
  1121. * Accessors
  1122. */
  1123. isPressed: function isPressed(code) {
  1124. return code in this.getKeys();
  1125. },
  1126. getKeys: function getKeys() {
  1127. if (this.isProxied()) {
  1128. return this.el.sceneEl.components['proxy-controls'].getKeyboard();
  1129. }
  1130. return this.localKeys;
  1131. },
  1132. isProxied: function isProxied() {
  1133. var proxyControls = this.el.sceneEl.components['proxy-controls'];
  1134. return proxyControls && proxyControls.isConnected();
  1135. }
  1136. });
  1137. },{"../../lib/keyboard.polyfill":4}],9:[function(require,module,exports){
  1138. 'use strict';
  1139. /**
  1140. * Movement Controls
  1141. *
  1142. * @author Don McCurdy <dm@donmccurdy.com>
  1143. */
  1144. var COMPONENT_SUFFIX = '-controls',
  1145. MAX_DELTA = 0.2,
  1146. // ms
  1147. EPS = 10e-6;
  1148. module.exports = AFRAME.registerComponent('movement-controls', {
  1149. /*******************************************************************
  1150. * Schema
  1151. */
  1152. dependencies: ['rotation'],
  1153. schema: {
  1154. enabled: { default: true },
  1155. controls: { default: ['gamepad', 'trackpad', 'keyboard', 'touch'] },
  1156. easing: { default: 15 }, // m/s2
  1157. easingY: { default: 0 }, // m/s2
  1158. acceleration: { default: 80 }, // m/s2
  1159. fly: { default: false },
  1160. constrainToNavMesh: { default: false },
  1161. camera: { default: '[camera]', type: 'selector' }
  1162. },
  1163. /*******************************************************************
  1164. * Lifecycle
  1165. */
  1166. init: function init() {
  1167. var el = this.el;
  1168. this.velocityCtrl = null;
  1169. this.velocity = new THREE.Vector3();
  1170. this.heading = new THREE.Quaternion();
  1171. // Navigation
  1172. this.navGroup = null;
  1173. this.navNode = null;
  1174. if (el.sceneEl.hasLoaded) {
  1175. this.injectControls();
  1176. } else {
  1177. el.sceneEl.addEventListener('loaded', this.injectControls.bind(this));
  1178. }
  1179. },
  1180. update: function update() {
  1181. if (this.el.sceneEl.hasLoaded) {
  1182. this.injectControls();
  1183. }
  1184. },
  1185. injectControls: function injectControls() {
  1186. var data = this.data;
  1187. var name;
  1188. for (var i = 0; i < data.controls.length; i++) {
  1189. name = data.controls[i] + COMPONENT_SUFFIX;
  1190. if (!this.el.components[name]) {
  1191. this.el.setAttribute(name, '');
  1192. }
  1193. }
  1194. },
  1195. updateNavNode: function updateNavNode() {
  1196. this.navNode = null;
  1197. },
  1198. /*******************************************************************
  1199. * Tick
  1200. */
  1201. tick: function () {
  1202. var start = new THREE.Vector3();
  1203. var end = new THREE.Vector3();
  1204. var clampedEnd = new THREE.Vector3();
  1205. return function (t, dt) {
  1206. if (!dt) return;
  1207. var el = this.el;
  1208. var data = this.data;
  1209. if (!data.enabled) return;
  1210. this.updateVelocityCtrl();
  1211. var velocityCtrl = this.velocityCtrl;
  1212. var velocity = this.velocity;
  1213. if (!velocityCtrl) return;
  1214. // Update velocity. If FPS is too low, reset.
  1215. if (dt / 1000 > MAX_DELTA) {
  1216. velocity.set(0, 0, 0);
  1217. } else {
  1218. this.updateVelocity(dt);
  1219. }
  1220. if (data.constrainToNavMesh && velocityCtrl.isNavMeshConstrained !== false) {
  1221. if (velocity.lengthSq() < EPS) return;
  1222. start.copy(el.object3D.position);
  1223. end.copy(velocity).multiplyScalar(dt / 1000).add(start);
  1224. var nav = el.sceneEl.systems.nav;
  1225. this.navGroup = this.navGroup || nav.getGroup(start);
  1226. this.navNode = this.navNode || nav.getNode(start, this.navGroup);
  1227. this.navNode = nav.clampStep(start, end, this.navGroup, this.navNode, clampedEnd);
  1228. el.object3D.position.copy(clampedEnd);
  1229. } else if (el.hasAttribute('velocity')) {
  1230. el.setAttribute('velocity', velocity);
  1231. } else {
  1232. el.object3D.position.x += velocity.x * dt / 1000;
  1233. el.object3D.position.y += velocity.y * dt / 1000;
  1234. el.object3D.position.z += velocity.z * dt / 1000;
  1235. }
  1236. };
  1237. }(),
  1238. /*******************************************************************
  1239. * Movement
  1240. */
  1241. updateVelocityCtrl: function updateVelocityCtrl() {
  1242. var data = this.data;
  1243. if (data.enabled) {
  1244. for (var i = 0, l = data.controls.length; i < l; i++) {
  1245. var control = this.el.components[data.controls[i] + COMPONENT_SUFFIX];
  1246. if (control && control.isVelocityActive()) {
  1247. this.velocityCtrl = control;
  1248. return;
  1249. }
  1250. }
  1251. this.velocityCtrl = null;
  1252. }
  1253. },
  1254. updateVelocity: function () {
  1255. // var matrix = new THREE.Matrix4();
  1256. // var matrix2 = new THREE.Matrix4();
  1257. // var position = new THREE.Vector3();
  1258. // var quaternion = new THREE.Quaternion();
  1259. // var scale = new THREE.Vector3();
  1260. return function (dt) {
  1261. var dVelocity = void 0;
  1262. var el = this.el;
  1263. var control = this.velocityCtrl;
  1264. var velocity = this.velocity;
  1265. var data = this.data;
  1266. if (control) {
  1267. if (control.getVelocityDelta) {
  1268. dVelocity = control.getVelocityDelta(dt);
  1269. } else if (control.getVelocity) {
  1270. velocity.copy(control.getVelocity());
  1271. return;
  1272. } else if (control.getPositionDelta) {
  1273. velocity.copy(control.getPositionDelta(dt).multiplyScalar(1000 / dt));
  1274. return;
  1275. } else {
  1276. throw new Error('Incompatible movement controls: ', control);
  1277. }
  1278. }
  1279. if (AFRAME.components.velocity && !data.constrainToNavMesh) velocity.copy(this.el.getAttribute('velocity'));
  1280. velocity.x -= velocity.x * data.easing * dt / 1000;
  1281. velocity.y -= velocity.y * data.easingY * dt / 1000;
  1282. velocity.z -= velocity.z * data.easing * dt / 1000;
  1283. if (dVelocity && data.enabled) {
  1284. // Set acceleration
  1285. if (dVelocity.length() > 1) {
  1286. dVelocity.setLength(this.data.acceleration * dt / 1000);
  1287. } else {
  1288. dVelocity.multiplyScalar(this.data.acceleration * dt / 1000);
  1289. }
  1290. // TODO: Handle rotated rig.
  1291. var cameraEl = data.camera;
  1292. // matrix.copy(cameraEl.object3D.matrixWorld);
  1293. // matrix2.getInverse(el.object3D.matrixWorld);
  1294. // matrix.multiply(matrix2);
  1295. // matrix.decompose(position, quaternion, scale);
  1296. // dVelocity.applyQuaternion(quaternion);
  1297. // Rotate to heading
  1298. dVelocity.applyQuaternion(cameraEl.object3D.quaternion);
  1299. if (!data.fly) dVelocity.y = 0;
  1300. velocity.add(dVelocity);
  1301. }
  1302. };
  1303. }()
  1304. });
  1305. },{}],10:[function(require,module,exports){
  1306. 'use strict';
  1307. /**
  1308. * Touch-to-move-forward controls for mobile.
  1309. */
  1310. module.exports = AFRAME.registerComponent('touch-controls', {
  1311. schema: {
  1312. enabled: { default: true }
  1313. },
  1314. init: function init() {
  1315. this.dVelocity = new THREE.Vector3();
  1316. this.bindMethods();
  1317. },
  1318. play: function play() {
  1319. this.addEventListeners();
  1320. },
  1321. pause: function pause() {
  1322. this.removeEventListeners();
  1323. this.dVelocity.set(0, 0, 0);
  1324. },
  1325. remove: function remove() {
  1326. this.pause();
  1327. },
  1328. addEventListeners: function addEventListeners() {
  1329. var sceneEl = this.el.sceneEl;
  1330. var canvasEl = sceneEl.canvas;
  1331. if (!canvasEl) {
  1332. sceneEl.addEventListener('render-target-loaded', this.addEventListeners.bind(this));
  1333. return;
  1334. }
  1335. canvasEl.addEventListener('touchstart', this.onTouchStart);
  1336. canvasEl.addEventListener('touchend', this.onTouchEnd);
  1337. },
  1338. removeEventListeners: function removeEventListeners() {
  1339. var canvasEl = this.el.sceneEl && this.el.sceneEl.canvas;
  1340. if (!canvasEl) {
  1341. return;
  1342. }
  1343. canvasEl.removeEventListener('touchstart', this.onTouchStart);
  1344. canvasEl.removeEventListener('touchend', this.onTouchEnd);
  1345. },
  1346. isVelocityActive: function isVelocityActive() {
  1347. return this.data.enabled && this.isMoving;
  1348. },
  1349. getVelocityDelta: function getVelocityDelta() {
  1350. this.dVelocity.z = this.isMoving ? -1 : 0;
  1351. return this.dVelocity.clone();
  1352. },
  1353. bindMethods: function bindMethods() {
  1354. this.onTouchStart = this.onTouchStart.bind(this);
  1355. this.onTouchEnd = this.onTouchEnd.bind(this);
  1356. },
  1357. onTouchStart: function onTouchStart(e) {
  1358. this.isMoving = true;
  1359. e.preventDefault();
  1360. },
  1361. onTouchEnd: function onTouchEnd(e) {
  1362. this.isMoving = false;
  1363. e.preventDefault();
  1364. }
  1365. });
  1366. },{}],11:[function(require,module,exports){
  1367. 'use strict';
  1368. /**
  1369. * 3dof (Gear VR, Daydream) controls for mobile.
  1370. */
  1371. module.exports = AFRAME.registerComponent('trackpad-controls', {
  1372. schema: {
  1373. enabled: { default: true }
  1374. },
  1375. init: function init() {
  1376. this.dVelocity = new THREE.Vector3();
  1377. this.zVel = 0;
  1378. this.bindMethods();
  1379. },
  1380. play: function play() {
  1381. this.addEventListeners();
  1382. },
  1383. pause: function pause() {
  1384. this.removeEventListeners();
  1385. this.dVelocity.set(0, 0, 0);
  1386. },
  1387. remove: function remove() {
  1388. this.pause();
  1389. },
  1390. addEventListeners: function addEventListeners() {
  1391. var sceneEl = this.el.sceneEl;
  1392. sceneEl.addEventListener('axismove', this.onAxisMove);
  1393. sceneEl.addEventListener('trackpadtouchstart', this.onTouchStart);
  1394. sceneEl.addEventListener('trackpadtouchend', this.onTouchEnd);
  1395. },
  1396. removeEventListeners: function removeEventListeners() {
  1397. var sceneEl = this.el.sceneEl;
  1398. sceneEl.removeEventListener('axismove', this.onAxisMove);
  1399. sceneEl.removeEventListener('trackpadtouchstart', this.onTouchStart);
  1400. sceneEl.removeEventListener('trackpadtouchend', this.onTouchEnd);
  1401. },
  1402. isVelocityActive: function isVelocityActive() {
  1403. return this.data.enabled && this.isMoving;
  1404. },
  1405. getVelocityDelta: function getVelocityDelta() {
  1406. this.dVelocity.z = this.isMoving ? -this.zVel : 1;
  1407. return this.dVelocity.clone();
  1408. },
  1409. bindMethods: function bindMethods() {
  1410. this.onTouchStart = this.onTouchStart.bind(this);
  1411. this.onTouchEnd = this.onTouchEnd.bind(this);
  1412. this.onAxisMove = this.onAxisMove.bind(this);
  1413. },
  1414. onTouchStart: function onTouchStart(e) {
  1415. this.isMoving = true;
  1416. e.preventDefault();
  1417. },
  1418. onTouchEnd: function onTouchEnd(e) {
  1419. this.isMoving = false;
  1420. e.preventDefault();
  1421. },
  1422. onAxisMove: function onAxisMove(e) {
  1423. var axis_data = e.detail.axis;
  1424. if (axis_data[1] < 0) {
  1425. this.zVel = 1;
  1426. }
  1427. if (axis_data[1] > 0) {
  1428. this.zVel = -1;
  1429. }
  1430. }
  1431. });
  1432. },{}]},{},[1]);