Commit alt code of VR engine

This commit is contained in:
Logophilist
2020-10-05 20:20:57 +02:00
parent 3494f678e3
commit e4d192fb06
4 changed files with 143 additions and 23 deletions

View File

@@ -83,11 +83,12 @@ namespace RH_Engine
return JsonConvert.SerializeObject(Payload(payload));
}
public string DeleteNode(string uuid)
public string DeleteNode(string uuid, string serialCode)
{
dynamic payload = new
{
id = "scene/node/delete",
serial = serialCode,
data = new
{
id = uuid,
@@ -105,14 +106,13 @@ namespace RH_Engine
data = new
{
name = "dashboard",
parent = uuidBike,
components = new
{
panel = new
{
size = new int[] { 1, 1 },
resolution = new int[] { 512, 512 },
background = new int[] { 1, 0, 0, 0 },
background = new int[] { 1, 1, 1, 1 },
castShadow = false
}
}
@@ -151,17 +151,18 @@ namespace RH_Engine
return JsonConvert.SerializeObject(Payload(payload));
}
public string bikeSpeed(string uuidPanel, double speed)
public string bikeSpeed(string uuidPanel, string serialCode, double speed)
{
dynamic payload = new
{
id = "scene/panel/drawtext",
serial = serialCode,
data = new
{
id = uuidPanel,
text = "Bike speed placeholder",
position = new int[] { 0, 0 },
size = 32.0,
text = "Speed: " + speed.ToString(),
position = new int[] { 4, 24 },
size = 36.0,
color = new int[] { 0, 0, 0, 1 },
font = "segoeui"
}
@@ -250,16 +251,17 @@ namespace RH_Engine
return JsonConvert.SerializeObject(Payload(payload));
}
public string MoveTo(string uuid, float[] positionVector, float rotateValue, float speedValue, float timeValue)
public string MoveTo(string uuid, string serial, float[] positionVector, string rotateValue, int speedValue, int timeValue)
{
return MoveTo(uuid, "idk", positionVector, rotateValue, "linear", false, speedValue, timeValue);
return MoveTo(uuid, serial, "stop", positionVector, rotateValue, "linear", false, speedValue, timeValue);
}
private string MoveTo(string uuid, string stopValue, float[] positionVector, float rotateValue, string interpolateValue, bool followHeightValue, float speedValue, float timeValue)
private string MoveTo(string uuid, string serialCode, string stopValue, float[] positionVector, string rotateValue, string interpolateValue, bool followHeightValue, int speedValue, int timeValue)
{
dynamic payload = new
{
id = "scene/node/moveto",
serial = serialCode,
data = new
{
id = uuid,
@@ -319,7 +321,7 @@ namespace RH_Engine
}
}
};
Console.WriteLine("route command: " + JsonConvert.SerializeObject(Payload(payload)));
//Console.WriteLine("route command: " + JsonConvert.SerializeObject(Payload(payload)));
return JsonConvert.SerializeObject(Payload(payload));
}
@@ -350,7 +352,7 @@ namespace RH_Engine
{
return RouteFollow(routeID, nodeID, speedValue, 0, "XYZ", 1, true, new float[] { 0, 0, 0 }, positionOffsetVector);
}
private string RouteFollow(string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector)
public string RouteFollow(string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector)
{
dynamic payload = new
{

View File

@@ -25,6 +25,20 @@ namespace RH_Engine
return res;
}
public static string GetIdSceneInfoChild(string msg, string nodeName)
{
dynamic jsonData = JsonConvert.DeserializeObject(msg);
Newtonsoft.Json.Linq.JArray children = jsonData.data.data.data.children;
foreach (dynamic d in children)
{
if (d.name == nodeName)
{
return d.uuid;
}
}
return null;
}
public static string GetSessionID(string msg, PC[] PCs)
{
dynamic jsonData = JsonConvert.DeserializeObject(msg);
@@ -45,6 +59,12 @@ namespace RH_Engine
return null;
}
public static bool GetStatus(string json)
{
dynamic jsonData = JsonConvert.DeserializeObject(json);
return jsonData.data.data.status == "ok";
}
public static string GetSerial(string json)
{
dynamic jsonData = JsonConvert.DeserializeObject(json);

View File

@@ -1,4 +1,5 @@
using LibNoise.Primitive;
using Microsoft.VisualBasic.FileIO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
@@ -16,7 +17,7 @@ namespace RH_Engine
//new PC("DESKTOP-M2CIH87", "Fabian"),
//new PC("T470S", "Shinichi"),
//new PC("DESKTOP-DHS478C", "semme"),
new PC("HP-ZBOOK-SEM", "Sem"),
//new PC("HP-ZBOOK-SEM", "Sem"),
//new PC("DESKTOP-TV73FKO", "Wouter"),
new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
//new PC("NA", "Bart")
@@ -25,9 +26,11 @@ namespace RH_Engine
private static ServerResponseReader serverResponseReader;
private static string sessionId = string.Empty;
private static string tunnelId = string.Empty;
private static string cameraId = string.Empty;
private static string routeId = string.Empty;
private static string panelId = string.Empty;
private static string bikeId = string.Empty;
private static string headId = string.Empty;
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
@@ -55,6 +58,7 @@ namespace RH_Engine
/// <param name="message">the response message from the server</param>
public static void HandleResponse(string message)
{
//Console.WriteLine(message);
string id = JSONParser.GetID(message);
// because the first messages don't have a serial, we need to check on the id
@@ -109,7 +113,7 @@ namespace RH_Engine
stream.Write(res);
Console.WriteLine("sent message " + message);
//Console.WriteLine("sent message " + message);
}
/// <summary>
@@ -144,23 +148,85 @@ namespace RH_Engine
{
Command mainCommand = new Command(tunnelID);
// Reset scene
WriteTextMessage(stream, mainCommand.ResetScene());
//headId = GetId("Root", stream, mainCommand);
//while (headId == string.Empty) { }
//Get sceneinfo
SendMessageAndOnResponse(stream, mainCommand.GetSceneInfoCommand("sceneinfo"), "sceneinfo",
(message) =>
{
//Console.WriteLine("\r\n\r\n\r\nscene info" + message);
cameraId = JSONParser.GetIdSceneInfoChild(message, "Camera");
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
//Force(stream, mainCommand.DeleteNode(handLeftId, "deleteHandL"), "deleteHandL", (message) => Console.WriteLine("Left hand deleted"));
//Force(stream, mainCommand.DeleteNode(handRightId, "deleteHandR"), "deleteHandR", (message) => Console.WriteLine("Right hand deleted"));
});
//Add route, bike and put camera and bike to follow route at same speed.
SendMessageAndOnResponse(stream, mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
SendMessageAndOnResponse(stream, mainCommand.AddBikeModel("bikeID"), "bikeID",
(message) =>
{
bikeId = JSONParser.GetResponseUuid(message);
SendMessageAndOnResponse(stream, mainCommand.addPanel("panelAdd", bikeId), "panelAdd",
(message) =>
{
bool speedReplied = false;
bool moveReplied = true;
panelId = JSONParser.getPanelID(message);
WriteTextMessage(stream, mainCommand.ClearPanel(panelId));
SendMessageAndOnResponse(stream, mainCommand.MoveTo(panelId, "panelMove", new float[] { 0f, 0f, 0f }, "Z", 1, 5), "panelMove",
(message) =>
{
Console.WriteLine(message);
SendMessageAndOnResponse(stream, mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed",
(message) =>
{
WriteTextMessage(stream, mainCommand.SwapPanel(panelId));
});
});
//while (!(speedReplied && moveReplied)) { }
while (cameraId == string.Empty) { }
SetFollowSpeed(5.0f, stream, mainCommand);
});
});
//Force(stream, mainCommand.addPanel("panelID", bikeId), "panelID",
// (message) =>
// {
// Console.WriteLine("panel response: " + message);
// panelId = JSONParser.GetResponseUuid(message);
// while(bikeId == string.Empty) { }
// SetFollowSpeed(5.0f, stream, mainCommand);
// });
//SendMessageAndOnResponse(stream, maincommand.addpanel("panelid", bikeid), "panelid",
// (message) =>
// {
// console.writeline("panelid: " + message);
// //panelid = jsonparser.getpanelid(message);
// panelid = jsonparser.getresponseuuid(message);
// while (bikeid == string.empty) { }
// setfollowspeed(5.0f, stream, maincommand);
// });
//WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null));
//string command;
SendMessageAndOnResponse(stream, mainCommand.AddBikeModel("bikeID"), "bikeID", (message) => bikeId = JSONParser.GetResponseUuid(message));
SendMessageAndOnResponse(stream, mainCommand.addPanel("panelID", bikeId), "panelID",
(message) =>
{
panelId = JSONParser.GetResponseUuid(message);
while (bikeId == string.Empty) { }
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, 5, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
});
Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand));
//Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand));
//command = mainCommand.AddModel("car", "data\\customModels\\TeslaRoadster.fbx");
//WriteTextMessage(stream, command);
@@ -255,6 +321,30 @@ namespace RH_Engine
return res;
}
private static void SetFollowSpeed(float speed, NetworkStream stream, Command mainCommand)
{
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, cameraId, speed));
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, panelId, speed, 0, "XYZ", 1, false, new float[] { 0, 0, 0 }, new float[] { 0f, 0f, 150f }));
}
//string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector)
private static void Force(NetworkStream stream, string message, string serial, HandleSerial action)
{
SendMessageAndOnResponse(stream, message, serial,
(message) =>
{
if (!JSONParser.GetStatus(message))
{
serialResponses.Remove(serial);
Force(stream, message, serial,action);
} else
{
action(message);
}
}
);
}
}
/// <summary>

View File

@@ -0,0 +1,8 @@
{
"profiles": {
"RH-Engine": {
"commandName": "Project",
"nativeDebugging": true
}
}
}