The ViewerInteractionAPI provides methods to control the user's interaction with a viewer.
Quick Start
The following example enables snapping to topological entities and then reacts to
NodeClickedEvents:
constcontext = webvis.getContext();constviewer = context.getViewer();// Render topological entities// This is required to enable interaction with and snapping// to topological entitiesviewer.forceRenderMode(webvis.RenderMode.FacesTopology);viewer.setInteractionLevel(webvis.ViewerInteractionLevel.TOPOLOGY);viewer.enableSnapping(true);// Disable the default node selection on click.// This is not required, but recommended to improve the user experiencecontext.setInteractionMode(webvis.InteractionMode.NONE);constlistenerId = context.registerListener([webvis.EventType.NODE_CLICKED], async (event) => {constpointerInfo = event.pointerInfo;console.log("Click position in 3D: ", pointerInfo.position);consttopologyHandle = awaitpointerInfo.requestTopologyHandle();console.log("Topological entity: ", topologyHandle);}, 0, true); // Set option 'observeSubTree' to true to observe all entities//...// Don't forget to unregister the listener when you are donecontext.unregisterListener(listenerId);
By default, the interaction level is set to NODE, which means that the user will interact with viewer at the
node level. In other words, on a desktop device using a mouse, the viewer will respond to clicks with the respective
node under the mouse cursor.
Changing the interaction level to TOPOLOGY will make the viewer respond to clicks with the respective topology
under the mouse cursor:
The ViewerInteractionAPI also provides the option to enable or disable snapping.
Snapping is a feature that allows the user to snap to the nearest edge or point.
ViewerInteractionAPI
Overview
The
ViewerInteractionAPIprovides methods to control the user's interaction with a viewer.Quick Start
The following example enables snapping to topological entities and then reacts to NodeClickedEvents:
Interaction Levels
Get the current interaction level of a viewer:
By default, the interaction level is set to
NODE, which means that the user will interact with viewer at the node level. In other words, on a desktop device using a mouse, the viewer will respond to clicks with the respective node under the mouse cursor.Changing the interaction level to
TOPOLOGYwill make the viewer respond to clicks with the respective topology under the mouse cursor:Snapping
The
ViewerInteractionAPIalso provides the option to enable or disable snapping. Snapping is a feature that allows the user to snap to the nearest edge or point.Remarks
Interaction and snapping only work on entities that are being rendered in the viewer. For example, if the ViewerInteractionLevel is set to ViewerInteractionLevel.TOPOLOGY, but the viewer's ViewerSettingStrings.RENDER_MODE is set to RenderMode.Faces only, then snapping to edges will not work. To enable snapping to all topological entities, the render mode should be set to RenderMode.FacesTopology instead.
Events
The
ViewerInteractionAPIemits the following events: