Exemple #1
0
        /// <summary>
        /// Init HMD device.
        /// </summary>
        public void Init()
        {
            if (m_IsInit)
            {
                return;
            }
            NRTools.Init();
            Loom.Initialize();

#if UNITY_ANDROID && !UNITY_EDITOR
            // Init before all actions.
            AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            m_UnityActivity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            NativeApi.NRSDKInitSetAndroidActivity(m_UnityActivity.GetRawObject());
#endif
            m_IsInit = true;
        }
Exemple #2
0
        /// <summary>
        /// Init HMD device.
        /// </summary>
        public void Init()
        {
            if (m_IsInit || isGlassesPlugOut)
            {
                return;
            }
            NRTools.Init();
            MainThreadDispather.Initialize();
#if UNITY_ANDROID && !UNITY_EDITOR
            // Init before all actions.
            AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            m_UnityActivity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            NativeApi.NRSDKInitSetAndroidActivity(m_UnityActivity.GetRawObject());
#endif
            CreateGlassesController();
            CreateHMD();

            m_IsInit = true;
        }
Exemple #3
0
        /// @endcond

        /// @cond EXCLUDE_FROM_DOXYGEN
        /// <summary>
        /// Rebuilds the database asset, if needed.
        /// </summary>
        public void BuildIfNeeded()
        {
            if (!m_IsRawDataDirty)
            {
                return;
            }
            m_IsRawDataDirty = false;

            string directory = NRTools.GetTrackingImageDataGenPath() + GUID;

            if (!Directory.Exists(directory))
            {
                ZipUtility.UnzipFile(RawData, NRTools.GetTrackingImageDataGenPath(), NativeConstants.ZipKey);
            }

            //Generate marker data by json file
            var result_json = TrackingImageDataPath + "markers.json";

            if (File.Exists(result_json))
            {
                var json_data = File.ReadAllText(result_json);

                StringBuilder str = new StringBuilder();
                str.AppendLine("# Number of markers");
                str.AppendLine(Count.ToString());

                DirectoryInfo dir          = new DirectoryInfo(directory);
                var           fsinfos      = dir.GetDirectories();
                string        dataPathName = "Data";

                if (fsinfos != null && fsinfos.Length > 0)
                {
                    Array.Sort(fsinfos, (dir1, dir2) => dir1.CreationTime.CompareTo(dir2.CreationTime));
                    dataPathName = fsinfos[0].Name;
                }
                for (int i = 0; i < Count; i++)
                {
                    var image_info = JsonMapper.ToObject(json_data)[this[i].Name];
                    str.AppendLine();
                    str.AppendLine(string.Format("./{0}/{1}", dataPathName, this[i].Name));
                    str.AppendLine("NFT");
                    str.AppendLine(string.Format("FILTER {0}", image_info["filter"]));
                    str.AppendLine(string.Format("MARKER_WIDTH {0}", image_info["physical_width"]));
                    str.AppendLine(string.Format("MARKER_HEIGHT {0}", image_info["physical_height"]));
                }

                File.WriteAllText(TrackingImageDataPath + "markers.dat", str.ToString());
            }

            string file_path = directory + "_zipFile";

            // Generate zip file
            ZipUtility.Zip(new string[1] {
                directory
            }, file_path, NativeConstants.ZipKey, new ZipUtility.ZipCallback(_result =>
            {
                m_IsRawDataDirty = _result ? false : true;
                if (!string.IsNullOrEmpty(file_path) && File.Exists(file_path))
                {
                    // Read the zip bytes
                    m_RawData = File.ReadAllBytes(file_path);
                    //Debug.Log("Generate raw data success!" + file_path);
                    //m_IsNeedLoadRawData = false;

                    EditorUtility.SetDirty(this);
                    // Force a save to make certain build process will get updated asset.
                    AssetDatabase.SaveAssets();
                }
            }));

            UpdateClipVersion();
        }
        private static void RunDirtyQualityJobs(NRTrackingImageDatabase database)
        {
            if (database == null)
            {
                Debug.Log("database is null");
                return;
            }
            if (m_DatabaseForQualityJobs != database)
            {
                // If another database is already running quality evaluation,
                // stop all pending jobs to prioritise the current database.
                if (m_DatabaseForQualityJobs != null)
                {
                    m_QualityBackgroundExecutor.RemoveAllPendingJobs();
                }

                m_DatabaseForQualityJobs = database;
            }

            UpdateDatabaseQuality(database);

            // Set database dirty to refresh inspector UI for each frame that there are still pending jobs.
            // Otherwise if there exists one frame with no newly finished jobs, the UI will never get refreshed.
            // EditorUtility.SetDirty can only be called from main thread.
            if (m_QualityBackgroundExecutor.PendingJobsCount > 0)
            {
                EditorUtility.SetDirty(database);
                return;
            }

            List <NRTrackingImageDatabaseEntry> dirtyEntries = database.GetDirtyQualityEntries();

            if (dirtyEntries.Count == 0)
            {
                return;
            }

            string cliBinaryPath;

            if (!NRTrackingImageDatabase.FindCliBinaryPath(out cliBinaryPath))
            {
                return;
            }

            string outpath = NRTools.GetTrackingImageDataGenPath() + database.GUID + "/";

            if (!Directory.Exists(outpath))
            {
                Directory.CreateDirectory(outpath);
            }

            var resultjson = database.TrackingImageDataPath + "markers.json";

            for (int i = 0; i < dirtyEntries.Count; ++i)
            {
                NRTrackingImageDatabaseEntry image = dirtyEntries[i];
                var imagePath = AssetDatabase.GetAssetPath(image.Texture);
                imagePath = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + imagePath;

                m_QualityBackgroundExecutor.PushJob(() =>
                {
                    BuildImage(cliBinaryPath, image, imagePath, outpath, resultjson);
                });
            }
        }
        public static void BuildDataBase(NRTrackingImageDatabase database)
        {
            Debug.Log("Start to build database...");
            if (database == null)
            {
                Debug.Log("database is null");
                return;
            }

            List <NRTrackingImageDatabaseEntry> dirtyEntries = database.GetDirtyQualityEntries();

            if (dirtyEntries.Count == 0)
            {
                return;
            }

            string cliBinaryPath;

            if (!NRTrackingImageDatabase.FindCliBinaryPath(out cliBinaryPath))
            {
                return;
            }

            string outpath = NRTools.GetTrackingImageDataGenPath() + database.GUID + "/";

            if (!Directory.Exists(outpath))
            {
                Directory.CreateDirectory(outpath);
            }

            var resultjson = database.TrackingImageDataPath + "markers.json";

            for (int i = 0; i < dirtyEntries.Count; ++i)
            {
                NRTrackingImageDatabaseEntry image = dirtyEntries[i];
                var imagePath = AssetDatabase.GetAssetPath(image.Texture);

                BuildImage(cliBinaryPath, image, imagePath, outpath, resultjson);
            }

            if (File.Exists(resultjson))
            {
                var json_data = File.ReadAllText(resultjson);
                var json_obj  = JsonMapper.ToObject(json_data);
                for (int i = 0; i < dirtyEntries.Count; i++)
                {
                    NRTrackingImageDatabaseEntry image = dirtyEntries[i];
                    var textureGUID = image.TextureGUID;

                    //Debug.Log("update quality dict " + image.Name);
                    var image_info = json_obj[image.Name];
                    m_UpdatedQualityScores.Remove(textureGUID);
                    m_UpdatedQualityScores.Add(textureGUID, image_info);
                }
                UpdateDatabaseQuality(database);
                for (int i = 0; i < database.Count; i++)
                {
                    NRTrackingImageDatabaseEntry image = database[i];
                    Debug.Log(image.ToString());
                }
            }
        }