SceneSelection.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. using BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. /** @addtogroup Scene-Editor
  9. * @{
  10. */
  11. /// <summary>
  12. /// Contains information regarding object snapping.
  13. /// </summary>
  14. struct SnapData
  15. {
  16. /// <summary>
  17. /// The normal to the object surface at the snapping point.
  18. /// </summary>
  19. public Vector3 normal;
  20. /// <summary>
  21. /// The 3D position on the surface of the object
  22. /// </summary>
  23. public Vector3 position;
  24. }
  25. /// <summary>
  26. /// Handles rendering of the selection overlay and picking of objects in the target camera's view.
  27. /// </summary>
  28. internal sealed class SceneSelection : ScriptObject
  29. {
  30. /// <summary>
  31. /// Creates a new scene selection manager.
  32. /// </summary>
  33. /// <param name="sceneCamera">Camera into which to render the selection overlay, and perform picking from.</param>
  34. internal SceneSelection(Camera sceneCamera)
  35. {
  36. Internal_Create(this, sceneCamera.Native.GetCachedPtr());
  37. }
  38. /// <summary>
  39. /// Queues selection overlay drawing for this frame.
  40. /// </summary>
  41. internal void Draw()
  42. {
  43. Internal_Draw(mCachedPtr);
  44. }
  45. /// <summary>
  46. /// Attempts to select a scene object under the pointer position.
  47. /// </summary>
  48. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  49. /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
  50. /// <param name="ignoreRenderables">An array of renderables that should not be rendered during scene picking.</param>
  51. internal void PickObject(Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreRenderables = null)
  52. {
  53. Internal_PickObject(mCachedPtr, ref pointerPos, controlHeld, ignoreRenderables);
  54. }
  55. /// <summary>
  56. /// Returns the 3D position of an object under the cursor, along with the surface normal in that point.
  57. /// </summary>
  58. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  59. /// <param name="ignoreRenderables">An array of renderables that should not be rendered during scene picking.</param>
  60. /// <returns>The position on the object surface and the normal in that point.</returns>
  61. internal SnapData Snap(Vector2I pointerPos, SceneObject[] ignoreRenderables = null)
  62. {
  63. SnapData data;
  64. if (ignoreRenderables == null)
  65. ignoreRenderables = new SceneObject[0];
  66. Internal_Snap(mCachedPtr, ref pointerPos, out data, ignoreRenderables);
  67. return data;
  68. }
  69. [MethodImpl(MethodImplOptions.InternalCall)]
  70. private static extern void Internal_Create(SceneSelection managedInstance, IntPtr camera);
  71. [MethodImpl(MethodImplOptions.InternalCall)]
  72. private static extern void Internal_Draw(IntPtr thisPtr);
  73. [MethodImpl(MethodImplOptions.InternalCall)]
  74. private static extern void Internal_PickObject(IntPtr thisPtr, ref Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreRenderables);
  75. [MethodImpl(MethodImplOptions.InternalCall)]
  76. private static extern void Internal_Snap(IntPtr thisPtr, ref Vector2I pointerPos, out SnapData data, SceneObject[] ignoreRenderables);
  77. }
  78. /** @} */
  79. }