فهرست منبع

Split SceneViewHandler into different types to allow better granularity as to where they're used

BearishSun 10 سال پیش
والد
کامیت
ec82c8e6fd
29فایلهای تغییر یافته به همراه1272 افزوده شده و 1117 حذف شده
  1. 0 2
      BansheeEditor/BansheeEditor.vcxproj
  2. 0 6
      BansheeEditor/BansheeEditor.vcxproj.filters
  3. 114 108
      BansheeEditor/Include/BsHandleManager.h
  4. 69 69
      BansheeEditor/Include/BsHandleSliderManager.h
  5. 136 136
      BansheeEditor/Include/BsSceneGrid.h
  6. 152 152
      BansheeEditor/Include/BsScenePicking.h
  7. 0 81
      BansheeEditor/Include/BsSceneViewHandler.h
  8. 103 103
      BansheeEditor/Include/BsSelectionRenderer.h
  9. 76 73
      BansheeEditor/Source/BsHandleManager.cpp
  10. 0 142
      BansheeEditor/Source/BsSceneViewHandler.cpp
  11. 4 1
      MBansheeEditor/MBansheeEditor.csproj
  12. 35 0
      MBansheeEditor/Scene/SceneGizmos.cs
  13. 36 0
      MBansheeEditor/Scene/SceneGrid.cs
  14. 84 0
      MBansheeEditor/Scene/SceneHandles.cs
  15. 48 0
      MBansheeEditor/Scene/SceneSelection.cs
  16. 0 112
      MBansheeEditor/Scene/SceneViewHandler.cs
  17. 18 10
      MBansheeEditor/Scene/SceneWindow.cs
  18. 26 0
      SBansheeEditor/Include/BsScriptSceneGizmos.h
  19. 26 0
      SBansheeEditor/Include/BsScriptSceneGrid.h
  20. 42 0
      SBansheeEditor/Include/BsScriptSceneHandles.h
  21. 28 0
      SBansheeEditor/Include/BsScriptSceneSelection.h
  22. 0 34
      SBansheeEditor/Include/BsScriptSceneViewHandler.h
  23. 8 2
      SBansheeEditor/SBansheeEditor.vcxproj
  24. 24 6
      SBansheeEditor/SBansheeEditor.vcxproj.filters
  25. 34 0
      SBansheeEditor/Source/BsScriptSceneGizmos.cpp
  26. 35 0
      SBansheeEditor/Source/BsScriptSceneGrid.cpp
  27. 107 0
      SBansheeEditor/Source/BsScriptSceneHandles.cpp
  28. 67 0
      SBansheeEditor/Source/BsScriptSceneSelection.cpp
  29. 0 80
      SBansheeEditor/Source/BsScriptSceneViewHandler.cpp

+ 0 - 2
BansheeEditor/BansheeEditor.vcxproj

@@ -363,7 +363,6 @@
     <ClInclude Include="Include\BsProjectResourceMetaRTTI.h" />
     <ClInclude Include="Include\BsGUIVector2Field.h" />
     <ClInclude Include="Include\BsSceneGrid.h" />
-    <ClInclude Include="Include\BsSceneViewHandler.h" />
     <ClInclude Include="Include\BsSelection.h" />
     <ClInclude Include="Include\BsSelectionRenderer.h" />
     <ClInclude Include="Include\BsSettings.h" />
@@ -441,7 +440,6 @@
     <ClCompile Include="Source\BsProjectLibraryEntries.cpp" />
     <ClCompile Include="Source\BsProjectResourceMeta.cpp" />
     <ClCompile Include="Source\BsSceneGrid.cpp" />
-    <ClCompile Include="Source\BsSceneViewHandler.cpp" />
     <ClCompile Include="Source\BsSelection.cpp" />
     <ClCompile Include="Source\BsSelectionRenderer.cpp" />
     <ClCompile Include="Source\BsSettings.cpp" />

+ 0 - 6
BansheeEditor/BansheeEditor.vcxproj.filters

@@ -225,9 +225,6 @@
     <ClInclude Include="Include\BsScenePicking.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Include\BsSceneViewHandler.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsSelection.h">
       <Filter>Header Files</Filter>
     </ClInclude>
@@ -473,9 +470,6 @@
     <ClCompile Include="Source\BsScenePicking.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Source\BsSceneViewHandler.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsSelection.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>

+ 114 - 108
BansheeEditor/Include/BsHandleManager.h

@@ -1,109 +1,115 @@
-#pragma once
-
-#include "BsEditorPrerequisites.h"
-#include "BsModule.h"
-#include "BsDegree.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	The central place for interacting with and drawing handles.
-	 */
-	class BS_ED_EXPORT HandleManager : public Module<HandleManager>
-	{
-	public:
-		HandleManager();
-		virtual ~HandleManager();
-
-		/**
-		 * @brief	To be called every frame. Updates interactable handle sliders based on provided input
-		 *			and queues handles for drawing.
-		 *
-		 * @param	camera		Camera that the input positions are relative to, and destination to draw the handles to.
-		 * @param	inputPos	Position of the pointer, relative to the provided camera viewport.
-		 * @param	inputDelta	Determines pointer movement since last call to this method.
-		 */
-		void update(const CameraPtr& camera, const Vector2I& inputPos, const Vector2I& inputDelta);
-
-		/**
-		 * @brief	Select a handle slider at the specified location, if there is any under the pointer. Makes
-		 *			the selected slider active and draggable.
-		 *
-		 * @param	camera		Camera that the input positions are relative to, and destination to draw the handles to.
-		 * @param	inputPos	Position of the pointer, relative to the provided camera viewport.
-		 */
-		void trySelect(const CameraPtr& camera, const Vector2I& inputPos);
-
-		/**
-		 * @brief	Clears the currently selected/active handle slider.
-		 */
-		void clearSelection();
-
-		/**
-		 * @brief	Is any handle slider selected/active.
-		 */
-		bool isHandleActive() const;
-
-		/**
-		 * @brief	Returns the manager that can be used for interacting with handle sliders.
-		 */
-		HandleSliderManager& getSliderManager() const { return *mSliderManager; }
-
-		/**
-		 * @brief	Returns the manager that can be used for drawing handle geometry.
-		 */
-		HandleDrawManager& getDrawManager() const { return *mDrawManager; }
-
-		/**
-		 * @brief	Returns the uniform size for a handle rendered in @p camera, at the world
-		 *			position @p handlePos. The handles will be scaled so that they appear
-		 *			the same size regardless of distance from camera.
-		 */
-		float getHandleSize(const CameraPtr& camera, const Vector3& handlePos) const;
-
-		/**
-		 * @brief	Sets the default handle size. This controls the uniform scale returned from
-		 *			::getHandleSize method.
-		 */
-		void setDefaultHandleSize(float value) { mDefaultHandleSize = value; }
-
-		/**
-		 * @brief	Sets editor settings that will be used for controlling various 
-		 *			handle behaviour.
-		 */
-		void setSettings(const EditorSettingsPtr& settings);
-
-	protected:
-		/**
-		 * @brief	Updates the internal properties from editor settings.
-		 */
-		void updateFromEditorSettings();
-
-		/**
-		 * @brief	Called during handle update. Allows handle sliders to be created or 
-		 *			destroyed before any input is handled.
-		 */
-		virtual void refreshHandles() = 0;
-
-		/**
-		 * @brief	Called during handle update after handle input is processed.
-		 *			Allows implementation to respond to delta values calculated in sliders
-		 *			due to input.
-		 */
-		virtual void triggerHandles() = 0;
-
-		/**
-		 * @brief	Called during handle update. Allows implementation to
-		 *			queue handle draw commands.
-		 */
-		virtual void queueDrawCommands() = 0;
-
-		HandleSliderManager* mSliderManager;
-		HandleDrawManager* mDrawManager;
-
-		float mDefaultHandleSize = 20.0f;
-
-		EditorSettingsPtr mSettings;
-		UINT32 mSettingsHash;
-	};
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+#include "BsModule.h"
+#include "BsDegree.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	The central place for interacting with and drawing handles.
+	 */
+	class BS_ED_EXPORT HandleManager : public Module<HandleManager>
+	{
+	public:
+		HandleManager();
+		virtual ~HandleManager();
+
+		/**
+		 * To be called every frame. Updates interactable handle sliders based on provided input.
+		 *
+		 * @param	camera		Camera that the input positions are relative to.
+		 * @param	inputPos	Position of the pointer, relative to the provided camera viewport.
+		 * @param	inputDelta	Determines pointer movement since last call to this method.
+		 */
+		void updateInput(const CameraPtr& camera, const Vector2I& inputPos, const Vector2I& inputDelta);
+
+		/**
+		 * To be called every frame. Queues handles for drawing.
+		 *
+		 * @param	camera		Camera to draw the handles to.
+		 */
+		void draw(const CameraPtr& camera);
+
+		/**
+		 * @brief	Select a handle slider at the specified location, if there is any under the pointer. Makes
+		 *			the selected slider active and draggable.
+		 *
+		 * @param	camera		Camera that the input positions are relative to, and destination to draw the handles to.
+		 * @param	inputPos	Position of the pointer, relative to the provided camera viewport.
+		 */
+		void trySelect(const CameraPtr& camera, const Vector2I& inputPos);
+
+		/**
+		 * @brief	Clears the currently selected/active handle slider.
+		 */
+		void clearSelection();
+
+		/**
+		 * @brief	Is any handle slider selected/active.
+		 */
+		bool isHandleActive() const;
+
+		/**
+		 * @brief	Returns the manager that can be used for interacting with handle sliders.
+		 */
+		HandleSliderManager& getSliderManager() const { return *mSliderManager; }
+
+		/**
+		 * @brief	Returns the manager that can be used for drawing handle geometry.
+		 */
+		HandleDrawManager& getDrawManager() const { return *mDrawManager; }
+
+		/**
+		 * @brief	Returns the uniform size for a handle rendered in @p camera, at the world
+		 *			position @p handlePos. The handles will be scaled so that they appear
+		 *			the same size regardless of distance from camera.
+		 */
+		float getHandleSize(const CameraPtr& camera, const Vector3& handlePos) const;
+
+		/**
+		 * @brief	Sets the default handle size. This controls the uniform scale returned from
+		 *			::getHandleSize method.
+		 */
+		void setDefaultHandleSize(float value) { mDefaultHandleSize = value; }
+
+		/**
+		 * @brief	Sets editor settings that will be used for controlling various 
+		 *			handle behaviour.
+		 */
+		void setSettings(const EditorSettingsPtr& settings);
+
+	protected:
+		/**
+		 * @brief	Updates the internal properties from editor settings.
+		 */
+		void updateFromEditorSettings();
+
+		/**
+		 * @brief	Called during handle update. Allows handle sliders to be created or 
+		 *			destroyed before any input is handled.
+		 */
+		virtual void refreshHandles() = 0;
+
+		/**
+		 * @brief	Called during handle update after handle input is processed.
+		 *			Allows implementation to respond to delta values calculated in sliders
+		 *			due to input.
+		 */
+		virtual void triggerHandles() = 0;
+
+		/**
+		 * @brief	Called during handle update. Allows implementation to
+		 *			queue handle draw commands.
+		 */
+		virtual void queueDrawCommands() = 0;
+
+		HandleSliderManager* mSliderManager;
+		HandleDrawManager* mDrawManager;
+
+		float mDefaultHandleSize = 20.0f;
+
+		EditorSettingsPtr mSettings;
+		UINT32 mSettingsHash;
+	};
 }

+ 69 - 69
BansheeEditor/Include/BsHandleSliderManager.h

@@ -1,70 +1,70 @@
-#pragma once
-
-#include "BsEditorPrerequisites.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Controls all instantiated HandleSlider%s.
-	 */
-	class BS_ED_EXPORT HandleSliderManager
-	{
-	public:
-		HandleSliderManager();
-		~HandleSliderManager();
-
-		/**
-		 * @brief	Updates all underlying sliders, changing their state and dragging them depending
-		 *			on their state and pointer movement.
-		 *
-		 * @param	camera		Camera through which we're interacting with sliders.
-		 * @param	inputPos	Position of the pointer.
-		 * @param	inputDelta	Movement of the pointer since last frame.
-		 */
-		void update(const CameraPtr& camera, const Vector2I& inputPos, const Vector2I& inputDelta);
-
-		/**
-		 * @brief	Attempts to select (activate) a slider at the specified position (if there is any).
-		 *
-		 * @param	camera		Camera through which we're interacting with sliders.
-		 * @param	inputPos	Position of the pointer.
-		 */
-		void trySelect(const CameraPtr& camera, const Vector2I& inputPos);
-
-		/**
-		 * @brief	Clears the 0active slider (deactivates it).
-		 */
-		void clearSelection();
-
-		/**
-		 * @brief	Checks is any slider active.
-		 */
-		bool isSliderActive() const { return mActiveSlider != nullptr; }
-
-		/**
-		 * @brief	Registers a new instantiated slider.
-		 */
-		void _registerSlider(HandleSlider* slider);
-
-		/**
-		 * @brief	Unregisters a previously instantiated slider.
-		 */
-		void _unregisterSlider(HandleSlider* slider);
-
-	private:
-
-		/**
-		 * @brief	Attempts to find slider at the specified position.
-		 *
-		 * @param	camera		Camera through which we're interacting with sliders.
-		 * @param	inputPos	Position of the pointer.
-		 *
-		 * @return	Slider if we're intersecting with one, or null otherwise.
-		 */
-		HandleSlider* findUnderCursor(const CameraPtr& camera, const Vector2I& inputPos) const;
-
-		HandleSlider* mActiveSlider;
-		HandleSlider* mHoverSlider;
-		UnorderedSet<HandleSlider*> mSliders;
-	};
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Controls all instantiated HandleSlider%s.
+	 */
+	class BS_ED_EXPORT HandleSliderManager
+	{
+	public:
+		HandleSliderManager();
+		~HandleSliderManager();
+
+		/**
+		 * @brief	Updates all underlying sliders, changing their state and dragging them depending
+		 *			on their state and pointer movement.
+		 *
+		 * @param	camera		Camera through which we're interacting with sliders.
+		 * @param	inputPos	Position of the pointer.
+		 * @param	inputDelta	Movement of the pointer since last frame.
+		 */
+		void update(const CameraPtr& camera, const Vector2I& inputPos, const Vector2I& inputDelta);
+
+		/**
+		 * @brief	Attempts to select (activate) a slider at the specified position (if there is any).
+		 *
+		 * @param	camera		Camera through which we're interacting with sliders.
+		 * @param	inputPos	Position of the pointer.
+		 */
+		void trySelect(const CameraPtr& camera, const Vector2I& inputPos);
+
+		/**
+		 * @brief	Clears the active slider (deactivates it).
+		 */
+		void clearSelection();
+
+		/**
+		 * @brief	Checks is any slider active.
+		 */
+		bool isSliderActive() const { return mActiveSlider != nullptr; }
+
+		/**
+		 * @brief	Registers a new instantiated slider.
+		 */
+		void _registerSlider(HandleSlider* slider);
+
+		/**
+		 * @brief	Unregisters a previously instantiated slider.
+		 */
+		void _unregisterSlider(HandleSlider* slider);
+
+	private:
+
+		/**
+		 * @brief	Attempts to find slider at the specified position.
+		 *
+		 * @param	camera		Camera through which we're interacting with sliders.
+		 * @param	inputPos	Position of the pointer.
+		 *
+		 * @return	Slider if we're intersecting with one, or null otherwise.
+		 */
+		HandleSlider* findUnderCursor(const CameraPtr& camera, const Vector2I& inputPos) const;
+
+		HandleSlider* mActiveSlider;
+		HandleSlider* mHoverSlider;
+		UnorderedSet<HandleSlider*> mSliders;
+	};
 }

+ 136 - 136
BansheeEditor/Include/BsSceneGrid.h

