Skip to content

Commit

Permalink
refactor(TileMesh): new structuring of the data linked to the node.
Browse files Browse the repository at this point in the history
All linked/attached layer data are organized by layer ID.
  • Loading branch information
gchoqueux committed Mar 15, 2023
1 parent 606b6b8 commit 05eb368
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Core/TileMesh.js
Expand Up @@ -47,7 +47,7 @@ class TileMesh extends THREE.Mesh {

this.geoidHeight = 0;

this.link = [];
this.link = {};
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/Process/FeatureProcessing.js
Expand Up @@ -21,12 +21,10 @@ export default {
node.layerUpdateState[layer.id] = new LayerUpdateState();
} else if (!node.layerUpdateState[layer.id].canTryUpdate()) {
// toggle visibility features
node.link.forEach((f) => {
if (f.layer?.id == layer.id) {
f.layer.object3d.add(f);
f.meshes.position.z = geoidLayerIsVisible(layer.parent) ? node.geoidHeight : 0;
f.meshes.updateMatrixWorld();
}
node.link[layer.id]?.forEach((f) => {
f.layer.object3d.add(f);
f.meshes.position.z = geoidLayerIsVisible(layer.parent) ? node.geoidHeight : 0;
f.meshes.updateMatrixWorld();
});
return;
}
Expand Down Expand Up @@ -60,6 +58,7 @@ export default {

featureMeshes.forEach((featureMesh) => {
if (featureMesh) {
node.link[layer.id] = node.link[layer.id] || [];
featureMesh.as(context.view.referenceCrs);
featureMesh.meshes.position.z = geoidLayerIsVisible(layer.parent) ? node.geoidHeight : 0;
featureMesh.updateMatrixWorld();
Expand All @@ -73,7 +72,7 @@ export default {
ObjectRemovalHelper.removeChildrenAndCleanupRecursively(layer, featureMesh);
} else {
layer.object3d.add(featureMesh);
node.link.push(featureMesh);
node.link[layer.id].push(featureMesh);
}
featureMesh.layer = layer;
} else {
Expand Down
10 changes: 4 additions & 6 deletions src/Process/ObjectRemovalHelper.js
Expand Up @@ -83,12 +83,10 @@ export default {
// Objects are filtered by id because the obj hierarchy may also contain labels that have been added as childs
// of the objects which have their own removal logic
let toRemove = obj.children.filter(c => c.layer && c.layer.id === layer.id);
if (obj.link) {
const linkedObjects = obj.link.filter(c => c.layer && c.layer.id === layer.id);
if (linkedObjects.length) {
toRemove = toRemove.concat(linkedObjects);
obj.link = obj.link.filter(c => c.layer && c.layer.id !== layer.id);
}
const linked = obj.link && obj.link[layer.id];
if (linked?.children.length) {
toRemove = toRemove.concat(linked.children);
delete obj.link[layer.id];
}
for (const c of toRemove) {
this.removeChildrenAndCleanupRecursively(layer, c);
Expand Down
4 changes: 2 additions & 2 deletions utils/debug/TileDebug.js
Expand Up @@ -122,7 +122,7 @@ export default function createTileDebugUI(datDebugTool, view, layer, debugInstan
}

// filtering helper attached to node with the current debug layer
let helper = node.link.filter(n => n.layer && (n.layer.id == layer.id))[0];
let helper = node.link[layer.id];
if (node.visible && node.material && node.material.visible) {
if (!helper) {
helper = new THREE.Group();
Expand All @@ -144,7 +144,7 @@ export default function createTileDebugUI(datDebugTool, view, layer, debugInstan
helper.add(sphereHelper);
}

node.link.push(helper);
node.link[layer.id] = helper;
}

layer.object3d.add(helper);
Expand Down

0 comments on commit 05eb368

Please sign in to comment.