I’m rendering a scene using Metal and I have a custom renderer that’s passed into a CompositorLayer. I want to use gestures something like
.onTapGesture {
print("test")
}
Currently, the problem is that I can’t wrap the CompositorLayer in a view, so I don’t have access to the gestures API. How can I get access to the gestures API? Ideally, I want the model/mesh in the scene to act like the view.
ImmersiveSpace(id: "ImmersiveSpace") {
CompositorLayer(configuration: ContentStageConfiguration()) { layerRenderer in
let renderer = Renderer(layerRenderer)
Context.render.layerRenderer = layerRenderer
Context.state.scene = GameScene()
renderer.startRenderLoop()
}
}.immersionStyle(selection: .constant(.full), in: .full)
Ideally I’d like the code to look something like this
struct Model {
onTapGesture() {
}
}
2
Answers
You can't use the built in gestures provided by SwiftUI. So you need to manually figure out gestures via HandTrackingProvider.
You can use the onspatialevent API on the LayerRenderer: https://developer.apple.com/documentation/compositorservices/layerrenderer/4245856-onspatialevent