Wavefront .obj WITH materials .mtl

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.

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

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?

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.

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: \

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

that’s correct

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

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

Glad it is working and it was an easy fix…

Dear Jourdain
I have finished the exchange from .obj and the assumed file .mtl. And also there is no error when I compile the script. Finally I got the .pvsm file, but how should I open it in paraview. I check that paraview can not be open the .pvsm type. How should I do this ?
Regards.
Feng

.pvsm are state file which means that you need to do “Load state” rather than “Load dataset”.

Thanks for your reply. I tried to load state with my .pvsm file. There is no visualization in the paraview. Can I send you my file? I am confused.
Regards.
Feng

Do you also have a bunch of vtp and images on the side of your state file?

example3.rar (1.4 MB)
There are files which I used. First I run the command /patch/to/…/pvpython obj-mtl-importer.py /patch/to…/1.obj and I got a new file 1-pv-state.pvsm and I load state in paraview with it(all files in this compressed file). But there is just nothing in paraviewer…
Regards


%E5%9B%BE%E7%89%87

nothing in the window…

Dear Sebastien
I have deal with it. I load state and then view it in the database window. And I got the result which include image and obj mesh.
Thanks a lot
Regards~~
Feng

1 Like

Hi, can you explain how do you show the rendering. I followed all the step, have my state loaded with several objects in the pipeline but nothin is showed.
Thanks
Reynlado

You may want to open a new topic to explain your own issue.

I believe this topic is referring to the same problem described in https://gitlab.kitware.com/paraview/paraview/issues/19240

The issue was resolved prior to the ParaView 5.7.0 release.