# Display of a OBJ file.

**URL:** https://discourse.vtk.org/t/display-of-a-obj-file/7659
**Category:** Support
**Created:** [January 17, 2022, 8:22pm UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659 "2022-01-17T20:22:39Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [January 17, 2022, 8:22pm UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/1 "2022-01-17T20:22:39Z")

</div>

Dear All,

Has VTK, support to load and display an OBJ file (color vectorial image, extension .obj with .mtl and .png files)?

Can you please provide a link for an example code?

Thanks,

Luís Gonçalves

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [January 18, 2022, 8:57am UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/2 "2022-01-18T08:57:12Z")

</div>

[https://kitware.github.io/vtk-examples/site/Cxx/IO/OBJImporter/](https://kitware.github.io/vtk-examples/site/Cxx/IO/OBJImporter/)

> <https://github.com/f3d-app/f3d/blob/master/src/library/readers/F3DOBJReader.inl>

Alternativaly, you can use F3D directly: [F3D](https://f3d-app.github.io/f3d/)

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [February 13, 2022, 9:19pm UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/4 "2022-02-13T21:19:15Z")

</div>

Dear All,

I translated the following example to Python:

[https://kitware.github.io/vtk-examples/site/Cxx/IO/OBJImporter/](https://kitware.github.io/vtk-examples/site/Cxx/IO/OBJImporter/)

And gives the following error:

( 166.199s) [paraview] vtkOBJImporter.cxx:843 ERR| vtkOBJPolyDataProcessor (0x28763c0): material ‘material\_0’ appears in OBJ but not MTL file?  
( 167.862s) [paraview] vtkOBJImporter.cxx:843 ERR| vtkOBJPolyDataProcessor (0x28763c0): material ‘“material\_1”’ appears in OBJ but not MTL file?

* * *

#file .mtl

# File exported by Artec Group 3D Scanning Solutions

# [www.artec-group.com](http://www.artec-group.com)

newmtl material\_0  
Ka 1 1 1  
Kd 1 1 1  
Ks 1 1 1  
Ns 1000  
map\_Kd output1\_1.png

newmtl material\_1  
Ka 1 1 1  
Kd 1 1 1  
Ks 1 1 1  
Ns 1000

* * *

#File .Obj

# File exported by Artec Group 3D Scanning Solutions

# [www.artec-group.com](http://www.artec-group.com)

# 387296 vertices

# 765202 triangular faces

mtllib output1.mtl

o Copy of Sharp fusion 1

v -157.45563 -18.5831 220.40683

usemtl material\_0  
vt 0.087013 0.803479  
f 6256/1 6257/2 6253/3

usemtl “material\_1”

* * *

Result (appears without the textures) I suppose in error:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/c/c86a6fbe2e62fa3e51fdf5f2ddcc1b0464564b44.jpeg)

This within example “web-project-templates-master” with Paraview Python.

Thanks,

Luís Gonçalves

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [February 14, 2022, 9:14am UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/5 "2022-02-14T09:14:35Z")

</div>

please share your data.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [February 14, 2022, 9:21am UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/6 "2022-02-14T09:21:51Z")

</div>

```
      importer=vtk.vtkOBJImporter()
      importer.SetFileName(path1+file8+'.obj');
      #importer.SetFileNameMTL(path1+file4+'.mtl');
      #importer.SetTexturePath(path1+file9+'.png');

      colors=vtk.vtkNamedColors()

      #vtkNew<vtkRenderer> renderer;
      #vtkNew<vtkRenderWindow> renWin;
      #vtkNew<vtkRenderWindowInteractor> iren;

      renderer.SetBackground2(colors.GetColor3d("Silver"))
      renderer.SetBackground(colors.GetColor3d("Gold"))
      renderer.GradientBackgroundOn()
      renderWindow.Modified()
      #renWin->AddRenderer(renderer);
      renderer.UseHiddenLineRemovalOn()
      renderWindow.Modified()
      #renWin->AddRenderer(renderer);
      renderWindow.SetSize(640, 480);
      #renWin->SetWindowName("OBJImporter");

      #iren->SetRenderWindow(renWin);
      importer.SetRenderWindow(renderWindow);
      importer.Update()

      actors = renderer.GetActors()
      actors.InitTraversal()
      #std::cout << "There are " << actors->GetNumberOfItems() << " actors"
      # << std::endl;

      for a in range(actors.GetNumberOfItems()):
          actor =vtk.vtkActor() 
          actor=actors.GetNextActor()
          if (actor.GetTexture()):
              actor.GetTexture().InterpolateOn()
          pd =vtk.vtkPolyData(actor.GetMapper().GetInput())
          mapper =vtk.vtkPolyDataMapper(actor.GetMapper())
          mapper.SetInputData(pd)

```

* * *

renderWindow.SetSize(640, 480); has no effect.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [February 14, 2022, 9:22am UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/7 "2022-02-14T09:22:43Z")

</div>

> [@mwestphal](#):
>
> please share your data.

please share your **data**.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [February 15, 2022, 9:46am UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/8 "2022-02-15T09:46:10Z")

</div>

I reproduce the issue, but more investigation is needed to understand where this is coming from.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [February 15, 2022, 2:40pm UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/9 "2022-02-15T14:40:20Z")

</div>

Solved:  
Changed:

```
    importer.SetFileName(path1+file8+'.obj')
    importer.SetFileNameMTL(path1+file4+'.mtl')
    importer.SetTexturePath(path1)
```

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [February 15, 2022, 5:14pm UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/10 "2022-02-15T17:14:18Z")

</div>

The code works like this (I removed the redundant code).

```
    self.importer=vtk.vtkOBJImporter()
    self.importer.SetFileName(path1+file8+'.obj')
    self.importer.SetFileNameMTL(path1+file4+'.mtl')
    self.importer.SetTexturePath(path1)#+file9+'.png')
    colors=vtk.vtkNamedColors()
    renderer.SetBackground2(colors.GetColor3d("Silver"))
    renderer.SetBackground(colors.GetColor3d("Gold"))
    renderer.GradientBackgroundOn()
    renderWindow.Modified()
    renderer.UseHiddenLineRemovalOn()
    self.importer.SetRenderWindow(renderWindow);
    self.importer.Update()

```

**How I remove the picture from the screen?**

I tried

```
        self.importer.RemoveRenderWindow(renderWindow);

```

but do not works.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [March 17, 2022, 8:40am UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/11 "2022-03-17T08:40:43Z")

</div>

This thread is still open.

I only want to remove this “volume” from the screen. But it is not a volume, I suppose.

Can anyone help?

Thanks.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [March 17, 2022, 1:08pm UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/12 "2022-03-17T13:08:18Z")

</div>

What do you mean by removing the picture? Clearing the render window to the background?

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [March 17, 2022, 1:14pm UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/13 "2022-03-17T13:14:22Z")

</div>

Yes, clearing the render window. Of that image in particular.

---

<div class="post-metadata">

### Author: ![yangyang117](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/da6949/32.png) [@yangyang117](https://discourse.vtk.org/u/yangyang117)
#### Post date: [December 13, 2023, 6:27am UTC](https://discourse.vtk.org/t/display-of-a-obj-file/7659/14 "2023-12-13T06:27:13Z")

</div>

you can try to learn the c++ demo, which is easy to translate it to python. it shows how to get the actor and mapper of the import.  
[https://examples.vtk.org/site/Cxx/IO/OBJImporter/](https://examples.vtk.org/site/Cxx/IO/OBJImporter/)
