I am working on an Apple Vision Pro app in RealityKit. Unfortunately we are limited in devices, so I have to run the code and do tests on the simulator.
We want to do some pinches for interaction. I have implemented what looks like the correct code, only I am getting no output. I now wonder if this is maybe something that the AVP Simulator is not able to handle.
struct ImmersiveView: View {
var body: some View {
Group {
let model = ModelEntity(
mesh: .generateBox(size: 0.1),
materials: [SimpleMaterial(color: .green, isMetallic: true)]
)
RealityView { content in
model.position = [0, 1.5, -2]
content.add(model)
}
// Gestures might not work in Simulator
.onTapGesture {
print("hello")
}
.gesture(
SpatialTapGesture()
// Pinch Targeted on entity
.targetedToEntity(model)
.onEnded { value in
print("hello")
}
)
.gesture(
SpatialTapGesture()
// Pinch Targeted on all entities
.targetedToAnyEntity()
.onEnded { event in
print("hello")
}
)
}
}
}
Is this code correct? Also is there a way to test pinching on the simulator, or is this only doable on a actual device?