Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Three.js不可见平面不使用raycaster.intersectObject_Javascript_Three.js_Raycasting - Fatal编程技术网

Javascript Three.js不可见平面不使用raycaster.intersectObject

Javascript Three.js不可见平面不使用raycaster.intersectObject,javascript,three.js,raycasting,Javascript,Three.js,Raycasting,我正在尝试创建可拖动对象,如本例所示: 应可拖动的对象位于数组objectMoverLines中 我已使用以下代码将平面添加到场景中: plane = new THREE.Mesh(new THREE.PlaneBufferGeometry(500, 500, 8, 8), new THREE.MeshBasicMaterial({color: 0x248f24, alphaTest: 0})); plane.visible = false; scene.add(plane); 问题发生在on

我正在尝试创建可拖动对象,如本例所示:

应可拖动的对象位于数组objectMoverLines中

我已使用以下代码将平面添加到场景中:

plane = new THREE.Mesh(new THREE.PlaneBufferGeometry(500, 500, 8, 8), new THREE.MeshBasicMaterial({color: 0x248f24, alphaTest: 0}));
plane.visible = false;
scene.add(plane);
问题发生在onDocumentMouseDown功能下。由于某些原因,如果平面可见性设置为false(plane.visible=false),则在某个点上,将不会填充相交的sAbjOvers。但是,如果将平面的可见性设置为true,它将正常工作(但显然,这会导致一个巨大的平面挡住一切):

另外,这是我目前在onDocumentMouseMove功能下拥有的:

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

    mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
    mouse.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;

    // Get 3D vector from 3D mouse position using 'unproject' function
    var vector = new THREE.Vector3(mouse.x, mouse.y, 1);
    vector.unproject(camera);

    // Set the raycaster position
    raycaster.set( camera.position, vector.sub( camera.position ).normalize() );

    if (objmoverselection) {
        // Check the position where the plane is intersected
        var intersectsobjmovers = raycaster.intersectObject(plane);
        // Reposition the object based on the intersection point with the plane
        objmoverselection.position.copy(intersectsobjmovers[0].point.sub(offset));
    } else {
        // Update position of the plane if need
        var intersectsobjmovers = raycaster.intersectObjects(objectMoverLines);
        if (intersectsobjmovers.length > 0) {
            // var lookAtVector = new THREE.Vector3(0,0, -1);
            // lookAtVector.applyQuaternion(camera.quaternion);
            plane.position.copy(intersectsobjmovers[0].object.position);
            plane.lookAt(camera.position);
        }
    }

    requestAnimationFrame( render );
}
试试这个:

plane = new THREE.Mesh(new THREE.PlaneBufferGeometry(500, 500, 8, 8), 
   new THREE.MeshBasicMaterial( {
       color: 0x248f24, alphaTest: 0, visible: false
}));

scene.add(plane);

哦,我明白了。。。我必须在材质上将可见性设置为false,而不是网格。。。我早该知道的
plane = new THREE.Mesh(new THREE.PlaneBufferGeometry(500, 500, 8, 8), 
   new THREE.MeshBasicMaterial( {
       color: 0x248f24, alphaTest: 0, visible: false
}));

scene.add(plane);