Spread config node in normalisation + types
This commit is contained in:
@@ -282,6 +282,10 @@ Scene.loadNodes = function (nodes) {
|
|||||||
AppState.clipping.boundingSphere = node.getBound();
|
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});
|
AppState.nodes.push({id: n.label, active: true});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
14
js/state.js
14
js/state.js
@@ -1,6 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* @namespace AppState
|
* @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 = {
|
let AppState = {
|
||||||
// The Leaflet map object
|
// The Leaflet map object
|
||||||
map : null,
|
map : null,
|
||||||
@@ -8,6 +19,9 @@ let AppState = {
|
|||||||
root: null,
|
root: null,
|
||||||
// {id: String, active: Boolean}
|
// {id: String, active: Boolean}
|
||||||
nodes: [],
|
nodes: [],
|
||||||
|
/**
|
||||||
|
* @property {NormalizedSceneNode[]} normalizedNodes
|
||||||
|
*/
|
||||||
normalizedNodes: [],
|
normalizedNodes: [],
|
||||||
mainNodeId: null,
|
mainNodeId: null,
|
||||||
currentScene: 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 {SceneNode} node
|
||||||
* @param {Object[]} flatList
|
* @param {Array} flatList
|
||||||
* @param {Number} depth
|
* @param {Number} depth
|
||||||
*/
|
*/
|
||||||
function traverse(node, flatList, depth = 1) {
|
function traverse(node, flatList, depth = 1) {
|
||||||
|
if (!node.label) {
|
||||||
|
console.error("Node missing label:", node);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const normNode = {
|
const normNode = {
|
||||||
id: node.label,
|
...node,
|
||||||
label: node.label,
|
id: node.id ?? node.label,
|
||||||
opacity: node.opacity ?? null,
|
|
||||||
isMain: node.isMain ?? false,
|
isMain: node.isMain ?? false,
|
||||||
active: true,
|
active: true,
|
||||||
};
|
};
|
||||||
@@ -23,7 +47,7 @@ function traverse(node, flatList, depth = 1) {
|
|||||||
...normNode,
|
...normNode,
|
||||||
depth
|
depth
|
||||||
});
|
});
|
||||||
if (node.children) {
|
if (node.children && Array.isArray(node.children)) {
|
||||||
for(let child of node.children) {
|
for(let child of node.children) {
|
||||||
traverse(child, flatList, depth + 1);
|
traverse(child, flatList, depth + 1);
|
||||||
}
|
}
|
||||||
@@ -34,7 +58,7 @@ function traverse(node, flatList, depth = 1) {
|
|||||||
* Create a flat list of nodes from
|
* Create a flat list of nodes from
|
||||||
* the nested structure in config
|
* the nested structure in config
|
||||||
* @param {Array} nodes
|
* @param {Array} nodes
|
||||||
* @returns {Object[]} A flat list of nodes
|
* @returns {NormalizedSceneNode[]} A flat list of nodes
|
||||||
**/
|
**/
|
||||||
export function normalizeNodes (nodes) {
|
export function normalizeNodes (nodes) {
|
||||||
let flatList = [];
|
let flatList = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user