Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: TinDragon on March 12, 2009
-
Ok I found the code for the truespace .asc exported model format to a series of data staements, the code in writen in blitzbasic(2d/plus3d compatiable)
It reads in the information from the .asc file and spits out data staements which contain vertex and face data, due to it exporting the data for the ttd lib the 1st value in the face data is the number of points in the face, 3 for triangle and 4 for quad, since truespace worked in tri's this code stuck a 3 in front by default. Feel free to use, edit, convert to whatever you like, a note in the credits would be nice ;)
;-------------------------------------------------------------------
; NAME : ConvertfileTSasc()
; PURPOSE : This function converts the file
; INPUTS : Filename$.
; RETURNS : Nothing.
;-------------------------------------------------------------------
Function ConvertfileTSasc(inputfile$)
count=Len(inputfile$)-4
inputfileshort$=Left$(inputfile$,count)
outputfile$=inputfileshort$+"data.bb"
dc=count
While Mid$(inputfileshort$,dc,1)<>"\"
dc=dc-1
Wend
dc=count-dc
name$=Right$(inputfileshort$,dc)
label$="."+name$+"shape"
filein=ReadFile(inputfile$)
fileout=WriteFile(outputfile$)
vertfound=False
Repeat
t$ = ReadLine(filein)
test$=NthField$(t$," ",2)
If test$="Vertices:" Then vertfound=True
Until vertfound=True
vertcount$=NthField$(t$," ",3)
facecount$=NthField$(t$," ",9)
WriteLine(fileout,label$)
WriteLine(fileout,"; Vert count")
WriteLine(fileout,"DATA "+vertcount$)
WriteLine(fileout,"; Verts")
vertfound=False
Repeat
t$ = ReadLine(filein)
test$=NthField$(t$," ",2)
If test$="0:" Then vertfound=True
Until vertfound=True
x$=NthField$(t$," ",4)
y$=NthField$(t$," ",9)
z$=NthField$(t$," ",14)
countx=Len(x$)-2
county=Len(y$)-2
countz=Len(z$)-2
dat$="data "+Right$(x$,countx)+","+Right$(y$,county)+","+Right$(z$,countz)
WriteLine(fileout,dat$)
facefound=False
Repeat
t$ = ReadLine(filein)
test$=Left$(t$,4)
If test$="Face"
facefound=True
Else
If test$="Vert"
x$=NthField$(t$," ",4)
y$=NthField$(t$," ",9)
z$=NthField$(t$," ",14)
countx=Len(x$)-2
county=Len(y$)-2
countz=Len(z$)-2
dat$="data "+Right$(x$,countx)+","+Right$(y$,county)+","+Right$(z$,countz)
WriteLine(fileout,dat$)
EndIf
EndIf
Until facefound=True
facefound=False
WriteLine(fileout,"; face count")
WriteLine(fileout,"DATA "+facecount$)
WriteLine(fileout,"; tri faces")
Repeat
t$ = ReadLine(filein)
test$=Left$(t$,4)
If test$="Face"
a$=NthField$(t$," ",6)
b$=NthField$(t$," ",7)
c$=NthField$(t$," ",8)
countx=Len(a$)-2
county=Len(b$)-2
countz=Len(c$)-2
dat$="data 3,"+Right$(c$,countz)+","+Right$(b$,county)+","+Right$(a$,countx)
WriteLine(fileout,dat$)
EndIf
Until Eof(filein)
CloseFile(filein)
CloseFile(fileout)
End Function
;-------------------------------------------------------------------
; NAME : NthField$()
; PURPOSE : This function extracts a string
; INPUTS : Starting string, delimiter, which string to return.
; RETURNS : The extracted string.
;-------------------------------------------------------------------
Function NthField$(s$, delim$, n)
o = 1
For i = 1 To n - 1
o = Instr(s, delim, o)
If o = 0 Then
Return ""
End If
o = o + 1
Next
p = Instr(s, delim, o)
If p = 0 Then
Return Mid(s, o)
Else
Return Mid(s, o, p - o)
End If
End Function
here's an example input file for a cube
Ambient light color: Red=0.3 Green=0.3 Blue=0.3
Named object: "Cube"
Tri-mesh, Vertices: 8 Faces: 12
Vertex list:
Vertex 0: X:-1.000000 Y:-1.000000 Z:0.000000
Vertex 1: X:-1.000000 Y:-1.000000 Z:2.000000
Vertex 2: X:1.000000 Y:-1.000000 Z:0.000000
Vertex 3: X:1.000000 Y:-1.000000 Z:2.000000
Vertex 4: X:-1.000000 Y:1.000000 Z:0.000000
Vertex 5: X:1.000000 Y:1.000000 Z:0.000000
Vertex 6: X:1.000000 Y:1.000000 Z:2.000000
Vertex 7: X:-1.000000 Y:1.000000 Z:2.000000
Face list:
Face 0: A:2 B:3 C:1 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 1: A:2 B:1 C:0 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 2: A:4 B:5 C:2 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 3: A:4 B:2 C:0 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 4: A:6 B:3 C:2 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 5: A:6 B:2 C:5 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 6: A:6 B:7 C:1 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 7: A:6 B:1 C:3 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 8: A:6 B:5 C:4 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 9: A:6 B:4 C:7 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 10: A:1 B:7 C:4 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
Face 11: A:1 B:4 C:0 AB:1 BC:1 CA:1
Material:"r210g210b210a0"
Smoothing: 1
and what the output should look like
.cubeTSshape
; Vert count
DATA 8
; Verts
data -1.000000,-1.000000,0.000000
data -1.000000,-1.000000,2.000000
data 1.000000,-1.000000,0.000000
data 1.000000,-1.000000,2.000000
data -1.000000,1.000000,0.000000
data 1.000000,1.000000,0.000000
data 1.000000,1.000000,2.000000
data -1.000000,1.000000,2.000000
; face count
DATA 12
; tri faces
data 3,1,3,2
data 3,0,1,2
data 3,2,5,4
data 3,0,2,4
data 3,2,3,6
data 3,5,2,6
data 3,1,7,6
data 3,3,1,6
data 3,4,5,6
data 3,7,4,6
data 3,4,7,1
data 3,0,4,1
Well hopefully someone will find it of use, it could be expanded to deal with more information but at the time this was all we were using it for. The same idea can be adapted to any loader/converter as long as you can get valid info on the file format.
Cheer
Jon
-
Nice one, now I don't have to dig into my archieves and find it. :)
-
Cool dudes and do you dudes, have a Milkshape asc converter?
-
I think I have a version that does milkshape .ace files somewhere clyde, tho the above might actualy be able to do them as well. Will see if I can find it and post it up