Ejemplo n.º 1
0
 public TrackedPlaneRecord(TrackedPlane plane, ApiPlaneData planeData,
                           Action <ApiPlaneData, TrackedPlane, bool> updatePlane)
 {
     m_plane       = plane;
     m_planeData   = planeData;
     m_updatePlane = updatePlane;
 }
Ejemplo n.º 2
0
        public void OnApplicationPause(bool isPaused)
        {
            if (!isPaused)
            {
                return;
            }

            for (int i = 0; i < m_allPlaneRecords.Count; i++)
            {
                ApiPlaneData invalidPlane = new ApiPlaneData();
                invalidPlane.id = m_allPlaneRecords[i].m_planeData.id;
                m_allPlaneRecords[i].m_updatePlane(invalidPlane, null, true);
            }
        }
Ejemplo n.º 3
0
        private bool _UpdateMostRecentApiPlanes()
        {
            IntPtr apiPlanesPtr = IntPtr.Zero;
            int    planeCount   = 0;

            if (TangoClientApi.TangoService_Experimental_getPlanes(ref apiPlanesPtr, ref planeCount).IsTangoFailure())
            {
                for (int i = 0; i < m_mostRecentApiPlanes.Count; i++)
                {
                    ApiPlaneData planeData = m_mostRecentApiPlanes[i];
                    planeData.isValid        = false;
                    m_mostRecentApiPlanes[i] = planeData;
                }

                return(true);
            }

            // The planes api is handling a COM reset, and the current state is not available. Leave the most recent
            // Api planes collection unchanged.
            if (apiPlanesPtr == null)
            {
                return(false);
            }

            // Marshal the most recent planes returned from the Api into m_mostRecentApiPlanes.
            m_mostRecentApiPlanes.Clear();
            MarshalingHelper.AddUnmanagedStructArrayToList <ApiPlaneData>(apiPlanesPtr, planeCount,
                                                                          m_mostRecentApiPlanes);

            if (TangoClientApi.TangoPlaneData_free(apiPlanesPtr, planeCount).IsTangoFailure())
            {
                ARDebug.LogErrorFormat("Failed to deallocate planes from the ARCore API.");
            }

            return(false);
        }
Ejemplo n.º 4
0
        private void _UpdatePlanes(List <ApiPlaneData> latestPlaneData, List <TrackedPlaneRecord> newPlaneRecords,
                                   List <TrackedPlaneRecord> planeRecords, bool forceUpdate)
        {
            // Add latest planedata to a convenient hash on ID (note: not hashing plane itself to avoid potential boxing
            // of the struct on comparison overloads).
            m_tmpLastestPlanesHash.Clear();
            for (int i = 0; i < latestPlaneData.Count; i++)
            {
                m_tmpLastestPlanesHash.Add(latestPlaneData[i].id);
            }

            // Create or update all planes that appear in latestPlaneData.
            newPlaneRecords.Clear();
            for (int i = 0; i < latestPlaneData.Count; i++)
            {
                int planeRecordIndex = _FindPlaneRecordById(latestPlaneData[i].id, planeRecords);
                if (planeRecordIndex != -1)
                {
                    planeRecords[planeRecordIndex] = new TrackedPlaneRecord(planeRecords[planeRecordIndex].m_plane,
                                                                            latestPlaneData[i], planeRecords[planeRecordIndex].m_updatePlane);
                    planeRecords[planeRecordIndex].m_updatePlane(latestPlaneData[i], null, forceUpdate);
                }
                else
                {
                    Action <ApiPlaneData, TrackedPlane, bool> updatePlane;
                    var trackedPlane = new TrackedPlane(latestPlaneData[i], out updatePlane);
                    newPlaneRecords.Add(new TrackedPlaneRecord(trackedPlane, latestPlaneData[i], updatePlane));
                }
            }

            // Add new planes into plane records
            for (int i = 0; i < newPlaneRecords.Count; i++)
            {
                planeRecords.Add(newPlaneRecords[i]);
            }

            // Invalidate planes that were previously tracking but not present in latestPlaneData.  Delete planes that
            // are invalid or subsumed.
            for (int i = planeRecords.Count - 1; i >= 0; i--)
            {
                if (!m_tmpLastestPlanesHash.Contains(planeRecords[i].m_planeData.id))
                {
                    ApiPlaneData invalidPlane = new ApiPlaneData();
                    invalidPlane.id = planeRecords[i].m_planeData.id;
                    planeRecords[i].m_updatePlane(invalidPlane, null, true);
                    planeRecords.RemoveAt(i);
                }
                else if (planeRecords[i].m_planeData.subsumedBy > -1)
                {
                    int subsumerIndex = _FindPlaneRecordById(planeRecords[i].m_planeData.subsumedBy, planeRecords);
                    if (subsumerIndex == -1)
                    {
                        ARDebug.LogError("Failed to find a record of the subsuming plane.");
                        continue;
                    }

                    planeRecords[i].m_updatePlane(planeRecords[i].m_planeData, planeRecords[subsumerIndex].m_plane,
                                                  true);
                    planeRecords.RemoveAt(i);
                }
            }
        }