guybrush77 / rapidobj

A fast, header-only, C++17 library for parsing Wavefront .obj files.
MIT License
159 stars 14 forks source link

materials generally unnecessary #10

Closed GraspingArms closed 1 year ago

GraspingArms commented 1 year ago

Could materials be considered optional? Currently, Merge() returns prematurely when it hasn't found a material file, and then the geometry won't be loaded at all. Is it safe to just comment out those lines?

In my experience, when .OBJ files are used, it's only the geometry that's of interest, and material files are likely to be ignored. It's not like they can describe a decent shader by today's standards, and they rarely contain more than a single shade of grey or the name of a single texture map anyway.

It's good to be able to see where multiple materials may exist, of course, but I don't think their absence needs to be a show-stopping error.

Great work, by the way! Millions of triangles per second! Most 3D applications can't even open their own binary formats that fast.

guybrush77 commented 1 year ago

Thanks for the compliment!

Yes, I agree with you. I will update the API so that material parsing becomes optional. I will am to have the change committed to master in the next few days.

guybrush77 commented 1 year ago

I have published a new branch called MaterialLibrary. It features a new API that enables more flexible material library loading.

To optionally load a material library:

using namespace rapidobj;
Result result = ParseFile("/path/to/some.obj", MaterialLibrary::Default(Load::Optional));

MaterialLibrary::Default searches for the material library in the .obj file's folder (i.e. /path/to folder). Because loading is optional, ParseFile() will not generate an error if the material library file cannot be opened. Of course, result.materials will be empty. However, result.shapes[index].mesh.material_ids will contain ids. The ids will be assigned in order of appearance in the .obj file (0, 1, 2 etc.). This makes it possible to determine if multiple materials exist.

Another option is to use: Result result = ParseFile("/path/to/some.obj", MaterialLibrary::Ignore());

In this case, ParseFile() will not attempt to locate a material library; all the result.shapes[index].mesh.material_ids arrays will be empty.

Please let me know if this addresses your issue. If there are no objections, I will merge this into main branch soon.

guybrush77 commented 1 year ago

MaterialLibrary API merged into main branch