Guest User

Untitled

a guest
May 24th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. /*
  2. See LICENSE folder for this sample’s licensing information.
  3.  
  4. Abstract:
  5. An `SCNNode` subclass demonstrating a basic use of `ARSCNFaceGeometry`.
  6. */
  7.  
  8. import ARKit
  9. import SceneKit
  10.  
  11. class Mask: SCNNode, VirtualFaceContent {
  12.  
  13. var faceOrigin: SCNNode?
  14.  
  15. init(geometry: ARSCNFaceGeometry) {
  16. let material = geometry.firstMaterial!
  17.  
  18. material.diffuse.contents = UIColor.lightGray
  19. material.lightingModel = .physicallyBased
  20.  
  21. super.init()
  22. self.geometry = geometry
  23.  
  24. faceOrigin = loadedContentForAsset(named: "coordinateOrigin")
  25. addChildNode(faceOrigin!)
  26. faceOrigin?.position.z = 0.05;
  27. }
  28.  
  29. required init?(coder aDecoder: NSCoder) {
  30. fatalError("\(#function) has not been implemented")
  31. }
  32.  
  33. // MARK: VirtualFaceContent
  34.  
  35. /// - Tag: SCNFaceGeometryUpdate
  36. func update(withFaceAnchor anchor: ARFaceAnchor) {
  37. let faceGeometry = geometry as! ARSCNFaceGeometry
  38. faceGeometry.update(from: anchor.geometry)
  39. let nosePos: SCNVector3 = faceOrigin!.worldPosition
  40. let facePos: SCNVector3 = self.worldPosition
  41. let vector: SCNVector3 = SCNVector3(
  42. nosePos.x - facePos.x,
  43. nosePos.y - facePos.y,
  44. nosePos.z - facePos.z
  45. )
  46.  
  47. /* Calculate the fromula */
  48. let t = (-facePos.z)/vector.z
  49. let newX = facePos.x + vector.x * t
  50. let newY = facePos.y + vector.y * t
  51. let newZ = 0
  52.  
  53. print(newX, newY, newZ)
  54. }
  55. }
Add Comment
Please, Sign In to add comment