I’m using Project Dents ARKit + CoreLocation Pod to place a 3D model from a local file path at specific gps coordinates in the real world. I’m able to see my 3d model in AR. However, it seems like it’s not fixed to the coordinates since the model moves with the camera and doesn’t stick to the given gps location when I move away.
Here’s what I’ve tried
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)
Can anyone lead me in the right direction here?
2
Answers
The
ARGeoAnchor
seems very suited to your needs.Your Location Node is missing following configuration:
This will allow the node to actually reduce its scale when it’s further away or upscale it when it’s closer.
In addition, adding the SCNNode containing the 3D model to the child nodes of your location node does not work because the child nodes do not inherit the configuration of its parent. To fix that the 3D model node has to be either of type
LocationNode
or of a type which inherits fromLocationNode
.