Jump to content

how to import a object transform in vex

Recommended Posts

On 4/25/2008 at 3:27 PM, sanostol said:


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


For the record, there is a way to do this, but it's fugly... since coming up with this I have moved to using SpencerL's approach of using an objectmerge Sop instead... but in case someone really needs it, here it is. The full wrangle for making a matrix out of this should be straightforward but for reference it is on http://andy.moonbase.net. Cheers.

// Create vectors to fill a matrix using the second node input's transform (ie a null)
vector translate = set(`chs(opinputpath(".", 1)+"/tx")`, `chs(opinputpath(".", 1)+"/ty")`, `chs(opinputpath(".", 1)+"/tz")`);
vector rotate = set(`chs(opinputpath(".", 1)+"/rx")`, `chs(opinputpath(".", 1)+"/ry")`, `chs(opinputpath(".", 1)+"/rz")`);
vector scale = set(`chs(opinputpath(".", 1)+"/sizex")`, `chs(opinputpath(".", 1)+"/sizey")`, `chs(opinputpath(".", 1)+"/sizez")`);

But there's a much cleaner way, too. Get a matrix for your object (a camera or null usually) via optransform and then use the cracktransform function if you need some portion of the matrix, in this example I extract out the position. (The result is a simple way for getting the position of the camera in vex, which is a subject on a bunch of threads here.)

vector @cdir;

matrix camMatrix = optransform(chs("camera")); 
//get a matrix with the camera's transforms.

@cdir = cracktransform(0, 0, 0, {0,0,0}, camMatrix);
//extract out the camera position as a vector


Edited by Matic3D

Share this post

Link to post
Share on other sites

Lol yes much simpler... I figured it out around the time you posted and my message has been edited for reference. Thanks Tomas! I'm finding optransform and cracktransform to be pretty handy. Now in my 9'th week of houdini after moving over from ICE and liking it more and more, cheers.

Edited by Matic3D

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