Skip to content

Commit

Permalink
Remove tile Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Jul 19, 2018
1 parent bdb6a2f commit eab0d23
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 123 deletions.
6 changes: 5 additions & 1 deletion src/Core/Prefab/GlobeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { globeCulling, preGlobeUpdate, globeSubdivisionControl, globeSchemeTileW
import BuilderEllipsoidTile from './Globe/BuilderEllipsoidTile';
import SubdivisionControl from '../../Process/SubdivisionControl';
import Picking from '../Picking';
import convertToTile from '../../Parser/convertToTile';
import tiledMeshLayer from './tiledMeshLayer';

/**
* Fires when the view is completely loaded. Controls and view's functions can be called then.
Expand Down Expand Up @@ -272,7 +274,9 @@ function GlobeView(viewerDiv, coordCarto, options = {}) {

this.addEventListener(VIEW_EVENTS.LAYERS_INITIALIZED, fn);

this.notifyChange(this.wgs84TileLayer);
tiledMeshLayer.buildRootTile(wgs84TileLayer, this, this.mainLoop.scheduler);

wgs84TileLayer.convert = convertToTile.convert;
}

GlobeView.prototype = Object.create(View.prototype);
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Prefab/PlanarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { planarCulling, planarSubdivisionControl, prePlanarUpdate } from '../../
import PlanarTileBuilder from './Planar/PlanarTileBuilder';
import SubdivisionControl from '../../Process/SubdivisionControl';
import Picking from '../Picking';
import convertToTile from '../../Parser/convertToTile';
import tiledMeshLayer from './tiledMeshLayer';

export function createPlanarLayer(id, extent, options) {
const tileLayer = new GeometryLayer(id, options.object3d || new THREE.Group());
Expand Down Expand Up @@ -135,6 +137,10 @@ function PlanarView(viewerDiv, extent, options = {}) {
});

this.tileLayer = tileLayer;

tiledMeshLayer.buildRootTile(tileLayer, this, this.mainLoop.scheduler);

tileLayer.convert = convertToTile.convert;
}

PlanarView.prototype = Object.create(View.prototype);
Expand Down
27 changes: 27 additions & 0 deletions src/Core/Prefab/tiledMeshLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { requestNewTile } from '../../Process/TiledNodeProcessing';

// TODO: move to tiledMeshLayer class constructor,
// when it will be created
export default {
buildRootTile(tiledMeshLayer, view, scheduler) {
if (!tiledMeshLayer.schemeTile) {
throw new Error(`Cannot init tiled layer without schemeTile for layer ${tiledMeshLayer.id}`);
}

tiledMeshLayer.level0Nodes = [];
tiledMeshLayer.onTileCreated = tiledMeshLayer.onTileCreated || (() => {});

const promises = [];

for (const root of tiledMeshLayer.schemeTile) {
promises.push(requestNewTile(view, scheduler, tiledMeshLayer, root));
}
tiledMeshLayer.whenReady = Promise.all(promises).then((level0s) => {
tiledMeshLayer.level0Nodes = level0s;
for (const level0 of level0s) {
tiledMeshLayer.object3d.add(level0);
level0.updateMatrixWorld();
}
});
},
};
3 changes: 1 addition & 2 deletions src/Core/Scheduler/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import PriorityQueue from 'js-priority-queue';
import extendedDataProvider from '../../Provider/extendedDataProvider';
import TileProvider from '../../Provider/TileProvider';
import $3dTilesProvider from '../../Provider/3dTilesProvider';
import PointCloudProvider from '../../Provider/PointCloudProvider';
import CancelledCommandException from './CancelledCommandException';
Expand Down Expand Up @@ -134,7 +133,7 @@ Scheduler.prototype.initDefaultProviders = function initDefaultProviders() {
this.addProtocolProvider('xyz', extendedDataProvider);
this.addProtocolProvider('wfs', extendedDataProvider);
this.addProtocolProvider('file', extendedDataProvider);
this.addProtocolProvider('tile', TileProvider);
this.addProtocolProvider('tile', extendedDataProvider);
this.addProtocolProvider('3d-tiles', $3dTilesProvider);
this.addProtocolProvider('potreeconverter', PointCloudProvider);
};
Expand Down
77 changes: 77 additions & 0 deletions src/Parser/convertToTile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import * as THREE from 'three';
import TileGeometry from '../Core/TileGeometry';
import TileMesh from '../Core/TileMesh';
import LayeredMaterial from '../Renderer/LayeredMaterial';
import Cache from '../Core/Scheduler/Cache';

export default {
convert(data, extent, layer, requester) {
const builder = layer.builder;
const parent = requester;
const level = (parent !== undefined) ? (parent.level + 1) : 0;

const { sharableExtent, quaternion, position } = builder.computeSharableExtent(extent);
const south = sharableExtent.south().toFixed(6);
const segment = layer.segments || 16;
const key = `${builder.type}_${layer.disableSkirt ? 0 : 1}_${segment}_${level}_${south}`;

let geometry = Cache.get(key);
// build geometry if doesn't exist
if (!geometry) {
const paramsGeometry = {
extent: sharableExtent,
level,
segment,
disableSkirt: layer.disableSkirt,
};

geometry = new TileGeometry(paramsGeometry, builder);
Cache.set(key, geometry);

geometry._count = 0;
geometry.dispose = () => {
geometry._count--;
if (geometry._count == 0) {
THREE.BufferGeometry.prototype.dispose.call(geometry);
Cache.delete(key);
}
};
}

// build tile
geometry._count++;
const material = new LayeredMaterial(layer.materialOptions);
const tile = new TileMesh(layer, geometry, material, extent, level);
// TODO semble ne pas etre necessaire
tile.layers.set(layer.threejsLayer);

if (parent && parent instanceof TileMesh) {
// get parent extent transformation
const pTrans = builder.computeSharableExtent(parent.extent);
// place relative to his parent
position.sub(pTrans.position).applyQuaternion(pTrans.quaternion.inverse());
quaternion.premultiply(pTrans.quaternion);
}

tile.position.copy(position);
tile.quaternion.copy(quaternion);

tile.material.transparent = layer.opacity < 1.0;
tile.material.uniforms.opacity.value = layer.opacity;
tile.setVisibility(false);
tile.updateMatrix();

if (parent) {
tile.setBBoxZ(parent.OBB().z.min, parent.OBB().z.max);
} else if (layer.materialOptions && layer.materialOptions.useColorTextureElevation) {
tile.setBBoxZ(layer.materialOptions.colorTextureElevationMinZ, layer.materialOptions.colorTextureElevationMaxZ);
}

return Promise.resolve(tile);
},
};
2 changes: 1 addition & 1 deletion src/Process/PlanarTileProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function prePlanarUpdate(context, layer) {
const elevationLayers = context.view.getLayers((l, a) => a && a.id == layer.id && l.type == 'elevation');
context.maxElevationLevel = -1;
for (const e of elevationLayers) {
context.maxElevationLevel = Math.max(e.options.zoom.max, context.maxElevationLevel);
context.maxElevationLevel = Math.max(e.source.zoom.max, context.maxElevationLevel);
}
if (context.maxElevationLevel == -1) {
context.maxElevationLevel = Infinity;
Expand Down
6 changes: 2 additions & 4 deletions src/Process/TiledNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ function subdivisionExtents(bbox) {
return [northWest, northEast, southWest, southEast];
}

export function requestNewTile(view, scheduler, geometryLayer, extent, parent, level) {
export function requestNewTile(view, scheduler, geometryLayer, extent, parent) {
const command = {
/* mandatory */
view,
requester: parent,
layer: geometryLayer,
priority: 10000,
/* specific params */
extent,
level,
extents: [extent],
redraw: false,
threejsLayer: geometryLayer.threejsLayer,
};

return scheduler.execute(command).then((node) => {
Expand Down
110 changes: 0 additions & 110 deletions src/Provider/TileProvider.js

This file was deleted.

23 changes: 18 additions & 5 deletions src/Provider/extendedDataProvider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import GeoJsonParser from '../Parser/GeoJsonParser';
import Fetcher from './Fetcher';
import Cache from '../Core/Scheduler/Cache';
import CancelledCommandException from '../Core/Scheduler/CancelledCommandException';

const supportedFormats = new Map([
['image/png', Fetcher.texture],
Expand Down Expand Up @@ -36,13 +37,25 @@ export default {
const promises = [];
const layer = command.layer;
const source = layer.source;
const requester = command.requester;

if (requester &&
!requester.material) {
// request has been deleted
return Promise.reject(new CancelledCommandException(command));
}

for (const extent of command.extents) {
const url = source.urlFromExtent(extent);
const tag = source.data ?
`${url},${extent.east()},${extent.north()},${extent.west()},${extent.south()}` : url;
if (source) {
const url = source.urlFromExtent(extent);
const tag = source.data ?
`${url},${extent.east()},${extent.north()},${extent.west()},${extent.south()}` : url;

promises.push((Cache.get(tag) || Cache.set(tag, getExtentedData(source, url, command.dataSourceParent)
.then(data => layer.convert(data, extent, layer)), Cache.POLICIES.TEXTURE)));
promises.push((Cache.get(tag) || Cache.set(tag, getExtentedData(source, url, command.dataSourceParent)
.then(data => layer.convert(data, extent, layer)), Cache.POLICIES.TEXTURE)));
} else {
return layer.convert({}, extent, layer, requester);
}
}

return Promise.all(promises);
Expand Down

0 comments on commit eab0d23

Please sign in to comment.