Viewport Functionality
 
 
 

Many plug-ins (e.g. modifiers and objects) have visual representations in a viewport and must implement a number of functions for displaying themselves in the viewport and interacting with the user.

Displaying Plug-ins in the Viewport

A plug-in displays itself in the viewport by overriding the method BaseObject::Display(). In the case of a modifier plug-in, the modifier will draw its gizmo in this method.

Hit Tests

Plug-ins with a viewport representation must implement the BaseObject::HitTest() method to indicate if a mouse point passed intersects the entity. Hit testing is used extensively by Max. For example, when the user wants to select a node and clicks the mouse in a viewport, the system calls the HitTest() method of nodes within range of the point picked.

For modifiers the BaseObject::HitTest() method checks to see if the pointer location intersects the gizmo or center mark of the modifier. SimpleMod provides a default implementation (SimpleMod::HitTest())

Bounding Boxes

An object or modifier plug-in is expected to implement two methods that return bounding boxes. Bounding boxes are used primarily for fast rejection during hit testing and for computing the extent of an object or modifier gizmos.

The BaseObject::GetLocalBoundBox() method returns the object space bounding box. The system expects that requesting the object space bounding box will be fast, so in most cases an object should cache its bounding box. The object should not, for instance, traverse a long list of vertices calculating minimums and maximums. In the Ripple sample, the cached mesh is used for these bounding box computations.

The BaseObject::GetWorldBoundBox() method returns the world space bounding box. The bounding box returned by this method does not need to be precise. It should, however, be calculated rapidly. The object can handle this by transforming the 8 points of its local bounding box into world space and take the minimums and maximums of the result. Although this isn't necessarily the tightest bounding box of the object's points in world space, it is close enough. This box is mainly used for trivial rejection during hit testing and rendering.

Node Snapping

Plug-ins that can be selected in the viewport by a mouse, and that wish to support node snapping must implement the BaseObject::Snap() method.