[Bf-blender-cvs] [def165ca0bb] new-object-types: Volumes: improve openvdb grid access API, split off render utilities

Brecht Van Lommel noreply at git.blender.org
Sun Feb 16 11:30:34 CET 2020


Commit: def165ca0bbe4d127cfd01a222be8d4b9a7c92e1
Author: Brecht Van Lommel
Date:   Sun Feb 16 10:27:47 2020 +0100
Branches: new-object-types
https://developer.blender.org/rBdef165ca0bbe4d127cfd01a222be8d4b9a7c92e1

Volumes: improve openvdb grid access API, split off render utilities

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

M	intern/cycles/blender/blender_image.cpp
M	intern/cycles/blender/blender_util.h
M	intern/cycles/blender/blender_volume.cpp
M	source/blender/blenkernel/BKE_volume.h
A	source/blender/blenkernel/BKE_volume_render.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/volume.cc
A	source/blender/blenkernel/intern/volume_render.cc
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl_volume.c

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

diff --git a/intern/cycles/blender/blender_image.cpp b/intern/cycles/blender/blender_image.cpp
index b476def9bb8..69de40bf572 100644
--- a/intern/cycles/blender/blender_image.cpp
+++ b/intern/cycles/blender/blender_image.cpp
@@ -76,6 +76,7 @@ void BlenderSession::builtin_image_info(const string &builtin_name,
       BL::VolumeGrid b_grid = *b_grid_iter;
 
       if (b_grid.name() == builtin_name) {
+        Volume *volume = (Volume *)b_volume.ptr.data;
         VolumeGrid *volume_grid = (VolumeGrid *)b_grid.ptr.data;
 
         /* Skip grid that we can parse as float channels. */
@@ -85,11 +86,10 @@ void BlenderSession::builtin_image_info(const string &builtin_name,
 
         /* Load grid, and free after reading voxels if it wasn't already loaded. */
         metadata.builtin_free_cache = !b_grid.is_loaded();
-        b_grid.load();
 
         /* Compute grid dimensions. */
         size_t min[3], max[3];
-        if (!BKE_volume_grid_dense_bounds(volume_grid, min, max)) {
+        if (!BKE_volume_grid_dense_bounds(volume, volume_grid, min, max)) {
           return;
         }
 
@@ -294,12 +294,13 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
       BL::VolumeGrid b_grid = *b_grid_iter;
 
       if (b_grid.name() == builtin_name) {
+        Volume *volume = (Volume *)b_volume.ptr.data;
         VolumeGrid *volume_grid = (VolumeGrid *)b_grid.ptr.data;
 
         /* TODO: don't compute resolution twice */
         size_t min[3], max[3];
-        if (BKE_volume_grid_dense_bounds(volume_grid, min, max)) {
-          BKE_volume_grid_dense_voxels(volume_grid, min, max, pixels);
+        if (BKE_volume_grid_dense_bounds(volume, volume_grid, min, max)) {
+          BKE_volume_grid_dense_voxels(volume, volume_grid, min, max, pixels);
         }
 
         if (free_cache) {
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 3c7f2fda3f8..e6807496e07 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -38,12 +38,16 @@ unsigned char *BKE_image_get_pixels_for_frame(void *image, int frame, int tile);
 float *BKE_image_get_float_pixels_for_frame(void *image, int frame, int tile);
 
 struct VolumeGrid;
-bool BKE_volume_grid_dense_bounds(const VolumeGrid *volume_grid, size_t min[3], size_t max[3]);
+bool BKE_volume_grid_dense_bounds(const Volume *volume,
+                                  VolumeGrid *volume_grid,
+                                  size_t min[3],
+                                  size_t max[3]);
 void BKE_volume_grid_dense_transform_matrix(const VolumeGrid *volume_grid,
                                             const size_t min[3],
                                             const size_t max[3],
                                             float mat[4][4]);
-void BKE_volume_grid_dense_voxels(const VolumeGrid *volume_grid,
+void BKE_volume_grid_dense_voxels(const Volume *volume,
+                                  VolumeGrid *volume_grid,
                                   const size_t min[3],
                                   const size_t max[3],
                                   float *voxels);
diff --git a/intern/cycles/blender/blender_volume.cpp b/intern/cycles/blender/blender_volume.cpp
index 605c74cc979..bdcd25d08f2 100644
--- a/intern/cycles/blender/blender_volume.cpp
+++ b/intern/cycles/blender/blender_volume.cpp
@@ -145,11 +145,10 @@ static void sync_volume_object(BL::BlendData &b_data, BL::Object &b_ob, Scene *s
         Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED_TRANSFORM);
         Transform *tfm = attr->data_transform();
 
-        b_grid.load();
-
+        Volume *volume = (Volume *)b_volume.ptr.data;
         VolumeGrid *volume_grid = (VolumeGrid *)b_grid.ptr.data;
         size_t min[3], max[3];
-        if (BKE_volume_grid_dense_bounds(volume_grid, min, max)) {
+        if (BKE_volume_grid_dense_bounds(volume, volume_grid, min, max)) {
           float mat[4][4];
           BKE_volume_grid_dense_transform_matrix(volume_grid, min, max, mat);
           *tfm = transform_inverse(get_transform(mat));
diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h
index cf0260b417b..4d4b152a579 100644
--- a/source/blender/blenkernel/BKE_volume.h
+++ b/source/blender/blenkernel/BKE_volume.h
@@ -25,7 +25,7 @@
 
 /** \file BKE_volume.h
  *  \ingroup bke
- *  \brief General operations for volumes.
+ *  \brief Volume datablock.
  */
 #ifdef __cplusplus
 extern "C" {
@@ -118,8 +118,8 @@ typedef enum VolumeGridType {
   VOLUME_GRID_VECTOR_INT,
 } VolumeGridType;
 
-bool BKE_volume_grid_load(struct Volume *volume, struct VolumeGrid *grid);
-void BKE_volume_grid_unload(struct Volume *volume, struct VolumeGrid *grid);
+bool BKE_volume_grid_load(const struct Volume *volume, struct VolumeGrid *grid);
+void BKE_volume_grid_unload(const struct Volume *volume, struct VolumeGrid *grid);
 bool BKE_volume_grid_is_loaded(const struct VolumeGrid *grid);
 
 /* Metadata */
@@ -128,21 +128,9 @@ VolumeGridType BKE_volume_grid_type(const struct VolumeGrid *grid);
 int BKE_volume_grid_channels(const struct VolumeGrid *grid);
 void BKE_volume_grid_transform_matrix(const struct VolumeGrid *grid, float mat[4][4]);
 
-/* Tree and Voxels */
+/* Bounds */
 bool BKE_volume_grid_bounds(const struct VolumeGrid *grid, float min[3], float max[3]);
 
-bool BKE_volume_grid_dense_bounds(const struct VolumeGrid *volume_grid,
-                                  size_t min[3],
-                                  size_t max[3]);
-void BKE_volume_grid_dense_transform_matrix(const struct VolumeGrid *volume_grid,
-                                            const size_t min[3],
-                                            const size_t max[3],
-                                            float mat[4][4]);
-void BKE_volume_grid_dense_voxels(const struct VolumeGrid *volume_grid,
-                                  const size_t min[3],
-                                  const size_t max[3],
-                                  float *voxels);
-
 /* Volume Editing
  *
  * These are intended for modifiers to use on evaluated datablocks.
@@ -151,11 +139,7 @@ void BKE_volume_grid_dense_voxels(const struct VolumeGrid *volume_grid,
  * preserves other settings such as viewport display options.
  *
  * copy_for_eval creates a volume datablock preserving everything except the
- * file path. Grids are shared with the source datablock, not copied.
- *
- * Before modifying grids after copy_for_eval, call ensure_writable first.
- * It will duplicate (or clear) the grid if it is shared with any other
- * datablocks, so that it can be safely modified. */
+ * file path. Grids are shared with the source datablock, not copied. */
 
 struct Volume *BKE_volume_new_for_eval(const struct Volume *volume_src);
 struct Volume *BKE_volume_copy_for_eval(struct Volume *volume_src, bool reference);
@@ -164,23 +148,24 @@ struct VolumeGrid *BKE_volume_grid_add(struct Volume *volume,
                                        const char *name,
                                        VolumeGridType type);
 void BKE_volume_grid_remove(struct Volume *volume, struct VolumeGrid *grid);
-void BKE_volume_grid_ensure_writable(struct Volume *volume,
-                                     struct VolumeGrid *grid,
-                                     const bool clear);
 
 #ifdef __cplusplus
 }
 #endif
 
-/* OpenVDB Grid
+/* OpenVDB Grid Access
  *
- * Access to OpenVDB grid for C++. This will call BKE_volume_grid_load if the
- * grid has not already been loaded into memory. */
+ * Access to OpenVDB grid for C++. These will automatically load grids from
+ * file or copy shared grids to make them writeable. */
 
 #if defined(__cplusplus) && defined(WITH_OPENVDB)
 #  include <openvdb/openvdb.h>
-openvdb::GridBase::Ptr BKE_volume_grid_ensure_openvdb(struct Volume *volume,
-                                                      struct VolumeGrid *grid);
+openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_metadata(const struct VolumeGrid *grid);
+openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_read(const struct Volume *volume,
+                                                             struct VolumeGrid *grid);
+openvdb::GridBase::Ptr BKE_volume_grid_openvdb_for_write(const struct Volume *volume,
+                                                         struct VolumeGrid *grid,
+                                                         const bool clear);
 #endif
 
 #endif
diff --git a/source/blender/blenkernel/BKE_volume_render.h b/source/blender/blenkernel/BKE_volume_render.h
new file mode 100644
index 00000000000..902b835306a
--- /dev/null
+++ b/source/blender/blenkernel/BKE_volume_render.h
@@ -0,0 +1,57 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * Contributor(s): Brecht Van Lommel.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_VOLUME_RENDER_H__
+#define __BKE_VOLUME_RENDER_H__
+
+/** \file BKE_volume_render.h
+ *  \ingroup bke
+ *  \brief Volume datablock rendering and viewport drawing utilities.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Volume;
+struct VolumeGrid;
+
+/* Dense Voxels */
+
+bool BKE_volume_grid_dense_bounds(const struct Volume *volume,
+                                  struct VolumeGrid *volume_grid,
+                                  size_t min[3],
+                                  size_t max[3]);
+void BKE_volume_grid_dense_transform_matrix(const struct VolumeGrid *volume_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list