Skip to content

Commit

Permalink
clean up #70
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Apr 4, 2016
2 parents 0f23c14 + 33e09ce commit 79fe784
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 92 deletions.
28 changes: 25 additions & 3 deletions src/Core/Commander/Interfaces/ApiInterface/ApiGlobe.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ define('Core/Commander/Interfaces/ApiInterface/ApiGlobe', [

};

ApiGlobe.prototype.addImageryLayer = function(layer) {

var map = this.scene.getMap();
var manager = this.scene.managerCommand;
var providerWMTS = manager.getProvider(map.tiles).providerWMTS;

providerWMTS.addLayer(layer);
manager.addLayer(map.colorTerrain,providerWMTS);

};

ApiGlobe.prototype.addElevationLayer = function(layer) {

var map = this.scene.getMap();
var manager = this.scene.managerCommand;
var providerWMTS = manager.getProvider(map.tiles).providerWMTS;

providerWMTS.addLayer(layer);
manager.addLayer(map.elevationTerrain,providerWMTS);

};

ApiGlobe.prototype.createSceneGlobe = function(coordCarto) {
// TODO: Normalement la creation de scene ne doit pas etre ici....
// Deplacer plus tard
Expand All @@ -74,7 +96,7 @@ define('Core/Commander/Interfaces/ApiInterface/ApiGlobe', [

this.scene.add(map);

this.scene.addImageryLayer({
this.addImageryLayer({
protocol: "wmts",
id: "IGNPO",
url: "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
Expand Down Expand Up @@ -214,7 +236,7 @@ define('Core/Commander/Interfaces/ApiInterface/ApiGlobe', [
}
});

this.scene.addElevationLayer({
this.addElevationLayer({
protocol: "wmts",
id: "IGN_MNT",
url: "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
Expand Down Expand Up @@ -288,7 +310,7 @@ define('Core/Commander/Interfaces/ApiInterface/ApiGlobe', [
}
});

this.scene.addElevationLayer({
this.addElevationLayer({
protocol: "wmts",
id: "IGN_MNT_HIGHRES",
url: "http://wxs.ign.fr/va5orxd0pgzvq3jxutqfuy0b/geoportail/wmts",
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Commander/ManagerCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ define('Core/Commander/ManagerCommands', [
return when(0);
}

return when.all(this.arrayDeQueue(8))
return when.all(this.arrayDeQueue(16))
.then(function() {

// if (this.commandsLength() <= 8)
Expand Down
37 changes: 21 additions & 16 deletions src/Core/Commander/Providers/TileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ define('Core/Commander/Providers/TileProvider', [
'Core/Math/Ellipsoid',
'Globe/BuilderEllipsoidTile',
'Core/defaultValue',
'Scene/BoundingBox',
'three'
'Scene/BoundingBox'
],
function(
when,
Expand All @@ -38,8 +37,7 @@ define('Core/Commander/Providers/TileProvider', [
Ellipsoid,
BuilderEllipsoidTile,
defaultValue,
BoundingBox,
THREE
BoundingBox
) {

function TileProvider(size,gLDebug) {
Expand Down Expand Up @@ -105,43 +103,50 @@ define('Core/Commander/Providers/TileProvider', [
}
};

var center = new THREE.Vector3();

TileProvider.prototype.executeCommand = function(command) {

var bbox = command.paramsFunction.bbox;
var cooWMTS = this.projection.WGS84toWMTS(bbox);

// TODO not generic
var tileCoord = this.projection.WGS84toWMTS(bbox);
var parent = command.requester;

// build tile
var geometry = undefined; //getGeometry(bbox,cooWMTS);
var geometry = undefined; //getGeometry(bbox,tileCoord);

var params = {bbox:bbox,zoom:tileCoord.zoom,segment:16,center:null,projected:null}

var tile = new command.type(params,this.builder);

var tile = new command.type(bbox, cooWMTS, this.builder, this.nNode++, geometry,parent.link,center);
tile.tileCoord = tileCoord;
tile.material.setUuid(this.nNode++);
tile.link = parent.link;
tile.geometricError = Math.pow(2, (18 - tileCoord.zoom));

if (geometry) {
tile.rotation.set(0, (cooWMTS.col % 2) * (Math.PI * 2.0 / Math.pow(2, cooWMTS.zoom + 1)), 0);
tile.rotation.set(0, (tileCoord.col % 2) * (Math.PI * 2.0 / Math.pow(2, tileCoord.zoom + 1)), 0);
}

parent.worldToLocal(center);
parent.worldToLocal(params.center);

tile.position.copy(center);
tile.position.copy(params.center);
tile.setVisibility(false);

parent.add(tile);
tile.updateMatrix();
tile.updateMatrixWorld();

var elevationlayerId = command.paramsFunction.elevationLayerId[cooWMTS.zoom > 11 ? 1 : 0];
var elevationlayerId = command.paramsFunction.elevationLayerId[tileCoord.zoom > 11 ? 1 : 0];
var colorlayerId = command.paramsFunction.colorLayerId;

if(cooWMTS.zoom > 3 )
cooWMTS = undefined;
if(tileCoord.zoom > 3 )
tileCoord = undefined;

tile.texturesNeeded =+ 1;

return when.all([

this.providerElevationTexture.getElevationTexture(cooWMTS,elevationlayerId).then(function(terrain){
this.providerElevationTexture.getElevationTexture(tileCoord,elevationlayerId).then(function(terrain){

this.setTextureElevation(terrain);}.bind(tile)),

Expand Down
9 changes: 5 additions & 4 deletions src/Core/Commander/Providers/WMTS_Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ define('Core/Commander/Providers/WMTS_Provider', [

if(parent.downScaledLayer(0))
{
var layerId = command.paramsFunction.elevationLayerId[parent.cooWMTS.zoom > 11 ? 1 : 0];
var layerId = command.paramsFunction.elevationLayerId[parent.tileCoord.zoom > 11 ? 1 : 0];

return this.getElevationTexture(parent.cooWMTS,layerId).then(function(terrain)
return this.getElevationTexture(parent.tileCoord,layerId).then(function(terrain)
{
this.setTextureElevation(terrain);

Expand All @@ -233,13 +233,14 @@ define('Core/Commander/Providers/WMTS_Provider', [
WMTS_Provider.prototype.getColorTextures = function(tile,layerId) {


if (tile.cooWMTS.zoom >= 2)
if (tile.level >= 2)
{

var promises = [];
var lookAtAncestor = tile.currentLevelLayers[1] === -1;

var box = this.projection.WMTS_WGS84ToWMTS_PM(tile.cooWMTS, tile.bbox); //
// TODO not generic
var box = this.projection.WMTS_WGS84ToWMTS_PM(tile.tileCoord, tile.bbox); //
var col = box[0].col;

var colorTexturesNeeded = box[1].row + 1 - box[0].row;
Expand Down
8 changes: 4 additions & 4 deletions src/Globe/BuilderEllipsoidTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ define('Globe/BuilderEllipsoidTile',
// get center tile in cartesian 3D
BuilderEllipsoidTile.prototype.Center = function(params)
{
params.center3D = this.ellipsoid.cartographicToCartesian(new CoordCarto(params.bbox.center.x, params.bbox.center.y, 0));
return params.center3D;
params.center = this.ellipsoid.cartographicToCartesian(new CoordCarto(params.bbox.center.x, params.bbox.center.y, 0));
return params.center;
};

// get position 3D cartesian
Expand Down Expand Up @@ -83,7 +83,7 @@ define('Globe/BuilderEllipsoidTile',

var cardinals = [];

var normal = params.center3D.clone().normalize();
var normal = params.center.clone().normalize();

var phiStart = params.bbox.minCarto.longitude;
var phiLength = params.bbox.dimension.x;
Expand Down Expand Up @@ -124,7 +124,7 @@ define('Globe/BuilderEllipsoidTile',
for (var i = 0; i < cardinals.length; i++) {
cardinals3D.push(this.ellipsoid.cartographicToCartesian(cardinals[i]));
cardin3DPlane.push(tangentPlane.projectPoint(cardinals3D[i]));
vec.subVectors(cardinals3D[i], params.center3D);
vec.subVectors(cardinals3D[i], params.center);
maxHeight = Math.max(maxHeight, cardin3DPlane[i].distanceTo(vec));
cardin3DPlane[i].applyQuaternion(qRotY);
maxV.max(cardin3DPlane[i]);
Expand Down
67 changes: 28 additions & 39 deletions src/Globe/TileMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,32 @@ define('Globe/TileMesh', [
var l_ELEVATION = 0;
var l_COLOR = 1;

function TileMesh(bbox, cooWMTS, builder, id, geometryCache,link,center) {
function TileMesh(params, builder, geometryCache) {
//Constructor
NodeMesh.call(this);

this.matrixAutoUpdate = false;
this.rotationAutoUpdate = false;

this.level = cooWMTS.zoom;
this.cooWMTS = cooWMTS;
this.bbox = defaultValue(bbox, new BoundingBox());
this.id = id;
this.link = link;

var precision = 16;
var levelMax = 18;

this.geometricError = Math.pow(2, (levelMax - this.level));

var params = {bbox:this.bbox,zoom:cooWMTS.zoom,segment:precision,center3D:null,projected:null}
this.level = params.zoom;
this.bbox = defaultValue(params.bbox, new BoundingBox());

this.geometry = defaultValue(geometryCache, new TileGeometry(params, builder));
this.normal = params.center3D.clone().normalize();
this.normal = params.center.clone().normalize();

center.copy(params.center3D);
this.distance = params.center3D.length();
this.distance = params.center.length();

// TODO Why move sphere center
this.centerSphere = new THREE.Vector3().addVectors(this.geometry.boundingSphere.center, params.center3D);
this.centerSphere = new THREE.Vector3().addVectors(this.geometry.boundingSphere.center, params.center);

this.oSphere = new THREE.Sphere(this.centerSphere.clone(),this.geometry.boundingSphere.radius);

this.texturesNeeded = 0;
this.material = new LayeredMaterial(id);
this.dot = 0;
this.material = new LayeredMaterial();
this.frustumCulled = false;
this.levelElevation = this.level;

// TODO not generic
for (var i = 0; i < groupelevation.length; i++) {
var gLev = groupelevation[i];
if (this.level >= gLev) {
Expand All @@ -82,37 +71,37 @@ define('Globe/TileMesh', [
this.currentLevelLayers[l_ELEVATION] = -1;
this.currentLevelLayers[l_COLOR] = -1;

var showHelper = true;
showHelper = false;
}

TileMesh.prototype = Object.create(NodeMesh.prototype);

if (showHelper && this.level >= 2) {
TileMesh.prototype.constructor = TileMesh;

// TODO Dispose HELPER!!!
var text = (this.level + 1).toString();
TileMesh.prototype.buildHelper = function() {

if(showHelper)
this.helper = new THREE.OBBHelper(this.geometry.OBB, text);
else
this.helper = new THREE.SphereHelper(this.geometry.boundingSphere.radius);
// TODO Dispose HELPER!!!
var text = (this.level + 1).toString();

if (this.helper instanceof THREE.SphereHelper)
var showHelperBox = true;

this.helper.position.add(params.center3D);
if(showHelperBox)
this.helper = new THREE.OBBHelper(this.geometry.OBB, text);
else
this.helper = new THREE.SphereHelper(this.geometry.boundingSphere.radius);

else if (this.helper instanceof THREE.OBBHelper)
if (this.helper instanceof THREE.SphereHelper)

this.helper.translateZ(this.distance);
this.helper.position.add(new THREE.Vector3().setFromMatrixPosition(this.matrixWorld));

if(this.helper)
this.link.add(this.helper);
else if (this.helper instanceof THREE.OBBHelper)

}
this.helper.translateZ(this.distance);

}
this.link.add(this.helper);

};

TileMesh.prototype = Object.create(NodeMesh.prototype);

TileMesh.prototype.constructor = TileMesh;

TileMesh.prototype.dispose = function() {
// TODO à mettre dans node mesh
Expand Down Expand Up @@ -228,7 +217,7 @@ define('Globe/TileMesh', [
this.currentLevelLayers[l_ELEVATION] = ancestor.currentLevelLayers[l_ELEVATION];
}
else
this.currentLevelLayers[l_ELEVATION] = -2; // TODO /!\ debug but why
this.currentLevelLayers[l_ELEVATION] = -2;

} else {

Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/LayeredMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ define('Renderer/LayeredMaterial', ['THREE',
value: new THREE.Vector3(-0.5, 0.0, 1.0)
};

this.setUuid(id);
this.setUuid(id || 0);
this.wireframe = false;
//this.wireframe = true;

Expand Down
4 changes: 1 addition & 3 deletions src/Scene/BrowseTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ define('Scene/BrowseTree', ['Globe/TileMesh', 'THREE'], function( TileMesh, THRE
if(!process.isCulled(node, camera)) {
node.setVisibility(true);
process.SSE(node, camera,params);
}

if (node.isVisible())
this.uniformsProcess(node, camera);
}

return !node.material.visible && !node.wait;

Expand Down
21 changes: 0 additions & 21 deletions src/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,6 @@ define('Scene/Scene', [
this.gfxEngine.add3DScene(node.getMesh());
};

Scene.prototype.addImageryLayer = function(layer) {

var tileProvider = this.managerCommand.getProvider(this.getMap().tiles);

tileProvider.providerWMTS.addLayer(layer);

this.managerCommand.addLayer(this.getMap().colorTerrain,tileProvider.providerWMTS);

};

Scene.prototype.addElevationLayer = function(layer) {

var tileProvider = this.managerCommand.getProvider(this.getMap().tiles);

tileProvider.providerWMTS.addLayer(layer);

this.managerCommand.addLayer(this.getMap().elevationTerrain,tileProvider.providerWMTS);

};


Scene.prototype.getMap = function()
{
return this.map;
Expand Down

0 comments on commit 79fe784

Please sign in to comment.