public void CopyInputValuesTo(HEU_SessionBase session, HEU_InputNode destInputNode)
	{
	    destInputNode._pendingInputObjectType = _inputObjectType;

	    if (destInputNode._inputObjectType == InputObjectType.HDA)
	    {
		destInputNode.ResetConnectionForForceUpdate(session);
	    }

	    destInputNode.RemoveAllInputEntries();

	    foreach (HEU_InputObjectInfo srcInputObject in _inputObjects)
	    {
		HEU_InputObjectInfo newInputObject = new HEU_InputObjectInfo();
		srcInputObject.CopyTo(newInputObject);

		destInputNode._inputObjects.Add(newInputObject);
	    }

	    foreach (HEU_InputHDAInfo srcInputInfo in _inputAssetInfos)
	    {
		HEU_InputHDAInfo newInputInfo = new HEU_InputHDAInfo();
		srcInputInfo.CopyTo(newInputInfo);

		destInputNode._inputAssetInfos.Add(newInputInfo);
	    }

	    destInputNode._keepWorldTransform = _keepWorldTransform;
	    destInputNode._packGeometryBeforeMerging = _packGeometryBeforeMerging;
	}
	private HEU_InputObjectInfo CreateInputObjectInfo(GameObject inputGameObject)
	{
	    HEU_InputObjectInfo newObjectInfo = new HEU_InputObjectInfo();
	    newObjectInfo._gameObject = inputGameObject;

	    return newObjectInfo;
	}
Exemple #3
0
		public void CopyInputValuesTo(HEU_SessionBase session, HEU_InputNode destInputNode)
		{
			destInputNode._pendingInputObjectType = _inputObjectType;

			if(destInputNode._inputObjectType == InputObjectType.HDA)
			{
				destInputNode.ResetConnectionForForceUpdate(session);
			}

			destInputNode._inputObjects.Clear();
			foreach(HEU_InputObjectInfo inputObj in _inputObjects)
			{
				HEU_InputObjectInfo newInputObject = new HEU_InputObjectInfo();
				inputObj.CopyTo(newInputObject);
				//newInputObject._syncdTransform = Matrix4x4.identity;

				destInputNode._inputObjects.Add(newInputObject);
			}

			destInputNode._inputAsset = _inputAsset;
			destInputNode._connectedInputAsset = _connectedInputAsset;

			destInputNode._keepWorldTransform = _keepWorldTransform;
			destInputNode._packGeometryBeforeMerging = _packGeometryBeforeMerging;
		}
Exemple #4
0
		public void CopyTo(HEU_InputObjectInfo destObject)
		{
			destObject._gameObject = _gameObject;
			destObject._syncdTransform = _syncdTransform;
			destObject._useTransformOffset = _useTransformOffset;
			destObject._translateOffset = _translateOffset;
			destObject._rotateOffset = _rotateOffset;
			destObject._scaleOffset = _scaleOffset;
		}
Exemple #5
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;
	}
Exemple #6
0
	/// <summary>
	/// Return the input interface that can upload the given inputObjectInfo's data.
	/// It checks the inputObjectInfo._inputInterfaceType to see if it was previously
	/// uploaded, and if so, uses the same interface.
	/// </summary>
	/// <param name="inputObjectInfo">Input object info used to find the interface</param>
	/// <returns>Compatible input interface or null</returns>
	internal static HEU_InputInterface GetInputInterface(HEU_InputObjectInfo inputObjectInfo)
	{
	    HEU_InputInterface inputInterface = null;
	    if (inputObjectInfo._inputInterfaceType == null)
	    {
		inputInterface = GetInputInterfaceByType(inputObjectInfo._inputInterfaceType);
	    }
	    if (inputInterface == null)
	    {
		inputInterface = GetInputInterface(inputObjectInfo._gameObject);
		if (inputInterface != null)
		{
		    inputObjectInfo._inputInterfaceType = inputInterface.GetType();
		}
	    }
	    return inputInterface;
	}
	public void LoadPreset(HEU_SessionBase session, HEU_InputPreset inputPreset)
	{
	    ResetInputNode(session);

	    ChangeInputType(session, inputPreset._inputObjectType);

	    if (inputPreset._inputObjectType == InputObjectType.UNITY_MESH)
	    {
		bool bSet = false;
		int numObjects = inputPreset._inputObjectPresets.Count;
		for (int i = 0; i < numObjects; ++i)
		{
		    bSet = false;

		    if (!string.IsNullOrEmpty(inputPreset._inputObjectPresets[i]._gameObjectName))
		    {
			GameObject inputGO = null;
			if (inputPreset._inputObjectPresets[i]._isSceneObject)
			{
			    inputGO = HEU_GeneralUtility.GetGameObjectByNameInScene(inputPreset._inputObjectPresets[i]._gameObjectName);
			}
			else
			{
			    // Use the _gameObjectName as path to find in scene
			    inputGO = HEU_AssetDatabase.LoadAssetAtPath(inputPreset._inputObjectPresets[i]._gameObjectName, typeof(GameObject)) as GameObject;
			    if (inputGO == null)
			    {
				Debug.LogErrorFormat("Unable to find input at {0}", inputPreset._inputObjectPresets[i]._gameObjectName);
			    }
			}

			if (inputGO != null)
			{
			    HEU_InputObjectInfo inputObject = InternalAddInputObjectAtEnd(inputGO);
			    bSet = true;

			    inputObject._useTransformOffset = inputPreset._inputObjectPresets[i]._useTransformOffset;
			    inputObject._translateOffset = inputPreset._inputObjectPresets[i]._translateOffset;
			    inputObject._rotateOffset = inputPreset._inputObjectPresets[i]._rotateOffset;
			    inputObject._scaleOffset = inputPreset._inputObjectPresets[i]._scaleOffset;
			}
			else
			{
			    Debug.LogWarningFormat("Gameobject with name {0} not found. Unable to set input object.", inputPreset._inputAssetName);
			}
		    }

		    if (!bSet)
		    {
			// Add dummy spot (user can replace it manually)
			InternalAddInputObjectAtEnd(null);
		    }
		}
	    }
	    else if (inputPreset._inputObjectType == HEU_InputNode.InputObjectType.HDA)
	    {
		bool bSet = false;
		int numInptus = inputPreset._inputAssetPresets.Count;
		for (int i = 0; i < numInptus; ++i)
		{
		    bSet = false;
		    if (!string.IsNullOrEmpty(inputPreset._inputAssetPresets[i]._gameObjectName))
		    {
			bSet = FindAddToInputHDA(inputPreset._inputAssetPresets[i]._gameObjectName);
		    }

		    if (!bSet)
		    {
			// Couldn't add for some reason, so just add dummy spot (user can replace it manually)
			InternalAddInputHDAAtEnd(null);
		    }
		}

		if (numInptus == 0 && !string.IsNullOrEmpty(inputPreset._inputAssetName))
		{
		    // Old preset. Add it to input
		    FindAddToInputHDA(inputPreset._inputAssetName);
		}
	    }

	    KeepWorldTransform = inputPreset._keepWorldTransform;
	    PackGeometryBeforeMerging = inputPreset._packGeometryBeforeMerging;

	    RequiresUpload = true;

	    ClearUICache();
	}
	private HEU_InputObjectInfo InternalAddInputObjectAtEnd(GameObject newInputGameObject)
	{
	    HEU_InputObjectInfo inputObject = CreateInputObjectInfo(newInputGameObject);
	    _inputObjects.Add(inputObject);
	    return inputObject;
	}
	public void UploadInput(HEU_SessionBase session)
	{
	    if (_nodeID == HEU_Defines.HEU_INVALID_NODE_ID)
	    {
		Debug.LogErrorFormat("Input Node ID is invalid. Unable to upload input. Try recooking.");
		return;
	    }

	    if (_pendingInputObjectType != _inputObjectType)
	    {
		ChangeInputType(session, _pendingInputObjectType);
	    }

	    if (_inputObjectType == InputObjectType.UNITY_MESH)
	    {
		// Connect regular gameobjects

		if (_inputObjects == null || _inputObjects.Count == 0)
		{
		    DisconnectAndDestroyInputs(session);
		}
		else
		{
		    DisconnectAndDestroyInputs(session);

		    List<HEU_InputObjectInfo> inputObjectClone = new List<HEU_InputObjectInfo>(_inputObjects);

		    // Special input interface preprocessing
		    for (int i = inputObjectClone.Count - 1; i >= 0; i--)
		    {
			if (inputObjectClone[i] == null || inputObjectClone[i]._gameObject == null)
			{
			    continue;
			}

			HEU_BoundingVolume boundingVolume = inputObjectClone[i]._gameObject.GetComponent<HEU_BoundingVolume>();
			if (boundingVolume == null)
			{
			    continue;
			}

			List<GameObject> boundingBoxObjects = boundingVolume.GetAllIntersectingObjects();
			if (boundingBoxObjects == null)
			{
			    continue;
			}

			foreach (GameObject obj in boundingBoxObjects)
			{
			    if (obj == null)
			    {
				continue;
			    }

			    HEU_InputObjectInfo newObjInfo = new HEU_InputObjectInfo();
			    inputObjectClone[i].CopyTo(newObjInfo);
			    newObjInfo._gameObject = obj;
			    inputObjectClone.Add(newObjInfo);
			}

			// Remove this because it's not a real interface
			inputObjectClone.RemoveAt(i);

		    }

		    // Create merge object, and input nodes with data, then connect them to the merge object
		    bool bResult = HEU_InputUtility.CreateInputNodeWithMultiObjects(session, _nodeID, ref _connectedNodeID, ref inputObjectClone, ref _inputObjectsConnectedAssetIDs, _keepWorldTransform);
		    if (!bResult)
		    {
			DisconnectAndDestroyInputs(session);
			return;
		    }

		    // Now connect from this asset to the merge object
		    ConnectToMergeObject(session);

		    if (!UploadObjectMergeTransformType(session))
		    {
			Debug.LogErrorFormat("Failed to upload object merge transform type!");
			return;
		    }

		    if (!UploadObjectMergePackGeometry(session))
		    {
			Debug.LogErrorFormat("Failed to upload object merge pack geometry value!");
			return;
		    }
		}
	    }
	    else if (_inputObjectType == InputObjectType.HDA)
	    {
		// Connect HDAs

		// First clear all previous input connections
		DisconnectAndDestroyInputs(session);

		// Create merge object, and connect all input HDAs
		bool bResult = HEU_InputUtility.CreateInputNodeWithMultiAssets(session, _parentAsset, ref _connectedNodeID, ref _inputAssetInfos, _keepWorldTransform, -1);
		if (!bResult)
		{
		    DisconnectAndDestroyInputs(session);
		    return;
		}

		// Now connect from this asset to the merge object
		ConnectToMergeObject(session);

		if (!UploadObjectMergeTransformType(session))
		{
		    Debug.LogErrorFormat("Failed to upload object merge transform type!");
		    return;
		}

		if (!UploadObjectMergePackGeometry(session))
		{
		    Debug.LogErrorFormat("Failed to upload object merge pack geometry value!");
		    return;
		}
	    }
	    //else if (_inputObjectType == InputObjectType.CURVE)
	    //{
	    // TODO INPUT NODE - create new Curve SOP (add HEU_Curve here?)
	    //}
	    else
	    {
		Debug.LogErrorFormat("Unsupported input type {0}. Unable to upload input.", _inputObjectType);
	    }

	    RequiresUpload = false;
	    RequiresCook = true;

	    ClearUICache();
	}
