| 1201 | #if WITH_CLOTH |
| 1202 | |
| 1203 | void ScenePhysX::PreSimulateCloth(int32 i) |
| 1204 | { |
| 1205 | PROFILE_CPU(); |
| 1206 | PROFILE_MEM(PhysicsCloth); |
| 1207 | auto clothPhysX = ClothsList[i]; |
| 1208 | auto& clothSettings = Cloths[clothPhysX]; |
| 1209 | if (!clothSettings.Actor) |
| 1210 | return; |
| 1211 | |
| 1212 | if (clothSettings.Actor->OnPreUpdate()) |
| 1213 | { |
| 1214 | // Cull simulation based on distance |
| 1215 | if (!clothSettings.Culled) |
| 1216 | { |
| 1217 | clothSettings.Culled = true; |
| 1218 | ClothLocker.Lock(); |
| 1219 | ClothSolver->removeCloth(clothPhysX); |
| 1220 | ClothLocker.Unlock(); |
| 1221 | } |
| 1222 | return; |
| 1223 | } |
| 1224 | if (clothSettings.Culled) |
| 1225 | { |
| 1226 | clothSettings.Culled = false; |
| 1227 | ClothLocker.Lock(); |
| 1228 | ClothSolver->addCloth(clothPhysX); |
| 1229 | ClothLocker.Unlock(); |
| 1230 | } |
| 1231 | |
| 1232 | // Setup automatic scene collisions with colliders around the cloth |
| 1233 | if (clothSettings.SceneCollisions && clothSettings.CollisionsUpdateFramesLeft == 0) |
| 1234 | { |
| 1235 | PROFILE_CPU_NAMED("Collisions"); |
| 1236 | clothSettings.CollisionsUpdateFramesLeft = CLOTH_COLLISIONS_UPDATE_RATE; |
| 1237 | if (clothSettings.CollisionsUpdateFramesRandomize) |
| 1238 | { |
| 1239 | clothSettings.CollisionsUpdateFramesRandomize = false; |
| 1240 | clothSettings.CollisionsUpdateFramesLeft = i % CLOTH_COLLISIONS_UPDATE_RATE; |
| 1241 | } |
| 1242 | |
| 1243 | // Reset existing colliders |
| 1244 | clothPhysX->setSpheres(nv::cloth::Range<const PxVec4>(), 0, clothPhysX->getNumSpheres()); |
| 1245 | clothPhysX->setPlanes(nv::cloth::Range<const PxVec4>(), 0, clothPhysX->getNumPlanes()); |
| 1246 | clothPhysX->setTriangles(nv::cloth::Range<const PxVec3>(), 0, clothPhysX->getNumTriangles()); |
| 1247 | |
| 1248 | // Setup environment query |
| 1249 | const bool hitTriggers = false; |
| 1250 | const bool blockSingle = false; |
| 1251 | PxQueryFilterData filterData; |
| 1252 | filterData.flags |= PxQueryFlag::ePREFILTER; |
| 1253 | filterData.data.word1 = blockSingle ? 1 : 0; |
| 1254 | filterData.data.word2 = hitTriggers ? 1 : 0; |
| 1255 | filterData.data.word0 = Physics::LayerMasks[clothSettings.Actor->GetLayer()]; |
| 1256 | const PxTransform clothPose(clothPhysX->getTranslation(), clothPhysX->getRotation()); |
| 1257 | const PxVec3 clothBoundsPos = clothPhysX->getBoundingBoxCenter(); |
| 1258 | const PxVec3 clothBoundsSize = clothPhysX->getBoundingBoxScale(); |
| 1259 | const PxTransform overlapPose(clothPose.transform(clothBoundsPos), clothPose.q); |
| 1260 | const float boundsMargin = 1.6f; // Pick nearby objects |
nothing calls this directly
no test coverage detected