When exporting an
.obj object for use within Three.js, you will likely use the
OBJLoader.js for importing the object.
One thing the OBJLoader does not support, are objects with n-gons.
In order for the object to correctly import, every face can have maximum 4 edges. I made a script that will automatically check if these faces are present and change them to quads/triangles.
First, we loop over all the objects in the scene
(1) and check if the object is a mesh
(2). When we have a mesh, we will make that mesh the currently active object
We do this to make sure we have the right object selected when we are going into EDIT mode
(4). In EDIT mode, we make sure we are going to work with the faces
(5), and deselect all faces that would currently be selected
After that, we search and select all the faces that have more than 4 edges
(7). We triangulate these faces
(8), and then attempt to convert these triangles into quads
Last but not least, before moving on and searching for the next mesh, we set the scene back into object mode