This repository was archived by the owner on Dec 10, 2022. It is now read-only.
forked from ataulien/ZenLib
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathzCModelPrototype.cpp
246 lines (209 loc) · 6.66 KB
/
zCModelPrototype.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#include "zCModelPrototype.h"
#include <algorithm>
#include <string>
#include "zTypes.h"
#include "zenParser.h"
#include <stdlib.h>
#include "utils/alignment.h"
#include "utils/logger.h"
#include "vdfs/fileIndex.h"
using namespace ZenLoad;
enum class EIdxAni : int
{
def,
name,
layer,
nextAni,
blendIn,
blendOut,
flags,
ASC_Name,
aniDir,
startFrame,
endFrame,
fps,
};
enum class EIdxMeshAndTree
{
def,
name,
dontUseMesh
};
enum class EIdxRegisterMesh
{
def,
name
};
/**
* Splits one of the MDS-Declerations like the example seen inside the function
* @param _line line to parse
* @return Vector of all parameters as strings
*/
std::vector<std::string> splitDecl(const std::string& _line)
{
// Example: registerMesh ("Gob_Body.ASC")
// Example: ani ("s_FistRun" 1 "s_FistRun" 0.1 0.1 M. "Gob_1hRunAmbient_M01.asc" F 0 30 FPS:10)
// Collapse
std::vector<std::string> out;
out.push_back("");
bool inArg = true;
for (auto& c : _line)
{
if (c == ' ' || c == '\t' || c == '(')
{
if (inArg) // Only add a new section, when the last one was filled
{
out.push_back("");
inArg = false;
}
}
else
{
if (c != '"' && c != ')') // Don't add quotes and the closing bracket
{
out.back() += c;
inArg = true;
}
// Handle empty strings
if (c == '"')
inArg = true;
}
}
return out;
}
zCModelPrototype::zCModelPrototype(const std::string& fileName, const VDFS::FileIndex& fileIndex)
{
std::vector<uint8_t> data;
fileIndex.getFileData(fileName, data);
if (data.empty())
return; // TODO: Throw an exception or something
try
{
// Create parser from memory
// FIXME: There is an internal copy of the data here. Optimize!
ZenLoad::ZenParser parser(data.data(), data.size());
readObjectData(parser);
}
catch (std::exception& e)
{
LogError() << e.what();
return;
}
}
/**
* @brief Reads the mesh-object from the given binary stream
*/
void zCModelPrototype::readObjectData(ZenParser& parser)
{
// TODO: Implement G2-Variant of this
enum Section
{
Model,
AniEnum,
MeshAndTree,
RegisterMesh,
StartMesh,
};
/**
* Ani enum
*/
/*
auto readAniEnum = [&]() {
while (parser.getSeek() < parser.getFileSize())
{
std::string line = parser.readLine(true);
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
LogInfo() << "MDS-Line: " << line;
if (line.find("//") != std::string::npos)
continue; // Skip comments. These MUST be on their own lines, by definition.
else if (line.find("}") != std::string::npos)
break; // There can be only one } per block
}
};
*/
/**
* Register mesh
*/
/*
auto readRegisterMesh = [&](const std::string& line) {
std::vector<std::string> args = splitDecl(line);
LogInfo() << "Args: " << args;
};
*/
/**
* Ani
*/
auto readAni = [&](const std::string& line) {
std::vector<std::string> args = splitDecl(line);
LogInfo() << "Args: " << args;
Animation ani;
ani.animationName = args[(int)EIdxAni::name];
ani.layer = atoi(args[(int)EIdxAni::layer].c_str());
ani.nextAnimation = args[(int)EIdxAni::nextAni];
ani.blendIn = float(atof(args[(int)EIdxAni::blendIn].c_str()));
ani.blendOut = float(atof(args[(int)EIdxAni::blendOut].c_str()));
ani.ascName = args[(int)EIdxAni::ASC_Name];
ani.aniReversed = args[(int)EIdxAni::aniDir] == "R";
ani.startFrame = atoi(args[(int)EIdxAni::startFrame].c_str());
ani.endFrame = atoi(args[(int)EIdxAni::endFrame].c_str());
ani.flags = 0;
if (args[(int)EIdxAni::flags].find("m") != std::string::npos)
ani.flags |= Animation::MoveObject;
if (args[(int)EIdxAni::flags].find("r") != std::string::npos)
ani.flags |= Animation::RotateObject;
if (args[(int)EIdxAni::flags].find("e") != std::string::npos)
ani.flags |= Animation::WaitEnd;
if (args[(int)EIdxAni::flags].find("f") != std::string::npos)
ani.flags |= Animation::Fly;
if (args[(int)EIdxAni::flags].find("i") != std::string::npos)
ani.flags |= Animation::Idle;
m_Animations.push_back(ani);
};
/**
* Base node
*/
auto readModel = [&]() {
while (parser.getSeek() < parser.getFileSize())
{
std::string line = parser.readLine(true);
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
LogInfo() << "MDS-Line: " << line;
if (line.find("//") != std::string::npos)
continue; // Skip comments. These MUST be on their own lines, by definition.
else if (line.find("anienum") != std::string::npos)
continue;
else if (line.find("aniblend") != std::string::npos)
continue;
else if (line.find("eventmmstartani") != std::string::npos)
continue;
else if (line.find("anialias") != std::string::npos)
continue;
else if (line.find("anicomb") != std::string::npos)
continue;
else if (line.find("anidisable") != std::string::npos)
continue;
else if (line.find("ani") != std::string::npos)
readAni(line);
else if (line.find("meshandtree") != std::string::npos)
continue;
else if (line.find("registermesh") != std::string::npos)
continue;
else if (line.find("startmesh") != std::string::npos)
continue;
else if (line.find("{") != std::string::npos)
continue;
else if (line.find("}") != std::string::npos)
continue; //break; // There can be only one } per block
}
};
while (parser.getSeek() < parser.getFileSize())
{
std::string line = parser.readLine(true);
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
LogInfo() << "MDS-Line: " << line;
if (line.find("//") != std::string::npos)
continue; // Skip comments. These MUST be on their own lines, by definition.
else if (line.find("model") != std::string::npos)
readModel();
}
}