Compatiblity with RoboidControl

This commit is contained in:
Pascal Serrarens 2025-05-28 12:19:59 +02:00
parent 5c34066d8e
commit 5432a9660d
9 changed files with 68 additions and 72 deletions

View File

@ -51,5 +51,5 @@ MonoBehaviour:
_sendRate: 2 _sendRate: 2
_createLocalRemotes: 0 _createLocalRemotes: 0
sitePort: 7681 sitePort: 7681
localPort: 7682
siteAddress: 127.0.0.1 siteAddress: 127.0.0.1
networkId: 0

View File

@ -7,7 +7,7 @@ namespace RoboidControl
{ {
protected HumanoidTarget.TargetedBone bone; protected HumanoidTarget.TargetedBone bone;
public BoneThing(HumanoidTarget.TargetedBone bone) public BoneThing(Participant owner, HumanoidTarget.TargetedBone bone) : base(owner)
{ {
this.bone = bone; this.bone = bone;
} }

View File

@ -35,7 +35,8 @@ namespace Passer.Humanoid
set { _createLocalRemotes = value; } set { _createLocalRemotes = value; }
} }
public int sitePort = 7681; public int sitePort = 7682;
public int localPort = 7681;
public string siteAddress = "127.0.0.1"; public string siteAddress = "127.0.0.1";
// protected UdpClient udpClient; // protected UdpClient udpClient;
// protected IPEndPoint endPoint; // protected IPEndPoint endPoint;
@ -158,7 +159,7 @@ namespace Passer.Humanoid
{ {
readonly HumanoidPlayer player; 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; this.player = player;
} }
@ -238,7 +239,7 @@ namespace Passer.Humanoid
mInstance = this; mInstance = this;
Console.SetOut(new UnityLogWriter()); 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); // endPoint = new IPEndPoint(IPAddress.Any, sitePort + 3);
// udpClient = new UdpClient(endPoint); // udpClient = new UdpClient(endPoint);
@ -264,7 +265,7 @@ namespace Passer.Humanoid
} }
humanoid = humanoids[0]; 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)); // this.participant.Send(new ThingMsg((byte)humanoid.nwId, headThing));
// //
//endpoint = new IPEndPoint(IPAddress.Any, sitePort); //endpoint = new IPEndPoint(IPAddress.Any, sitePort);
@ -337,6 +338,7 @@ namespace Passer.Humanoid
protected virtual void LateUpdate() protected virtual void LateUpdate()
{ {
participant.Update((ulong)(Time.time * 1000));
// foreach (Client client in Client.clients) { // foreach (Client client in Client.clients) {
// if (client is HumanoidParticipant humanoidClient) { // if (client is HumanoidParticipant humanoidClient) {
// while (humanoidClient.messageQueue.TryDequeue(out Passer.Control.IMessage msg)) // while (humanoidClient.messageQueue.TryDequeue(out Passer.Control.IMessage msg))
@ -344,26 +346,26 @@ namespace Passer.Humanoid
// } // }
// } // }
if (Time.time > lastSend + 1 / sendRate) // if (Time.time > lastSend + 1 / sendRate)
{ // {
if (humanoids != null) // if (humanoids != null)
{ // {
foreach (HumanoidControl humanoid in humanoids) // foreach (HumanoidControl humanoid in humanoids)
{ // {
if (!humanoid.isRemote) // if (!humanoid.isRemote)
{ // {
UpdateHumanoidPose(humanoid); // UpdateHumanoidPose(humanoid);
} // }
} // }
} // }
lastSend = Time.time; // lastSend = Time.time;
} // }
if (Time.time > lastClientMsg + clientMsgInterval) // if (Time.time > lastClientMsg + clientMsgInterval)
{ // {
//SendClientMsg(humanoids[0]); // We just need it for the networkId // //SendClientMsg(humanoids[0]); // We just need it for the networkId
this.participant.Send(new ParticipantMsg((byte)humanoid.nwId)); // this.participant.Send(new ParticipantMsg((byte)humanoid.nwId));
lastClientMsg = Time.time; // lastClientMsg = Time.time;
} // }
} }
#endregion Update #endregion Update

View File

