[vtkusers] Exporting RGB Polydata to .OBJ or .PLY

Radosław Furmaniak rastor.ragereaver at gmail.com
Thu Dec 6 13:12:31 EST 2018


Hello,
I have set up PolyData and added 4 component scalar array to it. When I
create PolyDataMapper, set scalar visibility and add actor to the scene,
all colors are rendered properly.
However, I have a problem with exporting this scene or just the polydata to
the .OBJ (+mtl) file or to the .PLY. When I open it up in Blender, geometry
is exported correctly, however OBJ is created all white, and .PLY has a
single, grayish color (apart from the shadows of course), which I don't
think is even present in input PolyData.

I am trying to do it like this:

plyWriter = vtk.vtkPLYWriter()
plyWriter.SetInputData(polydata)
plyWriter.SetFileTypeToBinary()
plyWriter.SetDataByteOrderToLittleEndian()
plyWriter.SetArrayName("Scalars")
plyWriter.SetFileName("model.ply")
plyWriter.Write()

I have also tried setting up different color modes in plyWriter,
 but the results are always the same.

Scalar array is set up like this:

scalarArray = vtk.vtkDoubleArray()
scalarArray.SetNumberOfComponents(4)
scalarArray.SetName("Scalars")

polydata.GetPointData().AddArray(scalarArray)

polydata.GetPointData().SetActiveScalars("Scalars")

(I am omitting the part where I am actually setting elements of this array)

I have also tried using the OBJExporter:

writer = vtk.vtkOBJExporter()
writer.SetFilePrefix(output_prefix)
writer.SetInput(renWin)
writer.Write()

where renWin is rendering window with a single actor made from
polydata mentioned above.

I am using Python 3.6 and VTK 8.1.1.

Any help how to export geometry and colors, so they can be reused in other
programs?

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181206/6754c52d/attachment.html>


More information about the vtkusers mailing list