clean and comment
This commit is contained in:
@@ -1,329 +0,0 @@
|
|||||||
using LibNoise.Primitive;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace RH_Engine
|
|
||||||
{
|
|
||||||
class CreateGraphics
|
|
||||||
{
|
|
||||||
public const string STANDARD_HEAD = "Head";
|
|
||||||
public const string STANDARD_GROUND = "GroundPlane";
|
|
||||||
public const string STANDARD_SUN = "SunLight";
|
|
||||||
public const string STANDARD_LEFTHAND = "LeftHand";
|
|
||||||
public const string STANDARD_RIGHTHAND = "RightHand";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string tunnelID;
|
|
||||||
|
|
||||||
public CreateGraphics(string tunnelID)
|
|
||||||
{
|
|
||||||
this.tunnelID = tunnelID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string TerrainCommand(int[] sizeArray, float[] heightsArray)
|
|
||||||
{
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/terrain/add",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
size = sizeArray,
|
|
||||||
heights = heightsArray
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
public string AddLayer(string uid, string texture)
|
|
||||||
{
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/node/addlayer",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
id = uid,
|
|
||||||
diffuse = @"C:\Users\woute\Downloads\NetworkEngine.18.10.10.1\NetworkEngine\data\NetworkEngine\textures\terrain\adesert_cracks_d.jpg",
|
|
||||||
normal = @"C:\Users\woute\Downloads\NetworkEngine.18.10.10.1\NetworkEngine\data\NetworkEngine\textures\terrain\adesert_mntn_d.jpg",
|
|
||||||
minHeight = 0,
|
|
||||||
maxHeight = 10,
|
|
||||||
fadeDist = 1
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
public string UpdateTerrain()
|
|
||||||
{
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/terrain/update",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
public string AddNodeCommand()
|
|
||||||
{
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/node/add",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
name = "newNode",
|
|
||||||
components = new
|
|
||||||
{
|
|
||||||
terrain = new
|
|
||||||
{
|
|
||||||
smoothnormals = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DeleteNode(string uuid)
|
|
||||||
{
|
|
||||||
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/node/delete",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
id = uuid,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public string AddBikeModel()
|
|
||||||
{
|
|
||||||
return AddModel("bike", "data\\NetworkEngine\\models\\bike\\bike.fbx");
|
|
||||||
}
|
|
||||||
|
|
||||||
public string AddModel(string nodeName, string fileLocation)
|
|
||||||
{
|
|
||||||
return AddModel(nodeName, fileLocation, null, new float[] { 0, 0, 0 }, 1, new float[] { 0, 0, 0 });
|
|
||||||
}
|
|
||||||
|
|
||||||
public string AddModel(string nodeName, string fileLocation, float[] positionVector, float scalar, float[] rotationVector)
|
|
||||||
{
|
|
||||||
return AddModel(nodeName, fileLocation, null, positionVector, scalar, rotationVector);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string AddModel(string nodeName, string fileLocation, string animationLocation, float[] positionVector, float scalar, float[] rotationVector)
|
|
||||||
{
|
|
||||||
string namename = nodeName;
|
|
||||||
bool animatedBool = false;
|
|
||||||
if (animationLocation != null)
|
|
||||||
{
|
|
||||||
animatedBool = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/node/add",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
name = namename,
|
|
||||||
components = new
|
|
||||||
{
|
|
||||||
transform = new
|
|
||||||
{
|
|
||||||
position = positionVector,
|
|
||||||
scale = scalar,
|
|
||||||
rotation = rotationVector
|
|
||||||
|
|
||||||
},
|
|
||||||
model = new
|
|
||||||
{
|
|
||||||
file = fileLocation,
|
|
||||||
cullbackfaces = true,
|
|
||||||
animated = animatedBool,
|
|
||||||
animation = animationLocation
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
public string MoveTo(string uuid, float[] positionVector, float rotateValue, float speedValue, float timeValue)
|
|
||||||
{
|
|
||||||
return MoveTo(uuid, "idk", 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)
|
|
||||||
{
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/node/moveto",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
id = uuid,
|
|
||||||
stop = stopValue,
|
|
||||||
position = positionVector,
|
|
||||||
rotate = rotateValue,
|
|
||||||
interpolate = interpolateValue,
|
|
||||||
followheight = followHeightValue,
|
|
||||||
speed = speedValue,
|
|
||||||
time = timeValue
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public string RouteCommand()
|
|
||||||
{
|
|
||||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(4325, LibNoise.NoiseQuality.Best);
|
|
||||||
Random r = new Random();
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "route/add",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
nodes = new dynamic[]
|
|
||||||
{
|
|
||||||
new
|
|
||||||
{
|
|
||||||
/*pos = GetPos(0.6f, improvedPerlin)*/
|
|
||||||
pos = new int[] {0,0,5 },
|
|
||||||
dir = new int[] { r.Next(20,100),0,-r.Next(20, 100) }
|
|
||||||
},
|
|
||||||
new
|
|
||||||
{
|
|
||||||
//pos = GetPos(1.6f, improvedPerlin),
|
|
||||||
pos = new int[] {50,0,0 },
|
|
||||||
dir = new int[] { r.Next(20, 100),0,r.Next(20, 100) }
|
|
||||||
},
|
|
||||||
new
|
|
||||||
{
|
|
||||||
//pos = GetPos(2.654f, improvedPerlin),
|
|
||||||
pos = new int[] {20,0,20 },
|
|
||||||
dir = new int[] { r.Next(20, 100),0,r.Next(20, 100) }
|
|
||||||
},
|
|
||||||
new
|
|
||||||
{
|
|
||||||
//pos = GetPos(3.6543f, improvedPerlin),
|
|
||||||
pos = new int[] {10,0,50 },
|
|
||||||
dir = new int[] { -r.Next(3,7),0,r.Next(3,7) }
|
|
||||||
},
|
|
||||||
new
|
|
||||||
{
|
|
||||||
pos = new int[] {0,0,50 },
|
|
||||||
dir = new int[] { -r.Next(20, 50),0,-r.Next(20, 50) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Console.WriteLine("route command: " + JsonConvert.SerializeObject(Payload(payload)));
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
private float[] GetPos(float n, ImprovedPerlin improvedPerlin)
|
|
||||||
{
|
|
||||||
float[] res = new float[] { improvedPerlin.GetValue(n) * 50, 0, improvedPerlin.GetValue(n) * 50 };
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int[] GetDir()
|
|
||||||
{
|
|
||||||
Random rng = new Random();
|
|
||||||
int[] dir = {rng.Next(50), 0, rng.Next(50)};
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string FollowRouteCommand()
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string RoadCommand(string uuid_route)
|
|
||||||
{
|
|
||||||
Console.WriteLine("road");
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/road/add",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
route = uuid_route,
|
|
||||||
diffuse = "data/NetworkEngine/textures/tarmac_diffuse.png",
|
|
||||||
normal = "data/NetworkEngine/textures/tarmac_normale.png",
|
|
||||||
specular = "data/NetworkEngine/textures/tarmac_specular.png",
|
|
||||||
heightoffset = 1f
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetSceneInfoCommand()
|
|
||||||
{
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/get"
|
|
||||||
};
|
|
||||||
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ResetScene()
|
|
||||||
{
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/reset"
|
|
||||||
};
|
|
||||||
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
public string SkyboxCommand(double timeToSet)
|
|
||||||
{
|
|
||||||
if (timeToSet < 0 || timeToSet > 24)
|
|
||||||
{
|
|
||||||
throw new Exception("The time must be between 0 and 24!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
dynamic payload = new
|
|
||||||
{
|
|
||||||
id = "scene/skybox/settime",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
time = timeToSet
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private object Payload(dynamic message)
|
|
||||||
{
|
|
||||||
return new
|
|
||||||
{
|
|
||||||
id = "tunnel/send",
|
|
||||||
data = new
|
|
||||||
{
|
|
||||||
dest = tunnelID,
|
|
||||||
data = message,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -103,31 +103,41 @@ namespace RH_Engine
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateGraphics createGraphics = new CreateGraphics(tunnelID);
|
sendCommands(stream, tunnelID);
|
||||||
|
|
||||||
|
|
||||||
WriteTextMessage(stream, createGraphics.ResetScene());
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sends all the commands to the server
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stream">the network stream to use</param>
|
||||||
|
/// <param name="tunnelID">the tunnel id to use</param>
|
||||||
|
private static void sendCommands(NetworkStream stream, string tunnelID)
|
||||||
|
{
|
||||||
|
Command mainCommand = new Command(tunnelID);
|
||||||
|
|
||||||
|
|
||||||
|
WriteTextMessage(stream, mainCommand.ResetScene());
|
||||||
ReadPrefMessage(stream);
|
ReadPrefMessage(stream);
|
||||||
string routeid = CreateRoute(stream, createGraphics);
|
string routeid = CreateRoute(stream, mainCommand);
|
||||||
|
|
||||||
WriteTextMessage(stream, createGraphics.TerrainCommand(new int[] { 256, 256 }, null));
|
WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null));
|
||||||
Console.WriteLine(ReadPrefMessage(stream));
|
Console.WriteLine(ReadPrefMessage(stream));
|
||||||
string command;
|
string command;
|
||||||
|
|
||||||
command = createGraphics.AddBikeModel();
|
command = mainCommand.AddBikeModel();
|
||||||
|
|
||||||
WriteTextMessage(stream, command);
|
WriteTextMessage(stream, command);
|
||||||
|
|
||||||
Console.WriteLine(ReadPrefMessage(stream));
|
Console.WriteLine(ReadPrefMessage(stream));
|
||||||
|
|
||||||
command = createGraphics.AddModel("car", "data\\customModels\\TeslaRoadster.fbx");
|
command = mainCommand.AddModel("car", "data\\customModels\\TeslaRoadster.fbx");
|
||||||
|
|
||||||
WriteTextMessage(stream, command);
|
WriteTextMessage(stream, command);
|
||||||
|
|
||||||
Console.WriteLine(ReadPrefMessage(stream));
|
Console.WriteLine(ReadPrefMessage(stream));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -137,7 +147,7 @@ namespace RH_Engine
|
|||||||
/// <param name="stream">the network stream to send requests to</param>
|
/// <param name="stream">the network stream to send requests to</param>
|
||||||
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
||||||
/// <returns> the uuid of the object with the given name, <c>null</c> otherwise.</returns>
|
/// <returns> the uuid of the object with the given name, <c>null</c> otherwise.</returns>
|
||||||
public static string GetId(string name, NetworkStream stream, CreateGraphics createGraphics)
|
public static string GetId(string name, NetworkStream stream, Command createGraphics)
|
||||||
{
|
{
|
||||||
JArray children = GetChildren(stream, createGraphics);
|
JArray children = GetChildren(stream, createGraphics);
|
||||||
|
|
||||||
@@ -153,7 +163,7 @@ namespace RH_Engine
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CreateRoute(NetworkStream stream, CreateGraphics createGraphics)
|
public static string CreateRoute(NetworkStream stream, Command createGraphics)
|
||||||
{
|
{
|
||||||
WriteTextMessage(stream, createGraphics.RouteCommand());
|
WriteTextMessage(stream, createGraphics.RouteCommand());
|
||||||
dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
||||||
@@ -165,7 +175,7 @@ namespace RH_Engine
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateTerrain(NetworkStream stream, CreateGraphics createGraphics)
|
public static void CreateTerrain(NetworkStream stream, Command createGraphics)
|
||||||
{
|
{
|
||||||
float x = 0f;
|
float x = 0f;
|
||||||
float[] height = new float[256 * 256];
|
float[] height = new float[256 * 256];
|
||||||
@@ -189,7 +199,7 @@ namespace RH_Engine
|
|||||||
/// <param name="stream">the network stream to send requests to</param>
|
/// <param name="stream">the network stream to send requests to</param>
|
||||||
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
||||||
/// <returns>all the children objects in the current scene</returns>
|
/// <returns>all the children objects in the current scene</returns>
|
||||||
public static JArray GetChildren(NetworkStream stream, CreateGraphics createGraphics)
|
public static JArray GetChildren(NetworkStream stream, Command createGraphics)
|
||||||
{
|
{
|
||||||
WriteTextMessage(stream, createGraphics.GetSceneInfoCommand());
|
WriteTextMessage(stream, createGraphics.GetSceneInfoCommand());
|
||||||
dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
||||||
@@ -202,7 +212,7 @@ namespace RH_Engine
|
|||||||
/// <param name="stream">the network stream to send requests to</param>
|
/// <param name="stream">the network stream to send requests to</param>
|
||||||
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
||||||
/// <returns>an array of name-uuid tuples for each object</returns>
|
/// <returns>an array of name-uuid tuples for each object</returns>
|
||||||
public static (string, string)[] GetObjectsInScene(NetworkStream stream, CreateGraphics createGraphics)
|
public static (string, string)[] GetObjectsInScene(NetworkStream stream, Command createGraphics)
|
||||||
{
|
{
|
||||||
JArray children = GetChildren(stream, createGraphics);
|
JArray children = GetChildren(stream, createGraphics);
|
||||||
(string, string)[] res = new (string, string)[children.Count];
|
(string, string)[] res = new (string, string)[children.Count];
|
||||||
|
|||||||
Reference in New Issue
Block a user