Manipulating the control points of an arbitrary collection of curves requires an application that can first find the closest curve to the current cursor position, then find the closest control point on that curve in order to move and place it while in 'place' mode. This is achieved using global variables to keep track of the indexes of the closestCrv and closestPt. Here we show how to build a simple application for editing open NURBS curves.
Initialization and Live Rendering
The initial curve geometries are stored in a global variable called crvs. By listening for changes to the crvs global variable using the dynamic update toggle, we can create mesh pipes from these curves that render their shape during and after editing. We also listen for changes to our cursor position and draw a small sphere in order to easily select control points near our cursor.
Picking Nearest Curves and Control Points
To find the index of the closest curve to edit, we first use the Closest Point component to find the closest point to our cursor on each of the curves, then sort the distance to these points using a Sort component. By simultaneously sorting the list of curves themselves, and an ordered list of integers representing the indexes of the curves, we can use a List Item component to find the closest curve geometry as well as its index in the crvs list. This index is stored in the closestCrv global variable to be used during the place mode.
We then find the closest control point on our closest curve using the Closest Point component. The point geometry is rendered using a mesh sphere for visual feedback on what will be edited during place mode. We store the index of the closest control point in the closestPt global variable.
Placing Control Points and Updating the Curve Geometry
To edit the control point of the curve we first select the curve from the list of crvs using the closestCrv variable. We then get the curve control points with the Control Points component and replace the point at the index of closestPt with the live position of our cursor. A new NURBS curve is interpolated through these points. We then replace the curve at index closestCrv with our new curve geometry, and update the value of crvs.