Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions packages/Main/src/Converter/convertToTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,38 @@ export default {
hideSkirt: layer.hideSkirt,
};

return newTileGeometry(builder, paramsGeometry).then((result) => {
// build tile mesh
result.geometry.increaseRefCount();
const crsCount = layer.tileMatrixSets.length;
const material = new LayeredMaterial(layer.materialOptions, crsCount);
ReferLayerProperties(material, layer);
const { tileGeometry, quaternion: tileQuaternion, position: tilePosition } = newTileGeometry(builder, paramsGeometry);

const tile = new TileMesh(result.geometry, material, layer, extent, level);
// build tile mesh
tileGeometry.increaseRefCount();
const crsCount = layer.tileMatrixSets.length;
const material = new LayeredMaterial(layer.materialOptions, crsCount);
ReferLayerProperties(material, layer);

if (parent && parent.isTileMesh) {
// get parent extent transformation
const pTrans = builder.computeShareableExtent(parent.extent);
// place relative to his parent
result.position.sub(pTrans.position).applyQuaternion(pTrans.quaternion.invert());
result.quaternion.premultiply(pTrans.quaternion);
}
const tile = new TileMesh(tileGeometry, material, layer, extent, level);

tile.position.copy(result.position);
tile.quaternion.copy(result.quaternion);
tile.visible = false;
tile.updateMatrix();
if (parent && parent.isTileMesh) {
// get parent extent transformation
const pTrans = builder.computeShareableExtent(parent.extent);
// place relative to his parent
tilePosition.sub(pTrans.position).applyQuaternion(pTrans.quaternion.invert());
tileQuaternion.premultiply(pTrans.quaternion);
}

setTileFromTiledLayer(tile, layer);
tile.position.copy(tilePosition);
tile.quaternion.copy(tileQuaternion);
tile.visible = false;
tile.updateMatrix();

if (parent) {
tile.geoidHeight = parent.geoidHeight;
const geoidHeight = geoidLayerIsVisible(layer) ? tile.geoidHeight : 0;
tile.setBBoxZ({ min: parent.obb.z.min, max: parent.obb.z.max, geoidHeight });
tile.material.geoidHeight = geoidHeight;
}
setTileFromTiledLayer(tile, layer);

return tile;
});
if (parent) {
tile.geoidHeight = parent.geoidHeight;
const geoidHeight = geoidLayerIsVisible(layer) ? tile.geoidHeight : 0;
tile.setBBoxZ({ min: parent.obb.z.min, max: parent.obb.z.max, geoidHeight });
tile.material.geoidHeight = geoidHeight;
}

return tile;
},
};
51 changes: 21 additions & 30 deletions packages/Main/src/Core/Prefab/TileBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
index: THREE.BufferAttribute,
uv: THREE.BufferAttribute,
}>();
const cacheTile = new LRUCache<string, Promise<TileGeometry>>({ max: 500 });
const cacheTile = new LRUCache<string, TileGeometry>({ max: 500 });

export type GpuBufferAttributes = {
index: THREE.BufferAttribute | null;
Expand Down Expand Up @@ -85,13 +85,11 @@
`${builder.crs}_${params.disableSkirt ? 0 : 1}_${params.segments}`;

const key = `s${south}l${params.level}bK${bufferKey}`;
let promiseGeometry = cacheTile.get(key);
let tileGeometry = cacheTile.get(key);

// build geometry if doesn't exist
if (!promiseGeometry) {
let resolve;
promiseGeometry = new Promise((r) => { resolve = r; });
cacheTile.set(key, promiseGeometry);
if (!tileGeometry) {
cacheTile.set(key, tileGeometry);

params.extent = shareableExtent;
params.center = builder.center(params.extent).clone();
Expand All @@ -100,21 +98,18 @@
let cachedBuffers = cacheBuffer.get(bufferKey);

let buffers;
try {
buffers = computeBuffers(
builder,
params,
cachedBuffers !== undefined
? {
index: cachedBuffers.index.array as
Uint8Array | Uint16Array | Uint32Array,
uv: cachedBuffers.uv.array as Float32Array,
}
: undefined,
);
} catch (e) {
return Promise.reject(e);
}
// TODO removed a try catch here that didn't seem needed after a first quick look, but needs to be re-checked

Check warning on line 101 in packages/Main/src/Core/Prefab/TileBuilder.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

This line has a comment length of 117. Maximum allowed is 80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there's no need to add a try block. Could remove comment

buffers = computeBuffers(

Check failure on line 102 in packages/Main/src/Core/Prefab/TileBuilder.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

'buffers' is never reassigned. Use 'const' instead
builder,
params,
cachedBuffers !== undefined
? {
index: cachedBuffers.index.array as
Uint8Array | Uint16Array | Uint32Array,
uv: cachedBuffers.uv.array as Float32Array,
}
: undefined,
);

if (!cachedBuffers) {
// We know the fields will exist due to the condition
Expand Down Expand Up @@ -143,15 +138,11 @@
normal: new THREE.BufferAttribute(buffers.normal, 3),
};

const geometry = new TileGeometry(builder, params, gpuBuffers);
geometry.OBB =
new OBB(geometry.boundingBox!.min, geometry.boundingBox!.max);
geometry.initRefCount(cacheTile, key);
resolve!(geometry);

return Promise.resolve({ geometry, quaternion, position });
tileGeometry = new TileGeometry(builder, params, gpuBuffers);
tileGeometry.OBB =
new OBB(tileGeometry.boundingBox!.min, tileGeometry.boundingBox!.max);
tileGeometry.initRefCount(cacheTile, key);
}

return (promiseGeometry as Promise<TileGeometry>)
.then(geometry => ({ geometry, quaternion, position }));
return { tileGeometry, quaternion, position };
}
2 changes: 0 additions & 2 deletions packages/Main/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 DataSourceProvider from 'Provider/DataSourceProvider';
import TileProvider from 'Provider/TileProvider';
import $3dTilesProvider from 'Provider/3dTilesProvider';
import PointCloudProvider from 'Provider/PointCloudProvider';
import URLBuilder from 'Provider/URLBuilder';
Expand Down Expand Up @@ -122,7 +121,6 @@ Scheduler.prototype.constructor = Scheduler;

Scheduler.prototype.initDefaultProviders = function initDefaultProviders() {
// Register all providers
this.addProtocolProvider('tile', TileProvider);
this.addProtocolProvider('3d-tiles', $3dTilesProvider);
this.addProtocolProvider('pointcloud', PointCloudProvider);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/Main/src/Core/TileGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class TileGeometry extends THREE.BufferGeometry {
* @param keys - The [south, level, epsg] key of this geometry.
*/
public initRefCount(
cacheTile: LRUCache<string, Promise<TileGeometry>>,
cacheTile: LRUCache<string, TileGeometry>,
key: string,
): void {
if (this._refCount !== null) {
Expand Down
9 changes: 2 additions & 7 deletions packages/Main/src/Layer/LayerUpdateStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ export const STRATEGY_GROUP = 1;
export const STRATEGY_PROGRESSIVE = 2;
export const STRATEGY_DICHOTOMY = 3;

function _minimizeNetworkTraffic(node, nodeLevel, currentLevel, source) {
// TO DO source.isVectorTileSource is a temp fix for pendingSubdivision.
// see issue https://github.com/iTowns/itowns/issues/2214
if (node.pendingSubdivision && !source.isVectorTileSource) {
return currentLevel;
}
function _minimizeNetworkTraffic(node, nodeLevel) {
return nodeLevel;
}
Comment on lines -15 to 16
Copy link
Contributor

@gchoqueux gchoqueux Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method could be removed


Expand Down Expand Up @@ -74,7 +69,7 @@ export function chooseNextLevelToFetch(strategy, node, nodeLevel = node.level, c
// default strategy
case STRATEGY_MIN_NETWORK_TRAFFIC:
default:
nextLevelToFetch = _minimizeNetworkTraffic(node, nodeLevel, currentLevel, layer.source);
nextLevelToFetch = _minimizeNetworkTraffic(node, nodeLevel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove _minimizeNetworkTraffic

Suggested change
nextLevelToFetch = _minimizeNetworkTraffic(node, nodeLevel);
nextLevelToFetch = nodeLevel

}
nextLevelToFetch = Math.min(nextLevelToFetch, maxZoom);
}
Expand Down
48 changes: 9 additions & 39 deletions packages/Main/src/Layer/TiledGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,6 @@ class TiledGeometryLayer extends GeometryLayer {
if (!node.parent) {
return ObjectRemovalHelper.removeChildrenAndCleanup(this, node);
}
// early exit if parent' subdivision is in progress
if (node.parent.pendingSubdivision) {
node.visible = false;
node.material.visible = false;
this.info.update(node);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the updating info is released in each case ?

return undefined;
}

// do proper culling
node.visible = !this.culling(node, context.camera);
Expand All @@ -320,10 +313,10 @@ class TiledGeometryLayer extends GeometryLayer {
node.material.visible = true;
this.info.update(node);

if (node.pendingSubdivision || (TiledGeometryLayer.hasEnoughTexturesToSubdivide(context, node) && this.subdivision(context, this, node))) {
if (this.subdivision(context, this, node)) {
this.subdivideNode(context, node);
// display iff children aren't ready
node.material.visible = node.pendingSubdivision;
node.material.visible = false;
this.info.update(node);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.info.update(node); Could this call be written only once in this method?

requestChildrenUpdate = true;
}
Expand Down Expand Up @@ -422,39 +415,16 @@ class TiledGeometryLayer extends GeometryLayer {
* @param {Object} context - The context of the update; see the {@link
* MainLoop} for more informations.
* @param {TileMesh} node - The node to subdivide.
* @return {Promise} { description_of_the_return_value }
*/
subdivideNode(context, node) {
if (!node.pendingSubdivision && !node.children.some(n => n.layer == this)) {
if (!node.children.some(n => n.layer == this)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be could be write
if (node.children.length)Because the children can only be on the same node's layer (to be verified).

const extents = node.extent.subdivision();
// TODO: pendingSubdivision mechanism is fragile, get rid of it
node.pendingSubdivision = true;

const command = {
/* mandatory */
view: context.view,
requester: node,
layer: this,
priority: 10000,
/* specific params */
extentsSource: extents,
redraw: false,
};

return context.scheduler.execute(command).then((children) => {
for (const child of children) {
node.add(child);
child.updateMatrixWorld(true);
}

node.pendingSubdivision = false;
context.view.notifyChange(node, false);
}, (err) => {
node.pendingSubdivision = false;
if (!err.isCancelledCommandException) {
throw new Error(err);
}
});
for (const extent of extents) {
const child = this.convert(node, extent);
node.add(child);
child.updateMatrixWorld(true);
}
context.view.notifyChange(node, false);
}
}

Expand Down
21 changes: 0 additions & 21 deletions packages/Main/src/Provider/TileProvider.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/Main/src/Utils/DEMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function _readZCorrect(layer, texture, uv, tileDimensions, tileOwnerDimensions)
// 'modulo' is the gap (in [0, 1]) between 2 successive vertices in the geometry
// e.g if you have 5 vertices, the only possible values for u (or v) are: 0, 0.25, 0.5, 0.75, 1
// so modulo would be 0.25
// note: currently the number of segments is hard-coded to 16 (see TileProvider) => 17 vertices
// note: currently the number of segments is hard-coded to 16 (see TileBuilder) => 17 vertices
const modulo = (tileDimensions.x / tileOwnerDimensions.x) / (17 - 1);
let u = Math.floor(uv.x / modulo) * modulo;
let v = Math.floor(uv.y / modulo) * modulo;
Expand Down
25 changes: 3 additions & 22 deletions packages/Main/test/unit/dataSourceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { globalExtentTMS } from 'Core/Tile/TileGrid';
import OBB from 'Renderer/OBB';
import DataSourceProvider from 'Provider/DataSourceProvider';
import Fetcher from 'Provider/Fetcher';
import TileProvider from 'Provider/TileProvider';
import WMTSSource from 'Source/WMTSSource';
import WMSSource from 'Source/WMSSource';
import WFSSource from 'Source/WFSSource';
Expand Down Expand Up @@ -210,29 +209,11 @@ describe('Provide in Sources', function () {
}).catch(done);
});

it('should get 4 TileMesh from TileProvider', (done) => {
const tile = new TileMesh(geom, material, planarlayer, extent, zoom);
material.visible = true;
nodeLayer.level = EMPTY_TEXTURE_ZOOM;
tile.parent = { };

planarlayer.subdivideNode(context, tile);
TileProvider.executeCommand(context.scheduler.commands[0])
.then((tiles) => {
assert.equal(tiles.length, 4);
assert.equal(tiles[0].extent.west, tile.extent.east * 0.5);
assert.equal(tiles[0].extent.east, tile.extent.east);
assert.equal(tiles[0].extent.north, tile.extent.north);
assert.equal(tiles[0].extent.south, tile.extent.north * 0.5);
done();
}).catch(done);
});

it('should get 3 meshs with WFS source and DataSourceProvider', (done) => {
const tile = new TileMesh(geom, material, planarlayer, extent, featureLayer.zoom.min);
material.visible = true;
nodeLayer.level = EMPTY_TEXTURE_ZOOM;
tile.parent = { pendingSubdivision: false };
tile.parent = {};
featureLayer.mergeFeatures = false;
tile.layerUpdateState = { test: new LayerUpdateState() };

Expand All @@ -254,7 +235,7 @@ describe('Provide in Sources', function () {
extent,
featureLayer.zoom.min);
tile.material.visible = true;
tile.parent = { pendingSubdivision: false };
tile.parent = {};
featureLayer.source.uid = 8;
featureLayer.mergeFeatures = true;
featureLayer.cache.clear();
Expand All @@ -279,7 +260,7 @@ describe('Provide in Sources', function () {
extent,
zoom);
material.visible = true;
tile.parent = { pendingSubdivision: false };
tile.parent = {};
nodeLayer.level = EMPTY_TEXTURE_ZOOM;
tile.material.visible = true;
featureLayer.source.uid = 22;
Expand Down
Loading
Loading