Correcting rotation of imported Cesium GLTF/GLB file in Three.js

1,054 views
Skip to first unread message

randy....@primitive.us

unread,
Jun 15, 2018, 2:38:28 PM6/15/18
to cesium-dev
I have a Cesium 3D tile set of buildings in Boston. Here is a sample tile: https://www.dropbox.com/s/cf9g1zi2wv7fhyb/model.glb?dl=1. When I import this tile into Three.js using THREE.GLTFLoader, the model is rotated relative to the XZ plane. Through trial and error, I have found that I can straighten the model out by rotating it as follows:

model.rotation.x = -Math.PI / 4;
model.rotation.z = Math.PI / 10;

I suspect this rotation is due to Cesiuim using Earth-fixed frame axes (ITRF) by default. How can I reverse this rotation automatically in Three.js (versus manually doing so via trial and error)?

Here is a screenshot of the model before I manually rotate it:

https://i.stack.imgur.com/eFyJ1.png

Here is a screenshot of the model after I manually rotate it:

https://i.stack.imgur.com/VaYDt.png

Here is the geospatial information associated with the Cesium 3D tile:

{
"boundingVolume":{"sphere":[1525116.05769,-4463608.36127,4278734.88048,28.30055]},
"geometricError":0.09375,
"content":{"url":"L12_0000110010123.b3dm"}
}

Gabby Getz

unread,
Jun 18, 2018, 4:14:39 PM6/18/18
to cesium-dev
Hi Randy,

Cesium 3D Tiles have a different coordinate reference system than glTF. Take a look at the Coordinate System section of the 3D Tiles Specification for the details and the necessary transformations.

randy....@primitive.us

unread,
Jun 19, 2018, 1:04:06 PM6/19/18
to cesium-dev
Thanks for your help. Here is what I ended up doing:

// Get the tile's cartesian center.
var cartesian = new Cesium.Cartesian3(1525116.05769, -4463608.36127, 4278734.88048);

// Get the tile's cartographic center.
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);

// Rotate the model.
model.rotation.x = -cartographic.latitude;
model.rotation.z = cartographic.longitude + Math.PI / 2;

Gabby Getz

unread,
Jun 21, 2018, 9:47:59 AM6/21/18
to cesium-dev
Thanks for the update, glad it's solved!

文文武

unread,
Sep 17, 2018, 10:24:10 AM9/17/18
to cesium-dev
thanks for your topic,I meet the same problem.
       double[] p = fun.XYZtoBL(rtc_center.X, rtc_center.Y, rtc_center.Z);

                    //count the rotation way in your value
                    double angleX = -p[1] / 180 * Math.PI;
                    double angleZ = p[0] / 180 * Math.PI +Math.PI / 2;

                    Vector3 t = new Vector3(v1, v2, v3);
                  //rotation the coordinate
                    Matrix4 m4 = Matrix4.RotateFromEuler(angleX,  0, angleZ);
                    Vector3 t2 = m4 * t;
                  
                    //translate the corrdinate by the cesium_rtc
                    t2.X += rtc_center.X;
                    t2.Y += rtc_center.Y;
                    t2.Z += rtc_center.Z;
                    //the ans geted not in the correct location
                    double[] ans = fun.XYZtoBL(t2.X, t2.Y, t2.Z);
there is the screenshot,the lable whit number shoud on the terrain if the answer is correct.my coordinate location is in china,is there some change should be apply to the rotation value? 
thank you for tour replay!

screenshot.png




在 2018年6月20日星期三 UTC+8上午1:04:06,randy....@primitive.us写道:

Omar Shehata

unread,
Sep 18, 2018, 10:04:06 AM9/18/18
to cesium-dev
This might be a slightly different problem. It's also a bit hard to tell what the issue is without a bit more context.

Can you open a new topic with a bit more context and perhaps a running Sandcastle example of your code?
Reply all
Reply to author
Forward
0 new messages