Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #763 #804

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/systems/collada_world_exporter/ColladaWorldExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class ignition::gazebo::systems::ColladaWorldExporterPrivate
ignition::common::MeshManager *meshManager =
ignition::common::MeshManager::Instance();

auto addSubmeshFunc = [&](int i) {
auto addSubmeshFunc = [&](int i, int k) {
subm = worldMesh.AddSubMesh(
*mesh->SubMeshByIndex(0).lock().get());
*mesh->SubMeshByIndex(k).lock().get());
subm.lock()->SetMaterialIndex(i);
subm.lock()->Scale(scale);
subMeshMatrix.push_back(matrix);
Expand All @@ -128,7 +128,7 @@ class ignition::gazebo::systems::ColladaWorldExporterPrivate
scale = _geom->Data().BoxShape()->Size();
int i = worldMesh.AddMaterial(mat);

addSubmeshFunc(i);
addSubmeshFunc(i, 0);
}
}
else if (_geom->Data().Type() == sdf::GeometryType::CYLINDER)
Expand All @@ -142,7 +142,7 @@ class ignition::gazebo::systems::ColladaWorldExporterPrivate

int i = worldMesh.AddMaterial(mat);

addSubmeshFunc(i);
addSubmeshFunc(i, 0);
}
}
else if (_geom->Data().Type() == sdf::GeometryType::PLANE)
Expand All @@ -166,7 +166,7 @@ class ignition::gazebo::systems::ColladaWorldExporterPrivate
matrix = math::Matrix4d(worldPose);

int i = worldMesh.AddMaterial(mat);
addSubmeshFunc(i);
addSubmeshFunc(i, 0);
}
}
else if (_geom->Data().Type() == sdf::GeometryType::SPHERE)
Expand All @@ -180,8 +180,7 @@ class ignition::gazebo::systems::ColladaWorldExporterPrivate
scale.Z() = scale.X();

int i = worldMesh.AddMaterial(mat);

addSubmeshFunc(i);
addSubmeshFunc(i, 0);
}
}
else if (_geom->Data().Type() == sdf::GeometryType::MESH)
Expand Down Expand Up @@ -221,8 +220,7 @@ class ignition::gazebo::systems::ColladaWorldExporterPrivate
}

scale = _geom->Data().MeshShape()->Scale();

addSubmeshFunc(i);
addSubmeshFunc(i, k);
}
}
else
Expand Down
27 changes: 27 additions & 0 deletions test/integration/collada_world_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ TEST_F(ColladaWorldExporterFixture, ExportWorld)
common::removeAll("./collada_world_exporter_box_test");
}

TEST_F(ColladaWorldExporterFixture, ExportWorldFromFuelWithSubmesh)
{
ignition::common::setenv("IGN_GAZEBO_RESOURCE_PATH",
(std::string(PROJECT_SOURCE_PATH) + "/test/worlds:" +
std::string(PROJECT_SOURCE_PATH) + "/test/worlds/models").c_str());

this->LoadWorld(common::joinPaths("test", "worlds",
"collada_world_exporter_submesh.sdf"));

const std::string outputPath = "./collada_world_exporter_submesh_test";

// Cleanup
common::removeAll(outputPath);

// The export directory shouldn't exist.
EXPECT_FALSE(common::exists(outputPath));

// Run one iteration which should export the world.
server->Run(true, 1, false);

// The export directory should now exist.
EXPECT_TRUE(common::exists(outputPath));

// Cleanup
common::removeAll(outputPath);
}

/////////////////////////////////////////////////
/// Main
int main(int _argc, char **_argv)
Expand Down
24 changes: 24 additions & 0 deletions test/worlds/collada_world_exporter_submesh.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" ?>
<!--
Test world downloading two tile files
-->
<sdf version="1.6">
<world name="collada_world_exporter_submesh_test">
<plugin
filename="libignition-gazebo-physics-system.so"
name="ignition::gazebo::systems::Physics">
</plugin>

<plugin
filename="ignition-gazebo-collada-world-exporter-system"
name="ignition::gazebo::systems::ColladaWorldExporter">
</plugin>

<include>
<static>true</static>
<pose>22 111 -10 0 -0 0</pose>
<uri>model://mesh_with_submeshes</uri>
</include>

</world>
</sdf>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
186 changes: 186 additions & 0 deletions test/worlds/models/mesh_with_submeshes/meshes/mesh_with_submeshes.dae

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/worlds/models/mesh_with_submeshes/model.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" ?>
<model>
<name>mesh_with_submeshes</name>
<version>1.0</version>
<sdf version="1.6">model.sdf</sdf>
</model>

23 changes: 23 additions & 0 deletions test/worlds/models/mesh_with_submeshes/model.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version='1.0'?>
<sdf version='1.6'>
<model name='scheme_resource_uri'>
<pose>0 0 1 0 0 0</pose>
<link name='the_link'>
<visual name='the_visual'>
<geometry>
<mesh>
<uri>model://mesh_with_submeshes/meshes/mesh_with_submeshes.dae</uri>
</mesh>
</geometry>
</visual>
<collision name='the_collision'>
<geometry>
<mesh>
<uri>model://mesh_with_submeshes/meshes/mesh_with_submeshes.dae</uri>
</mesh>
</geometry>
</collision>
</link>
</model>
</sdf>