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

geometry

#1

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


#2

@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.


#3

@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.


#4

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


#5

@prisoner849 yes only tubular geometries:)


#6

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


#7

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