'// MD3 Model Loader v.01
'// By John Onyon a.k.a Unseen Machine
CONST True
= -1, False
= 0 '// Generic valuations
'// Set up screen
_FPS 30
'// Flags
InitGL = True
Debug = True
'// Model file information
File$ = "3d programs\md3\Vehicle.md3"
'// Create the model header
'// Get model header data - Gives sizes of needed arrays.
MD3_Load Model, File$
'// DIM containers
DIM MDL_Frame
(Model.NumFrames
- 1) AS MD3_Frame
DIM MDL_Surface
(Model.NumSurfaces
- 1) AS MD3_Surface
'// Open the file
'// Load frame data
BytePos& = Model.FrameOffset + 1
FOR i%
= 0 TO Model.NumFrames
- 1 GET #FFile%
, BytePos&
, MDL_Frame
(i%
) BytePos&
= BytePos&
+ LEN(MDL_Frame
(0))
'// Load surface (mesh) data
BytePos& = Model.SurfaceOffset + 1
FOR i%
= 0 TO Model.NumSurfaces
- 1 GET #FFile%
, BytePos&
, MDL_Surface
(i%
) NumTris& = NumTris& + MDL_Surface(i%).Triangles '// Count how many triangles in total
BytePos& = BytePos& + MDL_Surface(i%).EndOffset
'// Load triangle data - each surface has it's own set of triangles!!! Arghh!!!
'// Not actual coordinates, these are indexes into the Vertex array.
DIM MDL_Tris
(NumTris&
- 1) AS MD3_Triangle
'// Triangle index array BytePos& = Model.SurfaceOffset + MDL_Surface(0).TriangleOffset + 1
FOR i%
= 0 TO Model.NumSurfaces
- 1 FOR j&
= 0 TO MDL_Surface
(i%
).Triangles
- 1 GET #FFile%
, BytePos&
, MDL_Tris
(Tcnt&
) BytePos&
= BytePos&
+ LEN(MDL_Tris
(0)) Tcnt& = Tcnt& + 1
'// Load vertex data
FOR i%
= 0 TO Model.NumSurfaces
- 1 TotalVerts& = TotalVerts& + (MDL_Surface(i%).Frames * MDL_Surface(i%).Verts) '// Calculate total array size needed
DIM MDL_Verts
(TotalVerts&
- 1) AS MD3_Vertex
'// Vertex array (due to scaling this need dividing by 64) BytePos& = Model.SurfaceOffset + MDL_Surface(0).VertOffset + 1
FOR i&
= 0 TO TotalVerts&
- 1 GET #FFile%
, BytePos&
, MDL_Verts
(i&
) BytePos&
= BytePos&
+ LEN(MDL_Verts
(0))
'// Load texture coordinates
'// All data should be loaded so close the model file.
'// Calculate all array sizes and create _MEM block
'/////// Main Loop \\\\\\\
PRINT Model.ID
, Model.Ident
PRINT Model.NumFrames
, Model.NumTags
, Model.NumSurfaces
, Model.NumSkins
PRINT Model.FrameOffset
, Model.TagsOffset
, Model.SurfaceOffset
FOR i%
= 0 TO Model.NumFrames
- 1 PRINT MDL_Frame
(i%
).Min_Bounds.X
, MDL_Frame
(i%
).Min_Bounds.Y
, MDL_Frame
(i%
).Min_Bounds.Z
PRINT MDL_Frame
(i%
).Max_Bounds.X
, MDL_Frame
(i%
).Max_Bounds.Y
, MDL_Frame
(i%
).Max_Bounds.Z
PRINT "Surfaces : "; Model.NumSurfaces
FOR i%
= 0 TO Model.NumSurfaces
- 1 PRINT MDL_Surface
(i%
).ID
, MDL_Surface
(i%
).
Name, MDL_Surface
(i%
).Triangles
PRINT "Total triangles : "; Tcnt&
PRINT "Total vertices : "; TotalVerts&
'PRINT MDL_Tris(j&).Vert1, MDL_Tris(j&).Vert2, MDL_Tris(j&).Vert3
FOR i&
= 0 TO TotalVerts&
- 1 ' PRINT MDL_Verts(i&).X / 64, MDL_Verts(i&).Y / 64, MDL_Verts(i&).Z / 64
' IF MDL_Verts(i&).Y THEN PRINT MDL_Verts(i&).Y / 64
'//////////////////////////////////
Local_Origin
AS MD3_Vector
'//////////////////////////////////
SUB MD3_Load
(MDL
AS MD3
, File$
)
'//////////////////////////////////
InitGL = False
AllowGL = True
'//RENDER