【发布时间】:2021-05-21 03:16:06
【问题描述】:
我正在尝试沿 Three.js 中的路径移动对象。我想以“构造”方式构建路径,使用 Path 对象,如下所示:
var path = new THREE.Path([
new THREE.Vector2(0, 0),
new THREE.Vector2(0, inDistance)
]);
path.arc(arcRadius, 0, arcRadius,
Geo.rad(180), Geo.rad(90), true);
path.lineTo(arcRadius + outDistance, arcRadius + inDistance);
然后我可以使用path.getPoint(t) 和path.getTangent(t) 来获取我的对象的更新位置:
let position = path.getPoint(percentTraveled);
let tangent = path.getTangent(percentTraveled);
state.model.position.x = position.x;
state.model.position.y = position.y;
这样做有两个问题:
- 路径只有二维
- Path 对象无法转换为对象的位置和方向,因此返回的位置/切线是绝对位置。
我读过this question,其中讨论了如何使用SplineCurve3 沿路径移动,但该解决方案没有说明如何构建由一组直线和圆弧构成的样条线。
你是怎么做到的?
【问题讨论】:
-
我的回答没有解决您的问题吗?有什么遗漏吗?
-
对不起,第二个答案是我想的我需要的,买我还没有机会申请它。它在我的队列中,一旦我确认它对我有意义,我会接受答案!
标签: javascript three.js