Mouse activity is supported through two feedback functions. The Patch Editor.jsl sample script uses these functions to support the dragging and dropping of points. Part of that script, the call-back function for mouse activity, is explained below. To run the script, open PatchEditor.jsl in the Scene3D folder inside the Sample Scripts folder.
X and Y are the coordinates of the mouse.
M shows the state of the mouse and button. M=0 says that the mouse button is up. M=1 says that the button was just pressed. M=2 says that the button is down and the mouse is moving. M=3 says that the button was just released.
K is related to the keys Shift, Alt, and control. K=1 for the Shift key, K=2 for the Control (command) key, and K=3 for the Alt (Option) key.
The 3-D function is called similarly. The arguments are X, Y, M, K, hitlist, where hitlist is a list of matrices
znear, zfar is the Z distance from the camera of the near and far edge of the object. The matrices are sorted from near to far by the midpoint of znear, zfar. The ids in the list are the pushname, loadname, and popname values you just put in the display list.
This SceneBox callback gets the 2-D mouse coordinates, and then uses pick to determine the “named” object under the mouse. For example, hitlist is a 5x5 pixel pick box around x,y; up to 1000 items returned, but just the leaf names. The format of the return is determined by the last argument (1 returns a simple array, 0 returns a sorted (by depth) list of arrays).
... hitlist[1..n] // are names that you put in the display list
Contrast this with a call back Track3d function, where the pick rectangle is always 1x1 and picking only happens when the mouse moves. This is almost always what you want, but points are difficult to pick because the 1x1 pick area is the same small size as the point. This function lets you pick without a mouse move.
The Track3d function always provides a depth-sorted list of arrays; each array can describe multiple names in a hierarchy (pushname and popname construct a hierarchy of objects). The sorting can be very slow when thousands of objects are selected. The final argument (1, above) controls whether the pick function replaces the sorted list of arrays with a simple array. The simple array contains only the “leaf” names, not higher level names.