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

Sehoon/sdfparser #775

Merged
merged 7 commits into from
Oct 2, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

* Parsers

* Added `sdf` parsing for `fixed` joint and `material` tag of visual shape: [#775](https://github.com/dartsim/dart/pull/775)
* Added support of urdfdom_headers 1.0: [#766](https://github.com/dartsim/dart/pull/766)

* Misc improvements and bug fixes
Expand Down
39 changes: 39 additions & 0 deletions dart/utils/sdf/SdfParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ dynamics::ShapeNode* readShapeNode(
const std::string& skelPath,
const common::ResourceRetrieverPtr& retriever);


void readMaterial(
tinyxml2::XMLElement* materialEle,
dynamics::ShapeNode* shapeNode);

void readVisualizationShapeNode(
dynamics::BodyNode* bodyNode,
tinyxml2::XMLElement* vizShapeNodeEle,
Expand Down Expand Up @@ -634,6 +639,10 @@ std::pair<dynamics::Joint*,dynamics::BodyNode*> createJointAndNodePair(
return skeleton->createJointAndBodyNodePair<dynamics::BallJoint>(parent,
static_cast<const dynamics::BallJoint::Properties&>(*joint.properties),
static_cast<const typename NodeType::Properties&>(*node.properties));
else if (std::string("fixed") == type)
return skeleton->createJointAndBodyNodePair<dynamics::WeldJoint>(parent,
static_cast<const dynamics::WeldJoint::Properties&>(*joint.properties),
static_cast<const typename NodeType::Properties&>(*node.properties));
else if (std::string("free") == type)
return skeleton->createJointAndBodyNodePair<dynamics::FreeJoint>(parent,
static_cast<const dynamics::FreeJoint::Properties&>(*joint.properties),
Expand Down Expand Up @@ -981,6 +990,29 @@ dynamics::ShapeNode* readShapeNode(
return shapeNode;
}


//==============================================================================
void readMaterial(
tinyxml2::XMLElement* materialEle,
dynamics::ShapeNode* shapeNode) {

auto visualAspect = shapeNode->getVisualAspect();
if (hasElement(materialEle, "diffuse")) {
Eigen::VectorXd color = getValueVectorXd(materialEle, "diffuse");
if (color.size() == 3) {
Eigen::Vector3d color3d = color;
visualAspect->setColor(color3d);
} else if (color.size() == 4) {
Eigen::Vector4d color4d = color;
visualAspect->setColor(color4d);
} else {
dterr << "[SdfParse::readMaterial] Unsupported color vector size: "
<< color.size() << "\n";
}
}
}


//==============================================================================
void readVisualizationShapeNode(
dynamics::BodyNode* bodyNode,
Expand All @@ -994,6 +1026,13 @@ void readVisualizationShapeNode(
skelPath, retriever);

newShapeNode->createVisualAspect();

// Material
if (hasElement(vizShapeNodeEle, "material"))
{
tinyxml2::XMLElement* materialEle = getElement(vizShapeNodeEle, "material");
readMaterial(materialEle, newShapeNode);
}
}

//==============================================================================
Expand Down
Loading