Skip to content

Instantly share code, notes, and snippets.

@mauriciomassaia
Created August 9, 2016 02:58
Show Gist options
  • Save mauriciomassaia/cb17cad48c51ff281cd2bddbd8132294 to your computer and use it in GitHub Desktop.
Save mauriciomassaia/cb17cad48c51ff281cd2bddbd8132294 to your computer and use it in GitHub Desktop.
Draw a line from the Raycaster origin and dest Vectors. Threejs
drawRaycastLine(raycaster) {
let material = new THREE.LineBasicMaterial({
color: 0xff0000,
linewidth: 10
});
let geometry = new THREE.Geometry();
let startVec = new THREE.Vector3(
raycaster.ray.origin.x,
raycaster.ray.origin.y,
raycaster.ray.origin.z);
let endVec = new THREE.Vector3(
raycaster.ray.direction.x,
raycaster.ray.direction.y,
raycaster.ray.direction.z);
// could be any number
endVec.multiplyScalar(5000);
// get the point in the middle
let midVec = new THREE.Vector3();
midVec.lerpVectors(startVec, endVec, 0.5);
geometry.vertices.push(startVec);
geometry.vertices.push(midVec);
geometry.vertices.push(endVec);
console.log('vec start', startVec);
console.log('vec mid', midVec);
console.log('vec end', endVec);
let line = new THREE.Line(geometry, material);
this.scene.add(line);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment