Jump to content
konstantin magnus

Rotate cameras from vector list to degrees

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)

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

Edited by konstantin magnus

Share this post

Link to post
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

Share this post

Link to post
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?

Share this post

Link to post
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

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