mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-07-14 01:59:10 +00:00
Compare commits
24 Commits
textureinf
...
DingboDing
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81d75df48a | ||
|
|
83ccb9f28d | ||
|
|
ff51570c26 | ||
|
|
a472a3fa0f | ||
|
|
1f160d5b8f | ||
|
|
5150a46072 | ||
|
|
cea69e37a5 | ||
|
|
8b56c016ab | ||
|
|
c7e205be87 | ||
|
|
6dba6c6aac | ||
|
|
6df800d2b6 | ||
|
|
2f044e77f1 | ||
|
|
af5a5ef026 | ||
|
|
6591ba4461 | ||
|
|
74c3c10121 | ||
|
|
ad63bf748b | ||
|
|
5d43cf8e64 | ||
|
|
4e2988eebd | ||
|
|
ee179b2cb6 | ||
|
|
4ebd6368fb | ||
|
|
67d3d2504d | ||
|
|
d9a468bbb4 | ||
|
|
c7bae71f7f | ||
|
|
f93642c196 |
@@ -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");
|
||||
|
||||
186
tiny_gltf.h
186
tiny_gltf.h
@@ -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 ¶m, json &o) {
|
||||
for (ParameterMap::iterator paramIt = param.begin(); paramIt != param.end();
|
||||
++paramIt) {
|
||||
@@ -5101,6 +5166,7 @@ static void SerializeParameterMap(ParameterMap ¶m, 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user