- 通过 UDP 接收数据

如果从 PC 端向 iOS 端口 49993 发送字符串 “FACEMOTION3D_OtherStreaming”,Facemotion3d 会通过 UDP 以 60FPS 向端口 49993 返回数据。

- 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 Name&Parameters (0 ~ 100) | BlendShape Names-Parameters (0 ~ 100) | .... | = head # Euler angles X (degree), Euler angles Y, Euler angles Z, Position values X, Position values Y, Position values Z | rightEye #Euler angles X, Euler angles Y, Euler angles Z | leftEye #Euler angles X, Euler angles Y, Euler angles Z |

参数可能包含负值,也可能超过 100。

角度相关数据以度数发送,而不是弧度。

- 通过 TCP/IP 接收数据

使用 UDP 时可能会丢帧,因此也可以使用 TCP/IP 接收。

如果通过 UDP 向 iOS 端口 49993 发送字符串 “FACEMOTION3D_OtherStreaming|protocol=tcp”,数据会发送到 PC 端口 49986。

发送的字符串只是在 UDP 时发送的字符串末尾追加了 “___FACEMOTION3D”。

-sample

BlendShape Name&Parameter (0 ~ 100) | BlendShape Name-Parameter (0 ~ 100) | .... | = head # Euler angles X, Euler angles Y, Euler angles Z, moving values X, moving values Y, moving values Z | rightEye #Euler angles X, Euler angles Y, Euler angles Z | leftEye #Euler angles X, Euler angles Y, Euler angles Z | ___ Facemotion3d

通过 TCP/IP 从 iOS 接收到 PC 时,会发送按帧分割的字符串,因此请使用末尾的 “___FACEMOTION3D” 作为分隔符。

要停止 TCP/IP 发送,请向端口 49993 发送字符串 “StopStreaming_FACEMOTION3D”。

- 通过 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 向 iOS 端口 49993 发送字符串 “v2_OtherBakeRecordedAnimation_FACEMOTION3D”,录制数据会通过 TCP/IP 发送到 PC 端口 49987。

发送的字符串格式如下:

["......", "......", "......"]===[time01, time02, time03]___FACEMOTION3D.

The ["......", "......", "......"] 部分为 JSON 格式,包含与 UDP 和 TCP/IP 使用的相同字符串。

[time01, time02, time03] 包含与每个录制数据索引对应的录制时间。

- 接收 iOS 中录制数据和音频的方法

如果通过 UDP 向 iOS 端口 49993 发送字符串 “v2_OtherBakeRecordedAnimation_FACEMOTION3D”,录制数据会通过 TCP/IP 发送到 PC 端口 49987。

发送的字符串格式如下:

["......", "......", "......"]===[time01, time02, time03]___FACEMOTION3D.

The ["......", "......", "......"] 部分为 JSON 格式,包含与 UDP 和 TCP/IP 使用的相同字符串。

[time01, time02, time03] 包含与每个录制数据索引对应的录制时间。

- 向用户显示当前正在 Bake

要在 iOS 应用中显示 “Currently baking”,请向 UDP 端口 49993 发送 “BakeOther_FACEMOTION3D”。要隐藏 baking 消息,请向 UDP 端口 49993 发送 “BakeFinishOther_FACEMOTION3D”。

- 在 iOS 应用内开始录制

要在 iOS 应用内开始录制,请向端口 49993 发送 “FACEMOTION3D_StartRecording”。

- 在 iOS 应用内停止录制

要在 iOS 应用内停止录制,请向端口 49993 发送 “FACEMOTION3D_StopRecording”。

- 在 iOS 应用内停止 streaming

要在 iOS 应用内停止 streaming,请向端口 49993 发送 “StopStreaming_FACEMOTION3D”。

- 执行 Reset 按钮

向 iOS 端口 49993 发送字符串 “FACEMOTION3D_resetButton”。

- Bluetooth

使用 Other 许可证通过 Bluetooth 连接时,请使用以下代码:
https://github.com/emoto-yasushi/iFacialMocap_Facemotion3d_Bluetooth

- 追加信息

- Facemotion3d 接受命令后,在 0.02 秒内不会接受外部命令。
- 目前,接收命令的服务器只有 UDP 服务器。UDP 有时会丢失数据,因此发送约三次可以提高准确通信的概率。
第三方开发者不一定必须使用 Other 许可证。
第三方开发者可以使用 Unity 许可证、Blender 许可证等自己偏好的许可证来选择要发送的数据类型。
请理解,各许可证的价格今后可能会根据情况发生变化。