Wavefront .obj WITH materials .mtl


(Richard Simmons) #1

I have CAD models with colors already applied (.obj (with .mtl)). How do I import the .obj file and apply the .mtl file to display the colors correctly? I have not found a clear or concise way of doing this.

Also, would the same method apply to a .vrml file which contains color information?

I am not familiar with OSPRay settings or creating my own color editor colormap.

Thank you, I love using Paraview to display scientific results, I would just love to be able to overlay that data on great looking CAD models.


(Sebastien Jourdain) #2

We have a macro or python script that can be used with Paraview to create a state file with all the settings properly done.

That script is available here:

HTH,

Seb


(Richard Simmons) #3

A couple questions…

  1. Do I have to ‘edit’ the python file each time I want to load an .obj file? I’m assuming I have to change the ‘User conifguration’ each time and change the ‘objToLoad’ and ‘mtlToLoad’ variables.

  2. Are the installation steps: Macros–>Add new macro? I changed the path and file names to load and then loaded the macro, but nothing appears to happen when I click the macro’s button.

  3. Are ‘objToLoad’ and ‘mtlToLoad’ the correct variable names? I don’t see those being used in the script?


(Sebastien Jourdain) #4

If you use that script as a macro, then yes you will have to edit that script.

But you can also use it as a data converter for ParaView which will then make it easy to load such scene inside ParaView.

To use it as a script just run the following command:

/path/to/paraview/bin/pvpython obj-mtl-importer.py /path/to/your/file.obj

The script will assume a file /path/to/your/file.mtl.

This will create a /path/to/your/file-pv-state.pvsm file that correspond to a state file that can be loaded in Paraview which will then contains all the textures and various settings the obj/mtl contains.


(Richard Simmons) #5

This is what I get when I run it from the cmd prompt:

Traeback (most recent call last):
File “obj-mtl-importer.py”, line 358, in
loadScene(objPath, ‘%s.mtl’ % objPath[:-4])
File “obj-mtl-importer.py”, line 337, in loadScene
objReader = OBJParser(objFilePath, ‘usemtl’)
File “obj-mtl-importer.py”, line 47, in init
self.parseLine(line.rstrip(’/n’))
File “obj-mtl-importer.py”, line 120, in parseLine
self.vn.append(float(tokens[3]))
ValueError: could not convert string to float: \


(Sebastien Jourdain) #6

This could be related to some weird formatting in your obj. I’m guessing you are on windows?


(Richard Simmons) #7

that’s correct


(Sebastien Jourdain) #8

Would is be possible to share that obj/mtl privately with me to see what could be the issue?


(Richard Simmons) #9

Everything is working… I found out what I was doing wrong… when using tab completion in the cmd prompt, I was specifying the .mtl instead of .obj


(Sebastien Jourdain) #10

Glad it is working and it was an easy fix…