[Bf-blender-cvs] [f456cc7] openvdb: Fix grid not being in the proper place (transform).

Kévin Dietrich noreply at git.blender.org
Fri Jun 5 14:08:25 CEST 2015


Commit: f456cc75f2003c8c5cae60f205598c6e1dfb5261
Author: Kévin Dietrich
Date:   Thu May 28 15:40:43 2015 +0200
Branches: openvdb
https://developer.blender.org/rBf456cc75f2003c8c5cae60f205598c6e1dfb5261

Fix grid not being in the proper place (transform).

Basically the smoke simulator uses the MAC grid approach meaning that
the fields (like density, heat...) are cell centered. On the other hand
VDB uses a node center storage; this implies that we have to offset the
position of the grid by half a voxel in each direction.

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

M	source/blender/blenkernel/intern/smoke.c

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

diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 9c99dfa..b84881d 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -3055,6 +3055,7 @@ int smoke_get_data_flags(SmokeDomainSettings *sds)
 static void compute_fluid_matrices(SmokeDomainSettings *sds)
 {
 	float bbox_min[3];
+	float adjust[3];
 
 	copy_v3_v3(bbox_min, sds->p0);
 
@@ -3068,6 +3069,12 @@ static void compute_fluid_matrices(SmokeDomainSettings *sds)
 	/* construct low res matrix */
 	size_to_mat4(sds->fluidmat, sds->cell_size);
 	copy_v3_v3(sds->fluidmat[3], bbox_min);
+
+	/* The smoke simulator stores voxels cell-centered, whilst VDB is node
+	 * centered, so we offset the matrix by half a voxel to compensate. */
+	mul_v3_v3fl(adjust, sds->cell_size, 0.5f);
+	add_v3_v3(sds->fluidmat[3], adjust);
+
 	mul_m4_m4m4(sds->fluidmat, sds->obmat, sds->fluidmat);
 
 	if (sds->wt) {
@@ -3076,6 +3083,11 @@ static void compute_fluid_matrices(SmokeDomainSettings *sds)
 		mul_v3_v3fl(voxel_size_high, sds->cell_size, 1.0f / (float)(sds->amplify + 1));
 		size_to_mat4(sds->fluidmat_wt, voxel_size_high);
 		copy_v3_v3(sds->fluidmat_wt[3], bbox_min);
+
+		/* Same here, add half a voxel to adjust the position of the fluid. */
+		mul_v3_v3fl(adjust, voxel_size_high, 0.5f);
+		add_v3_v3(sds->fluidmat_wt[3], adjust);
+
 		mul_m4_m4m4(sds->fluidmat_wt, sds->obmat, sds->fluidmat_wt);
 	}
 }




More information about the Bf-blender-cvs mailing list