I need assistance with creating a connection between two dynamic vertices in my project. The information for each vertex is stored within an object named object
, containing the position data as a THREE.Vector3
.
To create the line connecting these vertices, I used the following code:
var Line = function(scene, source, target){
var geometry = new THREE.Geometry();
geometry.dynamic = true;
geometry.vertices.push(source.object.position);
geometry.vertices.push(target.object.position);
geometry.verticesNeedUpdate = true;
var material = new THREE.LineBasicMaterial({ color: 0x000000 });
var line = new THREE.Line( geometry, material );
scene.add(line);
return line;
};
The positions of the vertices are updated using the following code snippet:
vertex.object.position.add(vertex.velocity);
I attempted to link the line's points to the corresponding vertices by assigning source.object.position
and target.object.position
to line.geometry.vertices[0]
and line.geometry.vertices[1]
. However, the connections between the vertices and lines seem to be inaccurate. Despite the vertices moving correctly, the lines do not align properly.
How can I ensure that the lines move accurately along with the vertices?