Skip to content

Commit

Permalink
Merge pull request #187 from davidmtech/master
Browse files Browse the repository at this point in the history
Faster loading
  • Loading branch information
davidmtech authored Jun 9, 2020
2 parents 56e8f89 + b8bbc7f commit 45aa6c5
Show file tree
Hide file tree
Showing 28 changed files with 2,998 additions and 72 deletions.
4 changes: 2 additions & 2 deletions demos/switching-geodata/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function onSwitchView() {
surfaces: {
'melown-viewfinder-world': [
'bmng08-world',
'bing-world'
"sentinel2-cloudless-eox"
]
},
freeLayers: {}
Expand All @@ -58,7 +58,7 @@ function onSwitchView() {
surfaces: {
'melown-viewfinder-world': [
'bmng08-world',
'bing-world'
"sentinel2-cloudless-eox"
]
},
freeLayers: {
Expand Down
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.22.6",
"version": "2.23.2",
"description": "JavaScript WebGL 3D maps rendering engine",
"main": "src/browser/index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ Browser.prototype.initConfig = function() {
controlLoading : true,
searchElement : null,
searchValue : null,
walkMode : false,
fixedHeight : 0,
geojson : null,
tiltConstrainThreshold : [0.5,1],
bigScreenMargins : false, //75,
Expand Down Expand Up @@ -411,6 +413,8 @@ Browser.prototype.setConfigParam = function(key, value, ignoreCore) {
case 'timeNormalizedInertia': this.config.timeNormalizedInertia = utils.validateBool(value, false); break;
case 'bigScreenMargins': this.config.bigScreenMargins = utils.validateBool(value, false); break;
case 'tiltConstrainThreshold': this.config.tiltConstrainThreshold = utils.validateNumberArray(value, 2, [0.5,1], [-Number.MAXINTEGER, -Number.MAXINTEGER], [Number.MAXINTEGER, Number.MAXINTEGER]); break;
case 'walkMode': this.config.walkMode = utils.validateBool(value, false); break;
case 'fixedHeight': this.config.fixedHeight = utils.validateNumber(value, -Number.MAXINTEGER, Number.MAXINTEGER, 0); break;
case 'geodata': this.config.geodata = value; break;
case 'geojson': this.config.geojson = value; break;
case 'geojsonStyle': this.config.geojsonStyle = JSON.parse(value); break;
Expand Down
14 changes: 13 additions & 1 deletion src/browser/control-mode/map-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,15 @@ ControlModeMapObserver.prototype.keypress = function() {


ControlModeMapObserver.prototype.setPosition = function(pos) {
pos = constrainMapPosition(this.browser, pos);

if (!this.config.walkMode) {
pos = constrainMapPosition(this.browser, pos);
}

if (this.config.fixedHeight) {
pos.setHeight(this.config.fixedHeight);
}

var map = this.browser.getMap();
map.setPosition(pos);
//console.log(JSON.stringify(pos));
Expand Down Expand Up @@ -269,6 +277,10 @@ ControlModeMapObserver.prototype.getAzimuthAndDistance = function(dx, dy) {
var viewExtent = pos.getViewExtent();
var fov = pos.getFov()*0.5;

if (this.config.walkMode) {
viewExtent += 5;
}

//var sensitivity = 0.5;
var zoomFactor = (((viewExtent*0.5) * Math.tan(math.radians(fov))) / 800);
dx *= zoomFactor;
Expand Down
9 changes: 7 additions & 2 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ var Core = function(element, config, coreInterface) {
mapLoadErrorMaxRetryCount : 3,
mapLoadMode : 'topdown', // 'topdown', 'downtop', 'fit', 'fitonly'
mapGeodataLoadMode : 'fit', // 'fitonly'
mapSplitMeshes : true, // used for topdown load mode
mapSplitSpace : null, // used octant spliting demo
mapSplitLods : false, // used octant spliting demo
mapGridMode : 'linear', // 'flat'
mapGridSurrogatez : false,
mapGridUnderSurface: 0,
Expand All @@ -73,11 +76,13 @@ var Core = function(element, config, coreInterface) {
mapPackLoaderEvents : true,
mapParseMeshInWorker : true,
mapPackGeodataEvents : true,
mapCheckTextureSize : false,

mapFeatureStickMode : [1,1],

map16bitMeshes : true,
mapOnlyOneUVs : true,
//mapOnlyOneUVs : true,
mapOnlyOneUVs : false,
mapIndexBuffers : true,
mapAsyncImageDecode : true,

Expand Down Expand Up @@ -580,7 +585,7 @@ string getCoreVersion()
*/

function getCoreVersion(full) {
return (full ? 'Core: ' : '') + '2.22.7';
return (full ? 'Core: ' : '') + '2.23.2';
}


Expand Down
23 changes: 20 additions & 3 deletions src/core/inspector/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ InspectorInput.prototype.onKeyUp = function(event, press) {

case 67:
case 99:
map.config.mapDegradeHorizon = !map.config.mapDegradeHorizon;
inspector.shakeCamera = !inspector.shakeCamera;

//map.config.mapDegradeHorizon = !map.config.mapDegradeHorizon;
//this.measureMode = !this.measureMode;
//this.measurePoints = [];
//var pos = this.core.hitTest(this.mouseX, this.mouseY, "all");
Expand Down Expand Up @@ -245,6 +246,10 @@ InspectorInput.prototype.onKeyUp = function(event, press) {
case 120:
debug.drawFog = !debug.drawFog; hit = true; break; //key X pressed

case 89:
case 120:
map.config.mapSplitLods = !map.config.mapSplitLods; hit = true; break; //key Y pressed

case 82:
case 114:
inspector.graphs.switchPanel(); break; //key R pressed
Expand All @@ -263,7 +268,7 @@ InspectorInput.prototype.onKeyUp = function(event, press) {

case 78:
case 110:
inspector.shakeCamera = !inspector.shakeCamera; break; //key N pressed
debug.drawNBBoxes = !debug.drawNBBoxes; break; //key N pressed

default:
blockHit = false;
Expand Down Expand Up @@ -320,7 +325,7 @@ InspectorInput.prototype.onKeyUp = function(event, press) {
}
}

if (this.diagnosticMode && debug.drawBBoxes && !this.shiftDown && !press) {
if (this.diagnosticMode && (debug.drawBBoxes || debug.drawNBBoxes) && !this.shiftDown && !press) {
blockHit = true;

switch(keyCode) {
Expand Down Expand Up @@ -348,6 +353,10 @@ InspectorInput.prototype.onKeyUp = function(event, press) {
case 100:
debug.drawDistance = !debug.drawDistance; break; //key D pressed

case 86:
case 118:
debug.drawSpaceBBox = !debug.drawSpaceBBox; break; //key V pressed

case 78:
case 110:
debug.drawNodeInfo = !debug.drawNodeInfo; break; //key N pressed
Expand All @@ -364,6 +373,10 @@ InspectorInput.prototype.onKeyUp = function(event, press) {
case 98:
debug.drawBoundLayers = !debug.drawBoundLayers; break; //key B pressed

case 82:
case 114:
debug.drawResources = !debug.drawResources; break; //key R pressed

case 83:
case 115:
debug.drawSurfaces = !debug.drawSurfaces; break; //key S pressed
Expand Down Expand Up @@ -433,8 +446,11 @@ InspectorInput.prototype.setParameter = function(key, value) {
var getBool = (function(a){ return (value === true || value == 'true' || value == '1') });

switch(key) {
case 'debugMode': this.diagnosticMode = true; break;
case 'debugBBox':
debug.drawBBoxes = true;
case 'debugNBBox':
if (key == 'debugNBBox') debug.drawNBBoxes = true;
var has = (function(a){ return (value.indexOf(a)!=-1); });
if (has('L')) debug.drawLods = true;
if (has('P')) debug.drawPositions = true;
Expand All @@ -443,6 +459,7 @@ InspectorInput.prototype.setParameter = function(key, value) {
if (has('G')) debug.drawGeodataOnly = true;
if (has('D')) debug.drawDistance = true;
if (has('N')) debug.drawNodeInfo = true;
if (has('V')) debug.drawSpaceBBox = true;
if (has('M')) debug.drawMeshBBox = true;
if (has('I')) debug.drawIndices = true;
if (has('B')) debug.drawBoundLayers = true;
Expand Down
10 changes: 7 additions & 3 deletions src/core/inspector/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ InspectorStats.prototype.updateStatsPanel = function(stats) {

text3 += 'Metatiles: ' + (stats.processedMetatiles) +'<br/>'+
'Metanodes: ' + (stats.processedNodes) + ' / ' + (stats.usedNodes) + '<br/>'+
'GeodataTiles: ' + (stats.drawnGeodataTiles) + '<br/><br/>' +
//'GVGeodataTiles: ' + (stats.drawnGeodataTilesPerLayer) +'<br/><br/>' +
'Tiles: ' + (stats.drawnTiles) +'<br/>';
'GeodataTiles: ' + (stats.drawnGeodataTiles) + '<br/><br/>';

if (renderer) {
text3 += 'Nodes: ' + (renderer.drawnNodes) +'<br/><br/>';
}

text3 += 'Tiles: ' + (stats.drawnTiles) +'<br/>';

for (var i =0, li = stats.renderedLods.length; i < li; i++) {
if (stats.renderedLods[i]) {
Expand Down
8 changes: 7 additions & 1 deletion src/core/map/draw-tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,20 @@ MapDrawTiles.prototype.drawTileInfo = function(tile, node, cameraPos, mesh) {

b = node.border;
if (b) {
text = '' + Math.floor(b[0]) + ' ' + Math.floor(b[1]) + ' ' + Math.floor(b[2]) + ' ' + Math.floor(b[3]) + ' ' + Math.floor(b[4]) + ' ' + Math.floor(b[5]) + ' ' + Math.floor(b[6]) + ' ' + Math.floor(b[7]) + ' ' + Math.floor(b[8]);
draw.getDrawCommandsGpuSize(tile.drawCommands[draw.drawChannel] || tile.lastRenderState.drawCommands[draw.drawChannel]); Math.floor(b[0]) + ' ' + Math.floor(b[1]) + ' ' + Math.floor(b[2]) + ' ' + Math.floor(b[3]) + ' ' + Math.floor(b[4]) + ' ' + Math.floor(b[5]) + ' ' + Math.floor(b[6]) + ' ' + Math.floor(b[7]) + ' ' + Math.floor(b[8]);
this.drawText(Math.round(pos[0]-this.getTextSize(4*factor, text)*0.5), Math.round(pos[1]+10*factor), 4*factor, text, [0,1,1,1], pos[2]);
}

//text = 'llx:' + Math.floor(node.llx) + ' lly:' + Math.floor(node.lly) + ' urx:' + Math.floor(node.urx) + ' ury:' + Math.floor(node.ury);
//this.drawText(Math.round(pos[0]-this.getTextSize(4*factor, text)*0.5), Math.round(pos[1]+3*factor), 4*factor, text, [0,1,1,1], pos[2]);
}

//draw resources
if (debug.drawResources && mesh) {
text = '' + (this.draw.getDrawCommandsGpuSize(tile.drawCommands[0] || tile.lastRenderState.drawCommands[0])/(1024*1024)).toFixed(2) + 'MB';
this.drawText(Math.round(pos[0]-this.getTextSize(4*factor, text)*0.5), Math.round(pos[1]+10*factor), 4*factor, text, [0,1,0,1], pos[2]);
}

//draw face count
if (debug.drawFaceCount && mesh) {
text = '' + mesh.faces + ' - ' + mesh.submeshes.length + ((tile.surface && tile.surface.glue) ? ' - 1' : ' - 0');
Expand Down
8 changes: 5 additions & 3 deletions src/core/map/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ var MapDraw = function(map) {
this.debug = {
heightmapOnly : false,
blendHeightmap : true,
drawBBoxes : false,
drawBBoxes : false,
drawNBBoxes : false,
drawSpaceBBox : false,
drawMeshBBox : false,
drawLods : false,
drawPositions : false,
Expand Down Expand Up @@ -745,10 +747,10 @@ MapDraw.prototype.processDrawCommands = function(cameraPos, commands, priority,
material = VTS_MATERIAL_FLAT;
break;
}
mesh.drawSubmesh(cameraPos, command.submesh, texture, material, command.alpha, command.layer, command.surface);
mesh.drawSubmesh(cameraPos, command.submesh, texture, material, command.alpha, command.layer, command.surface, tile.splitMask);
} else {
//tile.renderHappen = true;
mesh.drawSubmesh(cameraPos, command.submesh, texture, command.material, command.alpha, command.layer, command.surface);
mesh.drawSubmesh(cameraPos, command.submesh, texture, command.material, command.alpha, command.layer, command.surface, tile.splitMask);
}

}
Expand Down
65 changes: 59 additions & 6 deletions src/core/map/geodata-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import MapGeodataGeometry_ from './geodata-geometry';
import MapGeodataImportGeoJSON_ from './geodata-import/geojson';
import MapGeodataImportVTSGeodata_ from './geodata-import/vts-geodata';
import MapGeodataImport3DTiles_ from './geodata-import/3dtiles';
//import GeographicLib_ from 'geographiclib';
import {vec3 as vec3_, mat4 as mat4_,} from '../utils/matrix';

Expand All @@ -11,6 +12,8 @@ import {vec3 as vec3_, mat4 as mat4_,} from '../utils/matrix';
var MapGeodataGeometry = MapGeodataGeometry_;
var MapGeodataImportGeoJSON = MapGeodataImportGeoJSON_;
var MapGeodataImportVTSGeodata = MapGeodataImportVTSGeodata_;
var MapGeodataImport3DTiles = MapGeodataImport3DTiles_;

//var GeographicLib = GeographicLib_;
var vec3 = vec3_;
var mat4 = mat4_;
Expand All @@ -19,6 +22,7 @@ var mat4 = mat4_;
var MapGeodataBuilder = function(map) {
this.map = map;
this.groups = [];
this.nodes = [];
this.currentGroup = null;
this.bboxMin = [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY];
this.bboxMax = [Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY];
Expand Down Expand Up @@ -107,6 +111,33 @@ MapGeodataBuilder.prototype.addGroup = function(id) {
return this;
};


MapGeodataBuilder.prototype.addNode = function(parentNode, volume, precision, tileset) {
var node = {
meshes: [],
precision : precision,
volume : volume,
tileset: tileset ? true : false,
nodes : []
};

if(!parentNode) {
parentNode = this;
}

parentNode.nodes.push(node);

return node;
};


MapGeodataBuilder.prototype.addMesh = function(node, path) {
if (node) {
node.meshes.push(path);
}
};


MapGeodataBuilder.prototype.addPoint = function(point, heightMode, properties, id, srs, directCopy) {
if (!this.currentGroup) {
this.addGroup('some-group');
Expand Down Expand Up @@ -1357,7 +1388,7 @@ MapGeodataBuilder.prototype.addPolygon3 = function(shape, holes, middle, heightM
};


MapGeodataBuilder.prototype.addPolygonRAW = function(vertices, surface, borders, middle, heightMode, properties, id, srs, directCopy) {
MapGeodataBuilder.prototype.addPolygonRAW = function(vertices, surface, borders, middle, heightMode, properties, id, srs, directCopy, transform) {
if (!this.currentGroup) {
this.addGroup('some-group');
}
Expand Down Expand Up @@ -1387,10 +1418,13 @@ MapGeodataBuilder.prototype.addPolygonRAW = function(vertices, surface, borders,
} else {

for (i = 0, li = vertices.length; i < li; i+=3) {
coords = [vertices[i], vertices[i+1], vertices[i+2]];

if (directCopy) {
featureVertices[j++] = coords;
if (transform) {
featureVertices[j++] = [vertices[i]*transform.sx+transform.px, vertices[i+1]*transform.sy+transform.py, vertices[i+2]*transform.sz+transform.pz];
} else {
featureVertices[j++] = [vertices[i], vertices[i+1], vertices[i+2]];
}
} else {
featureVertices[j++] = this.physSrs.convertCoordsFrom(coords, srs);
}
Expand Down Expand Up @@ -1425,6 +1459,16 @@ MapGeodataBuilder.prototype.importGeoJson = function(json, heightMode, srs, opti
};


MapGeodataBuilder.prototype.import3DTiles = function(json, options) {
var importer = new MapGeodataImport3DTiles(this, options);
return importer.processJSON(json);
};

MapGeodataBuilder.prototype.load3DTiles = function(path, options, onLoaded) {
var importer = new MapGeodataImport3DTiles(this, options);
importer.loadJSON(path, options, onLoaded);
};

MapGeodataBuilder.prototype.processHeights = function(heightsSource, precision, onProcessed) {
if (this.heightsToProcess <= 0) {
if (onProcessed) {
Expand Down Expand Up @@ -1870,19 +1914,28 @@ MapGeodataBuilder.prototype.makeGeodata = function(resolution) {

var geodata = {
"version" : 1,
"groups" : []
"groups" : [],
}

for (var i = 0, li = this.groups.length; i < li; i++) {
geodata["groups"].push(this.compileGroup(this.groups[i], resolution));
}

if (this.nodes.length > 0) {
geodata.nodes = [];
for (i = 0, li = this.nodes.length; i < li; i++) {
geodata["nodes"].push(this.nodes[i]);
}
}

return geodata;
};


MapGeodataBuilder.prototype.makeFreeLayer = function(style, resolution) {
var geodata = this.makeGeodata(resolution);
MapGeodataBuilder.prototype.makeFreeLayer = function(style, resolution, geodata) {
if (!geodata) {
geodata = this.makeGeodata(resolution);
}

if (!style) {
style = {
Expand Down
Loading

0 comments on commit 45aa6c5

Please sign in to comment.