From efcdbf00aa134530fae8cad05920d0ac309ad5eb Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Thu, 4 May 2017 17:23:59 +0200 Subject: [PATCH 1/2] fixed bboxes --- package.json | 2 +- src/core/core.js | 2 +- src/core/map/draw.js | 6 +++--- src/core/map/metanode.js | 23 +++++++++++++++++++++++ src/core/map/surface-tree.js | 4 ++-- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index c0083528..fc9c193e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vts-browser-js", - "version": "2.2.0", + "version": "2.2.1", "description": "JavaScript WebGL 3D maps rendering engine", "main": "src/browser/index.js", "scripts": { diff --git a/src/core/core.js b/src/core/core.js index 3f1c4879..9228323e 100755 --- a/src/core/core.js +++ b/src/core/core.js @@ -468,7 +468,7 @@ string getCoreVersion() */ function getCoreVersion(full) { - return (full ? 'Core: ' : '') + '2.2.0'; + return (full ? 'Core: ' : '') + '2.2.1'; } diff --git a/src/core/map/draw.js b/src/core/map/draw.js index 95c341f8..83e4bacb 100755 --- a/src/core/map/draw.js +++ b/src/core/map/draw.js @@ -235,7 +235,7 @@ MapDraw.prototype.drawMap = function(skipFreeLayers) { for (i = 0, li = tiles.length; i < li; i++) { if (!tiles[i][1]) { //skip grids tile = tiles[i][0]; - if ((single && tile.id[0] == lod) || (!single && tile.id[0] <= lod)) { + if (tile && ((single && tile.id[0] == lod) || (!single && tile.id[0] <= lod))) { drawTiles.drawSurfaceTile(tile, tile.metanode, cameraPos, tile.pixelSize, tile.priority, false, false); } } @@ -247,7 +247,7 @@ MapDraw.prototype.drawMap = function(skipFreeLayers) { for (i = 0, li = tiles.length; i < li; i++) { if (!tiles[i][1]) { //skip grids tile = tiles[i][0]; - if ((single && tile.id[0] == lod) || (!single && tile.id[0] <= lod)) { + if (tile && ((single && tile.id[0] == lod) || (!single && tile.id[0] <= lod))) { drawTiles.drawSurfaceTile(tile, tile.metanode, cameraPos, tile.pixelSize, tile.priority, false, false); } } @@ -260,7 +260,7 @@ MapDraw.prototype.drawMap = function(skipFreeLayers) { debug.drawBBoxes = true; for (i = 0, li = tiles.length; i < li; i++) { tile = tiles[i]; - if ((single && tile.id[0] == lod) || (!single && tile.id[0] <= lod)) { + if (tile && ((single && tile.id[0] == lod) || (!single && tile.id[0] <= lod))) { drawTiles.drawTileInfo(tile, tile.metanode, cameraPos, tile.surfaceMesh, tile.pixelSize); } } diff --git a/src/core/map/metanode.js b/src/core/map/metanode.js index 7ae50365..eedefb17 100755 --- a/src/core/map/metanode.js +++ b/src/core/map/metanode.js @@ -488,6 +488,7 @@ MapMetanode.prototype.generateCullingHelpers = function(virtual) { bbox[18] = maxX; bbox[19] = maxY; bbox[20] = maxZ; bbox[21] = minX; bbox[22] = maxY; bbox[23] = maxZ; } else { + normalize = vec3.normalize3; dot = vec3.dot2; @@ -505,6 +506,28 @@ MapMetanode.prototype.generateCullingHelpers = function(virtual) { maxDelta = Math.min(d1, d2, d3, d4); + if (this.id[0] <= 8) { //extend bbox because of lon curvature + pos = this.diskPos; + + var expand = 0.11; + + bbox[0] += (bbox[0] - pos[0]) * expand; + bbox[1] += (bbox[1] - pos[1]) * expand; + bbox[2] += (bbox[2] - pos[2]) * expand; + + bbox[3] += (bbox[3] - pos[0]) * expand; + bbox[4] += (bbox[4] - pos[1]) * expand; + bbox[5] += (bbox[5] - pos[2]) * expand; + + bbox[6] += (bbox[6] - pos[0]) * expand; + bbox[7] += (bbox[7] - pos[1]) * expand; + bbox[8] += (bbox[8] - pos[2]) * expand; + + bbox[9] += (bbox[9] - pos[0]) * expand; + bbox[10] += (bbox[10] - pos[1]) * expand; + bbox[11] += (bbox[11] - pos[2]) * expand; + } + //extend bbox height by tile curvature height += draw.planetRadius - (draw.planetRadius * maxDelta); diff --git a/src/core/map/surface-tree.js b/src/core/map/surface-tree.js index e5f43972..6b6da1db 100755 --- a/src/core/map/surface-tree.js +++ b/src/core/map/surface-tree.js @@ -443,8 +443,8 @@ MapSurfaceTree.prototype.drawSurface = function() { if (replay.storeTiles || replay.storeFreeTiles) { //used only in inspectors - if (!this.map.tileBuffer[0]) { - this.map.tileBuffer[0] = []; + if (!draw.tileBuffer[0]) { + draw.tileBuffer[0] = []; } var tiles = draw.tileBuffer[0]; From eef90df788ce52b502b94fc8323cbbd91c6bc35d Mon Sep 17 00:00:00 2001 From: David Levinsky Date: Fri, 5 May 2017 09:41:06 +0200 Subject: [PATCH 2/2] fixed street names orientation, faster cameraInfo, flatform module is public --- src/browser/index.js | 4 +++- src/core/index.js | 4 +++- src/core/inspector/input.js | 2 +- src/core/map/measure.js | 17 ++++++++++------- src/core/map/metanode.js | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/browser/index.js b/src/browser/index.js index b777e7f2..566298f9 100644 --- a/src/browser/index.js +++ b/src/browser/index.js @@ -4,6 +4,7 @@ import {getCoreVersion as getCoreVersion_, checkSupport as checkSupport_} from ' import {vec2 as vec2_, vec3 as vec3_, vec4 as vec4_, mat3 as mat3_, mat4 as mat4_} from '../core/utils/matrix'; import {utils as utils_} from '../core/utils/utils'; import {math as math_} from '../core/utils/math'; +import {platform as platform_} from '../core/utils/platform'; import BrowserInterface_ from './interface'; //get rid of compiler mess @@ -13,6 +14,7 @@ var utils = utils_; var math = math_; var BrowserInterface = BrowserInterface_; var proj4 = Proj4; +var platform = platform_; function browser (element, config) { var browserInterface = new BrowserInterface(element, config); @@ -24,4 +26,4 @@ function getBrowserVersion() { return '' + getCoreVersion(); } -export {vec2,vec3,vec4,mat3,mat4,math,utils,getCoreVersion,checkSupport,browser,getBrowserVersion,proj4}; +export {vec2,vec3,vec4,mat3,mat4,math,utils,getCoreVersion,checkSupport,browser,getBrowserVersion,proj4,platform}; diff --git a/src/core/index.js b/src/core/index.js index 525c7f85..5e89b313 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -4,6 +4,7 @@ import {CoreInterface as CoreInterface_} from './interface'; import {vec2 as vec2_, vec3 as vec3_, vec4 as vec4_, mat3 as mat3_, mat4 as mat4_} from './utils/matrix'; import {utils as utils_} from './utils/utils'; import {math as math_} from './utils/math'; +import {platform as platform_} from './utils/platform'; //get rid of compiler mess var getCoreVersion = getCoreVersion_, checkSupport = checkSupport_; @@ -12,6 +13,7 @@ var vec2 = vec2_, vec3 = vec3_, vec4 = vec4_, mat3 = mat3_, mat4 = mat4_; var utils = utils_; var math = math_; var proj4 = Proj4; +var platform = platform_; function core(element, config) { @@ -25,5 +27,5 @@ function core(element, config) { } -export {vec2,vec3,vec4,mat3,mat4,math,utils,getCoreVersion,checkSupport,core,proj4}; +export {vec2,vec3,vec4,mat3,mat4,math,utils,getCoreVersion,checkSupport,core,proj4,platform}; diff --git a/src/core/inspector/input.js b/src/core/inspector/input.js index dc2d6b1f..a45a5567 100755 --- a/src/core/inspector/input.js +++ b/src/core/inspector/input.js @@ -270,7 +270,7 @@ InspectorInput.prototype.onKeyUp = function(event, press) { case 88: case 120: - debug.config.mapFog = !debug.config.mapFog; hit = true; break; //key X pressed + debug.drawFog = !debug.drawFog; hit = true; break; //key X pressed case 82: case 114: diff --git a/src/core/map/measure.js b/src/core/map/measure.js index a49c4d13..40a92bcd 100755 --- a/src/core/map/measure.js +++ b/src/core/map/measure.js @@ -701,9 +701,11 @@ MapMeasure.prototype.getPositionCameraInfo = function(position, projected, clamp if (clampTilt) { //used for street labels orientation[1] = math.clamp(orientation[1], -89.0, 90.0); } - + + var roty = math.clamp(orientation[1], -89.5, 89.5); + var tmpMatrix = mat4.create(); - mat4.multiply(math.rotationMatrix(2, math.radians(-orientation[0])), math.rotationMatrix(0, math.radians(orientation[1])), tmpMatrix); + mat4.multiply(math.rotationMatrix(2, math.radians(-orientation[0])), math.rotationMatrix(0, math.radians(roty)), tmpMatrix); var orbitPos, ned, north, east, direction, spaceMatrix, rotationMatrix; var east2, north2, direction2, dir, up, right; @@ -730,7 +732,7 @@ MapMeasure.prototype.getPositionCameraInfo = function(position, projected, clamp if (projected) { tmpMatrix = mat4.create(); - mat4.multiply(math.rotationMatrix(0, math.radians(-orientation[1] - 90.0)), math.rotationMatrix(2, math.radians(orientation[0])), tmpMatrix); + mat4.multiply(math.rotationMatrix(0, math.radians(-roty - 90.0)), math.rotationMatrix(2, math.radians(orientation[0])), tmpMatrix); ned = this.getNED(coords); north = ned.north; @@ -820,7 +822,7 @@ MapMeasure.prototype.getPositionCameraInfo = function(position, projected, clamp //spaceMatrix = mat4.inverse(spaceMatrix); var localRotMatrix = mat4.create(); - mat4.multiply(math.rotationMatrix(0, math.radians(-orientation[1] - 90.0)), math.rotationMatrix(2, math.radians(orientation[0])), localRotMatrix); + mat4.multiply(math.rotationMatrix(0, math.radians(-roty - 90.0)), math.rotationMatrix(2, math.radians(orientation[0])), localRotMatrix); east2 = [1,0,0]; direction2 = [0,1,0]; @@ -892,13 +894,14 @@ MapMeasure.prototype.getPositionCameraInfo = function(position, projected, clamp spaceMatrix = mat4.inverse(spaceMatrix); mat4.multiplyVec3(spaceMatrix, orbitPos); - ret.vector2 = [-spaceMatrix[8], -spaceMatrix[9], -spaceMatrix[10]]; //vector2 is probably hack for tree.js bboxVisible + //ret.vector2 = [-spaceMatrix[8], -spaceMatrix[9], -spaceMatrix[10]]; //vector2 is probably hack for tree.js bboxVisible + ret.vector = [-rotationMatrix[2], -rotationMatrix[6], -rotationMatrix[10]]; //var ray = this.map.renderer.getScreenRay(800,400); //get camera direction - mat4.inverse(rotationMatrix, spaceMatrix); - ret.vector = [-spaceMatrix[8], -spaceMatrix[9], -spaceMatrix[10]]; + //mat4.inverse(rotationMatrix, spaceMatrix); + //ret.vector = [-spaceMatrix[8], -spaceMatrix[9], -spaceMatrix[10]]; //console.log("cam vec: " + JSON.stringify(this.cameraVector)); diff --git a/src/core/map/metanode.js b/src/core/map/metanode.js index eedefb17..598085af 100755 --- a/src/core/map/metanode.js +++ b/src/core/map/metanode.js @@ -509,7 +509,7 @@ MapMetanode.prototype.generateCullingHelpers = function(virtual) { if (this.id[0] <= 8) { //extend bbox because of lon curvature pos = this.diskPos; - var expand = 0.11; + var expand = 0.12 / (9-4) * (5-(this.id[0]-4)); bbox[0] += (bbox[0] - pos[0]) * expand; bbox[1] += (bbox[1] - pos[1]) * expand;