Gradient Descent

   3094   2   1
User Avatar
Member
11 posts
Joined: July 2013
Offline
I'm hoping someone can help me out with creating a gradient descent algorithm in VOPs (it might not be possible?).

I've be trying to reverse engineer this - https://vimeo.com/60606152 [vimeo.com] which is done with Rhino. I can get as far as the point where you need to push the points back to the surface (timecode 2:49 in the video). They do this using a surface CP node (which as far as I can tell imports the vectors for the nurbs surface?). Is the there an equivalent way of doing this in VOPs or am I going about it in the wrong way? Any help will be much appreciated.

Thank you,
Mark

Attachments:
GradDescent_01.hip (80.5 KB)

User Avatar
Member
339 posts
Joined: Aug. 2007
Offline
Here's a fairly efficient take…
You can do the curve building in Vops but it's probably easier to understand this way. When looking up the closest point on a surface it's much more efficient to work on polygons than nurbs.

Attachments:
graddescent_01_132.hip (112.0 KB)

Jesse Erickson
Fx Animator
WDAS
User Avatar
Member
27 posts
Joined: Jan. 2007
Offline
I ported the example to VEX, thought it might be helpful even though the thread is a few years now.

int numiterations = chi("number_of_iterations");
float gravity = chf("gravity");
float max_search_distance = chf("max_search_distance");

vector last_position = @P;
for (int _i=0; _i < numiterations; _i++) {
    
    // Move with gravity
    //        |
    //        |
    //        v
    vector new_position = last_position + set(0, -gravity, 0);
    
    // Resolve collision
    //
    //    _____|
    //   /     |
    //  /      |\
    // /       v -->
    //            \____
    //
    last_position = minpos(1, "", new_position, max_search_distance);

    int ptnum = addpoint(0, last_position);
    setpointattrib(0, "id", ptnum, @ptnum);
}

Attachments:
graddescent.hipnc (89.7 KB)

  • Quick Links