gpt4 book ai didi

Three.js 可变半径管

转载 作者:行者123 更新时间:2023-12-02 19:28:47 25 4
gpt4 key购买 nike

我正在尝试沿着路径绘制一根 pipe ,而 TubeGeometry 对象似乎就是为此而设计的。然而,有一个问题 - 我还希望半径沿着路径的每个点都是可变的。基本上,我正在尝试绘制一个可变宽度的管。

我可以使用多个 pipe 和圆柱体来绘制它,但我忍不住认为必须有更好的方法。

最佳答案

WestLangley 的建议很有效。我最终创建了一个基于 THREE.TubeGeometry 的类,并进行了以下修改(R59):

  1. 修改了构造函数参数 radius,以采用表示每个控制点处半径的数字数组。
  2. 修改后的代码如下(引入 posRadius 变量并替换为 radius):
    for (i = 0; i < numpoints; i++) {
this.grid[i] = [];

u = i / (numpoints - 1);

pos = path.getPointAt(u);
var posRadius = this.radius[Math.floor((this.radius.length - 1) * u)];

tangent = tangents[i];
normal = normals[i];
binormal = binormals[i];

for (j = 0; j < this.radialSegments; j++) {

v = j / this.radialSegments * 2 * Math.PI;
// TODO: Hack: Negating it so it faces outside.
cx = -posRadius * Math.cos(v);
cy = posRadius * Math.sin(v);

pos2.copy(pos);
pos2.x += cx * normal.x + cy * binormal.x;
pos2.y += cx * normal.y + cy * binormal.y;
pos2.z += cx * normal.z + cy * binormal.z;

this.grid[i][j] = vert(pos2.x, pos2.y, pos2.z);

}
}

关于Three.js 可变半径管,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20955852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com