Stress Solver (NvBlastExtStress)

The Blast™ stress solver extension provides an implementation of a quite fast and easy to use stress solver which works directly with the bond graph. It simulates more complex damage model on support graph by allowing to apply forces on nodes of the support graph (on chunks). The most common usage is just applying gravity force on a static construction so that it will fall apart at some point when the carcass cannot hold anymore. Dynamic actors are also supported, you could for example add centrifugal force so that rotating an object fast enough will break bonds.

It also can be used as another way to apply impact damage, which can give the visually pleasant result of an actor breaking in a weak place instead of the place of contact.


Features


Settings Tuning

Computational time is linearly proportional to the bondIterationsPerFrame setting. To fine tune, look for balance between bondIterationsPerFrame and graphReductionLevel . The more bond iterations are set, the more precise the computation will be. The smaller graph allows to make higher fidelity computations within the same bond iterations per frame (same time spent), but actual cracks (damaged bonds) will be more sparse as the result.

Debug render can help a lot for tuning, consider using stressSolver->fillDebugRender(...) for that.


Usage

In order to use the stress solver, create an instance with ExtStressSolver::create(...).

ExtStressSolver* stressSolver = ExtStressSolver::create(family, settings);

ExtStressSolverSettings are passed in create function, but also can be changed at any time with stressSolver->setSettings(...).

It fully utilizes the fact that it knows the initial support graph structure and does a maximum of processing in the create(...) method call. After that, all actor split calls are synchronized internally and efficiently so only the actual stress propagation takes most of computational time.

You need to provide physics specific information (mass, volume, position, static) for every node in support graph since Blast™ itself is physics agnostic. There are two ways to do it. One way is to call stressSolver->setNodeInfo(...) for every graph node. The other way is to call stressSolver->setAllNodesInfoFromLL() once: all the data will be populated using NvBlastAsset chunk's data, in particular volume and centroid. All nodes connected to 'world' chunk are marked as static.

stressSolver->setAllNodesInfoFromLL();

Stress solver needs to keep track for actor create/destroy events in order to update its internal stress graph accordingly. So you need to call stressSolver->notifyActorCreated(actor) and stressSolver->notifyActorDestroyed(actor) every time an actor is created or destroyed, including the initial actor the family had when the stress solver was created. There is no need to track actors which contain only one or less graph nodes. In that case notifyActorCreated(actor) returns 'false' as a hint. It means that the stress solver will ignore them, as for those actors applying forces does not make any sense.

A typical update loop looks like this:

  1. If split happened, call relevant stressSolver->notifyActorCreated(actor) and stressSolver->notifyActorDestroyed(actor)
  2. Apply all forces, use stressSolver->addForce(...), stressSolver->addGravityForce(...), stressSolver->addAngularVelocity(...)
  3. Call stressSolver->update(). This is where all expensive computation takes place.
  4. If stressSolver->getOverstressedBondCount() > 0, use one of stressSolver->generateFractureCommands() methods to get bond fracture commands and apply them on actors.

Example code from ExtPxStressSolverImpl:

void ExtPxStressSolverImpl::onActorCreated(ExtPxFamily& /*family*/, ExtPxActor& actor)
{
    if (m_solver->notifyActorCreated(*actor.getTkActor().getActorLL()))
    {
        m_actors.insert(&actor);
    }
}

void ExtPxStressSolverImpl::onActorDestroyed(ExtPxFamily& /*family*/, ExtPxActor& actor)
{
    m_solver->notifyActorDestroyed(*actor.getTkActor().getActorLL());
    m_actors.erase(&actor);
}

void ExtPxStressSolverImpl::update(bool doDamage)
{
    for (auto it = m_actors.getIterator(); !it.done(); ++it)
    {
        const ExtPxActor* actor = *it;

        PxRigidDynamic& rigidDynamic = actor->getPhysXActor();
        const bool isStatic = rigidDynamic.getRigidBodyFlags() & PxRigidBodyFlag::eKINEMATIC;
        if (isStatic)
        {
            PxVec3 gravity = rigidDynamic.getScene()->getGravity();
            PxVec3 localGravity = rigidDynamic.getGlobalPose().rotateInv(gravity);

            m_solver->addGravityForce(*actor->getTkActor().getActorLL(), localGravity);
        }
        else
        {
            PxVec3 localCenterMass = rigidDynamic.getCMassLocalPose().p;
            PxVec3 localAngularVelocity = rigidDynamic.getGlobalPose().rotateInv(rigidDynamic.getAngularVelocity());
            m_solver->addAngularVelocity(*actor->getTkActor().getActorLL(), localCenterMass, localAngularVelocity);
        }
    }

    m_solver->update();

    if (doDamage && m_solver->getOverstressedBondCount() > 0)
    {
        NvBlastFractureBuffers commands;
        m_solver->generateFractureCommands(commands);
        if (commands.bondFractureCount > 0)
        {
            m_family.getTkFamily().applyFracture(&commands);
        }
    }
}

Have a look at ExtPxStressSolver implementation code, which is basically a high level wrapper on NvBlastExtStress to couple it with PhysX™ and NvBlastExtPx extension (see extpxstresssolver).