mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 03:15:53 +08:00
Merge branch 'master' of github.com:syoyo/tinygltf
This commit is contained in:
commit
e26117e026
2
Makefile
2
Makefile
@ -6,4 +6,4 @@ all:
|
||||
clang++ $(EXTRA_CXXFLAGS) -std=c++11 -g -O0 -o loader_example loader_example.cc
|
||||
|
||||
lint:
|
||||
./cpplint.py tiny_gltf_loader.h
|
||||
deps/cpplint.py tiny_gltf.h
|
||||
|
@ -33,10 +33,10 @@ v2.0.0 release(22 Aug, 2018)!
|
||||
* [x] Binary glTF(GLB)
|
||||
* [x] PBR material description
|
||||
* Buffers
|
||||
* [x] Parse BASE64 encoded embedded buffer fata(DataURI).
|
||||
* [x] Parse BASE64 encoded embedded buffer data(DataURI).
|
||||
* [x] Load `.bin` file.
|
||||
* 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] PNG(8bit only)
|
||||
* [x] JPEG(8bit only)
|
||||
|
@ -11,6 +11,7 @@ solution "glview"
|
||||
files { "glview.cc", "../common/trackball.cc" }
|
||||
includedirs { "./" }
|
||||
includedirs { "../../" }
|
||||
includedirs { "../common/" }
|
||||
|
||||
configuration { "linux" }
|
||||
linkoptions { "`pkg-config --libs glfw3`" }
|
||||
|
35
tiny_gltf.h
35
tiny_gltf.h
@ -923,7 +923,8 @@ class TinyGLTF {
|
||||
///
|
||||
bool WriteGltfSceneToFile(Model *model, const std::string &filename,
|
||||
bool embedImages,
|
||||
bool embedBuffers /*, bool writeBinary*/);
|
||||
bool embedBuffers,
|
||||
bool prettyPrint /*, bool writeBinary*/);
|
||||
|
||||
///
|
||||
/// 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();
|
||||
for (; extIt != it.value().end(); extIt++) {
|
||||
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) {
|
||||
(*ret) = extensions;
|
||||
@ -4071,12 +4077,14 @@ static void SerializeGltfBufferData(const std::vector<unsigned char> &data,
|
||||
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) {
|
||||
std::ofstream output(binFilename.c_str(), std::ofstream::binary);
|
||||
if(!output.is_open()) return false;
|
||||
output.write(reinterpret_cast<const char *>(&data[0]),
|
||||
std::streamsize(data.size()));
|
||||
output.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
static void SerializeParameterMap(ParameterMap ¶m, json &o) {
|
||||
@ -4120,7 +4128,8 @@ static void SerializeExtensionMap(ExtensionMap &extensions, json &o) {
|
||||
json ret;
|
||||
if (ValueToJson(extIt->second, &ret)) {
|
||||
extMap[extIt->first] = ret;
|
||||
} else {
|
||||
}
|
||||
if(ret.is_null()) {
|
||||
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.
|
||||
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 &binBaseFilename) {
|
||||
SerializeGltfBufferData(buffer.data, binFilename);
|
||||
if(!SerializeGltfBufferData(buffer.data, binFilename)) return false;
|
||||
SerializeNumberProperty("byteLength", buffer.data.size(), o);
|
||||
SerializeStringProperty("uri", binBaseFilename, o);
|
||||
|
||||
@ -4262,6 +4271,7 @@ static void SerializeGltfBuffer(Buffer &buffer, json &o,
|
||||
if (buffer.extras.Type() != NULL_TYPE) {
|
||||
SerializeValue("extras", buffer.extras, o);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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) {
|
||||
SerializeStringProperty("type", camera.type, o);
|
||||
if (!camera.name.empty()) {
|
||||
SerializeStringProperty("name", camera.type, o);
|
||||
SerializeStringProperty("name", camera.name, o);
|
||||
}
|
||||
|
||||
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 embedImages = false,
|
||||
bool embedBuffers = false
|
||||
bool embedBuffers = false,
|
||||
bool prettyPrint = true
|
||||
/*, bool writeBinary*/) {
|
||||
json output;
|
||||
|
||||
@ -4606,8 +4617,10 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
||||
}
|
||||
usedUris.push_back(binUri);
|
||||
binSavePath = JoinPath(baseDir, binUri);
|
||||
SerializeGltfBuffer(model->buffers[i], buffer, binSavePath,
|
||||
binUri);
|
||||
if(!SerializeGltfBuffer(model->buffers[i], buffer, binSavePath,
|
||||
binUri)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
buffers.push_back(buffer);
|
||||
}
|
||||
@ -4771,7 +4784,7 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
||||
}
|
||||
|
||||
// pretty printing with spacing 2
|
||||
return WriteGltfFile(filename, output.dump(2));
|
||||
return WriteGltfFile(filename, output.dump(prettyPrint ? 2 : 0));
|
||||
}
|
||||
|
||||
} // namespace tinygltf
|
||||
|
Loading…
x
Reference in New Issue
Block a user