@openglobus/og 0.22.2 → 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 (167) 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 +63 -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 +1 -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/Object3d.d.ts +20 -10
  57. package/lib/js/Object3d.js +124 -48
  58. package/lib/js/camera/Camera.d.ts +9 -0
  59. package/lib/js/camera/Camera.js +27 -1
  60. package/lib/js/camera/Frustum.d.ts +3 -0
  61. package/lib/js/camera/Frustum.js +7 -0
  62. package/lib/js/control/Atmosphere.js +10 -6
  63. package/lib/js/control/CameraLock.d.ts +38 -0
  64. package/lib/js/control/CameraLock.js +216 -0
  65. package/lib/js/control/Control.js +1 -1
  66. package/lib/js/control/DebugInfo.js +13 -3
  67. package/lib/js/control/KeyboardNavigation.js +1 -1
  68. package/lib/js/control/ScaleControl.js +9 -3
  69. package/lib/js/control/SimpleNavigation.d.ts +27 -10
  70. package/lib/js/control/SimpleNavigation.js +148 -49
  71. package/lib/js/control/Sun.js +1 -1
  72. package/lib/js/control/elevationProfile/ElevationProfileScene.js +4 -4
  73. package/lib/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  74. package/lib/js/control/geoObjectEditor/ArrowEntity.js +59 -0
  75. package/lib/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  76. package/lib/js/control/geoObjectEditor/AxisTrackEntity.js +93 -0
  77. package/lib/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  78. package/lib/js/control/geoObjectEditor/GeoObjectEditor.js +30 -0
  79. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  80. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.js +502 -0
  81. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  82. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.js +487 -43
  83. package/lib/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  84. package/lib/js/control/geoObjectEditor/MoveAxisEntity.js +106 -0
  85. package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  86. package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +34 -0
  87. package/lib/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  88. package/lib/js/control/geoObjectEditor/RotateEntity.js +105 -0
  89. package/lib/js/control/geoObjectEditor/colors.d.ts +8 -0
  90. package/lib/js/control/geoObjectEditor/colors.js +8 -0
  91. package/lib/js/control/index.d.ts +2 -0
  92. package/lib/js/control/index.js +2 -0
  93. package/lib/js/control/timeline/TimelineControl.js +2 -0
  94. package/lib/js/entity/Entity.d.ts +278 -19
  95. package/lib/js/entity/Entity.js +483 -63
  96. package/lib/js/entity/EntityCollection.d.ts +8 -9
  97. package/lib/js/entity/EntityCollection.js +48 -45
  98. package/lib/js/entity/GeoObject.d.ts +141 -36
  99. package/lib/js/entity/GeoObject.js +153 -90
  100. package/lib/js/entity/GeoObjectHandler.d.ts +39 -63
  101. package/lib/js/entity/GeoObjectHandler.js +198 -295
  102. package/lib/js/entity/InstanceData.d.ts +76 -0
  103. package/lib/js/entity/InstanceData.js +344 -0
  104. package/lib/js/entity/Polyline.d.ts +19 -6
  105. package/lib/js/entity/Polyline.js +76 -36
  106. package/lib/js/entity/PolylineHandler.d.ts +7 -0
  107. package/lib/js/entity/PolylineHandler.js +26 -1
  108. package/lib/js/index.d.ts +2 -1
  109. package/lib/js/index.js +2 -1
  110. package/lib/js/layer/Bing.js +2 -2
  111. package/lib/js/layer/Vector.d.ts +4 -0
  112. package/lib/js/layer/Vector.js +16 -0
  113. package/lib/js/light/LightSource.d.ts +1 -139
  114. package/lib/js/light/LightSource.js +21 -227
  115. package/lib/js/math/Quat.d.ts +46 -33
  116. package/lib/js/math/Quat.js +91 -90
  117. package/lib/js/math/Ray.d.ts +10 -4
  118. package/lib/js/math/Ray.js +20 -4
  119. package/lib/js/math/Vec3.d.ts +15 -0
  120. package/lib/js/math/Vec3.js +30 -1
  121. package/lib/js/math.d.ts +2 -2
  122. package/lib/js/math.js +3 -3
  123. package/lib/js/quadTree/EntityCollectionNode.d.ts +2 -2
  124. package/lib/js/quadTree/EntityCollectionNode.js +8 -8
  125. package/lib/js/quadTree/Node.d.ts +1 -1
  126. package/lib/js/quadTree/Node.js +2 -2
  127. package/lib/js/quadTree/QuadTreeStrategy.js +1 -1
  128. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  129. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.js +2 -2
  130. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  131. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.js +2 -2
  132. package/lib/js/renderer/Renderer.d.ts +63 -44
  133. package/lib/js/renderer/Renderer.js +260 -263
  134. package/lib/js/renderer/RendererEvents.d.ts +1 -0
  135. package/lib/js/renderer/RendererEvents.js +2 -1
  136. package/lib/js/scene/Planet.d.ts +11 -7
  137. package/lib/js/scene/Planet.js +109 -87
  138. package/lib/js/scene/RenderNode.d.ts +10 -25
  139. package/lib/js/scene/RenderNode.js +70 -58
  140. package/lib/js/shaders/depth.js +2 -5
  141. package/lib/js/shaders/drawnode.d.ts +1 -0
  142. package/lib/js/shaders/drawnode.js +51 -52
  143. package/lib/js/shaders/geoObject.d.ts +1 -0
  144. package/lib/js/shaders/geoObject.js +154 -91
  145. package/lib/js/shaders/polyline.js +68 -51
  146. package/lib/js/shaders/utils.d.ts +1 -1
  147. package/lib/js/shaders/utils.js +11 -0
  148. package/lib/js/ui/Checkbox.d.ts +31 -0
  149. package/lib/js/ui/Checkbox.js +110 -0
  150. package/lib/js/ui/Color.js +2 -1
  151. package/lib/js/ui/Dialog.d.ts +3 -0
  152. package/lib/js/ui/Dialog.js +20 -0
  153. package/lib/js/ui/Input.d.ts +32 -0
  154. package/lib/js/ui/Input.js +107 -0
  155. package/lib/js/ui/View.d.ts +3 -1
  156. package/lib/js/ui/View.js +6 -0
  157. package/lib/js/utils/objParser.d.ts +44 -12
  158. package/lib/js/utils/objParser.js +241 -149
  159. package/lib/js/utils/shared.d.ts +22 -0
  160. package/lib/js/utils/shared.js +34 -0
  161. package/lib/js/webgl/BaseFramebuffer.d.ts +0 -1
  162. package/lib/js/webgl/Framebuffer.d.ts +35 -8
  163. package/lib/js/webgl/Framebuffer.js +136 -29
  164. package/lib/js/webgl/Handler.d.ts +1 -0
  165. package/lib/js/webgl/Handler.js +11 -1
  166. package/lib/js/webgl/Program.js +0 -8
  167. package/package.json +4 -2
