Beispiel #1
0
        public void registerImageFromData(byte[] imageData, int imageID, string imageName = "")
        {
            Texture2D texture = new Texture2D(4, 4);

            texture.name = imageName;
            texture.LoadImage(imageData);
            GL.sRGBWrite = true;
            saveTexture(GLTFTextureUtils.flipTexture(texture), imageID);
        }
        private Texture2D TextureFlipY(Texture2D texture, Func<Color, Color> convertColor = null, Action<Texture2D> processTexture = null)
        {
            Texture2D newTex;
            TextureImporter im = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;

            if (convertColor == null && (im == null || im.textureType != TextureImporterType.NormalMap))
            {
                // use gpu to speed up
                newTex = GLTFTextureUtils.flipTexture(texture);
            }
            else
            {
                int height = texture.height;
                int width = texture.width;
                Color[] newTextureColors = new Color[height * width];

                ExporterUtils.DoActionForTexture(ref texture, tex =>
                {
                    Color[] textureColors = tex.GetPixels();
                    for (int i = 0; i < height; ++i)
                    {
                        for (int j = 0; j < width; ++j)
                        {
                            var c = textureColors[(height - i - 1) * width + j];

                            newTextureColors[i * width + j] = convertColor != null ? convertColor(c) : c;
                        }
                    }
                }
                );

                newTex = new Texture2D(width, height);
                newTex.SetPixels(newTextureColors);
                newTex.Apply();
            }

            if (processTexture != null)
            {
                processTexture(newTex);
            }

            return newTex;
        }