在缩放手势期间获取RealityKit实体的宽度和深度

时间:2020-06-01 15:08:14

标签: ios swift arkit realitykit

我有一个RealityKit,它允许用户通过一些手势来调整其比例和沿平面的平移。它的生成方式如下:

let aPlane = MeshResource.generatePlane(width: width, depth: depth)
let model = ModelEntity(mesh: aPlane, materials: [someMaterial])
model.generateCollisionShapes(recursive: true)
arView.installGestures([.scale, .translation], for: model)

我想在用户捏捏以调整其大小时检索其宽度和深度。目的是显示实体的比例(例如1:1、1:2、3.5:1)。

有人知道在调整大小时如何获取宽度和深度值吗?我似乎在文档中找不到任何属性。

我也尝试覆盖touchesBegan并打印boundingRadius,但即使将其捏到调整大小后,它似乎仍会打印一个恒定值。

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let model = modelEntities[0].children.first!.components[ModelComponent] as? ModelComponent
    print(model!.mesh.bounds.boundingRadius)

}

1 个答案:

答案 0 :(得分:0)

ARView.installGestures的响应返回了一组UIGestureRecognizer的子类EntityGestureRecognizer。

您可以在此处使用UIGestureRecognizerDelegate方法来检查触摸何时开始以及从那里开始。