|
@@ -57,6 +57,8 @@
|
|
|
#include <Bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
|
|
#include <Bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
|
|
|
#include <StanHull/hull.h>
|
|
#include <StanHull/hull.h>
|
|
|
|
|
|
|
|
|
|
+using namespace std;
|
|
|
|
|
+
|
|
|
namespace Urho3D
|
|
namespace Urho3D
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -198,30 +200,30 @@ private:
|
|
|
|
|
|
|
|
TriangleMeshData::TriangleMeshData(Model* model, unsigned lodLevel)
|
|
TriangleMeshData::TriangleMeshData(Model* model, unsigned lodLevel)
|
|
|
{
|
|
{
|
|
|
- meshInterface_ = new TriangleMeshInterface(model, lodLevel);
|
|
|
|
|
- shape_ = new btBvhTriangleMeshShape(meshInterface_.Get(), meshInterface_->useQuantize_, true);
|
|
|
|
|
|
|
+ meshInterface_ = make_unique<TriangleMeshInterface>(model, lodLevel);
|
|
|
|
|
+ shape_ = make_unique<btBvhTriangleMeshShape>(meshInterface_.get(), meshInterface_->useQuantize_, true);
|
|
|
|
|
|
|
|
- infoMap_ = new btTriangleInfoMap();
|
|
|
|
|
- btGenerateInternalEdgeInfo(shape_.Get(), infoMap_.Get());
|
|
|
|
|
|
|
+ infoMap_ = make_unique<btTriangleInfoMap>();
|
|
|
|
|
+ btGenerateInternalEdgeInfo(shape_.get(), infoMap_.get());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TriangleMeshData::TriangleMeshData(CustomGeometry* custom)
|
|
TriangleMeshData::TriangleMeshData(CustomGeometry* custom)
|
|
|
{
|
|
{
|
|
|
- meshInterface_ = new TriangleMeshInterface(custom);
|
|
|
|
|
- shape_ = new btBvhTriangleMeshShape(meshInterface_.Get(), meshInterface_->useQuantize_, true);
|
|
|
|
|
|
|
+ meshInterface_ = make_unique<TriangleMeshInterface>(custom);
|
|
|
|
|
+ shape_ = make_unique<btBvhTriangleMeshShape>(meshInterface_.get(), meshInterface_->useQuantize_, true);
|
|
|
|
|
|
|
|
- infoMap_ = new btTriangleInfoMap();
|
|
|
|
|
- btGenerateInternalEdgeInfo(shape_.Get(), infoMap_.Get());
|
|
|
|
|
|
|
+ infoMap_ = make_unique<btTriangleInfoMap>();
|
|
|
|
|
+ btGenerateInternalEdgeInfo(shape_.get(), infoMap_.get());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
GImpactMeshData::GImpactMeshData(Model* model, unsigned lodLevel)
|
|
GImpactMeshData::GImpactMeshData(Model* model, unsigned lodLevel)
|
|
|
{
|
|
{
|
|
|
- meshInterface_ = new TriangleMeshInterface(model, lodLevel);
|
|
|
|
|
|
|
+ meshInterface_ = make_unique<TriangleMeshInterface>(model, lodLevel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
GImpactMeshData::GImpactMeshData(CustomGeometry* custom)
|
|
GImpactMeshData::GImpactMeshData(CustomGeometry* custom)
|
|
|
{
|
|
{
|
|
|
- meshInterface_ = new TriangleMeshInterface(custom);
|
|
|
|
|
|
|
+ meshInterface_ = make_unique<TriangleMeshInterface>(custom);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ConvexData::ConvexData(Model* model, unsigned lodLevel)
|
|
ConvexData::ConvexData(Model* model, unsigned lodLevel)
|
|
@@ -431,7 +433,7 @@ btCollisionShape* CreateCollisionGeometryDataShape(ShapeType shapeType, Collisio
|
|
|
case SHAPE_TRIANGLEMESH:
|
|
case SHAPE_TRIANGLEMESH:
|
|
|
{
|
|
{
|
|
|
auto* triMesh = static_cast<TriangleMeshData*>(geometry);
|
|
auto* triMesh = static_cast<TriangleMeshData*>(geometry);
|
|
|
- return new btScaledBvhTriangleMeshShape(triMesh->shape_.Get(), ToBtVector3(scale));
|
|
|
|
|
|
|
+ return new btScaledBvhTriangleMeshShape(triMesh->shape_.get(), ToBtVector3(scale));
|
|
|
}
|
|
}
|
|
|
case SHAPE_CONVEXHULL:
|
|
case SHAPE_CONVEXHULL:
|
|
|
{
|
|
{
|
|
@@ -443,7 +445,7 @@ btCollisionShape* CreateCollisionGeometryDataShape(ShapeType shapeType, Collisio
|
|
|
case SHAPE_GIMPACTMESH:
|
|
case SHAPE_GIMPACTMESH:
|
|
|
{
|
|
{
|
|
|
auto* gimpactMesh = static_cast<GImpactMeshData*>(geometry);
|
|
auto* gimpactMesh = static_cast<GImpactMeshData*>(geometry);
|
|
|
- auto* shape = new btGImpactMeshShape(gimpactMesh->meshInterface_.Get());
|
|
|
|
|
|
|
+ auto* shape = new btGImpactMeshShape(gimpactMesh->meshInterface_.get());
|
|
|
shape->setLocalScaling(ToBtVector3(scale));
|
|
shape->setLocalScaling(ToBtVector3(scale));
|
|
|
shape->updateBound();
|
|
shape->updateBound();
|
|
|
return shape;
|
|
return shape;
|
|
@@ -559,7 +561,7 @@ void CollisionShape::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
|
|
|
Quaternion worldRotation(worldTransform.Rotation() * rotation_);
|
|
Quaternion worldRotation(worldTransform.Rotation() * rotation_);
|
|
|
|
|
|
|
|
btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
|
|
btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
|
|
|
- world->debugDrawObject(btTransform(ToBtQuaternion(worldRotation), ToBtVector3(worldPosition)), shape_.Get(), bodyActive ?
|
|
|
|
|
|
|
+ world->debugDrawObject(btTransform(ToBtQuaternion(worldRotation), ToBtVector3(worldPosition)), shape_.get(), bodyActive ?
|
|
|
WHITE : GREEN);
|
|
WHITE : GREEN);
|
|
|
|
|
|
|
|
physicsWorld_->SetDebugRenderer(nullptr);
|
|
physicsWorld_->SetDebugRenderer(nullptr);
|
|
@@ -848,7 +850,7 @@ void CollisionShape::NotifyRigidBody(bool updateMass)
|
|
|
if (node_ && shape_ && compound)
|
|
if (node_ && shape_ && compound)
|
|
|
{
|
|
{
|
|
|
// Remove the shape first to ensure it is not added twice
|
|
// Remove the shape first to ensure it is not added twice
|
|
|
- compound->removeChildShape(shape_.Get());
|
|
|
|
|
|
|
+ compound->removeChildShape(shape_.get());
|
|
|
|
|
|
|
|
if (IsEnabledEffective())
|
|
if (IsEnabledEffective())
|
|
|
{
|
|
{
|
|
@@ -864,7 +866,7 @@ void CollisionShape::NotifyRigidBody(bool updateMass)
|
|
|
btTransform offset;
|
|
btTransform offset;
|
|
|
offset.setOrigin(ToBtVector3(node_->GetWorldScale() * position));
|
|
offset.setOrigin(ToBtVector3(node_->GetWorldScale() * position));
|
|
|
offset.setRotation(ToBtQuaternion(rotation_));
|
|
offset.setRotation(ToBtQuaternion(rotation_));
|
|
|
- compound->addChildShape(offset, shape_.Get());
|
|
|
|
|
|
|
+ compound->addChildShape(offset, shape_.get());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Finally tell the rigid body to update its mass
|
|
// Finally tell the rigid body to update its mass
|
|
@@ -891,12 +893,11 @@ void CollisionShape::ReleaseShape()
|
|
|
btCompoundShape* compound = GetParentCompoundShape();
|
|
btCompoundShape* compound = GetParentCompoundShape();
|
|
|
if (shape_ && compound)
|
|
if (shape_ && compound)
|
|
|
{
|
|
{
|
|
|
- compound->removeChildShape(shape_.Get());
|
|
|
|
|
|
|
+ compound->removeChildShape(shape_.get());
|
|
|
rigidBody_->UpdateMass();
|
|
rigidBody_->UpdateMass();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- shape_.Reset();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ shape_.reset();
|
|
|
geometry_.Reset();
|
|
geometry_.Reset();
|
|
|
|
|
|
|
|
if (physicsWorld_)
|
|
if (physicsWorld_)
|
|
@@ -1018,31 +1019,31 @@ void CollisionShape::UpdateShape()
|
|
|
switch (shapeType_)
|
|
switch (shapeType_)
|
|
|
{
|
|
{
|
|
|
case SHAPE_BOX:
|
|
case SHAPE_BOX:
|
|
|
- shape_ = new btBoxShape(ToBtVector3(size_ * 0.5f));
|
|
|
|
|
|
|
+ shape_ = make_unique<btBoxShape>(ToBtVector3(size_ * 0.5f));
|
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_SPHERE:
|
|
case SHAPE_SPHERE:
|
|
|
- shape_ = new btSphereShape(size_.x_ * 0.5f);
|
|
|
|
|
|
|
+ shape_ = make_unique<btSphereShape>(size_.x_ * 0.5f);
|
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_STATICPLANE:
|
|
case SHAPE_STATICPLANE:
|
|
|
- shape_ = new btStaticPlaneShape(btVector3(0.0f, 1.0f, 0.0f), 0.0f);
|
|
|
|
|
|
|
+ shape_ = make_unique<btStaticPlaneShape>(btVector3(0.0f, 1.0f, 0.0f), 0.0f);
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_CYLINDER:
|
|
case SHAPE_CYLINDER:
|
|
|
- shape_ = new btCylinderShape(btVector3(size_.x_ * 0.5f, size_.y_ * 0.5f, size_.x_ * 0.5f));
|
|
|
|
|
|
|
+ shape_ = make_unique<btCylinderShape>(btVector3(size_.x_ * 0.5f, size_.y_ * 0.5f, size_.x_ * 0.5f));
|
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_CAPSULE:
|
|
case SHAPE_CAPSULE:
|
|
|
- shape_ = new btCapsuleShape(size_.x_ * 0.5f, Max(size_.y_ - size_.x_, 0.0f));
|
|
|
|
|
|
|
+ shape_ = make_unique<btCapsuleShape>(size_.x_ * 0.5f, Max(size_.y_ - size_.x_, 0.0f));
|
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_CONE:
|
|
case SHAPE_CONE:
|
|
|
- shape_ = new btConeShape(size_.x_ * 0.5f, size_.y_);
|
|
|
|
|
|
|
+ shape_ = make_unique<btConeShape>(size_.x_ * 0.5f, size_.y_);
|
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -1067,9 +1068,10 @@ void CollisionShape::UpdateShape()
|
|
|
geometry_ = new HeightfieldData(terrain, lodLevel_);
|
|
geometry_ = new HeightfieldData(terrain, lodLevel_);
|
|
|
auto* heightfield = static_cast<HeightfieldData*>(geometry_.Get());
|
|
auto* heightfield = static_cast<HeightfieldData*>(geometry_.Get());
|
|
|
|
|
|
|
|
- shape_ =
|
|
|
|
|
- new btHeightfieldTerrainShape(heightfield->size_.x_, heightfield->size_.y_, heightfield->heightData_.Get(),
|
|
|
|
|
- 1.0f, heightfield->minHeight_, heightfield->maxHeight_, 1, PHY_FLOAT, false);
|
|
|
|
|
|
|
+ shape_ = make_unique<btHeightfieldTerrainShape>(
|
|
|
|
|
+ heightfield->size_.x_, heightfield->size_.y_, heightfield->heightData_.Get(),
|
|
|
|
|
+ 1.0f, heightfield->minHeight_, heightfield->maxHeight_, 1, PHY_FLOAT, false);
|
|
|
|
|
+
|
|
|
shape_->setLocalScaling(
|
|
shape_->setLocalScaling(
|
|
|
ToBtVector3(Vector3(heightfield->spacing_.x_, 1.0f, heightfield->spacing_.z_) * cachedWorldScale_ * size_));
|
|
ToBtVector3(Vector3(heightfield->spacing_.x_, 1.0f, heightfield->spacing_.z_) * cachedWorldScale_ * size_));
|
|
|
}
|
|
}
|
|
@@ -1077,7 +1079,7 @@ void CollisionShape::UpdateShape()
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
|
- shape_ = this->UpdateDerivedShape(shapeType_, cachedWorldScale_);
|
|
|
|
|
|
|
+ shape_.reset(this->UpdateDerivedShape(shapeType_, cachedWorldScale_));
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1106,7 +1108,8 @@ void CollisionShape::UpdateCachedGeometryShape(CollisionGeometryDataCache& cache
|
|
|
{
|
|
{
|
|
|
geometry_ = CreateCollisionGeometryData(shapeType_, custom);
|
|
geometry_ = CreateCollisionGeometryData(shapeType_, custom);
|
|
|
assert(geometry_);
|
|
assert(geometry_);
|
|
|
- shape_ = CreateCollisionGeometryDataShape(shapeType_, geometry_.Get(), cachedWorldScale_ * size_);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ shape_.reset(CreateCollisionGeometryDataShape(shapeType_, geometry_.Get(), cachedWorldScale_ * size_));
|
|
|
assert(shape_);
|
|
assert(shape_);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1129,7 +1132,7 @@ void CollisionShape::UpdateCachedGeometryShape(CollisionGeometryDataCache& cache
|
|
|
cache[id] = geometry_;
|
|
cache[id] = geometry_;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- shape_ = CreateCollisionGeometryDataShape(shapeType_, geometry_.Get(), cachedWorldScale_ * size_);
|
|
|
|
|
|
|
+ shape_.reset(CreateCollisionGeometryDataShape(shapeType_, geometry_.Get(), cachedWorldScale_ * size_));
|
|
|
assert(shape_);
|
|
assert(shape_);
|
|
|
// Watch for live reloads of the collision model to reload the geometry if necessary
|
|
// Watch for live reloads of the collision model to reload the geometry if necessary
|
|
|
SubscribeToEvent(model_, E_RELOADFINISHED, URHO3D_HANDLER(CollisionShape, HandleModelReloadFinished));
|
|
SubscribeToEvent(model_, E_RELOADFINISHED, URHO3D_HANDLER(CollisionShape, HandleModelReloadFinished));
|