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

Added alpha texture support #124

Merged
merged 2 commits into from
Jan 24, 2018
Merged

Added alpha texture support #124

merged 2 commits into from
Jan 24, 2018

Conversation

lilleyse
Copy link
Contributor

@lilleyse lilleyse commented Jan 4, 2018

Added support for parsing map_d in the mtl file. The alpha texture is packed with the diffuse texture.

@shehzan10 - would you like to review? No rush at all with this.

Tested with red-baron.zip from https://groups.google.com/d/msg/cesium-dev/FFKF3N77FmQ/4kBkgD4qBAAJ

Command for running: node bin/obj2gltf.js -i red-baron/red-baron.obj --metallicRoughness

Copy link
Member

@shehzan10 shehzan10 left a comment

Choose a reason for hiding this comment

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

Just 2 comments. Tests (and red baron) passed locally.

writeChannel(pixels, blueChannel, 2);

// First try reading the alpha component from the alpha channel, but if it is a single color read from the red channel instead.
var alphaChannel = getTextureChannel(alphaTexture, 3, width, height, scratchChannel);
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better if this line was in in the else part. The cost here is reading the entire channel twice vs using an else and in this case, the else would be better.

Alternately, you can have a shortcut exit from the getTextureChannel function that returns if the channel number is beyond the number of channels available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reading the alpha channel before the red channel is probably safer. There could be a case where someone sets the diffuse slot and alpha slot to the same texture, in which case getting the transparency from the red channel would be a mistake.

var greenChannel = getTextureChannel(diffuseTexture, 1, width, height, scratchChannel);
writeChannel(pixels, greenChannel, 1);
var blueChannel = getTextureChannel(diffuseTexture, 2, width, height, scratchChannel);
writeChannel(pixels, blueChannel, 2);
Copy link
Member

Choose a reason for hiding this comment

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

How about adding a function that writes RGB at once? That way you can read the channels and then just use a single writeChannels function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the purpose of doing it this way was so we could use the same scratchChannel and only need to read a single channel of the texture at a time.

@shehzan10 shehzan10 merged commit bb3a189 into master Jan 24, 2018
@shehzan10 shehzan10 deleted the alpha-texture branch January 24, 2018 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants