Ejemplo n.º 1
0
        public Texture2D GetTexture(PreviewType previewType)
        {
            Texture2D tex = GetModule().GetTexture(textureSize);

            if (invert)
            {
                TextureMaker.InvertColors(ref tex);
            }

            switch (previewType)
            {
            case PreviewType.GRAYSCALE:
                tex = TextureMaker.MakeGrayscale(tex);
                break;

            case PreviewType.NORMAL_MAP:
                tex = TextureMaker.MakeNormalMap(tex, strength);
                break;

            case PreviewType.SOBEL_OPERATOR:
                tex = TextureMaker.SobelFilter(tex, strength);
                break;
            }

            return(tex);
        }
Ejemplo n.º 2
0
        private static void Init()
        {
            // Generate a random icon on startup.
            Gradient gradient = new Gradient();

            gradient.mode = GradientMode.Fixed;

            GradientColorKey[] cKeys = new GradientColorKey[3];
            cKeys[0].color = Random.ColorHSV();
            cKeys[0].time  = 0.33f;
            cKeys[1].color = Random.ColorHSV();;
            cKeys[1].time  = 0.66f;
            cKeys[2].color = Random.ColorHSV();;
            cKeys[2].time  = 1.00f;

            GradientAlphaKey[] aKeys = new GradientAlphaKey[1];
            aKeys[0].alpha = 1f;
            aKeys[0].time  = 0f;

            gradient.SetKeys(cKeys, aKeys);

            GUIContent content = new GUIContent();

            content.text  = "Texture Maker";
            content.image = TextureMaker.FillHorizontal(16, 8, gradient, false);

            window = GetWindow <TextureMakerEditor>();
            window.titleContent = content;
            window.minSize      = new Vector2(300, 450);
            window.maxSize      = new Vector2(400, 600);
            window.Show();
        }
Ejemplo n.º 3
0
        public Texture2D GetTexture()
        {
            if (useAlphaTextures)
            {
                return(TextureMaker.BlendUsingMaskTextures(texturesList.ToArray(), alphaTexturesList.ToArray()));
            }

            return(TextureMaker.BlendTextures(texturesList.ToArray(), blendingFactorsList.ToArray()));
        }
Ejemplo n.º 4
0
        void OnUndo()
        {
            // TODO: Clean up.
            borderTexture = TextureMaker.FillSolid(8, 8, new Color(0.25f, 0.25f, 0.25f, 1f));

            if (currentWindowTab == 0)
            {
                generatedTextureOutput = textureModule.GetTexture(previewType);
            }
            else
            {
                toolsTabTextureOutput = toolsModule.GetTexture(previewType);
            }
        }
Ejemplo n.º 5
0
        public Texture2D GetTexture(Vector2Int textureSize)
        {
            switch (patternType)
            {
            case PatternType.CHECKER:
                return(TextureMaker.FillChecker(textureSize.x, textureSize.y, count, color1, color2, flip));

            case PatternType.CIRCLES:
                return(TextureMaker.FillCircles(textureSize.x, textureSize.y, count, color1, color2, scale, flip));

            case PatternType.TILE:
                return(TextureMaker.FillTile(textureSize.x, textureSize.y, count, padding, color1, color2, flip));

            default:
                return(Texture2D.whiteTexture);
            }
        }
Ejemplo n.º 6
0
        public Texture2D GetTexture(Vector2Int textureSize)
        {
            switch (gradientType)
            {
            case GradientType.HORIZONTAL:
                return(TextureMaker.FillHorizontal(textureSize.x, textureSize.y, gradient, flip));

            case GradientType.VERTICAL:
                return(TextureMaker.FillVertical(textureSize.x, textureSize.y, gradient, flip));

            case GradientType.RADIAL:
                return(TextureMaker.FillRadial(textureSize.x, textureSize.y, gradient, radialMaskThreshold, flip));

            default:
                return(Texture2D.whiteTexture);
            }
        }
