예제 #1
0
파일: Fracture.cs 프로젝트: pppnnn/Blendity
        public static void CreateFrac()
        {
            ParamsModal modal = ScriptableObject.CreateInstance <ParamsModal>();

            string[,] defaultVariables =
            {
                { "numOfPieces",    "20",    "int:2,500" },
                { "noise",          "0",     "float:0,1" },
                { "scaleX",         "1",     "float:0,1" },
                { "scaleY",         "1",     "float:0,1" },
                { "scaleZ",         "1",     "float:0,1" },
                { "smoothFaces",    "False", "bool"      },
                { "sharpEdges",     "True",  "bool"      },
                { "margin",         "0",     "float:0,1" },
                { "recenterOrigin", "True",  "bool"      },
            };
            modal.defaultVariables = defaultVariables;
            modal.OnStart          = (List <KeyValueConfig> variables) =>
            {
                EditorUtility.DisplayProgressBar("Shattering Your Mesh !", "Generating Pieces", .1f);

                Func <string, int, Dictionary <string, string> > EnvCreator = (string fileName, int threadSeed) =>
                {
                    int    seed   = (int)Stopwatch.GetTimestamp() + threadSeed;
                    string output = Utils.GetWindowsPath(fileName, "-frac");
                    Dictionary <string, string> envVars = new Dictionary <string, string> {
                        { "input", $"{fileName}" },
                        { "output", $"{output}" },
                        { "seed", $"{seed}" },
                    };
                    variables.ForEach((variable) => envVars.Add(variable.key, variable.value));
                    return(envVars);
                };

                List <CommandOutput> procOutputs = Core.RunCommandOnSelected(
                    $@"-b -P py_scripts~\fracture.py",
                    EnvCreator
                    );
                procOutputs.ForEach(UnityEngine.Debug.Log);
                EditorUtility.DisplayProgressBar("Shattering Your Mesh !", "Importing Models", .8f);
                AssetDatabase.Refresh();
                EditorUtility.ClearProgressBar();
            };
            modal.ShowModalUtility();
        }
예제 #2
0
        public static void GenerateLOD()
        {
            ParamsModal modal = ScriptableObject.CreateInstance <ParamsModal>();

            string[,] defaultVariables =
            {
                { "number_of_LOD",        "4",  "int:1,8"    },
                { "least_detail_percent", "30", "float:0,99" }
            };
            modal.defaultVariables = defaultVariables;
            modal.OnStart          = (List <KeyValueConfig> variables) =>
            {
                EditorUtility.DisplayProgressBar("Decimating Your Mesh !", "Generating LOD clones", .2f);

                Func <string, int, Dictionary <string, string> > EnvCreator = (string fileName, int threadSeed) =>
                {
                    string input  = Utils.GetWindowsPath(fileName);
                    string output = Utils.GetWindowsPath(fileName, "-LOD");
                    Dictionary <string, string> envVars = new Dictionary <string, string> {
                        { "input", $"{input}" },
                        { "output", $"{output}" }
                    };
                    variables.ForEach((variable) => envVars.Add(variable.key, variable.value));
                    return(envVars);
                };

                List <CommandOutput> procOutputs = Core.RunCommandOnSelected(
                    $@"-b -P py_scripts~\generate_LOD.py",
                    EnvCreator
                    );
                procOutputs.ForEach(UnityEngine.Debug.Log);
                EditorUtility.DisplayProgressBar("Decimating Your Mesh !", "Importing Models", .8f);
                AssetDatabase.Refresh();
                EditorUtility.ClearProgressBar();
            };
            modal.ShowModalUtility();
        }
