syntax = "proto3";

package MujocoMessage;

service GrpcService {
  // 全局控制
  rpc SetSimulationState (SetSimulationStateRequest) returns (SetSimulationStateResponse);
  rpc LoadInitialFrame (LoadInitialFrameRequest) returns (LoadInitialFrameResponse);
  rpc LoadKeyFrame (LoadKeyFrameRequest) returns (LoadKeyFrameResponse);
  rpc UpdateLocalEnv (UpdateLocalEnvRequest) returns (UpdateLocalEnvResponse);
  rpc LoadLocalEnv (LoadLocalEnvRequest) returns (LoadLocalEnvResponse);
  rpc LoadContentFile (LoadContentFileRequest) returns (LoadContentFileResponse);

  // 场景控制
  rpc AddActor (AddActorRequest) returns (AddActorResponse);
  rpc PublishScene (PublishSceneRequest) returns (PublishSceneResponse);
  rpc SetLightInfo (SetLightInfoRequest) returns (SetLightInfoResponse);
  rpc SetCameraSensorInfo (SetCameraSensorInfoRequest) returns (SetCameraSensorInfoResponse);
  rpc MakeCameraViewportActive (MakeCameraViewportActiveRequest) returns (MakeCameraViewportActiveResponse);
  rpc SetMaterialInfo (SetMaterialInfoRequest) returns (SetMaterialInfoResponse);
  rpc BeginSaveMp4File(BeginSaveMp4FileRequest) returns (BeginSaveMp4FileResponse);
  rpc StopSaveMp4File(StopSaveMp4FileRequest) returns (StopSaveMp4FileResponse);
  rpc GetCurrentFrameIndex(GetCurrentFrameIndexRequest) returns (GetCurrentFrameIndexResponse);
  rpc GetTimeStamp(GetTimeStampRequest) returns (GetTimeStampResponse);
  rpc GetCameraFramePNG(GetCameraFramePNGRequest) returns (GetCameraFramePNGResponse);

  // 键鼠操作
  rpc GetKeyPressedEvents (GetKeyPressedEventsRequest) returns (GetKeyPressedEventsResponse);
  rpc GetMouseMovementEvents (GetMouseMovementEventsRequest) returns (GetMouseMovementEventsResponse);
  rpc GetBodyManipulationAnchored (GetBodyManipulationAnchoredRequest) returns (GetBodyManipulationAnchoredResponse);
  rpc GetBodyManipulationMovement (GetBodyManipulationMovementRequest) returns (GetBodyManipulationMovementResponse);

  // 动画控制
  rpc SetActorAnimParamNumber (SetActorAnimParamNumberRequest) returns (SetActorAnimParamNumberResponse);
  rpc SetActorAnimParamBool (SetActorAnimParamBoolRequest) returns (SetActorAnimParamBoolResponse);
  rpc SetActorAnimParamString (SetActorAnimParamStringRequest) returns (SetActorAnimParamStringResponse);


  // 配置查询
  rpc QueryModelInfo (QueryModelInfoRequest) returns (QueryModelInfoResponse);
  rpc QueryOptConfig (QueryOptConfigRequest) returns (QueryOptConfigResponse);

  // 配置设置
  rpc SetOptTimestep (SetOptTimestepRequest) returns (SetOptTimestepResponse);
  rpc SetOptConfig (SetOptConfigRequest) returns (SetOptConfigResponse);

  // Model 查询
  rpc QueryAllBodies (QueryAllBodiesRequest) returns (QueryAllBodiesResponse);
  rpc QueryAllJoints (QueryAllJointsRequest) returns (QueryAllJointsResponse);
  rpc QueryAllActuators (QueryAllActuatorsRequest) returns (QueryAllActuatorsResponse);
  rpc QueryAllGeoms (QueryAllGeomsRequest) returns (QueryAllGeomsResponse);
  rpc QueryAllMocapBodies (QueryAllMocapBodiesRequest) returns (QueryAllMocapBodiesResponse);
  rpc QueryAllEqualityConstraints (QueryAllEqualityConstraintsRequest) returns (QueryAllEqualityConstraintsResponse);
  rpc QueryAllSites (QueryAllSitesRequest) returns (QueryAllSitesResponse);

  // Data 查询
  rpc QueryAllQposQvelQacc(QueryAllQposQvelQaccRequest) returns (QueryAllQposQvelQaccResponse);
  rpc QueryContact (QueryContactRequest) returns (QueryContactResponse);
  rpc QueryContactSimple (QueryContactSimpleRequest) returns (QueryContactSimpleResponse);
  rpc QueryQfrcInverse (QueryQfrcInverseRequest) returns (QueryQfrcInverseResponse);
  rpc QueryActuatorMoment (QueryActuatorMomentRequest) returns (QueryActuatorMomentResponse);
  rpc QueryQfrcActuator (QueryQfrcActuatorRequest) returns (QueryQfrcActuatorResponse);  
  rpc QueryCfrcExt (QueryCfrcExtRequest) returns (QueryCfrcExtResponse);
  rpc QueryActuatorForce (QueryActuatorForceRequest) returns (QueryActuatorForceResponse);
  rpc QueryBodyVelocities (QueryBodyVelocitiesRequest) returns (QueryBodyVelocitiesResponse);
  rpc QueryQfrcBias(QueryQfrcBiasRequest) returns (QueryQfrcBiasResponse);
  rpc QuerySubtreeCom(QuerySubtreeComRequest) returns (QuerySubtreeComResponse);
  rpc QuerySensorData (QuerySensorDataRequest) returns (QuerySensorDataResponse);

  // 全量数据覆盖写入
  rpc SetQpos (SetQposRequest) returns (SetQposResponse);
  rpc SetQacc (SetQaccRequest) returns (SetQaccResponse);
  rpc SetCtrl (SetCtrlRequest) returns (SetCtrlResponse);
  rpc SetQvel (SetQvelRequest) returns (SetQvelResponse);

  // 元素查询
  rpc QueryJointNames (QueryJointNamesRequest) returns (QueryJointNamesResponse);
  rpc QueryJointDofadr (QueryJointDofadrRequest) returns (QueryJointDofadrResponse);  
  rpc QueryChildBody (QueryChildBodyRequest) returns (QueryChildBodyResponse);
  rpc QueryBodyQpos (QueryBodyQposRequest) returns (QueryBodyQposResponse);
  rpc QueryBodyQvel (QueryBodyQvelRequest) returns (QueryBodyQvelResponse);
  rpc QueryJointQpos (QueryJointQposRequest) returns (QueryJointQposResponse);
  rpc QueryJointQvel (QueryJointQvelRequest) returns (QueryJointQvelResponse);
  rpc QueryBodySubtreeMassByName (QueryBodySubtreeMassByNameRequest) returns (QueryBodySubtreeMassByNameResponse);
  rpc QueryJointLimits (QueryJointLimitsRequest) returns (QueryJointLimitsResponse);
  rpc QueryActuatorGainPrm (QueryActuatorGainPrmRequest) returns (QueryActuatorGainPrmResponse);
  rpc QueryActuatorBiasPrm (QueryActuatorBiasPrmRequest) returns (QueryActuatorBiasPrmResponse);
  rpc QuerySitePosAndMat (QuerySitePosAndMatRequest) returns (QuerySitePosAndMatResponse);
  rpc QuerySiteJac (QuerySiteJacRequest) returns (QuerySiteJacResponse);
  rpc QueryBodyComPosMat (QueryBodyComPosMatRequest) returns (QueryBodyComPosMatResponse);
  rpc QueryBodyPosMatQuat (QueryBodyPosMatQuatRequest) returns (QueryBodyPosMatQuatResponse);
  rpc QueryGeomPosMat (QueryGeomPosMatRequest) returns (QueryGeomPosMatResponse);
  rpc QueryContactForce(QueryContactForceRequest) returns (QueryContactForceResponse);
  rpc QueryJointOffsets (QueryJointOffsetsRequest) returns (QueryJointOffsetsResponse);

  // 元素设置
  rpc SetControlInput (SetControlInputRequest) returns (SetControlInputResponse);
  rpc SetJointQpos (SetJointQposRequest) returns (SetJointQposResponse);
  rpc SetActuatorGainPrm (SetActuatorGainPrmRequest) returns (SetActuatorGainPrmResponse);
  rpc SetActuatorBiasPrm (SetActuatorBiasPrmRequest) returns (SetActuatorBiasPrmResponse);
  rpc QueryMocapPosAndQuat (QueryMocapPosAndQuatRequest) returns (QueryMocapPosAndQuatResponse);
  rpc SetMocapPosAndQuat (SetMocapPosAndQuatRequest) returns (SetMocapPosAndQuatResponse);
  rpc UpdateEqualityConstraints (UpdateEqualityConstraintsRequest) returns (UpdateEqualityConstraintsResponse);
  rpc SetGeomFriction(SetGeomFrictionRequest) returns (SetGeomFrictionResponse);

  // 动力学计算
  rpc MJ_Forward (MJ_ForwardRequest) returns (MJ_ForwardResponse);
  rpc MJ_Inverse (MJ_InverseRequest) returns (MJ_InverseResponse);
  rpc MJ_Step (MJ_StepRequest) returns (MJ_StepResponse);
  rpc CalculateStateDifference (CalculateStateDifferenceRequest) returns (CalculateStateDifferenceResponse);
  rpc MJ_DifferentiatePos (DifferentiatePosRequest) returns (DifferentiatePosResponse);
  rpc MJD_TransitionFD (TransitionFDRequest) returns (TransitionFDResponse);
  rpc MJ_JacSubtreeCom (JacSubtreeComRequest) returns (JacSubtreeComResponse);
  rpc MJ_JacBodyCom (JacBodyComRequest) returns (JacBodyComResponse);  
  rpc MJ_Jac(MJ_JacRequest) returns (MJ_JacResponse);
  rpc CalcFullMassMatrix(CalcFullMassMatrixRequest) returns (CalcFullMassMatrixResponse); // 计算全局的质量矩阵，不只包含机器人本体，还有其他有关节的物品
}

