[Bf-blender-cvs] [5ccc748f415] fluid-mantaflow: added initial support for motion blur (cycles)

Sebastián Barschkis noreply at git.blender.org
Sun Jul 29 18:23:49 CEST 2018


Commit: 5ccc748f415722aad446a408d86448be5c7e1f5f
Author: Sebastián Barschkis
Date:   Sun Jul 29 18:23:30 2018 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB5ccc748f415722aad446a408d86448be5c7e1f5f

added initial support for motion blur (cycles)

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/mantaflow/extern/manta_fluid_API.h
M	intern/mantaflow/intern/FLUID.cpp
M	intern/mantaflow/intern/FLUID.h
M	intern/mantaflow/intern/manta_fluid_API.cpp
M	intern/mantaflow/intern/manta_pp/omp/fileio/iomeshes.cpp
M	intern/mantaflow/intern/manta_pp/omp/fileio/mantaio.h
M	intern/mantaflow/intern/manta_pp/omp/levelset.cpp
M	intern/mantaflow/intern/manta_pp/omp/mesh.cpp
M	intern/mantaflow/intern/manta_pp/omp/mesh.h
M	intern/mantaflow/intern/manta_pp/omp/mesh.h.reg
M	intern/mantaflow/intern/manta_pp/omp/mesh.h.reg.cpp
M	intern/mantaflow/intern/manta_pp/tbb/fileio/iomeshes.cpp
M	intern/mantaflow/intern/manta_pp/tbb/fileio/mantaio.h
M	intern/mantaflow/intern/manta_pp/tbb/levelset.cpp
M	intern/mantaflow/intern/manta_pp/tbb/mesh.cpp
M	intern/mantaflow/intern/manta_pp/tbb/mesh.h
M	intern/mantaflow/intern/manta_pp/tbb/mesh.h.reg
M	intern/mantaflow/intern/manta_pp/tbb/mesh.h.reg.cpp
M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/shared_script.h
M	intern/mantaflow/intern/strings/smoke_script.h
M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesdna/DNA_smoke_types.h
M	source/blender/makesrna/intern/rna_smoke.c

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 76d17bc1ae6..b718362c384 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -1032,6 +1032,43 @@ static void create_subd_mesh(Scene *scene,
 
 /* Sync */
 
+static void sync_mesh_manta_motion(BL::Object& b_ob, Scene *scene, Mesh *mesh)
+{
+	if(scene->need_motion() == Scene::MOTION_NONE)
+		return;
+
+	BL::SmokeDomainSettings b_smoke_domain = object_smoke_domain_find(b_ob);
+
+	if(!b_smoke_domain)
+		return;
+
+	/* If the mesh has modifiers following the fluid domain we can't export motion. */
+	if(b_smoke_domain.mesh_vertices.length() != mesh->verts.size())
+		return;
+
+	/* Find or add attribute */
+	float3 *P = &mesh->verts[0];
+	Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
+
+	if(!attr_mP) {
+		attr_mP = mesh->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
+	}
+
+	/* Only export previous and next frame, we don't have any in between data. */
+	float motion_times[2] = {-1.0f, 1.0f};
+	for(int step = 0; step < 2; step++) {
+		float relative_time = motion_times[step] * scene->motion_shutter_time() * 0.5f;
+		float3 *mP = attr_mP->data_float3() + step*mesh->verts.size();
+
+		BL::SmokeDomainSettings::mesh_vertices_iterator svi;
+		int i = 0;
+
+		for(b_smoke_domain.mesh_vertices.begin(svi); svi != b_smoke_domain.mesh_vertices.end(); ++svi, ++i) {
+			mP[i] = P[i] + get_float3(svi->velocity()) * relative_time;
+		}
+	}
+}
+
 static void sync_mesh_fluid_motion(BL::Object& b_ob, Scene *scene, Mesh *mesh)
 {
 	if(scene->need_motion() == Scene::MOTION_NONE)
@@ -1216,6 +1253,9 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
 	}
 	mesh->geometry_flags = requested_geometry_flags;
 
+	/* mesh fluid motion mantaflow */
+	sync_mesh_manta_motion(b_ob, scene, mesh);
+
 	/* fluid motion */
 	sync_mesh_fluid_motion(b_ob, scene, mesh);
 
@@ -1265,6 +1305,11 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
 	 * would need a more extensive check to see which objects are animated */
 	BL::Mesh b_mesh(PointerRNA_NULL);
 
+	/* manta motion is exported immediate with mesh, skip here */
+	BL::SmokeDomainSettings b_smoke_domain = object_smoke_domain_find(b_ob);
+	if(b_smoke_domain)
+		return;
+
 	/* fluid motion is exported immediate with mesh, skip here */
 	BL::DomainFluidSettings b_fluid_domain = object_fluid_domain_find(b_ob);
 	if(b_fluid_domain)
diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 1d51231b583..39234079408 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -113,9 +113,12 @@ float liquid_get_vertex_z_at(struct FLUID *liquid, int i);
 float liquid_get_normal_x_at(struct FLUID *liquid, int i);
 float liquid_get_normal_y_at(struct FLUID *liquid, int i);
 float liquid_get_normal_z_at(struct FLUID *liquid, int i);
-float liquid_get_triangle_x_at(struct FLUID *liquid, int i);
-float liquid_get_triangle_y_at(struct FLUID *liquid, int i);
-float liquid_get_triangle_z_at(struct FLUID *liquid, int i);
+int liquid_get_triangle_x_at(struct FLUID *liquid, int i);
+int liquid_get_triangle_y_at(struct FLUID *liquid, int i);
+int liquid_get_triangle_z_at(struct FLUID *liquid, int i);
+float liquid_get_vertvel_x_at(struct FLUID *liquid, int i);
+float liquid_get_vertvel_y_at(struct FLUID *liquid, int i);
+float liquid_get_vertvel_z_at(struct FLUID *liquid, int i);
 
 // Liquids particles
 int liquid_get_num_flip_particles(struct FLUID *liquid);
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 797273af72d..f6cdd07fe50 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -66,6 +66,7 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
 	mUsingInvel    = smd->domain->active_fields & SM_ACTIVE_INVEL;
 	mUsingNoise    = smd->domain->flags & MOD_SMOKE_NOISE;
 	mUsingMesh     = smd->domain->flags & MOD_SMOKE_MESH;
+	mUsingMVel     = smd->domain->flags & MOD_SMOKE_SPEED_VECTORS;
 	mUsingGuiding  = smd->domain->flags & MOD_SMOKE_GUIDING;
 	mUsingLiquid   = smd->domain->type == MOD_SMOKE_DOMAIN_TYPE_LIQUID;
 	mUsingSmoke    = smd->domain->type == MOD_SMOKE_DOMAIN_TYPE_GAS;
@@ -129,6 +130,7 @@ FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
 	// Mesh
 	mMeshNodes      = NULL;
 	mMeshTriangles  = NULL;
+	mMeshVelocities = NULL;
 
 	// Fluid obstacle
 	mPhiObsIn    = NULL;
@@ -261,6 +263,8 @@ void FLUID::initDomain(SmokeModifierData *smd)
 		+ fluid_file_export
 		+ fluid_save_data
 		+ fluid_load_data
+		+ fluid_pre_step
+		+ fluid_post_step
 		+ fluid_adapt_time_step
 		+ fluid_adaptive_time_stepping;
 	std::string finalString = parseScript(tmpString, smd);
@@ -290,9 +294,7 @@ void FLUID::initSmoke(SmokeModifierData *smd)
 		+ smoke_adaptive_step
 		+ smoke_save_data
 		+ smoke_load_data
-		+ smoke_pre_step
-		+ smoke_step
-		+ smoke_post_step;
+		+ smoke_step;
 	std::string finalString = parseScript(tmpString, smd);
 	pythonCommands.push_back(finalString);
 	
@@ -403,10 +405,7 @@ void FLUID::initLiquid(SmokeModifierData *smd)
 			+ liquid_load_data
 			+ liquid_load_flip
 			+ liquid_adaptive_step
-			+ liquid_pre_step
-			+ liquid_step
-			+ liquid_post_step
-			+ liquid_step_particles;
+			+ liquid_step;
 		std::string finalString = parseScript(tmpString, smd);
 		pythonCommands.push_back(finalString);
 
@@ -432,7 +431,8 @@ void FLUID::initLiquidMesh(SmokeModifierData *smd)
 	std::vector<std::string> pythonCommands;
 	std::string tmpString = liquid_alloc_mesh
 		+ liquid_step_mesh
-		+ liquid_save_mesh;
+		+ liquid_save_mesh
+		+ liquid_save_meshvel;
 	std::string finalString = parseScript(tmpString, smd);
 	pythonCommands.push_back(finalString);
 
@@ -504,6 +504,7 @@ void FLUID::initLiquidSndParts(SmokeModifierData *smd)
 	if (!mSndParticleData) {
 		std::vector<std::string> pythonCommands;
 		std::string tmpString = fluid_alloc_sndparts
+			+ liquid_step_particles
 			+ fluid_with_sndparts;
 		std::string finalString = parseScript(tmpString, smd);
 		pythonCommands.push_back(finalString);
@@ -572,6 +573,7 @@ FLUID::~FLUID()
 	// Mesh
 	mMeshNodes      = NULL;
 	mMeshTriangles  = NULL;
+	mMeshVelocities = NULL;
 
 	// Fluid obstacle
 	mPhiObsIn    = NULL;
@@ -899,6 +901,8 @@ std::string FLUID::getRealValue(const std::string& varName,  SmokeModifierData *
 		ss << mCurrentID;
 	else if (varName == "USING_ADAPTIVETIME")
 		ss << (smd->domain->flags & MOD_SMOKE_ADAPTIVE_TIME ? "True" : "False");
+	else if (varName == "USING_SPEEDVECTORS")
+		ss << (smd->domain->flags & MOD_SMOKE_SPEED_VECTORS ? "True" : "False");
 	else
 		std::cout << "ERROR: Unknown option: " << varName << std::endl;
 	return ss.str();
@@ -984,7 +988,7 @@ int FLUID::updateFlipStructures(SmokeModifierData *smd, int framenr)
 	BLI_path_frame(targetFile, framenr, 0);
 
 	if (BLI_exists(targetFile)) {
-		updateParticlesFromFile(targetFile, false);
+		updateParticlesFromFile(targetFile, false, false);
 	}
 
 	ss.str("");
@@ -993,7 +997,7 @@ int FLUID::updateFlipStructures(SmokeModifierData *smd, int framenr)
 	BLI_path_frame(targetFile, framenr, 0);
 
 	if (BLI_exists(targetFile)) {
-		updateParticlesFromFile(targetFile, false);
+		updateParticlesFromFile(targetFile, false, true);
 	}
 	return 1;
 }
@@ -1011,15 +1015,27 @@ int FLUID::updateMeshStructures(SmokeModifierData *smd, int framenr)
 	targetFile[0] = '\0';
 
 	std::string mformat = getCacheFileEnding(smd->domain->cache_surface_format);
+	std::string dformat = getCacheFileEnding(smd->domain->cache_volume_format);
 	BLI_path_join(cacheDir, sizeof(cacheDir), smd->domain->cache_directory, FLUID_CACHE_DIR_MESH, NULL);
 
-	ss << "liquid_mesh_####" << mformat;
+	ss << "lMesh_####" << mformat;
 	BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
 	BLI_path_frame(targetFile, framenr, 0);
 
 	if (BLI_exists(targetFile)) {
 		updateMeshFromFile(targetFile);
 	}
+
+	if (mUsingMVel) {
+		ss.str("");
+		ss << "lVelMesh_####" << dformat;
+		BLI_join_dirfile(targetFile, sizeof(targetFile), cacheDir, ss.str().c_str());
+		BLI_path_frame(targetFile, framenr, 0);
+
+		if (BLI_exists(targetFile)) {
+			updateMeshFromFile(targetFile);
+		}
+	}
 	return 1;
 }
 
@@ -1043,7 +1059,7 @@ int FLUID::updateParticleStructures(SmokeModifierData *smd, int framenr)
 	BLI_path_frame(targetFile, framenr, 0);
 
 	if (BLI_exists(targetFile)) {
-		updateParticlesFromFile(targetFile, true);
+		updateParticlesFromFile(targetFile, true, false);
 	}
 
 	ss.str("");
@@ -1052,7 +1068,7 @@ int FLUID::updateParticleStructures(SmokeModifierData *smd, int framenr)
 	BLI_path_frame(targetFile, framenr, 0);
 
 	if (BLI_exists(targetFile)) {
-		updateParticlesFromFile(targetFile, true);
+		updateParticlesFromFile(targetFile, true, true);
 	}
 
 	ss.str("");
@@ -1061,7 +1077,7 @@ int FLUID::updateParticleStructures(SmokeModifierData *smd, int framenr)
 	BLI_path_frame(targetFile, framenr, 0);
 
 	if (BLI_exists(targetFile)) {
-		updateParticlesFromFile(targetFile, true);
+		updateParticlesFromFile(targetFile, true, false);
 	}
 	return 1;
 }
@@ -1478,11 +1494,11 @@ void FLUID::exportSmokeScript(SmokeModifierData *smd)
 	if (highres)
 		manta_script += smoke_load_noise;
 
-	manta_script += smoke_pre_step;
+	manta_script += fluid_pre_step;
 	if (highres)
 		manta_script += smoke_pre_step_noise;
 
-	manta_script += smoke_post_step;
+	manta_script += fluid_post_step;
 	if (highres)
 		manta_script += smoke_post_step_noise;
 
@@ -1595,8 +1611,8 @@ void FLUID::exportLiquidScript(SmokeModifierData *smd)
 	if (drops || bubble || floater || tracer)
 		manta_script += fluid_load_particles;
 
-	manta_script += liquid_pre_step;
-	manta_script += liquid_post_step;
+	manta_script += fluid_pre_step;
+	manta_script += fluid_post_step;
 
 	manta_script += fluid_adapt_time_step
 			+ liquid_step
@@ -1744,21 +1760,23 @@ void FLUID::updateMeshFromFile(const char* filename)
 		std::string extension = fname.substr(idx+1);
 
 		if (extension.compare("gz")==0)
-			updateMeshDataFromBobj(filename);
+			updateMeshFromBobj(filename);
 		else if (extension.compare("obj")==0)
-			updateMeshDataF

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list