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.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)) { 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, 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 (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; }
public override void OnInspectorGUI() { try { myDelayBuild = false; myParmChanges = false; myFocusChanged = false; Event current_event = Event.current; bool commit_changes = false; if (current_event.isKey && current_event.type == EventType.KeyUp && current_event.keyCode == KeyCode.Return) { commit_changes = true; } else if ( current_event.type == EventType.ValidateCommand && current_event.commandName == "UndoRedoPerformed") { performUndo(); } /////////////////////////////////////////////////////////////////////// // Draw Asset Controls bool is_editable = myParms.prEditable && HoudiniHost.isInstallationOk(); // We can only build or do anything if we can link to our libraries. #if !( HAPI_ENABLE_RUNTIME ) is_editable = false; HoudiniGUI.help(HoudiniConstants.HAPI_UNSUPPORTED_PLATFORM_MSG, MessageType.Info); #else if (!myParms.prEditable) { HoudiniGUI.help("The parameters on this node are readonly.", MessageType.Info); } else if (!HoudiniHost.isInstallationOk()) { HoudiniGUI.help(HoudiniHost.getMissingEngineInstallHelpString(), MessageType.Info); } #endif // !( HAPI_ENABLE_RUNTIME ) bool gui_enable = GUI.enabled; GUI.enabled = is_editable; myParmChanges |= generateAssetControls(); GUI.enabled = gui_enable; /////////////////////////////////////////////////////////////////////// // Apply Changes // Only record undo info object if parameters are not being changed // due to an undo/redo event. bool record_undo = current_event.commandName != "UndoRedoPerformed"; applyChanges(commit_changes, record_undo); } catch (HoudiniErrorIgnorable) {} catch (HoudiniError error) { Debug.LogError(error.ToString() + "\nSource: " + error.Source); } catch (System.Exception error) { Debug.LogError(error.ToString() + "\nSource: " + error.Source); } }
public override void OnInspectorGUI() { bool gui_enable = GUI.enabled; // We can only build or do anything if we can link to our libraries. #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 ) try { myDelayBuild = false; myParmChanges = false; /////////////////////////////////////////////////////////////////////// // Draw License/Logo Thingy #if ( HAPI_ENABLE_RUNTIME ) drawLicenseLogo(); #endif /////////////////////////////////////////////////////////////////////// // Draw Game Object Controls if (HoudiniHost.isAssetValid(myAsset.prAssetId, myAsset.prAssetValidationId) && (myAsset.prTransformInputCount > 0 || myAsset.prGeoInputCount > 0) && myAsset.prAssetSubType != HAPI_AssetSubType.HAPI_ASSETSUBTYPE_CURVE) { myAsset.prShowInputControls = HoudiniGUI.foldout("Inputs", myAsset.prShowInputControls, true); if (myAsset.prShowInputControls) { if (myAsset.prHAPIAssetType == HAPI_AssetType.HAPI_ASSETTYPE_OBJ) { for (int ii = 0; ii < myAsset.prTransformInputCount; ++ii) { myParmChanges |= setTransformInput(ii); } } if (myAsset.prUpStreamGeoObjects == null || myAsset.prUpStreamGeoAssets == null || myAsset.prUpStreamGeoObjects.Count <= 0 || myAsset.prUpStreamGeoAssets.Count <= 0) { return; } for (int input_index = 0; input_index < myAsset.prGeoInputCount; ++input_index) { bool join_last = false; bool no_label_toggle_last = true; HoudiniGUIParm geo_input = new HoudiniGUIParm( "geo_input_" + input_index, myAsset.prGeoInputNames[input_index]); Object obj = (Object)myAsset.prUpStreamGeoObjects[input_index]; myParmChanges |= HoudiniGUI.objectField( ref geo_input, ref obj, typeof(GameObject), ref join_last, ref no_label_toggle_last); if (myParmChanges || !myAsset.isGeoInputValid(input_index)) { if (!obj) { myAsset.removeGeoInput(input_index); myAsset.buildClientSide(); } else { GameObject new_obj = (GameObject)obj; myAsset.prUpStreamGeoObjects[input_index] = new_obj; // Select the asset component (if it exists). HoudiniAsset asset = new_obj.GetComponent <HoudiniAsset>(); // If we're selecting a specific object to input than try and // get the object id. Note that by getting the HAPI_ObjectControl // component we also cover the geo and part controls because // they all inherit from HAPI_ObjectControl. The user can therefore // drag any gameObject under the asset into another asset's // input and have it all work. int object_index = 0; HoudiniObjectControl obj_control = new_obj.GetComponent <HoudiniObjectControl>(); if (obj_control) { object_index = obj_control.prObjectId; asset = obj_control.prAsset; } if (asset == null) { myAsset.addGeoAsGeoInput(new_obj, input_index); myAsset.buildClientSide(); } else if (myAsset.prUpStreamGeoAssets[input_index] != asset) { if (myAsset == asset) { Debug.LogError("Can't connect an asset to itself!"); } else { myAsset.addAssetAsGeoInput(asset, object_index, input_index); myAsset.buildClientSide(); } } } } } // for } // if } // if // Draw Cook Log Pane myAsset.prShowCookLog = HoudiniGUI.foldout("Asset Cook Log", myAsset.prShowCookLog, true); if (myAsset.prShowCookLog) { drawCookLog(); } } catch (HoudiniError e) { Debug.LogError(e.ToString()); } GUI.enabled = gui_enable; }
private void generateMaterialSettings() { if (GUILayout.Button("Re-Render")) { HoudiniAssetUtility.reApplyMaterials(myAsset); } // Material Shader Type { HAPI_ShaderType value = myAsset.prMaterialShaderType; bool is_bold = myParentPrefabAsset && myParentPrefabAsset.prMaterialShaderType != value; string[] labels = { "OpenGL", "Houdini Mantra Renderer" }; HAPI_ShaderType[] values = { HAPI_ShaderType.HAPI_SHADER_OPENGL, HAPI_ShaderType.HAPI_SHADER_MANTRA }; bool changed = HoudiniGUI.dropdown( "material_renderer", "Material Renderer", ref value, is_bold, labels, values, myUndoInfo, ref myUndoInfo.materialShaderType); if (changed) { myAsset.prMaterialShaderType = (HAPI_ShaderType)value; HoudiniAssetUtility.reApplyMaterials(myAsset); } } // Render Resolution { bool delay_build = false; int[] values = new int[2]; values[0] = (int)myAsset.prRenderResolution[0]; values[1] = (int)myAsset.prRenderResolution[1]; int[] undo_values = new int[2]; undo_values[0] = (int)myUndoInfo.renderResolution[0]; undo_values[1] = (int)myUndoInfo.renderResolution[1]; HoudiniGUIParm gui_parm = new HoudiniGUIParm("render_resolution", "Render Resolution", 2); gui_parm.isBold = myParentPrefabAsset && (int)myParentPrefabAsset.prRenderResolution[0] != values[0] && (int)myParentPrefabAsset.prRenderResolution[1] != values[1]; bool changed = HoudiniGUI.intField( ref gui_parm, ref delay_build, ref values, myUndoInfo, ref undo_values); if (changed) { Vector2 new_resolution = new Vector2((float)values[0], (float)values[1]); myAsset.prRenderResolution = new_resolution; myUndoInfo.renderResolution = new_resolution; } } // Show Vertex Colours createToggleForProperty( "show_only_vertex_colours", "Show Only Vertex Colors", "prShowOnlyVertexColours", ref myUndoInfo.showOnlyVertexColours, () => HoudiniAssetUtility.reApplyMaterials(myAsset)); // Generate Tangents createToggleForProperty( "generate_tangents", "Generate Tangents", "prGenerateTangents", ref myUndoInfo.generateTangents, () => myAssetOTL.build( true, // reload_asset false, // unload_asset_first false, // serialization_recovery_only true, // force_reconnect false, // is_duplication myAsset.prCookingTriggersDownCooks, true // use_delay_for_progress_bar ), !HoudiniHost.isGenerateTangentsDefault()); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); bool gui_enable = GUI.enabled; // 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)) GUI.enabled = false; #else if (!HoudiniHost.isInstallationOk()) { GUI.enabled = false; } #endif // !( UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || ( UNITY_METRO && UNITY_EDITOR ) ) if (myAssetOTL.isPrefabInstance()) { myParentPrefabAsset = myAsset.getParentPrefabAsset(); } /////////////////////////////////////////////////////////////////////// // Draw Game Object Controls myAsset.prShowHoudiniControls = HoudiniGUI.foldout("Houdini Controls", myAsset.prShowHoudiniControls, true); if (myAsset.prShowHoudiniControls) { if (!myAsset.isPrefab()) { if (GUILayout.Button("Rebuild")) { myAsset.buildAll(); } if (GUILayout.Button("Recook")) { myAsset.buildClientSide(); } if (GUILayout.Button("Bake")) { myAsset.bakeAsset(); } } } // Draw Help Pane myAsset.prShowHelp = HoudiniGUI.foldout("Asset Help", myAsset.prShowHelp, true); if (myAsset.prShowHelp) { drawHelpBox(myAsset.prAssetHelp); } /////////////////////////////////////////////////////////////////////// // Draw Asset Settings // These don't affect the asset directly so they don't trigger rebuilds. myAsset.prShowAssetSettings = HoudiniGUI.foldout("Asset Settings", myAsset.prShowAssetSettings, true); if (myAsset.prShowAssetSettings) { generateAssetSettings(); } /////////////////////////////////////////////////////////////////////// // Draw Baking Controls if (!myAsset.isPrefab()) { myAsset.prShowBakeOptions = HoudiniGUI.foldout("Bake Animations", myAssetOTL.prShowBakeOptions, true); if (myAsset.prShowBakeOptions) { generateAssetBakeControls(); } } /////////////////////////////////////////////////////////////////////// // Draw Paint Tools #if !HAPI_PAINT_SUPPORT if (!myAsset.isPrefab()) { myAsset.prShowPaintTools = HoudiniGUI.foldout("Paint Tools", myAssetOTL.prShowPaintTools, true); if (myAsset.prShowPaintTools) { generatePaintToolGUI(); } } #endif // !HAPI_PAINT_SUPPORT GUI.enabled = gui_enable; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Public public void handlesOnSceneGUI() { if (myAssetOTL.prShowPinnedInstances) { drawPinnedInstances(); } // On mouse up the drag operation is completed. if (Event.current.type == EventType.MouseUp) { myOpInProgress = false; } string currentGlobalManipTool = Tools.current.ToString(); if (currentGlobalManipTool == "Rotate") { myManipMode = XformManipMode.Rotate; } else if (currentGlobalManipTool == "Move") { myManipMode = XformManipMode.Translate; } else if (currentGlobalManipTool == "Scale") { myManipMode = XformManipMode.Scale; } if (myAssetOTL == null) { return; } int node_id = myAssetOTL.prNodeId; HAPI_HandleInfo[] handleInfos = myAssetOTL.prHandleInfos; if (handleInfos == null) { return; } // Detect changes and build asset only when changed. bool changed = false; for (int ii = 0; ii < handleInfos.Length; ++ii) { HAPI_HandleInfo handleInfo = handleInfos[ii]; if (handleInfo.typeName == "xform") { float tx = 0, ty = 0, tz = 0; float rx = 0, ry = 0, rz = 0; float sx = 1, sy = 1, sz = 1; HAPI_RSTOrder rstOrder = HAPI_RSTOrder.HAPI_SRT; HAPI_XYZOrder xyzOrder = HAPI_XYZOrder.HAPI_XYZ; HAPI_HandleBindingInfo[] bindingInfos = myAssetOTL.prHandleBindingInfos[ii]; int[] parm_int_values = myAssetOTL.prParms.prParmIntValues; float[] parm_float_values = myAssetOTL.prParms.prParmFloatValues; if (parm_int_values == null || parm_float_values == null) { Debug.LogError("No parm int/float values yet handles exist?"); continue; } int translate_parm_id = -1; int rotate_parm_id = -1; int scale_parm_id = -1; int rst_order_parm_id = -1; int xyz_order_parm_id = -1; foreach (HAPI_HandleBindingInfo bindingInfo in bindingInfos) { string parm_name = bindingInfo.handleParmName; if (parm_name == "tx") { translate_parm_id = bindingInfo.assetParmId; } else if (parm_name == "rx") { rotate_parm_id = bindingInfo.assetParmId; } else if (parm_name == "sx") { scale_parm_id = bindingInfo.assetParmId; } else if (parm_name == "trs_order") { rst_order_parm_id = bindingInfo.assetParmId; } else if (parm_name == "xyz_order") { xyz_order_parm_id = bindingInfo.assetParmId; } } if (translate_parm_id >= 0) { HAPI_ParmInfo parm_info = myAssetOTL.prParms.findParm(translate_parm_id); tx = parm_float_values[parm_info.floatValuesIndex + 0]; ty = parm_float_values[parm_info.floatValuesIndex + 1]; tz = parm_float_values[parm_info.floatValuesIndex + 2]; } if (rotate_parm_id >= 0) { HAPI_ParmInfo parm_info = myAssetOTL.prParms.findParm(rotate_parm_id); rx = parm_float_values[parm_info.floatValuesIndex + 0]; ry = parm_float_values[parm_info.floatValuesIndex + 1]; rz = parm_float_values[parm_info.floatValuesIndex + 2]; } if (scale_parm_id >= 0) { HAPI_ParmInfo parm_info = myAssetOTL.prParms.findParm(scale_parm_id); sx = parm_float_values[parm_info.floatValuesIndex + 0]; sy = parm_float_values[parm_info.floatValuesIndex + 1]; sz = parm_float_values[parm_info.floatValuesIndex + 2]; } if (rst_order_parm_id >= 0) { HAPI_ParmInfo parm_info = myAssetOTL.prParms.findParm(rst_order_parm_id); rstOrder = (HAPI_RSTOrder)parm_int_values[parm_info.intValuesIndex]; } if (xyz_order_parm_id >= 0) { HAPI_ParmInfo parm_info = myAssetOTL.prParms.findParm(xyz_order_parm_id); xyzOrder = (HAPI_XYZOrder)parm_int_values[parm_info.intValuesIndex]; } HAPI_TransformEuler xform = new HAPI_TransformEuler(true); // This bit is a little tricky. We will eventually call Handle.PositionHandle // or Handle.RotationHandle to display the translation and rotation handles. // These function take a translation parameter and a rotation parameter in // order to display the handle in its proper location and orientation. // These functions have an assumed order that it will put the rotation // and translation back together. Depending whether the order of translation // and roation matches that of the rstOrder setting, we may, or may not // need to convert the translation parameter for use with the handle. if (rstOrder == HAPI_RSTOrder.HAPI_TSR || rstOrder == HAPI_RSTOrder.HAPI_STR || rstOrder == HAPI_RSTOrder.HAPI_SRT) { xform.position[0] = tx; xform.position[1] = ty; xform.position[2] = tz; xform.rotationEuler[0] = rx; xform.rotationEuler[1] = ry; xform.rotationEuler[2] = rz; xform.scale[0] = 1; xform.scale[1] = 1; xform.scale[2] = 1; xform.rotationOrder = xyzOrder; xform.rstOrder = rstOrder; } else { xform.position[0] = 0; xform.position[1] = 0; xform.position[2] = 0; xform.rotationEuler[0] = rx; xform.rotationEuler[1] = ry; xform.rotationEuler[2] = rz; xform.scale[0] = 1; xform.scale[1] = 1; xform.scale[2] = 1; xform.rotationOrder = xyzOrder; xform.rstOrder = rstOrder; } xform = HoudiniHost.convertTransform(xform, HAPI_RSTOrder.HAPI_SRT, HAPI_XYZOrder.HAPI_ZXY); // Axis and Rotation conversions: // Note that Houdini's X axis points in the opposite direction that Unity's does. Also, Houdini's // rotation is right handed, whereas Unity is left handed. To account for this, we need to invert // the x coordinate of the translation, and do the same for the rotations (except for the x rotation, // which doesn't need to be flipped because the change in handedness AND direction of the left x axis // causes a double negative - yeah, I know). xform.position[0] = -xform.position[0]; xform.rotationEuler[1] = -xform.rotationEuler[1]; xform.rotationEuler[2] = -xform.rotationEuler[2]; tx = -tx; Handles.matrix = myAssetOTL.transform.localToWorldMatrix; Vector3 position; if (rstOrder == HAPI_RSTOrder.HAPI_TSR || rstOrder == HAPI_RSTOrder.HAPI_STR || rstOrder == HAPI_RSTOrder.HAPI_SRT) { position = new Vector3(xform.position[0], xform.position[1], xform.position[2]); } else { position = new Vector3(tx, ty, tz); } Quaternion rotation = Quaternion.Euler( xform.rotationEuler[0], xform.rotationEuler[1], xform.rotationEuler[2]); Vector3 scale = new Vector3(sx, sy, sz); if (myManipMode == XformManipMode.Translate) { if (translate_parm_id < 0) { continue; } HAPI_ParmInfo parm_info = myAssetOTL.prParms.findParm(translate_parm_id); if (parm_info.invisible) { continue; } GUIStyle style = new GUIStyle(EditorStyles.textField); style.contentOffset = new Vector2(1.4f, 1.4f); string handle_name = handleInfo.name; if (parm_info.disabled) { handle_name = handle_name + " (disabled)"; } GUIContent content = new GUIContent(handle_name); content.tooltip = handle_name; Handles.Label(position, content, style); if (parm_info.disabled) { Handles.lighting = false; Handles.PositionHandle(position, rotation); Handles.lighting = true; continue; } Vector3 new_position = Handles.PositionHandle(position, rotation); if (new_position != position) { changed = true; if (!myOpInProgress) { Undo.RecordObject(myAssetOTL.prParms.prParmsUndoInfo, handleInfo.name); myOpInProgress = true; } if (rstOrder == HAPI_RSTOrder.HAPI_TSR || rstOrder == HAPI_RSTOrder.HAPI_STR || rstOrder == HAPI_RSTOrder.HAPI_SRT) { xform.position[0] = new_position[0]; xform.position[1] = new_position[1]; xform.position[2] = new_position[2]; xform = HoudiniHost.convertTransform(xform, rstOrder, xyzOrder); new_position.x = xform.position[0]; new_position.y = xform.position[1]; new_position.z = xform.position[2]; } // the - in the x coordinate is to convert back to "Houdini" coordinates parm_float_values[parm_info.floatValuesIndex + 0] = -new_position.x; parm_float_values[parm_info.floatValuesIndex + 1] = new_position.y; parm_float_values[parm_info.floatValuesIndex + 2] = new_position.z; float[] temp_float_values = new float[HoudiniConstants.HAPI_POSITION_VECTOR_SIZE]; for (int pp = 0; pp < HoudiniConstants.HAPI_POSITION_VECTOR_SIZE; ++pp) { temp_float_values[pp] = parm_float_values[parm_info.floatValuesIndex + pp]; } HoudiniHost.setParmFloatValues(node_id, temp_float_values, parm_info.floatValuesIndex, parm_info.size); myAsset.savePreset(); } // if changed } else if (myManipMode == XformManipMode.Rotate) { if (rotate_parm_id < 0) { continue; } HAPI_ParmInfo parm_info = myAssetOTL.prParms.findParm(rotate_parm_id); if (parm_info.invisible) { continue; } GUIStyle style = new GUIStyle(EditorStyles.textField); style.contentOffset = new Vector2(1.4f, 1.4f); string handle_name = handleInfo.name; if (parm_info.disabled) { handle_name = handle_name + " (disabled)"; } GUIContent content = new GUIContent(handle_name); content.tooltip = handle_name; Handles.Label(position, content, style); if (parm_info.disabled) { Handles.lighting = false; Handles.RotationHandle(rotation, position); Handles.lighting = true; continue; } Quaternion new_rotation = Handles.RotationHandle(rotation, position); if (new_rotation != rotation) { changed = true; if (!myOpInProgress) { Undo.RecordObject(myAssetOTL.prParms.prParmsUndoInfo, handleInfo.name); myOpInProgress = true; } Vector3 newRot = new_rotation.eulerAngles; xform.position[0] = 0; xform.position[1] = 0; xform.position[2] = 0; xform.rotationEuler[0] = newRot.x; xform.rotationEuler[1] = newRot.y; xform.rotationEuler[2] = newRot.z; xform.scale[0] = 1; xform.scale[1] = 1; xform.scale[2] = 1; xform.rotationOrder = HAPI_XYZOrder.HAPI_ZXY; xform.rstOrder = HAPI_RSTOrder.HAPI_SRT; xform = HoudiniHost.convertTransform(xform, rstOrder, xyzOrder); parm_float_values[parm_info.floatValuesIndex + 0] = xform.rotationEuler[0]; // the - in the y & z coordinate is to convert back to "Houdini" coordinates parm_float_values[parm_info.floatValuesIndex + 1] = -xform.rotationEuler[1]; parm_float_values[parm_info.floatValuesIndex + 2] = -xform.rotationEuler[2]; float[] temp_float_values = new float[HoudiniConstants.HAPI_POSITION_VECTOR_SIZE]; for (int pp = 0; pp < HoudiniConstants.HAPI_POSITION_VECTOR_SIZE; ++pp) { temp_float_values[pp] = parm_float_values[parm_info.floatValuesIndex + pp]; } HoudiniHost.setParmFloatValues( node_id, temp_float_values, parm_info.floatValuesIndex, parm_info.size); myAsset.savePreset(); } // if changed } else if (myManipMode == XformManipMode.Scale) { if (scale_parm_id < 0) { continue; } HAPI_ParmInfo parm_info = myAssetOTL.prParms.findParm(scale_parm_id); if (parm_info.invisible) { continue; } GUIStyle style = new GUIStyle(EditorStyles.textField); style.contentOffset = new Vector2(1.4f, 1.4f); string handle_name = handleInfo.name; if (parm_info.disabled) { handle_name = handle_name + " (disabled)"; } GUIContent content = new GUIContent(handle_name); content.tooltip = handle_name; Handles.Label(position, content, style); if (parm_info.disabled) { Handles.lighting = false; Handles.ScaleHandle(scale, position, rotation, 1.0f); Handles.lighting = true; continue; } Vector3 new_scale = Handles.ScaleHandle(scale, position, rotation, 1.0f); if (new_scale != scale) { changed = true; if (!myOpInProgress) { Undo.RecordObject(myAssetOTL.prParms.prParmsUndoInfo, handleInfo.name); myOpInProgress = true; } parm_float_values[parm_info.floatValuesIndex + 0] = new_scale.x; parm_float_values[parm_info.floatValuesIndex + 1] = new_scale.y; parm_float_values[parm_info.floatValuesIndex + 2] = new_scale.z; float[] temp_float_values = new float[HoudiniConstants.HAPI_POSITION_VECTOR_SIZE]; for (int pp = 0; pp < HoudiniConstants.HAPI_POSITION_VECTOR_SIZE; ++pp) { temp_float_values[pp] = parm_float_values[parm_info.floatValuesIndex + pp]; } HoudiniHost.setParmFloatValues( node_id, temp_float_values, parm_info.floatValuesIndex, parm_info.size); myAsset.savePreset(); } // if changed } // if myManipMode } // if typeName } // for each handle if (changed) { myAssetOTL.buildClientSide(); } }
public void getParameterValues() { if (prControl == null) { return; } if (prControl.prAsset == null) { return; } if (prControl.prAssetId < 0) { return; } if (myPostSerialization) { myValuesEqualToHoudini = areValuesEqualToHoudini(); } else { myValuesEqualToHoudini = true; } // Create undo info if it hasn't been created already if (myParmsUndoInfo == null) { myParmsUndoInfo = ScriptableObject.CreateInstance <HoudiniParmsUndoInfo>(); } // Get the node info again HAPI_NodeInfo node_info = HoudiniHost.getNodeInfo(prControl.prNodeId); prParmCount = node_info.parmCount; prParmIntValueCount = node_info.parmIntValueCount; prParmFloatValueCount = node_info.parmFloatValueCount; prParmStringValueCount = node_info.parmStringValueCount; prParmChoiceCount = node_info.parmChoiceCount; // Get all parameters. prParms = new HAPI_ParmInfo[prParmCount]; myParmInfoStrings = new HAPI_ParmInfoStrings[prParmCount]; if (myParmInputs == null) { myParmInputs = new HAPI_ParmInput[prParmCount]; } HoudiniAssetUtility.getArray1Id(prControl.prNodeId, HoudiniHost.getParameters, prParms, prParmCount); // Get parameter int values. prParmIntValues = new int[prParmIntValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmIntValues, prParmIntValues, prParmIntValueCount); myParmsUndoInfo.parmIntValues = new int[prParmIntValueCount]; Array.Copy(prParmIntValues, myParmsUndoInfo.parmIntValues, prParmIntValueCount); // Get parameter float values. prParmFloatValues = new float[prParmFloatValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmFloatValues, prParmFloatValues, prParmFloatValueCount); myParmsUndoInfo.parmFloatValues = new float[prParmFloatValueCount]; Array.Copy(prParmFloatValues, myParmsUndoInfo.parmFloatValues, prParmFloatValueCount); // Get parameter string (handle) values. prParmStringHandles = new int[prParmStringValueCount]; myParmStringValues = new string[prParmStringValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmStringValues, prParmStringHandles, prParmStringValueCount); // Get parameter choice lists. prParmChoiceLists = new HAPI_ParmChoiceInfo[prParmChoiceCount]; myParmChoiceInfoStrings = new HAPI_ParmChoiceInfoStrings[prParmChoiceCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmChoiceLists, prParmChoiceLists, prParmChoiceCount); cacheStringsFromHost(); // Go through parameters and set index map and multiparm map for undo info myParmsUndoInfo.parmNames.Clear(); myParmsUndoInfo.parmIndices.Clear(); foreach (HAPI_ParmInfo parm in prParms) { // Need to check the index values are greater or equal to 0 // for now because there is a bug where some parameters are // being set to have an integer parameter type, a size of // zero, and an index value of -1 if (parm.isInt() && parm.intValuesIndex >= 0) { myParmsUndoInfo.parmIndices.Add(parm.intValuesIndex); } else if (parm.isFloat() && parm.floatValuesIndex >= 0) { myParmsUndoInfo.parmIndices.Add(parm.floatValuesIndex); } else if (parm.isString() && parm.stringValuesIndex >= 0) { myParmsUndoInfo.parmIndices.Add(parm.stringValuesIndex); } else { continue; } myParmsUndoInfo.parmNames.Add(parm.name); } }
public void statusCheckLoop() { #if UNITY_EDITOR HAPI_State state = HAPI_State.HAPI_STATE_STARTING_LOAD; prCurrentValue = 0; prTotal = 100; bool progress_cancelled = false; while ((int)state > (int)HAPI_State.HAPI_STATE_MAX_READY_STATE) { state = (HAPI_State)HoudiniHost.getStatus(HAPI_StatusType.HAPI_STATUS_COOK_STATE); if (state == HAPI_State.HAPI_STATE_COOKING) { prCurrentValue = HoudiniHost.getCookingCurrentCount(); prTotal = HoudiniHost.getCookingTotalCount(); } else { prCurrentValue = (System.DateTime.Now - prStartTime).Seconds; prTotal = 100; } prMessage = HoudiniHost.getStatusString( HAPI_StatusType.HAPI_STATUS_COOK_STATE, HAPI_StatusVerbosity.HAPI_STATUSVERBOSITY_WARNINGS); if (progress_cancelled) { EditorUtility.DisplayProgressBar(prTitle, "Aborting...", 0); } else { try { displayProgressBar(); } catch (HoudiniErrorProgressCancelled) { progress_cancelled = true; EditorUtility.DisplayProgressBar(prTitle, "Aborting...", 0); } } } // We want to propage the cancellation of the progress still, even if it is after a delay. if (progress_cancelled) { throw new HoudiniErrorProgressCancelled(); } if (state == HAPI_State.HAPI_STATE_READY_WITH_COOK_ERRORS) { state = HAPI_State.HAPI_STATE_READY; string messages = HoudiniHost.getCookErrorMessage(); HoudiniHost.logWarning(messages); } else if (state == HAPI_State.HAPI_STATE_READY_WITH_FATAL_ERRORS) { state = HAPI_State.HAPI_STATE_READY; HoudiniHost.throwCookError(); } #endif // UNITY_EDITOR }
public void resetFull() { HoudiniHost.destroyAsset(prAssetId); reset(); }
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 ) myUndoInfo = HoudiniHost.prHostUndoInfo; myScrollPosition = GUILayout.BeginScrollView(myScrollPosition); if (GUILayout.Button(HoudiniGUIUtility.myRevertAllSettingsLabel)) { if (EditorUtility.DisplayDialog( "Revert all settings?", "Are you sure you want to revert ALL Houdini plugin settings?", "Yes", "No")) { HoudiniHost.revertAllSettingsToDefaults(); HoudiniHost.repaint(); } } HoudiniGUI.separator(); GUIContent[] modes = new GUIContent[6]; modes[0] = new GUIContent("General"); modes[1] = new GUIContent("Materials"); modes[2] = new GUIContent("Cooking"); modes[3] = new GUIContent("Geometry"); modes[4] = new GUIContent("Curves"); modes[5] = new GUIContent("Advanced"); mySettingsTabSelection = GUILayout.Toolbar(mySettingsTabSelection, modes); switch (mySettingsTabSelection) { case 0: generateGeneralSettings(); break; case 1: generateMaterialSettings(); break; case 2: generateCookingSettings(); break; case 3: generateGeometrySettings(); break; case 4: generateCurveSettings(); break; case 5: generateAdvancedSettings(); break; default: Debug.LogError("Invalid Settings Tab."); break; } GUILayout.EndScrollView(); GUI.enabled = gui_enable; }
protected void displayProgressBar(int value) { #if UNITY_EDITOR System.DateTime current = System.DateTime.Now; System.TimeSpan delta = current - prStartTime; // This delay for displaying the progress bar is so the bar won't flicker for really quick updates // (less than a few seconds). Also, when we do show the progress bar the focus of the current // inspector control is lost. if (prUseDelay && delta.TotalSeconds < HoudiniConstants.HAPI_SEC_BEFORE_PROGRESS_BAR_SHOW) { EditorUtility.ClearProgressBar(); return; } // If there are no changes to the progress bar value or message don't re-display it again. if (value == myLastValue && prMessage == myLastMsg && delta == prCurrentDuration) { return; } prCurrentValue = value; string message = ""; if (delta.Hours > 0) { message = delta.Hours + "h " + delta.Minutes + "m " + delta.Seconds + "s - " + prMessage; } else if (delta.Minutes > 0) { message = delta.Minutes + "m " + delta.Seconds + "s - " + prMessage; } else if (delta.Seconds > 0) { message = delta.Seconds + "s - " + prMessage; } else { message = prMessage; } string title = prTitle; if (prAsset != null && prAsset.prAssetName != "ASSET_NAME") { title = "Building Houdini Asset: " + prAsset.prAssetName; } bool result = !EditorUtility.DisplayCancelableProgressBar( title, message, Mathf.InverseLerp(0, prTotal, prCurrentValue)); if (!result) { prCurrentDuration = new System.TimeSpan(0); myLastValue = -1; myLastMsg = ""; HoudiniHost.interrupt(); throw new HoudiniErrorProgressCancelled(); } else { myLastValue = value; myLastMsg = prMessage; prCurrentDuration = delta; } #endif // UNITY_EDITOR }
private static void generateGeometrySettings() { // Paint Brush Rate { // Everything is opposite here because the higher the number the slower // the paint rate and we want the user to think the higher the number // the FASTER the rate - so we have to invert. float value = HoudiniHost.prPaintBrushRate; bool changed = HoudiniGUI.floatField( "paint_brush_rate", "Paint Brush Rate", ref value, 0.0f, 1.0f, myUndoInfo, ref myUndoInfo.paintBrushRate); if (changed) { HoudiniHost.prPaintBrushRate = value; HoudiniHost.repaint(); } } // Painting Mode Hot Key { KeyCode value = HoudiniHost.prPaintingModeHotKey; string[] labels = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .Select(v => v.ToString()) .ToArray(); KeyCode[] values = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .ToArray(); bool changed = HoudiniGUI.dropdown( "painting_mode_hot_key", "Painting Key", ref value, labels, values, myUndoInfo, ref myUndoInfo.paintingModeHotKey); if (changed) { HoudiniHost.prPaintingModeHotKey = (KeyCode)value; HoudiniHost.repaint(); } } // Painting Mode Colour { Color value = HoudiniHost.prPaintingModeColour; bool changed = HoudiniGUI.colourField( "painting_mode_colour", "Painting Mode", ref value, myUndoInfo, ref myUndoInfo.paintingModeColour); if (changed) { HoudiniHost.prPaintingModeColour = value; HoudiniHost.repaint(); } } // Painting Node Switch Hot Key { KeyCode value = HoudiniHost.prPaintingNodeSwitchHotKey; string[] labels = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .Select(v => v.ToString()) .ToArray(); KeyCode[] values = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .ToArray(); bool changed = HoudiniGUI.dropdown( "painting_node_switch_hot_key", "Node Switch Key", ref value, labels, values, myUndoInfo, ref myUndoInfo.paintingNodeSwitchHotKey); if (changed) { HoudiniHost.prPaintingNodeSwitchHotKey = (KeyCode)value; HoudiniHost.repaint(); } } // Painting Attribute Switch Hot Key { KeyCode value = HoudiniHost.prPaintingAttributeSwitchHotKey; string[] labels = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .Select(v => v.ToString()) .ToArray(); KeyCode[] values = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .ToArray(); bool changed = HoudiniGUI.dropdown( "painting_attribute_switch_hot_key", "Attr. Switch Key", ref value, labels, values, myUndoInfo, ref myUndoInfo.paintingAttributeSwitchHotKey); if (changed) { HoudiniHost.prPaintingAttributeSwitchHotKey = (KeyCode)value; HoudiniHost.repaint(); } } // Painting Value Change Hot Key { KeyCode value = HoudiniHost.prPaintingValueChangeHotKey; string[] labels = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .Select(v => v.ToString()) .ToArray(); KeyCode[] values = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .ToArray(); bool changed = HoudiniGUI.dropdown( "painting_value_change_hot_key", "Value Change Key", ref value, labels, values, myUndoInfo, ref myUndoInfo.paintingValueChangeHotKey); if (changed) { HoudiniHost.prPaintingValueChangeHotKey = (KeyCode)value; HoudiniHost.repaint(); } } // Painting Falloff Change Hot Key { KeyCode value = HoudiniHost.prPaintingFalloffChangeHotKey; string[] labels = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .Select(v => v.ToString()) .ToArray(); KeyCode[] values = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .ToArray(); bool changed = HoudiniGUI.dropdown( "painting_falloff_change_hot_key", "Falloff Change Key", ref value, labels, values, myUndoInfo, ref myUndoInfo.paintingFalloffChangeHotKey); if (changed) { HoudiniHost.prPaintingFalloffChangeHotKey = (KeyCode)value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Adding Points Mode Hot Key { KeyCode value = HoudiniHost.prAddingPointsModeHotKey; string[] labels = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .Select(v => v.ToString()) .ToArray(); KeyCode[] values = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .ToArray(); bool changed = HoudiniGUI.dropdown( "adding_points_mode_hot_key", "Adding Points Key", ref value, labels, values, myUndoInfo, ref myUndoInfo.addingPointsModeHotKey); if (changed) { HoudiniHost.prAddingPointsModeHotKey = (KeyCode)value; HoudiniHost.repaint(); } } // Adding Points Mode Colour { Color value = HoudiniHost.prAddingPointsModeColour; bool changed = HoudiniGUI.colourField( "adding_ponits_mode_colour", "Adding Points Mode", ref value, myUndoInfo, ref myUndoInfo.addingPointsModeColour); if (changed) { HoudiniHost.prAddingPointsModeColour = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Editing Points Mode Hot Key { KeyCode value = HoudiniHost.prEditingPointsModeHotKey; string[] labels = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .Select(v => v.ToString()) .ToArray(); KeyCode[] values = System.Enum.GetValues(typeof(KeyCode)) .Cast <KeyCode>() .ToArray(); bool changed = HoudiniGUI.dropdown( "editing_points_mode_hot_key", "Editing Points Key", ref value, labels, values, myUndoInfo, ref myUndoInfo.editingPointsModeHotKey); if (changed) { HoudiniHost.prEditingPointsModeHotKey = (KeyCode)value; HoudiniHost.repaint(); } } // Editing Points Mode Colour { Color value = HoudiniHost.prEditingPointsModeColour; bool changed = HoudiniGUI.colourField( "editing_ponits_mode_colour", "Editing Points Mode", ref value, myUndoInfo, ref myUndoInfo.editingPointsModeColour); if (changed) { HoudiniHost.prEditingPointsModeColour = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Wireframe Colour { Color value = HoudiniHost.prWireframeColour; bool changed = HoudiniGUI.colourField( "wireframe_colour", "Wireframe", ref value, myUndoInfo, ref myUndoInfo.wireframeColour); if (changed) { HoudiniHost.prWireframeColour = value; HoudiniHost.repaint(); } } // Guide Wireframe Colour { Color value = HoudiniHost.prGuideWireframeColour; bool changed = HoudiniGUI.colourField( "guide_wireframe_colour", "Guide Wireframe", ref value, myUndoInfo, ref myUndoInfo.guideWireframeColour); if (changed) { HoudiniHost.prGuideWireframeColour = value; HoudiniHost.repaint(); } } // Unselectable Guide Wireframe Colour { Color value = HoudiniHost.prUnselectableGuideWireframeColour; bool changed = HoudiniGUI.colourField( "unselectable_guide_wireframe_colour", "Unselectable Guide", ref value, myUndoInfo, ref myUndoInfo.unselectableGuideWireframeColour); if (changed) { HoudiniHost.prUnselectableGuideWireframeColour = value; HoudiniHost.repaint(); } } // Unselected Guide Wireframe Colour { Color value = HoudiniHost.prUnselectedGuideWireframeColour; bool changed = HoudiniGUI.colourField( "unselected_guide_wireframe_colour", "Unselected Guide", ref value, myUndoInfo, ref myUndoInfo.unselectedGuideWireframeColour); if (changed) { HoudiniHost.prUnselectedGuideWireframeColour = value; HoudiniHost.repaint(); } } // Selected Guide Wireframe Colour { Color value = HoudiniHost.prSelectedGuideWireframeColour; bool changed = HoudiniGUI.colourField( "selected_guide_wireframe_colour", "Selected Guide", ref value, myUndoInfo, ref myUndoInfo.selectedGuideWireframeColour); if (changed) { HoudiniHost.prSelectedGuideWireframeColour = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Guide Point Size { float value = HoudiniHost.prGuidePointSize; bool changed = HoudiniGUI.floatField( "guide_point_size", "Guide Point Size", ref value, 4.0f, 40.0f, myUndoInfo, ref myUndoInfo.guidePointSize); if (changed) { HoudiniHost.prGuidePointSize = value; HoudiniHost.repaint(); } } // Min. Distance For Point Selection { float value = HoudiniHost.prMinDistanceForPointSelection; bool changed = HoudiniGUI.floatField( "min_distance_for_point_selection", "Min. Distance For Point Selection", ref value, 1.0f, 20.0f, myUndoInfo, ref myUndoInfo.minDistanceForPointSelection); if (changed) { HoudiniHost.prMinDistanceForPointSelection = value; HoudiniHost.repaint(); } } // Guide Min. Distance For Mid Point Insertion { float value = HoudiniHost.prGuideMinDistanceForMidPointInsertion; bool changed = HoudiniGUI.floatField( "guide_min_distance_for_mid_point_insertion", "Guide Min. Distance For Mid Point Insertion", ref value, 1.0f, 20.0f, myUndoInfo, ref myUndoInfo.guideMinDistanceForMidPointInsertion); if (changed) { HoudiniHost.prGuideMinDistanceForMidPointInsertion = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Create Groups from Bool Attribute { bool value = HoudiniHost.prCreateGroupsFromBoolAttributes; bool changed = HoudiniGUI.toggle( "create_groups_from_bool_attributes", "Create Groups from Bool Attributes", ref value, myUndoInfo, ref myUndoInfo.createGroupsFromBoolAttributes); if (changed) { HoudiniHost.prCreateGroupsFromBoolAttributes = value; HoudiniHost.repaint(); } } }
private static void generateCookingSettings() { // Enable Cooking { bool value = HoudiniHost.prEnableCooking; bool changed = HoudiniGUI.toggle( "enable_cooking", "Enable Cooking", ref value, myUndoInfo, ref myUndoInfo.enableCooking); if (changed) { HoudiniHost.prEnableCooking = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Cooking Triggers Downstream Cooks { bool value = HoudiniHost.prCookingTriggersDownCooks; bool changed = HoudiniGUI.toggle( "cooking_triggers_downstream_cooks", "Cooking Triggers Downstream Cooks", ref value, myUndoInfo, ref myUndoInfo.cookingTriggersDownCooks); if (changed) { HoudiniHost.prCookingTriggersDownCooks = value; HoudiniHost.repaint(); } } // Playmode Per-Frame Cooking { bool value = HoudiniHost.prPlaymodePerFrameCooking; bool changed = HoudiniGUI.toggle( "playmode_per_frame_cooking", "Playmode Per-Frame Cooking", ref value, myUndoInfo, ref myUndoInfo.playmodePerFrameCooking); if (changed) { HoudiniHost.prPlaymodePerFrameCooking = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Push Unity Transform To Houdini Engine { bool value = HoudiniHost.prPushUnityTransformToHoudini; bool changed = HoudiniGUI.toggle( "push_unity_transform_to_houdini", "Push Unity Transform to Houdini Engine", ref value, myUndoInfo, ref myUndoInfo.pushUnityTransformToHoudini); if (changed) { HoudiniHost.prPushUnityTransformToHoudini = value; HoudiniHost.repaint(); } } // Transform Change Triggers Cooks { bool value = HoudiniHost.prTransformChangeTriggersCooks; bool changed = HoudiniGUI.toggle( "transform_change_triggers_cooks", "Transform Change Triggers Cooks", ref value, myUndoInfo, ref myUndoInfo.transformChangeTriggersCooks); if (changed) { HoudiniHost.prTransformChangeTriggersCooks = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Import Templated Geos { bool value = HoudiniHost.prImportTemplatedGeos; bool changed = HoudiniGUI.toggle( "import_templated_geos", "Import Templated Geos", ref value, myUndoInfo, ref myUndoInfo.importTemplatedGeos); if (changed) { HoudiniHost.prImportTemplatedGeos = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Split Geos by Group { bool value = HoudiniHost.prSplitGeosByGroup; bool changed = HoudiniGUI.toggle( "split_geos_by_group", "Split Geos by Group", ref value, myUndoInfo, ref myUndoInfo.splitGeosByGroup); if (changed) { HoudiniHost.prSplitGeosByGroup = value; HoudiniHost.repaint(); EditorUtility.DisplayDialog( "Rebuild Required", "This change will take affect only after a full asset rebuild.", "Ok"); } } // Split Points by Vertex Attributes { bool value = HoudiniHost.prSplitPointsByVertexAttributes; bool changed = HoudiniGUI.toggle( "split_points_by_vertex_attributes", "Split Points by Vertex Attributes", ref value, myUndoInfo, ref myUndoInfo.splitGeosByGroup); if (changed) { HoudiniHost.prSplitPointsByVertexAttributes = value; HoudiniHost.repaint(); EditorUtility.DisplayDialog( "Rebuild Required", "This change will take affect only after a full asset rebuild.", "Ok"); } } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Private private static void generateGeneralSettings() { // Pin Size { float value = HoudiniHost.prPinSize; bool changed = HoudiniGUI.floatField( "pin_size", "Pin Size", ref value, myUndoInfo, ref myUndoInfo.pinSize); if (changed) { HoudiniHost.prPinSize = value; HoudiniHost.repaint(); } } // Pin Colour { Color value = HoudiniHost.prPinColour; bool changed = HoudiniGUI.colourField( "pin_colour", "Pin Color", ref value, myUndoInfo, ref myUndoInfo.pinColour); if (changed) { HoudiniHost.prPinColour = value; HoudiniHost.repaint(); } } // Auto pin { bool value = HoudiniHost.prAutoPinInstances; bool changed = HoudiniGUI.toggle( "auto_pin_instances", "Auto Pin Instances", ref value, myUndoInfo, ref myUndoInfo.autoPinInstances); if (changed) { HoudiniHost.prAutoPinInstances = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Enable Support Warnings { bool value = HoudiniHost.prEnableSupportWarnings; bool changed = HoudiniGUI.toggle( "enable_support_warnings", "Enable Support Warnings", ref value, myUndoInfo, ref myUndoInfo.enableSupportWarnings); if (changed) { HoudiniHost.prEnableSupportWarnings = value; } } HoudiniGUI.separator(); // Auto Select Asset Root Node { bool value = HoudiniHost.prAutoSelectAssetRootNode; bool changed = HoudiniGUI.toggle( "auto_select_asset_root_node", "Auto Select Asset Root Node", ref value, myUndoInfo, ref myUndoInfo.autoSelectAssetRootNode); if (changed) { HoudiniHost.prAutoSelectAssetRootNode = value; HoudiniHost.repaint(); } } HoudiniGUI.separator(); // Enable particles { bool value = HoudiniHost.prEnablePointsAsParticles; bool changed = HoudiniGUI.toggle( "enable_points_as_particles", "Create Points as Particles", ref value, myUndoInfo, ref myUndoInfo.enablePointsAsParticles); if (changed) { HoudiniHost.prEnablePointsAsParticles = value; } } }
public override void OnInspectorGUI() { if (myGeoAttributeManager == null) { return; } bool is_editable = true; // We can only build or do anything if we can link to our libraries. #if !( HAPI_ENABLE_RUNTIME ) is_editable = false; HoudiniGUI.help(HoudiniConstants.HAPI_UNSUPPORTED_PLATFORM_MSG, MessageType.Info); #else if (!is_editable) { HoudiniGUI.help("This mesh is not editable.", MessageType.Info); } #endif // !( HAPI_ENABLE_RUNTIME ) bool gui_enable = GUI.enabled; GUI.enabled = is_editable; myAssetInput.prShowHoudiniControls = HoudiniGUI.foldout("Houdini Controls", myAssetInput.prShowHoudiniControls, true); if (myAssetInput.prShowHoudiniControls) { if (GUILayout.Button("Rebuild")) { myAssetInput.buildAll(); } if (GUILayout.Button("Recook")) { myAssetInput.buildClientSide(); } } // Draw Help Pane myAssetInput.prShowHelp = HoudiniGUI.foldout("Asset Help", myAssetInput.prShowHelp, true); if (myAssetInput.prShowHelp) { drawHelpBox(myHelpText); } /////////////////////////////////////////////////////////////////////// // Draw Asset Settings // These don't affect the asset directly so they don't trigger rebuilds. myAssetInput.prShowAssetSettings = HoudiniGUI.foldout("Asset Settings", myAssetInput.prShowAssetSettings, true); if (myAssetInput.prShowAssetSettings) { // Enable Cooking Toggle createToggleForProperty( "enable_cooking", "Enable Cooking", "prEnableCooking", ref myUndoInfo.enableCooking, null, !HoudiniHost.isEnableCookingDefault()); HoudiniGUI.separator(); // Cooking Triggers Downstream Cooks Toggle createToggleForProperty( "cooking_triggers_downstream_cooks", "Cooking Triggers Downstream Cooks", "prCookingTriggersDownCooks", ref myUndoInfo.cookingTriggersDownCooks, null, !HoudiniHost.isCookingTriggersDownCooksDefault(), !myAssetInput.prEnableCooking, " (all cooking is disabled)"); HoudiniGUI.separator(); // Push Unity Transform To Houdini Engine Toggle createToggleForProperty( "push_unity_transform_to_houdini_engine", "Push Unity Transform To Houdini Engine", "prPushUnityTransformToHoudini", ref myUndoInfo.pushUnityTransformToHoudini, null, !HoudiniHost.isPushUnityTransformToHoudiniDefault()); // Transform Change Triggers Cooks Toggle createToggleForProperty( "transform_change_triggers_cooks", "Transform Change Triggers Cooks", "prTransformChangeTriggersCooks", ref myUndoInfo.transformChangeTriggersCooks, null, !HoudiniHost.isTransformChangeTriggersCooksDefault(), !myAssetInput.prEnableCooking, " (all cooking is disabled)"); } /////////////////////////////////////////////////////////////////////// // Draw Point Attributes myAssetInput.prShowAttributesTable = HoudiniGUI.foldout("Point Attributes", myAssetInput.prShowAttributesTable, true); if (myAssetInput.prShowAttributesTable) { // Draw Create Point Attributes Action Bar { string[] preset_labels = new string[] { "Create Point Attribute:", "Custom", "Color", "UV", "Normal", "Bool", "Int", "Float", "String" }; int[] preset_values = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; GUIStyle style = new GUIStyle(EditorStyles.popup); style.fixedHeight = 18; style.margin.bottom = 6; int preset_selected = EditorGUILayout.IntPopup( 0, preset_labels, preset_values, style); if (preset_selected == 1) { myGeoAttributeManager.createAttribute(); myAssetInput.prHasAttributeChanges = true; } else if (preset_selected > 1) { HoudiniGeoAttribute.Preset preset = (HoudiniGeoAttribute.Preset)(preset_selected - 2); myGeoAttributeManager.createAttribute(preset); myAssetInput.prHasAttributeChanges = true; } } // Draw recook notice. string help_msg = "There are uncommitted attribute changes. Press 'Recook' when ready."; if (myAssetInput.prHasError) { help_msg += "\nError: " + myAssetInput.prErrorMsg; } if (myAssetInput.prHasAttributeChanges) { HoudiniGUI.help(help_msg, MessageType.Info); } else { HoudiniGUI.help("Ready", MessageType.Info); } HoudiniGUI.separator(); string[] type_labels = new string[] { "bool", "int", "float", "string" }; int[] type_values = new int[] { 0, 1, 2, 3 }; string[] tuple_labels = new string[] { "1", "2", "3", "4", "5" }; int[] tuple_values = new int[] { 1, 2, 3, 4, 5 }; // Draw table header. { EditorGUILayout.BeginHorizontal(); GUIStyle label_style = new GUIStyle(EditorStyles.label); label_style.padding.right = -5; label_style.margin.left = -5; label_style.border.right = -10; EditorGUILayout.LabelField("Name", GUILayout.MinWidth(100)); EditorGUILayout.LabelField("Type", GUILayout.Width(50)); EditorGUILayout.LabelField("Tuple", GUILayout.Width(50)); EditorGUILayout.LabelField("|", GUILayout.Width(8)); EditorGUILayout.LabelField("Min", GUILayout.Width(50)); EditorGUILayout.LabelField("Max", GUILayout.Width(50)); EditorGUILayout.LabelField("", GUILayout.Width(27)); EditorGUILayout.EndHorizontal(); } for (int i = 0; i < myGeoAttributeManager.prAttributes.Count; ++i) { HoudiniGeoAttribute attrib = myGeoAttributeManager.prAttributes[i]; EditorGUILayout.BeginHorizontal(); // Attribute Name string new_name = EditorGUILayout.TextField(attrib.prName, GUILayout.MinWidth(100)); if (new_name != attrib.prName) { attrib.prName = new_name; myAssetInput.prHasAttributeChanges = true; } // Attribute Type HoudiniGeoAttribute.Type new_attrib_type = (HoudiniGeoAttribute.Type)EditorGUILayout.IntPopup( (int)attrib.prType, type_labels, type_values, GUILayout.Width(50)); if (new_attrib_type != attrib.prType) { attrib.prType = new_attrib_type; myAssetInput.prHasAttributeChanges = true; } // Attribute Tuple Size int new_tuple_size = EditorGUILayout.IntPopup( attrib.prTupleSize, tuple_labels, tuple_values, GUILayout.Width(50)); if (new_tuple_size != attrib.prTupleSize) { attrib.prTupleSize = new_tuple_size; myAssetInput.prHasAttributeChanges = true; } EditorGUILayout.LabelField("|", GUILayout.Width(8)); // Range if (attrib.prType == HoudiniGeoAttribute.Type.STRING) { EditorGUILayout.LabelField("N/A", GUILayout.MinWidth(20)); } else { if (attrib.prType == HoudiniGeoAttribute.Type.BOOL || attrib.prType == HoudiniGeoAttribute.Type.INT) { attrib.prIntMin = EditorGUILayout.IntField("", attrib.prIntMin, GUILayout.Width(50)); } else if (attrib.prType == HoudiniGeoAttribute.Type.FLOAT) { attrib.prFloatMin = EditorGUILayout.FloatField("", attrib.prFloatMin, GUILayout.Width(50)); } if (attrib.prType == HoudiniGeoAttribute.Type.BOOL || attrib.prType == HoudiniGeoAttribute.Type.INT) { attrib.prIntMax = EditorGUILayout.IntField("", attrib.prIntMax, GUILayout.Width(50)); } else if (attrib.prType == HoudiniGeoAttribute.Type.FLOAT) { attrib.prFloatMax = EditorGUILayout.FloatField("", attrib.prFloatMax, GUILayout.Width(50)); } } EditorGUILayout.LabelField("|", GUILayout.Width(8)); GUIStyle label_style = new GUIStyle(EditorStyles.label); label_style.fontStyle = FontStyle.Bold; if (GUILayout.Button("X", label_style, GUILayout.Width(15), GUILayout.Height(15))) { myGeoAttributeManager.deleteAttribute(attrib.prName); myAssetInput.prHasAttributeChanges = true; } EditorGUILayout.EndHorizontal(); } { EditorGUILayout.BeginHorizontal(); GUIStyle label_style = new GUIStyle(EditorStyles.label); label_style.fontStyle = FontStyle.Normal; label_style.alignment = TextAnchor.MiddleRight; label_style.padding.left = 0; label_style.margin.left = 0; label_style.padding.right = 0; label_style.margin.right = 0; EditorGUILayout.LabelField("Delete Attribute", label_style, GUILayout.MinWidth(40)); label_style.fontStyle = FontStyle.Bold; label_style.padding.left = 0; label_style.margin.left = 6; label_style.padding.right = 5; label_style.margin.right = 5; EditorGUILayout.LabelField("↲", label_style, GUILayout.Width(10)); EditorGUILayout.EndHorizontal(); } } // Show Attributes Table GUI.enabled = gui_enable; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Protected Methods protected override int buildCreateAsset(HoudiniProgressBar progress_bar) { //return HoudiniHost.createInputAsset( transform.name ); return(HoudiniHost.instantiateAsset("SOP/merge", true)); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Protected Methods protected override int buildCreateAsset(HoudiniProgressBar progress_bar) { return(HoudiniHost.createInputAsset(transform.name)); }
public void refresh(bool reload_asset, bool has_geo_changed, bool has_material_changed) { if (prGeoControl == null) { Debug.LogError("Why is my geo control null on a refresh?"); return; } GameObject part_node = gameObject; // Get Part info. HAPI_PartInfo part_info = new HAPI_PartInfo(); HoudiniHost.getPartInfo(prAssetId, prObjectId, prGeoId, prPartId, out part_info); bool is_empty = part_info.vertexCount <= 0 && part_info.pointCount <= 0; bool is_mesh = (part_info.vertexCount > 0); // For Debugging. #if false Debug.Log("ATTRIBS"); HoudiniAssetUtility.printAllAttributeNames(prAssetId, prObjectId, prGeoId, prPartId); Debug.Log("GROUPS"); HoudiniAssetUtility.printAllGroups(prAssetId, prObjectId, prGeoId, prPartId); Debug.Log("DONE"); Debug.Log(""); #endif // TODO: Make this info a permanent UI display. //if ( prEnableLogging && ( reload_asset || has_geo_changed || has_material_changed ) ) // Debug.Log( "Obj #" + part_control.prObjectId + " (" + part_control.prObjectName + "): " // + "verts: " + part_info.vertexCount + " faces: " + part_info.faceCount ); if (reload_asset || has_geo_changed) { // Initialize our part control. init(-1, part_info.id, part_info.name); // Overwrite name. part_node.name = part_info.name; if (is_empty) { // Add required components. MeshFilter mesh_filter = getOrCreateComponent <MeshFilter>(); // Get or create mesh. Mesh part_mesh = mesh_filter.sharedMesh; if (part_mesh == null) { mesh_filter.mesh = new Mesh(); part_mesh = mesh_filter.sharedMesh; } part_mesh.Clear(); } else if (is_mesh) // Valid mesh. { // Add required components. MeshFilter mesh_filter = getOrCreateComponent <MeshFilter>(); // Get or create mesh. Mesh part_mesh = mesh_filter.sharedMesh; if (part_mesh == null) { mesh_filter.mesh = new Mesh(); part_mesh = mesh_filter.sharedMesh; } part_mesh.Clear(); // Get mesh. try { HoudiniAssetUtility.getMesh( this, part_mesh, prAsset.prGenerateTangents && HoudiniHost.prGenerateTangents); } catch (HoudiniErrorIgnorable) {} catch (HoudiniError error) { Debug.LogWarning(error.ToString()); return; } // Add collider if group name matches. (Should be added after the mesh is set so that it // picks up the mesh automagically) if (part_info.name.Contains(HoudiniHost.prRenderedCollisionGroupName)) { MeshCollider mesh_collider = getOrCreateComponent <MeshCollider>(); getOrCreateComponent <MeshRenderer>(); mesh_collider.enabled = false; mesh_collider.enabled = true; } else if (part_info.name.Contains(HoudiniHost.prCollisionGroupName)) { MeshCollider mesh_collider = getOrCreateComponent <MeshCollider>(); mesh_collider.enabled = false; mesh_collider.enabled = true; } else { getOrCreateComponent <MeshRenderer>(); } #if !HAPI_PAINT_SUPPORT if (myGeoControl.prGeoType == HAPI_GeoType.HAPI_GEOTYPE_INTERMEDIATE) { MeshRenderer mesh_renderer = getOrCreateComponent <MeshRenderer>(); MeshCollider mesh_collider = getOrCreateComponent <MeshCollider>(); if (myGeoControl.prGeoAttributeManager) { myGeoControl.prGeoAttributeManager.reInit( part_mesh, mesh_renderer, mesh_collider, transform); } mesh_collider.enabled = false; mesh_collider.enabled = true; } #endif // !HAPI_PAINT_SUPPORT // Add Mesh-to-Prefab component. HoudiniMeshToPrefab mesh_saver = getOrCreateComponent <HoudiniMeshToPrefab>(); mesh_saver.prGameObject = part_node; mesh_saver.prMeshName = prAsset.prAssetName + "_" + part_node.name; } else if (HoudiniHost.prEnablePointsAsParticles && part_info.vertexCount <= 0 && part_info.pointCount > 0) // Particles? { // Get position attributes. HAPI_AttributeInfo pos_attr_info = new HAPI_AttributeInfo(HoudiniConstants.HAPI_ATTRIB_POSITION); float[] pos_attr = new float[0]; HoudiniAssetUtility.getAttribute( prAssetId, prObjectId, prGeoId, prPartId, HoudiniConstants.HAPI_ATTRIB_POSITION, ref pos_attr_info, ref pos_attr, HoudiniHost.getAttributeFloatData); if (!pos_attr_info.exists) { throw new HoudiniError("No position attribute found."); } else if (pos_attr_info.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_POINT) { throw new HoudiniErrorIgnorable("I only understand position as point attributes!"); } // Get colour attributes. HAPI_AttributeInfo colour_attr_info = new HAPI_AttributeInfo(HoudiniConstants.HAPI_ATTRIB_COLOR); float[] colour_attr = new float[0]; HoudiniAssetUtility.getAttribute( prAssetId, prObjectId, prGeoId, prPartId, HoudiniConstants.HAPI_ATTRIB_COLOR, ref colour_attr_info, ref colour_attr, HoudiniHost.getAttributeFloatData); ParticleEmitter particle_emitter = part_node.GetComponent <ParticleEmitter>(); if (particle_emitter == null) { #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 particle_emitter = part_node.AddComponent("EllipsoidParticleEmitter") as ParticleEmitter; #else particle_emitter = part_node.AddComponent <EllipsoidParticleEmitter>() as ParticleEmitter; #endif // UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 } particle_emitter.ClearParticles(); particle_emitter.emit = false; particle_emitter.useWorldSpace = true; particle_emitter.maxSize = 0.06f; particle_emitter.minSize = 0.02f; ParticleRenderer renderer = getOrCreateComponent <ParticleRenderer>(); Material mat = new Material(Shader.Find("Particles/Additive (Soft)")); int width = 20; int length = 20; Texture2D tex = new Texture2D(width, length, TextureFormat.RGBA32, false); for (int x = 0; x < width; ++x) { for (int y = 0; y < length; ++y) { float dist = (x - 10) * (x - 10) + (y - 10) * (y - 10); dist = Mathf.Sqrt(dist); float alpha_f = 1.0f - dist / 10.0f; Color col = new Color(0.8f, 0.8f, 0.8f, alpha_f); tex.SetPixel(x, y, col); } } tex.Apply(); mat.mainTexture = tex; mat.color = new Color(1.0f, 1.0f, 0.5f); renderer.material = mat; particle_emitter.Emit(part_info.pointCount); Particle[] particles = particle_emitter.particles; if (particle_emitter.particles.Length < part_info.pointCount) { Debug.LogWarning("Geo has too many particles. Expected less than " + particle_emitter.particles.Length + " but found " + part_info.pointCount + ". " + " Only using the first " + particle_emitter.particles.Length + "."); } for (int i = 0; i < particle_emitter.particles.Length; ++i) { particles[i].position = new Vector3(pos_attr[i * 3 + 0], pos_attr[i * 3 + 1], pos_attr[i * 3 + 2]); if (colour_attr_info.exists && colour_attr_info.owner == HAPI_AttributeOwner.HAPI_ATTROWNER_POINT) { float alpha = colour_attr_info.tupleSize == 4 ? colour_attr[i * colour_attr_info.tupleSize + 3] : 1.0f; particles[i].color = new Color(colour_attr[i * colour_attr_info.tupleSize + 0], colour_attr[i * colour_attr_info.tupleSize + 1], colour_attr[i * colour_attr_info.tupleSize + 2], alpha); } } particle_emitter.particles = particles; } if (part_info.hasVolume) { // Clear previous volume tiles. destroyChildren(part_node.transform); // If we have a volume, retrieve the volume info HAPI_VolumeInfo volume = new HAPI_VolumeInfo(); HoudiniHost.getVolumeInfo(prAssetId, prObjectId, prGeoId, prPartId, ref volume); // The volume.transform.scale is the voxel size. Both the particle // delta and the point size are affected by the voxel size. HoudiniAssetUtility.applyTransform(volume.transform, part_node.transform); float particle_delta = HoudiniConstants.HAPI_VOLUME_SURFACE_DELTA_MULT * Mathf.Max(Mathf.Max( volume.transform.scale[0], volume.transform.scale[1]), volume.transform.scale[2]); float point_size = HoudiniConstants.HAPI_VOLUME_SURFACE_PT_SIZE_MULT * particle_delta; List <Vector3> acc_vertices = new List <Vector3>(); List <Vector3> acc_normals = new List <Vector3>(); float[] values = new float[volume.tileSize * volume.tileSize * volume.tileSize]; int tile_index = 0; int current_container_particle_index = 0; // Iterate through the voxels and print out the data, for now. HAPI_VolumeTileInfo tile = new HAPI_VolumeTileInfo(); HoudiniHost.getFirstVolumeTile(prAssetId, prObjectId, prGeoId, prPartId, ref tile); while (tile.isValid) { for (int i = 0; i < values.Length; ++i) { values[i] = 0; } HoudiniHost.getVolumeTileFloatData( prAssetId, prObjectId, prGeoId, prPartId, ref tile, values); Vector3 tileMin = new Vector3(tile.minX, tile.minY, tile.minZ); int part_index = 0; for (int z = 0; z < volume.tileSize; ++z) { for (int y = 0; y < volume.tileSize; ++y) { for (int x = 0; x < volume.tileSize; ++x) { int index = z * volume.tileSize * volume.tileSize + y * volume.tileSize + x; if (values[index] > -particle_delta && values[index] < particle_delta) { // Make sure we have enough room in our arrays. if (current_container_particle_index > HoudiniConstants.HAPI_VOLUME_SURFACE_MAX_PT_PER_C) { createVolumeTilesObject( point_size, part_node.transform, acc_vertices, acc_normals); current_container_particle_index = 0; acc_vertices.Clear(); acc_normals.Clear(); } // Get particle position. Vector3 pos = new Vector3((float)x, (float)y, (float)z); pos = HoudiniConstants.HAPI_VOLUME_POSITION_MULT * (pos + tileMin); pos.x = -pos.x; acc_vertices.Add(part_node.transform.TransformPoint(pos)); // Get particle normal. int amount = 1; int sample_count = 0; Vector3 average_normal = Vector3.zero; for (int xi = -1; xi <= 1; ++xi) { for (int yi = -1; yi <= 1; ++yi) { for (int zi = -1; zi <= 1; ++zi) { if (xi == 0 && yi == 0 && zi == 0) { continue; } float result = getVolumeData( values, volume, particle_delta, x + xi * amount, y + yi * amount, z + zi * amount); Vector3 normal = Vector3.zero; if (result < -0.5f) { normal = new Vector3(-xi, -yi, -zi); } else if (result > 0.5f) { normal = new Vector3(xi, yi, zi); } else { continue; } average_normal += normal; sample_count++; } } } average_normal /= sample_count; average_normal.Normalize(); acc_normals.Add(average_normal); part_index++; current_container_particle_index++; } } } } HoudiniHost.getNextVolumeTile(prAssetId, prObjectId, prGeoId, prPartId, ref tile); tile_index++; } // tile iteration // If we have left-over particles in our arrays we need another container. createVolumeTilesObject(point_size, part_node.transform, acc_vertices, acc_normals); } // if has volume else // Restore part node if previously used to store volume. { // Clear previous volume tiles. destroyChildren(part_node.transform); part_node.transform.localScale = Vector3.one; part_node.transform.localPosition = Vector3.zero; part_node.transform.localRotation = Quaternion.identity; } } // Refresh enabled flags. if (gameObject.GetComponent <MeshCollider>()) { gameObject.GetComponent <MeshCollider>().enabled = prObjectVisible && (prAsset.prIsGeoVisible || prGeoType == HAPI_GeoType.HAPI_GEOTYPE_INTERMEDIATE); } if (gameObject.GetComponent <MeshRenderer>()) { gameObject.GetComponent <MeshRenderer>().enabled = prObjectVisible && (prAsset.prIsGeoVisible || prGeoType == HAPI_GeoType.HAPI_GEOTYPE_INTERMEDIATE); } // Assign materials. HoudiniAssetUtility.assignMaterial(this, prAsset, (reload_asset || has_material_changed)); // Assign unity tag. assignUnityTag(); }
public bool areValuesEqualToHoudini() { if (prControl == null) { return(false); } if (prControl.prAsset == null) { return(false); } if (prControl.prAssetId < 0) { return(false); } // Get the node info again HAPI_NodeInfo node_info = HoudiniHost.getNodeInfo(prControl.prNodeId); if (prParmCount != node_info.parmCount) { return(false); } if (prParmIntValueCount != node_info.parmIntValueCount) { return(false); } if (prParmFloatValueCount != node_info.parmFloatValueCount) { return(false); } if (prParmStringValueCount != node_info.parmStringValueCount) { return(false); } if (prParmChoiceCount != node_info.parmChoiceCount) { return(false); } // Get parameter int values. int[] houdini_int_values = new int[prParmIntValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmIntValues, houdini_int_values, prParmIntValueCount); if (prParmIntValues.Length != houdini_int_values.Length) { return(false); } for (int i = 0; i < prParmIntValueCount; ++i) { if (!prParmIntValues[i].Equals(houdini_int_values[i])) { return(false); } } // Get parameter float values. float[] houdini_float_values = new float[prParmFloatValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmFloatValues, houdini_float_values, prParmFloatValueCount); if (prParmFloatValues.Length != houdini_float_values.Length) { return(false); } for (int i = 0; i < prParmFloatValueCount; ++i) { if (!prParmFloatValues[i].Equals(houdini_float_values[i])) { return(false); } } // Get parameter string (handle) values. int[] houdini_string_values = new int[prParmStringValueCount]; HoudiniAssetUtility.getArray1Id( prControl.prNodeId, HoudiniHost.getParmStringValues, houdini_string_values, prParmStringValueCount); if (prParmStringHandles.Length != houdini_string_values.Length) { return(false); } for (int i = 0; i < prParmStringValueCount; ++i) { if (!HoudiniHost.getString(prParmStringHandles[i]).Equals( HoudiniHost.getString(houdini_string_values[i]))) { return(false); } } return(true); }
public bool sync( int asset_id, int object_id, int geo_id, int part_id, Mesh mesh, HAPI_AttributeInfo attribute_info) { int tuple_size = attribute_info.tupleSize; prStorageType = attribute_info.storage; prTupleSize = tuple_size; myVertexCount = mesh.vertexCount; Type type = prType; if (myInitializedVertexCount != mesh.vertexCount) { int new_size = mesh.vertexCount * tuple_size; if (type == Type.BOOL || type == Type.INT) { System.Array.Resize <int>(ref myIntData, new_size); } else if (type == Type.FLOAT) { System.Array.Resize <float>(ref myFloatData, new_size); } else if (type == Type.STRING) { System.Array.Resize <string>(ref myStringData, new_size); } } if (myInitializedVertexCount < mesh.vertexCount) { // Get Vertex list. HAPI_PartInfo part_info = new HAPI_PartInfo(); HoudiniHost.getPartInfo( asset_id, object_id, geo_id, part_id, out part_info); int[] vertex_list = new int[part_info.vertexCount]; HoudiniAssetUtility.getArray4Id( asset_id, object_id, geo_id, part_id, HoudiniHost.getVertexList, vertex_list, part_info.vertexCount); if (type == Type.BOOL || type == Type.INT) { int[] data = new int[0]; HoudiniAssetUtility.getAttribute( asset_id, object_id, geo_id, part_id, myName, ref attribute_info, ref data, HoudiniHost.getAttributeIntData); for (int i = myInitializedVertexCount; i < part_info.vertexCount; ++i) { for (int tuple = 0; tuple < tuple_size; ++tuple) { prIntData[i * tuple_size + tuple] = data[vertex_list[i] * tuple_size + tuple]; } } } else if (type == Type.FLOAT) { float[] data = new float[0]; HoudiniAssetUtility.getAttribute( asset_id, object_id, geo_id, part_id, myName, ref attribute_info, ref data, HoudiniHost.getAttributeFloatData); for (int i = myInitializedVertexCount; i < part_info.vertexCount; ++i) { for (int tuple = 0; tuple < tuple_size; ++tuple) { prFloatData[i * tuple_size + tuple] = data[vertex_list[i] * tuple_size + tuple]; } } } else if (type == Type.STRING) { int[] data = new int[0]; HoudiniAssetUtility.getAttribute( asset_id, object_id, geo_id, part_id, myName, ref attribute_info, ref data, HoudiniHost.getAttributeStringData); for (int i = myInitializedVertexCount; i < part_info.vertexCount; ++i) { for (int tuple = 0; tuple < tuple_size; ++tuple) { prStringData[i * tuple_size + tuple] = HoudiniHost.getString(data[vertex_list[i] * tuple_size + tuple]); } } } } // If some of the data was already bool needs_recook = myInitializedVertexCount > 0; myInitializedVertexCount = mesh.vertexCount; return(needs_recook); }
public bool setNodeParameterIntoHost(int id) { HAPI_ParmInfo parm = findParm(id); var parm_input = myParmInputs[id]; if (!parm_input.inputObject) { return(false); } // Create new input node. GameObject input_object = parm_input.inputObject; HoudiniControl houdini_control = input_object.GetComponent <HoudiniControl>(); MeshFilter mesh_filter = input_object.GetComponent <MeshFilter>(); if (houdini_control && houdini_control.prAsset.gameObject.GetComponentInChildren <HoudiniGeoControl>()) { if (!houdini_control.prAsset.isAssetValid()) { houdini_control.prAsset.buildAll(); } HoudiniGeoControl geo_control = houdini_control.prAsset.gameObject.GetComponentInChildren <HoudiniGeoControl>(); parm_input.inputNodeId = geo_control.prNodeId; // Add ourselves to our input asset's downstream nodes so when it cooks we cook. houdini_control.prAsset.addDownstreamAsset(myControl.prAsset); } else if (houdini_control && input_object.GetComponent <HoudiniAssetCurve>()) { if (!houdini_control.prAsset.isAssetValid()) { houdini_control.prAsset.buildAll(); } parm_input.inputNodeId = houdini_control.prNodeId; // Add ourselves to our input asset's downstream nodes so when it cooks we cook. houdini_control.prAsset.addDownstreamAsset(myControl.prAsset); } else if (mesh_filter && mesh_filter.sharedMesh) { // We need to remove spaces in the input name string inputName = input_object.name.Replace(' ', '_'); parm_input.inputNodeId = HoudiniHost.createInputNode(inputName); Mesh mesh = mesh_filter.sharedMesh; HoudiniAssetUtility.setMesh( parm_input.inputNodeId, 0, parm_input.inputNodeId, ref mesh, null, null); // Set the asset transform from the source GameObject transform. HAPI_TransformEuler trans = HoudiniAssetUtility.getHapiTransform(input_object.transform.localToWorldMatrix); HAPI_NodeInfo input_node_info = HoudiniHost.getNodeInfo(parm_input.inputNodeId); HoudiniHost.setObjectTransform(input_node_info.parentId, ref trans); } else { return(false); } HAPI_NodeInfo node_info = HoudiniHost.getNodeInfo(parm_input.inputNodeId); parm_input.inputNodeUniqueId = node_info.uniqueHoudiniNodeId; // Assign node parm input. HoudiniHost.setParmNodeValue(prControl.prNodeId, parm.name, parm_input.inputNodeId); myParmInputs[id] = parm_input; return(true); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Protected Methods protected override int buildCreateAsset(HoudiniProgressBar progress_bar) { return(HoudiniHost.createCurve()); }
private void generateCookingSettings() { // Enable Cooking Toggle createToggleForProperty( "enable_cooking", "Enable Cooking", "prEnableCooking", ref myUndoInfo.enableCooking, null, !HoudiniHost.isEnableCookingDefault()); HoudiniGUI.separator(); // Cooking Triggers Downstream Cooks Toggle createToggleForProperty( "cooking_triggers_downstream_cooks", "Cooking Triggers Downstream Cooks", "prCookingTriggersDownCooks", ref myUndoInfo.cookingTriggersDownCooks, null, !HoudiniHost.isCookingTriggersDownCooksDefault(), !myAsset.prEnableCooking, " (all cooking is disabled)"); // Playmode Per-Frame Cooking Toggle createToggleForProperty( "playmode_per_frame_cooking", "Playmode Per-Frame Cooking", "prPlaymodePerFrameCooking", ref myUndoInfo.playmodePerFrameCooking, null, !HoudiniHost.isPlaymodePerFrameCookingDefault(), !myAsset.prEnableCooking, " (all cooking is disabled)"); HoudiniGUI.separator(); // Push Unity Transform To Houdini Engine Toggle createToggleForProperty( "push_unity_transform_to_houdini_engine", "Push Unity Transform To Houdini Engine", "prPushUnityTransformToHoudini", ref myUndoInfo.pushUnityTransformToHoudini, null, !HoudiniHost.isPushUnityTransformToHoudiniDefault()); // Transform Change Triggers Cooks Toggle createToggleForProperty( "transform_change_triggers_cooks", "Transform Change Triggers Cooks", "prTransformChangeTriggersCooks", ref myUndoInfo.transformChangeTriggersCooks, null, !HoudiniHost.isTransformChangeTriggersCooksDefault(), !myAsset.prEnableCooking, " (all cooking is disabled)"); HoudiniGUI.separator(); // Import Templated Geos Toggle createToggleForProperty( "import_templated_geos", "Import Templated Geos", "prImportTemplatedGeos", ref myUndoInfo.importTemplatedGeos, null, !HoudiniHost.isImportTemplatedGeosDefault(), !myAsset.prEnableCooking, " (all cooking is disabled)"); HoudiniGUI.separator(); // Split Geos by Group Toggle { createToggleForProperty( "split_geos_by_group_override", "Override Split Geos by Group", "prSplitGeosByGroupOverride", ref myUndoInfo.splitGeosByGroupOverride, null); createToggleForProperty( "split_geos_by_group", "Split Geos by Group", "prSplitGeosByGroup", ref myUndoInfo.splitGeosByGroup, () => EditorUtility.DisplayDialog( "Rebuild Required", "This change will take affect only after a full asset rebuild.", "Ok"), false, !myAsset.prSplitGeosByGroupOverride, " (check the override checkbox to enable)"); } }
public bool syncAttributes(int asset_id, int object_id, int geo_id, int part_id, Mesh mesh) { bool needs_recook = false; // Fetch all point attributes. string[] point_attribute_names = HoudiniHost.getAttributeNames( geo_id, part_id, HAPI_AttributeOwner.HAPI_ATTROWNER_POINT); foreach (string point_attribute_name in point_attribute_names) { if (point_attribute_name == "P") { continue; } HAPI_AttributeInfo point_attribute_info = HoudiniHost.getAttributeInfo( geo_id, part_id, point_attribute_name, HAPI_AttributeOwner.HAPI_ATTROWNER_POINT); HoudiniGeoAttribute attribute = null; // If we already have an attribute with the same name, sync it with // the attribute in Houdini - trying to salvage any data even if the // attribute storage type, tuple size, or mesh point count has changed. if (hasAttribute(point_attribute_name)) { attribute = getAttribute(point_attribute_name); } else // Attribute not found. { HoudiniGeoAttribute.Type geo_attribute_type = HoudiniGeoAttribute.Type.UNDEFINED; switch (point_attribute_info.storage) { case HAPI_StorageType.HAPI_STORAGETYPE_INT: geo_attribute_type = HoudiniGeoAttribute.Type.INT; break; case HAPI_StorageType.HAPI_STORAGETYPE_FLOAT: geo_attribute_type = HoudiniGeoAttribute.Type.FLOAT; break; case HAPI_StorageType.HAPI_STORAGETYPE_STRING: geo_attribute_type = HoudiniGeoAttribute.Type.STRING; break; } attribute = createAttribute(point_attribute_name); attribute.init( mesh, point_attribute_name, geo_attribute_type, point_attribute_info.tupleSize); attribute.prOriginalAttributeOwner = HAPI_AttributeOwner.HAPI_ATTROWNER_POINT; } // Sync the values of the Unity attribute with the Houdini attribute. needs_recook |= attribute.sync(geo_id, part_id, mesh, point_attribute_info); // If the sync updated the values from the asset we need to refresh our mesh. if (needs_recook) { refreshMesh(); } } return(needs_recook); }
public bool refresh( bool reload_asset ) { bool needs_recook = false; if ( prObjectControl == null ) { Debug.LogError( "Why is my object control null on a refresh?" ); return needs_recook; } GameObject geo_node = gameObject; // Get Geo info. HAPI_GeoInfo geo_info = new HAPI_GeoInfo(); try { // If templated geos are off this will error out for templated // geos because they woudn't have cooked. But we still need to // get the geo info to see that this is a templated geo and skip it. HoudiniHost.getGeoInfo( prAssetId, prObjectId, prGeoId, out geo_info ); } catch ( HoudiniErrorInvalidArgument ) {} if ( geo_info.type == HAPI_GeoType.HAPI_GEOTYPE_INPUT ) return needs_recook; if ( geo_info.isTemplated && !prAsset.prImportTemplatedGeos && !geo_info.isEditable ) return needs_recook; if ( !reload_asset && !geo_info.hasGeoChanged && !geo_info.hasMaterialChanged ) return needs_recook; if ( reload_asset || geo_info.type == HAPI_GeoType.HAPI_GEOTYPE_CURVE ) { for ( int i = 0; i < myParts.Count; ++i ) HoudiniAssetUtility.destroyGameObject( myParts[ i ] ); myParts.Clear(); } if ( reload_asset || geo_info.hasGeoChanged ) { // Initialize our geo control. init( geo_info.nodeId, prGeoId, geo_info.name, (HAPI_GeoType) geo_info.type, geo_info.isEditable, geo_info.isDisplayGeo ); // Set node name. geo_node.name = prGeoName; } if ( !geo_info.isDisplayGeo && ( geo_info.type != HAPI_GeoType.HAPI_GEOTYPE_CURVE && !myObjectControl.prAsset.prImportTemplatedGeos && geo_info.isTemplated ) ) { return needs_recook; } if ( geo_info.type == HAPI_GeoType.HAPI_GEOTYPE_CURVE ) { createAndInitCurve( prNodeId, prObjectId, prGeoId, prIsEditable ); needs_recook = true; } else { if ( reload_asset || geo_info.hasGeoChanged ) { // Add new geos as needed. while ( myParts.Count < geo_info.partCount ) myParts.Add( createPart( myParts.Count ) ); // Remove stale geos. while ( myParts.Count > geo_info.partCount ) { HoudiniAssetUtility.destroyGameObject( myParts[ geo_info.partCount ] ); myParts.RemoveAt( geo_info.partCount ); } } // Refresh all geos. for ( int i = 0; i < myParts.Count; ++i ) myParts[ i ].GetComponent< HoudiniPartControl >().refresh( reload_asset, geo_info.hasGeoChanged, geo_info.hasMaterialChanged ); // Handle Edit/Paint Nodes if ( geo_info.type == HAPI_GeoType.HAPI_GEOTYPE_INTERMEDIATE ) { // Currently, we only support painting on the first part. const int part_id = 0; GameObject part_gameobject = myParts[ part_id ]; HoudiniPartControl part_control = part_gameobject.GetComponent< HoudiniPartControl >(); MeshFilter mesh_filter = part_control.getOrCreateComponent< MeshFilter >(); MeshRenderer mesh_renderer = part_control.getOrCreateComponent< MeshRenderer >(); MeshCollider mesh_collider = part_control.getOrCreateComponent< MeshCollider >(); Mesh mesh = mesh_filter.sharedMesh; // We are limited to using the first part, always. if ( myGeoAttributeManager == null && myParts.Count > 0 ) { if ( prAsset.prGeoAttributeManagerMap.contains( getRelativePath() ) ) { myGeoAttributeManager = prAsset.prGeoAttributeManagerMap.get( getRelativePath() ); myGeoAttributeManager.name = getAbsolutePath() + "/GeoAttributeManager"; myGeoAttributeManager.reInit( mesh, mesh_renderer, mesh_collider, part_gameobject.transform ); } else { myGeoAttributeManager = ScriptableObject.CreateInstance< HoudiniGeoAttributeManager >(); myGeoAttributeManager.name = getAbsolutePath() + "/GeoAttributeManager"; myGeoAttributeManager.init( mesh, mesh_renderer, mesh_collider, part_gameobject.transform ); prAsset.prGeoAttributeManagerMap.add( getRelativePath(), myGeoAttributeManager ); } // Sync the attributes and see if we need a recook. if ( myGeoAttributeManager.syncAttributes( prAssetId, prObjectId, prGeoId, part_id, mesh ) ) { HoudiniAssetUtility.setMesh( prAssetId, prObjectId, prGeoId, ref mesh, part_control, myGeoAttributeManager ); needs_recook = true; } } else { // Just sync the attributes but don't recook. Setting needs_recook to true here would // cause infinite cooking. myGeoAttributeManager.syncAttributes( prAssetId, prObjectId, prGeoId, part_id, mesh ); } } // Handle script attaching. if ( reload_asset && geo_info.partCount > 0 ) { HAPI_AttributeInfo script_attr_info = new HAPI_AttributeInfo( "Unity_Script" ); int[] script_attr = new int[ 0 ]; HoudiniAssetUtility.getAttribute( prAssetId, prObjectId, prGeoId, 0, "Unity_Script", ref script_attr_info, ref script_attr, HoudiniHost.getAttributeStringData ); if ( script_attr_info.exists && script_attr_info.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_DETAIL ) throw new HoudiniErrorIgnorable( "I only understand Unity_Script as detail attributes!" ); if ( script_attr_info.exists && script_attr.Length > 0 ) { string script_to_attach = HoudiniHost.getString( script_attr[ 0 ] ); HoudiniAssetUtility.attachScript( geo_node, script_to_attach ); } } } return needs_recook; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); bool gui_enable = GUI.enabled; // We can only build or do anything if we can link to our libraries. #if !( HAPI_ENABLE_RUNTIME ) GUI.enabled = false; #else if (!HoudiniHost.isInstallationOk()) { GUI.enabled = false; } #endif // !( HAPI_ENABLE_RUNTIME ) /////////////////////////////////////////////////////////////////////// // Draw Game Object Controls myAsset.prShowHoudiniControls = HoudiniGUI.foldout("Houdini Controls", myAsset.prShowHoudiniControls, true); if (myAsset.prShowHoudiniControls) { if (GUILayout.Button("Rebuild")) { myGeoAttributeManagerGUI = null; myAsset.buildAll(); if (myAsset.prGeoInputCount > 0 || myAsset.prTransformInputCount > 0) { myAsset.buildClientSide(); } } if (GUILayout.Button("Recook")) { myAsset.buildClientSide(); } if (GUILayout.Button("Bake")) { myAsset.bakeAsset(); } } // Draw Help Pane myAsset.prShowHelp = HoudiniGUI.foldout("Asset Help", myAsset.prShowHelp, true); if (myAsset.prShowHelp) { drawHelpBox(myAsset.prAssetHelp); } /////////////////////////////////////////////////////////////////////// // Draw Asset Settings // These don't affect the asset directly so they don't trigger rebuilds. myAsset.prShowAssetSettings = HoudiniGUI.foldout("Asset Settings", myAsset.prShowAssetSettings, true); if (myAsset.prShowAssetSettings) { generateAssetSettings(); } /////////////////////////////////////////////////////////////////////// // Draw Baking Controls myAsset.prShowBakeOptions = HoudiniGUI.foldout("Bake Animations", myAssetOTL.prShowBakeOptions, true); if (myAsset.prShowBakeOptions) { generateAssetBakeControls(); } GUI.enabled = gui_enable; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Private private void performUndo() { HoudiniParmsUndoInfo undo_info = ScriptableObject.Instantiate(myParms.prParmsUndoInfo) as HoudiniParmsUndoInfo; // First find all multiparms and add/remove instances as necessary. foreach (HAPI_ParmInfo parm in myParms.prParms) { if ( parm.type == HAPI_ParmType.HAPI_PARMTYPE_MULTIPARMLIST && undo_info.parmNames.Contains(parm.name)) { // Get value of multiparm from undo info. int new_value_index = undo_info.parmIndices[undo_info.parmNames.IndexOf(parm.name)]; int new_value = undo_info.parmIntValues[new_value_index]; // get current value of multiparm int current_value = myParms.prParmIntValues[parm.intValuesIndex]; // Add/Remove number of instances from current parameters to match number // of parameters from undo info. int difference = new_value - current_value; if (difference > 0) { myParms.appendMultiparmInstances(parm, difference); } else if (difference < 0) { myParms.removeMultiparmInstances(parm, -difference); } else { continue; } myParms.getParameterValues(); myParmChanges = true; } } // Next loop through all parameters and copy changed values over from undo info. foreach (HAPI_ParmInfo parm in myParms.prParms) { if (!undo_info.parmNames.Contains(parm.name)) { continue; } if (parm.isInt()) { int new_value_index = undo_info.parmIndices[undo_info.parmNames.IndexOf(parm.name)]; bool is_different = false; for (int idx = 0; idx < parm.size; ++idx) { is_different |= undo_info.parmIntValues[new_value_index + idx] != myParms.prParmIntValues[parm.intValuesIndex + idx]; } if (is_different && parm.type != HAPI_ParmType.HAPI_PARMTYPE_MULTIPARMLIST) { myParmChanges = true; int[] values = new int[parm.size]; Array.Copy(undo_info.parmIntValues, new_value_index, values, 0, parm.size); HoudiniHost.setParmIntValues( myParms.prControl.prNodeId, values, parm.intValuesIndex, parm.size); } } else if (parm.isFloat()) { int new_value_index = undo_info.parmIndices[undo_info.parmNames.IndexOf(parm.name)]; bool is_different = false; for (int idx = 0; idx < parm.size; ++idx) { is_different |= undo_info.parmFloatValues[new_value_index + idx] != myParms.prParmFloatValues[parm.floatValuesIndex + idx]; } if (is_different) { myParmChanges = true; float[] values = new float[parm.size]; Array.Copy(undo_info.parmFloatValues, new_value_index, values, 0, parm.size); HoudiniHost.setParmFloatValues( myParms.prControl.prNodeId, values, parm.floatValuesIndex, parm.size); } } else if (parm.isString()) { string[] current_string_values = new string[parm.size]; current_string_values = myParms.getParmStrings(parm); for (int i = 0; i < parm.size; i++) { int new_value_index = undo_info.parmIndices[undo_info.parmNames.IndexOf(parm.name)]; string new_string_value = undo_info.parmStringValues[new_value_index + i]; string current_string_value = current_string_values[i]; if (string.Compare(current_string_value, new_string_value) != 0) { myParmChanges = true; HoudiniHost.setParmStringValue( myParms.prControl.prNodeId, new_string_value, parm.id, i); } } } // By type of parm. } // For all parms. }
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.
public void bakeAnimation(float curr_time, GameObject parent_object) { try { HAPI_GeoInfo geo_info = HoudiniHost.getDisplayGeoInfo(prObjectId); HAPI_Transform[] instance_transforms = new HAPI_Transform[myNumInstances]; Utility.getArray2Id( geo_info.nodeId, HAPI_RSTOrder.HAPI_SRT, HoudiniHost.getInstanceTransforms, instance_transforms, myNumInstances); Matrix4x4 parent_xform_inverse = Matrix4x4.identity; if (parent_object != null) { parent_xform_inverse = parent_object.transform.localToWorldMatrix.inverse; } for (int ii = 0; ii < myNumInstances; ++ii) { Vector3 pos = new Vector3(); // Apply object transforms. // // Axis and Rotation conversions: // Note that Houdini's X axis points in the opposite direction that Unity's does. Also, Houdini's // rotation is right handed, whereas Unity is left handed. To account for this, we need to invert // the x coordinate of the translation, and do the same for the rotations (except for the x rotation, // which doesn't need to be flipped because the change in handedness AND direction of the left x axis // causes a double negative - yeah, I know). pos[0] = -instance_transforms[ii].position[0]; pos[1] = instance_transforms[ii].position[1]; pos[2] = instance_transforms[ii].position[2]; Quaternion quat = new Quaternion(instance_transforms[ii].rotationQuaternion[0], instance_transforms[ii].rotationQuaternion[1], instance_transforms[ii].rotationQuaternion[2], instance_transforms[ii].rotationQuaternion[3]); Vector3 euler = quat.eulerAngles; euler.y = -euler.y; euler.z = -euler.z; quat = Quaternion.Euler(euler); Vector3 scale = new Vector3(instance_transforms[ii].scale[0], instance_transforms[ii].scale[1], instance_transforms[ii].scale[2]); if (parent_object != null) { Matrix4x4 world_mat = Matrix4x4.identity; world_mat.SetTRS(pos, quat, scale); Matrix4x4 local_mat = parent_xform_inverse * world_mat; quat = HoudiniAssetUtility.getQuaternion(local_mat); scale = HoudiniAssetUtility.getScale(local_mat); pos = HoudiniAssetUtility.getPosition(local_mat); } HoudiniCurvesCollection curves = myCurvesCollection[ii]; HoudiniAssetUtility.addKeyToCurve(curr_time, pos[0], curves.tx); HoudiniAssetUtility.addKeyToCurve(curr_time, pos[1], curves.ty); HoudiniAssetUtility.addKeyToCurve(curr_time, pos[2], curves.tz); HoudiniAssetUtility.addKeyToCurve(curr_time, quat.x, curves.qx); HoudiniAssetUtility.addKeyToCurve(curr_time, quat.y, curves.qy); HoudiniAssetUtility.addKeyToCurve(curr_time, quat.z, curves.qz); HoudiniAssetUtility.addKeyToCurve(curr_time, quat.w, curves.qw); HoudiniAssetUtility.addKeyToCurve(curr_time, scale.x, curves.sx); HoudiniAssetUtility.addKeyToCurve(curr_time, scale.y, curves.sy); HoudiniAssetUtility.addKeyToCurve(curr_time, scale.z, curves.sz); } } catch (HoudiniError error) { Debug.LogWarning(error.ToString()); return; } }
public override void OnInspectorGUI() { myPartControl.prShowDisplayOptions = HoudiniGUI.foldout("Display Options", myPartControl.prShowDisplayOptions, true); if (myPartControl.prShowDisplayOptions) { { if (HoudiniGUI.button("print_attribute_names", "Print Attribute Names")) { HoudiniAssetUtility.printAllAttributeNames( myPartControl.prAssetId, myPartControl.prObjectId, myPartControl.prGeoId, myPartControl.prPartId); } if (HoudiniGUI.button("print_group_info", "Print Group Info")) { HoudiniAssetUtility.printAllGroups( myPartControl.prAssetId, myPartControl.prObjectId, myPartControl.prGeoId, myPartControl.prPartId); } } { // Show Houdini Point Numbers bool value = myPartControl.prShowPointNumbers; bool undo_value = false; bool changed = HoudiniGUI.toggle( "show_point_numbers", "Show Houdini Point Numbers", ref value, null, ref undo_value); myPartControl.prShowPointNumbers = value; if (changed) { EditorUtility.SetDirty(myPartControl); } } } myPartControl.prShowIntermediateResultControls = HoudiniGUI.foldout("Intermediate Results", myPartControl.prShowIntermediateResultControls, true); if (myPartControl.prShowIntermediateResultControls) { bool gui_enabled = GUI.enabled; if (myPartControl.prGeoType != HAPI_GeoType.HAPI_GEOTYPE_INTERMEDIATE) { HoudiniGUI.help( "Only specially marked intermediate results geometries can be edited.", MessageType.Info); GUI.enabled = false; } if (GUILayout.Button("Update Intermediate Result")) { MeshFilter mesh_filter = myPartControl.gameObject.GetComponent <MeshFilter>(); Mesh shared_mesh = mesh_filter.sharedMesh; HoudiniPartControl part_control = myPartControl.gameObject.GetComponent <HoudiniPartControl>(); HoudiniAssetUtility.setMesh( myPartControl.prAsset.prAssetId, myPartControl.prObjectId, myPartControl.prGeoId, ref shared_mesh, part_control, null); myPartControl.prAsset.buildClientSide(); } if (GUILayout.Button("Clear Edits")) { HoudiniHost.revertGeo( myPartControl.prAsset.prAssetId, myPartControl.prObjectId, myPartControl.prGeoId); myPartControl.prAsset.buildClientSide(); } GUI.enabled = gui_enabled; } myPartControl.prShowInfo = HoudiniGUI.foldout("Info", myPartControl.prShowInfo, true); if (myPartControl.prShowInfo) { HoudiniGUI.help("Values here are for debugging only and should not be modified directly.", MessageType.Info); bool gui_enabled = GUI.enabled; GUI.enabled = false; DrawDefaultInspector(); GUI.enabled = gui_enabled; } }