Jump to content

Bending a curve and stopping the bend at a certain angle


Recommended Posts

So here's the problem; I'm trying to bend a curve but have it stop when it is pointing straight down or up, ie. when the absolute value of the dot product of the normal (difference of prev point and current point) and a (0,1,0) vector is equal to 1. Think of it as a gravity force pulling an elastic curve down.

 

I've managed to bend it properly using a rotate-vop in a single vopsop, but I can't get it to stop bending. As far as I know it's because the vopsop doesn't process points in order.

I've tried using a foreach sop and bending one point per loop and looping it, but the problem I stumble upon here is that I don't know how to merge the results properly.

I have also tried using a while loop in a vopsop and recalculating the bend for each point for every point, but this is obviously very slow.

If I was to program this using code I would probably calculate the bend for each point in order once and then store it an array and from there lookup the result based on the point number, but I don't think it can be done in Houdini or can it?

 

I have attached an example file using the method I mentioned first so hopefully you can understand what I'm trying to do. I would appreciate any help I can get. Thank you.

 

Cheers,

Jonathan

curveBendingExample.hipnc

Edited by JonathanGranskg
Link to comment
Share on other sites

...

If I was to program this using code I would probably calculate the bend for each point in order once and then store it an array and from there lookup the result based on the point number, but I don't think it can be done in Houdini or can it?

...

you can

just create attribwrangle in detail mode

then all the code will be executed only once, not per point

so you can loop through all your points and set their individual values using setattrib()

Link to comment
Share on other sites

you can

just create attribwrangle in detail mode

then all the code will be executed only once, not per point

so you can loop through all your points and set their individual values using setattrib()

 

Thank you. I haven't tried it yet, I'll post here again if I encounter any problems.

Edited by JonathanGranskg
Link to comment
Share on other sites

How do I use the import() function in VEX to get the "P" attribute from a certain point? Currently I'm using:

 

import("P", pp; 0; pointnumber);

 

this is giving me an error message, pp is the variable I want "P" to be put into. What am I doing wrong?

 

I also think I had a moment of clarity and realized that this won't work the way I want to or maybe I'm just being confused, but essentially what I want is a curve to rotate like the points acting like they're parented to the previous points, like joints, but stop when they have rotated fully upward or fully downward.

Link to comment
Share on other sites

 

You have to define pp before import as it's passed by reference.

vector pp;
import...

 

Sorry, I should've been clearer. I have pp defined in my code.

 

you can't use import() in Attrib Wrangle

 

use point() to get the value of desired point

like:

vector pos = point(@OpInput1, "P", pointnumber);

Thank you. No more errors, but it doesn't work yet. Here's my code, bear in mind I'm a VEX newbie. ;)

 

 

float angle = 70;

for(int i = 0; i < 50; i += 1){

    int c = 0;

    int stopC = 0;

    vector pp;

    pp = point(@OpInput1, "P", i);

    vector pv;

    if (i != 0){

        pv = point(@OpInput1, "P", i-1);

    } else {

        pv = 0;

    }

    vector diff = normalize(pp - pv);

    float grad = point(@OpInput1, "grad", c);

    vector cross = cross(diff, {0,1,0});

    matrix m = { {1,0,0}, {0,1,0}, {0,0,1} };

    float mult = angle/50 * grad;

    if (abs(dot(diff, {0,1,0})) < 0.90){

        rotate(m, radians(mult*c), diff);

        pp *= m;

    } else if (c != 0){

        rotate(m, radians(mult*(c-1)), diff);

        pp *= m;

        stopC = 1;

    }

    if (stopC == 0){

    c += 1;

    }

    

     

    setattrib(geoself(), "point", "P", i, 0, pp, "set");

}

 

The c variable is just a counter for when the bending should stop after it has been stopped all the following points will be bent to the stopped degree or at least that's the purpose. pv is just the position of the previous point. The angle is supposed to be varied through a parameter to control the bend. I wouldn't be surprised if I've managed to miss something very basic been working on a digital asset for several hours in a row today. I should probably just sleep on it.

 

Feel free to ask if anything looks confusing, hopefully I'll be able to answer it.

 

Edit: grad attribute is an attribute on the points that takes $PT/($NPT-1)

Edited by JonathanGranskg
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...