Skip to content

Commit

Permalink
Merge pull request #104 from DavidLevinsky/master
Browse files Browse the repository at this point in the history
Fixed view switching
  • Loading branch information
davidmtech authored May 31, 2018
2 parents e9360a2 + ec5425d commit 3cc76a6
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 101 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.15.7",
"version": "2.15.8",
"description": "JavaScript WebGL 3D maps rendering engine",
"main": "src/browser/index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var Core = function(element, config, coreInterface) {
mapFog : true,
mapNoTextures: false,
mapMetricUnits : !(lang == 'en' || lang.indexOf('en-') == 0),
rendererAnisotropic : 0,
rendererAntialiasing : true,
rendererAllowScreenshots : false,
inspector : true,
Expand Down Expand Up @@ -471,6 +472,7 @@ Core.prototype.getConfigParam = function(key) {

Core.prototype.setRendererConfigParam = function(key, value) {
switch (key) {
case 'rendererAnisotropic': this.config.rendererAnisotropic = utils.validateNumber(value, -1, 2048, 0); break;
case 'rendererAntialiasing': this.config.rendererAntialiasing = utils.validateBool(value, true); break;
case 'rendererAllowScreenshots': this.config.rendererAllowScreenshots = utils.validateBool(value, false); break;
}
Expand All @@ -479,6 +481,7 @@ Core.prototype.setRendererConfigParam = function(key, value) {

Core.prototype.getRendererConfigParam = function(key) {
switch (key) {
case 'rendererAnisotropic': return this.config.rendererAnisotropic;
case 'rendererAntialiasing': return this.config.rendererAntialiasing;
case 'rendererAllowScreenshots': return this.config.rendererAllowScreenshots;
}
Expand All @@ -491,7 +494,7 @@ string getCoreVersion()
*/

function getCoreVersion(full) {
return (full ? 'Core: ' : '') + '2.15.7';
return (full ? 'Core: ' : '') + '2.15.8';
}


Expand Down
87 changes: 55 additions & 32 deletions src/core/map/draw-tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ MapDrawTiles.prototype.drawSurfaceTile = function(tile, node, cameraPos, pixelSi
}
return true;
}

//tile.renderHappen = false;

if (!preventRedener) {
this.stats.renderedLods[tile.id[0]]++;
Expand Down Expand Up @@ -116,7 +118,7 @@ MapDrawTiles.prototype.drawSurfaceTile = function(tile, node, cameraPos, pixelSi
} else {
if (!preventRedener && tile.lastRenderState) {
var channel = this.draw.drawChannel;
this.draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true);
this.draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true, tile);
this.map.applyCredits(tile);
return true;
}
Expand All @@ -141,42 +143,46 @@ MapDrawTiles.prototype.drawMeshTile = function(tile, node, cameraPos, pixelSize,
var channel = draw.drawChannel;
var ret = false;

//we have commnad so we can draw them
if (tile.drawCommands[channel].length > 0 && this.draw.areDrawCommandsReady(tile.drawCommands[channel], priority, preventLoad, doNotCheckGpu)) {
if (!preventRedener) {
draw.processDrawCommands(cameraPos, tile.drawCommands[channel], priority);
draw.processDrawCommands(cameraPos, tile.drawCommands[channel], priority, null, tile);
this.map.applyCredits(tile);
}
tile.lastRenderState = null;
return true;
} else if (tile.lastRenderState){
} else if (tile.lastRenderState){ //we do not have cammnds or command are not redy yet, so we can draw last state if present and ready

if (tile.surfaceMesh.isReady(true, priority, doNotCheckGpu)) {
if (tile.drawCommands[channel].length > 0) {
if (tile.surfaceMesh.isReady(true, priority, doNotCheckGpu) && tile.drawCommands[channel].length > 0) {
if (this.draw.areDrawCommandsReady(tile.lastRenderState.drawCommands[channel], priority, preventLoad, doNotCheckGpu)) {
if (!preventRedener) {
draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true);
draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true, tile);
this.map.applyCredits(tile);
}
return true;
}
return true; // commands are generated so we can return from function here
} // else ret = false
} else {
if (!preventRedener) {
draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true);
this.map.applyCredits(tile);
if (this.draw.areDrawCommandsReady(tile.lastRenderState.drawCommands[channel], priority, preventLoad, doNotCheckGpu)) {
if (!preventRedener) {
draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true, tile);
this.map.applyCredits(tile);
}
ret = true;
}
ret = true;
}
}
if (tile.drawCommands[channel].length > 0) {

if (tile.drawCommands[channel].length > 0) { //command are generated but not ready, we can return from the function
if (this.config.mapHeightfiledWhenUnloaded && !preventRedener) {
//node.drawPlane(cameraPos, tile);
tile.drawGrid(cameraPos);
return false;
} else {
return false;
}
}

// information about support for extarnal or internal textures are present in the mesh,
// so we have to wait until is mesh ready and then we can generate commands
if (tile.surfaceMesh.isReady(preventLoad, priority, doNotCheckGpu) && !preventLoad) {
var submeshes = tile.surfaceMesh.submeshes;

Expand Down Expand Up @@ -447,6 +453,20 @@ MapDrawTiles.prototype.drawMeshTile = function(tile, node, cameraPos, pixelSize,

}

if (surface.pipeline > VTS_PIPELINE_BASIC) {
this.updateTileHmap(tile, node);

for (j = 0; j < 2; j++) {
var commands = tile.drawCommands[j];
for (i = 0, li = commands.length; i < li; i++) {
if (commands[i].type == VTS_DRAWCOMMAND_SUBMESH) {
commands[i].pipeline = surface.pipeline;
commands[i].hmap = tile.hmap;
}
}
}
}

if (tile.resetDrawCommands) {
return false;
}
Expand All @@ -458,18 +478,20 @@ MapDrawTiles.prototype.drawMeshTile = function(tile, node, cameraPos, pixelSize,
}

if (!preventRedener) {
draw.processDrawCommands(cameraPos, tile.drawCommands[channel], priority);
draw.processDrawCommands(cameraPos, tile.drawCommands[channel], priority, null, tile);
this.map.applyCredits(tile);
}

tile.lastRenderState = null;
ret = true;
} else if (tile.lastRenderState) {
if (!preventRedener) {
draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true);
this.map.applyCredits(tile);
}
ret = true;
if (this.draw.areDrawCommandsReady(tile.lastRenderState.drawCommands[channel], priority, preventLoad, doNotCheckGpu)) {
if (!preventRedener) {
draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true, tile);
this.map.applyCredits(tile);
}
ret = true;
} //else ret = false
} else {
if (this.config.mapHeightfiledWhenUnloaded && !preventRedener) {
//node.drawPlane(cameraPos, tile);
Expand All @@ -480,12 +502,11 @@ MapDrawTiles.prototype.drawMeshTile = function(tile, node, cameraPos, pixelSize,

} else {

if (this.config.mapHeightfiledWhenUnloaded && !preventRedener) {
if (!tile.lastRenderState && this.config.mapHeightfiledWhenUnloaded && !preventRedener) {
//node.drawPlane(cameraPos, tile);
tile.drawGrid(cameraPos);
ret = !(tile.drawCommands[channel].length > 0);
}

}
}

return ret;
Expand Down Expand Up @@ -539,7 +560,7 @@ MapDrawTiles.prototype.drawGeodataTile = function(tile, node, cameraPos, pixelSi

if (tile.drawCommands[channel].length > 0 && this.draw.areDrawCommandsReady(tile.drawCommands[channel], priority, preventLoad, doNotCheckGpu)) {
if (!preventRedener) {
this.draw.processDrawCommands(cameraPos, tile.drawCommands[channel], priority);
this.draw.processDrawCommands(cameraPos, tile.drawCommands[channel], priority, null, tile);
this.map.applyCredits(tile);
}
tile.lastRenderState = null;
Expand All @@ -551,14 +572,14 @@ MapDrawTiles.prototype.drawGeodataTile = function(tile, node, cameraPos, pixelSi
if (tile.surfaceGeodata.isReady(true, priority, doNotCheckGpu) {
if (tile.drawCommands[channel].length > 0) {
if (!preventRedener) {
this.draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true);
this.draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true, tile);
this.applyCredits(tile);
}
return;
}
} else {
if (!preventRedener) {
this.draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true);
this.draw.processDrawCommands(cameraPos, tile.lastRenderState.drawCommands[channel], priority, true, tile);
this.applyCredits(tile);
}
}
Expand Down Expand Up @@ -594,12 +615,14 @@ MapDrawTiles.prototype.drawGeodataTile = function(tile, node, cameraPos, pixelSi
};



/*MapDrawTiles.prototype.updateTileBoundsDirectly = function(preventLoad, priority) {
if (tile.surfaceMesh.isReady(preventLoad, priority) && !preventLoad) {
this.updateTileBounds(tile, tile.surfaceMesh.submeshes);
MapDrawTiles.prototype.updateTileHmap = function(tile, node) {
if (node && node.hasNavtile() && tile.surface) {
var path = tile.surface.getNavUrl(tile.id);
this.hmap = tile.resources.getTexture(path, null, null, null, tile, true);
} else {
this.hmap = this.renderer.blackTexture;
}
};*/
};


MapDrawTiles.prototype.updateTileBounds = function(tile, submeshes) {
Expand Down
23 changes: 16 additions & 7 deletions src/core/map/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,11 @@ MapDraw.prototype.areDrawCommandsReady = function(commands, priority, doNotLoad,
};


MapDraw.prototype.processDrawCommands = function(cameraPos, commands, priority, doNotLoad) {
MapDraw.prototype.processDrawCommands = function(cameraPos, commands, priority, doNotLoad, tile) {
if (commands.length > 0) {
this.drawTileCounter++;
}

for (var i = 0, li = commands.length; i < li; i++) {
var command = commands[i];

Expand All @@ -625,15 +625,25 @@ MapDraw.prototype.processDrawCommands = function(cameraPos, commands, priority,

case VTS_DRAWCOMMAND_SUBMESH:
var mesh = command.mesh;
var texture = command.texture;
var texture = command.texture, hmap;

var meshReady = (mesh && mesh.isReady(doNotLoad, priority)), textureReady;

if (this.config.mapNoTextures) {
textureReady = true;
texture = null;
} else {
textureReady = (!texture || (texture && texture.isReady(doNotLoad, priority)));
textureReady = (!texture || (texture && texture.isReady(doNotLoad, priority)));
}

var pipeline = command.pipeline;

if (pipeline) {
//hmap = command.hmap;
//textureReady = (textureReady && (hmap && hmap.isReady(doNotLoad, priority)));

tile.drawHmapTile(cameraPos, null, null, pipeline);
return;
}

if (meshReady && textureReady) {
Expand All @@ -653,19 +663,18 @@ MapDraw.prototype.processDrawCommands = function(cameraPos, commands, priority,
}
mesh.drawSubmesh(cameraPos, command.submesh, texture, material, command.alpha);
} else {
//tile.renderHappen = true;
mesh.drawSubmesh(cameraPos, command.submesh, texture, command.material, command.alpha);
}

} else {
//i = i;
//this should not happen
}

break;

case VTS_DRAWCOMMAND_GEODATA:

var geodataView = command.geodataView;
//tile.renderHappen = true;

if (geodataView && geodataView.isReady(doNotLoad, priority, true)) {
geodataView.draw(cameraPos);
Expand Down
Loading

0 comments on commit 3cc76a6

Please sign in to comment.