SceneSelection.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /// Settings that control how are pickable gizmos drawn.
  34. /// </summary>
  35. internal GizmoDrawSettings GizmoDrawSettings
  36. {
  37. get
  38. {
  39. GizmoDrawSettings value;
  40. Internal_GetGizmoDrawSettings(mCachedPtr, out value);
  41. return value;
  42. }
  43. set
  44. {
  45. Internal_SetGizmoDrawSettings(mCachedPtr, ref value);
  46. }
  47. }
  48. /// <summary>
  49. /// Creates a new scene selection manager.
  50. /// </summary>
  51. /// <param name="sceneCamera">Camera into which to render the selection overlay, and perform picking from.</param>
  52. /// <param name="drawSettings">Settings that control how are pickable gizmos drawn.</param>
  53. internal SceneSelection(Camera sceneCamera, GizmoDrawSettings gizmoDrawSettings)
  54. {
  55. Internal_Create(this, sceneCamera.GetCachedPtr(), ref gizmoDrawSettings);
  56. }
  57. /// <summary>
  58. /// Queues selection overlay drawing for this frame.
  59. /// </summary>
  60. internal void Draw()
  61. {
  62. Internal_Draw(mCachedPtr);
  63. }
  64. /// <summary>
  65. /// Attempts to select a scene object under the pointer position.
  66. /// </summary>
  67. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  68. /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
  69. /// <param name="ignoreSceneObjects">Optional set of objects to ignore during scene picking.</param>
  70. internal void PickObject(Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreSceneObjects = null)
  71. {
  72. Internal_PickObject(mCachedPtr, ref pointerPos, controlHeld, ignoreSceneObjects);
  73. }
  74. /// <summary>
  75. /// Attempts to select a scene object in the specified area.
  76. /// </summary>
  77. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  78. /// <param name="area">Size of the in which objects will be selected, in pixels and relative to
  79. /// <paramref name="pointerPos"/>.</param>
  80. /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
  81. /// <param name="ignoreSceneObjects">Optional set of objects to ignore during scene picking.</param>
  82. internal void PickObjects(Vector2I pointerPos, Vector2I area, bool controlHeld,
  83. SceneObject[] ignoreSceneObjects = null)
  84. {
  85. Internal_PickObjects(mCachedPtr, ref pointerPos, ref area, controlHeld, ignoreSceneObjects);
  86. }
  87. /// <summary>
  88. /// Attempts to find a scene object under the provided position, while also returning the world position and normal
  89. /// of the point that was hit.
  90. /// </summary>
  91. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  92. /// <param name="data">Position and normal on the object surface at the point that was hit.</param>
  93. /// <param name="ignoreSceneObjects">Optional set of objects to ignore during scene picking.</param>
  94. /// <returns>The object the pointer is snapping to.</returns>
  95. internal SceneObject Snap(Vector2I pointerPos, out SnapData data, SceneObject[] ignoreSceneObjects = null)
  96. {
  97. return Internal_Snap(mCachedPtr, ref pointerPos, out data, ignoreSceneObjects);
  98. }
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. private static extern void Internal_Create(SceneSelection managedInstance, IntPtr camera, ref GizmoDrawSettings gizmoDrawSettings);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. private static extern void Internal_Draw(IntPtr thisPtr);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. private static extern void Internal_PickObject(IntPtr thisPtr, ref Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreRenderables);
  105. [MethodImpl(MethodImplOptions.InternalCall)]
  106. private static extern void Internal_PickObjects(IntPtr thisPtr, ref Vector2I pointerPos, ref Vector2I extents, bool controlHeld, SceneObject[] ignoreRenderables);
  107. [MethodImpl(MethodImplOptions.InternalCall)]
  108. private static extern SceneObject Internal_Snap(IntPtr thisPtr, ref Vector2I pointerPos, out SnapData data, SceneObject[] ignoreRenderables);
  109. [MethodImpl(MethodImplOptions.InternalCall)]
  110. private static extern void Internal_SetGizmoDrawSettings(IntPtr thisPtr, ref GizmoDrawSettings settings);
  111. [MethodImpl(MethodImplOptions.InternalCall)]
  112. private static extern void Internal_GetGizmoDrawSettings(IntPtr thisPtr, out GizmoDrawSettings settings);
  113. }
  114. /** @} */
  115. }