Jump to content

Rotate cameras from vector list to degrees


konstantin magnus

Recommended Posts

I have read lots of camera angles from a text file, and try to convert them from vectors to degrees:

rot_list = rots.split()
# ['0.768704', '-0.628123', '-0.120648']
rot_deg = hou.Vector3.angleTo(rot_list)
node_camera.parmTuple('r').set(rot_deg)

It throws an error: unbound method angleTo() must be called with Vector3 instance as first argument (got str instance instead)

Edited by konstantin magnus
Link to comment
Share on other sites

it's not really clear what [ '0.768704',  '-0.628123', '-0.120648' ] is. Is it the xyz values of the camera's rotation or is it the vector the camera points to? (like houdini cam points to (0, 0, -1) by default)

I'm asking because angleTo() returns the degrees between 2 vectors as a float value.
So your code would fail because you dont specify the first of those 2 vectors. the line should be something like rot_deg = hou.Vector3(0,0,0).angleTo(rot_list)

next issue - your error message: the list returns the values as strings (notice the ' ' ). so you might add a step and fix that like so: myVec = hou.Vector3(float(rot_list[0]), float(rot_list[1]), float(rot_list[2]))
and then use rot_deg = ... angleTo(myVec) with proper vector3 as argument

still, you then try to set a single float to the parmTuple('r') wich is not gonna work as it expects a sequence of values

 

In case of it being radians you could

import math
and with math.degrees(float(rot_list[0])) convert it to degrees
save that in a list and try feeding that into parmTuple.set()

Edited by 3dome
Link to comment
Share on other sites

Hi Dominik, thanks for your help.

8 hours ago, 3dome said:

it's not really clear what [ '0.768704',  '-0.628123', '-0.120648' ] is.

Its a vector deviating from {0,0,-1}, exactly like the line SOP. So I am still looking for a method to convert this 3d vector to 3 degree values rx, ry, rz.

How is this usually done in Python?

Link to comment
Share on other sites

Hi Konstantin!

If i understood you right it must be working. 0,0,-1 is initial direction for a camera, rotDeg is vector with rotation in degrees.

def vtd(vector):
    vec = hou.Vector3(vector).normalized()
    m4 = hou.Vector3(0,0,-1).matrixToRotateTo(vec)
    m3 = m4.extractRotationMatrix3()
    rotDeg = m3.extractRotates()
    return rotDeg

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Try this:

def vtd(vector):
    vec = hou.Vector3(vector).normalized()
    initDir = hou.Vector3(0,0,-1)
    initUp = hou.Vector3(0,1,0)
    
    m4 = initDir.matrixToRotateTo(vec)
    dir = initDir * m4
    up = initUp * m4
    newUp = dir.cross(initUp.cross(dir))
    mrx = m4 * up.matrixToRotateTo(newUp)
    
    m3 = mrx.extractRotationMatrix3()
    rotDeg = m3.extractRotates()
    return rotDeg

 

  • Like 1
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...