[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46660] trunk/blender/source/blender: Cloth: Revert triangulation after talking with brecht.

Daniel Genrich daniel.genrich at gmx.net
Tue May 15 14:26:29 CEST 2012


Revision: 46660
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46660
Author:   genscher
Date:     2012-05-15 12:26:29 +0000 (Tue, 15 May 2012)
Log Message:
-----------
Cloth: Revert triangulation after talking with brecht. 

People: Better use subsurf after cloth since you can get failing collisions otherwise!

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_cloth.h
    trunk/blender/source/blender/blenkernel/intern/cloth.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/modifiers/intern/MOD_cloth.c

Modified: trunk/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_cloth.h	2012-05-15 12:25:26 UTC (rev 46659)
+++ trunk/blender/source/blender/blenkernel/BKE_cloth.h	2012-05-15 12:26:29 UTC (rev 46660)
@@ -211,7 +211,7 @@
 void cloth_free_modifier_extern (struct ClothModifierData *clmd );
 void cloth_free_modifier (struct ClothModifierData *clmd );
 void cloth_init (struct ClothModifierData *clmd );
-struct DerivedMesh *clothModifier_do (struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm);
+void clothModifier_do (struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]);
 
 int cloth_uses_vgroup(struct ClothModifierData *clmd);
 

Modified: trunk/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/cloth.c	2012-05-15 12:25:26 UTC (rev 46659)
+++ trunk/blender/source/blender/blenkernel/intern/cloth.c	2012-05-15 12:26:29 UTC (rev 46660)
@@ -93,7 +93,7 @@
 /* ********** cloth engine ******* */
 /* Prototypes for internal functions.
 */
-static void cloth_to_object (Object *ob,  ClothModifierData *clmd, DerivedMesh *dm);
+static void cloth_to_object (Object *ob,  ClothModifierData *clmd, float (*vertexCos)[3]);
 static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm );
 static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float framenr, int first);
 static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm );
@@ -419,7 +419,7 @@
 	return ret;
 }
 
-
+#if 0
 static DerivedMesh *cloth_to_triangles(DerivedMesh *dm)
 {
 	DerivedMesh *result = NULL;
@@ -472,18 +472,18 @@
 
 	return result;
 }
+#endif
 
 /************************************************
  * clothModifier_do - main simulation function
 ************************************************/
-DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm)
+void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3])
 {
 	PointCache *cache;
 	PTCacheID pid;
 	float timescale;
 	int framenr, startframe, endframe;
 	int cache_result;
-	DerivedMesh *result = NULL;
 
 	clmd->scene= scene;	/* nice to pass on later :) */
 	framenr= (int)scene->r.cfra;
@@ -503,7 +503,7 @@
 		BKE_ptcache_validate(cache, 0);
 		cache->last_exact= 0;
 		cache->flag &= ~PTCACHE_REDO_NEEDED;
-		return NULL;
+		return;
 	}
 	
 	// unused in the moment, calculated separately in implicit.c
@@ -515,21 +515,20 @@
 
 		/* do simulation */
 		if (!do_init_cloth(ob, clmd, dm, framenr))
-			return NULL;
+			return;
 
 		do_step_cloth(ob, clmd, dm, framenr);
-		result = cloth_to_triangles(dm);
-		cloth_to_object(ob, clmd, result);
+		cloth_to_object(ob, clmd, vertexCos);
 
 		clmd->clothObject->last_frame= framenr;
 
-		return result;
+		return;
 	}
 
 	/* simulation is only active during a specific period */
 	if (framenr < startframe) {
 		BKE_ptcache_invalidate(cache);
-		return NULL;
+		return;
 	}
 	else if (framenr > endframe) {
 		framenr= endframe;
@@ -537,7 +536,7 @@
 
 	/* initialize simulation data if it didn't exist already */
 	if (!do_init_cloth(ob, clmd, dm, framenr))
-		return NULL;
+		return;
 
 	if ((framenr == startframe) && (clmd->sim_parms->preroll == 0)) {
 		BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
@@ -545,7 +544,7 @@
 		BKE_ptcache_validate(cache, framenr);
 		cache->flag &= ~PTCACHE_REDO_NEEDED;
 		clmd->clothObject->last_frame= framenr;
-		return NULL;
+		return;
 	}
 
 	/* try to read from cache */
@@ -553,8 +552,7 @@
 
 	if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
 		implicit_set_positions(clmd);
-		result = cloth_to_triangles(dm);
-		cloth_to_object (ob, clmd, result);
+		cloth_to_object (ob, clmd, vertexCos);
 
 		BKE_ptcache_validate(cache, framenr);
 
@@ -563,7 +561,7 @@
 
 		clmd->clothObject->last_frame= framenr;
 
-		return result;
+		return;
 	}
 	else if (cache_result==PTCACHE_READ_OLD) {
 		implicit_set_positions(clmd);
@@ -571,11 +569,11 @@
 	else if ( /*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) { /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */
 		/* if baked and nothing in cache, do nothing */
 		BKE_ptcache_invalidate(cache);
-		return NULL;
+		return;
 	}
 
 	if (framenr!=clmd->clothObject->last_frame+1)
-		return NULL;
+		return;
 
 	/* if on second frame, write cache for first frame */
 	if (cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
@@ -592,11 +590,8 @@
 	else
 		BKE_ptcache_write(&pid, framenr);
 
-	result = cloth_to_triangles(dm);
-	cloth_to_object (ob, clmd, result);
+	cloth_to_object (ob, clmd, vertexCos);
 	clmd->clothObject->last_frame= framenr;
-
-	return result;
 }
 
 /* frees all */
@@ -743,19 +738,18 @@
  * cloth_to_object - copies the deformed vertices to the object.
  *
  **/
-static void cloth_to_object (Object *ob,  ClothModifierData *clmd, DerivedMesh *dm)
+static void cloth_to_object (Object *ob,  ClothModifierData *clmd, float (*vertexCos)[3])
 {
 	unsigned int	i = 0;
 	Cloth *cloth = clmd->clothObject;
-	MVert *verts = dm->getVertArray(dm);
 
 	if (clmd->clothObject) {
 		/* inverse matrix is not uptodate... */
 		invert_m4_m4(ob->imat, ob->obmat);
 
 		for (i = 0; i < cloth->numverts; i++) {
-			copy_v3_v3 (verts[i].co, cloth->verts[i].x);
-			mul_m4_v3(ob->imat, verts[i].co);	/* cloth is in global coords */
+			copy_v3_v3 (vertexCos[i], cloth->verts[i].x);
+			mul_m4_v3(ob->imat, vertexCos[i]);	/* cloth is in global coords */
 		}
 	}
 }

Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c	2012-05-15 12:25:26 UTC (rev 46659)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2012-05-15 12:26:29 UTC (rev 46660)
@@ -3555,7 +3555,6 @@
 {
 	ParticleSystem *psys = sim->psys;
 	DerivedMesh *dm = psys->hair_in_dm;
-	DerivedMesh *result = NULL;
 	MVert *mvert = NULL;
 	MEdge *medge = NULL;
 	MDeformVert *dvert = NULL;
@@ -3660,16 +3659,15 @@
 	psys->clmd->sim_parms->effector_weights = psys->part->effector_weights;
 
 	deformedVerts = MEM_callocN(sizeof(*deformedVerts)*dm->getNumVerts(dm), "do_hair_dynamics vertexCos");
+	psys->hair_out_dm = CDDM_copy(dm);
+	psys->hair_out_dm->getVertCos(psys->hair_out_dm, deformedVerts);
 
-	result = clothModifier_do(psys->clmd, sim->scene, sim->ob, dm);
+	clothModifier_do(psys->clmd, sim->scene, sim->ob, dm, deformedVerts);
 
-	if (result) {
-		CDDM_calc_normals(result);
-		psys->hair_out_dm = result;
-	}
-	else
-		psys->hair_out_dm = CDDM_copy(dm);
+	CDDM_apply_vert_coords(psys->hair_out_dm, deformedVerts);
 
+	MEM_freeN(deformedVerts);
+
 	psys->clmd->sim_parms->effector_weights = NULL;
 }
 static void hair_step(ParticleSimulationData *sim, float cfra)

Modified: trunk/blender/source/blender/modifiers/intern/MOD_cloth.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_cloth.c	2012-05-15 12:25:26 UTC (rev 46659)
+++ trunk/blender/source/blender/modifiers/intern/MOD_cloth.c	2012-05-15 12:26:29 UTC (rev 46660)
@@ -67,10 +67,10 @@
 	cloth_init(clmd);
 }
 
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
-								  DerivedMesh *dm,
-								  ModifierApplyFlag UNUSED(flag))
+static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3],
+                        int UNUSED(numVerts), ModifierApplyFlag UNUSED(flag))
 {
+	DerivedMesh *dm;
 	ClothModifierData *clmd = (ClothModifierData *) md;
 	DerivedMesh *result = NULL;
 	
@@ -79,20 +79,25 @@
 		initData(md);
 
 		if (!clmd->sim_parms || !clmd->coll_parms)
-			return dm;
+			return;
 	}
 
+	dm = get_dm(ob, NULL, derivedData, NULL, 0);
+	if (dm == derivedData)
+		dm = CDDM_copy(dm);
+
+	CDDM_apply_vert_coords(dm, vertexCos);
+
 	DM_ensure_tessface(dm); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */
 
-	result = clothModifier_do(clmd, md->scene, ob, dm);
+	clothModifier_do(clmd, md->scene, ob, dm, vertexCos);
 
-	if(result)
-	{
-		CDDM_calc_normals(result);
-		return result;
+	if (result) {
+		result->getVertCos(result, vertexCos);
+		result->release(result);
 	}
 
-	return dm;
+	dm->release(dm);
 }
 
 static void updateDepgraph(ModifierData *md, DagForest *forest, Scene *scene, Object *ob, DagNode *obNode)
@@ -200,17 +205,17 @@
 	/* name */              "Cloth",
 	/* structName */        "ClothModifierData",
 	/* structSize */        sizeof(ClothModifierData),
-	/* type */              eModifierTypeType_Constructive,
+	/* type */              eModifierTypeType_OnlyDeform,
 	/* flags */             eModifierTypeFlag_AcceptsMesh |
 	                        eModifierTypeFlag_UsesPointCache |
 	                        eModifierTypeFlag_Single,
 
 	/* copyData */          copyData,
-	/* deformVerts */       NULL,
+	/* deformVerts */       deformVerts,
 	/* deformMatrices */    NULL,
 	/* deformVertsEM */     NULL,
 	/* deformMatricesEM */  NULL,
-	/* applyModifier */     applyModifier,
+	/* applyModifier */     NULL,
 	/* applyModifierEM */   NULL,
 	/* initData */          initData,
 	/* requiredDataMask */  requiredDataMask,




More information about the Bf-blender-cvs mailing list