mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-08 19:23:50 +00:00
Compare commits
49 Commits
write-asse
...
jmousseau-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbd3885049 | ||
|
|
9471517c1e | ||
|
|
e59028d68f | ||
|
|
cfab524125 | ||
|
|
9229971bcb | ||
|
|
051149311c | ||
|
|
0c7789b1e5 | ||
|
|
51b12d2546 | ||
|
|
4749b0989d | ||
|
|
0bfcb4f49e | ||
|
|
17e6e310ce | ||
|
|
07ceb4c313 | ||
|
|
e7f1ff5c59 | ||
|
|
fd904063c9 | ||
|
|
38398cc2da | ||
|
|
ed1a294bc4 | ||
|
|
b86eb6c079 | ||
|
|
e4bc6c7bd4 | ||
|
|
13803659f8 | ||
|
|
a3d5d5d1c9 | ||
|
|
9e3d1f6db5 | ||
|
|
190382aecd | ||
|
|
c6501530e3 | ||
|
|
ed48224f4b | ||
|
|
19a41d20ec | ||
|
|
0598a20cce | ||
|
|
514167b475 | ||
|
|
0f76561ebf | ||
|
|
f3dc4acaa4 | ||
|
|
1588e75e26 | ||
|
|
d1453b5e5e | ||
|
|
7e83ef9fb4 | ||
|
|
425195bf9c | ||
|
|
ce3a30e612 | ||
|
|
8a35b8f6fe | ||
|
|
f66f3bfeb3 | ||
|
|
e29ba7c49a | ||
|
|
bc753d4ac5 | ||
|
|
688ba8a60e | ||
|
|
d07b976d59 | ||
|
|
08a7dd8dad | ||
|
|
87da1e775f | ||
|
|
151495558e | ||
|
|
84e15260ba | ||
|
|
03cdef430d | ||
|
|
fb4bd82e2c | ||
|
|
3ddf8301f6 | ||
|
|
298c37a954 | ||
|
|
001c870051 |
6
.github/workflows/c-cpp.yml
vendored
6
.github/workflows/c-cpp.yml
vendored
@@ -47,7 +47,8 @@ jobs:
|
||||
sudo apt-get install -y mingw-w64
|
||||
x86_64-w64-mingw32-g++ -std=c++11 -o loader_example loader_example.cc
|
||||
|
||||
# Windows(x64) + Visual Studio 2019 build
|
||||
# Windows(x64) + Visual Studio 2022 build
|
||||
# Assume windows-latest have VS2022 installed
|
||||
build-windows-msvc:
|
||||
|
||||
runs-on: windows-latest
|
||||
@@ -62,7 +63,8 @@ jobs:
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "Visual Studio 16 2019" -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=On ..
|
||||
cmake --help
|
||||
cmake -G "Visual Studio 17 2022" -A x64 -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=On ..
|
||||
cd ..
|
||||
- name: Build
|
||||
run: cmake --build build --config Release
|
||||
|
||||
@@ -4,10 +4,12 @@ PROJECT (tinygltf)
|
||||
|
||||
SET(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example" ON)
|
||||
option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example(load glTF and dump infos)" ON)
|
||||
option(TINYGLTF_BUILD_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF)
|
||||
option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator example" OFF)
|
||||
option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator exampe" OFF)
|
||||
option(TINYGLTF_BUILD_BUILDER_EXAMPLE "Build glTF builder example" OFF)
|
||||
option(TINYGLTF_HEADER_ONLY "On: header-only mode. Off: create tinygltf library(No TINYGLTF_IMPLEMENTATION required in your project)" OFF)
|
||||
option(TINYGLTF_INSTALL "Install tinygltf files during install step. Usually set to OFF if you include tinygltf through add_subdirectory()" ON)
|
||||
|
||||
if (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
||||
ADD_EXECUTABLE ( loader_example
|
||||
@@ -29,19 +31,46 @@ if (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||
endif (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||
|
||||
#
|
||||
# TinuGLTF is a header-only library, so no library build. just install header files.
|
||||
# for add_subdirectory and standalone build
|
||||
#
|
||||
INSTALL ( FILES
|
||||
json.hpp
|
||||
stb_image.h
|
||||
stb_image_write.h
|
||||
tiny_gltf.h
|
||||
DESTINATION
|
||||
include
|
||||
if (TINYGLTF_HEADER_ONLY)
|
||||
add_library(tinygltf INTERFACE)
|
||||
|
||||
target_include_directories(tinygltf
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
INSTALL ( FILES
|
||||
cmake/TinyGLTFConfig.cmake
|
||||
DESTINATION
|
||||
cmake
|
||||
)
|
||||
else (TINYGLTF_HEADER_ONLY)
|
||||
add_library(tinygltf)
|
||||
target_sources(tinygltf PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tiny_gltf.cc)
|
||||
target_include_directories(tinygltf
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
endif (TINYGLTF_HEADER_ONLY)
|
||||
|
||||
if (TINYGLTF_INSTALL)
|
||||
|
||||
# Do not install .lib even if !TINYGLTF_HEADER_ONLY
|
||||
|
||||
INSTALL ( FILES
|
||||
json.hpp
|
||||
stb_image.h
|
||||
stb_image_write.h
|
||||
tiny_gltf.h
|
||||
${TINYGLTF_EXTRA_SOUECES}
|
||||
DESTINATION
|
||||
include
|
||||
)
|
||||
|
||||
INSTALL ( FILES
|
||||
cmake/TinyGLTFConfig.cmake
|
||||
DESTINATION
|
||||
cmake
|
||||
)
|
||||
|
||||
endif(TINYGLTF_INSTALL)
|
||||
|
||||
19
README.md
19
README.md
@@ -7,6 +7,8 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch(bu
|
||||
|
||||
## Status
|
||||
|
||||
Currently TinyGLTF is stable and maintainance mode. No drastic changes and feature addition planned.
|
||||
|
||||
- v2.4.0 Experimental RapidJSON support. Experimental C++14 support(C++14 may give better performance)
|
||||
- v2.3.0 Modified Material representation according to glTF 2.0 schema(and introduced TextureInfo class)
|
||||
- v2.2.0 release(Support loading 16bit PNG. Sparse accessor support)
|
||||
@@ -170,11 +172,26 @@ if (!ret) {
|
||||
* `TINYGLTF_ANDROID_LOAD_FROM_ASSETS`: Load all files from packaged app assets instead of the regular file system. **Note:** You must pass a valid asset manager from your android app to `tinygltf::asset_manager` beforehand.
|
||||
* `TINYGLTF_ENABLE_DRACO`: Enable Draco compression. User must provide include path and link correspnding libraries in your project file.
|
||||
* `TINYGLTF_NO_INCLUDE_JSON `: Disable including `json.hpp` from within `tiny_gltf.h` because it has been already included before or you want to include it using custom path before including `tiny_gltf.h`.
|
||||
* `TINYGLTF_NO_INCLUDE_RAPIDJSON `: Disable including RapidJson's header files from within `tiny_gltf.h` because it has been already included before or you want to include it using custom path before including `tiny_gltf.h`.
|
||||
* `TINYGLTF_NO_INCLUDE_STB_IMAGE `: Disable including `stb_image.h` from within `tiny_gltf.h` because it has been already included before or you want to include it using custom path before including `tiny_gltf.h`.
|
||||
* `TINYGLTF_NO_INCLUDE_STB_IMAGE_WRITE `: Disable including `stb_image_write.h` from within `tiny_gltf.h` because it has been already included before or you want to include it using custom path before including `tiny_gltf.h`.
|
||||
* `TINYGLTF_USE_RAPIDJSON` : Use RapidJSON as a JSON parser/serializer. RapidJSON files are not included in TinyGLTF repo. Please set an include path to RapidJSON if you enable this featrure.
|
||||
* `TINYGLTF_USE_RAPIDJSON` : Use RapidJSON as a JSON parser/serializer. RapidJSON files are not included in TinyGLTF repo. Please set an include path to RapidJSON if you enable this feature.
|
||||
* `TINYGLTF_USE_CPP14` : Use C++14 feature(requires C++14 compiler). This may give better performance than C++11.
|
||||
|
||||
## CMake options
|
||||
|
||||
You can add tinygltf using `add_subdirectory` feature.
|
||||
If you add tinygltf to your project using `add_subdirectory`, it would be better to set `TINYGLTF_HEADER_ONLY` on(just add an include path to tinygltf) and `TINYGLTF_INSTALL` off(Which does not install tinygltf files).
|
||||
|
||||
```
|
||||
// Your project's CMakeLists.txt
|
||||
...
|
||||
|
||||
set(TINYGLTF_HEADER_ONLY ON CACHE INTERNAL "" FORCE)
|
||||
set(TINYGLTF_INSTALL OFF CACHE INTERNAL "" FORCE)
|
||||
add_subdirectory(/path/to/tinygltf)
|
||||
```
|
||||
|
||||
|
||||
### Saving gltTF 2.0 model
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ if (DEFINED DRACO_DIR)
|
||||
# TODO(syoyo): better CMake script for draco
|
||||
add_definitions(-DTINYGLTF_ENABLE_DRACO)
|
||||
include_directories(${DRACO_DIR}/include)
|
||||
|
||||
|
||||
link_directories(${DRACO_DIR}/lib)
|
||||
set(DRACO_LIBRARY draco)
|
||||
endif ()
|
||||
@@ -49,9 +49,9 @@ add_executable(glview
|
||||
)
|
||||
|
||||
target_link_libraries ( glview
|
||||
${DRACO_LIBRARY}
|
||||
${DRACO_LIBRARY}
|
||||
${GLFW3_UNIX_LINK_LIBRARIES}
|
||||
${GLEW_LIBRARY}
|
||||
${GLEW_LIBRARIES}
|
||||
${GLFW3_glfw_LIBRARY}
|
||||
${OPENGL_gl_LIBRARY}
|
||||
${OPENGL_glu_LIBRARY}
|
||||
|
||||
@@ -524,7 +524,7 @@ static void Dump(const tinygltf::Model &model) {
|
||||
<< std::endl;
|
||||
|
||||
std::cout << Indent(1) << "channels : [ " << std::endl;
|
||||
for (size_t j = 0; i < animation.channels.size(); i++) {
|
||||
for (size_t j = 0; j < animation.channels.size(); j++) {
|
||||
std::cout << Indent(2)
|
||||
<< "sampler : " << animation.channels[j].sampler
|
||||
<< std::endl;
|
||||
|
||||
267
models/regression/unassigned-skeleton.gltf
Normal file
267
models/regression/unassigned-skeleton.gltf
Normal file
File diff suppressed because one or more lines are too long
@@ -436,6 +436,36 @@ TEST_CASE("serialize-empty-material", "[issue-294]") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("empty-skeleton-id", "[issue-321]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/regression/unassigned-skeleton.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
|
||||
REQUIRE(model.skins.size() == 1);
|
||||
REQUIRE(model.skins[0].skeleton == -1); // unassigned
|
||||
|
||||
std::stringstream os;
|
||||
|
||||
ctx.WriteGltfSceneToStream(&model, os, false, false);
|
||||
|
||||
// use nlohmann json
|
||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||
|
||||
// Ensure `skeleton` property is not written to .gltf(was serialized as -1)
|
||||
REQUIRE(1 == j["skins"].size());
|
||||
REQUIRE(j["skins"][0].is_object());
|
||||
REQUIRE(j["skins"][0].count("skeleton") == 0);
|
||||
|
||||
}
|
||||
|
||||
#ifndef TINYGLTF_NO_FS
|
||||
TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
||||
|
||||
|
||||
4
tiny_gltf.cc
Normal file
4
tiny_gltf.cc
Normal file
@@ -0,0 +1,4 @@
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "tiny_gltf.h"
|
||||
175
tiny_gltf.h
175
tiny_gltf.h
@@ -191,14 +191,14 @@ AAssetManager *asset_manager = nullptr;
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
NULL_TYPE = 0,
|
||||
REAL_TYPE = 1,
|
||||
INT_TYPE = 2,
|
||||
BOOL_TYPE = 3,
|
||||
STRING_TYPE = 4,
|
||||
ARRAY_TYPE = 5,
|
||||
BINARY_TYPE = 6,
|
||||
OBJECT_TYPE = 7
|
||||
NULL_TYPE,
|
||||
REAL_TYPE,
|
||||
INT_TYPE,
|
||||
BOOL_TYPE,
|
||||
STRING_TYPE,
|
||||
ARRAY_TYPE,
|
||||
BINARY_TYPE,
|
||||
OBJECT_TYPE
|
||||
} Type;
|
||||
|
||||
static inline int32_t GetComponentSizeInBytes(uint32_t componentType) {
|
||||
@@ -253,7 +253,6 @@ bool DecodeDataURI(std::vector<unsigned char> *out, std::string &mime_type,
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
// Suppress warning for : static Value null_value
|
||||
// https://stackoverflow.com/questions/15708411/how-to-deal-with-global-constructor-warning-in-clang
|
||||
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||
#pragma clang diagnostic ignored "-Wpadded"
|
||||
#endif
|
||||
@@ -604,7 +603,7 @@ struct Sampler {
|
||||
// `magFilter`. Set -1 in TinyGLTF(issue #186)
|
||||
int minFilter =
|
||||
-1; // optional. -1 = no filter defined. ["NEAREST", "LINEAR",
|
||||
// "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_NEAREST",
|
||||
// "NEAREST_MIPMAP_NEAREST", "LINEAR_MIPMAP_NEAREST",
|
||||
// "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_LINEAR"]
|
||||
int magFilter =
|
||||
-1; // optional. -1 = no filter defined. ["NEAREST", "LINEAR"]
|
||||
@@ -1538,6 +1537,7 @@ class TinyGLTF {
|
||||
#ifndef TINYGLTF_USE_RAPIDJSON
|
||||
#include "json.hpp"
|
||||
#else
|
||||
#ifndef TINYGLTF_NO_INCLUDE_RAPIDJSON
|
||||
#include "document.h"
|
||||
#include "prettywriter.h"
|
||||
#include "rapidjson.h"
|
||||
@@ -1545,6 +1545,7 @@ class TinyGLTF {
|
||||
#include "writer.h"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TINYGLTF_ENABLE_DRACO
|
||||
#include "draco/compression/decode.h"
|
||||
@@ -1603,7 +1604,7 @@ class TinyGLTF {
|
||||
|
||||
#endif
|
||||
|
||||
#elif !defined(__ANDROID__)
|
||||
#elif !defined(__ANDROID__) && !defined(__OpenBSD__)
|
||||
#include <wordexp.h>
|
||||
#endif
|
||||
|
||||
@@ -1932,9 +1933,10 @@ bool Sampler::operator==(const Sampler &other) const {
|
||||
return this->extensions == other.extensions && this->extras == other.extras &&
|
||||
this->magFilter == other.magFilter &&
|
||||
this->minFilter == other.minFilter && this->name == other.name &&
|
||||
this->wrapS == other.wrapS &&
|
||||
this->wrapT == other.wrapT;
|
||||
|
||||
//this->wrapR == other.wrapR && this->wrapS == other.wrapS &&
|
||||
//this->wrapR == other.wrapR
|
||||
}
|
||||
bool Scene::operator==(const Scene &other) const {
|
||||
return this->extensions == other.extensions && this->extras == other.extras &&
|
||||
@@ -2038,9 +2040,12 @@ static std::string GetBaseDir(const std::string &filepath) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/8520560/get-a-file-name-from-a-path
|
||||
static std::string GetBaseFilename(const std::string &filepath) {
|
||||
return filepath.substr(filepath.find_last_of("/\\") + 1);
|
||||
constexpr char path_separators[2] = { '/', '\\' };
|
||||
auto idx = filepath.find_last_of(path_separators);
|
||||
if (idx != std::string::npos)
|
||||
return filepath.substr(idx + 1);
|
||||
return filepath;
|
||||
}
|
||||
|
||||
std::string base64_encode(unsigned char const *, unsigned int len);
|
||||
@@ -2186,47 +2191,35 @@ std::string base64_decode(std::string const &encoded_string) {
|
||||
// TODO(syoyo): Use uriparser https://uriparser.github.io/ for stricter Uri
|
||||
// decoding?
|
||||
//
|
||||
// https://stackoverflow.com/questions/18307429/encode-decode-url-in-c
|
||||
// Uri Decoding from DLIB
|
||||
// http://dlib.net/dlib/server/server_http.cpp.html
|
||||
|
||||
// --- dlib beign ------------------------------------------------------------
|
||||
// --- dlib begin ------------------------------------------------------------
|
||||
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
|
||||
// License: Boost Software License See LICENSE.txt for the full license.
|
||||
// License: Boost Software License
|
||||
// Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
namespace dlib {
|
||||
|
||||
#if 0
|
||||
inline unsigned char to_hex( unsigned char x )
|
||||
{
|
||||
return x + (x > 9 ? ('A'-10) : '0');
|
||||
}
|
||||
|
||||
const std::string urlencode( const std::string& s )
|
||||
{
|
||||
std::ostringstream os;
|
||||
|
||||
for ( std::string::const_iterator ci = s.begin(); ci != s.end(); ++ci )
|
||||
{
|
||||
if ( (*ci >= 'a' && *ci <= 'z') ||
|
||||
(*ci >= 'A' && *ci <= 'Z') ||
|
||||
(*ci >= '0' && *ci <= '9') )
|
||||
{ // allowed
|
||||
os << *ci;
|
||||
}
|
||||
else if ( *ci == ' ')
|
||||
{
|
||||
os << '+';
|
||||
}
|
||||
else
|
||||
{
|
||||
os << '%' << to_hex(static_cast<unsigned char>(*ci >> 4)) << to_hex(static_cast<unsigned char>(*ci % 16));
|
||||
}
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
inline unsigned char from_hex(unsigned char ch) {
|
||||
if (ch <= '9' && ch >= '0')
|
||||
ch -= '0';
|
||||
@@ -2627,7 +2620,7 @@ std::string ExpandFilePath(const std::string &filepath, void *) {
|
||||
#else
|
||||
|
||||
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \
|
||||
defined(__ANDROID__) || defined(__EMSCRIPTEN__)
|
||||
defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__OpenBSD__)
|
||||
// no expansion
|
||||
std::string s = filepath;
|
||||
#else
|
||||
@@ -3200,6 +3193,7 @@ static bool ParseJsonAsValue(Value *ret, const json &o) {
|
||||
break;
|
||||
case json::value_t::null:
|
||||
case json::value_t::discarded:
|
||||
case json::value_t::binary:
|
||||
// default:
|
||||
break;
|
||||
}
|
||||
@@ -4223,7 +4217,9 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err,
|
||||
accessor->sparse.isSparse = true;
|
||||
|
||||
int count = 0;
|
||||
ParseIntegerProperty(&count, err, o, "count", true);
|
||||
if (!ParseIntegerProperty(&count, err, o, "count", true, "SparseAccessor")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
json_const_iterator indices_iterator;
|
||||
json_const_iterator values_iterator;
|
||||
@@ -4241,18 +4237,24 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err,
|
||||
const json &values_obj = GetValue(values_iterator);
|
||||
|
||||
int indices_buffer_view = 0, indices_byte_offset = 0, component_type = 0;
|
||||
ParseIntegerProperty(&indices_buffer_view, err, indices_obj, "bufferView",
|
||||
true);
|
||||
if (!ParseIntegerProperty(&indices_buffer_view, err, indices_obj, "bufferView",
|
||||
true, "SparseAccessor")) {
|
||||
return false;
|
||||
}
|
||||
ParseIntegerProperty(&indices_byte_offset, err, indices_obj, "byteOffset",
|
||||
true);
|
||||
ParseIntegerProperty(&component_type, err, indices_obj, "componentType",
|
||||
true);
|
||||
false);
|
||||
if (!ParseIntegerProperty(&component_type, err, indices_obj, "componentType",
|
||||
true, "SparseAccessor")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int values_buffer_view = 0, values_byte_offset = 0;
|
||||
ParseIntegerProperty(&values_buffer_view, err, values_obj, "bufferView",
|
||||
true);
|
||||
if (!ParseIntegerProperty(&values_buffer_view, err, values_obj, "bufferView",
|
||||
true, "SparseAccessor")) {
|
||||
return false;
|
||||
}
|
||||
ParseIntegerProperty(&values_byte_offset, err, values_obj, "byteOffset",
|
||||
true);
|
||||
false);
|
||||
|
||||
accessor->sparse.count = count;
|
||||
accessor->sparse.indices.bufferView = indices_buffer_view;
|
||||
@@ -4261,8 +4263,6 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err,
|
||||
accessor->sparse.values.bufferView = values_buffer_view;
|
||||
accessor->sparse.values.byteOffset = values_byte_offset;
|
||||
|
||||
// todo check theses values
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4470,6 +4470,7 @@ static bool GetAttributeForAllPoints(uint32_t componentType, draco::Mesh *mesh,
|
||||
static bool ParseDracoExtension(Primitive *primitive, Model *model,
|
||||
std::string *err,
|
||||
const Value &dracoExtensionValue) {
|
||||
(void)err;
|
||||
auto bufferViewValue = dracoExtensionValue.Get("bufferView");
|
||||
if (!bufferViewValue.IsInt()) return false;
|
||||
auto attributesValue = dracoExtensionValue.Get("attributes");
|
||||
@@ -4530,7 +4531,6 @@ static bool ParseDracoExtension(Primitive *primitive, Model *model,
|
||||
|
||||
int dracoAttributeIndex = attribute.second.Get<int>();
|
||||
const auto pAttribute = mesh->GetAttributeByUniqueId(dracoAttributeIndex);
|
||||
const auto pBuffer = pAttribute->buffer();
|
||||
const auto componentType =
|
||||
model->accessors[primitiveAttribute->second].componentType;
|
||||
|
||||
@@ -5830,13 +5830,13 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
||||
{
|
||||
json_const_iterator it;
|
||||
if (FindMember(o, "extensions", it)) {
|
||||
model->extensions_json_string = JsonToString(GetValue(it));
|
||||
scene.extensions_json_string = JsonToString(GetValue(it));
|
||||
}
|
||||
}
|
||||
{
|
||||
json_const_iterator it;
|
||||
if (FindMember(o, "extras", it)) {
|
||||
model->extras_json_string = JsonToString(GetValue(it));
|
||||
scene.extras_json_string = JsonToString(GetValue(it));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7241,11 +7241,17 @@ static void SerializeGltfScene(Scene &scene, json &o) {
|
||||
}
|
||||
|
||||
static void SerializeGltfSkin(Skin &skin, json &o) {
|
||||
if (skin.inverseBindMatrices != -1)
|
||||
SerializeNumberProperty("inverseBindMatrices", skin.inverseBindMatrices, o);
|
||||
|
||||
// required
|
||||
SerializeNumberArrayProperty<int>("joints", skin.joints, o);
|
||||
SerializeNumberProperty("skeleton", skin.skeleton, o);
|
||||
|
||||
if (skin.inverseBindMatrices >= 0) {
|
||||
SerializeNumberProperty("inverseBindMatrices", skin.inverseBindMatrices, o);
|
||||
}
|
||||
|
||||
if (skin.skeleton >= 0) {
|
||||
SerializeNumberProperty("skeleton", skin.skeleton, o);
|
||||
}
|
||||
|
||||
if (skin.name.size()) {
|
||||
SerializeStringProperty("name", skin.name, o);
|
||||
}
|
||||
@@ -7520,31 +7526,24 @@ static void WriteBinaryGltfStream(std::ostream &stream,
|
||||
const std::string header = "glTF";
|
||||
const int version = 2;
|
||||
|
||||
// https://stackoverflow.com/questions/3407012/c-rounding-up-to-the-nearest-multiple-of-a-number
|
||||
auto roundUp = [](uint32_t numToRound, uint32_t multiple) {
|
||||
if (multiple == 0) return numToRound;
|
||||
|
||||
uint32_t remainder = numToRound % multiple;
|
||||
if (remainder == 0) return numToRound;
|
||||
|
||||
return numToRound + multiple - remainder;
|
||||
};
|
||||
|
||||
const uint32_t padding_size =
|
||||
roundUp(uint32_t(content.size()), 4) - uint32_t(content.size());
|
||||
const uint32_t content_size = uint32_t(content.size());
|
||||
const uint32_t binBuffer_size = uint32_t(binBuffer.size());
|
||||
// determine number of padding bytes required to ensure 4 byte alignment
|
||||
const uint32_t content_padding_size = content_size % 4 == 0 ? 0 : 4 - content_size % 4;
|
||||
const uint32_t bin_padding_size = binBuffer_size % 4 == 0 ? 0 : 4 - binBuffer_size % 4;
|
||||
|
||||
// 12 bytes for header, JSON content length, 8 bytes for JSON chunk info.
|
||||
// Chunk data must be located at 4-byte boundary.
|
||||
// Chunk data must be located at 4-byte boundary, which may require padding
|
||||
const uint32_t length =
|
||||
12 + 8 + roundUp(uint32_t(content.size()), 4) +
|
||||
(binBuffer.size() ? (8 + roundUp(uint32_t(binBuffer.size()), 4)) : 0);
|
||||
12 + 8 + content_size + content_padding_size +
|
||||
(binBuffer_size ? (8 + binBuffer_size + bin_padding_size) : 0);
|
||||
|
||||
stream.write(header.c_str(), std::streamsize(header.size()));
|
||||
stream.write(reinterpret_cast<const char *>(&version), sizeof(version));
|
||||
stream.write(reinterpret_cast<const char *>(&length), sizeof(length));
|
||||
|
||||
// JSON chunk info, then JSON data
|
||||
const uint32_t model_length = uint32_t(content.size()) + padding_size;
|
||||
const uint32_t model_length = uint32_t(content.size()) + content_padding_size;
|
||||
const uint32_t model_format = 0x4E4F534A;
|
||||
stream.write(reinterpret_cast<const char *>(&model_length),
|
||||
sizeof(model_length));
|
||||
@@ -7553,13 +7552,11 @@ static void WriteBinaryGltfStream(std::ostream &stream,
|
||||
stream.write(content.c_str(), std::streamsize(content.size()));
|
||||
|
||||
// Chunk must be multiplies of 4, so pad with spaces
|
||||
if (padding_size > 0) {
|
||||
const std::string padding = std::string(size_t(padding_size), ' ');
|
||||
if (content_padding_size > 0) {
|
||||
const std::string padding = std::string(size_t(content_padding_size), ' ');
|
||||
stream.write(padding.c_str(), std::streamsize(padding.size()));
|
||||
}
|
||||
if (binBuffer.size() > 0) {
|
||||
const uint32_t bin_padding_size =
|
||||
roundUp(uint32_t(binBuffer.size()), 4) - uint32_t(binBuffer.size());
|
||||
// BIN chunk info, then BIN data
|
||||
const uint32_t bin_length = uint32_t(binBuffer.size()) + bin_padding_size;
|
||||
const uint32_t bin_format = 0x004e4942;
|
||||
|
||||
Reference in New Issue
Block a user