.ASE Importer

Blitz3D Forums/Blitz3D Programming/.ASE Importer

N(Posted 2003) [#1]
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 :)


MarkT(Posted 2003) [#2]
There is a guy named fredborg or somthing like that and he created a great and i mean excelent .3ds and .ase importer. He had a little challenge that if you could find a model that his importer wounld load he would give you the source. Well i found a model, but unfortunalty he didnt have the .ase importer workign when he gave me the source. I cant give the source away, but when i get home i can check and see what he does in his and maybe help you a little


fredborg(Posted 2003) [#3]
Hi,

The ASE format is a bit tricky to convert to Blitz, but it is totally possible, I know coz I've written an importer.

The thing is that the number of vertices, texture vertices, faces, and texture faces are intertwined in a very complex way. And it takes quite a bit of swapping around, and matching data with each other, to get the end result perfect. I'm very busy with stuff (exams + work) these days, but if I get the time, I will take a look at your code. I'm sorry, but I can't release my converter just yet :)

I think there is a converter for ASE in the code archives as well, but I've never tried it! Yep...Here it is

Not much help, I know, but hey.... :)


MarkT(Posted 2003) [#4]
Fredborg: Hey thanks again for the code :) Brilliant stuff


fredborg(Posted 2003) [#5]
No problem :)


N(Posted 2003) [#6]
Thanks, Fred and Mark. I'd be happy if you could look it over some time, it's not of great importance to me at the moment.