Skip to content

Commit

Permalink
Merge branch 'release' of github.com:syoyo/tinygltf into release
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Dec 29, 2022
2 parents 186016b + a40ca4c commit 584f1df
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 77 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.6)

PROJECT (tinygltf)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

SET(CMAKE_CXX_STANDARD 11)

option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example(load glTF and dump infos)" ON)
Expand Down Expand Up @@ -54,7 +57,10 @@ else (TINYGLTF_HEADER_ONLY)
endif (TINYGLTF_HEADER_ONLY)

if (TINYGLTF_INSTALL)

install(TARGETS tinygltf EXPORT tinygltfTargets)
install(EXPORT tinygltfTargets NAMESPACE tinygltf:: FILE TinyGLTFTargets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/TinyGLTFConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/TinyGLTFConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TinyGLTFConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
# Do not install .lib even if !TINYGLTF_HEADER_ONLY

INSTALL ( FILES
Expand All @@ -67,10 +73,4 @@ if (TINYGLTF_INSTALL)
include
)

INSTALL ( FILES
cmake/TinyGLTFConfig.cmake
DESTINATION
cmake
)

endif(TINYGLTF_INSTALL)
15 changes: 0 additions & 15 deletions cmake/TinyGLTFConfig.cmake

This file was deleted.

3 changes: 3 additions & 0 deletions cmake/TinyGLTFConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/TinyGLTFTargets.cmake)
63 changes: 63 additions & 0 deletions tests/tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,66 @@ TEST_CASE("empty-bin-buffer", "[issue-382]") {
}
REQUIRE(true == ret);
}

TEST_CASE("serialize-const-image", "[issue-394]") {
tinygltf::Model m;
tinygltf::Image i;
i.width = 1;
i.height = 1;
i.component = 4;
i.bits = 8;
i.pixel_type = TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE;
i.image = {255, 255, 255, 255};
i.uri = "image.png";
m.images.push_back(i);

std::stringstream os;

tinygltf::TinyGLTF ctx;
ctx.WriteGltfSceneToStream(const_cast<const tinygltf::Model *>(&m), os, false,
false);
REQUIRE(m.images[0].uri == i.uri);

// use nlohmann json
nlohmann::json j = nlohmann::json::parse(os.str());

REQUIRE(1 == j["images"].size());
REQUIRE(j["images"][0].is_object());
REQUIRE(j["images"][0]["uri"].get<std::string>() != i.uri);
REQUIRE(j["images"][0]["uri"].get<std::string>().rfind("data:", 0) == 0);
}

TEST_CASE("serialize-image-callback", "[issue-394]") {
tinygltf::Model m;
tinygltf::Image i;
i.width = 1;
i.height = 1;
i.bits = 32;
i.image = {255, 255, 255, 255};
i.uri = "foo";
m.images.push_back(i);

std::stringstream os;

auto writer = [](const std::string *basepath, const std::string *filename,
const tinygltf::Image *image, bool embedImages,
std::string *out_uri, void *user_pointer) -> bool {
REQUIRE(*filename == "foo");
REQUIRE(embedImages == true);
REQUIRE(user_pointer == (void *)0xba5e1e55);
*out_uri = "bar";
return true;
};

tinygltf::TinyGLTF ctx;
ctx.SetImageWriter(writer, (void *)0xba5e1e55);
ctx.WriteGltfSceneToStream(const_cast<const tinygltf::Model *>(&m), os, false,
false);

// use nlohmann json
nlohmann::json j = nlohmann::json::parse(os.str());

REQUIRE(1 == j["images"].size());
REQUIRE(j["images"][0].is_object());
REQUIRE(j["images"][0]["uri"].get<std::string>() == "bar");
}
Loading

0 comments on commit 584f1df

Please sign in to comment.