[Bf-blender-cvs] [9b598eb] openvdb: Cleanup of Blender sync code for OpenVDB volume attributes.

Lukas Tönne noreply at git.blender.org
Thu Nov 17 10:14:48 CET 2016


Commit: 9b598ebc4701b53fc990409989f4bb4580b5838f
Author: Lukas Tönne
Date:   Thu Nov 17 10:10:39 2016 +0100
Branches: openvdb
https://developer.blender.org/rB9b598ebc4701b53fc990409989f4bb4580b5838f

Cleanup of Blender sync code for OpenVDB volume attributes.

Besides removing some debug printing lines, the code should also become
easier to adapt to alternative sources of volume data beside the smoke sim.

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

M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_volume.cpp

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

diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index cf81c22..38829b3 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -77,27 +77,16 @@ bool BlenderSync::object_is_light(BL::Object& b_ob)
 bool BlenderSync::object_has_sparse_volume(BL::Object& b_ob)
 {
 	BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
-
-	if(!b_domain) {
-		return false;
-	}
-
-	BL::PointCache b_ptcache = b_domain.point_cache();
-
-	if (!b_ptcache.is_baked()) {
-	    return false;
-	}
-
-	if (b_domain.cache_file_format() != BL::SmokeDomainSettings::cache_file_format_OPENVDB) {
-	    return false;
+	if (b_domain) {
+		BL::PointCache b_ptcache = b_domain.point_cache();
+		if (b_ptcache.is_baked() && b_domain.cache_file_format() == BL::SmokeDomainSettings::cache_file_format_OPENVDB) {
+			char filename[1024];
+			SmokeDomainSettings_cache_filename_get(&b_domain.ptr, filename);
+			return strcmp(filename, "");
+		}
 	}
-
-	char filename[1024];
-	SmokeDomainSettings_cache_filename_get(&b_domain.ptr, filename);
-
-	printf("filename (blender sync): %s\n", filename);
-
-	return strcmp(filename, "");
+	
+	return false;
 }
 
 static uint object_ray_visibility(BL::Object& b_ob)
@@ -386,8 +375,6 @@ Object *BlenderSync::sync_object(BL::Object& b_parent,
 	bool use_holdout = (layer_flag & render_layer.holdout_layer) != 0;
 	
 	if(object_has_sparse_volume(b_ob)) {
-		//object->mesh = NULL;
-		printf("object has sparse volume\n");
 		sync_volume(b_ob);
 	}
 	/*else*/ {
diff --git a/intern/cycles/blender/blender_volume.cpp b/intern/cycles/blender/blender_volume.cpp
index 5c25668..e68f2ef 100644
--- a/intern/cycles/blender/blender_volume.cpp
+++ b/intern/cycles/blender/blender_volume.cpp
@@ -25,7 +25,9 @@
 
 CCL_NAMESPACE_BEGIN
 
-static Attribute *get_openvdb_attribute(Volume *volume, const string& filename, const ustring& name)
+static Attribute *create_openvdb_attribute(Volume *volume,
+                                           const string& filename,
+                                           const ustring& name)
 {
 	Attribute *attr = NULL;
 
@@ -40,16 +42,13 @@ static Attribute *get_openvdb_attribute(Volume *volume, const string& filename,
 
 	if(value_type == "float") {
 		attr = volume->attributes.add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL);
-		fprintf(stderr, "Adding volume attribute: %s\n", name.string().c_str());
 	}
 	else if(value_type == "vec3s") {
 		if (grid->getMetadata< openvdb::TypedMetadata<bool> >("is_color")) {
 			attr = volume->attributes.add(name, TypeDesc::TypeColor, ATTR_ELEMENT_VOXEL);
-			fprintf(stderr, "Adding volume attribute: %s\n", name.string().c_str());
 		}
 		else {
 			attr = volume->attributes.add(name, TypeDesc::TypeVector, ATTR_ELEMENT_VOXEL);
-			fprintf(stderr, "Adding volume attribute: %s\n", name.string().c_str());
 		}
 	}
 	else {
@@ -59,33 +58,39 @@ static Attribute *get_openvdb_attribute(Volume *volume, const string& filename,
 	return attr;
 }
 
-static void create_volume_attribute(BL::Object& b_ob,
-                                    Volume *volume,
-                                    VolumeManager *volume_manager,
-                                    const ustring& name,
-                                    float /*frame*/)
+static Attribute *create_smoke_attribute(BL::Object& b_ob,
+                                         Volume *volume,
+                                         VolumeManager *volume_manager,
+                                         const ustring& name,
+                                         float /*frame*/)
 {
+	Attribute *attr = NULL;
+	
 	BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
-
-	if(!b_domain) {
-		fprintf(stderr, "No domain found!\n");
-		return;
-	}
-
-	char filename[1024];
-	SmokeDomainSettings_cache_filename_get(&b_domain.ptr, filename);
-
-	Attribute *attr = get_openvdb_attribute(volume, filename, name);
-	VoxelAttribute *volume_data = attr->data_voxel();
-	int slot = volume_manager->add_volume(volume, filename, name.string());
-
-	if (!volume_data) {
-		fprintf(stderr, "Failed to create volume data!\n");
+	if(b_domain) {
+		char filename[1024];
+		SmokeDomainSettings_cache_filename_get(&b_domain.ptr, filename);
+		
+		attr = create_openvdb_attribute(volume, filename, name);
+		if (attr) {
+			VoxelAttribute *volume_data = attr->data_voxel();
+			assert(volume_data && "Failed to create volume data!\n");
+			
+			// TODO(kevin): add volume fields to the Volume*
+			//volume_data->manager = volume_manager;
+			volume_data->slot = volume_manager->add_volume(volume, filename, name.string());
+		}
 	}
+	
+	return attr;
+}
 
-	// TODO(kevin): add volume fields to the Volume*
-//	volume_data->manager = volume_manager;
-	volume_data->slot = slot;
+static bool is_volume_attribute(AttributeStandard std) {
+	return std == ATTR_STD_VOLUME_DENSITY
+	        || std == ATTR_STD_VOLUME_COLOR
+	        || std == ATTR_STD_VOLUME_FLAME
+	        || std == ATTR_STD_VOLUME_HEAT
+	        || std == ATTR_STD_VOLUME_VELOCITY;
 }
 
 static void create_volume_attributes(Scene *scene,
@@ -94,34 +99,18 @@ static void create_volume_attributes(Scene *scene,
                                      float frame)
 {
 	foreach(Shader *shader, volume->used_shaders) {
-		fprintf(stderr, "Number of attribute requests: %lu\n", shader->attributes.requests.size());
-
 		foreach(AttributeRequest req, shader->attributes.requests) {
 			ustring name;
-
-			if (req.std == ATTR_STD_VOLUME_DENSITY) {
-				name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_DENSITY));
-			}
-			else if (req.std == ATTR_STD_VOLUME_FLAME) {
-				name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_FLAME));
-			}
-			else if (req.std == ATTR_STD_VOLUME_COLOR) {
-				name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_COLOR));
+			if (is_volume_attribute(req.std)) {
+				name = ustring(Attribute::standard_name(req.std));
 			}
-			else if (req.std == ATTR_STD_VOLUME_VELOCITY) {
-				name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY));
-			}
-			else if (req.std == ATTR_STD_VOLUME_HEAT) {
-				name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_HEAT));
-			}
-			else if (req.name != "") {
+			else {
 				name = req.name;
 			}
-			else {
-				continue;
+			
+			if (!name.empty()) {
+				/*Attribute *attr =*/ create_smoke_attribute(b_ob, volume, scene->volume_manager, name, frame);
 			}
-
-			create_volume_attribute(b_ob, volume, scene->volume_manager, name, frame);
 		}
 	}
 }
@@ -135,8 +124,6 @@ Volume *BlenderSync::sync_volume(BL::Object &b_ob)
 	vector<Shader*> used_shaders;
 	BL::ID b_ob_data = b_ob.data();
 
-	fprintf(stderr, "%s: before material assignment\n", __func__);
-
 	BL::Object::material_slots_iterator slot;
 	for(b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
 		if(material_override) {
@@ -155,8 +142,6 @@ Volume *BlenderSync::sync_volume(BL::Object &b_ob)
 			used_shaders.push_back(scene->default_volume);
 	}
 
-	fprintf(stderr, "%s: after material assignment\n", __func__);
-
 	Volume *volume;
 
 	if(!volume_map.sync(&volume, key)) {
@@ -186,8 +171,6 @@ Volume *BlenderSync::sync_volume(BL::Object &b_ob)
 	volume->used_shaders = used_shaders;
 	volume->name = ustring(b_ob_data.name().c_str());
 
-	fprintf(stderr, "Number of shaders: %lu\n", volume->used_shaders.size());
-
 	create_volume_attributes(scene, b_ob, volume, b_scene.frame_current());
 
 	/* tag update */




More information about the Bf-blender-cvs mailing list