Compare commits

...

24 Commits

Author SHA1 Message Date
Syoyo Fujita
81d75df48a Rename typeSizeInBytes to numComponents. 2019-08-30 19:19:52 +09:00
DingboDingboDingbo
83ccb9f28d GetTypeSizeInBytes not returning Type Size In Bytes
Changed name to be less misleading.
2019-08-29 18:49:15 -04:00
Syoyo Fujita
ff51570c26 Apply clang format.
Remove `const static std::string` global variable.
2019-08-24 16:29:14 +09:00
Syoyo Fujita
a472a3fa0f Add Set/Get SerializeDefaultValues method(W.I.P.) 2019-08-21 14:23:00 +09:00
Syoyo Fujita
1f160d5b8f Merge pull request #195 from ux3d/fix/parse-int-as-double
(also) parse int as double
2019-08-20 19:33:20 +09:00
Syoyo Fujita
5150a46072 Merge branch 'master' of github.com:syoyo/tinygltf 2019-08-20 17:11:29 +09:00
Syoyo Fujita
cea69e37a5 Suppress clang warnings. 2019-08-20 17:10:30 +09:00
Syoyo Fujita
8b56c016ab Merge pull request #193 from Selmar/emissiveFactor_defaults
Emissive factor defaults
2019-08-20 13:13:12 +09:00
Benjamin Schmithüsen
c7e205be87 when parsing a number from an int, also set the 'real value' to the value 2019-08-19 16:16:43 +02:00
Selmar Kok
6dba6c6aac [emissiveFactor] correct default values 2019-08-19 11:23:31 +02:00
Selmar Kok
6df800d2b6 [emissiveFactor] fix inconsistency with baseColorFactor where default values were set only for baseColorFactor and not emissiveFactor 2019-08-19 11:05:28 +02:00
Syoyo Fujita
2f044e77f1 Merge pull request #191 from Selmar/animation_extension_properties
Animation extension properties
2019-08-17 01:09:34 +09:00
Selmar Kok
af5a5ef026 Merge branch 'master' of github.com:syoyo/tinygltf into animation_extension_properties 2019-08-16 17:54:14 +02:00
Syoyo Fujita
6591ba4461 Merge pull request #190 from ux3d/feature/parse-node-weights
parse/serialize node weights
2019-08-16 22:21:48 +09:00
Benjamin Schmithüsen
74c3c10121 serialize node weights 2019-08-16 14:24:26 +02:00
Benjamin Schmithüsen
ad63bf748b parse node weights 2019-08-16 14:19:27 +02:00
Selmar Kok
5d43cf8e64 Merge branch 'master' of github.com:syoyo/tinygltf 2019-08-16 14:08:31 +02:00
Selmar Kok
4e2988eebd add extension property for Animation and AnimationChannel 2019-08-16 14:08:08 +02:00
Syoyo Fujita
ee179b2cb6 Set default value of minFilter and magFilter in Sampler to -1(unset), since glTF 2.0 spec does not declare default values for it.
Fixes #186
2019-08-16 13:11:30 +09:00
Syoyo Fujita
4ebd6368fb Fix inequality of texture index check when serializing texture of material.
Texture info was written even if it have invalid index(-1). Fixes #189
2019-08-15 12:25:50 +09:00
Syoyo Fujita
67d3d2504d Merge pull request #188 from ux3d/fix/alphaMode
Fixed saving of alphaMode if not OPAQUE
2019-08-14 21:40:07 +09:00
Patrick Härtl
d9a468bbb4 Fixed saving of alphaMode if not OPAQUE
Removed duplicated code for alphaCutoff
2019-08-14 14:14:07 +02:00
Syoyo Fujita
c7bae71f7f Merge pull request #185 from DerouineauNicolas/endif
remove extra #endif in examples/basic app
2019-08-14 03:09:53 +09:00
nicolasDEROUINEAU
f93642c196 remove extra #endif in examples/basic app 2019-08-13 15:08:01 +02:00
2 changed files with 130 additions and 57 deletions

