3DTileset rotation

For questions like this, it is usually very helpful to provide a Sandcastle that illustrates the problem. From only looking at the code, it may be hard or even impossible to understand what the problem is. A sandcastle and a clear description of the goal or desired behavior will make it much more likely to receive a helpful response.

As far as I understood, the intention is to have some sort of “editing functionality” for the position and orientation of the tileset. Specifically, you tried to rotate the tileset with mouse drags. And you did this by modifying the modelMatrix of the tileset.

The general approach seemed to be

  • move the tileset to the origin
  • apply the rotation
  • move the tileset back to its original position

That is generally the correct approach for “rotating something around its ‘local’ center in 3D”. And… this also worked for the tileset. That’s why it seemed to disappear :slight_smile:

There are different ways for positioning “geometry” (of a tileset) on the globe. And often, the position of the geometry is determined by the transform of the root node of the tileset. So even when the modelMatrix of a tileset is the identity matrix, the geometry may appear on a certain position on the globe, due to the root node transform.

When you then modify the modelMatrix so that it describes a small rotation, it will cause the tileset to be rotated “around the center of the earth”, and end up at a completely different position:

So in order to properly rotate a tileset, you have to take all transforms into account.

There are many transforms and many different representations of them. You might even have a tileset where the vertex positions store the actual positions on the globe. In this case, the following approach will not work. You’d have to compute the “origin” for the rotation … somehow.

But one approach that might be a solution for what you are trying to do:

  • Store the initial root.transform
  • Set the root.transform to be the identity matrix
  • Compute the desired rotation from the editing operations
  • Compute the current modelMatrix from the rotation and from the initial root transform

This could allow you to rotate a tileset like this:

Cesium Tileset Rotate

And … here is a Sandcastle for that:

Again: Depending on how exactly the “position of the geometry” is represented in the tileset, this approach might not work for all tilesets. But based on the example and the information in this post, you might be able to figure out a solution for other cases as well.

2 Likes