用鼠标选择Collada对象单击Three.JS [英] Select Collada objects by mouse Click in Three.JS

查看:123
本文介绍了用鼠标选择Collada对象单击Three.JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过鼠标单击在Three.JS中选择Collada对象.我知道我可以根据其ID选择对象,并且看到一些用户可以与Geometry定义的对象进行交互的示例(此处).但是我需要访问Collada格式的对象.

I need to select Collada objects in Three.JS by mouse click. I know that I can select object based on their id and I saw some samples that user can interact with Geometry defined objects (here). But I need to have access to the objects in Collada format.

推荐答案

假定dae_scene是从ColladaLoader返回的COLLADA场景,可以执行以下操作检查交叉点:

Assuming that dae_scene is a COLLADA scene returned from the ColladaLoader, here's what you can do to check for intersection:

var toIntersect = [];
THREE.SceneUtils.traverseHierarchy(dae_scene, function (child) {
    if (child instanceof THREE.Mesh) {
        toIntersect.push(child);
    }
});

这将在COLLADA场景中获取所有Mesh对象.然后,您可以使用该数组查找射线相交,如下所示:

This gets all Mesh objects inside the COLLADA scene. You can then use that array to look for ray intersections, like this:

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

这篇关于用鼠标选择Collada对象单击Three.JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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