From de5bf3a10e0f9a6ac789394bec4425263771e500 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 19 Nov 2024 17:32:51 +0100 Subject: [PATCH] Tested with VR --- .../Networking/Roboid/HumanoidPlayerRoboid.cs | 107 ++++++++++++------ 1 file changed, 74 insertions(+), 33 deletions(-) diff --git a/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs b/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs index bce4f2e..3cd3640 100644 --- a/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs +++ b/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs @@ -250,6 +250,25 @@ namespace Passer.Humanoid { SendName(remoteHumanoid, 0, "Humanoid"); SendModel(remoteHumanoid, "https://gitlab.passervr.com/passer/models/humanoid/-/raw/main/MakeHumanPasserMedium.glb?ref_type=heads&inline=false"); + SendSubThing(remoteHumanoid, remoteHumanoid.hipsTarget.hips); + SendSubThing(remoteHumanoid, remoteHumanoid.hipsTarget.spine); + SendSubThing(remoteHumanoid, remoteHumanoid.hipsTarget.chest); + SendSubThing(remoteHumanoid, remoteHumanoid.headTarget.neck); + SendSubThing(remoteHumanoid, remoteHumanoid.headTarget.head); + + SendSubThing(remoteHumanoid, remoteHumanoid.leftHandTarget.upperArm); + SendSubThing(remoteHumanoid, remoteHumanoid.leftHandTarget.forearm); + SendSubThing(remoteHumanoid, remoteHumanoid.leftHandTarget.hand); + + SendSubThing(remoteHumanoid, remoteHumanoid.rightHandTarget.upperArm); + SendSubThing(remoteHumanoid, remoteHumanoid.rightHandTarget.forearm); + SendSubThing(remoteHumanoid, remoteHumanoid.rightHandTarget.hand); + + SendSubThing(remoteHumanoid, remoteHumanoid.rightFootTarget.upperLeg); + SendSubThing(remoteHumanoid, remoteHumanoid.rightFootTarget.lowerLeg); + SendSubThing(remoteHumanoid, remoteHumanoid.rightFootTarget.foot); + SendSubThing(remoteHumanoid, remoteHumanoid.rightFootTarget.toes); + SendSubThing(remoteHumanoid, remoteHumanoid.leftFootTarget.upperLeg); SendSubThing(remoteHumanoid, remoteHumanoid.leftFootTarget.lowerLeg); SendSubThing(remoteHumanoid, remoteHumanoid.leftFootTarget.foot); @@ -350,7 +369,11 @@ namespace Passer.Humanoid { if (debug <= HumanoidNetworking.DebugLevel.Debug) Debug.Log("Send SubThing " + humanoid.humanoidId + " nwId: " + humanoid.nwId); - SubThingMsg thingMsg = new((byte)bone.boneId, (byte)bone.parent.boneId, bone.bone.transform.position); + SubThingMsg thingMsg; + if (bone.parent != null) + thingMsg = new((byte)bone.boneId, (byte)bone.parent.boneId, bone.bone.transform.position); + else + thingMsg = new((byte)bone.boneId, 0, bone.bone.transform.position); if (udpClient != null) { byte[] data = thingMsg.Serialize(); @@ -480,9 +503,13 @@ namespace Passer.Humanoid { readonly byte boneId; readonly Quat32 boneOrientation; - public RoboidBonePose(HumanoidTarget.TargetedBone targetedBone) { + public RoboidBonePose(HumanoidTarget.TargetedBone targetedBone, bool isRoot = false) { this.boneId = (byte)targetedBone.boneId; - this.boneOrientation = new Quat32(targetedBone.bone.transform.localRotation); + if (isRoot) { + this.boneOrientation = new Quat32(targetedBone.bone.transform.rotation); + } + else + this.boneOrientation = new Quat32(targetedBone.bone.transform.rotation); } public override byte[] Serialize() { @@ -502,45 +529,59 @@ namespace Passer.Humanoid { } - [Serializable] - public class RoboidPose : HumanoidNetworking.HumanoidPose { - readonly Quat32 headOrientation; + //[Serializable] + //public class RoboidPose : HumanoidNetworking.HumanoidPose { + // readonly Quat32 headOrientation; - public RoboidPose(HumanoidControl humanoid) { - headOrientation = new Quat32(humanoid.headTarget.head.bone.transform.rotation); - } + // public RoboidPose(HumanoidControl humanoid) { + // headOrientation = new Quat32(humanoid.headTarget.head.bone.transform.rotation); + // } - public override byte[] Serialize() { - MemoryStream ms = new(); - BinaryWriter bw = new(ms); - bw.Write((byte)0x10); // PoseMsg - bw.Write((byte)this.head.boneId); // Thing Id - bw.Write((byte)0x03); // Pose_Orientation + // public override byte[] Serialize() { + // MemoryStream ms = new(); + // BinaryWriter bw = new(ms); + // bw.Write((byte)0x10); // PoseMsg + // bw.Write((byte)this.head.boneId); // Thing Id + // bw.Write((byte)0x03); // Pose_Orientation - bw.Write((byte)0x00); // Dummy data - bw.Write((byte)0x00); - bw.Write((byte)0x00); - bw.Write((byte)0x00); + // bw.Write((byte)0x00); // Dummy data + // bw.Write((byte)0x00); + // bw.Write((byte)0x00); + // bw.Write((byte)0x00); - SendQuat32(bw, headOrientation); + // SendQuat32(bw, headOrientation); - byte[] data = ms.ToArray(); - return data; - } - } + // byte[] data = ms.ToArray(); + // return data; + // } + //} public virtual void UpdateHumanoidPose(HumanoidControl humanoid) { if (debug <= HumanoidNetworking.DebugLevel.Debug) Debug.Log("Send Pose Humanoid " + humanoid.humanoidId + " nwId: " + humanoid.nwId); - RoboidPose humanoidPose = new(humanoid); - if (createLocalRemotes) - this.Receive(humanoidPose); + //RoboidPose humanoidPose = new(humanoid); + //if (createLocalRemotes) + // this.Receive(humanoidPose); + + //if (udpClient != null) { + // byte[] data = humanoidPose.Serialize(); + // udpClient.Send(data, data.Length, "127.0.0.1", nssPort); + //} + SendBone(humanoid.hipsTarget.hips, true); + SendBone(humanoid.hipsTarget.spine); + SendBone(humanoid.hipsTarget.chest); + SendBone(humanoid.headTarget.neck); + SendBone(humanoid.headTarget.head); + + SendBone(humanoid.leftHandTarget.upperArm); + SendBone(humanoid.leftHandTarget.forearm); + SendBone(humanoid.leftHandTarget.hand); + + SendBone(humanoid.rightHandTarget.upperArm); + SendBone(humanoid.rightHandTarget.forearm); + SendBone(humanoid.rightHandTarget.hand); - if (udpClient != null) { - byte[] data = humanoidPose.Serialize(); - udpClient.Send(data, data.Length, "127.0.0.1", nssPort); - } SendBone(humanoid.leftFootTarget.upperLeg); SendBone(humanoid.leftFootTarget.lowerLeg); SendBone(humanoid.leftFootTarget.foot); @@ -550,8 +591,8 @@ namespace Passer.Humanoid { SendBone(humanoid.rightFootTarget.foot); } - private void SendBone(HumanoidTarget.TargetedBone bone) { - RoboidBonePose bonePose = new(bone); + private void SendBone(HumanoidTarget.TargetedBone bone, bool isRoot = false) { + RoboidBonePose bonePose = new(bone, isRoot); byte[] buffer = bonePose.Serialize(); udpClient.Send(buffer, buffer.Length, "127.0.0.1", nssPort); }