SceneSelection.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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="ignoreSceneObjects">An array of renderables that should not be rendered during scene picking.</param>
  51. internal void PickObject(Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreSceneObjects = null)
  52. {
  53. Internal_PickObject(mCachedPtr, ref pointerPos, controlHeld, ignoreSceneObjects);
  54. }
  55. /// <summary>
  56. /// Attempts to select a scene object in the specified area.
  57. /// </summary>
  58. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  59. /// <param name="area">The screen area in which objects will be selected.</param>
  60. /// <param name="controlHeld">Should this selection add to the existing selection, or replace it.</param>
  61. /// <param name="ignoreSceneObjects">An array of renderables that should not be rendered during scene picking.</param>
  62. internal void PickObjects(Vector2I pointerPos, Vector2I area, bool controlHeld, SceneObject[] ignoreSceneObjects = null)
  63. {
  64. Internal_PickObjects(mCachedPtr, ref pointerPos, ref area, controlHeld, ignoreSceneObjects);
  65. }
  66. /// <summary>
  67. /// Returns the 3D position of an object under the cursor, along with the surface normal in that point.
  68. /// </summary>
  69. /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
  70. /// <param name="ignoreSceneObjects">An array of renderables that should not be rendered during scene picking.</param>
  71. /// <returns>The position on the object surface and the normal in that point.</returns>
  72. internal SnapData Snap(Vector2I pointerPos, SceneObject[] ignoreSceneObjects = null)
  73. {
  74. SnapData data;
  75. Internal_Snap(mCachedPtr, ref pointerPos, out data, ignoreSceneObjects);
  76. return data;
  77. }
  78. [MethodImpl(MethodImplOptions.InternalCall)]
  79. private static extern void Internal_Create(SceneSelection managedInstance, IntPtr camera);
  80. [MethodImpl(MethodImplOptions.InternalCall)]
  81. private static extern void Internal_Draw(IntPtr thisPtr);
  82. [MethodImpl(MethodImplOptions.InternalCall)]
  83. private static extern void Internal_PickObject(IntPtr thisPtr, ref Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreRenderables);
  84. [MethodImpl(MethodImplOptions.InternalCall)]
  85. private static extern void Internal_PickObjects(IntPtr thisPtr, ref Vector2I pointerPos, ref Vector2I extents, bool controlHeld, SceneObject[] ignoreRenderables);
  86. [MethodImpl(MethodImplOptions.InternalCall)]
  87. private static extern void Internal_Snap(IntPtr thisPtr, ref Vector2I pointerPos, out SnapData data, SceneObject[] ignoreRenderables);
  88. }
  89. /** @} */
  90. }