예제 #1
0
        public void Stop()
        {
            NDKARStatus status = NDKAPI.HwArSession_stop(m_ndkSession.SessionHandle);

            ARDebug.LogInfo("native stop end with value:{0}", status);
            ARExceptionAdapter.ExtractException(status);
        }
예제 #2
0
        public void LoadSharedData(ARSharedData sharedData)
        {
            NDKARStatus status = NDKAPI.HwArSession_load(m_ndkSession.SessionHandle, sharedData.RawData.m_pinAddr,
                                                         sharedData.RawData.DataSize);

            ARExceptionAdapter.ExtractException(status);
        }
예제 #3
0
        public IntPtr AcquireDepthImage()
        {
            IntPtr      imageHandle = IntPtr.Zero;
            NDKARStatus status      = NDKAPI.HwArFrame_acquireDepthImage(m_ndkSession.SessionHandle, m_ndkSession.FrameHandle, ref imageHandle);

            ARExceptionAdapter.ExtractException(status);
            return(imageHandle);
        }
예제 #4
0
        public long GetSerializeAnchorsLimit()
        {
            long        ret    = 0;
            NDKARStatus status = NDKAPI.HwArSession_getSerializeAnchorsLimit(m_ndkSession.SessionHandle, ref ret);

            ARExceptionAdapter.ExtractException(status);
            return(ret);
        }
        public IntPtr AcquireSceneMesh()
        {
            IntPtr      sceneMeshHandle = IntPtr.Zero;
            NDKARStatus status          = NDKAPI.HwArFrame_acquireSceneMesh(m_ndkSession.SessionHandle, m_ndkSession.FrameHandle, ref sceneMeshHandle);

            ARExceptionAdapter.ExtractException(status);
            return(sceneMeshHandle);
        }
        public void HitTestArea(float[] inPoints, List <ARHitResult> hitResultList)
        {
            hitResultList.Clear();

            if (inPoints == null || inPoints.Length == 0)
            {
                ARDebug.LogError("HitTestArea inPoints is empty");
                return;
            }

            float[] tmpIn = new float[inPoints.Length];
            inPoints.CopyTo(tmpIn, 0);
            GCHandle unmanagedInUVHandle = GCHandle.Alloc(tmpIn, GCHandleType.Pinned);

            IntPtr      hitResultListHandle = m_ndkSession.HitResultAdapter.CreateList();
            NDKARStatus status = NDKAPI.HwArFrame_hitTestArea(m_ndkSession.SessionHandle, m_ndkSession.FrameHandle,
                                                              unmanagedInUVHandle.AddrOfPinnedObject(), tmpIn.Length, hitResultListHandle);

            unmanagedInUVHandle.Free();

            if (status != NDKARStatus.HWAR_SUCCESS)
            {
                ARDebug.LogError("HitTestArea status is error:{}", status);
                return;
            }

            int cntOfResult = m_ndkSession.HitResultAdapter.GetListSize(hitResultListHandle);

            ARDebug.LogInfo("HitTestArea hit result count{0}", cntOfResult);
            for (int i = 0; i < cntOfResult; i++)
            {
                //todo refactor the following code when arplaneHitResult is removed
                IntPtr hitResultHandle = m_ndkSession.HitResultAdapter.AcquireListItem(hitResultListHandle, i);
                IntPtr trackableHandle = m_ndkSession.HitResultAdapter.GetTrackbaleHandle(hitResultHandle);
                ARDebug.LogInfo("HitTestArea hittype! {0}", m_ndkSession.TrackableAdapter.GetType(trackableHandle), i);
                switch (m_ndkSession.TrackableAdapter.GetType(trackableHandle))
                {
                case NDKARTrackableType.Plane:
                    hitResultList.Add(new ARPlaneHitResult(hitResultHandle, m_ndkSession));
                    break;

                case NDKARTrackableType.Point:
                    hitResultList.Add(new ARPointCloudHitResult(hitResultHandle, m_ndkSession, ARFrame.AcquirePointCloud()));
                    break;

                case NDKARTrackableType.Invalid:
                    break;

                case (NDKARTrackableType)0x41520105:
                    break;

                default:
                    hitResultList.Add(new ARHitResult(hitResultHandle, m_ndkSession));
                    break;
                }
            }
            m_ndkSession.HitResultAdapter.DestroyList(hitResultListHandle);
        }
예제 #7
0
        public IntPtr AcquirePointCloudHandle()
        {
            IntPtr      pointcouldHandle = IntPtr.Zero;
            NDKARStatus status           = NDKAPI.HwArFrame_acquirePointCloud(m_ndkSession.SessionHandle,
                                                                              m_ndkSession.FrameHandle, ref pointcouldHandle);

            ARExceptionAdapter.ExtractException(status);
            return(pointcouldHandle);
        }
예제 #8
0
        public ARInstallStatus RequestInstall(bool userRequestedInstall)
        {
            int         installState = 0;
            NDKARStatus status       = NDKAPI.HwArApk_requestInstall(ARUnityHelper.Instance.GetJEnv(),
                                                                     ARUnityHelper.Instance.GetActivityHandle(), userRequestedInstall, ref installState);

            ARExceptionAdapter.ExtractException(status);
            return((ARInstallStatus)installState);
        }
        //todo changed
        public ARAnchor AcquireNewAnchor(IntPtr hitResultHandle)
        {
            IntPtr      anchorHandle = IntPtr.Zero;
            NDKARStatus status       = NDKAPI.HwArHitResult_acquireNewAnchor(m_ndkSession.SessionHandle, hitResultHandle,
                                                                             ref anchorHandle);

            ARExceptionAdapter.ExtractException(status);
            ARAnchor anchor = m_ndkSession.AnchorManager.ARAnchorFactory(anchorHandle, true);

            return(anchor);
        }
        public IntPtr CreateAugImgDatabaseFromBytes(byte[] databaseBytes)
        {
            IntPtr      databaseHandle = IntPtr.Zero;
            var         bytesHandle    = GCHandle.Alloc(databaseBytes, GCHandleType.Pinned);
            NDKARStatus status         = NDKAPI.HwArAugmentedImageDatabase_deserialize(m_ndkSession.SessionHandle,
                                                                                       bytesHandle.AddrOfPinnedObject(), databaseBytes.Length, ref databaseHandle);

            ARDebug.LogInfo("native AddImageWithPhysicalSize end with status={0}", status);
            ARExceptionAdapter.ExtractException(status);
            bytesHandle.Free();
            return(databaseHandle);
        }
예제 #11
0
        public void Config(ARConfigBase unityConfig)
        {
            //ARDebug.LogInfo("native config begin" + unityConfig.ToString());
            IntPtr configHandle = m_ndkSession.ConfigBaseAdapter.Create();

            m_ndkSession.ConfigBaseAdapter.UpdateNDKConfigWithUnityConfig(configHandle, unityConfig);
            NDKARStatus status = NDKAPI.HwArSession_configure(m_ndkSession.SessionHandle, configHandle);

            ARDebug.LogInfo("native config end with value:{0}", status);
            m_ndkSession.ConfigBaseAdapter.UpdateUnityConfigWithNDKConfig(configHandle, unityConfig);
            m_ndkSession.ConfigBaseAdapter.Destroy(configHandle);
            ARExceptionAdapter.ExtractException(status);
        }
예제 #12
0
        public ARSharedData SaveSharedData()
        {
            long dataSize = GetSaveLimit();
            long usedSize = 0;

            ARSharedData.ARRawData rawdata = new ARSharedData.ARRawData(dataSize);
            NDKARStatus            status  = NDKAPI.HwArSession_save(m_ndkSession.SessionHandle, rawdata.m_pinAddr, dataSize,
                                                                     ref usedSize);

            ARExceptionAdapter.ExtractException(status);

            rawdata.DataSize = usedSize > 0? usedSize : 0;
            return(new ARSharedData(rawdata));
        }
예제 #13
0
        public IntPtr Create()
        {
            IntPtr sessionHandle = IntPtr.Zero;

            ARDebug.LogInfo("native create seesion begin");

            IntPtr      jEnv     = ARUnityHelper.Instance.GetJEnv();
            IntPtr      activity = ARUnityHelper.Instance.GetActivityHandle();
            NDKARStatus status   = NDKAPI.HwArSession_create(jEnv, activity, ref sessionHandle);

            ARDebug.LogInfo("native create seesion returns status {0}", status);
            ARExceptionAdapter.ExtractException(status);
            return(sessionHandle);
        }
예제 #14
0
        public ARAnchor CreateAnchor(Pose pose)
        {
            IntPtr poseHandle   = m_ndkSession.PoseAdapter.Create(pose);
            IntPtr anchorHandle = IntPtr.Zero;

            ARDebug.LogInfo("native acquire anchor begin with pose:{0}", pose.ToString());
            NDKARStatus status = NDKAPI.HwArSession_acquireNewAnchor(m_ndkSession.SessionHandle,
                                                                     poseHandle, ref anchorHandle);

            ARDebug.LogInfo("native acquire anchor end with status={0}", status);
            m_ndkSession.PoseAdapter.Destroy(poseHandle);
            ARExceptionAdapter.ExtractException(status);
            var anchor = m_ndkSession.AnchorManager.ARAnchorFactory(anchorHandle, true);

            return(anchor);
        }
예제 #15
0
        public void Update()
        {
            //release form handle
            if (m_ndkSession.FrameHandle != IntPtr.Zero)
            {
                m_ndkSession.FrameAdapter.Destroy(m_ndkSession.FrameHandle);
            }

            IntPtr frameHandle = m_ndkSession.FrameAdapter.Create();

            GL.InvalidateState();
            NDKARStatus status = NDKAPI.HwArSession_update(m_ndkSession.SessionHandle, frameHandle);

            GL.InvalidateState();
            ARExceptionAdapter.ExtractException(status);
            m_ndkSession.FrameHandle = frameHandle;
        }
예제 #16
0
        public void DeSerializeAnchors(ARSharedData sharedData, List <ARAnchor> anchors)
        {
            IntPtr      anchorListHandle = m_ndkSession.AnchorAdapter.CreateList();
            NDKARStatus status           = NDKAPI.HwArSession_deserializeAnchors(m_ndkSession.SessionHandle,
                                                                                 sharedData.RawData.m_pinAddr, sharedData.RawData.DataSize, anchorListHandle);

            ARExceptionAdapter.ExtractException(status);
            int anchorListSize = m_ndkSession.AnchorAdapter.GetListSize(anchorListHandle);

            for (int i = 0; i < anchorListSize; i++)
            {
                IntPtr   anchorHandle = m_ndkSession.AnchorAdapter.AcquireListItem(anchorListHandle, i);
                ARAnchor anchor       = m_ndkSession.AnchorManager.ARAnchorFactory(anchorHandle, true);
                anchors.Add(anchor);
            }
            m_ndkSession.AnchorAdapter.DestroyList(anchorListHandle);
        }
예제 #17
0
        public ARSharedData SerializeAnchors(List <ARAnchor> anchorList, bool isNeedAlign)
        {
            long   dataSize         = GetSerializeAnchorsLimit();
            long   usedSize         = 0;
            IntPtr anchorListHandle = m_ndkSession.AnchorAdapter.CreateList();

            foreach (ARAnchor anchor in anchorList)
            {
                m_ndkSession.AnchorAdapter.AddListItem(anchorListHandle, anchor.m_anchorHandle);
            }
            ARSharedData.ARRawData rawData = new ARSharedData.ARRawData(dataSize);
            NDKARStatus            status  = NDKAPI.HwArSession_serializeAnchors(m_ndkSession.SessionHandle,
                                                                                 anchorListHandle, isNeedAlign, rawData.m_pinAddr, dataSize, ref usedSize);

            ARExceptionAdapter.ExtractException(status);
            rawData.DataSize = usedSize;
            return(new ARSharedData(rawData));
        }
        public void Update()
        {
            //release form handle
            if (m_ndkSession.FrameHandle != IntPtr.Zero)
            {
                m_ndkSession.FrameAdapter.Destroy(m_ndkSession.FrameHandle);
            }

            //IntPtr frameHandle = m_ndkSession.FrameAdapter.Create();
            //GL.InvalidateState();
            //NDKARStatus status = NDKAPI.HwArSession_update(m_ndkSession.SessionHandle, frameHandle);
            //GL.InvalidateState();
            IntPtr frameHandle = IntPtr.Zero;

            NDKAPI.SetCurrentSessionHandle(m_ndkSession.SessionHandle);
            GL.IssuePluginEvent(NDKAPI.GetRenderEventFunc(), 1);
            NDKAPI.WaitForRenderingThreadFinished();
            NDKARStatus status = NDKARStatus.HWAR_SUCCESS;

            NDKAPI.GetCurrentFrameHandleAndStatus(ref frameHandle, ref status);
            ARExceptionAdapter.ExtractException(status);
            m_ndkSession.FrameHandle = frameHandle;
        }
        public static void ExtractException(NDKARStatus status)
        {
            switch (status)
            {
            case NDKARStatus.HWAR_SUCCESS:
                return;

            case NDKARStatus.HWAR_ERROR_INVALID_ARGUMENT:
                throw new ArgumentException();

            case NDKARStatus.HWAR_ERROR_FATAL:
                throw new SystemException();

            case NDKARStatus.HWAR_ERROR_SESSION_NOT_PAUSED:
                throw new ARSessionNotPausedException();

            case NDKARStatus.HWAR_ERROR_SESSION_PAUSED:
                throw new ARSessionPausedException();

            case NDKARStatus.HWAR_ERROR_TEXTURE_NOT_SET:
                throw new ARTextureNotSetException();

            case NDKARStatus.HWAR_UNAVAILABLE_SDK_TOO_OLD:
                throw new ARUnavailableClientSdkTooOldException();

            case NDKARStatus.HWAR_UNAVAILABLE_DEVICE_NOT_COMPATIBLE:
                throw new ARUnavailableDeviceNotCompatibleException();

            case NDKARStatus.HWAR_UNAVAILABLE_EMUI_NOT_CAPABLE:
                throw new ARUnavailableEmuiNotCompatibleException();

            case NDKARStatus.HWAR_UNAVAILABLE_APK_TOO_OLD:
                throw new ARUnavailableServiceApkTooOldException();

            case NDKARStatus.HWAR_UNAVAILABLE_AREXECUTOR_NOT_INSTALLED:
                throw new ARUnavailableServiceNotInstalledException();

            case NDKARStatus.HWAR_ERROR_UNSUPPORTED_CONFIGURATION:
                throw new ARUnSupportedConfigurationException();

            case NDKARStatus.HWAR_UNAVAILABLE_USER_DECLINED_INSTALLATION:
                throw new ARUnavailableUserDeclinedInstallationException();

            case NDKARStatus.HWAR_ERROR_CAMERA_PERMISSION_NOT_GRANTED:
                throw new ARCameraPermissionDeniedException();

            case NDKARStatus.HWAR_ERROR_DEADLINE_EXCEEDED:
                throw new ARDeadlineExceededException();

            case NDKARStatus.HWAR_ERROR_RESOURCE_EXHAUSTED:
                throw new ARResourceExhaustedException();

            case NDKARStatus.HWAR_ERROR_NOT_YET_AVAILABLE:
                throw new ARNotYetAvailableException();

            case NDKARStatus.HWAR_UNAVAILABLE_CONNECT_SERVER_TIME_OUT:
                throw new ARUnavailableConnectServerTimeOutException();

            default:
                throw new ApplicationException();
            }
        }
예제 #20
0
        public void Resume()
        {
            NDKARStatus status = NDKAPI.HwArSession_resume(m_ndkSession.SessionHandle);

            ARExceptionAdapter.ExtractException(status);
        }
 public static extern void GetCurrentFrameHandleAndStatus(ref IntPtr frameHandle, ref NDKARStatus status);