Get and set world space coordinates/vectors of an Object?

   979   0   0
User Avatar
Member
41 posts
Joined: May 2021
Offline
I'm trying to align(move) an end controller of an IK inverse kin to a null object parented to the end(tip) of a FK bone, so I need world space coordinates vector, and I get them with hou.node("/obj/geo1").worldTransform().extractTranslates() ... depending on transform order ('srt' or 'trs') I'm getting different results... right, OK... now the weird thing is, if I move the end controller object in the viewport, the value of the printed vector doesn't change/update? I'm missing something... what? And the .set() function doesn't work on vector3 objects, so what do you use for that purpose?

EDIT: Ok, setWorldTransform does the job, but now I want to limit it only to translation? I don't need rotation, or scaling...

EDIT N.2 Ok guys this is driving me nuts... If I apply .extractTranslates() to target object this basically explodes its matrix and takes only translations (vectors), but I can't figure out how to shove these values into another matrix... is this even possible? Anyone? Anything?

From Ik_Ctrl I'm getting "hou.Matrix4[, , , ]" and I need to change only the fourth row... Do I need to create another (desired) matrix and apply it as a whole package?

EDIT N.3
Well I got it... If this is not the most cumbersome way of getting and setting values and vectors in the world then I'm Einstein himself...

You poor souls are getting and setting world space positions (vector3)of an object (in .obj level) like this:

##Grab the object you want
IK_Target_Obj = hou.node('/obj/L_Arm_IK_Target')

##Explode (Hulk SMASH) the matrix4 in different values and grab only world space position as a Vector3 in one of the transform
##orders...right...ok...
IK_Target_WS_Pos_Vector3 = hou.node('/obj/L_Arm_IK_Target').worldTransform().extractTransform('srt')

##Create/rebuild NEW (WTF!?!?) matrix containing only translate values from a Vector3 you just extracted
##while all the other values are zeroed out
New_Position_Matrix = hou.hmath.buildTranslate(IK_Target_WS_Pos_Vector3)

##Slap the new matrix on the object you want to move to the target position while keeping other values intact(scale, rotate etc)
IK_CTRL_Obj = hou.node('/obj/L_Arm_IK_CTRL').setWorldTransform(New_Position_Matrix)

So this squeezing of vectors out of matrices and again creating new matrices out of squeezed vectors only to be passed as a new position/rotation/scale value is really, REALLY, REALLY, unnecessary for us the poor users...

I want something like this:

IK_Target_WS_Pos_Vector3 = hou.node('/obj/L_Arm_IK_Target').GetWorldPosition()
Why do I need to fiddle around with matrices and vectors? I don't know much (but I'm forced to learn) about matrices and vectors and frankly, I don't care and don't want to know...
Edited by kriegmesser74 - Aug. 22, 2021 09:33:57
  • Quick Links