Animation-Instancing
Animation-Instancing copied to clipboard
The size and number of baked textures were incorrectly estimated
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;
}
}
}
...
}