wrap bsphere to setBoundingSphere

This commit is contained in:
Zemledelec 2018-07-22 13:05:02 +03:00
parent 544e709107
commit d50b396493
3 changed files with 52 additions and 23 deletions

View File

@ -62,7 +62,7 @@ let osm = new XYZ("OSM", {
window.globe = new Globe({
'name': "Earth",
'target': "earth",
'terrain': new MapboxTerrain(),
'terrain': new GlobusTerrain(),//new MapboxTerrain(),
'layers': [osm]
});

View File

@ -174,8 +174,7 @@ Node.prototype.createBounds = function () {
if (seg.tileZoom === 0) {
seg.bsphere.radius = seg.planet.ellipsoid._a;
seg.bsphere.center = new Vec3();
seg.setBoundingSphere(0.0, 0.0, 0.0, seg.planet.ellipsoid._a);
} else if (seg.tileZoom < seg.planet.terrain.minZoom) {
@ -215,15 +214,13 @@ Node.prototype.createBounds = function () {
let v_sw = new Vec3(pVerts[ind_sw], pVerts[ind_sw + 1], pVerts[ind_sw + 2]),
v_ne = new Vec3(pVerts[ind_ne], pVerts[ind_ne + 1], pVerts[ind_ne + 2]);
seg.bsphere.center.set(
seg.setBoundingSphere(
v_sw.x + (v_ne.x - v_sw.x) * 0.5,
v_sw.y + (v_ne.y - v_sw.y) * 0.5,
v_sw.z + (v_ne.z - v_sw.z) * 0.5
v_sw.z + (v_ne.z - v_sw.z) * 0.5,
v_sw
);
seg.bsphere.radius = seg.bsphere.center.distance(v_sw);
if (seg.tileZoom < MAX_NORMAL_ZOOM) {
//check for segment zoom
let v_nw = new Vec3(pVerts[ind_nw], pVerts[ind_nw + 1], pVerts[ind_nw + 2]),
@ -277,8 +274,12 @@ Node.prototype.createBounds = function () {
coords_rb = Vec3.add(vs.scaleTo(1 - vi_x / insideSize), ve.scaleTo(1 - vi_y / insideSize)).addA(v_rb);
}
seg.bsphere.radius = coords_lt.distance(coords_rb) * 0.5;
seg.bsphere.center = coords_lt.addA(coords_rb.subA(coords_lt).scale(0.5));
seg.setBoundingSphere(
coords_lt.x + (coords_rb.x - coords_lt.x) * 0.5,
coords_lt.y + (coords_rb.y - coords_lt.y) * 0.5,
coords_lt.z + (coords_rb.z - coords_lt.z) * 0.5,
coords_lt
);
}
} else {
seg.createBoundsByExtent();
@ -805,13 +806,12 @@ Node.prototype.whileTerrainLoading = function () {
//is used for earth point calculation(see segment object)
seg.tempVertices = tempVertices;
seg.bsphere.center.set(
seg.setBoundingSphere(
BOUNDS.xmin + (BOUNDS.xmax - BOUNDS.xmin) * 0.5,
BOUNDS.ymin + (BOUNDS.ymax - BOUNDS.ymin) * 0.5,
BOUNDS.zmin + (BOUNDS.zmax - BOUNDS.zmin) * 0.5
BOUNDS.zmin + (BOUNDS.zmax - BOUNDS.zmin) * 0.5,
new Vec3(BOUNDS.xmin, BOUNDS.ymin, BOUNDS.zmin)
);
seg.bsphere.radius = seg.bsphere.center.distance(new Vec3(BOUNDS.xmin, BOUNDS.ymin, BOUNDS.zmin));
}
let maxZ = terrain.maxZoom;

View File

@ -86,6 +86,12 @@ const Segment = function (node, planet, tileZoom, extent) {
this._seNorm = null;
this._neNorm = null;
/**
* experimental
*/
this._deltaHeight = 0;
/**
* Geographical extent.
* @type {og.Extent}
@ -465,7 +471,14 @@ Segment.prototype._terrainWorkerCallback = function (data) {
this.tempVertices = data.terrainVertices;
//var tgs = this.planet.terrain.gridSizeByZoom[this.tileZoom];
this.bsphere.setFromBounds(data.bounds);
var b = data.bounds;
this.setBoundingSphere(
b[0] + (b[1] - b[0]) * 0.5,
b[2] + (b[3] - b[2]) * 0.5,
b[4] + (b[5] - b[4]) * 0.5,
new Vec3(b[0], b[2], b[4])
);
this.gridSize = Math.sqrt(this.terrainVertices.length / 3) - 1;
this.node.appliedTerrainNodeId = this.node.nodeId;
@ -473,7 +486,7 @@ Segment.prototype._terrainWorkerCallback = function (data) {
this.terrainIsLoading = false;
this.parentNormalMapReady = true;
this.terrainExists = true;
if (!this.normalMapTexturePtr) {
var nmc = this.planet._normalMapCreator;
this.normalMapTexturePtr = this.planet.renderer.handler.createEmptyTexture_l(nmc._width, nmc._height);
@ -833,19 +846,29 @@ Segment.prototype.createBoundsByExtent = function () {
}
if (this.tileZoom < 4) {
this.bsphere.center.set(
this.setBoundingSphere(
(coord_sw.x + coord_nw.x + (coord_ne.x - coord_sw.x + coord_se.x - coord_nw.x) * 0.5) * 0.5,
(coord_sw.y + coord_nw.y + (coord_ne.y - coord_sw.y + coord_se.y - coord_nw.y) * 0.5) * 0.5,
(coord_sw.z + coord_nw.z + (coord_ne.z - coord_sw.z + coord_se.z - coord_nw.z) * 0.5) * 0.5
(coord_sw.z + coord_nw.z + (coord_ne.z - coord_sw.z + coord_se.z - coord_nw.z) * 0.5) * 0.5,
coord_ne
);
this.bsphere.radius = 0.5 * (this.bsphere.center.distance(coord_ne) + this.bsphere.center.distance(coord_sw));
} else {
this.bsphere.center.set(coord_sw.x + (coord_ne.x - coord_sw.x) * 0.5, coord_sw.y + (coord_ne.y - coord_sw.y) * 0.5, coord_sw.z + (coord_ne.z - coord_sw.z) * 0.5);
this.bsphere.radius = this.bsphere.center.distance(coord_ne);
this.setBoundingSphere(
coord_sw.x + (coord_ne.x - coord_sw.x) * 0.5,
coord_sw.y + (coord_ne.y - coord_sw.y) * 0.5,
coord_sw.z + (coord_ne.z - coord_sw.z) * 0.5,
coord_ne
);
}
};
Segment.prototype.setBoundingSphere = function (x, y, z, v) {
this.bsphere.center.x = x;
this.bsphere.center.y = y;
this.bsphere.center.z = z;
this.bsphere.radius = this.bsphere.center.distance(v);
};
/**
* @todo: remake it
*/
@ -934,7 +957,13 @@ Segment.prototype.createTerrainFromChildNodes = function () {
//this.createCoordsBuffers(this.terrainVertices, this.gridSize);
this.readyToEngage = true;
this.bsphere.setFromBounds([xmin, xmax, ymin, ymax, zmin, zmax]);
this.setBoundingSphere(
xmin + (xmax - xmin) * 0.5,
ymin + (ymax - ymin) * 0.5,
zmin + (zmax - zmin) * 0.5,
new Vec3(xmin, ymin, zmin)
);
this.appliedTerrainNodeId = this.nodeId;
this.terrainReady = true;