Three.js THREE.Projector has been moved to

后端 未结 5 607
萌比男神i
萌比男神i 2020-12-09 17:47

I understand there is no THREE.projector in version 71 (see the deprecated list), but I don\'t understand how to replace it, particularly in this code that dete

5条回答
  •  天命终不由人
    2020-12-09 18:26

    The THREE.JS raycaster documentation actually gives all the relevant information that is laid out in these answers as well as all the missing points that may be difficult to get your head around.

    var raycaster = new THREE.Raycaster(); 
    var mouse = new THREE.Vector2(); 
    
    function onMouseMove( event ) { 
      // calculate mouse position in normalized device coordinates 
      // (-1 to +1) for both components 
      mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; 
      mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; 
    } 
    
    function render() { 
      // update the picking ray with the camera and mouse position
      raycaster.setFromCamera( mouse, camera ); 
      // calculate objects intersecting the picking ray var intersects =     
      raycaster.intersectObjects( scene.children ); 
    
      for ( var i = 0; i < intersects.length; i++ ) { 
        intersects[ i ].object.material.color.set( 0xff0000 ); 
      }
    
      renderer.render( scene, camera ); 
    } 
    window.addEventListener( 'mousemove', onMouseMove, false );        
    window.requestAnimationFrame(render);`
    

    Hope it helps.

提交回复
热议问题