[f5d911f8b0d] blender2.8: Modifiers: ported Cloth DerivedMesh → Mesh

Sybren A. Stüvel noreply at git.blender.org
Tue May 22 17:11:35 CEST 2018


Commit: f5d911f8b0deb28d04737451adf355da80c792c3
Author: Sybren A. Stüvel
Date:   Fri May 18 17:32:22 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBf5d911f8b0deb28d04737451adf355da80c792c3

Modifiers: ported Cloth DerivedMesh → Mesh

The modifier is still quite slow; this could be due to caches being written
to a CoW datablock instead of the original one. More investigation is
needed.

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

M	source/blender/blenkernel/BKE_cloth.h
M	source/blender/blenkernel/intern/cloth.c
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/modifiers/intern/MOD_cloth.c

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

diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 94daf615054..d598923edbc 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -37,8 +37,8 @@
 
 struct Object;
 struct Scene;
+struct Mesh;
 struct MFace;
-struct DerivedMesh;
 struct ClothModifierData;
 struct CollisionModifierData;
 struct Depsgraph;
@@ -227,7 +227,7 @@ void cloth_free_contacts(ColliderContacts *collider_contacts, int totcolliders);
 void cloth_free_modifier_extern (struct ClothModifierData *clmd );
 void cloth_free_modifier (struct ClothModifierData *clmd );
 void cloth_init (struct ClothModifierData *clmd );
-void clothModifier_do(struct ClothModifierData *clmd, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]);
+void clothModifier_do(struct ClothModifierData *clmd, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Mesh *dm, float (*vertexCos)[3]);
 
 int cloth_uses_vgroup(struct ClothModifierData *clmd);
 
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index d769020503b..a39de284064 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -33,6 +33,7 @@
 #include "DNA_cloth_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
 #include "BLI_utildefines.h"
@@ -43,10 +44,11 @@
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
 
-#include "BKE_cdderivedmesh.h"
+#include "BKE_bvhutils.h"
 #include "BKE_cloth.h"
 #include "BKE_effect.h"
 #include "BKE_global.h"
+#include "BKE_mesh.h"
 #include "BKE_modifier.h"
 #include "BKE_pointcache.h"
 
@@ -58,13 +60,13 @@
 /* Prototypes for internal functions.
  */
 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 void cloth_from_mesh ( ClothModifierData *clmd, Mesh *mesh );
+static int cloth_from_object(Object *ob, ClothModifierData *clmd, Mesh *mesh, float framenr, int first);
 static void cloth_update_springs( ClothModifierData *clmd );
-static void cloth_update_verts( Object *ob, ClothModifierData *clmd, DerivedMesh *dm );
-static void cloth_update_spring_lengths( ClothModifierData *clmd, DerivedMesh *dm );
-static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm );
-static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm );
+static void cloth_update_verts( Object *ob, ClothModifierData *clmd, Mesh *mesh );
+static void cloth_update_spring_lengths( ClothModifierData *clmd, Mesh *mesh );
+static int cloth_build_springs ( ClothModifierData *clmd, Mesh *mesh );
+static void cloth_apply_vgroup ( ClothModifierData *clmd, Mesh *mesh );
 
 /******************************************************************************
  *
@@ -320,7 +322,7 @@ void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
 	BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_AFTER, framenr);
 }
 
-static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *result, int framenr)
+static int do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
 {
 	PointCache *cache;
 
@@ -348,7 +350,7 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
 	return 1;
 }
 
-static int do_step_cloth(struct Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, DerivedMesh *result, int framenr)
+static int do_step_cloth(struct Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
 {
 	ClothVertex *verts = NULL;
 	Cloth *cloth;
@@ -360,7 +362,7 @@ static int do_step_cloth(struct Depsgraph *depsgraph, Object *ob, ClothModifierD
 	/* simulate 1 frame forward */
 	cloth = clmd->clothObject;
 	verts = cloth->verts;
-	mvert = result->getVertArray(result);
+	mvert = result->mvert;
 
 	/* force any pinned verts to their constrained location. */
 	for (i = 0; i < clmd->clothObject->mvert_num; i++, verts++) {
@@ -403,7 +405,7 @@ static int do_step_cloth(struct Depsgraph *depsgraph, Object *ob, ClothModifierD
 /************************************************
  * clothModifier_do - main simulation function
  ************************************************/
-void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3])
+void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *mesh, float (*vertexCos)[3])
 {
 	PointCache *cache;
 	PTCacheID pid;
@@ -419,7 +421,7 @@ void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scen
 	BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale);
 	clmd->sim_parms->timescale= timescale * clmd->sim_parms->time_scale;
 
