CesiumGS / 3d-tiles

Specification for streaming massive heterogeneous 3D geospatial datasets :earth_americas:
2.09k stars 463 forks source link

Transformation clarification for glTF and b3dm #451

Closed chenkianwee closed 3 years ago

chenkianwee commented 3 years ago

transformation_confusion.zip This is the quote in the specification document.

Implementation note: when working with source data that is inherently z-up, such as data in WGS 84 coordinates or in a local z-up coordinate system, a common workflow is:

    Mesh data, including positions and normals, are not modified - they remain z-up.
    The root node matrix specifies a column-major z-up to y-up transform. This transforms the source data into a y-up coordinate      system as required by glTF.
    At runtime the glTF is transformed back from y-up to z-up with the matrix above. Effectively the transforms cancel out.

I am working with inherently z-up data. Following the suggestion, I have applied a z-up to y-up transformation in the gltf file. "nodes": [ { "mesh": 0, "matrix": [1,0,0,0, 0,0,-1,0, 0,1,0,0, 0,0,0,1] } ],

In my tile, as suggested I applied a transformation to flip the y-up to z-up, which should cancel out the transformation. I have also transformed my tile to my geo-location with the following.

{"boundingVolume": {"region": [-1.3030801391878386, 0.7041554118231639, -1.3030471625682685, 0.7041636827048515, 19.47514388523996, 85.09088445734233]}, 
"geometricError": 186.58280840556253, 
"transform": [1.0, 0.0, 0.0, 0.0, 
                    0.0, 0.0, -1.0, 0.0, 
                    0.0, 1.0, 0.0, 0.0, 
                    1287842.7921026754, -4694570.208870642, 4107320.9487041077, 1.0]
"content": {"uri": "tiles/01.b3dm"}
[transformation_confusion.zip](https://github.com/CesiumGS/3d-tiles/files/5921764/transformation_confusion.zip)

However, the result of this is confusing as shown in the image below. It is tilted at this 45 degree angle and it is not flat. I am confused with the transformation. Am I doing something wrong and mis-reading the instruction? I have attached my 3dtiles here if it helps. Thanks in advance.

image

lilleyse commented 3 years ago

That implementation note is mainly geared towards data in WGS84 ECEF coordinates, whereas yours is in a local ENU reference frame.

The changes you made to the glTF are still good, but the tile transform should be a matrix that transforms from local space back to global space, which will include a rotational component.

This sandcastle takes the center point and creates a fixed frame matrix: Sandcastle. If you use that transform as the tile transform it should be positioned better. You may need to make adjustments to the center point to have it be lined up perfectly.

Capture

One other thing to note is that the y-up to z-up transform happens automatically by the runtime engine so you don't need to include it in your tile transform.

chenkianwee commented 3 years ago

Thanks for the clarification. I have never worked with ECEF CS and this answer is really helpful in my understanding. Thanks!