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

@@ -417,59 +417,60 @@ bool UrdfParser::parseGeometry(UrdfGeometry& geom, TiXmlElement* g, ErrorLogger*
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;
geom.m_meshScale.setValue(1,1,1);
std::string fn;
if (m_parseSDF) if (m_parseSDF)
{ {
TiXmlElement* scale = shape->FirstChildElement("scale"); if (TiXmlElement* scale = shape->FirstChildElement("scale"))
if (0==scale)
{
geom.m_meshScale.setValue(1,1,1);
}
else
{ {
parseVector3(geom.m_meshScale,scale->GetText(),logger); parseVector3(geom.m_meshScale,scale->GetText(),logger);
} }
if (TiXmlElement* filename = shape->FirstChildElement("uri"))
TiXmlElement* filename = shape->FirstChildElement("uri"); {
geom.m_meshFileName = filename->GetText(); fn = filename->GetText();
}
} }
else else
{ {
if (!shape->Attribute("filename")) // URDF
if (shape->Attribute("filename"))
{ {
logger->reportError("Mesh must contain a filename attribute"); fn = shape->Attribute("filename");
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 (shape->Attribute("scale"))
{ {
if (!parseVector3(geom.m_meshScale,shape->Attribute("scale"),logger)) if (!parseVector3(geom.m_meshScale, shape->Attribute("scale"), logger))
{ {
logger->reportWarning("%s: scale should be a vector3, not single scalar. Workaround activated.\n"); logger->reportWarning("Scale should be a vector3, not single scalar. Workaround activated.\n");
std::string scalar_str = shape->Attribute("scale"); std::string scalar_str = shape->Attribute("scale");
double scaleFactor = urdfLexicalCast<double>(scalar_str.c_str()); double scaleFactor = urdfLexicalCast<double>(scalar_str.c_str());
if (scaleFactor) if (scaleFactor)
{ {
geom.m_meshScale.setValue(scaleFactor,scaleFactor,scaleFactor); geom.m_meshScale.setValue(scaleFactor, scaleFactor, scaleFactor);
} }
} }
} else }
}
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);
} }
} }