[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27746] branches/render25: Render Branch: Cloth simulation can now use a group to specify which objects

Brecht Van Lommel brecht at blender.org
Thu Mar 25 15:58:41 CET 2010


Revision: 27746
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27746
Author:   blendix
Date:     2010-03-25 15:58:40 +0100 (Thu, 25 Mar 2010)

Log Message:
-----------
Render Branch: Cloth simulation can now use a group to specify which objects
to collide with, in addition to the effectors group.

Modified Paths:
--------------
    branches/render25/release/scripts/ui/properties_physics_cloth.py
    branches/render25/source/blender/blenkernel/BKE_collision.h
    branches/render25/source/blender/blenkernel/intern/collision.c
    branches/render25/source/blender/blenkernel/intern/effect.c
    branches/render25/source/blender/blenkernel/intern/implicit.c
    branches/render25/source/blender/blenkernel/intern/particle_system.c
    branches/render25/source/blender/blenkernel/intern/scene.c
    branches/render25/source/blender/blenloader/intern/readfile.c
    branches/render25/source/blender/makesdna/DNA_cloth_types.h
    branches/render25/source/blender/makesrna/intern/rna_cloth.c

Modified: branches/render25/release/scripts/ui/properties_physics_cloth.py
===================================================================
--- branches/render25/release/scripts/ui/properties_physics_cloth.py	2010-03-25 14:32:29 UTC (rev 27745)
+++ branches/render25/release/scripts/ui/properties_physics_cloth.py	2010-03-25 14:58:40 UTC (rev 27746)
@@ -179,6 +179,7 @@
         sub.prop(cloth, "self_collision_quality", slider=True, text="Quality")
         sub.prop(cloth, "self_min_distance", slider=True, text="Distance")
 
+        layout.prop(cloth, "group")
 
 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel):
     bl_label = "Cloth Stiffness Scaling"

Modified: branches/render25/source/blender/blenkernel/BKE_collision.h
===================================================================
--- branches/render25/source/blender/blenkernel/BKE_collision.h	2010-03-25 14:32:29 UTC (rev 27745)
+++ branches/render25/source/blender/blenkernel/BKE_collision.h	2010-03-25 14:58:40 UTC (rev 27746)
@@ -49,12 +49,13 @@
 
 #include "BLI_kdopbvh.h"
 
+struct Cloth;
+struct ClothModifierData;
+struct DerivedMesh;
+struct Group;
+struct MFace;
 struct Object;
 struct Scene;
-struct Cloth;
-struct MFace;
-struct DerivedMesh;
-struct ClothModifierData;
 
 ////////////////////////////////////////
 // used for collisions in collision.c
@@ -139,7 +140,7 @@
 /////////////////////////////////////////////////
 // used in effect.c
 /////////////////////////////////////////////////
-Object **get_collisionobjects(struct Scene *scene, Object *self, int *numcollobj);
+struct Object **get_collisionobjects(struct Scene *scene, struct Object *self, struct Group *group, int *numcollobj);
 
 typedef struct ColliderCache {
 	struct ColliderCache *next, *prev;
@@ -147,7 +148,7 @@
 	struct CollisionModifierData *collmd;
 } ColliderCache;
 
-struct ListBase *get_collider_cache(struct Scene *scene, Object *self);
+struct ListBase *get_collider_cache(struct Scene *scene, struct Object *self, struct Group *group);
 void free_collider_cache(struct ListBase **colliders);
 
 /////////////////////////////////////////////////

Modified: branches/render25/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/collision.c	2010-03-25 14:32:29 UTC (rev 27745)
+++ branches/render25/source/blender/blenkernel/intern/collision.c	2010-03-25 14:58:40 UTC (rev 27746)
@@ -1299,188 +1299,122 @@
 }
 #endif
 
-
-// return all collision objects in scene
-// collision object will exclude self 
-Object **get_collisionobjects(Scene *scene, Object *self, int *numcollobj)
+static void add_collision_object(Object ***objs, int *numobj, int *maxobj, Object *ob, Object *self, int level)
 {
-	Base *base=NULL;
-	Object **objs = NULL;
-	Object *coll_ob = NULL;
-	CollisionModifierData *collmd = NULL;
-	int numobj = 0, maxobj = 100;
+	CollisionModifierData *cmd= NULL;
+
+	if(ob == self)
+		return;
+
+	/* only get objects with collision modifier */
+	if(ob->pd && ob->pd->deflect)
+		cmd= (CollisionModifierData *)modifiers_findByType(ob, eModifierType_Collision);
 	
-	objs = MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray");
-	// check all collision objects
-	for ( base = scene->base.first; base; base = base->next )
-	{
-		/* object in same layer */
-		if(!(base->lay & self->lay)) 
-			continue;
-		
-		coll_ob = base->object;
-		
-		if(coll_ob == self)
-				continue;
-		
-		if(coll_ob->pd && coll_ob->pd->deflect)
-		{
-			collmd = ( CollisionModifierData * ) modifiers_findByType ( coll_ob, eModifierType_Collision );
+	if(cmd) {	
+		/* extend array */
+		if(*numobj >= *maxobj) {
+			*maxobj *= 2;
+			*objs= MEM_reallocN(*objs, sizeof(Object*)*(*maxobj));
 		}
-		else
-			collmd = NULL;
 		
-		if ( collmd )
-		{	
-			if(numobj >= maxobj)
-			{
-				// realloc
-				int oldmax = maxobj;
-				Object **tmp;
-				maxobj *= 2;
-				tmp = MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray");
-				memcpy(tmp, objs, sizeof(Object *)*oldmax);
-				MEM_freeN(objs);
-				objs = tmp;
-				
-			}
-			
-			objs[numobj] = coll_ob;
-			numobj++;
-		}
-		else
-		{
-			if ( coll_ob->dup_group )
-			{
-				GroupObject *go;
-				Group *group = coll_ob->dup_group;
+		(*objs)[*numobj] = ob;
+		(*numobj)++;
+	}
 
-				for ( go= group->gobject.first; go; go= go->next )
-				{
-					coll_ob = go->ob;
-					collmd = NULL;
-					
-					if(coll_ob == self)
-						continue;
-					
-					if(coll_ob->pd && coll_ob->pd->deflect)
-					{
-						collmd = ( CollisionModifierData * ) modifiers_findByType ( coll_ob, eModifierType_Collision );
-					}
-					else
-						collmd = NULL;
+	/* objects in dupli groups, one level only for now */
+	if(ob->dup_group && level == 0) {
+		GroupObject *go;
+		Group *group= ob->dup_group;
 
-					if ( !collmd )
-						continue;
-					
-					if( !collmd->bvhtree)
-						continue;
+		/* add objects */
+		for(go= group->gobject.first; go; go= go->next)
+			add_collision_object(objs, numobj, maxobj, go->ob, self, level+1);
+	}	
+}
 
-					if(numobj >= maxobj)
-					{
-						// realloc
-						int oldmax = maxobj;
-						Object **tmp;
-						maxobj *= 2;
-						tmp = MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray");
-						memcpy(tmp, objs, sizeof(Object *)*oldmax);
-						MEM_freeN(objs);
-						objs = tmp;
-					}
-					
-					objs[numobj] = coll_ob;
-					numobj++;
-				}
-			}
-		}	
+// return all collision objects in scene
+// collision object will exclude self 
+Object **get_collisionobjects(Scene *scene, Object *self, Group *group, int *numcollobj)
+{
+	Base *base;
+	Object **objs;
+	GroupObject *go;
+	int numobj= 0, maxobj= 100;
+	
+	objs= MEM_callocN(sizeof(Object *)*maxobj, "CollisionObjectsArray");
+
+	/* gather all collision objects */
+	if(group) {
+		/* use specified group */
+		for(go= group->gobject.first; go; go= go->next)
+			add_collision_object(&objs, &numobj, &maxobj, go->ob, self, 0);
 	}
-	*numcollobj = numobj;
+	else {
+		/* add objects in same layer in scene */
+		for(base = scene->base.first; base; base = base->next)
+			if(base->lay & self->lay) 
+				add_collision_object(&objs, &numobj, &maxobj, base->object, self, 0);
+	}
+
+	*numcollobj= numobj;
+
 	return objs;
 }
 
-ListBase *get_collider_cache(Scene *scene, Object *self)
+static void add_collider_cache_object(ListBase **objs, Object *ob, Object *self, int level)
 {
-	Base *base=NULL;
-	ListBase *objs = NULL;
-	Object *coll_ob = NULL;
-	CollisionModifierData *collmd = NULL;
+	CollisionModifierData *cmd= NULL;
 	ColliderCache *col;
-	
-	// check all collision objects
-	for ( base = scene->base.first; base; base = base->next )
-	{
-		/*Only proceed for mesh object in same layer */
-		if(base->object->type!=OB_MESH)
-			continue;
 
-		if(self && (base->lay & self->lay)==0) 
-			continue;
+	if(ob == self)
+		return;
 
-		
-		coll_ob = base->object;
-		
-		if(coll_ob == self)
-				continue;
-		
-		if(coll_ob->pd && coll_ob->pd->deflect)
-		{
-			collmd = ( CollisionModifierData * ) modifiers_findByType ( coll_ob, eModifierType_Collision );
-		}
-		else
-			collmd = NULL;
-		
-		if ( collmd )
-		{	
-			if(objs == NULL)
-				objs = MEM_callocN(sizeof(ListBase), "ColliderCache array");
+	if(ob->pd && ob->pd->deflect)
+		cmd =(CollisionModifierData *)modifiers_findByType(ob, eModifierType_Collision);
+	
+	if(cmd && cmd->bvhtree) {	
+		if(*objs == NULL)
+			*objs = MEM_callocN(sizeof(ListBase), "ColliderCache array");
 
-			col = MEM_callocN(sizeof(ColliderCache), "ColliderCache");
-			col->ob = coll_ob;
-			col->collmd = collmd;
-			/* make sure collider is properly set up */
-			collision_move_object(collmd, 1.0, 0.0);
-			BLI_addtail(objs, col);
-		}
-		else if ( coll_ob->dup_group )
-			{
-				GroupObject *go;
-				Group *group = coll_ob->dup_group;
+		col = MEM_callocN(sizeof(ColliderCache), "ColliderCache");
+		col->ob = ob;
+		col->collmd = cmd;
+		/* make sure collider is properly set up */
+		collision_move_object(cmd, 1.0, 0.0);
+		BLI_addtail(*objs, col);
+	}
 
-				for ( go= group->gobject.first; go; go= go->next )
-				{
-					coll_ob = go->ob;
-					collmd = NULL;
-					
-					if(coll_ob == self)
-						continue;
-					
-					if(coll_ob->pd && coll_ob->pd->deflect)
-					{
-						collmd = ( CollisionModifierData * ) modifiers_findByType ( coll_ob, eModifierType_Collision );
-					}
-					else
-						collmd = NULL;
+	/* objects in dupli groups, one level only for now */
+	if(ob->dup_group && level == 0) {
+		GroupObject *go;
+		Group *group= ob->dup_group;
 
-					if ( !collmd )
-						continue;
-					
-					if( !collmd->bvhtree)
-						continue;
+		/* add objects */
+		for(go= group->gobject.first; go; go= go->next)
+			add_collider_cache_object(objs, go->ob, self, level+1);
+	}
+}
 
-					if(objs == NULL)
-						objs = MEM_callocN(sizeof(ListBase), "ColliderCache array");
-
-					col = MEM_callocN(sizeof(ColliderCache), "ColliderCache");
-					col->ob = coll_ob;
-					col->collmd = collmd;
-					/* make sure collider is properly set up */
-					collision_move_object(collmd, 1.0, 0.0);
-					BLI_addtail(objs, col);
-				}
-			}
+ListBase *get_collider_cache(Scene *scene, Object *self, Group *group)
+{
+	Base *base;
+	GroupObject *go;
+	ListBase *objs= NULL;
+	
+	/* add object in same layer in scene */
+	if(group) {
+		for(go= group->gobject.first; go; go= go->next)
+			add_collider_cache_object(&objs, go->ob, self, 0);
 	}
+	else {
+		for(base = scene->base.first; base; base = base->next)
+			if(self && (base->lay & self->lay)==0) 
+				add_collider_cache_object(&objs, base->object, self, 0);
+	}
+
 	return objs;
 }
+
 void free_collider_cache(ListBase **colliders)
 {
 	if(*colliders) {
@@ -1489,6 +1423,7 @@
 		*colliders = NULL;
 	}
 }
+
 static void cloth_bvh_objcollisions_nearcheck ( ClothModifierData * clmd, CollisionModifierData *collmd, CollPair **collisions, CollPair **collisions_index, int numresult, BVHTreeOverlap *overlap)
 {
 	int i;
@@ -1574,7 +1509,7 @@
 	bvhtree_update_from_cloth ( clmd, 1 ); // 0 means STATIC, 1 means MOVING (see later in this function)
 	bvhselftree_update_from_cloth ( clmd, 0 ); // 0 means STATIC, 1 means MOVING (see later in this function)
 	
-	collobjs = get_collisionobjects(clmd->scene, ob, &numcollobj);
+	collobjs = get_collisionobjects(clmd->scene, ob, clmd->coll_parms->group, &numcollobj);
 	
 	if(!collobjs)
 		return 0;

Modified: branches/render25/source/blender/blenkernel/intern/effect.c
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list