[Bf-blender-cvs] [ce3dd12371f] master: USD: add volume/VDB export

Piotr Makal noreply at git.blender.org
Fri May 6 11:45:58 CEST 2022


Commit: ce3dd12371f5bd02eb64488712d8c529ffe62f6b
Author: Piotr Makal
Date:   Fri May 6 11:36:27 2022 +0200
Branches: master
https://developer.blender.org/rBce3dd12371f5bd02eb64488712d8c529ffe62f6b

USD: add volume/VDB export

Add support for volume (OpenVDB) USD export:

- Allows to export both static and animated volumes.
- Supports volumes that have OpenVDB data from files or are generated in
  Blender with 'Mesh to Volume' modifier.
- For volumes that have generated data in Blender it also exports
  corresponding .vdb files. Those files are saved in a new folder named
  "volumes".
- Slightly changes the USD export UI panel. "Relative Texture Paths"
  becomes "Relative Paths" (and has separate UI box) as the
  functionality will now apply to both textures and volumes. Disabling
  of this option due to "Materials" checkbox being turned off has been
  removed.

Reviewed By: sybren, makowalski

Differential Revision: https://developer.blender.org/D14193

Manifest Task: T95407

===================================================================

M	source/blender/editors/io/io_usd.c
M	source/blender/io/alembic/exporter/abc_export_capi.cc
M	source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
M	source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
M	source/blender/io/common/IO_abstract_hierarchy_iterator.h
M	source/blender/io/common/intern/abstract_hierarchy_iterator.cc
M	source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc
M	source/blender/io/usd/CMakeLists.txt
M	source/blender/io/usd/intern/usd_capi_export.cc
M	source/blender/io/usd/intern/usd_exporter_context.h
M	source/blender/io/usd/intern/usd_hierarchy_iterator.cc
M	source/blender/io/usd/intern/usd_hierarchy_iterator.h
M	source/blender/io/usd/intern/usd_writer_abstract.cc
M	source/blender/io/usd/intern/usd_writer_abstract.h
M	source/blender/io/usd/intern/usd_writer_material.cc
A	source/blender/io/usd/intern/usd_writer_volume.cc
A	source/blender/io/usd/intern/usd_writer_volume.h
M	source/blender/io/usd/usd.h

===================================================================

diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index e0616a0cec3..97ca9b026ec 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -118,7 +118,7 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
   const bool generate_preview_surface = RNA_boolean_get(op->ptr, "generate_preview_surface");
   const bool export_textures = RNA_boolean_get(op->ptr, "export_textures");
   const bool overwrite_textures = RNA_boolean_get(op->ptr, "overwrite_textures");
-  const bool relative_texture_paths = RNA_boolean_get(op->ptr, "relative_texture_paths");
+  const bool relative_paths = RNA_boolean_get(op->ptr, "relative_paths");
 
   struct USDExportParams params = {
       export_animation,
@@ -133,7 +133,7 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
       generate_preview_surface,
       export_textures,
       overwrite_textures,
-      relative_texture_paths,
+      relative_paths,
   };
 
   bool ok = USD_export(C, filename, &params, as_background_job);
@@ -181,9 +181,9 @@ static void wm_usd_export_draw(bContext *UNUSED(C), wmOperator *op)
   const bool export_tex = RNA_boolean_get(ptr, "export_textures");
   uiLayoutSetActive(row, export_mtl && preview && export_tex);
 
-  row = uiLayoutRow(col, true);
-  uiItemR(row, ptr, "relative_texture_paths", 0, NULL, ICON_NONE);
-  uiLayoutSetActive(row, export_mtl && preview);
+  box = uiLayoutBox(layout);
+  col = uiLayoutColumnWithHeading(box, true, IFACE_("File References"));
+  uiItemR(col, ptr, "relative_paths", 0, NULL, ICON_NONE);
 
   box = uiLayoutBox(layout);
   uiItemL(box, IFACE_("Experimental"), ICON_NONE);
@@ -282,10 +282,11 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
                   "Allow overwriting existing texture files when exporting textures");
 
   RNA_def_boolean(ot->srna,
-                  "relative_texture_paths",
+                  "relative_paths",
                   true,
-                  "Relative Texture Paths",
-                  "Make texture asset paths relative to the USD file");
+                  "Relative Paths",
+                  "Use relative paths to reference external files (i.e. textures, volumes) in "
+                  "USD, otherwise use absolute paths");
 }
 
 /* ====== USD Import ====== */
diff --git a/source/blender/io/alembic/exporter/abc_export_capi.cc b/source/blender/io/alembic/exporter/abc_export_capi.cc
index c1ff7df0c37..edaf53b3efa 100644
--- a/source/blender/io/alembic/exporter/abc_export_capi.cc
+++ b/source/blender/io/alembic/exporter/abc_export_capi.cc
@@ -115,7 +115,7 @@ static void export_startjob(void *customdata,
     return;
   }
 
-  ABCHierarchyIterator iter(data->depsgraph, abc_archive.get(), data->params);
+  ABCHierarchyIterator iter(data->bmain, data->depsgraph, abc_archive.get(), data->params);
 
   if (export_animation) {
     CLOG_INFO(&LOG, 2, "Exporting animation");
diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
index d33adfdb4b9..ab62694b802 100644
--- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
+++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
@@ -26,10 +26,11 @@
 
 namespace blender::io::alembic {
 
-ABCHierarchyIterator::ABCHierarchyIterator(Depsgraph *depsgraph,
+ABCHierarchyIterator::ABCHierarchyIterator(Main *bmain,
+                                           Depsgraph *depsgraph,
                                            ABCArchive *abc_archive,
                                            const AlembicExportParams &params)
-    : AbstractHierarchyIterator(depsgraph), abc_archive_(abc_archive), params_(params)
+    : AbstractHierarchyIterator(bmain, depsgraph), abc_archive_(abc_archive), params_(params)
 {
 }
 
diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
index 24d3f319fbd..f7814c28a55 100644
--- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
+++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
@@ -13,6 +13,7 @@
 #include <Alembic/Abc/OObject.h>
 
 struct Depsgraph;
+struct Main;
 struct Object;
 
 namespace blender::io::alembic {
@@ -36,7 +37,8 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator {
   const AlembicExportParams &params_;
 
  public:
-  ABCHierarchyIterator(Depsgraph *depsgraph,
+  ABCHierarchyIterator(Main *bmain,
+                       Depsgraph *depsgraph,
                        ABCArchive *abc_archive_,
                        const AlembicExportParams &params);
 
diff --git a/source/blender/io/common/IO_abstract_hierarchy_iterator.h b/source/blender/io/common/IO_abstract_hierarchy_iterator.h
index 3c6b6cc631e..3371501db95 100644
--- a/source/blender/io/common/IO_abstract_hierarchy_iterator.h
+++ b/source/blender/io/common/IO_abstract_hierarchy_iterator.h
@@ -30,6 +30,7 @@
 struct Depsgraph;
 struct DupliObject;
 struct ID;
+struct Main;
 struct Object;
 struct ParticleSystem;
 
@@ -204,12 +205,13 @@ class AbstractHierarchyIterator {
  protected:
   ExportGraph export_graph_;
   ExportPathMap duplisource_export_path_;
+  Main *bmain_;
   Depsgraph *depsgraph_;
   WriterMap writers_;
   ExportSubset export_subset_;
 
  public:
-  explicit AbstractHierarchyIterator(Depsgraph *depsgraph);
+  explicit AbstractHierarchyIterator(Main *bmain, Depsgraph *depsgraph);
   virtual ~AbstractHierarchyIterator();
 
   /* Iterate over the depsgraph, create writers, and tell the writers to write.
diff --git a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc
index f0501d4cf62..82bb1c57833 100644
--- a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc
+++ b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc
@@ -161,8 +161,8 @@ bool AbstractHierarchyWriter::check_has_deforming_physics(const HierarchyContext
   return rbo != nullptr && rbo->type == RBO_TYPE_ACTIVE && (rbo->flag & RBO_FLAG_USE_DEFORM) != 0;
 }
 
-AbstractHierarchyIterator::AbstractHierarchyIterator(Depsgraph *depsgraph)
-    : depsgraph_(depsgraph), export_subset_({true, true})
+AbstractHierarchyIterator::AbstractHierarchyIterator(Main *bmain, Depsgraph *depsgraph)
+    : bmain_(bmain), depsgraph_(depsgraph), export_subset_({true, true})
 {
 }
 
diff --git a/source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc b/source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc
index 52cae89c2e8..81a3546259e 100644
--- a/source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc
+++ b/source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc
@@ -54,7 +54,8 @@ class TestingHierarchyIterator : public AbstractHierarchyIterator {
   used_writers hair_writers;
   used_writers particle_writers;
 
-  explicit TestingHierarchyIterator(Depsgraph *depsgraph) : AbstractHierarchyIterator(depsgraph)
+  explicit TestingHierarchyIterator(Main *bmain, Depsgraph *depsgraph)
+      : AbstractHierarchyIterator(bmain, depsgraph)
   {
   }
   ~TestingHierarchyIterator() override
@@ -105,7 +106,7 @@ class AbstractHierarchyIteratorTest : public BlendfileLoadingBaseTest {
   /* Create a test iterator. */
   void iterator_create()
   {
-    iterator = new TestingHierarchyIterator(depsgraph);
+    iterator = new TestingHierarchyIterator(bfile->main, depsgraph);
   }
   /* Free the test iterator if it is not nullptr. */
   void iterator_free()
diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt
index e2e959814fa..7a7c95b29f9 100644
--- a/source/blender/io/usd/CMakeLists.txt
+++ b/source/blender/io/usd/CMakeLists.txt
@@ -69,6 +69,7 @@ set(SRC
   intern/usd_writer_mesh.cc
   intern/usd_writer_metaball.cc
   intern/usd_writer_transform.cc
+  intern/usd_writer_volume.cc
 
   intern/usd_reader_camera.cc
   intern/usd_reader_curve.cc
@@ -95,6 +96,7 @@ set(SRC
   intern/usd_writer_mesh.h
   intern/usd_writer_metaball.h
   intern/usd_writer_transform.h
+  intern/usd_writer_volume.h
 
   intern/usd_reader_camera.h
   intern/usd_reader_curve.h
@@ -119,8 +121,15 @@ list(APPEND LIB
   ${BOOST_LIBRARIES}
 )
 
-list(APPEND LIB
-)
+if(WITH_OPENVDB)
+  add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS})
+  list(APPEND INC_SYS
+    ${OPENVDB_INCLUDE_DIRS}
+  )
+  list(APPEND LIB
+    ${OPENVDB_LIBRARIES}
+  )
+endif()
 
 blender_add_lib(bf_usd "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
 
diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc
index d7c1a5adc7c..c52d791f3b3 100644
--- a/source/blender/io/usd/intern/usd_capi_export.cc
+++ b/source/blender/io/usd/intern/usd_capi_export.cc
@@ -97,7 +97,7 @@ static void export_startjob(void *customdata,
     usd_stage->SetEndTimeCode(scene->r.efra);
   }
 
-  USDHierarchyIterator iter(data->depsgraph, usd_stage, data->params);
+  USDHierarchyIterator iter(data->bmain, data->depsgraph, usd_stage, data->params);
 
   if (data->params.export_animation) {
     /* Writing the animated frames is not 100% of the work, but it's our best guess. */
diff --git a/source/blender/io/usd/intern/usd_exporter_context.h b/source/blender/io/usd/intern/usd_exporter_context.h
index 5a3f94d01f8..a636d849296 100644
--- a/source/blender/io/usd/intern/usd_exporter_context.h
+++ b/source/blender/io/usd/intern/usd_exporter_context.h
@@ -8,12 +8,14 @@
 #include <pxr/usd/usd/common.h>
 
 struct Depsgraph;
+struct Main;
 
 namespace blender::io::usd {
 
 class USDHierarchyIterator;
 
 struct USDExporterContext {
+  Main *bmain;
   Depsgraph *depsgraph;
   const pxr::UsdStageRefPtr stage;
   const pxr::SdfPath usd_path;
diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc
index 7a0d896fb3e..51261c4d91e 100644
--- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc
+++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc
@@ -10,6 +10,7 @@
 #include "usd_writer_mesh.h"
 #include "usd_writer_metaball.h"
 #include "usd_writer_transform.h"
+#include "usd_writer_volume.h"
 
 #include <string>
 
@@ -28,10 +29,11 @@
 
 namesp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list