Exemplo n.º 1
0
        private void LoadOptions()
        {
            string storedModelPath   = Loader.Core.RootNode.GetStringProperty(ExportParameters.ModelFilePathProperty, string.Empty);
            string absoluteModelPath = Tools.ResolveRelativePath(storedModelPath);

            txtModelPath.MaxPath(absoluteModelPath);

            string storedFolderPath           = Loader.Core.RootNode.GetStringProperty(ExportParameters.TextureFolderPathProperty, string.Empty);
            string absoluteTexturesFolderPath = Tools.ResolveRelativePath(storedFolderPath);

            txtTexturesPath.MaxPath(absoluteTexturesFolderPath);

            singleExportItem = new ExportItem(absoluteModelPath);

            Tools.PrepareCheckBox(chkManifest, Loader.Core.RootNode, "babylonjs_generatemanifest");
            Tools.PrepareCheckBox(chkWriteTextures, Loader.Core.RootNode, "babylonjs_writetextures", 1);
            Tools.PrepareCheckBox(chkOverwriteTextures, Loader.Core.RootNode, "babylonjs_overwritetextures", 1);
            Tools.PrepareCheckBox(chkHidden, Loader.Core.RootNode, "babylonjs_exporthidden");
            Tools.PrepareCheckBox(chkAutoSave, Loader.Core.RootNode, "babylonjs_autosave", 1);
            Tools.PrepareCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
            Tools.PrepareCheckBox(chkExportTangents, Loader.Core.RootNode, "babylonjs_exporttangents");
            Tools.PrepareComboBox(comboOutputFormat, Loader.Core.RootNode, "babylonjs_outputFormat", "babylon");
            Tools.PrepareTextBox(txtScaleFactor, Loader.Core.RootNode, "babylonjs_txtScaleFactor", "1");
            Tools.PrepareTextBox(txtQuality, Loader.Core.RootNode, "babylonjs_txtCompression", "100");
            Tools.PrepareCheckBox(chkMergeAOwithMR, Loader.Core.RootNode, "babylonjs_mergeAOwithMR", 1);
            Tools.PrepareCheckBox(chkDracoCompression, Loader.Core.RootNode, "babylonjs_dracoCompression", 0);
            Tools.PrepareCheckBox(chkKHRLightsPunctual, Loader.Core.RootNode, "babylonjs_khrLightsPunctual");
            Tools.PrepareCheckBox(chkKHRTextureTransform, Loader.Core.RootNode, "babylonjs_khrTextureTransform");
            Tools.PrepareCheckBox(chkAnimgroupExportNonAnimated, Loader.Core.RootNode, "babylonjs_animgroupexportnonanimated");
            Tools.PrepareCheckBox(chkDoNotOptimizeAnimations, Loader.Core.RootNode, "babylonjs_donotoptimizeanimations");
            Tools.PrepareCheckBox(chkKHRMaterialsUnlit, Loader.Core.RootNode, "babylonjs_khr_materials_unlit");
            Tools.PrepareCheckBox(chkExportMaterials, Loader.Core.RootNode, "babylonjs_export_materials", 1);
            Tools.PrepareCheckBox(chkExportAnimations, Loader.Core.RootNode, "babylonjs_export_animations", 1);
            Tools.PrepareCheckBox(chkExportAnimationsOnly, Loader.Core.RootNode, "babylonjs_export_animations_only");
            Tools.PrepareCheckBox(chkExportMorphTangents, Loader.Core.RootNode, "babylonjs_export_Morph_Tangents", 0);
            Tools.PrepareCheckBox(chkExportMorphNormals, Loader.Core.RootNode, "babylonjs_export_Morph_Normals", 1);
            Tools.PrepareCheckBox(chkExportTextures, Loader.Core.RootNode, "babylonjs_export_Textures", 1);
            Tools.PrepareComboBox(cmbBakeAnimationOptions, Loader.Core.RootNode, "babylonjs_bakeAnimationsType", (int)BakeAnimationType.DoNotBakeAnimation);
            Tools.PrepareCheckBox(chkApplyPreprocessToScene, Loader.Core.RootNode, "babylonjs_applyPreprocess", 0);

            if (comboOutputFormat.SelectedText == "babylon" || comboOutputFormat.SelectedText == "binary babylon" || !gltfPipelineInstalled)
            {
                chkDracoCompression.Checked = false;
                chkDracoCompression.Enabled = false;
            }

            Tools.PrepareCheckBox(chkFullPBR, Loader.Core.RootNode, ExportParameters.PBRFullPropertyName);
            Tools.PrepareCheckBox(chkNoAutoLight, Loader.Core.RootNode, ExportParameters.PBRNoLightPropertyName);
            string storedEnvironmentPath   = Loader.Core.RootNode.GetStringProperty(ExportParameters.PBREnvironmentPathPropertyName, string.Empty);
            string absoluteEnvironmentPath = Tools.ResolveRelativePath(storedEnvironmentPath);

            txtEnvironmentName.MaxPath(absoluteEnvironmentPath);

            Tools.PrepareCheckBox(chkUsePreExportProces, Loader.Core.RootNode, "babylonjs_preproces", 0);
            Tools.PrepareCheckBox(chkFlatten, Loader.Core.RootNode, "babylonjs_flattenScene", 0);
            Tools.PrepareCheckBox(chkMrgContainersAndXref, Loader.Core.RootNode, "babylonjs_mergecontainersandxref", 0);
        }
Exemplo n.º 2
0
        private ExportItem AddExportItem(DataGridViewRow row, string exportPath)
        {
            ExportItem item = new ExportItem(exportItemList.OutputFileExtension);

            item.SetExportFilePath(GetUniqueExportPath(exportPath));
            item.Selected = row.Cells[0].Value == null ? Default_ExportItemSelected : (bool)row.Cells[0].Value;
            exportItemList.Add(item);
            return(item);
        }
Exemplo n.º 3
0
        private void ExportItemGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            var        row  = ExportItemGridView.Rows[e.RowIndex];
            ExportItem item = row.Tag as ExportItem;

            if (e.ColumnIndex == ColumnExportCheckbox.Index)
            {
                if (item != null)
                {
                    item.Selected = row.Cells[0].Value == null ? Default_ExportItemSelected : (bool)row.Cells[0].Value;
                }
            }
            if (e.ColumnIndex == ColumnKeepPositionCheckbox.Index)
            {
                if (item != null)
                {
                    item.KeepPosition = row.Cells[e.ColumnIndex].Value == null ? Default_KeepPosition : (bool)row.Cells[e.ColumnIndex].Value;
                }
            }
            if (e.ColumnIndex == ColumnFilePath.Index)
            {
                string str = row.Cells[e.ColumnIndex].Value as string;

                if (item == null)
                {
                    item = AddExportItem(row, str);
                }
                else
                {
                    item.SetExportFilePath(str);
                }

                SetRowData(row, item);
            }

            if (e.ColumnIndex == ColumnTexturesFolder.Index)
            {
                string str = row.Cells[e.ColumnIndex].Value as string;

                if (item == null)
                {
                    item = AddExportItem(row, str);
                }
                else
                {
                    item.SetExportTexturesFolderPath(str);
                }

                SetRowData(row, item);
            }
        }
 public void DeepCopyFrom(ExportItem other)
 {
     outputFileExt      = other.outputFileExt;
     exportPathAbsolute = other.exportPathAbsolute;
     exportPathRelative = other.exportPathRelative;
     exportNodeHandle   = other.exportNodeHandle;
     NodeName           = other.NodeName;
     selected           = other.selected;
     IsDirty            = true;
 }
Exemplo n.º 5
0
 private void SetRowData(DataGridViewRow row, ExportItem item)
 {
     row.Tag            = item;
     row.Cells[0].Value = item.Selected;
     row.Cells[1].Value = item.LayersToString(item.Layers);
     row.Cells[2].Value = item.NodeName;
     row.Cells[3].Value = item.ExportFilePathAbsolute;
     row.Cells[4].Value = item.ExportTexturesesFolderPath;
     Refresh();
 }
Exemplo n.º 6
0
        private void ExportItemGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            // double-clicked node column cell, select a node!
            if (e.ColumnIndex == ColumnNode.Index)
            {
                if (Loader.Core.DoHitByNameDialog(null) && Loader.Core.SelNodeCount > 0)
                {
                    int        highestRowIndexEdited = e.RowIndex;
                    var        selectedRow           = ExportItemGridView.Rows[e.RowIndex];
                    ExportItem existingItem          = selectedRow.Tag as ExportItem;
                    IINode     node = Loader.Core.GetSelNode(0);

                    if (existingItem == null)
                    {
                        existingItem = TryAddExportItem(selectedRow, node.Handle);
                    }
                    else
                    {
                        existingItem.NodeHandle = node.Handle;
                    }

                    // may be null after trying to add a node that already exists in another row
                    if (existingItem != null)
                    {
                        SetRowData(selectedRow, existingItem);
                    }

                    // add remaining selected nodes as new rows
                    for (int i = 1; i < Loader.Core.SelNodeCount; ++i)
                    {
                        int rowIndex = ExportItemGridView.Rows.Add();
                        var newRow   = ExportItemGridView.Rows[rowIndex];

                        ExportItem newItem = TryAddExportItem(newRow, Loader.Core.GetSelNode(i).Handle);

                        // may be null after trying to add a node that already exists in another row
                        if (newItem == null)
                        {
                            continue;
                        }

                        SetRowData(newRow, newItem);
                        highestRowIndexEdited = rowIndex;
                    }

                    // have to explicitly set it dirty for an edge case:
                    // when a new row is added "automatically-programmatically", through notify cell dirty and endedit(),
                    //   if the user then clicks on the checkbox of the newly added row,
                    //     it doesn't add a new row "automatically", whereas otherwise it will.
                    ExportItemGridView.CurrentCell = ExportItemGridView[e.ColumnIndex, highestRowIndexEdited];
                    ExportItemGridView.NotifyCurrentCellDirty(true);
                    ExportItemGridView.EndEdit();
                }
            }
        }
Exemplo n.º 7
0
        private void SetRowData(DataGridViewRow row, ExportItem item)
        {
            row.Tag = item;
            var i = 0;

            row.Cells[i++].Value = item.Selected;
            row.Cells[i++].Value = item.KeepPosition;
            row.Cells[i++].Value = item.LayersToString(item.Layers);
            row.Cells[i++].Value = item.NodeName;
            row.Cells[i++].Value = item.ExportFilePathAbsolute;
            row.Cells[i].Value   = item.ExportTexturesesFolderAbsolute;
            Refresh();
        }
Exemplo n.º 8
0
        private async Task <bool> DoExport(ExportItem exportItem, bool multiExport = false)
        {
            new BabylonAnimationActionItem().Close();

            exporter = new BabylonExporter(logger);

            butExport.Enabled = false;
            butCancel.Enabled = true;

            bool success = true;

            try
            {
                string modelAbsolutePath = multiExport ? exportItem.ExportFilePathAbsolute : txtModelPath.Text;
                string textureExportPath = multiExport ? exportItem.ExportTexturesesFolderAbsolute : txtTexturesPath.Text;

                exportParameters.outputPath       = modelAbsolutePath;
                exportParameters.textureFolder    = textureExportPath;
                exportParameters.exportNode       = exportItem?.Node;
                exportParameters.exportLayers     = exportItem?.Layers;
                exportParameters.useMultiExporter = multiExport;

                exporter.callerForm = this;

                exporter.Export(exportParameters);
            }
            catch (OperationCanceledException)
            {
                progressBar.Value = 0;
                success           = false;;
            }
            catch (Exception ex)
            {
                IUTF8Str operationStatus = GlobalInterface.Instance.UTF8Str.Create("BabylonExportAborted");
                Loader.Global.BroadcastNotification(SystemNotificationCode.PreExport, operationStatus);

                currentNode = CreateTreeNode(0, "Export cancelled: " + ex.Message, Color.Red);
                currentNode = CreateTreeNode(1, ex.ToString(), Color.Red);
                currentNode.EnsureVisible();

                progressBar.Value = 0;
                success           = false;
            }

            butCancel.Enabled = false;
            butExport.Enabled = true;

            BringToFront();

            return(success);
        }
Exemplo n.º 9
0
        private ExportItem TryAddExportItem(DataGridViewRow row, List <IILayer> iLayers)
        {
            foreach (ExportItem existingItem in exportItemList)
            {
                if (existingItem.Layers == iLayers)
                {
                    return(null);
                }
            }

            ExportItem item = new ExportItem(iLayers);

            item.NodeHandle = Loader.Core.RootNode.Handle;
            item.Selected   = row.Cells[0].Value == null ? Default_ExportItemSelected : (bool)row.Cells[0].Value;
            exportItemList.Add(item);
            return(item);
        }
Exemplo n.º 10
0
        //! Add a new export item. Returns null if the given handle already exists in the export item list.
        private ExportItem TryAddExportItem(DataGridViewRow row, uint nodeHandle, string exportPath = null)
        {
            foreach (ExportItem existingItem in exportItemList)
            {
                if (existingItem.NodeHandle == nodeHandle)
                {
                    return(null);
                }
            }

            ExportItem item = new ExportItem(exportItemList.OutputFileExtension, nodeHandle);

            item.SetExportFilePath(GetUniqueExportPath(exportPath != null ? exportPath : item.ExportFilePathRelative));
            item.Selected = row.Cells[0].Value == null ? Default_ExportItemSelected : (bool)row.Cells[0].Value;
            exportItemList.Add(item);
            return(item);
        }
Exemplo n.º 11
0
        private void ExporterForm_Load(object sender, EventArgs e)
        {
            string storedModelPath  = Loader.Core.RootNode.GetStringProperty(ExportParameters.ModelFilePathProperty, string.Empty);
            string userRelativePath = Tools.ResolveRelativePath(storedModelPath);

            txtModelName.Text = userRelativePath;
            string absoluteModelPath = Tools.UnformatPath(txtModelName.Text);

            singleExportItem = new ExportItem(absoluteModelPath);

            string storedFolderPath   = Loader.Core.RootNode.GetStringProperty(ExportParameters.TextureFolderPathProperty, string.Empty);
            string formatedFolderPath = Tools.ResolveRelativePath(storedFolderPath);

            txtTextureName.Text = formatedFolderPath;

            Tools.PrepareCheckBox(chkManifest, Loader.Core.RootNode, "babylonjs_generatemanifest");
            Tools.PrepareCheckBox(chkWriteTextures, Loader.Core.RootNode, "babylonjs_writetextures", 1);
            Tools.PrepareCheckBox(chkOverwriteTextures, Loader.Core.RootNode, "babylonjs_overwritetextures", 1);
            Tools.PrepareCheckBox(chkHidden, Loader.Core.RootNode, "babylonjs_exporthidden");
            Tools.PrepareCheckBox(chkAutoSave, Loader.Core.RootNode, "babylonjs_autosave", 1);
            Tools.PrepareCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
            Tools.PrepareCheckBox(chkExportTangents, Loader.Core.RootNode, "babylonjs_exporttangents");
            Tools.PrepareComboBox(comboOutputFormat, Loader.Core.RootNode, "babylonjs_outputFormat", "babylon");
            Tools.PrepareTextBox(txtScaleFactor, Loader.Core.RootNode, "babylonjs_txtScaleFactor", "1");
            Tools.PrepareTextBox(txtQuality, Loader.Core.RootNode, "babylonjs_txtCompression", "100");
            Tools.PrepareCheckBox(chkMergeAOwithMR, Loader.Core.RootNode, "babylonjs_mergeAOwithMR", 1);
            Tools.PrepareCheckBox(chkDracoCompression, Loader.Core.RootNode, "babylonjs_dracoCompression", 0);
            Tools.PrepareCheckBox(chkKHRLightsPunctual, Loader.Core.RootNode, "babylonjs_khrLightsPunctual");
            Tools.PrepareCheckBox(chkKHRTextureTransform, Loader.Core.RootNode, "babylonjs_khrTextureTransform");
            Tools.PrepareCheckBox(chkKHRMaterialsUnlit, Loader.Core.RootNode, "babylonjs_khr_materials_unlit");
            Tools.PrepareCheckBox(chkExportMaterials, Loader.Core.RootNode, "babylonjs_export_materials", 1);

            if (comboOutputFormat.SelectedText == "babylon" || comboOutputFormat.SelectedText == "binary babylon" || !gltfPipelineInstalled)
            {
                chkDracoCompression.Checked = false;
                chkDracoCompression.Enabled = false;
            }

            Tools.PrepareCheckBox(chkFullPBR, Loader.Core.RootNode, ExportParameters.PBRFullPropertyName);
            Tools.PrepareCheckBox(chkNoAutoLight, Loader.Core.RootNode, ExportParameters.PBRNoLightPropertyName);
            string storedEnvironmentPath   = Loader.Core.RootNode.GetStringProperty(ExportParameters.PBREnvironmentPathPropertyName, string.Empty);
            string formatedEnvironmentPath = Tools.ResolveRelativePath(storedEnvironmentPath);

            txtEnvironmentName.Text = formatedEnvironmentPath;
        }
Exemplo n.º 12
0
        private void SceneExplorerOnClosed(object sender, EventArgs e)
        {
            List <IILayer> selectedLayers = layerSelector.SelectedLayers;

            if (selectedLayers.Count > 0)
            {
                int highestRowIndexEdited = layersRowIndex;
                var selectedRow           = ExportItemGridView.Rows[layersRowIndex];


                ExportItem existingItem = selectedRow.Tag as ExportItem;

                if (existingItem == null)
                {
                    existingItem = TryAddExportItem(selectedRow, selectedLayers);
                }
                else
                {
                    existingItem.SetExportLayers(selectedLayers);
                }

                // may be null after trying to add a node that already exists in another row
                if (existingItem != null)
                {
                    SetRowData(selectedRow, existingItem);
                }

                // have to explicitly set it dirty for an edge case:
                // when a new row is added "automatically-programmatically", through notify cell dirty and endedit(),
                //   if the user then clicks on the checkbox of the newly added row,
                //     it doesn't add a new row "automatically", whereas otherwise it will.
                ExportItemGridView.CurrentCell = ExportItemGridView[layersColumnIndex, highestRowIndexEdited];
                ExportItemGridView.NotifyCurrentCellDirty(true);
                ExportItemGridView.EndEdit();
            }
        }
