Havok Engine getting body position without new memory allocation

I’m trying to optimize memory churning in a debug physics view that I’m creating (see this post and playgound.

In a memory allocation snapshot when PhysicsBodies are still active, a loop that synchronizes the debug mesh visualization with the physics body’s position and rotation, I use

        const btq = this.#havokPlugin._hknp.HP_Body_GetQTransform(bidTuple);

        // we could assign btq objects directly,
        // but copying using fromArray *might* avoid continuous object creation
        dm.position.fromArray(btq[1][0]);
        dm.rotationQuaternion.fromArray(btq[1][1]);

It looks like HP_Body_GetQTransform() is internally allocating on each call either the btq array itself or the arrays within it.

Is there a way to retrieve a body’s position and rotation from the Havok Engine itself without any new allocations? If I can get the pairing of BodyId to position and rotation, I could accomodate retrieving in bulk.

1 Like

I haven’t explored these functions yet, though it’s possible they could be useful here?

In havokPlugin.ts:

Thank you. That is my next step. I couldn’t figure out how to make those work, but I can review the Plugin more carefully to see how it uses these. Maybe frame-by-frame PhysicsBody is available as a HEAP buffer where I can just pull what is needed.

1 Like