Skip to content

Commit

Permalink
implement SetNodeRigidBody
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Jun 30, 2024
1 parent 7d3fc88 commit d7b7db2
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 381 deletions.
31 changes: 25 additions & 6 deletions crates/unavi-scripting/src/api/wired_gltf/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use crate::{
actions::ScriptAction,
api::{
wired_input::spatial_handler::SpatialHandler,
wired_physics::wired::physics::types::{Cuboid, Shape, Sphere},
wired_physics::wired::{
math::types::Vec3,
physics::types::{RigidBodyType, Shape, Sphere},
},
},
state::StoreState,
};
Expand Down Expand Up @@ -180,11 +183,7 @@ impl HostNode for StoreState {

let collider = match collider.shape {
Shape::Sphere(Sphere { radius }) => bevy_xpbd_3d::prelude::Collider::sphere(radius),
Shape::Cuboid(Cuboid {
x_len,
y_len,
z_len,
}) => bevy_xpbd_3d::prelude::Collider::cuboid(x_len, y_len, z_len),
Shape::Cuboid(Vec3 { x, y, z }) => bevy_xpbd_3d::prelude::Collider::cuboid(x, y, z),
};

self.sender.send(ScriptAction::SetNodeCollider {
Expand Down Expand Up @@ -220,6 +219,26 @@ impl HostNode for StoreState {
self_: Resource<Node>,
value: Option<Resource<RigidBody>>,
) -> wasm_bridge::Result<()> {
if let Some(value) = &value {
let rigid_body = self.table.get(value)?;

let rigid_body = match rigid_body.rigid_body_type {
RigidBodyType::Dynamic => bevy_xpbd_3d::prelude::RigidBody::Dynamic,
RigidBodyType::Fixed => bevy_xpbd_3d::prelude::RigidBody::Static,
RigidBodyType::Kinematic => bevy_xpbd_3d::prelude::RigidBody::Kinematic,
};

self.sender.send(ScriptAction::SetNodeRigidBody {
id: self_.rep(),
rigid_body: Some(rigid_body),
})?;
} else {
self.sender.send(ScriptAction::SetNodeRigidBody {
id: self_.rep(),
rigid_body: None,
})?;
}

let node = self.table.get_mut(&self_)?;
node.rigid_body = value;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/unavi-scripting/src/api/wired_physics/rigid_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::wired::{
};

pub struct RigidBody {
rigid_body_type: RigidBodyType,
pub rigid_body_type: RigidBodyType,
}

impl RigidBody {
Expand Down
116 changes: 47 additions & 69 deletions wasm/example-wired-gltf/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,22 +1657,6 @@ pub mod wired {
}
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct Cuboid {
pub x_len: f32,
pub y_len: f32,
pub z_len: f32,
}
impl ::core::fmt::Debug for Cuboid {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("Cuboid")
.field("x-len", &self.x_len)
.field("y-len", &self.y_len)
.field("z-len", &self.z_len)
.finish()
}
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Sphere {
Expand All @@ -1687,7 +1671,7 @@ pub mod wired {
}
#[derive(Clone, Copy)]
pub enum Shape {
Cuboid(Cuboid),
Cuboid(Vec3),
Sphere(Sphere),
}
impl ::core::fmt::Debug for Shape {
Expand Down Expand Up @@ -1785,18 +1769,13 @@ pub mod wired {
unsafe {
let (result2_0, result2_1, result2_2, result2_3) = match shape {
Shape::Cuboid(e) => {
let Cuboid {
x_len: x_len0,
y_len: y_len0,
z_len: z_len0,
let super::super::super::wired::math::types::Vec3 {
x: x0,
y: y0,
z: z0,
} = e;

(
0i32,
_rt::as_f32(x_len0),
_rt::as_f32(y_len0),
_rt::as_f32(z_len0),
)
(0i32, _rt::as_f32(x0), _rt::as_f32(y0), _rt::as_f32(z0))
}
Shape::Sphere(e) => {
let Sphere { radius: radius1 } = e;
Expand Down Expand Up @@ -2514,8 +2493,8 @@ pub(crate) use __export_script_impl as export;
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.25.0:script:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 3153] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xd4\x17\x01A\x02\x01\
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 3117] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb0\x17\x01A\x02\x01\
A\x16\x01B\x16\x01r\x04\x01rv\x01gv\x01bv\x01av\x04\0\x05color\x03\0\0\x04\0\x08\
material\x03\x01\x01h\x02\x01@\x01\x04self\x03\0y\x04\0\x13[method]material.id\x01\
\x04\x01@\x01\x04self\x03\0s\x04\0\x15[method]material.name\x01\x05\x01@\x02\x04\
Expand Down Expand Up @@ -2547,46 +2526,45 @@ ve-mesh\x01\x1d\x03\x01\x0fwired:gltf/mesh\x05\x02\x01B\x06\x01r\x03\x01xv\x01yv
\x04vec3\x01B\x09\x02\x03\x02\x01\x04\x04\0\x04mesh\x03\0\0\x02\x03\x02\x01\x05\x04\
\0\x04vec3\x03\0\x02\x01i\x01\x01@\x01\x04size\x03\0\x04\x04\0\x0dcreate-cuboid\x01\
\x05\x01@\x03\x06radiusv\x07sectorsy\x06stacksy\0\x04\x04\0\x0dcreate-sphere\x01\
\x06\x03\x01\x10unavi:shapes/api\x05\x06\x01B\x1e\x02\x03\x02\x01\x05\x04\0\x04v\
ec3\x03\0\0\x04\0\x08collider\x03\x01\x01r\x03\x05x-lenv\x05y-lenv\x05z-lenv\x04\
\0\x06cuboid\x03\0\x03\x01r\x01\x06radiusv\x04\0\x06sphere\x03\0\x05\x01q\x02\x06\
cuboid\x01\x04\0\x06sphere\x01\x06\0\x04\0\x05shape\x03\0\x07\x04\0\x0arigid-bod\
y\x03\x01\x01m\x03\x07dynamic\x05fixed\x09kinematic\x04\0\x0frigid-body-type\x03\
\0\x0a\x01i\x02\x01@\x01\x05shape\x08\0\x0c\x04\0\x15[constructor]collider\x01\x0d\
\x01h\x02\x01@\x01\x04self\x0e\0v\x04\0\x18[method]collider.density\x01\x0f\x01@\
\x02\x04self\x0e\x05valuev\x01\0\x04\0\x1c[method]collider.set-density\x01\x10\x01\
i\x09\x01@\x01\x0frigid-body-type\x0b\0\x11\x04\0\x17[constructor]rigid-body\x01\
\x12\x01h\x09\x01@\x01\x04self\x13\0\x01\x04\0\x19[method]rigid-body.angvel\x01\x14\
\x01@\x02\x04self\x13\x05value\x01\x01\0\x04\0\x1d[method]rigid-body.set-angvel\x01\
\x15\x04\0\x19[method]rigid-body.linvel\x01\x14\x04\0\x1d[method]rigid-body.set-\
linvel\x01\x15\x03\x01\x13wired:physics/types\x05\x07\x02\x03\0\x02\x09transform\
\x02\x03\0\x04\x08collider\x02\x03\0\x04\x0arigid-body\x01B<\x02\x03\x02\x01\x04\
\x04\0\x04mesh\x03\0\0\x02\x03\x02\x01\x08\x04\0\x09transform\x03\0\x02\x02\x03\x02\
\x01\x09\x04\0\x08collider\x03\0\x04\x02\x03\x02\x01\x0a\x04\0\x0arigid-body\x03\
\0\x06\x04\0\x04node\x03\x01\x01h\x08\x01@\x01\x04self\x09\0y\x04\0\x0f[method]n\
ode.id\x01\x0a\x01@\x01\x04self\x09\0s\x04\0\x11[method]node.name\x01\x0b\x01@\x02\
\x04self\x09\x05values\x01\0\x04\0\x15[method]node.set-name\x01\x0c\x01i\x08\x01\
p\x0d\x01@\x01\x04self\x09\0\x0e\x04\0\x15[method]node.children\x01\x0f\x01@\x02\
\x04self\x09\x05value\x09\x01\0\x04\0\x16[method]node.add-child\x01\x10\x04\0\x19\
[method]node.remove-child\x01\x10\x01k\x0d\x01@\x01\x04self\x09\0\x11\x04\0\x13[\
method]node.parent\x01\x12\x01@\x01\x04self\x09\0\x03\x04\0\x16[method]node.tran\
sform\x01\x13\x01@\x02\x04self\x09\x05value\x03\x01\0\x04\0\x1a[method]node.set-\
transform\x01\x14\x01i\x01\x01k\x15\x01@\x01\x04self\x09\0\x16\x04\0\x11[method]\
node.mesh\x01\x17\x01h\x01\x01k\x18\x01@\x02\x04self\x09\x05value\x19\x01\0\x04\0\
\x15[method]node.set-mesh\x01\x1a\x01i\x05\x01k\x1b\x01@\x01\x04self\x09\0\x1c\x04\
\0\x15[method]node.collider\x01\x1d\x01h\x05\x01k\x1e\x01@\x02\x04self\x09\x05va\
lue\x1f\x01\0\x04\0\x19[method]node.set-collider\x01\x20\x01i\x07\x01k!\x01@\x01\
\x04self\x09\0\"\x04\0\x17[method]node.rigid-body\x01#\x01h\x07\x01k$\x01@\x02\x04\
self\x09\x05value%\x01\0\x04\0\x1b[method]node.set-rigid-body\x01&\x01@\0\0\x0e\x04\
\0\x0alist-nodes\x01'\x01@\0\0\x0d\x04\0\x0bcreate-node\x01(\x01@\x01\x05value\x0d\
\x01\0\x04\0\x0bremove-node\x01)\x03\x01\x0fwired:gltf/node\x05\x0b\x01B\x04\x01\
m\x04\x05debug\x04info\x04warn\x05error\x04\0\x09log-level\x03\0\0\x01@\x02\x05l\
evel\x01\x07messages\x01\0\x04\0\x03log\x01\x02\x03\x01\x0dwired:log/api\x05\x0c\
\x01B\x07\x04\0\x06script\x03\x01\x01i\0\x01@\0\0\x01\x04\0\x13[constructor]scri\
pt\x01\x02\x01h\0\x01@\x02\x04self\x03\x05deltav\x01\0\x04\0\x15[method]script.u\
pdate\x01\x04\x04\x01\x12wired:script/types\x05\x0d\x04\x01\x19example:wired-glt\
f/script\x04\0\x0b\x0c\x01\0\x06script\x03\0\0\0G\x09producers\x01\x0cprocessed-\
by\x02\x0dwit-component\x070.208.1\x10wit-bindgen-rust\x060.25.0";
\x06\x03\x01\x10unavi:shapes/api\x05\x06\x01B\x1c\x02\x03\x02\x01\x05\x04\0\x04v\
ec3\x03\0\0\x04\0\x08collider\x03\x01\x01r\x01\x06radiusv\x04\0\x06sphere\x03\0\x03\
\x01q\x02\x06cuboid\x01\x01\0\x06sphere\x01\x04\0\x04\0\x05shape\x03\0\x05\x04\0\
\x0arigid-body\x03\x01\x01m\x03\x07dynamic\x05fixed\x09kinematic\x04\0\x0frigid-\
body-type\x03\0\x08\x01i\x02\x01@\x01\x05shape\x06\0\x0a\x04\0\x15[constructor]c\
ollider\x01\x0b\x01h\x02\x01@\x01\x04self\x0c\0v\x04\0\x18[method]collider.densi\
ty\x01\x0d\x01@\x02\x04self\x0c\x05valuev\x01\0\x04\0\x1c[method]collider.set-de\
nsity\x01\x0e\x01i\x07\x01@\x01\x0frigid-body-type\x09\0\x0f\x04\0\x17[construct\
or]rigid-body\x01\x10\x01h\x07\x01@\x01\x04self\x11\0\x01\x04\0\x19[method]rigid\
-body.angvel\x01\x12\x01@\x02\x04self\x11\x05value\x01\x01\0\x04\0\x1d[method]ri\
gid-body.set-angvel\x01\x13\x04\0\x19[method]rigid-body.linvel\x01\x12\x04\0\x1d\
[method]rigid-body.set-linvel\x01\x13\x03\x01\x13wired:physics/types\x05\x07\x02\
\x03\0\x02\x09transform\x02\x03\0\x04\x08collider\x02\x03\0\x04\x0arigid-body\x01\
B<\x02\x03\x02\x01\x04\x04\0\x04mesh\x03\0\0\x02\x03\x02\x01\x08\x04\0\x09transf\
orm\x03\0\x02\x02\x03\x02\x01\x09\x04\0\x08collider\x03\0\x04\x02\x03\x02\x01\x0a\
\x04\0\x0arigid-body\x03\0\x06\x04\0\x04node\x03\x01\x01h\x08\x01@\x01\x04self\x09\
\0y\x04\0\x0f[method]node.id\x01\x0a\x01@\x01\x04self\x09\0s\x04\0\x11[method]no\
de.name\x01\x0b\x01@\x02\x04self\x09\x05values\x01\0\x04\0\x15[method]node.set-n\
ame\x01\x0c\x01i\x08\x01p\x0d\x01@\x01\x04self\x09\0\x0e\x04\0\x15[method]node.c\
hildren\x01\x0f\x01@\x02\x04self\x09\x05value\x09\x01\0\x04\0\x16[method]node.ad\
d-child\x01\x10\x04\0\x19[method]node.remove-child\x01\x10\x01k\x0d\x01@\x01\x04\
self\x09\0\x11\x04\0\x13[method]node.parent\x01\x12\x01@\x01\x04self\x09\0\x03\x04\
\0\x16[method]node.transform\x01\x13\x01@\x02\x04self\x09\x05value\x03\x01\0\x04\
\0\x1a[method]node.set-transform\x01\x14\x01i\x01\x01k\x15\x01@\x01\x04self\x09\0\
\x16\x04\0\x11[method]node.mesh\x01\x17\x01h\x01\x01k\x18\x01@\x02\x04self\x09\x05\
value\x19\x01\0\x04\0\x15[method]node.set-mesh\x01\x1a\x01i\x05\x01k\x1b\x01@\x01\
\x04self\x09\0\x1c\x04\0\x15[method]node.collider\x01\x1d\x01h\x05\x01k\x1e\x01@\
\x02\x04self\x09\x05value\x1f\x01\0\x04\0\x19[method]node.set-collider\x01\x20\x01\
i\x07\x01k!\x01@\x01\x04self\x09\0\"\x04\0\x17[method]node.rigid-body\x01#\x01h\x07\
\x01k$\x01@\x02\x04self\x09\x05value%\x01\0\x04\0\x1b[method]node.set-rigid-body\
\x01&\x01@\0\0\x0e\x04\0\x0alist-nodes\x01'\x01@\0\0\x0d\x04\0\x0bcreate-node\x01\
(\x01@\x01\x05value\x0d\x01\0\x04\0\x0bremove-node\x01)\x03\x01\x0fwired:gltf/no\
de\x05\x0b\x01B\x04\x01m\x04\x05debug\x04info\x04warn\x05error\x04\0\x09log-leve\
l\x03\0\0\x01@\x02\x05level\x01\x07messages\x01\0\x04\0\x03log\x01\x02\x03\x01\x0d\
wired:log/api\x05\x0c\x01B\x07\x04\0\x06script\x03\x01\x01i\0\x01@\0\0\x01\x04\0\
\x13[constructor]script\x01\x02\x01h\0\x01@\x02\x04self\x03\x05deltav\x01\0\x04\0\
\x15[method]script.update\x01\x04\x04\x01\x12wired:script/types\x05\x0d\x04\x01\x19\
example:wired-gltf/script\x04\0\x0b\x0c\x01\0\x06script\x03\0\0\0G\x09producers\x01\
\x0cprocessed-by\x02\x0dwit-component\x070.208.1\x10wit-bindgen-rust\x060.25.0";

#[inline(never)]
#[doc(hidden)]
Expand Down
Loading

0 comments on commit d7b7db2

Please sign in to comment.