diff --git a/.appveyor.yml b/.appveyor.yml index 5e49a40..a94b21c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -36,6 +36,7 @@ install: - git submodule update --init before_build: +- cd tools/batch/ && update_parser_by_scheme.bat && cd ../../ - mkdir build - cd build - if "%TARGET_VSENV%" equ "VS14_WIN32" cmake -G "Visual Studio 14 2015" -D CMAKE_CONFIGURATION_TYPES=%CONFIGURATION% -D CMAKE_CXX_COMPILER_ID=MSVC_14 ../ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0826739..04eb20e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,6 @@ variables: GIT_SUBMODULE_STRATEGY: "recursive" + ANDROID_NDK: "~/develop/android-ndk-r18b" before_script: - git lfs fetch @@ -10,60 +11,54 @@ after_script: stages: - check - - test + - build checked_by_cppcheck: stage: check script: - - echo check + - 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../' - 'cppcheck . --enable=warning,style,performance,portability --xml-version=2 --error-exitcode=1 -i external/ -i build/ -i tools/' tags: + - linux + - python - cppcheck -test_win32: - stage: test +compile_windows: + stage: build script: + - 'cd tools/batch/ && python .\..\..\tools\jsonschematoc11 glTF_2.0_schema.ini && cd ../../' - 'call "%VS140COMNTOOLS%VsDevCmd.bat"' - 'if exist build rmdir /s /q build' - 'if exist output rmdir /s /q output' - - 'mkdir build' - - 'cd build' - - 'cmake -G "Visual Studio 14 2015" ../' + - 'mkdir build && cd build' + - 'mkdir win32 && cd win32' + - 'cmake -G "Visual Studio 14 2015" -DLIBGLTF_WITH_UNICODE=TRUE ../../' - 'msbuild libgltf.sln /t:Rebuild /p:Configuration="Debug" /p:Platform="Win32"' - - '..\output\bin\win32\Debug\runtest.exe ..\resource\example-2.0\glTF-BarramundiFish.gltf' - - '..\output\bin\win32\Debug\runtest.exe ..\resource\example-2.0\glTF-Draco-BarramundiFish.gltf' - - '..\output\bin\win32\Debug\runtest.exe ..\resource\example-2.0\glTF-pbrSpecularGlossinessBarramundiFish.gltf' + - '..\..\output\bin\win32\Debug\runtest.exe ..\..\resource\example-2.0\glTF-BarramundiFish.gltf' + - '..\..\output\bin\win32\Debug\runtest.exe ..\..\resource\example-2.0\glTF-Draco-BarramundiFish.gltf' + - '..\..\output\bin\win32\Debug\runtest.exe ..\..\resource\example-2.0\glTF-pbrSpecularGlossinessBarramundiFish.gltf' - 'cd ../' - tags: - - win32 - - cmake - - vs2015 - -test_win64: - stage: test - script: - - 'call "%VS140COMNTOOLS%VsDevCmd.bat"' - - 'if exist build rmdir /s /q build' - - 'if exist output rmdir /s /q output' - - 'mkdir build' - - 'cd build' - - 'cmake -G "Visual Studio 14 2015 Win64" ../' + - 'mkdir win64 && cd win64' + - 'cmake -G "Visual Studio 14 2015 Win64" -DLIBGLTF_WITH_UNICODE=TRUE ../../' - 'msbuild libgltf.sln /t:Rebuild /p:Configuration="Debug" /p:Platform="x64"' - - '..\output\bin\win64\Debug\runtest.exe ..\resource\example-2.0\glTF-BarramundiFish.gltf' - - '..\output\bin\win64\Debug\runtest.exe ..\resource\example-2.0\glTF-Draco-BarramundiFish.gltf' - - '..\output\bin\win64\Debug\runtest.exe ..\resource\example-2.0\glTF-pbrSpecularGlossinessBarramundiFish.gltf' + - '..\..\output\bin\win64\Debug\runtest.exe ..\..\resource\example-2.0\glTF-BarramundiFish.gltf' + - '..\..\output\bin\win64\Debug\runtest.exe ..\..\resource\example-2.0\glTF-Draco-BarramundiFish.gltf' + - '..\..\output\bin\win64\Debug\runtest.exe ..\..\resource\example-2.0\glTF-pbrSpecularGlossinessBarramundiFish.gltf' + - 'cd ../' - 'cd ../' tags: + - win32 - win64 + - python - cmake - vs2015 -test_linux: - stage: test +compile_linux: + stage: build script: - - 'mkdir build' - - 'cd build' - - 'cmake -DCMAKE_BUILD_TYPE=Debug -DLIBGLTF_BUILD_GCOV=TRUE -G "Unix Makefiles" ../' + - 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../' + - 'mkdir build && cd build' + - 'cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DLIBGLTF_BUILD_GCOV=TRUE ../' - 'make' - 'valgrind --leak-check=full --show-leak-kinds=all ./../output/bin/linux/runtest --coveralls' - 'valgrind --leak-check=full --show-leak-kinds=all ./../output/bin/linux/runtest --coveralls ../resource/nothing.gltf' @@ -80,17 +75,17 @@ test_linux: - 'cd ../' tags: - linux + - python - cmake - make - valgrind - - gcc - gcovr -test_macos: - stage: test +compile_macos: + stage: build script: - - 'mkdir build' - - 'cd build' + - 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../' + - 'mkdir build && cd build' - 'cmake -G "Unix Makefiles" ../' - 'make' - './../output/bin/macos/runtest ../resource/example-2.0/glTF-BarramundiFish.gltf' @@ -99,6 +94,65 @@ test_macos: - 'cd ../' tags: - macos + - python - cmake - make - gcc + +compile_android: + stage: build + script: + - 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../' + - 'mkdir build && cd build' + - 'mkdir armeabi-v7a && cd armeabi-v7a' + - 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../' + - 'ninja' + - 'cd ../' + - 'mkdir armeabi-v7a-with-neon && cd armeabi-v7a-with-neon' + - 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_ARM_NEON=ON -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../' + - 'ninja' + - 'cd ../' + - 'mkdir arm64-v8a && cd arm64-v8a' + - 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../' + - 'ninja' + - 'cd ../' + - 'mkdir x86 && cd x86' + - 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86 -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../' + - 'ninja' + - 'cd ../' + - 'mkdir x86_64 && cd x86_64' + - 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86_64 -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../' + - 'ninja' + - 'cd ../' + - 'cd ../' + tags: + - linux + - android + - python + - cmake + - ninja + +compile_ios: + stage: build + script: + - 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../' + - 'mkdir build && cd build' + - 'mkdir os && cd os' + - 'cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/toolchain/iOS.cmake -DIOS_PLATFORM=OS -DLIBGLTF_PLATFORM_IOS=TRUE -DLIBGLTF_WITH_UNICODE=TRUE -DLIBGLTF_USING_CHAR16=TRUE ../../' + - 'make libgltf' + - 'cd ../' + - 'mkdir simulator && cd simulator' + - 'cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/toolchain/iOS.cmake -DIOS_PLATFORM=SIMULATOR -DLIBGLTF_PLATFORM_IOS=TRUE -DLIBGLTF_WITH_UNICODE=TRUE -DLIBGLTF_USING_CHAR16=TRUE ../../' + - 'make libgltf' + - 'cd ../' + - 'mkdir watchos && cd watchos' + - 'cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/toolchain/iOS.cmake -DIOS_PLATFORM=WATCHOS -DLIBGLTF_PLATFORM_IOS=TRUE -DLIBGLTF_WITH_UNICODE=TRUE -DLIBGLTF_USING_CHAR16=TRUE ../../' + - 'make libgltf' + - 'cd ../' + - 'cd ../' + tags: + - macos + - ios + - python + - cmake + - make diff --git a/.gitmodules b/.gitmodules index ca4f063..a549d5b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "external/glTF"] path = external/glTF url = https://github.com/KhronosGroup/glTF.git +[submodule "external/ios-cmake"] + path = external/ios-cmake + url = https://github.com/Yangqing/ios-cmake.git diff --git a/.travis.yml b/.travis.yml index b90a97d..0b91ea3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ install: script: - set -e +- cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../ - mkdir ./build && cd ./build - if [ $RUN_COVERALLS == true ]; then cmake -D LIBGLTF_COVERAGE_GCOV=TRUE ./../; else cmake ./../; fi - make diff --git a/CHANGELOG.md b/CHANGELOG.md index 775c741..f1a76f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 0.1.4 (2018/11/5) + +* Support Android and iOS platforms + ## 0.0.1 (2017/12/5) ### Changes diff --git a/CMakeLists.txt b/CMakeLists.txt index 672fe55..42dce1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ set(CMAKE_DEBUG_POSTFIX "d") set(LIBGLTF_PLATFORM_WINDOWS FALSE) set(LIBGLTF_PLATFORM_LINUX FALSE) set(LIBGLTF_PLATFORM_MACOS FALSE) +set(LIBGLTF_PLATFORM_ANDROID FALSE) +option(LIBGLTF_PLATFORM_IOS OFF) option(LIBGLTF_COVERAGE_GCOV "Coverage gcov (debug, Linux builds only)" OFF) option(LIBGLTF_WITH_UNICODE "Build with UNICODE" OFF) @@ -46,7 +48,17 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -lgcov") add_definitions(-DBUILD_COVERALLS) endif() -elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(LIBGLTF_PLATFORM_ANDROID TRUE) + add_definitions(-DLIBGLTF_PLATFORM_LINUX) + set(DYNAMIC_LIBRARY_EXTENSION ".so") + set(STATIC_LIBRARY_EXTENSION ".a") + set(PLATFORM_NAME "android") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wconversion -Wno-long-long -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic") + set(CMAKE_STATIC_LIBRARY_PREFIX "") + set(CMAKE_SHARED_LIBRARY_PREFIX "") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND (NOT ${LIBGLTF_PLATFORM_IOS})) set(LIBGLTF_PLATFORM_MACOS TRUE) add_definitions(-DLIBGLTF_PLATFORM_MACOS) set(DYNAMIC_LIBRARY_EXTENSION ".dylib") @@ -56,9 +68,19 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic ${CMAKE_CXX_FLAGS}") set(CMAKE_STATIC_LIBRARY_PREFIX "") set(CMAKE_SHARED_LIBRARY_PREFIX "") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ${LIBGLTF_PLATFORM_IOS}) + set(LIBGLTF_PLATFORM_IOS TRUE) + add_definitions(-DLIBGLTF_PLATFORM_IOS) + set(DYNAMIC_LIBRARY_EXTENSION ".dylib") + set(STATIC_LIBRARY_EXTENSION ".a") + set(PLATFORM_NAME "ios") + set(CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Wconversion -Wno-long-long -pedantic ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic ${CMAKE_CXX_FLAGS}") + set(CMAKE_STATIC_LIBRARY_PREFIX "") + set(CMAKE_SHARED_LIBRARY_PREFIX "") endif() -if((NOT ${LIBGLTF_PLATFORM_WINDOWS}) AND (NOT ${LIBGLTF_PLATFORM_LINUX}) AND (NOT ${LIBGLTF_PLATFORM_MACOS})) +if((NOT ${LIBGLTF_PLATFORM_WINDOWS}) AND (NOT ${LIBGLTF_PLATFORM_LINUX}) AND (NOT ${LIBGLTF_PLATFORM_ANDROID}) AND (NOT ${LIBGLTF_PLATFORM_MACOS}) AND (NOT ${LIBGLTF_PLATFORM_IOS})) message(FATAL_ERROR "Sorry, don't support your system ${CMAKE_SYSTEM_NAME}!") endif() @@ -106,4 +128,3 @@ add_subdirectory(source) add_subdirectory(tools) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT libgltf) - diff --git a/docs/index.md b/docs/index.md index 2fd2dce..7a31849 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,9 +1,22 @@ # About -This project can automatically generate C++11 code by glTF JSON schema. Then you can compile the generated C++11 code to parser the glTF to a struct `SGlTF` or convert the struct `SGlTF` to JSON string. +This project can automatically generate C++11 code by glTF JSON schema. Then you can compile the generated C++11 code to parser the glTF string to a struct `SGlTF` or convert the struct `SGlTF` to JSON string. It was used in [glTFForUE4](https://github.com/code4game/glTFForUE4). +## Platforms + +### Desktop + +* Windows +* Linux +* MacOS + +### Mobile + +* Android (armeabi-v7a, armeabi-v7a-with-neon, arm64-v8a, x86 and x86_64) +* iOS (iOS, simulator and watchOS) + ## Donation [![Become a patreon](https://img.shields.io/badge/donation-become%20a%20patreon-ff69b4.svg?style=flat)](https://www.patreon.com/bePatron?u=7553208) diff --git a/docs/usage.md b/docs/usage.md index 15bb210..be2eb94 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -1,15 +1,28 @@ # Usage -Generate the `makefile` or `vs project` by [CMake]. +Generate the `makefile` or `ninja` or `vs project` by [CMake]. For now, just build to a static library - `libgltf.(lib/a/dylib)`. ## Advance +### Generate new code by the official glTF schema + > You can update the c++11 source code by `jsonschematoc11`. Generate the c++11 code: -1. Run `tools/batch/update_parser_by_scheme.bat` or `tools/batch/update_parser_by_scheme.sh` +1. Run `tools/batch/update_parser_by_scheme.bat` (Windows) or `tools/batch/update_parser_by_scheme.sh` (Unix/Linux/MacOS) +2. Build your version by [CMake], [Ninja] or [VisualStudio]. + +### String encode + +* default using utf8, char and std::string +* set LIBGLTF_WITH_UNICODE as TRUE in cmake command, if you want using unicode + * default using wchar_t and std::wstring + * set LIBGLTF_USING_CHAR16 as TRUE in cmake command, if you wnat using utf16, char16_t and std::u16string + * set LIBGLTF_USING_CHAR32 as TRUE in cmake command, if you want using utf32, char32_t and std::u32string [CMake]: https://cmake.org +[Ninja]: https://ninja-build.org +[VisualStudio]: https://visualstudio.microsoft.com diff --git a/external/ios-cmake b/external/ios-cmake new file mode 160000 index 0000000..8abaed6 --- /dev/null +++ b/external/ios-cmake @@ -0,0 +1 @@ +Subproject commit 8abaed637d56f1337d6e1d2c4026e25c1eade724 diff --git a/include/libgltf/libgltf.h b/include/libgltf/libgltf.h index aea638d..db84557 100644 --- a/include/libgltf/libgltf.h +++ b/include/libgltf/libgltf.h @@ -7,8 +7,8 @@ #include #define LIBGLTF_MAJOR_VERSION 0 -#define LIBGLTF_MINOR_VERSION 0 -#define LIBGLTF_PATCH_VERSION 0 +#define LIBGLTF_MINOR_VERSION 1 +#define LIBGLTF_PATCH_VERSION 4 #if defined(UNICODE) #if defined(USING_CHAR16) @@ -41,55 +41,12 @@ namespace libgltf SGlTFProperty(); // Check valid - virtual operator bool() const; + operator bool() const; std::shared_ptr extras; std::shared_ptr extensions; }; - /*! - * struct: SGlTFChildofRootProperty - */ - struct SGlTFChildofRootProperty : SGlTFProperty - { - SGlTFChildofRootProperty(); - - // Check valid - virtual 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 - virtual 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. @@ -99,7 +56,7 @@ namespace libgltf SAsset(); // Check valid - virtual operator bool() const; + operator bool() const; // The minimum glTF version that this asset targets. GLTFString minVersion; @@ -111,6 +68,20 @@ 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. @@ -120,7 +91,7 @@ namespace libgltf SSampler(); // Check valid - virtual operator bool() const; + operator bool() const; // s wrapping mode. int32_t wrapS; @@ -141,7 +112,7 @@ namespace libgltf SAnimationSampler(); // Check valid - virtual operator bool() const; + operator bool() const; // The index of an accessor containing keyframe input values, e.g., time. std::shared_ptr input; @@ -152,15 +123,32 @@ namespace libgltf }; /*! - * struct: SExtras - * Application-specific data. + * struct: SMaterial + * The material appearance of a primitive. */ - struct SExtras : SObject + struct SMaterial : SGlTFChildofRootProperty { - SExtras(); + SMaterial(); // Check valid - virtual operator bool() const; + 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; }; /*! @@ -172,7 +160,7 @@ namespace libgltf SScene(); // Check valid - virtual operator bool() const; + operator bool() const; // The indices of each root node. std::vector> nodes; @@ -187,7 +175,7 @@ namespace libgltf SCameraPerspective(); // Check valid - virtual operator bool() const; + operator bool() const; // The floating-point aspect ratio of the field of view. float aspectRatio; @@ -208,7 +196,7 @@ namespace libgltf SBufferView(); // Check valid - virtual operator bool() const; + operator bool() const; // The length of the bufferView in bytes. int32_t byteLength; @@ -231,7 +219,7 @@ namespace libgltf STextureInfo(); // Check valid - virtual operator bool() const; + operator bool() const; // The index of the texture. std::shared_ptr index; @@ -247,7 +235,7 @@ namespace libgltf SMaterialNormalTextureInfo(); // Check valid - virtual operator bool() const; + operator bool() const; // The scalar multiplier applied to each normal vector of the normal texture. float scale; @@ -261,7 +249,7 @@ namespace libgltf SMaterialOcclusionTextureInfo(); // Check valid - virtual operator bool() const; + operator bool() const; // A scalar multiplier controlling the amount of occlusion applied. float strength; @@ -276,7 +264,7 @@ namespace libgltf SAccessorSparseValues(); // Check valid - virtual operator bool() const; + operator bool() const; // The index of the bufferView with sparse values. Referenced bufferView can't have ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target. std::shared_ptr bufferView; @@ -293,7 +281,7 @@ namespace libgltf SAnimationChannelTarget(); // Check valid - virtual operator bool() const; + operator bool() const; // The index of the node to target. std::shared_ptr node; @@ -302,20 +290,15 @@ namespace libgltf }; /*! - * 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 + * Application-specific data. */ - struct SMesh : SGlTFChildofRootProperty + struct SExtras : SObject { - SMesh(); + SExtras(); // Check valid - virtual 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; + operator bool() const; }; /*! @@ -327,7 +310,7 @@ namespace libgltf SAccessorSparse(); // Check valid - virtual operator bool() const; + operator bool() const; // Number of entries stored in the sparse array. int32_t count; @@ -346,7 +329,7 @@ namespace libgltf SMeshPrimitive(); // Check valid - virtual operator bool() const; + operator bool() const; // The index of the accessor that contains the indices. std::shared_ptr indices; @@ -369,7 +352,7 @@ namespace libgltf SKHR_materials_pbrSpecularGlossinessglTFextension(); // Check valid - virtual operator bool() const; + operator bool() const; // The specular RGB color of the material. std::vector specularFactor; @@ -392,7 +375,7 @@ namespace libgltf SExtension(); // Check valid - virtual operator bool() const; + operator bool() const; // Manual code lines std::map> properties; @@ -407,7 +390,7 @@ namespace libgltf SAnimationChannel(); // Check valid - virtual operator bool() const; + operator bool() const; // The index of the node and TRS property to target. std::shared_ptr target; @@ -423,7 +406,7 @@ namespace libgltf SGlTFId(); // Check valid - virtual operator bool() const; + operator bool() const; operator int32_t() const; @@ -439,7 +422,7 @@ namespace libgltf SAccessorSparseIndices(); // Check valid - virtual operator bool() const; + operator bool() const; // The indices data type. int32_t componentType; @@ -458,7 +441,7 @@ namespace libgltf SNode(); // Check valid - virtual operator bool() const; + operator bool() const; // The node's non-uniform scale, given as the scaling factors along the x, y, and z axes. std::vector scale; @@ -489,7 +472,7 @@ namespace libgltf SAnimation(); // Check valid - virtual operator bool() const; + operator bool() const; // An array of channels, each of which targets an animation's sampler at a node's property. Different channels of the same animation can't have equal targets. std::vector> channels; @@ -506,7 +489,7 @@ namespace libgltf SSkin(); // Check valid - virtual operator bool() const; + operator bool() const; // Indices of skeleton nodes, used as joints in this skin. std::vector> joints; @@ -525,7 +508,7 @@ namespace libgltf SMaterialPBRMetallicRoughness(); // Check valid - virtual operator bool() const; + operator bool() const; // The roughness of the material. float roughnessFactor; @@ -547,7 +530,7 @@ namespace libgltf SKHR_draco_mesh_compressionextension(); // Check valid - virtual operator bool() const; + operator bool() const; // A dictionary object, where each key corresponds to an attribute and its unique attribute id stored in the compressed geometry. std::map> attributes; @@ -564,7 +547,7 @@ namespace libgltf SCamera(); // Check valid - virtual operator bool() const; + operator bool() const; // Specifies if the camera uses a perspective or orthographic projection. GLTFString type; @@ -583,7 +566,7 @@ namespace libgltf SImage(); // Check valid - virtual operator bool() const; + operator bool() const; // The image's MIME type. GLTFString mimeType; @@ -593,6 +576,23 @@ 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. @@ -602,7 +602,7 @@ namespace libgltf STexture(); // Check valid - virtual operator bool() const; + operator bool() const; // The index of the image used by this texture. std::shared_ptr source; @@ -619,7 +619,7 @@ namespace libgltf SCameraOrthographic(); // Check valid - virtual operator bool() const; + operator bool() const; // The floating-point horizontal magnification of the view. Must not be zero. float xmag; @@ -640,7 +640,7 @@ namespace libgltf SBuffer(); // Check valid - virtual operator bool() const; + operator bool() const; // The length of the buffer in bytes. int32_t byteLength; @@ -657,7 +657,7 @@ namespace libgltf SAccessor(); // Check valid - virtual operator bool() const; + operator bool() const; // The number of attributes referenced by this accessor. int32_t count; @@ -688,7 +688,7 @@ namespace libgltf SGlTF(); // Check valid - virtual operator bool() const; + operator bool() const; // An array of textures. std::vector> textures; diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index f11eb6f..fbe9401 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,2 +1,5 @@ add_subdirectory(libgltf) -add_subdirectory(runtest) + +if (${LIBGLTF_PLATFORM_WINDOWS} OR ${LIBGLTF_PLATFORM_LINUX} OR ${LIBGLTF_PLATFORM_MACOS}) + add_subdirectory(runtest) +endif() diff --git a/source/libgltf/CMakeLists.txt b/source/libgltf/CMakeLists.txt index 5ffb2bc..8168c0c 100644 --- a/source/libgltf/CMakeLists.txt +++ b/source/libgltf/CMakeLists.txt @@ -31,6 +31,21 @@ set(SOURCE_FILE_LIST source_group("header" FILES ${HEADER_FILE_LIST}) source_group("source" FILES ${SOURCE_FILE_LIST}) +if(${LIBGLTF_PLATFORM_ANDROID}) + set(ANDROID_ABI_PATH ${ANDROID_ABI}) + if(${ANDROID_ARM_NEON}) + set(ANDROID_ABI_PATH "${ANDROID_ABI}-with-neon") + endif() + string(TOLOWER ${ANDROID_ABI_PATH} ANDROID_ABI_PATH) + set(OUT_BIN_PATH "${OUT_BIN_PATH}/${ANDROID_ABI_PATH}") + set(OUT_LIB_PATH "${OUT_LIB_PATH}/${ANDROID_ABI_PATH}") +elseif(${LIBGLTF_PLATFORM_IOS}) + set(IOS_PLATFORM_PATH ${IOS_PLATFORM}) + string(TOLOWER ${IOS_PLATFORM_PATH} IOS_PLATFORM_PATH) + set(OUT_BIN_PATH "${OUT_BIN_PATH}/${IOS_PLATFORM_PATH}") + set(OUT_LIB_PATH "${OUT_LIB_PATH}/${IOS_PLATFORM_PATH}") +endif() + set(RUNTIME_OUTPUT_PATH ${OUT_BIN_PATH}) set(LIBRARY_OUTPUT_PATH ${OUT_LIB_PATH}) diff --git a/source/libgltf/libgltf.cpp b/source/libgltf/libgltf.cpp index d12188d..fdddb7a 100644 --- a/source/libgltf/libgltf.cpp +++ b/source/libgltf/libgltf.cpp @@ -23,50 +23,30 @@ namespace libgltf return true; } - SGlTFChildofRootProperty::SGlTFChildofRootProperty() + SAsset::SAsset() : SGlTFProperty() - , name(GLTFTEXT("")) - { - // - } - - SGlTFChildofRootProperty::operator bool() const - { - //TODO: - 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 }) + , minVersion(GLTFTEXT("")) + , version(GLTFTEXT("")) + , generator(GLTFTEXT("")) + , copyright(GLTFTEXT("")) { // } - SMaterial::operator bool() const + SAsset::operator bool() const { //TODO: 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; @@ -103,13 +83,21 @@ namespace libgltf return true; } - SExtras::SExtras() - : SObject() + 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::operator bool() const + SMaterial::operator bool() const { //TODO: return true; @@ -229,15 +217,13 @@ namespace libgltf return true; } - SMesh::SMesh() - : SGlTFChildofRootProperty() - , primitives() - , weights() + SExtras::SExtras() + : SObject() { // } - SMesh::operator bool() const + SExtras::operator bool() const { //TODO: return true; @@ -464,6 +450,20 @@ 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 374b4f7..03a07bc 100644 --- a/source/libgltf/libgltfparser.cpp +++ b/source/libgltf/libgltfparser.cpp @@ -217,128 +217,6 @@ namespace libgltf return operator>> >(_vDatas, _JsonValue); } - bool operator<<(SMaterial& _rData, const GLTFCharValue& _JsonValue) - { - { - SGlTFChildofRootProperty& super_ptr = _rData; - if (!(super_ptr << _JsonValue)) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("alphaCutoff")) && _JsonValue[GLTFTEXT("alphaCutoff")].IsFloat()) - { - _rData.alphaCutoff = _JsonValue[GLTFTEXT("alphaCutoff")].GetFloat(); - } - if (_JsonValue.HasMember(GLTFTEXT("emissiveTexture")) && _JsonValue[GLTFTEXT("emissiveTexture")].IsObject()) - { - if (!(_rData.emissiveTexture << _JsonValue[GLTFTEXT("emissiveTexture")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("pbrMetallicRoughness")) && _JsonValue[GLTFTEXT("pbrMetallicRoughness")].IsObject()) - { - if (!(_rData.pbrMetallicRoughness << _JsonValue[GLTFTEXT("pbrMetallicRoughness")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("occlusionTexture")) && _JsonValue[GLTFTEXT("occlusionTexture")].IsObject()) - { - if (!(_rData.occlusionTexture << _JsonValue[GLTFTEXT("occlusionTexture")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("alphaMode")) && _JsonValue[GLTFTEXT("alphaMode")].IsString()) - { - _rData.alphaMode = _JsonValue[GLTFTEXT("alphaMode")].GetString(); - } - if (_JsonValue.HasMember(GLTFTEXT("doubleSided")) && _JsonValue[GLTFTEXT("doubleSided")].IsBool()) - { - _rData.doubleSided = _JsonValue[GLTFTEXT("doubleSided")].GetBool(); - } - if (_JsonValue.HasMember(GLTFTEXT("normalTexture")) && _JsonValue[GLTFTEXT("normalTexture")].IsObject()) - { - if (!(_rData.normalTexture << _JsonValue[GLTFTEXT("normalTexture")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("emissiveFactor")) && _JsonValue[GLTFTEXT("emissiveFactor")].IsArray()) - { - if (!(_rData.emissiveFactor << _JsonValue[GLTFTEXT("emissiveFactor")])) return false; - } - _rData.schemaType = GLTFTEXT("material.schema.json"); - return true; - } - - bool operator>>(const SMaterial& _rData, GLTFCharValue& _JsonValue) - { - if (!g_json_doc_ptr) return false; - _JsonValue.SetObject(); - { - const SGlTFChildofRootProperty& super_ptr = _rData; - if (!(super_ptr >> _JsonValue)) return false; - } - { - GLTFCharValue json_value; - if (!(_rData.alphaCutoff >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("alphaCutoff"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!!_rData.emissiveTexture) - { - GLTFCharValue json_value; - if (!(_rData.emissiveTexture >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("emissiveTexture"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!!_rData.pbrMetallicRoughness) - { - GLTFCharValue json_value; - if (!(_rData.pbrMetallicRoughness >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("pbrMetallicRoughness"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!!_rData.occlusionTexture) - { - GLTFCharValue json_value; - if (!(_rData.occlusionTexture >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("occlusionTexture"), json_value, g_json_doc_ptr->GetAllocator()); - } - { - GLTFCharValue json_value; - if (!(_rData.alphaMode >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("alphaMode"), json_value, g_json_doc_ptr->GetAllocator()); - } - { - GLTFCharValue json_value; - if (!(_rData.doubleSided >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("doubleSided"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!!_rData.normalTexture) - { - GLTFCharValue json_value; - if (!(_rData.normalTexture >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("normalTexture"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!_rData.emissiveFactor.empty()) - { - GLTFCharValue json_value; - if (!(_rData.emissiveFactor >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("emissiveFactor"), json_value, g_json_doc_ptr->GetAllocator()); - } - return true; - } - - bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) - { - std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); - if (!(*data_ptr << _JsonValue)) return false; - _pData = data_ptr; - return true; - } - - bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue) - { - if (!_pData) return false; - return (*_pData >> _JsonValue); - } - - 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<<(SAsset& _rData, const GLTFCharValue& _JsonValue) { { @@ -629,41 +507,126 @@ namespace libgltf return operator>> >(_vDatas, _JsonValue); } - bool operator<<(SExtras& _rData, const GLTFCharValue& _JsonValue) + bool operator<<(SMaterial& _rData, const GLTFCharValue& _JsonValue) { - _rData.schemaType = GLTFTEXT("extras.schema.json"); + { + SGlTFChildofRootProperty& super_ptr = _rData; + if (!(super_ptr << _JsonValue)) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("alphaCutoff")) && _JsonValue[GLTFTEXT("alphaCutoff")].IsFloat()) + { + _rData.alphaCutoff = _JsonValue[GLTFTEXT("alphaCutoff")].GetFloat(); + } + if (_JsonValue.HasMember(GLTFTEXT("emissiveTexture")) && _JsonValue[GLTFTEXT("emissiveTexture")].IsObject()) + { + if (!(_rData.emissiveTexture << _JsonValue[GLTFTEXT("emissiveTexture")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("pbrMetallicRoughness")) && _JsonValue[GLTFTEXT("pbrMetallicRoughness")].IsObject()) + { + if (!(_rData.pbrMetallicRoughness << _JsonValue[GLTFTEXT("pbrMetallicRoughness")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("occlusionTexture")) && _JsonValue[GLTFTEXT("occlusionTexture")].IsObject()) + { + if (!(_rData.occlusionTexture << _JsonValue[GLTFTEXT("occlusionTexture")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("alphaMode")) && _JsonValue[GLTFTEXT("alphaMode")].IsString()) + { + _rData.alphaMode = _JsonValue[GLTFTEXT("alphaMode")].GetString(); + } + if (_JsonValue.HasMember(GLTFTEXT("doubleSided")) && _JsonValue[GLTFTEXT("doubleSided")].IsBool()) + { + _rData.doubleSided = _JsonValue[GLTFTEXT("doubleSided")].GetBool(); + } + if (_JsonValue.HasMember(GLTFTEXT("normalTexture")) && _JsonValue[GLTFTEXT("normalTexture")].IsObject()) + { + if (!(_rData.normalTexture << _JsonValue[GLTFTEXT("normalTexture")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("emissiveFactor")) && _JsonValue[GLTFTEXT("emissiveFactor")].IsArray()) + { + if (!(_rData.emissiveFactor << _JsonValue[GLTFTEXT("emissiveFactor")])) return false; + } + _rData.schemaType = GLTFTEXT("material.schema.json"); return true; } - bool operator>>(const SExtras& _rData, GLTFCharValue& _JsonValue) + bool operator>>(const SMaterial& _rData, GLTFCharValue& _JsonValue) { if (!g_json_doc_ptr) return false; _JsonValue.SetObject(); + { + const SGlTFChildofRootProperty& super_ptr = _rData; + if (!(super_ptr >> _JsonValue)) return false; + } + { + GLTFCharValue json_value; + if (!(_rData.alphaCutoff >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("alphaCutoff"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!!_rData.emissiveTexture) + { + GLTFCharValue json_value; + if (!(_rData.emissiveTexture >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("emissiveTexture"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!!_rData.pbrMetallicRoughness) + { + GLTFCharValue json_value; + if (!(_rData.pbrMetallicRoughness >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("pbrMetallicRoughness"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!!_rData.occlusionTexture) + { + GLTFCharValue json_value; + if (!(_rData.occlusionTexture >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("occlusionTexture"), json_value, g_json_doc_ptr->GetAllocator()); + } + { + GLTFCharValue json_value; + if (!(_rData.alphaMode >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("alphaMode"), json_value, g_json_doc_ptr->GetAllocator()); + } + { + GLTFCharValue json_value; + if (!(_rData.doubleSided >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("doubleSided"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!!_rData.normalTexture) + { + GLTFCharValue json_value; + if (!(_rData.normalTexture >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("normalTexture"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!_rData.emissiveFactor.empty()) + { + GLTFCharValue json_value; + if (!(_rData.emissiveFactor >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("emissiveFactor"), json_value, g_json_doc_ptr->GetAllocator()); + } return true; } - 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(); if (!(*data_ptr << _JsonValue)) 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) return false; return (*_pData >> _JsonValue); } - 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<<(SScene& _rData, const GLTFCharValue& _JsonValue) @@ -1129,69 +1092,41 @@ namespace libgltf return operator>> >(_vDatas, _JsonValue); } - bool operator<<(SMesh& _rData, const GLTFCharValue& _JsonValue) + bool operator<<(SExtras& _rData, const GLTFCharValue& _JsonValue) { - { - SGlTFChildofRootProperty& super_ptr = _rData; - if (!(super_ptr << _JsonValue)) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("primitives")) && _JsonValue[GLTFTEXT("primitives")].IsArray()) - { - if (!(_rData.primitives << _JsonValue[GLTFTEXT("primitives")])) return false; - } - if (_JsonValue.HasMember(GLTFTEXT("weights")) && _JsonValue[GLTFTEXT("weights")].IsArray()) - { - if (!(_rData.weights << _JsonValue[GLTFTEXT("weights")])) return false; - } - _rData.schemaType = GLTFTEXT("mesh.schema.json"); + _rData.schemaType = GLTFTEXT("extras.schema.json"); return true; } - bool operator>>(const SMesh& _rData, GLTFCharValue& _JsonValue) + bool operator>>(const SExtras& _rData, GLTFCharValue& _JsonValue) { if (!g_json_doc_ptr) return false; _JsonValue.SetObject(); - { - const SGlTFChildofRootProperty& super_ptr = _rData; - if (!(super_ptr >> _JsonValue)) return false; - } - if (!_rData.primitives.empty()) - { - GLTFCharValue json_value; - if (!(_rData.primitives >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("primitives"), json_value, g_json_doc_ptr->GetAllocator()); - } - if (!_rData.weights.empty()) - { - GLTFCharValue json_value; - if (!(_rData.weights >> json_value)) return false; - _JsonValue.AddMember(GLTFTEXT("weights"), json_value, g_json_doc_ptr->GetAllocator()); - } return true; } - 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(); if (!(*data_ptr << _JsonValue)) 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) return false; return (*_pData >> _JsonValue); } - 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<<(SAccessorSparse& _rData, const GLTFCharValue& _JsonValue) @@ -2275,6 +2210,71 @@ namespace libgltf return operator>> >(_vDatas, _JsonValue); } + bool operator<<(SMesh& _rData, const GLTFCharValue& _JsonValue) + { + { + SGlTFChildofRootProperty& super_ptr = _rData; + if (!(super_ptr << _JsonValue)) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("primitives")) && _JsonValue[GLTFTEXT("primitives")].IsArray()) + { + if (!(_rData.primitives << _JsonValue[GLTFTEXT("primitives")])) return false; + } + if (_JsonValue.HasMember(GLTFTEXT("weights")) && _JsonValue[GLTFTEXT("weights")].IsArray()) + { + if (!(_rData.weights << _JsonValue[GLTFTEXT("weights")])) return false; + } + _rData.schemaType = GLTFTEXT("mesh.schema.json"); + return true; + } + + bool operator>>(const SMesh& _rData, GLTFCharValue& _JsonValue) + { + if (!g_json_doc_ptr) return false; + _JsonValue.SetObject(); + { + const SGlTFChildofRootProperty& super_ptr = _rData; + if (!(super_ptr >> _JsonValue)) return false; + } + if (!_rData.primitives.empty()) + { + GLTFCharValue json_value; + if (!(_rData.primitives >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("primitives"), json_value, g_json_doc_ptr->GetAllocator()); + } + if (!_rData.weights.empty()) + { + GLTFCharValue json_value; + if (!(_rData.weights >> json_value)) return false; + _JsonValue.AddMember(GLTFTEXT("weights"), json_value, g_json_doc_ptr->GetAllocator()); + } + return true; + } + + bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue) + { + std::shared_ptr data_ptr = !!_pData ? _pData : std::make_shared(); + if (!(*data_ptr << _JsonValue)) return false; + _pData = data_ptr; + return true; + } + + bool operator>>(const std::shared_ptr& _pData, GLTFCharValue& _JsonValue) + { + if (!_pData) return false; + return (*_pData >> _JsonValue); + } + + 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<<(STexture& _rData, const GLTFCharValue& _JsonValue) { { diff --git a/source/libgltf/libgltfparser.h b/source/libgltf/libgltfparser.h index 3b16a9a..ee20598 100644 --- a/source/libgltf/libgltfparser.h +++ b/source/libgltf/libgltfparser.h @@ -14,13 +14,6 @@ namespace libgltf bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); - bool operator<<(struct SMaterial& _rData, const GLTFCharValue& _JsonValue); - bool operator>>(const struct SMaterial& _rData, 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<<(struct SAsset& _rData, const GLTFCharValue& _JsonValue); bool operator>>(const struct SAsset& _rData, GLTFCharValue& _JsonValue); bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); @@ -49,12 +42,12 @@ namespace libgltf bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); - bool operator<<(struct SExtras& _rData, const GLTFCharValue& _JsonValue); - bool operator>>(const struct SExtras& _rData, 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<<(struct SMaterial& _rData, const GLTFCharValue& _JsonValue); + bool operator>>(const struct SMaterial& _rData, 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<<(struct SScene& _rData, const GLTFCharValue& _JsonValue); bool operator>>(const struct SScene& _rData, GLTFCharValue& _JsonValue); @@ -105,12 +98,12 @@ namespace libgltf bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); - bool operator<<(struct SMesh& _rData, const GLTFCharValue& _JsonValue); - bool operator>>(const struct SMesh& _rData, 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<<(struct SExtras& _rData, const GLTFCharValue& _JsonValue); + bool operator>>(const struct SExtras& _rData, 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<<(struct SAccessorSparse& _rData, const GLTFCharValue& _JsonValue); bool operator>>(const struct SAccessorSparse& _rData, GLTFCharValue& _JsonValue); @@ -210,6 +203,13 @@ namespace libgltf bool operator<<(std::vector>& _vDatas, const GLTFCharValue& _JsonValue); bool operator>>(const std::vector>& _vDatas, GLTFCharValue& _JsonValue); + bool operator<<(struct SMesh& _rData, const GLTFCharValue& _JsonValue); + bool operator>>(const struct SMesh& _rData, 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<<(struct STexture& _rData, const GLTFCharValue& _JsonValue); bool operator>>(const struct STexture& _rData, GLTFCharValue& _JsonValue); bool operator<<(std::shared_ptr& _pData, const GLTFCharValue& _JsonValue); diff --git a/tools/jsonschematoc11/__init__.py b/tools/jsonschematoc11/__init__.py index e6683f4..82db268 100644 --- a/tools/jsonschematoc11/__init__.py +++ b/tools/jsonschematoc11/__init__.py @@ -8,4 +8,4 @@ sys.exit(error_code) else: print u'Success' - exit(error_code) + sys.exit(error_code) diff --git a/tools/jsonschematoc11/__main__.py b/tools/jsonschematoc11/__main__.py index e6683f4..82db268 100644 --- a/tools/jsonschematoc11/__main__.py +++ b/tools/jsonschematoc11/__main__.py @@ -8,4 +8,4 @@ sys.exit(error_code) else: print u'Success' - exit(error_code) + sys.exit(error_code) diff --git a/tools/jsonschematoc11/jsonschematoc11.py b/tools/jsonschematoc11/jsonschematoc11.py index fc58758..bfe18e9 100644 --- a/tools/jsonschematoc11/jsonschematoc11.py +++ b/tools/jsonschematoc11/jsonschematoc11.py @@ -532,4 +532,4 @@ def JSONSchemaToC11(argv): sys.exit(error_code) else: logger.info(u'Success') - exit(error_code) + sys.exit(error_code)