小编Ala*_*ier的帖子

ARKit - 如何将3D对象放在QRCode上?

我实际上是想用QRKode3D对象放在QRCode上 为此我使用AVCaptureDevice来检测QRCode并建立QRCode的区域,它给我一个CGRect.然后,我在CGRect的每个点上进行一次hitTest来获得平均3D坐标,如下所示:

positionGiven = SCNVector3(0, 0, 0)

for column in Int(qrZone.origin.x)...2*Int(qrZone.origin.x + qrZone.width) {
    for row in Int(qrZone.origin.y)...2*Int(qrZone.origin.y + qrZone.height) {
        for result in sceneView.hitTest(CGPoint(x: CGFloat(column)/2,y:CGFloat(row)/2), types: [.existingPlaneUsingExtent,.featurePoint]) {

            positionGiven.x+=result.worldTransform.columns.3.x
            positionGiven.y+=result.worldTransform.columns.3.y
            positionGiven.z+=result.worldTransform.columns.3.z
            cpts += 1
        }
    }
}

positionGiven.x=positionGiven.x/cpts
positionGiven.y=positionGiven.y/cpts
positionGiven.z=positionGiven.z/cpts
Run Code Online (Sandbox Code Playgroud)

但是hitTest没有检测到任何结果并冻结相机,而当我通过屏幕上的触摸进行hitTest时它可以工作.你知道它为什么不起作用吗?你有其他想法可以帮助我实现我想做的事吗?

我已经考虑过使用CoreMotion进行3D翻译,它可以让我倾斜设备,但这看起来真的很乏味.我也听说过可以锁定场景坐标以匹配相机方向的ARWorldAlignmentCamera,但我不知道如何使用它!

编辑:我每次触摸屏幕时尝试移动我的3D对象并且hitTest为正,并且它非常准确!我真的不明白为什么像素区域上的hitTest不起作用...

编辑2:以下是在屏幕上使用2-5次触摸的hitTest的代码:

@objc func touch(sender : UITapGestureRecognizer) {

    for result in sceneView.hitTest(CGPoint(x: sender.location(in: view).x,y: sender.location(in: view).y), types: [.existingPlaneUsingExtent,.featurePoint]) {
        //Pop up …
Run Code Online (Sandbox Code Playgroud)

3d qr-code core-motion swift arkit

12
推荐指数
1
解决办法
4737
查看次数

ARKit - ARCamera的位置

我正在尝试使用ARKit,我的问题非常简单.我怎样才能获得相机的位置?

我知道,如果我把一个SCNNode在(0,0,0)和我ARCamera正在地上例如,我将不得不抬头看3D对象.这意味着必须以某种方式获得设备相机的位置和方向.

所以,我怎么知道where the camera iswhere she is looking to

提前致谢.

3d camera augmented-reality scenekit arkit

6
推荐指数
1
解决办法
5502
查看次数

标签 统计

3d ×2

arkit ×2

augmented-reality ×1

camera ×1

core-motion ×1

qr-code ×1

scenekit ×1

swift ×1