зеркало из https://github.com/microsoft/AirSim.git
Merge pull request #4467 from SimtoReal/master
add meterial element index
This commit is contained in:
Коммит
19ac0f265e
|
@ -152,8 +152,8 @@ namespace airlib
|
|||
void simSetKinematics(const Kinematics::State& state, bool ignore_collision, const std::string& vehicle_name = "");
|
||||
msr::airlib::Environment::State simGetGroundTruthEnvironment(const std::string& vehicle_name = "") const;
|
||||
std::vector<std::string> simSwapTextures(const std::string& tags, int tex_id = 0, int component_id = 0, int material_id = 0);
|
||||
bool simSetObjectMaterial(const std::string& object_name, const std::string& material_name);
|
||||
bool simSetObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path);
|
||||
bool simSetObjectMaterial(const std::string& object_name, const std::string& material_name, const int component_id = 0);
|
||||
bool simSetObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path, const int component_id = 0);
|
||||
|
||||
// Recording APIs
|
||||
void startRecording();
|
||||
|
|
|
@ -74,8 +74,8 @@ namespace airlib
|
|||
virtual bool setObjectScale(const std::string& object_name, const Vector3r& scale) = 0;
|
||||
virtual std::unique_ptr<std::vector<std::string>> swapTextures(const std::string& tag, int tex_id = 0, int component_id = 0, int material_id = 0) = 0;
|
||||
virtual bool setLightIntensity(const std::string& light_name, float intensity) = 0;
|
||||
virtual bool setObjectMaterial(const std::string& object_name, const std::string& material_name) = 0;
|
||||
virtual bool setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path) = 0;
|
||||
virtual bool setObjectMaterial(const std::string& object_name, const std::string& material_name, const int component_id = 0) = 0;
|
||||
virtual bool setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path, const int component_id = 0) = 0;
|
||||
virtual vector<MeshPositionVertexBuffersResponse> getMeshPositionVertexBuffers() const = 0;
|
||||
|
||||
virtual bool createVoxelGrid(const Vector3r& position, const int& x_size, const int& y_size, const int& z_size, const float& res, const std::string& output_file) = 0;
|
||||
|
|
|
@ -493,14 +493,14 @@ __pragma(warning(disable : 4239))
|
|||
return pimpl_->client.call("simSwapTextures", tags, tex_id, component_id, material_id).as<vector<string>>();
|
||||
}
|
||||
|
||||
bool RpcLibClientBase::simSetObjectMaterial(const std::string& object_name, const std::string& material_name)
|
||||
bool RpcLibClientBase::simSetObjectMaterial(const std::string& object_name, const std::string& material_name, const int component_id)
|
||||
{
|
||||
return pimpl_->client.call("simSetObjectMaterial", object_name, material_name).as<bool>();
|
||||
return pimpl_->client.call("simSetObjectMaterial", object_name, material_name, component_id).as<bool>();
|
||||
}
|
||||
|
||||
bool RpcLibClientBase::simSetObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path)
|
||||
bool RpcLibClientBase::simSetObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path, const int component_id)
|
||||
{
|
||||
return pimpl_->client.call("simSetObjectMaterialFromTexture", object_name, texture_path).as<bool>();
|
||||
return pimpl_->client.call("simSetObjectMaterialFromTexture", object_name, texture_path, component_id).as<bool>();
|
||||
}
|
||||
|
||||
bool RpcLibClientBase::simLoadLevel(const string& level_name)
|
||||
|
|
|
@ -477,12 +477,12 @@ namespace airlib
|
|||
return *getWorldSimApi()->swapTextures(tag, tex_id, component_id, material_id);
|
||||
});
|
||||
|
||||
pimpl_->server.bind("simSetObjectMaterial", [&](const std::string& object_name, const std::string& material_name) -> bool {
|
||||
return getWorldSimApi()->setObjectMaterial(object_name, material_name);
|
||||
pimpl_->server.bind("simSetObjectMaterial", [&](const std::string& object_name, const std::string& material_name, const int component_id) -> bool {
|
||||
return getWorldSimApi()->setObjectMaterial(object_name, material_name, component_id);
|
||||
});
|
||||
|
||||
pimpl_->server.bind("simSetObjectMaterialFromTexture", [&](const std::string& object_name, const std::string& texture_path) -> bool {
|
||||
return getWorldSimApi()->setObjectMaterialFromTexture(object_name, texture_path);
|
||||
pimpl_->server.bind("simSetObjectMaterialFromTexture", [&](const std::string& object_name, const std::string& texture_path, const int component_id) -> bool {
|
||||
return getWorldSimApi()->setObjectMaterialFromTexture(object_name, texture_path, component_id);
|
||||
});
|
||||
|
||||
pimpl_->server.bind("startRecording", [&]() -> void {
|
||||
|
|
|
@ -190,31 +190,33 @@ class VehicleClient:
|
|||
"""
|
||||
return self.client.call("simSwapTextures", tags, tex_id, component_id, material_id)
|
||||
|
||||
def simSetObjectMaterial(self, object_name, material_name):
|
||||
def simSetObjectMaterial(self, object_name, material_name, component_id = 0):
|
||||
"""
|
||||
Runtime Swap Texture API
|
||||
See https://microsoft.github.io/AirSim/retexturing/ for details
|
||||
Args:
|
||||
object_name (str): name of object to set material for
|
||||
material_name (str): name of material to set for object
|
||||
component_id (int, optional) : index of material elements
|
||||
|
||||
Returns:
|
||||
bool: True if material was set
|
||||
"""
|
||||
return self.client.call("simSetObjectMaterial", object_name, material_name)
|
||||
return self.client.call("simSetObjectMaterial", object_name, material_name, component_id)
|
||||
|
||||
def simSetObjectMaterialFromTexture(self, object_name, texture_path):
|
||||
def simSetObjectMaterialFromTexture(self, object_name, texture_path, component_id = 0):
|
||||
"""
|
||||
Runtime Swap Texture API
|
||||
See https://microsoft.github.io/AirSim/retexturing/ for details
|
||||
Args:
|
||||
object_name (str): name of object to set material for
|
||||
texture_path (str): path to texture to set for object
|
||||
component_id (int, optional) : index of material elements
|
||||
|
||||
Returns:
|
||||
bool: True if material was set
|
||||
"""
|
||||
return self.client.call("simSetObjectMaterialFromTexture", object_name, texture_path)
|
||||
return self.client.call("simSetObjectMaterialFromTexture", object_name, texture_path, component_id)
|
||||
|
||||
|
||||
# time-of-day control
|
||||
|
@ -1616,4 +1618,4 @@ class CarClient(VehicleClient, object):
|
|||
CarControls:
|
||||
"""
|
||||
controls_raw = self.client.call('getCarControls', vehicle_name)
|
||||
return CarControls.from_msgpack(controls_raw)
|
||||
return CarControls.from_msgpack(controls_raw)
|
|
@ -75,7 +75,7 @@ std::unique_ptr<std::vector<std::string>> WorldSimApi::swapTextures(const std::s
|
|||
return result;
|
||||
}
|
||||
|
||||
bool WorldSimApi::setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path)
|
||||
bool WorldSimApi::setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path, const int component_id)
|
||||
{
|
||||
throw std::invalid_argument(common_utils::Utils::stringf(
|
||||
"setObjectMaterialFromTexture is not supported on unity")
|
||||
|
@ -83,7 +83,7 @@ bool WorldSimApi::setObjectMaterialFromTexture(const std::string& object_name, c
|
|||
return false;
|
||||
}
|
||||
|
||||
bool WorldSimApi::setObjectMaterial(const std::string& object_name, const std::string& material_name)
|
||||
bool WorldSimApi::setObjectMaterial(const std::string& object_name, const std::string& material_name, const int component_id)
|
||||
{
|
||||
throw std::invalid_argument(common_utils::Utils::stringf(
|
||||
"setObjectMaterial is not supported on unity")
|
||||
|
|
|
@ -40,8 +40,8 @@ public:
|
|||
|
||||
virtual bool setLightIntensity(const std::string& light_name, float intensity) override;
|
||||
virtual std::unique_ptr<std::vector<std::string>> swapTextures(const std::string& tag, int tex_id = 0, int component_id = 0, int material_id = 0) override;
|
||||
virtual bool setObjectMaterial(const std::string& object_name, const std::string& material_name) override;
|
||||
virtual bool setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path) override;
|
||||
virtual bool setObjectMaterial(const std::string& object_name, const std::string& material_name, const int component_id = 0) override;
|
||||
virtual bool setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path, const int component_id = 0) override;
|
||||
virtual std::vector<std::string> listSceneObjects(const std::string& name_regex) const override;
|
||||
virtual Pose getObjectPose(const std::string& object_name) const override;
|
||||
|
||||
|
|
|
@ -476,10 +476,10 @@ std::unique_ptr<std::vector<std::string>> WorldSimApi::swapTextures(const std::s
|
|||
return swappedObjectNames;
|
||||
}
|
||||
|
||||
bool WorldSimApi::setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path)
|
||||
bool WorldSimApi::setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path, const int component_id)
|
||||
{
|
||||
bool success = false;
|
||||
UAirBlueprintLib::RunCommandOnGameThread([this, &object_name, &texture_path, &success]() {
|
||||
UAirBlueprintLib::RunCommandOnGameThread([this, &object_name, &texture_path, &success, &component_id]() {
|
||||
if (!IsValid(simmode_->domain_rand_material_)) {
|
||||
UAirBlueprintLib::LogMessageString("Cannot find material for domain randomization",
|
||||
"",
|
||||
|
@ -495,7 +495,7 @@ bool WorldSimApi::setObjectMaterialFromTexture(const std::string& object_name, c
|
|||
for (UStaticMeshComponent* staticMeshComponent : components) {
|
||||
UMaterialInstanceDynamic* dynamic_material = UMaterialInstanceDynamic::Create(simmode_->domain_rand_material_, staticMeshComponent);
|
||||
dynamic_material->SetTextureParameterValue("TextureParameter", texture_desired);
|
||||
staticMeshComponent->SetMaterial(0, dynamic_material);
|
||||
staticMeshComponent->SetMaterial(component_id, dynamic_material);
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
|
@ -511,10 +511,10 @@ bool WorldSimApi::setObjectMaterialFromTexture(const std::string& object_name, c
|
|||
return success;
|
||||
}
|
||||
|
||||
bool WorldSimApi::setObjectMaterial(const std::string& object_name, const std::string& material_name)
|
||||
bool WorldSimApi::setObjectMaterial(const std::string& object_name, const std::string& material_name, const int component_id)
|
||||
{
|
||||
bool success = false;
|
||||
UAirBlueprintLib::RunCommandOnGameThread([this, &object_name, &material_name, &success]() {
|
||||
UAirBlueprintLib::RunCommandOnGameThread([this, &object_name, &material_name, &success, &component_id]() {
|
||||
AActor* actor = UAirBlueprintLib::FindActor<AActor>(simmode_, FString(object_name.c_str()));
|
||||
UMaterial* material = static_cast<UMaterial*>(StaticLoadObject(UMaterial::StaticClass(), nullptr, *FString(material_name.c_str())));
|
||||
|
||||
|
@ -528,7 +528,7 @@ bool WorldSimApi::setObjectMaterial(const std::string& object_name, const std::s
|
|||
TArray<UStaticMeshComponent*> components;
|
||||
actor->GetComponents<UStaticMeshComponent>(components);
|
||||
for (UStaticMeshComponent* staticMeshComponent : components) {
|
||||
staticMeshComponent->SetMaterial(0, material);
|
||||
staticMeshComponent->SetMaterial(component_id, material);
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
|
@ -843,7 +843,6 @@ std::vector<msr::airlib::GeoPoint> WorldSimApi::getWorldExtents() const
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
msr::airlib::CameraInfo WorldSimApi::getCameraInfo(const CameraDetails& camera_details) const
|
||||
{
|
||||
msr::airlib::CameraInfo info;
|
||||
|
|
|
@ -50,8 +50,8 @@ public:
|
|||
|
||||
virtual bool setLightIntensity(const std::string& light_name, float intensity) override;
|
||||
virtual std::unique_ptr<std::vector<std::string>> swapTextures(const std::string& tag, int tex_id = 0, int component_id = 0, int material_id = 0) override;
|
||||
virtual bool setObjectMaterial(const std::string& object_name, const std::string& material_name) override;
|
||||
virtual bool setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path) override;
|
||||
virtual bool setObjectMaterial(const std::string& object_name, const std::string& material_name, const int component_id = 0) override;
|
||||
virtual bool setObjectMaterialFromTexture(const std::string& object_name, const std::string& texture_path, const int component_id = 0) override;
|
||||
virtual std::vector<std::string> listSceneObjects(const std::string& name_regex) const override;
|
||||
virtual Pose getObjectPose(const std::string& object_name) const override;
|
||||
virtual bool setObjectPose(const std::string& object_name, const Pose& pose, bool teleport) override;
|
||||
|
|
Загрузка…
Ссылка в новой задаче