Merge branch 'master' of github.com:syoyo/tinygltf

This commit is contained in:
Syoyo Fujita 2018-11-05 13:33:27 +09:00
commit e26117e026
4 changed files with 28 additions and 14 deletions

View File

@ -6,4 +6,4 @@ all:
clang++ $(EXTRA_CXXFLAGS) -std=c++11 -g -O0 -o loader_example loader_example.cc clang++ $(EXTRA_CXXFLAGS) -std=c++11 -g -O0 -o loader_example loader_example.cc
lint: lint:
./cpplint.py tiny_gltf_loader.h deps/cpplint.py tiny_gltf.h

View File

@ -33,10 +33,10 @@ v2.0.0 release(22 Aug, 2018)!
* [x] Binary glTF(GLB) * [x] Binary glTF(GLB)
* [x] PBR material description * [x] PBR material description
* Buffers * Buffers
* [x] Parse BASE64 encoded embedded buffer fata(DataURI). * [x] Parse BASE64 encoded embedded buffer data(DataURI).
* [x] Load `.bin` file. * [x] Load `.bin` file.
* Image(Using stb_image) * Image(Using stb_image)
* [x] Parse BASE64 encoded embedded image fata(DataURI). * [x] Parse BASE64 encoded embedded image data(DataURI).
* [x] Load external image file. * [x] Load external image file.
* [x] PNG(8bit only) * [x] PNG(8bit only)
* [x] JPEG(8bit only) * [x] JPEG(8bit only)

View File

@ -11,6 +11,7 @@ solution "glview"
files { "glview.cc", "../common/trackball.cc" } files { "glview.cc", "../common/trackball.cc" }
includedirs { "./" } includedirs { "./" }
includedirs { "../../" } includedirs { "../../" }
includedirs { "../common/" }
configuration { "linux" } configuration { "linux" }
linkoptions { "`pkg-config --libs glfw3`" } linkoptions { "`pkg-config --libs glfw3`" }

View File

@ -923,7 +923,8 @@ class TinyGLTF {
/// ///
bool WriteGltfSceneToFile(Model *model, const std::string &filename, bool WriteGltfSceneToFile(Model *model, const std::string &filename,
bool embedImages, bool embedImages,
bool embedBuffers /*, bool writeBinary*/); bool embedBuffers,
bool prettyPrint /*, bool writeBinary*/);
/// ///
/// Set callback to use for loading image data /// Set callback to use for loading image data
@ -2347,7 +2348,12 @@ static bool ParseExtensionsProperty(ExtensionMap *ret, std::string *err,
json::const_iterator extIt = it.value().begin(); json::const_iterator extIt = it.value().begin();
for (; extIt != it.value().end(); extIt++) { for (; extIt != it.value().end(); extIt++) {
if (!extIt.value().is_object()) continue; if (!extIt.value().is_object()) continue;
ParseJsonAsValue(&extensions[extIt.key()], extIt.value()); if (!ParseJsonAsValue(&extensions[extIt.key()], extIt.value())) {
if (!extIt.key().empty()) {
// create empty object so that an extension object is still of type object
extensions[extIt.key()] = Value{ Value::Object{} };
}
}
} }
if (ret) { if (ret) {
(*ret) = extensions; (*ret) = extensions;
@ -4071,12 +4077,14 @@ static void SerializeGltfBufferData(const std::vector<unsigned char> &data,
SerializeStringProperty("uri", header + encodedData, o); SerializeStringProperty("uri", header + encodedData, o);
} }
static void SerializeGltfBufferData(const std::vector<unsigned char> &data, static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
const std::string &binFilename) { const std::string &binFilename) {
std::ofstream output(binFilename.c_str(), std::ofstream::binary); std::ofstream output(binFilename.c_str(), std::ofstream::binary);
if(!output.is_open()) return false;
output.write(reinterpret_cast<const char *>(&data[0]), output.write(reinterpret_cast<const char *>(&data[0]),
std::streamsize(data.size())); std::streamsize(data.size()));
output.close(); output.close();
return true;
} }
static void SerializeParameterMap(ParameterMap &param, json &o) { static void SerializeParameterMap(ParameterMap &param, json &o) {
@ -4120,7 +4128,8 @@ static void SerializeExtensionMap(ExtensionMap &extensions, json &o) {
json ret; json ret;
if (ValueToJson(extIt->second, &ret)) { if (ValueToJson(extIt->second, &ret)) {
extMap[extIt->first] = ret; extMap[extIt->first] = ret;
} else { }
if(ret.is_null()) {
if (!(extIt->first.empty())) { // name should not be empty, but for sure if (!(extIt->first.empty())) { // name should not be empty, but for sure
// create empty object so that an extension name is still included in json. // create empty object so that an extension name is still included in json.
extMap[extIt->first] = json({}); extMap[extIt->first] = json({});
@ -4250,10 +4259,10 @@ static void SerializeGltfBuffer(Buffer &buffer, json &o) {
} }
} }
static void SerializeGltfBuffer(Buffer &buffer, json &o, static bool SerializeGltfBuffer(Buffer &buffer, json &o,
const std::string &binFilename, const std::string &binFilename,
const std::string &binBaseFilename) { const std::string &binBaseFilename) {
SerializeGltfBufferData(buffer.data, binFilename); if(!SerializeGltfBufferData(buffer.data, binFilename)) return false;
SerializeNumberProperty("byteLength", buffer.data.size(), o); SerializeNumberProperty("byteLength", buffer.data.size(), o);
SerializeStringProperty("uri", binBaseFilename, o); SerializeStringProperty("uri", binBaseFilename, o);
@ -4262,6 +4271,7 @@ static void SerializeGltfBuffer(Buffer &buffer, json &o,
if (buffer.extras.Type() != NULL_TYPE) { if (buffer.extras.Type() != NULL_TYPE) {
SerializeValue("extras", buffer.extras, o); SerializeValue("extras", buffer.extras, o);
} }
return true;
} }
static void SerializeGltfBufferView(BufferView &bufferView, json &o) { static void SerializeGltfBufferView(BufferView &bufferView, json &o) {
@ -4471,7 +4481,7 @@ static void SerializeGltfPerspectiveCamera(const PerspectiveCamera &camera,
static void SerializeGltfCamera(const Camera &camera, json &o) { static void SerializeGltfCamera(const Camera &camera, json &o) {
SerializeStringProperty("type", camera.type, o); SerializeStringProperty("type", camera.type, o);
if (!camera.name.empty()) { if (!camera.name.empty()) {
SerializeStringProperty("name", camera.type, o); SerializeStringProperty("name", camera.name, o);
} }
if (camera.type.compare("orthographic") == 0) { if (camera.type.compare("orthographic") == 0) {
@ -4533,7 +4543,8 @@ static bool WriteGltfFile(const std::string &output,
bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename, bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
bool embedImages = false, bool embedImages = false,
bool embedBuffers = false bool embedBuffers = false,
bool prettyPrint = true
/*, bool writeBinary*/) { /*, bool writeBinary*/) {
json output; json output;
@ -4606,8 +4617,10 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
} }
usedUris.push_back(binUri); usedUris.push_back(binUri);
binSavePath = JoinPath(baseDir, binUri); binSavePath = JoinPath(baseDir, binUri);
SerializeGltfBuffer(model->buffers[i], buffer, binSavePath, if(!SerializeGltfBuffer(model->buffers[i], buffer, binSavePath,
binUri); binUri)) {
return false;
}
} }
buffers.push_back(buffer); buffers.push_back(buffer);
} }
@ -4771,7 +4784,7 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
} }
// pretty printing with spacing 2 // pretty printing with spacing 2
return WriteGltfFile(filename, output.dump(2)); return WriteGltfFile(filename, output.dump(prettyPrint ? 2 : 0));
} }
} // namespace tinygltf } // namespace tinygltf