Three.js - 如何更新 arrowHelper? [英] Three.js - how can I update an arrowHelper?

查看:40
本文介绍了Three.js - 如何更新 arrowHelper?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新一个 arrowHelper.我试过操作箭头对象线中的顶点,设置所有 dynamic = true 等等,但我似乎能做到的唯一方法是删除旧线并绘制一条新线.有没有办法更新 arrowHelper?

I'm trying to update an arrowHelper. I've tried manipulating the vertices in the arrow object's line, setting everything dynamic = true and so on, but the only way I can seem to do it is by removing the old line and drawing a new one. Is there a way to update an arrowHelper?

推荐答案

因此,您无法通过更改用于创建对象的值,以通常的方式更新 arrowHelper 本身.

So you can't update an arrowHelper per se in the usual way you update something, by changing the values you used to create the object.

但是:您可以移动箭头的位置,从而移动其明显的起点,并且您可以给它一个新的方向和长度,从而移动其明显的终点.

However: you can move the arrow's position, which moves its apparent start point, and you can give it a new direction and length, which moves its apparent end point.

方法如下:

// 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());

这篇关于Three.js - 如何更新 arrowHelper?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