RFUnivese Player 接口文档¶
Unity通用场景是一个不包含任何物体的Unity端空白场景,物体的创建和驱动皆通过python端发送消息实现。
创建的物体必须分配一个全局唯一的ID,后续驱动物体的操作通过该ID来进行区分,不同类型的消息通过不同的通道(channel)管理。
通过实例仿真环境打开Player窗口并调用所有接口:
from pyrfuniverse.envs import RFUniverseBaseEnv
env = RFUniverseBaseEnv(
executable_file='<player_path>',
scene_file='<scenedata_json_path>',
assets=assets_name_list,
game_object_channel=True,
rigidbody_channel=True,
articulation_channel=True,
...
)
- (str)executable_file:Player可执行文件路径
- (str)scene_file:需要加载的场景Json文件路径
- (list
)assets:需要预加载的物理名列表,通过InstanceObject接口实例化物体前需要预加载,非则会出现异步问题 - (bool)game_object_channel:开启gameobject消息通道
- (bool)rigidbody_channel:开启rigidbody消息通道
- (bool)articulation_channel:开启articulation消息通道
......
AssetChannel:¶
负责资源加载创建以及其他通用功能
支持的消息类型:
- PreLoadAssetsAsync:资源预加载,将所有使用的到资源预先加载,防止由于异步任务导致的报错。
通过RFUniverseBaseEnv的初始化参数assets传递所有使用到的资源名。 * LoadSceneAsync:加载通过RFUnivese Editer导出的场景JSON文件。
通过RFUniverseBaseEnv的初始化参数scene_file传递场景JSON文件路径。 * SendMessage:发送一个由字符串标识的事件
* (必要) (str)msg:消息标识 * SetLayerCollision:设置层间的碰撞开启或关闭 * (必要) (int) layer1:层1 * (必要) (int) layer2:层2 * (必要) (bool) ignore:忽略或不忽略碰撞 * InstanceObject:创建物体,并初始化。 * (必要) (stirng) name:资源名称 * (必要) (int) id:物体创建后赋予实例ID现有资源类型及名称:¶
- GameObjcet:静态模型
###### Base:
GameObject_Box
GameObject_Cylinder
GameObject_Sphere
GameObject_Quad
Collider_Box
###### IGbison环境:
Hainesburg_mesh_texture
Halfway_mesh_texture
Hallettsville_mesh_texture
Hambleton_mesh_texture
Hammon_mesh_texture
Hatfield_mesh_texture
Haxtun_mesh_texture
Haymarket_mesh_texture
Hendrix_mesh_texture
Hercules_mesh_texture
Highspire_mesh_texture
Hitchland_mesh_texture * Rigidbody:刚体
###### Base:
Rigidbody_Box
Rigidbody_Cylinder
Rigidbody_Sphere
###### 77个YCB数据集模型:
详见The YCB Object and Model Set * Controller:机械臂及关节体
###### Robots:
kinova_gen3_robotiq85
ur5_robotiq85
franka_panda
tobor_robotiq85_robotiq85
###### Other:
pen_and_pencap
handled_box,handled_drawer
Drawer1,Drawer2,Drawer3,Drawer4,Drawer5,Drawer6,Drawer7,Drawer8,Drawer9,Drawer10
InstanceChannel¶
是所有管理实例物体Channel的基类,实现了通用的消息类型
- SetTransform:修改局部空间 Position, Rotation, Scale
env.game_object_channel.set_action
(
'SetTransform',
id=123,
position=[0,0,0],
rotation=[0,0,0],
scale=[0,0,0]
)
-
SetRotationQuaternion:传入Quaternion修改局部空间 Rotation
* (必要) (int) id:物体实例ID * (list[4]) quaternion:局部坐标四元数旋转
SetActive:修改激活状态
* (必要) (int)id:物体实例ID * (必要) (bool)active:是否激活- SetParent:修改父物体
- SetLayer:修改物体层
- Destroy:销毁物体
GamebjectChannel¶
管理所有GameObjectAttr类型的实例物体
支持的消息类型:
- Translate:增量移动物体
- Rotate:增量旋转物体
- SetColor:修改物体基础颜色
RigidbodyChannel¶
管理所有RigidbodyAttr类型的实例物体
支持的消息类型:
- AddForce:为Rigidbody施加持续的力
- SetVelocity:修改Rigidbody速度
ArticulationChannel¶
管理所有BaseController类型的实例物体
支持的消息类型:
- SetTransform:效果为修改关节体根节点的局部空间Position,Rotation
- SetParent:由于关节体的特殊性,目前使用该方法需要等待一帧才能正确生效
- SetJointPosition:修改关节体内每个关节的目标位置
env.rigidbody_channel.set_action
(
'SetJointPosition',
id=123,
joint_positions=[],
speed_scales=[]
)
- SetJointPositionDirectly:直接修改关节体内每个关节的位置
CameraChannel¶
管理所有CameraAttr类型的实例物体
支持的消息类型:
- GetImage:获取相机渲染结果
- [3]>[n])rendering_params:需要获取图像的相机ID,宽,高
- SetMode:设置相机渲染模式
ObiClothChannel¶
管理所有ClothAttr类型的实例物体
ObiClothWithGraspingChannel¶
管理所有ClothWithGraspingAttr类型的实例物体
ObiSoftbodyChannel¶
管理所有SoftbodyAttr类型的实例物体
HumanDressingChannel¶
管理所有HumanDressingAttr类型的实例物体