Created
October 14, 2018 02:13
-
-
Save SunXiaoShan/7a191e9f59cb30d841544fa14ff6aba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func updateFeatures(for node: SCNNode, using anchor: ARFaceAnchor) { | |
for (feature, indices) in zip(features, featureIndices) { | |
let child = node.childNode(withName: feature, recursively: false) as? EmojiNode | |
let vertices = indices.map { anchor.geometry.vertices[$0] } | |
child?.updatePosition(for: vertices) | |
switch feature { | |
case "leftEye": | |
let scaleX = child?.scale.x ?? 1.0 | |
let eyeBlinkValue = anchor.blendShapes[.eyeBlinkLeft]?.floatValue ?? 0.0 | |
child?.scale = SCNVector3(scaleX, 1.0 - eyeBlinkValue, 1.0) | |
case "rightEye": | |
let scaleX = child?.scale.x ?? 1.0 | |
let eyeBlinkValue = anchor.blendShapes[.eyeBlinkRight]?.floatValue ?? 0.0 | |
child?.scale = SCNVector3(scaleX, 1.0 - eyeBlinkValue, 1.0) | |
case "mouth": | |
let jawOpenValue = anchor.blendShapes[.jawOpen]?.floatValue ?? 0.2 | |
child?.scale = SCNVector3(1.0, 0.8 + jawOpenValue, 1.0) | |
default: | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment