Browse Source

Add item to Edit menu ("Add children to SM-group") to add all children of the StaticModelGroup node as instances. Closes #676.

Lasse Öörni 10 years ago
parent
commit
dffab8cff1
2 changed files with 29 additions and 0 deletions
  1. 28 0
      bin/Data/Scripts/Editor/EditorScene.as
  2. 1 0
      bin/Data/Scripts/Editor/EditorUI.as

+ 28 - 0
bin/Data/Scripts/Editor/EditorScene.as

@@ -1013,6 +1013,34 @@ bool SceneRebuildNavigation()
     return success;
 }
 
+bool SceneAddChildrenStaticModelGroup()
+{
+    StaticModelGroup@ smg = cast<StaticModelGroup>(editComponents.length > 0 ? editComponents[0] : null);
+    if (smg is null && editNode !is null)
+        smg = editNode.GetComponent("StaticModelGroup");
+
+    if (smg is null)
+    {
+        MessageBox("Must have a StaticModelGroup component selected.");
+        return false;
+    }
+
+    uint attrIndex = GetAttributeIndex(smg, "Instance Nodes");
+    Variant oldValue = smg.attributes[attrIndex];
+
+    Array<Node@> children = smg.node.GetChildren(true);
+    for (uint i = 0; i < children.length; ++i)
+        smg.AddInstanceNode(children[i]);
+
+    EditAttributeAction action;
+    action.Define(smg, attrIndex, oldValue);;
+    SaveEditAction(action);
+    SetSceneModified();
+    FocusComponent(smg);
+    
+    return true;
+}
+
 void AssignMaterial(StaticModel@ model, String materialPath)
 {
     Material@ material = cache.GetResource("Material", materialPath);

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

@@ -341,6 +341,7 @@ void CreateMenuBar()
         popup.AddChild(CreateMenuItem("Stop test animation", @StopTestAnimation));
         CreateChildDivider(popup);
         popup.AddChild(CreateMenuItem("Rebuild navigation data", @SceneRebuildNavigation));
+        popup.AddChild(CreateMenuItem("Add children to SM-group", @SceneAddChildrenStaticModelGroup));
         FinalizedPopupMenu(popup);
         uiMenuBar.AddChild(menu);
     }