Exemple #1
0
        public void Update()
        {
            // Do not update if huaweiAR is not tracking.
            if (ARFrame.GetTrackingState() != ARTrackable.TrackingState.TRACKING)
            {
                m_mesh.Clear();
                return;
            }

            // Fill in the data to draw the point cloud.
            ARPointCloud pointCloud = ARFrame.AcquirePointCloud();

            pointCloud.GetPoints(ref m_points);
            pointCloud.Release();
            if (m_points.Count > 0)
            {
                // Update the mesh indicies array.
                m_pointIndex.Clear();
                for (int i = 0; i < Mathf.Min(m_points.Count, k_maxPointCount); i++)
                {
                    m_pointIndex.Add(i);
                }

                m_mesh.Clear();
                m_mesh.vertices = m_points.ToArray();
                m_mesh.SetIndices(m_pointIndex.ToArray(), MeshTopology.Points, 0);
            }
        }
        public void HitTest(float pixelX, float pixelY, List <ARHitResult> hitResultList)
        {
            hitResultList.Clear();

            IntPtr hitResultListHandle = m_ndkSession.HitResultAdapter.CreateList();

            NDKAPI.HwArFrame_hitTest(m_ndkSession.SessionHandle, m_ndkSession.FrameHandle, pixelX, pixelY, hitResultListHandle);
            int cntOfResult = m_ndkSession.HitResultAdapter.GetListSize(hitResultListHandle);

            ARDebug.LogInfo("HitTest hitresult {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("HitTest 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);
        }
        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);
        }