Skip to content

Commit e541b87

Browse files
committed
CollisionSpace: add 2 public methods to manage overlap filtering
1 parent 97335a5 commit e541b87

5 files changed

Lines changed: 95 additions & 2 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ is Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
77
All rights reserved.
88

99
The buildSrc, src/main/java/jme3utilities, and src/test software
10-
are Copyright (c) 2013-2025 Stephen Gold
10+
are Copyright (c) 2013-2026 Stephen Gold
1111
All rights reserved.
1212

1313
The src/main/java/vhacd and src/main/java/vhacd4 software

src/main/java/com/jme3/bullet/CollisionSpace.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ public boolean isForceUpdateAllAabbs() {
452452
return isForceUpdateAllAabbs(spaceId);
453453
}
454454

455+
/**
456+
* Test whether the {@code needsCollision()} callback is enabled.
457+
*
458+
* @return true if it's enabled, otherwise false
459+
*/
460+
public boolean isOverlapFilterEnabled() {
461+
long spaceId = nativeId();
462+
boolean result = isOverlapFilterEnabled(spaceId);
463+
464+
return result;
465+
}
466+
455467
/**
456468
* Test whether the "deterministic overlapping pairs" option is enabled in
457469
* the collision dispatcher (native field: m_deterministicOverlappingPairs).
@@ -668,6 +680,17 @@ public static void setLocalThreadPhysicsSpace(CollisionSpace space) {
668680
physicsSpaceTL.set(space);
669681
}
670682

683+
/**
684+
* Alter whether the {@code needsCollision()} callback is enabled.
685+
*
686+
* @param enable true to enable the callback, or false to skip it
687+
* (default=true)
688+
*/
689+
public void setOverlapFilterEnabled(boolean enable) {
690+
long spaceId = nativeId();
691+
setOverlapFilterEnabled(spaceId, enable);
692+
}
693+
671694
/**
672695
* Alter the flags used in ray tests (native field: m_flags).
673696
*
@@ -858,6 +881,8 @@ native private long createCollisionSpace(
858881

859882
native private static boolean isForceUpdateAllAabbs(long spaceId);
860883

884+
native private static boolean isOverlapFilterEnabled(long spaceId);
885+
861886
native private static int pairTest(long spaceId, long aId, long bId,
862887
PhysicsCollisionListener listener);
863888

@@ -874,6 +899,9 @@ native private static void rayTestNativeDp(
874899
native private static void setDeterministicOverlappingPairs(
875900
long spaceId, boolean desiredSetting);
876901

902+
native private static void setOverlapFilterEnabled(
903+
long spaceId, boolean enable);
904+
877905
native private static void
878906
setForceUpdateAllAabbs(long spaceId, boolean desiredSetting);
879907

src/main/native/glue/com_jme3_bullet_CollisionSpace.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,30 @@ JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_CollisionSpace_isForceUpdateAllA
299299
return pWorld->getForceUpdateAllAabbs();
300300
}
301301

302+
/*
303+
* Class: com_jme3_bullet_CollisionSpace
304+
* Method: isOverlapFilterEnabled
305+
* Signature: (J)Z
306+
*/
307+
JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_CollisionSpace_isOverlapFilterEnabled
308+
(JNIEnv *pEnv, jclass, jlong spaceId) {
309+
jmeCollisionSpace * const
310+
pSpace = reinterpret_cast<jmeCollisionSpace *> (spaceId);
311+
NULL_CHK(pEnv, pSpace, "The collision space does not exist.", JNI_FALSE);
312+
btCollisionWorld * const pWorld = pSpace->getCollisionWorld();
313+
NULL_CHK(pEnv, pWorld, "The collision world does not exist.", JNI_FALSE)
314+
btOverlappingPairCache * const pPairCache = pWorld->getPairCache();
315+
NULL_CHK(pEnv, pPairCache, "The pair cache does not exist.", JNI_FALSE)
316+
317+
const btOverlapFilterCallback *
318+
pOFCallback = pPairCache->getOverlapFilterCallback();
319+
if (pOFCallback) {
320+
return JNI_TRUE;
321+
} else {
322+
return JNI_FALSE;
323+
}
324+
}
325+
302326
/*
303327
* Class: com_jme3_bullet_CollisionSpace
304328
* Method: pairTest
@@ -486,6 +510,30 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_CollisionSpace_setDeterministicOverl
486510
dispatchInfo.m_deterministicOverlappingPairs = (bool)desiredSetting;
487511
}
488512

513+
/*
514+
* Class: com_jme3_bullet_CollisionSpace
515+
* Method: setOverlapFilterEnabled
516+
* Signature: (JZ)V
517+
*/
518+
JNIEXPORT void JNICALL Java_com_jme3_bullet_CollisionSpace_setOverlapFilterEnabled
519+
(JNIEnv *pEnv, jclass, jlong spaceId, jboolean enable) {
520+
jmeCollisionSpace * const
521+
pSpace = reinterpret_cast<jmeCollisionSpace *> (spaceId);
522+
NULL_CHK(pEnv, pSpace, "The collision space does not exist.",);
523+
btCollisionWorld * const pWorld = pSpace->getCollisionWorld();
524+
NULL_CHK(pEnv, pWorld, "The collision world does not exist.",)
525+
btOverlappingPairCache * const pPairCache = pWorld->getPairCache();
526+
NULL_CHK(pEnv, pPairCache, "The pair cache does not exist.",)
527+
528+
btOverlapFilterCallback *
529+
pOFCallback = pPairCache->getOverlapFilterCallback();
530+
if (pOFCallback) {
531+
delete pOFCallback; //dance011
532+
}
533+
pOFCallback = enable ? new jmeFilterCallback() : NULL;
534+
pPairCache->setOverlapFilterCallback(pOFCallback); //dance011
535+
}
536+
489537
/*
490538
* Class: com_jme3_bullet_CollisionSpace
491539
* Method: setForceUpdateAllAabbs

src/main/native/glue/com_jme3_bullet_CollisionSpace.h

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/java/TestLibbulletjme.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2020-2025 Stephen Gold
2+
Copyright (c) 2020-2026 Stephen Gold
33
All rights reserved.
44
55
Redistribution and use in source and binary forms, with or without
@@ -2150,6 +2150,7 @@ private static void verifyCollisionSpaceDefaults(CollisionSpace space) {
21502150
Assert.assertEquals(
21512151
RayTestFlag.SubSimplexRaytest, space.getRayTestFlags());
21522152
Assert.assertTrue(space.isForceUpdateAllAabbs());
2153+
Assert.assertTrue(space.isOverlapFilterEnabled());
21532154
Assert.assertFalse(space.isUsingDeterministicDispatch());
21542155
}
21552156

0 commit comments

Comments
 (0)