/// <summary> /// Open given session in a new Houdini instance. /// </summary> /// <param name="session">Session to open. If null, will use default session.</param> /// <returns>True if successfully loaded session</returns> public static bool OpenSessionInHoudini(HEU_SessionBase session = null) { if (session == null || !session.IsSessionValid()) { session = GetOrCreateDefaultSession(); if (session == null || !session.IsSessionValid()) { session.SetSessionErrorMsg("No valid session found. Unable to open session in Houdini!", true); return false; } } string HIPName = string.Format("hscene_{0}.hip", System.IO.Path.GetRandomFileName().Replace(".", "")); string HIPPath = Application.temporaryCachePath + HEU_Platform.DirectorySeparatorStr + HIPName; if(!session.SaveHIPFile(HIPPath, false)) { session.SetSessionErrorMsg("Unable to save session to .hip file at: " + HIPPath, true); return false; } Debug.Log("Saved session to " + HIPPath); string HoudiniPath = HEU_PluginSettings.HoudiniDebugLaunchPath; #if UNITY_EDITOR_OSX // On macOS, need to add path to actual binary within the .app if (HoudiniPath.EndsWith(".app", System.StringComparison.InvariantCulture)) { HoudiniPath += "/Contents/MacOS/houdini"; } #endif var HoudiniProcess = new System.Diagnostics.Process(); HoudiniProcess.StartInfo.FileName = HoudiniPath; HoudiniProcess.StartInfo.Arguments = string.Format("\"{0}\"", HIPPath); if(!HoudiniProcess.Start()) { session.SetSessionErrorMsg("Unable to start Houdini. Check that the Houdini Debug Exectable path is valid in Plugin Settings.", true); HEU_EditorUtility.RevealInFinder(HIPPath); return false; } return true; }
/// <summary> /// Save given session to a HIP file. /// The user will be prompted with Unity's file dialog to choose HIP file location. /// </summary> /// <param name="bLockNodes">Whether to lock nodes in HIP file so as not to recook them on load</param> /// <param name="session">Session to save out. If null, uses default session.</param> /// <returns>True if successfully saved session</returns> public static bool SaveSessionToHIP(bool bLockNodes, HEU_SessionBase session = null) { if (session == null || !session.IsSessionValid()) { session = GetOrCreateDefaultSession(); if (session == null || !session.IsSessionValid()) { session.SetSessionErrorMsg("No valid session found. Unable to save session!", true); return false; } } #if UNITY_EDITOR string fileExt = "hip"; HAPI_License license = GetCurrentLicense(false); if (license == HAPI_License.HAPI_LICENSE_HOUDINI_INDIE || license == HAPI_License.HAPI_LICENSE_HOUDINI_ENGINE_INDIE) { fileExt = "hiplc"; } string filePath = UnityEditor.EditorUtility.SaveFilePanel("Save HIP File", "", "hscene", fileExt); if (!string.IsNullOrEmpty(filePath)) { bool bResult = session.SaveHIPFile(filePath, bLockNodes); if (bResult) { HEU_EditorUtility.RevealInFinder(filePath); } return bResult; } else { return true; } #else session.SetSessionErrorMsg("Save session only supported in Unity Editor!", true); return false; #endif }
/// <summary> /// Open given session in a new Houdini instance. /// </summary> /// <param name="session">Session to open. If null, will use default session.</param> /// <returns>True if successfully loaded session</returns> public static bool OpenSessionInHoudini(HEU_SessionBase session = null) { if (session == null || !session.IsSessionValid()) { session = GetOrCreateDefaultSession(); if (session == null || !session.IsSessionValid()) { session.SetSessionErrorMsg("No valid session found. Unable to open session in Houdini!", true); return false; } } string HIPName = string.Format("hscene_{0}.hip", System.IO.Path.GetRandomFileName().Replace(".", "")); string HIPPath = Application.temporaryCachePath + HEU_Platform.DirectorySeparatorStr + HIPName; if (!session.SaveHIPFile(HIPPath, false)) { session.SetSessionErrorMsg("Unable to save session to .hip file at: " + HIPPath, true); return false; } Debug.Log("Saved session to " + HIPPath); string HoudiniPath = HEU_PluginSettings.HoudiniDebugLaunchPath; #if UNITY_EDITOR_OSX // On macOS, need to find the actual executable, which is within one of .app folders // that Houdini ships with, depending on the installation type. // HoudiniPath should by default be pointing to the HFS (Houdini install) folder. // Or user should have selected one of the .app folders within. // If not set to .app, then set it based on what app is available if (!HoudiniPath.EndsWith(".app", System.StringComparison.InvariantCulture)) { string[] appNames = { "FX", "Core", "Indie", "Apprentice", "Indie", "Indie Steam Edition" }; string tryPath; foreach(string name in appNames) { tryPath = HEU_Platform.BuildPath(HoudiniPath, string.Format("Houdini {0} {1}.app", name, HEU_HoudiniVersion.HOUDINI_VERSION_STRING)); if (HEU_Platform.DoesPathExist(tryPath)) { HoudiniPath = tryPath; break; } } } if (HoudiniPath.EndsWith(".app", System.StringComparison.InvariantCulture)) { // Get the executable name inside the .app, but the executable // name is based on the license type, so need to query the // license type and map it to executable name: // Houdini Apprenctice 18.0.100 // Houdini Core 18.0.100 // Houdini FX 18.0.100 // Houdini Indie 18.0.100 // Houdini Indie Steam Edition 18.0.100 //HoudiniPath = "/Applications/Houdini/Houdini18.0.100/Houdini Indie 18.0.100.app"; string hexecutable = ""; string pattern = @"(.*)/Houdini (.*) (.*).app$"; Regex reg = new Regex(pattern); Match match = reg.Match(HoudiniPath); if (match.Success && match.Groups.Count > 2) { switch(match.Groups[2].Value) { case "Apprentice": hexecutable = "happrentice"; break; case "Core": hexecutable = "houdinicore"; break; case "FX": hexecutable = "houdini"; break; case "Indie": hexecutable = "hindie"; break; case "Indie Steam Edition": hexecutable = "hindie.steam"; break; default: break; } } HoudiniPath += "/Contents/MacOS/" + hexecutable; } #endif var HoudiniProcess = new System.Diagnostics.Process(); HoudiniProcess.StartInfo.FileName = HoudiniPath; HoudiniProcess.StartInfo.Arguments = string.Format("\"{0}\"", HIPPath); if (!HoudiniProcess.Start()) { session.SetSessionErrorMsg("Unable to start Houdini. Check that the Houdini Debug Exectable path is valid in Plugin Settings.", true); HEU_EditorUtility.RevealInFinder(HIPPath); return false; } return true; }