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 = [
[3, 2, 1, 0],
[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:
- Is there anything wrong or missing in my approach to using
vtkCesium3DTilesWriter
for writing 3D tiles? - Does
vtkCesium3DTilesWriter
require additional data or input types (such as textures) to generate valid 3D tiles? - 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!