Skip to content

Commit

Permalink
Fix ColladaExporter submesh index bug (#763)
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
  • Loading branch information
Blast545 committed Apr 27, 2021
1 parent 9599770 commit a96cfa5
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 9 deletions.
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>

0 comments on commit a96cfa5

Please sign in to comment.