在three.js中对'subscenes'进行光线投射 [英] Raycasting against 'subscenes' in three.js

查看:203
本文介绍了在three.js中对'subscenes'进行光线投射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在使用three.js示例中的webgl_interactive_cubes.html,我有一个相对简单的问题:是否可以测试光线与对象子节点的交集。

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 ( var i = 0; i < 2000; i ++ ) {

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

}

当我致电

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

它将与这些对象相交。但是,如果我首先像这样创建一个'subScene':

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

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

然后将所有这些对象添加到subScene而不是场景中,交叉点将不再出现。

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

是否可以在场景和子场景中交叉所有对象(在最终项目中我希望有多层嵌套的subScenes)或者我应该尝试如果我正在使用光线投射,请将所有对象保留在同一场景中?

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?

提前感谢您的时间,

Isaac

推荐答案

您只需要设置递归标志:

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

three.js r.58

three.js r.58

这篇关于在three.js中对'subscenes'进行光线投射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