-	if (clmd->sim_parms->reset || (clmd->clothObject && dm->getNumVerts(dm) != clmd->clothObject->mvert_num)) {
+	if (clmd->sim_parms->reset || (clmd->clothObject && mesh->totvert != clmd->clothObject->mvert_num)) {
 		clmd->sim_parms->reset = 0;
 		cache->flag |= PTCACHE_OUTDATED;
 		BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
@@ -441,12 +443,12 @@ void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scen
 	}
 
 	/* initialize simulation data if it didn't exist already */
-	if (!do_init_cloth(ob, clmd, dm, framenr))
+	if (!do_init_cloth(ob, clmd, mesh, framenr))
 		return;
 
 	if (framenr == startframe) {
 		BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
-		do_init_cloth(ob, clmd, dm, framenr);
+		do_init_cloth(ob, clmd, mesh, framenr);
 		BKE_ptcache_validate(cache, framenr);
 		cache->flag &= ~PTCACHE_REDO_NEEDED;
 		clmd->clothObject->last_frame= framenr;
@@ -491,7 +493,7 @@ void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scen
 	/* do simulation */
 	BKE_ptcache_validate(cache, framenr);
 
-	if (!do_step_cloth(depsgraph, ob, clmd, dm, framenr)) {
+	if (!do_step_cloth(depsgraph, ob, clmd, mesh, framenr)) {
 		BKE_ptcache_invalidate(cache);
 	}
 	else
@@ -674,7 +676,7 @@ int cloth_uses_vgroup(ClothModifierData *clmd)
  *
  **/
 /* can be optimized to do all groups in one loop */
-static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
+static void cloth_apply_vgroup ( ClothModifierData *clmd, Mesh *mesh )
 {
 	int i = 0;
 	int j = 0;
@@ -684,11 +686,11 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
 	/* float goalfac = 0; */ /* UNUSED */
 	ClothVertex *verts = NULL;
 
-	if (!clmd || !dm) return;
+	if (!clmd || !mesh) return;
 
 	clothObj = clmd->clothObject;
 
-	mvert_num = dm->getNumVerts(dm);
+	mvert_num = mesh->totvert;
 
 	verts = clothObj->verts;
 	
@@ -708,7 +710,7 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
 			verts->flags &= ~CLOTH_VERT_FLAG_PINNED;
 			verts->flags &= ~CLOTH_VERT_FLAG_NOSELFCOLL;
 
-			dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT );
+			dvert = CustomData_get(&mesh->vdata, i, CD_MDEFORMVERT);
 			if ( dvert ) {
 				for ( j = 0; j < dvert->totweight; j++ ) {
 					if (( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) && (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )) {
@@ -774,7 +776,7 @@ static float cloth_shrink_factor(ClothModifierData *clmd, ClothVertex *verts, in
 		return 1.0f;
 }
 
-static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float UNUSED(framenr), int first)
+static int cloth_from_object(Object *ob, ClothModifierData *clmd, Mesh *mesh, float UNUSED(framenr), int first)
 {
 	int i = 0;
 	MVert *mvert = NULL;
@@ -804,25 +806,25 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 		return 0;
 	}
 
-	// mesh input objects need DerivedMesh
-	if ( !dm )
+	// mesh input objects need Mesh
+	if ( !mesh )
 		return 0;
 
-	cloth_from_mesh ( clmd, dm );
+	cloth_from_mesh ( clmd, mesh );
 
 	// create springs
 	clmd->clothObject->springs = NULL;
 	clmd->clothObject->numsprings = -1;
 
 	if ( clmd->sim_parms->shapekey_rest && !(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH ) )
-		shapekey_rest = dm->getVertDataArray ( dm, CD_CLOTH_ORCO );
+		shapekey_rest = CustomData_get_layer(&mesh->vdata, CD_CLOTH_ORCO);
 
-	mvert = dm->getVertArray (dm);
+	mvert = mesh->mvert;
 
 	verts = clmd->clothObject->verts;
 
 	// set initial values
-	for ( i = 0; i < dm->getNumVerts(dm); i++, verts++ ) {
+	for ( i = 0; i < mesh->totvert; i++, verts++ ) {
 		if (first) {
 			copy_v3_v3(verts->x, mvert[i].co);
 
@@ -860,9 +862,9 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 	
 	// apply / set vertex groups
 	// has to be happen before springs are build!
-	cloth_apply_vgroup (clmd, dm);
+	cloth_apply_vgroup (clmd, mesh);
 
-	if ( !cloth_build_springs ( clmd, dm ) ) {
+	if ( !cloth_build_springs ( clmd, mesh ) ) {
 		cloth_free_modifier ( clmd );
 		modifier_setError(&(clmd->modifier), "Cannot build springs");
 		printf("cloth_free_modifier cloth_build_springs\n");
@@ -877,7 +879,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 
 	clmd->clothObject->bvhtree = bvhtree_build_from_cloth ( clmd, MAX2(clmd->coll_parms->epsilon, clmd->coll_parms->distance_repel) );
 	
-	for (i = 0; i < dm->getNumVerts(dm); i++) {
+	for (i = 0; i < mesh->totvert; i++) {
 		maxdist = MAX2(maxdist, clmd->coll_parms->selfepsilon* ( cloth->verts[i].avg_spring_len*2.0f));
 	}
 	
@@ -886,12 +888,12 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 	return 1;
 }
 
-static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm )
+static void cloth_from_mesh ( ClothModifierData *clmd, Mesh *mesh )
 {
-	const MLoop *mloop = dm->getLoopArray(dm);
-	const MLoopTri *looptri = dm->getLoopTriArray(dm);
-	const unsigned int mvert_num = dm->getNumVerts(dm);
-	const unsigned int looptri_num = d

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list