Skip to content

Commit

Permalink
UPBGE: Fix deformer conversion.
Browse files Browse the repository at this point in the history
THe deformer conversion have some extra constraint, first it had to be placed
before the RAS_MeshUser are created with AddMeshUser, secondly BL_ShapeDeformer
have to check the case when parent object is null.

Also the function BL_SkinDeformer::SetArmature became useless and the construtors
in deformers in case of conversion of non-replicated object are removed because
unused anymore.
  • Loading branch information
panzergame committed Oct 16, 2017
1 parent b339165 commit 1ab4c09
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 84 deletions.
35 changes: 10 additions & 25 deletions source/gameengine/Converter/BL_BlenderDataConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,6 @@ static KX_GameObject *BL_GameObjectFromBlenderObject(Object *ob, KX_Scene *kxsce

case OB_ARMATURE:
{
bArmature *arm = (bArmature *)ob->data;
gameobj = new BL_ArmatureObject(kxscene, KX_Scene::m_callbacks, ob, kxscene->GetBlenderScene());

kxscene->AddAnimatedObject(gameobj);
Expand Down Expand Up @@ -1202,7 +1201,6 @@ static void bl_ConvertBlenderObject_Single(BL_BlenderSceneConverter& converter,
objectlist->Add(CM_AddRef(gameobj));

gameobj->NodeUpdateGS(0);
gameobj->AddMeshUser();
}
else {
// We must store this object otherwise it will be deleted at the end of this function if it is not a root object.
Expand Down Expand Up @@ -1513,29 +1511,6 @@ void BL_ConvertBlenderObjects(struct Main *maggie,
}
vec_parent_child.clear();

// Load deformers
for (KX_GameObject *gameobj : sumolist) {
gameobj->LoadDeformer();
}

// Set up armatures.
for (Object *blenderobj : allblobj) {
if (blenderobj->type == OB_MESH) {
Mesh *me = (Mesh *)blenderobj->data;

if (me->dvert) {
BL_DeformableGameObject *obj = static_cast<BL_DeformableGameObject *>(converter.FindGameObject(blenderobj));

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

// Find 'root' parents (object that has not parents in SceneGraph).
for (KX_GameObject *gameobj : sumolist) {
if (!gameobj->GetSGNode()->GetSGParent()) {
Expand All @@ -1544,6 +1519,16 @@ void BL_ConvertBlenderObjects(struct Main *maggie,
}
}

// Load deformers
for (KX_GameObject *gameobj : sumolist) {
gameobj->LoadDeformer();
}

// Init mesh users and mesh slots once the deformers are available.
for (KX_GameObject *gameobj : objectlist) {
gameobj->AddMeshUser();
}

// Create graphic controller for culling.
if (kxscene->GetDbvtCulling()) {
bool occlusion = false;
Expand Down
12 changes: 0 additions & 12 deletions source/gameengine/Converter/BL_ModifierDeformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ class BL_ModifierDeformer : public BL_ShapeDeformer
static bool HasCompatibleDeformer(Object *ob);
static bool HasArmatureDeformer(Object *ob);

BL_ModifierDeformer(BL_DeformableGameObject *gameobj,
Scene *scene,
Object *bmeshobj,
RAS_MeshObject *mesh)
:BL_ShapeDeformer(gameobj, bmeshobj, mesh),
m_lastModifierUpdate(-1.0),
m_scene(scene),
m_dm(nullptr)
{
}

/* this second constructor is needed for making a mesh deformable on the fly. */
BL_ModifierDeformer(BL_DeformableGameObject *gameobj,
Scene *scene,
Object *bmeshobj_old,
Expand Down
18 changes: 3 additions & 15 deletions source/gameengine/Converter/BL_ShapeDeformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@ extern "C" {
#include "BLI_blenlib.h"
#include "BLI_math.h"

BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj,
RAS_MeshObject *mesh)
:BL_SkinDeformer(gameobj, bmeshobj, mesh, nullptr),
m_useShapeDrivers(false),
m_lastShapeUpdate(-1)
{
m_key = m_bmesh->key ? BKE_key_copy(G.main, m_bmesh->key) : nullptr;
}

/* this second constructor is needed for making a mesh deformable on the fly. */
BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj_old,
Object *bmeshobj_new,
Expand Down Expand Up @@ -120,8 +109,7 @@ bool BL_ShapeDeformer::LoadShapeDrivers(KX_GameObject *parent)
}

// Fix drivers since BL_ArmatureObject makes copies
if (parent->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE && GetKey()->adt) {
BL_ArmatureObject *arma = (BL_ArmatureObject *)parent;
if (m_armobj && GetKey()->adt) {
FCurve *fcu;

for (fcu = (FCurve *)GetKey()->adt->drivers.first; fcu; fcu = (FCurve *)fcu->next) {
Expand All @@ -131,8 +119,8 @@ bool BL_ShapeDeformer::LoadShapeDrivers(KX_GameObject *parent)
DRIVER_TARGETS_USED_LOOPER(dvar)
{
if (dtar->id) {
if ((Object *)dtar->id == arma->GetOrigArmatureObject())
dtar->id = (ID *)arma->GetArmatureObject();
if ((Object *)dtar->id == m_armobj->GetOrigArmatureObject())
dtar->id = (ID *)m_armobj->GetArmatureObject();
}
}
DRIVER_TARGETS_LOOPER_END
Expand Down
5 changes: 0 additions & 5 deletions source/gameengine/Converter/BL_ShapeDeformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ class RAS_MeshObject;
class BL_ShapeDeformer : public BL_SkinDeformer
{
public:
BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj,
RAS_MeshObject *mesh);

/* this second constructor is needed for making a mesh deformable on the fly. */
BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj_old,
Object *bmeshobj_new,
Expand Down
20 changes: 0 additions & 20 deletions source/gameengine/Converter/BL_SkinDeformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ static short get_deformflags(Object *bmeshobj)
return flags;
}

BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj,
RAS_MeshObject *mesh,
BL_ArmatureObject *arma)
:BL_MeshDeformer(gameobj, bmeshobj, mesh),
m_armobj(arma),
m_lastArmaUpdate(-1),
m_copyNormals(false)
{
copy_m4_m4(m_obmat, bmeshobj->obmat);
m_deformflags = get_deformflags(bmeshobj);
}

BL_SkinDeformer::BL_SkinDeformer(
BL_DeformableGameObject *gameobj,
Object *bmeshobj_old, // Blender object that owns the new mesh
Expand Down Expand Up @@ -352,10 +339,3 @@ bool BL_SkinDeformer::Update(void)
{
return UpdateInternal(false);
}

/* XXX note: I propose to drop this function */
void BL_SkinDeformer::SetArmature(BL_ArmatureObject *armobj)
{
// only used to set the object now
m_armobj = armobj;
}
7 changes: 0 additions & 7 deletions source/gameengine/Converter/BL_SkinDeformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ class BL_SkinDeformer : public BL_MeshDeformer
{
public:
virtual void Relink(std::map<SCA_IObject *, SCA_IObject *>& map);
void SetArmature(BL_ArmatureObject *armobj);

BL_SkinDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj,
RAS_MeshObject *mesh,
BL_ArmatureObject *arma);

/* this second constructor is needed for making a mesh deformable on the fly. */
BL_SkinDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj_old,
Object *bmeshobj_new,
Expand Down

0 comments on commit 1ab4c09

Please sign in to comment.