diff --git a/tiny_gltf.h b/tiny_gltf.h index 4f8fcd2b..3572388c 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -32,7 +32,7 @@ // - v2.6.0 Support serializing sparse accessor(Thanks to @fynv). // Disable expanding file path for security(no use of awkward `wordexp` anymore). // - 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 material has all default // parameters. // - v2.4.2 Decode percent-encoded URI. // - v2.4.1 Fix some glTF object class does not have `extensions` and/or @@ -46,7 +46,7 @@ // - v2.2.0 Add loading 16bit PNG support. Add Sparse accessor support(Thanks // to @Ybalrid) // - v2.1.0 Add draco compression. -// - v2.0.1 Add comparsion feature(Thanks to @Selmar). +// - v2.0.1 Add comparison feature(Thanks to @Selmar). // - v2.0.0 glTF 2.0!. // // Tiny glTF loader is using following third party libraries: @@ -233,7 +233,7 @@ static inline int32_t GetComponentSizeInBytes(uint32_t componentType) { } else if (componentType == TINYGLTF_COMPONENT_TYPE_DOUBLE) { return 8; } else { - // Unknown componenty type + // Unknown component type return -1; } } @@ -254,7 +254,7 @@ static inline int32_t GetNumComponentsInType(uint32_t ty) { } else if (ty == TINYGLTF_TYPE_MAT4) { return 16; } else { - // Unknown componenty type + // Unknown component type return -1; } } @@ -441,7 +441,7 @@ TINYGLTF_VALUE_GET(Value::Object, object_value_) #pragma clang diagnostic ignored "-Wpadded" #endif -/// Agregate object for representing a color +/// Aggregate object for representing a color using ColorValue = std::array; // === legacy interface ==== @@ -478,7 +478,7 @@ struct Parameter { if (it != std::end(json_double_value)) { return int(it->second); } - // As per the spec, if texCoord is ommited, this parameter is 0 + // As per the spec, if texCoord is omitted, this parameter is 0 return 0; } @@ -490,7 +490,7 @@ struct Parameter { if (it != std::end(json_double_value)) { return it->second; } - // As per the spec, if scale is ommited, this paramter is 1 + // As per the spec, if scale is omitted, this parameter is 1 return 1; } @@ -502,7 +502,7 @@ struct Parameter { if (it != std::end(json_double_value)) { return it->second; } - // As per the spec, if strenghth is ommited, this parameter is 1 + // As per the spec, if strength is omitted, this parameter is 1 return 1; } @@ -516,7 +516,7 @@ struct Parameter { /// material ColorValue ColorFactor() const { return { - {// this agregate intialize the std::array object, and uses C++11 RVO. + {// this aggregate initialize the std::array object, and uses C++11 RVO. number_array[0], number_array[1], number_array[2], (number_array.size() > 3 ? number_array[3] : 1.0)}}; } @@ -827,7 +827,7 @@ struct BufferView { size_t byteStride{0}; // minimum 4, maximum 252 (multiple of 4), default 0 = // understood to be tightly packed int target{0}; // ["ARRAY_BUFFER", "ELEMENT_ARRAY_BUFFER"] for vertex indices - // or atttribs. Could be 0 for other data + // or attribs. Could be 0 for other data Value extras; ExtensionMap extensions; @@ -903,7 +903,7 @@ struct Accessor { return componentSizeInBytes * numComponents; } else { - // Check if byteStride is a mulple of the size of the accessor's component + // Check if byteStride is a multiple of the size of the accessor's component // type. int componentSizeInBytes = GetComponentSizeInBytes(static_cast(componentType)); @@ -942,7 +942,7 @@ struct PerspectiveCamera { PerspectiveCamera() : aspectRatio(0.0), yfov(0.0), - zfar(0.0) // 0 = use infinite projecton matrix + zfar(0.0) // 0 = use infinite projection matrix , znear(0.0) {} DEFAULT_METHODS(PerspectiveCamera) @@ -1003,7 +1003,7 @@ struct Primitive { int indices; // The index of the accessor that contains the indices. int mode; // one of TINYGLTF_MODE_*** std::vector > targets; // array of morph targets, - // where each target is a dict with attribues in ["POSITION, "NORMAL", + // where each target is a dict with attributes in ["POSITION, "NORMAL", // "TANGENT"] pointing // to their corresponding accessors ExtensionMap extensions; @@ -1138,7 +1138,7 @@ struct Light { std::vector color; double intensity{1.0}; std::string type; - double range{0.0}; // 0.0 = inifinite + double range{0.0}; // 0.0 = infinite SpotLight spot; Light() : intensity(1.0), range(0.0) {} @@ -1288,7 +1288,7 @@ bool WriteWholeFile(std::string *err, const std::string &filepath, #endif /// -/// glTF Parser/Serialier context. +/// glTF Parser/Serializer context. /// class TinyGLTF { public: @@ -1351,7 +1351,7 @@ class TinyGLTF { unsigned int check_sections = REQUIRE_VERSION); /// - /// Write glTF to stream, buffers and images will be embeded + /// Write glTF to stream, buffers and images will be embedded /// bool WriteGltfSceneToStream(Model *model, std::ostream &stream, bool prettyPrint, bool writeBinary); @@ -1386,7 +1386,7 @@ class TinyGLTF { /// /// 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 + /// This may be helpful if you want to serialize a full description of glTF /// data. /// /// TODO(LTE): Supply parsing option as function arguments to @@ -1412,8 +1412,8 @@ class TinyGLTF { } /// - /// Specify whether preserve image channales when loading images or not. - /// (Not effective when the user suppy their own LoadImageData callbacks) + /// Specify whether preserve image channels when loading images or not. + /// (Not effective when the user supplies their own LoadImageData callbacks) /// void SetPreserveImageChannels(bool onoff) { preserve_image_channels_ = onoff; @@ -1550,7 +1550,7 @@ class TinyGLTF { #endif #endif -// Disable GCC warnigs +// Disable GCC warnings #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wtype-limits" @@ -1599,7 +1599,7 @@ class TinyGLTF { // issue 143. // Define NOMINMAX to avoid min/max defines, -// but undef it after included windows.h +// but undef it after included Windows.h #ifndef NOMINMAX #define TINYGLTF_INTERNAL_NOMINMAX #define NOMINMAX @@ -1609,7 +1609,11 @@ class TinyGLTF { #define WIN32_LEAN_AND_MEAN #define TINYGLTF_INTERNAL_WIN32_LEAN_AND_MEAN #endif -#include // include API for expanding a file path +#ifndef __MINGW32__ +#include // include API for expanding a file path +#else +#include +#endif #ifdef TINYGLTF_INTERNAL_WIN32_LEAN_AND_MEAN #undef WIN32_LEAN_AND_MEAN @@ -1740,7 +1744,7 @@ namespace tinygltf { struct LoadImageDataOption { // true: preserve image channels(e.g. load as RGB image if the image has RGB // channels) default `false`(channels are expanded to RGBA for backward - // compatiblity). + // compatibility). bool preserve_channels{false}; }; @@ -2387,7 +2391,7 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err, // It is possible that the image we want to load is a 16bit per channel image // We are going to attempt to load it as 16bit per channel, and if it worked, - // set the image data accodingly. We are casting the returned pointer into + // set the image data accordingly. We are casting the returned pointer into // unsigned char, because we are representing "bytes". But we are updating // the Image metadata to signal that this image uses 2 bytes (16bits) per // channel: @@ -2402,7 +2406,7 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err, // at this point, if data is still NULL, it means that the image wasn't // 16bit per channel, we are going to load it as a normal 8bit per channel - // mage as we used to do: + // image as we used to do: // if image cannot be decoded, ignore parsing and keep it by its path // don't break in this case // FIXME we should only enter this function if the image is embedded. If @@ -2562,7 +2566,7 @@ void TinyGLTF::SetFsCallbacks(FsCallbacks callbacks) { fs = callbacks; } static inline std::wstring UTF8ToWchar(const std::string &str) { int wstr_size = MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), nullptr, 0); - std::wstring wstr(wstr_size, 0); + std::wstring wstr((size_t)wstr_size, 0); MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), &wstr[0], (int)wstr.size()); return wstr; @@ -2570,10 +2574,10 @@ static inline std::wstring UTF8ToWchar(const std::string &str) { static inline std::string WcharToUTF8(const std::wstring &wstr) { int str_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), - nullptr, 0, NULL, NULL); - std::string str(str_size, 0); + nullptr, 0, nullptr, nullptr); + std::string str((size_t)str_size, 0); WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), &str[0], - (int)str.size(), NULL, NULL); + (int)str.size(), nullptr, nullptr); return str; } #endif @@ -2826,7 +2830,7 @@ static void UpdateImageObject(Image &image, std::string &baseDir, int index, void *user_data = nullptr) { std::string filename; std::string ext; - // If image has uri, use it it as a filename + // If image has uri, use it as a filename if (image.uri.size()) { filename = GetBaseFilename(image.uri); ext = GetFilePathExtension(filename); @@ -4272,7 +4276,7 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err, } if (!FindMember(o, "values", values_iterator)) { - (*err) = "the sparse object ob ths accessor doesn't have values"; + (*err) = "the sparse object of this accessor doesn't have values"; return false; } @@ -4618,7 +4622,7 @@ static bool ParsePrimitive(Primitive *primitive, Model *model, std::string *err, int mode = TINYGLTF_MODE_TRIANGLES; ParseIntegerProperty(&mode, err, o, "mode", false); - primitive->mode = mode; // Why only triangled were supported ? + primitive->mode = mode; // Why only triangles were supported ? int indices = -1; ParseIntegerProperty(&indices, err, o, "indices", false); @@ -4901,7 +4905,7 @@ static bool ParseMaterial(Material *material, std::string *err, const json &o, // Old code path. For backward compatibility, we still store material values // as Parameter. This will create duplicated information for - // example(pbrMetallicRoughness), but should be neglible in terms of memory + // example(pbrMetallicRoughness), but should be negligible in terms of memory // consumption. // TODO(syoyo): Remove in the next major release. material->values.clear(); @@ -4934,7 +4938,7 @@ static bool ParseMaterial(Material *material, std::string *err, const json &o, Parameter param; if (ParseParameterProperty(¶m, err, o, key, false)) { // names of materials have already been parsed. Putting it in this map - // doesn't correctly reflext the glTF specification + // doesn't correctly reflect the glTF specification if (key != "name") material->additionalValues.emplace(std::move(key), std::move(param)); } @@ -5140,7 +5144,7 @@ static bool ParseSampler(Sampler *sampler, std::string *err, const json &o, // ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf // extension - // TODO(syoyo): Check the value is alloed one. + // TODO(syoyo): Check the value is allowed one. // (e.g. we allow 9728(NEAREST), but don't allow 9727) sampler->minFilter = minFilter; @@ -5349,7 +5353,7 @@ static bool ParseCamera(Camera *camera, std::string *err, const json &o, if (!FindMember(o, "orthographic", orthoIt)) { if (err) { std::stringstream ss; - ss << "Orhographic camera description not found." << std::endl; + ss << "Orthographic camera description not found." << std::endl; (*err) += ss.str(); } return false; @@ -5801,7 +5805,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn, model->bufferViews[size_t(bufferView)].target = TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER; - // we could optionally check if acessors' bufferView type is Scalar, as + // we could optionally check if accessors' bufferView type is Scalar, as // it should be } @@ -5810,7 +5814,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn, if (accessorsIndex < model->accessors.size()) { const auto bufferView = model->accessors[accessorsIndex].bufferView; // bufferView could be null(-1) for sparse morph target - if (bufferView >= 0 && bufferView < model->bufferViews.size()) { + if (bufferView >= 0 && bufferView < (int)model->bufferViews.size()) { model->bufferViews[size_t(bufferView)].target = TINYGLTF_TARGET_ARRAY_BUFFER; } @@ -5823,7 +5827,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn, if (accessorsIndex < model->accessors.size()) { const auto bufferView = model->accessors[accessorsIndex].bufferView; // bufferView could be null(-1) for sparse morph target - if (bufferView >= 0 && bufferView < model->bufferViews.size()) { + if (bufferView >= 0 && bufferView < (int)model->bufferViews.size()) { model->bufferViews[size_t(bufferView)].target = TINYGLTF_TARGET_ARRAY_BUFFER; } @@ -6324,7 +6328,7 @@ bool TinyGLTF::LoadBinaryFromMemory(Model *model, std::string *err, bin_size_ = 0; } else { // Read Chunk1 info(BIN data) - // At least Chunk1 should have 12 bytes(8 bytes(header) + 4 bytes(bin payload could be 1~3 bytes, but need to be aliged to 4 bytes) + // At least Chunk1 should have 12 bytes(8 bytes(header) + 4 bytes(bin payload could be 1~3 bytes, but need to be aligned to 4 bytes) if ((header_and_json_size + 12ull) > uint64_t(length)) { if (err) { (*err) = "Insufficient storage space for Chunk1(BIN data). At least Chunk1 Must have 4 bytes or more bytes, but got " + std::to_string((header_and_json_size + 12ull) - uint64_t(length)) + ".\n"; @@ -6364,7 +6368,7 @@ bool TinyGLTF::LoadBinaryFromMemory(Model *model, std::string *err, if (chunk1_format != 0x004e4942) { if (err) { - (*err) = "Invlid type for chunk1 data."; + (*err) = "Invalid type for chunk1 data."; } return false; } @@ -6653,7 +6657,7 @@ static void SerializeGltfBufferData(const std::vector &data, SerializeStringProperty("uri", header + encodedData, o); } else { // Issue #229 - // size 0 is allowd. Just emit mime header. + // size 0 is allowed. Just emit mime header. SerializeStringProperty("uri", header, o); } } @@ -7151,7 +7155,7 @@ static void SerializeGltfMaterial(Material &material, json &o) { // Do not serialize `pbrMetallicRoughness` if pbrMetallicRoughness has all // default values(json is null). Otherwise it will serialize to // `pbrMetallicRoughness : null`, which cannot be read by other glTF - // importers(and validators). + // importers (and validators). // if (!JsonIsNull(pbrMetallicRoughness)) { JsonAddMember(o, "pbrMetallicRoughness", std::move(pbrMetallicRoughness)); @@ -7193,7 +7197,7 @@ static void SerializeGltfMesh(Mesh &mesh, json &o) { JsonAddMember(primitive, "attributes", std::move(attributes)); } - // Indicies is optional + // Indices is optional if (gltfPrimitive.indices > -1) { SerializeNumberProperty("indices", gltfPrimitive.indices, primitive); }