I wont be able to debug your code directly as serializing mesh files falls outside the scope of our support but based on the images The issue with your function appears to be related to how the vertex indices are written to the file in the face definitions. OBJ files are 1-indexed, meaning the vertex indices should start from 1, but your code might be incorrectly handling indices or the vertex order in a way that causes incorrect connections between vertices.