Jump to content

Matrix in wrangle SOP


reyan

Recommended Posts

Hello wizards!
I have a question about point wrangle SOP.
Is it possible create a matrix, and use that matrix in copy SOP as a transform ?
In the file attached, i build all axis that i need for create a matrix, and rotate the copies with "roll_on_path" ramp parameter, but until now, no way.

If someone have an idea...

a big Thanks

 

 

  • Like 1
Link to comment
Share on other sites

Ah, I've not set matrix values manually as you've done before, but looks like its the same as vectors; the {} syntax only works for constant values. If you want to set them based on other variables, use set():

 

So this:

matrix3 mat = {{@N.x, @N.y, @N.z},{@binormal.x, @binormal.y, @binormal.z},{@up.x, @up.y, @up.z}};

becomes this (ie set() each of the internal vectors, and another set() around the whole matrix):

matrix3 mat = set(set(@N.x, @N.y, @N.z),set(@binormal.x, @binormal.y, @binormal.z),set(@up.x, @up.y, @up.z));

Then  to convert matrix to an orient:

@orient = quaternion(mat);

That said, it gets wacky results, so you might need to rethink your logic. :)

  • Like 2
Link to comment
Share on other sites

Rows order is is another quite painful issue outside matrix creation scope. This will also work:

mat = set(normal, up, binormal);
mat = set(normal.x, normal.y, normal.z,
          up.x, up.y, up.z,
          binormal.x, binormal.y, binormal.z);

All set function signatures, obtained with vcc --list-context CVEX command:

float     set( float )
float     set( int )
float     set( vector4 )
float     set( vector )
float     set( float[] )
float[]   set( matrix3 )
float[]   set( matrix )
float[]   set( float )
float[]   set( vector4 )
float[]   set( vector )
float[]   set( float[] )
float[]   set( int[] )
vector2   set( float )
vector2   set( float; float )
vector2   set( int )
vector2   set( vector4 )
vector2   set( vector2 )
vector2   set( vector )
vector2[] set( float[] )
vector2[] set( vector2[] )
vector    set( float )
vector    set( float; float; float )
vector    set( int )
vector    set( vector4 )
vector    set( vector2 )
vector    set( vector )
vector    set( float[] )
vector[]  set( matrix3 )
vector[]  set( float[] )
vector[]  set( vector[] )
vector4   set( float )
vector4   set( float; float; float; float )
vector4   set( int )
vector4   set( vector4 )
vector4   set( vector2 )
vector4   set( vector )
vector4   set( float[] )
vector4[] set( matrix )
vector4[] set( float[] )
vector4[] set( vector4[] )
matrix2   set( matrix2 )
matrix2   set( matrix3 )
matrix2   set( matrix )
matrix2   set( float )
matrix2   set( float; float; float; float )
matrix2   set( int )
matrix2   set( vector2; vector2 )
matrix2[] set( matrix2[] )
matrix2[] set( float[] )
matrix3   set( matrix2 )
matrix3   set( matrix3 )
matrix3   set( matrix )
matrix3   set( float )
matrix3   set( float; float; float; float; float; float; float; float; float )
matrix3   set( int )
matrix3   set( vector; vector; vector )
matrix3   set( float[] )
matrix3   set( vector[] )
matrix3[] set( matrix3[] )
matrix3[] set( float[] )
matrix    set( matrix2 )
matrix    set( matrix3 )
matrix    set( matrix )
matrix    set( float )
matrix    set( float; float; float; float; float; float; float; float; float; float; float; float; float; float; float; float )
matrix    set( int )
matrix    set( vector4; vector4; vector4; vector4 )
matrix    set( float[] )
matrix    set( vector4[] )
matrix[]  set( matrix[] )
matrix[]  set( float[] )
int       set( float )
int       set( int )
int[]     set( float[] )
int[]     set( int[] )
string    set( string )
string[]  set( string[] )
bsdf      set( bsdf )
bsdf[]    set( bsdf[] )
  • Like 6
