From f1d0f909b6fbc92967bb2684ef30345cec80a1e0 Mon Sep 17 00:00:00 2001
From: Sylvain Buche <sylvain.buche@orange.com>
Date: Tue, 14 May 2024 16:56:49 +0200
Subject: [PATCH] WorldAnalysis interface: now a singleton, helper update to
 manage conversion between generated code and Unity data structures

---
 Runtime/Scripts/WorldAnalysisInterface.cs   |  2 +
 Runtime/Scripts/WorldAnalysisUnityHelper.cs | 56 +++++++++++++++++++--
 2 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/Runtime/Scripts/WorldAnalysisInterface.cs b/Runtime/Scripts/WorldAnalysisInterface.cs
index 163b049..24f1b3b 100644
--- a/Runtime/Scripts/WorldAnalysisInterface.cs
+++ b/Runtime/Scripts/WorldAnalysisInterface.cs
@@ -2,6 +2,8 @@ using ETSI.ARF.OpenAPI.WorldAnalysis;
 
 public interface WorldAnalysisInterface
 {
+    public static WorldAnalysisInterface Instance;
+
     #region ResponseCode
 
     /// <summary>
diff --git a/Runtime/Scripts/WorldAnalysisUnityHelper.cs b/Runtime/Scripts/WorldAnalysisUnityHelper.cs
index 2862037..65d3829 100644
--- a/Runtime/Scripts/WorldAnalysisUnityHelper.cs
+++ b/Runtime/Scripts/WorldAnalysisUnityHelper.cs
@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using UnityEngine;
 
 public class WorldAnalysisUnityHelper 
@@ -7,7 +8,7 @@ public class WorldAnalysisUnityHelper
     /// Convert a float array of length 3 to a Vector3
     /// </summary>
     /// <param name="value">the values to convert</param>
-    /// <returns></returns>
+    /// <returns>Converted Unity Vector3</returns>
     /// <exception cref="ArgumentException"></exception>
     public static Vector3 ConvertETSIVector3ToUnity(ETSI.ARF.OpenAPI.WorldAnalysis.Vector3 value)
     {
@@ -19,7 +20,7 @@ public class WorldAnalysisUnityHelper
     ///  Convert a float array of length 4 to a Quaternion
     /// </summary>
     /// <param name="value">the values to convert</param>
-    /// <returns></returns>
+    /// <returns>Converted Unity Quaternion</returns>
     /// <exception cref="ArgumentException"></exception>
     public static Quaternion ConvertETSIARFQuaternionToUnity(ETSI.ARF.OpenAPI.WorldAnalysis.Quaternion value)
     {
@@ -30,9 +31,9 @@ public class WorldAnalysisUnityHelper
     /// <summary>
     /// Convert a float array of length 16 to a Matrix
     /// </summary>
-    /// <param name="matrix"></param>
-    /// <returns></returns>
-    public static Matrix4x4 ConvertETSIARFTransform3DToUnity(ETSI.ARF.OpenAPI.WorldAnalysis.Transform3D value)
+    /// <param name="matrix">the values to convert</param>
+    /// <returns>Converted Unity Matrix</returns>
+    public static Matrix4x4 ConvertETSIARFTransform3DToUnity(ETSI.ARF.OpenAPI.WorldStorage.Transform3D value)
     {
         if (value.Count == 16)
         {
@@ -64,4 +65,49 @@ public class WorldAnalysisUnityHelper
             throw new ArgumentException("The numer of floats in the value parameter must be 16!");
         }  
     }
+
+    /// <summary>
+    /// Function to extract translation from a Matrix4x4
+    /// </summary>
+    /// <param name="matrix"></param>
+    /// <returns></returns>
+    public static Vector3 ExtractTranslationFromMatrix(Matrix4x4 matrix)
+    {
+        return matrix.GetColumn(3);
+    }
+
+    /// <summary>
+    /// Function to extract rotation from a Matrix4x4
+    /// </summary>
+    /// <param name="matrix"></param>
+    /// <returns></returns>
+    public static Quaternion ExtractRotationFromMatrix(Matrix4x4 matrix)
+    {
+        // Convert the matrix to a Quaternion
+        return Quaternion.LookRotation(matrix.GetColumn(2), matrix.GetColumn(1));
+    }
+
+}
+
+namespace ETSI.ARF.OpenAPI.WorldAnalysis
+ {
+    /// <summary>
+    /// Override generated Vector3 constructor
+    /// </summary>
+    public partial class Vector3 : System.Collections.ObjectModel.Collection<float>
+    {
+        public Vector3(float x, float y, float z) : base(new List<float> { x, y, z })
+        {
+        }
+    }
+
+    /// <summary>
+    /// Override generated Quaternion constructor
+    /// </summary>
+    public partial class Quaternion : System.Collections.ObjectModel.Collection<float>
+    {
+        public Quaternion(float x, float y, float z, float w) : base(new List<float> { x, y, z, w})
+        {
+        }
+    }
 }
\ No newline at end of file
-- 
GitLab