Wavefront obj file format save function
Blitz3D Forums/Blitz3D Programming/Wavefront obj file format save function
| ||
| Hi, I'm trying to write a blitz3d function to save a mesh to a .obj wavefront format. I think i have a problem with the tag f into the obj file. Someone can help me please ?
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
Global c=CreateCube()
SaveToObj( c )
End
Function SaveToObj( pMesh )
fileout = WriteFile("mymesh.txt")
For i=1 To CountSurfaces( pMesh )
Surface_Handle = GetSurface( pMesh, i )
For j=0 To CountVertices( Surface_Handle ) - 1
vx# = VertexX#(Surface_Handle, j)
vy# = VertexY#(Surface_Handle, j)
vz# = VertexZ#(Surface_Handle, j)
WriteLine( fileout, "v " +vx+ " " + vy + " " + vz )
Next
Next
For i=1 To CountSurfaces( pMesh )
Surface_Handle = GetSurface( pMesh, i )
For j=0 To CountVertices( Surface_Handle ) - 1
vnx# = VertexNX#(Surface_Handle, j)
vny# = VertexNY#(Surface_Handle, j)
vnz# = VertexNZ#(Surface_Handle, j)
WriteLine( fileout, "vn " +vnx+ " " + vny + " " + vnz )
Next
Next
For i=1 To CountSurfaces( pMesh )
Surface_Handle = GetSurface( pMesh, i )
For j=0 To CountTriangles( Surface_Handle ) - 1
a = TriangleVertex(Surface_Handle, j,0)
b = TriangleVertex(Surface_Handle, j,1)
c = TriangleVertex(Surface_Handle, j,2)
WriteLine( fileout, "f " +a+ " " + b + " " + c )
Next
Next
CloseFile( fileout )
End Function
|
| ||
| Blitz3D numbers the vertices starting from 0. I think .obj expects them to start at 1. |