Exemplo n.º 1
0
	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 "";
	}
Exemplo n.º 2
0
        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>
        /// 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
        }