[英]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.