Exemplo n.º 13
0
        private async Task <bool> DoExport(ExportItem exportItem, bool multiExport = false, bool clearLogs = true)
        {
            new BabylonAnimationActionItem().Close();
            SaveOptions();

            //store layer visibility status and force visibility on

            Dictionary <IILayer, bool> layerState = new Dictionary <IILayer, bool>();

            if (exportItem.Layers != null)
            {
                foreach (IILayer layer in exportItem.Layers)
                {
                    List <IILayer> treeLayers = layer.LayerTree().ToList();
                    treeLayers.Add(layer);

                    foreach (IILayer l in treeLayers)
                    {
#if MAX2015
                        layerState.Add(l, l.IsHidden);
#else
                        layerState.Add(l, l.IsHidden(false));
#endif
                        l.Hide(false, false);
                    }
                }
            }

            exporter = new BabylonExporter();

            if (clearLogs)
            {
                treeView.Nodes.Clear();
            }

            exporter.OnExportProgressChanged += progress =>
            {
                progressBar.Value = progress;
                Application.DoEvents();
            };

            exporter.OnWarning += (warning, rank) => CreateWarningMessage(warning, rank);

            exporter.OnError += (error, rank) => CreateErrorMessage(error, rank);

            exporter.OnMessage += (message, color, rank, emphasis) => CreateMessage(message, color, rank, emphasis);

            exporter.OnVerbose += (message, color, rank, emphasis) =>
            {
                try
                {
                    currentNode = CreateTreeNode(rank, message, color);

                    if (emphasis)
                    {
                        currentNode.EnsureVisible();
                    }
                }
                catch
                {
                    //do nothing
                }
                Application.DoEvents();
            };

            butExport.Enabled       = false;
            butExportAndRun.Enabled = false;
            butMultiExport.Enabled  = false;
            butCancel.Enabled       = true;

            bool success = true;
            try
            {
                string modelAbsolutePath = multiExport ? exportItem.ExportFilePathAbsolute : txtModelPath.Text;
                string textureExportPath = multiExport ? exportItem.ExportTexturesesFolderAbsolute : txtTexturesPath.Text;

                var scaleFactorParsed    = 1.0f;
                var textureQualityParsed = 100L;
                try
                {
                    scaleFactorParsed = float.Parse(txtScaleFactor.Text);
                }
                catch (Exception e)
                {
                    throw new InvalidDataException(String.Format("Invalid Scale Factor value: {0}", txtScaleFactor.Text));
                }
                try
                {
                    textureQualityParsed = long.Parse(txtQuality.Text);
                }
                catch (Exception e)
                {
                    throw new InvalidDataException(String.Format("Invalid Texture Quality value: {0}", txtScaleFactor.Text));
                }

                MaxExportParameters exportParameters = new MaxExportParameters
                {
                    outputPath                 = modelAbsolutePath,
                    textureFolder              = textureExportPath,
                    outputFormat               = comboOutputFormat.SelectedItem.ToString(),
                    scaleFactor                = scaleFactorParsed,
                    writeTextures              = chkWriteTextures.Enabled && chkWriteTextures.Checked,
                    overwriteTextures          = chkOverwriteTextures.Enabled && chkOverwriteTextures.Checked,
                    exportHiddenObjects        = chkHidden.Checked,
                    exportOnlySelected         = chkOnlySelected.Checked,
                    generateManifest           = chkManifest.Checked,
                    autoSaveSceneFile          = chkAutoSave.Checked,
                    exportTangents             = chkExportTangents.Checked,
                    exportMorphTangents        = chkExportMorphTangents.Checked,
                    exportMorphNormals         = chkExportMorphNormals.Checked,
                    txtQuality                 = textureQualityParsed,
                    mergeAOwithMR              = chkMergeAOwithMR.Enabled && chkMergeAOwithMR.Checked,
                    bakeAnimationType          = (BakeAnimationType)cmbBakeAnimationOptions.SelectedIndex,
                    dracoCompression           = chkDracoCompression.Enabled && chkDracoCompression.Checked,
                    enableKHRLightsPunctual    = chkKHRLightsPunctual.Checked,
                    enableKHRTextureTransform  = chkKHRTextureTransform.Checked,
                    enableKHRMaterialsUnlit    = chkKHRMaterialsUnlit.Checked,
                    exportMaterials            = chkExportMaterials.Enabled && chkExportMaterials.Checked,
                    exportAnimations           = chkExportAnimations.Checked,
                    exportAnimationsOnly       = chkExportAnimationsOnly.Checked,
                    optimizeAnimations         = !chkDoNotOptimizeAnimations.Checked,
                    animgroupExportNonAnimated = chkAnimgroupExportNonAnimated.Checked,
                    exportNode                 = exportItem?.Node,
                    exportLayers               = exportItem?.Layers,
                    pbrNoLight                 = chkNoAutoLight.Checked,
                    pbrFull                = chkFullPBR.Checked,
                    pbrEnvironment         = txtEnvironmentName.Text,
                    usePreExportProcess    = chkUsePreExportProces.Checked,
                    flattenScene           = chkFlatten.Enabled && chkFlatten.Checked,
                    mergeContainersAndXRef = chkMrgContainersAndXref.Checked,
                    useMultiExporter       = multiExport
                };

                exporter.callerForm = this;

                exporter.Export(exportParameters);
            }
            catch (OperationCanceledException)
            {
                progressBar.Value = 0;
                success           = false;
                ScriptsUtilities.ExecuteMaxScriptCommand(@"global BabylonExporterStatus = ""Available""");
            }
            catch (Exception ex)
            {
                IUTF8Str operationStatus = GlobalInterface.Instance.UTF8Str.Create("BabylonExportAborted");
                Loader.Global.BroadcastNotification(SystemNotificationCode.PreExport, operationStatus);

                currentNode = CreateTreeNode(0, "Export cancelled: " + ex.Message, Color.Red);
                currentNode = CreateTreeNode(1, ex.ToString(), Color.Red);
                currentNode.EnsureVisible();

                progressBar.Value = 0;
                success           = false;
                ScriptsUtilities.ExecuteMaxScriptCommand(@"global BabylonExporterStatus = Available");
            }

            butCancel.Enabled       = false;
            butExport.Enabled       = true;
            butMultiExport.Enabled  = true;
            butExportAndRun.Enabled = WebServer.IsSupported;

            BringToFront();

            //re-store layer visibility status
            if (exportItem.Layers != null)
            {
                foreach (IILayer layer in exportItem.Layers)
                {
                    List <IILayer> treeLayers = layer.LayerTree().ToList();
                    treeLayers.Add(layer);
                    foreach (IILayer l in treeLayers)
                    {
                        bool exist;
                        layerState.TryGetValue(l, out exist);
                        if (exist)
                        {
                            l.Hide(layerState[l], false);
                        }
                    }
                }
            }

            return(success);
        }
Exemplo n.º 14
0
        private void ExportItemGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            // double-clicked node column cell, select a node!
            if (e.ColumnIndex == ColumnNode.Index)
            {
                if (Loader.Core.DoHitByNameDialog(null) && Loader.Core.SelNodeCount > 0)
                {
                    int        highestRowIndexEdited = e.RowIndex;
                    var        selectedRow           = ExportItemGridView.Rows[e.RowIndex];
                    ExportItem existingItem          = selectedRow.Tag as ExportItem;
                    IINode     node = Loader.Core.GetSelNode(0);

                    if (existingItem == null)
                    {
                        existingItem = TryAddExportItem(selectedRow, node.Handle);
                    }
                    else
                    {
                        if (existingItem.Layers != null && existingItem.Layers.Count > 0)
                        {
                            MessageBox.Show("You can't specify a Node when export is layer based");
                            return;
                        }
                        existingItem.NodeHandle = node.Handle;
                    }

                    // may be null after trying to add a node that already exists in another row
                    if (existingItem != null)
                    {
                        SetRowData(selectedRow, existingItem);
                    }

                    // add remaining selected nodes as new rows
                    for (int i = 1; i < Loader.Core.SelNodeCount; ++i)
                    {
                        int rowIndex = ExportItemGridView.Rows.Add();
                        var newRow   = ExportItemGridView.Rows[rowIndex];

                        ExportItem newItem = TryAddExportItem(newRow, Loader.Core.GetSelNode(i).Handle);

                        // may be null after trying to add a node that already exists in another row
                        if (newItem == null)
                        {
                            continue;
                        }

                        SetRowData(newRow, newItem);
                        highestRowIndexEdited = rowIndex;
                    }

                    // have to explicitly set it dirty for an edge case:
                    // when a new row is added "automatically-programmatically", through notify cell dirty and endedit(),
                    //   if the user then clicks on the checkbox of the newly added row,
                    //     it doesn't add a new row "automatically", whereas otherwise it will.
                    ExportItemGridView.CurrentCell = ExportItemGridView[e.ColumnIndex, highestRowIndexEdited];
                    ExportItemGridView.NotifyCurrentCellDirty(true);
                    ExportItemGridView.EndEdit();
                }
            }


            // double-clicked layers column cell, select some layers!
            if (e.ColumnIndex == ColumnLayers.Index)
            {
                layersRowIndex    = e.RowIndex;
                layersColumnIndex = e.ColumnIndex;
                ExportItem existingItem = ExportItemGridView.Rows[layersRowIndex].Tag as ExportItem;
                if (layerSelector == null || layerSelector.IsDisposed)
                {
                    layerSelector = new LayerSelector();
                    layerSelector.Show();
                    layerSelector.FillLayerSelector(existingItem?.Layers);

                    layerSelector.OnConfirmButtonClicked += LayerExplorerClosed;
                }
                else
                {
                    layerSelector.Focus();
                }
            }
        }
