[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16204] trunk/blender: BGE bug #17491 fixed: BGE, Dupli instance with different scale, massive slowdown.

Benoit Bolsee benoit.bolsee at online.be
Thu Aug 21 17:19:57 CEST 2008


Revision: 16204
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16204
Author:   ben2610
Date:     2008-08-21 17:19:54 +0200 (Thu, 21 Aug 2008)

Log Message:
-----------
BGE bug #17491 fixed: BGE, Dupli instance with different scale, massive slowdown.

The root cause of this bug is the fact that Bullet shapes 
are shared between duplicated game objects. As the physics
object scale is stored in the shape, all duplicas must 
have the same scale otherwise the physics representation
is incorrect.
This fix introduces a mechanism to duplicate shapes at
runtime so that Bullet shapes are not shared anymore.
The drawback is an increased memory consuption. 
A reference count mechanism will be introduced in a 
later revision to keep Bullet shape shared between
duplicas that have the same scale.

Modified Paths:
--------------
    trunk/blender/projectfiles_vc7/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/common/PHY_DynamicTypes.h

Modified: trunk/blender/projectfiles_vc7/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj
===================================================================
--- trunk/blender/projectfiles_vc7/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj	2008-08-21 14:07:24 UTC (rev 16203)
+++ trunk/blender/projectfiles_vc7/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj	2008-08-21 15:19:54 UTC (rev 16204)
@@ -151,7 +151,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="..\..\..\..\..\..\build\msvc_7\intern\moto\include;..\..\..\..\..\..\build\msvc_7\extern\bullet\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet"
+				AdditionalIncludeDirectories="..\..\..\..\..\..\build\msvc_7\intern\moto\include;..\..\..\..\..\..\build\msvc_7\intern\string\include;..\..\..\..\..\..\build\msvc_7\extern\bullet\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\kernel\gen_system"
 				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
 				MinimalRebuild="FALSE"
 				BasicRuntimeChecks="3"

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2008-08-21 14:07:24 UTC (rev 16203)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2008-08-21 15:19:54 UTC (rev 16204)
@@ -680,189 +680,7 @@
 
 
 // forward declarations
