USD: prepare for building with Python support and shared libraries
Shared libraries and USD plugins will be placed in the same folder, where USD already looks for plugins. This means that specifying the path to the plugins will no longer be needed once the new libraries are available for all platforms. For now the code was refactored to support both cases. Ref T99618
This commit is contained in:
parent
ebff39d5bb
commit
70375c96d5
Notes:
blender-bot
2023-02-14 08:45:12 +01:00
Referenced by issue #99618, Library changes for Blender 3.5
|
@ -13,6 +13,7 @@
|
|||
#
|
||||
# This module defines
|
||||
# PYTHON_VERSION
|
||||
# PYTHON_VERSION_NO_DOTS
|
||||
# PYTHON_INCLUDE_DIRS
|
||||
# PYTHON_INCLUDE_CONFIG_DIRS
|
||||
# PYTHON_LIBRARIES
|
||||
|
@ -64,11 +65,11 @@ IF(DEFINED PYTHON_LIBPATH)
|
|||
SET(_IS_LIB_PATH_DEF ON)
|
||||
ENDIF()
|
||||
|
||||
STRING(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
|
||||
STRING(REPLACE "." "" PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
|
||||
|
||||
SET(_python_SEARCH_DIRS
|
||||
${PYTHON_ROOT_DIR}
|
||||
"$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}"
|
||||
"$ENV{HOME}/py${PYTHON_VERSION_NO_DOTS}"
|
||||
"/opt/lib/python-${PYTHON_VERSION}"
|
||||
)
|
||||
|
||||
|
@ -211,7 +212,6 @@ IF(PYTHONLIBSUNIX_FOUND)
|
|||
)
|
||||
ENDIF()
|
||||
|
||||
UNSET(_PYTHON_VERSION_NO_DOTS)
|
||||
UNSET(_PYTHON_ABI_FLAGS)
|
||||
UNSET(_python_SEARCH_DIRS)
|
||||
|
||||
|
|
|
@ -59,6 +59,9 @@ ELSE()
|
|||
get_filename_component(USD_LIBRARY_DIR ${USD_LIBRARY} DIRECTORY)
|
||||
SET(USD_INCLUDE_DIRS ${USD_INCLUDE_DIR})
|
||||
set(USD_LIBRARIES ${USD_LIBRARY})
|
||||
IF(EXISTS ${USD_INCLUDE_DIR}/pxr/base/tf/pyModule.h)
|
||||
SET(USD_PYTHON_SUPPORT ON)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ if(UNIX AND NOT APPLE)
|
|||
add_definitions(-D_GLIBCXX_PERMIT_BACKWARD_HASH)
|
||||
endif()
|
||||
if(WIN32)
|
||||
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN)
|
||||
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN -DBOOST_DEBUG_PYTHON)
|
||||
endif()
|
||||
add_definitions(-DPXR_STATIC)
|
||||
add_definitions(-DBOOST_ALL_NO_LIB)
|
||||
|
||||
# USD headers use deprecated TBB headers, silence warning.
|
||||
add_definitions(-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1)
|
||||
|
@ -56,6 +56,7 @@ set(INC_SYS
|
|||
${USD_INCLUDE_DIRS}
|
||||
${BOOST_INCLUDE_DIR}
|
||||
${TBB_INCLUDE_DIR}
|
||||
${PYTHON_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
set(SRC
|
||||
|
@ -122,6 +123,7 @@ set(LIB
|
|||
|
||||
list(APPEND LIB
|
||||
${BOOST_LIBRARIES}
|
||||
${PYTHON_LIBRARIES}
|
||||
)
|
||||
|
||||
if(WITH_OPENVDB)
|
||||
|
|
|
@ -174,8 +174,6 @@ bool USD_export(bContext *C,
|
|||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
|
||||
blender::io::usd::ensure_usd_plugin_path_registered();
|
||||
|
||||
blender::io::usd::ExportJobData *job = static_cast<blender::io::usd::ExportJobData *>(
|
||||
MEM_mallocN(sizeof(blender::io::usd::ExportJobData), "ExportJobData"));
|
||||
|
||||
|
|
|
@ -382,13 +382,16 @@ static void import_freejob(void *user_data)
|
|||
|
||||
using namespace blender::io::usd;
|
||||
|
||||
void USD_ensure_plugin_path_registered()
|
||||
{
|
||||
blender::io::usd::ensure_usd_plugin_path_registered();
|
||||
}
|
||||
|
||||
bool USD_import(struct bContext *C,
|
||||
const char *filepath,
|
||||
const USDImportParams *params,
|
||||
bool as_background_job)
|
||||
{
|
||||
blender::io::usd::ensure_usd_plugin_path_registered();
|
||||
|
||||
/* Using new here since `MEM_*` functions do not call constructor to properly initialize data. */
|
||||
ImportJobData *job = new ImportJobData();
|
||||
job->bmain = CTX_data_main(C);
|
||||
|
@ -542,9 +545,6 @@ CacheArchiveHandle *USD_create_handle(struct Main * /*bmain*/,
|
|||
const char *filepath,
|
||||
ListBase *object_paths)
|
||||
{
|
||||
/* Must call this so that USD file format plugins are loaded. */
|
||||
ensure_usd_plugin_path_registered();
|
||||
|
||||
pxr::UsdStageRefPtr stage = pxr::UsdStage::Open(filepath);
|
||||
|
||||
if (!stage) {
|
||||
|
|
|
@ -11,6 +11,10 @@ namespace blender::io::usd {
|
|||
|
||||
void ensure_usd_plugin_path_registered()
|
||||
{
|
||||
/* if PXR_PYTHON_SUPPORT_ENABLED is defined, we *must* be dynamic and
|
||||
the plugins are placed relative to the USD shared library hence no
|
||||
hinting is required. */
|
||||
#ifndef PXR_PYTHON_SUPPORT_ENABLED
|
||||
static bool plugin_path_registered = false;
|
||||
if (plugin_path_registered) {
|
||||
return;
|
||||
|
@ -22,6 +26,7 @@ void ensure_usd_plugin_path_registered()
|
|||
const std::string blender_usd_datafiles = BKE_appdir_folder_id(BLENDER_DATAFILES, "usd");
|
||||
/* The trailing slash indicates to the USD library that the path is a directory. */
|
||||
pxr::PlugRegistry::GetInstance().RegisterPlugins(blender_usd_datafiles + "/");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace blender::io::usd
|
||||
|
|
|
@ -36,9 +36,12 @@ std::string register_usd_plugins_for_tests()
|
|||
BLI_assert(path_len + 1 < FILE_MAX);
|
||||
usd_datafiles_dir[path_len] = '/';
|
||||
usd_datafiles_dir[path_len + 1] = '\0';
|
||||
|
||||
/* if PXR_PYTHON_SUPPORT_ENABLED is defined, we *must* be dynamic and
|
||||
the plugins are placed relative to the USD shared library hence no
|
||||
hinting is required. */
|
||||
#ifndef PXR_PYTHON_SUPPORT_ENABLED
|
||||
pxr::PlugRegistry::GetInstance().RegisterPlugins(usd_datafiles_dir);
|
||||
|
||||
#endif
|
||||
return usd_datafiles_dir;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ struct CacheReader *CacheReader_open_usd_object(struct CacheArchiveHandle *handl
|
|||
|
||||
void USD_CacheReader_incref(struct CacheReader *reader);
|
||||
void USD_CacheReader_free(struct CacheReader *reader);
|
||||
|
||||
void USD_ensure_plugin_path_registered(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,7 @@ set(INC
|
|||
../blender/editors/include
|
||||
../blender/gpu
|
||||
../blender/imbuf
|
||||
../blender/io/usd
|
||||
../blender/makesdna
|
||||
../blender/makesrna
|
||||
../blender/render
|
||||
|
@ -1312,10 +1313,32 @@ blender_target_include_dirs(blender ${INC})
|
|||
# These files are required at runtime.
|
||||
if(WITH_USD)
|
||||
add_definitions(-DWITH_USD)
|
||||
install(
|
||||
DIRECTORY ${USD_LIBRARY_DIR}/usd
|
||||
DESTINATION "${TARGETDIR_VER}/datafiles"
|
||||
)
|
||||
absolute_include_dirs(../blender/io/usd)
|
||||
|
||||
# On windows the usd library sits in ./blender.shared copy the files
|
||||
# relative to the location of the USD dll, if the dll does not exist
|
||||
# assume we are linking against the static 3.5 lib.
|
||||
if(WIN32 AND
|
||||
(
|
||||
EXISTS ${LIBDIR}/usd/lib/usd_usd_ms.dll OR # USD 22.03
|
||||
EXISTS ${LIBDIR}/usd/lib/usd_ms.dll # USD 22.11
|
||||
)
|
||||
)
|
||||
install(DIRECTORY
|
||||
${USD_LIBRARY_DIR}/usd
|
||||
DESTINATION "./blender.shared"
|
||||
)
|
||||
elseif(USD_PYTHON_SUPPORT)
|
||||
install(DIRECTORY
|
||||
${USD_LIBRARY_DIR}/usd
|
||||
DESTINATION ${TARGETDIR_LIB}
|
||||
)
|
||||
else()
|
||||
install(DIRECTORY
|
||||
${USD_LIBRARY_DIR}/usd
|
||||
DESTINATION "${TARGETDIR_VER}/datafiles"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
|
|
|
@ -95,6 +95,10 @@
|
|||
# include "sdlew.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_USD
|
||||
# include "usd.h"
|
||||
#endif
|
||||
|
||||
#include "creator_intern.h" /* Own include. */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@ -471,6 +475,10 @@ int main(int argc,
|
|||
/* Initialize sub-systems that use `BKE_appdir.h`. */
|
||||
IMB_init();
|
||||
|
||||
#ifdef WITH_USD
|
||||
USD_ensure_plugin_path_registered();
|
||||
#endif
|
||||
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
/* First test for background-mode (#Global.background) */
|
||||
BLI_args_parse(ba, ARG_PASS_SETTINGS, NULL, NULL);
|
||||
|
|
Loading…
Reference in New Issue