Bending a curve towards vector by weight blending matrices

   2928   3   1
User Avatar
Member
79 posts
Joined: March 2016
Offline
Hi all,

So I have a curve on the y-axis. That I want to bend for example towards the x-axis (see picture 1).



Each point has a weight attrib, the sum of all those weight attribs should be 1, meaning that the end of the curve is exactly aiming like the aim/goal vector. I do that by using this script (the aim vector is the goal I want it to aim like):

vector aim = set(1,0,0);
int npts = npoints(0);

//Create empty lists
vector new_p[];
vector new_n[];

//Store all current values in list
for(int pt = 0; pt < npts; pt++){
    new_p[pt] = point(0, "P", pt);
    new_n[pt] = point(0, "N", pt);
}

//Transform points
for(int pt = 0; pt < npts; pt++){
    vector p = new_p[pt];
    vector n = new_n[pt];
    float weight = point(0, "weight", pt);
    matrix m = dihedral(n, aim);
    
    //Blend transformation by weight
    m = slerp(ident(), m, weight);
    
    for(int cpt = pt; cpt < npts; cpt++){       
        vector cp = new_p[cpt];
        vector cn = new_n[cpt];

        cp = (cp - p) * m + p;
        cn *= m;
           
        setpointattrib(0, "P", cpt, cp, "set");
        setpointattrib(0, "N", cpt, cn, "set");
            
        new_p[cpt] = cp;
        new_n[cpt] = cn;
    }
}

The problem is that if I use a linear weight ramp (so point 0 has the lowest weight and point 9 the highest, still summed up being 1) the curve is bend somewhere half-way it is supposed to be (picture 2 goal_vector_bend).



But when I remap the weight to just one point being 1 (pt 4) and all the other points being 0 it does work. See picture 3 (goal_vector_correct).



Does anyone know how to get this working correctly? Like as long as the sum of the weight attribs is 1 it should be aligned with the aim vector and if the sum would be lower than 1 it should ofcourse not be fully aligned.

I added the scene file in the attachments.
Edited by Klonkel - Dec. 16, 2022 07:52:46

Attachments:
goal_vector.png (428.9 KB)
goal_vector_bend.png (437.5 KB)
goal_vector_correct.PNG (435.7 KB)
tree_rig_v008_sidefx.hip (149.2 KB)

https://www.youtube.com/@Klonkel
User Avatar
Member
9380 posts
Joined: July 2007
Offline
- first of all I'd suggest you have a look at KineFX (Rig Attribute Wrangle or Rig Attribute VOP) as that does the heavy lifting of accumulating rotations for you so all you need to do is update the matrices per point based on per point weights

- in your particular approach it seems like the problem is in this line
matrix m = dihedral(n, aim);
since you keep modifying n with updated new_n[pt]from previous iterations
the n is getting closer to the aim
but then you are taking only a weighted fraction of the difference between updated n and aim, which will be less rotation than from original n to aim

if you are ok with assuming that you are starting with the straight line you can compute the full rotation difference only once (from the first N) and for each point just get the corresponding weighted fraction from it

as a quick fix assuming the original line is pointing up in Y you can change it to to see if it works:
matrix m = dihedral({0,1,0}, aim);
Edited by tamte - Dec. 16, 2022 08:21:29
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
5100 posts
Joined: Feb. 2012
Offline
I show an example of bending a line using KineFX and then a more complex geometry here:

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
79 posts
Joined: March 2016
Offline
Thank you both!

@tamte that makes sense indeed, the updated N needs a new sort of weight in order to still be correct.

@animatrix yeah I actually came acros that video last week, very very interesting work, also tried the rig_wrangle approach.

Currently I found out that the weight is needed, but not in a way where I have to make the sum of all weights together 1. But just all weight attribs just ramped between 0-1. That gives me more control.

Thank you both for the help!

Cheers,
Chris
https://www.youtube.com/@Klonkel
  • Quick Links