marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.04k stars 265 forks source link

why some textures did not load correctly in vedo library in python? #593

Open ganjbakhshali opened 2 years ago

ganjbakhshali commented 2 years ago

I'm trying to load some .obj files with their texture by vedo lib:

from vedo import *
from transparent import *

mesh = Mesh("3d/gol1/raw_model.obj")#load 3d model
mesh.texture("3d/gol1/texture.png")#load texture on 3d mode

plt = Plotter(offscreen=True)
plt += mesh
plt.show().screenshot("hi.png")#save as png

I added Images in StackOverflow question

marcomusy commented 2 years ago

uhm that looks strange.. is there a way that you can share one of these obj files?

ganjbakhshali commented 2 years ago

Hello Yes sure. Here is the link this obj file was downloaded from Alibaba 3d obj files

marcomusy commented 2 years ago

I'm not completely sure why that happens but depth peeling fixes it..:

from vedo import *
settings.useDepthPeeling = True
msh = Mesh("normalized_model.obj").texture("texture.png")
show(msh, axes=1)

Screenshot from 2022-02-08 00-08-11

ganjbakhshali commented 2 years ago

Thank you very much for your time But unfortunately, by running your code, I hit this error:

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  152 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  111
  Current serial number in output stream:  112
marcomusy commented 2 years ago

uhm what version of vtk do you have and your OS? Try type: vedo --info

ganjbakhshali commented 2 years ago

here is my system info:

vedo version      : 2022.0.1   https://vedo.embl.es
vtk version       : 9.0.3
python version    : 3.8.12 (default, Oct 12 2021, 13:49:34) [GCC 7.5.0]
python interpreter: .../python
vedo installation : /home/.../anaconda3/envs/3d/lib/python3.8/site-packages/vedo
system            : Linux 5.13.0-27-generic posix x86_64
raphaelsulzer commented 2 years ago

Indeed it seems like vedo 2022 broke something around mesh textures. I can load a mesh texture with the sample code above in vedo 2021.0.3 correctly, but not in vedo 2022.0.3.

marcomusy commented 2 years ago

Sorry - I might have overlooked the issue... What is currently going wrong with the script above? I can run it fine on ubuntu, vtk9.0.3, python 3.8, 3.9

raphaelsulzer commented 2 years ago

Hi, I experience the following behaviour on MacOS and Ubuntu 18.04, python 3.8 / 3.9, vedo installed with conda:

with this code:

vedo.settings.useDepthPeeling = True
mesh = vedo.Mesh("mesh.obj", c=[90, 90, 90])
mesh.texture( "texture.jpg"))

plt = vedo.Plotter()
plt += mesh
plt.show()
vedo.io.screenshot("img.png")
plt.close()

I get the following results in vedo 2021.0.3 vs 2022.0.3

img000

img000 copy

The data is free from here: sketchfab

marcomusy commented 2 years ago

Hi , sorry for the late reply I could not download the above from sketchfab in any supported format... so I tried a new on another one mesh but could not reproduce the issue:

import vedo
mesh = vedo.Mesh("craneo.OBJ").texture("difuso_flip_oscuro.jpg")
vedo.show(mesh).close()

on vedo 2022.3.0 | vtk 9.0.3 | python 3.9

I attach the zip here skull-downloadable.zip

raphaelsulzer commented 2 years ago

Very strange, with your files it works well with both versions. I attached the same minimal example with the bunny file, the problem persists. The only difference I see is that the bunny.obj has vertex normals and the craneo.obj does not.

bunny.zip

marcomusy commented 2 years ago

thanks, I can now reproduce the issue I will look into it tomorrow.

marcomusy commented 2 years ago

I think I've found the issue... Try the dev version: pip install -U git+https://github.com/marcomusy/vedo.git