@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,268 +1,298 @@
1
- "use strict";
2
-
3
- import * as mercator from "../mercator.js";
4
- import * as quadTree from "../quadTree/quadTree.js";
5
- import { EPSG4326 } from "../proj/EPSG4326.js";
6
- import { Extent } from "../Extent.js";
7
- import { inherits } from "../inherits.js";
8
- import { Layer } from "../layer/Layer.js";
9
- import { LonLat } from "../LonLat.js";
10
- import { Segment } from "./Segment.js";
11
- import { Vec3 } from "../math/Vec3.js";
12
-
13
- const _heightLat = 90.0 - mercator.MAX_LAT;
14
- const _maxPoleZoom = 7;
15
- const _pieceSize = _heightLat / Math.pow(2, _maxPoleZoom);
16
-
17
- let _tempHigh = new Vec3(),
18
- _tempLow = new Vec3();
19
-
20
- /**
21
- * Planet segment Web Mercator tile class that stored and rendered with quad tree.
22
- * @class
23
- * @extends {og.planetSegment.Segment}
24
- * @param {og.quadNode.Node} node - Quad tree segment node.
25
- * @param {og.scene.Planet} planet - Scene planet.
26
- * @param {Number} tileZoom - Segment tile zoom index.
27
- * @param {og.Extent} extent - Segment WGS84 extent.
28
- */
29
- const SegmentLonLat = function (node, planet, tileZoom, extent) {
30
- this._isNorth = false;
31
- Segment.call(this, node, planet, tileZoom, extent);
32
- this._projection = EPSG4326;
33
- this._extentMerc = new Extent(
34
- extent.southWest.forwardMercatorEPS01(),
35
- extent.northEast.forwardMercatorEPS01()
36
- );
37
- this.isPole = true;
38
- };
39
-
40
- inherits(SegmentLonLat, Segment);
41
-
42
- SegmentLonLat.prototype._setExtentLonLat = function () {
43
- this._extentLonLat = this._extent;
44
- };
45
-
46
- SegmentLonLat.prototype.projectNative = function (coords) {
47
- return coords;
48
- };
49
-
50
- SegmentLonLat.prototype.getTerrainPoint = function (xyz, insideSegmentPosition, res, normal) {
51
- res.copy(this.planet.ellipsoid.hitRay(xyz, xyz.negateTo().normalize()));
52
- if (normal) {
53
- normal.copy(res.normal());
54
- }
55
- return xyz.length() - res.length();
56
- };
57
-
58
- SegmentLonLat.prototype.acceptForRendering = function (camera) {
59
- var maxPoleZoom;
60
- var lat = this._extent.northEast.lat;
61
- if (this._isNorth) {
62
- //north pole limits
63
- let Yz = Math.floor((90.0 - lat) / _pieceSize);
64
- maxPoleZoom = Math.floor(Yz / 16) + 7;
65
- } else {
66
- //south pole limits
67
- let Yz = Math.floor((mercator.MIN_LAT - lat) / _pieceSize);
68
- maxPoleZoom = 12 - Math.floor(Yz / 16);
69
- }
70
- return Segment.prototype.acceptForRendering.call(this, camera) || this.tileZoom >= maxPoleZoom;
71
- };
72
-
73
- SegmentLonLat.prototype._assignTileIndexes = function () {
74
- var tileZoom = this.tileZoom;
75
- var extent = this._extent;
76
-
77
- this.tileX = Math.round(
78
- Math.abs(-180.0 - extent.southWest.lon) / (extent.northEast.lon - extent.southWest.lon)
79
- );
80
-
81
- var lat = extent.northEast.lat;
82
-
83
- if (lat > 0) {
84
- //north pole
85
- this._isNorth = true;
86
- this._tileGroup = 1;
87
- this.tileY = Math.round((90.0 - lat) / (extent.northEast.lat - extent.southWest.lat));
88
- } else {
89
- //south pole
90
- this._tileGroup = 2;
91
- this.tileY = Math.round(
92
- (mercator.MIN_LAT - lat) / (extent.northEast.lat - extent.southWest.lat)
93
- );
94
- }
95
-
96
- var p2 = Math.pow(2, tileZoom);
97
- this.tileXE = (this.tileX + 1) % p2;
98
- this.tileXW = (p2 + this.tileX - 1) % p2;
99
-
100
- this.tileYN = this.tileY - 1;
101
- this.tileYS = this.tileY + 1;
102
-
103
- this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
104
- };
105
-
106
- SegmentLonLat.prototype._createPlainVertices = function () {
107
- var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
108
-
109
- var e = this._extent,
110
- fgs = this.planet.terrain.plainGridSize;
111
- var lonSize = e.getWidth();
112
- var latSize = e.getHeight();
113
- var llStep = lonSize / Math.max(fgs, gridSize);
114
- var ltStep = latSize / gridSize;
115
- var esw_lon = e.southWest.lon,
116
- ene_lat = e.northEast.lat;
117
- var dg = Math.max(fgs / gridSize, 1),
118
- gs = Math.max(fgs, gridSize) + 1;
119
- var r2 = this.planet.ellipsoid._invRadii2;
120
- var ind = 0,
121
- nmInd = 0;
122
- const gsgs = gs * gs;
123
-
124
- var gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
125
-
126
- this.plainNormals = new Float32Array(gridSize3);
127
- this.plainVertices = new Float64Array(gridSize3);
128
- this.plainVerticesHigh = new Float32Array(gridSize3);
129
- this.plainVerticesLow = new Float32Array(gridSize3);
130
-
131
- this.normalMapNormals = new Float32Array(gsgs * 3);
132
- this.normalMapVertices = new Float64Array(gsgs * 3);
133
- this.normalMapVerticesHigh = new Float32Array(gsgs * 3);
134
- this.normalMapVerticesLow = new Float32Array(gsgs * 3);
135
-
136
- var verts = this.plainVertices,
137
- vertsHigh = this.plainVerticesHigh,
138
- vertsLow = this.plainVerticesLow,
139
- norms = this.plainNormals,
140
- nmVerts = this.normalMapVertices,
141
- nmVertsHigh = this.normalMapVerticesHigh,
142
- nmVertsLow = this.normalMapVerticesLow,
143
- nmNorms = this.normalMapNormals;
144
-
145
- for (var k = 0; k < gsgs; k++) {
146
- var j = k % gs,
147
- i = ~~(k / gs);
148
-
149
- var v = this.planet.ellipsoid.lonLatToCartesian(
150
- new LonLat(esw_lon + j * llStep, ene_lat - i * ltStep)
151
- );
152
- var nx = v.x * r2.x,
153
- ny = v.y * r2.y,
154
- nz = v.z * r2.z;
155
- var l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
156
- var nxl = nx * l,
157
- nyl = ny * l,
158
- nzl = nz * l;
159
-
160
- Vec3.doubleToTwoFloats(v, _tempHigh, _tempLow);
161
-
162
- nmVerts[nmInd] = v.x;
163
- nmVertsHigh[nmInd] = _tempHigh.x;
164
- nmVertsLow[nmInd] = _tempLow.x;
165
- nmNorms[nmInd++] = nxl;
166
-
167
- nmVerts[nmInd] = v.y;
168
- nmVertsHigh[nmInd] = _tempHigh.y;
169
- nmVertsLow[nmInd] = _tempLow.y;
170
- nmNorms[nmInd++] = nyl;
171
-
172
- nmVerts[nmInd] = v.z;
173
- nmVertsHigh[nmInd] = _tempHigh.z;
174
- nmVertsLow[nmInd] = _tempLow.z;
175
- nmNorms[nmInd++] = nzl;
176
-
177
- if (i % dg === 0 && j % dg === 0) {
178
- verts[ind] = v.x;
179
- vertsHigh[ind] = _tempHigh.x;
180
- vertsLow[ind] = _tempLow.x;
181
- norms[ind++] = nxl;
182
-
183
- verts[ind] = v.y;
184
- vertsHigh[ind] = _tempHigh.y;
185
- vertsLow[ind] = _tempLow.y;
186
- norms[ind++] = nyl;
187
-
188
- verts[ind] = v.z;
189
- vertsHigh[ind] = _tempHigh.z;
190
- vertsLow[ind] = _tempLow.z;
191
- norms[ind++] = nzl;
192
- }
193
- }
194
-
195
- this.terrainVertices = verts;
196
- this.terrainVerticesHigh = vertsHigh;
197
- this.terrainVerticesLow = vertsLow;
198
-
199
- //store raw normals
200
- this.normalMapNormalsRaw = new Float32Array(nmNorms.length);
201
- this.normalMapNormalsRaw.set(nmNorms);
202
-
203
- this.plainReady = true;
204
- };
205
-
206
- SegmentLonLat.prototype._assignGlobalTextureCoordinates = function () {
207
- var e = this._extent;
208
- this._globalTextureCoordinates[0] = (e.southWest.lon + 180.0) / 360.0;
209
- this._globalTextureCoordinates[1] = (90 - e.northEast.lat) / 180.0;
210
- this._globalTextureCoordinates[2] = (e.northEast.lon + 180.0) / 360.0;
211
- this._globalTextureCoordinates[3] = (90 - e.southWest.lat) / 180.0;
212
- };
213
-
214
- SegmentLonLat.prototype._collectVisibleNodes = function () {
215
- if (this._isNorth) {
216
- this.planet._visibleNodesNorth[this.node.nodeId] = this.node;
217
- } else {
218
- this.planet._visibleNodesSouth[this.node.nodeId] = this.node;
219
- }
220
- };
221
-
222
- SegmentLonLat.prototype.isEntityInside = function (e) {
223
- return this._extent.isInside(e._lonlat);
224
- };
225
-
226
- SegmentLonLat.prototype._getLayerExtentOffset = function (layer) {
227
- var v0s = layer._extent;
228
- var v0t = this._extent;
229
- var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
230
- var sSize_y = v0s.northEast.lat - v0s.southWest.lat;
231
- var dV0s_x = (v0t.southWest.lon - v0s.southWest.lon) / sSize_x;
232
- var dV0s_y = (v0s.northEast.lat - v0t.northEast.lat) / sSize_y;
233
- var dSize_x = (v0t.northEast.lon - v0t.southWest.lon) / sSize_x;
234
- var dSize_y = (v0t.northEast.lat - v0t.southWest.lat) / sSize_y;
235
- return [dV0s_x, dV0s_y, dSize_x, dSize_y];
236
- };
237
-
238
- SegmentLonLat.prototype.layerOverlap = function (layer) {
239
- return this._extent.overlaps(layer._extent);
240
- };
241
-
242
- SegmentLonLat.prototype.getDefaultTexture = function () {
243
- return this._isNorth ? this.planet.solidTextureOne : this.planet.solidTextureTwo;
244
- };
245
-
246
- SegmentLonLat.prototype.getExtentLonLat = function () {
247
- return this._extent;
248
- };
249
-
250
- SegmentLonLat.prototype.getExtentMerc = function () {
251
- return this._extentMerc;
252
- };
253
-
254
- SegmentLonLat.prototype.getNodeState = function () {
255
- var vn;
256
- if (this._isNorth) {
257
- vn = this.planet._visibleNodesNorth[this.node.nodeId];
258
- } else {
259
- vn = this.planet._visibleNodesSouth[this.node.nodeId];
260
- }
261
- return (vn && vn.state) || quadTree.NOTRENDERING;
262
- };
263
-
264
- SegmentLonLat.prototype._freeCache = function () {
265
- //empty for a time
266
- };
267
-
268
- export { SegmentLonLat };
1
+ "use strict";
2
+
3
+ import { Extent } from "../Extent.js";
4
+ import { Layer } from "../layer/Layer.js";
5
+ import { LonLat } from "../LonLat.js";
6
+ import { Vec3 } from "../math/Vec3.js";
7
+ import * as mercator from "../mercator.js";
8
+ import { EPSG4326 } from "../proj/EPSG4326.js";
9
+ import * as quadTree from "../quadTree/quadTree.js";
10
+ import { Segment } from "./Segment.js";
11
+
12
+ const _heightLat = 90.0 - mercator.MAX_LAT;
13
+ const _maxPoleZoom = 7;
14
+ const _pieceSize = _heightLat / Math.pow(2, _maxPoleZoom);
15
+
16
+ let _tempHigh = new Vec3(),
17
+ _tempLow = new Vec3();
18
+
19
+ /**
20
+ * Planet segment Web Mercator tile class that stored and rendered with quad tree.
21
+ * @class
22
+ * @extends {Segment}
23
+ * @param {quadNode.Node} node - Quad tree segment node.
24
+ * @param {Planet} planet - Scene planet.
25
+ * @param {Number} tileZoom - Segment tile zoom index.
26
+ * @param {Extent} extent - Segment WGS84 extent.
27
+ */
28
+ class SegmentLonLat extends Segment {
29
+ /**
30
+ * @param {quadTree.Node} node - Segment node.
31
+ * @param {Planet} planet - Current planet scene.
32
+ * @param {number} tileZoom - Zoom index.
33
+ * @param {Extent} extent - Segment extent.
34
+ */
35
+ constructor(node, planet, tileZoom, extent) {
36
+ super(node, planet, tileZoom, extent);
37
+
38
+ // TODO:
39
+ // be carefull with functions in constructor _assignTileIndexes
40
+ // this._isNorth = false;
41
+
42
+ this._projection = EPSG4326;
43
+ this._extentMerc = new Extent(
44
+ extent.southWest.forwardMercatorEPS01(),
45
+ extent.northEast.forwardMercatorEPS01()
46
+ );
47
+ this.isPole = true;
48
+ }
49
+
50
+ _setExtentLonLat() {
51
+ this._extentLonLat = this._extent;
52
+ }
53
+
54
+ projectNative(coords) {
55
+ return coords;
56
+ }
57
+
58
+ getTerrainPoint(xyz, insideSegmentPosition, res, normal) {
59
+ res.copy(this.planet.ellipsoid.hitRay(xyz, xyz.negateTo().normalize()));
60
+ if (normal) {
61
+ normal.copy(res.normal());
62
+ }
63
+ return xyz.length() - res.length();
64
+ }
65
+
66
+ acceptForRendering(camera) {
67
+ var maxPoleZoom;
68
+ var lat = this._extent.northEast.lat;
69
+ if (this._isNorth) {
70
+ //north pole limits
71
+ let Yz = Math.floor((90.0 - lat) / _pieceSize);
72
+ maxPoleZoom = Math.floor(Yz / 16) + 7;
73
+ } else {
74
+ //south pole limits
75
+ let Yz = Math.floor((mercator.MIN_LAT - lat) / _pieceSize);
76
+ maxPoleZoom = 12 - Math.floor(Yz / 16);
77
+ }
78
+ return (
79
+ Segment.prototype.acceptForRendering.call(this, camera) || this.tileZoom >= maxPoleZoom
80
+ );
81
+ }
82
+
83
+ _assignTileIndexes() {
84
+ var tileZoom = this.tileZoom;
85
+ var extent = this._extent;
86
+
87
+ this.tileX = Math.round(
88
+ Math.abs(-180.0 - extent.southWest.lon) / (extent.northEast.lon - extent.southWest.lon)
89
+ );
90
+
91
+ var lat = extent.northEast.lat;
92
+
93
+ if (lat > 0) {
94
+ //north pole
95
+ this._isNorth = true;
96
+ this._tileGroup = 1;
97
+ this.tileY = Math.round((90.0 - lat) / (extent.northEast.lat - extent.southWest.lat));
98
+ } else {
99
+ //south pole
100
+ this._tileGroup = 2;
101
+ this.tileY = Math.round(
102
+ (mercator.MIN_LAT - lat) / (extent.northEast.lat - extent.southWest.lat)
103
+ );
104
+ }
105
+
106
+ var p2 = 1 << tileZoom;
107
+ this.tileXE = (this.tileX + 1) % p2;
108
+ this.tileXW = (p2 + this.tileX - 1) % p2;
109
+
110
+ this.tileYN = this.tileY - 1;
111
+ this.tileYS = this.tileY + 1;
112
+
113
+ this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
114
+ }
115
+
116
+ _createPlainVertices() {
117
+ var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
118
+
119
+ var e = this._extent,
120
+ fgs = this.planet.terrain.plainGridSize;
121
+ var lonSize = e.getWidth();
122
+ var latSize = e.getHeight();
123
+ var llStep = lonSize / Math.max(fgs, gridSize);
124
+ var ltStep = latSize / gridSize;
125
+ var esw_lon = e.southWest.lon,
126
+ ene_lat = e.northEast.lat;
127
+ var dg = Math.max(fgs / gridSize, 1),
128
+ gs = Math.max(fgs, gridSize) + 1;
129
+ var r2 = this.planet.ellipsoid._invRadii2;
130
+ var ind = 0,
131
+ nmInd = 0;
132
+ const gsgs = gs * gs;
133
+
134
+ var gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
135
+
136
+ this.plainNormals = new Float32Array(gridSize3);
137
+ this.plainVertices = new Float64Array(gridSize3);
138
+ this.plainVerticesHigh = new Float32Array(gridSize3);
139
+ this.plainVerticesLow = new Float32Array(gridSize3);
140
+
141
+ this.normalMapNormals = new Float32Array(gsgs * 3);
142
+ this.normalMapVertices = new Float64Array(gsgs * 3);
143
+ this.normalMapVerticesHigh = new Float32Array(gsgs * 3);
144
+ this.normalMapVerticesLow = new Float32Array(gsgs * 3);
145
+
146
+ let xmin = 549755748352.0,
147
+ xmax = -549755748352.0,
148
+ ymin = 549755748352.0,
149
+ ymax = -549755748352.0,
150
+ zmin = 549755748352.0,
151
+ zmax = -549755748352.0;
152
+
153
+ var verts = this.plainVertices,
154
+ vertsHigh = this.plainVerticesHigh,
155
+ vertsLow = this.plainVerticesLow,
156
+ norms = this.plainNormals,
157
+ nmVerts = this.normalMapVertices,
158
+ nmVertsHigh = this.normalMapVerticesHigh,
159
+ nmVertsLow = this.normalMapVerticesLow,
160
+ nmNorms = this.normalMapNormals;
161
+
162
+ for (var k = 0; k < gsgs; k++) {
163
+ var j = k % gs,
164
+ i = ~~(k / gs);
165
+
166
+ var v = this.planet.ellipsoid.lonLatToCartesian(
167
+ new LonLat(esw_lon + j * llStep, ene_lat - i * ltStep)
168
+ );
169
+ var nx = v.x * r2.x,
170
+ ny = v.y * r2.y,
171
+ nz = v.z * r2.z;
172
+ var l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
173
+ var nxl = nx * l,
174
+ nyl = ny * l,
175
+ nzl = nz * l;
176
+
177
+ Vec3.doubleToTwoFloats(v, _tempHigh, _tempLow);
178
+
179
+ nmVerts[nmInd] = v.x;
180
+ nmVertsHigh[nmInd] = _tempHigh.x;
181
+ nmVertsLow[nmInd] = _tempLow.x;
182
+ nmNorms[nmInd++] = nxl;
183
+
184
+ nmVerts[nmInd] = v.y;
185
+ nmVertsHigh[nmInd] = _tempHigh.y;
186
+ nmVertsLow[nmInd] = _tempLow.y;
187
+ nmNorms[nmInd++] = nyl;
188
+
189
+ nmVerts[nmInd] = v.z;
190
+ nmVertsHigh[nmInd] = _tempHigh.z;
191
+ nmVertsLow[nmInd] = _tempLow.z;
192
+ nmNorms[nmInd++] = nzl;
193
+
194
+ if (i % dg === 0 && j % dg === 0) {
195
+ verts[ind] = v.x;
196
+ vertsHigh[ind] = _tempHigh.x;
197
+ vertsLow[ind] = _tempLow.x;
198
+ norms[ind++] = nxl;
199
+
200
+ verts[ind] = v.y;
201
+ vertsHigh[ind] = _tempHigh.y;
202
+ vertsLow[ind] = _tempLow.y;
203
+ norms[ind++] = nyl;
204
+
205
+ verts[ind] = v.z;
206
+ vertsHigh[ind] = _tempHigh.z;
207
+ vertsLow[ind] = _tempLow.z;
208
+ norms[ind++] = nzl;
209
+
210
+ if (v.x < xmin) xmin = v.x;
211
+ if (v.x > xmax) xmax = v.x;
212
+ if (v.y < ymin) ymin = v.y;
213
+ if (v.y > ymax) ymax = v.y;
214
+ if (v.z < zmin) zmin = v.z;
215
+ if (v.z > zmax) zmax = v.z;
216
+ }
217
+ }
218
+
219
+ this.terrainVertices = verts;
220
+ this.terrainVerticesHigh = vertsHigh;
221
+ this.terrainVerticesLow = vertsLow;
222
+
223
+ //store raw normals
224
+ this.normalMapNormalsRaw = new Float32Array(nmNorms.length);
225
+ this.normalMapNormalsRaw.set(nmNorms);
226
+
227
+ let x = (xmax - xmin) * 0.5,
228
+ y = (ymax - ymin) * 0.5,
229
+ z = (zmax - zmin) * 0.5;
230
+
231
+ this._plainRadius = Math.sqrt(x * x + y * y + z * z);
232
+
233
+ this.plainReady = true;
234
+ }
235
+
236
+ _assignGlobalTextureCoordinates() {
237
+ var e = this._extent;
238
+ this._globalTextureCoordinates[0] = (e.southWest.lon + 180.0) / 360.0;
239
+ this._globalTextureCoordinates[1] = (90 - e.northEast.lat) / 180.0;
240
+ this._globalTextureCoordinates[2] = (e.northEast.lon + 180.0) / 360.0;
241
+ this._globalTextureCoordinates[3] = (90 - e.southWest.lat) / 180.0;
242
+ }
243
+
244
+ _collectVisibleNodes() {
245
+ if (this._isNorth) {
246
+ this.planet._visibleNodesNorth[this.node.nodeId] = this.node;
247
+ } else {
248
+ this.planet._visibleNodesSouth[this.node.nodeId] = this.node;
249
+ }
250
+ }
251
+
252
+ isEntityInside(e) {
253
+ return this._extent.isInside(e._lonlat);
254
+ }
255
+
256
+ _getLayerExtentOffset(layer) {
257
+ var v0s = layer._extent;
258
+ var v0t = this._extent;
259
+ var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
260
+ var sSize_y = v0s.northEast.lat - v0s.southWest.lat;
261
+ var dV0s_x = (v0t.southWest.lon - v0s.southWest.lon) / sSize_x;
262
+ var dV0s_y = (v0s.northEast.lat - v0t.northEast.lat) / sSize_y;
263
+ var dSize_x = (v0t.northEast.lon - v0t.southWest.lon) / sSize_x;
264
+ var dSize_y = (v0t.northEast.lat - v0t.southWest.lat) / sSize_y;
265
+ return [dV0s_x, dV0s_y, dSize_x, dSize_y];
266
+ }
267
+
268
+ layerOverlap(layer) {
269
+ return this._extent.overlaps(layer._extent);
270
+ }
271
+
272
+ getDefaultTexture() {
273
+ return this._isNorth ? this.planet.solidTextureOne : this.planet.solidTextureTwo;
274
+ }
275
+
276
+ getExtentLonLat() {
277
+ return this._extent;
278
+ }
279
+
280
+ getExtentMerc() {
281
+ return this._extentMerc;
282
+ }
283
+
284
+ getNodeState() {
285
+ var vn;
286
+ if (this._isNorth) {
287
+ vn = this.planet._visibleNodesNorth[this.node.nodeId];
288
+ } else {
289
+ vn = this.planet._visibleNodesSouth[this.node.nodeId];
290
+ }
291
+ return (vn && vn.state) || quadTree.NOTRENDERING;
292
+ }
293
+
294
+ _freeCache() {
295
+ //empty for a time
296
+ }
297
+ }
298
+ export { SegmentLonLat };
@@ -4,7 +4,7 @@ import { N, W, S, E } from '../quadTree/quadTree.js';
4
4
 
5
5
  function NewIndexesTypedArray(arr) {
6
6
  return new Uint32Array(arr);
7
- };
7
+ }
8
8
 
9
9
  function createCenterBodyIndexes(size) {
10
10
 
@@ -29,7 +29,7 @@ function createCenterBodyIndexes(size) {
29
29
  indexes.push(indexes[indexes.length - 1], size * size - size);
30
30
 
31
31
  return NewIndexesTypedArray(indexes);
32
- };
32
+ }
33
33
 
34
34
  function createWestNeighborSkirt(size, deltaGr) {
35
35
  let indexes = [];
@@ -51,7 +51,7 @@ function createWestNeighborSkirt(size, deltaGr) {
51
51
  }
52
52
 
53
53
  return NewIndexesTypedArray(indexes);
54
- };
54
+ }
55
55
 
56
56
  function createNorthNeighborSkirt(size, deltaGr) {
57
57
  let indexes = [];
@@ -72,7 +72,7 @@ function createNorthNeighborSkirt(size, deltaGr) {
72
72
  }
73
73
 
74
74
  return NewIndexesTypedArray(indexes);
75
- };
75
+ }
76
76
 
77
77
  function createEastNeighborSkirt(size, deltaGr) {
78
78
  let indexes = [];
@@ -93,7 +93,7 @@ function createEastNeighborSkirt(size, deltaGr) {
93
93
  }
94
94
 
95
95
  return NewIndexesTypedArray(indexes);
96
- };
96
+ }
97
97
 
