步骤
1.在内容浏览器中,
将Unreal/CarlaUE4/Content/Carla/Static/Car/4Wheeled/Tesla
复制到当前文件夹并重命名为BYD
,
将Unreal/CarlaUE4/Content/Carla/Blueprints/Vehicles/Tesla
复制到当前文件夹并重命名为BYD
。
2.添加车辆到蓝图库并测试。
- 在
内容(Content)/Carla/Blueprint/Vehicles
中,打开VehicleFactory
文件。 - 在 Generate Definitions 选项卡中,双击 Vehicles 。
- 在 细节(Details) 面板中,展开 默认值(Default Value) 部分并向车辆数组添加一个新元素。
- 填写您车辆的品牌 Make(BYD) 和型号 Model(seal) 。
- 使用您的
BP_<vehicle_name>
文件填写 Class 值(BP_BYDseal)。 - Number of Wheels 填
4
,Generation 填0
- 编译并保存。
测试代码:
python manual_control.py --filter vehicle.BYD.seal
python manual_control.py --filter vehicle.tesla.model3
如果车辆配置不对,生成玩家的代码一致返回为空:
self.player = self.world.try_spawn_actor(blueprint, spawn_point)
方法try_spawn_actor()
是从carla/PythonAPI/carla/source/libcarla/World.cpp
的.def("try_spawn_actor", SPAWN_ACTOR_WITHOUT_GIL(TrySpawnActor))
传递给 C++ 端的。
LibCarla的调用过程:
LibCarla/source/carla/client/World.cpp
SharedPtr<Actor> World::TrySpawnActor()
SharedPtr<Actor> World::SpawnActor()
LibCarla/source/carla/client/detail/Simulator.cpp
SharedPtr<Actor> Simulator::SpawnActor()
actor = _client.SpawnActor()
LibCarla/source/carla/client/detail/Client.cpp
rpc::Actor Client::SpawnActor()
_pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, transform);
auto CallAndWait(const std::string &function, Args && ... args)
auto object = RawCall(function, std::forward<Args>(args) ...);
auto RawCall(const std::string &function, Args && ... args)
return rpc_client.call(function, std::forward<Args>(args) ...);
LibCarla/source/carla/rpc/Client.h
auto call(const std::string &function, Args &&... args)
// 远程调用(_client里保存了IP地址和端口号)
return _client.call(function, Metadata::MakeSync(), std::forward<Args>(args)...);
CarlaUE4的调用过程:
Server/CarlaServer.cpp
auto Result = Episode->SpawnActorWithInfo(Transform, std::move(Description));
Game/CarlaEpisode.cpp
auto result = ActorDispatcher->SpawnActor(LocalTransform, thisActorDescription, DesiredId);
Actor/ActorDispatcher.cpp
// 在哪调用生成函数导致生成失败
FActorSpawnResult Result = SpawnFunctions[Description.UId - 1](Transform, Description);
// 这里的ActorFactory.SpawnActor函数似乎是ue4里的
void UActorDispatcher::Bind(ACarlaActorFactory &ActorFactory)
{
for (const auto &Definition : ActorFactory.GetDefinitions())
{
Bind(Definition, [&](const FTransform &Transform, const FActorDescription &Description) {
return ActorFactory.SpawnActor(Transform, Description);
});
}
}
新加内容的分析
Static 资产
新加的车辆静态资产位于Carla\Static\Car\4Wheeled\BYD
,包括:
* SM_sc_BYDseal.uasset (SMC_BYDseal.uasset) :静态网格(Static Mesh)
蓝图
新加的车辆蓝图位于Carla\Blueprints\Vehicles\BYD
,包括:
- BP_BYDseal.uasset :车辆蓝图
- BP_BYD_FLW.uasset :左前轮(Front Left Wheel)
- BP_BYD_FRW.uasset :右前轮(Front Right Wheel)
- BP_BYD_RLW.uasset :左后轮(Rear Left Wheel)
- BP_BYD_RRW.uasset : 右后轮(Rear Right Wheel)
问题
轮子不旋转
目录Carla\Static\Car\4Wheeled\BYD
下有两个动画蓝图,删除其中的一个并参考 8. 配置车辆蓝图 重新将动画蓝图 BYD_Animation
绑定到车辆蓝图Carla/Blueprints/Vehicles/{Vehicle_Name}/BP_BYDseal
。
参考
跟踪和解决spawn_actor指令引发的问题:UnknownError while spawning the actor