BGE Fix for: [#22142] Armature deformation does not work in Game Engine. + parent type to modifiers doversion(). Patch by Xavier Thomas (xat)

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()
This commit is contained in:
Dalai Felinto 2010-05-25 08:42:11 +00:00
parent e26cc71bd0
commit 5416f51b7a
5 changed files with 56 additions and 5 deletions

@ -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! */

@ -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);

@ -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();

@ -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,

@ -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));