f3d-app / f3d

Fast and minimalist 3D viewer.
https://f3d.app
BSD 3-Clause "New" or "Revised" License
2.87k stars 207 forks source link

Obj's with tga textures don't get their textures displayed #1281

Open Git-i opened 9 months ago

Git-i commented 9 months ago

Describe the bug Obj imports don't support .tga textures

To Reproduce Steps to reproduce the behavior:

  1. Open any obj file with a .tga texture

Expected behavior The file loads and the texture is displayed

System Information:

F3D Information F3D 2.3.0

F3D - A fast and minimalist 3D viewer Version: 2.3.0. Build date: 2024-01-21 19:20:59. Build system: Windows 64-bits. Compiler: MSVC 19.37.32826.1. External rendering module: ON. Raytracing module: OFF. VTK version: 9.3.0-1702-geb008dfe7b (date: 20240111). Copyright (C) 2019-2021 Kitware SAS. Copyright (C) 2021-2024 Michael Migliore, Mathieu Westphal. License BSD-3-Clause. By Michael Migliore, Mathieu Westphal and Joachim Pouderoux.

mwestphal commented 9 months ago

vtkOBJImporter indeed does not support TGA texture for now. It would be nice to add and should not be that hard. wdyt @Meakk ?

Meakk commented 9 months ago

Isn't it using the image factory?

Meakk commented 6 months ago

The problem is indeed in VTK. In the file IO/Import/vtkOBJImporterInternals.cxx, function bindTexturedPolydataToRenderWindow, a bunch of image formats are tested (TIFF, PNG, JPG, BMP), but it should be changed to use the image reader factory.

e.g.

auto reader = vtkSmartPointer<vtkImageReader2>::Take(
    vtkImageReader2Factory::CreateImageReader2(textureFilename.c_str()));

  if (reader)
  {
    reader->SetFileName(fullPath.c_str());
    reader->Update();
    vtkSmartPointer<vtkTexture> vtk_texture = vtkSmartPointer<vtkTexture>::New();
    vtk_texture->AddInputConnection(reader->GetOutputPort());
    actor->SetTexture(vtk_texture);
    knownTextures[textureFilename] = vtk_texture;
  }
mwestphal commented 6 months ago

Nice find, should be simple indeed.

gapry commented 1 month ago

I'd like to work on this issue. Could you please assign it to me?

Meakk commented 1 month ago

Nice. Thanks!

mwestphal commented 6 days ago

@gapry any news on this ?

gapry commented 6 days ago

@mwestphal Sorry, I need more time, I anticipate having the first patch ready between the 15th and 17th of this month.

mwestphal commented 6 days ago

No worries!