Node group colors and toggling (draft)

This commit is contained in:
2026-05-14 16:32:06 +02:00
parent 589b551558
commit 87245233b7
7 changed files with 82 additions and 19 deletions

View File

@@ -28,41 +28,49 @@
* @param {Array} flatList
* @param {Number} depth
*/
function traverse(node, flatList, depth = 1) {
function traverseTree(node, flatList, depth = 1, inheritedColor = null) {
if (!node.label) {
console.error("Node missing label:", node);
return;
}
const color = node.color ?? inheritedColor;
const normNode = {
...node,
id: node.id ?? node.label,
isMain: node.isMain ?? false,
active: true,
color: color ?? null,
depth,
children: [],
};
if (node.model) {
normNode.model = node.model;
}
flatList.push({
...normNode,
depth
});
flatList.push(normNode);
if (node.children && Array.isArray(node.children)) {
for(let child of node.children) {
traverse(child, flatList, depth + 1);
for(const child of node.children) {
normNode.children.push(
traverseTree(child, flatList, depth + 1, color)
);
}
}
return normNode;
}
/**
* Create a flat list of nodes from
* the nested structure in config
* @param {Array} nodes
* @returns {NormalizedSceneNode[]} A flat list of nodes
* @returns {{flat: NormalizedSceneNode[], normNode: object}} A flat list of nodes
**/
export function normalizeNodes (nodes) {
let flatList = [];
traverse(nodes, flatList);
const normNode = traverseTree(nodes, flatList);
return flatList;
return {flat: flatList, normNode};
}