Exemplo n.º 15
0
        private async Task <bool> DoExport(ExportItem exportItem = null, bool clearLogs = true)
        {
            Tools.UpdateCheckBox(chkManifest, Loader.Core.RootNode, "babylonjs_generatemanifest");
            Tools.UpdateCheckBox(chkWriteTextures, Loader.Core.RootNode, "babylonjs_writetextures");
            Tools.UpdateCheckBox(chkOverwriteTextures, Loader.Core.RootNode, "babylonjs_overwritetextures");
            Tools.UpdateCheckBox(chkHidden, Loader.Core.RootNode, "babylonjs_exporthidden");
            Tools.UpdateCheckBox(chkAutoSave, Loader.Core.RootNode, "babylonjs_autosave");
            Tools.UpdateCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
            Tools.UpdateCheckBox(chkExportTangents, Loader.Core.RootNode, "babylonjs_exporttangents");
            Tools.UpdateComboBox(comboOutputFormat, Loader.Core.RootNode, "babylonjs_outputFormat");
            Tools.UpdateTextBox(txtScaleFactor, Loader.Core.RootNode, "babylonjs_txtScaleFactor");
            Tools.UpdateTextBox(txtQuality, Loader.Core.RootNode, "babylonjs_txtCompression");
            Tools.UpdateCheckBox(chkMergeAOwithMR, Loader.Core.RootNode, "babylonjs_mergeAOwithMR");
            Tools.UpdateCheckBox(chkDracoCompression, Loader.Core.RootNode, "babylonjs_dracoCompression");
            Tools.UpdateCheckBox(chkKHRTextureTransform, Loader.Core.RootNode, "babylonjs_khrTextureTransform");
            Tools.UpdateCheckBox(chkKHRLightsPunctual, Loader.Core.RootNode, "babylonjs_khrLightsPunctual");
            Tools.UpdateCheckBox(chkKHRMaterialsUnlit, Loader.Core.RootNode, "babylonjs_khr_materials_unlit");
            Tools.UpdateCheckBox(chkExportMaterials, Loader.Core.RootNode, "babylonjs_export_materials");

            Loader.Core.RootNode.SetLocalData(txtFilename.Text);

            exporter = new BabylonExporter();

            if (clearLogs)
            {
                treeView.Nodes.Clear();
            }

            exporter.OnImportProgressChanged += progress =>
            {
                progressBar.Value = progress;
                Application.DoEvents();
            };

            exporter.OnWarning += (warning, rank) =>
            {
                try
                {
                    currentNode = CreateTreeNode(rank, warning, Color.DarkOrange);
                    currentNode.EnsureVisible();
                }
                catch
                {
                }
                Application.DoEvents();
            };

            exporter.OnError += (error, rank) =>
            {
                try
                {
                    currentNode = CreateTreeNode(rank, error, Color.Red);
                    currentNode.EnsureVisible();
                }
                catch
                {
                }
                Application.DoEvents();
            };

            exporter.OnMessage += (message, color, rank, emphasis) =>
            {
                try
                {
                    currentNode = CreateTreeNode(rank, message, color);

                    if (emphasis)
                    {
                        currentNode.EnsureVisible();
                    }
                }
                catch
                {
                }
                Application.DoEvents();
            };

            butExport.Enabled       = false;
            butExportAndRun.Enabled = false;
            butMultiExport.Enabled  = false;
            butCancel.Enabled       = true;

            bool success = true;

            try
            {
                ExportParameters exportParameters = new ExportParameters
                {
                    outputPath                = exportItem != null ? exportItem.ExportFilePathAbsolute : txtFilename.Text,
                    outputFormat              = comboOutputFormat.SelectedItem.ToString(),
                    scaleFactor               = txtScaleFactor.Text,
                    writeTextures             = chkWriteTextures.Checked,
                    overwriteTextures         = chkOverwriteTextures.Checked,
                    exportHiddenObjects       = chkHidden.Checked,
                    exportOnlySelected        = chkOnlySelected.Checked,
                    generateManifest          = chkManifest.Checked,
                    autoSave3dsMaxFile        = chkAutoSave.Checked,
                    exportTangents            = chkExportTangents.Checked,
                    txtQuality                = txtQuality.Text,
                    mergeAOwithMR             = chkMergeAOwithMR.Checked,
                    dracoCompression          = chkDracoCompression.Checked,
                    enableKHRLightsPunctual   = chkKHRLightsPunctual.Checked,
                    enableKHRTextureTransform = chkKHRTextureTransform.Checked,
                    enableKHRMaterialsUnlit   = chkKHRMaterialsUnlit.Checked,
                    exportMaterials           = chkExportMaterials.Checked,
                    exportNode                = exportItem != null ? exportItem.Node : null
                };

                exporter.callerForm = this;

                exporter.Export(exportParameters);
            }
            catch (OperationCanceledException)
            {
                progressBar.Value = 0;
                success           = false;
            }
            catch (Exception ex)
            {
                IUTF8Str operationStatus = GlobalInterface.Instance.UTF8Str.Create("BabylonExportAborted");
                Loader.Global.BroadcastNotification(SystemNotificationCode.PreExport, operationStatus);

                currentNode = CreateTreeNode(0, "Export cancelled: " + ex.Message, Color.Red);
                currentNode = CreateTreeNode(1, ex.ToString(), Color.Red);
                currentNode.EnsureVisible();

                progressBar.Value = 0;
                success           = false;
            }

            butCancel.Enabled       = false;
            butExport.Enabled       = true;
            butMultiExport.Enabled  = true;
            butExportAndRun.Enabled = WebServer.IsSupported;

            BringToFront();

            return(success);
        }
 public ExportItem(ExportItem other)
 {
     DeepCopyFrom(other);
 }