@@ -11,24 +11,35 @@ import { PointCloud } from "./PointCloud";
11
11
  import { Polyline } from "./Polyline";
12
12
  import { Ray } from "./Ray";
13
13
  import { Strip } from "./Strip";
14
+ import { Quat } from "../math/Quat";
15
+ import { RADIANS, clamp, DEGREES } from "../math";
14
16
  /**
15
17
  * Entity instances aggregate multiple forms of visualization into a single high-level object.
16
18
  * They can be created manually and added to entity collection.
17
19
  *
18
20
  * @class
19
- * @param {Object} [options] - Entity options:
20
- * @param {string} [options.name] - A human-readable name to display to users. It does not have to be unique.
21
- * @param {Vec3|Array.<number>} [options.cartesian] - Spatial entities like billboard, label etc. cartesian position.
22
- * @param {LonLat} [options.lonlat] - Geodetic coordinates for an entities like billboard, label etc.
23
- * @param {boolean} [options.aground] - True for entities that have to be placed on the relief.
24
- * @param {boolean} [options.visibility] - Entity visibility.
25
- * @param {*} [options.billboard] - Billboard options(see {@link Billboard}).
26
- * @param {*} [options.label] - Label options(see {@link Label}).
27
- * @param {*} [options.polyline] - Polyline options(see {@link Polyline}).
28
- * @param {*} [options.ray] - Ray options(see {@link Ray}).
29
- * @param {*} [options.pointCloud] - Point cloud options(see {@link PointCloud}).
30
- * @param {*} [options.geometry] - Geometry options (see {@link Geometry}), available for vector layer only.
31
- * @param {*} [options.properties] - Entity custom properties.
21
+ * @param {IEntityParams} [options] - Entity options:
22
+ * @param {string} [options.name] - Name of the entity.
23
+ * @param {any} [options.properties] - Additional properties of the entity.
24
+ * @param {Vec3 | NumberArray3} [options.cartesian] - Cartesian position.
25
+ * @param {LonLat | NumberArray3 | NumberArray2} [options.lonlat] - Geographic coordinates.
26
+ * @param {number} [options.altitude] - Altitude.
27
+ * @param {boolean} [options.visibility] - Visibility flag.
28
+ * @param {Billboard | IBillboardParams} [options.billboard] - Billboard object or parameters.
29
+ * @param {Label | ILabelParams} [options.label] - Label object or parameters.
30
+ * @param {Polyline | IPolylineParams} [options.polyline] - Polyline object or parameters.
31
+ * @param {Ray | IRayParams} [options.ray] - Ray object or parameters.
32
+ * @param {PointCloud | IPointCloudParams} [options.pointCloud] - Point cloud object or parameters.
33
+ * @param {Geometry | IGeometryParams} [options.geometry] - Geometry object or parameters.
34
+ * @param {GeoObject | IGeoObjectParams} [options.geoObject] - Geo object or parameters.
35
+ * @param {Strip | IStripParams} [options.strip] - Strip object or parameters.
36
+ * @param {boolean} [options.independentPicking] - Independent picking flag.
37
+ * @param {boolean} [options.relativePosition] - Parent relative position flag, otherwise position is absolute.
38
+ * @param {number} [options.pitch] - Rotation around local X-axis.
39
+ * @param {number} [options.yaw] - Rotation around local Y-axis.
40
+ * @param {number} [options.roll] - Rotation around local Z-axis.
41
+ * @param {number | Vec3 | NumberArray3} [options.scale] - Scaling factor.
42
+ * @param {boolean} [options.forceGlobalPosition] - Forces global position for children entities make them the same position as the parent.
32
43
  */
33
44
  class Entity {
34
45
  constructor(options = {}) {
@@ -36,9 +47,13 @@ class Entity {
36
47
  this.__id = Entity.__counter__++;
37
48
  this.properties = options.properties || {};
38
49
  this.properties.name = this.properties.name != undefined ? this.properties.name : "";
39
- this.childrenNodes = [];
50
+ this.childEntities = [];
40
51
  this.parent = null;
52
+ this.forceGlobalPosition = options.forceGlobalPosition || false;
41
53
  this._cartesian = utils.createVector3(options.cartesian);
54
+ this._rootCartesian = new Vec3();
55
+ this._localPosition = utils.createVector3(options.localPosition);
56
+ this._absoluteLocalPosition = new Vec3();
42
57
  this._lonLat = utils.createLonLat(options.lonlat);
43
58
  this._lonLatMerc = new LonLat();
44
59
  this._altitude = options.altitude || 0.0;
@@ -49,6 +64,17 @@ class Entity {
49
64
  this._layerIndex = -1;
50
65
  this._pickingColor = new Vec3(0, 0, 0);
51
66
  this._independentPicking = options.independentPicking || false;
67
+ this._relativePosition = options.relativePosition || false;
68
+ this._pitch = options.pitch || 0;
69
+ this._yaw = options.yaw || 0;
70
+ this._roll = options.roll || 0;
71
+ this._pitchRad = this._pitch * RADIANS;
72
+ this._yawRad = this._yaw * RADIANS;
73
+ this._rollRad = this._roll * RADIANS;
74
+ this._scale = utils.createVector3(options.scale, new Vec3(1, 1, 1));
75
+ this._qFrame = Quat.IDENTITY;
76
+ this._qRot = Quat.IDENTITY;
77
+ this._absoluteQRot = Quat.IDENTITY;
52
78
  this._featureConstructorArray = {
53
79
  billboard: [Billboard, this.setBillboard],
54
80
  label: [Label, this.setLabel],
@@ -68,15 +94,90 @@ class Entity {
68
94
  this.geoObject = this._createOptionFeature("geoObject", options.geoObject);
69
95
  this.strip = this._createOptionFeature("strip", options.strip);
70
96
  }
97
+ /**
98
+ * Returns root entity object.
99
+ * @public
100
+ * @return {Entity}
101
+ */
102
+ get rootEntity() {
103
+ let pn = this;
104
+ while (pn) {
105
+ if (!pn.parent) {
106
+ return pn;
107
+ }
108
+ pn = pn.parent;
109
+ }
110
+ return this;
111
+ }
112
+ /**
113
+ * Sets relative position property
114
+ * @param isRelative
115
+ */
116
+ set relativePosition(isRelative) {
117
+ if (isRelative !== this._relativePosition) {
118
+ let cart = this.getAbsoluteCartesian(), pitch = this.getAbsolutePitch(), yaw = this.getAbsoluteYaw(), roll = this.getAbsoluteRoll();
119
+ this._relativePosition = isRelative;
120
+ // probably need to take root this.rootEntity
121
+ if (this.parent) {
122
+ this._rootCartesian.copy(this.parent._rootCartesian);
123
+ }
124
+ if (!isRelative) {
125
+ this.setCartesian3v(cart);
126
+ this.setPitch(pitch);
127
+ this.setYaw(yaw);
128
+ this.setRoll(roll);
129
+ }
130
+ else if (this.parent) {
131
+ this.setAbsoluteCartesian3v(cart);
132
+ this.setAbsolutePitch(pitch);
133
+ this.setAbsoluteYaw(yaw);
134
+ this.setAbsoluteRoll(roll);
135
+ }
136
+ }
137
+ }
138
+ /**
139
+ * Gets relative position property
140
+ * @public
141
+ * @returns{boolean}
142
+ */
143
+ get relativePosition() {
144
+ return this._relativePosition;
145
+ }
146
+ /**
147
+ * Gets current entity collection container.
148
+ * @public
149
+ * @returns {EntityCollection | null}
150
+ */
151
+ get entityCollection() {
152
+ return this._entityCollection;
153
+ }
154
+ /**
155
+ * Gets entity uniq id
156
+ * @public
157
+ * @returns {number}
158
+ */
71
159
  get id() {
72
160
  return this.__id;
73
161
  }
162
+ /**
163
+ * Checks if the given entity is equal to the current entity.
164
+ * @param {Entity} entity - The entity to compare.
165
+ * @returns {boolean} True if entities are equal, otherwise false.
166
+ */
74
167
  isEqual(entity) {
75
168
  return this.__id === entity.__id;
76
169
  }
170
+ /**
171
+ * Gets the layer index of the entity.
172
+ * @returns {number} The layer index.
173
+ */
77
174
  get layerIndex() {
78
175
  return this._layerIndex;
79
176
  }
177
+ /**
178
+ * Gets the instance class name of the entity.
179
+ * @returns {string} The instance name "Entity".
180
+ */
80
181
  get instanceName() {
81
182
  return "Entity";
82
183
  }
@@ -87,6 +188,10 @@ class Entity {
87
188
  }
88
189
  return null;
89
190
  }
191
+ /**
192
+ * Gets the collection index of the entity.
193
+ * @returns {number} The entity collection index.
194
+ */
90
195
  getCollectionIndex() {
91
196
  return this._entityCollectionIndex;
92
197
  }
@@ -94,7 +199,7 @@ class Entity {
94
199
  * Adds current entity into the specified entity collection.
95
200
  * @public
96
201
  * @param {EntityCollection | Vector} collection - Specified entity collection or vector layer.
97
- * @param {Boolean} [rightNow=false] - Entity insertion option for vector layer.
202
+ * @param {boolean} [rightNow=false] - Entity insertion option for vector layer.
98
203
  * @returns {Entity} - This object.
99
204
  */
100
205
  addTo(collection, rightNow = false) {
@@ -102,7 +207,7 @@ class Entity {
102
207
  return this;
103
208
  }
104
209
  /**
105
- * Removes current entity from collection and layer.
210
+ * Removes current entity from its collection or layer.
106
211
  * @public
107
212
  */
108
213
  remove() {
@@ -128,8 +233,8 @@ class Entity {
128
233
  this.ray && this.ray.setVisibility(visibility);
129
234
  // geometry
130
235
  this.geometry && this.geometry.setVisibility(visibility);
131
- for (let i = 0; i < this.childrenNodes.length; i++) {
132
- this.childrenNodes[i].setVisibility(visibility);
236
+ for (let i = 0; i < this.childEntities.length; i++) {
237
+ this.childEntities[i].setVisibility(visibility);
133
238
  }
134
239
  }
135
240
  /**
@@ -148,6 +253,278 @@ class Entity {
148
253
  setCartesian3v(cartesian) {
149
254
  this.setCartesian(cartesian.x, cartesian.y, cartesian.z);
150
255
  }
256
+ /**
257
+ * Gets scale factor
258
+ * @public
259
+ * @returns {Vec3}
260
+ */
261
+ getScale() {
262
+ return this._scale;
263
+ }
264
+ /**
265
+ * Sets XYZ axis scale for the inner object such as GeoObject
266
+ * @public
267
+ * @param {Vec3} scale - Scale factor
268
+ */
269
+ setScale3v(scale) {
270
+ this._scale.copy(scale);
271
+ this.geoObject && this.geoObject.setScale3v(this._scale);
272
+ for (let i = 0; i < this.childEntities.length; i++) {
273
+ this.childEntities[i].setScale3v(this.childEntities[i].getScale());
274
+ }
275
+ }
276
+ /**
277
+ * Sets scale for the inner object such as GeoObject
278
+ * @public
279
+ * @param {number} val - Scale factor
280
+ */
281
+ setScale(val) {
282
+ this._scale.set(val, val, val);
283
+ this.geoObject && this.geoObject.setScale(val);
284
+ for (let i = 0; i < this.childEntities.length; i++) {
285
+ this.childEntities[i].setScale3v(this.childEntities[i].getScale());
286
+ }
287
+ }
288
+ /**
289
+ * Gets the absolute rotation direction of the entity.
290
+ * @public
291
+ * @returns {Quat} The absolute rotation quaternion.
292
+ */
293
+ getAbsoluteRotation() {
294
+ return this._absoluteQRot.clone();
295
+ }
296
+ /**
297
+ * Gets the local rotation of the entity. For the root entity it is equal to the absolute rotation.
298
+ * @public
299
+ * @returns {Quat} The rotation quaternion.
300
+ */
301
+ getRotation() {
302
+ return this._qRot;
303
+ }
304
+ /**
305
+ * Rotates the entity to look at a given point in world coordinates.
306
+ * @public
307
+ * @param {Vec3} cart - The target position to look at.
308
+ */
309
+ setLook3v(cart) {
310
+ let lq = new Quat();
311
+ let p0 = this.getAbsoluteCartesian();
312
+ let rot;
313
+ if (this._entityCollection) {
314
+ let up = this._entityCollection.renderNode.ellipsoid.getSurfaceNormal3v(p0);
315
+ rot = lq.setLookRotation(cart.sub(p0), up).conjugate();
316
+ }
317
+ else {
318
+ rot = lq.setLookRotation(cart.sub(p0), Vec3.UP).conjugate();
319
+ }
320
+ this.setAbsoluteRotation(rot);
321
+ }
322
+ /**
323
+ * Rotates the entity to look at a given geographic coordinate.
324
+ * @public
325
+ * @param {LonLat} lonLat - The longitude and latitude to look at.
326
+ */
327
+ setLookLonLat(lonLat) {
328
+ if (this._entityCollection) {
329
+ let cart = this._entityCollection.renderNode.ellipsoid.lonLatToCartesian(lonLat);
330
+ this.setLook3v(cart);
331
+ }
332
+ }
333
+ /**
334
+ * Sets the absolute rotation of the entity.
335
+ * @public
336
+ * @param {Quat} rot - The new absolute rotation quaternion.
337
+ */
338
+ setAbsoluteRotation(rot) {
339
+ this._absoluteQRot.copy(rot);
340
+ this._updatePitchYawRoll();
341
+ }
342
+ /**
343
+ * Sets the local rotation of the entity.
344
+ * @param {Quat} rot - The new rotation quaternion.
345
+ */
346
+ setRotation(rot) {
347
+ //this._qRot.copy(rot);
348
+ //
349
+ //@todo when necessary
350
+ //
351
+ }
352
+ /**
353
+ * Sets the pitch rotation of the entity.
354
+ * @param {number} val - The new pitch angle in degrees.
355
+ */
356
+ setPitch(val) {
357
+ this._pitch = val;
358
+ this._pitchRad = val * RADIANS;
359
+ this._updateAbsolutePosition();
360
+ }
361
+ /**
362
+ * Sets the yaw rotation of the entity.
363
+ * @param {number} val - The new yaw angle in degrees.
364
+ */
365
+ setYaw(val) {
366
+ this._yaw = val;
367
+ this._yawRad = val * RADIANS;
368
+ this._updateAbsolutePosition();
369
+ }
370
+ /**
371
+ * Sets the roll rotation of the entity.
372
+ * @public
373
+ * @param {number} val - The new roll angle in degrees.
374
+ */
375
+ setRoll(val) {
376
+ this._roll = val;
377
+ this._rollRad = val * RADIANS;
378
+ this._updateAbsolutePosition();
379
+ }
380
+ /**
381
+ * Gets the pitch angle of the entity.
382
+ * @public
383
+ * @returns {number} The pitch angle in degrees.
384
+ */
385
+ getPitch() {
386
+ return this._pitch;
387
+ }
388
+ /**
389
+ * Gets the yaw angle of the entity.
390
+ * @public
391
+ * @returns {number} The yaw angle in degrees.
392
+ */
393
+ getYaw() {
394
+ return this._yaw;
395
+ }
396
+ /**
397
+ * Gets the roll angle of the entity.
398
+ * @public
399
+ * @returns {number} The roll angle in degrees.
400
+ */
401
+ getRoll() {
402
+ return this._roll;
403
+ }
404
+ /**
405
+ * Sets the absolute pitch of the entity.
406
+ * @public
407
+ * @param {number} val - The absolute pitch angle in degrees.
408
+ */
409
+ setAbsolutePitch(val) {
410
+ if (this._relativePosition) {
411
+ this._absoluteQRot.setPitchYawRoll(val * RADIANS, this.getAbsoluteYaw() * RADIANS, this.getAbsoluteRoll() * RADIANS, this._qFrame);
412
+ this._updatePitchYawRoll();
413
+ }
414
+ else {
415
+ this.setPitch(val);
416
+ }
417
+ }
418
+ /**
419
+ * Sets the absolute yaw of the entity.
420
+ * @public
421
+ * @param {number} val - The absolute yaw angle in degrees.
422
+ */
423
+ setAbsoluteYaw(val) {
424
+ if (this._relativePosition) {
425
+ this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch() * RADIANS, val * RADIANS, this.getAbsoluteRoll() * RADIANS, this._qFrame);
426
+ this._updatePitchYawRoll();
427
+ }
428
+ else {
429
+ this.setYaw(val);
430
+ }
431
+ }
432
+ /**
433
+ * Sets the absolute roll of the entity.
434
+ * @public
435
+ * @param {number} val - The absolute roll angle in degrees.
436
+ */
437
+ setAbsoluteRoll(val) {
438
+ if (this._relativePosition) {
439
+ this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch() * RADIANS, this.getAbsoluteYaw() * RADIANS, val * RADIANS, this._qFrame);
440
+ this._updatePitchYawRoll();
441
+ }
442
+ else {
443
+ this.setRoll(val);
444
+ }
445
+ }
446
+ /**
447
+ * Gets the absolute pitch angle of the entity.
448
+ * @public
449
+ * @returns {number} The absolute pitch angle in degrees.
450
+ */
451
+ getAbsolutePitch() {
452
+ if (this.parent && this._relativePosition) {
453
+ return this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getPitch() * DEGREES;
454
+ }
455
+ return this._pitch;
456
+ }
457
+ /**
458
+ * Gets the absolute yaw angle of the entity.
459
+ * @public
460
+ * @returns {number} The absolute yaw angle in degrees.
461
+ */
462
+ getAbsoluteYaw() {
463
+ if (this.parent && this._relativePosition) {
464
+ return this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getYaw() * DEGREES;
465
+ }
466
+ return this._yaw;
467
+ }
468
+ /**
469
+ * Gets the absolute roll angle of the entity.
470
+ * @public
471
+ * @returns {number} The absolute roll angle in degrees.
472
+ */
473
+ getAbsoluteRoll() {
474
+ if (this.parent && this._relativePosition) {
475
+ return this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getRoll() * DEGREES;
476
+ }
477
+ return this._roll;
478
+ }
479
+ _getScaleByDistance() {
480
+ let scd = 1;
481
+ if (this._entityCollection) {
482
+ let scaleByDistance = this._entityCollection.scaleByDistance;
483
+ let lookLength = 1;
484
+ if (this._entityCollection.renderNode && this._entityCollection.renderNode.renderer) {
485
+ lookLength = this._entityCollection.renderNode.renderer.activeCamera.eye.distance(this._rootCartesian);
486
+ }
487
+ //the same in the shader
488
+ scd = scaleByDistance[2] * clamp(lookLength, scaleByDistance[0], scaleByDistance[1]) / scaleByDistance[0];
489
+ }
490
+ return scd;
491
+ }
492
+ /**
493
+ * Sets the absolute cartesian position of the entity.
494
+ * @public
495
+ * @param {number} x - X coordinate.
496
+ * @param {number} y - Y coordinate.
497
+ * @param {number} z - Z coordinate.
498
+ */
499
+ setAbsoluteCartesian(x, y, z) {
500
+ this.setAbsoluteCartesian3v(new Vec3(x, y, z));
501
+ }
502
+ /**
503
+ * Sets the absolute cartesian position of the entity using a Vec3.
504
+ * @public
505
+ * @param {Vec3} absolutCartesian - The absolute cartesian position.
506
+ */
507
+ setAbsoluteCartesian3v(absolutCartesian) {
508
+ let pos = absolutCartesian;
509
+ if (this.parent && this._relativePosition) {
510
+ let scd = this._getScaleByDistance();
511
+ pos = absolutCartesian.sub(this.parent.getAbsoluteCartesian()).scale(1 / scd);
512
+ pos = this.parent._absoluteQRot.conjugate().mulVec3(pos);
513
+ }
514
+ this.setCartesian3v(pos);
515
+ }
516
+ /**
517
+ * Returns absolute cartesian position.
518
+ * @public
519
+ * @returns {Vec3} -
520
+ */
521
+ getAbsoluteCartesian() {
522
+ if (this.parent && this._relativePosition) {
523
+ let scd = this._getScaleByDistance();
524
+ return this._rootCartesian.add(this._absoluteLocalPosition.scaleTo(scd));
525
+ }
526
+ return this._cartesian.clone();
527
+ }
151
528
  /**
152
529
  * Sets entity cartesian position.
153
530
  * @public
@@ -156,31 +533,69 @@ class Entity {
156
533
  * @param {number} z - 3d space Z - position.
157
534
  */
158
535
  setCartesian(x, y, z) {
159
- let p = this._cartesian;
160
- p.x = x || 0.0;
161
- p.y = y || 0.0;
162
- p.z = z || 0.0;
163
- // billboards
164
- this.billboard && this.billboard.setPosition3v(p);
165
- // geoObject
166
- this.geoObject && this.geoObject.setPosition3v(p);
167
- // labels
168
- this.label && this.label.setPosition3v(p);
169
- for (let i = 0; i < this.childrenNodes.length; i++) {
170
- this.childrenNodes[i].setCartesian(x, y, z);
171
- }
172
- let ec = this._entityCollection;
173
- if (ec && ec.renderNode && ec.renderNode.ellipsoid) {
174
- this._lonLat = ec.renderNode.ellipsoid.cartesianToLonLat(p);
175
- if (Math.abs(this._lonLat.lat) < mercator.MAX_LAT) {
176
- this._lonLatMerc = this._lonLat.forwardMercator();
536
+ this._cartesian.set(x, y, z);
537
+ this._updateAbsolutePosition();
538
+ for (let i = 0; i < this.childEntities.length; i++) {
539
+ let chi = this.childEntities[i];
540
+ if (chi._relativePosition) {
541
+ chi.setCartesian3v(chi.getCartesian());
177
542
  }
178
- else {
179
- this._lonLatMerc.lon = this._lonLatMerc.lat = this._lonLatMerc.height = 0;
543
+ else if (chi.forceGlobalPosition) {
544
+ chi.setCartesian(x, y, z);
180
545
  }
181
546
  }
547
+ this._updateLonLat();
182
548
  //ec && ec.events.dispatch(ec.events.entitymove, this);
183
549
  }
550
+ _updatePitchYawRoll() {
551
+ if (this.parent) {
552
+ this._qRot = this.parent._absoluteQRot.conjugate().mul(this._absoluteQRot);
553
+ this._pitchRad = this._qRot.getPitch();
554
+ this._yawRad = this._qRot.getYaw();
555
+ this._rollRad = this._qRot.getRoll();
556
+ this._pitch = this._pitchRad * DEGREES;
557
+ this._yaw = this._yawRad * DEGREES;
558
+ this._roll = this._rollRad * DEGREES;
559
+ if (this.geoObject) {
560
+ this.geoObject.setRotation(this._absoluteQRot);
561
+ }
562
+ for (let i = 0; i < this.childEntities.length; i++) {
563
+ this.childEntities[i]._updateAbsolutePosition();
564
+ }
565
+ }
566
+ }
567
+ _updateAbsolutePosition() {
568
+ let parent = this.parent;
569
+ if (parent && this._relativePosition) {
570
+ this._qFrame.copy(parent._qFrame);
571
+ this._rootCartesian.copy(parent._rootCartesian);
572
+ this._qRot.setPitchYawRoll(this._pitchRad, this._yawRad, this._rollRad);
573
+ parent._absoluteQRot.mulRes(this._qRot, this._absoluteQRot);
574
+ let rotCart = parent._absoluteQRot.mulVec3(this._cartesian.add(this._localPosition));
575
+ parent._absoluteLocalPosition.addRes(rotCart, this._absoluteLocalPosition);
576
+ }
577
+ else {
578
+ this._qFrame = Quat.IDENTITY;
579
+ if (this._entityCollection && this._entityCollection.renderNode) {
580
+ this._qFrame = this._entityCollection.renderNode.getFrameRotation(this._cartesian);
581
+ }
582
+ this._qRot.setPitchYawRoll(this._pitchRad, this._yawRad, this._rollRad, this._qFrame);
583
+ this._absoluteQRot.copy(this._qRot);
584
+ this._rootCartesian.copy(this._cartesian);
585
+ this._absoluteLocalPosition.copy(this._localPosition);
586
+ }
587
+ if (this.geoObject) {
588
+ this.geoObject.setRotation(this._absoluteQRot);
589
+ this.geoObject.setPosition3v(this._rootCartesian);
590
+ this.geoObject.setLocalPosition3v(this._absoluteLocalPosition);
591
+ }
592
+ this.billboard && this.billboard.setPosition3v(this._rootCartesian);
593
+ this.label && this.label.setPosition3v(this._rootCartesian);
594
+ for (let i = 0, len = this.childEntities.length; i < len; i++) {
595
+ this.childEntities[i]._updateAbsolutePosition();
596
+ }
597
+ this._updateLonLat();
598
+ }
184
599
  /**
185
600
  * Sets entity cartesian position without event dispatching.
186
601
  * @public
@@ -188,27 +603,25 @@ class Entity {
188
603
  * @param {boolean} skipLonLat - skip geodetic calculation.
189
604
  */
190
605
  _setCartesian3vSilent(cartesian, skipLonLat = false) {
191
- let p = this._cartesian;
192
- p.x = cartesian.x || 0.0;
193
- p.y = cartesian.y || 0.0;
194
- p.z = cartesian.z || 0.0;
195
- // billboards
196
- this.billboard && this.billboard.setPosition3v(p);
197
- // geoObject
198
- this.geoObject && this.geoObject.setPosition3v(p);
199
- // labels
200
- this.label && this.label.setPosition3v(p);
201
- for (let i = 0; i < this.childrenNodes.length; i++) {
202
- this.childrenNodes[i].setCartesian(p.x, p.y, p.z);
606
+ this._cartesian.copy(cartesian);
607
+ this._updateAbsolutePosition();
608
+ for (let i = 0; i < this.childEntities.length; i++) {
609
+ this.childEntities[i].setCartesian(this._cartesian.x, this._cartesian.y, this._cartesian.z);
610
+ }
611
+ if (!skipLonLat) {
612
+ this._updateLonLat();
203
613
  }
614
+ }
615
+ _updateLonLat() {
204
616
  let ec = this._entityCollection;
205
- if (!skipLonLat && ec && ec.renderNode && ec.renderNode.ellipsoid) {
206
- this._lonLat = ec.renderNode.ellipsoid.cartesianToLonLat(p);
617
+ if (ec && ec.renderNode && ec.renderNode.ellipsoid) {
618
+ //let cart = this._rootCartesian.add(this._absoluteLocalPosition);
619
+ this._lonLat = ec.renderNode.ellipsoid.cartesianToLonLat(this.getAbsoluteCartesian());
207
620
  if (Math.abs(this._lonLat.lat) < mercator.MAX_LAT) {
208
621
  this._lonLatMerc = this._lonLat.forwardMercator();
209
622
  }
210
623
  else {
211
- //this._lonLatMerc = null;
624
+ this._lonLatMerc.lon = this._lonLatMerc.lat = 0;
212
625
  }
213
626
  }
214
627
  }
@@ -223,7 +636,7 @@ class Entity {
223
636
  /**
224
637
  * Sets geodetic coordinates of the entity point object.
225
638
  * @public
226
- * @param {LonLat} lonlat - WGS84 coordinates.
639
+ * @param {LonLat} lonlat - coordinates.
227
640
  */
228
641
  setLonLat(lonlat) {
229
642
  let l = this._lonLat;
@@ -238,8 +651,9 @@ class Entity {
238
651
  else {
239
652
  //this._lonLatMerc = null;
240
653
  }
241
- ec.renderNode.ellipsoid.lonLatToCartesianRes(l, this._cartesian);
242
- this.setCartesian3v(this._cartesian);
654
+ let temp = new Vec3();
655
+ ec.renderNode.ellipsoid.lonLatToCartesianRes(l, temp);
656
+ this.setAbsoluteCartesian3v(temp);
243
657
  }
244
658
  }
245
659
  /**
@@ -262,8 +676,9 @@ class Entity {
262
676
  else {
263
677
  this._lonLatMerc.lon = this._lonLatMerc.lat = this._lonLatMerc.height = 0;
264
678
  }
265
- ec.renderNode.ellipsoid.lonLatToCartesianRes(l, this._cartesian);
266
- this.setCartesian3v(this._cartesian);
679
+ let temp = new Vec3();
680
+ ec.renderNode.ellipsoid.lonLatToCartesianRes(l, temp);
681
+ this.setAbsoluteCartesian3v(temp);
267
682
  }
268
683
  }
269
684
  /**
@@ -425,6 +840,11 @@ class Entity {
425
840
  this._entityCollection && this._entityCollection.stripHandler.add(strip);
426
841
  return strip;
427
842
  }
843
+ /**
844
+ * Gets layer container
845
+ * @public
846
+ * @returns {Vector | null}
847
+ */
428
848
  get layer() {
429
849
  return this._layer;
430
850
  }
@@ -448,7 +868,7 @@ class Entity {
448
868
  entity._pickingColor = this._pickingColor;
449
869
  }
450
870
  entity.parent = this;
451
- this.childrenNodes.push(entity);
871
+ this.childEntities.push(entity);
452
872
  this._entityCollection && this._entityCollection.appendChildEntity(entity);
453
873
  }
454
874
  /**
@@ -463,8 +883,8 @@ class Entity {
463
883
  this.ray && this.ray.setPickingColor3v(c);
464
884
  this.strip && this.strip.setPickingColor3v(c);
465
885
  this.geoObject && this.geoObject.setPickingColor3v(c);
466
- for (let i = 0; i < this.childrenNodes.length; i++) {
467
- this.childrenNodes[i].setPickingColor();
886
+ for (let i = 0; i < this.childEntities.length; i++) {
887
+ this.childEntities[i].setPickingColor();
468
888
  }
469
889
  }
470
890
  /**
@@ -504,8 +924,8 @@ class Entity {
504
924
  if (e.northEast.lat > ne.lat)
505
925
  ne.lat = e.northEast.lat;
506
926
  }
507
- for (let i = 0; i < this.childrenNodes.length; i++) {
508
- let e = this.childrenNodes[i].getExtent();
927
+ for (let i = 0; i < this.childEntities.length; i++) {
928
+ let e = this.childEntities[i].getExtent();
509
929
  if (e.southWest.lon < sw.lon)
510
930
  sw.lon = e.southWest.lon;
511
931
  if (e.southWest.lat < sw.lat)