diff --git a/Runtime/Scripts/REST/AdminRequest.cs b/Runtime/Scripts/REST/AdminRequest.cs index 36492dcd1f18b91f0058778820b38febd2bb8747..cf2304bc537b86492b7cd20fb391c8f10f9fcd0a 100644 --- a/Runtime/Scripts/REST/AdminRequest.cs +++ b/Runtime/Scripts/REST/AdminRequest.cs @@ -48,7 +48,7 @@ namespace ETSI.ARF.WorldStorage.REST var httpClient = new UnityWebRequestHttpClient(ws.URI); apiClient = new WorldStorageClient(httpClient); - Debug.Log("Request Ping..."); + Debug.Log("[REST] Request Ping..."); ResponseObject ro = new ResponseObject("Request Ping", func); apiClient.GetPingAsync().ContinueWith(OnReceiveObject, ro); return ro; @@ -60,7 +60,7 @@ namespace ETSI.ARF.WorldStorage.REST var httpClient = new UnityWebRequestHttpClient(ws.URI); apiClient = new WorldStorageClient(httpClient); - Debug.Log("Request Admin..."); + Debug.Log("[REST] Request Admin..."); ResponseObject ro = new ResponseObject("Request Admin", func); apiClient.GetAdminAsync().ContinueWith(OnReceiveObject, ro); return ro; @@ -72,7 +72,7 @@ namespace ETSI.ARF.WorldStorage.REST var httpClient = new UnityWebRequestHttpClient(ws.URI); apiClient = new WorldStorageClient(httpClient); - Debug.Log("Request Version..."); + Debug.Log("[REST] Request Version..."); ResponseObject ro = new ResponseObject("Request Version", func); apiClient.GetVersionAsync().ContinueWith(OnReceiveObject, ro); return ro; diff --git a/Runtime/Scripts/REST/RequestBase.cs b/Runtime/Scripts/REST/RequestBase.cs index 4d98fb29ac916fd877b8915987b978d791ce1e95..776541f15886e6473a20d3ebbc060804f26b673a 100644 --- a/Runtime/Scripts/REST/RequestBase.cs +++ b/Runtime/Scripts/REST/RequestBase.cs @@ -49,11 +49,11 @@ namespace ETSI.ARF.WorldStorage.REST ResponseObject o = (ResponseObject)id; o.responseTime = DateTime.Now; o.result = t.Result; - Debug.Log($"Server Response = {o.result} (ID={o.transactionId}, Msg={o.message})"); + Debug.Log($"[REST] Server Response = {o.result.ToString()} (ID={o.transactionId}, Msg={o.message})"); o.callback?.Invoke(o); } - else Debug.Log("OpenAPI Timeout!"); + else Debug.Log("[REST] OpenAPI Timeout!"); } static protected void OnReceiveListOfObjects(Task> t, object id) where TObj : IModel diff --git a/Runtime/Scripts/REST/TrackableRequest.cs b/Runtime/Scripts/REST/TrackableRequest.cs index 4712c422fbefb9bafb4f4a33e11ff06674fc13c6..73f5fe34ce4c69639791eb5bba5d265fb8efa921 100644 --- a/Runtime/Scripts/REST/TrackableRequest.cs +++ b/Runtime/Scripts/REST/TrackableRequest.cs @@ -15,18 +15,16 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Last change: March 2024 +// Last change: June 2024 // -#define USING_OPENAPI_GENERATOR // alt. is Swagger - using System; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; -using ETSI.ARF.OpenAPI.WorldStorage; using ETSI.ARF.OpenAPI; +using ETSI.ARF.OpenAPI.WorldStorage; namespace ETSI.ARF.WorldStorage.REST { @@ -41,7 +39,7 @@ namespace ETSI.ARF.WorldStorage.REST var httpClient = new UnityWebRequestHttpClient(ws.URI); apiClient = new WorldStorageClient(httpClient); - Debug.Log("Request 1 Trackable..."); + Debug.Log("[REST] Request 1 Trackable..."); ResponseObject ro = new ResponseObject("Request Trackable " + UUID.ToString(), func); apiClient.GetTrackableByIdAsync(token, UUID, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); return ro; @@ -53,7 +51,7 @@ namespace ETSI.ARF.WorldStorage.REST var httpClient = new UnityWebRequestHttpClient(ws.URI); apiClient = new WorldStorageClient(httpClient); - Debug.Log("Request Trackables..."); + Debug.Log("[REST] Request Trackables..."); ResponseObject> ro = new ResponseObject>("Request Trackables", func); apiClient.GetTrackablesAsync(token, ro.cancellationToken).ContinueWith(OnReceiveListOfObjects, ro); return ro; @@ -65,7 +63,7 @@ namespace ETSI.ARF.WorldStorage.REST var httpClient = new UnityWebRequestHttpClient(ws.URI); apiClient = new WorldStorageClient(httpClient); - Debug.Log("Create 1 Trackable..."); + Debug.Log("[REST] Create 1 Trackable..."); // Add some management stuffs trackable.UUID = Guid.NewGuid(); @@ -82,7 +80,7 @@ namespace ETSI.ARF.WorldStorage.REST var httpClient = new UnityWebRequestHttpClient(ws.URI); apiClient = new WorldStorageClient(httpClient); - Debug.Log("Update Trackable..."); + Debug.Log("[REST] Update Trackable..."); ResponseObject ro = new ResponseObject("Update Trackable " + trackable.UUID.ToString(), func); apiClient.ModifyTrackableAsync(token, trackable,ro.cancellationToken).ContinueWith(OnReceiveObject, ro); return ro; @@ -93,7 +91,7 @@ namespace ETSI.ARF.WorldStorage.REST var httpClient = new UnityWebRequestHttpClient(ws.URI); apiClient = new WorldStorageClient(httpClient); - Debug.Log("Delete 1 Trackable..."); + Debug.Log("[REST] Delete 1 Trackable..."); ResponseObject ro = new ResponseObject("Delete Trackable " + UUID.ToString(), func); apiClient.DeleteTrackableAsync(token, UUID, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); return ro; diff --git a/Runtime/Scripts/REST/WorldAnchorRequest.cs b/Runtime/Scripts/REST/WorldAnchorRequest.cs index db10a3856062fc4789370725cd0f1bb9a8c754d6..7ed14187f0dc6285f1475245e1a737a0bc437eac 100644 --- a/Runtime/Scripts/REST/WorldAnchorRequest.cs +++ b/Runtime/Scripts/REST/WorldAnchorRequest.cs @@ -18,55 +18,85 @@ // Last change: March 2024 // +using System; using System.Collections.Generic; +using System.Threading.Tasks; using UnityEngine; +using ETSI.ARF.OpenAPI; using ETSI.ARF.OpenAPI.WorldStorage; //#if UNITY_EDITOR namespace ETSI.ARF.WorldStorage.REST { - public class WorldAnchorRequest + public class WorldAnchorRequest : RequestBase { - //static public string AddWorldAnchor(WorldStorageServer ws, WorldAnchor anchor) - //{ - // Debug.Log("Posting Add World Anchor to Server"); - // WorldAnchorsApi api = new WorldAnchorsApi(ws.URI); - // string result = api.AddWorldAnchor(anchor); - // Debug.Log(result); - // return result; - //} + // + // Wrapper for the endpoints + // + static public ResponseObject GetWorldAnchorAsync(WorldStorageServer ws, Guid UUID, Action> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); - //static public string UpdateWorldAnchor(WorldStorageServer ws, WorldAnchor anchor) - //{ - // Debug.Log("Posting Add World Anchor to Server"); - // WorldAnchorsApi api = new WorldAnchorsApi(ws.URI); - // string result = api.ModifyWorldAnchor(anchor); - // Debug.Log(result); - // return result; - //} + Debug.Log("[REST] Request 1 WorldAnchor..."); + ResponseObject ro = new ResponseObject("Request WorldAnchor " + UUID.ToString(), func); + apiClient.GetWorldAnchorByIdAsync(token, UUID, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); + return ro; + } - //static public List GetAllWorldAnchors(WorldStorageServer ws) - //{ - // WorldAnchorsApi api = new WorldAnchorsApi(ws.URI); - // List result = api.GetWorldAnchors(); - // return result; - //} + static public ResponseObject> GetWorldAnchorsAsync(WorldStorageServer ws, Action>> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); - //static public WorldAnchor GetWorldAnchor(WorldStorageServer ws, string uuid) - //{ - // System.Guid _uuid = System.Guid.Parse(uuid); - // WorldAnchorsApi api = new WorldAnchorsApi(ws.URI); - // WorldAnchor result = api.GetWorldAnchorById(_uuid); - // return result; - //} + Debug.Log("[REST] Request WorldAnchors..."); + ResponseObject> ro = new ResponseObject>("Request WorldAnchors", func); + apiClient.GetWorldAnchorsAsync(token, ro.cancellationToken).ContinueWith(OnReceiveListOfObjects, ro); + return ro; + } - //static public void DeleteWorldAnchor(WorldStorageServer ws, string uuid) - //{ - // System.Guid _uuid = System.Guid.Parse(uuid); - // WorldAnchorsApi api = new WorldAnchorsApi(ws.URI); - // api.DeleteWorldAnchor(_uuid); - //} + static public ResponseObject CreateWorldAnchorAsync(WorldStorageServer ws, WorldAnchor worldAnchor, Action> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); + + Debug.Log("[REST] Create 1 WorldAnchor..."); + + // Add some management stuffs + worldAnchor.UUID = Guid.NewGuid(); + worldAnchor.CreatorUUID = Guid.Empty; + + ResponseObject ro = new ResponseObject("Create WorldAnchor " + worldAnchor.Name + " (no UUID)", func); + apiClient.AddWorldAnchorAsync(token, worldAnchor, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); + return ro; + } + + static public ResponseObject UpdateWorldAnchorAsync(WorldStorageServer ws, WorldAnchor worldAnchor, Action> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); + + Debug.Log("[REST] Update WorldAnchor..."); + ResponseObject ro = new ResponseObject("Update WorldAnchor " + worldAnchor.UUID.ToString(), func); + apiClient.ModifyWorldAnchorAsync(token, worldAnchor, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); + return ro; + } + static public ResponseObject DeleteWorldAnchorAsync(WorldStorageServer ws, Guid UUID, Action> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); + + Debug.Log("[REST] Delete 1 WorldAnchor..."); + ResponseObject ro = new ResponseObject("Delete WorldAnchor " + UUID.ToString(), func); + apiClient.DeleteWorldAnchorAsync(token, UUID, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); + return ro; + } } } //#endif \ No newline at end of file diff --git a/Runtime/Scripts/REST/WorldLinkRequest.cs b/Runtime/Scripts/REST/WorldLinkRequest.cs index 07a6c3fabd361c810a591138de64ddeb85b4b69c..2ea9ef3f2fb1019a9af862fcc2ddc31bed6fc979 100644 --- a/Runtime/Scripts/REST/WorldLinkRequest.cs +++ b/Runtime/Scripts/REST/WorldLinkRequest.cs @@ -15,58 +15,87 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Last change: March 2024 +// Last change: June 2024 // +using System; using System.Collections.Generic; +using System.Threading.Tasks; using UnityEngine; +using ETSI.ARF.OpenAPI; using ETSI.ARF.OpenAPI.WorldStorage; -//#if UNITY_EDITOR namespace ETSI.ARF.WorldStorage.REST { - public class WorldLinkRequest + public class WorldLinkRequest : RequestBase { - //static public string AddWorldLink(WorldStorageServer ws, WorldLink link) - //{ - // Debug.Log("Posting Add Trackable to Server"); - // WorldLinksApi api = new WorldLinksApi(ws.URI); - // string result = api.AddWorldLink(link); - // Debug.Log(result); - // return result; - //} + // + // Wrapper for the endpoints + // + static public ResponseObject GetWorldLinkAsync(WorldStorageServer ws, Guid UUID, Action> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); - //static public string UpdateWorldLink(WorldStorageServer ws, WorldLink link) - //{ - // Debug.Log("Posting Add Trackable to Server"); - // WorldLinksApi api = new WorldLinksApi(ws.URI); - // string result = api.ModifyWorldLink(link); - // Debug.Log(result); - // return result; - //} + Debug.Log("[REST] Request 1 WorldLink..."); + ResponseObject ro = new ResponseObject("Request WorldLink " + UUID.ToString(), func); + apiClient.GetWorldLinkByIdAsync(token, UUID, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); + return ro; + } - //static public List GetAllWorldLinks(WorldStorageServer ws) - //{ - // WorldLinksApi api = new WorldLinksApi(ws.URI); - // List result = api.GetWorldLinks(); - // return result; - //} + static public ResponseObject> GetWorldLinksAsync(WorldStorageServer ws, Action>> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); - //static public WorldLink GetWorldLink(WorldStorageServer ws, string uuid) - //{ - // System.Guid _uuid = System.Guid.Parse(uuid); - // WorldLinksApi api = new WorldLinksApi(ws.URI); - // WorldLink result = api.GetWorldLinkById(_uuid); - // return result; - //} + Debug.Log("[REST] Request WorldLinks..."); + ResponseObject> ro = new ResponseObject>("Request WorldLinks", func); + apiClient.GetWorldLinksAsync(token, ro.cancellationToken).ContinueWith(OnReceiveListOfObjects, ro); + return ro; + } - //static public void DeleteWorldLink(WorldStorageServer ws, string uuid) - //{ - // System.Guid _uuid = System.Guid.Parse(uuid); - // WorldLinksApi api = new WorldLinksApi(ws.URI); - // api.DeleteWorldLink(_uuid); - //} + static public ResponseObject CreateWorldLinkAsync(WorldStorageServer ws, WorldLink worldLink, Action> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); + + Debug.Log("[REST] Create 1 WorldLink..."); + + // Add some management stuffs + worldLink.UUID = Guid.NewGuid(); + worldLink.CreatorUUID = Guid.Empty; + + ResponseObject ro = new ResponseObject("Create WorldLink (no UUID)", func); + apiClient.AddWorldLinkAsync(token, worldLink, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); + return ro; + } + + static public ResponseObject UpdateWorldLinkAsync(WorldStorageServer ws, WorldLink worldLink, Action> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); + + Debug.Log("[REST] Update WorldLink..."); + ResponseObject ro = new ResponseObject("Update WorldLink " + worldLink.UUID.ToString(), func); + apiClient.ModifyWorldLinkAsync(token, worldLink, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); + return ro; + } + static public ResponseObject DeleteWorldLinkAsync(WorldStorageServer ws, Guid UUID, Action> func) + { + wsServer = ws; + var httpClient = new UnityWebRequestHttpClient(ws.URI); + apiClient = new WorldStorageClient(httpClient); + + Debug.Log("[REST] Delete 1 WorldLink..."); + ResponseObject ro = new ResponseObject("Delete WorldLink " + UUID.ToString(), func); + apiClient.DeleteWorldLinkAsync(token, UUID, ro.cancellationToken).ContinueWith(OnReceiveObject, ro); + return ro; + } } } //#endif \ No newline at end of file diff --git a/Runtime/Scripts/WorldStorageUnityHelper.cs b/Runtime/Scripts/WorldStorageUnityHelper.cs index 0a5478e3e31787ace1d7c541380cd4cece64adfd..30cc44bf6f191df13c4091b4b34dbe123cca07d4 100644 --- a/Runtime/Scripts/WorldStorageUnityHelper.cs +++ b/Runtime/Scripts/WorldStorageUnityHelper.cs @@ -22,4 +22,52 @@ public class WorldStorageUnityHelper }; return result; } + + /// + /// Convert a float array of length 16 to a Matrix + /// + /// the values to convert + /// Converted Unity Matrix + public static Matrix4x4 ConvertETSIARFTransform3DToUnity(ETSI.ARF.OpenAPI.WorldStorage.Transform3D value) + { + if (value.Count == 16) + { + Matrix4x4 resul = new Matrix4x4(); + resul[0, 0] = value[0]; + resul[0, 1] = value[1]; + resul[0, 2] = value[2]; + resul[0, 3] = value[3]; + + resul[1, 0] = value[4]; + resul[1, 1] = value[5]; + resul[1, 2] = value[6]; + resul[1, 3] = value[7]; + + resul[2, 0] = value[8]; + resul[2, 1] = value[9]; + resul[2, 2] = value[10]; + resul[2, 3] = value[11]; + + resul[3, 0] = value[12]; + resul[3, 1] = value[13]; + resul[3, 2] = value[14]; + resul[3, 3] = value[15]; + + return resul; + } + else + { + throw new ArgumentException("The numer of floats in the value parameter must be 16!"); + } + } + + static public Matrix4x4 MatrixFromLocalCRS(List value) + { + Matrix4x4 result = new Matrix4x4(); + result.m00 = value[0]; result.m01 = value[1]; result.m02 = value[2]; result.m03 = value[3]; + result.m10 = value[4]; result.m11 = value[5]; result.m12 = value[6]; result.m13 = value[7]; + result.m20 = value[8]; result.m21 = value[9]; result.m22 = value[10]; result.m23 = value[11]; + result.m30 = value[12]; result.m31 = value[13]; result.m32 = value[14]; result.m33 = value[15]; + return result; + } }