Exemplo n.º 17
0
        private async Task <bool> DoExport(ExportItem exportItem, bool multiExport = false, bool clearLogs = true)
        {
            SaveOptions();

            exporter = new BabylonExporter();

            if (clearLogs)
            {
                treeView.Nodes.Clear();
            }

            exporter.OnImportProgressChanged += progress =>
            {
                progressBar.Value = progress;
                Application.DoEvents();
            };

            exporter.OnWarning += (warning, rank) =>
            {
                try
                {
                    currentNode = CreateTreeNode(rank, warning, Color.DarkOrange);
                    currentNode.EnsureVisible();
                }
                catch
                {
                }
                Application.DoEvents();
            };

            exporter.OnError += (error, rank) =>
            {
                try
                {
                    currentNode = CreateTreeNode(rank, error, Color.Red);
                    currentNode.EnsureVisible();
                }
                catch
                {
                }
                Application.DoEvents();
            };

            exporter.OnMessage += (message, color, rank, emphasis) =>
            {
                try
                {
                    currentNode = CreateTreeNode(rank, message, color);

                    if (emphasis)
                    {
                        currentNode.EnsureVisible();
                    }
                }
                catch
                {
                }
                Application.DoEvents();
            };

            butExport.Enabled       = false;
            butExportAndRun.Enabled = false;
            butMultiExport.Enabled  = false;
            butCancel.Enabled       = true;

            bool success = true;

            try
            {
                string modelAbsolutePath             = multiExport ? exportItem.ExportFilePathAbsolute : txtModelName.Text;
                string textureExportPath             = multiExport ? exportItem.ExportTexturesesFolderPath : txtTextureName.Text;
                MaxExportParameters exportParameters = new MaxExportParameters
                {
                    outputPath                 = modelAbsolutePath,
                    textureFolder              = textureExportPath,
                    outputFormat               = comboOutputFormat.SelectedItem.ToString(),
                    scaleFactor                = float.Parse(txtScaleFactor.Text),
                    writeTextures              = chkWriteTextures.Checked,
                    overwriteTextures          = chkOverwriteTextures.Checked,
                    exportHiddenObjects        = chkHidden.Checked,
                    exportOnlySelected         = chkOnlySelected.Checked,
                    generateManifest           = chkManifest.Checked,
                    autoSaveSceneFile          = chkAutoSave.Checked,
                    exportTangents             = chkExportTangents.Checked,
                    exportMorphTangents        = chkExportMorphTangents.Checked,
                    exportMorphNormals         = chkExportMorphNormals.Checked,
                    txtQuality                 = long.Parse(txtQuality.Text),
                    mergeAOwithMR              = chkMergeAOwithMR.Checked,
                    dracoCompression           = chkDracoCompression.Checked,
                    enableKHRLightsPunctual    = chkKHRLightsPunctual.Checked,
                    enableKHRTextureTransform  = chkKHRTextureTransform.Checked,
                    enableKHRMaterialsUnlit    = chkKHRMaterialsUnlit.Checked,
                    exportMaterials            = chkExportMaterials.Checked,
                    optimizeAnimations         = !chkDoNotOptimizeAnimations.Checked,
                    animgroupExportNonAnimated = chkAnimgroupExportNonAnimated.Checked,
                    exportNode                 = exportItem != null ? exportItem.Node : null,
                    pbrNoLight                 = chkNoAutoLight.Checked,
                    pbrFull                  = chkFullPBR.Checked,
                    pbrEnvironment           = txtEnvironmentName.Text,
                    usePreExportProcess      = chkUsePreExportProces.Checked,
                    flattenScene             = chkFlatten.Checked,
                    mergeInheritedContainers = chkMrgInheritedContainers.Checked
                };

                exporter.callerForm = this;

                exporter.Export(exportParameters);
            }
            catch (OperationCanceledException)
            {
                progressBar.Value = 0;
                success           = false;
            }
            catch (Exception ex)
            {
                IUTF8Str operationStatus = GlobalInterface.Instance.UTF8Str.Create("BabylonExportAborted");
                Loader.Global.BroadcastNotification(SystemNotificationCode.PreExport, operationStatus);

                currentNode = CreateTreeNode(0, "Export cancelled: " + ex.Message, Color.Red);
                currentNode = CreateTreeNode(1, ex.ToString(), Color.Red);
                currentNode.EnsureVisible();

                progressBar.Value = 0;
                success           = false;
            }

            butCancel.Enabled       = false;
            butExport.Enabled       = true;
            butMultiExport.Enabled  = true;
            butExportAndRun.Enabled = WebServer.IsSupported;

            BringToFront();

            return(success);
        }
Exemplo n.º 18
0
        private void LoadOptions()
        {
            string storedModelPath   = Loader.Core.RootNode.GetStringProperty(ExportParameters.ModelFilePathProperty, string.Empty);
            string absoluteModelPath = Tools.ResolveRelativePath(storedModelPath);

            txtModelPath.MaxPath(absoluteModelPath);

            string storedFolderPath           = Loader.Core.RootNode.GetStringProperty(ExportParameters.TextureFolderPathProperty, string.Empty);
            string absoluteTexturesFolderPath = Tools.ResolveRelativePath(storedFolderPath);

            txtTexturesPath.MaxPath(absoluteTexturesFolderPath);

            singleExportItem = new ExportItem(absoluteModelPath);

            Tools.PrepareCheckBox(chkManifest, Loader.Core.RootNode, "babylonjs_generatemanifest");
            Tools.PrepareCheckBox(chkWriteTextures, Loader.Core.RootNode, "babylonjs_writetextures", 1);
            Tools.PrepareCheckBox(chkOverwriteTextures, Loader.Core.RootNode, "babylonjs_overwritetextures", 1);
            Tools.PrepareCheckBox(chkHidden, Loader.Core.RootNode, "babylonjs_exporthidden");
            Tools.PrepareCheckBox(chkAutoSave, Loader.Core.RootNode, "babylonjs_autosave", 0);
            Tools.PrepareCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
            Tools.PrepareCheckBox(chkExportAsSubmodel, Loader.Core.RootNode, "flightsim_exportAsSubmodel", 0);
            Tools.PrepareCheckBox(chkExportTangents, Loader.Core.RootNode, "babylonjs_exporttangents", 0);
            Tools.PrepareComboBox(comboOutputFormat, Loader.Core.RootNode, "babylonjs_outputFormat", "gltf");
            Tools.PrepareTextBox(txtScaleFactor, Loader.Core.RootNode, "babylonjs_txtScaleFactor", "1");
            Tools.PrepareTextBox(txtQuality, Loader.Core.RootNode, "babylonjs_txtCompression", "100");
            Tools.PrepareCheckBox(chkMergeAOwithMR, Loader.Core.RootNode, "babylonjs_mergeAOwithMR", 0);
            Tools.PrepareCheckBox(chkDracoCompression, Loader.Core.RootNode, "babylonjs_dracoCompression", 0);
            Tools.PrepareCheckBox(chkKHRLightsPunctual, Loader.Core.RootNode, "babylonjs_khrLightsPunctual");
            Tools.PrepareCheckBox(chkKHRTextureTransform, Loader.Core.RootNode, "babylonjs_khrTextureTransform");
            Tools.PrepareCheckBox(chkKHRMaterialsUnlit, Loader.Core.RootNode, "babylonjs_khr_materials_unlit");
            Tools.PrepareCheckBox(chkExportMaterials, Loader.Core.RootNode, "babylonjs_export_materials", 1);
            Tools.PrepareComboBox(cmbExportAnimationType, Loader.Core.RootNode, "babylonjs_export_animations_type", AnimationExportType.Export.ToString());
            Tools.PrepareCheckBox(chkASBAnimationRetargeting, Loader.Core.RootNode, "babylonjs_asb_animation_retargeting", 1);
            Tools.PrepareCheckBox(chkUniqueID, Loader.Core.RootNode, "flightsim_asb_unique_id", 1);
            Tools.PrepareCheckBox(chkExportMorphTangents, Loader.Core.RootNode, "babylonjs_export_Morph_Tangents", 0);
            Tools.PrepareCheckBox(chkExportMorphNormals, Loader.Core.RootNode, "babylonjs_export_Morph_Normals", 0);
            Tools.PrepareComboBox(cmbBakeAnimationOptions, Loader.Core.RootNode, "babylonjs_bakeAnimationsType", (int)BakeAnimationType.BakeSelective);
            Tools.PrepareCheckBox(chkFlattenGroups, Loader.Core.RootNode, "flightsim_flattenGroups", 0);
            Tools.PrepareCheckBox(chkApplyPreprocessToScene, Loader.Core.RootNode, "babylonjs_applyPreprocess", 0);

            Tools.PrepareCheckBox(chk_RemoveLodPrefix, Loader.Core.RootNode, "flightsim_removelodprefix", 1);
            Tools.PrepareCheckBox(chkRemoveNamespace, Loader.Core.RootNode, "flightsim_removenamespaces", 1);
            Tools.PrepareTextBox(txtSrcTextureExt, Loader.Core.RootNode, "flightsim_texture_destination_extension", string.Empty);
            Tools.PrepareTextBox(txtDstTextureExt, Loader.Core.RootNode, "flightsim_texture_destination_extension", string.Empty);
            Tools.PrepareComboBox(cmbNormalMapConvention, Loader.Core.RootNode, "flightsim_tangent_space_convention", (int)TangentSpaceConvention.DirectX);
            Tools.PrepareCheckBox(chkKeepInstances, Loader.Core.RootNode, "flightsim_keepInstances", 1);

            Tools.PrepareComboBox(logLevelcmb, Loader.Core.RootNode, "babylonjs_logLevel", (int)LogLevel.WARNING);

            if (comboOutputFormat.SelectedText == "babylon" || comboOutputFormat.SelectedText == "binary babylon" || !gltfPipelineInstalled)
            {
                chkDracoCompression.Checked = false;
                chkDracoCompression.Enabled = false;
            }

            Tools.PrepareCheckBox(chkFullPBR, Loader.Core.RootNode, ExportParameters.PBRFullPropertyName);
            Tools.PrepareCheckBox(chkNoAutoLight, Loader.Core.RootNode, ExportParameters.PBRNoLightPropertyName);
            string storedEnvironmentPath   = Loader.Core.RootNode.GetStringProperty(ExportParameters.PBREnvironmentPathPropertyName, string.Empty);
            string absoluteEnvironmentPath = Tools.ResolveRelativePath(storedEnvironmentPath);

            txtEnvironmentName.MaxPath(absoluteEnvironmentPath);

            Tools.PrepareCheckBox(chkUsePreExportProces, Loader.Core.RootNode, "babylonjs_preproces", 0);
            Tools.PrepareCheckBox(chkMrgContainersAndXref, Loader.Core.RootNode, "babylonjs_mergecontainersandxref", 0);
        }
