Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-10-05 11:29:34 +0300
committerJacques Lucke <jacques@blender.org>2020-10-05 11:29:34 +0300
commita4f8b2ad7653cac8a5f7821ce7ee9af44b13a758 (patch)
tree73c8a83d11ea4461546648602234b0626c11367d /source/blender/blenkernel/intern/volume.cc
parent3e101759b1b726e3cc16c69b2619cd1d82b00a8e (diff)
Volumes: more generic way to handle different openvdb types
Reviewers: brecht Differential Revision: https://developer.blender.org/D9093
Diffstat (limited to 'source/blender/blenkernel/intern/volume.cc')
-rw-r--r--source/blender/blenkernel/intern/volume.cc51
1 files changed, 16 insertions, 35 deletions
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index 79ed3d3d08d..6090c0fec20 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -1291,47 +1291,28 @@ Volume *BKE_volume_copy_for_eval(Volume *volume_src, bool reference)
return result;
}
+struct CreateGridOp {
+ template<typename GridType> typename openvdb::GridBase::Ptr operator()()
+ {
+ if constexpr (std::is_same_v<GridType, openvdb::points::PointDataGrid>) {
+ return {};
+ }
+ else {
+ return GridType::create();
+ }
+ }
+};
+
VolumeGrid *BKE_volume_grid_add(Volume *volume, const char *name, VolumeGridType type)
{
#ifdef WITH_OPENVDB
VolumeGridVector &grids = *volume->runtime.grids;
BLI_assert(BKE_volume_grid_find(volume, name) == NULL);
+ BLI_assert(type != VOLUME_GRID_UNKNOWN);
- openvdb::GridBase::Ptr vdb_grid;
- switch (type) {
- case VOLUME_GRID_FLOAT:
- vdb_grid = openvdb::FloatGrid::create();
- break;
- case VOLUME_GRID_VECTOR_FLOAT:
- vdb_grid = openvdb::Vec3fGrid::create();
- break;
- case VOLUME_GRID_BOOLEAN:
- vdb_grid = openvdb::BoolGrid::create();
- break;
- case VOLUME_GRID_DOUBLE:
- vdb_grid = openvdb::DoubleGrid::create();
- break;
- case VOLUME_GRID_INT:
- vdb_grid = openvdb::Int32Grid::create();
- break;
- case VOLUME_GRID_INT64:
- vdb_grid = openvdb::Int64Grid::create();
- break;
- case VOLUME_GRID_VECTOR_INT:
- vdb_grid = openvdb::Vec3IGrid::create();
- break;
- case VOLUME_GRID_VECTOR_DOUBLE:
- vdb_grid = openvdb::Vec3dGrid::create();
- break;
- case VOLUME_GRID_STRING:
- vdb_grid = openvdb::StringGrid::create();
- break;
- case VOLUME_GRID_MASK:
- vdb_grid = openvdb::MaskGrid::create();
- break;
- case VOLUME_GRID_POINTS:
- case VOLUME_GRID_UNKNOWN:
- return NULL;
+ openvdb::GridBase::Ptr vdb_grid = BKE_volume_grid_type_operation(type, CreateGridOp{});
+ if (!vdb_grid) {
+ return NULL;
}
vdb_grid->setName(name);