@openglobus/og 0.11.4 → 0.11.8

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 (260) hide show
  1. package/css/og.css +3 -2
  2. package/package.json +12 -14
  3. package/src/og/Clock.js +6 -10
  4. package/src/og/Events.js +5 -7
  5. package/src/og/Extent.js +73 -32
  6. package/src/og/Globe.js +8 -5
  7. package/src/og/ImageCanvas.js +18 -15
  8. package/src/og/LonLat.js +13 -10
  9. package/src/og/Popup.js +19 -17
  10. package/src/og/QueueArray.js +3 -4
  11. package/src/og/Rectangle.js +4 -6
  12. package/src/og/Stack.js +2 -4
  13. package/src/og/ajax.js +20 -14
  14. package/src/og/astro/earth.js +21 -15
  15. package/src/og/bv/Box.js +2 -3
  16. package/src/og/bv/Sphere.js +10 -7
  17. package/src/og/camera/Frustum.js +19 -12
  18. package/src/og/camera/PlanetCamera.js +9 -5
  19. package/src/og/control/CompassButton.js +1 -2
  20. package/src/og/control/Control.js +7 -9
  21. package/src/og/control/DebugInfo.js +0 -1
  22. package/src/og/control/KeyboardNavigation.js +9 -9
  23. package/src/og/control/LayerSwitcher.js +21 -20
  24. package/src/og/control/Lighting.js +74 -64
  25. package/src/og/control/MouseNavigation.js +21 -18
  26. package/src/og/control/MouseWheelZoomControl.js +257 -0
  27. package/src/og/control/SegmentBoundVisualization.js +5 -6
  28. package/src/og/control/ShowFps.js +12 -7
  29. package/src/og/control/SimpleNavigation.js +5 -7
  30. package/src/og/control/Sun.js +22 -12
  31. package/src/og/control/ToggleWireframe.js +3 -3
  32. package/src/og/control/TouchNavigation.js +43 -32
  33. package/src/og/control/ZoomControl.js +40 -24
  34. package/src/og/control/index.js +2 -0
  35. package/src/og/control/visibleExtent/Segment.js +1862 -0
  36. package/src/og/control/visibleExtent/VisibleExtent.js +80 -0
  37. package/src/og/control/visibleExtent/drawnode.js +751 -0
  38. package/src/og/ellipsoid/Ellipsoid.js +149 -57
  39. package/src/og/ellipsoid/wgs84.js +3 -3
  40. package/src/og/entity/BaseBillboard.js +72 -30
  41. package/src/og/entity/Billboard.js +9 -5
  42. package/src/og/entity/BillboardHandler.js +315 -62
  43. package/src/og/entity/Entity.js +39 -1
  44. package/src/og/entity/EntityCollection.js +47 -24
  45. package/src/og/entity/GeoObject.js +228 -0
  46. package/src/og/entity/GeoObjectHandler.js +910 -0
  47. package/src/og/entity/GeometryHandler.js +595 -123
  48. package/src/og/entity/Label.js +62 -30
  49. package/src/og/entity/LabelHandler.js +40 -242
  50. package/src/og/entity/LabelWorker.js +218 -0
  51. package/src/og/entity/Object3d.js +504 -0
  52. package/src/og/entity/PointCloud.js +76 -28
  53. package/src/og/entity/PointCloudHandler.js +5 -5
  54. package/src/og/entity/Ray.js +49 -16
  55. package/src/og/entity/Strip.js +72 -43
  56. package/src/og/entity/StripHandler.js +23 -23
  57. package/src/og/layer/BaseGeoImage.js +50 -19
  58. package/src/og/layer/CanvasTiles.js +16 -17
  59. package/src/og/layer/GeoImage.js +8 -16
  60. package/src/og/layer/GeoTexture2d.js +2 -10
  61. package/src/og/layer/GeoVideo.js +2 -10
  62. package/src/og/layer/KML.js +55 -33
  63. package/src/og/layer/Layer.js +24 -32
  64. package/src/og/layer/Material.js +1 -1
  65. package/src/og/layer/Vector.js +94 -48
  66. package/src/og/layer/WMS.js +33 -18
  67. package/src/og/layer/XYZ.js +4 -5
  68. package/src/og/light/LightSource.js +19 -12
  69. package/src/og/math/Mat3.js +24 -12
  70. package/src/og/math/Mat4.js +603 -603
  71. package/src/og/math/Plane.js +19 -18
  72. package/src/og/math/Ray.js +17 -12
  73. package/src/og/math/Vec2.js +24 -14
  74. package/src/og/math/Vec3.js +60 -30
  75. package/src/og/math/coder.js +7 -7
  76. package/src/og/proj/EPSG3857.js +3 -3
  77. package/src/og/proj/EPSG4326.js +3 -3
  78. package/src/og/proj/Proj.js +2 -4
  79. package/src/og/quadTree/Node.js +3 -3
  80. package/src/og/renderer/Renderer.js +106 -124
  81. package/src/og/renderer/RendererEvents.js +45 -23
  82. package/src/og/scene/BaseNode.js +2 -3
  83. package/src/og/scene/Planet.js +51 -90
  84. package/src/og/scene/RenderNode.js +15 -8
  85. package/src/og/segment/Segment.js +60 -156
  86. package/src/og/segment/Slice.js +45 -0
  87. package/src/og/shaders/drawnode.js +245 -342
  88. package/src/og/shaders/geoObject.js +211 -0
  89. package/src/og/shaders/pointCloud.js +41 -41
  90. package/src/og/shaders/shape.js +12 -18
  91. package/src/og/shaders/skybox.js +36 -36
  92. package/src/og/shaders/toneMapping.js +1 -0
  93. package/src/og/shapes/BaseShape.js +108 -36
  94. package/src/og/shapes/Icosphere.js +25 -10
  95. package/src/og/shapes/Sphere.js +8 -11
  96. package/src/og/utils/FontAtlas.js +6 -2
  97. package/src/og/utils/GeoImageCreator.js +5 -1
  98. package/src/og/utils/TextureAtlas.js +18 -20
  99. package/src/og/utils/VectorTileCreator.js +1 -3
  100. package/src/og/utils/shared.js +2 -2
  101. package/src/og/webgl/Handler.js +215 -162
  102. package/src/og/webgl/Multisample.js +44 -16
  103. package/src/og/webgl/Program.js +78 -33
  104. package/src/og/webgl/callbacks.js +3 -3
  105. package/types/Clock.d.ts +0 -94
  106. package/types/Deferred.d.ts +0 -6
  107. package/types/Events.d.ts +0 -77
  108. package/types/Extent.d.ts +0 -166
  109. package/types/Globe.d.ts +0 -82
  110. package/types/ImageCanvas.d.ts +0 -123
  111. package/types/Lock.d.ts +0 -12
  112. package/types/LonLat.d.ts +0 -108
  113. package/types/Popup.d.ts +0 -42
  114. package/types/QueueArray.d.ts +0 -19
  115. package/types/Rectangle.d.ts +0 -80
  116. package/types/Stack.d.ts +0 -19
  117. package/types/ajax.d.ts +0 -24
  118. package/types/arial.d.ts +0 -48
  119. package/types/astro/astro.d.ts +0 -38
  120. package/types/astro/earth.d.ts +0 -7
  121. package/types/astro/jd.d.ts +0 -254
  122. package/types/bv/Box.d.ts +0 -30
  123. package/types/bv/Sphere.d.ts +0 -38
  124. package/types/bv/index.d.ts +0 -3
  125. package/types/camera/Camera.d.ts +0 -312
  126. package/types/camera/Frustum.d.ts +0 -133
  127. package/types/camera/PlanetCamera.d.ts +0 -218
  128. package/types/camera/index.d.ts +0 -3
  129. package/types/cons.d.ts +0 -40
  130. package/types/control/CompassButton.d.ts +0 -17
  131. package/types/control/Control.d.ts +0 -104
  132. package/types/control/DebugInfo.d.ts +0 -15
  133. package/types/control/EarthCoordinates.d.ts +0 -47
  134. package/types/control/EarthNavigation.d.ts +0 -42
  135. package/types/control/GeoImageDragControl.d.ts +0 -6
  136. package/types/control/KeyboardNavigation.d.ts +0 -21
  137. package/types/control/LayerSwitcher.d.ts +0 -21
  138. package/types/control/Lighting.d.ts +0 -16
  139. package/types/control/MouseNavigation.d.ts +0 -47
  140. package/types/control/ScaleControl.d.ts +0 -22
  141. package/types/control/ShowFps.d.ts +0 -11
  142. package/types/control/SimpleNavigation.d.ts +0 -25
  143. package/types/control/Sun.d.ts +0 -50
  144. package/types/control/ToggleWireframe.d.ts +0 -12
  145. package/types/control/TouchNavigation.d.ts +0 -48
  146. package/types/control/ZoomControl.d.ts +0 -27
  147. package/types/control/index.d.ts +0 -17
  148. package/types/ellipsoid/Ellipsoid.d.ts +0 -146
  149. package/types/ellipsoid/index.d.ts +0 -3
  150. package/types/ellipsoid/wgs84.d.ts +0 -6
  151. package/types/entity/BaseBillboard.d.ts +0 -208
  152. package/types/entity/Billboard.d.ts +0 -94
  153. package/types/entity/BillboardHandler.d.ts +0 -78
  154. package/types/entity/Entity.d.ts +0 -333
  155. package/types/entity/EntityCollection.d.ts +0 -311
  156. package/types/entity/Geometry.d.ts +0 -74
  157. package/types/entity/GeometryHandler.d.ts +0 -76
  158. package/types/entity/Label.d.ts +0 -189
  159. package/types/entity/LabelHandler.d.ts +0 -29
  160. package/types/entity/PointCloud.d.ts +0 -174
  161. package/types/entity/PointCloudHandler.d.ts +0 -38
  162. package/types/entity/Polyline.d.ts +0 -306
  163. package/types/entity/PolylineHandler.d.ts +0 -18
  164. package/types/entity/Ray.d.ts +0 -124
  165. package/types/entity/RayHandler.d.ts +0 -67
  166. package/types/entity/ShapeHandler.d.ts +0 -22
  167. package/types/entity/Strip.d.ts +0 -119
  168. package/types/entity/StripHandler.d.ts +0 -38
  169. package/types/entity/index.d.ts +0 -8
  170. package/types/index.core.d.ts +0 -65
  171. package/types/index.d.ts +0 -45
  172. package/types/index.webgl.d.ts +0 -7
  173. package/types/input/KeyboardHandler.d.ts +0 -10
  174. package/types/input/MouseHandler.d.ts +0 -5
  175. package/types/input/TouchHandler.d.ts +0 -5
  176. package/types/input/input.d.ts +0 -34
  177. package/types/layer/BaseGeoImage.d.ts +0 -94
  178. package/types/layer/CanvasTiles.d.ts +0 -68
  179. package/types/layer/GeoImage.d.ts +0 -52
  180. package/types/layer/GeoTexture2d.d.ts +0 -8
  181. package/types/layer/GeoVideo.d.ts +0 -55
  182. package/types/layer/KML.d.ts +0 -63
  183. package/types/layer/Layer.d.ts +0 -325
  184. package/types/layer/Material.d.ts +0 -45
  185. package/types/layer/Vector.d.ts +0 -208
  186. package/types/layer/WMS.d.ts +0 -63
  187. package/types/layer/XYZ.d.ts +0 -120
  188. package/types/layer/index.d.ts +0 -10
  189. package/types/light/LightSource.d.ts +0 -178
  190. package/types/math/Line2.d.ts +0 -11
  191. package/types/math/Line3.d.ts +0 -10
  192. package/types/math/Mat3.d.ts +0 -65
  193. package/types/math/Mat4.d.ts +0 -176
  194. package/types/math/Plane.d.ts +0 -18
  195. package/types/math/Quat.d.ts +0 -379
  196. package/types/math/Ray.d.ts +0 -82
  197. package/types/math/Vec2.d.ts +0 -309
  198. package/types/math/Vec3.d.ts +0 -460
  199. package/types/math/Vec4.d.ts +0 -162
  200. package/types/math/coder.d.ts +0 -43
  201. package/types/math/index.d.ts +0 -11
  202. package/types/math.d.ts +0 -261
  203. package/types/mercator.d.ts +0 -92
  204. package/types/proj/EPSG3857.d.ts +0 -6
  205. package/types/proj/EPSG4326.d.ts +0 -6
  206. package/types/proj/Proj.d.ts +0 -42
  207. package/types/quadTree/EntityCollectionNode.d.ts +0 -34
  208. package/types/quadTree/Node.d.ts +0 -61
  209. package/types/quadTree/quadTree.d.ts +0 -40
  210. package/types/renderer/Renderer.d.ts +0 -298
  211. package/types/renderer/RendererEvents.d.ts +0 -233
  212. package/types/res/images.d.ts +0 -3
  213. package/types/scene/Axes.d.ts +0 -11
  214. package/types/scene/BaseNode.d.ts +0 -60
  215. package/types/scene/Planet.d.ts +0 -577
  216. package/types/scene/RenderNode.d.ts +0 -142
  217. package/types/scene/SkyBox.d.ts +0 -10
  218. package/types/scene/index.d.ts +0 -4
  219. package/types/segment/Segment.d.ts +0 -279
  220. package/types/segment/SegmentLonLat.d.ts +0 -16
  221. package/types/segment/segmentHelper.d.ts +0 -13
  222. package/types/shaders/billboard.d.ts +0 -3
  223. package/types/shaders/depth.d.ts +0 -2
  224. package/types/shaders/drawnode.d.ts +0 -7
  225. package/types/shaders/label.d.ts +0 -4
  226. package/types/shaders/pointCloud.d.ts +0 -2
  227. package/types/shaders/polyline.d.ts +0 -3
  228. package/types/shaders/ray.d.ts +0 -2
  229. package/types/shaders/screenFrame.d.ts +0 -2
  230. package/types/shaders/shape.d.ts +0 -4
  231. package/types/shaders/skybox.d.ts +0 -2
  232. package/types/shaders/toneMapping.d.ts +0 -2
  233. package/types/shapes/BaseShape.d.ts +0 -250
  234. package/types/shapes/Sphere.d.ts +0 -41
  235. package/types/terrain/BilTerrain.d.ts +0 -7
  236. package/types/terrain/EmptyTerrain.d.ts +0 -72
  237. package/types/terrain/Geoid.d.ts +0 -26
  238. package/types/terrain/GlobusTerrain.d.ts +0 -116
  239. package/types/terrain/MapboxTerrain.d.ts +0 -7
  240. package/types/terrain/index.d.ts +0 -5
  241. package/types/utils/FontAtlas.d.ts +0 -14
  242. package/types/utils/GeoImageCreator.d.ts +0 -30
  243. package/types/utils/ImagesCacheManager.d.ts +0 -10
  244. package/types/utils/Loader.d.ts +0 -25
  245. package/types/utils/NormalMapCreator.d.ts +0 -39
  246. package/types/utils/PlainSegmentWorker.d.ts +0 -10
  247. package/types/utils/TerrainWorker.d.ts +0 -9
  248. package/types/utils/TextureAtlas.d.ts +0 -111
  249. package/types/utils/VectorTileCreator.d.ts +0 -16
  250. package/types/utils/colorTable.d.ts +0 -143
  251. package/types/utils/earcut.d.ts +0 -6
  252. package/types/utils/shared.d.ts +0 -231
  253. package/types/webgl/Framebuffer.d.ts +0 -135
  254. package/types/webgl/Handler.d.ts +0 -388
  255. package/types/webgl/Multisample.d.ts +0 -89
  256. package/types/webgl/Program.d.ts +0 -155
  257. package/types/webgl/ProgramController.d.ts +0 -89
  258. package/types/webgl/callbacks.d.ts +0 -1
  259. package/types/webgl/index.d.ts +0 -6
  260. package/types/webgl/types.d.ts +0 -2
