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

Resizing textures to 2k is broken for a particular model #562

Closed
hybridherbst opened this issue Apr 16, 2022 · 3 comments · Fixed by #775
Closed

Resizing textures to 2k is broken for a particular model #562

hybridherbst opened this issue Apr 16, 2022 · 3 comments · Fixed by #775
Labels
bug Something isn't working package:functions
Milestone

Comments

@hybridherbst
Copy link

hybridherbst commented Apr 16, 2022

Describe the bug
While reducing texture sizes, I noted that a particular model produces wrong results in specific texture sizes; 2k breaks and 1k works.

To Reproduce
Steps to reproduce the behavior:

  1. Download https://drive.google.com/file/d/1zX2hyLozcOU5awRGSE01_NPtimz8qWzl/view?usp=sharing
  2. Run gltf-transform resize --width 2048 --height 2048 066.glb 066.2048.glb
  3. Run gltf-transform resize --width 1024 --height 1024 066.glb 066.1024.glb
  4. View in gltf.report
  5. Note that the 2048px version is broken while the 1024px version matches the original.

Expected behavior
Same appearance between 1024 and 2048px, and consistent with the input.

Versions:

  • Version: 2.1.4
  • Environment: tested in CLI and gltf.report
@hybridherbst hybridherbst added the bug Something isn't working label Apr 16, 2022
@donmccurdy
Copy link
Owner

Hm thanks! I think my resizing dependency (https://github.com/donmccurdy/ndarray-lanczos) is having trouble with some input/output ratios, like the 5464x3070 input here. I'm using that package because it works both on the web and in node.js, but there are much better (faster, more stable) alternatives for node.js, like sharp or squoosh/lib. If speed and memory footprint are an important concerns, you might want to try swapping out a couple lines here for a different resizing library:

const srcImage = texture.getImage()!;
const srcPixels = await getPixels(srcImage, texture.getMimeType());
const dstPixels = ndarray(new Uint8Array(dstWidth * dstHeight * 4), [dstWidth, dstHeight, 4]);
logger.debug(`${NAME}: Resizing "${uri || name}", ${srcPixels.shape}${dstPixels.shape}...`);
try {
options.filter === TextureResizeFilter.LANCZOS3
? lanczos3(srcPixels, dstPixels)
: lanczos2(srcPixels, dstPixels);

@donmccurdy
Copy link
Owner

I've been hoping ndarray-lanczos would be a temporary stopgap until squoosh/lib gets web support (GoogleChromeLabs/squoosh#1084)...

@donmccurdy donmccurdy added this to the v2.1 milestone Apr 22, 2022
@donmccurdy donmccurdy modified the milestones: v2.1, v2.2 Jul 14, 2022
@donmccurdy
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package:functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants