Mtl file of obj not loaded

I have another issue with the materials not loading of obj files. I found the issue because of quotes in the mtllib reference

mtllib "outcrop.mtl"

when I manually edit the obj file and remove the quotes then the mtl materials and textures load. The issue is these obj files come from 3rd party software and I can’t edit them all by hand. Is there a way to help resolving the mtl file?

@njannink

It appears that the issue with your OBJ files not loading the materials correctly is related to the quotes in the mtllib reference. If manual editing is not feasible, you can use a script to automate the removal of quotes from the mtllib lines in your OBJ files.

Here’s a Python script that reads an OBJ file, removes the quotes from the mtllib line, and writes the changes back to the file:

def fix_obj_file(file_path):
    with open(file_path, 'r') as file:
        lines = file.readlines()

    with open(file_path, 'w') as file:
        for line in lines:
            if line.startswith('mtllib'):
                line = line.replace('"', '')  # Remove quotes
            file.write(line)

# Example usage
fix_obj_file('path/to/your/file.obj')

To process multiple OBJ files, you can extend this script to loop through all OBJ files in a specified directory. Here’s a quick example of how to do that:

import os

def fix_all_obj_files(directory):
    for filename in os.listdir(directory):
        if filename.endswith('.obj'):
            fix_obj_file(os.path.join(directory, filename))

# Example usage
fix_all_obj_files('path/to/your/directory')

This will help you efficiently process all your OBJ files. If you need further assistance, feel free to ask!

thats not going to work I have c# program and can’t run scripts next to it. Aspose should be able to handle quoted references

@njannink
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): THREEDNET-1729

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@njannink

Indeed it should be handled by Aspose.3D, we’ll fix it in the next release.

the quotes around filenames can also me in the referred mtl files. So far I have seen de following formats for references in obj/mtl files:

mtllib file.mtl
mtllib ./file.mtl
mtllib "file.mtl"

Would be nice if aspose can handle all variants

@njannink

Thanks for the suggestion - that’s very helpful. We’ll add support for all these variants.