This tutorial shows how highlight parts as a response to a mouse press event.
A highlighted part is shown with a white halo. This is useful for indicating for instance selection. Highlighting can be toggled on any number and any type of part independently.
The highlighting mechanism applies to all types of parts:
The mouse pressed event in the viewer needs to be modified to handle picking. In this tutorial we will trigger a picking event for all mouse clicks.
The tutorial code is Qt based.
In the mouse button pressed event, find the intersect ray for the current mouse coordinates.
Emit a pick signal with the computed ray. This signal must be connected to a slot in the main application.
Create a simple geometry model with 4 boxes.
The model is ready to use and can be added to the view. Exactly where the view exists depends on the platform and solution. These examples uses Qt and the view is set up in a cee::qt::ViewerWidget.
The viewer need to get the pick event from the viewer. This can typically be in the mouse release event. The viewer produces a Ray based on the pick coordinates using Camera::rayFromWindowCoordinates() and passes this ray to the handling function.
Get the current geometry model. Since this tutorials don't keep local pointer to all the possible models it can create, get the model from the view.
Create a hit item from the ray object received from the viewer.
rayIntersect() returns true if any part were hit byt the ray. Check if any parts where hit. If not, leave the highlighting as it is and return.
If a part was hit, deselect all other parts and highlight the hit part.