BGE Fix for: [#22142] Armature deformation does not work in Game Engine. + parent...
authorDalai Felinto <dfelinto@gmail.com>
Tue, 25 May 2010 08:42:11 +0000 (08:42 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Tue, 25 May 2010 08:42:11 +0000 (08:42 +0000)
This fix the problem of not being able to play animations created with Blender 2.5 in BGE. Patch reviewed by Benoit

Added also other parent to modifier conversions as requested by Joshua (aligorith). I didn't bump subversion here, but the patch should work still. If not I'm increasing subversion sooner anyways (tomorrow or by the middle of the week I hope).

I was waiting to commit this one together with the Logic Editor datablock patch (converting material_name DNA properties to struct Material *). However my patch is getting too big and it's better if it's alone (easier to analyze later, eventual fixes, ...)

Mitchell, this commit adds a function that can help hardware skinning - HasArmatureDeformer()

source/blender/blenloader/intern/readfile.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/BL_ModifierDeformer.cpp
source/gameengine/Converter/BL_ModifierDeformer.h
source/gameengine/Ketsji/KX_Scene.cpp

index 8dbf2682bb6a8c8b423d51cee1ca51efb6120d81..b23be6917ac7939fc930cf11c3bfa1caaa5d02ed 100644 (file)
@@ -10848,8 +10848,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        
+
        /* put 2.50 compatibility code here until next subversion bump */
        {
+               Object *ob;
                bScreen *sc;
 
                for (sc= main->screen.first; sc; sc= sc->id.next) {
@@ -10871,6 +10873,38 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
 
                do_version_mdef_250(fd, lib, main);
+
+               /* parent type to modifier */
+               for(ob = main->object.first; ob; ob = ob->id.next) {
+                       if(ob->parent) {
+                               Object *parent= newlibadr(fd, lib, ob->parent);
+                               if(parent->type==OB_ARMATURE && ob->partype==PARSKEL) {
+                                       ArmatureModifierData *amd;
+
+                                       amd = (ArmatureModifierData*) modifier_new(eModifierType_Armature);
+                                       amd->object = ob->parent;
+                                       BLI_addtail((ListBase*)&ob->modifiers, amd);
+                                       amd->deformflag= ((bArmature *)(parent->data))->deformflag;
+                                       ob->partype = PAROBJECT;
+                               }
+                               else if(parent->type==OB_LATTICE && ob->partype==PARSKEL) {
+                                       LatticeModifierData *lmd;
+
+                                       lmd = (LatticeModifierData*) modifier_new(eModifierType_Lattice);
+                                       lmd->object = ob->parent;
+                                       BLI_addtail((ListBase*)&ob->modifiers, lmd);
+                                       ob->partype = PAROBJECT;
+                               }
+                               else if(parent->type==OB_CURVE && ob->partype==PARCURVE) {
+                                       CurveModifierData *cmd;
+
+                                       cmd = (CurveModifierData*) modifier_new(eModifierType_Curve);
+                                       cmd->object = ob->parent;
+                                       BLI_addtail((ListBase*)&ob->modifiers, cmd);
+                                       ob->partype = PAROBJECT;
+                               }
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
index 4a2aa3695faf8885568a3db1a1f76cc2af90e7b9..2f0f70ed9fe0db623b2e3ba01bfb3712636ee85b 100644 (file)
@@ -1729,7 +1729,7 @@ static KX_GameObject *gameobject_from_blenderobject(
                // only support relative shape key
                bool bHasShapeKey = mesh->key != NULL && mesh->key->type==KEY_RELATIVE;
                bool bHasDvert = mesh->dvert != NULL && ob->defbase.first;
-               bool bHasArmature = (ob->parent && ob->parent->type == OB_ARMATURE && ob->partype==PARSKEL && bHasDvert);
+               bool bHasArmature = (BL_ModifierDeformer::HasArmatureDeformer(ob) && ob->parent && ob->parent->type == OB_ARMATURE && bHasDvert);
                bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(ob);
                bool bHasSoftBody = (!ob->parent && (ob->gameflag & OB_SOFT_BODY));
 
@@ -2357,8 +2357,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        
                        if (me->dvert){
                                BL_DeformableGameObject *obj = (BL_DeformableGameObject*)converter->FindGameObject(blenderobj);
-       
-                               if (obj && blenderobj->parent && blenderobj->parent->type==OB_ARMATURE && blenderobj->partype==PARSKEL){
+
+                               if (obj && BL_ModifierDeformer::HasArmatureDeformer(blenderobj) && blenderobj->parent && blenderobj->parent->type==OB_ARMATURE){
                                        KX_GameObject *par = converter->FindGameObject(blenderobj->parent);
                                        if (par && obj->GetDeformer())
                                                ((BL_SkinDeformer*)obj->GetDeformer())->SetArmature((BL_ArmatureObject*) par);
index e28ea47b16226fffef84aaeccdec18e60eb8b526..5ccf8de29b1e11da588f2d3b41946e576ac73ea7 100644 (file)
@@ -114,11 +114,27 @@ bool BL_ModifierDeformer::HasCompatibleDeformer(Object *ob)
                        continue;
                if (!(md->mode & eModifierMode_Realtime))
                        continue;
+               /* armature modifier are handled by SkinDeformer, not ModifierDeformer */
+               if (md->type == eModifierType_Armature )
+                       continue;
                return true;
        }
        return false;
 }
 
+bool BL_ModifierDeformer::HasArmatureDeformer(Object *ob)
+{
+       if (!ob->modifiers.first)
+               return false;
+
+       ModifierData* md;
+       for (md = (ModifierData*)ob->modifiers.first; md; md = (ModifierData*)md->next) {
+               if (md->type == eModifierType_Armature )
+                       return true;
+       }
+       return false;
+}
+
 bool BL_ModifierDeformer::Update(void)
 {
        bool bShapeUpdate = BL_ShapeDeformer::Update();
index 1122d5e8b324240eacb60cc239e88f46acc738a3..adf537110f1677686f8bf66a5bce3992124f64d4 100644 (file)
@@ -45,6 +45,7 @@ class BL_ModifierDeformer : public BL_ShapeDeformer
 {
 public:
        static bool HasCompatibleDeformer(Object *ob);
+       static bool HasArmatureDeformer(Object *ob);
 
 
        BL_ModifierDeformer(BL_DeformableGameObject *gameobj,
index ebd0fa5c5255116c648501dfa0dc48b675f7d6ee..d72fef166e643eb1214e37fafb9737f897cdd0b3 100644 (file)
@@ -1067,12 +1067,12 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj, bool use_gfx, bool u
                        bool bHasShapeKey = blendmesh->key != NULL && blendmesh->key->type==KEY_RELATIVE;
                        bool bHasDvert = blendmesh->dvert != NULL;
                        bool bHasArmature = 
+                               BL_ModifierDeformer::HasArmatureDeformer(blendobj) &&
                                parentobj &&                                                            // current parent is armature
                                parentobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE &&
                                oldblendobj &&                                                          // needed for mesh deform
                                blendobj->parent &&                                                     // original object had armature (not sure this test is needed)
-                               blendobj->parent->type == OB_ARMATURE && 
-                               blendobj->partype==PARSKEL && 
+                               blendobj->parent->type == OB_ARMATURE &&
                                blendmesh->dvert!=NULL;                                         // mesh has vertex group
                        bool bHasSoftBody = (!parentobj && (blendobj->gameflag & OB_SOFT_BODY));