diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_Scene.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.cpp | 220 |
1 files changed, 113 insertions, 107 deletions
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index b57a07779cb..caab0f38db9 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1017,92 +1017,119 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) -void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj) +void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj, bool use_gfx, bool use_phys) { KX_GameObject* gameobj = static_cast<KX_GameObject*>(obj); RAS_MeshObject* mesh = static_cast<RAS_MeshObject*>(meshobj); - if(!gameobj || !mesh) - { - std::cout << "warning: invalid object, mesh will not be replaced" << std::endl; + if(!gameobj) { + std::cout << "KX_Scene::ReplaceMesh Warning: invalid object, doing nothing" << std::endl; return; } - - gameobj->RemoveMeshes(); - gameobj->AddMesh(mesh); - if (gameobj->m_isDeformable) - { - BL_DeformableGameObject* newobj = static_cast<BL_DeformableGameObject*>( gameobj ); + if(use_gfx && mesh != NULL) + { + gameobj->RemoveMeshes(); + gameobj->AddMesh(mesh); - if (newobj->GetDeformer()) + if (gameobj->m_isDeformable) { - delete newobj->GetDeformer(); - newobj->SetDeformer(NULL); - } - - if (mesh->IsDeformed()) - { - // we must create a new deformer but which one? - KX_GameObject* parentobj = newobj->GetParent(); - // this always return the original game object (also for replicate) - Object* blendobj = newobj->GetBlenderObject(); - // object that owns the new mesh - Object* oldblendobj = static_cast<struct Object*>(m_logicmgr->FindBlendObjByGameMeshName(mesh->GetName())); - Mesh* blendmesh = mesh->GetMesh(); - - bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(blendobj); - bool bHasShapeKey = blendmesh->key != NULL && blendmesh->key->type==KEY_RELATIVE; - bool bHasDvert = blendmesh->dvert != NULL; - bool bHasArmature = - 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 && - blendmesh->dvert!=NULL; // mesh has vertex group - bool releaseParent = true; - + BL_DeformableGameObject* newobj = static_cast<BL_DeformableGameObject*>( gameobj ); - if (oldblendobj==NULL) { - std::cout << "warning: ReplaceMesh() new mesh is not used in an object from the current scene, you will get incorrect behavior" << std::endl; - bHasShapeKey= bHasDvert= bHasArmature=bHasModifier= false; + if (newobj->GetDeformer()) + { + delete newobj->GetDeformer(); + newobj->SetDeformer(NULL); } - - if (bHasModifier) + + if (mesh->IsDeformed()) { - BL_ModifierDeformer* modifierDeformer; - if (bHasShapeKey || bHasArmature) - { - modifierDeformer = new BL_ModifierDeformer( - newobj, - oldblendobj, blendobj, - static_cast<BL_SkinMeshObject*>(mesh), - true, - static_cast<BL_ArmatureObject*>( parentobj ) - ); - releaseParent= false; - modifierDeformer->LoadShapeDrivers(blendobj->parent); + // we must create a new deformer but which one? + KX_GameObject* parentobj = newobj->GetParent(); + // this always return the original game object (also for replicate) + Object* blendobj = newobj->GetBlenderObject(); + // object that owns the new mesh + Object* oldblendobj = static_cast<struct Object*>(m_logicmgr->FindBlendObjByGameMeshName(mesh->GetName())); + Mesh* blendmesh = mesh->GetMesh(); + + bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(blendobj); + bool bHasShapeKey = blendmesh->key != NULL && blendmesh->key->type==KEY_RELATIVE; + bool bHasDvert = blendmesh->dvert != NULL; + bool bHasArmature = + 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 && + blendmesh->dvert!=NULL; // mesh has vertex group + bool releaseParent = true; + + + if (oldblendobj==NULL) { + std::cout << "warning: ReplaceMesh() new mesh is not used in an object from the current scene, you will get incorrect behavior" << std::endl; + bHasShapeKey= bHasDvert= bHasArmature=bHasModifier= false; } - else + + if (bHasModifier) { - modifierDeformer = new BL_ModifierDeformer( - newobj, - oldblendobj, blendobj, - static_cast<BL_SkinMeshObject*>(mesh), - false, - NULL - ); + BL_ModifierDeformer* modifierDeformer; + if (bHasShapeKey || bHasArmature) + { + modifierDeformer = new BL_ModifierDeformer( + newobj, + oldblendobj, blendobj, + static_cast<BL_SkinMeshObject*>(mesh), + true, + static_cast<BL_ArmatureObject*>( parentobj ) + ); + releaseParent= false; + modifierDeformer->LoadShapeDrivers(blendobj->parent); + } + else + { + modifierDeformer = new BL_ModifierDeformer( + newobj, + oldblendobj, blendobj, + static_cast<BL_SkinMeshObject*>(mesh), + false, + NULL + ); + } + newobj->SetDeformer(modifierDeformer); + } + else if (bHasShapeKey) + { + BL_ShapeDeformer* shapeDeformer; + if (bHasArmature) + { + shapeDeformer = new BL_ShapeDeformer( + newobj, + oldblendobj, blendobj, + static_cast<BL_SkinMeshObject*>(mesh), + true, + true, + static_cast<BL_ArmatureObject*>( parentobj ) + ); + releaseParent= false; + shapeDeformer->LoadShapeDrivers(blendobj->parent); + } + else + { + shapeDeformer = new BL_ShapeDeformer( + newobj, + oldblendobj, blendobj, + static_cast<BL_SkinMeshObject*>(mesh), + false, + true, + NULL + ); + } + newobj->SetDeformer( shapeDeformer); } - newobj->SetDeformer(modifierDeformer); - } - else if (bHasShapeKey) - { - BL_ShapeDeformer* shapeDeformer; - if (bHasArmature) + else if (bHasArmature) { - shapeDeformer = new BL_ShapeDeformer( + BL_SkinDeformer* skinDeformer = new BL_SkinDeformer( newobj, oldblendobj, blendobj, static_cast<BL_SkinMeshObject*>(mesh), @@ -1111,49 +1138,28 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj) static_cast<BL_ArmatureObject*>( parentobj ) ); releaseParent= false; - shapeDeformer->LoadShapeDrivers(blendobj->parent); + newobj->SetDeformer(skinDeformer); } - else + else if (bHasDvert) { - shapeDeformer = new BL_ShapeDeformer( - newobj, - oldblendobj, blendobj, - static_cast<BL_SkinMeshObject*>(mesh), - false, - true, - NULL + BL_MeshDeformer* meshdeformer = new BL_MeshDeformer( + newobj, oldblendobj, static_cast<BL_SkinMeshObject*>(mesh) ); + newobj->SetDeformer(meshdeformer); } - newobj->SetDeformer( shapeDeformer); - } - else if (bHasArmature) - { - BL_SkinDeformer* skinDeformer = new BL_SkinDeformer( - newobj, - oldblendobj, blendobj, - static_cast<BL_SkinMeshObject*>(mesh), - true, - true, - static_cast<BL_ArmatureObject*>( parentobj ) - ); - releaseParent= false; - newobj->SetDeformer(skinDeformer); - } - else if (bHasDvert) - { - BL_MeshDeformer* meshdeformer = new BL_MeshDeformer( - newobj, oldblendobj, static_cast<BL_SkinMeshObject*>(mesh) - ); - newobj->SetDeformer(meshdeformer); + + // release parent reference if its not being used + if( releaseParent && parentobj) + parentobj->Release(); } - - // release parent reference if its not being used - if( releaseParent && parentobj) - parentobj->Release(); } - } - gameobj->AddMeshUser(); + gameobj->AddMeshUser(); + } + + if(use_phys) { /* update the new assigned mesh with the physics mesh */ + KX_ReInstanceBulletShapeFromMesh(gameobj, NULL, use_gfx?NULL:mesh); + } } KX_Camera* KX_Scene::FindCamera(KX_Camera* cam) @@ -1844,4 +1850,4 @@ KX_PYMETHODDEF_DOC(KX_Scene, addObject, // the object is added to the scene so we dont want python to own a reference replica->Release(); return replica->GetProxy(); -}
\ No newline at end of file +} |