如何利用ARKIT在GPS坐标系下放置三维物体 [英] How to place 3D object at GPS coordinates with ARkit

查看:119
本文介绍了如何利用ARKIT在GPS坐标系下放置三维物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Project Dent尝试将3D对象置于绝对GPS坐标。

自述说明如何将2D信息批注对象放入AR空间,但我无法让它将3D对象放置在GPS坐标中

Project Dent不使用标准的SceneView,这使得基于大量教程来尝试和实现这一点变得很困难。使用基于ARCL的SceneLocationView

这是2D批注的示例代码

let coordinate = CLLocationCoordinate2D(latitude: 51.504571, longitude: -0.019717)
let location = CLLocation(coordinate: coordinate, altitude: 300)
let view = UIView() // or a custom UIView subclass

let annotationNode = LocationAnnotationNode(location: location, view: view)

sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: annotationNode)

以下是我一直在尝试使其与3D对象一起工作的方法

let coordinate = CLLocationCoordinate2D(latitude: 51.504571, longitude: -0.019717)
let location = CLLocation(coordinate: coordinate, altitude: 300)
let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)

let objectNode = LocationNode(location: location, SCNbox: box)

sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: objectNode)

理想情况下,我希望此代码简单地将3D框放置在AR空间中的这些GPS坐标上。

遗憾的是,我目前甚至无法生成它。

作为更新,我做了以下工作。基于LocationNode在Nodes中创建一个名为ThreeDNode的新类-

open class ThreeDNode: LocationNode {

   // Class for placing 3d objects in AR space
   public let threeDObjectNode: LocationNode

   public init(location: CLLocation?, scene: SCNScene) {

       let boxGeometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)
       //let boxNode = SCNNode(geometry: boxGeometry)

       threeDObjectNode = LocationNode(location: location)
       threeDObjectNode.geometry = boxGeometry
       threeDObjectNode.removeFlicker()

       super.init(location: location)

       addChildNode(threeDObjectNode)
   }

   required public init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }

然后在POIView控制器中,尝试使用以下代码将3D对象放置在AR空间中-

//example using 3d box object
        let coordinate2 = CLLocationCoordinate2D(latitude: 52.010339, longitude: -8.351157)
        let location2 = CLLocation(coordinate: coordinate2, altitude: 300)

        let asset = SCNScene(named: "art.scnassets/ship.scn")!

        let object = ThreeDNode(location: location2, scene: asset)

        //add to scene with confirmed location
        sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: object)

没有joy:(帮个忙,非常感谢。

推荐答案

您需要创建一个位置节点,并将框添加为其几何体或子节点:

let boxNode = SCNNode(geometry: box)

let locationNode = LocationNode(location: location)
locationNode.addChildNode(boxNode)

sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: locationNode)

我没有在Xcode中运行此代码,因此您可能需要调整。

这篇关于如何利用ARKIT在GPS坐标系下放置三维物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