Jump to content
sanostol

how to import a object transform in vex

Recommended Posts

hi,

I want to get the matrix4 of a object ( a null ), and use it for some stuff in vex. is it possible? I was looking for something like the object CHOP in chops. where UYou simply provide the path to a object

?

Share this post


Link to post
Share on other sites

you could create a geometry OBJ and put an object merge SOP inside it. Merge your object and change the Transform Parameter of the obj merge SOP to "Into This Obj".

Share this post


Link to post
Share on other sites

I think we missunderstood us :)

i meant vex( a VOPSOP to be exact) not SOP, but maybe I'm too shortsighted. i want to use the transform of the object to control something in the vexcontext

you could create a geometry OBJ and put an object merge SOP inside it. Merge your object and change the Transform Parameter of the obj merge SOP to "Into This Obj".
Edited by sanostol

Share this post


Link to post
Share on other sites
I think we missunderstood us :)

i meant vex( a VOPSOP to be exact) not SOP, but maybe I'm too shortsighted. i want to use the transform of the object to control something in the vexcontext

Vex is best in handling points - maybe you can transfer the values to a point (addSOP) first?

Share this post


Link to post
Share on other sites
i meant vex( a VOPSOP to be exact) not SOP, but maybe I'm too shortsighted. i want to use the transform of the object to control something in the vexcontext

Right, maybe Im missing something but doing the obj merge SOP brings your OBJ Transform into the SOP context and then you could create a point attribute which represents the OBJ xform and then bring that into your VOP SOP via a parameter VOP.

Share this post


Link to post
Share on other sites

maybe You can explain a bit more. cause I don't see the way. for example when I import my /obj/null1/point1 inot another object, the point does not store any data, beside it;s position, not rotation, and no scale.

Right, maybe Im missing something but doing the obj merge SOP brings your OBJ Transform into the SOP context and then you could create a point attribute which represents the OBJ xform and then bring that into your VOP SOP via a parameter VOP.

Share this post


Link to post
Share on other sites
maybe You can explain a bit more. cause I don't see the way. for example when I import my /obj/null1/point1 inot another object, the point does not store any data, beside it;s position, not rotation, and no scale.

maybe:

objectMerge.

attributeCreate -> matrix -> get the matrix data

here I stumble as well. You definitively can read all sorts of transforms with a objectCHOP.

I guess there is even a vex function for getting maxtrix stuff ...

Share this post


Link to post
Share on other sites

Depending on what you are really doing you might be able to use the attributeReorient sop to get the rotation as a quaternion and the position is easily extracted from the point positions.

The quaternion if necessary can be converted into a rotation matrix in vops...

Share this post


Link to post
Share on other sites
Depending on what you are really doing you might be able to use the attributeReorient sop to get the rotation as a quaternion and the position is easily extracted from the point positions.

The quaternion if necessary can be converted into a rotation matrix in vops...

Great hint, Simon!

thank you!

Share this post


Link to post
Share on other sites
maybe You can explain a bit more. cause I don't see the way. for example when I import my /obj/null1/point1 inot another object, the point does not store any data, beside it;s position, not rotation, and no scale.

AH, Im completely mis-read the post. I was thinking you were trying to get the transform, not the rotation. :unsure:

Share this post


Link to post
Share on other sites

I'm getting back into quaternion's they are so useful and now better integrated into Houdini with the attributeReorient sop and dops...

Share this post


Link to post
Share on other sites
I'm getting back into quaternion's they are so useful and now better integrated into Houdini with the attributeReorient sop and dops...

Yes, I can feel it, but I don't see it ;). So, if quaternion is an efficient way to store and manipulate a rotation data in 3d, how to compute it in directly in VEX? Lets say we have some attributes N & Up on point and we know its values before and after some transformations. How to compute quaternion from that? dihedral() gives me a matrix3 for one of attribute (vector) which is not enough to recreate rotation that happened? Could you bless us with your enlightenment?

thank you, thank you! :)

Sy.

Edited by SYmek

Share this post


Link to post
Share on other sites

Why try and compute it yourself? That's what attributeReorient is for.

Use attributeCreate to add a default quaternion (0,0,0,1) to the rest position of your geometry, then bring in the animated version and use attributeReorient to calculate the new quaternion. Then in vex if you need it use "Quaternion to Matrix3" vop to extract the rotation matrix.

If you have to build a quaternion in vex then what you need to know is how easy it is to build a rotation matrix from a set of axis vectors. Assuming N and Up are at 90 degrees to each other and normalised you can calculate the 3rd axis by building the cross product vector (cross product vop) then you just need to stuff all 9 floats into a matrix this will give you the matrix that aligns the axis back to the origin. Then just take the inverse to compute the matrix that will rotate something from the origin to the orientation specified by N and Up. Finally use "Matrix3 to Quaternion" vop to get the quaternion.

The way you build a matrix from your axis is like this

N = x_axis

Up = y_axis

CrossUpN = z_axis

matrix =

| x_axis0, x_axis1, x_axis2 |

| y_axis0, y_axis1, y_axis2 |

| z_axis0, z_axis1, z_axis2 |

You can also do something similar if you need to align one axis with another (ie not the origin), just do the same calculation as above for both axis so you have 2 matrices but only invert one of them, multiplying the 2 together will give you a combined matrix that will orient one axis to another.

Edited by sibarrick
  • Like 2

Share this post


Link to post
Share on other sites
Why try and compute it yourself? That's what attributeReorient is for.

Use attributeCreate to add a default quaternion (0,0,0,1) to the rest position of your geometry, then bring in the animated version and use attributeReorient to calculate the new quaternion. Then in vex if you need it use "Quaternion to Matrix3" vop to extract the rotation matrix.

If you have to build a quaternion in vex then what you need to know is how easy it is to build a rotation matrix from a set of axis vectors. Assuming N and Up are at 90 degrees to each other and normalised you can calculate the 3rd axis by building the cross product vector (cross product vop) then you just need to stuff all 9 floats into a matrix this will give you the matrix that aligns the axis back to the origin. Then just take the inverse to compute the matrix that will rotate something from the origin to the orientation specified by N and Up. Finally use "Matrix3 to Quaternion" vop to get the quaternion.

The way you build a matrix from your axis is like this

N = x_axis

Up = y_axis

CrossUpN = z_axis

matrix =

| x_axis0, x_axis1, x_axis2 |

| y_axis0, y_axis1, y_axis2 |

| z_axis0, z_axis1, z_axis2 |

You can also do something similar if you need to align one axis with another (ie not the origin), just do the same calculation as above for both axis so you have 2 matrices but only invert one of them, multiplying the 2 together will give you a combined matrix that will orient one axis to another.

Thanks Simon, this is what I expected, but I thought that, thanks to the whole quaternion business, I don't have to build a matrix (axes->matrix->quaternion), so I can keep somehow everything as a quaternion and at the end convert it to matrix to transform my geometry as needed.

But it explain a lot!

cheers,

Sy.

Share this post


Link to post
Share on other sites

thank You very much sibarrick, that was indeed very enlightend. :) i completely forgot what a point can store and do.

unfortunately, the length of the vecotors is not correct. when i scale the object at the objlevel about 2 times, the normals get 2 times longer in the viewport.

but when I objectmerge it into another geo. the normals are one again. it seems that the objectmerge does not consider scaling for vector attributes. this makes it hard to do scaling in the procedure mentioned above

Edited by sanostol

Share this post


Link to post
Share on other sites
unfortunately, the length of the vecotors is not correct. when i scale the object at the objlevel about 2 times, the normals get 2 times longer in the viewport.

Probably a bug in the viewport display of the normals. Submitted the bug.

Vectors aren't really scaled if you scale an object in the scene.

Share this post


Link to post
Share on other sites

The procedure I outlined has nothing to do with scaling anything, only rotation, and to build the rotation matrix you need normalised vectors, so the one thing you don't want to be doing is scaling them.

However if you do need to scale a vector for some other reason it is easily done inside the vex code simply by multiplying by a float.

Share this post


Link to post
Share on other sites

it wasn't my intention to scale a vector, but instead i was interested in the full transform of a object at the object level, meaning position, orientation and scaling. the way You outlined gave me position and rotation. scaling was the last component of my transform. I added a single point to my object of desire and added 3 vector attributes xyz, with their axis values. I made them visible in the viewport and when I scaled my object the vectors got bigger. but it seems that the viewport tricks me here. when I object merge them into a new object the vectors have their unscaled length. rotation and position are handled correct. with scaled vectors i could get the rotation also, by normalizing them, but could also get the scaling of the axis. just seemed strange to me.

The procedure I outlined has nothing to do with scaling anything, only rotation, and to build the rotation matrix you need normalised vectors, so the one thing you don't want to be doing is scaling them.

However if you do need to scale a vector for some other reason it is easily done inside the vex code simply by multiplying by a float.

Share this post


Link to post
Share on other sites

If you want the scale how about comparing the distance between point 0 and 1 on the scaled and non scaled versions?

Share this post


Link to post
Share on other sites

mh, don't get it :unsure:

my next try is to add 3 other points, that i can use to get the scale of every axis. the distance of the imported ones should give me the scale, hopefully

but still it would be usefull to have a simple vop that gives You access to the full transfom of obj

If you want the scale how about comparing the distance between point 0 and 1 on the scaled and non scaled versions?

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

×