@openglobus/og 0.11.8 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,6 @@ import { Vec3 } from "../math/Vec3.js";
7
7
  import { MAX_LAT } from "../mercator.js";
8
8
  import { EPSG3857 } from "../proj/EPSG3857.js";
9
9
  import { EPSG4326 } from "../proj/EPSG4326.js";
10
- import { MAX_NORMAL_ZOOM } from "../segment/Segment.js";
11
10
  import { getMatrixSubArray, getMatrixSubArrayBoundsExt } from "../utils/shared.js";
12
11
  import {
13
12
  COMSIDE,
@@ -30,8 +29,6 @@ import {
30
29
  WALKTHROUGH
31
30
  } from "./quadTree.js";
32
31
 
33
- const VISIBLE_HEIGHT = 1400000.0;
34
-
35
32
  let _tempHigh = new Vec3(),
36
33
  _tempLow = new Vec3();
37
34
 
@@ -67,6 +64,7 @@ class Node {
67
64
 
68
65
  constructor(SegmentPrototype, planet, partId, parent, id, tileZoom, extent) {
69
66
  this.SegmentPrototype = SegmentPrototype;
67
+ planet._createdNodesCount++;
70
68
  this.planet = planet;
71
69
  this.parentNode = parent;
72
70
  this.partId = partId;
@@ -84,7 +82,6 @@ class Node {
84
82
  this._cameraInside = false;
85
83
  this.inFrustum = 0;
86
84
  this.createBounds();
87
- this.planet._createdNodesCount++;
88
85
  }
89
86
 
90
87
  createChildrenNodes() {
@@ -102,45 +99,10 @@ class Node {
102
99
  var c = new LonLat(sw.lon + size_x, sw.lat + size_y);
103
100
  var nd = this.nodes;
104
101
 
105
- nd[NW] = new Node(
106
- this.SegmentPrototype,
107
- p,
108
- NW,
109
- this,
110
- id,
111
- z,
112
- new Extent(new LonLat(sw.lon, sw.lat + size_y), new LonLat(sw.lon + size_x, ne.lat))
113
- );
114
-
115
- nd[NE] = new Node(
116
- this.SegmentPrototype,
117
- p,
118
- NE,
119
- this,
120
- id,
121
- z,
122
- new Extent(c, new LonLat(ne.lon, ne.lat))
123
- );
124
-
125
- nd[SW] = new Node(
126
- this.SegmentPrototype,
127
- p,
128
- SW,
129
- this,
130
- id,
131
- z,
132
- new Extent(new LonLat(sw.lon, sw.lat), c)
133
- );
134
-
135
- nd[SE] = new Node(
136
- this.SegmentPrototype,
137
- p,
138
- SE,
139
- this,
140
- id,
141
- z,
142
- new Extent(new LonLat(sw.lon + size_x, sw.lat), new LonLat(ne.lon, sw.lat + size_y))
143
- );
102
+ nd[NW] = new Node(this.SegmentPrototype, p, NW, this, id, z, new Extent(new LonLat(sw.lon, sw.lat + size_y), new LonLat(sw.lon + size_x, ne.lat)));
103
+ nd[NE] = new Node(this.SegmentPrototype, p, NE, this, id, z, new Extent(c, new LonLat(ne.lon, ne.lat)));
104
+ nd[SW] = new Node(this.SegmentPrototype, p, SW, this, id, z, new Extent(new LonLat(sw.lon, sw.lat), c));
105
+ nd[SE] = new Node(this.SegmentPrototype, p, SE, this, id, z, new Extent(new LonLat(sw.lon + size_x, sw.lat), new LonLat(ne.lon, sw.lat + size_y)));
144
106
  }
145
107
 
146
108
  createBounds() {
@@ -153,6 +115,15 @@ class Node {
153
115
  } else {
154
116
  seg.createBoundsByParent();
155
117
  }
118
+
119
+ let x = seg.bsphere.center.x,
120
+ y = seg.bsphere.center.y,
121
+ z = seg.bsphere.center.z;
122
+
123
+ let length = 1.0 / Math.sqrt(x * x + y * y + z * z);
124
+ seg.centerNormal.x = x * length;
125
+ seg.centerNormal.y = y * length;
126
+ seg.centerNormal.z = z * length;
156
127
  }
157
128
 
158
129
  getState() {
@@ -204,15 +175,10 @@ class Node {
204
175
  }
205
176
 
206
177
  renderTree(cam, maxZoom, terrainReadySegment, stopLoading) {
207
- if (
208
- this.planet._renderedNodes.length >= MAX_RENDERED_NODES ||
209
- this.planet._nodeCounterError_ > 2000
210
- ) {
178
+ if (this.planet._renderedNodes.length >= MAX_RENDERED_NODES) {
211
179
  return;
212
180
  }
213
181
 
214
- this.planet._nodeCounterError_++;
215
-
216
182
  this.state = WALKTHROUGH;
217
183
 
218
184
  this.neighbors[0] = null;
@@ -282,27 +248,49 @@ class Node {
282
248
  if (this.inFrustum || this._cameraInside || seg.tileZoom < 3) {
283
249
  let h = cam._lonLat.height;
284
250
 
285
- let altVis =
286
- cam.eye.distance(seg.bsphere.center) - seg.bsphere.radius <
287
- VISIBLE_DISTANCE * Math.sqrt(h) ||
251
+ let eye = cam.eye;
252
+ let horizonDist = eye.length2() - this.planet.ellipsoid._b2;
253
+
254
+ let altVis = seg.tileZoom > 19 ||
288
255
  (seg.tileZoom < 4 && !seg.terrainReady) ||
289
256
  seg.tileZoom < 2;
290
257
 
258
+ if (h > 21000) {
259
+ altVis = altVis || eye.distance2(seg._sw) < horizonDist
260
+ || eye.distance2(seg._nw) < horizonDist
261
+ || eye.distance2(seg._ne) < horizonDist
262
+ || eye.distance2(seg._se) < horizonDist;
263
+ } else {
264
+ altVis = altVis || cam.eye.distance(seg.bsphere.center) - seg.bsphere.radius < VISIBLE_DISTANCE * Math.sqrt(h);
265
+ }
266
+
291
267
  if ((this.inFrustum && (altVis || h > 10000.0)) || this._cameraInside) {
292
268
  seg._collectVisibleNodes();
293
269
  }
294
270
 
295
271
  if (seg.tileZoom < 2 && seg.normalMapReady) {
296
272
  this.traverseNodes(cam, maxZoom, terrainReadySegment, stopLoading);
297
- } else if ((!maxZoom && seg.acceptForRendering(cam)) || seg.tileZoom === maxZoom || !altVis && maxZoom) {
298
- this.prepareForRendering(cam, altVis, this.inFrustum, terrainReadySegment, stopLoading);
299
- } else if (seg.tileZoom < planet.terrain._maxNodeZoom && seg.terrainReady) {
300
- // Deleting terrainReady here, you have to remove
301
- // this.appliedTerrainNodeId !== pn.nodeId in whileTerrainLoading,
302
- // also have to fix createBoundsByParent(*)
273
+ } else if (seg.terrainReady && (
274
+ !maxZoom && cam.projectedSize(seg.bsphere.center, seg._plainRadius) < planet._lodSize ||
275
+ maxZoom && ((seg.tileZoom === maxZoom) || !altVis))) {
276
+
277
+ if (altVis) {
278
+ seg.loadTile = true;
279
+ this.renderNode(this.inFrustum, !this.inFrustum, terrainReadySegment, stopLoading);
280
+ } else {
281
+ this.state = NOTRENDERING;
282
+ }
283
+
284
+ } else if (
285
+ seg.terrainReady &&
286
+ seg.tileZoom < planet.terrain._maxNodeZoom &&
287
+ (!maxZoom || maxZoom && cam.projectedSize(seg.bsphere.center, seg.bsphere.radius) > this.planet._maxLodSize)) {
303
288
  this.traverseNodes(cam, maxZoom, seg, stopLoading);
289
+ } else if (altVis) {
290
+ seg.loadTile = false;
291
+ this.renderNode(this.inFrustum, !this.inFrustum, terrainReadySegment, stopLoading);
304
292
  } else {
305
- this.prepareForRendering(cam, altVis, this.inFrustum, terrainReadySegment, stopLoading);
293
+ this.state = NOTRENDERING;
306
294
  }
307
295
  } else {
308
296
  this.state = NOTRENDERING;
@@ -322,39 +310,6 @@ class Node {
322
310
  n[3].renderTree(cam, maxZoom, terrainReadySegment, stopLoading);
323
311
  }
324
312
 
325
- prepareForRendering(
326
- cam,
327
- altVis,
328
- inFrustum,
329
- terrainReadySegment,
330
- stopLoading
331
- ) {
332
- let seg = this.segment;
333
-
334
- if (cam._lonLat.height < VISIBLE_HEIGHT) {
335
- if (altVis) {
336
- this.renderNode(inFrustum, !inFrustum, terrainReadySegment, stopLoading);
337
- } else {
338
- this.state = NOTRENDERING;
339
- }
340
- } else {
341
- if (seg.tileZoom < 2) {
342
- this.renderNode(inFrustum, !inFrustum, terrainReadySegment, stopLoading);
343
- } else if (seg.tileZoom > MAX_NORMAL_ZOOM) {
344
- this.renderNode(inFrustum, !inFrustum, terrainReadySegment, stopLoading);
345
- } else if (
346
- seg._swNorm.dot(cam._n) > 0.0 ||
347
- seg._nwNorm.dot(cam._n) > 0.0 ||
348
- seg._neNorm.dot(cam._n) > 0.0 ||
349
- seg._seNorm.dot(cam._n) > 0.0
350
- ) {
351
- this.renderNode(inFrustum, !inFrustum, terrainReadySegment, stopLoading);
352
- } else {
353
- this.state = NOTRENDERING;
354
- }
355
- }
356
- }
357
-
358
313
  renderNode(inFrustum, onlyTerrain, terrainReadySegment, stopLoading) {
359
314
  var seg = this.segment;
360
315
 
@@ -376,7 +331,7 @@ class Node {
376
331
  }
377
332
 
378
333
  // Create normal map texture
379
- if (seg.planet.lightEnabled && !seg.normalMapReady && !seg.parentNormalMapReady) {
334
+ if (seg.planet.lightEnabled && !seg.normalMapReady /*&& !seg.parentNormalMapReady*/) {
380
335
  this.whileNormalMapCreating();
381
336
  }
382
337
 
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  export const VISIBLE_DISTANCE = 3570.0;
4
- export const MAX_RENDERED_NODES = 700;
4
+ export const MAX_RENDERED_NODES = 1000;
5
5
 
6
6
  export const NW = 0;
7
7
  export const NE = 1;
@@ -210,8 +210,6 @@ class Renderer {
210
210
 
211
211
  this._currentOutput = "screen";
212
212
 
213
- this.isActiveBackbuffers = true;
214
-
215
213
  this.labelWorker = new LabelWorker();
216
214
  }
217
215
 
@@ -481,8 +479,8 @@ class Renderer {
481
479
  }
482
480
 
483
481
  this.handler.onCanvasResize = () => {
482
+ this.resize();
484
483
  this.events.dispatch(this.events.resize, this.handler.canvas);
485
- this._resize();
486
484
  };
487
485
 
488
486
  this._screenFrameCornersBuffer = this.handler.createArrayBuffer(
@@ -509,7 +507,7 @@ class Renderer {
509
507
  }
510
508
  }
511
509
 
512
- _resize() {
510
+ resize() {
513
511
  let c = this.handler.canvas;
514
512
  this.activeCamera.setAspectRatio(c.width / c.height);
515
513
  this.sceneFramebuffer.setSize(c.width, c.height);
@@ -744,7 +742,7 @@ class Renderer {
744
742
 
745
743
  let frustums = this.activeCamera.frustums;
746
744
 
747
- let anyEvent = this.events.mouseState.anyEvent() && this.isActiveBackbuffers;
745
+ let anyEvent = this.events.mouseState.anyEvent();
748
746
 
749
747
  // Rendering scene nodes and entityCollections
750
748
  let rn = this._renderNodesArr;
@@ -32,14 +32,16 @@ import { wgs84 } from "../ellipsoid/wgs84.js";
32
32
  import { NIGHT, SPECULAR } from "../res/images.js";
33
33
  import { Geoid } from "../terrain/Geoid.js";
34
34
  import { isUndef } from "../utils/shared.js";
35
+ import { MAX_RENDERED_NODES } from "../quadTree/quadTree.js";
35
36
 
36
- const MAX_LOD = 1.0;
37
- const MIN_LOD = 0.75;
37
+ const CUR_LOD_SIZE = 250; //px
38
+ const MIN_LOD_SIZE = 312; //px
39
+ const MAX_LOD_SIZE = 190; //px
38
40
 
39
41
  let _tempPickingPix_ = new Uint8Array(4),
40
42
  _tempDepthColor_ = new Uint8Array(4);
41
43
 
42
- const DEPTH_DISTANCE = 11;
44
+ const DEPTH_DISTANCE = 11;//m
43
45
 
44
46
  /**
45
47
  * Maximum created nodes count. The more nodes count the more memory usage.
@@ -49,6 +51,8 @@ const DEPTH_DISTANCE = 11;
49
51
  */
50
52
  const MAX_NODES = 200;
51
53
 
54
+ const HORIZON_TANGENT = 0.81;
55
+
52
56
  const EVENT_NAMES = [
53
57
  /**
54
58
  * Triggered before globe frame begins to render.
@@ -108,6 +112,13 @@ export class Planet extends RenderNode {
108
112
  constructor(options = {}) {
109
113
  super(options.name);
110
114
 
115
+ this._cameraFrustums = options.frustums || [
116
+ [1, 100 + 0.075],
117
+ [100, 1000 + 0.075],
118
+ [1000, 1e6 + 10000],
119
+ [1e6, 1e9]
120
+ ];
121
+
111
122
  /**
112
123
  * @public
113
124
  * @type {Ellipsoid}
@@ -378,9 +389,10 @@ export class Planet extends RenderNode {
378
389
  * @public
379
390
  * @type {number}
380
391
  */
381
- this._lodRatio = MAX_LOD;
382
- this._maxLodRatio = MAX_LOD;
383
- this._minLodRatio = MIN_LOD;
392
+ this._lodSize = CUR_LOD_SIZE;
393
+ this._curLodSize = CUR_LOD_SIZE;
394
+ this._minLodSize = MIN_LOD_SIZE;
395
+ this._maxLodSize = MAX_LOD_SIZE;
384
396
 
385
397
  this._pickingColorArr = new Float32Array(this.SLICE_SIZE_4);
386
398
  this._samplerArr = new Int32Array(this.SLICE_SIZE);
@@ -397,11 +409,11 @@ export class Planet extends RenderNode {
397
409
 
398
410
  this._normalMapCreator = null;
399
411
 
400
- this._terrainWorker = new TerrainWorker(2);
412
+ this._terrainWorker = new TerrainWorker(3);
401
413
 
402
- this._plainSegmentWorker = new PlainSegmentWorker(2);
414
+ this._plainSegmentWorker = new PlainSegmentWorker(4);
403
415
 
404
- this._tileLoader = new Loader(14);
416
+ this._tileLoader = new Loader(options.loadingBatchSize || 12);
405
417
 
406
418
  this._memKey = new Key();
407
419
 
@@ -433,11 +445,14 @@ export class Planet extends RenderNode {
433
445
  control.addTo(this.renderer);
434
446
  }
435
447
 
436
- setRatioLod(maxLod, minLod) {
437
- this._maxLodRatio = maxLod;
438
- if (minLod) {
439
- this._minLodRatio = minLod;
440
- }
448
+ get lodSize() {
449
+ return this._lodSize;
450
+ }
451
+
452
+ setLodSize(currentLodSize, minLodSize, maxLodSize) {
453
+ this._maxLodSize = maxLodSize || this._maxLodSize;
454
+ this._minLodSize = minLodSize || this._minLodSize;
455
+ this._curLodSize = currentLodSize || this._curLodSize;
441
456
  this._renderCompletedActivated = false;
442
457
  }
443
458
 
@@ -717,6 +732,7 @@ export class Planet extends RenderNode {
717
732
  this.transparentTexture = this.renderer.handler.transparentTexture;
718
733
 
719
734
  this.camera = this.renderer.activeCamera = new PlanetCamera(this, {
735
+ frustums: this._cameraFrustums,
720
736
  eye: new Vec3(0, 0, 28000000),
721
737
  look: new Vec3(0, 0, 0),
722
738
  up: new Vec3(0, 1, 0),
@@ -981,16 +997,10 @@ export class Planet extends RenderNode {
981
997
  _collectRenderNodes() {
982
998
  let cam = this.camera;
983
999
 
984
- this._lodRatio = math.lerp(
985
- cam.slope < 0.0 ? 0.0 : cam.slope,
986
- this._maxLodRatio,
987
- this._minLodRatio
988
- );
1000
+ this._lodSize = math.lerp(cam.slope < 0.0 ? 0.0 : cam.slope, this._curLodSize, this._minLodSize);
989
1001
 
990
1002
  cam._insideSegment = null;
991
1003
 
992
- this._nodeCounterError_ = 0;
993
-
994
1004
  // clear first
995
1005
  this._clearRenderedNodeList();
996
1006
 
@@ -1005,11 +1015,11 @@ export class Planet extends RenderNode {
1005
1015
 
1006
1016
  this._quadTree.renderTree(cam, 0, null);
1007
1017
 
1008
- if (
1009
- cam.slope > this.minEqualZoomCameraSlope &&
1018
+ if (cam.slope > this.minEqualZoomCameraSlope &&
1010
1019
  cam._lonLat.height < this.maxEqualZoomAltitude &&
1011
1020
  cam._lonLat.height > this.minEqualZoomAltitude
1012
1021
  ) {
1022
+
1013
1023
  this.minCurrZoom = this.maxCurrZoom;
1014
1024
 
1015
1025
  let temp = this._renderedNodes,
@@ -1026,7 +1036,8 @@ export class Planet extends RenderNode {
1026
1036
 
1027
1037
  for (var i = 0, len = temp.length; i < len; i++) {
1028
1038
  var ri = temp[i];
1029
- if (ri.segment.tileZoom === this.maxCurrZoom) {
1039
+ let ht = ri.segment.centerNormal.dot(cam._b);
1040
+ if (ri.segment.tileZoom === this.maxCurrZoom || ht < HORIZON_TANGENT) {
1030
1041
  this._renderedNodes.push(ri);
1031
1042
  let k = 0,
1032
1043
  inFrustum = ri.inFrustum;
@@ -1076,9 +1087,7 @@ export class Planet extends RenderNode {
1076
1087
  frame() {
1077
1088
  this._renderScreenNodesPASS();
1078
1089
 
1079
- if (this.renderer.isActiveBackbuffers) {
1080
- this._renderHeightPickingFramebufferPASS();
1081
- }
1090
+ this._renderHeightPickingFramebufferPASS();
1082
1091
 
1083
1092
  this.drawEntityCollections(this._frustumEntityCollections);
1084
1093
  }
@@ -1156,11 +1165,8 @@ export class Planet extends RenderNode {
1156
1165
 
1157
1166
  // bind night glowing material
1158
1167
  gl.activeTexture(gl.TEXTURE0 + this.SLICE_SIZE);
1159
- gl.bindTexture(
1160
- gl.TEXTURE_2D,
1161
- (this.camera._lonLat.height > 329958.0 &&
1162
- (this._nightTexture || this.transparentTexture)) ||
1163
- this.transparentTexture
1168
+ gl.bindTexture(gl.TEXTURE_2D,
1169
+ (this.camera._lonLat.height > 329958.0 && (this._nightTexture || this.transparentTexture)) || this.transparentTexture
1164
1170
  );
1165
1171
  gl.uniform1i(shu.nightTexture, this.SLICE_SIZE);
1166
1172
 
@@ -1227,63 +1233,45 @@ export class Planet extends RenderNode {
1227
1233
  * @protected
1228
1234
  */
1229
1235
  _renderHeightPickingFramebufferPASS() {
1230
- this._heightPickingFramebuffer.activate();
1236
+ if (!this.terrain.isEmpty) {
1231
1237
 
1232
- let sh;
1233
- let renderer = this.renderer;
1234
- let h = renderer.handler;
1235
- let gl = h.gl;
1236
- let cam = renderer.activeCamera;
1237
- let frustumIndex = cam.getCurrentFrustum();
1238
+ this._heightPickingFramebuffer.activate();
1238
1239
 
1239
- if (frustumIndex === cam.FARTHEST_FRUSTUM_INDEX) {
1240
- gl.clearColor(0.0, 0.0, 0.0, 1.0);
1241
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
1242
- } else {
1243
- gl.clear(gl.DEPTH_BUFFER_BIT);
1244
- }
1245
-
1246
- gl.enable(gl.CULL_FACE);
1247
- gl.blendEquation(gl.FUNC_ADD);
1248
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
1249
- gl.enable(gl.BLEND);
1240
+ let sh;
1241
+ let renderer = this.renderer;
1242
+ let h = renderer.handler;
1243
+ let gl = h.gl;
1244
+ let cam = renderer.activeCamera;
1245
+ let frustumIndex = cam.getCurrentFrustum();
1250
1246
 
1251
- h.programs.drawnode_heightPicking.activate();
1252
- sh = h.programs.drawnode_heightPicking._program;
1253
- let shu = sh.uniforms;
1247
+ if (frustumIndex === cam.FARTHEST_FRUSTUM_INDEX) {
1248
+ gl.clearColor(0.0, 0.0, 0.0, 1.0);
1249
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
1250
+ } else {
1251
+ gl.clear(gl.DEPTH_BUFFER_BIT);
1252
+ }
1254
1253
 
1255
- gl.uniformMatrix4fv(shu.viewMatrix, false, renderer.activeCamera.getViewMatrix());
1256
- gl.uniformMatrix4fv(
1257
- shu.projectionMatrix,
1258
- false,
1259
- renderer.activeCamera.getProjectionMatrix()
1260
- );
1254
+ h.programs.drawnode_heightPicking.activate();
1255
+ sh = h.programs.drawnode_heightPicking._program;
1256
+ let shu = sh.uniforms;
1261
1257
 
1262
- gl.uniform3fv(shu.eyePositionHigh, cam.eyeHigh);
1263
- gl.uniform3fv(shu.eyePositionLow, cam.eyeLow);
1258
+ gl.uniformMatrix4fv(shu.viewMatrix, false, renderer.activeCamera.getViewMatrix());
1259
+ gl.uniformMatrix4fv(shu.projectionMatrix, false, renderer.activeCamera.getProjectionMatrix());
1264
1260
 
1265
- // drawing planet nodes
1266
- var rn = this._renderedNodesInFrustum[frustumIndex],
1267
- sl = this._visibleTileLayerSlices;
1261
+ gl.uniform3fv(shu.eyePositionHigh, cam.eyeHigh);
1262
+ gl.uniform3fv(shu.eyePositionLow, cam.eyeLow);
1268
1263
 
1269
- let i = rn.length;
1270
- while (i--) {
1271
- rn[i].segment.heightPickingRendering(sh, sl[0], 0);
1272
- }
1264
+ // drawing planet nodes
1265
+ var rn = this._renderedNodesInFrustum[frustumIndex],
1266
+ sl = this._visibleTileLayerSlices;
1273
1267
 
1274
- //gl.enable(gl.POLYGON_OFFSET_FILL);
1275
- for (let j = 1, len = sl.length; j < len; j++) {
1276
- i = rn.length;
1277
- //gl.polygonOffset(0, -j);
1268
+ let i = rn.length;
1278
1269
  while (i--) {
1279
- rn[i].segment.heightPickingRendering(sh, sl[j], j, this.transparentTexture, true);
1270
+ rn[i].segment.heightPickingRendering(sh, sl[0]);
1280
1271
  }
1281
- }
1282
- //gl.disable(gl.POLYGON_OFFSET_FILL);
1283
1272
 
1284
- gl.disable(gl.BLEND);
1285
-
1286
- this._heightPickingFramebuffer.deactivate();
1273
+ this._heightPickingFramebuffer.deactivate();
1274
+ }
1287
1275
  }
1288
1276
 
1289
1277
  /**
@@ -1362,15 +1350,7 @@ export class Planet extends RenderNode {
1362
1350
 
1363
1351
  let i = rn.length;
1364
1352
  while (i--) {
1365
- rn[i].segment.depthRendering(sh, sl[0], 0);
1366
- }
1367
-
1368
- for (let j = 1, len = sl.length; j < len; j++) {
1369
- i = rn.length;
1370
- gl.polygonOffset(0, -j);
1371
- while (i--) {
1372
- rn[i].segment.depthRendering(sh, sl[j], j, this.transparentTexture, true);
1373
- }
1353
+ rn[i].segment.depthRendering(sh, sl[0]);
1374
1354
  }
1375
1355
  }
1376
1356
 
@@ -1561,41 +1541,48 @@ export class Planet extends RenderNode {
1561
1541
  * @returns {number} -
1562
1542
  */
1563
1543
  getDistanceFromPixel(px) {
1564
- let r = this.renderer,
1565
- cnv = this.renderer.handler.canvas;
1544
+ if (this.terrain.isEmpty) {
1545
+ return this.getDistanceFromPixelEllipsoid(px) || 0;
1546
+ } else {
1566
1547
 
1567
- let spx = px.x / cnv.width,
1568
- spy = (cnv.height - px.y) / cnv.height;
1548
+ let r = this.renderer,
1549
+ cnv = this.renderer.handler.canvas;
1569
1550
 
1570
- // HEIGHT
1571
- this._heightPickingFramebuffer.activate();
1572
- if (this._heightPickingFramebuffer.isComplete()) {
1573
- this._heightPickingFramebuffer.readPixels(_tempPickingPix_, spx, spy);
1574
- }
1575
- this._heightPickingFramebuffer.deactivate();
1576
-
1577
- let dist = decodeFloatFromRGBAArr(_tempPickingPix_);
1578
-
1579
- if (!(_tempPickingPix_[0] || _tempPickingPix_[1] || _tempPickingPix_[2])) {
1580
- dist = this.getDistanceFromPixelEllipsoid(px) || 0;
1581
- } else if (dist < DEPTH_DISTANCE) {
1582
- r.screenDepthFramebuffer.activate();
1583
- if (r.screenDepthFramebuffer.isComplete()) {
1584
- r.screenDepthFramebuffer.readPixels(_tempDepthColor_, spx, spy);
1585
- let screenPos = new Vec4(
1586
- spx * 2.0 - 1.0,
1587
- spy * 2.0 - 1.0,
1588
- (_tempDepthColor_[0] / 255.0) * 2.0 - 1.0,
1589
- 1.0 * 2.0 - 1.0
1590
- );
1591
- let viewPosition = this.camera.frustums[0]._inverseProjectionMatrix.mulVec4(screenPos);
1592
- let dir = px.direction || this.renderer.activeCamera.unproject(px.x, px.y);
1593
- dist = -(viewPosition.z / viewPosition.w) / dir.dot(this.renderer.activeCamera.getForward());
1551
+ let spx = px.x / cnv.width,
1552
+ spy = (cnv.height - px.y) / cnv.height;
1553
+
1554
+ _tempPickingPix_[0] = _tempPickingPix_[1] = _tempPickingPix_[2] = 0.0;
1555
+
1556
+ let dist = 0;
1557
+
1558
+ // HEIGHT
1559
+ this._heightPickingFramebuffer.activate();
1560
+ if (this._heightPickingFramebuffer.isComplete()) {
1561
+ this._heightPickingFramebuffer.readPixels(_tempPickingPix_, spx, spy);
1562
+ dist = decodeFloatFromRGBAArr(_tempPickingPix_);
1594
1563
  }
1595
- r.screenDepthFramebuffer.deactivate();
1564
+ this._heightPickingFramebuffer.deactivate();
1565
+
1566
+ if (!(_tempPickingPix_[0] || _tempPickingPix_[1] || _tempPickingPix_[2])) {
1567
+ dist = this.getDistanceFromPixelEllipsoid(px) || 0;
1568
+ } else if (dist < DEPTH_DISTANCE) {
1569
+ r.screenDepthFramebuffer.activate();
1570
+ if (r.screenDepthFramebuffer.isComplete()) {
1571
+ r.screenDepthFramebuffer.readPixels(_tempDepthColor_, spx, spy);
1572
+ let screenPos = new Vec4(
1573
+ spx * 2.0 - 1.0,
1574
+ spy * 2.0 - 1.0,
1575
+ (_tempDepthColor_[0] / 255.0) * 2.0 - 1.0,
1576
+ 1.0 * 2.0 - 1.0
1577
+ );
1578
+ let viewPosition = this.camera.frustums[0]._inverseProjectionMatrix.mulVec4(screenPos);
1579
+ let dir = px.direction || this.renderer.activeCamera.unproject(px.x, px.y);
1580
+ dist = -(viewPosition.z / viewPosition.w) / dir.dot(this.renderer.activeCamera.getForward());
1581
+ }
1582
+ r.screenDepthFramebuffer.deactivate();
1583
+ }
1584
+ return dist;
1596
1585
  }
1597
-
1598
- return dist;
1599
1586
  }
1600
1587
 
1601
1588
  /**