Explorar o código

Bugfix: Editor handles & gizmos no longer lag one frame behind actual scene objects

BearishSun %!s(int64=7) %!d(string=hai) anos
pai
achega
77fc1ff3e7

+ 0 - 11
Source/BansheeEditor/Handles/BsHandleDrawManager.cpp

@@ -319,17 +319,6 @@ namespace bs
 
 
 			SPtr<RenderTarget> renderTarget = camera.getViewport()->getTarget();
 			SPtr<RenderTarget> renderTarget = camera.getViewport()->getTarget();
 
 
-			float width = (float)renderTarget->getProperties().width;
-			float height = (float)renderTarget->getProperties().height;
-
-			Rect2 normArea = camera.getViewport()->getArea();
-
-			Rect2I screenArea;
-			screenArea.x = (int)(normArea.x * width);
-			screenArea.y = (int)(normArea.y * height);
-			screenArea.width = (int)(normArea.width * width);
-			screenArea.height = (int)(normArea.height * height);
-
 			Matrix4 viewProjMat = camera.getProjectionMatrixRS() * camera.getViewMatrix();
 			Matrix4 viewProjMat = camera.getProjectionMatrixRS() * camera.getViewMatrix();
 
 
 			gHandleParamBlockDef.gMatViewProj.set(mParamBuffer, viewProjMat);
 			gHandleParamBlockDef.gMatViewProj.set(mParamBuffer, viewProjMat);

+ 39 - 20
Source/MBansheeEditor/Windows/Scene/Handles/DefaultHandleManager.cs

@@ -90,26 +90,8 @@ namespace BansheeEditor
 
 
             if (activeHandle != null)
             if (activeHandle != null)
             {
             {
-                Quaternion rotation;
-                if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
-                    rotation = Quaternion.Identity;
-                else
-                    rotation = selectedSceneObjects[0].Rotation; // We don't average rotation in case of multi-selection
-
-                Vector3 position;
-                if (EditorApplication.ActivePivotMode == HandlePivotMode.Pivot)
-                    position = selectedSceneObjects[0].Position; // Just take pivot from the first one, no averaging
-                else
-                {
-                    List<SceneObject> flatenedHierarchy = new List<SceneObject>();
-                    foreach (var so in selectedSceneObjects)
-                        flatenedHierarchy.AddRange(EditorUtility.FlattenHierarchy(so));
-
-                    position = EditorUtility.CalculateCenter(flatenedHierarchy.ToArray());
-                }
-
-                activeHandle.Position = position;
-                activeHandle.Rotation = rotation;
+                // In case the object moved programmatically, make the handle reflect its current transform
+                UpdateActiveHandleTransform(selectedSceneObjects);
 
 
                 activeHandle.PreInput();
                 activeHandle.PreInput();
             }
             }
@@ -217,6 +199,13 @@ namespace BansheeEditor
                             break;
                             break;
                     }
                     }
 
 
+                    SceneObject[] selectedSceneObjects = new SceneObject[activeSelection.Length];
+                    for (int i = 0; i < activeSelection.Length; i++)
+                        selectedSceneObjects[i] = activeSelection[i].so;
+
+                    // Make sure to update handle positions for the drawing method (otherwise they lag one frame)
+                    UpdateActiveHandleTransform(selectedSceneObjects);
+
                     EditorApplication.SetSceneDirty();
                     EditorApplication.SetSceneDirty();
                 }
                 }
             }
             }
@@ -233,6 +222,36 @@ namespace BansheeEditor
             if (activeHandle != null)
             if (activeHandle != null)
                 activeHandle.Draw();
                 activeHandle.Draw();
         }
         }
