- 透過 UDP 接收資料
如果從 PC 端將字串 "FACEMOTION3D_OtherStreaming" 傳送到 iOS 端的 49993 port,Facemotion3d 會以 UDP 60FPS 回覆到 49993 port。
- Python 範例
from socket import *
DstIP = "192.168.1.7"
DstPort = 49993
DstAddr = (DstIP,DstPort)
udpClntSock = socket(AF_INET, SOCK_DGRAM)
data = "FACEMOTION3D_OtherStreaming"
data = data.encode('utf-8')
udpClntSock.sendto(data,DstAddr)
server = socket(AF_INET, SOCK_DGRAM)
server.bind(("", 49983))
server.settimeout(0.05)
while True:
try:
messages, address = server.recvfrom(8192)
print(messages.decode('utf-8'))
except:
pass
- 每一幀送出的字串如下。
eyeLookOutLeft&3|mouthPressRight&14|jawForward&8|browInnerUp&19|jawLeft&4|mouthShrugUpper&28|eyeSquintLeft&4|eyeWideLeft&0|mouthPucker&5|mouthLowerDownLeft&6|eyeBlinkLeft&29|mouthShrugLower&20|mouthSmileLeft&0|cheekSquintRight&9|eyeWideRight&0|mouthFunnel&4|mouthStretchRight&13|browDownRight&2|tongueOut&0|cheekSquintLeft&8|mouthStretchLeft&17|mouthUpperUpRight&10|noseSneerLeft&28|browOuterUpLeft&0|eyeLookInRight&15|mouthDimpleRight&7|mouthRollUpper&5|mouthLowerDownRight&6|mouthClose&6|mouthFrownLeft&3|eyeBlinkRight&29|mouthFrownRight&2|mouthUpperUpLeft&11|browDownLeft&1|eyeLookOutRight&0|cheekPuff&4|eyeLookInLeft&0|mouthDimpleLeft&8|eyeLookDownLeft&36|eyeSquintRight&4|mouthRollLower&7|eyeLookUpLeft&0|eyeLookUpRight&0|mouthSmileRight&0|jawRight&0|noseSneerRight&25|mouthPressLeft&13|jawOpen&4|browOuterUpRight&0|eyeLookDownRight&36|mouthLeft&1|mouthRight&0|FM_SAD&0|FM_ANGRY&0|FM_VF&0|FM_TH&0|FM_browUpRight&0|FM_browUpLeft&0|=head#-22.167973,0.45402408,-4.8798294,-0.039975993,-0.048437987,-0.45562273|rightEye#12.759762,5.527712,1.2244859|leftEye#12.862795,1.264116,0.28145725|
- 每一幀送出的字串格式如下。
BlendShape 名稱&參數 (0 ~ 100) | BlendShape 名稱-參數 (0 ~ 100) | .... | = head # Euler 角 X(度)、Euler 角 Y、Euler 角 Z、位置值 X、位置值 Y、位置值 Z | rightEye #Euler 角 X、Euler 角 Y、Euler 角 Z | leftEye #Euler 角 X、Euler 角 Y、Euler 角 Z |
參數可能包含負值,也可能超過 100。
角度相關資料會以度數傳送,而不是弧度。
- 透過 TCP / IP 接收資料
使用 UDP 時可能會掉幀,因此也可以改用 TCP / IP 接收。
如果透過 UDP 將字串 "FACEMOTION3D_OtherStreaming|protocol=tcp" 傳送到 iOS 端的 49993 port,資料會被送到 PC 端的 49986 port。
送出的字串只是把 "___FACEMOTION3D" 加到 UDP 時傳送的字串後面。
- 範例
BlendShape 名稱&參數 (0 ~ 100) | BlendShape 名稱-參數 (0 ~ 100) | .... | = head # Euler 角 X、Euler 角 Y、Euler 角 Z、移動值 X、移動值 Y、移動值 Z | rightEye #Euler 角 X、Euler 角 Y、Euler 角 Z | leftEye #Euler 角 X、Euler 角 Y、Euler 角 Z | ___ Facemotion3d
透過 TCP / IP 從 iOS 傳到 PC 時,可能會收到被切開的字串,因此請使用結尾的 "___FACEMOTION3D" 作為分隔符。
若要停止 TCP / IP 傳送,請將字串 "StopStreaming_FACEMOTION3D" 傳送到 49993 port。
- 透過 TCP / IP 接收的 Python 使用範例
from socket import socket, AF_INET, SOCK_DGRAM, SOCK_STREAM
#UDP send
HOST = ''
PORT = 49993
ADDRESS = "192.168.1.7" #iOS address
s = socket(AF_INET, SOCK_DGRAM)
msg = "FACEMOTION3D_OtherStreaming|protocol=tcp"
s.sendto(msg.encode(), (ADDRESS, PORT))
s.close()
#create tcp server
with socket(AF_INET, SOCK_STREAM) as tcp_server:
tcp_server.bind(('192.168.1.5', 49986)) #192.168.1.5 is pc address
tcp_server.listen(1)
while True:
conn, addr = tcp_server.accept()
with conn:
while True:
data = conn.recv(10000)
print(data.decode('utf-8'))
- 接收 iOS 中的錄製資料
如果透過 UDP 將字串「v2_OtherBakeRecordedAnimation_FACEMOTION3D」傳送到 iOS 端的 49993 port,錄製資料會透過 TCP/IP 的 49987 port 傳送到 PC。
傳送的字串格式如下:
["......", "......", "......"]===[time01, time02, time03]___FACEMOTION3D.
其中["......", "......", "......"]為 JSON 格式,內含與 UDP 和 TCP/IP 使用相同的字串。
[time01, time02, time03]包含各錄製資料索引所對應的錄製時間。
- 接收 iOS 中的錄製資料與音訊
如果透過 UDP 將字串「v2_OtherBakeRecordedAnimation_FACEMOTION3D」傳送到 iOS 端的 49993 port,錄製資料會透過 TCP/IP 的 49987 port 傳送到 PC。
傳送的字串格式如下:
["......", "......", "......"]===[time01, time02, time03]___FACEMOTION3D.
其中["......", "......", "......"]為 JSON 格式,內含與 UDP 和 TCP/IP 使用相同的字串。
[time01, time02, time03]包含各錄製資料索引所對應的錄製時間。
- 向使用者顯示目前正在 baking
若要在 iOS App 中顯示「Currently baking」,請將「BakeOther_FACEMOTION3D」送到 UDP 49993 port。若要隱藏 baking 訊息,請將「BakeFinishOther_FACEMOTION3D」送到 UDP 49993 port。
- 在 iOS App 內開始錄製
若要在 iOS App 內開始錄製,請將 "FACEMOTION3D_StartRecording" 傳送到 49993 port。
- 在 iOS App 內停止錄製
若要在 iOS App 內停止錄製,請將 "FACEMOTION3D_StopRecording" 傳送到 49993 port。
- 在 iOS App 內停止串流
若要在 iOS App 內停止串流,請將 "StopStreaming_FACEMOTION3D" 傳送到 49993 port。
- 執行 Reset Button
將字串 "FACEMOTION3D_resetButton" 傳送到 iOS 的 49993 port。
- Bluetooth
若要使用 Other license 透過 Bluetooth 連線,請使用以下程式碼:
https://github.com/emoto-yasushi/iFacialMocap_Facemotion3d_Bluetooth
- 補充資訊
- Facemotion3d 接受指令後,0.02 秒內不會再接受外部指令。
- 目前只有 UDP server 會接收指令。UDP 有時可能遺失資料,因此傳送約三次可提高正確通訊的機率。
第三方開發者不一定必須使用 Other license。
第三方開發者可以使用自己偏好的 license,例如 Unity license 或 Blender license,來選擇要傳送的資料類型。
請理解,各 license 的價格日後可能依情況而變更。