[Bf-blender-cvs] [7bd3b34] openvdb: Exporter: option to write grids as 16-bit half floats.

Kévin Dietrich noreply at git.blender.org
Tue Jun 23 11:30:54 CEST 2015


Commit: 7bd3b34e0240449b7a19b237bcf0e60cfc582aa7
Author: Kévin Dietrich
Date:   Mon Jun 22 18:09:41 2015 +0200
Branches: openvdb
https://developer.blender.org/rB7bd3b34e0240449b7a19b237bcf0e60cfc582aa7

Exporter: option to write grids as 16-bit half floats.

This is just for storing on disk, the grids are converted back to full
float format upon reading. Also this affects all grids to be written for
now.

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

M	intern/openvdb/intern/openvdb_writer.cpp
M	intern/openvdb/intern/openvdb_writer.h
M	intern/openvdb/openvdb_capi.cpp
M	intern/openvdb/openvdb_capi.h
M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/makesdna/DNA_smoke_types.h
M	source/blender/makesrna/intern/rna_smoke.c

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

diff --git a/intern/openvdb/intern/openvdb_writer.cpp b/intern/openvdb/intern/openvdb_writer.cpp
index 9c2ad40..b24e393 100644
--- a/intern/openvdb/intern/openvdb_writer.cpp
+++ b/intern/openvdb/intern/openvdb_writer.cpp
@@ -30,6 +30,7 @@ OpenVDBWriter::OpenVDBWriter()
     , m_meta_map(new openvdb::MetaMap())
 {
 	m_meta_map->insertMeta("creator", openvdb::StringMetadata("Blender/OpenVDBWriter"));
+	m_save_as_half = false;
 }
 
 OpenVDBWriter::~OpenVDBWriter()
@@ -37,6 +38,7 @@ OpenVDBWriter::~OpenVDBWriter()
 
 void OpenVDBWriter::insert(const openvdb::GridBase::Ptr &grid)
 {
+	grid->setSaveFloatAsHalf(m_save_as_half);
 	m_grids->push_back(grid);
 }
 