enum SimulationState {
  RUNNING = 0;
  PAUSED = 1;
}

message SetSimulationStateRequest {
  SimulationState state = 1;
}

message SetSimulationStateResponse {}

message QueryModelInfoRequest {}

message QueryModelInfoResponse {
  int32 nq = 1;
  int32 nv = 2;
  int32 nu = 3;
  int32 nbody = 4;
  int32 njnt = 5;
  int32 ngeom = 6;
  int32 nsite = 7;
  int32 nmesh = 8;
  int32 ncam = 9;
  int32 nlight = 10;
  int32 nuser_body = 11;
  int32 nuser_jnt = 12;
  int32 nuser_geom = 13;
  int32 nuser_site = 14;
  int32 nuser_tendon = 15;
  int32 nuser_actuator = 16;
  int32 nuser_sensor = 17;
}

message QueryOptConfigRequest {}

message QueryOptConfigResponse {
    double timestep = 1;
    double apirate = 2;
    double impratio = 3;
    double tolerance = 4;
    double ls_tolerance = 5;
    double noslip_tolerance = 6;
    double ccd_tolerance = 7;
    repeated double gravity = 8;
    repeated double wind = 9;
    repeated double magnetic = 10;
    double density = 11;
    double viscosity = 12;
    double o_margin = 13;
    repeated double o_solref = 14;
    repeated double o_solimp = 15;
    repeated double o_friction = 16;
    int32 integrator = 17;
    int32 cone = 18;
    int32 jacobian = 19;
    int32 solver = 20;
    int32 iterations = 21;
    int32 ls_iterations = 22;
    int32 noslip_iterations = 23;
    int32 ccd_iterations = 24;
    int32 disableflags = 25;
    int32 enableflags = 26;
    int32 disableactuator = 27;
    int32 sdf_initpoints = 28;
    int32 sdf_iterations = 29;
}

