# How to detect intersections of two faces of two bufferGeometryBox?

Because there are 12 faces, and i want to detect side

So, we have 12 faces on 6 sides, each side has 2 faces, thus to find the side by a face index, you need to divide it by 2.
`Math.floor( intersects[0].faceIndex / 2 );`

Oh, sorry. This number from other code. Yes, ofcourse, but my face has faceIndex in range from 30 to 1800

You can see it in console log
http://alovert.ru/

Are you sure that you intersect a box with 12 faces?

Not sure. I set group in raycaster

`intersects = raycaster.intersectObject(group, true);`

If i set single mesh object, intersection not working

Pardon, i forgot delete this code .toNonIndexed()

Hi again! I have some trouble ā¦

How to intersect non indexed buffer geometry? I want to detect intersection between two defferent faces of two different non indexed buffergeometry. I set ray from middle of each faces, but raycaster don`t work with non indexed geometry.

I want to see result like this:

Thank you very much!

my code

``````var box = new THREE.Mesh(geometry.toNonIndexed(), material);

var raycaster = new THREE.Raycaster();
var intersects = [];

var pos = box.geometry.attributes.position;
var ori = new THREE.Vector3();
var dir = new THREE.Vector3();

var a = new THREE.Vector3(),
b = new THREE.Vector3(),
c = new THREE.Vector3(),
tri = new THREE.Triangle();

var faces = pos.count / 3;
for (let i = 0; i < faces; i++) {
a.fromBufferAttribute(pos, i * 3 + 0);
b.fromBufferAttribute(pos, i * 3 + 1);
c.fromBufferAttribute(pos, i * 3 + 2);
tri.set(a, b, c);
tri.getMidpoint(ori);
tri.getNormal(dir)
raycaster.ray.origin, 30, 0xff0000));
raycaster.set(ori, dir);
intersects = raycaster.intersectObject(box, true);

if (intersects.length > 0) {

console.log(intersects[0]);

}
}
``````

/cc

What does it mean?

Nothing bad. Just the other users can track the issue on other resources.

Oh, ok! I just intersting what mean /cc

CC comes from the email domain: https://www.techwalla.com/articles/what-does-cc-mean-in-a-text

Wow, this is a discovery for me. Iām Russian

Hi! I sucessfully set ray from each faces and when intersection detect face , its return flag true. But i have a problem. I cant to return flag false when i delete object, that intersects. My code:

``````				box.userData.sides = {
0: false,
1: false,
2: false,
3: false,
4: false,
5: false
}

collision.push(box);

checkRaycast();

}

load(0, 0, 0, 'cube', 0, 0, 0);

function checkRaycast() {
var raycaster = new THREE.Raycaster();
var intersects = [];
for (let j = 0; j < collision.length; j++) {

var pos = collision[j].geometry.attributes.position;
var ori = new THREE.Vector3();
var dir = new THREE.Vector3();
var a = new THREE.Vector3(),
b = new THREE.Vector3(),
c = new THREE.Vector3(),
tri = new THREE.Triangle();

var index = collision[j].geometry.index;
var faces = index.count / 3;
scene.updateMatrixWorld()
for (let i = 0; i < faces; i++) {
a.fromBufferAttribute(pos, index.array[i * 3 + 0]);
b.fromBufferAttribute(pos, index.array[i * 3 + 1]);
c.fromBufferAttribute(pos, index.array[i * 3 + 2]);
a.set(a.x + collision[j].position.x, a.y + collision[j].position.y, a.z + collision[j].position.z);
b.set(b.x + collision[j].position.x, b.y + collision[j].position.y, b.z + collision[j].position.z);
c.set(c.x + collision[j].position.x, c.y + collision[j].position.y, c.z + collision[j].position.z);
tri.set(a, b, c);
tri.getMidpoint(ori);
tri.getNormal(dir);

raycaster.set(ori, dir);

intersects = raycaster.intersectObjects(collision, true);

if (intersects.length > 0) {
var intFace = Math.floor(intersects[0].faceIndex / 2);
if (intersects[0].distance > 0 && intersects[0].distance < 0.2) {
intersects[0].object.userData.sides[intFace] = true;
}
} else {

collision[j].userData.sides[0] = false;
collision[j].userData.sides[1] = false;
collision[j].userData.sides[2] = false;
collision[j].userData.sides[3] = false;
collision[j].userData.sides[4] = false;
collision[j].userData.sides[5] = false;

}

}
}
}
``````

My project: https://alovert.ru