I've been writing this ASE importer since last night, and it seems I've got something that works partially (for creating geometry, I've yet to finish anything relating to texturing or uvw mapping). But one problem I've been encountering if a few faces are incorrectly created, which is what's bothering me now. So I was wondering if anyone would mind taking a look at it and telling me if they can see any issues. I'm assuming it's a problem with the way I'm retrieving the vertex numbers and such, but a second opinion would be nice. So, here's the code:
Type ASEMESH
Field mesh
Field surf
End Type
Dim Vertices#(1)
Function ImportASE(file$,scale#,FlipYZWhen3dsImport)
If FileType(file$) = 1 Then
ASE = ReadFile(file$)
Else
DebugLog "File does not exist"
Return False
EndIf
M.ASEMESH = New ASEMESH
m\mesh = CreateMesh()
m\surf = CreateSurface(m\mesh)
While Not Eof(ASE)
CurrentLine$ = ReadLine(ASE)
Repeat
If Left(CurrentLine,1) = " " Or Right(CurrentLine,1) = " " Then
CurrentLine = Trim(CurrentLine)
Else
NoSpaces = True
EndIf
Until NoSpaces
If Instr(CurrentLine,"*MESH_NUMVERTEX") Then
VertCount$ = Replace(CurrentLine,"*MESH_NUMVERTEX ","")
VertCount = Int(VertCount)
Dim Vertices#(VertCount)
DebugLog VertCount
EndIf
If Instr(CurrentLine,"*MESH_NUMFACES") Then
Faces$ = Replace(CurrentLine,"*MESH_NUMFACES ","")
Faces = Int(Faces)
DebugLog Faces
EndIf
If Instr(CurrentLine,"*MESH_VERTEX_LIST") Then
For x = 1 To VertCount
CurrentLine$ = ReadLine(ASE)
Vline$ = Right(CurrentLine,Len(CurrentLine)-21)
Vline$ = Trim(Vline)
DebugLog Vline
VX$ = Trim(Left(Vline,7))
VZ$ = Trim(Right(Vline,7))
Vline$ = Replace(Vline$,VX,"")
Vline$ = Replace(Vline$,VZ,"")
VX = Float(VX)
VY# = Trim(Vline$)
VZ = Float(VZ)
DebugLog Vline
DebugLog "VX: "+VX+" VY: "+VY+" VZ: "+VZ
If FlipYZWhen3dsImport Then
Vertices(x-1) = AddVertex(m\surf, VX, VZ, VY)
Else
Vertices(x-1) = AddVertex(m\surf, VX, VY, VZ)
EndIf
Next
EndIf
If Instr(CurrentLine,"*MESH_FACE_LIST") Then
For x = 1 To Faces
CurrentLine$ = ReadLine(ASE)
Repeat
U = U + 1
Fline$ = Mid(CurrentLine,U,4)
If Left(Fline,2) = "A:" Then Y = True
Until Y
Repeat
V = V+1
Fline$ = Mid(CurrentLine,U,V)
If Right(Fline,2) = "C:" Then Z = True
Until Z
Fline$ = Mid(CurrentLine,U,V+6)
Fline$ = Replace(Replace(Replace(Fline$,"A:",""),"B:",""),"C:","")
U = 0 : V = 0 : Y = 0 : Z = 0
For W = 0 To 5
Fline$ = Trim(Fline$)
Next
V1 = Int( Trim( Left(Fline, 4) ) )
V3 = Int( Trim( Right( Fline, 4) ) )
V2 = Int(Replace( Replace(Fline, V1, ""), V3, "" ))
DebugLog Fline
AddTriangle(m\surf,Vertices(v1),Vertices(v2),Vertices(v3))
DebugLog "V1: "+V1+" V2: "+V2+" V3: "+V3
Next
EndIf
Wend
And, if you want an ASE model so you can see what they look like (the format), download this. Any help would be greatly appreciated. Thanks in advance :)
|