Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare multiple physics engines support #338

Merged
merged 1 commit into from
Apr 28, 2021

Conversation

diegoferigo
Copy link
Member

@diegoferigo diegoferigo commented Apr 28, 2021

The current logic of the vendored Physics system allows loading the ign-physics plugin, among other options, by reading the PhysicsEnginePlugin component. Until now, we just supported DART (the only available "real" physics engine) and we were relying on the fact that it loads it by default.

This PR updates our logic to use the PhysicsEnginePlugin component. This is in preparation of the upcoming bullet plugin.


Note that we do not currently support loading custom ignition physics plugin. This support would mean passing the OS-agnostic name of the plugin, and without introducing new methods, adding a new argument would break APIs (even though, only the ScenarIO Gazebo API, and not the ScenarIO core APIs).

Since there are no third-party plugins yet, let's leave this option to a future PR. If there's interest from downstream, adding a new method would be trivial.

// 1. Engine from component (from command line / ServerConfig)
auto engineComp = _ecm.Component<components::PhysicsEnginePlugin>(_entity);
if (engineComp && !engineComp->Data().empty())
{
pluginLib = engineComp->Data();
}
// 2. Engine from SDF
else if (_sdf->HasElement("engine"))
{
auto sdfClone = _sdf->Clone();
auto engineElem = sdfClone->GetElement("engine");
pluginLib = engineElem->Get<std::string>("filename", pluginLib).first;
}
// 3. Use DART by default
if (pluginLib.empty())
{
pluginLib = "libignition-physics-dartsim-plugin.so";
}
// Update component
if (!engineComp)
{
_ecm.CreateComponent(_entity, components::PhysicsEnginePlugin(pluginLib));
}
else
{
engineComp->SetData(pluginLib,
[](const std::string &_a, const std::string &_b){return _a == _b;});
}

@diegoferigo diegoferigo merged commit fe227b5 into devel Apr 28, 2021
@diegoferigo diegoferigo deleted the feature/prepare_multiple_physics_engines branch April 28, 2021 11:16
@diegoferigo diegoferigo linked an issue Jun 29, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set the physics engine through the component
2 participants