Remove BulletPhysics3D module

Having two physics engine seems redundant, Bullet3 development seems to have halted and JoltPhysics seems to be a better fit to Nazara
This commit is contained in:
Lynix
2024-02-06 20:45:06 +01:00
committed by Jérôme Leclercq
parent cb484a2432
commit 139bed2b0a
40 changed files with 31 additions and 2503 deletions

View File

@@ -2,7 +2,6 @@
#include <Nazara/Core.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Network.hpp>
#include <Nazara/BulletPhysics3D.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NazaraSDK/Application.hpp>

View File

@@ -2,7 +2,7 @@
#include <Nazara/Platform.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Math/PidController.hpp>
#include <Nazara/BulletPhysics3D.hpp>
#include <Nazara/JoltPhysics3D.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <entt/entt.hpp>
@@ -20,14 +20,14 @@ int main(int argc, char* argv[])
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
Nz::Application<Nz::Graphics, Nz::BulletPhysics3D> app(argc, argv);
Nz::Application<Nz::Graphics, Nz::JoltPhysics3D> app(argc, argv);
auto& windowing = app.AddComponent<Nz::WindowingAppComponent>();
auto& ecs = app.AddComponent<Nz::EntitySystemAppComponent>();
auto& world = ecs.AddWorld<Nz::EnttWorld>();
Nz::BulletPhysics3DSystem& physSytem = world.AddSystem<Nz::BulletPhysics3DSystem>();
Nz::JoltPhysics3DSystem& physSytem = world.AddSystem<Nz::JoltPhysics3DSystem>();
physSytem.GetPhysWorld().SetGravity(Nz::Vector3f::Zero());
Nz::RenderSystem& renderSystem = world.AddSystem<Nz::RenderSystem>();
@@ -101,7 +101,7 @@ int main(int argc, char* argv[])
cameraComponent.UpdateClearColor(Nz::Color(0.5f, 0.5f, 0.5f));
}
auto shipCollider = std::make_shared<Nz::BulletConvexCollider3D>(vertices, vertexMapper.GetVertexCount());
auto shipCollider = std::make_shared<Nz::JoltConvexHullCollider3D>(vertices, vertexMapper.GetVertexCount());
std::shared_ptr<Nz::MaterialInstance> colliderMat = Nz::MaterialInstance::Instantiate(Nz::MaterialType::Basic);
colliderMat->SetValueProperty("BaseColor", Nz::Color::Green());
@@ -139,7 +139,11 @@ int main(int argc, char* argv[])
auto& entityNode = playerEntity.emplace<Nz::NodeComponent>();
entityNode.SetPosition(Nz::Vector3f(12.5f, 0.f, 25.f));
auto& entityPhys = playerEntity.emplace<Nz::BulletRigidBody3DComponent>(physSytem.CreateRigidBody(shipCollider));
Nz::JoltRigidBody3D::DynamicSettings settings;
settings.geom = shipCollider;
settings.mass = 100.f;
auto& entityPhys = playerEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
entityPhys.SetMass(50.f);
entityPhys.SetAngularDamping(0.1f);
entityPhys.SetLinearDamping(0.5f);
@@ -178,7 +182,11 @@ int main(int argc, char* argv[])
entityNode.SetPosition(Nz::Vector3f(x * 2.f, y * 1.5f, z * 2.f));
entityNode.SetRotation(Nz::EulerAnglesf(0.f, Nz::TurnAnglef(0.5f), 0.f));
auto& entityPhys = entity.emplace<Nz::BulletRigidBody3DComponent>(physSytem.CreateRigidBody(shipCollider));
Nz::JoltRigidBody3D::DynamicSettings settings;
settings.geom = shipCollider;
settings.mass = 100.f;
auto& entityPhys = entity.emplace<Nz::JoltRigidBody3DComponent>(settings);
entityPhys.SetMass(1.f);
entityPhys.SetAngularDamping(0.f);
entityPhys.SetLinearDamping(0.f);
@@ -213,13 +221,13 @@ int main(int argc, char* argv[])
showColliders = !showColliders;
if (showColliders)
{
auto view = world.GetRegistry().view<Nz::GraphicsComponent, Nz::BulletRigidBody3DComponent>();
auto view = world.GetRegistry().view<Nz::GraphicsComponent, Nz::JoltRigidBody3DComponent>();
for (auto [entity, gfxComponent, _] : view.each())
gfxComponent.AttachRenderable(colliderModel, 1);
}
else
{
auto view = world.GetRegistry().view<Nz::GraphicsComponent, Nz::BulletRigidBody3DComponent>();
auto view = world.GetRegistry().view<Nz::GraphicsComponent, Nz::JoltRigidBody3DComponent>();
for (auto [entity, gfxComponent, _] : view.each())
gfxComponent.DetachRenderable(colliderModel);
}
@@ -234,7 +242,11 @@ int main(int argc, char* argv[])
entity.emplace<Nz::NodeComponent>();
auto& entityPhys = entity.emplace<Nz::BulletRigidBody3DComponent>(physSytem.CreateRigidBody(shipCollider));
Nz::JoltRigidBody3D::DynamicSettings settings;
settings.geom = shipCollider;
settings.mass = 100.f;
auto& entityPhys = entity.emplace<Nz::JoltRigidBody3DComponent>(settings);
entityPhys.SetMass(1.f);
entityPhys.SetAngularDamping(0.f);
entityPhys.SetLinearDamping(0.f);
@@ -261,7 +273,7 @@ int main(int argc, char* argv[])
{
float elapsedTime = deltaTime->AsSeconds();
auto spaceshipView = world.GetRegistry().view<Nz::NodeComponent, Nz::BulletRigidBody3DComponent>();
auto spaceshipView = world.GetRegistry().view<Nz::NodeComponent, Nz::JoltRigidBody3DComponent>();
for (auto&& [entity, node, _] : spaceshipView.each())
{
if (entity == playerEntity)
@@ -272,7 +284,7 @@ int main(int argc, char* argv[])
world.GetRegistry().destroy(entity);
}
Nz::BulletRigidBody3DComponent& playerShipBody = playerEntity.get<Nz::BulletRigidBody3DComponent>();
Nz::JoltRigidBody3DComponent& playerShipBody = playerEntity.get<Nz::JoltRigidBody3DComponent>();
Nz::Quaternionf currentRotation = playerShipBody.GetRotation();
Nz::Vector3f desiredHeading = headingEntity.get<Nz::NodeComponent>().GetForward();

View File

@@ -1,5 +1,5 @@
target("PhysicsDemo")
add_deps("NazaraGraphics", "NazaraBulletPhysics3D")
add_deps("NazaraGraphics", "NazaraJoltPhysics3D")
add_packages("entt")
add_files("main.cpp")
add_defines("NAZARA_ENTT")

View File

@@ -1,15 +1,7 @@
// Sources pour https://github.com/NazaraEngine/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World
#define USE_JOLT 1
#include <Nazara/Core.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Platform/WindowingAppComponent.hpp>
#if USE_JOLT
#include <Nazara/JoltPhysics3D.hpp>
#else
#include <Nazara/BulletPhysics3D.hpp>
#endif
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <iostream>
@@ -24,11 +16,7 @@ int main(int argc, char* argv[])
Nz::Renderer::Config renderConfig;
renderConfig.validationLevel = Nz::RenderAPIValidationLevel::None;
#if USE_JOLT
Nz::Application<Nz::Graphics, Nz::JoltPhysics3D> app(argc, argv, renderConfig);
#else
Nz::Application<Nz::Graphics, Nz::BulletPhysics3D> app(argc, argv, renderConfig);
#endif
auto& windowing = app.AddComponent<Nz::WindowingAppComponent>();
Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1280, 720), "Physics playground");
@@ -45,11 +33,7 @@ int main(int argc, char* argv[])
auto& ecs = app.AddComponent<Nz::EntitySystemAppComponent>();
auto& world = ecs.AddWorld<Nz::EnttWorld>();
#if USE_JOLT
auto& physSystem = world.AddSystem<Nz::JoltPhysics3DSystem>();
#else
auto& physSystem = world.AddSystem<Nz::BulletPhysics3DSystem>();
#endif
physSystem.GetPhysWorld().SetMaxStepCount(1);
physSystem.GetPhysWorld().SetStepSize(Nz::Time::TickDuration(30));
physSystem.GetPhysWorld().SetGravity(Nz::Vector3f::Down() * 9.81f);
@@ -96,46 +80,24 @@ int main(int argc, char* argv[])
boxColliderEntity.emplace<Nz::NodeComponent>();
#if USE_JOLT
float thickness = 1.f;
std::shared_ptr<Nz::JoltBoxCollider3D> wallCollider = std::make_shared<Nz::JoltBoxCollider3D>(Nz::Vector3f(BoxDims + thickness * 2.f, BoxDims + thickness * 2.f, thickness));
#else
std::shared_ptr<Nz::BulletBoxCollider3D> wallCollider = std::make_shared<Nz::BulletBoxCollider3D>(Nz::Vector3f(BoxDims, BoxDims, 1.f));
#endif
#if USE_JOLT
std::vector<Nz::JoltCompoundCollider3D::ChildCollider> colliders;
#else
std::vector<Nz::BulletCompoundCollider3D::ChildCollider> colliders;
#endif
for (Nz::Vector3f normal : { Nz::Vector3f::Forward(), Nz::Vector3f::Backward(), Nz::Vector3f::Left(), Nz::Vector3f::Right(), Nz::Vector3f::Up(), Nz::Vector3f::Down() })
{
auto& colliderEntry = colliders.emplace_back();
colliderEntry.collider = wallCollider;
#if USE_JOLT
colliderEntry.rotation = Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), normal);
colliderEntry.offset = normal * BoxDims * 0.5f + normal * 0.5f;
#else
colliderEntry.offsetMatrix = Nz::Matrix4f::Transform(normal * BoxDims * 0.5f + normal * 0.5f, Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), normal));
#endif
}
#if USE_JOLT
std::shared_ptr<Nz::JoltCompoundCollider3D> boxCollider = std::make_shared<Nz::JoltCompoundCollider3D>(std::move(colliders));
#else
std::shared_ptr<Nz::BulletCompoundCollider3D> boxCollider = std::make_shared<Nz::BulletCompoundCollider3D>(std::move(colliders));
#endif
#if USE_JOLT
Nz::JoltRigidBody3D::StaticSettings settings;
settings.geom = boxCollider;
boxColliderEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
#else
auto& boxBody = boxColliderEntity.emplace<Nz::BulletRigidBody3DComponent>(physSystem.CreateRigidBody(boxCollider));
boxBody.SetMass(0.f);
#endif
std::shared_ptr<Nz::Model> colliderModel;
{
@@ -163,11 +125,7 @@ int main(int argc, char* argv[])
float radius = radiusDis(rd);
std::uniform_real_distribution<float> positionRandom(-BoxDims * 0.5f + radius, BoxDims * 0.5f - radius);
#if USE_JOLT
std::shared_ptr<Nz::JoltSphereCollider3D> sphereCollider = std::make_shared<Nz::JoltSphereCollider3D>(radius);
#else
std::shared_ptr<Nz::BulletSphereCollider3D> sphereCollider = std::make_shared<Nz::BulletSphereCollider3D>(radius);
#endif
entt::handle ballEntity = world.CreateEntity();
@@ -184,15 +142,11 @@ int main(int argc, char* argv[])
ballNode.SetPosition(positionRandom(rd), positionRandom(rd), positionRandom(rd));
ballNode.SetScale(radius);
#if USE_JOLT
Nz::JoltRigidBody3D::DynamicSettings settings;
settings.geom = sphereCollider;
settings.mass = 4.f / 3.f * Nz::Pi<float> * Nz::IntegralPow(radius, 3);
ballEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
#else
ballEntity.emplace<Nz::BulletRigidBody3DComponent>(physSystem.CreateRigidBody(sphereCollider));
#endif
}
std::uniform_real_distribution<float> lengthDis(0.2f, 1.5f);
@@ -223,21 +177,13 @@ int main(int argc, char* argv[])
ballNode.SetPosition(xRandom(rd), yRandom(rd), zRandom(rd));
ballNode.SetScale(width, height, depth);
#if USE_JOLT
std::shared_ptr<Nz::JoltBoxCollider3D> boxCollider = std::make_shared<Nz::JoltBoxCollider3D>(Nz::Vector3f(width, height, depth));
#else
std::shared_ptr<Nz::BulletBoxCollider3D> boxCollider = std::make_shared<Nz::BulletBoxCollider3D>(Nz::Vector3f(width, height, depth));
#endif
#if USE_JOLT
Nz::JoltRigidBody3D::DynamicSettings settings;
settings.geom = boxCollider;
settings.mass = width * height * depth;
boxEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
#else
boxEntity.emplace<Nz::BulletRigidBody3DComponent>(physSystem.CreateRigidBody(boxCollider));
#endif
}
// Spaceships
@@ -281,11 +227,7 @@ int main(int argc, char* argv[])
Nz::VertexMapper vertexMapper(*spaceshipMesh->GetSubMesh(0));
Nz::SparsePtr<Nz::Vector3f> vertices = vertexMapper.GetComponentPtr<Nz::Vector3f>(Nz::VertexComponent::Position);
#if USE_JOLT
auto shipCollider = std::make_shared<Nz::JoltConvexHullCollider3D>(vertices, vertexMapper.GetVertexCount(), 0.1f);
#else
auto shipCollider = std::make_shared<Nz::BulletConvexCollider3D>(vertices, vertexMapper.GetVertexCount());
#endif
std::shared_ptr<Nz::Model> colliderModel;
{
@@ -307,15 +249,11 @@ int main(int argc, char* argv[])
auto& shipNode = shipEntity.emplace<Nz::NodeComponent>();
shipNode.SetPosition(xRandom(rd), yRandom(rd), zRandom(rd));
#if USE_JOLT
Nz::JoltRigidBody3D::DynamicSettings settings;
settings.geom = shipCollider;
settings.mass = 100.f;
shipEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
#else
shipEntity.emplace<Nz::BulletRigidBody3DComponent>(physSystem.CreateRigidBody(shipCollider));
#endif
//shipEntity.get<Nz::GraphicsComponent>().AttachRenderable(colliderModel);
}
@@ -363,7 +301,7 @@ int main(int argc, char* argv[])
NazaraSlot(Nz::WindowEventHandler, OnMouseMoved, cameraMove);
NazaraSlot(Nz::WindowEventHandler, OnMouseMoved, grabbedObjectMove);
#if USE_JOLT
struct GrabConstraint
{
GrabConstraint(Nz::JoltRigidBody3D& body, const Nz::Vector3f& grabPos) :
@@ -401,9 +339,6 @@ int main(int argc, char* argv[])
};
std::optional<GrabConstraint> grabConstraint;
#else
std::optional<Nz::BulletPivotConstraint3D> grabConstraint;
#endif
auto mouseMoveCallback = [&](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseMoveEvent& event)
{
@@ -430,11 +365,7 @@ int main(int argc, char* argv[])
Nz::Vector3f from = cameraComponent.Unproject({ float(event.x), float(event.y), 0.f });
Nz::Vector3f to = cameraComponent.Unproject({ float(event.x), float(event.y), 1.f });
#if USE_JOLT
Nz::JoltPhysics3DSystem::RaycastHit lastHitInfo;
#else
Nz::BulletPhysics3DSystem::RaycastHit lastHitInfo;
#endif
auto callback = [&](const decltype(lastHitInfo)& hitInfo) -> std::optional<float>
{
if (hitInfo.hitEntity == boxColliderEntity)
@@ -455,12 +386,7 @@ int main(int argc, char* argv[])
{
if (lastHitInfo.hitBody && lastHitInfo.hitEntity != boxColliderEntity)
{
#if USE_JOLT
grabConstraint.emplace(static_cast<Nz::JoltRigidBody3D&>(*lastHitInfo.hitBody), lastHitInfo.hitPosition);
#else
grabConstraint.emplace(*lastHitInfo.hitBody, lastHitInfo.hitPosition);
grabConstraint->SetImpulseClamp(30.f);
#endif
grabbedObjectMove.Connect(eventHandler.OnMouseMoved, [&, distance = Nz::Vector3f::Distance(from, lastHitInfo.hitPosition)](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseMoveEvent& event)
{
@@ -468,11 +394,7 @@ int main(int argc, char* argv[])
Nz::Vector3f to = cameraComponent.Unproject({ float(event.x), float(event.y), 1.f });
Nz::Vector3f newPosition = from + (to - from).Normalize() * distance;
#if USE_JOLT
grabConstraint->SetPosition(newPosition);
#else
grabConstraint->SetSecondAnchor(newPosition);
#endif
});
}
else

View File

@@ -1,5 +1,5 @@
target("PhysicsPlayground")
add_deps("NazaraGraphics", "NazaraBulletPhysics3D", "NazaraJoltPhysics3D")
add_deps("NazaraGraphics", "NazaraJoltPhysics3D")
add_packages("entt")
add_files("main.cpp")
add_defines("NAZARA_ENTT")

View File

@@ -2,7 +2,6 @@
#include <Nazara/Platform.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Math/PidController.hpp>
#include <Nazara/BulletPhysics3D.hpp>
#include <Nazara/JoltPhysics3D.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
@@ -597,7 +596,7 @@ int main(int argc, char* argv[])
//renderBuffer->Fill(skeletalBufferMem.data(), 0, skeletalBufferMem.size());
/*auto spaceshipView = registry.view<Nz::NodeComponent, Nz::RigidBody3DComponent>();
/*auto spaceshipView = registry.view<Nz::NodeComponent, Nz::JoltRigidBody3DComponent>();
for (auto&& [entity, node, _] : spaceshipView.each())
{
if (entity == playerEntity)
@@ -608,7 +607,7 @@ int main(int argc, char* argv[])
registry.destroy(entity);
}
Nz::RigidBody3DComponent& playerShipBody = registry.get<Nz::RigidBody3DComponent>(playerEntity);
Nz::JoltRigidBody3DComponent& playerShipBody = registry.get<Nz::JoltRigidBody3DComponent>(playerEntity);
Nz::Quaternionf currentRotation = playerShipBody.GetRotation();
Nz::Vector3f desiredHeading = registry.get<Nz::NodeComponent>(headingEntity).GetForward();

View File

@@ -5,7 +5,7 @@ end
target("Showcase")
set_group("Examples")
set_kind("binary")
add_deps("NazaraAudio", "NazaraGraphics", "NazaraChipmunkPhysics2D", "NazaraBulletPhysics3D", "NazaraJoltPhysics3D", "NazaraWidgets")
add_deps("NazaraAudio", "NazaraGraphics", "NazaraChipmunkPhysics2D", "NazaraJoltPhysics3D", "NazaraWidgets")
if has_config("embed_plugins", "static") then
add_deps("PluginAssimp")
else

View File

@@ -2,7 +2,6 @@
#include <Nazara/Core.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Network.hpp>
#include <Nazara/BulletPhysics3D.hpp>
#include <Nazara/ChipmunkPhysics2D.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
@@ -12,7 +11,7 @@ int main(int argc, char* argv[])
{
// This "example" has only one purpose: Giving an empty project for you to test whatever you want
// If you wish to have multiple test projects, you only have to copy/paste this directory and change the name in the xmake.lua
Nz::Application<Nz::Audio, Nz::Core, Nz::Graphics, Nz::Network, Nz::ChipmunkPhysics2D, Nz::BulletPhysics3D, Nz::Renderer, Nz::Utility> app(argc, argv);
Nz::Application<Nz::Audio, Nz::Core, Nz::Graphics, Nz::Network, Nz::ChipmunkPhysics2D, Nz::Renderer, Nz::Utility> app(argc, argv);
return EXIT_SUCCESS;
}

View File

@@ -1,3 +1,3 @@
target("Tut00_EmptyProject")
add_deps("NazaraAudio", "NazaraGraphics", "NazaraNetwork", "NazaraChipmunkPhysics2D", "NazaraBulletPhysics3D", "NazaraRenderer", "NazaraUtility")
add_deps("NazaraAudio", "NazaraGraphics", "NazaraNetwork", "NazaraChipmunkPhysics2D", "NazaraRenderer", "NazaraUtility")
add_files("main.cpp")