mirror of
https://github.com/bulletphysics/bullet3.git
synced 2026-06-08 08:13:55 +00:00
Also adds user data specified in URDF files to rigid bodies (previously,
only multi bodies were added correctly).
This commit is contained in:
@@ -3433,34 +3433,46 @@ bool PhysicsServerCommandProcessor::processImportedObjects(const char* fileName,
|
||||
}
|
||||
}
|
||||
|
||||
// Because the link order between UrdfModel and MultiBody may be different,
|
||||
// create a mapping from link name to link index in order to apply the user
|
||||
// data to the correct link in the MultiBody.
|
||||
btHashMap<btHashString, int> linkNameToIndexMap;
|
||||
if (bodyHandle->m_multiBody)
|
||||
{
|
||||
btMultiBody* mb = bodyHandle->m_multiBody;
|
||||
linkNameToIndexMap.insert(mb->getBaseName(), -1);
|
||||
for (int linkIndex = 0; linkIndex < mb->getNumLinks(); ++linkIndex)
|
||||
{
|
||||
linkNameToIndexMap.insert(mb->getLink(linkIndex).m_linkName, linkIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Add user data specified in URDF to the added body.
|
||||
const UrdfModel* urdfModel = u2b.getUrdfModel();
|
||||
if (urdfModel)
|
||||
{
|
||||
addUserData(urdfModel->m_userData, bodyUniqueId);
|
||||
for (int i = 0; i < urdfModel->m_links.size(); ++i)
|
||||
if (bodyHandle->m_multiBody)
|
||||
{
|
||||
const UrdfLink* link = *urdfModel->m_links.getAtIndex(i);
|
||||
int* linkIndex = linkNameToIndexMap.find(link->m_name.c_str());
|
||||
if (linkIndex)
|
||||
btMultiBody* mb = bodyHandle->m_multiBody;
|
||||
// Because the link order between UrdfModel and MultiBody may be different,
|
||||
// create a mapping from link name to link index in order to apply the user
|
||||
// data to the correct link in the MultiBody.
|
||||
btHashMap<btHashString, int> linkNameToIndexMap;
|
||||
linkNameToIndexMap.insert(mb->getBaseName(), -1);
|
||||
for (int linkIndex = 0; linkIndex < mb->getNumLinks(); ++linkIndex)
|
||||
{
|
||||
addUserData(link->m_userData, bodyUniqueId, *linkIndex);
|
||||
linkNameToIndexMap.insert(mb->getLink(linkIndex).m_linkName, linkIndex);
|
||||
}
|
||||
for (int i = 0; i < urdfModel->m_links.size(); ++i)
|
||||
{
|
||||
const UrdfLink* link = *urdfModel->m_links.getAtIndex(i);
|
||||
int* linkIndex = linkNameToIndexMap.find(link->m_name.c_str());
|
||||
if (linkIndex)
|
||||
{
|
||||
addUserData(link->m_userData, bodyUniqueId, *linkIndex);
|
||||
for (int visualShapeIndex = 0; visualShapeIndex < link->m_visualArray.size(); ++visualShapeIndex)
|
||||
{
|
||||
addUserData(link->m_visualArray.at(visualShapeIndex).m_userData, bodyUniqueId, *linkIndex, visualShapeIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (bodyHandle->m_rigidBody)
|
||||
{
|
||||
for (int i = 0; i < urdfModel->m_links.size(); ++i)
|
||||
{
|
||||
const UrdfLink* link = *urdfModel->m_links.getAtIndex(i);
|
||||
addUserData(link->m_userData, bodyUniqueId, -1);
|
||||
for (int visualShapeIndex = 0; visualShapeIndex < link->m_visualArray.size(); ++visualShapeIndex)
|
||||
{
|
||||
addUserData(link->m_visualArray.at(visualShapeIndex).m_userData, bodyUniqueId, *linkIndex, visualShapeIndex);
|
||||
addUserData(link->m_visualArray.at(visualShapeIndex).m_userData, bodyUniqueId, -1, visualShapeIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user