98
98
  function createSouthNeighborSkirt(size, deltaGr) {
99
99
  let indexes = [];
@@ -116,7 +116,7 @@ function createSouthNeighborSkirt(size, deltaGr) {
116
116
  indexes.push(size * size - size);
117
117
 
118
118
  return NewIndexesTypedArray(indexes);
119
- };
119
+ }
120
120
 
121
121
  function initIndexesBodySkirts(pow) {
122
122
  var table = [];
@@ -145,7 +145,7 @@ function initIndexesBodySkirts(pow) {
145
145
  }
146
146
  }
147
147
  return table;
148
- };
148
+ }
149
149
 
150
150
  function initIndexBodiesTable(pow) {
151
151
  var table = [];
@@ -154,7 +154,7 @@ function initIndexBodiesTable(pow) {
154
154
  table[i] = createCenterBodyIndexes(d + 1);
155
155
  }
156
156
  return table;
157
- };
157
+ }
158
158
 
159
159
  function createTextureCoords(size) {
160
160
  var texCoords = new Uint16Array((size + 1) * (size + 1) * 2);
@@ -166,7 +166,7 @@ function createTextureCoords(size) {
166
166
  }
167
167
  }
168
168
  return texCoords;
169
- };
169
+ }
170
170
 
171
171
  class SegmentHelper {
172
172
  constructor(maxGridSize = 0) {
@@ -217,10 +217,10 @@ class SegmentHelper {
217
217
  }
218
218
  return table;
219
219
  }
220
- };
220
+ }
221
221
 
222
222
  let instance = new SegmentHelper();
223
223
 
224
224
  export function getInstance() {
225
225
  return instance;
226
- };
226
+ }