[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49188] branches/smoke2: Smoke + Cycles:

Daniel Genrich daniel.genrich at gmx.net
Wed Jul 25 01:49:51 CEST 2012


Revision: 49188
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49188
Author:   genscher
Date:     2012-07-24 23:49:50 +0000 (Tue, 24 Jul 2012)
Log Message:
-----------
Smoke + Cycles:

- Reorganize code a bit
- Use RNA function to directly copy density over

TODO:
- Fix scons to include blender_smoke.cpp
- "use_volume": Need flags to differ between "no density found" (can happen at frame 1) and "not a volume" (objects which have nothing to do with volume).
- Actually render something
- handle rendering (ignoring) of Smoke Domain + Flow

Modified Paths:
--------------
    branches/smoke2/intern/cycles/blender/CMakeLists.txt
    branches/smoke2/intern/cycles/blender/blender_object.cpp
    branches/smoke2/intern/cycles/blender/blender_sync.h
    branches/smoke2/intern/cycles/blender/blender_util.h
    branches/smoke2/intern/cycles/render/object.h
    branches/smoke2/source/blender/makesrna/intern/rna_smoke.c

Added Paths:
-----------
    branches/smoke2/intern/cycles/blender/blender_smoke.cpp

Modified: branches/smoke2/intern/cycles/blender/CMakeLists.txt
===================================================================
--- branches/smoke2/intern/cycles/blender/CMakeLists.txt	2012-07-24 21:11:22 UTC (rev 49187)
+++ branches/smoke2/intern/cycles/blender/CMakeLists.txt	2012-07-24 23:49:50 UTC (rev 49188)
@@ -23,6 +23,7 @@
 	blender_mesh.cpp
 	blender_object.cpp
 	blender_particles.cpp
+	blender_smoke.cpp
 	blender_python.cpp
 	blender_session.cpp
 	blender_shader.cpp

Modified: branches/smoke2/intern/cycles/blender/blender_object.cpp
===================================================================
--- branches/smoke2/intern/cycles/blender/blender_object.cpp	2012-07-24 21:11:22 UTC (rev 49187)
+++ branches/smoke2/intern/cycles/blender/blender_object.cpp	2012-07-24 23:49:50 UTC (rev 49188)
@@ -53,26 +53,6 @@
 	return false;
 }
 
