コード例 #1
0
	/// <summary>
	/// Project curve points onto collider or layer.
	/// </summary>
	/// <param name="parentAsset">Parent asset of the curve</param>
	/// <param name="rayDirection">Direction to cast ray</param>
	/// <param name="rayDistance">Maximum ray cast distance</param>
	public void ProjectToColliders(HEU_HoudiniAsset parentAsset, Vector3 rayDirection, float rayDistance)
	{
	    bool bRequiresUpload = false;

	    LayerMask layerMask = Physics.DefaultRaycastLayers;

	    HEU_Curve.CurveDrawCollision collisionType = parentAsset.CurveDrawCollision;
	    if (collisionType == CurveDrawCollision.COLLIDERS)
	    {
		List<Collider> colliders = parentAsset.GetCurveDrawColliders();

		bool bFoundHit = false;
		int numPoints = _points.Count;
		for (int i = 0; i < numPoints; ++i)
		{
		    bFoundHit = false;
		    RaycastHit[] rayHits = Physics.RaycastAll(_points[i], rayDirection, rayDistance, layerMask, QueryTriggerInteraction.Ignore);
		    foreach (RaycastHit hit in rayHits)
		    {
			foreach (Collider collider in colliders)
			{
			    if (hit.collider == collider)
			    {
				_points[i] = hit.point;
				bFoundHit = true;
				bRequiresUpload = true;
				break;
			    }
			}

			if (bFoundHit)
			{
			    break;
			}
		    }
		}


	    }
	    else if (collisionType == CurveDrawCollision.LAYERMASK)
	    {
		layerMask = parentAsset.GetCurveDrawLayerMask();

		int numPoints = _points.Count;
		for (int i = 0; i < numPoints; ++i)
		{
		    RaycastHit hitInfo;
		    if (Physics.Raycast(_points[i], rayDirection, out hitInfo, rayDistance, layerMask, QueryTriggerInteraction.Ignore))
		    {
			_points[i] = hitInfo.point;
			bRequiresUpload = true;
		    }
		}
	    }

	    if (bRequiresUpload)
	    {
		HEU_ParameterData paramData = _parameters.GetParameter(HEU_Defines.CURVE_COORDS_PARAM);
		if (paramData != null)
		{
		    paramData._stringValues[0] = GetPointsString(_points);
		}

		SetEditState(CurveEditState.REQUIRES_GENERATION);
	    }
	}
コード例 #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;
		}