How to use vtkCesium3DTilesWriter with vtkPolyData to Export 3D Tiles?

Hello,

I’m trying to export a cube mesh to 3D Tiles using vtkCesium3DTilesWriter. According to the documentation, the writer accepts vtkPolyData for meshes. Since I’m working with vtkUnstructuredGrid to define my cube mesh, I’m converting it to vtkPolyData using vtkGeometryFilter before passing it to the writer. Additionally, I’m wrapping the vtkPolyData in a vtkMultiBlockDataSet, as specified in the documentation.

However, when I run the script, no output is generated, and no files are created in the specified path. Here’s my code:

from vtk import *

# Define points for the cube
points = vtkPoints()
points.InsertNextPoint(0, 0, 0) 
points.InsertNextPoint(1, 0, 0) 
points.InsertNextPoint(1, 1, 0) 
points.InsertNextPoint(0, 1, 0) 
points.InsertNextPoint(0, 0, 1) 
points.InsertNextPoint(1, 0, 1) 
points.InsertNextPoint(1, 1, 1) 
points.InsertNextPoint(0, 1, 1) 

# Define the faces of the cube
faces = [
    [0, 1, 2, 3],  
    [4, 5, 6, 7], 
    [0, 1, 5, 4],  
    [1, 2, 6, 5],  
    [2, 3, 7, 6], 
    [3, 0, 4, 7]   
]

# Create vtkIdList for face indexing
faceId = vtkIdList()
faceId.InsertNextId(6)  # 6 faces
for face in faces:
    faceId.InsertNextId(len(face)) 
    [faceId.InsertNextId(j) for j in face]

# Assign colors to the faces 
cell_colors = vtkUnsignedCharArray()
cell_colors.SetNumberOfComponents(3) 
cell_colors.SetName("FaceColors")

# Assign red color to each face
for _ in faces:
    cell_colors.InsertNextTuple3(255, 0, 0)

# Create UnstructuredGrid for the cube
ugrid = vtkUnstructuredGrid()
ugrid.SetPoints(points)
ugrid.InsertNextCell(VTK_POLYHEDRON, faceId)  # Define the cube faces as polyhedron
ugrid.GetCellData().SetScalars(cell_colors)  # Set the face colors

# Convert UnstructuredGrid to PolyData using vtkGeometryFilter
geometry_filter = vtkGeometryFilter()
geometry_filter.SetInputData(ugrid)
geometry_filter.Update()

# Get the output as vtkPolyData
polydata = geometry_filter.GetOutput()

# Wrap vtkPolyData in vtkMultiBlockDataSet
multi_block_dataset = vtkMultiBlockDataSet()
multi_block_dataset.SetBlock(0, polydata)

# Setup vtkCesium3DTilesWriter for exporting the tiles
writer = vtkCesium3DTilesWriter()
writer.SetDirectoryName("output_directory")
writer.SetSaveTextures(True)
writer.SetSaveTiles(True)
writer.SetContentGLTF(True)
writer.SetContentGLTFSaveGLB(False)
writer.SetInputType(vtkCesium3DTilesWriter.Mesh)  # Input type: Mesh
writer.SetInputData(multi_block_dataset)

# Write the 3D tiles
writer.Write()

Questions:

  1. Is there anything wrong or missing in my approach to using vtkCesium3DTilesWriter for writing 3D tiles?
  2. Does vtkCesium3DTilesWriter require additional data or input types (such as textures) to generate valid 3D tiles?
  3. Are there any debugging steps or logs available to verify that the writing process with vtkCesium3DTilesWriter is functioning correctly?

I’d be grateful for any suggestions or advice, thank you!

It looks like you did already receive a response at How to use vtkCesium3DTilesWriter with vtkPolyData to Export 3D Tiles in VTK? - Support - VTK (and in general, it is probably more likely to receive helpful responses for the VTK library in the VTK forum)

I also tried this out (quickly), and with the fix from the linked thread, it does generate the output_directory for me. But that directory does not contain any data. This might be releated to the error that the other thread refers to, but I don’t see any error/crash message here.