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

Fix textures not exporting after loading a world that uses obj models #874

Merged
merged 9 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 4 additions & 5 deletions src/systems/collada_world_exporter/ColladaWorldExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ class ignition::gazebo::systems::ColladaWorldExporterPrivate
int newMatIndex = 0;
if (_matIndex != -1)
{
newMatIndex = worldMesh.IndexOfMaterial(
mesh->MaterialByIndex(_matIndex).get());
if (_matIndex < 0)
auto m = mesh->MaterialByIndex(_matIndex);
newMatIndex = worldMesh.IndexOfMaterial(m.get());
if (newMatIndex < 0)
{
newMatIndex = worldMesh.AddMaterial(
mesh->MaterialByIndex(_matIndex));
newMatIndex = worldMesh.AddMaterial(m);
}
}
else
Expand Down
44 changes: 42 additions & 2 deletions test/integration/collada_world_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ TEST_F(ColladaWorldExporterFixture, ExportWorld)

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

this->LoadWorld(common::joinPaths("test", "worlds",
"collada_world_exporter_submesh.sdf"));
Expand Down Expand Up @@ -110,6 +112,44 @@ TEST_F(ColladaWorldExporterFixture, ExportWorldFromFuelWithSubmesh)
common::removeAll(outputPath);
}

TEST_F(ColladaWorldExporterFixture, ExportWorldMadeFromObj)
{
std::string world_path =
ignition::common::joinPaths(PROJECT_SOURCE_PATH, "test", "worlds");
ignition::common::setenv("IGN_GAZEBO_RESOURCE_PATH",
(world_path + ":" +
ignition::common::joinPaths(world_path, "models")).c_str());

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

const std::string outputPath = "./office_world";
const std::string outputPathTextures =
common::joinPaths(outputPath, "materials", "textures");
const std::string outputPathTexture1 =
common::joinPaths(outputPathTextures, "default.png");
const std::string outputPathTexture2 =
common::joinPaths(outputPathTextures, "blue_linoleum.png");

// 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 and corresponding textures should now exist.
EXPECT_TRUE(common::exists(outputPath));
EXPECT_TRUE(common::exists(outputPathTextures));
EXPECT_TRUE(common::exists(outputPathTexture1));
EXPECT_TRUE(common::exists(outputPathTexture2));

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

ddengster marked this conversation as resolved.
Show resolved Hide resolved
/////////////////////////////////////////////////
/// Main
int main(int _argc, char **_argv)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/worlds/models/building_L1/meshes/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test/worlds/models/building_L1/meshes/floor_1.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The Great Editor v0.0.1
newmtl floor_1
Ka 1.0 1.0 1.0
Kd 1.0 1.0 1.0
Ke 0.0 0.0 0.0
Ns 50.0
Ni 1.0
d 1.0
illum 2
map_Kd blue_linoleum.png
93 changes: 93 additions & 0 deletions test/worlds/models/building_L1/meshes/floor_1.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# The Great Editor v0.0.1
mtllib floor_1.mtl
o floor_1
v 6.53267851016078 -1.1435613801846989 0
v 6.53267851016078 -1.1435613801846989 -0.1
v 8.487429009296054 -1.9423062216146643 0
v 8.487429009296054 -1.9423062216146643 -0.1
v 10.123115005198834 -2.370169265455913 0
v 10.123115005198834 -2.370169265455913 -0.1
v 11.8122859979555 -2.608608395146717 0
v 11.8122859979555 -2.608608395146717 -0.1
v 12.184437619781013 -2.599694229004403 0
v 12.184437619781013 -2.599694229004403 -0.1
v 14.079464052312275 -2.5592799562946147 0
v 14.079464052312275 -2.5592799562946147 -0.1
v 23.683364858074697 -2.8822216561967937 0
v 23.683364858074697 -2.8822216561967937 -0.1
v 23.1498185757523 -6.032037606561247 0
v 23.1498185757523 -6.032037606561247 -0.1
v 22.780071154481785 -8.681068739912664 0
v 22.780071154481785 -8.681068739912664 -0.1
v 22.494580804070203 -11.2739313145231 0
v 22.494580804070203 -11.2739313145231 -0.1
v 19.461766458884213 -11.540704455684297 0
v 19.461766458884213 -11.540704455684297 -0.1
v 13.709716631041763 -12.004054854196562 0
v 13.709716631041763 -12.004054854196562 -0.1
v 10.789239403337737 -11.952567714141905 0
v 10.789239403337737 -11.952567714141905 -0.1
v 7.887470919389182 -11.50794299037494 0
v 7.887470919389182 -11.50794299037494 -0.1
v 5.552678957170429 -10.839312805742093 0
v 5.552678957170429 -10.839312805742093 -0.1
v 5.0034207162914015 -10.693384604449395 0
v 5.0034207162914015 -10.693384604449395 -0.1
v 2.277641406067981 -9.52562037431135 0
v 2.277641406067981 -9.52562037431135 -0.1
v 5.189085950700927 -3.7721398778287742 0
v 5.189085950700927 -3.7721398778287742 -0.1
vt 6.53267851016078 -1.1435613801846989 0
vt 8.487429009296054 -1.9423062216146643 0
vt 10.123115005198834 -2.370169265455913 0
vt 11.8122859979555 -2.608608395146717 0
vt 12.184437619781013 -2.599694229004403 0
vt 14.079464052312275 -2.5592799562946147 0
vt 23.683364858074697 -2.8822216561967937 0
vt 23.1498185757523 -6.032037606561247 0
vt 22.780071154481785 -8.681068739912664 0
vt 22.494580804070203 -11.2739313145231 0
vt 19.461766458884213 -11.540704455684297 0
vt 13.709716631041763 -12.004054854196562 0
vt 10.789239403337737 -11.952567714141905 0
vt 7.887470919389182 -11.50794299037494 0
vt 5.552678957170429 -10.839312805742093 0
vt 5.0034207162914015 -10.693384604449395 0
vt 2.277641406067981 -9.52562037431135 0
vt 5.189085950700927 -3.7721398778287742 0
vn 0 0 1
vn 0 0 -1
usemtl floor_1
s off
f 31/16/1 35/18/1 33/17/1
f 34/17/2 36/18/2 32/16/2
f 31/16/1 29/15/1 35/18/1
f 36/18/2 30/15/2 32/16/2
f 29/15/1 27/14/1 35/18/1
f 36/18/2 28/14/2 30/15/2
f 27/14/1 5/3/1 35/18/1
f 36/18/2 6/3/2 28/14/2
f 5/3/1 3/2/1 35/18/1
f 36/18/2 4/2/2 6/3/2
f 3/2/1 1/1/1 35/18/1
f 36/18/2 2/1/2 4/2/2
f 11/6/1 15/8/1 13/7/1
f 14/7/2 16/8/2 12/6/2
f 21/11/1 11/6/1 23/12/1
f 24/12/2 12/6/2 22/11/2
f 11/6/1 9/5/1 23/12/1
f 24/12/2 10/5/2 12/6/2
f 9/5/1 25/13/1 23/12/1
f 24/12/2 26/13/2 10/5/2
f 9/5/1 7/4/1 25/13/1
f 26/13/2 8/4/2 10/5/2
f 7/4/1 5/3/1 25/13/1
f 26/13/2 6/3/2 8/4/2
f 5/3/1 27/14/1 25/13/1
f 26/13/2 28/14/2 6/3/2
f 21/11/1 15/8/1 11/6/1
f 12/6/2 16/8/2 22/11/2
f 21/11/1 17/9/1 15/8/1
f 16/8/2 18/9/2 22/11/2
f 17/9/1 21/11/1 19/10/1
f 20/10/2 22/11/2 18/9/2
26 changes: 26 additions & 0 deletions test/worlds/models/building_L1/meshes/model.material
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
material floor_1_Diffuse
chapulina marked this conversation as resolved.
Show resolved Hide resolved
{
technique
{
pass
{
texture_unit
{
texture blue_linoleum.png
}
}
}
}
material wall_1_Diffuse
{
technique
{
pass
{
texture_unit
{
texture default.png
}
}
}
}
10 changes: 10 additions & 0 deletions test/worlds/models/building_L1/meshes/wall_1.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The Great Editor v0.0.1
newmtl wall_1
Ka 1.0 1.0 1.0
Kd 1.0 1.0 1.0
Ke 0.0 0.0 0.0
Ns 50.0
Ni 1.0
d 1.0
illum 2
map_Kd default.png
Loading