Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
//! bevy_rapier3d (docs/plugins.feature PL3). What had to be written by hand: rapier's Collider holds a shape object
//! and isn't reflected upstream, so a body spawned from TypeScript could have no collider.
//! `ColliderShape` is a reflected component of ours that builds the Collider from plain numbers when it's added or
//! changed; RigidBody, Velocity, Friction and the rest are rapier's own, reflected.
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
/// A collider's shape, built into rapier's Collider on the entity it's on (metres).
#[derive(Component, Reflect, Clone, Debug)]
#[reflect(Component, Default)]
pub enum ColliderShape {
Ball { radius: f32 },
/// half of its size on each axis
Cuboid { half_size: Vec3 },
/// along y: half the straight part's height, and the radius of its ends
Capsule { half_height: f32, radius: f32 },
/// along y
Cylinder { half_height: f32, radius: f32 },
}
impl Default for ColliderShape {
fn default() -> Self {
Self::Ball { radius: 0.5 }
}
}
rapier_adapter!("rapier3d");
fn build_colliders(changed: Query<(Entity, &ColliderShape), Changed<ColliderShape>>, mut commands: Commands) {
for (e, s) in &changed {
let c = match *s {
ColliderShape::Ball { radius } => Collider::ball(radius),
ColliderShape::Cuboid { half_size: h } => Collider::cuboid(h.x, h.y, h.z),
ColliderShape::Capsule { half_height, radius } => Collider::capsule_y(half_height, radius),
ColliderShape::Cylinder { half_height, radius } => Collider::cylinder(half_height, radius),
};
commands.entity(e).insert(c);
}
}