Skip to content

Commit

Permalink
add nalgebra feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann committed Mar 1, 2022
1 parent 326f3f2 commit 90632e9
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 203 deletions.
20 changes: 7 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ no-default-features = true

[features]
default = ["clipboard"]
# rapier = ["bevy_rapier3d", "nalgebra"]
# rapier2d = ["bevy_rapier2d", "nalgebra"]
clipboard = ["bevy_egui/manage_clipboard"]
nightly = []

Expand All @@ -31,9 +29,7 @@ bevy = { version = "0.6", default-features = false, features = [
bevy_egui = { version = "0.11.1", default-features = false, features = ["open_url"] }
pretty-type-name = "1.0"
image = { version = "0.23", default-features = false }
# bevy_rapier3d = { version = "0.10", optional = true }
# bevy_rapier2d = { version = "0.10", optional = true }
# nalgebra = { version = "0.27", features = ["convert-glam013"], optional = true }
nalgebra030 = { package = "nalgebra", version = "0.30", optional = true }

bevy-inspector-egui-derive = { version = "0.7.1", path = "bevy-inspector-egui-derive" }
rand = "0.8"
Expand All @@ -44,14 +40,6 @@ bevy = { version = "0.6", default-features = false, features = ["x11", "bevy_win
noise = "0.7"
once_cell = "1.0"

# [[example]]
# name = "rapier"
# required-features = ["rapier"]

[[example]]
name = "rapier2d"
# required-features = ["rapier2d"]

[[example]]
name = "texture"
required-features = ["bevy/png"]
Expand All @@ -60,3 +48,9 @@ required-features = ["bevy/png"]
name = "world"

[patch.crates-io]

[workspace]
members = [".", "bevy-inspector-egui-derive", "integrations/*"]

[profile.dev.package."*"]
opt-level = 2
80 changes: 0 additions & 80 deletions examples/rapier.rs

This file was deleted.

88 changes: 0 additions & 88 deletions examples/rapier2d.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod list;
mod number;
mod primitives;
mod quat;
mod third_party;
mod ui;
mod vec;
pub(crate) mod with_context;
Expand All @@ -13,6 +14,3 @@ pub use primitives::{OptionAttributes, StringAttributes};
pub use quat::{QuatAttributes, QuatDisplay};
pub use vec::Vec2dAttributes;
pub use with_context::{FilterType, TextureAttributes};

#[cfg(any(feature = "rapier", feature = "rapier2d"))]
mod rapier;
4 changes: 2 additions & 2 deletions src/impls/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ impl<T> NumberAttributes<T> {
}
}
impl NumberAttributes<f32> {
pub(crate) fn positive() -> Self {
pub fn positive() -> Self {
NumberAttributes::min(0.0)
}

pub(crate) fn normalized() -> Self {
pub fn normalized() -> Self {
NumberAttributes::between(0.0, 1.0).with_speed(0.1)
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/impls/rapier/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
mod nalgebra_impls;
#[cfg(feature = "rapier2d")]
mod rapier2d_impls;
#[cfg(feature = "rapier")]
mod rapier_impls;
2 changes: 2 additions & 0 deletions src/impls/third_party/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(feature = "nalgebra030")]
mod nalgebra030;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy_egui::egui;
use nalgebra::{
storage::StorageMut, Complex, Dim, Isometry, Matrix, Quaternion, SVector, Scalar, Translation,
Unit,
use nalgebra030::{
allocator::Allocator, storage::StorageMut, Complex, DefaultAllocator, Dim, DimName, Isometry,
Matrix, OPoint, Quaternion, SVector, Scalar, Translation, Unit,
};

use crate::Inspectable;
Expand Down Expand Up @@ -47,6 +47,22 @@ impl<T: Scalar + Inspectable, R: Dim, C: Dim, S: StorageMut<T, R, C>> Inspectabl
}
}

impl<T: Scalar + Inspectable, D: DimName> Inspectable for OPoint<T, D>
where
DefaultAllocator: Allocator<T, D>,
{
type Attributes = ();

fn ui(
&mut self,
ui: &mut egui::Ui,
options: Self::Attributes,
context: &mut crate::Context,
) -> bool {
self.coords.ui(ui, options, context)
}
}

impl<T: Scalar + Inspectable, const D: usize> Inspectable for Translation<T, D> {
type Attributes = <SVector<T, D> as Inspectable>::Attributes;

Expand All @@ -69,12 +85,11 @@ impl Inspectable for Unit<Quaternion<f32>> {
_: Self::Attributes,
context: &mut crate::Context,
) -> bool {
let vec: bevy::math::Vec4 = (*self.as_vector()).into();
let mut quat = bevy::math::Quat::from(vec);
let mut quat = bevy::math::Quat::from_slice(self.as_vector().as_slice());
let changed = quat.ui(ui, Default::default(), context);
if changed {
let vec: bevy::math::Vec4 = quat.into();
let quat = Quaternion::<f32>::from_vector(vec.into());
let values: [f32; 4] = quat.into();
let quat = Quaternion::<f32>::from_vector(values.into());
let quat = Unit::<Quaternion<f32>>::new_normalize(quat);
*self = quat;
}
Expand Down Expand Up @@ -109,16 +124,16 @@ impl<T: Inspectable + Scalar, R: Inspectable, const D: usize> Inspectable for Is

ui.vertical_centered(|ui| {
crate::egui::Grid::new(context.id()).show(ui, |ui| {
ui.label("Rotation");
changed |= self
.rotation
.ui(ui, Default::default(), &mut context.with_id(0));
ui.end_row();
ui.label("Translation");
changed |= self
.translation
.ui(ui, Default::default(), &mut context.with_id(1));
ui.end_row();
ui.label("Rotation");
changed |= self
.rotation
.ui(ui, Default::default(), &mut context.with_id(0));
ui.end_row();
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/world_inspector/inspectable_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl InspectableRegistry {
/// Registers a type that doesn't need to implement [`Inspectable`](crate::Inspectable)
pub fn register_raw<T: 'static, F>(&mut self, f: F)
where
F: Fn(&mut T, &mut egui::Ui, &mut Context) -> bool + Send + Sync + 'static,
F: Fn(&mut T, &mut egui::Ui, &mut Context<'_>) -> bool + Send + Sync + 'static,
{
let type_id = TypeId::of::<T>();
let callback = Box::new(
Expand Down

0 comments on commit 90632e9

Please sign in to comment.