threejs raycasting does not work

前端 未结 1 877
情深已故
情深已故 2020-12-22 07:15

I\'m having a problem trying to write a unit test to check collision detection. I simplify code as only this possible - I have a plane in (0, 0, 0) and I do raycasting from

相关标签:
1条回答
  • 2020-12-22 08:07

    You need to update the world transform of the ground mesh prior to raycasting. (Normally, the renderer does this for your in the render() call.)

    console.clear();
    var intersections,
        from = new THREE.Vector3(0, 100, 0);
        direction = new THREE.Vector3(0, -1, 0),
        raycaster = new THREE.Raycaster();
    
    var geometry = new THREE.PlaneGeometry(10, 10, 1, 1);
    var ground = new THREE.Mesh(geometry);
    ground.position.set(0, 0, 0);
    ground.rotation.x = THREE.Math.degToRad(-90);
    
    ground.updateMatrixWorld(); // add this
    
    raycaster.set(from, direction);
    intersections = raycaster.intersectObjects([ground]);
    console.log(intersections);
    

    three.js r.73

    0 讨论(0)
提交回复
热议问题