Skip to content

Commit bf0e688

Browse files
committed
Fix impl + update every frame
1 parent 5ddbb99 commit bf0e688

7 files changed

Lines changed: 305 additions & 215 deletions

File tree

alvr/client_openxr/src/extra_extensions/spatial_marker_tracking.rs

Lines changed: 249 additions & 141 deletions
Large diffs are not rendered by default.

alvr/client_openxr/src/interaction.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ use crate::{
88
};
99
use alvr_common::{
1010
glam::{Quat, Vec3},
11-
settings_schema::Switch,
1211
*,
1312
};
1413
use alvr_graphics::HandData;
1514
use alvr_packets::{ButtonEntry, ButtonValue, FaceData, FaceExpressions, StreamConfig};
16-
use alvr_session::{
17-
BodyTrackingBDConfig, BodyTrackingSourcesConfig, FaceTrackingSourcesConfig, RecenteringMode,
18-
};
15+
use alvr_session::{BodyTrackingBDConfig, BodyTrackingSourcesConfig, FaceTrackingSourcesConfig};
1916
use openxr as xr;
2017
use std::{
2118
collections::{HashMap, HashSet},
@@ -148,7 +145,7 @@ pub struct InteractionSourcesConfig {
148145
pub face_tracking: Option<FaceTrackingSourcesConfig>,
149146
pub body_tracking: Option<BodyTrackingSourcesConfig>,
150147
pub prefers_multimodal_input: bool,
151-
pub initial_marker_discovery_state: bool,
148+
pub markers_to_track: Option<HashSet<String>>,
152149
}
153150

154151
impl InteractionSourcesConfig {
@@ -172,12 +169,12 @@ impl InteractionSourcesConfig {
172169
.multimodal_tracking
173170
.as_option()
174171
.is_some_and(|c| c.enabled),
175-
initial_marker_discovery_state: matches!(
176-
config.settings.headset.recentering_mode,
177-
RecenteringMode::Stage {
178-
marker_based_colocation: Switch::Enabled(_)
179-
}
180-
),
172+
markers_to_track: config
173+
.settings
174+
.headset
175+
.marker_colocation
176+
.as_option()
177+
.map(|c| HashSet::from_iter([c.qr_code_string.clone()])),
181178
}
182179
}
183180
}
@@ -697,10 +694,12 @@ impl InteractionContext {
697694
}
698695
}
699696

700-
self.marker_spatial_context = check_ext_object(
701-
"MarkerSpatialContext",
702-
QRCodesSpatialContext::new(&self.xr_session, config.initial_marker_discovery_state),
703-
);
697+
self.marker_spatial_context = config.markers_to_track.as_ref().and_then(|strings| {
698+
check_ext_object(
699+
"QRCodesSpatialContext",
700+
QRCodesSpatialContext::new(&self.xr_session, strings.clone()),
701+
)
702+
});
704703
}
705704
}
706705

alvr/client_openxr/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use interaction::{InteractionContext, InteractionSourcesConfig};
2626
use lobby::Lobby;
2727
use openxr as xr;
2828
use passthrough::PassthroughLayer;
29-
use std::{ffi::CStr, path::Path, rc::Rc, sync::Arc, thread, time::Duration};
29+
use std::{collections::HashSet, ffi::CStr, path::Path, rc::Rc, sync::Arc, thread, time::Duration};
3030
use stream::StreamContext;
3131

3232
fn from_xr_vec3(v: xr::Vector3f) -> Vec3 {
@@ -357,7 +357,7 @@ pub fn entry_point() {
357357
face_tracking: None,
358358
body_tracking: lobby_body_tracking_config,
359359
prefers_multimodal_input: true,
360-
initial_marker_discovery_state: true,
360+
markers_to_track: Some(HashSet::new()),
361361
};
362362
interaction_context
363363
.write()
@@ -510,9 +510,6 @@ pub fn entry_point() {
510510
} else if config.passthrough.is_none() && passthrough_layer.is_some() {
511511
passthrough_layer = None;
512512
}
513-
if let Some(context) = &interaction_context.read().marker_spatial_context {
514-
context.set_discovery_enabled(config.marker_colocation);
515-
}
516513

517514
if let Some(stream) = &mut stream_context {
518515
stream.update_real_time_config(&config);

alvr/packets/src/lib.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ use alvr_common::{
33
anyhow::Result,
44
glam::{Quat, UVec2, Vec2},
55
semver::Version,
6-
settings_schema::Switch,
76
};
87
use alvr_session::{
9-
ClientsidePostProcessingConfig, CodecType, PassthroughMode, RecenteringMode, SessionConfig,
10-
Settings,
8+
ClientsidePostProcessingConfig, CodecType, PassthroughMode, SessionConfig, Settings,
119
};
1210
use serde::{Deserialize, Serialize};
1311
use serde_json as json;
@@ -330,7 +328,6 @@ pub enum FirewallRulesAction {
330328
pub struct RealTimeConfig {
331329
pub passthrough: Option<PassthroughMode>,
332330
pub clientside_post_processing: Option<ClientsidePostProcessingConfig>,
333-
pub marker_colocation: bool,
334331
pub ext_str: String,
335332
}
336333

@@ -343,12 +340,6 @@ impl RealTimeConfig {
343340
.clientside_post_processing
344341
.clone()
345342
.into_option(),
346-
marker_colocation: matches!(
347-
settings.headset.recentering_mode,
348-
RecenteringMode::Stage {
349-
marker_based_colocation: Switch::Enabled(_)
350-
}
351-
),
352343
ext_str: String::new(), // No extensions for now
353344
}
354345
}

alvr/server_core/src/connection.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use alvr_packets::{
2525
};
2626
use alvr_session::{
2727
BodyTrackingSinkConfig, CodecType, ControllersEmulationMode, FrameSize, H264Profile,
28-
OpenvrConfig, RecenteringMode, SessionConfig, SocketProtocol,
28+
OpenvrConfig, SessionConfig, SocketProtocol,
2929
};
3030
use alvr_sockets::{
3131
CONTROL_PORT, KEEPALIVE_INTERVAL, KEEPALIVE_TIMEOUT, PeerType, ProtoControlSocket,
@@ -1194,11 +1194,9 @@ fn connection_pipeline(
11941194
if !initial_settings.headset.tracking_ref_only {
11951195
let session_manager_lock = SESSION_MANAGER.read();
11961196
let config = &session_manager_lock.settings().headset;
1197-
if !matches!(config.recentering_mode, RecenteringMode::Stage { .. }) {
1198-
ctx.tracking_manager
1199-
.write()
1200-
.recenter(&config.recentering_mode);
1201-
}
1197+
ctx.tracking_manager
1198+
.write()
1199+
.recenter(&config.recentering_mode);
12021200

12031201
let area = packet.unwrap_or(Vec2::new(2.0, 2.0));
12041202
let wh = area.x * area.y;

alvr/server_core/src/tracking/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl TrackingManager {
8282

8383
pub fn recenter(&mut self, recentering_mode: &RecenteringMode) {
8484
let position = match recentering_mode {
85-
RecenteringMode::Stage { .. } => Vec3::ZERO,
85+
RecenteringMode::Stage => Vec3::ZERO,
8686
RecenteringMode::LocalFloor => {
8787
let mut pos = self.last_head_pose.position;
8888
pos.y = 0.0;
@@ -95,7 +95,7 @@ impl TrackingManager {
9595
};
9696

9797
let orientation = match recentering_mode {
98-
RecenteringMode::Stage { .. } => Quat::IDENTITY,
98+
RecenteringMode::Stage => Quat::IDENTITY,
9999
RecenteringMode::LocalFloor | RecenteringMode::Local { .. } => {
100100
let mut rot = self.last_head_pose.orientation;
101101
// extract yaw rotation
@@ -452,10 +452,7 @@ pub fn tracking_loop(
452452
if !tracking.markers.is_empty() {
453453
tracking_manager_lock.report_markers(tracking.markers);
454454

455-
if let RecenteringMode::Stage {
456-
marker_based_colocation: Switch::Enabled(config),
457-
} = &headset_config.recentering_mode
458-
{
455+
if let Some(config) = headset_config.marker_colocation.as_option() {
459456
tracking_manager_lock.recenter_from_marker(config);
460457
};
461458
}

alvr/session/src/settings.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,28 +1220,9 @@ Currently this cannot be reliably estimated automatically. The correct value sho
12201220
pub button_mapping_config: AutomaticButtonMappingConfig,
12211221
}
12221222

1223-
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
1224-
pub struct MarkerColocationConfig {
1225-
#[schema(strings(display_string = "QR Code string"))]
1226-
pub qr_code_string: String,
1227-
1228-
#[schema(strings(
1229-
help = r"Offset coordinate on the floor between the marker and the playspace origin.
1230-
The height doesn't need to be measured"
1231-
))]
1232-
#[schema(suffix = "m")]
1233-
pub floor_offset: [f32; 2],
1234-
}
1235-
12361223
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
12371224
pub enum RecenteringMode {
1238-
Stage {
1239-
#[schema(strings(
1240-
help = "Use a QR code to synchronize the playspace origin between players.",
1241-
notice = "Print at https://www.qr-code-generator.com"
1242-
))]
1243-
marker_based_colocation: Switch<MarkerColocationConfig>,
1244-
},
1225+
Stage,
12451226
LocalFloor,
12461227
Local {
12471228
#[schema(gui(slider(min = 0.0, max = 3.0)), suffix = "m")]
@@ -1253,6 +1234,20 @@ pub enum RecenteringMode {
12531234
},
12541235
}
12551236

1237+
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
1238+
pub struct MarkerColocationConfig {
1239+
#[schema(strings(display_string = "QR Code string"))]
1240+
pub qr_code_string: String,
1241+
1242+
#[schema(flag = "real-time")]
1243+
#[schema(strings(
1244+
help = r"Offset coordinate on the floor between the marker and the playspace origin.
1245+
The height of the marker doesn't need to be measured"
1246+
))]
1247+
#[schema(suffix = "m")]
1248+
pub floor_offset: [f32; 2],
1249+
}
1250+
12561251
#[derive(SettingsSchema, Serialize, Deserialize, Clone, Copy)]
12571252
pub struct MultimodalTracking {
12581253
pub enabled: bool,
@@ -1277,6 +1272,13 @@ Tilted: the world gets tilted when long pressing the recentering button. This is
12771272
#[schema(flag = "real-time")]
12781273
pub recentering_mode: RecenteringMode,
12791274

1275+
#[schema(strings(
1276+
string = "Marker-based co-location",
1277+
help = "Use a QR code to synchronize the playspace origin between players.",
1278+
notice = "Print at https://www.qr-code-generator.com"
1279+
))]
1280+
pub marker_colocation: Switch<MarkerColocationConfig>,
1281+
12801282
#[schema(flag = "steamvr-restart")]
12811283
pub controllers: Switch<ControllersConfig>,
12821284

@@ -2105,22 +2107,20 @@ pub fn session_settings_default() -> SettingsDefault {
21052107
},
21062108
},
21072109
recentering_mode: RecenteringModeDefault {
2108-
Stage: RecenteringModeStageDefault {
2109-
marker_based_colocation: SwitchDefault {
2110-
enabled: false,
2111-
content: MarkerColocationConfigDefault {
2112-
qr_code_string: String::new(),
2113-
floor_offset: ArrayDefault {
2114-
gui_collapsed: false,
2115-
content: [0.0, 0.0],
2116-
},
2117-
},
2118-
},
2119-
},
21202110
Local: RecenteringModeLocalDefault { view_height: 1.5 },
21212111
Tilted: RecenteringModeTiltedDefault { view_height: 1.5 },
21222112
variant: RecenteringModeDefaultVariant::LocalFloor,
21232113
},
2114+
marker_colocation: SwitchDefault {
2115+
enabled: false,
2116+
content: MarkerColocationConfigDefault {
2117+
qr_code_string: String::new(),
2118+
floor_offset: ArrayDefault {
2119+
gui_collapsed: false,
2120+
content: [0.0, 0.0],
2121+
},
2122+
},
2123+
},
21242124
max_prediction_ms: 100,
21252125
},
21262126
connection: ConnectionConfigDefault {

0 commit comments

Comments
 (0)