mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
2.96k stars 575 forks source link

Trimesh fails to load mesh texture for a large mesh #2235

Open easteine opened 4 months ago

easteine commented 4 months ago

I am using trimesh to load a obj mesh that is quite large (563416 faces) with a .mtl texture. Without the texture the mesh object can be loaded but with texture the process is killed with exit error # 247. Meshlab can open the mesh fine (takes ~10s). I'm assuming this may just be a limitation with trimesh and mesh sizes.

I don't actually need to see the texture when viewing the mesh or scene with mesh.show(). My goal is just produce rendered images with texture based on camera locations.

Do you have any suggestions?

Kiord commented 4 months ago

This looks like an issue from pillow.

from PIL import Image
# Image.MAX_IMAGE_PIXELS = None # Try this if next line is crashing
texture = Image.open('texture.jpg')
easteine commented 3 months ago

That doesn't seem to be a problem, my textures are 2048x2048.

Since then I've also tried converting my files from obj to glb file type instead in case it was a problem with multiple textures. As well, I tried using meshlab to save only a subsection of the mesh to see if the number of vertices and faces was a problem. Neither has worked.

Kiord commented 3 months ago
import trimesh as tm
from PIL import Image

mesh =  tm.load('large_mesh.obj', skip_materials=True)
print(type(mesh.visual)) # should be TextureVisuals since your mesh has uv coordinates
print(mesh.visual.uv.shape) # should be (n_vertices, 2)
image = Image.open('large_mesh_texture.jpg')
mesh.visual.material = tm.visual.material.SimpleMaterial(image=img)

Are there any problems with these lines?

PS : sharing your mesh and texture might help others reproducing the error.