Hello chaert-s,
You can do this by serializing the transform data of the ARCamera every frame and writing it to disk (along with the time stamp of the frame).
You could also accomplish something like this using Model I/O (though I don't believe it will export to fbx, other common formats are supported though):
1. Create an MDLTransform object.
2. In the ARSession update method, set the translation and orientation of the transform based on the elapsed time:
func session(_ session: ARSession, didUpdate frame: ARFrame) {
if firstUpdateTime == nil {
firstUpdateTime = frame.timestamp
}
let transform = frame.camera.transform
let rotation = frame.camera.eulerAngles
let position = transform.columns.3
let elapsedTime = frame.timestamp - firstUpdateTime!
// cameraTransform is an `MDLTransform`
cameraTransform.setTranslation(position[SIMD3(0,1,2)], forTime: elapsedTime)
cameraTransform.setRotation(rotation, forTime: elapsedTime)
}
- When you are ready to export the MDLAsset that you added the mesh objects to, you create a new MDLObject, set it’s transform, and then add it to the asset:
// A box to visually represent the camera as it animates through the scene.
let object = MDLMesh(boxWithExtent: .init(0.1, 0.1, 0.1), segments: .init(10, 10, 10), inwardNormals: false, geometryType: .triangles, allocator: nil)
object.name = "Camera Transform"
object.transform = cameraTransform
let asset = MDLAsset()
asset.add(object)
- Export your MDLAsset to a supported file format (the format should also support keyframe animation):
try! asset.export(to: url)