在移动物体之间画一条线

时间:2016-11-05 16:02:21

标签: javascript three.js

我正在尝试在两个移动顶点之间画一条线。顶点的绘图存储在名为Path = "D:\Test.pdf" Set App = CreateObject("Acroexch.app") app.show Set AVDoc = CreateObject("AcroExch.AVDoc") Set AForm = CreateObject("AFormAut.App") 'from AFormAPI If AVDoc.Open(Path,"") Then '// write some js code on a vbs variable js = "f = this.addField(""newField"", ""text"", 0, [250,650,20,600]);" &vblf _ & "f.value = ""any Text""; " &vblf _ & "f.flatten" '//execute the js code AForm.Fields.ExecuteThisJavaScript js end if Set AForm = Nothing Set AVDoc = Nothing Set APP = Nothing 的变量中,该变量的objectposition

这条线就是这样创造的:

THREE.Vector3

...,其中source和target是顶点,顶点通过以下方式更新:

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;
};

现在,我已将vertex.object.position.add(vertex.velocity); source.object.position分配给target.object.positionline.geometry.vertices[0],因为我希望其中一个更新。但相反,顶点位置从线位置变化很大。顶点就在它们的位置,但这些线不会连接到顶点。

如何使线条与顶点一起移动?

1 个答案:

答案 0 :(得分:4)

在动画循环中,您必须设置line.geometry.verticesNeedUpdate = true。因为每次渲染后它变为falsejsfiddle示例