Exemplo n.º 19
0
        private void ExporterForm_Load(object sender, EventArgs e)
        {
            string storedModelPath   = Loader.Core.RootNode.GetStringProperty(ExportParameters.ModelFilePathProperty, string.Empty);
            string absoluteModelPath = Tools.ResolveRelativePath(storedModelPath);

            txtModelName.MaxPath(absoluteModelPath);

            string storedFolderPath           = Loader.Core.RootNode.GetStringProperty(ExportParameters.TextureFolderPathProperty, string.Empty);
            string absoluteTexturesFolderPath = Tools.ResolveRelativePath(storedFolderPath);

            txtTextureName.MaxPath(absoluteTexturesFolderPath);

            singleExportItem = new ExportItem(absoluteModelPath);

            Tools.PrepareCheckBox(chkManifest, Loader.Core.RootNode, "babylonjs_generatemanifest");
            Tools.PrepareCheckBox(chkWriteTextures, Loader.Core.RootNode, "babylonjs_writetextures", 1);
            Tools.PrepareCheckBox(chkOverwriteTextures, Loader.Core.RootNode, "babylonjs_overwritetextures", 1);
            Tools.PrepareCheckBox(chkHidden, Loader.Core.RootNode, "babylonjs_exporthidden");
            Tools.PrepareCheckBox(chkAutoSave, Loader.Core.RootNode, "babylonjs_autosave", 1);
            Tools.PrepareCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
            Tools.PrepareCheckBox(chkExportTangents, Loader.Core.RootNode, "babylonjs_exporttangents");
            Tools.PrepareComboBox(comboOutputFormat, Loader.Core.RootNode, "babylonjs_outputFormat", "babylon");
            Tools.PrepareTextBox(txtScaleFactor, Loader.Core.RootNode, "babylonjs_txtScaleFactor", "1");
            Tools.PrepareTextBox(txtQuality, Loader.Core.RootNode, "babylonjs_txtCompression", "100");
            Tools.PrepareCheckBox(chkMergeAOwithMR, Loader.Core.RootNode, "babylonjs_mergeAOwithMR", 1);
            Tools.PrepareCheckBox(chkDracoCompression, Loader.Core.RootNode, "babylonjs_dracoCompression", 0);
            Tools.PrepareCheckBox(chkKHRLightsPunctual, Loader.Core.RootNode, "babylonjs_khrLightsPunctual");
            Tools.PrepareCheckBox(chkKHRTextureTransform, Loader.Core.RootNode, "babylonjs_khrTextureTransform");
            Tools.PrepareCheckBox(chkAnimgroupExportNonAnimated, Loader.Core.RootNode, "babylonjs_animgroupexportnonanimated");
            Tools.PrepareCheckBox(chkDoNotOptimizeAnimations, Loader.Core.RootNode, "babylonjs_donotoptimizeanimations");
            Tools.PrepareCheckBox(chkKHRMaterialsUnlit, Loader.Core.RootNode, "babylonjs_khr_materials_unlit");
            Tools.PrepareCheckBox(chkExportMaterials, Loader.Core.RootNode, "babylonjs_export_materials", 1);
            Tools.PrepareCheckBox(chkExportMorphTangents, Loader.Core.RootNode, "babylonjs_export_Morph_Tangents", 0);
            Tools.PrepareCheckBox(chkExportMorphNormals, Loader.Core.RootNode, "babylonjs_export_Morph_Normals", 1);
            Tools.PrepareComboBox(cmbBakeAnimationOptions, Loader.Core.RootNode, "babylonjs_bakeAnimationsType", (int)BakeAnimationType.DoNotBakeAnimation);
            Tools.PrepareCheckBox(chkApplyPreprocessToScene, Loader.Core.RootNode, "babylonjs_applyPreprocess", 0);

            if (comboOutputFormat.SelectedText == "babylon" || comboOutputFormat.SelectedText == "binary babylon" || !gltfPipelineInstalled)
            {
                chkDracoCompression.Checked = false;
                chkDracoCompression.Enabled = false;
            }

            Tools.PrepareCheckBox(chkFullPBR, Loader.Core.RootNode, ExportParameters.PBRFullPropertyName);
            Tools.PrepareCheckBox(chkNoAutoLight, Loader.Core.RootNode, ExportParameters.PBRNoLightPropertyName);
            string storedEnvironmentPath   = Loader.Core.RootNode.GetStringProperty(ExportParameters.PBREnvironmentPathPropertyName, string.Empty);
            string absoluteEnvironmentPath = Tools.ResolveRelativePath(storedEnvironmentPath);

            txtEnvironmentName.MaxPath(absoluteEnvironmentPath);

            Tools.PrepareCheckBox(chkUsePreExportProces, Loader.Core.RootNode, "babylonjs_preproces", 0);
            Tools.PrepareCheckBox(chkFlatten, Loader.Core.RootNode, "babylonjs_flattenScene", 0);
            Tools.PrepareCheckBox(chkMrgContainersAndXref, Loader.Core.RootNode, "babylonjs_mergecontainersandxref", 0);

            var maxVersion = Tools.GetMaxVersion();

            if (maxVersion.Major == 22 && maxVersion.Minor < 2)
            {
                CreateErrorMessage("You must update 3dsMax 2020 to version 2020.2 to use Max2Babylon. Unpatched versions of 3dsMax will crash during export.", 0);
            }
            else
            {
                CreateMessage(String.Format("Using Max2Babylon for 3dsMax version v{0}.{1}.{2}.{3}", maxVersion.Major, maxVersion.Minor, maxVersion.Revision, maxVersion.BuildNumber), Color.Black, 0, true);
            }
        }
        private async Task <bool> DoExport(ExportItem exportItem, bool multiExport = false, bool clearLogs = true)
        {
            new BabylonAnimationActionItem().Close();
            SaveOptions();

            if (multiExport)
            {
                ShowExportItemLayers(exportItem.Layers);
            }

            exporter = new BabylonExporter();

            if (clearLogs)
            {
                treeView.Nodes.Clear();
            }

            exporter.OnExportProgressChanged += progress =>
            {
                progressBar.Value = progress;
                Application.DoEvents();
            };

            exporter.OnWarning += (warning, rank) => CreateWarningMessage(warning, rank);

            exporter.OnError += (error, rank) => CreateErrorMessage(error, rank);

            exporter.OnMessage += (message, color, rank, emphasis) => CreateMessage(message, color, rank, emphasis);

            exporter.OnVerbose += (message, color, rank, emphasis) => CreateMessage(message, color, rank, emphasis);

            exporter.OnPrint += (message, color, rank, emphasis) => CreateMessage(message, color, rank, emphasis);

            butExport.Enabled       = false;
            butExportAndRun.Enabled = false;
            butMultiExport.Enabled  = false;
            butCancel.Enabled       = true;

            bool success = true;

            try
            {
                string modelAbsolutePath = multiExport ? exportItem.ExportFilePathAbsolute : txtModelPath.Text;
                string textureExportPath = multiExport ? exportItem.ExportTexturesesFolderAbsolute : txtTexturesPath.Text;

                var scaleFactorParsed    = 1.0f;
                var textureQualityParsed = 100L;
                try
                {
                    scaleFactorParsed = float.Parse(txtScaleFactor.Text);
                }
                catch (Exception e)
                {
                    throw new InvalidDataException(String.Format("Invalid Scale Factor value: {0}", txtScaleFactor.Text));
                }
                try
                {
                    textureQualityParsed = long.Parse(txtQuality.Text);
                }
                catch (Exception e)
                {
                    throw new InvalidDataException(String.Format("Invalid Texture Quality value: {0}", txtScaleFactor.Text));
                }

                MaxExportParameters exportParameters = new MaxExportParameters
                {
                    outputPath                    = modelAbsolutePath,
                    textureFolder                 = textureExportPath,
                    outputFormat                  = comboOutputFormat.SelectedItem.ToString(),
                    scaleFactor                   = scaleFactorParsed,
                    writeTextures                 = chkWriteTextures.Enabled && chkWriteTextures.Checked,
                    overwriteTextures             = chkOverwriteTextures.Enabled && chkOverwriteTextures.Checked,
                    exportHiddenObjects           = chkHidden.Checked,
                    exportOnlySelected            = chkOnlySelected.Checked,
                    generateManifest              = chkManifest.Checked,
                    autoSaveSceneFile             = chkAutoSave.Checked,
                    exportTangents                = chkExportTangents.Checked,
                    exportMorphTangents           = chkExportMorphTangents.Checked,
                    exportMorphNormals            = chkExportMorphNormals.Checked,
                    txtQuality                    = textureQualityParsed,
                    mergeAOwithMR                 = chkMergeAOwithMR.Enabled && chkMergeAOwithMR.Checked,
                    bakeAnimationType             = (BakeAnimationType)cmbBakeAnimationOptions.SelectedIndex,
                    logLevel                      = (LogLevel)logLevelcmb.SelectedIndex,
                    dracoCompression              = chkDracoCompression.Enabled && chkDracoCompression.Checked,
                    enableKHRLightsPunctual       = chkKHRLightsPunctual.Checked,
                    enableKHRTextureTransform     = chkKHRTextureTransform.Checked,
                    enableKHRMaterialsUnlit       = chkKHRMaterialsUnlit.Checked,
                    exportMaterials               = chkExportMaterials.Enabled && chkExportMaterials.Checked,
                    animationExportType           = (AnimationExportType)cmbExportAnimationType.SelectedIndex,
                    enableASBAnimationRetargeting = chkASBAnimationRetargeting.Checked,
                    optimizeAnimations            = !chkDoNotOptimizeAnimations.Checked,
                    animgroupExportNonAnimated    = chkAnimgroupExportNonAnimated.Checked,
                    exportNode                    = exportItem?.Node,
                    exportLayers                  = exportItem?.Layers,
                    pbrNoLight                    = chkNoAutoLight.Checked,
                    pbrFull                = chkFullPBR.Checked,
                    pbrEnvironment         = txtEnvironmentName.Text,
                    usePreExportProcess    = chkUsePreExportProces.Checked,
                    flattenScene           = chkFlatten.Enabled && chkFlatten.Checked,
                    mergeContainersAndXRef = chkMrgContainersAndXref.Checked,
                    useMultiExporter       = multiExport,
                    tangentSpaceConvention = (TangentSpaceConvention)cmbNormalMapConvention.SelectedIndex,
                    removeLodPrefix        = chk_RemoveLodPrefix.Checked,
                    removeNamespaces       = chkRemoveNamespace.Checked,
                    srcTextureExtension    = txtSrcTextureExt.Text,
                    dstTextureExtension    = txtDstTextureExt.Text
                };

                exporter.callerForm = this;

                exporter.Export(exportParameters);
            }
            catch (OperationCanceledException)
            {
                progressBar.Value = 0;
                success           = false;
                ScriptsUtilities.ExecuteMaxScriptCommand(@"global BabylonExporterStatus = ""Available""");
            }
            catch (Exception ex)
            {
                IUTF8Str operationStatus = GlobalInterface.Instance.UTF8Str.Create("BabylonExportAborted");
                Loader.Global.BroadcastNotification(SystemNotificationCode.PreExport, operationStatus);

                currentNode = CreateTreeNode(0, "Export cancelled: " + ex.Message, Color.Red);
                currentNode = CreateTreeNode(1, ex.ToString(), Color.Red);
                currentNode.EnsureVisible();

                progressBar.Value = 0;
                success           = false;
                ScriptsUtilities.ExecuteMaxScriptCommand(@"global BabylonExporterStatus = Available");
            }

            butCancel.Enabled       = false;
            butExport.Enabled       = true;
            butMultiExport.Enabled  = true;
            butExportAndRun.Enabled = WebServer.IsSupported;

            BringToFront();

            return(success);
        }