message SetOptConfigRequest {
    double timestep = 1;
    double apirate = 2;
    double impratio = 3;
    double tolerance = 4;
    double ls_tolerance = 5;
    double noslip_tolerance = 6;
    double ccd_tolerance = 7;
    repeated double gravity = 8;
    repeated double wind = 9;
    repeated double magnetic = 10;
    double density = 11;
    double viscosity = 12;
    double o_margin = 13;
    repeated double o_solref = 14;
    repeated double o_solimp = 15;
    repeated double o_friction = 16;
    int32 integrator = 17;
    int32 cone = 18;
    int32 jacobian = 19;
    int32 solver = 20;
    int32 iterations = 21;
    int32 ls_iterations = 22;
    int32 noslip_iterations = 23;
    int32 ccd_iterations = 24;
    int32 disableflags = 25;
    int32 enableflags = 26;
    int32 disableactuator = 27;
    int32 sdf_initpoints = 28;
    int32 sdf_iterations = 29;
}

message SetOptConfigResponse {}

message QueryAllBodiesRequest {}

message QueryAllBodiesResponse {
    message BodyInfo {
        string name = 1;
        int32 id = 2;
        int32 parent_id = 3;
        int32 root_id = 4;
        int32 weld_id = 5;
        int32 mocap_id = 6;
        int32 jnt_num = 7;
        int32 jnt_adr = 8;
        int32 dof_num = 9;
        int32 dof_adr = 10;
        int32 tree_id = 11;
        int32 geom_num = 12;
        int32 geom_adr = 13;
        bool simple = 14;
        bool same_frame = 15;
        repeated double pos = 16;
        repeated double quat = 17;
        repeated double ipos = 18;
        repeated double iquat = 19;
        double mass = 20;
        double subtree_mass = 21;
        repeated double inertia = 22;
        repeated double inv_weight = 23;
        double grav_comp = 24;
        double margin = 25;
    }
    repeated BodyInfo body_info = 1;
}

message QueryAllJointsRequest {}

message QueryAllJointsResponse {
  message JointInfo {
    string name = 1;
    int32 id = 2;
    int32 body_id = 3;
    int32 type = 4;
    repeated double range = 5;
    int32 qpos_idx_start = 6;
    int32 qvel_idx_start = 7;
    int32 group = 8;
    bool limited = 9;
    bool actfrclimited = 10;
    repeated double solref = 11;
    repeated double solimp = 12;
    repeated double pos = 13;
    repeated double axis = 14;
    double stiffness = 15;
    repeated double actfrcrange = 16;
    double margin = 17;
  }
  repeated JointInfo joint_info = 1;
}

message QueryJointNamesRequest {}
message QueryJointNamesResponse {
  repeated string JointNames = 1;
}

message QueryJointDofadrRequest {
  repeated string JointNames = 1;
}
message QueryJointDofadrResponse {
  repeated int32 JointDofadrs = 1;
}

