[Bf-blender-cvs] [dab11ef764d] new-object-types: Volumes: tweaks for better initial setup of volume object
Brecht Van Lommel
noreply at git.blender.org
Tue Feb 25 18:52:21 CET 2020
Commit: dab11ef764def80d4ef8c203ee04ab63a9240e07
Author: Brecht Van Lommel
Date: Tue Feb 25 16:30:37 2020 +0100
Branches: new-object-types
https://developer.blender.org/rBdab11ef764def80d4ef8c203ee04ab63a9240e07
Volumes: tweaks for better initial setup of volume object
* Auto rotate Houdini VDB files from Y-up to Z-up
* Set default workbench display density to 1.0
* Disable bounding box display by default
* Expose wireframe display option in object properties
* Display warning if VDB grid contains only points (unsupported)
===================================================================
M release/scripts/startup/bl_ui/properties_object.py
M source/blender/blenkernel/BKE_volume.h
M source/blender/blenkernel/intern/volume.cc
M source/blender/blenkernel/intern/volume_render.cc
M source/blender/editors/object/object_volume.c
M source/blender/makesrna/intern/rna_volume.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index bb020084b03..0193f8a8c40 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -216,7 +216,7 @@ class OBJECT_PT_display(ObjectButtonsPanel, Panel):
obj = context.object
obj_type = obj.type
- is_geometry = (obj_type in {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT'})
+ is_geometry = (obj_type in {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT', 'VOLUME', 'HAIR', 'POINTCLOUD'})
is_wire = (obj_type in {'CAMERA', 'EMPTY'})
is_empty_image = (obj_type == 'EMPTY' and obj.empty_display_type == 'IMAGE')
is_dupli = (obj.instance_type != 'NONE')
diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h
index 4d4b152a579..84802bd1390 100644
--- a/source/blender/blenkernel/BKE_volume.h
+++ b/source/blender/blenkernel/BKE_volume.h
@@ -58,6 +58,9 @@ void BKE_volume_free(struct Volume *volume);
struct BoundBox *BKE_volume_boundbox_get(struct Object *ob);
+bool BKE_volume_is_y_up(const struct Volume *volume);
+bool BKE_volume_is_points_only(const struct Volume *volume);
+
/* Depsgraph */
void BKE_volume_eval_geometry(struct Depsgraph *depsgraph, struct Volume *volume);
@@ -93,11 +96,11 @@ bool BKE_volume_load(struct Volume *volume, struct Main *bmain);
void BKE_volume_unload(struct Volume *volume);
bool BKE_volume_is_loaded(const struct Volume *volume);
-int BKE_volume_num_grids(struct Volume *volume);
+int BKE_volume_num_grids(const 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);
+VolumeGrid *BKE_volume_grid_get(const struct Volume *volume, int grid_index);
+VolumeGrid *BKE_volume_grid_active_get(const struct Volume *volume);
+VolumeGrid *BKE_volume_grid_find(const struct Volume *volume, const char *name);
/* Grid
*
@@ -116,6 +119,7 @@ typedef enum VolumeGridType {
VOLUME_GRID_VECTOR_FLOAT,
VOLUME_GRID_VECTOR_DOUBLE,
VOLUME_GRID_VECTOR_INT,
+ VOLUME_GRID_POINTS,
} VolumeGridType;
bool BKE_volume_grid_load(const struct Volume *volume, struct VolumeGrid *grid);
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index f8ebee61a48..c95da151bf3 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -63,6 +63,7 @@ static CLG_LogRef LOG = {"bke.volume"};
# include <unordered_set>
# include <openvdb/openvdb.h>
+# include <openvdb/points/PointDataGrid.h>
/* Global Volume File Cache
*
@@ -403,10 +404,20 @@ struct VolumeGridVector : public std::list<VolumeGrid> {
return filepath[0] != '\0';
}
+ void clear_all()
+ {
+ std::list<VolumeGrid>::clear();
+ filepath[0] = '\0';
+ error_msg.clear();
+ metadata.reset();
+ }
+
/* Absolute file path that grids have been loaded from. */
char filepath[FILE_MAX];
/* File loading error message. */
std::string error_msg;
+ /* File Metadata. */
+ openvdb::MetaMap::Ptr metadata;
/* Mutex for file loading of grids list. */
std::mutex mutex;
};
@@ -433,8 +444,7 @@ void BKE_volume_init(Volume *volume)
volume->frame_start = 1;
volume->frame_offset = 0;
volume->frame_duration = 0;
- /* TODO: why is this needed for common volume files? */
- volume->display.density = 10.0f;
+ volume->display.density = 1.0f;
volume->display.wireframe_type = VOLUME_WIREFRAME_COARSE;
BKE_volume_init_grids(volume);
}
@@ -650,6 +660,7 @@ bool BKE_volume_load(Volume *volume, Main *bmain)
file.setCopyMaxBytes(0);
file.open();
vdb_grids = *(file.readAllGridMetadata());
+ grids.metadata = file.getMetadata();
}
catch (const openvdb::IoError &e) {
grids.error_msg = e.what();
@@ -678,9 +689,7 @@ void BKE_volume_unload(Volume *volume)
if (grids.filepath[0] != '\0') {
const char *volume_name = volume->id.name + 2;
CLOG_INFO(&LOG, 1, "Volume %s: unload", volume_name);
- grids.clear();
- grids.error_msg.clear();
- grids.filepath[0] = '\0';
+ grids.clear_all();
}
#else
UNUSED_VARS(volume);
@@ -736,6 +745,43 @@ BoundBox *BKE_volume_boundbox_get(Object *ob)
return ob->runtime.bb;
}
+bool BKE_volume_is_y_up(const Volume *volume)
+{
+ /* Simple heuristic for common files to open the right way up. */
+#ifdef WITH_OPENVDB
+ VolumeGridVector &grids = *volume->runtime.grids;
+ if (grids.metadata) {
+ openvdb::StringMetadata::ConstPtr creator =
+ grids.metadata->getMetadata<openvdb::StringMetadata>("creator");
+ if (!creator) {
+ creator = grids.metadata->getMetadata<openvdb::StringMetadata>("Creator");
+ }
+ return (creator && creator->str().rfind("Houdini", 0) == 0);
+ }
+#else
+ UNUSED_VARS(volume);
+#endif
+
+ return false;
+}
+
+bool BKE_volume_is_points_only(const Volume *volume)
+{
+ int num_grids = BKE_volume_num_grids(volume);
+ if (num_grids == 0) {
+ return false;
+ }
+
+ for (int i = 0; i < num_grids; i++) {
+ VolumeGrid *grid = BKE_volume_grid_get(volume, i);
+ if (BKE_volume_grid_type(grid) != VOLUME_GRID_POINTS) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
/* Dependency Graph */
static Volume *volume_evaluate_modifiers(struct Depsgraph *depsgraph,
@@ -864,7 +910,7 @@ void BKE_volume_batch_cache_free(Volume *volume)
/* Grids */
-int BKE_volume_num_grids(Volume *volume)
+int BKE_volume_num_grids(const Volume *volume)
{
#ifdef WITH_OPENVDB
return volume->runtime.grids->size();
@@ -884,7 +930,7 @@ const char *BKE_volume_grids_error_msg(const Volume *volume)
#endif
}
-VolumeGrid *BKE_volume_grid_get(Volume *volume, int grid_index)
+VolumeGrid *BKE_volume_grid_get(const Volume *volume, int grid_index)
{
#ifdef WITH_OPENVDB
VolumeGridVector &grids = *volume->runtime.grids;
@@ -900,7 +946,7 @@ VolumeGrid *BKE_volume_grid_get(Volume *volume, int grid_index)
#endif
}
-VolumeGrid *BKE_volume_grid_active_get(Volume *volume)
+VolumeGrid *BKE_volume_grid_active_get(const Volume *volume)
{
const int num_grids = BKE_volume_num_grids(volume);
if (num_grids == 0) {
@@ -911,7 +957,7 @@ VolumeGrid *BKE_volume_grid_active_get(Volume *volume)
return BKE_volume_grid_get(volume, index);
}
-VolumeGrid *BKE_volume_grid_find(Volume *volume, const char *name)
+VolumeGrid *BKE_volume_grid_find(const Volume *volume, const char *name)
{
int num_grids = BKE_volume_num_grids(volume);
for (int i = 0; i < num_grids; i++) {
@@ -1011,6 +1057,9 @@ VolumeGridType BKE_volume_grid_type(const VolumeGrid *volume_grid)
else if (grid->isType<openvdb::MaskGrid>()) {
return VOLUME_GRID_MASK;
}
+ else if (grid->isType<openvdb::points::PointDataGrid>()) {
+ return VOLUME_GRID_POINTS;
+ }
#else
UNUSED_VARS(volume_grid);
#endif
@@ -1041,6 +1090,7 @@ int BKE_volume_grid_channels(const VolumeGrid *grid)
return 3;
case VOLUME_GRID_VECTOR_INT:
return 3;
+ case VOLUME_GRID_POINTS:
case VOLUME_GRID_UNKNOWN:
return 0;
}
@@ -1172,6 +1222,7 @@ VolumeGrid *BKE_volume_grid_add(Volume *volume, const char *name, VolumeGridType
case VOLUME_GRID_MASK:
vdb_grid = openvdb::MaskGrid::create();
break;
+ case VOLUME_GRID_POINTS:
case VOLUME_GRID_UNKNOWN:
return NULL;
}
diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc
index 0902777eca6..42462a37d91 100644
--- a/source/blender/blenkernel/intern/volume_render.cc
+++ b/source/blender/blenkernel/intern/volume_render.cc
@@ -156,6 +156,7 @@ void BKE_volume_grid_dense_voxels(const Volume *volume,
break;
}
case VOLUME_GRID_STRING:
+ case VOLUME_GRID_POINTS:
case VOLUME_GRID_UNKNOWN: {
/* Zero channels to copy. */
break;
@@ -326,6 +327,7 @@ void BKE_volume_grid_wireframe(const Volume *volume,
wireframe.add_grid<openvdb::StringGrid>(grid, coarse);
break;
}
+ case VOLUME_GRID_POINTS:
case VOLUME_GRID_UNKNOWN: {
break;
}
diff --git a/source/blender/editors/object/object_volume.c b/source/blender/editors/object/object_volume.c
index 249b5204baf..5a0458921f1 100644
--- a/source/blender/editors/object/object_volume.c
+++ b/source/blender/editors/object/object_volume.c
@@ -27,6 +27,7 @@
#include "BLI_fileops.h"
#include "BLI_listbase.h"
+#include "BLI_math_base.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
@@ -38,6 +39,8 @@
#include "BKE_context.h"
#include "BKE_main.h"
+#include "BKE_report.h"
+#include "BKE_volume.h"
#include "WM_types.h"
#include "WM_api.h"
@@ -59,7 +62,6 @@ static Object *object_volume_add(bContext *C, wmOperator *op, const char *name)
return false;
}
Object *object = ED_object_add_type(C, OB_VOLUME, name, loc, rot, false, local_view_bits);
- object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */
return object;
}
@@ -112,6 +114,18 @@ static int volume_import_exec(bContext *C, wmOperator *op)
volume->frame_start = 1;
volume->frame_offset = (volume->is_sequence) ? range->offset - 1 : 0;
+ BKE_volume_load(volume, bmain);
+ if (BKE_volume_is_y_up(volume)) {
+ object->rot[0] += M_PI_2;
+ }
+ if (BKE_volume_is_points_only(volume)) {
+ BKE_reportf(op->reports,
+ RPT_WARNING,
+ "Volume %s contains points, only voxel grids are supported",
+ filename);
+ }
+ BKE_volume_unload(volume);
+
imported = true;
}
BLI_freelistN(&ranges);
diff --git a/source/blender/makesrna/intern/rna_volume.c b/source/blender/makesrna/intern/rna_volume.c
index 121133189e5..980f098fecc 100644
--- a/source/blender/makesrna/intern/rna_volume.c
+++ b/source/blender/makesrna/intern/rna_volume.c
@@ -228,6 +228,11 @@ static void rna_def_volume_grid(BlenderRNA *brna)
{VOLUME_GRID_VECTOR_FLOAT, "VECTOR_FLOAT
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list