ryanslikesocool / Mecanim2Texture

Bake skinned mesh animations to 2D textures
MIT License
52 stars 7 forks source link

Normalize Texture Sizes to allow Texture2DArray Generation #5

Open transcendtient opened 3 years ago

transcendtient commented 3 years ago

This will allow GPU instancing for any number of animations by setting the appropriate uv.z to index the slice you want to animate.

I did this by passing textureSize into the private IEnumerator CreateAllAnimationTexturesForRig(Vector2Int[] sizes, int vertexCount, int fps, AnimationClip[] clips, GameObject original, Vector2Int maxSize) {

Here is the relevant changes.

for (int clip = 0; clip < clips.Length; clip++) {
            Texture2D result = new Texture2D(maxSize.x, maxSize.y, DefaultFormat.HDR, TextureCreationFlags.None);
            Debug.Log(sizes[clip].ToString());
            float clipTime = clips[clip].length;
            int frames = sizes[clip].y;

            //Color[] clearColors = new Color[sizes[clip].x * sizes[clip].y];
            Color[] clearColors = new Color[maxSize.x * maxSize.y];