skip to Main Content

Is it possible to detect which hand chirality that executed a gesture?

For example,

    TapGesture(count: 2)
            .targetedToAnyEntity()
            .onEnded { value in
                // if left hand
                    // do something
                // if right hand
                    // do something
            }

2

Answers


  1. I do not think SwiftUI offers that information as of visionOS 1.1. You’ll need to use ARKit’s hand tracking APIs if you want to know which hand is gesturing. It will be a substantial amount of work. Start with the ARKit in visionOS documentation and check out the HandTrackingProvider class.

    Login or Signup to reply.
  2. With VisionOS 2 it will be possible using Compositor-Services

    https://developer.apple.com/documentation/visionos-release-notes/visionos-2-release-notes#Compositor-Services

    SpatialEventGesture

    
    struct ParticlePlayground: View {
        @State var model = ParticlesModel()
    
    
        var body: some View {
            Canvas { context, size in
                for particle in model.particles {
                    context.fill(Path(ellipseIn: particle.frame),
                                 with: .color(particle.color))
                }
            }
            .gesture(
                SpatialEventGesture()
                    .onChanged { events in
                        for event in events {
                            if event.phase == .active { //or chirality
    
                                // Update particle emitters.
                                model.emitters[event.id] = ParticlesModel.Emitter(
                                    location: event.location
                                )
                            } else {
                                // Remove emitters when no longer active.
                                model.emitters[event.id] = nil
                            }
                        }
                    }
                    .onEnded { events in
                        for event in events {
                            // Remove emitters when no longer active.
                            model.emitters[event.id] = nil
                        }
                    }
            )
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search