@@ -44,6 +44,7 @@ class BitmaskContactFilter : public dart::collision::BodyNodeCollisionFilter
4444 public: using DartShapeConstPtr = const dart::dynamics::ShapeNode*;
4545
4646 private: std::unordered_map<DartShapeConstPtr, uint16_t > bitmaskMap;
47+ private: std::unordered_map<DartShapeConstPtr, uint16_t > categoryBitmaskMap;
4748
4849 public: bool ignoresCollision (
4950 DartCollisionConstPtr _object1,
@@ -58,9 +59,20 @@ class BitmaskContactFilter : public dart::collision::BodyNodeCollisionFilter
5859
5960 auto shape1Iter = bitmaskMap.find (shapeNode1);
6061 auto shape2Iter = bitmaskMap.find (shapeNode2);
61- if (shape1Iter != bitmaskMap.end () && shape2Iter != bitmaskMap.end () &&
62- ((shape1Iter->second & shape2Iter->second ) == 0 ))
63- return true ;
62+ if (shape1Iter != bitmaskMap.end () && shape2Iter != bitmaskMap.end ())
63+ {
64+ // For backward compatibility, if category bitmask is not set, it
65+ // defaults to the same value as collide bitmask.
66+ auto category1Iter = categoryBitmaskMap.find (shapeNode1);
67+ auto category2Iter = categoryBitmaskMap.find (shapeNode2);
68+ uint16_t categoryMask1 = (category1Iter != categoryBitmaskMap.end ()) ?
69+ category1Iter->second : shape1Iter->second ;
70+ uint16_t categoryMask2 = (category2Iter != categoryBitmaskMap.end ()) ?
71+ category2Iter->second : shape2Iter->second ;
72+
73+ return !((categoryMask1 & shape2Iter->second ) |
74+ (categoryMask2 & shape1Iter->second ));
75+ }
6476
6577 return false ;
6678 }
@@ -85,12 +97,35 @@ class BitmaskContactFilter : public dart::collision::BodyNodeCollisionFilter
8597 bitmaskMap.erase (shapeIter);
8698 }
8799
100+ public: void SetIgnoredCategory (DartShapeConstPtr _shapePtr, uint16_t _mask)
101+ {
102+ categoryBitmaskMap[_shapePtr] = _mask;
103+ }
104+
105+ public: uint16_t GetIgnoredCategory (DartShapeConstPtr _shapePtr) const
106+ {
107+ auto shapeIter = categoryBitmaskMap.find (_shapePtr);
108+ if (shapeIter != categoryBitmaskMap.end ())
109+ return shapeIter->second ;
110+ // For backward compatibility, if category bitmask is not set, it
111+ // defaults to the same value as collide bitmask.
112+ return GetIgnoredCollision (_shapePtr);
113+ }
114+
115+ public: void RemoveIgnoredCategory (DartShapeConstPtr _shapePtr)
116+ {
117+ auto shapeIter = categoryBitmaskMap.find (_shapePtr);
118+ if (shapeIter != categoryBitmaskMap.end ())
119+ categoryBitmaskMap.erase (shapeIter);
120+ }
121+
88122 public: void RemoveSkeletonCollisions (dart::dynamics::SkeletonPtr _skelPtr)
89123 {
90124 for (std::size_t i = 0 ; i < _skelPtr->getNumShapeNodes (); ++i)
91125 {
92126 auto shapePtr = _skelPtr->getShapeNode (i);
93127 this ->RemoveIgnoredCollision (shapePtr);
128+ this ->RemoveIgnoredCategory (shapePtr);
94129 }
95130 }
96131
@@ -850,6 +885,33 @@ void EntityManagementFeatures::RemoveCollisionFilterMask(
850885 filterPtr->RemoveIgnoredCollision (shapeNode);
851886}
852887
888+ void EntityManagementFeatures::SetCategoryFilterMask (
889+ const Identity &_shapeID, uint16_t _mask)
890+ {
891+ const auto shapeNode = this ->ReferenceInterface <ShapeInfo>(_shapeID)->node ;
892+ const std::size_t worldID = GetWorldOfShapeNode (this , shapeNode);
893+ const auto filterPtr = GetFilterPtr (this , worldID);
894+ filterPtr->SetIgnoredCategory (shapeNode, _mask);
895+ }
896+
897+ uint16_t EntityManagementFeatures::GetCategoryFilterMask (
898+ const Identity &_shapeID) const
899+ {
900+ const auto shapeNode = this ->ReferenceInterface <ShapeInfo>(_shapeID)->node ;
901+ const std::size_t worldID = GetWorldOfShapeNode (this , shapeNode);
902+ const auto filterPtr = GetFilterPtr (this , worldID);
903+ return filterPtr->GetIgnoredCategory (shapeNode);
904+ }
905+
906+ void EntityManagementFeatures::RemoveCategoryFilterMask (
907+ const Identity &_shapeID)
908+ {
909+ const auto shapeNode = this ->ReferenceInterface <ShapeInfo>(_shapeID)->node ;
910+ const std::size_t worldID = GetWorldOfShapeNode (this , shapeNode);
911+ const auto filterPtr = GetFilterPtr (this , worldID);
912+ filterPtr->RemoveIgnoredCategory (shapeNode);
913+ }
914+
853915Identity EntityManagementFeatures::GetWorldModel (const Identity &_worldID) const
854916{
855917 auto modelID = this ->modelProxiesToWorld .MaybeAt (_worldID);
0 commit comments