I have this to create a line between 2 points:
var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(0, 0, 0));
geometry.vertices.pus
Old question, but still relevant today. Building on Lee Stemkoski's answer, this is what i ended up getting to work:
const cylinderMesh = function( pointX, pointY )
{
// edge from X to Y
const direction = new THREE.Vector3().subVectors( pointY, pointX );
const arrow = new THREE.ArrowHelper( direction.clone().normalize(), pointY );
// cylinder: radiusAtTop, radiusAtBottom,
// height, radiusSegments, heightSegments
const edgeGeometry = new THREE.CylinderGeometry( 2, 2, direction.length(), 6, 4 );
const edge = new THREE.Mesh( edgeGeometry,
new THREE.MeshBasicMaterial( { color: 0x0000ff } ) );
edge.rotation = arrow.rotation.clone();
edge.position = new THREE.Vector3().addVectors( pointX, direction.multiplyScalar(0.5) );
return edge;
}
Note the main difference: you have to normalize the direction
vector and take the origin to be pointY
. Normalizing the direction
vector requires a .clone()
in order to allow you to use it later on in the position
calculation