mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-13 18:58:53 +00:00
Compare commits
1 Commits
minijson
...
remove-ass
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6817d206b |
45
.github/workflows/mingw-w64-msys2.yml
vendored
45
.github/workflows/mingw-w64-msys2.yml
vendored
@@ -1,45 +0,0 @@
|
|||||||
name: MSYS2 MinGW-w64 Windows 64bit Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- release
|
|
||||||
- devel
|
|
||||||
paths:
|
|
||||||
- 'tiny_gltf.*'
|
|
||||||
- 'CMakeLists.txt'
|
|
||||||
- '.github/workflows/mingw-w64-msys2.yml'
|
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
mingw-w64-msys2-build:
|
|
||||||
name: MSYS2 MinGW-w64 Windows Build
|
|
||||||
runs-on: windows-latest
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: msys2 {0}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install core & build dependencies
|
|
||||||
uses: msys2/setup-msys2@v2
|
|
||||||
with:
|
|
||||||
msystem: UCRT64
|
|
||||||
install: base-devel
|
|
||||||
pacboy: >-
|
|
||||||
cc:p cmake:p ninja:p
|
|
||||||
update: true
|
|
||||||
release: false
|
|
||||||
|
|
||||||
- name: Configure
|
|
||||||
run: |
|
|
||||||
cmake \
|
|
||||||
-G"Ninja" \
|
|
||||||
-S . \
|
|
||||||
-B build
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
cmake --build build
|
|
||||||
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -24,7 +24,6 @@ premake5.tar.gz
|
|||||||
#binary directories
|
#binary directories
|
||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
out/
|
|
||||||
|
|
||||||
#runtime gui config
|
#runtime gui config
|
||||||
imgui.ini
|
imgui.ini
|
||||||
|
|||||||
10
.travis-before-install.sh
Executable file
10
.travis-before-install.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$TRAVIS_OS_NAME" == "osx" ]]
|
||||||
|
then
|
||||||
|
brew upgrade
|
||||||
|
curl -o premake5.tar.gz https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-macosx.tar.gz
|
||||||
|
else
|
||||||
|
wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-linux.tar.gz -O premake5.tar.gz
|
||||||
|
fi
|
||||||
|
tar xzf premake5.tar.gz
|
||||||
63
.travis.yml
Normal file
63
.travis.yml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
language: cpp
|
||||||
|
sudo: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- addons: &1
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- george-edison55-precise-backports
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
- llvm-toolchain-trusty-3.9
|
||||||
|
packages:
|
||||||
|
- g++-4.9
|
||||||
|
- clang-3.9
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug
|
||||||
|
- addons: *1
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER_VERSION=3.9 BUILD_TYPE=Release
|
||||||
|
- addons: &2
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- george-edison55-precise-backports
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- g++-4.9
|
||||||
|
compiler: gcc
|
||||||
|
env: COMPILER_VERSION=4.9 BUILD_TYPE=Debug EXTRA_CXXFLAGS="-fsanitize=address"
|
||||||
|
- addons: *2
|
||||||
|
compiler: gcc
|
||||||
|
env: COMPILER_VERSION=4.9 BUILD_TYPE=Release EXTRA_CXXFLAGS="-fsanitize=address"
|
||||||
|
- addons: *1
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug CFLAGS="-O0" CXXFLAGS="-O0"
|
||||||
|
- addons: &3
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- g++-4.8
|
||||||
|
compiler: gcc
|
||||||
|
env: COMPILER_VERSION=4.8 BUILD_TYPE=Debug
|
||||||
|
- addons: *3
|
||||||
|
compiler: gcc
|
||||||
|
env: COMPILER_VERSION=4.8 BUILD_TYPE=Release
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- ./.travis-before-install.sh
|
||||||
|
|
||||||
|
|
||||||
|
script:
|
||||||
|
- export CC="${CC}-${COMPILER_VERSION}"
|
||||||
|
- export CXX="${CXX}-${COMPILER_VERSION}"
|
||||||
|
- ${CC} -v
|
||||||
|
- ${CXX} ${EXTRA_CXXFLAGS} -std=c++11 -Wall -g -o loader_example loader_example.cc
|
||||||
|
- ./loader_example ./models/Cube/Cube.gltf
|
||||||
|
- cd tests
|
||||||
|
- clang++ -v
|
||||||
|
- make
|
||||||
|
- ./tester
|
||||||
|
- ./tester_noexcept
|
||||||
|
- cd ../examples/raytrace
|
||||||
|
- ../../premake5 gmake
|
||||||
|
- make
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
cmake_minimum_required(VERSION 3.6)
|
cmake_minimum_required(VERSION 3.6)
|
||||||
|
|
||||||
project(tinygltf)
|
PROJECT (tinygltf)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
SET(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED On)
|
|
||||||
set(CMAKE_CXX_EXTENSIONS Off)
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
|
|
||||||
option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example(load glTF and dump infos)" 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_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF)
|
||||||
@@ -18,22 +15,22 @@ option(TINYGLTF_HEADER_ONLY "On: header-only mode. Off: create tinygltf library(
|
|||||||
option(TINYGLTF_INSTALL "Install tinygltf files during install step. Usually set to OFF if you include tinygltf through add_subdirectory()" ON)
|
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)
|
if (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
||||||
add_executable(loader_example
|
ADD_EXECUTABLE ( loader_example
|
||||||
loader_example.cc
|
loader_example.cc
|
||||||
)
|
)
|
||||||
endif (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
endif (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
||||||
|
|
||||||
if (TINYGLTF_BUILD_GL_EXAMPLES)
|
if (TINYGLTF_BUILD_GL_EXAMPLES)
|
||||||
add_subdirectory( examples/gltfutil )
|
ADD_SUBDIRECTORY ( examples/gltfutil )
|
||||||
add_subdirectory( examples/glview )
|
ADD_SUBDIRECTORY ( examples/glview )
|
||||||
endif (TINYGLTF_BUILD_GL_EXAMPLES)
|
endif (TINYGLTF_BUILD_GL_EXAMPLES)
|
||||||
|
|
||||||
if (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
if (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
||||||
add_subdirectory( examples/validator )
|
ADD_SUBDIRECTORY ( examples/validator )
|
||||||
endif (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
endif (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
||||||
|
|
||||||
if (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
if (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||||
add_subdirectory ( examples/build-gltf )
|
ADD_SUBDIRECTORY ( examples/build-gltf )
|
||||||
endif (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
endif (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ Currently TinyGLTF is stable and maintenance mode. No drastic changes and featur
|
|||||||
|
|
||||||
## Builds
|
## Builds
|
||||||
|
|
||||||
|
[](https://travis-ci.org/syoyo/tinygltf)
|
||||||
|
|
||||||
[](https://ci.appveyor.com/project/syoyo/tinygltf)
|
[](https://ci.appveyor.com/project/syoyo/tinygltf)
|
||||||
|
|
||||||

|

|
||||||
@@ -107,7 +109,6 @@ WASI build example is located in [wasm](wasm) .
|
|||||||
* [SanityEngine](https://github.com/DethRaid/SanityEngine) - A C++/D3D12 renderer focused on the personal and professional development of its developer
|
* [SanityEngine](https://github.com/DethRaid/SanityEngine) - A C++/D3D12 renderer focused on the personal and professional development of its developer
|
||||||
* [Open3D](http://www.open3d.org/) - A Modern Library for 3D Data Processing
|
* [Open3D](http://www.open3d.org/) - A Modern Library for 3D Data Processing
|
||||||
* [Supernova Engine](https://github.com/supernovaengine/supernova) - Game engine for 2D and 3D projects with Lua or C++ in data oriented design.
|
* [Supernova Engine](https://github.com/supernovaengine/supernova) - Game engine for 2D and 3D projects with Lua or C++ in data oriented design.
|
||||||
* [Wicked Engine<img src="https://github.com/turanszkij/WickedEngine/blob/master/Content/logo_small.png" width="28px" align="center"/>](https://github.com/turanszkij/WickedEngine) - 3D engine with modern graphics
|
|
||||||
* Your projects here! (Please send PR)
|
* Your projects here! (Please send PR)
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR})
|
|
||||||
add_executable(create_triangle_gltf create_triangle_gltf.cpp)
|
|
||||||
target_compile_options(create_triangle_gltf PUBLIC -Wall)
|
|
||||||
target_link_libraries(create_triangle_gltf )
|
|
||||||
@@ -788,10 +788,8 @@ static void QuatToAngleAxis(const std::vector<double> quaternion,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr double pi = 3.14159265358979323846;
|
|
||||||
|
|
||||||
double denom = sqrt(1-qw*qw);
|
double denom = sqrt(1-qw*qw);
|
||||||
outAngleDegrees = angleRadians * 180.0 / pi;
|
outAngleDegrees = angleRadians * 180.0 / M_PI;
|
||||||
axis[0] = qx / denom;
|
axis[0] = qx / denom;
|
||||||
axis[1] = qy / denom;
|
axis[1] = qy / denom;
|
||||||
axis[2] = qz / denom;
|
axis[2] = qz / denom;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
//
|
//
|
||||||
// TODO(syoyo): Print extensions and extras for each glTF object.
|
// TODO(syoyo): Print extensions and extras for each glTF object.
|
||||||
//
|
//
|
||||||
#include <iostream>
|
|
||||||
#define TINYGLTF_IMPLEMENTATION
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|||||||
3186
minijson.h
3186
minijson.h
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -773,7 +773,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
|
|||||||
#ifdef __STDC_LIB_EXT1__
|
#ifdef __STDC_LIB_EXT1__
|
||||||
len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||||
#else
|
#else
|
||||||
len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||||
#endif
|
#endif
|
||||||
s->func(s->context, buffer, len);
|
s->func(s->context, buffer, len);
|
||||||
|
|
||||||
|
|||||||
459
tests/tester.cc
459
tests/tester.cc
@@ -474,7 +474,7 @@ TEST_CASE("image-uri-spaces", "[issue-236]") {
|
|||||||
}
|
}
|
||||||
REQUIRE(true == ret);
|
REQUIRE(true == ret);
|
||||||
REQUIRE(err.empty());
|
REQUIRE(err.empty());
|
||||||
REQUIRE(warn.empty());
|
REQUIRE(!warn.empty()); // relative image path won't exist in tests/
|
||||||
REQUIRE(saved.images.size() == model.images.size());
|
REQUIRE(saved.images.size() == model.images.size());
|
||||||
|
|
||||||
// The image uri in CubeImageUriMultipleSpaces.gltf is not encoded and
|
// The image uri in CubeImageUriMultipleSpaces.gltf is not encoded and
|
||||||
@@ -494,23 +494,25 @@ TEST_CASE("image-uri-spaces", "[issue-236]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("serialize-empty-material", "[issue-294]") {
|
TEST_CASE("serialize-empty-material", "[issue-294]") {
|
||||||
|
|
||||||
tinygltf::Model m;
|
tinygltf::Model m;
|
||||||
// Add default constructed material to model
|
|
||||||
m.materials.push_back({});
|
tinygltf::Material mat;
|
||||||
// Serialize model to output stream
|
mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 1.0f, 1.0f, 1.0f}; // default baseColorFactor
|
||||||
|
m.materials.push_back(mat);
|
||||||
|
|
||||||
std::stringstream os;
|
std::stringstream os;
|
||||||
|
|
||||||
tinygltf::TinyGLTF ctx;
|
tinygltf::TinyGLTF ctx;
|
||||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
||||||
REQUIRE(true == ret);
|
REQUIRE(true == ret);
|
||||||
// Parse serialized model
|
|
||||||
|
// use nlohmann json
|
||||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||||
// Serialized materials shall hold an empty object that
|
|
||||||
// represents the default constructed material
|
|
||||||
REQUIRE(j.find("materials") != j.end());
|
|
||||||
REQUIRE(j["materials"].is_array());
|
|
||||||
REQUIRE(1 == j["materials"].size());
|
REQUIRE(1 == j["materials"].size());
|
||||||
CHECK(j["materials"][0].is_object());
|
REQUIRE(j["materials"][0].is_object());
|
||||||
CHECK(j["materials"][0].empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("empty-skeleton-id", "[issue-321]") {
|
TEST_CASE("empty-skeleton-id", "[issue-321]") {
|
||||||
@@ -662,11 +664,10 @@ TEST_CASE("serialize-image-callback", "[issue-394]") {
|
|||||||
|
|
||||||
auto writer = [](const std::string *basepath, const std::string *filename,
|
auto writer = [](const std::string *basepath, const std::string *filename,
|
||||||
const tinygltf::Image *image, bool embedImages,
|
const tinygltf::Image *image, bool embedImages,
|
||||||
const tinygltf::FsCallbacks* fs, const tinygltf::URICallbacks *uri_cb,
|
const tinygltf::URICallbacks *uri_cb, std::string *out_uri,
|
||||||
std::string *out_uri, void *user_pointer) -> bool {
|
void *user_pointer) -> bool {
|
||||||
(void)basepath;
|
(void)basepath;
|
||||||
(void)image;
|
(void)image;
|
||||||
(void)fs;
|
|
||||||
(void)uri_cb;
|
(void)uri_cb;
|
||||||
REQUIRE(*filename == "foo");
|
REQUIRE(*filename == "foo");
|
||||||
REQUIRE(embedImages == true);
|
REQUIRE(embedImages == true);
|
||||||
@@ -700,13 +701,12 @@ TEST_CASE("serialize-image-failure", "[issue-394]") {
|
|||||||
|
|
||||||
auto writer = [](const std::string *basepath, const std::string *filename,
|
auto writer = [](const std::string *basepath, const std::string *filename,
|
||||||
const tinygltf::Image *image, bool embedImages,
|
const tinygltf::Image *image, bool embedImages,
|
||||||
const tinygltf::FsCallbacks* fs, const tinygltf::URICallbacks *uri_cb,
|
const tinygltf::URICallbacks *uri_cb, std::string *out_uri,
|
||||||
std::string *out_uri, void *user_pointer) -> bool {
|
void *user_pointer) -> bool {
|
||||||
(void)basepath;
|
(void)basepath;
|
||||||
(void)filename;
|
(void)filename;
|
||||||
(void)image;
|
(void)image;
|
||||||
(void)embedImages;
|
(void)embedImages;
|
||||||
(void)fs;
|
|
||||||
(void)uri_cb;
|
(void)uri_cb;
|
||||||
(void)out_uri;
|
(void)out_uri;
|
||||||
(void)user_pointer;
|
(void)user_pointer;
|
||||||
@@ -757,428 +757,3 @@ TEST_CASE("load-issue-416-model", "[issue-416]") {
|
|||||||
// external file load fails, but reading glTF itself is ok.
|
// external file load fails, but reading glTF itself is ok.
|
||||||
REQUIRE(true == ret);
|
REQUIRE(true == ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("serialize-empty-node", "[issue-457]") {
|
|
||||||
tinygltf::Model m;
|
|
||||||
// Add default constructed node to model
|
|
||||||
m.nodes.push_back({});
|
|
||||||
// Add scene to model
|
|
||||||
m.scenes.push_back({});
|
|
||||||
// The scene's only node is the empty node
|
|
||||||
m.scenes.front().nodes.push_back(0);
|
|
||||||
|
|
||||||
// Serialize model to output stream
|
|
||||||
std::stringstream os;
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
|
||||||
REQUIRE(true == ret);
|
|
||||||
|
|
||||||
// Parse serialized model
|
|
||||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
|
||||||
|
|
||||||
// Serialized nodes shall hold an empty object that
|
|
||||||
// represents the default constructed node
|
|
||||||
REQUIRE(j.find("nodes") != j.end());
|
|
||||||
REQUIRE(j["nodes"].is_array());
|
|
||||||
REQUIRE(1 == j["nodes"].size());
|
|
||||||
CHECK(j["nodes"][0].is_object());
|
|
||||||
CHECK(j["nodes"][0].empty());
|
|
||||||
|
|
||||||
// We also want to make sure that the serialized scene
|
|
||||||
// is referencing the empty node.
|
|
||||||
|
|
||||||
// There shall be a single serialized scene
|
|
||||||
auto scenes = j.find("scenes");
|
|
||||||
REQUIRE(scenes != j.end());
|
|
||||||
REQUIRE(scenes->is_array());
|
|
||||||
REQUIRE(1 == scenes->size());
|
|
||||||
auto scene = scenes->at(0);
|
|
||||||
REQUIRE(scene.is_object());
|
|
||||||
// The scene's nodes array shall hold a reference
|
|
||||||
// to the single node
|
|
||||||
auto nodes = scene.find("nodes");
|
|
||||||
REQUIRE(nodes != scene.end());
|
|
||||||
REQUIRE(nodes->is_array());
|
|
||||||
REQUIRE(1 == nodes->size());
|
|
||||||
auto node = nodes->at(0);
|
|
||||||
CHECK(node.is_number_integer());
|
|
||||||
int idx = -1;
|
|
||||||
node.get_to(idx);
|
|
||||||
CHECK(0 == idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("serialize-light-index", "[issue-458]") {
|
|
||||||
|
|
||||||
// Create the light
|
|
||||||
tinygltf::Light light;
|
|
||||||
light.type = "point";
|
|
||||||
light.intensity = 0.75;
|
|
||||||
light.color = std::vector<double>{1.0, 0.8, 0.95};
|
|
||||||
|
|
||||||
// Stream to serialize to
|
|
||||||
std::stringstream os;
|
|
||||||
|
|
||||||
{
|
|
||||||
tinygltf::Model m;
|
|
||||||
tinygltf::Scene scene;
|
|
||||||
// Add the light to the model
|
|
||||||
m.lights.push_back(light);
|
|
||||||
// Create a node that uses the light
|
|
||||||
tinygltf::Node node;
|
|
||||||
node.light = 0;
|
|
||||||
// Add the node to the model
|
|
||||||
m.nodes.push_back(node);
|
|
||||||
// Add the node to the scene
|
|
||||||
scene.nodes.push_back(0);
|
|
||||||
// Add the scene to the model
|
|
||||||
m.scenes.push_back(scene);
|
|
||||||
// Serialize model to output stream
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
|
||||||
REQUIRE(true == ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
tinygltf::Model m;
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
// Parse the serialized model
|
|
||||||
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
|
|
||||||
REQUIRE(true == ok);
|
|
||||||
// Check if the light was correctly serialized
|
|
||||||
REQUIRE(1 == m.lights.size());
|
|
||||||
CHECK(m.lights[0] == light);
|
|
||||||
// Check that the node properly references the light
|
|
||||||
REQUIRE(1 == m.nodes.size());
|
|
||||||
CHECK(m.nodes[0].light == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("default-material", "[issue-459]") {
|
|
||||||
const std::vector<double> default_emissive_factor{ 0.0, 0.0, 0.0 };
|
|
||||||
const std::vector<double> default_base_color_factor{ 1.0, 1.0, 1.0, 1.0 };
|
|
||||||
const std::string default_alpha_mode = "OPAQUE";
|
|
||||||
const double default_alpha_cutoff = 0.5;
|
|
||||||
const bool default_double_sided = false;
|
|
||||||
const double default_metallic_factor = 1.0;
|
|
||||||
const double default_roughness_factor = 1.0;
|
|
||||||
// Check that default constructed material
|
|
||||||
// holds actual default GLTF material properties
|
|
||||||
tinygltf::Material mat;
|
|
||||||
CHECK(mat.alphaMode == default_alpha_mode);
|
|
||||||
CHECK(mat.alphaCutoff == default_alpha_cutoff);
|
|
||||||
CHECK(mat.doubleSided == default_double_sided);
|
|
||||||
CHECK(mat.emissiveFactor == default_emissive_factor);
|
|
||||||
CHECK(mat.pbrMetallicRoughness.baseColorFactor == default_base_color_factor);
|
|
||||||
CHECK(mat.pbrMetallicRoughness.metallicFactor == default_metallic_factor);
|
|
||||||
CHECK(mat.pbrMetallicRoughness.roughnessFactor == default_roughness_factor);
|
|
||||||
// None of the textures should be set
|
|
||||||
CHECK(mat.normalTexture.index == -1);
|
|
||||||
CHECK(mat.occlusionTexture.index == -1);
|
|
||||||
CHECK(mat.emissiveTexture.index == -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("serialize-empty-scene", "[issue-464]") {
|
|
||||||
// Stream to serialize to
|
|
||||||
std::stringstream os;
|
|
||||||
|
|
||||||
{
|
|
||||||
tinygltf::Model m;
|
|
||||||
// Add empty scene to the model
|
|
||||||
m.scenes.push_back({});
|
|
||||||
// Serialize model to output stream
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
|
||||||
REQUIRE(true == ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
tinygltf::Model m;
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
// Parse the serialized model
|
|
||||||
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
|
|
||||||
REQUIRE(true == ok);
|
|
||||||
// Make sure the empty scene is there
|
|
||||||
REQUIRE(1 == m.scenes.size());
|
|
||||||
tinygltf::Scene scene{};
|
|
||||||
// Check that the scene is empty
|
|
||||||
CHECK(m.scenes[0] == scene);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("zero-sized-bin-chunk-glb", "[issue-440]") {
|
|
||||||
|
|
||||||
tinygltf::Model model;
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
std::string err;
|
|
||||||
std::string warn;
|
|
||||||
|
|
||||||
// Input glb has zero-sized data in bin chunk(8 bytes for BIN chunk, and chunksize == 0)
|
|
||||||
// The spec https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#binary-buffer says
|
|
||||||
//
|
|
||||||
// When the binary buffer is empty or when it is stored by other means, this chunk SHOULD be omitted.
|
|
||||||
//
|
|
||||||
// 'SHOULD' mean 'RECOMMENDED', so we'll need to allow such zero-sized bin chunk is NOT omitted.
|
|
||||||
bool ret = ctx.LoadBinaryFromFile(&model, &err, &warn, "../models/regression/zero-sized-bin-chunk-issue-440.glb");
|
|
||||||
if (!warn.empty()) {
|
|
||||||
std::cout << "WARN: " << warn << "\n";
|
|
||||||
}
|
|
||||||
if (!err.empty()) {
|
|
||||||
std::cerr << err << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(true == ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("serialize-node-emitter", "[KHR_audio]") {
|
|
||||||
// Stream to serialize to
|
|
||||||
std::stringstream os;
|
|
||||||
|
|
||||||
{
|
|
||||||
tinygltf::Model m;
|
|
||||||
// Create a default audio emitter
|
|
||||||
m.audioEmitters.resize(1);
|
|
||||||
// Create a single node
|
|
||||||
m.nodes.resize(1);
|
|
||||||
// The node references the single emitter
|
|
||||||
m.nodes[0].emitter = 0;
|
|
||||||
// Create a single scene
|
|
||||||
m.scenes.resize(1);
|
|
||||||
// Make the scene reference the single node
|
|
||||||
m.scenes[0].nodes.push_back(0);
|
|
||||||
|
|
||||||
// Serialize model to output stream
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
|
||||||
REQUIRE(true == ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
tinygltf::Model m;
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
// Parse the serialized model
|
|
||||||
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
|
|
||||||
REQUIRE(true == ok);
|
|
||||||
|
|
||||||
// Make sure the single scene is there
|
|
||||||
REQUIRE(1 == m.scenes.size());
|
|
||||||
// Make sure all three nodes are there
|
|
||||||
REQUIRE(1 == m.nodes.size());
|
|
||||||
// Make sure the single root node of the scene is there
|
|
||||||
REQUIRE(1 == m.scenes[0].nodes.size());
|
|
||||||
REQUIRE(0 == m.scenes[0].nodes[0]);
|
|
||||||
// Retrieve the scene root node
|
|
||||||
const tinygltf::Node& node = m.nodes[m.scenes[0].nodes[0]];
|
|
||||||
// Make sure the single root node has both lod nodes
|
|
||||||
REQUIRE(0 == node.emitter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("serialize-lods", "[lods]") {
|
|
||||||
// Stream to serialize to
|
|
||||||
std::stringstream os;
|
|
||||||
|
|
||||||
{
|
|
||||||
tinygltf::Model m;
|
|
||||||
|
|
||||||
m.nodes.resize(4);
|
|
||||||
// Add Node 1 and Node 2 as lods to Node 0
|
|
||||||
m.nodes[0].lods.push_back(1);
|
|
||||||
m.nodes[0].lods.push_back(2);
|
|
||||||
|
|
||||||
// Add Material 1 and Material 2 as lods to Material 0
|
|
||||||
m.materials.resize(4);
|
|
||||||
m.materials[0].lods.push_back(1);
|
|
||||||
m.materials[0].lods.push_back(2);
|
|
||||||
|
|
||||||
tinygltf::Scene scene;
|
|
||||||
// Scene uses Node 0 and 3 as root node
|
|
||||||
scene.nodes.push_back(0);
|
|
||||||
scene.nodes.push_back(3);
|
|
||||||
// Add scene to the model
|
|
||||||
m.scenes.push_back(scene);
|
|
||||||
|
|
||||||
// Serialize model to output stream
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
|
||||||
REQUIRE(true == ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
tinygltf::Model m;
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
// Parse the serialized model
|
|
||||||
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
|
|
||||||
REQUIRE(true == ok);
|
|
||||||
// Make sure the model's used extensions hold MSFT_lod
|
|
||||||
CHECK(m.extensionsUsed.size() == 1);
|
|
||||||
CHECK(m.extensionsUsed[0].compare("MSFT_lod") == 0);
|
|
||||||
// MSFT_lod is not a required extension
|
|
||||||
CHECK(m.extensionsRequired.size() == 0);
|
|
||||||
|
|
||||||
// Make sure all four materials are there
|
|
||||||
REQUIRE(4 == m.materials.size());
|
|
||||||
// Make sure the first material has both lod materials
|
|
||||||
REQUIRE(2 == m.materials[0].lods.size());
|
|
||||||
// Make sure the order is still the same after serialization and deserialization
|
|
||||||
CHECK(1 == m.materials[0].lods[0]);
|
|
||||||
CHECK(2 == m.materials[0].lods[1]);
|
|
||||||
// Make sure the material with lods exposes the MSFT_lod extension
|
|
||||||
CHECK(m.materials[0].extensions.size() == 1);
|
|
||||||
CHECK(m.materials[0].extensions.count("MSFT_lod") == 1);
|
|
||||||
// Make sure the last material has no lod materials
|
|
||||||
CHECK(0 == m.materials[3].lods.size());
|
|
||||||
// Make sure the material without lods does not exposes the MSFT_lod extension
|
|
||||||
CHECK(m.materials[3].extensions.size() == 0);
|
|
||||||
CHECK(m.materials[3].extensions.count("MSFT_lod") == 0);
|
|
||||||
|
|
||||||
// Make sure the single scene is there
|
|
||||||
REQUIRE(1 == m.scenes.size());
|
|
||||||
// Make sure all four nodes are there
|
|
||||||
REQUIRE(4 == m.nodes.size());
|
|
||||||
// Make sure the two root nodes of the scene are there
|
|
||||||
REQUIRE(2 == m.scenes[0].nodes.size());
|
|
||||||
REQUIRE(0 == m.scenes[0].nodes[0]);
|
|
||||||
REQUIRE(3 == m.scenes[0].nodes[1]);
|
|
||||||
// Retrieve the node with lods
|
|
||||||
const tinygltf::Node& nodeWithLods = m.nodes[m.scenes[0].nodes[0]];
|
|
||||||
// Make sure the node has both lod nodes
|
|
||||||
REQUIRE(2 == nodeWithLods.lods.size());
|
|
||||||
// Make sure the order is still the same after serialization and deserialization
|
|
||||||
CHECK(1 == nodeWithLods.lods[0]);
|
|
||||||
CHECK(2 == nodeWithLods.lods[1]);
|
|
||||||
// Make sure the node with lods exposes the MSFT_lod extension
|
|
||||||
CHECK(nodeWithLods.extensions.size() == 1);
|
|
||||||
CHECK(nodeWithLods.extensions.count("MSFT_lod") == 1);
|
|
||||||
// Retrieve the node without lods
|
|
||||||
const tinygltf::Node& nodeWithoutLods = m.nodes[m.scenes[0].nodes[1]];
|
|
||||||
// Make sure the node has no lod nodes
|
|
||||||
CHECK(0 == nodeWithoutLods.lods.size());
|
|
||||||
// Make sure the node without lods does not exposes the MSFT_lod extension
|
|
||||||
CHECK(nodeWithoutLods.extensions.size() == 0);
|
|
||||||
CHECK(nodeWithoutLods.extensions.count("MSFT_lod") == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("write-image-issue", "[issue-473]") {
|
|
||||||
std::string err;
|
|
||||||
std::string warn;
|
|
||||||
tinygltf::Model model;
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
bool ok = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Cube/Cube.gltf");
|
|
||||||
REQUIRE(ok);
|
|
||||||
REQUIRE(err.empty());
|
|
||||||
REQUIRE(warn.empty());
|
|
||||||
|
|
||||||
REQUIRE(model.images.size() == 2);
|
|
||||||
REQUIRE(model.images[0].uri == "Cube_BaseColor.png");
|
|
||||||
REQUIRE(model.images[1].uri == "Cube_MetallicRoughness.png");
|
|
||||||
|
|
||||||
REQUIRE_FALSE(model.images[0].image.empty());
|
|
||||||
REQUIRE_FALSE(model.images[1].image.empty());
|
|
||||||
|
|
||||||
ok = ctx.WriteGltfSceneToFile(&model, "Cube.gltf");
|
|
||||||
REQUIRE(ok);
|
|
||||||
|
|
||||||
for (const auto& image : model.images) {
|
|
||||||
std::fstream file(image.uri);
|
|
||||||
CHECK(file.good());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("images-as-is", "[issue-487]") {
|
|
||||||
std::string err;
|
|
||||||
std::string warn;
|
|
||||||
tinygltf::Model model;
|
|
||||||
tinygltf::TinyGLTF ctx;
|
|
||||||
ctx.SetImagesAsIs(true);
|
|
||||||
bool ok = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Cube/Cube.gltf");
|
|
||||||
REQUIRE(ok);
|
|
||||||
REQUIRE(err.empty());
|
|
||||||
REQUIRE(warn.empty());
|
|
||||||
|
|
||||||
for (const auto& image : model.images) {
|
|
||||||
CHECK(image.as_is == true);
|
|
||||||
CHECK_FALSE(image.uri.empty());
|
|
||||||
CHECK_FALSE(image.image.empty());
|
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_STB_IMAGE
|
|
||||||
// Make sure we can decode the images
|
|
||||||
int w = -1, h = -1, component = -1;
|
|
||||||
unsigned char *data = stbi_load_from_memory(image.image.data(), static_cast<int>(image.image.size()), &w, &h, &component, 0);
|
|
||||||
CHECK(data != nullptr);
|
|
||||||
CHECK(w == 512);
|
|
||||||
CHECK(h == 512);
|
|
||||||
CHECK(component >= 3);
|
|
||||||
stbi_image_free(data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write glTF model to disk, and images as separate files
|
|
||||||
{
|
|
||||||
ok = ctx.WriteGltfSceneToFile(&model, "Cube_with_image_files.gltf");
|
|
||||||
REQUIRE(ok);
|
|
||||||
|
|
||||||
// All the images should have been written to disk with their original data
|
|
||||||
for (const auto& image : model.images) {
|
|
||||||
// Make sure the image files exist
|
|
||||||
std::fstream file(image.uri);
|
|
||||||
CHECK(file.good());
|
|
||||||
#ifndef TINYGLTF_NO_STB_IMAGE
|
|
||||||
// Make sure we can load the images
|
|
||||||
int w = -1, h = -1, component = -1;
|
|
||||||
unsigned char *data = stbi_load(image.uri.c_str(), &w, &h, &component, 0);
|
|
||||||
CHECK(data != nullptr);
|
|
||||||
CHECK(w == 512);
|
|
||||||
CHECK(h == 512);
|
|
||||||
CHECK(component >= 3);
|
|
||||||
stbi_image_free(data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write glTF model to disk, and embed images as data URIs
|
|
||||||
{
|
|
||||||
ok = ctx.WriteGltfSceneToFile(&model, "Cube_with_embedded_images.gltf", true, false);
|
|
||||||
REQUIRE(ok);
|
|
||||||
|
|
||||||
// Load above model again, and check if the images are loaded properly
|
|
||||||
tinygltf::Model embeddedImages;
|
|
||||||
ctx.SetImagesAsIs(false);
|
|
||||||
bool ok = ctx.LoadASCIIFromFile(&embeddedImages, &err, &warn, "Cube_with_embedded_images.gltf");
|
|
||||||
REQUIRE(ok);
|
|
||||||
REQUIRE(err.empty());
|
|
||||||
REQUIRE(warn.empty());
|
|
||||||
|
|
||||||
for (const auto& image : embeddedImages.images) {
|
|
||||||
CHECK(image.as_is == false);
|
|
||||||
CHECK_FALSE(image.mimeType.empty());
|
|
||||||
CHECK_FALSE(image.image.empty());
|
|
||||||
CHECK(image.width == 512);
|
|
||||||
CHECK(image.height == 512);
|
|
||||||
CHECK(image.component >= 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write glTF model to disk, as GLB
|
|
||||||
{
|
|
||||||
ok = ctx.WriteGltfSceneToFile(&model, "Cube.glb", true, true, true, true);
|
|
||||||
REQUIRE(ok);
|
|
||||||
|
|
||||||
// Load above model again, and check if the images are loaded properly
|
|
||||||
tinygltf::Model glbModel;
|
|
||||||
ctx.SetImagesAsIs(false);
|
|
||||||
bool ok = ctx.LoadBinaryFromFile(&glbModel, &err, &warn, "Cube.glb");
|
|
||||||
REQUIRE(ok);
|
|
||||||
REQUIRE(err.empty());
|
|
||||||
REQUIRE(warn.empty());
|
|
||||||
|
|
||||||
for (const auto& image : glbModel.images) {
|
|
||||||
CHECK(image.as_is == false);
|
|
||||||
CHECK_FALSE(image.mimeType.empty());
|
|
||||||
CHECK_FALSE(image.image.empty());
|
|
||||||
CHECK(image.width == 512);
|
|
||||||
CHECK(image.height == 512);
|
|
||||||
CHECK(image.component >= 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
2021
tiny_gltf.h
2021
tiny_gltf.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user