Exemple #1
0
        /// <summary>
        /// Enables the user to perform automatic retopology on the .OBJ mesh via Instant Meshes.
        /// </summary>
        /// <param name="serializedObject"></param> The serialized object to modify.
        public void SubsectionRunInstantMeshesOBJ(SerializedObject serializedObject)
        {
            EditorGUILayout.Space();
            string workspace      = dataHandler.dataDirectory;
            string inputFilePath  = Path.Combine(workspace, BlenderConnector.convertPLYtoOBJOutputFileName);
            string outputFilePath = inputFilePath;
            string label          = "Perform automatic retopology.";
            string tooltip        = "This will re-mesh the .OBJ file at \"" + GeneralToolkit.FormatPathForCommand(inputFilePath) + "\".";
            // Check if this option is available.
            bool isGUIEnabled = GUI.enabled;

            GUI.enabled = isGUIEnabled && File.Exists(inputFilePath) && Application.isPlaying;
            GeneralToolkit.EditorRequirePlayMode(ref tooltip);
            // Display a button to launch the helper method.
            bool hasPressed = GeneralToolkit.EditorWordWrapLeftButton(new GUIContent("Run", tooltip), new GUIContent(label, tooltip));

            // If the button is pressed, launch the method.
            if (hasPressed)
            {
                BlenderHelper blenderHelper = GetComponent <BlenderHelper>();
                StartCoroutine(InstantMeshesConnector.RunInstantMeshesCoroutine(this, workspace, inputFilePath, outputFilePath, blenderHelper));
            }
            // Reset the GUI.
            GUI.enabled = isGUIEnabled;
            EditorGUILayout.Space();
        }
        /// <summary>
        /// Coroutine that applies the Smart UV Project algorithm to the given .OBJ file.
        /// </summary>
        /// <param name="caller"></param> The Blender helper calling this method.
        /// <param name="inputFilePath"></param> The full path to the input .OBJ file.
        /// <param name="outputFilePath"></param> The full path to the output .OBJ file.
        /// <returns></returns>
        public static IEnumerator RunSmartUVProjectOBJCoroutine(BlenderHelper caller, string inputFilePath, string outputFilePath)
        {
            // Indicate to the user that the process has started.
            GeneralToolkit.ResetCancelableProgressBar(true, true);
            // Initialize the coroutine parameters.
            bool displayProgressBar; bool stopOnError; string[] progressBarParams;

            InitBlenderCoroutineParams(true, out displayProgressBar, out stopOnError, out progressBarParams);
            progressBarParams[1] = "Smart UV Project on .OBJ";
            // Launch the command.
            string command = FormatBlenderCommand(_smartUVProjectOBJFileName, inputFilePath, outputFilePath);

            yield return(caller.StartCoroutine(GeneralToolkit.RunCommandCoroutine(typeof(BlenderConnector), command, _externalPythonScriptsDir, displayProgressBar, null, _harmlessWarnings, stopOnError, progressBarParams)));

            // Display the uv-mapped mesh in the Scene view.
            caller.DisplayMeshInSceneView(outputFilePath);
            // Indicate to the user that the process has ended.
            GeneralToolkit.ResetCancelableProgressBar(false, false);
        }
        // /// <summary>
        // /// Coroutine that checks an .OBJ's mesh information.
        // /// </summary>
        // /// <param name="caller"></param> The object calling this method.
        // /// <param name="inputFilePath"></param> The full path to the input .OBJ file.
        // /// <param name="storeFaceCount"></param> Action that stores the mesh's face count.
        // /// <returns></returns>
        // public static IEnumerator RunCheckOBJMeshInfoCoroutine(MonoBehaviour caller, string inputFilePath, System.Diagnostics.DataReceivedEventHandler storeFaceCount)
        // {
        //     // Indicate to the user that the process has started.
        //     GeneralToolkit.ResetCancelableProgressBar(true, false);
        //     // Initialize the coroutine parameters.
        //     bool displayProgressBar; bool stopOnError; string[] progressBarParams;
        //     InitBlenderCoroutineParams(false, out displayProgressBar, out stopOnError, out progressBarParams);
        //     progressBarParams[1] = "Check .OBJ mesh information";
        //     // Launch the command.
        //     string command = FormatBlenderCommand(_checkOBJMeshInfoFileName, inputFilePath);
        //     yield return caller.StartCoroutine(GeneralToolkit.RunCommandCoroutine(typeof(BlenderConnector), command, _externalPythonScriptsDir, displayProgressBar, storeFaceCount, _harmlessWarnings, stopOnError, progressBarParams));
        //     // Indicate to the user that the process has ended.
        //     GeneralToolkit.ResetCancelableProgressBar(false, false);
        // }

        /// <summary>
        /// Coroutine that simplifies the mesh in a .OBJ file using the decimation modifier.
        /// </summary>
        /// <param name="caller"></param> The Blender helper calling this method.
        /// <param name="inputFilePath"></param> The full path to the input .OBJ file.
        /// <param name="outputFilePath"></param> The full path to the output .OBJ file.
        /// <param name="storeFaceCount"></param> Action that stores the mesh's face count.
        /// <returns></returns>
        public static IEnumerator RunSimplifyOBJCoroutine(BlenderHelper caller, string inputFilePath, string outputFilePath, System.Diagnostics.DataReceivedEventHandler storeFaceCount)
        {
            // Indicate to the user that the process has started.
            GeneralToolkit.ResetCancelableProgressBar(true, true);
            // Initialize the coroutine parameters.
            bool displayProgressBar; bool stopOnError; string[] progressBarParams;

            InitBlenderCoroutineParams(true, out displayProgressBar, out stopOnError, out progressBarParams);
            progressBarParams[1] = "Convert .PLY to .OBJ";
            // Launch the command.
            string command = FormatBlenderCommand(_simplifyOBJFileName, inputFilePath, outputFilePath);

            yield return(caller.StartCoroutine(GeneralToolkit.RunCommandCoroutine(typeof(BlenderConnector), command, _externalPythonScriptsDir, displayProgressBar, storeFaceCount, _harmlessWarnings, stopOnError, progressBarParams)));

            // Display the simplified mesh in the Scene view.
            caller.DisplayMeshInSceneView(outputFilePath);
            // Indicate to the user that the process has ended.
            GeneralToolkit.ResetCancelableProgressBar(false, false);
        }
