-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
fixed_joint_3d.rs
65 lines (58 loc) · 1.83 KB
/
fixed_joint_3d.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use avian3d::{math::*, prelude::*};
use bevy::prelude::*;
use examples_common_3d::ExampleCommonPlugin;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
ExampleCommonPlugin,
PhysicsPlugins::default(),
))
.insert_resource(ClearColor(Color::srgb(0.05, 0.05, 0.1)))
.insert_resource(SubstepCount(50))
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
) {
let cube_mesh = meshes.add(Cuboid::default());
let cube_material = materials.add(Color::srgb(0.8, 0.7, 0.6));
// Kinematic rotating "anchor" object
let anchor = commands
.spawn((
Mesh3d(cube_mesh.clone()),
MeshMaterial3d(cube_material.clone()),
RigidBody::Kinematic,
AngularVelocity(Vector::Z * 1.5),
))
.id();
// Dynamic object rotating around anchor
let object = commands
.spawn((
Mesh3d(cube_mesh),
MeshMaterial3d(cube_material),
Transform::from_xyz(1.5, 0.0, 0.0),
RigidBody::Dynamic,
MassPropertiesBundle::new_computed(&Collider::cuboid(1.0, 1.0, 1.0), 1.0),
))
.id();
// Connect anchor and dynamic object
commands.spawn(FixedJoint::new(anchor, object).with_local_anchor_1(Vector::X * 1.5));
// Directional light
commands.spawn((
DirectionalLight {
illuminance: 2000.0,
shadows_enabled: true,
..default()
},
Transform::default().looking_at(Vec3::new(-1.0, -2.5, -1.5), Vec3::Y),
));
// Camera
commands.spawn((
Camera3d::default(),
Transform::from_translation(Vec3::Z * 10.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}