@@ -1,137 +1,137 @@
-#pragma once
-
-#include "BsEditorPrerequisites.h"
-#include "BsVector3.h"
-#include "BsColor.h"
-#include "BsMaterial.h"
-
-namespace BansheeEngine
-{
-	class SceneGridCore;
-
-	/**
-	 * @brief	Handles rendering of the grid in the scene view.
-	 */
-	class SceneGrid
-	{
-	public:
-		SceneGrid(const CameraPtr& camera);
-		~SceneGrid();
-
-		/**
-		 * @brief	Sets the grid origin in world coordinates.
-		 */
-		void setOrigin(const Vector3& origin);
-
-		/**
-		 * @brief	Sets the total width/height of the grid in XZ plane.
-		 */
-		void setSize(UINT32 size);
-		
-		/**
-		 * @brief	Sets the spacing between grid lines.
-		 */
-		void setSpacing(float spacing);
-
-		/**
-		 * @brief	Changes the active editor settings. Grid properties
-		 *			will be updated internally when editor settings change.
-		 */
-		void setSettings(const EditorSettingsPtr& settings);
-
-		/**
-		 * @brief	Called once per frame.
-		 *
-		 * @note	Internal method.
-		 */
-		void update();
-	private:
-		/**
-		 * @brief	Updates internal grid parameters from the attached settings object.
-		 */
-		void updateFromEditorSettings();
-
-		/**
-		 * @brief	Rebuilds the scene grid mesh. Call this whenever grid parameters change.
-		 */
-		void updateGridMesh();
-
-		/**
-		 * @brief	Initializes the core thread portion of the scene grid renderer.
-		 *
-		 * @param	material	Material used for drawing the grid.
-		 * @param	camera		Camera to render the scene grid to.
-		 */
-		void initializeCore(const SPtr<CameraCore>& camera, const SPtr<MaterialCore>& material);
-
-		/**
-		 * @brief	Destroys the core thread portion of the draw manager.
-		 */
-		void destroyCore(SceneGridCore* core);
-
-		Vector3 mOrigin;
-		float mSpacing = 1.0f;
-		UINT32 mSize = 256;
-		bool mCoreDirty;
-
-		EditorSettingsPtr mSettings;
-		UINT32 mSettingsHash = 0;
-
-		HMesh mGridMesh;
-		VertexDataDescPtr mVertexDesc;
-		std::atomic<SceneGridCore*> mCore;
-	};
-
-	/**
-	 * @brief	Handles scene grid rendering on the core thread.
-	 */
-	class SceneGridCore
-	{
-	public:
-		SceneGridCore() { }
-		~SceneGridCore();
-
-	private:
-		friend class SceneGrid;
-
-		/**
-		 * @brief	Initializes the object. Must be called right after construction and before any use.
-		 *
-		 * @param	material	Material used for drawing the grid.
-		 * @param	camera		Camera to render the scene grid to.
-		 */
-		void initialize(const SPtr<CameraCore>& camera, const SPtr<MaterialCore>& material);
-
-		/**
-		 * @brief	Updates the grid mesh to render.
-		 * 			
-		 * @param	mesh		Grid mesh to render.
-		 * @param	spacing		Spacing between the grid lines.
-		 */
-		void updateData(const SPtr<MeshCore>& mesh, float spacing);
-
-		/**
-		 * @brief	Callback triggered by the renderer, actually draws the grid mesh.
-		 */
-		void render();
-
-		SPtr<CameraCore> mCamera;
-		SPtr<MeshCore> mGridMesh;
-		SPtr<MaterialCore> mGridMaterial;
-		float mSpacing = 1.0f;
-
-		MaterialParamMat4Core mViewProjParam;
-		MaterialParamVec4Core mWorldCameraPosParam;
-		MaterialParamColorCore mGridColorParam;
-		MaterialParamFloatCore mGridSpacingParam;
-		MaterialParamFloatCore mGridBorderWidthParam;
-		MaterialParamFloatCore mGridFadeOutStartParam;
-		MaterialParamFloatCore mGridFadeOutEndParam;
-
-		static const Color GRID_LINE_COLOR;
-		static const float LINE_WIDTH;
-		static const float LINE_BORDER_WIDTH;
-		static const float FADE_OUT_START;
-		static const float FADE_OUT_END;
-	};
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+#include "BsVector3.h"
+#include "BsColor.h"
+#include "BsMaterial.h"
+
+namespace BansheeEngine
+{
+	class SceneGridCore;
+
+	/**
+	 * @brief	Handles rendering of the grid in the scene view.
+	 */
+	class BS_ED_EXPORT SceneGrid
+	{
+	public:
+		SceneGrid(const CameraPtr& camera);
+		~SceneGrid();
+
+		/**
+		 * @brief	Sets the grid origin in world coordinates.
+		 */
+		void setOrigin(const Vector3& origin);
+
+		/**
+		 * @brief	Sets the total width/height of the grid in XZ plane.
+		 */
+		void setSize(UINT32 size);
+		
+		/**
+		 * @brief	Sets the spacing between grid lines.
+		 */
+		void setSpacing(float spacing);
+
+		/**
+		 * @brief	Changes the active editor settings. Grid properties
+		 *			will be updated internally when editor settings change.
+		 */
+		void setSettings(const EditorSettingsPtr& settings);
+
+		/**
+		 * @brief	Called once per frame.
+		 *
+		 * @note	Internal method.
+		 */
+		void update();
+	private:
+		/**
+		 * @brief	Updates internal grid parameters from the attached settings object.
+		 */
+		void updateFromEditorSettings();
+
+		/**
+		 * @brief	Rebuilds the scene grid mesh. Call this whenever grid parameters change.
+		 */
+		void updateGridMesh();
+
+		/**
+		 * @brief	Initializes the core thread portion of the scene grid renderer.
+		 *
+		 * @param	material	Material used for drawing the grid.
+		 * @param	camera		Camera to render the scene grid to.
+		 */
+		void initializeCore(const SPtr<CameraCore>& camera, const SPtr<MaterialCore>& material);
+
+		/**
+		 * @brief	Destroys the core thread portion of the draw manager.
+		 */
+		void destroyCore(SceneGridCore* core);
+
+		Vector3 mOrigin;
+		float mSpacing = 1.0f;
+		UINT32 mSize = 256;
+		bool mCoreDirty;
+
+		EditorSettingsPtr mSettings;
+		UINT32 mSettingsHash = 0;
+
+		HMesh mGridMesh;
+		VertexDataDescPtr mVertexDesc;
+		std::atomic<SceneGridCore*> mCore;
+	};
+
+	/**
+	 * @brief	Handles scene grid rendering on the core thread.
+	 */
+	class SceneGridCore
+	{
+	public:
+		SceneGridCore() { }
+		~SceneGridCore();
+
+	private:
+		friend class SceneGrid;
+
+		/**
+		 * @brief	Initializes the object. Must be called right after construction and before any use.
+		 *
+		 * @param	material	Material used for drawing the grid.
+		 * @param	camera		Camera to render the scene grid to.
+		 */
+		void initialize(const SPtr<CameraCore>& camera, const SPtr<MaterialCore>& material);
+
+		/**
+		 * @brief	Updates the grid mesh to render.
+		 * 			
+		 * @param	mesh		Grid mesh to render.
+		 * @param	spacing		Spacing between the grid lines.
+		 */
+		void updateData(const SPtr<MeshCore>& mesh, float spacing);
+
+		/**
+		 * @brief	Callback triggered by the renderer, actually draws the grid mesh.
+		 */
+		void render();
+
+		SPtr<CameraCore> mCamera;
+		SPtr<MeshCore> mGridMesh;
+		SPtr<MaterialCore> mGridMaterial;
+		float mSpacing = 1.0f;
+
+		MaterialParamMat4Core mViewProjParam;
+		MaterialParamVec4Core mWorldCameraPosParam;
+		MaterialParamColorCore mGridColorParam;
+		MaterialParamFloatCore mGridSpacingParam;
+		MaterialParamFloatCore mGridBorderWidthParam;
+		MaterialParamFloatCore mGridFadeOutStartParam;
+		MaterialParamFloatCore mGridFadeOutEndParam;
+
+		static const Color GRID_LINE_COLOR;
+		static const float LINE_WIDTH;
+		static const float LINE_BORDER_WIDTH;
+		static const float FADE_OUT_START;
+		static const float FADE_OUT_END;
+	};
 }

+ 152 - 152
BansheeEditor/Include/BsScenePicking.h

@@ -1,153 +1,153 @@
-#pragma once
-
-#include "BsEditorPrerequisites.h"
-#include "BsModule.h"
-#include "BsMatrix4.h"
-#include "BsGpuParam.h"
-
-namespace BansheeEngine
-{
-	class ScenePickingCore;
-
-	/**
-	 * @brief	Handles picking of scene objects with a pointer in scene view.
-	 */
-	class ScenePicking : public Module<ScenePicking>
-	{
-		/**
-		 * @brief	Contains information about a single pickable item (mesh).
-		 */
-		struct RenderablePickData
-		{
-			SPtr<MeshCore> mesh;
-			UINT32 index;
-			Matrix4 wvpTransform;
-			bool alpha;
-			CullingMode cullMode;
-			HTexture mainTexture;
-		};
-
-	public:
-		ScenePicking();
-		~ScenePicking();
-
-		/**
-		 * @brief	Attempts to find a single nearest scene object under the provided position and area.
-		 *
-		 * @param	cam			Camera to perform the picking from.
-		 * @param	position	Pointer position relative to the camera viewport, in pixels.
-		 * @param	area		Width/height of the checked area in pixels. Use (1, 1) if you want the
-		 *						exact position under the pointer.
-		 *
-		 * @return	Nearest SceneObject under the provided area, or an empty handle if no object is found.
-		 */
-		HSceneObject pickClosestObject(const CameraPtr& cam, const Vector2I& position, const Vector2I& area);
-
-
-		/**
-		 * @brief	Attempts to find all scene objects under the provided position and area. This does not mean
-		 *			objects occluded by other objects.
-		 *
-		 * @param	cam			Camera to perform the picking from.
-		 * @param	position	Pointer position relative to the camera viewport, in pixels.
-		 * @param	area		Width/height of the checked area in pixels. Use (1, 1) if you want the
-		 *						exact position under the pointer.
-		 *
-		 * @return	A list of SceneObject%s under the provided area.
-		 */
-		Vector<HSceneObject> pickObjects(const CameraPtr& cam, const Vector2I& position, const Vector2I& area);
-
-	private:
-		friend class ScenePickingCore;
-
-		typedef Set<RenderablePickData, std::function<bool(const RenderablePickData&, const RenderablePickData&)>> RenderableSet;
-
-		/**
-		 * @brief	Encodes a pickable object identifier to a unique color.
-		 */
-		static Color encodeIndex(UINT32 index);
-
-		/**
-		 * @brief	Decodes a color into a unique object identifier. Color should
-		 *			have initially been encoded with ::encodeIndex.
-		 */
-		static UINT32 decodeIndex(Color color);
-
-		ScenePickingCore* mCore;
-	};
-
-	/**
-	 * @brief	Core thread version of the ScenePicking manager. Handles
-	 *			actual rendering.
-	 */
-	class ScenePickingCore
-	{
-		/**
-		 * @brief	A list of materials and their parameters to be used for rendering
-		 *			of pickable objects.
-		 */
-		struct MaterialData
-		{
-			SPtr<MaterialCore> mMatPickingCore;
-			SPtr<MaterialCore> mMatPickingAlphaCore;
-
-			SPtr<GpuParamsCore> mParamPickingVertParams;
-			SPtr<GpuParamsCore> mParamPickingFragParams;
-			SPtr<GpuParamsCore> mParamPickingAlphaVertParams;
-			SPtr<GpuParamsCore> mParamPickingAlphaFragParams;
-
-			GpuParamMat4Core mParamPickingWVP;
-			GpuParamMat4Core mParamPickingAlphaWVP;
-			GpuParamColorCore mParamPickingColor;
-			GpuParamColorCore mParamPickingAlphaColor;
-			GpuParamTextureCore mParamPickingAlphaTexture;
-		};
-
-	public:
-		/**
-		 * @brief	Initializes the manager. Must be called right after construction.
-		 */
-		void initialize();
-
-		/**
-		 * @brief	Destroys the manager. Must be called right before destruction.
-		 */
-		void destroy();
-
-		/**
-		 * @brief	Sets up the viewport, materials and their parameters as needed for picking. Also renders
-		 *			all the provided renderable objects. Must be followed by ::corePickingEnd. You may call other methods
-		 *			after this one, but you must ensure they render proper unique pickable colors that can be resolved
-		 *			to SceneObject%s later.
-		 *
-		 * @param	target			Render target to render to.
-		 * @param	viewportArea	Normalized area of the render target to render in.
-		 * @param	renderables		A set of pickable Renderable objects to render.
-		 * @param	position		Position of the pointer where to pick objects, in pixels relative to viewport.
-		 * @param	area			Width/height of the area to pick objects, in pixels.
-		 */
-		void corePickingBegin(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, const ScenePicking::RenderableSet& renderables,
-			const Vector2I& position, const Vector2I& area);
-		
-		/**
-		 * @brief	Ends picking operation started by ::corePickingBegin. Render target is resolved and objects in the picked area
-		 *			are returned.
-		 *
-		 * @param	target			Render target we're rendering to.
-		 * @param	viewportArea	Normalized area of the render target we're rendering in.
-		 * @param	position		Position of the pointer where to pick objects, in pixels relative to viewport.
-		 * @param	area			Width/height of the area to pick objects, in pixels.
-		 * @param	asyncOp			Async operation handle that when complete will contain the results of the picking
-		 *							operation in the form of Vector<SelectedObject>.
-		 */
-		void corePickingEnd(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, const Vector2I& position,
-			const Vector2I& area, AsyncOp& asyncOp);
-
-	private:
-		friend class ScenePicking;
-
-		static const float ALPHA_CUTOFF;
-
-		MaterialData mMaterialData[3];
-	};
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+#include "BsModule.h"
+#include "BsMatrix4.h"
+#include "BsGpuParam.h"
+
+namespace BansheeEngine
+{
+	class ScenePickingCore;
+
+	/**
+	 * @brief	Handles picking of scene objects with a pointer in scene view.
+	 */
+	class BS_ED_EXPORT ScenePicking : public Module<ScenePicking>
+	{
+		/**
+		 * @brief	Contains information about a single pickable item (mesh).
+		 */
+		struct RenderablePickData
+		{
+			SPtr<MeshCore> mesh;
+			UINT32 index;
+			Matrix4 wvpTransform;
+			bool alpha;
+			CullingMode cullMode;
+			HTexture mainTexture;
+		};
+
+	public:
+		ScenePicking();
+		~ScenePicking();
+
+		/**
+		 * @brief	Attempts to find a single nearest scene object under the provided position and area.
+		 *
+		 * @param	cam			Camera to perform the picking from.
+		 * @param	position	Pointer position relative to the camera viewport, in pixels.
+		 * @param	area		Width/height of the checked area in pixels. Use (1, 1) if you want the
+		 *						exact position under the pointer.
+		 *
+		 * @return	Nearest SceneObject under the provided area, or an empty handle if no object is found.
+		 */
+		HSceneObject pickClosestObject(const CameraPtr& cam, const Vector2I& position, const Vector2I& area);
+
+
+		/**
+		 * @brief	Attempts to find all scene objects under the provided position and area. This does not mean
+		 *			objects occluded by other objects.
+		 *
+		 * @param	cam			Camera to perform the picking from.
+		 * @param	position	Pointer position relative to the camera viewport, in pixels.
+		 * @param	area		Width/height of the checked area in pixels. Use (1, 1) if you want the
+		 *						exact position under the pointer.
+		 *
+		 * @return	A list of SceneObject%s under the provided area.
+		 */
+		Vector<HSceneObject> pickObjects(const CameraPtr& cam, const Vector2I& position, const Vector2I& area);
+
+	private:
+		friend class ScenePickingCore;
+
+		typedef Set<RenderablePickData, std::function<bool(const RenderablePickData&, const RenderablePickData&)>> RenderableSet;
+
+		/**
+		 * @brief	Encodes a pickable object identifier to a unique color.
+		 */
+		static Color encodeIndex(UINT32 index);
+
+		/**
+		 * @brief	Decodes a color into a unique object identifier. Color should
+		 *			have initially been encoded with ::encodeIndex.
+		 */
+		static UINT32 decodeIndex(Color color);
+
+		ScenePickingCore* mCore;
+	};
+
+	/**
+	 * @brief	Core thread version of the ScenePicking manager. Handles
+	 *			actual rendering.
+	 */
+	class ScenePickingCore
+	{
+		/**
+		 * @brief	A list of materials and their parameters to be used for rendering
+		 *			of pickable objects.
+		 */
+		struct MaterialData
+		{
+			SPtr<MaterialCore> mMatPickingCore;
+			SPtr<MaterialCore> mMatPickingAlphaCore;
+
+			SPtr<GpuParamsCore> mParamPickingVertParams;
+			SPtr<GpuParamsCore> mParamPickingFragParams;
+			SPtr<GpuParamsCore> mParamPickingAlphaVertParams;
+			SPtr<GpuParamsCore> mParamPickingAlphaFragParams;
+
+			GpuParamMat4Core mParamPickingWVP;
+			GpuParamMat4Core mParamPickingAlphaWVP;
+			GpuParamColorCore mParamPickingColor;
+			GpuParamColorCore mParamPickingAlphaColor;
+			GpuParamTextureCore mParamPickingAlphaTexture;
+		};
+
+	public:
+		/**
+		 * @brief	Initializes the manager. Must be called right after construction.
+		 */
+		void initialize();
+
+		/**
+		 * @brief	Destroys the manager. Must be called right before destruction.
+		 */
+		void destroy();
+
+		/**
+		 * @brief	Sets up the viewport, materials and their parameters as needed for picking. Also renders
+		 *			all the provided renderable objects. Must be followed by ::corePickingEnd. You may call other methods
+		 *			after this one, but you must ensure they render proper unique pickable colors that can be resolved
+		 *			to SceneObject%s later.
+		 *
+		 * @param	target			Render target to render to.
+		 * @param	viewportArea	Normalized area of the render target to render in.
+		 * @param	renderables		A set of pickable Renderable objects to render.
+		 * @param	position		Position of the pointer where to pick objects, in pixels relative to viewport.
+		 * @param	area			Width/height of the area to pick objects, in pixels.
+		 */
+		void corePickingBegin(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, const ScenePicking::RenderableSet& renderables,
+			const Vector2I& position, const Vector2I& area);
+		
+		/**
+		 * @brief	Ends picking operation started by ::corePickingBegin. Render target is resolved and objects in the picked area
+		 *			are returned.
+		 *
+		 * @param	target			Render target we're rendering to.
+		 * @param	viewportArea	Normalized area of the render target we're rendering in.
+		 * @param	position		Position of the pointer where to pick objects, in pixels relative to viewport.
+		 * @param	area			Width/height of the area to pick objects, in pixels.
+		 * @param	asyncOp			Async operation handle that when complete will contain the results of the picking
+		 *							operation in the form of Vector<SelectedObject>.
+		 */
+		void corePickingEnd(const SPtr<RenderTargetCore>& target, const Rect2& viewportArea, const Vector2I& position,
+			const Vector2I& area, AsyncOp& asyncOp);
+
+	private:
+		friend class ScenePicking;
+
+		static const float ALPHA_CUTOFF;
+
+		MaterialData mMaterialData[3];
+	};
 }

+ 0 - 81
BansheeEditor/Include/BsSceneViewHandler.h

@@ -1,81 +0,0 @@
-#pragma once
-
-#include "BsEditorPrerequisites.h"
-#include "BsVector2I.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Handles various operations specific to the scene view, like updating,
-	 *			selecting and rendering handles, selecting objects, rendering scene grid, etc.
-	 *
-	 * @note	Internal class.
-	 */
-	class BS_ED_EXPORT SceneViewHandler
-	{
-	public:
-		SceneViewHandler(EditorWidgetBase* parentWidget, const SPtr<Camera>& camera);
-		virtual ~SceneViewHandler();
-
-		/**
-		 * @brief	Called once per frame. Updates gizmos and the scene grid.
-		 */
-		void update();
-
-		/**
-		 * @brief	Updates currently active handles.
-		 *
-		 * @param	position	Position of the pointer relative to the scene camera viewport.
-		 * @param	delta		Movement of the pointer since last frame.
-		 */
-		void updateHandle(const Vector2I& position, const Vector2I& delta);
-
-		/**
-		 * @brief	Updates the selection overlay for currently selected object(s).
-		 */
-		void updateSelection();
-
-		/**
-		 * @brief	Selects a handle under the pointer position.
-		 *
-		 * @param	position	Position of the pointer relative to the scene camera viewport.
-		 */
-		void trySelectHandle(const Vector2I& position);
-
-		/**
-		 * @brief	Checks is any handle currently active.
-		 */
-		bool isHandleActive() const;
-
-		/**
-		 * @brief	Deselects any currently active handles.
-		 */
-		void clearHandleSelection();
-
-		/**
-		 * @brief	Attempts to select a scene object under the pointer position.
-		 *
-		 * @param	position	Position of the pointer relative to the scene camera viewport.
-		 * @param	additive	Should this selection add to the existing selection, or replace it.
-		 */
-		void pickObject(const Vector2I& position, bool additive);
-
-	protected:
-		/**
-		 * @brief	Checks is the pointer currently within the provided window, and if it is not
-		 *			the cursor is wrapped in such a way so that it is returned to within the window bounds.
-		 *		
-		 * @return	How far was the cursor moved due to wrapping. This will be (0, 0) if the cursor is within
-		 *			window bounds initially.
-		 */
-		Vector2I wrapCursorToWindow();
-
-	private:
-		EditorWidgetBase* mParentWidget;
-		SPtr<Camera> mCamera;
-		SceneGrid* mSceneGrid;
-		SelectionRenderer* mSelectionRenderer;
-
-		Vector2I mMouseDeltaCompensate;
-	};
-}

+ 103 - 103
BansheeEditor/Include/BsSelectionRenderer.h

@@ -1,104 +1,104 @@
-#pragma once
-
-#include "BsEditorPrerequisites.h"
-#include "BsColor.h"
-#include "BsMatrix4.h"
-#include "BsGpuParam.h"
-
-namespace BansheeEngine
-{
-	class SelectionRendererCore;
-
-	/**
-	 * @brief	Handles rendering of the selected SceneObject%s overlay.
-	 */
-	class SelectionRenderer
-	{
-		/**
-		 * @brief	Contains data about a selected mesh.
-		 */
-		struct ObjectData
-		{
-			SPtr<MeshCoreBase> mesh;
-			Matrix4 worldTfrm;
-		};
-
-	public:
-		SelectionRenderer();
-		~SelectionRenderer();
-
-		/**
-		 * @brief	Called once per frame. Updates the overlay depending on current selection.
-		 *
-		 * @note	Internal method.
-		 */
-		void update(const CameraPtr& camera);
-
-	private:
-		friend class SelectionRendererCore;
-
-		/**
-		 * @brief	Initializes the core thread counterpart of the selection renderer.
-		 *
-		 * @param	mat	Material used for selection rendering.
-		 */
-		void initializeCore(const SPtr<MaterialCore>& mat);
-
-		/**
-		 * @brief	Destroys the core thread counterpart of the selection renderer.
-		 *
-		 * @param	core	Previously constructed core thread selection renderer instance.
-		 */
-		void destroyCore(SelectionRendererCore* core);
-
-		std::atomic<SelectionRendererCore*> mCore;
-	};
-
-	/**
-	 * @brief	Core thread version of the selection renderer, that handles
-	 *			actual rendering.
-	 */
-	class SelectionRendererCore
-	{
-		friend class SelectionRenderer;
-		
-		struct PrivatelyConstuct { };
-
-	public:
-		SelectionRendererCore(const PrivatelyConstuct& dummy);
-		~SelectionRendererCore();
-
-	private:
-		/**
-		 * @brief	Initializes the selection renderer. Should be called right
-		 *			after construction.
-		 *
-		 * @param	mat	Material used for selection rendering.
-		 */
-		void initialize(const SPtr<MaterialCore>& mat);
-
-		/**
-		 * @brief	Triggered by the Renderer when the overlay should be rendered.
-		 */
-		void render();
-
-		/**
-		 * @brief	Updates the internal data that determines what will be rendered on the next
-		 *			::render call.
-		 *
-		 * @param	camera	Camera to render the selection overlay in.
-		 * @param	objects	A set of objects to render with the selection overlay.
-		 */
-		void updateData(const SPtr<CameraCore>& camera, const Vector<SelectionRenderer::ObjectData>& objects);
-
-		Vector<SelectionRenderer::ObjectData> mObjects;
-		SPtr<CameraCore> mCamera;
-
-		// Immutable
-		SPtr<MaterialCore> mMaterial;
-		GpuParamMat4Core mMatWorldViewProj;
-		GpuParamColorCore mColor;
-
-		static const Color SELECTION_COLOR;
-	};
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+#include "BsColor.h"
+#include "BsMatrix4.h"
+#include "BsGpuParam.h"
+
+namespace BansheeEngine
+{
+	class SelectionRendererCore;
+
+	/**
+	 * @brief	Handles rendering of the selected SceneObject%s overlay.
+	 */
+	class BS_ED_EXPORT SelectionRenderer
+	{
+		/**
+		 * @brief	Contains data about a selected mesh.
+		 */
+		struct ObjectData
+		{
+			SPtr<MeshCoreBase> mesh;
+			Matrix4 worldTfrm;
+		};
+
+	public:
+		SelectionRenderer();
+		~SelectionRenderer();
+
+		/**
+		 * @brief	Called once per frame. Updates the overlay depending on current selection.
+		 *
+		 * @note	Internal method.
+		 */
+		void update(const CameraPtr& camera);
+
+	private:
+		friend class SelectionRendererCore;
+
+		/**
+		 * @brief	Initializes the core thread counterpart of the selection renderer.
+		 *
+		 * @param	mat	Material used for selection rendering.
+		 */
+		void initializeCore(const SPtr<MaterialCore>& mat);
+
+		/**
+		 * @brief	Destroys the core thread counterpart of the selection renderer.
+		 *
+		 * @param	core	Previously constructed core thread selection renderer instance.
+		 */
+		void destroyCore(SelectionRendererCore* core);
+
+		std::atomic<SelectionRendererCore*> mCore;
+	};
+
+	/**
+	 * @brief	Core thread version of the selection renderer, that handles
+	 *			actual rendering.
+	 */
+	class SelectionRendererCore
+	{
+		friend class SelectionRenderer;
+		
+		struct PrivatelyConstuct { };
+
+	public:
+		SelectionRendererCore(const PrivatelyConstuct& dummy);
+		~SelectionRendererCore();
+
+	private:
+		/**
+		 * @brief	Initializes the selection renderer. Should be called right
+		 *			after construction.
+		 *
+		 * @param	mat	Material used for selection rendering.
+		 */
+		void initialize(const SPtr<MaterialCore>& mat);
+
+		/**
+		 * @brief	Triggered by the Renderer when the overlay should be rendered.
+		 */
+		void render();
+
+		/**
+		 * @brief	Updates the internal data that determines what will be rendered on the next
+		 *			::render call.
+		 *
+		 * @param	camera	Camera to render the selection overlay in.
+		 * @param	objects	A set of objects to render with the selection overlay.
+		 */
+		void updateData(const SPtr<CameraCore>& camera, const Vector<SelectionRenderer::ObjectData>& objects);
+
+		Vector<SelectionRenderer::ObjectData> mObjects;
+		SPtr<CameraCore> mCamera;
+
+		// Immutable
+		SPtr<MaterialCore> mMaterial;
+		GpuParamMat4Core mMatWorldViewProj;
+		GpuParamColorCore mColor;
+
+		static const Color SELECTION_COLOR;
+	};
 }

+ 76 - 73
BansheeEditor/Source/BsHandleManager.cpp

@@ -1,74 +1,77 @@
-#include "BsHandleManager.h"
-#include "BsHandleDrawManager.h"
-#include "BsHandleSliderManager.h"
-#include "BsCCamera.h"
-#include "BsSceneObject.h"
-#include "BsEditorSettings.h"
-
-namespace BansheeEngine
-{
-	HandleManager::HandleManager()
-		:mSliderManager(nullptr), mDrawManager(nullptr), mSettingsHash(0xFFFFFFFF)
-	{
-		mSliderManager = bs_new<HandleSliderManager>();
-		mDrawManager = bs_new<HandleDrawManager>();
-	}
-
-	HandleManager::~HandleManager()
-	{
-		bs_delete(mSliderManager);
-		bs_delete(mDrawManager);
-	}
-
-	bool HandleManager::isHandleActive() const
-	{
-		return mSliderManager->isSliderActive();
-	}
-
-	void HandleManager::update(const CameraPtr& camera, const Vector2I& inputPos, const Vector2I& inputDelta)
-	{
-		if (mSettings != nullptr && mSettingsHash != mSettings->getHash())
-			updateFromEditorSettings();
-
-		refreshHandles();
-		mSliderManager->update(camera, inputPos, inputDelta);
-		triggerHandles();
-
-		queueDrawCommands();
-		mDrawManager->draw(camera);
-	}
-
-	void HandleManager::setSettings(const EditorSettingsPtr& settings)
-	{
-		mSettings = settings;
-
-		updateFromEditorSettings();
-	}
-
-	void HandleManager::updateFromEditorSettings()
-	{
-		setDefaultHandleSize(mSettings->getHandleSize());
-
-		mSettingsHash = mSettings->getHash();
-	}
-
-	void HandleManager::trySelect(const CameraPtr& camera, const Vector2I& inputPos)
-	{
-		return mSliderManager->trySelect(camera, inputPos);
-	}
-
-	void HandleManager::clearSelection()
-	{
-		return mSliderManager->clearSelection();
-	}
-
-	float HandleManager::getHandleSize(const CameraPtr& camera, const Vector3& handlePos) const
-	{
-		Vector3 cameraPos = camera->getPosition();
-
-		Vector3 diff = handlePos - cameraPos;
-		float distAlongViewDir = Math::abs(diff.dot(camera->getRotation().zAxis()));
-
-		return distAlongViewDir * mDefaultHandleSize;
-	}
+#include "BsHandleManager.h"
+#include "BsHandleDrawManager.h"
+#include "BsHandleSliderManager.h"
+#include "BsCCamera.h"
+#include "BsSceneObject.h"
+#include "BsEditorSettings.h"
+
+namespace BansheeEngine
+{
+	HandleManager::HandleManager()
+		:mSliderManager(nullptr), mDrawManager(nullptr), mSettingsHash(0xFFFFFFFF)
+	{
+		mSliderManager = bs_new<HandleSliderManager>();
+		mDrawManager = bs_new<HandleDrawManager>();
+	}
+
+	HandleManager::~HandleManager()
+	{
+		bs_delete(mSliderManager);
+		bs_delete(mDrawManager);
+	}
+
+	bool HandleManager::isHandleActive() const
+	{
+		return mSliderManager->isSliderActive();
+	}
+
+	void HandleManager::updateInput(const CameraPtr& camera, const Vector2I& inputPos, const Vector2I& inputDelta)
+	{
+		if (mSettings != nullptr && mSettingsHash != mSettings->getHash())
+			updateFromEditorSettings();
+
+		refreshHandles();
+		mSliderManager->update(camera, inputPos, inputDelta);
+		triggerHandles();
+	}
+
+	void HandleManager::draw(const CameraPtr& camera)
+	{
+		queueDrawCommands();
+		mDrawManager->draw(camera);
+	}
+
+	void HandleManager::setSettings(const EditorSettingsPtr& settings)
+	{
+		mSettings = settings;
+
+		updateFromEditorSettings();
+	}
+
+	void HandleManager::updateFromEditorSettings()
+	{
+		setDefaultHandleSize(mSettings->getHandleSize());
+
+		mSettingsHash = mSettings->getHash();
+	}
+
+	void HandleManager::trySelect(const CameraPtr& camera, const Vector2I& inputPos)
+	{
+		return mSliderManager->trySelect(camera, inputPos);
+	}
+
+	void HandleManager::clearSelection()
+	{
+		return mSliderManager->clearSelection();
+	}
+
+	float HandleManager::getHandleSize(const CameraPtr& camera, const Vector3& handlePos) const
+	{
+		Vector3 cameraPos = camera->getPosition();
+
+		Vector3 diff = handlePos - cameraPos;
+		float distAlongViewDir = Math::abs(diff.dot(camera->getRotation().zAxis()));
+
+		return distAlongViewDir * mDefaultHandleSize;
+	}
 }

+ 0 - 142
BansheeEditor/Source/BsSceneViewHandler.cpp

@@ -1,142 +0,0 @@
-#include "BsSceneViewHandler.h"
-#include "BsRendererManager.h"
-#include "BsRenderer.h"
-#include "BsGizmoManager.h"
-#include "BsHandleManager.h"
-#include "BsSceneGrid.h"
-#include "BsSelection.h"
-#include "BsScenePicking.h"
-#include "BsCamera.h"
-#include "BsEditorApplication.h"
-#include "BsEditorWidget.h"
-#include "BsEditorWindowBase.h"
-#include "BsRenderWindow.h"
-#include "BsCursor.h"
-#include "BsSelectionRenderer.h"
-
-#include "BsDebug.h"
-
-using namespace std::placeholders;
-
-namespace BansheeEngine
-{
-	SceneViewHandler::SceneViewHandler(EditorWidgetBase* parentWidget, const SPtr<Camera>& camera)
-		:mCamera(camera), mSceneGrid(nullptr), mParentWidget(parentWidget)
-	{
-		mSelectionRenderer = bs_new<SelectionRenderer>();
-		mSceneGrid = bs_new<SceneGrid>(mCamera);
-		mSceneGrid->setSettings(gEditorApplication().getEditorSettings());
-		HandleManager::instance().setSettings(gEditorApplication().getEditorSettings());
-	}
-
-	SceneViewHandler::~SceneViewHandler()
-	{
-		bs_delete(mSceneGrid);
-		bs_delete(mSelectionRenderer);
-
-		if (GizmoManager::isStarted()) // If not active, we don't care
-			GizmoManager::instance().clearRenderData();
-	}
-
-	void SceneViewHandler::update()
-	{
-		GizmoManager::instance().update(mCamera);
-		mSceneGrid->update();
-	}
-
-	void SceneViewHandler::updateHandle(const Vector2I& position, const Vector2I& delta)
-	{
-		// If mouse wrapped around last frame then we need to compensate for the jump amount
-		Vector2I realDelta = delta - mMouseDeltaCompensate;
-		mMouseDeltaCompensate = Vector2I::ZERO;
-
-		if (HandleManager::instance().isHandleActive())
-			mMouseDeltaCompensate = wrapCursorToWindow();
-
-		HandleManager::instance().update(mCamera, position, realDelta);
-	}
-
-	void SceneViewHandler::updateSelection()
-	{
-		// Call this after handle update to ensure its drawn at the right place
-		mSelectionRenderer->update(mCamera);
-	}
-
-	void SceneViewHandler::trySelectHandle(const Vector2I& position)
-	{
-		HandleManager::instance().trySelect(mCamera, position);
-	}
-
-	bool SceneViewHandler::isHandleActive() const
-	{
-		return HandleManager::instance().isHandleActive();
-	}
-
-	void SceneViewHandler::clearHandleSelection()
-	{
-		HandleManager::instance().clearSelection();
-	}
-
-	void SceneViewHandler::pickObject(const Vector2I& position, bool additive)
-	{
-		// TODO - Handle multi-selection (i.e. selection rectangle when dragging)
-		HSceneObject pickedObject = ScenePicking::instance().pickClosestObject(mCamera, position, Vector2I(1, 1));
-
-		if (pickedObject)
-		{
-			if (additive) // Append to existing selection
-			{
-				Vector<HSceneObject> selectedSOs = Selection::instance().getSceneObjects();
-
-				auto iterFind = std::find_if(selectedSOs.begin(), selectedSOs.end(),
-					[&](const HSceneObject& obj) { return obj == pickedObject; }
-				);
-
-				if (iterFind == selectedSOs.end())
-					selectedSOs.push_back(pickedObject);
-
-				Selection::instance().setSceneObjects(selectedSOs);
-			}
-			else
-			{
-				Vector<HSceneObject> selectedSOs = { pickedObject };
-
-				Selection::instance().setSceneObjects(selectedSOs);
-			}
-		}
-		else
-			Selection::instance().clearSceneSelection();
-	}
-
-	Vector2I SceneViewHandler::wrapCursorToWindow()
-	{
-		if (mParentWidget == nullptr)
-			return Vector2I();
-
-		RenderWindowPtr parentWindow = mParentWidget->getParentWindow()->getRenderWindow();
-
-		Vector2I windowPos = parentWindow->screenToWindowPos(Cursor::instance().getScreenPosition());
-		const RenderWindowProperties& rwProps = parentWindow->getProperties();
-
-		INT32 maxWidth = std::max(0, (INT32)rwProps.getWidth() - 1);
-		INT32 maxHeight = std::max(0, (INT32)rwProps.getHeight() - 1);
-
-		Vector2I offset;
-		if (windowPos.x <= 0)
-			offset.x = maxWidth;
-		else if (windowPos.x >= maxWidth)
-			offset.x = -maxWidth;
-
-		if (windowPos.y <= 0)
-			offset.y = maxHeight;
-		else if (windowPos.y >= maxHeight)
-			offset.y = -maxHeight;
-
-		windowPos += offset;
-
-		Vector2I wrappedScreenPos = parentWindow->windowToScreenPos(windowPos);
-		Cursor::instance().setScreenPosition(wrappedScreenPos);
-
-		return offset;
-	}
-}

+ 4 - 1
MBansheeEditor/MBansheeEditor.csproj

@@ -133,7 +133,10 @@
     <Compile Include="ProjectWindow.cs" />
     <Compile Include="Scene\SceneAxesHandle.cs" />
     <Compile Include="Scene\SceneCamera.cs" />
-    <Compile Include="Scene\SceneViewHandler.cs" />
+    <Compile Include="Scene\SceneGizmos.cs" />
+    <Compile Include="Scene\SceneGrid.cs" />
+    <Compile Include="Scene\SceneHandles.cs" />
+    <Compile Include="Scene\SceneSelection.cs" />
     <Compile Include="Scene\SceneWindow.cs" />
     <Compile Include="Scene\DefaultHandle.cs" />
     <Compile Include="Scene\DefaultHandleManager.cs" />

+ 35 - 0
MBansheeEditor/Scene/SceneGizmos.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Runtime.CompilerServices;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Handles rendering of the scene gizmos for the specified camera. 
+    /// </summary>
+    internal sealed class SceneGizmos : ScriptObject
+    {
+        /// <summary>
+        /// Creates a new scene gizmo renderer.
+        /// </summary>
+        /// <param name="sceneCamera">Camera into which the gizmos will be rendered.</param>
+        internal SceneGizmos(Camera sceneCamera)
+        {
+            Internal_Create(this, sceneCamera.Native.GetCachedPtr());
+        }
+
+        /// <summary>
+        /// Queues gizmo drawing for this frame.
+        /// </summary>
+        internal void Draw()
+        {
+            Internal_Draw(mCachedPtr);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Create(SceneGizmos managedInstance, IntPtr camera);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Draw(IntPtr thisPtr);
+    }
+}

+ 36 - 0
MBansheeEditor/Scene/SceneGrid.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Runtime.CompilerServices;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Handles rendering of the scene grid for the specified camera. Grid properties are controlled through 
+    /// <see cref="EditorSettings"/>.
+    /// </summary>
+    internal sealed class SceneGrid : ScriptObject
+    {
+        /// <summary>
+        /// Creates a new scene grid renderer.
+        /// </summary>
+        /// <param name="sceneCamera">Camera into which the grid will be rendered.</param>
+        internal SceneGrid(Camera sceneCamera)
+        {
+            Internal_Create(this, sceneCamera.Native.GetCachedPtr());
+        }
+
+        /// <summary>
+        /// Queues grid drawing for this frame.
+        /// </summary>
+        internal void Draw()
+        {
+            Internal_Draw(mCachedPtr);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Create(SceneGrid managedInstance, IntPtr camera);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Draw(IntPtr thisPtr);
+    }
+}

+ 84 - 0
MBansheeEditor/Scene/SceneHandles.cs

@@ -0,0 +1,84 @@
+using System;
+using System.Runtime.CompilerServices;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Handles rendering and interaction with scene handles for the specified camera. 
+    /// </summary>
+    internal sealed class SceneHandles : ScriptObject
+    {
+        /// <summary>
+        /// Creates a new scene handle manager.
+        /// </summary>
+        /// <param name="parent">Editor window in which the scene handles are displayed.</param>
+        /// <param name="sceneCamera">Camera through which the scene handles are displayed.</param>
+        internal SceneHandles(EditorWindow parent, Camera sceneCamera)
+        {
+            Internal_Create(this, parent.GetCachedPtr(), sceneCamera.Native.GetCachedPtr());
+        }
+
+        /// <summary>
+        /// Updates active handles by moving them as a result of any input.
+        /// </summary>
+        /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
+        /// <param name="inputDelta">Movement of the pointer since last frame.</param>
+        internal void UpdateInput(Vector2I pointerPos, Vector2I inputDelta)
+        {
+            Internal_UpdateInput(mCachedPtr, ref pointerPos, ref inputDelta);
+        }
+
+        /// <summary>
+        /// Draws the handles onto the target camera.
+        /// </summary>
+        internal void Draw()
+        {
+            Internal_Draw(mCachedPtr);
+        }
+
+        /// <summary>
+        /// Selects a handle under the pointer position.
+        /// </summary>
+        /// <param name="pointerPos">Position of the pointer relative to the target camera's viewport.</param>
+        internal void TrySelect(Vector2I pointerPos)
+        {
+            Internal_TrySelect(mCachedPtr, ref pointerPos);
+        }
+
+        /// <summary>
+        /// Checks is any handle currently active.
+        /// </summary>
+        /// <returns>True if a handle is active.</returns>
+        internal bool IsActive()
+        {
+            return Internal_IsActive(mCachedPtr);
+        }
+
+        /// <summary>
+        /// Deselects any currently active handles.
+        /// </summary>
+        internal void ClearSelection()
+        {
+            Internal_ClearSelection(mCachedPtr);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Create(SceneHandles managedInstance, IntPtr parentWindow, IntPtr camera);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_UpdateInput(IntPtr thisPtr, ref Vector2I pointerPos, ref Vector2I inputDelta);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Draw(IntPtr thisPtr);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_TrySelect(IntPtr thisPtr, ref Vector2I pointerPos);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_IsActive(IntPtr thisPtr);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ClearSelection(IntPtr thisPtr);
+    }
+}

+ 48 - 0
MBansheeEditor/Scene/SceneSelection.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Runtime.CompilerServices;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Handles rendering of the selection overlay and picking of objects in the target camera's view.
+    /// </summary>
+    internal sealed class SceneSelection : ScriptObject
+    {
+        /// <summary>
+        /// Creates a new scene selection manager.
+        /// </summary>
+        /// <param name="sceneCamera">Camera into which to render the selection overlay, and perform picking from.</param>
+        internal SceneSelection(Camera sceneCamera)
+        {
+            Internal_Create(this, sceneCamera.Native.GetCachedPtr());
+        }
+
+        /// <summary>
+        /// Queues selection overlay drawing for this frame.
+        /// </summary>
+        internal void Draw()
+        {
+            Internal_Draw(mCachedPtr);
+        }
+
+        /// <summary>
+        /// Attempts to select a scene object under the pointer position.
+        /// </summary>
+        /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
+        /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
+        internal void PickObject(Vector2I pointerPos, bool controlHeld)
+        {
+            Internal_PickObject(mCachedPtr, ref pointerPos, controlHeld);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Create(SceneSelection managedInstance, IntPtr camera);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Draw(IntPtr thisPtr);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_PickObject(IntPtr thisPtr, ref Vector2I pointerPos, bool controlHeld);
+    }
+}

+ 0 - 112
MBansheeEditor/Scene/SceneViewHandler.cs

@@ -1,112 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
-using System.Threading.Tasks;
-using BansheeEngine;
-
-namespace BansheeEditor
-{
-    /// <summary>
-    /// Handles scene view handle interactions, object picking and gizmos.
-    /// </summary>
-    internal sealed class SceneViewHandler : ScriptObject
-    {
-        /// <summary>
-        /// Creates a new scene view handler.
-        /// </summary>
-        /// <param name="parent">Editor window in which the scene view is displayed.</param>
-        /// <param name="sceneCamera">Camera through which the scene view is displayed.</param>
-        internal SceneViewHandler(EditorWindow parent, Camera sceneCamera)
-        {
-            Internal_Create(this, parent.GetCachedPtr(), sceneCamera.Native.GetCachedPtr());
-        }
-
-        /// <summary>
-        /// Called every frame. Updates gizmos and scene grid.
-        /// </summary>
-        internal void Update()
-        {
-            Internal_Update(mCachedPtr);
-        }
-
-        /// <summary>
-        /// Updates currently active handles.
-        /// </summary>
-        /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
-        /// <param name="inputDelta">Movement of the pointer since last frame.</param>
-        internal void UpdateHandle(Vector2I pointerPos, Vector2I inputDelta)
-        {
-            Internal_UpdateHandle(mCachedPtr, ref pointerPos, ref inputDelta);
-        }
-
-        /// <summary>
-        /// Updates the selection overlay for currently selected object(s).
-        /// </summary>
-        internal void UpdateSelection()
-        {
-            Internal_UpdateSelection(mCachedPtr);
-        }
-
-        /// <summary>
-        /// Selects a handle under the pointer position.
-        /// </summary>
-        /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
-        internal void TrySelectHandle(Vector2I pointerPos)
-        {
-            Internal_TrySelectHandle(mCachedPtr, ref pointerPos);
-        }
-
-        /// <summary>
-        /// Checks is any handle currently active.
-        /// </summary>
-        /// <returns>True if a handle is active.</returns>
-        internal bool IsHandleActive()
-        {
-            return Internal_IsHandleActive(mCachedPtr);
-        }
-
-        /// <summary>
-        /// Deselects any currently active handles.
-        /// </summary>
-        internal void ClearHandleSelection()
-        {
-            Internal_ClearHandleSelection(mCachedPtr);
-        }
-
-        /// <summary>
-        /// Attempts to select a scene object under the pointer position.
-        /// </summary>
-        /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
-        /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
-        internal void PickObject(Vector2I pointerPos, bool controlHeld)
-        {
-            Internal_PickObject(mCachedPtr, ref pointerPos, controlHeld);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Create(SceneViewHandler managedInstance, IntPtr parentWindow, IntPtr camera);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Update(IntPtr thisPtr);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_UpdateHandle(IntPtr thisPtr, ref Vector2I pointerPos, ref Vector2I inputDelta);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_UpdateSelection(IntPtr thisPtr);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_TrySelectHandle(IntPtr thisPtr, ref Vector2I pointerPos);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern bool Internal_IsHandleActive(IntPtr thisPtr);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_ClearHandleSelection(IntPtr thisPtr);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_PickObject(IntPtr thisPtr, ref Vector2I pointerPos, bool controlHeld);
-    }
-}

+ 18 - 10
MBansheeEditor/Scene/SceneWindow.cs

@@ -34,7 +34,10 @@ namespace BansheeEditor
         private GUIPanel rtPanel;
 
         private GUIRenderTexture renderTextureGUI;
-        private SceneViewHandler sceneViewHandler;
+        private SceneGrid sceneGrid;
+        private SceneSelection sceneSelection;
+        private SceneGizmos sceneGizmos;
+        private SceneHandles sceneHandles;
 
         private GUIToggle viewButton;
         private GUIToggle moveButton;
@@ -311,14 +314,15 @@ namespace BansheeEditor
             }
 
             // Update scene view handles and selection
-            sceneViewHandler.Update();
+            sceneGizmos.Draw();
+            sceneGrid.Draw();
 
             bool handleActive = false;
             if (Input.IsPointerButtonUp(PointerButton.Left))
             {
-                if (sceneViewHandler.IsHandleActive())
+                if (sceneHandles.IsActive())
                 {
-                    sceneViewHandler.ClearHandleSelection();
+                    sceneHandles.ClearSelection();
                     handleActive = true;
                 }
             }
@@ -406,7 +410,7 @@ namespace BansheeEditor
                 {
                     if (Input.IsPointerButtonDown(PointerButton.Left))
                     {
-                        sceneViewHandler.TrySelectHandle(scenePos);
+                        sceneHandles.TrySelect(scenePos);
                     }
                     else if (Input.IsPointerButtonUp(PointerButton.Left))
                     {
@@ -415,7 +419,7 @@ namespace BansheeEditor
                             bool ctrlHeld = Input.IsButtonHeld(ButtonCode.LeftControl) ||
                                             Input.IsButtonHeld(ButtonCode.RightControl);
 
-                            sceneViewHandler.PickObject(scenePos, ctrlHeld);
+                            sceneSelection.PickObject(scenePos, ctrlHeld);
                         }
                     }
                 }
@@ -423,8 +427,9 @@ namespace BansheeEditor
             else
                 cameraController.EnableInput(false);
 
-            sceneViewHandler.UpdateHandle(scenePos, Input.PointerDelta);
-            sceneViewHandler.UpdateSelection();
+            sceneHandles.UpdateInput(scenePos, Input.PointerDelta);
+            sceneHandles.Draw();
+            sceneSelection.Draw();
 
             if (VirtualInput.IsButtonDown(frameKey))
             {
@@ -445,7 +450,7 @@ namespace BansheeEditor
         {
             if (!inFocus)
             {
-                sceneViewHandler.ClearHandleSelection();
+                sceneHandles.ClearSelection();
             }
         }
 
@@ -640,7 +645,10 @@ namespace BansheeEditor
                 renderTextureGUI = new GUIRenderTexture(renderTexture);
                 rtPanel.AddElement(renderTextureGUI);
 
-                sceneViewHandler = new SceneViewHandler(this, camera);
+		        sceneGrid = new SceneGrid(camera);
+		        sceneSelection = new SceneSelection(camera);
+		        sceneGizmos = new SceneGizmos(camera);
+		        sceneHandles = new SceneHandles(this, camera);
 		    }
 		    else
 		    {

+ 26 - 0
SBansheeEditor/Include/BsScriptSceneGizmos.h

@@ -0,0 +1,26 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptObject.h"
+
+namespace BansheeEngine
+{
+	/** Interop class between C++ & CLR for SceneGizmos. */
+	class BS_SCR_BED_EXPORT ScriptSceneGizmos : public ScriptObject <ScriptSceneGizmos>
+	{
+	public:
+		SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "SceneGizmos")
+
+	private:
+		ScriptSceneGizmos(MonoObject* object, const SPtr<Camera>& camera);
+		~ScriptSceneGizmos();
+
+		SPtr<Camera> mCamera;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_Create(MonoObject* managedInstance, ScriptCamera* camera);
+		static void internal_Draw(ScriptSceneGizmos* thisPtr);
+	};
+}

+ 26 - 0
SBansheeEditor/Include/BsScriptSceneGrid.h

@@ -0,0 +1,26 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptObject.h"
+
+namespace BansheeEngine
+{
+	/** Interop class between C++ & CLR for SceneGrid. */
+	class BS_SCR_BED_EXPORT ScriptSceneGrid : public ScriptObject <ScriptSceneGrid>
+	{
+	public:
+		SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "SceneGrid")
+
+	private:
+		ScriptSceneGrid(MonoObject* object, const SPtr<Camera>& camera);
+		~ScriptSceneGrid();
+
+		SceneGrid* mSceneGrid;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_Create(MonoObject* managedInstance, ScriptCamera* camera);
+		static void internal_Draw(ScriptSceneGrid* thisPtr);
+	};
+}

+ 42 - 0
SBansheeEditor/Include/BsScriptSceneHandles.h

@@ -0,0 +1,42 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsVector2I.h"
+
+namespace BansheeEngine
+{
+	/** Interop class between C++ & CLR for SceneHandles. */
+	class BS_SCR_BED_EXPORT ScriptSceneHandles : public ScriptObject <ScriptSceneHandles>
+	{
+	public:
+		SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "SceneHandles")
+
+	private:
+		ScriptSceneHandles(MonoObject* object, EditorWidgetBase* parentWidget, const SPtr<Camera>& camera);
+		~ScriptSceneHandles();
+
+		/**
+		 * @brief	Checks is the pointer currently within the provided window, and if it is not
+		 *			the cursor is wrapped in such a way so that it is returned to within the window bounds.
+		 *		
+		 * @return	How far was the cursor moved due to wrapping. This will be (0, 0) if the cursor is within
+		 *			window bounds initially.
+		 */
+		Vector2I wrapCursorToWindow() const;
+
+		EditorWidgetBase* mParentWidget;
+		SPtr<Camera> mCamera;
+		Vector2I mMouseDeltaCompensate;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_Create(MonoObject* managedInstance, ScriptEditorWindow* parentWindow, ScriptCamera* camera);
+		static void internal_Draw(ScriptSceneHandles* thisPtr);
+		static void internal_UpdateInput(ScriptSceneHandles* thisPtr, Vector2I* inputPos, Vector2I* inputDelta);
+		static void internal_TrySelect(ScriptSceneHandles* thisPtr, Vector2I* inputPos);
+		static bool internal_IsActive(ScriptSceneHandles* thisPtr);
+		static void internal_ClearSelection(ScriptSceneHandles* thisPtr);
+	};
+}

