@openglobus/og 0.22.1 → 0.23.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 (168) hide show
  1. package/css/og.css +137 -1
  2. package/lib/@openglobus/js/Object3d.d.ts +20 -10
  3. package/lib/@openglobus/js/camera/Camera.d.ts +9 -0
  4. package/lib/@openglobus/js/camera/Frustum.d.ts +3 -0
  5. package/lib/@openglobus/js/control/CameraLock.d.ts +38 -0
  6. package/lib/@openglobus/js/control/SimpleNavigation.d.ts +27 -10
  7. package/lib/@openglobus/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  8. package/lib/@openglobus/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  9. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  10. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  11. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  12. package/lib/@openglobus/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  13. package/lib/@openglobus/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  14. package/lib/@openglobus/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  15. package/lib/@openglobus/js/control/geoObjectEditor/colors.d.ts +8 -0
  16. package/lib/@openglobus/js/control/index.d.ts +2 -0
  17. package/lib/@openglobus/js/entity/Entity.d.ts +278 -19
  18. package/lib/@openglobus/js/entity/EntityCollection.d.ts +8 -9
  19. package/lib/@openglobus/js/entity/GeoObject.d.ts +141 -36
  20. package/lib/@openglobus/js/entity/GeoObjectHandler.d.ts +39 -63
  21. package/lib/@openglobus/js/entity/InstanceData.d.ts +76 -0
  22. package/lib/@openglobus/js/entity/Polyline.d.ts +19 -6
  23. package/lib/@openglobus/js/entity/PolylineHandler.d.ts +7 -0
  24. package/lib/@openglobus/js/index.d.ts +2 -1
  25. package/lib/@openglobus/js/layer/Vector.d.ts +4 -0
  26. package/lib/@openglobus/js/light/LightSource.d.ts +1 -139
  27. package/lib/@openglobus/js/math/Quat.d.ts +46 -33
  28. package/lib/@openglobus/js/math/Ray.d.ts +10 -4
  29. package/lib/@openglobus/js/math/Vec3.d.ts +15 -0
  30. package/lib/@openglobus/js/math.d.ts +2 -2
  31. package/lib/@openglobus/js/quadTree/EntityCollectionNode.d.ts +2 -2
  32. package/lib/@openglobus/js/quadTree/Node.d.ts +1 -1
  33. package/lib/@openglobus/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  34. package/lib/@openglobus/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  35. package/lib/@openglobus/js/renderer/Renderer.d.ts +64 -44
  36. package/lib/@openglobus/js/renderer/RendererEvents.d.ts +1 -0
  37. package/lib/@openglobus/js/scene/Planet.d.ts +11 -7
  38. package/lib/@openglobus/js/scene/RenderNode.d.ts +10 -25
  39. package/lib/@openglobus/js/shaders/drawnode.d.ts +1 -0
  40. package/lib/@openglobus/js/shaders/geoObject.d.ts +1 -0
  41. package/lib/@openglobus/js/shaders/utils.d.ts +1 -1
  42. package/lib/@openglobus/js/ui/Checkbox.d.ts +31 -0
  43. package/lib/@openglobus/js/ui/Dialog.d.ts +3 -0
  44. package/lib/@openglobus/js/ui/Input.d.ts +32 -0
  45. package/lib/@openglobus/js/ui/View.d.ts +3 -1
  46. package/lib/@openglobus/js/utils/objParser.d.ts +44 -12
  47. package/lib/@openglobus/js/utils/shared.d.ts +22 -0
  48. package/lib/@openglobus/js/webgl/BaseFramebuffer.d.ts +0 -1
  49. package/lib/@openglobus/js/webgl/Framebuffer.d.ts +35 -8
  50. package/lib/@openglobus/js/webgl/Handler.d.ts +3 -0
  51. package/lib/@openglobus/og.css +1 -1
  52. package/lib/@openglobus/og.esm.js +1 -1
  53. package/lib/@openglobus/og.esm.js.map +1 -1
  54. package/lib/@openglobus/og.umd.js +1 -1
  55. package/lib/@openglobus/og.umd.js.map +1 -1
  56. package/lib/js/Globe.js +2 -1
  57. package/lib/js/Object3d.d.ts +20 -10
  58. package/lib/js/Object3d.js +124 -48
  59. package/lib/js/camera/Camera.d.ts +9 -0
  60. package/lib/js/camera/Camera.js +27 -1
  61. package/lib/js/camera/Frustum.d.ts +3 -0
  62. package/lib/js/camera/Frustum.js +7 -0
  63. package/lib/js/control/Atmosphere.js +10 -6
  64. package/lib/js/control/CameraLock.d.ts +38 -0
  65. package/lib/js/control/CameraLock.js +216 -0
  66. package/lib/js/control/Control.js +1 -1
  67. package/lib/js/control/DebugInfo.js +13 -3
  68. package/lib/js/control/KeyboardNavigation.js +1 -1
  69. package/lib/js/control/ScaleControl.js +9 -3
  70. package/lib/js/control/SimpleNavigation.d.ts +27 -10
  71. package/lib/js/control/SimpleNavigation.js +148 -49
  72. package/lib/js/control/Sun.js +1 -1
  73. package/lib/js/control/elevationProfile/ElevationProfileScene.js +4 -4
  74. package/lib/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  75. package/lib/js/control/geoObjectEditor/ArrowEntity.js +59 -0
  76. package/lib/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  77. package/lib/js/control/geoObjectEditor/AxisTrackEntity.js +93 -0
  78. package/lib/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  79. package/lib/js/control/geoObjectEditor/GeoObjectEditor.js +30 -0
  80. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  81. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.js +502 -0
  82. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  83. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.js +487 -43
  84. package/lib/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  85. package/lib/js/control/geoObjectEditor/MoveAxisEntity.js +106 -0
  86. package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  87. package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +34 -0
  88. package/lib/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  89. package/lib/js/control/geoObjectEditor/RotateEntity.js +105 -0
  90. package/lib/js/control/geoObjectEditor/colors.d.ts +8 -0
  91. package/lib/js/control/geoObjectEditor/colors.js +8 -0
  92. package/lib/js/control/index.d.ts +2 -0
  93. package/lib/js/control/index.js +2 -0
  94. package/lib/js/control/timeline/TimelineControl.js +2 -0
  95. package/lib/js/entity/Entity.d.ts +278 -19
  96. package/lib/js/entity/Entity.js +483 -63
  97. package/lib/js/entity/EntityCollection.d.ts +8 -9
  98. package/lib/js/entity/EntityCollection.js +48 -45
  99. package/lib/js/entity/GeoObject.d.ts +141 -36
  100. package/lib/js/entity/GeoObject.js +153 -90
  101. package/lib/js/entity/GeoObjectHandler.d.ts +39 -63
  102. package/lib/js/entity/GeoObjectHandler.js +198 -295
  103. package/lib/js/entity/InstanceData.d.ts +76 -0
  104. package/lib/js/entity/InstanceData.js +344 -0
  105. package/lib/js/entity/Polyline.d.ts +19 -6
  106. package/lib/js/entity/Polyline.js +76 -36
  107. package/lib/js/entity/PolylineHandler.d.ts +7 -0
  108. package/lib/js/entity/PolylineHandler.js +26 -1
  109. package/lib/js/index.d.ts +2 -1
  110. package/lib/js/index.js +2 -1
  111. package/lib/js/layer/Bing.js +2 -2
  112. package/lib/js/layer/Vector.d.ts +4 -0
  113. package/lib/js/layer/Vector.js +16 -0
  114. package/lib/js/light/LightSource.d.ts +1 -139
  115. package/lib/js/light/LightSource.js +21 -227
  116. package/lib/js/math/Quat.d.ts +46 -33
  117. package/lib/js/math/Quat.js +91 -90
  118. package/lib/js/math/Ray.d.ts +10 -4
  119. package/lib/js/math/Ray.js +20 -4
  120. package/lib/js/math/Vec3.d.ts +15 -0
  121. package/lib/js/math/Vec3.js +30 -1
  122. package/lib/js/math.d.ts +2 -2
  123. package/lib/js/math.js +3 -3
  124. package/lib/js/quadTree/EntityCollectionNode.d.ts +2 -2
  125. package/lib/js/quadTree/EntityCollectionNode.js +8 -8
  126. package/lib/js/quadTree/Node.d.ts +1 -1
  127. package/lib/js/quadTree/Node.js +2 -2
  128. package/lib/js/quadTree/QuadTreeStrategy.js +1 -1
  129. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  130. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.js +2 -2
  131. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  132. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.js +2 -2
  133. package/lib/js/renderer/Renderer.d.ts +64 -44
  134. package/lib/js/renderer/Renderer.js +264 -263
  135. package/lib/js/renderer/RendererEvents.d.ts +1 -0
  136. package/lib/js/renderer/RendererEvents.js +2 -1
  137. package/lib/js/scene/Planet.d.ts +11 -7
  138. package/lib/js/scene/Planet.js +109 -87
  139. package/lib/js/scene/RenderNode.d.ts +10 -25
  140. package/lib/js/scene/RenderNode.js +70 -58
  141. package/lib/js/shaders/depth.js +2 -5
  142. package/lib/js/shaders/drawnode.d.ts +1 -0
  143. package/lib/js/shaders/drawnode.js +51 -52
  144. package/lib/js/shaders/geoObject.d.ts +1 -0
  145. package/lib/js/shaders/geoObject.js +154 -91
  146. package/lib/js/shaders/polyline.js +68 -51
  147. package/lib/js/shaders/utils.d.ts +1 -1
  148. package/lib/js/shaders/utils.js +11 -0
  149. package/lib/js/ui/Checkbox.d.ts +31 -0
  150. package/lib/js/ui/Checkbox.js +110 -0
  151. package/lib/js/ui/Color.js +2 -1
  152. package/lib/js/ui/Dialog.d.ts +3 -0
  153. package/lib/js/ui/Dialog.js +20 -0
  154. package/lib/js/ui/Input.d.ts +32 -0
  155. package/lib/js/ui/Input.js +107 -0
  156. package/lib/js/ui/View.d.ts +3 -1
  157. package/lib/js/ui/View.js +6 -0
  158. package/lib/js/utils/objParser.d.ts +44 -12
  159. package/lib/js/utils/objParser.js +241 -149
  160. package/lib/js/utils/shared.d.ts +22 -0
  161. package/lib/js/utils/shared.js +34 -0
  162. package/lib/js/webgl/BaseFramebuffer.d.ts +0 -1
  163. package/lib/js/webgl/Framebuffer.d.ts +35 -8
  164. package/lib/js/webgl/Framebuffer.js +136 -29
  165. package/lib/js/webgl/Handler.d.ts +3 -0
  166. package/lib/js/webgl/Handler.js +11 -1
  167. package/lib/js/webgl/Program.js +0 -8
  168. package/package.json +4 -2