message QueryChildBodyRequest {
  string ParentBodyName = 1;
}

message QueryChildBodyResponse {
  repeated string ChildrenBodyName = 1;
}

message QueryBodyQposRequest {
  repeated string BodyNameList = 1;
}

message JointQpos {
  string JointName = 1;
  repeated double Qpos = 2;
}

message BodyQpos {
  string BodyName = 1;
  repeated JointQpos Joints = 2;
}

message QueryBodyQposResponse {
  repeated BodyQpos BodyQposList = 1;
}

message QueryBodyQvelRequest {
  repeated string BodyNameList = 1;
}

message JointQvel {
  string JointName = 1;
  repeated double Qvel = 2;
}

message BodyQvel {
  string BodyName = 1;
  repeated JointQvel Joints = 2;
}

message QueryBodyQvelResponse {
  repeated BodyQvel BodyQvelList = 1;
}

message SetControlInputRequest {
  message ActuatorControl {
    string ActuatorName = 1;
    double ControlInput = 2;
  }
  repeated ActuatorControl Controls = 1;
}

message SetControlInputResponse {
  message ActuatorResult {
    string ActuatorName = 1;
    bool Success = 2;
  }
  repeated ActuatorResult Results = 1;
}

message LoadInitialFrameRequest {}

message LoadInitialFrameResponse {}

message LoadKeyFrameRequest {
  string KeyFrameName = 1;
}

message LoadKeyFrameResponse {
  bool success = 1;
}

message QueryAllActuatorsRequest {}

message QueryAllActuatorsResponse {
    message ActuatorData {
        string ActuatorName = 1;
        string JointName = 2;
        double GearRatio = 3;
        repeated int32 actuator_trnid = 4;
        bool actuator_ctrllimited = 5;
        bool actuator_forcelimited = 6;
        bool actuator_actlimited = 7;
        repeated double actuator_ctrlrange = 8;
        repeated double actuator_forcerange = 9;
        repeated double actuator_actrange = 10;
        int32 actuator_trntype = 11;
        int32 actuator_dyntype = 12;
        int32 actuator_gaintype = 13;
        int32 actuator_biastype = 14;
        int32 actuator_actadr = 15;
        int32 actuator_actnum = 16;
        int32 actuator_group = 17;
        repeated double actuator_dynprm = 18;
        repeated double actuator_gainprm = 19;
        repeated double actuator_biasprm = 20;
        bool actuator_actearly = 21;
        repeated double actuator_gear = 22;
        double actuator_cranklength = 23;
        double actuator_acc0 = 24;
        double actuator_length0 = 25;
        repeated double actuator_lengthrange = 26;
    }

    repeated ActuatorData ActuatorDataList = 1;
}

message QueryAllGeomsRequest {}

message QueryAllGeomsResponse {
    message GeomData {
        string geom_name = 1;
        string body_name = 2;
        int32 geom_type = 3;
        int32 geom_contype = 4;
        int32 geom_conaffinity = 5;
        int32 geom_condim = 6;
        double geom_solmix = 7;
        repeated double geom_solref = 8;
        repeated double geom_solimp = 9;
        repeated double geom_size = 10;
        repeated double geom_friction = 11;
        int32 geom_dataid = 12;
        int32 geom_matid = 13;
        int32 geom_group = 14;
        int32 geom_priority = 15;
        int32 geom_plugin = 16;
        bool geom_sameframe = 17;
        repeated double geom_pos = 18;
        repeated double geom_quat = 19;
        double geom_margin = 20;
        double geom_gap = 21;
    }

    repeated GeomData geom_data_list = 1;
}


message QueryJointQposRequest {
  repeated string JointNameList = 1;
}

message QueryJointQposResponse {
  repeated JointQpos JointQposList = 1;
}

message QueryJointQvelRequest {
  repeated string JointNameList = 1;
}

message QueryJointQvelResponse {
  repeated JointQvel JointQvelList = 1;
}

message CalculateStateDifferenceRequest {
  repeated string JointNames = 1;
  repeated double InitialQpos = 2;
}

message StateDifference {
  string JointName = 1;
  repeated double Dq = 2;
  repeated double Qvel = 3;
}

message CalculateStateDifferenceResponse {
  repeated StateDifference StateDiffList = 1;
}

message DifferentiatePosRequest {
  repeated double InitialQpos = 1;
  repeated double Qpos = 2;
}

message DifferentiatePosResponse {
  repeated double Dq = 1;
}

message TransitionFDRequest {
  double Epsilon = 1;
  bool FlgCentered = 2;
}

message TransitionFDResponse {
  int32 nv = 1;
  int32 nu = 2;
  repeated double A = 3;
  repeated double B = 4;
}

message JacSubtreeComRequest {
  string BodyName = 1;
}

message JacSubtreeComResponse {
  repeated double JacCom = 1;
}

message JacBodyComRequest {
  string BodyName = 1;
}

message JacBodyComResponse {
  repeated double JacP = 1;
  repeated double JacR = 2;
}

message QueryAllQposQvelQaccRequest {
}

message QueryAllQposQvelQaccResponse {
    repeated double qpos = 1;  // 返回的 qpos 值
    repeated double qvel = 2;  // 返回的 qvel 值
    repeated double qacc = 3;  // 返回的 qacc 值
}

message QueryContactRequest {}

message QueryContactResponse {
    message ContactData {
        double dist = 1;
        repeated double pos = 2;
        repeated double frame = 3;
        double includemargin = 4;
        repeated double friction = 5;
        repeated double solref = 6;
        repeated double solreffriction = 7;
        repeated double solimp = 8;
        double mu = 9;
        repeated double H = 10;
        int32 dim = 11;
        int32 geom1 = 12;
        int32 geom2 = 13;
        repeated int32 geom = 14;
        repeated int32 flex = 15;
        repeated int32 elem = 16;
        repeated int32 vert = 17;
        int32 exclude = 18;
        int32 efc_address = 19;
    }

    repeated ContactData contacts = 1;
}

message QueryContactSimpleRequest {}

message QueryContactSimpleResponse {
    message ContactData {
        int32 dim = 1;
        int32 geom1 = 2;
        int32 geom2 = 3;
    }

    repeated ContactData contacts = 1;
}

message QueryQfrcInverseRequest {}

message QueryQfrcInverseResponse {
  repeated double qfrc_inverse = 1;
}

message QueryActuatorMomentRequest {}

message QueryActuatorMomentResponse {
  repeated double actuator_moment = 1;
  int32 nv = 2;
  int32 nu = 3;
}

message QueryQfrcActuatorRequest {}

message QueryQfrcActuatorResponse {
  repeated double qfrc_actuator = 1;
}

message SetQposRequest {
    repeated double qpos = 1;
}

message SetQposResponse {}

message SetQaccRequest {
    repeated double qacc = 1;
}

message SetQaccResponse {}

message QueryBodySubtreeMassByNameRequest {
  string body_name = 1;
}

message QueryBodySubtreeMassByNameResponse {
  double body_subtreemass = 1;
}

message SetOptTimestepRequest {
    double timestep = 1;
}

message SetOptTimestepResponse {}

message SetCtrlRequest {
    repeated double ctrl = 1;
}

message SetCtrlResponse {}

message MJ_ForwardRequest {}

message MJ_ForwardResponse {}

message MJ_InverseRequest {}

message MJ_InverseResponse {}

message MJ_StepRequest {
    int32 nstep = 1;  // 需要模拟的步数
}

message MJ_StepResponse {}

message SetQvelRequest {
    repeated double qvel = 1;  // 关节速度数组
}

message SetQvelResponse {}

message QueryCfrcExtRequest {
    repeated string body_names = 1;  // 要查询的身体部件的名字列表
}

message QueryCfrcExtResponse {
    repeated BodyCfrcExt body_cfrc_exts = 1;  // 每个身体部件的外部接触力矩
    bool success = 2;                         // 操作是否成功
}

message BodyCfrcExt {
    string body_name = 1;  // 身体部件名字
    repeated double cfrc_ext = 2;  // 外部接触力矩，长度为6
}

message SetJointQposRequest {
  repeated JointQpos joint_qpos_list = 1;
}

message SetJointQposResponse {
  bool success = 1;
}

message QueryActuatorForceRequest {}

message QueryActuatorForceResponse {
  repeated double actuator_force = 1;
}

message QueryJointLimitsRequest {
    repeated string joint_names = 1; // 需要查询的关节名字列表
}

message JointLimit {
    string joint_name = 1; // 关节名字
    bool has_limit = 2;    // 是否有位置限制
    double range_min = 3;  // 位置限制最小值
    double range_max = 4;  // 位置限制最大值
}

message QueryJointLimitsResponse {
    repeated JointLimit joint_limits = 1; // 关节限制列表
}

// 添加查询 body 线速度和角速度的接口
message QueryBodyVelocitiesRequest {
    repeated string body_names = 1;
}

message QueryBodyVelocitiesResponse {
    message BodyVelocity {
        string body_name = 1;
        repeated double linear_velocity = 2;
        repeated double angular_velocity = 3;
    }
    repeated BodyVelocity body_velocities = 1;
}

// QueryActuatorGainPrm
message QueryActuatorGainPrmRequest {
    repeated string actuator_names = 1; // 要查询的actuator名称列表
}

message ActuatorGainPrm {
    string actuator_name = 1;
    repeated double gain_prm = 2;
}

message QueryActuatorGainPrmResponse {
    repeated ActuatorGainPrm gain_prm_list = 1;
}

// SetActuatorGainPrm
message SetActuatorGainPrmRequest {
    message ActuatorGainPrmSet {
        string actuator_name = 1;
        repeated double gain_prm = 2;
    }
    repeated ActuatorGainPrmSet gain_prm_set_list = 1;
}

