@openglobus/og 0.23.0 → 0.24.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 (84) hide show
  1. package/lib/@openglobus/js/Globe.d.ts +0 -1
  2. package/lib/@openglobus/js/camera/Camera.d.ts +48 -15
  3. package/lib/@openglobus/js/camera/PlanetCamera.d.ts +13 -0
  4. package/lib/@openglobus/js/control/MouseNavigation.d.ts +62 -51
  5. package/lib/@openglobus/js/control/OldMouseNavigation.d.ts +64 -0
  6. package/lib/@openglobus/js/control/index.d.ts +1 -2
  7. package/lib/@openglobus/js/entity/Entity.d.ts +24 -20
  8. package/lib/@openglobus/js/entity/GeoObject.d.ts +0 -9
  9. package/lib/@openglobus/js/input/MouseHandler.d.ts +1 -0
  10. package/lib/@openglobus/js/math/Mat3.d.ts +1 -1
  11. package/lib/@openglobus/js/math/Mat4.d.ts +10 -1
  12. package/lib/@openglobus/js/math/Plane.d.ts +3 -1
  13. package/lib/@openglobus/js/math/Quat.d.ts +1 -0
  14. package/lib/@openglobus/js/math/Ray.d.ts +6 -16
  15. package/lib/@openglobus/js/math/Vec2.d.ts +22 -0
  16. package/lib/@openglobus/js/renderer/RendererEvents.d.ts +1 -0
  17. package/lib/@openglobus/js/scene/Planet.d.ts +4 -0
  18. package/lib/@openglobus/js/webgl/Handler.d.ts +21 -12
  19. package/lib/@openglobus/og.esm.js +1 -1
  20. package/lib/@openglobus/og.esm.js.map +1 -1
  21. package/lib/@openglobus/og.umd.js +1 -1
  22. package/lib/@openglobus/og.umd.js.map +1 -1
  23. package/lib/js/Globe.d.ts +0 -1
  24. package/lib/js/Globe.js +4 -2
  25. package/lib/js/Popup.js +1 -1
  26. package/lib/js/camera/Camera.d.ts +48 -15
  27. package/lib/js/camera/Camera.js +82 -28
  28. package/lib/js/camera/PlanetCamera.d.ts +13 -0
  29. package/lib/js/camera/PlanetCamera.js +52 -5
  30. package/lib/js/control/CameraLock.js +1 -1
  31. package/lib/js/control/DebugInfo.js +30 -10
  32. package/lib/js/control/KeyboardNavigation.js +8 -8
  33. package/lib/js/control/MouseNavigation.d.ts +62 -51
  34. package/lib/js/control/MouseNavigation.js +361 -305
  35. package/lib/js/control/MouseWheelZoomControl.d.ts +0 -44
  36. package/lib/js/control/MouseWheelZoomControl.js +270 -181
  37. package/lib/js/control/OldMouseNavigation.d.ts +64 -0
  38. package/lib/js/control/OldMouseNavigation.js +368 -0
  39. package/lib/js/control/ScaleControl.js +2 -2
  40. package/lib/js/control/SimpleNavigation.js +8 -7
  41. package/lib/js/control/Sun.js +5 -5
  42. package/lib/js/control/TouchNavigation.js +11 -8
  43. package/lib/js/control/elevationProfile/ElevationProfileScene.js +2 -1
  44. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.js +19 -33
  45. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.js +18 -18
  46. package/lib/js/control/geoObjectEditor/MoveAxisEntity.js +3 -2
  47. package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +1 -4
  48. package/lib/js/control/geoObjectEditor/RotateEntity.js +1 -1
  49. package/lib/js/control/index.d.ts +1 -2
  50. package/lib/js/control/index.js +1 -2
  51. package/lib/js/control/visibleExtent/Segment.js +4 -4
  52. package/lib/js/entity/Entity.d.ts +24 -20
  53. package/lib/js/entity/Entity.js +62 -47
  54. package/lib/js/entity/GeoObject.d.ts +0 -9
  55. package/lib/js/entity/GeoObject.js +0 -3
  56. package/lib/js/entity/InstanceData.js +6 -3
  57. package/lib/js/input/MouseHandler.d.ts +1 -0
  58. package/lib/js/input/MouseHandler.js +12 -1
  59. package/lib/js/math/Mat3.d.ts +1 -1
  60. package/lib/js/math/Mat3.js +1 -1
  61. package/lib/js/math/Mat4.d.ts +10 -1
  62. package/lib/js/math/Mat4.js +17 -1
  63. package/lib/js/math/Plane.d.ts +3 -1
  64. package/lib/js/math/Plane.js +11 -1
  65. package/lib/js/math/Quat.d.ts +1 -0
  66. package/lib/js/math/Quat.js +1 -0
  67. package/lib/js/math/Ray.d.ts +6 -16
  68. package/lib/js/math/Ray.js +53 -46
  69. package/lib/js/math/Vec2.d.ts +22 -0
  70. package/lib/js/math/Vec2.js +32 -0
  71. package/lib/js/renderer/Renderer.js +10 -6
  72. package/lib/js/renderer/RendererEvents.d.ts +1 -0
  73. package/lib/js/renderer/RendererEvents.js +3 -1
  74. package/lib/js/scene/Planet.d.ts +4 -0
  75. package/lib/js/scene/Planet.js +24 -3
  76. package/lib/js/segment/Segment.js +4 -4
  77. package/lib/js/terrain/GlobusTerrain.js +2 -2
  78. package/lib/js/webgl/Handler.d.ts +21 -12
  79. package/lib/js/webgl/Handler.js +42 -33
  80. package/package.json +2 -2
  81. package/lib/@openglobus/js/control/EarthNavigation.d.ts +0 -50
  82. package/lib/@openglobus/js/control/MouseWheelZoomControl.d.ts +0 -44
  83. package/lib/js/control/EarthNavigation.d.ts +0 -50
  84. package/lib/js/control/EarthNavigation.js +0 -202
