I have this in stock:
It is a basic implementation for static mesh (file read only, mesh building is a another task). It could be a good start for something more complete.
It requires IanM's Matrix1 DLLs
ObjModelHeader:
Type TOBJVertexPos
X#, Y#, Z#
EndType
Dim ObjModelVerticesPos(0) As TOBJVertexPos
Type TOBJTexCoords
u#, v#
EndType
Dim ObjModelTexCoords(0) As TOBJTexCoords
Type TOBJFace
Vertex1, Vertex2, Vertex3
TexCoords1, TexCoords2, TexCoords3
Group, FaceZone
EndType
Dim ObjModelFaces(0) As TOBJFace
Global ObjModelVertexCount, ObjModelTexCoordCount, ObjModelFaceCount
Return
`_____________________________________________________________________________________________________
Function ObjModel_Load(FileName$, ProgressFunction As DWORD)
ObjModelScale# = 1.0
Open To Read 1, FileName$
Delims$ =" " + Tab$()
Group = -1
Error = 0
ObjModelVertexBufferSize = 0
ObjModelFaceBufferSize = 0
ObjModelTexCoordBufferSize = 0
lc = 0
LineCount = 0
Do
Inc lc
Inc LineCount
If lc > 999
Progress# = Progress# + 1.0
If Progress# > 100.0 Then Progress# = 100.0
lc = 0
If ProgressFunction Then Call Function Ptr ProgressFunction, Progress#
EndIf
Read String 1, s$
l$ = Fast Upper$(Mid$(s$, 1))
If l$ = "V" Then Inc ObjModelVertexBufferSize
If l$ = "V" And Fast Upper$(Mid$(s$, 2)) = "T" Then Inc ObjModelTexCoordBufferSize
If l$ = "F" Then Inc ObjModelFaceBufferSize
If File End(1) Then Exit
Loop
Close File 1
UnDim ObjModelVerticesPos(0)
UnDim ObjModelFaces(0)
UnDim ObjModelTexCoords(0)
Dim ObjModelVerticesPos(ObjModelVertexBufferSize) As TOBJVertexPos
Dim ObjModelFaces(ObjModelFaceBufferSize) As TOBJFace
Dim ObjModelTexCoords(ObjModelTexCoordBufferSize) As TOBJTexCoords
ObjModelVertexCount = 0
ObjModelTexCoordCount = 0
ObjModelFaceCount = 0
ObjModelGroup = 0
Open To Read 1, FileName$
lc = 0
Do
Inc lc
Inc CurrentLine
If lc > 99
Progress# = (CurrentLine * 100.0) / (LineCount * 1.0)
lc = 0
If ProgressFunction Then Call Function Ptr ProgressFunction, Progress#
EndIf
Read String 1, s$
Split String s$, Delims$
SplitCount = Split Count()
If SplitCount
w1$ = "": w2$ = "": w3$ = ""
If SplitCount > 1
w = 1
For i = 2 To SplitCount
If Get Split Word$(i) <> ""
If w = 1 Then w1$ = Get Split Word$(i)
If w = 2 Then w2$ = Get Split Word$(i)
If w = 3 Then w3$ = Get Split Word$(i)
Inc w
EndIf
Next i
EndIf
Cmd = 0
If Get Split Word$(1) = "v" Then cmd = 1
If Get Split Word$(1) = "vt" Then cmd = 2
If Get Split Word$(1) = "g" Then cmd = 3
If Get Split Word$(1) = "f" Then cmd = 4
If Cmd = 1
Inc ObjModelVertexCount
ObjModelVerticesPos(ObjModelVertexCount).X# = Val(w1$) * ObjModelScale#
ObjModelVerticesPos(ObjModelVertexCount).Y# = Val(w2$) * ObjModelScale#
ObjModelVerticesPos(ObjModelVertexCount).Z# = Val(w3$) * ObjModelScale#
EndIf
If Cmd = 2
Inc ObjModelTexCoordCount
ObjModelTexCoords(ObjModelTexCoordCount).u# = Val(w1$)
ObjModelTexCoords(ObjModelTexCoordCount).v# = Val(w2$)
EndIf
If Cmd = 3 Then Inc Group
If Cmd = 4
Inc ObjModelFaceCount
V1 = 0: V2 = 0: V3 = 0: TC1 = 0: TC2 = 0: TC3 = 0
Split String w1$, "/"
SplitCount = Split Count()
If SplitCount = 2 Then V1 = IntVal(Get Split Word$(1)): TC1 = IntVal(Get Split Word$(2))
Split String w2$, "/"
SplitCount = Split Count()
If SplitCount = 2 Then V2 = IntVal(Get Split Word$(1)): TC2 = IntVal(Get Split Word$(2))
Split String w3$, "/"
SplitCount = Split Count()
If SplitCount = 2 Then V3 = IntVal(Get Split Word$(1)): TC3 = IntVal(Get Split Word$(2))
ObjModelFaces(ObjModelFaceCount).Vertex1 = V1
ObjModelFaces(ObjModelFaceCount).Vertex2 = V2
ObjModelFaces(ObjModelFaceCount).Vertex3 = V3
ObjModelFaces(ObjModelFaceCount).TexCoords1 = TC1
ObjModelFaces(ObjModelFaceCount).TexCoords2 = TC2
ObjModelFaces(ObjModelFaceCount).TexCoords3 = TC3
ObjModelFaces(ObjModelFaceCount).Group = Group
EndIf
EndIf
If File End(1) Then Exit
Loop
Close File 1
rem Print Console "ObjModelLoad: ", ObjModelVertexCount," Vertices / "
rem Print Console ObjModelTexCoordCount," TexCoords / "
rem Print Console ObjModelFaceCount," Faces ", CRLF$()
rem Print Console Group+1," groups ", CRLF$()
If ProgressFunction Then Call Function Ptr ProgressFunction, 100.0
EndFunction Error
`_____________________________________________________________________________________________________
Function ObjModel_SwapYZ()
VertexCount = Array Count(ObjModelVerticesPos(0))
For v = 0 To VertexCount
Y# = ObjModelVerticesPos(v).Y#
Z# = ObjModelVerticesPos(v).Z#
ObjModelVerticesPos(v).Y# = Z#
ObjModelVerticesPos(v).Z# = Y#
Next v
EndFunction
`_____________________________________________________________________________________________________
Function ObjModel_ReverseNormals()
FaceCount = Array Count(ObjModelFaces(0))
For f = 1 To FaceCount
V1 = ObjModelFaces(f).Vertex1
ObjModelFaces(f).Vertex1 = ObjModelFaces(f).Vertex3
ObjModelFaces(f).Vertex3 = V1
TC1 = ObjModelFaces(f).TexCoords1
ObjModelFaces(f).TexCoords1 = ObjModelFaces(f).TexCoords3
ObjModelFaces(f).TexCoords3 = TC1
Next f
EndFunction