[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23709] trunk/blender: Smoke:

Daniel Genrich daniel.genrich at gmx.net
Thu Oct 8 12:18:14 CEST 2009


Revision: 23709
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23709
Author:   genscher
Date:     2009-10-08 12:18:14 +0200 (Thu, 08 Oct 2009)

Log Message:
-----------
Smoke:
* Enable external forces like e.g. wind

Modified Paths:
--------------
    trunk/blender/intern/smoke/extern/smoke_API.h
    trunk/blender/intern/smoke/intern/FLUID_3D.cpp
    trunk/blender/intern/smoke/intern/smoke_API.cpp
    trunk/blender/release/scripts/ui/buttons_physics_smoke.py
    trunk/blender/source/blender/blenkernel/intern/smoke.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/makesdna/DNA_smoke_types.h
    trunk/blender/source/blender/makesrna/intern/rna_smoke.c

Modified: trunk/blender/intern/smoke/extern/smoke_API.h
===================================================================
--- trunk/blender/intern/smoke/extern/smoke_API.h	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/intern/smoke/extern/smoke_API.h	2009-10-08 10:18:14 UTC (rev 23709)
@@ -50,6 +50,10 @@
 float *smoke_get_velocity_y(struct FLUID_3D *fluid);
 float *smoke_get_velocity_z(struct FLUID_3D *fluid);
 
+float *smoke_get_force_x(struct FLUID_3D *fluid);
+float *smoke_get_force_y(struct FLUID_3D *fluid);
+float *smoke_get_force_z(struct FLUID_3D *fluid);
+
 unsigned char *smoke_get_obstacle(struct FLUID_3D *fluid);
 
 size_t smoke_get_index(int x, int max_x, int y, int max_y, int z);

Modified: trunk/blender/intern/smoke/intern/FLUID_3D.cpp
===================================================================
--- trunk/blender/intern/smoke/intern/FLUID_3D.cpp	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/intern/smoke/intern/FLUID_3D.cpp	2009-10-08 10:18:14 UTC (rev 23709)
@@ -184,13 +184,6 @@
 {
 	// addSmokeTestCase(_density, _res);
 	// addSmokeTestCase(_heat, _res);
-	
-	// wipe forces
-	for (int i = 0; i < _totalCells; i++)
-	{
-		_xForce[i] = _yForce[i] = _zForce[i] = 0.0f;
-		// _obstacles[i] &= ~2;
-	}
 
 	wipeBoundaries();
 
@@ -232,6 +225,13 @@
 
 	// todo xxx dg: only clear obstacles, not boundaries
 	// memset(_obstacles, 0, sizeof(unsigned char)*_xRes*_yRes*_zRes);
+
+	// wipe forces
+	// for external forces we can't do it at the beginning of this function but at the end
+	for (int i = 0; i < _totalCells; i++)
+	{
+		_xForce[i] = _yForce[i] = _zForce[i] = 0.0f;
+	}
 }
 
 //////////////////////////////////////////////////////////////////////

Modified: trunk/blender/intern/smoke/intern/smoke_API.cpp
===================================================================
--- trunk/blender/intern/smoke/intern/smoke_API.cpp	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/intern/smoke/intern/smoke_API.cpp	2009-10-08 10:18:14 UTC (rev 23709)
@@ -235,6 +235,21 @@
 	return fluid->_zVelocity;
 }
 
