Home / IOS Development / ios – Update ARSCNFaceGeometry effectively from a set of blending forms

ios – Update ARSCNFaceGeometry effectively from a set of blending forms



I use ARSCNFaceGeometry and need to update the face model mix forms as part of my game loop. My current solution is to call ARSCNFaceGeometry.update with a new one ARFaceGeometry:

class Face {
    let geometry: ARSCNFaceGeometry
    
    init(device: MTLDevice) {
        guard let geometry = ARSCNFaceGeometry(device: device, fillMesh: true) else {
            fatalError("Could not create ARSCNFaceGeometry")
        }
        self.geometry = geometry
    }
    
    func update(blendShapes: [ARFaceAnchor.BlendShapeLocation: NSNumber]) {
        let faceGeometry = ARFaceGeometry(blendShapes: blendShapes)!
        geometry.update(from: faceGeometry)
    }
}

However, this is not suitable for real-time use since ARFaceGeometry the line alone takes around 0.01

seconds (for reference only, at 60 fps we have a total frame budget of 0.0166 seconds).

After a few hundred updates, we seem to run into a kind of error that takes the entire game loop to 10-20 frames per second. Here is a six second sample from the profile that looks ARFaceGeometry takes 2.3 seconds !:

ARFaceGeometry takes 2.3 seconds in a 6 second sample

Is there a more efficient way to update an existing one ARSCNFaceGeometry from a set of mixture forms?

For example, with custom 3D models, I can only update the blend shape values SCNNode.morpher. Is there an equivalent for ARSCNFaceGeometry?


Source link