Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QoL grab-bag: Tickbox for hand visibility, keep SteamVR worldspace when visionOS recenters #55

Merged
merged 10 commits into from
Feb 26, 2024
4 changes: 4 additions & 0 deletions ALVRClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
C5E5903E2B6379EE00328ED6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C5E5903D2B6379EE00328ED6 /* Assets.xcassets */; };
D61E6FE02B71CE080076031A /* VideoHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D61E6FDF2B71CE080076031A /* VideoHandler.swift */; };
D68FA8092B742F6F0052B7FF /* FFR.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68FA8082B742F6F0052B7FF /* FFR.swift */; };
E702FBDC2B899B8700EE75D0 /* GlobalSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = E702FBDB2B899B8300EE75D0 /* GlobalSettings.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -61,6 +62,7 @@
D68FA8042B73D5DD0052B7FF /* ALVRClient.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ALVRClient.xcconfig; sourceTree = "<group>"; };
D68FA8052B73D6260052B7FF /* Override.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Override.xcconfig; sourceTree = "<group>"; };
D68FA8082B742F6F0052B7FF /* FFR.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FFR.swift; sourceTree = "<group>"; };
E702FBDB2B899B8300EE75D0 /* GlobalSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalSettings.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -119,6 +121,7 @@
C5E590312B6379ED00328ED6 /* ALVRClientApp.swift */,
C5E590492B637C7E00328ED6 /* ALVRClient-Bridging-Header.h */,
C5E590332B6379ED00328ED6 /* ContentView.swift */,
E702FBDB2B899B8300EE75D0 /* GlobalSettings.swift */,
C5E590352B6379ED00328ED6 /* Renderer.swift */,
D61E6FDF2B71CE080076031A /* VideoHandler.swift */,
8E458AB22B7E05FB0019FC73 /* EventHandler.swift */,
Expand Down Expand Up @@ -222,6 +225,7 @@
D61E6FE02B71CE080076031A /* VideoHandler.swift in Sources */,
8E458AB32B7E05FB0019FC73 /* EventHandler.swift in Sources */,
8E1240FF2B7CC02E005B75F2 /* Entry.swift in Sources */,
E702FBDC2B899B8700EE75D0 /* GlobalSettings.swift in Sources */,
8E1241032B7CC0E1005B75F2 /* EntryControls.swift in Sources */,
D68FA8092B742F6F0052B7FF /* FFR.swift in Sources */,
C5E590342B6379ED00328ED6 /* ContentView.swift in Sources */,
Expand Down
9 changes: 6 additions & 3 deletions ALVRClient/ALVRClientApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct MetalRendererApp: App {
@State private var model = ViewModel()
@Environment(\.scenePhase) private var scenePhase
@State private var clientImmersionStyle: ImmersionStyle = .full
//@State private var clientHandVisibility: Visibility = .visible

var body: some Scene {
//Entry point, this is the default window chosen in Info.plist from UIApplicationPreferredDefaultSceneSessionRole
Expand All @@ -44,7 +45,7 @@ struct MetalRendererApp: App {
EventHandler.shared.start()
}
}
.defaultSize(width: 350, height: 300)
.defaultSize(width: 650, height: 600)
.windowStyle(.plain)
.onChange(of: scenePhase) {
switch scenePhase {
Expand All @@ -57,7 +58,9 @@ struct MetalRendererApp: App {
// Scene inactive, currently no action for this
break
case .active:
// Scene active, currently no action for this
// Scene active, make sure everything is started if it isn't
EventHandler.shared.initializeAlvr()
EventHandler.shared.start()
break
@unknown default:
break
Expand All @@ -71,7 +74,7 @@ struct MetalRendererApp: App {
}
}
.immersionStyle(selection: $clientImmersionStyle, in: .full)
//.upperLimbVisibility(.hidden) // TODO: make this an option
.upperLimbVisibility(GlobalSettings.shared.showHandsOverlaid ? .visible : .hidden)
}

}
Expand Down
3 changes: 0 additions & 3 deletions ALVRClient/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//
// ContentView.swift
// ALVRClient
//
// Created by Zhuowei Zhang on 1/26/24.
//

import SwiftUI
Expand Down
31 changes: 30 additions & 1 deletion ALVRClient/Entry/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,40 @@ import SwiftUI
struct Entry: View {
@Environment(ViewModel.self) private var model
@ObservedObject var eventHandler = EventHandler.shared
@ObservedObject var globalSettings = GlobalSettings.shared
@State private var dontKeepSteamVRCenter = false
@State private var showHandsOverlaid = false

var body: some View {
VStack {
Text("ALVR")
.font(.system(size: 50, weight: .bold))
.padding()

Text("Options:")
.font(.system(size: 20, weight: .bold))
VStack {
Toggle(isOn: $showHandsOverlaid) {
Text("Show hands overlaid")
}
.toggleStyle(.switch)
.onChange(of: showHandsOverlaid) {
globalSettings.showHandsOverlaid = showHandsOverlaid
}

Toggle(isOn: $dontKeepSteamVRCenter) {
Text("Crown Button long-press also recenters SteamVR")
}
.toggleStyle(.switch)
.onChange(of: dontKeepSteamVRCenter) {
globalSettings.keepSteamVRCenter = !dontKeepSteamVRCenter
}
}
.frame(width: 450)
.padding()

Text("Connection Information:")
.font(.system(size: 20, weight: .bold))

if eventHandler.hostname != "" && eventHandler.IP != "" {
let columns = [
Expand All @@ -30,7 +59,7 @@ struct Entry: View {
.frame(width: 250, alignment: .center)
}
}
.frame(minWidth: 350, minHeight: 200)
.frame(minWidth: 650, minHeight: 500)
.glassBackgroundEffect()

EntryControls()
Expand Down
28 changes: 21 additions & 7 deletions ALVRClient/EventHandler.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//
// EventHandler.swift
// ALVRClient
//
//

import Foundation
import Metal
import VideoToolbox
import Combine
import AVKit

class EventHandler: ObservableObject {
static let shared = EventHandler()
Expand Down Expand Up @@ -48,6 +47,7 @@ class EventHandler: ObservableObject {
init() {}

func initializeAlvr() {
fixAudioForDirectStereo()
if !alvrInitialized {
print("Initialize ALVR")
alvrInitialized = true
Expand All @@ -58,6 +58,7 @@ class EventHandler: ObservableObject {
}

func start() {
fixAudioForDirectStereo()
if !inputRunning {
print("Starting event thread")
inputRunning = true
Expand All @@ -70,12 +71,25 @@ class EventHandler: ObservableObject {
}

func stop() {
print("Stopping")
inputRunning = false
renderStarted = false
if renderStarted {
print("Stopping")
inputRunning = false
renderStarted = false
alvr_destroy()
alvrInitialized = false
}
updateConnectionState(.disconnected)
alvr_destroy()
alvrInitialized = false
}

func fixAudioForDirectStereo() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(.playAndRecord, options: [.mixWithOthers, .allowBluetoothA2DP, .allowAirPlay])
try audioSession.setPreferredOutputNumberOfChannels(2)
try audioSession.setIntendedSpatialExperience(.bypassed)
} catch {
print("Failed to set the audio session configuration?")
}
}

func handleAlvrEvents() {
Expand Down
3 changes: 0 additions & 3 deletions ALVRClient/FFR.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//
// FFR.swift
// ALVRClient
//
// Created by Shadowfacts on 2/7/24.
//

import Foundation
Expand Down
13 changes: 13 additions & 0 deletions ALVRClient/GlobalSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// GlobalSettings.swift
//

import Foundation

class GlobalSettings: ObservableObject {
static let shared = GlobalSettings()

// TODO: configuration persistence
var keepSteamVRCenter = true
var showHandsOverlaid = false
}
4 changes: 4 additions & 0 deletions ALVRClient/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSHandsTrackingUsageDescription</key>
<string>ALVR would like to send hand positions and skeletons to SteamVR.</string>
<key>NSWorldSensingUsageDescription</key>
<string>ALVR would like to scan your surroundings for obstacles and playspace boundaries.</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationPreferredDefaultSceneSessionRole</key>
Expand Down
Loading