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

Exposing functions - e.g. running textureCompress for individual textures #853

Closed
marwie opened this issue Mar 15, 2023 · 3 comments
Closed
Labels
feature New enhancement or request package:functions

Comments

@marwie
Copy link
Contributor

marwie commented Mar 15, 2023

Is your feature request related to a problem? Please describe.
I'd like to use existing compression functions for individual textures/primitives/...

Describe the solution you'd like
Similarly to #767 It would be nice to be able to run the textureCompress function on individual textures (providing the texture compression options per texture?)

Describe alternatives you've considered
Copying and modifying the code I need (e.g. the inner textures.map loop of textureCompress to apply webp compression to individual textures)

Additional context

textures.map(async (texture, textureIndex) => {

Something like this:
needle-tools@45fedf0
https://github.com/needle-tools/glTF-Transform/blob/45fedf070b0983e9de384893497780a2fbf2bb27/packages/functions/src/texture-compress.ts#L164

@marwie marwie added the feature New enhancement or request label Mar 15, 2023
@marwie marwie changed the title Exposing textureCompress for individual textures Exposing functions - e.g. running textureCompress for individual textures Mar 15, 2023
@donmccurdy
Copy link
Owner

Related:

I think we could do a textureCompress function, yes — would you be up for writing a PR?

It's worth noting that texture compression can be done in less code than I'm using, and @gltf-transform/functions will never expose the entirety of Sharp's API. So being able to do skip the wrapping function and use Sharp directly is something that I hope users will feel very free to do, too:

import sharp from 'sharp';
import { BufferUtils, HTTPUtils } from '@gltf-transform/core';

for (const texture of document.getRoot().listTextures()) {
  const buffer = await sharp(texture.getImage()).toFormat('webp', {lossless: true}).toBuffer();
  texture
    .setMimeType('image/webp')
    .setImage(BufferUtils.toView(buffer))
    .setURI(HTTPUtils.basename(texture.getURI()) + '.webp');
}

document.createExtension(EXTTextureWebP).setRequired(true);

@donmccurdy donmccurdy added this to the Backlog milestone Mar 15, 2023
@marwie
Copy link
Contributor Author

marwie commented Mar 15, 2023

Yes happy to PR this, just wanted to run some tests before to make sure I didnt break anything and it's working as intended.

Thanks for the code snippet. That's goo to know and maybe something I'll be doing then instead in our code and just handle the settings we ship in our extension (that being said having a fallback to the default gltf-transform compression function is still handy in cases where no explicit compression settings were assigned to a texture but we still want to apply defaults)

marwie added a commit to needle-tools/glTF-Transform that referenced this issue Mar 17, 2023
@donmccurdy
Copy link
Owner

Fixed by #859.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New enhancement or request package:functions
Projects
None yet
Development

No branches or pull requests

2 participants