Vex and VOPs – A Twist Deformer (Part 2)

So twisting some points around the origin was easy, but not useful as a generalized tool since you really need to place the twist anywhere it’s needed in world space.

The trick to this is to create and store a transformation matrix based on the origin of your control object, then move your deforming geometry to the origin via the inverse of that matrix. Then, after performing the deformation, apply the stored transformation matrix to move your deformed geometry back to where it was in world space.

Getting the vex wrangle right took me a fair amount of teeth pulling because I’m so new, and frankly it feels like it could be reduced to something a lot simpler. Email me if you see a better or cleaner way! Here’s what I ended up with:

// Create vectors to fill matrix using the second node input's transform
vector translate = set(`chs(opinputpath(".", 1)+"/tx")`,`chs(opinputpath(".", 1)+"/ty")`,`chs(opinputpath(".", 1)+"/tz")`);
vector rotate = set(`chs(opinputpath(".", 1)+"/rx")`,`chs(opinputpath(".", 1)+"/ry")`,`chs(opinputpath(".", 1)+"/rz")`);
vector scale = {1,1,1}; // I'm not worrying about scale...
// Build the transform matrix of the control object
matrix xform = invert(maketransform(0, 0, translate, rotate, scale));
// Apply the matrix to the current points to move them to the origin centered on control object
@P *= xform;
// Store the matrix to return to original location after deformation
4@xform_matrix = xform;

Yeah so there you go, that takes up a pointwrangle before the deform VOP and then a little wrangle after it returns the points to world space:

@P *= invert(4@xform_matrix);

Here’s a houdini take on that original twist scene using this setup: