Skip to content

Commit

Permalink
Improve hand tracking for VCam Tracking 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tattn committed Nov 3, 2023
1 parent bd22b30 commit 0929c80
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
5 changes: 2 additions & 3 deletions app/xcode/Sources/VCamTracking/AvatarWebCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,8 @@ public final class AvatarWebCamera {
prevHands[1].setValues(.init(right.wrist.x * 0.5, right.wrist.y))
}

// A real human finds it tedious to move their hands, so make it exaggerate the movement a bit (also helps to avoid the issue of accuracy dropping at the edges of the camera's field of view)
let wristLeft = prevHands[0].appending(min(left.wrist * 1.1, 1))
let wristRight = prevHands[1].appending(min(right.wrist * 1.1, 1))
let wristLeft = prevHands[0].appending(left.wrist)
let wristRight = prevHands[1].appending(right.wrist)
let thumbCMCLeft = prevHands[2].appending(left.thumbCMC)
let thumbCMCRight = prevHands[3].appending(right.thumbCMC)
let littleMCPLeft = prevHands[4].appending(left.littleMCP)
Expand Down
16 changes: 10 additions & 6 deletions app/xcode/Sources/VCamTracking/VCamHands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,16 @@ public extension VCamHands.Hand {

// Originally, the origin is the bottom right, with the top left being positive (opposite of a mirror)
// Convert to a coordinate system where the center of the body is the origin and left-right is the positive direction (0.0 to 1.0)
let wrist = SIMD2(
x: isRight ? (1 - hand.wrist.x) * 2 - 1 : hand.wrist.x * 2 - 1,
y: hand.wrist.y
)
let thumbCMC = hand.thumbCMC
let littleMCP = hand.littleMCP
let wrist: SIMD2<Float>, thumbCMC: SIMD2<Float>, littleMCP: SIMD2<Float>
if isRight {
wrist = SIMD2(x: 1 - hand.wrist.x * 2, y: hand.wrist.y)
thumbCMC = SIMD2(x: 1 - hand.thumbCMC.x * 2, y: hand.thumbCMC.y)
littleMCP = SIMD2(x: 1 - hand.littleMCP.x * 2, y: hand.littleMCP.y)
} else {
wrist = SIMD2(x: hand.wrist.x * 2 - 1, y: hand.wrist.y)
thumbCMC = SIMD2(x: hand.thumbCMC.x * 2 - 1, y: hand.thumbCMC.y)
littleMCP = SIMD2(x: hand.littleMCP.x * 2 - 1, y: hand.littleMCP.y)
}

guard config.isFingerEnabled else {
self.init(wrist: wrist, thumbCMC: thumbCMC, littleMCP: littleMCP, thumbTip: 0.7, indexTip: 0.7, middleTip: 0.7, ringTip: 0.7, littleTip: 0.7)
Expand Down
4 changes: 3 additions & 1 deletion app/xcode/Sources/VCamUI/Extensions/NSApp+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public extension NSApplication {
}

var vcamWindow: NSWindow? {
windows.first { $0.title == "VCam" }
Self._vcamWindow
}

private static var _vcamWindow = NSApp.windows.first { $0.title == "VCam" } // for Unity
}
3 changes: 1 addition & 2 deletions app/xcode/Sources/VCamUI/VCamSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public final class VCamSystem {

public func configure() {
guard windowManager.isUnity else { return }
windowManager.setUpWindow()
windowManager.setUpView()
NSApp.vcamWindow?.orderFront(nil)
}

public func startSystem() {
Expand Down
3 changes: 1 addition & 2 deletions app/xcode/Sources/VCamUI/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ public final class WindowManager: ObservableObject {
Logger.log("")
VCamSystem.shared.dispose()
isConfigured = false
containerView.subviews.forEach { $0.removeFromSuperview() } // for Unity

if isUnity {
uniDebugLog("WindowManager.dispose()")
SceneObjectManager.shared.dispose()
NSApp.vcamWindow?.close()
NSApp.vcamWindow?.orderOut(nil)
} else {
NSApp.stop(nil)
}
Expand Down

0 comments on commit 0929c80

Please sign in to comment.