From 67fa1eb924756968f4dd0893b6594a30603e7b48 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Wed, 23 Aug 2023 19:32:53 +0900 Subject: [PATCH] Make usdMtlx non-builtin module(built by default) --- CMakeLists.txt | 16 +++++++++------- src/usdMtlx.cc | 46 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b6824106..807a0da86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,7 @@ option(TINYUSDZ_CXX_EXCEPTIONS "Enable/Disable C++ exceptions(default: Off for posix, on for MSVC)" ${TINYUSDZ_CXX_EXCEPTIONS_DEFAULT}) +option(TINYUSDZ_WITH_USDMTLX "Build with MaterialX support" ON) option(TINYUSDZ_WITH_JSON "Build with JSON serialization support" OFF) option(TINYUSDZ_WITH_USDOBJ "Build with usdObj support(import wavefront .obj)" ON) @@ -406,14 +407,7 @@ set(TINYUSDZ_DEP_SOURCES ${PROJECT_SOURCE_DIR}/src/lz4/lz4.c ${PROJECT_SOURCE_DIR}/src/external/pystring.cpp ${PROJECT_SOURCE_DIR}/src/external/staticstruct.cc - ${PROJECT_SOURCE_DIR}/src/external/pugixml.cpp #${PROJECT_SOURCE_DIR}/src/external/tinyxml2/tinyxml2.cpp - #${PROJECT_SOURCE_DIR}/src/external/string_id/string_id.cpp - #${PROJECT_SOURCE_DIR}/src/external/string_id/error.cpp - #${PROJECT_SOURCE_DIR}/src/external/string_id/generator.cpp - #${PROJECT_SOURCE_DIR}/src/external/string_id/database.cpp - #${PROJECT_SOURCE_DIR}/src/external/ryu/ryu/s2d.c - #${PROJECT_SOURCE_DIR}/src/external/ryu/ryu/s2f.c ) if (TINYUSDZ_WITH_BUILTIN_IMAGE_LOADER) @@ -423,6 +417,9 @@ if (TINYUSDZ_WITH_BUILTIN_IMAGE_LOADER) PROPERTIES COMPILE_DEFINITIONS "FPNG_NO_SSE=1") endif() +if(TINYUSDZ_WITH_JSON) + list(APPEND TINYUSDZ_DEP_SOURCES ${PROJECT_SOURCE_DIR}/src/external/pugixml.cpp) +endif() if(TINYUSDZ_WITH_JSON) list(APPEND TINYUSDZ_DEP_SOURCES ${PROJECT_SOURCE_DIR}/src/json-to-usd.cc) @@ -722,6 +719,11 @@ target_include_directories(tinyusdz_object # PRIVATE ${PROJECT_SOURCE_DIR}/src/external/jsonhpp/) #endif() +if(TINYUSDZ_WITH_USDMTLX) + target_compile_definitions(tinyusdz_object + PRIVATE "TINYUSDZ_USE_USDMTLX") +endif() + if(TINYUSDZ_WITH_USDFBX) target_compile_definitions(tinyusdz_object PRIVATE "TINYUSDZ_USE_USDFBX") diff --git a/src/usdMtlx.cc b/src/usdMtlx.cc index 94fe695d7..80a6621f0 100644 --- a/src/usdMtlx.cc +++ b/src/usdMtlx.cc @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: Apache 2.0 +// Copyright 2023 - Present, Light Transport Entertainment, Inc. + +#if defined(TINYUSDZ_USE_USDMTLX) #ifdef __clang__ #pragma clang diagnostic push @@ -10,14 +14,18 @@ #ifdef __clang__ #pragma clang diagnostic pop #endif +#endif // TINYUSDZ_USE_USDMTLX #include +#include "usdMtlx.hh" + +#if defined(TINYUSDZ_USE_USDMTLX) + #include "io-util.hh" #include "tiny-format.hh" #include "ascii-parser.hh" // To parse color3f value #include "common-macros.inc" -#include "usdMtlx.hh" #include "value-pprint.hh" #include "pprinter.hh" #include "tiny-format.hh" @@ -82,7 +90,7 @@ bool is_supported_type(const std::string &typeName) { //if (typeName.compare("color") == 0) return true; //if (typeName.compare("geomname") == 0) return true; //if (typeName.compare("geomnamearray") == 0) return true; - + return false; } @@ -465,6 +473,38 @@ bool WriteMaterialXToString(const MtlxModel &mtlx, std::string &xml_str, return false; } - //} // namespace usdMtlx } // namespace tinyusdz + +#else + +namespace tinyusdz { + +bool ReadMaterialXFromFile(const AssetResolutionResolver &resolver, const std::string &asset_path, MtlxModel *mtlx, std::string *err) { + + (void)resolver; + (void)asset_path; + (void)mtlx; + + if (err) { + (*err) += "MaterialX support is disabled in this build.\n"; + } + return false; +} + +bool WriteMaterialXToString(const MtlxModel &mtlx, std::string &xml_str, + std::string *err) { + (void)mtlx; + (void)xml_str; + + if (err) { + (*err) += "MaterialX support is disabled in this build.\n"; + } + return false; +} + +} // namespace tinyusdz + +#endif // TINYUSDZ_USE_USDMTLX + +