示例#1
0
        private void InstantiatePerUnitTypeData(UnitType type)
        {
            var gameObject               = type == UnitType.Melee? UnitViewSettings.Instance.MeleePrefab: UnitViewSettings.Instance.SkeletonPrefab;
            var renderingData            = gameObject.GetComponentInChildren <RenderingDataWrapper>().Value;
            SkinnedMeshRenderer renderer = renderingData.SkinnedMeshRenderer;
            Material            material = renderingData.Material;
            LodData             lodData  = renderingData.LodData;

            var animationComponent = gameObject.GetComponent <Animation>();

            var dataPerUnitType = new Data.DataPerUnitType
            {
                BakedData = KeyframeTextureBaker.BakeClips(renderer, animationComponent, lodData),
                Material  = material,
            };

            dataPerUnitType.Drawer     = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.NewMesh);
            dataPerUnitType.Lod1Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.Lods.Lod1Mesh);
            dataPerUnitType.Lod2Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.Lods.Lod2Mesh);
            dataPerUnitType.Lod3Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.Lods.Lod3Mesh);


            _perUnitTypeDataHolder.Add(type, dataPerUnitType);
            // TransferAnimationData(type);
        }
示例#2
0
    private void InstantiatePerUnitTypeData(UnitType type)
    {
        var                 minionPrefab  = Spawner.GetMinionPrefab(type);
        var                 renderingData = minionPrefab.GetComponentInChildren <RenderingDataWrapper>().Value;
        GameObject          bakingObject  = GameObject.Instantiate(renderingData.BakingPrefab);
        SkinnedMeshRenderer renderer      = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>();
        Material            material      = renderingData.Material;
        LodData             lodData       = renderingData.LodData;

        var dataPerUnitType = new DataPerUnitType
        {
            UnitType  = type,
            BakedData = KeyframeTextureBaker.BakeClips(renderer,
                                                       GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), lodData),
            Material = material,
        };

        dataPerUnitType.Drawer     = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.NewMesh);
        dataPerUnitType.Lod1Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.lods.Lod1Mesh);
        dataPerUnitType.Lod2Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.lods.Lod2Mesh);
        dataPerUnitType.Lod3Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.lods.Lod3Mesh);

        perUnitTypeDataHolder.Add(type, dataPerUnitType);
        TransferAnimationData(type);
        GameObject.Destroy(bakingObject);
    }
        /// <summary>
        /// Gets the grid square preview color based on which LOD
        /// level it falls within.
        /// </summary>
        /// <returns></returns>
        private Color GetLodPreviewColor(GridPosition position)
        {
            if (Generator == null || Generator.Lod == null)
            {
                return(Color.white);
            }

            Vector3 worldXYZ = Generator.TrackedObject == null ? Vector3.zero : Generator.TrackedObject.transform.position;

            LodData lod = Generator.Lod;

            LodData.Lod lvlType = lod.GetLevelForPosition(position, worldXYZ);

            return(lvlType.PreviewColor);
        }
示例#4
0
    private void initilize()
    {
        if (init)
        {
            return;
        }
        init = true;
        PreSetting          setting      = Resources.Load <PreSetting>("PreSetting");
        var                 bakingObject = GameObject.Instantiate(setting.go) as GameObject;
        SkinnedMeshRenderer renderer     = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>();
        LodData             lodData      = new LodData();

        lodData.Lod1Mesh     = setting.mesh0;
        lodData.Lod2Mesh     = setting.mesh1;
        lodData.Lod3Mesh     = setting.mesh2;
        lodData.Lod1Distance = 10;
        lodData.Lod2Distance = 20;
        lodData.Lod3Distance = 30;
        Material material = setting.material;

        //SkinnedMeshRenderer r = Combine.CombineIt(bakingObject.transform);
        bakedData = KeyframeTextureBaker.BakeClips(renderer, GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), lodData);
        //bakedData = KeyframeTextureBaker.BakeClips(r, GetAllAnimationClips(r.GetComponentInParent<Animation>()), lodData);

        TransferAnimationData();

        //UnityEngine.Object fGo = Resources.Load("Formation");
        for (int i = 0; i < formationCount; i++)
        {
            Vector3 formationPosition = new Vector3(i % 5 * (width + 30), 1, i / 5 * (height + 20));

            //GameObject instance = Object.Instantiate(fGo) as GameObject;
            //instance.name = "Formation_" + i;
            //Formation form = instance.GetComponent<Formation>();
            //form.Init(width, height);
            //instance.transform.position = formationPosition;
            FormationData data = new FormationData();
            data.width             = width;
            data.height            = height;
            data.formationPosition = formationPosition;
            formationList.Add(data);
        }

        lodDrawer0 = new LodedDrawerECS(bakedData.NewMesh, material, bakedData);
        lodDrawer1 = new LodedDrawerECS(bakedData.lods.Lod1Mesh, material, bakedData);
        lodDrawer2 = new LodedDrawerECS(bakedData.lods.Lod2Mesh, material, bakedData);
        lodDrawer3 = new LodedDrawerECS(bakedData.lods.Lod3Mesh, material, bakedData);
    }
