Spread config node in normalisation + types
This commit is contained in:
@@ -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});
|
||||
});
|
||||
}
|
||||
|
||||
14
js/state.js
14
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,
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user