How to manipulate the modelMatrix for a 3DTile tileset

As the title says, I am trying to manipulate the modelMatrix of a 3DTile tileset. I keep seeing posts online that are telling me that “the transformations, rotations, and scaling can be changed using the modelMatrix” but what does each value actually correlate to the in the matrix??

Hi @lkaval,

The Matrix4 API has several functions to get / set the transformation properties in the matrix. In particular, you can use getTranslation / setTranslation, getRotation / setRotation, and getScale / setScale without having to worry about what values in the matrix correspond to what.

https://cesium.com/learn/cesiumjs/ref-doc/Matrix4.html

However, to answer your question more thoroughly, the scale and rotation are stored in the upper left 3x3 sub-matrix of the Matrix4. This can be retrieved with getMatrix3. The translation is stored in the fourth column of the Matrix4, which can be retrieved with getColumn, though you would have to ignore the last component because it’s always set to 1 as a special value. In other words, if I have a model matrix that looks like this:

 m = [A, B, C, D]
     [E, F, G, H]
     [J, K, L, M]
     [N, P, Q, R]

Then the scale / rotation component of the model matrix would be:

[A, B, C]
[E, F, G]
[J, K, L]

and the translation component would be [D, H, M]. The row [N, P, Q, R] are always set to [0, 0, 0, 1] in a valid model matrix, so realistically you’ll have a model matrix that looks like so:

 m = [A, B, C, D]
     [E, F, G, H]
     [J, K, L, M]
     [0, 0, 0, 1]

Hope that answers your question!