@@ -76,15 +78,16 @@ void OpenVDBWriter::insertMat4sMeta(const std::string &name, const float value[4
 	m_meta_map->insertMeta(name, openvdb::Mat4SMetadata(mat));
 }
 
-void OpenVDBWriter::setFileCompression(const int flags)
+void OpenVDBWriter::setFlags(const int compression, const bool save_as_half)
 {
-	m_flags = flags;
+	m_compression_flags = compression;
+	m_save_as_half = save_as_half;
 }
 
 void OpenVDBWriter::write(const std::string &filename) const
 {
 	openvdb::io::File file(filename);
-	file.setCompression(m_flags);
+	file.setCompression(m_compression_flags);
 	file.write(*m_grids, *m_meta_map);
 	file.close();
 
diff --git a/intern/openvdb/intern/openvdb_writer.h b/intern/openvdb/intern/openvdb_writer.h
index 6f36d62..e9760ce 100644
--- a/intern/openvdb/intern/openvdb_writer.h
+++ b/intern/openvdb/intern/openvdb_writer.h
@@ -32,7 +32,8 @@ class OpenVDBWriter {
 	openvdb::GridPtrVecPtr m_grids;
 	openvdb::MetaMap::Ptr m_meta_map;
 
-	int m_flags;
+	int m_compression_flags;
+	bool m_save_as_half;
 
 public:
 	OpenVDBWriter();
@@ -47,7 +48,7 @@ public:
 	void insertVec3IMeta(const std::string &name, const openvdb::Vec3I value);
 	void insertMat4sMeta(const std::string &name, const float value[4][4]);
 
-	void setFileCompression(const int flags);
+	void setFlags(const int compression, const bool save_as_half);
 
 	void write(const std::string &filename) const;
 };
diff --git a/intern/openvdb/openvdb_capi.cpp b/intern/openvdb/openvdb_capi.cpp
index 4b506fb..83ac2ef 100644
--- a/intern/openvdb/openvdb_capi.cpp
+++ b/intern/openvdb/openvdb_capi.cpp
@@ -150,7 +150,7 @@ void OpenVDBWriter_free(OpenVDBWriter *writer)
 	writer = NULL;
 }
 
-void OpenVDBWriter_set_compression(OpenVDBWriter *writer, const int flag)
+void OpenVDBWriter_set_flags(OpenVDBWriter *writer, const int flag, const bool half)
 {
 	int compression_flags = io::COMPRESS_ACTIVE_MASK;
 
@@ -164,7 +164,7 @@ void OpenVDBWriter_set_compression(OpenVDBWriter *writer, const int flag)
 		compression_flags = io::COMPRESS_NONE;
 	}
 
-	writer->setFileCompression(compression_flags);
+	writer->setFlags(compression_flags, half);
 }
 
 void OpenVDBWriter_add_meta_fl(OpenVDBWriter *writer, const char *name, const float value)
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index 45e0572..0b97bfd 100644
--- a/intern/openvdb/openvdb_capi.h
+++ b/intern/openvdb/openvdb_capi.h
@@ -101,7 +101,7 @@ void OpenVDB_import_grid_vec(struct OpenVDBReader *reader,
 
 struct OpenVDBWriter *OpenVDBWriter_create(void);
 void OpenVDBWriter_free(struct OpenVDBWriter *writer);
-void OpenVDBWriter_set_compression(struct OpenVDBWriter *writer, const int flag);
+void OpenVDBWriter_set_flags(struct OpenVDBWriter *writer, const int flag, const bool half);
 void OpenVDBWriter_add_meta_fl(struct OpenVDBWriter *writer, const char *name, const float value);
 void OpenVDBWriter_add_meta_int(struct OpenVDBWriter *writer, const char *name, const int value);
 void OpenVDBWriter_add_meta_v3(struct OpenVDBWriter *writer, const char *name, const float value[3]);
diff --git a/release/scripts/startup/bl_ui/properties_physics_smoke.py b/release/scripts/startup/bl_ui/properties_physics_smoke.py
index 1d8c146..2c3d434 100644
--- a/release/scripts/startup/bl_ui/properties_physics_smoke.py
+++ b/release/scripts/startup/bl_ui/properties_physics_smoke.py
@@ -368,6 +368,8 @@ class PHYSICS_PT_smoke_openvdb(PhysicButtonsPanel, Panel):
             row = layout.row(align=True)
             row.prop(cache, "frame_start")
             row.prop(cache, "frame_end")
+            row = layout.row()
+            row.prop(cache, "save_as_half")
 
         layout.operator("object.smoke_vdb_export")
         layout.operator("object.smoke_vdb_transform_update")
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index ce2f59e..9a55013 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -3345,6 +3345,7 @@ void smokeModifier_OpenVDB_export(SmokeModifierData *smd, Scene *scene, Object *
 	float progress;
 	const char *relbase = modifier_path_relbase(ob);
 	char filename[FILE_MAX];
+	bool save_as_half;
 
 	orig_frame = scene->r.cfra;
 
@@ -3354,7 +3355,9 @@ void smokeModifier_OpenVDB_export(SmokeModifierData *smd, Scene *scene, Object *
 		cache->writer = OpenVDBWriter_create();
 	}
 
-	OpenVDBWriter_set_compression(cache->writer, cache->compression);
+	save_as_half = ((cache->flags & VDB_CACHE_SAVE_AS_HALF) != 0);
+
+	OpenVDBWriter_set_flags(cache->writer, cache->compression, save_as_half);
 
 	for (fr = cache->startframe; fr <= cache->endframe; fr++) {
 		/* smd->time is overwritten with scene->r.cfra in smokeModifier_process,
diff --git a/source/blender/makesdna/DNA_smoke_types.h b/source/blender/makesdna/DNA_smoke_types.h
index c7a5a24..aeb222e 100644
--- a/source/blender/makesdna/DNA_smoke_types.h
+++ b/source/blender/makesdna/DNA_smoke_types.h
@@ -179,6 +179,7 @@ typedef struct OpenVDBDrawData {
 enum {
 	VDB_CACHE_CURRENT        = (1 << 0),
 	VDB_CACHE_SMOKE_EXPORTED = (1 << 1),
+	VDB_CACHE_SAVE_AS_HALF   = (1 << 2),
 };
 
 enum {
diff --git a/source/blender/makesrna/intern/rna_smoke.c b/source/blender/makesrna/intern/rna_smoke.c
index bfbfbda..67414e0 100644
--- a/source/blender/makesrna/intern/rna_smoke.c
+++ b/source/blender/makesrna/intern/rna_smoke.c
@@ -359,7 +359,14 @@ static void rna_def_openvdb_cache(BlenderRNA *brna)
 	RNA_def_property_enum_items(prop, prop_compression_items);
 	RNA_def_property_ui_text(prop, "File Compression",
 	                         "Select what type of compression to use when writing the files");
-	RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Smoke_reset");
+	RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL);
+
+	prop = RNA_def_property(srna, "save_as_half", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flags", VDB_CACHE_SAVE_AS_HALF);
+	RNA_def_property_ui_text(prop, "Save as Half",
+	                         "Write all scalar (including vector) grids to the file as 16-bit half floats to reduce file size");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL);
 }
 
 static void rna_def_openvdb_draw_data(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list