How to modify the source code of TorusGeometry to close both ends?

Hi everyone,

I’m trying to modify the source code of TorusGeometry in Three.js in order to make the rendered torus closed on both ends. I have looked at the source code of CylinderGeometry and I understand that the key point lies in how to generate the vertices, normals, and uvs for the end caps. However, I’m not sure how to proceed and implement this.

I have created a CodePen example that you can directly modify and run: https://codepen.io/laddishx/pen/dyLQbdQ

Could anyone please guide me on how to generate the vertices, normals, and uvs for the end caps properly? I would greatly appreciate any help or suggestions.

Thank you very much.

Hi!
You can merge geometries (torus and two circles), getting a new one:

Example: https://codepen.io/prisoner849/full/BaEGazQ

4 Likes

Thank you for your solution! :smiling_face_with_three_hearts: It’s a brilliant idea to merge the geometries of the torus and two circles to achieve the desired result. :star_struck: I appreciate your creative thinking and sharing this approach with me. I will definitely give it a try and see if it works for my case. Thanks once again! :two_hearts:

1 Like

@Joe_Perry
I extended the codepen provided above, added the approach with a bent cylinder (the aqua one there):

2 Likes

Just wanted to say a quick thank you for your suggestion to merge the geometries and for inspiring me to explore further.

I successfully achieved a torus with a square cross-section using box geometry. :blush:


It’s been such a fun process, and now I feel like I can “bend everything” with my newfound knowledge. :rofl:

Your help and guidence has been greatly appreciated! :smiling_face_with_three_hearts:

1 Like