| 1403 | } |
| 1404 | |
| 1405 | void ScenePhysX::UpdateCloths(float dt) |
| 1406 | { |
| 1407 | nv::cloth::Solver* clothSolver = ClothSolver; |
| 1408 | if (!clothSolver || ClothsList.IsEmpty()) |
| 1409 | return; |
| 1410 | PROFILE_CPU_NAMED("Physics.Cloth"); |
| 1411 | PROFILE_MEM(PhysicsCloth); |
| 1412 | |
| 1413 | { |
| 1414 | PROFILE_CPU_NAMED("Pre"); |
| 1415 | Function<void(int32)> job; |
| 1416 | job.Bind<ScenePhysX, &ScenePhysX::PreSimulateCloth>(this); |
| 1417 | JobSystem::Execute(job, ClothsList.Count()); |
| 1418 | } |
| 1419 | |
| 1420 | { |
| 1421 | PROFILE_CPU_NAMED("Simulation"); |
| 1422 | if (clothSolver->beginSimulation(dt)) |
| 1423 | { |
| 1424 | Function<void(int32)> job; |
| 1425 | job.Bind<ScenePhysX, &ScenePhysX::SimulateCloth>(this); |
| 1426 | JobSystem::Execute(job, clothSolver->getSimulationChunkCount()); |
| 1427 | clothSolver->endSimulation(); |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | { |
| 1432 | PROFILE_CPU_NAMED("Post"); |
| 1433 | ScopeLock lock(ClothLocker); |
| 1434 | Array<Cloth*> brokenCloths; |
| 1435 | for (auto clothPhysX : ClothsList) |
| 1436 | { |
| 1437 | const auto& clothSettings = Cloths[clothPhysX]; |
| 1438 | if (clothSettings.Culled) |
| 1439 | continue; |
| 1440 | if (clothSettings.UpdateBounds(clothPhysX)) |
| 1441 | brokenCloths.Add(clothSettings.Actor); |
| 1442 | clothSettings.Actor->OnPostUpdate(); |
| 1443 | } |
| 1444 | for (auto cloth : brokenCloths) |
| 1445 | { |
| 1446 | // Rebuild cloth object but keep fabric ref to prevent fabric recook |
| 1447 | auto fabric = &((nv::cloth::Cloth*)cloth->GetPhysicsCloth())->getFabric(); |
| 1448 | Fabrics[fabric].Refs++; |
| 1449 | fabric->incRefCount(); |
| 1450 | cloth->Rebuild(); |
| 1451 | fabric->decRefCount(); |
| 1452 | if (--Fabrics[fabric].Refs == 0) |
| 1453 | Fabrics.Remove(fabric); |
| 1454 | } |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | #endif |
| 1459 |
no test coverage detected