+extern "C" float *smoke_get_force_x(FLUID_3D *fluid)
+{
+	return fluid->_xForce;
+}
+
+extern "C" float *smoke_get_force_y(FLUID_3D *fluid)
+{
+	return fluid->_yForce;
+}
+
+extern "C" float *smoke_get_force_z(FLUID_3D *fluid)
+{
+	return fluid->_zForce;
+}
+
 extern "C" float *smoke_turbulence_get_density(WTURBULENCE *wt)
 {
 	return wt ? wt->getDensityBig() : NULL;

Modified: trunk/blender/release/scripts/ui/buttons_physics_smoke.py
===================================================================
--- trunk/blender/release/scripts/ui/buttons_physics_smoke.py	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/release/scripts/ui/buttons_physics_smoke.py	2009-10-08 10:18:14 UTC (rev 23709)
@@ -1,7 +1,8 @@
 
 import bpy
 
-from buttons_particle import point_cache_ui
+from buttons_physics_common import point_cache_ui
+from buttons_physics_common import effector_weights_ui
 
 class PhysicButtonsPanel(bpy.types.Panel):
 	__space_type__ = 'PROPERTIES'
@@ -171,8 +172,20 @@
 		cache = md.point_cache_high
 			
 		point_cache_ui(self, cache, cache.baked==False, 0, 1)
+		
+class PHYSICS_PT_smoke_field_weights(PhysicButtonsPanel):
+	__label__ = "Smoke Field Weights"
+	__default_closed__ = True
+	
+	def poll(self, context):
+		return (context.smoke)
+	
+	def draw(self, context):
+		domain = context.smoke.domain_settings
+		effector_weights_ui(self, domain.effector_weights)
 					
 bpy.types.register(PHYSICS_PT_smoke)
+bpy.types.register(PHYSICS_PT_smoke_field_weights)
 bpy.types.register(PHYSICS_PT_smoke_cache)
 bpy.types.register(PHYSICS_PT_smoke_highres)
 bpy.types.register(PHYSICS_PT_smoke_groups)

Modified: trunk/blender/source/blender/blenkernel/intern/smoke.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/smoke.c	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/source/blender/blenkernel/intern/smoke.c	2009-10-08 10:18:14 UTC (rev 23709)
@@ -53,6 +53,7 @@
 #include "BKE_cdderivedmesh.h"
 #include "BKE_customdata.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_effect.h"
 #include "BKE_modifier.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
@@ -547,6 +548,10 @@
 		if(smd->domain->wt)
 			smoke_turbulence_free(smd->domain->wt);
 
+		if(smd->domain->effector_weights)
+				MEM_freeN(smd->domain->effector_weights);
+		smd->domain->effector_weights = NULL;
+
 		BKE_ptcache_free_list(&(smd->domain->ptcaches[0]));
 		smd->domain->point_cache[0] = NULL;
 		BKE_ptcache_free_list(&(smd->domain->ptcaches[1]));
@@ -714,6 +719,7 @@
 			smd->domain->diss_speed = 5;
 			// init 3dview buffer
 			smd->domain->viewsettings = 0;
+			smd->domain->effector_weights = BKE_add_effector_weights(NULL);
 		}
 		else if(smd->type & MOD_SMOKE_TYPE_FLOW)
 		{
@@ -938,21 +944,53 @@
 	}
 
 	// do effectors
-	/*
-	if(sds->eff_group)
 	{
-		for(go = sds->eff_group->gobject.first; go; go = go->next) 
+		ListBase *effectors = pdInitEffectors(scene, ob, NULL, sds->effector_weights);
+
+		if(effectors)
 		{
-			if(go->ob)
-			{
-				if(ob->pd)
-				{
-					
-				}					
+			float *density = smoke_get_density(sds->fluid);
+			float *force_x = smoke_get_force_x(sds->fluid);
+			float *force_y = smoke_get_force_y(sds->fluid);
+			float *force_z = smoke_get_force_z(sds->fluid);
+			float *velocity_x = smoke_get_velocity_x(sds->fluid);
+			float *velocity_y = smoke_get_velocity_y(sds->fluid);
+			float *velocity_z = smoke_get_velocity_z(sds->fluid);
+			int x, y, z;
+
+			// precalculate wind forces
+			for(x = 0; x < sds->res[0]; x++)
+				for(y = 0; y < sds->res[1]; y++)
+					for(z = 0; z < sds->res[2]; z++)
+			{	
+				EffectedPoint epoint;
+				float voxelCenter[3], vel[3], retvel[3];
+
+				unsigned int index = smoke_get_index(x, sds->res[0], y, sds->res[1], z);
+
+				if(density[index] < FLT_EPSILON)					
+					continue;	
+
+				vel[0] = velocity_x[index];
+				vel[1] = velocity_y[index];
+				vel[2] = velocity_z[index];
+
+				voxelCenter[0] = sds->p0[0] + sds->dx *  x + sds->dx * 0.5;
+				voxelCenter[1] = sds->p0[1] + sds->dx *  y + sds->dx * 0.5;
+				voxelCenter[2] = sds->p0[2] + sds->dx *  z + sds->dx * 0.5;
+
+				pd_point_from_loc(scene, voxelCenter, vel, index, &epoint);
+				pdDoEffectors(effectors, NULL, sds->effector_weights, &epoint, retvel, NULL);
+
+				// TODO dg - do in force!
+				force_x[index] += MIN2(MAX2(-1.0, retvel[0] * 0.002), 1.0); 
+				force_y[index] += MIN2(MAX2(-1.0, retvel[1] * 0.002), 1.0); 
+				force_z[index] += MIN2(MAX2(-1.0, retvel[2] * 0.002), 1.0);
 			}
 		}
+
+		pdEndEffectors(&effectors);
 	}
-	*/
 
 	// do collisions	
 	if(1)

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2009-10-08 10:18:14 UTC (rev 23709)
@@ -3655,6 +3655,8 @@
 					smd->domain->coll_group = newlibadr_us(fd, ob->id.lib, smd->domain->coll_group);
 					smd->domain->eff_group = newlibadr_us(fd, ob->id.lib, smd->domain->eff_group);
 					smd->domain->fluid_group = newlibadr_us(fd, ob->id.lib, smd->domain->fluid_group);
