[英]How can I move a ModelEntity along the Y-axis using gesture?
按照此文档,我不明白是否有一种简单的方法可以沿 Y 轴移动 ModelEntity。 我期望这是因为在 ARQuickLook 中,此功能与.scale
和.rotate
功能一起使用,也列在 Apple 文档中。
如果有任何简单/类似的方法来安装这些手势,请告诉我。
在 RealityKit 2.0 中,与 ARQuickLook 不同,仅实现了单点触摸拖动手势来移动 model (目前尚未实现垂直拖动的双指手势)。 使用单指手势,您可以沿其锚定平面移动实体 - 通常它是 XZ 平面,因此没有 Y 轴拖动。
public static let translation: ARView.EntityGestures
尽管如此,您还是可以选择另外实现 2D UIGestureRecognizer
。
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
var box: ModelEntity? = nil
override func viewDidLoad() {
super.viewDidLoad()
box = ModelEntity(mesh: .generateBox(size: 0.05))
box!.generateCollisionShapes(recursive: true)
arView.installGestures([.all], for: box! as (Entity & HasCollision))
let anchor = AnchorEntity(world: [0, 0,-0.2])
anchor.addChild(box!)
arView.scene.anchors.append(anchor)
for swipe in [UISwipeGestureRecognizer.Direction.up,
UISwipeGestureRecognizer.Direction.down] {
let sw = UISwipeGestureRecognizer(target: self,
action: #selector(dragUpAndDown))
sw.direction = swipe
arView.addGestureRecognizer(sw)
}
}
@objc func dragUpAndDown(recognizer: UISwipeGestureRecognizer) {
if recognizer.direction == .up {
box!.position.y += 0.01
}
if recognizer.direction == .down {
box!.position.y -= 0.01
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.