[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43732] trunk/blender/source/blender: Fix #29957: Texture "Generate" mapping work as global with cloth modifier

Sergey Sharybin sergey.vfx at gmail.com
Thu Jan 26 18:03:41 CET 2012


Revision: 43732
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43732
Author:   nazgul
Date:     2012-01-26 17:03:30 +0000 (Thu, 26 Jan 2012)
Log Message:
-----------
Fix #29957: Texture "Generate" mapping work as global with cloth modifier

Make Cloth modifier deformation only so now it applies on orco dm properly.

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-01-26 15:37:33 UTC (rev 43731)
+++ trunk/blender/source/blender/blenkernel/BKE_cloth.h	2012-01-26 17:03:30 UTC (rev 43732)
@@ -216,7 +216,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]);
 
 void cloth_update_normals ( ClothVertex *verts, int nVerts, struct MFace *face, int totface );
 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-01-26 15:37:33 UTC (rev 43731)
+++ trunk/blender/source/blender/blenkernel/intern/cloth.c	2012-01-26 17:03:30 UTC (rev 43732)
@@ -90,7 +90,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 );
@@ -429,9 +429,8 @@
 /************************************************
  * 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])
 {
-	DerivedMesh *result;
 	PointCache *cache;
 	PTCacheID pid;
 	float timescale;
@@ -441,20 +440,14 @@
 	clmd->scene= scene;	/* nice to pass on later :) */
 	framenr= (int)scene->r.cfra;
 	cache= clmd->point_cache;
-	result = CDDM_copy(dm);
 
 	BKE_ptcache_id_from_cloth(&pid, ob, clmd);
 	BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale);
 	clmd->sim_parms->timescale= timescale;
 
-	if(!result) {
-		BKE_ptcache_invalidate(cache);
-		return dm;
-	}
-
 	if(clmd->sim_parms->reset
 		|| (framenr == (startframe - clmd->sim_parms->preroll) && clmd->sim_parms->preroll != 0)
-		|| (clmd->clothObject && result->getNumVerts(result) != clmd->clothObject->numverts))
+		|| (clmd->clothObject && dm->getNumVerts(dm) != clmd->clothObject->numverts))
 	{
 		clmd->sim_parms->reset = 0;
 		cache->flag |= PTCACHE_OUTDATED;
@@ -462,7 +455,7 @@
 		BKE_ptcache_validate(cache, 0);
 		cache->last_exact= 0;
 		cache->flag &= ~PTCACHE_REDO_NEEDED;
-		return result;
+		return;
 	}
 	
 	// unused in the moment, calculated separately in implicit.c
@@ -474,20 +467,20 @@
 
 		/* do simulation */
 		if(!do_init_cloth(ob, clmd, dm, framenr))
-			return result;
+			return;
 
 		do_step_cloth(ob, clmd, dm, framenr);
-		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 result;
+		return;
 	}
 	else if(framenr > endframe) {
 		framenr= endframe;
@@ -495,7 +488,7 @@
 
 	/* initialize simulation data if it didn't exist already */
 	if(!do_init_cloth(ob, clmd, dm, framenr))
-		return result;
+		return;
 
 	if((framenr == startframe) && (clmd->sim_parms->preroll == 0)) {
 		BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
@@ -503,7 +496,7 @@
 		BKE_ptcache_validate(cache, framenr);
 		cache->flag &= ~PTCACHE_REDO_NEEDED;
 		clmd->clothObject->last_frame= framenr;
-		return result;
+		return;
 	}
 
 	/* try to read from cache */
@@ -511,7 +504,7 @@
 
 	if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
 		implicit_set_positions(clmd);
-		cloth_to_object (ob, clmd, result);
+		cloth_to_object (ob, clmd, vertexCos);
 
 		BKE_ptcache_validate(cache, framenr);
 
@@ -520,7 +513,7 @@
 
 		clmd->clothObject->last_frame= framenr;
 
-		return result;
+		return;
 	}
 	else if(cache_result==PTCACHE_READ_OLD) {
 		implicit_set_positions(clmd);
@@ -528,11 +521,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 result;
+		return;
 	}
 
 	if(framenr!=clmd->clothObject->last_frame+1)
-		return result;
+		return;
 
 	/* if on second frame, write cache for first frame */
 	if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
@@ -549,10 +542,8 @@
 	else
 		BKE_ptcache_write(&pid, framenr);
 
-	cloth_to_object (ob, clmd, result);
+	cloth_to_object (ob, clmd, vertexCos);
 	clmd->clothObject->last_frame= framenr;
-
-	return result;
 }
 
 /* frees all */
@@ -707,24 +698,19 @@
  * 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;
-	MVert *mvert = NULL;
-	unsigned int numverts;
 	Cloth *cloth = clmd->clothObject;
 
 	if (clmd->clothObject) {
 		/* inverse matrix is not uptodate... */
 		invert_m4_m4(ob->imat, ob->obmat);
 
-		mvert = CDDM_get_verts(dm);
-		numverts = dm->getNumVerts(dm);
-
-		for (i = 0; i < numverts; i++)
+		for (i = 0; i < cloth->numverts; i++)
 		{
-			copy_v3_v3 (mvert[i].co, cloth->verts[i].x);
-			mul_m4_v3(ob->imat, mvert[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-01-26 15:37:33 UTC (rev 43731)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2012-01-26 17:03:30 UTC (rev 43732)
@@ -3480,6 +3480,7 @@
 	int totedge;
 	int k;
 	float hairmat[4][4];
+	float (*deformedVerts)[3];
 
 	if(!psys->clmd) {
 		psys->clmd = (ClothModifierData*)modifier_new(eModifierType_Cloth);
@@ -3573,8 +3574,16 @@
 	psys->clmd->point_cache = psys->pointcache;
 	psys->clmd->sim_parms->effector_weights = psys->part->effector_weights;
 
-	psys->hair_out_dm = clothModifier_do(psys->clmd, sim->scene, sim->ob, dm);
+	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);
 
+	clothModifier_do(psys->clmd, sim->scene, sim->ob, dm, deformedVerts);
+
+	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-01-26 15:37:33 UTC (rev 43731)
+++ trunk/blender/source/blender/modifiers/intern/MOD_cloth.c	2012-01-26 17:03:30 UTC (rev 43732)
@@ -67,11 +67,10 @@
 	cloth_init (clmd);
 }
 
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
-						DerivedMesh *dm,
-						int UNUSED(useRenderParams),
-						int UNUSED(isFinalCalc))
+static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3],
+			int UNUSED(numVerts), int UNUSED(useRenderParams), int UNUSED(isFinalCalc))
 {
+	DerivedMesh *dm;
 	ClothModifierData *clmd = (ClothModifierData*) md;
 	DerivedMesh *result=NULL;
 	
@@ -79,19 +78,22 @@
 	if(!clmd->sim_parms || !clmd->coll_parms)
 	{
 		initData(md);
-		
+
 		if(!clmd->sim_parms || !clmd->coll_parms)
-			return dm;
+			return;
 	}
 
-	result = clothModifier_do(clmd, md->scene, ob, dm);
+	dm = get_dm(ob, NULL, derivedData, NULL, 0);
 
-	if(result)
-	{
-		CDDM_calc_normals(result);
-		return result;
+	clothModifier_do(clmd, md->scene, ob, dm, vertexCos);
+
+	if(result) {
+		result->getVertCos(result, vertexCos);
+		result->release(result);
 	}
-	return dm;
+
+	if(dm != derivedData)
+		dm->release(dm);
 }
 
 static void updateDepgraph(
@@ -206,17 +208,17 @@
 	/* name */              "Cloth",
 	/* structName */        "ClothModifierData",
 	/* structSize */        sizeof(ClothModifierData),
-	/* type */              eModifierTypeType_Nonconstructive,
+	/* 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