# Open the file in read mode file = open("test.obj", "r") # Read the entire content of the file content = file.read().split("\n") file.close() startVerts = 0 verts = [] for index,line in enumerate(content): if line[0] == 'o': startVerts = index + 1 content = content[startVerts:] break for index,line in enumerate(content): if "vn" in line: endVerts = index verts = content[:endVerts] content = content[endVerts:] break startFaces = 0; faces = [] for index,line in enumerate(content): if line[0] == 'f': startFaces = index faces = content[startFaces:-1] break verts = ["vec3(" +",".join(vert.split(" ")[1:4]) + ")" for vert in verts] faces = [ ",".join([str(int((d.split("/")[0])) - 1) for d in face.split(" ")[1:4]]) for face in faces] out = "#include \"model.hpp\" \n const model testModel({" + ",".join(verts) +"},{" + ",".join(faces) + "});" with open("testModel.hpp", "w") as f: f.write(out) print(out) # Close the file