gpt4 book ai didi

ios - 如何使用平移手势识别器在 ARSCNView 中移动节点?

转载 作者:行者123 更新时间:2023-11-29 11:43:39 24 4
gpt4 key购买 nike

我在 viewDidLoad 中有以下代码

let scene = SCNScene(named: "funModel")!
myNode = scene.rootNode.childNode(withName: "blah")!
myNode.position = SCNVector3Make(0, 0, -1)
sceneView.scene = scene
let pan = UIPanGestureRecognizer(target: self, action: #selector(panGesture(recognizer:)))
view.addGestureRecognizer(pan)

然后是来自 another SO answerpanGesture 中的以下代码,但它不起作用。该节点似乎只是转到 0, 0, 0。我只想能够在屏幕上拖动节点。

let projectedOrigin = sceneView.projectPoint(SCNVector3Zero)
let vp = recognizer.location(in: sceneView)
let vpWithZ = SCNVector3(x: Float(vp.x), y: Float(vp.y), z: Float(projectedOrigin.z))
let worldPoint = sceneView.unprojectPoint(vpWithZ)
myNode.position = worldPoint

最佳答案

您首先需要从 UIPanGestureRecognizer 位置(在您的 UIPanGestureRecognizer 函数中)获取命中点,例如:

let point = pan.location(in: scene)
let result = scene.hitTest(point, types: .featurePoint)
let resultPoint = result.first

现在你的新世界点是:

let vpWithZ = SCNVector3(x: Float(resultPoint.worldTransform.columns.3.x), y: Float(resultPoint.worldTransform.columns.3.y), z: Float(projectedOrigin.z))

希望对您有所帮助。

关于ios - 如何使用平移手势识别器在 ARSCNView 中移动节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45134068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com