示例#5
0
    void Start()
    {
        var bakingObject             = GameObject.Instantiate(go);
        SkinnedMeshRenderer renderer = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>();

        lodData              = new LodData();
        lodData.Lod1Mesh     = mesh0;
        lodData.Lod2Mesh     = mesh1;
        lodData.Lod3Mesh     = mesh2;
        lodData.Lod1Distance = 10;
        lodData.Lod2Distance = 20;
        lodData.Lod3Distance = 30;

        bakedData = KeyframeTextureBaker.BakeClips(renderer, GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), lodData);

        TransferAnimationData();

        UnityEngine.Object fGo = Resources.Load("Formation");
        for (int i = 0; i < formationCount; i++)
        {
            int width  = 12;
            int height = 6;

            Vector3 formationPosition = new Vector3(i % 5 * (width + 5), 1, i / 5 * (height + 4));

            GameObject instance = Instantiate(fGo) as GameObject;
            instance.name = "Formation_" + i;
            Formation form = instance.GetComponent <Formation>();
            form.Init(width, height);
            instance.transform.position = formationPosition;
            formationList.Add(form);
        }

        //SaveTextureToFile(bakedData.Texture0, "tp1.png");
        //SaveTextureToFile(bakedData.Texture1, "tp2.png");
        //SaveTextureToFile(bakedData.Texture2, "tp3.png");

        lodDrawer0 = new LodedDrawer(bakedData.NewMesh, material, bakedData, animationClipData, formationList);
        lodDrawer1 = new LodedDrawer(bakedData.lods.Lod1Mesh, material, bakedData, animationClipData, formationList);
        lodDrawer2 = new LodedDrawer(bakedData.lods.Lod2Mesh, material, bakedData, animationClipData, formationList);
        lodDrawer3 = new LodedDrawer(bakedData.lods.Lod3Mesh, material, bakedData, animationClipData, formationList);
    }
示例#6
0
    private void InstantiatePerUnitTypeData(UnitType type)
    {
        var minionPrefab             = Spawner.GetMinionPrefab(type);
        var renderingData            = minionPrefab.GetComponentInChildren <RenderingDataWrapper>().Value;
        var bakingObject             = GameObject.Instantiate(renderingData.BakingPrefab);
        SkinnedMeshRenderer renderer = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>();
        Material            material = renderingData.Material;
        LodData             lodData  = renderingData.LodData;

        var dataPerUnitType = new DataPerUnitType
        {
            UnitType  = type,
            BakedData = KeyframeTextureBaker.BakeClips(renderer,
                                                       GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), lodData),
            Material = material,
        };

        dataPerUnitType.Drawer     = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.NewMesh);
        dataPerUnitType.Lod1Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.lods.Lod1Mesh);
        dataPerUnitType.Lod2Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.lods.Lod2Mesh);
        dataPerUnitType.Lod3Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.lods.Lod3Mesh);

#if !USE_SAFE_JOBS
        dataPerUnitType.BufferPointers     = new NativeArray <IntPtr>(12, Allocator.Persistent);
        dataPerUnitType.BufferPointers[0]  = dataPerUnitType.Drawer.BufferPointers[0];
        dataPerUnitType.BufferPointers[1]  = dataPerUnitType.Drawer.BufferPointers[1];
        dataPerUnitType.BufferPointers[2]  = dataPerUnitType.Drawer.BufferPointers[2];
        dataPerUnitType.BufferPointers[3]  = dataPerUnitType.Lod1Drawer.BufferPointers[0];
        dataPerUnitType.BufferPointers[4]  = dataPerUnitType.Lod1Drawer.BufferPointers[1];
        dataPerUnitType.BufferPointers[5]  = dataPerUnitType.Lod1Drawer.BufferPointers[2];
        dataPerUnitType.BufferPointers[6]  = dataPerUnitType.Lod2Drawer.BufferPointers[0];
        dataPerUnitType.BufferPointers[7]  = dataPerUnitType.Lod2Drawer.BufferPointers[1];
        dataPerUnitType.BufferPointers[8]  = dataPerUnitType.Lod2Drawer.BufferPointers[2];
        dataPerUnitType.BufferPointers[9]  = dataPerUnitType.Lod3Drawer.BufferPointers[0];
        dataPerUnitType.BufferPointers[10] = dataPerUnitType.Lod3Drawer.BufferPointers[1];
        dataPerUnitType.BufferPointers[11] = dataPerUnitType.Lod3Drawer.BufferPointers[2];
