[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48320] branches/soc-2012-fried_chicken/ source/blender: * Changing (most) smoke domain settings no longer clears whole domain but just the cache.

Miika Hamalainen miika.hamalainen at kolumbus.fi
Tue Jun 26 21:15:47 CEST 2012


Revision: 48320
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48320
Author:   miikah
Date:     2012-06-26 19:15:47 +0000 (Tue, 26 Jun 2012)
Log Message:
-----------
* Changing (most) smoke domain settings no longer clears whole domain but just the cache. This way it's easier to try out different settings while playback.
* Copying domain object now also preserves adaptive settings. :p
* Heat/velocity debug visualization (dev only) works again.
* Some code cleanup.

Modified Paths:
--------------
    branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/smoke.c
    branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/drawvolume.c
    branches/soc-2012-fried_chicken/source/blender/makesrna/intern/rna_smoke.c

Modified: branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/smoke.c
===================================================================
--- branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/smoke.c	2012-06-26 18:06:42 UTC (rev 48319)
+++ branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/smoke.c	2012-06-26 19:15:47 UTC (rev 48320)
@@ -564,6 +564,10 @@
 		tsmd->domain->time_scale = smd->domain->time_scale;
 		tsmd->domain->border_collisions = smd->domain->border_collisions;
 
+		tsmd->domain->adapt_margin = smd->domain->adapt_margin;
+		tsmd->domain->adapt_res = smd->domain->adapt_res;
+		tsmd->domain->adapt_threshold = smd->domain->adapt_threshold;
+
 		tsmd->domain->burning_rate = smd->domain->burning_rate;
 		tsmd->domain->flame_smoke = smd->domain->flame_smoke;
 		tsmd->domain->flame_vorticity = smd->domain->flame_vorticity;
@@ -1509,12 +1513,13 @@
 					for(gy = em->min[1]; gy < em->max[1]; gy++)
 						for(gz = em->min[2]; gz < em->max[2]; gz++)													
 						{
-							// get emission map index
+							/* get emission map index */
 							ex = gx-em->min[0];
 							ey = gy-em->min[1];
 							ez = gz-em->min[2];
 							e_index = smoke_get_index(ex, em->res[0], ey, em->res[1], ez);
 							if (!emission_map[e_index]) continue;
+							/* get domain index */
 							dx = gx-sds->res_min[0];
 							dy = gy-sds->res_min[1];
 							dz = gz-sds->res_min[2];
@@ -1530,8 +1535,8 @@
 							}
 							else { // inflow
 								heat[d_index] = MAX2(emission_map[e_index]*sfs->temp, heat[d_index]);
-								if (absolute_flow) // absolute
-								{
+								/* absolute */
+								if (absolute_flow) {
 									if (sfs->type != MOD_SMOKE_FLOW_TYPE_FIRE) {
 										if (emission_map[e_index] * sfs->density > density[d_index])
 											density[d_index] = emission_map[e_index] * sfs->density;
@@ -1541,8 +1546,8 @@
 											fuel[d_index] = emission_map[e_index] * sfs->fuel_amount;
 									}
 								}
-								else // additive
-								{
+								/* additive */
+								else {
 									if (sfs->type != MOD_SMOKE_FLOW_TYPE_FIRE)
 										density[d_index] += emission_map[e_index] * sfs->density;
 									if (sfs->type != MOD_SMOKE_FLOW_TYPE_SMOKE)
@@ -1785,16 +1790,15 @@
 
 	/* adapt timestep for different framerates, dt = 0.1 is at 25fps */
 	dt *= (25.0f / fps);
-
 	// maximum timestep/"CFL" constraint: dt < 5.0 *dx / maxVel
 	maxVel = (sds->dx * 5.0);
 
-	for(i = 0; i < size; i++)
+	/*for(i = 0; i < size; i++)
 	{
 		float vtemp = (velX[i]*velX[i]+velY[i]*velY[i]+velZ[i]*velZ[i]);
 		if(vtemp > maxVelMag)
 			maxVelMag = vtemp;
-	}
+	}*/
 
 	maxVelMag = sqrt(maxVelMag) * dt * sds->time_scale;
 	totalSubsteps = (int)((maxVelMag / maxVel) + 1.0f); /* always round up */
@@ -1839,7 +1843,7 @@
 	float ob_loc[3] = {0};
 	float ob_cache_loc[3] = {0};
 
-	/* dont generate any mesh if there is domain area */
+	/* dont generate any mesh if there isnt any content */
 	if (sds->total_cells <= 1) {
 		num_verts = 0;
 		num_faces = 0;
@@ -1889,7 +1893,7 @@
 		ml[0].v = 1; ml[1].v = 0; ml[2].v = 4; ml[3].v = 5;
 
 		/* calculate required shift to match domain's global position
-		*  where it was originally simulated (if object moves without smoke step) */
+		*  it was originally simulated at (if object moves without smoke step) */
 		invert_m4_m4(ob->imat, ob->obmat);
 		mul_m4_v3(ob->obmat, ob_loc);
 		mul_m4_v3(sds->obmat, ob_cache_loc);
@@ -1976,7 +1980,6 @@
 			return;
 
 		smd->domain->flags &= ~MOD_SMOKE_FILE_LOAD;
-
 		CLAMP(framenr, startframe, endframe);
 
 		/* If already viewing a pre/after frame, no need to reload */
@@ -2026,8 +2029,6 @@
 
 		/* do simulation */
 
-		// low res
-
 		// simulate the actual smoke (c++ code in intern/smoke)
 		// DG: interesting commenting this line + deactivating loading of noise files
 		if(framenr!=startframe)
@@ -2061,6 +2062,7 @@
 {
 	smokeModifier_process(smd, scene, ob, dm);
 
+	/* return generated geometry for adaptive domain */
 	if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain &&
 		smd->domain->flags & MOD_SMOKE_ADAPTIVE_DOMAIN)
 	{
@@ -2231,7 +2233,7 @@
 				voxelCenter[1] = (float)y;
 				voxelCenter[2] = (float)z;
 
-				// get starting cell (light)
+				// get starting cell (light pos)
 				if(BLI_bvhtree_bb_raycast(bv, light, voxelCenter, pos) > FLT_EPSILON)
 				{
 					// we're ouside -> use point on side of domain

Modified: branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/drawvolume.c
===================================================================
--- branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/drawvolume.c	2012-06-26 18:06:42 UTC (rev 48319)
+++ branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/drawvolume.c	2012-06-26 19:15:47 UTC (rev 48320)
@@ -404,7 +404,6 @@
 	ds = (ABS(viewnormal[0]) * size[0] + ABS(viewnormal[1]) * size[1] + ABS(viewnormal[2]) * size[2]);
 	dd = dx*base_scale/128.f;
 	dd = MAX3(sds->global_size[0],sds->global_size[1],sds->global_size[2])/128.f;
-	//dd = (viewnormal[0]*viewnormal[0]*sds->cell_size[0] + viewnormal[1]*viewnormal[1]*sds->cell_size[1] + viewnormal[2]*viewnormal[2]*sds->cell_size[2]) * sds->maxres / 128.f;
 	n = 0;
 	good_index = i;
 
@@ -447,7 +446,6 @@
 				}
 			}
 
-			// printf("numpoints: %d\n", numpoints);
 			/* render fire slice */
 			glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 			glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, 1.0, 0.0, 0.0, 0.0);
@@ -521,26 +519,22 @@
 	float *vel_y = smoke_get_velocity_y(domain->fluid);
 	float *vel_z = smoke_get_velocity_z(domain->fluid);
 
-	float *min = domain->p0;
+	float min[3];
 	float *cell_size = domain->cell_size;
 	float step_size = ((float)MAX3(base_res[0], base_res[1], base_res[2]))/16.f;
-	float vf = domain->scale / 16.f * 2.f;
+	float vf = domain->scale / 16.f * 2.f; /* velocity factor */
 
-	glColor3f(1.0f, 0.5f, 0.0f);
 	glLineWidth(1.0f);
 
 	/* set first position so that it doesn't jump when domain moves */
-	/*x0 = fmod(-(float)domain->shift[0],step_size);
-	y0 = fmod(-(float)domain->shift[1],step_size);
-	z0 = fmod(-(float)domain->shift[2],step_size);
-	if (x0<0.0f) x0+=step_size;
-	if (y0<0.0f) y0+=step_size;
-	if (z0<0.0f) z0+=step_size;*/
+	x0 = res_min[0] + fmod(-(float)domain->shift[0]+res_min[0],step_size);
+	y0 = res_min[1] + fmod(-(float)domain->shift[1]+res_min[1],step_size);
+	z0 = res_min[2] + fmod(-(float)domain->shift[2]+res_min[2],step_size);
+	if (x0<res_min[0]) x0+=step_size;
+	if (y0<res_min[1]) y0+=step_size;
+	if (z0<res_min[2]) z0+=step_size;
+	add_v3_v3v3(min, domain->p0, domain->obj_shift_f);
 
-	x0 = res_min[0];
-	y0 = res_min[1];
-	z0 = res_min[2];
-
 	for (x=floor(x0); x<res_max[0]; x+=step_size)
 		for (y=floor(y0); y<res_max[1]; y+=step_size)
 			for (z=floor(z0); z<res_max[2]; z+=step_size) {
@@ -549,6 +543,7 @@
 				float pos[3] = {min[0]+((float)x + 0.5f)*cell_size[0], min[1]+((float)y + 0.5f)*cell_size[1], min[2]+((float)z + 0.5f)*cell_size[2]};
 				float vel = sqrtf(vel_x[index]*vel_x[index] + vel_y[index]*vel_y[index] + vel_z[index]*vel_z[index]);
 
+				/* draw heat as scaled "arrows" */
 				if (vel >= 0.01f) {
 					float col_g = 1.0f - vel;
 					CLAMP(col_g, 0.0f, 1.0f);
@@ -571,20 +566,35 @@
 void draw_smoke_heat(SmokeDomainSettings *domain, Object *ob)
 {
 	float x,y,z;
+	float x0,y0,z0;
+	int *base_res = domain->base_res;
 	int *res = domain->res;
+	int *res_min = domain->res_min;
+	int *res_max = domain->res_max;
 	float *heat = smoke_get_heat(domain->fluid);
 
-	float *min = domain->p0;
-	float cell_size = domain->dx * domain->scale;
-	float step_size = ((float)MAX3(res[0], res[1], res[2]))/16.f;
+	float min[3];
+	float *cell_size = domain->cell_size;
+	float step_size = ((float)MAX3(base_res[0], base_res[1], base_res[2]))/16.f;
+	float vf = domain->scale / 16.f * 2.f; /* velocity factor */
 
-	for (x=0; x<res[0]; x+=step_size)
-		for (y=0; y<res[1]; y+=step_size)
-			for (z=0; z<res[2]; z+=step_size) {
-				int index = floor(x) + floor(y)*res[0] + floor(z)*res[0]*res[1];
+	/* set first position so that it doesn't jump when domain moves */
+	x0 = res_min[0] + fmod(-(float)domain->shift[0]+res_min[0],step_size);
+	y0 = res_min[1] + fmod(-(float)domain->shift[1]+res_min[1],step_size);
+	z0 = res_min[2] + fmod(-(float)domain->shift[2]+res_min[2],step_size);
+	if (x0<res_min[0]) x0+=step_size;
+	if (y0<res_min[1]) y0+=step_size;
+	if (z0<res_min[2]) z0+=step_size;
+	add_v3_v3v3(min, domain->p0, domain->obj_shift_f);
 
-				float pos[3] = {min[0]+((float)x + 0.5f)*cell_size, min[1]+((float)y + 0.5f)*cell_size, min[2]+((float)z + 0.5f)*cell_size};
+	for (x=floor(x0); x<res_max[0]; x+=step_size)
+		for (y=floor(y0); y<res_max[1]; y+=step_size)
+			for (z=floor(z0); z<res_max[2]; z+=step_size) {
+				int index = (floor(x)-res_min[0]) + (floor(y)-res_min[1])*res[0] + (floor(z)-res_min[2])*res[0]*res[1];
 
+				float pos[3] = {min[0]+((float)x + 0.5f)*cell_size[0], min[1]+((float)y + 0.5f)*cell_size[1], min[2]+((float)z + 0.5f)*cell_size[2]};
+
+				/* draw heat as different sized points */
 				if (heat[index] >= 0.01f) {
 					float col_gb = 1.0f - heat[index];
 					CLAMP(col_gb, 0.0f, 1.0f);

Modified: branches/soc-2012-fried_chicken/source/blender/makesrna/intern/rna_smoke.c
===================================================================
--- branches/soc-2012-fried_chicken/source/blender/makesrna/intern/rna_smoke.c	2012-06-26 18:06:42 UTC (rev 48319)
+++ branches/soc-2012-fried_chicken/source/blender/makesrna/intern/rna_smoke.c	2012-06-26 19:15:47 UTC (rev 48320)
@@ -65,15 +65,20 @@
 	DAG_scene_sort(bmain, scene);
 }
 
+static void rna_Smoke_resetCache(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	SmokeDomainSettings *settings = (SmokeDomainSettings *)ptr->data;
+	if (settings->smd && settings->smd->domain)
+		settings->point_cache[0]->flag |= PTCACHE_OUTDATED;
+}
+
 static void rna_Smoke_reset(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	SmokeDomainSettings *settings = (SmokeDomainSettings *)ptr->data;
 
 	smokeModifier_reset(settings->smd);
+	rna_Smoke_resetCache(bmain, scene, ptr);
 
-	if (settings->smd && settings->smd->domain)
-		settings->point_cache[0]->flag |= PTCACHE_OUTDATED;
-
 	rna_Smoke_update(bmain, scene, ptr);
 }
 
@@ -235,7 +240,7 @@
 	RNA_def_property_ui_range(prop, -5.0, 5.0, 0.02, 5);
 	RNA_def_property_ui_text(prop, "Density",
 	                         "How much density affects smoke motion (higher value results in faster rising smoke)");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list