+ 28 - 0
SBansheeEditor/Include/BsScriptSceneSelection.h

@@ -0,0 +1,28 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptObject.h"
+
+namespace BansheeEngine
+{
+	/** Interop class between C++ & CLR for SceneSelection. */
+	class BS_SCR_BED_EXPORT ScriptSceneSelection : public ScriptObject <ScriptSceneSelection>
+	{
+	public:
+		SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "SceneSelection")
+
+	private:
+		ScriptSceneSelection(MonoObject* object, const SPtr<Camera>& camera);
+		~ScriptSceneSelection();
+
+		SPtr<Camera> mCamera;
+		SelectionRenderer* mSelectionRenderer;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_Create(MonoObject* managedInstance, ScriptCamera* camera);
+		static void internal_Draw(ScriptSceneSelection* thisPtr);
+		static void internal_PickObject(ScriptSceneSelection* thisPtr, Vector2I* inputPos, bool additive);
+	};
+}

+ 0 - 34
SBansheeEditor/Include/BsScriptSceneViewHandler.h

@@ -1,34 +0,0 @@
-#pragma once
-
-#include "BsScriptEditorPrerequisites.h"
-#include "BsScriptObject.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Interop class between C++ & CLR for SceneViewHandler.
-	 */
-	class BS_SCR_BED_EXPORT ScriptSceneViewHandler : public ScriptObject < ScriptSceneViewHandler >
-	{
-	public:
-		SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "SceneViewHandler")
-
-	private:
-		ScriptSceneViewHandler(MonoObject* object, EditorWidgetBase* parentWidget, const SPtr<Camera>& camera);
-		~ScriptSceneViewHandler();
-
-		SceneViewHandler* mHandler;
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static void internal_Create(MonoObject* managedInstance, ScriptEditorWindow* parentWindow, ScriptCamera* camera);
-		static void internal_Update(ScriptSceneViewHandler* thisPtr);
-		static void internal_UpdateHandle(ScriptSceneViewHandler* thisPtr, Vector2I* inputPos, Vector2I* inputDelta);
-		static void internal_UpdateSelection(ScriptSceneViewHandler* thisPtr);
-		static void internal_TrySelectHandle(ScriptSceneViewHandler* thisPtr, Vector2I* inputPos);
-		static bool internal_IsHandleActive(ScriptSceneViewHandler* thisPtr);
-		static void internal_ClearHandleSelection(ScriptSceneViewHandler* thisPtr);
-		static void internal_PickObject(ScriptSceneViewHandler* thisPtr, Vector2I* inputPos, bool additive);
-	};
-}

+ 8 - 2
SBansheeEditor/SBansheeEditor.vcxproj

@@ -257,6 +257,7 @@
     <ClInclude Include="Include\BsGUIResourceField.h" />
     <ClInclude Include="Include\BsGUITextureField.h" />
     <ClInclude Include="Include\BsMenuItemManager.h" />
+    <ClInclude Include="Include\BsScriptSceneHandles.h" />
     <ClInclude Include="Include\BsScriptBrowseDialog.h" />
     <ClInclude Include="Include\BsScriptBuildManager.h" />
     <ClInclude Include="Include\BsScriptCodeEditor.h" />
@@ -304,7 +305,9 @@
     <ClInclude Include="Include\BsScriptPrefabUtility.h" />
     <ClInclude Include="Include\BsScriptProjectLibrary.h" />
     <ClInclude Include="Include\BsScriptProjectSettings.h" />
-    <ClInclude Include="Include\BsScriptSceneViewHandler.h" />
+    <ClInclude Include="Include\BsScriptSceneGizmos.h" />
+    <ClInclude Include="Include\BsScriptSceneGrid.h" />
+    <ClInclude Include="Include\BsScriptSceneSelection.h" />
     <ClInclude Include="Include\BsScriptSelection.h" />
     <ClInclude Include="Include\BsScriptUndoRedo.h" />
     <ClInclude Include="Include\BsScriptUnitTests.h" />
@@ -315,6 +318,7 @@
     <ClCompile Include="Source\BsEditorScriptLibrary.cpp" />
     <ClCompile Include="Source\BsGUITextureField.cpp" />
     <ClCompile Include="Source\BsMenuItemManager.cpp" />
+    <ClCompile Include="Source\BsScriptSceneHandles.cpp" />
     <ClCompile Include="Source\BsScriptBuildManager.cpp" />
     <ClCompile Include="Source\BsScriptCodeEditor.cpp" />
     <ClCompile Include="Source\BsScriptDragDropManager.cpp" />
@@ -365,7 +369,9 @@
     <ClCompile Include="Source\BsScriptPrefabUtility.cpp" />
     <ClCompile Include="Source\BsScriptProjectLibrary.cpp" />
     <ClCompile Include="Source\BsScriptProjectSettings.cpp" />
-    <ClCompile Include="Source\BsScriptSceneViewHandler.cpp" />
+    <ClCompile Include="Source\BsScriptSceneGizmos.cpp" />
+    <ClCompile Include="Source\BsScriptSceneGrid.cpp" />
+    <ClCompile Include="Source\BsScriptSceneSelection.cpp" />
     <ClCompile Include="Source\BsScriptSelection.cpp" />
     <ClCompile Include="Source\BsScriptUndoRedo.cpp" />
     <ClCompile Include="Source\BsScriptUnitTests.cpp" />

+ 24 - 6
SBansheeEditor/SBansheeEditor.vcxproj.filters

@@ -96,9 +96,6 @@
     <ClInclude Include="Include\BsScriptHandleSliderManager.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Include\BsScriptSceneViewHandler.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsScriptEditorSettings.h">
       <Filter>Header Files</Filter>
     </ClInclude>
@@ -192,6 +189,18 @@
     <ClInclude Include="Include\BsScriptEditorVirtualInput.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptSceneGrid.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptSceneSelection.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptSceneGizmos.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptSceneHandles.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptEditorPlugin.cpp">
@@ -275,9 +284,6 @@
     <ClCompile Include="Source\BsScriptHandleSliderManager.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Source\BsScriptSceneViewHandler.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsScriptEditorSettings.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
@@ -371,5 +377,17 @@
     <ClCompile Include="Source\BsScriptEditorVirtualInput.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptSceneGrid.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptSceneSelection.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptSceneGizmos.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptSceneHandles.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 34 - 0
SBansheeEditor/Source/BsScriptSceneGizmos.cpp

@@ -0,0 +1,34 @@
+#include "BsScriptSceneGizmos.h"
+#include "BsScriptCamera.h"
+#include "BsGizmoManager.h"
+
+namespace BansheeEngine
+{
+	ScriptSceneGizmos::ScriptSceneGizmos(MonoObject* object, const SPtr<Camera>& camera)
+		:ScriptObject(object), mCamera(camera)
+	{
+
+	}
+
+	ScriptSceneGizmos::~ScriptSceneGizmos()
+	{
+		if (GizmoManager::isStarted()) // If not active, we don't care
+			GizmoManager::instance().clearRenderData();
+	}
+
+	void ScriptSceneGizmos::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_Create", &ScriptSceneGizmos::internal_Create);
+		metaData.scriptClass->addInternalCall("Internal_Draw", &ScriptSceneGizmos::internal_Draw);
+	}
+
+	void ScriptSceneGizmos::internal_Create(MonoObject* managedInstance, ScriptCamera* camera)
+	{
+		new (bs_alloc<ScriptSceneGizmos>()) ScriptSceneGizmos(managedInstance, camera->getInternal());
+	}
+
+	void ScriptSceneGizmos::internal_Draw(ScriptSceneGizmos* thisPtr)
+	{
+		GizmoManager::instance().update(thisPtr->mCamera);
+	}
+}

+ 35 - 0
SBansheeEditor/Source/BsScriptSceneGrid.cpp

@@ -0,0 +1,35 @@
+#include "BsScriptSceneGrid.h"
+#include "BsScriptCamera.h"
+#include "BsEditorApplication.h"
+#include "BsSceneGrid.h"
+
+namespace BansheeEngine
+{
+	ScriptSceneGrid::ScriptSceneGrid(MonoObject* object, const SPtr<Camera>& camera)
+		:ScriptObject(object), mSceneGrid(nullptr)
+	{
+		mSceneGrid = bs_new<SceneGrid>(camera);
+		mSceneGrid->setSettings(gEditorApplication().getEditorSettings());
+	}
+
+	ScriptSceneGrid::~ScriptSceneGrid()
+	{
+		bs_delete(mSceneGrid);
+	}
+
+	void ScriptSceneGrid::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_Create", &ScriptSceneGrid::internal_Create);
+		metaData.scriptClass->addInternalCall("Internal_Draw", &ScriptSceneGrid::internal_Draw);
+	}
+
+	void ScriptSceneGrid::internal_Create(MonoObject* managedInstance, ScriptCamera* camera)
+	{
+		new (bs_alloc<ScriptSceneGrid>()) ScriptSceneGrid(managedInstance, camera->getInternal());
+	}
+
+	void ScriptSceneGrid::internal_Draw(ScriptSceneGrid* thisPtr)
+	{
+		thisPtr->mSceneGrid->update();
+	}
+}

+ 107 - 0
SBansheeEditor/Source/BsScriptSceneHandles.cpp

