简体   繁体   English

如何检测两个bufferGeometryBox的两个面的交点?

[英]How to detect intersections of two faces of two bufferGeometryBox?

I am developing a 3d configurator. 我正在开发一个3d配置器。 A cube appears on the scene. 场景中会出现一个立方体。 If you click on the side of this cube, a rectangle appears. 如果单击此立方体的一侧,则会出现一个矩形。 The problem is that if I click on the same side of the cube, another one will be added over the existing rectangle. 问题是,如果我点击立方体的同一侧,将在现有矩形上添加另一个。 I would like to block the clicked side. 我想阻止点击的一面。 My cubes and rectangles is buffer geometry. 我的立方体和矩形是缓冲几何。 I can get raycasting face (a,b,c) and faceIndex. 我可以获得光线投射面(a,b,c)和faceIndex。 But how to get intersection of two different faces of two different objects? 但是如何获得两个不同对象的两个不同面的交集? Sorry for my english 对不起我的英语不好

This is my project https://alovert.ru 这是我的项目https://alovert.ru

在此输入图像描述 在此输入图像描述 在此输入图像描述

my code 我的代码

if (intersect) {
            var index = Math.floor( intersect.faceIndex / 6 );
                if ( intersect.object.name == 'cube' ) {

                    switch ( index ) {
                        case 0: load( intersect.object.position.x + 6.58, intersect.object.position.y, intersect.object.position.z, 'beam', 0, 0, 0 ); break;
                        case 1: load( intersect.object.position.x - 6.58, intersect.object.position.y, intersect.object.position.z, 'beam', 0, 0, 0 ); break;
                        case 2: load( intersect.object.position.x, intersect.object.position.y + 6.58, intersect.object.position.z, 'beam', 0, 0, 90 ); break;
                        case 3: load( intersect.object.position.x, intersect.object.position.y - 6.58, intersect.object.position.z, 'beam', 0, 0, 90 ); break;
                        case 4: load( intersect.object.position.x, intersect.object.position.y, intersect.object.position.z + 6.58, 'beam', 0, 90, 0 ); break;
                        case 5: load( intersect.object.position.x, intersect.object.position.y, intersect.object.position.z - 6.58, 'beam', 0, 90, 0 ); break;
                    }

                }`





I suppose that the newly created object that is duplicated will have the same global position (check this ) value as the already existing one. 我想新复制的对象将具有与已存在的对象相同的全局位置(检查值)。 So you can simply traverse over the existing objects and compare their positions, if they match or have a minor difference in position values, then block. 因此,您可以简单地遍历现有对象并比较它们的位置,如果它们匹配或位置值有微小差异,则阻止。

To make things faster, you can keep the objects global position values in a list once they are created and iterate over the list instead. 为了加快速度,可以在创建对象后将对象全局位置值保留在列表中,然后迭代列表。

see the following meta-code that describes the idea: 请参阅以下描述该想法的元代码:

let newObject = loadObject(...);
parentObj.add(newObject);
newObject.position.set(new_x, new_y, new_z);
let globalPosition = new THREE.Vector3();
newObject.getWorldPosition(globalPosition);
for (let i = 0; i < existingPositions.length; i++){
    if(     existingPositions[i].x === globalPosition.x
        &&  existingPositions[i].y === globalPosition.y
        &&  existingPositions[i].z === globalPosition.z) {
            parentObj.remove(newObject);
            return;
    }
}
existingPositions.push(globalPosition);

Maybe it can be useful for people have the same problem. 也许它对人们有同样的问题很有用。 The main idea is to create rectangle and cubes with userData, that have 6 parameters “false”. 主要思想是使用userData创建矩形和多维数据集,其中有6个参数为“false”。 From every face i cast a ray and if it intersect face from other object, this face became “true”. 从每一张脸上投下一条光线,如果它与其他物体相交,那么这张脸就变成了“真实”。 Check it out 看看这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM