Created
January 6, 2023 09:38
-
-
Save wizard1066/71a948291005265b3e12a58ba37811fd to your computer and use it in GitHub Desktop.
This file contains 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 renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { | |
lastTime = time | |
if time > spawnTime { | |
if faceAnchor != nil { | |
DispatchQueue.main.async { [self] in | |
self.cubeNode.simdOrientation = faceAnchor!.leftEyeTransform.orientation | |
let leftOut = faceAnchor?.blendShapes[.eyeLookInLeft]?.doubleValue | |
let rightOut = faceAnchor?.blendShapes[.eyeLookInRight]?.doubleValue | |
let rightUp = faceAnchor?.blendShapes[.eyeLookUpRight]?.doubleValue | |
let leftDown = faceAnchor?.blendShapes[.eyeLookDownLeft]?.doubleValue | |
let angle = rad2deg(Double(faceAnchor!.transform.orientation.angle)) | |
looked.gazeX = rightUp!.description | |
looked.gazeY = angle.description | |
var divisor = 0.3 | |
if leftOut! < divisor && rightOut! < divisor { | |
sphereNode.simdPosition = SIMD3(x: 0, y: 0, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.red.withAlphaComponent(0.90) | |
} | |
if angle < 8 { | |
var corner = false | |
if leftOut! > divisor && rightUp! > 0.1 { | |
sphereNode.simdPosition = SIMD3(x: -1, y: 1, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.yellow.withAlphaComponent(0.90) | |
corner = true | |
} | |
if rightOut! > divisor && rightUp! > 0.1 { | |
sphereNode.simdPosition = SIMD3(x: 1, y: 1, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.yellow.withAlphaComponent(0.90) | |
corner = true | |
} | |
if leftOut! > 0.2 && leftDown! > 0.1 { | |
sphereNode.simdPosition = SIMD3(x: -1, y: -1, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.purple.withAlphaComponent(0.90) | |
corner = true | |
} | |
if rightOut! > 0.2 && leftDown! > 0.1 { | |
sphereNode.simdPosition = SIMD3(x: 1, y: -1, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.purple.withAlphaComponent(0.90) | |
corner = true | |
} | |
if !corner { | |
if leftOut! > divisor { | |
sphereNode.simdPosition = SIMD3(x: -1, y: 0, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.blue.withAlphaComponent(0.90) | |
} | |
if rightOut! > divisor { | |
sphereNode.simdPosition = SIMD3(x: 1, y: 0, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.blue.withAlphaComponent(0.90) | |
} | |
if rightUp! > 0.1 { | |
sphereNode.simdPosition = SIMD3(x: 0, y: 1, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.green.withAlphaComponent(0.90) | |
} | |
if leftDown! > divisor { | |
sphereNode.simdPosition = SIMD3(x: 0, y: -1, z: -6) | |
sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.green.withAlphaComponent(0.90) | |
} | |
} | |
} | |
} | |
} | |
spawnTime = time + TimeInterval(0.25) | |
} | |
} | |
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) { | |
guard let faceAnchor = anchor as? ARFaceAnchor else { return } | |
self.faceAnchor = faceAnchor | |
} | |
func rad2deg(_ number: Double) -> Double { | |
return number * 180 / .pi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment