Esempio n. 1
0
		public bool GetUpdatedPosition(HEU_HoudiniAsset asset, ref Vector3 inPosition)
		{
			if (_handleParamTranslateBinding == null || _handleParamTranslateBinding._bDisabled)
			{
				return false;
			}

			HEU_SessionBase session = asset.GetAssetSession(true);
			if(session == null)
			{
				return false;
			}

			if (IsSpecialRSTOrder(_rstOrder))
			{
				HAPI_TransformEuler transformEuler = _convertedTransformEuler;
				transformEuler.position[0] = inPosition[0];
				transformEuler.position[1] = inPosition[1];
				transformEuler.position[2] = inPosition[2];

				HAPI_TransformEuler newTransformEuler;
				if (!session.ConvertTransform(ref transformEuler, _rstOrder, _xyzOrder, out newTransformEuler))
				{
					return false;
				}

				inPosition[0] = newTransformEuler.position[0];
				inPosition[1] = newTransformEuler.position[1];
				inPosition[2] = newTransformEuler.position[2];
			}

			inPosition[0] = -inPosition[0];

			return true;
		}
Esempio n. 2
0
        public static HAPI_TransformEuler GetHAPITransformFromMatrix(ref Matrix4x4 mat)
        {
            Quaternion q = GetQuaternion(ref mat);
            Vector3    r = q.eulerAngles;

            Vector3 p = GetPosition(ref mat);
            Vector3 s = GetScale(ref mat);

            HAPI_TransformEuler transform = new HAPI_TransformEuler(true);

            transform.position[0] = -p[0];
            transform.position[1] = p[1];
            transform.position[2] = p[2];

            transform.rotationEuler[0] = r[0];
            transform.rotationEuler[1] = -r[1];
            transform.rotationEuler[2] = -r[2];

            transform.scale[0] = s[0];
            transform.scale[1] = s[1];
            transform.scale[2] = s[2];

            transform.rotationOrder = HAPI_XYZOrder.HAPI_ZXY;
            transform.rstOrder      = HAPI_RSTOrder.HAPI_SRT;

            return(transform);
        }
Esempio n. 3
0
		/// <summary>
		/// Generates heightfield/terrain data from the given object relevant for uploading to Houdini.
		/// </summary>
		/// <param name="inputObject"></param>
		/// <returns>Valid input object or null if given object is not supported</returns>
		public HEU_InputDataTerrain GenerateTerrainDataFromGameObject(GameObject inputObject)
		{
			HEU_InputDataTerrain inputData = null;

			Terrain terrain = inputObject.GetComponent<Terrain>();
			if (terrain != null)
			{
				TerrainData terrainData = terrain.terrainData;

				Vector3 terrainSize = terrainData.size;
				if (terrainSize.x != terrainSize.z)
				{
					Debug.LogError("Only square sized terrains are supported for input! Change to square size and try again.");
					return null;
				}

				inputData = new HEU_InputDataTerrain();
				inputData._inputObject = inputObject;
				inputData._terrain = terrain;
				inputData._terrainData = terrainData;

				// Height values in Unity are normalized between 0 and 1, so this height scale
				// will multiply them before uploading to Houdini.
				inputData._heightScale = terrainSize.y;

				// Terrain heightMapResolution is the pixel resolution, which we set to the number of voxels
				// by dividing the terrain size with it. In Houdini, this is the Grid Spacing.
				inputData._voxelSize = terrainSize.x / inputData._terrainData.heightmapResolution;

				// This is the number of heightfield voxels on each dimension.
				inputData._numPointsX = Mathf.RoundToInt(inputData._terrainData.heightmapResolution * inputData._voxelSize);
				inputData._numPointsY = Mathf.RoundToInt(inputData._terrainData.heightmapResolution * inputData._voxelSize);

				Matrix4x4 transformMatrix = inputObject.transform.localToWorldMatrix;
				HAPI_TransformEuler transformEuler = HEU_HAPIUtility.GetHAPITransformFromMatrix(ref transformMatrix);

				// Volume transform used for all heightfield layers
				inputData._transform = new HAPI_Transform(false);

				// Unity terrain pivots are at bottom left, but Houdini uses centered heightfields so
				// apply local position offset by half sizes and account for coordinate change
				inputData._transform.position[0] = terrainSize.z * 0.5f;
				inputData._transform.position[1] = -terrainSize.x * 0.5f;
				inputData._transform.position[2] = 0;

				// Volume scale controls final size, but requires to be divided by 2
				inputData._transform.scale[0] = terrainSize.x * 0.5f;
				inputData._transform.scale[1] = terrainSize.z * 0.5f;
				inputData._transform.scale[2] = 0.5f;

				inputData._transform.rotationQuaternion[0] = 0f;
				inputData._transform.rotationQuaternion[1] = 0f;
				inputData._transform.rotationQuaternion[2] = 0f;
				inputData._transform.rotationQuaternion[3] = 1f;
			}

			return inputData;
		}
Esempio n. 4
0
	/// <summary>
	/// Set the input node's transform.
	/// </summary>
	/// <param name="session">Session that the input node exists in</param>
	/// <param name="inputObject">The input object info containing data about the input</param>
	/// <param name="inputNodeID">The input node ID</param>
	/// <param name="bKeepWorldTransform">Whether to use world transform or not</param>
	/// <returns></returns>
	internal static bool UploadInputObjectTransform(HEU_SessionBase session, HEU_InputObjectInfo inputObject, HAPI_NodeId inputNodeID, bool bKeepWorldTransform)
	{
	    Matrix4x4 inputTransform = Matrix4x4.identity;
	    if (inputObject._useTransformOffset)
	    {
		if (bKeepWorldTransform)
		{
		    // Add offset tranform to world transform
		    Transform inputObjTransform = inputObject._gameObject.transform;
		    Vector3 position = inputObjTransform.position + inputObject._translateOffset;
		    Quaternion rotation = inputObjTransform.rotation * Quaternion.Euler(inputObject._rotateOffset);
		    Vector3 scale = Vector3.Scale(inputObjTransform.localScale, inputObject._scaleOffset);

		    Vector3 rotVector = rotation.eulerAngles;
		    inputTransform = HEU_HAPIUtility.GetMatrix4x4(ref position, ref rotVector, ref scale);
		}
		else
		{
		    // Offset from origin.
		    inputTransform = HEU_HAPIUtility.GetMatrix4x4(ref inputObject._translateOffset, ref inputObject._rotateOffset, ref inputObject._scaleOffset);
		}
	    }
	    else
	    {
		inputTransform = inputObject._gameObject.transform.localToWorldMatrix;
	    }

	    HAPI_TransformEuler transformEuler = HEU_HAPIUtility.GetHAPITransformFromMatrix(ref inputTransform);

	    HAPI_NodeInfo inputNodeInfo = new HAPI_NodeInfo();
	    if (!session.GetNodeInfo(inputNodeID, ref inputNodeInfo))
	    {
		return false;
	    }

	    if (session.SetObjectTransform(inputNodeInfo.parentId, ref transformEuler))
	    {
		inputObject._syncdTransform = inputTransform;

		inputObject._syncdChildTransforms.Clear();

		GetChildrenTransforms(inputObject._gameObject.transform, ref inputObject._syncdChildTransforms);
	    }

	    return true;
	}
Esempio n. 5
0
		public bool GetUpdatedRotation(HEU_HoudiniAsset asset, ref Quaternion inRotation)
		{
			if (_handleParamTranslateBinding == null || _handleParamTranslateBinding._bDisabled)
			{
				return false;
			}

			HEU_SessionBase session = asset.GetAssetSession(true);
			if (session == null)
			{
				return false;
			}

			Vector3 newRotation = inRotation.eulerAngles;

			HAPI_TransformEuler transformEuler = _convertedTransformEuler;

			transformEuler.position[0] = 0;
			transformEuler.position[1] = 0;
			transformEuler.position[2] = 0;
			transformEuler.rotationEuler[0] = newRotation[0];
			transformEuler.rotationEuler[1] = newRotation[1];
			transformEuler.rotationEuler[2] = newRotation[2];
			transformEuler.scale[0] = 1;
			transformEuler.scale[1] = 1;
			transformEuler.scale[2] = 1;
			transformEuler.rotationOrder = HAPI_XYZOrder.HAPI_ZXY;
			transformEuler.rstOrder = HAPI_RSTOrder.HAPI_SRT;

			HAPI_TransformEuler newTransformEuler;
			if (!session.ConvertTransform(ref transformEuler, _rstOrder, _xyzOrder, out newTransformEuler))
			{
				return false;
			}

			inRotation[0] = newTransformEuler.rotationEuler[0];
			inRotation[1] = -newTransformEuler.rotationEuler[1];
			inRotation[2] = -newTransformEuler.rotationEuler[2];

			return true;
		}
Esempio n. 6
0
        public static HAPI_TransformEuler GetHAPITransform(ref Vector3 p, ref Vector3 r, ref Vector3 s)
        {
            HAPI_TransformEuler transform = new HAPI_TransformEuler(true);

            transform.position[0] = -p[0];
            transform.position[1] = p[1];
            transform.position[2] = p[2];

            transform.rotationEuler[0] = r[0];
            transform.rotationEuler[1] = -r[1];
            transform.rotationEuler[2] = -r[2];

            transform.scale[0] = s[0];
            transform.scale[1] = s[1];
            transform.scale[2] = s[2];

            transform.rotationOrder = HAPI_XYZOrder.HAPI_ZXY;
            transform.rstOrder      = HAPI_RSTOrder.HAPI_SRT;

            return(transform);
        }
Esempio n. 7
0
		public void GenerateTransform(HEU_SessionBase session, HEU_Parameters parameters)
		{
			HAPI_TransformEuler transformEuler = new HAPI_TransformEuler(true);

			transformEuler.rstOrder = _rstOrder;
			transformEuler.rotationOrder = _xyzOrder;

			transformEuler.position[0] = 0;
			transformEuler.position[1] = 0;
			transformEuler.position[2] = 0;

			transformEuler.rotationEuler[0] = 0;
			transformEuler.rotationEuler[1] = 0;
			transformEuler.rotationEuler[2] = 0;

			transformEuler.scale[0] = 1;
			transformEuler.scale[1] = 1;
			transformEuler.scale[2] = 1;

			if (_handleParamTranslateBinding != null)
			{
				HEU_ParameterData parmData = parameters.GetParameterWithParmID(_handleParamTranslateBinding._parmID);
				if (parmData != null && !parmData._parmInfo.invisible)
				{
					transformEuler.position[0] = parmData._floatValues[0];
					transformEuler.position[1] = parmData._floatValues[1];
					transformEuler.position[2] = parmData._floatValues[2];
				}
			}

			if(_handleParamRotateBinding != null)
			{
				HEU_ParameterData parmData = parameters.GetParameterWithParmID(_handleParamRotateBinding._parmID);
				if (parmData != null && !parmData._parmInfo.invisible)
				{
					transformEuler.rotationEuler[0] = parmData._floatValues[0];
					transformEuler.rotationEuler[1] = parmData._floatValues[1];
					transformEuler.rotationEuler[2] = parmData._floatValues[2];
				}
			}

			if(_handleParamScaleBinding != null)
			{
				HEU_ParameterData parmData = parameters.GetParameterWithParmID(_handleParamScaleBinding._parmID);
				if (parmData != null && !parmData._parmInfo.invisible)
				{
					transformEuler.scale[0] = parmData._floatValues[0];
					transformEuler.scale[1] = parmData._floatValues[1];
					transformEuler.scale[2] = parmData._floatValues[2];
				}
			}

			if (!session.ConvertTransform(ref transformEuler, HAPI_RSTOrder.HAPI_SRT, HAPI_XYZOrder.HAPI_ZXY, out _convertedTransformEuler))
			{
				return;
			}

			// Convert to left-handed Unity
			_convertedTransformEuler.position[0] = -_convertedTransformEuler.position[0];
			_convertedTransformEuler.rotationEuler[1] = -_convertedTransformEuler.rotationEuler[1];
			_convertedTransformEuler.rotationEuler[2] = -_convertedTransformEuler.rotationEuler[2];

			if (IsSpecialRSTOrder(transformEuler.rstOrder))
			{
				_handlePosition = new Vector3(_convertedTransformEuler.position[0], _convertedTransformEuler.position[1], _convertedTransformEuler.position[2]);
			}
			else if (_handleParamTranslateBinding != null)
			{
				_handlePosition = new Vector3(-transformEuler.position[0], transformEuler.position[1], transformEuler.position[2]);
			}
			else
			{
				_handlePosition = Vector3.zero;
			}

			_handleRotation = Quaternion.Euler(_convertedTransformEuler.rotationEuler[0], _convertedTransformEuler.rotationEuler[1], _convertedTransformEuler.rotationEuler[2]);

			if (_handleParamScaleBinding != null)
			{
				_handleScale = new Vector3(transformEuler.scale[0], transformEuler.scale[1], transformEuler.scale[2]);
			}
			else
			{
				_handleScale = Vector3.one;
			}
		}
		/// <summary>
		/// Set the transform of an OBJ node.
		/// </summary>
		/// <param name="nodeID">The object node ID</param>
		/// <param name="hapiTransform">The transform to set</param>
		/// <returns>True if successfully set the transform</returns>
		public virtual bool SetObjectTransform(HAPI_NodeId nodeID, ref HAPI_TransformEuler hapiTransform)
		{
			return false;
		}
		public virtual bool ConvertTransform(ref HAPI_TransformEuler inTransform, HAPI_RSTOrder RSTOrder, HAPI_XYZOrder ROTOrder, out HAPI_TransformEuler outTransform)
		{
			outTransform = new HAPI_TransformEuler();
			return false;
		}