Transformation Parameters

What are Transformation Parameters?

Transformation parameters are built-in parameters, that affect the location of a mesh, these are:

While re-locating imported meshes seems to be a very basic task it can sometimes be difficult to understand, how these transformation parameters are exactly applied.
Especially if the imported meshes already have transformations on their own or if the meshes are nested inside various sub-meshes.

So what about the initial transformations of the imported model?

It is very common that imported models already have altered transformation data.
There can be position offsets in order to fit the individual meshes of the model together.
Also a lot of 3D tools convert the models root rotation or scaling before exporting as GLB to fit certain specifications.

Now it's important to understand, that the viewer must keep these internal transformations, because otherwise the model would break.

Here is why

Let's assume you have an element with 2 meshes, one having an x-offset of 1 unit and the other one has an offset of 2 units.

Repositioning Start

Now you want to move the element 0.5 units, using the position parameter.
If the value of the position parameter would just directly be applied to the meshes, they would both end up on the same x position and the internal assignment would break.

Repositioning Wrong

Therefore the position parameter is applied relative to the initial mesh position.
In this example the resulting positions are 1.5 (1 + 0.5) and 2.5 (2 + 0.5).
As you can see the meshes are still connected and the model as a whole looks like before, just on a different position.

Repositioning Correct

It's worth mentioning that the position parameter will always be added to the initial position after importing.
So if you move the mesh multiple times the resulting position is not a sum of all these translations but always the last target position, added to the initial position.

Another thing to consider is that the position shift is applied in the World coordinate system.
That means even if you have a very deeply nested mesh, you don't have to worry about the parent structure and potential transformation offsets along the way.

How does the rotation work?

As you might have guessed, the rotation parameter is also applied relative to the rotation of the imported meshes.
But that's not the end of the story!
If this would be the only change, the model would still break, because the rotation is always done on the mesh origin.

Let's check out this issue on the following example.
There we have our 2 imported meshes again, but this time we want to rotate the combined model some degrees to the top.
The mesh origins are marked with a purple dot.

Rotation Start

If we just apply the rotation value to these two meshes, they will both rotate around their purple dot and the model breaks.

Rotation Wrong

What we do instead is to rotate both meshes around the World origin (red dot), in this way we make sure that the meshes stay together as a unit.

Rotation Correct

As you might have noticed the absolute position of the meshes has changed due to the rotation.
The absolute position is the vector between the red dot (World origin) and purple dots (mesh origin).
Whereas this vector has changed, the absolute distance, which is the "magnitude" of the vector, remained constant.

Finally the scaling parameter

The resulting scaling is again a combination of the initial scaling of the mesh and the scaling parameter value, whereas this time the values are multiplied.

For example if you want to scale down a mesh with an initial scaling of (10, 10, -10) to the half of the initial size, you have to insert (0.5, 0.5, 0.5).
This leads to a resulting scaling of (5, 5, -5).

But doesn't that break the model again?

Yep, it does, as shown in the following example.
Let's scale down the meshes to their half size.

Scaling Start

There will be gaps when only applying the scaling to the meshes itself.

Scaling Wrong

Instead we are also scaling down the distance to the World origin by the same amount.
This will "glue" the meshes together again, but also adjusts the absolute position of the meshes, just like it was the case with the rotation parameter.

Scaling Correct

What happens if all transformation parameters are applied at once?

The resulting transformation is more or less just a combination of the topics descibed above.
With the following rules in mind you should be fine to tackle more complex scenarios:

  • All transformation parameters are applied relative to the initial values of the mesh
  • All transformation parameters modify the mesh in World coordinates
  • Rotation and scaling also adjusts the absolute position of the meshes
  • Rotation and scaling is applied after the position parameter has been set

Tips and Tricks

It can be helpful to check out how the model and the meshes are located in their initial state, before adjusting the transformation parameters.
Then apply the transformation parameter afterwards one by one to get a good feeling, how the individual changes are affecting the model.
Start with the position parameter and add rotation and scaling afterwards.

We also recommend to temporarily activate the World coordinate system with the showWorldCoordinates function when checking the transformations.
In this way you can visualize the effect of the individual transformations on the model very clearly.

Generated using TypeDoc