#endif

        perUnitTypeDataHolder.Add(type, dataPerUnitType);
        TransferAnimationData(type);
        GameObject.Destroy(bakingObject);
    }
        public static BakedData BakeClips(GameObject animationRoot, AnimationClip[] animationClips, float framerate, LodData lods)
        {
            var skinRenderers = animationRoot.GetComponentsInChildren <SkinnedMeshRenderer>();

            if (skinRenderers.Length != 1)
            {
                throw new System.ArgumentException("There must be exactly one SkinnedMeshRenderer");
            }

            // @TODO: warning about more than one materials

            // Before messing about with some arbitrary game object hierarchy.
            // Instantiate the character, but make sure it's inactive so it doesn't trigger any unexpected systems.
            var wasActive = animationRoot.activeSelf;

            animationRoot.SetActive(false);
            var instance = GameObject.Instantiate(animationRoot, Vector3.zero, Quaternion.identity);

            animationRoot.SetActive(wasActive);

            instance.transform.localScale = Vector3.one;
            var skinRenderer = instance.GetComponentInChildren <SkinnedMeshRenderer>();

            BakedData bakedData = new BakedData();

            bakedData.NewMesh = CreateMesh(skinRenderer);
            var lod1Mesh = CreateMesh(skinRenderer, lods.Lod1Mesh);
            var lod2Mesh = CreateMesh(skinRenderer, lods.Lod2Mesh);
            var lod3Mesh = CreateMesh(skinRenderer, lods.Lod3Mesh);

            bakedData.lods = new LodData(lod1Mesh, lod2Mesh, lod3Mesh, lods.Lod1Distance, lods.Lod2Distance, lods.Lod3Distance);

            bakedData.Framerate = framerate;

            var sampledBoneMatrices = new List <Matrix4x4[, ]>();

            int numberOfKeyFrames = 0;

            for (int i = 0; i < animationClips.Length; i++)
            {
                var sampledMatrix = SampleAnimationClip(instance, animationClips[i], skinRenderer, bakedData.Framerate);
                sampledBoneMatrices.Add(sampledMatrix);

                numberOfKeyFrames += sampledMatrix.GetLength(0);
            }

            int numberOfBones = sampledBoneMatrices[0].GetLength(1);

            var tex0 = bakedData.AnimationTextures.Animation0 = new Texture2D(numberOfKeyFrames, numberOfBones, TextureFormat.RGBAFloat, false);

            tex0.wrapMode   = TextureWrapMode.Clamp;
            tex0.filterMode = FilterMode.Point;
            tex0.anisoLevel = 0;

            var tex1 = bakedData.AnimationTextures.Animation1 = new Texture2D(numberOfKeyFrames, numberOfBones, TextureFormat.RGBAFloat, false);

            tex1.wrapMode   = TextureWrapMode.Clamp;
            tex1.filterMode = FilterMode.Point;
            tex1.anisoLevel = 0;

            var tex2 = bakedData.AnimationTextures.Animation2 = new Texture2D(numberOfKeyFrames, numberOfBones, TextureFormat.RGBAFloat, false);

            tex2.wrapMode   = TextureWrapMode.Clamp;
            tex2.filterMode = FilterMode.Point;
            tex2.anisoLevel = 0;

            Color[] texture0Color = new Color[tex0.width * tex0.height];
            Color[] texture1Color = new Color[tex0.width * tex0.height];
            Color[] texture2Color = new Color[tex0.width * tex0.height];

            int runningTotalNumberOfKeyframes = 0;

            for (int i = 0; i < sampledBoneMatrices.Count; i++)
            {
                for (int boneIndex = 0; boneIndex < sampledBoneMatrices[i].GetLength(1); boneIndex++)
                {
                    //Color previousRotation = new Color();

                    for (int keyframeIndex = 0; keyframeIndex < sampledBoneMatrices[i].GetLength(0); keyframeIndex++)
                    {
                        //var rotation = GetRotation(Quaternion.LookRotation(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetColumn(2),
                        //													sampledBoneMatrices[i][keyframeIndex, boneIndex].GetColumn(1)));

                        //if (keyframeIndex != 0)
                        //{
                        //	if (Distance(previousRotation, rotation) > Distance(Negate(rotation), previousRotation))
                        //	{
                        //		rotation = new Color(-rotation.r, -rotation.g, -rotation.b, -rotation.a);
                        //	}
                        //}

                        //var translation = GetTranslation(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetColumn(3), rotation);

                        //previousRotation = rotation;
                        //int index = Get1DCoord(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex, bakedData.TranslationTexture.width);
                        //translations[index] = translation;
                        //rotations[index] = rotation;

                        int index = Get1DCoord(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex, tex0.width);

                        texture0Color[index] = sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(0);
                        texture1Color[index] = sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(1);
                        texture2Color[index] = sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(2);
                    }
                }

                AnimationClipData clipData = new AnimationClipData
                {
                    Clip       = animationClips[i],
                    PixelStart = runningTotalNumberOfKeyframes + 1,
                    PixelEnd   = runningTotalNumberOfKeyframes + sampledBoneMatrices[i].GetLength(0) - 1
                };

                if (clipData.Clip.wrapMode == WrapMode.Default)
                {
                    clipData.PixelEnd -= 1;
                }

                bakedData.Animations.Add(clipData);

                runningTotalNumberOfKeyframes += sampledBoneMatrices[i].GetLength(0);
            }

            tex0.SetPixels(texture0Color);
            tex1.SetPixels(texture1Color);
            tex2.SetPixels(texture2Color);

            runningTotalNumberOfKeyframes = 0;
            for (int i = 0; i < sampledBoneMatrices.Count; i++)
            {
                for (int boneIndex = 0; boneIndex < sampledBoneMatrices[i].GetLength(1); boneIndex++)
                {
                    for (int keyframeIndex = 0; keyframeIndex < sampledBoneMatrices[i].GetLength(0); keyframeIndex++)
                    {
                        //int d1_index = Get1DCoord(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex, bakedData.Texture0.width);

                        Color pixel0 = tex0.GetPixel(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex);
                        Color pixel1 = tex1.GetPixel(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex);
                        Color pixel2 = tex2.GetPixel(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex);

                        if ((Vector4)pixel0 != sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(0))
                        {
                            Debug.LogError("Error at (" + (runningTotalNumberOfKeyframes + keyframeIndex) + ", " + boneIndex + ") expected " + Format(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(0)) + " but got " + Format(pixel0));
                        }
                        if ((Vector4)pixel1 != sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(1))
                        {
                            Debug.LogError("Error at (" + (runningTotalNumberOfKeyframes + keyframeIndex) + ", " + boneIndex + ") expected " + Format(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(1)) + " but got " + Format(pixel1));
                        }
                        if ((Vector4)pixel2 != sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(2))
                        {
                            Debug.LogError("Error at (" + (runningTotalNumberOfKeyframes + keyframeIndex) + ", " + boneIndex + ") expected " + Format(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(2)) + " but got " + Format(pixel2));
                        }
                    }
                }
                runningTotalNumberOfKeyframes += sampledBoneMatrices[i].GetLength(0);
            }

            tex0.Apply(false, true);
            tex1.Apply(false, true);
            tex2.Apply(false, true);

            bakedData.AnimationsDictionary = new Dictionary <string, AnimationClipData>();
            foreach (var clipData in bakedData.Animations)
            {
                bakedData.AnimationsDictionary[clipData.Clip.name] = clipData;
            }

            GameObject.DestroyImmediate(instance);

            return(bakedData);
        }
