MeshToolkit allows exporting obj, dae, stl etc. which is great. However, what I need is basically an array of the file contents rather than writing to a file. This should be pretty straightforward to implement, right?
If it is too specific a demand, do you have any suggestions on how I achieve this in another way?
I fixed it. If anyone else is interested, here is my code:
def meshToObj(mesh):
normals = mesh.VertexNormals()
vertices = mesh.Vertices()
triangles = mesh.Triangles()
vn = ''.join(["vn %s %s %s\n" % (str(int(v.X)),str(int(v.Y)),str(int(v.Z))) for v in normals ])
v = ''.join(["v %s %s %s\n" % (str(p.X),str(p.Y),str(p.Z)) for p in vertices ])
f = ''
for t in triangles:
points = [vt.PointGeometry for vt in t.Vertices]
idx = [vertices.IndexOf(p)+1 for p in points]
f+= "f %s//%s %s//%s %s//%s\n" % (idx[0],idx[0],idx[1],idx[1],idx[2],idx[2])
return v+vn+f
solved, closing
Most helpful comment
I fixed it. If anyone else is interested, here is my code: