Blend4Webs m_trans.set_matrix does not respect linear algebra
As it turned out recent Blend4Web (17.12.0) does not support non-uniform scaling (it will be added with the next release). Which also means: its 4D matrix module does not expose the real transformation entity, which it usess at its deepest abstraction.

General workaround:

However Blend4Web supports non-uniform scale animations exported from blender, and it is also possible to jump to a specific animation frame. So make a appropriate scale animation and wrote a code which interpolates between its frames.

Example:

I wrote a window-scaleresponsive input range GUI element with this method, the relevant code snippet should be rather simple for someone with a basic knowledge about the Blend4Web SDK.

function registerSliderResize(railObj, knobObj, frameNum) {

  var etalonRatio = 16 / 9;

  function resize() {

    var ratio = window.innerWidth / window.innerHeight;
    var frameInd = Math.floor(ratio / etalonRatio * frameNum);

    if (frameInd &gt; frameNum)
      frameInd = frameNum;
    else if (frameInd &lt; 1)
      frameInd = 1;

    // invert frameInd
    frameInd = frameNum - frameInd;

    m_anim.apply(railObj, "rail-resize", m_anim.SLOT_0);
    m_anim.set_behavior(railObj, m_anim.AB_FINISH_STOP, m_anim.SLOT_0);
    m_anim.play(railObj, null, m_anim.SLOT_0);
    console.log(frameInd);
    m_anim.set_frame(railObj, frameInd, m_anim.SLOT_0);
    m_anim.stop(railObj, m_anim.SLOT_0);

    m_anim.apply(knobObj, "knob-resize", m_anim.SLOT_0);
    m_anim.set_behavior(railObj, m_anim.AB_FINISH_STOP, m_anim.SLOT_0);
    m_anim.play(railObj, null, m_anim.SLOT_0);
    console.log(frameInd);
    m_anim.set_frame(railObj, frameInd, m_anim.SLOT_0);
    m_anim.stop(railObj, m_anim.SLOT_0);
  };

  resize();

  window.addEventListener("resize", resize);
}


The result:



Two non-uniformly scaled version of the same slider adapted to the window size, changed by Chromium inspector.

The whole project:

You can download the whole source code and the corresponding .blend file.