[Bf-blender-cvs] [f19a416] alembic: Correct progression handling of the strands motion state through cache baking.

Lukas Tönne noreply at git.blender.org
Fri Apr 3 11:23:02 CEST 2015


Commit: f19a416b363cf19c0b353afc7d26461a4e25c44d
Author: Lukas Tönne
Date:   Fri Apr 3 11:21:40 2015 +0200
Branches: alembic
https://developer.blender.org/rBf19a416b363cf19c0b353afc7d26461a4e25c44d

Correct progression handling of the strands motion state through cache
baking.

For now this simply applies gravity and applies the basic hair solver
for velocities and positions.

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

M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/strands.c
M	source/blender/editors/space_view3d/drawstrands.c
M	source/blender/physics/BPH_mass_spring.h
M	source/blender/physics/intern/BPH_mass_spring.cpp
M	source/blender/pointcache/alembic/abc_particles.cpp

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

diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index b711100..0a2a773 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -583,12 +583,10 @@ static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx
 			Strands *strands = link->strands;
 			
 			struct Implicit_Data *solver_data;
-			int numsprings;
 			
 			BKE_strands_add_motion_state(strands);
 			
-			numsprings = strands->totverts - strands->totcurves;
-			solver_data = BPH_mass_spring_solver_create(strands->totverts, numsprings);
+			solver_data = BPH_strands_solver_create(strands, &hsmd->sim_params);
 			
 			BPH_strands_solve(strands, solver_data, &hsmd->sim_params, (float)frame, (float)frame_prev, ctx->scene, NULL);
 			
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index e91aed5..2f4b9da 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -53,7 +53,18 @@ void BKE_strands_free(Strands *strands)
 void BKE_strands_add_motion_state(Strands *strands)
 {
 	if (!strands->state) {
+		int i;
+		
 		strands->state = MEM_mallocN(sizeof(StrandsMotionState) * strands->totverts, "strand motion states");
+		
+		/* XXX for now just copy from the goal state to initialize
+		 * this could be much more interesting
+		 */
+		for (i = 0; i < strands->totverts; ++i) {
+			copy_v3_v3(strands->state[i].co, strands->verts[i].co);
+			zero_v3(strands->state[i].vel);
+			copy_v3_v3(strands->state[i].nor, strands->verts[i].nor);
+		}
 	}
 }
 
diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c
index c7c6ba5..adf6b7a 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -52,6 +52,8 @@
 
 static void draw_strand_lines(Strands *strands, short dflag)
 {
+	const bool has_motion_state = strands->state;
+	
 	GLint polygonmode[2];
 	StrandIterator it_strand;
 	
@@ -75,8 +77,14 @@ static void draw_strand_lines(Strands *strands, short dflag)
 		if (it_strand.tot <= 0)
 			continue;
 		
-		glVertexPointer(3, GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->co);
-		glNormalPointer(GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->nor);
+		if (has_motion_state) {
+			glVertexPointer(3, GL_FLOAT, sizeof(StrandsMotionState), it_strand.state->co);
+			glNormalPointer(GL_FLOAT, sizeof(StrandsMotionState), it_strand.state->nor);
+		}
+		else {
+			glVertexPointer(3, GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->co);
+			glNormalPointer(GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->nor);
+		}
 		if ((dflag & DRAW_CONSTCOLOR) == 0) {
 //			if (part->draw_col == PART_DRAW_COL_MAT) {
 //				glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
diff --git a/source/blender/physics/BPH_mass_spring.h b/source/blender/physics/BPH_mass_spring.h
index 91014d6..1eaa20a 100644
--- a/source/blender/physics/BPH_mass_spring.h
+++ b/source/blender/physics/BPH_mass_spring.h
@@ -57,6 +57,7 @@ void BKE_cloth_solver_set_positions(struct ClothModifierData *clmd);
 
 bool BPH_cloth_solver_get_texture_data(struct Object *ob, struct ClothModifierData *clmd, struct VoxelData *vd);
 
+struct Implicit_Data *BPH_strands_solver_create(struct Strands *strands, struct StrandSimParams *params);
 bool BPH_strands_solve(struct Strands *strands, struct Implicit_Data *id, struct StrandSimParams *params, float frame, float frame_prev, struct Scene *scene, struct ListBase *effectors);
 
 #ifdef __cplusplus
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index a65be4d..2522dd9 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -1120,6 +1120,81 @@ bool BPH_cloth_solver_get_texture_data(Object *UNUSED(ob), ClothModifierData *cl
 
 /* ========================================================================= */
 
+struct Implicit_Data *BPH_strands_solver_create(struct Strands *strands, struct StrandSimParams *UNUSED(params))
+{
+	static float I3[3][3] = { {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f} };
+	
+	struct Implicit_Data *id;
+	int numverts = strands->totverts;
+	int numsprings = strands->totverts - strands->totcurves;
+	int i;
+	
+	id = BPH_mass_spring_solver_create(numverts, numsprings);
+	
+	for (i = 0; i < numverts; i++) {
+		// TODO define mass
+		float mass = 1.0f;
+		BPH_mass_spring_set_vertex_mass(id, i, mass);
+	}
+	
+	for (i = 0; i < numverts; i++) {
+		BPH_mass_spring_set_rest_transform(id, i, I3);
+		BPH_mass_spring_set_motion_state(id, i, strands->state[i].co, strands->state[i].vel);
+	}
+	
+	return id;
+}
+
+/* Init constraint matrix
+ * This is part of the modified CG method suggested by Baraff/Witkin in
+ * "Large Steps in Cloth Simulation" (Siggraph 1998)
+ */
+static void strands_setup_constraints(Strands *strands, Implicit_Data *data, ColliderContacts *contacts, int totcolliders, float dt)
+{
+	BPH_mass_spring_clear_constraints(data);
+	
+#if 0
+	for (v = 0; v < numverts; v++) {
+		if (verts[v].flags & CLOTH_VERT_FLAG_PINNED) {
+			/* pinned vertex constraints */
+			BPH_mass_spring_add_constraint_ndof0(data, v, ZERO); /* velocity is defined externally */
+		}
+		
+		verts[v].impulse_count = 0;
+	}
+#endif
+
+#if 0
+	for (i = 0; i < totcolliders; ++i) {
+		ColliderContacts *ct = &contacts[i];
+		for (j = 0; j < ct->totcollisions; ++j) {
+			CollPair *collpair = &ct->collisions[j];
+//			float restitution = (1.0f - clmd->coll_parms->damping) * (1.0f - ct->ob->pd->pdef_sbdamp);
+			float restitution = 0.0f;
+			int v = collpair->face1;
+			float impulse[3];
+			
+			/* pinned verts handled separately */
+			if (verts[v].flags & CLOTH_VERT_FLAG_PINNED)
+				continue;
+			
+			/* XXX cheap way of avoiding instability from multiple collisions in the same step
+			 * this should eventually be supported ...
+			 */
+			if (verts[v].impulse_count > 0)
+				continue;
+			
+			/* calculate collision response */
+			if (!collision_response(clmd, ct->collmd, collpair, dt, restitution, impulse))
+				continue;
+			
+			BPH_mass_spring_add_constraint_ndof2(data, v, collpair->normal, impulse);
+			++verts[v].impulse_count;
+		}
+	}
+#endif
+}
+
 /* Collect forces and derivatives:  F, dFdX, dFdV */
 static void strands_calc_force(Strands *strands, StrandSimParams *params, Implicit_Data *data, float UNUSED(frame), Scene *scene, ListBase *effectors, float step)
 {
@@ -1203,8 +1278,8 @@ bool BPH_strands_solve(Strands *strands, Implicit_Data *id, StrandSimParams *par
 	
 	int i;
 	float step;
-//	ColliderContacts *contacts = NULL;
-//	int totcolliders = 0;
+	ColliderContacts *contacts = NULL;
+	int totcolliders = 0;
 	
 //	if (!clmd->solver_result)
 //		clmd->solver_result = (ClothSolverResult *)MEM_callocN(sizeof(ClothSolverResult), "cloth solver result");
@@ -1233,17 +1308,15 @@ bool BPH_strands_solve(Strands *strands, Implicit_Data *id, StrandSimParams *par
 		ImplicitSolverResult result;
 		
 #if 0
-		if (is_hair) {
-			/* determine contact points */
-			if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) {
-				cloth_find_point_contacts(ob, clmd, 0.0f, tf, &contacts, &totcolliders);
-			}
-			
-			/* setup vertex constraints for pinned vertices and contacts */
-			cloth_setup_constraints(clmd, contacts, totcolliders, dt);
+		/* determine contact points */
+		if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) {
+			cloth_find_point_contacts(ob, clmd, 0.0f, tf, &contacts, &totcolliders);
 		}
 #endif
 		
+		/* setup vertex constraints for pinned vertices and contacts */
+		strands_setup_constraints(strands, id, contacts, totcolliders, dt);
+		
 		/* initialize forces to zero */
 		BPH_mass_spring_clear_forces(id);
 		
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp b/source/blender/pointcache/alembic/abc_particles.cpp
index 87dfc46..d3b4346 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -272,12 +272,12 @@ void AbcStrandsWriter::init_abc(OObject parent)
 	OCurvesSchema &schema = m_curves.getSchema();
 	OCompoundProperty geom_props = schema.getArbGeomParams();
 	
-	m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, 0);
-	m_param_weights = OFloatGeomParam(geom_props, "weights", false, kVertexScope, 1, 0);
+	m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, abc_archive()->frame_sampling());
+	m_param_weights = OFloatGeomParam(geom_props, "weights", false, kVertexScope, 1, abc_archive()->frame_sampling());
 	
-	m_param_motion_state = OCompoundProperty(geom_props, "motion_state");
-	m_param_motion_co = OP3fGeomParam(m_param_motion_state, "position", false, kVertexScope, 1, 0);
-	m_param_motion_vel = OV3fGeomParam(m_param_motion_state, "velocity", false, kVertexScope, 1, 0);
+	m_param_motion_state = OCompoundProperty(geom_props, "motion_state", abc_archive()->frame_sampling());
+	m_param_motion_co = OP3fGeomParam(m_param_motion_state, "position", false, kVertexScope, 1, abc_archive()->frame_sampling());
+	m_param_motion_vel = OV3fGeomParam(m_param_motion_state, "velocity", false, kVertexScope, 1, abc_archive()->frame_sampling());
 }
 
 static void strands_create_sample(Strands *strands, StrandsSample &sample, bool do_numverts)
@@ -350,7 +350,7 @@ void AbcStrandsWriter::write_sample()
 	m_param_times.set(OFloatGeomParam::Sample(FloatArraySample(strands_sample.times), kVertexScope));
 	m_param_weights.set(OFloatGeomParam::Sample(FloatArraySample(strands_sample.weights), kVertexScope));
 	
-	if (!strands->state) {
+	if (strands->state) {
 		m_param_motion_co.set(OP3fGeomParam::Sample(P3fArraySample(strands_sample.motion_co), kVertexScope));
 		m_param_motion_vel.set(OV3fGeomParam::Sample(V3fArraySample(strands_sample.motion_vel), kVertexScope));
 	}
@@ -438,11 +438,11 @@ PTCReadSampleResult AbcStrandsReader::read_sample(float frame)
 		IP3fGeomParam::Sample sample_motion_co = m_param_motion_co.getExpandedValue(ss);
 		IV3fGeomParam::Sample samp

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list