+
+        /// <summary>
+        /// Updates active handle position/rotation based on the currently selected object(s).
+        /// </summary>
+        private void UpdateActiveHandleTransform(SceneObject[] selectedSceneObjects)
+        {
+            if (activeHandle == null)
+                return;
+
+            Quaternion rotation;
+            if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
+                rotation = Quaternion.Identity;
+            else
+                rotation = selectedSceneObjects[0].Rotation; // We don't average rotation in case of multi-selection
+
+            Vector3 position;
+            if (EditorApplication.ActivePivotMode == HandlePivotMode.Pivot)
+                position = selectedSceneObjects[0].Position; // Just take pivot from the first one, no averaging
+            else
+            {
+                List<SceneObject> flatenedHierarchy = new List<SceneObject>();
+                foreach (var so in selectedSceneObjects)
+                    flatenedHierarchy.AddRange(EditorUtility.FlattenHierarchy(so));
+
+                position = EditorUtility.CalculateCenter(flatenedHierarchy.ToArray());
+            }
+
+            activeHandle.Position = position;
+            activeHandle.Rotation = rotation;
+        }
     }
     }
 
 
     /** @} */
     /** @} */

+ 5 - 4
Source/MBansheeEditor/Windows/Scene/SceneWindow.cs

@@ -493,7 +493,6 @@ namespace BansheeEditor
             }
             }
 
 
             // Update scene view handles and selection
             // Update scene view handles and selection
-            sceneGizmos.Draw();
             sceneGrid.Draw();
             sceneGrid.Draw();
 
 
             bool handleActive = sceneHandles.IsActive() || sceneAxesGUI.IsActive();
             bool handleActive = sceneHandles.IsActive() || sceneAxesGUI.IsActive();
@@ -662,12 +661,14 @@ namespace BansheeEditor
             
             
             SceneHandles.BeginInput();
             SceneHandles.BeginInput();
             sceneHandles.UpdateInput(scenePos, Input.PointerDelta);
             sceneHandles.UpdateInput(scenePos, Input.PointerDelta);
-            sceneHandles.Draw();
-
             sceneAxesGUI.UpdateInput(scenePos);
             sceneAxesGUI.UpdateInput(scenePos);
-            sceneAxesGUI.Draw();
             SceneHandles.EndInput();
             SceneHandles.EndInput();
 
 
+            sceneHandles.Draw();
+            sceneAxesGUI.Draw();
+
+            // Must be done after handle input is processed, in order to reflect most recent transform
+            sceneGizmos.Draw();
             sceneSelection.Draw();
             sceneSelection.Draw();
 
 
             UpdateGridMode();
             UpdateGridMode();

+ 0 - 1
Source/SBansheeEditor/BsEditorScriptManager.cpp

@@ -102,7 +102,6 @@ namespace bs
 			mLastUpdateTime += numUpdates * EDITOR_UPDATE_RATE;
 			mLastUpdateTime += numUpdates * EDITOR_UPDATE_RATE;
 		}
 		}
 
 
-		ScriptGizmoManager::instance().update();
 		ScriptDragDropManager::instance().update();
 		ScriptDragDropManager::instance().update();
 		ScriptFolderMonitorManager::instance().update();
 		ScriptFolderMonitorManager::instance().update();
 		ScriptEditorApplication::update();
 		ScriptEditorApplication::update();

+ 3 - 1
Source/SBansheeEditor/Wrappers/BsScriptSceneGizmos.cpp

@@ -2,6 +2,7 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 #include "Wrappers/BsScriptSceneGizmos.h"
 #include "Wrappers/BsScriptSceneGizmos.h"
 #include "Scene/BsGizmoManager.h"
 #include "Scene/BsGizmoManager.h"
+#include "BsScriptGizmoManager.h"
 #include "Components/BsCCamera.h"
 #include "Components/BsCCamera.h"
 
 
 #include "BsScriptCCamera.generated.h"
 #include "BsScriptCCamera.generated.h"
@@ -33,6 +34,7 @@ namespace bs
 
 
 	void ScriptSceneGizmos::internal_Draw(ScriptSceneGizmos* thisPtr)
 	void ScriptSceneGizmos::internal_Draw(ScriptSceneGizmos* thisPtr)
 	{
 	{
+		ScriptGizmoManager::instance().update();
 		GizmoManager::instance().update(thisPtr->mCamera);
 		GizmoManager::instance().update(thisPtr->mCamera);
 	}
 	}
-}
+}