ConvertFromUnity() public method

public ConvertFromUnity ( ) : void
return void
Exemplo n.º 1
0
        public void Export(bool run)
        {
            try
            {
                string sceneName = EditorSceneManager.GetActiveScene().name;

                exportationOptions.DefaultFolder = EditorUtility.SaveFolderPanel("Please select a folder", exportationOptions.DefaultFolder, "");

                if (string.IsNullOrEmpty(exportationOptions.DefaultFolder))
                {
                    return;
                }

                Stopwatch watch = new Stopwatch();

                watch.Start();

                var jsWriter = new JsonWriter();
                File.WriteAllText("Unity3D2Babylon.ini", jsWriter.Write(exportationOptions));
                logs.Clear();

                ReportProgress(0);

                var sceneBuilder = new SceneBuilder(exportationOptions.DefaultFolder, sceneName, exportationOptions);

                sceneBuilder.ConvertFromUnity();

                ReportProgress(1, "Generating output file");
                var outputFile = sceneBuilder.WriteToBabylonFile();

                watch.Stop();
                ReportProgress(1, string.Format("Exportation done in {0:0.00}s", watch.Elapsed.TotalSeconds));
                EditorUtility.ClearProgressBar();

                sceneBuilder.GenerateStatus(logs);

                ShowMessage("Exportation done");

                if (run)
                {
                    WebServer.SceneFolder   = Path.GetDirectoryName(outputFile);
                    WebServer.SceneFilename = Path.GetFileName(outputFile);

                    Process.Start("http://localhost:" + WebServer.Port);
                }
            }
            catch (Exception ex)
            {
                EditorUtility.ClearProgressBar();
                ShowMessage("A problem occurred: " + ex.Message + ex.StackTrace, "Error");
            }
        }
Exemplo n.º 2
0
        public void Export()
        {
            try
            {
                int    pos       = EditorApplication.currentScene.LastIndexOf("/", StringComparison.Ordinal);
                string sceneName = EditorApplication.currentScene.Substring(pos + 1);

                exportationOptions.DefaultFolder = EditorUtility.SaveFolderPanel("Please select a folder", exportationOptions.DefaultFolder, "");

                if (string.IsNullOrEmpty(exportationOptions.DefaultFolder))
                {
                    return;
                }

                Stopwatch watch = new Stopwatch();

                watch.Start();

                var jsWriter = new JsonWriter();
                File.WriteAllText("Unity3D2Babylon.ini", jsWriter.Write(exportationOptions));
                logs.Clear();

                ReportProgress(0);

                var sceneBuilder = new SceneBuilder(exportationOptions.DefaultFolder, sceneName, exportationOptions);

                sceneBuilder.ConvertFromUnity();

                ReportProgress(1, "Generating output file");
                sceneBuilder.WriteToBabylonFile();

                watch.Stop();
                ReportProgress(1, string.Format("Exportation done in {0:0.00}s", watch.Elapsed.TotalSeconds));
                EditorUtility.ClearProgressBar();

                sceneBuilder.GenerateStatus(logs);

                ShowMessage("Exportation done");
            }
            catch (Exception ex)
            {
                EditorUtility.ClearProgressBar();
                ShowMessage("A problem occurred: " + ex.Message + ex.StackTrace, "Error");
            }
        }
