简体   繁体   中英

JSONLoader raycaster & collision meshes - three.js

I'm using raycaster to see if I hit a mesh with the mouse ( or touch ) the object is thin and I could do with increasing the size of whatever can be intersected with the Ray. As with games objects, (using three.js) can I add my own collision mesh, that obviously does not render, but triggers the Ray?

在此处输入图片说明

So, when my ray hits the (invisible) pink cylinder that is associated with the original mesh, it triggers the intersect.

I can't simply make another mesh that is grouped with the original and make it visible = false; or opacity = 0; that dosen't work. I'm looking for something 'built in' ( if it exists )

many thanks

You want to add a collision mesh to your scene that responds to raycasting, but does not render.

To do so, add your collision mesh as a child of your mesh, and set the visibility of the collision mesh's material to false.

collisionMeshMaterial = new THREE.MeshBasicMaterial( {
    visible: false
} );

The collision mesh will not render, but it will respond to raycasting.

three.js r.74

You could maintain a collection of clickable meshes without adding them to the scene. Then just raycast against this collection: raycaster.intersectObjects(collection);

You may have to keep them "synchronized" with their parent object though.

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