diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-10-07 17:39:51 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-10-07 18:11:09 +0300 |
commit | fc767502dc7dce4ff92d239abbcc49a68fe45e02 (patch) | |
tree | d319dbc2a828d0fdf9f1ae6ba4bdf2cf32ca0f8d /source/blender/blenkernel/intern/volume.cc | |
parent | 0ea4aab55e9352779e786157d4004ba445fedfb4 (diff) |
Python API: add volume.grids.save(filepath) to save grids and metadata to disk
Particularly useful now that we can dynamically generate volume using
modifiers. Not exposed in the user interface currently, but it can be used
by add-ons that need to export an entire scene including volumes.
Diffstat (limited to 'source/blender/blenkernel/intern/volume.cc')
-rw-r--r-- | source/blender/blenkernel/intern/volume.cc | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index 7e895e0ba7a..87c45753393 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -44,6 +44,7 @@ #include "BKE_modifier.h" #include "BKE_object.h" #include "BKE_packedFile.h" +#include "BKE_report.h" #include "BKE_scene.h" #include "BKE_volume.h" @@ -401,7 +402,7 @@ struct VolumeGrid { * the actual grids are always saved in a VDB file. */ struct VolumeGridVector : public std::list<VolumeGrid> { - VolumeGridVector() + VolumeGridVector() : metadata(new openvdb::MetaMap()) { filepath[0] = '\0'; } @@ -803,6 +804,40 @@ void BKE_volume_unload(Volume *volume) #endif } +/* File Save */ + +bool BKE_volume_save(Volume *volume, Main *bmain, ReportList *reports, const char *filepath) +{ +#ifdef WITH_OPENVDB + if (!BKE_volume_load(volume, bmain)) { + BKE_reportf(reports, RPT_ERROR, "Could not load volume for writing"); + return false; + } + + VolumeGridVector &grids = *volume->runtime.grids; + openvdb::GridCPtrVec vdb_grids; + + for (VolumeGrid &grid : grids) { + vdb_grids.push_back(BKE_volume_grid_openvdb_for_read(volume, &grid)); + } + + try { + openvdb::io::File file(filepath); + file.write(vdb_grids, *grids.metadata); + file.close(); + } + catch (const openvdb::IoError &e) { + BKE_reportf(reports, RPT_ERROR, "Could not write volume: %s", e.what()); + return false; + } + + return true; +#else + UNUSED_VARS(volume, bmain, reports, filepath); + return false; +#endif +} + BoundBox *BKE_volume_boundbox_get(Object *ob) { BLI_assert(ob->type == OB_VOLUME); |