【问题标题】:How to place a 3D model from a local file path on gps coordinates?如何将本地文件路径中的 3D 模型放置在 gps 坐标上?
【发布时间】:2022-01-28 19:23:56
【问题描述】:

我正在使用 Project Dents ARKit + CoreLocation Pod 将 3D 模型从本地文件路径放置在现实世界中特定 gps 坐标处。我可以在 AR 中看到我的 3d 模型。但是,它似乎没有固定在坐标上,因为模型随着相机移动并且在我离开时不会粘在给定的 gps 位置。

这是我尝试过的

sceneLocationView.run()
view?.addSubview(sceneLocationView)
    
// Config
self.sceneLocationView.autoenablesDefaultLighting = true
self.sceneLocationView.showsStatistics = true
    
// Coordinates of where the model should be placed
let coordinate = CLLocationCoordinate2D(latitude: arConfig?.positionValue?.latitude ?? 0, longitude: arConfig?.positionValue?.longitude ?? 0)
let location = CLLocation(coordinate: coordinate, altitude: -1.5)
    
// Load model
let model = MDLAsset(url: (self.arConfig?.models.first!)!)
model.loadTextures()
    
let modelNode: SCNNode = SCNNode(mdlObject: model.object(at: 0))
modelNode.scale = SCNVector3(x: 15, y: 15, z: 15)
    
// Rotate
let orientation = modelNode.orientation
var glQuaternion = GLKQuaternionMake(orientation.x, orientation.y, orientation.z, orientation.w)
let multiplier = GLKQuaternionMakeWithAngleAndAxis(90, 0, 1, 0)
glQuaternion = GLKQuaternionMultiply(glQuaternion, multiplier)
    
modelNode.orientation = SCNQuaternion(x: glQuaternion.x, y: glQuaternion.y, z: glQuaternion.z, w: glQuaternion.w)
    
// Create location node and add the model node to it
let locationNode = LocationNode(location: location)
locationNode.addChildNode(modelNode)

// Add the location node for a given location which includes the model to the scene
sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: locationNode)

任何人都可以在这里引导我走向正确的方向吗?

【问题讨论】:

    标签: ios swift scenekit arkit core-location


    【解决方案1】:

    ARGeoAnchor 似乎非常适合您的需求。

    地理定位点(也称为位置定位点)用于标识应用可以在 AR 体验中引用的世界特定区域。当用户在场景中移动时,会话会根据锚点的坐标和设备的罗盘方向更新位置锚点的变换。

    init(name: String, coordinate: CLLocationCoordinate2D, altitude: CLLocationDistance)

    用给定的坐标和高度初始化一个命名的位置锚。

    【讨论】:

    • 我已经调查过了,但不幸的是,本地化图像仅适用于特定区域。
    【解决方案2】:

    您的位置节点缺少以下配置:

    locationNode.continuallyUpdatePositionAndScale = true
    locationNode.continuallyAdjustNodePositionWhenWithinRange = true
    locationNode.scaleRelativeToDistance = true
    

    这将允许节点在距离较远时实际缩小规模,或在距离较近时扩大规模。

    此外,将包含 3D 模型的 SCNNode 添加到您的位置节点的子节点不起作用,因为子节点不继承其父节点的配置。要修复 3D 模型节点必须是 LocationNode 类型或继承自 LocationNode 的类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      相关资源
      最近更新 更多