1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| from omni.isaac.core.articulations import Articulation from omni.isaac.core.utils.stage import add_reference_to_stage import numpy as np
class DriverController: """驾驶员动画控制器""" def __init__(self, metahuman_path): """ Args: metahuman_path: Metahuman 资产路径 """ add_reference_to_stage(metahuman_path, "/World/Driver") self.driver = Articulation(prim_path="/World/Driver") self.joints = { 'head': 'Head', 'neck': 'Neck', 'spine': 'Spine', 'left_shoulder': 'LeftArm/LeftShoulder', 'right_shoulder': 'RightArm/RightShoulder', 'left_elbow': 'LeftArm/LeftForeArm/LeftElbow', 'right_elbow': 'RightArm/RightForeArm/RightElbow' } def apply_fatigue_pose(self, intensity): """ 应用疲劳姿态 Args: intensity: 疲劳强度 (0.0-1.0) """ head_pitch = -30.0 * intensity self.driver.set_joint_positions( positions=np.array([head_pitch]), joint_indices=[self.joints['head']] ) neck_pitch = -15.0 * intensity self.driver.set_joint_positions( positions=np.array([neck_pitch]), joint_indices=[self.joints['neck']] ) spine_pitch = -10.0 * intensity self.driver.set_joint_positions( positions=np.array([spine_pitch]), joint_indices=[self.joints['spine']] ) def apply_distraction_pose(self, distraction_type): """ 应用分心姿态 Args: distraction_type: 'phone_left' | 'phone_right' | 'radio' | 'rear' """ poses = { 'phone_left': { 'left_shoulder': (-20, -60, -30), 'left_elbow': (-90, 0, 0), 'head': (0, 20, -40) }, 'phone_right': { 'right_shoulder': (-20, 60, 30), 'right_elbow': (-90, 0, 0), 'head': (0, 20, 40) }, 'radio': { 'right_shoulder': (0, 45, 0), 'right_elbow': (-45, 0, 0), 'head': (0, -30, 20) }, 'rear': { 'spine': (0, 45, 0), 'head': (0, 60, 0) } } pose = poses.get(distraction_type, {}) for joint_name, rotation in pose.items(): self.driver.set_joint_positions( positions=np.array(rotation), joint_indices=[self.joints[joint_name]] )
|