BGE patch: break parent relationship when child and parent are not active/inactive...
authorBenoit Bolsee <benoit.bolsee@online.be>
Sat, 6 Sep 2008 22:06:01 +0000 (22:06 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Sat, 6 Sep 2008 22:06:01 +0000 (22:06 +0000)
source/gameengine/Converter/BL_BlenderDataConversion.cpp

index def4938b053064c3b99fe20c340e45ec1b43b55c..15e65ac9fe5a1733b4c108446279d42c4520e190 100644 (file)
@@ -2144,7 +2144,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                                
                                                                gameobj->NodeUpdateGS(0,true);
                                                                gameobj->AddMeshUser();
-                                               
                                                        }
                                                        else
                                                        {
@@ -2209,6 +2208,24 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        {
        
                struct Object* blenderchild = pcit->m_blenderchild;
+               struct Object* blenderparent = blenderchild->parent;
+               KX_GameObject* parentobj = converter->FindGameObject(blenderparent);
+               KX_GameObject* childobj = converter->FindGameObject(blenderchild);
+
+               assert(childobj);
+
+               if (!parentobj || objectlist->SearchValue(childobj) != objectlist->SearchValue(parentobj))
+               {
+                       // special case: the parent and child object are not in the same layer. 
+                       // This weird situation is used in Apricot for test purposes.
+                       // Resolve it by breaking the parent relationship
+                       childobj->GetSGNode()->DisconnectFromParent();
+                       delete pcit->m_gamechildnode;
+                       // This leave the child object is an incorrect position: its local position becomes
+                       // the global position but we don't care: the child should be in an invisble layer
+                       continue;
+               }
+
                switch (blenderchild->partype)
                {
                        case PARVERT1:
@@ -2248,12 +2265,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                break;
                }
        
-               struct Object* blenderparent = blenderchild->parent;
-               KX_GameObject* parentobj = converter->FindGameObject(blenderparent);
-               if (parentobj)
-               {
-                       parentobj->     GetSGNode()->AddChild(pcit->m_gamechildnode);
-               }
+               parentobj->     GetSGNode()->AddChild(pcit->m_gamechildnode);
        }
        vec_parent_child.clear();