如何使用 Raycaster 选择根 Object3D [英] How to select a root Object3D using Raycaster

查看:23
本文介绍了如何使用 Raycaster 选择根 Object3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有子网格的父 Object3D.如何使用 Raycaster 仅选择根父对象?

I have a parent Object3D that has child meshes. How can I use Raycaster to select only the root parent object?

我的例子

推荐答案

如果你的父 Object3D 有多个子网格,并且你想通过光线投射选择父,你可以这样做以下:

If you have a parent Object3D that has multiple child meshes, and you want to select the parent by raycasting, you can do the following:

将父对象添加到对象数组中:

Add the parent object to the array of objects:

var objects = [];
...
objects.push( root_parent_object );

向每个子对象添加一个指向根父对象的指针:

Add to each child object a pointer to the root parent object:

child.userData.parent = root_parent_object;

将递归标志传入intersectObjects().

var intersects = raycaster.intersectObjects( objects, true );

现在当光线投射器与子对象相交时,您可以获得根对象.

Now when the raycaster intersects a child object, you can obtain the root object.

three.js r.68

three.js r.68

这篇关于如何使用 Raycaster 选择根 Object3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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