From 568896c28db73c7892c35de422b8d1ba006edf6d Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 14 Oct 2020 12:21:53 +0200 Subject: [PATCH] fully added the vr engine stuff to the client app --- ClientApp/Utils/EngineConnection.cs | 82 ++++++++++++++++++++++++++++- RH-Engine/JSONParser.cs | 15 ++++++ RH-Engine/Program.cs | 4 +- 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/ClientApp/Utils/EngineConnection.cs b/ClientApp/Utils/EngineConnection.cs index bc7781f..80b1822 100644 --- a/ClientApp/Utils/EngineConnection.cs +++ b/ClientApp/Utils/EngineConnection.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Text; using RH_Engine; using System.Net.Sockets; +using Newtonsoft.Json.Linq; +using System.Diagnostics; +using LibNoise.Primitive; namespace ClientApp.Utils { @@ -37,6 +40,8 @@ namespace ClientApp.Utils private static string panelId = string.Empty; private static string bikeId = string.Empty; private static string headId = string.Empty; + private static string groundPlaneId = string.Empty; + private static string terrainId = string.Empty; public float BikeSpeed { get; set; } public float BikePower { get; set; } @@ -191,8 +196,11 @@ namespace ClientApp.Utils string headId = JSONParser.GetIdSceneInfoChild(message, "Head"); string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand"); string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand"); + groundPlaneId = JSONParser.GetIdSceneInfoChild(message, "GroundPlane"); + Write("--- Ground plane id is " + groundPlaneId); }); // add the route and set the route id + CreateTerrain(); SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message)); } @@ -217,8 +225,45 @@ namespace ClientApp.Utils while (cameraId == string.Empty) { } SetFollowSpeed(5.0f); + WriteTextMessage(mainCommand.RoadCommand(routeId, "road")); + WriteTextMessage(mainCommand.ShowRoute("showRouteFalse", false)); }); }); + setEnvironment(); + + + } + + private void setEnvironment() + { + Write("Setting environment"); + WriteTextMessage(mainCommand.DeleteNode(groundPlaneId, "none")); + + PlaceHouses(mainCommand); + + WriteTextMessage(mainCommand.SkyboxCommand(DateTime.Now.Hour)); + } + + private void PlaceHouses(Command mainCommand) + { + PlaceHouse(mainCommand, 2, new float[] { 10f, 1f, 30f }, 1); + PlaceHouse(mainCommand, 1, new float[] { 42f, 1f, 22f }, new float[] { 0f, 90f, 0f }, 2); + PlaceHouse(mainCommand, 11, new float[] { -20f, 1f, 0f }, new float[] { 0f, -35f, 0f }, 3); + PlaceHouse(mainCommand, 7, new float[] { -15f, 1f, 50f }, new float[] { 0f, -50f, 0f }, 4); + PlaceHouse(mainCommand, 24, new float[] { 40f, 1f, 40f }, new float[] { 0f, 75f, 0f }, 5); + PlaceHouse(mainCommand, 22, new float[] { 34f, 1f, -20f }, 6); + PlaceHouse(mainCommand, 14, new float[] { 0f, 1f, -20f }, new float[] { 0f, 210f, 0f }, 7); + } + + private void PlaceHouse(Command mainCommand, int numberHousemodel, float[] position, int serialNumber) + { + PlaceHouse(mainCommand, numberHousemodel, position, new float[] { 0f, 0f, 0f }, serialNumber); + } + + private void PlaceHouse(Command mainCommand, int numberHousemodel, float[] position, float[] rotation, int serialNumber) + { + string folderHouses = @"data\NetworkEngine\models\houses\set1\"; + SendMessageAndOnResponse(mainCommand.AddModel("House1", "housePlacement" + serialNumber, folderHouses + "house" + numberHousemodel + ".obj", position, 4, rotation), "housePlacement" + serialNumber, (message) => Console.WriteLine(message)); } public void UpdateInfoPanel() @@ -264,6 +309,41 @@ namespace ClientApp.Utils WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed)); } + public void CreateTerrain() + { + float x = 0f; + float[] height = new float[256 * 256]; + ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best); + for (int i = 0; i < 256 * 256; i++) + { + height[i] = improvedPerlin.GetValue(x / 10, x / 10, x * 100) / 3.5f + 1; + + if (height[i] > 1.1f) + { + height[i] = height[i] * 0.8f; + } + else if (height[i] < 0.9f) + { + height[i] = height[i] * 1.2f; + } + x += 0.001f; + } + + SendMessageAndOnResponse(mainCommand.TerrainAdd(new int[] { 256, 256 }, height, "terrain"), "terrain", + (message) => + { + + SendMessageAndOnResponse(mainCommand.renderTerrain("renderTerrain"), "renderTerrain", + (message) => + { + terrainId = JSONParser.GetTerrainID(message); + string addLayerMsg = mainCommand.AddLayer(terrainId, "addLayer"); + SendMessageAndOnResponse(addLayerMsg, "addLayer", (message) => Console.WriteLine("")); + + }); + }); + } + #endregion #region message send/receive @@ -315,7 +395,7 @@ namespace ClientApp.Utils } public void Write(string msg) { - Console.WriteLine("[ENGINECONNECT] " + msg); + Debug.WriteLine("[ENGINECONNECT] " + msg); } } diff --git a/RH-Engine/JSONParser.cs b/RH-Engine/JSONParser.cs index 19bf695..30d750a 100644 --- a/RH-Engine/JSONParser.cs +++ b/RH-Engine/JSONParser.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; namespace RH_Engine @@ -122,5 +123,19 @@ namespace RH_Engine } return null; } + + public static string GetChildUuid(string name, JArray children) + { + foreach (dynamic child in children) + { + if (child.name == name) + { + return child.uuid; + } + } + Console.WriteLine("Could not find id of " + name); + return null; + } + } } \ No newline at end of file diff --git a/RH-Engine/Program.cs b/RH-Engine/Program.cs index 4df6e5e..5eba099 100644 --- a/RH-Engine/Program.cs +++ b/RH-Engine/Program.cs @@ -19,9 +19,9 @@ 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("DESKTOP-SINMKT1", "Ralf van Aert"), //new PC("NA", "Bart") };