瀏覽代碼

some fixes for smart duplicate

MonkeyFirst 10 年之前
父節點
當前提交
8fc2ae9436

+ 2 - 0
Docs/GettingStarted.dox

@@ -790,6 +790,8 @@ Z                  - Cycle through solid, wireframe and point rendering
 M                  - Show/Hide LayerEditor
 F                  - Focus on selected object (LookAt)               
 X                  - Delete node or component
+Alt+D              - Smart Duplicate (note: select one of axises on gizmo to show direction for next instance)
+Key "." or Del     - View Closer selected node(s)  
 \endverbatim
 
 Press right mouse button in the 3D view if you want to defocus the active window without changing the object selection.

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

@@ -497,6 +497,7 @@ void SelectNode(Node@ node, bool multiselect)
         return;
     }
     
+    lastSelectedNode = node;
     uint index = GetListIndex(node);
     uint numItems = hierarchyList.numItems;
 

+ 55 - 35
bin/Data/Scripts/Editor/EditorScene.as

@@ -37,6 +37,8 @@ uint undoStackPos = 0;
 bool revertOnPause = false;
 XMLFile@ revertData;
 
+Vector3 lastOffsetForSmartDuplicate;
+
 void ClearSceneSelection()
 {
     selectedNodes.Clear();
@@ -820,56 +822,74 @@ bool NodesParentToLastSelected()
 }
 
 bool SceneSmartDuplicateNode() 
-{      
+{       
+    const float minOffset = 0.1;
+    
     if (!CheckHierarchyWindowFocus() || !selectedComponents.empty || selectedNodes.empty)
-    {
         return false;
-    }
     
     Node@ node = lastSelectedNode;
     Node@ parent = node.parent;
-    Vector3 offset = Vector3(0,0,0);
+    Vector3 offset = Vector3(1,0,0); // default offset
     
     if (parent is editorScene) // if parent of selected node is Scene make empty parent for it and place in same position; 
     {
         parent = CreateNode(LOCAL);
         SceneChangeParent(parent, editorScene, false);
         parent.worldPosition = node.worldPosition;
-        //node.worldPosition = Vector3(0.0, 0.0, 0.0);
-        SceneChangeParent(node, parent, false);
-        parent = node.parent;
         parent.name = node.name + "Group";
         node.name = parent.name + "Instance" + String(parent.numChildren);
+        SceneChangeParent(node, parent, false);
+        parent = node.parent;
+        SelectNode(node, false);
     } 
-    else
-    {  
-        Node@ lastChild = parent.children[parent.numChildren-1];
-        Node@ beforeLastChild;
-        
-        if (parent.numChildren == 1)  // make first offset in step of object side size
-        {   
-            Drawable@ drawable = GetFirstDrawable(lastChild);
-            if (drawable !is null) 
-            {
-                BoundingBox bb = drawable.boundingBox;
-                float side =  bb.size.length ;
-                offset = Vector3(0.0, 0.0, side); 
-            } 
-        }      
-        else if (parent.numChildren > 1) 
-        {  
-            beforeLastChild = parent.children[parent.numChildren-2];
-            offset = lastChild.worldPosition - beforeLastChild.worldPosition;
-        }
-        
-        Vector3 lastInstancePosition = lastChild.worldPosition;
-        SelectNode(lastChild, false);
-        SceneDuplicate();
-        Node@ newInstance = parent.children[parent.numChildren-1];
-        SelectNode(newInstance, false);
-        newInstance.worldPosition = lastInstancePosition + offset;
-        newInstance.name = parent.name + "Instance" + String(parent.numChildren);
+
+    Node@ lastChild = lastSelectedNode;
+    Node@ beforeLastChild;
+    float sideSize = 0;
+    Vector3 size;
+    BoundingBox bb;
+    
+    // get bb for offset  
+    Drawable@ drawable = GetFirstDrawable(lastChild);
+    if (drawable !is null) 
+    {
+        bb = drawable.boundingBox;
+        size =  bb.size * drawable.node.worldScale;
+        offset = Vector3(size.x, 0, 0); 
+    } 
+    
+    // make offset on axis that select user by mouse
+    if (gizmoAxisX.selected)
+    {
+        if (size.x < minOffset) size.x = minOffset;
+        offset = lastChild.rotation * Vector3(size.x,0,0);
+    }
+    else if (gizmoAxisY.selected)
+    {
+        if (size.y < minOffset) size.y = minOffset;
+        offset = lastChild.rotation * Vector3(0,size.y,0);
     }
+    else if (gizmoAxisZ.selected)
+    {
+        if (size.z < minOffset) size.z = minOffset;
+        offset = lastChild.rotation * Vector3(0,0,size.z);
+    }
+    else
+        offset = lastOffsetForSmartDuplicate;    
+    
+    Vector3 lastInstancePosition = lastChild.worldPosition;
+    
+    SelectNode(lastChild, false);
+    SceneDuplicate();
+    Node@ newInstance = parent.children[parent.numChildren-1];
+    SelectNode(newInstance, false);
+    newInstance.worldPosition = lastInstancePosition;
+    newInstance.Translate(offset, TS_WORLD);
+    newInstance.name = parent.name + "Instance" + String(parent.numChildren-1);
+    
+    lastOffsetForSmartDuplicate = offset;
+
     return true;
 }
 

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

@@ -390,7 +390,7 @@ void CreateMenuBar()
         {
              popup.AddChild(CreateMenuItem("Move to layer", @ShowLayerMover, 'M'));
              popup.AddChild(CreateMenuItem("Smart Duplicate", @SceneSmartDuplicateNode, 'D', QUAL_ALT));
-             popup.AddChild(CreateMenuItem("View closer", @ViewCloser, KEY_KP_PERIOD));        
+             popup.AddChild(CreateMenuItem("View closer", @ViewCloser, KEY_KP_PERIOD));                     
         }
         
         CreateChildDivider(popup);

+ 4 - 8
bin/Data/Scripts/Editor/EditorView.as

@@ -27,7 +27,6 @@ Drawable@ lastSelectedDrawable;
 Component@ lastSelectedComponent;
 bool viewCloser = false;
 
-
 const uint VIEWPORT_BORDER_H     = 0x00000001;
 const uint VIEWPORT_BORDER_H1    = 0x00000002;
 const uint VIEWPORT_BORDER_H2    = 0x00000004;
@@ -1300,8 +1299,7 @@ void UpdateView(float timeStep)
                     camera.zoom = Clamp(zoom, .1, 30);
                 }
             }
-        }
-        
+        }       
     }
 
     if (input.keyDown[KEY_HOME])
@@ -1391,8 +1389,7 @@ void UpdateView(float timeStep)
 
     if (orbiting && !input.mouseButtonDown[MOUSEB_MIDDLE])
         orbiting = false;
-    
-    // View closer on KP_PERIOD
+        
     if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
     if ( viewCloser && lastSelectedDrawable !is null) 
     {
@@ -1409,7 +1406,7 @@ void UpdateView(float timeStep)
         {
             for (int i = 0; i < selectedNodes.length; i++) 
             {
-                    bb.Merge(selectedNodes[i].position);
+                bb.Merge(selectedNodes[i].position);
             }
                   
             centerPoint = SelectedNodesCenterPoint();
@@ -1424,8 +1421,7 @@ void UpdateView(float timeStep)
     }
     else 
         viewCloser =  false;
-         
-
+    
     // Move/rotate/scale object
     if ( hotKeyMode == HOTKEYS_MODE_BLENDER) // force to select component node for manipulation if selected only component and not his node
     {    if ((editMode != EDIT_SELECT && editNodes.empty) && lastSelectedComponent !is null )