@@ -156,17 +156,20 @@ export class InstanceData {
156
156
  }
157
157
  createColorTexture(image) {
158
158
  if (this._geoObjectHandler && this._geoObjectHandler._renderer) {
159
- this._colorTexture = this._geoObjectHandler._renderer.handler.createTextureDefault(image);
159
+ let h = this._geoObjectHandler._renderer.handler;
160
+ this._colorTexture = h.createTextureDefault(image, null, h.gl.REPEAT);
160
161
  }
161
162
  }
162
163
  createNormalTexture(image) {
163
164
  if (this._geoObjectHandler && this._geoObjectHandler._renderer) {
164
- this._normalTexture = this._geoObjectHandler._renderer.handler.createTextureDefault(image);
165
+ let h = this._geoObjectHandler._renderer.handler;
166
+ this._normalTexture = h.createTextureDefault(image, null, h.gl.REPEAT);
165
167
  }
166
168
  }
167
169
  createMetallicRoughnessTexture(image) {
168
170
  if (this._geoObjectHandler && this._geoObjectHandler._renderer) {
169
- this._metallicRoughnessTexture = this._geoObjectHandler._renderer.handler.createTextureDefault(image);
171
+ let h = this._geoObjectHandler._renderer.handler;
172
+ this._metallicRoughnessTexture = h.createTextureDefault(image, null, h.gl.REPEAT);
170
173
  }
171
174
  }
