private void NotifyTOPNodePDGStateClear(HEU_PDGAssetLink assetLink, HEU_TOPNodeData topNode) { //Debug.LogFormat("NotifyTOPNodePDGStateClear:: {0}", topNode._nodeName); topNode._pdgState = HEU_TOPNodeData.PDGState.NONE; topNode._workItemTally.ZeroAll(); assetLink.RepaintUI(); }
public void UpdateTOPNodeResultsVisibility(HEU_TOPNodeData topNode) { if (topNode._workResultParentGO != null) { topNode._workResultParentGO.SetActive(topNode._showResults); } }
public string GetTOPNodeStatus(HEU_TOPNodeData topNode) { if (topNode._pdgState == HEU_TOPNodeData.PDGState.COOK_FAILED || topNode.AnyWorkItemsFailed()) { return "Cook Failed"; } else if(topNode._pdgState == HEU_TOPNodeData.PDGState.COOK_COMPLETE) { return "Cook Completed"; } else if (topNode._pdgState == HEU_TOPNodeData.PDGState.COOKING) { return "Cook In Progress"; } else if (topNode._pdgState == HEU_TOPNodeData.PDGState.DIRTIED) { return "Dirtied"; } else if (topNode._pdgState == HEU_TOPNodeData.PDGState.DIRTYING) { return "Dirtying"; } return ""; }
/// <summary> /// Cook the specified TOP node. /// </summary> /// <param name="topNode"></param> public void CookTOPNode(HEU_TOPNodeData topNode) { HEU_PDGSession pdgSession = HEU_PDGSession.GetPDGSession(); if (pdgSession != null) { pdgSession.CookTOPNode(topNode._nodeID); } }
private void CheckCallback(HEU_TOPNodeData topNode) { if (_cookedDataEvent != null && _pendingCallback && _numItemsCompleted >= _totalNumItems) { _cookedDataEvent.Invoke(new HEU_PDGCookedEventData(_callbackSuccess, topNode)); ResetCallbackVariables(); } }
/// <summary> /// Dirty the specified TOP node and clear its work item results. /// </summary> /// <param name="topNode"></param> public void DirtyTOPNode(HEU_TOPNodeData topNode) { HEU_PDGSession pdgSession = HEU_PDGSession.GetPDGSession(); if (pdgSession != null && pdgSession.DirtyTOPNode(topNode._nodeID)) { ClearTOPNodeWorkItemResults(topNode); } }
private static void ClearWorkItemResult(HEU_TOPNodeData topNode, HEU_TOPWorkResult result) { if (result != null) { DestroyWorkItemResultData(topNode, result); topNode._workResults.Remove(result); } }
private void SetTOPNodePDGState(HEU_PDGAssetLink assetLink, HEU_TOPNodeData topNode, HEU_TOPNodeData.PDGState pdgState) { topNode._pdgState = pdgState; assetLink.RepaintUI(); if (_cookedDataEvent != null && (pdgState == HEU_TOPNodeData.PDGState.COOK_COMPLETE || pdgState == HEU_TOPNodeData.PDGState.COOK_FAILED)) { bool bSuccess = pdgState == HEU_TOPNodeData.PDGState.COOK_COMPLETE; _callbackSuccess &= bSuccess; _pendingCallback = true; } }
public void CookTOPNode(HEU_TOPNodeData topNode) { HEU_SessionBase session = GetHAPISession(); if (session == null || !session.IsSessionValid()) { return; } if (!session.CookPDG(topNode._nodeID, 0, 0)) { Debug.LogErrorFormat("Cook node failed!"); } }
private static HEU_TOPWorkResult GetWorkResultByID(HEU_TOPNodeData topNode, HAPI_PDG_WorkitemId workItemID) { HEU_TOPWorkResult result = null; foreach (HEU_TOPWorkResult res in topNode._workResults) { if (res._workItemID == workItemID) { result = res; break; } } return result; }
private static HEU_TOPWorkResult GetWorkResultByIndex(HEU_TOPNodeData topNode, int workItemIndex) { HEU_TOPWorkResult result = null; foreach (HEU_TOPWorkResult res in topNode._workResults) { if (res._workItemIndex == workItemIndex) { result = res; break; } } return result; }
public static void ClearTOPNodeWorkItemResults(HEU_TOPNodeData topNode) { int numResults = topNode._workResults.Count; for (int i = 0; i < numResults; ++i) { DestroyWorkItemResultData(topNode, topNode._workResults[i]); } topNode._workResults.Clear(); if (topNode._workResultParentGO != null) { HEU_GeneralUtility.DestroyImmediate(topNode._workResultParentGO); } }
public void DirtyTOPNode(HEU_TOPNodeData topNode) { HEU_SessionBase session = GetHAPISession(); if (session == null || !session.IsSessionValid()) { return; } if (!session.DirtyPDGNode(topNode._nodeID, true)) { Debug.LogErrorFormat("Dirty node failed!"); return; } ClearTOPNodeWorkItemResults(topNode); }
private static void DestroyWorkItemResultData(HEU_TOPNodeData topNode, HEU_TOPWorkResult result) { if (result._generatedGOs != null) { int numGOs = result._generatedGOs.Count; for (int i = 0; i < numGOs; ++i) { HEU_GeoSync geoSync = result._generatedGOs[i].GetComponent<HEU_GeoSync>(); if (geoSync != null) { geoSync.Unload(); } //Debug.LogFormat("Destroy result: " + result._generatedGOs[i].name); HEU_GeneralUtility.DestroyImmediate(result._generatedGOs[i]); result._generatedGOs[i] = null; } result._generatedGOs.Clear(); } }
/// <summary> /// Given TOP nodes from a TOP network, populate internal state from each TOP node. /// </summary> /// <param name="session">Houdini Engine session</param> /// <param name="topNetwork">TOP network to query TOP nodes from</param> /// <param name="topNodeIDs">List of TOP nodes in the TOP network</param> /// <param name="useHEngineData">Whether or not to use HEngine data for filtering</param> /// <returns>True if successfully populated data</returns> public static bool PopulateTOPNodes(HEU_SessionBase session, HEU_TOPNetworkData topNetwork, HAPI_NodeId[] topNodeIDs, bool useHEngineData) { // Holds list of found TOP nodes List<HEU_TOPNodeData> newNodes = new List<HEU_TOPNodeData>(); foreach (HAPI_NodeId topNodeID in topNodeIDs) { // Not necessary. Blocks main thread. //session.CookNode(childNodeID, HEU_PluginSettings.CookTemplatedGeos); HAPI_NodeInfo childNodeInfo = new HAPI_NodeInfo(); if (!session.GetNodeInfo(topNodeID, ref childNodeInfo)) { return false; } string nodeName = HEU_SessionManager.GetString(childNodeInfo.nameSH, session); //Debug.LogFormat("TOP Node: name={0}, type={1}", nodeName, childNodeInfo.type); TOPNodeTags tags = new TOPNodeTags(); if (useHEngineData) { ParseHEngineData(session, topNodeID, ref childNodeInfo, ref tags); if (!tags._show) { continue; } } else { tags._show = true; } HEU_TOPNodeData topNodeData = GetTOPNodeByName(nodeName, topNetwork._topNodes); if (topNodeData == null) { topNodeData = new HEU_TOPNodeData(); } else { topNetwork._topNodes.Remove(topNodeData); } newNodes.Add(topNodeData); //topNodeData.Reset(); topNodeData._nodeID = topNodeID; topNodeData._nodeName = nodeName; topNodeData._parentName = topNetwork._parentName + "_" + topNetwork._nodeName; topNodeData._tags = tags; } // Clear old unused TOP nodes for (int i = 0; i < topNetwork._topNodes.Count; ++i) { ClearTOPNodeWorkItemResults(topNetwork._topNodes[i]); } topNetwork._topNodes = newNodes; // Get list of updated TOP node names topNetwork._topNodeNames = new string[topNetwork._topNodes.Count]; for (int i = 0; i < topNetwork._topNodes.Count; ++i) { topNetwork._topNodeNames[i] = topNetwork._topNodes[i]._nodeName; } return true; }
/// <summary> /// Displays a dropdown list of TOP nodes, and shows the selected TOP node info /// </summary> private void DrawSelectedTOPNode() { HEU_TOPNetworkData topNetworkData = _assetLink.GetSelectedTOPNetwork(); if (topNetworkData == null) { return; } using (new EditorGUILayout.VerticalScope(_backgroundStyle)) { int numTopNodes = topNetworkData._topNodeNames.Length; if (numTopNodes > 0) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel(_topNodeChooseLabel); int selectedIndex = Mathf.Clamp(topNetworkData._selectedTOPIndex, 0, numTopNodes); int newSelectedIndex = EditorGUILayout.Popup(selectedIndex, topNetworkData._topNodeNames); if (newSelectedIndex != selectedIndex) { _assetLink.SelectTOPNode(topNetworkData, newSelectedIndex); } } } else { EditorGUILayout.PrefixLabel(_topNodeNoneLabel); } EditorGUILayout.Space(); HEU_TOPNodeData topNode = _assetLink.GetSelectedTOPNode(); if (topNode != null) { topNode._tags._autoload = EditorGUILayout.Toggle(_autoloadContent, topNode._tags._autoload); bool showResults = topNode._showResults; showResults = EditorGUILayout.Toggle(_showHideResultsContent, showResults); if (showResults != topNode._showResults) { topNode._showResults = showResults; _assetLink.UpdateTOPNodeResultsVisibility(topNode); } EditorGUILayout.Space(); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button(_buttonDirtyContent)) { _assetLink.DirtyTOPNode(topNode); } if (GUILayout.Button(_buttonCookContent)) { _assetLink.CookTOPNode(topNode); } } EditorGUILayout.Space(); using (new EditorGUILayout.VerticalScope(HEU_EditorUI.GetSectionStyle())) { EditorGUILayout.LabelField("TOP Node State: " + _assetLink.GetTOPNodeStatus(topNode)); EditorGUILayout.Space(); EditorGUILayout.LabelField(_topNodeStatusLabel); DrawWorkItemTally(topNode._workItemTally); } } } }
public void ClearWorkItemResult(HEU_SessionBase session, HAPI_PDG_GraphContextId contextID, HAPI_PDG_EventInfo eventInfo, HEU_TOPNodeData topNode) { session.LogErrorOverride = false; bool bCleared = false; HAPI_PDG_WorkitemInfo workItemInfo = new HAPI_PDG_WorkitemInfo(); if (session.GetWorkItemInfo(contextID, eventInfo.workitemId, ref workItemInfo)) { //Debug.LogFormat("Clear: index={0}, state={1}", workItemInfo.index, (HAPI_PDG_WorkitemState)eventInfo.currentState); if (workItemInfo.index >= 0) { HEU_PDGAssetLink.ClearWorkItemResultByIndex(topNode, workItemInfo.index); bCleared = true; } } if (!bCleared) { HEU_PDGAssetLink.ClearWorkItemResultByID(topNode, eventInfo.workitemId); } session.LogErrorOverride = true; }
private void NotifyTOPNodeCookingWorkItem(HEU_PDGAssetLink assetLink, HEU_TOPNodeData topNode, int inc) { topNode._workItemTally._cookingWorkItems = Mathf.Max(topNode._workItemTally._cookingWorkItems + inc, 0); assetLink.RepaintUI(); }
private void NotifyTOPNodeErrorWorkItem(HEU_PDGAssetLink assetLink, HEU_TOPNodeData topNode) { topNode._workItemTally._erroredWorkItems++; assetLink.RepaintUI(); }
/// <summary> /// Clear all work items' results of the specified TOP node. This destroys any loaded results (geometry etc). /// </summary> /// <param name="session"></param> /// <param name="contextID"></param> /// <param name="eventInfo"></param> /// <param name="topNode"></param> public void ClearWorkItemResult(HEU_SessionBase session, HAPI_PDG_GraphContextId contextID, HAPI_PDG_EventInfo eventInfo, HEU_TOPNodeData topNode) { #if HOUDINIENGINEUNITY_ENABLED session.LogErrorOverride = false; HEU_PDGAssetLink.ClearWorkItemResultByID(topNode, eventInfo.workitemId); session.LogErrorOverride = true; #endif }
/// <summary> /// Process a PDG event. Notify the relevant HEU_PDGAssetLink object. /// </summary> /// <param name="session">Houdini Engine session</param> /// <param name="contextID">PDG graph context ID</param> /// <param name="eventInfo">PDG event info</param> private void ProcessPDGEvent(HEU_SessionBase session, HAPI_PDG_GraphContextId contextID, ref HAPI_PDG_EventInfo eventInfo) { #if HOUDINIENGINEUNITY_ENABLED HEU_PDGAssetLink assetLink = null; HEU_TOPNodeData topNode = null; HAPI_PDG_EventType evType = (HAPI_PDG_EventType)eventInfo.eventType; HAPI_PDG_WorkitemState currentState = (HAPI_PDG_WorkitemState)eventInfo.currentState; HAPI_PDG_WorkitemState lastState = (HAPI_PDG_WorkitemState)eventInfo.lastState; GetTOPAssetLinkAndNode(eventInfo.nodeId, out assetLink, out topNode); //string topNodeName = topNode != null ? string.Format("node={0}", topNode._nodeName) : string.Format("id={0}", eventInfo.nodeId); //HEU_Logger.LogFormat("PDG Event: {0}, type={1}, workitem={2}, curState={3}, lastState={4}", topNodeName, evType.ToString(), // eventInfo.workitemId, currentState, lastState); if (assetLink == null || topNode == null || topNode._nodeID != eventInfo.nodeId) { return; } EventMessageColor msgColor = EventMessageColor.DEFAULT; // Events can be split into TOP node specific or work item specific if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_NULL) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.NONE); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_NODE_CLEAR) { NotifyTOPNodePDGStateClear(assetLink, topNode); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_DIRTY_START) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.DIRTYING); //HEU_PDGAssetLink.ClearTOPNodeWorkItemResults(topNode); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_DIRTY_STOP) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.DIRTIED); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_COOK_ERROR) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOK_FAILED); msgColor = EventMessageColor.ERROR; } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_COOK_WARNING) { msgColor = EventMessageColor.WARNING; } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_COOK_COMPLETE) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOK_COMPLETE); } else { // Work item events HEU_TOPNodeData.PDGState currentTOPPDGState = topNode._pdgState; if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_WORKITEM_ADD) { _totalNumItems++; NotifyTOPNodeTotalWorkItem(assetLink, topNode, 1); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_WORKITEM_REMOVE) { NotifyTOPNodeTotalWorkItem(assetLink, topNode, -1); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_WORKITEM_STATE_CHANGE) { // Last states if (lastState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_WAITING && currentState != HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_WAITING) { NotifyTOPNodeWaitingWorkItem(assetLink, topNode, -1); } else if (lastState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKING && currentState != HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKING) { NotifyTOPNodeCookingWorkItem(assetLink, topNode, -1); } else if (lastState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_SCHEDULED && currentState != HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_SCHEDULED) { NotifyTOPNodeScheduledWorkItem(assetLink, topNode, -1); } // New states if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_WAITING) { NotifyTOPNodeWaitingWorkItem(assetLink, topNode, 1); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_UNCOOKED) { } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_DIRTY) { //HEU_Logger.LogFormat("Dirty: id={0}", eventInfo.workitemId); ClearWorkItemResult(session, contextID, eventInfo, topNode); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_SCHEDULED) { NotifyTOPNodeScheduledWorkItem(assetLink, topNode, 1); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKING) { NotifyTOPNodeCookingWorkItem(assetLink, topNode, 1); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKED_SUCCESS || currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKED_CACHE) { NotifyTOPNodeCookedWorkItem(assetLink, topNode); // On cook success, handle results if (topNode._tags._autoload) { HAPI_PDG_WorkitemInfo workItemInfo = new HAPI_PDG_WorkitemInfo(); if (!session.GetWorkItemInfo(contextID, eventInfo.workitemId, ref workItemInfo)) { HEU_Logger.LogErrorFormat("Failed to get work item {1} info for {0}", topNode._nodeName, eventInfo.workitemId); return; } if (workItemInfo.numResults > 0) { HAPI_PDG_WorkitemResultInfo[] resultInfos = new HAPI_PDG_WorkitemResultInfo[workItemInfo.numResults]; int resultCount = workItemInfo.numResults; if (!session.GetWorkitemResultInfo(topNode._nodeID, eventInfo.workitemId, resultInfos, resultCount)) { HEU_Logger.LogErrorFormat("Failed to get work item {1} result info for {0}", topNode._nodeName, eventInfo.workitemId); return; } assetLink.LoadResults(session, topNode, workItemInfo, resultInfos, eventInfo.workitemId, OnWorkItemLoadResults); } } } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKED_FAIL) { // TODO: on cook failure, get log path? NotifyTOPNodeErrorWorkItem(assetLink, topNode); msgColor = EventMessageColor.ERROR; } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKED_CANCEL) { // Ignore it because in-progress cooks can be cancelled when automatically recooking graph } } if (currentTOPPDGState == HEU_TOPNodeData.PDGState.COOKING) { if (topNode.AreAllWorkItemsComplete()) { if (topNode.AnyWorkItemsFailed()) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOK_FAILED); } else { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOK_COMPLETE); } } } else if (topNode.AnyWorkItemsPending()) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOKING); } } if (eventInfo.msgSH >= 0) { string eventMsg = HEU_SessionManager.GetString(eventInfo.msgSH, session); if (!string.IsNullOrEmpty(eventMsg)) { AddEventMessage(string.Format("<color={0}>{1} - {2}: {3}</color>\n", _eventMessageColorCode[(int)msgColor], evType, topNode._nodeName, eventMsg)); } } CheckCallback(topNode); #endif }
private void OnWorkItemLoadResults(HEU_TOPNodeData topNode, HEU_SyncedEventData OnSynced) { _numItemsCompleted++; CheckCallback(topNode); }
public static void ClearWorkItemResultByID(HEU_TOPNodeData topNode, HAPI_PDG_WorkitemId workItemID) { HEU_TOPWorkResult result = GetWorkResultByID(topNode, workItemID); ClearWorkItemResult(topNode, result); }
private void SetTOPNodePDGState(HEU_PDGAssetLink assetLink, HEU_TOPNodeData topNode, HEU_TOPNodeData.PDGState pdgState) { topNode._pdgState = pdgState; assetLink.RepaintUI(); }
private bool GetTOPAssetLinkAndNode(HAPI_NodeId nodeID, out HEU_PDGAssetLink assetLink, out HEU_TOPNodeData topNode) { assetLink = null; topNode = null; int numAssets = _pdgAssets.Count; for (int i = 0; i < numAssets; ++i) { topNode = _pdgAssets[i].GetTOPNode(nodeID); if (topNode != null) { assetLink = _pdgAssets[i]; return(true); } } return(false); }
public static void ClearWorkItemResultByIndex(HEU_TOPNodeData topNode, int workItemIndex) { HEU_TOPWorkResult result = GetWorkResultByIndex(topNode, workItemIndex); ClearWorkItemResult(topNode, result); }
/// <summary> /// Displays a dropdown list of TOP nodes, and shows the selected TOP node info /// </summary> private void DrawSelectedTOPNode() { HEU_TOPNetworkData topNetworkData = _assetLink.GetSelectedTOPNetwork(); if (topNetworkData == null) { return; } using (new EditorGUILayout.VerticalScope(_backgroundStyle)) { List<KeyValuePair<int, HEU_TOPNodeData>> displayNodeData = _assetLink.GetNonHiddenTOPNodes(topNetworkData); int numTopNodes = displayNodeData.Count; if (numTopNodes > 0) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel(_topNodeChooseLabel); int currentSelectedIndex = -1; for (int i = 0; i < displayNodeData.Count; i++) { if (displayNodeData[i].Key == topNetworkData._selectedTOPIndex) { currentSelectedIndex = i; break; } } int selectedIndex = Mathf.Clamp(currentSelectedIndex, 0, displayNodeData.Count); int newSelectedIndex = EditorGUILayout.Popup(selectedIndex, topNetworkData._topNodeNames); if (newSelectedIndex != selectedIndex) { _assetLink.SelectTOPNode(topNetworkData, displayNodeData[newSelectedIndex].Key); } } } else { EditorGUILayout.PrefixLabel(_topNodeNoneLabel); } EditorGUILayout.Space(); HEU_TOPNodeData topNode = _assetLink.GetSelectedTOPNode(); if (topNode != null) { topNode._tags._autoload = EditorGUILayout.Toggle(_autoloadContent, topNode._tags._autoload); bool showResults = topNode._showResults; showResults = EditorGUILayout.Toggle(_showHideResultsContent, showResults); if (showResults != topNode._showResults) { topNode._showResults = showResults; _assetLink.UpdateTOPNodeResultsVisibility(topNode); } EditorGUILayout.Space(); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button(_buttonDirtyContent)) { _assetLink.DirtyTOPNode(topNode); } if (GUILayout.Button(_buttonCookContent)) { _assetLink.CookTOPNode(topNode); } } EditorGUILayout.Space(); using (new EditorGUILayout.VerticalScope(HEU_EditorUI.GetSectionStyle())) { EditorGUILayout.LabelField("TOP Node State: " + _assetLink.GetTOPNodeStatus(topNode)); EditorGUILayout.Space(); EditorGUILayout.LabelField(_topNodeStatusLabel); DrawWorkItemTally(topNode._workItemTally); } } } }
private void ProcessPDGEvent(HEU_SessionBase session, HAPI_PDG_GraphContextId contextID, ref HAPI_PDG_EventInfo eventInfo) { HEU_PDGAssetLink assetLink = null; HEU_TOPNodeData topNode = null; HAPI_PDG_EventType evType = (HAPI_PDG_EventType)eventInfo.eventType; HAPI_PDG_WorkitemState currentState = (HAPI_PDG_WorkitemState)eventInfo.currentState; HAPI_PDG_WorkitemState lastState = (HAPI_PDG_WorkitemState)eventInfo.lastState; GetTOPAssetLinkAndNode(eventInfo.nodeId, out assetLink, out topNode); //string topNodeName = topNode != null ? string.Format("node={0}", topNode._nodeName) : string.Format("id={0}", eventInfo.nodeId); //Debug.LogFormat("PDG Event: {0}, type={1}, workitem={2}, curState={3}, lastState={4}", topNodeName, evType.ToString(), // eventInfo.workitemId, currentState, lastState); if (assetLink == null || topNode == null || topNode._nodeID != eventInfo.nodeId) { return; } if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_NULL) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.NONE); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_NODE_CLEAR) { NotifyTOPNodePDGStateClear(assetLink, topNode); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_DIRTY_START) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.DIRTYING); //HEU_PDGAssetLink.ClearTOPNodeWorkItemResults(topNode); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_DIRTY_STOP) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.DIRTIED); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_COOK_ERROR) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOK_FAILED); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_COOK_WARNING) { } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_COOK_COMPLETE) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOK_COMPLETE); } else { // Work item events HEU_TOPNodeData.PDGState currentTOPPDGState = topNode._pdgState; if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_WORKITEM_ADD) { NotifyTOPNodeTotalWorkItem(assetLink, topNode, 1); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_WORKITEM_REMOVE) { NotifyTOPNodeTotalWorkItem(assetLink, topNode, -1); } else if (evType == HAPI_PDG_EventType.HAPI_PDG_EVENT_WORKITEM_STATE_CHANGE) { // Last states if (lastState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_WAITING && currentState != HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_WAITING) { NotifyTOPNodeWaitingWorkItem(assetLink, topNode, -1); } else if (lastState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKING && currentState != HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKING) { NotifyTOPNodeCookingWorkItem(assetLink, topNode, -1); } else if (lastState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_SCHEDULED && currentState != HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_SCHEDULED) { NotifyTOPNodeScheduledWorkItem(assetLink, topNode, -1); } // New states if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_WAITING) { NotifyTOPNodeWaitingWorkItem(assetLink, topNode, 1); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_UNCOOKED) { } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_DIRTY) { //Debug.LogFormat("Dirty: id={0}", eventInfo.workitemId); ClearWorkItemResult(session, contextID, eventInfo, topNode); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_SCHEDULED) { NotifyTOPNodeScheduledWorkItem(assetLink, topNode, 1); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKING) { NotifyTOPNodeCookingWorkItem(assetLink, topNode, 1); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKED_SUCCESS) { NotifyTOPNodeCookedWorkItem(assetLink, topNode); if (topNode._tags._autoload) { HAPI_PDG_WorkitemInfo workItemInfo = new HAPI_PDG_WorkitemInfo(); if (!session.GetWorkItemInfo(contextID, eventInfo.workitemId, ref workItemInfo)) { Debug.LogErrorFormat("Failed to get work item {1} info for {0}", topNode._nodeName, eventInfo.workitemId); return; } if (workItemInfo.numResults > 0) { HAPI_PDG_WorkitemResultInfo[] resultInfos = new HAPI_PDG_WorkitemResultInfo[workItemInfo.numResults]; int resultCount = workItemInfo.numResults; if (!session.GetWorkitemResultInfo(topNode._nodeID, eventInfo.workitemId, resultInfos, resultCount)) { Debug.LogErrorFormat("Failed to get work item {1} result info for {0}", topNode._nodeName, eventInfo.workitemId); return; } assetLink.LoadResults(session, topNode, workItemInfo, resultInfos, eventInfo.workitemId); } } } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKED_FAIL) { NotifyTOPNodeErrorWorkItem(assetLink, topNode); } else if (currentState == HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_COOKED_CANCEL) { // Ignore it because in-progress cooks can be cancelled when automatically recooking graph } } if (currentTOPPDGState == HEU_TOPNodeData.PDGState.COOKING) { if (topNode.AreAllWorkItemsComplete()) { if (topNode.AnyWorkItemsFailed()) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOK_FAILED); } else { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOK_COMPLETE); } } } else if (topNode.AnyWorkItemsPending()) { SetTOPNodePDGState(assetLink, topNode, HEU_TOPNodeData.PDGState.COOKING); } } }
/// <summary> /// Load the geometry generated as results of the given work item, of the given TOP node. /// The load will be done asynchronously. /// Results must be tagged with 'file', and must have a file path, otherwise will not be loaded. /// </summary> /// <param name="session">Houdini Engine session that the TOP node is in</param> /// <param name="topNode">TOP node that the work item belongs to</param> /// <param name="workItemInfo">Work item whose results to load</param> /// <param name="resultInfos">Results data</param> /// <param name="workItemID">The work item's ID. Required for clearning its results.</param> public void LoadResults(HEU_SessionBase session, HEU_TOPNodeData topNode, HAPI_PDG_WorkitemInfo workItemInfo, HAPI_PDG_WorkitemResultInfo[] resultInfos, HAPI_PDG_WorkitemId workItemID) { // Create HEU_GeoSync objects, set results, and sync it string workItemName = HEU_SessionManager.GetString(workItemInfo.nameSH, session); //Debug.LogFormat("Work item: {0}:: name={1}, results={2}", workItemInfo.index, workItemName, workItemInfo.numResults); // Clear previously generated result ClearWorkItemResultByID(topNode, workItemID); if (resultInfos == null || resultInfos.Length == 0) { return; } HEU_TOPWorkResult result = GetWorkResultByID(topNode, workItemID); if (result == null) { result = new HEU_TOPWorkResult(); result._workItemIndex = workItemInfo.index; result._workItemID = workItemID; topNode._workResults.Add(result); } // Load each result geometry int numResults = resultInfos.Length; for (int i = 0; i < numResults; ++i) { if (resultInfos[i].resultTagSH <= 0 || resultInfos[i].resultSH <= 0) { continue; } string tag = HEU_SessionManager.GetString(resultInfos[i].resultTagSH, session); string path = HEU_SessionManager.GetString(resultInfos[i].resultSH, session); //Debug.LogFormat("Result for work item {0}: result={1}, tag={2}, path={3}", result._workItemIndex, i, tag, path); if (string.IsNullOrEmpty(tag) || !tag.StartsWith("file")) { continue; } string name = string.Format("{0}_{1}_{2}", topNode._parentName, workItemName, workItemInfo.index); // Get or create parent GO if (topNode._workResultParentGO == null) { topNode._workResultParentGO = new GameObject(topNode._nodeName); HEU_GeneralUtility.SetParentWithCleanTransform(GetLoadRootTransform(), topNode._workResultParentGO.transform); topNode._workResultParentGO.SetActive(topNode._showResults); } GameObject newOrExistingGO = null; int existingObjectIndex = -1; for (int j = 0; j < result._generatedGOs.Count; j++) { if (result._generatedGOs[j] != null) { HEU_GeoSync oldGeoSync = result._generatedGOs[j].GetComponent<HEU_GeoSync>(); if (oldGeoSync != null && oldGeoSync._filePath == path) { oldGeoSync.Reset(); existingObjectIndex = j; newOrExistingGO = result._generatedGOs[j]; break; } } } if (existingObjectIndex < 0) { newOrExistingGO = new GameObject(name); result._generatedGOs.Add(newOrExistingGO); } HEU_GeneralUtility.SetParentWithCleanTransform(topNode._workResultParentGO.transform, newOrExistingGO.transform); // HEU_GeoSync does the loading HEU_GeoSync geoSync = newOrExistingGO.GetComponent<HEU_GeoSync>(); if (geoSync == null) { geoSync = newOrExistingGO.AddComponent<HEU_GeoSync>(); } geoSync._filePath = path; geoSync.SetOutputCacheDirectory(_outputCachePathRoot); geoSync.StartSync(); } }
/// <summary> /// Given TOP nodes from a TOP network, populate internal state from each TOP node. /// </summary> /// <param name="session">Houdini Engine session</param> /// <param name="topNetwork">TOP network to query TOP nodes from</param> /// <param name="topNodeIDs">List of TOP nodes in the TOP network</param> /// <param name="useHEngineData">Whether or not to use HEngine data for filtering</param> /// <returns>True if successfully populated data</returns> private bool PopulateTOPNodes(HEU_SessionBase session, HEU_TOPNetworkData topNetwork, HAPI_NodeId[] topNodeIDs, bool useHEngineData) { // Holds list of found TOP nodes List<HEU_TOPNodeData> newNodes = new List<HEU_TOPNodeData>(); foreach (HAPI_NodeId topNodeID in topNodeIDs) { // Not necessary. Blocks main thread. //session.CookNode(childNodeID, HEU_PluginSettings.CookTemplatedGeos); HAPI_NodeInfo childNodeInfo = new HAPI_NodeInfo(); if (!session.GetNodeInfo(topNodeID, ref childNodeInfo)) { return false; } string nodeName = HEU_SessionManager.GetString(childNodeInfo.nameSH, session); //HEU_Logger.LogFormat("TOP Node: name={0}, type={1}", nodeName, childNodeInfo.type); TOPNodeTags tags = new TOPNodeTags(); if (useHEngineData) { ParseHEngineData(session, topNodeID, ref childNodeInfo, ref tags); if (!tags._showHEngineData) { continue; } } else { tags._show = true; tags._showHEngineData = true; } HEU_TOPNodeData topNodeData = GetTOPNodeByName(nodeName, topNetwork._topNodes); if (topNodeData == null) { topNodeData = new HEU_TOPNodeData(); } else { topNetwork._topNodes.Remove(topNodeData); } newNodes.Add(topNodeData); //topNodeData.Reset(); topNodeData._nodeID = topNodeID; topNodeData._nodeName = nodeName; topNodeData._parentName = topNetwork._parentName + "_" + topNetwork._nodeName; topNodeData._tags = tags; // Note: Don't have to compare with _showHEngineData because it won't exist in network if false if (_bUseTOPOutputFilter && _topNodeFilter != "") { if (!nodeName.StartsWith(_topNodeFilter)) { topNodeData._tags._show = false; } } if (_bUseTOPOutputFilter) { bool bAutoLoad = false; if (_topOutputFilter == "") { bAutoLoad = true; } else if (nodeName.StartsWith(_topOutputFilter)) { bAutoLoad = true; } topNodeData._tags._autoload |= bAutoLoad; topNodeData._showResults = topNodeData._tags._autoload; } } // Clear old unused TOP nodes for (int i = 0; i < topNetwork._topNodes.Count; ++i) { ClearTOPNodeWorkItemResults(topNetwork._topNodes[i]); } topNetwork._topNodes = newNodes; // Get list of updated TOP node names SetupTopNetworkNames(topNetwork); return true; }