Exemple #4
0
        /// <summary>
        /// Coroutine that performs automatic retopology on a given mesh using the Instant Meshes implementation.
        /// </summary>
        /// <param name="caller"></param> The object calling this method.
        /// <param name="workspace"></param> The workspace from which to launch the command.
        /// <param name="inputFilePath"></param> The full path to the input .PLY or .OBJ file.
        /// <param name="outputFilePath"></param> The full path to the output .PLY or .OBJ file.
        /// <param name="blenderHelper"></param> The helper component for Blender.
        /// <returns></returns>
        public static IEnumerator RunInstantMeshesCoroutine(MonoBehaviour caller, string workspace, string inputFilePath, string outputFilePath, BlenderHelper blenderHelper)
        {
            // Indicate to the user that the process has started.
            GeneralToolkit.ResetCancelableProgressBar(true, true);
            // Initialize the command parameters.
            bool displayProgressBar = true;
            bool stopOnError        = true;

            string[] progressBarParams = new string[3];
            progressBarParams[0] = "2";
            progressBarParams[1] = "Automatic retopology";
            progressBarParams[2] = "Processing canceled by user.";
            // Prepare the command.
            string formattedExePath = InstantMeshesSettings.formattedInstantMeshesExePath;
            string command          = "CALL " + formattedExePath;

            command += " --output " + GeneralToolkit.FormatPathForCommand(outputFilePath);
            command += " --deterministic --boundaries --rosy 6 --posy 6";
            // If there is a Blender helper, use the determined mesh face count to define the desired face count.
            if (blenderHelper != null && blenderHelper.meshFaceCount != -1)
            {
                command += " --faces " + GeneralToolkit.ToString(blenderHelper.meshFaceCount);
            }
            // Launch the command.
            command += " " + GeneralToolkit.FormatPathForCommand(inputFilePath);
            yield return(caller.StartCoroutine(GeneralToolkit.RunCommandCoroutine(typeof(InstantMeshesConnector), command, workspace, displayProgressBar, null, null, stopOnError, progressBarParams)));

            // If there is a Blender helper, update the mesh's face count.
            if (blenderHelper != null)
            {
                blenderHelper.CheckOBJMeshInfo(workspace);
            }
            // Indicate to the user that the process has ended.
            GeneralToolkit.ResetCancelableProgressBar(false, false);
        }