旋转后来自对象的三个JS box3是错误的 [英] Three JS box3 from object is wrong after rotation

查看:33
本文介绍了旋转后来自对象的三个JS box3是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景包含一些对象,我选择其中一个然后旋转它然后通过这些代码测试碰撞

i have a scene contains some objects, i select one of them then rotate it then test collision by thes code

        var firstObject = SELECTED;
        for(var i=0;i<objects.length;i++){
            if(objects[i]!=SELECTED){
                var secondObject = objects[i];
                firstBB = new THREE.Box3().setFromObject(firstObject);
                secondBB = new THREE.Box3().setFromObject(secondObject);
                var collision = firstBB.isIntersectionBox(secondBB);
                if(collision){
                    return;
                }
            }
        }

代码在旋转前工作正常,但旋转后有界 bos 计算不正确.

the code is works fine before rotation but after rotation the bounded bos is not computed correctly.

推荐答案

我也面临同样的问题.这是因为边界框是在没有平移和旋转因素的情况下创建的,因此对此的快速解决方法是在计算 setFromObject 之前尝试在网格上应用矩阵运算,例如:

I was too facing the same issue. This is beacuse the bounding box is created without the factor of translation and rotation so the quick fix for this is try to apply the matrix operation on the Mesh before computing the setFromObject like:

    firstObject.updateMatrix(); 
    firstObject.geometry.applyMatrix( firstObject.matrix );
    secondObject.updateMatrix(); 
    secondObject.geometry.applyMatrix( secondObject.matrix );
    firstBB = new THREE.Box3().setFromObject(firstObject);
    secondBB = new THREE.Box3().setFromObject(secondObject);
    var collision = firstBB.isIntersectionBox(secondBB);

这篇关于旋转后来自对象的三个JS box3是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