【发布时间】:2018-09-01 15:13:49
【问题描述】:
好的,和其他人一样,我在 ARKit/世界空间中拖动/翻译 SCNNode 时遇到了麻烦。我查看了Dragging SCNNode in ARKit Using SceneKit 和所有热门问题,以及来自 Apple 的代码https://github.com/gao0122/ARKit-Example-by-Apple/blob/master/ARKitExample/VirtualObject.swift
我尝试尽可能简化,只是做了我在普通场景套件游戏中会做的事情 - http://dayoftheindie.com/tutorials/3d-games-graphics/t-scenekit-3d-picking-dragging/
我可以获取被点击的对象并存储当前手指的位置没有问题:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let results = gameView.hitTest(touch.location(in: gameView), types: [ARHitTestResult.ResultType.featurePoint])
//TAP Test
let hits = gameView.hitTest(touch.location(in: gameView), options: nil)
currentTapPos = getARPos(hitFeature: hitFeature) //TAP POSITION
if let tappedNode = hits.first?.node {
但是,我的问题是在更新中执行此操作 - 没有动画。该对象只出现在我点击的任何地方,并且总体上不起作用 -
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let results = gameView.hitTest(touch.location(in: gameView), types: [ARHitTestResult.ResultType.featurePoint])
guard let hitFeature = results.last else { return }
testNode.position = currentTapPos
我用这个函数转换为 SCNVector3:
func getARPos(hitFeature: ARHitTestResult)->SCNVector3
{
let hitTransform = SCNMatrix4.init(hitFeature.worldTransform)
let hitPosition = SCNVector3Make(hitTransform.m41,
hitTransform.m42,
hitTransform.m43)
return hitPosition
}
我试过了:
-按向量翻译 -pan 手势(这搞砸了其他功能) -SCNAction.moveTo
我可以在这里做什么?怎么了?
【问题讨论】:
-
看看苹果的newer version of that sample code。现在似乎有了更简单、更清晰的拖动代码(带有手势识别器)。
-
对 - 我的问题是我不能使用手势识别器,因为我在屏幕上有其他 UI 并且它搞砸了。您是否看到无需平移手势即可拉出/应用的任何内容?
-
SCNAction有什么问题?我使用了平移手势,但使用SCNAction进行了平滑过渡。
标签: swift scenekit augmented-reality arkit