SceneSelection.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 System.Runtime.InteropServices;
  6. using BansheeEngine;
  7. namespace BansheeEditor
  8. {
  9. /** @addtogroup Scene-Editor
  10. * @{
  11. */
  12. /// <summary>
  13. /// Contains information regarding object snapping.
  14. /// </summary>
  15. [StructLayout(LayoutKind.Sequential)]
  16. struct SnapData
  17. {
  18. /// <summary>
  19. /// The normal to the object surface at the snapping point.
  20. /// </summary>
  21. public Vector3 normal;
  22. /// <summary>
  23. /// The 3D position on the surface of the object
  24. /// </summary>
  25. public Vector3 position;
  26. }
  27. /// <summary>
  28. /// Handles rendering of the selection overlay and picking of objects in the target camera's view.
  29. /// </summary>
  30. internal sealed class SceneSelection : ScriptObject
  31. {
  32. /// <summary>
  33. /// Creates a new scene selection manager.
  34. /// </summary>
  35. /// <param name="sceneCamera">Camera into which to render the selection overlay, and perform picking from.</param>
  36. internal SceneSelection(Camera sceneCamera)
  37. {
  38. Internal_Create(this, sceneCamera.Native.GetCachedPtr());
  39. }
  40. /// <summary>
  41. /// Queues selection overlay drawing for this frame.
  42. /// </summary>
  43. internal void Draw()
  44. {
  45. Internal_Draw(mCachedPtr);
  46. }
  47. /// <summary>
  48. /// Attempts to select a scene object under the pointer position.
  49. /// </summary>
  50. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  51. /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
  52. /// <param name="ignoreSceneObjects">An array of renderables that should not be rendered during scene picking.</param>
  53. internal void PickObject(Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreSceneObjects = null)
  54. {
  55. Internal_PickObject(mCachedPtr, ref pointerPos, controlHeld, ignoreSceneObjects);
  56. }
  57. /// <summary>
  58. /// Attempts to select a scene object in the specified area.
  59. /// </summary>
  60. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  61. /// <param name="area">The screen area in which objects will be selected.</param>
  62. /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
  63. /// <param name="ignoreSceneObjects">An array of renderables that should not be rendered during scene picking.</param>
  64. internal void PickObjects(Vector2I pointerPos, Vector2I area, bool controlHeld, SceneObject[] ignoreSceneObjects = null)
  65. {
  66. Internal_PickObjects(mCachedPtr, ref pointerPos, ref area, controlHeld, ignoreSceneObjects);
  67. }
  68. /// <summary>
  69. /// Returns the 3D position of an object under the cursor, along with the surface normal in that point.
  70. /// </summary>
  71. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  72. /// <param name="data">A struct containing the position on the object surface and the normal in that point.</param>
  73. /// <param name="ignoreSceneObjects">An array of renderables that should not be rendered during scene picking.</param>
  74. /// <returns>The object the pointer is snapping to.</returns>
  75. internal SceneObject Snap(Vector2I pointerPos, out SnapData data, SceneObject[] ignoreSceneObjects = null)
  76. {
  77. return Internal_Snap(mCachedPtr, ref pointerPos, out data, ignoreSceneObjects);
  78. }
  79. [MethodImpl(MethodImplOptions.InternalCall)]
  80. private static extern void Internal_Create(SceneSelection managedInstance, IntPtr camera);
  81. [MethodImpl(MethodImplOptions.InternalCall)]
  82. private static extern void Internal_Draw(IntPtr thisPtr);
  83. [MethodImpl(MethodImplOptions.InternalCall)]
  84. private static extern void Internal_PickObject(IntPtr thisPtr, ref Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreRenderables);
  85. [MethodImpl(MethodImplOptions.InternalCall)]
  86. private static extern void Internal_PickObjects(IntPtr thisPtr, ref Vector2I pointerPos, ref Vector2I extents, bool controlHeld, SceneObject[] ignoreRenderables);
  87. [MethodImpl(MethodImplOptions.InternalCall)]
  88. private static extern SceneObject Internal_Snap(IntPtr thisPtr, ref Vector2I pointerPos, out SnapData data, SceneObject[] ignoreRenderables);
  89. }
  90. /** @} */
  91. }