Cant get vertices in three js anymore

I have been trying to make a physics engine for long enough and still haven’t found a way to get the vertices to detect collisions because I need obj meshes to have their own collisions but I only found ways for cubes and spheres but not obj meshes. I’ve tried to use geometry.vertices but it just says its undefined I think it has been deprecated is what I think. Here is an example of what I really wanted to use but its probably been deprecated because I console.logged object.geometry and I am pretty sure its just deprecated.

for (var vertexIndex = 0; vertexIndex < Player.geometry.vertices.length; vertexIndex++)
{       
    var localVertex = Player.geometry.vertices[vertexIndex].clone();
    var globalVertex = Player.matrix.multiplyVector3(localVertex);
    var directionVector = globalVertex.subSelf( Player.position );

    var ray = new THREE.Ray( Player.position, directionVector.clone().normalize() );
    var collisionResults = ray.intersectObjects( collidableMeshList );
    if ( collisionResults.length > 0 && collisionResults[0].distance < directionVector.length() ) 
    {
        // a collision occurred... do something...
    }
}
1 Like

Yup. It’s geometry.vertices has been deprecated. Now vertices are stored in geometry.attributes.position.array.
Look at the docs for BufferGeometry to see accessing methods… or just grab them out of the array… it’s a flat array of xyzxyzxyzxyz

yeah I used that one and it worked thanks!

1 Like