Skip to content

Commit 4bf71cd

Browse files
authored
Merge branch 'main' into issue/452_aiscene_custom_deleter
2 parents bcd1b68 + d111194 commit 4bf71cd

File tree

73 files changed

+2158
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2158
-203
lines changed

cmake/DARTFindDependencies.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ if(ASSIMP_FOUND)
4646
return 1;
4747
}
4848
"
49-
ASSIMP_AISCENE_CTOR_DTOR_DEFINED
49+
DART_ASSIMP_AISCENE_CTOR_DTOR_DEFINED
5050
)
5151

52-
if(NOT ASSIMP_AISCENE_CTOR_DTOR_DEFINED)
52+
if(NOT DART_ASSIMP_AISCENE_CTOR_DTOR_DEFINED)
5353
if(DART_VERBOSE)
5454
message(
5555
WARNING
@@ -72,10 +72,10 @@ if(ASSIMP_FOUND)
7272
return 1;
7373
}
7474
"
75-
ASSIMP_AIMATERIAL_CTOR_DTOR_DEFINED
75+
DART_ASSIMP_AIMATERIAL_CTOR_DTOR_DEFINED
7676
)
7777

78-
if(NOT ASSIMP_AIMATERIAL_CTOR_DTOR_DEFINED)
78+
if(NOT DART_ASSIMP_AIMATERIAL_CTOR_DTOR_DEFINED)
7979
if(DART_VERBOSE)
8080
message(
8181
WARNING
@@ -97,18 +97,18 @@ endif()
9797
dart_find_package(octomap)
9898
if(OCTOMAP_FOUND OR octomap_FOUND)
9999
if(NOT DEFINED octomap_VERSION)
100-
set(HAVE_OCTOMAP FALSE CACHE BOOL "Check if octomap found." FORCE)
100+
set(DART_HAVE_OCTOMAP FALSE CACHE BOOL "Check if octomap found." FORCE)
101101
message(WARNING "Looking for octomap - octomap_VERSION is not defined, "
102102
"please install octomap with version information"
103103
)
104104
else()
105-
set(HAVE_OCTOMAP TRUE CACHE BOOL "Check if octomap found." FORCE)
105+
set(DART_HAVE_OCTOMAP TRUE CACHE BOOL "Check if octomap found." FORCE)
106106
if(DART_VERBOSE)
107107
message(STATUS "Looking for octomap - version ${octomap_VERSION} found")
108108
endif()
109109
endif()
110110
else()
111-
set(HAVE_OCTOMAP FALSE CACHE BOOL "Check if octomap found." FORCE)
111+
set(DART_HAVE_OCTOMAP FALSE CACHE BOOL "Check if octomap found." FORCE)
112112
message(WARNING "Looking for octomap - NOT found, to use VoxelGridShape, "
113113
"please install octomap"
114114
)

cmake/dart_defs.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,12 +1391,14 @@ macro(dart_check_optional_package variable component dependency)
13911391
mark_as_advanced(DART_SKIP_${variable})
13921392
if(${${variable}_FOUND} AND NOT ${DART_SKIP_${variable}})
13931393
set(HAVE_${variable} TRUE CACHE BOOL "Check if ${variable} found." FORCE)
1394+
set(DART_HAVE_${variable} TRUE CACHE BOOL "Check if ${variable} found." FORCE)
13941395
if(DART_VERBOSE)
13951396
message(STATUS "Looking for ${dependency} - version ${${variable}_VERSION}"
13961397
" found")
13971398
endif()
13981399
else()
13991400
set(HAVE_${variable} FALSE CACHE BOOL "Check if ${variable} found." FORCE)
1401+
set(DART_HAVE_${variable} FALSE CACHE BOOL "Check if ${variable} found." FORCE)
14001402
if(NOT ${${variable}_FOUND})
14011403
if(ARGV3) # version
14021404
message(WARNING "Looking for ${dependency} - NOT found, to use"

dart/collision/CollisionGroup.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "dart/dynamics/Skeleton.hpp"
4040

4141
#include <cassert>
42+
#include <cstdint>
4243

4344
namespace dart {
4445
namespace collision {
@@ -321,6 +322,31 @@ void CollisionGroup::removeDeletedShapeFrames()
321322
mObserver.mDeletedFrames.clear();
322323
}
323324

325+
//==============================================================================
326+
std::size_t CollisionGroup::computeMetaSkeletonVersion(
327+
const dynamics::MetaSkeleton& metaSkeleton)
328+
{
329+
if (const auto* skeleton
330+
= dynamic_cast<const dynamics::Skeleton*>(&metaSkeleton)) {
331+
return skeleton->getVersion();
332+
}
333+
334+
const std::size_t numBodies = metaSkeleton.getNumBodyNodes();
335+
std::size_t seed = numBodies;
336+
337+
for (std::size_t i = 0u; i < numBodies; ++i) {
338+
const auto* bodyNode = metaSkeleton.getBodyNode(i);
339+
const auto bodyNodeHash
340+
= static_cast<std::size_t>(reinterpret_cast<std::uintptr_t>(bodyNode));
341+
const auto bodyNodeVersion = bodyNode ? bodyNode->getVersion() : 0u;
342+
343+
seed ^= bodyNodeHash + 0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2);
344+
seed ^= bodyNodeVersion + 0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2);
345+
}
346+
347+
return seed;
348+
}
349+
324350
//==============================================================================
325351
void CollisionGroup::updateEngineData()
326352
{
@@ -449,18 +475,12 @@ bool CollisionGroup::updateSkeletonSource(SkeletonSources::value_type& entry)
449475
// This skeleton no longer exists, so we should remove all its contents from
450476
// the CollisionGroup.
451477
for (const auto& object : source.mObjects)
452-
removeShapeFrameInternal(object.second->mFrame, object.first);
478+
removeShapeFrameInternal(object.second->mFrame, entry.first);
453479

454480
return true;
455481
}
456482

457-
// Note: Right now we can only subscribe to Skeletons, not MetaSkeletons, so
458-
// we can safely do a static_cast here. Eventually this static_cast should not
459-
// be needed, if we can figure out a versioning system for MetaSkeleton.
460-
const dynamics::Skeleton* skeleton
461-
= dynamic_cast<const dynamics::Skeleton*>(meta.get());
462-
463-
const std::size_t currentSkeletonVersion = skeleton->getVersion();
483+
const std::size_t currentSkeletonVersion = computeMetaSkeletonVersion(*meta);
464484
// If the version hasn't changed, then there will be nothing to update.
465485
if (currentSkeletonVersion == source.mLastKnownVersion)
466486
return false;
@@ -473,8 +493,8 @@ bool CollisionGroup::updateSkeletonSource(SkeletonSources::value_type& entry)
473493
// Check each child to see if its version number has changed. If it has, then
474494
// check to see if any of its ShapeFrames need to be updated, added, or
475495
// removed from the CollisionGroup.
476-
for (std::size_t i = 0; i < skeleton->getNumBodyNodes(); ++i) {
477-
const dynamics::BodyNode* bn = skeleton->getBodyNode(i);
496+
for (std::size_t i = 0; i < meta->getNumBodyNodes(); ++i) {
497+
const dynamics::BodyNode* bn = meta->getBodyNode(i);
478498
const std::size_t currentVersion = bn->getVersion();
479499

480500
unusedChildren.erase(bn);
@@ -541,7 +561,8 @@ bool CollisionGroup::updateSkeletonSource(SkeletonSources::value_type& entry)
541561
}
542562
}
543563

544-
// Remove from this group any BodyNodes that no longer belong to the skeleton
564+
// Remove from this group any BodyNodes that no longer belong to the meta
565+
// skeleton
545566
for (const auto& unusedChild : unusedChildren) {
546567
for (const dynamics::ShapeFrame* unusedFrame : unusedChild.second.mFrames) {
547568
updateNeeded = true;

dart/collision/CollisionGroup.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,15 @@ class DART_API CollisionGroup
133133
void subscribeTo(
134134
const dynamics::ConstBodyNodePtr& bodyNode, const Others&... others);
135135

136-
/// Add ShapeFrames of skeleton, and also subscribe to the Skeleton so that
137-
/// the results from this CollisionGroup automatically reflect any changes
138-
/// that are made to skeleton.
136+
/// Add ShapeFrames of metaSkeleton, and also subscribe so that the results
137+
/// from this CollisionGroup automatically reflect any changes that are made
138+
/// to metaSkeleton.
139139
///
140140
/// This does likewise for the objects in ...others.
141-
//
142-
// TODO(MXG): Figure out how to determine a version number for MetaSkeletons
143-
// so that this function can accept a ConstMetaSkeletonPtr instead of only a
144-
// ConstSkeletonPtr.
145141
template <typename... Others>
146142
void subscribeTo(
147-
const dynamics::ConstSkeletonPtr& skeleton, const Others&... others);
143+
const dynamics::ConstMetaSkeletonPtr& metaSkeleton,
144+
const Others&... others);
148145

149146
/// Do nothing. This function is for terminating the recursive variadic
150147
/// template.
@@ -222,7 +219,7 @@ class DART_API CollisionGroup
222219
/// removed if no other source is requesting them for this group.
223220
template <typename... Others>
224221
void unsubscribeFrom(
225-
const dynamics::Skeleton* skeleton, const Others*... others);
222+
const dynamics::MetaSkeleton* skeleton, const Others*... others);
226223

227224
/// Do nothing. This function is for terminating the recursive variadic
228225
/// template.
@@ -236,7 +233,7 @@ class DART_API CollisionGroup
236233
/// Check if this is subscribed to skeleton and the other sources
237234
template <typename... Others>
238235
bool isSubscribedTo(
239-
const dynamics::Skeleton* skeleton, const Others*... others);
236+
const dynamics::MetaSkeleton* skeleton, const Others*... others);
240237

