# 3DTileset rotation

**URL:** <https://community.cesium.com/t/3dtileset-rotation/27554>\
**Category:** CesiumJS\
**Created:** [October 23, 2023, 1:26pm UTC](https://community.cesium.com/t/3dtileset-rotation/27554 "2023-10-23T13:26:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [November 14, 2023, 3:11pm UTC](https://community.cesium.com/t/3dtileset-rotation/27554/2 "2023-11-14T15:11:59Z")

</div>

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 🙂

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:

 ![Cesium Tileset Rotate 001](https://global.discourse-cdn.com/cesium/original/3X/9/7/979aea42c50f0b213a6c0c388e7e0757db7a9a34.png)

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](https://global.discourse-cdn.com/cesium/original/3X/3/0/307bb9c880b51fd7f4d2f28d19d7382b69043329.gif)

And … here is a Sandcastle for that:

> **[Cesium Sandcastle](https://sandcastle.cesium.com/index.html#c=nVZtj9o4EP4rPj5UQeLM9baqTgVWXbGcbqVSqoVt1VOkysQD655jR7Zhoaf+9xvHSUiygav6heDxvDzz7kQr68hewBMYMiEKnsgUrNil9GNOi+Jekp+nWjkmFJi4NyD/xooQB8Yg5U0psApnujE6/aSN5AUh6g9i9b0/ilWshkNyKyxbSyDuEQhq30q9hrjXJ0Y75oRWZKMNkbBxJNU7C4QbtrWxChCpTUAB/hoAtcxYAlOWgmEendFSIgcor/7eawP0aMOkhdy2BEeckGDxOyENfZkRqXBiD5YyziPvHXtiwpWuhc/V7SqI5y7eaXVj8XDHo1e//fH6dT9WlY9Lp03w0BmmLHqUEr3JCUZrR5TmUBBy/hIWszlP3Mu5Klkfcmat2Cq8FjYXKViFQtxMYqw44C9zRhyQWXHi9VX6z6NwmqwDVMFBOeGOsUryovA8q0pwUsZintt4RROpFUQFcuqZaWXGB6K8yZEFoXNKGpbqsk2t58RbxLvb2fvV3eqzVxQ82eykvC/K6zKSC6pCAVmQkDjgRSWMArXIwtwX7AdthTdUWQ8FWfk34wKrAwE4swuFGdgeMWmy3YTLU6HP9pievwJT1KjehKk9swFjoYX6wlTZzt0kHkvE7FElJEqkSP7pk8l16OBgOEMa8MX6Kzr2rDHwLkjRrPDL2yFEbEjU7diLF02NeP6lTqCC94N50o4mWm9wVm05CuxdYT5lcsqMw39M/V4kswv3dxxFg3PRXR0zoO9mf66+3C4+vb8Y0HYon3uisOhCqLpRF/c/gubhw2Usqd5DihInOD49bUiYiC4oVTJCNeTdJlkJ8lSKVXivon6Rj1a3bCF0cZBu268PgkHdTPDthID77ixdwnHOS6T0QH7tdIEeRnUFR/bU6O9H6vQ94wjdRvxwMoeDcapTjCMUM7FYQPUpmu6kE5k8EuEqIRyZYUr7udIWi3t1KOXlVXvgXOU7pBxKf0eIuT/qkjw3r+riUWXm5FyLvfQjCrekYyYOyivTTX4uEW7OBtQXT30vEY857KSCu7nm8oB7wc641mKDiuf/v1UuzPJLAWoso0FXnFr2G/7fZL5YurzvnHit7dhUXNf7kHH/numcJf7BFCweXNU4PzUxu7ruR+fmfPGwnH2ZLz7OQkCKPfJN63Sly3eCv+oNemPrjhKuy8p6K9JMG0d2RkaUDh2kGY4GsMP1DreBo4m1ZdbGw7romIs9vlsmHY9Ukkh8Mk1Cky7FN3xjXo+HyP9MVGqcDWq72IOR7OjZHl9evwtESul4iMduSae1XDPT0vwf)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

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.

---

_[View the full topic](https://community.cesium.com/t/3dtileset-rotation/27554)._
