From 5432a9660d5f9e9bd3b51dbf65285db748f587c8 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 28 May 2025 12:19:59 +0200 Subject: [PATCH] Compatiblity with RoboidControl --- .../Resources/HumanoidPlayer.prefab | 2 +- .../Scripts/Networking/Roboid/BoneThing.cs | 2 +- .../Networking/Roboid/HumanoidPlayerRoboid.cs | 50 ++++++++++--------- .../Scripts/Targets/FingersTarget.cs | 8 +-- .../Scripts/Targets/FootTarget.cs | 16 +++--- .../Scripts/Targets/HandTarget.cs | 10 ++-- .../Scripts/Targets/HeadTarget.cs | 8 +-- .../Scripts/Targets/HipsTarget.cs | 14 +++--- .../Scripts/Targets/HumanoidTarget.cs | 30 +++++------ 9 files changed, 68 insertions(+), 72 deletions(-) diff --git a/Runtime/HumanoidControl/Prefabs/Networking/Resources/HumanoidPlayer.prefab b/Runtime/HumanoidControl/Prefabs/Networking/Resources/HumanoidPlayer.prefab index 62a7795..2921609 100644 --- a/Runtime/HumanoidControl/Prefabs/Networking/Resources/HumanoidPlayer.prefab +++ b/Runtime/HumanoidControl/Prefabs/Networking/Resources/HumanoidPlayer.prefab @@ -51,5 +51,5 @@ MonoBehaviour: _sendRate: 2 _createLocalRemotes: 0 sitePort: 7681 + localPort: 7682 siteAddress: 127.0.0.1 - networkId: 0 diff --git a/Runtime/HumanoidControl/Scripts/Networking/Roboid/BoneThing.cs b/Runtime/HumanoidControl/Scripts/Networking/Roboid/BoneThing.cs index a5e2570..2badf5f 100644 --- a/Runtime/HumanoidControl/Scripts/Networking/Roboid/BoneThing.cs +++ b/Runtime/HumanoidControl/Scripts/Networking/Roboid/BoneThing.cs @@ -7,7 +7,7 @@ namespace RoboidControl { protected HumanoidTarget.TargetedBone bone; - public BoneThing(HumanoidTarget.TargetedBone bone) + public BoneThing(Participant owner, HumanoidTarget.TargetedBone bone) : base(owner) { this.bone = bone; } diff --git a/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs b/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs index b32424b..297520b 100644 --- a/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs +++ b/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs @@ -35,7 +35,8 @@ namespace Passer.Humanoid set { _createLocalRemotes = value; } } - public int sitePort = 7681; + public int sitePort = 7682; + public int localPort = 7681; public string siteAddress = "127.0.0.1"; // protected UdpClient udpClient; // protected IPEndPoint endPoint; @@ -158,7 +159,7 @@ namespace Passer.Humanoid { readonly HumanoidPlayer player; - public HumanoidParticipant(string ipAddress, int port, HumanoidPlayer player) : base(ipAddress, port) + public HumanoidParticipant(string ipAddress, int port, int localPort, HumanoidPlayer player) : base(ipAddress, port, localPort) { this.player = player; } @@ -238,7 +239,7 @@ namespace Passer.Humanoid mInstance = this; Console.SetOut(new UnityLogWriter()); - this.participant = new HumanoidParticipant(siteAddress, sitePort, this); + this.participant = new HumanoidParticipant(siteAddress, sitePort, localPort, this); // endPoint = new IPEndPoint(IPAddress.Any, sitePort + 3); // udpClient = new UdpClient(endPoint); @@ -264,7 +265,7 @@ namespace Passer.Humanoid } humanoid = humanoids[0]; - headThing = new BoneThing(humanoid.headTarget.head); + headThing = new BoneThing(this.participant, humanoid.headTarget.head); // this.participant.Send(new ThingMsg((byte)humanoid.nwId, headThing)); // //endpoint = new IPEndPoint(IPAddress.Any, sitePort); @@ -337,6 +338,7 @@ namespace Passer.Humanoid protected virtual void LateUpdate() { + participant.Update((ulong)(Time.time * 1000)); // foreach (Client client in Client.clients) { // if (client is HumanoidParticipant humanoidClient) { // while (humanoidClient.messageQueue.TryDequeue(out Passer.Control.IMessage msg)) @@ -344,26 +346,26 @@ namespace Passer.Humanoid // } // } - if (Time.time > lastSend + 1 / sendRate) - { - if (humanoids != null) - { - foreach (HumanoidControl humanoid in humanoids) - { - if (!humanoid.isRemote) - { - UpdateHumanoidPose(humanoid); - } - } - } - lastSend = Time.time; - } - if (Time.time > lastClientMsg + clientMsgInterval) - { - //SendClientMsg(humanoids[0]); // We just need it for the networkId - this.participant.Send(new ParticipantMsg((byte)humanoid.nwId)); - lastClientMsg = Time.time; - } + // if (Time.time > lastSend + 1 / sendRate) + // { + // if (humanoids != null) + // { + // foreach (HumanoidControl humanoid in humanoids) + // { + // if (!humanoid.isRemote) + // { + // UpdateHumanoidPose(humanoid); + // } + // } + // } + // lastSend = Time.time; + // } + // if (Time.time > lastClientMsg + clientMsgInterval) + // { + // //SendClientMsg(humanoids[0]); // We just need it for the networkId + // this.participant.Send(new ParticipantMsg((byte)humanoid.nwId)); + // lastClientMsg = Time.time; + // } } #endregion Update diff --git a/Runtime/HumanoidControl/Scripts/Targets/FingersTarget.cs b/Runtime/HumanoidControl/Scripts/Targets/FingersTarget.cs index 00593f4..f21df30 100644 --- a/Runtime/HumanoidControl/Scripts/Targets/FingersTarget.cs +++ b/Runtime/HumanoidControl/Scripts/Targets/FingersTarget.cs @@ -75,9 +75,9 @@ namespace Passer.Humanoid { distal.boneId = firstBoneId + 2; //metaCarpal.RetrieveBones(humanoid); - proximal.RetrieveBones(); - intermediate.RetrieveBones(); - distal.RetrieveBones(); + proximal.RetrieveBones(humanoid); + intermediate.RetrieveBones(humanoid); + distal.RetrieveBones(humanoid); } public void MatchTargetToAvatar() { @@ -346,7 +346,7 @@ namespace Passer.Humanoid { //private Quaternion localDefaultRotation; public TargetedPhalanges(TargetedFinger finger, HumanoidTarget.TargetedBone nextBone) - : base(finger.fingers.handTarget.humanoid, nextBone) { + : base(nextBone) { this.finger = finger; } diff --git a/Runtime/HumanoidControl/Scripts/Targets/FootTarget.cs b/Runtime/HumanoidControl/Scripts/Targets/FootTarget.cs index f61815d..85111f5 100644 --- a/Runtime/HumanoidControl/Scripts/Targets/FootTarget.cs +++ b/Runtime/HumanoidControl/Scripts/Targets/FootTarget.cs @@ -216,7 +216,7 @@ namespace Passer.Humanoid { public class TargetedUpperLegBone : TargetedBone { private FootTarget footTarget; - public TargetedUpperLegBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.lowerLeg) { + public TargetedUpperLegBone(FootTarget footTarget) : base(footTarget.lowerLeg) { this.footTarget = footTarget; this.parent = footTarget.humanoid.hipsTarget.hips; } @@ -261,7 +261,7 @@ namespace Passer.Humanoid { public class TargetedLowerLegBone : TargetedBone { private FootTarget footTarget; - public TargetedLowerLegBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.foot) { + public TargetedLowerLegBone(FootTarget footTarget) : base(footTarget.foot) { this.footTarget = footTarget; this.parent = footTarget.upperLeg; } @@ -306,7 +306,7 @@ namespace Passer.Humanoid { public class TargetedFootBone : TargetedBone { private FootTarget footTarget; - public TargetedFootBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.toes) { + public TargetedFootBone(FootTarget footTarget) : base(footTarget.toes) { this.footTarget = footTarget; this.parent = footTarget.lowerLeg; } @@ -378,7 +378,7 @@ namespace Passer.Humanoid { public class TargetedToesBone : TargetedBone { private FootTarget footTarget; - public TargetedToesBone(FootTarget footTarget) : base(footTarget.humanoid) { + public TargetedToesBone(FootTarget footTarget) : base() { this.footTarget = footTarget; this.parent = footTarget.foot; } @@ -555,10 +555,10 @@ namespace Passer.Humanoid { } public void RetrieveBones() { - upperLeg.RetrieveBones(); - lowerLeg.RetrieveBones(); - foot.RetrieveBones(); - toes.RetrieveBones(); + upperLeg.RetrieveBones(this.humanoid); + lowerLeg.RetrieveBones(this.humanoid); + foot.RetrieveBones(this.humanoid); + toes.RetrieveBones(this.humanoid); } #endregion diff --git a/Runtime/HumanoidControl/Scripts/Targets/HandTarget.cs b/Runtime/HumanoidControl/Scripts/Targets/HandTarget.cs index 0850657..905ec40 100644 --- a/Runtime/HumanoidControl/Scripts/Targets/HandTarget.cs +++ b/Runtime/HumanoidControl/Scripts/Targets/HandTarget.cs @@ -387,7 +387,7 @@ namespace Passer.Humanoid { public class TargetedShoulderBone : TargetedBone { private HandTarget handTarget; - public TargetedShoulderBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.upperArm) { + public TargetedShoulderBone(HandTarget handTarget) : base(handTarget.upperArm) { this.handTarget = handTarget; if (handTarget.humanoid == null || handTarget.humanoid.hipsTarget == null) this.parent = null; @@ -463,7 +463,7 @@ namespace Passer.Humanoid { public class TargetedUpperArmBone : TargetedBone { private HandTarget handTarget; - public TargetedUpperArmBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.forearm) { + public TargetedUpperArmBone(HandTarget handTarget) : base(handTarget.forearm) { this.handTarget = handTarget; this.parent = handTarget.shoulder; } @@ -520,7 +520,7 @@ namespace Passer.Humanoid { public class TargetedForearmBone : TargetedBone { private HandTarget handTarget; - public TargetedForearmBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.hand) { + public TargetedForearmBone(HandTarget handTarget) : base(handTarget.hand) { this.handTarget = handTarget; this.parent = handTarget.upperArm; } @@ -583,7 +583,7 @@ namespace Passer.Humanoid { public class TargetedHandBone : TargetedBone { private HandTarget handTarget; - public TargetedHandBone(HandTarget handTarget) : base(handTarget.humanoid) { + public TargetedHandBone(HandTarget handTarget) : base() { this.handTarget = handTarget; this.parent = handTarget.forearm; } @@ -824,7 +824,7 @@ namespace Passer.Humanoid { public void RetrieveBones() { foreach (TargetedBone subTarget in subTargets) - subTarget.RetrieveBones(); + subTarget.RetrieveBones(this.humanoid); fingers.RetrieveBones(this); } diff --git a/Runtime/HumanoidControl/Scripts/Targets/HeadTarget.cs b/Runtime/HumanoidControl/Scripts/Targets/HeadTarget.cs index b260faf..c825a68 100644 --- a/Runtime/HumanoidControl/Scripts/Targets/HeadTarget.cs +++ b/Runtime/HumanoidControl/Scripts/Targets/HeadTarget.cs @@ -326,7 +326,7 @@ namespace Passer.Humanoid { public class TargetedHeadBone : TargetedBone { readonly private HeadTarget headTarget; - public TargetedHeadBone(HeadTarget headTarget) : base(headTarget.humanoid) { + public TargetedHeadBone(HeadTarget headTarget) : base() { this.headTarget = headTarget; this.parent = headTarget.neck; @@ -418,7 +418,7 @@ namespace Passer.Humanoid { public class TargetedNeckBone : TargetedBone { readonly private HeadTarget headTarget; - public TargetedNeckBone(HeadTarget headTarget) : base(headTarget.humanoid) { + public TargetedNeckBone(HeadTarget headTarget) : base() { this.headTarget = headTarget; if (headTarget.humanoid == null || headTarget.humanoid.hipsTarget == null) this.parent = null; @@ -600,8 +600,8 @@ namespace Passer.Humanoid { } public void RetrieveBones() { - neck.RetrieveBones(); - head.RetrieveBones(); + neck.RetrieveBones(this.humanoid); + head.RetrieveBones(this.humanoid); #if hFACE face.InitComponent(); face.RetrieveBones(this); diff --git a/Runtime/HumanoidControl/Scripts/Targets/HipsTarget.cs b/Runtime/HumanoidControl/Scripts/Targets/HipsTarget.cs index ae90bfb..b53edbd 100644 --- a/Runtime/HumanoidControl/Scripts/Targets/HipsTarget.cs +++ b/Runtime/HumanoidControl/Scripts/Targets/HipsTarget.cs @@ -176,7 +176,7 @@ namespace Passer.Humanoid { public class TargetedChestBone : TargetedBone { private HipsTarget hipsTarget; - public TargetedChestBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) { + public TargetedChestBone(HipsTarget hipsTarget) : base() { this.hipsTarget = hipsTarget; this.parent = hipsTarget.spine; boneId = Bone.Chest; @@ -231,7 +231,7 @@ namespace Passer.Humanoid { public class TargetedSpineBone : TargetedBone { private HipsTarget hipsTarget; - public TargetedSpineBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) { + public TargetedSpineBone(HipsTarget hipsTarget) : base() { this.hipsTarget = hipsTarget; this.parent = hipsTarget.hips; boneId = Bone.Spine; @@ -280,7 +280,7 @@ namespace Passer.Humanoid { public class TargetedHipsBone : TargetedBone { public HipsTarget hipsTarget; - public TargetedHipsBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) { + public TargetedHipsBone(HipsTarget hipsTarget) : base() { this.hipsTarget = hipsTarget; boneId = Bone.Hips; } @@ -457,9 +457,9 @@ namespace Passer.Humanoid { } public void RetrieveBones() { - hips.RetrieveBones(); - spine.RetrieveBones(); - chest.RetrieveBones(); + hips.RetrieveBones(this.humanoid); + spine.RetrieveBones(this.humanoid); + chest.RetrieveBones(this.humanoid); } public void RetrieveBonesWithoutAvatar(Transform rootBone) { @@ -563,7 +563,7 @@ namespace Passer.Humanoid { // We need the neck.bone to measure the chest length. This can be null when the avatar is changed if (humanoid.headTarget.neck.bone.transform == null) - humanoid.headTarget.neck.RetrieveBones(); + humanoid.headTarget.neck.RetrieveBones(this.humanoid); //HeadTarget.GetDefaultNeck(humanoid.avatarRig, ref humanoid.headTarget.neck.bone.transform); humanoid.headTarget.neck.SetTargetPositionToAvatar(); diff --git a/Runtime/HumanoidControl/Scripts/Targets/HumanoidTarget.cs b/Runtime/HumanoidControl/Scripts/Targets/HumanoidTarget.cs index 7c9be52..90c71b6 100644 --- a/Runtime/HumanoidControl/Scripts/Targets/HumanoidTarget.cs +++ b/Runtime/HumanoidControl/Scripts/Targets/HumanoidTarget.cs @@ -411,17 +411,11 @@ namespace Passer.Humanoid { [System.NonSerialized] public TargetedBone nextBone; - protected HumanoidControl humanoid; + //protected HumanoidControl humanoid = null; - public TargetedBone(HumanoidControl humanoid) { - if (humanoid == null) - throw new System.Exception("Humanoid may not be null"); - this.humanoid = humanoid; + public TargetedBone() { } - public TargetedBone(HumanoidControl humanoid, TargetedBone _nextBone) { - if (humanoid == null) - throw new System.Exception("Humanoid may not be null"); - this.humanoid = humanoid; + public TargetedBone(TargetedBone _nextBone) { this.nextBone = _nextBone; } @@ -438,19 +432,19 @@ namespace Passer.Humanoid { return obj.transform; } - public virtual void RetrieveBones() { - if (this.humanoid == null) + public virtual void RetrieveBones(HumanoidControl humanoid) { + if (humanoid == null) return; - if (this.humanoid.targetsRig != null) - GetDefaultTargetBone(this.humanoid.targetsRig, ref target.transform, boneId); - if (this.humanoid.avatarRig != null) - GetDefaultBone(this.humanoid.avatarRig, ref bone.transform, boneId); + if (humanoid.targetsRig != null) + GetDefaultTargetBone(humanoid.targetsRig, ref target.transform, boneId); + if (humanoid.avatarRig != null) + GetDefaultBone(humanoid.avatarRig, ref bone.transform, boneId); } - public void RetrieveBone(HumanBodyBones boneID) { - if ((bone.transform == null || bone.transform == null) && this.humanoid.avatarRig != null) { - bone.transform = this.humanoid.avatarRig.GetBoneTransform(boneID); + public void RetrieveBone(HumanoidControl humanoid, HumanBodyBones boneID) { + if ((bone.transform == null || bone.transform == null) && humanoid.avatarRig != null) { + bone.transform = humanoid.avatarRig.GetBoneTransform(boneID); } }