Breadcrumb
Breadcrumb

Reputation: 31

How do I create a 3D polygon from a series of 3D points in three.js?

I wonder what would be the best way to generate a custom 3D polygon given an array of 3D points in three.js. It is a simple polygon without holes. The points are ordered so that they represent neighboring vertices.I can do it in 2D, but I don't want the vertices to be coplanar. Thank you for your help!

Upvotes: 3

Views: 4327

Answers (2)

Ilya
Ilya

Reputation: 1

The question is pretty old but someone who's looking for an answer as I did may try to use ConvexGeometry or ConvexHull

Upvotes: 0

Martin Schuhfuß
Martin Schuhfuß

Reputation: 6986

The main problem here is how to create a 3D mesh from a bunch of points. In other words: you need to figure out which of the vertices should be connect to form a triangle.

This is an surprisingly complicated thing to do (well, at least I was surprised) and there are tons of scientific papers, libraries and so on about that.

However, in your case it is a bit simpler as you already know roughly how the vertices should get connected. I would recommend you have a look at the earcut-library or libtess.js, both of which should be able to create the triangulations you need.

Once you have that, you can roughly go with @lior-trau's recommendation for how to create the geometry from the result.

Upvotes: 3

Related Questions