elation-engine 0.9.113 → 0.9.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/css/systems/render.css +5 -1
  2. package/package.json +1 -1
  3. package/scripts/assets.js +103 -20
  4. package/scripts/assetworker.js +18 -1
  5. package/scripts/external/holoplay.js +1494 -0
  6. package/scripts/external/octree.js +0 -0
  7. package/scripts/external/three/CSS3DRenderer.js +46 -43
  8. package/scripts/external/three/CubemapToEquirectangular.js +1 -1
  9. package/scripts/external/three/three-extras.js +1553 -392
  10. package/scripts/external/three/three-icosa.js +2575 -0
  11. package/scripts/external/three/three-loaders.js +925 -133
  12. package/scripts/external/three/three-postprocessing.js +3 -3
  13. package/scripts/external/three/three-r116dev.js +50930 -0
  14. package/scripts/external/three/three-spotlighttextures.js +50953 -0
  15. package/scripts/external/three/three-vrm.js +2 -2
  16. package/scripts/external/three/three-working.js +35968 -0
  17. package/scripts/external/three/three.js +38532 -24087
  18. package/scripts/external/three-mesh-bvh.js +5370 -0
  19. package/scripts/external/three-old/BVHLoader.js +406 -0
  20. package/scripts/external/three-old/ColladaLoader.js +5519 -0
  21. package/scripts/external/three-old/ColladaLoader2.js +1694 -0
  22. package/scripts/external/three-old/CubemapToEquirectangular.js +188 -0
  23. package/scripts/external/three-old/DDSLoader.js +269 -0
  24. package/scripts/external/three-old/FBXLoader-mine.js +5063 -0
  25. package/scripts/external/three-old/FBXLoader.js +5112 -0
  26. package/scripts/external/three-old/FlyControls.js +295 -0
  27. package/scripts/external/three-old/GLTF2Loader.js +2950 -0
  28. package/scripts/external/three-old/GLTFLoader.js +2213 -0
  29. package/scripts/external/three-old/JSONLoader.js +435 -0
  30. package/scripts/external/three-old/MTLLoader.js +533 -0
  31. package/scripts/external/three-old/OBJLoader-experimental.js +874 -0
  32. package/scripts/external/three-old/OBJLoader-working.js +727 -0
  33. package/scripts/external/three-old/OBJLoader.js +723 -0
  34. package/scripts/external/three-old/OBJMTLLoader.js +440 -0
  35. package/scripts/external/three-old/OrbitControls.js +592 -0
  36. package/scripts/external/three-old/PLYLoader.js +517 -0
  37. package/scripts/external/three-old/TransformControls.js +1100 -0
  38. package/scripts/external/three-old/VRMLLoader.js +1021 -0
  39. package/scripts/external/three-old/glTFLoader-combined.js +2513 -0
  40. package/scripts/external/three-old/nodethree.js +44018 -0
  41. package/scripts/external/three-old/render/BleachBypassShader.js +64 -0
  42. package/scripts/external/three-old/render/BloomPass.js +116 -0
  43. package/scripts/external/three-old/render/CSS3DRenderer.js +310 -0
  44. package/scripts/external/three-old/render/ClearPass.js +44 -0
  45. package/scripts/external/three-old/render/ConvolutionShader.js +101 -0
  46. package/scripts/external/three-old/render/CopyShader.js +46 -0
  47. package/scripts/external/three-old/render/EffectComposer.js +211 -0
  48. package/scripts/external/three-old/render/FXAAShader.js +88 -0
  49. package/scripts/external/three-old/render/FilmPass.js +60 -0
  50. package/scripts/external/three-old/render/FilmShader.js +104 -0
  51. package/scripts/external/three-old/render/ManualMSAARenderPass.js +168 -0
  52. package/scripts/external/three-old/render/MaskPass.js +97 -0
  53. package/scripts/external/three-old/render/OculusRenderPass.js +84 -0
  54. package/scripts/external/three-old/render/OculusRiftEffect.js +240 -0
  55. package/scripts/external/three-old/render/PortalRenderPass.js +166 -0
  56. package/scripts/external/three-old/render/RecordingPass.js +208 -0
  57. package/scripts/external/three-old/render/RenderPass.js +57 -0
  58. package/scripts/external/three-old/render/SSAOShader.js +259 -0
  59. package/scripts/external/three-old/render/SepiaShader.js +54 -0
  60. package/scripts/external/three-old/render/ShaderPass.js +66 -0
  61. package/scripts/external/three-old/render/VREffect.js +482 -0
  62. package/scripts/external/three-old/shimthree.js +23 -0
  63. package/scripts/external/three-old/stats.js +6 -0
  64. package/scripts/external/three-old/three-88dev.js +45004 -0
  65. package/scripts/external/three-old/three-backgroundoptimization.js +44432 -0
  66. package/scripts/external/three-old/three-updates.js +44735 -0
  67. package/scripts/external/three-old/three-working.js +44719 -0
  68. package/scripts/external/three-old/three.js +44431 -0
  69. package/scripts/external/three-old/threex.rendererstats.js +66 -0
  70. package/scripts/external/three-old/tween.js +13 -0
  71. package/scripts/external/webvr-polyfill-new.js +3497 -0
  72. package/scripts/external/webvr-polyfill-newest.js +3491 -0
  73. package/scripts/external/webvr-polyfill-old.js +6337 -0
  74. package/scripts/geometries.js +2 -2
  75. package/scripts/math.js +6 -6
  76. package/scripts/systems/admin.js +1 -1
  77. package/scripts/systems/controls.js +6 -4
  78. package/scripts/systems/physics.js +10 -10
  79. package/scripts/systems/render.js +58 -20
  80. package/scripts/systems/render2.js +38 -0
  81. package/scripts/things/camera.js +6 -1
  82. package/scripts/things/generic-trackedvectors.js +1875 -0
  83. package/scripts/things/generic.js +3 -4
  84. package/scripts/things/label2d.js +1 -1
  85. package/scripts/things/leapmotion.js +6 -6
  86. package/scripts/things/menu.js +1 -1
  87. package/scripts/things/player-bak.js +638 -0
  88. package/scripts/things/player.js +28 -10
  89. package/scripts/things/skysphere.js +1 -1
  90. package/scripts/things/terrain.js +1 -1
  91. package/scripts/things/text.js +1 -1