message SetActuatorGainPrmResponse {
    bool success = 1;
}

// QueryActuatorBiasPrm
message QueryActuatorBiasPrmRequest {
    repeated string actuator_names = 1; // 要查询的actuator名称列表
}

message ActuatorBiasPrm {
    string actuator_name = 1;
    repeated double bias_prm = 2;
}

message QueryActuatorBiasPrmResponse {
    repeated ActuatorBiasPrm bias_prm_list = 1;
}

// SetActuatorBiasPrm
message SetActuatorBiasPrmRequest {
    message ActuatorBiasPrmSet {
        string actuator_name = 1;
        repeated double bias_prm = 2;
    }
    repeated ActuatorBiasPrmSet bias_prm_set_list = 1;
}

message SetActuatorBiasPrmResponse {
    bool success = 1;
}

// 查询所有 mocap body 
message QueryAllMocapBodiesRequest {}
message QueryAllMocapBodiesResponse {
    message MocapBodyInfo {
        string mocap_body_name = 1;
        int32 mocap_body_id = 2;
    }
    repeated  MocapBodyInfo mocap_bodies = 1;
}

// 查询 mocap body 的位置和方向
message QueryMocapPosAndQuatRequest {
    repeated string mocap_body_names = 1;
}
message QueryMocapPosAndQuatResponse {
    message MocapBodyInfo {
        string mocap_body_name = 1;
        repeated double pos = 2;
        repeated double quat = 3;
    }
    repeated MocapBodyInfo mocap_body_info = 1;
}

// 设置 mocap body 的位置和方向
message SetMocapPosAndQuatRequest {
    message MocapBodyInfo {
        string mocap_body_name = 1;
        repeated double pos = 2;
        repeated double quat = 3;
    }
    repeated MocapBodyInfo mocap_body_info = 1;
}
message SetMocapPosAndQuatResponse {
    repeated bool success = 1;
} 

// 查询所有 equality 约束信息
message QueryAllEqualityConstraintsRequest {}
message QueryAllEqualityConstraintsResponse {
    message EqualityConstraintInfo {
        int32 eq_type = 1;
        int32 obj1_id = 2;
        int32 obj2_id = 3;
        bool active = 4;
        repeated double solref = 5;
        repeated double solimp = 6;
        repeated double data = 7;
    }
    repeated EqualityConstraintInfo equality_constraints = 1;
}

message QuerySitePosAndMatRequest {
    repeated string site_names = 1;
}

message QuerySitePosAndMatResponse {
    message SitePosAndMat {
        string site_name = 1;
        repeated double xpos = 2;
        repeated double xmat = 3;
    }  
    repeated SitePosAndMat site_pos_and_mat = 1;
}

// 查询多个 site 的 jacobian
message QuerySiteJacRequest {
    repeated string site_names = 1;
}

message QuerySiteJacResponse {
    message SiteJac {
        string site_name = 1;
        repeated double jacp = 2;
        repeated double jacr = 3;
    }
    repeated SiteJac site_jacs = 1;
}

message UpdateEqualityConstraintsRequest {
    message EqualityConstraintsInfo {
        int32 obj1_id = 1;
        int32 obj2_id = 2;
        repeated double data = 3;
    }
    repeated EqualityConstraintsInfo equality_constraints = 1;
}

message UpdateEqualityConstraintsResponse {
    bool success = 1;
}

message QueryBodyComPosMatRequest {
    repeated string body_name_list = 1; // 要查询的 body 名字列表
}

message QueryBodyComPosMatResponse {
    message BodyComPosMat {
        string body_name = 1;
        repeated double com_pos = 2;  // 质心位置 (3 elements)
        repeated double com_mat = 3;  // 惯性矩阵 (9 elements)
    }
    repeated BodyComPosMat body_com_pos_mat_list = 1;
}

message QueryBodyPosMatQuatRequest {
    repeated string body_name_list = 1; // 要查询的 body 名字列表
}

message QueryBodyPosMatQuatResponse {
    message BodyPosMatQuat {
        string body_name = 1;
        repeated double pos = 2;      // 位置 (3 elements)
        repeated double mat = 3;      // 旋转矩阵 (9 elements)
        repeated double quat = 4;     // 旋转四元数 (4 elements)
    }
    repeated BodyPosMatQuat body_pos_mat_quat_list = 1;
}

message QueryGeomPosMatRequest {
    repeated string geom_name_list = 1; // 要查询的 geom 名字列表
}

message QueryGeomPosMatResponse {
    message GeomPosMat {
        string geom_name = 1;
        repeated double pos = 2;      // 位置 (3 elements)
        repeated double mat = 3;      // 旋转矩阵 (9 elements)
    }
    repeated GeomPosMat geom_pos_mat_list = 1;
}

message QueryContactForceRequest {
    repeated int32 contact_ids = 1; // List of contact IDs to query
}

message QueryContactForceResponse {
    message ContactForce {
        int32 id = 1;  // Contact ID
        repeated double forces = 2;  // Forces array (3 for tangential forces and 3 for normal force)
    }
    repeated ContactForce contact_forces = 1;
}

