Place a GLTF georeferenced file

Hello everyone.

I have a gltf mesh file, which has been georeferenced by setting the vertices of geometry as coordinates.

in my case it is Georeferenced using EPSG:23032 , which I know is NOT used by Cesium so I can expect to don’t see it if trying to load the model.

so using GLTFLoader and GLTFExporter, I tried to convert the vertices of GLTF file to EPSG:4326, and also to EPSG:4978, but in both cases I can not see the model.

this what I am doing roughly:

function defineProj4EPSG(epsgCode: string, projString: string) {
        if (!proj4.defs(epsgCode)) {
            proj4.defs(epsgCode, projString);
        }
    }

    function transformVertices(gltf: THREE.Group, sourceEPSG: string, targetEPSG: string) {
        defineProj4EPSG("EPSG:23032", "+proj=utm +zone=32 +datum=ED50 +units=m +no_defs"); // Example UTM
        defineProj4EPSG( "EPSG:4326", "+proj=longlat +datum=WGS84 +no_defs"); // WGS84
        defineProj4EPSG("EPSG:4978", "+proj=geocent +datum=WGS84 +units=m +no_defs"); // ECEF


        gltf.traverse((child: any) => {
          if (child.isMesh) {
            const geometry = child.geometry;
            const positionAttribute = geometry.attributes.position;
      
            const newPositions = new Float32Array(positionAttribute.count * 3);
      
            for (let i = 0; i < positionAttribute.count; i++) {
              const vertex = new THREE.Vector3().fromBufferAttribute(positionAttribute, i);
              const [x, y, z] = proj4(sourceEPSG, "EPSG:4978", [vertex.x, vertex.y, vertex.z]);
              newPositions[i * 3] = x;
              newPositions[i * 3 + 1] = y;
              newPositions[i * 3 + 2] = z;

            }
            geometry.setAttribute('position', new THREE.BufferAttribute(newPositions, 3));
            geometry.attributes.position.needsUpdate = true;

           
          }
        });
      
        return gltf;
      }

I read a lot of topics about it, but I still have not figured out what is the best way to handle such files, (here some topics I read: 1 , 2, and lots of others topics about it)

I understand that using cesium ion API I can set the model wherever I want, but shouldn’t these already georeferenced files be positioned correctly “automatically” (or just setting in an api the EPSG reference code, and eventually an offset) ?

or I MUST have the models in local coordinates?

in my case, who gave us the files (gltf and las) also gave us a metadata xml file, with the following content:

<ModelMetadata version="1">
<!-- Spatial Reference System -->
<SRS>EPSG:23032</SRS>
<!-- Origin in Spatial Reference System -->
<SRSOrigin>0,0,0</SRSOrigin>
<Texture>
<ColorSource>Visible</ColorSource>
</Texture>
</ModelMetadata>

I don’t see how these files could be useful at this point.

I tried to upload everything on Ion, and try to move it from there, but the position is wrong, and there is an enormous offset between the position of the mesh and the handles to move the mesh.

in order to be more clear, I will share with you my files.
As a new user I can not upload files here, so I will leave here a wetransfer link, with validity for 7 days:
georef GLTF, LAS and metadata xml

thank you in advance for the support

In the meantime, I uploaded to Ion a Las file with that xml file, and it has been positioned correctly.
I just tried without knowing exactly what I was doing.
But how do I find all the indication/settings/combinations of files to use to position a model on the globe?

still with the gltf I have the same issue.

Hi there,

Since this seems to be a more data-oriented question and you are using Cesium ion, I’m moving this to the Cesium ion category. The developers there should be able to provide more support around the workflow.

Thanks!

Coordinate system transforms are complicated. I don’t know many of the details that may be necessary for answering the specific question.

But a more general hint: You should not encode geographic positions in the vertex positions of the gometry data.

When you drag-and-drop the GLB into https://gltf.report/ and rotate view slightly, you’ll see why:

Cesium Forum 38966 Georeferenced glTF Forum

That wiggling and jittering comes from the vertex positions just containing values that are too large to sensibly be represented as 32 bit floating point values. (You can see the large values, in the range of ~500000, for the bounding box at the end of the screencap).

For technical details (and how to avoid that on a technical level) you can refer to Precisions, Precisions | DME Component Libraries for .NET 2024 r3


That said: You should really try to export this glTF without any georeferencing, if possible. The generator of that glTF says “Agisoft Metashape” (which is probably unrelated to the ‘AGI’ from the link above…). I don’t know this tool, and quick searches did not reveal the answer of how to do this, but maybe you’ll find some setting that allows you to export the result without any georeference.

(If not, then there might be ways to salvage the data as it is. Some small script with glTF-Transform should do the trick here. But the precision that is lost from exporting it in a georeferenced form will be lost forever…)

Thank you so much for these considerations, I really appreciate!
for 3D models I will use only those with local coordinates!