Ejemplo n.º 1
0
    void OnWizardOtherButton()
    {
        bool isExist = System.IO.File.Exists(importAssetPath);

        if (isExist)
        {
            statusText = "Import processing...";
            if (cadManager.Import(importAssetPath, m_tessParam))
            {
                var startTime = DateTime.Now;
                // エディタ上で進捗更新をチェック
                EditorApplication.CallbackFunction update = null;
                update = () => {
                    if (cadManager.isDone() == false)
                    {
                        // 毎フレームチェック
                        int progress = cadManager.GetProgress();
                        var sPercent = string.Format("{0:0}%", progress);
                        //Debug.Log("Progress: " + sPercent);
                        if (EditorUtility.DisplayCancelableProgressBar("Importing progress", "import processing..." + sPercent, progress / 100.0f) != false)
                        {
                            // インポート処理中断
                            cadManager.Close();
                            EditorUtility.ClearProgressBar();
                            EditorApplication.update -= update;
                            if (cadManager.GetExitCode() != 0)
                            {
                                statusText = "Canceled";
                                Debug.Log(statusText);
                            }
                        }
                    }
                    else
                    {
                        // インポート処理終了
                        cadManager.Close();
                        EditorUtility.ClearProgressBar();
                        EditorApplication.update -= update;
                        if (cadManager.GetExitCode() != 0)
                        {
                            statusText = "Failed";
                            Debug.Log(statusText);
                            // cache ディレクトリにある "Debug.txt"を開いて先頭行にある例外名を取得し、そのメッセージを表示する
                            var sErrorMessage = cadManager.GetErrorMessage();
                            if (!string.IsNullOrEmpty(sErrorMessage))
                            {
                                Debug.LogError(sErrorMessage);
                                if (sErrorMessage == "System.OutOfMemoryException")
                                {
                                    EditorUtility.DisplayDialog("Error", "Memory Overflow", "OK");
                                }
                            }
                        }
                        else
                        {
                            // メッシュデータを復元する
                            int nVertices, nFacets;
                            if (cadManager.GetMesh(out nVertices, out nFacets) == false)
                            {
                                statusText = "Failed";
                                Debug.LogWarning(statusText);
                                Debug.LogWarning("Can't import file:" + importAssetPath);
                            }
                            else
                            {
                                statusText = "Succeeded";
                                Debug.Log(statusText);
                                var duration = DateTime.Now - startTime;
                                Debug.Log("Duration: " + duration.ToString());
                                Debug.Log(string.Format("Vertices: {0}, Facets: {1}", nVertices, nFacets));
                            }
                        }
                    }
                };
                EditorApplication.update += update;
            }
            else
            {
                statusText = "Failed";
                Debug.LogWarning("Can't import file:" + importAssetPath);
            }
        }
        else
        {
            statusText = "Failed";
            Debug.LogWarning("Can't read file:" + importAssetPath);
        }
    }
Ejemplo n.º 2
0
    // Import Button
    void OnWizardOtherButton()
    {
        bool directoryExists = Directory.Exists(importAssetPath);

        if (directoryExists && firstPass)
        {
            FirstPass();
        }

        string filePath = filePaths[counter];

        bool fileExists = File.Exists(filePath);

        if (fileExists)
        {
            statusText = "Import processing...";

            if (cadManager.Import(filePath, m_tessParam))
            {
                var startTime = DateTime.Now;

                EditorApplication.CallbackFunction update = null;

                update = () => {
                    if (cadManager.isDone() == false)
                    {
                        int progress = cadManager.GetProgress();
                        var sPercent = string.Format("{0:0}%", progress);

                        if (EditorUtility.DisplayCancelableProgressBar("Importing progress", "import processing..." + sPercent, progress / 100.0f) != false)
                        {
                            cadManager.Close();

                            EditorUtility.ClearProgressBar();

                            EditorApplication.update -= update;

                            if (cadManager.GetExitCode() != 0)
                            {
                                statusText = "Canceled";
                                Debug.Log(statusText);
                            }
                        }
                    }
                    else
                    {
                        cadManager.Close();

                        EditorUtility.ClearProgressBar();

                        EditorApplication.update -= update;

                        if (cadManager.GetExitCode() != 0)
                        {
                            statusText = "Failed";
                            Debug.Log(statusText);

                            string sErrorMessage = cadManager.GetErrorMessage();

                            if (!string.IsNullOrEmpty(sErrorMessage))
                            {
                                Debug.LogError(sErrorMessage);

                                if (sErrorMessage == "System.OutOfMemoryException")
                                {
                                    EditorUtility.DisplayDialog("Error", "Memory Overflow", "OK");
                                }
                            }
                        }
                        else
                        {
                            int nVertices, nFacets;

                            if (cadManager.GetMesh(out nVertices, out nFacets) == false)
                            {
                                statusText = "Failed";
                                Debug.LogWarning(statusText);
                                Debug.LogWarning("Can't import file:" + filePath);
                            }
                            else
                            {
                                statusText = "File : " + filePath + "was imported sucessfully ";

                                TimeSpan duration = DateTime.Now - startTime;
                                Debug.Log("Duration: " + duration.ToString());
                                Debug.Log(string.Format("Vertices: {0}, Facets: {1}", nVertices, nFacets));

                                // Keep iterating until all files are imported
                                if (counter < numberOfFiles)
                                {
                                    OnWizardOtherButton();

                                    counter++;
                                }
                            }
                        }
                    }
                };

                EditorApplication.update += update;
            }
            else
            {
                statusText = "Failed";
                Debug.LogWarning("Can't import file:" + filePath);
            }
        }
        else
        {
            statusText = "Failed";
            Debug.LogWarning("Can't read file:" + filePath);
        }
    }