Example #1
0
        public static void AddNoise(string path, List <NoiseType> noiseTypes, double attenMin, double attenMax, bool monoChrome)
        {
            if (noiseTypes.Count < 1)
            {
                return;
            }
            MagickImage img = IOUtils.ReadImage(path);

            if (img == null)
            {
                return;
            }
            NoiseType chosenNoiseType = GetRandomNoiseType(noiseTypes);

            PreProcessing(path, "- Noise Type: " + chosenNoiseType.ToString());
            Random rand = new Random();
            double att  = (double)rand.Next((int)attenMin, (int)attenMax + 1);

            Program.Print("-> Using attenuate factor " + att);
            if (monoChrome)
            {
                MagickImage noiseImg = new MagickImage(MagickColors.White, img.Width, img.Height);
                noiseImg.AddNoise(chosenNoiseType, att);
                noiseImg.ColorSpace = ColorSpace.LinearGray;
                noiseImg.Write(Path.Combine(IOUtils.GetAppDataDir(), "lastnoiseimg.png"));
                img.Composite(noiseImg, CompositeOperator.Multiply);
            }
            else
            {
                img.AddNoise(chosenNoiseType, att);
            }
            img.Write(path);
            PostProcessing(img, path, path);
        }
        public IGameObject Generate()
        {
            var arr = Utils.GetEmptyArray(Size, Size, 0);

            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    arr[i][j] = GetCellular(i, j);
                }
            }

            arr = PostModifications.Normalize(arr, Size, Height);
            HeightMapGenerator.Generate(_graphicDevice, arr, "Voronoi (" + noiseType.ToString() + ")");
            return(new PrimitiveBase(_graphicDevice, _graphicDeviceManeger, arr, Size));
        }
Example #3
0
    public void Heard(Transform source, NoiseType type)
    {
        Debug.Log("Heard : " + type.ToString());
        switch (type)
        {
        case NoiseType.INTERPEL:
            brain.SetCheck(source);
            break;

        case NoiseType.AGRESSIVE:
        case NoiseType.WEIRD:
            brain.mouth.SayToRadio(null);
            brain.mouth.TellInformationToOthers(IAInformation.InformationType.CHECKING, 2f, type.ToString());
            brain.SetCheck(source);
            break;

        case NoiseType.BYE:
            if (brain.currentState.tag == IAState.IAStateTag.TALKING)
            {
                brain.StopTalking();
            }
            break;
        }
    }
Example #4
0
    void OnGUI()
    {
        GUILayout.Label("Noise Texture Generator", EditorStyles.boldLabel);


        noiseType = (NoiseType)EditorGUILayout.EnumPopup("noise type", noiseType);

        if ((int)noiseType == 0 || (int)noiseType == 1)
        {
            boxSize  = EditorGUILayout.Slider("boxSize", boxSize, 0, 1);
            deepness = EditorGUILayout.IntField("deepness", deepness);
            delta    = EditorGUILayout.IntField("delta", delta);
        }
        else
        {
            EditorGUILayout.Space();
        }

        textureSpace = (TextureSpace)EditorGUILayout.EnumPopup("texture space", textureSpace);

        if ((int)textureSpace == 0)
        {
            resolution2d = EditorGUILayout.IntSlider("texture2d size", resolution2d, 2, 2048);
        }
        if ((int)textureSpace == 1)
        {
            resolution3d = EditorGUILayout.IntSlider("texture3d size", resolution3d, 2, 256);
        }
        //limit atlas textures to squares
        int sqrt = Mathf.RoundToInt(Mathf.Pow(resolution3d, 0.25f));

        resolution3d = sqrt * sqrt * sqrt * sqrt;
        //
        if (GUI.changed)
        {
            NoiseGenerator.noiseType = noiseType;
        }
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Generate Texture", GUILayout.Width(150)))
        {
            if ((int)textureSpace == 0)
            {
                noiseTex = NoiseGenerator.Generate2D(boxSize, deepness, delta, resolution2d);
            }
            if ((int)textureSpace == 1)
            {
                noiseTex = NoiseGenerator.Generate3DAtlas(boxSize, deepness, delta, resolution3d);
            }
            saved = false;
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        Rect    rect = GUILayoutUtility.GetLastRect();
        Vector2 size = rect.size;

        //Debug.Log(rect.ToString());

        if (noiseTex)
        {
            rect.position += new Vector2(155, rect.height + 10);
            if (rect.width - 159 > 0)
            {
                rect.width  = Mathf.Min(rect.width - 159, noiseTex.width);
                rect.height = rect.width * noiseTex.height / noiseTex.width;
                EditorGUI.DrawPreviewTexture(rect, noiseTex, null, ScaleMode.ScaleToFit);
            }

            GUILayout.Space(20);
            if (GUILayout.Button("Save Texture", GUILayout.Width(120), GUILayout.Height(25)))
            {
                //encode creation parameters into the texture name
                string[] tNameParts = tName.Split('_');
                int      nParts     = tNameParts.Length;
                tName = tNameParts[0] + "_" + textureSpace.ToString().Replace("texture", "") + "_" + noiseType.ToString();
                if ((int)noiseType != 2)
                {
                    tName += "_" + boxSize.ToString() + "_" + deepness.ToString("0") + "_" + delta.ToString("0");
                }
                tName += "_";
                if (nParts > 1)
                {
                    tName += tNameParts[nParts - 1];
                }
                //

                string path = EditorUtility.SaveFilePanel("Save Noise Texture", tPath, tName + ".png", "png");

                if (path.Length > 0)
                {
                    byte[] bytes = noiseTex.EncodeToPNG();
                    File.WriteAllBytes(path, bytes);
                    tName = Path.GetFileNameWithoutExtension(path);
                    tPath = Path.GetDirectoryName(path);
                    saved = true;
                    if (path.Contains(Application.dataPath)) //reimport if saved within the Assets folder
                    {
                        AssetDatabase.Refresh();
                        string          assetPath = path.Replace(Application.dataPath, "Assets");
                        TextureImporter A         = (TextureImporter)AssetImporter.GetAtPath(assetPath);
                        A.textureCompression = TextureImporterCompression.Uncompressed;

                        if (noiseType == NoiseType.pixel)
                        {
                            A.filterMode = FilterMode.Point;
                        }
                        A.maxTextureSize = 8192;
                        A.mipmapEnabled  = false;
                        AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
                        tName = Path.GetFileNameWithoutExtension(path);
                    }
                }
            }

            GUILayout.Space(20);
            GUI.skin.label.wordWrap = true;
            if (saved)
            {
                GUILayout.Label(new GUIContent(tName + ".png"), GUILayout.Width(120), GUILayout.ExpandHeight(true));
            }
        }
    }
Example #5
0
 public override string ToString()
 {
     return(Type.ToString());
 }