mikedh / trimesh

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

Is there a way to load mesh without material info? #1709

Closed Iven-Wu closed 2 years ago

Iven-Wu commented 2 years ago

I saved a .obj file with materials previously. But the directory to the material information has been removed. When loading, it will report some errors like failed to load image Traceback (most recent call last): File "/projects/perception/personals/yuefanw/miniconda3/envs/lasr/lib/python3.8/site-packages/trimesh/exchange/obj.py", line 333, in parse_mtl file_data = resolver.get(split[1]) File "/projects/perception/personals/yuefanw/miniconda3/envs/lasr/lib/python3.8/site-packages/trimesh/resolvers.py", line 84, in get with open(os.path.join(self.parent, name.strip()), 'rb') as f: FileNotFoundError: [Errno 2] No such file or directory: '/scratch/users/yuefanw/planetzoo/Content1/Large_Bears/Polar_Bear/Polar_Bear_Juvenile/polar_bear_juvenile_eye.pbasecolourandmasktexture.PNG'

mikedh commented 2 years ago

Hey, is that an error or a log.warning? The mesh should probably still load?

mikedh commented 2 years ago

I switched a bunch of the log.warning calls to log.debug in #1713 so they won't print unless you've attached to the log. You can also pass skip_materials=True to the OBJ loader:

mikedh@luna:trimesh$ ipython -i
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import trimesh

In [6]: print(trimesh.exchange.obj.load_obj.__doc__)

    Load a Wavefront OBJ file into kwargs for a trimesh.Scene
    object.

    Parameters
    --------------
    file_obj : file like object
      Contains OBJ data
    resolver : trimesh.visual.resolvers.Resolver
      Allow assets such as referenced textures and
      material files to be loaded
    split_object : bool
      Split meshes at each `o` declared in file
    group_material : bool
      Group faces that share the same material
      into the same mesh.
    skip_materials : bool
      Don't load any materials.
    maintain_order : bool or None
      Do not reorder faces or vertices which may result
      in visual artifacts.

    Returns
    -------------
    kwargs : dict
      Keyword arguments which can be loaded by
      trimesh.exchange.load.load_kwargs into a trimesh.Scene

In [7]: m = trimesh.load('models/fuze.obj', skip_materials=True)

In [8]: m
Out[8]: <trimesh.Trimesh(vertices.shape=(664, 3), faces.shape=(1000, 3))>