@openglobus/og 0.14.10 → 0.15.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 (140) hide show
  1. package/css/og.css +378 -275
  2. package/dist/@openglobus/og.css +1 -1
  3. package/dist/@openglobus/og.esm.js +2 -2
  4. package/dist/@openglobus/og.esm.js.map +1 -1
  5. package/dist/@openglobus/og.umd.js +2 -2
  6. package/dist/@openglobus/og.umd.js.map +1 -1
  7. package/package.json +18 -17
  8. package/src/og/Clock.js +218 -194
  9. package/src/og/Globe.js +5 -5
  10. package/src/og/Object3d.js +104 -145
  11. package/src/og/camera/Camera.js +31 -27
  12. package/src/og/camera/PlanetCamera.js +22 -14
  13. package/src/og/cons.js +107 -107
  14. package/src/og/control/Atmosphere.js +396 -0
  15. package/src/og/control/CompassButton.js +11 -18
  16. package/src/og/control/Control.js +197 -188
  17. package/src/og/control/GeoImageDragControl.js +84 -66
  18. package/src/og/control/LayerSwitcher.js +56 -138
  19. package/src/og/control/Lighting.js +314 -186
  20. package/src/og/control/MouseNavigation.js +2 -2
  21. package/src/og/control/RulerSwitcher.js +24 -19
  22. package/src/og/control/ScaleControl.js +30 -10
  23. package/src/og/control/SimpleSkyBackground.js +210 -0
  24. package/src/og/control/Sun.js +3 -1
  25. package/src/og/control/ZoomControl.js +30 -42
  26. package/src/og/control/index.js +6 -0
  27. package/src/og/control/ruler/RulerScene.js +5 -23
  28. package/src/og/control/selection/Selection.js +99 -0
  29. package/src/og/control/selection/SelectionScene.js +350 -0
  30. package/src/og/control/timeline/TimelineControl.js +99 -0
  31. package/src/og/control/timeline/TimelineModel.js +133 -0
  32. package/src/og/control/timeline/TimelineView.js +449 -0
  33. package/src/og/control/timeline/timelineUtils.js +132 -0
  34. package/src/og/ellipsoid/Ellipsoid.js +120 -93
  35. package/src/og/ellipsoid/wgs84.js +13 -13
  36. package/src/og/entity/Entity.js +36 -9
  37. package/src/og/entity/EntityCollection.js +0 -2
  38. package/src/og/entity/GeoObject.js +72 -56
  39. package/src/og/entity/GeoObjectHandler.js +487 -656
  40. package/src/og/entity/GeometryHandler.js +1341 -1337
  41. package/src/og/entity/Polyline.js +0 -16
  42. package/src/og/entity/Ray.js +0 -10
  43. package/src/og/entity/RayHandler.js +3 -44
  44. package/src/og/entity/Strip.js +1 -6
  45. package/src/og/index.js +13 -7
  46. package/src/og/input/input.js +3 -1
  47. package/src/og/layer/CanvasTiles.js +39 -34
  48. package/src/og/layer/Layer.js +69 -9
  49. package/src/og/layer/Material.js +1 -8
  50. package/src/og/layer/WMS.js +16 -5
  51. package/src/og/light/LightSource.js +2 -0
  52. package/src/og/math/Line3.js +140 -139
  53. package/src/og/math/Plane.js +118 -117
  54. package/src/og/math/Ray.js +242 -239
  55. package/src/og/math/Vec3.js +56 -37
  56. package/src/og/math/Vec4.js +3 -4
  57. package/src/og/math.js +21 -21
  58. package/src/og/quadTree/Node.js +5 -4
  59. package/src/og/quadTree/index.js +12 -0
  60. package/src/og/renderer/Renderer.js +64 -37
  61. package/src/og/renderer/RendererEvents.js +1071 -1065
  62. package/src/og/scene/Planet.js +354 -174
  63. package/src/og/scene/RenderNode.js +27 -12
  64. package/src/og/segment/Segment.js +0 -5
  65. package/src/og/shaders/atmos.js +332 -0
  66. package/src/og/shaders/drawnode.js +475 -109
  67. package/src/og/shaders/geoObject.js +96 -51
  68. package/src/og/shaders/polyline.js +212 -17
  69. package/src/og/shaders/ray.js +13 -6
  70. package/src/og/shaders/toneMapping.js +5 -5
  71. package/src/og/shaders/utils.js +88 -0
  72. package/src/og/terrain/GlobusTerrain.js +5 -4
  73. package/src/og/terrain/MapboxTerrain.js +231 -52
  74. package/src/og/ui/Button.js +106 -0
  75. package/src/og/ui/ButtonGroup.js +57 -0
  76. package/src/og/ui/Dialog.js +242 -0
  77. package/src/og/ui/Slider.js +144 -0
  78. package/src/og/ui/ToggleButton.js +51 -0
  79. package/src/og/{control → ui}/UIhelpers.js +11 -2
  80. package/src/og/ui/View.js +190 -0
  81. package/src/og/utils/shared.js +960 -942
  82. package/src/og/webgl/Framebuffer.js +308 -387
  83. package/src/og/webgl/Handler.js +90 -30
  84. package/src/og/webgl/Multisample.js +8 -0
  85. package/types/Clock.d.ts +7 -2
  86. package/types/Object3d.d.ts +14 -3
  87. package/types/camera/Camera.d.ts +18 -17
  88. package/types/camera/PlanetCamera.d.ts +3 -1
  89. package/types/control/Atmosphere.d.ts +15 -0
  90. package/types/control/CompassButton.d.ts +1 -2
  91. package/types/control/GeoImageDragControl.d.ts +7 -1
  92. package/types/control/LayerSwitcher.d.ts +5 -6
  93. package/types/control/Lighting.d.ts +32 -7
  94. package/types/control/ScaleControl.d.ts +2 -1
  95. package/types/control/SimpleSkyBackground.d.ts +15 -0
  96. package/types/control/ZoomControl.d.ts +0 -1
  97. package/types/control/index.d.ts +4 -1
  98. package/types/control/ruler/RulerScene.d.ts +0 -1
  99. package/types/control/selection/Selection.d.ts +49 -0
  100. package/types/control/selection/SelectionScene.d.ts +34 -0
  101. package/types/ellipsoid/Ellipsoid.d.ts +3 -2
  102. package/types/entity/Entity.d.ts +8 -0
  103. package/types/entity/GeoObject.d.ts +28 -22
  104. package/types/entity/GeoObjectHandler.d.ts +16 -56
  105. package/types/entity/Ray.d.ts +0 -3
  106. package/types/entity/RayHandler.d.ts +0 -4
  107. package/types/index.d.ts +9 -6
  108. package/types/input/input.d.ts +2 -0
  109. package/types/layer/CanvasTiles.d.ts +1 -0
  110. package/types/layer/Layer.d.ts +9 -0
  111. package/types/layer/WMS.d.ts +7 -3
  112. package/types/math/Plane.d.ts +1 -1
  113. package/types/math/Vec3.d.ts +19 -16
  114. package/types/math/Vec4.d.ts +2 -3
  115. package/types/math.d.ts +20 -20
  116. package/types/quadTree/index.d.ts +10 -0
  117. package/types/renderer/Renderer.d.ts +11 -37
  118. package/types/scene/Planet.d.ts +27 -1
  119. package/types/scene/RenderNode.d.ts +2 -1
  120. package/types/segment/Segment.d.ts +1 -1
  121. package/types/shaders/atmos.d.ts +4 -0
  122. package/types/shaders/drawnode.d.ts +3 -2
  123. package/types/shaders/utils.d.ts +1 -0
  124. package/types/terrain/GlobusTerrain.d.ts +1 -1
  125. package/types/terrain/MapboxTerrain.d.ts +2 -1
  126. package/types/ui/Button.d.ts +21 -0
  127. package/types/ui/Dialog.d.ts +41 -0
  128. package/types/ui/Slider.d.ts +30 -0
  129. package/types/ui/ToggleButton.d.ts +10 -0
  130. package/types/{control → ui}/UIhelpers.d.ts +1 -1
  131. package/types/ui/View.d.ts +32 -0
  132. package/types/utils/shared.d.ts +16 -14
  133. package/types/webgl/Framebuffer.d.ts +2 -5
  134. package/types/webgl/Handler.d.ts +15 -10
  135. package/types/webgl/Multisample.d.ts +2 -0
  136. package/src/og/ajax.js +0 -204
  137. package/src/og/entity/Object3d.js +0 -504
  138. package/src/og/utils/quadTreeType.js +0 -11
  139. package/types/ajax.d.ts +0 -24
  140. package/types/utils/quadTreeType.d.ts +0 -8
