0

I am trying to get a 3Dpoint on Sun light in Blender 3D, so that I can use it to specify directional light target position in Three JS. I have read from this How to convert Euler angles to directional vector? I could not get it. Please let me know how to get it.

  • Welcome to Stackoverflow. Please take the [tour](https://stackoverflow.com/tour) and read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Lucan May 10 '21 at 09:48

1 Answers1

0

I think it is a good question. In blender, since the unit vector starts from the z-axis (the light points down when initialized), I think you could use the last column of the total rotation matrix. The function for calculating the total rotation matrix is given here. Here is a modification of the function that will return a point at unit distance in the direction of the light source:

def getCosinesFromEuler(roll,pitch,yaw):
    Rz_yaw = np.array([
        [np.cos(yaw), -np.sin(yaw), 0],
        [np.sin(yaw),  np.cos(yaw), 0],
        [          0,            0, 1]])
    Ry_pitch = np.array([
        [ np.cos(pitch), 0, np.sin(pitch)],
        [             0, 1,             0],
        [-np.sin(pitch), 0, np.cos(pitch)]])
    Rx_roll = np.array([
        [1,            0,             0],
        [0, np.cos(roll), -np.sin(roll)],
        [0, np.sin(roll),  np.cos(roll)]])

    rotMat = Rz_yaw @ Ry_pitch @ Rx_roll
    return rotMat @ np.array([0,0,1])

And it can be called like this :

# assuming ob is the light object
roll = ob.rotation_euler.x
pitch = ob.rotation_euler.y
yaw = ob.rotation_euler.z
x,y,z = getCosinesFromEuler(roll,pitch,yaw)

And this point (x,y,z) needs to be subtracted from the position of the light object to get a point at unit distance on the ray.