Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- See LICENSE folder for this sample’s licensing information.
- Abstract:
- An `SCNNode` subclass demonstrating a basic use of `ARSCNFaceGeometry`.
- */
- import ARKit
- import SceneKit
- class Mask: SCNNode, VirtualFaceContent {
- var faceOrigin: SCNNode?
- init(geometry: ARSCNFaceGeometry) {
- let material = geometry.firstMaterial!
- material.diffuse.contents = UIColor.lightGray
- material.lightingModel = .physicallyBased
- super.init()
- self.geometry = geometry
- faceOrigin = loadedContentForAsset(named: "coordinateOrigin")
- addChildNode(faceOrigin!)
- faceOrigin?.position.z = 0.05;
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("\(#function) has not been implemented")
- }
- // MARK: VirtualFaceContent
- /// - Tag: SCNFaceGeometryUpdate
- func update(withFaceAnchor anchor: ARFaceAnchor) {
- let faceGeometry = geometry as! ARSCNFaceGeometry
- faceGeometry.update(from: anchor.geometry)
- let nosePos: SCNVector3 = faceOrigin!.worldPosition
- let facePos: SCNVector3 = self.worldPosition
- let vector: SCNVector3 = SCNVector3(
- nosePos.x - facePos.x,
- nosePos.y - facePos.y,
- nosePos.z - facePos.z
- )
- /* Calculate the fromula */
- let t = (-facePos.z)/vector.z
- let newX = facePos.x + vector.x * t
- let newY = facePos.y + vector.y * t
- let newZ = 0
- print(newX, newY, newZ)
- }
- }
Add Comment
Please, Sign In to add comment