Hi there!
I’ve got a strange problem recently.
I create a custom filter shader following the submarine sample, however, it(MyEngineFilterShader) doesn’t get called.
I don’t know whether there’s some false configuration here.
Here is the code dong its job. I really need help. Thank you guys!
class TryClass : public PxSimulationEventCallback, public PxDeletionListener
{
......
}
PxFilterFlags MyEngineFilterShader(
PxFilterObjectAttributes attributes0, PxFilterData filterData0,
PxFilterObjectAttributes attributes1, PxFilterData filterData1,
PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize)
{
//OutputDebugStringW(L"MyEngineFilterShader");
// let triggers through
if (PxFilterObjectIsTrigger(attributes0) || PxFilterObjectIsTrigger(attributes1))
{
pairFlags = PxPairFlag::eTRIGGER_DEFAULT;
return PxFilterFlag::eDEFAULT;
}
// generate contacts for all that were not filtered above
pairFlags = PxPairFlag::eCONTACT_DEFAULT;
// trigger the contact callback for pairs (A,B) where
// the filtermask of A contains the ID of B and vice versa.
if ((filterData0.word0 & filterData1.word1) && (filterData1.word0 & filterData0.word1))
pairFlags |= PxPairFlag::eNOTIFY_TOUCH_FOUND;
return PxFilterFlag::eDEFAULT;
}
void TryClass::Init()
{
bool recordMemoryAllocations = true;
const bool useCustomTrackingAllocator = true;
PxAllocatorCallback* allocator = &gDefaultAllocatorCallback;
if (useCustomTrackingAllocator)
allocator = GetAllocator(); //optional override that will track memory allocations
mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, *allocator, getSampleErrorCallback());
if (!mFoundation)
MessageBox(0, L"PxCreateFoundation failed!", 0, 0);
mProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mFoundation);
if (!mProfileZoneManager)
MessageBox(0, L"PxProfileZoneManager::createProfileZoneManager failed!", 0, 0);
PxTolerancesScale scale;
mPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, scale, recordMemoryAllocations, mProfileZoneManager);
if (!mPhysicsSDK)
MessageBox(0, L"PxCreatePhysics failed!", 0, 0);
if (!PxInitExtensions(*mPhysicsSDK))
MessageBox(0, L"PxInitExtensions failed!", 0, 0);
PxCookingParams params(scale);
params.meshWeldTolerance = 0.001f;
params.meshPreprocessParams = PxMeshPreprocessingFlags(PxMeshPreprocessingFlag::eWELD_VERTICES | PxMeshPreprocessingFlag::eREMOVE_UNREFERENCED_VERTICES | PxMeshPreprocessingFlag::eREMOVE_DUPLICATED_TRIANGLES);
mCooking = PxCreateCooking(PX_PHYSICS_VERSION, *mFoundation, params);
if (!mCooking)
MessageBox(0, L"PxCreateCooking failed!", 0, 0);
if (mPhysicsSDK->getPvdConnectionManager())
mPhysicsSDK->getPvdConnectionManager()->addHandler(*this);
mPhysicsSDK->registerDeletionListener(*this, PxDeletionEventFlag::eUSER_RELEASE);
mMaterial = mPhysicsSDK->createMaterial(0.5f, 0.5f, 0.1f);
if (!mMaterial)
MessageBox(0, L"createMaterial failed!", 0, 0);
PxSceneDesc sceneDesc(mPhysicsSDK->getTolerancesScale());
sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
PxU32 nbThreads = 1;
if (!sceneDesc.cpuDispatcher)
{
mCpuDispatcher = PxDefaultCpuDispatcherCreate(nbThreads);
if (!mCpuDispatcher)
MessageBox(0, L"PxDefaultCpuDispatcherCreate failed!", 0, 0);
sceneDesc.cpuDispatcher = mCpuDispatcher;
}
sceneDesc.filterShader = MyEngineFilterShader;
sceneDesc.simulationEventCallback = this;
sceneDesc.flags |= PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
mScene = mPhysicsSDK->createScene(sceneDesc);
if (!mScene)
MessageBox(0, L"createScene failed!", 0, 0);
mScene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1.0); //Global visualization scale which gets multiplied with the individual scales
mScene->setVisualizationParameter(PxVisualizationParameter::eCOLLISION_SHAPES, 1.0f); //Enable visualization of actor's shape
mScene->setVisualizationParameter(PxVisualizationParameter::eACTOR_AXES, 1.0f);
}
and in the main game loop
mScene->simulate(1.0f / 600.0f); //Advances the simulation by 'gTimeStep' time
result = mScene->fetchResults(true); //Block until the simulation run is completed