Openholo  v5.0
Open Source Digital Holographic Library
FBXparser.cpp
Go to the documentation of this file.
1 
2 #include "FBXParser.h"
3 
4 using namespace std;
5 
7  : m_version(7400)
8 {
9 }
10 
12 {
13 
14 }
15 
16 bool FBXParser::checkHeader(std::ifstream& input)
17 {
18  string signature("Kaydara FBX Binary ");
19  string buffer;
20  buffer.resize(signature.length());
21  input.read(const_cast<char*>(buffer.c_str()), signature.length());
22  if (buffer.compare(signature)) return false;
23 
24  unsigned char c;
25  input >> c;
26  if (c != 0x00) return false;
27  input >> c;
28  if (c != 0x1A) return false;
29  input >> c;
30  if (c != 0x00) return false;
31  return true;
32 }
33 
34 uint32_t FBXParser::getVersion(std::ifstream& input)
35 {
36  uint32_t version = 0;
37  input.read((char *)&version, sizeof(uint32_t));
38  return version;
39 }
40 
41 uint32_t FBXParser::readNode(std::ifstream& input, uint32_t offset)
42 {
43  uint32_t bytes = 0;
44  uint32_t endOffset;
45  uint32_t numProperties;
46  uint32_t propertyListLength;
47  uint8_t nameLength;
48  string name;
49 
50  input.read((char*)&endOffset, sizeof(uint32_t));
51  input.read((char*)&numProperties, sizeof(uint32_t));
52  input.read((char*)&propertyListLength, sizeof(uint32_t));
53  input.read((char*)&nameLength, sizeof(uint8_t));
54  name.resize(nameLength + 1);
55  name[nameLength + 1] = 0;
56  input.read((char*)name.c_str(), nameLength);
57  bytes += 13 + nameLength;
58 
59  return bytes;
60 }
61 
62 bool FBXParser::loadFBX(const std::string& fileName, ulonglong& n_points, Vertex** vertices)
63 {
64  ifstream file(fileName, ios::binary);
65 
66  if (!file.is_open()) {
67  cerr << "Failed to open file." << endl;
68  return false;
69  }
70  if (!checkHeader(file)) {
71  cerr << "Not a FBX file." << endl;
72  return false;
73  }
74  m_version = getVersion(file);
75  uint32_t maxVersion = 7400;
76  if (m_version > maxVersion) {
77  cerr << "Unsupported FBX version " << m_version << endl;
78  return false;
79  }
80 
81  uint32_t start_offset = 27;
82 
83 
84  return true;
85 }
86 
88 {
89 
90 }
91 
93 {
94 
95 }
96 
98 {
99 
100 }
101 
103 {
104 
105 }
unsigned long long ulonglong
Definition: typedef.h:67
uint32_t getVersion()
Definition: FBXParser.h:64
Definition: struct.h:102
~FBXNode()
Definition: FBXparser.cpp:92
bool loadFBX(const std::string &fileName, ulonglong &n_points, Vertex **vertices)
Definition: FBXparser.cpp:62