# glTF texture export error

**URL:** <https://discourse.vtk.org/t/gltf-texture-export-error/5300>\
**Category:** Development\
**Tags:** file-formats\
**Created:** [March 2, 2021, 7:51pm UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300 "2021-03-02T19:51:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mostapha](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mostapha/32/3092_2.png) [@mostapha](https://discourse.vtk.org/u/mostapha)\
**Post date:** [March 2, 2021, 7:51pm UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300/1 "2021-03-02T19:51:20Z")

</div>

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](https://github.com/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](https://discourse.vtk.org/uploads/short-url/9K6pPQGk52IswwFrzlV1QSLD0Lr.vtu) (25.9 KB)

This is how it renders in ParaView Glance:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/58707cca94fff4c057447d5e5f505752439f7d3f.png)

and here is how it looks like as a glTF:

[new\_grid.gltf](https://discourse.vtk.org/uploads/short-url/riVHi3anXiyOg2D4w4jKTOdEzO.gltf) (55.0 KB)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/73af6709d4dd64a2fbda54570653c6b8e306083c.jpeg)

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.

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

```

---

<div class="post-metadata">

**Author:** ![mostapha](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mostapha/32/3092_2.png) [@mostapha](https://discourse.vtk.org/u/mostapha)\
**Post date:** [March 2, 2021, 10:19pm UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300/2 "2021-03-02T22:19:00Z")

</div>

To make sure it is not happening because of my input file I tested the exporter with [AssignCellColorsFromLUT](https://lorensen.github.io/VTKExamples/site/Python/Visualization/AssignCellColorsFromLUT/) example and I can recreate the issue.

![image](https://discourse.vtk.org/uploads/default/original/2X/1/10e4b1b0d38e706b2785c59866cfbcc5c3bfec84.png)

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](https://discourse.vtk.org/uploads/short-url/wjpiZbVYsiUciQbtXv2yJt97uqD.gltf) (55.1 KB)

---

<div class="post-metadata">

**Author:** ![mostapha](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mostapha/32/3092_2.png) [@mostapha](https://discourse.vtk.org/u/mostapha)\
**Post date:** [March 2, 2021, 10:52pm UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300/3 "2021-03-02T22:52:48Z")

</div>

> [@mostapha](#):
>
> I suspect that I need to map the `CellData` to `PointData` before exporting to glTF but I’m not sure how to try that.

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

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/7783978465295278b0fa5bb5ae8be41c4262c686.jpeg)

~~I will update this post and add the code once I figure out how to do it using [vtkCellDataToPointData](https://vtk.org/doc/nightly/html/classvtkCellDataToPointData.html) class.~~ 😃

```python
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()

```

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [March 3, 2021, 7:56am UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300/4 "2021-03-03T07:56:38Z")

</div>

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

FYI @ken-martin

---

<div class="post-metadata">

**Author:** ![Manish\_Aryal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/manish_aryal/32/6606_2.png) [@Manish\_Aryal](https://discourse.vtk.org/u/Manish_Aryal)\
**Post date:** [February 23, 2023, 8:49pm UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300/5 "2023-02-23T20:49:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [February 24, 2023, 8:59am UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300/6 "2023-02-24T08:59:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nickholt15](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nickholt15/32/8630_2.png) [@nickholt15](https://discourse.vtk.org/u/nickholt15)\
**Post date:** [March 12, 2024, 8:44pm UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300/7 "2024-03-12T20:44:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [March 13, 2024, 11:06am UTC](https://discourse.vtk.org/t/gltf-texture-export-error/5300/8 "2024-03-13T11:06:54Z")

</div>

FYI @Loic_Gaillard
