Raycasting against 'subscenes' in three.js

半世苍凉 提交于 2019-12-12 01:38:31

问题


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


回答1:


You just need to set the recursive flag:

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

three.js r.58



来源:https://stackoverflow.com/questions/17607435/raycasting-against-subscenes-in-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!