示例#8
0
    public static BakedData BakeClips(SkinnedMeshRenderer originalRenderer, AnimationClip[] animationClips, LodData lods)
    {
        BakedData bakedData = new BakedData();

        bakedData.NewMesh = CreateMesh(originalRenderer, lods.Scale);
        var lod1Mesh = CreateMesh(originalRenderer, lods.Scale, lods.Lod1Mesh);
        var lod2Mesh = CreateMesh(originalRenderer, lods.Scale, lods.Lod2Mesh);
        var lod3Mesh = CreateMesh(originalRenderer, lods.Scale, lods.Lod3Mesh);

        bakedData.lods = new LodData(lod1Mesh, lod2Mesh, lod3Mesh, lods.Lod1Distance, lods.Lod2Distance, lods.Lod3Distance);

        bakedData.Framerate = 60f;

        List <Matrix4x4[, ]> sampledBoneMatrices = new List <Matrix4x4[, ]>();

        int numberOfKeyFrames  = 0;
        var animationComponent = originalRenderer.GetComponentInParent <Animation>();

        for (int i = 0; i < animationClips.Length; i++)
        {
            animationComponent[animationClips[i].name].enabled = false;
            animationComponent[animationClips[i].name].weight  = 0f;
        }

        for (int i = 0; i < animationClips.Length; i++)
        {
            Debug.Log("x " + i + " " + animationClips[i].name);
            var sampledMatrix = SampleAnimationClip(animationClips[i], originalRenderer, bakedData.Framerate);
            sampledBoneMatrices.Add(sampledMatrix);

            numberOfKeyFrames += sampledMatrix.GetLength(0);
        }

        int numberOfBones = sampledBoneMatrices[0].GetLength(1);

        bakedData.Texture0            = new Texture2D(numberOfKeyFrames, numberOfBones, TextureFormat.RGBAFloat, false);
        bakedData.Texture0.wrapMode   = TextureWrapMode.Clamp;
        bakedData.Texture0.filterMode = FilterMode.Point;
        bakedData.Texture0.anisoLevel = 0;

        bakedData.Texture1            = new Texture2D(numberOfKeyFrames, numberOfBones, TextureFormat.RGBAFloat, false);
        bakedData.Texture1.wrapMode   = TextureWrapMode.Clamp;
        bakedData.Texture1.filterMode = FilterMode.Point;
        bakedData.Texture1.anisoLevel = 0;

        bakedData.Texture2            = new Texture2D(numberOfKeyFrames, numberOfBones, TextureFormat.RGBAFloat, false);
        bakedData.Texture2.wrapMode   = TextureWrapMode.Clamp;
        bakedData.Texture2.filterMode = FilterMode.Point;
        bakedData.Texture2.anisoLevel = 0;

        Color[] texture0Color = new Color[bakedData.Texture0.width * bakedData.Texture0.height];
        Color[] texture1Color = new Color[bakedData.Texture0.width * bakedData.Texture0.height];
        Color[] texture2Color = new Color[bakedData.Texture0.width * bakedData.Texture0.height];

        int runningTotalNumberOfKeyframes = 0;

        for (int i = 0; i < sampledBoneMatrices.Count; i++)
        {
            for (int boneIndex = 0; boneIndex < sampledBoneMatrices[i].GetLength(1); boneIndex++)
            {
                //Color previousRotation = new Color();

                for (int keyframeIndex = 0; keyframeIndex < sampledBoneMatrices[i].GetLength(0); keyframeIndex++)
                {
                    //var rotation = GetRotation(Quaternion.LookRotation(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetColumn(2),
                    //													sampledBoneMatrices[i][keyframeIndex, boneIndex].GetColumn(1)));

                    //if (keyframeIndex != 0)
                    //{
                    //	if (Distance(previousRotation, rotation) > Distance(Negate(rotation), previousRotation))
                    //	{
                    //		rotation = new Color(-rotation.r, -rotation.g, -rotation.b, -rotation.a);
                    //	}
                    //}

                    //var translation = GetTranslation(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetColumn(3), rotation);

                    //previousRotation = rotation;
                    //int index = Get1DCoord(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex, bakedData.TranslationTexture.width);
                    //translations[index] = translation;
                    //rotations[index] = rotation;

                    int index = Get1DCoord(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex, bakedData.Texture0.width);

                    texture0Color[index] = sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(0);
                    texture1Color[index] = sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(1);
                    texture2Color[index] = sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(2);
                }
            }

            AnimationClipData clipData = new AnimationClipData
            {
                Clip       = animationClips[i],
                PixelStart = runningTotalNumberOfKeyframes + 1,
                PixelEnd   = runningTotalNumberOfKeyframes + sampledBoneMatrices[i].GetLength(0) - 1
            };

            if (clipData.Clip.wrapMode == WrapMode.Default)
            {
                clipData.PixelEnd -= 1;
            }

            bakedData.Animations.Add(clipData);

            runningTotalNumberOfKeyframes += sampledBoneMatrices[i].GetLength(0);
        }

        bakedData.Texture0.SetPixels(texture0Color);
        bakedData.Texture0.Apply(false, false);

        bakedData.Texture1.SetPixels(texture1Color);
        bakedData.Texture1.Apply(false, false);

        bakedData.Texture2.SetPixels(texture2Color);
        bakedData.Texture2.Apply(false, false);


        runningTotalNumberOfKeyframes = 0;
        for (int i = 0; i < sampledBoneMatrices.Count; i++)
        {
            for (int boneIndex = 0; boneIndex < sampledBoneMatrices[i].GetLength(1); boneIndex++)
            {
                for (int keyframeIndex = 0; keyframeIndex < sampledBoneMatrices[i].GetLength(0); keyframeIndex++)
                {
                    //int d1_index = Get1DCoord(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex, bakedData.Texture0.width);

                    Color pixel0 = bakedData.Texture0.GetPixel(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex);
                    Color pixel1 = bakedData.Texture1.GetPixel(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex);
                    Color pixel2 = bakedData.Texture2.GetPixel(runningTotalNumberOfKeyframes + keyframeIndex, boneIndex);

                    if ((Vector4)pixel0 != sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(0))
                    {
                        Debug.LogError("Error at (" + (runningTotalNumberOfKeyframes + keyframeIndex) + ", " + boneIndex + ") expected " + Format(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(0)) + " but got " + Format(pixel0));
                    }
                    if ((Vector4)pixel1 != sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(1))
                    {
                        Debug.LogError("Error at (" + (runningTotalNumberOfKeyframes + keyframeIndex) + ", " + boneIndex + ") expected " + Format(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(1)) + " but got " + Format(pixel1));
                    }
                    if ((Vector4)pixel2 != sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(2))
                    {
                        Debug.LogError("Error at (" + (runningTotalNumberOfKeyframes + keyframeIndex) + ", " + boneIndex + ") expected " + Format(sampledBoneMatrices[i][keyframeIndex, boneIndex].GetRow(2)) + " but got " + Format(pixel2));
                    }
                }
            }
            runningTotalNumberOfKeyframes += sampledBoneMatrices[i].GetLength(0);
        }

        bakedData.AnimationsDictionary = new Dictionary <string, AnimationClipData>();
        foreach (var clipData in bakedData.Animations)
        {
            bakedData.AnimationsDictionary[clipData.Clip.name] = clipData;
        }

        return(bakedData);
    }