Commit: 147d8093204618345743699d1401c1c8c9d1bcb9 Author: Sybren A. Stüvel Date: Thu Jun 20 14:32:29 2019 +0200 Branches: sybren-usd https://developer.blender.org/rB147d8093204618345743699d1401c1c8c9d1bcb9
USD: Introducing experimental USD support This introduces very limited USD support: - The USD libraries are expected to be in /opt/usd/, not yet built by install_deps.sh. - The code requires cleanup & some restructuring to simplify once the way we want to iterate over the depsgraph is deemed ok. - No support for instancing, animation, or other features; all duplicated objects are made real in the USD file. This is fine for exporting a linked-in posed character, not so much for thousands of pebbles etc. - Debug prints are still in place. =================================================================== M CMakeLists.txt A build_files/cmake/Modules/FindUSD.cmake M source/blender/CMakeLists.txt M source/blender/editors/io/CMakeLists.txt M source/blender/editors/io/io_ops.c A source/blender/editors/io/io_usd.c A source/blender/editors/io/io_usd.h M source/blender/editors/space_file/filelist.c M source/blender/makesdna/DNA_space_types.h A source/blender/usd/CMakeLists.txt A source/blender/usd/intern/abstract_hierarchy_iterator.cc A source/blender/usd/intern/abstract_hierarchy_iterator.h A source/blender/usd/intern/debug_timer.h A source/blender/usd/intern/usd_capi.cc A source/blender/usd/intern/usd_exporter_context.h A source/blender/usd/intern/usd_hierarchy_iterator.cc A source/blender/usd/intern/usd_hierarchy_iterator.h A source/blender/usd/intern/usd_writer_abstract.cc A source/blender/usd/intern/usd_writer_abstract.h A source/blender/usd/intern/usd_writer_mesh.cc A source/blender/usd/intern/usd_writer_mesh.h A source/blender/usd/intern/usd_writer_transform.cc A source/blender/usd/intern/usd_writer_transform.h A source/blender/usd/usd.h =================================================================== diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dd165b0185..31ba7874fdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -323,6 +323,9 @@ option(WITH_CODEC_SNDFILE "Enable libsndfile Support (http://www.mega-nerd option(WITH_ALEMBIC "Enable Alembic Support" OFF) option(WITH_ALEMBIC_HDF5 "Enable Legacy Alembic Support (not officially supported)" OFF) +# Universal Scene Description support +option(WITH_USD "Enable Universal Scene Description (USD) Support" OFF) + # 3D format support # Disable opencollada when we don't have precompiled libs option(WITH_OPENCOLLADA "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA}) @@ -1762,6 +1765,7 @@ if(FIRST_RUN) info_cfg_option(WITH_OPENCOLORIO) info_cfg_option(WITH_OPENVDB) info_cfg_option(WITH_ALEMBIC) + info_cfg_option(WITH_USD) info_cfg_text("Compiler Options:") info_cfg_option(WITH_BUILDINFO) diff --git a/build_files/cmake/Modules/FindUSD.cmake b/build_files/cmake/Modules/FindUSD.cmake new file mode 100644 index 00000000000..65716e97c66 --- /dev/null +++ b/build_files/cmake/Modules/FindUSD.cmake @@ -0,0 +1,70 @@ +# - Find Universal Scene Description (USD) library +# Find the native USD includes and libraries +# This module defines +# USD_INCLUDE_DIRS, where to find USD headers, Set when +# USD_INCLUDE_DIR is found. +# USD_LIBRARIES, libraries to link against to use USD. +# USD_ROOT_DIR, The base directory to search for USD. +# This can also be an environment variable. +# USD_FOUND, If false, do not try to use USD. +# + +#============================================================================= +# Copyright 2019 Blender Foundation. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= + +# If USD_ROOT_DIR was defined in the environment, use it. +IF(NOT USD_ROOT_DIR AND NOT $ENV{USD_ROOT_DIR} STREQUAL "") + SET(USD_ROOT_DIR $ENV{USD_ROOT_DIR}) +ENDIF() + +SET(_usd_SEARCH_DIRS + ${USD_ROOT_DIR} + /usr/local + /sw # Fink + /opt/local # DarwinPorts + /opt/lib/usd + /opt/usd +) + +FIND_PATH(USD_INCLUDE_DIR + NAMES + pxr/usd/usd/api.h + HINTS + ${_usd_SEARCH_DIRS} + PATH_SUFFIXES + include +) + +FIND_LIBRARY(USD_LIBRARY + NAMES + usd + HINTS + ${_usd_SEARCH_DIRS} + PATH_SUFFIXES + lib64 lib lib/static +) + +# handle the QUIETLY and REQUIRED arguments and set USD_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(USD DEFAULT_MSG USD_LIBRARY USD_INCLUDE_DIR) + +IF(USD_FOUND) + SET(USD_LIBRARIES ${USD_LIBRARY}) + SET(USD_INCLUDE_DIRS ${USD_INCLUDE_DIR}) +ENDIF(USD_FOUND) + +MARK_AS_ADVANCED( + USD_INCLUDE_DIR + USD_LIBRARY +) + +UNSET(_usd_SEARCH_DIRS) diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt index 76442048594..2f00cce25b3 100644 --- a/source/blender/CMakeLists.txt +++ b/source/blender/CMakeLists.txt @@ -153,3 +153,6 @@ endif() if(WITH_ALEMBIC) add_subdirectory(alembic) endif() +if(WITH_USD) + add_subdirectory(usd) +endif() diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt index 5a35b251d0c..5afe348158f 100644 --- a/source/blender/editors/io/CMakeLists.txt +++ b/source/blender/editors/io/CMakeLists.txt @@ -26,6 +26,7 @@ set(INC ../../depsgraph ../../makesdna ../../makesrna + ../../usd ../../windowmanager ../../../../intern/guardedalloc ) @@ -39,11 +40,13 @@ set(SRC io_cache.c io_collada.c io_ops.c + io_usd.c io_alembic.h io_cache.h io_collada.h io_ops.h + io_usd.h ) set(LIB @@ -69,6 +72,13 @@ if(WITH_ALEMBIC) endif() endif() +if(WITH_USD) + list(APPEND LIB + bf_usd + ) + add_definitions(-DWITH_USD) +endif() + if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c index e04fe4a20c0..acb511a414d 100644 --- a/source/blender/editors/io/io_ops.c +++ b/source/blender/editors/io/io_ops.c @@ -33,6 +33,10 @@ # include "io_alembic.h" #endif +#ifdef WITH_USD +# include "io_usd.h" +#endif + #include "io_cache.h" void ED_operatortypes_io(void) @@ -46,6 +50,9 @@ void ED_operatortypes_io(void) WM_operatortype_append(WM_OT_alembic_import); WM_operatortype_append(WM_OT_alembic_export); #endif +#ifdef WITH_USD + WM_operatortype_append(WM_OT_usd_export); +#endif WM_operatortype_append(CACHEFILE_OT_open); WM_operatortype_append(CACHEFILE_OT_reload); diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c new file mode 100644 index 00000000000..21055ef0309 --- /dev/null +++ b/source/blender/editors/io/io_usd.c @@ -0,0 +1,115 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2016 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup editor/io + */ + +#ifdef WITH_USD +# include "DNA_space_types.h" + +# include "BKE_context.h" +# include "BKE_main.h" +# include "BKE_report.h" + +# include "BLI_path_util.h" +# include "BLI_string.h" + +# include "RNA_access.h" +# include "RNA_define.h" + +# include "WM_api.h" +# include "WM_types.h" + +# include "io_usd.h" +# include "usd.h" + +static int wm_usd_export_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + if (!RNA_struct_property_is_set(op->ptr, "_as_background_job")) { + RNA_boolean_set(op->ptr, "_as_background_job", true); + } + + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + Main *bmain = CTX_data_main(C); + char filepath[FILE_MAX]; + + if (BKE_main_blendfile_path(bmain)[0] == '\0') { + BLI_strncpy(filepath, "untitled", sizeof(filepath)); + } + else { + BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); + } + + BLI_path_extension_replace(filepath, sizeof(filepath), ".usdc"); + RNA_string_set(op->ptr, "filepath", filepath); + } + + WM_event_add_fileselect(C, op); + + return OPERATOR_RUNNING_MODAL; + + UNUSED_VARS(event); +} + +static int wm_usd_export_exec(bContext *C, wmOperator *op) +{ + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + BKE_report(op->reports, RPT_ERROR, "No filename given"); + return OPERATOR_CANCELLED; + } + + char filename[FILE_MAX]; + RNA_string_get(op->ptr, "filepath", filename); + + struct USDExportParams params = {}; + + /* Take some defaults from the scene, if not specified explicitly. */ + Scene *scene = CTX_data_scene(C); + + const bool as_background_job = RNA_boolean_get(op->ptr, "_as_background_job"); + bool ok = USD_export(scene, C, filename, ¶ms, as_background_job); + + return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; +} + +void WM_OT_usd_export(struct wmOperatorType *ot) +{ + ot->name = "Export USD"; + ot->description = "Export current scene in a USD archive"; + ot->idname = "WM_OT_usd_export"; + + ot->invoke = wm_usd_export_invoke; + ot->exec = wm_usd_export_exec; + ot->poll = WM_operator_winactive; + + WM_operator_properties_filesel( + ot, 0, FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); + + RNA_def_boolean( + ot->srna, + "_as_background_job", + false, + "Run as Background Job", + "Enable this to run the import in the background, disable to block Blender while importing. " + "This option is deprecated; EXECUTE this operator to run in the foreground, and INVOKE it " + "to run as a background job"); +} + +#endif /* WITH_USD */ diff --git a/source/blender/editors/io/io_usd.h b/source/blender/editors/io/io_usd.h new file mode 100644 index 00000000000..4ebf536c41f --- /dev/null +++ b/source/blender/editors/io/io_usd.h @@ -0,0 +1,31 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2016 Blender Foundation. + * All rights reserved. + */ + +#ifndef __IO_USD_H__ +#define __IO_USD_H__ + +/** \file + * \ingroup editor/io + */ + +struct wmOperatorType; + +void WM_OT_usd_export(struct wmOperatorType *ot); + +#endif /* __IO_USD_H__ */ diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 9004eaa7bf6..879ee27b756 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -2125,6 +2125,9 @@ int ED_path_extension_type(const char *path) else if (BLI_path_extension_check(path, ".abc" @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
