Non tri faces to mesh


I have a model defined by a list of vertices and a list of faces. But the faces aren’t all triangles but can be any flat convex polygons (triangle, square, pentagon, etc). aka they can be tris, quads and n-gons.

// vertices, list of x,y,z
let vertices = [ 

// faces, list of list of indices of vertices
let faces = [
  [1,2,3], // a tri
  [2,3,4,5], // a quad
  [6,7,8,9,10], // a penta
  [4,6,8], // a tri

(for instance a box could be defined by 6 quad faces instead of the usual 12 tris).

I’m thinking of using VertexData and converting every non tri to some tris by a simple fan triangulation but I was wondering if something like that already exists in BJS.

And is this the most efficient way to do this (I can sometimes have 300k+ faces) both in term of time to compute and memory/typescript efficiency ?

Additionally how can I render the orignal faces in wireframe (so without seeing the triangulation) ?


You could potentially use lines to draw the faces outlines but as as bjs features to triangulate, i do not think we have such things in stock.

Maybe ear ut provide some ?

Else @jerome or @Cedric might have some ideas ?

If you can’t use your DCC to triangulate, then I’d add a process to do it once it’s loaded.
Maybe have 2 meshes: one triangulate for filled rendering and 1 with lines for wire display.
Also, you can try to display lines as a post process to check for normal discontinuities. This implies normals are per face and are the same for all face rasterization.

no DCC used. everything is generated directly in the browser by a typescript algorithm which produces tris, quads and n-gons.

So I guess so far doing fan triangulation is the only solution.


1 Like