# GLTF export and texture to PNG

**URL:** https://discourse.vtk.org/t/gltf-export-and-texture-to-png/10930
**Category:** Support
**Tags:** python, code
**Created:** [March 9, 2023, 4:45pm UTC](https://discourse.vtk.org/t/gltf-export-and-texture-to-png/10930 "2023-03-09T16:45:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ashishgupta79](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ashishgupta79/32/6543_2.png) [@ashishgupta79](https://discourse.vtk.org/u/ashishgupta79)
#### Post date: [March 9, 2023, 4:45pm UTC](https://discourse.vtk.org/t/gltf-export-and-texture-to-png/10930/1 "2023-03-09T16:45:17Z")

</div>

I have a vtk structured grid with single scalar points data (temperature values). I am taking a planar slice out of it using vtk cutter and supplying it a constant z plane. Then, I am exporting that slice out to a gltf file. I am also trying to export out the slice texture as png. Here is my code snippet:

> plane = vtk.vtkPlane()  
> plane.SetOrigin(grid.GetCenter())  
> plane.SetNormal(0.0, 0.0, 1.0)
> 
> cutter = vtk.vtkCutter()  
> cutter.SetInputData(grid);  
> cutter.SetCutFunction(plane);  
> cutter.Update()
> 
> slice = cutter.GetOutput()
> 
> slice.GetPointData().SetActiveScalars(attr)  
> mapper = vtk.vtkPolyDataMapper()  
> mapper.SetInputData(slice)  
> mapper.SetInterpolateScalarsBeforeMapping(True)
> 
> actor = vtk.vtkActor()  
> actor.SetMapper(mapper)
> 
> renderer = vtk.vtkRenderer()  
> renderer.AddActor(actor)
> 
> render\_window = vtk.vtkRenderWindow()  
> render\_window.AddRenderer(renderer)

> render\_window.Render()

> exporter = vtk.vtkGLTFExporter()  
> exporter.SetFileName(“slice.gltf”)  
> exporter.SetRenderWindow(render\_window)  
> exporter.SetInlineData(True)  
> exporter.Update()
> 
> w2if = vtk.vtkWindowToImageFilter()  
> w2if.SetInput(render\_window);  
> w2if.Update();
> 
> writer = vtk.vtkPNGWriter()  
> writer.SetFileName(outPath+“/”+attr+“-z(”+str(z)+“)-slice.png”)  
> writer.SetInputData(w2if.GetOutput());  
> writer.Write();
> 
> exporter.Write()

Firstly, the vtk render window doesn’t show temperature colors. When I open the exported GLTF in paraview, it opens in “Solid color” mode by default, and when I change that to TEXCOORD\_0, it correctly shows colors corresponding to temperature values, just that the slice colors correspond to temperature range within the slice. Additionally, when I open this GLTF in a GLTF viewer, e.g. Babylon.js, it doesn’t show up with TEXCOOR\_0 colors. Furthermore, what I export out as png is the render\_window, while I just want to export out the slice.

My questions are:

1. How to rename TEXCOORD\_0 to a more appropriate attribute name, e.g. “temp”?
2. How to change slice colors so that they correspond to the temperature values in the grid and not in the slice?
3. How to setup gltf export such that by default it opens with TEXCOORD\_O or temp in any gltf viewer.
4. How to export slice texture out as a png image?

Thanks  
Ashish
