如何在 Three.js 中创建倾斜的圆柱体/圆锥体
我正在努力弄清楚如何在 Three.js 中绘制倾斜的圆柱体。本质上,我想生成一个顶部半径为 r1 、底部半径为 r2 (即半径不同)的圆柱体,圆柱体的顶部和底部偏移特定因子,假设为 x。
我可能不想绘制 360 度的圆柱体,可能只想绘制其中的一部分(比如 90 度)。
我被已经存在的圆柱体函数所吸引,因为它勾选了我想要的大多数框,例如我可以给出开始和结束角度以及不同的顶部和底部半径。唯一的问题是试图实现顶部和底部之间的偏移。
我对 Three.js 相当陌生,所以可能有一些技术或方法可以实现这一点,但我尝试过搜索,但没有找到任何有帮助的东西。
I'm struggling to work out how to draw an oblique cyclinder in three.js. Essentially, I would like to produce a cylinder with a top radius of r1 and a bottom radius of r2 (ie not the same radii), with the top and bottom of the cylinder offset by a particular factor, let's say x.
I might not want to draw 360 degrees of the cylinder, maybe only a portion of it (say 90 degrees).
I'm drawn to the cylinder function already present as this ticks most of the boxes that I want, as in I can give a start and end angle, and differing top and bottom radii. The only issue is trying to achieve the offset between the top and bottom.
I'm reasonably new to three.js, so there may be some technique or way to achieve this, but I've tried searching and haven't come up with anything that helps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
CylinderGeometry
的自定义版本来实现此目的。这里的代码大部分借自 CylinderGeometry ,但变化是不再定义开始和结束radius,您传入一个函数,该函数会为圆柱体的每个“层”调用,并且它需要返回一个 4 数字数组:
[centerX、layerY、centerZ、radius]
。这允许具有不均匀高度和中心的圆柱体和圆锥体几何形状。
例如,在 CodeSandbox 的示例中,勾勒出这个,其功能是
,结果是一个时髦的螺旋花瓶:
对于倾斜的圆柱体,您需要更简单的东西:
产生
You can implement this with a customized version of
CylinderGeometry
.The code here is mostly borrowed from CylinderGeometry, but with the change that instead of defining a start and end radius, you pass in a function that gets called for each "layer" of the cylinder, and it needs to return a 4-array of numbers:
[centerX, layerY, centerZ, radius]
.This allows for cylinder- and cone-like geometries with an uneven height and center.
For instance, in the example in the CodeSandbox where I sketched this out, the function is
and the result is a funky spiraling vase of sorts:
For a skewed cylinder, you'd want something simpler:
yields