JSFiddle - React, Tailwind, and code Playground

by Hoshua

HTML

<script src="//cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script>

CSS

body {
	  margin: 0;
}

JavaScript

var camera, scene, renderer;
var geometry, material, mesh;

init();
animate();

function init() {

    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
    camera.position.z = 1;

    scene = new THREE.Scene();
    geometry = new THREE.PlaneGeometry( 1, 1);
    material = new THREE.MeshNormalMaterial();

    mesh = new THREE.Mesh( geometry, material );
    mesh.rotation.set( 0, 45 / 180 * Math.PI, 0)
    scene.add( mesh );

    renderer = new THREE.WebGLRenderer( { antialias: true } );
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );
    seta()

}

function seta(){
  const origin = new THREE.Vector3(0.5, 0, 0),
        direction = new THREE.Vector3(-1, 0, 0)
  const raycaster = new THREE.Raycaster( origin, direction );
  const intersects = raycaster.intersectObject( mesh );

  const length = 1.5;
  const hex = 0xff0000;

  const arrowHelper = new THREE.ArrowHelper( direction, origin, length, hex );
  scene.add( arrowHelper );
	
  console.log(intersects)
  
}

function animate() {

    requestAnimationFrame( animate );


    renderer.render( scene, camera );

}