Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete material property export for wavefront (.obj) files #2349

Open
mariusbrinkmann opened this issue Jan 30, 2025 · 0 comments
Open

Comments

@mariusbrinkmann
Copy link

When loading wavefront (.obj) files with associated .mtl materials using group_material = False and skip_materials = False and exporting it afterwards, not all material properties from the .mtl file are exported.

Currently, only ambient (Ka), diffuse (Kd), specular (Ks), and glossiness (Ns) properties are supported and exported by SimpleMaterial. Other properties, such as the index of refraction (Ni), are parsed and stored in SimpleMaterial.kwargs but not exported by SimpleMaterial.to_obj(). Furthermore, the hash generation for unique material names only considers the exported properties, potentially leading to naming conflicts for materials differing by unexported properties.

The index of refraction is officially supported and even used in some of the models /models/box.mtl. Loading the corresponding .obj file and exporting it would result in lost information.

Proposed Solutions:

  1. Enhanced material support: Add support for the (optional) index of refraction (Ni) to SimpleMaterial similar to the optional SimpleMaterial.image.
  2. Flexible export option: Introduce a flag export_all: bool = False to SimpleMaterial.to_obj(), allowing for the export of all parsed material properties from kwargs. Note: This requires careful handling of hash generation to accommodate non-hashable types.

Setting the material names during import

I was also wondering why the material names are parsed but not used in the generation of the SimpleMaterial instances? All materials are called material_0. Extending it as follows would make the names available before export.

This would store the original material names (instead of material_0) in the .obj file and allow re-using the original .mtl file.

materials = {k: SimpleMaterial(**v) for k, v in material_kwargs.items()}
for k, v in materials.items():
    materials[k].name = k
  • Python version: 3.11.9
  • trimesh version: 4.6.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant