1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | (function (global, factory) {
|
10 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@egjs/component'), require('promise-polyfill'), require('@egjs/agent'), require('@egjs/axes'), require('gl-matrix'), require('@egjs/imready')) :
|
11 | typeof define === 'function' && define.amd ? define(['@egjs/component', 'promise-polyfill', '@egjs/agent', '@egjs/axes', 'gl-matrix', '@egjs/imready'], factory) :
|
12 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, (global.eg = global.eg || {}, global.eg.view360 = factory(global.eg.Component, global.Promise, global.eg.agent, global.eg.Axes, global.glMatrix, global.eg.ImReady)));
|
13 | }(this, (function (Component, Promise$1, agent$1, Axes, glMatrix, ImReady) { 'use strict';
|
14 |
|
15 | var VERSION = "3.6.1";
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | var extendStatics = function (d, b) {
|
34 | extendStatics = Object.setPrototypeOf || {
|
35 | __proto__: []
|
36 | } instanceof Array && function (d, b) {
|
37 | d.__proto__ = b;
|
38 | } || function (d, b) {
|
39 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
40 | };
|
41 |
|
42 | return extendStatics(d, b);
|
43 | };
|
44 |
|
45 | function __extends(d, b) {
|
46 | extendStatics(d, b);
|
47 |
|
48 | function __() {
|
49 | this.constructor = d;
|
50 | }
|
51 |
|
52 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
53 | }
|
54 | var __assign = function () {
|
55 | __assign = Object.assign || function __assign(t) {
|
56 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
57 | s = arguments[i];
|
58 |
|
59 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
60 | }
|
61 |
|
62 | return t;
|
63 | };
|
64 |
|
65 | return __assign.apply(this, arguments);
|
66 | };
|
67 | function __awaiter(thisArg, _arguments, P, generator) {
|
68 | function adopt(value) {
|
69 | return value instanceof P ? value : new P(function (resolve) {
|
70 | resolve(value);
|
71 | });
|
72 | }
|
73 |
|
74 | return new (P || (P = Promise))(function (resolve, reject) {
|
75 | function fulfilled(value) {
|
76 | try {
|
77 | step(generator.next(value));
|
78 | } catch (e) {
|
79 | reject(e);
|
80 | }
|
81 | }
|
82 |
|
83 | function rejected(value) {
|
84 | try {
|
85 | step(generator["throw"](value));
|
86 | } catch (e) {
|
87 | reject(e);
|
88 | }
|
89 | }
|
90 |
|
91 | function step(result) {
|
92 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
93 | }
|
94 |
|
95 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
96 | });
|
97 | }
|
98 | function __generator(thisArg, body) {
|
99 | var _ = {
|
100 | label: 0,
|
101 | sent: function () {
|
102 | if (t[0] & 1) throw t[1];
|
103 | return t[1];
|
104 | },
|
105 | trys: [],
|
106 | ops: []
|
107 | },
|
108 | f,
|
109 | y,
|
110 | t,
|
111 | g;
|
112 | return g = {
|
113 | next: verb(0),
|
114 | "throw": verb(1),
|
115 | "return": verb(2)
|
116 | }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
117 | return this;
|
118 | }), g;
|
119 |
|
120 | function verb(n) {
|
121 | return function (v) {
|
122 | return step([n, v]);
|
123 | };
|
124 | }
|
125 |
|
126 | function step(op) {
|
127 | if (f) throw new TypeError("Generator is already executing.");
|
128 |
|
129 | while (_) try {
|
130 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
131 | if (y = 0, t) op = [op[0] & 2, t.value];
|
132 |
|
133 | switch (op[0]) {
|
134 | case 0:
|
135 | case 1:
|
136 | t = op;
|
137 | break;
|
138 |
|
139 | case 4:
|
140 | _.label++;
|
141 | return {
|
142 | value: op[1],
|
143 | done: false
|
144 | };
|
145 |
|
146 | case 5:
|
147 | _.label++;
|
148 | y = op[1];
|
149 | op = [0];
|
150 | continue;
|
151 |
|
152 | case 7:
|
153 | op = _.ops.pop();
|
154 |
|
155 | _.trys.pop();
|
156 |
|
157 | continue;
|
158 |
|
159 | default:
|
160 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
161 | _ = 0;
|
162 | continue;
|
163 | }
|
164 |
|
165 | if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
166 | _.label = op[1];
|
167 | break;
|
168 | }
|
169 |
|
170 | if (op[0] === 6 && _.label < t[1]) {
|
171 | _.label = t[1];
|
172 | t = op;
|
173 | break;
|
174 | }
|
175 |
|
176 | if (t && _.label < t[2]) {
|
177 | _.label = t[2];
|
178 |
|
179 | _.ops.push(op);
|
180 |
|
181 | break;
|
182 | }
|
183 |
|
184 | if (t[2]) _.ops.pop();
|
185 |
|
186 | _.trys.pop();
|
187 |
|
188 | continue;
|
189 | }
|
190 |
|
191 | op = body.call(thisArg, _);
|
192 | } catch (e) {
|
193 | op = [6, e];
|
194 | y = 0;
|
195 | } finally {
|
196 | f = t = 0;
|
197 | }
|
198 |
|
199 | if (op[0] & 5) throw op[1];
|
200 | return {
|
201 | value: op[0] ? op[1] : void 0,
|
202 | done: true
|
203 | };
|
204 | }
|
205 | }
|
206 | function __values(o) {
|
207 | var s = typeof Symbol === "function" && Symbol.iterator,
|
208 | m = s && o[s],
|
209 | i = 0;
|
210 | if (m) return m.call(o);
|
211 | if (o && typeof o.length === "number") return {
|
212 | next: function () {
|
213 | if (o && i >= o.length) o = void 0;
|
214 | return {
|
215 | value: o && o[i++],
|
216 | done: !o
|
217 | };
|
218 | }
|
219 | };
|
220 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
221 | }
|
222 | function __read(o, n) {
|
223 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
224 | if (!m) return o;
|
225 | var i = m.call(o),
|
226 | r,
|
227 | ar = [],
|
228 | e;
|
229 |
|
230 | try {
|
231 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
232 | } catch (error) {
|
233 | e = {
|
234 | error: error
|
235 | };
|
236 | } finally {
|
237 | try {
|
238 | if (r && !r.done && (m = i["return"])) m.call(i);
|
239 | } finally {
|
240 | if (e) throw e.error;
|
241 | }
|
242 | }
|
243 |
|
244 | return ar;
|
245 | }
|
246 | function __spread() {
|
247 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
248 |
|
249 | return ar;
|
250 | }
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | var win = typeof window !== "undefined" && window.Math === Math ? window : typeof self !== "undefined" && self.Math === Math ? self : Function("return this")();
|
256 |
|
257 |
|
258 | var doc = win.document;
|
259 | var nav = win.navigator;
|
260 | var agent = agent$1();
|
261 | var osName = agent.os.name;
|
262 | var browserName = agent.browser.name;
|
263 | var IS_IOS = osName === "ios";
|
264 | var IS_SAFARI_ON_DESKTOP = osName === "mac" && browserName === "safari";
|
265 |
|
266 |
|
267 | win.Float32Array = typeof win.Float32Array !== "undefined" ? win.Float32Array : win.Array;
|
268 | var Float32Array$1 = win.Float32Array;
|
269 | var getComputedStyle = win.getComputedStyle;
|
270 | var userAgent = win.navigator && win.navigator.userAgent;
|
271 | var SUPPORT_TOUCH = ("ontouchstart" in win);
|
272 | var SUPPORT_DEVICEMOTION = ("ondevicemotion" in win);
|
273 | var DeviceMotionEvent = win.DeviceMotionEvent;
|
274 | var devicePixelRatio = win.devicePixelRatio;
|
275 |
|
276 | var TRANSFORM = function () {
|
277 | var _a;
|
278 |
|
279 | var docStyle = (_a = doc === null || doc === void 0 ? void 0 : doc.documentElement.style) !== null && _a !== void 0 ? _a : {};
|
280 | var target = ["transform", "webkitTransform", "msTransform", "mozTransform"];
|
281 |
|
282 | for (var i = 0, len = target.length; i < len; i++) {
|
283 | if (target[i] in docStyle) {
|
284 | return target[i];
|
285 | }
|
286 | }
|
287 |
|
288 | return "";
|
289 | }();
|
290 |
|
291 |
|
292 | var SUPPORT_WILLCHANGE = win.CSS && win.CSS.supports && win.CSS.supports("will-change", "transform");
|
293 | var WEBXR_SUPPORTED = false;
|
294 |
|
295 | var checkXRSupport = function () {
|
296 | var navigator = window.navigator;
|
297 |
|
298 | if (!navigator.xr) {
|
299 | return;
|
300 | }
|
301 |
|
302 | if (navigator.xr.isSessionSupported) {
|
303 | navigator.xr.isSessionSupported("immersive-vr").then(function (res) {
|
304 | WEBXR_SUPPORTED = res;
|
305 | }).catch(function () {
|
306 | return void 0;
|
307 | });
|
308 | } else if (navigator.xr.supportsSession) {
|
309 | navigator.xr.supportsSession("immersive-vr").then(function (res) {
|
310 | WEBXR_SUPPORTED = res;
|
311 | }).catch(function () {
|
312 | return void 0;
|
313 | });
|
314 | }
|
315 | };
|
316 |
|
317 | |
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | var quatToVec3 = function (quaternion) {
|
325 | var baseV = glMatrix.vec3.fromValues(0, 0, 1);
|
326 | glMatrix.vec3.transformQuat(baseV, baseV, quaternion);
|
327 | return baseV;
|
328 | };
|
329 |
|
330 | var toDegree = function (a) {
|
331 | return a * 180 / Math.PI;
|
332 | };
|
333 |
|
334 | var util = {};
|
335 |
|
336 | util.isPowerOfTwo = function (n) {
|
337 | return n && (n & n - 1) === 0;
|
338 | };
|
339 |
|
340 | util.extractPitchFromQuat = function (quaternion) {
|
341 | var baseV = quatToVec3(quaternion);
|
342 | return -1 * Math.atan2(baseV[1], Math.sqrt(Math.pow(baseV[0], 2) + Math.pow(baseV[2], 2)));
|
343 | };
|
344 |
|
345 | util.hypot = Math.hypot || function (x, y) {
|
346 | return Math.sqrt(x * x + y * y);
|
347 | };
|
348 |
|
349 |
|
350 |
|
351 |
|
352 | var ROTATE_CONSTANT = {
|
353 | PITCH_DELTA: 1,
|
354 | YAW_DELTA_BY_ROLL: 2,
|
355 | YAW_DELTA_BY_YAW: 3
|
356 | };
|
357 | ROTATE_CONSTANT[ROTATE_CONSTANT.PITCH_DELTA] = {
|
358 | targetAxis: [0, 1, 0],
|
359 | meshPoint: [0, 0, 1]
|
360 | };
|
361 | ROTATE_CONSTANT[ROTATE_CONSTANT.YAW_DELTA_BY_ROLL] = {
|
362 | targetAxis: [0, 1, 0],
|
363 | meshPoint: [1, 0, 0]
|
364 | };
|
365 | ROTATE_CONSTANT[ROTATE_CONSTANT.YAW_DELTA_BY_YAW] = {
|
366 | targetAxis: [1, 0, 0],
|
367 | meshPoint: [0, 0, 1]
|
368 | };
|
369 |
|
370 | var getRotationDelta = function (prevQ, curQ, rotateKind) {
|
371 | var targetAxis = glMatrix.vec3.fromValues(ROTATE_CONSTANT[rotateKind].targetAxis[0], ROTATE_CONSTANT[rotateKind].targetAxis[1], ROTATE_CONSTANT[rotateKind].targetAxis[2]);
|
372 | var meshPoint = ROTATE_CONSTANT[rotateKind].meshPoint;
|
373 | var prevQuaternion = glMatrix.quat.clone(prevQ);
|
374 | var curQuaternion = glMatrix.quat.clone(curQ);
|
375 | glMatrix.quat.normalize(prevQuaternion, prevQuaternion);
|
376 | glMatrix.quat.normalize(curQuaternion, curQuaternion);
|
377 | var prevPoint = glMatrix.vec3.fromValues(0, 0, 1);
|
378 | var curPoint = glMatrix.vec3.fromValues(0, 0, 1);
|
379 | glMatrix.vec3.transformQuat(prevPoint, prevPoint, prevQuaternion);
|
380 | glMatrix.vec3.transformQuat(curPoint, curPoint, curQuaternion);
|
381 | glMatrix.vec3.transformQuat(targetAxis, targetAxis, curQuaternion);
|
382 | var rotateDistance = glMatrix.vec3.dot(targetAxis, glMatrix.vec3.cross(glMatrix.vec3.create(), prevPoint, curPoint));
|
383 | var rotateDirection = rotateDistance > 0 ? 1 : -1;
|
384 |
|
385 |
|
386 |
|
387 | var meshPoint2 = glMatrix.vec3.fromValues(meshPoint[0], meshPoint[1], meshPoint[2]);
|
388 | var meshPoint3;
|
389 |
|
390 | if (rotateKind !== ROTATE_CONSTANT.YAW_DELTA_BY_YAW) {
|
391 | meshPoint3 = glMatrix.vec3.fromValues(0, rotateDirection, 0);
|
392 | } else {
|
393 | meshPoint3 = glMatrix.vec3.fromValues(rotateDirection, 0, 0);
|
394 | }
|
395 |
|
396 | glMatrix.vec3.transformQuat(meshPoint2, meshPoint2, curQuaternion);
|
397 | glMatrix.vec3.transformQuat(meshPoint3, meshPoint3, curQuaternion);
|
398 | var vecU = meshPoint2;
|
399 | var vecV = meshPoint3;
|
400 | var vecN = glMatrix.vec3.create();
|
401 | glMatrix.vec3.cross(vecN, vecU, vecV);
|
402 | glMatrix.vec3.normalize(vecN, vecN);
|
403 | var coefficientA = vecN[0];
|
404 | var coefficientB = vecN[1];
|
405 | var coefficientC = vecN[2];
|
406 |
|
407 |
|
408 | curPoint = glMatrix.vec3.fromValues(meshPoint[0], meshPoint[1], meshPoint[2]);
|
409 | glMatrix.vec3.transformQuat(curPoint, curPoint, curQuaternion);
|
410 |
|
411 | prevPoint = glMatrix.vec3.fromValues(meshPoint[0], meshPoint[1], meshPoint[2]);
|
412 | glMatrix.vec3.transformQuat(prevPoint, prevPoint, prevQuaternion);
|
413 |
|
414 | var distance = Math.abs(prevPoint[0] * coefficientA + prevPoint[1] * coefficientB + prevPoint[2] * coefficientC);
|
415 | var projectedPrevPoint = glMatrix.vec3.create();
|
416 | glMatrix.vec3.subtract(projectedPrevPoint, prevPoint, glMatrix.vec3.scale(glMatrix.vec3.create(), vecN, distance));
|
417 | var trigonometricRatio = (projectedPrevPoint[0] * curPoint[0] + projectedPrevPoint[1] * curPoint[1] + projectedPrevPoint[2] * curPoint[2]) / (glMatrix.vec3.length(projectedPrevPoint) * glMatrix.vec3.length(curPoint));
|
418 |
|
419 | if (trigonometricRatio > 1) {
|
420 | trigonometricRatio = 1;
|
421 | }
|
422 |
|
423 | var theta = Math.acos(trigonometricRatio);
|
424 | var crossVec = glMatrix.vec3.cross(glMatrix.vec3.create(), curPoint, projectedPrevPoint);
|
425 | distance = coefficientA * crossVec[0] + coefficientB * crossVec[1] + coefficientC * crossVec[2];
|
426 | var thetaDirection;
|
427 |
|
428 | if (rotateKind !== ROTATE_CONSTANT.YAW_DELTA_BY_YAW) {
|
429 | thetaDirection = distance > 0 ? 1 : -1;
|
430 | } else {
|
431 | thetaDirection = distance < 0 ? 1 : -1;
|
432 | }
|
433 |
|
434 | var deltaRadian = theta * thetaDirection * rotateDirection;
|
435 | return toDegree(deltaRadian);
|
436 | };
|
437 |
|
438 | var angleBetweenVec2 = function (v1, v2) {
|
439 | var det = v1[0] * v2[1] - v2[0] * v1[1];
|
440 | var theta = -Math.atan2(det, glMatrix.vec2.dot(v1, v2));
|
441 | return theta;
|
442 | };
|
443 |
|
444 | util.yawOffsetBetween = function (viewDir, targetDir) {
|
445 | var viewDirXZ = glMatrix.vec2.fromValues(viewDir[0], viewDir[2]);
|
446 | var targetDirXZ = glMatrix.vec2.fromValues(targetDir[0], targetDir[2]);
|
447 | glMatrix.vec2.normalize(viewDirXZ, viewDirXZ);
|
448 | glMatrix.vec2.normalize(targetDirXZ, targetDirXZ);
|
449 | var theta = -angleBetweenVec2(viewDirXZ, targetDirXZ);
|
450 | return theta;
|
451 | };
|
452 |
|
453 | util.sign = function (x) {
|
454 | return Math.sign ? Math.sign(x) : Number(x > 0) - Number(x < 0) || +x;
|
455 | };
|
456 |
|
457 | util.toDegree = toDegree;
|
458 | util.getRotationDelta = getRotationDelta;
|
459 | util.angleBetweenVec2 = angleBetweenVec2;
|
460 |
|
461 | var toAxis = function (source, offset) {
|
462 | return offset.reduce(function (acc, v, i) {
|
463 | if (source[i]) {
|
464 | acc[source[i]] = v;
|
465 | }
|
466 |
|
467 | return acc;
|
468 | }, {});
|
469 | };
|
470 |
|
471 | |
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 | |
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 | var version = -1;
|
487 |
|
488 | var branch = null;
|
489 | var build = null;
|
490 | var match = /Chrome\/([0-9]+)\.(?:[0-9]*)\.([0-9]*)\.([0-9]*)/i.exec(userAgent);
|
491 |
|
492 | if (match) {
|
493 | version = parseInt(match[1], 10);
|
494 | branch = match[2];
|
495 | build = match[3];
|
496 | }
|
497 |
|
498 | var CHROME_VERSION = version;
|
499 | var IS_CHROME_WITHOUT_DEVICE_MOTION = version === 65 && branch === "3325" && parseInt(build, 10) < 148;
|
500 | var IS_ANDROID = /Android/i.test(userAgent);
|
501 | var CONTROL_MODE_VR = 1;
|
502 | var CONTROL_MODE_YAWPITCH = 2;
|
503 | var TOUCH_DIRECTION_NONE = 1;
|
504 | var TOUCH_DIRECTION_YAW = 2;
|
505 | var TOUCH_DIRECTION_PITCH = 4;
|
506 | var TOUCH_DIRECTION_ALL = TOUCH_DIRECTION_YAW | TOUCH_DIRECTION_PITCH;
|
507 |
|
508 |
|
509 | var MC_DECELERATION = 0.0014;
|
510 | var MC_MAXIMUM_DURATION = 1000;
|
511 | var MC_BIND_SCALE = [0.20, 0.20];
|
512 | var MAX_FIELD_OF_VIEW = 110;
|
513 | var PAN_SCALE = 320;
|
514 |
|
515 | var YAW_RANGE_HALF = 180;
|
516 | var PITCH_RANGE_HALF = 90;
|
517 | var CIRCULAR_PITCH_RANGE_HALF = 180;
|
518 | var GYRO_MODE = {
|
519 | NONE: "none",
|
520 | YAWPITCH: "yawPitch",
|
521 | VR: "VR"
|
522 | };
|
523 |
|
524 |
|
525 | var MathUtil = win.MathUtil || {};
|
526 | MathUtil.degToRad = Math.PI / 180;
|
527 | MathUtil.radToDeg = 180 / Math.PI;
|
528 |
|
529 |
|
530 | MathUtil.Vector2 = function (x, y) {
|
531 | this.x = x || 0;
|
532 | this.y = y || 0;
|
533 | };
|
534 |
|
535 | MathUtil.Vector2.prototype = {
|
536 | constructor: MathUtil.Vector2,
|
537 | set: function (x, y) {
|
538 | this.x = x;
|
539 | this.y = y;
|
540 | return this;
|
541 | },
|
542 | copy: function (v) {
|
543 | this.x = v.x;
|
544 | this.y = v.y;
|
545 | return this;
|
546 | },
|
547 | subVectors: function (a, b) {
|
548 | this.x = a.x - b.x;
|
549 | this.y = a.y - b.y;
|
550 | return this;
|
551 | }
|
552 | };
|
553 |
|
554 | MathUtil.Vector3 = function (x, y, z) {
|
555 | this.x = x || 0;
|
556 | this.y = y || 0;
|
557 | this.z = z || 0;
|
558 | };
|
559 |
|
560 | MathUtil.Vector3.prototype = {
|
561 | constructor: MathUtil.Vector3,
|
562 | set: function (x, y, z) {
|
563 | this.x = x;
|
564 | this.y = y;
|
565 | this.z = z;
|
566 | return this;
|
567 | },
|
568 | copy: function (v) {
|
569 | this.x = v.x;
|
570 | this.y = v.y;
|
571 | this.z = v.z;
|
572 | return this;
|
573 | },
|
574 | length: function () {
|
575 | return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
576 | },
|
577 | normalize: function () {
|
578 | var scalar = this.length();
|
579 |
|
580 | if (scalar !== 0) {
|
581 | var invScalar = 1 / scalar;
|
582 | this.multiplyScalar(invScalar);
|
583 | } else {
|
584 | this.x = 0;
|
585 | this.y = 0;
|
586 | this.z = 0;
|
587 | }
|
588 |
|
589 | return this;
|
590 | },
|
591 | multiplyScalar: function (scalar) {
|
592 | this.x *= scalar;
|
593 | this.y *= scalar;
|
594 | this.z *= scalar;
|
595 | },
|
596 | applyQuaternion: function (q) {
|
597 | var x = this.x;
|
598 | var y = this.y;
|
599 | var z = this.z;
|
600 | var qx = q.x;
|
601 | var qy = q.y;
|
602 | var qz = q.z;
|
603 | var qw = q.w;
|
604 |
|
605 | var ix = qw * x + qy * z - qz * y;
|
606 | var iy = qw * y + qz * x - qx * z;
|
607 | var iz = qw * z + qx * y - qy * x;
|
608 | var iw = -qx * x - qy * y - qz * z;
|
609 |
|
610 | this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
611 | this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
612 | this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
613 | return this;
|
614 | },
|
615 | dot: function (v) {
|
616 | return this.x * v.x + this.y * v.y + this.z * v.z;
|
617 | },
|
618 | crossVectors: function (a, b) {
|
619 | var ax = a.x;
|
620 | var ay = a.y;
|
621 | var az = a.z;
|
622 | var bx = b.x;
|
623 | var by = b.y;
|
624 | var bz = b.z;
|
625 | this.x = ay * bz - az * by;
|
626 | this.y = az * bx - ax * bz;
|
627 | this.z = ax * by - ay * bx;
|
628 | return this;
|
629 | }
|
630 | };
|
631 |
|
632 | MathUtil.Quaternion = function (x, y, z, w) {
|
633 | this.x = x || 0;
|
634 | this.y = y || 0;
|
635 | this.z = z || 0;
|
636 | this.w = w !== undefined ? w : 1;
|
637 | };
|
638 |
|
639 | MathUtil.Quaternion.prototype = {
|
640 | constructor: MathUtil.Quaternion,
|
641 | set: function (x, y, z, w) {
|
642 | this.x = x;
|
643 | this.y = y;
|
644 | this.z = z;
|
645 | this.w = w;
|
646 | return this;
|
647 | },
|
648 | copy: function (quaternion) {
|
649 | this.x = quaternion.x;
|
650 | this.y = quaternion.y;
|
651 | this.z = quaternion.z;
|
652 | this.w = quaternion.w;
|
653 | return this;
|
654 | },
|
655 | setFromEulerXYZ: function (x, y, z) {
|
656 | var c1 = Math.cos(x / 2);
|
657 | var c2 = Math.cos(y / 2);
|
658 | var c3 = Math.cos(z / 2);
|
659 | var s1 = Math.sin(x / 2);
|
660 | var s2 = Math.sin(y / 2);
|
661 | var s3 = Math.sin(z / 2);
|
662 | this.x = s1 * c2 * c3 + c1 * s2 * s3;
|
663 | this.y = c1 * s2 * c3 - s1 * c2 * s3;
|
664 | this.z = c1 * c2 * s3 + s1 * s2 * c3;
|
665 | this.w = c1 * c2 * c3 - s1 * s2 * s3;
|
666 | return this;
|
667 | },
|
668 | setFromEulerYXZ: function (x, y, z) {
|
669 | var c1 = Math.cos(x / 2);
|
670 | var c2 = Math.cos(y / 2);
|
671 | var c3 = Math.cos(z / 2);
|
672 | var s1 = Math.sin(x / 2);
|
673 | var s2 = Math.sin(y / 2);
|
674 | var s3 = Math.sin(z / 2);
|
675 | this.x = s1 * c2 * c3 + c1 * s2 * s3;
|
676 | this.y = c1 * s2 * c3 - s1 * c2 * s3;
|
677 | this.z = c1 * c2 * s3 - s1 * s2 * c3;
|
678 | this.w = c1 * c2 * c3 + s1 * s2 * s3;
|
679 | return this;
|
680 | },
|
681 | setFromAxisAngle: function (axis, angle) {
|
682 |
|
683 |
|
684 | var halfAngle = angle / 2;
|
685 | var s = Math.sin(halfAngle);
|
686 | this.x = axis.x * s;
|
687 | this.y = axis.y * s;
|
688 | this.z = axis.z * s;
|
689 | this.w = Math.cos(halfAngle);
|
690 | return this;
|
691 | },
|
692 | multiply: function (q) {
|
693 | return this.multiplyQuaternions(this, q);
|
694 | },
|
695 | multiplyQuaternions: function (a, b) {
|
696 |
|
697 | var qax = a.x;
|
698 | var qay = a.y;
|
699 | var qaz = a.z;
|
700 | var qaw = a.w;
|
701 | var qbx = b.x;
|
702 | var qby = b.y;
|
703 | var qbz = b.z;
|
704 | var qbw = b.w;
|
705 | this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
|
706 | this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
|
707 | this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
|
708 | this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
|
709 | return this;
|
710 | },
|
711 | inverse: function () {
|
712 | this.x *= -1;
|
713 | this.y *= -1;
|
714 | this.z *= -1;
|
715 | this.normalize();
|
716 | return this;
|
717 | },
|
718 | normalize: function () {
|
719 | var l = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
|
720 |
|
721 | if (l === 0) {
|
722 | this.x = 0;
|
723 | this.y = 0;
|
724 | this.z = 0;
|
725 | this.w = 1;
|
726 | } else {
|
727 | l = 1 / l;
|
728 | this.x = this.x * l;
|
729 | this.y = this.y * l;
|
730 | this.z = this.z * l;
|
731 | this.w = this.w * l;
|
732 | }
|
733 |
|
734 | return this;
|
735 | },
|
736 | slerp: function (qb, t) {
|
737 | if (t === 0) return this;
|
738 | if (t === 1) return this.copy(qb);
|
739 | var x = this.x;
|
740 | var y = this.y;
|
741 | var z = this.z;
|
742 | var w = this.w;
|
743 |
|
744 | var cosHalfTheta = w * qb.w + x * qb.x + y * qb.y + z * qb.z;
|
745 |
|
746 | if (cosHalfTheta < 0) {
|
747 | this.w = -qb.w;
|
748 | this.x = -qb.x;
|
749 | this.y = -qb.y;
|
750 | this.z = -qb.z;
|
751 | cosHalfTheta = -cosHalfTheta;
|
752 | } else {
|
753 | this.copy(qb);
|
754 | }
|
755 |
|
756 | if (cosHalfTheta >= 1.0) {
|
757 | this.w = w;
|
758 | this.x = x;
|
759 | this.y = y;
|
760 | this.z = z;
|
761 | return this;
|
762 | }
|
763 |
|
764 | var halfTheta = Math.acos(cosHalfTheta);
|
765 | var sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);
|
766 |
|
767 | if (Math.abs(sinHalfTheta) < 0.001) {
|
768 | this.w = 0.5 * (w + this.w);
|
769 | this.x = 0.5 * (x + this.x);
|
770 | this.y = 0.5 * (y + this.y);
|
771 | this.z = 0.5 * (z + this.z);
|
772 | return this;
|
773 | }
|
774 |
|
775 | var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;
|
776 | var ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
|
777 | this.w = w * ratioA + this.w * ratioB;
|
778 | this.x = x * ratioA + this.x * ratioB;
|
779 | this.y = y * ratioA + this.y * ratioB;
|
780 | this.z = z * ratioA + this.z * ratioB;
|
781 | return this;
|
782 | },
|
783 | setFromUnitVectors: function () {
|
784 |
|
785 |
|
786 | var v1;
|
787 | var r;
|
788 | var EPS = 0.000001;
|
789 | return function (vFrom, vTo) {
|
790 | if (v1 === undefined) v1 = new MathUtil.Vector3();
|
791 | r = vFrom.dot(vTo) + 1;
|
792 |
|
793 | if (r < EPS) {
|
794 | r = 0;
|
795 |
|
796 | if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
|
797 | v1.set(-vFrom.y, vFrom.x, 0);
|
798 | } else {
|
799 | v1.set(0, -vFrom.z, vFrom.y);
|
800 | }
|
801 | } else {
|
802 | v1.crossVectors(vFrom, vTo);
|
803 | }
|
804 |
|
805 | this.x = v1.x;
|
806 | this.y = v1.y;
|
807 | this.z = v1.z;
|
808 | this.w = r;
|
809 | this.normalize();
|
810 | return this;
|
811 | };
|
812 | }()
|
813 | };
|
814 |
|
815 |
|
816 |
|
817 | |
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 | var _a;
|
832 | var userAgent$1 = (_a = nav === null || nav === void 0 ? void 0 : nav.userAgent) !== null && _a !== void 0 ? _a : "";
|
833 | var Util = win.Util || {};
|
834 | Util.MIN_TIMESTEP = 0.001;
|
835 | Util.MAX_TIMESTEP = 1;
|
836 |
|
837 | Util.base64 = function (mimeType, base64) {
|
838 | return "data:" + mimeType + ";base64," + base64;
|
839 | };
|
840 |
|
841 | Util.clamp = function (value, min, max) {
|
842 | return Math.min(Math.max(min, value), max);
|
843 | };
|
844 |
|
845 | Util.lerp = function (a, b, t) {
|
846 | return a + (b - a) * t;
|
847 | };
|
848 |
|
849 | Util.isIOS = function () {
|
850 | var isIOS = /iPad|iPhone|iPod/.test(nav === null || nav === void 0 ? void 0 : nav.platform);
|
851 | return function () {
|
852 | return isIOS;
|
853 | };
|
854 | }();
|
855 |
|
856 | Util.isWebViewAndroid = function () {
|
857 | var isWebViewAndroid = userAgent$1.indexOf("Version") !== -1 && userAgent$1.indexOf("Android") !== -1 && userAgent$1.indexOf("Chrome") !== -1;
|
858 | return function () {
|
859 | return isWebViewAndroid;
|
860 | };
|
861 | }();
|
862 |
|
863 | Util.isSafari = function () {
|
864 | var isSafari = /^((?!chrome|android).)*safari/i.test(userAgent$1);
|
865 | return function () {
|
866 | return isSafari;
|
867 | };
|
868 | }();
|
869 |
|
870 | Util.isFirefoxAndroid = function () {
|
871 | var isFirefoxAndroid = userAgent$1.indexOf("Firefox") !== -1 && userAgent$1.indexOf("Android") !== -1;
|
872 | return function () {
|
873 | return isFirefoxAndroid;
|
874 | };
|
875 | }();
|
876 |
|
877 | Util.isR7 = function () {
|
878 | var isR7 = userAgent$1.indexOf("R7 Build") !== -1;
|
879 | return function () {
|
880 | return isR7;
|
881 | };
|
882 | }();
|
883 |
|
884 | Util.isLandscapeMode = function () {
|
885 | var rtn = win.orientation === 90 || win.orientation === -90;
|
886 | return Util.isR7() ? !rtn : rtn;
|
887 | };
|
888 |
|
889 |
|
890 | Util.isTimestampDeltaValid = function (timestampDeltaS) {
|
891 | if (isNaN(timestampDeltaS)) {
|
892 | return false;
|
893 | }
|
894 |
|
895 | if (timestampDeltaS <= Util.MIN_TIMESTEP) {
|
896 | return false;
|
897 | }
|
898 |
|
899 | if (timestampDeltaS > Util.MAX_TIMESTEP) {
|
900 | return false;
|
901 | }
|
902 |
|
903 | return true;
|
904 | };
|
905 |
|
906 | Util.getScreenWidth = function () {
|
907 | return Math.max(win.screen.width, win.screen.height) * win.devicePixelRatio;
|
908 | };
|
909 |
|
910 | Util.getScreenHeight = function () {
|
911 | return Math.min(win.screen.width, win.screen.height) * win.devicePixelRatio;
|
912 | };
|
913 |
|
914 | Util.requestFullscreen = function (element) {
|
915 | if (Util.isWebViewAndroid()) {
|
916 | return false;
|
917 | }
|
918 |
|
919 | if (element.requestFullscreen) {
|
920 | element.requestFullscreen();
|
921 | } else if (element.webkitRequestFullscreen) {
|
922 | element.webkitRequestFullscreen();
|
923 | } else if (element.mozRequestFullScreen) {
|
924 | element.mozRequestFullScreen();
|
925 | } else if (element.msRequestFullscreen) {
|
926 | element.msRequestFullscreen();
|
927 | } else {
|
928 | return false;
|
929 | }
|
930 |
|
931 | return true;
|
932 | };
|
933 |
|
934 | Util.exitFullscreen = function () {
|
935 | if (doc.exitFullscreen) {
|
936 | doc.exitFullscreen();
|
937 | } else if (doc.webkitExitFullscreen) {
|
938 | doc.webkitExitFullscreen();
|
939 | } else if (doc.mozCancelFullScreen) {
|
940 | doc.mozCancelFullScreen();
|
941 | } else if (doc.msExitFullscreen) {
|
942 | doc.msExitFullscreen();
|
943 | } else {
|
944 | return false;
|
945 | }
|
946 |
|
947 | return true;
|
948 | };
|
949 |
|
950 | Util.getFullscreenElement = function () {
|
951 | return doc.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement;
|
952 | };
|
953 |
|
954 | Util.linkProgram = function (gl, vertexSource, fragmentSource, attribLocationMap) {
|
955 |
|
956 | var vertexShader = gl.createShader(gl.VERTEX_SHADER);
|
957 | gl.shaderSource(vertexShader, vertexSource);
|
958 | gl.compileShader(vertexShader);
|
959 | var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
|
960 | gl.shaderSource(fragmentShader, fragmentSource);
|
961 | gl.compileShader(fragmentShader);
|
962 | var program = gl.createProgram();
|
963 | gl.attachShader(program, vertexShader);
|
964 | gl.attachShader(program, fragmentShader);
|
965 |
|
966 | for (var attribName in attribLocationMap) gl.bindAttribLocation(program, attribLocationMap[attribName], attribName);
|
967 |
|
968 | gl.linkProgram(program);
|
969 | gl.deleteShader(vertexShader);
|
970 | gl.deleteShader(fragmentShader);
|
971 | return program;
|
972 | };
|
973 |
|
974 | Util.getProgramUniforms = function (gl, program) {
|
975 | var uniforms = {};
|
976 | var uniformCount = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
977 | var uniformName = "";
|
978 |
|
979 | for (var i = 0; i < uniformCount; i++) {
|
980 | var uniformInfo = gl.getActiveUniform(program, i);
|
981 | uniformName = uniformInfo.name.replace("[0]", "");
|
982 | uniforms[uniformName] = gl.getUniformLocation(program, uniformName);
|
983 | }
|
984 |
|
985 | return uniforms;
|
986 | };
|
987 |
|
988 | Util.orthoMatrix = function (out, left, right, bottom, top, near, far) {
|
989 | var lr = 1 / (left - right);
|
990 | var bt = 1 / (bottom - top);
|
991 | var nf = 1 / (near - far);
|
992 | out[0] = -2 * lr;
|
993 | out[1] = 0;
|
994 | out[2] = 0;
|
995 | out[3] = 0;
|
996 | out[4] = 0;
|
997 | out[5] = -2 * bt;
|
998 | out[6] = 0;
|
999 | out[7] = 0;
|
1000 | out[8] = 0;
|
1001 | out[9] = 0;
|
1002 | out[10] = 2 * nf;
|
1003 | out[11] = 0;
|
1004 | out[12] = (left + right) * lr;
|
1005 | out[13] = (top + bottom) * bt;
|
1006 | out[14] = (far + near) * nf;
|
1007 | out[15] = 1;
|
1008 | return out;
|
1009 | };
|
1010 |
|
1011 | Util.copyArray = function (source, dest) {
|
1012 | for (var i = 0, n = source.length; i < n; i++) {
|
1013 | dest[i] = source[i];
|
1014 | }
|
1015 | };
|
1016 |
|
1017 | Util.isMobile = function () {
|
1018 | var check = false;
|
1019 |
|
1020 | (function (a) {
|
1021 | if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true;
|
1022 | })(userAgent$1 || (nav === null || nav === void 0 ? void 0 : nav.vendor) || win.opera);
|
1023 |
|
1024 | return check;
|
1025 | };
|
1026 |
|
1027 | Util.extend = function (dest, src) {
|
1028 | for (var key in src) {
|
1029 | if (src.hasOwnProperty(key)) {
|
1030 | dest[key] = src[key];
|
1031 | }
|
1032 | }
|
1033 |
|
1034 | return dest;
|
1035 | };
|
1036 |
|
1037 | Util.safariCssSizeWorkaround = function (canvas) {
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 | if (Util.isIOS()) {
|
1046 | var width_1 = canvas.style.width;
|
1047 | var height_1 = canvas.style.height;
|
1048 | canvas.style.width = parseInt(width_1) + 1 + "px";
|
1049 | canvas.style.height = parseInt(height_1) + "px";
|
1050 | setTimeout(function () {
|
1051 | canvas.style.width = width_1;
|
1052 | canvas.style.height = height_1;
|
1053 | }, 100);
|
1054 | }
|
1055 |
|
1056 |
|
1057 | win.Util = Util;
|
1058 | win.canvas = canvas;
|
1059 | };
|
1060 |
|
1061 | Util.isDebug = function () {
|
1062 | return Util.getQueryParameter("debug");
|
1063 | };
|
1064 |
|
1065 | Util.getQueryParameter = function (name) {
|
1066 | name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
1067 | var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
|
1068 | var results = regex.exec(location.search);
|
1069 | return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
1070 | };
|
1071 |
|
1072 | Util.frameDataFromPose = function () {
|
1073 | var piOver180 = Math.PI / 180.0;
|
1074 | var rad45 = Math.PI * 0.25;
|
1075 |
|
1076 | function mat4_perspectiveFromFieldOfView(out, fov, near, far) {
|
1077 | var upTan = Math.tan(fov ? fov.upDegrees * piOver180 : rad45);
|
1078 | var downTan = Math.tan(fov ? fov.downDegrees * piOver180 : rad45);
|
1079 | var leftTan = Math.tan(fov ? fov.leftDegrees * piOver180 : rad45);
|
1080 | var rightTan = Math.tan(fov ? fov.rightDegrees * piOver180 : rad45);
|
1081 | var xScale = 2.0 / (leftTan + rightTan);
|
1082 | var yScale = 2.0 / (upTan + downTan);
|
1083 | out[0] = xScale;
|
1084 | out[1] = 0.0;
|
1085 | out[2] = 0.0;
|
1086 | out[3] = 0.0;
|
1087 | out[4] = 0.0;
|
1088 | out[5] = yScale;
|
1089 | out[6] = 0.0;
|
1090 | out[7] = 0.0;
|
1091 | out[8] = -((leftTan - rightTan) * xScale * 0.5);
|
1092 | out[9] = (upTan - downTan) * yScale * 0.5;
|
1093 | out[10] = far / (near - far);
|
1094 | out[11] = -1.0;
|
1095 | out[12] = 0.0;
|
1096 | out[13] = 0.0;
|
1097 | out[14] = far * near / (near - far);
|
1098 | out[15] = 0.0;
|
1099 | return out;
|
1100 | }
|
1101 |
|
1102 | function mat4_fromRotationTranslation(out, q, v) {
|
1103 |
|
1104 | var x = q[0];
|
1105 | var y = q[1];
|
1106 | var z = q[2];
|
1107 | var w = q[3];
|
1108 | var x2 = x + x;
|
1109 | var y2 = y + y;
|
1110 | var z2 = z + z;
|
1111 | var xx = x * x2;
|
1112 | var xy = x * y2;
|
1113 | var xz = x * z2;
|
1114 | var yy = y * y2;
|
1115 | var yz = y * z2;
|
1116 | var zz = z * z2;
|
1117 | var wx = w * x2;
|
1118 | var wy = w * y2;
|
1119 | var wz = w * z2;
|
1120 | out[0] = 1 - (yy + zz);
|
1121 | out[1] = xy + wz;
|
1122 | out[2] = xz - wy;
|
1123 | out[3] = 0;
|
1124 | out[4] = xy - wz;
|
1125 | out[5] = 1 - (xx + zz);
|
1126 | out[6] = yz + wx;
|
1127 | out[7] = 0;
|
1128 | out[8] = xz + wy;
|
1129 | out[9] = yz - wx;
|
1130 | out[10] = 1 - (xx + yy);
|
1131 | out[11] = 0;
|
1132 | out[12] = v[0];
|
1133 | out[13] = v[1];
|
1134 | out[14] = v[2];
|
1135 | out[15] = 1;
|
1136 | return out;
|
1137 | }
|
1138 |
|
1139 | function mat4_translate(out, a, v) {
|
1140 | var x = v[0];
|
1141 | var y = v[1];
|
1142 | var z = v[2];
|
1143 | var a00;
|
1144 | var a01;
|
1145 | var a02;
|
1146 | var a03;
|
1147 | var a10;
|
1148 | var a11;
|
1149 | var a12;
|
1150 | var a13;
|
1151 | var a20;
|
1152 | var a21;
|
1153 | var a22;
|
1154 | var a23;
|
1155 |
|
1156 | if (a === out) {
|
1157 | out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
1158 | out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
1159 | out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
1160 | out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
1161 | } else {
|
1162 | a00 = a[0];
|
1163 | a01 = a[1];
|
1164 | a02 = a[2];
|
1165 | a03 = a[3];
|
1166 | a10 = a[4];
|
1167 | a11 = a[5];
|
1168 | a12 = a[6];
|
1169 | a13 = a[7];
|
1170 | a20 = a[8];
|
1171 | a21 = a[9];
|
1172 | a22 = a[10];
|
1173 | a23 = a[11];
|
1174 | out[0] = a00;
|
1175 | out[1] = a01;
|
1176 | out[2] = a02;
|
1177 | out[3] = a03;
|
1178 | out[4] = a10;
|
1179 | out[5] = a11;
|
1180 | out[6] = a12;
|
1181 | out[7] = a13;
|
1182 | out[8] = a20;
|
1183 | out[9] = a21;
|
1184 | out[10] = a22;
|
1185 | out[11] = a23;
|
1186 | out[12] = a00 * x + a10 * y + a20 * z + a[12];
|
1187 | out[13] = a01 * x + a11 * y + a21 * z + a[13];
|
1188 | out[14] = a02 * x + a12 * y + a22 * z + a[14];
|
1189 | out[15] = a03 * x + a13 * y + a23 * z + a[15];
|
1190 | }
|
1191 |
|
1192 | return out;
|
1193 | }
|
1194 |
|
1195 | function mat4_invert(out, a) {
|
1196 | var a00 = a[0];
|
1197 | var a01 = a[1];
|
1198 | var a02 = a[2];
|
1199 | var a03 = a[3];
|
1200 | var a10 = a[4];
|
1201 | var a11 = a[5];
|
1202 | var a12 = a[6];
|
1203 | var a13 = a[7];
|
1204 | var a20 = a[8];
|
1205 | var a21 = a[9];
|
1206 | var a22 = a[10];
|
1207 | var a23 = a[11];
|
1208 | var a30 = a[12];
|
1209 | var a31 = a[13];
|
1210 | var a32 = a[14];
|
1211 | var a33 = a[15];
|
1212 | var b00 = a00 * a11 - a01 * a10;
|
1213 | var b01 = a00 * a12 - a02 * a10;
|
1214 | var b02 = a00 * a13 - a03 * a10;
|
1215 | var b03 = a01 * a12 - a02 * a11;
|
1216 | var b04 = a01 * a13 - a03 * a11;
|
1217 | var b05 = a02 * a13 - a03 * a12;
|
1218 | var b06 = a20 * a31 - a21 * a30;
|
1219 | var b07 = a20 * a32 - a22 * a30;
|
1220 | var b08 = a20 * a33 - a23 * a30;
|
1221 | var b09 = a21 * a32 - a22 * a31;
|
1222 | var b10 = a21 * a33 - a23 * a31;
|
1223 | var b11 = a22 * a33 - a23 * a32;
|
1224 |
|
1225 | var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
1226 |
|
1227 | if (!det) {
|
1228 | return null;
|
1229 | }
|
1230 |
|
1231 | det = 1.0 / det;
|
1232 | out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
1233 | out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
1234 | out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
1235 | out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
1236 | out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
1237 | out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
1238 | out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
1239 | out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
1240 | out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
1241 | out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
1242 | out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
1243 | out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
1244 | out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
1245 | out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
1246 | out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
1247 | out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
1248 | return out;
|
1249 | }
|
1250 |
|
1251 | var defaultOrientation = new Float32Array([0, 0, 0, 1]);
|
1252 | var defaultPosition = new Float32Array([0, 0, 0]);
|
1253 |
|
1254 | function updateEyeMatrices(projection, view, pose, parameters, vrDisplay) {
|
1255 | mat4_perspectiveFromFieldOfView(projection, parameters ? parameters.fieldOfView : null, vrDisplay.depthNear, vrDisplay.depthFar);
|
1256 | var orientation = pose.orientation || defaultOrientation;
|
1257 | var position = pose.position || defaultPosition;
|
1258 | mat4_fromRotationTranslation(view, orientation, position);
|
1259 | if (parameters) mat4_translate(view, view, parameters.offset);
|
1260 | mat4_invert(view, view);
|
1261 | }
|
1262 |
|
1263 | return function (frameData, pose, vrDisplay) {
|
1264 | if (!frameData || !pose) return false;
|
1265 | frameData.pose = pose;
|
1266 | frameData.timestamp = pose.timestamp;
|
1267 | updateEyeMatrices(frameData.leftProjectionMatrix, frameData.leftViewMatrix, pose, vrDisplay.getEyeParameters("left"), vrDisplay);
|
1268 | updateEyeMatrices(frameData.rightProjectionMatrix, frameData.rightViewMatrix, pose, vrDisplay.getEyeParameters("right"), vrDisplay);
|
1269 | return true;
|
1270 | };
|
1271 | }();
|
1272 |
|
1273 | Util.isInsideCrossDomainIFrame = function () {
|
1274 | var isFramed = win.self !== win.top;
|
1275 | var refDomain = Util.getDomainFromUrl(doc.referrer);
|
1276 | var thisDomain = Util.getDomainFromUrl(win.location.href);
|
1277 | return isFramed && refDomain !== thisDomain;
|
1278 | };
|
1279 |
|
1280 |
|
1281 | Util.getDomainFromUrl = function (url) {
|
1282 | var domain;
|
1283 |
|
1284 | if (url.indexOf("://") > -1) {
|
1285 | domain = url.split("/")[2];
|
1286 | } else {
|
1287 | domain = url.split("/")[0];
|
1288 | }
|
1289 |
|
1290 |
|
1291 | domain = domain.split(":")[0];
|
1292 | return domain;
|
1293 | };
|
1294 |
|
1295 |
|
1296 | |
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 | var PosePredictor =
|
1306 |
|
1307 | function () {
|
1308 | function PosePredictor(predictionTimeS) {
|
1309 | this.predictionTimeS = predictionTimeS;
|
1310 |
|
1311 | this.previousQ = new MathUtil.Quaternion();
|
1312 |
|
1313 | this.previousTimestampS = null;
|
1314 |
|
1315 | this.deltaQ = new MathUtil.Quaternion();
|
1316 |
|
1317 | this.outQ = new MathUtil.Quaternion();
|
1318 | }
|
1319 |
|
1320 | var __proto = PosePredictor.prototype;
|
1321 |
|
1322 | __proto.getPrediction = function (currentQ, gyro, timestampS) {
|
1323 | if (!this.previousTimestampS) {
|
1324 | this.previousQ.copy(currentQ);
|
1325 | this.previousTimestampS = timestampS;
|
1326 | return currentQ;
|
1327 | }
|
1328 |
|
1329 |
|
1330 | var axis = new MathUtil.Vector3();
|
1331 | axis.copy(gyro);
|
1332 | axis.normalize();
|
1333 | var angularSpeed = gyro.length();
|
1334 |
|
1335 | if (angularSpeed < MathUtil.degToRad * 20) {
|
1336 | if (Util.isDebug()) {
|
1337 | console.log("Moving slowly, at %s deg/s: no prediction", (MathUtil.radToDeg * angularSpeed).toFixed(1));
|
1338 | }
|
1339 |
|
1340 | this.outQ.copy(currentQ);
|
1341 | this.previousQ.copy(currentQ);
|
1342 | return this.outQ;
|
1343 | }
|
1344 |
|
1345 |
|
1346 | var deltaT = timestampS - this.previousTimestampS;
|
1347 | var predictAngle = angularSpeed * this.predictionTimeS;
|
1348 | this.deltaQ.setFromAxisAngle(axis, predictAngle);
|
1349 | this.outQ.copy(this.previousQ);
|
1350 | this.outQ.multiply(this.deltaQ);
|
1351 | this.previousQ.copy(currentQ);
|
1352 | this.previousTimestampS = timestampS;
|
1353 | return this.outQ;
|
1354 | };
|
1355 |
|
1356 | return PosePredictor;
|
1357 | }();
|
1358 |
|
1359 | var STILLNESS_THRESHOLD = 200;
|
1360 |
|
1361 | var DeviceMotion =
|
1362 |
|
1363 | function (_super) {
|
1364 | __extends(DeviceMotion, _super);
|
1365 |
|
1366 | function DeviceMotion() {
|
1367 | var _this = _super.call(this) || this;
|
1368 |
|
1369 | _this._onDeviceMotion = _this._onDeviceMotion.bind(_this);
|
1370 | _this._onDeviceOrientation = _this._onDeviceOrientation.bind(_this);
|
1371 | _this._onChromeWithoutDeviceMotion = _this._onChromeWithoutDeviceMotion.bind(_this);
|
1372 | _this.isWithoutDeviceMotion = IS_CHROME_WITHOUT_DEVICE_MOTION;
|
1373 | _this.isAndroid = IS_ANDROID;
|
1374 | _this.stillGyroVec = glMatrix.vec3.create();
|
1375 | _this.rawGyroVec = glMatrix.vec3.create();
|
1376 | _this.adjustedGyroVec = glMatrix.vec3.create();
|
1377 | _this._timer = -1;
|
1378 | _this.lastDevicemotionTimestamp = 0;
|
1379 | _this._isEnabled = false;
|
1380 |
|
1381 | _this.enable();
|
1382 |
|
1383 | return _this;
|
1384 | }
|
1385 |
|
1386 | var __proto = DeviceMotion.prototype;
|
1387 |
|
1388 | __proto.enable = function () {
|
1389 | if (this.isAndroid) {
|
1390 | win.addEventListener("deviceorientation", this._onDeviceOrientation);
|
1391 | }
|
1392 |
|
1393 | if (this.isWithoutDeviceMotion) {
|
1394 | win.addEventListener("deviceorientation", this._onChromeWithoutDeviceMotion);
|
1395 | } else {
|
1396 | win.addEventListener("devicemotion", this._onDeviceMotion);
|
1397 | }
|
1398 |
|
1399 | this._isEnabled = true;
|
1400 | };
|
1401 |
|
1402 | __proto.disable = function () {
|
1403 | win.removeEventListener("deviceorientation", this._onDeviceOrientation);
|
1404 | win.removeEventListener("deviceorientation", this._onChromeWithoutDeviceMotion);
|
1405 | win.removeEventListener("devicemotion", this._onDeviceMotion);
|
1406 | this._isEnabled = false;
|
1407 | };
|
1408 |
|
1409 | __proto._onChromeWithoutDeviceMotion = function (e) {
|
1410 | var alpha = e.alpha,
|
1411 | beta = e.beta,
|
1412 | gamma = e.gamma;
|
1413 |
|
1414 |
|
1415 | if (alpha === null) {
|
1416 | return;
|
1417 | }
|
1418 |
|
1419 |
|
1420 | alpha = (alpha || 0) * Math.PI / 180;
|
1421 | beta = (beta || 0) * Math.PI / 180;
|
1422 | gamma = (gamma || 0) * Math.PI / 180;
|
1423 | this.trigger(new Component.ComponentEvent("devicemotion", {
|
1424 | inputEvent: {
|
1425 | deviceorientation: {
|
1426 | alpha: alpha,
|
1427 | beta: beta,
|
1428 | gamma: -gamma
|
1429 | }
|
1430 | }
|
1431 | }));
|
1432 | };
|
1433 |
|
1434 | __proto._onDeviceOrientation = function () {
|
1435 | var _this = this;
|
1436 |
|
1437 | if (this._timer) {
|
1438 | clearTimeout(this._timer);
|
1439 | }
|
1440 |
|
1441 | this._timer = win.setTimeout(function () {
|
1442 | if (new Date().getTime() - _this.lastDevicemotionTimestamp < STILLNESS_THRESHOLD) {
|
1443 | glMatrix.vec3.copy(_this.stillGyroVec, _this.rawGyroVec);
|
1444 | }
|
1445 | }, STILLNESS_THRESHOLD);
|
1446 | };
|
1447 |
|
1448 | __proto._onDeviceMotion = function (e) {
|
1449 |
|
1450 |
|
1451 | var isGyroSensorAvailable = !(e.rotationRate.alpha == null);
|
1452 | var isGravitySensorAvailable = !(e.accelerationIncludingGravity.x == null);
|
1453 |
|
1454 | if (e.interval === 0 || !(isGyroSensorAvailable && isGravitySensorAvailable)) {
|
1455 | return;
|
1456 | }
|
1457 |
|
1458 | var devicemotionEvent = __assign({}, e);
|
1459 |
|
1460 | devicemotionEvent.interval = e.interval;
|
1461 | devicemotionEvent.timeStamp = e.timeStamp;
|
1462 | devicemotionEvent.type = e.type;
|
1463 | devicemotionEvent.rotationRate = {
|
1464 | alpha: e.rotationRate.alpha,
|
1465 | beta: e.rotationRate.beta,
|
1466 | gamma: e.rotationRate.gamma
|
1467 | };
|
1468 | devicemotionEvent.accelerationIncludingGravity = {
|
1469 | x: e.accelerationIncludingGravity.x,
|
1470 | y: e.accelerationIncludingGravity.y,
|
1471 | z: e.accelerationIncludingGravity.z
|
1472 | };
|
1473 | devicemotionEvent.acceleration = {
|
1474 | x: e.acceleration.x,
|
1475 | y: e.acceleration.y,
|
1476 | z: e.acceleration.z
|
1477 | };
|
1478 |
|
1479 | if (this.isAndroid) {
|
1480 | glMatrix.vec3.set(this.rawGyroVec, e.rotationRate.alpha || 0, e.rotationRate.beta || 0, e.rotationRate.gamma || 0);
|
1481 | glMatrix.vec3.subtract(this.adjustedGyroVec, this.rawGyroVec, this.stillGyroVec);
|
1482 | this.lastDevicemotionTimestamp = new Date().getTime();
|
1483 | devicemotionEvent.adjustedRotationRate = {
|
1484 | alpha: this.adjustedGyroVec[0],
|
1485 | beta: this.adjustedGyroVec[1],
|
1486 | gamma: this.adjustedGyroVec[2]
|
1487 | };
|
1488 | }
|
1489 |
|
1490 | this.trigger(new Component.ComponentEvent("devicemotion", {
|
1491 | inputEvent: devicemotionEvent
|
1492 | }));
|
1493 | };
|
1494 |
|
1495 | return DeviceMotion;
|
1496 | }(Component);
|
1497 |
|
1498 | var SensorSample =
|
1499 |
|
1500 | function () {
|
1501 | function SensorSample(sample, timestampS) {
|
1502 | this.set(sample, timestampS);
|
1503 | }
|
1504 |
|
1505 | var __proto = SensorSample.prototype;
|
1506 |
|
1507 | __proto.set = function (sample, timestampS) {
|
1508 | this.sample = sample;
|
1509 | this.timestampS = timestampS;
|
1510 | };
|
1511 |
|
1512 | __proto.copy = function (sensorSample) {
|
1513 | this.set(sensorSample.sample, sensorSample.timestampS);
|
1514 | };
|
1515 |
|
1516 | return SensorSample;
|
1517 | }();
|
1518 |
|
1519 |
|
1520 | |
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 | var ComplementaryFilter =
|
1536 |
|
1537 | function () {
|
1538 | function ComplementaryFilter(kFilter) {
|
1539 | this.addGyroMeasurement = function (vector, timestampS) {
|
1540 | this.currentGyroMeasurement.set(vector, timestampS);
|
1541 | var deltaT = timestampS - this.previousGyroMeasurement.timestampS;
|
1542 |
|
1543 | if (Util.isTimestampDeltaValid(deltaT)) {
|
1544 | this.run_();
|
1545 | }
|
1546 |
|
1547 | this.previousGyroMeasurement.copy(this.currentGyroMeasurement);
|
1548 | };
|
1549 |
|
1550 | this.kFilter = kFilter;
|
1551 |
|
1552 | this.currentAccelMeasurement = new SensorSample();
|
1553 | this.currentGyroMeasurement = new SensorSample();
|
1554 | this.previousGyroMeasurement = new SensorSample();
|
1555 |
|
1556 | if (Util.isIOS()) {
|
1557 | this.filterQ = new MathUtil.Quaternion(-1, 0, 0, 1);
|
1558 | } else {
|
1559 | this.filterQ = new MathUtil.Quaternion(1, 0, 0, 1);
|
1560 | }
|
1561 |
|
1562 | this.previousFilterQ = new MathUtil.Quaternion();
|
1563 | this.previousFilterQ.copy(this.filterQ);
|
1564 |
|
1565 | this.accelQ = new MathUtil.Quaternion();
|
1566 |
|
1567 | this.isOrientationInitialized = false;
|
1568 |
|
1569 | this.estimatedGravity = new MathUtil.Vector3();
|
1570 |
|
1571 | this.measuredGravity = new MathUtil.Vector3();
|
1572 |
|
1573 | this.gyroIntegralQ = new MathUtil.Quaternion();
|
1574 | }
|
1575 |
|
1576 | var __proto = ComplementaryFilter.prototype;
|
1577 |
|
1578 | __proto.addAccelMeasurement = function (vector, timestampS) {
|
1579 | this.currentAccelMeasurement.set(vector, timestampS);
|
1580 | };
|
1581 |
|
1582 | __proto.getOrientation = function () {
|
1583 | return this.filterQ;
|
1584 | };
|
1585 |
|
1586 | __proto.run_ = function () {
|
1587 | if (!this.isOrientationInitialized) {
|
1588 | this.accelQ = this.accelToQuaternion_(this.currentAccelMeasurement.sample);
|
1589 | this.previousFilterQ.copy(this.accelQ);
|
1590 | this.isOrientationInitialized = true;
|
1591 | return;
|
1592 | }
|
1593 |
|
1594 | var deltaT = this.currentGyroMeasurement.timestampS - this.previousGyroMeasurement.timestampS;
|
1595 |
|
1596 | var gyroDeltaQ = this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample, deltaT);
|
1597 | this.gyroIntegralQ.multiply(gyroDeltaQ);
|
1598 |
|
1599 | this.filterQ.copy(this.previousFilterQ);
|
1600 | this.filterQ.multiply(gyroDeltaQ);
|
1601 |
|
1602 |
|
1603 | var invFilterQ = new MathUtil.Quaternion();
|
1604 | invFilterQ.copy(this.filterQ);
|
1605 | invFilterQ.inverse();
|
1606 | this.estimatedGravity.set(0, 0, -1);
|
1607 | this.estimatedGravity.applyQuaternion(invFilterQ);
|
1608 | this.estimatedGravity.normalize();
|
1609 | this.measuredGravity.copy(this.currentAccelMeasurement.sample);
|
1610 | this.measuredGravity.normalize();
|
1611 |
|
1612 |
|
1613 | var deltaQ = new MathUtil.Quaternion();
|
1614 | deltaQ.setFromUnitVectors(this.estimatedGravity, this.measuredGravity);
|
1615 | deltaQ.inverse();
|
1616 |
|
1617 | if (Util.isDebug()) {
|
1618 | console.log("Delta: %d deg, G_est: (%s, %s, %s), G_meas: (%s, %s, %s)", MathUtil.radToDeg * Util.getQuaternionAngle(deltaQ), this.estimatedGravity.x.toFixed(1), this.estimatedGravity.y.toFixed(1), this.estimatedGravity.z.toFixed(1), this.measuredGravity.x.toFixed(1), this.measuredGravity.y.toFixed(1), this.measuredGravity.z.toFixed(1));
|
1619 | }
|
1620 |
|
1621 |
|
1622 |
|
1623 | var targetQ = new MathUtil.Quaternion();
|
1624 | targetQ.copy(this.filterQ);
|
1625 | targetQ.multiply(deltaQ);
|
1626 |
|
1627 | this.filterQ.slerp(targetQ, 1 - this.kFilter);
|
1628 | this.previousFilterQ.copy(this.filterQ);
|
1629 | };
|
1630 |
|
1631 | __proto.accelToQuaternion_ = function (accel) {
|
1632 | var normAccel = new MathUtil.Vector3();
|
1633 | normAccel.copy(accel);
|
1634 | normAccel.normalize();
|
1635 | var quat = new MathUtil.Quaternion();
|
1636 | quat.setFromUnitVectors(new MathUtil.Vector3(0, 0, -1), normAccel);
|
1637 | quat.inverse();
|
1638 | return quat;
|
1639 | };
|
1640 |
|
1641 | __proto.gyroToQuaternionDelta_ = function (gyro, dt) {
|
1642 |
|
1643 | var quat = new MathUtil.Quaternion();
|
1644 | var axis = new MathUtil.Vector3();
|
1645 | axis.copy(gyro);
|
1646 | axis.normalize();
|
1647 | quat.setFromAxisAngle(axis, gyro.length() * dt);
|
1648 | return quat;
|
1649 | };
|
1650 |
|
1651 | return ComplementaryFilter;
|
1652 | }();
|
1653 |
|
1654 | ComplementaryFilter.prototype.run_ = function () {
|
1655 | if (!this.isOrientationInitialized) {
|
1656 | this.accelQ = this.accelToQuaternion_(this.currentAccelMeasurement.sample);
|
1657 | this.previousFilterQ.copy(this.accelQ);
|
1658 | this.isOrientationInitialized = true;
|
1659 | return;
|
1660 | }
|
1661 |
|
1662 | var deltaT = this.currentGyroMeasurement.timestampS - this.previousGyroMeasurement.timestampS;
|
1663 |
|
1664 | var gyroDeltaQ = this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample, deltaT);
|
1665 | this.gyroIntegralQ.multiply(gyroDeltaQ);
|
1666 |
|
1667 | this.filterQ.copy(this.previousFilterQ);
|
1668 | this.filterQ.multiply(gyroDeltaQ);
|
1669 |
|
1670 |
|
1671 | var invFilterQ = new MathUtil.Quaternion();
|
1672 | invFilterQ.copy(this.filterQ);
|
1673 | invFilterQ.inverse();
|
1674 | this.estimatedGravity.set(0, 0, -1);
|
1675 | this.estimatedGravity.applyQuaternion(invFilterQ);
|
1676 | this.estimatedGravity.normalize();
|
1677 | this.measuredGravity.copy(this.currentAccelMeasurement.sample);
|
1678 | this.measuredGravity.normalize();
|
1679 |
|
1680 |
|
1681 | var deltaQ = new MathUtil.Quaternion();
|
1682 | deltaQ.setFromUnitVectors(this.estimatedGravity, this.measuredGravity);
|
1683 | deltaQ.inverse();
|
1684 |
|
1685 |
|
1686 | var targetQ = new MathUtil.Quaternion();
|
1687 | targetQ.copy(this.filterQ);
|
1688 | targetQ.multiply(deltaQ);
|
1689 |
|
1690 | this.filterQ.slerp(targetQ, 1 - this.kFilter);
|
1691 | this.previousFilterQ.copy(this.filterQ);
|
1692 |
|
1693 | if (!this.isFilterQuaternionInitialized) {
|
1694 | this.isFilterQuaternionInitialized = true;
|
1695 | }
|
1696 | };
|
1697 |
|
1698 | ComplementaryFilter.prototype.getOrientation = function () {
|
1699 | if (this.isFilterQuaternionInitialized) {
|
1700 | return this.filterQ;
|
1701 | } else {
|
1702 | return null;
|
1703 | }
|
1704 | };
|
1705 |
|
1706 | var K_FILTER = 0.98;
|
1707 | var PREDICTION_TIME_S = 0.040;
|
1708 |
|
1709 | var FusionPoseSensor =
|
1710 |
|
1711 | function (_super) {
|
1712 | __extends(FusionPoseSensor, _super);
|
1713 |
|
1714 | function FusionPoseSensor() {
|
1715 | var _this = _super.call(this) || this;
|
1716 |
|
1717 | _this.deviceMotion = new DeviceMotion();
|
1718 | _this.accelerometer = new MathUtil.Vector3();
|
1719 | _this.gyroscope = new MathUtil.Vector3();
|
1720 | _this._onDeviceMotionChange = _this._onDeviceMotionChange.bind(_this);
|
1721 | _this._onScreenOrientationChange = _this._onScreenOrientationChange.bind(_this);
|
1722 | _this.filter = new ComplementaryFilter(K_FILTER);
|
1723 | _this.posePredictor = new PosePredictor(PREDICTION_TIME_S);
|
1724 | _this.filterToWorldQ = new MathUtil.Quaternion();
|
1725 | _this.isFirefoxAndroid = Util.isFirefoxAndroid();
|
1726 |
|
1727 | _this.isIOS = IS_IOS || IS_SAFARI_ON_DESKTOP;
|
1728 |
|
1729 | _this.isChromeUsingDegrees = CHROME_VERSION >= 66;
|
1730 | _this._isEnabled = false;
|
1731 |
|
1732 | if (_this.isIOS) {
|
1733 | _this.filterToWorldQ.setFromAxisAngle(new MathUtil.Vector3(1, 0, 0), Math.PI / 2);
|
1734 | } else {
|
1735 | _this.filterToWorldQ.setFromAxisAngle(new MathUtil.Vector3(1, 0, 0), -Math.PI / 2);
|
1736 | }
|
1737 |
|
1738 | _this.inverseWorldToScreenQ = new MathUtil.Quaternion();
|
1739 | _this.worldToScreenQ = new MathUtil.Quaternion();
|
1740 | _this.originalPoseAdjustQ = new MathUtil.Quaternion();
|
1741 |
|
1742 | _this.originalPoseAdjustQ.setFromAxisAngle(new MathUtil.Vector3(0, 0, 1), -win.orientation * Math.PI / 180);
|
1743 |
|
1744 | _this._setScreenTransform();
|
1745 |
|
1746 |
|
1747 | if (Util.isLandscapeMode()) {
|
1748 | _this.filterToWorldQ.multiply(_this.inverseWorldToScreenQ);
|
1749 | }
|
1750 |
|
1751 |
|
1752 | _this.resetQ = new MathUtil.Quaternion();
|
1753 |
|
1754 | _this.deviceMotion.on("devicemotion", _this._onDeviceMotionChange);
|
1755 |
|
1756 | _this.enable();
|
1757 |
|
1758 | return _this;
|
1759 | }
|
1760 |
|
1761 | var __proto = FusionPoseSensor.prototype;
|
1762 |
|
1763 | __proto.enable = function () {
|
1764 | if (this.isEnabled()) {
|
1765 | return;
|
1766 | }
|
1767 |
|
1768 | this.deviceMotion.enable();
|
1769 | this._isEnabled = true;
|
1770 | win.addEventListener("orientationchange", this._onScreenOrientationChange);
|
1771 | };
|
1772 |
|
1773 | __proto.disable = function () {
|
1774 | if (!this.isEnabled()) {
|
1775 | return;
|
1776 | }
|
1777 |
|
1778 | this.deviceMotion.disable();
|
1779 | this._isEnabled = false;
|
1780 | win.removeEventListener("orientationchange", this._onScreenOrientationChange);
|
1781 | };
|
1782 |
|
1783 | __proto.isEnabled = function () {
|
1784 | return this._isEnabled;
|
1785 | };
|
1786 |
|
1787 | __proto.destroy = function () {
|
1788 | this.disable();
|
1789 | this.deviceMotion = null;
|
1790 | };
|
1791 |
|
1792 | __proto.getOrientation = function () {
|
1793 | var _this = this;
|
1794 |
|
1795 | var orientation;
|
1796 |
|
1797 | if (this.deviceMotion.isWithoutDeviceMotion && this._deviceOrientationQ) {
|
1798 | this.deviceOrientationFixQ = this.deviceOrientationFixQ || function () {
|
1799 | var y = new MathUtil.Quaternion().setFromAxisAngle(new MathUtil.Vector3(0, 1, 0), -_this._alpha);
|
1800 | return y;
|
1801 | }();
|
1802 |
|
1803 | orientation = this._deviceOrientationQ;
|
1804 | var out = new MathUtil.Quaternion();
|
1805 | out.copy(orientation);
|
1806 | out.multiply(this.filterToWorldQ);
|
1807 | out.multiply(this.resetQ);
|
1808 | out.multiply(this.worldToScreenQ);
|
1809 | out.multiplyQuaternions(this.deviceOrientationFixQ, out);
|
1810 |
|
1811 | var outQuat = glMatrix.quat.fromValues(out.x, out.y, out.z, out.w);
|
1812 | return glMatrix.quat.normalize(outQuat, outQuat);
|
1813 | } else {
|
1814 |
|
1815 |
|
1816 | orientation = this.filter.getOrientation();
|
1817 |
|
1818 | if (!orientation) {
|
1819 | return null;
|
1820 | }
|
1821 |
|
1822 | var out = this._convertFusionToPredicted(orientation);
|
1823 |
|
1824 |
|
1825 | var outQuat = glMatrix.quat.fromValues(out.x, out.y, out.z, out.w);
|
1826 | return glMatrix.quat.normalize(outQuat, outQuat);
|
1827 | }
|
1828 | };
|
1829 |
|
1830 | __proto._triggerChange = function () {
|
1831 | var orientation = this.getOrientation();
|
1832 |
|
1833 | if (!orientation) {
|
1834 | return;
|
1835 | }
|
1836 |
|
1837 | if (!this._prevOrientation) {
|
1838 | this._prevOrientation = orientation;
|
1839 | return;
|
1840 | }
|
1841 |
|
1842 | if (glMatrix.quat.equals(this._prevOrientation, orientation)) {
|
1843 | return;
|
1844 | }
|
1845 |
|
1846 | this.trigger(new Component.ComponentEvent("change", {
|
1847 | quaternion: orientation
|
1848 | }));
|
1849 | };
|
1850 |
|
1851 | __proto._convertFusionToPredicted = function (orientation) {
|
1852 |
|
1853 | this.predictedQ = this.posePredictor.getPrediction(orientation, this.gyroscope, this.previousTimestampS);
|
1854 |
|
1855 | var out = new MathUtil.Quaternion();
|
1856 | out.copy(this.filterToWorldQ);
|
1857 | out.multiply(this.resetQ);
|
1858 | out.multiply(this.predictedQ);
|
1859 | out.multiply(this.worldToScreenQ);
|
1860 | return out;
|
1861 | };
|
1862 |
|
1863 | __proto._onDeviceMotionChange = function (_a) {
|
1864 | var inputEvent = _a.inputEvent;
|
1865 | var deviceorientation = inputEvent.deviceorientation;
|
1866 | var deviceMotion = inputEvent;
|
1867 | var accGravity = deviceMotion.accelerationIncludingGravity;
|
1868 | var rotRate = deviceMotion.adjustedRotationRate || deviceMotion.rotationRate;
|
1869 | var timestampS = deviceMotion.timeStamp / 1000;
|
1870 |
|
1871 | if (deviceorientation) {
|
1872 | if (!this._alpha) {
|
1873 | this._alpha = deviceorientation.alpha;
|
1874 | }
|
1875 |
|
1876 | this._deviceOrientationQ = this._deviceOrientationQ || new MathUtil.Quaternion();
|
1877 |
|
1878 | this._deviceOrientationQ.setFromEulerYXZ(deviceorientation.beta, deviceorientation.alpha, deviceorientation.gamma);
|
1879 |
|
1880 | this._triggerChange();
|
1881 | } else {
|
1882 |
|
1883 | if (this.isFirefoxAndroid) {
|
1884 | timestampS /= 1000;
|
1885 | }
|
1886 |
|
1887 | this.accelerometer.set(-accGravity.x, -accGravity.y, -accGravity.z);
|
1888 | this.gyroscope.set(rotRate.alpha, rotRate.beta, rotRate.gamma);
|
1889 |
|
1890 |
|
1891 | if (this.isIOS || this.isFirefoxAndroid || this.isChromeUsingDegrees) {
|
1892 | this.gyroscope.multiplyScalar(Math.PI / 180);
|
1893 | }
|
1894 |
|
1895 | this.filter.addAccelMeasurement(this.accelerometer, timestampS);
|
1896 | this.filter.addGyroMeasurement(this.gyroscope, timestampS);
|
1897 |
|
1898 | this._triggerChange();
|
1899 |
|
1900 | this.previousTimestampS = timestampS;
|
1901 | }
|
1902 | };
|
1903 |
|
1904 | __proto._onScreenOrientationChange = function () {
|
1905 | this._setScreenTransform();
|
1906 | };
|
1907 |
|
1908 | __proto._setScreenTransform = function () {
|
1909 | this.worldToScreenQ.set(0, 0, 0, 1);
|
1910 | var orientation = win.orientation;
|
1911 |
|
1912 | switch (orientation) {
|
1913 | case 0:
|
1914 | break;
|
1915 |
|
1916 | case 90:
|
1917 | case -90:
|
1918 | case 180:
|
1919 | this.worldToScreenQ.setFromAxisAngle(new MathUtil.Vector3(0, 0, 1), orientation / -180 * Math.PI);
|
1920 | break;
|
1921 | }
|
1922 |
|
1923 | this.inverseWorldToScreenQ.copy(this.worldToScreenQ);
|
1924 | this.inverseWorldToScreenQ.inverse();
|
1925 | };
|
1926 |
|
1927 | return FusionPoseSensor;
|
1928 | }(Component);
|
1929 |
|
1930 | var getDeltaYaw = function (prvQ, curQ) {
|
1931 | var yawDeltaByYaw = util.getRotationDelta(prvQ, curQ, ROTATE_CONSTANT.YAW_DELTA_BY_YAW);
|
1932 | var yawDeltaByRoll = util.getRotationDelta(prvQ, curQ, ROTATE_CONSTANT.YAW_DELTA_BY_ROLL) * Math.sin(util.extractPitchFromQuat(curQ));
|
1933 | return yawDeltaByRoll + yawDeltaByYaw;
|
1934 | };
|
1935 |
|
1936 | var getDeltaPitch = function (prvQ, curQ) {
|
1937 | var pitchDelta = util.getRotationDelta(prvQ, curQ, ROTATE_CONSTANT.PITCH_DELTA);
|
1938 | return pitchDelta;
|
1939 | };
|
1940 |
|
1941 |
|
1942 | var TiltMotionInput =
|
1943 |
|
1944 | function (_super) {
|
1945 | __extends(TiltMotionInput, _super);
|
1946 |
|
1947 | function TiltMotionInput(el, options) {
|
1948 | if (options === void 0) {
|
1949 | options = {};
|
1950 | }
|
1951 |
|
1952 | var _this = _super.call(this) || this;
|
1953 |
|
1954 | _this.element = el;
|
1955 | _this._prevQuaternion = null;
|
1956 | _this._quaternion = null;
|
1957 | _this.fusionPoseSensor = null;
|
1958 | _this.options = __assign({
|
1959 | scale: 1,
|
1960 | threshold: 0
|
1961 | }, options);
|
1962 | _this._onPoseChange = _this._onPoseChange.bind(_this);
|
1963 | return _this;
|
1964 | }
|
1965 |
|
1966 | var __proto = TiltMotionInput.prototype;
|
1967 |
|
1968 | __proto.mapAxes = function (axes) {
|
1969 | this.axes = axes;
|
1970 | };
|
1971 |
|
1972 | __proto.connect = function (observer) {
|
1973 | if (this.observer) {
|
1974 | return this;
|
1975 | }
|
1976 |
|
1977 | this.observer = observer;
|
1978 | this.fusionPoseSensor = new FusionPoseSensor();
|
1979 | this.fusionPoseSensor.enable();
|
1980 |
|
1981 | this._attachEvent();
|
1982 |
|
1983 | return this;
|
1984 | };
|
1985 |
|
1986 | __proto.disconnect = function () {
|
1987 | if (!this.observer) {
|
1988 | return this;
|
1989 | }
|
1990 |
|
1991 | this._dettachEvent();
|
1992 |
|
1993 | this.fusionPoseSensor.disable();
|
1994 | this.fusionPoseSensor.destroy();
|
1995 | this.fusionPoseSensor = null;
|
1996 | this.observer = null;
|
1997 | return this;
|
1998 | };
|
1999 |
|
2000 | __proto.destroy = function () {
|
2001 | this.disconnect();
|
2002 | this.element = null;
|
2003 | this.options = null;
|
2004 | this.axes = null;
|
2005 | this._prevQuaternion = null;
|
2006 | this._quaternion = null;
|
2007 | };
|
2008 |
|
2009 | __proto._onPoseChange = function (event) {
|
2010 | if (!this._prevQuaternion) {
|
2011 | this._prevQuaternion = glMatrix.quat.clone(event.quaternion);
|
2012 | this._quaternion = glMatrix.quat.clone(event.quaternion);
|
2013 | return;
|
2014 | }
|
2015 |
|
2016 | glMatrix.quat.copy(this._prevQuaternion, this._quaternion);
|
2017 | glMatrix.quat.copy(this._quaternion, event.quaternion);
|
2018 | this.observer.change(this, event, toAxis(this.axes, [getDeltaYaw(this._prevQuaternion, this._quaternion), getDeltaPitch(this._prevQuaternion, this._quaternion)]));
|
2019 | };
|
2020 |
|
2021 | __proto._attachEvent = function () {
|
2022 | this.fusionPoseSensor.on("change", this._onPoseChange);
|
2023 | };
|
2024 |
|
2025 | __proto._dettachEvent = function () {
|
2026 | this.fusionPoseSensor.off("change", this._onPoseChange);
|
2027 | };
|
2028 |
|
2029 | return TiltMotionInput;
|
2030 | }(Component);
|
2031 |
|
2032 | var screenRotationAngleInst = null;
|
2033 | var refCount = 0;
|
2034 |
|
2035 | var ScreenRotationAngle =
|
2036 |
|
2037 | function () {
|
2038 | function ScreenRotationAngle() {
|
2039 | refCount++;
|
2040 |
|
2041 | if (screenRotationAngleInst) {
|
2042 | return screenRotationAngleInst;
|
2043 | }
|
2044 |
|
2045 |
|
2046 |
|
2047 | screenRotationAngleInst = this;
|
2048 |
|
2049 |
|
2050 | this._onDeviceOrientation = this._onDeviceOrientation.bind(this);
|
2051 | this._onOrientationChange = this._onOrientationChange.bind(this);
|
2052 | this._spinR = 0;
|
2053 | this._screenOrientationAngle = 0;
|
2054 | win.addEventListener("deviceorientation", this._onDeviceOrientation);
|
2055 | win.addEventListener("orientationchange", this._onOrientationChange);
|
2056 | }
|
2057 |
|
2058 | var __proto = ScreenRotationAngle.prototype;
|
2059 |
|
2060 | __proto.getRadian = function () {
|
2061 |
|
2062 |
|
2063 | return this._spinR + glMatrix.glMatrix.toRadian(this._screenOrientationAngle);
|
2064 | };
|
2065 |
|
2066 | __proto.unref = function () {
|
2067 | if (--refCount > 0) {
|
2068 | return;
|
2069 | }
|
2070 |
|
2071 | win.removeEventListener("deviceorientation", this._onDeviceOrientation);
|
2072 | win.removeEventListener("orientationchange", this._onOrientationChange);
|
2073 | this._spinR = 0;
|
2074 | this._screenOrientationAngle = 0;
|
2075 |
|
2076 |
|
2077 | screenRotationAngleInst = null;
|
2078 |
|
2079 |
|
2080 | refCount = 0;
|
2081 | };
|
2082 |
|
2083 | __proto._onDeviceOrientation = function (e) {
|
2084 | if (e.beta === null || e.gamma === null) {
|
2085 |
|
2086 | return;
|
2087 | }
|
2088 |
|
2089 |
|
2090 | var betaR = glMatrix.glMatrix.toRadian(e.beta);
|
2091 | var gammaR = glMatrix.glMatrix.toRadian(e.gamma);
|
2092 |
|
2093 |
|
2094 | this._spinR = Math.atan2(Math.cos(betaR) * Math.sin(gammaR), Math.sin(betaR));
|
2095 | };
|
2096 |
|
2097 | __proto._onOrientationChange = function () {
|
2098 | if (win.screen && win.screen.orientation && win.screen.orientation.angle !== undefined) {
|
2099 | this._screenOrientationAngle = screen.orientation.angle;
|
2100 | } else if (win.orientation !== undefined) {
|
2101 |
|
2102 | this._screenOrientationAngle = win.orientation >= 0 ? win.orientation : 360 + win.orientation;
|
2103 | }
|
2104 | };
|
2105 |
|
2106 | return ScreenRotationAngle;
|
2107 | }();
|
2108 |
|
2109 | |
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 |
|
2120 | var RotationPanInput =
|
2121 |
|
2122 | function (_super) {
|
2123 | __extends(RotationPanInput, _super);
|
2124 | |
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 | function RotationPanInput(el, options) {
|
2134 | if (options === void 0) {
|
2135 | options = {};
|
2136 | }
|
2137 |
|
2138 | var _this = _super.call(this, el, options) || this;
|
2139 |
|
2140 | _this._useRotation = false;
|
2141 | _this._screenRotationAngle = null;
|
2142 |
|
2143 | _this.setUseRotation(!!(options && options.useRotation));
|
2144 |
|
2145 | _this._userDirection = Axes.DIRECTION_ALL;
|
2146 | return _this;
|
2147 | }
|
2148 |
|
2149 | var __proto = RotationPanInput.prototype;
|
2150 |
|
2151 | __proto.setUseRotation = function (useRotation) {
|
2152 | this._useRotation = useRotation;
|
2153 |
|
2154 | if (this._screenRotationAngle) {
|
2155 | this._screenRotationAngle.unref();
|
2156 |
|
2157 | this._screenRotationAngle = null;
|
2158 | }
|
2159 |
|
2160 | if (this._useRotation) {
|
2161 | this._screenRotationAngle = new ScreenRotationAngle();
|
2162 | }
|
2163 | };
|
2164 |
|
2165 | __proto.connect = function (observer) {
|
2166 |
|
2167 | this._userDirection = this._direction;
|
2168 |
|
2169 |
|
2170 |
|
2171 | if (this._useRotation && this._direction & Axes.DIRECTION_ALL) {
|
2172 | this._direction = Axes.DIRECTION_HORIZONTAL;
|
2173 | }
|
2174 |
|
2175 | return _super.prototype.connect.call(this, observer);
|
2176 | };
|
2177 |
|
2178 | __proto.destroy = function () {
|
2179 | if (this._useRotation && this._screenRotationAngle) {
|
2180 | this._screenRotationAngle.unref();
|
2181 | }
|
2182 |
|
2183 | _super.prototype.destroy.call(this);
|
2184 | };
|
2185 |
|
2186 |
|
2187 | __proto.getOffset = function (properties, useDirection) {
|
2188 | if (this._useRotation === false) {
|
2189 |
|
2190 | return _super.prototype.getOffset.call(this, properties, useDirection);
|
2191 | }
|
2192 |
|
2193 |
|
2194 | var offset = _super.prototype.getOffset.call(this, properties, [true, true]);
|
2195 |
|
2196 | var newOffset = [0, 0];
|
2197 |
|
2198 | var theta = this._screenRotationAngle.getRadian();
|
2199 |
|
2200 | var cosTheta = Math.cos(theta);
|
2201 | var sinTheta = Math.sin(theta);
|
2202 |
|
2203 | newOffset[0] = offset[0] * cosTheta - offset[1] * sinTheta;
|
2204 | newOffset[1] = offset[1] * cosTheta + offset[0] * sinTheta;
|
2205 |
|
2206 | if (!(this._userDirection & Axes.DIRECTION_HORIZONTAL)) {
|
2207 | newOffset[0] = 0;
|
2208 | } else if (!(this._userDirection & Axes.DIRECTION_VERTICAL)) {
|
2209 | newOffset[1] = 0;
|
2210 | }
|
2211 |
|
2212 | return newOffset;
|
2213 | };
|
2214 |
|
2215 | return RotationPanInput;
|
2216 | }(Axes.PanInput);
|
2217 | |
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 | var Y_AXIS_VECTOR = glMatrix.vec3.fromValues(0, 1, 0);
|
2228 |
|
2229 | var DeviceQuaternion =
|
2230 |
|
2231 | function (_super) {
|
2232 | __extends(DeviceQuaternion, _super);
|
2233 |
|
2234 | function DeviceQuaternion() {
|
2235 | var _this = _super.call(this) || this;
|
2236 |
|
2237 | _this._fusionPoseSensor = new FusionPoseSensor();
|
2238 | _this._quaternion = glMatrix.quat.create();
|
2239 |
|
2240 | _this._fusionPoseSensor.enable();
|
2241 |
|
2242 | _this._fusionPoseSensor.on("change", function (e) {
|
2243 | _this._quaternion = e.quaternion;
|
2244 |
|
2245 | _this.trigger(new Component.ComponentEvent("change", {
|
2246 | isTrusted: true
|
2247 | }));
|
2248 | });
|
2249 |
|
2250 | return _this;
|
2251 | }
|
2252 |
|
2253 | var __proto = DeviceQuaternion.prototype;
|
2254 |
|
2255 | __proto.getCombinedQuaternion = function (yaw) {
|
2256 | var yawQ = glMatrix.quat.setAxisAngle(glMatrix.quat.create(), Y_AXIS_VECTOR, glMatrix.glMatrix.toRadian(-yaw));
|
2257 | var conj = glMatrix.quat.conjugate(glMatrix.quat.create(), this._quaternion);
|
2258 |
|
2259 | var outQ = glMatrix.quat.multiply(glMatrix.quat.create(), conj, yawQ);
|
2260 | return outQ;
|
2261 | };
|
2262 |
|
2263 | __proto.destroy = function () {
|
2264 |
|
2265 | this.off();
|
2266 |
|
2267 | if (this._fusionPoseSensor) {
|
2268 | this._fusionPoseSensor.off();
|
2269 |
|
2270 | this._fusionPoseSensor.destroy();
|
2271 |
|
2272 | this._fusionPoseSensor = null;
|
2273 | }
|
2274 | };
|
2275 |
|
2276 | return DeviceQuaternion;
|
2277 | }(Component);
|
2278 |
|
2279 | var DEFAULT_YAW_RANGE = [-YAW_RANGE_HALF, YAW_RANGE_HALF];
|
2280 | var DEFAULT_PITCH_RANGE = [-PITCH_RANGE_HALF, PITCH_RANGE_HALF];
|
2281 | var CIRCULAR_PITCH_RANGE = [-CIRCULAR_PITCH_RANGE_HALF, CIRCULAR_PITCH_RANGE_HALF];
|
2282 | |
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 |
|
2290 | var YawPitchControl =
|
2291 |
|
2292 | function (_super) {
|
2293 | __extends(YawPitchControl, _super);
|
2294 | |
2295 |
|
2296 |
|
2297 |
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 |
|
2311 |
|
2312 | function YawPitchControl(options) {
|
2313 | var _this = _super.call(this) || this;
|
2314 |
|
2315 | _this.options = {};
|
2316 |
|
2317 | var opt = __assign({
|
2318 | element: null,
|
2319 | yaw: 0,
|
2320 | pitch: 0,
|
2321 | fov: 65,
|
2322 | showPolePoint: false,
|
2323 | useZoom: true,
|
2324 | useKeyboard: true,
|
2325 | gyroMode: GYRO_MODE.YAWPITCH,
|
2326 | touchDirection: TOUCH_DIRECTION_ALL,
|
2327 | yawRange: DEFAULT_YAW_RANGE,
|
2328 | pitchRange: DEFAULT_PITCH_RANGE,
|
2329 | fovRange: [30, 110],
|
2330 | aspectRatio: 1
|
2331 |
|
2332 |
|
2333 | }, options);
|
2334 |
|
2335 | _this._element = opt.element;
|
2336 | _this._initialFov = opt.fov;
|
2337 | _this._enabled = false;
|
2338 | _this._isAnimating = false;
|
2339 | _this._deviceQuaternion = null;
|
2340 |
|
2341 | _this._initAxes(opt);
|
2342 |
|
2343 | _this.option(opt);
|
2344 |
|
2345 | return _this;
|
2346 | }
|
2347 | |
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 |
|
2354 |
|
2355 |
|
2356 | var __proto = YawPitchControl.prototype;
|
2357 |
|
2358 | __proto.updatePanScale = function (param) {
|
2359 | if (param === void 0) {
|
2360 | param = {};
|
2361 | }
|
2362 |
|
2363 | var fov = this._axes.get().fov;
|
2364 |
|
2365 | var areaHeight = param.height || parseInt(window.getComputedStyle(this._element).height, 10);
|
2366 | var scale = MC_BIND_SCALE[0] * fov / this._initialFov * PAN_SCALE / areaHeight;
|
2367 | this._axesPanInput.options.scale = [scale, scale];
|
2368 | this._axes.options.deceleration = MC_DECELERATION * fov / MAX_FIELD_OF_VIEW;
|
2369 | return this;
|
2370 | };
|
2371 | |
2372 |
|
2373 |
|
2374 |
|
2375 |
|
2376 |
|
2377 |
|
2378 |
|
2379 | __proto.option = function (key, newValue) {
|
2380 |
|
2381 | if (!key) {
|
2382 | return this._getOptions();
|
2383 | } else if (key && typeof key === "string" && typeof newValue === "undefined") {
|
2384 | return this._getOptions(key);
|
2385 | }
|
2386 |
|
2387 |
|
2388 | var newOptions = {};
|
2389 | var changedKeyList = [];
|
2390 |
|
2391 | if (typeof key === "string") {
|
2392 | changedKeyList.push(key);
|
2393 | newOptions[key] = newValue;
|
2394 | } else {
|
2395 | var options = key;
|
2396 |
|
2397 | changedKeyList = Object.keys(options);
|
2398 | newOptions = __assign({}, options);
|
2399 | }
|
2400 |
|
2401 | this._setOptions(this._getValidatedOptions(newOptions));
|
2402 |
|
2403 | this._applyOptions(changedKeyList);
|
2404 |
|
2405 | return this;
|
2406 | };
|
2407 | |
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 | __proto.enable = function () {
|
2414 | if (this._enabled) {
|
2415 | return this;
|
2416 | }
|
2417 |
|
2418 | this._enabled = true;
|
2419 |
|
2420 | this._applyOptions(Object.keys(this.options));
|
2421 |
|
2422 |
|
2423 | this.updatePanScale();
|
2424 | return this;
|
2425 | };
|
2426 | |
2427 |
|
2428 |
|
2429 |
|
2430 |
|
2431 |
|
2432 | __proto.disable = function (persistOrientation) {
|
2433 | if (persistOrientation === void 0) {
|
2434 | persistOrientation = false;
|
2435 | }
|
2436 |
|
2437 | if (!this._enabled) {
|
2438 | return this;
|
2439 | }
|
2440 |
|
2441 |
|
2442 | if (!persistOrientation) {
|
2443 | this._resetOrientation();
|
2444 | }
|
2445 |
|
2446 | this._axes.disconnect();
|
2447 |
|
2448 | this._enabled = false;
|
2449 | return this;
|
2450 | };
|
2451 | |
2452 |
|
2453 |
|
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 | __proto.lookAt = function (_a, duration) {
|
2459 | var yaw = _a.yaw,
|
2460 | pitch = _a.pitch,
|
2461 | fov = _a.fov;
|
2462 |
|
2463 | var pos = this._axes.get();
|
2464 |
|
2465 | var y = yaw === undefined ? 0 : yaw - pos.yaw;
|
2466 | var p = pitch === undefined ? 0 : pitch - pos.pitch;
|
2467 | var f = fov === undefined ? 0 : fov - pos.fov;
|
2468 |
|
2469 | this._axes.options.maximumDuration = Infinity;
|
2470 |
|
2471 | this._axes.setBy({
|
2472 | yaw: y,
|
2473 | pitch: p,
|
2474 | fov: f
|
2475 | }, duration);
|
2476 | };
|
2477 |
|
2478 | __proto.getYawPitch = function () {
|
2479 | var yawPitch = this._axes.get();
|
2480 |
|
2481 | return {
|
2482 | yaw: yawPitch.yaw,
|
2483 | pitch: yawPitch.pitch
|
2484 | };
|
2485 | };
|
2486 |
|
2487 | __proto.getFov = function () {
|
2488 | return this._axes.get().fov;
|
2489 | };
|
2490 |
|
2491 | __proto.getQuaternion = function () {
|
2492 | var pos = this._axes.get();
|
2493 |
|
2494 | return this._deviceQuaternion.getCombinedQuaternion(pos.yaw);
|
2495 | };
|
2496 |
|
2497 | __proto.shouldRenderWithQuaternion = function () {
|
2498 | return this.options.gyroMode === GYRO_MODE.VR;
|
2499 | };
|
2500 | |
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 | __proto.destroy = function () {
|
2506 |
|
2507 | this._axes && this._axes.destroy();
|
2508 | this._axesPanInput && this._axesPanInput.destroy();
|
2509 | this._axesWheelInput && this._axesWheelInput.destroy();
|
2510 | this._axesTiltMotionInput && this._axesTiltMotionInput.destroy();
|
2511 | this._axesPinchInput && this._axesPinchInput.destroy();
|
2512 | this._axesMoveKeyInput && this._axesMoveKeyInput.destroy();
|
2513 | this._deviceQuaternion && this._deviceQuaternion.destroy();
|
2514 |
|
2515 | };
|
2516 |
|
2517 | __proto._initAxes = function (opt) {
|
2518 | var _this = this;
|
2519 |
|
2520 | var yRange = this._updateYawRange(opt.yawRange, opt.fov, opt.aspectRatio);
|
2521 |
|
2522 | var pRange = this._updatePitchRange(opt.pitchRange, opt.fov, opt.showPolePoint);
|
2523 |
|
2524 | var useRotation = opt.gyroMode === GYRO_MODE.VR;
|
2525 | this._axesPanInput = new RotationPanInput(this._element, {
|
2526 | useRotation: useRotation
|
2527 | });
|
2528 | this._axesWheelInput = new Axes.WheelInput(this._element, {
|
2529 | scale: -4
|
2530 | });
|
2531 | this._axesTiltMotionInput = null;
|
2532 | this._axesPinchInput = SUPPORT_TOUCH ? new Axes.PinchInput(this._element, {
|
2533 | scale: -1
|
2534 | }) : null;
|
2535 | this._axesMoveKeyInput = new Axes.MoveKeyInput(this._element, {
|
2536 | scale: [-6, 6]
|
2537 | });
|
2538 | this._axes = new Axes({
|
2539 | yaw: {
|
2540 | range: yRange,
|
2541 | circular: this._isCircular(yRange),
|
2542 | bounce: [0, 0]
|
2543 | },
|
2544 | pitch: {
|
2545 | range: pRange,
|
2546 | circular: this._isCircular(pRange),
|
2547 | bounce: [0, 0]
|
2548 | },
|
2549 | fov: {
|
2550 | range: opt.fovRange,
|
2551 | circular: [false, false],
|
2552 | bounce: [0, 0]
|
2553 | }
|
2554 | }, {
|
2555 | deceleration: MC_DECELERATION,
|
2556 | maximumDuration: MC_MAXIMUM_DURATION
|
2557 | }, {
|
2558 | yaw: opt.yaw,
|
2559 | pitch: opt.pitch,
|
2560 | fov: opt.fov
|
2561 | }).on({
|
2562 |
|
2563 | hold: function (evt) {
|
2564 |
|
2565 | _this._axes.options.maximumDuration = MC_MAXIMUM_DURATION;
|
2566 |
|
2567 | _this.trigger(new Component.ComponentEvent("hold", {
|
2568 | isTrusted: evt.isTrusted
|
2569 | }));
|
2570 | },
|
2571 | change: function (evt) {
|
2572 | if (evt.delta.fov !== 0) {
|
2573 | _this._updateControlScale(evt);
|
2574 |
|
2575 | _this.updatePanScale();
|
2576 | }
|
2577 |
|
2578 | _this._triggerChange(evt);
|
2579 | },
|
2580 | release: function (evt) {
|
2581 | _this._triggerChange(evt);
|
2582 | },
|
2583 | animationEnd: function (evt) {
|
2584 | _this.trigger(new Component.ComponentEvent("animationEnd", {
|
2585 | isTrusted: evt.isTrusted
|
2586 | }));
|
2587 | }
|
2588 | });
|
2589 | };
|
2590 |
|
2591 | __proto._getValidatedOptions = function (newOptions) {
|
2592 | if (newOptions.yawRange) {
|
2593 | newOptions.yawRange = this._getValidYawRange(newOptions.yawRange, newOptions.fov, newOptions.aspectRatio);
|
2594 | }
|
2595 |
|
2596 | if (newOptions.pitchRange) {
|
2597 | newOptions.pitchRange = this._getValidPitchRange(newOptions.pitchRange, newOptions.fov);
|
2598 | }
|
2599 |
|
2600 | return newOptions;
|
2601 | };
|
2602 |
|
2603 | __proto._getOptions = function (key) {
|
2604 | var value;
|
2605 |
|
2606 | if (typeof key === "string") {
|
2607 | value = this.options[key];
|
2608 | } else if (arguments.length === 0) {
|
2609 | value = this.options;
|
2610 | }
|
2611 |
|
2612 | return value;
|
2613 | };
|
2614 |
|
2615 | __proto._setOptions = function (options) {
|
2616 | for (var key in options) {
|
2617 | this.options[key] = options[key];
|
2618 | }
|
2619 | };
|
2620 |
|
2621 | __proto._applyOptions = function (keys) {
|
2622 | var options = this.options;
|
2623 | var axes = this._axes;
|
2624 | var isVR = options.gyroMode === GYRO_MODE.VR;
|
2625 | var isYawPitch = options.gyroMode === GYRO_MODE.YAWPITCH;
|
2626 |
|
2627 | var touchDirection = isVR ? TOUCH_DIRECTION_YAW & options.touchDirection : options.touchDirection;
|
2628 |
|
2629 | if (keys.some(function (key) {
|
2630 | return key === "showPolePoint" || key === "fov" || key === "aspectRatio" || key === "yawRange" || key === "pitchRange";
|
2631 | })) {
|
2632 |
|
2633 | if (keys.indexOf("fov") >= 0) {
|
2634 | axes.setTo({
|
2635 | "fov": options.fov
|
2636 | });
|
2637 | this.updatePanScale();
|
2638 | }
|
2639 |
|
2640 | this._updateControlScale();
|
2641 | }
|
2642 |
|
2643 | if (keys.some(function (key) {
|
2644 | return key === "fovRange";
|
2645 | })) {
|
2646 | var fovRange = options.fovRange;
|
2647 | var prevFov = axes.get().fov;
|
2648 | var nextFov = axes.get().fov;
|
2649 | glMatrix.vec2.copy(axes.axis.fov.range, fovRange);
|
2650 |
|
2651 | if (nextFov < fovRange[0]) {
|
2652 | nextFov = fovRange[0];
|
2653 | } else if (prevFov > fovRange[1]) {
|
2654 | nextFov = fovRange[1];
|
2655 | }
|
2656 |
|
2657 | if (prevFov !== nextFov) {
|
2658 | axes.setTo({
|
2659 | fov: nextFov
|
2660 | }, 0);
|
2661 |
|
2662 | this._updateControlScale();
|
2663 |
|
2664 | this.updatePanScale();
|
2665 | }
|
2666 | }
|
2667 |
|
2668 | if (keys.some(function (key) {
|
2669 | return key === "gyroMode";
|
2670 | }) && SUPPORT_DEVICEMOTION) {
|
2671 |
|
2672 | if (this._axesTiltMotionInput) {
|
2673 | this._axes.disconnect(this._axesTiltMotionInput);
|
2674 |
|
2675 | this._axesTiltMotionInput.destroy();
|
2676 |
|
2677 | this._axesTiltMotionInput = null;
|
2678 | }
|
2679 |
|
2680 | if (this._deviceQuaternion) {
|
2681 | this._deviceQuaternion.destroy();
|
2682 |
|
2683 | this._deviceQuaternion = null;
|
2684 | }
|
2685 |
|
2686 | if (isVR) {
|
2687 | this._initDeviceQuaternion();
|
2688 | } else if (isYawPitch) {
|
2689 | this._axesTiltMotionInput = new TiltMotionInput(this._element);
|
2690 |
|
2691 | this._axes.connect(["yaw", "pitch"], this._axesTiltMotionInput);
|
2692 | }
|
2693 |
|
2694 | this._axesPanInput.setUseRotation(isVR);
|
2695 | }
|
2696 |
|
2697 | if (keys.some(function (key) {
|
2698 | return key === "useKeyboard";
|
2699 | })) {
|
2700 | var useKeyboard = options.useKeyboard;
|
2701 |
|
2702 | if (useKeyboard) {
|
2703 | axes.connect(["yaw", "pitch"], this._axesMoveKeyInput);
|
2704 | } else {
|
2705 | axes.disconnect(this._axesMoveKeyInput);
|
2706 | }
|
2707 | }
|
2708 |
|
2709 | if (keys.some(function (key) {
|
2710 | return key === "useZoom";
|
2711 | })) {
|
2712 | var useZoom = options.useZoom;
|
2713 |
|
2714 | axes.disconnect(this._axesWheelInput);
|
2715 |
|
2716 | if (useZoom) {
|
2717 | axes.connect(["fov"], this._axesWheelInput);
|
2718 | }
|
2719 | }
|
2720 |
|
2721 | this._togglePinchInputByOption(options.touchDirection, options.useZoom);
|
2722 |
|
2723 | if (keys.some(function (key) {
|
2724 | return key === "touchDirection";
|
2725 | }) && this._enabled) {
|
2726 | this._enableTouch(touchDirection);
|
2727 | }
|
2728 | };
|
2729 |
|
2730 | __proto._togglePinchInputByOption = function (touchDirection, useZoom) {
|
2731 | if (this._axesPinchInput) {
|
2732 |
|
2733 | this._axes.disconnect(this._axesPinchInput);
|
2734 |
|
2735 |
|
2736 | if (useZoom && touchDirection === TOUCH_DIRECTION_ALL &&
|
2737 | this._axes._inputs.indexOf(this._axesPinchInput) === -1) {
|
2738 | this._axes.connect(["fov"], this._axesPinchInput);
|
2739 | }
|
2740 | }
|
2741 | };
|
2742 |
|
2743 | __proto._enableTouch = function (direction) {
|
2744 |
|
2745 | if (this._axesPanInput) {
|
2746 | this._axes.disconnect(this._axesPanInput);
|
2747 | }
|
2748 |
|
2749 | var yawEnabled = direction & TOUCH_DIRECTION_YAW ? "yaw" : null;
|
2750 | var pitchEnabled = direction & TOUCH_DIRECTION_PITCH ? "pitch" : null;
|
2751 |
|
2752 | this._axes.connect([yawEnabled, pitchEnabled], this._axesPanInput);
|
2753 | };
|
2754 |
|
2755 | __proto._initDeviceQuaternion = function () {
|
2756 | var _this = this;
|
2757 |
|
2758 | this._deviceQuaternion = new DeviceQuaternion();
|
2759 |
|
2760 | this._deviceQuaternion.on("change", function (e) {
|
2761 | _this._triggerChange(e);
|
2762 | });
|
2763 | };
|
2764 |
|
2765 | __proto._getValidYawRange = function (newYawRange, newFov, newAspectRatio) {
|
2766 | var ratio = this._adjustAspectRatio(newAspectRatio || this.options.aspectRatio || 1);
|
2767 |
|
2768 | var fov = newFov || this._axes.get().fov;
|
2769 |
|
2770 | var horizontalFov = fov * ratio;
|
2771 | var isValid = newYawRange[1] - newYawRange[0] >= horizontalFov;
|
2772 |
|
2773 | if (isValid) {
|
2774 | return newYawRange;
|
2775 | } else {
|
2776 | return this.options.yawRange || DEFAULT_YAW_RANGE;
|
2777 | }
|
2778 | };
|
2779 |
|
2780 | __proto._getValidPitchRange = function (newPitchRange, newFov) {
|
2781 | var fov = newFov || this._axes.get().fov;
|
2782 |
|
2783 | var isValid = newPitchRange[1] - newPitchRange[0] >= fov;
|
2784 |
|
2785 | if (isValid) {
|
2786 | return newPitchRange;
|
2787 | } else {
|
2788 | return this.options.pitchRange || DEFAULT_PITCH_RANGE;
|
2789 | }
|
2790 | };
|
2791 |
|
2792 | __proto._isCircular = function (range) {
|
2793 | return range[1] - range[0] < 360 ? [false, false] : [true, true];
|
2794 | };
|
2795 | |
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 | __proto._updateControlScale = function (changeEvt) {
|
2809 | var opt = this.options;
|
2810 |
|
2811 | var fov = this._axes.get().fov;
|
2812 |
|
2813 | var pRange = this._updatePitchRange(opt.pitchRange, fov, opt.showPolePoint);
|
2814 |
|
2815 | var yRange = this._updateYawRange(opt.yawRange, fov, opt.aspectRatio);
|
2816 |
|
2817 |
|
2818 | var pos = this._axes.get();
|
2819 |
|
2820 | var y = pos.yaw;
|
2821 | var p = pos.pitch;
|
2822 | glMatrix.vec2.copy(this._axes.axis.yaw.range, yRange);
|
2823 | glMatrix.vec2.copy(this._axes.axis.pitch.range, pRange);
|
2824 | this._axes.axis.yaw.circular = this._isCircular(yRange);
|
2825 | this._axes.axis.pitch.circular = this._isCircular(pRange);
|
2826 | |
2827 |
|
2828 |
|
2829 |
|
2830 | if (y < yRange[0]) {
|
2831 | y = yRange[0];
|
2832 | } else if (y > yRange[1]) {
|
2833 | y = yRange[1];
|
2834 | }
|
2835 |
|
2836 | if (p < pRange[0]) {
|
2837 | p = pRange[0];
|
2838 | } else if (p > pRange[1]) {
|
2839 | p = pRange[1];
|
2840 | }
|
2841 |
|
2842 | if (changeEvt) {
|
2843 | changeEvt.set({
|
2844 | yaw: y,
|
2845 | pitch: p
|
2846 | });
|
2847 | }
|
2848 |
|
2849 | this._axes.setTo({
|
2850 | yaw: y,
|
2851 | pitch: p
|
2852 | }, 0);
|
2853 |
|
2854 | return this;
|
2855 | };
|
2856 |
|
2857 | __proto._updatePitchRange = function (pitchRange, fov, showPolePoint) {
|
2858 | if (this.options.gyroMode === GYRO_MODE.VR) {
|
2859 |
|
2860 | return CIRCULAR_PITCH_RANGE;
|
2861 | }
|
2862 |
|
2863 | var verticalAngle = pitchRange[1] - pitchRange[0];
|
2864 | var halfFov = fov / 2;
|
2865 | var isPanorama = verticalAngle < 180;
|
2866 |
|
2867 | if (showPolePoint && !isPanorama) {
|
2868 |
|
2869 | return pitchRange.concat();
|
2870 | }
|
2871 |
|
2872 |
|
2873 | return [pitchRange[0] + halfFov, pitchRange[1] - halfFov];
|
2874 | };
|
2875 |
|
2876 | __proto._updateYawRange = function (yawRange, fov, aspectRatio) {
|
2877 | if (this.options.gyroMode === GYRO_MODE.VR) {
|
2878 | return DEFAULT_YAW_RANGE;
|
2879 | }
|
2880 |
|
2881 | var horizontalAngle = yawRange[1] - yawRange[0];
|
2882 | |
2883 |
|
2884 |
|
2885 |
|
2886 | if (horizontalAngle >= 360) {
|
2887 |
|
2888 | return yawRange.concat();
|
2889 | }
|
2890 | |
2891 |
|
2892 |
|
2893 |
|
2894 |
|
2895 |
|
2896 | var halfHorizontalFov = util.toDegree(Math.atan2(aspectRatio, 1 / Math.tan(glMatrix.glMatrix.toRadian(fov / 2))));
|
2897 |
|
2898 | return [yawRange[0] + halfHorizontalFov, yawRange[1] - halfHorizontalFov];
|
2899 | };
|
2900 |
|
2901 |
|
2902 | __proto._triggerChange = function (evt) {
|
2903 | var pos = this._axes.get();
|
2904 |
|
2905 | var opt = this.options;
|
2906 | var event = {
|
2907 | targetElement: opt.element,
|
2908 | isTrusted: evt.isTrusted,
|
2909 | yaw: pos.yaw,
|
2910 | pitch: pos.pitch,
|
2911 | fov: pos.fov,
|
2912 | quaternion: null
|
2913 | };
|
2914 |
|
2915 | if (opt.gyroMode === GYRO_MODE.VR && this._deviceQuaternion) {
|
2916 | event.quaternion = this._deviceQuaternion.getCombinedQuaternion(pos.yaw);
|
2917 | }
|
2918 |
|
2919 | this.trigger(new Component.ComponentEvent("change", event));
|
2920 | };
|
2921 |
|
2922 |
|
2923 | __proto._adjustAspectRatio = function (input) {
|
2924 | var inputRange = [0.520, 0.540, 0.563, 0.570, 0.584, 0.590, 0.609, 0.670, 0.702, 0.720, 0.760, 0.780, 0.820, 0.920, 0.970, 1.00, 1.07, 1.14, 1.19, 1.25, 1.32, 1.38, 1.40, 1.43, 1.53, 1.62, 1.76, 1.77, 1.86, 1.96, 2.26, 2.30, 2.60, 3.00, 5.00, 6.00];
|
2925 | var outputRange = [0.510, 0.540, 0.606, 0.560, 0.628, 0.630, 0.647, 0.710, 0.736, 0.757, 0.780, 0.770, 0.800, 0.890, 0.975, 1.00, 1.07, 1.10, 1.15, 1.18, 1.22, 1.27, 1.30, 1.33, 1.39, 1.45, 1.54, 1.55, 1.58, 1.62, 1.72, 1.82, 1.92, 2.00, 2.24, 2.30];
|
2926 | var rangeIdx = -1;
|
2927 |
|
2928 | for (var i = 0; i < inputRange.length - 1; i++) {
|
2929 | if (inputRange[i] <= input && inputRange[i + 1] >= input) {
|
2930 | rangeIdx = i;
|
2931 | break;
|
2932 | }
|
2933 | }
|
2934 |
|
2935 | if (rangeIdx === -1) {
|
2936 | if (inputRange[0] > input) {
|
2937 | return outputRange[0];
|
2938 | } else {
|
2939 |
|
2940 | return outputRange[outputRange[0].length - 1];
|
2941 | }
|
2942 | }
|
2943 |
|
2944 | var inputA = inputRange[rangeIdx];
|
2945 | var inputB = inputRange[rangeIdx + 1];
|
2946 | var outputA = outputRange[rangeIdx];
|
2947 | var outputB = outputRange[rangeIdx + 1];
|
2948 | return this._lerp(outputA, outputB, (input - inputA) / (inputB - inputA));
|
2949 | };
|
2950 |
|
2951 | __proto._lerp = function (a, b, fraction) {
|
2952 | return a + fraction * (b - a);
|
2953 | };
|
2954 |
|
2955 | __proto._resetOrientation = function () {
|
2956 | var opt = this.options;
|
2957 |
|
2958 | this._axes.setTo({
|
2959 | yaw: opt.yaw,
|
2960 | pitch: opt.pitch,
|
2961 | fov: opt.fov
|
2962 | }, 0);
|
2963 |
|
2964 | return this;
|
2965 | };
|
2966 |
|
2967 | YawPitchControl.VERSION = VERSION;
|
2968 |
|
2969 | YawPitchControl.CONTROL_MODE_VR = CONTROL_MODE_VR;
|
2970 | YawPitchControl.CONTROL_MODE_YAWPITCH = CONTROL_MODE_YAWPITCH;
|
2971 | YawPitchControl.TOUCH_DIRECTION_ALL = TOUCH_DIRECTION_ALL;
|
2972 | YawPitchControl.TOUCH_DIRECTION_YAW = TOUCH_DIRECTION_YAW;
|
2973 | YawPitchControl.TOUCH_DIRECTION_PITCH = TOUCH_DIRECTION_PITCH;
|
2974 | YawPitchControl.TOUCH_DIRECTION_NONE = TOUCH_DIRECTION_NONE;
|
2975 | return YawPitchControl;
|
2976 | }(Component);
|
2977 |
|
2978 | |
2979 |
|
2980 |
|
2981 |
|
2982 |
|
2983 |
|
2984 |
|
2985 |
|
2986 | var ERROR_TYPE = {
|
2987 | |
2988 |
|
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 |
|
2996 | INVALID_DEVICE: 10,
|
2997 |
|
2998 | |
2999 |
|
3000 |
|
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 |
|
3006 |
|
3007 | NO_WEBGL: 11,
|
3008 |
|
3009 | |
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 |
|
3017 |
|
3018 | FAIL_IMAGE_LOAD: 12,
|
3019 |
|
3020 | |
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 |
|
3026 |
|
3027 |
|
3028 |
|
3029 | FAIL_BIND_TEXTURE: 13,
|
3030 |
|
3031 | |
3032 |
|
3033 |
|
3034 |
|
3035 |
|
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 | INVALID_RESOURCE: 14,
|
3041 |
|
3042 | |
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 | RENDERING_CONTEXT_LOST: 15
|
3052 | };
|
3053 | |
3054 |
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 | var PANOVIEWER_EVENTS = {
|
3062 | |
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 |
|
3068 |
|
3069 |
|
3070 |
|
3071 | READY: "ready",
|
3072 |
|
3073 | |
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 | VIEW_CHANGE: "viewChange",
|
3083 |
|
3084 | |
3085 |
|
3086 |
|
3087 |
|
3088 |
|
3089 |
|
3090 |
|
3091 |
|
3092 |
|
3093 | ANIMATION_END: "animationEnd",
|
3094 |
|
3095 | |
3096 |
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 |
|
3102 |
|
3103 |
|
3104 | ERROR: "error"
|
3105 | };
|
3106 | |
3107 |
|
3108 |
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 | var PROJECTION_TYPE = {
|
3115 | |
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 | EQUIRECTANGULAR: "equirectangular",
|
3125 |
|
3126 | |
3127 |
|
3128 |
|
3129 |
|
3130 |
|
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 | CUBEMAP: "cubemap",
|
3136 |
|
3137 | |
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 |
|
3143 |
|
3144 |
|
3145 |
|
3146 |
|
3147 | CUBESTRIP: "cubestrip",
|
3148 |
|
3149 | |
3150 |
|
3151 |
|
3152 |
|
3153 |
|
3154 |
|
3155 |
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 | PANORAMA: "panorama",
|
3162 |
|
3163 | |
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 |
|
3174 |
|
3175 | STEREOSCOPIC_EQUI: "stereoequi"
|
3176 | };
|
3177 | |
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 | var STEREO_FORMAT = {
|
3186 | |
3187 |
|
3188 |
|
3189 |
|
3190 |
|
3191 |
|
3192 |
|
3193 |
|
3194 |
|
3195 | TOP_BOTTOM: "3dv",
|
3196 |
|
3197 | |
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 | LEFT_RIGHT: "3dh",
|
3207 |
|
3208 | |
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 | NONE: ""
|
3218 | };
|
3219 |
|
3220 | var PANOVIEWER_OPTIONS = {
|
3221 | image: true,
|
3222 | video: true,
|
3223 | projectionType: true,
|
3224 | cubemapConfig: true,
|
3225 | stereoFormat: true,
|
3226 | width: true,
|
3227 | height: true,
|
3228 | yaw: true,
|
3229 | pitch: true,
|
3230 | fov: true,
|
3231 | showPolePoint: true,
|
3232 | useZoom: true,
|
3233 | useKeyboard: true,
|
3234 | gyroMode: true,
|
3235 | yawRange: true,
|
3236 | pitchRange: true,
|
3237 | fovRange: true,
|
3238 | touchDirection: true,
|
3239 | canvasClass: true
|
3240 | };
|
3241 | var DEFAULT_CANVAS_CLASS = "view360-canvas";
|
3242 |
|
3243 | var merge = function (target) {
|
3244 | var srcs = [];
|
3245 |
|
3246 | for (var _i = 1; _i < arguments.length; _i++) {
|
3247 | srcs[_i - 1] = arguments[_i];
|
3248 | }
|
3249 |
|
3250 | srcs.forEach(function (source) {
|
3251 | Object.keys(source).forEach(function (key) {
|
3252 | var value = source[key];
|
3253 |
|
3254 | if (Array.isArray(target[key]) && Array.isArray(value)) {
|
3255 | target[key] = __spread(target[key], value);
|
3256 | } else {
|
3257 | target[key] = value;
|
3258 | }
|
3259 | });
|
3260 | });
|
3261 | return target;
|
3262 | };
|
3263 | var toImageElement = function (image) {
|
3264 | var images = image instanceof Array ? image : [image];
|
3265 | var parsedImages = images.map(function (img) {
|
3266 | var imgEl = img;
|
3267 |
|
3268 | if (typeof img === "string") {
|
3269 | imgEl = new Image();
|
3270 | imgEl.crossOrigin = "anonymous";
|
3271 | imgEl.src = img;
|
3272 | }
|
3273 |
|
3274 | return imgEl;
|
3275 | });
|
3276 | return parsedImages.length === 1 ? parsedImages[0] : parsedImages;
|
3277 | };
|
3278 | var toVideoElement = function (videoCandidate) {
|
3279 | if (videoCandidate instanceof HTMLVideoElement) {
|
3280 | return videoCandidate;
|
3281 | } else {
|
3282 |
|
3283 | var video_1 = document.createElement("video");
|
3284 | video_1.setAttribute("crossorigin", "anonymous");
|
3285 | video_1.setAttribute("webkit-playsinline", "");
|
3286 | video_1.setAttribute("playsinline", "");
|
3287 |
|
3288 | if (videoCandidate instanceof Array) {
|
3289 | videoCandidate.forEach(function (v) {
|
3290 | return appendSourceElement(video_1, v);
|
3291 | });
|
3292 | } else {
|
3293 | appendSourceElement(video_1, videoCandidate);
|
3294 | }
|
3295 |
|
3296 | var sourceCount = video_1.querySelectorAll("source").length;
|
3297 |
|
3298 | if (sourceCount > 0) {
|
3299 | if (video_1.readyState < 1) {
|
3300 | video_1.load();
|
3301 | }
|
3302 | }
|
3303 |
|
3304 | return video_1;
|
3305 | }
|
3306 | };
|
3307 | |
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 | var appendSourceElement = function (video, videoUrl) {
|
3313 | var videoSrc;
|
3314 | var videoType;
|
3315 |
|
3316 | if (typeof videoUrl === "object") {
|
3317 | videoSrc = videoUrl.src;
|
3318 | videoType = videoUrl.type;
|
3319 | } else if (typeof videoUrl === "string") {
|
3320 | videoSrc = videoUrl;
|
3321 | }
|
3322 |
|
3323 | if (!videoSrc) {
|
3324 | return false;
|
3325 | }
|
3326 |
|
3327 | var sourceElement = document.createElement("source");
|
3328 | sourceElement.src = videoSrc;
|
3329 |
|
3330 | if (videoType) {
|
3331 | sourceElement.type = videoType;
|
3332 | }
|
3333 |
|
3334 | video.appendChild(sourceElement);
|
3335 | };
|
3336 |
|
3337 | var WEBGL_ERROR_CODE = {
|
3338 | "0": "NO_ERROR",
|
3339 | "1280": "INVALID_ENUM",
|
3340 | "1281": "INVALID_VALUE",
|
3341 | "1282": "INVALID_OPERATION",
|
3342 | "1285": "OUT_OF_MEMORY",
|
3343 | "1286": "INVALID_FRAMEBUFFER_OPERATION",
|
3344 | "37442": "CONTEXT_LOST_WEBGL"
|
3345 | };
|
3346 | var webglAvailability = null;
|
3347 |
|
3348 | var WebGLUtils =
|
3349 |
|
3350 | function () {
|
3351 | function WebGLUtils() {}
|
3352 |
|
3353 | WebGLUtils.createShader = function (gl, type, source) {
|
3354 | var shader = gl.createShader(type);
|
3355 | gl.shaderSource(shader, source);
|
3356 | gl.compileShader(shader);
|
3357 | var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
3358 |
|
3359 | if (success) {
|
3360 | return shader;
|
3361 | }
|
3362 |
|
3363 |
|
3364 | console.error(gl.getShaderInfoLog(shader));
|
3365 | return null;
|
3366 | };
|
3367 |
|
3368 | WebGLUtils.createProgram = function (gl, vertexShader, fragmentShader) {
|
3369 | var program = gl.createProgram();
|
3370 | gl.attachShader(program, vertexShader);
|
3371 | gl.attachShader(program, fragmentShader);
|
3372 | gl.linkProgram(program);
|
3373 | gl.deleteShader(vertexShader);
|
3374 | gl.deleteShader(fragmentShader);
|
3375 | var success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
3376 |
|
3377 | if (success) {
|
3378 | return program;
|
3379 | }
|
3380 |
|
3381 | gl.deleteProgram(program);
|
3382 | return null;
|
3383 | };
|
3384 |
|
3385 | WebGLUtils.initBuffer = function (gl, target
|
3386 | /* bind point */
|
3387 | , data, itemSize, attr) {
|
3388 | var buffer = gl.createBuffer();
|
3389 | gl.bindBuffer(target, buffer);
|
3390 | gl.bufferData(target, data, gl.STATIC_DRAW);
|
3391 |
|
3392 | if (buffer) {
|
3393 | buffer.itemSize = itemSize;
|
3394 | buffer.numItems = data.length / itemSize;
|
3395 | }
|
3396 |
|
3397 | if (attr !== undefined) {
|
3398 | gl.enableVertexAttribArray(attr);
|
3399 | gl.vertexAttribPointer(attr, buffer.itemSize, gl.FLOAT, false, 0, 0);
|
3400 | }
|
3401 |
|
3402 | return buffer;
|
3403 | };
|
3404 |
|
3405 | WebGLUtils.getWebglContext = function (canvas, userContextAttributes) {
|
3406 | var e_1, _a;
|
3407 |
|
3408 | var webglIdentifiers = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
|
3409 | var context = null;
|
3410 |
|
3411 | var contextAttributes = __assign({
|
3412 | preserveDrawingBuffer: false,
|
3413 | antialias: false
|
3414 | }, userContextAttributes);
|
3415 |
|
3416 | var onWebglcontextcreationerror = function (e) {
|
3417 | return e.statusMessage;
|
3418 | };
|
3419 |
|
3420 | canvas.addEventListener("webglcontextcreationerror", onWebglcontextcreationerror);
|
3421 |
|
3422 | try {
|
3423 | for (var webglIdentifiers_1 = __values(webglIdentifiers), webglIdentifiers_1_1 = webglIdentifiers_1.next(); !webglIdentifiers_1_1.done; webglIdentifiers_1_1 = webglIdentifiers_1.next()) {
|
3424 | var identifier = webglIdentifiers_1_1.value;
|
3425 |
|
3426 | try {
|
3427 | context = canvas.getContext(identifier, contextAttributes);
|
3428 | } catch (t) {}
|
3429 |
|
3430 |
|
3431 | if (context) {
|
3432 | break;
|
3433 | }
|
3434 | }
|
3435 | } catch (e_1_1) {
|
3436 | e_1 = {
|
3437 | error: e_1_1
|
3438 | };
|
3439 | } finally {
|
3440 | try {
|
3441 | if (webglIdentifiers_1_1 && !webglIdentifiers_1_1.done && (_a = webglIdentifiers_1.return)) _a.call(webglIdentifiers_1);
|
3442 | } finally {
|
3443 | if (e_1) throw e_1.error;
|
3444 | }
|
3445 | }
|
3446 |
|
3447 | canvas.removeEventListener("webglcontextcreationerror", onWebglcontextcreationerror);
|
3448 | return context;
|
3449 | };
|
3450 |
|
3451 | WebGLUtils.createTexture = function (gl, textureTarget) {
|
3452 | var texture = gl.createTexture();
|
3453 | gl.bindTexture(textureTarget, texture);
|
3454 | gl.texParameteri(textureTarget, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
3455 | gl.texParameteri(textureTarget, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
3456 | gl.texParameteri(textureTarget, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
3457 | gl.texParameteri(textureTarget, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
3458 | gl.bindTexture(textureTarget, null);
|
3459 | return texture;
|
3460 | };
|
3461 | |
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 | WebGLUtils.isWebGLAvailable = function () {
|
3469 | if (webglAvailability === null) {
|
3470 | var canvas = document.createElement("canvas");
|
3471 | var webglContext = WebGLUtils.getWebglContext(canvas);
|
3472 | webglAvailability = !!webglContext;
|
3473 |
|
3474 | if (webglContext) {
|
3475 | var loseContextExtension = webglContext.getExtension("WEBGL_lose_context");
|
3476 |
|
3477 | if (loseContextExtension) {
|
3478 | loseContextExtension.loseContext();
|
3479 | }
|
3480 | }
|
3481 | }
|
3482 |
|
3483 | return !!webglAvailability;
|
3484 | };
|
3485 | |
3486 |
|
3487 |
|
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 | WebGLUtils.isStableWebGL = function () {
|
3493 | var agentInfo = agent$1();
|
3494 | var isStableWebgl = true;
|
3495 |
|
3496 | if (agentInfo.os.name === "android") {
|
3497 | var version = parseFloat(agentInfo.os.version);
|
3498 |
|
3499 | if (version <= 4.3 && version >= 1) {
|
3500 | isStableWebgl = false;
|
3501 | } else if (version === 4.4) {
|
3502 | if (agentInfo.browser.name !== "chrome") {
|
3503 | isStableWebgl = false;
|
3504 | }
|
3505 | }
|
3506 | }
|
3507 |
|
3508 | return isStableWebgl;
|
3509 | };
|
3510 |
|
3511 | WebGLUtils.getErrorNameFromWebGLErrorCode = function (code) {
|
3512 | if (!(code in WEBGL_ERROR_CODE)) {
|
3513 | return "UNKNOWN_ERROR";
|
3514 | }
|
3515 |
|
3516 | return WEBGL_ERROR_CODE[code];
|
3517 | };
|
3518 | |
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 | WebGLUtils.texImage2D = function (gl, target, pixels) {
|
3525 | try {
|
3526 | gl.texImage2D(target, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
3527 | } catch (error) {
|
3528 |
|
3529 | console.error("WebGLUtils.texImage2D error:", error);
|
3530 |
|
3531 | }
|
3532 | };
|
3533 |
|
3534 | WebGLUtils.getMaxTextureSize = function (gl) {
|
3535 |
|
3536 | return gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
3537 | };
|
3538 |
|
3539 | return WebGLUtils;
|
3540 | }();
|
3541 |
|
3542 | var agentInfo = agent$1();
|
3543 | var isIE11 = agentInfo.browser.name === "ie" && agentInfo.browser.majorVersion === 11;
|
3544 | var EVENTS = {
|
3545 | ERROR: "error"
|
3546 | };
|
3547 | |
3548 |
|
3549 |
|
3550 |
|
3551 |
|
3552 | var Renderer =
|
3553 |
|
3554 | function (_super) {
|
3555 | __extends(Renderer, _super);
|
3556 |
|
3557 | function Renderer() {
|
3558 | var _this = _super.call(this) || this;
|
3559 |
|
3560 | _this._forceDimension = null;
|
3561 | _this._pixelCanvas = null;
|
3562 | _this._pixelContext = null;
|
3563 | return _this;
|
3564 | }
|
3565 |
|
3566 | var __proto = Renderer.prototype;
|
3567 |
|
3568 | __proto.render = function (_a) {
|
3569 | var gl = _a.gl,
|
3570 | shaderProgram = _a.shaderProgram,
|
3571 | indexBuffer = _a.indexBuffer,
|
3572 | mvMatrix = _a.mvMatrix,
|
3573 | pMatrix = _a.pMatrix;
|
3574 | gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, pMatrix);
|
3575 | gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix);
|
3576 |
|
3577 | if (indexBuffer) {
|
3578 | gl.drawElements(gl.TRIANGLES, indexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
|
3579 | }
|
3580 | };
|
3581 |
|
3582 | |
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 |
|
3593 |
|
3594 |
|
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 | __proto.getDimension = function (pixelSource) {
|
3603 | var width = pixelSource.naturalWidth || pixelSource.videoWidth;
|
3604 | var height = pixelSource.naturalHeight || pixelSource.videoHeight;
|
3605 | return {
|
3606 | width: width,
|
3607 | height: height
|
3608 | };
|
3609 | };
|
3610 | |
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 | __proto.updateShaderData = function (param) {
|
3616 | |
3617 |
|
3618 |
|
3619 |
|
3620 |
|
3621 |
|
3622 |
|
3623 |
|
3624 | };
|
3625 | |
3626 |
|
3627 |
|
3628 |
|
3629 |
|
3630 |
|
3631 |
|
3632 | __proto._initPixelSource = function (image, forceDimension) {
|
3633 | if (forceDimension === void 0) {
|
3634 | forceDimension = null;
|
3635 | }
|
3636 |
|
3637 | var isIE11Video = isIE11 && image instanceof HTMLVideoElement;
|
3638 |
|
3639 | if (isIE11Video || forceDimension) {
|
3640 | var _a = forceDimension || this.getDimension(image),
|
3641 | width = _a.width,
|
3642 | height = _a.height;
|
3643 |
|
3644 | this._pixelCanvas = document.createElement("canvas");
|
3645 | this._pixelCanvas.width = width;
|
3646 | this._pixelCanvas.height = height;
|
3647 | this._pixelContext = this._pixelCanvas.getContext("2d");
|
3648 | }
|
3649 |
|
3650 | this._forceDimension = forceDimension;
|
3651 | };
|
3652 |
|
3653 | __proto._getPixelSource = function (image) {
|
3654 | if (!this._pixelCanvas) {
|
3655 | return image;
|
3656 | }
|
3657 | |
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 | var contentDimension = this.getDimension(image);
|
3665 | var textureDimension = this._forceDimension || contentDimension;
|
3666 |
|
3667 | if (this._pixelCanvas.width !== textureDimension.width) {
|
3668 | this._pixelCanvas.width = textureDimension.width;
|
3669 | }
|
3670 |
|
3671 | if (this._pixelCanvas.height !== textureDimension.height) {
|
3672 | this._pixelCanvas.height = textureDimension.height;
|
3673 | }
|
3674 |
|
3675 | if (this._forceDimension) {
|
3676 | this._pixelContext.drawImage(image, 0, 0, contentDimension.width, contentDimension.height, 0, 0, textureDimension.width, textureDimension.height);
|
3677 | } else {
|
3678 | this._pixelContext.drawImage(image, 0, 0);
|
3679 | }
|
3680 |
|
3681 | return this._pixelCanvas;
|
3682 | };
|
3683 |
|
3684 | __proto._extractTileConfig = function (imageConfig) {
|
3685 | var tileConfig = Array.isArray(imageConfig.tileConfig) ? imageConfig.tileConfig : Array.apply(void 0, __spread(Array(6))).map(function () {
|
3686 | return imageConfig.tileConfig;
|
3687 | });
|
3688 | tileConfig = tileConfig.map(function (config) {
|
3689 | return __assign({
|
3690 | flipHorizontal: false,
|
3691 | rotation: 0
|
3692 | }, config);
|
3693 | });
|
3694 | return tileConfig;
|
3695 | };
|
3696 |
|
3697 | __proto._triggerError = function (error) {
|
3698 |
|
3699 | console.error("Renderer Error:", error);
|
3700 |
|
3701 |
|
3702 | this.trigger(new Component.ComponentEvent(EVENTS.ERROR, {
|
3703 | message: typeof error === "string" ? error : error.message
|
3704 | }));
|
3705 | };
|
3706 |
|
3707 | Renderer.EVENTS = EVENTS;
|
3708 | return Renderer;
|
3709 | }(Component);
|
3710 |
|
3711 | var CubeRenderer =
|
3712 |
|
3713 | function (_super) {
|
3714 | __extends(CubeRenderer, _super);
|
3715 |
|
3716 | function CubeRenderer() {
|
3717 | return _super !== null && _super.apply(this, arguments) || this;
|
3718 | }
|
3719 |
|
3720 | var __proto = CubeRenderer.prototype;
|
3721 |
|
3722 | CubeRenderer.extractOrder = function (imageConfig) {
|
3723 | return imageConfig.order || "RLUDBF";
|
3724 | };
|
3725 |
|
3726 | __proto.getVertexPositionData = function () {
|
3727 | CubeRenderer._VERTEX_POSITION_DATA = CubeRenderer._VERTEX_POSITION_DATA !== null ? CubeRenderer._VERTEX_POSITION_DATA : [
|
3728 | 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1,
|
3729 | -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1,
|
3730 | -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1,
|
3731 | 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1,
|
3732 | 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1,
|
3733 | -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1];
|
3734 | return CubeRenderer._VERTEX_POSITION_DATA;
|
3735 | };
|
3736 |
|
3737 | __proto.getIndexData = function () {
|
3738 | if (CubeRenderer._INDEX_DATA) {
|
3739 | return CubeRenderer._INDEX_DATA;
|
3740 | }
|
3741 |
|
3742 | var indexData = [];
|
3743 | var vertexPositionData = this.getVertexPositionData();
|
3744 |
|
3745 | for (var i = 0; i < vertexPositionData.length / 3; i += 4) {
|
3746 | indexData.push(i, i + 2, i + 1, i, i + 3, i + 2);
|
3747 | }
|
3748 |
|
3749 | CubeRenderer._INDEX_DATA = indexData;
|
3750 | return indexData;
|
3751 | };
|
3752 |
|
3753 | __proto.getTextureCoordData = function (_a) {
|
3754 | var _this = this;
|
3755 |
|
3756 | var image = _a.image,
|
3757 | imageConfig = _a.imageConfig;
|
3758 | var vertexOrder = "BFUDRL";
|
3759 | var order = CubeRenderer.extractOrder(imageConfig);
|
3760 | var base = this.getVertexPositionData();
|
3761 |
|
3762 | var tileConfig = this._extractTileConfig(imageConfig);
|
3763 |
|
3764 | var elemSize = 3;
|
3765 | var vertexPerTile = 4;
|
3766 | var trim = imageConfig.trim;
|
3767 | var texCoords = vertexOrder.split("").map(function (face) {
|
3768 | return tileConfig[order.indexOf(face)];
|
3769 | }).map(function (config, i) {
|
3770 | var rotation = Math.floor(config.rotation / 90);
|
3771 | var ordermap = config.flipHorizontal ? [0, 1, 2, 3] : [1, 0, 3, 2];
|
3772 |
|
3773 | for (var r = 0; r < Math.abs(rotation); r++) {
|
3774 | if (config.flipHorizontal && rotation > 0 || !config.flipHorizontal && rotation < 0) {
|
3775 | ordermap.push(ordermap.shift());
|
3776 | } else {
|
3777 | ordermap.unshift(ordermap.pop());
|
3778 | }
|
3779 | }
|
3780 |
|
3781 | var elemPerTile = elemSize * vertexPerTile;
|
3782 | var tileVertex = base.slice(i * elemPerTile, i * elemPerTile + elemPerTile);
|
3783 | var tileTemp = [];
|
3784 |
|
3785 | for (var j = 0; j < vertexPerTile; j++) {
|
3786 | tileTemp[ordermap[j]] = tileVertex.splice(0, elemSize);
|
3787 | }
|
3788 |
|
3789 | return tileTemp;
|
3790 | }).map(function (coord) {
|
3791 | return _this._shrinkCoord({
|
3792 | image: image,
|
3793 | faceCoords: coord,
|
3794 | trim: trim
|
3795 | });
|
3796 | }).reduce(function (acc, val) {
|
3797 | return __spread(acc, val.reduce(function (coords, coord) {
|
3798 | return __spread(coords, coord);
|
3799 | }, []));
|
3800 | }, []);
|
3801 | return texCoords;
|
3802 | };
|
3803 |
|
3804 | __proto.getVertexShaderSource = function () {
|
3805 | return "\nattribute vec3 aVertexPosition;\nattribute vec3 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvarying highp vec3 vVertexDirectionVector;\nvoid main(void) {\n vVertexDirectionVector = aTextureCoord;\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}";
|
3806 | };
|
3807 |
|
3808 | __proto.getFragmentShaderSource = function () {
|
3809 | return "\nprecision highp float;\nuniform samplerCube uSampler;\nvarying highp vec3 vVertexDirectionVector;\nvoid main(void) {\n gl_FragColor = textureCube(uSampler, vVertexDirectionVector);\n}";
|
3810 | };
|
3811 |
|
3812 | __proto.updateTexture = function (gl, image, imageConfig) {
|
3813 | var baseOrder = "RLUDBF";
|
3814 | var order = CubeRenderer.extractOrder(imageConfig);
|
3815 | var orderMap = {};
|
3816 | order.split("").forEach(function (v, i) {
|
3817 | orderMap[v] = i;
|
3818 | });
|
3819 |
|
3820 | try {
|
3821 | if (image instanceof Array) {
|
3822 | for (var surfaceIdx = 0; surfaceIdx < 6; surfaceIdx++) {
|
3823 | var tileIdx = orderMap[baseOrder[surfaceIdx]];
|
3824 | WebGLUtils.texImage2D(gl, gl.TEXTURE_CUBE_MAP_POSITIVE_X + surfaceIdx, image[tileIdx]);
|
3825 | }
|
3826 | } else {
|
3827 | var maxCubeMapTextureSize = this.getMaxCubeMapTextureSize(gl, image);
|
3828 |
|
3829 | for (var surfaceIdx = 0; surfaceIdx < 6; surfaceIdx++) {
|
3830 | var tileIdx = orderMap[baseOrder[surfaceIdx]];
|
3831 | var tile = this.extractTileFromImage(image, tileIdx, maxCubeMapTextureSize);
|
3832 | WebGLUtils.texImage2D(gl, gl.TEXTURE_CUBE_MAP_POSITIVE_X + surfaceIdx, tile);
|
3833 | }
|
3834 | }
|
3835 | } catch (e) {
|
3836 | this._triggerError(e);
|
3837 | }
|
3838 | };
|
3839 |
|
3840 | __proto.bindTexture = function (gl, texture, image, imageConfig) {
|
3841 | gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
3842 | this.updateTexture(gl, image, imageConfig);
|
3843 | };
|
3844 |
|
3845 | __proto.getSourceTileSize = function (image) {
|
3846 | var _a = this.getDimension(image),
|
3847 | width = _a.width,
|
3848 | height = _a.height;
|
3849 |
|
3850 | var aspectRatio = width / height;
|
3851 | var inputTextureSize;
|
3852 |
|
3853 | if (aspectRatio === 1 / 6) {
|
3854 | inputTextureSize = width;
|
3855 | } else if (aspectRatio === 6) {
|
3856 | inputTextureSize = height;
|
3857 | } else if (aspectRatio === 2 / 3) {
|
3858 | inputTextureSize = width / 2;
|
3859 | } else {
|
3860 | inputTextureSize = width / 3;
|
3861 | }
|
3862 |
|
3863 | return inputTextureSize;
|
3864 | };
|
3865 |
|
3866 | __proto.extractTileFromImage = function (image, tileIdx, outputTextureSize) {
|
3867 | var width = this.getDimension(image).width;
|
3868 | var inputTextureSize = this.getSourceTileSize(image);
|
3869 | var canvas = document.createElement("canvas");
|
3870 | canvas.width = outputTextureSize;
|
3871 | canvas.height = outputTextureSize;
|
3872 | var context = canvas.getContext("2d");
|
3873 | var tilePerRow = width / inputTextureSize;
|
3874 | var x = inputTextureSize * tileIdx % (inputTextureSize * tilePerRow);
|
3875 | var y = Math.floor(tileIdx / tilePerRow) * inputTextureSize;
|
3876 | context.drawImage(image, x, y, inputTextureSize, inputTextureSize, 0, 0, outputTextureSize, outputTextureSize);
|
3877 | return canvas;
|
3878 | };
|
3879 |
|
3880 | __proto.getMaxCubeMapTextureSize = function (gl, image) {
|
3881 | var agentInfo = agent$1();
|
3882 | var maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
|
3883 | var imageWidth = this.getSourceTileSize(image);
|
3884 |
|
3885 | if (agentInfo.browser.name === "ie" && agentInfo.browser.majorVersion === 11) {
|
3886 | if (!util.isPowerOfTwo(imageWidth)) {
|
3887 | for (var i = 1; i < maxCubeMapTextureSize; i *= 2) {
|
3888 | if (i < imageWidth) {
|
3889 | continue;
|
3890 | } else {
|
3891 | imageWidth = i;
|
3892 | break;
|
3893 | }
|
3894 | }
|
3895 | }
|
3896 | }
|
3897 |
|
3898 | if (agentInfo.os.name === "ios") {
|
3899 | var majorVersion = agentInfo.os.majorVersion;
|
3900 |
|
3901 | if (majorVersion === 9) {
|
3902 | imageWidth = 1024;
|
3903 | }
|
3904 |
|
3905 |
|
3906 | if (majorVersion === 8) {
|
3907 | imageWidth = 512;
|
3908 | }
|
3909 | }
|
3910 |
|
3911 |
|
3912 | return Math.min(maxCubeMapTextureSize, imageWidth);
|
3913 | };
|
3914 |
|
3915 | __proto._shrinkCoord = function (coordData) {
|
3916 | var image = coordData.image,
|
3917 | faceCoords = coordData.faceCoords,
|
3918 | trim = coordData.trim;
|
3919 | var inputTextureSize = Array.isArray(image) ? this.getDimension(image[0]).width : this.getSourceTileSize(image);
|
3920 |
|
3921 | var SHRINK_MULTIPLIER = 1 - trim * (2 / inputTextureSize);
|
3922 | var axisMultipliers = [0, 1, 2].map(function (axisIndex) {
|
3923 | var axisDir = util.sign(faceCoords[0][axisIndex]);
|
3924 | var notSameDir = faceCoords.some(function (coord) {
|
3925 | return util.sign(coord[axisIndex]) !== axisDir;
|
3926 | });
|
3927 | return notSameDir;
|
3928 | }).map(function (notSameDir) {
|
3929 | return notSameDir ? SHRINK_MULTIPLIER : 1;
|
3930 | });
|
3931 | return faceCoords.map(function (coords) {
|
3932 | return coords.map(function (coord, axisIndex) {
|
3933 | return coord * axisMultipliers[axisIndex];
|
3934 | });
|
3935 | });
|
3936 | };
|
3937 |
|
3938 | CubeRenderer._VERTEX_POSITION_DATA = null;
|
3939 | CubeRenderer._INDEX_DATA = null;
|
3940 | return CubeRenderer;
|
3941 | }(Renderer);
|
3942 |
|
3943 | var CubeStripRenderer =
|
3944 |
|
3945 | function (_super) {
|
3946 | __extends(CubeStripRenderer, _super);
|
3947 |
|
3948 | function CubeStripRenderer() {
|
3949 | return _super !== null && _super.apply(this, arguments) || this;
|
3950 | }
|
3951 |
|
3952 | var __proto = CubeStripRenderer.prototype;
|
3953 |
|
3954 | __proto.getVertexShaderSource = function () {
|
3955 | return "\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvarying highp vec2 vTextureCoord;\nvoid main(void) {\n vTextureCoord = aTextureCoord;\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}";
|
3956 | };
|
3957 |
|
3958 | __proto.getFragmentShaderSource = function () {
|
3959 | return "\n#define PI 3.14159265359\nprecision highp float;\nvarying highp vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform bool uIsEAC;\nconst vec2 OPERATE_COORDS_RANGE = vec2(-1.0, 1.0);\nconst vec2 TEXTURE_COORDS_RANGE = vec2(0.0, 1.0);\n// vector type is used for initializing values instead of array.\nconst vec4 TEXTURE_DIVISION_X = vec4(0.0, 1.0 / 3.0, 2.0 / 3.0, 1.0);\nconst vec3 TEXTURE_DIVISION_Y = vec3(0.0, 1.0 / 2.0, 1.0);\nconst float EAC_CONST = 2.0 / PI;\nfloat scale(vec2 domainRange, vec2 targetRange, float val) {\n float unit = 1.0 / (domainRange[1] - domainRange[0]);\n return targetRange[0] + (targetRange[1] - targetRange[0]) * (val - domainRange[0]) * unit;\n}\nvoid main(void) {\n float transformedCoordX;\n float transformedCoordY;\n\n if (uIsEAC) {\n vec2 orgTextureRangeX;\n vec2 orgTextureRangeY;\n\n // Apply EAC transform\n if (vTextureCoord.s >= TEXTURE_DIVISION_X[2]) {\n orgTextureRangeX = vec2(TEXTURE_DIVISION_X[2], TEXTURE_DIVISION_X[3]);\n } else if (vTextureCoord.s >= TEXTURE_DIVISION_X[1]) {\n orgTextureRangeX = vec2(TEXTURE_DIVISION_X[1], TEXTURE_DIVISION_X[2]);\n } else {\n orgTextureRangeX = vec2(TEXTURE_DIVISION_X[0], TEXTURE_DIVISION_X[1]);\n }\n\n if (vTextureCoord.t >= TEXTURE_DIVISION_Y[1]) {\n orgTextureRangeY = vec2(TEXTURE_DIVISION_Y[1], TEXTURE_DIVISION_Y[2]);\n } else {\n orgTextureRangeY = vec2(TEXTURE_DIVISION_Y[0], TEXTURE_DIVISION_Y[1]);\n }\n\n // scaling coors by the coordinates following the range from -1.0 to 1.0.\n float px = scale(orgTextureRangeX, OPERATE_COORDS_RANGE, vTextureCoord.s);\n float py = scale(orgTextureRangeY, OPERATE_COORDS_RANGE, vTextureCoord.t);\n\n float qu = EAC_CONST * atan(px) + 0.5;\n float qv = EAC_CONST * atan(py) + 0.5;\n\n // re-scaling coors by original coordinates ranges\n transformedCoordX = scale(TEXTURE_COORDS_RANGE, orgTextureRangeX, qu);\n transformedCoordY = scale(TEXTURE_COORDS_RANGE, orgTextureRangeY, qv);\n } else {\n // normal cubemap\n transformedCoordX = vTextureCoord.s;\n transformedCoordY = vTextureCoord.t;\n }\n\n gl_FragColor = texture2D(uSampler, vec2(transformedCoordX, transformedCoordY));\n}";
|
3960 | };
|
3961 |
|
3962 | __proto.getVertexPositionData = function () {
|
3963 | if (!this._vertices) {
|
3964 | this._vertices = [
|
3965 | 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1,
|
3966 | -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1,
|
3967 | -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1,
|
3968 | -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1,
|
3969 | 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1,
|
3970 | -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1];
|
3971 | }
|
3972 |
|
3973 | return this._vertices;
|
3974 | };
|
3975 |
|
3976 | __proto.getIndexData = function () {
|
3977 | var _this = this;
|
3978 |
|
3979 |
|
3980 | var indices = function () {
|
3981 | var indexData = [];
|
3982 |
|
3983 | for (var i = 0; i < _this._vertices.length / 3; i += 4) {
|
3984 | indexData.push(i, i + 1, i + 2, i, i + 2, i + 3);
|
3985 | }
|
3986 |
|
3987 | return indexData;
|
3988 | }();
|
3989 |
|
3990 | return indices;
|
3991 | };
|
3992 |
|
3993 | __proto.getTextureCoordData = function (_a) {
|
3994 | var _this = this;
|
3995 |
|
3996 | var image = _a.image,
|
3997 | imageConfig = _a.imageConfig;
|
3998 |
|
3999 | var cols = 3;
|
4000 | var rows = 2;
|
4001 | var textureSize = this.getDimension(image);
|
4002 | var trim = imageConfig.trim;
|
4003 | var order = imageConfig.order || "RLUDFB";
|
4004 | var coords = [];
|
4005 |
|
4006 | for (var r = rows - 1; r >= 0; r--) {
|
4007 | for (var c = 0; c < cols; c++) {
|
4008 | var coord = [c / cols, r / rows, (c + 1) / cols, r / rows, (c + 1) / cols, (r + 1) / rows, c / cols, (r + 1) / rows];
|
4009 | coords.push(coord);
|
4010 | }
|
4011 | }
|
4012 |
|
4013 | var tileConfigs = this._extractTileConfig(imageConfig);
|
4014 |
|
4015 |
|
4016 | coords = coords
|
4017 | .map(function (coord) {
|
4018 | return _this._shrinkCoord(coord, textureSize, trim);
|
4019 | }).map(function (coord, i) {
|
4020 | return _this._transformCoord(coord, tileConfigs[i]);
|
4021 | });
|
4022 |
|
4023 | return "BFUDRL".split("").map(function (face) {
|
4024 | return order.indexOf(face);
|
4025 | }).map(function (index) {
|
4026 | return coords[index];
|
4027 | }).reduce(function (acc, val) {
|
4028 | return acc.concat(val);
|
4029 | }, []);
|
4030 | };
|
4031 |
|
4032 | __proto.updateTexture = function (gl, image) {
|
4033 | WebGLUtils.texImage2D(gl, gl.TEXTURE_2D, this._getPixelSource(image));
|
4034 | };
|
4035 |
|
4036 | __proto.bindTexture = function (gl, texture, image) {
|
4037 |
|
4038 | var _a = this.getDimension(image),
|
4039 | width = _a.width,
|
4040 | height = _a.height;
|
4041 |
|
4042 | var size = Math.max(width, height);
|
4043 | var maxSize = WebGLUtils.getMaxTextureSize(gl);
|
4044 |
|
4045 | if (size > maxSize) {
|
4046 | this._triggerError("Image width(" + width + ") exceeds device limit(" + maxSize + "))");
|
4047 |
|
4048 | return;
|
4049 | }
|
4050 |
|
4051 |
|
4052 | this._initPixelSource(image);
|
4053 |
|
4054 | gl.activeTexture(gl.TEXTURE0);
|
4055 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
4056 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
4057 | this.updateTexture(gl, image);
|
4058 | };
|
4059 |
|
4060 | __proto._transformCoord = function (coord, tileConfig) {
|
4061 | var newCoord = coord.slice();
|
4062 |
|
4063 | if (tileConfig.flipHorizontal) {
|
4064 | newCoord = this._flipHorizontalCoord(newCoord);
|
4065 | }
|
4066 |
|
4067 | if (tileConfig.rotation) {
|
4068 | newCoord = this._rotateCoord(newCoord, tileConfig.rotation);
|
4069 | }
|
4070 |
|
4071 | return newCoord;
|
4072 | };
|
4073 |
|
4074 | __proto._shrinkCoord = function (coord, textureSize, trim) {
|
4075 | var width = textureSize.width,
|
4076 | height = textureSize.height;
|
4077 |
|
4078 | var SHRINK_Y = trim * (1 / height);
|
4079 | var SHRINK_X = trim * (1 / width);
|
4080 | return [coord[0] + SHRINK_X, coord[1] + SHRINK_Y, coord[2] - SHRINK_X, coord[3] + SHRINK_Y, coord[4] - SHRINK_X, coord[5] - SHRINK_Y, coord[6] + SHRINK_X, coord[7] - SHRINK_Y];
|
4081 | };
|
4082 |
|
4083 | __proto._rotateCoord = function (coord, rotationAngle) {
|
4084 | var SIZE = 2;
|
4085 |
|
4086 | var shiftCount = Math.floor(rotationAngle / 90) % 4;
|
4087 |
|
4088 | if (shiftCount === 0) {
|
4089 | return coord;
|
4090 | }
|
4091 |
|
4092 | var moved;
|
4093 | var rotatedCoord = [];
|
4094 |
|
4095 | if (shiftCount > 0) {
|
4096 | moved = coord.splice(0, shiftCount * SIZE);
|
4097 | rotatedCoord = coord.concat(moved);
|
4098 | } else {
|
4099 | moved = coord.splice((4 + shiftCount) * SIZE, -shiftCount * SIZE);
|
4100 | rotatedCoord = moved.concat(coord);
|
4101 | }
|
4102 |
|
4103 | return rotatedCoord;
|
4104 | };
|
4105 |
|
4106 | __proto._flipHorizontalCoord = function (coord) {
|
4107 | return [coord[2], coord[3], coord[0], coord[1], coord[6], coord[7], coord[4], coord[5]];
|
4108 | };
|
4109 |
|
4110 | return CubeStripRenderer;
|
4111 | }(Renderer);
|
4112 |
|
4113 | var latitudeBands = 60;
|
4114 | var longitudeBands = 60;
|
4115 | var radius = 2;
|
4116 | var ANGLE_CORRECTION_FOR_CENTER_ALIGN = -0.5 * Math.PI;
|
4117 | var textureCoordData = [];
|
4118 | var vertexPositionData = [];
|
4119 | var indexData = [];
|
4120 | var latIdx;
|
4121 | var lngIdx;
|
4122 |
|
4123 | for (latIdx = 0; latIdx <= latitudeBands; latIdx++) {
|
4124 | var theta = (latIdx / latitudeBands - 0.5) * Math.PI;
|
4125 | var sinTheta = Math.sin(theta);
|
4126 | var cosTheta = Math.cos(theta);
|
4127 |
|
4128 | for (lngIdx = 0; lngIdx <= longitudeBands; lngIdx++) {
|
4129 | var phi = (lngIdx / longitudeBands - 0.5) * 2 * Math.PI + ANGLE_CORRECTION_FOR_CENTER_ALIGN;
|
4130 | var sinPhi = Math.sin(phi);
|
4131 | var cosPhi = Math.cos(phi);
|
4132 | var x = cosPhi * cosTheta;
|
4133 | var y = sinTheta;
|
4134 | var z = sinPhi * cosTheta;
|
4135 | var u = lngIdx / longitudeBands;
|
4136 | var v = latIdx / latitudeBands;
|
4137 | textureCoordData.push(u, v);
|
4138 | vertexPositionData.push(radius * x, radius * y, radius * z);
|
4139 |
|
4140 | if (lngIdx !== longitudeBands && latIdx !== latitudeBands) {
|
4141 | var a = latIdx * (longitudeBands + 1) + lngIdx;
|
4142 | var b = a + longitudeBands + 1;
|
4143 | indexData.push(a, b, a + 1, b, b + 1, a + 1);
|
4144 | }
|
4145 | }
|
4146 | }
|
4147 |
|
4148 | var SphereRenderer =
|
4149 |
|
4150 | function (_super) {
|
4151 | __extends(SphereRenderer, _super);
|
4152 |
|
4153 | function SphereRenderer(format) {
|
4154 | var _this = _super.call(this) || this;
|
4155 |
|
4156 | _this._stereoFormat = format;
|
4157 | return _this;
|
4158 | }
|
4159 |
|
4160 | var __proto = SphereRenderer.prototype;
|
4161 |
|
4162 | __proto.render = function (ctx) {
|
4163 | var gl = ctx.gl,
|
4164 | shaderProgram = ctx.shaderProgram;
|
4165 | var leftEyeScaleOffset;
|
4166 | var rightEyeScaleOffset;
|
4167 |
|
4168 | switch (this._stereoFormat) {
|
4169 | case STEREO_FORMAT.TOP_BOTTOM:
|
4170 | leftEyeScaleOffset = [1, 0.5, 0, 0];
|
4171 | rightEyeScaleOffset = [1, 0.5, 0, 0.5];
|
4172 | break;
|
4173 |
|
4174 | case STEREO_FORMAT.LEFT_RIGHT:
|
4175 | leftEyeScaleOffset = [0.5, 1, 0, 0];
|
4176 | rightEyeScaleOffset = [0.5, 1, 0.5, 0];
|
4177 | break;
|
4178 |
|
4179 | default:
|
4180 | leftEyeScaleOffset = [1, 1, 0, 0];
|
4181 | rightEyeScaleOffset = [1, 1, 0, 0];
|
4182 | }
|
4183 |
|
4184 | var uTexScaleOffset = gl.getUniformLocation(shaderProgram, "uTexScaleOffset");
|
4185 | gl.uniform4fv(uTexScaleOffset, __spread(leftEyeScaleOffset, rightEyeScaleOffset));
|
4186 |
|
4187 | _super.prototype.render.call(this, ctx);
|
4188 | };
|
4189 |
|
4190 | __proto.getVertexPositionData = function () {
|
4191 | return SphereRenderer._VERTEX_POSITION_DATA;
|
4192 | };
|
4193 |
|
4194 | __proto.getIndexData = function () {
|
4195 | return SphereRenderer._INDEX_DATA;
|
4196 | };
|
4197 |
|
4198 | __proto.getTextureCoordData = function () {
|
4199 | return SphereRenderer._TEXTURE_COORD_DATA;
|
4200 | };
|
4201 |
|
4202 | __proto.getVertexShaderSource = function () {
|
4203 | return "\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nuniform float uEye;\nuniform vec4 uTexScaleOffset[2];\nvarying highp vec2 vTextureCoord;\nvoid main(void) {\n vec4 scaleOffset = uTexScaleOffset[int(uEye)];\n vTextureCoord = aTextureCoord.xy * scaleOffset.xy + scaleOffset.zw;\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}";
|
4204 | };
|
4205 |
|
4206 | __proto.getFragmentShaderSource = function () {
|
4207 | return "\nprecision highp float;\nvarying highp vec2 vTextureCoord;\nuniform sampler2D uSampler;\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vTextureCoord.st);\n}";
|
4208 | };
|
4209 |
|
4210 | __proto.updateTexture = function (gl, image) {
|
4211 | WebGLUtils.texImage2D(gl, gl.TEXTURE_2D, this._getPixelSource(image));
|
4212 | };
|
4213 |
|
4214 | __proto.bindTexture = function (gl, texture, image) {
|
4215 |
|
4216 | var _a = this.getDimension(image),
|
4217 | width = _a.width,
|
4218 | height = _a.height;
|
4219 |
|
4220 | var size = Math.max(width, height);
|
4221 | var maxSize = WebGLUtils.getMaxTextureSize(gl);
|
4222 |
|
4223 | if (size > maxSize) {
|
4224 | this._triggerError("Image width(" + width + ") exceeds device limit(" + maxSize + "))");
|
4225 |
|
4226 | return;
|
4227 | }
|
4228 |
|
4229 |
|
4230 | this._initPixelSource(image);
|
4231 |
|
4232 | gl.activeTexture(gl.TEXTURE0);
|
4233 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
4234 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
4235 | this.updateTexture(gl, image);
|
4236 | };
|
4237 |
|
4238 | SphereRenderer._VERTEX_POSITION_DATA = vertexPositionData;
|
4239 | SphereRenderer._TEXTURE_COORD_DATA = textureCoordData;
|
4240 | SphereRenderer._INDEX_DATA = indexData;
|
4241 | return SphereRenderer;
|
4242 | }(Renderer);
|
4243 |
|
4244 | var MIN_ASPECT_RATIO_FOR_FULL_PANORAMA = 6;
|
4245 | var longitudeBands$1 = 60;
|
4246 | var textureCoordData$1 = [];
|
4247 | var vertexPositionData$1 = [];
|
4248 | var indexData$1 = [];
|
4249 |
|
4250 | var CylinderRenderer =
|
4251 |
|
4252 | function (_super) {
|
4253 | __extends(CylinderRenderer, _super);
|
4254 |
|
4255 | function CylinderRenderer() {
|
4256 | return _super !== null && _super.apply(this, arguments) || this;
|
4257 | }
|
4258 |
|
4259 | var __proto = CylinderRenderer.prototype;
|
4260 |
|
4261 | __proto.getVertexPositionData = function () {
|
4262 | return CylinderRenderer._VERTEX_POSITION_DATA;
|
4263 | };
|
4264 |
|
4265 | __proto.getIndexData = function () {
|
4266 | return CylinderRenderer._INDEX_DATA;
|
4267 | };
|
4268 |
|
4269 | __proto.getTextureCoordData = function () {
|
4270 | return CylinderRenderer._TEXTURE_COORD_DATA;
|
4271 | };
|
4272 |
|
4273 | __proto.getVertexShaderSource = function () {
|
4274 | return "\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvarying highp vec2 vTextureCoord;\nvoid main(void) {\n vTextureCoord = aTextureCoord;\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}";
|
4275 | };
|
4276 |
|
4277 | __proto.getFragmentShaderSource = function () {
|
4278 | return "\nprecision highp float;\nvarying highp vec2 vTextureCoord;\nuniform sampler2D uSampler;\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));\n}";
|
4279 | };
|
4280 |
|
4281 | __proto.updateTexture = function (gl, image) {
|
4282 | WebGLUtils.texImage2D(gl, gl.TEXTURE_2D, this._getPixelSource(image));
|
4283 | };
|
4284 |
|
4285 | __proto.bindTexture = function (gl, texture, image) {
|
4286 |
|
4287 | var _a = this.getDimension(image),
|
4288 | width = _a.width,
|
4289 | height = _a.height;
|
4290 |
|
4291 | var size = Math.max(width, height);
|
4292 | var maxSize = WebGLUtils.getMaxTextureSize(gl);
|
4293 | var resizeDimension;
|
4294 |
|
4295 | if (size > maxSize) {
|
4296 | this._triggerError("Image width(" + width + ") exceeds device texture limit(" + maxSize + "))");
|
4297 |
|
4298 | |
4299 |
|
4300 |
|
4301 |
|
4302 |
|
4303 | resizeDimension = width > height ? {
|
4304 | width: maxSize,
|
4305 | height: maxSize * height / width
|
4306 | } : {
|
4307 | width: maxSize * width / height,
|
4308 | height: maxSize
|
4309 | };
|
4310 | }
|
4311 |
|
4312 |
|
4313 | this._initPixelSource(image, resizeDimension);
|
4314 |
|
4315 | gl.activeTexture(gl.TEXTURE0);
|
4316 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
4317 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
4318 | this.updateTexture(gl, image);
|
4319 | };
|
4320 |
|
4321 | __proto.updateShaderData = function (_a) {
|
4322 | var _b = _a.imageAspectRatio,
|
4323 | imageAspectRatio = _b === void 0 ? MIN_ASPECT_RATIO_FOR_FULL_PANORAMA : _b;
|
4324 | var lngIdx;
|
4325 | var cylinderMaxRadian;
|
4326 | var halfCylinderY;
|
4327 | var rotated;
|
4328 | var aspectRatio;
|
4329 |
|
4330 | if (imageAspectRatio < 1) {
|
4331 | |
4332 |
|
4333 |
|
4334 |
|
4335 | rotated = true;
|
4336 | aspectRatio = 1 / imageAspectRatio;
|
4337 | } else {
|
4338 | rotated = false;
|
4339 | aspectRatio = imageAspectRatio;
|
4340 | }
|
4341 |
|
4342 | if (aspectRatio >= MIN_ASPECT_RATIO_FOR_FULL_PANORAMA) {
|
4343 | var fov = 360 / aspectRatio;
|
4344 | cylinderMaxRadian = 2 * Math.PI;
|
4345 |
|
4346 | halfCylinderY = Math.tan(glMatrix.glMatrix.toRadian(fov / 2));
|
4347 | } else {
|
4348 | cylinderMaxRadian = aspectRatio;
|
4349 | halfCylinderY = 0.5;
|
4350 | }
|
4351 |
|
4352 |
|
4353 | textureCoordData$1.length = 0;
|
4354 | vertexPositionData$1.length = 0;
|
4355 | indexData$1.length = 0;
|
4356 | var CYLIDER_Y = [-halfCylinderY, halfCylinderY];
|
4357 | var startAngleForCenterAlign = Math.PI / 2 + (2 * Math.PI - cylinderMaxRadian) / 2;
|
4358 |
|
4359 |
|
4360 | for (var yIdx = 0, yLength = CYLIDER_Y.length; yIdx < yLength
|
4361 |
|
4362 | ; yIdx++) {
|
4363 | for (lngIdx = 0; lngIdx <= longitudeBands$1; lngIdx++) {
|
4364 | var angle = startAngleForCenterAlign + lngIdx / longitudeBands$1 * cylinderMaxRadian;
|
4365 | var x = Math.cos(angle);
|
4366 | var y = CYLIDER_Y[yIdx];
|
4367 | var z = Math.sin(angle);
|
4368 | var u = void 0;
|
4369 | var v = void 0;
|
4370 |
|
4371 | if (rotated) {
|
4372 |
|
4373 | u = 1 - yIdx;
|
4374 |
|
4375 | v = lngIdx / longitudeBands$1;
|
4376 | } else {
|
4377 |
|
4378 | u = lngIdx / longitudeBands$1;
|
4379 | v = yIdx;
|
4380 | }
|
4381 |
|
4382 | textureCoordData$1.push(u, v);
|
4383 | vertexPositionData$1.push(x, y, z);
|
4384 |
|
4385 | if (yIdx === 0 && lngIdx < longitudeBands$1) {
|
4386 | var a = lngIdx;
|
4387 | var b = a + longitudeBands$1 + 1;
|
4388 | indexData$1.push(a, b, a + 1, b, b + 1, a + 1);
|
4389 | }
|
4390 | }
|
4391 | }
|
4392 | };
|
4393 |
|
4394 | CylinderRenderer._VERTEX_POSITION_DATA = vertexPositionData$1;
|
4395 | CylinderRenderer._TEXTURE_COORD_DATA = textureCoordData$1;
|
4396 | CylinderRenderer._INDEX_DATA = indexData$1;
|
4397 | return CylinderRenderer;
|
4398 | }(Renderer);
|
4399 |
|
4400 | var VR_DISPLAY_PRESENT_CHANGE = "vrdisplaypresentchange";
|
4401 | var DEFAULT_LEFT_BOUNDS = [0, 0, 0.5, 1];
|
4402 | var DEFAULT_RIGHT_BOUNDS = [0.5, 0, 0.5, 1];
|
4403 | var EYES = {
|
4404 | LEFT: "left",
|
4405 | RIGHT: "right"
|
4406 | };
|
4407 |
|
4408 | var VRManager =
|
4409 |
|
4410 | function () {
|
4411 | function VRManager() {
|
4412 | var _this = this;
|
4413 |
|
4414 | this.destroy = function () {
|
4415 | var vrDisplay = _this._vrDisplay;
|
4416 |
|
4417 | _this.removeEndCallback(_this.destroy);
|
4418 |
|
4419 | if (vrDisplay && vrDisplay.isPresenting) {
|
4420 | void vrDisplay.exitPresent();
|
4421 | }
|
4422 |
|
4423 | _this._clear();
|
4424 | };
|
4425 |
|
4426 | this._frameData = new window.VRFrameData();
|
4427 |
|
4428 | this._clear();
|
4429 | }
|
4430 |
|
4431 | var __proto = VRManager.prototype;
|
4432 | Object.defineProperty(__proto, "context", {
|
4433 | get: function () {
|
4434 | return this._vrDisplay;
|
4435 | },
|
4436 | enumerable: false,
|
4437 | configurable: true
|
4438 | });
|
4439 |
|
4440 | __proto.canRender = function () {
|
4441 | return Boolean(this._vrDisplay);
|
4442 | };
|
4443 |
|
4444 | __proto.beforeRender = function (gl) {
|
4445 |
|
4446 | gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
4447 | };
|
4448 |
|
4449 | __proto.afterRender = function () {
|
4450 | this._vrDisplay.submitFrame();
|
4451 | };
|
4452 |
|
4453 | __proto.getEyeParams = function (gl) {
|
4454 | var display = this._vrDisplay;
|
4455 | var halfWidth = gl.drawingBufferWidth * 0.5;
|
4456 | var height = gl.drawingBufferHeight;
|
4457 | var frameData = this._frameData;
|
4458 | display.getFrameData(frameData);
|
4459 | var leftMVMatrix = frameData.leftViewMatrix;
|
4460 | var rightMVMatrix = frameData.rightViewMatrix;
|
4461 | glMatrix.mat4.rotateY(leftMVMatrix, leftMVMatrix, this._yawOffset);
|
4462 | glMatrix.mat4.rotateY(rightMVMatrix, rightMVMatrix, this._yawOffset);
|
4463 | return [{
|
4464 | viewport: [0, 0, halfWidth, height],
|
4465 | mvMatrix: leftMVMatrix,
|
4466 | pMatrix: frameData.leftProjectionMatrix
|
4467 | }, {
|
4468 | viewport: [halfWidth, 0, halfWidth, height],
|
4469 | mvMatrix: rightMVMatrix,
|
4470 | pMatrix: frameData.rightProjectionMatrix
|
4471 | }];
|
4472 | };
|
4473 |
|
4474 | __proto.isPresenting = function () {
|
4475 | return Boolean(this._vrDisplay && this._vrDisplay.isPresenting);
|
4476 | };
|
4477 |
|
4478 | __proto.addEndCallback = function (callback) {
|
4479 | window.addEventListener(VR_DISPLAY_PRESENT_CHANGE, callback);
|
4480 | };
|
4481 |
|
4482 | __proto.removeEndCallback = function (callback) {
|
4483 | window.removeEventListener(VR_DISPLAY_PRESENT_CHANGE, callback);
|
4484 | };
|
4485 |
|
4486 | __proto.requestPresent = function (canvas) {
|
4487 | var _this = this;
|
4488 |
|
4489 | return navigator.getVRDisplays().then(function (displays) {
|
4490 | var vrDisplay = displays.length && displays[0];
|
4491 |
|
4492 | if (!vrDisplay) {
|
4493 | return Promise$1.reject(new Error("No displays available."));
|
4494 | }
|
4495 |
|
4496 | if (!vrDisplay.capabilities.canPresent) {
|
4497 | return Promise$1.reject(new Error("Display lacking capability to present."));
|
4498 | }
|
4499 |
|
4500 | return vrDisplay.requestPresent([{
|
4501 | source: canvas
|
4502 | }]).then(function () {
|
4503 | var leftEye = vrDisplay.getEyeParameters(EYES.LEFT);
|
4504 | var rightEye = vrDisplay.getEyeParameters(EYES.RIGHT);
|
4505 | canvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
|
4506 | canvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);
|
4507 |
|
4508 | _this._setDisplay(vrDisplay);
|
4509 | });
|
4510 | });
|
4511 | };
|
4512 |
|
4513 | __proto.setYawOffset = function (offset) {
|
4514 | this._yawOffset = offset;
|
4515 | };
|
4516 |
|
4517 | __proto._setDisplay = function (vrDisplay) {
|
4518 | this._vrDisplay = vrDisplay;
|
4519 | var layers = vrDisplay.getLayers();
|
4520 |
|
4521 | if (layers.length) {
|
4522 | var layer = layers[0];
|
4523 | this._leftBounds = layer.leftBounds;
|
4524 | this._rightBounds = layer.rightBounds;
|
4525 | }
|
4526 |
|
4527 | this.addEndCallback(this.destroy);
|
4528 | };
|
4529 |
|
4530 | __proto._clear = function () {
|
4531 | this._vrDisplay = null;
|
4532 | this._leftBounds = DEFAULT_LEFT_BOUNDS;
|
4533 | this._rightBounds = DEFAULT_RIGHT_BOUNDS;
|
4534 | this._yawOffset = 0;
|
4535 | };
|
4536 |
|
4537 | return VRManager;
|
4538 | }();
|
4539 |
|
4540 | var XR_REFERENCE_SPACE = "local";
|
4541 |
|
4542 | var XRManager =
|
4543 |
|
4544 | function () {
|
4545 | function XRManager(options) {
|
4546 | var _this = this;
|
4547 |
|
4548 | if (options === void 0) {
|
4549 | options = {};
|
4550 | }
|
4551 |
|
4552 | this.destroy = function () {
|
4553 | var xrSession = _this._xrSession;
|
4554 |
|
4555 | _this.removeEndCallback(_this.destroy);
|
4556 |
|
4557 | if (xrSession) {
|
4558 |
|
4559 | xrSession.end().then(function () {
|
4560 | return void 0;
|
4561 | }, function () {
|
4562 | return void 0;
|
4563 | });
|
4564 | }
|
4565 |
|
4566 | _this._clear();
|
4567 | };
|
4568 |
|
4569 | this._clear();
|
4570 |
|
4571 | this._options = options;
|
4572 | }
|
4573 |
|
4574 | var __proto = XRManager.prototype;
|
4575 | Object.defineProperty(__proto, "context", {
|
4576 | get: function () {
|
4577 | return this._xrSession;
|
4578 | },
|
4579 | enumerable: false,
|
4580 | configurable: true
|
4581 | });
|
4582 |
|
4583 | __proto.canRender = function (frame) {
|
4584 | var pose = frame.getViewerPose(this._xrRefSpace);
|
4585 | return Boolean(pose);
|
4586 | };
|
4587 |
|
4588 | __proto.beforeRender = function (gl, frame) {
|
4589 | var session = frame.session;
|
4590 | var baseLayer = session.renderState.baseLayer;
|
4591 | gl.bindFramebuffer(gl.FRAMEBUFFER, baseLayer.framebuffer);
|
4592 | };
|
4593 |
|
4594 |
|
4595 | __proto.afterRender = function () {};
|
4596 |
|
4597 | __proto.getEyeParams = function (gl, frame) {
|
4598 | var _this = this;
|
4599 |
|
4600 | var session = frame.session;
|
4601 | var pose = frame.getViewerPose(this._xrRefSpace);
|
4602 |
|
4603 | if (!pose) {
|
4604 |
|
4605 | return null;
|
4606 | }
|
4607 |
|
4608 | var glLayer = session.renderState.baseLayer;
|
4609 | return pose.views.map(function (view) {
|
4610 | var viewport = glLayer.getViewport(view);
|
4611 | var mvMatrix = view.transform.inverse.matrix;
|
4612 |
|
4613 | if (IS_SAFARI_ON_DESKTOP) {
|
4614 | glMatrix.mat4.rotateX(mvMatrix, mvMatrix, glMatrix.glMatrix.toRadian(180));
|
4615 | }
|
4616 |
|
4617 | glMatrix.mat4.rotateY(mvMatrix, mvMatrix, _this._yawOffset);
|
4618 | return {
|
4619 | viewport: [viewport.x, viewport.y, viewport.width, viewport.height],
|
4620 | mvMatrix: mvMatrix,
|
4621 | pMatrix: view.projectionMatrix
|
4622 | };
|
4623 | });
|
4624 | };
|
4625 |
|
4626 | __proto.isPresenting = function () {
|
4627 | return this._presenting;
|
4628 | };
|
4629 |
|
4630 | __proto.addEndCallback = function (callback) {
|
4631 | var _a;
|
4632 |
|
4633 | (_a = this._xrSession) === null || _a === void 0 ? void 0 : _a.addEventListener("end", callback);
|
4634 | };
|
4635 |
|
4636 | __proto.removeEndCallback = function (callback) {
|
4637 | var _a;
|
4638 |
|
4639 | (_a = this._xrSession) === null || _a === void 0 ? void 0 : _a.removeEventListener("end", callback);
|
4640 | };
|
4641 |
|
4642 | __proto.requestPresent = function (canvas, gl) {
|
4643 | return __awaiter(this, void 0, void 0, function () {
|
4644 | var options, attributes;
|
4645 |
|
4646 | var _this = this;
|
4647 |
|
4648 | return __generator(this, function (_a) {
|
4649 | switch (_a.label) {
|
4650 | case 0:
|
4651 | options = merge({
|
4652 | requiredFeatures: [XR_REFERENCE_SPACE]
|
4653 | }, this._options);
|
4654 | attributes = gl.getContextAttributes();
|
4655 | if (!(attributes && attributes.xrCompatible !== true)) return [3
|
4656 |
|
4657 | , 2];
|
4658 | return [4
|
4659 |
|
4660 | , gl.makeXRCompatible()];
|
4661 |
|
4662 | case 1:
|
4663 | _a.sent();
|
4664 |
|
4665 | _a.label = 2;
|
4666 |
|
4667 | case 2:
|
4668 | return [2
|
4669 |
|
4670 | , navigator.xr.requestSession("immersive-vr", options).then(function (session) {
|
4671 | var xrLayer = new window.XRWebGLLayer(session, gl);
|
4672 | session.updateRenderState({
|
4673 | baseLayer: xrLayer
|
4674 | });
|
4675 | return session.requestReferenceSpace(XR_REFERENCE_SPACE).then(function (refSpace) {
|
4676 | _this._setSession(session, xrLayer, refSpace);
|
4677 | });
|
4678 | })];
|
4679 | }
|
4680 | });
|
4681 | });
|
4682 | };
|
4683 |
|
4684 | __proto.setYawOffset = function (offset) {
|
4685 | this._yawOffset = offset;
|
4686 | };
|
4687 |
|
4688 | __proto._setSession = function (session, xrLayer, refSpace) {
|
4689 | this._xrSession = session;
|
4690 | this._xrLayer = xrLayer;
|
4691 | this._xrRefSpace = refSpace;
|
4692 | this._presenting = true;
|
4693 | this.addEndCallback(this.destroy);
|
4694 | };
|
4695 |
|
4696 | __proto._clear = function () {
|
4697 | this._xrSession = null;
|
4698 | this._xrLayer = null;
|
4699 | this._xrRefSpace = null;
|
4700 | this._presenting = false;
|
4701 | this._yawOffset = 0;
|
4702 | this._options = {};
|
4703 | };
|
4704 |
|
4705 | return XRManager;
|
4706 | }();
|
4707 |
|
4708 | var WebGLAnimator =
|
4709 |
|
4710 | function () {
|
4711 | function WebGLAnimator() {
|
4712 | var _this = this;
|
4713 | |
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 | this._onLoop = function () {
|
4719 | var args = [];
|
4720 |
|
4721 | for (var _i = 0; _i < arguments.length; _i++) {
|
4722 | args[_i] = arguments[_i];
|
4723 | }
|
4724 |
|
4725 | _this._callback.apply(_this, __spread(args));
|
4726 |
|
4727 | _this._rafId = _this._context.requestAnimationFrame(_this._onLoop);
|
4728 | };
|
4729 | |
4730 |
|
4731 |
|
4732 |
|
4733 |
|
4734 |
|
4735 |
|
4736 |
|
4737 |
|
4738 |
|
4739 |
|
4740 | this._onLoopNextTick = function () {
|
4741 | var args = [];
|
4742 |
|
4743 | for (var _i = 0; _i < arguments.length; _i++) {
|
4744 | args[_i] = arguments[_i];
|
4745 | }
|
4746 |
|
4747 | var before = performance.now();
|
4748 |
|
4749 | _this._callback.apply(_this, __spread(args));
|
4750 |
|
4751 | var diff = performance.now() - before;
|
4752 |
|
4753 | if (_this._rafTimer >= 0) {
|
4754 | clearTimeout(_this._rafTimer);
|
4755 | _this._rafTimer = -1;
|
4756 | }
|
4757 |
|
4758 |
|
4759 |
|
4760 | if (diff < 16) {
|
4761 | _this._rafId = _this._context.requestAnimationFrame(_this._onLoop);
|
4762 | } else {
|
4763 |
|
4764 | _this._rafTimer = window.setTimeout(_this._onLoop, 0);
|
4765 | }
|
4766 | };
|
4767 |
|
4768 | this._callback = null;
|
4769 | this._context = window;
|
4770 | this._rafId = -1;
|
4771 | this._rafTimer = -1;
|
4772 | }
|
4773 |
|
4774 | var __proto = WebGLAnimator.prototype;
|
4775 |
|
4776 | __proto.setCallback = function (callback) {
|
4777 | this._callback = callback;
|
4778 | };
|
4779 |
|
4780 | __proto.setContext = function (context) {
|
4781 | this._context = context;
|
4782 | };
|
4783 |
|
4784 | __proto.start = function () {
|
4785 | var context = this._context;
|
4786 | var callback = this._callback;
|
4787 |
|
4788 | if (!context || !callback) return;
|
4789 |
|
4790 | if (this._rafId >= 0 || this._rafTimer >= 0) return;
|
4791 |
|
4792 | if (IS_SAFARI_ON_DESKTOP) {
|
4793 | this._rafId = context.requestAnimationFrame(this._onLoopNextTick);
|
4794 | } else {
|
4795 | this._rafId = context.requestAnimationFrame(this._onLoop);
|
4796 | }
|
4797 | };
|
4798 |
|
4799 | __proto.stop = function () {
|
4800 | if (this._rafId >= 0) {
|
4801 | this._context.cancelAnimationFrame(this._rafId);
|
4802 | }
|
4803 |
|
4804 | if (this._rafTimer >= 0) {
|
4805 | clearTimeout(this._rafTimer);
|
4806 | }
|
4807 |
|
4808 | this._rafId = -1;
|
4809 | this._rafTimer = -1;
|
4810 | };
|
4811 |
|
4812 | return WebGLAnimator;
|
4813 | }();
|
4814 |
|
4815 | var ImageType = PROJECTION_TYPE;
|
4816 |
|
4817 | var DEVICE_PIXEL_RATIO = devicePixelRatio || 1;
|
4818 |
|
4819 | if (DEVICE_PIXEL_RATIO > 2) {
|
4820 | DEVICE_PIXEL_RATIO = 2;
|
4821 | }
|
4822 |
|
4823 | |
4824 |
|
4825 |
|
4826 |
|
4827 |
|
4828 |
|
4829 |
|
4830 | var EVENTS$1 = {
|
4831 | BIND_TEXTURE: "bindTexture",
|
4832 | IMAGE_LOADED: "imageLoaded",
|
4833 | ERROR: "error",
|
4834 | RENDERING_CONTEXT_LOST: "renderingContextLost",
|
4835 | RENDERING_CONTEXT_RESTORE: "renderingContextRestore"
|
4836 | };
|
4837 | var ERROR_TYPE$1 = {
|
4838 | INVALID_DEVICE: 10,
|
4839 | NO_WEBGL: 11,
|
4840 | FAIL_IMAGE_LOAD: 12,
|
4841 | RENDERER_ERROR: 13
|
4842 | };
|
4843 |
|
4844 | var PanoImageRenderer =
|
4845 |
|
4846 | function (_super) {
|
4847 | __extends(PanoImageRenderer, _super);
|
4848 |
|
4849 | function PanoImageRenderer(image, width, height, isVideo, container, canvasClass, sphericalConfig, renderingContextAttributes) {
|
4850 | var _this =
|
4851 | _super.call(this) || this;
|
4852 |
|
4853 | _this.textureCoordBuffer = null;
|
4854 | _this.vertexBuffer = null;
|
4855 | _this.indexBuffer = null;
|
4856 |
|
4857 | _this.exitVR = function () {
|
4858 | var vr = _this._vr;
|
4859 | var gl = _this.context;
|
4860 | var animator = _this._animator;
|
4861 | if (!vr) return;
|
4862 | vr.removeEndCallback(_this.exitVR);
|
4863 | vr.destroy();
|
4864 | _this._vr = null;
|
4865 |
|
4866 | if (IS_IOS) {
|
4867 | _this._restoreStyle();
|
4868 | }
|
4869 |
|
4870 | _this.updateViewportDimensions(_this.width, _this.height);
|
4871 |
|
4872 | _this._updateViewport();
|
4873 |
|
4874 | gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
4875 |
|
4876 | _this._bindBuffers();
|
4877 |
|
4878 | _this._shouldForceDraw = true;
|
4879 | animator.stop();
|
4880 | animator.setContext(window);
|
4881 | animator.setCallback(_this._render.bind(_this));
|
4882 | animator.start();
|
4883 | };
|
4884 |
|
4885 | _this._renderStereo = function (time, frame) {
|
4886 | var e_1, _a;
|
4887 |
|
4888 | var vr = _this._vr;
|
4889 | var gl = _this.context;
|
4890 | var eyeParams = vr.getEyeParams(gl, frame);
|
4891 | if (!eyeParams) return;
|
4892 | vr.beforeRender(gl, frame);
|
4893 |
|
4894 | try {
|
4895 |
|
4896 | for (var _b = __values([0, 1]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
4897 | var eyeIndex = _c.value;
|
4898 | var eyeParam = eyeParams[eyeIndex];
|
4899 | _this.mvMatrix = eyeParam.mvMatrix;
|
4900 | _this.pMatrix = eyeParam.pMatrix;
|
4901 | gl.viewport.apply(gl, __spread(eyeParam.viewport));
|
4902 | gl.uniform1f(_this.shaderProgram.uEye, eyeIndex);
|
4903 |
|
4904 | _this._bindBuffers();
|
4905 |
|
4906 | _this._draw();
|
4907 | }
|
4908 | } catch (e_1_1) {
|
4909 | e_1 = {
|
4910 | error: e_1_1
|
4911 | };
|
4912 | } finally {
|
4913 | try {
|
4914 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
4915 | } finally {
|
4916 | if (e_1) throw e_1.error;
|
4917 | }
|
4918 | }
|
4919 |
|
4920 | vr.afterRender();
|
4921 | };
|
4922 |
|
4923 | _this._onFirstVRFrame = function (time, frame) {
|
4924 | var vr = _this._vr;
|
4925 | var gl = _this.context;
|
4926 | var animator = _this._animator;
|
4927 |
|
4928 | if (!vr.canRender(frame)) return;
|
4929 | var minusZDir = glMatrix.vec3.fromValues(0, 0, -1);
|
4930 | var eyeParam = vr.getEyeParams(gl, frame)[0];
|
4931 |
|
4932 | var mvMatrix = glMatrix.mat3.fromMat4(glMatrix.mat3.create(), eyeParam.mvMatrix);
|
4933 | var pMatrix = glMatrix.mat3.fromMat4(glMatrix.mat3.create(), eyeParam.pMatrix);
|
4934 | var mvInv = glMatrix.mat3.invert(glMatrix.mat3.create(), mvMatrix);
|
4935 | var pInv = glMatrix.mat3.invert(glMatrix.mat3.create(), pMatrix);
|
4936 | var viewDir = glMatrix.vec3.transformMat3(glMatrix.vec3.create(), minusZDir, pInv);
|
4937 | glMatrix.vec3.transformMat3(viewDir, viewDir, mvInv);
|
4938 | var yawOffset = util.yawOffsetBetween(viewDir, glMatrix.vec3.fromValues(0, 0, 1));
|
4939 |
|
4940 | if (yawOffset === 0) {
|
4941 |
|
4942 |
|
4943 | return;
|
4944 | }
|
4945 |
|
4946 | vr.setYawOffset(yawOffset);
|
4947 | animator.setCallback(_this._renderStereo);
|
4948 | };
|
4949 |
|
4950 | _this.sphericalConfig = sphericalConfig;
|
4951 | _this.fieldOfView = sphericalConfig.fieldOfView;
|
4952 | _this.width = width;
|
4953 | _this.height = height;
|
4954 | _this._lastQuaternion = null;
|
4955 | _this._lastYaw = null;
|
4956 | _this._lastPitch = null;
|
4957 | _this._lastFieldOfView = null;
|
4958 | _this.pMatrix = glMatrix.mat4.create();
|
4959 | _this.mvMatrix = glMatrix.mat4.create();
|
4960 |
|
4961 | glMatrix.mat4.perspective(_this.pMatrix, glMatrix.glMatrix.toRadian(_this.fieldOfView), width / height, 0.1, 100);
|
4962 | _this.textureCoordBuffer = null;
|
4963 | _this.vertexBuffer = null;
|
4964 | _this.indexBuffer = null;
|
4965 | _this.canvas = _this._initCanvas(container, canvasClass, width, height);
|
4966 |
|
4967 | _this._setDefaultCanvasStyle();
|
4968 |
|
4969 | _this._wrapper = null;
|
4970 |
|
4971 | _this._wrapperOrigStyle = null;
|
4972 | _this._renderingContextAttributes = renderingContextAttributes;
|
4973 | _this._image = null;
|
4974 | _this._imageConfig = null;
|
4975 | _this._imageIsReady = false;
|
4976 | _this._shouldForceDraw = false;
|
4977 | _this._keepUpdate = false;
|
4978 |
|
4979 | _this._onContentLoad = _this._onContentLoad.bind(_this);
|
4980 | _this._onContentError = _this._onContentError.bind(_this);
|
4981 | _this._animator = new WebGLAnimator();
|
4982 |
|
4983 | _this._vr = null;
|
4984 |
|
4985 | if (image) {
|
4986 | _this.setImage({
|
4987 | image: image,
|
4988 | imageType: sphericalConfig.imageType,
|
4989 | isVideo: isVideo,
|
4990 | cubemapConfig: sphericalConfig.cubemapConfig
|
4991 | });
|
4992 | }
|
4993 |
|
4994 | return _this;
|
4995 | }
|
4996 |
|
4997 |
|
4998 | var __proto = PanoImageRenderer.prototype;
|
4999 |
|
5000 | __proto.setYawPitchControl = function (yawPitchControl) {
|
5001 | this._yawPitchControl = yawPitchControl;
|
5002 | };
|
5003 |
|
5004 | __proto.getContent = function () {
|
5005 | return this._image;
|
5006 | };
|
5007 |
|
5008 | __proto.setImage = function (_a) {
|
5009 | var image = _a.image,
|
5010 | imageType = _a.imageType,
|
5011 | _b = _a.isVideo,
|
5012 | isVideo = _b === void 0 ? false : _b,
|
5013 | cubemapConfig = _a.cubemapConfig;
|
5014 | this._imageIsReady = false;
|
5015 | this._isVideo = isVideo;
|
5016 | this._imageConfig = __assign({
|
5017 |
|
5018 | order: imageType === ImageType.CUBEMAP ? "RLUDBF" : "RLUDFB",
|
5019 | tileConfig: {
|
5020 | flipHorizontal: false,
|
5021 | rotation: 0
|
5022 | },
|
5023 | trim: 0
|
5024 | }, cubemapConfig);
|
5025 |
|
5026 | this._setImageType(imageType);
|
5027 |
|
5028 | if (this._contentLoader) {
|
5029 | this._contentLoader.destroy();
|
5030 | }
|
5031 |
|
5032 | this._contentLoader = new ImReady().on("ready", this._onContentLoad).on("error", this._onContentError);
|
5033 |
|
5034 | if (isVideo) {
|
5035 | this._image = toVideoElement(image);
|
5036 |
|
5037 | this._contentLoader.check([this._image]);
|
5038 |
|
5039 | this._keepUpdate = true;
|
5040 | } else {
|
5041 | this._image = toImageElement(image);
|
5042 |
|
5043 | this._contentLoader.check(Array.isArray(this._image) ? this._image : [this._image]);
|
5044 |
|
5045 | this._keepUpdate = false;
|
5046 | }
|
5047 | };
|
5048 |
|
5049 | __proto.isImageLoaded = function () {
|
5050 | return !!this._image && this._imageIsReady && (!this._isVideo || this._image.readyState >= 2
|
5051 |
|
5052 | );
|
5053 | };
|
5054 |
|
5055 | __proto.bindTexture = function () {
|
5056 | var _this = this;
|
5057 |
|
5058 | return new Promise$1(function (res, rej) {
|
5059 | var contentLoader = _this._contentLoader;
|
5060 |
|
5061 | if (!_this._image) {
|
5062 | return rej("Image is not defined");
|
5063 | }
|
5064 |
|
5065 | if (!contentLoader) {
|
5066 | return rej("ImageLoader is not initialized");
|
5067 | }
|
5068 |
|
5069 | if (contentLoader.isReady()) {
|
5070 | _this._bindTexture();
|
5071 |
|
5072 | res();
|
5073 | } else {
|
5074 | contentLoader.check(Array.isArray(_this._image) ? _this._image : [_this._image]);
|
5075 | contentLoader.once("ready", function (e) {
|
5076 | if (e.errorCount > 0) {
|
5077 | rej("Failed to load images.");
|
5078 | } else {
|
5079 | _this._bindTexture();
|
5080 |
|
5081 | res();
|
5082 | }
|
5083 | });
|
5084 | }
|
5085 | });
|
5086 | };
|
5087 |
|
5088 |
|
5089 | __proto.attachTo = function (parentElement) {
|
5090 | if (!this._hasExternalCanvas) {
|
5091 | this.detach();
|
5092 | parentElement.appendChild(this.canvas);
|
5093 | }
|
5094 |
|
5095 | this._wrapper = parentElement;
|
5096 | };
|
5097 |
|
5098 | __proto.forceContextLoss = function () {
|
5099 | if (this.hasRenderingContext()) {
|
5100 | var loseContextExtension = this.context.getExtension("WEBGL_lose_context");
|
5101 |
|
5102 | if (loseContextExtension) {
|
5103 | loseContextExtension.loseContext();
|
5104 | }
|
5105 | }
|
5106 | };
|
5107 |
|
5108 |
|
5109 | __proto.detach = function () {
|
5110 | if (!this._hasExternalCanvas && this.canvas.parentElement) {
|
5111 | this.canvas.parentElement.removeChild(this.canvas);
|
5112 | }
|
5113 | };
|
5114 |
|
5115 | __proto.destroy = function () {
|
5116 | if (this._contentLoader) {
|
5117 | this._contentLoader.destroy();
|
5118 | }
|
5119 |
|
5120 | this._animator.stop();
|
5121 |
|
5122 | this.detach();
|
5123 | this.forceContextLoss();
|
5124 | this.off();
|
5125 | this.canvas.removeEventListener("webglcontextlost", this._onWebglcontextlost);
|
5126 | this.canvas.removeEventListener("webglcontextrestored", this._onWebglcontextrestored);
|
5127 | };
|
5128 |
|
5129 | __proto.hasRenderingContext = function () {
|
5130 | var ctx = this.context;
|
5131 |
|
5132 | if (!ctx || ctx.isContextLost() || !ctx.getProgramParameter(this.shaderProgram, ctx.LINK_STATUS)) {
|
5133 | return false;
|
5134 | }
|
5135 |
|
5136 | return true;
|
5137 | };
|
5138 |
|
5139 | __proto.updateFieldOfView = function (fieldOfView) {
|
5140 | this.fieldOfView = fieldOfView;
|
5141 |
|
5142 | this._updateViewport();
|
5143 | };
|
5144 |
|
5145 | __proto.updateViewportDimensions = function (width, height) {
|
5146 | var viewPortChanged = false;
|
5147 | this.width = width;
|
5148 | this.height = height;
|
5149 | var w = width * DEVICE_PIXEL_RATIO;
|
5150 | var h = height * DEVICE_PIXEL_RATIO;
|
5151 |
|
5152 | if (w !== this.canvas.width) {
|
5153 | this.canvas.width = w;
|
5154 | viewPortChanged = true;
|
5155 | }
|
5156 |
|
5157 | if (h !== this.canvas.height) {
|
5158 | this.canvas.height = h;
|
5159 | viewPortChanged = true;
|
5160 | }
|
5161 |
|
5162 | if (!viewPortChanged) {
|
5163 | return;
|
5164 | }
|
5165 |
|
5166 | this._updateViewport();
|
5167 |
|
5168 | this._shouldForceDraw = true;
|
5169 | };
|
5170 |
|
5171 | __proto.keepUpdate = function (doUpdate) {
|
5172 | if (doUpdate && this.isImageLoaded() === false) {
|
5173 |
|
5174 | this._shouldForceDraw = true;
|
5175 | }
|
5176 |
|
5177 | this._keepUpdate = doUpdate;
|
5178 | };
|
5179 |
|
5180 | __proto.startRender = function () {
|
5181 | this._animator.setCallback(this._render.bind(this));
|
5182 |
|
5183 | this._animator.start();
|
5184 | };
|
5185 |
|
5186 | __proto.stopRender = function () {
|
5187 | this._animator.stop();
|
5188 | };
|
5189 |
|
5190 | __proto.renderWithQuaternion = function (quaternion, fieldOfView) {
|
5191 | if (!this.isImageLoaded()) {
|
5192 | return;
|
5193 | }
|
5194 |
|
5195 | if (this._keepUpdate === false && this._lastQuaternion && glMatrix.quat.exactEquals(this._lastQuaternion, quaternion) && this.fieldOfView && this.fieldOfView === fieldOfView && this._shouldForceDraw === false) {
|
5196 | return;
|
5197 | }
|
5198 |
|
5199 |
|
5200 | if (fieldOfView !== undefined && fieldOfView !== this.fieldOfView) {
|
5201 | this.updateFieldOfView(fieldOfView);
|
5202 | }
|
5203 |
|
5204 | this.mvMatrix = glMatrix.mat4.fromQuat(glMatrix.mat4.create(), quaternion);
|
5205 |
|
5206 | this._draw();
|
5207 |
|
5208 | this._lastQuaternion = glMatrix.quat.clone(quaternion);
|
5209 |
|
5210 | if (this._shouldForceDraw) {
|
5211 | this._shouldForceDraw = false;
|
5212 | }
|
5213 | };
|
5214 |
|
5215 | __proto.renderWithYawPitch = function (yaw, pitch, fieldOfView) {
|
5216 | if (!this.isImageLoaded()) {
|
5217 | return;
|
5218 | }
|
5219 |
|
5220 | if (this._keepUpdate === false && this._lastYaw !== null && this._lastYaw === yaw && this._lastPitch !== null && this._lastPitch === pitch && this.fieldOfView && this.fieldOfView === fieldOfView && this._shouldForceDraw === false) {
|
5221 | return;
|
5222 | }
|
5223 |
|
5224 |
|
5225 | if (fieldOfView !== undefined && fieldOfView !== this.fieldOfView) {
|
5226 | this.updateFieldOfView(fieldOfView);
|
5227 | }
|
5228 |
|
5229 | glMatrix.mat4.identity(this.mvMatrix);
|
5230 | glMatrix.mat4.rotateX(this.mvMatrix, this.mvMatrix, -glMatrix.glMatrix.toRadian(pitch));
|
5231 | glMatrix.mat4.rotateY(this.mvMatrix, this.mvMatrix, -glMatrix.glMatrix.toRadian(yaw));
|
5232 |
|
5233 | this._draw();
|
5234 |
|
5235 | this._lastYaw = yaw;
|
5236 | this._lastPitch = pitch;
|
5237 |
|
5238 | if (this._shouldForceDraw) {
|
5239 | this._shouldForceDraw = false;
|
5240 | }
|
5241 | };
|
5242 | |
5243 |
|
5244 |
|
5245 |
|
5246 |
|
5247 | __proto.getProjectionRenderer = function () {
|
5248 | return this._renderer;
|
5249 | };
|
5250 | |
5251 |
|
5252 |
|
5253 |
|
5254 |
|
5255 | __proto.enterVR = function (options) {
|
5256 | var vr = this._vr;
|
5257 |
|
5258 | if (!WEBXR_SUPPORTED && !navigator.getVRDisplays) {
|
5259 | return Promise$1.reject("VR is not available on this browser.");
|
5260 | }
|
5261 |
|
5262 | if (vr && vr.isPresenting()) {
|
5263 | return Promise$1.resolve("VR already enabled.");
|
5264 | }
|
5265 |
|
5266 | return this._requestPresent(options);
|
5267 | };
|
5268 |
|
5269 | __proto._setImageType = function (imageType) {
|
5270 | var _this = this;
|
5271 |
|
5272 | if (!imageType || this._imageType === imageType) {
|
5273 | return;
|
5274 | }
|
5275 |
|
5276 | this._imageType = imageType;
|
5277 | this._isCubeMap = imageType === ImageType.CUBEMAP;
|
5278 |
|
5279 | if (this._renderer) {
|
5280 | this._renderer.off();
|
5281 | }
|
5282 |
|
5283 | switch (imageType) {
|
5284 | case ImageType.CUBEMAP:
|
5285 | this._renderer = new CubeRenderer();
|
5286 | break;
|
5287 |
|
5288 | case ImageType.CUBESTRIP:
|
5289 | this._renderer = new CubeStripRenderer();
|
5290 | break;
|
5291 |
|
5292 | case ImageType.PANORAMA:
|
5293 | this._renderer = new CylinderRenderer();
|
5294 | break;
|
5295 |
|
5296 | case ImageType.STEREOSCOPIC_EQUI:
|
5297 | this._renderer = new SphereRenderer(this.sphericalConfig.stereoFormat);
|
5298 | break;
|
5299 |
|
5300 | default:
|
5301 | this._renderer = new SphereRenderer(STEREO_FORMAT.NONE);
|
5302 | break;
|
5303 | }
|
5304 |
|
5305 | this._renderer.on(Renderer.EVENTS.ERROR, function (e) {
|
5306 | _this.trigger(new Component.ComponentEvent(EVENTS$1.ERROR, {
|
5307 | type: ERROR_TYPE$1.RENDERER_ERROR,
|
5308 | message: e.message
|
5309 | }));
|
5310 | });
|
5311 |
|
5312 | this._initWebGL();
|
5313 | };
|
5314 |
|
5315 | __proto._initCanvas = function (container, canvasClass, width, height) {
|
5316 | var canvasInContainer = container.querySelector("." + canvasClass);
|
5317 |
|
5318 | var canvas = canvasInContainer || this._createCanvas(canvasClass);
|
5319 |
|
5320 | this._hasExternalCanvas = !!canvasInContainer;
|
5321 | canvas.width = width;
|
5322 | canvas.height = height;
|
5323 | this._onWebglcontextlost = this._onWebglcontextlost.bind(this);
|
5324 | this._onWebglcontextrestored = this._onWebglcontextrestored.bind(this);
|
5325 | canvas.addEventListener("webglcontextlost", this._onWebglcontextlost);
|
5326 | canvas.addEventListener("webglcontextrestored", this._onWebglcontextrestored);
|
5327 | return canvas;
|
5328 | };
|
5329 |
|
5330 | __proto._createCanvas = function (className) {
|
5331 | var canvas = document.createElement("canvas");
|
5332 | canvas.className = className;
|
5333 | return canvas;
|
5334 | };
|
5335 |
|
5336 | __proto._setDefaultCanvasStyle = function () {
|
5337 | var canvas = this.canvas;
|
5338 | canvas.style.bottom = "0";
|
5339 | canvas.style.left = "0";
|
5340 | canvas.style.right = "0";
|
5341 | canvas.style.top = "0";
|
5342 | canvas.style.margin = "auto";
|
5343 | canvas.style.maxHeight = "100%";
|
5344 | canvas.style.maxWidth = "100%";
|
5345 | canvas.style.outline = "none";
|
5346 | canvas.style.position = "absolute";
|
5347 | };
|
5348 |
|
5349 | __proto._onContentError = function () {
|
5350 | this._imageIsReady = false;
|
5351 | this._image = null;
|
5352 | this.trigger(new Component.ComponentEvent(EVENTS$1.ERROR, {
|
5353 | type: ERROR_TYPE$1.FAIL_IMAGE_LOAD,
|
5354 | message: "failed to load image"
|
5355 | }));
|
5356 | return false;
|
5357 | };
|
5358 |
|
5359 | __proto._triggerContentLoad = function () {
|
5360 | this.trigger(new Component.ComponentEvent(EVENTS$1.IMAGE_LOADED, {
|
5361 | content: this._image,
|
5362 | isVideo: this._isVideo,
|
5363 | projectionType: this._imageType
|
5364 | }));
|
5365 | };
|
5366 |
|
5367 | __proto._onContentLoad = function (e) {
|
5368 | if (e.errorCount > 0) return;
|
5369 | this._imageIsReady = true;
|
5370 |
|
5371 | this._triggerContentLoad();
|
5372 | };
|
5373 |
|
5374 | __proto._initShaderProgram = function () {
|
5375 | var gl = this.context;
|
5376 |
|
5377 | if (this.shaderProgram) {
|
5378 | gl.deleteProgram(this.shaderProgram);
|
5379 | this.shaderProgram = null;
|
5380 | }
|
5381 |
|
5382 | var renderer = this._renderer;
|
5383 | var vsSource = renderer.getVertexShaderSource();
|
5384 | var fsSource = renderer.getFragmentShaderSource();
|
5385 | var vertexShader = WebGLUtils.createShader(gl, gl.VERTEX_SHADER, vsSource);
|
5386 | var fragmentShader = WebGLUtils.createShader(gl, gl.FRAGMENT_SHADER, fsSource);
|
5387 | var shaderProgram = WebGLUtils.createProgram(gl, vertexShader, fragmentShader);
|
5388 |
|
5389 | if (!shaderProgram) {
|
5390 | throw new Error("Failed to initialize shaders: " + WebGLUtils.getErrorNameFromWebGLErrorCode(gl.getError()));
|
5391 | }
|
5392 |
|
5393 | gl.useProgram(shaderProgram);
|
5394 | shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
|
5395 | shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
|
5396 | shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
|
5397 | shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler");
|
5398 | shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
|
5399 | shaderProgram.uEye = gl.getUniformLocation(shaderProgram, "uEye");
|
5400 | gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
|
5401 | gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
|
5402 |
|
5403 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
5404 |
|
5405 | gl.uniform1i(shaderProgram.samplerUniform, 0);
|
5406 | this.shaderProgram = shaderProgram;
|
5407 | };
|
5408 |
|
5409 | __proto._onWebglcontextlost = function (e) {
|
5410 | e.preventDefault();
|
5411 | this.trigger(new Component.ComponentEvent(EVENTS$1.RENDERING_CONTEXT_LOST));
|
5412 | };
|
5413 |
|
5414 | __proto._onWebglcontextrestored = function () {
|
5415 | this._initWebGL();
|
5416 |
|
5417 | this.trigger(new Component.ComponentEvent(EVENTS$1.RENDERING_CONTEXT_RESTORE));
|
5418 | };
|
5419 |
|
5420 | __proto._updateViewport = function () {
|
5421 | glMatrix.mat4.perspective(this.pMatrix, glMatrix.glMatrix.toRadian(this.fieldOfView), this.canvas.width / this.canvas.height, 0.1, 100);
|
5422 | this.context.viewport(0, 0, this.context.drawingBufferWidth, this.context.drawingBufferHeight);
|
5423 | };
|
5424 |
|
5425 | __proto._initWebGL = function () {
|
5426 | var gl;
|
5427 |
|
5428 | try {
|
5429 | this._initRenderingContext();
|
5430 |
|
5431 | gl = this.context;
|
5432 | this.updateViewportDimensions(this.width, this.height);
|
5433 |
|
5434 | this._initShaderProgram();
|
5435 | } catch (e) {
|
5436 | this.trigger(new Component.ComponentEvent(EVENTS$1.ERROR, {
|
5437 | type: ERROR_TYPE$1.NO_WEBGL,
|
5438 | message: "no webgl support"
|
5439 | }));
|
5440 | this.destroy();
|
5441 | console.error(e);
|
5442 |
|
5443 | return;
|
5444 | }
|
5445 |
|
5446 |
|
5447 | gl.clearColor(0, 0, 0, 0);
|
5448 | var textureTarget = this._isCubeMap ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
|
5449 |
|
5450 | if (this.texture) {
|
5451 | gl.deleteTexture(this.texture);
|
5452 | }
|
5453 |
|
5454 | this.texture = WebGLUtils.createTexture(gl, textureTarget);
|
5455 |
|
5456 | if (this._imageType === ImageType.CUBESTRIP) {
|
5457 |
|
5458 | gl.enable(gl.CULL_FACE);
|
5459 | }
|
5460 | };
|
5461 |
|
5462 | __proto._initRenderingContext = function () {
|
5463 | if (this.hasRenderingContext()) {
|
5464 | return;
|
5465 | }
|
5466 |
|
5467 | if (!window.WebGLRenderingContext) {
|
5468 | throw new Error("WebGLRenderingContext not available.");
|
5469 | }
|
5470 |
|
5471 | this.context = WebGLUtils.getWebglContext(this.canvas, this._renderingContextAttributes);
|
5472 |
|
5473 | if (!this.context) {
|
5474 | throw new Error("Failed to acquire 3D rendering context");
|
5475 | }
|
5476 | };
|
5477 |
|
5478 | __proto._initBuffers = function () {
|
5479 | var image = this._image;
|
5480 |
|
5481 | var vertexPositionData = this._renderer.getVertexPositionData();
|
5482 |
|
5483 | var indexData = this._renderer.getIndexData();
|
5484 |
|
5485 | var textureCoordData = this._renderer.getTextureCoordData({
|
5486 | image: image,
|
5487 | imageConfig: this._imageConfig
|
5488 | });
|
5489 |
|
5490 | var gl = this.context;
|
5491 | this.vertexBuffer = WebGLUtils.initBuffer(gl, gl.ARRAY_BUFFER, new Float32Array(vertexPositionData), 3, this.shaderProgram.vertexPositionAttribute);
|
5492 | this.indexBuffer = WebGLUtils.initBuffer(gl, gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData), 1);
|
5493 | this.textureCoordBuffer = WebGLUtils.initBuffer(gl, gl.ARRAY_BUFFER, new Float32Array(textureCoordData), this._isCubeMap ? 3 : 2, this.shaderProgram.textureCoordAttribute);
|
5494 |
|
5495 | this._bindBuffers();
|
5496 | };
|
5497 |
|
5498 | __proto._bindTexture = function () {
|
5499 |
|
5500 |
|
5501 | if (this._imageType === ImageType.CUBESTRIP) {
|
5502 | var _a = this._renderer.getDimension(this._image),
|
5503 | width = _a.width,
|
5504 | height = _a.height;
|
5505 |
|
5506 | var isEAC = width && height && width / height !== 1.5 ? 1 : 0;
|
5507 | this.context.uniform1f(this.context.getUniformLocation(this.shaderProgram, "uIsEAC"), isEAC);
|
5508 | } else if (this._imageType === ImageType.PANORAMA) {
|
5509 | var _b = this._renderer.getDimension(this._image),
|
5510 | width = _b.width,
|
5511 | height = _b.height;
|
5512 |
|
5513 | var imageAspectRatio = width && height && width / height;
|
5514 |
|
5515 | this._renderer.updateShaderData({
|
5516 | imageAspectRatio: imageAspectRatio
|
5517 | });
|
5518 | }
|
5519 |
|
5520 |
|
5521 |
|
5522 | this._initBuffers();
|
5523 |
|
5524 | this._renderer.bindTexture(this.context, this.texture, this._image, this._imageConfig);
|
5525 |
|
5526 | this._shouldForceDraw = true;
|
5527 | this.trigger(new Component.ComponentEvent(EVENTS$1.BIND_TEXTURE));
|
5528 | };
|
5529 |
|
5530 | __proto._updateTexture = function () {
|
5531 | this._renderer.updateTexture(this.context, this._image, this._imageConfig);
|
5532 | };
|
5533 |
|
5534 | __proto._render = function () {
|
5535 | var yawPitchControl = this._yawPitchControl;
|
5536 | var fov = yawPitchControl.getFov();
|
5537 |
|
5538 | if (yawPitchControl.shouldRenderWithQuaternion()) {
|
5539 | var quaternion = yawPitchControl.getQuaternion();
|
5540 | this.renderWithQuaternion(quaternion, fov);
|
5541 | } else {
|
5542 | var yawPitch = yawPitchControl.getYawPitch();
|
5543 | this.renderWithYawPitch(yawPitch.yaw, yawPitch.pitch, fov);
|
5544 | }
|
5545 | };
|
5546 |
|
5547 | __proto._bindBuffers = function () {
|
5548 | var gl = this.context;
|
5549 | var program = this.shaderProgram;
|
5550 | var vertexBuffer = this.vertexBuffer;
|
5551 | var textureCoordBuffer = this.textureCoordBuffer;
|
5552 | gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
5553 | gl.enableVertexAttribArray(program.vertexPositionAttribute);
|
5554 | gl.vertexAttribPointer(program.vertexPositionAttribute, vertexBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
5555 | gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
5556 | gl.bindBuffer(gl.ARRAY_BUFFER, textureCoordBuffer);
|
5557 | gl.enableVertexAttribArray(program.textureCoordAttribute);
|
5558 | gl.vertexAttribPointer(program.textureCoordAttribute, textureCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
5559 | };
|
5560 |
|
5561 | __proto._draw = function () {
|
5562 | if (this._isVideo && this._keepUpdate) {
|
5563 | this._updateTexture();
|
5564 | }
|
5565 |
|
5566 | this._renderer.render({
|
5567 | gl: this.context,
|
5568 | shaderProgram: this.shaderProgram,
|
5569 | indexBuffer: this.indexBuffer,
|
5570 | mvMatrix: this.mvMatrix,
|
5571 | pMatrix: this.pMatrix
|
5572 | });
|
5573 | };
|
5574 |
|
5575 | __proto._requestPresent = function (options) {
|
5576 | var _this = this;
|
5577 |
|
5578 | var gl = this.context;
|
5579 | var canvas = this.canvas;
|
5580 | var animator = this._animator;
|
5581 | this._vr = WEBXR_SUPPORTED ? new XRManager(options) : new VRManager();
|
5582 | var vr = this._vr;
|
5583 | animator.stop();
|
5584 | return new Promise$1(function (resolve, reject) {
|
5585 | vr.requestPresent(canvas, gl).then(function () {
|
5586 | vr.addEndCallback(_this.exitVR);
|
5587 | animator.setContext(vr.context);
|
5588 | animator.setCallback(_this._onFirstVRFrame);
|
5589 |
|
5590 | if (IS_IOS) {
|
5591 | _this._setWrapperFullscreen();
|
5592 | }
|
5593 |
|
5594 | _this._shouldForceDraw = true;
|
5595 | animator.start();
|
5596 | resolve("success");
|
5597 | }).catch(function (e) {
|
5598 | vr.destroy();
|
5599 | _this._vr = null;
|
5600 | animator.start();
|
5601 | reject(e);
|
5602 | });
|
5603 | });
|
5604 | };
|
5605 |
|
5606 | __proto._setWrapperFullscreen = function () {
|
5607 | var wrapper = this._wrapper;
|
5608 | if (!wrapper) return;
|
5609 | this._wrapperOrigStyle = wrapper.getAttribute("style");
|
5610 | var wrapperStyle = wrapper.style;
|
5611 | wrapperStyle.width = "100vw";
|
5612 | wrapperStyle.height = "100vh";
|
5613 | wrapperStyle.position = "fixed";
|
5614 | wrapperStyle.left = "0";
|
5615 | wrapperStyle.top = "0";
|
5616 | wrapperStyle.zIndex = "9999";
|
5617 | };
|
5618 |
|
5619 | __proto._restoreStyle = function () {
|
5620 | var wrapper = this._wrapper;
|
5621 | var canvas = this.canvas;
|
5622 | if (!wrapper) return;
|
5623 |
|
5624 | if (this._wrapperOrigStyle) {
|
5625 | wrapper.setAttribute("style", this._wrapperOrigStyle);
|
5626 | } else {
|
5627 | wrapper.removeAttribute("style");
|
5628 | }
|
5629 |
|
5630 | this._wrapperOrigStyle = null;
|
5631 |
|
5632 | canvas.removeAttribute("style");
|
5633 |
|
5634 | this._setDefaultCanvasStyle();
|
5635 | };
|
5636 |
|
5637 | PanoImageRenderer.EVENTS = EVENTS$1;
|
5638 | PanoImageRenderer.ERROR_TYPE = ERROR_TYPE$1;
|
5639 | return PanoImageRenderer;
|
5640 | }(Component);
|
5641 |
|
5642 | |
5643 |
|
5644 |
|
5645 |
|
5646 |
|
5647 |
|
5648 | var PanoViewer =
|
5649 |
|
5650 | function (_super) {
|
5651 | __extends(PanoViewer, _super);
|
5652 | |
5653 |
|
5654 |
|
5655 |
|
5656 |
|
5657 |
|
5658 |
|
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 |
|
5680 |
|
5681 |
|
5682 |
|
5683 |
|
5684 |
|
5685 |
|
5686 |
|
5687 |
|
5688 |
|
5689 |
|
5690 |
|
5691 |
|
5692 |
|
5693 |
|
5694 |
|
5695 |
|
5696 |
|
5697 |
|
5698 |
|
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 |
|
5709 | function PanoViewer(container, options) {
|
5710 | if (options === void 0) {
|
5711 | options = {};
|
5712 | }
|
5713 |
|
5714 | var _this = _super.call(this) || this;
|
5715 |
|
5716 |
|
5717 | if (!WebGLUtils.isWebGLAvailable()) {
|
5718 | setTimeout(function () {
|
5719 | _this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.ERROR, {
|
5720 | type: ERROR_TYPE.NO_WEBGL,
|
5721 | message: "no webgl support"
|
5722 | }));
|
5723 | }, 0);
|
5724 | return _this;
|
5725 | }
|
5726 |
|
5727 | if (!WebGLUtils.isStableWebGL()) {
|
5728 | setTimeout(function () {
|
5729 | _this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.ERROR, {
|
5730 | type: ERROR_TYPE.INVALID_DEVICE,
|
5731 | message: "blacklisted browser"
|
5732 | }));
|
5733 | }, 0);
|
5734 | return _this;
|
5735 | }
|
5736 |
|
5737 | if (!!options.image && !!options.video) {
|
5738 | setTimeout(function () {
|
5739 | _this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.ERROR, {
|
5740 | type: ERROR_TYPE.INVALID_RESOURCE,
|
5741 | message: "Specifying multi resouces(both image and video) is not valid."
|
5742 | }));
|
5743 | }, 0);
|
5744 | return _this;
|
5745 | }
|
5746 |
|
5747 |
|
5748 |
|
5749 | checkXRSupport();
|
5750 | _this._container = container;
|
5751 | _this._image = options.image || options.video;
|
5752 | _this._isVideo = !!options.video;
|
5753 | _this._projectionType = options.projectionType || PROJECTION_TYPE.EQUIRECTANGULAR;
|
5754 | _this._cubemapConfig = __assign({
|
5755 |
|
5756 | order: _this._projectionType === PROJECTION_TYPE.CUBEMAP ? "RLUDBF" : "RLUDFB",
|
5757 | tileConfig: {
|
5758 | flipHorizontal: false,
|
5759 | rotation: 0
|
5760 | },
|
5761 | trim: 0
|
5762 | }, options.cubemapConfig);
|
5763 | _this._stereoFormat = options.stereoFormat || STEREO_FORMAT.TOP_BOTTOM;
|
5764 |
|
5765 | _this._width = options.width || parseInt(window.getComputedStyle(container).width, 10);
|
5766 | _this._height = options.height || parseInt(window.getComputedStyle(container).height, 10);
|
5767 | |
5768 |
|
5769 |
|
5770 |
|
5771 |
|
5772 |
|
5773 | _this._yaw = options.yaw || 0;
|
5774 | _this._pitch = options.pitch || 0;
|
5775 | _this._fov = options.fov || 65;
|
5776 | _this._gyroMode = options.gyroMode || GYRO_MODE.YAWPITCH;
|
5777 | _this._quaternion = null;
|
5778 | _this._aspectRatio = _this._height !== 0 ? _this._width / _this._height : 1;
|
5779 | _this._canvasClass = options.canvasClass || DEFAULT_CANVAS_CLASS;
|
5780 | var fovRange = options.fovRange || [30, 110];
|
5781 | var touchDirection = PanoViewer._isValidTouchDirection(options.touchDirection) ? options.touchDirection : YawPitchControl.TOUCH_DIRECTION_ALL;
|
5782 |
|
5783 | var yawPitchConfig = __assign(__assign({}, options), {
|
5784 | element: container,
|
5785 | yaw: _this._yaw,
|
5786 | pitch: _this._pitch,
|
5787 | fov: _this._fov,
|
5788 | gyroMode: _this._gyroMode,
|
5789 | fovRange: fovRange,
|
5790 | aspectRatio: _this._aspectRatio,
|
5791 | touchDirection: touchDirection
|
5792 | });
|
5793 |
|
5794 | _this._isReady = false;
|
5795 |
|
5796 | _this._initYawPitchControl(yawPitchConfig);
|
5797 |
|
5798 | _this._initRenderer(_this._yaw, _this._pitch, _this._fov, _this._projectionType, _this._cubemapConfig);
|
5799 |
|
5800 | return _this;
|
5801 | }
|
5802 | |
5803 |
|
5804 |
|
5805 |
|
5806 |
|
5807 |
|
5808 |
|
5809 | var __proto = PanoViewer.prototype;
|
5810 |
|
5811 | PanoViewer.isSupported = function () {
|
5812 | return WebGLUtils.isWebGLAvailable() && WebGLUtils.isStableWebGL();
|
5813 | };
|
5814 | |
5815 |
|
5816 |
|
5817 |
|
5818 |
|
5819 |
|
5820 |
|
5821 | PanoViewer.isWebGLAvailable = function () {
|
5822 | return WebGLUtils.isWebGLAvailable();
|
5823 | };
|
5824 | |
5825 |
|
5826 |
|
5827 |
|
5828 |
|
5829 |
|
5830 |
|
5831 | PanoViewer.isGyroSensorAvailable = function (callback) {
|
5832 | if (!DeviceMotionEvent && callback) {
|
5833 | callback(false);
|
5834 | return;
|
5835 | }
|
5836 |
|
5837 | var onDeviceMotionChange;
|
5838 |
|
5839 | var checkGyro = function () {
|
5840 | return new Promise$1(function (res) {
|
5841 | onDeviceMotionChange = function (deviceMotion) {
|
5842 | var isGyroSensorAvailable = !(deviceMotion.rotationRate.alpha == null);
|
5843 | res(isGyroSensorAvailable);
|
5844 | };
|
5845 |
|
5846 | window.addEventListener("devicemotion", onDeviceMotionChange);
|
5847 | });
|
5848 | };
|
5849 |
|
5850 | var timeout = function () {
|
5851 | return new Promise$1(function (res) {
|
5852 | setTimeout(function () {
|
5853 | return res(false);
|
5854 | }, 1000);
|
5855 | });
|
5856 | };
|
5857 |
|
5858 | Promise$1.race([checkGyro(), timeout()]).then(function (isGyroSensorAvailable) {
|
5859 | window.removeEventListener("devicemotion", onDeviceMotionChange);
|
5860 |
|
5861 | if (callback) {
|
5862 | callback(isGyroSensorAvailable);
|
5863 | }
|
5864 |
|
5865 | PanoViewer.isGyroSensorAvailable = function (fb) {
|
5866 | if (fb) {
|
5867 | fb(isGyroSensorAvailable);
|
5868 | }
|
5869 |
|
5870 | return isGyroSensorAvailable;
|
5871 | };
|
5872 | });
|
5873 | };
|
5874 |
|
5875 | PanoViewer._isValidTouchDirection = function (direction) {
|
5876 | return direction === PanoViewer.TOUCH_DIRECTION.NONE || direction === PanoViewer.TOUCH_DIRECTION.YAW || direction === PanoViewer.TOUCH_DIRECTION.PITCH || direction === PanoViewer.TOUCH_DIRECTION.ALL;
|
5877 | };
|
5878 | |
5879 |
|
5880 |
|
5881 |
|
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 |
|
5887 |
|
5888 |
|
5889 |
|
5890 | __proto.getVideo = function () {
|
5891 | if (!this._isVideo) {
|
5892 | return null;
|
5893 | }
|
5894 |
|
5895 | return this._photoSphereRenderer.getContent();
|
5896 | };
|
5897 | |
5898 |
|
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 |
|
5908 |
|
5909 |
|
5910 |
|
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 |
|
5916 | __proto.setVideo = function (video, param) {
|
5917 | if (param === void 0) {
|
5918 | param = {};
|
5919 | }
|
5920 |
|
5921 | if (video) {
|
5922 | this.setImage(video, {
|
5923 | projectionType: param.projectionType,
|
5924 | isVideo: true,
|
5925 | cubemapConfig: param.cubemapConfig,
|
5926 | stereoFormat: param.stereoFormat
|
5927 | });
|
5928 | }
|
5929 |
|
5930 | return this;
|
5931 | };
|
5932 | |
5933 |
|
5934 |
|
5935 |
|
5936 |
|
5937 |
|
5938 |
|
5939 |
|
5940 |
|
5941 | __proto.getImage = function () {
|
5942 | if (this._isVideo) {
|
5943 | return null;
|
5944 | }
|
5945 |
|
5946 | return this._photoSphereRenderer.getContent();
|
5947 | };
|
5948 | |
5949 |
|
5950 |
|
5951 |
|
5952 |
|
5953 |
|
5954 |
|
5955 |
|
5956 |
|
5957 |
|
5958 |
|
5959 |
|
5960 |
|
5961 |
|
5962 |
|
5963 |
|
5964 |
|
5965 |
|
5966 |
|
5967 |
|
5968 | __proto.setImage = function (image, param) {
|
5969 | if (param === void 0) {
|
5970 | param = {};
|
5971 | }
|
5972 |
|
5973 | var cubemapConfig = __assign({
|
5974 | order: "RLUDBF",
|
5975 | tileConfig: {
|
5976 | flipHorizontal: false,
|
5977 | rotation: 0
|
5978 | },
|
5979 | trim: 0
|
5980 | }, param.cubemapConfig);
|
5981 |
|
5982 | var stereoFormat = param.stereoFormat || STEREO_FORMAT.TOP_BOTTOM;
|
5983 | var isVideo = !!param.isVideo;
|
5984 |
|
5985 | if (this._image && this._isVideo !== isVideo) {
|
5986 |
|
5987 | console.warn("PanoViewer is not currently supporting content type changes. (Image <--> Video)");
|
5988 |
|
5989 |
|
5990 | return this;
|
5991 | }
|
5992 |
|
5993 | if (image) {
|
5994 | this._deactivate();
|
5995 |
|
5996 | this._image = image;
|
5997 | this._isVideo = isVideo;
|
5998 | this._projectionType = param.projectionType || PROJECTION_TYPE.EQUIRECTANGULAR;
|
5999 | this._cubemapConfig = cubemapConfig;
|
6000 | this._stereoFormat = stereoFormat;
|
6001 |
|
6002 | this._initRenderer(this._yaw, this._pitch, this._fov, this._projectionType, this._cubemapConfig);
|
6003 | }
|
6004 |
|
6005 | return this;
|
6006 | };
|
6007 | |
6008 |
|
6009 |
|
6010 |
|
6011 |
|
6012 |
|
6013 |
|
6014 |
|
6015 | __proto.keepUpdate = function (doUpdate) {
|
6016 | this._photoSphereRenderer.keepUpdate(doUpdate);
|
6017 |
|
6018 | return this;
|
6019 | };
|
6020 | |
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 |
|
6027 | __proto.getProjectionType = function () {
|
6028 | return this._projectionType;
|
6029 | };
|
6030 | |
6031 |
|
6032 |
|
6033 |
|
6034 |
|
6035 |
|
6036 |
|
6037 |
|
6038 |
|
6039 | __proto.enableSensor = function () {
|
6040 | return new Promise$1(function (resolve, reject) {
|
6041 | if (DeviceMotionEvent && typeof DeviceMotionEvent.requestPermission === "function") {
|
6042 | DeviceMotionEvent.requestPermission().then(function (permissionState) {
|
6043 | if (permissionState === "granted") {
|
6044 | resolve();
|
6045 | } else {
|
6046 | reject(new Error("permission denied"));
|
6047 | }
|
6048 | }).catch(function (e) {
|
6049 |
|
6050 | reject(e);
|
6051 | });
|
6052 | } else {
|
6053 | resolve();
|
6054 | }
|
6055 | });
|
6056 | };
|
6057 | |
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 | __proto.disableSensor = function () {
|
6066 | return this;
|
6067 | };
|
6068 | |
6069 |
|
6070 |
|
6071 |
|
6072 |
|
6073 |
|
6074 |
|
6075 |
|
6076 |
|
6077 |
|
6078 |
|
6079 |
|
6080 | __proto.enterVR = function (options) {
|
6081 | var _this = this;
|
6082 |
|
6083 | if (options === void 0) {
|
6084 | options = {};
|
6085 | }
|
6086 |
|
6087 | if (!this._isReady) {
|
6088 | return Promise$1.reject(new Error("PanoViewer is not ready to show image."));
|
6089 | }
|
6090 |
|
6091 | return new Promise$1(function (resolve, reject) {
|
6092 | _this.enableSensor().then(function () {
|
6093 | return _this._photoSphereRenderer.enterVR(options);
|
6094 | }).then(function (res) {
|
6095 | return resolve(res);
|
6096 | }).catch(function (e) {
|
6097 | return reject(e);
|
6098 | });
|
6099 | });
|
6100 | };
|
6101 | |
6102 |
|
6103 |
|
6104 |
|
6105 |
|
6106 |
|
6107 |
|
6108 | __proto.exitVR = function () {
|
6109 | this._photoSphereRenderer.exitVR();
|
6110 |
|
6111 | return this;
|
6112 | };
|
6113 | |
6114 |
|
6115 |
|
6116 |
|
6117 |
|
6118 |
|
6119 |
|
6120 |
|
6121 | __proto.setUseZoom = function (useZoom) {
|
6122 | if (typeof useZoom === "boolean") {
|
6123 | this._yawPitchControl.option("useZoom", useZoom);
|
6124 | }
|
6125 |
|
6126 | return this;
|
6127 | };
|
6128 | |
6129 |
|
6130 |
|
6131 |
|
6132 |
|
6133 |
|
6134 |
|
6135 |
|
6136 | __proto.setUseKeyboard = function (useKeyboard) {
|
6137 | this._yawPitchControl.option("useKeyboard", useKeyboard);
|
6138 |
|
6139 | return this;
|
6140 | };
|
6141 | |
6142 |
|
6143 |
|
6144 |
|
6145 |
|
6146 |
|
6147 |
|
6148 |
|
6149 |
|
6150 |
|
6151 |
|
6152 |
|
6153 |
|
6154 |
|
6155 | __proto.setGyroMode = function (gyroMode) {
|
6156 | this._yawPitchControl.option("gyroMode", gyroMode);
|
6157 |
|
6158 | return this;
|
6159 | };
|
6160 | |
6161 |
|
6162 |
|
6163 |
|
6164 |
|
6165 |
|
6166 |
|
6167 |
|
6168 |
|
6169 |
|
6170 | __proto.setFovRange = function (range) {
|
6171 | this._yawPitchControl.option("fovRange", range);
|
6172 |
|
6173 | return this;
|
6174 | };
|
6175 | |
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 | __proto.getFovRange = function () {
|
6185 | return this._yawPitchControl.option("fovRange");
|
6186 | };
|
6187 | |
6188 |
|
6189 |
|
6190 |
|
6191 |
|
6192 |
|
6193 |
|
6194 |
|
6195 |
|
6196 |
|
6197 | __proto.updateViewportDimensions = function (size) {
|
6198 | if (size === void 0) {
|
6199 | size = {};
|
6200 | }
|
6201 |
|
6202 | if (!this._isReady) {
|
6203 | return this;
|
6204 | }
|
6205 |
|
6206 | var containerSize;
|
6207 |
|
6208 | if (size.width === undefined || size.height === undefined) {
|
6209 | containerSize = window.getComputedStyle(this._container);
|
6210 | }
|
6211 |
|
6212 | var width = size.width || parseInt(containerSize.width, 10);
|
6213 | var height = size.height || parseInt(containerSize.height, 10);
|
6214 |
|
6215 | if (width === this._width && height === this._height) {
|
6216 | return this;
|
6217 | }
|
6218 |
|
6219 | this._width = width;
|
6220 | this._height = height;
|
6221 | this._aspectRatio = width / height;
|
6222 |
|
6223 | this._photoSphereRenderer.updateViewportDimensions(width, height);
|
6224 |
|
6225 | this._yawPitchControl.option("aspectRatio", this._aspectRatio);
|
6226 |
|
6227 | this._yawPitchControl.updatePanScale({
|
6228 | height: height
|
6229 | });
|
6230 |
|
6231 | this.lookAt({}, 0);
|
6232 | return this;
|
6233 | };
|
6234 | |
6235 |
|
6236 |
|
6237 |
|
6238 |
|
6239 |
|
6240 | __proto.getFov = function () {
|
6241 | return this._fov;
|
6242 | };
|
6243 | |
6244 |
|
6245 |
|
6246 |
|
6247 |
|
6248 |
|
6249 | __proto.getYaw = function () {
|
6250 | return this._yaw;
|
6251 | };
|
6252 | |
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 |
|
6258 | __proto.getPitch = function () {
|
6259 | return this._pitch;
|
6260 | };
|
6261 | |
6262 |
|
6263 |
|
6264 |
|
6265 |
|
6266 |
|
6267 | __proto.getYawRange = function () {
|
6268 | return this._yawPitchControl.option("yawRange");
|
6269 | };
|
6270 | |
6271 |
|
6272 |
|
6273 |
|
6274 |
|
6275 |
|
6276 | __proto.getPitchRange = function () {
|
6277 | return this._yawPitchControl.option("pitchRange");
|
6278 | };
|
6279 | |
6280 |
|
6281 |
|
6282 |
|
6283 |
|
6284 |
|
6285 |
|
6286 |
|
6287 |
|
6288 |
|
6289 | __proto.setYawRange = function (yawRange) {
|
6290 | this._yawPitchControl.option("yawRange", yawRange);
|
6291 |
|
6292 | return this;
|
6293 | };
|
6294 | |
6295 |
|
6296 |
|
6297 |
|
6298 |
|
6299 |
|
6300 |
|
6301 |
|
6302 |
|
6303 |
|
6304 | __proto.setPitchRange = function (pitchRange) {
|
6305 | this._yawPitchControl.option("pitchRange", pitchRange);
|
6306 |
|
6307 | return this;
|
6308 | };
|
6309 | |
6310 |
|
6311 |
|
6312 |
|
6313 |
|
6314 |
|
6315 |
|
6316 |
|
6317 | __proto.setShowPolePoint = function (showPolePoint) {
|
6318 | this._yawPitchControl.option("showPolePoint", showPolePoint);
|
6319 |
|
6320 | return this;
|
6321 | };
|
6322 | |
6323 |
|
6324 |
|
6325 |
|
6326 |
|
6327 |
|
6328 |
|
6329 |
|
6330 |
|
6331 |
|
6332 |
|
6333 |
|
6334 |
|
6335 |
|
6336 |
|
6337 |
|
6338 |
|
6339 | __proto.lookAt = function (orientation, duration) {
|
6340 | if (duration === void 0) {
|
6341 | duration = 0;
|
6342 | }
|
6343 |
|
6344 | if (!this._isReady) {
|
6345 | return this;
|
6346 | }
|
6347 |
|
6348 | var yaw = orientation.yaw !== undefined ? orientation.yaw : this._yaw;
|
6349 | var pitch = orientation.pitch !== undefined ? orientation.pitch : this._pitch;
|
6350 |
|
6351 | var pitchRange = this._yawPitchControl.option("pitchRange");
|
6352 |
|
6353 | var verticalAngleOfImage = pitchRange[1] - pitchRange[0];
|
6354 | var fov = orientation.fov !== undefined ? orientation.fov : this._fov;
|
6355 |
|
6356 | if (verticalAngleOfImage < fov) {
|
6357 | fov = verticalAngleOfImage;
|
6358 | }
|
6359 |
|
6360 | this._yawPitchControl.lookAt({
|
6361 | yaw: yaw,
|
6362 | pitch: pitch,
|
6363 | fov: fov
|
6364 | }, duration);
|
6365 |
|
6366 | if (duration === 0) {
|
6367 | this._photoSphereRenderer.renderWithYawPitch(yaw, pitch, fov);
|
6368 | }
|
6369 |
|
6370 | return this;
|
6371 | };
|
6372 | |
6373 |
|
6374 |
|
6375 |
|
6376 |
|
6377 |
|
6378 |
|
6379 |
|
6380 |
|
6381 |
|
6382 |
|
6383 |
|
6384 |
|
6385 |
|
6386 | __proto.setTouchDirection = function (direction) {
|
6387 | if (PanoViewer._isValidTouchDirection(direction)) {
|
6388 | this._yawPitchControl.option("touchDirection", direction);
|
6389 | }
|
6390 |
|
6391 | return this;
|
6392 | };
|
6393 | |
6394 |
|
6395 |
|
6396 |
|
6397 |
|
6398 |
|
6399 |
|
6400 |
|
6401 |
|
6402 |
|
6403 |
|
6404 |
|
6405 |
|
6406 | __proto.getTouchDirection = function () {
|
6407 | return this._yawPitchControl.option("touchDirection");
|
6408 | };
|
6409 | |
6410 |
|
6411 |
|
6412 |
|
6413 |
|
6414 |
|
6415 |
|
6416 | __proto.destroy = function () {
|
6417 | this._deactivate();
|
6418 |
|
6419 | if (this._yawPitchControl) {
|
6420 | this._yawPitchControl.destroy();
|
6421 |
|
6422 | this._yawPitchControl = null;
|
6423 | }
|
6424 |
|
6425 | return this;
|
6426 | };
|
6427 |
|
6428 |
|
6429 | __proto._initRenderer = function (yaw, pitch, fov, projectionType, cubemapConfig) {
|
6430 | var _this = this;
|
6431 |
|
6432 | this._photoSphereRenderer = new PanoImageRenderer(this._image, this._width, this._height, this._isVideo, this._container, this._canvasClass, {
|
6433 | initialYaw: yaw,
|
6434 | initialPitch: pitch,
|
6435 | fieldOfView: fov,
|
6436 | imageType: projectionType,
|
6437 | cubemapConfig: cubemapConfig,
|
6438 | stereoFormat: this._stereoFormat
|
6439 | });
|
6440 |
|
6441 | this._photoSphereRenderer.setYawPitchControl(this._yawPitchControl);
|
6442 |
|
6443 | this._bindRendererHandler();
|
6444 |
|
6445 | this._photoSphereRenderer.bindTexture().then(function () {
|
6446 | return _this._activate();
|
6447 | }).catch(function () {
|
6448 | _this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.ERROR, {
|
6449 | type: ERROR_TYPE.FAIL_BIND_TEXTURE,
|
6450 | message: "failed to bind texture"
|
6451 | }));
|
6452 | });
|
6453 | };
|
6454 | |
6455 |
|
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 |
|
6463 | __proto._updateYawPitchIfNeeded = function () {
|
6464 | if (this._projectionType === PanoViewer.ProjectionType.PANORAMA) {
|
6465 |
|
6466 | var image = this._photoSphereRenderer.getContent();
|
6467 |
|
6468 | var imageAspectRatio = image.naturalWidth / image.naturalHeight;
|
6469 | var yawSize = void 0;
|
6470 | var maxFov = void 0;
|
6471 |
|
6472 | if (imageAspectRatio < 1) {
|
6473 |
|
6474 | imageAspectRatio = 1 / imageAspectRatio;
|
6475 | }
|
6476 |
|
6477 | if (imageAspectRatio < 6) {
|
6478 | yawSize = util.toDegree(imageAspectRatio);
|
6479 |
|
6480 | maxFov = util.toDegree(Math.atan(0.5)) * 2;
|
6481 | } else {
|
6482 | yawSize = 360;
|
6483 | maxFov = 360 / imageAspectRatio;
|
6484 | }
|
6485 |
|
6486 |
|
6487 | var minFov = this._yawPitchControl.option("fovRange")[0];
|
6488 |
|
6489 |
|
6490 | this._yawPitchControl.option({
|
6491 | "fov": maxFov,
|
6492 | "yawRange": [-yawSize / 2, yawSize / 2],
|
6493 | "pitchRange": [-maxFov / 2, maxFov / 2],
|
6494 | "fovRange": [minFov, maxFov]
|
6495 | });
|
6496 |
|
6497 | this.lookAt({
|
6498 | fov: maxFov
|
6499 | });
|
6500 | }
|
6501 | };
|
6502 |
|
6503 | __proto._bindRendererHandler = function () {
|
6504 | var _this = this;
|
6505 |
|
6506 | this._photoSphereRenderer.on(PanoImageRenderer.EVENTS.ERROR, function (e) {
|
6507 | _this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.ERROR, e));
|
6508 | });
|
6509 |
|
6510 | this._photoSphereRenderer.on(PanoImageRenderer.EVENTS.RENDERING_CONTEXT_LOST, function () {
|
6511 | _this._deactivate();
|
6512 |
|
6513 | _this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.ERROR, {
|
6514 | type: ERROR_TYPE.RENDERING_CONTEXT_LOST,
|
6515 | message: "webgl rendering context lost"
|
6516 | }));
|
6517 | });
|
6518 | };
|
6519 |
|
6520 | __proto._initYawPitchControl = function (yawPitchConfig) {
|
6521 | var _this = this;
|
6522 |
|
6523 | this._yawPitchControl = new YawPitchControl(yawPitchConfig);
|
6524 |
|
6525 | this._yawPitchControl.on(PANOVIEWER_EVENTS.ANIMATION_END, function (e) {
|
6526 | _this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.ANIMATION_END, e));
|
6527 | });
|
6528 |
|
6529 | this._yawPitchControl.on("change", function (e) {
|
6530 | _this._yaw = e.yaw;
|
6531 | _this._pitch = e.pitch;
|
6532 | _this._fov = e.fov;
|
6533 | _this._quaternion = e.quaternion;
|
6534 |
|
6535 | _this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.VIEW_CHANGE, e));
|
6536 | });
|
6537 | };
|
6538 |
|
6539 | __proto._activate = function () {
|
6540 | this._photoSphereRenderer.attachTo(this._container);
|
6541 |
|
6542 | this._yawPitchControl.enable();
|
6543 |
|
6544 | this.updateViewportDimensions();
|
6545 | this._isReady = true;
|
6546 |
|
6547 | this._updateYawPitchIfNeeded();
|
6548 |
|
6549 | this.trigger(new Component.ComponentEvent(PANOVIEWER_EVENTS.READY));
|
6550 |
|
6551 | this._photoSphereRenderer.startRender();
|
6552 | };
|
6553 | |
6554 |
|
6555 |
|
6556 |
|
6557 |
|
6558 | __proto._deactivate = function () {
|
6559 |
|
6560 | var video = this.getVideo();
|
6561 |
|
6562 | if (video) {
|
6563 | video.pause();
|
6564 | }
|
6565 |
|
6566 | if (this._isReady) {
|
6567 | this._photoSphereRenderer.stopRender();
|
6568 |
|
6569 | this._yawPitchControl.disable();
|
6570 |
|
6571 | this._isReady = false;
|
6572 | }
|
6573 |
|
6574 | if (this._photoSphereRenderer) {
|
6575 | this._photoSphereRenderer.destroy();
|
6576 |
|
6577 | this._photoSphereRenderer = null;
|
6578 | }
|
6579 | };
|
6580 | |
6581 |
|
6582 |
|
6583 |
|
6584 |
|
6585 |
|
6586 |
|
6587 |
|
6588 |
|
6589 |
|
6590 |
|
6591 |
|
6592 | PanoViewer.VERSION = VERSION;
|
6593 | PanoViewer.ERROR_TYPE = ERROR_TYPE;
|
6594 | PanoViewer.EVENTS = PANOVIEWER_EVENTS;
|
6595 | PanoViewer.PROJECTION_TYPE = PROJECTION_TYPE;
|
6596 | PanoViewer.GYRO_MODE = GYRO_MODE;
|
6597 |
|
6598 |
|
6599 | PanoViewer.ProjectionType = PROJECTION_TYPE;
|
6600 | PanoViewer.STEREO_FORMAT = STEREO_FORMAT;
|
6601 | |
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 |
|
6607 |
|
6608 | PanoViewer.TOUCH_DIRECTION = {
|
6609 | |
6610 |
|
6611 |
|
6612 |
|
6613 |
|
6614 |
|
6615 |
|
6616 |
|
6617 |
|
6618 | NONE: YawPitchControl.TOUCH_DIRECTION_NONE,
|
6619 |
|
6620 | |
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 | YAW: YawPitchControl.TOUCH_DIRECTION_YAW,
|
6630 |
|
6631 | |
6632 |
|
6633 |
|
6634 |
|
6635 |
|
6636 |
|
6637 |
|
6638 |
|
6639 |
|
6640 | PITCH: YawPitchControl.TOUCH_DIRECTION_PITCH,
|
6641 |
|
6642 | |
6643 |
|
6644 |
|
6645 |
|
6646 |
|
6647 |
|
6648 |
|
6649 |
|
6650 |
|
6651 | ALL: YawPitchControl.TOUCH_DIRECTION_ALL
|
6652 | };
|
6653 | return PanoViewer;
|
6654 | }(Component);
|
6655 |
|
6656 | var PanoViewer$1 = {
|
6657 | __proto__: null,
|
6658 | PanoViewer: PanoViewer,
|
6659 | VERSION: VERSION,
|
6660 | GYRO_MODE: GYRO_MODE,
|
6661 | PANOVIEWER_EVENTS: PANOVIEWER_EVENTS,
|
6662 | ERROR_TYPE: ERROR_TYPE,
|
6663 | PROJECTION_TYPE: PROJECTION_TYPE,
|
6664 | STEREO_FORMAT: STEREO_FORMAT,
|
6665 | PANOVIEWER_OPTIONS: PANOVIEWER_OPTIONS,
|
6666 | DEFAULT_CANVAS_CLASS: DEFAULT_CANVAS_CLASS
|
6667 | };
|
6668 |
|
6669 |
|
6670 | var SPINVIEWER_OPTIONS = {
|
6671 | imageUrl: true,
|
6672 | rowCount: true,
|
6673 | colCount: true,
|
6674 | width: true,
|
6675 | height: true,
|
6676 | autoHeight: true,
|
6677 | colRow: true,
|
6678 | scale: true,
|
6679 | frameIndex: true,
|
6680 | wrapperClass: true,
|
6681 | imageClass: true
|
6682 | };
|
6683 | var SPINVIEWER_EVENTS = {
|
6684 | LOAD: "load",
|
6685 | IMAGE_ERROR: "imageError",
|
6686 | CHANGE: "change",
|
6687 | ANIMATION_END: "animationEnd"
|
6688 | };
|
6689 | var DEFAULT_WRAPPER_CLASS = "view360-wrapper";
|
6690 | var DEFAULT_IMAGE_CLASS = "view360-image";
|
6691 |
|
6692 | |
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 | var SpriteImage =
|
6699 |
|
6700 | function (_super) {
|
6701 | __extends(SpriteImage, _super);
|
6702 | |
6703 |
|
6704 |
|
6705 |
|
6706 |
|
6707 |
|
6708 |
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 |
|
6714 |
|
6715 |
|
6716 |
|
6717 |
|
6718 |
|
6719 |
|
6720 |
|
6721 |
|
6722 |
|
6723 |
|
6724 |
|
6725 |
|
6726 |
|
6727 |
|
6728 |
|
6729 |
|
6730 |
|
6731 |
|
6732 |
|
6733 | function SpriteImage(element, options) {
|
6734 | if (options === void 0) {
|
6735 | options = {};
|
6736 | }
|
6737 |
|
6738 | var _this = _super.call(this) || this;
|
6739 |
|
6740 | var opt = options || {};
|
6741 | _this._el = element;
|
6742 | _this._rowCount = opt.rowCount || 1;
|
6743 | _this._colCount = opt.colCount || 1;
|
6744 | _this._totalCount = _this._rowCount * _this._colCount;
|
6745 |
|
6746 | _this._width = opt.width || "auto";
|
6747 | _this._height = opt.height || "auto";
|
6748 | _this._autoHeight = opt.autoHeight != null ? opt.autoHeight : true;
|
6749 |
|
6750 | _this._colRow = [0, 0];
|
6751 |
|
6752 | if (opt.colRow) {
|
6753 | _this._colRow = opt.colRow;
|
6754 | } else if (opt.frameIndex) {
|
6755 | _this.setFrameIndex(opt.frameIndex);
|
6756 | }
|
6757 |
|
6758 | _this._el.style.width = SpriteImage._getSizeString(_this._width);
|
6759 | _this._el.style.height = SpriteImage._getSizeString(_this._height);
|
6760 | var wrapperClass = opt.wrapperClass || DEFAULT_WRAPPER_CLASS;
|
6761 | var imageClass = opt.imageClass || DEFAULT_IMAGE_CLASS;
|
6762 |
|
6763 | if (!opt.imageUrl) {
|
6764 | setTimeout(function () {
|
6765 | _this.trigger(new Component.ComponentEvent("imageError", {
|
6766 | imageUrl: opt.imageUrl
|
6767 | }));
|
6768 | }, 0);
|
6769 | return _this;
|
6770 | }
|
6771 |
|
6772 | var imageInContainer = element.querySelector("." + imageClass);
|
6773 | var wrapperInContainer = element.querySelector("." + wrapperClass);
|
6774 |
|
6775 | if (wrapperInContainer && imageInContainer) {
|
6776 |
|
6777 | imageInContainer.style.display = "none";
|
6778 | }
|
6779 |
|
6780 | _this._image = imageInContainer || new Image();
|
6781 | |
6782 |
|
6783 |
|
6784 |
|
6785 | var image = _this._image;
|
6786 |
|
6787 | image.onload = function () {
|
6788 | if (wrapperInContainer && imageInContainer) {
|
6789 | imageInContainer.style.display = "";
|
6790 | }
|
6791 |
|
6792 | _this._bg = SpriteImage._createBgDiv(wrapperInContainer, image, _this._rowCount, _this._colCount, _this._autoHeight);
|
6793 |
|
6794 | _this._el.appendChild(_this._bg);
|
6795 |
|
6796 | _this.setColRow(_this._colRow[0], _this._colRow[1]);
|
6797 |
|
6798 | _this.trigger(new Component.ComponentEvent("load", {
|
6799 | target: _this._el,
|
6800 | bgElement: _this._bg
|
6801 | }));
|
6802 |
|
6803 | if (_this._autoPlayReservedInfo) {
|
6804 | _this.play(_this._autoPlayReservedInfo);
|
6805 |
|
6806 | _this._autoPlayReservedInfo = null;
|
6807 | }
|
6808 | };
|
6809 |
|
6810 | image.onerror = function () {
|
6811 | _this.trigger(new Component.ComponentEvent("imageError", {
|
6812 | imageUrl: opt.imageUrl
|
6813 | }));
|
6814 | };
|
6815 |
|
6816 | image.src = opt.imageUrl;
|
6817 | return _this;
|
6818 | }
|
6819 |
|
6820 | var __proto = SpriteImage.prototype;
|
6821 |
|
6822 | SpriteImage._createBgDiv = function (wrapperInContainer, img, rowCount, colCount, autoHeight) {
|
6823 | var el = wrapperInContainer || document.createElement("div");
|
6824 | el.style.position = "relative";
|
6825 | el.style.overflow = "hidden";
|
6826 | img.style.position = "absolute";
|
6827 | img.style.width = colCount * 100 + "%";
|
6828 | img.style.height = rowCount * 100 + "%";
|
6829 |
|
6830 |
|
6831 | img.ondragstart = function () {
|
6832 | return false;
|
6833 | };
|
6834 |
|
6835 |
|
6836 |
|
6837 | if (SUPPORT_WILLCHANGE) {
|
6838 | img.style.willChange = "transform";
|
6839 | }
|
6840 |
|
6841 | el.appendChild(img);
|
6842 | var unitWidth = img.naturalWidth / colCount;
|
6843 | var unitHeight = img.naturalHeight / rowCount;
|
6844 |
|
6845 | if (autoHeight) {
|
6846 | var r = unitHeight / unitWidth;
|
6847 | el.style.paddingBottom = r * 100 + "%";
|
6848 | } else {
|
6849 | el.style.height = "100%";
|
6850 | }
|
6851 |
|
6852 | return el;
|
6853 | };
|
6854 |
|
6855 | SpriteImage._getSizeString = function (size) {
|
6856 | if (typeof size === "number") {
|
6857 | return size + "px";
|
6858 | }
|
6859 |
|
6860 | return size;
|
6861 | };
|
6862 | |
6863 |
|
6864 |
|
6865 |
|
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 |
|
6871 |
|
6872 |
|
6873 |
|
6874 | __proto.setFrameIndex = function (index) {
|
6875 | var colRow = this.toColRow(index);
|
6876 | this.setColRow(colRow[0], colRow[1]);
|
6877 | };
|
6878 | |
6879 |
|
6880 |
|
6881 |
|
6882 |
|
6883 |
|
6884 |
|
6885 |
|
6886 |
|
6887 |
|
6888 |
|
6889 |
|
6890 |
|
6891 | __proto.getFrameIndex = function () {
|
6892 | return this._colRow[1] * this._colCount + this._colRow[0];
|
6893 | };
|
6894 | |
6895 |
|
6896 |
|
6897 |
|
6898 |
|
6899 |
|
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 |
|
6906 |
|
6907 | __proto.setColRow = function (col, row) {
|
6908 | if (row > this._rowCount - 1 || col > this._colCount - 1) {
|
6909 | return;
|
6910 | }
|
6911 |
|
6912 | if (this._image && TRANSFORM) {
|
6913 |
|
6914 | this._image.style[TRANSFORM] = "translate(" + -(col / this._colCount * 100) + "%, " + -(row / this._rowCount * 100) + "%)";
|
6915 | }
|
6916 |
|
6917 | this._colRow = [col, row];
|
6918 | };
|
6919 | |
6920 |
|
6921 |
|
6922 |
|
6923 |
|
6924 |
|
6925 |
|
6926 |
|
6927 |
|
6928 |
|
6929 |
|
6930 |
|
6931 |
|
6932 |
|
6933 | __proto.getColRow = function () {
|
6934 | return this._colRow;
|
6935 | };
|
6936 | |
6937 |
|
6938 |
|
6939 |
|
6940 |
|
6941 |
|
6942 |
|
6943 |
|
6944 |
|
6945 |
|
6946 |
|
6947 |
|
6948 | __proto.stop = function () {
|
6949 | if (this._autoPlayTimer) {
|
6950 | clearInterval(this._autoPlayTimer);
|
6951 | this._autoPlayTimer = -1;
|
6952 | }
|
6953 | };
|
6954 | |
6955 |
|
6956 |
|
6957 |
|
6958 |
|
6959 |
|
6960 |
|
6961 |
|
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 | __proto.play = function (_a) {
|
6970 | var _this = this;
|
6971 |
|
6972 | var _b = _a === void 0 ? {
|
6973 | interval: 1000 / this._totalCount,
|
6974 | playCount: 0
|
6975 | } : _a,
|
6976 | interval = _b.interval,
|
6977 | playCount = _b.playCount;
|
6978 |
|
6979 | if (!this._bg) {
|
6980 | this._autoPlayReservedInfo = {
|
6981 | interval: interval,
|
6982 | playCount: playCount
|
6983 | };
|
6984 | return;
|
6985 | }
|
6986 |
|
6987 | if (this._autoPlayTimer) {
|
6988 | clearInterval(this._autoPlayTimer);
|
6989 | this._autoPlayTimer = -1;
|
6990 | }
|
6991 |
|
6992 | var frameIndex = this.getFrameIndex();
|
6993 | var count = 0;
|
6994 | var frameCount = 0;
|
6995 |
|
6996 | this._autoPlayTimer = window.setInterval(function () {
|
6997 | frameIndex %= _this._totalCount;
|
6998 |
|
6999 | var colRow = _this.toColRow(frameIndex);
|
7000 |
|
7001 | _this.setColRow(colRow[0], colRow[1]);
|
7002 |
|
7003 | frameIndex++;
|
7004 |
|
7005 | if (++frameCount === _this._totalCount) {
|
7006 | frameCount = 0;
|
7007 | count++;
|
7008 | }
|
7009 |
|
7010 | if (playCount > 0 && count === playCount) {
|
7011 | clearInterval(_this._autoPlayTimer);
|
7012 | }
|
7013 | }, interval);
|
7014 | };
|
7015 |
|
7016 | __proto.toColRow = function (frameIndex) {
|
7017 | var colCount = this._colCount;
|
7018 | var rowCount = this._rowCount;
|
7019 |
|
7020 | if (frameIndex < 0) {
|
7021 | return [0, 0];
|
7022 | } else if (frameIndex >= this._totalCount) {
|
7023 | return [colCount - 1, rowCount - 1];
|
7024 | }
|
7025 |
|
7026 | var col = frameIndex % colCount;
|
7027 | var row = Math.floor(frameIndex / colCount);
|
7028 |
|
7029 | return [col, row];
|
7030 | };
|
7031 |
|
7032 | SpriteImage.VERSION = VERSION;
|
7033 | return SpriteImage;
|
7034 | }(Component);
|
7035 |
|
7036 | var DEFAULT_PAN_SCALE = 0.21;
|
7037 | |
7038 |
|
7039 |
|
7040 |
|
7041 |
|
7042 |
|
7043 | var SpinViewer =
|
7044 |
|
7045 | function (_super) {
|
7046 | __extends(SpinViewer, _super);
|
7047 | |
7048 |
|
7049 |
|
7050 |
|
7051 |
|
7052 |
|
7053 |
|
7054 |
|
7055 |
|
7056 |
|
7057 |
|
7058 |
|
7059 |
|
7060 |
|
7061 |
|
7062 |
|
7063 |
|
7064 |
|
7065 |
|
7066 |
|
7067 |
|
7068 |
|
7069 |
|
7070 |
|
7071 |
|
7072 |
|
7073 |
|
7074 |
|
7075 |
|
7076 |
|
7077 | function SpinViewer(element, options) {
|
7078 | if (options === void 0) {
|
7079 | options = {};
|
7080 | }
|
7081 |
|
7082 | var _this = _super.call(this) || this;
|
7083 |
|
7084 | _this._el = element;
|
7085 |
|
7086 | var opt = __assign({}, options);
|
7087 |
|
7088 | var colCount = opt.colCount || 1;
|
7089 | var rowCount = opt.rowCount || 1;
|
7090 | _this._scale = opt.scale || 1;
|
7091 | _this._panScale = _this._scale * DEFAULT_PAN_SCALE;
|
7092 | _this._frameCount = colCount * rowCount;
|
7093 |
|
7094 | _this._sprites = new SpriteImage(element, opt).on({
|
7095 | "load": function (evt) {
|
7096 | _this.trigger(new Component.ComponentEvent("load", evt));
|
7097 | },
|
7098 | "imageError": function (evt) {
|
7099 | _this.trigger(new Component.ComponentEvent("imageError", {
|
7100 | imageUrl: evt.imageUrl
|
7101 | }));
|
7102 | }
|
7103 | });
|
7104 |
|
7105 | _this._panInput = new Axes.PanInput(_this._el, {
|
7106 | scale: [_this._panScale, _this._panScale]
|
7107 | });
|
7108 | _this._axes = new Axes({
|
7109 | angle: {
|
7110 | range: [0, 359],
|
7111 | circular: true
|
7112 | }
|
7113 | }).on({
|
7114 | "change": function (evt) {
|
7115 | var curr = Math.floor(evt.pos.angle / (360 / _this._frameCount));
|
7116 | var frameIndex = _this._frameCount - curr - 1;
|
7117 |
|
7118 | _this._sprites.setFrameIndex(frameIndex);
|
7119 |
|
7120 | _this.trigger(new Component.ComponentEvent("change", {
|
7121 | frameIndex: frameIndex,
|
7122 | colRow: _this._sprites.getColRow(),
|
7123 | angle: evt.pos.angle
|
7124 | }));
|
7125 | },
|
7126 | "animationEnd": function (evt) {
|
7127 | _this.trigger(new Component.ComponentEvent("animationEnd", {
|
7128 | isTrusted: evt.isTrusted
|
7129 | }));
|
7130 | }
|
7131 | });
|
7132 |
|
7133 | _this._axes.connect("angle", _this._panInput);
|
7134 |
|
7135 | return _this;
|
7136 | }
|
7137 | |
7138 |
|
7139 |
|
7140 |
|
7141 |
|
7142 |
|
7143 |
|
7144 |
|
7145 |
|
7146 |
|
7147 |
|
7148 |
|
7149 | var __proto = SpinViewer.prototype;
|
7150 |
|
7151 | __proto.setScale = function (scale) {
|
7152 | if (isNaN(scale) || scale < 0) {
|
7153 | return this;
|
7154 | }
|
7155 |
|
7156 | this._scale = scale;
|
7157 | this._panScale = scale * DEFAULT_PAN_SCALE;
|
7158 | this._panInput.options.scale = [this._panScale, this._panScale];
|
7159 | return this;
|
7160 | };
|
7161 | |
7162 |
|
7163 |
|
7164 |
|
7165 |
|
7166 |
|
7167 |
|
7168 |
|
7169 |
|
7170 |
|
7171 |
|
7172 | __proto.getScale = function () {
|
7173 | return this._scale;
|
7174 | };
|
7175 | |
7176 |
|
7177 |
|
7178 |
|
7179 |
|
7180 |
|
7181 |
|
7182 |
|
7183 |
|
7184 |
|
7185 |
|
7186 |
|
7187 |
|
7188 |
|
7189 | __proto.spinBy = function (angle, param) {
|
7190 | if (angle === void 0) {
|
7191 | angle = 0;
|
7192 | }
|
7193 |
|
7194 | if (param === void 0) {
|
7195 | param = {
|
7196 | duration: 0
|
7197 | };
|
7198 | }
|
7199 |
|
7200 | this._axes.setBy({
|
7201 | angle: angle
|
7202 | }, param.duration);
|
7203 |
|
7204 | return this;
|
7205 | };
|
7206 | |
7207 |
|
7208 |
|
7209 |
|
7210 |
|
7211 |
|
7212 |
|
7213 |
|
7214 |
|
7215 |
|
7216 |
|
7217 |
|
7218 |
|
7219 |
|
7220 | __proto.spinTo = function (angle, param) {
|
7221 | if (angle === void 0) {
|
7222 | angle = 0;
|
7223 | }
|
7224 |
|
7225 | if (param === void 0) {
|
7226 | param = {
|
7227 | duration: 0
|
7228 | };
|
7229 | }
|
7230 |
|
7231 | this._axes.setTo({
|
7232 | angle: angle
|
7233 | }, param.duration);
|
7234 |
|
7235 | return this;
|
7236 | };
|
7237 | |
7238 |
|
7239 |
|
7240 |
|
7241 |
|
7242 |
|
7243 |
|
7244 |
|
7245 | __proto.getAngle = function () {
|
7246 | return this._axes.get().angle || 0;
|
7247 | };
|
7248 | |
7249 |
|
7250 |
|
7251 |
|
7252 |
|
7253 |
|
7254 |
|
7255 |
|
7256 |
|
7257 |
|
7258 | SpinViewer.VERSION = VERSION;
|
7259 | return SpinViewer;
|
7260 | }(Component);
|
7261 |
|
7262 | var SpinViewer$1 = {
|
7263 | __proto__: null,
|
7264 | SpinViewer: SpinViewer,
|
7265 | SpriteImage: SpriteImage,
|
7266 | VERSION: VERSION,
|
7267 | SPINVIEWER_OPTIONS: SPINVIEWER_OPTIONS,
|
7268 | SPINVIEWER_EVENTS: SPINVIEWER_EVENTS,
|
7269 | DEFAULT_WRAPPER_CLASS: DEFAULT_WRAPPER_CLASS,
|
7270 | DEFAULT_IMAGE_CLASS: DEFAULT_IMAGE_CLASS
|
7271 | };
|
7272 |
|
7273 | var withMethods = function (component, prototype, vanillaInstance) {
|
7274 | [Component.prototype, component.prototype].forEach(function (proto) {
|
7275 | Object.getOwnPropertyNames(proto).filter(function (name) {
|
7276 | return !prototype[name] && !name.startsWith("_") && name !== "constructor";
|
7277 | }).forEach(function (name) {
|
7278 | var descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
7279 |
|
7280 | if (descriptor.value) {
|
7281 |
|
7282 | Object.defineProperty(prototype, name, {
|
7283 | value: function () {
|
7284 | var _a;
|
7285 |
|
7286 | var args = [];
|
7287 |
|
7288 | for (var _i = 0; _i < arguments.length; _i++) {
|
7289 | args[_i] = arguments[_i];
|
7290 | }
|
7291 |
|
7292 | return (_a = descriptor.value).call.apply(_a, __spread([this[vanillaInstance]], args));
|
7293 | }
|
7294 | });
|
7295 | } else {
|
7296 | var getterDescriptor = {};
|
7297 |
|
7298 | if (descriptor.get) {
|
7299 | getterDescriptor.get = function () {
|
7300 | var _a;
|
7301 |
|
7302 | return (_a = descriptor.get) === null || _a === void 0 ? void 0 : _a.call(this[vanillaInstance]);
|
7303 | };
|
7304 | }
|
7305 |
|
7306 | if (descriptor.set) {
|
7307 | getterDescriptor.set = function () {
|
7308 | var _a;
|
7309 |
|
7310 | var args = [];
|
7311 |
|
7312 | for (var _i = 0; _i < arguments.length; _i++) {
|
7313 | args[_i] = arguments[_i];
|
7314 | }
|
7315 |
|
7316 | return (_a = descriptor.set) === null || _a === void 0 ? void 0 : _a.call.apply(_a, __spread([this[vanillaInstance]], args));
|
7317 | };
|
7318 | }
|
7319 |
|
7320 | Object.defineProperty(prototype, name, getterDescriptor);
|
7321 | }
|
7322 | });
|
7323 | });
|
7324 | };
|
7325 |
|
7326 | var withPanoViewerMethods = function (prototype, name) {
|
7327 | withMethods(PanoViewer, prototype, name);
|
7328 | };
|
7329 |
|
7330 | var withSpinViewerMethods = function (prototype, name) {
|
7331 | withMethods(SpinViewer, prototype, name);
|
7332 | };
|
7333 |
|
7334 | var updatePanoViewer = (function (panoViewer, newProps, prevProps) {
|
7335 | if (isPropChanged(newProps.image, prevProps.image)) {
|
7336 | panoViewer.setImage(newProps.image, {
|
7337 | projectionType: newProps.projectionType,
|
7338 | cubemapConfig: newProps.cubemapConfig,
|
7339 | stereoFormat: newProps.stereoFormat,
|
7340 | isVideo: false
|
7341 | });
|
7342 | } else if (isPropChanged(newProps.video, prevProps.video)) {
|
7343 | panoViewer.setVideo(newProps.video, {
|
7344 | projectionType: newProps.projectionType,
|
7345 | cubemapConfig: newProps.cubemapConfig,
|
7346 | stereoFormat: newProps.stereoFormat
|
7347 | });
|
7348 | }
|
7349 |
|
7350 | var singleUpdateOptions = ["fovRange", "gyroMode", "pitchRange", "showPolePoint", "touchDirection", "useKeyboard", "useZoom", "yawRange"];
|
7351 | singleUpdateOptions.forEach(function (optionName) {
|
7352 | updateOption(panoViewer, optionName, newProps, prevProps);
|
7353 | });
|
7354 | });
|
7355 |
|
7356 | var isPropChanged = function (val, prevVal) {
|
7357 | return val != null && val !== prevVal;
|
7358 | };
|
7359 |
|
7360 | var updateOption = function (panoViewer, optionName, newProps, prevProps) {
|
7361 | if (isPropChanged(newProps[optionName], prevProps[optionName])) {
|
7362 | panoViewer["set" + optionName[0].toUpperCase() + optionName.slice(1)](newProps[optionName]);
|
7363 | }
|
7364 | };
|
7365 |
|
7366 | var CFC = {
|
7367 | __proto__: null,
|
7368 | withMethods: withMethods,
|
7369 | withPanoViewerMethods: withPanoViewerMethods,
|
7370 | withSpinViewerMethods: withSpinViewerMethods,
|
7371 | updatePanoViewer: updatePanoViewer
|
7372 | };
|
7373 |
|
7374 | |
7375 |
|
7376 |
|
7377 |
|
7378 | var View360 = {};
|
7379 | merge(View360, PanoViewer$1);
|
7380 | merge(View360, SpinViewer$1);
|
7381 | merge(View360, CFC);
|
7382 |
|
7383 | return View360;
|
7384 |
|
7385 | })));
|
7386 |
|