我试图用 Three.js 表示一个图表,其中节点对象可以通过单击并拖动来移动。我当前的问题是,从一个节点到另一个节点创建为 THREE.Line 的边不会随节点移动(边应该旋转/改变长度)。
到目前为止我的代码:
var colour = 0x568c4b, geometry = new THREE.BoxGeometry(size, size, size),
material = new THREE.MeshLambertMaterial({ color: colour }),
position0 = new THREE.Vector3(-100, -60, 0),
position1 = new THREE.Vector3(150, 50, 0);
node0 = new THREE.Mesh(geometry, material);
node0.position = position0;
scene.add(node0);
objects.push(node0);
node1 = new THREE.Mesh(geometry, material);
node1.position = position1;
scene.add(node1);
objects.push(node1);
var edge_def = new THREE.Geometry();
/*
* How to refresh this so that 'edge0' is always connected to 'node0' and 'node1'?
*/
edge_def.vertices.push(node0.position);
edge_def.vertices.push(node1.position);
/* …Run Code Online (Sandbox Code Playgroud)