message MJ_JacRequest {
    message BodyPoint {
        repeated double point = 1;  // The 3D point in the world frame
        int32 body = 2;             // The ID of the body
    }

    repeated BodyPoint body_point_list = 1;  // 一组 body 和 point 信息
    bool compute_jacp = 2;     // 是否计算平移分量
    bool compute_jacr = 3;     // 是否计算旋转分量
}

message MJ_JacResponse {
    message JacResult {
        repeated double jacp = 1;  // 平移分量
        repeated double jacr = 2;  // 旋转分量
    }

    repeated JacResult jac_results = 1;  // 一组结果
}

message CalcFullMassMatrixRequest {
}

message CalcFullMassMatrixResponse {
    repeated double full_mass_matrix = 1;  // 计算得出的全质量矩阵
}

message QueryQfrcBiasRequest {
}

message QueryQfrcBiasResponse {
    repeated double qfrc_bias = 1;  // 返回的 qfrc_bias 值
}

message QuerySubtreeComRequest {
    repeated string body_name_list = 1;  // 要查询的 body 名称列表
}

message QuerySubtreeComResponse {
    repeated string body_name_list = 1;  // 返回的 body 名称列表
    repeated double subtree_com = 2;      // 返回的 subtree_com 值
}

message SetGeomFrictionRequest {  
    repeated string geom_name_list = 1;
    repeated Friction friction_list = 2;  // 每个 friction 对应一个 geom_name

    message Friction {
        repeated double values = 1;  // 3个元素，分别是slide, spin, roll
    }
}

message SetGeomFrictionResponse {
    repeated bool success_list = 1;  // 每个 geom 的设置成功状态
}

message QuerySensorDataRequest {
    repeated string sensor_names = 1;  // 查询传感器名称列表
}

message QuerySensorDataResponse {
    message SensorData {
        string sensor_name = 1;  // 传感器名称
        string sensor_type = 2;  // 传感器类型
        repeated double sensor_value = 3;  // 当前传感器值
    }

    repeated SensorData sensor_data_list = 1;  // 包含所有传感器数据
}

message QueryJointOffsetsRequest {
    repeated string joint_names = 1;  // 一个关节名称数组
}

message QueryJointOffsetsResponse {
    message JointOffset {
        string joint_name = 1;
        int32 qpos_offset = 2;
        int32 qvel_offset = 3;
        int32 qacc_offset = 4;
    }

    repeated JointOffset joint_offsets = 1;  // 对应的关节偏移量数组
}

message QueryAllSitesRequest {}

message QueryAllSitesResponse {
    message SiteInfo {
        string name = 1;
        int32 id = 2;
        repeated double pos = 3;        // Site position in the global frame
        repeated double mat = 4;        // Site orientation matrix in the global frame
        int32 site_bodyid = 5;         // Body ID the site is attached to
        int32 site_type = 6;           // Geom type for rendering
        repeated double local_pos = 7;  // Local position offset relative to the body
        repeated double local_quat = 8; // Local orientation offset relative to the body
    }  
    repeated SiteInfo site_info = 1;
}

message UpdateLocalEnvRequest{
    repeated double qpos = 1;
    double time = 2;
}

message UpdateLocalEnvResponse{
    message OverrideCtrlInfo {
        int32 index = 1; // 控制输入索引
        double value = 2; // 控制输入值
    }
    repeated OverrideCtrlInfo override_ctrls = 1; // 覆盖的控制输入列表
}

message LoadLocalEnvRequest {
    enum ReqType {
        XML_FILE_NAME = 0;
        XML_FILE_CONTENT = 1;
    }
    ReqType req_type = 1;
}

message LoadLocalEnvResponse {
    string file_name = 1;   // 返回文件名
    bytes xml_content = 2; // 使用bytes类型存储文件内容
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 3; // 添加状态码字段
    string error_message = 4; // 错误详情（可选）
}

message LoadContentFileRequest {
    string file_name = 1;
    string file_dir = 2;   // 可选，如果为空表示使用默认xml临时路径，否则为指定路径
}

message LoadContentFileResponse {
    bytes content = 1; // 使用bytes类型存储文件内容
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 2; // 添加状态码字段
    string error_message = 3; // 错误详情（可选）
}

message AddActorRequest {
    string name = 1;              // Actor Entity 的名字
    string spawnable_name = 2;    // Actor 使用的 spawnable 名字
    repeated double pos = 3;      // 位置 (3 elements)
    repeated double quat = 4;     // 旋转四元数 (4 elements)
    double scale = 5;             // 等比缩放 (1 elements)
}
message AddActorResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 添加状态码字段
    string error_message = 2; // 错误详情（可选）
}

message PublishSceneRequest {}
message PublishSceneResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 状态码字段
    string error_message = 2; // 错误详情（可选）
}

