I’m struggling to change modelMatrix . My tileset is local coordinate system ,i want to transforms from the tile’s local coordinate system to the WGS84, my code as follow:
var cesiumViewer = new Cesium.Viewer(‘cesiumContainer’);
It’s hard to tell what the problem is exactly, but my guess is that the model’s vertices are not centered about (0,0,0). You may need to either adjust the model or adjust the sphere bounding volume. If you send over the tileset I could take a closer look.
I think the problem has to do with the modelMatrix offsetting the bounding sphere differently than the model.
I noticed the bounding sphere and model CESIUM_RTC use the same value ( -9.97391280580907, 4.1, 44.8553492029579) - so it seems like it would be correct. But what’s happening is the modelMatrix acts as a matrix multiply against the bounding’ sphere center, which causes it to rotate a bit. Meanwhile the modelMatrix is multiplied against the model’s origin (which is implicitly (0,0,0)), and THEN the CESIUM_RTC value is added. So the CESIUM_RTC is not affected by the rotational component of the modelMatrix. This slight difference is what causes the bounding sphere and model to be not aligned.
There are a couple approaches to fixing this:
Get rid of CESIUM_RTC and change the bounding sphere’s center to (0, 0, 0). In the tileset.json add a transform to the tile that has a translation of ( -9.97391280580907, 4.1, 44.8553492029579). This transform will be applied to both the bounding sphere and model and they will be aligned correctly. You can still set the tileset’s modelMatrix with this approach. I think this is the best approach to use in your case. https://github.com/AnalyticalGraphicsInc/3d-tiles#tile-transform
Bake the modelMatrix into both the bounding sphere and model’s geometry and CESIUM_RTC, and don’t use the modelMatrix in the code
Use a different center for the bounding sphere. I think this will require some matrix math to get right and will be dependent on the modelMatrix used.