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
let noseOptions = ["👃", "🐽", "💧", " "] | |
let eyeOptions = ["👁", "🌕", "🌟", "🔥", "⚽️", "🔎", " "] | |
let mouthOptions = ["👄", "👅", "❤️", " "] | |
let hatOptions = ["🎓", "🎩", "🧢", "⛑", "👒", " "] | |
let features = ["nose", "leftEye", "rightEye", "mouth", "hat"] | |
let featureIndices = [[9], [1064], [42], [24, 25], [20]] |
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 renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) { | |
guard let faceAnchor = anchor as? ARFaceAnchor, let faceGeometry = node.geometry as? ARSCNFaceGeometry else { return } | |
// 更新,臉部表情變化時的位置 | |
faceGeometry.update(from: faceAnchor.geometry) | |
updateFeatures(for: node, using: faceAnchor) | |
} |
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
public enum SCNFillMode : UInt { | |
case fill | |
case lines | |
} |
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
var originalSource: Any? = nil | |
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { | |
if originalSource == nil { | |
originalSource = sceneView.scene.background.contents | |
sceneView.scene.background.contents = UIColor.black | |
} else { | |
sceneView.scene.background.contents = originalSource | |
originalSource = nil | |
} | |
} |
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
extension ViewController: ARSCNViewDelegate { | |
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 | |
DispatchQueue.main.async { |
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
override func viewDidLoad() { | |
super.viewDidLoad() | |
// 判斷是否裝置支援 ar face 功能 | |
guard ARFaceTrackingConfiguration.isSupported else { fatalError() } | |
sceneView.delegate = self | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) |
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
@IBOutlet weak var sceneView: ARSCNView! |
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
- (void)sendMessage:(NSString *)context { | |
if ([self.peripherals count] < 1 || context == nil) { | |
return; | |
} | |
NSData *xmlData = [context dataUsingEncoding:NSUTF8StringEncoding]; | |
CBPeripheral *peripheral = [self.peripherals firstObject]; | |
[peripheral writeValue:xmlData forCharacteristic:self.cbCharacteristic type:CBCharacteristicWriteWithResponse]; | |
} |
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
- (void)peripheral:(CBPeripheral *)peripheral | |
didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic | |
error:(NSError *)error { | |
if (error) { | |
return; | |
} | |
if (characteristic.value == nil) { | |
return; | |
} |
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
- (void)centralManager:(CBCentralManager *)central | |
didConnectPeripheral:(CBPeripheral *)peripheral { | |
[self.centralManager stopScan]; | |
peripheral.delegate = self; | |
[peripheral discoverServices:@[[CBUUID UUIDWithString:kServiceUUID]]]; | |
} | |
- (void)centralManager:(CBCentralManager *)central | |
didFailToConnectPeripheral:(CBPeripheral *)peripheral |