Repository navigation
WaveFrontReader: handle MTL xyz and spectral colors and 'd -halo' - #324
Open
Joel Kiptoo (Kiptoo-Deus) wants to merge 3 commits into
Open
Joel Kiptoo (Kiptoo-Deus) wants to merge 3 commits into
Joel Kiptoo (Kiptoo-Deus) wants to merge 3 commits into
Conversation
The color statements (Ka, Kd, Ks, Ke) read three floats directly from the stream, so 'Kd xyz x y z', 'Kd spectral file.rfl' or 'd -halo factor' put the stream into a failed state. LoadMTL then stopped reading the rest of the file but still returned S_OK, and for 'xyz' the color was set from uninitialized values. Each color statement now parses its own line: - 'r [g b]', where g and b default to r - 'xyz x [y z]', converted from CIE XYZ to linear sRGB (D65) - 'spectral file.rfl [factor]' is skipped (debug message) 'd -halo factor' uses the factor, and 'Tf' reports that it is not supported in debug builds. Fixes microsoft#229
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #229.
Besides the missing features, the current MTL reader has a failure mode: the color statements read three floats straight from the stream, so
Kd xyz 0.5 0.5 0.5,Kd spectral file.rflord -halo 0.8putInFileinto a failed state. The main loop's nextInFile >> strCommandthen fails, soLoadMTLsilently stops reading the rest of the file but still returnsS_OK. Forxyz, the color is also assigned from the uninitializedr, g, b.Changes in
WaveFrontReader.h:LoadColorhelper forKa,Kd,KsandKeparses the rest of the line (read the same way asLoadTexturePath, ignoring an end-of-line comment):r [g b]:gandbdefault tor, as in the MTL specxyz x [y z]:yandzdefault tox; converted from CIE XYZ to linear sRGB (D65), clamping negative, out-of-gamut values to 0spectral file.rfl [factor]: skipped, leaving the color unchanged, with a debug messaged -halo factoruses the factor, since view-dependent dissolve isn't supported.Tfgets its own branch with a debug message saying it isn't supported.For the XYZ conversion I used the standard sRGB/D65 matrix rather than
XMColorXYZToRGB, because that function converts to CIE RGB and doesn't map D65 white to (1, 1, 1). Happy to switch if you'd prefer the DirectXMath function.Testing: on macOS with clang (using the
wslstubs from DirectX-Headers andsal.h), I calledLoadMTLon a file using the forms from the issue:Before (returns
S_OK):After:
A typical Blender-exported MTL (RGB colors,
Ns,Ni,Tr,illum,map_Kd, tab-separated values) gives identical results before and after.I couldn't build the full
Loadpath on macOS:std::wifstream(const wchar_t*)is an MSVC extension that libc++ doesn't have, so the test calledLoadMTLdirectly through a small shim. That's unrelated to this change.