In this tutorial we describe how to manually control and animate the skeletons of walkers from the CARLA Python API. The reference of all classes and methods available can be found at Python API reference.
!!! note
This document assumes the user is familiar with the Python API.
The user should read the first steps tutorial before reading this document.
Core concepts.
All walkers have the same skeleton hierarchy and bone names. Below is an image of the skeleton hierarchy.
crl_root
└── crl_hips__C
├── crl_spine__C
│ └── crl_spine01__C
│ ├── ctrl_shoulder__L
│ │ └── crl_arm__L
│ │ └── crl_foreArm__L
│ │ └── crl_hand__L
│ │ ├── crl_handThumb__L
│ │ │ └── crl_handThumb01__L
│ │ │ └── crl_handThumb02__L
│ │ │ └── crl_handThumbEnd__L
│ │ ├── crl_handIndex__L
│ │ │ └── crl_handIndex01__L
│ │ │ └── crl_handIndex02__L
│ │ │ └── crl_handIndexEnd__L
│ │ ├── crl_handMiddle_L
│ │ │ └── crl_handMiddle01__L
│ │ │ └── crl_handMiddle02__L
│ │ │ └── crl_handMiddleEnd__L
│ │ ├── crl_handRing_L
│ │ │ └── crl_handRing01__L
│ │ │ └── crl_handRing02__L
│ │ │ └── crl_handRingEnd__L
│ │ └── crl_handPinky_L
│ │ └── crl_handPinky01__L
│ │ └── crl_handPinky02__L
│ │ └── crl_handPinkyEnd__L
│ ├── crl_neck__C
│ │ └── crl_Head__C
│ │ ├── crl_eye__L
│ │ └── crl_eye__R
│ └── crl_shoulder__R
│ └── crl_arm__R
│ └── crl_foreArm__R
│ └── crl_hand__R
│ ├── crl_handThumb__R
│ │ └── crl_handThumb01__R
│ │ └── crl_handThumb02__R
│ │ └── crl_handThumbEnd__R
│ ├── crl_handIndex__R
│ │ └── crl_handIndex01__R
│ │ └── crl_handIndex02__R
│ │ └── crl_handIndexEnd__R
│ ├── crl_handMiddle_R
│ │ └── crl_handMiddle01__R
│ │ └── crl_handMiddle02__R
│ │ └── crl_handMiddleEnd__R
│ ├── crl_handRing_R
│ │ └── crl_handRing01__R
│ │ └── crl_handRing02__R
│ │ └── crl_handRingEnd__R
│ └── crl_handPinky_R
│ └── crl_handPinky01__R
│ └── crl_handPinky02__R
│ └── crl_handPinkyEnd__R
├── crl_thigh__L
│ └── crl_leg__L
│ └── crl_foot__L
│ └── crl_toe__L
│ └── crl_toeEnd__L
└── crl_thigh__R
└── crl_leg__R
└── crl_foot__R
└── crl_toe__R
└── crl_toeEnd__R
Following is a detailed step-by-step example of how to change the bone transforms of a walker from the CARLA Python API
Import neccessary libraries used in this example
import carla
import random
Initialize the carla client
client = carla.Client('127.0.0.1', 2000)
client.set_timeout(2.0)
Spawn a random walker at one of the map's spawn points
world = client.get_world()
blueprint = random.choice(self.world.get_blueprint_library().filter('walker.*'))
spawn_points = world.get_map().get_spawn_points()
spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform()
world.try_spawn_actor(blueprint, spawn_point)
A walker's skeleton can be modified by passing an instance of the WalkerBoneControl class to the walker's apply_control function. The WalkerBoneControl class contains the transforms of the bones to be modified. Its bone_transforms member is a list of tuples of value pairs where the first value is the bone name and the second value is the bone transform. The apply_control function can be called on every tick to animate a walker's skeleton. The location and rotation of each transform is relative to its parent. Therefore when a parent bone's transform is modified, the transforms of the child bones in model space will also be changed relatively.
In the example below, the rotations of the walker's hands are set to be 90 degrees around the forward axis and the locations are set to the origin.
control = carla.WalkerBoneControl()
first_tuple = ('crl_hand__R', carla.Transform(rotation=carla.Rotation(roll=90)))
second_tuple = ('crl_hand__L', carla.Transform(rotation=carla.Rotation(roll=90)))
control.bone_transforms = [first_tuple, second_tuple]
world.player.apply_control(control)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。