@antv/g-webgpu 0.5.6 → 0.7.0

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