URDF loader: fix SDF branch, warn about unsupported geometry

This commit is contained in:
Oleg Klimov
2017-03-14 02:32:02 +03:00
parent 3a8199ec28
commit fa60cc5f56
3 changed files with 61 additions and 59 deletions

View File

@@ -755,7 +755,8 @@ upAxisMat.setIdentity();
} // mesh case } // mesh case
default: default:
b3Warning("Error: unknown visual geometry type\n"); b3Warning("Error: unknown collision geometry type %i\n", collision->m_geometry.m_type);
// for example, URDF_GEOM_PLANE
} }
return shape; return shape;
} }
@@ -943,7 +944,7 @@ static void convertURDFToVisualShapeInternal(const UrdfVisual* visual, const cha
} }
default: default:
b3Warning("Error: unknown visual geometry type\n"); b3Warning("Error: unknown visual geometry type %i\n", visual->m_geometry.m_type);
} }
//if we have a convex, tesselate into localVertices/localIndices //if we have a convex, tesselate into localVertices/localIndices

View File

@@ -410,67 +410,68 @@ bool UrdfParser::parseGeometry(UrdfGeometry& geom, TiXmlElement* g, ErrorLogger*
geom.m_type = URDF_GEOM_CAPSULE; geom.m_type = URDF_GEOM_CAPSULE;
if (!shape->Attribute("length") || if (!shape->Attribute("length") ||
!shape->Attribute("radius")) !shape->Attribute("radius"))
{ {
logger->reportError("Capsule shape must have both length and radius attributes"); logger->reportError("Capsule shape must have both length and radius attributes");
return false; return false;
} }
geom.m_hasFromTo = false; geom.m_hasFromTo = false;
geom.m_capsuleRadius = urdfLexicalCast<double>(shape->Attribute("radius")); geom.m_capsuleRadius = urdfLexicalCast<double>(shape->Attribute("radius"));
geom.m_capsuleHalfHeight = btScalar(0.5)*urdfLexicalCast<double>(shape->Attribute("length")); geom.m_capsuleHalfHeight = btScalar(0.5)*urdfLexicalCast<double>(shape->Attribute("length"));
} }
else if (type_name == "mesh") else if (type_name == "mesh")
{ {
geom.m_type = URDF_GEOM_MESH; geom.m_type = URDF_GEOM_MESH;
if (m_parseSDF) geom.m_meshScale.setValue(1,1,1);
{ std::string fn;
TiXmlElement* scale = shape->FirstChildElement("scale");
if (0==scale)
{
geom.m_meshScale.setValue(1,1,1);
}
else
{
parseVector3(geom.m_meshScale,scale->GetText(),logger);
}
TiXmlElement* filename = shape->FirstChildElement("uri");
geom.m_meshFileName = filename->GetText();
}
else
{
if (!shape->Attribute("filename"))
{
logger->reportError("Mesh must contain a filename attribute");
return false;
}
bool success = findExistingMeshFile(
m_urdf2Model.m_sourceFile, shape->Attribute("filename"), sourceFileLocation(shape),
&geom.m_meshFileName, &geom.m_meshFileType);
if (!success)
{
// warning printed
return false;
}
geom.m_meshScale.setValue(1,1,1);
if (shape->Attribute("scale")) if (m_parseSDF)
{ {
if (!parseVector3(geom.m_meshScale,shape->Attribute("scale"),logger)) if (TiXmlElement* scale = shape->FirstChildElement("scale"))
{ {
logger->reportWarning("%s: scale should be a vector3, not single scalar. Workaround activated.\n"); parseVector3(geom.m_meshScale,scale->GetText(),logger);
std::string scalar_str = shape->Attribute("scale"); }
double scaleFactor = urdfLexicalCast<double>(scalar_str.c_str()); if (TiXmlElement* filename = shape->FirstChildElement("uri"))
if (scaleFactor) {
{ fn = filename->GetText();
geom.m_meshScale.setValue(scaleFactor,scaleFactor,scaleFactor); }
} }
} else
} else {
{ // URDF
} if (shape->Attribute("filename"))
} {
fn = shape->Attribute("filename");
}
if (shape->Attribute("scale"))
{
if (!parseVector3(geom.m_meshScale, shape->Attribute("scale"), logger))
{
logger->reportWarning("Scale should be a vector3, not single scalar. Workaround activated.\n");
std::string scalar_str = shape->Attribute("scale");
double scaleFactor = urdfLexicalCast<double>(scalar_str.c_str());
if (scaleFactor)
{
geom.m_meshScale.setValue(scaleFactor, scaleFactor, scaleFactor);
}
}
}
}
if (fn.empty())
{
logger->reportError("Mesh filename is empty");
return false;
}
geom.m_meshFileName = fn;
bool success = findExistingMeshFile(
m_urdf2Model.m_sourceFile, fn, sourceFileLocation(shape),
&geom.m_meshFileName, &geom.m_meshFileType);
if (!success)
{
// warning already printed
return false;
}
} }
else else
{ {

View File

@@ -380,7 +380,7 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref
default: default:
{ {
b3Warning("Error: unknown visual geometry type\n"); b3Warning("TinyRenderer: unknown visual geometry type %i\n", visual->m_geometry.m_type);
} }
} }