Created
November 9, 2020 19:39
Star
You must be signed in to star a gist
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 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/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