Пример #1
0
 private static void ResetPDGEventInfo(ref HAPI_PDG_EventInfo eventInfo)
 {
     eventInfo.nodeId       = HEU_Defines.HEU_INVALID_NODE_ID;
     eventInfo.workitemId   = -1;
     eventInfo.dependencyId = -1;
     eventInfo.currentState = (int)HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_UNDEFINED;
     eventInfo.lastState    = (int)HAPI_PDG_WorkitemState.HAPI_PDG_WORKITEM_UNDEFINED;
     eventInfo.eventType    = (int)HAPI_PDG_EventType.HAPI_PDG_EVENT_NULL;
 }
Пример #2
0
        /// <summary>
        /// Query all the PDG graph context in the current Houdini Engine session.
        /// Handle PDG events, work item status updates.
        /// Forward relevant events to HEU_PDGAssetLink objects.
        /// </summary>
        private void UpdatePDGContext()
        {
#if HOUDINIENGINEUNITY_ENABLED
            HEU_SessionBase session = GetHAPIPDGSession();
            if (session == null || !session.IsSessionValid())
            {
                return;
            }

            // Get current PDG graph contexts
            ReinitializePDGContext();

            // Process next set of events for each graph context
            if (_pdgContextIDs != null)
            {
                foreach (HAPI_PDG_GraphContextId contextID in _pdgContextIDs)
                {
                    int pdgStateInt;
                    if (!session.GetPDGState(contextID, out pdgStateInt))
                    {
                        SetErrorState("Failed to get PDG state", true);
                        continue;
                    }

                    _pdgState = (HAPI_PDG_State)pdgStateInt;

                    // Only initialize event array if not valid, or user resized max size
                    if (_pdgQueryEvents == null || _pdgQueryEvents.Length != _pdgMaxProcessEvents)
                    {
                        _pdgQueryEvents = new HAPI_PDG_EventInfo[_pdgMaxProcessEvents];
                    }

                    for (int i = 0; i < _pdgQueryEvents.Length; ++i)
                    {
                        ResetPDGEventInfo(ref _pdgQueryEvents[i]);
                    }

                    int eventCount     = 0;
                    int remainingCount = 0;
                    if (!session.GetPDGEvents(contextID, _pdgQueryEvents, _pdgMaxProcessEvents, out eventCount, out remainingCount))
                    {
                        SetErrorState("Failed to get PDG events", true);
                        continue;
                    }

                    for (int i = 0; i < eventCount; ++i)
                    {
                        ProcessPDGEvent(session, contextID, ref _pdgQueryEvents[i]);
                    }
                }
            }
#endif
        }
Пример #3
0
        private void UpdatePDGContext()
        {
            HEU_SessionBase session = GetHAPIPDGSession();

            if (session == null || !session.IsSessionValid())
            {
                return;
            }

            ReinitializePDGContext();

            // Get next set of events for each graph context
            if (_pdgContextIDs != null)
            {
                foreach (HAPI_PDG_GraphContextId contextID in _pdgContextIDs)
                {
                    int pdgStateInt;
                    if (!session.GetPDGState(contextID, out pdgStateInt))
                    {
                        SetErrorState("Failed to get PDG state", true);
                        continue;
                    }

                    _pdgState = (HAPI_PDG_State)pdgStateInt;


                    if (_pdgQueryEvents == null || _pdgQueryEvents.Length != _pdgMaxProcessEvents)
                    {
                        _pdgQueryEvents = new HAPI_PDG_EventInfo[_pdgMaxProcessEvents];
                    }

                    for (int i = 0; i < _pdgQueryEvents.Length; ++i)
                    {
                        ResetPDGEventInfo(ref _pdgQueryEvents[i]);
                    }

                    int eventCount     = 0;
                    int remainingCount = 0;
                    if (!session.GetPDGEvents(contextID, _pdgQueryEvents, _pdgMaxProcessEvents, out eventCount, out remainingCount))
                    {
                        SetErrorState("Failed to get PDG events", true);
                        continue;
                    }

                    for (int i = 0; i < eventCount; ++i)
                    {
                        ProcessPDGEvent(session, contextID, ref _pdgQueryEvents[i]);
                    }
                }
            }
        }
Пример #4
0
        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;
        }
Пример #5
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>
        /// 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
        }