将SCNNode添加到GPS坐标

时间:2018-04-03 00:30:43

标签: swift gps scenekit arkit

我正在尝试使用此开源项目中的MatrixHelper函数在GPS坐标处放置一个节点:https://github.com/chriswebb09/ARKitNavigationDemo但是当我运行应用程序时,它会打印"在(xyz坐标)处添加了sphereNode&# 34;这证明它一直在通过代码,但是没有添加球体。我试着调整球体的大小,认为它们可能距离太远而无法看到,但改变半径并没有帮助。

这里是添加球体的功能:

func repositionTarget(stepLocation: CLLocation) {
        let locationTransform = MatrixHelper.transformMatrix(for: matrix_identity_float4x4, originLocation: userLoc!, location: stepLocation)
        let stepAnchor = ARAnchor(transform: locationTransform)
        let sphere = SphereNode(location: stepLocation)
        sphere.addSphere(with: 3.5, and: .blue)
        sphere.location = stepLocation
        sphere.anchor = stepAnchor
        sphere.position = SCNVector3(stepAnchor.transform.columns.3.x, 0, stepAnchor.transform.columns.3.z)
        sceneView.session.add(anchor: stepAnchor)
        sceneView.scene.rootNode.addChildNode(sphere)
        print("added sphereNode at", sphere.position)
}

这是我的SphereNode:

import Foundation
import SceneKit
import UIKit
import ARKit
import CoreLocation

class SphereNode: SCNNode {

    var anchor: ARAnchor?
    var location: CLLocation!

    init(location: CLLocation) {
        super.init()
        let billboardConstraint = SCNBillboardConstraint()
        billboardConstraint.freeAxes = SCNBillboardAxis.Y
        constraints = [billboardConstraint]
    }

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

    func createSphereNode(with radius: CGFloat, color: UIColor) -> SCNNode {
        let geometry = SCNSphere(radius: radius)
        geometry.firstMaterial?.diffuse.contents = color
        let sphereNode = SCNNode(geometry: geometry)
        return sphereNode
    }

    func addSphere(with radius: CGFloat, and color: UIColor) {
        let sphereNode = createSphereNode(with: radius, color: color)
        addChildNode(sphereNode)
    }
}

我在这里使用的MatrixHelper:https://github.com/chriswebb09/ARKitNavigationDemo/blob/master/ARKitNavigationDemo/ARKitNavigationDemo/Services/Helpers/MatrixHelper.swift

任何人都可以看到我出错的地方吗?谢谢!

0 个答案:

没有答案