[Bf-blender-cvs] [ea54cbe1b42] master: USD: add USD importer
Michael Kowalski
noreply at git.blender.org
Tue Aug 3 12:35:32 CEST 2021
Commit: ea54cbe1b42efb3107285c89685f555c06997062
Author: Michael Kowalski
Date: Tue Aug 3 11:55:53 2021 +0200
Branches: master
https://developer.blender.org/rBea54cbe1b42efb3107285c89685f555c06997062
USD: add USD importer
This is an initial implementation of a USD importer.
This work is comprised of Tangent Animation's open source USD importer,
combined with features @makowalski had implemented.
The design is very similar to the approach taken in the Alembic
importer. The core functionality resides in a collection of "reader"
classes, each of which is responsible for converting an instance of a
USD prim to the corresponding Blender Object representation.
The flow of control for the conversion can be followed in the
`import_startjob()` and `import_endjob()` functions in `usd_capi.cc`.
The `USDStageReader` class is responsible for traversing the USD stage
and instantiating the appropriate readers.
Reviewed By: sybren, HooglyBoogly
Differential Revision: https://developer.blender.org/D10700
===================================================================
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/abc_util.h
M source/blender/io/alembic/intern/alembic_capi.cc
M source/blender/io/common/CMakeLists.txt
A source/blender/io/common/IO_types.h
M source/blender/io/usd/CMakeLists.txt
R092 source/blender/io/usd/intern/usd_capi.cc source/blender/io/usd/intern/usd_capi_export.cc
A source/blender/io/usd/intern/usd_capi_import.cc
A source/blender/io/usd/intern/usd_common.cc
A source/blender/io/usd/intern/usd_common.h
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_instance.cc
A source/blender/io/usd/intern/usd_reader_instance.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_material.cc
A source/blender/io/usd/intern/usd_reader_material.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
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/makesrna/intern/rna_cachefile.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 5e68896a2a7..bcf579208a0 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -468,6 +468,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)")
self.layout.operator("wm.gpencil_import_svg", text="SVG as Grease Pencil")
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 78bfe8c9afb..adaef22d5bc 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -698,6 +698,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 eaba5d33a20..75180de94d8 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)
@@ -166,15 +170,30 @@ void BKE_cachefile_reader_open(CacheFile *cache_file,
Object *object,
const char *object_path)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_ALEMBIC) || defined(WITH_USD)
+
BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE);
if (cache_file->handle == NULL) {
return;
}
- /* Open Alembic cache reader. */
- *reader = CacheReader_open_alembic_object(cache_file->handle, *reader, object, object_path);
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ /* Open Alembic cache reader. */
+ *reader = CacheReader_open_alembic_object(cache_file->handle, *reader, object, object_path);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ /* Open USD cache reader. */
+ *reader = CacheReader_open_usd_object(cache_file->handle, *reader, object, object_path);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
/* Multiple modifiers and constraints can call this function concurrently. */
BLI_spin_lock(&spin);
@@ -197,16 +216,30 @@ void BKE_cachefile_reader_open(CacheFile *cache_file,
void BKE_cachefile_reader_free(CacheFile *cache_file, struct CacheReader **reader)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_ALEMBIC) || defined(WITH_USD)
/* Multiple modifiers and constraints can call this function concurrently, and
* cachefile_handle_free() can also be called at the same time. */
BLI_spin_lock(&spin);
if (*reader != NULL) {
if (cache_file) {
BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE);
+
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ ABC_CacheReader_free(*reader);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ USD_CacheReader_free(*reader);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
}
- CacheReader_free(*reader);
*reader = NULL;
if (cache_file && cache_file->handle_readers) {
@@ -221,7 +254,8 @@ void BKE_cachefile_reader_free(CacheFile *cache_file, struct CacheReader **reade
static void cachefile_handle_free(CacheFile *cache_file)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_ALEMBIC) || defined(WITH_USD)
+
/* Free readers in all modifiers and constraints that use the handle, before
* we free the handle itself. */
BLI_spin_lock(&spin);
@@ -230,7 +264,21 @@ static void cachefile_handle_free(CacheFile *cache_file)
GSET_ITER (gs_iter, cache_file->handle_readers) {
struct CacheReader **reader = BLI_gsetIterator_getKey(&gs_iter);
if (*reader != NULL) {
- CacheReader_free(*reader);
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ ABC_CacheReader_free(*reader);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ USD_CacheReader_free(*reader);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
+
*reader = NULL;
}
}
@@ -242,7 +290,22 @@ static void cachefile_handle_free(CacheFile *cache_file)
/* Free handle. */
if (cache_file->handle) {
- ABC_free_handle(cache_file->handle);
+
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ ABC_free_handle(cache_file->handle);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ USD_free_handle(cache_file->handle);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
+
cache_file->handle = NULL;
}
@@ -289,8 +352,18 @@ 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 = ABC_create_handle(bmain, filepath, &cache_file->object_paths);
+ BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
+ }
+#endif
+#ifdef WITH_USD
+ if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc")) {
+ cache_file->type = CACHEFILE_TYPE_USD;
+ cache_file->handle = USD_create_handle(bmain, filepath, &cache_file->object_paths);
+ BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
+ }
#endif
if (DEG_is_active(depsgraph)) {
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 47df31e3a2c..022073b0f12 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -95,6 +95,10 @@
# include "ABC_alembic.h"
#endif
+#ifdef WITH_USD
+# include "usd.h"
+#endif
+
/* ---------------------------------------------------------------------------- */
/* Useful macros for testing various common flag combinations */
@@ -5403,7 +5407,7 @@ static void transformcache_id_looper(bConstraint *con, ConstraintIDFunc func, vo
static void transformcache_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_ALEMBIC) || defined(WITH_USD)
bTransformCacheConstraint *data = con->data;
Scene *scene = cob->scene;
@@ -5421,7 +5425,20 @@ static void transformcache_evaluate(bConstraint *con, bConstraintOb *cob, ListBa
BKE_cachefile_reader_open(cache_file, &data->reader, cob->ob, data->object_path);
}
- ABC_get_transform(data->reader, cob->matrix, time, cache_file->scale);
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ ABC_get_transform(data->reader, cob->matrix, time, cache_file->scale);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ USD_get_transform(data->reader, cob->matrix, time * FPS, cache_file->scale);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
#else
UNUSED_VARS(con, cob);
#endif
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index 9fa34a1c55d..b2788ee49a2 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -52,6 +52,7 @@ void ED_operatortypes_io(void)
WM_operatortype_append(WM_OT_alembic_export);
#endif
#ifdef WITH_USD
+ WM_operatortype_append(WM_OT_usd_import);
WM_operatortype_append(WM_OT_usd_export);
#endif
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 0eadb38abb5..d0007d9e5be 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -22,23 +22,30 @@
*/
#ifdef WITH_USD
+# include "DNA_modifier_types.h"
# include "DNA_space_types.h"
+# include <string.h>
# include "BKE_context.h"
# include "BKE_main.h"
# include "BKE_report.h"
+# include "BLI_blenlib.h"
# include "BLI_path_util.h"
# include "BLI_string.h"
# include "BLI_utildefines.h"
# include "BLT_translation.h"
+# include "ED_object.h"
+
# include "MEM_guardedalloc.h"
# include "RNA_access.h"
# include "RNA_define.h"
+# include "RNA_enum_types.h"
+
# include "UI_interface.h"
# include "UI_resources.h"
@@ -50,6 +57,8 @@
# include "io_usd.h"
# include "usd.h"
+# include "stdio.h"
+
const EnumPropertyItem rna_enum_usd_export_evaluation_mode_items[] = {
{DAG_EVAL_RENDER,
"RENDER",
@@ -242,4 +251,274 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
"are different settings for viewport and rendering");
}
+/* ====== USD Import ====== */
+
+static int wm_usd_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ eUSDOperatorOptions *options = MEM_callocN(sizeof(eUSDOperatorOptions), "eUSDOperatorOptions");
+ options->as_background_job = true;
+ op->customdata = options;
+
+ return WM_operator_filesel(C, op, event);
+}
+
+static int wm_usd_import_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);
+
+ eUSDOperatorOptions *options = (eUSDOperatorOptions *)op->customdata;
+ const bool as_backgro
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list