# Wavefront .obj WITH materials .mtl

**URL:** https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012
**Category:** ParaView Support
**Created:** [December 6, 2018, 6:54pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012 "2018-12-06T18:54:21Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Richard\_Simmons](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@Richard\_Simmons](https://discourse.paraview.org/u/Richard_Simmons)
#### Post date: [December 6, 2018, 6:54pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/1 "2018-12-06T18:54:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [December 6, 2018, 7:53pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/2 "2018-12-06T19:53:20Z")

</div>

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:

> <https://github.com/Kitware/vtk-js/blob/master/Utilities/ParaView/obj-mtl-importer.py>

HTH,

Seb

---

<div class="post-metadata">

### Author: ![Richard\_Simmons](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@Richard\_Simmons](https://discourse.paraview.org/u/Richard_Simmons)
#### Post date: [December 7, 2018, 2:29pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/3 "2018-12-07T14:29:03Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [December 7, 2018, 5:18pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/4 "2018-12-07T17:18:15Z")

</div>

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:

```auto
/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.

---

<div class="post-metadata">

### Author: ![Richard\_Simmons](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@Richard\_Simmons](https://discourse.paraview.org/u/Richard_Simmons)
#### Post date: [December 7, 2018, 6:46pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/5 "2018-12-07T18:46:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [December 7, 2018, 8:28pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/6 "2018-12-07T20:28:58Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Richard\_Simmons](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@Richard\_Simmons](https://discourse.paraview.org/u/Richard_Simmons)
#### Post date: [December 7, 2018, 8:43pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/7 "2018-12-07T20:43:51Z")

</div>

that’s correct

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [December 7, 2018, 10:50pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/8 "2018-12-07T22:50:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Richard\_Simmons](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@Richard\_Simmons](https://discourse.paraview.org/u/Richard_Simmons)
#### Post date: [December 11, 2018, 7:03pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/9 "2018-12-11T19:03:04Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [December 11, 2018, 7:46pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/10 "2018-12-11T19:46:26Z")

</div>

Glad it is working and it was an easy fix…

---

<div class="post-metadata">

### Author: ![fengzekang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/9fc29f/32.png) [@fengzekang](https://discourse.paraview.org/u/fengzekang)
#### Post date: [August 1, 2019, 2:46pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/11 "2019-08-01T14:46:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [August 1, 2019, 3:06pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/12 "2019-08-01T15:06:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fengzekang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/9fc29f/32.png) [@fengzekang](https://discourse.paraview.org/u/fengzekang)
#### Post date: [August 1, 2019, 3:15pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/13 "2019-08-01T15:15:17Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [August 1, 2019, 3:26pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/14 "2019-08-01T15:26:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fengzekang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/9fc29f/32.png) [@fengzekang](https://discourse.paraview.org/u/fengzekang)
#### Post date: [August 1, 2019, 3:31pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/15 "2019-08-01T15:31:58Z")

</div>

[example3.rar](https://discourse.paraview.org/uploads/short-url/d91I57SCCWyK2xs9nOJVrzb8S5x.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

---

<div class="post-metadata">

### Author: ![fengzekang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/9fc29f/32.png) [@fengzekang](https://discourse.paraview.org/u/fengzekang)
#### Post date: [August 1, 2019, 3:34pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/16 "2019-08-01T15:34:36Z")

</div>

![%E5%9B%BE%E7%89%87](https://discourse.paraview.org/uploads/default/original/2X/0/0608e59339e2e03dd3be12b2bf2bbe642d97394f.png)  
 ![%E5%9B%BE%E7%89%87](https://discourse.paraview.org/uploads/default/original/2X/5/574339a30a7b3fa79c789a58b3cd817f1c155d6f.png)  
 ![%E5%9B%BE%E7%89%87](https://discourse.paraview.org/uploads/default/original/2X/d/dad3135745d4e5d76bb2b5e25993eeb70e1942da.png)  
nothing in the window…

---

<div class="post-metadata">

### Author: ![fengzekang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/9fc29f/32.png) [@fengzekang](https://discourse.paraview.org/u/fengzekang)
#### Post date: [August 1, 2019, 3:52pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/17 "2019-08-01T15:52:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gilcu2](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gilcu2/32/2183_2.png) [@gilcu2](https://discourse.paraview.org/u/gilcu2)
#### Post date: [October 17, 2019, 2:23pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/18 "2019-10-17T14:23:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [October 18, 2019, 2:59am UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/19 "2019-10-18T02:59:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [January 7, 2020, 7:35pm UTC](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012/20 "2020-01-07T19:35:58Z")

</div>

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

The issue was [resolved](https://gitlab.kitware.com/paraview/paraview/merge_requests/3505) prior to the ParaView 5.7.0 release.

[Next page](https://discourse.paraview.org/t/wavefront-obj-with-materials-mtl/1012.md?page=2)
