Inheritance: HoudiniEngineUnity.HEU_BaseSync
        /// <summary>
        /// Load a NodeSync file and create its construct in Unity.
        /// </summary>
        /// <param name="filePath">Path to the NodeSync file</param>
        /// <param name="name">Name of the NodeSync node</param>
        void CreateNodeSyncFromFile(string filePath, string name)
        {
            HEU_SessionBase session = HEU_SessionManager.GetDefaultSession();

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

            HAPI_NodeId parentNodeID = -1;
            string      nodeName     = name;
            HAPI_NodeId newNodeID    = -1;

            // This loads the node network from file, and returns the node that was created
            // with newNodeID. It is either a SOP object, or a subnet object.
            // The actual loader (HEU_ThreadedTaskLoadGeo) will deal with either case.
            if (!session.LoadNodeFromFile(filePath, parentNodeID, nodeName, true, out newNodeID))
            {
                Log(string.Format("Failed to load node network from file: {0}.", filePath));
                return;
            }

            // Wait until finished
            if (!HEU_HAPIUtility.ProcessHoudiniCookStatus(session, nodeName))
            {
                Log(string.Format("Failed to cook loaded node with name: {0}.", nodeName));
                return;
            }

            GameObject newGO = new GameObject(nodeName);

            HEU_NodeSync nodeSync = newGO.AddComponent <HEU_NodeSync>();

            nodeSync.InitializeFromHoudini(session, newNodeID, nodeName, filePath);
        }