Exemple #10
0
		public static void ExecuteToolOperatorMultiple(string toolName, string toolPath, GameObject[] inputObjects)
		{
			GameObject outputObjectToSelect = null;

			GameObject go = HEU_HAPIUtility.InstantiateHDA(toolPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), false);
			if(go == null)
			{
				Debug.LogWarningFormat("Failed to instantiate tool: {0}", toolName);
				return;
			}

			HEU_HoudiniAssetRoot assetRoot = go.GetComponent<HEU_HoudiniAssetRoot>();
			if (assetRoot != null)
			{
				HEU_HoudiniAsset asset = assetRoot._houdiniAsset;
				HEU_SessionBase session = asset.GetAssetSession(true);

				int numInputs = inputObjects.Length;

				List<HEU_InputNode> inputNodes = asset.GetInputNodes();
				if (inputNodes == null || inputNodes.Count == 0)
				{
					Debug.LogErrorFormat("Unable to assign input geometry due to no asset inputs on selected tool.");
				}
				else
				{
					// User could have selected any number of inputs objects, and asset could have any number of inputs.
					// So use minimum of either to set input object into asset input.
					int minInputCount = Mathf.Min(inputNodes.Count, numInputs);
					for (int i = 0; i < minInputCount; ++i)
					{
						if (!IsValidInput(inputObjects[i]))
						{
							continue;
						}
						GameObject inputObject = inputObjects[i];

						HEU_InputNode inputNode = inputNodes[i];
						inputNode.ResetInputNode(session);

						inputNode.ChangeInputType(session, HEU_InputNode.InputObjectType.UNITY_MESH);

						HEU_InputObjectInfo inputInfo = inputNode.AddInputEntryAtEnd(inputObject);
						inputInfo._useTransformOffset = false;
						inputNode.KeepWorldTransform = true;
						inputNode.PackGeometryBeforeMerging = false;

						inputNode.RequiresUpload = true;
					}

					asset.RequestCook(true, true, true, true);

					outputObjectToSelect = assetRoot.gameObject;
				}
			}

			if (outputObjectToSelect != null)
			{
				HEU_EditorUtility.SelectObject(outputObjectToSelect);
			}
		}
