glTF texture export error

I have a .vtu file with scalardata that renders fine in VTK viewers but the texture doesn’t export correctly to glTF format. I tested it with web viewers as well as F3D to ensure it’s not the viewer. It might be helpful to add that the glTF validator gives me a validation error:

Validation report

  • Format: glTF 2.0
  • Generator: VTK
  • Stats:
    • 1 draw calls
    • 0 animations
    • 1 materials
    • 1768 vertices
    • 1768 triangles
  • Extensions: None

Report generated by KhronosGroup/glTF-Validator 2.0.0-dev.3.3.

Error Message Pointer
MESH_PRIMITIVE_UNEQUAL_ACCESSOR_COUNT All accessors of the same primitive must have the same count. /meshes/0/primitives/0/attributes/POSITION

Here is the generated file: new_grid.vtu (25.9 KB)

This is how it renders in ParaView Glance:

and here is how it looks like as a glTF:

new_grid.gltf (55.0 KB)

Here is the part of code the exports it as glTF. It might be a bug or my lack of knowledge on how the model should be prepared. I suspect that I need to map the CellData to PointData before exporting to glTF but I’m not sure how to try that.

exporter = vtk.vtkGLTFExporter()
exporter.SaveNormalOn()
exporter.InlineDataOn()
exporter.SetFileName('new_grid.gltf')
exporter.SetRenderWindow(window)
exporter.Modified()
exporter.Write()

To make sure it is not happening because of my input file I tested the exporter with AssignCellColorsFromLUT example and I can recreate the issue.

image

Also tested from ParaView to make sure I have tested all the tools that I have access to. Here is the file exported form ParaView. It doesn’t even show up in F3D.

new_grid_pv.gltf (55.1 KB)

1 Like

That was correct! After adding “CellData to PointData” filter in ParaView I could export the scene correctly.

I will update this post and add the code once I figure out how to do it using vtkCellDataToPointData class. :smiley:

import vtk

cell_to_point = vtk.vtkCellDataToPointData()
cell_to_point.SetInputData(polydata)
data = cell_to_point.GetOutputPort()

# you can use this data now to set up the mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(data )
mapper.SetColorModeToMapScalars()
mapper.SetScalarModeToUsePointData()
mapper.SetScalarVisibility(True)
# ... more code to set-up the mapper as you need
# ...
# update mapper - I'm not sure if this is required but I'll do it to be safe!
mapper.Update()

This looks like a bug or missing feature in the glTF exporter.

FYI @ken-martin

Hey anyone do you know how to solve this missing bug or feature in the gITF exporter…

Someone needs to contribute time or money to fix this issue in the vtkGLTFExporter.

I was able to sidestep this issue by exporting to an X3D format in ParaView, then importing with Blender and saving as a glTF.

FYI @Loic_Gaillard