Object3D中的交集 [英] Intersection within Object3D

查看:96
本文介绍了Object3D中的交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些对象添加到Object3D(用于分组元素),我试图检测它上面的点击。
我的场景大小为 600x400 ,我的相机在三个对象内,我的事件处理程序代码如下所示:

I have some objects added to an Object3D (for grouping elements) and I'm trying to detect clicks on it. My scene has a size of 600x400, my camera is within a three-object and my event handler code looks like below:

function onDocumentMouseDown( event ) {
   event.preventDefault();

   var mouse = {};
   mouse.x = ( event.clientX / 600 ) * 2 - 1;
   mouse.y = - ( event.clientY / 400 ) * 2 + 1;

   var vector = new THREE.Vector3( mouse.x, mouse.y, 1 );
   projector.unprojectVector( vector, three.camera );

   var ray = new THREE.Ray( three.camera.position, vector.subSelf( three.camera.position ).normalize() );

   var intersects = ray.intersectObjects( group.children );
   alert(intersects.length);
   [...]
}

其实我在警惕计数相交的物体。但它保持为零。它找不到任何相交的物体。我已经对我的投影向量的x,y和z值进行了一些调整 - 没有成功。

Actually I'm alerting the count of intersected objects. But it stays zero. It couldn't find any intersected objects. I've already played a bit aroud with the x, y and z values of my projection vector - without success.

我添加了一个精简样本来演示这个 jsfiddle 上的问题。也许某人有一个简短的提示,告诉我它出了什么问题?

I've added a stripped down sample for demonstrating this issue on jsfiddle. Maybe someone has a short hint for me what goes wrong with it?

推荐答案

在你的小提琴中,因为你打电话给 THREE.SceneUtils.createMultiMaterialObject(),它创建一个层次结构,你需要将递归标志添加到 ray.intersectObjects()

In your fiddle, because you are calling THREE.SceneUtils.createMultiMaterialObject( ), which creates a hierarchical structure, you need to add the recursive flag to ray.intersectObjects().

var intersects = ray.intersectObjects( group.children, true );

EDiT: ray 现在是一个实例 THREE.Raycaster - 不是 THREE.Ray

EDiT: ray is now an instance of THREE.Raycaster -- not THREE.Ray.

three.js r.58

three.js r.58

这篇关于Object3D中的交集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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