I have been struggling with mesh triangulation in Three.js. I have to create a roof based on the shape of the house which is represented by a polygon. Now this polygon could be somewhat irregular, not always in rectangular shape and the algorithm must dynamically adapt to different polygon shapes. I am stuck at computing the normals for this roof mesh.
Thanks in advance!
Just to clarify your question – you have made the geometry of the roof, you have all its data ready (e.g. coordinates of vertices, faces, etc) … and you only need to define the normal vectors. Is my understanding correct?
Something like this should do the trick — triangulate-polyline - npm … if you know other constraints (no holes? convex polygons?) simpler options would probably exist too.
Hi guys @PavelBoytchev @donmccurdy,
Sorry for the late reply and thank you for checking my question. I did manage to triangulate using the earcut algorithm and then computed normals using
mesh.geometry.computeVertexNormals(). I hope this way will not mess up my shading. I haven’t tried yet but I’ll have to soon.