Prechádzať zdrojové kódy

Max2Babylon: Improving treeview report

David Catuhe 11 rokov pred
rodič
commit
8e505c87a6

BIN
Exporters/3ds Max/Max2Babylon-0.5.4.zip


+ 5 - 0
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Animation.cs

@@ -57,6 +57,11 @@ namespace Max2Babylon
         {
             var result = false;
 
+            if (control == null)
+            {
+                return false;
+            }
+
             if (control.XController != null || control.YController != null || control.ZController != null)
             {
                 result |= ExportFloatController(control.XController, property + ".x", animations);

+ 1 - 1
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Camera.cs

@@ -16,7 +16,7 @@ namespace Max2Babylon
             var maxCamera = (cameraNode.Object as Camera)._Camera;
             var babylonCamera = new BabylonCamera();
 
-            RaiseMessage(cameraNode.Name, true);
+            RaiseMessage(cameraNode.Name, 1);
             babylonCamera.name = cameraNode.Name;
             babylonCamera.id = cameraNode.GetGuid().ToString();
             if (cameraNode.HasParent())

+ 2 - 2
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Light.cs

@@ -18,7 +18,7 @@ namespace Max2Babylon
             var maxLight = (lightNode.Object as Light);
             var babylonLight = new BabylonLight();
 
-            RaiseMessage(maxLight.Name, true);
+            RaiseMessage(maxLight.Name, 1);
             babylonLight.name = lightNode.Name;
             babylonLight.id = lightNode.GetGuid().ToString();
 
@@ -56,7 +56,7 @@ namespace Max2Babylon
                 }
                 else
                 {
-                    RaiseWarning("Shadows maps are only supported for directional lights", true);
+                    RaiseWarning("Shadows maps are only supported for directional lights", 2);
                 }
             }
 

+ 3 - 3
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Material.cs

@@ -15,7 +15,7 @@ namespace Max2Babylon
             var name = materialNode._Mtl.Name;
             var id = materialNode.GetGuid().ToString();
 
-            RaiseMessage(name, true);
+            RaiseMessage(name, 1);
 
             if (materialNode.NumSubMaterials > 0)
             {
@@ -95,8 +95,8 @@ namespace Max2Babylon
                     // This is a alpha testing purpose
                     babylonMaterial.opacityTexture = null;
                     babylonMaterial.diffuseTexture.hasAlpha = true;
-                    RaiseWarning("Opacity texture was removed because alpha from diffuse texture can be use instead", true);
-                    RaiseWarning("If you do not want this behavior, just set Alpha Source = None on your diffuse texture", true);
+                    RaiseWarning("Opacity texture was removed because alpha from diffuse texture can be use instead", 2);
+                    RaiseWarning("If you do not want this behavior, just set Alpha Source = None on your diffuse texture", 2);
                 }
             }
 

+ 3 - 3
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs

@@ -107,7 +107,7 @@ namespace Max2Babylon
             var mesh = triObject != null ? triObject.Mesh : null;
             var computedMesh = meshNode.GetMesh();
 
-            RaiseMessage(meshNode.Name, mesh == null ? System.Drawing.Color.Gray : System.Drawing.Color.Black, true);
+            RaiseMessage(meshNode.Name, 1);
 
             if (mesh != null)
             {
@@ -195,7 +195,7 @@ namespace Max2Babylon
                     }
                 }
 
-                RaiseMessage(string.Format("{0} vertices, {1} faces", vertices.Count, indices.Count / 3), true, false, true);
+                RaiseMessage(string.Format("{0} vertices, {1} faces", vertices.Count, indices.Count / 3), 2);
 
                 // Buffers
                 babylonMesh.positions = vertices.SelectMany(v => v.Position.ToArraySwitched()).ToArray();
@@ -418,7 +418,7 @@ namespace Max2Babylon
 
                 if (nbBones > 4)
                 {
-                    RaiseError("Too many bones per vertex: " + nbBones);
+                    RaiseError("Too many bones influences per vertex: " + nbBones + ". Babylon.js only support 4 bones influences per vertex.", 2);
                 }
 
                 vertex.Weights = Loader.Global.Point4.Create(weight0, weight1, weight2, 1.0 - weight0 - weight1 - weight2);

+ 1 - 1
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.ShadowGenerator.cs

@@ -11,7 +11,7 @@ namespace Max2Babylon
             var maxLight = (lightNode.Object as Light);
             var babylonShadowGenerator = new BabylonShadowGenerator();
 
