Skip to content

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

Open
@bbccyy

Description

@bbccyy

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;
            }
        }
    }
    ...
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bbccyy

        Issue actions

          The size and number of baked textures were incorrectly estimated · Issue #116 · Unity-Technologies/Animation-Instancing