Example #2
0
	public static void CreateNodeSync(HEU_SessionBase session, string opName, string nodeNabel)
	{
	    if (session == null)
	    {
		session = HEU_SessionManager.GetDefaultSession();
	    }
	    if (session == null || !session.IsSessionValid())
	    {
		return;
	    }

	    HAPI_NodeId newNodeID = -1;
	    HAPI_NodeId parentNodeId = -1;

	    if (!session.CreateNode(parentNodeId, opName, nodeNabel, true, out newNodeID))
	    {
		Debug.LogErrorFormat("Unable to create merge SOP node for connecting input assets.");
		return;
	    }

	    if (parentNodeId == -1)
	    {
		// When creating a node without a parent, for SOP nodes, a container
		// geometry object will have been created by HAPI.
		// In all cases we want to use the node ID of that object container
		// so the below code sets the parent's node ID.

		// But for SOP/subnet we actually do want the subnet SOP node ID
		// hence the useSOPNodeID argument here is to override it.
		bool useSOPNodeID = opName.Equals("SOP/subnet");

		HAPI_NodeInfo nodeInfo = new HAPI_NodeInfo();
		if (!session.GetNodeInfo(newNodeID, ref nodeInfo))
		{
		    return;
		}

		if (nodeInfo.type == HAPI_NodeType.HAPI_NODETYPE_SOP)
		{
		    if (!useSOPNodeID)
		    {
			newNodeID = nodeInfo.parentId;
		    }
		}
		else if (nodeInfo.type != HAPI_NodeType.HAPI_NODETYPE_OBJ)
		{
		    Debug.LogErrorFormat("Unsupported node type {0}", nodeInfo.type);
		    return;
		}
	    }

	    GameObject newGO = new GameObject(nodeNabel);

	    HEU_NodeSync nodeSync = newGO.AddComponent<HEU_NodeSync>();
	    nodeSync.InitializeFromHoudini(session, newNodeID, nodeNabel, "");
	}
        /// <summary>
        /// Unity callback to draw this UI.
        /// </summary>
        void OnGUI()
        {
            SetupUI();

            HEU_SessionSyncData syncData = GetSessionSyncData();

            EditorGUI.BeginChangeCheck();

            bool bSessionStarted  = (syncData != null && syncData.SyncStatus != HEU_SessionSyncData.Status.Stopped);
            bool bSessionCanStart = !bSessionStarted;

            if (bSessionCanStart)
            {
                // Only able to start a session if no session exists.
                HEU_SessionBase session = HEU_SessionManager.GetDefaultSession();
                if (session != null && session.IsSessionValid())
                {
                    bSessionCanStart = false;
                }
            }

            HEU_HoudiniAssetUI.DrawHeaderSection();

            // Draw SessionSync status.
            if (syncData != null)
            {
                if (syncData.SyncStatus == HEU_SessionSyncData.Status.Stopped)
                {
                    if (!bSessionCanStart)
                    {
                        EditorGUILayout.LabelField("Another session already running. Disconnect it to start SessionSync.");
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Status: " + syncData.SyncStatus);
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Status: " + syncData.SyncStatus);
                }
            }
            else
            {
                if (!bSessionCanStart)
                {
                    EditorGUILayout.LabelField("Another session already running. Disconnect it to start SessionSync.");
                }
                else
                {
                    EditorGUILayout.LabelField("No active session.");
                }
            }

            EditorGUILayout.Separator();

            EditorGUI.indentLevel++;

            // Draw initial connection buttons (Start, Connect)
            using (new EditorGUILayout.HorizontalScope())
            {
                using (new EditorGUI.DisabledScope(bSessionStarted || !bSessionCanStart))
                {
                    if (GUILayout.Button("Start Houdini"))
                    {
                        StartAndConnectToHoudini(syncData);
                    }
                    else if (GUILayout.Button("Connect to Houdini"))
                    {
                        ConnectSessionSync(syncData);
                    }
                }
            }

            using (new EditorGUI.DisabledScope((syncData == null || !bSessionStarted) && bSessionCanStart))
            {
                if (GUILayout.Button("Disconnect"))
                {
                    Disconnect(syncData);
                }
            }

            EditorGUILayout.Separator();

            // Draw Connection Settings
            EditorGUILayout.LabelField("Connection Settings");

            using (new EditorGUI.DisabledScope(bSessionStarted))
            {
                SessionMode newSessionMode = (SessionMode)EditorGUILayout.EnumPopup("Type", _sessionMode);
                if (_sessionMode != newSessionMode)
                {
                    _sessionMode = newSessionMode;
                    HEU_PluginSettings.Session_Mode = newSessionMode;
                }

                EditorGUI.indentLevel++;
                if (_sessionMode == SessionMode.Pipe)
                {
                    string newPipeName = EditorGUILayout.DelayedTextField("Pipe Name", _pipeName);
                    if (_pipeName != newPipeName)
                    {
                        HEU_PluginSettings.Session_PipeName = newPipeName;
                        _pipeName = newPipeName;
                    }
                }
                else if (_sessionMode == SessionMode.Socket)
                {
                    int newPort = EditorGUILayout.DelayedIntField("Port", _port);
                    HEU_PluginSettings.Session_Port = newPort;
                    if (_port != newPort)
                    {
                        HEU_PluginSettings.Session_Port = newPort;
                        _port = newPort;
                    }
                }
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Separator();

            // The rest requires syncData

            // Synchronization settings, and new nodes
            if (syncData != null)
            {
                using (new EditorGUI.DisabledScope(syncData.SyncStatus != HEU_SessionSyncData.Status.Connected))
                {
                    EditorGUILayout.LabelField("Synchronization Settings");

                    EditorGUI.indentLevel++;

                    HEU_PluginSettings.SessionSyncAutoCook = HEU_EditorUI.DrawToggleLeft(HEU_PluginSettings.SessionSyncAutoCook, "Sync With Houdini Cook");

                    bool enableHoudiniTime = HEU_EditorUI.DrawToggleLeft(syncData._syncInfo.cookUsingHoudiniTime, "Cook Using Houdini Time");
                    if (syncData._syncInfo.cookUsingHoudiniTime != enableHoudiniTime)
                    {
                        syncData._syncInfo.cookUsingHoudiniTime = enableHoudiniTime;
                        UploadSessionSyncInfo(null, syncData);
                    }

                    bool enableSyncViewport = HEU_EditorUI.DrawToggleLeft(syncData._syncInfo.syncViewport, "Sync Viewport");
                    if (syncData._syncInfo.syncViewport != enableSyncViewport)
                    {
                        syncData._syncInfo.syncViewport = enableSyncViewport;
                        UploadSessionSyncInfo(null, syncData);
                    }

                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.Separator();

                EditorGUILayout.LabelField("New Node");

                using (new EditorGUI.DisabledScope(syncData.SyncStatus != HEU_SessionSyncData.Status.Connected))
                {
                    EditorGUI.indentLevel++;

                    syncData._newNodeName = EditorGUILayout.TextField("Name", syncData._newNodeName);

                    syncData._nodeTypeIndex = EditorGUILayout.Popup("Type", syncData._nodeTypeIndex, _nodeTypesLabels);

                    using (new EditorGUI.DisabledGroupScope(string.IsNullOrEmpty(syncData._newNodeName)))
                    {
                        using (new EditorGUILayout.VerticalScope())
                        {
                            if (GUILayout.Button("Create"))
                            {
                                if (syncData._nodeTypeIndex >= 0 && syncData._nodeTypeIndex < 3)
                                {
                                    HEU_NodeSync.CreateNodeSync(null, _nodeTypes[syncData._nodeTypeIndex],
                                                                syncData._newNodeName);
                                }
                                else if (syncData._nodeTypeIndex == 3)
                                {
                                    CreateCurve(syncData._newNodeName);
                                }
                                else if (syncData._nodeTypeIndex == 4)
                                {
                                    CreateInput(syncData._newNodeName);
                                }
                            }

                            if (GUILayout.Button("Load NodeSync"))
                            {
                                LoadNodeSyncDialog(syncData._newNodeName);
                            }
                        }
                    }

                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.Separator();

                // Log
                using (new EditorGUILayout.VerticalScope(_backgroundStyle))
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        EditorGUILayout.PrefixLabel(_eventMessageContent);

                        if (GUILayout.Button("Clear"))
                        {
                            ClearLog();
                        }
                    }

                    string logMsg = GetLog();

                    using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(_eventMessageScrollPos, GUILayout.Height(120)))
                    {
                        _eventMessageScrollPos = scrollViewScope.scrollPosition;

                        GUILayout.Label(logMsg, _eventMessageStyle);
                    }
                }
            }

            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck() && syncData != null)
            {
                HEU_SessionBase sessionBase = HEU_SessionManager.GetDefaultSession();
                if (sessionBase != null)
                {
                    HEU_SessionManager.SaveAllSessionData();
                }
            }
        }