简体   繁体   中英

THREE.js Mesh Vertices

I am new THREE.js and making game in it. I want to ask that is there any command in THREE.js to find out the vertices where exactly the ray from a mesh hits to another mesh. Like if a ray emits from a car and hit the road so I want to find out the exact point where the ray ffrom the car hits the road. I searched for this a find out a command but it is not giving the solution

for(var i = 0; i < Mesh.geometry.vertices.length; i++){
 Mesh.geometry.vertices[k].x;
}

please help me in this regard.

There is - have a look at the Raycaster class which does exactly what you want. The documentation is OK, but it's worth looking at the source code to see exactly what it does.

Here's an untested example:

var rc = new THREE.Raycaster(from, direction);
var results = rc.intersectObjects(your_scene_objects);
if (results[0])
  alert('hit at ' + results[0].point); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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