我正在尝试更新一个 arrowHelper。我试过操纵箭头对象的线中的顶点,设置所有内容dynamic = true
等等,但我似乎能做到的唯一方法是删除旧线并绘制一条新线。有没有办法更新 arrowHelper?
因此,您无法通过更改用于创建对象的值,以通常的方式更新 arrowHelper 本身。
但是:您可以移动箭头的位置,这会移动其明显的起点,并且您可以给它一个新的方向和长度,从而移动其明显的终点。
这是如何做到的:
// new arrowHelper
var sourcePos = new THREE.Vector3(0, 0, 0);
var targetPos = new THREE.Vector3(0, 50, 0);
var direction = new THREE.Vector3().sub(targetPos, sourcePos);
var arrow = new THREE.ArrowHelper(direction.clone().normalize(), sourcePos, direction.length(), 0x00ff00);
scene.add(arrow);
// update the arrow
var newSourcePos = new THREE.Vector3(10, 10, 10);
var newTargetPos = new THREE.Vector3(60, 10, 10);
arrow.position.set(newSourcePos);
direction = new THREE.Vector3().sub(newTargetPos, newSourcePos);
arrow.setDirection(direction.normalize());
arrow.setLength(direction.length());
Run Code Online (Sandbox Code Playgroud)