I may be at the end of my research on this.
I believe it is impossible. The persuasive comment on stackexchange.
I found the above linked answer to the following question:
How do I combine (in what order) the two sets of transformations into a third set t3, r3 and s3, such that mat4(t1, r1, s1) * mat4(t2, r2, s2) == mat4(t3, r3, s3), without actually converting to matrices?
To save you a click to the answer:
This is not possible in the general case when you have both non-90-degree rotations on the “first” transformation and non-uniform scale on the second transformation. This can result in a squash or stretch being applied diagonal to the coordinate axes, which a vec3 of axis-aligned scale values is insufficient to describe. See discussion in this Q&A for more details. [emphasis added]
I was thinking we could reduce the problem to reparenting the child to it’s grandparent. This way, we already have the decomposed values of both the child’s and parent’s local matrix. If the parent’s local transformations could be applied to the child’s already‐decomposed values, then the child’s parent is assigned to it’s grandparent. Done (but not possible in all cases).
My research adventure included reading mathematical descriptions to general problems regarding the theoretical math and generalized matrices that included shear. Those solutions (including Shoemake’s decomposition, polar decomposition (might be the same as polar decomposition), Gram -Schmidt orthogonalization, and QR decomposition) solved the mathematical problem, but the result cannot (for cases mentioned above) be expressed as only including scale, rotation, and translation in that order of application. My previous assertion that shear can be decomposed into rotation and non-uniform scaling overlooked the fact(?) that shear can be expressed as an initial rotation, then scaling, followed by another rotation. Given that Babylon (as well as the other popular 3D web-based frameworks) only represent transformations as SRT (also referred to as TRS representing the order of matrix multiplications?) and do NOT include shear NOR an additional pre-rotation, decomposing a matrix that is composed with transformations described in the above answer into Babylon-supported SRT is not possible.
I think this leads to a potential way forward, if the Babylon community wished to better accomodate non-uniform scaling. What if BABYLON supported shear as a fundamental transformation side by side with scale, rotation, and translation? The core GPU performance would be unmodified, I think, because, in the cases I’m familiar with, the GPU represents transformations as either translation (“position” vector in the case of vertices and PointsCloudSystem particles) or a full 16-float matrix (mesh/geometry, ThinInstance). If it’s true that the GPU does not ever use rotations or scale directly, then incorporating shear into tranformations is only on the CPU side when calculating the matrix to send to the GPU. This may have an adverse impact on some custom (vertex?) shaders, though, that assume or use decomposed SRT only.
It’s unclear to me how deep the assumption of “only SRT transformations” is. Perhaps it’s abstracted/isolated sufficiently in Matrix4 and TransformNode that making additions in these core functions is plausible. However, I do think dependant code (such as mesh.setParent()) will not be a small change. I wonder if abstracting Matrix components would be beneficial. Instead of decompose, for example, writing to three separate objects, it could write to an object like {scale,rotation,translation} then adding shear might be less traumatic.
If adding full support of non-uniform scales and shear constitutes a fully generalized matrix transformation/decomposition from/into a single set of transformations in a fixed order, then I think adding this support could set BABYLON apart from other frameworks.