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

texture-packer output textures compression #57

Closed
wants to merge 1 commit into from

Conversation

ddenisyuk
Copy link
Contributor

@ddenisyuk ddenisyuk commented Feb 20, 2024

plugin-texture-packer extended with possibility to compress output image/texture with the compressed methods from plugin-compress.

pixijs/pixijs#10217

@ddenisyuk ddenisyuk changed the title texture-packer out textures compressions texture-packer output textures compression Feb 20, 2024
@Sparking2
Copy link

@ddenisyuk One question, this would allow the packed texture to be exported as WebP?

@ddenisyuk
Copy link
Contributor Author

ddenisyuk commented Apr 26, 2024

@ddenisyuk One question, this would allow the packed texture to be exported as WebP?

yep, you are able define compression config inside texturePacker plugin:

 const assetpack = new AssetPack({
            entry: inputDir,
            output: outputDir,
            plugins: {
                tps: texturePacker({
                    compression: {
                        avif: compression.compress.to.avif,
                        webp: compression.compress.to.webp,
                    },
                    resolutionOptions: {
                        resolutions: { default: 1 },
                    },
                })
            }
        });

https://github.com/pixijs/assetpack/pull/57/files#diff-cd9ba657672197a1492e400c08f4780e573959cf5ef8b2c48c85fb4500d11dc3R52-R55

@Sparking2
Copy link

Oh, I'd like to have a feature like that, to have more control over the resulting files.

@drfrankius
Copy link

drfrankius commented May 7, 2024

I tried using this. I am able to create the atlases in webp / avif. but in my manifest I get an entry like { "alias": [ "images/popups/popups", "popups.json", "popups" ], "src": [ "images/popups/[email protected]", "images/popups/[email protected]", "images/popups/[email protected]" ], "data": { "tags": { "tps": true } } }
When i load the bundle though. it always seems to default to the .png ( the first entry in the src list).

@Zyie
Copy link
Member

Zyie commented May 7, 2024

When i load the bundle though. it always seems to default to the .png ( the first entry in the src list).

You will need to create a custom resolver to allow pixi to understand what format the json is

import type { ResolveURLParser } from 'pixi.js';
import { extensions, ExtensionType, settings } from 'pixi.js';

const knownFormats = ['png', 'webp', 'avif', 'jpg', 'jpeg'];

export const resolveJsonUrl = {
    extension: ExtensionType.ResolveParser,
    test: (value) => settings.RETINA_PREFIX.test(value) && value.endsWith('.json'),
    parse: (value) => {
        console.log('resolveJsonUrl.parse: value = ', value.split('.'));
        const parts = value.split('.');
        let format = 'json';
        if (knownFormats.includes(parts.at(-2))) {
            format = parts.at(-2);
        }
        return {
            resolution: parseFloat(settings.RETINA_PREFIX.exec(value)?.[1] ?? '1'),
            format,
            src: value,
        };
    },
} as ResolveURLParser;

extensions.add(resolveJsonUrl)

@ddenisyuk
Copy link
Contributor Author

I tried using this. I am able to create the atlases in webp / avif. but in my manifest I get an entry like { "alias": [ "images/popups/popups", "popups.json", "popups" ], "src": [ "images/popups/[email protected]", "images/popups/[email protected]", "images/popups/[email protected]" ], "data": { "tags": { "tps": true } } } When i load the bundle though. it always seems to default to the .png ( the first entry in the src list).

Are you using the latest version of Pixi? 7.4.2 or 8+?

@drfrankius
Copy link

I tried using this. I am able to create the atlases in webp / avif. but in my manifest I get an entry like { "alias": [ "images/popups/popups", "popups.json", "popups" ], "src": [ "images/popups/[email protected]", "images/popups/[email protected]", "images/popups/[email protected]" ], "data": { "tags": { "tps": true } } } When i load the bundle though. it always seems to default to the .png ( the first entry in the src list).

Are you using the latest version of Pixi? 7.4.2 or 8+?

I am using pixi 8+.

I have not setup a custom resolver though like Zyie has mentioned.

@ddenisyuk
Copy link
Contributor Author

ddenisyuk commented May 7, 2024

You will need to create a custom resolver to allow pixi to understand what format the json is

Shouldn't it be resolved via the built-in resolver: https://github.com/pixijs/pixijs/blob/dev/src/spritesheet/spritesheetAsset.ts#L79-L99

Maybe it's related to pixijs/pixijs#10234 (comment), right?

UPD: I conducted a small test, and I'm not completely sure if I used it correctly, but here is the link: https://jsfiddle.net/xq0hk1y8/9/. In the DevTools, you can see that it is attempting to load AVIF or WebP formats.

Main part is:

PIXI.extensions.remove(PIXI.resolveJsonUrl);
PIXI.extensions.add(PIXI.spritesheetAsset);

Since both extensions are checked for '.json', and PIXI.resolveJsonUrl is the default with higher priority, I removed it for the test.

@drfrankius
Copy link

drfrankius commented May 7, 2024

You will need to create a custom resolver to allow pixi to understand what format the json is

Shouldn't it be resolved via the built-in resolver: https://github.com/pixijs/pixijs/blob/dev/src/spritesheet/spritesheetAsset.ts#L79-L99

Maybe it's related to pixijs/pixijs#10234 (comment), right?

UPD: I conducted a small test, and I'm not completely sure if I used it correctly, but here is the link: https://jsfiddle.net/xq0hk1y8/9/. In the DevTools, you can see that it is attempting to load AVIF or WebP formats.

Main part is:

PIXI.extensions.remove(PIXI.resolveJsonUrl);
PIXI.extensions.add(PIXI.spritesheetAsset);

Since both extensions are checked for '.json', and PIXI.resolveJsonUrl is the default with higher priority, I removed it for the test.

thanks, yes i just tested this on my side to removing PIXI.resolveJsonUrl, and adding PIXI.spritesheetAsset I am able to load my atlases now in avif, webp . Thanks for the help on this. I hope in 1 way or another more texture types will be supported soon for assetpack.

@ddenisyuk
Copy link
Contributor Author

I hope in 1 way or another more texture types will be supported soon for assetpack.

like this #56 ?

@ddenisyuk
Copy link
Contributor Author

@Zyie, could you please clarify if the following usage of PIXI extensions is correct:

PIXI.extensions.remove(PIXI.resolveJsonUrl);
PIXI.extensions.add(PIXI.spritesheetAsset);

And is this still considered an issue?

@Zyie
Copy link
Member

Zyie commented May 10, 2024

@Zyie, could you please clarify if the following usage of PIXI extensions is correct:

PIXI.extensions.remove(PIXI.resolveJsonUrl);
PIXI.extensions.add(PIXI.spritesheetAsset);

This is an interesting one and i think highlights an issue with pixi that i need to fix, but for now yes, doing this is correct

And is this still considered an issue?

Yes this is still an issue for anyone using the pixi.js buncle and not using something like npm

@Zyie
Copy link
Member

Zyie commented Jul 17, 2024

this has been added in the 1.0 rewrite, thanks for putting together this PR

@Zyie Zyie closed this Jul 17, 2024
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.

4 participants