How to set up material lookuptable for OSPRay

Howdy,

The new OSPRay path tracer in ParaView 5.5.0 has a mode in which each cell gets a material assigned via colormapping. To use it:

  • choose “Value Indexed” for the OSPRay Material instead of any of the individual material names.
  • pick an array to material map, for example “MaterialIds” that you will get with many .obj files
  • set up a categorical color map with annotations that are material names.

With .obj files there is a field aligned array “MaterialNames” that has all of the material names referenced by the .obj in it. You can see it in the spreadsheet view. You could manually create a lookup table from it, but the following script will create a lookup table automatically (copy and paste it into the Python Shell).

anObject = GetActiveSource()
vtklevel = anObject.GetClientSideObject()
lut = GetColorTransferFunction('MaterialIds')
arr = vtklevel.GetOutput().GetFieldData().GetAbstractArray("MaterialNames")
lut.InterpretValuesAsCategories = 1
ll = []
for x in range(0, arr.GetNumberOfTuples()):
  ll.append(str(x))
  ll.append(arr.GetValue(x))

lut.Annotations = ll

hth