forked from HaloMods/SparkEdit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModelManager.cpp
188 lines (152 loc) · 3.78 KB
/
ModelManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// ModelManager.cpp: implementation of the CModelManager class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "sparkedit.h"
#include "ModelManager.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#include "HaloMapFile.h"
extern CHaloMapFile HaloMap;
CModelManager::CModelManager()
{
m_XboxModelCount = 0;
m_PcModelCount = 0;
m_pMapFile = 0;
ZeroMemory(m_TagIdList, sizeof(m_TagIdList));
}
CModelManager::~CModelManager()
{
}
void CModelManager::Cleanup()
{
for(int i=0; i<m_PcModelCount; i++)
{
m_PcModels[i].Cleanup();
}
for(int i=0; i<m_PcModelCount; i++)
{
m_XboxModels[i].Cleanup();
}
m_pMapFile = 0;
m_PcModelCount = 0;
m_XboxModelCount = 0;
ZeroMemory(m_TagIdList, sizeof(m_TagIdList));
m_Version = 0;
}
void CModelManager::Initialize(CFile *pMapFile, UINT magic, UINT vert_offset, UINT indices_offset, UINT version)
{
m_pMapFile = pMapFile;
m_Magic = magic;
m_PcModelVertOffset = vert_offset;
m_PcModelIndOffset = indices_offset;
m_Version = version;
}
CPcModel* CModelManager::AddPcModel(UINT tag_id, INDEX_ITEM *pIndexItem)
{
CString name;
INDEX_ITEM *pNext;
int size;
CPcModel *pModel = NULL;
if(m_PcModelCount < 500)
{
name = CheckForReference(m_pMapFile, pIndexItem->stringoffset, 0);
m_PcModels[m_PcModelCount].m_TagId = tag_id;
m_PcModels[m_PcModelCount].Initialize(m_pMapFile,
m_Magic,
m_PcModelVertOffset,
m_PcModelIndOffset,
name);
pNext = pIndexItem + 1;
size = pNext->offset - pIndexItem->offset;
m_PcModels[m_PcModelCount].LoadModel(pIndexItem->offset, size);
pModel = &m_PcModels[m_PcModelCount];
m_TagIdList[m_PcModelCount] = pIndexItem->tag_id;
m_PcModelCount++;
}
return(pModel);
}
CXboxModel* CModelManager::AddXboxModel(UINT tag_id, INDEX_ITEM *pIndexItem)
{
CString name;
INDEX_ITEM *pNext;
int size;
CXboxModel *pModel = NULL;
if(m_XboxModelCount < 500)
{
name = CheckForReference(m_pMapFile, pIndexItem->stringoffset, 0);
m_XboxModels[m_XboxModelCount].m_NamePtr = pIndexItem->stringoffset;
m_XboxModels[m_XboxModelCount].Initialize(m_pMapFile, m_Magic, name);
pNext = pIndexItem + 1;
size = pNext->offset - pIndexItem->offset;
m_XboxModels[m_XboxModelCount].LoadModel(pIndexItem->offset, size);
pModel = &m_XboxModels[m_XboxModelCount];
m_XboxModelCount++;
}
return(pModel);
}
void CModelManager::FindMatchingPcModel(UINT TopLevelObjTag, CPcModel **ppPcModel)
{
}
void CModelManager::FindMatchingXboxModel(UINT TopLevelObjTag, CXboxModel **ppXboxModel)
{
}
void CModelManager::CompileModelTextures()
{
int i;
for(i=0; i<m_PcModelCount; i++)
{
m_PcModels[i].CompileShader();
}
for(i=0; i<m_XboxModelCount; i++)
{
m_XboxModels[i].CompileShader();
}
}
UINT CModelManager::GetModelCount()
{
UINT model_count = 0;
switch (m_Version)
{
case 0x5:
model_count = m_XboxModelCount;
break;
case 0x7:
model_count = m_PcModelCount;
break;
case 0x261:
model_count = m_PcModelCount;
break;
}
return(model_count);
}
void CModelManager::GetModel(int index, CPcModel **ppPcModel, CXboxModel **ppXboxModel)
{
if(index < m_XboxModelCount)
*ppXboxModel = &m_XboxModels[index];
if(index < m_PcModelCount)
*ppPcModel = &m_PcModels[index];
}
CString CModelManager::GetModelName(int index)
{
CString str;
switch (m_Version)
{
case 0x5:
if(index < m_XboxModelCount)
str = m_XboxModels[index].m_ModelName;
break;
case 0x7:
if(index < m_PcModelCount)
str = m_PcModels[index].m_ModelName;
break;
case 0x261:
if(index < m_PcModelCount)
str = m_PcModels[index].m_ModelName;
break;
}
return(str);
}