three-laser-pointer

three-laser-pointer is a three.js based library class that provides a reflective laser pointer. It is especially suitable for adding a laser pointing interface in VR-like scenes where the camera is serving as first-person shooter, and not limited to this use case.

The laser object has methods that are useful for

Demo

We present two live demos using this three-laser-pointer library.

Setup

Install

$ npm install three-laser-pointer

Loading

Via script tags: use LaserPointer.Laser after

<script src="three.min.js"></script>
<script src="dist/three-laser-pointer.min.js"></script>

Via the ES6 module system: use Laser after

import { Laser } from 'three-laser-pointer';

Usage

// create and add a red laser in the scene
var laser = new Laser({color: 0xff0000});
scene.add(laser);

var pt = new THREE.Vector3(0, 0, -1); // the target point to shoot

// set the source point relative to the camera
// with offset (0.3, -0.4, -0.2)
laser.setSource(new THREE.Vector3(0.3, -0.4, -0.2), camera);

// shoot the target from the source point
laser.point(pt);
// create and add a green laser in the scene
var laser = new Laser({color: 0x00ff00});
scene.add(laser);

var pt = new THREE.Vector3(0, 0, 1); // the target point to shoot

// prepare an array of THREE.Mesh objects that interact with the laser
var meshes = [...];

// set the source point relative to the camera
laser.setSource(new THREE.Vector3(0.3, -0.4, -0.2), camera);

// shoot the target with raytrace considering the meshes in the scene
laser.pointWithRaytrace(pt, meshes);

API

Laser

Build

$ npm install  # set up build tools
$ npm run build  # generate module files in lib/