Commit: 1e5e81a873874ac23ed390292221c9745c0bfc2b Author: Benjamin Skinner Date: Tue Nov 17 10:43:35 2020 -0500 Branches: usd-importer-T81257-merge https://developer.blender.org/rB1e5e81a873874ac23ed390292221c9745c0bfc2b
Initial USD Import open sourcing. Cherry-picked commit of Tangent Animation's USD importer from branch ta-usd-import in https://github.com/tangent-opensource/blender.git. =================================================================== M release/scripts/startup/bl_ui/space_topbar.py M source/blender/blenkernel/CMakeLists.txt M source/blender/blenkernel/intern/cachefile.c M source/blender/blenkernel/intern/constraint.c M source/blender/editors/io/io_ops.c M source/blender/editors/io/io_usd.c M source/blender/editors/io/io_usd.h M source/blender/io/alembic/ABC_alembic.h M source/blender/io/alembic/intern/alembic_capi.cc M source/blender/io/usd/CMakeLists.txt M source/blender/io/usd/intern/usd_capi.cc A source/blender/io/usd/intern/usd_reader_camera.cc A source/blender/io/usd/intern/usd_reader_camera.h A source/blender/io/usd/intern/usd_reader_curve.cc A source/blender/io/usd/intern/usd_reader_curve.h A source/blender/io/usd/intern/usd_reader_geom.cc A source/blender/io/usd/intern/usd_reader_geom.h A source/blender/io/usd/intern/usd_reader_light.cc A source/blender/io/usd/intern/usd_reader_light.h A source/blender/io/usd/intern/usd_reader_mesh.cc A source/blender/io/usd/intern/usd_reader_mesh.h A source/blender/io/usd/intern/usd_reader_nurbs.cc A source/blender/io/usd/intern/usd_reader_nurbs.h A source/blender/io/usd/intern/usd_reader_prim.cc A source/blender/io/usd/intern/usd_reader_prim.h A source/blender/io/usd/intern/usd_reader_stage.cc A source/blender/io/usd/intern/usd_reader_stage.h A source/blender/io/usd/intern/usd_reader_volume.cc A source/blender/io/usd/intern/usd_reader_volume.h A source/blender/io/usd/intern/usd_reader_xform.cc A source/blender/io/usd/intern/usd_reader_xform.h A source/blender/io/usd/intern/usd_util.cc A source/blender/io/usd/intern/usd_util.h M source/blender/io/usd/usd.h M source/blender/makesdna/DNA_cachefile_defaults.h M source/blender/makesdna/DNA_cachefile_types.h M source/blender/makesdna/DNA_customdata_types.h M source/blender/makesdna/DNA_modifier_types.h M source/blender/makesrna/intern/rna_cachefile.c M source/blender/makesrna/intern/rna_modifier.c M source/blender/modifiers/CMakeLists.txt M source/blender/modifiers/intern/MOD_meshsequencecache.c =================================================================== diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py index a7e28c38b9e..02cc4cc4266 100644 --- a/release/scripts/startup/bl_ui/space_topbar.py +++ b/release/scripts/startup/bl_ui/space_topbar.py @@ -441,6 +441,9 @@ class TOPBAR_MT_file_import(Menu): text="Collada (Default) (.dae)") if bpy.app.build_options.alembic: self.layout.operator("wm.alembic_import", text="Alembic (.abc)") + if bpy.app.build_options.usd: + self.layout.operator( + "wm.usd_import", text="Universal Scene Description (.usd, .usdc, .usda)") class TOPBAR_MT_file_export(Menu): diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 82f985a3227..3a7715a1d33 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -668,6 +668,13 @@ if(WITH_ALEMBIC) add_definitions(-DWITH_ALEMBIC) endif() +if(WITH_USD) + list(APPEND INC + ../io/usd + ) + add_definitions(-DWITH_USD) +endif() + if(WITH_OPENSUBDIV) list(APPEND INC_SYS ${OPENSUBDIV_INCLUDE_DIRS} diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index d6c31809a2e..fa11c43769c 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -55,6 +55,10 @@ # include "ABC_alembic.h" #endif +#ifdef WITH_USD +# include "usd.h" +#endif + static void cachefile_handle_free(CacheFile *cache_file); static void cache_file_init_data(ID *id) @@ -162,89 +166,178 @@ void BKE_cachefile_reader_open(CacheFile *cache_file, Object *object, const char *object_path) { + switch (cache_file->type) { #ifdef WITH_ALEMBIC - BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); + case CACHEFILE_TYPE_ALEMBIC: + BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); - if (cache_file->handle == NULL) { - return; - } + if (cache_file->handle == NULL) { + return; + } - /* Open Alembic cache reader. */ - *reader = CacheReader_open_alembic_object(cache_file->handle, *reader, object, object_path); + /* Open Alembic cache reader. */ + *reader = CacheReader_open_alembic_object( + (CacheArchiveHandle *)cache_file->handle, *reader, object, object_path); + + /* Multiple modifiers and constraints can call this function concurrently. */ + BLI_spin_lock(&spin); + if (*reader) { + /* Register in set so we can free it when the cache file changes. */ + if (cache_file->handle_readers == NULL) { + cache_file->handle_readers = BLI_gset_ptr_new("CacheFile.handle_readers"); + } + BLI_gset_reinsert(cache_file->handle_readers, reader, NULL); + } + else if (cache_file->handle_readers) { + /* Remove in case CacheReader_open_alembic_object free the existing reader. */ + BLI_gset_remove(cache_file->handle_readers, reader, NULL); + } + BLI_spin_unlock(&spin); + break; +#endif +#ifdef WITH_USD + case CACHEFILE_TYPE_USD: + BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); + if (cache_file->handle == NULL) { + return; + } - /* Multiple modifiers and constraints can call this function concurrently. */ - BLI_spin_lock(&spin); - if (*reader) { - /* Register in set so we can free it when the cache file changes. */ - if (cache_file->handle_readers == NULL) { - cache_file->handle_readers = BLI_gset_ptr_new("CacheFile.handle_readers"); - } - BLI_gset_reinsert(cache_file->handle_readers, reader, NULL); - } - else if (cache_file->handle_readers) { - /* Remove in case CacheReader_open_alembic_object free the existing reader. */ - BLI_gset_remove(cache_file->handle_readers, reader, NULL); - } - BLI_spin_unlock(&spin); -#else - UNUSED_VARS(cache_file, reader, object, object_path); + /* Open USD cache reader. */ + *reader = CacheReader_open_usd_object( + (USDStageHandle *)cache_file->handle, *reader, object, object_path); + /* Multiple modifiers and constraints can call this function concurrently. */ + BLI_spin_lock(&spin); + if (*reader) { + /* Register in set so we can free it when the cache file changes. */ + if (cache_file->handle_readers == NULL) { + cache_file->handle_readers = BLI_gset_ptr_new("CacheFile.handle_readers"); + } + BLI_gset_reinsert(cache_file->handle_readers, reader, NULL); + } + else if (cache_file->handle_readers) { + /* Remove in case CacheReader_open_usd_object free the existing reader. */ + BLI_gset_remove(cache_file->handle_readers, reader, NULL); + } + BLI_spin_unlock(&spin); + break; #endif + default: + UNUSED_VARS(cache_file, reader, object, object_path); + break; + } } void BKE_cachefile_reader_free(CacheFile *cache_file, struct CacheReader **reader) { + switch (cache_file->type) { #ifdef WITH_ALEMBIC - if (*reader != NULL) { - if (cache_file) { - BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); - } + case CACHEFILE_TYPE_ALEMBIC: + if (*reader != NULL) { + if (cache_file) { + BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); + } - CacheReader_free(*reader); - *reader = NULL; + CacheReader_free(*reader); + *reader = NULL; - /* Multiple modifiers and constraints can call this function concurrently. */ - BLI_spin_lock(&spin); - if (cache_file && cache_file->handle_readers) { - BLI_gset_remove(cache_file->handle_readers, reader, NULL); - } - BLI_spin_unlock(&spin); - } -#else - UNUSED_VARS(cache_file, reader); + /* Multiple modifiers and constraints can call this function concurrently. */ + BLI_spin_lock(&spin); + if (cache_file && cache_file->handle_readers) { + BLI_gset_remove(cache_file->handle_readers, reader, NULL); + } + BLI_spin_unlock(&spin); + } #endif +#ifdef WITH_USD + case CACHEFILE_TYPE_USD: + if (*reader != NULL) { + if (cache_file) { + BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); + } + + USDCacheReader_free(*reader); + *reader = NULL; + + /* Multiple modifiers and constraints can call this function concurrently. */ + BLI_spin_lock(&spin); + if (cache_file && cache_file->handle_readers) { + BLI_gset_remove(cache_file->handle_readers, reader, NULL); + } + BLI_spin_unlock(&spin); + } + break; +#endif + default: + UNUSED_VARS(cache_file, reader); + break; + } } static void cachefile_handle_free(CacheFile *cache_file) { + switch (cache_file->type) { #ifdef WITH_ALEMBIC - /* Free readers in all modifiers and constraints that use the handle, before - * we free the handle itself. */ - BLI_spin_lock(&spin); - if (cache_file->handle_readers) { - GSetIterator gs_iter; - GSET_ITER (gs_iter, cache_file->handle_readers) { - struct CacheReader **reader = BLI_gsetIterator_getKey(&gs_iter); - if (*reader != NULL) { - CacheReader_free(*reader); - *reader = NULL; + case CACHEFILE_TYPE_ALEMBIC: + /* Free readers in all modifiers and constraints that use the handle, before + * we free the handle itself. */ + BLI_spin_lock(&spin); + if (cache_file->handle_readers) { + GSetIterator gs_iter; + GSET_ITER (gs_iter, cache_file->handle_readers) { + struct CacheReader **reader = BLI_gsetIterator_getKey(&gs_iter); + if (*reader != NULL) { + CacheReader_free(*reader); + *reader = NULL; + } + } + + BLI_gset_free(cache_file->handle_readers, NULL); + cache_file->handle_readers = NULL; } - } + BLI_spin_unlock(&spin); - BLI_gset_free(cache_file->handle_readers, NULL); - cache_file->handle_readers = NULL; - } - BLI_spin_unlock(&spin); + /* Free handle. */ + if (cache_file->handle) { + ABC_free_handle((CacheArchiveHandle *)cache_file->handle); + cache_file->handle = NULL; + } - /* Free handle. */ - if (cache_file->handle) { - ABC_free_handle(cache_file->handle); - cache_file->handle = NULL; - } + cache_file->handle_filepath[0] = '\0'; + break; +#endif +#ifdef WITH_USD + case CACHEFILE_TYPE_USD: + /* Free readers in all modifiers and constraints that use the handle, before + * we free the handle itself. */ + BLI_spin_lock(&spin); + if (cache_file->handle_readers) { + GSetIterator gs_iter; + GSET_ITER (gs_iter, cache_file->handle_readers) { + struct CacheReader **reader = BLI_gsetIterator_getKey(&gs_iter); + if (*reader != NULL) { + USDCacheReader_free(*reader); + *reader = NULL; + } + } + + BLI_gset_free(cache_file->handle_readers, NULL); + cache_file->handle_readers = NULL; + } + BLI_spin_unlock(&spin); - cache_file->handle_filepath[0] = '\0'; -#else - UNUSED_VARS(cache_file); + /* Free handle. */ + if (cache_file->handle) { + USD_free_handle((USDStageHandle *)cache_file->handle); + cache_file->handle = NULL; + } + + cache_file->handle_filepath[0] = '\0'; + break; #endif + default: + UNUSED_VARS(cache_file); + break; + } } void *BKE_cachefile_add(Main *bmain, const char *name) @@ -284,8 +377,20 @@ void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file BLI_freelistN(&cache_file->object_paths); #ifdef WITH_ALEMBIC - cache_file->handle = ABC_create_handle(bmain, filepath, &cache_file->object_paths); - BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX); + if (BLI_path_extension_check_glob(filepath, "*abc")) { + cache_file->type = CACHEFILE_TYPE_ALEMBIC; + cache_file->handle = (CacheArchiveHandle *)ABC_create_handle( + bmain, filepath, &cache_file->object_paths); + BLI_strncpy(cache_file->handle_fi @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