-static btCollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool polytope)
-{
-	if (!meshobj)
-		return 0;
 
-	btCollisionShape* collisionMeshShape = 0;
-	btConvexHullShape* convexHullShape = 0;
-	btTriangleMeshShape* concaveShape = 0;
-
-	btTriangleMesh* collisionMeshData = 0;
-
-	//see if there is any polygons, if not, bail out.
-
-	int numPoints = 0;
-	btVector3* points = 0;
-
-	// Mesh has no polygons!
-	int numpolys = meshobj->NumPolygons();
-	if (!numpolys)
-	{
-		return NULL;
-	}
-
-	// Count the number of collision polygons and check they all come from the same 
-	// vertex array
-	int numvalidpolys = 0;
-	int vtxarray = -1;
-	RAS_IPolyMaterial *poly_material = NULL;
-	bool reinstance = true;
-
-	for (int p=0; p<numpolys; p++)
-	{
-		RAS_Polygon* poly = meshobj->GetPolygon(p);
-
-		// only add polygons that have the collisionflag set
-		if (poly->IsCollider())
-		{
-			// check polygon is from the same vertex array
-			if (poly->GetVertexIndexBase().m_vtxarray != vtxarray)
-			{
-				if (vtxarray < 0)
-					vtxarray = poly->GetVertexIndexBase().m_vtxarray;
-				else
-				{
-					reinstance = false;
-					vtxarray = -1;
-				}
-			}
-
-			// check poly is from the same material
-			if (poly->GetMaterial()->GetPolyMaterial() != poly_material)
-			{
-				if (poly_material)
-				{
-					reinstance = false;
-					poly_material = NULL;
-				}
-				else
-					poly_material = poly->GetMaterial()->GetPolyMaterial();
-			}
-
-			// count the number of collision polys
-			numvalidpolys++;
-
-			// We have one collision poly, and we can't reinstance, so we
-			// might as well break here.
-			if (!reinstance)
-				break;
-		}
-	}
-
-	// No collision polygons
-	if (numvalidpolys < 1)
-		return NULL;
-
-
-	if (polytope)
-	{
-		convexHullShape = new btConvexHullShape(&points[0].getX(),numPoints);
-		collisionMeshShape = convexHullShape;
-	} else
-	{
-		collisionMeshData = new btTriangleMesh();
-//		concaveShape = new btTriangleMeshShape(collisionMeshData);
-		//collisionMeshShape = concaveShape;
-
-	}
-
-
-	numvalidpolys = 0;
-
-	for (int p2=0; p2<numpolys; p2++)
-	{
-		RAS_Polygon* poly = meshobj->GetPolygon(p2);
-
-		// only add polygons that have the collisionflag set
-		if (poly->IsCollider())
-		{   
-			//Bullet can raycast any shape, so
-			if (polytope)
-			{
-				for (int i=0;i<poly->VertexCount();i++)
-				{
-					const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
-						poly->GetVertexIndexBase().m_indexarray[i],
-						poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
-					btPoint3 point(vtx[0],vtx[1],vtx[2]);
-					convexHullShape->addPoint(point);
-				}
-				if (poly->VertexCount())
-					numvalidpolys++;
-
-			} else
-			{
-				{
-					const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
-						poly->GetVertexIndexBase().m_indexarray[2],
-						poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
-					btPoint3 vertex0(vtx[0],vtx[1],vtx[2]);
-					vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
-						poly->GetVertexIndexBase().m_indexarray[1],
-						poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
-					btPoint3 vertex1(vtx[0],vtx[1],vtx[2]);
-					vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
-						poly->GetVertexIndexBase().m_indexarray[0],
-						poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
-					btPoint3 vertex2(vtx[0],vtx[1],vtx[2]);
-					collisionMeshData->addTriangle(vertex0,vertex1,vertex2);
-					numvalidpolys++;
-				}
-				if (poly->VertexCount() == 4)
-				{
-					const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
-						poly->GetVertexIndexBase().m_indexarray[3],
-						poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
-					btPoint3 vertex0(vtx[0],vtx[1],vtx[2]);
-					vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
-						poly->GetVertexIndexBase().m_indexarray[2],
-						poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
-					btPoint3 vertex1(vtx[0],vtx[1],vtx[2]);
-					vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
-						poly->GetVertexIndexBase().m_indexarray[0],
-						poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
-					btPoint3 vertex2(vtx[0],vtx[1],vtx[2]);
-					collisionMeshData->addTriangle(vertex0,vertex1,vertex2);
-					numvalidpolys++;
-				}
-
-			}		
-		}
-	}
-
-
-
-	if (numvalidpolys > 0)
-	{
-		
-		if (!polytope)
-		{
-			bool useQuantization = true;
-			concaveShape = new btBvhTriangleMeshShape( collisionMeshData, useQuantization );
-			//concaveShape = new btTriangleMeshShape( collisionMeshData );
-
-			concaveShape->recalcLocalAabb();
-			if (collisionMeshShape)
-				delete collisionMeshShape;
-			collisionMeshShape = concaveShape;
-
-		} 
-		
-		
-
-		return collisionMeshShape;
-	}
-	if (collisionMeshShape)
-		delete collisionMeshShape;
-	if (collisionMeshData)
-		delete collisionMeshData;
-	return NULL;
-
-}
-
-
 void	KX_ConvertBulletObject(	class	KX_GameObject* gameobj,
 	class	RAS_MeshObject* meshobj,
 	class	KX_Scene* kxscene,
@@ -878,6 +696,7 @@
 	bool isbulletdyna = false;
 	CcdConstructionInfo ci;
 	class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
+	class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo();
 
 	
 
@@ -894,120 +713,80 @@
 	ci.m_gravity = btVector3(0,0,0);
 	ci.m_localInertiaTensor =btVector3(0,0,0);
 	ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f;
+	shapeInfo->m_radius = objprop->m_radius;
 	isbulletdyna = objprop->m_dyna;
 	
 	ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
 	
-	btTransform trans;
-	trans.setIdentity();
-	
 	btCollisionShape* bm = 0;
 
 	switch (objprop->m_boundclass)
 	{
 	case KX_BOUNDSPHERE:
 		{
-			float radius = objprop->m_radius;
-			btVector3 inertiaHalfExtents (
-				radius,
-				radius,
-				radius);
+			//float radius = objprop->m_radius;
+			//btVector3 inertiaHalfExtents (
+			//	radius,
+			//	radius,
+			//	radius);
 			
 			//blender doesn't support multisphere, but for testing:
 
 			//bm = new MultiSphereShape(inertiaHalfExtents,,&trans.getOrigin(),&radius,1);
-			bm = new btSphereShape(objprop->m_radius);
-			bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+			shapeInfo->m_shapeType = PHY_SHAPE_SPHERE;
+			bm = shapeInfo->CreateBulletShape();
 			break;
 		};
 	case KX_BOUNDBOX:
 		{
-			MT_Vector3 halfExtents (
+			shapeInfo->m_halfExtend.setValue(
 				objprop->m_boundobject.box.m_extends[0],
-			objprop->m_boundobject.box.m_extends[1],
-			objprop->m_boundobject.box.m_extends[2]);
+				objprop->m_boundobject.box.m_extends[1],
+				objprop->m_boundobject.box.m_extends[2]);
 
-			halfExtents /= 2.f;
-
-			//btVector3 he (halfExtents[0]-CONVEX_DISTANCE_MARGIN ,halfExtents[1]-CONVEX_DISTANCE_MARGIN ,halfExtents[2]-CONVEX_DISTANCE_MARGIN );
-			//he = he.absolute();
-
-			btVector3 he (halfExtents[0],halfExtents[1],halfExtents[2]);
-			he = he.absolute();
-
-
-			bm = new btBoxShape(he);
-			bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+			shapeInfo->m_halfExtend /= 2.0;
+			shapeInfo->m_halfExtend = shapeInfo->m_halfExtend.absolute();
+			shapeInfo->m_shapeType = PHY_SHAPE_BOX;
+			bm = shapeInfo->CreateBulletShape();
 			break;
 		};
 	case KX_BOUNDCYLINDER:
 		{
-			btVector3 halfExtents (
+			shapeInfo->m_halfExtend.setValue(
 				objprop->m_boundobject.c.m_radius,
 				objprop->m_boundobject.c.m_radius,
 				objprop->m_boundobject.c.m_height * 0.5f
 			);
-			bm = new btCylinderShapeZ(halfExtents);
-			bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
-
+			shapeInfo->m_shapeType = PHY_SHAPE_CYLINDER;
+			bm = shapeInfo->CreateBulletShape();
 			break;
 		}
 
-		case KX_BOUNDCONE:
+	case KX_BOUNDCONE:
 		{
-				btVector3 halfExtents (objprop->m_boundobject.box.m_extends[0],
-				objprop->m_boundobject.box.m_extends[1],
-				objprop->m_boundobject.box.m_extends[2]);
-
-
-				halfExtents /= 2.f;
-
-				bm = new btConeShapeZ(objprop->m_boundobject.c.m_radius,objprop->m_boundobject.c.m_height);
-				bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
-
+			shapeInfo->m_radius = objprop->m_boundobject.c.m_radius;
+			shapeInfo->m_height = objprop->m_boundobject.c.m_height;
+			shapeInfo->m_shapeType = PHY_SHAPE_CONE;
+			bm = shapeInfo->CreateBulletShape();
 			break;
 		}
-		case KX_BOUNDPOLYTOPE:
-			{
-				bm = CreateBulletShapeFromMesh(meshobj,true);
-				if (bm)
-				{
-					bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
-				}
-				break;
-			}
-		case KX_BOUNDMESH:
-			{
-				if (!ci.m_mass)
-				{				
-					bm = CreateBulletShapeFromMesh(meshobj,false);
-					ci.m_localInertiaTensor.setValue(0.f,0.f,0.f);
-					//no moving concave meshes, so don't bother calculating inertia
-					//bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
-				}
-
-				break;
-			}
-
-	default:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list