Looking into Three.js, it appears that the CollisionUtils.js and Collisions.js utilities are no longer supported. mrdoob, the creator of three.js, now suggests updating to the latest version of three.js and utilizing the Ray class instead. Below is a suggestion on how to implement this.
The concept involves checking if a specific mesh named "Player" intersects with any meshes within an array known as "collidableMeshList". The approach is to generate a series of rays originating from the Player mesh's coordinates (Player.position) and extending towards each vertex in the Player mesh's geometry. Each Ray includes a method called "intersectObjects" which provides details on objects intersected by the Ray and their respective distances from the origin of the Ray. If the distance to an intersection is less than the distance between the Player's position and the vertex of the geometry, then a collision has occurred within the player's mesh - commonly referred to as an "actual" collision.
An operational example can be found at:
You can control the red wireframe cube using arrow keys for movement and W/A/S/D for rotation. When the cube intersects with one of the blue cubes, the text "Hit" will display at the top of the screen for each intersection following the described criteria. Refer to the critical section of the code below.
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() )
{
// handle collision scenario...
}
}
There are potential limitations to this method.
(1) If the ray's origin lies within a mesh M, no collisions will be detected between the ray and M.
(2) Small objects relative to the Player mesh may bypass detection between rays, resulting in missed collisions. To address this, consider having small objects create the rays and conduct collision detection from their perspective or incorporate more vertices on the mesh (e.g., using CubeGeometry(100, 100, 100, 20, 20, 20) rather than CubeGeometry(100, 100, 100, 1, 1, 1)). However, adding more vertices may impact performance, so use this cautiously.
I encourage others to share their solutions and insights on this matter. It took me some time to come up with the solution detailed above, so collaboration is welcomed.