Advertisement
yskang

threejs-minecraft-24

Apr 21st, 2020
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class RayHelper {
  2.     constructor( ) {
  3.         this.line = null;
  4.     }
  5.  
  6.     attach( raycaster, scene ) {
  7.         if( !raycaster || !scene ) return;
  8.  
  9.         const rayLineGeometry = new THREE.Geometry();
  10.         rayLineGeometry.vertices.push( raycaster.ray.origin.clone() );
  11.         rayLineGeometry.vertices.push( raycaster.ray.origin.clone().add( raycaster.ray.direction.clone().setLength( 10000 ) ) );
  12.  
  13.         const rayLineMaterial = new THREE.LineBasicMaterial({ color: 0x00ff00 });
  14.         const line = new THREE.Line( rayLineGeometry, rayLineMaterial );
  15.  
  16.         this.line = line; scene.add( line );
  17.     }
  18.  
  19.     detach( scene ) {
  20.         if( !this.line ) return;
  21.  
  22.         scene.remove( this.line );
  23.         delete this.line;
  24.         this.line = null;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement