[Bf-blender-cvs] [d5c17b2] openvdb: Properly set the fluid transformation matrix.

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


Commit: d5c17b2c92d903863a764ba41b6e1210b4950e1e
Author: Kévin Dietrich
Date:   Sun May 17 18:53:49 2015 +0200
Branches: openvdb
https://developer.blender.org/rBd5c17b2c92d903863a764ba41b6e1210b4950e1e

Properly set the fluid transformation matrix.

This time for real, though we need to account for adaptive domain, but
that's for another commit I guess.
Also add metadata to the grid to mark it as in local space.

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

M	source/blender/blenkernel/intern/smoke.c
M	source/blender/openvdb/intern/openvdb_smoke_export.cpp

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

diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index ae92d95..6c21abd 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -3045,7 +3045,7 @@ int smoke_get_data_flags(SmokeDomainSettings *sds)
 static struct FluidDomainDescr get_fluid_description(SmokeDomainSettings *sds)
 {
 	FluidDomainDescr descr;
-	float voxel_size[3], voxel_size_high[3], bbox_min[3];
+	float voxel_size[3], voxel_size_high[3];
 
 	descr.active_fields = sds->active_fields;
 	descr.fluid_fields = smoke_get_data_flags(sds);
@@ -3053,9 +3053,9 @@ static struct FluidDomainDescr get_fluid_description(SmokeDomainSettings *sds)
 	copy_v3_v3_int(descr.shift, sds->shift);
 	copy_v3_v3(descr.active_color, sds->active_color);
 
-	mul_m4_m4m4(descr.obmat, sds->obmat, sds->imat);
+	copy_m4_m4(descr.obmat, sds->obmat);
 
-	/* Construct a matrix that represents a voxel:
+	/* Construct a matrix which represents the fluid object:
 	 * vs 0  0  0
 	 * 0  vs 0  0
 	 * 0  0  vs 0
@@ -3064,23 +3064,42 @@ static struct FluidDomainDescr get_fluid_description(SmokeDomainSettings *sds)
 	 * bounding box.
 	 */
 
+	/* construct low res matrix */
 	copy_v3_v3(voxel_size, sds->cell_size);
-	mul_mat3_m4_v3(sds->obmat, voxel_size);
+	size_to_mat4(descr.fluidmat, voxel_size);
+	copy_v3_v3(descr.fluidmat[3], sds->p0);
+	mul_m4_m4m4(descr.fluidmat, sds->obmat, descr.fluidmat);
+
+	/* make sure voxels have the same size on all axises */
+	voxel_size[0] = descr.fluidmat[0][0];
+	voxel_size[1] = descr.fluidmat[1][1];
+	voxel_size[2] = descr.fluidmat[2][2];
 
-	/* only consider the max value as due to float precision issues coupled with
-	 * cuboid domain we might get slightly different xyz values... In short,
-	 * voxels should be cubes!
-	 */
 	copy_v3_fl(voxel_size, max_fff(voxel_size[0], voxel_size[1], voxel_size[2]));
 
-	copy_v3_v3(bbox_min, sds->p0);
-	mul_mat3_m4_v3(sds->obmat, bbox_min);
-	size_to_mat4(descr.fluidmat, voxel_size);
-	copy_v3_v3(descr.fluidmat[3], bbox_min);
+	descr.fluidmat[0][0] = voxel_size[0];
+	descr.fluidmat[1][1] = voxel_size[1];
+	descr.fluidmat[2][2] = voxel_size[2];
+
+	if (sds->wt) {
+		/* construct high res matrix */
+		mul_v3_v3fl(voxel_size_high, sds->cell_size, 1.0f / (float)(sds->amplify + 1));
+		size_to_mat4(descr.fluidmathigh, voxel_size_high);
+		copy_v3_v3(descr.fluidmathigh[3], sds->p0);
+		mul_m4_m4m4(descr.fluidmathigh, sds->obmat, descr.fluidmathigh);
 
-	mul_v3_v3fl(voxel_size_high, voxel_size, 1.0f / (float)(sds->amplify + 1));
-	size_to_mat4(descr.fluidmathigh, voxel_size_high);
-	copy_v3_v3(descr.fluidmathigh[3], bbox_min);
+		/* make sure voxels have the same size on all axises */
+		voxel_size_high[0] = descr.fluidmathigh[0][0];
+		voxel_size_high[1] = descr.fluidmathigh[1][1];
+		voxel_size_high[2] = descr.fluidmathigh[2][2];
+
+		copy_v3_fl(voxel_size, max_fff(voxel_size_high[0], voxel_size_high[1], voxel_size_high[2]));
+
+		descr.fluidmathigh[0][0] = voxel_size_high[0];
+		descr.fluidmathigh[1][1] = voxel_size_high[1];
+		descr.fluidmathigh[2][2] = voxel_size_high[2];
+
+	}
 
 	return descr;
 }
diff --git a/source/blender/openvdb/intern/openvdb_smoke_export.cpp b/source/blender/openvdb/intern/openvdb_smoke_export.cpp
index d084552..bd0c728 100644
--- a/source/blender/openvdb/intern/openvdb_smoke_export.cpp
+++ b/source/blender/openvdb/intern/openvdb_smoke_export.cpp
@@ -54,6 +54,7 @@ static void OpenVDB_export_grid(GridPtrVec &gridVec,
 	grid->setName(name);
 	grid->setGridClass(GRID_FOG_VOLUME);
 	grid->setTransform(transform->copy());
+	grid->setIsInWorldSpace(false);
 
 	gridVec.push_back(grid);
 }
@@ -82,6 +83,7 @@ static void OpenVDB_export_vector_grid(GridPtrVec &gridVec,
 	grid->setName(name);
 	grid->setGridClass(GRID_FOG_VOLUME);
 	grid->setTransform(transform->copy());
+	grid->setIsInWorldSpace(false);
 
 	gridVec.push_back(grid);
 }
@@ -145,9 +147,6 @@ static MetaMap getSimMetaMap(FLUID_3D *fluid, FluidDomainDescr descr)
 	sim_data.insertMeta("shift", Vec3IMetadata(Vec3I(descr.shift)));
 	sim_data.insertMeta("obj_shift_f", Vec3SMetadata(Vec3s(descr.obj_shift_f)));
 
-	/* TODO(kevin): Meta datas can't take double matrices, and transforms can't
-	 * take float matrices, so this is duplicated.
-	 */
 	Mat4s obj_mat = Mat4s(
 			descr.obmat[0][0], descr.obmat[0][1], descr.obmat[0][2], descr.obmat[0][3],
 	        descr.obmat[1][0], descr.obmat[1][1], descr.obmat[1][2], descr.obmat[1][3],
@@ -162,12 +161,6 @@ static MetaMap getSimMetaMap(FLUID_3D *fluid, FluidDomainDescr descr)
 
 void OpenVDB_export_fluid(FLUID_3D *fluid, WTURBULENCE *wt, FluidDomainDescr descr, const char *filename, float *shadow)
 {
-	Mat4R obj_mat = Mat4R(
-			descr.obmat[0][0], descr.obmat[0][1], descr.obmat[0][2], descr.obmat[0][3],
-	        descr.obmat[1][0], descr.obmat[1][1], descr.obmat[1][2], descr.obmat[1][3],
-	        descr.obmat[2][0], descr.obmat[2][1], descr.obmat[2][2], descr.obmat[2][3],
-	        descr.obmat[3][0], descr.obmat[3][1], descr.obmat[3][2], descr.obmat[3][3]);
-
 	Mat4R fluid_mat = Mat4R(
 		  descr.fluidmat[0][0], descr.fluidmat[0][1], descr.fluidmat[0][2], descr.fluidmat[0][3],
           descr.fluidmat[1][0], descr.fluidmat[1][1], descr.fluidmat[1][2], descr.fluidmat[1][3],
@@ -177,7 +170,7 @@ void OpenVDB_export_fluid(FLUID_3D *fluid, WTURBULENCE *wt, FluidDomainDescr des
 	GridPtrVec gridVec;
 	math::CoordBBox bbox(Coord(0), Coord(fluid->_xRes - 1, fluid->_yRes - 1, fluid->_zRes - 1));
 
-	math::Transform::Ptr transform = math::Transform::createLinearTransform(fluid_mat * obj_mat);
+	math::Transform::Ptr transform = math::Transform::createLinearTransform(fluid_mat);
 
 	OpenVDB_export_grid<FloatGrid>(gridVec, "Shadow", shadow, 0.0f, bbox, transform);
 	OpenVDB_export_grid<FloatGrid>(gridVec, "Density", fluid->_density, 0.0f, bbox, transform);
@@ -207,7 +200,7 @@ void OpenVDB_export_fluid(FLUID_3D *fluid, WTURBULENCE *wt, FluidDomainDescr des
 	          descr.fluidmathigh[2][0], descr.fluidmathigh[2][1], descr.fluidmathigh[2][2], descr.fluidmathigh[2][3],
 	          descr.fluidmathigh[3][0], descr.fluidmathigh[3][1], descr.fluidmathigh[3][2], descr.fluidmathigh[3][3]);
 
-		math::Transform::Ptr transformBig = math::Transform::createLinearTransform(fluid_matBig * obj_mat);
+		math::Transform::Ptr transformBig = math::Transform::createLinearTransform(fluid_matBig);
 		math::CoordBBox bboxBig(Coord(0), Coord(wt->_xResBig - 1, wt->_yResBig - 1, wt->_zResBig - 1));
 
 		OpenVDB_export_grid<FloatGrid>(gridVec, "Density High", wt->_densityBig, 0.0f, bboxBig, transformBig);
@@ -333,12 +326,6 @@ void OpenVDB_update_fluid_transform(const char *filename, FluidDomainDescr descr
 	/* TODO(kevin): deduplicate this call */
 	initialize();
 
-	Mat4R obj_mat = Mat4R(
-	        descr.obmat[0][0], descr.obmat[0][1], descr.obmat[0][2], descr.obmat[0][3],
-	        descr.obmat[1][0], descr.obmat[1][1], descr.obmat[1][2], descr.obmat[1][3],
-	        descr.obmat[2][0], descr.obmat[2][1], descr.obmat[2][2], descr.obmat[2][3],
-	        descr.obmat[3][0], descr.obmat[3][1], descr.obmat[3][2], descr.obmat[3][3]);
-
 	Mat4R fluid_mat = Mat4R(
 	        descr.fluidmat[0][0], descr.fluidmat[0][1], descr.fluidmat[0][2], descr.fluidmat[0][3],
 	        descr.fluidmat[1][0], descr.fluidmat[1][1], descr.fluidmat[1][2], descr.fluidmat[1][3],
@@ -351,8 +338,8 @@ void OpenVDB_update_fluid_transform(const char *filename, FluidDomainDescr descr
 	        descr.fluidmathigh[2][0], descr.fluidmathigh[2][1], descr.fluidmathigh[2][2], descr.fluidmathigh[2][3],
 	        descr.fluidmathigh[3][0], descr.fluidmathigh[3][1], descr.fluidmathigh[3][2], descr.fluidmathigh[3][3]);
 
-	math::Transform::Ptr transform = math::Transform::createLinearTransform(fluid_mat * obj_mat);
-	math::Transform::Ptr transformBig = math::Transform::createLinearTransform(fluid_matBig * obj_mat);
+	math::Transform::Ptr transform = math::Transform::createLinearTransform(fluid_mat);
+	math::Transform::Ptr transformBig = math::Transform::createLinearTransform(fluid_matBig);
 
 	io::File file(filename);
 	file.open();




More information about the Bf-blender-cvs mailing list