Havok: Understanding `syncTransform()` in `havokPlugin.ts` source

syncTransform() in havokPlugin.ts

syncTransform(body: PhysicsBody, transformNode: TransformNode): void {
    if (body._pluginDataInstances.length) {
        // HEAPU8 buffer reading and Instance matrix setting
        // Why do we have this if block portion?
        // ...
    } else {
        try {
            // regular
            const bodyTransform = this._hknp.HP_Body_GetQTransform(body._pluginData.hpBodyId)[1];
            // ...

I’m trying to learn Babylon’s source for the Havok plugin. For this function, I was wondering why we don’t always use HP_Body_GetQTransform()? I’m curious about the purpose of the portion above where we read the HEAPU8 buffer.

Thank you all for helping to learn and understand this!

cc @Cedric

In the case where a PhysicsBody is used with Thin Instances (and not just 1 mesh), then syncTransform will copy matrix datas from Havok into the Instances buffer. Instances use 4x4 matrices for rendering and not Quaternion/Translation.
For single Mesh, the regular is to get Quaternion/Translation and apply it to the Node Transform infos.

1 Like

Thank you so much, @Cedric!