Skip to content

Commit 4fcf2b2

Browse files
authored
Merge pull request #1815 from Areloch/StaticShapePhysRepFix
Implements mPhysicsRep to StaticShape
2 parents d6ff1be + 43ac39a commit 4fcf2b2

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Engine/source/T3D/staticShape.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#include "math/mathIO.h"
4040
#include "sim/netConnection.h"
4141
#include "scene/sceneObjectLightingPlugin.h"
42+
#include "T3D/physics/physicsPlugin.h"
43+
#include "T3D/physics/physicsBody.h"
44+
#include "T3D/physics/physicsCollision.h"
4245

4346
extern void wireCube(F32 size,Point3F pos);
4447

@@ -183,6 +186,8 @@ StaticShape::StaticShape()
183186
{
184187
mTypeMask |= StaticShapeObjectType | StaticObjectType;
185188
mDataBlock = 0;
189+
190+
mPhysicsRep = NULL;
186191
}
187192

188193
StaticShape::~StaticShape()
@@ -208,6 +213,8 @@ bool StaticShape::onAdd()
208213

209214
addToScene();
210215

216+
_updatePhysics();
217+
211218
if (isServerObject())
212219
scriptOnAdd();
213220
return true;
@@ -219,6 +226,8 @@ bool StaticShape::onNewDataBlock(GameBaseData* dptr, bool reload)
219226
if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
220227
return false;
221228

229+
_updatePhysics();
230+
222231
scriptOnNewDataBlock(reload);
223232
return true;
224233
}
@@ -227,9 +236,32 @@ void StaticShape::onRemove()
227236
{
228237
scriptOnRemove();
229238
removeFromScene();
239+
240+
SAFE_DELETE(mPhysicsRep);
241+
230242
Parent::onRemove();
231243
}
232244

245+
//----------------------------------------------------------------------------
246+
247+
void StaticShape::_updatePhysics()
248+
{
249+
if (PHYSICSMGR)
250+
{
251+
PhysicsCollision* colShape = NULL;
252+
253+
Resource<TSShape> shape = mDataBlock->shapeAssetRef.assetPtr->getShapeResource();
254+
colShape = shape->buildColShape(true, getScale());
255+
256+
if (colShape)
257+
{
258+
PhysicsWorld* world = PHYSICSMGR->getWorld(isServerObject() ? "server" : "client");
259+
mPhysicsRep = PHYSICSMGR->createBody();
260+
mPhysicsRep->init(colShape, 0, 0, this, world);
261+
mPhysicsRep->setTransform(getTransform());
262+
}
263+
}
264+
}
233265

234266
//----------------------------------------------------------------------------
235267

@@ -255,6 +287,10 @@ void StaticShape::interpolateTick(F32 delta)
255287
void StaticShape::setTransform(const MatrixF& mat)
256288
{
257289
Parent::setTransform(mat);
290+
291+
if (mPhysicsRep)
292+
mPhysicsRep->setTransform(mat);
293+
258294
setMaskBits(PositionMask);
259295
}
260296

Engine/source/T3D/staticShape.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "T3D/shapeBase.h"
3333
#endif
3434

35+
class PhysicsBody;
36+
3537
//----------------------------------------------------------------------------
3638

3739
struct StaticShapeData: public ShapeBaseData {
@@ -65,6 +67,8 @@ class StaticShape: public ShapeBase
6567
StaticShapeData* mDataBlock;
6668
bool mPowered;
6769

70+
PhysicsBody* mPhysicsRep;
71+
6872
void onUnmount(SceneObject* obj,S32 node) override;
6973

7074
protected:
@@ -73,6 +77,8 @@ class StaticShape: public ShapeBase
7377
NextFreeMask = Parent::NextFreeMask << 1
7478
};
7579

80+
void _updatePhysics();
81+
7682
public:
7783
DECLARE_CONOBJECT(StaticShape);
7884
DECLARE_CATEGORY("Object \t Destructable");

0 commit comments

Comments
 (0)