- 使用包含BlendShapes的模型。如sample的fbx模型
- 在Blender中匯入fbx模型,確認Object Data Properties有外形鍵
- 匯出成dae檔,確認有勾選外形鍵
- 使用ColladaMorphAdjuster將剛剛的dae檔,轉成SceneKit支援的dae檔
- 在XCode中,可以看到模型的Attributes裡,Geometry Morphers中會有類似臉部細心的key
- Editor -> convert to SceneKit file format
- 載入模型
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
if anchor is ARFaceAnchor {
let scene = SCNScene(named: "art.scnassets/POLYWINK_BOD_157_SAMPLE.scn")!
face = scene.rootNode.childNode(withName: "POLYWINK_Louise", recursively: true)
face?.geometry?.firstMaterial?.lightingModel = .physicallyBased
return scene.rootNode
} else {
return nil
}
}
- 將BlendShapesLocation對照到模型的外形鍵
let blendShapeMap: [ARFaceAnchor.BlendShapeLocation: String] = [
.eyeBlinkLeft: "Eye_Closed_Left",
.eyeBlinkRight: "Eye_Closed_Right"
]
- 將faceAnchor的blendShapes對照到node的morpher
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
if let faceAnchor = anchor as? ARFaceAnchor {
let blendShapes = faceAnchor.blendShapes
blendShapeMap.forEach{ key, name in
if let weight = blendShapes[key] as? CGFloat {
face?.morpher?.setWeight(weight, forTargetNamed: name)
}
}
}
}
2022年2月28日 星期一
ARKit(SceneKit) 更新模型臉部表情
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言