Select Collada objects by mouse Click in Three.JS

北慕城南 提交于 2020-01-15 04:15:10

问题


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.


回答1:


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);
    }
});

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 );


来源:https://stackoverflow.com/questions/11792867/select-collada-objects-by-mouse-click-in-three-js

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