Screen bounding box after rotate

Hi,
Trying to keep my 2d bounding box calculate at same angle but it seem the bounding box follow the first object even if i cloned the mesh and reset the Z angle to zero
any ideas !

controls.addEventListener("dragstart", function (event) {

            if (event.object) {

                AnimatorObject = event.object;

                AnimatorObject.rotation.z += MathUtils.degToRad(30);

                FakeAnimatorObject = AnimatorObject.clone();

                FakeAnimatorObject.rotation.z = 0;

                return;

            }

        });

let boundingBox2D = computeScreenSpaceBoundingBox(
    FakeAnimatorObject,
    Camera
);

Calling FakeAnimatorObject.updateMatrixWorld(); for the cloned mesh solved my problem
any explanation am new on threejs

I assume computeScreenSpaceBoundingBox() requires an up-to-date world matrix. The clone operation should actually copy the world matrix, too, so I’m a bit irritated that it does not work in the first place.

i even try to trick it without clone like that but still giving bounding box of the rotated mesh not the default angle (zero) , really confusing any explanation

AnimatorObject.rotation.z = 0;
let boundingBox2D = computeScreenSpaceBoundingBox(
    AnimatorObject,
    Camera
);
AnimatorObject.rotation.z = MathUtils.degToRad(30);

Well, after this line, the world matrix requires a re-computation. Otherwise it won’t honor the new transformation of the object.

is there is any preformance impact using updateMatrixWorld() in loop

That depends on the complexity of the scene graph. There are use cases where updateMatrixWorld() is a CPU hot spot.

2 Likes