2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-11-24 22:44:29 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-11-24 22:44:29 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:30:41 +00:00
|
|
|
/** \file gameengine/Converter/KX_SoftBodyDeformer.cpp
|
|
|
|
* \ingroup bgeconv
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-10-15 02:15:07 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable:4786)
|
2009-11-24 22:44:29 +00:00
|
|
|
#endif //WIN32
|
|
|
|
|
|
|
|
#include "MT_assert.h"
|
|
|
|
|
|
|
|
#include "KX_ConvertPhysicsObject.h"
|
|
|
|
#include "KX_SoftBodyDeformer.h"
|
|
|
|
#include "RAS_MeshObject.h"
|
2011-05-06 20:18:42 +00:00
|
|
|
#include "CTR_Map.h"
|
|
|
|
#include "CTR_HashedPtr.h"
|
2009-11-24 22:44:29 +00:00
|
|
|
|
2013-01-23 07:26:39 +00:00
|
|
|
#ifdef WITH_BULLET
|
2009-11-24 22:44:29 +00:00
|
|
|
|
|
|
|
#include "CcdPhysicsEnvironment.h"
|
|
|
|
#include "CcdPhysicsController.h"
|
|
|
|
#include "BulletSoftBody/btSoftBody.h"
|
|
|
|
|
|
|
|
#include "btBulletDynamicsCommon.h"
|
|
|
|
|
2011-05-06 20:18:42 +00:00
|
|
|
void KX_SoftBodyDeformer::Relink(CTR_Map<class CTR_HashedPtr, void*>*map)
|
2009-11-24 22:44:29 +00:00
|
|
|
{
|
|
|
|
void **h_obj = (*map)[m_gameobj];
|
|
|
|
|
|
|
|
if (h_obj) {
|
|
|
|
m_gameobj = (BL_DeformableGameObject*)(*h_obj);
|
|
|
|
m_pMeshObject = m_gameobj->GetMesh(0);
|
|
|
|
} else {
|
|
|
|
m_gameobj = NULL;
|
|
|
|
m_pMeshObject = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KX_SoftBodyDeformer::Apply(class RAS_IPolyMaterial *polymat)
|
|
|
|
{
|
BGE: Cleaning up the BGE's physics code and removing KX_IPhysicsController and KX_BulletPhysicsController. Instead, we just use PHY_IPhysicsController, which removes a lot of duplicate code.
This is a squashed commit of the following:
BGE Physics Cleanup: Fix crashes with LibLoading and replication. Also fixing some memory leaks.
BGE Physics Cleanup: Removing KX_IPhysicsController and KX_BulletPhysicsController.
BGE Physics Cleanup: Moving the replication code outside of KX_BlenderBulletController and switching KX_ConvertPhysicsObjects to create a CcdPhysicsController instead of a KX_BlenderBulletController.
BGE Physics Cleanup: Getting rid of an unsued KX_BulletPhysicsController.h include in KX_Scene.cpp.
BGE Physics Cleanup: Removing unused KX_IPhysicsController and KX_BulletPhysicsController includes.
BGE Physics Cleanup: Removing m_pPhysicsController1 and GetPhysicsController1() from KX_GameObject.
BGE Physics Cleanup: Remove SetRigidBody() from KX_IPhysicsController and remove GetName() from CcdPhysicsController.
BGE Physics Cleanup: Moving Add/RemoveCompoundChild() from KX_IPhysicsController to PHY_IPhysicsController.
BGE Physics Cleanup: Removing GetLocalInertia() from KX_IPhysicsController.
BGE Physics Cleanup: Making BlenderBulletCharacterController derive from PHY_ICharacter and removing CharacterWrapper from CcdPhysicsEnvironment.cpp. Also removing the character functions from KX_IPhysicsController.
BGE Physics Cleanup: Removing GetOrientation(), SetOrientation(), SetPosition(), SetScaling(), and GetRadius() from KX_IPhysicsController.
BGE Physics Cleanup: Removing GetReactionForce() since all implementations returned (0, 0, 0). The Python interface for KX_GameObject still has reaction force code, but it still also returns (0, 0, 0). This can probably be removed as well, but removing it can break scripts, so I'll leave it for now.
BGE Physics Cleanup: Removing Get/SetLinVelocityMin() and Get/SetLinVelocityMax() from KX_IPhysicsController.
BGE Physics Cleanup: Removing SetMargin(), RelativeTranslate(), and RelativeRotate() from KX_IPhysicsController.
BGE Physics Cleanup: Using constant references for function arguments in PHY_IPhysicsController where appropriate.
BGE Physics Cleanup: Removing ApplyImpulse() from KX_IPhysicsController.
BGE Physics Cleanup: Removing ResolveCombinedVelocities() from KX_IPhysicsController.
BGE Physics Cleanup: Accidently removed a return when cleaning up KX_GameObject::PyGetVelocity().
BGE Physics Cleanup: Remove GetLinearVelocity(), GetAngularVelocity() and GetVelocity() from KX_IPhysicsController. The corresponding PHY_IPhysicsController functions now also take Moto types instead of scalars to match the KX_IPhysicsController interface.
BGE Physics Cleanup: Moving SuspendDynamics, RestoreDynamics, SetMass, GetMass, and SetTransform from KX_IPhysicsController to PHY_IPhysicsController.
BGE Physics Cleanup: PHY_IPhysicsEnvironment and derived classes now use the same naming scheme as PHY_IController.
BGE Physics Cleanup: PHY_IMotionState and derived classes now use the same naming convention as PHY_IController.
BGE Phsyics Cleanup: Making PHY_IController and its derived classes follow a consistent naming scheme for member functions. They now all start with capital letters (e.g., setWorldOrientation becomes SetWorldOrientation).
BGE Physics Cleanup: Getting rid of KX_GameObject::SuspendDynamics() and KX_GameObject::RestoreDynamics(). Instead, use the functions from the physics controller.
BGE: Some first steps in trying to cleanup the KX_IPhysicsController mess. KX_GameObject now has a GetPhysicsController() and a GetPhysicsController1(). The former returns a PHY_IPhysicsController* while the latter returns a KX_IPhysicsController. The goal is to get everything using GetPhysicsController() instead of GetPhysicsController1().
2013-11-04 19:22:47 +00:00
|
|
|
CcdPhysicsController* ctrl = (CcdPhysicsController*) m_gameobj->GetPhysicsController();
|
2009-11-24 22:44:29 +00:00
|
|
|
if (!ctrl)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
btSoftBody* softBody= ctrl->GetSoftBody();
|
|
|
|
if (!softBody)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//printf("apply\n");
|
|
|
|
RAS_MeshSlot::iterator it;
|
|
|
|
RAS_MeshMaterial *mmat;
|
|
|
|
RAS_MeshSlot *slot;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
// update the vertex in m_transverts
|
|
|
|
Update();
|
|
|
|
|
|
|
|
// The vertex cache can only be updated for this deformer:
|
|
|
|
// Duplicated objects with more than one ploymaterial (=multiple mesh slot per object)
|
|
|
|
// share the same mesh (=the same cache). As the rendering is done per polymaterial
|
|
|
|
// cycling through the objects, the entire mesh cache cannot be updated in one shot.
|
|
|
|
mmat = m_pMeshObject->GetMeshMaterial(polymat);
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!mmat->m_slots[(void*)m_gameobj])
|
2009-11-24 22:44:29 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
slot = *mmat->m_slots[(void*)m_gameobj];
|
|
|
|
|
|
|
|
// for each array
|
2012-03-24 07:52:14 +00:00
|
|
|
for (slot->begin(it); !slot->end(it); slot->next(it))
|
2009-11-24 22:44:29 +00:00
|
|
|
{
|
|
|
|
btSoftBody::tNodeArray& nodes(softBody->m_nodes);
|
|
|
|
|
|
|
|
int index = 0;
|
2012-03-24 07:52:14 +00:00
|
|
|
for (i=it.startvertex; i<it.endvertex; i++,index++) {
|
2009-11-24 22:44:29 +00:00
|
|
|
RAS_TexVert& v = it.vertex[i];
|
|
|
|
btAssert(v.getSoftBodyIndex() >= 0);
|
|
|
|
|
|
|
|
MT_Point3 pt (
|
|
|
|
nodes[v.getSoftBodyIndex()].m_x.getX(),
|
|
|
|
nodes[v.getSoftBodyIndex()].m_x.getY(),
|
|
|
|
nodes[v.getSoftBodyIndex()].m_x.getZ());
|
|
|
|
v.SetXYZ(pt);
|
|
|
|
|
|
|
|
MT_Vector3 normal (
|
|
|
|
nodes[v.getSoftBodyIndex()].m_n.getX(),
|
|
|
|
nodes[v.getSoftBodyIndex()].m_n.getY(),
|
|
|
|
nodes[v.getSoftBodyIndex()].m_n.getZ());
|
|
|
|
v.SetNormal(normal);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|