@openglobus/og 0.11.6 → 0.12.1
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.
- package/css/og.css +5 -2
- package/package.json +12 -12
- package/src/og/Globe.js +25 -10
- package/src/og/Popup.js +3 -2
- package/src/og/camera/Camera.js +70 -79
- package/src/og/camera/PlanetCamera.js +33 -33
- package/src/og/control/DebugInfo.js +2 -2
- package/src/og/control/EarthNavigation.js +26 -17
- package/src/og/control/Lighting.js +74 -64
- package/src/og/control/MouseNavigation.js +30 -29
- package/src/og/control/MouseWheelZoomControl.js +257 -0
- package/src/og/control/Sun.js +3 -3
- package/src/og/control/index.js +2 -0
- package/src/og/control/visibleExtent/Segment.js +1862 -0
- package/src/og/control/visibleExtent/VisibleExtent.js +80 -0
- package/src/og/control/visibleExtent/drawnode.js +751 -0
- package/src/og/ellipsoid/Ellipsoid.js +1 -1
- package/src/og/entity/BaseBillboard.js +67 -76
- package/src/og/entity/BillboardHandler.js +15 -8
- package/src/og/entity/Entity.js +742 -742
- package/src/og/entity/GeoObjectHandler.js +102 -117
- package/src/og/entity/Label.js +45 -48
- package/src/og/entity/LabelHandler.js +24 -23
- package/src/og/entity/LabelWorker.js +21 -16
- package/src/og/layer/CanvasTiles.js +8 -12
- package/src/og/layer/GeoImage.js +2 -10
- package/src/og/layer/GeoTexture2d.js +2 -10
- package/src/og/layer/GeoVideo.js +2 -10
- package/src/og/layer/Layer.js +23 -32
- package/src/og/layer/Material.js +1 -1
- package/src/og/layer/WMS.js +0 -2
- package/src/og/layer/XYZ.js +31 -33
- package/src/og/math/Vec3.js +18 -2
- package/src/og/quadTree/Node.js +52 -111
- package/src/og/quadTree/quadTree.js +1 -1
- package/src/og/renderer/Renderer.js +85 -122
- package/src/og/renderer/RendererEvents.js +44 -22
- package/src/og/scene/Planet.js +179 -198
- package/src/og/segment/Segment.js +99 -268
- package/src/og/segment/Slice.js +45 -0
- package/src/og/shaders/drawnode.js +174 -360
- package/src/og/shaders/toneMapping.js +1 -0
- package/src/og/shapes/BaseShape.js +1 -1
- package/src/og/terrain/EmptyTerrain.js +3 -2
- package/src/og/terrain/GlobusTerrain.js +2 -0
- package/src/og/utils/FontAtlas.js +6 -2
- package/src/og/utils/GeoImageCreator.js +5 -1
- package/src/og/utils/Loader.js +1 -1
- package/src/og/utils/PlainSegmentWorker.js +0 -13
- package/src/og/utils/TextureAtlas.js +2 -2
- package/src/og/utils/VectorTileCreator.js +1 -3
- package/src/og/utils/shared.js +1 -1
- package/src/og/webgl/Handler.js +156 -118
- package/types/Clock.d.ts +0 -94
- package/types/Deferred.d.ts +0 -6
- package/types/Events.d.ts +0 -77
- package/types/Extent.d.ts +0 -166
- package/types/Globe.d.ts +0 -82
- package/types/ImageCanvas.d.ts +0 -123
- package/types/Lock.d.ts +0 -12
- package/types/LonLat.d.ts +0 -108
- package/types/Popup.d.ts +0 -42
- package/types/QueueArray.d.ts +0 -19
- package/types/Rectangle.d.ts +0 -80
- package/types/Stack.d.ts +0 -19
- package/types/ajax.d.ts +0 -24
- package/types/arial.d.ts +0 -48
- package/types/astro/astro.d.ts +0 -38
- package/types/astro/earth.d.ts +0 -7
- package/types/astro/jd.d.ts +0 -254
- package/types/bv/Box.d.ts +0 -30
- package/types/bv/Sphere.d.ts +0 -38
- package/types/bv/index.d.ts +0 -3
- package/types/camera/Camera.d.ts +0 -312
- package/types/camera/Frustum.d.ts +0 -133
- package/types/camera/PlanetCamera.d.ts +0 -218
- package/types/camera/index.d.ts +0 -3
- package/types/cons.d.ts +0 -40
- package/types/control/CompassButton.d.ts +0 -17
- package/types/control/Control.d.ts +0 -104
- package/types/control/DebugInfo.d.ts +0 -15
- package/types/control/EarthCoordinates.d.ts +0 -47
- package/types/control/EarthNavigation.d.ts +0 -42
- package/types/control/GeoImageDragControl.d.ts +0 -6
- package/types/control/KeyboardNavigation.d.ts +0 -21
- package/types/control/LayerSwitcher.d.ts +0 -21
- package/types/control/Lighting.d.ts +0 -16
- package/types/control/MouseNavigation.d.ts +0 -47
- package/types/control/ScaleControl.d.ts +0 -22
- package/types/control/ShowFps.d.ts +0 -11
- package/types/control/SimpleNavigation.d.ts +0 -25
- package/types/control/Sun.d.ts +0 -50
- package/types/control/ToggleWireframe.d.ts +0 -12
- package/types/control/TouchNavigation.d.ts +0 -48
- package/types/control/ZoomControl.d.ts +0 -27
- package/types/control/index.d.ts +0 -17
- package/types/ellipsoid/Ellipsoid.d.ts +0 -146
- package/types/ellipsoid/index.d.ts +0 -3
- package/types/ellipsoid/wgs84.d.ts +0 -6
- package/types/entity/BaseBillboard.d.ts +0 -215
- package/types/entity/Billboard.d.ts +0 -94
- package/types/entity/BillboardHandler.d.ts +0 -78
- package/types/entity/Entity.d.ts +0 -348
- package/types/entity/EntityCollection.d.ts +0 -317
- package/types/entity/GeoObject.d.ts +0 -111
- package/types/entity/GeoObjectHandler.d.ts +0 -77
- package/types/entity/Geometry.d.ts +0 -74
- package/types/entity/GeometryHandler.d.ts +0 -76
- package/types/entity/Label.d.ts +0 -189
- package/types/entity/LabelHandler.d.ts +0 -31
- package/types/entity/LabelWorker.d.ts +0 -9
- package/types/entity/PointCloud.d.ts +0 -174
- package/types/entity/PointCloudHandler.d.ts +0 -38
- package/types/entity/Polyline.d.ts +0 -306
- package/types/entity/PolylineHandler.d.ts +0 -18
- package/types/entity/Ray.d.ts +0 -124
- package/types/entity/RayHandler.d.ts +0 -67
- package/types/entity/ShapeHandler.d.ts +0 -22
- package/types/entity/Strip.d.ts +0 -119
- package/types/entity/StripHandler.d.ts +0 -38
- package/types/entity/index.d.ts +0 -8
- package/types/index.core.d.ts +0 -65
- package/types/index.d.ts +0 -45
- package/types/index.webgl.d.ts +0 -7
- package/types/input/KeyboardHandler.d.ts +0 -10
- package/types/input/MouseHandler.d.ts +0 -5
- package/types/input/TouchHandler.d.ts +0 -5
- package/types/input/input.d.ts +0 -34
- package/types/layer/BaseGeoImage.d.ts +0 -94
- package/types/layer/CanvasTiles.d.ts +0 -68
- package/types/layer/GeoImage.d.ts +0 -52
- package/types/layer/GeoTexture2d.d.ts +0 -8
- package/types/layer/GeoVideo.d.ts +0 -55
- package/types/layer/KML.d.ts +0 -63
- package/types/layer/Layer.d.ts +0 -326
- package/types/layer/Material.d.ts +0 -45
- package/types/layer/Vector.d.ts +0 -208
- package/types/layer/WMS.d.ts +0 -63
- package/types/layer/XYZ.d.ts +0 -120
- package/types/layer/index.d.ts +0 -10
- package/types/light/LightSource.d.ts +0 -178
- package/types/math/Line2.d.ts +0 -11
- package/types/math/Line3.d.ts +0 -10
- package/types/math/Mat3.d.ts +0 -65
- package/types/math/Mat4.d.ts +0 -176
- package/types/math/Plane.d.ts +0 -18
- package/types/math/Quat.d.ts +0 -379
- package/types/math/Ray.d.ts +0 -82
- package/types/math/Vec2.d.ts +0 -309
- package/types/math/Vec3.d.ts +0 -460
- package/types/math/Vec4.d.ts +0 -162
- package/types/math/coder.d.ts +0 -43
- package/types/math/index.d.ts +0 -11
- package/types/math.d.ts +0 -261
- package/types/mercator.d.ts +0 -92
- package/types/proj/EPSG3857.d.ts +0 -6
- package/types/proj/EPSG4326.d.ts +0 -6
- package/types/proj/Proj.d.ts +0 -42
- package/types/quadTree/EntityCollectionNode.d.ts +0 -34
- package/types/quadTree/Node.d.ts +0 -61
- package/types/quadTree/quadTree.d.ts +0 -40
- package/types/renderer/Renderer.d.ts +0 -300
- package/types/renderer/RendererEvents.d.ts +0 -233
- package/types/res/images.d.ts +0 -3
- package/types/scene/Axes.d.ts +0 -11
- package/types/scene/BaseNode.d.ts +0 -60
- package/types/scene/Planet.d.ts +0 -577
- package/types/scene/RenderNode.d.ts +0 -142
- package/types/scene/SkyBox.d.ts +0 -10
- package/types/scene/index.d.ts +0 -4
- package/types/segment/Segment.d.ts +0 -279
- package/types/segment/SegmentLonLat.d.ts +0 -16
- package/types/segment/segmentHelper.d.ts +0 -13
- package/types/shaders/billboard.d.ts +0 -3
- package/types/shaders/depth.d.ts +0 -2
- package/types/shaders/drawnode.d.ts +0 -7
- package/types/shaders/geoObject.d.ts +0 -3
- package/types/shaders/label.d.ts +0 -4
- package/types/shaders/pointCloud.d.ts +0 -2
- package/types/shaders/polyline.d.ts +0 -3
- package/types/shaders/ray.d.ts +0 -2
- package/types/shaders/screenFrame.d.ts +0 -2
- package/types/shaders/shape.d.ts +0 -4
- package/types/shaders/skybox.d.ts +0 -2
- package/types/shaders/toneMapping.d.ts +0 -2
- package/types/shapes/BaseShape.d.ts +0 -250
- package/types/shapes/Sphere.d.ts +0 -41
- package/types/terrain/BilTerrain.d.ts +0 -7
- package/types/terrain/EmptyTerrain.d.ts +0 -72
- package/types/terrain/Geoid.d.ts +0 -26
- package/types/terrain/GlobusTerrain.d.ts +0 -116
- package/types/terrain/MapboxTerrain.d.ts +0 -7
- package/types/terrain/index.d.ts +0 -5
- package/types/utils/FontAtlas.d.ts +0 -14
- package/types/utils/GeoImageCreator.d.ts +0 -30
- package/types/utils/ImagesCacheManager.d.ts +0 -10
- package/types/utils/Loader.d.ts +0 -25
- package/types/utils/NormalMapCreator.d.ts +0 -39
- package/types/utils/PlainSegmentWorker.d.ts +0 -10
- package/types/utils/TerrainWorker.d.ts +0 -9
- package/types/utils/TextureAtlas.d.ts +0 -111
- package/types/utils/VectorTileCreator.d.ts +0 -16
- package/types/utils/colorTable.d.ts +0 -143
- package/types/utils/earcut.d.ts +0 -6
- package/types/utils/shared.d.ts +0 -231
- package/types/webgl/Framebuffer.d.ts +0 -135
- package/types/webgl/Handler.d.ts +0 -397
- package/types/webgl/Multisample.d.ts +0 -89
- package/types/webgl/Program.d.ts +0 -161
- package/types/webgl/ProgramController.d.ts +0 -89
- package/types/webgl/callbacks.d.ts +0 -1
- package/types/webgl/index.d.ts +0 -6
- package/types/webgl/types.d.ts +0 -2
|
@@ -0,0 +1,1862 @@
|
|
|
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.layerOpacityArr = new Float32Array(p.SLICE_SIZE);
|
|
26
|
+
|
|
27
|
+
this.clear = function () {
|
|
28
|
+
this.layers = null;
|
|
29
|
+
this.tileOffsetArr = null;
|
|
30
|
+
this.visibleExtentOffsetArr = null;
|
|
31
|
+
this.layerOpacityArr = 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._projection = null;
|
|
994
|
+
this._appliedNeighborsZoom = null;
|
|
995
|
+
|
|
996
|
+
this._globalTextureCoordinates = null;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
_setExtentLonLat() {
|
|
1000
|
+
this._extentLonLat = this._extent.inverseMercator();
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Creates bound volumes by segment geographical extent.
|
|
1005
|
+
*/
|
|
1006
|
+
createBoundsByExtent() {
|
|
1007
|
+
var ellipsoid = this.planet.ellipsoid,
|
|
1008
|
+
extent = this._extentLonLat;
|
|
1009
|
+
|
|
1010
|
+
var coord_sw = ellipsoid.geodeticToCartesian(extent.southWest.lon, extent.southWest.lat);
|
|
1011
|
+
var coord_ne = ellipsoid.geodeticToCartesian(extent.northEast.lon, extent.northEast.lat);
|
|
1012
|
+
|
|
1013
|
+
// check for zoom
|
|
1014
|
+
if (this.tileZoom <= MAX_NORMAL_ZOOM) {
|
|
1015
|
+
var coord_nw = ellipsoid.geodeticToCartesian(
|
|
1016
|
+
extent.southWest.lon,
|
|
1017
|
+
extent.northEast.lat
|
|
1018
|
+
);
|
|
1019
|
+
var coord_se = ellipsoid.geodeticToCartesian(
|
|
1020
|
+
extent.northEast.lon,
|
|
1021
|
+
extent.southWest.lat
|
|
1022
|
+
);
|
|
1023
|
+
|
|
1024
|
+
this._swNorm = coord_sw.normal();
|
|
1025
|
+
this._nwNorm = coord_nw.normal();
|
|
1026
|
+
this._neNorm = coord_ne.normal();
|
|
1027
|
+
this._seNorm = coord_se.normal();
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
this.setBoundingVolume3v(coord_sw, coord_ne);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
createBoundsByParent() {
|
|
1034
|
+
let pn = this.node;
|
|
1035
|
+
|
|
1036
|
+
while (pn.parentNode && !pn.segment.terrainReady) {
|
|
1037
|
+
pn = pn.parentNode;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
let dZ2 = 1 << (this.tileZoom - pn.segment.tileZoom);
|
|
1041
|
+
|
|
1042
|
+
let offsetX = this.tileX - pn.segment.tileX * dZ2,
|
|
1043
|
+
offsetY = this.tileY - pn.segment.tileY * dZ2;
|
|
1044
|
+
|
|
1045
|
+
if (pn.segment.terrainReady && pn.segment.tileZoom >= this.planet.terrain.minZoom) {
|
|
1046
|
+
let gridSize = pn.segment.gridSize / dZ2;
|
|
1047
|
+
|
|
1048
|
+
if (gridSize >= 1.0) {
|
|
1049
|
+
//
|
|
1050
|
+
// (*) Actually, we get parent whole bounding volume
|
|
1051
|
+
//
|
|
1052
|
+
this.bsphere.center.x = pn.segment.bsphere.center.x;
|
|
1053
|
+
this.bsphere.center.y = pn.segment.bsphere.center.y;
|
|
1054
|
+
this.bsphere.center.z = pn.segment.bsphere.center.z;
|
|
1055
|
+
this.bsphere.radius = pn.segment.bsphere.radius;
|
|
1056
|
+
|
|
1057
|
+
if (this.tileZoom <= MAX_NORMAL_ZOOM) {
|
|
1058
|
+
let i0 = gridSize * offsetY;
|
|
1059
|
+
let j0 = gridSize * offsetX;
|
|
1060
|
+
|
|
1061
|
+
let pnGsOne = pn.segment.gridSize + 1;
|
|
1062
|
+
|
|
1063
|
+
let ind_sw = 3 * ((i0 + gridSize) * pnGsOne + j0),
|
|
1064
|
+
ind_nw = 3 * (i0 * pnGsOne + j0),
|
|
1065
|
+
ind_ne = 3 * (i0 * pnGsOne + j0 + gridSize),
|
|
1066
|
+
ind_se = 3 * ((i0 + gridSize) * pnGsOne + j0 + gridSize);
|
|
1067
|
+
|
|
1068
|
+
let pVerts = pn.segment.tempVertices;
|
|
1069
|
+
|
|
1070
|
+
let v_sw = new Vec3(pVerts[ind_sw], pVerts[ind_sw + 1], pVerts[ind_sw + 2]),
|
|
1071
|
+
v_ne = new Vec3(pVerts[ind_ne], pVerts[ind_ne + 1], pVerts[ind_ne + 2]);
|
|
1072
|
+
|
|
1073
|
+
// check for segment zoom
|
|
1074
|
+
let v_nw = new Vec3(pVerts[ind_nw], pVerts[ind_nw + 1], pVerts[ind_nw + 2]),
|
|
1075
|
+
v_se = new Vec3(pVerts[ind_se], pVerts[ind_se + 1], pVerts[ind_se + 2]);
|
|
1076
|
+
|
|
1077
|
+
this._swNorm = v_sw.normal();
|
|
1078
|
+
this._nwNorm = v_nw.normal();
|
|
1079
|
+
this._neNorm = v_ne.normal();
|
|
1080
|
+
this._seNorm = v_se.normal();
|
|
1081
|
+
}
|
|
1082
|
+
} else {
|
|
1083
|
+
let pseg = pn.segment;
|
|
1084
|
+
|
|
1085
|
+
let i0 = Math.floor(gridSize * offsetY),
|
|
1086
|
+
j0 = Math.floor(gridSize * offsetX);
|
|
1087
|
+
|
|
1088
|
+
let insideSize = 1.0 / gridSize;
|
|
1089
|
+
|
|
1090
|
+
let t_i0 = offsetY - insideSize * i0,
|
|
1091
|
+
t_j0 = offsetX - insideSize * j0;
|
|
1092
|
+
|
|
1093
|
+
let bigOne;
|
|
1094
|
+
if (pseg.gridSize === 1) {
|
|
1095
|
+
bigOne = pseg.tempVertices;
|
|
1096
|
+
} else {
|
|
1097
|
+
bigOne = getMatrixSubArray(pseg.tempVertices, pseg.gridSize, i0, j0, 1);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
let v_lt = new Vec3(bigOne[0], bigOne[1], bigOne[2]),
|
|
1101
|
+
v_rb = new Vec3(bigOne[9], bigOne[10], bigOne[11]);
|
|
1102
|
+
|
|
1103
|
+
let vn = new Vec3(
|
|
1104
|
+
bigOne[3] - bigOne[0],
|
|
1105
|
+
bigOne[4] - bigOne[1],
|
|
1106
|
+
bigOne[5] - bigOne[2]
|
|
1107
|
+
),
|
|
1108
|
+
vw = new Vec3(
|
|
1109
|
+
bigOne[6] - bigOne[0],
|
|
1110
|
+
bigOne[7] - bigOne[1],
|
|
1111
|
+
bigOne[8] - bigOne[2]
|
|
1112
|
+
),
|
|
1113
|
+
ve = new Vec3(
|
|
1114
|
+
bigOne[3] - bigOne[9],
|
|
1115
|
+
bigOne[4] - bigOne[10],
|
|
1116
|
+
bigOne[5] - bigOne[11]
|
|
1117
|
+
),
|
|
1118
|
+
vs = new Vec3(
|
|
1119
|
+
bigOne[6] - bigOne[9],
|
|
1120
|
+
bigOne[7] - bigOne[10],
|
|
1121
|
+
bigOne[8] - bigOne[11]
|
|
1122
|
+
);
|
|
1123
|
+
|
|
1124
|
+
let vi_y = t_i0,
|
|
1125
|
+
vi_x = t_j0;
|
|
1126
|
+
|
|
1127
|
+
let coords_lt, coords_rb;
|
|
1128
|
+
|
|
1129
|
+
if (vi_y + vi_x < insideSize) {
|
|
1130
|
+
coords_lt = Vec3.add(
|
|
1131
|
+
vn.scaleTo(vi_x / insideSize),
|
|
1132
|
+
vw.scaleTo(vi_y / insideSize)
|
|
1133
|
+
).addA(v_lt);
|
|
1134
|
+
} else {
|
|
1135
|
+
coords_lt = Vec3.add(
|
|
1136
|
+
vs.scaleTo(1 - vi_x / insideSize),
|
|
1137
|
+
ve.scaleTo(1 - vi_y / insideSize)
|
|
1138
|
+
).addA(v_rb);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
vi_y = t_i0 + 1;
|
|
1142
|
+
vi_x = t_j0 + 1;
|
|
1143
|
+
|
|
1144
|
+
if (vi_y + vi_x < insideSize) {
|
|
1145
|
+
coords_rb = Vec3.add(
|
|
1146
|
+
vn.scaleTo(vi_x / insideSize),
|
|
1147
|
+
vw.scaleTo(vi_y / insideSize)
|
|
1148
|
+
).addA(v_lt);
|
|
1149
|
+
} else {
|
|
1150
|
+
coords_rb = Vec3.add(
|
|
1151
|
+
vs.scaleTo(1 - vi_x / insideSize),
|
|
1152
|
+
ve.scaleTo(1 - vi_y / insideSize)
|
|
1153
|
+
).addA(v_rb);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
this.setBoundingVolume3v(coords_lt, coords_rb);
|
|
1157
|
+
}
|
|
1158
|
+
} else {
|
|
1159
|
+
this.createBoundsByExtent();
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
setBoundingSphere(x, y, z, v) {
|
|
1164
|
+
this.bsphere.center.x = x;
|
|
1165
|
+
this.bsphere.center.y = y;
|
|
1166
|
+
this.bsphere.center.z = z;
|
|
1167
|
+
this.bsphere.radius = this.bsphere.center.distance(v);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
setBoundingVolume(xmin, ymin, zmin, xmax, ymax, zmax) {
|
|
1171
|
+
this.bbox.setFromBoundsArr([xmin, ymin, zmin, xmax, ymax, zmax]);
|
|
1172
|
+
|
|
1173
|
+
let x = xmin + (xmax - xmin) * 0.5,
|
|
1174
|
+
y = ymin + (ymax - ymin) * 0.5,
|
|
1175
|
+
z = zmin + (zmax - zmin) * 0.5;
|
|
1176
|
+
|
|
1177
|
+
this.bsphere.center.set(x, y, z);
|
|
1178
|
+
this.bsphere.radius = this.bsphere.center.distance(new Vec3(xmin, ymin, zmin));
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
setBoundingVolume3v(vmin, vmax) {
|
|
1182
|
+
this.bbox.setFromBoundsArr([vmin.x, vmin.y, vmin.z, vmax.x, vmax.y, vmax.z]);
|
|
1183
|
+
|
|
1184
|
+
let x = vmin.x + (vmax.x - vmin.x) * 0.5,
|
|
1185
|
+
y = vmin.y + (vmax.y - vmin.y) * 0.5,
|
|
1186
|
+
z = vmin.z + (vmax.z - vmin.z) * 0.5;
|
|
1187
|
+
|
|
1188
|
+
this.bsphere.center.set(x, y, z);
|
|
1189
|
+
this.bsphere.radius = this.bsphere.center.distance(new Vec3(vmin.x, vmin.y, vmin.z));
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
setBoundingVolumeArr(bounds) {
|
|
1193
|
+
this.bbox.setFromBoundsArr(bounds);
|
|
1194
|
+
|
|
1195
|
+
let x = bounds[0] + (bounds[3] - bounds[0]) * 0.5,
|
|
1196
|
+
y = bounds[1] + (bounds[4] - bounds[1]) * 0.5,
|
|
1197
|
+
z = bounds[2] + (bounds[5] - bounds[2]) * 0.5;
|
|
1198
|
+
|
|
1199
|
+
this.bsphere.center.set(x, y, z);
|
|
1200
|
+
this.bsphere.radius = this.bsphere.center.distance(
|
|
1201
|
+
new Vec3(bounds[0], bounds[1], bounds[2])
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
createCoordsBuffers(verticesHigh, verticesLow, gridSize) {
|
|
1206
|
+
var gsgs = (gridSize + 1) * (gridSize + 1);
|
|
1207
|
+
var h = this.handler;
|
|
1208
|
+
|
|
1209
|
+
if (this.vertexPositionBufferHigh && this.vertexPositionBufferHigh.numItems === gsgs) {
|
|
1210
|
+
h.setStreamArrayBuffer(this.vertexPositionBufferHigh, verticesHigh);
|
|
1211
|
+
h.setStreamArrayBuffer(this.vertexPositionBufferLow, verticesLow);
|
|
1212
|
+
} else {
|
|
1213
|
+
h.gl.deleteBuffer(this.vertexPositionBufferHigh);
|
|
1214
|
+
h.gl.deleteBuffer(this.vertexPositionBufferLow);
|
|
1215
|
+
|
|
1216
|
+
this.vertexTextureCoordBuffer =
|
|
1217
|
+
this.planet._textureCoordsBufferCache[Math.log2(gridSize)];
|
|
1218
|
+
|
|
1219
|
+
//this.vertexPositionBufferHigh = h.createStreamArrayBuffer(3, gsgs);
|
|
1220
|
+
//h.setStreamArrayBuffer(this.vertexPositionBufferHigh, verticesHigh);
|
|
1221
|
+
//this.vertexPositionBufferLow = h.createStreamArrayBuffer(3, gsgs);
|
|
1222
|
+
//h.setStreamArrayBuffer(this.vertexPositionBufferLow, verticesLow);
|
|
1223
|
+
|
|
1224
|
+
// It works, but I'm not sure that it is correct and better use the comment above
|
|
1225
|
+
this.vertexPositionBufferHigh = h.createArrayBuffer(verticesHigh, 3, gsgs);
|
|
1226
|
+
this.vertexPositionBufferLow = h.createArrayBuffer(verticesLow, 3, gsgs);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
_addViewExtent() {
|
|
1231
|
+
var ext = this._extentLonLat;
|
|
1232
|
+
|
|
1233
|
+
if (!this.planet._viewExtent) {
|
|
1234
|
+
this.planet._viewExtent = new Extent(
|
|
1235
|
+
new LonLat(ext.southWest.lon, ext.southWest.lat),
|
|
1236
|
+
new LonLat(ext.northEast.lon, ext.northEast.lat)
|
|
1237
|
+
);
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
var viewExt = this.planet._viewExtent;
|
|
1242
|
+
|
|
1243
|
+
if (ext.southWest.lon < viewExt.southWest.lon) {
|
|
1244
|
+
viewExt.southWest.lon = ext.southWest.lon;
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
if (ext.northEast.lon > viewExt.northEast.lon) {
|
|
1248
|
+
viewExt.northEast.lon = ext.northEast.lon;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
if (ext.southWest.lat < viewExt.southWest.lat) {
|
|
1252
|
+
viewExt.southWest.lat = ext.southWest.lat;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
if (ext.northEast.lat > viewExt.northEast.lat) {
|
|
1256
|
+
viewExt.northEast.lat = ext.northEast.lat;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
_assignTileIndexes() {
|
|
1261
|
+
this._tileGroup = 0;
|
|
1262
|
+
var tileZoom = this.tileZoom;
|
|
1263
|
+
var extent = this._extent;
|
|
1264
|
+
var pole = mercator.POLE;
|
|
1265
|
+
this.tileX = Math.round(
|
|
1266
|
+
Math.abs(-pole - extent.southWest.lon) / (extent.northEast.lon - extent.southWest.lon)
|
|
1267
|
+
);
|
|
1268
|
+
this.tileY = Math.round(
|
|
1269
|
+
Math.abs(pole - extent.northEast.lat) / (extent.northEast.lat - extent.southWest.lat)
|
|
1270
|
+
);
|
|
1271
|
+
var p2 = Math.pow(2, tileZoom);
|
|
1272
|
+
this.tileXE = (this.tileX + 1) % p2;
|
|
1273
|
+
this.tileXW = (p2 + this.tileX - 1) % p2;
|
|
1274
|
+
|
|
1275
|
+
this.tileYN = this.tileY - 1;
|
|
1276
|
+
this.tileYS = this.tileY + 1;
|
|
1277
|
+
|
|
1278
|
+
this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
|
|
1279
|
+
this.planet._quadTreeNodesCacheMerc[this.tileIndex] = this.node;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
initialize() {
|
|
1283
|
+
var p = this.planet;
|
|
1284
|
+
var n = this.node;
|
|
1285
|
+
|
|
1286
|
+
n.sideSize[0] =
|
|
1287
|
+
n.sideSize[1] =
|
|
1288
|
+
n.sideSize[2] =
|
|
1289
|
+
n.sideSize[3] =
|
|
1290
|
+
this.gridSize =
|
|
1291
|
+
p.terrain.gridSizeByZoom[this.tileZoom] || p.terrain.plainGridSize;
|
|
1292
|
+
|
|
1293
|
+
n.sideSizeLog2[0] =
|
|
1294
|
+
n.sideSizeLog2[1] =
|
|
1295
|
+
n.sideSizeLog2[2] =
|
|
1296
|
+
n.sideSizeLog2[3] =
|
|
1297
|
+
Math.log2(p.terrain.gridSizeByZoom[this.tileZoom] || p.terrain.plainGridSize);
|
|
1298
|
+
|
|
1299
|
+
if (this.tileZoom <= p.terrain.maxZoom) {
|
|
1300
|
+
var nmc = this.planet._normalMapCreator;
|
|
1301
|
+
this.normalMapTexturePtr = p.renderer.handler.createEmptyTexture_l(
|
|
1302
|
+
nmc._width,
|
|
1303
|
+
nmc._height
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
this.normalMapTexture = this.planet.transparentTexture;
|
|
1308
|
+
|
|
1309
|
+
this._assignGlobalTextureCoordinates();
|
|
1310
|
+
|
|
1311
|
+
this.initialized = true;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
_assignGlobalTextureCoordinates() {
|
|
1315
|
+
var e = this._extent;
|
|
1316
|
+
this._globalTextureCoordinates[0] =
|
|
1317
|
+
(e.southWest.lon + mercator.POLE) * mercator.ONE_BY_POLE_DOUBLE;
|
|
1318
|
+
this._globalTextureCoordinates[1] =
|
|
1319
|
+
(mercator.POLE - e.northEast.lat) * mercator.ONE_BY_POLE_DOUBLE;
|
|
1320
|
+
this._globalTextureCoordinates[2] =
|
|
1321
|
+
(e.northEast.lon + mercator.POLE) * mercator.ONE_BY_POLE_DOUBLE;
|
|
1322
|
+
this._globalTextureCoordinates[3] =
|
|
1323
|
+
(mercator.POLE - e.southWest.lat) * mercator.ONE_BY_POLE_DOUBLE;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
createPlainSegmentAsync() {
|
|
1327
|
+
let p = this.planet,
|
|
1328
|
+
t = p.terrain;
|
|
1329
|
+
|
|
1330
|
+
if (t.isReady() && this.tileZoom <= t.maxZoom && !this.plainReady) {
|
|
1331
|
+
this.plainProcessing = true;
|
|
1332
|
+
p._plainSegmentWorker.make(this);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
createPlainSegment() {
|
|
1337
|
+
this.initialize();
|
|
1338
|
+
this._createPlainVertices();
|
|
1339
|
+
this.readyToEngage = true;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
_createPlainVertices() {
|
|
1343
|
+
var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
|
|
1344
|
+
|
|
1345
|
+
var e = this._extent,
|
|
1346
|
+
fgs = this.planet.terrain.plainGridSize;
|
|
1347
|
+
var lonSize = e.getWidth();
|
|
1348
|
+
var llStep = lonSize / Math.max(fgs, gridSize);
|
|
1349
|
+
var esw_lon = e.southWest.lon,
|
|
1350
|
+
ene_lat = e.northEast.lat;
|
|
1351
|
+
var dg = Math.max(fgs / gridSize, 1),
|
|
1352
|
+
gs = Math.max(fgs, gridSize) + 1;
|
|
1353
|
+
var r2 = this.planet.ellipsoid._invRadii2;
|
|
1354
|
+
var ind = 0,
|
|
1355
|
+
nmInd = 0;
|
|
1356
|
+
const gsgs = gs * gs;
|
|
1357
|
+
|
|
1358
|
+
var gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
|
|
1359
|
+
|
|
1360
|
+
this.plainNormals = new Float32Array(gridSize3);
|
|
1361
|
+
this.plainVertices = new Float64Array(gridSize3);
|
|
1362
|
+
this.plainVerticesHigh = new Float32Array(gridSize3);
|
|
1363
|
+
this.plainVerticesLow = new Float32Array(gridSize3);
|
|
1364
|
+
|
|
1365
|
+
this.normalMapNormals = new Float32Array(gsgs * 3);
|
|
1366
|
+
this.normalMapVertices = new Float64Array(gsgs * 3);
|
|
1367
|
+
this.normalMapVerticesHigh = new Float32Array(gsgs * 3);
|
|
1368
|
+
this.normalMapVerticesLow = new Float32Array(gsgs * 3);
|
|
1369
|
+
|
|
1370
|
+
var verts = this.plainVertices,
|
|
1371
|
+
vertsHigh = this.plainVerticesHigh,
|
|
1372
|
+
vertsLow = this.plainVerticesLow,
|
|
1373
|
+
norms = this.plainNormals,
|
|
1374
|
+
nmVerts = this.normalMapVertices,
|
|
1375
|
+
nmVertsHigh = this.normalMapVerticesHigh,
|
|
1376
|
+
nmVertsLow = this.normalMapVerticesLow,
|
|
1377
|
+
nmNorms = this.normalMapNormals;
|
|
1378
|
+
|
|
1379
|
+
for (var k = 0; k < gsgs; k++) {
|
|
1380
|
+
var j = k % gs,
|
|
1381
|
+
i = ~~(k / gs);
|
|
1382
|
+
|
|
1383
|
+
var v = this.planet.ellipsoid.lonLatToCartesian(
|
|
1384
|
+
LonLat.inverseMercator(esw_lon + j * llStep, ene_lat - i * llStep)
|
|
1385
|
+
);
|
|
1386
|
+
var nx = v.x * r2.x,
|
|
1387
|
+
ny = v.y * r2.y,
|
|
1388
|
+
nz = v.z * r2.z;
|
|
1389
|
+
var l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
1390
|
+
var nxl = nx * l,
|
|
1391
|
+
nyl = ny * l,
|
|
1392
|
+
nzl = nz * l;
|
|
1393
|
+
|
|
1394
|
+
Vec3.doubleToTwoFloats(v, _tempHigh, _tempLow);
|
|
1395
|
+
|
|
1396
|
+
nmVerts[nmInd] = v.x;
|
|
1397
|
+
nmVertsHigh[nmInd] = _tempHigh.x;
|
|
1398
|
+
nmVertsLow[nmInd] = _tempLow.x;
|
|
1399
|
+
nmNorms[nmInd++] = nxl;
|
|
1400
|
+
|
|
1401
|
+
nmVerts[nmInd] = v.y;
|
|
1402
|
+
nmVertsHigh[nmInd] = _tempHigh.y;
|
|
1403
|
+
nmVertsLow[nmInd] = _tempLow.y;
|
|
1404
|
+
nmNorms[nmInd++] = nyl;
|
|
1405
|
+
|
|
1406
|
+
nmVerts[nmInd] = v.z;
|
|
1407
|
+
nmVertsHigh[nmInd] = _tempHigh.z;
|
|
1408
|
+
nmVertsLow[nmInd] = _tempLow.z;
|
|
1409
|
+
nmNorms[nmInd++] = nzl;
|
|
1410
|
+
|
|
1411
|
+
if (i % dg === 0 && j % dg === 0) {
|
|
1412
|
+
verts[ind] = v.x;
|
|
1413
|
+
vertsHigh[ind] = _tempHigh.x;
|
|
1414
|
+
vertsLow[ind] = _tempLow.x;
|
|
1415
|
+
norms[ind++] = nxl;
|
|
1416
|
+
|
|
1417
|
+
verts[ind] = v.y;
|
|
1418
|
+
vertsHigh[ind] = _tempHigh.y;
|
|
1419
|
+
vertsLow[ind] = _tempLow.y;
|
|
1420
|
+
norms[ind++] = nyl;
|
|
1421
|
+
|
|
1422
|
+
verts[ind] = v.z;
|
|
1423
|
+
vertsHigh[ind] = _tempHigh.z;
|
|
1424
|
+
vertsLow[ind] = _tempLow.z;
|
|
1425
|
+
norms[ind++] = nzl;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
this.terrainVertices = verts;
|
|
1430
|
+
this.terrainVerticesHigh = vertsHigh;
|
|
1431
|
+
this.terrainVerticesLow = vertsLow;
|
|
1432
|
+
|
|
1433
|
+
this.plainReady = true;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Gets specific layer material.
|
|
1438
|
+
* @public
|
|
1439
|
+
* @param {Layer} layer - Layer object.
|
|
1440
|
+
* @returns {planetSegment.Material} - Segment material.
|
|
1441
|
+
*/
|
|
1442
|
+
getMaterialByLayer(layer) {
|
|
1443
|
+
return this.materials[layer._id];
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
_getLayerExtentOffset(layer) {
|
|
1447
|
+
var v0s = layer._extentMerc;
|
|
1448
|
+
var v0t = this._extent;
|
|
1449
|
+
var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
|
|
1450
|
+
var sSize_y = v0s.northEast.lat - v0s.southWest.lat;
|
|
1451
|
+
var dV0s_x = (v0t.southWest.lon - v0s.southWest.lon) / sSize_x;
|
|
1452
|
+
var dV0s_y = (v0s.northEast.lat - v0t.northEast.lat) / sSize_y;
|
|
1453
|
+
var dSize_x = (v0t.northEast.lon - v0t.southWest.lon) / sSize_x;
|
|
1454
|
+
var dSize_y = (v0t.northEast.lat - v0t.southWest.lat) / sSize_y;
|
|
1455
|
+
return [dV0s_x, dV0s_y, dSize_x, dSize_y];
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
screenRendering(sh, layerSlice, sliceIndex, defaultTexture, isOverlay) {
|
|
1459
|
+
var gl = this.handler.gl;
|
|
1460
|
+
var sha = sh.attributes,
|
|
1461
|
+
shu = sh.uniforms;
|
|
1462
|
+
|
|
1463
|
+
var pm = this.materials,
|
|
1464
|
+
p = this.planet;
|
|
1465
|
+
|
|
1466
|
+
var currHeight, li;
|
|
1467
|
+
if (layerSlice) {
|
|
1468
|
+
li = layerSlice[0];
|
|
1469
|
+
currHeight = li._height;
|
|
1470
|
+
} else {
|
|
1471
|
+
currHeight = 0;
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// First always draw whole planet base layer segment with solid texture.
|
|
1475
|
+
gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE + 2);
|
|
1476
|
+
gl.bindTexture(gl.TEXTURE_2D, defaultTexture || this.getDefaultTexture());
|
|
1477
|
+
gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE + 2);
|
|
1478
|
+
|
|
1479
|
+
var n = 0,
|
|
1480
|
+
i = 0;
|
|
1481
|
+
|
|
1482
|
+
var notEmpty = false;
|
|
1483
|
+
|
|
1484
|
+
var slice = this._renderingSlices[sliceIndex];
|
|
1485
|
+
|
|
1486
|
+
if (!slice) {
|
|
1487
|
+
slice = this._renderingSlices[sliceIndex] = new _RenderingSlice(p);
|
|
1488
|
+
} else {
|
|
1489
|
+
slice.layers = [];
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
this._indexBuffer = this._getIndexBuffer();
|
|
1493
|
+
|
|
1494
|
+
while (li) {
|
|
1495
|
+
if (
|
|
1496
|
+
this.layerOverlap(li) &&
|
|
1497
|
+
((li._fading && li._fadingOpacity > 0.0) ||
|
|
1498
|
+
((li.minZoom >= p.minCurrZoom || li.maxZoom >= p.minCurrZoom) &&
|
|
1499
|
+
(li.minZoom <= p.maxCurrZoom || li.maxZoom <= p.maxCurrZoom)))
|
|
1500
|
+
) {
|
|
1501
|
+
notEmpty = true;
|
|
1502
|
+
var m = pm[li._id];
|
|
1503
|
+
if (!m) {
|
|
1504
|
+
m = pm[li._id] = li.createMaterial(this);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
if (!m.isReady) {
|
|
1508
|
+
this.planet._renderCompleted = false;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
slice.layers.push(li);
|
|
1512
|
+
|
|
1513
|
+
var n4 = n * 4;
|
|
1514
|
+
|
|
1515
|
+
var arr = li.applyMaterial(m);
|
|
1516
|
+
slice.tileOffsetArr[n4] = arr[0];
|
|
1517
|
+
slice.tileOffsetArr[n4 + 1] = arr[1];
|
|
1518
|
+
slice.tileOffsetArr[n4 + 2] = arr[2];
|
|
1519
|
+
slice.tileOffsetArr[n4 + 3] = arr[3];
|
|
1520
|
+
|
|
1521
|
+
arr = this._getLayerExtentOffset(li);
|
|
1522
|
+
slice.visibleExtentOffsetArr[n4] = arr[0];
|
|
1523
|
+
slice.visibleExtentOffsetArr[n4 + 1] = arr[1];
|
|
1524
|
+
slice.visibleExtentOffsetArr[n4 + 2] = arr[2];
|
|
1525
|
+
slice.visibleExtentOffsetArr[n4 + 3] = arr[3];
|
|
1526
|
+
|
|
1527
|
+
slice.layerOpacityArr[n] = li.opacity;
|
|
1528
|
+
|
|
1529
|
+
p._samplerArr[n] = n;
|
|
1530
|
+
|
|
1531
|
+
gl.activeTexture(gl.TEXTURE0 + n);
|
|
1532
|
+
gl.bindTexture(gl.TEXTURE_2D, m.texture || p.transparentTexture);
|
|
1533
|
+
|
|
1534
|
+
n++;
|
|
1535
|
+
}
|
|
1536
|
+
i++;
|
|
1537
|
+
li = layerSlice[i];
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
if (notEmpty || !isOverlay) {
|
|
1541
|
+
gl.uniform1i(shu.samplerCount, n);
|
|
1542
|
+
gl.uniform1f(shu.height, currHeight);
|
|
1543
|
+
gl.uniform1iv(shu.samplerArr, p._samplerArr);
|
|
1544
|
+
gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
|
|
1545
|
+
gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
|
|
1546
|
+
gl.uniform1fv(shu.layerOpacityArr, slice.layerOpacityArr);
|
|
1547
|
+
|
|
1548
|
+
// bind normalmap texture
|
|
1549
|
+
if (p.lightEnabled) {
|
|
1550
|
+
gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE + 3);
|
|
1551
|
+
gl.bindTexture(gl.TEXTURE_2D, this.normalMapTexture || p.transparentTexture);
|
|
1552
|
+
gl.uniform1i(shu.uNormalMap, p.SLICE_SIZE + 3);
|
|
1553
|
+
|
|
1554
|
+
gl.uniform3fv(shu.uNormalMapBias, this.normalMapTextureBias);
|
|
1555
|
+
|
|
1556
|
+
// bind segment specular and night material texture coordinates
|
|
1557
|
+
gl.uniform4fv(shu.uGlobalTextureCoord, this._globalTextureCoordinates);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
|
|
1561
|
+
gl.vertexAttribPointer(
|
|
1562
|
+
sha.aVertexPositionHigh,
|
|
1563
|
+
this.vertexPositionBufferHigh.itemSize,
|
|
1564
|
+
gl.FLOAT,
|
|
1565
|
+
false,
|
|
1566
|
+
0,
|
|
1567
|
+
0
|
|
1568
|
+
);
|
|
1569
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
|
|
1570
|
+
gl.vertexAttribPointer(
|
|
1571
|
+
sha.aVertexPositionLow,
|
|
1572
|
+
this.vertexPositionBufferLow.itemSize,
|
|
1573
|
+
gl.FLOAT,
|
|
1574
|
+
false,
|
|
1575
|
+
0,
|
|
1576
|
+
0
|
|
1577
|
+
);
|
|
1578
|
+
|
|
1579
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
|
|
1580
|
+
gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
|
|
1581
|
+
|
|
1582
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
|
1583
|
+
gl.drawElements(p.drawMode, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
heightPickingRendering(sh, layerSlice, sliceIndex, defaultTexture, isOverlay) {
|
|
1588
|
+
var gl = this.handler.gl;
|
|
1589
|
+
var sha = sh.attributes,
|
|
1590
|
+
shu = sh.uniforms;
|
|
1591
|
+
|
|
1592
|
+
var pm = this.materials,
|
|
1593
|
+
p = this.planet;
|
|
1594
|
+
|
|
1595
|
+
// First always draw whole planet base layer segment with solid texture.
|
|
1596
|
+
gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE);
|
|
1597
|
+
gl.bindTexture(gl.TEXTURE_2D, defaultTexture || p.solidTextureOne);
|
|
1598
|
+
gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE);
|
|
1599
|
+
|
|
1600
|
+
var currHeight;
|
|
1601
|
+
if (layerSlice) {
|
|
1602
|
+
currHeight = layerSlice[0]._height;
|
|
1603
|
+
} else {
|
|
1604
|
+
currHeight = 0;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
var n = 0;
|
|
1608
|
+
|
|
1609
|
+
var slice = this._renderingSlices[sliceIndex];
|
|
1610
|
+
|
|
1611
|
+
var notEmpty = false;
|
|
1612
|
+
|
|
1613
|
+
for (n = 0; n < slice.layers.length; n++) {
|
|
1614
|
+
notEmpty = true;
|
|
1615
|
+
p._samplerArr[n] = n;
|
|
1616
|
+
gl.activeTexture(gl.TEXTURE0 + n);
|
|
1617
|
+
gl.bindTexture(gl.TEXTURE_2D, pm[slice.layers[n]._id].texture || p.transparentTexture);
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
if (notEmpty || !isOverlay) {
|
|
1621
|
+
gl.uniform1i(shu.samplerCount, n);
|
|
1622
|
+
gl.uniform1f(shu.height, currHeight);
|
|
1623
|
+
gl.uniform1iv(shu.samplerArr, p._samplerArr);
|
|
1624
|
+
gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
|
|
1625
|
+
gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
|
|
1626
|
+
gl.uniform1fv(shu.layerOpacityArr, slice.layerOpacityArr);
|
|
1627
|
+
|
|
1628
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
|
|
1629
|
+
gl.vertexAttribPointer(
|
|
1630
|
+
sha.aVertexPositionHigh,
|
|
1631
|
+
this.vertexPositionBufferHigh.itemSize,
|
|
1632
|
+
gl.FLOAT,
|
|
1633
|
+
false,
|
|
1634
|
+
0,
|
|
1635
|
+
0
|
|
1636
|
+
);
|
|
1637
|
+
|
|
1638
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
|
|
1639
|
+
gl.vertexAttribPointer(
|
|
1640
|
+
sha.aVertexPositionLow,
|
|
1641
|
+
this.vertexPositionBufferLow.itemSize,
|
|
1642
|
+
gl.FLOAT,
|
|
1643
|
+
false,
|
|
1644
|
+
0,
|
|
1645
|
+
0
|
|
1646
|
+
);
|
|
1647
|
+
|
|
1648
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
|
|
1649
|
+
gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
|
|
1650
|
+
|
|
1651
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
|
1652
|
+
gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
colorPickingRendering(sh, layerSlice, sliceIndex, defaultTexture, isOverlay) {
|
|
1657
|
+
var gl = this.handler.gl;
|
|
1658
|
+
var sha = sh.attributes,
|
|
1659
|
+
shu = sh.uniforms;
|
|
1660
|
+
|
|
1661
|
+
var pm = this.materials,
|
|
1662
|
+
p = this.planet;
|
|
1663
|
+
|
|
1664
|
+
var currHeight;
|
|
1665
|
+
if (layerSlice) {
|
|
1666
|
+
currHeight = layerSlice[0]._height;
|
|
1667
|
+
} else {
|
|
1668
|
+
currHeight = 0;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
var notEmpty = false;
|
|
1672
|
+
|
|
1673
|
+
var slice = this._renderingSlices[sliceIndex];
|
|
1674
|
+
|
|
1675
|
+
for (var n = 0; n < slice.layers.length; n++) {
|
|
1676
|
+
notEmpty = true;
|
|
1677
|
+
|
|
1678
|
+
var li = slice.layers[n];
|
|
1679
|
+
var n4 = n * 4;
|
|
1680
|
+
|
|
1681
|
+
p._pickingColorArr[n4] = li._pickingColor.x / 255.0;
|
|
1682
|
+
p._pickingColorArr[n4 + 1] = li._pickingColor.y / 255.0;
|
|
1683
|
+
p._pickingColorArr[n4 + 2] = li._pickingColor.z / 255.0;
|
|
1684
|
+
p._pickingColorArr[n4 + 3] = li._pickingEnabled;
|
|
1685
|
+
|
|
1686
|
+
p._samplerArr[n] = n;
|
|
1687
|
+
gl.activeTexture(gl.TEXTURE0 + n);
|
|
1688
|
+
gl.bindTexture(gl.TEXTURE_2D, pm[li._id].texture || this.planet.transparentTexture);
|
|
1689
|
+
|
|
1690
|
+
p._pickingMaskArr[n] = n + p.SLICE_SIZE;
|
|
1691
|
+
gl.activeTexture(gl.TEXTURE0 + n + p.SLICE_SIZE);
|
|
1692
|
+
gl.bindTexture(gl.TEXTURE_2D, pm[li._id].pickingMask || this.planet.transparentTexture);
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
if (notEmpty || !isOverlay) {
|
|
1696
|
+
gl.uniform1i(shu.samplerCount, n);
|
|
1697
|
+
gl.uniform1f(shu.height, currHeight);
|
|
1698
|
+
gl.uniform1iv(shu.samplerArr, p._samplerArr);
|
|
1699
|
+
gl.uniform1iv(shu.pickingMaskArr, p._pickingMaskArr);
|
|
1700
|
+
gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
|
|
1701
|
+
gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
|
|
1702
|
+
gl.uniform1fv(shu.layerOpacityArr, slice.layerOpacityArr);
|
|
1703
|
+
gl.uniform4fv(shu.pickingColorArr, p._pickingColorArr);
|
|
1704
|
+
|
|
1705
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
|
|
1706
|
+
gl.vertexAttribPointer(
|
|
1707
|
+
sha.aVertexPositionHigh,
|
|
1708
|
+
this.vertexPositionBufferHigh.itemSize,
|
|
1709
|
+
gl.FLOAT,
|
|
1710
|
+
false,
|
|
1711
|
+
0,
|
|
1712
|
+
0
|
|
1713
|
+
);
|
|
1714
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
|
|
1715
|
+
gl.vertexAttribPointer(
|
|
1716
|
+
sha.aVertexPositionLow,
|
|
1717
|
+
this.vertexPositionBufferLow.itemSize,
|
|
1718
|
+
gl.FLOAT,
|
|
1719
|
+
false,
|
|
1720
|
+
0,
|
|
1721
|
+
0
|
|
1722
|
+
);
|
|
1723
|
+
|
|
1724
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
|
|
1725
|
+
gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
|
|
1726
|
+
|
|
1727
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
|
1728
|
+
gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
depthRendering(sh, layerSlice, sliceIndex, defaultTexture, isOverlay) {
|
|
1733
|
+
var gl = this.handler.gl;
|
|
1734
|
+
var sha = sh.attributes,
|
|
1735
|
+
shu = sh.uniforms;
|
|
1736
|
+
|
|
1737
|
+
var pm = this.materials,
|
|
1738
|
+
p = this.planet;
|
|
1739
|
+
|
|
1740
|
+
// First always draw whole planet base layer segment with solid texture.
|
|
1741
|
+
gl.activeTexture(gl.TEXTURE0 + p.SLICE_SIZE);
|
|
1742
|
+
gl.bindTexture(gl.TEXTURE_2D, defaultTexture || p.solidTextureOne);
|
|
1743
|
+
gl.uniform1i(shu.defaultTexture, p.SLICE_SIZE);
|
|
1744
|
+
|
|
1745
|
+
var currHeight;
|
|
1746
|
+
if (layerSlice) {
|
|
1747
|
+
currHeight = layerSlice[0]._height;
|
|
1748
|
+
} else {
|
|
1749
|
+
currHeight = 0;
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
var n = 0;
|
|
1753
|
+
|
|
1754
|
+
var slice = this._renderingSlices[sliceIndex];
|
|
1755
|
+
|
|
1756
|
+
var notEmpty = false;
|
|
1757
|
+
|
|
1758
|
+
for (n = 0; n < slice.layers.length; n++) {
|
|
1759
|
+
notEmpty = true;
|
|
1760
|
+
p._samplerArr[n] = n;
|
|
1761
|
+
gl.activeTexture(gl.TEXTURE0 + n);
|
|
1762
|
+
gl.bindTexture(gl.TEXTURE_2D, pm[slice.layers[n]._id].texture || p.transparentTexture);
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
if (notEmpty || !isOverlay) {
|
|
1766
|
+
gl.uniform1i(shu.samplerCount, n);
|
|
1767
|
+
gl.uniform1f(shu.height, currHeight);
|
|
1768
|
+
gl.uniform1iv(shu.samplerArr, p._samplerArr);
|
|
1769
|
+
gl.uniform4fv(shu.tileOffsetArr, slice.tileOffsetArr);
|
|
1770
|
+
gl.uniform4fv(shu.visibleExtentOffsetArr, slice.visibleExtentOffsetArr);
|
|
1771
|
+
gl.uniform1fv(shu.layerOpacityArr, slice.layerOpacityArr);
|
|
1772
|
+
|
|
1773
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferHigh);
|
|
1774
|
+
gl.vertexAttribPointer(
|
|
1775
|
+
sha.aVertexPositionHigh,
|
|
1776
|
+
this.vertexPositionBufferHigh.itemSize,
|
|
1777
|
+
gl.FLOAT,
|
|
1778
|
+
false,
|
|
1779
|
+
0,
|
|
1780
|
+
0
|
|
1781
|
+
);
|
|
1782
|
+
|
|
1783
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexPositionBufferLow);
|
|
1784
|
+
gl.vertexAttribPointer(
|
|
1785
|
+
sha.aVertexPositionLow,
|
|
1786
|
+
this.vertexPositionBufferLow.itemSize,
|
|
1787
|
+
gl.FLOAT,
|
|
1788
|
+
false,
|
|
1789
|
+
0,
|
|
1790
|
+
0
|
|
1791
|
+
);
|
|
1792
|
+
|
|
1793
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer);
|
|
1794
|
+
gl.vertexAttribPointer(sha.aTextureCoord, 2, gl.UNSIGNED_SHORT, true, 0, 0);
|
|
1795
|
+
|
|
1796
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
|
1797
|
+
gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
_getIndexBuffer() {
|
|
1802
|
+
var s = this.node.sideSizeLog2;
|
|
1803
|
+
var cache = this.planet._indexesCache[Math.log2(this.gridSize)][s[0]][s[1]][s[2]][s[3]];
|
|
1804
|
+
if (!cache.buffer) {
|
|
1805
|
+
let indexes = segmentHelper
|
|
1806
|
+
.getInstance()
|
|
1807
|
+
.createSegmentIndexes(Math.log2(this.gridSize), [s[0], s[1], s[2], s[3]]);
|
|
1808
|
+
cache.buffer = this.planet.renderer.handler.createElementArrayBuffer(indexes, 1);
|
|
1809
|
+
this.planet._indexesCacheToRemoveCounter++;
|
|
1810
|
+
indexes = null;
|
|
1811
|
+
}
|
|
1812
|
+
return cache.buffer;
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
_collectVisibleNodes() {
|
|
1816
|
+
this.planet._visibleNodes[this.node.nodeId] = this.node;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
layerOverlap(layer) {
|
|
1820
|
+
return this._extent.overlaps(layer._extentMerc);
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
getDefaultTexture() {
|
|
1824
|
+
return this.planet.solidTextureOne;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
getExtentLonLat() {
|
|
1828
|
+
return this._extentLonLat;
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
getExtentMerc() {
|
|
1832
|
+
return this._extent;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
getExtent() {
|
|
1836
|
+
return this._extent;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
getNodeState() {
|
|
1840
|
+
var vn = this.planet._visibleNodes[this.node.nodeId];
|
|
1841
|
+
return (vn && vn.state) || NOTRENDERING;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
getNeighborSide(b) {
|
|
1845
|
+
if (this.tileY === b.tileY) {
|
|
1846
|
+
if (this.tileX === b.tileXE) {
|
|
1847
|
+
return W;
|
|
1848
|
+
} else if (this.tileX === b.tileXW) {
|
|
1849
|
+
return E;
|
|
1850
|
+
}
|
|
1851
|
+
} else if (this.tileX === b.tileX) {
|
|
1852
|
+
if (this.tileY === b.tileYS) {
|
|
1853
|
+
return N;
|
|
1854
|
+
} else if (this.tileY === b.tileYN) {
|
|
1855
|
+
return S;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
return -1;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
export { Segment };
|