@openglobus/og 0.11.1 → 0.11.6

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 (255) hide show
  1. package/package.json +18 -20
  2. package/src/og/Clock.js +11 -11
  3. package/src/og/Deferred.js +1 -1
  4. package/src/og/Events.js +9 -7
  5. package/src/og/Extent.js +117 -72
  6. package/src/og/Globe.js +35 -22
  7. package/src/og/ImageCanvas.js +24 -18
  8. package/src/og/Lock.js +2 -2
  9. package/src/og/LonLat.js +40 -37
  10. package/src/og/Popup.js +21 -15
  11. package/src/og/QueueArray.js +7 -3
  12. package/src/og/Rectangle.js +11 -6
  13. package/src/og/Stack.js +8 -5
  14. package/src/og/ajax.js +21 -33
  15. package/src/og/astro/astro.js +5 -5
  16. package/src/og/astro/earth.js +23 -17
  17. package/src/og/astro/jd.js +44 -39
  18. package/src/og/astro/orbit.js +20 -18
  19. package/src/og/astro/rotation.js +17 -8
  20. package/src/og/bv/Box.js +7 -3
  21. package/src/og/bv/Sphere.js +17 -9
  22. package/src/og/camera/Camera.js +137 -86
  23. package/src/og/camera/Frustum.js +30 -19
  24. package/src/og/camera/PlanetCamera.js +30 -26
  25. package/src/og/control/CompassButton.js +8 -2
  26. package/src/og/control/Control.js +13 -11
  27. package/src/og/control/DebugInfo.js +4 -1
  28. package/src/og/control/EarthCoordinates.js +62 -41
  29. package/src/og/control/EarthNavigation.js +20 -22
  30. package/src/og/control/GeoImageDragControl.js +1 -1
  31. package/src/og/control/KeyboardNavigation.js +12 -12
  32. package/src/og/control/LayerSwitcher.js +24 -23
  33. package/src/og/control/Lighting.js +1 -1
  34. package/src/og/control/MouseNavigation.js +1 -1
  35. package/src/og/control/ScaleControl.js +1 -1
  36. package/src/og/control/SegmentBoundVisualization.js +8 -9
  37. package/src/og/control/ShowFps.js +15 -10
  38. package/src/og/control/SimpleNavigation.js +8 -10
  39. package/src/og/control/Sun.js +25 -15
  40. package/src/og/control/ToggleWireframe.js +5 -5
  41. package/src/og/control/TouchNavigation.js +58 -45
  42. package/src/og/control/ZoomControl.js +41 -25
  43. package/src/og/control/index.js +4 -0
  44. package/src/og/ellipsoid/Ellipsoid.js +181 -85
  45. package/src/og/ellipsoid/wgs84.js +4 -4
  46. package/src/og/entity/BaseBillboard.js +97 -44
  47. package/src/og/entity/Billboard.js +15 -11
  48. package/src/og/entity/BillboardHandler.js +314 -64
  49. package/src/og/entity/Entity.js +106 -74
  50. package/src/og/entity/EntityCollection.js +72 -49
  51. package/src/og/entity/GeoObject.js +228 -0
  52. package/src/og/entity/GeoObjectHandler.js +910 -0
  53. package/src/og/entity/Geometry.js +29 -26
  54. package/src/og/entity/GeometryHandler.js +598 -126
  55. package/src/og/entity/Label.js +74 -40
  56. package/src/og/entity/LabelHandler.js +47 -246
  57. package/src/og/entity/LabelWorker.js +213 -0
  58. package/src/og/entity/Object3d.js +504 -0
  59. package/src/og/entity/PointCloud.js +81 -33
  60. package/src/og/entity/PointCloudHandler.js +9 -9
  61. package/src/og/entity/Polyline.js +39 -39
  62. package/src/og/entity/Ray.js +61 -28
  63. package/src/og/entity/ShapeHandler.js +1 -1
  64. package/src/og/entity/Strip.js +77 -48
  65. package/src/og/entity/StripHandler.js +27 -27
  66. package/src/og/entity/index.js +8 -16
  67. package/src/og/input/KeyboardHandler.js +107 -104
  68. package/src/og/input/MouseHandler.js +81 -78
  69. package/src/og/input/TouchHandler.js +55 -51
  70. package/src/og/layer/BaseGeoImage.js +61 -30
  71. package/src/og/layer/CanvasTiles.js +26 -24
  72. package/src/og/layer/GeoImage.js +10 -10
  73. package/src/og/layer/GeoTexture2d.js +1 -1
  74. package/src/og/layer/GeoVideo.js +3 -3
  75. package/src/og/layer/KML.js +66 -40
  76. package/src/og/layer/Layer.js +27 -17
  77. package/src/og/layer/Material.js +93 -61
  78. package/src/og/layer/Vector.js +118 -72
  79. package/src/og/layer/WMS.js +36 -19
  80. package/src/og/layer/XYZ.js +55 -48
  81. package/src/og/light/LightSource.js +47 -40
  82. package/src/og/math/Line2.js +24 -24
  83. package/src/og/math/Line3.js +103 -102
  84. package/src/og/math/Mat3.js +134 -121
  85. package/src/og/math/Mat4.js +603 -459
  86. package/src/og/math/Plane.js +21 -20
  87. package/src/og/math/Quat.js +980 -927
  88. package/src/og/math/Ray.js +195 -187
  89. package/src/og/math/Vec2.js +127 -117
  90. package/src/og/math/Vec3.js +206 -176
  91. package/src/og/math/Vec4.js +49 -53
  92. package/src/og/math/coder.js +18 -18
  93. package/src/og/math.js +12 -12
  94. package/src/og/mercator.js +11 -11
  95. package/src/og/proj/EPSG3857.js +4 -4
  96. package/src/og/proj/EPSG4326.js +4 -4
  97. package/src/og/proj/Proj.js +31 -31
  98. package/src/og/quadTree/EntityCollectionNode.js +310 -300
  99. package/src/og/quadTree/Node.js +1008 -993
  100. package/src/og/renderer/Renderer.js +768 -747
  101. package/src/og/renderer/RendererEvents.js +9 -6
  102. package/src/og/scene/Axes.js +1 -1
  103. package/src/og/scene/BaseNode.js +8 -9
  104. package/src/og/scene/Planet.js +115 -87
  105. package/src/og/scene/RenderNode.js +29 -22
  106. package/src/og/scene/SkyBox.js +1 -1
  107. package/src/og/segment/Segment.js +1886 -1878
  108. package/src/og/segment/SegmentLonLat.js +298 -268
  109. package/src/og/segment/segmentHelper.js +11 -11
  110. package/src/og/shaders/bloom.js +1 -1
  111. package/src/og/shaders/blur.js +2 -2
  112. package/src/og/shaders/depth.js +1 -1
  113. package/src/og/shaders/geoObject.js +211 -0
  114. package/src/og/shaders/label.js +1 -1
  115. package/src/og/shaders/lumFilter.js +1 -1
  116. package/src/og/shaders/pointCloud.js +42 -42
  117. package/src/og/shaders/screenFrame.js +1 -1
  118. package/src/og/shaders/shape.js +15 -21
  119. package/src/og/shaders/skybox.js +37 -37
  120. package/src/og/shaders/toneMapping.js +1 -1
  121. package/src/og/shapes/BaseShape.js +129 -57
  122. package/src/og/shapes/Icosphere.js +30 -15
  123. package/src/og/shapes/Sphere.js +13 -16
  124. package/src/og/terrain/BilTerrain.js +2 -1
  125. package/src/og/terrain/EmptyTerrain.js +2 -2
  126. package/src/og/terrain/Geoid.js +2 -2
  127. package/src/og/terrain/GlobusTerrain.js +10 -10
  128. package/src/og/terrain/MapboxTerrain.js +1 -1
  129. package/src/og/utils/GeoImageCreator.js +9 -9
  130. package/src/og/utils/Loader.js +6 -6
  131. package/src/og/utils/NormalMapCreator.js +13 -13
  132. package/src/og/utils/TerrainWorker.js +1 -1
  133. package/src/og/utils/TextureAtlas.js +20 -22
  134. package/src/og/utils/VectorTileCreator.js +5 -5
  135. package/src/og/utils/earcut.js +1 -1
  136. package/src/og/utils/shared.js +15 -15
  137. package/src/og/webgl/Framebuffer.js +101 -53
  138. package/src/og/webgl/Handler.js +125 -85
  139. package/src/og/webgl/Multisample.js +55 -27
  140. package/src/og/webgl/Program.js +80 -35
  141. package/src/og/webgl/ProgramController.js +27 -23
  142. package/src/og/webgl/callbacks.js +8 -8
  143. package/types/Clock.d.ts +6 -2
  144. package/types/Deferred.d.ts +1 -1
  145. package/types/Events.d.ts +8 -4
  146. package/types/Extent.d.ts +37 -33
  147. package/types/Globe.d.ts +15 -13
  148. package/types/ImageCanvas.d.ts +5 -3
  149. package/types/LonLat.d.ts +24 -24
  150. package/types/Popup.d.ts +4 -0
  151. package/types/QueueArray.d.ts +6 -2
  152. package/types/Rectangle.d.ts +10 -4
  153. package/types/Stack.d.ts +4 -0
  154. package/types/ajax.d.ts +1 -1
  155. package/types/astro/earth.d.ts +3 -2
  156. package/types/bv/Box.d.ts +10 -5
  157. package/types/bv/Sphere.d.ts +13 -7
  158. package/types/camera/Camera.d.ts +90 -81
  159. package/types/camera/Frustum.d.ts +26 -22
  160. package/types/camera/PlanetCamera.d.ts +49 -53
  161. package/types/control/CompassButton.d.ts +4 -4
  162. package/types/control/Control.d.ts +7 -4
  163. package/types/control/DebugInfo.d.ts +3 -4
  164. package/types/control/EarthCoordinates.d.ts +6 -6
  165. package/types/control/EarthNavigation.d.ts +42 -0
  166. package/types/control/KeyboardNavigation.d.ts +3 -4
  167. package/types/control/LayerSwitcher.d.ts +3 -5
  168. package/types/control/Lighting.d.ts +3 -3
  169. package/types/control/MouseNavigation.d.ts +47 -0
  170. package/types/control/ScaleControl.d.ts +3 -3
  171. package/types/control/ShowFps.d.ts +3 -4
  172. package/types/control/SimpleNavigation.d.ts +3 -6
  173. package/types/control/Sun.d.ts +8 -10
  174. package/types/control/ToggleWireframe.d.ts +3 -3
  175. package/types/control/TouchNavigation.d.ts +48 -0
  176. package/types/control/ZoomControl.d.ts +3 -4
  177. package/types/control/index.d.ts +3 -1
  178. package/types/ellipsoid/Ellipsoid.d.ts +47 -43
  179. package/types/ellipsoid/wgs84.d.ts +3 -2
  180. package/types/entity/BaseBillboard.d.ts +41 -34
  181. package/types/entity/Billboard.d.ts +7 -7
  182. package/types/entity/BillboardHandler.d.ts +4 -0
  183. package/types/entity/Entity.d.ts +101 -83
  184. package/types/entity/EntityCollection.d.ts +57 -43
  185. package/types/entity/GeoObject.d.ts +111 -0
  186. package/types/entity/GeoObjectHandler.d.ts +77 -0
  187. package/types/entity/Geometry.d.ts +9 -7
  188. package/types/entity/GeometryHandler.d.ts +2 -2
  189. package/types/entity/Label.d.ts +24 -29
  190. package/types/entity/LabelHandler.d.ts +9 -2
  191. package/types/entity/LabelWorker.d.ts +9 -0
  192. package/types/entity/PointCloud.d.ts +8 -8
  193. package/types/entity/PointCloudHandler.d.ts +3 -3
  194. package/types/entity/Polyline.d.ts +58 -55
  195. package/types/entity/Ray.d.ts +19 -18
  196. package/types/entity/Strip.d.ts +8 -7
  197. package/types/entity/StripHandler.d.ts +3 -3
  198. package/types/entity/index.d.ts +7 -7
  199. package/types/input/KeyboardHandler.d.ts +10 -0
  200. package/types/input/MouseHandler.d.ts +5 -0
  201. package/types/input/TouchHandler.d.ts +5 -0
  202. package/types/layer/BaseGeoImage.d.ts +23 -35
  203. package/types/layer/CanvasTiles.d.ts +15 -22
  204. package/types/layer/GeoImage.d.ts +5 -18
  205. package/types/layer/GeoVideo.d.ts +5 -30
  206. package/types/layer/KML.d.ts +20 -15
  207. package/types/layer/Layer.d.ts +326 -0
  208. package/types/layer/Material.d.ts +45 -0
  209. package/types/layer/Vector.d.ts +208 -0
  210. package/types/layer/WMS.d.ts +4 -7
  211. package/types/layer/XYZ.d.ts +19 -25
  212. package/types/light/LightSource.d.ts +54 -53
  213. package/types/math/Line2.d.ts +11 -0
  214. package/types/math/Line3.d.ts +10 -0
  215. package/types/math/Mat3.d.ts +30 -18
  216. package/types/math/Mat4.d.ts +71 -52
  217. package/types/math/Plane.d.ts +5 -4
  218. package/types/math/Quat.d.ts +379 -0
  219. package/types/math/Ray.d.ts +82 -0
  220. package/types/math/Vec2.d.ts +102 -101
  221. package/types/math/Vec3.d.ts +143 -142
  222. package/types/math/Vec4.d.ts +40 -39
  223. package/types/math/coder.d.ts +12 -11
  224. package/types/math.d.ts +8 -8
  225. package/types/mercator.d.ts +3 -3
  226. package/types/proj/EPSG3857.d.ts +3 -2
  227. package/types/proj/EPSG4326.d.ts +3 -2
  228. package/types/proj/Proj.d.ts +42 -0
  229. package/types/quadTree/EntityCollectionNode.d.ts +34 -0
  230. package/types/quadTree/Node.d.ts +61 -0
  231. package/types/renderer/Renderer.d.ts +300 -0
  232. package/types/renderer/RendererEvents.d.ts +10 -7
  233. package/types/scene/BaseNode.d.ts +9 -9
  234. package/types/scene/Planet.d.ts +131 -126
  235. package/types/scene/RenderNode.d.ts +22 -23
  236. package/types/segment/Segment.d.ts +279 -0
  237. package/types/segment/SegmentLonLat.d.ts +16 -0
  238. package/types/shaders/geoObject.d.ts +3 -0
  239. package/types/shapes/BaseShape.d.ts +43 -40
  240. package/types/shapes/Sphere.d.ts +7 -7
  241. package/types/terrain/BilTerrain.d.ts +0 -1
  242. package/types/terrain/EmptyTerrain.d.ts +4 -4
  243. package/types/terrain/GlobusTerrain.d.ts +17 -54
  244. package/types/terrain/MapboxTerrain.d.ts +0 -1
  245. package/types/utils/GeoImageCreator.d.ts +3 -2
  246. package/types/utils/TextureAtlas.d.ts +8 -8
  247. package/types/utils/shared.d.ts +25 -24
  248. package/types/webgl/Framebuffer.d.ts +5 -5
  249. package/types/webgl/Handler.d.ts +68 -43
  250. package/types/webgl/Multisample.d.ts +5 -5
  251. package/types/webgl/Program.d.ts +8 -2
  252. package/types/webgl/ProgramController.d.ts +18 -13
  253. package/src/og/inherits.js +0 -8
  254. package/src/og/utils/polylabel.js +0 -176
  255. package/types/inherits.d.ts +0 -4
