MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / UpdateCloths

Method UpdateCloths

Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp:1405–1456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1403}
1404
1405void 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

Callers 1

EndSimulateSceneMethod · 0.80

Calls 10

OnPostUpdateMethod · 0.80
GetPhysicsClothMethod · 0.80
incRefCountMethod · 0.80
decRefCountMethod · 0.80
IsEmptyMethod · 0.45
CountMethod · 0.45
UpdateBoundsMethod · 0.45
AddMethod · 0.45
RebuildMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected