[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48248] branches/soc-2012-fried_chicken: This commit includes my smoke work from previous weeks.

Miika Hamalainen miika.hamalainen at kolumbus.fi
Sun Jun 24 22:21:58 CEST 2012


Revision: 48248
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48248
Author:   miikah
Date:     2012-06-24 20:21:57 +0000 (Sun, 24 Jun 2012)
Log Message:
-----------
This commit includes my smoke work from previous weeks.

There are lots of changes in the code but here is a list of new things visible to users:
* A new "Adaptive Domain" setting. It makes smoke domain dynamically adapt to domain and fluid changes:
1) Domain resolution and size adapts to only cover areas where smoke is, so that as small domain as possible has to be calculated at a time. You can also add additional simulation cells around the original domain area if needed.
2) When you move the domain object during simulation you only move the smoke "boundaries". Smoke itself remains still. This way you can limit simulated area to stay around moving emitters etc.
* Domain is now rotatable. This means you are no longer need to align your simulation on x, y or z axis but you can freely rotate the domain to match the target area.
* Rotation and scaling also work during simulation with one limitation: Domain contents (smoke,fire) move with the domain.
* Smoke now uses the scene gravity setting, so you can change gravity direction if required.
* Added a new option for volume textures when "Generated" coordinates are used: "Map to Bounds". This maps texture coordinates to mesh bounding box allowing you to render adaptive domain content. It also solves issues with domains scaled in edit mode, so I'm considering to make this enabled by default.

Please note that this feature is not yet finished. I still have quite a few todos left and I'm sure there are still several bugs there.

Modified Paths:
--------------
    branches/soc-2012-fried_chicken/intern/smoke/extern/smoke_API.h
    branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.cpp
    branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.h
    branches/soc-2012-fried_chicken/intern/smoke/intern/smoke_API.cpp
    branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_physics_smoke.py
    branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_texture.py
    branches/soc-2012-fried_chicken/source/blender/blenkernel/BKE_smoke.h
    branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/pointcache.c
    branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/smoke.c
    branches/soc-2012-fried_chicken/source/blender/blenlib/BLI_utildefines.h
    branches/soc-2012-fried_chicken/source/blender/blenloader/intern/readfile.c
    branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/drawvolume.c
    branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/view3d_intern.h
    branches/soc-2012-fried_chicken/source/blender/makesdna/DNA_smoke_types.h
    branches/soc-2012-fried_chicken/source/blender/makesdna/DNA_texture_types.h
    branches/soc-2012-fried_chicken/source/blender/makesrna/intern/rna_material.c
    branches/soc-2012-fried_chicken/source/blender/makesrna/intern/rna_smoke.c
    branches/soc-2012-fried_chicken/source/blender/modifiers/intern/MOD_smoke.c
    branches/soc-2012-fried_chicken/source/blender/render/intern/source/render_texture.c

Modified: branches/soc-2012-fried_chicken/intern/smoke/extern/smoke_API.h
===================================================================
--- branches/soc-2012-fried_chicken/intern/smoke/extern/smoke_API.h	2012-06-24 20:18:32 UTC (rev 48247)
+++ branches/soc-2012-fried_chicken/intern/smoke/extern/smoke_API.h	2012-06-24 20:21:57 UTC (rev 48248)
@@ -42,12 +42,12 @@
 				  float **vx, float **vy, float **vz, unsigned char **obstacles);
 
 // low res
-struct FLUID_3D *smoke_init(int *res, float *p0, float dtdef);
+struct FLUID_3D *smoke_init(int *res, float dx, float dtdef);
 void smoke_free(struct FLUID_3D *fluid);
 
 void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli,
 						  float *burning_rate, float *flame_smoke, float *flame_vorticity, float *flame_ignition_temp, float *flame_max_temp);
-void smoke_step(struct FLUID_3D *fluid, float dtSubdiv);
+void smoke_step(struct FLUID_3D *fluid, float gravity[3], float dtSubdiv);
 
 float *smoke_get_density(struct FLUID_3D *fluid);
 float *smoke_get_flame(struct FLUID_3D *fluid);

Modified: branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.cpp
===================================================================
--- branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.cpp	2012-06-24 20:18:32 UTC (rev 48247)
+++ branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.cpp	2012-06-24 20:21:57 UTC (rev 48248)
@@ -44,16 +44,11 @@
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-FLUID_3D::FLUID_3D(int *res, float *p0, float dtdef) :
+FLUID_3D::FLUID_3D(int *res, float dx, float dtdef) :
 	_xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
 {
 	// set simulation consts
 	_dt = dtdef;	// just in case. set in step from a RNA factor
-	
-	// start point of array
-	_p0[0] = p0[0];
-	_p0[1] = p0[1];
-	_p0[2] = p0[2];
 
 	_iterations = 100;
 	_tempAmb = 0; 
@@ -72,7 +67,10 @@
 	*/
 	
 	// scale the constants according to the refinement of the grid
-	_dx = 1.0f / (float)_maxRes;
+	if (!dx)
+		_dx = 1.0f / (float)_maxRes;
+	else
+		_dx = dx;
 	_constantScaling = 64.0f / _maxRes;
 	_constantScaling = (_constantScaling < 1.0f) ? 1.0f : _constantScaling;
 	_vorticityEps = 2.0f / _constantScaling; // Just in case set a default value
@@ -250,7 +248,7 @@
 //////////////////////////////////////////////////////////////////////
 // step simulation once
 //////////////////////////////////////////////////////////////////////
-void FLUID_3D::step(float dt)
+void FLUID_3D::step(float dt, float gravity[3])
 {
 #if 0
 	// If border rules have been changed
@@ -301,7 +299,7 @@
 
 		wipeBoundariesSL(zBegin, zEnd);
 		addVorticity(zBegin, zEnd);
-		addBuoyancy(_heat, _density, zBegin, zEnd);
+		addBuoyancy(_heat, _density, gravity, zBegin, zEnd);
 		addForce(zBegin, zEnd);
 
 #if PARALLEL==1
@@ -1200,7 +1198,7 @@
 //////////////////////////////////////////////////////////////////////
 // add buoyancy forces
 //////////////////////////////////////////////////////////////////////
-void FLUID_3D::addBuoyancy(float *heat, float *density, int zBegin, int zEnd)
+void FLUID_3D::addBuoyancy(float *heat, float *density, float gravity[3], int zBegin, int zEnd)
 {
 	int index = zBegin*_slabSize;
 
@@ -1208,7 +1206,10 @@
 		for (int y = 0; y < _yRes; y++)
 			for (int x = 0; x < _xRes; x++, index++)
 			{
-				_zForce[index] += *_alpha * density[index] + (*_beta * (heat[index] - _tempAmb)); // DG: was _yForce, changed for Blender
+				float buoyancy = *_alpha * density[index] + (*_beta * (heat[index] - _tempAmb));
+				_xForce[index] -= gravity[0] * buoyancy;
+				_yForce[index] -= gravity[1] * buoyancy;
+				_zForce[index] -= gravity[2] * buoyancy;
 			}
 }
 

Modified: branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.h
===================================================================
--- branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.h	2012-06-24 20:18:32 UTC (rev 48247)
+++ branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.h	2012-06-24 20:21:57 UTC (rev 48248)
@@ -46,7 +46,7 @@
 class FLUID_3D  
 {
 	public:
-		FLUID_3D(int *res, /* int amplify, */ float *p0, float dtdef);
+		FLUID_3D(int *res, float dx, float dtdef);
 		FLUID_3D() {};
 		virtual ~FLUID_3D();
 
@@ -59,7 +59,7 @@
 		void addSmokeColumn();
 		static void addSmokeTestCase(float* field, Vec3Int res);
 
-		void step(float dt);
+		void step(float dt, float gravity[3]);
 		void addObstacle(OBSTACLE* obstacle);
 
 		const float* xVelocity() { return _xVelocity; }; 
@@ -161,7 +161,7 @@
 		void wipeBoundariesSL(int zBegin, int zEnd);
 		void addForce(int zBegin, int zEnd);
 		void addVorticity(int zBegin, int zEnd);
-		void addBuoyancy(float *heat, float *density, int zBegin, int zEnd);
+		void addBuoyancy(float *heat, float *density, float gravity[3], int zBegin, int zEnd);
 
 		// solver stuff
 		void project();

Modified: branches/soc-2012-fried_chicken/intern/smoke/intern/smoke_API.cpp
===================================================================
--- branches/soc-2012-fried_chicken/intern/smoke/intern/smoke_API.cpp	2012-06-24 20:18:32 UTC (rev 48247)
+++ branches/soc-2012-fried_chicken/intern/smoke/intern/smoke_API.cpp	2012-06-24 20:21:57 UTC (rev 48248)
@@ -38,10 +38,10 @@
 #include <math.h>
 
 // y in smoke is z in blender
-extern "C" FLUID_3D *smoke_init(int *res, float *p0, float dtdef)
+extern "C" FLUID_3D *smoke_init(int *res, float dx, float dtdef)
 {
 	// smoke lib uses y as top-bottom/vertical axis where blender uses z
-	FLUID_3D *fluid = new FLUID_3D(res, p0, dtdef);
+	FLUID_3D *fluid = new FLUID_3D(res, dx, dtdef);
 
 	// printf("xres: %d, yres: %d, zres: %d\n", res[0], res[1], res[2]);
 
@@ -80,10 +80,10 @@
 	return x + y * max_x;
 }
 
-extern "C" void smoke_step(FLUID_3D *fluid, float dtSubdiv)
+extern "C" void smoke_step(FLUID_3D *fluid, float gravity[3], float dtSubdiv)
 {
 	fluid->processBurn(fluid->_fuel, fluid->_density, fluid->_flame, fluid->_heat, fluid->_totalCells, (*fluid->_dtFactor)*dtSubdiv);
-	fluid->step(dtSubdiv);
+	fluid->step(dtSubdiv, gravity);
 }
 
 extern "C" void smoke_turbulence_step(WTURBULENCE *wt, FLUID_3D *fluid)

Modified: branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_physics_smoke.py
===================================================================
--- branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_physics_smoke.py	2012-06-24 20:18:32 UTC (rev 48247)
+++ branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_physics_smoke.py	2012-06-24 20:21:57 UTC (rev 48248)
@@ -147,6 +147,38 @@
         col.label(text="Temperatures:")
         col.prop(domain, "flame_ignition")
         col.prop(domain, "flame_max_temp")
+        
+class PHYSICS_PT_smoke_adaptive_domain(PhysicButtonsPanel, Panel):
+    bl_label = "Smoke Adaptive Domain"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    @classmethod
+    def poll(cls, context):
+        md = context.smoke
+        return md and (md.smoke_type == 'DOMAIN')
+
+    def draw_header(self, context):
+        md = context.smoke.domain_settings
+
+        self.layout.prop(md, "use_adaptive_domain", text="")
+
+    def draw(self, context):
+        layout = self.layout
+
+        domain = context.smoke.domain_settings
+        layout.active = domain.use_adaptive_domain
+        
+        split = layout.split()
+        split.enabled = not domain.point_cache.is_baked
+ 
+        col = split.column(align=True)
+        col.label(text="Resolution:")
+        col.prop(domain, "additional_res")
+        col.prop(domain, "adapt_margin")
+
+        col = split.column(align=True)
+        col.label(text="Advanced:")
+        col.prop(domain, "adapt_threshold")
             
 class PHYSICS_PT_smoke_groups(PhysicButtonsPanel, Panel):
     bl_label = "Smoke Groups"

Modified: branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_texture.py
===================================================================
--- branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_texture.py	2012-06-24 20:18:32 UTC (rev 48247)
+++ branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_texture.py	2012-06-24 20:21:57 UTC (rev 48248)
@@ -870,6 +870,8 @@
                 col = split.column()
                 if tex.texture_coords in {'ORCO', 'UV'}:
                     col.prop(tex, "use_from_dupli")
+                    if (idblock.type == 'VOLUME' and tex.texture_coords == 'ORCO'):
+                        col.prop(tex, "use_map_to_bounds")
                 elif tex.texture_coords == 'OBJECT':
                     col.prop(tex, "use_from_original")
                 else:

Modified: branches/soc-2012-fried_chicken/source/blender/blenkernel/BKE_smoke.h
===================================================================
--- branches/soc-2012-fried_chicken/source/blender/blenkernel/BKE_smoke.h	2012-06-24 20:18:32 UTC (rev 48247)
+++ branches/soc-2012-fried_chicken/source/blender/blenkernel/BKE_smoke.h	2012-06-24 20:21:57 UTC (rev 48248)
@@ -35,8 +35,10 @@
 
 typedef float (*bresenham_callback)(float *result, float *input, int res[3], int *pixel, float *tRay, float correct);
 
-void smokeModifier_do(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm);
+struct DerivedMesh *smokeModifier_do(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm);
 
+void smoke_reallocate_fluid(struct SmokeDomainSettings *sds, float dx, int res[3], int free_old);
+void smoke_reallocate_highres_fluid(struct SmokeDomainSettings *sds, float dx, int res[3], int free_old);
 void smokeModifier_free(struct SmokeModifierData *smd);
 void smokeModifier_reset(struct SmokeModifierData *smd);
 void smokeModifier_reset_turbulence(struct SmokeModifierData *smd);

Modified: branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/pointcache.c	2012-06-24 20:18:32 UTC (rev 48247)
+++ branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/pointcache.c	2012-06-24 20:21:57 UTC (rev 48248)
@@ -534,16 +534,24 @@
 	SmokeDomainSettings *sds = smd->domain;
 	
 	if (sds->fluid) {
-		return sds->res[0]*sds->res[1]*sds->res[2];

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list