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

The size and number of baked textures were incorrectly estimated #116

Open
bbccyy opened this issue Aug 9, 2022 · 0 comments
Open

The size and number of baked textures were incorrectly estimated #116

bbccyy opened this issue Aug 9, 2022 · 0 comments

Comments

@bbccyy
Copy link

bbccyy commented Aug 9, 2022

The problem code locates right at method "CalculateTextureSize" in script file "AnimationGenerator.cs". According to the project context, the method is trying to pack all animation data as tight as possible, which means it will try packing all data into ONE(or more) texture with largest size(1024) at first, if still remains some, it'll find out the best suited texture (probably with size smaller then 1024) to fit all rest data. However, when dealing with those remaining data, what the code really does is to find out a texture with certain size that can just hold data from "One Animation Clip", not from "Rest All Clips" , which may lead to a releatively smaller size of estimation for the last texture.

for (int i = stardardTextureSize.Length - 1; i >= 0; --i)
{
    ...
    bool suitable = false;
    if (count > 1 && i == stardardTextureSize.Length - 1)
    {
        for (int m = 0; m != stardardTextureSize.Length; ++m) //from small to large
        {
            size = stardardTextureSize[m];
            x = y = 0;
            for (int n = k; n < frames.Length; ++n) //go through all the rest anim info
            {
                int frame = frames[n];
                int currentLineEmptyBlockCount = (size - x) / blockWidth % blockCountEachLine; 
                x = (x + frame % blockCountEachLine * blockWidth) % size;
                if (frame > currentLineEmptyBlockCount) //是否要换行 
                {
                    y += (frame - currentLineEmptyBlockCount) / blockCountEachLine * blockHeight;
                    y += currentLineEmptyBlockCount > 0 ? blockHeight : 0;
                }
                if (y + blockHeight <= size) 
                {   
                    suitable = true;  //**algorithm stops here but:(n ?= frames.Length - 1)**
                    break;
                }
            }
            if (suitable)
            {
                textureWidth = size;
                break;
            }
        }
    }
    ...
}
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

No branches or pull requests

1 participant