Rayhan Moidu

rayhanm

About Me

Connect

LOCATION
Toronto, Canada
ウェブサイト

Houdini Engine

Availability

Not Specified

My Badges

SideFX Staff
Since 9月 2023

Recent Forum Posts

How to correctly pre-orient Python state xform handles? 2025年9月25日15:55

If I am understanding correctly, you have some local space, which is some translation and axis rotation, defined as a 4x4 matrix.

What you can do is use the handle's preform parameters to express the local space transformation. If you explode your local space matrix, you can shove the resulting translate, rotate, scale, and shear into pivot_comp_t*, pivot_comp_r*, pivot_comp_s*, and pivot_comp_shear_*, respectively. This can be done in onStateToHandle.

With this, the handle should be oriented based on the local space you used. If you interactively move the handle, the value you receive in onHandleToState will be in the local space. So for example, if you simply move the handle's red "x-axis" translation component, the handle will effectively experience displacement in all 3 world space axes, due to it being oriented to your local space. But you'd only receive meaningful updates to "tx" in onHandleToState (the updates to "ty" and "tz" will be 0, or some negligibly small value).

I am assuming you have node parameters that match those within the handle (similar to the Transform or Edit SOP, which have node parms for translate, rotate, etc, that are bound to the handle). Because you've shoved your local space information into the preform, which is the first step in the handle's matrix sequence computation, the remaining parms will all be applied in the local space.
For instance, in onStateToHandle, say you shove your node's translate parms directly into the handle's tx, ty, and tz. If you start adjusting your node's tx parm in the parm dialogue, the handle will begin to move that amount in the local space x-axis (since the preform will have been applied by the time the handle applies tx).

So, if you treat the handle's preform parms I mentioned above as representative of the local space, the remaining parms can just be bound directly in onStateToHandle and onHandleToState, without needing any special matrix manipulation or extraction.
Things might get more complex if your node also has options for user-defined preforms, like the Edit SOP has. Because then your handle's preform parms will have to be a combination of the local space, and the true preform.
But please let me know if you have further questions.