/**
 *
 * @param {THREE.Object3D} object
 * @param {function} callback
 * @param {*} [thisArg]
 * @param {*} [ctx]
 */
export async function async_traverse_three_object(object, callback, thisArg, ctx) {
    await callback.call(thisArg, object, ctx);

    const children = object.children;
    const n = children.length;

    const child_promises = [];

    for (let i = 0; i < n; i++) {
        const child = children[i];

        child_promises.push(async_traverse_three_object(child, callback, thisArg, ctx));
    }

    // wait for all children at the same time
    await Promise.all(child_promises);
}
