using System; using System.Runtime.InteropServices; using Rokid.UXR.Utility; using UnityEngine; namespace Rokid.UXR.Native { public partial class NativeInterface { public partial class NativeAPI { /// /// Init gesture /// public static void InitGesture() { if (Utils.IsAndroidPlatfrom()) NativeInterface.NativeAPI.openGestureTracker(); } /// /// Relese gesture /// public static void ReleaseGesure() { if (Utils.IsAndroidPlatfrom()) NativeInterface.NativeAPI.closeGestureTracker(); } /// /// Retrieve the number of tracked hand vertices. /// /// public static int GetTrackingHandVertsNum() { if (Utils.IsAndroidPlatfrom()) return getTrackingHandVertsNum(); return 0; } /// /// Retrieve the number of tracked skeletons. /// /// public static int GetTrackingHandSkeletonNum() { if (Utils.IsAndroidPlatfrom()) return getTrackingHandSkeletonNum(); return 0; } /// /// Retrieve the number of tracked hands. /// /// public static int GetTrackingHandNum() { if (Utils.IsAndroidPlatfrom()) return getTrackingHandNum(); return 0; } /// /// Retrieve the type of tracked hands /// /// hand index /// 0:lefthand 1:righthand public static int GetTrackingHandLrHand(int index) { if (Utils.IsAndroidPlatfrom()) return getTrackingHandLrHand(index); return 0; } /// /// Retrieve the type of tracked gestures. /// /// /// public static int GetTrackingGestureType(int index) { if (Utils.IsAndroidPlatfrom()) return getTrackingGestureType(index); return 0; } /// /// Retrieve the type of tracked gestures. /// When there is a conflict between "grip" and "pinch" in the combine type, prioritize selecting "grip." /// /// /// public static int GetTrackingHandCombineGestureType(int index) { if (Utils.IsAndroidPlatfrom()) return getTrackingHandCombineGestureType(index); return 0; } /// /// Retrieve the skeleton information in camera space. /// /// /// public static void GetTrackingHandSkeletonCAM(float[] skeletonCAM, int index) { if (Utils.IsAndroidPlatfrom()) getTrackingHandSkeletonCAM(skeletonCAM, index); } /// /// Retrieve the skeleton information in NDC (Normalized Device Coordinates) space. /// /// /// public static void GetTrackingHandSkeletonNDC(float[] skeletonNDC, int index) { if (Utils.IsAndroidPlatfrom()) getTrackingHandSkeletonNDC(skeletonNDC, index); } /// /// Retrieve the mesh points of the hand in NDC (Normalized Device Coordinates) space. /// /// /// public static void GetTrackingHandVertsNDC(float[] vertsNDC, int index) { if (Utils.IsAndroidPlatfrom()) getTrackingHandVertsNDC(vertsNDC, index); } /// /// Retrieve the mesh points of the hand in camera space. /// /// /// public static void GetTrackingHandVertsCAM(float[] vertsCAM, int index) { if (Utils.IsAndroidPlatfrom()) getTrackingHandVertsCAM(vertsCAM, index); } /// /// Retrieve the rotation of the hand as a quaternion. /// /// quaternion /// hand index public static void GetTrackingHandRootRotation(float[] rotation, int index) { if (Utils.IsAndroidPlatfrom()) getTrackingHandRootRotation(rotation, index); } /// /// Retrieve the type of palm and back of the hand. /// /// hand index /// public static int GetTrackingHandOrientation(int index) { if (Utils.IsAndroidPlatfrom()) return getTrackingHandOrientation(index); return 0; } /// /// Retrieve the coordinate axes of the hand in camera space. /// /// /// public static void GetTrackingHandRootRotationAxisCAM(float[] axis, int index) { if (Utils.IsAndroidPlatfrom()) getTrackingHandRootRotationAxisCAM(axis, index); } /// /// Retrieve the hand velocity tracking. /// /// /// // public static void GetTrackingHandVelocity(float[] data, int index) // { // if (Utils.IsAndroidPlatfrom()) // getTrackingHandVelocity(data, index); // } /// /// Retrieve the timestamp of the gesture image moment. /// /// public static long GetCurrentFrameTimeStamp() { if (Utils.IsAndroidPlatfrom()) return getCurrentFrameTimeStamp(); return 0; } /// /// Retrieve the timestamp of the completed gesture image processing. /// /// public static long GetFinishProcessTimeStamp() { if (Utils.IsAndroidPlatfrom()) return GetFinishProcessTimeStamp(); return 0; } /// /// Set the tracking count for hands. /// /// public static void SetMaxHandNum(int maxHandNum) { if (Utils.IsAndroidPlatfrom()) setMaxHandNum(maxHandNum); } /// /// Enable DSP /// /// 0 means neither detection nor tracking DSP is enabled /// 1 means detection is enabled, but tracking is disabled. /// 2 means detection is disabled, but tracking is enabled. /// 3 means both detection and tracking are enabled. /// /// public static void SetUseDsp(int useDsp) { if (Utils.IsAndroidPlatfrom()) setUseDsp(useDsp); } /// /// Enable fisheye distortion correction /// /// ,0-false,1-true public static void SetUseFishEyeDistort(int useFishEyeDistort) { if (Utils.IsAndroidPlatfrom()) setUseFishEyeDistort(useFishEyeDistort); } /// /// Retrieve skeleton rotation data /// /// /// hand index /// 0-matrix(21*9),1-quaternion(21*4),2-euler(21*3 public static void GetTrackingHandSkeletonRotationAll(float[] data, int index, int type) { if (Utils.IsAndroidPlatfrom()) getTrackingHandSkeletonRotationAll(data, index, type); } /// /// Set gesture loglevel /// /// "debug", "info", "warn", "err", "fatal", "none" public static void SetGestureLogLevel(string logLevel) { if (Utils.IsAndroidPlatfrom()) { setGestureLogLevel(logLevel); } } /// /// It is physical camera pose /// /// /// [Obsolete("Only gesture use")] public static Pose GetHeadPoseForGes(long timestamp) { Pose pose = Pose.identity; if (Utils.IsAndroidPlatfrom()) { getHistoryHeadPosePysRHS(timestamp, position, rotation); pose.position = new Vector3(position[0], position[1], -position[2]); pose.rotation = new Quaternion(-rotation[0], -rotation[1], rotation[2], rotation[3]); } return pose; } /// /// Get upforward influencePow /// /// public static float GetUpForwardInfluencePow() { if (Utils.IsAndroidPlatfrom()) return getUpForwardInfluencePow(); return 0; } #region NativeInterface [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void openGestureTracker(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void closeGestureTracker(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern int getTrackingHandVertsNum(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern int getTrackingHandSkeletonNum(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern int getTrackingHandNum(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern int getTrackingHandLrHand(int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern int getTrackingGestureType(int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern int getTrackingHandCombineGestureType(int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandSkeletonCAM(float[] skeletonCAM, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandVertsNDC(float[] vertsNDC, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandVertsCAM(float[] vertsCAM, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandSkeletonNDC(float[] skeletonNDC, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandRootRotation(float[] rotation, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern int getTrackingHandOrientation(int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandRootRotationAxisCAM(float[] axis, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN), Obsolete] static extern void getTrackingHandStableAnchorPoint(float[] stableAnchorPoint, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandSkeletonRotationAll(float[] data, int index, int type); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandVelocity(float[] data, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern long getCurrentFrameTimeStamp(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern long getFinishProcessTimeStamp(); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void setMaxHandNum(int maxHandNum); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void setUseDsp(int useDsp); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void setUseFishEyeDistort(int useFishEyeDistort); [DllImport(ApiConstants.UXR_GFX_PLUGIN, CharSet = CharSet.Ansi)] static extern void setGestureLogLevel(string logLevel); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getHistoryHeadPosePysRHS(long timestamp, float[] position, float[] orientation); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern float getUpForwardInfluencePow(); #region OPEN_GL_INTERFACE [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandVertsCAM_GLAxis(float[] data, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandSkeletonCAM_GLAxis(float[] data, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandRootRotation_GLAxis(float[] data, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandRootRotationEuler_GLAxis(float[] data, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandRootRotationAxisCAM_GLAxis(float[] data, int index); [DllImport(ApiConstants.UXR_GFX_PLUGIN)] static extern void getTrackingHandSkeletonRotationAll_GLAxis(float[] data, int index, int type); #endregion #endregion } } }