Skip to content

Commit 4916357

Browse files
authored
Twix mujoco visualizer (#2143)
* Add kinematics to sensor_data_receiver * Add bevy rendering to twix * Parse mujoco scene in twix * Use egui fork * Make meshes not fuchsia anymore * Compute normals to get proper lighting * Its alive!!!! * Request redraw when an update arrives * Retry connection until it succeeds * Fix axes * Extract processing scene updates from ui function * Implement resizing of the viewport * Use physical pixels instead of logical ui coordinates to calculate texture size * Forward necessary egui input to bevy to get pan-orbit-camera working * Rotate the scene instead of placing the camera weirdly to fix the pan-orbit-camera * Disable unimplemented events for now to prevent todo!()-crashes * Fix lints * Don't rotate everything all the time * Turn the robot right-side-up * Ignore input which does not belong to the bevy view * Request and receive initial scene description via websocket * Don't load /tmp/scene at startup * Forward mouse wheel events from egui to bevy to allow zooming the camera * Use github fork of egui for patching crates.io * Fix clippy lints: twix * Port bevyhavior_simulator to bevy 0.16 * Draw gizmo at left wrist joint * Draw remaining joints * Attach trunk frame to the trunk body instead of the trunk mesh * Fix toml issues * Remove unused code for simulator control * Use logging * Yeet js visualizer * Shorten websocket URL * Deduplicate between camera creation and camera update * Replace unwrap with expect * Replace Vec of known size with array * Check body name for "Trunk" instead of checking each mesh name * Address Ole review comments
1 parent d0c6c31 commit 4916357

73 files changed

Lines changed: 2337 additions & 1919 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1046 additions & 259 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ bat = { version = "0.25.0", default-features = false, features = [
8989
"paging",
9090
"regex-fancy",
9191
] }
92-
bevy = { version = "0.15.2", default-features = false }
92+
bevy = { version = "0.16.0", default-features = false }
9393
bevy-inspector-egui = "0.29.1"
9494
bevy_asset_loader = "0.22.0"
9595
bevy_egui = "0.33.0"
9696
bevy_obj = "0.15"
97-
bevy_panorbit_camera = { version = "0.23.0", features = ["bevy_egui"] }
97+
bevy_panorbit_camera = { version = "0.26.0", features = ["bevy_egui"] }
9898
bincode = "1.3.3"
9999
bindgen = "0.71.1"
100100
blake3 = { version = "1.8.2", features = ["mmap", "serde"] }
@@ -122,10 +122,10 @@ derive_more = { version = "2.0.1", features = [
122122
"not",
123123
] }
124124
dirs = "6.0.0"
125-
eframe = { version = "0.31.0", features = ["persistence"] }
126-
egui = { version = "0.31.0", features = ["persistence"] }
125+
eframe = { version = "0.31.1", features = ["persistence", "wgpu"] }
126+
egui = { version = "=0.31.1", features = ["persistence"] }
127127
egui_dock = { version = "0.16.0", features = ["serde"] }
128-
egui_extras = { version = "0.31.0", features = ["image"] }
128+
egui_extras = { version = "0.31.1", features = ["image"] }
129129
egui_plot = "0.31.0"
130130
energy_optimization = { path = "crates/energy_optimization" }
131131
enum-iterator = "2.1.0"
@@ -160,7 +160,11 @@ log = "0.4.25"
160160
mcap = "0.15.0"
161161
mlua = { version = "0.10.3", features = ["luajit", "serialize", "vendored"] }
162162
motionfile = { path = "crates/motionfile" }
163-
nalgebra = { version = "0.33.2", features = ["serde", "serde-serialize"] }
163+
nalgebra = { version = "0.33.2", features = [
164+
"convert-glam029",
165+
"serde",
166+
"serde-serialize",
167+
] }
164168
nao = { path = "crates/nao" }
165169
ndarray = { version = "0.16.1", features = ["serde"] }
166170
ndarray-conv = "0.4.1"
@@ -261,6 +265,9 @@ serde_derive = { git = "https://github.com/HULKs/serde.git", rev = "ef30eb8fdd0e
261265
# Pinned to forked serde version since https://github.com/serde-rs/serde/pull/2513 is not merged
262266
serde_core = { git = "https://github.com/HULKs/serde.git", rev = "ef30eb8fdd0ee12e4e6f3f5615c6bb022e02d1b2" }
263267

268+
egui = { git = "https://github.com/HULKs/egui/", rev = "7a3a88dcbb46a24d49a2388b2d9c8a6a273a9d4e" }
269+
egui-wgpu = { git = "https://github.com/HULKs/egui/", rev = "7a3a88dcbb46a24d49a2388b2d9c8a6a273a9d4e" }
270+
264271
[profile.dev]
265272
opt-level = 3
266273
debug = false

crates/bevyhavior_simulator/src/autoref.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use bevy::{
44
app::{App, Update},
55
ecs::{
66
event::{EventReader, EventWriter},
7-
schedule::IntoSystemConfigs,
8-
system::{Query, ResMut, Resource},
7+
resource::Resource,
8+
schedule::IntoScheduleConfigs,
9+
system::{Query, ResMut},
910
},
1011
prelude::Res,
1112
time::{Time, Timer, TimerMode},
@@ -87,7 +88,7 @@ pub fn autoref(
8788
.as_ref()
8889
.is_some_and(|timer| timer.finished())
8990
{
90-
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Set));
91+
game_controller_commands.write(GameControllerCommand::SetGameState(GameState::Set));
9192
}
9293
}
9394
GameState::Set => {
@@ -103,7 +104,7 @@ pub fn autoref(
103104
{
104105
match state.goal_mode {
105106
GoalMode::GoToReady => {
106-
game_controller_commands.send(GameControllerCommand::Goal(scoring_team));
107+
game_controller_commands.write(GameControllerCommand::Goal(scoring_team));
107108
ball.state = None;
108109
}
109110
GoalMode::ReturnBall => {

crates/bevyhavior_simulator/src/bin/ball_search.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn startup(
3333
] {
3434
commands.spawn(Robot::new(number));
3535
}
36-
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
36+
game_controller_commands.write(GameControllerCommand::SetGameState(GameState::Ready));
3737
}
3838

3939
fn update(
@@ -44,7 +44,7 @@ fn update(
4444
mut ball: ResMut<BallResource>,
4545
) {
4646
if time.ticks() == 5000 {
47-
game_controller_commands.send(GameControllerCommand::SetSubState(
47+
game_controller_commands.write(GameControllerCommand::SetSubState(
4848
Some(SubState::CornerKick),
4949
Team::Opponent,
5050
None,
@@ -58,10 +58,10 @@ fn update(
5858
}
5959
if game_controller.state.hulks_team.score > 0 {
6060
println!("Done");
61-
exit.send(AppExit::Success);
61+
exit.write(AppExit::Success);
6262
}
6363
if time.ticks() >= 20_000 {
6464
println!("No goal was scored :(");
65-
exit.send(AppExit::from_code(1));
65+
exit.write(AppExit::from_code(1));
6666
}
6767
}

crates/bevyhavior_simulator/src/bin/defender_positioning.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn startup(
3333
] {
3434
commands.spawn(Robot::new(number));
3535
}
36-
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
36+
game_controller_commands.write(GameControllerCommand::SetGameState(GameState::Ready));
3737
}
3838

3939
fn update(time: Res<Time<Ticks>>, mut ball: ResMut<BallResource>, mut exit: EventWriter<AppExit>) {
@@ -59,6 +59,6 @@ fn update(time: Res<Time<Ticks>>, mut ball: ResMut<BallResource>, mut exit: Even
5959
}
6060

6161
if time.ticks() == 30000 {
62-
exit.send(AppExit::Success);
62+
exit.write(AppExit::Success);
6363
}
6464
}

crates/bevyhavior_simulator/src/bin/demonstration.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn startup(
3333
] {
3434
commands.spawn(Robot::new(number));
3535
}
36-
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
36+
game_controller_commands.write(GameControllerCommand::SetGameState(GameState::Ready));
3737
}
3838

3939
/// Allows for checks to run during the scenario such that it can be decided whether the scenario passes or fails.
@@ -56,17 +56,17 @@ fn update(
5656
// Scenarios can pass if a certain condition is met
5757
if game_controller.state.hulks_team.score > 0 {
5858
println!("Done");
59-
exit.send(AppExit::Success);
59+
exit.write(AppExit::Success);
6060
}
6161
// Or fail based on a certain condition, such as if scoring takes too long
6262
if time.ticks() >= 20_000 {
6363
println!("No goal was scored :(");
64-
exit.send(AppExit::from_code(1));
64+
exit.write(AppExit::from_code(1));
6565
}
6666
// Based on time or other conditions you can modify the game state
6767
if time.ticks() == 6000 {
6868
// Set substate
69-
game_controller_commands.send(GameControllerCommand::SetSubState(
69+
game_controller_commands.write(GameControllerCommand::SetSubState(
7070
Some(SubState::PushingFreeKick),
7171
Team::Opponent,
7272
Some(PlayerNumber::Four),

crates/bevyhavior_simulator/src/bin/deny_keeper_ballsearch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn startup(
2727
for number in [PlayerNumber::One, PlayerNumber::Seven] {
2828
commands.spawn(Robot::new(number));
2929
}
30-
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
30+
game_controller_commands.write(GameControllerCommand::SetGameState(GameState::Ready));
3131
}
3232

3333
fn update(
@@ -54,7 +54,7 @@ fn update(
5454
PlayerNumber::Six,
5555
PlayerNumber::Seven,
5656
] {
57-
game_controller_commands.send(GameControllerCommand::Penalize(
57+
game_controller_commands.write(GameControllerCommand::Penalize(
5858
player_numer,
5959
penalty,
6060
Team::Hulks,
@@ -76,10 +76,10 @@ fn update(
7676
== Some(Action::Search)
7777
{
7878
println!("Keeper tried to enter ball search");
79-
exit.send(AppExit::from_code(1));
79+
exit.write(AppExit::from_code(1));
8080
}
8181
if time.ticks() >= 10_000 {
8282
println!("Done");
83-
exit.send(AppExit::Success);
83+
exit.write(AppExit::Success);
8484
}
8585
}

crates/bevyhavior_simulator/src/bin/flickering_ball.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn startup(
3232
robot.simulator_parameters.ball_timeout_factor = 0.001;
3333
commands.spawn(robot);
3434
}
35-
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
35+
game_controller_commands.write(GameControllerCommand::SetGameState(GameState::Ready));
3636
}
3737

3838
fn update(
@@ -47,10 +47,10 @@ fn update(
4747
}
4848
if game_controller.state.hulks_team.score > 0 {
4949
println!("Done");
50-
exit.send(AppExit::Success);
50+
exit.write(AppExit::Success);
5151
}
5252
if time.ticks() >= 20_000 {
5353
println!("No goal was scored :(");
54-
exit.send(AppExit::from_code(1));
54+
exit.write(AppExit::from_code(1));
5555
}
5656
}

crates/bevyhavior_simulator/src/bin/goal_kicks.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn startup(
3030
] {
3131
commands.spawn(Robot::new(number));
3232
}
33-
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
33+
game_controller_commands.write(GameControllerCommand::SetGameState(GameState::Ready));
3434
}
3535

3636
fn update(
@@ -40,25 +40,25 @@ fn update(
4040
mut exit: EventWriter<AppExit>,
4141
) {
4242
if time.ticks() == 3000 {
43-
game_controller_commands.send(GameControllerCommand::SetSubState(
43+
game_controller_commands.write(GameControllerCommand::SetSubState(
4444
Some(SubState::GoalKick),
4545
Team::Hulks,
4646
None,
4747
));
4848
}
4949
if time.ticks() == 5000 {
50-
game_controller_commands.send(GameControllerCommand::SetSubState(
50+
game_controller_commands.write(GameControllerCommand::SetSubState(
5151
Some(SubState::GoalKick),
5252
Team::Opponent,
5353
None,
5454
));
5555
}
5656
if game_controller.state.hulks_team.score > 0 {
5757
println!("Done");
58-
exit.send(AppExit::Success);
58+
exit.write(AppExit::Success);
5959
}
6060
if time.ticks() >= 10_000 {
6161
println!("No goal was scored :(");
62-
exit.send(AppExit::from_code(1));
62+
exit.write(AppExit::from_code(1));
6363
}
6464
}

crates/bevyhavior_simulator/src/bin/golden_goal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn startup(
3030
] {
3131
commands.spawn(Robot::new(number));
3232
}
33-
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
33+
game_controller_commands.write(GameControllerCommand::SetGameState(GameState::Ready));
3434
}
3535

3636
fn update(
@@ -40,10 +40,10 @@ fn update(
4040
) {
4141
if game_controller.state.hulks_team.score > 0 {
4242
println!("Done");
43-
exit.send(AppExit::Success);
43+
exit.write(AppExit::Success);
4444
}
4545
if time.ticks() >= 10_000 {
4646
println!("No goal was scored :(");
47-
exit.send(AppExit::from_code(1));
47+
exit.write(AppExit::from_code(1));
4848
}
4949
}

0 commit comments

Comments
 (0)