diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index 273b885f407..60b4f6a51b6 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -402,6 +402,7 @@ extern Object workob; #define OB_BOUND_POLYH 4 #define OB_BOUND_POLYT 5 #define OB_BOUND_DYN_MESH 6 +#define OB_BOUND_CAPSULE 7 /* **************** BASE ********************* */ @@ -564,4 +565,3 @@ typedef enum ObjectMode { #endif - diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 17074c7ec83..a6f99d01936 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -76,6 +76,7 @@ static EnumPropertyItem collision_bounds_items[] = { {OB_BOUND_CONE, "CONE", 0, "Cone", ""}, {OB_BOUND_POLYT, "CONVEX_HULL", 0, "Convex Hull", ""}, {OB_BOUND_POLYH, "TRIANGLE_MESH", 0, "Triangle Mesh", ""}, + {OB_BOUND_CAPSULE, "CAPSULE", 0, "Capsule", ""}, //{OB_DYN_MESH, "DYNAMIC_MESH", 0, "Dynamic Mesh", ""}, {0, NULL, 0, NULL, NULL}}; @@ -384,6 +385,7 @@ static EnumPropertyItem *rna_Object_collision_bounds_itemf(bContext *C, PointerR RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_CYLINDER); RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_SPHERE); RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_BOX); + RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_CAPSULE); } RNA_enum_item_end(&item, &totitem); @@ -1599,6 +1601,7 @@ static void rna_def_object(BlenderRNA *brna) {OB_BOUND_CYLINDER, "CYLINDER", 0, "Cylinder", ""}, {OB_BOUND_CONE, "CONE", 0, "Cone", ""}, {OB_BOUND_POLYH, "POLYHEDRON", 0, "Polyhedron", ""}, + {OB_BOUND_CAPSULE, "CAPSULE", 0, "Capsule", ""}, {0, NULL, 0, NULL, NULL}}; static EnumPropertyItem dupli_items[] = { @@ -2231,4 +2234,3 @@ void RNA_def_object(BlenderRNA *brna) } #endif - diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index fa32cfdb866..d34e86fd556 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1570,6 +1570,15 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, objprop.m_boundobject.c.m_height = 2.f*bb.m_extends[2]; break; } + case OB_BOUND_CAPSULE: + { + objprop.m_boundclass = KX_BOUNDCAPSULE; + objprop.m_boundobject.c.m_radius = MT_max(bb.m_extends[0], bb.m_extends[1]); + objprop.m_boundobject.c.m_height = 2.f*(bb.m_extends[2]-objprop.m_boundobject.c.m_radius); + if (objprop.m_boundobject.c.m_height < 0.f) + objprop.m_boundobject.c.m_height = 0.f; + break; + } } } diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index 879bcd472c6..ca20aa6b618 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -53,7 +53,8 @@ typedef enum { KX_BOUNDCONE, KX_BOUNDMESH, KX_BOUNDPOLYTOPE, - KX_BOUND_DYN_MESH + KX_BOUND_DYN_MESH, + KX_BOUNDCAPSULE } KX_BoundBoxClass; struct KX_BoxBounds @@ -168,4 +169,3 @@ bool KX_ReInstanceBulletShapeFromMesh(KX_GameObject *gameobj, KX_GameObject *fro #endif #endif //KX_CONVERTPHYSICSOBJECTS - diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 44ae032179b..d889c6386cd 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -184,6 +184,14 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, bm = shapeInfo->CreateBulletShape(ci.m_margin); break; } + case KX_BOUNDCAPSULE: + { + shapeInfo->m_radius = objprop->m_boundobject.c.m_radius; + shapeInfo->m_height = objprop->m_boundobject.c.m_height; + shapeInfo->m_shapeType = PHY_SHAPE_CAPSULE; + bm = shapeInfo->CreateBulletShape(ci.m_margin); + break; + } case KX_BOUNDMESH: { // mesh shapes can be shared, check first if we already have a shape on that mesh @@ -553,4 +561,4 @@ bool KX_ReInstanceBulletShapeFromMesh(KX_GameObject *gameobj, KX_GameObject *fro spc->ReplaceControllerShape(bm); return true; } -#endif +#endif \ No newline at end of file diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index fd1a62d8997..421a9fc64b8 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -2027,6 +2027,11 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape(btScalar margin, b collisionShape->setMargin(margin); break; + case PHY_SHAPE_CAPSULE: + collisionShape = new btCapsuleShapeZ(m_radius, m_height); + collisionShape->setMargin(margin); + break; + case PHY_SHAPE_MESH: // Let's use the latest btScaledBvhTriangleMeshShape: it allows true sharing of // triangle mesh information between duplicates => drastic performance increase when @@ -2162,4 +2167,3 @@ CcdShapeConstructionInfo::~CcdShapeConstructionInfo() } } - diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index 08d94a2850a..cc0f06a58cf 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -138,6 +138,7 @@ typedef enum PHY_ShapeType { PHY_SHAPE_SPHERE, PHY_SHAPE_CYLINDER, PHY_SHAPE_CONE, + PHY_SHAPE_CAPSULE, PHY_SHAPE_MESH, PHY_SHAPE_POLYTOPE, PHY_SHAPE_COMPOUND, @@ -148,4 +149,3 @@ typedef enum PHY_ShapeType { typedef float PHY_Vector3[3]; #endif //__PHY_DYNAMIC_TYPES -