I'm using python's media pipe library and webcam to track pose. The obtained pose landmarks is transferred to its unity clients. The data is of JSON form and its structure is
{
keypoint_number:{
"x": (some value say) 0.4134315135,
"y": 0.8134315135,
"z": 0.3123212312
}
}
totally 32 key points as per the media pipe pose estimation.
now I'm transferring these data over UDP connection.
Now the problem is when I try to map these coordinates onto unity's humanoid or robot character, the character dismantles/shatters.
What I did was I just mapped the local position of the bones of the character with the received key points coordinates.
I am stuck with this please help me.
Receiver.cs
public class Receiver : MonoBehaviour
{
private Socket? _clientSocket;
private EndPoint? _socketEndPoint;
private byte[]? _buffer;
public GameObject? Body;
void Start()
{
_clientSocket = new Socket (AddressFamily.InterNetwork
, SocketType.Dgram,
ProtocolType.Udp);
_clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
_clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_socketEndPoint = (EndPoint)new IPEndPoint(IPAddress.Any, 8080);
_clientSocket.Bind(_socketEndPoint);
_buffer = new byte[1024 * 5];
}
void Update() {
Array.Clear(_buffer, 0, _buffer.Length);
_clientSocket?.ReceiveFrom(_buffer
, ref _socketEndPoint);
string landmarksString = Encoding.UTF8.GetString(_buffer);
Dictionary<int, Dictionary<string, double>> landmarks
= JsonConvert.DeserializeObject<Dictionary<int, Dictionary<string, double>>>(landmarksString);
float z = (float)(landmarks[23]["z"] + landmarks[24]["z"]) / 2;
Transform[] bodyPoints = new Transform[Body.transform.childCount];
for (int i = 0; i < Body.transform.childCount; i++)
bodyPoints[i] = Body.transform.GetChild(i);
foreach(int keypoint in landmarks.Keys) {
float x = (float) landmarks[keypoint]["x"];
float y = (float) landmarks[keypoint]["y"];
bodyPoints[keypoint].localPosition = new Vector3(x, y, z);
}
}
}