-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlenderImporter.cpp
42 lines (34 loc) · 1.24 KB
/
BlenderImporter.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
#include "BlenderImporter.h"
////////////////////////////////////////////////
// BlenderImporter implementation
//
// A wrapper class for general purpose functions
// maybe should just be namespaced
////////////////////////////////////////////////
BlenderFile BlenderImporter::LoadBlendFile(std::string filename, BlenderImporterConfig config) {
BlenderFile blenderFile(filename, config);
blenderFile.Load();
return blenderFile;
}
// Computes the length of a field based on it's string representation,
// i.e. *variable is a pointer, variable[5][10] is a 2 dimensional array
unsigned int BlenderImporter::ComputeFieldLength(std::string field_name, unsigned short length, size_t pointer_size) {
// check if this is a pointer
if (field_name.at(0) == '*' || field_name.at(0) == '(')
return pointer_size;
size_t pos = field_name.find("[");
int arrayMult = 1;
while (pos != std::string::npos) {
// determine the number of array dimensions
size_t end = field_name.find("]", pos);
std::string arrayLength = field_name.substr(pos+1, end-pos-1);
std::stringstream ss(arrayLength);
long num;
if((ss >> num).fail()) {
assert(0 && "Error in number conversion");
}
arrayMult *= num;
pos = field_name.find("[", end);
}
return arrayMult * length;
}