Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created October 14, 2018 02:10
Show Gist options
  • Save SunXiaoShan/361a1dd76b50636eab9b8e4e2161c9a4 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/361a1dd76b50636eab9b8e4e2161c9a4 to your computer and use it in GitHub Desktop.
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
guard let faceAnchor = anchor as? ARFaceAnchor,
let device = sceneView.device else { return nil }
let faceGeometry = ARSCNFaceGeometry(device: device)
let node = SCNNode(geometry: faceGeometry)
node.geometry?.firstMaterial?.fillMode = .lines
node.geometry?.firstMaterial?.transparency = 0.0 // hide mask line
let noseNode = EmojiNode(with: noseOptions)
noseNode.name = "nose"
node.addChildNode(noseNode)
let leftEyeNode = EmojiNode(with: eyeOptions)
leftEyeNode.name = "leftEye"
leftEyeNode.rotation = SCNVector4(0, 1, 0, GLKMathDegreesToRadians(180.0))
node.addChildNode(leftEyeNode)
let rightEyeNode = EmojiNode(with: eyeOptions)
rightEyeNode.name = "rightEye"
node.addChildNode(rightEyeNode)
let mouthNode = EmojiNode(with: mouthOptions)
mouthNode.name = "mouth"
node.addChildNode(mouthNode)
let hatNode = EmojiNode(with: hatOptions)
hatNode.name = "hat"
node.addChildNode(hatNode)
DispatchQueue.main.async {
self.updateFeatures(for: node, using: faceAnchor)
}
return node
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment