예제 #1
0
        private static void ProcessDragEvent(Event dragEvent, SceneView sceneView)
        {
            if (dragEvent != null && (dragEvent.type == EventType.DragUpdated || dragEvent.type == EventType.DragPerform))
            {
                bool          dragHDAs = false;
                List <string> hdaList  = new List <string>();
                foreach (string file in DragAndDrop.paths)
                {
                    if (HEU_HAPIUtility.IsHoudiniAssetFile(file))
                    {
                        dragHDAs = true;
                        DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                        hdaList.Add(file);
                        break;
                    }
                }

                if (dragHDAs)
                {
                    if (dragEvent.type == EventType.DragPerform)
                    {
                        if (HEU_SessionManager.ValidatePluginSession())
                        {
                            Vector3 dropPos = Vector3.zero;
                            if (sceneView != null)
                            {
                                Camera  camera   = sceneView.camera;
                                Vector3 mousePos = HEU_EditorUI.GetMousePosition(ref dragEvent, camera);

                                Ray ray = camera.ScreenPointToRay(mousePos);
                                ray.origin = camera.transform.position;
                                Plane plane = new Plane();
                                plane.SetNormalAndPosition(Vector3.up, Vector3.zero);
                                float enter = 0f;
                                plane.Raycast(ray, out enter);
                                enter   = Mathf.Clamp(enter, camera.nearClipPlane, camera.farClipPlane);
                                dropPos = ray.origin + ray.direction * enter;
                            }

                            List <GameObject> createdGOs = new List <GameObject>();
                            foreach (string file in hdaList)
                            {
                                GameObject go = HEU_HAPIUtility.InstantiateHDA(file, dropPos, HEU_SessionManager.GetOrCreateDefaultSession(), true);
                                if (go != null)
                                {
                                    createdGOs.Add(go);
                                }
                            }

                            // Select the created assets
                            HEU_EditorUtility.SelectObjects(createdGOs.ToArray());
                        }
                    }

                    dragEvent.Use();
                }
            }
        }
예제 #2
0
		public static void ExecuteToolNoInput(string toolName, string toolPath)
		{
			GameObject go = HEU_HAPIUtility.InstantiateHDA(toolPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), false);
			if (go == null)
			{
				Debug.LogWarningFormat("Failed to instantiate tool: {0}", toolName);
			}
			else
			{
				HEU_EditorUtility.SelectObject(go);
			}
		}
		private static void LoadHoudiniAssetFromPath(string hdaPath)
		{
			if (!string.IsNullOrEmpty(hdaPath))
			{
				// Store HDA path for next time
				HEU_PluginSettings.LastLoadHDAPath = Path.GetDirectoryName(hdaPath);

				GameObject go = HEU_HAPIUtility.InstantiateHDA(hdaPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), true);
				if (go != null)
				{
					HEU_EditorUtility.SelectObject(go);
				}
			}
		}
예제 #4
0
		public static void ExecuteToolGenerator(string toolName, string toolPath, Vector3 targetPosition, Quaternion targetRotation, Vector3 targetScale)
		{
			GameObject go = HEU_HAPIUtility.InstantiateHDA(toolPath, targetPosition, HEU_SessionManager.GetOrCreateDefaultSession(), true);
			if (go != null)
			{
				go.transform.rotation = targetRotation;
				go.transform.localScale = targetScale;

				HEU_EditorUtility.SelectObject(go);
			}
			else
			{
				Debug.LogWarningFormat("Failed to instantiate tool: {0}", toolName);
			}
		}
예제 #5
0
		public static void LoadHoudiniAssetWindow()
		{
			if (HEU_SessionManager.ValidatePluginSession())
			{
				string[] extensions = { "HDAs", "otl,hda,otllc,hdalc,otlnc,hdanc" };
				string hdaPath = EditorUtility.OpenFilePanelWithFilters("Load Houdini Digital Asset", HEU_PluginSettings.LastLoadHDAPath, extensions);
				if (!string.IsNullOrEmpty(hdaPath))
				{
					// Store HDA path for next time
					HEU_PluginSettings.LastLoadHDAPath = Path.GetDirectoryName(hdaPath);

					GameObject go = HEU_HAPIUtility.InstantiateHDA(hdaPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), true);
					if (go != null)
					{
						HEU_EditorUtility.SelectObject(go);
					}
				}
			}
		}