Exemplo n.º 3
0
        public void Export(bool preview)
        {
            try
            {
                // Validate lightmap bake in progress
                if (exportationOptions.ExportLightmaps && exportationOptions.DefaultLightmapBaking == (int)BabylonLightmapBaking.Enabled && Lightmapping.isRunning)
                {
                    ShowMessage("There is a bake already in progress.");
                    return;
                }

                // Validate default project folder selected
                if (String.IsNullOrEmpty(exportationOptions.DefaultProjectFolder))
                {
                    ShowMessage("No default project file selected.");
                    return;
                }

                // Validate default project folder exists
                if (!Directory.Exists(exportationOptions.DefaultProjectFolder))
                {
                    if (ExporterWindow.ShowMessage("Create default project folder: " + exportationOptions.DefaultProjectFolder, "Babylon.js - Project not found", "Create"))
                    {
                        Directory.CreateDirectory(exportationOptions.DefaultProjectFolder);
                    }
                    else
                    {
                        return;
                    }
                }

                // Get validate scene path info
                string[] sceneInfo     = GetSceneInfomation(true);
                string   sceneName     = sceneInfo[0];
                string   scenePath     = sceneInfo[1];
                string   scriptPath    = sceneInfo[2];
                string   outputFile    = sceneInfo[3];
                string   projectScript = sceneInfo[4];
                if (!ExporterWindow.ShowMessage("Export current scene to babylon: " + sceneName, "Babylon.js", "Export"))
                {
                    return;
                }

                // Save current scene info
                SaveSettings();
                ExporterWindow.logs.Clear();
                Stopwatch watch = new Stopwatch();
                watch.Start();
                ReportProgress(0, "Exporting " + scenePath);

                // Auto lightmap baking
                if (exportationOptions.ExportLightmaps && exportationOptions.DefaultLightmapBaking == (int)BabylonLightmapBaking.Enabled)
                {
                    ReportProgress(1, "Baking lightmap textures... This may take a while.");
                    Lightmapping.GIWorkflowMode workflow = Lightmapping.giWorkflowMode;
                    Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
                    Lightmapping.Bake();
                    Lightmapping.giWorkflowMode = workflow;
                }

                // Save all open scenes
                ReportProgress(1, "Saving open scene information...");
                UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();

                // Build project preview
                if (preview)
                {
                    Tools.GenerateProjectIndexPage(exportationOptions.DefaultProjectFolder, exportationOptions.ShowDebugControls, exportationOptions.DefaultScenePath, Path.GetFileName(outputFile), exportationOptions.DefaultScriptPath, Path.GetFileName(projectScript));
                    if (exportationOptions.BuildJavaScript || exportationOptions.CompileTypeScript)
                    {
                        Build(false, sceneInfo);
                    }
                }

                // Build current scene
                BabylonSceneController sceneController = Tools.GetSceneController();
                var sceneBuilder = new SceneBuilder(scenePath, sceneName, exportationOptions, sceneController, scriptPath);
                sceneBuilder.ConvertFromUnity();

                ReportProgress(1, "Generating babylon scene... This may take a while.");
                sceneBuilder.WriteToBabylonFile(outputFile);

                watch.Stop();
                ReportProgress(1, string.Format("Exportation done in {0:0.00}s", watch.Elapsed.TotalSeconds));
                EditorUtility.ClearProgressBar();

                sceneBuilder.GenerateStatus(logs);

                string done = preview ? "Preview" : "OK";
                bool   ok   = ShowMessage("Scene exportation complete.", "Babylon.js", done);
                if (preview && ok)
                {
                    Preview();
                }
            }
            catch (Exception ex)
            {
                EditorUtility.ClearProgressBar();
                ShowMessage("A problem occurred: " + ex.Message + ex.StackTrace, "Error");
            }
        }
Exemplo n.º 4
0
        public void Export(bool run)
        {
            try
            {
                string sceneName = SceneManager.GetActiveScene().name;

                exportationOptions.DefaultFolder = EditorUtility.SaveFolderPanel("Please select a folder", exportationOptions.DefaultFolder, "");

                if (string.IsNullOrEmpty(exportationOptions.DefaultFolder))
                {
                    return;
                }

                Stopwatch watch = new Stopwatch();

                watch.Start();

                var jsWriter = new JsonWriter();
                File.WriteAllText("Unity3D2Babylon.ini", jsWriter.Write(exportationOptions));
                logs.Clear();

                ReportProgress(0);

                var sceneBuilder = new SceneBuilder(exportationOptions.DefaultFolder, sceneName, exportationOptions);

                sceneBuilder.ConvertFromUnity();

                ReportProgress(1, "Generating output file");
                var outputFile = sceneBuilder.WriteToBabylonFile();

                watch.Stop();
                ReportProgress(1, string.Format("Exportation done in {0:0.00}s", watch.Elapsed.TotalSeconds));
                EditorUtility.ClearProgressBar();

                sceneBuilder.GenerateStatus(logs);

                ShowMessage("Exportation done");

                if (run)
                {
                    WebServer.SceneFolder = Path.GetDirectoryName(outputFile);
                    WebServer.SceneFilename = Path.GetFileName(outputFile);

                    Process.Start("http://localhost:" + WebServer.Port);
                }
            }
            catch (Exception ex)
            {
                EditorUtility.ClearProgressBar();
                ShowMessage("A problem occurred: " + ex.Message + ex.StackTrace, "Error");
            }
        }
