public static List<HEU_Handle> FindOrGenerateHandles(HEU_SessionBase session, ref HAPI_AssetInfo assetInfo, HAPI_NodeId assetID, string assetName, HEU_Parameters parameters, List<HEU_Handle> currentHandles)
		{
			List<HEU_Handle> newHandles = new List<HEU_Handle>();

			if (assetInfo.handleCount == 0)
			{
				return newHandles;
			}

			HAPI_HandleInfo[] handleInfos = new HAPI_HandleInfo[assetInfo.handleCount];
			HEU_GeneralUtility.GetArray1Arg(assetID, session.GetHandleInfo, handleInfos, 0, assetInfo.handleCount);

			for (int i = 0; i < handleInfos.Length; ++i)
			{
				if (handleInfos[i].bindingsCount <= 0)
				{
					continue;
				}

				string handleName = HEU_SessionManager.GetString(handleInfos[i].nameSH, session);

				HEU_Handle.HEU_HandleType handleType = HEU_Handle.HEU_HandleType.UNSUPPORTED;
				string handleTypeString = HEU_SessionManager.GetString(handleInfos[i].typeNameSH, session);
				if (handleTypeString.Equals(HEU_Defines.HAPI_HANDLE_TRANSFORM))
				{
					handleType = HEU_Handle.HEU_HandleType.XFORM;
				}
				else
				{
					// Commented out warning as it gets annoying, especially with "Curve" handles
					//Debug.LogWarningFormat("Asset {0} has unsupported Handle type {0} for handle {1}", assetName, handleName, handleTypeString);
					continue;
				}

				HEU_Handle newHandle = null;
				foreach (HEU_Handle curHandle in currentHandles)
				{
					if (curHandle.HandleName.Equals(handleName))
					{
						newHandle = curHandle;
						break;
					}
				}

				if (newHandle == null)
				{
					newHandle = ScriptableObject.CreateInstance<HEU_Handle>();
				}

				bool bSuccess = newHandle.SetupHandle(session, assetID, i, handleName, handleType, ref handleInfos[i], parameters);
				if (bSuccess)
				{
					newHandles.Add(newHandle);
					//Debug.LogFormat("Found handle {0} of type {1}", handleName, handleTypeString);
				}
			}

			return newHandles;
		}
Пример #2
0
		//  LOGIC -----------------------------------------------------------------------------------------------------

		public bool SetupHandle(HEU_SessionBase session, HAPI_NodeId assetID, int handleIndex, string handleName, 
			HEU_HandleType handleType, ref HAPI_HandleInfo handleInfo, HEU_Parameters parameters)
		{
			_handleIndex = handleIndex;
			_handleName = handleName;
			_handleType = handleType;

			HAPI_HandleBindingInfo[] handleBindingInfos = new HAPI_HandleBindingInfo[handleInfo.bindingsCount];
			if (!session.GetHandleBindingInfo(assetID, _handleIndex, handleBindingInfos, 0, handleInfo.bindingsCount))
			{
				return false;
			}

			HAPI_ParmId translateParmID = -1;
			HAPI_ParmId rotateParmID = -1;
			HAPI_ParmId scaleParmID = -1;
			HAPI_ParmId rstOrderParmID = -1;
			HAPI_ParmId xyzOrderParmID = -1;

			_rstOrder = HAPI_RSTOrder.HAPI_SRT;
			_xyzOrder = HAPI_XYZOrder.HAPI_XYZ;

			_handleParamTranslateBinding = null;
			_handleParamRotateBinding = null;
			_handleParamScaleBinding = null;

			for (int i = 0; i < handleBindingInfos.Length; ++i)
			{
				string parmName = HEU_SessionManager.GetString(handleBindingInfos[i].handleParmNameSH, session);

				//string assetParmName = HEU_SessionManager.GetString(handleBindingInfos[i].assetParmNameSH, session);
				//Debug.LogFormat("Handle {0} has parm {1} with asset parm {2} with asset parm id {3}", handleName, parmName, assetParmName, handleBindingInfos[i].assetParmId);

				if (parmName.Equals("tx") || parmName.Equals("ty") || parmName.Equals("tz"))
				{
					translateParmID = handleBindingInfos[i].assetParmId;

					if(_handleParamTranslateBinding == null)
					{
						HEU_ParameterData parmData = parameters.GetParameterWithParmID(translateParmID);
						if (parmData != null && !parmData._parmInfo.invisible)
						{
							_handleParamTranslateBinding = new HEU_HandleParamBinding();
							_handleParamTranslateBinding._paramType = HEU_HandleParamBinding.HEU_HandleParamType.TRANSLATE;
							_handleParamTranslateBinding._parmID = parmData.ParmID;
							_handleParamTranslateBinding._paramName = parmData._name;
							_handleParamTranslateBinding._bDisabled = parmData._parmInfo.disabled;
						}
					}

					if(_handleParamTranslateBinding != null)
					{
						if(parmName.Equals("tx"))
						{
							_handleParamTranslateBinding._boundChannels[0] = true;
						}
						else if (parmName.Equals("ty"))
						{
							_handleParamTranslateBinding._boundChannels[1] = true;
						}
						else if (parmName.Equals("tz"))
						{
							_handleParamTranslateBinding._boundChannels[2] = true;
						}
					}
				}

				if (parmName.Equals("rx") || parmName.Equals("ry") || parmName.Equals("rz"))
				{
					rotateParmID = handleBindingInfos[i].assetParmId;

					if(_handleParamRotateBinding == null)
					{
						HEU_ParameterData parmData = parameters.GetParameterWithParmID(rotateParmID);
						if (parmData != null && !parmData._parmInfo.invisible)
						{
							_handleParamRotateBinding = new HEU_HandleParamBinding();
							_handleParamRotateBinding._paramType = HEU_HandleParamBinding.HEU_HandleParamType.ROTATE;
							_handleParamRotateBinding._parmID = parmData.ParmID;
							_handleParamRotateBinding._paramName = parmData._name;
							_handleParamRotateBinding._bDisabled = parmData._parmInfo.disabled;
						}
					}

					if (_handleParamRotateBinding != null)
					{
						if (parmName.Equals("rx"))
						{
							_handleParamRotateBinding._boundChannels[0] = true;
						}
						else if (parmName.Equals("ry"))
						{
							_handleParamRotateBinding._boundChannels[1] = true;
						}
						else if (parmName.Equals("rz"))
						{
							_handleParamRotateBinding._boundChannels[2] = true;
						}
					}
				}

				if (parmName.Equals("sx") || parmName.Equals("sy") || parmName.Equals("sz"))
				{
					scaleParmID = handleBindingInfos[i].assetParmId;

					if (_handleParamScaleBinding == null)
					{
						HEU_ParameterData parmData = parameters.GetParameterWithParmID(scaleParmID);
						if (parmData != null && !parmData._parmInfo.invisible)
						{
							_handleParamScaleBinding = new HEU_HandleParamBinding();
							_handleParamScaleBinding._paramType = HEU_HandleParamBinding.HEU_HandleParamType.SCALE;
							_handleParamScaleBinding._parmID = parmData.ParmID;
							_handleParamScaleBinding._paramName = parmData._name;
							_handleParamScaleBinding._bDisabled = parmData._parmInfo.disabled;
						}
					}

					if (_handleParamScaleBinding != null)
					{
						if (parmName.Equals("sx"))
						{
							_handleParamScaleBinding._boundChannels[0] = true;
						}
						else if (parmName.Equals("sy"))
						{
							_handleParamScaleBinding._boundChannels[1] = true;
						}
						else if (parmName.Equals("sz"))
						{
							_handleParamScaleBinding._boundChannels[2] = true;
						}
					}
				}

				if(parmName.Equals("trs_order"))
				{
					rstOrderParmID = handleBindingInfos[i].assetParmId;
				}

				if (parmName.Equals("xyz_order"))
				{
					xyzOrderParmID = handleBindingInfos[i].assetParmId;
				}
			}

			if (rstOrderParmID >= 0)
			{
				HEU_ParameterData parmData = parameters.GetParameter(rstOrderParmID);
				if (parmData != null)
				{
					_rstOrder = (HAPI_RSTOrder)parmData._intValues[0];
				}
			}

			if (xyzOrderParmID >= 0)
			{
				HEU_ParameterData parmData = parameters.GetParameter(xyzOrderParmID);
				if (parmData != null)
				{
					_xyzOrder = (HAPI_XYZOrder)parmData._intValues[0];
				}
			}

			GenerateTransform(session, parameters);

			return true;
		}