Skip to content

Commit

Permalink
Merge pull request #1743 from John3/fixDB_PSeditorTimmy
Browse files Browse the repository at this point in the history
replace fix #1736 for add physicShape datablock from the editor
  • Loading branch information
Lopuska authored Aug 21, 2016
2 parents 21bd220 + 5f463d0 commit fcfe2d6
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions Engine/source/T3D/physics/physicsShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "T3D/physics/physicsBody.h"
#include "T3D/physics/physicsWorld.h"
#include "T3D/physics/physicsCollision.h"
#include "T3D/gameBase/gameConnection.h"
#include "collision/concretePolyList.h"
#include "ts/tsShapeInstance.h"
#include "scene/sceneRenderState.h"
Expand Down Expand Up @@ -271,7 +272,7 @@ bool PhysicsShapeData::preload( bool server, String &errorBuffer )
{
if ( !Parent::preload( server, errorBuffer ) )
return false;

// If we don't have a physics plugin active then
// we have to fail completely.
if ( !PHYSICSMGR )
Expand All @@ -280,36 +281,39 @@ bool PhysicsShapeData::preload( bool server, String &errorBuffer )
return false;
}

if( shapeName && shapeName[0] != '\0' && !bool(shape) )
bool shapeError = false;

if (shapeName && shapeName[0])
{
// Load the shape.
// Resolve shapename
shape = ResourceManager::get().load(shapeName);
if( bool(shape) == false )
if (bool(shape) == false)
{
errorBuffer = String::ToString("PhysicsShapeData::load: Couldn't load shape \"%s\"", shapeName);
errorBuffer = String::ToString("PhysicsShapeData: Couldn't load shape \"%s\"", shapeName);
return false;
}
else
{
TSShapeInstance* pDummy = new TSShapeInstance(shape, !server);
delete pDummy;
}
if (!server && !shape->preloadMaterialList(shape.getPath()) && NetConnection::filesWereDownloaded())
shapeError = true;

}
else
return false;

// Prepare the shared physics collision shape.
if ( !colShape )
if ( !colShape && shape )
{
colShape = shape->buildColShape( false, Point3F::One );

// If we got here and didn't get a collision shape then
// we need to fail... can't have a shape without collision.
if ( !colShape )
{
errorBuffer = String::ToString( "PhysicsShapeData::preload - No collision found for shape '%s'.", shapeName );
return false;
//no collision so we create a simple box collision shape from the shapes bounds and alert the user
Con::warnf( "PhysicsShapeData::preload - No collision found for shape '%s', auto-creating one", shapeName );
Point3F halfWidth = shape->bounds.getExtents() * 0.5f;
colShape = PHYSICSMGR->createCollision();
MatrixF centerXfm(true);
centerXfm.setPosition(shape->bounds.getCenter());
colShape->addBox(halfWidth, centerXfm);
return true;
}
}

Expand Down Expand Up @@ -381,7 +385,7 @@ bool PhysicsShapeData::preload( bool server, String &errorBuffer )
MatrixF::Identity );
*/

return true;
return !shapeError;
}


Expand Down Expand Up @@ -699,7 +703,7 @@ bool PhysicsShape::_createShape()
mAmbientSeq = -1;

PhysicsShapeData *db = getDataBlock();
if ( !db )
if ( !db || !db->shape)
return false;

// Set the world box.
Expand Down

0 comments on commit fcfe2d6

Please sign in to comment.