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

Support loading PBR textures in OBJLoader #216

Merged
merged 9 commits into from
May 14, 2021
Merged

Support loading PBR textures in OBJLoader #216

merged 9 commits into from
May 14, 2021

Conversation

iche033
Copy link
Contributor

@iche033 iche033 commented May 7, 2021

Signed-off-by: Ian Chen ichen@osrfoundation.org

🎉 New feature

Summary

Extends the OBJLoader to support loading PBR textures. The Wavefront OBJ format has PBR extensions which our current version of the tiny_obj_loader is already able to parse and load. This PR updates the loader to load these new fields into the common::Material and common::Pbr data structures.

Note that we found out blender's current obj exporter shoves roughness map into the specular highlight field and metalness map into the reflection map field! Here's a PR that describes the existing issue with the exporter: https://developer.blender.org/D8868.
They are rewriting the exporter in C++ that will also fix these issues but until then all obj files exported by blender will have these fields incorrectly exported. I've updated the OBJLoader to handle this particular case but I'm open to removing these specific checks for blender.

I also updated OBJLoader_TEST to load and check an obj file exported by 3ds max and an obj file exported by blender.

Test it

Here is a model on Fuel in obj format with PBR textures for testing:
https://app.ignitionrobotics.org/iche033/fuel/models/Cube%20PBR%20OBJ

This model is exported by 3ds max.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@iche033 iche033 requested a review from luca-della-vedova May 7, 2021 23:05
@iche033 iche033 requested a review from mjcarroll as a code owner May 7, 2021 23:05
@github-actions github-actions bot added 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome labels May 7, 2021
graphics/src/OBJLoader_TEST.cc Outdated Show resolved Hide resolved
graphics/src/OBJLoader_TEST.cc Outdated Show resolved Hide resolved
graphics/src/OBJLoader_TEST.cc Outdated Show resolved Hide resolved
graphics/src/OBJLoader_TEST.cc Outdated Show resolved Hide resolved
iche033 added 2 commits May 10, 2021 12:19
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@iche033 iche033 requested a review from ahcorde May 10, 2021 19:20
graphics/src/OBJLoader_TEST.cc Outdated Show resolved Hide resolved
graphics/src/OBJLoader_TEST.cc Outdated Show resolved Hide resolved
graphics/src/OBJLoader_TEST.cc Outdated Show resolved Hide resolved
mjcarroll and others added 3 commits May 11, 2021 08:16
Signed-off-by: Michael Carroll <michael@openrobotics.org>

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Comment on lines 143 to 155
// We use this field to determine if obj is exported by blender
// blender obj exporter puts roughness map in specular highlight
// field and metalness map in reflection map field!
// see summary in https://developer.blender.org/D8868
// detailing the existing exporter issues
// todo(anyone) remove this hack when blender fixes their exporter
// issue?
if (!m.specular_highlight_texname.empty())
{
pbrMat.SetRoughnessMap(m.specular_highlight_texname);
if (!m.reflection_texname.empty())
pbrMat.SetMetalnessMap(m.reflection_texname);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings about this, from one side it's nice to make blender assets work out of the box, but to be honest we might not need it for our use case since we are writing mtl and obj files manually and we have full control over the mtl fields.
Do you think for average users it is OK to have such hack to make Blender assets out of the box or do you think it's too "ugly"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes

I wonder if there's a way to detect if the file was created with Blender. It's nice to support Blender because it's widely used, but we shouldn't propagate their issues to our parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I added a check for blender exported files. Looking at the obj files I have on disk, they have the exporter name in the first line of the .obj file so I'm using that to determine if the files are exported by blender or not. We'll likely need to add a blender version check to skip this workaround once the issue is fixed on their side. 96b109e

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@codecov
Copy link

codecov bot commented May 13, 2021

Codecov Report

Merging #216 (86b1875) into ign-common3 (2e24122) will increase coverage by 1.37%.
The diff coverage is 87.09%.

Impacted file tree graph

@@               Coverage Diff               @@
##           ign-common3     #216      +/-   ##
===============================================
+ Coverage        75.18%   76.56%   +1.37%     
===============================================
  Files               73       73              
  Lines            10326    10357      +31     
===============================================
+ Hits              7764     7930     +166     
+ Misses            2562     2427     -135     
Impacted Files Coverage Δ
graphics/src/OBJLoader.cc 93.04% <87.09%> (+0.18%) ⬆️
graphics/src/tiny_obj_loader.h 61.81% <0.00%> (+11.60%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e24122...86b1875. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel 🔮 dome Ignition Dome
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants