我已经在这里问过类似的问题=> Enabling gestures in RealityKit
但是我不能解决我的问题:我有一个自定义3DModel。自上一个问题以来,我已经进行了改进,现在它是一个.reality模型。我已经启用了物理和动画功能。
但是,如果我根据上一个问题开发解决方案,则会崩溃,因为它无法将我的Entity转换为HasCollision。
我已经阅读了一些解决方案,其中我的模型嵌入了一个符合各种协议的容器中,因此我可以安装Gesture。但是我想要一个更好的方法。
我已经用ARQuickLook
测试了我的模型,并且正确设置了所有手势和动画。
Ps。
如果添加我的模型,我将添加一个动画,但实际上无法将Gesture安装到我的模型中。但这是.reality!
所以我的问题是:如何从代码将Gesture安装到自定义3DModel(.reality)?
@discardableResult func installGestures(_ gestures: ARView.EntityGestures = .all,
for entity: HasCollision) -> [EntityGestureRecognizer]
我添加了一些代码以供参考,但它与我之前的问题很相似。
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")
}
}