Click or drag to resize
AB4D logo

DXEventManager3D Class

DXEventManager3D class is a enables subscribing to mouse and touch events on 3D objects rendered with DXEngine. The class is using Hit testing provided by DXEngine and not WPF's hit testing that is used by the EventManager3D provided by the Ab3d.PowerToys library.
Inheritance Hierarchy
SystemObject
  Ab3d.DirectX.UtilitiesDXEventManager3D

Namespace: Ab3d.DirectX.Utilities
Assembly: Ab3d.DXEngine.Wpf (in Ab3d.DXEngine.Wpf.dll) Version: 7.0.8865.1045
Syntax
C#
public class DXEventManager3D

The DXEventManager3D type exposes the following members.

Constructors
 NameDescription
Public methodDXEventManager3D Constructor
Top
Properties
 NameDescription
Public propertyCustomEventsSourceElement Gets or sets a FrameworkElement that can be used instead of TargetViewport3D to get the mouse events (MouseMove, MouseEnter, MouseLeave). If null (default) than TargetViewport3D is used as event source.
Public propertyDragMouseDistance Gets or sets the distance mouse must make when the move is considered as mouse drag. The default value is 5.
Public propertyDXView Parent DXView that is used to do the hit testing.
Public propertyIsEnabled Gets or sets a boolean value that specifies if the EventManager3D is enabled.
Public propertyIsManipulationEnabled Gets or sets a boolean that specifies if Manipulation (touch based) events are enabled by this EventManager3D (this works only when .Net 4 or higher version of the library is used). Default valus is false.
Public propertyUsePreviewEvents Gets or sets a boolean that specifies if EventManager3D subscribed to Preview moouse and touch events instead of standard events - for example PreviewMouseUp event instead of MouseUp event. Default value is false;
Top
Methods
 NameDescription
Public methodRegisterEventSource3D Registers the eventSource to the EventManager3D
Public methodRegisterExcludedSceneNode Registers a SceneNode that will be excluded from hit testing - the ray from the mouse will "travel" through that SceneNode and will hit the objects behind.
Public methodRegisterExcludedVisual3D Registers a visual3D that will be excluded from hit testing - the ray from the mouse will "travel" through that Visual and will hit the objects behind.
Public methodRemoveEventSource3D Removes the eventSource from the EventManager3D
Public methodRemoveExcludedSceneNode Remove the SceneNode from the list of excluded scene nodes. To remove all excluded SceneNode it is also possible to call ResetEventSources3D method.
Public methodRemoveExcludedVisual3D Removed the visual3D from the excluded visuals list. To remove all excluded visuals it is also possible to call ResetEventSources3D method.
Public methodResetEventSources3D Clears all the registered EventSource3D objects. This also removes all registered Visuals that are not hit visible.
Public methodUpdateHitObjects UpdateHitObjects method can be called to manually update the 3D objects that are behind the current mouse position. This is useful when the camera is changed without moving the mouse. In this case the 3D objects behind the mouse position can change. If this happens the MouseEnter, MouseLeave and other event handlers will be called from the UpdateHitObjects method.
Top
Remarks

DXEventManager3D class is a enables subscribing to mouse and touch events on 3D objects rendered with DXEngine. The class is using Hit testing provided by DXEngine and not WPF's hit testing that is used by the EventManager3D provided by the Ab3d.PowerToys library.

The following mouse events are supported:
MouseEnter
MouseLeave,
MouseMove,
MouseDown,
MouseUp,
MouseClick,
MouseDoubleClick,
MouseWheel,
BeginMouseDrag,
MouseDrag,
EndMouseDrag.
TouchEnter,
TouchDown,
TouchMove,
TouchUp,
TouchLeave.

It is also possible to exclude some Visual3D objects from hit testing with RegisterExcludedVisual3D(Visual3D) method. This means that when the ray from the mouse will hit the excluded Visual3D, it will not produce a hit test but will continue with checking if there are any objects behind. To remove the Visual3D form exclusion list, call the RemoveExcludedVisual3D(Visual3D) method (exclusion list is also cleared when called ResetEventSources3D method).

This can be very useful for example when we are drawing an object or 3D line at the position of mouse hit. Without an option to exclude the drawn object or 3d line, we would get many MouseEnter and MouseLeave events because mouse will sometimes hit the back object and sometimes the drawn object or 3D line.

Important:
It is highly recommended not to have more than one EventManager3D object per Viewport3D. Having multiple EventManager3D object can greatly reduce the performance because each time the Viewport3D camera is changed, each EventManager3D must perform a full 3D hit testing from the current mouse position. This operation is very CPU intensive and can affect performance when there are many 3D objects in the scene. When multiple EventManager3D object are defined, then the 3D hit testing is performed multiple times. Therefore it is recommended to have only one EventManager3D object per Viewport3D.

It is also recommended to remove registered event sources after they are not used any more. This can be done with RemoveEventSource3D(BaseEventSource3D) method.

See Also