Skip to content

Commit 067da32

Browse files
committed
UPBGE: Fix parent for physics object conversion.
Previously in CcdPhysicsEnvironment::ConvertObject we iterate over all the parents from the object tree to find the closer object possibly used as a compound shape parent. But by doing this we affected the search of just the root parent object to disable dynamic or just for tracking (e.g for fh spring). To found both the root parent and the root compound parent, two variables are used in COnvertObject, compoundParent and parentRoot. Also to clairfy, the function in physics controller named SetParentCtrl is rename SetParentRoot as it was used to set the root parent controller only, not the parent controller. Fix issue: #634.
1 parent 137faa3 commit 067da32

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

source/gameengine/Physics/Bullet/CcdPhysicsController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ CcdPhysicsController::CcdPhysicsController(const CcdConstructionInfo& ci)
173173
m_newClientInfo = 0;
174174
m_registerCount = 0;
175175
m_softBodyTransformInitialized = false;
176-
m_parentCtrl = 0;
176+
m_parentRoot = nullptr;
177177
// copy pointers locally to allow smart release
178178
m_MotionState = ci.m_MotionState;
179179
m_collisionShape = ci.m_collisionShape;
@@ -766,7 +766,7 @@ void CcdPhysicsController::WriteDynamicsToMotionState()
766766
// controller replication
767767
void CcdPhysicsController::PostProcessReplica(class PHY_IMotionState *motionstate, class PHY_IPhysicsController *parentctrl)
768768
{
769-
SetParentCtrl((CcdPhysicsController *)parentctrl);
769+
SetParentRoot((CcdPhysicsController *)parentctrl);
770770
m_softBodyTransformInitialized = false;
771771
m_MotionState = motionstate;
772772
m_registerCount = 0;

source/gameengine/Physics/Bullet/CcdPhysicsController.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ class CcdPhysicsController : public PHY_IPhysicsController
566566
int m_registerCount; // needed when multiple sensors use the same controller
567567
CcdConstructionInfo m_cci;//needed for replication
568568

569-
CcdPhysicsController *m_parentCtrl;
569+
CcdPhysicsController *m_parentRoot;
570570

571571
int m_savedCollisionFlags;
572572
short m_savedCollisionFilterGroup;
@@ -823,19 +823,14 @@ class CcdPhysicsController : public PHY_IPhysicsController
823823
return m_cci.m_physicsEnv;
824824
}
825825

826-
void SetParentCtrl(CcdPhysicsController *parentCtrl)
826+
void SetParentRoot(CcdPhysicsController *parentCtrl)
827827
{
828-
m_parentCtrl = parentCtrl;
828+
m_parentRoot = parentCtrl;
829829
}
830830

831-
CcdPhysicsController *GetParentCtrl()
831+
CcdPhysicsController *GetParentRoot() const
832832
{
833-
return m_parentCtrl;
834-
}
835-
836-
const CcdPhysicsController *GetParentCtrl() const
837-
{
838-
return m_parentCtrl;
833+
return m_parentRoot;
839834
}
840835

841836
virtual bool IsDynamic()

source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ void CcdPhysicsEnvironment::ProcessFhSprings(double curTime, float interval)
811811
if (body && (ctrl->GetConstructionInfo().m_do_fh || ctrl->GetConstructionInfo().m_do_rot_fh)) {
812812
//re-implement SM_FhObject.cpp using btCollisionWorld::rayTest and info from ctrl->getConstructionInfo()
813813
//send a ray from {0.0, 0.0, 0.0} towards {0.0, 0.0, -10.0}, in local coordinates
814-
CcdPhysicsController *parentCtrl = ctrl->GetParentCtrl();
814+
CcdPhysicsController *parentCtrl = ctrl->GetParentRoot();
815815
btRigidBody *parentBody = parentCtrl ? parentCtrl->GetRigidBody() : nullptr;
816816
btRigidBody *cl_object = parentBody ? parentBody : body;
817817

@@ -2692,21 +2692,34 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K
26922692
CcdConstructionInfo ci;
26932693
class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo();
26942694

2695-
Object *blenderparent = blenderobject->parent;
2696-
Object *rootparent = nullptr;
2697-
// Find the upper parent object using compound shape.
2698-
while (blenderparent) {
2699-
if ((blenderparent->gameflag & OB_CHILD) && (blenderobject->gameflag & (OB_COLLISION | OB_DYNAMIC | OB_RIGID_BODY)) &&
2700-
!(blenderobject->gameflag & OB_SOFT_BODY))
2701-
{
2702-
rootparent = blenderparent;
2695+
Object *blenderRoot = blenderobject->parent;
2696+
Object *blenderCompoundRoot = nullptr;
2697+
// Iterate over all parents in the object tree.
2698+
{
2699+
Object *parentit = blenderobject->parent;
2700+
while (parentit) {
2701+
// If the parent is valid for compound parent shape, update blenderCompoundRoot.
2702+
if ((parentit->gameflag & OB_CHILD) && (blenderobject->gameflag & (OB_COLLISION | OB_DYNAMIC | OB_RIGID_BODY)) &&
2703+
!(blenderobject->gameflag & OB_SOFT_BODY))
2704+
{
2705+
blenderCompoundRoot = parentit;
2706+
}
2707+
// Continue looking for root parent.
2708+
blenderRoot = parentit;
2709+
2710+
parentit = parentit->parent;
27032711
}
2704-
blenderparent = blenderparent->parent;
27052712
}
27062713

2707-
KX_GameObject *parent = nullptr;
2708-
if (rootparent) {
2709-
parent = converter.FindGameObject(rootparent);
2714+
KX_GameObject *compoundParent = nullptr;
2715+
if (blenderCompoundRoot) {
2716+
compoundParent = converter.FindGameObject(blenderCompoundRoot);
2717+
isbulletsoftbody = false;
2718+
}
2719+
2720+
KX_GameObject *parentRoot = nullptr;
2721+
if (blenderRoot) {
2722+
parentRoot = converter.FindGameObject(blenderRoot);
27102723
isbulletsoftbody = false;
27112724
}
27122725

@@ -2982,7 +2995,7 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K
29822995
if (isCompoundChild) {
29832996
//find parent, compound shape and add to it
29842997
//take relative transform into account!
2985-
CcdPhysicsController *parentCtrl = (CcdPhysicsController *)parent->GetPhysicsController();
2998+
CcdPhysicsController *parentCtrl = (CcdPhysicsController *)compoundParent->GetPhysicsController();
29862999
BLI_assert(parentCtrl);
29873000

29883001
// only makes compound shape if parent has a physics controller (i.e not an empty, etc)
@@ -2995,7 +3008,7 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K
29953008

29963009
// compute the local transform from parent, this may include several node in the chain
29973010
SG_Node *gameNode = gameobj->GetSGNode();
2998-
SG_Node *parentNode = parent->GetSGNode();
3011+
SG_Node *parentNode = compoundParent->GetSGNode();
29993012
// relative transform
30003013
MT_Vector3 parentScale = parentNode->GetWorldScaling();
30013014
parentScale[0] = MT_Scalar(1.0f) / parentScale[0];
@@ -3136,11 +3149,12 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K
31363149
}
31373150
}
31383151

3139-
if (parent)
3152+
if (parentRoot) {
31403153
physicscontroller->SuspendDynamics(false);
3154+
}
31413155

3142-
CcdPhysicsController *parentCtrl = parent ? (CcdPhysicsController *)parent->GetPhysicsController() : 0;
3143-
physicscontroller->SetParentCtrl(parentCtrl);
3156+
CcdPhysicsController *parentCtrl = parentRoot ? static_cast<CcdPhysicsController *>(parentRoot->GetPhysicsController()) : nullptr;
3157+
physicscontroller->SetParentRoot(parentCtrl);
31443158
}
31453159

31463160
void CcdPhysicsEnvironment::SetupObjectConstraints(KX_GameObject *obj_src, KX_GameObject *obj_dest,

0 commit comments

Comments
 (0)