Skip to content

Instantly share code, notes, and snippets.

@nbogie
Created November 9, 2020 19:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nbogie/10b857545aeb9e781c80d0da1bc2609b to your computer and use it in GitHub Desktop.
utility functions to report structure of scene / sub-scene to console, for three.js (at least for gltf-loaded-models). by@greggman https://threejsfundamentals.org/threejs/lessons/threejs-load-gltf.html
import * as THREE from 'https://unpkg.com/three@0.122.0/build/three.module.js';
function dumpObjectToTextLines(obj, lines = [], isLast = true, prefix = '') {
if (!obj || !obj.children) {
return lines;
}
const localPrefix = isLast ? '└─' : '├─';
lines.push(`${prefix}${prefix ? localPrefix : ''}${obj.name || '*no-name*'} [${obj.type}]`);
const newPrefix = prefix + (isLast ? ' ' : '│ ');
const lastNdx = obj.children.length - 1;
obj.children.forEach((child, ndx) => {
const isLast = ndx === lastNdx;
dumpObjectToTextLines(child, lines, isLast, newPrefix);
});
return lines;
}
export function dumpObjectToConsoleAsString(root) {
console.log(dumpObjectToTextLines(root).join("\n"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment