Share

Hit Testing

Hit testing is the process of determining if a given point (e.g. the location of a mouse) intersects an item (for example a node, a modifier gizmo/center, or a controller gizmo). A plug-in developer's responsibility regarding hit testing depends upon the type of plug-in and how much functionality is supplied by the base class the plug-in is derived from. For example, plug-ins that are derived from SimpleObject, SimpleMod or StdControl are not required to implement methods for hit testing as it is all handled internally by the base class. Other plug-ins that don't derive from these classes (for example the Boolean object or the Mapping modifier) must perform their own hit testing, by providing an implementation of one of the following methods:

  • BaseObject::HitTest() - For hit-testing geometric objects.
  • Modifier::HitTest() - A modifier uses a hit test function with a different signature than the inherited BaseObject::HitTest() method that has an additional ModContext parameter.
  • Control::HitTest() - For hit-testing controllers.

There are two types of hit testing:

  • Node level - This is for determining if a given node in the scene has been hit.
  • Sub-object level - This can be for objects, modifier or controllers. This is for determining if a sub-component of an item has been hit. Object space modifiers can have a visual representation in the scene that the user can manipulate. For example, many of the 3ds Max object space modifiers have a gizmo and center mark. These are the modifier's sub-object levels. In the case of an edit modifier this can be the sub-object parts of the object itself (like vertices, edges, or face for the Edit Mesh modifier). An object may hit test sub-object parts as well. For example, a compound object like the boolean object may hit test the operands of the boolean operation. The loft model compound object may hit test parts of the loft model such as the path or shapes.

There is also a distinction to be made between 'simple' hit testing and 'smart' hit testing. Simple hit testing involves finding any hit on an item. As soon as a single hit is found the process of searching for hits can stop. Smart hit testing involves finding the part of an item that was the close to the pick point. This involves hit testing everything and then searching through all the hits to find the closest one.

Was this information helpful?