Hi,
Please could you help me to install rotation and translation gestures for an RCProject? I have the code below but this crashes when running. Any help is very much appreciated.
import SwiftUI
import RealityKit
import ARKit
struct ContentView : View {
var body: some View {
ARViewContainer().edgesIgnoringSafeArea(.all)
}
}
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
// Load Model3 scene
let anchor = try! Model3.loadScene()
// Add the anchor to the scene
arView.scene.anchors.append(anchor)
anchor.generateCollisionShapes(recursive: true)
arView.installGestures([.rotation, .translation], for: anchor as! HasCollision)
anchor.actions.tap.onAction = HandleTapOnEntity(_:)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
func HandleTapOnEntity(_ entity: Entity?) {
guard let entity = entity else {return}
// code here for action - print for now
print("tapped \(entity.name)")
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif