I have a Mesh with a ConvexDecomposition Collider using bevy_rapier3d
.
How can I figure out the mass that rapier computes for this collider?
My code looks something like this:
fn asset_loaded(
mut commands: Commands,
my_object: Query<(Entity, &Handle<Mesh>), With<MyObjectMarker>>,
meshes: Res<Assets<Mesh>>,
asset_server: Res<AssetServer>,
loaded: Local<bool>,
){
if *loaded{
return;
}
let (my_entity, my_mesh) = my_object.single();
if asset_server.load_state(my_mesh) != LoadState::Loaded {
return;
}
let collider = Collider::from_bevy_mesh(
meshes.get(my_mesh).unwrap(),
&ComputedColliderShape::ConvexDecomposition(VHACDParameters::default()),
).unwrap();
// ??: how can i get the computed mass of the object here?
commands.get_entity(my_entity).unwrap().insert(collider);
*loaded = true;
}
You can use the function mass_properties
like so:
// ??: how can i get the computed mass of the object here?
println!("{:#?}", collider.raw.mass_properties(1.0));
Note that you need to specify the density
, if not done already. In the example above it is set to 1
.