Skip to content

Commit 08ef892

Browse files
committed
Implemented mirror functionality to overlay
1 parent 9eff429 commit 08ef892

File tree

4 files changed

+163
-72
lines changed

4 files changed

+163
-72
lines changed

CONTRIBUTING.md

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
# Contributing
2-
3-
Thanks for being interested in contributing to this project! This document describes
4-
what you need to know to get started with the code.
5-
6-
7-
## Installing the dependencies
8-
9-
First, install the `Rust` programming language by following the instructions at
10-
[rustup.rs](https://rustup.rs).
11-
12-
Next, install `libclang`, which is used by the
13-
[`ovr_overlay`](https://crates.io/crates/ovr_overlay) bindings for OpenVR. For windows,
14-
use [this] link. For Linux, simply `sudo apt-get install -y libclang-dev`.
15-
16-
[this]: https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.5/LLVM-14.0.5-win64.exe
17-
18-
You will also need SteamVR installed.
19-
20-
### Steam Deck
21-
22-
If you are building on the steam deck, be sure that you have all the necessary libraries
23-
for native development installed. To get them, follow [these] instructions.
24-
25-
[these]: https://www.reddit.com/r/SteamDeck/comments/t92ozw/for_compiling_c_code/
26-
27-
28-
## Building
29-
30-
`cargo` is the build tool for rust. You can `cargo run` to run the code, `cargo check`
31-
to check if your code compiles, and `cargo test` to run tests. You can also do
32-
`--release` to generate an optimized release mode version. This will take longer to
33-
compile but will run significantly faster.
34-
35-
36-
## Documentation
37-
38-
Documentation is autogenerated by cargo and can be viewed in a web browser with
39-
`cargo doc --all --open --no-deps --document-private-items`. You can run
40-
`cargo doc --help` to learn more about what those flags do. The documentation is also
41-
automatically published to github pages for every commit on the `main` branch [here].
42-
43-
[here]: https://slimevr.github.io/SlimeVR-Overlay/skeletal_model
44-
45-
46-
## Code Style
47-
48-
All code is autoformatted by `cargo fmt`. We suggest turning on autoformatting on save
49-
in your IDE, otherwise you can just run `cargo fmt` on the command line. Also, all files
50-
should end in a newline and have extra whitespace trimmed.
51-
52-
Its also a good idea to run `cargo clippy` to fix the style lints it generates.
1+
# Contributing
2+
3+
Thanks for being interested in contributing to this project! This document describes
4+
what you need to know to get started with the code.
5+
6+
7+
## Installing the dependencies
8+
9+
First, install the `Rust` programming language by following the instructions at
10+
[rustup.rs](https://rustup.rs).
11+
12+
Next, install `libclang`, which is used by the
13+
[`ovr_overlay`](https://crates.io/crates/ovr_overlay) bindings for OpenVR. For windows,
14+
use [this] link. For Linux, simply `sudo apt-get install -y libclang-dev`.
15+
16+
[this]: https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.5/LLVM-14.0.5-win64.exe
17+
18+
You will also need SteamVR installed.
19+
20+
### Steam Deck
21+
22+
If you are building on the steam deck, be sure that you have all the necessary libraries
23+
for native development installed. To get them, follow [these] instructions.
24+
25+
[these]: https://www.reddit.com/r/SteamDeck/comments/t92ozw/for_compiling_c_code/
26+
27+
28+
## Building
29+
30+
`cargo` is the build tool for rust. You can `cargo run` to run the code, `cargo check`
31+
to check if your code compiles, and `cargo test` to run tests. You can also do
32+
`--release` to generate an optimized release mode version. This will take longer to
33+
compile but will run significantly faster.
34+
35+
36+
## Documentation
37+
38+
Documentation is autogenerated by cargo and can be viewed in a web browser with
39+
`cargo doc --all --open --no-deps --document-private-items`. You can run
40+
`cargo doc --help` to learn more about what those flags do. The documentation is also
41+
automatically published to github pages for every commit on the `main` branch [here].
42+
43+
[here]: https://slimevr.github.io/SlimeVR-Overlay/skeletal_model
44+
45+
46+
## Code Style
47+
48+
All code is autoformatted by `cargo fmt`. We suggest turning on autoformatting on save
49+
in your IDE, otherwise you can just run `cargo fmt` on the command line. Also, all files
50+
should end in a newline and have extra whitespace trimmed.
51+
52+
Its also a good idea to run `cargo clippy` to fix the style lints it generates.

autoupdater/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Autoupdater
2-
3-
The SlimeVR autoupdater manages updating all the software for SlimeVR on a user's
4-
computer. It does not handle updates of firmware.
5-
6-
It reads a `version.yaml` file from a github release to determine the versions of the
7-
software to download, then fetches them and installs them.
8-
9-
Long term, we may use this to replace most or all of the business logic of the current
10-
[SlimeVR Web Installer](https://github.com/SlimeVR/SlimeVR-Installer).
11-
12-
## Project Status
13-
This is abandoned due to lack of interested developers.
14-
15-
When being actively developed, the Yaml description and serialization was complete
16-
already.
1+
# Autoupdater
2+
3+
The SlimeVR autoupdater manages updating all the software for SlimeVR on a user's
4+
computer. It does not handle updates of firmware.
5+
6+
It reads a `version.yaml` file from a github release to determine the versions of the
7+
software to download, then fetches them and installs them.
8+
9+
Long term, we may use this to replace most or all of the business logic of the current
10+
[SlimeVR Web Installer](https://github.com/SlimeVR/SlimeVR-Installer).
11+
12+
## Project Status
13+
This is abandoned due to lack of interested developers.
14+
15+
When being actively developed, the Yaml description and serialization was complete
16+
already.

overlay/src/main.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,27 @@ async fn overlay(
151151
.build(mngr)
152152
.wrap_err("Could not create skeleton")?;
153153

154+
let mut skeleton_mirrored = SkeletonBuilder {key: String::from("slimevr_mirrored"), ..SkeletonBuilder::default()}
155+
.build(mngr)
156+
.wrap_err("Could not create mirrored skeleton")?;
157+
154158
log::info!("Overlay Loop");
155159

156160
let loop_ = async {
157161
let mut hidden_bones: HashSet<BoneKind> = HashSet::new();
162+
let mut hidden_bones_mirrored: HashSet<BoneKind> = HashSet::new();
158163
loop {
159164
recv.changed()
160165
.await
161166
.wrap_err("Error while attempting to watch for feed update")?;
162167
let is_skeleton_visible = display_settings.borrow().is_visible;
168+
let is_skeleton_mirrored = display_settings.borrow().is_mirrored;
163169

164170
log::trace!("Got a feed update");
165171

166172
// Mark all bones as "need to hide"
167173
hidden_bones.extend(BoneKind::iter());
174+
hidden_bones_mirrored.extend(BoneKind::iter());
168175

169176
#[derive(Debug)]
170177
struct BoneInfo {
@@ -229,6 +236,70 @@ async fn overlay(
229236
.collect()
230237
};
231238

239+
let bones_mirrored: Vec<BoneInfo> = {
240+
let guard = recv.borrow_and_update();
241+
let table = guard.as_ref().unwrap().0.table();
242+
log::trace!("update: {:#?}", table);
243+
244+
let m = unwrap_or_continue!(table.data_feed_msgs());
245+
246+
// TODO: handle multiple updates?
247+
let m = m.get(0);
248+
let m = unwrap_or_continue!(m.message_as_data_feed_update());
249+
let bones_mirrored = unwrap_or_continue!(m.bones());
250+
log::debug!("Got {} bones before filtering", bones_mirrored.len());
251+
252+
bones_mirrored
253+
.iter()
254+
.filter_map(|b| {
255+
let part = b.body_part();
256+
log::trace!("body_part: {part:?}");
257+
258+
let bone_kind = BoneKind::try_from(part)
259+
.map_err(|e| {
260+
log::trace!("Filtering out {e:?}");
261+
e
262+
})
263+
.ok()?;
264+
265+
let pos = if let Some(p) = b.head_position_g() {
266+
p
267+
} else {
268+
log::warn!("No position");
269+
return None;
270+
};
271+
let rot = if let Some(r) = b.rotation_g() {
272+
r
273+
} else {
274+
log::warn!("No rotation");
275+
return None;
276+
};
277+
let length = b.bone_length();
278+
279+
let pos = Translation3::new(pos.x(),pos.y(), -1.0 - pos.z());
280+
281+
let mut rot = UnitQuaternion::from_quaternion(
282+
[rot.x(), rot.y(), rot.z(), rot.w()].into(),
283+
);
284+
285+
// This is BAD, someone please fix this to use quaternions instead of converting to euler XD
286+
let mut euler_angles = rot.euler_angles();
287+
euler_angles = (euler_angles.0, euler_angles.1, euler_angles.2);
288+
rot = UnitQuaternion::from_euler_angles(euler_angles.0, - euler_angles.1 + std::f32::consts::PI, euler_angles.2);
289+
290+
if is_skeleton_mirrored {
291+
hidden_bones_mirrored.remove(&bone_kind);
292+
}
293+
Some(BoneInfo {
294+
kind: bone_kind,
295+
pos,
296+
rot,
297+
length,
298+
})
299+
})
300+
.collect()
301+
};
302+
232303
log::debug!(
233304
"Bones after filtering: {:?}",
234305
bones.iter().map(|t| t.kind).collect::<Vec<_>>()
@@ -251,12 +322,32 @@ async fn overlay(
251322
skeleton.set_length(kind, length);
252323
}
253324

325+
for BoneInfo {
326+
kind,
327+
pos,
328+
rot,
329+
length,
330+
} in bones_mirrored
331+
{
332+
let iso_mirrored = Isometry {
333+
rotation: rot,
334+
translation: pos,
335+
};
336+
337+
skeleton_mirrored.set_isometry(kind, iso_mirrored);
338+
skeleton_mirrored.set_length(kind, length);
339+
}
340+
254341
// Update rendering state
255342
for kind in BoneKind::iter() {
256343
skeleton.set_visibility(kind, !hidden_bones.contains(&kind));
344+
skeleton_mirrored.set_visibility(kind, !hidden_bones_mirrored.contains(&kind));
257345
if let Err(e) = skeleton.update_render(kind, mngr) {
258346
log::error!("Error updating render for bone {kind:?}: {:?}", e);
259347
}
348+
if let Err(e) = skeleton_mirrored.update_render(kind, mngr) {
349+
log::error!("Error updating render for bone {kind:?}: {:?}", e);
350+
}
260351
}
261352
}
262353
};

overlay/src/model/skeleton.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ const BONE_RADIUS: f32 = 0.002;
4646

4747
/// Builder for the [`Skeleton`].
4848
pub struct SkeletonBuilder {
49-
colors: Option<BoneMap<Option<RGBA>>>,
50-
key: String,
51-
bone_radius: f32,
52-
bone_lengths: Option<BoneMap<f32>>,
49+
pub colors: Option<BoneMap<Option<RGBA>>>,
50+
pub key: String,
51+
pub bone_radius: f32,
52+
pub bone_lengths: Option<BoneMap<f32>>,
5353
}
5454
impl SkeletonBuilder {
5555
#[allow(dead_code)]

0 commit comments

Comments
 (0)