Exemple #11
0
		public static void ExecuteToolOperatorSingle(string toolName, string toolPath, GameObject[] inputObjects)
		{
			// Single operator means single asset input. If multiple inputs are provided, create tool for each input.

			List<GameObject> outputObjectsToSelect = new List<GameObject>();

			int numInputs = inputObjects.Length;
			for (int i = 0; i < numInputs; ++i)
			{
				if(!IsValidInput(inputObjects[i]))
				{
					continue;
				}
				GameObject inputObject = inputObjects[i];

				GameObject go = HEU_HAPIUtility.InstantiateHDA(toolPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), false);
				if (go != null)
				{
					HEU_HoudiniAssetRoot assetRoot = go.GetComponent<HEU_HoudiniAssetRoot>();
					if (assetRoot != null)
					{
						HEU_HoudiniAsset asset = assetRoot._houdiniAsset;
						HEU_SessionBase session = asset.GetAssetSession(true);

						List<HEU_InputNode> inputNodes = asset.GetInputNodes();
						if (inputNodes == null || inputNodes.Count == 0)
						{
							Debug.LogErrorFormat("Unable to assign input geometry due to no asset inputs on selected tool.");
						}
						else
						{
							HEU_InputNode inputNode = inputNodes[0];

							inputNode.ResetInputNode(session);

							inputNode.ChangeInputType(session, HEU_InputNode.InputObjectType.UNITY_MESH);

							HEU_InputObjectInfo inputInfo = inputNode.AddInputEntryAtEnd(inputObject);
							inputInfo._useTransformOffset = false;
							inputNode.KeepWorldTransform = true;
							inputNode.PackGeometryBeforeMerging = false;

							inputNode.RequiresUpload = true;

							asset.RequestCook(true, true, true, true);

							outputObjectsToSelect.Add(assetRoot.gameObject);
						}
					}
				}
				else
				{
					Debug.LogWarningFormat("Failed to instantiate tool: {0}", toolName);
				}
			}

			if (outputObjectsToSelect.Count > 0)
			{
				HEU_EditorUtility.SelectObjects(outputObjectsToSelect.ToArray());
			}
		}
