Skip to content

Commit

Permalink
fixed support for displaysize in metatile v5
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Apr 9, 2021
1 parent 303de6c commit 9fe0228
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vts-browser-js",
"version": "2.23.10",
"version": "2.23.11",
"description": "JavaScript WebGL 3D maps rendering engine",
"main": "src/browser/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ string getCoreVersion()
*/

function getCoreVersion(full) {
return (full ? 'Core: ' : '') + '2.23.10';
return (full ? 'Core: ' : '') + '2.23.11';
}


Expand Down
8 changes: 8 additions & 0 deletions src/core/map/metanode.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@ MapMetanode.prototype.generateCullingHelpers = function(virtual) {
maxDelta = Math.min(d1, d2, d3, d4);
}

if (version >= 5 && this.usedDisplaySize()) {
this.bboxMaxSize = Math.max(
vec3.distance2(bbox, 0, bbox, 3),
vec3.distance2(bbox, 3, bbox, 6),
vec3.distance2(bbox, 0, bbox, 12)
);
}

//get cos angle based at 90deg
this.diskAngle = Math.cos(Math.max(0,(Math.PI * 0.5) - Math.acos(maxDelta)));
this.diskAngle2 = maxDelta;
Expand Down
9 changes: 3 additions & 6 deletions src/core/map/surface-tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ MapSurfaceTile.prototype.updateTexelSize = function() {
if (node.usedTexelSize()) {
screenPixelSize = draw.ndcToScreenPixel * node.pixelSize;
} else if (node.usedDisplaySize()) {
screenPixelSize = draw.ndcToScreenPixel * (node.bbox.maxSize / node.displaySize);
screenPixelSize = draw.ndcToScreenPixel * ((node.bbox ? node.bbox.maxSize : node.bboxMaxSize) / node.displaySize);
}

if (camera.camera.ortho) {
Expand All @@ -929,22 +929,19 @@ MapSurfaceTile.prototype.updateTexelSize = function() {
if (node.usedDisplaySize()) {

if (!preciseDistance) {
screenPixelSize = draw.ndcToScreenPixel * (node.bbox.maxSize / 256);
screenPixelSize = draw.ndcToScreenPixel * ((node.bbox ? node.bbox.maxSize : node.bboxMaxSize) / 256);

factor = (node.displaySize / 256) * camera.distance;
//var factor = (256 / 256) * this.map.cameraDistance;

v = camera.vector; //move camera away hack
p = [cameraPos[0] - v[0] * factor, cameraPos[1] - v[1] * factor, cameraPos[2] - v[2] * factor];

pixelSize = this.getPixelSize(node.bbox, screenPixelSize, p, p, true);
} else {
if (draw.isGeocent) {
//screenPixelSize = draw.ndcToScreenPixel * ((node.diskAngle2A * draw.planetRadius * 2 * 0.70710678118) / 256) * (256 / node.displaySize);
screenPixelSize = draw.ndcToScreenPixel * ((node.diskAngle2A * draw.planetRadius * 1.41421356236) / node.displaySize);
} else {
//screenPixelSize = draw.ndcToScreenPixel * (node.bbox.maxSize / 256) * (256 / node.displaySize);
screenPixelSize = draw.ndcToScreenPixel * (node.bbox.maxSize / node.displaySize);
screenPixelSize = draw.ndcToScreenPixel * ((node.bbox ? node.bbox.maxSize : node.bboxMaxSize) / node.displaySize);
}

pixelSize = this.getPixelSize3(node, screenPixelSize);
Expand Down
8 changes: 8 additions & 0 deletions src/core/utils/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ vec3.distance = function (a, b) {
return Math.sqrt(dx*dx + dy*dy + dz*dz);
};

vec3.distance2 = function (a, i, b, j) {
var dx = b[j] - a[i];
var dy = b[j+1] - a[i+1];
var dz = b[j+2] - a[i+2];
return Math.sqrt(dx*dx + dy*dy + dz*dz);
};


vec3.squareDistance = function (a, b) {
var dx = b[0] - a[0];
var dy = b[1] - a[1];
Expand Down

0 comments on commit 9fe0228

Please sign in to comment.