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