241238
/// Return true. This function is for terminating the recursive variadic
242239
/// template
@@ -471,6 +468,11 @@ class DART_API CollisionGroup
471468
friend class ShapeFrameObserver;
472469
void handleShapeFrameDestruction(const dynamics::ShapeFrame* shapeFrame);
473470

471+
/// Compute a version tag for MetaSkeletons even when they do not expose a
472+
/// VersionCounter interface.
473+
static std::size_t computeMetaSkeletonVersion(
474+
const dynamics::MetaSkeleton& metaSkeleton);
475+
474476
/// Set this to true to have this CollisionGroup check for updates
475477
/// automatically. Default is true.
476478
bool mUpdateAutomatically;

dart/collision/RaycastOption.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,23 @@ namespace dart {
3636
namespace collision {
3737

3838
//==============================================================================
39-
RaycastOption::RaycastOption(bool enableAllHits, bool sortByClosest)
40-
: mEnableAllHits(enableAllHits), mSortByClosest(sortByClosest)
39+
RaycastOption::RaycastOption(
40+
bool enableAllHits, bool sortByClosest, RaycastFilter filter)
41+
: mEnableAllHits(enableAllHits),
42+
mSortByClosest(sortByClosest),
43+
mFilter(std::move(filter))
4144
{
4245
// Do nothing
4346
}
4447

48+
//==============================================================================
49+
bool RaycastOption::passesFilter(const CollisionObject* object) const
50+
{
51+
if (!mFilter)
52+
return true;
53+
54+
return mFilter(object);
55+
}
56+
4557
} // namespace collision
4658
} // namespace dart

dart/collision/RaycastOption.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,35 @@
3535

3636
#include <dart/Export.hpp>
3737

38+
#include <functional>
3839
#include <memory>
3940

4041
#include <cstddef>
4142

4243
namespace dart {
4344
namespace collision {
4445

46+
class CollisionObject;
47+
4548
struct DART_API RaycastOption
4649
{
50+
using RaycastFilter = std::function<bool(const CollisionObject*)>;
51+
4752
/// Constructor
48-
RaycastOption(bool enableAllHits = false, bool sortByClosest = false);
53+
RaycastOption(
54+
bool enableAllHits = false,
55+
bool sortByClosest = false,
56+
RaycastFilter filter = nullptr);
57+
58+
/// Returns true when the filter is not set or allows the object.
59+
bool passesFilter(const CollisionObject* object) const;
4960

5061
bool mEnableAllHits;
5162

5263
bool mSortByClosest;
5364

54-
// TODO(JS): Add filter
65+
/// Optional filter to reject hits from specific collision objects.
66+
RaycastFilter mFilter;
5567
};
5668

5769
} // namespace collision

0 commit comments

Comments
 (0)