diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e7e632..0f7f8a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,14 +14,18 @@ set(LIBGLTF_PLATFORM_LINUX FALSE) set(LIBGLTF_PLATFORM_MACOS FALSE) option(LIBGLTF_COVERAGE_GCOV "Coverage gcov (debug, Linux builds only)" OFF) -option(LIBGLTF_BUILD_DEBUG_FOR_UE4 "Build for UE4" OFF) +option(LIBGLTF_BUILD_FOR_UE4 "Build for UE4" OFF) + +if(LIBGLTF_BUILD_FOR_UE4) + add_definitions(-DLIBGLTF_USE_WCHAR) +endif() if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(LIBGLTF_PLATFORM_WINDOWS TRUE) add_definitions(-DLIBGLTF_PLATFORM_WINDOWS) set(DYNAMIC_LIBRARY_EXTENSION ".dll") set(STATIC_LIBRARY_EXTENSION ".lib") - if(LIBGLTF_BUILD_DEBUG_FOR_UE4) + if(LIBGLTF_BUILD_FOR_UE4) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MD") endif() if((CMAKE_EXE_LINKER_FLAGS STREQUAL "/machine:X86") OR (CMAKE_EXE_LINKER_FLAGS STREQUAL " /machine:X86")) @@ -101,3 +105,4 @@ add_subdirectory(source) add_subdirectory(tools) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT libgltf) + diff --git a/include/libgltf/libgltf.h b/include/libgltf/libgltf.h index 4a4889f..5eec812 100644 --- a/include/libgltf/libgltf.h +++ b/include/libgltf/libgltf.h @@ -8,16 +8,10 @@ namespace libgltf { -#if defined(LIBGLTF_PLATFORM_WINDOWS) -# if defined(UNICODE) +#if defined(LIBGLTF_USE_WCHAR) typedef std::wstring GLTFString; -# else - typedef std::string GLTFString; -# endif -#elif defined(LIBGLTF_PLATFORM_LINUX) || defined(LIBGLTF_PLATFORM_MACOS) || defined(PLATFORM_ANDROID) || defined(PLATFORM_IOS) - typedef std::string GLTFString; #else -#error Sorry, not support your platform. + typedef std::string GLTFString; #endif struct SGlTF; @@ -38,6 +32,49 @@ namespace libgltf std::shared_ptr extensions; }; + /*! + * struct: SGlTFChildofRootProperty + */ + struct SGlTFChildofRootProperty : SGlTFProperty + { + SGlTFChildofRootProperty(); + + // Check valid + operator bool() const; + + // The user-defined name of this object. + GLTFString name; + }; + + /*! + * struct: SMaterial + * The material appearance of a primitive. + */ + struct SMaterial : SGlTFChildofRootProperty + { + SMaterial(); + + // Check valid + operator bool() const; + + // The alpha cutoff value of the material. + float alphaCutoff; + // The emissive map texture. + std::shared_ptr emissiveTexture; + // A set of parameter values that are used to define the metallic-roughness material model from Physically-Based Rendering (PBR) methodology. When not specified, all the default values of `pbrMetallicRoughness` apply. + std::shared_ptr pbrMetallicRoughness; + // The occlusion map texture. + std::shared_ptr occlusionTexture; + // The alpha rendering mode of the material. + GLTFString alphaMode; + // Specifies whether the material is double sided. + bool doubleSided; + // The normal map texture. + std::shared_ptr normalTexture; + // The emissive color of the material. + std::vector emissiveFactor; + }; + /*! * struct: SAsset * Metadata about the glTF asset. @@ -59,20 +96,6 @@ namespace libgltf GLTFString copyright; }; - /*! - * struct: SGlTFChildofRootProperty - */ - struct SGlTFChildofRootProperty : SGlTFProperty - { - SGlTFChildofRootProperty(); - - // Check valid - operator bool() const; - - // The user-defined name of this object. - GLTFString name; - }; - /*! * struct: SSampler * Texture sampler properties for filtering and wrapping modes. @@ -114,32 +137,16 @@ namespace libgltf }; /*! - * struct: SMaterial - * The material appearance of a primitive. + * struct: SExtras + * Application-specific data. */ - struct SMaterial : SGlTFChildofRootProperty + struct SExtras { - SMaterial(); + SExtras(); // Check valid operator bool() const; - // The alpha cutoff value of the material. - float alphaCutoff; - // The emissive map texture. - std::shared_ptr emissiveTexture; - // A set of parameter values that are used to define the metallic-roughness material model from Physically-Based Rendering (PBR) methodology. When not specified, all the default values of `pbrMetallicRoughness` apply. - std::shared_ptr pbrMetallicRoughness; - // The occlusion map texture. - std::shared_ptr occlusionTexture; - // The alpha rendering mode of the material. - GLTFString alphaMode; - // Specifies whether the material is double sided. - bool doubleSided; - // The normal map texture. - std::shared_ptr normalTexture; - // The emissive color of the material. - std::vector emissiveFactor; }; /*! @@ -281,16 +288,20 @@ namespace libgltf }; /*! - * struct: SExtras - * Application-specific data. + * struct: SMesh + * A set of primitives to be rendered. A node can contain one mesh. A node's transform places the mesh in the scene. */ - struct SExtras + struct SMesh : SGlTFChildofRootProperty { - SExtras(); + SMesh(); // Check valid operator bool() const; + // An array of primitives, each defining geometry to be rendered with a material. + std::vector> primitives; + // Array of weights to be applied to the Morph Targets. + std::vector weights; }; /*! @@ -528,23 +539,6 @@ namespace libgltf GLTFString uri; }; - /*! - * struct: SMesh - * A set of primitives to be rendered. A node can contain one mesh. A node's transform places the mesh in the scene. - */ - struct SMesh : SGlTFChildofRootProperty - { - SMesh(); - - // Check valid - operator bool() const; - - // An array of primitives, each defining geometry to be rendered with a material. - std::vector> primitives; - // Array of weights to be applied to the Morph Targets. - std::vector weights; - }; - /*! * struct: STexture * A texture and its sampler. diff --git a/source/libgltf/libgltf.cpp b/source/libgltf/libgltf.cpp index 73964bb..d2c1a51 100644 --- a/source/libgltf/libgltf.cpp +++ b/source/libgltf/libgltf.cpp @@ -16,30 +16,50 @@ namespace libgltf return true; } - SAsset::SAsset() + SGlTFChildofRootProperty::SGlTFChildofRootProperty() : SGlTFProperty() - , minVersion(GLTFTEXT("")) - , version(GLTFTEXT("")) - , generator(GLTFTEXT("")) - , copyright(GLTFTEXT("")) + , name(GLTFTEXT("")) { // } - SAsset::operator bool() const + SGlTFChildofRootProperty::operator bool() const { //TODO: return true; } - SGlTFChildofRootProperty::SGlTFChildofRootProperty() + SMaterial::SMaterial() + : SGlTFChildofRootProperty() + , alphaCutoff(0.500000f) + , emissiveTexture(nullptr) + , pbrMetallicRoughness(nullptr) + , occlusionTexture(nullptr) + , alphaMode(GLTFTEXT("OPAQUE")) + , doubleSided(false) + , normalTexture(nullptr) + , emissiveFactor({ 0.000000f, 0.000000f, 0.000000f }) + { + // + } + + SMaterial::operator bool() const + { + //TODO: + return true; + } + + SAsset::SAsset() : SGlTFProperty() - , name(GLTFTEXT("")) + , minVersion(GLTFTEXT("")) + , version(GLTFTEXT("")) + , generator(GLTFTEXT("")) + , copyright(GLTFTEXT("")) { // } - SGlTFChildofRootProperty::operator bool() const + SAsset::operator bool() const { //TODO: return true; @@ -76,21 +96,12 @@ namespace libgltf return true; } - SMaterial::SMaterial() - : SGlTFChildofRootProperty() - , alphaCutoff(0.500000f) - , emissiveTexture(nullptr) - , pbrMetallicRoughness(nullptr) - , occlusionTexture(nullptr) - , alphaMode(GLTFTEXT("OPAQUE")) - , doubleSided(false) - , normalTexture(nullptr) - , emissiveFactor({ 0.000000f, 0.000000f, 0.000000f }) + SExtras::SExtras() { // } - SMaterial::operator bool() const + SExtras::operator bool() const { //TODO: return true; @@ -210,12 +221,15 @@ namespace libgltf return true; } - SExtras::SExtras() + SMesh::SMesh() + : SGlTFChildofRootProperty() + , primitives() + , weights() { // } - SExtras::operator bool() const + SMesh::operator bool() const { //TODO: return true; @@ -407,20 +421,6 @@ namespace libgltf return true; } - SMesh::SMesh() - : SGlTFChildofRootProperty() - , primitives() - , weights() - { - // - } - - SMesh::operator bool() const - { - //TODO: - return true; - } - STexture::STexture() : SGlTFChildofRootProperty() , source(nullptr) diff --git a/source/libgltf/libgltfparser.cpp b/source/libgltf/libgltfparser.cpp index 583c2e9..c70f6d2 100644 --- a/source/libgltf/libgltfparser.cpp +++ b/source/libgltf/libgltfparser.cpp @@ -200,6 +200,115 @@ namespace libgltf return operator>> >(_vDatas, _JsonValue); } + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) + { + std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); + { + std::shared_ptr super_ptr = data_ptr; + if (!(super_ptr << _JsonValue)) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("alphaCutoff")) && _JsonValue[GLTFTEXT("alphaCutoff")].IsFloat()) + { + data_ptr->alphaCutoff = _JsonValue[GLTFTEXT("alphaCutoff")].GetFloat(); + } + if (_JsonValue.HasMember(GLTFTEXT("emissiveTexture")) && _JsonValue[GLTFTEXT("emissiveTexture")].IsObject()) + { + if (!(data_ptr->emissiveTexture << _JsonValue[GLTFTEXT("emissiveTexture")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("pbrMetallicRoughness")) && _JsonValue[GLTFTEXT("pbrMetallicRoughness")].IsObject()) + { + if (!(data_ptr->pbrMetallicRoughness << _JsonValue[GLTFTEXT("pbrMetallicRoughness")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("occlusionTexture")) && _JsonValue[GLTFTEXT("occlusionTexture")].IsObject()) + { + if (!(data_ptr->occlusionTexture << _JsonValue[GLTFTEXT("occlusionTexture")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("alphaMode")) && _JsonValue[GLTFTEXT("alphaMode")].IsString()) + { + data_ptr->alphaMode = _JsonValue[GLTFTEXT("alphaMode")].GetString(); + } + if (_JsonValue.HasMember(GLTFTEXT("doubleSided")) && _JsonValue[GLTFTEXT("doubleSided")].IsBool()) + { + data_ptr->doubleSided = _JsonValue[GLTFTEXT("doubleSided")].GetBool(); + } + if (_JsonValue.HasMember(GLTFTEXT("normalTexture")) && _JsonValue[GLTFTEXT("normalTexture")].IsObject()) + { + if (!(data_ptr->normalTexture << _JsonValue[GLTFTEXT("normalTexture")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("emissiveFactor")) && _JsonValue[GLTFTEXT("emissiveFactor")].IsArray()) + { + if (!(data_ptr->emissiveFactor << _JsonValue[GLTFTEXT("emissiveFactor")])) return false; + } + _pData = data_ptr; + return true; + } + + bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue) + { + if (!_pData || !g_json_doc_ptr) return false; + _JsonValue.SetObject(); + { + const std::shared_ptr super_ptr = _pData; + if (!(super_ptr >> _JsonValue)) return false; + } + { + GLTFCharValue json_value; + if (!(_pData->alphaCutoff >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("alphaCutoff"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!!_pData->emissiveTexture) + { + GLTFCharValue json_value; + if (!(_pData->emissiveTexture >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("emissiveTexture"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!!_pData->pbrMetallicRoughness) + { + GLTFCharValue json_value; + if (!(_pData->pbrMetallicRoughness >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("pbrMetallicRoughness"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!!_pData->occlusionTexture) + { + GLTFCharValue json_value; + if (!(_pData->occlusionTexture >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("occlusionTexture"), json_value, g_json_doc_ptr->GetAllocator()); + } + { + GLTFCharValue json_value; + if (!(_pData->alphaMode >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("alphaMode"), json_value, g_json_doc_ptr->GetAllocator()); + } + { + GLTFCharValue json_value; + if (!(_pData->doubleSided >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("doubleSided"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!!_pData->normalTexture) + { + GLTFCharValue json_value; + if (!(_pData->normalTexture >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("normalTexture"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!_pData->emissiveFactor.empty()) + { + GLTFCharValue json_value; + if (!(_pData->emissiveFactor >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("emissiveFactor"), json_value, g_json_doc_ptr->GetAllocator()); + } + return true; + } + + bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue) + { + return operator<< >(_vDatas, _JsonValue); + } + + bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue) + { + return operator>> >(_vDatas, _JsonValue); + } + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) { std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); @@ -438,113 +547,28 @@ namespace libgltf return operator>> >(_vDatas, _JsonValue); } - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) { - std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); - { - std::shared_ptr super_ptr = data_ptr; - if (!(super_ptr << _JsonValue)) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("alphaCutoff")) && _JsonValue[GLTFTEXT("alphaCutoff")].IsFloat()) - { - data_ptr->alphaCutoff = _JsonValue[GLTFTEXT("alphaCutoff")].GetFloat(); - } - if (_JsonValue.HasMember(GLTFTEXT("emissiveTexture")) && _JsonValue[GLTFTEXT("emissiveTexture")].IsObject()) - { - if (!(data_ptr->emissiveTexture << _JsonValue[GLTFTEXT("emissiveTexture")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("pbrMetallicRoughness")) && _JsonValue[GLTFTEXT("pbrMetallicRoughness")].IsObject()) - { - if (!(data_ptr->pbrMetallicRoughness << _JsonValue[GLTFTEXT("pbrMetallicRoughness")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("occlusionTexture")) && _JsonValue[GLTFTEXT("occlusionTexture")].IsObject()) - { - if (!(data_ptr->occlusionTexture << _JsonValue[GLTFTEXT("occlusionTexture")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("alphaMode")) && _JsonValue[GLTFTEXT("alphaMode")].IsString()) - { - data_ptr->alphaMode = _JsonValue[GLTFTEXT("alphaMode")].GetString(); - } - if (_JsonValue.HasMember(GLTFTEXT("doubleSided")) && _JsonValue[GLTFTEXT("doubleSided")].IsBool()) - { - data_ptr->doubleSided = _JsonValue[GLTFTEXT("doubleSided")].GetBool(); - } - if (_JsonValue.HasMember(GLTFTEXT("normalTexture")) && _JsonValue[GLTFTEXT("normalTexture")].IsObject()) - { - if (!(data_ptr->normalTexture << _JsonValue[GLTFTEXT("normalTexture")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("emissiveFactor")) && _JsonValue[GLTFTEXT("emissiveFactor")].IsArray()) - { - if (!(data_ptr->emissiveFactor << _JsonValue[GLTFTEXT("emissiveFactor")])) return false; - } + std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); _pData = data_ptr; return true; } - bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue) + bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue) { if (!_pData || !g_json_doc_ptr) return false; _JsonValue.SetObject(); - { - const std::shared_ptr super_ptr = _pData; - if (!(super_ptr >> _JsonValue)) return false; - } - { - GLTFCharValue json_value; - if (!(_pData->alphaCutoff >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("alphaCutoff"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!!_pData->emissiveTexture) - { - GLTFCharValue json_value; - if (!(_pData->emissiveTexture >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("emissiveTexture"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!!_pData->pbrMetallicRoughness) - { - GLTFCharValue json_value; - if (!(_pData->pbrMetallicRoughness >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("pbrMetallicRoughness"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!!_pData->occlusionTexture) - { - GLTFCharValue json_value; - if (!(_pData->occlusionTexture >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("occlusionTexture"), json_value, g_json_doc_ptr->GetAllocator()); - } - { - GLTFCharValue json_value; - if (!(_pData->alphaMode >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("alphaMode"), json_value, g_json_doc_ptr->GetAllocator()); - } - { - GLTFCharValue json_value; - if (!(_pData->doubleSided >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("doubleSided"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!!_pData->normalTexture) - { - GLTFCharValue json_value; - if (!(_pData->normalTexture >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("normalTexture"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!_pData->emissiveFactor.empty()) - { - GLTFCharValue json_value; - if (!(_pData->emissiveFactor >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("emissiveFactor"), json_value, g_json_doc_ptr->GetAllocator()); - } return true; } - bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue) + bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue) { - return operator<< >(_vDatas, _JsonValue); + return operator<< >(_vDatas, _JsonValue); } - bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue) + bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue) { - return operator>> >(_vDatas, _JsonValue); + return operator>> >(_vDatas, _JsonValue); } bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) @@ -919,28 +943,56 @@ namespace libgltf return operator>> >(_vDatas, _JsonValue); } - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) { - std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); + std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); + { + std::shared_ptr super_ptr = data_ptr; + if (!(super_ptr << _JsonValue)) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("primitives")) && _JsonValue[GLTFTEXT("primitives")].IsArray()) + { + if (!(data_ptr->primitives << _JsonValue[GLTFTEXT("primitives")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("weights")) && _JsonValue[GLTFTEXT("weights")].IsArray()) + { + if (!(data_ptr->weights << _JsonValue[GLTFTEXT("weights")])) return false; + } _pData = data_ptr; return true; } - bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue) + bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue) { if (!_pData || !g_json_doc_ptr) return false; _JsonValue.SetObject(); + { + const std::shared_ptr super_ptr = _pData; + if (!(super_ptr >> _JsonValue)) return false; + } + if (!_pData->primitives.empty()) + { + GLTFCharValue json_value; + if (!(_pData->primitives >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("primitives"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!_pData->weights.empty()) + { + GLTFCharValue json_value; + if (!(_pData->weights >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("weights"), json_value, g_json_doc_ptr->GetAllocator()); + } return true; } - bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue) + bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue) { - return operator<< >(_vDatas, _JsonValue); + return operator<< >(_vDatas, _JsonValue); } - bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue) + bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue) { - return operator>> >(_vDatas, _JsonValue); + return operator>> >(_vDatas, _JsonValue); } bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) @@ -1684,58 +1736,6 @@ namespace libgltf return operator>> >(_vDatas, _JsonValue); } - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) - { - std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); - { - std::shared_ptr super_ptr = data_ptr; - if (!(super_ptr << _JsonValue)) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("primitives")) && _JsonValue[GLTFTEXT("primitives")].IsArray()) - { - if (!(data_ptr->primitives << _JsonValue[GLTFTEXT("primitives")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("weights")) && _JsonValue[GLTFTEXT("weights")].IsArray()) - { - if (!(data_ptr->weights << _JsonValue[GLTFTEXT("weights")])) return false; - } - _pData = data_ptr; - return true; - } - - bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue) - { - if (!_pData || !g_json_doc_ptr) return false; - _JsonValue.SetObject(); - { - const std::shared_ptr super_ptr = _pData; - if (!(super_ptr >> _JsonValue)) return false; - } - if (!_pData->primitives.empty()) - { - GLTFCharValue json_value; - if (!(_pData->primitives >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("primitives"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!_pData->weights.empty()) - { - GLTFCharValue json_value; - if (!(_pData->weights >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("weights"), json_value, g_json_doc_ptr->GetAllocator()); - } - return true; - } - - bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue) - { - return operator<< >(_vDatas, _JsonValue); - } - - bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue) - { - return operator>> >(_vDatas, _JsonValue); - } - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) { std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); diff --git a/source/libgltf/libgltfparser.h b/source/libgltf/libgltfparser.h index f157bc2..f873f34 100644 --- a/source/libgltf/libgltfparser.h +++ b/source/libgltf/libgltfparser.h @@ -12,6 +12,11 @@ namespace libgltf bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); + bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); + bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); + bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); @@ -32,10 +37,10 @@ namespace libgltf bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); - bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); - bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); - bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); + bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); + bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); + bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); @@ -72,10 +77,10 @@ namespace libgltf bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); - bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); - bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); - bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); + bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); + bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); + bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); @@ -137,11 +142,6 @@ namespace libgltf bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); - bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); - bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); - bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue); bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); diff --git a/source/libgltf/libgltfpch.h b/source/libgltf/libgltfpch.h index c0fd878..acadf5a 100644 --- a/source/libgltf/libgltfpch.h +++ b/source/libgltf/libgltfpch.h @@ -4,24 +4,16 @@ #include #include -#if defined(LIBGLTF_PLATFORM_WINDOWS) -# if defined(UNICODE) -# define GLTFTEXT(t) L##t -# else -# define GLTFTEXT(t) t -# endif +#if defined(LIBGLTF_USE_WCHAR) +# define GLTFTEXT(t) L##t #else -# define GLTFTEXT(t) t +# define GLTFTEXT(t) t #endif namespace libgltf { -#if defined(LIBGLTF_PLATFORM_WINDOWS) -# if defined(UNICODE) +#if defined(LIBGLTF_USE_WCHAR) typedef rapidjson::UTF16<> GLTFCharType; -# else - typedef rapidjson::UTF8<> GLTFCharType; -# endif #else typedef rapidjson::UTF8<> GLTFCharType; #endif @@ -36,3 +28,4 @@ namespace libgltf typedef rapidjson::GenericObject GLTFCharConstObject; typedef rapidjson::GenericObject GLTFCharObject; } + diff --git a/source/runtest/runtest.cpp b/source/runtest/runtest.cpp index b0d7824..c4b794f 100644 --- a/source/runtest/runtest.cpp +++ b/source/runtest/runtest.cpp @@ -38,7 +38,7 @@ int main(int _iArgc, char* _pcArgv[]) return error_code; } -#if defined(LIBGLTF_PLATFORM_WINDOWS) +#if defined(LIBGLTF_USE_WCHAR) std::wstringstream input_content; { std::wifstream input_file(input_file_path.c_str(), std::ios::in | std::ios::binary); @@ -69,7 +69,7 @@ int main(int _iArgc, char* _pcArgv[]) return error_code; } -#if defined(LIBGLTF_PLATFORM_WINDOWS) +#if defined(LIBGLTF_USE_WCHAR) std::wstring output_content; #else std::string output_content; @@ -87,3 +87,4 @@ int main(int _iArgc, char* _pcArgv[]) return 0; } + diff --git a/tools/jsonschematoc11/jsonschematoc11.py b/tools/jsonschematoc11/jsonschematoc11.py index 1bd3992..3b12b5a 100644 --- a/tools/jsonschematoc11/jsonschematoc11.py +++ b/tools/jsonschematoc11/jsonschematoc11.py @@ -86,16 +86,10 @@ def generate(self, codeFileName, outputHeaderPath=None, outputSourcePath=None, n header_file.write(u'{\n') begin_space = u' ' - header_file.write(u'#if defined(LIBGLTF_PLATFORM_WINDOWS)\n') - header_file.write(u'# if defined(UNICODE)\n') + header_file.write(u'#if defined(LIBGLTF_USE_WCHAR)\n') header_file.write(u'%s%s\n' % (begin_space, u'typedef std::wstring GLTFString;')) - header_file.write(u'# else\n') - header_file.write(u'%s%s\n' % (begin_space, u'typedef std::string GLTFString;')) - header_file.write(u'# endif\n') - header_file.write(u'#elif defined(LIBGLTF_PLATFORM_LINUX) || defined(LIBGLTF_PLATFORM_MACOS) || defined(PLATFORM_ANDROID) || defined(PLATFORM_IOS)\n') - header_file.write(u'%s%s\n' % (begin_space, u'typedef std::string GLTFString;')) header_file.write(u'#else\n') - header_file.write(u'#error Sorry, not support your platform.\n') + header_file.write(u'%s%s\n' % (begin_space, u'typedef std::string GLTFString;')) header_file.write(u'#endif\n') header_file.write(u'\n') @@ -430,3 +424,4 @@ def JSONSchemaToC11(argv): else: logger.info(u'Success') exit(error_code) +