diff --git a/js/scene.js b/js/scene.js index bc1860b..86da6b2 100644 --- a/js/scene.js +++ b/js/scene.js @@ -282,6 +282,10 @@ Scene.loadNodes = function (nodes) { AppState.clipping.boundingSphere = node.getBound(); } + if (!AppState.clipping.boundingSphere) { + console.error("There is no computed bounding sphere, clipping will fail. Missing main node?"); + } + AppState.nodes.push({id: n.label, active: true}); }); } diff --git a/js/state.js b/js/state.js index 6f46dae..7300779 100644 --- a/js/state.js +++ b/js/state.js @@ -1,6 +1,17 @@ /** * @namespace AppState */ + +/** + * @typedef {Object} NormalizedSceneNode + * @property {String} label Required + * @property {String} id + * @property {String} model + * @property {Boolean} isMain + * @property {Number|null} opacity + * @property {Boolean} active + */ + let AppState = { // The Leaflet map object map : null, @@ -8,6 +19,9 @@ let AppState = { root: null, // {id: String, active: Boolean} nodes: [], + /** + * @property {NormalizedSceneNode[]} normalizedNodes + */ normalizedNodes: [], mainNodeId: null, currentScene: null, diff --git a/js/utils/nodeUtils.js b/js/utils/nodeUtils.js index 20a19cf..2158066 100644 --- a/js/utils/nodeUtils.js +++ b/js/utils/nodeUtils.js @@ -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 = [];