## Curve Twist Deformer

Since my last experiment involved curves, I decided to attempt another curve node. This time a twist deformer, using the curve as central axis for the twisting mesh. I was going to try and build a matrix for each point along the closest point on the curve, but I came to realize this was over-complicating things for what I was trying to accomplish. Instead I enlisted the help of MQuaternion and used it to rotate around the tangent of the closest point. I decided that I’d add a ramp to control the amount of twist based off of distance from the curve, and once I saw how that reacted I decided to add a couple more based on the parameter. The end result is that you can control which areas of the curve cause the most deformation, and even the width of the deformation. Here’s some sample videos and part of the compute statement:

double lastParam = curveFn.findParamFromLength(curveFn.length()); while (transMeshIt.isDone() == false) { // get closets point on curve // int index = transMeshIt.index(); double closestParamU; MPoint currentPoint = preDeformPoints[index]*inMeshMatrix; MPoint closestPointOnCurve = curveFn.closestPoint(currentPoint, &closestParamU, 0.0, MSpace::kObject); MVector normal(currentPoint-closestPointOnCurve); // measure input from ramps // float widthStrength; float lengthStrength; float distanceStrength; widthRamp.getValueAtPosition( closestParamU/lastParam, widthStrength); lengthRamp.getValueAtPosition( closestParamU/lastParam, lengthStrength); distanceRamp.getValueAtPosition( normal.length()/(distance*widthStrength), distanceStrength); // get vector to rotate around // MVector curve_deriv = curveFn.tangent(closestParamU,MSpace::kObject); MQuaternion rotate(mult*lengthStrength*distanceStrength,curve_deriv); normal*=rotate; // apply rotation and put point back to object space // MPoint newPoint= closestPointOnCurve+normal; newPoint *= inMeshMatrixInvert; postDeformPoints.set(newPoint,index); transMeshIt.next(); }