-
-
Notifications
You must be signed in to change notification settings - Fork 390
/
gltf-loader.cc
51 lines (40 loc) · 1.19 KB
/
gltf-loader.cc
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
#include "gltf-loader.h"
#include <iostream>
#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#include "tiny_gltf.h"
namespace example {
static std::string GetFilePathExtension(const std::string &FileName) {
if (FileName.find_last_of(".") != std::string::npos)
return FileName.substr(FileName.find_last_of(".") + 1);
return "";
}
///
/// Loads glTF 2.0 mesh
///
bool LoadGLTF(const std::string &filename, float scale, std::vector<Mesh<float> > *meshes, std::vector<Material> *materials, std::vector<Texture> *textures)
{
// TODO(syoyo): Texture
// TODO(syoyo): Material
tinygltf::Model model;
tinygltf::TinyGLTF loader;
std::string err;
std::string ext = GetFilePathExtension(filename);
bool ret = false;
if (ext.compare("glb") == 0) {
// assume binary glTF.
ret = loader.LoadBinaryFromFile(&model, &err, filename.c_str());
} else {
// assume ascii glTF.
ret = loader.LoadASCIIFromFile(&model, &err, filename.c_str());
}
if (!err.empty()) {
std::cerr << "glTF parse error: " << err << std::endl;
}
if (!ret) {
std::cerr << "Failed to load glTF: " << filename << std::endl;
return false;
}
return false;
}
} // namespace example