I've already asked a similar question here => Enabling gestures in RealityKit
But I can't solve my problem: I have a custom 3DModel. The improvement I've made since the last question is that it is now a .reality model. I've enabled physics and animation on it.
But if I develop the solution from the previous question I receive a crash since it is not able to downcast my Entity to HasCollision.
I've read some solution where my model is embedded in a sort of container which conform to the various protocol so I can installGesture. But I would like a better approach.
I've tested my model with ARQuickLook
and all the gesture and animation are set correctly.
P.s.
If I add my model I've an animation that I've added , but I really can't installGesture to my model. But it is .reality!
So my question is: How do I installGesture to a custom 3DModel (.reality) from code?
@discardableResult func installGestures(_ gestures: ARView.EntityGestures = .all,
for entity: HasCollision) -> [EntityGestureRecognizer]
I add some code for reference but it's quiete similar to my previous question.
func updateUIView(_ uiView: ARView, context: Context) {
if let modelEntity = model.modelEntity {
let anchorEntity = AnchorEntity(plane: .horizontal)
anchorEntity.addChild(modelEntity.clone(recursive: true))
uiView.scene.addAnchor(anchorEntity)
// modelEntity.generateCollisionShapes(recursive: true)
// If we have multiple object, recursive true help to generate collision for all of them
uiView.installGestures(.rotation, for: modelEntity as! Entity & HasCollision)
uiView.debugOptions = .showPhysics
} else {
print("Unable to load model")
}
}