@ -75,9 +75,9 @@ namespace Passer.Humanoid {
distal.boneId = firstBoneId + 2; distal.boneId = firstBoneId + 2;
//metaCarpal.RetrieveBones(humanoid); //metaCarpal.RetrieveBones(humanoid);
proximal.RetrieveBones(); proximal.RetrieveBones(humanoid);
intermediate.RetrieveBones(); intermediate.RetrieveBones(humanoid);
distal.RetrieveBones(); distal.RetrieveBones(humanoid);
} }
public void MatchTargetToAvatar() { public void MatchTargetToAvatar() {
@ -346,7 +346,7 @@ namespace Passer.Humanoid {
//private Quaternion localDefaultRotation; //private Quaternion localDefaultRotation;
public TargetedPhalanges(TargetedFinger finger, HumanoidTarget.TargetedBone nextBone) public TargetedPhalanges(TargetedFinger finger, HumanoidTarget.TargetedBone nextBone)
: base(finger.fingers.handTarget.humanoid, nextBone) { : base(nextBone) {
this.finger = finger; this.finger = finger;
} }

View File

@ -216,7 +216,7 @@ namespace Passer.Humanoid {
public class TargetedUpperLegBone : TargetedBone { public class TargetedUpperLegBone : TargetedBone {
private FootTarget footTarget; private FootTarget footTarget;
public TargetedUpperLegBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.lowerLeg) { public TargetedUpperLegBone(FootTarget footTarget) : base(footTarget.lowerLeg) {
this.footTarget = footTarget; this.footTarget = footTarget;
this.parent = footTarget.humanoid.hipsTarget.hips; this.parent = footTarget.humanoid.hipsTarget.hips;
} }
@ -261,7 +261,7 @@ namespace Passer.Humanoid {
public class TargetedLowerLegBone : TargetedBone { public class TargetedLowerLegBone : TargetedBone {
private FootTarget footTarget; private FootTarget footTarget;
public TargetedLowerLegBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.foot) { public TargetedLowerLegBone(FootTarget footTarget) : base(footTarget.foot) {
this.footTarget = footTarget; this.footTarget = footTarget;
this.parent = footTarget.upperLeg; this.parent = footTarget.upperLeg;
} }
@ -306,7 +306,7 @@ namespace Passer.Humanoid {
public class TargetedFootBone : TargetedBone { public class TargetedFootBone : TargetedBone {
private FootTarget footTarget; private FootTarget footTarget;
public TargetedFootBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.toes) { public TargetedFootBone(FootTarget footTarget) : base(footTarget.toes) {
this.footTarget = footTarget; this.footTarget = footTarget;
this.parent = footTarget.lowerLeg; this.parent = footTarget.lowerLeg;
} }
@ -378,7 +378,7 @@ namespace Passer.Humanoid {
public class TargetedToesBone : TargetedBone { public class TargetedToesBone : TargetedBone {
private FootTarget footTarget; private FootTarget footTarget;
public TargetedToesBone(FootTarget footTarget) : base(footTarget.humanoid) { public TargetedToesBone(FootTarget footTarget) : base() {
this.footTarget = footTarget; this.footTarget = footTarget;
this.parent = footTarget.foot; this.parent = footTarget.foot;
} }
@ -555,10 +555,10 @@ namespace Passer.Humanoid {
} }
public void RetrieveBones() { public void RetrieveBones() {
upperLeg.RetrieveBones(); upperLeg.RetrieveBones(this.humanoid);
lowerLeg.RetrieveBones(); lowerLeg.RetrieveBones(this.humanoid);
foot.RetrieveBones(); foot.RetrieveBones(this.humanoid);
toes.RetrieveBones(); toes.RetrieveBones(this.humanoid);
} }
#endregion #endregion

View File

@ -387,7 +387,7 @@ namespace Passer.Humanoid {
public class TargetedShoulderBone : TargetedBone { public class TargetedShoulderBone : TargetedBone {
private HandTarget handTarget; private HandTarget handTarget;
public TargetedShoulderBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.upperArm) { public TargetedShoulderBone(HandTarget handTarget) : base(handTarget.upperArm) {
this.handTarget = handTarget; this.handTarget = handTarget;
if (handTarget.humanoid == null || handTarget.humanoid.hipsTarget == null) if (handTarget.humanoid == null || handTarget.humanoid.hipsTarget == null)
this.parent = null; this.parent = null;
@ -463,7 +463,7 @@ namespace Passer.Humanoid {
public class TargetedUpperArmBone : TargetedBone { public class TargetedUpperArmBone : TargetedBone {
private HandTarget handTarget; private HandTarget handTarget;
public TargetedUpperArmBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.forearm) { public TargetedUpperArmBone(HandTarget handTarget) : base(handTarget.forearm) {
this.handTarget = handTarget; this.handTarget = handTarget;
this.parent = handTarget.shoulder; this.parent = handTarget.shoulder;
} }
@ -520,7 +520,7 @@ namespace Passer.Humanoid {
public class TargetedForearmBone : TargetedBone { public class TargetedForearmBone : TargetedBone {
private HandTarget handTarget; private HandTarget handTarget;
public TargetedForearmBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.hand) { public TargetedForearmBone(HandTarget handTarget) : base(handTarget.hand) {
this.handTarget = handTarget; this.handTarget = handTarget;
this.parent = handTarget.upperArm; this.parent = handTarget.upperArm;
} }
@ -583,7 +583,7 @@ namespace Passer.Humanoid {
public class TargetedHandBone : TargetedBone { public class TargetedHandBone : TargetedBone {
private HandTarget handTarget; private HandTarget handTarget;
public TargetedHandBone(HandTarget handTarget) : base(handTarget.humanoid) { public TargetedHandBone(HandTarget handTarget) : base() {
this.handTarget = handTarget; this.handTarget = handTarget;
this.parent = handTarget.forearm; this.parent = handTarget.forearm;
} }
@ -824,7 +824,7 @@ namespace Passer.Humanoid {
public void RetrieveBones() { public void RetrieveBones() {
foreach (TargetedBone subTarget in subTargets) foreach (TargetedBone subTarget in subTargets)
subTarget.RetrieveBones(); subTarget.RetrieveBones(this.humanoid);
fingers.RetrieveBones(this); fingers.RetrieveBones(this);
} }

View File

@ -326,7 +326,7 @@ namespace Passer.Humanoid {
public class TargetedHeadBone : TargetedBone { public class TargetedHeadBone : TargetedBone {
readonly private HeadTarget headTarget; readonly private HeadTarget headTarget;
public TargetedHeadBone(HeadTarget headTarget) : base(headTarget.humanoid) { public TargetedHeadBone(HeadTarget headTarget) : base() {
this.headTarget = headTarget; this.headTarget = headTarget;
this.parent = headTarget.neck; this.parent = headTarget.neck;
@ -418,7 +418,7 @@ namespace Passer.Humanoid {
public class TargetedNeckBone : TargetedBone { public class TargetedNeckBone : TargetedBone {
readonly private HeadTarget headTarget; readonly private HeadTarget headTarget;
public TargetedNeckBone(HeadTarget headTarget) : base(headTarget.humanoid) { public TargetedNeckBone(HeadTarget headTarget) : base() {
this.headTarget = headTarget; this.headTarget = headTarget;
if (headTarget.humanoid == null || headTarget.humanoid.hipsTarget == null) if (headTarget.humanoid == null || headTarget.humanoid.hipsTarget == null)
this.parent = null; this.parent = null;
@ -600,8 +600,8 @@ namespace Passer.Humanoid {
} }
public void RetrieveBones() { public void RetrieveBones() {
neck.RetrieveBones(); neck.RetrieveBones(this.humanoid);
head.RetrieveBones(); head.RetrieveBones(this.humanoid);
#if hFACE #if hFACE
face.InitComponent(); face.InitComponent();
face.RetrieveBones(this); face.RetrieveBones(this);

View File

@ -176,7 +176,7 @@ namespace Passer.Humanoid {
public class TargetedChestBone : TargetedBone { public class TargetedChestBone : TargetedBone {
private HipsTarget hipsTarget; private HipsTarget hipsTarget;
public TargetedChestBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) { public TargetedChestBone(HipsTarget hipsTarget) : base() {
this.hipsTarget = hipsTarget; this.hipsTarget = hipsTarget;
this.parent = hipsTarget.spine; this.parent = hipsTarget.spine;
boneId = Bone.Chest; boneId = Bone.Chest;
@ -231,7 +231,7 @@ namespace Passer.Humanoid {
public class TargetedSpineBone : TargetedBone { public class TargetedSpineBone : TargetedBone {
private HipsTarget hipsTarget; private HipsTarget hipsTarget;
public TargetedSpineBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) { public TargetedSpineBone(HipsTarget hipsTarget) : base() {
this.hipsTarget = hipsTarget; this.hipsTarget = hipsTarget;
this.parent = hipsTarget.hips; this.parent = hipsTarget.hips;
boneId = Bone.Spine; boneId = Bone.Spine;
@ -280,7 +280,7 @@ namespace Passer.Humanoid {
public class TargetedHipsBone : TargetedBone { public class TargetedHipsBone : TargetedBone {
public HipsTarget hipsTarget; public HipsTarget hipsTarget;
public TargetedHipsBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) { public TargetedHipsBone(HipsTarget hipsTarget) : base() {
this.hipsTarget = hipsTarget; this.hipsTarget = hipsTarget;
boneId = Bone.Hips; boneId = Bone.Hips;
} }
@ -457,9 +457,9 @@ namespace Passer.Humanoid {
} }
public void RetrieveBones() { public void RetrieveBones() {
hips.RetrieveBones(); hips.RetrieveBones(this.humanoid);
spine.RetrieveBones(); spine.RetrieveBones(this.humanoid);
chest.RetrieveBones(); chest.RetrieveBones(this.humanoid);
} }
public void RetrieveBonesWithoutAvatar(Transform rootBone) { 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 // 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) 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); //HeadTarget.GetDefaultNeck(humanoid.avatarRig, ref humanoid.headTarget.neck.bone.transform);
humanoid.headTarget.neck.SetTargetPositionToAvatar(); humanoid.headTarget.neck.SetTargetPositionToAvatar();

View File

@ -411,17 +411,11 @@ namespace Passer.Humanoid {
[System.NonSerialized] [System.NonSerialized]
public TargetedBone nextBone; public TargetedBone nextBone;
protected HumanoidControl humanoid; //protected HumanoidControl humanoid = null;
public TargetedBone(HumanoidControl humanoid) { public TargetedBone() {
if (humanoid == null)
throw new System.Exception("Humanoid may not be null");
this.humanoid = humanoid;
} }
public TargetedBone(HumanoidControl humanoid, TargetedBone _nextBone) { public TargetedBone(TargetedBone _nextBone) {
if (humanoid == null)
throw new System.Exception("Humanoid may not be null");
this.humanoid = humanoid;
this.nextBone = _nextBone; this.nextBone = _nextBone;
} }
@ -438,19 +432,19 @@ namespace Passer.Humanoid {
return obj.transform; return obj.transform;
} }
public virtual void RetrieveBones() { public virtual void RetrieveBones(HumanoidControl humanoid) {
if (this.humanoid == null) if (humanoid == null)
return; return;
if (this.humanoid.targetsRig != null) if (humanoid.targetsRig != null)
GetDefaultTargetBone(this.humanoid.targetsRig, ref target.transform, boneId); GetDefaultTargetBone(humanoid.targetsRig, ref target.transform, boneId);
if (this.humanoid.avatarRig != null) if (humanoid.avatarRig != null)
GetDefaultBone(this.humanoid.avatarRig, ref bone.transform, boneId); GetDefaultBone(humanoid.avatarRig, ref bone.transform, boneId);
} }
public void RetrieveBone(HumanBodyBones boneID) { public void RetrieveBone(HumanoidControl humanoid, HumanBodyBones boneID) {
if ((bone.transform == null || bone.transform == null) && this.humanoid.avatarRig != null) { if ((bone.transform == null || bone.transform == null) && humanoid.avatarRig != null) {
bone.transform = this.humanoid.avatarRig.GetBoneTransform(boneID); bone.transform = humanoid.avatarRig.GetBoneTransform(boneID);
} }
} }