@@ -0,0 +1,910 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @module og/entity/ShapeHandler
5
+ */
6
+ import * as shaders from "../shaders/geoObject.js";
7
+ import { concatArrays, makeArrayTyped, spliceArray } from "../utils/shared.js";
8
+
9
+ const VERTEX_BUFFER = 0,
10
+ POSITION_BUFFER = 1,
11
+ RGBA_BUFFER = 2,
12
+ NORMALS_BUFFER = 3,
13
+ INDECIES_BUFFER = 4,
14
+ DIRECTION_BUFFER = 5,
15
+ PITCH_ROLL_BUFFER = 6,
16
+ SIZE_BUFFER = 7,
17
+ PICKINGCOLOR_BUFFER = 8;
18
+
19
+ const setParametersToArray = (arr = [], index = 0, length, itemSize, ...params) => {
20
+ const currIndex = index * length;
21
+ for (let i = currIndex, len = currIndex + length; i < len; i++) {
22
+ arr[i] = params[i % itemSize];
23
+ }
24
+ return arr;
25
+ };
26
+
27
+ class GeoObjectHandler {
28
+ constructor(entityCollection) {
29
+ /**
30
+ * Picking rendering option.
31
+ * @public
32
+ * @type {boolean}
33
+ */
34
+ this.pickingEnabled = true;
35
+
36
+ this._entityCollection = entityCollection;
37
+ this._renderer = null;
38
+ this._planet = null;
39
+
40
+ this._geoObjects = [];
41
+ this._pitchRollArr = [[]];
42
+ this._sizeArr = [[]];
43
+ this._vertexArr = [[]];
44
+ this._positionHighArr = [[]];
45
+ this._positionLowArr = [[]];
46
+ this._directionArr = [[]];
47
+ this._rgbaArr = [[]];
48
+ this._normalsArr = [[]];
49
+ this._indicesArr = [[]];
50
+ this._pickingColorArr = [[]];
51
+
52
+ this._pitchRollBuffer = [];
53
+ this._sizeBuffer = [];
54
+ this._vertexBuffer = [];
55
+ this._positionHighBuffer = [];
56
+ this._positionLowBuffer = [];
57
+ this._directionBuffer = [];
58
+ this._rgbaBuffer = [];
59
+ this._normalsBuffer = [];
60
+ this._indicesBuffer = [];
61
+ this._pickingColorBuffer = [];
62
+
63
+ this.__staticId = GeoObjectHandler._staticCounter++;
64
+ this._buffersUpdateCallbacks = [];
65
+ this._buffersUpdateCallbacks[PICKINGCOLOR_BUFFER] = this.createPickingColorBuffer;
66
+ this._buffersUpdateCallbacks[POSITION_BUFFER] = this.createPositionBuffer;
67
+ this._buffersUpdateCallbacks[DIRECTION_BUFFER] = this.createDirectionBuffer;
68
+ this._buffersUpdateCallbacks[NORMALS_BUFFER] = this.createNormalsBuffer;
69
+ this._buffersUpdateCallbacks[RGBA_BUFFER] = this.createRgbaBuffer;
70
+ this._buffersUpdateCallbacks[INDECIES_BUFFER] = this.createIndicesBuffer;
71
+ this._buffersUpdateCallbacks[VERTEX_BUFFER] = this.createVertexBuffer;
72
+ this._buffersUpdateCallbacks[SIZE_BUFFER] = this.createSizeBuffer;
73
+ this._buffersUpdateCallbacks[PITCH_ROLL_BUFFER] = this.createPitchRollBuffer;
74
+
75
+ this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
76
+
77
+ this._instancedTags = new Map();
78
+ }
79
+
80
+ getObjectByIndex(index) {
81
+ return this._geoObjects[index];
82
+ }
83
+
84
+ //Create buffers
85
+ createVertexBuffer() {
86
+ const h = this._renderer.handler;
87
+ for (let i = 0, len = this._vertexArr.length; i < len; i++) {
88
+ this._vertexBuffer && h.gl.deleteBuffer(this._vertexBuffer[i]);
89
+ this._vertexArr[i] = makeArrayTyped(this._vertexArr[i]);
90
+ this._vertexBuffer[i] = h.createArrayBuffer(this._vertexArr[i], 3, len / 3);
91
+ }
92
+ }
93
+
94
+ createPitchRollBuffer() {
95
+ const h = this._renderer.handler;
96
+ for (let i = 0, len = this._pitchRollArr.length; i < len; i++) {
97
+ this._pitchRollBuffer && h.gl.deleteBuffer(this._pitchRollBuffer[i]);
98
+ this._pitchRollArr[i] = makeArrayTyped(this._pitchRollArr[i]);
99
+ this._pitchRollBuffer[i] = h.createArrayBuffer(this._pitchRollArr[i], 2, len / 2);
100
+ }
101
+ }
102
+
103
+ createSizeBuffer() {
104
+ const h = this._renderer.handler;
105
+ for (let i = 0, len = this._sizeArr.length; i < len; i++) {
106
+ this._sizeBuffer && h.gl.deleteBuffer(this._sizeBuffer[i]);
107
+ this._sizeArr[i] = makeArrayTyped(this._sizeArr[i]);
108
+ this._sizeBuffer[i] = h.createArrayBuffer(this._sizeArr[i], 1, len);
109
+ }
110
+ }
111
+
112
+ createPositionBuffer() {
113
+ let h = this._renderer.handler;
114
+ for (let i = 0, len = this._positionHighArr.length; i < len; i++) {
115
+ this._positionHighBuffer && h.gl.deleteBuffer(this._positionHighBuffer[i]);
116
+ this._positionHighArr[i] = makeArrayTyped(this._positionHighArr[i]);
117
+ this._positionHighBuffer[i] = h.createArrayBuffer(this._positionHighArr[i], 3, len / 3);
118
+ this._positionLowBuffer && h.gl.deleteBuffer(this._positionLowBuffer[i]);
119
+ this._positionLowArr[i] = makeArrayTyped(this._positionLowArr[i]);
120
+ this._positionLowBuffer[i] = h.createArrayBuffer(
121
+ this._positionLowArr[i],
122
+ 3,
123
+ this._positionLowArr[i].length / 3
124
+ );
125
+ }
126
+ }
127
+
128
+ createRgbaBuffer() {
129
+ const h = this._renderer.handler;
130
+ for (let i = 0, len = this._rgbaArr.length; i < len; i++) {
131
+ this._rgbaBuffer && h.gl.deleteBuffer(this._rgbaBuffer[i]);
132
+ this._rgbaArr[i] = makeArrayTyped(this._rgbaArr[i]);
133
+ this._rgbaBuffer[i] = h.createArrayBuffer(this._rgbaArr[i], 4, len / 4);
134
+ }
135
+ }
136
+
137
+ createDirectionBuffer() {
138
+ const h = this._renderer.handler;
139
+ for (let i = 0, len = this._directionArr.length; i < len; i++) {
140
+ this._directionBuffer && h.gl.deleteBuffer(this._directionBuffer[i]);
141
+ this._directionArr[i] = makeArrayTyped(this._directionArr[i]);
142
+ this._directionBuffer[i] = h.createArrayBuffer(this._directionArr[i], 3, len / 3);
143
+ }
144
+ }
145
+
146
+ createNormalsBuffer() {
147
+ const h = this._renderer.handler;
148
+ for (let i = 0, len = this._normalsArr.length; i < len; i++) {
149
+ this._normalsBuffer && h.gl.deleteBuffer(this._normalsBuffer[i]);
150
+ this._normalsArr[i] = makeArrayTyped(this._normalsArr[i]);
151
+ this._normalsBuffer[i] = h.createArrayBuffer(this._normalsArr[i], 3, len / 3);
152
+ }
153
+ }
154
+
155
+ createIndicesBuffer() {
156
+ const h = this._renderer.handler;
157
+ for (let i = 0, len = this._indicesArr.length; i < len; i++) {
158
+ this._indicesBuffer && h.gl.deleteBuffer(this._indicesBuffer[i]);
159
+ this._indicesArr[i] = makeArrayTyped(this._indicesArr[i], Uint16Array);
160
+ this._indicesBuffer[i] = h.createElementArrayBuffer(
161
+ this._indicesArr[i],
162
+ 1,
163
+ this._indicesArr[i].length
164
+ );
165
+ }
166
+ }
167
+
168
+ createPickingColorBuffer() {
169
+ const h = this._renderer.handler;
170
+ for (let i = 0, len = this._pickingColorArr.length; i < len; i++) {
171
+ this._pickingColorBuffer && h.gl.deleteBuffer(this._pickingColorBuffer[i]);
172
+ this._pickingColorArr[i] = makeArrayTyped(this._pickingColorArr[i]);
173
+ this._pickingColorBuffer[i] = h.createArrayBuffer(this._pickingColorArr[i], 3, len / 3);
174
+ }
175
+ }
176
+
177
+ static get _staticCounter() {
178
+ if (!this._counter && this._counter !== 0) {
179
+ this._counter = 0;
180
+ }
181
+ return this._counter;
182
+ }
183
+
184
+ static set _staticCounter(n) {
185
+ this._counter = n;
186
+ }
187
+
188
+ initProgram() {
189
+ if (this._renderer.handler) {
190
+ if (!this._renderer.handler.programs.geo_object) {
191
+ this._renderer.handler.addProgram(shaders.geo_object());
192
+ }
193
+ if (!this._renderer.handler.programs.geo_object_picking) {
194
+ this._renderer.handler.addProgram(shaders.geo_object_picking());
195
+ }
196
+ }
197
+ }
198
+
199
+ setRenderNode(renderNode) {
200
+ this._renderer = renderNode.renderer;
201
+ this._planet = renderNode;
202
+ this.initProgram();
203
+ }
204
+
205
+ setRenderer(planet) {
206
+ super.setRenderer(planet);
207
+ }
208
+
209
+ _addGeoObjectToArray(geoObject) {
210
+ let itemSize = 3;
211
+
212
+ const tag = geoObject.tag,
213
+ alreadyAdded = this._instancedTags.has(tag);
214
+
215
+ if (!alreadyAdded) {
216
+ this._instancedTags.set(tag, {
217
+ iCounts: 1,
218
+ index: this._instancedTags.size
219
+ });
220
+ } else {
221
+ const prevState = this._instancedTags.get(tag),
222
+ nextCount = prevState.iCounts + 1;
223
+ this._instancedTags.set(tag, {
224
+ iCounts: nextCount,
225
+ index: prevState.index
226
+ });
227
+ }
228
+ const tagData = this._instancedTags.get(tag),
229
+ ti = tagData.index;
230
+
231
+ /**
232
+ * mark object by index for recalc indices array
233
+ */
234
+ geoObject._tagIndex = tagData.iCounts - 1;
235
+ if (geoObject._visibility) {
236
+ if (!alreadyAdded) {
237
+ this._vertexArr[ti] = concatArrays(
238
+ this._vertexArr[ti],
239
+ setParametersToArray(
240
+ [],
241
+ 0,
242
+ geoObject._verticesCount * itemSize,
243
+ geoObject._verticesCount * itemSize,
244
+ ...geoObject._vertices
245
+ )
246
+ );
247
+ this._normalsArr[ti] = concatArrays(
248
+ this._normalsArr[ti],
249
+ setParametersToArray(
250
+ [],
251
+ 0,
252
+ geoObject._verticesCount * itemSize,
253
+ geoObject._verticesCount * itemSize,
254
+ ...geoObject._normals
255
+ // ...getTriangleNormals(geoObject._vertices, geoObject._indices)
256
+ )
257
+ );
258
+ }
259
+ } else {
260
+ this._vertexArr[ti] = concatArrays(
261
+ this._vertexArr[ti],
262
+ setParametersToArray([], 0, geoObject._verticesCount * itemSize, 1, 0)
263
+ );
264
+ }
265
+ let x = geoObject._positionHigh.x,
266
+ y = geoObject._positionHigh.y,
267
+ z = geoObject._positionHigh.z,
268
+ w;
269
+
270
+ this._positionHighArr[ti] = concatArrays(
271
+ this._positionHighArr[ti],
272
+ setParametersToArray([], 0, itemSize, itemSize, x, y, z)
273
+ );
274
+ x = geoObject._positionLow.x;
275
+ y = geoObject._positionLow.y;
276
+ z = geoObject._positionLow.z;
277
+ this._positionLowArr[ti] = concatArrays(
278
+ this._positionLowArr[ti],
279
+ setParametersToArray([], 0, itemSize, itemSize, x, y, z)
280
+ );
281
+
282
+ x = geoObject._entity._pickingColor.x / 255;
283
+ y = geoObject._entity._pickingColor.y / 255;
284
+ z = geoObject._entity._pickingColor.z / 255;
285
+ this._pickingColorArr[ti] = concatArrays(
286
+ this._pickingColorArr[ti],
287
+ setParametersToArray([], 0, itemSize, itemSize, x, y, z)
288
+ );
289
+
290
+ x = geoObject._direction.x;
291
+ y = geoObject._direction.y;
292
+ z = geoObject._direction.z;
293
+ this._directionArr[ti] = concatArrays(
294
+ this._directionArr[ti],
295
+ setParametersToArray([], 0, itemSize, itemSize, x, y, z)
296
+ );
297
+
298
+ itemSize = 4;
299
+
300
+ x = geoObject._color.x;
301
+ y = geoObject._color.y;
302
+ z = geoObject._color.z;
303
+ w = geoObject._color.w;
304
+ this._rgbaArr[ti] = concatArrays(
305
+ this._rgbaArr[ti],
306
+ setParametersToArray([], 0, itemSize, itemSize, x, y, z, w)
307
+ );
308
+
309
+ this._indicesArr[ti] = concatArrays(this._indicesArr[ti], geoObject._indices);
310
+
311
+ x = geoObject._pitch;
312
+ y = geoObject._roll;
313
+
314
+ itemSize = 2;
315
+
316
+ this._pitchRollArr[ti] = concatArrays(
317
+ this._pitchRollArr[ti],
318
+ setParametersToArray([], 0, itemSize, itemSize, x, y)
319
+ );
320
+
321
+ itemSize = 1;
322
+
323
+ this._sizeArr[ti] = concatArrays(
324
+ this._sizeArr[ti],
325
+ setParametersToArray([], 0, itemSize, itemSize, geoObject.scale)
326
+ );
327
+ this._recalculateIndices();
328
+ }
329
+
330
+ _displayPASS() {
331
+ const r = this._renderer,
332
+ sh = r.handler.programs.geo_object,
333
+ p = sh._program,
334
+ u = p.uniforms,
335
+ a = p.attributes,
336
+ gl = r.handler.gl,
337
+ ec = this._entityCollection;
338
+
339
+ sh.activate();
340
+
341
+ gl.enable(gl.CULL_FACE);
342
+ gl.uniform3fv(u.uScaleByDistance, ec.scaleByDistance);
343
+
344
+ gl.uniform3fv(u.eyePositionHigh, r.activeCamera.eyeHigh);
345
+ gl.uniform3fv(u.eyePositionLow, r.activeCamera.eyeLow);
346
+
347
+ gl.uniformMatrix4fv(u.projectionMatrix, false, r.activeCamera.getProjectionMatrix());
348
+ gl.uniformMatrix4fv(u.viewMatrix, false, r.activeCamera.getViewMatrix());
349
+ gl.uniformMatrix3fv(u.normalMatrix, false, r.activeCamera._normalMatrix._m);
350
+
351
+ gl.uniform4fv(u.lightsPositions, this._planet._lightsTransformedPositions);
352
+ gl.uniform3fv(u.lightsParamsv, this._planet._lightsParamsv);
353
+ gl.uniform1fv(u.lightsParamsf, this._planet._lightsParamsf);
354
+
355
+ for (const tag of this._instancedTags) {
356
+ const tagData = tag[1],
357
+ ti = tagData.index;
358
+
359
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._normalsBuffer[ti]);
360
+ gl.vertexAttribPointer(
361
+ a.aVertexNormal,
362
+ this._normalsBuffer[ti].itemSize,
363
+ gl.FLOAT,
364
+ false,
365
+ 0,
366
+ 0
367
+ );
368
+
369
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer[ti]);
370
+ gl.vertexAttribPointer(
371
+ a.aVertexPosition,
372
+ this._vertexBuffer[ti].itemSize,
373
+ gl.FLOAT,
374
+ false,
375
+ 0,
376
+ 0
377
+ );
378
+
379
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._directionBuffer[ti]);
380
+ gl.vertexAttribPointer(
381
+ a.aDirection,
382
+ this._directionBuffer[ti].itemSize,
383
+ gl.FLOAT,
384
+ false,
385
+ 0,
386
+ 0
387
+ );
388
+
389
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._sizeBuffer[ti]);
390
+ gl.vertexAttribPointer(a.aScale, this._sizeBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
391
+
392
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._pitchRollBuffer[ti]);
393
+ gl.vertexAttribPointer(
394
+ a.aPitchRoll,
395
+ this._pitchRollBuffer[ti].itemSize,
396
+ gl.FLOAT,
397
+ false,
398
+ 0,
399
+ 0
400
+ );
401
+
402
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._rgbaBuffer[ti]);
403
+ gl.vertexAttribPointer(a.aColor, this._rgbaBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
404
+
405
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionHighBuffer[ti]);
406
+ gl.vertexAttribPointer(
407
+ a.aPositionHigh,
408
+ this._positionHighBuffer[ti].itemSize,
409
+ gl.FLOAT,
410
+ false,
411
+ 0,
412
+ 0
413
+ );
414
+
415
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionLowBuffer[ti]);
416
+ gl.vertexAttribPointer(
417
+ a.aPositionLow,
418
+ this._positionLowBuffer[ti].itemSize,
419
+ gl.FLOAT,
420
+ false,
421
+ 0,
422
+ 0
423
+ );
424
+
425
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indicesBuffer[ti]);
426
+
427
+ if (tagData.iCounts) {
428
+ gl.drawElementsInstanced(
429
+ gl.TRIANGLES,
430
+ this._indicesBuffer[ti].numItems / tagData.iCounts,
431
+ gl.UNSIGNED_SHORT,
432
+ 0,
433
+ tagData.iCounts
434
+ );
435
+ } else {
436
+ gl.drawElements(
437
+ gl.TRIANGLES,
438
+ this._indicesBuffer[ti].numItems,
439
+ gl.UNSIGNED_SHORT,
440
+ 0
441
+ );
442
+ }
443
+ }
444
+ gl.disable(gl.CULL_FACE);
445
+ }
446
+
447
+ drawPicking() {
448
+ if (this._geoObjects.length && this.pickingEnabled) {
449
+ this._pickingPASS();
450
+ }
451
+ }
452
+
453
+ _pickingPASS() {
454
+ const r = this._renderer,
455
+ sh = r.handler.programs.geo_object_picking,
456
+ p = sh._program,
457
+ u = p.uniforms,
458
+ a = p.attributes,
459
+ gl = r.handler.gl,
460
+ ec = this._entityCollection;
461
+
462
+ sh.activate();
463
+
464
+ gl.enable(gl.CULL_FACE);
465
+ gl.uniform3fv(u.uScaleByDistance, ec.scaleByDistance);
466
+
467
+ gl.uniform1f(u.pickingScale, ec.pickingScale);
468
+
469
+ gl.uniform3fv(u.eyePositionHigh, r.activeCamera.eyeHigh);
470
+ gl.uniform3fv(u.eyePositionLow, r.activeCamera.eyeLow);
471
+
472
+ gl.uniformMatrix4fv(u.projectionMatrix, false, r.activeCamera.getProjectionMatrix());
473
+ gl.uniformMatrix4fv(u.viewMatrix, false, r.activeCamera.getViewMatrix());
474
+
475
+ for (const tag of this._instancedTags) {
476
+ const tagData = tag[1],
477
+ ti = tagData.index;
478
+
479
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer[ti]);
480
+ gl.vertexAttribPointer(
481
+ a.aVertexPosition,
482
+ this._vertexBuffer[ti].itemSize,
483
+ gl.FLOAT,
484
+ false,
485
+ 0,
486
+ 0
487
+ );
488
+
489
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._directionBuffer[ti]);
490
+ gl.vertexAttribPointer(
491
+ a.aDirection,
492
+ this._directionBuffer[ti].itemSize,
493
+ gl.FLOAT,
494
+ false,
495
+ 0,
496
+ 0
497
+ );
498
+
499
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._sizeBuffer[ti]);
500
+ gl.vertexAttribPointer(a.aScale, this._sizeBuffer[ti].itemSize, gl.FLOAT, false, 0, 0);
501
+
502
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._pitchRollBuffer[ti]);
503
+ gl.vertexAttribPointer(
504
+ a.aPitchRoll,
505
+ this._pitchRollBuffer[ti].itemSize,
506
+ gl.FLOAT,
507
+ false,
508
+ 0,
509
+ 0
510
+ );
511
+
512
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._pickingColorBuffer[ti]);
513
+ gl.vertexAttribPointer(
514
+ a.aPickingColor,
515
+ this._pickingColorBuffer[ti].itemSize,
516
+ gl.FLOAT,
517
+ false,
518
+ 0,
519
+ 0
520
+ );
521
+
522
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionHighBuffer[ti]);
523
+ gl.vertexAttribPointer(
524
+ a.aPositionHigh,
525
+ this._positionHighBuffer[ti].itemSize,
526
+ gl.FLOAT,
527
+ false,
528
+ 0,
529
+ 0
530
+ );
531
+
532
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionLowBuffer[ti]);
533
+ gl.vertexAttribPointer(
534
+ a.aPositionLow,
535
+ this._positionLowBuffer[ti].itemSize,
536
+ gl.FLOAT,
537
+ false,
538
+ 0,
539
+ 0
540
+ );
541
+
542
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indicesBuffer[ti]);
543
+
544
+ if (tagData.iCounts) {
545
+ gl.drawElementsInstanced(
546
+ gl.TRIANGLES,
547
+ this._indicesBuffer[ti].numItems / tagData.iCounts,
548
+ gl.UNSIGNED_SHORT,
549
+ 0,
550
+ tagData.iCounts
551
+ );
552
+ } else {
553
+ gl.drawElements(
554
+ gl.TRIANGLES,
555
+ this._indicesBuffer[ti].numItems,
556
+ gl.UNSIGNED_SHORT,
557
+ 0
558
+ );
559
+ }
560
+ }
561
+ gl.disable(gl.CULL_FACE);
562
+ }
563
+
564
+ _recalculateIndices() {
565
+ const allIndices = this._indicesArr,
566
+ goArr = this._geoObjects,
567
+ maxIndicesByTags = new Array(this._instancedTags.size).fill(0);
568
+
569
+ for (let gi = 0; gi < goArr.length; gi++) {
570
+ const go = goArr[gi],
571
+ ti = this.getTagIndexByObjectIndex(go._handlerIndex),
572
+ gIndices = go._indices;
573
+
574
+ for (let ii = 0; ii < gIndices.length; ii++) {
575
+ const gIndex = gIndices[ii];
576
+
577
+ const i = go._indicesCount * go._tagIndex + ii;
578
+ if (go._tagIndex > 0) {
579
+ allIndices[ti][i] = gIndex + maxIndicesByTags[ti];
580
+ if (allIndices[ti][i] > maxIndicesByTags[ti]) {
581
+ maxIndicesByTags[ti] = allIndices[ti][i] + 1;
582
+ }
583
+ } else {
584
+ allIndices[ti][i] = gIndex;
585
+ if (gIndex > maxIndicesByTags[ti]) {
586
+ maxIndicesByTags[ti] = gIndex + 1;
587
+ }
588
+ }
589
+ }
590
+ }
591
+ }
592
+
593
+ //todo refactor for support instancing
594
+ setVertexArr(index, vertexArr) {
595
+ this._vertexArr = [-0.5, 0.0, 0.5, -0.5, 0.0, -0.5, 0.5, 0.0, -0.5, 0.5, 0.0, 0.5];
596
+ this._changedBuffers[VERTEX_BUFFER] = true;
597
+ }
598
+
599
+ setDirectionArr(index, direction) {
600
+ const itemSize = 3,
601
+ ob = this.getObjectByIndex(index),
602
+ ti = this.getTagIndexByObjectIndex(index);
603
+ let length = ob._verticesCount * itemSize;
604
+
605
+ if (ob.instanced) {
606
+ length = itemSize;
607
+ }
608
+
609
+ setParametersToArray(
610
+ this._directionArr[ti],
611
+ ob._tagIndex,
612
+ length,
613
+ itemSize,
614
+ direction.x,
615
+ direction.y,
616
+ direction.z
617
+ );
618
+ this._changedBuffers[DIRECTION_BUFFER] = true;
619
+ }
620
+
621
+ setVisibility(index, visibility) {
622
+ const ob = this.getObjectByIndex(index);
623
+ let vArr;
624
+ if (visibility) {
625
+ vArr = ob._vertices;
626
+ } else {
627
+ vArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
628
+ }
629
+ this.setVertexArr(index, vArr);
630
+ }
631
+
632
+ setPositionArr(index, positionHigh, positionLow) {
633
+ const itemSize = 3,
634
+ ob = this.getObjectByIndex(index),
635
+ ti = this.getTagIndexByObjectIndex(index);
636
+ let length = ob._verticesCount * itemSize;
637
+
638
+ if (ob.instanced) {
639
+ length = itemSize;
640
+ }
641
+
642
+ setParametersToArray(
643
+ this._positionHighArr[ti],
644
+ ob._tagIndex,
645
+ length,
646
+ itemSize,
647
+ positionHigh.x,
648
+ positionHigh.y,
649
+ positionHigh.z
650
+ );
651
+
652
+ // Low
653
+ setParametersToArray(
654
+ this._positionLowArr[ti],
655
+ ob._tagIndex,
656
+ length,
657
+ itemSize,
658
+ positionLow.x,
659
+ positionLow.y,
660
+ positionLow.z
661
+ );
662
+
663
+ this._changedBuffers[POSITION_BUFFER] = true;
664
+ }
665
+
666
+ setRgbaArr(index, rgba) {
667
+ const itemSize = 4,
668
+ ob = this.getObjectByIndex(index),
669
+ ti = this.getTagIndexByObjectIndex(index);
670
+ let length = ob._verticesCount * itemSize;
671
+
672
+ if (ob.instanced) {
673
+ length = itemSize;
674
+ }
675
+
676
+ setParametersToArray(
677
+ this._rgbaArr[ti],
678
+ ob._tagIndex,
679
+ length,
680
+ itemSize,
681
+ rgba.x,
682
+ rgba.y,
683
+ rgba.z,
684
+ rgba.w
685
+ );
686
+
687
+ this._changedBuffers[RGBA_BUFFER] = true;
688
+ }
689
+
690
+ getTagIndexByObjectIndex(index) {
691
+ return this._instancedTags.get(this.getObjectByIndex(index).tag).index;
692
+ }
693
+
694
+ getTagDataByObjectIndex(index) {
695
+ return this._instancedTags.get(this.getObjectByIndex(index).tag);
696
+ }
697
+
698
+ setPickingColorArr(index, color) {
699
+ const itemSize = 3,
700
+ ti = this.getTagIndexByObjectIndex(index),
701
+ ob = this.getObjectByIndex(index),
702
+ x = color.x / 255,
703
+ y = color.y / 255,
704
+ z = color.z / 255;
705
+
706
+ let length = ob._verticesCount * itemSize;
707
+
708
+ if (ob.instanced) {
709
+ length = itemSize;
710
+ }
711
+
712
+ setParametersToArray(this._pickingColorArr[ti], ob._tagIndex, length, itemSize, x, y, z);
713
+ this._changedBuffers[PICKINGCOLOR_BUFFER] = true;
714
+ }
715
+
716
+ setPitchRollArr(index, pitch, roll) {
717
+ const itemSize = 2,
718
+ ti = this.getTagIndexByObjectIndex(index),
719
+ ob = this.getObjectByIndex(index);
720
+ let length = ob._verticesCount * itemSize;
721
+
722
+ if (ob.instanced) {
723
+ length = itemSize;
724
+ }
725
+
726
+ setParametersToArray(this._pitchRollArr[ti], ob._tagIndex, length, itemSize, pitch, roll);
727
+ this._changedBuffers[PITCH_ROLL_BUFFER] = true;
728
+ }
729
+
730
+ setScaleArr(index, scale) {
731
+ const itemSize = 1,
732
+ ti = this.getTagIndexByObjectIndex(index),
733
+ ob = this.getObjectByIndex(index);
734
+ let length = ob._verticesCount * itemSize;
735
+
736
+ if (ob.instanced) {
737
+ length = itemSize;
738
+ }
739
+
740
+ setParametersToArray(this._sizeArr[ti], ob._tagIndex, length, itemSize, scale);
741
+ this._changedBuffers[SIZE_BUFFER] = true;
742
+ }
743
+
744
+ refresh() {
745
+ let i = this._changedBuffers.length;
746
+ while (i--) {
747
+ this._changedBuffers[i] = true;
748
+ }
749
+ }
750
+
751
+ _removeGeoObjects() {
752
+ let i = this._geoObjects.length;
753
+ while (i--) {
754
+ const bi = this._geoObjects[i];
755
+ bi._handlerIndex = -1;
756
+ bi._handler = null;
757
+ }
758
+ this._geoObjects.length = 0;
759
+ this._geoObjects = [];
760
+ }
761
+
762
+ clear() {
763
+ this._sizeArr = null;
764
+ this._pitchRollArr = null;
765
+ this._vertexArr = null;
766
+ this._positionHighArr = null;
767
+ this._positionLowArr = null;
768
+ this._directionArr = null;
769
+ this._rgbaArr = null;
770
+ this._normalsArr = null;
771
+ this._indicesArr = null;
772
+ this._pickingColorArr = null;
773
+
774
+ this._pitchRollArr = new Float32Array();
775
+ this._sizeArr = new Float32Array();
776
+ this._vertexArr = new Float32Array();
777
+ this._positionHighArr = new Float32Array();
778
+ this._positionLowArr = new Float32Array();
779
+ this._rgbaArr = new Float32Array();
780
+ this._directionArr = new Float32Array();
781
+ this._normalsArr = new Float32Array();
782
+ this._indicesArr = new Uint16Array();
783
+ this._pickingColorArr = new Float32Array();
784
+
785
+ this._removeGeoObjects();
786
+ this._deleteBuffers();
787
+ this.refresh();
788
+ }
789
+
790
+ _deleteBuffers() {
791
+ if (this._renderer) {
792
+ const gl = this._renderer.handler.gl;
793
+ gl.deleteBuffer(this._sizeBuffer);
794
+ gl.deleteBuffer(this._pitchRollBuffer);
795
+ gl.deleteBuffer(this._vertexBuffer);
796
+ gl.deleteBuffer(this._positionHighBuffer);
797
+ gl.deleteBuffer(this._positionLowBuffer);
798
+ gl.deleteBuffer(this._rgbaBuffer);
799
+ gl.deleteBuffer(this._indicesBuffer);
800
+ gl.deleteBuffer(this._normalsBuffer);
801
+ gl.deleteBuffer(this._directionBuffer);
802
+ gl.deleteBuffer(this._pickingColorBuffer);
803
+ }
804
+
805
+ this._pitchRollBuffer = null;
806
+ this._sizeBuffer = null;
807
+ this._vertexBuffer = null;
808
+ this._positionHighBuffer = null;
809
+ this._positionLowBuffer = null;
810
+ this._rgbaBuffer = null;
811
+ this._indicesBuffer = null;
812
+ this._normalsBuffer = null;
813
+ this._directionBuffer = null;
814
+ this._pickingColorBuffer = null;
815
+ }
816
+
817
+ update() {
818
+ if (this._renderer) {
819
+ let i = this._changedBuffers.length;
820
+ while (i--) {
821
+ if (this._changedBuffers[i]) {
822
+ this._buffersUpdateCallbacks[i].call(this);
823
+ this._changedBuffers[i] = false;
824
+ }
825
+ }
826
+ }
827
+ }
828
+
829
+ draw() {
830
+ if (this._geoObjects.length) {
831
+ this.update();
832
+ this._displayPASS();
833
+ }
834
+ }
835
+
836
+ _reindexGeoObjects(startIndex, tag) {
837
+ const b = this._geoObjects;
838
+
839
+ for (let i = startIndex; i < b.length; i++) {
840
+ const go = b[i];
841
+
842
+ b[i]._handlerIndex = i;
843
+ if (tag === go.tag) {
844
+ --b[i]._tagIndex;
845
+ }
846
+ }
847
+ }
848
+
849
+ add(geoObject) {
850
+ if (geoObject._handlerIndex === -1) {
851
+ geoObject._handler = this;
852
+ geoObject._handlerIndex = this._geoObjects.length;
853
+ this._geoObjects.push(geoObject);
854
+ this._addGeoObjectToArray(geoObject);
855
+ this.refresh();
856
+ }
857
+ }
858
+
859
+ remove(geoObject) {
860
+ if (geoObject._handler && this.__staticId == geoObject._handler.__staticId) {
861
+ this._removeGeoObject(geoObject);
862
+ }
863
+ }
864
+
865
+ _removeGeoObject(geoObject) {
866
+ const gi = geoObject._handlerIndex,
867
+ tag = geoObject.tag,
868
+ ti = this.getTagIndexByObjectIndex(gi),
869
+ prevState = this._instancedTags.get(tag);
870
+
871
+ this._instancedTags.set(tag, {
872
+ iCounts: prevState.iCounts - 1,
873
+ index: prevState.index
874
+ });
875
+
876
+ this._geoObjects.splice(gi, 1);
877
+
878
+ let i = gi * 4;
879
+ this._rgbaArr[ti] = spliceArray(this._rgbaArr[ti], i, 4);
880
+
881
+ i = gi * 3;
882
+ if (prevState.iCounts <= 1) {
883
+ this._vertexArr[ti] = spliceArray(this._vertexArr[ti], 0, geoObject._verticesCount * 3);
884
+ this._normalsArr[ti] = spliceArray(
885
+ this._normalsArr[ti],
886
+ 0,
887
+ geoObject._verticesCount * 3
888
+ );
889
+ }
890
+ this._positionHighArr[ti] = spliceArray(this._positionHighArr[ti], i, 3);
891
+ this._positionLowArr[ti] = spliceArray(this._positionLowArr[ti], i, 3);
892
+ this._directionArr[ti] = spliceArray(this._directionArr[ti], i, 3);
893
+ this._pickingColorArr[ti] = spliceArray(this._pickingColorArr[ti], i, 3);
894
+
895
+ i = gi * 2;
896
+ this._pitchRollArr[ti] = spliceArray(this._pitchRollArr[ti], i, 2);
897
+ this._indicesArr[ti] = spliceArray(this._indicesArr[ti], i, geoObject._indicesCount);
898
+ i = gi * 1;
899
+ this._sizeArr[ti] = spliceArray(this._sizeArr[ti], i, 1);
900
+
901
+ this._reindexGeoObjects(gi, tag);
902
+ this._recalculateIndices();
903
+ this.refresh();
904
+
905
+ geoObject._handlerIndex = -1;
906
+ geoObject._handler = null;
907
+ }
908
+ }
909
+
910
+ export { GeoObjectHandler };