[Bf-blender-cvs] [4853f984005] new-object-types: Volumes: more work towards on-demand loading

Brecht Van Lommel noreply at git.blender.org
Wed Jan 29 20:54:59 CET 2020


Commit: 4853f9840054841086ef4093e8f8b876fe22cc5f
Author: Brecht Van Lommel
Date:   Wed Jan 29 20:48:33 2020 +0100
Branches: new-object-types
https://developer.blender.org/rB4853f9840054841086ef4093e8f8b876fe22cc5f

Volumes: more work towards on-demand loading

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

M	release/scripts/startup/bl_ui/properties_data_volume.py
M	source/blender/blenkernel/BKE_volume.h
M	source/blender/blenkernel/intern/packedFile.c
M	source/blender/blenkernel/intern/volume.cc
M	source/blender/draw/intern/draw_cache_impl_volume.c
M	source/blender/makesrna/intern/rna_volume.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_volume.py b/release/scripts/startup/bl_ui/properties_data_volume.py
index a5de87ea3d1..dfeadfb1af4 100644
--- a/release/scripts/startup/bl_ui/properties_data_volume.py
+++ b/release/scripts/startup/bl_ui/properties_data_volume.py
@@ -61,6 +61,7 @@ class DATA_PT_volume(DataButtonsPanel, Panel):
         layout = self.layout
 
         volume = context.volume
+        volume.grids.load()
 
         layout.prop(volume, "filepath", text="")
 
@@ -84,6 +85,7 @@ class DATA_PT_volume_grids(DataButtonsPanel, Panel):
         layout = self.layout
 
         volume = context.volume
+        volume.grids.load()
 
         layout.template_list("VOLUME_UL_grids", "grids", volume, "grids", volume.grids, "active_index", rows=2)
 
diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h
index 366dba87d2c..7b85fdb3d0e 100644
--- a/source/blender/blenkernel/BKE_volume.h
+++ b/source/blender/blenkernel/BKE_volume.h
@@ -49,7 +49,8 @@ struct Volume *BKE_volume_copy(struct Main *bmain, const struct Volume *volume);
 void BKE_volume_make_local(struct Main *bmain, struct Volume *volume, const bool lib_local);
 void BKE_volume_free(struct Volume *volume);
 
-void BKE_volume_reload(struct Main *bmain, struct Volume *volume);
+void BKE_volume_load(struct Volume *volume, struct Main *bmain);
+void BKE_volume_unload(struct Volume *volume);
 
 struct BoundBox *BKE_volume_boundbox_get(struct Object *ob);
 
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index e82af4ab887..34e86b29540 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -685,7 +685,7 @@ int BKE_packedfile_unpack_volume(Main *bmain,
       BKE_packedfile_free(volume->packedfile);
       volume->packedfile = NULL;
 
-      BKE_volume_reload(bmain, volume);
+      BKE_volume_unload(volume);
 
       ret_value = RET_OK;
     }
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index d8305e9711d..5ecb5ae6904 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -65,6 +65,11 @@ struct VolumeGrid {
 };
 
 struct VolumeGridVector : public std::vector<VolumeGrid> {
+  VolumeGridVector()
+  {
+    filepath[0] = '\0';
+  }
+
   /* Absolute file path that grids have been loaded from. */
   char filepath[FILE_MAX];
   /* File loading error message. */
@@ -144,12 +149,15 @@ void BKE_volume_free(Volume *volume)
 #endif
 }
 
-void BKE_volume_reload(Main *bmain, Volume *volume)
+void BKE_volume_load(Volume *volume, Main *bmain)
 {
 #ifdef WITH_OPENVDB
   VolumeGridVector &grids = *volume->grids;
-  grids.clear();
-  grids.error_msg.clear();
+
+  /* Test if there is a file to load, or if already loaded. */
+  if (volume->filepath[0] == '\0' || grids.filepath[0] != '\0') {
+    return;
+  }
 
   /* Get absolute file path. */
   STRNCPY(grids.filepath, volume->filepath);
@@ -183,6 +191,18 @@ void BKE_volume_reload(Main *bmain, Volume *volume)
 #endif
 }
 
+void BKE_volume_unload(Volume *volume)
+{
+#ifdef WITH_OPENVDB
+  VolumeGridVector &grids = *volume->grids;
+  grids.clear();
+  grids.error_msg.clear();
+  grids.filepath[0] = '\0';
+#else
+  UNUSED_VARS(volume);
+#endif
+}
+
 BoundBox *BKE_volume_boundbox_get(Object *ob)
 {
   BLI_assert(ob->type == OB_VOLUME);
@@ -192,13 +212,17 @@ BoundBox *BKE_volume_boundbox_get(Object *ob)
   }
 
   if (ob->runtime.bb == NULL) {
+    Volume *volume = (Volume *)ob->data;
+
     ob->runtime.bb = (BoundBox *)MEM_callocN(sizeof(BoundBox), "volume boundbox");
 
     float min[3], max[3];
     bool have_minmax = false;
     INIT_MINMAX(min, max);
 
-    Volume *volume = (Volume *)ob->data;
+    // TODO: avoid global access, load earlier?
+    BKE_volume_load(volume, G.main);
+
     const int num_grids = BKE_volume_num_grids(volume);
 
     for (int i = 0; i < num_grids; i++) {
diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c
index 73eeb1f9390..065d051a652 100644
--- a/source/blender/draw/intern/draw_cache_impl_volume.c
+++ b/source/blender/draw/intern/draw_cache_impl_volume.c
@@ -34,6 +34,7 @@
 #include "DNA_object_types.h"
 #include "DNA_volume_types.h"
 
+#include "BKE_global.h"
 #include "BKE_volume.h"
 
 #include "GPU_batch.h"
@@ -144,6 +145,9 @@ static DRWVolumeGrid *volume_grid_cache_get(Volume *volume,
   cache_grid->name = BLI_strdup(name);
   BLI_addtail(&cache->grids, cache_grid);
 
+  // TODO: avoid global access, load earlier?
+  BKE_volume_load(volume, G.main);
+
   /* Find grid with matching name. */
   int num_grids = BKE_volume_num_grids(volume);
   int grid_index = 0;
diff --git a/source/blender/makesrna/intern/rna_volume.c b/source/blender/makesrna/intern/rna_volume.c
index 9e51722b81e..75ad3f635c0 100644
--- a/source/blender/makesrna/intern/rna_volume.c
+++ b/source/blender/makesrna/intern/rna_volume.c
@@ -39,18 +39,20 @@
 #ifdef RNA_RUNTIME
 
 #  include "BKE_volume.h"
+
 #  include "DEG_depsgraph.h"
 
+#  include "WM_types.h"
+#  include "WM_api.h"
+
 /* Updates */
 
-static void rna_Volume_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
+static void rna_Volume_update_filepath(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
   Volume *volume = (Volume *)ptr->owner_id;
+  BKE_volume_unload(volume);
   DEG_id_tag_update(&volume->id, ID_RECALC_COPY_ON_WRITE);
-
-  /* TODO: remove and handle through depsgraph, but needs design for copy-on-write
-   * synchronization between copy and original */
-  BKE_volume_reload(bmain, volume);
+  WM_main_add_notifier(NC_GEOM | ND_DATA, volume);
 }
 
 /* Grid */
@@ -183,6 +185,12 @@ static void rna_def_volume_grids(BlenderRNA *brna, PropertyRNA *cprop)
       prop, "rna_VolumeGrids_error_message_get", "rna_VolumeGrids_error_message_length", NULL);
   RNA_def_property_ui_text(
       prop, "Error Message", "If loading grids failed, error message with details");
+
+  /* API */
+  FunctionRNA *func;
+  func = RNA_def_function(srna, "load", "BKE_volume_load");
+  RNA_def_function_ui_description(func, "Load file to populate grids list");
+  RNA_def_function_flag(func, FUNC_USE_MAIN);
 }
 
 static void rna_def_volume(BlenderRNA *brna)
@@ -196,7 +204,7 @@ static void rna_def_volume(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
   RNA_def_property_ui_text(prop, "File Path", "Volume sample file used by this Volume data-block");
-  RNA_def_property_update(prop, 0, "rna_Volume_update");
+  RNA_def_property_update(prop, 0, "rna_Volume_update_filepath");
 
   prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
   RNA_def_property_pointer_sdna(prop, NULL, "packedfile");



More information about the Bf-blender-cvs mailing list