Exemple #12
0
		public void LoadPreset(HEU_SessionBase session, HEU_InputPreset inputPreset)
		{
			ResetInputNode(session);

			ChangeInputType(session, inputPreset._inputObjectType);

			if (inputPreset._inputObjectType == HEU_InputNode.InputObjectType.UNITY_MESH)
			{
				int numObjects = inputPreset._inputObjectPresets.Count;
				for (int i = 0; i < numObjects; ++i)
				{
					if (!string.IsNullOrEmpty(inputPreset._inputObjectPresets[i]._gameObjectName))
					{
						GameObject inputGO = null;
						if (inputPreset._inputObjectPresets[i]._isSceneObject)
						{
							inputGO = HEU_GeneralUtility.GetGameObjectByNameInScene(inputPreset._inputObjectPresets[i]._gameObjectName);
						}
						else
						{
							// Use the _gameObjectName as path to find in scene
							inputGO = HEU_AssetDatabase.LoadAssetAtPath(inputPreset._inputObjectPresets[i]._gameObjectName, typeof(GameObject)) as GameObject;
							if(inputGO == null)
							{
								Debug.LogErrorFormat("Unable to find input at {0}", inputPreset._inputObjectPresets[i]._gameObjectName);
							}
						}

						if (inputGO != null)
						{
							HEU_InputObjectInfo inputObject = AddInputObjectAtEnd(inputGO);
							inputObject._useTransformOffset = inputPreset._inputObjectPresets[i]._useTransformOffset;
							inputObject._translateOffset = inputPreset._inputObjectPresets[i]._translateOffset;
							inputObject._rotateOffset = inputPreset._inputObjectPresets[i]._rotateOffset;
							inputObject._scaleOffset = inputPreset._inputObjectPresets[i]._scaleOffset;
						}
						else
						{
							Debug.LogWarningFormat("Gameobject with name {0} not found. Unable to set input object.", inputPreset._inputAssetName);
						}
					}
				}
			}
			else if (inputPreset._inputObjectType == HEU_InputNode.InputObjectType.HDA)
			{
				if (!string.IsNullOrEmpty(inputPreset._inputAssetName))
				{
					GameObject inputAsset = GameObject.Find(inputPreset._inputAssetName);
					if (inputAsset != null)
					{
						HEU_HoudiniAssetRoot inputAssetRoot = inputAsset != null ? inputAsset.GetComponent<HEU_HoudiniAssetRoot>() : null;
						if (inputAssetRoot != null && inputAssetRoot._houdiniAsset != null)
						{
							// Need to reconnect and make sure connected asset is in this session

							_inputAsset = inputAsset;

							if (!inputAssetRoot._houdiniAsset.IsAssetValidInHoudini(session))
							{
								inputAssetRoot._houdiniAsset.RequestCook(true, false, true, true);
							}

							_connectedNodeID = inputAssetRoot._houdiniAsset.AssetID;

							_parentAsset.ConnectToUpstream(inputAssetRoot._houdiniAsset);

							_connectedInputAsset = _inputAsset;
						}
						else
						{
							Debug.LogErrorFormat("Input HDA with name {0} is not a valid asset (missing components). Unable to set input asset.", inputPreset._inputAssetName);
						}
					}
					else
					{
						Debug.LogWarningFormat("Game with name {0} not found. Unable to set input asset.", inputPreset._inputAssetName);
					}
				}
			}

			KeepWorldTransform = inputPreset._keepWorldTransform;
			PackGeometryBeforeMerging = inputPreset._packGeometryBeforeMerging;

			RequiresUpload = true;

			ClearUICache();
		}
Exemple #13
0
		public HEU_InputObjectInfo AddInputObjectAtEnd(GameObject newInputGameObject)
		{
			HEU_InputObjectInfo inputObject = CreateInputObjectInfo(newInputGameObject);
			_inputObjects.Add(inputObject);
			return inputObject;
		}