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