Jump to content

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
Link to comment
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.

Link to comment
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

Link to comment
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

Link to comment
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

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...