import { object3DFastMatrixUpdate } from "./object3DFastMatrixUpdate.js";

export function commonObject3DFastMatrixUpdate(object) {
    // update children

    const children = object.children;

    for (let i = 0, l = children.length; i < l; i++) {

        const child = children[i];

        object3DFastMatrixUpdate(child);

    }

    if (object.isSkinnedMesh) {
        /*
        Code copy from THREE.SkinnedMesh.updateMatrixWorld
         */

        if (object.bindMode === 'attached') {

            object.bindMatrixInverse.copy(object.matrixWorld);
            object.bindMatrixInverse.invert();

        } else if (object.bindMode === 'detached') {

            object.bindMatrixInverse.copy(object.bindMatrix);
            object.bindMatrixInverse.invert();

        } else {

            console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + object.bindMode);

        }
    }
}