View File

@@ -332,7 +332,6 @@ int main(int argc, char **argv) {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
#endif
Window window = Window(800, 600, "TinyGLTF basic example");

View File

@@ -26,6 +26,7 @@
// THE SOFTWARE.
// Version:
// - v2.3.1 Set default value of minFilter and magFilter in Sampler to -1.
// - v2.3.0 Modified Material representation according to glTF 2.0 schema
// (and introduced TextureInfo class)
// Change the behavior of `Value::IsNumber`. It return true either the
@@ -194,7 +195,7 @@ static inline int32_t GetComponentSizeInBytes(uint32_t componentType) {
}
}
static inline int32_t GetTypeSizeInBytes(uint32_t ty) {
static inline int32_t GetNumComponentsInType(uint32_t ty) {
if (ty == TINYGLTF_TYPE_SCALAR) {
return 1;
} else if (ty == TINYGLTF_TYPE_VEC2) {
@@ -241,7 +242,10 @@ class Value {
boolean_value_(false) {}
explicit Value(bool b) : type_(BOOL_TYPE) { boolean_value_ = b; }
explicit Value(int i) : type_(INT_TYPE) { int_value_ = i; }
explicit Value(int i) : type_(INT_TYPE) {
int_value_ = i;
real_value_ = i;
}
explicit Value(double n) : type_(REAL_TYPE) { real_value_ = n; }
explicit Value(const std::string &s) : type_(STRING_TYPE) {
string_value_ = s;
@@ -487,6 +491,7 @@ struct AnimationChannel {
std::string target_path; // required in ["translation", "rotation", "scale",
// "weights"]
Value extras;
ExtensionMap extensions;
AnimationChannel() : sampler(-1), target_node(-1) {}
bool operator==(const AnimationChannel &) const;
@@ -508,6 +513,7 @@ struct Animation {
std::vector<AnimationChannel> channels;
std::vector<AnimationSampler> samplers;
Value extras;
ExtensionMap extensions;
bool operator==(const Animation &) const;
};
@@ -527,20 +533,26 @@ struct Skin {
struct Sampler {
std::string name;
int minFilter; // ["NEAREST", "LINEAR", "NEAREST_MIPMAP_LINEAR",
// "LINEAR_MIPMAP_NEAREST", "NEAREST_MIPMAP_LINEAR",
// "LINEAR_MIPMAP_LINEAR"]
int magFilter; // ["NEAREST", "LINEAR"]
int wrapS; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default
// "REPEAT"
int wrapT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default
// "REPEAT"
int wrapR; // TinyGLTF extension
// glTF 2.0 spec does not define default value for `minFilter` and
// `magFilter`. Set -1 in TinyGLTF(issue #186)
int minFilter =
-1; // optional. -1 = no filter defined. ["NEAREST", "LINEAR",
// "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_NEAREST",
// "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_LINEAR"]
int magFilter =
-1; // optional. -1 = no filter defined. ["NEAREST", "LINEAR"]
int wrapS =
TINYGLTF_TEXTURE_WRAP_REPEAT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT",
// "REPEAT"], default "REPEAT"
int wrapT =
TINYGLTF_TEXTURE_WRAP_REPEAT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT",
// "REPEAT"], default "REPEAT"
int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT; // TinyGLTF extension
Value extras;
Sampler()
: minFilter(TINYGLTF_TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR),
magFilter(TINYGLTF_TEXTURE_FILTER_LINEAR),
: minFilter(-1),
magFilter(-1),
wrapS(TINYGLTF_TEXTURE_WRAP_REPEAT),
wrapT(TINYGLTF_TEXTURE_WRAP_REPEAT),
wrapR(TINYGLTF_TEXTURE_WRAP_REPEAT) {}
@@ -733,12 +745,12 @@ struct Accessor {
return -1;
}
int typeSizeInBytes = GetTypeSizeInBytes(static_cast<uint32_t>(type));
if (typeSizeInBytes <= 0) {
int numComponents = GetNumComponentsInType(static_cast<uint32_t>(type));
if (numComponents <= 0) {
return -1;
}
return componentSizeInBytes * typeSizeInBytes;
return componentSizeInBytes * numComponents;
} else {
// Check if byteStride is a mulple of the size of the accessor's component
// type.
@@ -1069,6 +1081,9 @@ bool WriteWholeFile(std::string *err, const std::string &filepath,
const std::vector<unsigned char> &contents, void *);
#endif
///
/// glTF Parser/Serialier context.
///
class TinyGLTF {
public:
#ifdef __clang__
@@ -1153,6 +1168,21 @@ class TinyGLTF {
///
void SetFsCallbacks(FsCallbacks callbacks);
///
/// Set serializing default values(default = false).
/// When true, default values are force serialized to .glTF.
/// This may be helpfull if you want to serialize a full description of glTF
/// data.
///
/// TODO(LTE): Supply parsing option as function arguments to
/// `LoadASCIIFromFile()` and others, not by a class method
///
void SetSerializeDefaultValues(const bool enabled) {
serialize_default_values_ = enabled;
}
bool GetSerializeDefaultValues() const { return serialize_default_values_; }
private:
///
/// Loads glTF asset from string(memory).
@@ -1164,9 +1194,11 @@ class TinyGLTF {
const char *str, const unsigned int length,
const std::string &base_dir, unsigned int check_sections);
const unsigned char *bin_data_;
size_t bin_size_;
bool is_binary_;
const unsigned char *bin_data_ = nullptr;
size_t bin_size_ = 0;
bool is_binary_ = false;
bool serialize_default_values_ = false; ///< Serialize default values?
FsCallbacks fs = {
#ifndef TINYGLTF_NO_FS
@@ -1262,6 +1294,9 @@ class TinyGLTF {
#if __has_warning("-Wmismatched-tags")
#pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
#if __has_warning("-Wextra-semi-stmt")
#pragma clang diagnostic ignored "-Wextra-semi-stmt"
#endif
#endif
// Disable GCC warnigs
@@ -1411,11 +1446,12 @@ bool Accessor::operator==(const Accessor &other) const {
this->normalized == other.normalized && this->type == other.type;
}
bool Animation::operator==(const Animation &other) const {
return this->channels == other.channels && this->extras == other.extras &&
return this->channels == other.channels &&
this->extensions == other.extensions && this->extras == other.extras &&
this->name == other.name && this->samplers == other.samplers;
}
bool AnimationChannel::operator==(const AnimationChannel &other) const {
return this->extras == other.extras &&
return this->extensions == other.extensions && this->extras == other.extras &&
this->target_node == other.target_node &&
this->target_path == other.target_path &&
this->sampler == other.sampler;
@@ -1466,7 +1502,7 @@ bool Material::operator==(const Material &other) const {
(this->emissiveTexture == other.emissiveTexture) &&
Equals(this->emissiveFactor, other.emissiveFactor) &&
(this->alphaMode == other.alphaMode) &&
(this->alphaCutoff == other.alphaCutoff) &&
TINYGLTF_DOUBLE_EQUAL(this->alphaCutoff, other.alphaCutoff) &&
(this->doubleSided == other.doubleSided) &&
(this->extensions == other.extensions) &&
(this->extras == other.extras) && (this->values == other.values) &&
@@ -1558,7 +1594,6 @@ bool Sampler::operator==(const Sampler &other) const {
bool Scene::operator==(const Scene &other) const {
return this->extensions == other.extensions && this->extras == other.extras &&
this->name == other.name && this->nodes == other.nodes;
;
}
bool Skin::operator==(const Skin &other) const {
return this->inverseBindMatrices == other.inverseBindMatrices &&
@@ -1694,15 +1729,9 @@ std::string base64_decode(std::string const &s);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wexit-time-destructors"
#pragma clang diagnostic ignored "-Wglobal-constructors"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wconversion"
#endif
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
@@ -1716,6 +1745,11 @@ std::string base64_encode(unsigned char const *bytes_to_encode,
unsigned char char_array_3[3];
unsigned char char_array_4[4];
const char *base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
@@ -1756,6 +1790,11 @@ std::string base64_decode(std::string const &encoded_string) {
unsigned char char_array_4[4], char_array_3[3];
std::string ret;
const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
while (in_len-- && (encoded_string[in_] != '=') &&
is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_];
@@ -1877,7 +1916,7 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
(void)user_data;
(void)warn;
int w, h, comp, req_comp;
int w = 0, h = 0, comp = 0, req_comp = 0;
unsigned char *data = nullptr;
@@ -1894,8 +1933,8 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
// the Image metadata to signal that this image uses 2 bytes (16bits) per
// channel:
if (stbi_is_16_bit_from_memory(bytes, size)) {
data = (unsigned char *)stbi_load_16_from_memory(bytes, size, &w, &h, &comp,
req_comp);
data = reinterpret_cast<unsigned char *>(
stbi_load_16_from_memory(bytes, size, &w, &h, &comp, req_comp));
if (data) {
bits = 16;
pixel_type = TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT;
@@ -1922,7 +1961,7 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
return false;
}
if (w < 1 || h < 1) {
if ((w < 1) || (h < 1)) {
stbi_image_free(data);
if (err) {
(*err) += "Invalid image data for image[" + std::to_string(image_idx) +
@@ -1960,7 +1999,7 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
image->component = req_comp;
image->bits = bits;
image->pixel_type = pixel_type;
image->image.resize(static_cast<size_t>(w * h * req_comp) * (bits / 8));
image->image.resize(static_cast<size_t>(w * h * req_comp) * size_t(bits / 8));
std::copy(data, data + w * h * req_comp * (bits / 8), image->image.begin());
stbi_image_free(data);
@@ -3673,6 +3712,8 @@ static bool ParseNode(Node *node, std::string *err, const json &o) {
node->children.clear();
ParseIntegerArrayProperty(&node->children, err, o, "children", false);
ParseNumberArrayProperty(&node->weights, err, o, "weights", false);
ParseExtensionsProperty(&node->extensions, err, o);
ParseExtrasProperty(&(node->extras), o);
@@ -3729,8 +3770,22 @@ static bool ParsePbrMetallicRoughness(PbrMetallicRoughness *pbr,
static bool ParseMaterial(Material *material, std::string *err, const json &o) {
ParseStringProperty(&material->name, err, o, "name", /* required */ false);
ParseNumberArrayProperty(&material->emissiveFactor, err, o, "emissiveFactor",
/* required */ false);
if (ParseNumberArrayProperty(&material->emissiveFactor, err, o,
"emissiveFactor",
/* required */ false)) {
if (material->emissiveFactor.size() != 3) {
if (err) {
(*err) +=
"Array length of `emissiveFactor` parameter in "
"material must be 3, but got " +
std::to_string(material->emissiveFactor.size()) + "\n";
}
return false;
}
} else {
// fill with default values
material->emissiveFactor = {0.0, 0.0, 0.0};
}
ParseStringProperty(&material->alphaMode, err, o, "alphaMode",
/* required */ false);
@@ -3850,6 +3905,7 @@ static bool ParseAnimationChannel(AnimationChannel *channel, std::string *err,
channel->sampler = samplerIndex;
channel->target_node = targetIndex;
ParseExtensionsProperty(&channel->extensions, err, o);
ParseExtrasProperty(&(channel->extras), o);
return true;
@@ -3909,6 +3965,7 @@ static bool ParseAnimation(Animation *animation, std::string *err,
ParseStringProperty(&animation->name, err, o, "name", false);
ParseExtensionsProperty(&animation->extensions, err, o);
ParseExtrasProperty(&(animation->extras), o);
return true;
@@ -3917,19 +3974,25 @@ static bool ParseAnimation(Animation *animation, std::string *err,
static bool ParseSampler(Sampler *sampler, std::string *err, const json &o) {
ParseStringProperty(&sampler->name, err, o, "name", false);
int minFilter = TINYGLTF_TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR;
int magFilter = TINYGLTF_TEXTURE_FILTER_LINEAR;
int minFilter = -1;
int magFilter = -1;
int wrapS = TINYGLTF_TEXTURE_WRAP_REPEAT;
int wrapT = TINYGLTF_TEXTURE_WRAP_REPEAT;
int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT;
ParseIntegerProperty(&minFilter, err, o, "minFilter", false);
ParseIntegerProperty(&magFilter, err, o, "magFilter", false);
ParseIntegerProperty(&wrapS, err, o, "wrapS", false);
ParseIntegerProperty(&wrapT, err, o, "wrapT", false);
ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf extension
// TODO(syoyo): Check the value is alloed one.
// (e.g. we allow 9728(NEAREST), but don't allow 9727)
sampler->minFilter = minFilter;
sampler->magFilter = magFilter;
sampler->wrapS = wrapS;
sampler->wrapT = wrapT;
sampler->wrapR = wrapR;
ParseExtrasProperty(&(sampler->extras), o);
@@ -4432,7 +4495,8 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
return false;
}
auto bufferView = model->accessors[primitive.indices].bufferView;
auto bufferView =
model->accessors[size_t(primitive.indices)].bufferView;
if (bufferView < 0 || size_t(bufferView) >= model->bufferViews.size()) {
if (err) {
(*err) += "accessor[" + std::to_string(primitive.indices) +
@@ -4441,7 +4505,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
return false;
}
model->bufferViews[bufferView].target =
model->bufferViews[size_t(bufferView)].target =
TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER;
// we could optionally check if acessors' bufferView type is Scalar, as
// it should be
@@ -5073,6 +5137,7 @@ static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
return true;
}
#if 0 // FIXME(syoyo): not used. will be removed in the future release.
static void SerializeParameterMap(ParameterMap &param, json &o) {
for (ParameterMap::iterator paramIt = param.begin(); paramIt != param.end();
++paramIt) {
@@ -5101,6 +5166,7 @@ static void SerializeParameterMap(ParameterMap &param, json &o) {
}
}
}
#endif
static void SerializeExtensionMap(ExtensionMap &extensions, json &o) {
if (!extensions.size()) return;
@@ -5183,6 +5249,8 @@ static void SerializeGltfAnimationChannel(AnimationChannel &channel, json &o) {
if (channel.extras.Type() != NULL_TYPE) {
SerializeValue("extras", channel.extras, o);
}
SerializeExtensionMap(channel.extensions, o);
}
static void SerializeGltfAnimationSampler(AnimationSampler &sampler, json &o) {
@@ -5220,6 +5288,8 @@ static void SerializeGltfAnimation(Animation &animation, json &o) {
if (animation.extras.Type() != NULL_TYPE) {
SerializeValue("extras", animation.extras, o);
}
SerializeExtensionMap(animation.extensions, o);
}
static void SerializeGltfAsset(Asset &asset, json &o) {
@@ -5382,13 +5452,13 @@ static void SerializeGltfPbrMetallicRoughness(PbrMetallicRoughness &pbr,
SerializeNumberProperty("roughnessFactor", pbr.roughnessFactor, o);
}
if (pbr.baseColorTexture.index >= -1) {
if (pbr.baseColorTexture.index > -1) {
json texinfo;
SerializeGltfTextureInfo(pbr.baseColorTexture, texinfo);
o["baseColorTexture"] = texinfo;
}
if (pbr.metallicRoughnessTexture.index >= -1) {
if (pbr.metallicRoughnessTexture.index > -1) {
json texinfo;
SerializeGltfTextureInfo(pbr.metallicRoughnessTexture, texinfo);
o["metallicRoughnessTexture"] = texinfo;
@@ -5412,29 +5482,25 @@ static void SerializeGltfMaterial(Material &material, json &o) {
SerializeNumberProperty("alphaCutoff", material.alphaCutoff, o);
}
if (material.alphaMode.compare("OPAQUE") == 0) {
if (material.alphaMode.compare("OPAQUE") != 0) {
SerializeStringProperty("alphaMode", material.alphaMode, o);
}
if (!TINYGLTF_DOUBLE_EQUAL(material.alphaCutoff, 0.5)) {
SerializeNumberProperty("alphaCutoff", material.alphaCutoff, o);
}
o["doubleSided"] = json(material.doubleSided);
if (material.normalTexture.index >= -1) {
if (material.normalTexture.index > -1) {
json texinfo;
SerializeGltfNormalTextureInfo(material.normalTexture, texinfo);
o["normalTexture"] = texinfo;
}
if (material.occlusionTexture.index >= -1) {
if (material.occlusionTexture.index > -1) {
json texinfo;
SerializeGltfOcclusionTextureInfo(material.occlusionTexture, texinfo);
o["occlusionTexture"] = texinfo;
}
if (material.emissiveTexture.index >= -1) {
if (material.emissiveTexture.index > -1) {
json texinfo;
SerializeGltfTextureInfo(material.emissiveTexture, texinfo);
o["emissiveTexture"] = texinfo;
@@ -5579,6 +5645,10 @@ static void SerializeGltfNode(Node &node, json &o) {
SerializeNumberProperty<int>("camera", node.camera, o);
}
if (node.weights.size() > 0) {
SerializeNumberArrayProperty<double>("weights", node.weights, o);
}
if (node.extras.Type() != NULL_TYPE) {
SerializeValue("extras", node.extras, o);
}
@@ -5589,8 +5659,12 @@ static void SerializeGltfNode(Node &node, json &o) {
}
static void SerializeGltfSampler(Sampler &sampler, json &o) {
SerializeNumberProperty("magFilter", sampler.magFilter, o);
SerializeNumberProperty("minFilter", sampler.minFilter, o);
if (sampler.magFilter != -1) {
SerializeNumberProperty("magFilter", sampler.magFilter, o);
}
if (sampler.minFilter != -1) {
SerializeNumberProperty("minFilter", sampler.minFilter, o);
}
SerializeNumberProperty("wrapR", sampler.wrapR, o);
SerializeNumberProperty("wrapS", sampler.wrapS, o);
SerializeNumberProperty("wrapT", sampler.wrapT, o);
@@ -5883,7 +5957,7 @@ static void WriteBinaryGltfStream(std::ostream &stream,
// padding
const int length = 12 + 8 + int(content.size()) + padding_size;
stream.write(header.c_str(), header.size());
stream.write(header.c_str(), std::streamsize(header.size()));
stream.write(reinterpret_cast<const char *>(&version), sizeof(version));
stream.write(reinterpret_cast<const char *>(&length), sizeof(length));
@@ -5894,12 +5968,12 @@ static void WriteBinaryGltfStream(std::ostream &stream,
sizeof(model_length));
stream.write(reinterpret_cast<const char *>(&model_format),
sizeof(model_format));
stream.write(content.c_str(), content.size());
stream.write(content.c_str(), std::streamsize(content.size()));
// Chunk must be multiplies of 4, so pad with spaces
if (padding_size > 0) {
const std::string padding = std::string(padding_size, ' ');
stream.write(padding.c_str(), padding.size());
const std::string padding = std::string(size_t(padding_size), ' ');
stream.write(padding.c_str(), std::streamsize(padding.size()));
}
}