Created
November 9, 2020 19:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as THREE from 'https://unpkg.com/[email protected]/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