예제 #3
0
        public static void UnwrapperFn()
        {
            ParamsModal modal = ScriptableObject.CreateInstance <ParamsModal>();

            string[,] defaultVariables =
            {
                { "unwrap_mode", "smart_project", "dropdown:smart_project,lightmap_pack,cube_project,cylinder_project,sphere_project" }
            };
            modal.defaultVariables = defaultVariables;
            modal.OnStart          = (List <KeyValueConfig> variables) =>
            {
                EditorUtility.DisplayProgressBar("Looking at your Mesh !", "Unwraping ...", .1f);

                Func <string, int, Dictionary <string, string> > EnvCreator = (string path, int threadSeed) =>
                {
                    string output = Utils.GetWindowsPath(path, "-unwrapped");
                    Dictionary <string, string> envVars = new Dictionary <string, string> {
                        { "input", $"{path}" },
                        { "output", $"{output}" }
                    };
                    variables.ForEach((variable) => envVars.Add(variable.key, variable.value));
                    return(envVars);
                };

                List <CommandOutput> procOutputs = Core.RunCommandOnSelected(
                    $@"-b -P py_scripts~\unwrap.py",
                    EnvCreator
                    );
                EditorUtility.DisplayProgressBar("Looking at your Mesh !", "Importing Models", .5f);

                procOutputs.ForEach(UnityEngine.Debug.Log);
                AssetDatabase.Refresh();
                EditorUtility.ClearProgressBar();
            };
            modal.ShowModalUtility();
        }
예제 #4
0
        public static void GenerateSpaceship()
        {
            ParamsModal modal = ScriptableObject.CreateInstance <ParamsModal>();

            string[,] defaultVariables =
            {
                { "Number of Spaceships",       "1",     "int:1,20" },
                { "num_hull_segments_min",      "3",     "int:1,20" },
                { "num_hull_segments_max",      "6",     "int:1,20" },
                { "create_asymmetry_segments",  "True",  "bool"     },
                { "num_asymmetry_segments_min", "1",     "int:1,20" },
                { "num_asymmetry_segments_max", "5",     "int:1,20" },
                { "create_face_detail",         "True",  "bool"     },
                { "allow_horizontal_symmetry",  "False", "bool"     },
                { "allow_vertical_symmetry",    "False", "bool"     },
                { "apply_bevel_modifier",       "True",  "bool"     },
                { "assign_materials",           "True",  "bool"     },
            };
            modal.defaultVariables = defaultVariables;
            modal.OnStart          = (List <KeyValueConfig> variables) =>
            {
                EditorUtility.DisplayProgressBar("Creating Spaceships !", "Generating Spaceships", .1f);

                int numOfShips = int.Parse(variables[0].value);
                variables.RemoveAt(0);

                Func <string, int, Dictionary <string, string> > EnvCreator = (string path, int threadSeed) =>
                {
                    int    seed          = (int)Stopwatch.GetTimestamp() + threadSeed;
                    string spaceshipName = $"spaceship_{seed}";
                    string output        = $@"{path}\{spaceshipName}\{spaceshipName}.fbx";
                    Dictionary <string, string> envVars = new Dictionary <string, string> {
                        { "output", $"{output}" }
                    };
                    variables.ForEach((variable) => envVars.Add(variable.key, variable.value));
                    return(envVars);
                };

                List <CommandOutput> procOutputs = Core.RunCommandTimesN(
                    $@"-b -P py_scripts~\generate_spaceship.py",
                    numOfShips,
                    EnvCreator
                    );
                EditorUtility.DisplayProgressBar("Creating Spaceships !", "Importing Models", .5f);

                float progressPerLoop = 0.4f / procOutputs.Count;
                float progress        = 0.55f;
                int   i = 1;

                AssetDatabase.Refresh();
                procOutputs.ForEach(procOutput =>
                {
                    progress += progressPerLoop;
                    EditorUtility.DisplayProgressBar("Creating Spaceships !", "Importing Materials and Textures #" + i++, progress);
                    Utils.ExtractTexturesAndMaterials(procOutput.outputFile);
                });
                AssetDatabase.Refresh();
                EditorUtility.ClearProgressBar();
            };
            modal.ShowModalUtility();
        }