-
Notifications
You must be signed in to change notification settings - Fork 311
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
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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