Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/volume.cc
| Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | openvdb::GridBase::Ptr simplified_grid(const int simplify_level) | ||||
| BLI_assert(simplify_level >= 0); | BLI_assert(simplify_level >= 0); | ||||
| if (simplify_level == 0 || !is_loaded) { | if (simplify_level == 0 || !is_loaded) { | ||||
| return grid; | return grid; | ||||
| } | } | ||||
| std::lock_guard<std::mutex> lock(mutex); | std::lock_guard<std::mutex> lock(mutex); | ||||
| return simplified_grids.lookup_or_add_cb(simplify_level, [&]() { | return simplified_grids.lookup_or_add_cb(simplify_level, [&]() { | ||||
| const float resolution_factor = 1.0f / (1 << simplify_level); | const float resolution_factor = 1.0f / (1 << simplify_level); | ||||
| const VolumeGridType grid_type = BKE_volume_grid_type_openvdb(grid); | const VolumeGridType grid_type = BKE_volume_grid_type_openvdb(*grid); | ||||
| return BKE_volume_grid_create_with_changed_resolution(grid_type, *grid, resolution_factor); | return BKE_volume_grid_create_with_changed_resolution(grid_type, *grid, resolution_factor); | ||||
| }); | }); | ||||
| } | } | ||||
| /* Unique key: filename + grid name. */ | /* Unique key: filename + grid name. */ | ||||
| std::string filepath; | std::string filepath; | ||||
| std::string grid_name; | std::string grid_name; | ||||
| ▲ Show 20 Lines • Show All 378 Lines • ▼ Show 20 Lines | static void volume_copy_data(Main *UNUSED(bmain), | ||||
| volume_dst->mat = (Material **)MEM_dupallocN(volume_src->mat); | volume_dst->mat = (Material **)MEM_dupallocN(volume_src->mat); | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| if (volume_src->runtime.grids) { | if (volume_src->runtime.grids) { | ||||
| const VolumeGridVector &grids_src = *(volume_src->runtime.grids); | const VolumeGridVector &grids_src = *(volume_src->runtime.grids); | ||||
| volume_dst->runtime.grids = OBJECT_GUARDED_NEW(VolumeGridVector, grids_src); | volume_dst->runtime.grids = OBJECT_GUARDED_NEW(VolumeGridVector, grids_src); | ||||
| } | } | ||||
| #endif | #endif | ||||
| volume_dst->batch_cache = nullptr; | |||||
| } | } | ||||
| static void volume_free_data(ID *id) | static void volume_free_data(ID *id) | ||||
| { | { | ||||
| Volume *volume = (Volume *)id; | Volume *volume = (Volume *)id; | ||||
| BKE_animdata_free(&volume->id, false); | BKE_animdata_free(&volume->id, false); | ||||
| BKE_volume_batch_cache_free(volume); | BKE_volume_batch_cache_free(volume); | ||||
| MEM_SAFE_FREE(volume->mat); | MEM_SAFE_FREE(volume->mat); | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | IDTypeInfo IDType_ID_VO = { | ||||
| /* foreach_cache */ volume_foreach_cache, | /* foreach_cache */ volume_foreach_cache, | ||||
| /* blend_write */ volume_blend_write, | /* blend_write */ volume_blend_write, | ||||
| /* blend_read_data */ volume_blend_read_data, | /* blend_read_data */ volume_blend_read_data, | ||||
| /* blend_read_lib */ volume_blend_read_lib, | /* blend_read_lib */ volume_blend_read_lib, | ||||
| /* blend_read_expand */ volume_blend_read_expand, | /* blend_read_expand */ volume_blend_read_expand, | ||||
| /* blend_read_undo_preserve */ nullptr, | /* blend_read_undo_preserve */ nullptr, | ||||
| /* lib_override_apply_post */ nullptr, | |||||
| }; | }; | ||||
| void BKE_volume_init_grids(Volume *volume) | void BKE_volume_init_grids(Volume *volume) | ||||
| { | { | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| if (volume->runtime.grids == nullptr) { | if (volume->runtime.grids == nullptr) { | ||||
| volume->runtime.grids = OBJECT_GUARDED_NEW(VolumeGridVector); | volume->runtime.grids = OBJECT_GUARDED_NEW(VolumeGridVector); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 575 Lines • ▼ Show 20 Lines | #ifdef WITH_OPENVDB | ||||
| return volume_grid->name(); | return volume_grid->name(); | ||||
| #else | #else | ||||
| UNUSED_VARS(volume_grid); | UNUSED_VARS(volume_grid); | ||||
| return "density"; | return "density"; | ||||
| #endif | #endif | ||||
| } | } | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| VolumeGridType BKE_volume_grid_type_openvdb(const openvdb::GridBase::Ptr &grid) | VolumeGridType BKE_volume_grid_type_openvdb(const openvdb::GridBase &grid) | ||||
| { | { | ||||
| if (grid->isType<openvdb::FloatGrid>()) { | if (grid.isType<openvdb::FloatGrid>()) { | ||||
| return VOLUME_GRID_FLOAT; | return VOLUME_GRID_FLOAT; | ||||
| } | } | ||||
| if (grid->isType<openvdb::Vec3fGrid>()) { | if (grid.isType<openvdb::Vec3fGrid>()) { | ||||
| return VOLUME_GRID_VECTOR_FLOAT; | return VOLUME_GRID_VECTOR_FLOAT; | ||||
| } | } | ||||
| if (grid->isType<openvdb::BoolGrid>()) { | if (grid.isType<openvdb::BoolGrid>()) { | ||||
| return VOLUME_GRID_BOOLEAN; | return VOLUME_GRID_BOOLEAN; | ||||
| } | } | ||||
| if (grid->isType<openvdb::DoubleGrid>()) { | if (grid.isType<openvdb::DoubleGrid>()) { | ||||
| return VOLUME_GRID_DOUBLE; | return VOLUME_GRID_DOUBLE; | ||||
| } | } | ||||
| if (grid->isType<openvdb::Int32Grid>()) { | if (grid.isType<openvdb::Int32Grid>()) { | ||||
| return VOLUME_GRID_INT; | return VOLUME_GRID_INT; | ||||
| } | } | ||||
| if (grid->isType<openvdb::Int64Grid>()) { | if (grid.isType<openvdb::Int64Grid>()) { | ||||
| return VOLUME_GRID_INT64; | return VOLUME_GRID_INT64; | ||||
| } | } | ||||
| if (grid->isType<openvdb::Vec3IGrid>()) { | if (grid.isType<openvdb::Vec3IGrid>()) { | ||||
| return VOLUME_GRID_VECTOR_INT; | return VOLUME_GRID_VECTOR_INT; | ||||
| } | } | ||||
| if (grid->isType<openvdb::Vec3dGrid>()) { | if (grid.isType<openvdb::Vec3dGrid>()) { | ||||
| return VOLUME_GRID_VECTOR_DOUBLE; | return VOLUME_GRID_VECTOR_DOUBLE; | ||||
| } | } | ||||
| if (grid->isType<openvdb::StringGrid>()) { | if (grid.isType<openvdb::StringGrid>()) { | ||||
| return VOLUME_GRID_STRING; | return VOLUME_GRID_STRING; | ||||
| } | } | ||||
| if (grid->isType<openvdb::MaskGrid>()) { | if (grid.isType<openvdb::MaskGrid>()) { | ||||
| return VOLUME_GRID_MASK; | return VOLUME_GRID_MASK; | ||||
| } | } | ||||
| if (grid->isType<openvdb::points::PointDataGrid>()) { | if (grid.isType<openvdb::points::PointDataGrid>()) { | ||||
| return VOLUME_GRID_POINTS; | return VOLUME_GRID_POINTS; | ||||
| } | } | ||||
| return VOLUME_GRID_UNKNOWN; | return VOLUME_GRID_UNKNOWN; | ||||
| } | } | ||||
| #endif | #endif | ||||
| VolumeGridType BKE_volume_grid_type(const VolumeGrid *volume_grid) | VolumeGridType BKE_volume_grid_type(const VolumeGrid *volume_grid) | ||||
| { | { | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| const openvdb::GridBase::Ptr grid = volume_grid->grid(); | const openvdb::GridBase::Ptr grid = volume_grid->grid(); | ||||
| return BKE_volume_grid_type_openvdb(grid); | return BKE_volume_grid_type_openvdb(*grid); | ||||
| #else | #else | ||||
| UNUSED_VARS(volume_grid); | UNUSED_VARS(volume_grid); | ||||
| #endif | #endif | ||||
| return VOLUME_GRID_UNKNOWN; | return VOLUME_GRID_UNKNOWN; | ||||
| } | } | ||||
| int BKE_volume_grid_channels(const VolumeGrid *grid) | int BKE_volume_grid_channels(const VolumeGrid *grid) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 260 Lines • Show Last 20 Lines | |||||