예제 #6
0
		public static void ExecuteToolOperatorSingle(string toolName, string toolPath, GameObject[] inputObjects)
		{
			GameObject go = HEU_HAPIUtility.InstantiateHDA(toolPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), true);
			if (go != null)
			{
				HEU_HoudiniAssetRoot assetRoot = go.GetComponent<HEU_HoudiniAssetRoot>();
				if (assetRoot != null)
				{
					//assetRoot._houdiniAsset
					// TODO
				}

				HEU_EditorUtility.SelectObject(go);
			}
			else
			{
				Debug.LogWarningFormat("Failed to instantiate tool: {0}", toolName);
			}
		}
예제 #7
0
	public override void DoTask()
	{
	    if (_buildType == BuildType.LOAD)
	    {
		if (string.IsNullOrEmpty(_assetPath))
		{
		    // Bad path so fail		
		    HEU_TaskManager.CompleteTask(this, TaskResult.FAILED);
		}
		else
		{
		    // File-based HDA
		    GameObject newGO = HEU_HAPIUtility.InstantiateHDA(_assetPath, _position, GetTaskSession(), true);
		    if (newGO != null && newGO.GetComponent<HEU_HoudiniAssetRoot>() != null)
		    {
			// Add to post-load callback
			_asset = newGO.GetComponent<HEU_HoudiniAssetRoot>()._houdiniAsset;
			_asset._reloadEvent.AddListener(CookCompletedCallback);
			_asset._reloadDataEvent.AddListener(CookCompletedCallback);
		    }
		    else
		    {
			HEU_TaskManager.CompleteTask(this, TaskResult.FAILED);
		    }
		}
	    }
	    else if (_buildType == BuildType.COOK)
	    {
		_asset._cookedEvent.RemoveListener(CookCompletedCallback);
		_asset._cookedEvent.AddListener(CookCompletedCallback);
		_asset._cookedDataEvent.RemoveListener(CookCompletedCallback);
		_asset._cookedDataEvent.AddListener(CookCompletedCallback);
		_asset.RequestCook(true, true, false, true);
	    }
	    else if (_buildType == BuildType.RELOAD)
	    {
		_asset._reloadEvent.RemoveListener(CookCompletedCallback);
		_asset._reloadEvent.AddListener(CookCompletedCallback);
		_asset._reloadDataEvent.RemoveListener(CookCompletedCallback);
		_asset._reloadDataEvent.AddListener(CookCompletedCallback);
		_asset.RequestReload(true);
	    }
	}
예제 #8
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);
			}
		}
예제 #9
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());
			}
		}
        public void TriggerButton(GraphReference reference)
        {
            Flow    flow        = Flow.New(reference);
            string  hdaPath     = flow.GetValue <string>(inputPath);
            bool    hdaAsync    = flow.GetValue <bool>(inputAsync);
            Vector3 hdaPosition = flow.GetValue <Vector3>(inputPosition);

            System.Action ContinueFlow = () =>
            {
                flow.Invoke(trigger);
            };

            bool hasErrored = false;

            try
            {
                HEU_SessionBase session = HEU_SessionManager.GetOrCreateDefaultSession(true);
                if (session != null)
                {
                    GameObject go = HEU_HAPIUtility.InstantiateHDA(hdaPath, hdaPosition, session, bBuildAsync: hdaAsync);

                    hdaRoot = go.GetComponent <HEU_HoudiniAssetRoot>();

                    if (hdaRoot != null)
                    {
                        hdaAsset = hdaRoot.HoudiniAsset;
                        if (hdaAsync)
                        {
                            hdaAsset.ReloadDataEvent.AddListener((HEU_ReloadEventData data) =>
                            {
                                bSuccess = data.CookSuccess;
                                ContinueFlow();
                            });
                        }
                        else
                        {
                            bSuccess = hdaAsset.LastCookResult != HEU_AssetCookResultWrapper.ERRORED;
                        }
                    }
                    else
                    {
                        hasErrored = true;
                    }
                }
                else
                {
                    hasErrored = true;
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
                hasErrored = true;
            }


            if (hasErrored)
            {
                bSuccess = false;
                ContinueFlow();
            }
            else if (!hdaAsync)
            {
                ContinueFlow();
            }
        }