+
+					smd->domain->effector_weights->group = newlibadr(fd, ob->id.lib, smd->domain->effector_weights->group);
 				}
 			}
 
@@ -3784,6 +3786,11 @@
 				smd->domain->tex_shadow = NULL;
 				smd->domain->tex_wt = NULL;
 
+				if(smd->domain->effector_weights)
+					smd->domain->effector_weights = newdataadr(fd, smd->domain->effector_weights);
+				else
+					smd->domain->effector_weights = BKE_add_effector_weights(NULL);
+
 				direct_link_pointcache_list(fd, &(smd->domain->ptcaches[0]), &(smd->domain->point_cache[0]));
 				direct_link_pointcache_list(fd, &(smd->domain->ptcaches[1]), &(smd->domain->point_cache[1]));
 			}

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2009-10-08 10:18:14 UTC (rev 23709)
@@ -1153,7 +1153,10 @@
 			SmokeModifierData *smd = (SmokeModifierData*) md;
 			
 			if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
+			{
 				writestruct(wd, DATA, "SmokeDomainSettings", 1, smd->domain);
+				writestruct(wd, DATA, "EffectorWeights", 1, smd->domain->effector_weights);
+			}
 			else if(smd->type & MOD_SMOKE_TYPE_FLOW)
 				writestruct(wd, DATA, "SmokeFlowSettings", 1, smd->flow);
 			else if(smd->type & MOD_SMOKE_TYPE_COLL)

Modified: trunk/blender/source/blender/makesdna/DNA_smoke_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_smoke_types.h	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/source/blender/makesdna/DNA_smoke_types.h	2009-10-08 10:18:14 UTC (rev 23709)
@@ -45,7 +45,7 @@
 	struct SmokeModifierData *smd; /* for fast RNA access */
 	struct FLUID_3D *fluid;
 	struct Group *fluid_group;
-	struct Group *eff_group; // effector group for e.g. wind force
+	struct Group *eff_group; // UNUSED
 	struct Group *coll_group; // collision objects group
 	struct WTURBULENCE *wt; // WTURBULENCE object, if active
 	struct GPUTexture *tex;
@@ -75,6 +75,7 @@
 	int v3dnum;
 	struct PointCache *point_cache[2];	/* definition is in DNA_object_force.h */
 	struct ListBase ptcaches[2];
+	struct EffectorWeights *effector_weights;
 } SmokeDomainSettings;
 
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_smoke.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_smoke.c	2009-10-08 09:22:39 UTC (rev 23708)
+++ trunk/blender/source/blender/makesrna/intern/rna_smoke.c	2009-10-08 10:18:14 UTC (rev 23709)
@@ -220,6 +220,11 @@
 	RNA_def_property_flag(prop, PROP_NEVER_NULL);
 	RNA_def_property_pointer_sdna(prop, NULL, "point_cache[1]");
 	RNA_def_property_ui_text(prop, "Point Cache", "");
+
+	prop= RNA_def_property(srna, "effector_weights", PROP_POINTER, PROP_NONE);
+	RNA_def_property_struct_type(prop, "EffectorWeights");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Effector Weights", "");
 }
 
 static void rna_def_smoke_flow_settings(BlenderRNA *brna)





More information about the Bf-blender-cvs mailing list