Skip to content

Commit

Permalink
UPBGE: Fix blender deformer.
Browse files Browse the repository at this point in the history
Some deformers as skin and shape deformer need an object to update
a blender mesh, but this object must own the blender mesh. To do
so we used previously a argument in some deformer constructor to
pass a blender object owning the blender mesh.
But in case the mesh is replaced the blender object of a game object
can't be used, in these case we looked at a blender object registered
along the blender mesh during the conversion.

With the recent merge of deformer creation into BL_DeformableGameObject::LoadDeformer
the look at blender object from mesh was always used. This worked fine
only when only one game object used a deformer for one blender mesh,
when two deformer used the same mesh the both conflicted and no update
appeared.
To solve this issue we first check if the blender object of the game
object own the blender mesh, else we do the look at.
  • Loading branch information
panzergame committed Oct 30, 2017
1 parent 18e9d76 commit 050eea1
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions source/gameengine/Converter/BL_DeformableGameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,26 @@ void BL_DeformableGameObject::LoadDeformer()
Scene *blenderScene = scene->GetBlenderScene();
// We must create a new deformer but which one?
KX_GameObject *parentobj = GetParent();
// Object that owns the mesh.
Object *oldblendobj = static_cast<Object *>(scene->GetLogicManager()->FindBlendObjByGameMeshName(meshobj->GetName()));
/* Object that owns the mesh. If this is not the current blender object, look at one of the object registered
* along the blender mesh. */
Object *meshblendobj;
if (m_pBlenderObject->data != mesh) {
meshblendobj = static_cast<Object *>(scene->GetLogicManager()->FindBlendObjByGameMeshName(meshobj->GetName()));
}
else {
meshblendobj = m_pBlenderObject;
}

bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(m_pBlenderObject);
bool bHasShapeKey = mesh->key && mesh->key->type==KEY_RELATIVE;
bool bHasDvert = mesh->dvert;
bool bHasShapeKey = mesh->key && mesh->key->type == KEY_RELATIVE;
bool bHasDvert = mesh->dvert && m_pBlenderObject->defbase.first;
bool bHasArmature = BL_ModifierDeformer::HasArmatureDeformer(m_pBlenderObject) &&
parentobj && parentobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE && oldblendobj && bHasDvert;
parentobj && parentobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE && meshblendobj && bHasDvert;
#ifdef WITH_BULLET
bool bHasSoftBody = (!parentobj && (m_pBlenderObject->gameflag & OB_SOFT_BODY));
#endif

if (!oldblendobj) {
if (!meshblendobj) {
if (bHasModifier || bHasShapeKey || bHasDvert || bHasArmature) {
CM_FunctionWarning("new mesh is not used in an object from the current scene, you will get incorrect behavior.");
return;
Expand All @@ -181,32 +188,32 @@ void BL_DeformableGameObject::LoadDeformer()

if (bHasModifier) {
if (bHasShapeKey || bHasArmature) {
BL_ModifierDeformer *modifierDeformer = new BL_ModifierDeformer(this, blenderScene, oldblendobj, m_pBlenderObject,
BL_ModifierDeformer *modifierDeformer = new BL_ModifierDeformer(this, blenderScene, meshblendobj, m_pBlenderObject,
meshobj, static_cast<BL_ArmatureObject *>(parentobj));
modifierDeformer->LoadShapeDrivers(parentobj);
m_pDeformer = modifierDeformer;
}
else {
m_pDeformer = new BL_ModifierDeformer(this, blenderScene, oldblendobj, m_pBlenderObject, meshobj, nullptr);
m_pDeformer = new BL_ModifierDeformer(this, blenderScene, meshblendobj, m_pBlenderObject, meshobj, nullptr);
}
}
else if (bHasShapeKey) {
if (bHasArmature) {
BL_ShapeDeformer *shapeDeformer = new BL_ShapeDeformer(this, oldblendobj, m_pBlenderObject, meshobj,
BL_ShapeDeformer *shapeDeformer = new BL_ShapeDeformer(this, meshblendobj, m_pBlenderObject, meshobj,
static_cast<BL_ArmatureObject *>(parentobj));
shapeDeformer->LoadShapeDrivers(parentobj);
m_pDeformer = shapeDeformer;
}
else {
m_pDeformer = new BL_ShapeDeformer(this, oldblendobj, m_pBlenderObject, meshobj, nullptr);
m_pDeformer = new BL_ShapeDeformer(this, meshblendobj, m_pBlenderObject, meshobj, nullptr);
}
}
else if (bHasArmature) {
m_pDeformer = new BL_SkinDeformer(this, oldblendobj, m_pBlenderObject, meshobj,
m_pDeformer = new BL_SkinDeformer(this, meshblendobj, m_pBlenderObject, meshobj,
static_cast<BL_ArmatureObject *>(parentobj));
}
else if (bHasDvert) {
m_pDeformer = new BL_MeshDeformer(this, oldblendobj, meshobj);
m_pDeformer = new BL_MeshDeformer(this, meshblendobj, meshobj);
}
#ifdef WITH_BULLET
else if (bHasSoftBody) {
Expand Down

0 comments on commit 050eea1

Please sign in to comment.