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
4346extern 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
188193StaticShape::~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)
255287void StaticShape::setTransform (const MatrixF& mat)
256288{
257289 Parent::setTransform (mat);
290+
291+ if (mPhysicsRep )
292+ mPhysicsRep ->setTransform (mat);
293+
258294 setMaskBits (PositionMask);
259295}
260296
0 commit comments