2
0
Эх сурвалжийг харах

Editor functionality to assign child nodes as a spline path. Contributed by MonkeyFirst. Closes #781.

Lasse Öörni 10 жил өмнө
parent
commit
9b629b2a36

+ 41 - 1
bin/Data/Scripts/Editor/EditorScene.as

@@ -1036,7 +1036,7 @@ bool SceneAddChildrenStaticModelGroup()
         smg.AddInstanceNode(children[i]);
 
     EditAttributeAction action;
-    action.Define(smg, attrIndex, oldValue);;
+    action.Define(smg, attrIndex, oldValue);
     SaveEditAction(action);
     SetSceneModified();
     FocusComponent(smg);
@@ -1044,6 +1044,46 @@ bool SceneAddChildrenStaticModelGroup()
     return true;
 }
 
+bool SceneSetChildrenSplinePath(bool makeCycle)
+{
+    SplinePath@ sp = cast<SplinePath>(editComponents.length > 0 ? editComponents[0] : null);
+    if (sp is null && editNode !is null)
+        sp = editNode.GetComponent("SplinePath");
+
+    if (sp is null)
+    {
+        MessageBox("Must have a SplinePath component selected.");
+        return false;
+    }
+
+    uint attrIndex = GetAttributeIndex(sp, "Control Points");
+    Variant oldValue = sp.attributes[attrIndex];
+
+    Array<Node@> children = sp.node.GetChildren(true);
+    if (children.length >= 2)
+    {
+        sp.ClearControlPoints();
+        for (uint i = 0; i < children.length; ++i)
+            sp.AddControlPoint(children[i]);
+    }
+    else
+    {
+        MessageBox("You must have a minimum two children Nodes in selected Node.");
+        return false;
+    }
+
+    if (makeCycle)
+        sp.AddControlPoint(children[0]);
+
+    EditAttributeAction action;
+    action.Define(sp, attrIndex, oldValue);;
+    SaveEditAction(action);
+    SetSceneModified();
+    FocusComponent(sp);
+    
+    return true;
+}
+
 void AssignMaterial(StaticModel@ model, String materialPath)
 {
     Material@ material = cache.GetResource("Material", materialPath);

+ 15 - 0
bin/Data/Scripts/Editor/EditorUI.as

@@ -342,6 +342,11 @@ void CreateMenuBar()
         CreateChildDivider(popup);
         popup.AddChild(CreateMenuItem("Rebuild navigation data", @SceneRebuildNavigation));
         popup.AddChild(CreateMenuItem("Add children to SM-group", @SceneAddChildrenStaticModelGroup));
+        Menu@ childMenu = CreateMenuItem("Set children as spline path", null, SHOW_POPUP_INDICATOR);
+        Window@ childPopup = CreatePopup(childMenu);
+        childPopup.AddChild(CreateMenuItem("Non-cyclic", @SetSplinePath, 0, 0, true, "Set non-cyclic spline path"));
+        childPopup.AddChild(CreateMenuItem("Cyclic", @SetSplinePath, 0, 0, true, "Set cyclic spline path"));
+        popup.AddChild(childMenu);
         FinalizedPopupMenu(popup);
         uiMenuBar.AddChild(menu);
     }
@@ -1479,3 +1484,13 @@ UIElement@ LoadEditorUI(const String&in fileName)
 {
     return ui.LoadLayout(GetEditorUIXMLFile(fileName));
 }
+
+/// Set node children as a spline path, either cyclic or non-cyclic
+bool SetSplinePath()
+{
+    Menu@ menu = GetEventSender();
+    if (menu is null)
+        return false;
+
+    return SceneSetChildrenSplinePath(menu.name == "Cyclic");
+}