A Swift package that provides a clean, reusable interface for hand gesture detection in visionOS applications.
DicyaninHandGesture simplifies working with ARKit's hand tracking capabilities by providing:
- A clean, reusable interface for hand gesture detection
- Support for multiple concurrent gestures
- Hand-specific detection (left/right hand)
- Customizable gesture parameters
- Dominant/non-dominant hand support
DicyaninHandGesture depends on DicyaninHandSessionManager, a package that manages ARKit sessions and hand tracking updates. This separation of concerns is important because:
- Resource Management: ARKit sessions are resource-intensive and should be shared across multiple packages
- Consistency: Ensures all packages receive the same hand tracking data
- Performance: Prevents multiple ARKit sessions from running simultaneously
- Modularity: Allows other packages to use hand tracking without implementing their own session management
- visionOS 1.0+
- Swift 5.9+
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/hunterh37/DicyaninHandGesture.git", from: "0.0.1")
]import DicyaninHandGesture
import SwiftUI
import RealityKit
struct ContentView: View {
@StateObject private var gestureDetector = HandGestureDetector.shared
@State private var isPinching = false
var body: some View {
RealityView { content in
// Add your 3D content here
let box = ModelEntity(mesh: .generateBox(size: 0.3))
content.add(box)
} update: { content in
// Your update logic here
}
.task {
// Start hand tracking when the view appears
try? await gestureDetector.start()
}
.onDisappear {
// Stop hand tracking when the view disappears
gestureDetector.stop()
}
.onAppear {
// Set up gesture detection
let pinchGesture = PinchGesture(handSide: .right)
gestureDetector.addGesture(pinchGesture) { isActive in
isPinching = isActive
}
}
}
}- Add the following key to your Info.plist file to request hand tracking permissions:
<key>NSHandsTrackingUsageDescription</key>
<string>This app needs access to hand tracking to enable hand interaction features.</string>PinchGesture: Detects pinching between thumb and index fingerGrabGesture: Detects when all fingers are curledPointGesture: Detects when index finger is extended while others are curled
Copyright © 2025 Dicyanin Labs. All rights reserved.