├── .clang-format ├── .coveralls.yml ├── .editorconfig ├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── build.yml │ ├── coverage.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── CHANGELOG.md ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── docs ├── CMakeLists.txt ├── conf.py ├── index.rst └── requirements.txt ├── resource ├── 2.0 │ ├── Avocado │ │ ├── README.md │ │ └── glTF-pbrSpecularGlossiness │ │ │ ├── Avocado.bin │ │ │ └── Avocado.gltf │ ├── Cameras │ │ ├── README.md │ │ └── glTF │ │ │ ├── Cameras.gltf │ │ │ └── simpleSquare.bin │ ├── EnvironmentTest │ │ ├── README.md │ │ ├── glTF-IBL │ │ │ ├── EnvironmentTest.gltf │ │ │ └── EnvironmentTest_binary.bin │ │ └── glTF │ │ │ ├── EnvironmentTest.gltf │ │ │ └── EnvironmentTest_binary.bin │ ├── MaterialsVariantsShoe │ │ ├── README.md │ │ └── glTF │ │ │ ├── MaterialsVariantsShoe.bin │ │ │ └── MaterialsVariantsShoe.gltf │ ├── MetalRoughSpheres │ │ ├── README.md │ │ └── glTF │ │ │ ├── MetalRoughSpheres.gltf │ │ │ └── MetalRoughSpheres0.bin │ ├── Monster │ │ ├── README.md │ │ ├── glTF-Binary │ │ │ └── Monster.glb │ │ ├── glTF-Draco │ │ │ ├── 0.bin │ │ │ └── Monster.gltf │ │ ├── glTF-Embedded │ │ │ └── Monster.gltf │ │ ├── glTF │ │ │ ├── Monster.gltf │ │ │ └── Monster0.bin │ │ └── screenshot │ │ │ └── screenshot.gif │ ├── MorphPrimitivesTest │ │ ├── README.md │ │ └── glTF │ │ │ ├── MorphPrimitivesTest.bin │ │ │ └── MorphPrimitivesTest.gltf │ ├── MultiUVTest │ │ ├── README.md │ │ └── glTF │ │ │ ├── MultiUVTest.bin │ │ │ └── MultiUVTest.gltf │ ├── README.md │ ├── Triangle │ │ ├── README.md │ │ └── glTF │ │ │ ├── 三角形.bin │ │ │ └── 三角形.gltf │ ├── TriangleWithoutIndices │ │ ├── README.md │ │ └── glTF │ │ │ ├── TriangleWithoutIndices.gltf │ │ │ └── triangleWithoutIndices.bin │ ├── TwoSidedPlane │ │ ├── README.md │ │ └── glTF │ │ │ ├── TwoSidedPlane.bin │ │ │ └── TwoSidedPlane.gltf │ ├── UnlitTest │ │ ├── README.md │ │ └── glTF │ │ │ ├── UnlitTest.bin │ │ │ └── UnlitTest.gltf │ └── VertexColorTest │ │ ├── README.md │ │ └── glTF │ │ ├── VertexColorTest.bin │ │ └── VertexColorTest.gltf └── nothing.gltf ├── source ├── CMakeLists.txt ├── libgltf │ ├── CMakeLists.txt │ ├── common.cpp │ ├── common.h │ ├── extensions │ │ ├── google_draco.cpp │ │ └── google_draco.h │ ├── gltf_loader.cpp │ ├── gltf_loader.h │ ├── libgltf-config.cmake │ ├── libgltf.cpp │ ├── libgltf.h.cmakein │ ├── libgltfloader.cpp │ ├── libgltfparser.cpp │ ├── libgltfparser.h │ ├── utility.cpp │ └── utility.h └── runtest │ ├── CMakeLists.txt │ ├── runtest.cpp │ └── runtest.h └── tools ├── CMakeLists.txt ├── batch ├── CMakeLists.txt ├── codes │ ├── extension.schema.json.function.cpp │ ├── extension.schema.json.h │ ├── extension.schema.json.parser.from.cpp │ ├── extension.schema.json.parser.to.cpp │ ├── extension.schema.json.variable.cpp │ ├── libgltf.header.begin.h │ ├── libgltf.header.end.h │ ├── libgltf.header.include.h │ ├── libgltf.header.namespace.begin.h │ ├── libgltf.header.namespace.end.h │ └── libgltf.parser.h ├── glTF_2.0_schema.ini ├── update_parser_by_scheme.bat └── update_parser_by_scheme.sh └── jsonschematoc11 ├── CMakeLists.txt ├── __init__.py ├── __main__.py ├── c11types ├── __init__.py ├── c11type.py ├── c11typearray.py ├── c11typebool.py ├── c11typeinteger.py ├── c11typemap.py ├── c11typenone.py ├── c11typenumber.py ├── c11typestring.py ├── c11typestruct.py └── c11variable.py └── jsonschematoc11.py /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # We'll use defaults from the LLVM style, but with 4 columns indentation. 3 | BasedOnStyle: LLVM 4 | IndentWidth: 4 5 | 6 | --- 7 | Language: Cpp 8 | # Force pointers to the type for C++. 9 | AccessModifierOffset: -4 10 | AlignAfterOpenBracket: Align 11 | AlignConsecutiveAssignments: true 12 | AlignConsecutiveBitFields: true 13 | AlignConsecutiveDeclarations: true 14 | AlignConsecutiveMacros: true 15 | AlignEscapedNewlines: Right 16 | AlignOperands: AlignAfterOperator 17 | AlignTrailingComments: true 18 | AllowAllArgumentsOnNextLine: true 19 | AllowAllConstructorInitializersOnNextLine: true 20 | AllowAllParametersOfDeclarationOnNextLine: true 21 | AllowShortBlocksOnASingleLine: Never 22 | AllowShortCaseLabelsOnASingleLine: false 23 | AllowShortFunctionsOnASingleLine: None 24 | AllowShortIfStatementsOnASingleLine: Never 25 | AllowShortLambdasOnASingleLine: None 26 | AllowShortLoopsOnASingleLine: false 27 | AlwaysBreakTemplateDeclarations: Yes 28 | BinPackArguments: false 29 | BinPackParameters: false 30 | BitFieldColonSpacing: None 31 | BraceWrapping: 32 | AfterEnum: true 33 | AfterStruct: false 34 | SplitEmptyFunction: false 35 | BreakBeforeBraces: Allman 36 | BreakBeforeConceptDeclarations: true 37 | BreakBeforeTernaryOperators: true 38 | BreakConstructorInitializers: BeforeComma 39 | BreakInheritanceList: BeforeComma 40 | BreakStringLiterals: false 41 | ColumnLimit: 150 42 | CompactNamespaces: false 43 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 44 | Cpp11BracedListStyle: false 45 | DerivePointerAlignment: false 46 | EmptyLineBeforeAccessModifier: Always 47 | FixNamespaceComments: true 48 | IndentCaseBlocks: false 49 | IndentCaseLabels: false 50 | IndentPPDirectives: AfterHash 51 | IndentRequires: true 52 | NamespaceIndentation: All 53 | PointerAlignment: Left 54 | SortIncludes: false 55 | SpaceBeforeRangeBasedForLoopColon: true 56 | SpaceBeforeSquareBrackets: false 57 | SpacesInCStyleCastParentheses: false 58 | SpacesInConditionalStatement: false 59 | Standard: c++11 60 | -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: github-action 2 | exclude: 3 | - ./source/runtest/ 4 | - ./tools/ 5 | - ./external/ 6 | - ./build/CMakeFiles/ 7 | - ./build/draco/ 8 | - ./build/draco_compression_attributes_pred_schemes_dec.cc 9 | - ./build/draco_compression_mesh_traverser.cc 10 | - ./build/draco_dec_config.cc 11 | - ./build/draco_enc_config.cc 12 | - ./output/ 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # All files 2 | [*] 3 | guidelines = 150 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.bmp filter=lfs diff=lfs merge=lfs -text 2 | *.jpg filter=lfs diff=lfs merge=lfs -text 3 | *.jpeg filter=lfs diff=lfs merge=lfs -text 4 | *.tga filter=lfs diff=lfs merge=lfs -text 5 | *.png filter=lfs diff=lfs merge=lfs -text 6 | *.psd filter=lfs diff=lfs merge=lfs -text 7 | *.3ds filter=lfs diff=lfs merge=lfs -text 8 | *.fbx filter=lfs diff=lfs merge=lfs -text 9 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | #github: alexchicn 4 | patreon: c4gio 5 | custom: https://c4gio.itch.io/ 6 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: 'coverage' 2 | 3 | on: 4 | push: 5 | branches: [ '*' ] 6 | paths-ignore: 7 | - '!.github/coverage.yml' 8 | - 'docs/**' 9 | - '.readthedocs.yml' 10 | - '.git*' 11 | - '*.md' 12 | - 'LICENSE' 13 | 14 | jobs: 15 | coveralls: 16 | name: 'for coveralls' 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: 'install dependencies' 20 | run: | 21 | sudo apt-get install valgrind gcovr 22 | sudo pip install wheel 23 | sudo pip install cpp-coveralls 24 | - name: 'checkout the project' 25 | uses: actions/checkout@v3 26 | - name: 'update submodules' 27 | run: | 28 | git submodule update --init external/rapidjson 29 | git submodule update --init external/draco 30 | - name: 'build and make' 31 | run: | 32 | cmake -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DLIBGLTF_BUILD_COVERAGE=TRUE -DLIBGLTF_BUILD_RUNTEST=TRUE -DLIBGLTF_WITH_GOOGLE_DRACO=TRUE . 33 | cmake --build build --target runtest --config Debug 34 | - name: 'run valgrind and gcovr' 35 | run: | 36 | cd build 37 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest 38 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/nothing.gltf 39 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/Monster/glTF/Monster.gltf 40 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/Monster/glTF-Binary/Monster.glb 41 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/Monster/glTF-Draco/Monster.gltf 42 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/Monster/glTF-Embedded/Monster.gltf 43 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/Avocado/glTF-pbrSpecularGlossiness/Avocado.gltf 44 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/Cameras/glTF/Cameras.gltf 45 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/EnvironmentTest/glTF/EnvironmentTest.gltf 46 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/EnvironmentTest/glTF-IBL/EnvironmentTest.gltf 47 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/MaterialsVariantsShoe/glTF/MaterialsVariantsShoe.gltf 48 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/MetalRoughSpheres/glTF/MetalRoughSpheres.gltf 49 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/MorphPrimitivesTest/glTF/MorphPrimitivesTest.gltf 50 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/MultiUVTest/glTF/MultiUVTest.gltf 51 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/Triangle/glTF/三角形.gltf 52 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/TriangleWithoutIndices/glTF/TriangleWithoutIndices.gltf 53 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/TwoSidedPlane/glTF/TwoSidedPlane.gltf 54 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/UnlitTest/glTF/UnlitTest.gltf 55 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../resource/2.0/VertexColorTest/glTF/VertexColorTest.gltf 56 | valgrind --leak-check=full --show-leak-kinds=all ./../build/source/runtest/runtest ../external/glTF/extensions/2.0/Khronos/KHR_lights_punctual/schema/examples/lights.gltf 57 | gcov source/runtest/CMakeFiles/runtest.dir/runtest.cpp.gcda 58 | gcovr --root=../source/ . 59 | cd ../ 60 | export TRAVIS_JOB_ID=${{ github.run_number }} 61 | coveralls --repo-token ${{ secrets.COVERALLS_REPO_TOKEN }} -y .coveralls.yml --gcov-options '\-lp' 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # vim 2 | /**/*.*~ 3 | /**/*.swp 4 | 5 | # py 6 | /**/*.pyc 7 | /**/*.pyo 8 | 9 | # macos 10 | /**/.DS_Store 11 | 12 | # vs 13 | /**/.vs 14 | /**/.vscode 15 | 16 | # project 17 | /**/output/ 18 | /**/build*/ 19 | /docs/_build 20 | /resource/**/*.obj 21 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/rapidjson"] 2 | path = external/rapidjson 3 | url = https://github.com/miloyip/rapidjson.git 4 | [submodule "external/glTF"] 5 | path = external/glTF 6 | url = https://github.com/KhronosGroup/glTF.git 7 | [submodule "external/draco"] 8 | path = external/draco 9 | url = https://github.com/google/draco.git 10 | [submodule "external/ios-cmake"] 11 | path = external/ios-cmake 12 | url = https://github.com/code4game/ios-cmake.git 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## 0.1.10 (2023-02-06) 4 | 5 | * Update glTF 6 | * Supports more extensions 7 | * Fix an error when parse the embedded format 8 | 9 | ## 0.1.9 (2021-11-10) 10 | 11 | * Update glTF 12 | * Supports more material extensions 13 | 14 | ## 0.1.8 (2021-01-29) 15 | 16 | * Fix a bug: the parser can't parse the array that the type of its item is a map 17 | 18 | ## 0.1.7 (2020-10-15) 19 | 20 | * Supports the `KHR_lights_punctual` 21 | * Compile by github action 22 | 23 | ## 0.1.6 24 | 25 | * Fix some bugs 26 | 27 | ## 0.1.5 28 | 29 | * Fix some bugs 30 | 31 | ## 0.1.4 (2018-11-5) 32 | 33 | * Support Android and iOS platforms 34 | 35 | ## 0.0.1 (2017-12-5) 36 | 37 | ### Changes 38 | 39 | * Integrate more applications to check the project 40 | * Depoly the output files when build tags 41 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15 FATAL_ERROR) 2 | 3 | project(libgltf CXX) 4 | 5 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 6 | #enable_testing() 7 | 8 | set(CMAKE_DEBUG_POSTFIX "d") 9 | set(CMAKE_CXX_STANDARD 17) 10 | 11 | # define the platform 12 | set(LIBGLTF_PLATFORM_WINDOWS FALSE) 13 | set(LIBGLTF_PLATFORM_LINUX FALSE) 14 | set(LIBGLTF_PLATFORM_MACOS FALSE) 15 | set(LIBGLTF_PLATFORM_ANDROID FALSE) 16 | set(LIBGLTF_PLATFORM_IOS FALSE) 17 | 18 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND MSVC) 19 | set(LIBGLTF_WITH_MSVC_MT OFF CACHE BOOL "Build MSVC with 'MultiThreading(MT)' or 'MultiThreadingDLL(MD)'?") 20 | if(${LIBGLTF_WITH_MSVC_MT}) 21 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 22 | else() 23 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") 24 | endif() 25 | set(LIBGLTF_PLATFORM_WINDOWS TRUE) 26 | add_definitions(-DLIBGLTF_PLATFORM_WINDOWS) 27 | if((CMAKE_EXE_LINKER_FLAGS STREQUAL "/machine:X86") OR (CMAKE_EXE_LINKER_FLAGS STREQUAL " /machine:X86")) 28 | set(TARGET_ARCHITECTURES_X86 TRUE) 29 | set(PLATFORM_NAME "win32") 30 | elseif((CMAKE_EXE_LINKER_FLAGS STREQUAL "/machine:x64") OR (CMAKE_EXE_LINKER_FLAGS STREQUAL " /machine:x64")) 31 | set(TARGET_ARCHITECTURES_X64 TRUE) 32 | set(PLATFORM_NAME "win64") 33 | endif() 34 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 35 | set(LIBGLTF_PLATFORM_LINUX TRUE) 36 | add_definitions(-DLIBGLTF_PLATFORM_LINUX) 37 | set(PLATFORM_NAME "linux") 38 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wconversion -Wno-long-long -pedantic") 39 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic") 40 | set(LIBGLTF_BUILD_COVERAGE OFF CACHE BOOL "Coverage gcov (debug, Linux builds only)") 41 | if(LIBGLTF_BUILD_COVERAGE) 42 | add_definitions(-DLIBGLTF_BUILD_COVERAGE) 43 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -fPIC") 44 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -fPIC") 45 | set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov") 46 | endif() 47 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") 48 | set(LIBGLTF_PLATFORM_ANDROID TRUE) 49 | add_definitions(-DLIBGLTF_PLATFORM_ANDROID) 50 | set(PLATFORM_NAME "android") 51 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wconversion -Wno-long-long -pedantic") 52 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic") 53 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND (NOT ${LIBGLTF_PLATFORM_IOS})) 54 | set(LIBGLTF_PLATFORM_MACOS TRUE) 55 | add_definitions(-DLIBGLTF_PLATFORM_MACOS) 56 | set(PLATFORM_NAME "macos") 57 | set(CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Wconversion -Wno-long-long -pedantic ${CMAKE_C_FLAGS}") 58 | set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic ${CMAKE_CXX_FLAGS}") 59 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ${LIBGLTF_PLATFORM_IOS}) 60 | set(LIBGLTF_PLATFORM_IOS TRUE) 61 | add_definitions(-DLIBGLTF_PLATFORM_IOS) 62 | set(PLATFORM_NAME "ios") 63 | set(CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Wconversion -Wno-long-long -pedantic ${CMAKE_C_FLAGS}") 64 | set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic ${CMAKE_CXX_FLAGS}") 65 | endif() 66 | 67 | 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})) 68 | message(FATAL_ERROR "Sorry, don't support your system ${CMAKE_SYSTEM_NAME}!") 69 | endif() 70 | 71 | set(ROOT_PATH "${PROJECT_SOURCE_DIR}") 72 | set(SOURCE_PATH "${ROOT_PATH}/source") 73 | set(TOOLS_PATH "${ROOT_PATH}/tools") 74 | set(EXTERNAL_PATH "${ROOT_PATH}/external") 75 | 76 | find_package(RapidJSON CONFIG) 77 | find_package(draco CONFIG) 78 | 79 | # integrate the Google's draco 80 | set(LIBGLTF_WITH_GOOGLE_DRACO OFF CACHE BOOL "Use Google's Draco?") 81 | if(LIBGLTF_WITH_GOOGLE_DRACO) 82 | if(MSVC) 83 | set(LIBDRACO_NAME draco) 84 | else() 85 | set(LIBDRACO_NAME draco_static) 86 | endif() 87 | if(NOT draco_FOUND) 88 | #set(DRACO_GLTF TRUE CACHE BOOL "") 89 | add_subdirectory(${EXTERNAL_PATH}/draco) 90 | set_target_properties(${LIBDRACO_NAME} PROPERTIES FOLDER externals/draco) 91 | set_target_properties(draco_animation PROPERTIES FOLDER externals/draco) 92 | set_target_properties(draco_animation_dec PROPERTIES FOLDER externals/draco) 93 | set_target_properties(draco_animation_enc PROPERTIES FOLDER externals/draco) 94 | set_target_properties(draco_attributes PROPERTIES FOLDER externals/draco) 95 | set_target_properties(draco_compression_attributes_dec PROPERTIES FOLDER externals/draco) 96 | set_target_properties(draco_compression_attributes_enc PROPERTIES FOLDER externals/draco) 97 | set_target_properties(draco_compression_attributes_pred_schemes_dec PROPERTIES FOLDER externals/draco) 98 | set_target_properties(draco_compression_attributes_pred_schemes_enc PROPERTIES FOLDER externals/draco) 99 | set_target_properties(draco_compression_bit_coders PROPERTIES FOLDER externals/draco) 100 | set_target_properties(draco_compression_decode PROPERTIES FOLDER externals/draco) 101 | set_target_properties(draco_compression_encode PROPERTIES FOLDER externals/draco) 102 | set_target_properties(draco_compression_entropy PROPERTIES FOLDER externals/draco) 103 | set_target_properties(draco_compression_mesh_dec PROPERTIES FOLDER externals/draco) 104 | set_target_properties(draco_compression_mesh_enc PROPERTIES FOLDER externals/draco) 105 | set_target_properties(draco_compression_mesh_traverser PROPERTIES FOLDER externals/draco) 106 | set_target_properties(draco_compression_point_cloud_dec PROPERTIES FOLDER externals/draco) 107 | set_target_properties(draco_compression_point_cloud_enc PROPERTIES FOLDER externals/draco) 108 | set_target_properties(draco_core PROPERTIES FOLDER externals/draco) 109 | set_target_properties(draco_dec_config PROPERTIES FOLDER externals/draco) 110 | set_target_properties(draco_decoder PROPERTIES FOLDER externals/draco) 111 | set_target_properties(draco_enc_config PROPERTIES FOLDER externals/draco) 112 | set_target_properties(draco_encoder PROPERTIES FOLDER externals/draco) 113 | set_target_properties(draco_io PROPERTIES FOLDER externals/draco) 114 | set_target_properties(draco_mesh PROPERTIES FOLDER externals/draco) 115 | set_target_properties(draco_metadata PROPERTIES FOLDER externals/draco) 116 | set_target_properties(draco_metadata_dec PROPERTIES FOLDER externals/draco) 117 | set_target_properties(draco_metadata_enc PROPERTIES FOLDER externals/draco) 118 | set_target_properties(draco_point_cloud PROPERTIES FOLDER externals/draco) 119 | set_target_properties(draco_points_dec PROPERTIES FOLDER externals/draco) 120 | set_target_properties(draco_points_enc PROPERTIES FOLDER externals/draco) 121 | set(GOOGLE_DRACO_PATH_INCLUDE ${EXTERNAL_PATH}/draco/src) 122 | set(GOOGLE_DRACO_PATH_BUILD ${CMAKE_BINARY_DIR}) 123 | else() 124 | # 125 | endif() 126 | endif() 127 | 128 | set(LIBGLTF_BUILD_RUNTEST FALSE CACHE BOOL "Build runtest?") 129 | 130 | add_subdirectory(docs) 131 | add_subdirectory(source) 132 | add_subdirectory(tools) 133 | 134 | set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT libgltf) 135 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed 34 | representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 35 | 36 | ## Enforcement 37 | 38 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at info@c4g.io. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 39 | 40 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 41 | 42 | ## Attribution 43 | 44 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 45 | 46 | [homepage]: https://www.contributor-covenant.org 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. 4 | 5 | Please note we have a code of conduct, please follow it in all your interactions with the project. 6 | 7 | ## Pull Request Process 8 | 9 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. 10 | 2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters. 11 | 3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 12 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. 13 | 14 | ## Code of Conduct 15 | 16 | Please see [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md). 17 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | This software is released under the MIT license. 2 | 3 | Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libgltf 2 | 3 | [![glTF status](https://img.shields.io/badge/glTF-2%2E0-green.svg?style=flat)](https://github.com/KhronosGroup/glTF) 4 | [![libgltf document](https://readthedocs.org/projects/libgltf/badge/?version=latest)](http://libgltf.rtfd.io/) 5 | [![visit milestones](https://img.shields.io/badge/visit-milestones-blue.svg?style=flat)](https://github.com/code4game/libgltf/milestones) 6 | 7 | [![build](https://github.com/code4game/libgltf/workflows/build/badge.svg)](https://github.com/code4game/libgltf/actions?query=workflow%3Abuild) 8 | [![Coverage status from coveralls](https://coveralls.io/repos/github/code4game/libgltf/badge.svg?branch=master)](https://coveralls.io/github/code4game/libgltf?branch=master) 9 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/5480b79467244c528a22defcf1fd9c4f)](https://www.codacy.com/gh/code4game/libgltf/dashboard?utm_source=github.com&utm_medium=referral&utm_content=code4game/libgltf&utm_campaign=Badge_Grade) 10 | [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/code4game/libgltf.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/code4game/libgltf/context:python) 11 | 12 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcode4game%2Flibgltf.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcode4game%2Flibgltf?ref=badge_shield) 13 | [![CII best practices](https://bestpractices.coreinfrastructure.org/projects/1434/badge)](https://bestpractices.coreinfrastructure.org/projects/1434) 14 | [![support](https://img.shields.io/badge/support-buy%20a%20cup%20of%20coffee-orange.svg?style=flat)](https://c4gio.itch.io/libgltf-ue4) 15 | 16 | The project includes a generator that can generate codes by glTF 2.0 JSON schema. 17 | 18 | It is used in [glTFForUE4](https://github.com/code4game/glTFForUE4). 19 | 20 | ## Features 21 | 22 | * [glTF 2.0] 23 | * Load the gltf/embedded/glb file 24 | * This is a static library 25 | * Cross platform 26 | * C++17 27 | * Supports the Unicode and UTF8 28 | * Supports some extensions 29 | * `KHR_draco_mesh_compression` - [Google's Draco] 30 | * `KHR_lights_punctual` 31 | * `KHR_materials_clearcoat` 32 | * `KHR_materials_emissive_strength` 33 | * `KHR_materials_ior` 34 | * `KHR_materials_iridescence` 35 | * `KHR_materials_sheen` 36 | * `KHR_materials_specular` 37 | * `KHR_materials_transmission` 38 | * `KHR_materials_unlit` 39 | * `KHR_materials_variants` 40 | * `KHR_materials_volume` 41 | * `KHR_texture_transform` 42 | * `ADOBE_materials_thin_transparency` 43 | * `AGI_articulations` 44 | * `AGI_stk_metadata` 45 | * `CESIUM_primitive_outline` 46 | * `EXT_lights_ies` 47 | * `EXT_mesh_gpu_instancing` 48 | * `EXT_texture_webp` 49 | * `FB_geometry_metadata` 50 | * `MSFT_lod` 51 | * `MSFT_texture_dds` 52 | * Platforms 53 | * Windows 54 | * Win32 (win32) 55 | * x64 (win64) 56 | * Linux (linux) 57 | * macOS (macos) 58 | * Android 59 | * armeabi-v7a 60 | * armeabi-v7a-with-neon 61 | * arm64-v8a 62 | * x86 63 | * x86_64 64 | * iOS 65 | * iOS (iphoneos) 66 | * watchOS (watchos) 67 | * simulator 68 | 69 | ## Getting Started 70 | 71 | 1. Update the submodule 72 | > Run `git submodule update --init` 73 | 2. Generate the project by [CMake] 74 | > Run `cmake -G "[GENERATOR BY YOUR SYSTEM]" [LIBGLTF FOLDER]` 75 | 3. Build the project and generate the static library `libgltf.lib` or `libgltf.a` 76 | 4. Include `libgltf/libgltf.h` in your project. 77 | 5. Link the static library `libgltf.lib` or `libgltf.a` in your project. 78 | > You have to link the static library `draco.lib` or `draco.a` with your project, if you want to support the [Google's Draco]. 79 | > And you can find the draco in the external folder. 80 | 81 | Code example: 82 | 83 | ```cpp 84 | std::shared_ptr gltf_loader = libgltf::IglTFLoader::Create(/*a function to load the file by std::istream*/); 85 | std::shared_ptr loaded_gltf = gltf_loader->glTF().lock(); 86 | if (!loaded_gltf) 87 | { 88 | printf("failed to load your gltf file"); 89 | } 90 | ``` 91 | 92 | ## License 93 | 94 | This software is released under the MIT license. 95 | 96 | [glTF 2.0]: https://www.khronos.org/gltf/ 97 | [Google's Draco]: https://github.com/google/draco 98 | [CMake]: https://cmake.org/ 99 | 100 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcode4game%2Flibgltf.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcode4game%2Flibgltf?ref=badge_large) 101 | -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(DOC_ROOT_FILE_LIST 2 | ${ROOT_PATH}/README.md 3 | ${ROOT_PATH}/CONTRIBUTING.md 4 | ${ROOT_PATH}/CODE_OF_CONDUCT.md 5 | ${ROOT_PATH}/CHANGELOG.md 6 | ${ROOT_PATH}/LICENSE.md 7 | ) 8 | 9 | set(DOC_HELP_FILE_LIST 10 | ${ROOT_PATH}/docs/conf.py 11 | ${ROOT_PATH}/docs/index.rst 12 | ) 13 | 14 | source_group("root" FILES ${DOC_ROOT_FILE_LIST}) 15 | source_group("help" FILES ${DOC_HELP_FILE_LIST}) 16 | 17 | add_custom_target(DOC SOURCES ${DOC_ROOT_FILE_LIST} ${DOC_HELP_FILE_LIST}) 18 | set_property(TARGET DOC PROPERTY FOLDER CMakePredefinedTargets) 19 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | # import os 14 | # import sys 15 | # sys.path.insert(0, os.path.abspath('.')) 16 | 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | project = 'libgltf' 21 | copyright = '2023, Code 4 Game' 22 | author = 'Xing Ji' 23 | 24 | 25 | # -- General configuration --------------------------------------------------- 26 | 27 | # Add any Sphinx extension module names here, as strings. They can be 28 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 29 | # ones. 30 | extensions = [ 31 | 'breathe', 32 | 'sphinx.ext.mathjax' 33 | ] 34 | 35 | # Add any paths that contain templates here, relative to this directory. 36 | #templates_path = ['_templates'] 37 | templates_path = [] 38 | 39 | # List of patterns, relative to source directory, that match files and 40 | # directories to ignore when looking for source files. 41 | # This pattern also affects html_static_path and html_extra_path. 42 | exclude_patterns = [] 43 | 44 | 45 | # -- Options for HTML output ------------------------------------------------- 46 | 47 | # The theme to use for HTML and HTML Help pages. See the documentation for 48 | # a list of builtin themes. 49 | # 50 | html_theme = 'sphinx_rtd_theme' 51 | 52 | # Add any paths that contain custom static files (such as style sheets) here, 53 | # relative to this directory. They are copied after the builtin static files, 54 | # so a file named "default.css" will overwrite the builtin "default.css". 55 | #html_static_path = ['_static'] 56 | html_static_path = [] -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. libgltf documentation master file, created by 2 | sphinx-quickstart on Mon Oct 12 18:56:34 2020. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to libgltf's documentation! 7 | =================================== 8 | 9 | |glTF 2.0| |docs| |bestpractices| |visit-milstones| 10 | 11 | |github-action| |coveralls| 12 | 13 | |codacy| |lgtm-alerts| |lgtm-grade| 14 | 15 | This project was generated by glTF 2.0 JSON schema and support to load the glTF 2.0 file to a struct `SGlTF`. 16 | 17 | It was used in glTFForUE4_. 18 | 19 | Features 20 | ========== 21 | 22 | * `glTF 2.0`_ 23 | * Load the gltf/embedded/glb file 24 | * This is a static library 25 | * Cross platform 26 | * C++17 27 | * Supports the Unicode and UTF8 28 | * Supports some extensions 29 | * `KHR_draco_mesh_compression` - `Google's Draco`_ 30 | * `KHR_lights_punctual` 31 | * `KHR_materials_clearcoat` 32 | * `KHR_materials_emissive_strength` 33 | * `KHR_materials_ior` 34 | * `KHR_materials_iridescence` 35 | * `KHR_materials_sheen` 36 | * `KHR_materials_specular` 37 | * `KHR_materials_transmission` 38 | * `KHR_materials_unlit` 39 | * `KHR_materials_variants` 40 | * `KHR_materials_volume` 41 | * `KHR_texture_transform` 42 | * `ADOBE_materials_thin_transparency` 43 | * `AGI_articulations` 44 | * `AGI_stk_metadata` 45 | * `CESIUM_primitive_outline` 46 | * `EXT_lights_ies` 47 | * `EXT_mesh_gpu_instancing` 48 | * `EXT_texture_webp` 49 | * `FB_geometry_metadata` 50 | * `MSFT_lod` 51 | * `MSFT_texture_dds` 52 | * Platforms 53 | * Windows 54 | * Win32 (win32) 55 | * x64 (win64) 56 | * Linux (linux) 57 | * macOS (macos) 58 | * Android 59 | * armeabi-v7a 60 | * armeabi-v7a-with-neon 61 | * arm64-v8a 62 | * x86 63 | * x86_64 64 | * iOS 65 | * iOS (iphoneos) 66 | * watchOS (watchos) 67 | * simulator 68 | 69 | Getting Started 70 | =============== 71 | 72 | #. Update the submodule 73 | 74 | Run :code:`git submodule update --init` 75 | 76 | #. Generate the project by [CMake] 77 | 78 | Run :code:`cmake -G "[GENERATOR BY YOUR SYSTEM]" [LIBGLTF FOLDER]` 79 | 80 | #. Build the project and generate the static library :code:`libgltf.(lib/a)` 81 | #. Include :code:`libgltf/libgltf.h` in your project. 82 | #. Link the static library :code:`libgltf.(lib/a)` in your project. 83 | 84 | You have to link the static library `draco.lib` or `draco.a` with your project, if you want to support the `Google's Draco`_. 85 | And you can find the draco in the external folder. 86 | 87 | Code example: 88 | 89 | .. code-block:: cpp 90 | 91 | std::shared_ptr gltf_loader = libgltf::IglTFLoader::Create(/*a function to load the file by std::istream*/); 92 | gltf_loader->Execute(); 93 | std::shared_ptr loaded_gltf = gltf_loader->glTF().lock(); 94 | if (!loaded_gltf) 95 | { 96 | printf("failed to load your gltf file"); 97 | } 98 | 99 | Usage 100 | ========== 101 | 102 | Generate the *makefile* or *ninja* or *visual c++ project* or *xcode project* by CMake_. 103 | 104 | It is a static library - :code:`libgltf.(lib/a)`. 105 | 106 | How to use 107 | ^^^^^^^^^^ 108 | 109 | Load the glTF file 110 | ------------------ 111 | 112 | You can load the glTF file by the function - :code:`libgltf::IglTFLoader::Create`, like this: 113 | 114 | .. code-block:: cpp 115 | 116 | std::shared_ptr gltf_loader = libgltf::IglTFLoader::Create( 117 | [](const std::string& _path) 118 | { 119 | std::filesystem::path file_path; 120 | if (_path.empty()) 121 | file_path = std::filesystem::path("Monster.gltf"); 122 | else 123 | file_path = std::filesystem::path("Monster.gltf").parent_path().append(_path); 124 | 125 | std::shared_ptr stream_ptr = nullptr; 126 | if (!std::filesystem::exists(file_path)) 127 | return stream_ptr; 128 | 129 | stream_ptr = std::make_shared(file_path.string(), std::ios::in | std::ios::binary); 130 | return stream_ptr; 131 | }); 132 | std::shared_ptr loaded_gltf = gltf_loader->glTF().lock(); 133 | if (!loaded_gltf) 134 | { 135 | // the glTF file is valid 136 | return false; 137 | } 138 | 139 | Load the mesh data 140 | ------------------ 141 | 142 | And get the mesh data, like this: 143 | 144 | .. code-block:: cpp 145 | 146 | // get all indices of the triangle 147 | libgltf::TVertexList<1, size_t> triangle_data; 148 | std::shared_ptr > > triangle_stream = std::make_shared > >(triangle_data); 149 | gltf_loader->LoadMeshPrimitiveIndicesData(0, 0, triangle_stream); 150 | 151 | // get all points of the triangle 152 | libgltf::TVertexList<3, float> position_data; 153 | std::shared_ptr > > position_stream = std::make_shared > >(position_data); 154 | gltf_loader->LoadMeshPrimitiveAttributeData(0, 0, L"position", position_stream); 155 | 156 | Load the image data 157 | ------------------- 158 | 159 | You can get the image (data and type) by `libgltf::IglTFLoader::LoadImageData`, like this: 160 | 161 | .. code-block:: cpp 162 | 163 | std::vector image0_data; 164 | libgltf::string_t image0_data_type; 165 | gltf_loader->LoadImageData(0, image0_data, image0_data_type); 166 | 167 | Advance 168 | ^^^^^^^^^^ 169 | 170 | Regenerate new code by the glTF schema 171 | -------------------------------------- 172 | 173 | Generate the c++11 code: 174 | 175 | * You can update the c++11 source code by :code:`jsonschematoc11`. 176 | * You need update and pull the submodule :code:`external/glTF` 177 | 178 | #. Run :code:`update_parser_by_scheme.bat` 179 | 180 | * For Windows: :code:`cd tools\batch\ && update_parser_by_scheme.bat && cd ..\..\ ` 181 | * For Linux/MacOS :code:`cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../` 182 | 183 | #. Build your version by CMake_. 184 | 185 | Supports Google's draco 186 | ----------------------- 187 | 188 | You can update Google's draco submodule in external/draco or pull the draco repo by yourself. 189 | 190 | Check the :code:`LIBGLTF_WITH_GOOGLE_DRACO` or set :code:`LIBGLTF_WITH_GOOGLE_DRACO` is `TRUE`. 191 | 192 | * Set the :code:`GOOGLE_DRACO_PATH_INCLUDE`, :code:`GOOGLE_DRACO_PATH_BUILD`, :code:`GOOGLE_DRACO_LIBRARY_DRACO_DEBUG`. 193 | * And compile with the submodule - *external/draco*. 194 | 195 | Download libraries 196 | ------------------ 197 | 198 | This project is compiled by GitHub action, and you can download the compiled library with `Google's Draco`_ from `the action page`_ or `the release page`_. 199 | 200 | In `the action page`_ or `the release page`_, libraries was compiled with `MultiThreading` (/MT or /MTd) for **windows**. 201 | 202 | Donation 203 | ============================================================== 204 | 205 | **Please consider donating to sustain my activities** 206 | 207 | |support-buy-a-cup-of-coffee| |donation-beome-a-patreon| 208 | 209 | License 210 | ========== 211 | 212 | `The MIT license`_. 213 | 214 | .. _`glTF 2.0`: https://www.khronos.org/gltf/ 215 | 216 | .. _glTFForUE4: https://github.com/code4game/glTFForUE4 217 | 218 | .. _`Google's Draco`: https://github.com/google/draco 219 | 220 | .. _CMake: https://cmake.org/ 221 | 222 | .. _Ninja: https://ninja-build.org 223 | 224 | .. _VisualStudio: https://visualstudio.microsoft.com 225 | 226 | .. _`the action page`: https://github.com/code4game/libgltf/actions 227 | 228 | .. _`the release page`: https://github.com/code4game/libgltf/releases 229 | 230 | .. _`The MIT license`: https://github.com/code4game/libgltf/LICENSE 231 | 232 | .. |glTF 2.0| image:: https://img.shields.io/badge/glTF-2%2E0-green.svg?style=flat 233 | :target: https://github.com/KhronosGroup/glTF 234 | 235 | .. |docs| image:: https://readthedocs.org/projects/libgltf/badge/?version=latest 236 | :target: http://libgltf.rtfd.io/ 237 | 238 | .. |bestpractices| image:: https://bestpractices.coreinfrastructure.org/projects/1434/badge 239 | :target: https://bestpractices.coreinfrastructure.org/projects/1434 240 | 241 | .. |visit-milstones| image:: https://img.shields.io/badge/visit-milestones-blue.svg?style=flat 242 | :target: https://github.com/code4game/libgltf/milestones 243 | 244 | .. |github-action| image:: https://github.com/code4game/libgltf/workflows/build/badge.svg 245 | :target: https://github.com/code4game/libgltf/actions?query=workflow%3Abuild 246 | 247 | .. |coveralls| image:: https://coveralls.io/repos/github/code4game/libgltf/badge.svg 248 | :target: https://coveralls.io/github/code4game/libgltf 249 | 250 | .. |codacy| image:: https://api.codacy.com/project/badge/Grade/fa7ee9a5bc9b4befb703298ca721bc9a 251 | :target: https://www.codacy.com/app/code4game/libgltf?utm_source=github.com&utm_medium=referral&utm_content=code4game/libgltf&utm_campaign=Badge_Grade 252 | 253 | .. |lgtm-alerts| image:: https://img.shields.io/lgtm/alerts/g/code4game/libgltf.svg?logo=lgtm&logoWidth=18 254 | :target: https://lgtm.com/projects/g/code4game/libgltf/alerts/ 255 | 256 | .. |lgtm-grade| image:: https://img.shields.io/lgtm/grade/python/g/code4game/libgltf.svg?logo=lgtm&logoWidth=18 257 | :target: https://lgtm.com/projects/g/code4game/libgltf/context:python 258 | 259 | 260 | .. |support-buy-a-cup-of-coffee| image:: https://img.shields.io/badge/support-buy%20a%20cup%20of%20coffee-orange.svg?style=flat 261 | :target: https://c4gio.itch.io/libgltf-ue4 262 | 263 | .. |donation-beome-a-patreon| image:: https://img.shields.io/badge/donation-become%20a%20patreon-orange.svg?style=flat 264 | :target: https://www.patreon.com/bePatron?u=7553208 265 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | breathe -------------------------------------------------------------------------------- /resource/2.0/Avocado/README.md: -------------------------------------------------------------------------------- 1 | # Avocado 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.jpg) 6 | 7 | ## License Information 8 | 9 | [![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/) 10 | To the extent possible under law, Microsoft has waived all copyright and related or neighboring rights to this asset. 11 | -------------------------------------------------------------------------------- /resource/2.0/Avocado/glTF-pbrSpecularGlossiness/Avocado.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/Avocado/glTF-pbrSpecularGlossiness/Avocado.bin -------------------------------------------------------------------------------- /resource/2.0/Avocado/glTF-pbrSpecularGlossiness/Avocado.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "accessors": [ 3 | { 4 | "bufferView": 0, 5 | "componentType": 5126, 6 | "count": 406, 7 | "type": "VEC2" 8 | }, 9 | { 10 | "bufferView": 1, 11 | "componentType": 5126, 12 | "count": 406, 13 | "type": "VEC3" 14 | }, 15 | { 16 | "bufferView": 2, 17 | "componentType": 5126, 18 | "count": 406, 19 | "type": "VEC4" 20 | }, 21 | { 22 | "bufferView": 3, 23 | "componentType": 5126, 24 | "count": 406, 25 | "type": "VEC3", 26 | "max": [ 27 | 0.02128091, 28 | 0.06284806, 29 | 0.0138090011 30 | ], 31 | "min": [ 32 | -0.02128091, 33 | -4.773855E-05, 34 | -0.013809 35 | ] 36 | }, 37 | { 38 | "bufferView": 4, 39 | "componentType": 5123, 40 | "count": 2046, 41 | "type": "SCALAR" 42 | } 43 | ], 44 | "asset": { 45 | "generator": "glTF Tools for Unity", 46 | "version": "2.0" 47 | }, 48 | "bufferViews": [ 49 | { 50 | "buffer": 0, 51 | "byteLength": 3248 52 | }, 53 | { 54 | "buffer": 0, 55 | "byteOffset": 3248, 56 | "byteLength": 4872 57 | }, 58 | { 59 | "buffer": 0, 60 | "byteOffset": 8120, 61 | "byteLength": 6496 62 | }, 63 | { 64 | "buffer": 0, 65 | "byteOffset": 14616, 66 | "byteLength": 4872 67 | }, 68 | { 69 | "buffer": 0, 70 | "byteOffset": 19488, 71 | "byteLength": 4092 72 | } 73 | ], 74 | "buffers": [ 75 | { 76 | "uri": "Avocado.bin", 77 | "byteLength": 23580 78 | } 79 | ], 80 | "extensionsUsed": [ 81 | "KHR_materials_pbrSpecularGlossiness" 82 | ], 83 | "images": [ 84 | { 85 | "uri": "Avocado_baseColor.png" 86 | }, 87 | { 88 | "uri": "Avocado_roughnessMetallic.png" 89 | }, 90 | { 91 | "uri": "Avocado_normal.png" 92 | }, 93 | { 94 | "uri": "Avocado_diffuse.png" 95 | }, 96 | { 97 | "uri": "Avocado_specularGlossiness.png" 98 | } 99 | ], 100 | "meshes": [ 101 | { 102 | "primitives": [ 103 | { 104 | "attributes": { 105 | "TEXCOORD_0": 0, 106 | "NORMAL": 1, 107 | "TANGENT": 2, 108 | "POSITION": 3 109 | }, 110 | "indices": 4, 111 | "material": 0 112 | } 113 | ], 114 | "name": "Avocado" 115 | } 116 | ], 117 | "materials": [ 118 | { 119 | "pbrMetallicRoughness": { 120 | "baseColorTexture": { 121 | "index": 0 122 | }, 123 | "metallicRoughnessTexture": { 124 | "index": 1 125 | } 126 | }, 127 | "normalTexture": { 128 | "index": 2 129 | }, 130 | "name": "2256_Avocado_d", 131 | "extensions": { 132 | "KHR_materials_pbrSpecularGlossiness": { 133 | "diffuseTexture": { 134 | "index": 3 135 | }, 136 | "specularGlossinessTexture": { 137 | "index": 4 138 | } 139 | } 140 | } 141 | } 142 | ], 143 | "nodes": [ 144 | { 145 | "mesh": 0, 146 | "rotation": [ 147 | 0.0, 148 | 1.0, 149 | 0.0, 150 | 0.0 151 | ], 152 | "name": "Avocado" 153 | } 154 | ], 155 | "scene": 0, 156 | "scenes": [ 157 | { 158 | "nodes": [ 159 | 0 160 | ] 161 | } 162 | ], 163 | "textures": [ 164 | { 165 | "source": 0 166 | }, 167 | { 168 | "source": 1 169 | }, 170 | { 171 | "source": 2 172 | }, 173 | { 174 | "source": 3 175 | }, 176 | { 177 | "source": 4 178 | } 179 | ] 180 | } -------------------------------------------------------------------------------- /resource/2.0/Cameras/README.md: -------------------------------------------------------------------------------- 1 | # Cameras 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.png) 6 | 7 | ## License Information 8 | 9 | Public domain ([CC0](https://creativecommons.org/publicdomain/zero/1.0/)) 10 | 11 | ## Data layout 12 | 13 | The following image shows the data layout of this sample: 14 | 15 | ![simpleSquare](screenshot/simpleSquare.png) 16 | 17 | -------------------------------------------------------------------------------- /resource/2.0/Cameras/glTF/Cameras.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "scenes" : [ 3 | { 4 | "nodes" : [ 0, 1, 2 ] 5 | } 6 | ], 7 | "nodes" : [ 8 | { 9 | "rotation" : [ -0.383, 0.0, 0.0, 0.92375 ], 10 | "mesh" : 0 11 | }, 12 | { 13 | "translation" : [ 0.5, 0.5, 3.0 ], 14 | "camera" : 0 15 | }, 16 | { 17 | "translation" : [ 0.5, 0.5, 3.0 ], 18 | "camera" : 1 19 | } 20 | ], 21 | 22 | "cameras" : [ 23 | { 24 | "type": "perspective", 25 | "perspective": { 26 | "aspectRatio": 1.0, 27 | "yfov": 0.7, 28 | "zfar": 100, 29 | "znear": 0.01 30 | } 31 | }, 32 | { 33 | "type": "orthographic", 34 | "orthographic": { 35 | "xmag": 1.0, 36 | "ymag": 1.0, 37 | "zfar": 100, 38 | "znear": 0.01 39 | } 40 | } 41 | ], 42 | 43 | "meshes" : [ 44 | { 45 | "primitives" : [ { 46 | "attributes" : { 47 | "POSITION" : 1 48 | }, 49 | "indices" : 0 50 | } ] 51 | } 52 | ], 53 | 54 | "buffers" : [ 55 | { 56 | "uri" : "simpleSquare.bin", 57 | "byteLength" : 60 58 | } 59 | ], 60 | "bufferViews" : [ 61 | { 62 | "buffer" : 0, 63 | "byteOffset" : 0, 64 | "byteLength" : 12, 65 | "target" : 34963 66 | }, 67 | { 68 | "buffer" : 0, 69 | "byteOffset" : 12, 70 | "byteLength" : 48, 71 | "target" : 34962 72 | } 73 | ], 74 | "accessors" : [ 75 | { 76 | "bufferView" : 0, 77 | "byteOffset" : 0, 78 | "componentType" : 5123, 79 | "count" : 6, 80 | "type" : "SCALAR", 81 | "max" : [ 3 ], 82 | "min" : [ 0 ] 83 | }, 84 | { 85 | "bufferView" : 1, 86 | "byteOffset" : 0, 87 | "componentType" : 5126, 88 | "count" : 4, 89 | "type" : "VEC3", 90 | "max" : [ 1.0, 1.0, 0.0 ], 91 | "min" : [ 0.0, 0.0, 0.0 ] 92 | } 93 | ], 94 | 95 | "asset" : { 96 | "version" : "2.0" 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /resource/2.0/Cameras/glTF/simpleSquare.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/Cameras/glTF/simpleSquare.bin -------------------------------------------------------------------------------- /resource/2.0/EnvironmentTest/README.md: -------------------------------------------------------------------------------- 1 | # Environment Test 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.png) 6 | 7 | ## License Information 8 | 9 | https://stock.adobe.com/license-terms?prev_url=detail&comparison-full#enhanced-license-terms 10 | 11 | ## Original Asset 12 | 13 | https://stock.adobe.com/search/3d-assets?filters%5Bcontent_type%3A3d%5D=1&filters%5B3d_type_id%5D%5B%5D=2&order=relevance&safe_search=1&search_page=1&limit=100&acp=&aco=canyon&price%5B%24%5D=1&get_facets=1&asset_id=122687900 -------------------------------------------------------------------------------- /resource/2.0/EnvironmentTest/glTF-IBL/EnvironmentTest_binary.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/EnvironmentTest/glTF-IBL/EnvironmentTest_binary.bin -------------------------------------------------------------------------------- /resource/2.0/EnvironmentTest/glTF/EnvironmentTest.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "asset": { 3 | "copyright": "2018 (c) Adobe Systems Inc.", 4 | "generator": "Adobe Dimension - b417c10282aa66313155856d4a54e84f3f388647", 5 | "version": "2.0" 6 | }, 7 | "accessors": [ 8 | { 9 | "bufferView": 0, 10 | "componentType": 5126, 11 | "count": 4598, 12 | "type": "VEC3", 13 | "max": [ 14 | 10.647041320800782, 15 | 1.6470409631729127, 16 | 0.6470409631729126 17 | ], 18 | "min": [ 19 | -10.647041320800782, 20 | 0.3529590368270874, 21 | -0.6470409631729126 22 | ] 23 | }, 24 | { 25 | "bufferView": 1, 26 | "componentType": 5126, 27 | "count": 4598, 28 | "type": "VEC3" 29 | }, 30 | { 31 | "bufferView": 2, 32 | "componentType": 5126, 33 | "count": 4598, 34 | "type": "VEC2" 35 | }, 36 | { 37 | "bufferView": 3, 38 | "componentType": 5125, 39 | "count": 25344, 40 | "type": "SCALAR", 41 | "max": [ 42 | 4597.0 43 | ], 44 | "min": [ 45 | 0.0 46 | ] 47 | }, 48 | { 49 | "bufferView": 4, 50 | "componentType": 5126, 51 | "count": 4598, 52 | "type": "VEC3", 53 | "max": [ 54 | 10.647041320800782, 55 | -0.3529590368270874, 56 | 0.6470409631729126 57 | ], 58 | "min": [ 59 | -10.647041320800782, 60 | -1.6470409631729127, 61 | -0.6470409631729126 62 | ] 63 | }, 64 | { 65 | "bufferView": 5, 66 | "componentType": 5126, 67 | "count": 4598, 68 | "type": "VEC2" 69 | } 70 | ], 71 | "bufferViews": [ 72 | { 73 | "buffer": 0, 74 | "byteOffset": 0, 75 | "byteLength": 55176, 76 | "target": 34962 77 | }, 78 | { 79 | "buffer": 0, 80 | "byteOffset": 55176, 81 | "byteLength": 55176, 82 | "target": 34962 83 | }, 84 | { 85 | "buffer": 0, 86 | "byteOffset": 110352, 87 | "byteLength": 36784, 88 | "target": 34962 89 | }, 90 | { 91 | "buffer": 0, 92 | "byteOffset": 147136, 93 | "byteLength": 101376, 94 | "target": 34963 95 | }, 96 | { 97 | "buffer": 0, 98 | "byteOffset": 248512, 99 | "byteLength": 55176, 100 | "target": 34962 101 | }, 102 | { 103 | "buffer": 0, 104 | "byteOffset": 303688, 105 | "byteLength": 36784, 106 | "target": 34962 107 | } 108 | ], 109 | "buffers": [ 110 | { 111 | "byteLength": 340472, 112 | "uri": "EnvironmentTest_binary.bin" 113 | } 114 | ], 115 | "cameras": [ 116 | { 117 | "perspective": { 118 | "znear": 0.0010000000474974514, 119 | "yfov": 0.6024156808853149, 120 | "zfar": 200.0, 121 | "aspectRatio": 1.3333333730697632 122 | }, 123 | "type": "perspective", 124 | "name": "render_camera" 125 | } 126 | ], 127 | "images": [ 128 | { 129 | "name": "tmp_image_pie_dc1e_1a22_fbf9roughness_map_roughness_tmp_image_pie_dc1e_1a22_fbf9metal_map_metallic_0", 130 | "uri": "EnvironmentTest_images/roughness_metallic_0.jpg", 131 | "mimeType": "image/jpeg" 132 | }, 133 | { 134 | "name": "tmp_image_pie_b20b_ebb4_317droughness_map2_roughness_tmp_image_pie_b20b_ebb4_317dmetal_map2_metallic_1", 135 | "uri": "EnvironmentTest_images/roughness_metallic_1.jpg", 136 | "mimeType": "image/jpeg" 137 | } 138 | ], 139 | "materials": [ 140 | { 141 | "pbrMetallicRoughness": { 142 | "metallicRoughnessTexture": { 143 | "index": 0 144 | } 145 | }, 146 | "name": "MetallicSpheresMat", 147 | "doubleSided": true 148 | }, 149 | { 150 | "pbrMetallicRoughness": { 151 | "metallicRoughnessTexture": { 152 | "index": 1 153 | } 154 | }, 155 | "name": "DielectricSpheresMat", 156 | "doubleSided": true 157 | }, 158 | { 159 | "pbrMetallicRoughness": { 160 | "baseColorFactor": [ 161 | 0.0, 162 | 0.0, 163 | 0.0, 164 | 1.0 165 | ], 166 | "metallicRoughnessTexture": { 167 | "index": 1 168 | } 169 | }, 170 | "name": "DielectricSpheresMat", 171 | "doubleSided": true 172 | } 173 | ], 174 | "meshes": [ 175 | { 176 | "name": "Metallic0_N3D", 177 | "primitives": [ 178 | { 179 | "attributes": { 180 | "POSITION": 0, 181 | "NORMAL": 1, 182 | "TEXCOORD_0": 2 183 | }, 184 | "indices": 3, 185 | "material": 0 186 | } 187 | ] 188 | }, 189 | { 190 | "name": "Dielectric0_N3D2", 191 | "primitives": [ 192 | { 193 | "attributes": { 194 | "TEXCOORD_0": 5, 195 | "NORMAL": 1, 196 | "POSITION": 4 197 | }, 198 | "indices": 3, 199 | "material": 1 200 | } 201 | ] 202 | }, 203 | { 204 | "name": "Dielectric0_N3D", 205 | "primitives": [ 206 | { 207 | "attributes": { 208 | "POSITION": 4, 209 | "NORMAL": 1, 210 | "TEXCOORD_0": 5 211 | }, 212 | "indices": 3, 213 | "material": 2 214 | } 215 | ] 216 | } 217 | ], 218 | "nodes": [ 219 | { 220 | "matrix": [ 221 | 0.9999533295631409, 222 | 3.16067598760128e-8, 223 | 0.009662099182605744, 224 | 0.0, 225 | 0.0014864075928926468, 226 | 0.9880954027175903, 227 | -0.15383504331111909, 228 | 0.0, 229 | -0.009547080844640732, 230 | 0.15384222567081452, 231 | 0.988049328327179, 232 | 0.0, 233 | -0.7599077224731445, 234 | 7.708760738372803, 235 | 27.743375778198243, 236 | 1.0 237 | ], 238 | "camera": 0, 239 | "name": "render_camera_n3d" 240 | }, 241 | { 242 | "name": "ground_plane_n3d" 243 | }, 244 | { 245 | "children": [ 246 | 3, 247 | 4, 248 | 5 249 | ], 250 | "matrix": [ 251 | 1.0, 252 | 0.0, 253 | 0.0, 254 | 0.0, 255 | 0.0, 256 | 1.0, 257 | 0.0, 258 | 0.0, 259 | 0.0, 260 | 0.0, 261 | 1.0, 262 | 0.0, 263 | -0.5564079284667969, 264 | 4.774584770202637, 265 | -1.0962677001953126, 266 | 1.0 267 | ], 268 | "name": "ENV_Spheres" 269 | }, 270 | { 271 | "mesh": 0, 272 | "name": "Metallic0" 273 | }, 274 | { 275 | "mesh": 1, 276 | "name": "Dielectric0" 277 | }, 278 | { 279 | "matrix": [ 280 | 1.0, 281 | 0.0, 282 | 0.0, 283 | 0.0, 284 | 0.0, 285 | 1.0, 286 | 0.0, 287 | 0.0, 288 | 0.0, 289 | 0.0, 290 | 1.0, 291 | 0.0, 292 | 0.0, 293 | -1.985867977142334, 294 | 0.0, 295 | 1.0 296 | ], 297 | "mesh": 2, 298 | "name": "Dielectric0-Black" 299 | } 300 | ], 301 | "samplers": [ 302 | {}, 303 | {} 304 | ], 305 | "scenes": [ 306 | { 307 | "nodes": [ 308 | 0, 309 | 1, 310 | 2 311 | ], 312 | "name": "scene" 313 | } 314 | ], 315 | "textures": [ 316 | { 317 | "name": "tmp_image_pie_dc1e_1a22_fbf9roughness_map_roughness_tmp_image_pie_dc1e_1a22_fbf9metal_map_metallic_0_texture", 318 | "sampler": 0, 319 | "source": 0 320 | }, 321 | { 322 | "name": "tmp_image_pie_b20b_ebb4_317droughness_map2_roughness_tmp_image_pie_b20b_ebb4_317dmetal_map2_metallic_1_texture", 323 | "sampler": 1, 324 | "source": 1 325 | } 326 | ], 327 | "scene": 0 328 | } -------------------------------------------------------------------------------- /resource/2.0/EnvironmentTest/glTF/EnvironmentTest_binary.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/EnvironmentTest/glTF/EnvironmentTest_binary.bin -------------------------------------------------------------------------------- /resource/2.0/MaterialsVariantsShoe/README.md: -------------------------------------------------------------------------------- 1 | # Materials Variants Shoe 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot-large.png) 6 | 7 | ## Description 8 | 9 | This model uses the KHR_materials_variants extension. It is a shoe with 3 color variants in it: "Beach", "Midnight", and "Street". 10 | 11 | If each variant was a separate model, they would be 5.4 MB each. Combined they make up a single model that is 7.8MB since they share geometry and all textures except the base color texture. 12 | 13 | ## License Information 14 | Copyright 2020 Shopify, Inc. 15 | CC BY 4.0 https://creativecommons.org/licenses/by/4.0/ 16 | -------------------------------------------------------------------------------- /resource/2.0/MaterialsVariantsShoe/glTF/MaterialsVariantsShoe.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/MaterialsVariantsShoe/glTF/MaterialsVariantsShoe.bin -------------------------------------------------------------------------------- /resource/2.0/MaterialsVariantsShoe/glTF/MaterialsVariantsShoe.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "accessors": [ 3 | { 4 | "bufferView": 0, 5 | "byteOffset": 0, 6 | "count": 13540, 7 | "componentType": 5126, 8 | "type": "VEC3", 9 | "min": [ 10 | -0.999970018863678, 11 | -1, 12 | -0.9999949932098388 13 | ], 14 | "max": [ 15 | 0.999809980392456, 16 | 0.9999020099639891, 17 | 0.9999240040779114 18 | ] 19 | }, 20 | { 21 | "bufferView": 1, 22 | "byteOffset": 0, 23 | "count": 13540, 24 | "componentType": 5126, 25 | "type": "VEC3", 26 | "min": [ 27 | -1, 28 | -0.5139704942703247, 29 | -0.38874176144599915 30 | ], 31 | "max": [ 32 | 1.0000001192092896, 33 | 0.5139704942703247, 34 | 0.38874176144599915 35 | ] 36 | }, 37 | { 38 | "bufferView": 2, 39 | "byteOffset": 0, 40 | "count": 13540, 41 | "componentType": 5126, 42 | "type": "VEC2", 43 | "min": [ 44 | 0.001952999969944358, 45 | 0.03520399332046509 46 | ], 47 | "max": [ 48 | 0.9980469942092896, 49 | 0.9980469942092896 50 | ] 51 | }, 52 | { 53 | "bufferView": 3, 54 | "byteOffset": 0, 55 | "count": 68100, 56 | "componentType": 5125, 57 | "type": "SCALAR", 58 | "min": [ 59 | 0 60 | ], 61 | "max": [ 62 | 13539 63 | ] 64 | } 65 | ], 66 | "asset": { 67 | "generator": "THREE.GLTFExporter", 68 | "version": "2.0" 69 | }, 70 | "buffers": [ 71 | { 72 | "name": "shoes-processed", 73 | "byteLength": 705680, 74 | "uri": "MaterialsVariantsShoe.bin" 75 | } 76 | ], 77 | "bufferViews": [ 78 | { 79 | "buffer": 0, 80 | "byteLength": 162480, 81 | "byteOffset": 0, 82 | "byteStride": 12, 83 | "target": 34962 84 | }, 85 | { 86 | "buffer": 0, 87 | "byteLength": 162480, 88 | "byteOffset": 162480, 89 | "byteStride": 12, 90 | "target": 34962 91 | }, 92 | { 93 | "buffer": 0, 94 | "byteLength": 108320, 95 | "byteOffset": 324960, 96 | "byteStride": 8, 97 | "target": 34962 98 | }, 99 | { 100 | "buffer": 0, 101 | "byteLength": 272400, 102 | "byteOffset": 433280, 103 | "target": 34963 104 | } 105 | ], 106 | "scene": 0, 107 | "extensions": { 108 | "KHR_materials_variants": { 109 | "variants": [ 110 | {"name": "midnight"}, 111 | {"name": "beach" }, 112 | {"name": "street" } 113 | ] 114 | } 115 | }, 116 | "extensionsUsed": [ 117 | "KHR_materials_variants" 118 | ], 119 | "images": [ 120 | { 121 | "mimeType": "image/jpeg", 122 | "uri": "occlusionRougnessMetalness.jpg" 123 | }, 124 | { 125 | "mimeType": "image/jpeg", 126 | "uri": "diffuseMidnight.jpg" 127 | }, 128 | { 129 | "mimeType": "image/jpeg", 130 | "uri": "normal.jpg" 131 | }, 132 | { 133 | "mimeType": "image/jpeg", 134 | "uri": "diffuseBeach.jpg" 135 | }, 136 | { 137 | "mimeType": "image/jpeg", 138 | "uri": "diffuseStreet.jpg" 139 | } 140 | ], 141 | "materials": [ 142 | { 143 | "alphaMode": "OPAQUE", 144 | "doubleSided": false, 145 | "name": "phong1SG", 146 | "pbrMetallicRoughness": { 147 | "baseColorFactor": [ 148 | 1, 149 | 1, 150 | 1, 151 | 1 152 | ], 153 | "baseColorTexture": { 154 | "index": 1, 155 | "texCoord": 0 156 | }, 157 | "metallicFactor": 1, 158 | "roughnessFactor": 1, 159 | "metallicRoughnessTexture": { 160 | "index": 0, 161 | "texCoord": 0 162 | } 163 | }, 164 | "normalTexture": { 165 | "index": 2, 166 | "scale": 1, 167 | "texCoord": 0 168 | }, 169 | "occlusionTexture": { 170 | "index": 0, 171 | "strength": 1, 172 | "texCoord": 0 173 | }, 174 | "emissiveFactor": [ 175 | 0, 176 | 0, 177 | 0 178 | ] 179 | }, 180 | { 181 | "alphaMode": "OPAQUE", 182 | "doubleSided": false, 183 | "name": "phong1SG", 184 | "pbrMetallicRoughness": { 185 | "baseColorFactor": [ 186 | 1, 187 | 1, 188 | 1, 189 | 1 190 | ], 191 | "baseColorTexture": { 192 | "index": 3, 193 | "texCoord": 0 194 | }, 195 | "metallicFactor": 1, 196 | "roughnessFactor": 1, 197 | "metallicRoughnessTexture": { 198 | "index": 0, 199 | "texCoord": 0 200 | } 201 | }, 202 | "normalTexture": { 203 | "index": 2, 204 | "scale": 1, 205 | "texCoord": 0 206 | }, 207 | "occlusionTexture": { 208 | "index": 0, 209 | "strength": 1, 210 | "texCoord": 0 211 | }, 212 | "emissiveFactor": [ 213 | 0, 214 | 0, 215 | 0 216 | ] 217 | }, 218 | { 219 | "alphaMode": "OPAQUE", 220 | "doubleSided": false, 221 | "name": "phong1SG", 222 | "pbrMetallicRoughness": { 223 | "baseColorFactor": [ 224 | 1, 225 | 1, 226 | 1, 227 | 1 228 | ], 229 | "baseColorTexture": { 230 | "index": 4, 231 | "texCoord": 0 232 | }, 233 | "metallicFactor": 1, 234 | "roughnessFactor": 1, 235 | "metallicRoughnessTexture": { 236 | "index": 0, 237 | "texCoord": 0 238 | } 239 | }, 240 | "normalTexture": { 241 | "index": 2, 242 | "scale": 1, 243 | "texCoord": 0 244 | }, 245 | "occlusionTexture": { 246 | "index": 0, 247 | "strength": 1, 248 | "texCoord": 0 249 | }, 250 | "emissiveFactor": [ 251 | 0, 252 | 0, 253 | 0 254 | ] 255 | } 256 | ], 257 | "meshes": [ 258 | { 259 | "name": "shoe", 260 | "primitives": [ 261 | { 262 | "attributes": { 263 | "NORMAL": 0, 264 | "POSITION": 1, 265 | "TEXCOORD_0": 2 266 | }, 267 | "extensions": { 268 | "KHR_materials_variants": { 269 | "mappings": [ 270 | { 271 | "material": 0, 272 | "variants": [ 273 | 0 274 | ] 275 | }, 276 | { 277 | "material": 1, 278 | "variants": [ 279 | 1 280 | ] 281 | }, 282 | { 283 | "material": 2, 284 | "variants": [ 285 | 2 286 | ] 287 | } 288 | ] 289 | } 290 | }, 291 | "indices": 3, 292 | "material": 0, 293 | "mode": 4 294 | } 295 | ] 296 | } 297 | ], 298 | "nodes": [ 299 | { 300 | "extras": { 301 | "name": "Shoe" 302 | }, 303 | "mesh": 0, 304 | "name": "Shoe" 305 | }, 306 | { 307 | "children": [ 308 | 0 309 | ], 310 | "extras": { 311 | "name": "g Shoe" 312 | }, 313 | "name": "g_Shoe" 314 | }, 315 | { 316 | "children": [ 317 | 1 318 | ], 319 | "extras": { 320 | "name": "Shoe.obj" 321 | }, 322 | "matrix": [ 323 | 0.14893949, 324 | 0, 325 | 0, 326 | 0, 327 | 0, 328 | 0.14893949, 329 | 0, 330 | 0, 331 | 0, 332 | 0, 333 | 0.14893949, 334 | 0, 335 | 0.0016104877, 336 | 0.07590251, 337 | 0.0048509985, 338 | 1 339 | ], 340 | "name": "Shoeobj" 341 | } 342 | ], 343 | "samplers": [ 344 | { 345 | "magFilter": 9729, 346 | "minFilter": 9985, 347 | "wrapS": 10497, 348 | "wrapT": 10497 349 | }, 350 | { 351 | "magFilter": 9729, 352 | "minFilter": 9985, 353 | "wrapS": 10497, 354 | "wrapT": 10497 355 | }, 356 | { 357 | "magFilter": 9729, 358 | "minFilter": 9985, 359 | "wrapS": 10497, 360 | "wrapT": 10497 361 | } 362 | ], 363 | "scenes": [ 364 | { 365 | "name": "Scene", 366 | "nodes": [ 367 | 2 368 | ] 369 | } 370 | ], 371 | "textures": [ 372 | { 373 | "sampler": 0, 374 | "source": 0 375 | }, 376 | { 377 | "sampler": 1, 378 | "source": 1 379 | }, 380 | { 381 | "sampler": 2, 382 | "source": 2 383 | }, 384 | { 385 | "sampler": 0, 386 | "source": 3 387 | }, 388 | { 389 | "sampler": 0, 390 | "source": 4 391 | } 392 | ] 393 | } 394 | -------------------------------------------------------------------------------- /resource/2.0/MetalRoughSpheres/README.md: -------------------------------------------------------------------------------- 1 | # Metal-Rough Spheres 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.png) 6 | 7 | ## License Information 8 | 9 | Copyright 2017 Analytical Graphics, Inc. 10 | CC-BY 4.0 https://creativecommons.org/licenses/by/4.0/ 11 | Model and textures by Ed Mackey. 12 | -------------------------------------------------------------------------------- /resource/2.0/MetalRoughSpheres/glTF/MetalRoughSpheres0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/MetalRoughSpheres/glTF/MetalRoughSpheres0.bin -------------------------------------------------------------------------------- /resource/2.0/Monster/README.md: -------------------------------------------------------------------------------- 1 | # Monster 2 | ## Screenshot 3 | 4 | ![screenshot](screenshot/screenshot.gif) 5 | 6 | ## License Information 7 | 8 | Model from: http://www.3drt.com/downloads.htm 9 | -------------------------------------------------------------------------------- /resource/2.0/Monster/glTF-Binary/Monster.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/Monster/glTF-Binary/Monster.glb -------------------------------------------------------------------------------- /resource/2.0/Monster/glTF-Draco/0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/Monster/glTF-Draco/0.bin -------------------------------------------------------------------------------- /resource/2.0/Monster/glTF/Monster0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/Monster/glTF/Monster0.bin -------------------------------------------------------------------------------- /resource/2.0/Monster/screenshot/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/Monster/screenshot/screenshot.gif -------------------------------------------------------------------------------- /resource/2.0/MorphPrimitivesTest/README.md: -------------------------------------------------------------------------------- 1 | # Morph-Primitives Test 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.jpg) 6 | 7 | ## Description 8 | 9 | This model contains a simple mesh with two primitives: A larger red primitive displays a grid covering 3 of the 4 quadrants of the model's area, followed by a smaller green primitive covering the last quadrant. 10 | 11 | Each primitive has a morph target that creates an elevated area within these quadrants. The model's only mesh contains a `weights: [0.5]` instruction that should cause these morph targets to be applied at half strength, raising the center of the model as shown in the screenshot above. 12 | 13 | ## Common Problems 14 | 15 | If the entire model appears perfectly flat, it is likely that the morph targets have not been applied as requested. 16 | 17 | If the red area or green area is missing, particularly in the Draco-compressed version of this model, it could indicate a problem with decompression or with support of multiple primitives within a single mesh. 18 | 19 | ## License Information 20 | 21 | Model by [@ft-lab](https://github.com/ft-lab). 22 | 23 | CC-BY 4.0 https://creativecommons.org/licenses/by/4.0/ 24 | -------------------------------------------------------------------------------- /resource/2.0/MorphPrimitivesTest/glTF/MorphPrimitivesTest.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/MorphPrimitivesTest/glTF/MorphPrimitivesTest.bin -------------------------------------------------------------------------------- /resource/2.0/MorphPrimitivesTest/glTF/MorphPrimitivesTest.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "asset": { 3 | "generator": "glTF Converter for Shade3D", 4 | "version": "2.0", 5 | "extras": { 6 | "title": "multiple_primitives", 7 | "author": "ft-lab", 8 | "license": "CC BY-4.0 (https://creativecommons.org/licenses/by/4.0/)" 9 | } 10 | }, 11 | "accessors": [ 12 | { 13 | "bufferView": 0, 14 | "componentType": 5123, 15 | "count": 72, 16 | "type": "SCALAR", 17 | "byteOffset": 0 18 | }, 19 | { 20 | "bufferView": 1, 21 | "componentType": 5126, 22 | "count": 21, 23 | "type": "VEC3", 24 | "byteOffset": 0 25 | }, 26 | { 27 | "bufferView": 2, 28 | "componentType": 5126, 29 | "count": 21, 30 | "type": "VEC3", 31 | "max": [ 32 | 0.5, 33 | 0, 34 | 0.5 35 | ], 36 | "min": [ 37 | -0.5, 38 | 0, 39 | -0.5 40 | ], 41 | "byteOffset": 0 42 | }, 43 | { 44 | "bufferView": 3, 45 | "componentType": 5126, 46 | "count": 21, 47 | "type": "VEC2", 48 | "byteOffset": 0 49 | }, 50 | { 51 | "bufferView": 4, 52 | "componentType": 5126, 53 | "count": 21, 54 | "type": "VEC3", 55 | "max": [ 56 | 0, 57 | 0.20000000298023224, 58 | 0 59 | ], 60 | "min": [ 61 | 0, 62 | 0, 63 | 0 64 | ], 65 | "byteOffset": 0 66 | }, 67 | { 68 | "bufferView": 5, 69 | "componentType": 5123, 70 | "count": 24, 71 | "type": "SCALAR", 72 | "byteOffset": 0 73 | }, 74 | { 75 | "bufferView": 6, 76 | "componentType": 5126, 77 | "count": 9, 78 | "type": "VEC3", 79 | "byteOffset": 0 80 | }, 81 | { 82 | "bufferView": 7, 83 | "componentType": 5126, 84 | "count": 9, 85 | "type": "VEC3", 86 | "max": [ 87 | 0.5, 88 | 0, 89 | 0 90 | ], 91 | "min": [ 92 | 0, 93 | 0, 94 | -0.5 95 | ], 96 | "byteOffset": 0 97 | }, 98 | { 99 | "bufferView": 8, 100 | "componentType": 5126, 101 | "count": 9, 102 | "type": "VEC2", 103 | "byteOffset": 0 104 | }, 105 | { 106 | "bufferView": 9, 107 | "componentType": 5126, 108 | "count": 9, 109 | "type": "VEC3", 110 | "max": [ 111 | 0, 112 | 0.20000000298023224, 113 | 0 114 | ], 115 | "min": [ 116 | 0, 117 | 0, 118 | 0 119 | ], 120 | "byteOffset": 0 121 | } 122 | ], 123 | "bufferViews": [ 124 | { 125 | "buffer": 0, 126 | "byteOffset": 0, 127 | "byteLength": 144, 128 | "target": 34963 129 | }, 130 | { 131 | "buffer": 0, 132 | "byteOffset": 144, 133 | "byteLength": 252, 134 | "target": 34962, 135 | "byteStride": 12 136 | }, 137 | { 138 | "buffer": 0, 139 | "byteOffset": 396, 140 | "byteLength": 252, 141 | "target": 34962, 142 | "byteStride": 12 143 | }, 144 | { 145 | "buffer": 0, 146 | "byteOffset": 648, 147 | "byteLength": 168, 148 | "target": 34962, 149 | "byteStride": 8 150 | }, 151 | { 152 | "buffer": 0, 153 | "byteOffset": 816, 154 | "byteLength": 252, 155 | "target": 34962, 156 | "byteStride": 12 157 | }, 158 | { 159 | "buffer": 0, 160 | "byteOffset": 1068, 161 | "byteLength": 48, 162 | "target": 34963 163 | }, 164 | { 165 | "buffer": 0, 166 | "byteOffset": 1116, 167 | "byteLength": 108, 168 | "target": 34962, 169 | "byteStride": 12 170 | }, 171 | { 172 | "buffer": 0, 173 | "byteOffset": 1224, 174 | "byteLength": 108, 175 | "target": 34962, 176 | "byteStride": 12 177 | }, 178 | { 179 | "buffer": 0, 180 | "byteOffset": 1332, 181 | "byteLength": 72, 182 | "target": 34962, 183 | "byteStride": 8 184 | }, 185 | { 186 | "buffer": 0, 187 | "byteOffset": 1404, 188 | "byteLength": 108, 189 | "target": 34962, 190 | "byteStride": 12 191 | } 192 | ], 193 | "buffers": [ 194 | { 195 | "name": "MorphPrimitivesTest", 196 | "byteLength": 1512, 197 | "uri": "MorphPrimitivesTest.bin" 198 | } 199 | ], 200 | "images": [ 201 | { 202 | "name": "uv_texture.jpg", 203 | "mimeType": "image/jpeg", 204 | "uri": "uv_texture.jpg" 205 | } 206 | ], 207 | "materials": [ 208 | { 209 | "pbrMetallicRoughness": { 210 | "baseColorFactor": [ 211 | 1, 212 | 0, 213 | 0, 214 | 1 215 | ], 216 | "baseColorTexture": { 217 | "index": 0, 218 | "texCoord": 0 219 | }, 220 | "metallicFactor": 0, 221 | "roughnessFactor": 1 222 | }, 223 | "name": "red", 224 | "emissiveFactor": [ 225 | 0, 226 | 0, 227 | 0 228 | ], 229 | "alphaMode": "OPAQUE", 230 | "doubleSided": false 231 | }, 232 | { 233 | "pbrMetallicRoughness": { 234 | "baseColorFactor": [ 235 | 0, 236 | 1, 237 | 0, 238 | 1 239 | ], 240 | "baseColorTexture": { 241 | "index": 0, 242 | "texCoord": 0 243 | }, 244 | "metallicFactor": 0, 245 | "roughnessFactor": 1 246 | }, 247 | "name": "green", 248 | "emissiveFactor": [ 249 | 0, 250 | 0, 251 | 0 252 | ], 253 | "alphaMode": "OPAQUE", 254 | "doubleSided": false 255 | } 256 | ], 257 | "meshes": [ 258 | { 259 | "weights": [ 260 | 0.5 261 | ], 262 | "name": "mesh", 263 | "primitives": [ 264 | { 265 | "attributes": { 266 | "NORMAL": 1, 267 | "POSITION": 2, 268 | "TEXCOORD_0": 3 269 | }, 270 | "indices": 0, 271 | "material": 0, 272 | "targets": [ 273 | { 274 | "POSITION": 4 275 | } 276 | ], 277 | "mode": 4 278 | }, 279 | { 280 | "attributes": { 281 | "POSITION": 7, 282 | "NORMAL": 6, 283 | "TEXCOORD_0": 8 284 | }, 285 | "indices": 5, 286 | "material": 1, 287 | "targets": [ 288 | { 289 | "POSITION": 9 290 | } 291 | ], 292 | "mode": 4 293 | } 294 | ] 295 | } 296 | ], 297 | "nodes": [ 298 | { 299 | "children": [ 300 | 1 301 | ], 302 | "name": "ルートパート" 303 | }, 304 | { 305 | "mesh": 0, 306 | "name": "mesh" 307 | } 308 | ], 309 | "samplers": [ 310 | { 311 | "minFilter": 9729, 312 | "wrapS": 10497, 313 | "wrapT": 10497 314 | } 315 | ], 316 | "scenes": [ 317 | { 318 | "nodes": [ 319 | 0 320 | ], 321 | "name": "Scene" 322 | } 323 | ], 324 | "textures": [ 325 | { 326 | "sampler": 0, 327 | "source": 0 328 | } 329 | ], 330 | "scene": 0 331 | } 332 | -------------------------------------------------------------------------------- /resource/2.0/MultiUVTest/README.md: -------------------------------------------------------------------------------- 1 | # MultiUV Test 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.jpg) 6 | 7 | ## Description 8 | 9 | This model has two uv texture coordinates. 10 | 11 | ## License Information 12 | 13 | Donated by [Hilo3d](https://github.com/hiloteam/Hilo3d) for glTF testing. 14 | 15 | This model is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/). 16 | -------------------------------------------------------------------------------- /resource/2.0/MultiUVTest/glTF/MultiUVTest.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/MultiUVTest/glTF/MultiUVTest.bin -------------------------------------------------------------------------------- /resource/2.0/MultiUVTest/glTF/MultiUVTest.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "accessors" : [ 3 | { 4 | "bufferView" : 0, 5 | "componentType" : 5121, 6 | "count" : 36, 7 | "max" : [ 8 | 23 9 | ], 10 | "min" : [ 11 | 0 12 | ], 13 | "type" : "SCALAR" 14 | }, 15 | { 16 | "bufferView" : 1, 17 | "componentType" : 5126, 18 | "count" : 24, 19 | "max" : [ 20 | 1.0000004768371582, 21 | 1.0, 22 | 1.0000005960464478 23 | ], 24 | "min" : [ 25 | -1.0000003576278687, 26 | -1.0, 27 | -1.0000003576278687 28 | ], 29 | "type" : "VEC3" 30 | }, 31 | { 32 | "bufferView" : 2, 33 | "componentType" : 5126, 34 | "count" : 24, 35 | "max" : [ 36 | 1.0, 37 | 1.0, 38 | 1.0 39 | ], 40 | "min" : [ 41 | -1.0, 42 | -1.0, 43 | -1.0 44 | ], 45 | "type" : "VEC3" 46 | }, 47 | { 48 | "bufferView" : 3, 49 | "componentType" : 5126, 50 | "count" : 24, 51 | "max" : [ 52 | 1.0, 53 | 6.661325971652322e-16, 54 | 1.0, 55 | 1.0 56 | ], 57 | "min" : [ 58 | -1.0, 59 | -2.9802322387695312e-08, 60 | -1.0, 61 | 1.0 62 | ], 63 | "type" : "VEC4" 64 | }, 65 | { 66 | "bufferView" : 4, 67 | "componentType" : 5126, 68 | "count" : 24, 69 | "max" : [ 70 | 0.7499566674232483, 71 | 0.9999134124518605 72 | ], 73 | "min" : [ 74 | 8.658754813950509e-05, 75 | 8.660554885864258e-05 76 | ], 77 | "type" : "VEC2" 78 | }, 79 | { 80 | "bufferView" : 5, 81 | "componentType" : 5126, 82 | "count" : 24, 83 | "max" : [ 84 | 0.25, 85 | 0.25 86 | ], 87 | "min" : [ 88 | 0.0, 89 | 0.0 90 | ], 91 | "type" : "VEC2" 92 | } 93 | ], 94 | "asset" : { 95 | "copyright" : "hiloteam", 96 | "generator" : "Khronos Blender glTF 2.0 exporter", 97 | "version" : "2.0" 98 | }, 99 | "bufferViews" : [ 100 | { 101 | "buffer" : 0, 102 | "byteLength" : 36, 103 | "byteOffset" : 0, 104 | "target" : 34963 105 | }, 106 | { 107 | "buffer" : 0, 108 | "byteLength" : 288, 109 | "byteOffset" : 36, 110 | "target" : 34962 111 | }, 112 | { 113 | "buffer" : 0, 114 | "byteLength" : 288, 115 | "byteOffset" : 324, 116 | "target" : 34962 117 | }, 118 | { 119 | "buffer" : 0, 120 | "byteLength" : 384, 121 | "byteOffset" : 612, 122 | "target" : 34962 123 | }, 124 | { 125 | "buffer" : 0, 126 | "byteLength" : 192, 127 | "byteOffset" : 996, 128 | "target" : 34962 129 | }, 130 | { 131 | "buffer" : 0, 132 | "byteLength" : 192, 133 | "byteOffset" : 1188, 134 | "target" : 34962 135 | } 136 | ], 137 | "buffers" : [ 138 | { 139 | "byteLength" : 1380, 140 | "uri" : "MultiUVTest.bin" 141 | } 142 | ], 143 | "cameras" : [ 144 | { 145 | "name" : "Camera", 146 | "perspective" : { 147 | "aspectRatio" : 1.7777777777777777, 148 | "yfov" : 0.5033799372418416, 149 | "zfar" : 100.0, 150 | "znear" : 0.10000000149011612 151 | }, 152 | "type" : "perspective" 153 | } 154 | ], 155 | "images" : [ 156 | { 157 | "uri" : "uv0.png" 158 | }, 159 | { 160 | "uri" : "uv1.png" 161 | } 162 | ], 163 | "materials" : [ 164 | { 165 | "emissiveFactor" : [ 166 | 1.0, 167 | 1.0, 168 | 1.0 169 | ], 170 | "emissiveTexture" : { 171 | "index" : 1, 172 | "texCoord" : 1 173 | }, 174 | "name" : "Material", 175 | "pbrMetallicRoughness" : { 176 | "baseColorTexture" : { 177 | "index" : 0 178 | } 179 | } 180 | } 181 | ], 182 | "meshes" : [ 183 | { 184 | "name" : "Cube", 185 | "primitives" : [ 186 | { 187 | "attributes" : { 188 | "NORMAL" : 2, 189 | "POSITION" : 1, 190 | "TANGENT" : 3, 191 | "TEXCOORD_0" : 4, 192 | "TEXCOORD_1" : 5 193 | }, 194 | "indices" : 0, 195 | "material" : 0 196 | } 197 | ] 198 | } 199 | ], 200 | "nodes" : [ 201 | { 202 | "camera" : 0, 203 | "name" : "Correction_Camera", 204 | "rotation" : [ 205 | -0.7071067690849304, 206 | -0.0, 207 | 0.0, 208 | 0.7071067690849304 209 | ] 210 | }, 211 | { 212 | "children" : [ 213 | 0 214 | ], 215 | "name" : "Camera", 216 | "rotation" : [ 217 | 0.483536034822464, 218 | 0.33687159419059753, 219 | -0.20870360732078552, 220 | 0.7804827094078064 221 | ], 222 | "translation" : [ 223 | 7.481131553649902, 224 | 5.34366512298584, 225 | 6.5076398849487305 226 | ] 227 | }, 228 | { 229 | "mesh" : 0, 230 | "name" : "Cube" 231 | } 232 | ], 233 | "samplers" : [ 234 | {} 235 | ], 236 | "scene" : 0, 237 | "scenes" : [ 238 | { 239 | "name" : "Scene", 240 | "nodes" : [ 241 | 2, 242 | 1 243 | ] 244 | } 245 | ], 246 | "textures" : [ 247 | { 248 | "sampler" : 0, 249 | "source" : 0 250 | }, 251 | { 252 | "sampler" : 0, 253 | "source" : 1 254 | } 255 | ] 256 | } 257 | -------------------------------------------------------------------------------- /resource/2.0/README.md: -------------------------------------------------------------------------------- 1 | # Samples 2 | 3 | Come from [https://github.com/KhronosGroup/glTF-Sample-Models.git](https://github.com/KhronosGroup/glTF-Sample-Models.git) 4 | -------------------------------------------------------------------------------- /resource/2.0/Triangle/README.md: -------------------------------------------------------------------------------- 1 | # Triangle 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.png) 6 | 7 | ## License Information 8 | 9 | Public domain ([CC0](https://creativecommons.org/publicdomain/zero/1.0/)) 10 | 11 | ## Data layout 12 | 13 | The following image shows the data layout of this sample: 14 | 15 | ![simpleTriangle](screenshot/simpleTriangle.png) 16 | -------------------------------------------------------------------------------- /resource/2.0/Triangle/glTF/三角形.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/Triangle/glTF/三角形.bin -------------------------------------------------------------------------------- /resource/2.0/Triangle/glTF/三角形.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "scenes" : [ 3 | { 4 | "nodes" : [ 0 ] 5 | } 6 | ], 7 | 8 | "nodes" : [ 9 | { 10 | "mesh" : 0 11 | } 12 | ], 13 | 14 | "meshes" : [ 15 | { 16 | "primitives" : [ { 17 | "attributes" : { 18 | "POSITION" : 1 19 | }, 20 | "indices" : 0 21 | } ] 22 | } 23 | ], 24 | 25 | "buffers" : [ 26 | { 27 | "uri" : "三角形.bin", 28 | "byteLength" : 44 29 | } 30 | ], 31 | "bufferViews" : [ 32 | { 33 | "buffer" : 0, 34 | "byteOffset" : 0, 35 | "byteLength" : 6, 36 | "target" : 34963 37 | }, 38 | { 39 | "buffer" : 0, 40 | "byteOffset" : 8, 41 | "byteLength" : 36, 42 | "target" : 34962 43 | } 44 | ], 45 | "accessors" : [ 46 | { 47 | "bufferView" : 0, 48 | "byteOffset" : 0, 49 | "componentType" : 5123, 50 | "count" : 3, 51 | "type" : "SCALAR", 52 | "max" : [ 2 ], 53 | "min" : [ 0 ] 54 | }, 55 | { 56 | "bufferView" : 1, 57 | "byteOffset" : 0, 58 | "componentType" : 5126, 59 | "count" : 3, 60 | "type" : "VEC3", 61 | "max" : [ 1.0, 1.0, 0.0 ], 62 | "min" : [ 0.0, 0.0, 0.0 ] 63 | } 64 | ], 65 | 66 | "asset" : { 67 | "version" : "2.0" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /resource/2.0/TriangleWithoutIndices/README.md: -------------------------------------------------------------------------------- 1 | # TriangleWithoutIndices 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.png) 6 | 7 | ## License Information 8 | 9 | Public domain ([CC0](https://creativecommons.org/publicdomain/zero/1.0/)) 10 | 11 | ## Data layout 12 | 13 | The following image shows the data layout of this sample: 14 | 15 | ![triangleWithoutIndices](screenshot/triangleWithoutIndices.png) -------------------------------------------------------------------------------- /resource/2.0/TriangleWithoutIndices/glTF/TriangleWithoutIndices.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "scenes" : [ 3 | { 4 | "nodes" : [ 0 ] 5 | } 6 | ], 7 | 8 | "nodes" : [ 9 | { 10 | "mesh" : 0 11 | } 12 | ], 13 | 14 | "meshes" : [ 15 | { 16 | "primitives" : [ { 17 | "attributes" : { 18 | "POSITION" : 0 19 | } 20 | } ] 21 | } 22 | ], 23 | 24 | "buffers" : [ 25 | { 26 | "uri" : "triangleWithoutIndices.bin", 27 | "byteLength" : 36 28 | } 29 | ], 30 | "bufferViews" : [ 31 | { 32 | "buffer" : 0, 33 | "byteOffset" : 0, 34 | "byteLength" : 36, 35 | "target" : 34962 36 | } 37 | ], 38 | "accessors" : [ 39 | { 40 | "bufferView" : 0, 41 | "byteOffset" : 0, 42 | "componentType" : 5126, 43 | "count" : 3, 44 | "type" : "VEC3", 45 | "max" : [ 1.0, 1.0, 0.0 ], 46 | "min" : [ 0.0, 0.0, 0.0 ] 47 | } 48 | ], 49 | 50 | "asset" : { 51 | "version" : "2.0" 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /resource/2.0/TriangleWithoutIndices/glTF/triangleWithoutIndices.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/TriangleWithoutIndices/glTF/triangleWithoutIndices.bin -------------------------------------------------------------------------------- /resource/2.0/TwoSidedPlane/README.md: -------------------------------------------------------------------------------- 1 | # Two Sided Plane 2 | ## Screenshot 3 | 4 | ![screenshot](screenshot/screenshot.jpg) 5 | 6 | 7 | ## License Information 8 | 9 | Donated by Norbert Nopper for glTF testing. -------------------------------------------------------------------------------- /resource/2.0/TwoSidedPlane/glTF/TwoSidedPlane.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/TwoSidedPlane/glTF/TwoSidedPlane.bin -------------------------------------------------------------------------------- /resource/2.0/TwoSidedPlane/glTF/TwoSidedPlane.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "accessors" : [ 3 | { 4 | "bufferView" : 0, 5 | "byteOffset" : 0, 6 | "componentType" : 5123, 7 | "count" : 6, 8 | "max" : [ 9 | 5 10 | ], 11 | "min" : [ 12 | 0 13 | ], 14 | "type" : "SCALAR" 15 | }, 16 | { 17 | "bufferView" : 1, 18 | "byteOffset" : 0, 19 | "componentType" : 5126, 20 | "count" : 6, 21 | "max" : [ 22 | 1.000000, 23 | 0.000000, 24 | 1.000000 25 | ], 26 | "min" : [ 27 | -1.000000, 28 | 0.000000, 29 | -1.000000 30 | ], 31 | "type" : "VEC3" 32 | }, 33 | { 34 | "bufferView" : 2, 35 | "byteOffset" : 0, 36 | "componentType" : 5126, 37 | "count" : 6, 38 | "max" : [ 39 | -0.000000, 40 | 1.000000, 41 | -0.000000 42 | ], 43 | "min" : [ 44 | -0.000000, 45 | 1.000000, 46 | -0.000000 47 | ], 48 | "type" : "VEC3" 49 | }, 50 | { 51 | "bufferView" : 3, 52 | "byteOffset" : 0, 53 | "componentType" : 5126, 54 | "count" : 6, 55 | "max" : [ 56 | 0.000000, 57 | 0.000000, 58 | -1.000000, 59 | 1.000000 60 | ], 61 | "min" : [ 62 | 0.000000, 63 | 0.000000, 64 | -1.000000, 65 | 1.000000 66 | ], 67 | "type" : "VEC4" 68 | }, 69 | { 70 | "bufferView" : 4, 71 | "byteOffset" : 0, 72 | "componentType" : 5126, 73 | "count" : 6, 74 | "max" : [ 75 | 0.999900, 76 | 0.999900 77 | ], 78 | "min" : [ 79 | 0.000100, 80 | 0.000100 81 | ], 82 | "type" : "VEC2" 83 | } 84 | ], 85 | "asset" : { 86 | "generator" : "VKTS glTF 2.0 exporter", 87 | "version" : "2.0" 88 | }, 89 | "bufferViews" : [ 90 | { 91 | "buffer" : 0, 92 | "byteLength" : 12, 93 | "byteOffset" : 0, 94 | "target" : 34963 95 | }, 96 | { 97 | "buffer" : 0, 98 | "byteLength" : 72, 99 | "byteOffset" : 12, 100 | "target" : 34962 101 | }, 102 | { 103 | "buffer" : 0, 104 | "byteLength" : 72, 105 | "byteOffset" : 84, 106 | "target" : 34962 107 | }, 108 | { 109 | "buffer" : 0, 110 | "byteLength" : 96, 111 | "byteOffset" : 156, 112 | "target" : 34962 113 | }, 114 | { 115 | "buffer" : 0, 116 | "byteLength" : 48, 117 | "byteOffset" : 252, 118 | "target" : 34962 119 | } 120 | ], 121 | "buffers" : [ 122 | { 123 | "byteLength" : 300, 124 | "uri" : "TwoSidedPlane.bin" 125 | } 126 | ], 127 | "images" : [ 128 | { 129 | "uri" : "TwoSidedPlane_BaseColor.png" 130 | }, 131 | { 132 | "uri" : "TwoSidedPlane_MetallicRoughness.png" 133 | }, 134 | { 135 | "uri" : "TwoSidedPlane_Normal.png" 136 | } 137 | ], 138 | "materials" : [ 139 | { 140 | "doubleSided" : true, 141 | "name" : "TwoSidedPlane", 142 | "normalTexture" : { 143 | "index" : 2 144 | }, 145 | "pbrMetallicRoughness" : { 146 | "baseColorTexture" : { 147 | "index" : 0 148 | }, 149 | "metallicRoughnessTexture" : { 150 | "index" : 1 151 | } 152 | } 153 | } 154 | ], 155 | "meshes" : [ 156 | { 157 | "name" : "TwoSidedPlane", 158 | "primitives" : [ 159 | { 160 | "attributes" : { 161 | "NORMAL" : 2, 162 | "POSITION" : 1, 163 | "TANGENT" : 3, 164 | "TEXCOORD_0" : 4 165 | }, 166 | "indices" : 0, 167 | "material" : 0, 168 | "mode" : 4 169 | } 170 | ] 171 | } 172 | ], 173 | "nodes" : [ 174 | { 175 | "mesh" : 0, 176 | "name" : "TwoSidedPlane" 177 | } 178 | ], 179 | "samplers" : [ 180 | {} 181 | ], 182 | "scene" : 0, 183 | "scenes" : [ 184 | { 185 | "nodes" : [ 186 | 0 187 | ] 188 | } 189 | ], 190 | "textures" : [ 191 | { 192 | "sampler" : 0, 193 | "source" : 0 194 | }, 195 | { 196 | "sampler" : 0, 197 | "source" : 1 198 | }, 199 | { 200 | "sampler" : 0, 201 | "source" : 2 202 | } 203 | ] 204 | } 205 | -------------------------------------------------------------------------------- /resource/2.0/UnlitTest/README.md: -------------------------------------------------------------------------------- 1 | # Unlit Test 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot_large.jpg) 6 | 7 | ## Description 8 | 9 | This model tests the [`KHR_materials_unlit`](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit) extension. There are two objects, one orange-ish (`#FF7F00` in sRGB space) and one blue-ish (`#007FFF` in sRGB space). The visible surface of these two objects should appear as a uniform color, so much so that the 3D effect is intentionally lost. 10 | 11 | ## Problem: Lighting applied to un-lit model 12 | 13 | ![screenshot](screenshot/unlit_test_fail.jpg) 14 | 15 | The above screenshot shows a case where normal lighting calculations have been applied to an un-lit material. While the shadows on the ground are permissible, the various panels and edges visible on the orange and blue objects are not. 16 | 17 | ## `ExtensionsUsed` vs. `ExtensionsRequired` 18 | 19 | This model lists the unlit extension in both lists, like this: 20 | 21 | ``` 22 | "extensionsUsed": [ 23 | "KHR_materials_unlit" 24 | ], 25 | "extensionsRequired": [ 26 | "KHR_materials_unlit" 27 | ] 28 | ``` 29 | 30 | The first list includes all extensions used by the current model, so there's no doubt that `KHR_materials_unlit` belongs there in this case. The second list is a subset of the first list, naming all the extensions that a given glTF viewer is *required* to support in order for this model to be loaded and displayed correctly. In this case, the sample model is a showcase for the visual appearance of the un-lit material, and any visible lighting effects are being declared as errors in the glTF viewer implementation. 31 | 32 | For this reason, I decided to include `KHR_materials_unlit` in the `extensionsRequired` list in this case. A conforming glTF implementation that does not support the `KHR_materials_unlit` extension should find an unknown value in the `extensionsRequired` list, and report an error rather than loading or displaying the model without the unlit material. 33 | 34 | In your own models, if you consider using a lit material to be a reasonable fallback behavior for implementations that don't support this extension, you should omit `KHR_materials_unlit` from the `extensionsRequired` list. 35 | 36 | ## License Information 37 | 38 | Copyright 2019 Analytical Graphics, Inc. 39 | CC-BY 4.0 https://creativecommons.org/licenses/by/4.0/ 40 | Model by Ed Mackey. 41 | -------------------------------------------------------------------------------- /resource/2.0/UnlitTest/glTF/UnlitTest.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/UnlitTest/glTF/UnlitTest.bin -------------------------------------------------------------------------------- /resource/2.0/UnlitTest/glTF/UnlitTest.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "accessors" : [ 3 | { 4 | "bufferView" : 0, 5 | "componentType" : 5126, 6 | "count" : 96, 7 | "max" : [ 8 | 1, 9 | 1, 10 | 1 11 | ], 12 | "min" : [ 13 | -1, 14 | -1, 15 | -1 16 | ], 17 | "type" : "VEC3" 18 | }, 19 | { 20 | "bufferView" : 1, 21 | "componentType" : 5126, 22 | "count" : 96, 23 | "type" : "VEC3" 24 | }, 25 | { 26 | "bufferView" : 2, 27 | "componentType" : 5123, 28 | "count" : 132, 29 | "type" : "SCALAR" 30 | } 31 | ], 32 | "asset" : { 33 | "copyright": "Copyright 2019 Analytical Graphics, Inc, CC-BY 4.0 https://creativecommons.org/licenses/by/4.0/ - Model by Ed Mackey.", 34 | "generator" : "Khronos Blender glTF 2.0 I/O, with hand-edits", 35 | "version" : "2.0" 36 | }, 37 | "bufferViews" : [ 38 | { 39 | "buffer" : 0, 40 | "byteLength" : 1152, 41 | "byteOffset" : 0 42 | }, 43 | { 44 | "buffer" : 0, 45 | "byteLength" : 1152, 46 | "byteOffset" : 1152 47 | }, 48 | { 49 | "buffer" : 0, 50 | "byteLength" : 264, 51 | "byteOffset" : 2304 52 | } 53 | ], 54 | "buffers" : [ 55 | { 56 | "byteLength" : 2568, 57 | "uri" : "UnlitTest.bin" 58 | } 59 | ], 60 | "materials" : [ 61 | { 62 | "name" : "Orange", 63 | "pbrMetallicRoughness" : { 64 | "baseColorFactor": [ 65 | 1, 66 | 0.217637640824031, 67 | 0, 68 | 1 69 | ] 70 | }, 71 | "extensions": { 72 | "KHR_materials_unlit": {} 73 | } 74 | }, 75 | { 76 | "name" : "Blue", 77 | "pbrMetallicRoughness" : { 78 | "baseColorFactor": [ 79 | 0, 80 | 0.217637640824031, 81 | 1, 82 | 1 83 | ] 84 | }, 85 | "extensions": { 86 | "KHR_materials_unlit": {} 87 | } 88 | } 89 | ], 90 | "meshes" : [ 91 | { 92 | "name" : "Orange Mesh", 93 | "primitives" : [ 94 | { 95 | "attributes" : { 96 | "NORMAL" : 1, 97 | "POSITION" : 0 98 | }, 99 | "indices" : 2, 100 | "material" : 0 101 | } 102 | ] 103 | }, 104 | { 105 | "name" : "Blue Mesh", 106 | "primitives" : [ 107 | { 108 | "attributes" : { 109 | "NORMAL" : 1, 110 | "POSITION" : 0 111 | }, 112 | "indices" : 2, 113 | "material" : 1 114 | } 115 | ] 116 | } 117 | ], 118 | "nodes" : [ 119 | { 120 | "mesh" : 0, 121 | "name" : "Orange Object", 122 | "translation": [ 123 | -1.2, 124 | 0, 125 | 0 126 | ] 127 | }, 128 | { 129 | "mesh" : 1, 130 | "name" : "Blue Object", 131 | "translation": [ 132 | 1.2, 133 | 0, 134 | 0 135 | ] 136 | } 137 | ], 138 | "scene" : 0, 139 | "scenes" : [ 140 | { 141 | "name" : "Scene", 142 | "nodes" : [ 143 | 0, 144 | 1 145 | ] 146 | } 147 | ], 148 | "extensionsUsed": [ 149 | "KHR_materials_unlit" 150 | ], 151 | "extensionsRequired": [ 152 | "KHR_materials_unlit" 153 | ] 154 | } 155 | -------------------------------------------------------------------------------- /resource/2.0/VertexColorTest/README.md: -------------------------------------------------------------------------------- 1 | # Vertex Color Test 2 | 3 | ## Screenshot 4 | 5 | ![screenshot](screenshot/screenshot.png) 6 | 7 | ## Description 8 | 9 | This model tests the attribute semantic `COLOR_0`, as defined in the glTF [Metallic Roughness Material](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material), to check if it has been multipled by `baseColor`. For engines that read the vertex colors and apply them, you should see two rows of checkmarks, as shown in the screenshot. The top row is the "Test" row, which has been multipled by red, green, and blue vertex colors to reveal checkmarks in the corresponding color channels. The bottom row is a "sample pass" row, where checkmarks of each color are multiplied by white and should appear the same as the screenshot regardless of the rendering engine's ability to process vertex colors. 10 | 11 | For engines that ignore vertex colors, the top row of checks will look noticably mangled. The red check has a cyan X, the green check has a magenta X, and the blue check has a yellow X, occupying the other two color channels of each test checkmark. If you see these "X" marks fighting with the checkmarks, then you are seeing color channels that are supposed to have been zeroed out by the applied vertex colors on the mesh, and it means your rendering engine has not applied the vertex colors. 12 | -------------------------------------------------------------------------------- /resource/2.0/VertexColorTest/glTF/VertexColorTest.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/2.0/VertexColorTest/glTF/VertexColorTest.bin -------------------------------------------------------------------------------- /resource/2.0/VertexColorTest/glTF/VertexColorTest.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "accessors" : [ 3 | { 4 | "bufferView" : 0, 5 | "componentType" : 5121, 6 | "count" : 36, 7 | "max" : [ 8 | 23 9 | ], 10 | "min" : [ 11 | 0 12 | ], 13 | "type" : "SCALAR" 14 | }, 15 | { 16 | "bufferView" : 1, 17 | "componentType" : 5126, 18 | "count" : 24, 19 | "max" : [ 20 | 0.7554783821105957, 21 | -0.8512416481971741, 22 | 0.9750328660011292 23 | ], 24 | "min" : [ 25 | -0.7045658230781555, 26 | -0.8512417078018188, 27 | -0.9611154794692993 28 | ], 29 | "type" : "VEC3" 30 | }, 31 | { 32 | "bufferView" : 2, 33 | "componentType" : 5126, 34 | "count" : 24, 35 | "max" : [ 36 | 0.0, 37 | 1.0, 38 | -0.0 39 | ], 40 | "min" : [ 41 | 0.0, 42 | 1.0, 43 | -0.0 44 | ], 45 | "type" : "VEC3" 46 | }, 47 | { 48 | "bufferView" : 3, 49 | "componentType" : 5126, 50 | "count" : 24, 51 | "max" : [ 52 | 1.0, 53 | 7.121938949694595e-08, 54 | 1.5105192119335697e-07, 55 | 1.0 56 | ], 57 | "min" : [ 58 | 1.0, 59 | -1.4348813692777185e-07, 60 | -1.1257676391096538e-07, 61 | 1.0 62 | ], 63 | "type" : "VEC4" 64 | }, 65 | { 66 | "bufferView" : 4, 67 | "componentType" : 5126, 68 | "count" : 24, 69 | "max" : [ 70 | 0.9999998807907104, 71 | 0.8010409474372864 72 | ], 73 | "min" : [ 74 | 0.0, 75 | 0.05539727210998535 76 | ], 77 | "type" : "VEC2" 78 | }, 79 | { 80 | "bufferView" : 5, 81 | "componentType" : 5121, 82 | "count" : 72, 83 | "max" : [ 84 | 47 85 | ], 86 | "min" : [ 87 | 0 88 | ], 89 | "type" : "SCALAR" 90 | }, 91 | { 92 | "bufferView" : 6, 93 | "componentType" : 5126, 94 | "count" : 48, 95 | "max" : [ 96 | 1.0000004768371582, 97 | 1.0, 98 | 0.48742246627807617 99 | ], 100 | "min" : [ 101 | -1.0000003576278687, 102 | -1.0, 103 | -0.1718665361404419 104 | ], 105 | "type" : "VEC3" 106 | }, 107 | { 108 | "bufferView" : 7, 109 | "componentType" : 5126, 110 | "count" : 48, 111 | "max" : [ 112 | 1.0, 113 | 1.0, 114 | 1.0 115 | ], 116 | "min" : [ 117 | -1.0, 118 | -1.0, 119 | -1.0 120 | ], 121 | "type" : "VEC3" 122 | }, 123 | { 124 | "bufferView" : 8, 125 | "componentType" : 5126, 126 | "count" : 48, 127 | "max" : [ 128 | 1.0, 129 | 7.940933880509066e-23, 130 | 4.470348358154297e-08, 131 | 1.0 132 | ], 133 | "min" : [ 134 | 1.0, 135 | -6.617444900424222e-24, 136 | -0.0, 137 | 1.0 138 | ], 139 | "type" : "VEC4" 140 | }, 141 | { 142 | "bufferView" : 9, 143 | "componentType" : 5126, 144 | "count" : 48, 145 | "max" : [ 146 | 0.8361296057701111, 147 | 0.7666319012641907 148 | ], 149 | "min" : [ 150 | 0.22613045573234558, 151 | 0.2321176528930664 152 | ], 153 | "type" : "VEC2" 154 | }, 155 | { 156 | "bufferView" : 10, 157 | "componentType" : 5126, 158 | "count" : 48, 159 | "max" : [ 160 | 1.0, 161 | 1.0, 162 | 1.0, 163 | 1.0 164 | ], 165 | "min" : [ 166 | 0.0, 167 | 0.0, 168 | 0.0, 169 | 1.0 170 | ], 171 | "type" : "VEC4" 172 | } 173 | ], 174 | "asset" : { 175 | "copyright": "Copyright 2018 Analytical Graphics, Inc., CC-BY 4.0 https://creativecommons.org/licenses/by/4.0/ - Mesh and textures by Ed Mackey.", 176 | "generator" : "Khronos Blender glTF 2.0 exporter", 177 | "version" : "2.0" 178 | }, 179 | "bufferViews" : [ 180 | { 181 | "buffer" : 0, 182 | "byteLength" : 36, 183 | "byteOffset" : 0, 184 | "target" : 34963 185 | }, 186 | { 187 | "buffer" : 0, 188 | "byteLength" : 288, 189 | "byteOffset" : 36, 190 | "target" : 34962 191 | }, 192 | { 193 | "buffer" : 0, 194 | "byteLength" : 288, 195 | "byteOffset" : 324, 196 | "target" : 34962 197 | }, 198 | { 199 | "buffer" : 0, 200 | "byteLength" : 384, 201 | "byteOffset" : 612, 202 | "target" : 34962 203 | }, 204 | { 205 | "buffer" : 0, 206 | "byteLength" : 192, 207 | "byteOffset" : 996, 208 | "target" : 34962 209 | }, 210 | { 211 | "buffer" : 0, 212 | "byteLength" : 72, 213 | "byteOffset" : 1188, 214 | "target" : 34963 215 | }, 216 | { 217 | "buffer" : 0, 218 | "byteLength" : 576, 219 | "byteOffset" : 1260, 220 | "target" : 34962 221 | }, 222 | { 223 | "buffer" : 0, 224 | "byteLength" : 576, 225 | "byteOffset" : 1836, 226 | "target" : 34962 227 | }, 228 | { 229 | "buffer" : 0, 230 | "byteLength" : 768, 231 | "byteOffset" : 2412, 232 | "target" : 34962 233 | }, 234 | { 235 | "buffer" : 0, 236 | "byteLength" : 384, 237 | "byteOffset" : 3180, 238 | "target" : 34962 239 | }, 240 | { 241 | "buffer" : 0, 242 | "byteLength" : 768, 243 | "byteOffset" : 3564, 244 | "target" : 34962 245 | } 246 | ], 247 | "buffers" : [ 248 | { 249 | "byteLength" : 4332, 250 | "uri" : "VertexColorTest.bin" 251 | } 252 | ], 253 | "images" : [ 254 | { 255 | "uri" : "VertexColorTestLabels.png" 256 | }, 257 | { 258 | "uri" : "VertexColorChecks.png" 259 | } 260 | ], 261 | "materials" : [ 262 | { 263 | "doubleSided" : true, 264 | "name" : "Label_Mat", 265 | "pbrMetallicRoughness" : { 266 | "baseColorTexture" : { 267 | "index" : 0 268 | }, 269 | "metallicFactor" : 0.0, 270 | "roughnessFactor" : 0.8999999761581421 271 | } 272 | }, 273 | { 274 | "name" : "VC_Checks_Mat", 275 | "pbrMetallicRoughness" : { 276 | "baseColorTexture" : { 277 | "index" : 1 278 | }, 279 | "metallicFactor" : 0.0, 280 | "roughnessFactor" : 0.8999999761581421 281 | } 282 | } 283 | ], 284 | "meshes" : [ 285 | { 286 | "name" : "LabelMesh", 287 | "primitives" : [ 288 | { 289 | "attributes" : { 290 | "NORMAL" : 2, 291 | "POSITION" : 1, 292 | "TANGENT" : 3, 293 | "TEXCOORD_0" : 4 294 | }, 295 | "indices" : 0, 296 | "material" : 0 297 | } 298 | ] 299 | }, 300 | { 301 | "name" : "VertexColorTestMesh", 302 | "primitives" : [ 303 | { 304 | "attributes" : { 305 | "COLOR_0" : 10, 306 | "NORMAL" : 7, 307 | "POSITION" : 6, 308 | "TANGENT" : 8, 309 | "TEXCOORD_0" : 9 310 | }, 311 | "indices" : 5, 312 | "material" : 1 313 | } 314 | ] 315 | } 316 | ], 317 | "nodes" : [ 318 | { 319 | "mesh" : 0, 320 | "name" : "Labels", 321 | "rotation" : [ 322 | 0.7071068286895752, 323 | 0.0, 324 | -0.0, 325 | 0.7071068286895752 326 | ], 327 | "translation" : [ 328 | 0.0, 329 | 0.0, 330 | 0.9126079678535461 331 | ] 332 | }, 333 | { 334 | "mesh" : 1, 335 | "name" : "VertexColorTest", 336 | "scale" : [ 337 | 1.0, 338 | 1.0, 339 | 0.07413393259048462 340 | ] 341 | } 342 | ], 343 | "samplers" : [ 344 | {} 345 | ], 346 | "scene" : 0, 347 | "scenes" : [ 348 | { 349 | "name" : "Scene", 350 | "nodes" : [ 351 | 0, 352 | 1 353 | ] 354 | } 355 | ], 356 | "textures" : [ 357 | { 358 | "sampler" : 0, 359 | "source" : 0 360 | }, 361 | { 362 | "sampler" : 0, 363 | "source" : 1 364 | } 365 | ] 366 | } 367 | -------------------------------------------------------------------------------- /resource/nothing.gltf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/resource/nothing.gltf -------------------------------------------------------------------------------- /source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(libgltf) 2 | 3 | if (${LIBGLTF_BUILD_RUNTEST}) 4 | add_subdirectory(runtest) 5 | endif() 6 | -------------------------------------------------------------------------------- /source/libgltf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(libgltf) 2 | 3 | configure_file(${PROJECT_NAME}.h.cmakein ${CMAKE_BINARY_DIR}/include/libgltf/libgltf.h @ONLY) 4 | 5 | set(CODE_FILE_LIST) 6 | set(CODE_FILE_LIST_TEMP 7 | ${CMAKE_BINARY_DIR}/include/libgltf/libgltf.h 8 | ) 9 | source_group("include" FILES ${CODE_FILE_LIST_TEMP}) 10 | list(APPEND CODE_FILE_LIST ${CODE_FILE_LIST_TEMP}) 11 | 12 | set(CODE_FILE_LIST_TEMP 13 | libgltf.cpp 14 | libgltfparser.h 15 | libgltfparser.cpp 16 | libgltfloader.cpp 17 | common.h 18 | common.cpp 19 | utility.h 20 | utility.cpp 21 | gltf_loader.h 22 | gltf_loader.cpp 23 | ) 24 | source_group("src" FILES ${CODE_FILE_LIST_TEMP}) 25 | list(APPEND CODE_FILE_LIST ${CODE_FILE_LIST_TEMP}) 26 | 27 | if(LIBGLTF_WITH_GOOGLE_DRACO) 28 | set(CODE_FILE_LIST_TEMP 29 | extensions/google_draco.h 30 | extensions/google_draco.cpp 31 | ) 32 | source_group("source\\extensions" FILES ${CODE_FILE_LIST_TEMP}) 33 | list(APPEND CODE_FILE_LIST ${CODE_FILE_LIST_TEMP}) 34 | endif() 35 | 36 | add_library(${PROJECT_NAME} STATIC ${CODE_FILE_LIST}) 37 | 38 | if(${LIBGLTF_PLATFORM_ANDROID}) 39 | set(ANDROID_ABI_PATH ${ANDROID_ABI}) 40 | if(${ANDROID_ARM_NEON}) 41 | set(ANDROID_ABI_PATH "${ANDROID_ABI}-with-neon") 42 | endif() 43 | string(TOLOWER ${ANDROID_ABI_PATH} ANDROID_ABI_PATH) 44 | elseif(${LIBGLTF_PLATFORM_IOS}) 45 | set(IOS_PLATFORM_PATH ${IOS_PLATFORM}) 46 | string(TOLOWER ${IOS_PLATFORM_PATH} IOS_PLATFORM_PATH) 47 | endif() 48 | 49 | target_include_directories(${PROJECT_NAME} 50 | PUBLIC 51 | $ 52 | $ 53 | PRIVATE 54 | ${PROJECT_SOURCE_DIR} 55 | ) 56 | 57 | if(RapidJSON_FOUND) 58 | target_include_directories(${PROJECT_NAME} 59 | PRIVATE 60 | $ 61 | ) 62 | elseif(TARGET RapidJSON) 63 | get_target_property(RapidJSON_INCLUDE_DIRS RapidJSON INTERFACE_INCLUDE_DIRECTORIES) 64 | target_include_directories(${PROJECT_NAME} 65 | PRIVATE 66 | $ 67 | ) 68 | else() 69 | target_include_directories(${PROJECT_NAME} 70 | PRIVATE 71 | ${EXTERNAL_PATH}/rapidjson/include 72 | ) 73 | endif() 74 | 75 | if(LIBGLTF_WITH_GOOGLE_DRACO) 76 | if(draco_FOUND) 77 | target_include_directories(${PROJECT_NAME} 78 | PRIVATE 79 | $ 80 | ) 81 | target_link_libraries(${PROJECT_NAME} 82 | PUBLIC 83 | $ 84 | ) 85 | elseif(TARGET draco) 86 | target_include_directories(${PROJECT_NAME} 87 | PRIVATE 88 | ${GOOGLE_DRACO_PATH_INCLUDE} 89 | ${GOOGLE_DRACO_PATH_BUILD} 90 | ) 91 | target_link_libraries(${PROJECT_NAME} 92 | PUBLIC 93 | ${LIBDRACO_NAME} 94 | ) 95 | else() 96 | target_include_directories(${PROJECT_NAME} 97 | PRIVATE 98 | ${GOOGLE_DRACO_PATH_INCLUDE} 99 | ${GOOGLE_DRACO_PATH_BUILD} 100 | ) 101 | target_link_libraries(${PROJECT_NAME} 102 | PUBLIC 103 | ${LIBDRACO_NAME} 104 | ) 105 | install( 106 | TARGETS ${LIBDRACO_NAME} 107 | EXPORT ${LIBDRACO_NAME}-targets 108 | ARCHIVE DESTINATION lib 109 | LIBRARY DESTINATION lib 110 | RUNTIME DESTINATION bin 111 | ) 112 | install( 113 | EXPORT "${LIBDRACO_NAME}-targets" 114 | DESTINATION "cmake/${LIBDRACO_NAME}" 115 | ) 116 | endif() 117 | endif() 118 | 119 | set_target_properties(${PROJECT_NAME} 120 | PROPERTIES 121 | FOLDER main 122 | ) 123 | 124 | install( 125 | DIRECTORY "${CMAKE_BINARY_DIR}/include" 126 | DESTINATION "." 127 | ) 128 | 129 | install( 130 | FILES "libgltf-config.cmake" 131 | DESTINATION "cmake/${PROJECT_NAME}" 132 | ) 133 | 134 | install( 135 | TARGETS ${PROJECT_NAME} 136 | EXPORT ${PROJECT_NAME}-targets 137 | ARCHIVE DESTINATION lib 138 | LIBRARY DESTINATION lib 139 | RUNTIME DESTINATION bin 140 | ) 141 | 142 | install( 143 | EXPORT "${PROJECT_NAME}-targets" 144 | NAMESPACE "${PROJECT_NAME}::" 145 | DESTINATION "cmake/${PROJECT_NAME}" 146 | ) 147 | 148 | install(FILES ${ROOT_PATH}/LICENSE.md 149 | DESTINATION "." 150 | RENAME LICENSE.md 151 | ) 152 | 153 | if(NOT draco_FOUND) 154 | install(FILES ${EXTERNAL_PATH}/rapidjson/license.txt 155 | DESTINATION "." 156 | RENAME LICENSE-rapidjson.txt 157 | ) 158 | endif() 159 | 160 | if(LIBGLTF_WITH_GOOGLE_DRACO) 161 | if(NOT draco_FOUND) 162 | install(FILES ${EXTERNAL_PATH}/draco/LICENSE 163 | DESTINATION "." 164 | RENAME LICENSE-draco 165 | ) 166 | endif() 167 | endif() 168 | -------------------------------------------------------------------------------- /source/libgltf/common.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "common.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace libgltf 32 | { 33 | void Verify(bool condition) 34 | { 35 | assert(condition); 36 | #ifdef NDEBUG 37 | if (!condition) ::abort(); 38 | #endif 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /source/libgltf/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "libgltf/libgltf.h" 28 | 29 | namespace libgltf 30 | { 31 | static const std::vector GSDataEmpty; 32 | static const std::string GSStringEmpty = ""; 33 | 34 | /// check 35 | void Verify(bool condition); 36 | } 37 | -------------------------------------------------------------------------------- /source/libgltf/extensions/google_draco.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "google_draco.h" 26 | 27 | #include 28 | 29 | namespace libgltf 30 | { 31 | class CGoogleDracoStream : public IGoogleDracoStream 32 | { 33 | public: 34 | explicit CGoogleDracoStream(std::shared_ptr& _pAccessorStream, bool _bUseAttributeID, size_t _AttributeID) 35 | : m_pAccessorStream(_pAccessorStream) 36 | , m_bUseAttributeID(_bUseAttributeID) 37 | , m_AttributeID(_AttributeID) 38 | { 39 | // 40 | } 41 | 42 | public: 43 | virtual bool UseAttributeID() const override 44 | { 45 | return m_bUseAttributeID; 46 | } 47 | 48 | virtual size_t GetAttributeID() const override 49 | { 50 | return m_AttributeID; 51 | } 52 | 53 | public: 54 | virtual bool operator<<(const SAccessorData& _AccessorData) override 55 | { 56 | if (!m_pAccessorStream) return false; 57 | return (*m_pAccessorStream << _AccessorData); 58 | } 59 | 60 | private: 61 | std::shared_ptr m_pAccessorStream; 62 | bool m_bUseAttributeID; 63 | size_t m_AttributeID; 64 | }; 65 | 66 | std::shared_ptr IGoogleDracoStream::Create(std::shared_ptr _pAccessorStream, bool _bUseAttributeID, size_t _AttributeID) 67 | { 68 | return std::make_shared(_pAccessorStream, _bUseAttributeID, _AttributeID); 69 | } 70 | 71 | CGoogleDraco::SDracoPointAttribute::SDracoPointAttribute() 72 | : accessorData() 73 | , buffer() 74 | { 75 | // 76 | } 77 | 78 | CGoogleDraco::SDracoMesh::SDracoMesh(std::shared_ptr _pDracoMesh) 79 | : dracoMesh(_pDracoMesh) 80 | , indices() 81 | , pointAttributes() 82 | { 83 | // 84 | } 85 | 86 | CGoogleDraco::CGoogleDraco() 87 | : m_DracoMeshes() 88 | { 89 | // 90 | } 91 | 92 | bool CGoogleDraco::GetOrDecode(size_t _Index, const SBufferData& _BufferDataEncoded, std::shared_ptr _pGoogleDracoStream) 93 | { 94 | if (_BufferDataEncoded.buffer == nullptr || _BufferDataEncoded.bufferSize == 0 || !_pGoogleDracoStream) return false; 95 | 96 | std::map>::iterator found_iterator = m_DracoMeshes.find(_Index); 97 | if (found_iterator == m_DracoMeshes.end()) 98 | { 99 | draco::DecoderBuffer DracoDecoderBuffer; 100 | DracoDecoderBuffer.Init((const char*)_BufferDataEncoded.buffer, _BufferDataEncoded.bufferSize); 101 | auto StatusOrGeometryType = draco::Decoder::GetEncodedGeometryType(&DracoDecoderBuffer); 102 | if (StatusOrGeometryType.ok() && StatusOrGeometryType.value() == draco::TRIANGULAR_MESH) 103 | { 104 | draco::Decoder DracoDecoder; 105 | auto DracoStatusOrMesh = DracoDecoder.DecodeMeshFromBuffer(&DracoDecoderBuffer); 106 | if (DracoStatusOrMesh.ok()) 107 | { 108 | std::unique_ptr DracoMesh = std::move(DracoStatusOrMesh).value(); 109 | found_iterator = m_DracoMeshes.insert(std::make_pair(_Index, std::make_shared(std::shared_ptr(std::move(DracoMesh))))).first; 110 | } 111 | } 112 | } 113 | if (found_iterator == m_DracoMeshes.end()) 114 | { 115 | found_iterator = m_DracoMeshes.insert(std::make_pair(_Index, std::shared_ptr())).first; 116 | } 117 | std::shared_ptr found_draco_mesh = found_iterator->second; 118 | if (!found_draco_mesh) return false; 119 | const std::shared_ptr& draco_mesh = found_draco_mesh->dracoMesh; 120 | if (!draco_mesh) return false; 121 | 122 | if (_pGoogleDracoStream->UseAttributeID()) 123 | { 124 | std::map::iterator found_point_iterator = found_draco_mesh->pointAttributes.find(_pGoogleDracoStream->GetAttributeID()); 125 | if (found_point_iterator == found_draco_mesh->pointAttributes.end()) 126 | { 127 | if (const draco::PointAttribute* point_attribute = draco_mesh->GetAttributeByUniqueId(static_cast(_pGoogleDracoStream->GetAttributeID()))) 128 | { 129 | const int8_t components_num = point_attribute->num_components(); 130 | if (components_num > 0) 131 | { 132 | const size_t map_size = point_attribute->indices_map_size(); 133 | SDracoPointAttribute draco_point_attribute; 134 | SAccessorData& accessor_data = draco_point_attribute.accessorData; 135 | accessor_data.componentType = EAccessorComponentType::FLOAT; 136 | accessor_data.count = map_size; 137 | switch (components_num) 138 | { 139 | case 1: 140 | accessor_data.type = EAccessorType::SCALAR; 141 | break; 142 | 143 | case 2: 144 | accessor_data.type = EAccessorType::VEC2; 145 | break; 146 | 147 | case 3: 148 | accessor_data.type = EAccessorType::VEC3; 149 | break; 150 | 151 | case 4: 152 | accessor_data.type = EAccessorType::VEC4; 153 | break; 154 | 155 | default: 156 | return false; 157 | } 158 | const size_t sizeof_data = SizeOfAccessor(accessor_data.componentType, 1, accessor_data.type); 159 | draco_point_attribute.buffer.resize(sizeof_data * accessor_data.count); 160 | //TODO: size_t to uint32_t 161 | for (draco::PointIndex i(0); i < static_cast(accessor_data.count); ++i) 162 | { 163 | point_attribute->GetMappedValue(i, draco_point_attribute.buffer.data() + sizeof_data * i.value()); 164 | } 165 | found_point_iterator = found_draco_mesh->pointAttributes.insert(std::make_pair(_pGoogleDracoStream->GetAttributeID(), draco_point_attribute)).first; 166 | } 167 | } 168 | } 169 | if (found_point_iterator == found_draco_mesh->pointAttributes.end()) 170 | { 171 | SDracoPointAttribute draco_point_attribute; 172 | found_point_iterator = found_draco_mesh->pointAttributes.insert(std::make_pair(_pGoogleDracoStream->GetAttributeID(), draco_point_attribute)).first; 173 | } 174 | { 175 | const SDracoPointAttribute& draco_point_attribute = found_point_iterator->second; 176 | SAccessorData accessor_data = draco_point_attribute.accessorData; 177 | accessor_data.bufferData.buffer = draco_point_attribute.buffer.data(); 178 | accessor_data.bufferData.bufferSize = draco_point_attribute.buffer.size(); 179 | return (*_pGoogleDracoStream << accessor_data); 180 | } 181 | } 182 | else 183 | { 184 | const draco::FaceIndex::ValueType num_faces = draco_mesh->num_faces(); 185 | if (found_draco_mesh->indices.size() != num_faces) 186 | { 187 | found_draco_mesh->indices.resize(num_faces * 3); 188 | for (draco::FaceIndex i(0); i < num_faces; ++i) 189 | { 190 | const draco::Mesh::Face& draco_face = draco_mesh->face(i); 191 | for (uint8_t j = 0; j < 3; ++j) 192 | { 193 | found_draco_mesh->indices[i.value() * 3 + j] = draco_face[j].value(); 194 | } 195 | } 196 | } 197 | SAccessorData accessor_data; 198 | accessor_data.componentType = EAccessorComponentType::UNSIGNED_INT; 199 | accessor_data.count = found_draco_mesh->indices.size(); 200 | accessor_data.type = EAccessorType::SCALAR; 201 | accessor_data.bufferData.buffer = (uint8_t*)found_draco_mesh->indices.data(); 202 | accessor_data.bufferData.bufferSize = found_draco_mesh->indices.size() * sizeof(uint32_t); 203 | return (*_pGoogleDracoStream << accessor_data); 204 | } 205 | return false; 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /source/libgltf/extensions/google_draco.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "common.h" 28 | 29 | namespace draco 30 | { 31 | class Mesh; 32 | } 33 | 34 | namespace libgltf 35 | { 36 | class IGoogleDracoStream 37 | { 38 | public: 39 | virtual bool UseAttributeID() const = 0; 40 | virtual size_t GetAttributeID() const = 0; 41 | 42 | public: 43 | virtual bool operator<<(const SAccessorData& _AccessorData) = 0; 44 | 45 | public: 46 | static std::shared_ptr Create(std::shared_ptr _pAccessorStream, bool _bUseAttributeID, size_t _AttributeID); 47 | }; 48 | 49 | class CGoogleDraco 50 | { 51 | struct SDracoPointAttribute 52 | { 53 | explicit SDracoPointAttribute(); 54 | 55 | SAccessorData accessorData; 56 | std::vector buffer; 57 | }; 58 | 59 | struct SDracoMesh 60 | { 61 | explicit SDracoMesh(std::shared_ptr _pDracoMesh); 62 | 63 | std::shared_ptr dracoMesh; 64 | std::vector indices; 65 | std::map pointAttributes; 66 | }; 67 | 68 | public: 69 | CGoogleDraco(); 70 | 71 | public: 72 | bool GetOrDecode(size_t _Index, const SBufferData& _BufferDataEncoded, std::shared_ptr _pGoogleDracoStream); 73 | 74 | private: 75 | std::map > m_DracoMeshes; 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /source/libgltf/gltf_loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "libgltf/libgltf.h" 28 | 29 | #if defined(LIBGLTF_WITH_GOOGLE_DRACO) 30 | # include "extensions/google_draco.h" 31 | #endif 32 | 33 | namespace libgltf 34 | { 35 | class IBufferStream 36 | { 37 | public: 38 | virtual bool operator<<(const SBufferData& _buffer_data) = 0; 39 | }; 40 | 41 | class IBufferViewStream 42 | { 43 | public: 44 | virtual bool operator<<(const SBufferData& _buffer_data) = 0; 45 | }; 46 | 47 | class CglTFLoader : public IglTFLoader 48 | { 49 | struct SGLBHeader 50 | { 51 | SGLBHeader(); 52 | 53 | uint32_t magic; 54 | uint32_t version; 55 | uint32_t length; 56 | }; 57 | 58 | struct SGLBChunk 59 | { 60 | SGLBChunk(); 61 | 62 | uint32_t length; 63 | uint32_t type; 64 | }; 65 | 66 | public: 67 | explicit CglTFLoader(std::function(const std::string&)> _reader); 68 | 69 | protected: 70 | bool LoadByUri(const std::string& _uri, const uint8_t*& _data_ptr, std::size_t& _data_size, std::string& _data_type); 71 | bool LoadBuffer(const std::shared_ptr& _buffer, const uint8_t*& _data_ptr, std::size_t& _data_size); 72 | bool LoadImage(const std::shared_ptr& _image, std::vector& _data, std::string& _type); 73 | bool LoadBufferData(std::size_t _index, std::shared_ptr& _buffer_stream); 74 | bool LoadBufferViewData(std::size_t _index, std::shared_ptr _buffer_view_stream); 75 | bool LoadAccessorData(std::size_t _index, std::shared_ptr _accessor_stream); 76 | 77 | public: 78 | virtual const std::unique_ptr& glTF() const override; 79 | virtual bool LoadMeshPrimitiveIndicesData(std::size_t _mesh_index, // 80 | std::size_t _primitive_index, 81 | std::shared_ptr _accessor_stream) override; 82 | virtual bool LoadMeshPrimitiveAttributeData(std::size_t _mesh_index, 83 | std::size_t _primitive_index, 84 | const std::string& _attribute, 85 | std::shared_ptr _accessor_stream) override; 86 | virtual bool LoadImageData(std::size_t _index, std::vector& _data, std::string& _type) override; 87 | 88 | protected: 89 | std::unique_ptr m_glTF; 90 | 91 | private: 92 | std::function(const std::string&)> m_Reader; 93 | std::map, std::string>> m_CacheDatas; 94 | #if defined(LIBGLTF_WITH_GOOGLE_DRACO) 95 | std::unique_ptr m_pGoogleDraco; 96 | #endif 97 | 98 | public: 99 | static const uint32_t ms_GLBMagicEntry; 100 | static const uint32_t ms_GLBChunkTypeJSON; 101 | static const uint32_t ms_GLBChunkTypeBIN; 102 | }; 103 | } // namespace libgltf 104 | -------------------------------------------------------------------------------- /source/libgltf/libgltf-config.cmake: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/libgltf-targets.cmake" OPTIONAL) -------------------------------------------------------------------------------- /source/libgltf/libgltfloader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "libgltf/libgltf.h" 26 | 27 | #include "gltf_loader.h" 28 | #include "utility.h" 29 | 30 | namespace libgltf 31 | { 32 | int32_t AccessorComponentTypeToInt32(EAccessorComponentType _eType) 33 | { 34 | return static_cast(GSAccessorComponentTypes[uint32_t(_eType)].value); 35 | } 36 | 37 | EAccessorComponentType Int32ToAccessorComponentType(int32_t _iValue) 38 | { 39 | for (uint32_t i = 0; i < uint32_t(EAccessorComponentType::MAX); ++i) 40 | { 41 | if (GSAccessorComponentTypes[i].value != _iValue) continue; 42 | return EAccessorComponentType(i); 43 | } 44 | return EAccessorComponentType::NONE; 45 | } 46 | 47 | const std::string& AccessorTypeToText(EAccessorType _eType) 48 | { 49 | return GSAccessorTypes[uint8_t(_eType)].text; 50 | } 51 | 52 | EAccessorType TextToAccessorType(const std::string& _sText, bool _bCaseCensitive /*= true*/) 53 | { 54 | for (uint8_t i = 0; i < uint8_t(EAccessorType::MAX); ++i) 55 | { 56 | if (!StringEqual(GSAccessorTypes[i].text, _sText, _bCaseCensitive)) continue; 57 | return EAccessorType(i); 58 | } 59 | return EAccessorType::NONE; 60 | } 61 | 62 | size_t SizeOfAccessorComponentType(EAccessorComponentType _eType) 63 | { 64 | return GSAccessorComponentTypes[uint32_t(_eType)].size; 65 | }; 66 | 67 | size_t DimensionOfAccessorType(EAccessorType _eType) 68 | { 69 | return GSAccessorTypes[uint8_t(_eType)].dimension; 70 | } 71 | 72 | size_t SizeOfAccessor(EAccessorComponentType _eAccessorComponentType, size_t _iCount, EAccessorType _eAccessorType) 73 | { 74 | return (SizeOfAccessorComponentType(_eAccessorComponentType) * _iCount * DimensionOfAccessorType(_eAccessorType)); 75 | } 76 | 77 | SBufferData::SBufferData() 78 | : buffer(nullptr) 79 | , bufferSize(0) 80 | , bufferStride(0) 81 | { 82 | // 83 | } 84 | 85 | SAccessorData::SAccessorData() 86 | : componentType(EAccessorComponentType::NONE) 87 | , count(0) 88 | , type(EAccessorType::NONE) 89 | , bufferStride(0) 90 | , bufferData() 91 | { 92 | // 93 | } 94 | 95 | std::shared_ptr IglTFLoader::Create(std::function(const std::string&)> _reader) 96 | { 97 | return std::make_shared(_reader); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /source/libgltf/utility.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "utility.h" 26 | #include "libgltfparser.h" 27 | 28 | #include "common.h" 29 | 30 | #include 31 | 32 | namespace libgltf 33 | { 34 | int8_t CharacterIsAlphabet(std::string::value_type v) 35 | { 36 | if (v >= 'a' && v <= 'z') return -1; 37 | if (v >= 'A' && v <= 'Z') return 1; 38 | return 0; 39 | } 40 | 41 | std::string::value_type CharacterToLower(std::string::value_type v) 42 | { 43 | int8_t is_alphabet = CharacterIsAlphabet(v); 44 | if (is_alphabet == 0 || is_alphabet == -1) return v; 45 | return v + 'a' - 'A'; 46 | } 47 | 48 | bool CharacterEqual(std::string::value_type v0, std::string::value_type v1, bool case_sensitive = true) 49 | { 50 | if (case_sensitive) return (v0 == v1); 51 | return (CharacterToLower(v0) == CharacterToLower(v1)); 52 | } 53 | 54 | bool StringEqual(const std::string& value0, const std::string& value1, bool case_sensitive /*= true*/) 55 | { 56 | if (value0.size() != value1.size()) return false; 57 | if (case_sensitive) return (value0.compare(value1) == 0); 58 | for (size_t i = 0; i < value1.size(); ++i) 59 | { 60 | if (CharacterEqual(value0[i], value1[i], case_sensitive)) continue; 61 | return false; 62 | } 63 | return true; 64 | } 65 | 66 | bool StringStartWith(const std::string& value_target, const std::string& value_start, bool case_sensitive /*= true*/) 67 | { 68 | if (value_target.size() < value_start.size()) return false; 69 | return StringEqual(value_target.substr(0, value_start.size()), value_start, case_sensitive); 70 | } 71 | 72 | namespace base64 73 | { 74 | /// reference: https://github.com/ReneNyffenegger/cpp-base64 75 | static const std::string Base64Chars = u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 76 | 77 | static inline bool IsIt(char v) 78 | { 79 | return (isalnum(v) || (v == '+') || (v == '/')); 80 | } 81 | 82 | bool Encode(const std::vector& data, std::string& value) 83 | { 84 | value.clear(); 85 | if (data.empty()) return true; 86 | 87 | std::string result; 88 | size_t i = 0; 89 | uint8_t char_array_3[3]; 90 | uint8_t char_array_4[4]; 91 | 92 | size_t index = 0; 93 | size_t in_len = data.size(); 94 | while (index < in_len) 95 | { 96 | char_array_3[i++] = data[index++]; 97 | if (i == 3) 98 | { 99 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 100 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 101 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 102 | char_array_4[3] = char_array_3[2] & 0x3f; 103 | 104 | for (i = 0; (i < 4); i++) 105 | { 106 | result += Base64Chars[char_array_4[i]]; 107 | } 108 | i = 0; 109 | } 110 | } 111 | 112 | if (i) 113 | { 114 | for (size_t j = i; j < 3; j++) 115 | { 116 | char_array_3[j] = '\0'; 117 | } 118 | 119 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 120 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 121 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 122 | 123 | for (size_t j = 0; (j < i + 1); j++) 124 | { 125 | result += Base64Chars[char_array_4[j]]; 126 | } 127 | 128 | while ((i++ < 3)) 129 | { 130 | result += '='; 131 | } 132 | } 133 | 134 | value = result; 135 | return true; 136 | } 137 | 138 | bool Decode(const std::string& value, std::vector& data) 139 | { 140 | data.clear(); 141 | if (value.empty()) return true; 142 | 143 | size_t in_len = value.size(); 144 | size_t i = 0; 145 | size_t in_ = 0; 146 | uint8_t char_array_4[4], char_array_3[3]; 147 | 148 | while (in_len-- && (value[in_] != '=')) 149 | { 150 | if (!IsIt(value[in_])) return false; 151 | char_array_4[i++] = value[in_]; in_++; 152 | if (i == 4) 153 | { 154 | for (i = 0; i < 4; i++) 155 | { 156 | char_array_4[i] = static_cast(Base64Chars.find(char_array_4[i])); 157 | } 158 | 159 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 160 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 161 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 162 | 163 | for (i = 0; (i < 3); i++) 164 | { 165 | data.push_back(char_array_3[i]); 166 | } 167 | i = 0; 168 | } 169 | } 170 | 171 | if (i) 172 | { 173 | for (size_t j = 0; j < i; j++) 174 | { 175 | char_array_4[j] = static_cast(Base64Chars.find(char_array_4[j])); 176 | } 177 | 178 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 179 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 180 | 181 | for (size_t j = 0; (j < i - 1); j++) 182 | { 183 | data.push_back(char_array_3[j]); 184 | } 185 | } 186 | return true; 187 | } 188 | 189 | std::string Encode(const std::string& value) 190 | { 191 | if (value.empty()) return value; 192 | 193 | std::vector data; 194 | data.resize(value.length()); 195 | ::memcpy((void*)data.data(), (void*)value.data(), sizeof(uint8_t) * data.size()); 196 | std::string result; 197 | Encode(data, result); 198 | return result; 199 | } 200 | 201 | std::string Decode(const std::string& value) 202 | { 203 | if (value.empty()) return value; 204 | 205 | std::vector data; 206 | if (!Decode(value, data) || data.empty()) return std::string(); 207 | 208 | std::string result; 209 | result.resize(data.size()); 210 | ::memcpy((void*)result.data(), (void*)data.data(), sizeof(uint8_t) * data.size()); 211 | return result; 212 | } 213 | } 214 | 215 | bool UriParse(const std::string& value, std::string& data_type, std::string& data_encode, size_t& data_start) 216 | { 217 | static const std::string data = "data:"; 218 | if (!StringStartWith(value, data)) return false; 219 | static const size_t data_index = data.length(); 220 | 221 | size_t slash_index = value.find_first_of("/", data_index); 222 | if (slash_index >= value.length()) return false; 223 | ++slash_index; 224 | 225 | size_t semicolon_index = value.find_first_of(";", slash_index); 226 | if (semicolon_index >= value.length()) return false; 227 | ++semicolon_index; 228 | 229 | size_t comma_index = value.find_first_of(",", semicolon_index); 230 | if (comma_index >= value.length()) return false; 231 | ++comma_index; 232 | 233 | data_type = value.substr(data_index, semicolon_index - data_index - 1); 234 | data_encode = value.substr(semicolon_index, comma_index - semicolon_index - 1); 235 | data_start = comma_index; 236 | return true; 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /source/libgltf/utility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "libgltf/libgltf.h" 28 | 29 | namespace libgltf 30 | { 31 | bool StringEqual(const std::string& value0, const std::string& value1, bool case_sensitive = true); 32 | bool StringStartWith(const std::string& value_target, const std::string& value_start, bool case_sensitive = true); 33 | 34 | template 35 | bool StringMapFind(const std::map& value_source, const std::string& value_target, TType& value_founded, bool case_sensitive = true) 36 | { 37 | if (case_sensitive) 38 | { 39 | typename std::map::const_iterator iterator_founded = value_source.find(value_target); 40 | if (iterator_founded == value_source.cend()) return false; 41 | value_founded = iterator_founded->second; 42 | return true; 43 | } 44 | for (const std::pair& item : value_source) 45 | { 46 | if (!StringEqual(item.first, value_target, case_sensitive)) continue; 47 | value_founded = item.second; 48 | return true; 49 | } 50 | return false; 51 | } 52 | 53 | namespace base64 54 | { 55 | bool Encode(const std::vector& data, std::string& value); 56 | bool Decode(const std::string& value, std::vector& data); 57 | std::string Encode(const std::string& value); 58 | std::string Decode(const std::string& value); 59 | } 60 | 61 | bool UriParse(const std::string& value, std::string& data_type, std::string& data_encode, size_t& data_start); 62 | } 63 | -------------------------------------------------------------------------------- /source/runtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(runtest) 2 | 3 | set(SOURCE_FILE_PATH ${SOURCE_PATH}/runtest) 4 | 5 | set(HEADER_FILE_LIST 6 | ${SOURCE_FILE_PATH}/runtest.h 7 | ) 8 | source_group("src" FILES ${HEADER_FILE_LIST}) 9 | 10 | set(SOURCE_FILE_LIST 11 | ${SOURCE_FILE_PATH}/runtest.cpp 12 | ) 13 | source_group("src" FILES ${SOURCE_FILE_LIST}) 14 | 15 | add_executable(runtest 16 | ${HEADER_FILE_LIST} 17 | ${SOURCE_FILE_LIST} 18 | ) 19 | 20 | set(INCLUDE_PATH_LIST 21 | ${SOURCE_FILE_PATH} 22 | ${CMAKE_BINARY_DIR}/include 23 | ) 24 | target_include_directories(${PROJECT_NAME} 25 | PRIVATE 26 | ${INCLUDE_PATH_LIST} 27 | ) 28 | 29 | target_link_libraries(${PROJECT_NAME} 30 | PRIVATE 31 | libgltf 32 | ) 33 | 34 | set_target_properties(runtest 35 | PROPERTIES 36 | FOLDER main 37 | ) 38 | 39 | install( 40 | TARGETS ${PROJECT_NAME} 41 | EXPORT ${PROJECT_NAME}-targets 42 | RUNTIME DESTINATION bin 43 | ) 44 | -------------------------------------------------------------------------------- /source/runtest/runtest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "runtest.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #if defined(LIBGLTF_PLATFORM_WINDOWS) && defined(_DEBUG) 34 | # include 35 | #endif 36 | 37 | void SaveAsOBJ(const std::string& _sFilePath, 38 | const libgltf::TVertexList<1, size_t>& _TriangleIndices, 39 | const libgltf::TVertexList<3, float>& _VertexPositions, 40 | const libgltf::TVertexList<2, float>& _VertexTexcoord, 41 | const libgltf::TVertexList<3, float>& _VertexNormal, 42 | float _Scale = 100.0f) 43 | { 44 | std::ofstream obj_stream(_sFilePath.c_str()); 45 | if (!obj_stream.good()) 46 | return; 47 | 48 | obj_stream << "# generated by libgltf" << std::endl; 49 | 50 | obj_stream << "# vertex" << std::endl; 51 | for (size_t i = 0; i < _VertexPositions.size(); ++i) 52 | { 53 | const libgltf::TVertexList<3, float>::TValue& position_item = _VertexPositions[i]; 54 | obj_stream << "v " << position_item[0] * _Scale << " " << position_item[1] * _Scale << " " << position_item[2] * _Scale << std::endl; 55 | } 56 | obj_stream << std::endl; 57 | 58 | obj_stream << "# texcoord" << std::endl; 59 | for (size_t i = 0; i < _VertexTexcoord.size(); ++i) 60 | { 61 | const libgltf::TVertexList<2, float>::TValue& texcoord_0_item = _VertexTexcoord[i]; 62 | obj_stream << "vt " << texcoord_0_item[0] << " " << texcoord_0_item[1] << std::endl; 63 | } 64 | obj_stream << std::endl; 65 | 66 | obj_stream << "# normal" << std::endl; 67 | for (size_t i = 0; i < _VertexNormal.size(); ++i) 68 | { 69 | const libgltf::TVertexList<3, float>::TValue& normal_item = _VertexNormal[i]; 70 | obj_stream << "vn " << normal_item[0] << " " << normal_item[1] << " " << normal_item[2] << std::endl; 71 | } 72 | obj_stream << std::endl; 73 | 74 | obj_stream << "# face" << std::endl; 75 | for (size_t i = 0; i < _TriangleIndices.size(); i += 3) 76 | { 77 | obj_stream << "f"; 78 | for (size_t j = 0; j < 3; ++j) 79 | { 80 | size_t triangle_item = _TriangleIndices[i + j][0]; 81 | if (triangle_item >= _VertexPositions.size()) 82 | { 83 | break; 84 | } 85 | ++triangle_item; 86 | obj_stream << " " << triangle_item << "/" << triangle_item << "/" << triangle_item; 87 | } 88 | obj_stream << std::endl; 89 | } 90 | obj_stream.close(); 91 | } 92 | 93 | int main(int _argc, char* _argv[]) 94 | { 95 | #if defined(LIBGLTF_PLATFORM_WINDOWS) && defined(_DEBUG) 96 | _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); 97 | #endif 98 | 99 | #if defined(LIBGLTF_BUILD_COVERAGE) 100 | int error_code = 0; 101 | #else 102 | int error_code = 1; 103 | #endif 104 | 105 | std::string input_file_path; 106 | if (_argc == 2) 107 | { 108 | input_file_path = _argv[1]; 109 | } 110 | if (input_file_path.length() == 0) 111 | { 112 | printf("Usage: runtest \n"); 113 | return error_code; 114 | } 115 | 116 | std::shared_ptr gltf_loader = libgltf::IglTFLoader::Create( 117 | [input_file_path](const std::string& _path) 118 | { 119 | std::filesystem::path file_path; 120 | if (_path.empty()) 121 | file_path = std::filesystem::path(input_file_path); 122 | else 123 | file_path = std::filesystem::path(input_file_path).parent_path().append(_path); 124 | 125 | std::shared_ptr stream_ptr = nullptr; 126 | if (!std::filesystem::exists(file_path)) 127 | return stream_ptr; 128 | 129 | stream_ptr = std::make_shared(file_path.string(), std::ios::in | std::ios::binary); 130 | return stream_ptr; 131 | }); 132 | const std::unique_ptr& loaded_gltf = gltf_loader->glTF(); 133 | if (!loaded_gltf) 134 | { 135 | printf("Failed\n"); 136 | return error_code; 137 | } 138 | 139 | libgltf::TVertexList<1, size_t> triangle_data; 140 | { 141 | std::shared_ptr>> accessor_stream = 142 | std::make_shared>>(triangle_data); 143 | gltf_loader->LoadMeshPrimitiveIndicesData(0, 0, accessor_stream); 144 | } 145 | 146 | libgltf::TVertexList<3, float> position_data; 147 | { 148 | std::shared_ptr>> accessor_stream = 149 | std::make_shared>>(position_data); 150 | gltf_loader->LoadMeshPrimitiveAttributeData(0, 0, "position", accessor_stream); 151 | } 152 | 153 | libgltf::TVertexList<3, float> normal_data; 154 | { 155 | std::shared_ptr>> accessor_stream = 156 | std::make_shared>>(normal_data); 157 | gltf_loader->LoadMeshPrimitiveAttributeData(0, 0, "normal", accessor_stream); 158 | } 159 | 160 | libgltf::TVertexList<2, float> texcoord_0_data; 161 | { 162 | std::shared_ptr>> accessor_stream = 163 | std::make_shared>>(texcoord_0_data); 164 | gltf_loader->LoadMeshPrimitiveAttributeData(0, 0, "texcoord_0", accessor_stream); 165 | } 166 | 167 | std::vector image0_data; 168 | std::string image0_data_type; 169 | gltf_loader->LoadImageData(0, image0_data, image0_data_type); 170 | 171 | std::string gltf_json; 172 | if (!(*loaded_gltf >> gltf_json)) 173 | printf("Failed to convert to json!\n"); 174 | 175 | #if defined(LIBGLTF_BUILD_COVERAGE) 176 | const std::string obj_file_path = input_file_path + ".obj"; 177 | SaveAsOBJ(obj_file_path, triangle_data, position_data, texcoord_0_data, normal_data); 178 | #endif 179 | 180 | printf("Success\n"); 181 | return error_code; 182 | } 183 | -------------------------------------------------------------------------------- /source/runtest/runtest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is released under the MIT license. 3 | * 4 | * Copyright (c) 2017-2023 Code 4 Game, Org. All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(batch) 2 | add_subdirectory(jsonschematoc11) 3 | -------------------------------------------------------------------------------- /tools/batch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TOOLS_BATCH_PATH "${TOOLS_PATH}/batch") 2 | 3 | set(TOOLS_BATCH_FILE_LIST_SCRIPTS 4 | ${TOOLS_BATCH_PATH}/update_parser_by_scheme.bat 5 | ${TOOLS_BATCH_PATH}/update_parser_by_scheme.sh 6 | ) 7 | 8 | set(TOOLS_BATCH_FILE_LIST_CODES 9 | ${TOOLS_BATCH_PATH}/codes/extension.schema.json.h 10 | ${TOOLS_BATCH_PATH}/codes/extension.schema.json.variable.cpp 11 | ${TOOLS_BATCH_PATH}/codes/extension.schema.json.function.cpp 12 | ${TOOLS_BATCH_PATH}/codes/extension.schema.json.parser.to.cpp 13 | ${TOOLS_BATCH_PATH}/codes/extension.schema.json.parser.from.cpp 14 | ${TOOLS_BATCH_PATH}/codes/libgltf.header.include.h 15 | ${TOOLS_BATCH_PATH}/codes/libgltf.header.namespace.begin.h 16 | ${TOOLS_BATCH_PATH}/codes/libgltf.header.namespace.end.h 17 | ) 18 | 19 | set(TOOLS_BUILD_FILE_LIST_CONFIG 20 | ${ROOT_PATH}/.github/FUNDING.yml 21 | ${ROOT_PATH}/.github/workflows/coverage.yml 22 | ${ROOT_PATH}/.github/workflows/build.yml 23 | ${ROOT_PATH}/.github/workflows/release.yml 24 | ) 25 | 26 | source_group("scripts" FILES ${TOOLS_BATCH_FILE_LIST_SCRIPTS}) 27 | source_group("codes" FILES ${TOOLS_BATCH_FILE_LIST_CODES}) 28 | source_group("build" FILES ${TOOLS_BUILD_FILE_LIST_CONFIG}) 29 | 30 | add_custom_target(batch SOURCES ${TOOLS_BATCH_FILE_LIST_SCRIPTS} ${TOOLS_BATCH_FILE_LIST_CODES} ${TOOLS_BUILD_FILE_LIST_CONFIG}) 31 | set_property(TARGET batch PROPERTY FOLDER tools) 32 | -------------------------------------------------------------------------------- /tools/batch/codes/extension.schema.json.function.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/tools/batch/codes/extension.schema.json.function.cpp -------------------------------------------------------------------------------- /tools/batch/codes/extension.schema.json.h: -------------------------------------------------------------------------------- 1 | std::map> properties; -------------------------------------------------------------------------------- /tools/batch/codes/extension.schema.json.parser.from.cpp: -------------------------------------------------------------------------------- 1 | if (_JsonValue.HasMember("KHR_draco_mesh_compression") && _JsonValue["KHR_draco_mesh_compression"].IsObject()) 2 | { 3 | std::shared_ptr extension; 4 | if (!(extension << _JsonValue["KHR_draco_mesh_compression"])) return false; 5 | _rData.properties.insert(std::make_pair("KHR_draco_mesh_compression", extension)); 6 | } 7 | if (_JsonValue.HasMember("KHR_lights_punctual") && _JsonValue["KHR_lights_punctual"].IsObject()) 8 | { 9 | const JSONCharValue& json_extension = _JsonValue["KHR_lights_punctual"]; 10 | if (json_extension.HasMember("lights")) 11 | { 12 | std::shared_ptr extension; 13 | if (extension << json_extension) 14 | { 15 | _rData.properties.insert(std::make_pair("KHR_lights_punctual", extension)); 16 | } 17 | } 18 | if (json_extension.HasMember("light")) 19 | { 20 | std::shared_ptr extension; 21 | if (extension << json_extension) 22 | { 23 | _rData.properties.insert(std::make_pair("KHR_lights_punctual", extension)); 24 | } 25 | } 26 | } 27 | if (_JsonValue.HasMember("KHR_materials_clearcoat") && _JsonValue["KHR_materials_clearcoat"].IsObject()) 28 | { 29 | std::shared_ptr extension; 30 | if (!(extension << _JsonValue["KHR_materials_clearcoat"])) return false; 31 | _rData.properties.insert(std::make_pair("KHR_materials_clearcoat", extension)); 32 | } 33 | if (_JsonValue.HasMember("KHR_materials_emissive_strength") && _JsonValue["KHR_materials_emissive_strength"].IsObject()) 34 | { 35 | std::shared_ptr extension; 36 | if (!(extension << _JsonValue["KHR_materials_emissive_strength"])) return false; 37 | _rData.properties.insert(std::make_pair("KHR_materials_emissive_strength", extension)); 38 | } 39 | if (_JsonValue.HasMember("KHR_materials_ior") && _JsonValue["KHR_materials_ior"].IsObject()) 40 | { 41 | std::shared_ptr extension; 42 | if (!(extension << _JsonValue["KHR_materials_ior"])) return false; 43 | _rData.properties.insert(std::make_pair("KHR_materials_ior", extension)); 44 | } 45 | if (_JsonValue.HasMember("KHR_materials_iridescence") && _JsonValue["KHR_materials_iridescence"].IsObject()) 46 | { 47 | std::shared_ptr extension; 48 | if (!(extension << _JsonValue["KHR_materials_iridescence"])) return false; 49 | _rData.properties.insert(std::make_pair("KHR_materials_iridescence", extension)); 50 | } 51 | if (_JsonValue.HasMember("KHR_materials_sheen") && _JsonValue["KHR_materials_sheen"].IsObject()) 52 | { 53 | std::shared_ptr extension; 54 | if (!(extension << _JsonValue["KHR_materials_sheen"])) return false; 55 | _rData.properties.insert(std::make_pair("KHR_materials_sheen", extension)); 56 | } 57 | if (_JsonValue.HasMember("KHR_materials_specular") && _JsonValue["KHR_materials_specular"].IsObject()) 58 | { 59 | std::shared_ptr extension; 60 | if (!(extension << _JsonValue["KHR_materials_specular"])) return false; 61 | _rData.properties.insert(std::make_pair("KHR_materials_specular", extension)); 62 | } 63 | if (_JsonValue.HasMember("KHR_materials_transmission") && _JsonValue["KHR_materials_transmission"].IsObject()) 64 | { 65 | std::shared_ptr extension; 66 | if (!(extension << _JsonValue["KHR_materials_transmission"])) return false; 67 | _rData.properties.insert(std::make_pair("KHR_materials_transmission", extension)); 68 | } 69 | if (_JsonValue.HasMember("KHR_materials_unlit") && _JsonValue["KHR_materials_unlit"].IsObject()) 70 | { 71 | std::shared_ptr extension; 72 | if (!(extension << _JsonValue["KHR_materials_unlit"])) return false; 73 | _rData.properties.insert(std::make_pair("KHR_materials_unlit", extension)); 74 | } 75 | if (_JsonValue.HasMember("KHR_materials_variants") && _JsonValue["KHR_materials_variants"].IsObject()) 76 | { 77 | std::shared_ptr extension; 78 | if (!(extension << _JsonValue["KHR_materials_variants"])) return false; 79 | _rData.properties.insert(std::make_pair("KHR_materials_variants", extension)); 80 | } 81 | if (_JsonValue.HasMember("KHR_materials_volume") && _JsonValue["KHR_materials_volume"].IsObject()) 82 | { 83 | std::shared_ptr extension; 84 | if (!(extension << _JsonValue["KHR_materials_volume"])) return false; 85 | _rData.properties.insert(std::make_pair("KHR_materials_volume", extension)); 86 | } 87 | if (_JsonValue.HasMember("KHR_texture_transform") && _JsonValue["KHR_texture_transform"].IsObject()) 88 | { 89 | std::shared_ptr extension; 90 | if (!(extension << _JsonValue["KHR_texture_transform"])) return false; 91 | _rData.properties.insert(std::make_pair("KHR_texture_transform", extension)); 92 | } 93 | if (_JsonValue.HasMember("ADOBE_materials_thin_transparency") && _JsonValue["ADOBE_materials_thin_transparency"].IsObject()) 94 | { 95 | std::shared_ptr extension; 96 | if (!(extension << _JsonValue["ADOBE_materials_thin_transparency"])) return false; 97 | _rData.properties.insert(std::make_pair("ADOBE_materials_thin_transparency", extension)); 98 | } 99 | if (_JsonValue.HasMember("AGI_articulations") && _JsonValue["AGI_articulations"].IsObject()) 100 | { 101 | std::shared_ptr extension; 102 | if (!(extension << _JsonValue["AGI_articulations"])) return false; 103 | _rData.properties.insert(std::make_pair("AGI_articulations", extension)); 104 | } 105 | if (_JsonValue.HasMember("AGI_stk_metadata") && _JsonValue["AGI_stk_metadata"].IsObject()) 106 | { 107 | std::shared_ptr extension; 108 | if (!(extension << _JsonValue["AGI_stk_metadata"])) return false; 109 | _rData.properties.insert(std::make_pair("AGI_stk_metadata", extension)); 110 | } 111 | if (_JsonValue.HasMember("CESIUM_primitive_outline") && _JsonValue["CESIUM_primitive_outline"].IsObject()) 112 | { 113 | std::shared_ptr extension; 114 | if (!(extension << _JsonValue["CESIUM_primitive_outline"])) return false; 115 | _rData.properties.insert(std::make_pair("CESIUM_primitive_outline", extension)); 116 | } 117 | if (_JsonValue.HasMember("EXT_lights_ies") && _JsonValue["EXT_lights_ies"].IsObject()) 118 | { 119 | std::shared_ptr extension; 120 | if (!(extension << _JsonValue["EXT_lights_ies"])) return false; 121 | _rData.properties.insert(std::make_pair("EXT_lights_ies", extension)); 122 | } 123 | if (_JsonValue.HasMember("EXT_mesh_gpu_instancing") && _JsonValue["EXT_mesh_gpu_instancing"].IsObject()) 124 | { 125 | std::shared_ptr extension; 126 | if (!(extension << _JsonValue["EXT_mesh_gpu_instancing"])) return false; 127 | _rData.properties.insert(std::make_pair("EXT_mesh_gpu_instancing", extension)); 128 | } 129 | if (_JsonValue.HasMember("EXT_texture_webp") && _JsonValue["EXT_texture_webp"].IsObject()) 130 | { 131 | std::shared_ptr extension; 132 | if (!(extension << _JsonValue["EXT_texture_webp"])) return false; 133 | _rData.properties.insert(std::make_pair("EXT_texture_webp", extension)); 134 | } 135 | if (_JsonValue.HasMember("FB_geometry_metadata") && _JsonValue["FB_geometry_metadata"].IsObject()) 136 | { 137 | std::shared_ptr extension; 138 | if (!(extension << _JsonValue["FB_geometry_metadata"])) return false; 139 | _rData.properties.insert(std::make_pair("FB_geometry_metadata", extension)); 140 | } 141 | if (_JsonValue.HasMember("MSFT_lod") && _JsonValue["MSFT_lod"].IsObject()) 142 | { 143 | std::shared_ptr extension; 144 | if (!(extension << _JsonValue["MSFT_lod"])) return false; 145 | _rData.properties.insert(std::make_pair("MSFT_lod", extension)); 146 | } 147 | if (_JsonValue.HasMember("MSFT_texture_dds") && _JsonValue["MSFT_texture_dds"].IsObject()) 148 | { 149 | std::shared_ptr extension; 150 | if (!(extension << _JsonValue["MSFT_texture_dds"])) return false; 151 | _rData.properties.insert(std::make_pair("MSFT_texture_dds", extension)); 152 | } 153 | _rData.schemaType = "extension.schema.json"; 154 | return true; -------------------------------------------------------------------------------- /tools/batch/codes/extension.schema.json.variable.cpp: -------------------------------------------------------------------------------- 1 | properties() -------------------------------------------------------------------------------- /tools/batch/codes/libgltf.header.begin.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBGLTF_H 2 | #define LIBGLTF_H 3 | -------------------------------------------------------------------------------- /tools/batch/codes/libgltf.header.end.h: -------------------------------------------------------------------------------- 1 | #endif // LIBGLTF_H 2 | -------------------------------------------------------------------------------- /tools/batch/codes/libgltf.header.include.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | -------------------------------------------------------------------------------- /tools/batch/codes/libgltf.header.namespace.begin.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code4game/libgltf/abb907264c42a6d3059f50a8bd0808ac97255054/tools/batch/codes/libgltf.header.namespace.begin.h -------------------------------------------------------------------------------- /tools/batch/codes/libgltf.header.namespace.end.h: -------------------------------------------------------------------------------- 1 | enum class EAccessorComponentType : uint32_t 2 | { 3 | NONE, 4 | BYTE, 5 | UNSIGNED_BYTE, 6 | SHORT, 7 | UNSIGNED_SHORT, 8 | INT, 9 | UNSIGNED_INT, 10 | FLOAT, 11 | MAX, 12 | }; 13 | 14 | template 15 | class TComponentData 16 | { 17 | public: 18 | typedef TType value_type; 19 | 20 | public: 21 | operator EAccessorComponentType() const 22 | { 23 | return EAccessorComponentType::NONE; 24 | } 25 | }; 26 | 27 | #define LIBGLTF_ACCESSORCOMPONENTDATA(TType, EType)\ 28 | template<>\ 29 | class TComponentData\ 30 | {\ 31 | public:\ 32 | operator EAccessorComponentType() const\ 33 | {\ 34 | return EType;\ 35 | }\ 36 | template\ 37 | bool operator==(TComponentData _Another) const\ 38 | {\ 39 | return (EAccessorComponentType(_Another) == EType);\ 40 | }\ 41 | } 42 | LIBGLTF_ACCESSORCOMPONENTDATA(int8_t , EAccessorComponentType::BYTE ); 43 | LIBGLTF_ACCESSORCOMPONENTDATA(uint8_t , EAccessorComponentType::UNSIGNED_BYTE ); 44 | LIBGLTF_ACCESSORCOMPONENTDATA(int16_t , EAccessorComponentType::SHORT ); 45 | LIBGLTF_ACCESSORCOMPONENTDATA(uint16_t , EAccessorComponentType::UNSIGNED_SHORT); 46 | LIBGLTF_ACCESSORCOMPONENTDATA(int32_t , EAccessorComponentType::INT ); 47 | LIBGLTF_ACCESSORCOMPONENTDATA(uint32_t , EAccessorComponentType::UNSIGNED_INT ); 48 | LIBGLTF_ACCESSORCOMPONENTDATA(float , EAccessorComponentType::FLOAT ); 49 | 50 | struct SAccessorComponentType 51 | { 52 | size_t value; 53 | size_t size; 54 | }; 55 | 56 | const SAccessorComponentType GSAccessorComponentTypes[uint32_t(EAccessorComponentType::MAX)] = { 57 | SAccessorComponentType{ 0 , 0 }, 58 | SAccessorComponentType{ 5120, sizeof(int8_t) }, 59 | SAccessorComponentType{ 5121, sizeof(uint8_t) }, 60 | SAccessorComponentType{ 5122, sizeof(int16_t) }, 61 | SAccessorComponentType{ 5123, sizeof(uint16_t) }, 62 | SAccessorComponentType{ 5124, sizeof(int32_t) }, 63 | SAccessorComponentType{ 5125, sizeof(uint32_t) }, 64 | SAccessorComponentType{ 5126, sizeof(float) } 65 | }; 66 | 67 | enum class EAccessorType : uint8_t 68 | { 69 | NONE, 70 | SCALAR, 71 | VEC2, 72 | VEC3, 73 | VEC4, 74 | MAT2, 75 | MAT3, 76 | MAT4, 77 | MAX, 78 | }; 79 | 80 | struct SAccessorType 81 | { 82 | std::string text; 83 | size_t dimension; 84 | }; 85 | 86 | const SAccessorType GSAccessorTypes[uint8_t(EAccessorType::MAX)] = { 87 | SAccessorType{ "" , 0 }, 88 | SAccessorType{ "SCALAR" , 1 }, 89 | SAccessorType{ "VEC2" , 2 }, 90 | SAccessorType{ "VEC3" , 3 }, 91 | SAccessorType{ "VEC4" , 4 }, 92 | SAccessorType{ "MAT2" , 4 }, 93 | SAccessorType{ "MAT3" , 9 }, 94 | SAccessorType{ "MAT4" , 16 } 95 | }; 96 | 97 | int32_t AccessorComponentTypeToInt32(EAccessorComponentType _eType); 98 | EAccessorComponentType Int32ToAccessorComponentType(int32_t _iValue); 99 | const std::string& AccessorTypeToText(EAccessorType _eType); 100 | EAccessorType TextToAccessorType(const std::string& _eText, bool _bCaseCensitive = true); 101 | size_t SizeOfAccessorComponentType(EAccessorComponentType _eType); 102 | size_t DimensionOfAccessorType(EAccessorType _eType); 103 | size_t SizeOfAccessor(EAccessorComponentType _eAccessorComponentType, size_t _iCount, EAccessorType _eAccessorType); 104 | 105 | struct SBufferData 106 | { 107 | SBufferData(); 108 | 109 | const uint8_t* buffer; 110 | size_t bufferSize; 111 | size_t bufferStride; 112 | }; 113 | 114 | #define LIBGLTF_ACCESSORCOMPONENT_CASE(TType, EType)\ 115 | case EType: {\ 116 | _Vector.Resize(count);\ 117 | for (size_t i = 0; i < count; ++i)\ 118 | {\ 119 | for (size_t j = 0; j < dimension_of_accessor_type; ++j)\ 120 | {\ 121 | _Vector[i][j] = static_cast(*((TType*)bufferData.buffer + i * dimension_of_accessor_type + j));\ 122 | }\ 123 | }\ 124 | } break 125 | 126 | /// help to operate the accessor data 127 | struct SAccessorData 128 | { 129 | SAccessorData(); 130 | 131 | EAccessorComponentType componentType; 132 | size_t count; 133 | EAccessorType type; 134 | size_t bufferStride; 135 | SBufferData bufferData; 136 | 137 | template 138 | bool operator>>(TVector& _Vector) const 139 | { 140 | const size_t dimension_of_accessor_type = DimensionOfAccessorType(type); 141 | // not allow to convert to another with the different dimension 142 | if (dimension_of_accessor_type != TVector::Dimension) return false; 143 | 144 | const size_t sizeof_data = SizeOfAccessor(componentType, 1, type); 145 | if (bufferStride != 0 && bufferStride != sizeof_data) return false; 146 | 147 | const size_t sizeof_accessor = sizeof_data * count; 148 | if (sizeof_accessor > bufferData.bufferSize) return false; 149 | 150 | if (count > 0) 151 | { 152 | EAccessorComponentType v_component_type = TComponentData(); 153 | if (componentType == v_component_type) 154 | { 155 | _Vector.Resize(count); 156 | ::memcpy(_Vector.Data(), bufferData.buffer, sizeof_accessor); 157 | } 158 | else 159 | { 160 | switch (componentType) 161 | { 162 | LIBGLTF_ACCESSORCOMPONENT_CASE(int8_t , EAccessorComponentType::BYTE ); 163 | LIBGLTF_ACCESSORCOMPONENT_CASE(uint8_t , EAccessorComponentType::UNSIGNED_BYTE ); 164 | LIBGLTF_ACCESSORCOMPONENT_CASE(int16_t , EAccessorComponentType::SHORT ); 165 | LIBGLTF_ACCESSORCOMPONENT_CASE(uint16_t , EAccessorComponentType::UNSIGNED_SHORT); 166 | LIBGLTF_ACCESSORCOMPONENT_CASE(int32_t , EAccessorComponentType::INT ); 167 | LIBGLTF_ACCESSORCOMPONENT_CASE(uint32_t , EAccessorComponentType::UNSIGNED_INT ); 168 | LIBGLTF_ACCESSORCOMPONENT_CASE(float , EAccessorComponentType::FLOAT ); 169 | 170 | default: 171 | // not support 172 | return false; 173 | } 174 | } 175 | } 176 | return true; 177 | } 178 | }; 179 | 180 | class IAccessorStream 181 | { 182 | public: 183 | virtual bool operator<<(const SAccessorData& accessor_data) = 0; 184 | }; 185 | 186 | /// a dimension vertex that supports to construct some vertex variables like vec2, vec3, vec4, etc 187 | template 188 | class TVertex 189 | { 190 | public: 191 | static const size_t Dimension = VDim; 192 | 193 | public: 194 | const TType& operator[](size_t index) const 195 | { 196 | return m_aData[index]; 197 | } 198 | 199 | TType& operator[](size_t index) 200 | { 201 | return m_aData[index]; 202 | } 203 | 204 | private: 205 | TType m_aData[Dimension]; 206 | }; 207 | 208 | /// a vector, contains some vertex datas 209 | template 210 | class TVertexList : public std::vector > 211 | { 212 | public: 213 | typedef std::vector > TSuper; 214 | typedef typename TSuper::value_type TValue; 215 | typedef TType TComponent; 216 | 217 | public: 218 | static const size_t Dimension = TValue::Dimension; 219 | 220 | public: 221 | void Resize(size_t new_size) 222 | { 223 | TSuper::resize(new_size); 224 | } 225 | 226 | const TValue* Data() const 227 | { 228 | return TSuper::data(); 229 | } 230 | 231 | TValue* Data() 232 | { 233 | return TSuper::data(); 234 | } 235 | }; 236 | 237 | /// help to pass the vector 238 | template 239 | class TAccessorStream : public libgltf::IAccessorStream 240 | { 241 | public: 242 | explicit TAccessorStream(TVector& _Vector) 243 | : m_Vector(_Vector) 244 | { 245 | // 246 | } 247 | 248 | public: 249 | virtual bool operator<<(const libgltf::SAccessorData& accessor_data) override 250 | { 251 | return (accessor_data >> m_Vector); 252 | } 253 | 254 | private: 255 | TVector& m_Vector; 256 | }; 257 | 258 | /// gltf loader 259 | class IglTFLoader 260 | { 261 | public: 262 | static std::shared_ptr Create(std::function(const std::string&)> _reader); 263 | 264 | public: 265 | /// get the glTF structure 266 | virtual const std::unique_ptr& glTF() const = 0; 267 | 268 | /// load the indices data 269 | virtual bool LoadMeshPrimitiveIndicesData(size_t _mesh_index, size_t _primitive_index, std::shared_ptr _accessor_stream) = 0; 270 | 271 | /// load the attribute data like position, normal, texcoord, etc 272 | virtual bool LoadMeshPrimitiveAttributeData(size_t _mesh_index, size_t _primitive_index, const std::string& _attribute, std::shared_ptr _accessor_stream) = 0; 273 | 274 | /// load the image data and type 275 | virtual bool LoadImageData(size_t _index, std::vector& _data, std::string& _type) = 0; 276 | }; 277 | -------------------------------------------------------------------------------- /tools/batch/codes/libgltf.parser.h: -------------------------------------------------------------------------------- 1 | #include "libgltf/libgltf.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace libgltf 8 | { 9 | typedef rapidjson::UTF8 JSONChar; 10 | typedef rapidjson::SizeType JSONSizeType; 11 | typedef rapidjson::GenericDocument JSONCharDocument; 12 | typedef rapidjson::GenericValue JSONCharValue; 13 | typedef rapidjson::GenericStringRef JSONStringRef; 14 | typedef rapidjson::GenericStringBuffer JSONStringBuffer; 15 | typedef rapidjson::Writer JSONWriter; 16 | typedef rapidjson::GenericArray JSONCharConstArray; 17 | typedef rapidjson::GenericArray JSONCharArray; 18 | typedef rapidjson::GenericObject JSONCharConstObject; 19 | typedef rapidjson::GenericObject JSONCharObject; 20 | } 21 | -------------------------------------------------------------------------------- /tools/batch/glTF_2.0_schema.ini: -------------------------------------------------------------------------------- 1 | [glTF] 2 | schema_directory=%(CD)s/../../external/glTF/specification/2.0/schema/ 3 | code_file_name=libgltf 4 | extensions_schema_directories= 5 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_draco_mesh_compression/schema, 6 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_lights_punctual/schema, 7 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_clearcoat/schema, 8 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_emissive_strength/schema, 9 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_ior/schema, 10 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_iridescence/schema, 11 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_sheen/schema, 12 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_specular/schema, 13 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_transmission/schema, 14 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_unlit/schema, 15 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_variants/schema, 16 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_materials_volume/schema, 17 | %(CD)s/../../external/glTF/extensions/2.0/Khronos/KHR_texture_transform/schema, 18 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/ADOBE_materials_thin_transparency/schema, 19 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/AGI_articulations/schema, 20 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/AGI_stk_metadata/schema, 21 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/CESIUM_primitive_outline/schema, 22 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/EXT_lights_ies/schema, 23 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/schema, 24 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/EXT_texture_webp/schema, 25 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/FB_geometry_metadata/schema, 26 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/MSFT_lod/schema, 27 | %(CD)s/../../external/glTF/extensions/2.0/Vendor/MSFT_texture_dds/schema 28 | major_version=0 29 | minor_version=1 30 | patch_version=11 31 | 32 | [code] 33 | license=%(CD)s/../../LICENSE.md 34 | 35 | [code.headers] 36 | extension.schema.json=%(CD)s/codes/extension.schema.json.h 37 | header.begin=%(CD)s/codes/libgltf.header.begin.h 38 | header.end=%(CD)s/codes/libgltf.header.end.h 39 | header.include=%(CD)s/codes/libgltf.header.include.h 40 | header.namespace.begin=%(CD)s/codes/libgltf.header.namespace.begin.h 41 | header.namespace.end=%(CD)s/codes/libgltf.header.namespace.end.h 42 | 43 | [code.sources.variable] 44 | extension.schema.json=%(CD)s/codes/extension.schema.json.variable.cpp 45 | 46 | [code.sources.function] 47 | extension.schema.json=%(CD)s/codes/extension.schema.json.function.cpp 48 | 49 | [code.parser] 50 | header=%(CD)s/codes/libgltf.parser.h 51 | 52 | [code.parsers.to] 53 | extension.schema.json=%(CD)s/codes/extension.schema.json.parser.to.cpp 54 | 55 | [code.parsers.from] 56 | extension.schema.json=%(CD)s/codes/extension.schema.json.parser.from.cpp 57 | 58 | [output] 59 | output_header_path=%(CD)s/../../source/libgltf 60 | output_source_path=%(CD)s/../../source/libgltf 61 | namespace=libgltf 62 | -------------------------------------------------------------------------------- /tools/batch/update_parser_by_scheme.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | echo Generate the cpp code by glTF 2.0 schema files 3 | python .\..\..\tools\jsonschematoc11 glTF_2.0_schema.ini -------------------------------------------------------------------------------- /tools/batch/update_parser_by_scheme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo Generate the cpp code by glTF 2.0 schema files 3 | python ./../../tools/jsonschematoc11 glTF_2.0_schema.ini -------------------------------------------------------------------------------- /tools/jsonschematoc11/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TOOLS_JSONSCHEMATOC11_PATH "${TOOLS_PATH}/jsonschematoc11") 2 | 3 | set(TOOLS_JSONSCHEMATOC11_ROOT_FILE_LIST 4 | ${TOOLS_JSONSCHEMATOC11_PATH}/__init__.py 5 | ${TOOLS_JSONSCHEMATOC11_PATH}/__main__.py 6 | ${TOOLS_JSONSCHEMATOC11_PATH}/jsonschematoc11.py 7 | ) 8 | 9 | set(TOOLS_JSONSCHEMATOC11_C11TYPES_FILE_LIST 10 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/__init__.py 11 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11type.py 12 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11typearray.py 13 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11typebool.py 14 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11typeinteger.py 15 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11typemap.py 16 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11typenone.py 17 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11typenumber.py 18 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11typestring.py 19 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11typestruct.py 20 | ${TOOLS_JSONSCHEMATOC11_PATH}/c11types/c11variable.py 21 | ) 22 | 23 | source_group("script" FILES ${TOOLS_JSONSCHEMATOC11_ROOT_FILE_LIST}) 24 | source_group("script\\c11types" FILES ${TOOLS_JSONSCHEMATOC11_C11TYPES_FILE_LIST}) 25 | 26 | add_custom_target(jsonschematoc11 SOURCES ${TOOLS_JSONSCHEMATOC11_ROOT_FILE_LIST} ${TOOLS_JSONSCHEMATOC11_C11TYPES_FILE_LIST}) 27 | set_property(TARGET jsonschematoc11 PROPERTY FOLDER tools) 28 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/__init__.py: -------------------------------------------------------------------------------- 1 | """Build C11 code lines.""" 2 | 3 | import sys 4 | from .jsonschematoc11 import JSONSchemaToC11 5 | 6 | if __name__ == u'__main__': 7 | (error_code, error_message) = JSONSchemaToC11(sys.argv[1:]) 8 | if error_code != 0: 9 | print(u'Failed: ', error_message) 10 | sys.exit(error_code) 11 | else: 12 | print(u'Success') 13 | sys.exit(error_code) 14 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/__main__.py: -------------------------------------------------------------------------------- 1 | """Build C11 code lines.""" 2 | 3 | import sys 4 | from jsonschematoc11 import JSONSchemaToC11 5 | 6 | if __name__ == u'__main__': 7 | (error_code, error_message) = JSONSchemaToC11(sys.argv[1:]) 8 | if error_code != 0: 9 | print(u'Failed: ', error_message) 10 | sys.exit(error_code) 11 | else: 12 | print(u'Success') 13 | sys.exit(error_code) 14 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/__init__.py: -------------------------------------------------------------------------------- 1 | """Build C11 types.""" 2 | 3 | from .c11typebool import C11TypeBool 4 | from .c11typeinteger import C11TypeInteger 5 | from .c11typenumber import C11TypeNumber 6 | from .c11typestring import C11TypeString 7 | from .c11typearray import C11TypeArray 8 | from .c11typestruct import C11TypeStruct 9 | 10 | def BuildC11Type(schemaName, schemaValue, isSchema=False, manualCodeHeaders=None, manualCodeSourcesVariable=None, manualCodeSourcesFunction=None, manualCodeParsersFrom=None, manualCodeParsersTo=None): 11 | if u'title' not in schemaValue: 12 | return (None, 1, u'can\'t get the attribute `title` in %s' % schemaName) 13 | c11Type = None 14 | if not isSchema and u'type' in schemaValue: 15 | schemaValueType = schemaValue[u'type'] 16 | if schemaValueType == u'bool' or schemaValueType == u'boolean': 17 | c11Type = C11TypeBool() 18 | elif schemaValueType == u'integer': 19 | c11Type = C11TypeInteger() 20 | elif schemaValueType == u'number': 21 | c11Type = C11TypeNumber() 22 | elif schemaValueType == u'string': 23 | c11Type = C11TypeString() 24 | elif schemaValueType == u'array': 25 | c11Type = C11TypeArray() 26 | #elif schemaValueType == u'object': 27 | # c11Type = C11TypeMap() 28 | if c11Type is None: 29 | c11Type = C11TypeStruct() 30 | c11Type.setSchema(schemaName, schemaValue) 31 | c11Type.setCodes(manualCodeHeaders, manualCodeSourcesVariable, manualCodeSourcesFunction, manualCodeParsersFrom, manualCodeParsersTo) 32 | return (c11Type, 0, None) 33 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11type.py: -------------------------------------------------------------------------------- 1 | import abc 2 | 3 | class C11Type(object): 4 | 5 | """basic type.""" 6 | 7 | def __init__(self): 8 | """Construct and declare some vars.""" 9 | self.schemaName = None 10 | self.schemaValue = None 11 | self.typeName = None 12 | 13 | def setCodes(self, manualCodeHeaders, manualCodeSourcesVariable, manualCodeSourcesFunction, manualCodeParsersFrom, manualCodeParsersTo): 14 | self.manualCodeHeaders = manualCodeHeaders 15 | self.manualCodeSourcesVariable = manualCodeSourcesVariable 16 | self.manualCodeSourcesFunction = manualCodeSourcesFunction 17 | self.manualCodeParsersFrom = manualCodeParsersFrom 18 | self.manualCodeParsersTo = manualCodeParsersTo 19 | 20 | def setSchema(self, schemaName, schemaValue): 21 | self.schemaName = schemaName 22 | self.schemaValue = schemaValue 23 | self.typeName = schemaValue[u'title'] 24 | self.typeName = self.typeName.replace(u' ', u'') 25 | self.typeName = self.typeName.replace(u'.', u'') 26 | self.typeName = self.typeName.replace(u'/', u'') 27 | self.typeName = u'S' + self.typeName[:1].upper() + self.typeName[1:] 28 | if u'description' in schemaValue: 29 | self.description = schemaValue[u'description'] 30 | 31 | @abc.abstractmethod 32 | def revise(self, c11Types): 33 | return (0, u'') 34 | 35 | @abc.abstractmethod 36 | def codeTypeName(self, withDeclare=False, asVariable=False, withDocument=False): 37 | return self.typeName 38 | 39 | @abc.abstractmethod 40 | def codeDefineVariable(self, variableName, withDeclare=False, withDefault=False): 41 | pass 42 | 43 | @abc.abstractmethod 44 | def codeSetDefaultInConstructor(self): 45 | pass 46 | 47 | @abc.abstractmethod 48 | def codeHeader(self, codeTypeNames): 49 | return [u''] 50 | 51 | @abc.abstractmethod 52 | def codeSource(self, codeTypeNames): 53 | return [u''] 54 | 55 | @abc.abstractmethod 56 | def codeDefaultValue(self, schemaDefaultValue): 57 | return u'' 58 | 59 | @abc.abstractmethod 60 | def codeDefaultValueArray(self, schemaDefaultValue): 61 | return u'' 62 | 63 | @abc.abstractmethod 64 | def codeJsonCheck(self): 65 | return None 66 | 67 | @abc.abstractmethod 68 | def codeJsonSet(self, dataName, variableName): 69 | return None 70 | 71 | @abc.abstractmethod 72 | def codeJsonGet(self, dataName, variableName): 73 | return None 74 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11typearray.py: -------------------------------------------------------------------------------- 1 | from .c11type import C11Type 2 | 3 | class C11TypeArray(C11Type): 4 | 5 | """array type""" 6 | 7 | def __init__(self): 8 | """Construct and declare some vars.""" 9 | C11Type.__init__(self) 10 | self.typeName = u'std::vector' 11 | self.c11Type = None 12 | 13 | def buildC11Type(self, schemaValue): 14 | c11Type = None 15 | schemaValueType = None 16 | variableSchemaValue = schemaValue 17 | if u'type' in schemaValue: 18 | schemaValueType = schemaValue[u'type'] 19 | if schemaValueType == u'object': 20 | if u'additionalProperties' in schemaValue: 21 | schemaValueType = u'map' 22 | variableSchemaValue = schemaValue[u'additionalProperties'] 23 | elif u'allOf' in schemaValue and len(schemaValue[u'allOf']) > 0 and u'$ref' in schemaValue[u'allOf'][0]: 24 | schemaValueType = schemaValue[u'allOf'][0][u'$ref'] 25 | #print(schemaValueType) 26 | #schemaValueType = u'array' 27 | #doallof = True 28 | elif u'$ref' in schemaValue: 29 | schemaValueType = schemaValue[u'$ref'] 30 | 31 | if schemaValueType == u'bool' or schemaValueType == u'boolean': 32 | from .c11typebool import C11TypeBool 33 | c11Type = C11TypeBool() 34 | elif schemaValueType == u'integer': 35 | from .c11typeinteger import C11TypeInteger 36 | c11Type = C11TypeInteger() 37 | elif schemaValueType == u'number': 38 | from .c11typenumber import C11TypeNumber 39 | c11Type = C11TypeNumber() 40 | elif schemaValueType == u'string': 41 | from .c11typestring import C11TypeString 42 | c11Type = C11TypeString() 43 | elif schemaValueType == u'array': 44 | c11Type = C11TypeArray() 45 | elif schemaValueType == u'map': 46 | from .c11typemap import C11TypeMap 47 | c11Type = C11TypeMap() 48 | c11Type.setItemSchema(variableSchemaValue) 49 | if c11Type is None: 50 | from .c11typestruct import C11TypeStruct 51 | c11Type = C11TypeStruct() 52 | return (c11Type, 0, None) 53 | 54 | def setItemSchema(self, schemaValue): 55 | self.typeName = u'std::vector' 56 | self.schemaValue = schemaValue 57 | if u'items' in schemaValue: 58 | (c11_type, error_code, error_message) = self.buildC11Type(schemaValue[u'items']) 59 | elif u'$ref' in schemaValue: 60 | (c11_type, error_code, error_message) = self.buildC11Type(schemaValue[u'$ref']) 61 | if error_code != 0: 62 | print(error_message) 63 | self.c11Type = c11_type 64 | 65 | def revise(self, c11Types): 66 | from .c11typestruct import C11TypeStruct 67 | from .c11typemap import C11TypeMap 68 | if not isinstance(self.c11Type, C11TypeStruct) and not isinstance(self.c11Type, C11TypeMap): 69 | return (0, None) 70 | schemaValueType = None 71 | schemaValueItem = None 72 | if u'items' in self.schemaValue: 73 | schemaValueItem = self.schemaValue[u'items'] 74 | if u'$ref' in self.schemaValue: 75 | schemaValueItem = self.schemaValue 76 | if schemaValueItem is None: 77 | return (1, u'Can\'t find the items in schema of array') 78 | elif u'type' in schemaValueItem and schemaValueItem[u'type'] == 'object' and u'allOf' in schemaValueItem and len(schemaValueItem[u'allOf']) > 0 and u'$ref' in schemaValueItem[u'allOf'][0]: 79 | schemaValueType = schemaValueItem[u'allOf'][0][u'$ref'] 80 | elif u'$ref' in schemaValueItem: 81 | schemaValueType = schemaValueItem[u'$ref'] 82 | if schemaValueType not in c11Types: 83 | if u'additionalProperties' in schemaValueItem: 84 | schemaValueAdditionalProperties = schemaValueItem[u'additionalProperties'] 85 | if u'$ref' in schemaValueAdditionalProperties: 86 | schemaValueType = schemaValueAdditionalProperties[u'$ref'] 87 | if isinstance(self.c11Type, C11TypeMap): 88 | self.c11Type.revise(c11Types) 89 | elif schemaValueType in c11Types: 90 | self.c11Type = c11Types[schemaValueType] 91 | else: 92 | from .c11typenone import C11TypeNone 93 | self.c11Type = C11TypeNone() 94 | return (0, u'') 95 | 96 | def codeTypeName(self, withDeclare=False, asVariable=False, withDocument=False): 97 | #if withDocument: 98 | # return u'TDataDoc<%s<%s>>' % (self.typeName, self.c11Type.codeTypeName(withDeclare=withDeclare, asVariable=True)) 99 | return u'%s<%s>' % (self.typeName, self.c11Type.codeTypeName(withDeclare=withDeclare, asVariable=asVariable, withDocument=withDocument)) 100 | 101 | def codeDefaultValue(self, schemaDefaultValue): 102 | if schemaDefaultValue is None: 103 | return u'' 104 | return self.c11Type.codeDefaultValueArray(schemaDefaultValue) 105 | 106 | def codeJsonCheck(self): 107 | return u'IsArray()' 108 | 109 | def codeJsonSet(self, dataName, variableName): 110 | return u'if (!(%s.%s << _JsonValue["%s"])) return false;' % (dataName, variableName, variableName) 111 | 112 | def codeJsonGet(self, dataName, variableName): 113 | return u'if (!(%s.%s >> _JsonValue["%s"])) return false;' % (dataName, variableName, variableName) 114 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11typebool.py: -------------------------------------------------------------------------------- 1 | from .c11type import C11Type 2 | 3 | class C11TypeBool(C11Type): 4 | def __init__(self): 5 | """Construct and declare some vars.""" 6 | C11Type.__init__(self) 7 | self.typeName = u'bool' 8 | 9 | def setSchema(self, schemaName, schemaValue): 10 | C11Type.setSchema(self, schemaName, schemaValue) 11 | 12 | def codeDefaultValue(self, schemaDefaultValue): 13 | if schemaDefaultValue is not None and schemaDefaultValue is True: 14 | return u'true' 15 | return u'false' 16 | 17 | def codeDefaultValueArray(self, schemaDefaultValues): 18 | if schemaDefaultValues is None\ 19 | or not isinstance(schemaDefaultValues, list)\ 20 | or len(schemaDefaultValues) <= 0: 21 | return u'' 22 | code_default_value = u'' 23 | for schema_value in schemaDefaultValues: 24 | if len(code_default_value) > 0: 25 | code_default_value = code_default_value + u', ' 26 | if schema_value == True: 27 | code_default_value = code_default_value + u'true' 28 | else: 29 | code_default_value = code_default_value + u'false' 30 | return u'{ %s }' % code_default_value 31 | 32 | def codeJsonCheck(self): 33 | return u'IsBool()' 34 | 35 | def codeJsonSet(self, dataName, variableName): 36 | return u'%s.%s = _JsonValue["%s"].GetBool();' % (dataName, variableName, variableName) 37 | 38 | def codeJsonGet(self, dataName, variableName): 39 | return u'_JsonValue["%s"].SetBool(%s.%s);' % (variableName, dataName, variableName) 40 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11typeinteger.py: -------------------------------------------------------------------------------- 1 | from .c11type import C11Type 2 | 3 | class C11TypeInteger(C11Type): 4 | def __init__(self): 5 | """Construct and declare some vars.""" 6 | C11Type.__init__(self) 7 | self.typeName = u'int32_t' 8 | 9 | def setSchema(self, schemaName, schemaValue): 10 | C11Type.setSchema(self, schemaName, schemaValue) 11 | self.typeName = u'int32_t' 12 | 13 | def codeDefaultValue(self, schemaDefaultValue): 14 | if schemaDefaultValue != None: 15 | return u'%d' % schemaDefaultValue 16 | return u'0' 17 | 18 | def codeDefaultValueArray(self, schemaDefaultValues): 19 | if schemaDefaultValues is None or isinstance(schemaDefaultValues, list) or len(schemaDefaultValues) <= 0: 20 | return u'' 21 | code_default_value = u'' 22 | for schema_value in schemaDefaultValues: 23 | if len(code_default_value) > 0: 24 | code_default_value = code_default_value + u', ' 25 | code_default_value = code_default_value + u'%d' % schema_value 26 | return u'{ %s }' % code_default_value 27 | 28 | def codeJsonCheck(self): 29 | return u'IsInt()' 30 | 31 | def codeJsonSet(self, dataName, variableName): 32 | return u'%s.%s = _JsonValue["%s"].GetInt();' % (dataName, variableName, variableName) 33 | 34 | def codeJsonGet(self, dataName, variableName): 35 | return u'_JsonValue["%s"].SetInt(%s.%s);' % (variableName, dataName, variableName) 36 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11typemap.py: -------------------------------------------------------------------------------- 1 | from .c11type import C11Type 2 | 3 | class C11TypeMap(C11Type): 4 | 5 | """map type.""" 6 | 7 | def __init__(self): 8 | """Construct and declare some vars.""" 9 | C11Type.__init__(self) 10 | self.typeName = u'std::map' 11 | self.c11Type = None 12 | 13 | def buildC11Type(self, schemaValue): 14 | c11Type = None 15 | if u'type' in schemaValue: 16 | schemaValueType = schemaValue[u'type'] 17 | if schemaValueType == u'bool' or schemaValueType == u'boolean': 18 | from .c11typebool import C11TypeBool 19 | c11Type = C11TypeBool() 20 | elif schemaValueType == u'integer': 21 | from .c11typeinteger import C11TypeInteger 22 | c11Type = C11TypeInteger() 23 | elif schemaValueType == u'number': 24 | from .c11typenumber import C11TypeNumber 25 | c11Type = C11TypeNumber() 26 | elif schemaValueType == u'string': 27 | from .c11typestring import C11TypeString 28 | c11Type = C11TypeString() 29 | elif schemaValueType == u'array': 30 | from .c11typearray import C11TypeArray 31 | c11Type = C11TypeArray() 32 | if c11Type is None: 33 | from .c11typestruct import C11TypeStruct 34 | c11Type = C11TypeStruct() 35 | return (c11Type, 0, None) 36 | 37 | def setItemSchema(self, schemaValue): 38 | self.typeName = u'std::map' 39 | self.schemaValue = schemaValue 40 | if u'items' in schemaValue: 41 | (c11Type, _, _) = self.buildC11Type(schemaValue[u'items']) 42 | elif u'$ref' in schemaValue: 43 | (c11Type, _, _) = self.buildC11Type(schemaValue[u'$ref']) 44 | self.c11Type = c11Type 45 | 46 | def revise(self, c11Types): 47 | from .c11typestruct import C11TypeStruct 48 | if not isinstance(self.c11Type, C11TypeStruct): 49 | return (0, None) 50 | schemaValueType = None 51 | if u'$ref' in self.schemaValue: 52 | schemaValueType = self.schemaValue[u'$ref'] 53 | if schemaValueType in c11Types: 54 | self.c11Type = c11Types[schemaValueType] 55 | else: 56 | from .c11typenone import C11TypeNone 57 | self.c11Type = C11TypeNone() 58 | self.c11Type.revise(c11Types) 59 | return (0, u'') 60 | 61 | def codeTypeName(self, withDeclare=False, asVariable=False, withDocument=False): 62 | #if withDocument: 63 | # return u'TDataDoc<%s>' % (self.typeName, self.c11Type.codeTypeName(withDeclare=withDeclare, asVariable=True)) 64 | return u'%s' % (self.typeName, self.c11Type.codeTypeName(withDeclare=withDeclare, asVariable=asVariable, withDocument=withDocument)) 65 | 66 | def codeJsonCheck(self): 67 | return u'IsObject()' 68 | 69 | def codeJsonSet(self, dataName, variableName): 70 | return u'if (!(%s.%s << _JsonValue["%s"])) return false;' % (dataName, variableName, variableName) 71 | 72 | def codeJsonGet(self, dataName, variableName): 73 | return u'if (!(%s.%s >> _JsonValue["%s"])) return false;' % (dataName, variableName, variableName) 74 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11typenone.py: -------------------------------------------------------------------------------- 1 | from .c11type import C11Type 2 | 3 | class C11TypeNone(C11Type): 4 | def __init__(self): 5 | """Construct and declare some vars.""" 6 | C11Type.__init__(self) 7 | self.typeName = u'none' 8 | 9 | def setSchema(self, schemaName, schemaValue): 10 | C11Type.setSchema(self, schemaName, schemaValue) 11 | self.typeName = u'none' 12 | 13 | def codeTypeName(self, withDeclare=False, asVariable=False, withDocument=False): 14 | codeLine = self.typeName 15 | if withDeclare: 16 | if withDocument: 17 | codeLine = u'TDataDoc' % codeLine 18 | else: 19 | codeLine = u'struct %s' % codeLine 20 | else: 21 | if withDocument: 22 | codeLine = u'TDataDoc<%s>' % codeLine 23 | if asVariable: 24 | if withDocument: 25 | codeLine = u'TDataDoc>' % codeLine 26 | else: 27 | codeLine = u'std::shared_ptr<%s>' % codeLine 28 | return codeLine 29 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11typenumber.py: -------------------------------------------------------------------------------- 1 | from .c11type import C11Type 2 | 3 | class C11TypeNumber(C11Type): 4 | def __init__(self): 5 | """Construct and declare some vars.""" 6 | C11Type.__init__(self) 7 | self.typeName = u'float' 8 | 9 | def setSchema(self, schemaName, schemaValue): 10 | C11Type.setSchema(self, schemaName, schemaValue) 11 | self.typeName = u'float' 12 | 13 | def codeDefaultValue(self, schemaDefaultValue): 14 | if schemaDefaultValue != None: 15 | return u'%ff' % schemaDefaultValue 16 | return u'0.0f' 17 | 18 | def codeDefaultValueArray(self, schemaDefaultValues): 19 | if schemaDefaultValues is None\ 20 | or not isinstance(schemaDefaultValues, list)\ 21 | or len(schemaDefaultValues) <= 0: 22 | return u'' 23 | code_default_value = u'' 24 | for schema_value in schemaDefaultValues: 25 | if len(code_default_value) > 0: 26 | code_default_value = code_default_value + u', ' 27 | code_default_value = code_default_value + u'%ff' % schema_value 28 | return u'{ %s }' % code_default_value 29 | 30 | def codeJsonCheck(self): 31 | return u'IsNumber()' 32 | 33 | def codeJsonSet(self, dataName, variableName): 34 | return u'%s.%s = _JsonValue["%s"].GetFloat();' % (dataName, variableName, variableName) 35 | 36 | def codeJsonGet(self, dataName, variableName): 37 | return u'_JsonValue["%s"].SetFloat(%s.%s);' % (variableName, dataName, variableName) 38 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11typestring.py: -------------------------------------------------------------------------------- 1 | from .c11type import C11Type 2 | 3 | class C11TypeString(C11Type): 4 | 5 | """strig type.""" 6 | 7 | def __init__(self): 8 | """Construct and declare some vars.""" 9 | C11Type.__init__(self) 10 | self.typeName = u'std::string' 11 | 12 | def setSchema(self, schemaName, schemaValue): 13 | C11Type.setSchema(self, schemaName, schemaValue) 14 | 15 | def codeDefaultValue(self, schemaDefaultValue): 16 | if schemaDefaultValue != None: 17 | return u'"%s"' % schemaDefaultValue 18 | return u'""' 19 | 20 | def codeDefaultValueArray(self, schemaDefaultValues): 21 | if schemaDefaultValues is None\ 22 | or not isinstance(schemaDefaultValues, list)\ 23 | or len(schemaDefaultValues) <= 0: 24 | return u'' 25 | code_default_value = u'' 26 | for schema_value in schemaDefaultValues: 27 | if len(code_default_value) > 0: 28 | code_default_value = code_default_value + u', ' 29 | code_default_value = code_default_value + u'"%s"' % schema_value 30 | code_default_value = code_default_value[0:len(code_default_value) - 2] 31 | return u'{ %s }' % code_default_value 32 | 33 | def codeJsonCheck(self): 34 | return u'IsString()' 35 | 36 | def codeJsonSet(self, dataName, variableName): 37 | return u'%s.%s = _JsonValue["%s"].GetString();' % (dataName, variableName, variableName) 38 | 39 | def codeJsonGet(self, dataName, variableName): 40 | return u'_JsonValue["%s"].SetString(%s.%s.c_str(), _rData.doc->GetAllocator());' % (variableName, dataName, variableName) 41 | -------------------------------------------------------------------------------- /tools/jsonschematoc11/c11types/c11variable.py: -------------------------------------------------------------------------------- 1 | from .c11typebool import C11TypeBool 2 | from .c11typeinteger import C11TypeInteger 3 | from .c11typenumber import C11TypeNumber 4 | from .c11typestring import C11TypeString 5 | from .c11typearray import C11TypeArray 6 | from .c11typemap import C11TypeMap 7 | from .c11typenone import C11TypeNone 8 | 9 | class C11Variable(object): 10 | 11 | """variable.""" 12 | 13 | def __init__(self, name, schemaValue): 14 | """Construct and declare some vars.""" 15 | self.schemaValue = schemaValue 16 | self.typeName = "" 17 | self.c11Type = C11TypeNone() 18 | self.name = name 19 | self.comment = None 20 | if u'description' in schemaValue: 21 | self.comment = schemaValue[u'description'] 22 | 23 | def revise(self, c11Types): 24 | variableSchemaValue = self.schemaValue 25 | if u'$ref' in self.schemaValue: 26 | schemaValueType = self.schemaValue[u'$ref'] 27 | elif u'type' in self.schemaValue: 28 | schemaValueType = self.schemaValue[u'type'] 29 | if schemaValueType == u'object' and u'additionalProperties' in self.schemaValue: 30 | schemaValueType = u'map' 31 | variableSchemaValue = self.schemaValue[u'additionalProperties'] 32 | elif u'allOf' in self.schemaValue and len(self.schemaValue[u'allOf']) > 0 and u'$ref' in self.schemaValue[u'allOf'][0]: 33 | schemaValueType = self.schemaValue[u'allOf'][0][u'$ref'] 34 | #schemaValueType = u'array' 35 | #variableSchemaValue = self.schemaValue[u'allOf'][0] 36 | elif u'anyOf' in self.schemaValue and len(self.schemaValue[u'anyOf']) > 0: 37 | for schemaValueAnyOf in self.schemaValue[u'anyOf']: 38 | if u'type' not in schemaValueAnyOf: 39 | continue 40 | schemaValueType = schemaValueAnyOf[u'type'] 41 | break 42 | else: 43 | return (0, None) 44 | 45 | if schemaValueType == u'bool' or schemaValueType == u'boolean': 46 | self.c11Type = C11TypeBool() 47 | self.typeName = u'bool' 48 | elif schemaValueType == u'integer': 49 | self.c11Type = C11TypeInteger() 50 | self.typeName = u'integer' 51 | elif schemaValueType == u'number': 52 | self.c11Type = C11TypeNumber() 53 | self.typeName = u'number' 54 | elif schemaValueType == u'string': 55 | self.c11Type = C11TypeString() 56 | self.typeName = u'string' 57 | elif schemaValueType == u'array': 58 | self.c11Type = C11TypeArray() 59 | self.typeName = u'array' 60 | self.c11Type.setItemSchema(variableSchemaValue) 61 | elif schemaValueType == u'map': 62 | self.c11Type = C11TypeMap() 63 | self.typeName = u'map' 64 | self.c11Type.setItemSchema(variableSchemaValue) 65 | else: 66 | if schemaValueType not in c11Types: 67 | if u'additionalProperties' in self.schemaValue: 68 | schemaValueAdditionalProperties = self.schemaValue[u'additionalProperties'] 69 | if u'$ref' in schemaValueAdditionalProperties: 70 | schemaValueType = schemaValueAdditionalProperties[u'$ref'] 71 | if schemaValueType in c11Types: 72 | self.c11Type = c11Types[schemaValueType] 73 | self.typeName = u'struct' 74 | else: 75 | self.c11Type = C11TypeNone() 76 | self.c11Type.revise(c11Types) 77 | return (0, None) 78 | 79 | def hasComment(self): 80 | return self.comment != None 81 | 82 | def codeComment(self): 83 | return self.comment 84 | 85 | def codeDeclare(self): 86 | return u'%s %s' % (self.c11Type.codeTypeName(withDeclare=True, asVariable=True), self.name) 87 | 88 | def codeConstructorDefault(self): 89 | schemaDefaultValue = None 90 | if u'default' in self.schemaValue: 91 | schemaDefaultValue = self.schemaValue[u'default'] 92 | return u'%s(%s)' % (self.name, self.c11Type.codeDefaultValue(schemaDefaultValue)) 93 | 94 | def codeParser(self, isSet=True): 95 | codeLines = [] 96 | codeCheckLine = self.c11Type.codeJsonCheck() 97 | if isSet: 98 | if codeCheckLine is None or len(codeCheckLine) <= 0: 99 | codeLines.append(u'if (_JsonValue.HasMember("%s"))' % self.name) 100 | else: 101 | codeLines.append(u'if (_JsonValue.HasMember("%s") && _JsonValue["%s"].%s)' % (self.name, self.name, codeCheckLine)) 102 | else: 103 | if self.typeName == u'array' or self.typeName == u'map': 104 | codeLines.append(u'if (!_rData.data.%s.empty())' % self.name) 105 | elif self.typeName == u'struct': 106 | codeLines.append(u'if (!!_rData.data.%s)' % self.name) 107 | codeLines.append(u'{') 108 | if isSet: 109 | codeSetLine = self.c11Type.codeJsonSet(u'_rData', self.name) 110 | if codeSetLine != None and len(codeSetLine) > 0: 111 | codeLines.append(u' %s' % (codeSetLine)) 112 | else: 113 | codeLines.append(u' JSONCharValue json_value;') 114 | if self.typeName == u'struct': 115 | codeLines.append(u' if (!(%s(*_rData.data.%s, _rData.doc) >> json_value)) return false;' % (self.c11Type.codeTypeName(withDocument=True), self.name)) 116 | else: 117 | codeLines.append(u' if (!(TDataDoc<%s>(_rData.data.%s, _rData.doc) >> json_value)) return false;' % (self.c11Type.codeTypeName(asVariable=True), self.name)) 118 | codeLines.append(u' _JsonValue.AddMember("%s", json_value, _rData.doc->GetAllocator());' % self.name) 119 | codeLines.append(u'}') 120 | return codeLines 121 | --------------------------------------------------------------------------------