@@ -0,0 +1,1494 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = global || self, factory(global.HoloPlay = {}));
5
+ }(this, (function (exports) { 'use strict';
6
+
7
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
+
9
+ function createCommonjsModule(fn, module) {
10
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
11
+ }
12
+
13
+ var cbor = createCommonjsModule(function (module) {
14
+ /*
15
+ * The MIT License (MIT)
16
+ *
17
+ * Copyright (c) 2014 Patrick Gansterer <paroga@paroga.com>
18
+ *
19
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
20
+ * of this software and associated documentation files (the "Software"), to deal
21
+ * in the Software without restriction, including without limitation the rights
22
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
+ * copies of the Software, and to permit persons to whom the Software is
24
+ * furnished to do so, subject to the following conditions:
25
+ *
26
+ * The above copyright notice and this permission notice shall be included in all
27
+ * copies or substantial portions of the Software.
28
+ *
29
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ * SOFTWARE.
36
+ */
37
+
38
+ (function(global, undefined$1) {var POW_2_24 = Math.pow(2, -24),
39
+ POW_2_32 = Math.pow(2, 32),
40
+ POW_2_53 = Math.pow(2, 53);
41
+
42
+ function encode(value) {
43
+ var data = new ArrayBuffer(256);
44
+ var dataView = new DataView(data);
45
+ var lastLength;
46
+ var offset = 0;
47
+
48
+ function ensureSpace(length) {
49
+ var newByteLength = data.byteLength;
50
+ var requiredLength = offset + length;
51
+ while (newByteLength < requiredLength)
52
+ newByteLength *= 2;
53
+ if (newByteLength !== data.byteLength) {
54
+ var oldDataView = dataView;
55
+ data = new ArrayBuffer(newByteLength);
56
+ dataView = new DataView(data);
57
+ var uint32count = (offset + 3) >> 2;
58
+ for (var i = 0; i < uint32count; ++i)
59
+ dataView.setUint32(i * 4, oldDataView.getUint32(i * 4));
60
+ }
61
+
62
+ lastLength = length;
63
+ return dataView;
64
+ }
65
+ function write() {
66
+ offset += lastLength;
67
+ }
68
+ function writeFloat64(value) {
69
+ write(ensureSpace(8).setFloat64(offset, value));
70
+ }
71
+ function writeUint8(value) {
72
+ write(ensureSpace(1).setUint8(offset, value));
73
+ }
74
+ function writeUint8Array(value) {
75
+ var dataView = ensureSpace(value.length);
76
+ for (var i = 0; i < value.length; ++i)
77
+ dataView.setUint8(offset + i, value[i]);
78
+ write();
79
+ }
80
+ function writeUint16(value) {
81
+ write(ensureSpace(2).setUint16(offset, value));
82
+ }
83
+ function writeUint32(value) {
84
+ write(ensureSpace(4).setUint32(offset, value));
85
+ }
86
+ function writeUint64(value) {
87
+ var low = value % POW_2_32;
88
+ var high = (value - low) / POW_2_32;
89
+ var dataView = ensureSpace(8);
90
+ dataView.setUint32(offset, high);
91
+ dataView.setUint32(offset + 4, low);
92
+ write();
93
+ }
94
+ function writeTypeAndLength(type, length) {
95
+ if (length < 24) {
96
+ writeUint8(type << 5 | length);
97
+ } else if (length < 0x100) {
98
+ writeUint8(type << 5 | 24);
99
+ writeUint8(length);
100
+ } else if (length < 0x10000) {
101
+ writeUint8(type << 5 | 25);
102
+ writeUint16(length);
103
+ } else if (length < 0x100000000) {
104
+ writeUint8(type << 5 | 26);
105
+ writeUint32(length);
106
+ } else {
107
+ writeUint8(type << 5 | 27);
108
+ writeUint64(length);
109
+ }
110
+ }
111
+
112
+ function encodeItem(value) {
113
+ var i;
114
+
115
+ if (value === false)
116
+ return writeUint8(0xf4);
117
+ if (value === true)
118
+ return writeUint8(0xf5);
119
+ if (value === null)
120
+ return writeUint8(0xf6);
121
+ if (value === undefined$1)
122
+ return writeUint8(0xf7);
123
+
124
+ switch (typeof value) {
125
+ case "number":
126
+ if (Math.floor(value) === value) {
127
+ if (0 <= value && value <= POW_2_53)
128
+ return writeTypeAndLength(0, value);
129
+ if (-POW_2_53 <= value && value < 0)
130
+ return writeTypeAndLength(1, -(value + 1));
131
+ }
132
+ writeUint8(0xfb);
133
+ return writeFloat64(value);
134
+
135
+ case "string":
136
+ var utf8data = [];
137
+ for (i = 0; i < value.length; ++i) {
138
+ var charCode = value.charCodeAt(i);
139
+ if (charCode < 0x80) {
140
+ utf8data.push(charCode);
141
+ } else if (charCode < 0x800) {
142
+ utf8data.push(0xc0 | charCode >> 6);
143
+ utf8data.push(0x80 | charCode & 0x3f);
144
+ } else if (charCode < 0xd800) {
145
+ utf8data.push(0xe0 | charCode >> 12);
146
+ utf8data.push(0x80 | (charCode >> 6) & 0x3f);
147
+ utf8data.push(0x80 | charCode & 0x3f);
148
+ } else {
149
+ charCode = (charCode & 0x3ff) << 10;
150
+ charCode |= value.charCodeAt(++i) & 0x3ff;
151
+ charCode += 0x10000;
152
+
153
+ utf8data.push(0xf0 | charCode >> 18);
154
+ utf8data.push(0x80 | (charCode >> 12) & 0x3f);
155
+ utf8data.push(0x80 | (charCode >> 6) & 0x3f);
156
+ utf8data.push(0x80 | charCode & 0x3f);
157
+ }
158
+ }
159
+
160
+ writeTypeAndLength(3, utf8data.length);
161
+ return writeUint8Array(utf8data);
162
+
163
+ default:
164
+ var length;
165
+ if (Array.isArray(value)) {
166
+ length = value.length;
167
+ writeTypeAndLength(4, length);
168
+ for (i = 0; i < length; ++i)
169
+ encodeItem(value[i]);
170
+ } else if (value instanceof Uint8Array) {
171
+ writeTypeAndLength(2, value.length);
172
+ writeUint8Array(value);
173
+ } else {
174
+ var keys = Object.keys(value);
175
+ length = keys.length;
176
+ writeTypeAndLength(5, length);
177
+ for (i = 0; i < length; ++i) {
178
+ var key = keys[i];
179
+ encodeItem(key);
180
+ encodeItem(value[key]);
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ encodeItem(value);
187
+
188
+ if ("slice" in data)
189
+ return data.slice(0, offset);
190
+
191
+ var ret = new ArrayBuffer(offset);
192
+ var retView = new DataView(ret);
193
+ for (var i = 0; i < offset; ++i)
194
+ retView.setUint8(i, dataView.getUint8(i));
195
+ return ret;
196
+ }
197
+
198
+ function decode(data, tagger, simpleValue) {
199
+ var dataView = new DataView(data);
200
+ var offset = 0;
201
+
202
+ if (typeof tagger !== "function")
203
+ tagger = function(value) { return value; };
204
+ if (typeof simpleValue !== "function")
205
+ simpleValue = function() { return undefined$1; };
206
+
207
+ function read(value, length) {
208
+ offset += length;
209
+ return value;
210
+ }
211
+ function readArrayBuffer(length) {
212
+ return read(new Uint8Array(data, offset, length), length);
213
+ }
214
+ function readFloat16() {
215
+ var tempArrayBuffer = new ArrayBuffer(4);
216
+ var tempDataView = new DataView(tempArrayBuffer);
217
+ var value = readUint16();
218
+
219
+ var sign = value & 0x8000;
220
+ var exponent = value & 0x7c00;
221
+ var fraction = value & 0x03ff;
222
+
223
+ if (exponent === 0x7c00)
224
+ exponent = 0xff << 10;
225
+ else if (exponent !== 0)
226
+ exponent += (127 - 15) << 10;
227
+ else if (fraction !== 0)
228
+ return fraction * POW_2_24;
229
+
230
+ tempDataView.setUint32(0, sign << 16 | exponent << 13 | fraction << 13);
231
+ return tempDataView.getFloat32(0);
232
+ }
233
+ function readFloat32() {
234
+ return read(dataView.getFloat32(offset), 4);
235
+ }
236
+ function readFloat64() {
237
+ return read(dataView.getFloat64(offset), 8);
238
+ }
239
+ function readUint8() {
240
+ return read(dataView.getUint8(offset), 1);
241
+ }
242
+ function readUint16() {
243
+ return read(dataView.getUint16(offset), 2);
244
+ }
245
+ function readUint32() {
246
+ return read(dataView.getUint32(offset), 4);
247
+ }
248
+ function readUint64() {
249
+ return readUint32() * POW_2_32 + readUint32();
250
+ }
251
+ function readBreak() {
252
+ if (dataView.getUint8(offset) !== 0xff)
253
+ return false;
254
+ offset += 1;
255
+ return true;
256
+ }
257
+ function readLength(additionalInformation) {
258
+ if (additionalInformation < 24)
259
+ return additionalInformation;
260
+ if (additionalInformation === 24)
261
+ return readUint8();
262
+ if (additionalInformation === 25)
263
+ return readUint16();
264
+ if (additionalInformation === 26)
265
+ return readUint32();
266
+ if (additionalInformation === 27)
267
+ return readUint64();
268
+ if (additionalInformation === 31)
269
+ return -1;
270
+ throw "Invalid length encoding";
271
+ }
272
+ function readIndefiniteStringLength(majorType) {
273
+ var initialByte = readUint8();
274
+ if (initialByte === 0xff)
275
+ return -1;
276
+ var length = readLength(initialByte & 0x1f);
277
+ if (length < 0 || (initialByte >> 5) !== majorType)
278
+ throw "Invalid indefinite length element";
279
+ return length;
280
+ }
281
+
282
+ function appendUtf16data(utf16data, length) {
283
+ for (var i = 0; i < length; ++i) {
284
+ var value = readUint8();
285
+ if (value & 0x80) {
286
+ if (value < 0xe0) {
287
+ value = (value & 0x1f) << 6
288
+ | (readUint8() & 0x3f);
289
+ length -= 1;
290
+ } else if (value < 0xf0) {
291
+ value = (value & 0x0f) << 12
292
+ | (readUint8() & 0x3f) << 6
293
+ | (readUint8() & 0x3f);
294
+ length -= 2;
295
+ } else {
296
+ value = (value & 0x0f) << 18
297
+ | (readUint8() & 0x3f) << 12
298
+ | (readUint8() & 0x3f) << 6
299
+ | (readUint8() & 0x3f);
300
+ length -= 3;
301
+ }
302
+ }
303
+
304
+ if (value < 0x10000) {
305
+ utf16data.push(value);
306
+ } else {
307
+ value -= 0x10000;
308
+ utf16data.push(0xd800 | (value >> 10));
309
+ utf16data.push(0xdc00 | (value & 0x3ff));
310
+ }
311
+ }
312
+ }
313
+
314
+ function decodeItem() {
315
+ var initialByte = readUint8();
316
+ var majorType = initialByte >> 5;
317
+ var additionalInformation = initialByte & 0x1f;
318
+ var i;
319
+ var length;
320
+
321
+ if (majorType === 7) {
322
+ switch (additionalInformation) {
323
+ case 25:
324
+ return readFloat16();
325
+ case 26:
326
+ return readFloat32();
327
+ case 27:
328
+ return readFloat64();
329
+ }
330
+ }
331
+
332
+ length = readLength(additionalInformation);
333
+ if (length < 0 && (majorType < 2 || 6 < majorType))
334
+ throw "Invalid length";
335
+
336
+ switch (majorType) {
337
+ case 0:
338
+ return length;
339
+ case 1:
340
+ return -1 - length;
341
+ case 2:
342
+ if (length < 0) {
343
+ var elements = [];
344
+ var fullArrayLength = 0;
345
+ while ((length = readIndefiniteStringLength(majorType)) >= 0) {
346
+ fullArrayLength += length;
347
+ elements.push(readArrayBuffer(length));
348
+ }
349
+ var fullArray = new Uint8Array(fullArrayLength);
350
+ var fullArrayOffset = 0;
351
+ for (i = 0; i < elements.length; ++i) {
352
+ fullArray.set(elements[i], fullArrayOffset);
353
+ fullArrayOffset += elements[i].length;
354
+ }
355
+ return fullArray;
356
+ }
357
+ return readArrayBuffer(length);
358
+ case 3:
359
+ var utf16data = [];
360
+ if (length < 0) {
361
+ while ((length = readIndefiniteStringLength(majorType)) >= 0)
362
+ appendUtf16data(utf16data, length);
363
+ } else
364
+ appendUtf16data(utf16data, length);
365
+ return String.fromCharCode.apply(null, utf16data);
366
+ case 4:
367
+ var retArray;
368
+ if (length < 0) {
369
+ retArray = [];
370
+ while (!readBreak())
371
+ retArray.push(decodeItem());
372
+ } else {
373
+ retArray = new Array(length);
374
+ for (i = 0; i < length; ++i)
375
+ retArray[i] = decodeItem();
376
+ }
377
+ return retArray;
378
+ case 5:
379
+ var retObject = {};
380
+ for (i = 0; i < length || length < 0 && !readBreak(); ++i) {
381
+ var key = decodeItem();
382
+ retObject[key] = decodeItem();
383
+ }
384
+ return retObject;
385
+ case 6:
386
+ return tagger(decodeItem(), length);
387
+ case 7:
388
+ switch (length) {
389
+ case 20:
390
+ return false;
391
+ case 21:
392
+ return true;
393
+ case 22:
394
+ return null;
395
+ case 23:
396
+ return undefined$1;
397
+ default:
398
+ return simpleValue(length);
399
+ }
400
+ }
401
+ }
402
+
403
+ var ret = decodeItem();
404
+ if (offset !== data.byteLength)
405
+ throw "Remaining bytes";
406
+ return ret;
407
+ }
408
+
409
+ var obj = { encode: encode, decode: decode };
410
+
411
+ if (typeof undefined$1 === "function" && undefined$1.amd)
412
+ undefined$1("cbor/cbor", obj);
413
+ else if ( module.exports)
414
+ module.exports = obj;
415
+ else if (!global.CBOR)
416
+ global.CBOR = obj;
417
+
418
+ })(commonjsGlobal);
419
+ });
420
+
421
+ /**
422
+ * This files defines the HoloPlayClient class and Message class.
423
+ *
424
+ * Copyright (c) [2019] [Looking Glass Factory]
425
+ *
426
+ * @link https://lookingglassfactory.com/
427
+ * @file This files defines the HoloPlayClient class and Message class.
428
+ * @author Looking Glass Factory.
429
+ * @version 0.0.8
430
+ * @license SEE LICENSE IN LICENSE.md
431
+ */
432
+
433
+ // Polyfill WebSocket for nodejs applications.
434
+ const WebSocket =
435
+ typeof window === 'undefined' ? require('ws') : window.WebSocket;
436
+
437
+ /** Class representing a client to communicates with the HoloPlayService. */
438
+ class Client {
439
+ /**
440
+ * Establish a client to talk to HoloPlayService.
441
+ * @constructor
442
+ * @param {function} initCallback - optional; a function to trigger when
443
+ * response is received
444
+ * @param {function} errCallback - optional; a function to trigger when there
445
+ * is a connection error
446
+ * @param {function} closeCallback - optional; a function to trigger when the
447
+ * socket is closed
448
+ * @param {boolean} debug - optional; default is false
449
+ * @param {string} appId - optional
450
+ * @param {boolean} isGreedy - optional
451
+ * @param {string} oncloseBehavior - optional, can be 'wipe', 'hide', 'none'
452
+ */
453
+ constructor(
454
+ initCallback, errCallback, closeCallback, debug = false, appId, isGreedy,
455
+ oncloseBehavior) {
456
+ this.reqs = [];
457
+ this.reps = [];
458
+ this.requestId = this.getRequestId();
459
+ this.debug = debug;
460
+ this.isGreedy = isGreedy;
461
+ this.errCallback = errCallback;
462
+ this.closeCallback = closeCallback;
463
+ this.alwaysdebug = false;
464
+ this.isConnected = false;
465
+ let initCmd = null;
466
+ if (appId || isGreedy || oncloseBehavior) {
467
+ initCmd = new InitMessage(appId, isGreedy, oncloseBehavior, this.debug);
468
+ } else {
469
+ if (debug) this.alwaysdebug = true;
470
+ if (typeof initCallback == 'function') initCmd = new InfoMessage();
471
+ }
472
+ this.openWebsocket(initCmd, initCallback);
473
+ }
474
+ /**
475
+ * Send a message over the websocket to HoloPlayService.
476
+ * @public
477
+ * @param {Message} msg - message object
478
+ * @param {integer} timeoutSecs - optional, default is 60 seconds
479
+ */
480
+ sendMessage(msg, timeoutSecs = 60) {
481
+ if (this.alwaysdebug) msg.cmd.debug = true;
482
+ let cborData = msg.toCbor();
483
+ return this.sendRequestObj(cborData, timeoutSecs);
484
+ }
485
+ /**
486
+ * Disconnects from the web socket.
487
+ * @public
488
+ */
489
+ disconnect() {
490
+ this.ws.close();
491
+ }
492
+ /**
493
+ * Open a websocket and set handlers
494
+ * @private
495
+ */
496
+ openWebsocket(firstCmd = null, initCallback = null) {
497
+ this.ws =
498
+ new WebSocket('ws://localhost:11222/driver', ['rep.sp.nanomsg.org']);
499
+ this.ws.parent = this;
500
+ this.ws.binaryType = 'arraybuffer';
501
+ this.ws.onmessage = this.messageHandler;
502
+ this.ws.onopen = (() => {
503
+ this.isConnected = true;
504
+ if (this.debug) {
505
+ console.log('socket open');
506
+ }
507
+ if (firstCmd != null) {
508
+ this.sendMessage(firstCmd).then(initCallback);
509
+ }
510
+ });
511
+ this.ws.onerror = this.onSocketError;
512
+ this.ws.onclose = this.onClose;
513
+ }
514
+ /**
515
+ * Send a request object over websocket
516
+ * @private
517
+ */
518
+ sendRequestObj(data, timeoutSecs) {
519
+ return new Promise((resolve, reject) => {
520
+ let reqObj = {
521
+ id: this.requestId++,
522
+ parent: this,
523
+ payload: data,
524
+ success: resolve,
525
+ error: reject,
526
+ send: function() {
527
+ if (this.debug)
528
+ console.log('attemtping to send request with ID ' + this.id);
529
+ this.timeout = setTimeout(reqObj.send.bind(this), timeoutSecs * 1000);
530
+ let tmp = new Uint8Array(data.byteLength + 4);
531
+ let view = new DataView(tmp.buffer);
532
+ view.setUint32(0, this.id);
533
+ tmp.set(new Uint8Array(this.payload), 4);
534
+ this.parent.ws.send(tmp.buffer);
535
+ }
536
+ };
537
+ this.reqs.push(reqObj);
538
+ reqObj.send();
539
+ });
540
+ }
541
+ /**
542
+ * Handles a message when received
543
+ * @private
544
+ */
545
+ messageHandler(event) {
546
+ console.log('message');
547
+ let data = event.data;
548
+ if (data.byteLength < 4) return;
549
+ let view = new DataView(data);
550
+ let replyId = view.getUint32(0);
551
+ if (replyId < 0x80000000) {
552
+ this.parent.err('bad nng header');
553
+ return;
554
+ }
555
+ let i = this.parent.findReqIndex(replyId);
556
+ if (i == -1) {
557
+ this.parent.err('got reply that doesn\'t match known request!');
558
+ return;
559
+ }
560
+ let rep = {id: replyId, payload: cbor.decode(data.slice(4))};
561
+ if (rep.payload.error == 0) {
562
+ this.parent.reqs[i].success(rep.payload);
563
+ } else {
564
+ this.parent.reqs[i].error(rep.payload);
565
+ }
566
+ clearTimeout(this.parent.reqs[i].timeout);
567
+ this.parent.reqs.splice(i, 1);
568
+ this.parent.reps.push(rep);
569
+ if (this.debug) {
570
+ console.log(rep.payload);
571
+ }
572
+ }
573
+ getRequestId() {
574
+ return Math.floor(this.prng() * (0x7fffffff)) + 0x80000000;
575
+ }
576
+ onClose(event) {
577
+ this.parent.isConnected = false;
578
+ if (this.parent.debug) {
579
+ console.log('socket closed');
580
+ }
581
+ if (typeof this.parent.closeCallback == 'function')
582
+ this.parent.closeCallback(event);
583
+ }
584
+ onSocketError(error) {
585
+ if (this.parent.debug) {
586
+ console.log(error);
587
+ }
588
+ if (typeof this.parent.errCallback == 'function') {
589
+ this.parent.errCallback(error);
590
+ }
591
+ }
592
+ err(errorMsg) {
593
+ if (this.debug) {
594
+ console.log('[DRIVER ERROR]' + errorMsg);
595
+ }
596
+ // TODO : make this return an event obj rather than a string
597
+ // if (typeof this.errCallback == 'function')
598
+ // this.errCallback(errorMsg);
599
+ }
600
+ findReqIndex(replyId) {
601
+ let i = 0;
602
+ for (; i < this.reqs.length; i++) {
603
+ if (this.reqs[i].id == replyId) {
604
+ return i;
605
+ }
606
+ }
607
+ return -1;
608
+ }
609
+ prng() {
610
+ if (this.rng == undefined) {
611
+ this.rng = generateRng();
612
+ }
613
+ return this.rng();
614
+ }
615
+ }
616
+
617
+ /** A class to represent messages being sent over to HoloPlay Service */
618
+ class Message {
619
+ /**
620
+ * Construct a barebone message.
621
+ * @constructor
622
+ */
623
+ constructor(cmd, bin) {
624
+ this.cmd = cmd;
625
+ this.bin = bin;
626
+ }
627
+ /**
628
+ * Convert the class instance to the CBOR format
629
+ * @public
630
+ * @returns {CBOR} - cbor object of the message
631
+ */
632
+ toCbor() {
633
+ return cbor.encode(this);
634
+ }
635
+ }
636
+ /** Message to init. Extends the base Message class. */
637
+ class InitMessage extends Message {
638
+ /**
639
+ * @constructor
640
+ * @param {string} appId - a unique id for app
641
+ * @param {boolean} isGreedy - will it take over screen
642
+ * @param {string} oncloseBehavior - can be 'wipe', 'hide', 'none'
643
+ */
644
+ constructor(appId = '', isGreedy = false, onclose = '', debug = false) {
645
+ let cmd = {'init': {}};
646
+ if (appId != '') cmd['init'].appid = appId;
647
+ if (onclose != '') cmd['init'].onclose = onclose;
648
+ if (isGreedy) cmd['init'].greedy = true;
649
+ if (debug) cmd['init'].debug = true;
650
+ super(cmd, null);
651
+ }
652
+ }
653
+ /** Get info from the HoloPlayService */
654
+ class InfoMessage extends Message {
655
+ /**
656
+ * @constructor
657
+ */
658
+ constructor() {
659
+ let cmd = {'info': {}};
660
+ super(cmd, null);
661
+ }
662
+ }
663
+ /* helper function */
664
+ function generateRng() {
665
+ function xmur3(str) {
666
+ for (var i = 0, h = 1779033703 ^ str.length; i < str.length; i++)
667
+ h = Math.imul(h ^ str.charCodeAt(i), 3432918353), h = h << 13 | h >>> 19;
668
+ return function() {
669
+ h = Math.imul(h ^ h >>> 16, 2246822507);
670
+ h = Math.imul(h ^ h >>> 13, 3266489909);
671
+ return (h ^= h >>> 16) >>> 0;
672
+ }
673
+ }
674
+ function xoshiro128ss(a, b, c, d) {
675
+ return (() => {
676
+ var t = b << 9, r = a * 5;
677
+ r = (r << 7 | r >>> 25) * 9;
678
+ c ^= a;
679
+ d ^= b;
680
+ b ^= c;
681
+ a ^= d;
682
+ c ^= t;
683
+ d = d << 11 | d >>> 21;
684
+ return (r >>> 0) / 4294967296;
685
+ })
686
+ } var state = Date.now();
687
+ var seed = xmur3(state.toString());
688
+ return xoshiro128ss(seed(), seed(), seed(), seed());
689
+ }
690
+
691
+ const DEFAULT_CALIBRATION = {
692
+ 'configVersion': '1.0',
693
+ 'serial': '00000',
694
+ 'pitch': {'value': 47.556365966796878},
695
+ 'slope': {'value': -5.488804340362549},
696
+ 'center': {'value': 0.15815216302871705},
697
+ 'viewCone': {'value': 40.0},
698
+ 'invView': {'value': 1.0},
699
+ 'verticalAngle': {'value': 0.0},
700
+ 'DPI': {'value': 338.0},
701
+ 'screenW': {'value': 2560.0},
702
+ 'screenH': {'value': 1600.0},
703
+ 'flipImageX': {'value': 0.0},
704
+ 'flipImageY': {'value': 0.0},
705
+ 'flipSubp': {'value': 0.0}
706
+ };
707
+
708
+ function checkDriverInstall() {
709
+ if (confirm(
710
+ 'HoloPlayService not detected! Click OK to download. If you have it already installed, please make sure it is running.')) {
711
+ window.location.href = 'http://look.glass/holoplayservice';
712
+ }
713
+ }
714
+
715
+ let cachedPromise = null;
716
+
717
+ function getDevices() {
718
+ if (!cachedPromise) {
719
+ cachedPromise = new Promise((resolve, reject) => {
720
+ new Client(
721
+ (data) => {
722
+ if (data.devices.length == 0) {
723
+ alert(
724
+ 'No Looking Glass detected. Please make sure your Looking Glass is plugged in.');
725
+ }
726
+ resolve(data.devices);
727
+ },
728
+ (err) => {
729
+ console.error('error loading calibration', err);
730
+ checkDriverInstall();
731
+ reject(err);
732
+ },
733
+ console.log);
734
+ });
735
+ }
736
+ return cachedPromise;
737
+ }
738
+
739
+ function getFirstDevice() {
740
+ return getDevices().then((devices) => {
741
+ if (devices.length == 0) {
742
+ throw new Error('no devices');
743
+ }
744
+ return devices[0];
745
+ });
746
+ }
747
+
748
+ function getCalibration() {
749
+ return getFirstDevice()
750
+ .then((d) => {
751
+ return d.calibration;
752
+ })
753
+ .catch((err) => {
754
+ console.error('no devices connected. using default calibration.');
755
+ return DEFAULT_CALIBRATION;
756
+ });
757
+ }
758
+
759
+ const IDEAL_PROPERTIES = {
760
+ 'standard': {
761
+ 'quiltResolution': 4096,
762
+ 'tileCount': new THREE.Vector2(5, 9),
763
+ 'viewCone': 35,
764
+ 'fov': 12.5,
765
+ },
766
+ 'large': {
767
+ 'quiltResolution': 4096,
768
+ 'tileCount': new THREE.Vector2(5, 9),
769
+ 'viewCone': 35,
770
+ 'fov': 12.5,
771
+ },
772
+ 'pro': {
773
+ 'quiltResolution': 4096,
774
+ 'tileCount': new THREE.Vector2(5, 9),
775
+ 'viewCone': 35,
776
+ 'fov': 12.5,
777
+ },
778
+ '8k': {
779
+ 'quiltResolution': 8192,
780
+ 'tileCount': new THREE.Vector2(5, 9),
781
+ 'viewCone': 35,
782
+ 'fov': 12.5,
783
+ },
784
+ 'default': {
785
+ 'quiltResolution': 3360,
786
+ 'tileCount': new THREE.Vector2(8, 6),
787
+ 'viewCone': 35,
788
+ 'fov': 35,
789
+ },
790
+ };
791
+
792
+ function getIdealProperty(propName) {
793
+ return getFirstDevice()
794
+ .then((d) => {
795
+ return IDEAL_PROPERTIES[d.hardwareVersion][propName];
796
+ })
797
+ .catch((err) => {
798
+ return IDEAL_PROPERTIES['default'][propName];
799
+ });
800
+ }
801
+
802
+ function getIdealQuiltResolution() {
803
+ return getIdealProperty('quiltResolution');
804
+ }
805
+
806
+ function getIdealQuiltTileCount() {
807
+ return getIdealProperty('tileCount');
808
+ }
809
+
810
+ function getIdealViewCone() {
811
+ return getIdealProperty('viewCone');
812
+ }
813
+
814
+ function getIdealFov() {
815
+ return getIdealProperty('fov');
816
+ }
817
+
818
+ var calibration = /*#__PURE__*/Object.freeze({
819
+ __proto__: null,
820
+ DEFAULT_CALIBRATION: DEFAULT_CALIBRATION,
821
+ getFirstDevice: getFirstDevice,
822
+ getCalibration: getCalibration,
823
+ getIdealQuiltResolution: getIdealQuiltResolution,
824
+ getIdealQuiltTileCount: getIdealQuiltTileCount,
825
+ getIdealViewCone: getIdealViewCone,
826
+ getIdealFov: getIdealFov
827
+ });
828
+
829
+ const QUILT_VERTEX_SHADER = `
830
+ varying vec2 iUv;
831
+
832
+ void main() {
833
+ iUv = uv;
834
+ vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);
835
+ gl_Position = projectionMatrix * modelViewPosition;
836
+ }
837
+ `;
838
+
839
+ const QUILT_FRAGMENT_SHADER = `
840
+ uniform sampler2D quiltTexture;
841
+ uniform float pitch;
842
+ uniform float tilt;
843
+ uniform float center;
844
+ uniform float invView;
845
+ uniform float flipX;
846
+ uniform float flipY;
847
+ uniform float subp;
848
+ uniform float tilesX;
849
+ uniform float tilesY;
850
+ uniform vec2 quiltViewPortion;
851
+ varying vec2 iUv;
852
+
853
+ vec2 texArr(vec3 uvz) {
854
+ float z = floor(uvz.z * tilesX * tilesY);
855
+ float x = (mod(z, tilesX) + uvz.x) / tilesX;
856
+ float y = (floor(z / tilesX) + uvz.y) / tilesY;
857
+ return vec2(x, y) * quiltViewPortion;
858
+ }
859
+
860
+ float remap(float value, float from1, float to1, float from2, float to2) {
861
+ return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
862
+ }
863
+
864
+ void main() {
865
+ vec4 rgb[3];
866
+ vec3 nuv = vec3(iUv.xy, 0.0);
867
+
868
+ // Flip UVs if necessary
869
+ nuv.x = (1.0 - flipX) * nuv.x + flipX * (1.0 - nuv.x);
870
+ nuv.y = (1.0 - flipY) * nuv.y + flipY * (1.0 - nuv.y);
871
+
872
+ for (int i = 0; i < 3; i++) {
873
+ nuv.z = (iUv.x + float(i) * subp + iUv.y * tilt) * pitch - center;
874
+ nuv.z = mod(nuv.z + ceil(abs(nuv.z)), 1.0);
875
+ nuv.z = (1.0 - invView) * nuv.z + invView * (1.0 - nuv.z);
876
+ rgb[i] = texture2D(quiltTexture, texArr(vec3(iUv.x, iUv.y, nuv.z)));
877
+ }
878
+
879
+ gl_FragColor = vec4(rgb[0].r, rgb[1].g, rgb[2].b, 1);
880
+ }
881
+ `;
882
+
883
+ const QUILT_SHADER_PROPERTIES = {
884
+ uniforms: {
885
+ quiltTexture: {value: null},
886
+ pitch: {value: 0},
887
+ tilt: {value: 0},
888
+ center: {value: 0},
889
+ invView: {value: 0},
890
+ flipX: {value: 0},
891
+ flipY: {value: 0},
892
+ subp: {value: 0},
893
+ tilesX: {value: 0},
894
+ tilesY: {value: 0},
895
+ screenW: {value: 0},
896
+ screenH: {value: 0},
897
+ quiltViewPortion: {value: new THREE.Vector2(1, 1)},
898
+ },
899
+ vertexShader: QUILT_VERTEX_SHADER,
900
+ fragmentShader: QUILT_FRAGMENT_SHADER,
901
+ };
902
+
903
+ class QuiltRenderer {
904
+ constructor(tileCount, opt_renderer) {
905
+ getCalibration().then((calibration) => {
906
+ this.calibrationData = calibration;
907
+ this.updateCalibration();
908
+ });
909
+
910
+ this.tileCount = tileCount;
911
+
912
+ this.scene = new THREE.Scene();
913
+
914
+ const quiltPlaneGeometry = new THREE.PlaneGeometry(1, 1);
915
+ const quiltPlaneMaterial =
916
+ new THREE.ShaderMaterial(QUILT_SHADER_PROPERTIES);
917
+ this.quiltPlane = new THREE.Mesh(quiltPlaneGeometry, quiltPlaneMaterial);
918
+ this.scene.add(this.quiltPlane);
919
+
920
+ this.camera = new THREE.OrthographicCamera(-0.5, 0.5, 0.5, -0.5, 0);
921
+ this.renderer = opt_renderer || new THREE.WebGLRenderer();
922
+
923
+ this.renderSize = new THREE.Vector2(window.innerWidth, window.innerHeight);
924
+
925
+ this.domElement = this.renderer.domElement;
926
+ this.domElement.style.position = 'absolute';
927
+ }
928
+
929
+ render() {
930
+ this.renderer.setSize(this.renderSize.x, this.renderSize.y);
931
+ this.negateWindowZoomAndOffset();
932
+ this.renderer.render(this.scene, this.camera);
933
+ }
934
+
935
+ update(quiltResolution, tileCount) {
936
+ this.tileCount.copy(tileCount);
937
+ this.quiltPlane.material.uniforms.tilesX.value = this.tileCount.x;
938
+ this.quiltPlane.material.uniforms.tilesY.value = this.tileCount.y;
939
+
940
+ this.quiltPlane.material.uniforms.quiltViewPortion.value.set(
941
+ (Math.floor(quiltResolution / this.tileCount.x) * this.tileCount.x) /
942
+ quiltResolution,
943
+ (Math.floor(quiltResolution / this.tileCount.y) * this.tileCount.y) /
944
+ quiltResolution);
945
+ }
946
+
947
+ negateWindowZoomAndOffset() {
948
+ const windowZoom =
949
+ window.outerWidth / document.body.getBoundingClientRect().width;
950
+ const browserToolbarHeight = window.outerHeight - window.innerHeight;
951
+ this.domElement.style.width = `${this.domElement.width / windowZoom}px`;
952
+ this.domElement.style.height = `${this.domElement.height / windowZoom}px`;
953
+ this.domElement.style.left =
954
+ `${(window.screen.availLeft - window.screenLeft) / windowZoom}px`;
955
+ this.domElement.style.top =
956
+ `${- (window.screenTop + browserToolbarHeight) / windowZoom}px`;
957
+ }
958
+
959
+ setQuiltImageURL(url) {
960
+ const quiltImage = new Image();
961
+ quiltImage.src = url;
962
+ this.setQuiltImage(quiltImage);
963
+ }
964
+
965
+ setQuiltImage(quiltImage) {
966
+ const imageTexture = new THREE.Texture();
967
+ imageTexture.image = quiltImage;
968
+ imageTexture.minFilter = THREE.NearestFilter;
969
+ imageTexture.magFilter = THREE.NearestFilter;
970
+
971
+ this.setQuiltTexture(imageTexture);
972
+
973
+ // Update the texture when the image loads.
974
+ quiltImage.addEventListener('load', () => {
975
+ imageTexture.needsUpdate = true;
976
+ this.render();
977
+ });
978
+
979
+ if (quiltImage.complete) {
980
+ // Force a load event for an already downloaded file.
981
+ quiltImage.load();
982
+ }
983
+ }
984
+
985
+ setQuiltTexture(quiltTexture) {
986
+ this.quiltPlane.material.uniforms.quiltTexture.value = quiltTexture;
987
+ }
988
+
989
+ updateCalibration() {
990
+ if (!this.calibrationData) {
991
+ return;
992
+ }
993
+
994
+ this.renderSize.set(
995
+ this.calibrationData.screenW.value, this.calibrationData.screenH.value);
996
+
997
+ const quiltMaterial = this.quiltPlane.material;
998
+
999
+ const screenInches =
1000
+ this.calibrationData.screenW.value / this.calibrationData.DPI.value;
1001
+ let newPitch = this.calibrationData.pitch.value * screenInches;
1002
+
1003
+ // account for tilt in measuring pitch horizontally
1004
+ newPitch *= Math.cos(Math.atan(1.0 / this.calibrationData.slope.value));
1005
+ quiltMaterial.uniforms.pitch.value = newPitch;
1006
+
1007
+ // tilt
1008
+ let newTilt = this.calibrationData.screenH.value /
1009
+ (this.calibrationData.screenW.value * this.calibrationData.slope.value);
1010
+ if (this.calibrationData.flipImageX.value == 1) {
1011
+ newTilt *= -1;
1012
+ }
1013
+ quiltMaterial.uniforms.tilt.value = newTilt;
1014
+
1015
+ // center
1016
+ // I need the relationship between the amount of pixels I have moved over to
1017
+ // the amount of lenticulars I have jumped
1018
+ // ie how many pixels are there to a lenticular?
1019
+ quiltMaterial.uniforms.center.value = this.calibrationData.center.value;
1020
+
1021
+ // should we invert?
1022
+ quiltMaterial.uniforms.invView.value = this.calibrationData.invView.value;
1023
+
1024
+ // Should we flip it for peppers?
1025
+ quiltMaterial.uniforms.flipX.value = this.calibrationData.flipImageX.value;
1026
+ quiltMaterial.uniforms.flipY.value = this.calibrationData.flipImageY.value;
1027
+
1028
+ quiltMaterial.uniforms.subp.value =
1029
+ 1 / (this.calibrationData.screenW.value * 3);
1030
+
1031
+ // tiles
1032
+ quiltMaterial.uniforms.tilesX.value = this.tileCount.x;
1033
+ quiltMaterial.uniforms.tilesY.value = this.tileCount.y;
1034
+ };
1035
+ }
1036
+
1037
+ /*! (c) Andrea Giammarchi - ISC */
1038
+ var self$1 = undefined || /* istanbul ignore next */ {};
1039
+ try {
1040
+ self$1.EventTarget = (new EventTarget).constructor;
1041
+ } catch(EventTarget) {
1042
+ (function (Object, wm) {
1043
+ var create = Object.create;
1044
+ var defineProperty = Object.defineProperty;
1045
+ var proto = EventTarget.prototype;
1046
+ define(proto, 'addEventListener', function (type, listener, options) {
1047
+ for (var
1048
+ secret = wm.get(this),
1049
+ listeners = secret[type] || (secret[type] = []),
1050
+ i = 0, length = listeners.length; i < length; i++
1051
+ ) {
1052
+ if (listeners[i].listener === listener)
1053
+ return;
1054
+ }
1055
+ listeners.push({target: this, listener: listener, options: options});
1056
+ });
1057
+ define(proto, 'dispatchEvent', function (event) {
1058
+ var secret = wm.get(this);
1059
+ var listeners = secret[event.type];
1060
+ if (listeners) {
1061
+ define(event, 'target', this);
1062
+ define(event, 'currentTarget', this);
1063
+ listeners.slice(0).forEach(dispatch, event);
1064
+ delete event.currentTarget;
1065
+ delete event.target;
1066
+ }
1067
+ return true;
1068
+ });
1069
+ define(proto, 'removeEventListener', function (type, listener) {
1070
+ for (var
1071
+ secret = wm.get(this),
1072
+ listeners = secret[type] || (secret[type] = []),
1073
+ i = 0, length = listeners.length; i < length; i++
1074
+ ) {
1075
+ if (listeners[i].listener === listener) {
1076
+ listeners.splice(i, 1);
1077
+ return;
1078
+ }
1079
+ }
1080
+ });
1081
+ self$1.EventTarget = EventTarget;
1082
+ function EventTarget() { wm.set(this, create(null));
1083
+ }
1084
+ function define(target, name, value) {
1085
+ defineProperty(
1086
+ target,
1087
+ name,
1088
+ {
1089
+ configurable: true,
1090
+ writable: true,
1091
+ value: value
1092
+ }
1093
+ );
1094
+ }
1095
+ function dispatch(info) {
1096
+ var options = info.options;
1097
+ if (options && options.once)
1098
+ info.target.removeEventListener(this.type, info.listener);
1099
+ if (typeof info.listener === 'function')
1100
+ info.listener.call(info.target, this);
1101
+ else
1102
+ info.listener.handleEvent(this);
1103
+ }
1104
+ }(Object, new WeakMap));
1105
+ }
1106
+ var EventTarget$1 = self$1.EventTarget;
1107
+
1108
+ const BUTTON_NAMES = ['square', 'left', 'right', 'circle'];
1109
+
1110
+ class Buttons extends EventTarget$1 {
1111
+ constructor() {
1112
+ super();
1113
+
1114
+ this.lastButtonState = [];
1115
+ for (let i = 0; i < BUTTON_NAMES.length; i++) {
1116
+ this.lastButtonState.push(false);
1117
+ }
1118
+
1119
+ this.gamepadInfo = null;
1120
+
1121
+ window.addEventListener('gamepadconnected', (e) => {
1122
+ if (e.gamepad.id.indexOf('HoloPlay') > -1) {
1123
+ this.gamepadInfo = navigator.getGamepads()[e.gamepad.index];
1124
+ }
1125
+ });
1126
+
1127
+ window.addEventListener('gamepaddisconnected', (e) => {
1128
+ if (e.gamepad.id.indexOf('HoloPlay') > -1) {
1129
+ this.gamepadInfo = null;
1130
+ }
1131
+ });
1132
+
1133
+ requestAnimationFrame(this.update.bind(this));
1134
+ }
1135
+
1136
+ update() {
1137
+ requestAnimationFrame(this.update.bind(this));
1138
+
1139
+ if (this.gamepadInfo == null) {
1140
+ return;
1141
+ }
1142
+
1143
+ let holoplayGamepad;
1144
+ let allGamepads = navigator.getGamepads();
1145
+ for (let i = 0; i < allGamepads.length; i++) {
1146
+ if (allGamepads[i].index == this.gamepadInfo.index) {
1147
+ holoplayGamepad = allGamepads[i];
1148
+ break;
1149
+ }
1150
+ }
1151
+
1152
+ if (!holoplayGamepad) {
1153
+ return;
1154
+ }
1155
+
1156
+ for (let i = 0; i < holoplayGamepad.buttons.length; i++) {
1157
+ if (!this.lastButtonState[i] && holoplayGamepad.buttons[i].pressed) {
1158
+ this.dispatchButtonEvent('buttonDown', i);
1159
+ this.dispatchButtonEvent('buttonPressed', i);
1160
+ } else if (
1161
+ this.lastButtonState[i] && holoplayGamepad.buttons[i].pressed) {
1162
+ this.dispatchButtonEvent('buttonPressed', i);
1163
+ } else if (
1164
+ this.lastButtonState[i] && !holoplayGamepad.buttons[i].pressed) {
1165
+ this.dispatchButtonEvent('buttonUp', i);
1166
+ }
1167
+
1168
+ this.lastButtonState[i] = holoplayGamepad.buttons[i].pressed;
1169
+ }
1170
+ }
1171
+
1172
+ dispatchButtonEvent(type, buttonIndex) {
1173
+ this.dispatchEvent(new CustomEvent(type, {
1174
+ detail: {
1175
+ name: BUTTON_NAMES[buttonIndex],
1176
+ index: buttonIndex,
1177
+ }
1178
+ }));
1179
+ }
1180
+ }
1181
+
1182
+ class Camera extends THREE.ArrayCamera {
1183
+ constructor() {
1184
+ super();
1185
+
1186
+ this.tileCount = new THREE.Vector2();
1187
+ this.target = new THREE.Vector3(0, 0, 0);
1188
+ this.position.set(0, 0, 1);
1189
+
1190
+ // just some defaults. we'll get them from calibration in a sec.
1191
+ this.fov = 12.5;
1192
+ this.aspect = 2560 / 1600;
1193
+ this.viewCone = 35;
1194
+
1195
+ getIdealViewCone().then((viewCone) => {
1196
+ this.viewCone = viewCone;
1197
+ });
1198
+
1199
+ getIdealFov().then((fov) => {
1200
+ this.fov = fov;
1201
+ this.cameras.forEach((c) => {
1202
+ c.fov = this.fov;
1203
+ c.updateProjectionMatrix();
1204
+ });
1205
+ });
1206
+
1207
+ getCalibration().then((calibration) => {
1208
+ this.aspect = calibration.screenW.value / calibration.screenH.value;
1209
+ this.cameras.forEach((c) => {
1210
+ c.aspect = this.aspect;
1211
+ c.updateProjectionMatrix();
1212
+ });
1213
+ });
1214
+ }
1215
+
1216
+ update(quiltResolution, tileCount) {
1217
+ // rebuild camera array if the camera count changes
1218
+ if (this.tileCount.x != tileCount.x || this.tileCount.y != tileCount.y) {
1219
+ this.cameras = [];
1220
+ for (let i = 0; i < tileCount.x * tileCount.y; i++) {
1221
+ const subcamera = new THREE.PerspectiveCamera(this.fov, this.aspect);
1222
+ subcamera.viewport = new THREE.Vector4();
1223
+ this.cameras.push(subcamera);
1224
+ }
1225
+ this.tileCount.copy(tileCount);
1226
+ }
1227
+
1228
+ const tileSize = new THREE.Vector2(
1229
+ Math.floor(quiltResolution / tileCount.x),
1230
+ Math.floor(quiltResolution / tileCount.y));
1231
+
1232
+ for (let i = 0; i < this.cameras.length; i++) {
1233
+ const subcamera = this.cameras[i];
1234
+ subcamera.rotation.copy(this.rotation);
1235
+
1236
+ const tileGridPos =
1237
+ new THREE.Vector2(i % tileCount.x, Math.floor(i / tileCount.x));
1238
+ subcamera.viewport.set(
1239
+ tileGridPos.x * tileSize.x, tileGridPos.y * tileSize.y, tileSize.x,
1240
+ tileSize.y);
1241
+
1242
+ const distanceToTarget = this.position.distanceTo(this.target);
1243
+ const angleToThisCamera = THREE.Math.degToRad(THREE.Math.lerp(
1244
+ -this.viewCone / 2, this.viewCone / 2,
1245
+ i / (this.cameras.length - 1)));
1246
+ const offsetAlongBaseline =
1247
+ distanceToTarget * Math.tan(angleToThisCamera);
1248
+
1249
+ subcamera.position.copy(
1250
+ this.localToWorld(new THREE.Vector3(offsetAlongBaseline, 0, 0)));
1251
+ subcamera.updateMatrixWorld();
1252
+
1253
+ subcamera.projectionMatrix.elements[8] = -2 * offsetAlongBaseline /
1254
+ (2 * distanceToTarget *
1255
+ Math.tan(0.5 * THREE.Math.degToRad(subcamera.fov)) *
1256
+ subcamera.aspect);
1257
+ }
1258
+ }
1259
+
1260
+ lookAt(targetPosition) {
1261
+ super.lookAt(targetPosition);
1262
+ this.target.copy(targetPosition);
1263
+ }
1264
+ }
1265
+
1266
+ /*!
1267
+ * fullscreen-polyfill
1268
+ * 1.0.2 - 5/23/2018
1269
+ * https://github.com/nguyenj/fullscreen-polyfill#readme
1270
+ * (c) John Nguyen; MIT License
1271
+ */
1272
+ var FullscreenPolyfill=function(){var l=["fullscreen","fullscreenEnabled","fullscreenElement","fullscreenchange","fullscreenerror","exitFullscreen","requestFullscreen"],e=["webkitIsFullScreen","webkitFullscreenEnabled","webkitFullscreenElement","webkitfullscreenchange","webkitfullscreenerror","webkitExitFullscreen","webkitRequestFullscreen"],n=["mozFullScreen","mozFullScreenEnabled","mozFullScreenElement","mozfullscreenchange","mozfullscreenerror","mozCancelFullScreen","mozRequestFullScreen"],u=["","msFullscreenEnabled","msFullscreenElement","MSFullscreenChange","MSFullscreenError","msExitFullscreen","msRequestFullscreen"];document||(document={});var t,c=(t=[l[1],e[1],n[1],u[1]].find(function(e){return document[e]}),[l,e,n,u].find(function(e){return e.find(function(e){return e===t})})||[]);function r(e,n){document[l[0]]=document[c[0]]||!!document[c[2]]||!1,document[l[1]]=document[c[1]]||!1,document[l[2]]=document[c[2]]||null,document.dispatchEvent(new Event(e),n.target);}return document[l[1]]?{}:(document[l[0]]=document[c[0]]||!!document[c[2]]||!1,document[l[1]]=document[c[1]]||!1,document[l[2]]=document[c[2]]||null,document.addEventListener(c[3],r.bind(document,l[3]),!1),document.addEventListener(c[4],r.bind(document,l[4]),!1),document[l[5]]=function(){return document[c[5]]()},void(Element.prototype[l[6]]=function(){return this[c[6]].apply(this,arguments)}))}();
1273
+
1274
+ class FullscreenHelper {
1275
+ constructor(renderer) {
1276
+ this.renderer = renderer;
1277
+
1278
+ this.lkgDevice = null;
1279
+ getFirstDevice().then((d) => {
1280
+ this.lkgDevice = d;
1281
+
1282
+ const startOnLkg = this.isOnLkg();
1283
+ if (startOnLkg) {
1284
+ this.renderer.render2d = false;
1285
+ this.moveWarning.style.display = 'none';
1286
+ } else {
1287
+ this.renderer.render2d = true;
1288
+ this.moveWarning.style.display = '';
1289
+ }
1290
+
1291
+ requestAnimationFrame(this.update.bind(this));
1292
+ });
1293
+
1294
+ this.onLkg = null;
1295
+
1296
+ this.moveWarning = this.makeMoveWarning();
1297
+ document.body.appendChild(this.moveWarning);
1298
+
1299
+ this.fullscreenButton = this.makeFullscreenButton();
1300
+ document.body.appendChild(this.fullscreenButton);
1301
+ }
1302
+
1303
+ isOnLkg() {
1304
+ const sameResolution =
1305
+ window.screen.width == this.lkgDevice.calibration.screenW.value &&
1306
+ window.screen.height == this.lkgDevice.calibration.screenH.value;
1307
+ const sameScreenPos =
1308
+ window.screen.availLeft == this.lkgDevice.windowCoords[0];
1309
+ return sameResolution && sameScreenPos;
1310
+ }
1311
+
1312
+ update() {
1313
+ requestAnimationFrame(this.update.bind(this));
1314
+
1315
+ const nowOnLkg = this.isOnLkg();
1316
+ if (nowOnLkg && !this.onLkg) {
1317
+ // just moved to lkg
1318
+ this.renderer.render2d = false;
1319
+ this.moveWarning.style.display = 'none';
1320
+ } else if (!nowOnLkg && this.onLkg) {
1321
+ // just moved OFF lkg
1322
+ this.renderer.render2d = true;
1323
+ this.moveWarning.style.display = '';
1324
+ }
1325
+ this.onLkg = nowOnLkg;
1326
+
1327
+ if (this.onLkg && !document.fullscreen) {
1328
+ if (document.hasFocus()) {
1329
+ this.fullscreenButton.innerText = 'click to go fullscreen';
1330
+ } else {
1331
+ this.fullscreenButton.innerText = 'click to focus window';
1332
+ }
1333
+ this.fullscreenButton.style.display = '';
1334
+ } else {
1335
+ this.fullscreenButton.style.display = 'none';
1336
+ }
1337
+ }
1338
+
1339
+ makeMoveWarning() {
1340
+ const moveWarning = document.createElement('div');
1341
+ moveWarning.innerText = 'drag this window to the Looking Glass';
1342
+ moveWarning.style.cssText = `
1343
+ background: white;
1344
+ border-radius: 8px;
1345
+ bottom: 0px;
1346
+ display: none;
1347
+ font-family: sans-serif;
1348
+ font-size: 6em;
1349
+ left: 0px;
1350
+ margin: 16px;
1351
+ opacity: 0.5;
1352
+ padding: 8px;
1353
+ position: absolute;
1354
+ z-index: ${Number.MAX_SAFE_INTEGER};
1355
+ `;
1356
+ return moveWarning;
1357
+ }
1358
+
1359
+ makeFullscreenButton() {
1360
+ const fullscreenButton = document.createElement('div');
1361
+ fullscreenButton.innerText = 'go fullscreen';
1362
+ fullscreenButton.style.cssText = `
1363
+ background: white;
1364
+ border-radius: 8px;
1365
+ bottom: 0px;
1366
+ display: none;
1367
+ font-family: sans-serif;
1368
+ font-size: 6em;
1369
+ font-weight: bold;
1370
+ left: 0px;
1371
+ margin: 16px;
1372
+ opacity: 0.75;
1373
+ padding: 8px;
1374
+ pointer-events: none;
1375
+ position: absolute;
1376
+ z-index: ${Number.MAX_SAFE_INTEGER};
1377
+ `;
1378
+ window.addEventListener('click', () => {
1379
+ this.renderer.domElement.requestFullscreen();
1380
+ });
1381
+ return fullscreenButton;
1382
+ }
1383
+ }
1384
+
1385
+ class Renderer {
1386
+ constructor(opt_options) {
1387
+ this.enforceMandatoryDocumentStyle();
1388
+
1389
+ let options = opt_options || {};
1390
+
1391
+ this.quiltResolution = options.quiltResolution || 4096;
1392
+ this.tileCount = options.tileCount || new THREE.Vector2(5, 9);
1393
+
1394
+ this.render2d = options.render2d || false;
1395
+ this.renderQuilt = options.render2d || false;
1396
+
1397
+ this.fullscreenHelper = null;
1398
+ if (!options.disableFullscreenUi) {
1399
+ this.fullscreenHelper = new FullscreenHelper(this);
1400
+ }
1401
+
1402
+ this.webglRenderer = new THREE.WebGLRenderer();
1403
+
1404
+ this.domElement = this.webglRenderer.domElement;
1405
+
1406
+ this.quiltRenderTarget = new THREE.WebGLRenderTarget(
1407
+ this.quiltResolution, this.quiltResolution, {format: THREE.RGBFormat});
1408
+
1409
+ this.quiltRenderer = new QuiltRenderer(this.tileCount, this.webglRenderer);
1410
+ this.quiltRenderer.setQuiltTexture(this.quiltRenderTarget.texture);
1411
+
1412
+ if (!options.quiltResolution) {
1413
+ getIdealQuiltResolution().then((res) => {
1414
+ this.quiltResolution = res;
1415
+ });
1416
+ }
1417
+
1418
+ if (!options.tileCount) {
1419
+ getIdealQuiltTileCount().then((count) => {
1420
+ this.tileCount.copy(count);
1421
+ });
1422
+ }
1423
+
1424
+ this.debug2dCamera = new THREE.PerspectiveCamera();
1425
+ getIdealFov().then((fov) => {
1426
+ this.debug2dCamera.fov = fov;
1427
+ this.debug2dCamera.updateProjectionMatrix();
1428
+ });
1429
+ }
1430
+
1431
+ enforceMandatoryDocumentStyle() {
1432
+ document.body.style.margin = '0px';
1433
+ document.body.style.overflow = 'hidden';
1434
+ }
1435
+
1436
+ render(scene, camera) {
1437
+ this.enforceMandatoryDocumentStyle();
1438
+
1439
+ if (this.render2d) {
1440
+ this.debug2dCamera.position.copy(camera.position);
1441
+ this.debug2dCamera.rotation.copy(camera.rotation);
1442
+
1443
+ const aspect = window.innerWidth / window.innerHeight;
1444
+ if (aspect != this.debug2dCamera.aspect) {
1445
+ this.debug2dCamera.aspect = aspect;
1446
+ this.debug2dCamera.updateProjectionMatrix();
1447
+ }
1448
+
1449
+ this.webglRenderer.domElement.style.top =
1450
+ this.webglRenderer.domElement.style.left = '0px';
1451
+ this.webglRenderer.setSize(window.innerWidth, window.innerHeight);
1452
+ this.webglRenderer.render(scene, this.debug2dCamera);
1453
+ } else if (this.renderQuilt) {
1454
+ camera.update(this.quiltResolution, this.tileCount);
1455
+
1456
+ const minWindowDimension =
1457
+ Math.min(window.innerWidth, window.innerHeight);
1458
+ this.webglRenderer.domElement.style.width =
1459
+ this.webglRenderer.domElement.style.height =
1460
+ `${minWindowDimension}px`;
1461
+ this.webglRenderer.domElement.style.top =
1462
+ this.webglRenderer.domElement.style.left = '0px';
1463
+
1464
+ this.webglRenderer.setRenderTarget(null);
1465
+ this.webglRenderer.setSize(
1466
+ this.quiltResolution, this.quiltResolution, false);
1467
+ this.webglRenderer.render(scene, camera);
1468
+ } else {
1469
+ this.quiltRenderTarget.setSize(
1470
+ this.quiltResolution, this.quiltResolution);
1471
+
1472
+ camera.update(this.quiltResolution, this.tileCount);
1473
+ this.webglRenderer.setRenderTarget(this.quiltRenderTarget);
1474
+ this.webglRenderer.setSize(
1475
+ this.quiltResolution, this.quiltResolution, false);
1476
+ this.webglRenderer.render(scene, camera);
1477
+
1478
+ this.webglRenderer.setRenderTarget(null);
1479
+ this.quiltRenderer.update(this.quiltResolution, this.tileCount);
1480
+ this.quiltRenderer.render();
1481
+ }
1482
+ }
1483
+ }
1484
+
1485
+ exports.Buttons = Buttons;
1486
+ exports.Calibration = calibration;
1487
+ exports.Camera = Camera;
1488
+ exports.FullscreenHelper = FullscreenHelper;
1489
+ exports.QuiltRenderer = QuiltRenderer;
1490
+ exports.Renderer = Renderer;
1491
+
1492
+ Object.defineProperty(exports, '__esModule', { value: true });
1493
+
1494
+ })));