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

Incorrect loading of vertex color when there is none #380

Open
qnzhou opened this issue Mar 22, 2024 · 2 comments
Open

Incorrect loading of vertex color when there is none #380

qnzhou opened this issue Mar 22, 2024 · 2 comments

Comments

@qnzhou
Copy link

qnzhou commented Mar 22, 2024

Describe the issue
Tinyobjloader incorrectly populates the vertex color attribute with default values when vertex color does not exist in the file. It seems to be by design as shown in the comments below:

/// Parse vertex color.
/// If vertex color is not present, its filled with default value.
/// false = no vertex color
/// This will increase memory of parsed .obj
bool vertex_color;

However, I want to argue that this behavior is really confusing (especially during debugging). It would better to leave color field empty if no vertex color exists in the file.

To Reproduce
Steps to reproduce the behavior:

  1. Load any obj file that does not contain color. e.g.
v 1 0 0
v 0 1 0
v 0 0 1

Expected behavior
Tinyobject should not populate the color attribute.

@syoyo
Copy link
Collaborator

syoyo commented Mar 23, 2024

I cannot recall why default behavior is to create default vertex color. Probably to support parsing a .obj whose vertices partially have vertex colors, something like:

v 1 0 0 1 1 0
v 1 1 0
v 1 1 1

It'd be possible to add a condition(when all vertices does not have vertex color) to clear vertex colors here:

if (!found_all_colors && !default_vcols_fallback) {

PR is much appreciated!

@qnzhou
Copy link
Author

qnzhou commented Mar 24, 2024

Hmm, turns out setting ObjReaderConfig::vertex_color to false produces the correct behavior (only populate the color attribute when it is available). ObjReaderConfig::vertex_color in v2.0 API is really the default_vcols_fallback in v1.x API, but its name and documentation feel a bit misleading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants