@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
15 lines (13 loc) • 456 B
text/typescript
import {Object3D} from 'three';
type Callback = (object: Object3D) => void;
// this is a safer traversal, which does not break when children are removed within the callback
export function hierarchyTraverse(object: Object3D, callback: Callback) {
callback(object);
const childrenCount = object.children.length;
for (let i = 0; i < childrenCount; i++) {
const child = object.children[i];
if (child) {
hierarchyTraverse(child, callback);
}
}
}