message SetLightInfoRequest {
    string actor_name = 1;                  // Actor 名字
    repeated float light_color = 2;         // 灯光颜色 (3 elements)
    float light_intensity = 3;              // 灯光强度 (1 element)
}
message SetLightInfoResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 状态码字段
    string error_message = 2; // 错误详情（可选）
}

message SetCameraSensorInfoRequest {
    string actor_name = 1;                  // Actor 名字
    bool capture_rgb = 2;                   // 是否捕获 RGB 图像
    bool capture_depth = 3;                 // 是否捕获深度图像
    bool save_mp4_file = 4;                // 是否保存为 MP4 文件
    bool use_dds = 5;                     // 是否使用 DDS
}

message SetCameraSensorInfoResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 状态码字段
    string error_message = 2; // 错误详情（可选）
}

message BeginSaveMp4FileRequest {
  string file_path = 1; // 保存 MP4 文件的路径
  enum CaptureMode { //捕获相机帧的方式
    ASYNC = 0;
    SYNC = 1;
  }
  CaptureMode capture_mode = 2;
}

message BeginSaveMp4FileResponse {
  enum Status {
    SUCCESS = 0;
    ERROR = 1;
  }
  Status status = 1; // 状态码字段
  string error_message = 2; // 错误详情（可选）
}

message StopSaveMp4FileRequest {
    enum Status {
        SUCCESS = 0;
        FAILED = 1;
    }
    Status status = 1; // 状态码字段
}

message StopSaveMp4FileResponse {
  // 该请求不需要任何参数
}

message GetCurrentFrameIndexRequest
{
  // 该请求不需要任何参数
}

message GetCurrentFrameIndexResponse {
  int64 current_frame = 1;
  string error_message = 2;
}

message GetTimeStampRequest
{
  // 该请求不需要任何参数
  uint64 last_frame_index = 1; // 截止到哪个帧的时间戳
}

message TimeStampList {
  repeated uint64 time_stamps = 1; // 时间戳列表
}

message GetTimeStampResponse {
  map<string, TimeStampList> time_stamp_map = 1; // 时间戳，键为 Actor 名字，值为时间戳列表
  string error_message = 2; // 错误详情（可选）
}

message GetCameraFramePNGRequest
{
  string image_path = 1;
}

message NameAndTransform {
  string name = 1;
  repeated double pos = 2;
  repeated double quat = 3;
}

message GetCameraFramePNGResponse
{
  repeated NameAndTransform name_transform = 1;
}

message MakeCameraViewportActiveRequest {
    string actor_name = 1;                  // Actor 名字
    string entity_name = 2;                // Entity 名字
}
message MakeCameraViewportActiveResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 状态码字段
    string error_message = 2; // 错误详情（可选）
}

message SetMaterialInfoRequest {
    string actor_name = 1;                  // Actor 名字
    repeated float base_color = 4;          // 基础颜色 (4 elements)
}
message SetMaterialInfoResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 状态码字段
    string error_message = 2; // 错误详情（可选）
}

message GetKeyPressedEventsRequest {
    // 该请求不需要任何参数
}
message GetKeyPressedEventsResponse {
    repeated string events = 1;  // 按键事件列表
}


message GetMouseMovementEventsRequest {
    // 该请求不需要任何参数
}
message GetMouseMovementEventsResponse {
    float delta_x = 1;  // 鼠标在 x 轴上的移动距离
    float delta_y = 2;  // 鼠标在 y 轴上的移动距离
    float delta_z = 3;  // 鼠标在 z 轴上的移动距离（如果有）
}

message GetBodyManipulationAnchoredRequest {}

message GetBodyManipulationAnchoredResponse {
    enum AnchorType {
        NONE = 0; // 无锚定
        WELD = 1; // 焊接锚定
        BALL = 2;  // 球形锚定
    }
    string body_name = 1;  // 被锚定的 Body 名字
    AnchorType anchor_type = 2;  // 锚定类型
}

message GetBodyManipulationMovementRequest {}

message GetBodyManipulationMovementResponse {
    repeated double delta_pos = 1;  // Actor 在世界坐标系中的位置变化 (3 elements)
    repeated double delta_quat = 2; // Actor 在世界坐标系中的旋转变化 (4 elements)
}

message SetActorAnimParamNumberRequest {
    string actor_name = 1;
    string param_name = 2;
    double value = 3;
}

message SetActorAnimParamNumberResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 状态码字段
    string error_message = 2; // 错误详情（可选）
}

message SetActorAnimParamBoolRequest {
    string actor_name = 1;
    string param_name = 2;
    bool value = 3;
}

message SetActorAnimParamBoolResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 状态码字段
    string error_message = 2; // 错误详情（可选）
}

message SetActorAnimParamStringRequest {
    string actor_name = 1;
    string param_name = 2;
    string value = 3;
}

message SetActorAnimParamStringResponse {
    enum Status {
        SUCCESS = 0;
        ERROR = 1;
    }
    Status status = 1; // 状态码字段
    string error_message = 2; // 错误详情（可选）
}