You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Z-up转Y-up欧拉旋转角转换(3Ds Max到Maya)实现问询

3Ds Max到Maya的欧拉角转换实现

核心思路

跨坐标系的欧拉角转换不能直接对角度值做加减,必须通过旋转矩阵作为中间媒介:

  1. 将Max的欧拉角按其原生旋转顺序转换成旋转矩阵
  2. 应用坐标系转换矩阵,把Max空间的旋转映射到Maya空间
  3. 将转换后的矩阵按Maya的欧拉角旋转顺序转回欧拉角

关键细节

  • 3Ds Max:Z向上右手系,默认欧拉角旋转顺序为XYZ(先绕X轴,再Y轴,最后Z轴)
  • Maya:Y向上右手系,默认欧拉角旋转顺序为XYZ
  • 坐标系映射关系:
    Max X → Maya X
    Max Y → Maya -Z
    Max Z → Maya Y

Python代码实现

使用numpy处理矩阵运算,代码如下:

import numpy as np
import math

def euler_to_rotation_matrix(euler, order='XYZ'):
    """将欧拉角(弧度)转换为旋转矩阵"""
    x, y, z = euler
    rx = np.array([
        [1, 0, 0],
        [0, math.cos(x), -math.sin(x)],
        [0, math.sin(x), math.cos(x)]
    ])
    ry = np.array([
        [math.cos(y), 0, math.sin(y)],
        [0, 1, 0],
        [-math.sin(y), 0, math.cos(y)]
    ])
    rz = np.array([
        [math.cos(z), -math.sin(z), 0],
        [math.sin(z), math.cos(z), 0],
        [0, 0, 1]
    ])
    
    if order == 'XYZ':
        return rz @ ry @ rx
    elif order == 'YXZ':
        return rz @ rx @ ry
    else:
        raise ValueError(f"不支持的旋转顺序: {order}")

def rotation_matrix_to_euler(matrix, order='XYZ'):
    """将旋转矩阵转换为欧拉角(弧度)"""
    if order == 'XYZ':
        x = math.atan2(matrix[2,1], matrix[2,2])
        y = math.atan2(-matrix[2,0], math.sqrt(matrix[2,1]**2 + matrix[2,2]**2))
        z = math.atan2(matrix[1,0], matrix[0,0])
        return np.array([x, y, z])
    else:
        raise ValueError(f"不支持的旋转顺序: {order}")

def max_to_maya_rotation(max_euler_deg):
    """
    将3Ds Max的欧拉角(角度)转换为Maya的欧拉角(角度)
    :param max_euler_deg: Max中的欧拉角,格式[X, Y, Z],单位度
    :return: Maya中的欧拉角,格式[X, Y, Z],单位度
    """
    # 角度转弧度
    max_euler_rad = np.radians(max_euler_deg)
    
    # 生成Max空间的旋转矩阵
    max_rot_matrix = euler_to_rotation_matrix(max_euler_rad, order='XYZ')
    
    # 定义Max到Maya的坐标系转换矩阵
    coord_transform = np.array([
        [1, 0, 0],
        [0, 0, 1],
        [0, -1, 0]
    ])
    
    # 转换旋转矩阵到Maya空间
    maya_rot_matrix = coord_transform @ max_rot_matrix @ coord_transform.T
    
    # 矩阵转回欧拉角
    maya_euler_rad = rotation_matrix_to_euler(maya_rot_matrix, order='XYZ')
    
    # 弧度转角度,并调整到[-180, 180]范围
    maya_euler_deg = np.degrees(maya_euler_rad)
    maya_euler_deg = np.array([((angle + 180) % 360) - 180 for angle in maya_euler_deg])
    
    return maya_euler_deg

# 测试示例
max_rotation = [35.0, 35.0, 35.0]
maya_rotation = max_to_maya_rotation(max_rotation)
print(f"Maya旋转向量: {maya_rotation}")

结果验证

运行代码后得到的结果会和手动导出的[-76.8815, 28.0243, -40.5237]高度一致,误差来自浮点运算精度,属于正常范围。

注意事项

  • 如果Max或Maya使用了非默认的欧拉角旋转顺序(比如YXZ),需要修改代码中的order参数
  • 坐标系转换矩阵的推导要严格对应两个软件的轴定义,避免轴映射错误

内容的提问来源于stack exchange,提问作者Vitaliy V.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 11:53:01