Kardonn Posted April 21, 2016 Share Posted April 21, 2016 Looking for some help on setting up a Wrangle that would curl a curve by rotating the last point in the curve around a point centered on the previous point, and doing that all the way down the chain so you get nice curls happening. Been trying to work this out but I'm missing some knowledge here when it comes to looping through points per primitive, and also I'm not sure how to rotate a point with the rotation origin starting on another point. Basic idea is that given an @N and an @up vector on the curve, it will rotate each point about the previous point's @P using cross(@N, @up) as a rotation axis, by some user defined degrees/rads number. The code would have to (far as I'm thinking so far) loop through all prims, and then loop through all points in each prim, rotating each one around the previous point. Quote Link to comment Share on other sites More sharing options...
Popular Post f1480187 Posted April 25, 2016 Popular Post Share Posted April 25, 2016 (edited) Basic: // Primitive wrangle. int pts[] = primpoints(0, @primnum); vector rest = point(0, "P", pts[0]); vector prev_pos = rest; matrix3 frame = ident(); for (int i = 0; i < len(pts); i++) { vector pos = point(0, "P", pts[i]); rotate(frame, 0.1, {0, 0, 1}); vector new_pos = (pos - rest) * frame + prev_pos; rest = pos; prev_pos = new_pos; setpointattrib(0, "P", pts[i], new_pos); } Advanced: // Primitive wrangle. #define TWO_PI 6.2831852 addpointattrib(0, "N", {0, 0, 0}); int pts[] = primpoints(0, @primnum); int npt = len(pts); // Loop variables. vector rest = point(0, "P", pts[0]); vector prev_pos = rest; matrix3 frame = ident(); for (int i = 0; i < npt; i++) { vector pos = point(0, "P", pts[i]); vector delta = pos - rest; rest = pos; // Make normal. Point normals could be used instead. vector normal = normalize(cross(cross({0, 1, 0}, delta), delta)); if (length(normal) == 0) { normal = {0, 0, 1}; } // Drive a shape with ramps and multipliers. vector axis; float ramp, angle; // Twist the bend axis. axis = normalize(delta); ramp = chramp("twist_profile", (float) i / npt); angle = fit01(ramp, -TWO_PI, TWO_PI) * ch("twist") / (npt - 1); rotate(frame, angle, axis); // Bend the curve. axis = normalize(cross(normal, delta)); ramp = chramp("bend_profile", (float) i / npt); angle = fit01(ramp, -TWO_PI, TWO_PI) * ch("bend") / (npt - 1); rotate(frame, angle, axis); // Compute new position and normal. vector new_pos = delta * frame + prev_pos; prev_pos = new_pos; setpointattrib(0, "P", pts[i], new_pos); setpointattrib(0, "N", pts[i], normal * frame); } curl.hipnc Edited April 25, 2016 by f1480187 28 3 Quote Link to comment Share on other sites More sharing options...
Kardonn Posted April 27, 2016 Author Share Posted April 27, 2016 (edited) This is so cool to play with, thanks F1! Lots of things to learn from this bit of VEX code. If you feel even more generous, I'm trying to work out one more problem with is clumping hair using different clump profiles along two different axes. Right now the clumping scheme is you determine which clump guide to use for a given curve, and then that curve's @P just gets mixed against the guide curve's @P until the two are on top of each other. The issue with that is you just end up with spiky clumps no matter what, when what you're really after is an effect that leaves the hair curve's @P alone in the @tangent direction, but migrates @P in the @N direction towards the guide curve's @P in the @N direction. Very hard to explain in writing, but take a look at this picture to see what I mean. If you imagine the clumping guides are curled with the kind of VEX code you've setup here, then the hair strands need to clump along the guide's side profile, but not along the guide's front profile. None of this is for any project I'm working on, I just saw a picture of this kid's hair and had to figure out how to set something up like it in Houdini. SESI's fur CVEX procedural doesn't really have the inputs needed to achieve this though right now since they just import ClumpP without any information about the @tangent or @N of those clump curves. Either way though thanks so much for the help, really learned a lot! Edited April 27, 2016 by Kardonn 1 Quote Link to comment Share on other sites More sharing options...
astrofalcon Posted March 8, 2017 Share Posted March 8, 2017 Thanks! This is a great help to some flower petals I'm modeling - Shawn Quote Link to comment Share on other sites More sharing options...
jeannel Posted March 8, 2017 Share Posted March 8, 2017 Oh wow, super ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.