Threejs: Draw elbow with begin radius and end radius

Viewed 193

I'm new to Threejs. I'm trying to draw an elbow with different begin_radius and end_radius along a curve path with the curve_radius and an angle, however couldn't achieve results.

  • CylinderGeometry have begin_radius and end_radius but doesn't have curve path
  • TorusGeometry have curve_radius and angle but doesn't have begin_radius and end_radius, as well as it is not solid.
  • LatheGeometry had same limitation as CylinderGeometry
  • ExtrudeGeometry had same limitation as TorusGeometry
  • TubeGeometry had same limitation as TorusGeometry

Probably I'm overlooking the above geometries. Please guide some approach.

--EDIT: June 1 2020--

https://jsfiddle.net/arundhaj/ysfr8jb0 I've somehow managed to extend TubeGeometry to achieve the variable radius. However still couldn't able to make it solid. I've taken generateCap function from CylinderGeomery to add cap at the beginning and end of the arc. It works fine when I add only one cap, however if I add both the cap, shape is getting distorted.

Please help.

enter image description here

1 Answers

To my mind, I think the best solution would be to customize a thorus geometry to have at least the begin_radius and end_radius parameters.

What you could do is take the original file and replace the static radius argument by a gradient definition in there :

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

      }

  }

The remaining problem would just be to understand how to increase properly the right parameters, you'd have to test a bit to understand which parameters you need to change.

Related