Пример #1
0
        private static void GenerateOptions()
        {
            //Get a list of all available projections
            Type[] types = typeof(Projection).Assembly.GetTypes();
            optionValues = (from Type type in types where (type.IsSubclassOf(typeof(Projection)) && !type.IsAbstract) select type).ToArray();

            //Get a list of titles for all available projections
            options = new string[optionValues.Length];
            for (int i = 0; i < optionValues.Length; i++)
            {
                Type type = optionValues[i];
                while (type != typeof(Projection))
                {
                    if (options[i] == null)
                    {
                        options[i] = LlockhamEditorUtility.AddSpacesToType(type.Name);
                    }
                    else
                    {
                        options[i] = LlockhamEditorUtility.AddSpacesToType(type.Name) + "/" + options[i];
                    }
                    type = type.BaseType;
                }
            }
        }
Пример #2
0
        public void Update(SerializedProperty ShapeTexture, SerializedProperty Multiplier, SerializedProperty TransparencyType, SerializedProperty Cutoff)
        {
            if (marked)
            {
                Texture2D tex = LlockhamEditorUtility.TextureFromProperty(ShapeTexture);
                float     mul = Multiplier.floatValue;

                bool  cutout = (TransparencyType.enumValueIndex == 0);
                float cutoff = Cutoff.floatValue;

                Color[] pixels = new Color[texture.width * texture.height];
                for (int x = 0; x < texture.width; x++)
                {
                    for (int y = 0; y < texture.height; y++)
                    {
                        //Determine our pixel color
                        Color texPixel;

                        //Border
                        if (x < BorderWidth || x > texture.width - BorderWidth || y < BorderWidth || y > texture.height - BorderWidth)
                        {
                            texPixel = Border;
                        }
                        else
                        {
                            //Alpha
                            float alpha = 0;

                            //Texture & color alpha
                            if (tex != null)
                            {
                                alpha = tex.GetPixel(Mathf.FloorToInt(tex.width / texture.width * y), Mathf.FloorToInt(tex.height / texture.height * x)).r;
                                alpha = alpha * mul;
                            }
                            //Color alpha
                            else
                            {
                                alpha = mul;
                            }

                            //Blend between black and what based on alpha
                            if (cutout)
                            {
                                alpha = (alpha < cutoff) ? 0 : 1;
                            }
                            texPixel = Color.Lerp(Color.black, Color.white, alpha);
                        }

                        //Write to pixel
                        pixels[x * texture.width + y] = texPixel;
                    }
                }

                texture.SetPixels(pixels);
                texture.Apply();

                //No longer marked
                marked = false;
            }
        }
Пример #3
0
        public void Update(SerializedProperty AlbedoTexture, SerializedProperty AlbedoColor, SerializedProperty TransparencyType, SerializedProperty Cutoff)
        {
            if (marked)
            {
                Texture2D tex   = LlockhamEditorUtility.TextureFromProperty(AlbedoTexture);
                Color     color = AlbedoColor.colorValue;

                bool  cutout = (TransparencyType.enumValueIndex == 0);
                float cutoff = Cutoff.floatValue;

                Color[] pixels = new Color[texture.width * texture.height];
                for (int x = 0; x < texture.width; x++)
                {
                    for (int y = 0; y < texture.height; y++)
                    {
                        //Determine our pixel color
                        Color texPixel;

                        //Border
                        if (x < BorderWidth || x > texture.width - BorderWidth || y < BorderWidth || y > texture.height - BorderWidth)
                        {
                            texPixel = Border;
                        }
                        else
                        {
                            //Texture
                            if (tex != null)
                            {
                                texPixel = tex.GetPixel(Mathf.FloorToInt(tex.width / texture.width * y), Mathf.FloorToInt(tex.height / texture.height * x));
                                texPixel = texPixel * color;
                            }
                            //Color
                            else
                            {
                                texPixel = color;
                            }

                            //Checker
                            if (cutout)
                            {
                                texPixel.a = (texPixel.a < cutoff) ? 0 : 1;
                            }
                            texPixel = Color.Lerp(CheckerColor(x, y), texPixel, texPixel.a);
                        }

                        //Write to pixel
                        pixels[x * texture.width + y] = texPixel;
                    }
                }

                texture.SetPixels(pixels);
                texture.Apply();

                //No longer marked
                marked = false;
            }
        }
Пример #4
0
        public void Update(SerializedProperty Texture, SerializedProperty Strength)
        {
            if (marked)
            {
                Texture2D tex      = LlockhamEditorUtility.TextureFromProperty(Texture);
                float     strength = Strength.floatValue;

                Color[] pixels = new Color[texture.width * texture.height];
                for (int x = 0; x < texture.width; x++)
                {
                    for (int y = 0; y < texture.height; y++)
                    {
                        //Determine our pixel color
                        Color texPixel;

                        //Border
                        if (x < BorderWidth || x > texture.width - BorderWidth || y < BorderWidth || y > texture.height - BorderWidth)
                        {
                            texPixel = Border;
                        }
                        else
                        {
                            if (tex != null && strength != 0)
                            {
                                texPixel = tex.GetPixel(Mathf.FloorToInt(tex.width / texture.width * y), Mathf.FloorToInt(tex.height / texture.height * x));
                                //Unpack normals
                                Vector3 pixel = new Vector3((texPixel.r * 2) - 1, (texPixel.g * 2) - 1, (texPixel.b * 2) - 1);
                                //Modify
                                pixel.z /= strength;
                                pixel    = pixel.normalized;
                                //Apply back to pixel
                                texPixel.r = (pixel.x + 1) / 2;
                                texPixel.g = (pixel.y + 1) / 2;
                                texPixel.b = (pixel.z + 1) / 2;
                            }
                            else
                            {
                                texPixel = Color.black;
                            }
                        }

                        //Write to pixel
                        pixels[x * texture.width + y] = texPixel;
                    }
                }

                texture.SetPixels(pixels);
                texture.Apply();

                //No longer marked
                marked = false;
            }
        }
Пример #5
0
        public void Update(SerializedProperty Texture, SerializedProperty Color, SerializedProperty Intensity)
        {
            if (marked)
            {
                Texture2D tex       = LlockhamEditorUtility.TextureFromProperty(Texture);
                Color     color     = Color.colorValue;
                float     intensity = Intensity.floatValue;

                Color[] pixels = new Color[texture.width * texture.height];
                for (int x = 0; x < texture.width; x++)
                {
                    for (int y = 0; y < texture.height; y++)
                    {
                        //Determine our pixel color
                        Color texPixel;

                        //Border
                        if (x < BorderWidth || x > texture.width - BorderWidth || y < BorderWidth || y > texture.height - BorderWidth)
                        {
                            texPixel = Border;
                        }
                        else
                        {
                            //Texture
                            if (tex != null)
                            {
                                texPixel = tex.GetPixel(Mathf.FloorToInt(tex.width / texture.width * y), Mathf.FloorToInt(tex.height / texture.height * x));
                                texPixel = texPixel * (color * intensity);
                            }
                            //Color
                            else
                            {
                                texPixel = (color * intensity);
                            }
                        }

                        //Write to pixel
                        pixels[x * texture.width + y] = texPixel;
                    }
                }

                texture.SetPixels(pixels);
                texture.Apply();

                //No longer marked
                marked = false;
            }
        }
Пример #6
0
        private bool DrawProjection(Rect Rect, string Name, string Type)
        {
            //Draw Rect
            EditorGUI.DrawRect(Rect, LlockhamEditorUtility.ForegroundColor);

            //Draw Labels
            EditorGUI.LabelField(new Rect(Rect.x, Rect.y, Rect.width / 2, Rect.height), Name);
            EditorGUI.LabelField(new Rect(Rect.x + (Rect.width / 2), Rect.y, Rect.width / 2, Rect.height), LlockhamEditorUtility.AddSpacesToType(Type));

            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Rect.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #7
0
        public void Update(SerializedProperty Texture, TextureChannel Channel, SerializedProperty Multiplier)
        {
            if (marked)
            {
                Texture2D tex = LlockhamEditorUtility.TextureFromProperty(Texture);
                float     mul = Multiplier.floatValue;

                Color[] pixels = new Color[texture.width * texture.height];
                for (int x = 0; x < texture.width; x++)
                {
                    for (int y = 0; y < texture.height; y++)
                    {
                        //Determine our pixel color
                        Color texPixel;

                        //Border
                        if (x < BorderWidth || x > texture.width - BorderWidth || y < BorderWidth || y > texture.height - BorderWidth)
                        {
                            texPixel = Border;
                        }
                        else
                        {
                            float metallicity = 0;

                            //Texture
                            if (tex != null)
                            {
                                switch (Channel)
                                {
                                case TextureChannel.r:
                                    metallicity = tex.GetPixel(Mathf.FloorToInt(tex.width / texture.width * y), Mathf.FloorToInt(tex.height / texture.height * x)).r;
                                    break;

                                case TextureChannel.g:
                                    metallicity = tex.GetPixel(Mathf.FloorToInt(tex.width / texture.width * y), Mathf.FloorToInt(tex.height / texture.height * x)).g;
                                    break;

                                case TextureChannel.b:
                                    metallicity = tex.GetPixel(Mathf.FloorToInt(tex.width / texture.width * y), Mathf.FloorToInt(tex.height / texture.height * x)).b;
                                    break;

                                case TextureChannel.a:
                                    metallicity = tex.GetPixel(Mathf.FloorToInt(tex.width / texture.width * y), Mathf.FloorToInt(tex.height / texture.height * x)).a;
                                    break;
                                }

                                metallicity = metallicity * mul;
                            }
                            //Color
                            else
                            {
                                metallicity = mul;
                            }

                            texPixel = Color.Lerp(Color.black, Color.white, metallicity);
                        }

                        //Write to pixel
                        pixels[x * texture.width + y] = texPixel;
                    }
                }

                texture.SetPixels(pixels);
                texture.Apply();

                //No longer marked
                marked = false;
            }
        }