@@ -0,0 +1,216 @@
1
+ import { Control } from "./Control";
2
+ import { Quat } from "../math/Quat";
3
+ import { Vec3 } from "../math/Vec3";
4
+ import { createEvents } from "../Events";
5
+ import { input } from "../input/input";
6
+ import { RADIANS } from "../math";
7
+ const MIN_LOCK_DISTANCE = 0.001;
8
+ const MIN_VIEW_DISTANCE = 120.0;
9
+ let qOrientationRot = new Quat();
10
+ const t = 0.08;
11
+ const CameraLockEvents = ["lockview", "unlockview"];
12
+ export class CameraLock extends Control {
13
+ constructor(options = {}) {
14
+ super(options);
15
+ this._onLockViewDraw = () => {
16
+ if (this.renderer && this._lockEntity) {
17
+ if (this._isFromTheBack) {
18
+ // let cam = this.planet.camera;
19
+ // let vehPos = this._lockEntity.getCartesian(),
20
+ // vehDir = this._lockEntity.direction;
21
+ // let currPos = vehPos.sub(this._viewDir.scaleTo(this._lockDistance));
22
+ // let dh = new Vec3();
23
+ // let currPosProj = new Plane(vehPos, vehPos.normal()).getProjectionPoint(currPos, dh);
24
+ // let projViewDir = vehPos.sub(currPosProj);
25
+ // Quat.getRotationBetweenVectorsRes(projViewDir.normal(), vehDir, qOrientationRot);
26
+ // let rot = qOrientationRot.slerp(Quat.IDENTITY, 1.0 - t).normalize();
27
+ // let projViewDir_t = rot.mulVec3(projViewDir.normal());
28
+ // projViewDir = projViewDir_t.scale(projViewDir.length());
29
+ // let newPos = vehPos.add(dh).sub(projViewDir);
30
+ // this._viewDir = vehPos.sub(newPos).normalize();
31
+ // cam.set(newPos, vehPos, vehPos.normal());
32
+ // cam.update();
33
+ }
34
+ else {
35
+ this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(), this._lockDistance);
36
+ }
37
+ }
38
+ };
39
+ this._onMouseWheel = (e) => {
40
+ if (this.renderer && this._lockEntity) {
41
+ if (this._isFromTheBack) {
42
+ //...
43
+ }
44
+ else {
45
+ let d = this.renderer.activeCamera.eye.distance(this._lockEntity.getAbsoluteCartesian());
46
+ this._lockDistance -= 0.33 * d * Math.sign(e.wheelDelta);
47
+ if (this._lockDistance < MIN_LOCK_DISTANCE) {
48
+ this._lockDistance = MIN_LOCK_DISTANCE;
49
+ }
50
+ this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(), this._lockDistance);
51
+ }
52
+ }
53
+ };
54
+ this._onMouseMove = (ms) => {
55
+ if (this._lockEntity && this.renderer) {
56
+ if (ms.rightButtonDown || this.renderer.events.isKeyPressed(input.KEY_ALT)) {
57
+ let p = this._lockEntity.getAbsoluteCartesian(), cam = this.renderer.activeCamera, l = 0.5 / RADIANS;
58
+ if (l > 0.007)
59
+ l = 0.007;
60
+ if (this.planet) {
61
+ cam.rotateHorizontal(l * (ms.x - ms.prev_x), false, p, p.isZero() ? Vec3.UP : p.normal());
62
+ }
63
+ else {
64
+ cam.rotateHorizontal(l * (ms.x - ms.prev_x), false, p, Vec3.UP);
65
+ }
66
+ cam.rotateVertical(l * (ms.y - ms.prev_y), p);
67
+ this._viewDir = p.sub(cam.eye).normalize();
68
+ }
69
+ }
70
+ };
71
+ this.events = createEvents(CameraLockEvents);
72
+ this._name = "CameraLock";
73
+ this.planet = options.planet || null;
74
+ this._lockDistance = 0;
75
+ this._isFromTheBack = false;
76
+ this._lockEntity = null;
77
+ this._viewDir = new Vec3(0, 0, 0);
78
+ }
79
+ onactivate() {
80
+ if (this.renderer) {
81
+ }
82
+ }
83
+ ondeactivate() {
84
+ if (this.renderer) {
85
+ this.unlockView();
86
+ }
87
+ }
88
+ oninit() {
89
+ this.activate();
90
+ if (this.renderer) {
91
+ }
92
+ }
93
+ flyCartesian(cartesian, dist = MIN_VIEW_DISTANCE) {
94
+ if (cartesian.isZero() || !this.renderer) {
95
+ return;
96
+ }
97
+ this.unlockView();
98
+ if (this.planet) {
99
+ let cam = this.planet.camera;
100
+ if (this.isVisibleDistance(cartesian)) {
101
+ cam.flyDistance(cartesian, dist);
102
+ }
103
+ if (cam.eye.distance(cartesian) < 1000000.0) {
104
+ cam.flyDistance(cartesian, dist);
105
+ }
106
+ else {
107
+ cam.viewDistance(cartesian, dist);
108
+ }
109
+ }
110
+ else {
111
+ this.renderer.activeCamera.viewDistance(cartesian, dist);
112
+ }
113
+ }
114
+ lockView(entity, fromTheBack = false) {
115
+ if (!this.renderer)
116
+ return;
117
+ this._lockDistance = this._getDistance(entity, this._lockEntity);
118
+ this._isFromTheBack = fromTheBack;
119
+ this._deactivateLockViewEvents();
120
+ this._lockEntity = entity;
121
+ let cam = this.renderer.activeCamera;
122
+ if (this.planet) {
123
+ this.planet.camera.stopFlying();
124
+ }
125
+ cam.viewDistance(entity.getAbsoluteCartesian(), this._lockDistance);
126
+ this._deactivateNav();
127
+ this._activateLockViewEvents();
128
+ this._viewDir = entity.getAbsoluteCartesian().sub(cam.eye).normalize();
129
+ this.events.dispatch(this.events.lockview, this._lockEntity, fromTheBack);
130
+ }
131
+ _activateNav() {
132
+ if (this.renderer && this.renderer.controls.mouseNavigation) {
133
+ this.renderer.controls.mouseNavigation.activate();
134
+ }
135
+ if (this.renderer && this.renderer.controls.simpleNavigation) {
136
+ this.renderer.controls.simpleNavigation.activate();
137
+ }
138
+ }
139
+ _deactivateNav() {
140
+ if (this.renderer && this.renderer.controls.mouseNavigation) {
141
+ this.renderer.controls.mouseNavigation.deactivate();
142
+ this.renderer.controls.mouseNavigation.stopRotation();
143
+ }
144
+ if (this.renderer && this.renderer.controls.simpleNavigation) {
145
+ this.renderer.controls.simpleNavigation.deactivate();
146
+ }
147
+ }
148
+ unlockView() {
149
+ if (this._lockEntity) {
150
+ this._deactivateLockViewEvents();
151
+ this._activateNav();
152
+ this.events.dispatch(this.events.unlockview, this._lockEntity);
153
+ this._lockEntity = null;
154
+ }
155
+ }
156
+ _getCenterDist() {
157
+ if (this.renderer) {
158
+ return this.renderer.getDistanceFromPixel(this.renderer.handler.getCenter()) || 0;
159
+ }
160
+ return 0;
161
+ }
162
+ _getDistance(entity, prevEntity) {
163
+ if (this.renderer) {
164
+ let cartesian = entity.getAbsoluteCartesian();
165
+ let cam = this.renderer.activeCamera;
166
+ let dist = cam.eye.distance(cartesian);
167
+ if (prevEntity) {
168
+ dist = cam.eye.distance(prevEntity.getAbsoluteCartesian());
169
+ }
170
+ if (this.isVisibleDistance(cartesian)) {
171
+ return dist;
172
+ }
173
+ if (cam.eye.distance(cartesian) < 1000000.0) {
174
+ return this._getCenterDist();
175
+ }
176
+ else {
177
+ return MIN_VIEW_DISTANCE;
178
+ }
179
+ }
180
+ return 0;
181
+ }
182
+ isVisibleDistance(cart, C = 0.0) {
183
+ if (this.planet) {
184
+ let R = this.planet.ellipsoid.equatorialSize;
185
+ let eye = this.planet.camera.eye;
186
+ let camDist = eye.distance(cart);
187
+ return camDist < Math.sqrt(eye.length2() - R * R) + C;
188
+ }
189
+ return true;
190
+ }
191
+ get lockEntity() {
192
+ return this._lockEntity;
193
+ }
194
+ flyLonLat(lonLat, dist = MIN_VIEW_DISTANCE) {
195
+ if (this.planet) {
196
+ let cartesian = this.planet.ellipsoid.lonLatToCartesian(lonLat);
197
+ this.flyCartesian(cartesian, dist);
198
+ }
199
+ }
200
+ _activateLockViewEvents() {
201
+ if (this.renderer) {
202
+ this.renderer.events.on("mousewheel", this._onMouseWheel);
203
+ this.renderer.events.on("mousemove", this._onMouseMove);
204
+ this.renderer.events.on("draw", this._onLockViewDraw);
205
+ }
206
+ }
207
+ _deactivateLockViewEvents() {
208
+ if (this.renderer) {
209
+ this.renderer.events.off("mousewheel", this._onMouseWheel);
210
+ this.renderer.events.off("mousemove", this._onMouseMove);
211
+ if (this._lockEntity) {
212
+ this.renderer.events.off("draw", this._onLockViewDraw);
213
+ }
214
+ }
215
+ }
216
+ }
@@ -62,7 +62,7 @@ export class Control {
62
62
  this.renderer = renderer;
63
63
  renderer.controls[this.name] = this;
64
64
  this.onadd && this.onadd();
65
- if (renderer.isInitialized()) {
65
+ if (renderer.isInitialized() && !this._initialized) {
66
66
  this._initialized = true;
67
67
  this.oninit && this.oninit();
68
68
  if (this.autoActivate) {
@@ -186,10 +186,20 @@ export class DebugInfo extends Control {
186
186
  frame: () => p.getViewExtent().toString()
187
187
  },
188
188
  {
189
- label: "height/alt (km)",
190
- frame: () => `<div style="width:190px">${(p.camera._lonLat.height / 1000.0).toFixed(2) +
189
+ label: "Mouse distance, m",
190
+ frame: () => {
191
+ let cart = p.getCartesianFromMouseTerrain();
192
+ if (cart) {
193
+ return p.camera.eye.distance(cart).toFixed(3);
194
+ }
195
+ return "";
196
+ }
197
+ },
198
+ {
199
+ label: "height/alt, m",
200
+ frame: () => `<div style="width:190px">${(p.camera._lonLat.height).toFixed(2) +
191
201
  " / " +
192
- (p.camera.getAltitude() / 1000.0).toFixed(2)}</div>`
202
+ (p.camera.getAltitude()).toFixed(2)}</div>`
193
203
  },
194
204
  {
195
205
  label: "cam.slope",
@@ -9,7 +9,7 @@ export class KeyboardNavigation extends Control {
9
9
  constructor(options = {}) {
10
10
  options = options || {};
11
11
  super({ name: "KeyboardNavigation", ...options });
12
- this.step = options.step || 250;
12
+ this.step = options.step || 25000;
13
13
  }
14
14
  onactivate() {
15
15
  let r = this.renderer;
@@ -3,7 +3,7 @@ import { Control } from "./Control";
3
3
  import { RADIANS } from "../math";
4
4
  import { Vec3 } from "../math/Vec3";
5
5
  const scale = [
6
- 1, 2, 3, 5, 10, 20, 30, 50, 100, 200, 300, 500, 1e3, 2e3, 3e3, 5e3, 10e3, 20e3, 30e3, 50e3,
6
+ 0.001, 0.005, 0.01, 0.05, 0.1, 0.2, 0.5, 1, 2, 3, 5, 10, 20, 30, 50, 100, 200, 300, 500, 1e3, 2e3, 3e3, 5e3, 10e3, 20e3, 30e3, 50e3,
7
7
  100e3, 200e3, 300e3, 500e3, 1000e3, 2000e3, 3000e3, 5000e3, 10000e3
8
8
  ];
9
9
  const TEMPLATE = `<div class="og-scale-container">
@@ -79,12 +79,18 @@ export class ScaleControl extends Control {
79
79
  let minMeters = scale[index], maxMeters = scale[index + 1];
80
80
  let t = (minMeters - metersInMinSize) / (maxMeters - minMeters);
81
81
  this.currWidth = this._minWidth + t * (this._maxWidth - this._minWidth);
82
- if (minMeters > 1000) {
82
+ if (minMeters >= 1000) {
83
83
  this._scaleLabelEl.innerText = `${minMeters / 1000} km`;
84
84
  }
85
- else {
85
+ else if (minMeters >= 1) {
86
86
  this._scaleLabelEl.innerText = `${minMeters} m`;
87
87
  }
88
+ else if (minMeters >= 0.01) {
89
+ this._scaleLabelEl.innerText = `${minMeters * 100} cm`;
90
+ }
91
+ else {
92
+ this._scaleLabelEl.innerText = `${minMeters * 1000} mm`;
93
+ }
88
94
  this._metersInMinSize = metersInMinSize;
89
95
  this.el.style.width = this.currWidth + "px";
90
96
  }
@@ -1,4 +1,6 @@
1
1
  import { Control, IControlParams } from "./Control";
2
+ import { IMouseState } from "../renderer/RendererEvents";
3
+ import { Vec3 } from "../math/Vec3";
2
4
  interface ISimpleNavigationParams extends IControlParams {
3
5
  speed?: number;
4
6
  }
@@ -7,19 +9,34 @@ interface ISimpleNavigationParams extends IControlParams {
7
9
  */
8
10
  export declare class SimpleNavigation extends Control {
9
11
  speed: number;
12
+ force: Vec3;
13
+ vel: Vec3;
14
+ mass: number;
15
+ protected _lookPos: Vec3 | undefined;
16
+ protected _up: Vec3 | null;
17
+ protected _grabbedPoint: Vec3 | undefined;
18
+ protected _eye0: Vec3;
10
19
  constructor(options?: ISimpleNavigationParams);
11
20
  oninit(): void;
12
21
  onactivate(): void;
13
22
  ondeactivate(): void;
14
- protected onCameraMoveForward(): void;
15
- protected onCameraMoveBackward(): void;
16
- protected onCameraStrifeLeft(): void;
17
- protected onCameraStrifeRight(): void;
18
- protected onCameraLookUp(): void;
19
- protected onCameraLookDown(): void;
20
- protected onCameraTurnLeft(): void;
21
- protected onCameraTurnRight(): void;
22
- protected onCameraRollLeft(): void;
23
- protected onCameraRollRight(): void;
23
+ protected _onMouseLeftButtonClick: (e: IMouseState) => void;
24
+ protected _onMouseLeftButtonUp: (e: IMouseState) => void;
25
+ protected _onMouseLeftButtonDown: (e: IMouseState) => void;
26
+ protected _onRHold: (e: IMouseState) => void;
27
+ protected _onRDown: (e: IMouseState) => void;
28
+ protected _onMouseWheel: (e: IMouseState) => void;
29
+ protected onCameraMoveForward: () => void;
30
+ protected onCameraMoveBackward: () => void;
31
+ protected onCameraStrifeLeft: () => void;
32
+ protected onCameraStrifeRight: () => void;
33
+ protected onCameraLookUp: () => void;
34
+ protected onCameraLookDown: () => void;
35
+ protected onCameraTurnLeft: () => void;
36
+ protected onCameraTurnRight: () => void;
37
+ protected onCameraRollLeft: () => void;
38
+ protected onCameraRollRight: () => void;
39
+ protected get dt(): number;
40
+ protected onDraw(): void;
24
41
  }
25
42
  export {};
@@ -1,5 +1,8 @@
1
1
  import { Control } from "./Control";
2
2
  import { input } from "../input/input";
3
+ import { Vec3 } from "../math/Vec3";
4
+ import * as math from "../math";
5
+ import { Ray } from "../math/Ray";
3
6
  /**
4
7
  * Simple keyboard camera navigation with W,S,A,D and shift keys to fly around the scene.
5
8
  */
@@ -9,13 +12,134 @@ export class SimpleNavigation extends Control {
9
12
  name: "SimpleNavigation",
10
13
  autoActivate: true, ...options
11
14
  });
12
- this.speed = options.speed || 1.0;
15
+ this._onMouseLeftButtonClick = (e) => {
16
+ if (this._active && this.renderer) {
17
+ this.renderer.handler.canvas.classList.add("ogGrabbingPoiner");
18
+ this._grabbedPoint = this.renderer.getCartesianFromPixel(e);
19
+ if (this._grabbedPoint) {
20
+ this._eye0.copy(this.renderer.activeCamera.eye);
21
+ }
22
+ }
23
+ };
24
+ this._onMouseLeftButtonUp = (e) => {
25
+ this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner");
26
+ if (e.x === e.prev_x && e.y === e.prev_y) {
27
+ //this.force.set(0, 0, 0);
28
+ }
29
+ };
30
+ this._onMouseLeftButtonDown = (e) => {
31
+ if (this._active && this.renderer) {
32
+ if (!this._grabbedPoint) {
33
+ return;
34
+ }
35
+ if (e.moving) {
36
+ let cam = this.renderer.activeCamera;
37
+ let camSlope = Math.abs(cam.getForward().dot(Vec3.UP));
38
+ let p0 = this._grabbedPoint, p1, p2;
39
+ if (camSlope > 0.7) {
40
+ p1 = Vec3.add(p0, Vec3.LEFT);
41
+ p2 = Vec3.add(p0, cam.getRight());
42
+ }
43
+ else {
44
+ p1 = Vec3.add(p0, cam.getRight());
45
+ p2 = Vec3.add(p0, Vec3.UP);
46
+ }
47
+ let px = new Vec3();
48
+ if (new Ray(cam.eye, e.direction).hitPlane(p0, p1, p2, px) === Ray.INSIDE) {
49
+ cam.eye = this._eye0.addA(px.subA(p0).negate());
50
+ }
51
+ }
52
+ }
53
+ };
54
+ this._onRHold = (e) => {
55
+ if (this._lookPos && e.moving && this.renderer) {
56
+ const cam = this.renderer.activeCamera;
57
+ this.renderer.controlsBag.scaleRot = 1.0;
58
+ let l = (0.5 / cam.eye.distance(this._lookPos)) * math.RADIANS;
59
+ if (l > 0.007) {
60
+ l = 0.007;
61
+ }
62
+ else if (l < 0.003) {
63
+ l = 0.003;
64
+ }
65
+ cam.rotateHorizontal(l * (e.x - e.prev_x), false, this._lookPos, this._up);
66
+ cam.rotateVertical(l * (e.y - e.prev_y), this._lookPos);
67
+ }
68
+ };
69
+ this._onRDown = (e) => {
70
+ if (this.renderer) {
71
+ this._lookPos = this.renderer.getCartesianFromPixel(e.pos);
72
+ if (this._lookPos) {
73
+ this._up = Vec3.UP; //this.renderer.activeCamera.getUp();
74
+ }
75
+ }
76
+ };
77
+ this._onMouseWheel = (e) => {
78
+ if (this.renderer) {
79
+ let pos = this.renderer.getCartesianFromPixel(e), dist = 10;
80
+ if (pos) {
81
+ dist = this.renderer.activeCamera.eye.distance(pos);
82
+ }
83
+ this.force.addA(e.direction.scale(e.wheelDelta)).normalize().scale(dist);
84
+ }
85
+ };
86
+ this.onCameraMoveForward = () => {
87
+ this.force.addA(this.renderer.activeCamera.getForward()).normalize();
88
+ };
89
+ this.onCameraMoveBackward = () => {
90
+ this.force.addA(this.renderer.activeCamera.getBackward()).normalize();
91
+ };
92
+ this.onCameraStrifeLeft = () => {
93
+ this.force.addA(this.renderer.activeCamera.getLeft()).normalize();
94
+ };
95
+ this.onCameraStrifeRight = () => {
96
+ this.force.addA(this.renderer.activeCamera.getRight()).normalize();
97
+ };
98
+ this.onCameraLookUp = () => {
99
+ let cam = this.renderer.activeCamera;
100
+ cam.pitch(0.5);
101
+ cam.update();
102
+ };
103
+ this.onCameraLookDown = () => {
104
+ let cam = this.renderer.activeCamera;
105
+ cam.pitch(-0.5);
106
+ cam.update();
107
+ };
108
+ this.onCameraTurnLeft = () => {
109
+ let cam = this.renderer.activeCamera;
110
+ cam.yaw(0.5);
111
+ cam.update();
112
+ };
113
+ this.onCameraTurnRight = () => {
114
+ let cam = this.renderer.activeCamera;
115
+ cam.yaw(-0.5);
116
+ cam.update();
117
+ };
118
+ this.onCameraRollLeft = () => {
119
+ let cam = this.renderer.activeCamera;
120
+ cam.roll(-0.5);
121
+ cam.update();
122
+ };
123
+ this.onCameraRollRight = () => {
124
+ let cam = this.renderer.activeCamera;
125
+ cam.roll(0.5);
126
+ cam.update();
127
+ };
128
+ this.speed = options.speed || 1.0; // m/s
129
+ this.force = new Vec3();
130
+ this.vel = new Vec3();
131
+ this.mass = 1;
132
+ this._lookPos = undefined;
133
+ this._grabbedPoint = undefined;
134
+ this._up = null;
135
+ this._eye0 = new Vec3();
13
136
  }
14
137
  oninit() {
15
138
  }
16
139
  onactivate() {
17
140
  super.onactivate();
18
141
  let r = this.renderer;
142
+ r.events.on("mousewheel", this._onMouseWheel);
19
143
  r.events.on("keypress", input.KEY_W, this.onCameraMoveForward, this);
20
144
  r.events.on("keypress", input.KEY_S, this.onCameraMoveBackward, this);
21
145
  r.events.on("keypress", input.KEY_A, this.onCameraStrifeLeft, this);
@@ -26,10 +150,17 @@ export class SimpleNavigation extends Control {
26
150
  r.events.on("keypress", input.KEY_RIGHT, this.onCameraTurnRight, this);
27
151
  r.events.on("keypress", input.KEY_Q, this.onCameraRollLeft, this);
28
152
  r.events.on("keypress", input.KEY_E, this.onCameraRollRight, this);
153
+ r.events.on("rhold", this._onRHold, this);
154
+ r.events.on("rdown", this._onRDown, this);
155
+ r.events.on("lhold", this._onMouseLeftButtonDown);
156
+ r.events.on("ldown", this._onMouseLeftButtonClick);
157
+ r.events.on("lup", this._onMouseLeftButtonUp);
158
+ r.events.on("draw", this.onDraw, this, -1000);
29
159
  }
30
160
  ondeactivate() {
31
161
  super.ondeactivate();
32
162
  let r = this.renderer;
163
+ r.events.off("mousewheel", this._onMouseWheel);
33
164
  r.events.off("keypress", input.KEY_W, this.onCameraMoveForward);
34
165
  r.events.off("keypress", input.KEY_S, this.onCameraMoveBackward);
35
166
  r.events.off("keypress", input.KEY_A, this.onCameraStrifeLeft);
@@ -40,57 +171,25 @@ export class SimpleNavigation extends Control {
40
171
  r.events.off("keypress", input.KEY_RIGHT, this.onCameraTurnRight);
41
172
  r.events.off("keypress", input.KEY_Q, this.onCameraRollLeft);
42
173
  r.events.off("keypress", input.KEY_E, this.onCameraRollRight);
174
+ r.events.off("rhold", this._onRHold);
175
+ r.events.off("rdown", this._onRDown);
176
+ r.events.off("lhold", this._onMouseLeftButtonDown);
177
+ r.events.off("ldown", this._onMouseLeftButtonClick);
178
+ r.events.off("lup", this._onMouseLeftButtonUp);
179
+ r.events.off("draw", this.onDraw);
180
+ }
181
+ get dt() {
182
+ return 0.001 * this.renderer.handler.deltaTime;
43
183
  }
44
- onCameraMoveForward() {
45
- if (this._active) {
184
+ onDraw() {
185
+ if (this.renderer) {
186
+ let acc = this.force.scale(1.0 / this.mass);
187
+ this.vel.addA(acc);
188
+ this.vel.scale(0.96);
189
+ this.force.set(0, 0, 0);
46
190
  let cam = this.renderer.activeCamera;
47
- cam.slide(0, 0, -this.speed);
191
+ cam.eye = cam.eye.add(this.vel.scaleTo(this.dt));
48
192
  cam.update();
49
193
  }
50
194
  }
51
- onCameraMoveBackward() {
52
- let cam = this.renderer.activeCamera;
53
- cam.slide(0, 0, this.speed);
54
- cam.update();
55
- }
56
- onCameraStrifeLeft() {
57
- let cam = this.renderer.activeCamera;
58
- cam.slide(-this.speed, 0, 0);
59
- cam.update();
60
- }
61
- onCameraStrifeRight() {
62
- let cam = this.renderer.activeCamera;
63
- cam.slide(this.speed, 0, 0);
64
- cam.update();
65
- }
66
- onCameraLookUp() {
67
- let cam = this.renderer.activeCamera;
68
- cam.pitch(0.5);
69
- cam.update();
70
- }
71
- onCameraLookDown() {
72
- let cam = this.renderer.activeCamera;
73
- cam.pitch(-0.5);
74
- cam.update();
75
- }
76
- onCameraTurnLeft() {
77
- let cam = this.renderer.activeCamera;
78
- cam.yaw(0.5);
79
- cam.update();
80
- }
81
- onCameraTurnRight() {
82
- let cam = this.renderer.activeCamera;
83
- cam.yaw(-0.5);
84
- cam.update();
85
- }
86
- onCameraRollLeft() {
87
- let cam = this.renderer.activeCamera;
88
- cam.roll(-0.5);
89
- cam.update();
90
- }
91
- onCameraRollRight() {
92
- let cam = this.renderer.activeCamera;
93
- cam.roll(0.5);
94
- cam.update();
95
- }
96
195
  }
@@ -13,7 +13,7 @@ export class Sun extends Control {
13
13
  this.activationHeight = options.activationHeight || 12079000.0;
14
14
  this.offsetVertical = options.offsetVertical || -5000000;
15
15
  this.offsetHorizontal = options.offsetHorizontal || 5000000;
16
- this.sunlight = new LightSource("Sun", {
16
+ this.sunlight = new LightSource({
17
17
  ambient: new Vec3(0.15, 0.15, 0.25),
18
18
  diffuse: new Vec3(0.9, 0.9, 0.8),
19
19
  specular: new Vec3(0.1, 0.1, 0.06),
@@ -379,7 +379,7 @@ class ElevationProfileScene extends RenderNode {
379
379
  groundEntity.setCartesian3v(groundPos);
380
380
  heightLabelEntity.setCartesian3v(headPos);
381
381
  heightLabelEntity.label.setText(`${hEll.toFixed(1)} m`);
382
- heightLabelEntity.childrenNodes[0].label.setText(`${altitude.toFixed(1)} m`);
382
+ heightLabelEntity.childEntities[0].label.setText(`${altitude.toFixed(1)} m`);
383
383
  headEntity.properties.altitude = altitude;
384
384
  headEntity.setCartesian3v(headPos);
385
385
  headEntity.properties.columnEntity.ray.setStartPosition3v(groundPos);
@@ -419,7 +419,7 @@ class ElevationProfileScene extends RenderNode {
419
419
  let headPos = groundPos.add(groundNormal.scale(altitude));
420
420
  heightLabelEntity.setCartesian3v(headPos);
421
421
  heightLabelEntity.label.setText(`${hEll.toFixed(1)} m`);
422
- heightLabelEntity.childrenNodes[0].label.setText(`${altitude.toFixed(1)} m`);
422
+ heightLabelEntity.childEntities[0].label.setText(`${altitude.toFixed(1)} m`);
423
423
  headEntity.setCartesian3v(headPos);
424
424
  headEntity.properties.columnEntity.ray.setEndPosition3v(headPos);
425
425
  this._trackEntity.polyline?.setPoint3v(headPos, headEntity.properties.index);
@@ -444,7 +444,7 @@ class ElevationProfileScene extends RenderNode {
444
444
  headEntity.setCartesian3v(headPos);
445
445
  headEntity.properties.columnEntity.ray.setEndPosition3v(headPos);
446
446
  headEntity.properties.heightLabelEntity.setCartesian3v(headPos);
447
- headEntity.properties.heightLabelEntity.childrenNodes[0].label.setText(`${altitude.toFixed(1)} m`);
447
+ headEntity.properties.heightLabelEntity.childEntities[0].label.setText(`${altitude.toFixed(1)} m`);
448
448
  this._trackEntity.polyline.setPoint3v(headPos, entityIndex);
449
449
  this.events.dispatch(this.events.change, this._pickedHeadEntity);
450
450
  }
@@ -468,7 +468,7 @@ class ElevationProfileScene extends RenderNode {
468
468
  this._trackEntity.polyline?.setPoint3v(headPos, headEntity.properties.index);
469
469
  heightLabelEntity.setCartesian3v(headPos);
470
470
  heightLabelEntity.label.setText(`${lonLat.height.toFixed(1)} m`);
471
- heightLabelEntity.childrenNodes[0].label.setText(`${altitude.toFixed(1)} m`);
471
+ heightLabelEntity.childEntities[0].label.setText(`${altitude.toFixed(1)} m`);
472
472
  this.events.dispatch(this.events.change, groundEntity.properties.headEntity);
473
473
  }
474
474
  }
@@ -0,0 +1,15 @@
1
+ import { Entity, IEntityParams } from "../../entity/Entity";
2
+ export interface IArrowEntityParams extends IEntityParams {
3
+ yaw?: number;
4
+ pitch?: number;
5
+ roll?: number;
6
+ size?: number;
7
+ color?: string;
8
+ properties?: any;
9
+ }
10
+ export declare class ArrowEntity extends Entity {
11
+ protected _size: number;
12
+ constructor(params?: IArrowEntityParams);
13
+ setSize(size: number): void;
14
+ setColorHTML(color: string): void;
15
+ }