Browse Source

Added morph shape display for animation inspector

BearishSun 9 năm trước cách đây
mục cha
commit
bff15d4739

+ 63 - 0
Source/MBansheeEditor/Inspectors/AnimationInspector.cs

@@ -1,5 +1,7 @@
 //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
 //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+
+using System.Collections.Generic;
 using BansheeEngine;
 using BansheeEngine;
 
 
 namespace BansheeEditor
 namespace BansheeEditor
@@ -120,6 +122,67 @@ namespace BansheeEditor
             GUILayoutY boundsContent = boundsLayout.AddLayoutY();
             GUILayoutY boundsContent = boundsLayout.AddLayoutY();
             boundsContent.AddElement(centerField);
             boundsContent.AddElement(centerField);
             boundsContent.AddElement(sizeField);
             boundsContent.AddElement(sizeField);
+
+            // Morph shapes
+            Renderable renderable = animation.SceneObject.GetComponent<Renderable>();
+            MorphShapes morphShapes = renderable?.Mesh?.MorphShapes;
+            if (morphShapes != null)
+            {
+                GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout);
+
+                Layout.AddElement(morphShapesToggle);
+                GUILayoutY channelsLayout = Layout.AddLayoutY();
+
+                morphShapesToggle.OnToggled += x =>
+                {
+                    channelsLayout.Active = x;
+                    Persistent.SetBool("Channels_Expanded", x);
+                };
+
+                channelsLayout.Active = Persistent.GetBool("Channels_Expanded");
+
+                MorphChannel[] channels = morphShapes.Channels;
+                for (int i = 0; i < channels.Length; i++)
+                {
+                    GUILayoutY channelLayout = channelsLayout.AddLayoutY();
+
+                    GUILayoutX channelTitleLayout = channelLayout.AddLayoutX();
+                    GUILayoutX channelContentLayout = channelLayout.AddLayoutX();
+
+                    string channelName = channels[i].Name;
+                    GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Foldout);
+
+                    channelTitleLayout.AddSpace(15); // Indent
+                    channelTitleLayout.AddElement(channelNameField);
+                    channelTitleLayout.AddFlexibleSpace();
+
+                    channelNameField.OnToggled += x =>
+                    {
+                        channelContentLayout.Active = x;
+
+                        Persistent.SetBool(channelName + "_Expanded", x);
+                    };
+
+                    channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded");
+
+                    MorphShape[] shapes = channels[i].Shapes;
+                    for (int j = 0; j < shapes.Length; j++)
+                    {
+                        GUILayoutX shapeLayout = channelContentLayout.AddLayoutX();
+
+                        GUILabel shapeNameField = new GUILabel(shapes[j].Name);
+
+                        LocString weightString = new LocEdString("Weight: {0}");
+                        weightString.SetParameter(0, shapes[j].Weight.ToString());
+                        GUILabel weightField = new GUILabel(weightString);
+
+                        shapeLayout.AddSpace(30); // Indent
+                        shapeLayout.AddElement(shapeNameField);
+                        shapeLayout.AddFlexibleSpace();
+                        shapeLayout.AddElement(weightField);
+                    }
+                }
+            }
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 8 - 5
Source/MBansheeEditor/Windows/Animation/GUIAnimFieldDisplay.cs

@@ -372,6 +372,12 @@ namespace BansheeEditor
                 backgroundTexture.SetTint(Color.Transparent);
                 backgroundTexture.SetTint(Color.Transparent);
         }
         }
 
 
+        /// <summary>
+        /// Displays a floating point value in the value display.
+        /// </summary>
+        /// <param name="value">Value to display</param>
+        public virtual void SetValue(float value) { }
+
         /// <summary>
         /// <summary>
         /// Changes the displayed value next to the element's name.
         /// Changes the displayed value next to the element's name.
         /// </summary>
         /// </summary>
@@ -576,12 +582,9 @@ namespace BansheeEditor
         }
         }
 
 
         /// <inheritdoc/>
         /// <inheritdoc/>
-        public override void SetValue(object value)
+        public override void SetValue(float value)
         {
         {
-            if (value == null)
-                return;
-
-            string strValue = value.ToString();
+            string strValue = value.ToString("n2");
             valueDisplay.SetContent(strValue);
             valueDisplay.SetContent(strValue);
         }
         }
     }
     }