@@ -1,239 +1,242 @@
1
- /**
2
- * @module og/math/Ray
3
- */
4
-
5
- "use strict";
6
-
7
- import * as math from "../math.js";
8
- import { Vec3 } from "./Vec3.js";
9
-
10
- /**
11
- * Represents a ray that extends infinitely from the provided origin in the provided direction.
12
- * @class
13
- * @param {Vec3} origin - The origin of the ray.
14
- * @param {Vec3} direction - The direction of the ray.
15
- */
16
- export class Ray {
17
- constructor(origin = Vec3.ZERO, direction = Vec3.ZERO) {
18
- /**
19
- * The origin of the ray.
20
- * @public
21
- * @type {Vec3}
22
- */
23
- this.origin = origin || new Vec3();
24
-
25
- /**
26
- * The direction of the ray.
27
- * @public
28
- * @type {Vec3}
29
- */
30
- this.direction = direction || new Vec3();
31
- }
32
-
33
- /** @const */
34
- static get OUTSIDE() {
35
- return 0;
36
- }
37
-
38
- /** @const */
39
- static get INSIDE() {
40
- return 1;
41
- }
42
- /** @const */
43
- static get INPLANE() {
44
- return 2;
45
- }
46
- /** @const */
47
- static get AWAY() {
48
- return 3;
49
- }
50
-
51
- /**
52
- * Sets a ray parameters.
53
- * @public
54
- * @param {Vec3} origin - The origin of the ray.
55
- * @param {Vec3} direction - The direction of the ray.
56
- * @returns {Ray}
57
- */
58
- set(origin, direction) {
59
- this.origin = origin;
60
- this.direction = direction;
61
- return this;
62
- }
63
-
64
- /**
65
- * Computes the point along the ray on the distance.
66
- * @public
67
- * @param {number} distance - Point distance.
68
- * @returns {Vec3}
69
- */
70
- getPoint(distance) {
71
- return Vec3.add(this.origin, this.direction.scaleTo(distance));
72
- }
73
-
74
- /**
75
- * Returns ray hit a triange result.
76
- * @public
77
- * @param {Vec3} v0 - First triangle corner coordinate.
78
- * @param {Vec3} v1 - Second triangle corner coordinate.
79
- * @param {Vec3} v2 - Third triangle corner coordinate.
80
- * @param {Vec3} res - Hit point object pointer that stores hit result.
81
- * @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
82
- * 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
83
- */
84
- hitTriangle(v0, v1, v2, res) {
85
- var u = v1.sub(v0);
86
- var v = v2.sub(v0);
87
- var n = u.cross(v);
88
-
89
- var w0 = this.origin.sub(v0);
90
- var a = -n.dot(w0);
91
- var b = n.dot(this.direction);
92
-
93
- // ray is parallel to triangle plane
94
- if (Math.abs(b) < math.EPSILON10) {
95
- if (a === 0) {
96
- res.copy(this.origin);
97
- // ray lies in triangle plane
98
- return Ray.INPLANE;
99
- } else {
100
- // ray disjoint from plane
101
- return Ray.OUTSIDE;
102
- }
103
- }
104
-
105
- var r = a / b;
106
-
107
- // intersect point of ray and plane
108
- res.copy(this.origin.add(this.direction.scaleTo(r)));
109
-
110
- // ray goes away from triangle
111
- if (r < 0.0) {
112
- return Ray.AWAY;
113
- }
114
-
115
- // is res point inside the triangle?
116
- var uu = u.dot(u);
117
- var uv = u.dot(v);
118
- var vv = v.dot(v);
119
- var w = res.sub(v0);
120
- var wu = w.dot(u);
121
- var wv = w.dot(v);
122
- var D = uv * uv - uu * vv;
123
-
124
- var s = (uv * wv - vv * wu) / D;
125
- if (s < 0.0 || s > 1.0) {
126
- return Ray.OUTSIDE;
127
- }
128
-
129
- var t = (uv * wu - uu * wv) / D;
130
- if (t < 0.0 || s + t > 1.0) {
131
- return Ray.OUTSIDE;
132
- }
133
-
134
- return Ray.INSIDE;
135
- }
136
-
137
- /**
138
- * Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
139
- * @public
140
- * @param {Vec3} v0 - First plane point.
141
- * @param {Vec3} v1 - Second plane point.
142
- * @param {Vec3} v2 - Third plane point.
143
- * @param {Vec3} res - Hit point object pointer that stores hit result.
144
- * @returns {number}
145
- */
146
- hitPlane(v0, v1, v2, res) {
147
- var u = Vec3.sub(v1, v0);
148
- var v = Vec3.sub(v2, v0);
149
- var n = u.cross(v);
150
-
151
- var w0 = Vec3.sub(this.origin, v0);
152
- var a = -n.dot(w0);
153
- var b = n.dot(this.direction);
154
-
155
- // ray is parallel to the plane
156
- if (Math.abs(b) < math.EPSILON10) {
157
- if (a === 0) {
158
- return Ray.OUTSIDE;
159
- }
160
- }
161
-
162
- var r = a / b;
163
-
164
- if (r < 0) {
165
- return Ray.OUTSIDE;
166
- }
167
-
168
- var d = this.direction.scaleTo(r);
169
-
170
- // intersect point of ray and plane
171
- res.x = this.origin.x + d.x;
172
- res.y = this.origin.y + d.y;
173
- res.z = this.origin.z + d.z;
174
-
175
- return Ray.INSIDE;
176
- }
177
-
178
- /**
179
- * Returns a ray hit sphere coordiante. If there isn't hit returns null.
180
- * @public
181
- * @param {Sphere} sphere - Sphere object.
182
- * @returns {Vec3}
183
- */
184
- hitSphere(sphere) {
185
- var r = sphere.radius,
186
- c = sphere.center,
187
- o = this.origin,
188
- d = this.direction;
189
- var vpc = Vec3.sub(c, o);
190
- if (vpc.dot(d) < 0) {
191
- var l = vpc.length();
192
- if (l > r) {
193
- return null;
194
- } else if (l === r) {
195
- return o.clone();
196
- }
197
- let pc = c.projToRay(o, vpc);
198
- var lc = Vec3.sub(pc, c).length();
199
- let dist = Math.sqrt(r * r - lc * lc);
200
- let di1 = dist - Vec3.sub(pc, o).length();
201
- let intersection = Vec3.add(o, d.scaleTo(di1));
202
- return intersection;
203
- } else {
204
- let pc = c.projToRay(o, d);
205
- var cpcl = Vec3.sub(c, pc).length();
206
- if (cpcl > sphere.radius) {
207
- return null;
208
- } else {
209
- let dist = Math.sqrt(r * r - cpcl * cpcl);
210
- let di1;
211
- pc.subA(o);
212
- if (vpc.length() > r) {
213
- di1 = pc.length() - dist;
214
- } else {
215
- di1 = pc.length() + dist;
216
- }
217
- let intersection = Vec3.add(o, d.scaleTo(di1));
218
- return intersection;
219
- }
220
- }
221
- }
222
-
223
- hitBox(box) {
224
- //
225
- // TODO
226
- //
227
- }
228
- }
229
-
230
- /**
231
- * Ray object creator.
232
- * @function
233
- * @param {Vec3} origin - The origin of the ray.
234
- * @param {Vec3} direction - The direction of the ray.
235
- * @returns {Ray}
236
- */
237
- export function ray(origin, direction) {
238
- return new Ray(origin, direction);
239
- }
1
+ /**
2
+ * @module og/math/Ray
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as math from "../math.js";
8
+ import { EPS10 } from "../math.js";
9
+ import { Vec3 } from "./Vec3.js";
10
+
11
+ /**
12
+ * Represents a ray that extends infinitely from the provided origin in the provided direction.
13
+ * @class
14
+ * @param {Vec3} origin - The origin of the ray.
15
+ * @param {Vec3} direction - The direction of the ray.
16
+ */
17
+ export class Ray {
18
+ constructor(origin = Vec3.ZERO, direction = Vec3.ZERO) {
19
+ /**
20
+ * The origin of the ray.
21
+ * @public
22
+ * @type {Vec3}
23
+ */
24
+ this.origin = origin || new Vec3();
25
+
26
+ /**
27
+ * The direction of the ray.
28
+ * @public
29
+ * @type {Vec3}
30
+ */
31
+ this.direction = direction || new Vec3();
32
+ }
33
+
34
+ /** @const */
35
+ static get OUTSIDE() {
36
+ return 0;
37
+ }
38
+
39
+ /** @const */
40
+ static get INSIDE() {
41
+ return 1;
42
+ }
43
+
44
+ /** @const */
45
+ static get INPLANE() {
46
+ return 2;
47
+ }
48
+
49
+ /** @const */
50
+ static get AWAY() {
51
+ return 3;
52
+ }
53
+
54
+ /**
55
+ * Sets a ray parameters.
56
+ * @public
57
+ * @param {Vec3} origin - The origin of the ray.
58
+ * @param {Vec3} direction - The direction of the ray.
59
+ * @returns {Ray}
60
+ */
61
+ set(origin, direction) {
62
+ this.origin = origin;
63
+ this.direction = direction;
64
+ return this;
65
+ }
66
+
67
+ /**
68
+ * Computes the point along the ray on the distance.
69
+ * @public
70
+ * @param {number} distance - Point distance.
71
+ * @returns {Vec3}
72
+ */
73
+ getPoint(distance) {
74
+ return Vec3.add(this.origin, this.direction.scaleTo(distance));
75
+ }
76
+
77
+ /**
78
+ * Returns ray hit a triange result.
79
+ * @public
80
+ * @param {Vec3} v0 - First triangle corner coordinate.
81
+ * @param {Vec3} v1 - Second triangle corner coordinate.
82
+ * @param {Vec3} v2 - Third triangle corner coordinate.
83
+ * @param {Vec3} res - Hit point object pointer that stores hit result.
84
+ * @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
85
+ * 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
86
+ */
87
+ hitTriangle(v0, v1, v2, res) {
88
+ var u = v1.sub(v0);
89
+ var v = v2.sub(v0);
90
+ var n = u.cross(v);
91
+
92
+ var w0 = this.origin.sub(v0);
93
+ var a = -n.dot(w0);
94
+ var b = n.dot(this.direction);
95
+
96
+ // ray is parallel to triangle plane
97
+ if (Math.abs(b) < EPS10) {
98
+ if (a === 0) {
99
+ res.copy(this.origin);
100
+ // ray lies in triangle plane
101
+ return Ray.INPLANE;
102
+ } else {
103
+ // ray disjoint from plane
104
+ return Ray.OUTSIDE;
105
+ }
106
+ }
107
+
108
+ var r = a / b;
109
+
110
+ // intersect point of ray and plane
111
+ res.copy(this.origin.add(this.direction.scaleTo(r)));
112
+
113
+ // ray goes away from triangle
114
+ if (r < 0.0) {
115
+ return Ray.AWAY;
116
+ }
117
+
118
+ // is res point inside the triangle?
119
+ var uu = u.dot(u);
120
+ var uv = u.dot(v);
121
+ var vv = v.dot(v);
122
+ var w = res.sub(v0);
123
+ var wu = w.dot(u);
124
+ var wv = w.dot(v);
125
+ var D = uv * uv - uu * vv;
126
+
127
+ var s = (uv * wv - vv * wu) / D;
128
+ if (s < 0.0 || s > 1.0) {
129
+ return Ray.OUTSIDE;
130
+ }
131
+
132
+ var t = (uv * wu - uu * wv) / D;
133
+ if (t < 0.0 || s + t > 1.0) {
134
+ return Ray.OUTSIDE;
135
+ }
136
+
137
+ return Ray.INSIDE;
138
+ }
139
+
140
+ /**
141
+ * Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
142
+ * @public
143
+ * @param {Vec3} v0 - First plane point.
144
+ * @param {Vec3} v1 - Second plane point.
145
+ * @param {Vec3} v2 - Third plane point.
146
+ * @param {Vec3} res - Hit point object pointer that stores hit result.
147
+ * @returns {number}
148
+ */
149
+ hitPlane(v0, v1, v2, res) {
150
+ var u = Vec3.sub(v1, v0);
151
+ var v = Vec3.sub(v2, v0);
152
+ var n = u.cross(v);
153
+
154
+ var w0 = Vec3.sub(this.origin, v0);
155
+ var a = -n.dot(w0);
156
+ var b = n.dot(this.direction);
157
+
158
+ // ray is parallel to the plane
159
+ if (Math.abs(b) < EPS10) {
160
+ if (a === 0) {
161
+ return Ray.OUTSIDE;
162
+ }
163
+ }
164
+
165
+ var r = a / b;
166
+
167
+ if (r < 0) {
168
+ return Ray.OUTSIDE;
169
+ }
170
+
171
+ var d = this.direction.scaleTo(r);
172
+
173
+ // intersect point of ray and plane
174
+ res.x = this.origin.x + d.x;
175
+ res.y = this.origin.y + d.y;
176
+ res.z = this.origin.z + d.z;
177
+
178
+ return Ray.INSIDE;
179
+ }
180
+
181
+ /**
182
+ * Returns a ray hit sphere coordiante. If there isn't hit returns null.
183
+ * @public
184
+ * @param {Sphere} sphere - Sphere object.
185
+ * @returns {Vec3}
186
+ */
187
+ hitSphere(sphere) {
188
+ var r = sphere.radius,
189
+ c = sphere.center,
190
+ o = this.origin,
191
+ d = this.direction;
192
+ var vpc = Vec3.sub(c, o);
193
+ if (vpc.dot(d) < 0) {
194
+ var l = vpc.length();
195
+ if (l > r) {
196
+ return null;
197
+ } else if (l === r) {
198
+ return o.clone();
199
+ }
200
+ let pc = c.projToRay(o, vpc);
201
+ var lc = Vec3.sub(pc, c).length();
202
+ let dist = Math.sqrt(r * r - lc * lc);
203
+ let di1 = dist - Vec3.sub(pc, o).length();
204
+ let intersection = Vec3.add(o, d.scaleTo(di1));
205
+ return intersection;
206
+ } else {
207
+ let pc = c.projToRay(o, d);
208
+ var cpcl = Vec3.sub(c, pc).length();
209
+ if (cpcl > sphere.radius) {
210
+ return null;
211
+ } else {
212
+ let dist = Math.sqrt(r * r - cpcl * cpcl);
213
+ let di1;
214
+ pc.subA(o);
215
+ if (vpc.length() > r) {
216
+ di1 = pc.length() - dist;
217
+ } else {
218
+ di1 = pc.length() + dist;
219
+ }
220
+ let intersection = Vec3.add(o, d.scaleTo(di1));
221
+ return intersection;
222
+ }
223
+ }
224
+ }
225
+
226
+ hitBox(box) {
227
+ //
228
+ // TODO
229
+ //
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Ray object creator.
235
+ * @function
236
+ * @param {Vec3} origin - The origin of the ray.
237
+ * @param {Vec3} direction - The direction of the ray.
238
+ * @returns {Ray}
239
+ */
240
+ export function ray(origin, direction) {
241
+ return new Ray(origin, direction);
242
+ }