@@ -1,1878 +1,1886 @@
1
- "use strict";
2
-
3
- import * as mercator from "../mercator.js";
4
- import { N, E, S, W, OPSIDE, NOTRENDERING } from "../quadTree/quadTree.js";
5
- import { EPSG3857 } from "../proj/EPSG3857.js";
6
- import { Extent } from "../Extent.js";
7
- import { Layer } from "../layer/Layer.js";
8
- import { LonLat } from "../LonLat.js";
9
- import { Ray } from "../math/Ray.js";
10
- import { Sphere } from "../bv/Sphere.js";
11
- import { Box } from "../bv/Box.js";
12
- import { Vec3 } from "../math/Vec3.js";
13
- import * as segmentHelper from "../segment/segmentHelper.js";
14
-
15
- export const MAX_NORMAL_ZOOM = 7;
16
-
17
- var _tempHigh = new Vec3();
18
- var _tempLow = new Vec3();
19
-
20
- var _RenderingSlice = function (p) {
21
- this.layers = [];
22
- this.tileOffsetArr = new Float32Array(p.SLICE_SIZE_4);
23
- this.visibleExtentOffsetArr = new Float32Array(p.SLICE_SIZE_4);
24
- this.transparentColorArr = new Float32Array(p.SLICE_SIZE_4);
25
-
26
- this.clear = function () {
27
- this.layers = null;
28
- this.tileOffsetArr = null;
29
- this.visibleExtentOffsetArr = null;
30
- this.transparentColorArr = null;
31
- };
32
- };
33
-
34
- /**
35
- * Planet segment Web Mercator tile class that stored and rendered with quad tree.
36
- * @class
37
- * @param {og.quadTree.Node} node - Segment node.
38
- * @param {og.scene.Planet} planet - Current planet scene.
39
- * @param {Number} tileZoom - Zoom index.
40
- * @param {og.Extent} extent - Segment extent.
41
- */
42
- const Segment = function (node, planet, tileZoom, extent) {
43
- this.isPole = false;
44
-
45
- this._tileGroup = 0;
46
-
47
- this._projection = EPSG3857;
48
-
49
- /**
50
- * Quad tree node of the segment.
51
- * @type {og.quadTree.Node}
52
- */
53
- this.node = node;
54
-
55
- /**
56
- * Planet pointer.
57
- * @type {og.scene.Planet}
58
- */
59
- this.planet = planet;
60
-
61
- /**
62
- * WebGl handler pointer.
63
- * @type {og.webgl.Handler}
64
- */
65
- this.handler = planet.renderer.handler;
66
-
67
- /**
68
- * Segment bounding sphere
69
- * @type {og.bv.Sphere}
70
- */
71
- this.bsphere = new Sphere();
72
-
73
- this._plainRadius = 0;
74
-
75
- /**
76
- * Segment bounding box.
77
- * @type {og.bv.Box}
78
- */
79
- this.bbox = new Box();
80
-
81
- this._swNorm = null;
82
- this._nwNorm = null;
83
- this._seNorm = null;
84
- this._neNorm = null;
85
-
86
- /**
87
- * Geographical extent.
88
- * @type {og.Extent}
89
- */
90
- this._extent = extent;
91
-
92
- this._extentLonLat = null;
93
-
94
- /**
95
- * Vertices grid size.
96
- * @type {number}
97
- */
98
- this.gridSize = planet.terrain.gridSizeByZoom[tileZoom];
99
-
100
- this.fileGridSize = 0;
101
-
102
- /**
103
- * Tile zoom index.
104
- * @type {number}
105
- */
106
- this.tileZoom = tileZoom;
107
-
108
- /**
109
- * Horizontal tile index.
110
- * @type {number}
111
- */
112
- this.tileX = 0;
113
-
114
- this.tileXE = 0;
115
-
116
- this.tileXW = 0;
117
-
118
- this.tileYN = 0;
119
-
120
- this.tileYS = 0;
121
-
122
- /**
123
- * Vertical tile index.
124
- * @type {number}
125
- */
126
- this.tileY = 0;
127
-
128
- this.tileIndex = "";
129
-
130
- this._assignTileIndexes();
131
-
132
- /**
133
- * Texture materials array.
134
- * @type {Array.<og.planetSegment.Material>}
135
- */
136
- this.materials = [];
137
-
138
- /**
139
- * Plain segment vertices was created.
140
- * @type {boolean}
141
- */
142
- this.plainReady = false;
143
-
144
- /**
145
- * Segment is ready to create plain vertices.
146
- * @type {boolean}
147
- */
148
- this.initialized = false;
149
-
150
- /**
151
- * Normal map is allready made.
152
- * @type {boolean}
153
- */
154
- this.normalMapReady = false;
155
-
156
- /**
157
- * Parent normal map is made allready(optimization parameter).
158
- * @type {boolean}
159
- */
160
- this.parentNormalMapReady = false;
161
-
162
- /**
163
- * Terrain is allready applied flag.
164
- * @type {boolean}
165
- */
166
- this.terrainReady = false;
167
-
168
- /**
169
- * Terrain is loading now flag.
170
- * @type {boolean}
171
- */
172
- this.terrainIsLoading = false;
173
-
174
- /**
175
- * Terrain existing flag.
176
- * @type {boolean}
177
- */
178
- this.terrainExists = false;
179
-
180
- this.plainVertices = null;
181
- this.plainVerticesHigh = null;
182
- this.plainVerticesLow = null;
183
-
184
- this.plainNormals = null;
185
-
186
- this.terrainVertices = null;
187
- this.terrainVerticesHigh = null;
188
- this.terrainVerticesLow = null;
189
- this.noDataVertices = null;
190
-
191
- this.tempVertices = null;
192
- this.tempVerticesHigh = null;
193
- this.tempVerticesLow = null;
194
-
195
- this.normalMapTexture = null;
196
- this.normalMapTextureBias = new Float32Array(3);
197
- this.normalMapVertices = null;
198
- this.normalMapVerticesHigh = null;
199
- this.normalMapVerticesLow = null;
200
- this.normalMapNormals = null;
201
-
202
- this.vertexNormalBuffer = null;
203
- this.vertexPositionBuffer = null;
204
- this.vertexPositionBufferHigh = null;
205
- this.vertexPositionBufferLow = null;
206
- this.vertexTextureCoordBuffer = null;
207
-
208
- this._globalTextureCoordinates = new Float32Array(4);
209
- this._inTheQueue = false;
210
- this._appliedNeighborsZoom = [0, 0, 0, 0];
211
-
212
- this._renderingSlices = [];
213
-
214
- this._indexBuffer = null;
215
-
216
- this.readyToEngage = false;
217
-
218
- this.plainProcessing = false;
219
- };
220
-
221
- /**
222
- * Returns that segment good for rendering with camera by current lod ratio.
223
- * @public
224
- * @param {og.Camera} camera - Camera object.
225
- * @returns {boolean} -
226
- */
227
- Segment.prototype.acceptForRendering = function (camera) {
228
- return (
229
- camera.projectedSize(this.bsphere.center, this._plainRadius) < 256 / this.planet._lodRatio
230
- );
231
- };
232
-
233
- /**
234
- * Returns entity terrain point.
235
- * @public
236
- * @param {og.Entity} entity - Entity.
237
- * @param {og.Vec3} res - Point coordinates.
238
- * @param {og.Vec3} [normal] - Terrain point normal.
239
- * @returns {og.Vec3} -
240
- */
241
- Segment.prototype.getEntityTerrainPoint = function (entity, res, normal) {
242
- return this.getTerrainPoint(entity._cartesian, entity._lonlatMerc, res, normal);
243
- };
244
-
245
- Segment.prototype.isEntityInside = function (e) {
246
- return this._extent.isInside(e._lonlatMerc);
247
- };
248
-
249
- let _v0 = new Vec3(),
250
- _v1 = new Vec3(),
251
- _v2 = new Vec3(),
252
- _v3 = new Vec3();
253
-
254
- let _ray = new Ray(),
255
- _rayEx = new Ray();
256
-
257
- window.ELLNORM = false;
258
- /**
259
- * Returns distance from object to terrain coordinates and terrain point that calculates out in the res parameter.
260
- * @public
261
- * @param {og.Vec3} xyz - Cartesian object position.
262
- * @param {og.LonLat} insideSegmentPosition - Geodetic object position.
263
- * @param {og.Vec3} [res] - Result cartesian coordiantes on the terrain.
264
- * @param {og.Vec3} [normal] - Terrain point normal.
265
- * @returns {number} -
266
- */
267
- Segment.prototype.getTerrainPoint = function (xyz, insideSegmentPosition, res, normal) {
268
- var verts = this.tempVertices;
269
-
270
- _ray.set(xyz, xyz.negateTo());
271
-
272
- if (verts) {
273
- var ne = this._extent.northEast,
274
- sw = this._extent.southWest,
275
- size = Math.sqrt(verts.length / 3) - 1;
276
-
277
- var xmax = ne.lon,
278
- ymax = ne.lat,
279
- xmin = sw.lon,
280
- ymin = sw.lat,
281
- x = insideSegmentPosition.lon,
282
- y = insideSegmentPosition.lat;
283
-
284
- var sxn = xmax - xmin,
285
- syn = ymax - ymin;
286
-
287
- var qx = sxn / size,
288
- qy = syn / size;
289
-
290
- var xn = x - xmin,
291
- yn = y - ymin;
292
-
293
- var indX = Math.floor(xn / qx),
294
- indY = Math.floor(size - yn / qy);
295
-
296
- if (verts && verts.length) {
297
- var ind_v0 = ((size + 1) * indY + indX) * 3;
298
- var ind_v2 = ((size + 1) * (indY + 1) + indX) * 3;
299
-
300
- _v0.set(verts[ind_v0], verts[ind_v0 + 1], verts[ind_v0 + 2]);
301
- _v1.set(verts[ind_v0 + 3], verts[ind_v0 + 4], verts[ind_v0 + 5]);
302
- _v2.set(verts[ind_v2], verts[ind_v2 + 1], verts[ind_v2 + 2]);
303
-
304
- let d = _ray.hitTriangle(_v0, _v1, _v2, res, normal);
305
-
306
- if (d === Ray.INSIDE) {
307
- return xyz.distance(res);
308
- } else if (d === Ray.AWAY) {
309
- _rayEx.set(xyz, xyz);
310
- let d = _rayEx.hitTriangle(_v0, _v1, _v2, res, normal);
311
- if (d === Ray.INSIDE) {
312
- return -xyz.distance(res);
313
- }
314
- }
315
-
316
- _v3.set(verts[ind_v2 + 3], verts[ind_v2 + 4], verts[ind_v2 + 5]);
317
-
318
- d = _ray.hitTriangle(_v1, _v3, _v2, res, normal);
319
- if (d === Ray.INSIDE) {
320
- return xyz.distance(res);
321
- } else if (d === Ray.AWAY) {
322
- _rayEx.set(xyz, xyz);
323
- let d = _rayEx.hitTriangle(_v1, _v3, _v2, res, normal);
324
- if (d === Ray.INSIDE) {
325
- return -xyz.distance(res);
326
- }
327
- }
328
-
329
- if (d === Ray.AWAY) {
330
- return -xyz.distance(res);
331
- }
332
-
333
- return xyz.distance(res);
334
- }
335
-
336
- res.copy(this.planet.ellipsoid.hitRay(_ray.origin, _ray.direction));
337
- normal && normal.copy(xyz.normal());
338
- return xyz.distance(res);
339
- } else {
340
- normal && normal.copy(xyz.normal());
341
- return xyz.distance(this.planet.ellipsoid.hitRay(_ray.origin, _ray.direction));
342
- }
343
- };
344
-
345
- /**
346
- * Project wgs86 to segment native projection.
347
- * @public
348
- * @param {og.LonLat} lonlat - Coordinates to project.
349
- * @returns {og.LonLat} -
350
- */
351
- Segment.prototype.projectNative = function (lonlat) {
352
- return lonlat.forwardMercator();
353
- };
354
-
355
- Segment.prototype.loadTerrain = function (forceLoading) {
356
- if (this.tileZoom < this.planet.terrain.minZoom) {
357
- this.terrainIsLoading = true;
358
-
359
- this.elevationsNotExists();
360
-
361
- if (!this._inTheQueue) {
362
- this.planet._normalMapCreator.queue(this);
363
- }
364
- } else {
365
- if (this.tileZoom > this.planet.terrain.maxZoom) {
366
- this.elevationsNotExists();
367
- } else if (!this.terrainIsLoading && !this.terrainReady) {
368
- this.planet.terrain.loadTerrain(this, forceLoading);
369
- }
370
- }
371
- };
372
-
373
- /**
374
- * Terrain obtained from server.
375
- * @param {Float32Array} elevations - Elevation data.
376
- */
377
- Segment.prototype.elevationsExists = function (elevations) {
378
- if (this.plainReady && this.terrainIsLoading) {
379
- this.planet._terrainWorker.make(this, elevations);
380
-
381
- this.plainVerticesHigh = null;
382
- this.plainVerticesLow = null;
383
-
384
- this.normalMapVerticesHigh = null;
385
- this.normalMapVerticesLow = null;
386
-
387
- if (!this.planet.terrain.equalizeVertices) {
388
- this.tempVerticesHigh = null;
389
- this.tempVerticesLow = null;
390
- }
391
- }
392
- };
393
-
394
- Segment.prototype._checkEqualization = function (neighborSide, neigborNode) {
395
- return (
396
- neigborNode && this.tileZoom >= neigborNode.segment.tileZoom
397
-
398
- //&&
399
- //(
400
- // this.node.equalizedNeighborId[neighborSide] !== neigborNode.appliedTerrainNodeId ||
401
- // this.node.equalizedNeighborGridSize[neighborSide] !== neigborNode.segment.gridSize
402
- //||
403
-
404
- // neigborNode.equalizedNeighborId[OPSIDE[neighborSide]] !== this.node.appliedTerrainNodeId ||
405
- // neigborNode.equalizedNeighborGridSize[OPSIDE[neighborSide]] !== this.gridSize
406
- //)
407
- );
408
- };
409
-
410
- Segment.prototype.equalize = function () {
411
- if (this.tileZoom < 8 || this.gridSize < 2) {
412
- return;
413
- }
414
-
415
- this.readyToEngage = true;
416
- let nn = this.node.neighbors;
417
- let v = this.tempVertices,
418
- vHigh = this.tempVerticesHigh,
419
- vLow = this.tempVerticesLow;
420
- let gs = this.gridSize,
421
- gsOne = gs + 1;
422
-
423
- let n = nn[N][0];
424
- if (this._checkEqualization(N, n)) {
425
- //this.node.equalizedNeighborId[N] = n.appliedTerrainNodeId;
426
- //this.node.equalizedNeighborGridSize[N] = n.segment.gridSize;
427
-
428
- //n.equalizedNeighborId[OPSIDE[N]] = this.node.appliedTerrainNodeId;
429
- //n.equalizedNeighborGridSize[OPSIDE[N]] = this.gridSize;
430
-
431
- this.readyToEngage = true;
432
-
433
- let offset = this.node.getOffsetOppositeNeighbourSide(n, N);
434
-
435
- let nv = n.segment.tempVertices,
436
- nvHigh = n.segment.tempVerticesHigh,
437
- nvLow = n.segment.tempVerticesLow;
438
-
439
- let n_gs = n.segment.gridSize,
440
- n_gsOne = n_gs + 1;
441
-
442
- let dz = 1 / (1 << (this.tileZoom - n.segment.tileZoom));
443
-
444
- let inc = Math.max(gs / (n_gs * dz), 1),
445
- n_inc = Math.max((n_gs * dz) / gs, 1),
446
- n_offset = offset * n_gs;
447
-
448
- for (let k = 0, nk = n_offset; k < gsOne; k += inc, nk += n_inc) {
449
- const index = k * 3;
450
- const n_index = (n_gsOne * n_gs + nk) * 3;
451
-
452
- v[index] = nv[n_index];
453
- v[index + 1] = nv[n_index + 1];
454
- v[index + 2] = nv[n_index + 2];
455
-
456
- vHigh[index] = nvHigh[n_index];
457
- vHigh[index + 1] = nvHigh[n_index + 1];
458
- vHigh[index + 2] = nvHigh[n_index + 2];
459
-
460
- vLow[index] = nvLow[n_index];
461
- vLow[index + 1] = nvLow[n_index + 1];
462
- vLow[index + 2] = nvLow[n_index + 2];
463
- }
464
- }
465
-
466
- n = nn[E][0];
467
- if (this._checkEqualization(E, n)) {
468
- //this.node.equalizedNeighborId[E] = n.appliedTerrainNodeId;
469
- //this.node.equalizedNeighborGridSize[E] = n.segment.gridSize;
470
-
471
- //n.equalizedNeighborId[OPSIDE[E]] = this.node.appliedTerrainNodeId;
472
- //n.equalizedNeighborGridSize[OPSIDE[E]] = this.gridSize;
473
-
474
- this.readyToEngage = true;
475
-
476
- let offset = this.node.getOffsetOppositeNeighbourSide(n, E);
477
-
478
- let nv = n.segment.tempVertices,
479
- nvHigh = n.segment.tempVerticesHigh,
480
- nvLow = n.segment.tempVerticesLow;
481
-
482
- let n_gs = n.segment.gridSize,
483
- n_gsOne = n_gs + 1;
484
-
485
- let dz = 1 / (1 << (this.tileZoom - n.segment.tileZoom));
486
-
487
- let inc = Math.max(gs / (n_gs * dz), 1),
488
- n_inc = Math.max((n_gs * dz) / gs, 1),
489
- n_offset = offset * n_gs;
490
-
491
- for (let k = 0, nk = n_offset; k < gsOne; k += inc, nk += n_inc) {
492
- const index = (gsOne * k + gs) * 3;
493
- const n_index = n_gsOne * nk * 3;
494
-
495
- v[index] = nv[n_index];
496
- v[index + 1] = nv[n_index + 1];
497
- v[index + 2] = nv[n_index + 2];
498
-
499
- vHigh[index] = nvHigh[n_index];
500
- vHigh[index + 1] = nvHigh[n_index + 1];
501
- vHigh[index + 2] = nvHigh[n_index + 2];
502
-
503
- vLow[index] = nvLow[n_index];
504
- vLow[index + 1] = nvLow[n_index + 1];
505
- vLow[index + 2] = nvLow[n_index + 2];
506
- }
507
- }
508
-
509
- n = nn[S][0];
510
- if (this._checkEqualization(S, n)) {
511
- //this.node.equalizedNeighborId[S] = n.appliedTerrainNodeId;
512
- //this.node.equalizedNeighborGridSize[S] = n.segment.gridSize;
513
-
514
- //n.equalizedNeighborId[OPSIDE[S]] = this.node.appliedTerrainNodeId;
515
- //n.equalizedNeighborGridSize[OPSIDE[S]] = this.gridSize;
516
-
517
- this.readyToEngage = true;
518
-
519
- let offset = this.node.getOffsetOppositeNeighbourSide(n, S);
520
-
521
- let nv = n.segment.tempVertices,
522
- nvHigh = n.segment.tempVerticesHigh,
523
- nvLow = n.segment.tempVerticesLow;
524
-
525
- let n_gs = n.segment.gridSize; // n_gsOne = n_gs + 1;
526
-
527
- let dz = 1 / (1 << (this.tileZoom - n.segment.tileZoom));
528
-
529
- let inc = Math.max(gs / (n_gs * dz), 1),
530
- n_inc = Math.max((n_gs * dz) / gs, 1),
531
- n_offset = offset * n_gs;
532
-
533
- for (let k = 0, nk = n_offset; k < gsOne; k += inc, nk += n_inc) {
534
- const index = (gsOne * gs + k) * 3;
535
- const n_index = nk * 3;
536
-
537
- v[index] = nv[n_index];
538
- v[index + 1] = nv[n_index + 1];
539
- v[index + 2] = nv[n_index + 2];
540
-
541
- vHigh[index] = nvHigh[n_index];
542
- vHigh[index + 1] = nvHigh[n_index + 1];
543
- vHigh[index + 2] = nvHigh[n_index + 2];
544
-
545
- vLow[index] = nvLow[n_index];
546
- vLow[index + 1] = nvLow[n_index + 1];
547
- vLow[index + 2] = nvLow[n_index + 2];
548
- }
549
- }
550
-
551
- n = nn[W][0];
552
- if (this._checkEqualization(W, n)) {
553
- //this.node.equalizedNeighborId[W] = n.appliedTerrainNodeId;
554
- //this.node.equalizedNeighborGridSize[W] = n.segment.gridSize;
555
-
556
- //n.equalizedNeighborId[OPSIDE[W]] = this.node.appliedTerrainNodeId;
557
- //n.equalizedNeighborGridSize[OPSIDE[W]] = this.gridSize;
558
-
559
- this.readyToEngage = true;
560
-
561
- let offset = this.node.getOffsetOppositeNeighbourSide(n, W);
562
-
563
- let nv = n.segment.tempVertices,
564
- nvHigh = n.segment.tempVerticesHigh,
565
- nvLow = n.segment.tempVerticesLow;
566
-
567
- let n_gs = n.segment.gridSize,
568
- n_gsOne = n_gs + 1;
569
-
570
- let dz = 1 / (1 << (this.tileZoom - n.segment.tileZoom));
571
-
572
- let inc = Math.max(gs / (n_gs * dz), 1),
573
- n_inc = Math.max((n_gs * dz) / gs, 1),
574
- n_offset = offset * n_gs;
575
-
576
- for (let k = 0, nk = n_offset; k < gsOne; k += inc, nk += n_inc) {
577
- const index = gsOne * k * 3;
578
- const n_index = (n_gsOne * nk + n_gs) * 3;
579
-
580
- v[index] = nv[n_index];
581
- v[index + 1] = nv[n_index + 1];
582
- v[index + 2] = nv[n_index + 2];
583
-
584
- vHigh[index] = nvHigh[n_index];
585
- vHigh[index + 1] = nvHigh[n_index + 1];
586
- vHigh[index + 2] = nvHigh[n_index + 2];
587
-
588
- vLow[index] = nvLow[n_index];
589
- vLow[index + 1] = nvLow[n_index + 1];
590
- vLow[index + 2] = nvLow[n_index + 2];
591
- }
592
- }
593
- };
594
-
595
- Segment.prototype.engage = function () {
596
- this.readyToEngage = false;
597
- this.createCoordsBuffers(this.tempVerticesHigh, this.tempVerticesLow, this.gridSize);
598
- };
599
-
600
- Segment.prototype._plainSegmentWorkerCallback = function (data) {
601
- this.plainProcessing = false;
602
-
603
- if (this.initialized && !this.terrainReady) {
604
- this.plainVertices = data.plainVertices;
605
- this.plainVerticesHigh = data.plainVerticesHigh;
606
- this.plainVerticesLow = data.plainVerticesLow;
607
-
608
- this.plainNormals = data.plainNormals;
609
-
610
- this.normalMapNormals = data.normalMapNormals;
611
- this.normalMapVertices = data.normalMapVertices;
612
- this.normalMapVerticesHigh = data.normalMapVerticesHigh;
613
- this.normalMapVerticesLow = data.normalMapVerticesLow;
614
-
615
- this.terrainVertices = this.plainVertices;
616
- this.terrainVerticesHigh = this.plainVerticesHigh;
617
- this.terrainVerticesLow = this.plainVerticesLow;
618
-
619
- this.fileGridSize = Math.sqrt(data.normalMapVertices.length / 3) - 1;
620
-
621
- this._plainRadius = data.plainRadius;
622
-
623
- this.plainReady = true;
624
- }
625
- };
626
-
627
- Segment.prototype._terrainWorkerCallback = function (data) {
628
- if (this.plainReady) {
629
- this.readyToEngage = true;
630
-
631
- this.normalMapNormals = null;
632
-
633
- this.normalMapVertices = null;
634
- this.normalMapVerticesHigh = null;
635
- this.normalMapVerticesLow = null;
636
-
637
- this.terrainVertices = null;
638
- this.terrainVerticesHigh = null;
639
- this.terrainVerticesLow = null;
640
- this.noDataVertices = null;
641
-
642
- this.tempVertices = null;
643
- this.tempVerticesHigh = null;
644
- this.tempVerticesLow = null;
645
-
646
- this.normalMapNormals = data.normalMapNormals;
647
- this.normalMapVertices = data.normalMapVertices;
648
- this.normalMapVerticesHigh = data.normalMapVerticesHigh;
649
- this.normalMapVerticesLow = data.normalMapVerticesLow;
650
-
651
- this.terrainVertices = data.terrainVertices;
652
- this.terrainVerticesHigh = data.terrainVerticesHigh;
653
- this.terrainVerticesLow = data.terrainVerticesLow;
654
-
655
- this.noDataVertices = data.noDataVertices;
656
-
657
- this.tempVertices = this.terrainVertices;
658
- this.tempVerticesHigh = this.terrainVerticesHigh;
659
- this.tempVerticesLow = this.terrainVerticesLow;
660
-
661
- this.setBoundingVolumeArr(data.bounds);
662
-
663
- //var b = data.bounds;
664
-
665
- //this.setBoundingSphere(
666
- // b[0] + (b[1] - b[0]) * 0.5,
667
- // b[2] + (b[3] - b[2]) * 0.5,
668
- // b[4] + (b[5] - b[4]) * 0.5,
669
- // new Vec3(b[0], b[2], b[4])
670
- //);
671
-
672
- this.gridSize = Math.sqrt(this.terrainVertices.length / 3) - 1;
673
- this.node.appliedTerrainNodeId = this.node.nodeId;
674
-
675
- this.terrainReady = true;
676
- this.terrainIsLoading = false;
677
- this.parentNormalMapReady = true;
678
- this.terrainExists = true;
679
-
680
- if (!this.normalMapTexturePtr) {
681
- var nmc = this.planet._normalMapCreator;
682
- this.normalMapTexturePtr = this.planet.renderer.handler.createEmptyTexture_l(
683
- nmc._width,
684
- nmc._height
685
- );
686
- }
687
-
688
- if (this.planet.lightEnabled) {
689
- this.planet._normalMapCreator.queue(this);
690
- }
691
- }
692
- };
693
-
694
- /**
695
- * Terrain is not obtained or not exists on the server.
696
- */
697
- Segment.prototype.elevationsNotExists = function () {
698
- if (this.planet && this.tileZoom <= this.planet.terrain.maxZoom) {
699
- if (this.plainReady && this.terrainIsLoading) {
700
- this.terrainIsLoading = false;
701
-
702
- this.node.appliedTerrainNodeId = this.node.nodeId;
703
-
704
- if (this.planet.lightEnabled && !this._inTheQueue) {
705
- this.planet._normalMapCreator.queue(this);
706
- }
707
-
708
- this.readyToEngage = true;
709
- }
710
-
711
- this.terrainVertices = this.plainVertices;
712
- this.terrainVerticesHigh = this.plainVerticesHigh;
713
- this.terrainVerticesLow = this.plainVerticesLow;
714
-
715
- this.tempVertices = this.terrainVertices;
716
- this.tempVerticesHigh = this.terrainVerticesHigh;
717
- this.tempVerticesLow = this.terrainVerticesLow;
718
-
719
- this.noDataVertices = null;
720
-
721
- this.fileGridSize = Math.sqrt(this.terrainVertices.length / 3) - 1;
722
- this.gridSize = this.fileGridSize;
723
- this.terrainReady = true;
724
- this.terrainExists = false;
725
- }
726
- };
727
-
728
- const _S = new Array(4);
729
- _S[N] = 0;
730
- _S[E] = 1;
731
- _S[S] = 1;
732
- _S[W] = 0;
733
-
734
- const _V = new Array(4);
735
- _V[N] = false;
736
- _V[E] = true;
737
- _V[S] = false;
738
- _V[W] = true;
739
-
740
- Segment.prototype._normalMapEdgeEqualize = function (side) {
741
- let nn = this.node.neighbors;
742
- let n = nn[side][0];
743
- let maxZ = this.planet.terrain.maxZoom;
744
-
745
- if (this.tileZoom === maxZ) {
746
- if (!(nn[0].length || nn[1].length || nn[2].length || nn[3].length)) {
747
- n = this.node.getEqualNeighbor(side);
748
- }
749
- }
750
-
751
- let b = n && n.segment,
752
- s = this;
753
-
754
- if (
755
- n &&
756
- b &&
757
- b.terrainReady &&
758
- b.terrainExists &&
759
- b.tileZoom <= maxZ &&
760
- s._appliedNeighborsZoom[side] !== b.tileZoom
761
- ) {
762
- s._appliedNeighborsZoom[side] = b.tileZoom;
763
-
764
- let seg_a = s.normalMapNormals,
765
- seg_b = b.normalMapNormals;
766
-
767
- if (!(seg_a && seg_b)) return;
768
-
769
- let seg_a_raw = s.normalMapNormals,
770
- seg_b_raw = b.normalMapNormals;
771
-
772
- // let seg_a_verts = s.terrainVertices,
773
- // seg_b_verts = s.terrainVertices;
774
-
775
- let s_gs = Math.sqrt(seg_a.length / 3),
776
- // b_gs = Math.sqrt(seg_b.length / 3),
777
- s_gs1 = s_gs - 1;
778
- // b_gs1 = b_gs - 1;
779
-
780
- const i_a = s_gs1 * _S[side];
781
-
782
- let nx, ny, nz, q;
783
-
784
- if (s.tileZoom === b.tileZoom) {
785
- const i_b = s_gs1 - i_a;
786
-
787
- if (_V[side]) {
788
- for (let k = 0; k < s_gs; k++) {
789
- let vInd_a = (k * s_gs + i_a) * 3,
790
- vInd_b = (k * s_gs + i_b) * 3;
791
-
792
- nx = seg_a_raw[vInd_a] + seg_b_raw[vInd_b];
793
- ny = seg_a_raw[vInd_a + 1] + seg_b_raw[vInd_b + 1];
794
- nz = seg_a_raw[vInd_a + 2] + seg_b_raw[vInd_b + 2];
795
-
796
- q = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
797
-
798
- seg_b[vInd_b] = seg_a[vInd_a] = nx * q;
799
- seg_b[vInd_b + 1] = seg_a[vInd_a + 1] = ny * q;
800
- seg_b[vInd_b + 2] = seg_a[vInd_a + 2] = nz * q;
801
- }
802
- } else {
803
- for (let k = 0; k < s_gs; k++) {
804
- let vInd_a = (i_a * s_gs + k) * 3,
805
- vInd_b = (i_b * s_gs + k) * 3;
806
-
807
- nx = seg_a_raw[vInd_a] + seg_b_raw[vInd_b];
808
- ny = seg_a_raw[vInd_a + 1] + seg_b_raw[vInd_b + 1];
809
- nz = seg_a_raw[vInd_a + 2] + seg_b_raw[vInd_b + 2];
810
-
811
- q = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
812
-
813
- seg_b[vInd_b] = seg_a[vInd_a] = nx * q;
814
- seg_b[vInd_b + 1] = seg_a[vInd_a + 1] = ny * q;
815
- seg_b[vInd_b + 2] = seg_a[vInd_a + 2] = nz * q;
816
- }
817
- }
818
-
819
- if (!b._inTheQueue && b._appliedNeighborsZoom[OPSIDE[side]] !== s.tileZoom) {
820
- b._appliedNeighborsZoom[OPSIDE[side]] = s.tileZoom;
821
- s.planet._normalMapCreator.queue(b);
822
- }
823
- } else {
824
- }
825
- }
826
- };
827
-
828
- Segment.prototype.applyTerrain = function (elevations) {
829
- if (elevations) {
830
- this.elevationsExists(elevations);
831
- } else {
832
- this.elevationsNotExists();
833
- }
834
- };
835
-
836
- /**
837
- * Delete segment gl buffers.
838
- */
839
- Segment.prototype.deleteBuffers = function () {
840
- var gl = this.handler.gl;
841
- gl.deleteBuffer(this.vertexNormalBuffer);
842
- gl.deleteBuffer(this.vertexPositionBuffer);
843
- gl.deleteBuffer(this.vertexPositionBufferHigh);
844
- gl.deleteBuffer(this.vertexPositionBufferLow);
845
-
846
- this.vertexNormalBuffer = null;
847
- this.vertexPositionBuffer = null;
848
- this.vertexPositionBufferHigh = null;
849
- this.vertexPositionBufferLow = null;
850
- this.vertexTextureCoordBuffer = null;
851
- };
852
-
853
- /**
854
- * Delete materials.
855
- */
856
- Segment.prototype.deleteMaterials = function () {
857
- var m = this.materials;
858
- for (var i = 0; i < m.length; i++) {
859
- var mi = m[i];
860
- if (mi) {
861
- mi.clear();
862
- }
863
- }
864
- this.materials.length = 0;
865
- };
866
-
867
- /**
868
- * Delete elevation data.
869
- */
870
- Segment.prototype.deleteElevations = function () {
871
- this.terrainExists = false;
872
- this.terrainReady = false;
873
- this.terrainIsLoading = false;
874
-
875
- this.normalMapVertices = null;
876
- this.normalMapVerticesHigh = null;
877
- this.normalMapVerticesLow = null;
878
-
879
- this.normalMapNormals = null;
880
-
881
- this.tempVertices = null;
882
- this.tempVerticesHigh = null;
883
- this.tempVerticesLow = null;
884
-
885
- this.terrainVertices = null;
886
- this.terrainVerticesHigh = null;
887
- this.terrainVerticesLow = null;
888
- this.noDataVertices = null;
889
-
890
- this.plainVertices = null;
891
- this.plainVerticesHigh = null;
892
- this.plainVerticesLow = null;
893
-
894
- this.plainNormals = null;
895
-
896
- if (this.normalMapReady) {
897
- this.handler.gl.deleteTexture(this.normalMapTexture);
898
- }
899
- this.normalMapReady = false;
900
- this.parentNormalMapReady = false;
901
- this._appliedNeighborsZoom = [0, 0, 0, 0];
902
- this.normalMapTextureBias[0] = 0;
903
- this.normalMapTextureBias[1] = 0;
904
- this.normalMapTextureBias[2] = 1;
905
- this._inTheQueue = false;
906
- };
907
-
908
- /**
909
- * Clear but not destroy segment data.
910
- */
911
- Segment.prototype.clearSegment = function () {
912
- this.plainReady = false;
913
- this.initialized = false;
914
- this.deleteBuffers();
915
- this.deleteMaterials();
916
- this.deleteElevations();
917
- };
918
-
919
- /**
920
- * Removes cache records.
921
- */
922
- Segment.prototype._freeCache = function () {
923
- this.planet._quadTreeNodesCacheMerc[this.tileIndex] = null;
924
- delete this.planet._quadTreeNodesCacheMerc[this.tileIndex];
925
- };
926
-
927
- /**
928
- * Clear and destroy all segment data.
929
- */
930
- Segment.prototype.destroySegment = function () {
931
- this._freeCache();
932
-
933
- this.clearSegment();
934
-
935
- var i = this._renderingSlices.length;
936
- while (i--) {
937
- this._renderingSlices[i].clear();
938
- }
939
-
940
- this._renderingSlices = null;
941
-
942
- this.node = null;
943
-
944
- this.planet = null;
945
- this.handler = null;
946
- this.bbox = null;
947
- this.bsphere = null;
948
- this._extent = null;
949
-
950
- this.materials = null;
951
-
952
- this.plainVertices = null;
953
- this.plainVerticesHigh = null;
954
- this.plainVerticesLow = null;
955
- this.plainNormals = null;
956
-
957
- this.terrainVertices = null;
958
- this.terrainVerticesHigh = null;
959
- this.terrainVerticesLow = null;
960
- this.noDataVertices = null;
961
-
962
- this.tempVertices = null;
963
- this.tempVerticesHigh = null;
964
- this.tempVerticesLow = null;
965
-
966
- this.normalMapTexture = null;
967
- this.normalMapTextureBias = null;
968
- this.normalMapVertices = null;
969
- this.normalMapVerticesHigh = null;
970
- this.normalMapVerticesLow = null;
971
- this.normalMapNormals = null;
972
-
973
- this.vertexNormalBuffer = null;
974
- this.vertexPositionBuffer = null;
975
- this.vertexPositionBufferHigh = null;
976
- this.vertexPositionBufferLow = null;
977
- this.vertexTextureCoordBuffer = null;
978
-
979
- this._tileOffsetArr = null;
980
- this._visibleExtentOffsetArr = null;
981
-
982
- this._projection = null;
983
- this._appliedNeighborsZoom = null;
984
-
985
- this._globalTextureCoordinates = null;
986
- };
987
-
988
- Segment.prototype._setExtentLonLat = function () {
989
- this._extentLonLat = this._extent.inverseMercator();
990
- };
991
-
992
- /**
993
- * Creates bound volumes by segment geographical extent.
994
- */
995
- Segment.prototype.createBoundsByExtent = function () {
996
- var ellipsoid = this.planet.ellipsoid,
997
- extent = this._extentLonLat;
998
-
999
- var coord_sw = ellipsoid.geodeticToCartesian(extent.southWest.lon, extent.southWest.lat);
1000
- var coord_ne = ellipsoid.geodeticToCartesian(extent.northEast.lon, extent.northEast.lat);
1001
-
1002
- // check for zoom
1003
- if (this.tileZoom <= MAX_NORMAL_ZOOM) {
1004
- var coord_nw = ellipsoid.geodeticToCartesian(extent.southWest.lon, extent.northEast.lat);
1005
- var coord_se = ellipsoid.geodeticToCartesian(extent.northEast.lon, extent.southWest.lat);
1006
-
1007
- this._swNorm = coord_sw.normal();
1008
- this._nwNorm = coord_nw.normal();
1009
- this._neNorm = coord_ne.normal();
1010
- this._seNorm = coord_se.normal();
1011
- }
1012
-
1013
- this.setBoundingVolume3v(coord_sw, coord_ne);
1014
- };
1015
-
1016
- Segment.prototype.createBoundsByParent = function () {
1017
- let pn = this.node;
1018
-
1019
- while (pn.parentNode && !pn.segment.terrainReady) {
1020
- pn = pn.parentNode;
1021
- }
1022
-
1023
- let dZ2 = 1 << (this.tileZoom - pn.segment.tileZoom);
1024
-
1025
- let offsetX = this.tileX - pn.segment.tileX * dZ2,
1026
- offsetY = this.tileY - pn.segment.tileY * dZ2;
1027
-
1028
- if (pn.segment.terrainReady && pn.segment.tileZoom >= this.planet.terrain.minZoom) {
1029
- let gridSize = pn.segment.gridSize / dZ2;
1030
-
1031
- if (gridSize >= 1.0) {
1032
- //
1033
- // (*) Actually, we get parent whole bounding volume
1034
- //
1035
- this.bsphere.center.x = pn.segment.bsphere.center.x;
1036
- this.bsphere.center.y = pn.segment.bsphere.center.y;
1037
- this.bsphere.center.z = pn.segment.bsphere.center.z;
1038
- this.bsphere.radius = pn.segment.bsphere.radius;
1039
-
1040
- if (this.tileZoom <= MAX_NORMAL_ZOOM) {
1041
- let i0 = gridSize * offsetY;
1042
- let j0 = gridSize * offsetX;
1043
-
1044
- let pnGsOne = pn.segment.gridSize + 1;
1045
-
1046
- let ind_sw = 3 * ((i0 + gridSize) * pnGsOne + j0),
1047
- ind_nw = 3 * (i0 * pnGsOne + j0),
1048
- ind_ne = 3 * (i0 * pnGsOne + j0 + gridSize),
1049
- ind_se = 3 * ((i0 + gridSize) * pnGsOne + j0 + gridSize);
1050
-
1051
- let pVerts = pn.segment.tempVertices;
1052
-
1053
- let v_sw = new Vec3(pVerts[ind_sw], pVerts[ind_sw + 1], pVerts[ind_sw + 2]),
1054
- v_ne = new Vec3(pVerts[ind_ne], pVerts[ind_ne + 1], pVerts[ind_ne + 2]);
1055
-
1056
- // check for segment zoom
1057
- let v_nw = new Vec3(pVerts[ind_nw], pVerts[ind_nw + 1], pVerts[ind_nw + 2]),
1058
- v_se = new Vec3(pVerts[ind_se], pVerts[ind_se + 1], pVerts[ind_se + 2]);
1059
-
1060
- this._swNorm = v_sw.normal();
1061
- this._nwNorm = v_nw.normal();
1062
- this._neNorm = v_ne.normal();
1063
- this._seNorm = v_se.normal();
1064
- }
1065
- } else {
1066
- let pseg = pn.segment;
1067
-
1068
- let i0 = Math.floor(gridSize * offsetY),
1069
- j0 = Math.floor(gridSize * offsetX);
1070
-
1071
- let insideSize = 1.0 / gridSize;
1072
-
1073
- let t_i0 = offsetY - insideSize * i0,
1074
- t_j0 = offsetX - insideSize * j0;
1075
-
1076
- let bigOne;
1077
- if (pseg.gridSize === 1) {
1078
- bigOne = pseg.tempVertices;
1079
- } else {
1080
- bigOne = getMatrixSubArray(pseg.tempVertices, pseg.gridSize, i0, j0, 1);
1081
- }
1082
-
1083
- let v_lt = new Vec3(bigOne[0], bigOne[1], bigOne[2]),
1084
- v_rb = new Vec3(bigOne[9], bigOne[10], bigOne[11]);
1085
-
1086
- let vn = new Vec3(bigOne[3] - bigOne[0], bigOne[4] - bigOne[1], bigOne[5] - bigOne[2]),
1087
- vw = new Vec3(bigOne[6] - bigOne[0], bigOne[7] - bigOne[1], bigOne[8] - bigOne[2]),
1088
- ve = new Vec3(
1089
- bigOne[3] - bigOne[9],
1090
- bigOne[4] - bigOne[10],
1091
- bigOne[5] - bigOne[11]
1092
- ),
1093
- vs = new Vec3(
1094
- bigOne[6] - bigOne[9],
1095
- bigOne[7] - bigOne[10],
1096
- bigOne[8] - bigOne[11]
1097
- );
1098
-
1099
- let vi_y = t_i0,
1100
- vi_x = t_j0;
1101
-
1102
- let coords_lt, coords_rb;
1103
-
1104
- if (vi_y + vi_x < insideSize) {
1105
- coords_lt = Vec3.add(
1106
- vn.scaleTo(vi_x / insideSize),
1107
- vw.scaleTo(vi_y / insideSize)
1108
- ).addA(v_lt);
1109
- } else {
1110
- coords_lt = Vec3.add(
1111
- vs.scaleTo(1 - vi_x / insideSize),
1112
- ve.scaleTo(1 - vi_y / insideSize)
1113
- ).addA(v_rb);
1114
- }
1115
-
1116
- vi_y = t_i0 + 1;
1117
- vi_x = t_j0 + 1;
1118
-
1119
- if (vi_y + vi_x < insideSize) {
1120
- coords_rb = Vec3.add(
1121
- vn.scaleTo(vi_x / insideSize),
1122
- vw.scaleTo(vi_y / insideSize)
1123
- ).addA(v_lt);
1124
- } else {
1125
- coords_rb = Vec3.add(
1126
- vs.scaleTo(1 - vi_x / insideSize),
1127
- ve.scaleTo(1 - vi_y / insideSize)
1128
- ).addA(v_rb);
1129
- }
1130
-
1131
- this.setBoundingVolume3v(coords_lt, coords_rb);
1132
- }
1133
- } else {
1134
- this.createBoundsByExtent();
1135
- }
1136
- };
1137
-
1138
- Segment.prototype.setBoundingSphere = function (x, y, z, v) {
1139
- this.bsphere.center.x = x;
1140
- this.bsphere.center.y = y;
1141
- this.bsphere.center.z = z;
1142
- this.bsphere.radius = this.bsphere.center.distance(v);
1143
- };
1144
-
1145
- window.BBSC = 100;
1146
-
1147
- Segment.prototype.setBoundingVolume = function (xmin, ymin, zmin, xmax, ymax, zmax) {
1148
- this.bbox.setFromBoundsArr([xmin, ymin, zmin, xmax, ymax, zmax]);
1149
-
1150
- let x = xmin + (xmax - xmin) * 0.5,
1151
- y = ymin + (ymax - ymin) * 0.5,
1152
- z = zmin + (zmax - zmin) * 0.5;
1153
-
1154
- this.bsphere.center.set(x, y, z);
1155
- this.bsphere.radius = this.bsphere.center.distance(new Vec3(xmin, ymin, zmin));
1156
- };
1157
-
1158
- Segment.prototype.setBoundingVolume3v = function (vmin, vmax) {
1159
- this.bbox.setFromBoundsArr([vmin.x, vmin.y, vmin.z, vmax.x, vmax.y, vmax.z]);
1160
-
1161
- let x = vmin.x + (vmax.x - vmin.x) * 0.5,
1162
- y = vmin.y + (vmax.y - vmin.y) * 0.5,
1163
- z = vmin.z + (vmax.z - vmin.z) * 0.5;
1164
-
1165
- this.bsphere.center.set(x, y, z);
1166
- this.bsphere.radius = this.bsphere.center.distance(new Vec3(vmin.x, vmin.y, vmin.z));
1167
- };
1168
-
1169
- Segment.prototype.setBoundingVolumeArr = function (bounds) {
1170
- this.bbox.setFromBoundsArr(bounds);
1171
-
1172
- let x = bounds[0] + (bounds[3] - bounds[0]) * 0.5,
1173
- y = bounds[1] + (bounds[4] - bounds[1]) * 0.5,
1174
- z = bounds[2] + (bounds[5] - bounds[2]) * 0.5;
1175
-
1176
- this.bsphere.center.set(x, y, z);
1177
- this.bsphere.radius = this.bsphere.center.distance(new Vec3(bounds[0], bounds[1], bounds[2]));
1178
- };
1179
-
1180
- Segment.prototype.createCoordsBuffers = function (verticesHigh, verticesLow, gridSize) {
1181
- var gsgs = (gridSize + 1) * (gridSize + 1);
1182
- var h = this.handler;
1183
-
1184
- if (this.vertexPositionBufferHigh && this.vertexPositionBufferHigh.numItems === gsgs) {
1185
- h.setStreamArrayBuffer(this.vertexPositionBufferHigh, verticesHigh);
1186
- h.setStreamArrayBuffer(this.vertexPositionBufferLow, verticesLow);
1187
- } else {
1188
- h.gl.deleteBuffer(this.vertexPositionBufferHigh);
1189
- h.gl.deleteBuffer(this.vertexPositionBufferLow);
1190
-
1191
- this.vertexTextureCoordBuffer = this.planet._textureCoordsBufferCache[Math.log2(gridSize)];
1192
-
1193
- //this.vertexPositionBufferHigh = h.createStreamArrayBuffer(3, gsgs);
1194
- //h.setStreamArrayBuffer(this.vertexPositionBufferHigh, verticesHigh);
1195
- //this.vertexPositionBufferLow = h.createStreamArrayBuffer(3, gsgs);
1196
- //h.setStreamArrayBuffer(this.vertexPositionBufferLow, verticesLow);
1197
-
1198
- // It works, but I'm not sure that it is correct and better use the comment above
1199
- this.vertexPositionBufferHigh = h.createArrayBuffer(verticesHigh, 3, gsgs);
1200
- this.vertexPositionBufferLow = h.createArrayBuffer(verticesLow, 3, gsgs);
1201
- }
1202
- };
1203
-
1204
- Segment.prototype._addViewExtent = function () {
1205
- var ext = this._extentLonLat;
1206
-
1207
- if (!this.planet._viewExtent) {
1208
- this.planet._viewExtent = new Extent(
1209
- new LonLat(ext.southWest.lon, ext.southWest.lat),
1210
- new LonLat(ext.northEast.lon, ext.northEast.lat)
1211
- );
1212
- return;
1213
- }
1214
-
1215
- var viewExt = this.planet._viewExtent;
1216
-
1217
- if (ext.southWest.lon < viewExt.southWest.lon) {
1218
- viewExt.southWest.lon = ext.southWest.lon;
1219
- }
1220
-
1221
- if (ext.northEast.lon > viewExt.northEast.lon) {
1222
- viewExt.northEast.lon = ext.northEast.lon;
1223
- }
1224
-
1225
- if (ext.southWest.lat < viewExt.southWest.lat) {
1226
- viewExt.southWest.lat = ext.southWest.lat;
1227
- }
1228
-
1229
- if (ext.northEast.lat > viewExt.northEast.lat) {
1230
- viewExt.northEast.lat = ext.northEast.lat;
1231
- }
1232
- };
1233
-
1234
- Segment.prototype._assignTileIndexes = function () {
1235
- this._tileGroup = 0;
1236
- var tileZoom = this.tileZoom;
1237
- var extent = this._extent;
1238
- var pole = mercator.POLE;
1239
- this.tileX = Math.round(
1240
- Math.abs(-pole - extent.southWest.lon) / (extent.northEast.lon - extent.southWest.lon)
1241
- );
1242
- this.tileY = Math.round(
1243
- Math.abs(pole - extent.northEast.lat) / (extent.northEast.lat - extent.southWest.lat)
1244
- );
1245
- var p2 = Math.pow(2, tileZoom);
1246
- this.tileXE = (this.tileX + 1) % p2;
1247
- this.tileXW = (p2 + this.tileX - 1) % p2;
1248
-
1249
- this.tileYN = this.tileY - 1;
1250
- this.tileYS = this.tileY + 1;
1251
-
1252
- this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
1253
- this.planet._quadTreeNodesCacheMerc[this.tileIndex] = this.node;
1254
- };
1255
-
1256
- Segment.prototype.initialize = function () {
1257
- var p = this.planet;
1258
- var n = this.node;
1259
-
1260
- n.sideSize[0] =
1261
- n.sideSize[1] =
1262
- n.sideSize[2] =
1263
- n.sideSize[3] =
1264
- this.gridSize =
1265
- p.terrain.gridSizeByZoom[this.tileZoom] || p.terrain.plainGridSize;
1266
-
1267
- n.sideSizeLog2[0] =
1268
- n.sideSizeLog2[1] =
1269
- n.sideSizeLog2[2] =
1270
- n.sideSizeLog2[3] =
1271
- Math.log2(p.terrain.gridSizeByZoom[this.tileZoom] || p.terrain.plainGridSize);
1272
-
1273
- if (this.tileZoom <= p.terrain.maxZoom) {
1274
- var nmc = this.planet._normalMapCreator;
1275
- this.normalMapTexturePtr = p.renderer.handler.createEmptyTexture_l(nmc._width, nmc._height);
1276
- }
1277
-
1278
- this.normalMapTexture = this.planet.transparentTexture;
1279
-
1280
- this._assignGlobalTextureCoordinates();
1281
-
1282
- this.initialized = true;
1283
- };
1284
-
1285
- Segment.prototype._assignGlobalTextureCoordinates = function () {
1286
- var e = this._extent;
1287
- this._globalTextureCoordinates[0] =
1288
- (e.southWest.lon + mercator.POLE) * mercator.ONE_BY_POLE_DOUBLE;
1289
- this._globalTextureCoordinates[1] =
1290
- (mercator.POLE - e.northEast.lat) * mercator.ONE_BY_POLE_DOUBLE;
1291
- this._globalTextureCoordinates[2] =
1292
- (e.northEast.lon + mercator.POLE) * mercator.ONE_BY_POLE_DOUBLE;
1293
- this._globalTextureCoordinates[3] =
1294
- (mercator.POLE - e.southWest.lat) * mercator.ONE_BY_POLE_DOUBLE;
1295
- };
1296
-
1297
- Segment.prototype.createPlainSegmentAsync = function () {
1298
- let p = this.planet,
1299
- t = p.terrain;
1300
-
1301
- if (t.isReady() && this.tileZoom <= t.maxZoom && !this.plainReady) {
1302
- this.plainProcessing = true;
1303
- p._plainSegmentWorker.make(this);
1304
- }
1305
- };
1306
-
1307
- Segment.prototype.createPlainSegment = function () {
1308
- this.initialize();
1309
- this._createPlainVertices();
1310
- this.readyToEngage = true;
1311
- };
1312
-
1313
- Segment.prototype._createPlainVertices = function () {
1314
- var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
1315
-
1316
- var e = this._extent,
1317
- fgs = this.planet.terrain.plainGridSize;
1318
- var lonSize = e.getWidth();
1319
- var llStep = lonSize / Math.max(fgs, gridSize);
1320
- var esw_lon = e.southWest.lon,
1321
- ene_lat = e.northEast.lat;
1322
- var dg = Math.max(fgs / gridSize, 1),
1323
- gs = Math.max(fgs, gridSize) + 1;
1324
- var r2 = this.planet.ellipsoid._invRadii2;
1325
- var ind = 0,
1326
- nmInd = 0;
1327
- const gsgs = gs * gs;
1328
-
1329
- var gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
1330
-
1331
- this.plainNormals = new Float32Array(gridSize3);
1332
- this.plainVertices = new Float64Array(gridSize3);
1333
- this.plainVerticesHigh = new Float32Array(gridSize3);
1334
- this.plainVerticesLow = new Float32Array(gridSize3);
1335
-
1336
- this.normalMapNormals = new Float32Array(gsgs * 3);
1337
- this.normalMapVertices = new Float64Array(gsgs * 3);
1338
- this.normalMapVerticesHigh = new Float32Array(gsgs * 3);
1339
- this.normalMapVerticesLow = new Float32Array(gsgs * 3);
1340
-
1341
- var verts = this.plainVertices,
1342
- vertsHigh = this.plainVerticesHigh,
1343
- vertsLow = this.plainVerticesLow,
1344
- norms = this.plainNormals,
1345
- nmVerts = this.normalMapVertices,
1346
- nmVertsHigh = this.normalMapVerticesHigh,
1347
- nmVertsLow = this.normalMapVerticesLow,
1348
- nmNorms = this.normalMapNormals;
1349
-
1350
- for (var k = 0; k < gsgs; k++) {
1351
- var j = k % gs,
1352
- i = ~~(k / gs);
1353
-
1354
- var v = this.planet.ellipsoid.lonLatToCartesian(
1355
- LonLat.inverseMercator(esw_lon + j * llStep, ene_lat - i * llStep)
1356
- );
1357
- var nx = v.x * r2.x,
1358
- ny = v.y * r2.y,
1359
- nz = v.z * r2.z;
1360
- var l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
1361
- var nxl = nx * l,
1362
- nyl = ny * l,
1363
- nzl = nz * l;
1364
-
1365
- Vec3.doubleToTwoFloats(v, _tempHigh, _tempLow);
1366
-
1367
- nmVerts[nmInd] = v.x;
1368
- nmVertsHigh[nmInd] = _tempHigh.x;
1369
- nmVertsLow[nmInd] = _tempLow.x;
1370
- nmNorms[nmInd++] = nxl;
1371
-
1372
- nmVerts[nmInd] = v.y;
1373
- nmVertsHigh[nmInd] = _tempHigh.y;
1374
- nmVertsLow[nmInd] = _tempLow.y;
1375
- nmNorms[nmInd++] = nyl;
1376
-
1377
- nmVerts[nmInd] = v.z;
1378
- nmVertsHigh[nmInd] = _tempHigh.z;
1379
- nmVertsLow[nmInd] = _tempLow.z;
1380
- nmNorms[nmInd++] = nzl;
1381
-
1382
- if (i % dg === 0 && j % dg === 0) {
1383
- verts[ind] = v.x;
1384
- vertsHigh[ind] = _tempHigh.x;
1385
- vertsLow[ind] = _tempLow.x;
1386
- norms[ind++] = nxl;
1387
-
1388
- verts[ind] = v.y;
1389
- vertsHigh[ind] = _tempHigh.y;
1390
- vertsLow[ind] = _tempLow.y;
1391
- norms[ind++] = nyl;
1392
-
1393
- verts[ind] = v.z;
1394
- vertsHigh[ind] = _tempHigh.z;
1395
- vertsLow[ind] = _tempLow.z;
1396
- norms[ind++] = nzl;
1397
- }
1398
- }
1399
-
1400
- this.terrainVertices = verts;
1401
- this.terrainVerticesHigh = vertsHigh;
1402
- this.terrainVerticesLow = vertsLow;
1403
-
1404
- this.plainReady = true;
1405
- };
1406
-
1407
- /**
1408
- * Gets specific layer material.
1409
- * @public
1410
- * @param {og.Layer} layer - Layer object.
1411
- * @returns {og.planetSegment.Material} - Segment material.
1412
- */
1413
- Segment.prototype.getMaterialByLayer = function (layer) {
1414
- return this.materials[layer._id];
1415
- };
1416
-
1417
- Segment.prototype._getLayerExtentOffset = function (layer) {
1418
- var v0s = layer._extentMerc;
1419
- var v0t = this._extent;
1420
- var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
1421
- var sSize_y = v0s.northEast.lat - v0s.southWest.lat;
1422
- var dV0s_x = (v0t.southWest.lon - v0s.southWest.lon) / sSize_x;
1423
- var dV0s_y = (v0s.northEast.lat - v0t.northEast.lat) / sSize_y;
1424
- var dSize_x = (v0t.northEast.lon - v0t.southWest.lon) / sSize_x;
1425
- var dSize_y = (v0t.northEast.lat - v0t.southWest.lat) / sSize_y;
1426
- return [dV0s_x, dV0s_y, dSize_x, dSize_y];
1427
- };
1428
-
1429
- Segment.prototype.screenRendering = function (
1430
- sh,
1431
- layerSlice,
1432
- sliceIndex,
1433
- defaultTexture,
1434
- isOverlay
1435
- ) {
1436
- var gl = this.handler.gl;
1437
- var sha = sh.attributes,
1438
- shu = sh.uniforms;
1439
-
1440
- var pm = this.materials,
1441
- p = this.planet;
1442
-
1443
- var currHeight, li;
1444
- if (layerSlice) {
1445
- li = layerSlice[0];
1446
- currHeight = li._height;
1447
- } else {
1448
- currHeight = 0;
1449
- }
1450
-
1451
- // First always draw whole planet base layer segment with solid texture.
1452
- gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE + 2);
1453
- gl.bindTexture(gl.TEXTURE_2D, defaultTexture || this.getDefaultTexture());
1454
- gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE + 2);
1455
-
1456
- var n = 0,
1457
- i = 0;
1458
-
1459
- var notEmpty = false;
1460
-
1461
- var slice = this._renderingSlices[sliceIndex];
1462
-
1463
- if (!slice) {
1464
- slice = this._renderingSlices[sliceIndex] = new _RenderingSlice(p);
1465
- } else {
1466
- slice.layers = [];
1467
- }
1468
-
1469
- this._indexBuffer = this._getIndexBuffer();
1470
-
1471
- while (li) {
1472
- if (
1473
- this.layerOverlap(li) &&
1474
- ((li._fading && li._fadingOpacity > 0.0) ||
1475
- ((li.minZoom >= p.minCurrZoom || li.maxZoom >= p.minCurrZoom) &&
1476
- (li.minZoom <= p.maxCurrZoom || li.maxZoom <= p.maxCurrZoom)))
1477
- ) {
1478
- notEmpty = true;
1479
- var m = pm[li._id];
1480
- if (!m) {
1481
- m = pm[li._id] = li.createMaterial(this);
1482
- }
1483
-
1484
- if (!m.isReady) {
1485
- this.planet._renderCompleted = false;
1486
- }
1487
-
1488
- slice.layers.push(li);
1489
-
1490
- var n4 = n * 4,
1491
- n3 = n * 3;
1492
-
1493
- var arr = li.applyMaterial(m);
1494
- slice.tileOffsetArr[n4] = arr[0];
1495
- slice.tileOffsetArr[n4 + 1] = arr[1];
1496
- slice.tileOffsetArr[n4 + 2] = arr[2];
1497
- slice.tileOffsetArr[n4 + 3] = arr[3];
1498
-
1499
- arr = this._getLayerExtentOffset(li);
1500
- slice.visibleExtentOffsetArr[n4] = arr[0];
1501
- slice.visibleExtentOffsetArr[n4 + 1] = arr[1];
1502
- slice.visibleExtentOffsetArr[n4 + 2] = arr[2];
1503
- slice.visibleExtentOffsetArr[n4 + 3] = arr[3];
1504
-
1505
- slice.transparentColorArr[n4] = li.transparentColor[0];
1506
- slice.transparentColorArr[n4 + 1] = li.transparentColor[1];
1507
- slice.transparentColorArr[n4 + 2] = li.transparentColor[2];
1508
- slice.transparentColorArr[n4 + 3] = li.opacity;
1509
-
1510
- p._diffuseMaterialArr[n3 + 3] = li.diffuse.x;
1511
- p._diffuseMaterialArr[n3 + 1 + 3] = li.diffuse.y;
1512
- p._diffuseMaterialArr[n3 + 2 + 3] = li.diffuse.z;
1513
-
1514
- p._ambientMaterialArr[n3 + 3] = li.ambient.x;
1515
- p._ambientMaterialArr[n3 + 1 + 3] = li.ambient.y;
1516
- p._ambientMaterialArr[n3 + 2 + 3] = li.ambient.z;
1517
-
1518
- p._specularMaterialArr[n4 + 4] = li.specular.x;
1519
- p._specularMaterialArr[n4 + 1 + 4] = li.specular.y;
1520
- p._specularMaterialArr[n4 + 2 + 4] = li.specular.z;
1521
- p._specularMaterialArr[n4 + 3 + 4] = li.shininess;
1522
-
1523
- p._samplerArr[n] = n;
1524
-
1525
- gl.activeTexture(gl.TEXTURE0 + n);
1526
- gl.bindTexture(gl.TEXTURE_2D, m.texture || p.transparentTexture);
1527
-
1528
- n++;
1529
- }
1530
- i++;
1531
- li = layerSlice[i];
1532
- }
1533
-
1534
- if (notEmpty || !isOverlay) {
1535
- gl.uniform1i(shu.samplerCount, n);
1536
- gl.uniform1f(shu.height, currHeight);
1537
- gl.uniform1iv(shu.samplerArr, p._samplerArr);
1538
- gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
1539
- gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
1540
- gl.uniform4fv(shu.transparentColorArr, slice.transparentColorArr);
1541
-
1542
- // bind normalmap texture
1543
- if (p.lightEnabled) {
1544
- gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE + 3);
1545
- gl.bindTexture(gl.TEXTURE_2D, this.normalMapTexture || p.transparentTexture);
1546
- gl.uniform1i(shu.uNormalMap, p.SLICE_SIZE + 3);
1547
-
1548
- gl.uniform3fv(shu.uNormalMapBias, this.normalMapTextureBias);
1549
-
1550
- // bind segment specular and night material texture coordinates
1551
- gl.uniform4fv(shu.uGlobalTextureCoord, this._globalTextureCoordinates);
1552
-
1553
- gl.uniform3fv(shu.diffuseMaterial, p._diffuseMaterialArr);
1554
- gl.uniform3fv(shu.ambientMaterial, p._ambientMaterialArr);
1555
- gl.uniform4fv(shu.specularMaterial, p._specularMaterialArr);
1556
- }
1557
-
1558
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
1559
- gl.vertexAttribPointer(
1560
- sha.aVertexPositionHigh,
1561
- this.vertexPositionBufferHigh.itemSize,
1562
- gl.FLOAT,
1563
- false,
1564
- 0,
1565
- 0
1566
- );
1567
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
1568
- gl.vertexAttribPointer(
1569
- sha.aVertexPositionLow,
1570
- this.vertexPositionBufferLow.itemSize,
1571
- gl.FLOAT,
1572
- false,
1573
- 0,
1574
- 0
1575
- );
1576
-
1577
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
1578
- gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
1579
-
1580
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
1581
- gl.drawElements(p.drawMode, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
1582
- }
1583
- };
1584
-
1585
- Segment.prototype.heightPickingRendering = function (
1586
- sh,
1587
- layerSlice,
1588
- sliceIndex,
1589
- defaultTexture,
1590
- isOverlay
1591
- ) {
1592
- var gl = this.handler.gl;
1593
- var sha = sh.attributes,
1594
- shu = sh.uniforms;
1595
-
1596
- var pm = this.materials,
1597
- p = this.planet;
1598
-
1599
- // First always draw whole planet base layer segment with solid texture.
1600
- gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE);
1601
- gl.bindTexture(gl.TEXTURE_2D, defaultTexture || p.solidTextureOne);
1602
- gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE);
1603
-
1604
- var currHeight;
1605
- if (layerSlice) {
1606
- currHeight = layerSlice[0]._height;
1607
- } else {
1608
- currHeight = 0;
1609
- }
1610
-
1611
- var n = 0;
1612
-
1613
- var slice = this._renderingSlices[sliceIndex];
1614
-
1615
- var notEmpty = false;
1616
-
1617
- for (n = 0; n < slice.layers.length; n++) {
1618
- notEmpty = true;
1619
- p._samplerArr[n] = n;
1620
- gl.activeTexture(gl.TEXTURE0 + n);
1621
- gl.bindTexture(gl.TEXTURE_2D, pm[slice.layers[n]._id].texture || p.transparentTexture);
1622
- }
1623
-
1624
- if (notEmpty || !isOverlay) {
1625
- gl.uniform1i(shu.samplerCount, n);
1626
- gl.uniform1f(shu.height, currHeight);
1627
- gl.uniform1iv(shu.samplerArr, p._samplerArr);
1628
- gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
1629
- gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
1630
- gl.uniform4fv(shu.transparentColorArr, slice.transparentColorArr);
1631
-
1632
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
1633
- gl.vertexAttribPointer(
1634
- sha.aVertexPositionHigh,
1635
- this.vertexPositionBufferHigh.itemSize,
1636
- gl.FLOAT,
1637
- false,
1638
- 0,
1639
- 0
1640
- );
1641
-
1642
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
1643
- gl.vertexAttribPointer(
1644
- sha.aVertexPositionLow,
1645
- this.vertexPositionBufferLow.itemSize,
1646
- gl.FLOAT,
1647
- false,
1648
- 0,
1649
- 0
1650
- );
1651
-
1652
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
1653
- gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
1654
-
1655
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
1656
- gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
1657
- }
1658
- };
1659
-
1660
- Segment.prototype.colorPickingRendering = function (
1661
- sh,
1662
- layerSlice,
1663
- sliceIndex,
1664
- defaultTexture,
1665
- isOverlay
1666
- ) {
1667
- var gl = this.handler.gl;
1668
- var sha = sh.attributes,
1669
- shu = sh.uniforms;
1670
-
1671
- var pm = this.materials,
1672
- p = this.planet;
1673
-
1674
- var currHeight;
1675
- if (layerSlice) {
1676
- currHeight = layerSlice[0]._height;
1677
- } else {
1678
- currHeight = 0;
1679
- }
1680
-
1681
- var notEmpty = false;
1682
-
1683
- var slice = this._renderingSlices[sliceIndex];
1684
-
1685
- for (var n = 0; n < slice.layers.length; n++) {
1686
- notEmpty = true;
1687
-
1688
- var li = slice.layers[n];
1689
- var n4 = n * 4;
1690
-
1691
- p._pickingColorArr[n4] = li._pickingColor.x / 255.0;
1692
- p._pickingColorArr[n4 + 1] = li._pickingColor.y / 255.0;
1693
- p._pickingColorArr[n4 + 2] = li._pickingColor.z / 255.0;
1694
- p._pickingColorArr[n4 + 3] = li._pickingEnabled;
1695
-
1696
- p._samplerArr[n] = n;
1697
- gl.activeTexture(gl.TEXTURE0 + n);
1698
- gl.bindTexture(gl.TEXTURE_2D, pm[li._id].texture || this.planet.transparentTexture);
1699
-
1700
- p._pickingMaskArr[n] = n + p.SLICE_SIZE;
1701
- gl.activeTexture(gl.TEXTURE0 + n + p.SLICE_SIZE);
1702
- gl.bindTexture(gl.TEXTURE_2D, pm[li._id].pickingMask || this.planet.transparentTexture);
1703
- }
1704
-
1705
- if (notEmpty || !isOverlay) {
1706
- gl.uniform1i(shu.samplerCount, n);
1707
- gl.uniform1f(shu.height, currHeight);
1708
- gl.uniform1iv(shu.samplerArr, p._samplerArr);
1709
- gl.uniform1iv(shu.pickingMaskArr, p._pickingMaskArr);
1710
- gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
1711
- gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
1712
- gl.uniform4fv(shu.transparentColorArr, slice.transparentColorArr);
1713
- gl.uniform4fv(shu.pickingColorArr, p._pickingColorArr);
1714
-
1715
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
1716
- gl.vertexAttribPointer(
1717
- sha.aVertexPositionHigh,
1718
- this.vertexPositionBufferHigh.itemSize,
1719
- gl.FLOAT,
1720
- false,
1721
- 0,
1722
- 0
1723
- );
1724
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
1725
- gl.vertexAttribPointer(
1726
- sha.aVertexPositionLow,
1727
- this.vertexPositionBufferLow.itemSize,
1728
- gl.FLOAT,
1729
- false,
1730
- 0,
1731
- 0
1732
- );
1733
-
1734
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
1735
- gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
1736
-
1737
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
1738
- gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
1739
- }
1740
- };
1741
-
1742
- Segment.prototype.depthRendering = function (
1743
- sh,
1744
- layerSlice,
1745
- sliceIndex,
1746
- defaultTexture,
1747
- isOverlay
1748
- ) {
1749
- var gl = this.handler.gl;
1750
- var sha = sh.attributes,
1751
- shu = sh.uniforms;
1752
-
1753
- var pm = this.materials,
1754
- p = this.planet;
1755
-
1756
- // First always draw whole planet base layer segment with solid texture.
1757
- gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE);
1758
- gl.bindTexture(gl.TEXTURE_2D, defaultTexture || p.solidTextureOne);
1759
- gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE);
1760
-
1761
- var currHeight;
1762
- if (layerSlice) {
1763
- currHeight = layerSlice[0]._height;
1764
- } else {
1765
- currHeight = 0;
1766
- }
1767
-
1768
- var n = 0;
1769
-
1770
- var slice = this._renderingSlices[sliceIndex];
1771
-
1772
- var notEmpty = false;
1773
-
1774
- for (n = 0; n < slice.layers.length; n++) {
1775
- notEmpty = true;
1776
- p._samplerArr[n] = n;
1777
- gl.activeTexture(gl.TEXTURE0 + n);
1778
- gl.bindTexture(gl.TEXTURE_2D, pm[slice.layers[n]._id].texture || p.transparentTexture);
1779
- }
1780
-
1781
- if (notEmpty || !isOverlay) {
1782
- gl.uniform1i(shu.samplerCount, n);
1783
- gl.uniform1f(shu.height, currHeight);
1784
- gl.uniform1iv(shu.samplerArr, p._samplerArr);
1785
- gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
1786
- gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
1787
- gl.uniform4fv(shu.transparentColorArr, slice.transparentColorArr);
1788
-
1789
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
1790
- gl.vertexAttribPointer(
1791
- sha.aVertexPositionHigh,
1792
- this.vertexPositionBufferHigh.itemSize,
1793
- gl.FLOAT,
1794
- false,
1795
- 0,
1796
- 0
1797
- );
1798
-
1799
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
1800
- gl.vertexAttribPointer(
1801
- sha.aVertexPositionLow,
1802
- this.vertexPositionBufferLow.itemSize,
1803
- gl.FLOAT,
1804
- false,
1805
- 0,
1806
- 0
1807
- );
1808
-
1809
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
1810
- gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
1811
-
1812
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
1813
- gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
1814
- }
1815
- };
1816
-
1817
- Segment.prototype._getIndexBuffer = function () {
1818
- var s = this.node.sideSizeLog2;
1819
- var cache = this.planet._indexesCache[Math.log2(this.gridSize)][s[0]][s[1]][s[2]][s[3]];
1820
- if (!cache.buffer) {
1821
- let indexes = segmentHelper
1822
- .getInstance()
1823
- .createSegmentIndexes(Math.log2(this.gridSize), [s[0], s[1], s[2], s[3]]);
1824
- cache.buffer = this.planet.renderer.handler.createElementArrayBuffer(indexes, 1);
1825
- this.planet._indexesCacheToRemoveCounter++;
1826
- indexes = null;
1827
- }
1828
- return cache.buffer;
1829
- };
1830
-
1831
- Segment.prototype._collectVisibleNodes = function () {
1832
- this.planet._visibleNodes[this.node.nodeId] = this.node;
1833
- };
1834
-
1835
- Segment.prototype.layerOverlap = function (layer) {
1836
- return this._extent.overlaps(layer._extentMerc);
1837
- };
1838
-
1839
- Segment.prototype.getDefaultTexture = function () {
1840
- return this.planet.solidTextureOne;
1841
- };
1842
-
1843
- Segment.prototype.getExtentLonLat = function () {
1844
- return this._extentLonLat;
1845
- };
1846
-
1847
- Segment.prototype.getExtentMerc = function () {
1848
- return this._extent;
1849
- };
1850
-
1851
- Segment.prototype.getExtent = function () {
1852
- return this._extent;
1853
- };
1854
-
1855
- Segment.prototype.getNodeState = function () {
1856
- var vn = this.planet._visibleNodes[this.node.nodeId];
1857
- return (vn && vn.state) || NOTRENDERING;
1858
- };
1859
-
1860
- Segment.prototype.getNeighborSide = function (b) {
1861
- if (this.tileY === b.tileY) {
1862
- if (this.tileX === b.tileXE) {
1863
- return W;
1864
- } else if (this.tileX === b.tileXW) {
1865
- return E;
1866
- }
1867
- } else if (this.tileX === b.tileX) {
1868
- if (this.tileY === b.tileYS) {
1869
- return N;
1870
- } else if (this.tileY === b.tileYN) {
1871
- return S;
1872
- }
1873
- }
1874
-
1875
- return -1;
1876
- };
1877
-
1878
- export { Segment };
1
+ "use strict";
2
+
3
+ import * as mercator from "../mercator.js";
4
+ import { N, E, S, W, OPSIDE, NOTRENDERING } from "../quadTree/quadTree.js";
5
+ import { EPSG3857 } from "../proj/EPSG3857.js";
6
+ import { Extent } from "../Extent.js";
7
+ import { Layer } from "../layer/Layer.js";
8
+ import { LonLat } from "../LonLat.js";
9
+ import { Ray } from "../math/Ray.js";
10
+ import { Sphere } from "../bv/Sphere.js";
11
+ import { Box } from "../bv/Box.js";
12
+ import { Vec3 } from "../math/Vec3.js";
13
+ import * as segmentHelper from "../segment/segmentHelper.js";
14
+ import { getMatrixSubArray } from "../utils/shared.js";
15
+
16
+ export const MAX_NORMAL_ZOOM = 7;
17
+
18
+ var _tempHigh = new Vec3();
19
+ var _tempLow = new Vec3();
20
+
21
+ var _RenderingSlice = function (p) {
22
+ this.layers = [];
23
+ this.tileOffsetArr = new Float32Array(p.SLICE_SIZE_4);
24
+ this.visibleExtentOffsetArr = new Float32Array(p.SLICE_SIZE_4);
25
+ this.transparentColorArr = new Float32Array(p.SLICE_SIZE_4);
26
+
27
+ this.clear = function () {
28
+ this.layers = null;
29
+ this.tileOffsetArr = null;
30
+ this.visibleExtentOffsetArr = null;
31
+ this.transparentColorArr = null;
32
+ };
33
+ };
34
+
35
+ let _v0 = new Vec3(),
36
+ _v1 = new Vec3(),
37
+ _v2 = new Vec3(),
38
+ _v3 = new Vec3();
39
+
40
+ let _ray = new Ray(),
41
+ _rayEx = new Ray();
42
+
43
+ window.ELLNORM = false;
44
+
45
+ const _S = new Array(4);
46
+ _S[N] = 0;
47
+ _S[E] = 1;
48
+ _S[S] = 1;
49
+ _S[W] = 0;
50
+
51
+ const _V = new Array(4);
52
+ _V[N] = false;
53
+ _V[E] = true;
54
+ _V[S] = false;
55
+ _V[W] = true;
56
+
57
+ window.BBSC = 100;
58
+
59
+ /**
60
+ * Planet segment Web Mercator tile class that stored and rendered with quad tree.
61
+ * @class
62
+ * @param {quadTree.Node} node - Segment node.
63
+ * @param {Planet} planet - Current planet scene.
64
+ * @param {Number} tileZoom - Zoom index.
65
+ * @param {Extent} extent - Segment extent.
66
+ */
67
+ class Segment {
68
+ /**
69
+ * @param {quadTree.Node} node - Segment node.
70
+ * @param {Planet} planet - Current planet scene.
71
+ * @param {number} tileZoom - Zoom index.
72
+ * @param {Extent} extent - Segment extent.
73
+ */
74
+ constructor(node, planet, tileZoom, extent) {
75
+ this.isPole = false;
76
+
77
+ this._tileGroup = 0;
78
+
79
+ this._projection = EPSG3857;
80
+
81
+ /**
82
+ * Quad tree node of the segment.
83
+ * @type {quadTree.Node}
84
+ */
85
+ this.node = node;
86
+
87
+ /**
88
+ * Planet pointer.
89
+ * @type {Planet}
90
+ */
91
+ this.planet = planet;
92
+
93
+ /**
94
+ * WebGl handler pointer.
95
+ * @type {Handler}
96
+ */
97
+ this.handler = planet.renderer.handler;
98
+
99
+ /**
100
+ * Segment bounding sphere
101
+ * @type {Sphere}
102
+ */
103
+ this.bsphere = new Sphere();
104
+
105
+ this._plainRadius = 0;
106
+
107
+ /**
108
+ * Segment bounding box.
109
+ * @type {Box}
110
+ */
111
+ this.bbox = new Box();
112
+
113
+ this._swNorm = null;
114
+ this._nwNorm = null;
115
+ this._seNorm = null;
116
+ this._neNorm = null;
117
+
118
+ /**
119
+ * Geographical extent.
120
+ * @type {Extent}
121
+ */
122
+ this._extent = extent;
123
+
124
+ this._extentLonLat = null;
125
+
126
+ /**
127
+ * Vertices grid size.
128
+ * @type {number}
129
+ */
130
+ this.gridSize = planet.terrain.gridSizeByZoom[tileZoom];
131
+
132
+ this.fileGridSize = 0;
133
+
134
+ /**
135
+ * Tile zoom index.
136
+ * @type {number}
137
+ */
138
+ this.tileZoom = tileZoom;
139
+
140
+ /**
141
+ * Horizontal tile index.
142
+ * @type {number}
143
+ */
144
+ this.tileX = 0;
145
+
146
+ this.tileXE = 0;
147
+
148
+ this.tileXW = 0;
149
+
150
+ this.tileYN = 0;
151
+
152
+ this.tileYS = 0;
153
+
154
+ /**
155
+ * Vertical tile index.
156
+ * @type {number}
157
+ */
158
+ this.tileY = 0;
159
+
160
+ this.tileIndex = "";
161
+
162
+ this._assignTileIndexes();
163
+
164
+ /**
165
+ * Texture materials array.
166
+ * @type {Array.<planetSegment.Material>}
167
+ */
168
+ this.materials = [];
169
+
170
+ /**
171
+ * Plain segment vertices was created.
172
+ * @type {boolean}
173
+ */
174
+ this.plainReady = false;
175
+
176
+ /**
177
+ * Segment is ready to create plain vertices.
178
+ * @type {boolean}
179
+ */
180
+ this.initialized = false;
181
+
182
+ /**
183
+ * Normal map is allready made.
184
+ * @type {boolean}
185
+ */
186
+ this.normalMapReady = false;
187
+
188
+ /**
189
+ * Parent normal map is made allready(optimization parameter).
190
+ * @type {boolean}
191
+ */
192
+ this.parentNormalMapReady = false;
193
+
194
+ /**
195
+ * Terrain is allready applied flag.
196
+ * @type {boolean}
197
+ */
198
+ this.terrainReady = false;
199
+
200
+ /**
201
+ * Terrain is loading now flag.
202
+ * @type {boolean}
203
+ */
204
+ this.terrainIsLoading = false;
205
+
206
+ /**
207
+ * Terrain existing flag.
208
+ * @type {boolean}
209
+ */
210
+ this.terrainExists = false;
211
+
212
+ this.plainVertices = null;
213
+ this.plainVerticesHigh = null;
214
+ this.plainVerticesLow = null;
215
+
216
+ this.plainNormals = null;
217
+
218
+ this.terrainVertices = null;
219
+ this.terrainVerticesHigh = null;
220
+ this.terrainVerticesLow = null;
221
+ this.noDataVertices = null;
222
+
223
+ this.tempVertices = null;
224
+ this.tempVerticesHigh = null;
225
+ this.tempVerticesLow = null;
226
+
227
+ this.normalMapTexture = null;
228
+ this.normalMapTextureBias = new Float32Array(3);
229
+ this.normalMapVertices = null;
230
+ this.normalMapVerticesHigh = null;
231
+ this.normalMapVerticesLow = null;
232
+ this.normalMapNormals = null;
233
+
234
+ this.vertexNormalBuffer = null;
235
+ this.vertexPositionBuffer = null;
236
+ this.vertexPositionBufferHigh = null;
237
+ this.vertexPositionBufferLow = null;
238
+ this.vertexTextureCoordBuffer = null;
239
+
240
+ this._globalTextureCoordinates = new Float32Array(4);
241
+ this._inTheQueue = false;
242
+ this._appliedNeighborsZoom = [0, 0, 0, 0];
243
+
244
+ this._renderingSlices = [];
245
+
246
+ this._indexBuffer = null;
247
+
248
+ this.readyToEngage = false;
249
+
250
+ this.plainProcessing = false;
251
+ }
252
+
253
+ /**
254
+ * Returns that segment good for rendering with camera by current lod ratio.
255
+ * @public
256
+ * @param {Camera} camera - Camera object.
257
+ * @returns {boolean} -
258
+ */
259
+ acceptForRendering(camera) {
260
+ return (
261
+ camera.projectedSize(this.bsphere.center, this._plainRadius) <
262
+ 256 / this.planet._lodRatio
263
+ );
264
+ }
265
+
266
+ /**
267
+ * Returns entity terrain point.
268
+ * @public
269
+ * @param {Entity} entity - Entity.
270
+ * @param {Vec3} res - Point coordinates.
271
+ * @param {Vec3} [normal] - Terrain point normal.
272
+ * @returns {Vec3} -
273
+ */
274
+ getEntityTerrainPoint(entity, res, normal) {
275
+ return this.getTerrainPoint(entity._cartesian, entity._lonlatMerc, res, normal);
276
+ }
277
+
278
+ isEntityInside(e) {
279
+ return this._extent.isInside(e._lonlatMerc);
280
+ }
281
+
282
+ /**
283
+ * Returns distance from object to terrain coordinates and terrain point that calculates out in the res parameter.
284
+ * @public
285
+ * @param {Vec3} xyz - Cartesian object position.
286
+ * @param {LonLat} insideSegmentPosition - Geodetic object position.
287
+ * @param {Vec3} [res] - Result cartesian coordiantes on the terrain.
288
+ * @param {Vec3} [normal] - Terrain point normal.
289
+ * @returns {number} -
290
+ */
291
+ getTerrainPoint(xyz, insideSegmentPosition, res, normal) {
292
+ var verts = this.tempVertices;
293
+
294
+ _ray.set(xyz, xyz.negateTo());
295
+
296
+ if (verts) {
297
+ var ne = this._extent.northEast,
298
+ sw = this._extent.southWest,
299
+ size = Math.sqrt(verts.length / 3) - 1;
300
+
301
+ var xmax = ne.lon,
302
+ ymax = ne.lat,
303
+ xmin = sw.lon,
304
+ ymin = sw.lat,
305
+ x = insideSegmentPosition.lon,
306
+ y = insideSegmentPosition.lat;
307
+
308
+ var sxn = xmax - xmin,
309
+ syn = ymax - ymin;
310
+
311
+ var qx = sxn / size,
312
+ qy = syn / size;
313
+
314
+ var xn = x - xmin,
315
+ yn = y - ymin;
316
+
317
+ var indX = Math.floor(xn / qx),
318
+ indY = Math.floor(size - yn / qy);
319
+
320
+ if (verts && verts.length) {
321
+ var ind_v0 = ((size + 1) * indY + indX) * 3;
322
+ var ind_v2 = ((size + 1) * (indY + 1) + indX) * 3;
323
+
324
+ _v0.set(verts[ind_v0], verts[ind_v0 + 1], verts[ind_v0 + 2]);
325
+ _v1.set(verts[ind_v0 + 3], verts[ind_v0 + 4], verts[ind_v0 + 5]);
326
+ _v2.set(verts[ind_v2], verts[ind_v2 + 1], verts[ind_v2 + 2]);
327
+
328
+ let d = _ray.hitTriangle(_v0, _v1, _v2, res, normal);
329
+
330
+ if (d === Ray.INSIDE) {
331
+ return xyz.distance(res);
332
+ } else if (d === Ray.AWAY) {
333
+ _rayEx.set(xyz, xyz);
334
+ let d = _rayEx.hitTriangle(_v0, _v1, _v2, res, normal);
335
+ if (d === Ray.INSIDE) {
336
+ return -xyz.distance(res);
337
+ }
338
+ }
339
+
340
+ _v3.set(verts[ind_v2 + 3], verts[ind_v2 + 4], verts[ind_v2 + 5]);
341
+
342
+ d = _ray.hitTriangle(_v1, _v3, _v2, res, normal);
343
+ if (d === Ray.INSIDE) {
344
+ return xyz.distance(res);
345
+ } else if (d === Ray.AWAY) {
346
+ _rayEx.set(xyz, xyz);
347
+ let d = _rayEx.hitTriangle(_v1, _v3, _v2, res, normal);
348
+ if (d === Ray.INSIDE) {
349
+ return -xyz.distance(res);
350
+ }
351
+ }
352
+
353
+ if (d === Ray.AWAY) {
354
+ return -xyz.distance(res);
355
+ }
356
+
357
+ return xyz.distance(res);
358
+ }
359
+
360
+ res.copy(this.planet.ellipsoid.hitRay(_ray.origin, _ray.direction));
361
+ normal && normal.copy(xyz.normal());
362
+ return xyz.distance(res);
363
+ } else {
364
+ normal && normal.copy(xyz.normal());
365
+ return xyz.distance(this.planet.ellipsoid.hitRay(_ray.origin, _ray.direction));
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Project wgs86 to segment native projection.
371
+ * @public
372
+ * @param {LonLat} lonlat - Coordinates to project.
373
+ * @returns {LonLat} -
374
+ */
375
+ projectNative(lonlat) {
376
+ return lonlat.forwardMercator();
377
+ }
378
+
379
+ /**
380
+ *
381
+ * @param {boolean} forceLoading
382
+ */
383
+ loadTerrain(forceLoading) {
384
+ if (this.tileZoom < this.planet.terrain.minZoom) {
385
+ this.terrainIsLoading = true;
386
+
387
+ this.elevationsNotExists();
388
+
389
+ if (!this._inTheQueue) {
390
+ this.planet._normalMapCreator.queue(this);
391
+ }
392
+ } else {
393
+ if (this.tileZoom > this.planet.terrain.maxZoom) {
394
+ this.elevationsNotExists();
395
+ } else if (!this.terrainIsLoading && !this.terrainReady) {
396
+ this.planet.terrain.loadTerrain(this, forceLoading);
397
+ }
398
+ }
399
+ }
400
+
401
+ /**
402
+ * Terrain obtained from server.
403
+ * @param {Float32Array} elevations - Elevation data.
404
+ */
405
+ elevationsExists(elevations) {
406
+ if (this.plainReady && this.terrainIsLoading) {
407
+ this.planet._terrainWorker.make(this, elevations);
408
+
409
+ this.plainVerticesHigh = null;
410
+ this.plainVerticesLow = null;
411
+
412
+ this.normalMapVerticesHigh = null;
413
+ this.normalMapVerticesLow = null;
414
+
415
+ if (!this.planet.terrain.equalizeVertices) {
416
+ this.tempVerticesHigh = null;
417
+ this.tempVerticesLow = null;
418
+ }
419
+ }
420
+ }
421
+
422
+ _checkEqualization(neighborSide, neigborNode) {
423
+ return (
424
+ neigborNode && this.tileZoom >= neigborNode.segment.tileZoom
425
+
426
+ //&&
427
+ //(
428
+ // this.node.equalizedNeighborId[neighborSide] !== neigborNode.appliedTerrainNodeId ||
429
+ // this.node.equalizedNeighborGridSize[neighborSide] !== neigborNode.segment.gridSize
430
+ //||
431
+
432
+ // neigborNode.equalizedNeighborId[OPSIDE[neighborSide]] !== this.node.appliedTerrainNodeId ||
433
+ // neigborNode.equalizedNeighborGridSize[OPSIDE[neighborSide]] !== this.gridSize
434
+ //)
435
+ );
436
+ }
437
+
438
+ equalize() {
439
+ if (this.tileZoom < 8 || this.gridSize < 2) {
440
+ return;
441
+ }
442
+
443
+ this.readyToEngage = true;
444
+ let nn = this.node.neighbors;
445
+ let v = this.tempVertices,
446
+ vHigh = this.tempVerticesHigh,
447
+ vLow = this.tempVerticesLow;
448
+ let gs = this.gridSize,
449
+ gsOne = gs + 1;
450
+
451
+ let n = nn[N][0];
452
+ if (this._checkEqualization(N, n)) {
453
+ //this.node.equalizedNeighborId[N] = n.appliedTerrainNodeId;
454
+ //this.node.equalizedNeighborGridSize[N] = n.segment.gridSize;
455
+
456
+ //n.equalizedNeighborId[OPSIDE[N]] = this.node.appliedTerrainNodeId;
457
+ //n.equalizedNeighborGridSize[OPSIDE[N]] = this.gridSize;
458
+
459
+ this.readyToEngage = true;
460
+
461
+ let offset = this.node.getOffsetOppositeNeighbourSide(n, N);
462
+
463
+ let nv = n.segment.tempVertices,
464
+ nvHigh = n.segment.tempVerticesHigh,
465
+ nvLow = n.segment.tempVerticesLow;
466
+
467
+ let n_gs = n.segment.gridSize,
468
+ n_gsOne = n_gs + 1;
469
+
470
+ let dz = 1 / (1 << (this.tileZoom - n.segment.tileZoom));
471
+
472
+ let inc = Math.max(gs / (n_gs * dz), 1),
473
+ n_inc = Math.max((n_gs * dz) / gs, 1),
474
+ n_offset = offset * n_gs;
475
+
476
+ for (let k = 0, nk = n_offset; k < gsOne; k += inc, nk += n_inc) {
477
+ const index = k * 3;
478
+ const n_index = (n_gsOne * n_gs + nk) * 3;
479
+
480
+ v[index] = nv[n_index];
481
+ v[index + 1] = nv[n_index + 1];
482
+ v[index + 2] = nv[n_index + 2];
483
+
484
+ vHigh[index] = nvHigh[n_index];
485
+ vHigh[index + 1] = nvHigh[n_index + 1];
486
+ vHigh[index + 2] = nvHigh[n_index + 2];
487
+
488
+ vLow[index] = nvLow[n_index];
489
+ vLow[index + 1] = nvLow[n_index + 1];
490
+ vLow[index + 2] = nvLow[n_index + 2];
491
+ }
492
+ }
493
+
494
+ n = nn[E][0];
495
+ if (this._checkEqualization(E, n)) {
496
+ //this.node.equalizedNeighborId[E] = n.appliedTerrainNodeId;
497
+ //this.node.equalizedNeighborGridSize[E] = n.segment.gridSize;
498
+
499
+ //n.equalizedNeighborId[OPSIDE[E]] = this.node.appliedTerrainNodeId;
500
+ //n.equalizedNeighborGridSize[OPSIDE[E]] = this.gridSize;
501
+
502
+ this.readyToEngage = true;
503
+
504
+ let offset = this.node.getOffsetOppositeNeighbourSide(n, E);
505
+
506
+ let nv = n.segment.tempVertices,
507
+ nvHigh = n.segment.tempVerticesHigh,
508
+ nvLow = n.segment.tempVerticesLow;
509
+
510
+ let n_gs = n.segment.gridSize,
511
+ n_gsOne = n_gs + 1;
512
+
513
+ let dz = 1 / (1 << (this.tileZoom - n.segment.tileZoom));
514
+
515
+ let inc = Math.max(gs / (n_gs * dz), 1),
516
+ n_inc = Math.max((n_gs * dz) / gs, 1),
517
+ n_offset = offset * n_gs;
518
+
519
+ for (let k = 0, nk = n_offset; k < gsOne; k += inc, nk += n_inc) {
520
+ const index = (gsOne * k + gs) * 3;
521
+ const n_index = n_gsOne * nk * 3;
522
+
523
+ v[index] = nv[n_index];
524
+ v[index + 1] = nv[n_index + 1];
525
+ v[index + 2] = nv[n_index + 2];
526
+
527
+ vHigh[index] = nvHigh[n_index];
528
+ vHigh[index + 1] = nvHigh[n_index + 1];
529
+ vHigh[index + 2] = nvHigh[n_index + 2];
530
+
531
+ vLow[index] = nvLow[n_index];
532
+ vLow[index + 1] = nvLow[n_index + 1];
533
+ vLow[index + 2] = nvLow[n_index + 2];
534
+ }
535
+ }
536
+
537
+ n = nn[S][0];
538
+ if (this._checkEqualization(S, n)) {
539
+ //this.node.equalizedNeighborId[S] = n.appliedTerrainNodeId;
540
+ //this.node.equalizedNeighborGridSize[S] = n.segment.gridSize;
541
+
542
+ //n.equalizedNeighborId[OPSIDE[S]] = this.node.appliedTerrainNodeId;
543
+ //n.equalizedNeighborGridSize[OPSIDE[S]] = this.gridSize;
544
+
545
+ this.readyToEngage = true;
546
+
547
+ let offset = this.node.getOffsetOppositeNeighbourSide(n, S);
548
+
549
+ let nv = n.segment.tempVertices,
550
+ nvHigh = n.segment.tempVerticesHigh,
551
+ nvLow = n.segment.tempVerticesLow;
552
+
553
+ let n_gs = n.segment.gridSize; // n_gsOne = n_gs + 1;
554
+
555
+ let dz = 1 / (1 << (this.tileZoom - n.segment.tileZoom));
556
+
557
+ let inc = Math.max(gs / (n_gs * dz), 1),
558
+ n_inc = Math.max((n_gs * dz) / gs, 1),
559
+ n_offset = offset * n_gs;
560
+
561
+ for (let k = 0, nk = n_offset; k < gsOne; k += inc, nk += n_inc) {
562
+ const index = (gsOne * gs + k) * 3;
563
+ const n_index = nk * 3;
564
+
565
+ v[index] = nv[n_index];
566
+ v[index + 1] = nv[n_index + 1];
567
+ v[index + 2] = nv[n_index + 2];
568
+
569
+ vHigh[index] = nvHigh[n_index];
570
+ vHigh[index + 1] = nvHigh[n_index + 1];
571
+ vHigh[index + 2] = nvHigh[n_index + 2];
572
+
573
+ vLow[index] = nvLow[n_index];
574
+ vLow[index + 1] = nvLow[n_index + 1];
575
+ vLow[index + 2] = nvLow[n_index + 2];
576
+ }
577
+ }
578
+
579
+ n = nn[W][0];
580
+ if (this._checkEqualization(W, n)) {
581
+ //this.node.equalizedNeighborId[W] = n.appliedTerrainNodeId;
582
+ //this.node.equalizedNeighborGridSize[W] = n.segment.gridSize;
583
+
584
+ //n.equalizedNeighborId[OPSIDE[W]] = this.node.appliedTerrainNodeId;
585
+ //n.equalizedNeighborGridSize[OPSIDE[W]] = this.gridSize;
586
+
587
+ this.readyToEngage = true;
588
+
589
+ let offset = this.node.getOffsetOppositeNeighbourSide(n, W);
590
+
591
+ let nv = n.segment.tempVertices,
592
+ nvHigh = n.segment.tempVerticesHigh,
593
+ nvLow = n.segment.tempVerticesLow;
594
+
595
+ let n_gs = n.segment.gridSize,
596
+ n_gsOne = n_gs + 1;
597
+
598
+ let dz = 1 / (1 << (this.tileZoom - n.segment.tileZoom));
599
+
600
+ let inc = Math.max(gs / (n_gs * dz), 1),
601
+ n_inc = Math.max((n_gs * dz) / gs, 1),
602
+ n_offset = offset * n_gs;
603
+
604
+ for (let k = 0, nk = n_offset; k < gsOne; k += inc, nk += n_inc) {
605
+ const index = gsOne * k * 3;
606
+ const n_index = (n_gsOne * nk + n_gs) * 3;
607
+
608
+ v[index] = nv[n_index];
609
+ v[index + 1] = nv[n_index + 1];
610
+ v[index + 2] = nv[n_index + 2];
611
+
612
+ vHigh[index] = nvHigh[n_index];
613
+ vHigh[index + 1] = nvHigh[n_index + 1];
614
+ vHigh[index + 2] = nvHigh[n_index + 2];
615
+
616
+ vLow[index] = nvLow[n_index];
617
+ vLow[index + 1] = nvLow[n_index + 1];
618
+ vLow[index + 2] = nvLow[n_index + 2];
619
+ }
620
+ }
621
+ }
622
+
623
+ engage() {
624
+ this.readyToEngage = false;
625
+ this.createCoordsBuffers(this.tempVerticesHigh, this.tempVerticesLow, this.gridSize);
626
+ }
627
+
628
+ _plainSegmentWorkerCallback(data) {
629
+ this.plainProcessing = false;
630
+
631
+ if (this.initialized && !this.terrainReady) {
632
+ this.plainVertices = data.plainVertices;
633
+ this.plainVerticesHigh = data.plainVerticesHigh;
634
+ this.plainVerticesLow = data.plainVerticesLow;
635
+
636
+ this.plainNormals = data.plainNormals;
637
+
638
+ this.normalMapNormals = data.normalMapNormals;
639
+ this.normalMapVertices = data.normalMapVertices;
640
+ this.normalMapVerticesHigh = data.normalMapVerticesHigh;
641
+ this.normalMapVerticesLow = data.normalMapVerticesLow;
642
+
643
+ this.terrainVertices = this.plainVertices;
644
+ this.terrainVerticesHigh = this.plainVerticesHigh;
645
+ this.terrainVerticesLow = this.plainVerticesLow;
646
+
647
+ this.fileGridSize = Math.sqrt(data.normalMapVertices.length / 3) - 1;
648
+
649
+ this._plainRadius = data.plainRadius;
650
+
651
+ this.plainReady = true;
652
+ }
653
+ }
654
+
655
+ _terrainWorkerCallback(data) {
656
+ if (this.plainReady) {
657
+ this.readyToEngage = true;
658
+
659
+ this.normalMapNormals = null;
660
+
661
+ this.normalMapVertices = null;
662
+ this.normalMapVerticesHigh = null;
663
+ this.normalMapVerticesLow = null;
664
+
665
+ this.terrainVertices = null;
666
+ this.terrainVerticesHigh = null;
667
+ this.terrainVerticesLow = null;
668
+ this.noDataVertices = null;
669
+
670
+ this.tempVertices = null;
671
+ this.tempVerticesHigh = null;
672
+ this.tempVerticesLow = null;
673
+
674
+ this.normalMapNormals = data.normalMapNormals;
675
+ this.normalMapVertices = data.normalMapVertices;
676
+ this.normalMapVerticesHigh = data.normalMapVerticesHigh;
677
+ this.normalMapVerticesLow = data.normalMapVerticesLow;
678
+
679
+ this.terrainVertices = data.terrainVertices;
680
+ this.terrainVerticesHigh = data.terrainVerticesHigh;
681
+ this.terrainVerticesLow = data.terrainVerticesLow;
682
+
683
+ this.noDataVertices = data.noDataVertices;
684
+
685
+ this.tempVertices = this.terrainVertices;
686
+ this.tempVerticesHigh = this.terrainVerticesHigh;
687
+ this.tempVerticesLow = this.terrainVerticesLow;
688
+
689
+ this.setBoundingVolumeArr(data.bounds);
690
+
691
+ //var b = data.bounds;
692
+
693
+ //this.setBoundingSphere(
694
+ // b[0] + (b[1] - b[0]) * 0.5,
695
+ // b[2] + (b[3] - b[2]) * 0.5,
696
+ // b[4] + (b[5] - b[4]) * 0.5,
697
+ // new Vec3(b[0], b[2], b[4])
698
+ //);
699
+
700
+ this.gridSize = Math.sqrt(this.terrainVertices.length / 3) - 1;
701
+ this.node.appliedTerrainNodeId = this.node.nodeId;
702
+
703
+ this.terrainReady = true;
704
+ this.terrainIsLoading = false;
705
+ this.parentNormalMapReady = true;
706
+ this.terrainExists = true;
707
+
708
+ if (!this.normalMapTexturePtr) {
709
+ var nmc = this.planet._normalMapCreator;
710
+ this.normalMapTexturePtr = this.planet.renderer.handler.createEmptyTexture_l(
711
+ nmc._width,
712
+ nmc._height
713
+ );
714
+ }
715
+
716
+ if (this.planet.lightEnabled) {
717
+ this.planet._normalMapCreator.queue(this);
718
+ }
719
+ }
720
+ }
721
+
722
+ /**
723
+ * Terrain is not obtained or not exists on the server.
724
+ */
725
+ elevationsNotExists() {
726
+ if (this.planet && this.tileZoom <= this.planet.terrain.maxZoom) {
727
+ if (this.plainReady && this.terrainIsLoading) {
728
+ this.terrainIsLoading = false;
729
+
730
+ this.node.appliedTerrainNodeId = this.node.nodeId;
731
+
732
+ if (this.planet.lightEnabled && !this._inTheQueue) {
733
+ this.planet._normalMapCreator.queue(this);
734
+ }
735
+
736
+ this.readyToEngage = true;
737
+ }
738
+
739
+ this.terrainVertices = this.plainVertices;
740
+ this.terrainVerticesHigh = this.plainVerticesHigh;
741
+ this.terrainVerticesLow = this.plainVerticesLow;
742
+
743
+ this.tempVertices = this.terrainVertices;
744
+ this.tempVerticesHigh = this.terrainVerticesHigh;
745
+ this.tempVerticesLow = this.terrainVerticesLow;
746
+
747
+ this.noDataVertices = null;
748
+
749
+ this.fileGridSize = Math.sqrt(this.terrainVertices.length / 3) - 1;
750
+ this.gridSize = this.fileGridSize;
751
+ this.terrainReady = true;
752
+ this.terrainExists = false;
753
+ }
754
+ }
755
+ _normalMapEdgeEqualize(side) {
756
+ let nn = this.node.neighbors;
757
+ let n = nn[side][0];
758
+ let maxZ = this.planet.terrain.maxZoom;
759
+
760
+ if (this.tileZoom === maxZ) {
761
+ if (!(nn[0].length || nn[1].length || nn[2].length || nn[3].length)) {
762
+ n = this.node.getEqualNeighbor(side);
763
+ }
764
+ }
765
+
766
+ let b = n && n.segment,
767
+ s = this;
768
+
769
+ if (
770
+ n &&
771
+ b &&
772
+ b.terrainReady &&
773
+ b.terrainExists &&
774
+ b.tileZoom <= maxZ &&
775
+ s._appliedNeighborsZoom[side] !== b.tileZoom
776
+ ) {
777
+ s._appliedNeighborsZoom[side] = b.tileZoom;
778
+
779
+ let seg_a = s.normalMapNormals,
780
+ seg_b = b.normalMapNormals;
781
+
782
+ if (!(seg_a && seg_b)) return;
783
+
784
+ let seg_a_raw = s.normalMapNormals,
785
+ seg_b_raw = b.normalMapNormals;
786
+
787
+ // let seg_a_verts = s.terrainVertices,
788
+ // seg_b_verts = s.terrainVertices;
789
+
790
+ let s_gs = Math.sqrt(seg_a.length / 3),
791
+ // b_gs = Math.sqrt(seg_b.length / 3),
792
+ s_gs1 = s_gs - 1;
793
+ // b_gs1 = b_gs - 1;
794
+
795
+ const i_a = s_gs1 * _S[side];
796
+
797
+ let nx, ny, nz, q;
798
+
799
+ if (s.tileZoom === b.tileZoom) {
800
+ const i_b = s_gs1 - i_a;
801
+
802
+ if (_V[side]) {
803
+ for (let k = 0; k < s_gs; k++) {
804
+ let vInd_a = (k * s_gs + i_a) * 3,
805
+ vInd_b = (k * s_gs + i_b) * 3;
806
+
807
+ nx = seg_a_raw[vInd_a] + seg_b_raw[vInd_b];
808
+ ny = seg_a_raw[vInd_a + 1] + seg_b_raw[vInd_b + 1];
809
+ nz = seg_a_raw[vInd_a + 2] + seg_b_raw[vInd_b + 2];
810
+
811
+ q = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
812
+
813
+ seg_b[vInd_b] = seg_a[vInd_a] = nx * q;
814
+ seg_b[vInd_b + 1] = seg_a[vInd_a + 1] = ny * q;
815
+ seg_b[vInd_b + 2] = seg_a[vInd_a + 2] = nz * q;
816
+ }
817
+ } else {
818
+ for (let k = 0; k < s_gs; k++) {
819
+ let vInd_a = (i_a * s_gs + k) * 3,
820
+ vInd_b = (i_b * s_gs + k) * 3;
821
+
822
+ nx = seg_a_raw[vInd_a] + seg_b_raw[vInd_b];
823
+ ny = seg_a_raw[vInd_a + 1] + seg_b_raw[vInd_b + 1];
824
+ nz = seg_a_raw[vInd_a + 2] + seg_b_raw[vInd_b + 2];
825
+
826
+ q = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
827
+
828
+ seg_b[vInd_b] = seg_a[vInd_a] = nx * q;
829
+ seg_b[vInd_b + 1] = seg_a[vInd_a + 1] = ny * q;
830
+ seg_b[vInd_b + 2] = seg_a[vInd_a + 2] = nz * q;
831
+ }
832
+ }
833
+
834
+ if (!b._inTheQueue && b._appliedNeighborsZoom[OPSIDE[side]] !== s.tileZoom) {
835
+ b._appliedNeighborsZoom[OPSIDE[side]] = s.tileZoom;
836
+ s.planet._normalMapCreator.queue(b);
837
+ }
838
+ }
839
+ }
840
+ }
841
+
842
+ applyTerrain(elevations) {
843
+ if (elevations) {
844
+ this.elevationsExists(elevations);
845
+ } else {
846
+ this.elevationsNotExists();
847
+ }
848
+ }
849
+
850
+ /**
851
+ * Delete segment gl buffers.
852
+ */
853
+ deleteBuffers() {
854
+ var gl = this.handler.gl;
855
+ gl.deleteBuffer(this.vertexNormalBuffer);
856
+ gl.deleteBuffer(this.vertexPositionBuffer);
857
+ gl.deleteBuffer(this.vertexPositionBufferHigh);
858
+ gl.deleteBuffer(this.vertexPositionBufferLow);
859
+
860
+ this.vertexNormalBuffer = null;
861
+ this.vertexPositionBuffer = null;
862
+ this.vertexPositionBufferHigh = null;
863
+ this.vertexPositionBufferLow = null;
864
+ this.vertexTextureCoordBuffer = null;
865
+ }
866
+
867
+ /**
868
+ * Delete materials.
869
+ */
870
+ deleteMaterials() {
871
+ var m = this.materials;
872
+ for (var i = 0; i < m.length; i++) {
873
+ var mi = m[i];
874
+ if (mi) {
875
+ mi.clear();
876
+ }
877
+ }
878
+ this.materials.length = 0;
879
+ }
880
+
881
+ /**
882
+ * Delete elevation data.
883
+ */
884
+ deleteElevations() {
885
+ this.terrainExists = false;
886
+ this.terrainReady = false;
887
+ this.terrainIsLoading = false;
888
+
889
+ this.normalMapVertices = null;
890
+ this.normalMapVerticesHigh = null;
891
+ this.normalMapVerticesLow = null;
892
+
893
+ this.normalMapNormals = null;
894
+
895
+ this.tempVertices = null;
896
+ this.tempVerticesHigh = null;
897
+ this.tempVerticesLow = null;
898
+
899
+ this.terrainVertices = null;
900
+ this.terrainVerticesHigh = null;
901
+ this.terrainVerticesLow = null;
902
+ this.noDataVertices = null;
903
+
904
+ this.plainVertices = null;
905
+ this.plainVerticesHigh = null;
906
+ this.plainVerticesLow = null;
907
+
908
+ this.plainNormals = null;
909
+
910
+ if (this.normalMapReady) {
911
+ this.handler.gl.deleteTexture(this.normalMapTexture);
912
+ }
913
+ this.normalMapReady = false;
914
+ this.parentNormalMapReady = false;
915
+ this._appliedNeighborsZoom = [0, 0, 0, 0];
916
+ this.normalMapTextureBias[0] = 0;
917
+ this.normalMapTextureBias[1] = 0;
918
+ this.normalMapTextureBias[2] = 1;
919
+ this._inTheQueue = false;
920
+ }
921
+
922
+ /**
923
+ * Clear but not destroy segment data.
924
+ */
925
+ clearSegment() {
926
+ this.plainReady = false;
927
+ this.initialized = false;
928
+ this.deleteBuffers();
929
+ this.deleteMaterials();
930
+ this.deleteElevations();
931
+ }
932
+
933
+ /**
934
+ * Removes cache records.
935
+ */
936
+ _freeCache() {
937
+ this.planet._quadTreeNodesCacheMerc[this.tileIndex] = null;
938
+ delete this.planet._quadTreeNodesCacheMerc[this.tileIndex];
939
+ }
940
+
941
+ /**
942
+ * Clear and destroy all segment data.
943
+ */
944
+ destroySegment() {
945
+ this._freeCache();
946
+
947
+ this.clearSegment();
948
+
949
+ var i = this._renderingSlices.length;
950
+ while (i--) {
951
+ this._renderingSlices[i].clear();
952
+ }
953
+
954
+ this._renderingSlices = null;
955
+
956
+ this.node = null;
957
+
958
+ this.planet = null;
959
+ this.handler = null;
960
+ this.bbox = null;
961
+ this.bsphere = null;
962
+ this._extent = null;
963
+
964
+ this.materials = null;
965
+
966
+ this.plainVertices = null;
967
+ this.plainVerticesHigh = null;
968
+ this.plainVerticesLow = null;
969
+ this.plainNormals = null;
970
+
971
+ this.terrainVertices = null;
972
+ this.terrainVerticesHigh = null;
973
+ this.terrainVerticesLow = null;
974
+ this.noDataVertices = null;
975
+
976
+ this.tempVertices = null;
977
+ this.tempVerticesHigh = null;
978
+ this.tempVerticesLow = null;
979
+
980
+ this.normalMapTexture = null;
981
+ this.normalMapTextureBias = null;
982
+ this.normalMapVertices = null;
983
+ this.normalMapVerticesHigh = null;
984
+ this.normalMapVerticesLow = null;
985
+ this.normalMapNormals = null;
986
+
987
+ this.vertexNormalBuffer = null;
988
+ this.vertexPositionBuffer = null;
989
+ this.vertexPositionBufferHigh = null;
990
+ this.vertexPositionBufferLow = null;
991
+ this.vertexTextureCoordBuffer = null;
992
+
993
+ this._tileOffsetArr = null;
994
+ this._visibleExtentOffsetArr = null;
995
+
996
+ this._projection = null;
997
+ this._appliedNeighborsZoom = null;
998
+
999
+ this._globalTextureCoordinates = null;
1000
+ }
1001
+
1002
+ _setExtentLonLat() {
1003
+ this._extentLonLat = this._extent.inverseMercator();
1004
+ }
1005
+
1006
+ /**
1007
+ * Creates bound volumes by segment geographical extent.
1008
+ */
1009
+ createBoundsByExtent() {
1010
+ var ellipsoid = this.planet.ellipsoid,
1011
+ extent = this._extentLonLat;
1012
+
1013
+ var coord_sw = ellipsoid.geodeticToCartesian(extent.southWest.lon, extent.southWest.lat);
1014
+ var coord_ne = ellipsoid.geodeticToCartesian(extent.northEast.lon, extent.northEast.lat);
1015
+
1016
+ // check for zoom
1017
+ if (this.tileZoom <= MAX_NORMAL_ZOOM) {
1018
+ var coord_nw = ellipsoid.geodeticToCartesian(
1019
+ extent.southWest.lon,
1020
+ extent.northEast.lat
1021
+ );
1022
+ var coord_se = ellipsoid.geodeticToCartesian(
1023
+ extent.northEast.lon,
1024
+ extent.southWest.lat
1025
+ );
1026
+
1027
+ this._swNorm = coord_sw.normal();
1028
+ this._nwNorm = coord_nw.normal();
1029
+ this._neNorm = coord_ne.normal();
1030
+ this._seNorm = coord_se.normal();
1031
+ }
1032
+
1033
+ this.setBoundingVolume3v(coord_sw, coord_ne);
1034
+ }
1035
+
1036
+ createBoundsByParent() {
1037
+ let pn = this.node;
1038
+
1039
+ while (pn.parentNode && !pn.segment.terrainReady) {
1040
+ pn = pn.parentNode;
1041
+ }
1042
+
1043
+ let dZ2 = 1 << (this.tileZoom - pn.segment.tileZoom);
1044
+
1045
+ let offsetX = this.tileX - pn.segment.tileX * dZ2,
1046
+ offsetY = this.tileY - pn.segment.tileY * dZ2;
1047
+
1048
+ if (pn.segment.terrainReady && pn.segment.tileZoom >= this.planet.terrain.minZoom) {
1049
+ let gridSize = pn.segment.gridSize / dZ2;
1050
+
1051
+ if (gridSize >= 1.0) {
1052
+ //
1053
+ // (*) Actually, we get parent whole bounding volume
1054
+ //
1055
+ this.bsphere.center.x = pn.segment.bsphere.center.x;
1056
+ this.bsphere.center.y = pn.segment.bsphere.center.y;
1057
+ this.bsphere.center.z = pn.segment.bsphere.center.z;
1058
+ this.bsphere.radius = pn.segment.bsphere.radius;
1059
+
1060
+ if (this.tileZoom <= MAX_NORMAL_ZOOM) {
1061
+ let i0 = gridSize * offsetY;
1062
+ let j0 = gridSize * offsetX;
1063
+
1064
+ let pnGsOne = pn.segment.gridSize + 1;
1065
+
1066
+ let ind_sw = 3 * ((i0 + gridSize) * pnGsOne + j0),
1067
+ ind_nw = 3 * (i0 * pnGsOne + j0),
1068
+ ind_ne = 3 * (i0 * pnGsOne + j0 + gridSize),
1069
+ ind_se = 3 * ((i0 + gridSize) * pnGsOne + j0 + gridSize);
1070
+
1071
+ let pVerts = pn.segment.tempVertices;
1072
+
1073
+ let v_sw = new Vec3(pVerts[ind_sw], pVerts[ind_sw + 1], pVerts[ind_sw + 2]),
1074
+ v_ne = new Vec3(pVerts[ind_ne], pVerts[ind_ne + 1], pVerts[ind_ne + 2]);
1075
+
1076
+ // check for segment zoom
1077
+ let v_nw = new Vec3(pVerts[ind_nw], pVerts[ind_nw + 1], pVerts[ind_nw + 2]),
1078
+ v_se = new Vec3(pVerts[ind_se], pVerts[ind_se + 1], pVerts[ind_se + 2]);
1079
+
1080
+ this._swNorm = v_sw.normal();
1081
+ this._nwNorm = v_nw.normal();
1082
+ this._neNorm = v_ne.normal();
1083
+ this._seNorm = v_se.normal();
1084
+ }
1085
+ } else {
1086
+ let pseg = pn.segment;
1087
+
1088
+ let i0 = Math.floor(gridSize * offsetY),
1089
+ j0 = Math.floor(gridSize * offsetX);
1090
+
1091
+ let insideSize = 1.0 / gridSize;
1092
+
1093
+ let t_i0 = offsetY - insideSize * i0,
1094
+ t_j0 = offsetX - insideSize * j0;
1095
+
1096
+ let bigOne;
1097
+ if (pseg.gridSize === 1) {
1098
+ bigOne = pseg.tempVertices;
1099
+ } else {
1100
+ bigOne = getMatrixSubArray(pseg.tempVertices, pseg.gridSize, i0, j0, 1);
1101
+ }
1102
+
1103
+ let v_lt = new Vec3(bigOne[0], bigOne[1], bigOne[2]),
1104
+ v_rb = new Vec3(bigOne[9], bigOne[10], bigOne[11]);
1105
+
1106
+ let vn = new Vec3(
1107
+ bigOne[3] - bigOne[0],
1108
+ bigOne[4] - bigOne[1],
1109
+ bigOne[5] - bigOne[2]
1110
+ ),
1111
+ vw = new Vec3(
1112
+ bigOne[6] - bigOne[0],
1113
+ bigOne[7] - bigOne[1],
1114
+ bigOne[8] - bigOne[2]
1115
+ ),
1116
+ ve = new Vec3(
1117
+ bigOne[3] - bigOne[9],
1118
+ bigOne[4] - bigOne[10],
1119
+ bigOne[5] - bigOne[11]
1120
+ ),
1121
+ vs = new Vec3(
1122
+ bigOne[6] - bigOne[9],
1123
+ bigOne[7] - bigOne[10],
1124
+ bigOne[8] - bigOne[11]
1125
+ );
1126
+
1127
+ let vi_y = t_i0,
1128
+ vi_x = t_j0;
1129
+
1130
+ let coords_lt, coords_rb;
1131
+
1132
+ if (vi_y + vi_x < insideSize) {
1133
+ coords_lt = Vec3.add(
1134
+ vn.scaleTo(vi_x / insideSize),
1135
+ vw.scaleTo(vi_y / insideSize)
1136
+ ).addA(v_lt);
1137
+ } else {
1138
+ coords_lt = Vec3.add(
1139
+ vs.scaleTo(1 - vi_x / insideSize),
1140
+ ve.scaleTo(1 - vi_y / insideSize)
1141
+ ).addA(v_rb);
1142
+ }
1143
+
1144
+ vi_y = t_i0 + 1;
1145
+ vi_x = t_j0 + 1;
1146
+
1147
+ if (vi_y + vi_x < insideSize) {
1148
+ coords_rb = Vec3.add(
1149
+ vn.scaleTo(vi_x / insideSize),
1150
+ vw.scaleTo(vi_y / insideSize)
1151
+ ).addA(v_lt);
1152
+ } else {
1153
+ coords_rb = Vec3.add(
1154
+ vs.scaleTo(1 - vi_x / insideSize),
1155
+ ve.scaleTo(1 - vi_y / insideSize)
1156
+ ).addA(v_rb);
1157
+ }
1158
+
1159
+ this.setBoundingVolume3v(coords_lt, coords_rb);
1160
+ }
1161
+ } else {
1162
+ this.createBoundsByExtent();
1163
+ }
1164
+ }
1165
+
1166
+ setBoundingSphere(x, y, z, v) {
1167
+ this.bsphere.center.x = x;
1168
+ this.bsphere.center.y = y;
1169
+ this.bsphere.center.z = z;
1170
+ this.bsphere.radius = this.bsphere.center.distance(v);
1171
+ }
1172
+
1173
+ setBoundingVolume(xmin, ymin, zmin, xmax, ymax, zmax) {
1174
+ this.bbox.setFromBoundsArr([xmin, ymin, zmin, xmax, ymax, zmax]);
1175
+
1176
+ let x = xmin + (xmax - xmin) * 0.5,
1177
+ y = ymin + (ymax - ymin) * 0.5,
1178
+ z = zmin + (zmax - zmin) * 0.5;
1179
+
1180
+ this.bsphere.center.set(x, y, z);
1181
+ this.bsphere.radius = this.bsphere.center.distance(new Vec3(xmin, ymin, zmin));
1182
+ }
1183
+
1184
+ setBoundingVolume3v(vmin, vmax) {
1185
+ this.bbox.setFromBoundsArr([vmin.x, vmin.y, vmin.z, vmax.x, vmax.y, vmax.z]);
1186
+
1187
+ let x = vmin.x + (vmax.x - vmin.x) * 0.5,
1188
+ y = vmin.y + (vmax.y - vmin.y) * 0.5,
1189
+ z = vmin.z + (vmax.z - vmin.z) * 0.5;
1190
+
1191
+ this.bsphere.center.set(x, y, z);
1192
+ this.bsphere.radius = this.bsphere.center.distance(new Vec3(vmin.x, vmin.y, vmin.z));
1193
+ }
1194
+
1195
+ setBoundingVolumeArr(bounds) {
1196
+ this.bbox.setFromBoundsArr(bounds);
1197
+
1198
+ let x = bounds[0] + (bounds[3] - bounds[0]) * 0.5,
1199
+ y = bounds[1] + (bounds[4] - bounds[1]) * 0.5,
1200
+ z = bounds[2] + (bounds[5] - bounds[2]) * 0.5;
1201
+
1202
+ this.bsphere.center.set(x, y, z);
1203
+ this.bsphere.radius = this.bsphere.center.distance(
1204
+ new Vec3(bounds[0], bounds[1], bounds[2])
1205
+ );
1206
+ }
1207
+
1208
+ createCoordsBuffers(verticesHigh, verticesLow, gridSize) {
1209
+ var gsgs = (gridSize + 1) * (gridSize + 1);
1210
+ var h = this.handler;
1211
+
1212
+ if (this.vertexPositionBufferHigh && this.vertexPositionBufferHigh.numItems === gsgs) {
1213
+ h.setStreamArrayBuffer(this.vertexPositionBufferHigh, verticesHigh);
1214
+ h.setStreamArrayBuffer(this.vertexPositionBufferLow, verticesLow);
1215
+ } else {
1216
+ h.gl.deleteBuffer(this.vertexPositionBufferHigh);
1217
+ h.gl.deleteBuffer(this.vertexPositionBufferLow);
1218
+
1219
+ this.vertexTextureCoordBuffer =
1220
+ this.planet._textureCoordsBufferCache[Math.log2(gridSize)];
1221
+
1222
+ //this.vertexPositionBufferHigh = h.createStreamArrayBuffer(3, gsgs);
1223
+ //h.setStreamArrayBuffer(this.vertexPositionBufferHigh, verticesHigh);
1224
+ //this.vertexPositionBufferLow = h.createStreamArrayBuffer(3, gsgs);
1225
+ //h.setStreamArrayBuffer(this.vertexPositionBufferLow, verticesLow);
1226
+
1227
+ // It works, but I'm not sure that it is correct and better use the comment above
1228
+ this.vertexPositionBufferHigh = h.createArrayBuffer(verticesHigh, 3, gsgs);
1229
+ this.vertexPositionBufferLow = h.createArrayBuffer(verticesLow, 3, gsgs);
1230
+ }
1231
+ }
1232
+
1233
+ _addViewExtent() {
1234
+ var ext = this._extentLonLat;
1235
+
1236
+ if (!this.planet._viewExtent) {
1237
+ this.planet._viewExtent = new Extent(
1238
+ new LonLat(ext.southWest.lon, ext.southWest.lat),
1239
+ new LonLat(ext.northEast.lon, ext.northEast.lat)
1240
+ );
1241
+ return;
1242
+ }
1243
+
1244
+ var viewExt = this.planet._viewExtent;
1245
+
1246
+ if (ext.southWest.lon < viewExt.southWest.lon) {
1247
+ viewExt.southWest.lon = ext.southWest.lon;
1248
+ }
1249
+
1250
+ if (ext.northEast.lon > viewExt.northEast.lon) {
1251
+ viewExt.northEast.lon = ext.northEast.lon;
1252
+ }
1253
+
1254
+ if (ext.southWest.lat < viewExt.southWest.lat) {
1255
+ viewExt.southWest.lat = ext.southWest.lat;
1256
+ }
1257
+
1258
+ if (ext.northEast.lat > viewExt.northEast.lat) {
1259
+ viewExt.northEast.lat = ext.northEast.lat;
1260
+ }
1261
+ }
1262
+
1263
+ _assignTileIndexes() {
1264
+ this._tileGroup = 0;
1265
+ var tileZoom = this.tileZoom;
1266
+ var extent = this._extent;
1267
+ var pole = mercator.POLE;
1268
+ this.tileX = Math.round(
1269
+ Math.abs(-pole - extent.southWest.lon) / (extent.northEast.lon - extent.southWest.lon)
1270
+ );
1271
+ this.tileY = Math.round(
1272
+ Math.abs(pole - extent.northEast.lat) / (extent.northEast.lat - extent.southWest.lat)
1273
+ );
1274
+ var p2 = Math.pow(2, tileZoom);
1275
+ this.tileXE = (this.tileX + 1) % p2;
1276
+ this.tileXW = (p2 + this.tileX - 1) % p2;
1277
+
1278
+ this.tileYN = this.tileY - 1;
1279
+ this.tileYS = this.tileY + 1;
1280
+
1281
+ this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
1282
+ this.planet._quadTreeNodesCacheMerc[this.tileIndex] = this.node;
1283
+ }
1284
+
1285
+ initialize() {
1286
+ var p = this.planet;
1287
+ var n = this.node;
1288
+
1289
+ n.sideSize[0] =
1290
+ n.sideSize[1] =
1291
+ n.sideSize[2] =
1292
+ n.sideSize[3] =
1293
+ this.gridSize =
1294
+ p.terrain.gridSizeByZoom[this.tileZoom] || p.terrain.plainGridSize;
1295
+
1296
+ n.sideSizeLog2[0] =
1297
+ n.sideSizeLog2[1] =
1298
+ n.sideSizeLog2[2] =
1299
+ n.sideSizeLog2[3] =
1300
+ Math.log2(p.terrain.gridSizeByZoom[this.tileZoom] || p.terrain.plainGridSize);
1301
+
1302
+ if (this.tileZoom <= p.terrain.maxZoom) {
1303
+ var nmc = this.planet._normalMapCreator;
1304
+ this.normalMapTexturePtr = p.renderer.handler.createEmptyTexture_l(
1305
+ nmc._width,
1306
+ nmc._height
1307
+ );
1308
+ }
1309
+
1310
+ this.normalMapTexture = this.planet.transparentTexture;
1311
+
1312
+ this._assignGlobalTextureCoordinates();
1313
+
1314
+ this.initialized = true;
1315
+ }
1316
+
1317
+ _assignGlobalTextureCoordinates() {
1318
+ var e = this._extent;
1319
+ this._globalTextureCoordinates[0] =
1320
+ (e.southWest.lon + mercator.POLE) * mercator.ONE_BY_POLE_DOUBLE;
1321
+ this._globalTextureCoordinates[1] =
1322
+ (mercator.POLE - e.northEast.lat) * mercator.ONE_BY_POLE_DOUBLE;
1323
+ this._globalTextureCoordinates[2] =
1324
+ (e.northEast.lon + mercator.POLE) * mercator.ONE_BY_POLE_DOUBLE;
1325
+ this._globalTextureCoordinates[3] =
1326
+ (mercator.POLE - e.southWest.lat) * mercator.ONE_BY_POLE_DOUBLE;
1327
+ }
1328
+
1329
+ createPlainSegmentAsync() {
1330
+ let p = this.planet,
1331
+ t = p.terrain;
1332
+
1333
+ if (t.isReady() && this.tileZoom <= t.maxZoom && !this.plainReady) {
1334
+ this.plainProcessing = true;
1335
+ p._plainSegmentWorker.make(this);
1336
+ }
1337
+ }
1338
+
1339
+ createPlainSegment() {
1340
+ this.initialize();
1341
+ this._createPlainVertices();
1342
+ this.readyToEngage = true;
1343
+ }
1344
+
1345
+ _createPlainVertices() {
1346
+ var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
1347
+
1348
+ var e = this._extent,
1349
+ fgs = this.planet.terrain.plainGridSize;
1350
+ var lonSize = e.getWidth();
1351
+ var llStep = lonSize / Math.max(fgs, gridSize);
1352
+ var esw_lon = e.southWest.lon,
1353
+ ene_lat = e.northEast.lat;
1354
+ var dg = Math.max(fgs / gridSize, 1),
1355
+ gs = Math.max(fgs, gridSize) + 1;
1356
+ var r2 = this.planet.ellipsoid._invRadii2;
1357
+ var ind = 0,
1358
+ nmInd = 0;
1359
+ const gsgs = gs * gs;
1360
+
1361
+ var gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
1362
+
1363
+ this.plainNormals = new Float32Array(gridSize3);
1364
+ this.plainVertices = new Float64Array(gridSize3);
1365
+ this.plainVerticesHigh = new Float32Array(gridSize3);
1366
+ this.plainVerticesLow = new Float32Array(gridSize3);
1367
+
1368
+ this.normalMapNormals = new Float32Array(gsgs * 3);
1369
+ this.normalMapVertices = new Float64Array(gsgs * 3);
1370
+ this.normalMapVerticesHigh = new Float32Array(gsgs * 3);
1371
+ this.normalMapVerticesLow = new Float32Array(gsgs * 3);
1372
+
1373
+ var verts = this.plainVertices,
1374
+ vertsHigh = this.plainVerticesHigh,
1375
+ vertsLow = this.plainVerticesLow,
1376
+ norms = this.plainNormals,
1377
+ nmVerts = this.normalMapVertices,
1378
+ nmVertsHigh = this.normalMapVerticesHigh,
1379
+ nmVertsLow = this.normalMapVerticesLow,
1380
+ nmNorms = this.normalMapNormals;
1381
+
1382
+ for (var k = 0; k < gsgs; k++) {
1383
+ var j = k % gs,
1384
+ i = ~~(k / gs);
1385
+
1386
+ var v = this.planet.ellipsoid.lonLatToCartesian(
1387
+ LonLat.inverseMercator(esw_lon + j * llStep, ene_lat - i * llStep)
1388
+ );
1389
+ var nx = v.x * r2.x,
1390
+ ny = v.y * r2.y,
1391
+ nz = v.z * r2.z;
1392
+ var l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
1393
+ var nxl = nx * l,
1394
+ nyl = ny * l,
1395
+ nzl = nz * l;
1396
+
1397
+ Vec3.doubleToTwoFloats(v, _tempHigh, _tempLow);
1398
+
1399
+ nmVerts[nmInd] = v.x;
1400
+ nmVertsHigh[nmInd] = _tempHigh.x;
1401
+ nmVertsLow[nmInd] = _tempLow.x;
1402
+ nmNorms[nmInd++] = nxl;
1403
+
1404
+ nmVerts[nmInd] = v.y;
1405
+ nmVertsHigh[nmInd] = _tempHigh.y;
1406
+ nmVertsLow[nmInd] = _tempLow.y;
1407
+ nmNorms[nmInd++] = nyl;
1408
+
1409
+ nmVerts[nmInd] = v.z;
1410
+ nmVertsHigh[nmInd] = _tempHigh.z;
1411
+ nmVertsLow[nmInd] = _tempLow.z;
1412
+ nmNorms[nmInd++] = nzl;
1413
+
1414
+ if (i % dg === 0 && j % dg === 0) {
1415
+ verts[ind] = v.x;
1416
+ vertsHigh[ind] = _tempHigh.x;
1417
+ vertsLow[ind] = _tempLow.x;
1418
+ norms[ind++] = nxl;
1419
+
1420
+ verts[ind] = v.y;
1421
+ vertsHigh[ind] = _tempHigh.y;
1422
+ vertsLow[ind] = _tempLow.y;
1423
+ norms[ind++] = nyl;
1424
+
1425
+ verts[ind] = v.z;
1426
+ vertsHigh[ind] = _tempHigh.z;
1427
+ vertsLow[ind] = _tempLow.z;
1428
+ norms[ind++] = nzl;
1429
+ }
1430
+ }
1431
+
1432
+ this.terrainVertices = verts;
1433
+ this.terrainVerticesHigh = vertsHigh;
1434
+ this.terrainVerticesLow = vertsLow;
1435
+
1436
+ this.plainReady = true;
1437
+ }
1438
+
1439
+ /**
1440
+ * Gets specific layer material.
1441
+ * @public
1442
+ * @param {Layer} layer - Layer object.
1443
+ * @returns {planetSegment.Material} - Segment material.
1444
+ */
1445
+ getMaterialByLayer(layer) {
1446
+ return this.materials[layer._id];
1447
+ }
1448
+
1449
+ _getLayerExtentOffset(layer) {
1450
+ var v0s = layer._extentMerc;
1451
+ var v0t = this._extent;
1452
+ var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
1453
+ var sSize_y = v0s.northEast.lat - v0s.southWest.lat;
1454
+ var dV0s_x = (v0t.southWest.lon - v0s.southWest.lon) / sSize_x;
1455
+ var dV0s_y = (v0s.northEast.lat - v0t.northEast.lat) / sSize_y;
1456
+ var dSize_x = (v0t.northEast.lon - v0t.southWest.lon) / sSize_x;
1457
+ var dSize_y = (v0t.northEast.lat - v0t.southWest.lat) / sSize_y;
1458
+ return [dV0s_x, dV0s_y, dSize_x, dSize_y];
1459
+ }
1460
+
1461
+ screenRendering(sh, layerSlice, sliceIndex, defaultTexture, isOverlay) {
1462
+ var gl = this.handler.gl;
1463
+ var sha = sh.attributes,
1464
+ shu = sh.uniforms;
1465
+
1466
+ var pm = this.materials,
1467
+ p = this.planet;
1468
+
1469
+ var currHeight, li;
1470
+ if (layerSlice) {
1471
+ li = layerSlice[0];
1472
+ currHeight = li._height;
1473
+ } else {
1474
+ currHeight = 0;
1475
+ }
1476
+
1477
+ // First always draw whole planet base layer segment with solid texture.
1478
+ gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE + 2);
1479
+ gl.bindTexture(gl.TEXTURE_2D, defaultTexture || this.getDefaultTexture());
1480
+ gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE + 2);
1481
+
1482
+ var n = 0,
1483
+ i = 0;
1484
+
1485
+ var notEmpty = false;
1486
+
1487
+ var slice = this._renderingSlices[sliceIndex];
1488
+
1489
+ if (!slice) {
1490
+ slice = this._renderingSlices[sliceIndex] = new _RenderingSlice(p);
1491
+ } else {
1492
+ slice.layers = [];
1493
+ }
1494
+
1495
+ this._indexBuffer = this._getIndexBuffer();
1496
+
1497
+ while (li) {
1498
+ if (
1499
+ this.layerOverlap(li) &&
1500
+ ((li._fading && li._fadingOpacity > 0.0) ||
1501
+ ((li.minZoom >= p.minCurrZoom || li.maxZoom >= p.minCurrZoom) &&
1502
+ (li.minZoom <= p.maxCurrZoom || li.maxZoom <= p.maxCurrZoom)))
1503
+ ) {
1504
+ notEmpty = true;
1505
+ var m = pm[li._id];
1506
+ if (!m) {
1507
+ m = pm[li._id] = li.createMaterial(this);
1508
+ }
1509
+
1510
+ if (!m.isReady) {
1511
+ this.planet._renderCompleted = false;
1512
+ }
1513
+
1514
+ slice.layers.push(li);
1515
+
1516
+ var n4 = n * 4,
1517
+ n3 = n * 3;
1518
+
1519
+ var arr = li.applyMaterial(m);
1520
+ slice.tileOffsetArr[n4] = arr[0];
1521
+ slice.tileOffsetArr[n4 + 1] = arr[1];
1522
+ slice.tileOffsetArr[n4 + 2] = arr[2];
1523
+ slice.tileOffsetArr[n4 + 3] = arr[3];
1524
+
1525
+ arr = this._getLayerExtentOffset(li);
1526
+ slice.visibleExtentOffsetArr[n4] = arr[0];
1527
+ slice.visibleExtentOffsetArr[n4 + 1] = arr[1];
1528
+ slice.visibleExtentOffsetArr[n4 + 2] = arr[2];
1529
+ slice.visibleExtentOffsetArr[n4 + 3] = arr[3];
1530
+
1531
+ slice.transparentColorArr[n4] = li.transparentColor[0];
1532
+ slice.transparentColorArr[n4 + 1] = li.transparentColor[1];
1533
+ slice.transparentColorArr[n4 + 2] = li.transparentColor[2];
1534
+ slice.transparentColorArr[n4 + 3] = li.opacity;
1535
+
1536
+ p._diffuseMaterialArr[n3 + 3] = li.diffuse.x;
1537
+ p._diffuseMaterialArr[n3 + 1 + 3] = li.diffuse.y;
1538
+ p._diffuseMaterialArr[n3 + 2 + 3] = li.diffuse.z;
1539
+
1540
+ p._ambientMaterialArr[n3 + 3] = li.ambient.x;
1541
+ p._ambientMaterialArr[n3 + 1 + 3] = li.ambient.y;
1542
+ p._ambientMaterialArr[n3 + 2 + 3] = li.ambient.z;
1543
+
1544
+ p._specularMaterialArr[n4 + 4] = li.specular.x;
1545
+ p._specularMaterialArr[n4 + 1 + 4] = li.specular.y;
1546
+ p._specularMaterialArr[n4 + 2 + 4] = li.specular.z;
1547
+ p._specularMaterialArr[n4 + 3 + 4] = li.shininess;
1548
+
1549
+ p._samplerArr[n] = n;
1550
+
1551
+ gl.activeTexture(gl.TEXTURE0 + n);
1552
+ gl.bindTexture(gl.TEXTURE_2D, m.texture || p.transparentTexture);
1553
+
1554
+ n++;
1555
+ }
1556
+ i++;
1557
+ li = layerSlice[i];
1558
+ }
1559
+
1560
+ if (notEmpty || !isOverlay) {
1561
+ gl.uniform1i(shu.samplerCount, n);
1562
+ gl.uniform1f(shu.height, currHeight);
1563
+ gl.uniform1iv(shu.samplerArr, p._samplerArr);
1564
+ gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
1565
+ gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
1566
+ gl.uniform4fv(shu.transparentColorArr, slice.transparentColorArr);
1567
+
1568
+ // bind normalmap texture
1569
+ if (p.lightEnabled) {
1570
+ gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE + 3);
1571
+ gl.bindTexture(gl.TEXTURE_2D, this.normalMapTexture || p.transparentTexture);
1572
+ gl.uniform1i(shu.uNormalMap, p.SLICE_SIZE + 3);
1573
+
1574
+ gl.uniform3fv(shu.uNormalMapBias, this.normalMapTextureBias);
1575
+
1576
+ // bind segment specular and night material texture coordinates
1577
+ gl.uniform4fv(shu.uGlobalTextureCoord, this._globalTextureCoordinates);
1578
+
1579
+ gl.uniform3fv(shu.diffuseMaterial, p._diffuseMaterialArr);
1580
+ gl.uniform3fv(shu.ambientMaterial, p._ambientMaterialArr);
1581
+ gl.uniform4fv(shu.specularMaterial, p._specularMaterialArr);
1582
+ }
1583
+
1584
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
1585
+ gl.vertexAttribPointer(
1586
+ sha.aVertexPositionHigh,
1587
+ this.vertexPositionBufferHigh.itemSize,
1588
+ gl.FLOAT,
1589
+ false,
1590
+ 0,
1591
+ 0
1592
+ );
1593
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
1594
+ gl.vertexAttribPointer(
1595
+ sha.aVertexPositionLow,
1596
+ this.vertexPositionBufferLow.itemSize,
1597
+ gl.FLOAT,
1598
+ false,
1599
+ 0,
1600
+ 0
1601
+ );
1602
+
1603
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
1604
+ gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
1605
+
1606
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
1607
+ gl.drawElements(p.drawMode, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
1608
+ }
1609
+ }
1610
+
1611
+ heightPickingRendering(sh, layerSlice, sliceIndex, defaultTexture, isOverlay) {
1612
+ var gl = this.handler.gl;
1613
+ var sha = sh.attributes,
1614
+ shu = sh.uniforms;
1615
+
1616
+ var pm = this.materials,
1617
+ p = this.planet;
1618
+
1619
+ // First always draw whole planet base layer segment with solid texture.
1620
+ gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE);
1621
+ gl.bindTexture(gl.TEXTURE_2D, defaultTexture || p.solidTextureOne);
1622
+ gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE);
1623
+
1624
+ var currHeight;
1625
+ if (layerSlice) {
1626
+ currHeight = layerSlice[0]._height;
1627
+ } else {
1628
+ currHeight = 0;
1629
+ }
1630
+
1631
+ var n = 0;
1632
+
1633
+ var slice = this._renderingSlices[sliceIndex];
1634
+
1635
+ var notEmpty = false;
1636
+
1637
+ for (n = 0; n < slice.layers.length; n++) {
1638
+ notEmpty = true;
1639
+ p._samplerArr[n] = n;
1640
+ gl.activeTexture(gl.TEXTURE0 + n);
1641
+ gl.bindTexture(gl.TEXTURE_2D, pm[slice.layers[n]._id].texture || p.transparentTexture);
1642
+ }
1643
+
1644
+ if (notEmpty || !isOverlay) {
1645
+ gl.uniform1i(shu.samplerCount, n);
1646
+ gl.uniform1f(shu.height, currHeight);
1647
+ gl.uniform1iv(shu.samplerArr, p._samplerArr);
1648
+ gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
1649
+ gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
1650
+ gl.uniform4fv(shu.transparentColorArr, slice.transparentColorArr);
1651
+
1652
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
1653
+ gl.vertexAttribPointer(
1654
+ sha.aVertexPositionHigh,
1655
+ this.vertexPositionBufferHigh.itemSize,
1656
+ gl.FLOAT,
1657
+ false,
1658
+ 0,
1659
+ 0
1660
+ );
1661
+
1662
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
1663
+ gl.vertexAttribPointer(
1664
+ sha.aVertexPositionLow,
1665
+ this.vertexPositionBufferLow.itemSize,
1666
+ gl.FLOAT,
1667
+ false,
1668
+ 0,
1669
+ 0
1670
+ );
1671
+
1672
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
1673
+ gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
1674
+
1675
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
1676
+ gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
1677
+ }
1678
+ }
1679
+
1680
+ colorPickingRendering(sh, layerSlice, sliceIndex, defaultTexture, isOverlay) {
1681
+ var gl = this.handler.gl;
1682
+ var sha = sh.attributes,
1683
+ shu = sh.uniforms;
1684
+
1685
+ var pm = this.materials,
1686
+ p = this.planet;
1687
+
1688
+ var currHeight;
1689
+ if (layerSlice) {
1690
+ currHeight = layerSlice[0]._height;
1691
+ } else {
1692
+ currHeight = 0;
1693
+ }
1694
+
1695
+ var notEmpty = false;
1696
+
1697
+ var slice = this._renderingSlices[sliceIndex];
1698
+
1699
+ for (var n = 0; n < slice.layers.length; n++) {
1700
+ notEmpty = true;
1701
+
1702
+ var li = slice.layers[n];
1703
+ var n4 = n * 4;
1704
+
1705
+ p._pickingColorArr[n4] = li._pickingColor.x / 255.0;
1706
+ p._pickingColorArr[n4 + 1] = li._pickingColor.y / 255.0;
1707
+ p._pickingColorArr[n4 + 2] = li._pickingColor.z / 255.0;
1708
+ p._pickingColorArr[n4 + 3] = li._pickingEnabled;
1709
+
1710
+ p._samplerArr[n] = n;
1711
+ gl.activeTexture(gl.TEXTURE0 + n);
1712
+ gl.bindTexture(gl.TEXTURE_2D, pm[li._id].texture || this.planet.transparentTexture);
1713
+
1714
+ p._pickingMaskArr[n] = n + p.SLICE_SIZE;
1715
+ gl.activeTexture(gl.TEXTURE0 + n + p.SLICE_SIZE);
1716
+ gl.bindTexture(gl.TEXTURE_2D, pm[li._id].pickingMask || this.planet.transparentTexture);
1717
+ }
1718
+
1719
+ if (notEmpty || !isOverlay) {
1720
+ gl.uniform1i(shu.samplerCount, n);
1721
+ gl.uniform1f(shu.height, currHeight);
1722
+ gl.uniform1iv(shu.samplerArr, p._samplerArr);
1723
+ gl.uniform1iv(shu.pickingMaskArr, p._pickingMaskArr);
1724
+ gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
1725
+ gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
1726
+ gl.uniform4fv(shu.transparentColorArr, slice.transparentColorArr);
1727
+ gl.uniform4fv(shu.pickingColorArr, p._pickingColorArr);
1728
+
1729
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
1730
+ gl.vertexAttribPointer(
1731
+ sha.aVertexPositionHigh,
1732
+ this.vertexPositionBufferHigh.itemSize,
1733
+ gl.FLOAT,
1734
+ false,
1735
+ 0,
1736
+ 0
1737
+ );
1738
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
1739
+ gl.vertexAttribPointer(
1740
+ sha.aVertexPositionLow,
1741
+ this.vertexPositionBufferLow.itemSize,
1742
+ gl.FLOAT,
1743
+ false,
1744
+ 0,
1745
+ 0
1746
+ );
1747
+
1748
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
1749
+ gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
1750
+
1751
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
1752
+ gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
1753
+ }
1754
+ }
1755
+
1756
+ depthRendering(sh, layerSlice, sliceIndex, defaultTexture, isOverlay) {
1757
+ var gl = this.handler.gl;
1758
+ var sha = sh.attributes,
1759
+ shu = sh.uniforms;
1760
+
1761
+ var pm = this.materials,
1762
+ p = this.planet;
1763
+
1764
+ // First always draw whole planet base layer segment with solid texture.
1765
+ gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE);
1766
+ gl.bindTexture(gl.TEXTURE_2D, defaultTexture || p.solidTextureOne);
1767
+ gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE);
1768
+
1769
+ var currHeight;
1770
+ if (layerSlice) {
1771
+ currHeight = layerSlice[0]._height;
1772
+ } else {
1773
+ currHeight = 0;
1774
+ }
1775
+
1776
+ var n = 0;
1777
+
1778
+ var slice = this._renderingSlices[sliceIndex];
1779
+
1780
+ var notEmpty = false;
1781
+
1782
+ for (n = 0; n < slice.layers.length; n++) {
1783
+ notEmpty = true;
1784
+ p._samplerArr[n] = n;
1785
+ gl.activeTexture(gl.TEXTURE0 + n);
1786
+ gl.bindTexture(gl.TEXTURE_2D, pm[slice.layers[n]._id].texture || p.transparentTexture);
1787
+ }
1788
+
1789
+ if (notEmpty || !isOverlay) {
1790
+ gl.uniform1i(shu.samplerCount, n);
1791
+ gl.uniform1f(shu.height, currHeight);
1792
+ gl.uniform1iv(shu.samplerArr, p._samplerArr);
1793
+ gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
1794
+ gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
1795
+ gl.uniform4fv(shu.transparentColorArr, slice.transparentColorArr);
1796
+
1797
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
1798
+ gl.vertexAttribPointer(
1799
+ sha.aVertexPositionHigh,
1800
+ this.vertexPositionBufferHigh.itemSize,
1801
+ gl.FLOAT,
1802
+ false,
1803
+ 0,
1804
+ 0
1805
+ );
1806
+
1807
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
1808
+ gl.vertexAttribPointer(
1809
+ sha.aVertexPositionLow,
1810
+ this.vertexPositionBufferLow.itemSize,
1811
+ gl.FLOAT,
1812
+ false,
1813
+ 0,
1814
+ 0
1815
+ );
1816
+
1817
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
1818
+ gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
1819
+
1820
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
1821
+ gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
1822
+ }
1823
+ }
1824
+
1825
+ _getIndexBuffer() {
1826
+ var s = this.node.sideSizeLog2;
1827
+ var cache = this.planet._indexesCache[Math.log2(this.gridSize)][s[0]][s[1]][s[2]][s[3]];
1828
+ if (!cache.buffer) {
1829
+ let indexes = segmentHelper
1830
+ .getInstance()
1831
+ .createSegmentIndexes(Math.log2(this.gridSize), [s[0], s[1], s[2], s[3]]);
1832
+ cache.buffer = this.planet.renderer.handler.createElementArrayBuffer(indexes, 1);
1833
+ this.planet._indexesCacheToRemoveCounter++;
1834
+ indexes = null;
1835
+ }
1836
+ return cache.buffer;
1837
+ }
1838
+
1839
+ _collectVisibleNodes() {
1840
+ this.planet._visibleNodes[this.node.nodeId] = this.node;
1841
+ }
1842
+
1843
+ layerOverlap(layer) {
1844
+ return this._extent.overlaps(layer._extentMerc);
1845
+ }
1846
+
1847
+ getDefaultTexture() {
1848
+ return this.planet.solidTextureOne;
1849
+ }
1850
+
1851
+ getExtentLonLat() {
1852
+ return this._extentLonLat;
1853
+ }
1854
+
1855
+ getExtentMerc() {
1856
+ return this._extent;
1857
+ }
1858
+
1859
+ getExtent() {
1860
+ return this._extent;
1861
+ }
1862
+
1863
+ getNodeState() {
1864
+ var vn = this.planet._visibleNodes[this.node.nodeId];
1865
+ return (vn && vn.state) || NOTRENDERING;
1866
+ }
1867
+
1868
+ getNeighborSide(b) {
1869
+ if (this.tileY === b.tileY) {
1870
+ if (this.tileX === b.tileXE) {
1871
+ return W;
1872
+ } else if (this.tileX === b.tileXW) {
1873
+ return E;
1874
+ }
1875
+ } else if (this.tileX === b.tileX) {
1876
+ if (this.tileY === b.tileYS) {
1877
+ return N;
1878
+ } else if (this.tileY === b.tileYN) {
1879
+ return S;
1880
+ }
1881
+ }
1882
+
1883
+ return -1;
1884
+ }
1885
+ }
1886
+ export { Segment };