0

forge中自己加入的元素怎么通过鼠标选中

1 个回答

0

利用Raycaster的方法,但是这个跟three.js的方法不太一样,需要做一些设置,从老外源码扒出来的:

    
    var pointerVector = new THREE.Vector3();
    var pointerDir = new THREE.Vector3();
    var ray = new THREE.Raycaster();
    var pointer = event.pointers ? event.pointers[ 0 ] : event;
    var camera=viewer.getCamera();
    var obj=intersectObjects(pointer,camera).object;
    var rect = domElement.getBoundingClientRect();
    var x = ( ( pointer.clientX - rect.left ) / rect.width ) * 2 - 1;
    var y = - ( ( pointer.clientY - rect.top ) / rect.height ) * 2 + 1;
    pointerVector.set( x, y, -1 );
    pointerVector.unproject( camera );
    pointerDir.set( 0, 0, -1 );
    ray.set( pointerVector, pointerDir.transformDirection( camera.matrixWorld ) );
    var intersections = ray.intersectObjects( objects, true );