SceneSelection.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 bs;
  7. namespace bs.Editor
  8. {
  9. /** @addtogroup Scene-Editor
  10. * @{
  11. */
  12. /// <summary>
  13. /// Contains world position and normal of the surface of the object in a snap operation.
  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 world 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.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">Optional set of objects to ignore 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">Size of the in which objects will be selected, in pixels and relative to
  62. /// <paramref name="pointerPos"/>.</param>
  63. /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
  64. /// <param name="ignoreSceneObjects">Optional set of objects to ignore during scene picking.</param>
  65. internal void PickObjects(Vector2I pointerPos, Vector2I area, bool controlHeld,
  66. SceneObject[] ignoreSceneObjects = null)
  67. {
  68. Internal_PickObjects(mCachedPtr, ref pointerPos, ref area, controlHeld, ignoreSceneObjects);
  69. }
  70. /// <summary>
  71. /// Attempts to find a scene object under the provided position, while also returning the world position and normal
  72. /// of the point that was hit.
  73. /// </summary>
  74. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  75. /// <param name="data">Position and normal on the object surface at the point that was hit.</param>
  76. /// <param name="ignoreSceneObjects">Optional set of objects to ignore during scene picking.</param>
  77. /// <returns>The object the pointer is snapping to.</returns>
  78. internal SceneObject Snap(Vector2I pointerPos, out SnapData data, SceneObject[] ignoreSceneObjects = null)
  79. {
  80. return Internal_Snap(mCachedPtr, ref pointerPos, out data, ignoreSceneObjects);
  81. }
  82. [MethodImpl(MethodImplOptions.InternalCall)]
  83. private static extern void Internal_Create(SceneSelection managedInstance, IntPtr camera);
  84. [MethodImpl(MethodImplOptions.InternalCall)]
  85. private static extern void Internal_Draw(IntPtr thisPtr);
  86. [MethodImpl(MethodImplOptions.InternalCall)]
  87. private static extern void Internal_PickObject(IntPtr thisPtr, ref Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreRenderables);
  88. [MethodImpl(MethodImplOptions.InternalCall)]
  89. private static extern void Internal_PickObjects(IntPtr thisPtr, ref Vector2I pointerPos, ref Vector2I extents, bool controlHeld, SceneObject[] ignoreRenderables);
  90. [MethodImpl(MethodImplOptions.InternalCall)]
  91. private static extern SceneObject Internal_Snap(IntPtr thisPtr, ref Vector2I pointerPos, out SnapData data, SceneObject[] ignoreRenderables);
  92. }
  93. /** @} */
  94. }