dimforge / bevy_rapier

Official Rapier plugin for the Bevy game engine.
https://rapier.rs
Apache License 2.0
1.19k stars 256 forks source link

0.13.0 no longer works with renderless Bevy #152

Open starwolfy opened 2 years ago

starwolfy commented 2 years ago

The following cargo.toml configuration does not build anymore: bevy_rapier3d = {version= "0.13.0" ,default-features = false, features = [ "dim3" ]}

Build output:


Compiling bevy_rapier3d v0.13.1
error[E0433]: failed to resolve: could not find `render` in `bevy`
 --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:6:11
  |
6 |     bevy::render::mesh::{Indices, VertexAttributeValues},
  |           ^^^^^^ could not find `render` in `bevy`

error[E0433]: failed to resolve: could not find `render` in `bevy`
  --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/plugin/context.rs:11:11
   |
11 | use bevy::render::primitives::Aabb;
   |           ^^^^^^ could not find `render` in `bevy`

error[E0433]: failed to resolve: use of undeclared type `Mesh`
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:727:35
    |
727 |     let vertices = mesh.attribute(Mesh::ATTRIBUTE_POSITION)?;
    |                                   ^^^^ use of undeclared type `Mesh`

error[E0433]: failed to resolve: use of undeclared type `VertexAttributeValues`
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:731:9
    |
731 |         VertexAttributeValues::Float32(vtx) => Some(
    |         ^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `VertexAttributeValues`

error[E0433]: failed to resolve: use of undeclared type `VertexAttributeValues`
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:736:9
    |
736 |         VertexAttributeValues::Float32x3(vtx) => Some(
    |         ^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `VertexAttributeValues`

error[E0433]: failed to resolve: use of undeclared type `Indices`
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:745:9
    |
745 |         Indices::U16(idx) => idx
    |         ^^^^^^^ use of undeclared type `Indices`

error[E0433]: failed to resolve: use of undeclared type `Indices`
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:749:9
    |
749 |         Indices::U32(idx) => idx.chunks_exact(3).map(|i| [i[0], i[1], i[2]]).collect(),
    |         ^^^^^^^ use of undeclared type `Indices`

error[E0412]: cannot find type `Mesh` in this scope
  --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider.rs:19:17
   |
19 |     Mesh(Handle<Mesh>),
   |                 ^^^^ not found in this scope
   |
help: there is an enum variant `crate::prelude::AsyncCollider::Mesh`; try using the variant's enum
   |
19 |     Mesh(Handle<crate::prelude::AsyncCollider>),
   |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: you might be missing a type parameter
   |
17 | pub enum AsyncCollider<Mesh> {
   |                       ++++++

error[E0412]: cannot find type `Mesh` in this scope
  --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider.rs:21:32
   |
21 |     ConvexDecomposition(Handle<Mesh>, VHACDParameters),
   |                                ^^^^ not found in this scope
   |
help: there is an enum variant `crate::prelude::AsyncCollider::Mesh`; try using the variant's enum
   |
21 |     ConvexDecomposition(Handle<crate::prelude::AsyncCollider>, VHACDParameters),
   |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: you might be missing a type parameter
   |
17 | pub enum AsyncCollider<Mesh> {
   |                       ++++++

error[E0412]: cannot find type `Mesh` in this scope
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:161:29
    |
161 |     pub fn bevy_mesh(mesh: &Mesh) -> Option<Self> {
    |                             ^^^^ not found in this scope
    |
help: there is an enum variant `crate::prelude::AsyncCollider::Mesh`; try using the variant's enum
    |
161 |     pub fn bevy_mesh(mesh: &crate::prelude::AsyncCollider) -> Option<Self> {
    |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0412]: cannot find type `Mesh` in this scope
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:169:50
    |
169 |     pub fn bevy_mesh_convex_decomposition(mesh: &Mesh) -> Option<Self> {
    |                                                  ^^^^ not found in this scope
    |
help: there is an enum variant `crate::prelude::AsyncCollider::Mesh`; try using the variant's enum
    |
169 |     pub fn bevy_mesh_convex_decomposition(mesh: &crate::prelude::AsyncCollider) -> Option<Self> {
    |                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0412]: cannot find type `Mesh` in this scope
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:179:16
    |
179 |         mesh: &Mesh,
    |                ^^^^ not found in this scope
    |
help: there is an enum variant `crate::prelude::AsyncCollider::Mesh`; try using the variant's enum
    |
179 |         mesh: &crate::prelude::AsyncCollider,
    |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0412]: cannot find type `Mesh` in this scope
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/geometry/collider_impl.rs:724:41
    |
724 | fn extract_mesh_vertices_indices(mesh: &Mesh) -> Option<(Vec<na::Point3<Real>>, Vec<[u32; 3]>)> {
    |                                         ^^^^ not found in this scope
    |
help: there is an enum variant `crate::prelude::AsyncCollider::Mesh`; try using the variant's enum
    |
724 | fn extract_mesh_vertices_indices(mesh: &crate::prelude::AsyncCollider) -> Option<(Vec<na::Point3<Real>>, Vec<[u32; 3]>)> {
    |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0412]: cannot find type `Mesh` in this scope
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/plugin/systems.rs:544:24
    |
544 |     meshes: Res<Assets<Mesh>>,
    |                        ^^^^ not found in this scope
    |
help: there is an enum variant `crate::prelude::AsyncCollider::Mesh`; try using the variant's enum
    |
544 |     meshes: Res<Assets<crate::prelude::AsyncCollider>>,
    |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: you might be missing a type parameter
    |
542 | pub fn init_async_shapes<Mesh>(
    |                         ++++++

error[E0412]: cannot find type `Aabb` in this scope
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/plugin/context.rs:619:15
    |
619 |         aabb: Aabb,
    |               ^^^^ help: a type alias with a similar name exists: `AABB`
    |
   ::: /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier3d-0.12.0/src/geometry/mod.rs:42:1
    |
42  | pub type AABB = parry::bounding_volume::AABB;
    | --------------------------------------------- similarly named type alias `AABB` defined here

error[E0277]: the trait bound `for<'r, 's, 't0, 't1, 't2, 't3> fn(bevy::prelude::Commands<'r, 's>, bevy::prelude::Res<'t0, bevy::prelude::Assets<[type error]>>, bevy::prelude::Query<'t1, 't2, (bevy::prelude::Entity, &'t3 collider::AsyncCollider), bevy::prelude::Without<collider::Collider>>) {init_async_shapes}: IntoSystem<(), (), _>` is not satisfied
  --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/plugin/plugin.rs:86:34
   |
86 |                     .with_system(systems::init_async_shapes)
   |                      ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoSystem<(), (), _>` is not implemented for `for<'r, 's, 't0, 't1, 't2, 't3> fn(bevy::prelude::Commands<'r, 's>, bevy::prelude::Res<'t0, bevy::prelude::Assets<[type error]>>, bevy::prelude::Query<'t1, 't2, (bevy::prelude::Entity, &'t3 collider::AsyncCollider), bevy::prelude::Without<collider::Collider>>) {init_async_shapes}`
   |                      |
   |                      required by a bound introduced by this call
   |
   = note: required because of the requirements on the impl of `IntoSystemDescriptor<_>` for `for<'r, 's, 't0, 't1, 't2, 't3> fn(bevy::prelude::Commands<'r, 's>, bevy::prelude::Res<'t0, bevy::prelude::Assets<[type error]>>, bevy::prelude::Query<'t1, 't2, (bevy::prelude::Entity, &'t3 collider::AsyncCollider), bevy::prelude::Without<collider::Collider>>) {init_async_shapes}`
note: required by a bound in `bevy::prelude::SystemSet::with_system`
  --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.7.0/src/schedule/system_set.rs:80:55
   |
80 |     pub fn with_system<Params>(mut self, system: impl IntoSystemDescriptor<Params>) -> Self {
   |                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `bevy::prelude::SystemSet::with_system`

error[E0277]: the trait bound `for<'r, 's, 't0, 't1, 't2, 't3> fn(bevy::prelude::Commands<'r, 's>, bevy::prelude::Res<'t0, bevy::prelude::Assets<[type error]>>, bevy::prelude::Query<'t1, 't2, (bevy::prelude::Entity, &'t3 collider::AsyncCollider), bevy::prelude::Without<collider::Collider>>) {init_async_shapes}: AsSystemLabel<_>` is not satisfied
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/plugin/plugin.rs:87:61
    |
87  |                     .with_system(systems::apply_scale.after(systems::init_async_shapes))
    |                                                       ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsSystemLabel<_>` is not implemented for `for<'r, 's, 't0, 't1, 't2, 't3> fn(bevy::prelude::Commands<'r, 's>, bevy::prelude::Res<'t0, bevy::prelude::Assets<[type error]>>, bevy::prelude::Query<'t1, 't2, (bevy::prelude::Entity, &'t3 collider::AsyncCollider), bevy::prelude::Without<collider::Collider>>) {init_async_shapes}`
    |                                                       |
    |                                                       required by a bound introduced by this call
    |
note: required by a bound in `bevy::prelude::ParallelSystemDescriptorCoercion::after`
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.7.0/src/schedule/system_descriptor.rs:135:40
    |
135 |     fn after<Marker>(self, label: impl AsSystemLabel<Marker>) -> ParallelSystemDescriptor;
    |                                        ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `bevy::prelude::ParallelSystemDescriptorCoercion::after`

error[E0277]: the trait bound `for<'r, 's, 't0, 't1, 't2, 't3> fn(bevy::prelude::Commands<'r, 's>, bevy::prelude::Res<'t0, bevy::prelude::Assets<[type error]>>, bevy::prelude::Query<'t1, 't2, (bevy::prelude::Entity, &'t3 collider::AsyncCollider), bevy::prelude::Without<collider::Collider>>) {init_async_shapes}: AsSystemLabel<_>` is not satisfied
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_rapier3d-0.13.1/src/plugin/plugin.rs:103:36
    |
103 | ...                   .after(systems::init_async_shapes),
    |                        ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsSystemLabel<_>` is not implemented for `for<'r, 's, 't0, 't1, 't2, 't3> fn(bevy::prelude::Commands<'r, 's>, bevy::prelude::Res<'t0, bevy::prelude::Assets<[type error]>>, bevy::prelude::Query<'t1, 't2, (bevy::prelude::Entity, &'t3 collider::AsyncCollider), bevy::prelude::Without<collider::Collider>>) {init_async_shapes}`
    |                        |
    |                        required by a bound introduced by this call
    |
note: required by a bound in `bevy::prelude::ParallelSystemDescriptorCoercion::after`
   --> /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.7.0/src/schedule/system_descriptor.rs:135:40
    |
135 |     fn after<Marker>(self, label: impl AsSystemLabel<Marker>) -> ParallelSystemDescriptor;
    |                                        ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `bevy::prelude::ParallelSystemDescriptorCoercion::after`

Reproduction: rapier-renderless.zip

starwolfy commented 2 years ago

After further examination, it should also be said that v0.13.0 relies on render plugins to be added to the Bevy app or it will panick. So it is more than dependencies on the just Rust crates alone.

v0.12.0 Ran perfectly fine with only just these Bevy plugins: ScheduleRunnerPlugin,LogPlugin,TransformPlugin.

Trying to run a Bevy app with physics without DefaultPlugins added to the app, so without a render setup, gives:

thread 'main' panicked at 'Resource requested by bevy_rapier3d::plugin::systems::init_async_shapes does not exist: bevy_asset::assets::Assets<bevy_render::mesh::mesh::Mesh>', /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.7.0/src/system/system_param.rs:319:17
sebcrozet commented 2 years ago

I think this comes from the fact that we use Assets<Mesh>, and the Bevy Aabb type. Though both are not completely necessary for bevy_rapier to work, so this could be fixed by putting their usages behind a feature gate.

sethquantix commented 2 years ago

You can have best of both worlds. By inserting a WgpuSettings ressource with its backend field set to None before adding the bevy RenderPlugin, you'll get full initialization of bevy without any rendering context.

This has been made possible with the sub_apps, as the render_app won't be added to bevy runtime if it has no wgpu backend set. The bevy children plugins also do setup work on the condition of the render_app being present.

Edit: You'll also need some default plugin config else you won't meet dependencies for the render plugin.

.add(bevy::window::WindowPlugin { add_primary_window: false, exit_on_close: false })
   .add(bevy::asset::AssetPlugin)
   .add(bevy::render::RenderPlugin); 
starwolfy commented 2 years ago

Thank you @sethquantix this works, my project is once again renderless and is now initialized the way you've described!

However, requiring bevy_render and bevy_window as dependencies when you are not actually rendering is still a bit silly, because they are relatively large dependencies and as such including them also significantly increases the total project compile time, up to 40% longer compile time in my benchmarks. Admittedly this does seem more like a convenience issue.

MJohnson459 commented 1 year ago

You don't actually need to have the plugins running so can use this to disable them:

    // Bevy 0.8
    app.add_plugins_with(DefaultPlugins, |group| {
        group.disable::<RenderPlugin>().disable::<WindowPlugin>()
    });

    // Bevy 0.9
    app.add_plugins(
        DefaultPlugins
            .build()
            .disable::<RenderPlugin>()
            .disable::<WindowPlugin>()
    );

    // For 3D you also need to manually add the MeshPlugin
   app.add_plugin(MeshPlugin);

Using these dependencies.

[dependencies]
bevy = {version = "0.9.0", default-features = false, features = ["bevy_render"]}
bevy_rapier2d = {version = "0.19.0", default-features = false, features = ["dim2", "simd-stable"]}

This removes the runtime dependency on a GPU which I needed as just changing the window settings still causes a panic on some systems.

starwolfy commented 1 year ago

Since Bevy 0.9.0 and bevy_rapier3d 0.19.0 I haven't been able to disable the GPU Bevy plugins.

@MJohnson459 Your setup doesn't work for me and throws the following error:

thread 'main' panicked at 'Requested resource bevy_window::windows::Windows does not exist in the `World`. 
                Did you forget to add it using `app.insert_resource` / `app.init_resource`? 
                Resources are also implicitly added via `app.add_event`,
                and can be added by plugins.', /home/starwolf/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.9.0/src/world/world_cell.rs:245:21

Reproduction bevy_rapier_renderless.zip

MJohnson459 commented 1 year ago

@starwolfy sorry I was using 2D. It seems like 3D has an extra runtime dependency I can't get rid of either.

Edit: I updated the example with it working in 3D as well. It was just missing the bevy::render::mesh::MeshPlugin.

starwolfy commented 1 year ago

@MJohnson459 Thank you for the swift response and updated solution. Does your updated solution work for you on the reproduction project? It doesn't work for me, it continues to complain about more missing plugins all the way until it requires the Render plugin again.

MJohnson459 commented 1 year ago

@starwolfy yes it worked for me. Did you limit the bevy dependency to remove the default features?

bevy_rapier_renderless_updated.zip

starwolfy commented 1 year ago

@starwolfy yes it worked for me. Did you limit the bevy dependency to remove the default features?

bevy_rapier_renderless_updated.zip

It works, thanks a bunch!!