Stress Solver Extension (NvBlastExtStress)

The Blast™ stress solver extension provides implementation of quite fast and easy to use stress solver which works directly with bond graph. It simulates more complex damage model on support graph by allowing to apply forces on nodes of 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 carcass can't hold anymore. Dynamic actors are also supported, you could for example add centrifugal force so that rotating object fast enough will break bonds.

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


Features


Settings Tuning

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

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


Usage

In order to use it 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 initial support graph structure and does maximum of processing in create(...) method calls. After that all actors split calls are synced internally quite fast and only the actual stress propagation takes most of computational time.

Then 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, you can call stressSolver->setNodeInfo(...) for every graph node. Another was is to call stressSolver->setAllNodesInfoFromLL() once all the data will be populated using NvBlastAsset chunk's data, in particular volume and centroid are used. 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 it's internal stress graph accordingly. So you need to call stressSolver->notifyActorCreated(actor) and stressSolver->notifyActorDestroyed(actor) every time actor is created or destroyed including the initial actor family had when stress solver were created. There is no need to track actors which contain only one or lesser graph nodes in that case notifyActorCreated(actor) returns 'false' as a hint, it means that stress solver will ignore them. For those actors applying forces is also doesn't make any sense.

Typical update loop would can look like this:

  1. If split happend 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 happens.
  4. If stressSolver->getOverstressedBondCount() > 0 use one of stressSolver->generateFractureCommands() methods to get bond fracture commands and apply on them 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 high level wrapper on NvBlastExtStress to couple it with PhysX™ and NvBlatExtPx extension (see ExtPxStressSolver).