How to create spline from points

   1725   9   2
User Avatar
Member
40 posts
Joined: March 2018
Offline
Hi, I want to crate spline which follows the point direction. it's hard to connect this way, if I just try to connect the closest that won't be right in some cases, specifically in the corner. Anyone has a idea how to do that?
Edited by Beka - Aug. 31, 2023 12:20:15

Attachments:
Screenshot 2023-08-31 173536.png (581.8 KB)

User Avatar
Member
42 posts
Joined: March 2019
Offline
if they happen to be in right point order just use "add" sop enabling by group under polygons tab. Or otherwise if they somehow have fitting attributes you can also use 'add' to connect them via the attribute
User Avatar
Member
40 posts
Joined: March 2018
Offline
Lucca
if they happen to be in right point order just use "add" sop enabling by group under polygons tab. Or otherwise if they somehow have fitting attributes you can also use 'add' to connect them via the attribute
Thanks Lucca!
Problem is that I don't know the right point order. I have not any information, only this.
User Avatar
Member
4530 posts
Joined: Feb. 2012
Offline
You can look up points in the direction of the previously found point by making an exception in the first point and limit your search to a cone angle using pcopen:
https://www.sidefx.com/docs/houdini/vex/functions/pcopen.html [www.sidefx.com]

Alternatively you can implement the same cone angle yourself and use the newer pcfind VEX functions.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
40 posts
Joined: March 2018
Offline
animatrix_
You can look up points in the direction of the previously found point by making an exception in the first point and limit your search to a cone angle using pcopen:
https://www.sidefx.com/docs/houdini/vex/functions/pcopen.html [www.sidefx.com]

Alternatively you can implement the same cone angle yourself and use the newer pcfind VEX functions.
Thank you!
I thought something similar and probably it is the only way. I can not see how can I transfer cone information into pcopen(), but now I've found function of pccone() which can get direction and cone angle, (Wow I don't know that function). I think it will be difficult in the corner area, but yeah it will be good starting point
User Avatar
Member
120 posts
Joined: Aug. 2017
Offline
float pos_arr[] = {}; 
for(int i=0;i<@numpt;i++) {
    vector p = point(0, "P", i);
    push(pos_arr, p.z);
}
int ordering[] = argsort(pos_arr); 
ordering = reverse(ordering); 



for(int i=0;i<@numpt;i++) {
    setpointattrib(0, "sort_index", ordering[i], i);
}
sort by index and Add.
Conservation of Momentum
User Avatar
Member
40 posts
Joined: March 2018
Offline
cncverkstad
float pos_arr[] = {}; 
for(int i=0;i<@numpt;i++) {
    vector p = point(0, "P", i);
    push(pos_arr, p.z);
}
int ordering[] = argsort(pos_arr); 
ordering = reverse(ordering); 



for(int i=0;i<@numpt;i++) {
    setpointattrib(0, "sort_index", ordering[i], i);
}
sort by index and Add.
Thank you so much!
It has problem when curve turns around

Attachments:
Screenshot 2023-09-05 173540.png (890.8 KB)

User Avatar
Member
120 posts
Joined: Aug. 2017
Offline
For that you can use
Euclidean Minimum Spanning Tree by Satoru Yonekura that I got those codes from.
foreach(int pt; nearpoints(0, @P, 1.0, 10))
{
    if(pt == @ptnum) continue;
    
    vector p = point(0, 'P', pt);
    float dist = distance(p, @P);
    
    int ptsA[] = nearpoints(0, @P, dist);
    int ptsB[] = nearpoints(0, p, dist);
    
    int chk = 0;
    foreach(int cpt; ptsB)
    {
        if(cpt == @ptnum || cpt == pt) continue;
        
        chk = removevalue(ptsA, cpt);
        if(chk) break;
    }
    
    if(!chk)
    {
        int pr = addprim(0, 'polyline');
        addvertex(0, pr, @ptnum);
        addvertex(0, pr, pt);
    }
}
Clean
Convertline
detail wrangle
int ptlist[];
for(int pt=0; pt<@numpt; pt++)
    push(ptlist, pt);
    
int newlist[];
push(newlist, 0);
removevalue(ptlist, 0);

while(len(ptlist) > 0)
{
    float mindist = 10000;
    int newpt = -1;
    int newedge = -1;
    
    foreach(int pt; newlist)
    {
        foreach(int prim; pointprims(0, pt))
        {
            int targetpt = primpoint(0, prim, 0);
            if(targetpt == pt) targetpt = primpoint(0, prim, 1);
            
            if(find(newlist, targetpt) > -1) continue;
            
            float dist = prim(0, 'restlength', prim);
            if(dist <= mindist)
            {
                mindist = dist;
                newpt = targetpt;
                newedge = prim;
            }
        }
    }
    
    if(newpt == -1) break;
    
    push(newlist, newpt);
    removevalue(ptlist, newpt);
    setprimgroup(0, 'newedge', newedge, 1);
}

blast not newedge

Have Fun
Edited by cncverkstad - Sept. 5, 2023 12:09:31
Conservation of Momentum
User Avatar
Member
40 posts
Joined: March 2018
Offline
cncverkstad
For that you can use
Euclidean Minimum Spanning Tree by Satoru Yonekura that I got those codes from.
foreach(int pt; nearpoints(0, @P, 1.0, 10))
{
    if(pt == @ptnum) continue;
    
    vector p = point(0, 'P', pt);
    float dist = distance(p, @P);
    
    int ptsA[] = nearpoints(0, @P, dist);
    int ptsB[] = nearpoints(0, p, dist);
    
    int chk = 0;
    foreach(int cpt; ptsB)
    {
        if(cpt == @ptnum || cpt == pt) continue;
        
        chk = removevalue(ptsA, cpt);
        if(chk) break;
    }
    
    if(!chk)
    {
        int pr = addprim(0, 'polyline');
        addvertex(0, pr, @ptnum);
        addvertex(0, pr, pt);
    }
}
Clean
Convertline
detail wrangle
int ptlist[];
for(int pt=0; pt<@numpt; pt++)
    push(ptlist, pt);
    
int newlist[];
push(newlist, 0);
removevalue(ptlist, 0);

while(len(ptlist) > 0)
{
    float mindist = 10000;
    int newpt = -1;
    int newedge = -1;
    
    foreach(int pt; newlist)
    {
        foreach(int prim; pointprims(0, pt))
        {
            int targetpt = primpoint(0, prim, 0);
            if(targetpt == pt) targetpt = primpoint(0, prim, 1);
            
            if(find(newlist, targetpt) > -1) continue;
            
            float dist = prim(0, 'restlength', prim);
            if(dist <= mindist)
            {
                mindist = dist;
                newpt = targetpt;
                newedge = prim;
            }
        }
    }
    
    if(newpt == -1) break;
    
    push(newlist, newpt);
    removevalue(ptlist, newpt);
    setprimgroup(0, 'newedge', newedge, 1);
}

blast not newedge

Have Fun
Wow it works! amazing!
Only the areas where I have harsh edges have a problem, but the rest is great!
Thank you!

Attachments:
aa.png (726.6 KB)

User Avatar
Member
120 posts
Joined: Aug. 2017
Offline
change some values of code to made exact matching .it should work .Have Fun .
Conservation of Momentum
  • Quick Links