Ejemplo n.º 7
0
        public Texture2D GetTexture(Vector2Int textureSize)
        {
            switch (noiseType)
            {
            case NoiseType.PERLIN:
                return(TextureMaker.FillPerlinNoise(textureSize.x, textureSize.y, octaves, perlinNoisePersistence,
                                                    perlinNoiseScale, perlinNoiseOffset, gradient, seed, flip));

            case NoiseType.RANDOM:
                return(TextureMaker.FillRandomNoise(textureSize.x, textureSize.y, seed, useColors));

            case NoiseType.VORONOI:
                return(TextureMaker.FillVoronoi(textureSize.x, textureSize.y, sites, seed, voronoiDstType, renderFlat, useColors, flip));

            default:
                return(Texture2D.whiteTexture);
            }
        }
Ejemplo n.º 8
0
        void OnEnable()
        {
            // EditorPrefs.DeleteKey("TextureMaker");

            var data = EditorPrefs.GetString("TextureMaker", JsonUtility.ToJson(this, false));

            JsonUtility.FromJsonOverwrite(data, this);

            Undo.undoRedoPerformed += OnUndo;

            // TODO: Clean up.
            borderTexture = TextureMaker.FillSolid(8, 8, new Color(0.25f, 0.25f, 0.25f, 1f));

            if (currentWindowTab == 0)
            {
                generatedTextureOutput = textureModule.GetTexture(previewType);
            }
            else
            {
                toolsTabTextureOutput = toolsModule.GetTexture(previewType);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Draws a preview section for the generated texture.
        /// <param name="textureToPreview"> Texture to preview. </param>
        /// </summary>
        void ShowTexturePreview(Texture2D textureToPreview)
        {
            EditorGUILayout.LabelField("Preview", EditorStyles.centeredGreyMiniLabel, options);

            Rect verticalGroupRect = GUILayoutUtility.GetLastRect();

            // Calculate a rect in which the preview texture is drawn in.
            float drawRectX         = verticalGroupRect.x + 5;
            float drawRectY         = verticalGroupRect.y + verticalGroupRect.height + 5;
            float drawRectMaxWidth  = verticalGroupRect.width - 10;
            float drawRectMaxHeight = Mathf.Abs((position.height - (verticalGroupRect.y + verticalGroupRect.height)) - 15);

            Rect drawRect = new Rect(drawRectX, drawRectY, drawRectMaxWidth, drawRectMaxHeight);

            // Calculate a rect which acts as a border to the preview texture.
            Rect borderRect = drawRect;

            borderRect.x      -= 3;
            borderRect.y      -= 3;
            borderRect.width  += 6;
            borderRect.height += 6;


            if (previewMode == PreviewMode.THREE_D)
            {
                if (!createdPreviewObject)
                {
                    previewObject = GameObject.Find("_PreviewCube");

                    if (!previewObject)
                    {
                        previewObject      = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        previewObject.name = "_PreviewCube";
                    }

                    // Standard shader.

                    // previewMat = new Material(Shader.Find("Standard"));
                    // previewMat.EnableKeyword("_MainTex");
                    // previewMat.EnableKeyword("_BumpMap");

                    // Unlit shader.
                    previewMat = new Material(Shader.Find("Unlit/Texture"));

                    previewObject.GetComponent <Renderer>().material = previewMat;

                    previewObjectEditor = Editor.CreateEditor(previewObject);

                    createdPreviewObject = true;
                }

                if (GUI.changed)
                {
                    if (textureToPreview)
                    {
                        borderTexture = TextureMaker.FillSolid(8, 8, new Color(0.25f, 0.25f, 0.25f, 1f));

                        previewMat.SetTexture("_MainTex", textureToPreview);

                        DestroyImmediate(previewObjectEditor);
                        previewObjectEditor = Editor.CreateEditor(previewObject);
                    }
                }

                // Draw the "Preview" label.
                // EditorGUILayout.LabelField("Preview", EditorStyles.centeredGreyMiniLabel, options);

                if (previewObject != null)
                {
                    GUIStyle bgColor = new GUIStyle();
                    bgColor.normal.background = borderTexture;

                    if (previewObjectEditor)
                    {
                        previewObjectEditor.OnInteractivePreviewGUI(drawRect, bgColor);
                    }
                }
            }
            else if (previewMode == PreviewMode.TWO_D)
            {
                if (GUI.changed)
                {
                    if (textureToPreview)
                    {
                        borderTexture = TextureMaker.FillSolid(textureToPreview.width, textureToPreview.height, new Color(0.25f, 0.25f, 0.25f, 1f));
                    }
                }

                // Draw the "Preview" label.
                // EditorGUILayout.LabelField("Preview", EditorStyles.centeredGreyMiniLabel, options);

                if (textureToPreview)
                {
                    // Draws the border image.
                    EditorGUI.DrawTextureTransparent(borderRect, borderTexture, ScaleMode.ScaleToFit);

                    // Draws the preview of the generated image.
                    EditorGUI.DrawTextureTransparent(drawRect, textureToPreview, ScaleMode.ScaleToFit);
                }
            }
        }
Ejemplo n.º 10
0
        public void Draw()
        {
            boxStyle = new GUIStyle("box");
            boxStyle.normal.background = TextureMaker.FillSolid(8, 8, Color.gray);


            EditorGUILayout.BeginVertical(boxStyle);
            {
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false, GUIStyle.none, GUIStyle.none, EditorStyles.textArea, GUILayout.MinHeight(160));

                GUILayout.Space(3);


                for (int i = 0; i < texturesList.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        // TODO: Revisit this in the future. enhance the blending functionality?

                        if (i == 0)
                        {
                            EditorGUILayout.BeginVertical();
                            {
                                EditorGUILayout.HelpBox("Textures must be of equal size in order for blending to work.", MessageType.Info);
                                useAlphaTextures = EditorGUILayout.Toggle("Use alpha textures", useAlphaTextures);
                            }
                            EditorGUILayout.EndVertical();
                        }

                        if (i > 0)
                        {
                            // Alpha textures.

                            if (useAlphaTextures)
                            {
                                EditorGUILayout.LabelField(string.Format("Mask {0}", (i)), EditorStyles.centeredGreyMiniLabel, GUILayout.Width(50));
                                alphaTexturesList[i - 1] = (Texture2D)EditorGUILayout.ObjectField("", alphaTexturesList[i - 1], typeof(Texture2D), false, GUILayout.Width(80));
                            }
                            else
                            {
                                // Sliders.
                                if (texturesList[i])
                                {
                                    GUILayout.FlexibleSpace();

                                    EditorGUILayout.BeginHorizontal();
                                    {
                                        EditorGUILayout.LabelField("Blend " + i, EditorStyles.centeredGreyMiniLabel, GUILayout.MaxWidth(40));
                                        blendingFactorsList[i - 1] = EditorGUILayout.Slider("", blendingFactorsList[i - 1], 0f, 1f, GUILayout.MinWidth(100));
                                        GUILayout.FlexibleSpace();
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                        }

                        // Actual textures to blend.
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.LabelField(string.Format("Texture {0}", i + 1), EditorStyles.centeredGreyMiniLabel, GUILayout.Width(50));
                        texturesList[i] = (Texture2D)EditorGUILayout.ObjectField("", texturesList[i], typeof(Texture2D), false, GUILayout.Width(80));
                    }
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndScrollView();
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Reset"))
                {
                    Reset();
                }

                EditorGUILayout.Space();

                if (GUILayout.Button(" - ", GUILayout.Width(20), GUILayout.Height(20)))
                {
                    if (texturesList.Count > 2)
                    {
                        texturesList.RemoveAt(texturesList.Count - 1);
                        alphaTexturesList.RemoveAt(alphaTexturesList.Count - 1);
                        blendingFactorsList.RemoveAt(blendingFactorsList.Count - 1);
                        scrollPos.y -= 60;
                    }
                }

                if (GUILayout.Button(" + ", GUILayout.Width(20), GUILayout.Height(20)))
                {
                    texturesList.Add(null);
                    alphaTexturesList.Add(null);
                    blendingFactorsList.Add(0);
                    scrollPos.y += 70;
                }
            }
            EditorGUILayout.EndHorizontal();
        }