[英]Get 3D point on directional light ray in Blender Python given Euler angles
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.我正在尝试在 Blender 3D 中获得太阳光的 3D 点,以便我可以使用它在三个 JS 中指定定向光目标 position。 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.请让我知道如何获得它。
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.在搅拌机中,由于单位向量从 z 轴开始(初始化时灯光指向下方),我认为您可以使用总旋转矩阵的最后一列。 The function for calculating the total rotation matrix is given here . 此处给出了用于计算总旋转矩阵的 function。 Here is a modification of the function that will return a point at unit distance in the direction of the light source:这是 function 的修改,它将在光源方向上返回一个单位距离的点:
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.而这个点(x,y,z)需要从光object的position中减去,得到射线上单位距离处的一个点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.