Spread config node in normalisation + types

This commit is contained in:
2026-04-07 13:05:48 +02:00
parent a3ca2eb372
commit 39c3b1b537
3 changed files with 50 additions and 8 deletions

View File

@@ -1,18 +1,42 @@
/**
* @module
* @module nodeUtils
* Utilities to process scene nodes.
*/
/**
* @typedef {Object} SceneNode
* @property {String} label Required
* @property {String} model
* @property {Boolean} isMain
* @property {Number|null} opacity
* @property {SceneNode[]|null} children
*/
/**
* @typedef {Object} NormalizedSceneNode
* @property {String} label Required
* @property {String} id
* @property {String} model
* @property {Boolean} isMain
* @property {Number|null} opacity
* @property {Boolean} active
*/
/**
*
* @param {Object} node
* @param {Object[]} flatList
* @param {SceneNode} node
* @param {Array} flatList
* @param {Number} depth
*/
function traverse(node, flatList, depth = 1) {
if (!node.label) {
console.error("Node missing label:", node);
return;
}
const normNode = {
id: node.label,
label: node.label,
opacity: node.opacity ?? null,
...node,
id: node.id ?? node.label,
isMain: node.isMain ?? false,
active: true,
};
@@ -23,7 +47,7 @@ function traverse(node, flatList, depth = 1) {
...normNode,
depth
});
if (node.children) {
if (node.children && Array.isArray(node.children)) {
for(let child of node.children) {
traverse(child, flatList, depth + 1);
}
@@ -34,7 +58,7 @@ function traverse(node, flatList, depth = 1) {
* Create a flat list of nodes from
* the nested structure in config
* @param {Array} nodes
* @returns {Object[]} A flat list of nodes
* @returns {NormalizedSceneNode[]} A flat list of nodes
**/
export function normalizeNodes (nodes) {
let flatList = [];