Commit 29a370a8 authored by Jérémy Lacoche's avatar Jérémy Lacoche
Browse files

Add helper for managing conversions between generated code and Unity, add interface for REST

parent 31ac04a4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1713,7 +1713,7 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis
        /// The pose value
        /// </summary>
        [Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public MatrixPoseValue Value { get; set; }
        public PoseValue Value { get; set; }

        /// <summary>
        /// The URL to use for subscription (if available), see [/pose/subscriptions]
+0 −2
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@ using ETSI.ARF.OpenAPI.WorldAnalysis;

public interface WorldAnalysisInterface
{
    public static WorldAnalysisInterface Instance;

    #region ResponseCode

    /// <summary>
+101 −0
Original line number Diff line number Diff line
using UnityEngine;
using ETSI.ARF.OpenAPI.WorldAnalysis;
using static WorldAnalysisInterface;

//Implementation of the WorldAnalysis interface
public class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
{

    #region Unity_Methods

    /// <summary>
    /// Unity Awake Method
    /// </summary>
    protected void Awake()
    {
    }

    /// <summary>
    /// Unity Start Method
    /// </summary>
    protected void Start()
    {
    }

    /// <summary>
    /// Unity Update Method
    /// </summary>
    protected void Update()
    {
    }

    #endregion


    #region ARF_API

    public  AskFrameRateResult SetPoseEstimationFramerate(string token, PoseConfigurationTrackableType type, EncodingInformationStructure encodingInformation, int minimumFramerate)
    {
        return AskFrameRateResult.NOT_SUPPORTED; ///We cannot set any framerate for tracking on ARKit and ARCore
    }

    public PoseEstimationResult GetLastPose(string token, string uuid, Mode_WorldAnalysis mode, out ETSI.ARF.OpenAPI.WorldAnalysis.Pose pose)
    {
        pose = null;
        return PoseEstimationResult.OK;
    }


    public PoseEstimationResult[] GetLastPoses(string token, string[] uuids, Mode_WorldAnalysis [] modes, out ETSI.ARF.OpenAPI.WorldAnalysis.Pose[] poses)
    {
        poses = null;
        return null;
    }

    public InformationSubscriptionResult SubscribeToPose(string token, string uuid, Mode_WorldAnalysis mode, PoseCallback callback, ref int validity, out string subscriptionUUID)
    {
        subscriptionUUID = "";
        return InformationSubscriptionResult.OK;
    }

    public InformationSubscriptionResult[] SubscribeToPoses(string token, string[] uuids, Mode_WorldAnalysis [] modes, PoseCallback callback, ref int validity, out string[] subscriptionUUIDs)
    {
        subscriptionUUIDs = null;
        return null;
    }

    public InformationSubscriptionResult GetSubsription(string token, string subscriptionUUID, out PoseCallback callback, out string target, out Mode_WorldAnalysis mode, out int validity)
    {
        callback = null;
        target = "";
        mode = Mode_WorldAnalysis.TRACKABLES_TO_DEVICE;
        validity = 0;
        return InformationSubscriptionResult.OK;
    }

    public InformationSubscriptionResult UpdateSubscription(string token, string subscriptionUUID, Mode_WorldAnalysis mode, int validity, PoseCallback callback)
    {
        return InformationSubscriptionResult.OK;
    }

    public InformationSubscriptionResult UnSubscribeToPose(string subscriptionUUID)
    {
        return InformationSubscriptionResult.OK;
    }

    public CapabilityResult GetCapabilities(string token, out Capability[] capabilities)
    {
        capabilities = null;
        return CapabilityResult.OK;
    }

    public CapabilityResult GetCapability(string token, string uuid, out bool isSupported, out TypeWorldStorage type, out Capability capability)
    {
        isSupported = false;
        type = TypeWorldStorage.UNKNOWN;
        capability = null;
        return CapabilityResult.OK;
    }

    #endregion
}
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
fileFormatVersion: 2
guid: b0885b8471e62a34599778bb8e199c52
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 
+67 −0
Original line number Diff line number Diff line
using System;
using UnityEngine;

public class WorldAnalysisUnityHelper 
{
    /// <summary>
    /// Convert a float array of length 3 to a Vector3
    /// </summary>
    /// <param name="value">the values to convert</param>
    /// <returns></returns>
    /// <exception cref="ArgumentException"></exception>
    public static Vector3 ConvertETSIVector3ToUnity(ETSI.ARF.OpenAPI.WorldAnalysis.Vector3 value)
    {
        if (value.Count == 3) return new Vector3(value[0], value[1], value[2]);
        throw new ArgumentException("The numer of floats in the value parameter must be 3!");
    }

    /// <summary>
    ///  Convert a float array of length 4 to a Quaternion
    /// </summary>
    /// <param name="value">the values to convert</param>
    /// <returns></returns>
    /// <exception cref="ArgumentException"></exception>
    public static Quaternion ConvertETSIARFQuaternionToUnity(ETSI.ARF.OpenAPI.WorldAnalysis.Quaternion value)
    {
        if (value.Count == 4) return new Quaternion(value[0], value[1], value[2], value[3]);
        throw new ArgumentException("The numer of floats in the value parameter must be 4!");
    }

    /// <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)
    {
        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!");
        }  
    }
}
 No newline at end of file
Loading