Link to comment
Share on other sites

Hi again, i'm tryng to add a rotation to my path, so after matrix definition i have this code:

 

rotate(mat, angle, set(@N.x, @N.y, @N.z));

 

This works, and rotate the profile on the path by angle, but i would need control rotation with my spline ramp defined by

 

float ramp = chramp("roll_on_path");

 

How can i do that ?

​Thanks in advance

Link to comment
Share on other sites

Thanks, but maybe my code is a bit different let's see:
 

v@up = {0,1,0};
@N = normalize(@N);
v@binormal = normalize(cross(@N, @up));
@up = normalize(cross(@binormal, @N));
 
matrix3 mat = set(set(@N.x, @N.y, @N.z),set(@up.x, @up.y, @up.z), set(@binormal.x, @binormal.y, @binormal.z));
float angle = chramp("ramp", ch("turn")) * radians(360);
rotate(mat, angle,  set(@N.x, @N.y, @N.z));
 
@orient = quaternion(mat);
 
//@P *= mat;
 
float ramp = chramp("roll_on_path", @roll);

If i set P as you suggested works, but with weird result, seems that the rotation happen in world space and not with the matrix that i defined by hand;
But i'm using @orient for pass data to copy SOP, in this case doesn't work...
I attached the HDN file for better explanation

roll_test_tmp_002.zip

Link to comment
Share on other sites

if you want your ramp to control rotation over the length of the curve then replace your angle line with something like this:

...
float angle = chramp("ramp", @ptnum/(@numpt-1.0)) * radians(360) * ch("turn");
...

considering point numbers on your curve are in order

Link to comment
Share on other sites

That was an example of function usage. It rotates input around world's up using "Turn" parameter, where 1 does full revolution around axis. No need to set @P in your case. If you want to use roll attribute to control rotation instead, replace ch("turn") with @roll. There is no roll attribute defined on points in scene file, angle will be always zero for default ramp. Code you need now will be something like this:

v@up = {0,1,0};
@N = normalize(@N);
v@binormal = normalize(cross(@N, @up));
@up = normalize(cross(@binormal, @N));

matrix3 mat = set(@N, @up, @binormal);
float angle = chramp("ramp", @roll) * radians(360);
rotate(mat, angle,  @N);
@orient = quaternion(mat);
  • Like 2
Link to comment
Share on other sites

  • 11 months later...

hello

f1,  thank you for you great posts.

I have a situation here, and can't figure out why it's happening.

I'm applying the same code. ( a simple rotation around {1, 1, 1} , the white line)

matrix3 mat = ident();

float angle = ch("turn") * radians(360);

rotate(mat, angle, {1, 1, 1});

@P *= mat ;

 

but points, instead of rotating also moves. I tried to divide that with position vector of each point to get just rotation and not translation , no success.

is it meant to be working like this, with transform? .. I mean It should work.. but..

 

thank you in advance

 

 

 

 

Edited by haaranoos
Link to comment
Share on other sites

hello

I did that same thing in a scene with copy sop and simple teapot. ( here : 

decided to the same vop sop rotation matrix in attribute wrangler .. as you can see in the attached file, everything should work .. like the vop sop version but It doesn't .

I couldn't find out why.

might you please look at the file?

thank you in advance

 

teapot rotation.hip

Link to comment
Share on other sites

@haaranoos, here is the bug:

vector tangentu = point(0, 'tangentu', @ptnum);
vector tangentv = point(0, 'tangnetv', @ptnum);


matrix3 m = set (@tangentv, @tangentu ,@N);

Unlike @N, Houdini currently can't guess type of custom attributes like v@tangentu. You have to use proper type prefix. Also, you don't need two lines at the beginning, they just initialize two variables which was never used. They may be used instead of direct attribute access, but in that case you need to delete @.

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