Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To obtain the position of the center vertex for all faces in BoxGeometry using threejs, you can use the following method:

const box = new THREE.BoxGeometry();

for (let i = 0; i < box.faces.length; i++) {
    const face = box.faces[i];
    const v1 = box.vertices[face.a];
    const v2 = box.vertices[face.b];
    const v3 = box.vertices[face.c];

    // Calculate the centroid of the face
    const center = new THREE.Vector3();
    center.add(v1).add(v2).add(v3).divideScalar(3);

    console.log(center);
}

This code loops through all the faces of the BoxGeometry and calculates the centroid of each face using the three vertices that make up the face. The centroid is calculated by adding the three vertices together and dividing by three. The resulting center vector represents the position of the center vertex for that particular face. The center vector is then logged to the console for each face.