@antv/g-webgpu 0.6.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -35
  3. package/dist/index.umd.min.js +16 -0
  4. package/es/ContextRegisterPlugin.d.ts +7 -0
  5. package/es/ContextRegisterPlugin.js +28 -0
  6. package/es/WebGLContextService.d.ts +18 -0
  7. package/es/WebGLContextService.js +99 -0
  8. package/es/index.d.ts +10 -0
  9. package/es/index.js +31 -6
  10. package/lib/ContextRegisterPlugin.d.ts +7 -0
  11. package/lib/ContextRegisterPlugin.js +37 -0
  12. package/lib/WebGLContextService.d.ts +18 -0
  13. package/lib/WebGLContextService.js +107 -0
  14. package/lib/index.d.ts +10 -0
  15. package/lib/index.js +45 -29
  16. package/package.json +36 -33
  17. package/CHANGELOG.md +0 -75
  18. package/es/Kernel.js +0 -331
  19. package/es/Kernel.js.map +0 -1
  20. package/es/Renderer.js +0 -310
  21. package/es/Renderer.js.map +0 -1
  22. package/es/Scene.js +0 -39
  23. package/es/Scene.js.map +0 -1
  24. package/es/View.js +0 -86
  25. package/es/View.js.map +0 -1
  26. package/es/World.js +0 -239
  27. package/es/World.js.map +0 -1
  28. package/es/camera/Camera.js +0 -801
  29. package/es/camera/Camera.js.map +0 -1
  30. package/es/camera/Landmark.js +0 -86
  31. package/es/camera/Landmark.js.map +0 -1
  32. package/es/index.js.map +0 -1
  33. package/es/renderable/Renderable.js +0 -132
  34. package/es/renderable/Renderable.js.map +0 -1
  35. package/es/renderable/line/Line.js +0 -164
  36. package/es/renderable/line/Line.js.map +0 -1
  37. package/es/renderable/point/Point.js +0 -203
  38. package/es/renderable/point/Point.js.map +0 -1
  39. package/es/utils/canvas.js +0 -8
  40. package/es/utils/canvas.js.map +0 -1
  41. package/es/utils/math.js +0 -23
  42. package/es/utils/math.js.map +0 -1
  43. package/es/utils/picking.js +0 -4
  44. package/es/utils/picking.js.map +0 -1
  45. package/es/utils/polyline-normals.js +0 -127
  46. package/es/utils/polyline-normals.js.map +0 -1
  47. package/lib/Kernel.js +0 -352
  48. package/lib/Kernel.js.map +0 -1
  49. package/lib/Renderer.js +0 -325
  50. package/lib/Renderer.js.map +0 -1
  51. package/lib/Scene.js +0 -49
  52. package/lib/Scene.js.map +0 -1
  53. package/lib/View.js +0 -99
  54. package/lib/View.js.map +0 -1
  55. package/lib/World.js +0 -265
  56. package/lib/World.js.map +0 -1
  57. package/lib/camera/Camera.js +0 -870
  58. package/lib/camera/Camera.js.map +0 -1
  59. package/lib/camera/Landmark.js +0 -95
  60. package/lib/camera/Landmark.js.map +0 -1
  61. package/lib/index.js.map +0 -1
  62. package/lib/renderable/Renderable.js +0 -141
  63. package/lib/renderable/Renderable.js.map +0 -1
  64. package/lib/renderable/line/Line.js +0 -182
  65. package/lib/renderable/line/Line.js.map +0 -1
  66. package/lib/renderable/point/Point.js +0 -221
  67. package/lib/renderable/point/Point.js.map +0 -1
  68. package/lib/utils/canvas.js +0 -15
  69. package/lib/utils/canvas.js.map +0 -1
  70. package/lib/utils/math.js +0 -36
  71. package/lib/utils/math.js.map +0 -1
  72. package/lib/utils/picking.js +0 -11
  73. package/lib/utils/picking.js.map +0 -1
  74. package/lib/utils/polyline-normals.js +0 -135
  75. package/lib/utils/polyline-normals.js.map +0 -1
@@ -1,801 +0,0 @@
1
- import _initializerDefineProperty from "@babel/runtime/helpers/initializerDefineProperty";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _applyDecoratedDescriptor from "@babel/runtime/helpers/applyDecoratedDescriptor";
5
- import _initializerWarningHelper from "@babel/runtime/helpers/initializerWarningHelper";
6
-
7
- var _dec, _dec2, _class, _class2, _descriptor, _temp;
8
-
9
- import { Frustum, IDENTIFIER } from '@antv/g-webgpu-core';
10
- import { mat3, mat4, quat, vec3, vec4 } from 'gl-matrix';
11
- import { inject, injectable } from 'inversify';
12
- import { createVec3, getAngle } from '../utils/math';
13
- import Landmark from './Landmark';
14
- export var CAMERA_TYPE;
15
-
16
- (function (CAMERA_TYPE) {
17
- CAMERA_TYPE["ORBITING"] = "ORBITING";
18
- CAMERA_TYPE["EXPLORING"] = "EXPLORING";
19
- CAMERA_TYPE["TRACKING"] = "TRACKING";
20
- })(CAMERA_TYPE || (CAMERA_TYPE = {}));
21
-
22
- export var CAMERA_TRACKING_MODE;
23
-
24
- (function (CAMERA_TRACKING_MODE) {
25
- CAMERA_TRACKING_MODE["DEFAULT"] = "DEFAULT";
26
- CAMERA_TRACKING_MODE["ROTATIONAL"] = "ROTATIONAL";
27
- CAMERA_TRACKING_MODE["TRANSLATIONAL"] = "TRANSLATIONAL";
28
- CAMERA_TRACKING_MODE["CINEMATIC"] = "CINEMATIC";
29
- })(CAMERA_TRACKING_MODE || (CAMERA_TRACKING_MODE = {}));
30
-
31
- export var CAMERA_PROJECTION_MODE;
32
-
33
- (function (CAMERA_PROJECTION_MODE) {
34
- CAMERA_PROJECTION_MODE["ORTHOGRAPHIC"] = "ORTHOGRAPHIC";
35
- CAMERA_PROJECTION_MODE["PERSPECTIVE"] = "PERSPECTIVE";
36
- })(CAMERA_PROJECTION_MODE || (CAMERA_PROJECTION_MODE = {}));
37
-
38
- var DEG_2_RAD = Math.PI / 180;
39
- var RAD_2_DEG = 180 / Math.PI;
40
- /**
41
- * 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计
42
- * 保存相机参数,定义相机动作:
43
- * 1. dolly 沿 n 轴移动
44
- * 2. pan 沿 u v 轴移动
45
- * 3. rotate 以方位角旋转
46
- * 4. 移动到 Landmark,具有平滑的动画效果,其间禁止其他用户交互
47
- */
48
-
49
- export var Camera = (_dec = injectable(), _dec2 = inject(IDENTIFIER.InteractorService), _dec(_class = (_class2 = (_temp = /*#__PURE__*/function () {
50
- function Camera() {
51
- _classCallCheck(this, Camera);
52
-
53
- this.matrix = mat4.create();
54
- this.right = vec3.fromValues(1, 0, 0);
55
- this.up = vec3.fromValues(0, 1, 0);
56
- this.forward = vec3.fromValues(0, 0, 1);
57
- this.position = vec3.fromValues(0, 0, 1);
58
- this.focalPoint = vec3.fromValues(0, 0, 0);
59
- this.distanceVector = vec3.fromValues(0, 0, 0);
60
- this.distance = 1;
61
- this.azimuth = 0;
62
- this.elevation = 0;
63
- this.roll = 0;
64
- this.relAzimuth = 0;
65
- this.relElevation = 0;
66
- this.relRoll = 0;
67
- this.dollyingStep = 0;
68
- this.rotateWorld = false;
69
-
70
- _initializerDefineProperty(this, "interactor", _descriptor, this);
71
-
72
- this.fov = 30;
73
- this.near = 0.1;
74
- this.far = 10000;
75
- this.aspect = 1;
76
- this.left = void 0;
77
- this.rright = void 0;
78
- this.top = void 0;
79
- this.bottom = void 0;
80
- this.zoom = 1;
81
- this.perspective = mat4.create();
82
- this.view = void 0;
83
- this.following = undefined;
84
- this.type = CAMERA_TYPE.EXPLORING;
85
- this.trackingMode = CAMERA_TRACKING_MODE.DEFAULT;
86
- this.projectionMode = CAMERA_PROJECTION_MODE.PERSPECTIVE;
87
- this.frustum = new Frustum();
88
- this.landmarks = [];
89
- this.landmarkAnimationID = void 0;
90
- }
91
-
92
- _createClass(Camera, [{
93
- key: "clone",
94
- value: function clone() {
95
- var camera = new Camera();
96
- camera.setType(this.type, undefined);
97
- camera.interactor = this.interactor;
98
- return camera;
99
- }
100
- }, {
101
- key: "getPerspective",
102
- value: function getPerspective() {
103
- return this.perspective;
104
- }
105
- }, {
106
- key: "getFrustum",
107
- value: function getFrustum() {
108
- return this.frustum;
109
- }
110
- }, {
111
- key: "getPosition",
112
- value: function getPosition() {
113
- return this.position;
114
- }
115
- }, {
116
- key: "setType",
117
- value: function setType(type, trackingMode) {
118
- this.type = type;
119
-
120
- if (this.type === CAMERA_TYPE.EXPLORING) {
121
- this.setWorldRotation(true);
122
- } else {
123
- this.setWorldRotation(false);
124
- }
125
-
126
- this._getAngles();
127
-
128
- if (this.type === CAMERA_TYPE.TRACKING && trackingMode !== undefined) {
129
- this.setTrackingMode(trackingMode);
130
- }
131
-
132
- return this;
133
- }
134
- }, {
135
- key: "setProjectionMode",
136
- value: function setProjectionMode(projectionMode) {
137
- this.projectionMode = projectionMode;
138
- return this;
139
- }
140
- }, {
141
- key: "setTrackingMode",
142
- value: function setTrackingMode(trackingMode) {
143
- if (this.type !== CAMERA_TYPE.TRACKING) {
144
- throw new Error('Impossible to set a tracking mode if the camera is not of tracking type');
145
- }
146
-
147
- this.trackingMode = trackingMode;
148
- return this;
149
- }
150
- /**
151
- * If flag is true, it reverses the azimuth and elevation angles.
152
- * Subsequent calls to rotate, setAzimuth, setElevation,
153
- * changeAzimuth or changeElevation will cause the inverted effect.
154
- * setRoll or changeRoll is not affected by this method.
155
- *
156
- * This inversion is useful when one wants to simulate that the world
157
- * is moving, instead of the camera.
158
- *
159
- * By default the camera angles are not reversed.
160
- * @param {Boolean} flag the boolean flag to reverse the angles.
161
- */
162
-
163
- }, {
164
- key: "setWorldRotation",
165
- value: function setWorldRotation(flag) {
166
- this.rotateWorld = flag;
167
-
168
- this._getAngles();
169
- }
170
- /**
171
- * 计算 MV 矩阵,为相机矩阵的逆矩阵
172
- */
173
-
174
- }, {
175
- key: "getViewTransform",
176
- value: function getViewTransform() {
177
- return mat4.invert(mat4.create(), this.matrix);
178
- }
179
- /**
180
- * 设置相机矩阵
181
- */
182
-
183
- }, {
184
- key: "setMatrix",
185
- value: function setMatrix(matrix) {
186
- this.matrix = matrix;
187
-
188
- this._update();
189
-
190
- return this;
191
- }
192
- }, {
193
- key: "setAspect",
194
- value: function setAspect(aspect) {
195
- this.setPerspective(this.near, this.far, this.fov, aspect);
196
- return this;
197
- }
198
- /**
199
- * Sets an offset in a larger frustum, used in PixelPicking
200
- */
201
-
202
- }, {
203
- key: "setViewOffset",
204
- value: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
205
- this.aspect = fullWidth / fullHeight;
206
-
207
- if (this.view === undefined) {
208
- this.view = {
209
- enabled: true,
210
- fullWidth: 1,
211
- fullHeight: 1,
212
- offsetX: 0,
213
- offsetY: 0,
214
- width: 1,
215
- height: 1
216
- };
217
- }
218
-
219
- this.view.enabled = true;
220
- this.view.fullWidth = fullWidth;
221
- this.view.fullHeight = fullHeight;
222
- this.view.offsetX = x;
223
- this.view.offsetY = y;
224
- this.view.width = width;
225
- this.view.height = height;
226
-
227
- if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
228
- this.setPerspective(this.near, this.far, this.fov, this.aspect);
229
- } else {
230
- this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
231
- }
232
-
233
- return this;
234
- }
235
- }, {
236
- key: "clearViewOffset",
237
- value: function clearViewOffset() {
238
- if (this.view !== undefined) {
239
- this.view.enabled = false;
240
- }
241
-
242
- if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
243
- this.setPerspective(this.near, this.far, this.fov, this.aspect);
244
- } else {
245
- this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
246
- }
247
-
248
- return this;
249
- }
250
- }, {
251
- key: "setPerspective",
252
- value: function setPerspective(near, far, fov, aspect) {
253
- this.projectionMode = CAMERA_PROJECTION_MODE.PERSPECTIVE;
254
- this.fov = fov;
255
- this.near = near;
256
- this.far = far;
257
- this.aspect = aspect;
258
- mat4.perspective(this.perspective, this.fov * DEG_2_RAD, this.aspect, this.near, this.far);
259
- return this;
260
- }
261
- }, {
262
- key: "setOrthographic",
263
- value: function setOrthographic(l, r, t, b, near, far) {
264
- this.projectionMode = CAMERA_PROJECTION_MODE.ORTHOGRAPHIC;
265
- this.rright = r;
266
- this.left = l;
267
- this.top = t;
268
- this.bottom = b;
269
- this.near = near;
270
- this.far = far;
271
- var dx = (this.rright - this.left) / (2 * this.zoom);
272
- var dy = (this.top - this.bottom) / (2 * this.zoom);
273
- var cx = (this.rright + this.left) / 2;
274
- var cy = (this.top + this.bottom) / 2;
275
- var left = cx - dx;
276
- var right = cx + dx;
277
- var top = cy + dy;
278
- var bottom = cy - dy;
279
-
280
- if (this.view !== undefined && this.view.enabled) {
281
- var scaleW = (this.rright - this.left) / this.view.fullWidth / this.zoom;
282
- var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
283
- left += scaleW * this.view.offsetX;
284
- right = left + scaleW * this.view.width;
285
- top -= scaleH * this.view.offsetY;
286
- bottom = top - scaleH * this.view.height;
287
- }
288
-
289
- mat4.ortho(this.perspective, left, right, top, bottom, near, far);
290
- return this;
291
- }
292
- /**
293
- * 设置相机位置
294
- */
295
-
296
- }, {
297
- key: "setPosition",
298
- value: function setPosition(x, y, z) {
299
- this._setPosition(x, y, z);
300
-
301
- this.setFocalPoint(this.focalPoint);
302
- return this;
303
- }
304
- /**
305
- * 设置视点位置
306
- */
307
-
308
- }, {
309
- key: "setFocalPoint",
310
- value: function setFocalPoint(x, y, z) {
311
- var up = vec3.fromValues(0, 1, 0);
312
- this.focalPoint = createVec3(x, y, z);
313
-
314
- if (this.trackingMode === CAMERA_TRACKING_MODE.CINEMATIC) {
315
- var d = vec3.subtract(vec3.create(), this.focalPoint, this.position);
316
- x = d[0];
317
- y = d[1];
318
- z = d[2];
319
- var r = vec3.length(d);
320
- var el = Math.asin(y / r) * RAD_2_DEG;
321
- var az = 90 + Math.atan2(z, x) * RAD_2_DEG;
322
- var m = mat4.create();
323
- mat4.rotateY(m, m, az * DEG_2_RAD);
324
- mat4.rotateX(m, m, el * DEG_2_RAD);
325
- up = vec3.transformMat4(vec3.create(), [0, 1, 0], m);
326
- }
327
-
328
- mat4.invert(this.matrix, mat4.lookAt(mat4.create(), this.position, this.focalPoint, up));
329
-
330
- this._getAxes();
331
-
332
- this._getDistance();
333
-
334
- this._getAngles();
335
-
336
- return this;
337
- }
338
- /**
339
- * 固定当前视点,按指定距离放置相机
340
- */
341
-
342
- }, {
343
- key: "setDistance",
344
- value: function setDistance(d) {
345
- if (this.distance === d || d < 0) {
346
- return;
347
- }
348
-
349
- this.distance = d;
350
-
351
- if (this.distance < 0.0002) {
352
- this.distance = 0.0002;
353
- }
354
-
355
- this.dollyingStep = this.distance / 100;
356
- var pos = vec3.create();
357
- d = this.distance;
358
- var n = this.forward;
359
- var f = this.focalPoint;
360
- pos[0] = d * n[0] + f[0];
361
- pos[1] = d * n[1] + f[1];
362
- pos[2] = d * n[2] + f[2];
363
-
364
- this._setPosition(pos);
365
-
366
- return this;
367
- }
368
- /**
369
- * Changes the initial azimuth of the camera
370
- */
371
-
372
- }, {
373
- key: "changeAzimuth",
374
- value: function changeAzimuth(az) {
375
- this.setAzimuth(this.azimuth + az);
376
- return this;
377
- }
378
- /**
379
- * Changes the initial elevation of the camera
380
- */
381
-
382
- }, {
383
- key: "changeElevation",
384
- value: function changeElevation(el) {
385
- this.setElevation(this.elevation + el);
386
- return this;
387
- }
388
- /**
389
- * Changes the initial roll of the camera
390
- */
391
-
392
- }, {
393
- key: "changeRoll",
394
- value: function changeRoll(rl) {
395
- this.setRoll(this.roll + rl);
396
- return this;
397
- }
398
- /**
399
- * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
400
- * @param {Number} el the azimuth in degrees
401
- */
402
-
403
- }, {
404
- key: "setAzimuth",
405
- value: function setAzimuth(az) {
406
- this.azimuth = getAngle(az);
407
- this.computeMatrix();
408
-
409
- this._getAxes();
410
-
411
- if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
412
- this._getPosition();
413
- } else if (this.type === CAMERA_TYPE.TRACKING) {
414
- this._getFocalPoint();
415
- }
416
-
417
- return this;
418
- }
419
- }, {
420
- key: "getAzimuth",
421
- value: function getAzimuth() {
422
- return this.azimuth;
423
- }
424
- /**
425
- * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
426
- * @param {Number} el the elevation in degrees
427
- */
428
-
429
- }, {
430
- key: "setElevation",
431
- value: function setElevation(el) {
432
- this.elevation = getAngle(el);
433
- this.computeMatrix();
434
-
435
- this._getAxes();
436
-
437
- if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
438
- this._getPosition();
439
- } else if (this.type === CAMERA_TYPE.TRACKING) {
440
- this._getFocalPoint();
441
- }
442
-
443
- return this;
444
- }
445
- /**
446
- * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
447
- * @param {Number} angle the roll angle
448
- */
449
-
450
- }, {
451
- key: "setRoll",
452
- value: function setRoll(angle) {
453
- this.roll = getAngle(angle);
454
- this.computeMatrix();
455
-
456
- this._getAxes();
457
-
458
- if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
459
- this._getPosition();
460
- } else if (this.type === CAMERA_TYPE.TRACKING) {
461
- this._getFocalPoint();
462
- }
463
-
464
- return this;
465
- }
466
- /**
467
- * Changes the azimuth and elevation with respect to the current camera axes
468
- * @param {Number} azimuth the relative azimuth
469
- * @param {Number} elevation the relative elevation
470
- * @param {Number} roll the relative roll
471
- */
472
-
473
- }, {
474
- key: "rotate",
475
- value: function rotate(azimuth, elevation, roll) {
476
- if (this.type === CAMERA_TYPE.EXPLORING) {
477
- azimuth = getAngle(azimuth);
478
- elevation = getAngle(elevation);
479
- roll = getAngle(roll);
480
- var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld ? 1 : -1) * elevation * DEG_2_RAD);
481
- var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld ? 1 : -1) * azimuth * DEG_2_RAD);
482
- var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], roll * DEG_2_RAD);
483
- var rotQ = quat.multiply(quat.create(), rotY, rotX);
484
- rotQ = quat.multiply(quat.create(), rotQ, rotZ);
485
- var rotMatrix = mat4.fromQuat(mat4.create(), rotQ);
486
- mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]);
487
- mat4.multiply(this.matrix, this.matrix, rotMatrix);
488
- mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
489
- } else {
490
- if (Math.abs(this.elevation + elevation) > 90) {
491
- return;
492
- }
493
-
494
- this.relElevation = getAngle(elevation);
495
- this.relAzimuth = getAngle(azimuth);
496
- this.relRoll = getAngle(roll);
497
- this.elevation += this.relElevation;
498
- this.azimuth += this.relAzimuth;
499
- this.roll += this.relRoll;
500
- this.computeMatrix();
501
- }
502
-
503
- this._getAxes();
504
-
505
- if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
506
- this._getPosition();
507
- } else if (this.type === CAMERA_TYPE.TRACKING) {
508
- this._getFocalPoint();
509
- }
510
-
511
- this._update();
512
-
513
- return this;
514
- }
515
- /**
516
- * 沿水平(right) & 垂直(up)平移相机
517
- */
518
-
519
- }, {
520
- key: "pan",
521
- value: function pan(tx, ty) {
522
- var coords = createVec3(tx, ty, 0);
523
- var pos = vec3.clone(this.position);
524
- vec3.add(pos, pos, vec3.scale(vec3.create(), this.right, coords[0]));
525
- vec3.add(pos, pos, vec3.scale(vec3.create(), this.up, coords[1]));
526
-
527
- this._setPosition(pos);
528
-
529
- return this;
530
- }
531
- /**
532
- * 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢
533
- */
534
-
535
- }, {
536
- key: "dolly",
537
- value: function dolly(value) {
538
- var n = this.forward;
539
- var pos = vec3.clone(this.position);
540
- var step = value * this.dollyingStep;
541
- pos[0] += step * n[0];
542
- pos[1] += step * n[1];
543
- pos[2] += step * n[2];
544
-
545
- this._setPosition(pos);
546
-
547
- if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
548
- // 重新计算视点距离
549
- this._getDistance();
550
- } else if (this.type === CAMERA_TYPE.TRACKING) {
551
- // 保持视距,移动视点位置
552
- vec3.add(this.focalPoint, pos, this.distanceVector);
553
- }
554
-
555
- return this;
556
- }
557
- }, {
558
- key: "createLandmark",
559
- value: function createLandmark(name, params) {
560
- var camera = this.clone();
561
- camera.setPosition(params.position);
562
- camera.setFocalPoint(params.focalPoint);
563
-
564
- if (params.roll !== undefined) {
565
- camera.setRoll(params.roll);
566
- }
567
-
568
- var landmark = new Landmark(name, camera);
569
- this.landmarks.push(landmark);
570
- return landmark;
571
- }
572
- }, {
573
- key: "setLandmark",
574
- value: function setLandmark(name) {
575
- var landmark = new Landmark(name, this);
576
- this.landmarks.push(landmark);
577
- return this;
578
- }
579
- }, {
580
- key: "gotoLandmark",
581
- value: function gotoLandmark(name) {
582
- var _this = this;
583
-
584
- var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
585
- var landmark = this.landmarks.find(function (l) {
586
- return l.name === name;
587
- });
588
-
589
- if (landmark) {
590
- if (duration === 0) {
591
- landmark.retrieve(this);
592
- return;
593
- }
594
-
595
- if (this.landmarkAnimationID !== undefined) {
596
- window.cancelAnimationFrame(this.landmarkAnimationID);
597
- } // TODO: do not process events during animation
598
-
599
-
600
- this.interactor.disconnect();
601
- var destPosition = landmark.getPosition();
602
- var destFocalPoint = landmark.getFocalPoint();
603
- var destRoll = landmark.getRoll();
604
- var timeStart;
605
-
606
- var animate = function animate(timestamp) {
607
- if (timeStart === undefined) {
608
- timeStart = timestamp;
609
- }
610
-
611
- var elapsed = timestamp - timeStart; // TODO: use better ease function
612
-
613
- var t = (1 - Math.cos(elapsed / duration * Math.PI)) / 2;
614
- var interFocalPoint = vec3.create();
615
- var interPosition = vec3.create();
616
- var interRoll = 0;
617
- vec3.lerp(interFocalPoint, _this.focalPoint, destFocalPoint, t);
618
- vec3.lerp(interPosition, _this.position, destPosition, t);
619
- interRoll = _this.roll * (1 - t) + destRoll * t;
620
-
621
- _this.setFocalPoint(interFocalPoint);
622
-
623
- _this.setPosition(interPosition);
624
-
625
- _this.setRoll(interRoll);
626
-
627
- _this.computeMatrix();
628
-
629
- var dist = vec3.dist(interFocalPoint, destFocalPoint) + vec3.dist(interPosition, destPosition);
630
-
631
- if (dist > 0.01) {//
632
- } else {
633
- _this.setFocalPoint(interFocalPoint);
634
-
635
- _this.setPosition(interPosition);
636
-
637
- _this.setRoll(interRoll);
638
-
639
- _this.computeMatrix();
640
-
641
- _this.interactor.connect();
642
-
643
- return;
644
- }
645
-
646
- if (elapsed < duration) {
647
- _this.landmarkAnimationID = window.requestAnimationFrame(animate);
648
- }
649
- };
650
-
651
- window.requestAnimationFrame(animate);
652
- }
653
- }
654
- /**
655
- * 根据相机矩阵重新计算各种相机参数
656
- */
657
-
658
- }, {
659
- key: "_update",
660
- value: function _update() {
661
- this._getAxes();
662
-
663
- this._getPosition();
664
-
665
- this._getDistance();
666
-
667
- this._getAngles();
668
- }
669
- /**
670
- * 计算相机矩阵
671
- */
672
-
673
- }, {
674
- key: "computeMatrix",
675
- value: function computeMatrix() {
676
- var rotX;
677
- var rotY; // 使用四元数描述 3D 旋转
678
- // @see https://xiaoiver.github.io/coding/2018/12/28/Camera-%E8%AE%BE%E8%AE%A1-%E4%B8%80.html
679
-
680
- var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], this.roll * DEG_2_RAD);
681
- mat4.identity(this.matrix); // only consider HCS for EXPLORING and ORBITING cameras
682
-
683
- rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld && this.type !== CAMERA_TYPE.TRACKING || this.type === CAMERA_TYPE.TRACKING ? 1 : -1) * this.elevation * DEG_2_RAD);
684
- rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld && this.type !== CAMERA_TYPE.TRACKING || this.type === CAMERA_TYPE.TRACKING ? 1 : -1) * this.azimuth * DEG_2_RAD);
685
- var rotQ = quat.multiply(quat.create(), rotY, rotX);
686
- rotQ = quat.multiply(quat.create(), rotQ, rotZ);
687
- var rotMatrix = mat4.fromQuat(mat4.create(), rotQ);
688
-
689
- if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
690
- mat4.translate(this.matrix, this.matrix, this.focalPoint);
691
- mat4.multiply(this.matrix, this.matrix, rotMatrix);
692
- mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
693
- } else if (this.type === CAMERA_TYPE.TRACKING) {
694
- mat4.translate(this.matrix, this.matrix, this.position);
695
- mat4.multiply(this.matrix, this.matrix, rotMatrix);
696
- }
697
- }
698
- /**
699
- * Sets the camera position in the camera matrix
700
- */
701
-
702
- }, {
703
- key: "_setPosition",
704
- value: function _setPosition(x, y, z) {
705
- this.position = createVec3(x, y, z);
706
- var m = this.matrix;
707
- m[12] = this.position[0];
708
- m[13] = this.position[1];
709
- m[14] = this.position[2];
710
- m[15] = 1;
711
- }
712
- /**
713
- * Recalculates axes based on the current matrix
714
- */
715
-
716
- }, {
717
- key: "_getAxes",
718
- value: function _getAxes() {
719
- vec3.copy(this.right, createVec3(vec4.transformMat4(vec4.create(), [1, 0, 0, 0], this.matrix)));
720
- vec3.copy(this.up, createVec3(vec4.transformMat4(vec4.create(), [0, 1, 0, 0], this.matrix)));
721
- vec3.copy(this.forward, createVec3(vec4.transformMat4(vec4.create(), [0, 0, 1, 0], this.matrix)));
722
- vec3.normalize(this.right, this.right);
723
- vec3.normalize(this.up, this.up);
724
- vec3.normalize(this.forward, this.forward);
725
- }
726
- /**
727
- * Recalculates euler angles based on the current state
728
- */
729
-
730
- }, {
731
- key: "_getAngles",
732
- value: function _getAngles() {
733
- // Recalculates angles
734
- var x = this.distanceVector[0];
735
- var y = this.distanceVector[1];
736
- var z = this.distanceVector[2];
737
- var r = vec3.length(this.distanceVector); // FAST FAIL: If there is no distance we cannot compute angles
738
-
739
- if (r === 0) {
740
- this.elevation = 0;
741
- this.azimuth = 0;
742
- return;
743
- }
744
-
745
- if (this.type === CAMERA_TYPE.TRACKING) {
746
- this.elevation = Math.asin(y / r) * RAD_2_DEG;
747
- this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
748
- } else {
749
- if (this.rotateWorld) {
750
- this.elevation = Math.asin(y / r) * RAD_2_DEG;
751
- this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
752
- } else {
753
- this.elevation = -Math.asin(y / r) * RAD_2_DEG;
754
- this.azimuth = -Math.atan2(-x, -z) * RAD_2_DEG;
755
- }
756
- }
757
- }
758
- /**
759
- * 重新计算相机位置,只有 ORBITING 模式相机位置才会发生变化
760
- */
761
-
762
- }, {
763
- key: "_getPosition",
764
- value: function _getPosition() {
765
- vec3.copy(this.position, createVec3(vec4.transformMat4(vec4.create(), [0, 0, 0, 1], this.matrix))); // 相机位置变化,需要重新计算视距
766
-
767
- this._getDistance();
768
- }
769
- /**
770
- * 重新计算视点,只有 TRACKING 模式视点才会发生变化
771
- */
772
-
773
- }, {
774
- key: "_getFocalPoint",
775
- value: function _getFocalPoint() {
776
- vec3.transformMat3(this.distanceVector, [0, 0, -this.distance], mat3.fromMat4(mat3.create(), this.matrix));
777
- vec3.add(this.focalPoint, this.position, this.distanceVector); // 视点变化,需要重新计算视距
778
-
779
- this._getDistance();
780
- }
781
- /**
782
- * 重新计算视距
783
- */
784
-
785
- }, {
786
- key: "_getDistance",
787
- value: function _getDistance() {
788
- this.distanceVector = vec3.subtract(vec3.create(), this.focalPoint, this.position);
789
- this.distance = vec3.length(this.distanceVector);
790
- this.dollyingStep = this.distance / 100;
791
- }
792
- }]);
793
-
794
- return Camera;
795
- }(), _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "interactor", [_dec2], {
796
- configurable: true,
797
- enumerable: true,
798
- writable: true,
799
- initializer: null
800
- })), _class2)) || _class);
801
- //# sourceMappingURL=Camera.js.map