Here is a function I have made, which loads a .ase model file. It was made specific to my current openGL 3D engine, so its not 100% generic, but the way a .ase file is processed would be the same regardless of language, and Bmax is fairly easy to read through, so I figured that someone might be able to gain something from it.
It will process vertices, normals, faces.
Function loadASEmodel:TMesh(loadfile:String)
Local tmp:TMesh = TMesh.init()
Local v1:String, v2:String, v3:String
Local f1:Int, f2:Int, f3:Int, l:String
Local a:Int, b:Int, i:Int, vertices:Int, faces:Int
Local filein:TStream = ReadFile(loadfile)
Repeat
l = ReadLine(filein)
Until Instr( l, "*MESH_NUMVERTEX" ) ' find the point where the vetrice And face number is
l = Trim( l ) ' remove all unnecessary spaces
l = Right( l, Len( l )-16 ) ' find the vertex number
vertices = Int( l )
l = ReadLine(filein) ' read next line to get face number
l = Trim( l ) ' remove all unnecessary spaces
l = Right( l, Len( l )-15 ) ' find the face number
faces = Int( l )
l = ReadLine(filein) ' skip one line
For a = 1 To vertices
l = ReadLine( filein )
l = Trim( l ) ' remove all unnecessary spaces
l = Right( l, Len( l )-11 ) ' find the vertex data
l = Replace( l, " ", "," )
v1 = NthField( l, Chr(9), 2 )
v2 = NthField( l, Chr(9), 3 )
v3 = NthField( l, Chr(9), 4 )
tmp.addVertex(Float(v1),Float(v2),Float(v3))
Next
Repeat
l = ReadLine(filein)
Until Instr( l, "*MESH_FACE_LIST {" ) ' locate face list
For a = 1 To faces
l = ReadLine(filein)
l = Trim( l ) ' remove all unnecessary spaces
l = Right( l, Len( l ) - 10 )
l = Left(l, 61)
f1 = Int(Mid(l, 13,5))
f2 = Int(Mid(l, 21,5))
f3 = Int(Mid(l, 29,5))
tmp.addFace(f1,f2,f3)
Next
Repeat
l = ReadLine(filein)
Until Instr( l, "*MESH_NORMALS {" ) ' find the point where the vetrice And face normals are
For a = 1 To faces
l = ReadLine(filein)
l = Trim( l )
l = Right( l, Len( l )-19)
If Left( l, 1 ) = Chr(9) Then l = Right( l, Len( l )-1 )
l = Replace( l, Chr(9), "," )
v1 = NthField( l, ",", 1 )
v2 = NthField( l, ",", 2 )
v3 = NthField( l, ",", 3 )
tmp.addFaceNormal(Float(v1),Float(v2),Float(v3))
For b = 1 To 3
l = ReadLine(filein)
l = Trim( l )
l = Right( l, Len( l$ )-20)
If Left( l, 1 ) = Chr(9) Then l = Right( l, Len( l )-1 )
l = Replace( l, Chr(9), "," )
v1 = NthField( l, ",", 1 )
v2 = NthField( l, ",", 2 )
v3 = NthField( l, ",", 3 )
tmp.addVertexNormal(Float(v1),Float(v2),Float(v3))
Next
Next
CloseFile(filein)
Print "V:"+vertices
Print "F:"+faces
Return tmp
End Function
' Given a String, a delimiter, And a n -- returns the nth Field
Function NthField:String(s:String, delim:String, n:Int)
Local o:Int = 1
For Local i:Int = 1 To n - 1
o = Instr(s, delim, o)
If o = 0 Then
Return ""
End If
o = o + 1
Next
Local p:Int = Instr(s, delim, o)
If p = 0 Then
Return Mid(s, o)
Else
Return Mid(s, o, p - o)
End If
End Function