Tested with VR

This commit is contained in:
Pascal Serrarens 2024-11-19 17:32:51 +01:00
parent 28926a1507
commit de5bf3a10e

View File

@ -250,6 +250,25 @@ namespace Passer.Humanoid {
SendName(remoteHumanoid, 0, "Humanoid"); SendName(remoteHumanoid, 0, "Humanoid");
SendModel(remoteHumanoid, "https://gitlab.passervr.com/passer/models/humanoid/-/raw/main/MakeHumanPasserMedium.glb?ref_type=heads&inline=false"); 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.upperLeg);
SendSubThing(remoteHumanoid, remoteHumanoid.leftFootTarget.lowerLeg); SendSubThing(remoteHumanoid, remoteHumanoid.leftFootTarget.lowerLeg);
SendSubThing(remoteHumanoid, remoteHumanoid.leftFootTarget.foot); SendSubThing(remoteHumanoid, remoteHumanoid.leftFootTarget.foot);
@ -350,7 +369,11 @@ namespace Passer.Humanoid {
if (debug <= HumanoidNetworking.DebugLevel.Debug) if (debug <= HumanoidNetworking.DebugLevel.Debug)
Debug.Log("Send SubThing " + humanoid.humanoidId + " nwId: " + humanoid.nwId); 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) { if (udpClient != null) {
byte[] data = thingMsg.Serialize(); byte[] data = thingMsg.Serialize();
@ -480,9 +503,13 @@ namespace Passer.Humanoid {
readonly byte boneId; readonly byte boneId;
readonly Quat32 boneOrientation; readonly Quat32 boneOrientation;
public RoboidBonePose(HumanoidTarget.TargetedBone targetedBone) { public RoboidBonePose(HumanoidTarget.TargetedBone targetedBone, bool isRoot = false) {
this.boneId = (byte)targetedBone.boneId; 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() { public override byte[] Serialize() {
@ -502,45 +529,59 @@ namespace Passer.Humanoid {
} }
[Serializable] //[Serializable]
public class RoboidPose : HumanoidNetworking.HumanoidPose { //public class RoboidPose : HumanoidNetworking.HumanoidPose {
readonly Quat32 headOrientation; // readonly Quat32 headOrientation;
public RoboidPose(HumanoidControl humanoid) { // public RoboidPose(HumanoidControl humanoid) {
headOrientation = new Quat32(humanoid.headTarget.head.bone.transform.rotation); // headOrientation = new Quat32(humanoid.headTarget.head.bone.transform.rotation);
} // }
public override byte[] Serialize() { // public override byte[] Serialize() {
MemoryStream ms = new(); // MemoryStream ms = new();
BinaryWriter bw = new(ms); // BinaryWriter bw = new(ms);
bw.Write((byte)0x10); // PoseMsg // bw.Write((byte)0x10); // PoseMsg
bw.Write((byte)this.head.boneId); // Thing Id // bw.Write((byte)this.head.boneId); // Thing Id
bw.Write((byte)0x03); // Pose_Orientation // bw.Write((byte)0x03); // Pose_Orientation
bw.Write((byte)0x00); // Dummy data // bw.Write((byte)0x00); // Dummy data
bw.Write((byte)0x00); // bw.Write((byte)0x00);
bw.Write((byte)0x00); // bw.Write((byte)0x00);
bw.Write((byte)0x00); // bw.Write((byte)0x00);
SendQuat32(bw, headOrientation); // SendQuat32(bw, headOrientation);
byte[] data = ms.ToArray(); // byte[] data = ms.ToArray();
return data; // return data;
} // }
} //}
public virtual void UpdateHumanoidPose(HumanoidControl humanoid) { public virtual void UpdateHumanoidPose(HumanoidControl humanoid) {
if (debug <= HumanoidNetworking.DebugLevel.Debug) if (debug <= HumanoidNetworking.DebugLevel.Debug)
Debug.Log("Send Pose Humanoid " + humanoid.humanoidId + " nwId: " + humanoid.nwId); Debug.Log("Send Pose Humanoid " + humanoid.humanoidId + " nwId: " + humanoid.nwId);
RoboidPose humanoidPose = new(humanoid); //RoboidPose humanoidPose = new(humanoid);
if (createLocalRemotes) //if (createLocalRemotes)
this.Receive(humanoidPose); // 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.upperLeg);
SendBone(humanoid.leftFootTarget.lowerLeg); SendBone(humanoid.leftFootTarget.lowerLeg);
SendBone(humanoid.leftFootTarget.foot); SendBone(humanoid.leftFootTarget.foot);
@ -550,8 +591,8 @@ namespace Passer.Humanoid {
SendBone(humanoid.rightFootTarget.foot); SendBone(humanoid.rightFootTarget.foot);
} }
private void SendBone(HumanoidTarget.TargetedBone bone) { private void SendBone(HumanoidTarget.TargetedBone bone, bool isRoot = false) {
RoboidBonePose bonePose = new(bone); RoboidBonePose bonePose = new(bone, isRoot);
byte[] buffer = bonePose.Serialize(); byte[] buffer = bonePose.Serialize();
udpClient.Send(buffer, buffer.Length, "127.0.0.1", nssPort); udpClient.Send(buffer, buffer.Length, "127.0.0.1", nssPort);
} }