Select Collada objects by mouse Click in Three.JS

2019-07-18 03:42发布

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条回答
beautiful°
2楼-- · 2019-07-18 04:35

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 );
查看更多
登录 后发表回答