diff --git a/README.md b/README.md index cab3f77..68dee4f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Godot Rapier 3D +## Roadmap + +- [] Editor gizmos for collider shapes +- [] Serialize/deserialize physics state to/from variable +- [] Save/load physics state to/from resource file + ## Contributing See [CONTRIBUTING.md]() @@ -10,12 +16,11 @@ Inspired by [ilyas-taouaou/rapier-gdext](https://github.com/ilyas-taouaou/rapier ## TODO -1. Visualise colliders +1. collision shapes as resource +1. Simple example 1. On init, register all found rigid bodies and colliders -1. Save/load state -1. Switch to editor singleton for guaranteed access to scene tree? -1. Maybe wait 3 frames before step starts working to give colliders a chance to connect? (call deferred) -1. refactor engine singleton function to include pipeline retrieval +1. Maybe wait 3 frames before step starts working to give colliders a chance to connect? (call deferred) (document this in readme) +1. refactor utils engine singleton function to include pipeline retrieval ## Saving/loading diff --git a/addons/godot-rapier-3d/src/gdscript/shapes/RapierBallShape3D.gd b/addons/godot-rapier-3d/src/gdscript/shapes/RapierBallShape3D.gd new file mode 100644 index 0000000..12fcac8 --- /dev/null +++ b/addons/godot-rapier-3d/src/gdscript/shapes/RapierBallShape3D.gd @@ -0,0 +1,3 @@ +extends RapierShape3D + +@export var radius := 1.0 diff --git a/addons/godot-rapier-3d/src/gdscript/shapes/RapierCuboidShape3D.gd b/addons/godot-rapier-3d/src/gdscript/shapes/RapierCuboidShape3D.gd new file mode 100644 index 0000000..659fc7f --- /dev/null +++ b/addons/godot-rapier-3d/src/gdscript/shapes/RapierCuboidShape3D.gd @@ -0,0 +1,3 @@ +extends RapierShape3D + +@export var half_extents := Vector3(0.5, 0.5, 0.5) diff --git a/addons/godot-rapier-3d/src/gdscript/shapes/RapierShape3D.gd b/addons/godot-rapier-3d/src/gdscript/shapes/RapierShape3D.gd new file mode 100644 index 0000000..59fd261 --- /dev/null +++ b/addons/godot-rapier-3d/src/gdscript/shapes/RapierShape3D.gd @@ -0,0 +1,3 @@ +extends Resource +class_name RapierShape3D + diff --git a/addons/godot-rapier-3d/src/rust/collider.rs b/addons/godot-rapier-3d/src/rust/collider.rs index 775d356..359e636 100644 --- a/addons/godot-rapier-3d/src/rust/collider.rs +++ b/addons/godot-rapier-3d/src/rust/collider.rs @@ -3,9 +3,8 @@ use crate::rigid_body::RapierRigidBody3D; use godot::engine::notify::Node3DNotification; use godot::engine::INode3D; use godot::engine::Node3D; +use godot::engine::Shape3D; use godot::prelude::*; -use nalgebra::geometry::OPoint; -use nalgebra::Vector3 as NAVector3; use rapier3d::prelude::*; #[derive(GodotClass)] @@ -14,8 +13,12 @@ pub struct RapierCollider3D { #[var] pub id: Array, // ColliderHandle::into_raw_parts pub handle: ColliderHandle, + #[export] - pub shape: ShapeType, + #[var( + usage_flags = [DEFAULT, EDITOR_INSTANTIATE_OBJECT] + )] + pub shape: Option>, pub parent: Option, notify_parent: bool, base: Base, @@ -27,7 +30,7 @@ impl INode3D for RapierCollider3D { Self { id: Array::new(), handle: ColliderHandle::invalid(), - shape: ShapeType::Ball, + shape: None, parent: None, notify_parent: true, base, @@ -178,23 +181,25 @@ impl RapierCollider3D { } pub fn build(&self) -> Collider { - let shape = match self.shape { - ShapeType::Ball => SharedShape::ball(0.5), - ShapeType::Cuboid => SharedShape::cuboid(10.0, 1.0, 10.0), - ShapeType::Capsule => { - SharedShape::capsule(OPoint::origin(), OPoint::from(NAVector3::y()), 0.5) - } - }; - let collider = ColliderBuilder::new(shape).restitution(0.7).build(); + // let shape = match self.shape { + // ShapeType::Ball => SharedShape::ball(0.5), + // ShapeType::Cuboid => SharedShape::cuboid(10.0, 1.0, 10.0), + // ShapeType::Capsule => { + // SharedShape::capsule(OPoint::origin(), OPoint::from(NAVector3::y()), 0.5) + // } + // }; + let collider = ColliderBuilder::new(SharedShape::ball(0.5)) + .restitution(0.7) + .build(); collider } } -#[derive(GodotConvert, Var, Export)] -#[godot(via = GString)] -// https://docs.rs/rapier3d/latest/rapier3d/geometry/enum.ShapeType.html -pub enum ShapeType { - Ball, - Cuboid, - Capsule, -} +// #[derive(GodotConvert, Var, Export)] +// #[godot(via = GString)] +// // https://docs.rs/rapier3d/latest/rapier3d/geometry/enum.ShapeType.html +// pub enum ShapeType { +// Ball, +// Cuboid, +// Capsule, +// } diff --git a/addons/godot-rapier-3d/src/rust/utils.rs b/addons/godot-rapier-3d/src/rust/utils.rs index 3a7e2c7..298e1a7 100644 --- a/addons/godot-rapier-3d/src/rust/utils.rs +++ b/addons/godot-rapier-3d/src/rust/utils.rs @@ -1,4 +1,4 @@ -use crate::Rapier3DSingleton; +use crate::singleton::Rapier3DSingleton; use godot::builtin::Array as GArray; use godot::builtin::Quaternion as GQuaternion; use godot::builtin::Vector3 as GVector; diff --git a/examples/main.tscn b/examples/main.tscn index 27f7308..3e1bc7c 100644 --- a/examples/main.tscn +++ b/examples/main.tscn @@ -40,6 +40,7 @@ rotation_order = 0 visible = false [node name="Ground" parent="." instance=ExtResource("3_ayqm6")] +shape = null editor_description = "" transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0) rotation_order = 0