📄 modmd3helper.bas
字号:
Attribute VB_Name = "modMD3Helper"
Option Explicit
' Model header
Public Type udtModelHeader
Identity As String * 4 ' Identifies as Quake 3 MD3 header (IDP3)
Version As Long ' Should always be 15
FileName As String * 68 ' The name of this file
NumOfBoneFrames As Long ' The number of bone frames
NumOfTags As Long ' The number of tag's
NumOfMeshes As Long ' The number of individual meshes
MaxSkins As Long ' Maximum number of unique skins
HeaderLength As Long ' The file size of this header
Tag_Start As Long ' Start position of tag structure
Tag_End As Long ' End position of tag structures
FileSize As Long ' The size of this file
End Type
' Mesh header
Public Type udtMeshHeader
ID As String * 4 ' Identity must be 'IDP3'
MeshName As String * 68 ' Name of this mesh
NumOfMeshFrames As Long ' Number of mesh frames in this mesh
NumOfSkin As Long ' Number of skins in this mesh
NumOfVertex As Long ' Number of vertices this mesh
NumOfTriangle As Long ' Number of triangles this mesh
Triangle_Start As Long ' Start position of the triangle structures
HeaderSize As Long ' Size of the mesh header in bytes
TexVec_Start As Long ' Start position of the texvec structure, relative to start of mesh header
Vertex_Start As Long ' Start position of the vertex data, relative to mesh header
MeshSize As Long ' Size of this mesh in bytes
End Type
' The Tag structure
Public Type udtTags
TagName As String * 64 ' Tag name ie TAG_TORSO
TagTranslation As D3DVECTOR ' x,y & z translation matrix
TagRotation(2, 2) As Single ' x,y & z rotation matrix
End Type
' The Bone Frame structure (Not used as far as we can ascertain.)
Public Type udtBoneFrames
Mins As D3DVECTOR
Maxs As D3DVECTOR
Position As D3DVECTOR
Scale As Single
Creator(15) As Byte
End Type
' The Triangles structure
Public Type udtTriangles
Triangles(2) As Long
End Type
' The Vertices and Normal index structure
Public Type udtVertsNorms
Vertices(2) As Integer
Normal(1) As Byte
End Type
' Reference type for the individual mesh frames
Public Type udtFrameVerts
Frame() As udtVertsNorms
End Type
' The Texture cooridinate structure U & V values
Public Type udtTexCoords
Texture As D3DVECTOR2
End Type
' For identifying Tag links between model parts
Public Type udtTag
TagName As String
TagIndex() As Integer ' Unlikely MD3 will have more than 32,000 tags
End Type
Public Type udtDXVerts
MD3Verts() As MDLVERTEX
End Type
Public Type udtFrameNo
MD3FrameVerts() As udtDXVerts
End Type
' Custom MD3 mesh type
Public Type udtMD3Mesh
MD3MeshHeader As udtMeshHeader
MD3SkinNames() As String
MD3Triangles() As udtTriangles
MD3Frames() As udtFrameVerts
MD3TexCoords() As D3DVECTOR2
MD3VertexBuffer() As Direct3DVertexBuffer8
End Type
' Custom MD3 Model type (holds the whole model data)
Public Type udtMD3Model
MD3Header As udtModelHeader
MD3BoneFrames() As udtBoneFrames
MD3Tags() As udtTags
MD3Meshes() As udtMD3Mesh
MD3Vertices() As udtFrameNo
End Type
Public Const BOTH_DEATH1 As Long = 0
Public Const BOTH_DEAD1 As Long = 1
Public Const BOTH_DEATH2 As Long = 2
Public Const BOTH_DEAD2 As Long = 3
Public Const BOTH_DEATH3 As Long = 4
Public Const BOTH_DEAD3 As Long = 5
Public Const TORSO_GESTURE As Long = 6
Public Const TORSO_ATTACK As Long = 7
Public Const TORSO_ATTACK2 As Long = 8
Public Const TORSO_DROP As Long = 9
Public Const TORSO_RAISE As Long = 10
Public Const TORSO_STAND As Long = 11
Public Const TORSO_STAND2 As Long = 12
Public Const LEGS_WALKCR As Long = 13
Public Const LEGS_WALK As Long = 14
Public Const LEGS_RUN As Long = 15
Public Const LEGS_BACK As Long = 16
Public Const LEGS_SWIM As Long = 17
Public Const LEGS_JUMP As Long = 18
Public Const LEGS_LAND As Long = 19
Public Const LEGS_JUMPB As Long = 20
Public Const LEGS_LANDB As Long = 21
Public Const LEGS_IDLE As Long = 22
Public Const LEGS_IDLECR As Long = 23
Public Const LEGS_TURN As Long = 24
Public Const MAX_ANIMATIONS As Long = 25
' Variable to hold a lookup table of normal values
Private Normals(255, 255) As D3DVECTOR
Private bNormalsCreated As Boolean
' Variable used for an index
Private VIndex As Long
Private i As Long, j As Long, x As Long, s As Long, t As Long, u As Long, f As Long, v As Long, m As Long
Public Function GetNameOnly(ByVal sIn As String) As String
If InStr(sIn, "/") Then
If InStr(sIn, ".") Then
GetNameOnly = Mid$(sIn, InStrRev(sIn, "/") + 1, InStrRev(sIn, ".") - InStrRev(sIn, "/") - 1)
Else
GetNameOnly = Mid$(sIn, InStrRev(sIn, "/") + 1)
End If
ElseIf InStr(sIn, "\") Then
If InStr(sIn, ".") Then
GetNameOnly = Mid$(sIn, InStrRev(sIn, "\") + 1, InStrRev(sIn, ".") - InStrRev(sIn, "\") - 1)
Else
GetNameOnly = Mid$(sIn, InStrRev(sIn, "\") + 1)
End If
End If
End Function
Public Function GetPathOnly(ByVal sIn As String) As String
GetPathOnly = Left$(sIn, InStrRev(sIn, "\"))
End Function
'This turns an unix path into an win32 one
Public Function PathWin32(path As String) As String
If InStr(path, Chr(0)) > 0 Then
path = Mid$(path, 1, InStr(path, Chr(0)) - 1)
End If
PathWin32 = Replace$(path, "/", "\")
End Function
Private Sub TableOfNormals()
Dim A As Single
Dim B As Single
For i = 0 To 255
For j = 0 To 255
A = 2 * i * PI / 255
B = 2 * j * PI / 255
Normals(i, j).x = Cos(B) * sIn(A)
Normals(i, j).y = sIn(B) * sIn(A)
Normals(i, j).Z = Cos(A)
Next j
Next i
End Sub
Public Sub LoadModels(ByRef MD3 As udtMD3Model, ByRef sFileName As String)
'create if not already created
If bNormalsCreated = False Then
TableOfNormals
End If
Dim MatTemp As D3DMATRIX, MatX As D3DMATRIX, MatY As D3DMATRIX
D3DXMatrixIdentity MatTemp
D3DXMatrixRotationX MatX, -PI / 2
D3DXMatrixRotationY MatY, PI / 2
D3DXMatrixMultiply MatTemp, MatX, MatY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -