Search code examples
python-3.xvtk

vtkOBJReader object has no attribute SetFileNameMTL (.mtl) for Object (.obj) files


The code below complains that vtk.vtkOBJReader() object has no method SetFileNameMTL().

In the documentation it appears to exist vtkOBJImporter.SetFileNameMTL (Maybe the python wrapper for this is missing?).

How can the material (.mtl) for the object be set when parsing the (.obj) in vtk and made visible in k3d?

import k3d
import vtk
import ipywidgets as widgets

reader = vtk.vtkOBJReader() 
reader.SetFileName('sample_obj/Model.obj')
reader.SetFileNameMTL('sample_obj/Model.mtl') #Attribute not found
reader.Update() 

plot = k3d.plot()
poly_data = reader.GetOutput()

plot += k3d.vtk_poly_data(poly_data)
plot.display()

Solution

  • You are using vtkOBJReader, not vtkOBJImporter. Those are two different classes. vtkOBJReader is the older class, I think, and only reads in the geometry file. To load the material info, you need to use vtkOBJImporter.