@@ -0,0 +1,107 @@
+#include "BsScriptSceneHandles.h"
+#include "BsScriptCamera.h"
+#include "BsScriptEditorWindow.h"
+#include "BsCursor.h"
+#include "BsRenderWindow.h"
+#include "BsEditorWidget.h"
+#include "BsEditorWindow.h"
+#include "BsHandleManager.h"
+#include "BsEditorApplication.h"
+
+namespace BansheeEngine
+{
+	ScriptSceneHandles::ScriptSceneHandles(MonoObject* object, EditorWidgetBase* parentWidget, const SPtr<Camera>& camera)
+		:ScriptObject(object), mCamera(camera), mParentWidget(parentWidget)
+	{
+		HandleManager::instance().setSettings(gEditorApplication().getEditorSettings());
+	}
+
+	ScriptSceneHandles::~ScriptSceneHandles()
+	{
+
+	}
+
+	void ScriptSceneHandles::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_Create", &ScriptSceneHandles::internal_Create);
+		metaData.scriptClass->addInternalCall("Internal_Draw", &ScriptSceneHandles::internal_Draw);
+		metaData.scriptClass->addInternalCall("Internal_UpdateInput", &ScriptSceneHandles::internal_UpdateInput);
+		metaData.scriptClass->addInternalCall("Internal_TrySelect", &ScriptSceneHandles::internal_TrySelect);
+		metaData.scriptClass->addInternalCall("Internal_IsActive", &ScriptSceneHandles::internal_IsActive);
+		metaData.scriptClass->addInternalCall("Internal_ClearSelection", &ScriptSceneHandles::internal_ClearSelection);
+	}
+
+	Vector2I ScriptSceneHandles::wrapCursorToWindow() const
+	{
+		if (mParentWidget == nullptr)
+			return Vector2I();
+
+		RenderWindowPtr parentWindow = mParentWidget->getParentWindow()->getRenderWindow();
+
+		Vector2I windowPos = parentWindow->screenToWindowPos(Cursor::instance().getScreenPosition());
+		const RenderWindowProperties& rwProps = parentWindow->getProperties();
+
+		INT32 maxWidth = std::max(0, (INT32)rwProps.getWidth() - 1);
+		INT32 maxHeight = std::max(0, (INT32)rwProps.getHeight() - 1);
+
+		Vector2I offset;
+		if (windowPos.x <= 0)
+			offset.x = maxWidth;
+		else if (windowPos.x >= maxWidth)
+			offset.x = -maxWidth;
+
+		if (windowPos.y <= 0)
+			offset.y = maxHeight;
+		else if (windowPos.y >= maxHeight)
+			offset.y = -maxHeight;
+
+		windowPos += offset;
+
+		Vector2I wrappedScreenPos = parentWindow->windowToScreenPos(windowPos);
+		Cursor::instance().setScreenPosition(wrappedScreenPos);
+
+		return offset;
+	}
+
+	void ScriptSceneHandles::internal_Create(MonoObject* managedInstance, ScriptEditorWindow* parentWindow, ScriptCamera* camera)
+	{
+		EditorWidgetBase* widget = nullptr;
+
+		if (parentWindow != nullptr && !parentWindow->isDestroyed())
+			widget = parentWindow->getEditorWidget();
+
+		new (bs_alloc<ScriptSceneHandles>()) ScriptSceneHandles(managedInstance, widget, camera->getInternal());
+	}
+
+	void ScriptSceneHandles::internal_Draw(ScriptSceneHandles* thisPtr)
+	{
+		HandleManager::instance().draw(thisPtr->mCamera);
+	}
+
+	void ScriptSceneHandles::internal_UpdateInput(ScriptSceneHandles* thisPtr, Vector2I* inputPos, Vector2I* inputDelta)
+	{
+		// If mouse wrapped around last frame then we need to compensate for the jump amount
+		Vector2I realDelta = *inputDelta - thisPtr->mMouseDeltaCompensate;
+		thisPtr->mMouseDeltaCompensate = Vector2I::ZERO;
+
+		if (HandleManager::instance().isHandleActive())
+			thisPtr->mMouseDeltaCompensate = thisPtr->wrapCursorToWindow();
+
+		HandleManager::instance().updateInput(thisPtr->mCamera, *inputPos, realDelta);
+	}
+
+	void ScriptSceneHandles::internal_TrySelect(ScriptSceneHandles* thisPtr, Vector2I* inputPos)
+	{
+		HandleManager::instance().trySelect(thisPtr->mCamera, *inputPos);
+	}
+
+	bool ScriptSceneHandles::internal_IsActive(ScriptSceneHandles* thisPtr)
+	{
+		return HandleManager::instance().isHandleActive();
+	}
+
+	void ScriptSceneHandles::internal_ClearSelection(ScriptSceneHandles* thisPtr)
+	{
+		HandleManager::instance().clearSelection();
+	}
+}

+ 67 - 0
SBansheeEditor/Source/BsScriptSceneSelection.cpp

@@ -0,0 +1,67 @@
+#include "BsScriptSceneSelection.h"
+#include "BsScriptCamera.h"
+#include "BsSelectionRenderer.h"
+#include "BsScenePicking.h"
+#include "BsSelection.h"
+
+namespace BansheeEngine
+{
+	ScriptSceneSelection::ScriptSceneSelection(MonoObject* object, const SPtr<Camera>& camera)
+		:ScriptObject(object), mSelectionRenderer(nullptr), mCamera(camera)
+	{
+		mSelectionRenderer = bs_new<SelectionRenderer>();
+	}
+
+	ScriptSceneSelection::~ScriptSceneSelection()
+	{
+		bs_delete(mSelectionRenderer);
+	}
+
+	void ScriptSceneSelection::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_Create", &ScriptSceneSelection::internal_Create);
+		metaData.scriptClass->addInternalCall("Internal_Draw", &ScriptSceneSelection::internal_Draw);
+		metaData.scriptClass->addInternalCall("Internal_PickObject", &ScriptSceneSelection::internal_PickObject);
+	}
+
+	void ScriptSceneSelection::internal_Create(MonoObject* managedInstance, ScriptCamera* camera)
+	{
+		new (bs_alloc<ScriptSceneSelection>()) ScriptSceneSelection(managedInstance, camera->getInternal());
+	}
+
+	void ScriptSceneSelection::internal_Draw(ScriptSceneSelection* thisPtr)
+	{
+		thisPtr->mSelectionRenderer->update(thisPtr->mCamera);
+	}
+
+	void ScriptSceneSelection::internal_PickObject(ScriptSceneSelection* thisPtr, Vector2I* inputPos, bool additive)
+	{
+		// TODO - Handle multi-selection (i.e. selection rectangle when dragging)
+		HSceneObject pickedObject = ScenePicking::instance().pickClosestObject(thisPtr->mCamera, *inputPos, Vector2I(1, 1));
+
+		if (pickedObject)
+		{
+			if (additive) // Append to existing selection
+			{
+				Vector<HSceneObject> selectedSOs = Selection::instance().getSceneObjects();
+
+				auto iterFind = std::find_if(selectedSOs.begin(), selectedSOs.end(),
+					[&](const HSceneObject& obj) { return obj == pickedObject; }
+				);
+
+				if (iterFind == selectedSOs.end())
+					selectedSOs.push_back(pickedObject);
+
+				Selection::instance().setSceneObjects(selectedSOs);
+			}
+			else
+			{
+				Vector<HSceneObject> selectedSOs = { pickedObject };
+
+				Selection::instance().setSceneObjects(selectedSOs);
+			}
+		}
+		else
+			Selection::instance().clearSceneSelection();
+	}
+}

+ 0 - 80
SBansheeEditor/Source/BsScriptSceneViewHandler.cpp

@@ -1,80 +0,0 @@
-#include "BsScriptSceneViewHandler.h"
-#include "BsScriptMeta.h"
-#include "BsMonoClass.h"
-#include "BsMonoUtil.h"
-#include "BsSceneViewHandler.h"
-#include "BsScriptCamera.h"
-#include "BsScriptEditorWindow.h"
-#include "BsEditorWidgetContainer.h"
-#include "BsEditorWindowBase.h"
-
-namespace BansheeEngine
-{
-	ScriptSceneViewHandler::ScriptSceneViewHandler(MonoObject* object, EditorWidgetBase* parentWidget, const SPtr<Camera>& camera)
-		:ScriptObject(object), mHandler(nullptr)
-	{ 
-		mHandler = bs_new<SceneViewHandler>(parentWidget, camera);
-	}
-
-	ScriptSceneViewHandler::~ScriptSceneViewHandler()
-	{
-		bs_delete(mHandler);
-	}
-
-	void ScriptSceneViewHandler::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_Create", &ScriptSceneViewHandler::internal_Create);
-		metaData.scriptClass->addInternalCall("Internal_Update", &ScriptSceneViewHandler::internal_Update);
-		metaData.scriptClass->addInternalCall("Internal_UpdateHandle", &ScriptSceneViewHandler::internal_UpdateHandle);
-		metaData.scriptClass->addInternalCall("Internal_UpdateSelection", &ScriptSceneViewHandler::internal_UpdateSelection);
-		metaData.scriptClass->addInternalCall("Internal_TrySelectHandle", &ScriptSceneViewHandler::internal_TrySelectHandle);
-		metaData.scriptClass->addInternalCall("Internal_IsHandleActive", &ScriptSceneViewHandler::internal_IsHandleActive);
-		metaData.scriptClass->addInternalCall("Internal_ClearHandleSelection", &ScriptSceneViewHandler::internal_ClearHandleSelection);
-		metaData.scriptClass->addInternalCall("Internal_PickObject", &ScriptSceneViewHandler::internal_PickObject);
-	}
-
-	void ScriptSceneViewHandler::internal_Create(MonoObject* managedInstance, ScriptEditorWindow* parentWindow, ScriptCamera* camera)
-	{
-		EditorWidgetBase* widget = nullptr;
-		
-		if (parentWindow != nullptr && !parentWindow->isDestroyed())
-			widget = parentWindow->getEditorWidget();
-
-		new (bs_alloc<ScriptSceneViewHandler>()) ScriptSceneViewHandler(managedInstance, widget, camera->getInternal());
-	}
-
-	void ScriptSceneViewHandler::internal_Update(ScriptSceneViewHandler* thisPtr)
-	{
-		thisPtr->mHandler->update();
-	}
-
-	void ScriptSceneViewHandler::internal_UpdateHandle(ScriptSceneViewHandler* thisPtr, Vector2I* inputPos, Vector2I* inputDelta)
-	{
-		thisPtr->mHandler->updateHandle(*inputPos, *inputDelta);
-	}
-
-	void ScriptSceneViewHandler::internal_UpdateSelection(ScriptSceneViewHandler* thisPtr)
-	{
-		thisPtr->mHandler->updateSelection();
-	}
-
-	void ScriptSceneViewHandler::internal_TrySelectHandle(ScriptSceneViewHandler* thisPtr, Vector2I* inputPos)
-	{
-		thisPtr->mHandler->trySelectHandle(*inputPos);
-	}
-
-	bool ScriptSceneViewHandler::internal_IsHandleActive(ScriptSceneViewHandler* thisPtr)
-	{
-		return thisPtr->mHandler->isHandleActive();
-	}
-
-	void ScriptSceneViewHandler::internal_ClearHandleSelection(ScriptSceneViewHandler* thisPtr)
-	{
-		thisPtr->mHandler->clearHandleSelection();
-	}
-
-	void ScriptSceneViewHandler::internal_PickObject(ScriptSceneViewHandler* thisPtr, Vector2I* inputPos, bool additive)
-	{
-		thisPtr->mHandler->pickObject(*inputPos, additive);
-	}
-}