如何使用手势沿 Y 轴移动 ModelEntity?

发布于 2025-01-15 06:41:55 字数 299 浏览 0 评论 0原文

按照本文档,我不明白是否有一种简单的移动方法沿 Y 轴的 ModelEntity。我之所以期望如此,是因为在 ARQuickLook 中,此功能与 .scale.rotate 函数一起使用,这些函数也在 Apple 文档中列出。

如果有任何简单/类似的方法来安装这些手势,请告诉我。

Following this documentation, I have not understood if there is an easy way to move a ModelEntity along the Y-axis. The reason I expected this is that in ARQuickLook this functionality works together with the .scale and .rotate functions, also listed in the Apple documentation.

If there is any easy/similar way to install these gestures, please let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌 2025-01-22 06:41:55

在 RealityKit 2.0 中,与 ARQuickLook 不同,仅实现了单点触摸拖动手势来移动模型(目前尚未实现用于垂直拖动的双指手势)。使用单指手势,您可以沿着其锚定平面移动实体 - 通常是 XZ 平面,因此没有 Y 轴拖动。

public static let translation: ARView.EntityGestures

尽管如此,您仍然可以选择额外实现 2D UIGestureRecognizer。

(与在 AR Quick Look 应用程序中实现两指平移手势(也称为悬浮手势)的方式相同)

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
        }
    }
}

PS

另外,这篇文章将显示您将了解光线投射如何与 RealityKit 手势结合使用。

In RealityKit 2.0, unlike ARQuickLook, only a single touch drag gesture is implemented to move a model (double-finger gesture for vertical drag isn't implemented at the moment). With a single-finger gesture you can move entity along its anchoring plane – as a rule it's XZ plane, so there's no Y-axis drag.

public static let translation: ARView.EntityGestures

Despite this, you have the option to additionally implement 2D UIGestureRecognizer.

(The same way you can implement a two-finger pan gesture (also known as levitation gesture) like in AR Quick Look apps)

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
        }
    }
}

P. S.

Also, this post will show you how raycasting works in conjunction with RealityKit gestures.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文