Exemplo n.º 5
0
        public void Export(bool preview)
        {
            try
            {
                // Validate lightmap bake in progress
                if (exportationOptions.ExportLightmaps && exportationOptions.DefaultLightmapBaking == (int)BabylonLightmapBaking.Enabled && Lightmapping.isRunning)
                {
                    ShowMessage("There is a bake already in progress.");
                    return;
                }

                // Validate default project folder selected
                if (String.IsNullOrEmpty(exportationOptions.DefaultProjectFolder))
                {
                    ShowMessage("No default project file selected.");
                    return;
                }

                // Validate default project folder exists
                if (!Directory.Exists(exportationOptions.DefaultProjectFolder))
                {
                    if (ExporterWindow.ShowMessage("Create default project folder: " + exportationOptions.DefaultProjectFolder, "Babylon.js - Project not found", "Create"))
                    {
                        Directory.CreateDirectory(exportationOptions.DefaultProjectFolder);
                    }
                    else
                    {
                        return;
                    }
                }

                // Get validate scene path info
                string[] sceneInfo = GetSceneInfomation(true);
                string sceneName = sceneInfo[0];
                string scenePath = sceneInfo[1];
                string scriptPath = sceneInfo[2];
                string outputFile = sceneInfo[3];
                string projectScript = sceneInfo[4];
                if (!ExporterWindow.ShowMessage("Export current scene to babylon: " + sceneName, "Babylon.js", "Export"))
                {
                    return;
                }

                // Save current scene info
                SaveSettings();
                ExporterWindow.logs.Clear();
                Stopwatch watch = new Stopwatch();
                watch.Start();
                ReportProgress(0, "Exporting " + scenePath);

                // Auto lightmap baking
                if (exportationOptions.ExportLightmaps && exportationOptions.DefaultLightmapBaking == (int)BabylonLightmapBaking.Enabled)
                {
                    ReportProgress(1, "Baking lightmap textures... This may take a while.");
                    Lightmapping.GIWorkflowMode workflow = Lightmapping.giWorkflowMode;
                    Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
                    Lightmapping.Bake();
                    Lightmapping.giWorkflowMode = workflow;
                }

                // Save all open scenes
                ReportProgress(1, "Saving open scene information...");
                UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();

                // Build project preview
                if (preview)
                {
                    Tools.GenerateProjectIndexPage(exportationOptions.DefaultProjectFolder, exportationOptions.ShowDebugControls, exportationOptions.DefaultScenePath, Path.GetFileName(outputFile), exportationOptions.DefaultScriptPath, Path.GetFileName(projectScript));
                    if (exportationOptions.BuildJavaScript || exportationOptions.CompileTypeScript)
                    {
                        Build(false, sceneInfo);
                    }
                }

                // Build current scene
                BabylonSceneController sceneController = Tools.GetSceneController();
                var sceneBuilder = new SceneBuilder(scenePath, sceneName, exportationOptions, sceneController, scriptPath);
                sceneBuilder.ConvertFromUnity();

                ReportProgress(1, "Generating babylon scene... This may take a while.");
                sceneBuilder.WriteToBabylonFile(outputFile);

                watch.Stop();
                ReportProgress(1, string.Format("Exportation done in {0:0.00}s", watch.Elapsed.TotalSeconds));
                EditorUtility.ClearProgressBar();

                sceneBuilder.GenerateStatus(logs);

                string done = preview ? "Preview" : "OK";
                bool ok = ShowMessage("Scene exportation complete.", "Babylon.js", done);
                if (preview && ok)
                {
                    Preview();
                }
            }
            catch (Exception ex)
            {
                EditorUtility.ClearProgressBar();
                ShowMessage("A problem occurred: " + ex.Message + ex.StackTrace, "Error");
            }
        }
Exemplo n.º 6
0
        public void Export()
        {
            try
            {
                int pos = EditorApplication.currentScene.LastIndexOf("/", StringComparison.Ordinal);
                string sceneName = EditorApplication.currentScene.Substring(pos + 1);

                exportationOptions.DefaultFolder = EditorUtility.SaveFolderPanel("Please select a folder", exportationOptions.DefaultFolder, "");

                if (string.IsNullOrEmpty(exportationOptions.DefaultFolder))
                {
                    return;
                }

                Stopwatch watch = new Stopwatch();

                watch.Start();

                var jsWriter = new JsonWriter();                
                File.WriteAllText("Unity3D2Babylon.ini", jsWriter.Write(exportationOptions));
                logs.Clear();

                ReportProgress(0);

                var sceneBuilder = new SceneBuilder(exportationOptions.DefaultFolder, sceneName, exportationOptions);

                sceneBuilder.ConvertFromUnity();

                ReportProgress(1, "Generating output file");
                sceneBuilder.WriteToBabylonFile();

                watch.Stop();
                ReportProgress(1, string.Format("Exportation done in {0:0.00}s", watch.Elapsed.TotalSeconds));
                EditorUtility.ClearProgressBar();

                sceneBuilder.GenerateStatus(logs);

                ShowMessage("Exportation done");
            }
            catch (Exception ex)
            {
                EditorUtility.ClearProgressBar();
                ShowMessage("A problem occurred: " + ex.Message + ex.StackTrace, "Error");
            }
        }