Used Client override for processing messages
This commit is contained in:
parent
f4d002bb8a
commit
ae568e5489
@ -24,12 +24,13 @@ Transform:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1810220956971058}
|
m_GameObject: {fileID: 1810220956971058}
|
||||||
|
serializedVersion: 2
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!114 &114636771493283014
|
--- !u!114 &114636771493283014
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@ -43,4 +44,12 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: eb69cd2012a95b549a6c414c3619432c, type: 3}
|
m_Script: {fileID: 11500000, guid: eb69cd2012a95b549a6c414c3619432c, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_debug: 3
|
_syncFingerSwing: 0
|
||||||
|
_syncFace: 0
|
||||||
|
_syncTracking: 0
|
||||||
|
_debug: 1
|
||||||
|
_sendRate: 25
|
||||||
|
_createLocalRemotes: 0
|
||||||
|
sitePort: 7681
|
||||||
|
siteAddress: 127.0.0.1
|
||||||
|
networkId: 0
|
||||||
|
@ -826,7 +826,7 @@ namespace Passer.Humanoid {
|
|||||||
Rigidbody objRigidbody = RigidbodyDisabled.UnparentRigidbody(handPalm, grabbedObject.transform);
|
Rigidbody objRigidbody = RigidbodyDisabled.UnparentRigidbody(handPalm, grabbedObject.transform);
|
||||||
if (objRigidbody != null && !objRigidbody.isKinematic) {
|
if (objRigidbody != null && !objRigidbody.isKinematic) {
|
||||||
if (handRigidbody != null) {
|
if (handRigidbody != null) {
|
||||||
objRigidbody.velocity = handRigidbody.velocity;
|
objRigidbody.linearVelocity = handRigidbody.linearVelocity;
|
||||||
objRigidbody.angularVelocity = handRigidbody.angularVelocity;
|
objRigidbody.angularVelocity = handRigidbody.angularVelocity;
|
||||||
}
|
}
|
||||||
HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject);
|
HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject);
|
||||||
@ -854,7 +854,7 @@ namespace Passer.Humanoid {
|
|||||||
//grabbedRigidbody.centerOfMass = handTarget.storedCOM;
|
//grabbedRigidbody.centerOfMass = handTarget.storedCOM;
|
||||||
|
|
||||||
if (grabbedRigidbody.isKinematic == false) {
|
if (grabbedRigidbody.isKinematic == false) {
|
||||||
grabbedRigidbody.velocity = handRigidbody.velocity;
|
grabbedRigidbody.linearVelocity = handRigidbody.linearVelocity;
|
||||||
grabbedRigidbody.angularVelocity = handRigidbody.angularVelocity;
|
grabbedRigidbody.angularVelocity = handRigidbody.angularVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ namespace Passer.Humanoid {
|
|||||||
handTarget.handRigidbody = handTarget.hand.bone.transform.gameObject.AddComponent<Rigidbody>();
|
handTarget.handRigidbody = handTarget.hand.bone.transform.gameObject.AddComponent<Rigidbody>();
|
||||||
}
|
}
|
||||||
handTarget.handRigidbody.mass = 1;
|
handTarget.handRigidbody.mass = 1;
|
||||||
handTarget.handRigidbody.drag = 0;
|
handTarget.handRigidbody.linearDamping = 0;
|
||||||
handTarget.handRigidbody.angularDrag = 10;
|
handTarget.handRigidbody.angularDamping = 10;
|
||||||
handTarget.handRigidbody.useGravity = false;
|
handTarget.handRigidbody.useGravity = false;
|
||||||
handTarget.handRigidbody.isKinematic = true;
|
handTarget.handRigidbody.isKinematic = true;
|
||||||
handTarget.handRigidbody.interpolation = RigidbodyInterpolation.None;
|
handTarget.handRigidbody.interpolation = RigidbodyInterpolation.None;
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
|
namespace Passer.Control {
|
||||||
|
|
||||||
|
public class Client {
|
||||||
|
//public ConnectionMethod connection;
|
||||||
|
public UdpClient udpClient;
|
||||||
|
public string ipAddress;
|
||||||
|
public int port;
|
||||||
|
|
||||||
|
public byte networkId;
|
||||||
|
|
||||||
|
public readonly ConcurrentQueue<IMessage> messageQueue = new();
|
||||||
|
|
||||||
|
public static Client GetClient(string ipAddress, int port) {
|
||||||
|
foreach (Client c in clients) {
|
||||||
|
if (c.ipAddress == ipAddress && c.port == port)
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
static public List<Client> clients = new List<Client>();
|
||||||
|
|
||||||
|
public static Client NewClient() {
|
||||||
|
Client client = new();
|
||||||
|
clients.Add(client);
|
||||||
|
client.networkId = 0;
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Client NewUDPClient(UdpClient udpClient, string ipAddress, int port) {
|
||||||
|
Client client = NewClient();
|
||||||
|
client.ipAddress = null;
|
||||||
|
client.port = port;
|
||||||
|
client.udpClient = udpClient;
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ProcessMessage(IMessage msg) {
|
||||||
|
switch (msg) {
|
||||||
|
case ClientMsg clientMsg:
|
||||||
|
ProcessClient(clientMsg);
|
||||||
|
break;
|
||||||
|
case NetworkIdMsg networkId:
|
||||||
|
ProcessNetworkId(networkId);
|
||||||
|
break;
|
||||||
|
case InvestigateMsg investigate:
|
||||||
|
ProcessInvestigate(investigate);
|
||||||
|
break;
|
||||||
|
case ThingMsg thing:
|
||||||
|
ProcessThing(thing);
|
||||||
|
break;
|
||||||
|
case NameMsg name:
|
||||||
|
ProcessName(name);
|
||||||
|
break;
|
||||||
|
case ModelUrlMsg modelUrl:
|
||||||
|
ProcessModelUrl(modelUrl);
|
||||||
|
break;
|
||||||
|
case PoseMsg pose:
|
||||||
|
ProcessPose(pose);
|
||||||
|
break;
|
||||||
|
case CustomMsg custom:
|
||||||
|
ProcessCustom(custom);
|
||||||
|
break;
|
||||||
|
case TextMsg text:
|
||||||
|
ProcessText(text);
|
||||||
|
break;
|
||||||
|
case DestroyMsg destroy:
|
||||||
|
ProcessDestroy(destroy);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void ProcessClient(ClientMsg client) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessNetworkId(NetworkIdMsg networkId) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessInvestigate(InvestigateMsg investigate) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessThing(ThingMsg thing) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessName(NameMsg name) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessModelUrl(ModelUrlMsg modelUrl) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessPose(PoseMsg pose) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessCustom(CustomMsg custom) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessText(TextMsg text) { }
|
||||||
|
|
||||||
|
protected virtual void ProcessDestroy(DestroyMsg destroy) { }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: db9cd79cff119a9438110ead000031c3
|
@ -1,212 +1,172 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Passer.Control {
|
namespace Passer.Control {
|
||||||
|
|
||||||
public class Client {
|
public class IMessage {
|
||||||
//public ConnectionMethod connection;
|
public IMessage() { }
|
||||||
public UdpClient udpClient;
|
public IMessage(byte[] data) {
|
||||||
public string ipAddress;
|
Deserialize(data);
|
||||||
public int port;
|
}
|
||||||
|
|
||||||
public byte networkId;
|
public virtual byte[] Serialize() { return null; }
|
||||||
|
public virtual void Deserialize(byte[] data) { }
|
||||||
|
|
||||||
public readonly ConcurrentQueue<IMessage> messageQueue = new();
|
public static bool SendMsg(Client client, IMessage msg) {
|
||||||
|
return SendMsg(client, msg.Serialize());
|
||||||
|
}
|
||||||
|
public static bool SendMsg(Client client, byte[] data) {
|
||||||
|
if (client == null || client.ipAddress == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
public static Client GetClient(string ipAddress, int port) {
|
client.udpClient.Send(data, data.Length, client.ipAddress, client.port);
|
||||||
foreach (Client c in clients) {
|
return true;
|
||||||
if (c.ipAddress == ipAddress && c.port == port)
|
}
|
||||||
return c;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
static public List<Client> clients = new List<Client>();
|
|
||||||
|
|
||||||
public static Client NewClient() {
|
|
||||||
Client client = new();
|
|
||||||
clients.Add(client);
|
|
||||||
client.networkId = 0;
|
|
||||||
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Client NewUDPClient(UdpClient udpClient, string ipAddress, int port) {
|
|
||||||
Client client = NewClient();
|
|
||||||
client.ipAddress = null;
|
|
||||||
client.port = port;
|
|
||||||
client.udpClient = udpClient;
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IMessage {
|
|
||||||
public IMessage() { }
|
|
||||||
public IMessage(byte[] data) {
|
|
||||||
Deserialize(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual byte[] Serialize() { return null; }
|
|
||||||
public virtual void Deserialize(byte[] data) { }
|
|
||||||
|
|
||||||
public static bool SendMsg(Client client, IMessage msg) {
|
|
||||||
return SendMsg(client, msg.Serialize());
|
|
||||||
}
|
|
||||||
public static bool SendMsg(Client client, byte[] data) {
|
|
||||||
if (client == null || client.ipAddress == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
client.udpClient.Send(data, data.Length, client.ipAddress, client.port);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool PublishMsg(Client client, IMessage msg) {
|
public static bool PublishMsg(Client client, IMessage msg) {
|
||||||
return PublishMsg(client, msg.Serialize());
|
return PublishMsg(client, msg.Serialize());
|
||||||
}
|
}
|
||||||
public static bool PublishMsg(Client client, byte[] data) {
|
public static bool PublishMsg(Client client, byte[] data) {
|
||||||
if (client == null)
|
if (client == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
client.udpClient.Send(data, data.Length, "127.0.0.1", client.port);
|
client.udpClient.Send(data, data.Length, "127.0.0.1", client.port);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<byte[]> Receive(Stream dataStream, byte packetSize) {
|
public static async Task<byte[]> Receive(Stream dataStream, byte packetSize) {
|
||||||
byte[] buffer = new byte[packetSize - 1]; // without msgId
|
byte[] buffer = new byte[packetSize - 1]; // without msgId
|
||||||
int byteCount = dataStream.Read(buffer, 0, packetSize - 1);
|
int byteCount = dataStream.Read(buffer, 0, packetSize - 1);
|
||||||
while (byteCount < packetSize - 1) {
|
while (byteCount < packetSize - 1) {
|
||||||
// not all bytes have been read, wait and try again
|
// not all bytes have been read, wait and try again
|
||||||
await Task.Delay(1);
|
await Task.Delay(1);
|
||||||
byteCount += dataStream.Read(buffer, byteCount, packetSize - 1 - byteCount);
|
byteCount += dataStream.Read(buffer, byteCount, packetSize - 1 - byteCount);
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Client
|
|
||||||
|
|
||||||
public class ClientMsg : IMessage {
|
|
||||||
public const byte Id = 0xA0;
|
|
||||||
public const byte length = 2;
|
|
||||||
public byte networkId;
|
|
||||||
|
|
||||||
public ClientMsg(byte networkId) {
|
|
||||||
this.networkId = networkId;
|
|
||||||
}
|
|
||||||
public ClientMsg(byte[] data) : base(data) { }
|
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
|
||||||
byte[] buffer = new byte[ClientMsg.length];
|
|
||||||
buffer[0] = ClientMsg.Id;
|
|
||||||
buffer[1] = networkId;
|
|
||||||
return buffer;
|
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
}
|
||||||
base.Deserialize(data);
|
|
||||||
uint ix = 0;
|
|
||||||
networkId = data[ix];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Send(Client client, byte networkId) {
|
#region Client
|
||||||
ClientMsg msg = new(networkId);
|
|
||||||
return SendMsg(client, msg);
|
|
||||||
}
|
|
||||||
public static bool Publish(Client client, byte networkId) {
|
|
||||||
ClientMsg msg = new(networkId);
|
|
||||||
return PublishMsg(client, msg);
|
|
||||||
}
|
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
|
||||||
if (packetSize != length)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
public class ClientMsg : IMessage {
|
||||||
ClientMsg msg = new(buffer);
|
public const byte Id = 0xA0;
|
||||||
|
public const byte length = 2;
|
||||||
|
public byte networkId;
|
||||||
|
|
||||||
if (client.networkId == 0) {
|
public ClientMsg(byte networkId) {
|
||||||
client.networkId = (byte)(Client.clients.Count);
|
|
||||||
NetworkIdMsg.Send(client, client.networkId);
|
|
||||||
//if (string.IsNullOrEmpty(sceneUrl) == false)
|
|
||||||
//SendModelUrl(client, sceneUrl);
|
|
||||||
}
|
|
||||||
else if (msg.networkId == 0) {
|
|
||||||
NetworkIdMsg.Send(client, client.networkId);
|
|
||||||
//if (string.IsNullOrEmpty(sceneUrl) == false)
|
|
||||||
//SendModelUrl(client, sceneUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Client
|
|
||||||
|
|
||||||
#region Network Id
|
|
||||||
|
|
||||||
public class NetworkIdMsg : IMessage {
|
|
||||||
public const byte Id = 0xA1;
|
|
||||||
public const byte length = 2;
|
|
||||||
public byte networkId;
|
|
||||||
|
|
||||||
NetworkIdMsg(byte networkId) {
|
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
}
|
}
|
||||||
NetworkIdMsg(byte[] data) : base(data) { }
|
public ClientMsg(byte[] data) : base(data) { }
|
||||||
|
|
||||||
|
public override byte[] Serialize() {
|
||||||
|
byte[] buffer = new byte[ClientMsg.length];
|
||||||
|
buffer[0] = ClientMsg.Id;
|
||||||
|
buffer[1] = networkId;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
public override void Deserialize(byte[] data) {
|
||||||
|
base.Deserialize(data);
|
||||||
|
uint ix = 0;
|
||||||
|
networkId = data[ix];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Send(Client client, byte networkId) {
|
||||||
|
ClientMsg msg = new(networkId);
|
||||||
|
return SendMsg(client, msg);
|
||||||
|
}
|
||||||
|
public static bool Publish(Client client, byte networkId) {
|
||||||
|
ClientMsg msg = new(networkId);
|
||||||
|
return PublishMsg(client, msg);
|
||||||
|
}
|
||||||
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
|
if (packetSize != length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
|
ClientMsg msg = new(buffer);
|
||||||
|
|
||||||
|
if (client.networkId == 0) {
|
||||||
|
client.networkId = (byte)(Client.clients.Count);
|
||||||
|
NetworkIdMsg.Send(client, client.networkId);
|
||||||
|
//if (string.IsNullOrEmpty(sceneUrl) == false)
|
||||||
|
//SendModelUrl(client, sceneUrl);
|
||||||
|
}
|
||||||
|
else if (msg.networkId == 0) {
|
||||||
|
NetworkIdMsg.Send(client, client.networkId);
|
||||||
|
//if (string.IsNullOrEmpty(sceneUrl) == false)
|
||||||
|
//SendModelUrl(client, sceneUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Client
|
||||||
|
|
||||||
|
#region Network Id
|
||||||
|
|
||||||
|
public class NetworkIdMsg : IMessage {
|
||||||
|
public const byte Id = 0xA1;
|
||||||
|
public const byte length = 2;
|
||||||
|
public byte networkId;
|
||||||
|
|
||||||
|
NetworkIdMsg(byte networkId) {
|
||||||
|
this.networkId = networkId;
|
||||||
|
}
|
||||||
|
NetworkIdMsg(byte[] data) : base(data) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] data = new byte[NetworkIdMsg.length];
|
byte[] data = new byte[NetworkIdMsg.length];
|
||||||
data[0] = NetworkIdMsg.Id;
|
data[0] = NetworkIdMsg.Id;
|
||||||
data[1] = this.networkId;
|
data[1] = this.networkId;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] data) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.networkId = data[ix];
|
this.networkId = data[ix];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte networkId) {
|
public static bool Send(Client client, byte networkId) {
|
||||||
NetworkIdMsg msg = new(networkId);
|
NetworkIdMsg msg = new(networkId);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
//byte[] data = new byte[NetworkIdMsg.length];
|
//byte[] data = new byte[NetworkIdMsg.length];
|
||||||
//data[0] = NetworkIdMsg.Id;
|
//data[0] = NetworkIdMsg.Id;
|
||||||
//data[1] = client.networkId;
|
//data[1] = client.networkId;
|
||||||
//return SendMsg(client, data);
|
//return SendMsg(client, data);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
if (packetSize != length)
|
if (packetSize != length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
NetworkIdMsg msg = new(buffer);
|
NetworkIdMsg msg = new(buffer);
|
||||||
client.messageQueue.Enqueue(msg);
|
client.messageQueue.Enqueue(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Network Id
|
#endregion Network Id
|
||||||
|
|
||||||
#region Investigate
|
#region Investigate
|
||||||
|
|
||||||
class InvestigateMsg : IMessage {
|
public class InvestigateMsg : IMessage {
|
||||||
public const byte Id = 0x81;
|
public const byte Id = 0x81;
|
||||||
public const byte length = 3;
|
public const byte length = 3;
|
||||||
public byte networkId;
|
public byte networkId;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
|
|
||||||
public InvestigateMsg(byte networkId, byte thingId) {
|
public InvestigateMsg(byte networkId, byte thingId) {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
}
|
}
|
||||||
public InvestigateMsg(byte[] data) : base(data) { }
|
public InvestigateMsg(byte[] data) : base(data) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[InvestigateMsg.length];
|
byte[] buffer = new byte[InvestigateMsg.length];
|
||||||
buffer[0] = InvestigateMsg.Id;
|
buffer[0] = InvestigateMsg.Id;
|
||||||
buffer[1] = this.networkId;
|
buffer[1] = this.networkId;
|
||||||
buffer[2] = this.thingId;
|
buffer[2] = this.thingId;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] data) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
@ -214,11 +174,11 @@ namespace Passer.Control {
|
|||||||
this.thingId = data[ix++];
|
this.thingId = data[ix++];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId) {
|
public static bool Send(Client client, byte thingId) {
|
||||||
InvestigateMsg msg = new(client.networkId, thingId);
|
InvestigateMsg msg = new(client.networkId, thingId);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
if (packetSize != length)
|
if (packetSize != length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -235,20 +195,20 @@ namespace Passer.Control {
|
|||||||
#region Thing
|
#region Thing
|
||||||
|
|
||||||
public class ThingMsg : IMessage {
|
public class ThingMsg : IMessage {
|
||||||
public const byte length = 5;
|
public const byte length = 5;
|
||||||
public const byte Id = 0x80;
|
public const byte Id = 0x80;
|
||||||
public byte networkId;
|
public byte networkId;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public byte thingType;
|
public byte thingType;
|
||||||
public byte parentId;
|
public byte parentId;
|
||||||
|
|
||||||
public ThingMsg(byte networkId, byte thingId, byte thingType, byte parentId) {
|
public ThingMsg(byte networkId, byte thingId, byte thingType, byte parentId) {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
this.thingType = thingType;
|
this.thingType = thingType;
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
}
|
}
|
||||||
public ThingMsg(byte[] data) : base(data) { }
|
public ThingMsg(byte[] data) : base(data) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] data = new byte[ThingMsg.length];
|
byte[] data = new byte[ThingMsg.length];
|
||||||
@ -257,281 +217,303 @@ namespace Passer.Control {
|
|||||||
data[2] = this.thingId;
|
data[2] = this.thingId;
|
||||||
data[3] = this.thingType;
|
data[3] = this.thingType;
|
||||||
data[4] = this.parentId;
|
data[4] = this.parentId;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] data) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.networkId = data[ix++];
|
this.networkId = data[ix++];
|
||||||
this.thingId = data[ix++];
|
this.thingId = data[ix++];
|
||||||
this.thingType = data[ix++];
|
this.thingType = data[ix++];
|
||||||
this.parentId = data[ix];
|
this.parentId = data[ix];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, byte thingType, byte parentId) {
|
public static bool Send(Client client, byte thingId, byte thingType, byte parentId) {
|
||||||
ThingMsg msg = new(client.networkId, thingId, thingType, parentId);
|
ThingMsg msg = new(client.networkId, thingId, thingType, parentId);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
if (packetSize != length)
|
if (packetSize != length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
ThingMsg msg = new(buffer);
|
ThingMsg msg = new(buffer);
|
||||||
|
|
||||||
client.messageQueue.Enqueue(msg);
|
client.messageQueue.Enqueue(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Thing
|
#endregion Thing
|
||||||
|
|
||||||
#region Name
|
#region Name
|
||||||
|
|
||||||
public class NameMsg : IMessage {
|
public class NameMsg : IMessage {
|
||||||
public const byte Id = 0x91; // 145
|
public const byte Id = 0x91; // 145
|
||||||
public const byte length = 3;
|
public const byte length = 3;
|
||||||
public byte networkId = 0;
|
public byte networkId = 0;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public byte len;
|
public byte len;
|
||||||
public string name;
|
public string name;
|
||||||
|
|
||||||
public NameMsg(byte thingId, string name) {
|
public NameMsg(byte thingId, string name) {
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
public NameMsg(byte[] data) : base(data) { }
|
public NameMsg(byte[] data) : base(data) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[length + this.name.Length];
|
byte[] buffer = new byte[length + this.name.Length];
|
||||||
buffer[0] = NameMsg.Id;
|
buffer[0] = NameMsg.Id;
|
||||||
buffer[1] = this.thingId;
|
buffer[1] = this.thingId;
|
||||||
buffer[2] = (byte)this.name.Length;
|
buffer[2] = (byte)this.name.Length;
|
||||||
for (int ix = 0; ix < this.name.Length; ix++)
|
for (int ix = 0; ix < this.name.Length; ix++)
|
||||||
buffer[3 + ix] = (byte)this.name[ix];
|
buffer[3 + ix] = (byte)this.name[ix];
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] data) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.thingId = data[ix++];
|
this.thingId = data[ix++];
|
||||||
int strlen = data[ix++];
|
int strlen = data[ix++];
|
||||||
this.name = System.Text.Encoding.UTF8.GetString(data, (int)ix, strlen);
|
this.name = System.Text.Encoding.UTF8.GetString(data, (int)ix, strlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, string name) {
|
public static bool Send(Client client, byte thingId, string name) {
|
||||||
NameMsg msg = new(thingId, name);
|
NameMsg msg = new(thingId, name);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
NameMsg msg = new(buffer);
|
NameMsg msg = new(buffer);
|
||||||
|
|
||||||
client.messageQueue.Enqueue(msg);
|
client.messageQueue.Enqueue(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Model URL
|
#region Model URL
|
||||||
|
|
||||||
public class ModelUrlMsg : IMessage {
|
public class ModelUrlMsg : IMessage {
|
||||||
public const byte Id = 0x90; // (144) Model URL
|
public const byte Id = 0x90; // (144) Model URL
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public Spherical position;
|
public Spherical position;
|
||||||
public float scale;
|
public float scale;
|
||||||
public string url;
|
public string url;
|
||||||
|
|
||||||
public ModelUrlMsg(byte thingId, string url, float scale = 1) {
|
public ModelUrlMsg(byte thingId, string url, float scale = 1) {
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
this.position = Spherical.zero;
|
this.position = Spherical.zero;
|
||||||
}
|
}
|
||||||
public ModelUrlMsg(byte[] data) : base(data) { }
|
public ModelUrlMsg(byte[] data) : base(data) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] data = new byte[this.url.Length + 9];
|
byte[] data = new byte[this.url.Length + 9];
|
||||||
data[0] = ModelUrlMsg.Id;
|
data[0] = ModelUrlMsg.Id;
|
||||||
data[1] = this.thingId; // Thing Id
|
data[1] = this.thingId; // Thing Id
|
||||||
// data[2]..[5] == position 0, 0, 0
|
// data[2]..[5] == position 0, 0, 0
|
||||||
data[6] = 0x3C; // Dummy float16 value 1
|
data[6] = 0x3C; // Dummy float16 value 1
|
||||||
data[7] = 0x00;
|
data[7] = 0x00;
|
||||||
|
|
||||||
data[8] = (byte)url.Length;
|
data[8] = (byte)url.Length;
|
||||||
for (int ix = 0; ix < this.url.Length; ix++)
|
for (int ix = 0; ix < this.url.Length; ix++)
|
||||||
data[9 + ix] = (byte)url[ix];
|
data[9 + ix] = (byte)url[ix];
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] data) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.thingId = data[ix++];
|
this.thingId = data[ix++];
|
||||||
this.position = LowLevelMessages.ReceiveSpherical(data, ref ix);
|
this.position = LowLevelMessages.ReceiveSpherical(data, ref ix);
|
||||||
this.scale = LowLevelMessages.ReceiveFloat16(data, ref ix);
|
this.scale = LowLevelMessages.ReceiveFloat16(data, ref ix);
|
||||||
int strlen = data[ix++];
|
int strlen = data[ix++];
|
||||||
url = System.Text.Encoding.UTF8.GetString(data, (int)ix, strlen);
|
url = System.Text.Encoding.UTF8.GetString(data, (int)ix, strlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, string modelUrl) {
|
public static bool Send(Client client, byte thingId, string modelUrl) {
|
||||||
ModelUrlMsg msg = new(thingId, modelUrl);
|
ModelUrlMsg msg = new(thingId, modelUrl);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
ModelUrlMsg msg = new(buffer);
|
ModelUrlMsg msg = new(buffer);
|
||||||
client.messageQueue.Enqueue(msg);
|
client.messageQueue.Enqueue(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Model URL
|
#endregion Model URL
|
||||||
|
|
||||||
#region Pose
|
#region Pose
|
||||||
|
|
||||||
public class PoseMsg : IMessage {
|
public class PoseMsg : IMessage {
|
||||||
public const byte Id = 0x10;
|
public const byte Id = 0x10;
|
||||||
public const byte length = 3 + 4 + 4;
|
public const byte length = 3 + 4 + 4;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
|
|
||||||
public byte poseType;
|
public byte poseType;
|
||||||
public const byte Pose_Position = 0x01;
|
public const byte Pose_Position = 0x01;
|
||||||
public const byte Pose_Orientation = 0x02;
|
public const byte Pose_Orientation = 0x02;
|
||||||
|
|
||||||
public Spherical position;
|
public Spherical position;
|
||||||
public Quat32 orientation;
|
public Quat32 orientation;
|
||||||
|
|
||||||
public PoseMsg(byte thingId, Spherical position, Quat32 orientation) {
|
public PoseMsg(byte thingId, Spherical position, Quat32 orientation) {
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
this.poseType = 0;
|
this.poseType = 0;
|
||||||
if (this.position != null)
|
if (this.position != null)
|
||||||
this.poseType |= Pose_Position;
|
this.poseType |= Pose_Position;
|
||||||
else
|
else
|
||||||
this.position = new Spherical(0, 0, 0);
|
this.position = new Spherical(0, 0, 0);
|
||||||
if (this.orientation != null)
|
if (this.orientation != null)
|
||||||
this.poseType |= Pose_Orientation;
|
this.poseType |= Pose_Orientation;
|
||||||
else
|
else
|
||||||
this.orientation = new Quat32(0, 0, 0, 1);
|
this.orientation = new Quat32(0, 0, 0, 1);
|
||||||
}
|
}
|
||||||
public PoseMsg(byte[] data) : base(data) { }
|
public PoseMsg(byte[] data) : base(data) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[PoseMsg.length];
|
byte[] buffer = new byte[PoseMsg.length];
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
buffer[ix++] = PoseMsg.Id;
|
buffer[ix++] = PoseMsg.Id;
|
||||||
buffer[ix++] = this.thingId;
|
buffer[ix++] = this.thingId;
|
||||||
buffer[ix++] = this.poseType;
|
buffer[ix++] = this.poseType;
|
||||||
|
|
||||||
LowLevelMessages.SendSpherical(buffer, ref ix, position);
|
LowLevelMessages.SendSpherical(buffer, ref ix, position);
|
||||||
LowLevelMessages.SendQuat32(buffer, ref ix, orientation);
|
LowLevelMessages.SendQuat32(buffer, ref ix, orientation);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] data) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
thingId = data[ix++];
|
thingId = data[ix++];
|
||||||
poseType = data[ix++];
|
poseType = data[ix++];
|
||||||
|
|
||||||
//if ((poseType & Pose_Position) != 0)
|
//if ((poseType & Pose_Position) != 0)
|
||||||
position = LowLevelMessages.ReceiveSpherical(data, ref ix);
|
position = LowLevelMessages.ReceiveSpherical(data, ref ix);
|
||||||
//if ((poseType & Pose_Orientation) != 0) {
|
//if ((poseType & Pose_Orientation) != 0) {
|
||||||
orientation = LowLevelMessages.ReceiveQuat32(data, ref ix);
|
orientation = LowLevelMessages.ReceiveQuat32(data, ref ix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, Spherical position, Quat32 orientation) {
|
public static bool Send(Client client, byte thingId, Spherical position, Quat32 orientation) {
|
||||||
PoseMsg msg = new(thingId, position, orientation);
|
PoseMsg msg = new(thingId, position, orientation);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
if (packetSize != length)
|
if (packetSize != length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
PoseMsg msg = new(buffer);
|
PoseMsg msg = new(buffer);
|
||||||
|
|
||||||
client.messageQueue.Enqueue(msg);
|
client.messageQueue.Enqueue(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Pose
|
#endregion Pose
|
||||||
|
|
||||||
#region Bytes
|
#region Custom
|
||||||
|
|
||||||
public class BytesMsg : IMessage {
|
public class CustomMsg : IMessage {
|
||||||
public const byte Id = 0xB1;
|
public const byte Id = 0xB1;
|
||||||
public byte networkId;
|
public byte networkId;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public byte[] bytes;
|
public byte[] bytes;
|
||||||
|
|
||||||
public BytesMsg(byte[] data) : base(data) { }
|
public CustomMsg(byte[] data) : base(data) { }
|
||||||
public BytesMsg(byte networkId, byte thingId, byte[] bytes) : base() {
|
public CustomMsg(byte networkId, byte thingId, byte[] bytes) : base() {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
}
|
}
|
||||||
public override byte[] Serialize() {
|
|
||||||
byte[] buffer = new byte[4 + this.bytes.Length];
|
|
||||||
int ix = 0;
|
|
||||||
buffer[ix++] = BytesMsg.Id;
|
|
||||||
buffer[ix++] = this.networkId;
|
|
||||||
buffer[ix++] = this.thingId;
|
|
||||||
buffer[ix++] = (byte)bytes.Length;
|
|
||||||
foreach (byte b in bytes)
|
|
||||||
buffer[ix++] = b;
|
|
||||||
|
|
||||||
return buffer;
|
public override byte[] Serialize() {
|
||||||
}
|
byte[] buffer = new byte[4 + this.bytes.Length];
|
||||||
public override void Deserialize(byte[] data) {
|
int ix = 0;
|
||||||
//this.bytes = data;
|
buffer[ix++] = CustomMsg.Id;
|
||||||
uint ix = 0;
|
buffer[ix++] = this.networkId;
|
||||||
this.thingId = data[ix++];
|
buffer[ix++] = this.thingId;
|
||||||
this.bytes = new byte[data.Length - ix];
|
buffer[ix++] = (byte)bytes.Length;
|
||||||
for (uint bytesIx = 0; ix < data.Length; ix++, bytesIx++)
|
foreach (byte b in bytes)
|
||||||
this.bytes[bytesIx] = data[ix];
|
buffer[ix++] = b;
|
||||||
}
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
public override void Deserialize(byte[] data) {
|
||||||
|
uint ix = 0;
|
||||||
|
this.thingId = data[ix++];
|
||||||
|
this.bytes = new byte[data.Length - ix];
|
||||||
|
for (uint bytesIx = 0; ix < data.Length; ix++, bytesIx++)
|
||||||
|
this.bytes[bytesIx] = data[ix];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void Send(Client client, byte thingId, byte[] bytes) {
|
public static void Send(Client client, byte thingId, byte[] bytes) {
|
||||||
BytesMsg msg = new(client.networkId, thingId, bytes);
|
CustomMsg msg = new(client.networkId, thingId, bytes);
|
||||||
SendMsg(client, msg);
|
SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
|
CustomMsg msg = new(buffer);
|
||||||
|
client.messageQueue.Enqueue(msg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// received bytes
|
#endregion Custom
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
|
||||||
BytesMsg msg = new(buffer);
|
|
||||||
client.messageQueue.Enqueue(msg);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Bytes
|
#region Text
|
||||||
|
|
||||||
#region Destroy
|
public class TextMsg : IMessage {
|
||||||
|
public const byte Id = 0xB0;
|
||||||
|
public string text;
|
||||||
|
|
||||||
public class DestroyMsg : IMessage {
|
public TextMsg(byte[] data) : base(data) { }
|
||||||
public const byte Id = 0x20;
|
public override void Deserialize(byte[] data) {
|
||||||
public const byte length = 2;
|
uint ix = 0;
|
||||||
public byte objectId;
|
uint strlen = data[ix++];
|
||||||
|
this.text = System.Text.Encoding.UTF8.GetString(data, (int)ix, (int)strlen);
|
||||||
|
}
|
||||||
|
|
||||||
public DestroyMsg(byte[] data) : base(data) { }
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
|
TextMsg msg = new(buffer);
|
||||||
|
|
||||||
public override void Deserialize(byte[] data) {
|
client.messageQueue.Enqueue(msg);
|
||||||
objectId = data[0];
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
#endregion
|
||||||
if (packetSize != length)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
byte[] buffer = await Receive(dataStream, packetSize);
|
#region Destroy
|
||||||
DestroyMsg msg = new(buffer);
|
|
||||||
|
|
||||||
client.messageQueue.Enqueue(msg);
|
public class DestroyMsg : IMessage {
|
||||||
return true;
|
public const byte Id = 0x20;
|
||||||
}
|
public const byte length = 2;
|
||||||
}
|
public byte objectId;
|
||||||
|
|
||||||
|
public DestroyMsg(byte[] data) : base(data) { }
|
||||||
|
|
||||||
|
public override void Deserialize(byte[] data) {
|
||||||
|
objectId = data[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
|
if (packetSize != length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
byte[] buffer = await Receive(dataStream, packetSize);
|
||||||
|
DestroyMsg msg = new(buffer);
|
||||||
|
|
||||||
|
client.messageQueue.Enqueue(msg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion Destroy
|
#endregion Destroy
|
||||||
}
|
}
|
||||||
|
@ -26,35 +26,35 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (msgId) {
|
switch (msgId) {
|
||||||
case PoseMsg.Id: // Object Pose (16)
|
case ClientMsg.Id: // 0xA0 / 160
|
||||||
result = await PoseMsg.Receive(dataStream, client, packetSize);
|
|
||||||
break;
|
|
||||||
case DestroyMsg.Id: // Destroy object (32)
|
|
||||||
result = await DestroyMsg.Receive(dataStream, client, packetSize);
|
|
||||||
break;
|
|
||||||
case ThingMsg.Id:
|
|
||||||
result = await ThingMsg.Receive(dataStream, client, packetSize);
|
|
||||||
break;
|
|
||||||
case InvestigateMsg.Id:
|
|
||||||
result = await InvestigateMsg.Receive(dataStream, client, packetSize);
|
|
||||||
break;
|
|
||||||
case ModelUrlMsg.Id: // Model URL (144)
|
|
||||||
result = await BytesMsg.Receive(dataStream, client, packetSize);
|
|
||||||
break;
|
|
||||||
case NameMsg.Id: // Object Name (145)
|
|
||||||
result = await NameMsg.Receive(dataStream, client, packetSize);
|
|
||||||
break;
|
|
||||||
case ClientMsg.Id:
|
|
||||||
result = await ClientMsg.Receive(dataStream, client, packetSize);
|
result = await ClientMsg.Receive(dataStream, client, packetSize);
|
||||||
break;
|
break;
|
||||||
case NetworkIdMsg.Id:
|
case NetworkIdMsg.Id: // 0xA1 / 161
|
||||||
result = await NetworkIdMsg.Receive(dataStream, client, packetSize);
|
result = await NetworkIdMsg.Receive(dataStream, client, packetSize);
|
||||||
break;
|
break;
|
||||||
//case TextMsg.Id: // Text (176)
|
case InvestigateMsg.Id: // 0x81
|
||||||
// result = await TextMsg.Receive(dataStream, client, packetSize);
|
result = await InvestigateMsg.Receive(dataStream, client, packetSize);
|
||||||
// break;
|
break;
|
||||||
case BytesMsg.Id:
|
case ThingMsg.Id: // 0x80 / 128
|
||||||
result = await BytesMsg.Receive(dataStream, client, packetSize);
|
result = await ThingMsg.Receive(dataStream, client, packetSize);
|
||||||
|
break;
|
||||||
|
case NameMsg.Id: // 0x91 / 145
|
||||||
|
result = await NameMsg.Receive(dataStream, client, packetSize);
|
||||||
|
break;
|
||||||
|
case ModelUrlMsg.Id: // 0x90 / 144
|
||||||
|
result = await ModelUrlMsg.Receive(dataStream, client, packetSize);
|
||||||
|
break;
|
||||||
|
case PoseMsg.Id: // 0x10 / 16
|
||||||
|
result = await PoseMsg.Receive(dataStream, client, packetSize);
|
||||||
|
break;
|
||||||
|
case CustomMsg.Id: // 0xB1 / 177
|
||||||
|
result = await CustomMsg.Receive(dataStream, client, packetSize);
|
||||||
|
break;
|
||||||
|
case TextMsg.Id: // 0xB0 / 176
|
||||||
|
result = await TextMsg.Receive(dataStream, client, packetSize);
|
||||||
|
break;
|
||||||
|
case DestroyMsg.Id: // 0x20 / 32
|
||||||
|
result = await DestroyMsg.Receive(dataStream, client, packetSize);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -65,21 +65,54 @@ namespace Passer.Control {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ProcessMessage(ISiteServer site, Client client, IMessage msg) {
|
//public static void ProcessMessage(ISiteServer site, Client client, IMessage msg) {
|
||||||
switch (msg) {
|
// client.ProcessMessage(site, client, msg);
|
||||||
case NetworkIdMsg networkId:
|
// switch (msg) {
|
||||||
site.ProcessNetworkId(client, networkId);
|
// case ClientMsg clientMsg:
|
||||||
break;
|
// site.ProcessClient(client, clientMsg);
|
||||||
case ModelUrlMsg modelUrl:
|
// break;
|
||||||
site.ProcessModelUrl(client, modelUrl);
|
// case NetworkIdMsg networkId:
|
||||||
break;
|
// site.ProcessNetworkId(client, networkId);
|
||||||
}
|
// break;
|
||||||
}
|
// case InvestigateMsg investigate:
|
||||||
|
// site.ProcessInvestigate(client, investigate);
|
||||||
|
// break;
|
||||||
|
// case ThingMsg thing:
|
||||||
|
// site.ProcessThing(client, thing);
|
||||||
|
// break;
|
||||||
|
// case NameMsg name:
|
||||||
|
// site.ProcessName(client, name);
|
||||||
|
// break;
|
||||||
|
// case ModelUrlMsg modelUrl:
|
||||||
|
// site.ProcessModelUrl(client, modelUrl);
|
||||||
|
// break;
|
||||||
|
// case PoseMsg pose:
|
||||||
|
// site.ProcessPose(client, pose);
|
||||||
|
// break;
|
||||||
|
// case CustomMsg custom:
|
||||||
|
// site.ProcessCustom(client, custom);
|
||||||
|
// break;
|
||||||
|
// case TextMsg text:
|
||||||
|
// site.ProcessText(client, text);
|
||||||
|
// break;
|
||||||
|
// case DestroyMsg destroy:
|
||||||
|
// site.ProcessDestroy(client, destroy);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ISiteServer {
|
//public interface ISiteServer {
|
||||||
|
|
||||||
public void ProcessNetworkId(Client client, NetworkIdMsg networkId);
|
// public void ProcessClient(Client client, ClientMsg clientMsg);
|
||||||
public void ProcessModelUrl(Client client, ModelUrlMsg modelUrl);
|
// public void ProcessNetworkId(Client client, NetworkIdMsg networkId);
|
||||||
}
|
// public void ProcessInvestigate(Client client, InvestigateMsg investigate);
|
||||||
|
// public void ProcessThing(Client client, ThingMsg thing);
|
||||||
|
// public void ProcessName(Client client, NameMsg name);
|
||||||
|
// public void ProcessModelUrl(Client client, ModelUrlMsg modelUrl);
|
||||||
|
// public void ProcessPose(Client client, PoseMsg pose);
|
||||||
|
// public void ProcessCustom(Client client, CustomMsg custom);
|
||||||
|
// public void ProcessText(Client client, TextMsg text);
|
||||||
|
// public void ProcessDestroy(Client client, DestroyMsg destroy);
|
||||||
|
//}
|
||||||
}
|
}
|
@ -7,6 +7,8 @@ using System.Net.Sockets;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using GLTFast;
|
using GLTFast;
|
||||||
|
using Unity.Collections.LowLevel.Unsafe;
|
||||||
|
|
||||||
|
|
||||||
#if hNW_ROBOID
|
#if hNW_ROBOID
|
||||||
|
|
||||||
@ -15,7 +17,7 @@ using Passer.LinearAlgebra;
|
|||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
|
|
||||||
public partial class HumanoidPlayer : MonoBehaviour, IHumanoidNetworking, ISiteServer {
|
public partial class HumanoidPlayer : MonoBehaviour, IHumanoidNetworking { //}, ISiteServer {
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
protected float _sendRate = 25;
|
protected float _sendRate = 25;
|
||||||
@ -124,6 +126,39 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
#endregion Dummy Interface
|
#endregion Dummy Interface
|
||||||
|
|
||||||
|
public class HumanoidClient : Client {
|
||||||
|
readonly HumanoidPlayer player;
|
||||||
|
|
||||||
|
public HumanoidClient(UdpClient udpClient, string ipAddress, int port, HumanoidPlayer player) {
|
||||||
|
this.ipAddress = ipAddress;
|
||||||
|
this.port = port;
|
||||||
|
this.udpClient = udpClient;
|
||||||
|
this.player = player;
|
||||||
|
clients.Add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ProcessNetworkId(NetworkIdMsg msg) {
|
||||||
|
if (this.networkId == msg.networkId)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.networkId = msg.networkId;
|
||||||
|
player.ProcessNetworkId(this, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ProcessModelUrl(ModelUrlMsg msg) {
|
||||||
|
int ix = msg.url.LastIndexOf(".");
|
||||||
|
if (ix < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string extension = msg.url.Substring(msg.url.LastIndexOf("."));
|
||||||
|
string extension3 = extension.Substring(0, 4);
|
||||||
|
string extension4 = extension.Substring(0, 5);
|
||||||
|
if (extension4 == ".gltf" || extension3 == ".glb") {
|
||||||
|
player.ProcessGltfModel(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Awake() {
|
protected virtual void Awake() {
|
||||||
mInstance = this;
|
mInstance = this;
|
||||||
|
|
||||||
@ -142,8 +177,7 @@ namespace Passer.Humanoid {
|
|||||||
udpClient = new UdpClient(endPoint);
|
udpClient = new UdpClient(endPoint);
|
||||||
receiveCallback = new System.AsyncCallback(result => ReceiveUDP(client, result));
|
receiveCallback = new System.AsyncCallback(result => ReceiveUDP(client, result));
|
||||||
udpClient.BeginReceive(receiveCallback, obj);
|
udpClient.BeginReceive(receiveCallback, obj);
|
||||||
//client = Client.NewUDPClient(udpClient, endPoint.Address.ToString(), endPoint.Port);
|
client = new HumanoidClient(udpClient, siteAddress, sitePort, this);
|
||||||
client = Client.NewUDPClient(udpClient, siteAddress, sitePort);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//endpoint = new IPEndPoint(IPAddress.Any, sitePort);
|
//endpoint = new IPEndPoint(IPAddress.Any, sitePort);
|
||||||
@ -161,16 +195,21 @@ namespace Passer.Humanoid {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (udpClient.Client.Connected) {
|
if (udpClient.Client.Connected) {
|
||||||
byte[] data = udpClient.EndReceive(result, ref endPoint);
|
try {
|
||||||
dataStream.WriteByte((byte)data.Length);
|
byte[] data = udpClient.EndReceive(result, ref endPoint);
|
||||||
dataStream.Write(data, 0, data.Length);
|
dataStream.WriteByte((byte)data.Length);
|
||||||
if (client.ipAddress == null) {
|
dataStream.Write(data, 0, data.Length);
|
||||||
client.ipAddress = endPoint.Address.ToString();
|
if (client.ipAddress == null) {
|
||||||
client.port = endPoint.Port;
|
client.ipAddress = endPoint.Address.ToString();
|
||||||
// I thing sending now is too soon, we are currenlty processing a message...
|
client.port = endPoint.Port;
|
||||||
//SendNetworkId(client);
|
// I thing sending now is too soon, we are currenlty processing a message...
|
||||||
//if (string.IsNullOrEmpty(sceneUrl) == false)
|
//SendNetworkId(client);
|
||||||
// SendModelUrl(client, sceneUrl);
|
//if (string.IsNullOrEmpty(sceneUrl) == false)
|
||||||
|
// SendModelUrl(client, sceneUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception _) {
|
||||||
|
Debug.Log("connection error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -195,14 +234,12 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
protected virtual void LateUpdate() {
|
protected virtual void LateUpdate() {
|
||||||
foreach (Client client in Client.clients) {
|
foreach (Client client in Client.clients) {
|
||||||
while (client.messageQueue.TryDequeue(out Passer.Control.IMessage msg))
|
if (client is HumanoidClient humanoidClient) {
|
||||||
SiteServer.ProcessMessage(this, client, msg);
|
while (humanoidClient.messageQueue.TryDequeue(out Passer.Control.IMessage msg))
|
||||||
|
humanoidClient.ProcessMessage(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//while (messageQueue.TryDequeue(out HumanoidNetworking.IMessage msg)) {
|
|
||||||
// ProcessMessage(msg);
|
|
||||||
//}
|
|
||||||
|
|
||||||
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) {
|
||||||
@ -219,40 +256,6 @@ namespace Passer.Humanoid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//protected virtual void ProcessMessage(HumanoidNetworking.IMessage msg) {
|
|
||||||
// switch (msg) {
|
|
||||||
// case NetworkIdMsg networkId:
|
|
||||||
// ProcessNetworkId(networkId);
|
|
||||||
// break;
|
|
||||||
// case ModelUrlMsg modelUrl:
|
|
||||||
// ProcessModelURL(modelUrl);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//void Receiver(IAsyncResult result) {
|
|
||||||
// // Take care of buffered messages after the client has been closed
|
|
||||||
// if (udpClient == null || udpClient.Client.Connected == false)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// byte[] data = (udpClient.EndReceive(result, ref endPoint));
|
|
||||||
|
|
||||||
// ReceivePacket(data);
|
|
||||||
|
|
||||||
// udpClient.BeginReceive(receiveCallback, obj);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//void ReceivePacket(byte[] data) {
|
|
||||||
// byte msgId = data[0];
|
|
||||||
// switch (msgId) {
|
|
||||||
// case 0xA1: // (161) Network Id
|
|
||||||
// this.ReceiveNetworkId(data); break;
|
|
||||||
// case ModelUrlMsg.Id:
|
|
||||||
// this.ReceiveModelUrl(data); break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
#endregion Update
|
#endregion Update
|
||||||
|
|
||||||
#region Client
|
#region Client
|
||||||
@ -326,15 +329,19 @@ namespace Passer.Humanoid {
|
|||||||
// Debug.Log($"bone pos {bonePose.bonePosition.horizontal} {bonePose.bonePosition.vertical} {bonePose.bonePosition.distance}");
|
// Debug.Log($"bone pos {bonePose.bonePosition.horizontal} {bonePose.bonePosition.vertical} {bonePose.bonePosition.distance}");
|
||||||
//}
|
//}
|
||||||
//SendMsg(data);
|
//SendMsg(data);
|
||||||
Quaternion orientation = bone.bone.transform.rotation;
|
|
||||||
Quat32 boneOrientation = new(orientation.x, orientation.y, orientation.z, orientation.w);
|
|
||||||
if (isRoot) {
|
if (isRoot) {
|
||||||
|
Quaternion orientation = bone.bone.transform.rotation;
|
||||||
|
Quat32 boneOrientation = new(orientation.x, orientation.y, orientation.z, orientation.w);
|
||||||
FromVector3(bone.bone.transform.position, out float distance, out float horizontal, out float vertical);
|
FromVector3(bone.bone.transform.position, out float distance, out float horizontal, out float vertical);
|
||||||
Spherical bonePosition = new(distance, horizontal, vertical);
|
Spherical bonePosition = new(distance, horizontal, vertical);
|
||||||
PoseMsg.Send(client, (byte)bone.boneId, bonePosition, boneOrientation);
|
PoseMsg.Send(client, (byte)bone.boneId, bonePosition, boneOrientation);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
Quaternion orientation = bone.bone.transform.localRotation;
|
||||||
|
Quat32 boneOrientation = new(orientation.x, orientation.y, orientation.z, orientation.w);
|
||||||
PoseMsg.Send(client, (byte)bone.boneId, null, boneOrientation);
|
PoseMsg.Send(client, (byte)bone.boneId, null, boneOrientation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Pose
|
#endregion Pose
|
||||||
@ -343,36 +350,7 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
//#region NetworkId
|
//#region NetworkId
|
||||||
|
|
||||||
//public class NetworkIdMsg : HumanoidNetworking.IMessage {
|
void ProcessNetworkId(Client client, NetworkIdMsg msg) {
|
||||||
// public const byte msgId = 0xA1;
|
|
||||||
// public byte networkId = 0;
|
|
||||||
|
|
||||||
// public NetworkIdMsg(byte networkId) {
|
|
||||||
// this.networkId = networkId;
|
|
||||||
// }
|
|
||||||
// public NetworkIdMsg(byte[] data) : base(data) { }
|
|
||||||
|
|
||||||
// public override byte[] Serialize() {
|
|
||||||
// MemoryStream ms = new();
|
|
||||||
// BinaryWriter bw = new(ms);
|
|
||||||
// bw.Write(msgId);
|
|
||||||
// bw.Write(this.networkId); // Thing Id
|
|
||||||
// byte[] data = ms.ToArray();
|
|
||||||
// return data;
|
|
||||||
// }
|
|
||||||
// public override void Deserialize(byte[] data) {
|
|
||||||
// base.Deserialize(data);
|
|
||||||
// this.networkId = (byte)data[1];
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public void ReceiveNetworkId(byte[] data) {
|
|
||||||
// NetworkIdMsg msg = new(data);
|
|
||||||
|
|
||||||
// messageQueue.Enqueue(msg);
|
|
||||||
//}
|
|
||||||
|
|
||||||
void ISiteServer.ProcessNetworkId(Client client, NetworkIdMsg msg) {
|
|
||||||
if (this.networkId == msg.networkId)
|
if (this.networkId == msg.networkId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -430,34 +408,6 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
//#region Thing
|
//#region Thing
|
||||||
|
|
||||||
//protected class ThingMsg : HumanoidNetworking.IMessage {
|
|
||||||
// private const byte msgId = 0x80;
|
|
||||||
// public const byte length = 3;
|
|
||||||
// public byte thingId;
|
|
||||||
// public byte thingType;
|
|
||||||
|
|
||||||
// public ThingMsg(byte thingId, byte thingType) {
|
|
||||||
// this.thingId = thingId;
|
|
||||||
// this.thingType = thingType;
|
|
||||||
// }
|
|
||||||
// public ThingMsg(byte[] data) : base(data) { }
|
|
||||||
|
|
||||||
// public override byte[] Serialize() {
|
|
||||||
// byte[] data = new byte[3];
|
|
||||||
// data[0] = msgId;
|
|
||||||
// data[1] = thingId;
|
|
||||||
// data[2] = thingType;
|
|
||||||
// return data;
|
|
||||||
// }
|
|
||||||
// public override void Deserialize(byte[] data) {
|
|
||||||
// try {
|
|
||||||
// uint ix = 0;
|
|
||||||
// thingId = data[ix++];
|
|
||||||
// thingType = data[ix++];
|
|
||||||
// }
|
|
||||||
// catch { }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public void SendThing(Client client, HumanoidControl humanoid) {
|
public void SendThing(Client client, HumanoidControl humanoid) {
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Debug)
|
if (debug <= HumanoidNetworking.DebugLevel.Debug)
|
||||||
@ -476,42 +426,6 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
//#region SubThing
|
//#region SubThing
|
||||||
|
|
||||||
//protected class SubThingMsg : HumanoidNetworking.IMessage {
|
|
||||||
// private const byte msgId = 0x12; // (18)
|
|
||||||
// public const byte length = 3 + 4;
|
|
||||||
// public byte thingId;
|
|
||||||
// public byte parentId;
|
|
||||||
// readonly Vector3 position;
|
|
||||||
|
|
||||||
// public SubThingMsg(byte thingId, byte parentId, Vector3 position) {
|
|
||||||
// this.thingId = thingId;
|
|
||||||
// this.parentId = parentId;
|
|
||||||
// this.position = position;
|
|
||||||
// }
|
|
||||||
// public SubThingMsg(byte[] data) : base(data) { }
|
|
||||||
|
|
||||||
// public override byte[] Serialize() {
|
|
||||||
// byte[] data = new byte[7];
|
|
||||||
// data[0] = msgId;
|
|
||||||
// data[1] = thingId;
|
|
||||||
// data[2] = parentId;
|
|
||||||
|
|
||||||
// data[3] = 0;
|
|
||||||
// data[4] = 0;
|
|
||||||
// data[5] = 0;
|
|
||||||
// data[6] = 0;
|
|
||||||
// return data;
|
|
||||||
// }
|
|
||||||
// //public override void Deserialize(byte[] data) {
|
|
||||||
// // try {
|
|
||||||
// // uint ix = 0;
|
|
||||||
// // thingId = data[ix++];
|
|
||||||
// // thingType = data[ix++];
|
|
||||||
// // }
|
|
||||||
// // catch { }
|
|
||||||
// //}
|
|
||||||
//}
|
|
||||||
|
|
||||||
public void SendSubThing(HumanoidControl humanoid, HumanoidTarget.TargetedBone bone) {
|
public void SendSubThing(HumanoidControl humanoid, HumanoidTarget.TargetedBone bone) {
|
||||||
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);
|
||||||
@ -539,39 +453,6 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
//#region Name
|
//#region Name
|
||||||
|
|
||||||
//public class NameMsg : HumanoidNetworking.IMessage {
|
|
||||||
// public const byte msgId = 0x91; // (145) Name
|
|
||||||
// public byte networkId = 0;
|
|
||||||
// public byte thingId;
|
|
||||||
// public byte len;
|
|
||||||
// public string name;
|
|
||||||
|
|
||||||
// public NameMsg(byte thingId, string name) {
|
|
||||||
// this.thingId = thingId;
|
|
||||||
// this.name = name;
|
|
||||||
// }
|
|
||||||
// public NameMsg(byte[] data) : base(data) { }
|
|
||||||
|
|
||||||
// public override byte[] Serialize() {
|
|
||||||
// MemoryStream ms = new();
|
|
||||||
// BinaryWriter bw = new(ms);
|
|
||||||
// bw.Write(msgId); // 145 Name Msg
|
|
||||||
// bw.Write((byte)thingId); // Thing Id
|
|
||||||
// bw.Write((byte)name.Length);
|
|
||||||
|
|
||||||
// for (int ix = 0; ix < name.Length; ix++)
|
|
||||||
// bw.Write(name[ix]);
|
|
||||||
|
|
||||||
// byte[] data = ms.ToArray();
|
|
||||||
// return data;
|
|
||||||
// }
|
|
||||||
// public override void Deserialize(byte[] data) {
|
|
||||||
// uint ix = 0;
|
|
||||||
// this.thingId = data[ix++];
|
|
||||||
// int strlen = data[ix++];
|
|
||||||
// this.name = System.Text.Encoding.UTF8.GetString(data, (int)ix, strlen);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public void SendName(HumanoidControl humanoid, byte thingId, string name) {
|
public void SendName(HumanoidControl humanoid, byte thingId, string name) {
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Debug)
|
if (debug <= HumanoidNetworking.DebugLevel.Debug)
|
||||||
@ -590,68 +471,13 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
//#region Model
|
//#region Model
|
||||||
|
|
||||||
//protected class ModelUrlMsg : HumanoidNetworking.IMessage {
|
|
||||||
// public const byte Id = 0x90; // (144) Model URL
|
|
||||||
// public byte objectId;
|
|
||||||
// public Vector3 position;
|
|
||||||
// public float scale;
|
|
||||||
// public string url;
|
|
||||||
|
|
||||||
// public ModelUrlMsg(string url) {
|
|
||||||
// this.url = url;
|
|
||||||
// }
|
|
||||||
// public ModelUrlMsg(byte[] data) : base(data) { }
|
|
||||||
|
|
||||||
// public override byte[] Serialize() {
|
|
||||||
// MemoryStream ms = new();
|
|
||||||
// BinaryWriter bw = new(ms);
|
|
||||||
// bw.Write(ModelUrlMsg.Id); // 145 Name Msg
|
|
||||||
// bw.Write((byte)0x00); // Thing Id
|
|
||||||
|
|
||||||
// bw.Write((byte)0x00); // Dummy position
|
|
||||||
// bw.Write((byte)0x00);
|
|
||||||
// bw.Write((byte)0x00);
|
|
||||||
// bw.Write((byte)0x00);
|
|
||||||
|
|
||||||
// SendFloat16(bw, 1.0f);
|
|
||||||
|
|
||||||
// bw.Write((byte)url.Length);
|
|
||||||
|
|
||||||
// for (int ix = 0; ix < url.Length; ix++)
|
|
||||||
// bw.Write(url[ix]);
|
|
||||||
|
|
||||||
// byte[] data = ms.ToArray();
|
|
||||||
// return data;
|
|
||||||
// }
|
|
||||||
// public override void Deserialize(byte[] data) {
|
|
||||||
// uint ix = 1; // [0] = msgId
|
|
||||||
// this.objectId = data[ix++];
|
|
||||||
// //this.position = ReceiveVector3(data, ref ix);
|
|
||||||
// this.position = ReceiveSpherical(data, ref ix);
|
|
||||||
// this.scale = ReceiveFloat16(data, ref ix);
|
|
||||||
// int strlen = data[ix++];
|
|
||||||
// url = System.Text.Encoding.UTF8.GetString(data, (int)ix, strlen);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public void SendModel(HumanoidControl humanoid, string url) {
|
public void SendModel(HumanoidControl humanoid, string url) {
|
||||||
if (debug <= HumanoidNetworking.DebugLevel.Debug)
|
if (debug <= HumanoidNetworking.DebugLevel.Debug)
|
||||||
Debug.Log("Send URL " + humanoid.humanoidId + " nwId: " + humanoid.nwId);
|
Debug.Log("Send URL " + humanoid.humanoidId + " nwId: " + humanoid.nwId);
|
||||||
|
|
||||||
ModelUrlMsg.Send(client, 0, url);
|
ModelUrlMsg.Send(client, 0, url);
|
||||||
//ModelUrlMsg msg = new(url); // humanoid.name;
|
|
||||||
|
|
||||||
//if (udpClient != null) {
|
|
||||||
// byte[] data = msg.Serialize();
|
|
||||||
// udpClient.Send(data, data.Length, "127.0.0.1", nssPort);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//protected void ReceiveModelUrl(byte[] data) {
|
|
||||||
// ModelUrlMsg msg = new(data);
|
|
||||||
// messageQueue.Enqueue(msg);
|
|
||||||
//}
|
|
||||||
|
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
protected async void ProcessModelURL(Client client, ModelUrlMsg msg) {
|
protected async void ProcessModelURL(Client client, ModelUrlMsg msg) {
|
||||||
if (loaded)
|
if (loaded)
|
||||||
@ -681,18 +507,18 @@ namespace Passer.Humanoid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ISiteServer.ProcessModelUrl(Client client, ModelUrlMsg msg) {
|
//void ISiteServer.ProcessModelUrl(Client client, ModelUrlMsg msg) {
|
||||||
int ix = msg.url.LastIndexOf(".");
|
// int ix = msg.url.LastIndexOf(".");
|
||||||
if (ix < 0)
|
// if (ix < 0)
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
string extension = msg.url.Substring(msg.url.LastIndexOf("."));
|
// string extension = msg.url.Substring(msg.url.LastIndexOf("."));
|
||||||
string extension3 = extension.Substring(0, 4);
|
// string extension3 = extension.Substring(0, 4);
|
||||||
string extension4 = extension.Substring(0, 5);
|
// string extension4 = extension.Substring(0, 5);
|
||||||
if (extension4 == ".gltf" || extension3 == ".glb") {
|
// if (extension4 == ".gltf" || extension3 == ".glb") {
|
||||||
ProcessGltfModel(msg);
|
// ProcessGltfModel(msg);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
#region GLTF
|
#region GLTF
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
//Compensate for absolute rigidbody speed (specifically when on a moving platform)
|
//Compensate for absolute rigidbody speed (specifically when on a moving platform)
|
||||||
if (handRigidbody != null) {
|
if (handRigidbody != null) {
|
||||||
Vector3 residualVelocity = handRigidbody.velocity - velocityTowardsTarget;
|
Vector3 residualVelocity = handRigidbody.linearVelocity - velocityTowardsTarget;
|
||||||
damper += residualVelocity * 10;
|
damper += residualVelocity * 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -552,7 +552,7 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
Vector3 velocityTarget = (positionDelta * velocityMagic) * Time.fixedDeltaTime;
|
Vector3 velocityTarget = (positionDelta * velocityMagic) * Time.fixedDeltaTime;
|
||||||
if (float.IsNaN(velocityTarget.x) == false)
|
if (float.IsNaN(velocityTarget.x) == false)
|
||||||
handRigidbody.velocity = Vector3.MoveTowards(handRigidbody.velocity, velocityTarget, MaxVelocityChange);
|
handRigidbody.linearVelocity = Vector3.MoveTowards(handRigidbody.linearVelocity, velocityTarget, MaxVelocityChange);
|
||||||
|
|
||||||
rotationDelta.ToAngleAxis(out angle, out axis);
|
rotationDelta.ToAngleAxis(out angle, out axis);
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ namespace Passer {
|
|||||||
|
|
||||||
public RigidbodyData(Rigidbody rb) {
|
public RigidbodyData(Rigidbody rb) {
|
||||||
mass = rb.mass;
|
mass = rb.mass;
|
||||||
drag = rb.drag;
|
drag = rb.linearDamping;
|
||||||
angularDrag = rb.angularDrag;
|
angularDrag = rb.angularDamping;
|
||||||
useGravity = rb.useGravity;
|
useGravity = rb.useGravity;
|
||||||
isKinematic = rb.isKinematic;
|
isKinematic = rb.isKinematic;
|
||||||
interpolation = rb.interpolation;
|
interpolation = rb.interpolation;
|
||||||
@ -28,8 +28,8 @@ namespace Passer {
|
|||||||
|
|
||||||
public void CopyToRigidbody(Rigidbody rb) {
|
public void CopyToRigidbody(Rigidbody rb) {
|
||||||
rb.mass = mass;
|
rb.mass = mass;
|
||||||
rb.drag = drag;
|
rb.linearDamping = drag;
|
||||||
rb.angularDrag = angularDrag;
|
rb.angularDamping = angularDrag;
|
||||||
rb.useGravity = useGravity;
|
rb.useGravity = useGravity;
|
||||||
rb.isKinematic = isKinematic;
|
rb.isKinematic = isKinematic;
|
||||||
rb.interpolation = interpolation;
|
rb.interpolation = interpolation;
|
||||||
|
@ -1242,8 +1242,8 @@ namespace Passer.Humanoid {
|
|||||||
handRigidbody = hand.bone.transform.gameObject.AddComponent<Rigidbody>();
|
handRigidbody = hand.bone.transform.gameObject.AddComponent<Rigidbody>();
|
||||||
}
|
}
|
||||||
handRigidbody.mass = 1;
|
handRigidbody.mass = 1;
|
||||||
handRigidbody.drag = 0;
|
handRigidbody.linearDamping = 0;
|
||||||
handRigidbody.angularDrag = 10;
|
handRigidbody.angularDamping = 10;
|
||||||
handRigidbody.useGravity = false;
|
handRigidbody.useGravity = false;
|
||||||
handRigidbody.isKinematic = true;
|
handRigidbody.isKinematic = true;
|
||||||
handRigidbody.interpolation = RigidbodyInterpolation.None;
|
handRigidbody.interpolation = RigidbodyInterpolation.None;
|
||||||
|
@ -34,7 +34,7 @@ namespace Passer {
|
|||||||
if (thisRigidbody != null) {
|
if (thisRigidbody != null) {
|
||||||
thisRigidbody.MovePosition(new Vector3(startPosition.x, startPosition.y + 0.1F, startPosition.z));
|
thisRigidbody.MovePosition(new Vector3(startPosition.x, startPosition.y + 0.1F, startPosition.z));
|
||||||
thisRigidbody.MoveRotation(startRotation);
|
thisRigidbody.MoveRotation(startRotation);
|
||||||
thisRigidbody.velocity = Vector3.zero;
|
thisRigidbody.linearVelocity = Vector3.zero;
|
||||||
thisRigidbody.angularVelocity = Vector3.zero;
|
thisRigidbody.angularVelocity = Vector3.zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ namespace Passer {
|
|||||||
damper = -velocityTowardsTarget * damping;
|
damper = -velocityTowardsTarget * damping;
|
||||||
|
|
||||||
//Compensate for absolute rigidbody speed (specifically when on a moving platform)
|
//Compensate for absolute rigidbody speed (specifically when on a moving platform)
|
||||||
Vector3 residualVelocity = thisRigidbody.velocity - velocityTowardsTarget;
|
Vector3 residualVelocity = thisRigidbody.linearVelocity - velocityTowardsTarget;
|
||||||
damper += residualVelocity * 10;
|
damper += residualVelocity * 10;
|
||||||
}
|
}
|
||||||
lastDistanceToTarget = distanceToTarget;
|
lastDistanceToTarget = distanceToTarget;
|
||||||
|
@ -30,8 +30,8 @@ namespace Passer {
|
|||||||
|
|
||||||
public void CopyFromRigidbody(Rigidbody rb) {
|
public void CopyFromRigidbody(Rigidbody rb) {
|
||||||
mass = rb.mass;
|
mass = rb.mass;
|
||||||
drag = rb.drag;
|
drag = rb.linearDamping;
|
||||||
angularDrag = rb.angularDrag;
|
angularDrag = rb.angularDamping;
|
||||||
useGravity = rb.useGravity;
|
useGravity = rb.useGravity;
|
||||||
isKinematic = rb.isKinematic;
|
isKinematic = rb.isKinematic;
|
||||||
interpolation = rb.interpolation;
|
interpolation = rb.interpolation;
|
||||||
@ -44,8 +44,8 @@ namespace Passer {
|
|||||||
|
|
||||||
public void CopyToRigidbody(Rigidbody rb) {
|
public void CopyToRigidbody(Rigidbody rb) {
|
||||||
rb.mass = mass;
|
rb.mass = mass;
|
||||||
rb.drag = drag;
|
rb.linearDamping = drag;
|
||||||
rb.angularDrag = angularDrag;
|
rb.angularDamping = angularDrag;
|
||||||
rb.useGravity = useGravity;
|
rb.useGravity = useGravity;
|
||||||
rb.isKinematic = isKinematic;
|
rb.isKinematic = isKinematic;
|
||||||
rb.interpolation = interpolation;
|
rb.interpolation = interpolation;
|
||||||
|
@ -585,7 +585,7 @@ namespace Passer {
|
|||||||
if (rayType != RayType.Gravity)
|
if (rayType != RayType.Gravity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rigidbody.velocity = transform.forward * speed;
|
rigidbody.linearVelocity = transform.forward * speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LaunchPrefab(GameObject prefab) {
|
public void LaunchPrefab(GameObject prefab) {
|
||||||
|
@ -694,7 +694,7 @@ namespace Passer {
|
|||||||
Humanoid.HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject);
|
Humanoid.HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject);
|
||||||
|
|
||||||
if (thisRigidbody != null) {
|
if (thisRigidbody != null) {
|
||||||
objRigidbody.velocity = thisRigidbody.velocity;
|
objRigidbody.linearVelocity = thisRigidbody.linearVelocity;
|
||||||
objRigidbody.angularVelocity = thisRigidbody.angularVelocity;
|
objRigidbody.angularVelocity = thisRigidbody.angularVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user