Пример #1
0
        private void SetAsNewMeshAssetsAndSave(List <GameObject> texturedGameObjectList)
        {
            //Creates the directory these meshes will go into
            AssetDirectoryService vertexColoredGameObjectDirectoryService = new AssetDirectoryService(this.vertexColoredGameObject);

            vertexColoredGameObjectDirectoryService.CreateSubFolder(vertexColoredGameObjectDirectoryService.GetAssetDirectory(), "VertexColoredMeshes");

            foreach (MeshFilter texturedMeshFilter in texturedGameObjectList
                     .Select(go => go.GetComponent <MeshFilter>()))
            {
                //Create a copy of the mesh and set it as the new mesh
                Mesh newMesh = Object.Instantiate(texturedMeshFilter.sharedMesh);

                AssetDirectoryService newMeshAssetDirectoryService = new AssetDirectoryService(newMesh);

                newMeshAssetDirectoryService.SaveAsset(Path.Combine(vertexColoredGameObjectDirectoryService.GetAssetDirectory(), "VertexColoredMeshes"), newMesh.name);

                texturedMeshFilter.sharedMesh = newMesh;

                AssetDatabase.SaveAssets();
            }
        }
Пример #2
0
        void OnGUI()
        {
            textureToConvert = EditorGUILayout.ObjectField("Texture to Convert", textureToConvert, typeof(Texture2D), false)
                               as Texture2D;

            //TODO: Verify texture input before acting on it
            if (GUILayout.Button("Create Dx11 Texture2DArray") && textureToConvert != null)
            {
                //We'll save it at the same location
                AssetDirectoryService originalAssetDirectory = new AssetDirectoryService(textureToConvert);

                //These values should be the same
                int widthPerTile  = textureToConvert.width / 16;
                int heightPerTile = textureToConvert.height / 8;

                Debug.Log("Using Format: " + textureToConvert.format.ToString());
                //We use 16 by 8 because that is the layout for Spyro 1 and 2 (maybe 3 too haven't check)
                //meaning we have an entire array of them now.

                //TODO: Will we ever be able to support mipmapping?
                //TODO: We can do an optimization by cutting the length of it off at the tile count
                Texture2DArray textureArray = new Texture2DArray(widthPerTile, heightPerTile, 16 * 8, textureToConvert.format, false);

                List <int> index = new List <int>();
                //TODO: Should we allow configurable size?
                for (int indexX = 0; indexX < 16; indexX++)
                {
                    for (int indexY = 0; indexY < 8; indexY++)
                    {
                        index.Add(indexY * 16 + indexX);
                        //We use 7 - indexY because UV Y starts at the bottom left corner
                        textureArray.SetPixels(textureToConvert.GetPixels(indexX * widthPerTile, indexY * heightPerTile, widthPerTile, heightPerTile), indexY * 16 + indexX);
                    }
                }

                foreach (int i in index.OrderBy(i => i))
                {
                    Debug.Log(i);
                }

                textureArray.Apply(false, true);

                AssetDirectoryService newTextuAssetDirectoryService = new AssetDirectoryService(textureArray);
                newTextuAssetDirectoryService.SaveAsset(originalAssetDirectory.GetAssetDirectory(), textureToConvert.name + "_" + "texture2Darray");
            }
        }