//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using bs;
namespace bs.Editor
{
/** @addtogroup Scene-Editor
* @{
*/
///
/// Contains world position and normal of the surface of the object in a snap operation.
///
[StructLayout(LayoutKind.Sequential)]
struct SnapData
{
///
/// The normal to the object surface at the snapping point.
///
public Vector3 normal;
///
/// The world position on the surface of the object.
///
public Vector3 position;
}
///
/// Handles rendering of the selection overlay and picking of objects in the target camera's view.
///
internal sealed class SceneSelection : ScriptObject
{
///
/// Creates a new scene selection manager.
///
/// Camera into which to render the selection overlay, and perform picking from.
internal SceneSelection(Camera sceneCamera)
{
Internal_Create(this, sceneCamera.GetCachedPtr());
}
///
/// Queues selection overlay drawing for this frame.
///
internal void Draw()
{
Internal_Draw(mCachedPtr);
}
///
/// Attempts to select a scene object under the pointer position.
///
/// Position of the pointer relative to the scene camera viewport.
/// Should this selection add to the existing selection, or replace it.
/// Optional set of objects to ignore during scene picking.
internal void PickObject(Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreSceneObjects = null)
{
Internal_PickObject(mCachedPtr, ref pointerPos, controlHeld, ignoreSceneObjects);
}
///
/// Attempts to select a scene object in the specified area.
///
/// Position of the pointer relative to the scene camera viewport.
/// Size of the in which objects will be selected, in pixels and relative to
/// .
/// Should this selection add to the existing selection, or replace it.
/// Optional set of objects to ignore during scene picking.
internal void PickObjects(Vector2I pointerPos, Vector2I area, bool controlHeld,
SceneObject[] ignoreSceneObjects = null)
{
Internal_PickObjects(mCachedPtr, ref pointerPos, ref area, controlHeld, ignoreSceneObjects);
}
///
/// Attempts to find a scene object under the provided position, while also returning the world position and normal
/// of the point that was hit.
///
/// Position of the pointer relative to the scene camera viewport.
/// Position and normal on the object surface at the point that was hit.
/// Optional set of objects to ignore during scene picking.
/// The object the pointer is snapping to.
internal SceneObject Snap(Vector2I pointerPos, out SnapData data, SceneObject[] ignoreSceneObjects = null)
{
return Internal_Snap(mCachedPtr, ref pointerPos, out data, ignoreSceneObjects);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_Create(SceneSelection managedInstance, IntPtr camera);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_Draw(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_PickObject(IntPtr thisPtr, ref Vector2I pointerPos, bool controlHeld, SceneObject[] ignoreRenderables);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_PickObjects(IntPtr thisPtr, ref Vector2I pointerPos, ref Vector2I extents, bool controlHeld, SceneObject[] ignoreRenderables);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern SceneObject Internal_Snap(IntPtr thisPtr, ref Vector2I pointerPos, out SnapData data, SceneObject[] ignoreRenderables);
}
/** @} */
}