public override void OnInspectorGUI() { EditorGUILayout.LabelField(new GUIContent("Prefab Path:")); EditorGUILayout.BeginHorizontal(); { string old_prefab_path = myMeshToPrefab.prPathToPrefab; string new_prefab_path = ""; new_prefab_path = EditorGUILayout.TextField(old_prefab_path); if (GUILayout.Button("...", GUILayout.Width(myFileChooserButtonWidth))) { string prompt_result_path = HoudiniGUIUtility.promptForPrefabPath(old_prefab_path); if (prompt_result_path.Length > 0) { new_prefab_path = prompt_result_path; } } myMeshToPrefab.prPathToPrefab = new_prefab_path; } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Save To Prefab")) { myMeshToPrefab.SaveToPrefab(); } }
static private void loadHipFile() { if ( !HoudiniHost.isInstallationOk() ) { HoudiniHost.displayHoudiniEngineInstallInfo(); return; } string hip_file_path = HoudiniGUIUtility.promptForHIPPath(); HoudiniAssetUtility.loadHipFile( hip_file_path ); }
static private void createHAPIObject() { if ( !HoudiniHost.isInstallationOk() ) { HoudiniHost.displayHoudiniEngineInstallInfo(); return; } string asset_file_path = HoudiniGUIUtility.promptForOTLPath(); HoudiniAssetUtility.instantiateAsset( asset_file_path ); }
public void OnGUI() { bool gui_enable = GUI.enabled; #if !( HAPI_ENABLE_RUNTIME ) HoudiniGUI.help(HoudiniConstants.HAPI_UNSUPPORTED_PLATFORM_MSG, MessageType.Info); GUI.enabled = false; #else if (!HoudiniHost.isInstallationOk()) { HoudiniGUI.help( HoudiniHost.getMissingEngineInstallHelpString(), MessageType.Info); GUI.enabled = false; } #endif // !( HAPI_ENABLE_RUNTIME ) if (GUILayout.Button(HoudiniGUIUtility.myLoadAssetLabel)) { string asset_file_path = HoudiniGUIUtility.promptForOTLPath(); HoudiniAssetUtility.instantiateAsset(asset_file_path); } if (GUILayout.Button(HoudiniGUIUtility.myLoadHipLabel)) { string hip_file_path = HoudiniGUIUtility.promptForHIPPath(); HoudiniAssetUtility.loadHipFile(hip_file_path); } HoudiniGUI.separator(); if (GUILayout.Button(HoudiniGUIUtility.mySaveHoudiniSceneLabel)) { HoudiniGUIUtility.saveHoudiniScene(myLockNodesOnHipSave); } { bool undo_value = myLockNodesOnHipSave; HoudiniGUI.toggle( "lock_nodes", "Lock Nodes On Scene Save", ref myLockNodesOnHipSave, null, ref undo_value); } HoudiniGUI.separator(); if (GUILayout.Button("Check for New Untracked Asset Nodes")) { HoudiniAssetUtility.checkForNewAssets(); } HoudiniGUI.separator(); if (HoudiniGUI.floatField("global_time", "Global Time", ref myTime, null, ref myTime)) { HoudiniHost.setTime(myTime); } HoudiniGUI.separator(); string path = Application.dataPath; myScrollPosition = GUILayout.BeginScrollView(myScrollPosition); if (GUILayout.Button("Instantiate Core Assets")) { try { DirectoryInfo core = new DirectoryInfo(path + "//OTLs/Core"); if (!core.Exists) { throw new HoudiniError("Project/Assets/OTLs/Core directory does not exist!"); } foreach (FileInfo fi in core.GetFiles()) { if (fi.Extension == ".otl") { loadOTL(fi); } } } catch (System.Exception e) { Debug.LogError("Directory navigation failed: " + e.ToString()); } } #if ( HAPI_ENABLE_RUNTIME ) DirectoryInfo di = new DirectoryInfo(path + "//OTLs"); try { if (!di.Exists) { throw new HoudiniError("Project/Assets/OTLs directory does not exist!"); } foreach (DirectoryInfo child_directory in di.GetDirectories()) { OTLDirectory otlDir = null; foreach (OTLDirectory existingOTLDir in myOTLDirectories) { if (existingOTLDir.myDirectoryName == child_directory.Name) { otlDir = existingOTLDir; break; } } if (otlDir == null) { otlDir = new OTLDirectory(); otlDir.myDirectoryName = child_directory.Name; otlDir.myDirectoryPath = child_directory.FullName; otlDir.myExpanded = false; myOTLDirectories.Add(otlDir); } otlDir.myExpanded = EditorGUILayout.Foldout(otlDir.myExpanded, new GUIContent(otlDir.myDirectoryName)); if (otlDir.myDirectoryName == "Core") { otlDir.myExpanded = true; } if (otlDir.myExpanded) { DirectoryInfo dirContents = new DirectoryInfo(otlDir.myDirectoryPath); foreach (FileInfo fi in dirContents.GetFiles()) { if (fi.Extension == ".otl") { genOTLEntry(fi); } } } } } catch (System.Exception e) { Debug.LogError("Directory navigation failed: " + e.ToString()); } #endif // ( HAPI_ENABLE_RUNTIME ) GUILayout.EndScrollView(); GUI.enabled = gui_enable; }
public void OnSceneGUI() { // We can only build or do anything if we can link to our libraries. #if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || (UNITY_METRO && UNITY_EDITOR)) return; #pragma warning disable 0162 #endif // !( UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || ( UNITY_METRO && UNITY_EDITOR ) ) if (myCurve == null) { return; } // Enable point size on OpenGL. HoudiniHost.preDrawSetup(); // First Remake and Draw Guide Geometry if necessary. if (mySelectionMeshColours == null) { buildGuideGeometry(); } if (!myTempCamera && Camera.current) { myTempCamera = Camera.current; } Event current_event = Event.current; Vector3 mouse_position = getMousePosition(ref current_event); // Set appropriate handles matrix. // TODO: Fix. /* * Vector3 handle_pos = HAPI_AssetUtility.getPosition( myCurve.transform.localToWorldMatrix ); * Quaternion handle_rot = HAPI_AssetUtility.getQuaternion( myCurve.transform.localToWorldMatrix ); * Matrix4x4 handle_matrix = Matrix4x4.identity; * handle_matrix.SetTRS( handle_pos, handle_rot, new Vector3( 1.0f, 1.0f, 1.0f ) ); * //Debug.Log( handle_pos ); * //Debug.Log( handle_rot ); * //Debug.Log( handle_matrix ); * Handles.matrix = handle_matrix; */ Handles.matrix = myCurve.transform.localToWorldMatrix; // Determine key state. getKeyState(current_event); // Decide modes. if (current_event.type == EventType.Layout && mySceneWindowHasFocus) { decideModes(ref current_event); } // Draw scene UI. drawSceneUI(); // Add points. if (!current_event.alt && !(current_event.type == EventType.MouseDown && current_event.button == 1)) { if (myCurve.prIsAddingPoints) { Vector3 position = Vector3.zero; float handle_size = HandleUtility.GetHandleSize(position) * myBigButtonHandleSizeMultiplier; Quaternion rotation = HoudiniAssetUtility.getQuaternion(myTempCamera.transform.localToWorldMatrix); bool button_press = Handles.Button(position, rotation, handle_size, handle_size, Handles.RectangleCap); Ray ray = myTempCamera.ScreenPointToRay(mouse_position); #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 if (!myTempCamera.isOrthoGraphic) #else if (!myTempCamera.orthographic) #endif // UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6{ ray.origin = myTempCamera.transform.position; } Vector3 intersection = new Vector3(); if (myTarget != null && myTarget.GetComponent <Collider>()) { Collider collider = myTarget.GetComponent <Collider>(); RaycastHit hit_info; collider.Raycast(ray, out hit_info, myIntersectionRayLength); intersection = hit_info.point; } else { Plane plane = new Plane(); plane.SetNormalAndPosition(Vector3.up, Vector3.zero); float enter = 0.0f; plane.Raycast(ray, out enter); enter = Mathf.Clamp(enter, myTempCamera.nearClipPlane, myTempCamera.farClipPlane); intersection = ray.origin + ray.direction * enter; } bool is_mid_point = false; int insert_index = -1; Vector3 new_point_location = intersection; // Draw guide line. if (myCurve.prPoints.Count > 0) { Vector3 anchor1 = myCurve.transform.TransformPoint( myCurve.prPoints[myCurve.prPoints.Count - 1]); Vector3 anchor2 = Vector3.zero; insert_index = myCurve.prPoints.Count; // See if we're close to another segment. for (int i = 1; i < myCurve.prPoints.Count; ++i) { Vector3 p0 = myCurve.transform.TransformPoint(myCurve.prPoints[i - 1]); Vector3 p1 = myCurve.transform.TransformPoint(myCurve.prPoints[i]); Vector3 closest_point = new Vector3(); float distance = HoudiniGUIUtility.closestDistanceBetweenLineAndLineSegment( p0, p1, ray, out closest_point); if (distance < HandleUtility.GetHandleSize(closest_point) / HoudiniHost.prGuideMinDistanceForMidPointInsertion) { anchor1 = p0; anchor2 = p1; new_point_location = closest_point; insert_index = i; is_mid_point = true; } } int point_count = (is_mid_point ? 3 : 2); Vector3[] line_vertices = new Vector3[point_count]; int[] line_indices = new int[point_count]; Vector2[] uvs = new Vector2[point_count]; line_vertices[0] = HoudiniGUIUtility.getCameraNearPlanePoint(anchor1, myTempCamera); line_vertices[1] = HoudiniGUIUtility.getCameraNearPlanePoint(new_point_location, myTempCamera); float length = Vector3.Distance(line_vertices[0], line_vertices[1]) * myGuideLinesDashTilingMultiplier; line_indices[0] = 0; line_indices[1] = 1; uvs[0] = new Vector2(); uvs[1] = new Vector2(length, length); if (is_mid_point) { line_vertices[2] = HoudiniGUIUtility.getCameraNearPlanePoint(anchor2, myTempCamera); line_indices[2] = 2; length += Vector3.Distance(line_vertices[1], line_vertices[2]) * myGuideLinesDashTilingMultiplier; uvs[2] = new Vector2(length, length); } myGuideLinesMesh.Clear(); myGuideLinesMesh.vertices = line_vertices; myGuideLinesMesh.uv = uvs; myGuideLinesMesh.SetIndices(line_indices, MeshTopology.LineStrip, 0); myGuideLinesMaterial.SetPass(0); myGuideLinesMaterial.SetColor("_Color", HoudiniHost.prGuideWireframeColour); myGuideLinesMaterial.SetTextureScale("_MainTex", new Vector2(1.0f, 1.0f)); Graphics.DrawMeshNow(myGuideLinesMesh, Matrix4x4.identity); } // Add points on click. if (button_press) { // Once we add a point we are no longer bound to the user holding down the add points key. // Add points mode is now fully activated. myCurve.prModeChangeWait = false; // Need to inverse transform the new point because it is in world space // and we want it to stay in the same location as it is in world space // when it is parented to the curve's transform. new_point_location = myCurve.transform.InverseTransformPoint(new_point_location); if (is_mid_point) { myCurve.insertPoint(insert_index, new_point_location); } else { myCurve.addPoint(new_point_location); } // Remake and Draw Guide Geometry buildGuideGeometry(); } // Delete last point on backspace. if (current_event.isKey && current_event.type == EventType.KeyUp && (current_event.keyCode == KeyCode.Delete || current_event.keyCode == KeyCode.Backspace)) { // Once we add a point we are no longer bound to the user holding down the add points key. // Add points mode is now fully activated. myCurve.prModeChangeWait = false; myCurve.deleteLastPoint(); // Remake and Draw Guide Geometry buildGuideGeometry(); } if (current_event.isKey && current_event.keyCode == KeyCode.Delete || current_event.keyCode == KeyCode.Backspace) { Event.current.Use(); } } // Add mode. else if (myCurve.prIsEditingPoints) { // Track mouse dragging. if (current_event.type == EventType.MouseDown && current_event.button == 0 && !myIsMouseDown) { myIsMouseDown = true; myFirstMousePosition = mouse_position; } // I have to also interpret the Ignore event as the mouse up event because that's all I // get if the use lets go of the mouse button while over a different Unity window... else if (((current_event.type == EventType.MouseUp && current_event.button == 0) || (current_event.type == EventType.Ignore)) && myIsMouseDown) { myIsMouseDown = false; // Deselect all. if (!current_event.control) { clearSelection(); } Ray ray = myTempCamera.ScreenPointToRay(mouse_position); ray.origin = myTempCamera.transform.position; Vector3 mouse_delta = myFirstMousePosition - mouse_position; Vector3 max_bounds = mouse_position; Vector3 min_bounds = mouse_position; max_bounds.x = Mathf.Max(max_bounds.x, myFirstMousePosition.x); max_bounds.y = Mathf.Max(max_bounds.y, myFirstMousePosition.y); min_bounds.x = Mathf.Min(min_bounds.x, myFirstMousePosition.x); min_bounds.y = Mathf.Min(min_bounds.y, myFirstMousePosition.y); // Get Picking Information Vector3[] points = myCurve.prPoints.ToArray(); for (int i = 0; points != null && i < points.Length; ++i) { Vector3 transformed_point = myCurve.transform.TransformPoint(points[i]); Vector3 proj_pos = myTempCamera.WorldToScreenPoint(transformed_point); proj_pos.z = 0.0f; if (Mathf.Abs(mouse_delta.x) > 1.5f || Mathf.Abs(mouse_delta.y) > 1.5f) { if (proj_pos.x >= min_bounds.x && proj_pos.x <= max_bounds.x && proj_pos.y >= min_bounds.y && proj_pos.y <= max_bounds.y) { // Once we modify a point we are no longer bound to the user holding down // the point edit key. Edit point mode is now fully activated. myCurve.prModeChangeWait = false; togglePointSelection(i); } } // drag else { float distance = Vector3.Distance(mouse_position, proj_pos); if (distance < HoudiniHost.prMinDistanceForPointSelection) { // Once we modify a point we are no longer bound to the user holding down // the point edit key. Edit point mode is now fully activated. myCurve.prModeChangeWait = false; togglePointSelection(i); } // if point hit } // single click } // for all points } // mouse up // Prevent click from being passed lower (this is so stupid!). Vector3 position = Vector3.zero; float handle_size = HandleUtility.GetHandleSize(position) * myBigButtonHandleSizeMultiplier; Quaternion rotation = HoudiniAssetUtility.getQuaternion(myTempCamera.transform.localToWorldMatrix); Handles.Button(position, rotation, handle_size, handle_size, Handles.RectangleCap); // Prevent the delete key from deleting the curve in this mode. if (current_event.isKey && current_event.keyCode == KeyCode.Delete) { Event.current.Use(); } } // Edit mode. } // Not currently pressing alt.
static private void saveHoudiniScene() { HoudiniGUIUtility.saveHoudiniScene(false); }
public void OnGUI() { bool gui_enable = GUI.enabled; #if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || (UNITY_METRO && UNITY_EDITOR)) HoudiniGUI.help(HoudiniConstants.HAPI_UNSUPPORTED_PLATFORM_MSG, MessageType.Info); GUI.enabled = false; #else if (!HoudiniHost.isInstallationOk()) { HoudiniGUI.help( HoudiniHost.getMissingEngineInstallHelpString(), MessageType.Info); GUI.enabled = false; } #endif // !( UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || ( UNITY_METRO && UNITY_EDITOR ) ) if (GUILayout.Button(HoudiniGUIUtility.mySaveHoudiniSceneLabel)) { HAPI_License license = HoudiniHost.getCurrentLicense(); string ext = "hip"; if (license == HAPI_License.HAPI_LICENSE_HOUDINI_ENGINE_INDIE || license == HAPI_License.HAPI_LICENSE_HOUDINI_INDIE) { ext = "hiplc"; } string hip_file_path = EditorUtility.SaveFilePanel("Save HIP File", "", "hscene", ext); if (hip_file_path != "") { HoudiniHost.saveScene(hip_file_path); } } if (GUILayout.Button(HoudiniGUIUtility.myLoadAssetLabel)) { string asset_file_path = HoudiniGUIUtility.promptForOTLPath(); HoudiniAssetUtility.instantiateAsset(asset_file_path); } HoudiniGUI.separator(); if (GUILayout.Button("Check for New Untracked Asset Nodes")) { HoudiniAssetUtility.checkForNewAssets(); } HoudiniGUI.separator(); if (HoudiniGUI.floatField("global_time", "Global Time", ref myTime, null, ref myTime)) { HoudiniHost.setTime(myTime); } HoudiniGUI.separator(); string path = Application.dataPath; myScrollPosition = GUILayout.BeginScrollView(myScrollPosition); if (GUILayout.Button("Instantiate Core Assets")) { try { DirectoryInfo core = new DirectoryInfo(path + "//OTLs/Core"); if (!core.Exists) { throw new HoudiniError("Project/Assets/OTLs/Core directory does not exist!"); } foreach (FileInfo fi in core.GetFiles()) { if (fi.Extension == ".otl") { loadOTL(fi); } } } catch (System.Exception e) { Debug.LogError("Directory navigation failed: " + e.ToString()); } } #if (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || (UNITY_METRO && UNITY_EDITOR)) DirectoryInfo di = new DirectoryInfo(path + "//OTLs"); try { if (!di.Exists) { throw new HoudiniError("Project/Assets/OTLs directory does not exist!"); } foreach (DirectoryInfo child_directory in di.GetDirectories()) { OTLDirectory otlDir = null; foreach (OTLDirectory existingOTLDir in myOTLDirectories) { if (existingOTLDir.myDirectoryName == child_directory.Name) { otlDir = existingOTLDir; break; } } if (otlDir == null) { otlDir = new OTLDirectory(); otlDir.myDirectoryName = child_directory.Name; otlDir.myDirectoryPath = child_directory.FullName; otlDir.myExpanded = false; myOTLDirectories.Add(otlDir); } otlDir.myExpanded = EditorGUILayout.Foldout(otlDir.myExpanded, new GUIContent(otlDir.myDirectoryName)); if (otlDir.myDirectoryName == "Core") { otlDir.myExpanded = true; } if (otlDir.myExpanded) { DirectoryInfo dirContents = new DirectoryInfo(otlDir.myDirectoryPath); foreach (FileInfo fi in dirContents.GetFiles()) { if (fi.Extension == ".otl") { genOTLEntry(fi); } } } } } catch (System.Exception e) { Debug.LogError("Directory navigation failed: " + e.ToString()); } #endif // ( UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || ( UNITY_METRO && UNITY_EDITOR ) ) GUILayout.EndScrollView(); GUI.enabled = gui_enable; }