172
175
  clear() {
@@ -1,6 +1,7 @@
1
1
  export type MouseEventExt = MouseEvent & {
2
2
  wheelDelta?: number;
3
3
  deltaY?: number;
4
+ isTouchPad?: boolean;
4
5
  };
5
6
  export interface MouseHandlerEvent {
6
7
  button?: number;
@@ -1,3 +1,13 @@
1
+ function _checkTouchPad(e) {
2
+ //@ts-ignore
3
+ if (e.deltaMode !== 0) {
4
+ return false;
5
+ }
6
+ //@ts-ignore
7
+ return Math.abs(e.deltaY) < 50;
8
+ //@ts-ignore
9
+ //return e.wheelDeltaY ? e.wheelDeltaY === -3 * e.deltaY : e.deltaMode === 0
10
+ }
1
11
  class MouseHandler {
2
12
  constructor(htmlObject) {
3
13
  this._htmlObject = htmlObject;
@@ -13,11 +23,12 @@ class MouseHandler {
13
23
  // callback.call(sender, event);
14
24
  // event.preventDefault();
15
25
  // }, false);
16
- this._htmlObject.addEventListener('wheel', function (event) {
26
+ this._htmlObject.addEventListener('wheel', (event) => {
17
27
  let delta = event.deltaY || event.detail || event.wheelDelta || 0;
18
28
  if (event.wheelDelta == undefined) {
19
29
  event.wheelDelta = delta * (-120);
20
30
  }
31
+ event.isTouchPad = _checkTouchPad(event);
21
32
  callback.call(sender, event);
22
33
  event.preventDefault();
23
34
  }, false);
@@ -67,7 +67,7 @@ export declare class Mat3 {
67
67
  * @public
68
68
  * @returns {Mat4}
69
69
  */
70
- toMatrix4(): Mat4;
70
+ getMat4(): Mat4;
71
71
  }
72
72
  /**
73
73
  * Mat3 factory.
@@ -106,7 +106,7 @@ export class Mat3 {
106
106
  * @public
107
107
  * @returns {Mat4}
108
108
  */
109
- toMatrix4() {
109
+ getMat4() {
110
110
  let res = new Mat4();
111
111
  let b = res._m;
112
112
  let a = this._m;
@@ -37,6 +37,15 @@ export declare class Mat4 {
37
37
  * @returns {Mat4} -
38
38
  */
39
39
  static identity(): Mat4;
40
+ /**
41
+ * Get rotation matrix around the point
42
+ * @public
43
+ * @param {number} angle - Rotation angle in radians
44
+ * @param {Vec3} [center] - Point that the camera rotates around
45
+ * @param {Vec3} [up] - Camera up vector
46
+ */
47
+ static getRotationAroundPoint(angle: number, center?: Vec3, up?: Vec3): Mat4;
48
+ static getRotation(angle: number, up?: Vec3): Mat4;
40
49
  /**
41
50
  * Sets column-major order array matrix.
42
51
  * @public
@@ -62,7 +71,7 @@ export declare class Mat4 {
62
71
  * @public
63
72
  * @returns {Mat3} -
64
73
  */
65
- toMatrix3(): Mat3;
74
+ getMat3(): Mat3;
66
75
  /**
67
76
  * Multiply to 3d vector.
68
77
  * @public
@@ -45,6 +45,22 @@ export class Mat4 {
45
45
  res._m[15] = 1;
46
46
  return res;
47
47
  }
48
+ /**
49
+ * Get rotation matrix around the point
50
+ * @public
51
+ * @param {number} angle - Rotation angle in radians
52
+ * @param {Vec3} [center] - Point that the camera rotates around
53
+ * @param {Vec3} [up] - Camera up vector
54
+ */
55
+ static getRotationAroundPoint(angle, center = Vec3.ZERO, up = Vec3.UP) {
56
+ let rot = Mat4.getRotation(angle, up);
57
+ let tr = new Mat4().setIdentity().translate(center);
58
+ let ntr = new Mat4().setIdentity().translate(center.negateTo());
59
+ return tr.mul(rot).mul(ntr);
60
+ }
61
+ static getRotation(angle, up = Vec3.UP) {
62
+ return new Mat4().setRotation(up, angle);
63
+ }
48
64
  /**
49
65
  * Sets column-major order array matrix.
50
66
  * @public
@@ -94,7 +110,7 @@ export class Mat4 {
94
110
  * @public
95
111
  * @returns {Mat3} -
96
112
  */
97
- toMatrix3() {
113
+ getMat3() {
98
114
  let res = new Mat3();
99
115
  let a = this._m, b = res._m;
100
116
  b[0] = a[0];
@@ -9,7 +9,9 @@ import { Line3 } from "./Line3";
9
9
  declare class Plane {
10
10
  p: Vec3;
11
11
  n: Vec3;
12
- constructor(p: Vec3, n: Vec3);
12
+ constructor(p?: Vec3, n?: Vec3);
13
+ setByPoints(v0: Vec3, v1: Vec3, v2: Vec3): Plane;
14
+ static fromPoints(v0: Vec3, v1: Vec3, v2: Vec3): Plane;
13
15
  set(p: Vec3, n: Vec3): void;
14
16
  getNormal(): Vec3;
15
17
  distance(p: Vec3): number;
@@ -12,7 +12,17 @@ const INTERSECT = 2;
12
12
  class Plane {
13
13
  constructor(p, n) {
14
14
  this.p = p ? p.clone() : new Vec3();
15
- this.n = n ? n.clone() : this.p.normal();
15
+ this.n = n ? n.clone() : (this.p.isZero() ? Vec3.UP : this.p.getNormal());
16
+ }
17
+ setByPoints(v0, v1, v2) {
18
+ let u = Vec3.sub(v1, v0);
19
+ let v = Vec3.sub(v2, v0);
20
+ this.n = u.cross(v);
21
+ this.p.copy(v0);
22
+ return this;
23
+ }
24
+ static fromPoints(v0, v1, v2) {
25
+ return new Plane().setByPoints(v0, v1, v2);
16
26
  }
17
27
  set(p, n) {
18
28
  this.p.copy(p);
@@ -298,6 +298,7 @@ export declare class Quat {
298
298
  * Returns quaternion and vector production.
299
299
  * @public
300
300
  * @param {Vec3} v - 3d Vector.
301
+ * @param {Vec3} res - result output vector.
301
302
  * @returns {Vec3} -
302
303
  */
303
304
  mulVec3Res(v: Vec3, res: Vec3): Vec3;
@@ -617,6 +617,7 @@ export class Quat {
617
617
  * Returns quaternion and vector production.
618
618
  * @public
619
619
  * @param {Vec3} v - 3d Vector.
620
+ * @param {Vec3} res - result output vector.
620
621
  * @returns {Vec3} -
621
622
  */
622
623
  mulVec3Res(v, res) {
@@ -45,7 +45,7 @@ export declare class Ray {
45
45
  */
46
46
  getPoint(distance: number): Vec3;
47
47
  /**
48
- * Returns ray hit a triange result.
48
+ * Returns ray hit a triangle result.
49
49
  * @public
50
50
  * @param {Vec3} v0 - First triangle corner coordinate.
51
51
  * @param {Vec3} v1 - Second triangle corner coordinate.
@@ -54,17 +54,13 @@ export declare class Ray {
54
54
  * @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
55
55
  * 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
56
56
  */
57
- hitTriangle(v0: Vec3, v1: Vec3, v2: Vec3, res: Vec3): number;
57
+ hitTriangleRes(v0: Vec3, v1: Vec3, v2: Vec3, res: Vec3): number;
58
58
  /**
59
- * Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
60
- * @public
61
- * @param {Vec3} v0 - First plane point.
62
- * @param {Vec3} v1 - Second plane point.
63
- * @param {Vec3} v2 - Third plane point.
64
- * @param {Vec3} res - Hit point object pointer that stores hit result.
65
- * @returns {number}
59
+ * Finds the intersection of the ray with a plane.
60
+ * @param {Plane} plane - The plane to intersect with.
61
+ * @returns {Vec3 | null} The intersection point or null if no intersection.
66
62
  */
67
- hitPlane(v0: Vec3, v1: Vec3, v2: Vec3, res: Vec3): number;
63
+ hitPlaneRes(plane: Plane, res: Vec3): number;
68
64
  /**
69
65
  * Returns a ray hit sphere coordiante. If there isn't hit returns null.
70
66
  * @public
@@ -73,10 +69,4 @@ export declare class Ray {
73
69
  */
74
70
  hitSphere(sphere: Sphere): Vec3 | null;
75
71
  hitBox(box: Box): void;
76
- /**
77
- * Finds the intersection of the ray with a plane.
78
- * @param {Plane} plane - The plane to intersect with.
79
- * @returns {Vec3 | null} The intersection point or null if no intersection.
80
- */
81
- hitPlane2(plane: Plane, res: Vec3): number;
82
72
  }
@@ -48,7 +48,7 @@ export class Ray {
48
48
  return Vec3.add(this.origin, this.direction.scaleTo(distance));
49
49
  }
50
50
  /**
51
- * Returns ray hit a triange result.
51
+ * Returns ray hit a triangle result.
52
52
  * @public
53
53
  * @param {Vec3} v0 - First triangle corner coordinate.
54
54
  * @param {Vec3} v1 - Second triangle corner coordinate.
@@ -57,7 +57,7 @@ export class Ray {
57
57
  * @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
58
58
  * 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
59
59
  */
60
- hitTriangle(v0, v1, v2, res) {
60
+ hitTriangleRes(v0, v1, v2, res) {
61
61
  let u = v1.sub(v0);
62
62
  let v = v2.sub(v0);
63
63
  let n = u.cross(v);
@@ -101,37 +101,61 @@ export class Ray {
101
101
  }
102
102
  return Ray.INSIDE;
103
103
  }
104
+ // /**
105
+ // * Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
106
+ // * @public
107
+ // * @param {Vec3} v0 - First plane point.
108
+ // * @param {Vec3} v1 - Second plane point.
109
+ // * @param {Vec3} v2 - Third plane point.
110
+ // * @param {Vec3} res - Hit point object pointer that stores hit result.
111
+ // * @returns {number}
112
+ // */
113
+ // public hitPlaneRes(v0: Vec3, v1: Vec3, v2: Vec3, res: Vec3): number {
114
+ // let u = Vec3.sub(v1, v0);
115
+ // let v = Vec3.sub(v2, v0);
116
+ // let n = u.cross(v);
117
+ //
118
+ // let w0 = Vec3.sub(this.origin, v0);
119
+ // let a = -n.dot(w0);
120
+ // let b = n.dot(this.direction);
121
+ //
122
+ // // ray is parallel to the plane
123
+ // if (Math.abs(b) < EPS10) {
124
+ // if (a === 0) {
125
+ // return Ray.OUTSIDE;
126
+ // }
127
+ // }
128
+ //
129
+ // let r = a / b;
130
+ //
131
+ // if (r < 0) {
132
+ // return Ray.OUTSIDE;
133
+ // }
134
+ //
135
+ // let d = this.direction.scaleTo(r);
136
+ //
137
+ // // intersect point of ray and plane
138
+ // res.x = this.origin.x + d.x;
139
+ // res.y = this.origin.y + d.y;
140
+ // res.z = this.origin.z + d.z;
141
+ //
142
+ // return Ray.INSIDE;
143
+ // }
104
144
  /**
105
- * Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
106
- * @public
107
- * @param {Vec3} v0 - First plane point.
108
- * @param {Vec3} v1 - Second plane point.
109
- * @param {Vec3} v2 - Third plane point.
110
- * @param {Vec3} res - Hit point object pointer that stores hit result.
111
- * @returns {number}
145
+ * Finds the intersection of the ray with a plane.
146
+ * @param {Plane} plane - The plane to intersect with.
147
+ * @returns {Vec3 | null} The intersection point or null if no intersection.
112
148
  */
113
- hitPlane(v0, v1, v2, res) {
114
- let u = Vec3.sub(v1, v0);
115
- let v = Vec3.sub(v2, v0);
116
- let n = u.cross(v);
117
- let w0 = Vec3.sub(this.origin, v0);
118
- let a = -n.dot(w0);
119
- let b = n.dot(this.direction);
120
- // ray is parallel to the plane
121
- if (Math.abs(b) < EPS10) {
122
- if (a === 0) {
123
- return Ray.OUTSIDE;
124
- }
125
- }
126
- let r = a / b;
127
- if (r < 0) {
149
+ hitPlaneRes(plane, res) {
150
+ const d = this.direction.dot(plane.n);
151
+ if (Math.abs(d) < EPS10) {
128
152
  return Ray.OUTSIDE;
129
153
  }
130
- let d = this.direction.scaleTo(r);
131
- // intersect point of ray and plane
132
- res.x = this.origin.x + d.x;
133
- res.y = this.origin.y + d.y;
134
- res.z = this.origin.z + d.z;
154
+ const t = plane.p.sub(this.origin).dot(plane.n) / d;
155
+ if (t < 0) {
156
+ return Ray.AWAY;
157
+ }
158
+ res.copy(this.getPoint(t));
135
159
  return Ray.INSIDE;
136
160
  }
137
161
  /**
@@ -184,21 +208,4 @@ export class Ray {
184
208
  // TODO
185
209
  //
186
210
  }
187
- /**
188
- * Finds the intersection of the ray with a plane.
189
- * @param {Plane} plane - The plane to intersect with.
190
- * @returns {Vec3 | null} The intersection point or null if no intersection.
191
- */
192
- hitPlane2(plane, res) {
193
- const d = this.direction.dot(plane.n);
194
- if (Math.abs(d) < EPS10) {
195
- return Ray.OUTSIDE;
196
- }
197
- const t = plane.p.sub(this.origin).dot(plane.n) / d;
198
- if (t < 0) {
199
- return Ray.AWAY;
200
- }
201
- res.copy(this.getPoint(t));
202
- return Ray.INSIDE;
203
- }
204
211
  }
@@ -92,6 +92,15 @@ export declare class Vec2 {
92
92
  * @returns {Vec2}
93
93
  */
94
94
  static orthoNormalize(normal: Vec2, tangent: Vec2): Vec2;
95
+ /**
96
+ * Get projection of the vector to plane where n - normal to the plane.
97
+ * @static
98
+ * @param {Vec2} b - Vector to project.
99
+ * @param {Vec2} n - Plane normal.
100
+ * @param {Vec2} [def] - Default value for non existed result.
101
+ * @returns {Vec2} -
102
+ */
103
+ static proj_b_to_plane(b: Vec2, n: Vec2, def?: Vec3): Vec2;
95
104
  /**
96
105
  * Converts to 3d vector, third value is 0.0.
97
106
  * @public
@@ -221,10 +230,17 @@ export declare class Vec2 {
221
230
  clear(): Vec2;
222
231
  /**
223
232
  * Returns normalized vector.
233
+ * @deprecated
224
234
  * @public
225
235
  * @returns {Vec2}
226
236
  */
227
237
  normal(): Vec2;
238
+ /**
239
+ * Returns normalized vector.
240
+ * @public
241
+ * @returns {Vec2}
242
+ */
243
+ getNormal(): Vec2;
228
244
  /**
229
245
  * Normalize current vector.
230
246
  * @public
@@ -299,6 +315,12 @@ export declare class Vec2 {
299
315
  * @returns {Vec2}
300
316
  */
301
317
  slerp(v2: Vec2, t: number): Vec2;
318
+ /**
319
+ * Returns true if vector's values are zero.
320
+ * @public
321
+ * @returns {boolean} -
322
+ */
323
+ isZero(): boolean;
302
324
  }
303
325
  /**
304
326
  * Vector 2d object creator.
@@ -122,6 +122,21 @@ export class Vec2 {
122
122
  normal.scale(tangent.dot(normal));
123
123
  return tangent.sub(normal).normalize();
124
124
  }
125
+ /**
126
+ * Get projection of the vector to plane where n - normal to the plane.
127
+ * @static
128
+ * @param {Vec2} b - Vector to project.
129
+ * @param {Vec2} n - Plane normal.
130
+ * @param {Vec2} [def] - Default value for non existed result.
131
+ * @returns {Vec2} -
132
+ */
133
+ static proj_b_to_plane(b, n, def) {
134
+ let res = b.sub(n.scaleTo(n.dot(b) / n.dot(n)));
135
+ if (def && res.isZero()) {
136
+ return new Vec2(def.x, def.y);
137
+ }
138
+ return res;
139
+ }
125
140
  /**
126
141
  * Converts to 3d vector, third value is 0.0.
127
142
  * @public
@@ -302,10 +317,19 @@ export class Vec2 {
302
317
  }
303
318
  /**
304
319
  * Returns normalized vector.
320
+ * @deprecated
305
321
  * @public
306
322
  * @returns {Vec2}
307
323
  */
308
324
  normal() {
325
+ return this.getNormal();
326
+ }
327
+ /**
328
+ * Returns normalized vector.
329
+ * @public
330
+ * @returns {Vec2}
331
+ */
332
+ getNormal() {
309
333
  let res = new Vec2();
310
334
  res.copy(this);
311
335
  let length = 1.0 / res.length();
@@ -450,6 +474,14 @@ export class Vec2 {
450
474
  }
451
475
  return Vec2.add(this.scale(scale0), v2.scale(scale1));
452
476
  }
477
+ /**
478
+ * Returns true if vector's values are zero.
479
+ * @public
480
+ * @returns {boolean} -
481
+ */
482
+ isZero() {
483
+ return !(this.x || this.y);
484
+ }
453
485
  }
454
486
  /**
455
487
  * Vector 2d object creator.
@@ -319,6 +319,8 @@ class Renderer {
319
319
  });
320
320
  this.pickingFramebuffer.init();
321
321
  this.depthFramebuffer = new Framebuffer(this.handler, {
322
+ width: 640,
323
+ height: 480,
322
324
  targets: [{
323
325
  internalFormat: "RGBA",
324
326
  type: "UNSIGNED_BYTE",
@@ -430,7 +432,7 @@ class Renderer {
430
432
  this.blitFramebuffer && this.blitFramebuffer.setSize(c.width, c.height, true);
431
433
  this.toneMappingFramebuffer && this.toneMappingFramebuffer.setSize(c.width, c.height, true);
432
434
  this.screenDepthFramebuffer && this.screenDepthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
433
- this.depthFramebuffer && this.depthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
435
+ //this.depthFramebuffer && this.depthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
434
436
  if (this.handler.gl.type === "webgl") {
435
437
  this.screenTexture.screen = this.sceneFramebuffer.textures[0];
436
438
  this.screenTexture.picking = this.pickingFramebuffer.textures[0];
@@ -662,7 +664,7 @@ class Renderer {
662
664
  e.dispatch(e.draw, this);
663
665
  let frustums = this.activeCamera.frustums;
664
666
  let pointerEvent = e.pointerEvent();
665
- let mouseHold = e.mouseState.leftButtonDown || e.mouseState.rightButtonDown;
667
+ let mouseFree = !e.mouseState.leftButtonDown && !e.mouseState.rightButtonDown;
666
668
  // Rendering scene nodes and entityCollections
667
669
  let rn = this._renderNodesArr;
668
670
  let k = frustums.length;
@@ -683,7 +685,7 @@ class Renderer {
683
685
  }
684
686
  this._drawEntityCollections(0);
685
687
  e.dispatch(e.drawtransparent, this);
686
- if (pointerEvent && !mouseHold) {
688
+ if (pointerEvent && mouseFree) {
687
689
  this._drawPickingBuffer(0);
688
690
  }
689
691
  this._drawDepthBuffer(0);
@@ -698,7 +700,7 @@ class Renderer {
698
700
  while (k--) {
699
701
  this.activeCamera.setCurrentFrustum(k);
700
702
  this._drawEntityCollections(i);
701
- if (pointerEvent && !mouseHold) {
703
+ if (pointerEvent && mouseFree) {
702
704
  this._drawPickingBuffer(i);
703
705
  }
704
706
  this._drawDepthBuffer(i);
@@ -707,10 +709,12 @@ class Renderer {
707
709
  }
708
710
  sceneFramebuffer.deactivate();
709
711
  this.blitFramebuffer && sceneFramebuffer.blitTo(this.blitFramebuffer, 0);
710
- if (pointerEvent) {
712
+ if (pointerEvent && mouseFree) {
711
713
  this._readPickingBuffer();
712
714
  }
713
- this._readDepthBuffer();
715
+ if (mouseFree) {
716
+ this._readDepthBuffer();
717
+ }
714
718
  // Tone mapping followed by rendering on the screen
715
719
  this._fnScreenFrame();
716
720
  e.dispatch(e.postdraw, this);
@@ -111,6 +111,7 @@ export interface IMouseState extends IBaseInputState {
111
111
  wheelDelta: number;
112
112
  /** JavaScript mouse system event message. */
113
113
  sys: MouseEvent | null;
114
+ isTouchPad: boolean;
114
115
  }
115
116
  export interface ITouchState extends IBaseInputState {
116
117
  /** Touch has ended right now.*/
@@ -71,7 +71,8 @@ class RendererEvents extends Events {
71
71
  wheelDelta: 0,
72
72
  sys: null,
73
73
  pickingObject: null,
74
- renderer: renderer
74
+ renderer: renderer,
75
+ isTouchPad: false
75
76
  };
76
77
  this.touchState = {
77
78
  moving: false,
@@ -195,6 +196,7 @@ class RendererEvents extends Events {
195
196
  * @protected
196
197
  */
197
198
  onMouseWheel(event) {
199
+ this.mouseState.isTouchPad = event.isTouchPad || false;
198
200
  this.mouseState.sys = event;
199
201
  this.mouseState.wheelDelta = event.wheelDelta || 0;
200
202
  }
@@ -631,5 +631,9 @@ export declare class Planet extends RenderNode {
631
631
  getHeightDefault(lonLat: LonLat): Promise<number>;
632
632
  getHeightAboveELL(lonLat: LonLat): Promise<number>;
633
633
  onremove(): void;
634
+ /**
635
+ * @todo: refactor with events or something better
636
+ */
637
+ stopDragging(): void;
634
638
  }
635
639
  export {};
@@ -771,7 +771,7 @@ export class Planet extends RenderNode {
771
771
  this._renderedNodes = [];
772
772
  for (let i = 0, len = temp.length; i < len; i++) {
773
773
  let ri = temp[i];
774
- let ht = ri.segment.centerNormal.dot(cam._b);
774
+ let ht = ri.segment.centerNormal.dot(cam.getBackward());
775
775
  if (ri.segment.tileZoom === this.maxCurrZoom || ht < HORIZON_TANGENT) {
776
776
  this._renderedNodes.push(ri);
777
777
  let k = 0, inFrustum = ri.inFrustum;
@@ -1347,7 +1347,7 @@ export class Planet extends RenderNode {
1347
1347
  * @returns {Vec2} - Screen coordinates.
1348
1348
  */
1349
1349
  getPixelFromCartesian(coords) {
1350
- return this.renderer.activeCamera.project(coords);
1350
+ return this.renderer.activeCamera.project3v(coords);
1351
1351
  }
1352
1352
  /**
1353
1353
  * Project geodetic coordinates to screen space.
@@ -1358,7 +1358,7 @@ export class Planet extends RenderNode {
1358
1358
  getPixelFromLonLat(lonlat) {
1359
1359
  let coords = this.ellipsoid.lonLatToCartesian(lonlat);
1360
1360
  if (coords) {
1361
- return this.renderer.activeCamera.project(coords);
1361
+ return this.renderer.activeCamera.project3v(coords);
1362
1362
  }
1363
1363
  }
1364
1364
  /**
@@ -1551,6 +1551,27 @@ export class Planet extends RenderNode {
1551
1551
  this.quadTreeStrategy.destroyBranches();
1552
1552
  this._renderedNodes = [];
1553
1553
  }
1554
+ // function checkTerrainCollision(entity) {
1555
+ // let _tempTerrPoint = new Vec3();
1556
+ // let nodes = globus.planet._renderedNodes;
1557
+ // for (let j = 0; j < nodes.length; j++) {
1558
+ // let seg = nodes[j].segment;
1559
+ // if (seg && seg._extentLonLat.isInside(entity.getLonLat())) {
1560
+ // seg.getEntityTerrainPoint(entity, _tempTerrPoint);
1561
+ // entity.setCartesian3v(_tempTerrPoint);
1562
+ // break;
1563
+ // }
1564
+ // }
1565
+ // }
1566
+ /**
1567
+ * @todo: refactor with events or something better
1568
+ */
1569
+ stopDragging() {
1570
+ if (this.renderer && this.renderer.controls.EarthNavigation) {
1571
+ //@ts-ignore
1572
+ this.renderer.controls.EarthNavigation.stop();
1573
+ }
1574
+ }
1554
1575
  }
1555
1576
  const PLANET_EVENTS = [
1556
1577
  /**
@@ -175,25 +175,25 @@ class Segment {
175
175
  _v0.set(verts[ind_v0], verts[ind_v0 + 1], verts[ind_v0 + 2]);
176
176
  _v1.set(verts[ind_v0 + 3], verts[ind_v0 + 4], verts[ind_v0 + 5]);
177
177
  _v2.set(verts[ind_v2], verts[ind_v2 + 1], verts[ind_v2 + 2]);
178
- let d = _ray.hitTriangle(_v0, _v1, _v2, res);
178
+ let d = _ray.hitTriangleRes(_v0, _v1, _v2, res);
179
179
  if (d === Ray.INSIDE) {
180
180
  return xyz.distance(res);
181
181
  }
182
182
  else if (d === Ray.AWAY) {
183
183
  _rayEx.set(xyz, norm);
184
- let d = _rayEx.hitTriangle(_v0, _v1, _v2, res);
184
+ let d = _rayEx.hitTriangleRes(_v0, _v1, _v2, res);
185
185
  if (d === Ray.INSIDE) {
186
186
  return -xyz.distance(res);
187
187
  }
188
188
  }
189
189
  _v3.set(verts[ind_v2 + 3], verts[ind_v2 + 4], verts[ind_v2 + 5]);
190
- d = _ray.hitTriangle(_v1, _v3, _v2, res);
190
+ d = _ray.hitTriangleRes(_v1, _v3, _v2, res);
191
191
  if (d === Ray.INSIDE) {
192
192
  return xyz.distance(res);
193
193
  }
194
194
  else if (d === Ray.AWAY) {
195
195
  _rayEx.set(xyz, norm);
196
- let d = _rayEx.hitTriangle(_v1, _v3, _v2, res);
196
+ let d = _rayEx.hitTriangleRes(_v1, _v3, _v2, res);
197
197
  if (d === Ray.INSIDE) {
198
198
  return -xyz.distance(res);
199
199
  }
@@ -173,11 +173,11 @@ class GlobusTerrain extends EmptyTerrain {
173
173
  let v0 = new Vec3(tileData.extent.southWest.lon + size * j, h0, tileData.extent.northEast.lat - size * i - size), v1 = new Vec3(v0.x + size, h1, v0.z), v2 = new Vec3(v0.x, h2, v0.z + size), v3 = new Vec3(v0.x + size, h3, v0.z + size);
174
174
  let xyz = new Vec3(merc.lon, 100000.0, merc.lat), ray = new Ray(xyz, new Vec3(0, -1, 0));
175
175
  let res = new Vec3();
176
- let d = ray.hitTriangle(v0, v1, v2, res);
176
+ let d = ray.hitTriangleRes(v0, v1, v2, res);
177
177
  if (d === Ray.INSIDE) {
178
178
  return res.y;
179
179
  }
180
- d = ray.hitTriangle(v1, v3, v2, res);
180
+ d = ray.hitTriangleRes(v1, v3, v2, res);
181
181
  if (d === Ray.INSIDE) {
182
182
  return res.y;
183
183
  }