THREE.js triangulation

I currently have a set of vectors and would like to perform triangulation.
I know there’s earcut but it only performs on 2D.
My question is the following:
if I have a custom shape or a set of vectors how can I get all the triangles coordinates (I guess it’s also named faces) of this shape.
Thanks in advance

That is a very general formulation. How specifically is the shape described? Where do the vectors come from? Are they points on a surface?

I have carried out special triangulations.

Addon for triangulation of implicit surfaces/ forms with holes
Triangulation sphere with holes
Triangulation cylinder with holes
Inner Geometry (Triangulation)

1 Like

@hofk First thank you for your answer.
The points represents a set of speakers positionned in space onto a convex hull (Sphere). I need to get speakers by triplets ( faces )

According the documentation there is a third parameter dim that represents the dimension of the vertices. For 3D vertices you should be using dim=3. Have you tried whether 3D earcut works fine?

BTW, I’m not sure you actually need triangulation (i.e. I’m still struggling to understand what you actually want to do).

@PavelBoytchev thanks for your answer
the documentation of earcut says

Note that Earcut is a 2D triangulation algorithm, and handles 3D data as if it was projected onto the XY plane (with Z component ignored).

I’m implementing the VBAP alogrihtm where a certain number of speakers are positionned onto a convex hull.The sound is then played on a set of three speakers (triplet).The triangulation algorithm would help me get the sets of speakers 3 by 3.Any ideas?

1 Like

The link to the paper is not accessible to me. I do not understand “get the sets of speakers 3 by 3”. Somehow there must be some rule how to select 3x3 speakers out of all speakers. I have absolutely no idea what this rule might be. If you can formalize the rule of selection, then you might be able to translate it into code.

1 Like

If I’m right, it’s this topic - isn’t it? Working with Sphere :thinking:

@hofk exactly

@PavelBoytchev if you have let’s say 4 speakers ( 4 points ) Then you have 2 sets of 3 speakers. just a simple triangulation but in 3D

Still struggling. Am I close with this:

  • you have a cloud of points in 3D space
  • the points are on (or approximately on) the surface of an imaginary sphere
  • you want to make a mesh of triangles using these points as vertices.

If this is the case, I’d suggest to try the ConvexGeometry. If all points are on a sphere, then there are no internal points and all points will all take part in the convex hull … which is made of triangles.

@PavelBoytchev so yes all the points are onto the convex hull but my question is how can I get all the coordinates of one mesh of the geometry?thanks

Generally the coordinates of all vertices of a mesh are stored in the position attribute of its geometry. You can get this data and retrieve the XYZ of each vertex.

@PavelBoytchev I know that but I need the vertices of one mesh by one mesh.I don’t need only the vertices.

I’m sorry. My confusion increases exponentially. I do not understand this “one mesh by one mesh”. I do not understand how knowing vertex position will help you with triangulation. I do not understand how 4 speakers will make 2 sets of three speakers (as I can see 4 sets of 3 speakers each – the number of faces of tetrahedron). As I’m not native English speaker, it is most likely my fault for this misunderstanding. Again, I’m sorry. I hope someone could provide adequate help.

1 Like


@PavelBoytchev I’ll try one last time
I need the coordinates of each triangles vertices ( first triangle [[ x, y, z ],[x,y,z],[x,y,z]] then second triangle [[ x, y, z ],[x,y,z],[x,y,z]]) THanks in advance, if you don’t understand I won’t bother.

@hofk I’ve looked a bit sounds great but how can I install it I don’t see any npm packages (I guess I need to import the script in my project). Isn’t there a more lightweight solution, I will use that in a commercial app so I hope the licence is MIT? Thanks

This demo defines randomly N positions on a sphere (the speakers), then builds a triangular mesh from their positions and finally shows one by one the triangles (marking their vertices with red spheres).

https://codepen.io/boytchev/full/emOjwOB

image

5 Likes

@PavelBoytchev I guess this is exactly what I need. I’ll dive into the code and once understood I’ll mark that as a solution.You have done this just for me or is this an already made script?If you have done this just for me I really appreciate that.Thank you a lot

1 Like

I did it just now to show what I mean by using ConvexGeometry and its position attribute.

1 Like

There are different variants:

See the examples e.g.

THREEi.js/examples/InnerGeometryTHREEi_01.html at 6864a2786ca533edb59fb0bccf1df6bab1b664b9 · hofk/THREEi.js · GitHub
THREEi.js/examples/sphereWithHolesTHREEi.html at 6864a2786ca533edb59fb0bccf1df6bab1b664b9 · hofk/THREEi.js · GitHub

< script src=“…/js/THREEi.js”>< /script>

or as function see e.g. TriangulationSphereWithHoles


Yes, see there: GitHub - hofk/THREEi.js: three.js addon for triangulation of implicit surfaces and for forms with holes. The addon generates indexed BufferGeometries.

"THREEi
three.js addon for triangulation of implicit surfaces and for forms with holes. The addon generates indexed BufferGeometries.

License identical to three.js "

2 Likes