Просмотр исходного кода

Add configuration file to set path for calibration directory dynamically

Nick Steyer 1 год назад
Родитель
Сommit
e4b13df58e

+ 4 - 3
Assembly-CSharp.csproj

@@ -148,6 +148,7 @@
     <Compile Include="Assets\StreetLight\Serialization\GameObjectConverter.cs" />
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\ToggleButton.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Utilities\ExportNavMesh.cs" />
+    <Compile Include="Assets\CalibrationRecorderBehavior.cs" />
     <Compile Include="Assets\ZED\Examples\OpenCV ArUco Detection\Scripts\Core\MarkerObject_CreateObjectsAtMarkers.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\SpatialMapping\ZEDMeshRenderer.cs" />
     <Compile Include="Assets\StreetLight\MyZED3DObjectVisualizer.cs" />
@@ -173,6 +174,7 @@
     <Compile Include="Assets\ZED\Examples\Object Detection\Scripts\BBox3DHandler.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\LoggingZEDManager.cs" />
     <Compile Include="Assets\ZED\Examples\Plane Detection\Scripts\Bunny.cs" />
+    <Compile Include="Assets\CalibrationMarkerBehavior.cs" />
     <Compile Include="Assets\ZED\Examples\Plane Detection\Scripts\Capsule.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Interactions\ZEDControllerManager.cs" />
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\RotateRing.cs" />
@@ -193,6 +195,7 @@
     <Compile Include="Assets\ZED\Examples\Drone Shooter\Scripts\Simple\LaserShot_Drone.cs" />
     <Compile Include="Assets\StreetLight\Poco\Person.cs" />
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\TempAudioObject.cs" />
+    <Compile Include="Assets\StreetLight\Poco\CalibrationPoint.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Utilities\Utils.cs" />
     <Compile Include="Assets\Logging\Poco\DetectedObject.cs" />
     <Compile Include="Assets\ZED\Examples\GreenScreen\Scripts\GarbageMatte.cs" />
@@ -208,9 +211,7 @@
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\LookAtCameraPartialAxis.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\PlaneDetection\ZEDPlaneDetectionManager.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Utilities\ZEDLogMessage.cs" />
-    <Compile Include="Assets\CalibrationMarkerBehavior.cs" />
-    <Compile Include="Assets\CalibrationRecorderBehavior.cs" />
-    <Compile Include="Assets\StreetLight\Poco\CalibrationPoint.cs" />
+    <Compile Include="Assets\StreetLight\Configuration.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="Assets\ZED\Examples\GreenScreen\Shaders\Mask_Quad.shader" />

+ 8 - 4
Assets/CalibrationRecorderBehavior.cs

@@ -1,4 +1,6 @@
+using Assets.StreetLight;
 using Assets.StreetLight.Scripts;
+using Newtonsoft.Json;
 using System;
 using System.Collections;
 using System.Collections.Concurrent;
@@ -6,6 +8,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
+using Unity.VisualScripting;
 using UnityEngine;
 
 namespace Assets
@@ -14,6 +17,7 @@ namespace Assets
     {
         PersonManager PersonManager => personManagerLazy.Value;
         Lazy<PersonManager> personManagerLazy;
+        string calibrationFileName;
 
         private void Awake()
         {
@@ -22,14 +26,14 @@ namespace Assets
 
         BlockingCollection<Action> taskQueue;
 
-        string fileName = @$"C:\Users\nick.steyer\Desktop\{DateTime.Now:yyyy-dd-M_HH-mm-ss}.csv";
 
         void Start()
         {
             taskQueue = new BlockingCollection<Action>();
-            if (!File.Exists(fileName))
+            calibrationFileName = Path.Combine(Configuration.Instance.CalibrationFilesDirectory, $"{DateTime.Now:yyyy-dd-M_HH-mm-ss}.csv");
+            if (!File.Exists(calibrationFileName))
             {
-                File.WriteAllLines(fileName, new string[] { "Time,WorldX,WorldY,WorldZ,UnityX,UnityY,UnityZ" });
+                File.WriteAllLines(calibrationFileName, new string[] { "Time,WorldX,WorldY,WorldZ,UnityX,UnityY,UnityZ" });
             }
         }
 
@@ -46,7 +50,7 @@ namespace Assets
                 var personPosition = person.WorldPosition;
                 var markerPosition = marker.transform.position;
 
-                taskQueue.Add(() => File.AppendAllLines(fileName, new string[] { FormattableString.Invariant($"{DateTime.Now:yyyy-MM-dd-HH-mm-ss-ff},{personPosition.x},{personPosition.y},{personPosition.z},{markerPosition.x},{markerPosition.y},{markerPosition.z}") }));
+                taskQueue.Add(() => File.AppendAllLines(calibrationFileName, new string[] { FormattableString.Invariant($"{DateTime.Now:yyyy-MM-dd-HH-mm-ss-ff},{personPosition.x},{personPosition.y},{personPosition.z},{markerPosition.x},{markerPosition.y},{markerPosition.z}") }));
                 Task.Run(() => taskQueue.Take().Invoke());
             }
         }

+ 1 - 0
Assets/StreamingAssets/Configuration.json

@@ -0,0 +1 @@
+{"CalibrationFilesDirectory":"C:\\Users\\nick.steyer\\SmartStreetLight\\Calibration"}

+ 7 - 0
Assets/StreamingAssets/Configuration.json.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 472ae3cdca295fa4a80a9fe1eca99d1c
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 18 - 0
Assets/StreetLight/Configuration.cs

@@ -0,0 +1,18 @@
+using Newtonsoft.Json;
+using System;
+using System.IO;
+using UnityEngine;
+
+namespace Assets.StreetLight
+{
+    public sealed class Configuration
+    {
+        public string CalibrationFilesDirectory { get; set; }
+
+        private static readonly Lazy<Configuration> lazy = new(() => JsonConvert.DeserializeObject<Configuration>(File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "Configuration.json"))));
+
+        public static Configuration Instance => lazy.Value;
+
+        private Configuration() { }
+    }
+}

+ 11 - 0
Assets/StreetLight/Configuration.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f68979c239443944cb4651c66e078957
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: