Skip to content

Commit

Permalink
Make usdMtlx non-builtin module(built by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Aug 23, 2023
1 parent 38821b8 commit 67fa1eb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
46 changes: 43 additions & 3 deletions src/usdMtlx.cc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,14 +14,18 @@
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // TINYUSDZ_USE_USDMTLX

#include <sstream>

#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"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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


0 comments on commit 67fa1eb

Please sign in to comment.