-            RaiseMessage("Exporting shadow map", true, false, true);
+            RaiseMessage("Exporting shadow map", 2);
 
             babylonShadowGenerator.lightId = lightNode.GetGuid().ToString();
 

+ 1 - 1
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Skeleton.cs

@@ -88,7 +88,7 @@ namespace Max2Babylon
             var babylonSkeleton = new BabylonSkeleton {id = skins.IndexOf(skin)};
             babylonSkeleton.name = "skeleton #" + babylonSkeleton.id;
 
-            RaiseMessage(babylonSkeleton.name, true);
+            RaiseMessage(babylonSkeleton.name, 1);
 
             var bones = new List<BabylonBone>();
 

+ 2 - 2
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Texture.cs

@@ -124,7 +124,7 @@ namespace Max2Babylon
                     }
                     else
                     {
-                        RaiseWarning(string.Format("Texture {0} not found.", babylonTexture.name), true);
+                        RaiseWarning(string.Format("Texture {0} not found.", babylonTexture.name), 2);
                     }
                 }
             }
@@ -135,7 +135,7 @@ namespace Max2Babylon
 
             if (babylonTexture.isCube && !allowCube)
             {
-                RaiseWarning(string.Format("Cube texture are only supported for reflection channel"), true);
+                RaiseWarning(string.Format("Cube texture are only supported for reflection channel"), 2);
             }
 
             return babylonTexture;

+ 14 - 14
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.cs

@@ -17,9 +17,9 @@ namespace Max2Babylon
     internal partial class BabylonExporter
     {
         public event Action<int> OnImportProgressChanged;
-        public event Action<string, bool> OnWarning;
-        public event Action<string, bool, bool, bool, Color> OnMessage;
-        public event Action<string, bool> OnError;
+        public event Action<string, int> OnWarning;
+        public event Action<string, Color, int, bool> OnMessage;
+        public event Action<string, int> OnError;
 
         readonly List<string> alreadyExportedTextures = new List<string>();
 
@@ -35,32 +35,32 @@ namespace Max2Babylon
             }
         }
 
-        void RaiseError(string error, bool asChild = true)
+        void RaiseError(string error, int rank = 0)
         {
             if (OnError != null)
             {
-                OnError(error, asChild);
+                OnError(error, rank);
             }
         }
 
-        void RaiseWarning(string warning, bool asChild = false)
+        void RaiseWarning(string warning, int rank = 0)
         {
             if (OnWarning != null)
             {
-                OnWarning(warning, asChild);
+                OnWarning(warning, rank);
             }
         }
 
-        void RaiseMessage(string message, bool asChild = false, bool emphasis = false, bool embed = false)
+        void RaiseMessage(string message, int rank = 0, bool emphasis = false)
         {
-            RaiseMessage(message, Color.Black, asChild, emphasis, embed);
+            RaiseMessage(message, Color.Black, rank, emphasis);
         }
 
-        void RaiseMessage(string message, Color color, bool asChild = false, bool emphasis = false, bool embed = false)
+        void RaiseMessage(string message, Color color, int rank = 0, bool emphasis = false)
         {
             if (OnMessage != null)
             {
-                OnMessage(message, asChild, emphasis, embed, color);
+                OnMessage(message, color, rank, emphasis);
             }
         }
 
@@ -113,13 +113,13 @@ namespace Max2Babylon
                 {
                     mainCamera = babylonScene.CamerasList[0];
                     babylonScene.activeCameraID = mainCamera.id;
-                    RaiseMessage("Active camera set to " + mainCamera.name, true, true);
+                    RaiseMessage("Active camera set to " + mainCamera.name, 1, true);
                 }
             }
 
             if (mainCamera == null)
             {
-                RaiseWarning("No camera defined", true);
+                RaiseWarning("No camera defined", 1);
             }
 
             // Fog
@@ -182,7 +182,7 @@ namespace Max2Babylon
 
             if (babylonScene.LightsList.Count == 0)
             {
-                RaiseWarning("No light defined", true);
+                RaiseWarning("No light defined", 1);
             }
 
             // Skeletons

+ 52 - 41
Exporters/3ds Max/Max2Babylon/Forms/ExporterForm.cs

@@ -11,6 +11,9 @@ namespace Max2Babylon
         private readonly BabylonExportActionItem babylonExportAction;
         private BabylonExporter exporter;
 
+        TreeNode currentNode = null;
+        int currentRank = 0;
+
         public ExporterForm(BabylonExportActionItem babylonExportAction)
         {
             InitializeComponent();
@@ -36,53 +39,54 @@ namespace Max2Babylon
             Kernel.Scene.RootNode.SetLocalData(txtFilename.Text);
 
             exporter = new BabylonExporter();
-            TreeNode currentNode = null;
-            TreeNode previousNode = null;
 
             treeView.Nodes.Clear();
 
-            exporter.OnImportProgressChanged += progress => 
+            exporter.OnImportProgressChanged += progress =>
             {
                 progressBar.Value = progress;
                 Application.DoEvents();
             };
 
-            exporter.OnWarning += (warning, asChild) => 
+            exporter.OnWarning += (warning, rank) =>
             {
-                previousNode = new TreeNode(warning) { ForeColor = Color.Orange };
-
-                currentNode = CreateTreeNode(asChild, currentNode, previousNode);
-
-                previousNode.EnsureVisible();
+                try
+                {
+                    currentNode = CreateTreeNode(rank, warning, Color.Orange);
+                    currentNode.EnsureVisible();
+                }
+                catch
+                {
+                }
                 Application.DoEvents();
             };
 
-            exporter.OnError += (error, asChild) =>
+            exporter.OnError += (error, rank) =>
             {
-                previousNode = new TreeNode(error) { ForeColor = Color.Red };
-
-                currentNode = CreateTreeNode(asChild, currentNode, previousNode);
-
-                previousNode.EnsureVisible();
+                try
+                {
+                    currentNode = CreateTreeNode(rank, error, Color.Red);
+                    currentNode.EnsureVisible();
+                }
+                catch
+                {
+                }
                 Application.DoEvents();
             };
 
-            exporter.OnMessage += (message, asChild, emphasis, embed, color) => 
+            exporter.OnMessage += (message, color, rank, emphasis) =>
             {
-                var oldPrevious = previousNode;
-
-                previousNode = new TreeNode(message) {ForeColor = color};
-
-                if (emphasis)
+                try
                 {
-                    previousNode.ForeColor = Color.Green;
-                }
+                    currentNode = CreateTreeNode(rank, message, color);
 
-                currentNode = CreateTreeNode(asChild || embed, embed ? oldPrevious : currentNode, previousNode);
-
-                if (emphasis)
+                    if (emphasis)
+                    {
+                        currentNode.EnsureVisible();
+                    }
+                }
+                catch
                 {
-                    previousNode.EnsureVisible();
                 }
                 Application.DoEvents();
             };
@@ -96,15 +100,13 @@ namespace Max2Babylon
             }
             catch (OperationCanceledException)
             {
-                progressBar.Value = 0;                
+                progressBar.Value = 0;
             }
             catch (Exception ex)
             {
-                previousNode = new TreeNode("Exportation cancelled: " + ex.Message) { ForeColor = Color.Red };
-
-                currentNode = CreateTreeNode(false, currentNode, previousNode);
+                currentNode = CreateTreeNode(0, "Exportation cancelled: " + ex.Message, Color.Red);
 
-                previousNode.EnsureVisible();
+                currentNode.EnsureVisible();
                 progressBar.Value = 0;
             }
 
@@ -112,26 +114,35 @@ namespace Max2Babylon
             butExport.Enabled = true;
         }
 
-        private TreeNode CreateTreeNode(bool asChild, TreeNode currentNode, TreeNode treeNode)
+        private TreeNode CreateTreeNode(int rank, string text, Color color)
         {
-            if (asChild)
+            var newNode = new TreeNode(text) { ForeColor = color };
+            if (rank == 0)
             {
-                currentNode.Nodes.Add(treeNode);
+                treeView.Nodes.Add(newNode);
             }
-            else
+            else if (rank == currentRank + 1)
             {
-                treeView.Nodes.Add(treeNode);
+                currentNode.Nodes.Add(newNode);
             }
-
-            if (!asChild)
+            else
             {
-                currentNode = treeNode;
+                var parentNode = currentNode;
+                while (currentRank != rank - 1)
+                {
+                    parentNode = parentNode.Parent;
+                    currentRank--;
+                }
+                parentNode.Nodes.Add(newNode);
             }
-            return currentNode;
+
+            currentRank = rank;
+            return newNode;
         }
 
         private void ExporterForm_FormClosed(object sender, FormClosedEventArgs e)
         {
+            exporter.IsCancelled = true;
             babylonExportAction.Close();
         }