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

This commit is contained in:
Syoyo Fujita 2018-10-07 20:35:14 +09:00
commit 68353f1b34
2 changed files with 40 additions and 18 deletions

View File

@ -24,6 +24,7 @@ v2.0.0 release(22 Aug, 2018)!
* [x] Windows + MinGW * [x] Windows + MinGW
* [x] Windows + Visual Studio 2015 Update 3 or later. * [x] Windows + Visual Studio 2015 Update 3 or later.
* Visual Studio 2013 is not supported since they have limited C++11 support and failed to compile `json.hpp`. * Visual Studio 2013 is not supported since they have limited C++11 support and failed to compile `json.hpp`.
* [x] Android NDK
* [x] Android + CrystaX(NDK drop-in replacement) GCC * [x] Android + CrystaX(NDK drop-in replacement) GCC
* [x] Web using Emscripten(LLVM) * [x] Web using Emscripten(LLVM)
* Moderate parsing time and memory consumption. * Moderate parsing time and memory consumption.
@ -41,6 +42,7 @@ v2.0.0 release(22 Aug, 2018)!
* [x] JPEG(8bit only) * [x] JPEG(8bit only)
* [x] BMP * [x] BMP
* [x] GIF * [x] GIF
* [x] Custom Image decoder callback(e.g. for decoding OpenEXR image)
## Examples ## Examples
@ -63,7 +65,7 @@ v2.0.0 release(22 Aug, 2018)!
* [ ] Support `extensions` and `extras` property * [ ] Support `extensions` and `extras` property
* [ ] HDR image? * [ ] HDR image?
* [ ] OpenEXR extension through TinyEXR. * [ ] OpenEXR extension through TinyEXR.
* [ ] Write exampple and tests for `animation` and `skin` * [ ] Write example and tests for `animation` and `skin`
## Licenses ## Licenses

View File

@ -493,7 +493,7 @@ struct Texture {
std::string name; std::string name;
int sampler; int sampler;
int source; // Required (not specified in the spec ?) int source;
Value extras; Value extras;
ExtensionMap extensions; ExtensionMap extensions;
@ -1245,9 +1245,8 @@ bool Parameter::operator==(const Parameter &other) const {
this->has_number_value != other.has_number_value) this->has_number_value != other.has_number_value)
return false; return false;
if (this->has_number_value) if (!TINYGLTF_DOUBLE_EQUAL(this->number_value, other.number_value))
if (!TINYGLTF_DOUBLE_EQUAL(this->number_value, other.number_value)) return false;
return false;
if (this->json_double_value.size() != other.json_double_value.size()) if (this->json_double_value.size() != other.json_double_value.size())
return false; return false;
@ -2400,6 +2399,7 @@ static bool ParseImage(Image *image, std::string *err, std::string *warn,
ParseStringProperty(&image->name, err, o, "name", false); ParseStringProperty(&image->name, err, o, "name", false);
ParseExtensionsProperty(&image->extensions, err, o); ParseExtensionsProperty(&image->extensions, err, o);
ParseExtrasProperty(&image->extras, o);
if (hasBufferView) { if (hasBufferView) {
double bufferView = -1; double bufferView = -1;
@ -4504,8 +4504,9 @@ static void SerializeGltfTexture(Texture &texture, json &o) {
if (texture.sampler > -1) { if (texture.sampler > -1) {
SerializeNumberProperty("sampler", texture.sampler, o); SerializeNumberProperty("sampler", texture.sampler, o);
} }
SerializeNumberProperty("source", texture.source, o); if (texture.source > -1) {
SerializeNumberProperty("source", texture.source, o);
}
if (texture.extras.Type() != NULL_TYPE) { if (texture.extras.Type() != NULL_TYPE) {
SerializeValue("extras", texture.extras, o); SerializeValue("extras", texture.extras, o);
} }
@ -4553,31 +4554,50 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
SerializeGltfAsset(model->asset, asset); SerializeGltfAsset(model->asset, asset);
output["asset"] = asset; output["asset"] = asset;
std::string binFilename = GetBaseFilename(filename); std::string defaultBinFilename = GetBaseFilename(filename);
std::string ext = ".bin"; std::string defaultBinFileExt = ".bin";
std::string::size_type pos = binFilename.rfind('.', binFilename.length()); std::string::size_type pos = defaultBinFilename.rfind('.', defaultBinFilename.length());
if (pos != std::string::npos) { if (pos != std::string::npos) {
binFilename = binFilename.substr(0, pos) + ext; defaultBinFilename = defaultBinFilename.substr(0, pos);
} else {
binFilename = binFilename + ".bin";
} }
std::string baseDir = GetBaseDir(filename); std::string baseDir = GetBaseDir(filename);
if (baseDir.empty()) { if (baseDir.empty()) {
baseDir = "./"; baseDir = "./";
} }
std::string binSaveFilePath = JoinPath(baseDir, binFilename); // BUFFERS
std::vector<std::string> usedUris;
// BUFFERS (We expect only one buffer here)
json buffers; json buffers;
for (unsigned int i = 0; i < model->buffers.size(); ++i) { for (unsigned int i = 0; i < model->buffers.size(); ++i) {
json buffer; json buffer;
if (embedBuffers) { if (embedBuffers) {
SerializeGltfBuffer(model->buffers[i], buffer); SerializeGltfBuffer(model->buffers[i], buffer);
} else { } else {
SerializeGltfBuffer(model->buffers[i], buffer, binSaveFilePath, std::string binSavePath;
binFilename); std::string binUri;
if (!model->buffers[i].uri.empty()
&& !IsDataURI(model->buffers[i].uri)) {
binUri = model->buffers[i].uri;
}
else {
binUri = defaultBinFilename + defaultBinFileExt;
bool inUse = true;
int numUsed = 0;
while(inUse) {
inUse = false;
for (const std::string& usedName : usedUris) {
if (binUri.compare(usedName) != 0) continue;
inUse = true;
binUri = defaultBinFilename + std::to_string(numUsed++) + defaultBinFileExt;
break;
}
}
}
usedUris.push_back(binUri);
binSavePath = JoinPath(baseDir, binUri);
SerializeGltfBuffer(model->buffers[i], buffer, binSavePath,
binUri);
} }
buffers.push_back(buffer); buffers.push_back(buffer);
} }