【发布时间】: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