How to convert this geometry opengl code to three.js?

Hi there, I am trying to follow this tutorial, where they show how to make a bending cylinder in C and opengl (at Edit2)

Would anyone who knows C be willing to turn this into a three.js codepen? Or explain how to do it in three.js

@Tintinabulator_Zea out of curiosity, is this like a college homework assignment or something? I think I’ve seen @prisoner849 answering this same question about three times in the last few weeks in StackOverflow.

@marquizzo it’s not homework, i’m not in school. It’s for a tool i’m working on, but i am stuck with some of the math language.

@Tintinabulator_Zea will you work with such tubular-like geometries only?

@prisoner849 yes only tubular geometries:)

@Tintinabulator_Zea Another idea from the twilight zone of my mind is: maybe an easier way is just to use THREE.TubeBufferGeometry() then? With some modifications, of course :slight_smile:

Here, radius should be depending on the function (sin, cos etc.) of an angle, which is var v = j / radialSegments * Math.PI * 2; (see it above in the source code)


I went the path of less resistance :smile:

Just created a tube geometry and used its source code as a base to distort it (with some modifications and simplifications) :slight_smile:

All the magic is in these lines:

      var radius = geometry.parameters.radius;
      radius += Math.abs(Math.sin(v * 2.5)); // radial half-waves
      radius += Math.sin(pointAt * Math.PI * 4); // wave along the path
      normal.applyAxisAngle(geometry.tangents[ i ], pointAt * Math.PI * 2); // twisting