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

Add mesh simplification attribute to <mesh> #1380

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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: 9 additions & 0 deletions include/sdf/Mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ namespace sdf
/// an error code and message. An empty vector indicates no error.
public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);

/// \brief Get the mesh's simplifcation method
/// \return The mesh simplification method.
/// Empty string if no mesh simplificaton is done.
public: std::string Simplification() const;

/// \brief Set the mesh simplification method.
/// \param[in] _simplifcation The mesh simplification method.
public: void SetSimplification(const std::string &_simplifcation);

/// \brief Get the mesh's URI.
/// \return The URI of the mesh data.
public: std::string Uri() const;
Expand Down
7 changes: 7 additions & 0 deletions sdf/1.11/mesh_shape.sdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<element name="mesh" required="0">
<description>Mesh shape</description>

<attribute name="simplification" type="string" default="" required="0">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to decide if simplification is the right name for this attribute.

Alternatives (which might not be better):

  • //mesh/@transformation
  • //mesh/@convexity

with candidate values:

  • use_convex_hull
  • use_convex_decomposition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think transformation is generic and would be another good candidate. So we don't limit this to just creating convex meshes

<description>
Set whether to simplify the mesh using one of the specified methods. Values include: "convex_hull", "convex_decomposition". Default value is an empty string which means no mesh simplification.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it make sense to add a sentence, a link or a reference to what these methods mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded this to include description for the values. 64d7c97

</description>
</attribute>

<element name="uri" type="string" default="__default__" required="1">
<description>Mesh uri</description>
</element>
Expand Down
26 changes: 26 additions & 0 deletions src/Mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ using namespace sdf;
// Private data class
class sdf::Mesh::Implementation
{
/// \brief Mesh simplification method
public: std::string simplification;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use a enum here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added enum in 64d7c97


/// \brief The mesh's URI.
public: std::string uri = "";

Expand Down Expand Up @@ -87,6 +90,13 @@ Errors Mesh::Load(ElementPtr _sdf, const ParserConfig &_config)
return errors;
}

// Simplify
if (_sdf->HasAttribute("simplification"))
{
this->dataPtr->simplification = _sdf->Get<std::string>("simplification",
this->dataPtr->simplification).first;
}

if (_sdf->HasElement("uri"))
{
std::unordered_set<std::string> paths;
Expand Down Expand Up @@ -140,6 +150,18 @@ sdf::ElementPtr Mesh::Element() const
return this->dataPtr->sdf;
}

//////////////////////////////////////////////////
std::string Mesh::Simplification() const
{
return this->dataPtr->simplification;
}

//////////////////////////////////////////////////
void Mesh::SetSimplification(const std::string &_simplification)
{
this->dataPtr->simplification = _simplification;
}

//////////////////////////////////////////////////
std::string Mesh::Uri() const
{
Expand Down Expand Up @@ -244,6 +266,10 @@ sdf::ElementPtr Mesh::ToElement(sdf::Errors &_errors) const
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("mesh_shape.sdf", elem);

// Simplification
elem->GetAttribute("simplification")->Set<std::string>(
this->dataPtr->simplification);

// Uri
sdf::ElementPtr uriElem = elem->GetElement("uri", _errors);
uriElem->Set(_errors, this->Uri());
Expand Down
17 changes: 17 additions & 0 deletions src/Mesh_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TEST(DOMMesh, Construction)
sdf::Mesh mesh;
EXPECT_EQ(nullptr, mesh.Element());

EXPECT_EQ(std::string(), mesh.Simplification());
EXPECT_EQ(std::string(), mesh.FilePath());
EXPECT_EQ(std::string(), mesh.Uri());
EXPECT_EQ(std::string(), mesh.Submesh());
Expand All @@ -45,13 +46,15 @@ TEST(DOMMesh, Construction)
TEST(DOMMesh, MoveConstructor)
{
sdf::Mesh mesh;
mesh.SetSimplification("convex_hull");
mesh.SetUri("banana");
mesh.SetSubmesh("watermelon");
mesh.SetCenterSubmesh(true);
mesh.SetScale({0.5, 0.6, 0.7});
mesh.SetFilePath("/pear");

sdf::Mesh mesh2(std::move(mesh));
EXPECT_EQ("convex_hull", mesh2.Simplification());
EXPECT_EQ("banana", mesh2.Uri());
EXPECT_EQ("watermelon", mesh2.Submesh());
EXPECT_EQ(gz::math::Vector3d(0.5, 0.6, 0.7), mesh2.Scale());
Expand All @@ -63,13 +66,15 @@ TEST(DOMMesh, MoveConstructor)
TEST(DOMMesh, CopyConstructor)
{
sdf::Mesh mesh;
mesh.SetSimplification("convex_hull");
mesh.SetUri("banana");
mesh.SetSubmesh("watermelon");
mesh.SetCenterSubmesh(true);
mesh.SetScale({0.5, 0.6, 0.7});
mesh.SetFilePath("/pear");

sdf::Mesh mesh2(mesh);
EXPECT_EQ("convex_hull", mesh2.Simplification());
EXPECT_EQ("banana", mesh2.Uri());
EXPECT_EQ("watermelon", mesh2.Submesh());
EXPECT_EQ(gz::math::Vector3d(0.5, 0.6, 0.7), mesh2.Scale());
Expand All @@ -81,6 +86,7 @@ TEST(DOMMesh, CopyConstructor)
TEST(DOMMesh, CopyAssignmentOperator)
{
sdf::Mesh mesh;
mesh.SetSimplification("convex_hull");
mesh.SetUri("banana");
mesh.SetSubmesh("watermelon");
mesh.SetCenterSubmesh(true);
Expand All @@ -89,6 +95,7 @@ TEST(DOMMesh, CopyAssignmentOperator)

sdf::Mesh mesh2;
mesh2 = mesh;
EXPECT_EQ("convex_hull", mesh2.Simplification());
EXPECT_EQ("banana", mesh2.Uri());
EXPECT_EQ("watermelon", mesh2.Submesh());
EXPECT_EQ(gz::math::Vector3d(0.5, 0.6, 0.7), mesh2.Scale());
Expand All @@ -100,6 +107,7 @@ TEST(DOMMesh, CopyAssignmentOperator)
TEST(DOMMesh, MoveAssignmentOperator)
{
sdf::Mesh mesh;
mesh.SetSimplification("convex_hull");
mesh.SetUri("banana");
mesh.SetSubmesh("watermelon");
mesh.SetCenterSubmesh(true);
Expand All @@ -108,6 +116,7 @@ TEST(DOMMesh, MoveAssignmentOperator)

sdf::Mesh mesh2;
mesh2 = std::move(mesh);
EXPECT_EQ("convex_hull", mesh2.Simplification());
EXPECT_EQ("banana", mesh2.Uri());
EXPECT_EQ("watermelon", mesh2.Submesh());
EXPECT_EQ(gz::math::Vector3d(0.5, 0.6, 0.7), mesh2.Scale());
Expand Down Expand Up @@ -140,6 +149,10 @@ TEST(DOMMesh, Set)
sdf::Mesh mesh;
EXPECT_EQ(nullptr, mesh.Element());

EXPECT_EQ(std::string(), mesh.Simplification());
mesh.SetSimplification("convex_hull");
EXPECT_EQ("convex_hull", mesh.Simplification());

EXPECT_EQ(std::string(), mesh.Uri());
mesh.SetUri("http://myuri.com");
EXPECT_EQ("http://myuri.com", mesh.Uri());
Expand Down Expand Up @@ -296,6 +309,7 @@ TEST(DOMMesh, ToElement)
{
sdf::Mesh mesh;

mesh.SetSimplification("convex_hull");
mesh.SetUri("mesh-uri");
mesh.SetScale(gz::math::Vector3d(1, 2, 3));
mesh.SetSubmesh("submesh");
Expand All @@ -307,6 +321,7 @@ TEST(DOMMesh, ToElement)
sdf::Mesh mesh2;
mesh2.Load(elem);

EXPECT_EQ(mesh.Simplification(), mesh2.Simplification());
EXPECT_EQ(mesh.Uri(), mesh2.Uri());
EXPECT_EQ(mesh.Scale(), mesh2.Scale());
EXPECT_EQ(mesh.Submesh(), mesh2.Submesh());
Expand All @@ -332,6 +347,7 @@ TEST(DOMMesh, ToElementErrorOutput)
sdf::Mesh mesh;
sdf::Errors errors;

mesh.SetSimplification("convex_hull");
mesh.SetUri("mesh-uri");
mesh.SetScale(gz::math::Vector3d(1, 2, 3));
mesh.SetSubmesh("submesh");
Expand All @@ -345,6 +361,7 @@ TEST(DOMMesh, ToElementErrorOutput)
errors = mesh2.Load(elem);
EXPECT_TRUE(errors.empty());

EXPECT_EQ(mesh.Simplification(), mesh2.Simplification());
EXPECT_EQ(mesh.Uri(), mesh2.Uri());
EXPECT_EQ(mesh.Scale(), mesh2.Scale());
EXPECT_EQ(mesh.Submesh(), mesh2.Submesh());
Expand Down
2 changes: 2 additions & 0 deletions test/integration/geometry_dom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ TEST(DOMGeometry, Shapes)
EXPECT_EQ(sdf::GeometryType::MESH, meshCol->Geom()->Type());
const sdf::Mesh *meshColGeom = meshCol->Geom()->MeshShape();
ASSERT_NE(nullptr, meshColGeom);
EXPECT_EQ("convex_hull", meshColGeom->Simplification());

EXPECT_EQ("https://fuel.gazebosim.org/1.0/an_org/models/a_model/mesh/"
"mesh.dae", meshColGeom->Uri());
EXPECT_TRUE(gz::math::Vector3d(0.1, 0.2, 0.3) ==
Expand Down
2 changes: 1 addition & 1 deletion test/sdf/shapes.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

<collision name="mesh_col">
<geometry>
<mesh>
<mesh simplification="convex_hull">
<uri>https://fuel.gazebosim.org/1.0/an_org/models/a_model/mesh/mesh.dae</uri>
<submesh>
<name>my_submesh</name>
Expand Down
Loading