Terrain mesh to GLTF models

Progress update 2

I tried reading the mesh data as shown here and created a very simple OBJ file from the quantized mesh data.

const MAX_SHORT = 32767;
const tileCoord = {x:1936452, y: 711072}
const level = 20

this.map.terrainProvider.requestTileGeometry(tileCoord.x, tileCoord.y, level)
  .then((terrainData) => {
    console.log("Terrain tile data:", terrainData)
    const rect = new Cesium.GeographicTilingScheme().tileXYToRectangle(tileCoord.x, tileCoord.y, level);

    const data = terrainData as any;
    const minimumHeight = data._minimumHeight;
    const maximumHeight = data._maximumHeight;

    const indices: Uint16Array = data._indices;
    const quantizedVertices: Uint16Array = data._quantizedVertices;
    const vertexCount = quantizedVertices.length / 3;

    const vertices: [number, number, number][] = []
    const faces: [number, number, number][] = [];

    for (let i = 0; i < vertexCount; i++) {
      const rawU = quantizedVertices[i];
      const rawV = quantizedVertices[i + vertexCount];
      const rawH = quantizedVertices[i + vertexCount * 2];

      const u = rawU / MAX_SHORT;
      const v = rawV / MAX_SHORT;

      const longitude = Cesium.Math.lerp(rect.west, rect.east, u);
      const latitude = Cesium.Math.lerp(rect.south, rect.north, v);
      const height = Cesium.Math.lerp(minimumHeight, maximumHeight, rawH / MAX_SHORT);

      const carto = new Cesium.Cartographic(longitude, latitude, height);
      const cartesion = Cesium.Cartographic.toCartesian(carto)
      vertices.push([cartesion.x, cartesion.y, height])
    }

    // form triangle faces from indices
    let i = 0;
    while (i < indices.length) {
      faces.push([indices[i], indices[i + 1], indices[i + 2]])
      i += 3
    }

    console.log("Vertices:", vertices);
    console.log("faces:", faces)
  })

Now when I try loading that OBJ file in the Blender, I get the following error -

Python: Traceback (most recent call last):
  File "/snap/blender/1653/3.0/scripts/addons/io_scene_obj/__init__.py", line 151, in execute
    return import_obj.load(context, **keywords)
  File "/snap/blender/1653/3.0/scripts/addons/io_scene_obj/import_obj.py", line 1264, in load
    for data in split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP):
  File "/snap/blender/1653/3.0/scripts/addons/io_scene_obj/import_obj.py", line 547, in split_mesh
    verts_split.append(verts_loc[vert_idx])  # add the vert to the local verts
IndexError: list index out of range

location: <unknown location>:-1

Can someone please tell me what I’m doing wrong?

PS: Attaching OBJ file which I created - test.zip (22.5 KB)