Jump to content
prekabreki

Instanced mesh orientation along curve (help!)

Recommended Posts

I'm trying to create a pipe HDA for Unreal Engine 4 that either calls upon a straight piece or a corner piece and then orients each piece accordingly.

I feel like I'm going about it all wrong, but the result I have is so close!

As you can see in the first picture, it's KIND OF working, but I think it might fall apart very easily.

I've attached a hip file any help would be greatly appreciated.

 

01.JPG

02.JPG

pipeorient.hip

Edited by prekabreki

Share this post


Link to post
Share on other sites

Look at this Entagma tutorial :

 

Share this post


Link to post
Share on other sites
int primpts[] = primpoints(0,@primnum);
matrix3 m = ident(); //here you could use your own base matrix
foreach(int index;int i;primpts){
    //create direction vector, can be replaced by a predefined vector
    int forward = 1; 
    if(index == len(primpts)-1){
        forward = -1;
        }
    vector this_pos = point(0,"P",i);
    vector next_pos = point(0,"P",primpts[index]+forward);
    vector dir = normalize(next_pos-this_pos)*forward;
    setpointattrib(0,"dir",i,dir,"set");
    
    //align matrix
    vector matrix_z = set(getcomp(m,2,0),getcomp(m,2,1),getcomp(m,2,2));
    matrix_z = normalize(matrix_z);
    float angle = acos(dot(matrix_z,dir));
    vector axis = normalize(cross(matrix_z,dir));
    rotate(m,angle,axis);
    
    //convert to orient
    vector4 orient = quaternion(m);
    setpointattrib(0,"orient",i,orient,"set");    
    }

Put this code in a primitive wrangle and you will have parallel transport, you can evolve this into a bigger asset.

Share this post


Link to post
Share on other sites

Thanks for the help so far, this seems like a much more sensible and stable way to do things, even if it is a bit over my head.

I'm afraid I'm still having issues though when it comes to orienting the corner pieces.

My latest hip is below if someone wants to take a look, you can see my problem in the attached image.

pipesorient02.hip

pipes.JPG

Share this post


Link to post
Share on other sites

Hi,

parallel transport cannot handle this issue alone, because the (red)object has to invert its orientation, if you have a "right/left" corner. I would prefer a parallel transport implementation, which sets the v@up and v@N attributes for each point, because the "copy to points" node can use these attributes aswell and it will be easier to modify vectors.

To determine the type of the corners you can use the average of the neighbour points and compare the direction to it with v@N value (using the dot product). If the product < 0, you can multiply v@N with -1, but note, that you destroy the parallel transport frame.

There are probably other solutions out there ...

 

 

pipesorient02.hipnc

Share this post


Link to post
Share on other sites
1 hour ago, Aizatulin said:

Hi,

parallel transport cannot handle this issue alone, because the (red)object has to invert its orientation, if you have a "right/left" corner. I would prefer a parallel transport implementation, which sets the v@up and v@N attributes for each point, because the "copy to points" node can use these attributes aswell and it will be easier to modify vectors.

To determine the type of the corners you can use the average of the neighbour points and compare the direction to it with v@N value (using the dot product). If the product < 0, you can multiply v@N with -1, but note, that you destroy the parallel transport frame.

There are probably other solutions out there ...

 

 

pipesorient02.hipnc

Thanks so much Aizatulin, that's exacly what I was looking for. All this orientation math is a big weakspot of mine. I wanted to ask if you had a quick solution if I wanted to change the elevation of the curve like in the picture below?

pipes2.JPG

Share this post


Link to post
Share on other sites
8 minutes ago, Aizatulin said:

you can set v@N directly to dir, which is a more general solution, but the corner should be rectangular, if your pipe is rectangular aswell.

 

pipesorient02A.hipnc

You've saved my ass, thanks so much for your help!

(Also, neat path deformer!)

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×