Quake MD2 Files
Posted: Sun Mar 14, 2004 8:47 am
Hello,
I started to load a MD2File, but I get wrong values in the Triangle(maybe) and in the Vertexdata:
Can you help me?
PS: Test it with a democube
I started to load a MD2File, but I get wrong values in the Triangle(maybe) and in the Vertexdata:
Code: Select all
;1 short = 2bytes = 1 word
Structure tMd2Header
magic.l; // This is used to identify the file
version.l; // The version number of the file (Must be 8)
skinWidth.l; // The skin width in pixels
skinHeight.l; // The skin height in pixels
frameSize.l; // The size in bytes the frames are
numSkins.l; // The number of skins associated with the model
numVertices.l; // The number of vertices (constant for each frame)
numTexCoords.l; // The number of texture coordinates
numTriangles.l; // The number of faces (polygons)
numGlCommands.l; // The number of gl commands
numFrames.l; // The number of animation frames
offsetSkins.l; // The offset in the file for the skin data
offsetTexCoords.l; // The offset in the file for the texture data
offsetTriangles.l; // The offset in the file for the face data
offsetFrames.l; // The offset in the file for the frames data
offsetGlCommands.l; // The offset in the file for the gl commands data
offsetEnd.l; // The end of the file offset
EndStructure
Structure Triangles
vert.w[3]
tex.w[3]
EndStructure
Structure dtrivertx_t
v.b[3]
lightnormalindex.b
EndStructure
Structure aliasframe
scale.f[3]
translate.f[3]
name.s[16]
verts.dtrivertx_t[1]
EndStructure
Global m_Header.tMd2Header, m_Tri.Triangles, out.aliasframe
If OpenFile(0, "cube.MD2")
ReadData(@m_Header, SizeOf(tMd2Header))
FileSeek(m_Header\offsetSkins)
Skin = AllocateMemory(0, 64000)
ReadData(Skin, m_Header\numSkins * 64)
Debug "Skin: "+PeekS(Skin)
Dim TextureCoords.l(m_Header\numTexCoords)
ReadData(@TextureCoords(), m_Header\numTexCoords * 4)
Debug " "
Debug " "
Debug "Texturkoordinaten:"
For i=0 To m_Header\numTexCoords
Debug PeekW(@TextureCoords(i))
Debug PeekW(@TextureCoords(i)+2)
Debug "---"
Next
FileSeek(m_Header\offsetTriangles)
Debug " "
Debug " "
Debug "Triangles:"
For i = 0 To m_Header\numTriangles-1
ReadData(m_Tri, SizeOf(Triangles))
Debug m_Tri\vert[0]
Debug m_Tri\vert[1]
Debug m_Tri\vert[2]
Debug "---"
Next
FileSeek(m_Header\offsetFrames)
Debug " "
Debug " "
Debug "Vertexdata:"
For i=0 To m_Header\numVertices
ReadData(out, m_Header\frameSize)
Debug out\scale[0]
Debug out\verts\v[0]
Debug out\verts\v[1]
Debug out\verts\v[2]
Debug "---"
Next
CloseFile(0)
EndIf
PS: Test it with a democube