export_gltf generates invalid gltf
I was instructed in a pyvista github issue to open this issue. Linking both issues together.
TL;DR:
When exporting meshes as gltf, the generated gltf ends up being invalid, with bad vertice indexing.
Data files:
Code to reproduce:
import pyvista as pv
b = pv.read("boreholes-test-small.vtk")
c = b.extract_surface()
pl = pv.Plotter()
pl.add_mesh(c)
pl.export_gltf("boreholes-test-small.gltf", save_normals=True, inline_data=True)
Errors as reported by the validator built into https://sandbox.babylonjs.com/ for the single cell file:
{
"code": "MESH_PRIMITIVE_UNEQUAL_ACCESSOR_COUNT",
"message": "All accessors of the same primitive must have the same count.",
"severity": 0,
"pointer": "/meshes/0/primitives/0/attributes/POSITION"
},
{
"code": "ACCESSOR_INDEX_OOB",
"message": "Indices accessor element at index 1 has value 1 that is greater than the maximum vertex index available (0).",
"severity": 0,
"pointer": "/meshes/0/primitives/0/indices"
}
and for the 5 cell file:
{
"code": "MESH_PRIMITIVE_UNEQUAL_ACCESSOR_COUNT",
"message": "All accessors of the same primitive must have the same count.",
"severity": 0,
"pointer": "/meshes/0/primitives/0/attributes/POSITION"
},
{
"code": "ACCESSOR_INDEX_OOB",
"message": "Indices accessor element at index 5 has value 5 that is greater than the maximum vertex index available (4).",
"severity": 0,
"pointer": "/meshes/0/primitives/0/indices"
},
{
"code": "ACCESSOR_INDEX_OOB",
"message": "Indices accessor element at index 6 has value 6 that is greater than the maximum vertex index available (4).",
"severity": 0,
"pointer": "/meshes/0/primitives/0/indices"
},
{
"code": "ACCESSOR_INDEX_OOB",
"message": "Indices accessor element at index 7 has value 7 that is greater than the maximum vertex index available (4).",
"severity": 0,
"pointer": "/meshes/0/primitives/0/indices"
},
{
"code": "ACCESSOR_INDEX_OOB",
"message": "Indices accessor element at index 8 has value 8 that is greater than the maximum vertex index available (4).",
"severity": 0,
"pointer": "/meshes/0/primitives/0/indices"
},
{
"code": "ACCESSOR_INDEX_OOB",
"message": "Indices accessor element at index 9 has value 9 that is greater than the maximum vertex index available (4).",
"severity": 0,
"pointer": "/meshes/0/primitives/0/indices"
}
System information as per pyvista.Report()
:
--------------------------------------------------------------------------------
Date: Wed Mar 23 10:56:32 2022 CET
OS : Linux
CPU(s) : 8
Machine : x86_64
Architecture : 64bit
RAM : 38.9 GiB
Environment : Jupyter
GPU Vendor : Intel Open Source Technology Center
GPU Renderer : Mesa DRI Intel(R) UHD Graphics (CML GT2)
GPU Version : 4.6 (Core Profile) Mesa 20.0.8
Python 3.8.0 (default, Feb 25 2021, 22:10:10) [GCC 8.4.0]
pyvista : 0.33.3
vtk : 9.0.1
numpy : 1.22.1
imageio : 2.9.0
appdirs : 1.4.4
scooby : 0.5.7
matplotlib : 3.4.1
PyQt5 : 5.15.6
IPython : 7.22.0
scipy : 1.6.3
tqdm : 4.60.0
meshio : 4.4.0
--------------------------------------------------------------------------------