Exemplo n.º 1
0
	public static HEU_HandleManipMode GetCurrentGlobalManipMode()
	{
	    string manipTool = Tools.current.ToString();
	    HEU_HandleManipMode manipMode = HEU_HandleManipMode.MOVE;
	    if (manipTool.Equals("Move"))
	    {
		manipMode = HEU_HandleManipMode.MOVE;
	    }
	    else if (manipTool.Equals("Rotate"))
	    {
		manipMode = HEU_HandleManipMode.ROTATE;
	    }
	    else if (manipTool.Equals("Scale"))
	    {
		manipMode = HEU_HandleManipMode.SCALE;
	    }
	    return manipMode;
	}
Exemplo n.º 2
0
	public bool DrawHandles(HEU_HoudiniAsset asset)
	{
	    List<HEU_Handle> handles = CacheHandles();

	    HEU_HandleManipMode manipMode = GetCurrentGlobalManipMode();

	    GUIStyle textStyle = new GUIStyle(EditorStyles.textField);
	    textStyle.contentOffset = new Vector2(1.4f, 1.4f);

	    HEU_Parameters assetParameters = asset.Parameters;
	    SerializedObject serializedParametersObject = new SerializedObject(assetParameters);
	    SerializedProperty parameterListProperty = HEU_EditorUtility.GetSerializedProperty(serializedParametersObject, "_parameterList");

	    bool bChanged = false;

	    Matrix4x4 defaultMatrix = Handles.matrix;

	    foreach (HEU_Handle handle in handles)
	    {
		if (handle.HandleType == HEU_Handle.HEU_HandleType.XFORM)
		{
		    Handles.matrix = asset.transform.localToWorldMatrix;

		    Vector3 handlePosition = handle.HandlePosition;
		    Quaternion handleRotation = handle.HandleRotation;
		    Vector3 handleScale = handle.HandleScale;

		    string handleName = handle.HandleName;

		    if (manipMode == HEU_HandleManipMode.MOVE)
		    {
			if (!handle.HasTranslateHandle())
			{
			    continue;
			}

			bool bDisabled = handle.IsTranslateHandleDisabled();
			if (bDisabled)
			{
			    handleName += " (disabled)";
			}

			GUIContent labelContent = new GUIContent(handleName);
			labelContent.tooltip = handleName;

			Handles.Label(handlePosition, labelContent, textStyle);

			if (bDisabled)
			{
			    bool bLighting = Handles.lighting;
			    Handles.lighting = false;
			    Handles.PositionHandle(handlePosition, handleRotation);
			    Handles.lighting = bLighting;
			    continue;
			}

			Vector3 updatedPosition = Handles.PositionHandle(handlePosition, handleRotation);
			if (updatedPosition != handlePosition)
			{
			    if (!handle.GetUpdatedPosition(asset, ref updatedPosition))
			    {
				continue;
			    }

			    HEU_HandleParamBinding translateBinding = handle.GetTranslateBinding();
			    if (translateBinding != null)
			    {
				HEU_ParameterData paramData = assetParameters.GetParameterWithParmID(translateBinding._parmID);
				if (paramData != null && paramData._unityIndex < parameterListProperty.arraySize)
				{
				    SerializedProperty paramDataProperty = parameterListProperty.GetArrayElementAtIndex(paramData._unityIndex);
				    float[] posFloats = new float[3];
				    posFloats[0] = updatedPosition[0];
				    posFloats[1] = updatedPosition[1];
				    posFloats[2] = updatedPosition[2];
				    bChanged |= UpdateFloatArrayProperty(paramDataProperty, posFloats, translateBinding);
				}
			    }
			}
		    }
		    else if (manipMode == HEU_HandleManipMode.ROTATE)
		    {
			if (!handle.HasRotateHandle())
			{
			    continue;
			}

			bool bDisabled = handle.IsRotateHandleDisabled();
			if (bDisabled)
			{
			    handleName += " (disabled)";
			}

			GUIContent labelContent = new GUIContent(handleName);
			labelContent.tooltip = handleName;

			Handles.Label(handlePosition, labelContent, textStyle);

			if (bDisabled)
			{
			    bool bLighting = Handles.lighting;
			    Handles.lighting = false;
			    Handles.RotationHandle(handleRotation, handlePosition);
			    Handles.lighting = bLighting;
			    continue;
			}

			Quaternion updatedRotation = Handles.RotationHandle(handleRotation, handlePosition);
			if (updatedRotation != handleRotation)
			{
			    if (!handle.GetUpdatedRotation(asset, ref updatedRotation))
			    {
				continue;
			    }

			    HEU_HandleParamBinding rotateBinding = handle.GetRotateBinding();
			    if (rotateBinding != null)
			    {
				HEU_ParameterData paramData = assetParameters.GetParameterWithParmID(rotateBinding._parmID);
				if (paramData != null && paramData._unityIndex < parameterListProperty.arraySize)
				{
				    SerializedProperty paramDataProperty = parameterListProperty.GetArrayElementAtIndex(paramData._unityIndex);
				    float[] rotFloats = new float[3];
				    rotFloats[0] = updatedRotation[0];
				    rotFloats[1] = updatedRotation[1];
				    rotFloats[2] = updatedRotation[2];
				    bChanged |= UpdateFloatArrayProperty(paramDataProperty, rotFloats, rotateBinding);
				}
			    }
			}
		    }
		    else if (manipMode == HEU_HandleManipMode.SCALE)
		    {
			if (!handle.HasScaleHandle())
			{
			    continue;
			}

			bool bDisabled = handle.IsScaleHandleDisabled();
			if (bDisabled)
			{
			    handleName += " (disabled)";
			}

			GUIContent labelContent = new GUIContent(handleName);
			labelContent.tooltip = handleName;

			Handles.Label(handlePosition, labelContent, textStyle);

			if (bDisabled)
			{
			    bool bLighting = Handles.lighting;
			    Handles.lighting = false;
			    Handles.ScaleHandle(handleScale, handlePosition, handleRotation, 1f);
			    Handles.lighting = bLighting;
			    continue;
			}

			Vector3 updatedScale = Handles.ScaleHandle(handleScale, handlePosition, handleRotation, 1f);
			if (updatedScale != handleScale)
			{
			    HEU_HandleParamBinding scaleBinding = handle.GetScaleBinding();
			    if (scaleBinding != null)
			    {
				HEU_ParameterData paramData = assetParameters.GetParameterWithParmID(scaleBinding._parmID);
				if (paramData != null && paramData._unityIndex < parameterListProperty.arraySize)
				{
				    SerializedProperty paramDataProperty = parameterListProperty.GetArrayElementAtIndex(paramData._unityIndex);
				    float[] scaleFloats = new float[3];
				    scaleFloats[0] = updatedScale[0];
				    scaleFloats[1] = updatedScale[1];
				    scaleFloats[2] = updatedScale[2];
				    bChanged |= UpdateFloatArrayProperty(paramDataProperty, scaleFloats, scaleBinding);
				}
			    }
			}
		    }
		}
	    }

	    if (bChanged)
	    {
		serializedParametersObject.ApplyModifiedProperties();
	    }

	    Handles.matrix = defaultMatrix;

	    return bChanged;
	}