-/* Only looking for Smoke domains */
-// TODO DG: disable rendering of smoke flow??
-bool BlenderSync::BKE_modifiers_isSmokeEnabled(BL::Object b_ob)
-{
-	BL::Object::modifiers_iterator b_modifiers;
-	for(b_ob.modifiers.begin(b_modifiers); b_modifiers != b_ob.modifiers.end(); ++b_modifiers) {
-		BL::Modifier mod = (*b_modifiers);
-
-		if (mod.is_a(&RNA_SmokeModifier)) {
-			BL::SmokeModifier smd(mod);
-
-			if(smd.smoke_type() == BL::SmokeModifier::smoke_type_DOMAIN) {
-				return true;
-			}
-		}
-	}
-
-	return false;
-}
-
 bool BlenderSync::object_is_mesh(BL::Object b_ob)
 {
 	BL::ID b_ob_data = b_ob.data();
@@ -262,11 +242,6 @@
 	/* mesh sync */
 	object->mesh = sync_mesh(b_ob, object_updated);
 
-	if(BKE_modifiers_isSmokeEnabled(b_ob))
-	{
-		// TODO DG sync_volume(b_ob);
-	}
-
 	if(use_holdout != object->use_holdout) {
 		object->use_holdout = use_holdout;
 		scene->object_manager->tag_update(scene);
@@ -302,6 +277,9 @@
 		/* particle sync */
 		if (object_use_particles(b_ob))
 			sync_particles(object, b_ob);
+
+		// if(BKE_modifiers_isSmokeEnabled(b_ob))
+		// 	sync_smoke(object, b_ob);
 	
 		object->tag_update(scene);
 	}

Added: branches/smoke2/intern/cycles/blender/blender_smoke.cpp
===================================================================
--- branches/smoke2/intern/cycles/blender/blender_smoke.cpp	                        (rev 0)
+++ branches/smoke2/intern/cycles/blender/blender_smoke.cpp	2012-07-24 23:49:50 UTC (rev 49188)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "object.h"
+
+#include "mesh.h"
+#include "blender_sync.h"
+#include "blender_util.h"
+
+#include "util_foreach.h"
+
+CCL_NAMESPACE_BEGIN
+
+/* Utilities */
+
+
+/* Smoke Sync */
+
+/* Only looking for Smoke domains */
+// TODO DG: disable rendering of smoke flow??
+bool BlenderSync::BKE_modifiers_isSmokeEnabled(BL::Object b_ob)
+{
+	BL::Object::modifiers_iterator b_modifiers;
+	for(b_ob.modifiers.begin(b_modifiers); b_modifiers != b_ob.modifiers.end(); ++b_modifiers) {
+		BL::Modifier mod = (*b_modifiers);
+
+		if (mod.is_a(&RNA_SmokeModifier)) {
+			BL::SmokeModifier smd(mod);
+
+			if(smd.smoke_type() == BL::SmokeModifier::smoke_type_DOMAIN) {
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
+static BL::SmokeModifier *get_smoke(BL::Object b_ob)
+{
+	BL::Object::modifiers_iterator b_modifiers;
+	for(b_ob.modifiers.begin(b_modifiers); b_modifiers != b_ob.modifiers.end(); ++b_modifiers) {
+		BL::Modifier mod = (*b_modifiers);
+
+		if (mod.is_a(&RNA_SmokeModifier)) {
+			BL::SmokeModifier *smd = (BL::SmokeModifier *)(&mod);
+
+			if(smd->smoke_type() == BL::SmokeModifier::smoke_type_DOMAIN) {
+				return smd;
+			}
+		}
+	}
+	
+	return NULL;
+}
+
+void BlenderSync::sync_smoke(Object *ob, BL::Object b_ob)
+{
+	BL::SmokeModifier *smd = get_smoke(b_ob);
+	BL::SmokeDomainSettings sds = smd->domain_settings();
+
+	ob->resolution = get_int3(sds.domain_resolution());
+
+	// int rna_SmokeModifier_density_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION]);
+	// void rna_SmokeModifier_density_get(PointerRNA *ptr, float *values);
+
+	int length[3];
+	int numcells = rna_SmokeModifier_density_get_length(&sds.ptr, length);
+	
+	ob->grid.clear();
+
+	if(numcells == 0)
+		ob->use_volume = false; // still needs to be rendered transparent!
+	else
+	{
+		ob->use_volume = true;
+
+		vector<float> &grid = ob->grid;
+		grid.reserve(numcells);
+		grid.resize(numcells);
+		rna_SmokeModifier_density_get(&sds.ptr, &grid[0]);
+	}
+}
+
+CCL_NAMESPACE_END

Modified: branches/smoke2/intern/cycles/blender/blender_sync.h
===================================================================
--- branches/smoke2/intern/cycles/blender/blender_sync.h	2012-07-24 21:11:22 UTC (rev 49187)
+++ branches/smoke2/intern/cycles/blender/blender_sync.h	2012-07-24 23:49:50 UTC (rev 49188)
@@ -86,6 +86,7 @@
 	void sync_mesh_motion(BL::Object b_ob, Mesh *mesh, int motion);
 	void sync_camera_motion(BL::Object b_ob, int motion);
 	void sync_particles(Object *ob, BL::Object b_ob);
+	void sync_smoke(Object *ob, BL::Object b_ob);
 
 	/* util */
 	void find_shader(BL::ID id, vector<uint>& used_shaders, int default_shader);

Modified: branches/smoke2/intern/cycles/blender/blender_util.h
===================================================================
--- branches/smoke2/intern/cycles/blender/blender_util.h	2012-07-24 21:11:22 UTC (rev 49187)
+++ branches/smoke2/intern/cycles/blender/blender_util.h	2012-07-24 23:49:50 UTC (rev 49188)
@@ -56,6 +56,9 @@
 void BKE_image_user_frame_calc(void *iuser, int cfra, int fieldnr);
 void BKE_image_user_file_path(void *iuser, void *ima, char *path);
 
+int rna_SmokeModifier_density_get_length(PointerRNA *ptr, int length[3]);
+void rna_SmokeModifier_density_get(PointerRNA *ptr, float *values);
+
 }
 
 CCL_NAMESPACE_BEGIN
@@ -155,6 +158,11 @@
 	return make_int4(array[0], array[1], array[2], array[3]);
 }
 
+static inline int3 get_int3(BL::Array<int, 3> array)
+{
+	return make_int3(array[0], array[1], array[2]);
+}
+
 static inline uint get_layer(BL::Array<int, 20> array)
 {
 	uint layer = 0;

Modified: branches/smoke2/intern/cycles/render/object.h
===================================================================
--- branches/smoke2/intern/cycles/render/object.h	2012-07-24 21:11:22 UTC (rev 49187)
+++ branches/smoke2/intern/cycles/render/object.h	2012-07-24 23:49:50 UTC (rev 49188)
@@ -60,7 +60,7 @@
 	/* Voxel / 3D volume data */
 	bool use_volume;
 	int3 resolution;
-	vector<float3> grid;
+	vector<float> grid;
 
 	Object();
 	~Object();

Modified: branches/smoke2/source/blender/makesrna/intern/rna_smoke.c
===================================================================
--- branches/smoke2/source/blender/makesrna/intern/rna_smoke.c	2012-07-24 21:11:22 UTC (rev 49187)
+++ branches/smoke2/source/blender/makesrna/intern/rna_smoke.c	2012-07-24 23:49:50 UTC (rev 49188)
@@ -113,7 +113,7 @@
 	return BLI_sprintfN("modifiers[\"%s\"].coll_settings", md->name);
 }
 
-static int rna_SmokeModifier_density_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
+int rna_SmokeModifier_density_get_length(PointerRNA *ptr, int length[3])
 {
 	SmokeDomainSettings *settings = (SmokeDomainSettings *)ptr->data;
 
@@ -133,7 +133,7 @@
 	return length[0];
 }
 
-static void rna_SmokeModifier_density_get(PointerRNA *ptr, float *values)
+void rna_SmokeModifier_density_get(PointerRNA *ptr, float *values)
 {
 	SmokeDomainSettings *settings = (SmokeDomainSettings *)ptr->data;
 	float *density = smoke_get_density(settings->fluid);




More information about the Bf-blender-cvs mailing list