mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 08:15:52 +08:00
Merge branch 'master' of github.com:syoyo/tinygltf
This commit is contained in:
commit
9117abb45d
45
tiny_gltf.h
45
tiny_gltf.h
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
// Version:
|
// Version:
|
||||||
// - v2.6.0 Disable expanding file path for security(no use of awkward `wordexp` anymore).
|
// - v2.6.0 Disable expanding file path for security(no use of awkward `wordexp` anymore).
|
||||||
|
// Support serializing sparse accessor(Thanks to @fynv).
|
||||||
// - v2.5.0 Add SetPreserveImageChannels() option to load image data as is.
|
// - v2.5.0 Add SetPreserveImageChannels() option to load image data as is.
|
||||||
// - v2.4.3 Fix null object output when when material has all default
|
// - v2.4.3 Fix null object output when when material has all default
|
||||||
// parameters.
|
// parameters.
|
||||||
@ -1434,6 +1435,10 @@ class TinyGLTF {
|
|||||||
bool preserve_image_channels_ = false; /// Default false(expand channels to
|
bool preserve_image_channels_ = false; /// Default false(expand channels to
|
||||||
/// RGBA) for backward compatibility.
|
/// RGBA) for backward compatibility.
|
||||||
|
|
||||||
|
// Warning & error messages
|
||||||
|
std::string warn_;
|
||||||
|
std::string err_;
|
||||||
|
|
||||||
FsCallbacks fs = {
|
FsCallbacks fs = {
|
||||||
#ifndef TINYGLTF_NO_FS
|
#ifndef TINYGLTF_NO_FS
|
||||||
&tinygltf::FileExists, &tinygltf::ExpandFilePath,
|
&tinygltf::FileExists, &tinygltf::ExpandFilePath,
|
||||||
@ -6711,6 +6716,27 @@ static void SerializeGltfAccessor(Accessor &accessor, json &o) {
|
|||||||
if (accessor.extras.Type() != NULL_TYPE) {
|
if (accessor.extras.Type() != NULL_TYPE) {
|
||||||
SerializeValue("extras", accessor.extras, o);
|
SerializeValue("extras", accessor.extras, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sparse
|
||||||
|
if (accessor.sparse.isSparse)
|
||||||
|
{
|
||||||
|
json sparse;
|
||||||
|
SerializeNumberProperty<int>("count", accessor.sparse.count, sparse);
|
||||||
|
{
|
||||||
|
json indices;
|
||||||
|
SerializeNumberProperty<int>("bufferView", accessor.sparse.indices.bufferView, indices);
|
||||||
|
SerializeNumberProperty<int>("byteOffset", accessor.sparse.indices.byteOffset, indices);
|
||||||
|
SerializeNumberProperty<int>("componentType", accessor.sparse.indices.componentType, indices);
|
||||||
|
JsonAddMember(sparse, "indices", std::move(indices));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
json values;
|
||||||
|
SerializeNumberProperty<int>("bufferView", accessor.sparse.values.bufferView, values);
|
||||||
|
SerializeNumberProperty<int>("byteOffset", accessor.sparse.values.byteOffset, values);
|
||||||
|
JsonAddMember(sparse, "values", std::move(values));
|
||||||
|
}
|
||||||
|
JsonAddMember(o, "sparse", std::move(sparse));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfAnimationChannel(AnimationChannel &channel, json &o) {
|
static void SerializeGltfAnimationChannel(AnimationChannel &channel, json &o) {
|
||||||
@ -7547,7 +7573,7 @@ static bool WriteGltfFile(const std::string &output,
|
|||||||
return WriteGltfStream(gltfFile, content);
|
return WriteGltfStream(gltfFile, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteBinaryGltfStream(std::ostream &stream,
|
static bool WriteBinaryGltfStream(std::ostream &stream,
|
||||||
const std::string &content,
|
const std::string &content,
|
||||||
const std::vector<unsigned char> &binBuffer) {
|
const std::vector<unsigned char> &binBuffer) {
|
||||||
const std::string header = "glTF";
|
const std::string header = "glTF";
|
||||||
@ -7603,9 +7629,12 @@ static void WriteBinaryGltfStream(std::ostream &stream,
|
|||||||
std::streamsize(padding.size()));
|
std::streamsize(padding.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Check error on stream.write
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteBinaryGltfFile(const std::string &output,
|
static bool WriteBinaryGltfFile(const std::string &output,
|
||||||
const std::string &content,
|
const std::string &content,
|
||||||
const std::vector<unsigned char> &binBuffer) {
|
const std::vector<unsigned char> &binBuffer) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -7623,7 +7652,7 @@ static void WriteBinaryGltfFile(const std::string &output,
|
|||||||
#else
|
#else
|
||||||
std::ofstream gltfFile(output.c_str(), std::ios::binary);
|
std::ofstream gltfFile(output.c_str(), std::ios::binary);
|
||||||
#endif
|
#endif
|
||||||
WriteBinaryGltfStream(gltfFile, content, binBuffer);
|
return WriteBinaryGltfStream(gltfFile, content, binBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TinyGLTF::WriteGltfSceneToStream(Model *model, std::ostream &stream,
|
bool TinyGLTF::WriteGltfSceneToStream(Model *model, std::ostream &stream,
|
||||||
@ -7671,12 +7700,11 @@ bool TinyGLTF::WriteGltfSceneToStream(Model *model, std::ostream &stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (writeBinary) {
|
if (writeBinary) {
|
||||||
WriteBinaryGltfStream(stream, JsonToString(output), binBuffer);
|
return WriteBinaryGltfStream(stream, JsonToString(output), binBuffer);
|
||||||
} else {
|
} else {
|
||||||
WriteGltfStream(stream, JsonToString(output, prettyPrint ? 2 : -1));
|
return WriteGltfStream(stream, JsonToString(output, prettyPrint ? 2 : -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
||||||
@ -7761,12 +7789,11 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (writeBinary) {
|
if (writeBinary) {
|
||||||
WriteBinaryGltfFile(filename, JsonToString(output), binBuffer);
|
return WriteBinaryGltfFile(filename, JsonToString(output), binBuffer);
|
||||||
} else {
|
} else {
|
||||||
WriteGltfFile(filename, JsonToString(output, (prettyPrint ? 2 : -1)));
|
return WriteGltfFile(filename, JsonToString(output, (prettyPrint ? 2 : -1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tinygltf
|
} // namespace tinygltf
|
||||||
|
Loading…
x
Reference in New Issue
Block a user