Question

So I am working with the webgl_interactive_cubes.html in the three.js examples, and I have a relatively simple question: Is it possible to test for intersection of a ray with the children of an object.

for example, if I do something like:

for ( var i = 0; i < 2000; i ++ ) {

var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
scene.add( object );

}

When I call

var intersects = raycaster.intersectObjects( scene.children );

It will intersect these objects. However if I first create a 'subScene' like so:

var subScene = new THREE.Object3D();
scene.add(subScene);

And then add all of these objects to the subScene instead of the scene, the intersection will no longer occur.

Is it at all possible to intersect ALL the objects in the scene and subscenes ( in the final project I would like to have many layers of nested subScenes ) Or should I try to keep all objects in the same scene if I am using raycasting?

Thank you in advance for your time,

Isaac

Était-ce utile?

La solution

You just need to set the recursive flag:

var intersects = raycaster.intersectObjects( scene.children, true );

three.js r.58

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top