konstantin magnus Posted May 16, 2018 Share Posted May 16, 2018 (edited) 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 May 16, 2018 by konstantin magnus Quote Link to comment Share on other sites More sharing options...
3dome Posted May 16, 2018 Share Posted May 16, 2018 (edited) 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 May 16, 2018 by 3dome Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted May 16, 2018 Author Share Posted May 16, 2018 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? Quote Link to comment Share on other sites More sharing options...
3dome Posted May 17, 2018 Share Posted May 17, 2018 i dont think python has built in methods for that but you can do it with some math: https://stackoverflow.com/questions/15101103/euler-angles-between-two-3d-vectors https://stackoverflow.com/questions/10706708/find-x-y-z-rotation-between-two-normal-vectors Quote Link to comment Share on other sites More sharing options...
vicvvsh Posted May 18, 2018 Share Posted May 18, 2018 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 1 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted May 26, 2018 Author Share Posted May 26, 2018 Thanks to both of your help I was able to make it work: Just one more question: How can I change the matrices so that the cameras are not rolled sideways? Quote Link to comment Share on other sites More sharing options...
vicvvsh Posted May 26, 2018 Share Posted May 26, 2018 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 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.