【问题标题】:Threejs: Draw elbow with begin radius and end radiusThreejs:用开始半径和结束半径绘制弯头
【发布时间】:2020-09-12 19:39:16
【问题描述】:

我是 Threejs 的新手。我正在尝试使用curve_radiusangle 沿着曲线路径绘制具有不同begin_radiusend_radius 的肘部,但是无法获得结果。

  • CylinderGeometrybegin_radiusend_radius 但没有曲线路径
  • TorusGeometrycurve_radiusangle 但没有begin_radiusend_radius,也不是实心的。
  • LatheGeometryCylinderGeometry 具有相同的限制
  • ExtrudeGeometryTorusGeometry 具有相同的限制
  • TubeGeometryTorusGeometry 具有相同的限制

可能我忽略了上述几何形状。请指导一些方法。

--编辑:2020 年 6 月 1 日--

https://jsfiddle.net/arundhaj/ysfr8jb0 我设法扩展TubeGeometry 以实现可变半径。但是仍然无法使其坚固。 我从CylinderGeomery 中使用generateCap 函数在弧的开始和结束处添加上限。当我只添加一个帽子时效果很好,但是如果我同时添加两个帽子,形状就会变形。

请帮忙。

【问题讨论】:

标签: angular typescript three.js


【解决方案1】:

在我看来,我认为最好的解决方案是自定义一个thorus 几何体,使其至少具有begin_radiusend_radius 参数。

您可以做的是使用original file 并用其中的渐变定义替换静态radius 参数:

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

      for ( i = 0; i <= tubularSegments; i ++ ) {

          var u = i / tubularSegments * arc;          
          var v = j / radialSegments * Math.PI * 2;

          // vertex

          vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
          vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
          vertex.z = tube * Math.sin( v );

          vertices.push( vertex.x, vertex.y, vertex.z );

          // normal

          center.x = radius * Math.cos( u );          
          center.y = radius * Math.sin( u );          
          normal.subVectors( vertex, center ).normalize();

          normals.push( normal.x, normal.y, normal.z );

          // uv

          uvs.push( i / tubularSegments );            
          uvs.push( j / radialSegments );

      }

  }

剩下的问题就是要了解如何正确增加正确的参数,您必须进行一些测试以了解需要更改哪些参数。

【讨论】:

  • 我也尝试过你的方法jsfiddle.net/arundhaj/7cs9kvrj,但仍然试图通过在顶部和底部添加上限来使其看起来更稳固。
  • 您可以只创建一个具有良好半径的 CircleGeometry 对象(一端为半径,另一端为 endRadius),计算两端圆心的位置,将其从自定义管几何的中心,然后围绕右轴旋转 Math.PI/2 以创建帽。
  • 如果我是你,我会这样做,但更准确地说,我会创建一个新的 THREE.Group,从您的自定义 TubeGeometry 创建一个对象,并分别创建两个具有圆形几何形状和相同材料的盖子tubeGeometry,然后将它们移动到正确的位置
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-31
  • 1970-01-01
  • 2021-09-28
  • 2013-07-29
  • 2011-12-23
相关资源
最近更新 更多