[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16717] trunk/blender/source: improved game soft bodies, works for objects that are using 'set smooth'

Erwin Coumans blender at erwincoumans.com
Thu Sep 25 05:02:33 CEST 2008


Revision: 16717
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16717
Author:   erwin
Date:     2008-09-25 05:02:30 +0200 (Thu, 25 Sep 2008)

Log Message:
-----------
improved game soft bodies, works for objects that are using 'set smooth'
use shape matching by default for game soft bodies
store soft body index for game vertices

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
    trunk/blender/source/gameengine/Rasterizer/RAS_TexVert.h

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2008-09-24 22:58:49 UTC (rev 16716)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2008-09-25 03:02:30 UTC (rev 16717)
@@ -967,7 +967,7 @@
 	ob->linearStiffness = 1.0f;
 	ob->angularStiffness = 1.0f;
 	ob->volumePreservation = 1.0f;
-	ob->gamesoftFlag = 0;
+	ob->gamesoftFlag = OB_SOFT_SHAPE_MATCHING;
 
 	/* NT fluid sim defaults */
 	ob->fluidsimFlag = 0;

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2008-09-24 22:58:49 UTC (rev 16716)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2008-09-25 03:02:30 UTC (rev 16717)
@@ -7853,6 +7853,7 @@
 			ob->linearStiffness = 1.0f;
 			ob->angularStiffness = 1.0f;
 			ob->volumePreservation = 1.0f;
+			ob->softflag = OB_SOFT_SHAPE_MATCHING;
 		}
 	}
 

Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2008-09-24 22:58:49 UTC (rev 16716)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2008-09-25 03:02:30 UTC (rev 16717)
@@ -1321,6 +1321,13 @@
 	objprop.m_dyna = (blenderobject->gameflag & OB_DYNAMIC) != 0;
 	objprop.m_softbody = (blenderobject->gameflag & OB_SOFT_BODY) != 0;
 	objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
+	
+	///for game soft bodies
+	objprop.m_linearStiffness = blenderobject->linearStiffness;
+	objprop.m_angularStiffness = blenderobject->angularStiffness;
+	objprop.m_volumePreservation = blenderobject->volumePreservation;
+	objprop.m_gamesoftFlag = blenderobject->gamesoftFlag;
+
 	objprop.m_ghost = (blenderobject->gameflag & OB_GHOST) != 0;
 	objprop.m_disableSleeping = (blenderobject->gameflag & OB_COLLISION_RESPONSE) != 0;//abuse the OB_COLLISION_RESPONSE flag
 	//mmm, for now, taks this for the size of the dynamicobject

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h	2008-09-24 22:58:49 UTC (rev 16716)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h	2008-09-25 03:02:30 UTC (rev 16717)
@@ -87,6 +87,12 @@
 	bool	m_disableSleeping;
 	bool	m_hasCompoundChildren;
 	bool	m_isCompoundChild;
+
+	float	m_linearStiffness;
+	float m_angularStiffness;
+	float	m_volumePreservation;
+	int		m_gamesoftFlag;
+	
 	double  m_margin;
 	KX_BoundBoxClass	m_boundclass;
 	union {

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2008-09-24 22:58:49 UTC (rev 16716)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2008-09-25 03:02:30 UTC (rev 16717)
@@ -667,6 +667,85 @@
 #endif //WIN32
 
 
+							
+	class KX_SoftBodyDeformer : public RAS_Deformer
+	{
+		btSoftBody*	m_softBody;
+		class RAS_MeshObject*	m_pMeshObject;
+		class BL_DeformableGameObject*	m_gameobj;
+
+
+	public:
+		KX_SoftBodyDeformer(btSoftBody* softBody,RAS_MeshObject*	pMeshObject,BL_DeformableGameObject*	gameobj)
+			: m_softBody(softBody),
+			m_pMeshObject(pMeshObject),
+			m_gameobj(gameobj)
+		{
+			//printf("KX_SoftBodyDeformer\n");
+		};
+
+		virtual ~KX_SoftBodyDeformer()
+		{
+			//printf("~KX_SoftBodyDeformer\n");
+		};
+		virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
+		{
+			//printf("relink\n");
+		}
+		virtual bool Apply(class RAS_IPolyMaterial *polymat)
+		{
+			//printf("apply\n");
+			RAS_MeshSlot::iterator it;
+			RAS_MeshMaterial *mmat;
+			RAS_MeshSlot *slot;
+			size_t i;
+
+			// update the vertex in m_transverts
+			Update();
+
+			// The vertex cache can only be updated for this deformer:
+			// Duplicated objects with more than one ploymaterial (=multiple mesh slot per object)
+			// share the same mesh (=the same cache). As the rendering is done per polymaterial
+			// cycling through the objects, the entire mesh cache cannot be updated in one shot.
+			mmat = m_pMeshObject->GetMeshMaterial(polymat);
+			if(!mmat->m_slots[(void*)m_gameobj])
+				return true;
+
+			slot = *mmat->m_slots[(void*)m_gameobj];
+
+			// for each array
+			for(slot->begin(it); !slot->end(it); slot->next(it)) 
+			{
+				btSoftBody::tNodeArray&   nodes(m_softBody->m_nodes);
+
+				int index = 0;
+				for(i=it.startvertex; i<it.endvertex; i++,index++) {
+					RAS_TexVert& v = it.vertex[i];
+
+					MT_Point3 pt (
+						nodes[v.getSoftBodyIndex()].m_x.getX(),
+						nodes[v.getSoftBodyIndex()].m_x.getY(),
+						nodes[v.getSoftBodyIndex()].m_x.getZ());
+					v.SetXYZ(pt);
+				}
+			}
+			return true;
+		}
+		virtual bool Update(void)
+		{
+			//printf("update\n");
+			return true;//??
+		}
+		virtual RAS_Deformer *GetReplica()
+		{
+			//printf("getReplica\n");
+			return 0;
+		}
+	protected:
+		//class RAS_MeshObject	*m_pMesh;
+	};
+
+
 // forward declarations
 
 void	KX_ConvertBulletObject(	class	KX_GameObject* gameobj,
@@ -916,6 +995,11 @@
 	ci.m_angularDamping = 1.f - shapeprops->m_ang_drag;
 	//need a bit of damping, else system doesn't behave well
 	ci.m_inertiaFactor = shapeprops->m_inertia/0.4f;//defaults to 0.4, don't want to change behaviour
+	ci.m_linearStiffness = objprop->m_linearStiffness;
+	ci.m_angularStiffness= objprop->m_angularStiffness;
+	ci.m_volumePreservation= objprop->m_volumePreservation;
+	ci.m_gamesoftFlag = objprop->m_gamesoftFlag;
+
 	ci.m_collisionFilterGroup = (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) : short(CcdConstructionInfo::StaticFilter);
 	ci.m_collisionFilterMask = (isbulletdyna) ? short(CcdConstructionInfo::AllFilter) : short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter);
 	ci.m_bRigid = objprop->m_dyna && objprop->m_angular_rigidbody;
@@ -990,107 +1074,15 @@
 
 	physicscontroller->SetObject(gameobj->GetSGNode());
 
-	class KX_SoftBodyDeformer : public RAS_Deformer
-	{
-		btSoftBody*	m_softBody;
-		class BL_SkinMeshObject*	m_pMeshObject;
-		class BL_DeformableGameObject*	m_gameobj;
 
-
-	public:
-		KX_SoftBodyDeformer(btSoftBody* softBody,BL_SkinMeshObject*	pMeshObject,BL_DeformableGameObject*	gameobj)
-			: m_softBody(softBody),
-			m_pMeshObject(pMeshObject),
-			m_gameobj(gameobj)
-		{
-			//printf("KX_SoftBodyDeformer\n");
-		};
-
-		virtual ~KX_SoftBodyDeformer()
-		{
-			//printf("~KX_SoftBodyDeformer\n");
-		};
-		virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
-		{
-			//printf("relink\n");
-		}
-		virtual bool Apply(class RAS_IPolyMaterial *polymat)
-		{
-			//printf("apply\n");
-			RAS_MeshSlot::iterator it;
-			RAS_MeshMaterial *mmat;
-			RAS_MeshSlot *slot;
-			size_t i;
-
-			// update the vertex in m_transverts
-			Update();
-
-			// The vertex cache can only be updated for this deformer:
-			// Duplicated objects with more than one ploymaterial (=multiple mesh slot per object)
-			// share the same mesh (=the same cache). As the rendering is done per polymaterial
-			// cycling through the objects, the entire mesh cache cannot be updated in one shot.
-			mmat = m_pMeshObject->GetMeshMaterial(polymat);
-			if(!mmat->m_slots[(void*)m_gameobj])
-				return true;
-
-			slot = *mmat->m_slots[(void*)m_gameobj];
-
-			// for each array
-			for(slot->begin(it); !slot->end(it); slot->next(it)) 
-			{
-				// for each vertex
-				// copy the untransformed data from the original mvert
-				int count = 0;
-				{
-
-					for(i=it.startvertex; i<it.endvertex; i++,count++)
-					{
-					}
-				}
-				btSoftBody::tNodeArray&   nodes(m_softBody->m_nodes);
-
-				if (count == m_softBody->m_userIndexMapping.size())
-				{
-					int index = 0;
-					for(i=it.startvertex; i<it.endvertex; i++,index++) {
-						RAS_TexVert& v = it.vertex[i];
-
-						MT_Point3 pt (
-							nodes[m_softBody->m_userIndexMapping[index]].m_x.getX(),
-							nodes[m_softBody->m_userIndexMapping[index]].m_x.getY(),
-							nodes[m_softBody->m_userIndexMapping[index]].m_x.getZ());
-						v.SetXYZ(pt);
-
-						//(m_transverts[v.getOrigIndex()]);
-					}
-				}
-
-			}
-
-			return true;
-		}
-		virtual bool Update(void)
-		{
-			//printf("update\n");
-			return true;//??
-		}
-		virtual RAS_Deformer *GetReplica()
-		{
-			//printf("getReplica\n");
-			return 0;
-		}
-	protected:
-		//class RAS_MeshObject	*m_pMesh;
-	};
-
 	///test for soft bodies
 	if (objprop->m_softbody && physicscontroller)
 	{
 		btSoftBody* softBody = physicscontroller->GetSoftBody();
-		if (softBody && gameobj->GetMesh(0))
+		if (softBody && gameobj->GetMesh(0))//only the first mesh, if any
 		{
 			//should be a mesh then, so add a soft body deformer
-			KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer(softBody, (BL_SkinMeshObject*)gameobj->GetMesh(0),(BL_DeformableGameObject*)gameobj);
+			KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer(softBody, gameobj->GetMesh(0),(BL_DeformableGameObject*)gameobj);
 			gameobj->SetDeformer(softbodyDeformer);
 			
 		}

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp	2008-09-24 22:58:49 UTC (rev 16716)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp	2008-09-25 03:02:30 UTC (rev 16717)
@@ -222,14 +222,57 @@
 					psb->appendFace(idx[0],idx[1],idx[2]);
 				}
 				
+				///create a mapping between graphics mesh vertices and soft body vertices
 				{
-					for (int i=0;i<hlib.m_vertexIndexMapping.size();i++)
-						psb->m_userIndexMapping.push_back(hlib.m_vertexIndexMapping[i]);
-						//psb->m_userIndexMapping.push_back(hres.m_Indices[i]);
+					RAS_MeshObject* rasMesh= GetShapeInfo()->GetMesh();
+
+					if (rasMesh)
+					{
+						
+						//printf("apply\n");
+						RAS_MeshSlot::iterator it;
+						RAS_MeshMaterial *mmat;
+						RAS_MeshSlot *slot;
+						size_t i;
+
+						//for each material
+						for (int m=0;m<rasMesh->NumMaterials();m++)
+						{
+							// The vertex cache can only be updated for this deformer:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list