[Bf-blender-cvs] [b51c292fc87] new-object-types: Volumes: show active grid in workbench

Brecht Van Lommel noreply at git.blender.org
Wed Feb 5 19:14:04 CET 2020


Commit: b51c292fc8765fb883fa80d82a6a2eb3760ed558
Author: Brecht Van Lommel
Date:   Wed Feb 5 16:56:16 2020 +0100
Branches: new-object-types
https://developer.blender.org/rBb51c292fc8765fb883fa80d82a6a2eb3760ed558

Volumes: show active grid in workbench

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

M	source/blender/blenkernel/BKE_volume.h
M	source/blender/blenkernel/intern/volume.cc
M	source/blender/draw/engines/eevee/eevee_volumes.c
M	source/blender/draw/engines/workbench/workbench_volume.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl_volume.c
M	source/blender/makesrna/intern/rna_volume.c

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

diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h
index 75b8db09c21..9224e95327b 100644
--- a/source/blender/blenkernel/BKE_volume.h
+++ b/source/blender/blenkernel/BKE_volume.h
@@ -93,6 +93,7 @@ bool BKE_volume_is_loaded(const struct Volume *volume);
 int BKE_volume_num_grids(struct Volume *volume);
 const char *BKE_volume_grids_error_msg(const struct Volume *volume);
 VolumeGrid *BKE_volume_grid_get(struct Volume *volume, int grid_index);
+VolumeGrid *BKE_volume_grid_active_get(struct Volume *volume);
 VolumeGrid *BKE_volume_grid_find(struct Volume *volume, const char *name);
 
 /* Grid
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index efb8bfc9d6b..aff410639e0 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -429,6 +429,17 @@ VolumeGrid *BKE_volume_grid_get(Volume *volume, int grid_index)
 #endif
 }
 
+VolumeGrid *BKE_volume_grid_active_get(Volume *volume)
+{
+  const int num_grids = BKE_volume_num_grids(volume);
+  if (num_grids == 0) {
+    return NULL;
+  }
+
+  const int index = clamp_i(volume->active_grid, 0, num_grids - 1);
+  return BKE_volume_grid_get(volume, index);
+}
+
 VolumeGrid *BKE_volume_grid_find(Volume *volume, const char *name)
 {
   int num_grids = BKE_volume_num_grids(volume);
diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c
index 1f8b520b5d4..ab98b7abe73 100644
--- a/source/blender/draw/engines/eevee/eevee_volumes.c
+++ b/source/blender/draw/engines/eevee/eevee_volumes.c
@@ -32,9 +32,10 @@
 #include "DNA_volume_types.h"
 #include "DNA_world_types.h"
 
-#include "BKE_modifier.h"
-#include "BKE_mesh.h"
 #include "BKE_fluid.h"
+#include "BKE_mesh.h"
+#include "BKE_modifier.h"
+#include "BKE_volume.h"
 
 #include "ED_screen.h"
 
@@ -434,7 +435,11 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
   if (ob->type == OB_VOLUME) {
     // TODO: check what the BASE_FROM_DUPLI test is for, do we need it too?
     Volume *volume = ob->data;
-    DRWVolumeGrid *density = DRW_volume_batch_cache_get_grid(volume, "density");
+    VolumeGrid *volume_density = BKE_volume_grid_find(volume, "density");
+    if (volume_density == NULL) {
+      return;
+    }
+    DRWVolumeGrid *density = DRW_volume_batch_cache_get_grid(volume, volume_density);
     if (density == NULL) {
       return;
     }
diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c
index ea8a0a82479..9a5fe7db5bd 100644
--- a/source/blender/draw/engines/workbench/workbench_volume.c
+++ b/source/blender/draw/engines/workbench/workbench_volume.c
@@ -232,8 +232,12 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata, Objec
 {
   /* Create 3D textures. */
   Volume *volume = ob->data;
-  DRWVolumeGrid *density = DRW_volume_batch_cache_get_grid(volume, "density");
-  if (density == NULL) {
+  VolumeGrid *volume_grid = BKE_volume_grid_active_get(volume);
+  if (volume_grid == NULL) {
+    return;
+  }
+  DRWVolumeGrid *grid = DRW_volume_batch_cache_get_grid(volume, volume_grid);
+  if (grid == NULL) {
     return;
   }
 
@@ -258,7 +262,7 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata, Objec
 
   /* Combined texture to object, and object to world transform. */
   float texture_to_world[4][4];
-  mul_m4_m4m4(texture_to_world, ob->obmat, density->texture_to_object);
+  mul_m4_m4m4(texture_to_world, ob->obmat, grid->texture_to_object);
 
   /* Compute world space dimensions for step size. */
   float world_size[3];
@@ -269,7 +273,7 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata, Objec
   double noise_ofs;
   BLI_halton_1d(3, 0.0, effect_info->jitter_index, &noise_ofs);
   float step_length, max_slice;
-  float slice_ct[3] = {density->resolution[0], density->resolution[1], density->resolution[2]};
+  float slice_ct[3] = {grid->resolution[0], grid->resolution[1], grid->resolution[2]};
   mul_v3_fl(slice_ct, max_ff(0.001f, slice_per_voxel));
   max_slice = max_fff(slice_ct[0], slice_ct[1], slice_ct[2]);
   invert_v3(slice_ct);
@@ -285,7 +289,7 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata, Objec
 
   static float white[3] = {1.0f, 1.0f, 1.0f};
   // TODO: density is rgb color + a density, it's getting squared currently?
-  DRW_shgroup_uniform_texture(grp, "densityTexture", density->texture);
+  DRW_shgroup_uniform_texture(grp, "densityTexture", grid->texture);
   // TODO: implement shadow texture, like manta_smoke_calc_transparency
   DRW_shgroup_uniform_texture(grp, "shadowTexture", e_data.dummy_shadow_tex);
   DRW_shgroup_uniform_texture(grp, "flameTexture", e_data.dummy_tex);
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 52172be8990..f358a8d5328 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -30,6 +30,7 @@ struct Object;
 struct PTCacheEdit;
 struct ParticleSystem;
 struct Volume;
+struct VolumeGrid;
 
 void DRW_shape_cache_free(void);
 void DRW_shape_cache_reset(void);
@@ -228,6 +229,6 @@ typedef struct DRWVolumeGrid {
   float halfsize[3];
 } DRWVolumeGrid;
 
-DRWVolumeGrid *DRW_volume_batch_cache_get_grid(struct Volume *volume, const char *name);
+DRWVolumeGrid *DRW_volume_batch_cache_get_grid(struct Volume *volume, struct VolumeGrid *grid);
 
 #endif /* __DRAW_CACHE_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c
index b5696eda628..5ea2eee61b9 100644
--- a/source/blender/draw/intern/draw_cache_impl_volume.c
+++ b/source/blender/draw/intern/draw_cache_impl_volume.c
@@ -129,9 +129,11 @@ void DRW_volume_batch_cache_free(Volume *volume)
 }
 
 static DRWVolumeGrid *volume_grid_cache_get(Volume *volume,
-                                            VolumeBatchCache *cache,
-                                            const char *name)
+                                            VolumeGrid *grid,
+                                            VolumeBatchCache *cache)
 {
+  const char *name = BKE_volume_grid_name(grid);
+
   /* Return cached grid. */
   DRWVolumeGrid *cache_grid;
   for (cache_grid = cache->grids.first; cache_grid; cache_grid = cache_grid->next) {
@@ -148,12 +150,6 @@ static DRWVolumeGrid *volume_grid_cache_get(Volume *volume,
   // TODO: avoid global access, load earlier?
   BKE_volume_load(volume, G.main);
 
-  /* Load grid with matching name. */
-  VolumeGrid *grid = BKE_volume_grid_find(volume, name);
-  if (grid == NULL) {
-    return cache_grid;
-  }
-
   /* Test if we support textures with the number of channels. */
   size_t channels = BKE_volume_grid_channels(grid);
   if (!ELEM(channels, 1, 3)) {
@@ -220,10 +216,10 @@ static DRWVolumeGrid *volume_grid_cache_get(Volume *volume,
   return cache_grid;
 }
 
-DRWVolumeGrid *DRW_volume_batch_cache_get_grid(Volume *volume, const char *name)
+DRWVolumeGrid *DRW_volume_batch_cache_get_grid(Volume *volume, VolumeGrid *volume_grid)
 {
   VolumeBatchCache *cache = volume_batch_cache_get(volume);
-  DRWVolumeGrid *grid = volume_grid_cache_get(volume, cache, name);
+  DRWVolumeGrid *grid = volume_grid_cache_get(volume, volume_grid, cache);
   return (grid->texture != NULL) ? grid : NULL;
 }
 
diff --git a/source/blender/makesrna/intern/rna_volume.c b/source/blender/makesrna/intern/rna_volume.c
index 7b974ac0eed..b6d3f4a1aca 100644
--- a/source/blender/makesrna/intern/rna_volume.c
+++ b/source/blender/makesrna/intern/rna_volume.c
@@ -136,7 +136,7 @@ static int rna_Volume_grids_length(PointerRNA *ptr)
 
 /* Active Grid */
 
-static void rna_VolumeGrids_active_grid_index_range(
+static void rna_VolumeGrids_active_index_range(
     PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
 {
   Volume *volume = (Volume *)ptr->data;
@@ -146,14 +146,14 @@ static void rna_VolumeGrids_active_grid_index_range(
   *max = max_ii(0, num_grids - 1);
 }
 
-static int rna_VolumeGrids_active_grid_index_get(PointerRNA *ptr)
+static int rna_VolumeGrids_active_index_get(PointerRNA *ptr)
 {
   Volume *volume = (Volume *)ptr->data;
   int num_grids = BKE_volume_num_grids(volume);
   return clamp_i(volume->active_grid, 0, max_ii(num_grids - 1, 0));
 }
 
-static void rna_VolumeGrids_active_grid_index_set(PointerRNA *ptr, int value)
+static void rna_VolumeGrids_active_index_set(PointerRNA *ptr, int value)
 {
   Volume *volume = (Volume *)ptr->data;
   volume->active_grid = value;
@@ -263,9 +263,9 @@ static void rna_def_volume_grids(BlenderRNA *brna, PropertyRNA *cprop)
 
   prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
   RNA_def_property_int_funcs(prop,
-                             "rna_VolumeGrids_active_grid_index_get",
-                             "rna_VolumeGrids_active_grid_index_set",
-                             "rna_VolumeGrids_active_grid_index_range");
+                             "rna_VolumeGrids_active_index_get",
+                             "rna_VolumeGrids_active_index_set",
+                             "rna_VolumeGrids_active_index_range");
   RNA_def_property_ui_text(prop, "Active Grid Index", "Index of active volume grid");
 
   prop = RNA_def_property(srna, "error_message", PROP_STRING, PROP_NONE);



More information about the Bf-blender-cvs mailing list