I am building an app that captures facetracking data from the iPhone TrueDepth camera.
I need to write this data to files so I can use it as the basis for another app.
Within the app, the data is saved into four separate arrays, one containing ARFaceGeometry objects, and the other three with transform coordinates as simd_float4x4 matrices.
I am converting the arrays into Data objects using archivedData(withRootObject: requiringSecureCoding:)
then calling write(to:)
on them to create the files.
The file containing the ARFaceGeometry data is written and read back in correctly. But the three simd_float4x4 arrays aren't being written, even though the code for doing so is identical. Along with my print logs, the error being given is 'unrecognized selector sent to instance'.
Properties:
var faceGeometryCapture = [ARFaceGeometry]()
var faceTransformCapture = [simd_float4x4]()
var leftEyeTransformCapture = [simd_float4x4]()
var rightEyeTransformCapture = [simd_float4x4]()
var faceGeometryCaptureFilePath: URL!
var faceTransformCaptureFilePath: URL!
var leftEyeTransformCaptureFilePath: URL!
var rightEyeTransformCaptureFilePath: URL!
Code for establishing file URLs:
let fileManager = FileManager.default
let dirPaths = fileManager.urls(for: .documentDirectory,
in: .userDomainMask)
faceGeometryCaptureFilePath = dirPaths[0].appendingPathComponent("face-geometries.txt")
faceTransformCaptureFilePath = dirPaths[0].appendingPathComponent("face-transforms.txt")
leftEyeTransformCaptureFilePath = dirPaths[0].appendingPathComponent("left-eye-transforms.txt")
rightEyeTransformCaptureFilePath = dirPaths[0].appendingPathComponent("right-eye-transforms.txt")
Code for writing the data to files:
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: faceGeometryCapture, requiringSecureCoding: false)
try data.write(to: faceGeometryCaptureFilePath)
} catch { print("Error writing face geometries to file") }
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: faceTransformCapture, requiringSecureCoding: false)
try data.write(to: faceTransformCaptureFilePath)
} catch { print("Error writing face transforms to file") }
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: leftEyeTransformCapture, requiringSecureCoding: false)
try data.write(to: leftEyeTransformCaptureFilePath)
} catch { print("Error writing left eye transforms to file") }
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: rightEyeTransformCapture, requiringSecureCoding: false)
try data.write(to: rightEyeTransformCaptureFilePath)
} catch { print("Error writing right eye transforms to file") }
I'm guessing it's the simd_float4x4 struct that is causing the issue, as this is the only difference between working and not working. Can anyone confirm and suggest a solution?
Thanks in advance.