如何使用look right之类的面部表情移动模型



我在后置摄像头视图中设置了一个虚拟对象。我想使用面部表情相对于世界原点移动该对象,并测量虚拟对象的位移角。

使用ARKit或RealityKit可以做到这一点吗?

使用以下解决方案。首次设置配置时:

import RealityKit
import ARKit
class ViewController: UIViewController, ARSessionDelegate {
@IBOutlet var arView: ARView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
arView.session.delegate = self
arView.automaticallyConfigureSession = false

let config = ARFaceTrackingConfiguration()
config.isWorldTrackingEnabled = true        // Simultaneous tracking
arView.session.run(config)
}
}

当定义的面部表情出现时运行变换动画:

func facialExpression(anchor: ARFaceAnchor) {

let eyeUpLeft = anchor.blendShapes[.eyeLookUpLeft]
let eyeUpRight = anchor.blendShapes[.eyeLookUpRight]
if ((eyeUpLeft?.decimalValue ?? 0.0) + 
(eyeUpRight?.decimalValue ?? 0.0)) > 0.75 {
// ModelEntity's animation goes here
}
}

代理的方法(以每秒60帧的速度运行(:

func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
guard let faceAnchor = anchors[0] as? ARFaceAnchor else { return }
self.facialExpression(anchor: faceAnchor)
}

你的第二个问题的答案可以在这里看到。

最新更新