-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
DataTexture support for GLTFExporter #20588
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
Conversation
|
I don't think it makes sense to support anything except of RGB(A). If users create data texture let's say with |
|
^Probably not necessary to support more than RGB(A) within GLTFExporter, anyway, to keep this simple. That said, a full |
|
Somewhat related to this PR: There is actually another one for serializing/deserializing data textures in general: #17745 |
|
I don't think it's necessary to support |
|
@Mugen87 For now, my opinion is that we should keep the I also think RGB support should be kept as a feature as well. It is a widely used format, and the lack of this feature could be infuriating to users who have to do the conversion manually. |
I'm not sure I understand this argument. Data textures are generated by the user. If they generate textures for glTF assets, they just have to adjust an existing routine. No "conversion" is required. Hence, |
My issue with this approach is that it imposes an arbitrary constraint sooner in the pipeline that might a pain to work with. This is, in my opinion, unecessary added complexity. Using an efficient embedded conversion function to the exporter process removes that complexity for the user. To me, imposing this to the user also goes against the "easy-to-use" motto of three.js |
|
Another motto of |
I'm not sure I follow your logic here. The issue is that if those options are ignored for |
|
Like I said before, color data textures are generated by the user like you did it in your example. Since the user is in full control over this logic, he can already ensure proper texture sizes. It does not make sense to generate a larger texture and then ask the exporter to shrink it down. |
If the issue is to keep internal code to a minimum for maintenance, I can compact the conversion code to something like this : if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
ctx.drawImage( image, 0, 0, canvas.width, canvas.height );
} else {
// data texture must be of type RGBA or RGB
let data = image.data;
if ( format === THREE.RGBFormat ) {
data = new Uint8ClampedArray( image.height * image.width * 4 );
data.forEach( function ( _, i ) { data[ i ] = i % 4 === 3 ? 255 : image.data[ 3 * Math.floor( i / 4 ) + i % 4 ] } );
}
ctx.putImageData( data, 0, 0 );
}Would that be acceptable ? |
Okay, I can agree on that. |
|
It's best when @mrdoob decides about this. Your new code is definitely more appropriate 👍 . |
|
I'll push the new code right away then |
|
Thanks! |
|
There is a minor bug in the stride computation for the RGB texture. I'll file a PR. |
Related issues: GLTFExporter and TextureData
Description
Adds support of
DataTextureimages forGLTFExporter.The
DataTextureimage data will be converted to RGBA, downscaled linearly if needed (due tomaxTextureSizeorforcePowerOfTwoTexturesoptions), then put into anImageDataobject and then proceed to be put to the canvas.The example file has also been edited to test the feature: a linear gradient DataTexture is generated, added as a map to the sphere mesh.
So far, the supported DataTexture formats are:
RGBAIntegerFormatRGBAFormatRGBEFormat(note: linear downscale may have issues)RGBIntegrerFormatRGBFormatRGIntegerFormatRGFormatRedIntegerFormatRedFormatFor now, other formats will result in an explicit error
This contribution is funded by Dioxygen Software for Dualbox.com